本文整理汇总了Python中wirecloud.commons.utils.html.clean_html函数的典型用法代码示例。如果您正苦于以下问题:Python clean_html函数的具体用法?Python clean_html怎么用?Python clean_html使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了clean_html函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_workspace_data
def get_workspace_data(workspace, user):
user_workspace = None
if user.is_authenticated():
try:
user_workspace = UserWorkspace.objects.get(user=user, workspace=workspace)
except UserWorkspace.DoesNotExist:
pass
longdescription = workspace.longdescription
if longdescription != '':
longdescription = clean_html(markdown.markdown(longdescription, output_format='xhtml5'))
else:
longdescription = workspace.description
return {
'id': workspace.id,
'name': workspace.name,
'shared': workspace.is_shared(),
'creator': workspace.creator.username,
'owned': workspace.creator == user,
'removable': workspace.creator == user and (user_workspace is None or user_workspace.manager == ''),
'active': user_workspace is not None and user_workspace.active,
'lastmodified': workspace.last_modified,
'description': workspace.description,
'longdescription': longdescription,
}
开发者ID:GreenIDer-Donati,项目名称:wirecloud,代码行数:28,代码来源:utils.py
示例2: read
def read(self, request, vendor, name, version):
resource = get_object_or_404(CatalogueResource, vendor=vendor, short_name=name, version=version)
resource_info = json.loads(resource.json_description)
if resource_info['doc'] == '':
raise Http404
doc_base_url = None
if resource_info['doc'].startswith(('http://', 'https://')):
doc_code = _('You can find the userguide of this component in this external <a target="_blank" href="%s">link</a>') % resource_info['doc']
doc_code = '<div style="margin-top: 10px"><p>%s</p></div>' % doc_code
else:
doc_relative_path = url2pathname(resource_info['doc'])
doc_base_url = force_trailing_slash(urljoin(resource.get_template_url(request=request, for_base=True), pathname2url(os.path.dirname(doc_relative_path))))
doc_path = os.path.join(catalogue_utils.wgt_deployer.get_base_dir(vendor, name, version), doc_relative_path)
(doc_filename_root, doc_filename_ext) = os.path.splitext(doc_path)
localized_doc_path = doc_filename_root + '.' + get_language() + doc_filename_ext
try:
doc_code = download_local_file(localized_doc_path).decode('utf-8')
except:
try:
doc_code = download_local_file(doc_path).decode('utf-8')
except:
msg = _('Error opening the userguide file')
doc_code = '<div class="margin-top: 10px"><p>%s</p></div>' % msg
doc_pre_html = markdown.markdown(doc_code, output_format='xhtml5', extensions=['codehilite', 'fenced_code'])
doc = clean_html(doc_pre_html, base_url=doc_base_url)
return HttpResponse(doc, content_type='application/xhtml+xml; charset=UTF-8')
开发者ID:rachmadagitam,项目名称:apps.Wirecloud,代码行数:31,代码来源:views.py
示例3: test_relative_image_urls
def test_relative_image_urls(self):
initial_code = 'Example image: <img src="images/example.png"/>'
expected_code = 'Example image: <img src="http://example.com/images/example.png"/>'
self.assertEqual(clean_html(initial_code, base_url='http://example.com'), expected_code)
开发者ID:Mognom,项目名称:wirecloud,代码行数:4,代码来源:utils.py
示例4: test_relative_links_are_removed
def test_relative_links_are_removed(self):
initial_code = '<div class="alert">Follow this <a href="files/insecure_content.exe">link</a></div>'
expected_code = '<div class="alert">Follow this link</div>'
self.assertEqual(clean_html(initial_code), expected_code)
开发者ID:Mognom,项目名称:wirecloud,代码行数:4,代码来源:utils.py
示例5: test_links_are_forced_to_target_blank
def test_links_are_forced_to_target_blank(self):
self.assertEqual(clean_html('<div class="alert">Follow this <a href="http://example.com">link</a></div>'), '<div class="alert">Follow this <a href="http://example.com" target="_blank">link</a></div>')
开发者ID:Mognom,项目名称:wirecloud,代码行数:2,代码来源:utils.py
示例6: test_video_elements_need_controls
def test_video_elements_need_controls(self):
initial_code = '<video><source src="movie.mp4" type="video/mp4"/><source src="movie.ogg" type="video/ogg"/>Your browser does not support the video tag.</video>content'
expected_code = '<video controls="controls"><source src="movie.mp4" type="video/mp4"/><source src="movie.ogg" type="video/ogg"/>Your browser does not support the video tag.</video>content'
self.assertEqual(clean_html(initial_code), expected_code)
开发者ID:Mognom,项目名称:wirecloud,代码行数:4,代码来源:utils.py
示例7: test_audio_elements_are_removed
def test_audio_elements_are_removed(self):
initial_code = '<div class="alert"><audio controls="controls"><source src="sound.ogg" type="audio/ogg"/><source src="sound.mp3" type="audio/mpeg"/>Your browser does not support the audio tag.</audio>content</div>'
self.assertEqual(clean_html(initial_code), '<div class="alert">content</div>')
开发者ID:Mognom,项目名称:wirecloud,代码行数:3,代码来源:utils.py
示例8: test_processing_instructions_are_removed
def test_processing_instructions_are_removed(self):
self.assertEqual(clean_html('<div class="alert"><?php echo "<p>Hello World</p>"; ?>content</div>'), '<div class="alert">content</div>')
开发者ID:Mognom,项目名称:wirecloud,代码行数:2,代码来源:utils.py
示例9: test_event_attributes_are_removed
def test_event_attributes_are_removed(self):
self.assertEqual(clean_html('<div onclick="evil_script();" class="alert">content</div>'), '<div class="alert">content</div>')
开发者ID:Mognom,项目名称:wirecloud,代码行数:2,代码来源:utils.py
示例10: test_scripts_are_removed
def test_scripts_are_removed(self):
self.assertEqual(clean_html('<script>asdfas</script>'), '')
self.assertEqual(clean_html('start content <script>asdfas</script> valid content'), 'start content valid content')
开发者ID:Mognom,项目名称:wirecloud,代码行数:3,代码来源:utils.py
示例11: get_resource_data
def get_resource_data(resource, user, request=None):
"""Gets all the information related to the given resource."""
resource_info = resource.get_processed_info(request)
template_uri = get_absolute_reverse_url('wirecloud_catalogue.media', kwargs={
'vendor': resource.vendor,
'name': resource.short_name,
'version': resource.version,
'file_path': resource.template_uri
}, request=request)
wgt_path = os.path.join(wgt_deployer.get_base_dir(resource.vendor, resource.short_name, resource.version), resource.template_uri)
size = os.path.getsize(wgt_path)
cdate = resource.creation_date
creation_timestamp = time.mktime(cdate.timetuple()) * 1e3 + cdate.microsecond / 1e3
longdescription = resource_info['longdescription']
if longdescription != '':
longdescription_relative_path = url2pathname(longdescription)
longdescription_base_url = force_trailing_slash(urljoin(resource.get_template_url(request=request, for_base=True), pathname2url(os.path.dirname(longdescription_relative_path))))
longdescription_path = os.path.join(wgt_deployer.get_base_dir(resource.vendor, resource.short_name, resource.version), longdescription_relative_path)
(filename_root, filename_ext) = os.path.splitext(longdescription_path)
localized_longdescription_path = filename_root + '.' + get_language() + filename_ext
try:
description_code = download_local_file(localized_longdescription_path).decode('utf-8')
longdescription = clean_html(markdown.markdown(description_code, output_format='xhtml5'), base_url=longdescription_base_url)
except:
try:
description_code = download_local_file(longdescription_path).decode('utf-8')
longdescription = clean_html(markdown.markdown(description_code, output_format='xhtml5'), base_url=longdescription_base_url)
except:
longdescription = resource_info['description']
else:
longdescription = resource_info['description']
return {
'id': resource.pk,
'vendor': resource.vendor,
'name': resource.short_name,
'version': resource.version,
'type': resource_info['type'],
'date': creation_timestamp,
'permissions': {
'delete': user.is_superuser,
'uninstall': resource.public is False and resource.users.filter(pk=user.pk).exists(),
},
'authors': resource_info['authors'],
'contributors': resource_info['contributors'],
'title': resource_info['title'],
'description': resource_info['description'],
'longdescription': longdescription,
'email': resource_info['email'],
'image': resource_info['image'],
'homepage': resource_info['homepage'],
'doc': resource_info['doc'],
'changelog': resource_info['changelog'],
'size': size,
'uriTemplate': template_uri,
'license': resource_info['license'],
'licenseurl': resource_info['licenseurl'],
'issuetracker': resource_info['issuetracker'],
}
开发者ID:Wirecloud,项目名称:wirecloud,代码行数:66,代码来源:utils.py
示例12: get_resource_data
def get_resource_data(resource, user, request=None):
"""Gets all the information related to the given resource."""
resource_info = resource.get_processed_info(request)
template_uri = get_absolute_reverse_url(
"wirecloud_catalogue.media",
kwargs={
"vendor": resource.vendor,
"name": resource.short_name,
"version": resource.version,
"file_path": resource.template_uri,
},
request=request,
)
wgt_path = os.path.join(
wgt_deployer.get_base_dir(resource.vendor, resource.short_name, resource.version), resource.template_uri
)
size = os.path.getsize(wgt_path)
cdate = resource.creation_date
creation_timestamp = time.mktime(cdate.timetuple()) * 1e3 + cdate.microsecond / 1e3
longdescription = resource_info["longdescription"]
if longdescription != "":
longdescription_relative_path = url2pathname(longdescription)
longdescription_base_url = force_trailing_slash(
urljoin(
resource.get_template_url(request=request, for_base=True),
pathname2url(os.path.dirname(longdescription_relative_path)),
)
)
longdescription_path = os.path.join(
wgt_deployer.get_base_dir(resource.vendor, resource.short_name, resource.version),
longdescription_relative_path,
)
(filename_root, filename_ext) = os.path.splitext(longdescription_path)
localized_longdescription_path = filename_root + "." + get_language() + filename_ext
try:
description_code = download_local_file(localized_longdescription_path)
longdescription = clean_html(
markdown.markdown(description_code, output_format="xhtml5"), base_url=longdescription_base_url
)
except:
try:
description_code = download_local_file(longdescription_path)
longdescription = clean_html(
markdown.markdown(description_code, output_format="xhtml5"), base_url=longdescription_base_url
)
except:
longdescription = resource_info["description"]
else:
longdescription = resource_info["description"]
return {
"id": resource.pk,
"vendor": resource.vendor,
"name": resource.short_name,
"version": resource.version,
"type": resource_info["type"],
"date": creation_timestamp,
"permissions": {
"delete": user.is_superuser,
"uninstall": resource.public is False and resource.users.filter(pk=user.pk).exists(),
},
"authors": resource_info["authors"],
"contributors": resource_info["contributors"],
"title": resource_info["title"],
"description": resource_info["description"],
"longdescription": longdescription,
"email": resource_info["email"],
"image": resource_info["image"],
"homepage": resource_info["homepage"],
"doc": resource_info["doc"],
"changelog": resource_info["changelog"],
"size": size,
"uriTemplate": template_uri,
"license": resource_info["license"],
"licenseurl": resource_info["licenseurl"],
"issuetracker": resource_info["issuetracker"],
}
开发者ID:GreenIDer-Donati,项目名称:wirecloud,代码行数:84,代码来源:utils.py
注:本文中的wirecloud.commons.utils.html.clean_html函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论