本文整理汇总了Python中wirecloud.platform.widget.utils.fix_widget_code函数的典型用法代码示例。如果您正苦于以下问题:Python fix_widget_code函数的具体用法?Python fix_widget_code怎么用?Python fix_widget_code使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fix_widget_code函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_basic_xhtml
def test_basic_xhtml(self):
initial_code = self.read_file('test-data/xhtml2-initial.html')
final_code = fix_widget_code(initial_code, 'http://server.com/widget', 'application/xhtml+xml', None, False) + '\n'
expected_code = self.read_file('test-data/xhtml2-expected.html')
self.assertEqual(final_code, expected_code)
开发者ID:ciniguez,项目名称:FIREWA,代码行数:5,代码来源:tests.py
示例2: test_basic_xhtml_iso8859_15
def test_basic_xhtml_iso8859_15(self):
initial_code = self.read_file('test-data/xhtml2-iso8859-15-initial.html')
final_code = self.XML_NORMALIZATION_RE.sub('><', fix_widget_code(initial_code, 'http://server.com/widget', 'application/xhtml+xml', None, 'iso-8859-15', False)) + '\n'
expected_code = self.read_file('test-data/xhtml2-iso8859-15-expected.html')
self.assertEqual(final_code, expected_code)
开发者ID:Robinlovelace,项目名称:wirecloud,代码行数:5,代码来源:tests.py
示例3: test_unhandled_content_type
def test_unhandled_content_type(self):
initial_code = b'plain text'
final_code = fix_widget_code(initial_code, 'http://server.com/widget', 'text/plain', None, 'utf-8', False, {}, False, 'classic')
self.assertEqual(final_code, initial_code)
开发者ID:Mognom,项目名称:wirecloud,代码行数:5,代码来源:tests.py
示例4: test_html_unclosed_tags
def test_html_unclosed_tags(self):
initial_code = self.read_file('test-data/html-unclosed-tags-initial.html')
final_code = self.XML_NORMALIZATION_RE.sub(b'><', fix_widget_code(initial_code, 'http://server.com/widget', 'text/html', None, 'utf-8', False, {}, False, 'classic')) + b'\n'
expected_code = self.read_file('test-data/html-unclosed-tags-expected.html')
self.assertEqual(final_code, expected_code)
开发者ID:Mognom,项目名称:wirecloud,代码行数:6,代码来源:tests.py
示例5: test_html_with_more_than_one_base_element
def test_html_with_more_than_one_base_element(self):
initial_code = self.read_file('test-data/xhtml4-extra-base-elements-initial.html')
final_code = self.XML_NORMALIZATION_RE.sub(b'><', fix_widget_code(initial_code, 'text/html', None, 'utf-8', False, {}, 'classic', 'wirecloud_defaulttheme')) + b'\n'
expected_code = self.read_file('test-data/xhtml4-expected.html')
self.assertEqual(final_code, expected_code)
开发者ID:Fiware,项目名称:apps.Wirecloud,代码行数:5,代码来源:tests.py
示例6: test_basic_xhtml
def test_basic_xhtml(self):
initial_code = self.read_file('test-data/xhtml2-initial.html')
final_code = self.XML_NORMALIZATION_RE.sub(b'><', fix_widget_code(initial_code, 'http://server.com/widget', 'application/xhtml+xml', None, 'utf-8', False, {}, False, 'classic')) + b'\n'
expected_code = self.read_file('test-data/xhtml2-expected.html')
self.assertEqual(final_code, expected_code)
开发者ID:Mognom,项目名称:wirecloud,代码行数:5,代码来源:tests.py
示例7: build_error_response
return build_error_response(request, 502, msg)
else:
# Code contents comes as unicode from persistence, we need bytes
code = code.encode(charset)
if xhtml.cacheable and (xhtml.code == '' or xhtml.code_timestamp is None):
xhtml.code = code.decode(charset)
xhtml.code_timestamp = time.time() * 1000
xhtml.save()
elif not xhtml.cacheable and xhtml.code != '':
xhtml.code = ''
xhtml.code_timestamp = None
xhtml.save()
try:
code = fix_widget_code(code, base_url, content_type, request, charset, xhtml.use_platform_style, force_base=force_base)
except UnicodeEncodeError:
msg = _('Widget code was not encoded using the specified charset (%(charset)s according to the widget descriptor file).')
return build_error_response(request, 502, msg % {'charset': charset})
if xhtml.cacheable:
cache_timeout = 31536000 # 1 year
cache_entry = {
'code': code,
'mimetype': '%s; charset=%s' % (content_type, charset),
'timestamp': xhtml.code_timestamp,
'timeout': cache_timeout,
}
cache.set(cache_key, cache_entry, cache_timeout)
else:
cache_timeout = 0
开发者ID:Robinlovelace,项目名称:wirecloud,代码行数:31,代码来源:views.py
示例8: test_xhtml_without_head_element
def test_xhtml_without_head_element(self):
initial_code = self.read_file('test-data/xhtml3-initial.html')
final_code = self.XML_NORMALIZATION_RE.sub('><', fix_widget_code(initial_code, 'http://server.com/widget', 'application/xhtml+xml', None, False)) + '\n'
expected_code = self.read_file('test-data/xhtml3-expected.html')
self.assertEqual(final_code, expected_code)
开发者ID:fispace,项目名称:wirecloud,代码行数:5,代码来源:tests.py
示例9: test_unhandled_content_type
def test_unhandled_content_type(self):
initial_code = b'plain text'
final_code = fix_widget_code(initial_code, 'text/plain', None, 'utf-8', False, {}, 'classic', 'wirecloud.defaulttheme')
self.assertEqual(final_code, initial_code)
开发者ID:Fiware,项目名称:apps.Wirecloud,代码行数:5,代码来源:tests.py
示例10: test_basic_html
def test_basic_html(self):
initial_code = self.read_file('test-data/xhtml1-initial.html')
final_code = self.XML_NORMALIZATION_RE.sub(b'><', fix_widget_code(initial_code, 'text/html', None, 'utf-8', False, {}, 'classic', 'wirecloud_defaulttheme')) + b'\n'
expected_code = self.read_file('test-data/xhtml1-expected.html')
self.assertEqual(final_code, expected_code)
开发者ID:Fiware,项目名称:apps.Wirecloud,代码行数:5,代码来源:tests.py
示例11: test_xhtml_without_head_element
def test_xhtml_without_head_element(self):
initial_code = self.read_file('test-data/xhtml3-initial.html')
final_code = self.XML_NORMALIZATION_RE.sub(b'><', fix_widget_code(initial_code, 'application/xhtml+xml', None, 'utf-8', False, {}, 'classic', 'wirecloud_defaulttheme')) + b'\n'
expected_code = self.read_file('test-data/xhtml3-expected.html')
self.assertEqual(final_code, expected_code)
开发者ID:Fiware,项目名称:apps.Wirecloud,代码行数:5,代码来源:tests.py
示例12: test_basic_xhtml_iso8859_15
def test_basic_xhtml_iso8859_15(self):
initial_code = self.read_file('test-data/xhtml2-iso8859-15-initial.html')
final_code = self.XML_NORMALIZATION_RE.sub(b'><', fix_widget_code(initial_code, 'application/xhtml+xml', None, 'iso-8859-15', False, {}, 'classic', 'wirecloud_defaulttheme')) + b'\n'
expected_code = self.read_file('test-data/xhtml2-iso8859-15-expected.html')
self.assertEqual(final_code, expected_code)
开发者ID:Fiware,项目名称:apps.Wirecloud,代码行数:5,代码来源:tests.py
示例13: test_basic_xhtml_compressed
def test_basic_xhtml_compressed(self):
initial_code = self.read_file('test-data/xhtml2-initial.html')
final_code = self.XML_NORMALIZATION_RE.sub(b'><', fix_widget_code(initial_code, 'application/xhtml+xml', None, 'utf-8', False, {}, 'classic', 'wirecloud_defaulttheme')) + b'\n'
final_code = self.COMPRESS_HASH_RE.sub(b'/widgetapi.js', final_code)
expected_code = self.read_file('test-data/xhtml2-compressed-expected.html')
self.assertEqual(final_code, expected_code)
开发者ID:Fiware,项目名称:apps.Wirecloud,代码行数:6,代码来源:tests.py
示例14: process_widget_code
def process_widget_code(request, resource):
mode = request.GET.get('mode', 'classic')
theme = request.GET.get('theme', get_active_theme_name())
widget_info = json.loads(resource.json_description)
# check if the xhtml code has been cached
if widget_info['contents']['cacheable'] is True:
cache_key = resource.widget.xhtml.get_cache_key(get_current_domain(request), mode, theme)
cache_entry = cache.get(cache_key)
if cache_entry is not None:
response = HttpResponse(cache_entry['code'], content_type=cache_entry['content_type'])
patch_cache_headers(response, cache_entry['timestamp'], cache_entry['timeout'])
return response
# process xhtml
xhtml = resource.widget.xhtml
content_type = widget_info['contents'].get('contenttype', 'text/html')
charset = widget_info['contents'].get('charset', 'utf-8')
code = xhtml.code
if not xhtml.cacheable or code == '':
try:
code = download_local_file(os.path.join(showcase_utils.wgt_deployer.root_dir, url2pathname(xhtml.url)))
except Exception as e:
if isinstance(e, IOError) and e.errno == errno.ENOENT:
return build_response(request, 404, {'error_msg': _("Widget code not found"), 'details': "%s" % e}, WIDGET_ERROR_FORMATTERS)
else:
return build_response(request, 500, {'error_msg': _("Error reading widget code"), 'details': "%s" % e}, WIDGET_ERROR_FORMATTERS)
else:
# Code contents comes as unicode from persistence, we need bytes
code = code.encode(charset)
if xhtml.cacheable and (xhtml.code == '' or xhtml.code_timestamp is None):
try:
xhtml.code = code.decode(charset)
except UnicodeDecodeError:
msg = _('Widget code was not encoded using the specified charset (%(charset)s as stated in the widget description file).') % {'charset': charset}
return build_response(request, 502, {'error_msg': msg}, WIDGET_ERROR_FORMATTERS)
xhtml.code_timestamp = time.time() * 1000
xhtml.save()
try:
code = fix_widget_code(code, content_type, request, charset, xhtml.use_platform_style, process_requirements(widget_info['requirements']), mode, theme)
except UnicodeDecodeError:
msg = _('Widget code was not encoded using the specified charset (%(charset)s as stated in the widget description file).') % {'charset': charset}
return build_response(request, 502, {'error_msg': msg}, WIDGET_ERROR_FORMATTERS)
except Exception as e:
msg = _('Error processing widget code')
return build_response(request, 502, {'error_msg': msg, 'details':"%s" % e}, WIDGET_ERROR_FORMATTERS)
if xhtml.cacheable:
cache_timeout = 31536000 # 1 year
cache_entry = {
'code': code,
'content_type': '%s; charset=%s' % (content_type, charset),
'timestamp': xhtml.code_timestamp,
'timeout': cache_timeout,
}
cache.set(cache_key, cache_entry, cache_timeout)
else:
cache_timeout = 0
response = HttpResponse(code, content_type='%s; charset=%s' % (content_type, charset))
patch_cache_headers(response, xhtml.code_timestamp, cache_timeout)
return response
开发者ID:Fiware,项目名称:apps.Wirecloud,代码行数:69,代码来源:views.py
示例15: test_basic_html_iso8859_15
def test_basic_html_iso8859_15(self):
initial_code = self.read_file('test-data/xhtml1-iso8859-15-initial.html')
final_code = self.XML_NORMALIZATION_RE.sub(b'><', fix_widget_code(initial_code, 'http://server.com/widget', 'text/html', None, 'iso-8859-15', False, {}, False, 'classic')) + b'\n'
expected_code = self.read_file('test-data/xhtml1-iso8859-15-expected.html')
self.assertEqual(final_code, expected_code)
开发者ID:Mognom,项目名称:wirecloud,代码行数:5,代码来源:tests.py
示例16: test_basic_html
def test_basic_html(self):
initial_code = self.read_file('test-data/xhtml1-initial.html')
final_code = self.XML_NORMALIZATION_RE.sub('><', fix_widget_code(initial_code, 'http://server.com/widget', 'text/html', None, False)) + '\n'
expected_code = self.read_file('test-data/xhtml1-expected.html')
self.assertEqual(final_code, expected_code)
开发者ID:fispace,项目名称:wirecloud,代码行数:5,代码来源:tests.py
示例17: test_html_with_more_than_one_base_element_force_base
def test_html_with_more_than_one_base_element_force_base(self):
initial_code = self.read_file('test-data/xhtml4-extra-base-elements-initial.html')
final_code = self.XML_NORMALIZATION_RE.sub(b'><', fix_widget_code(initial_code, 'http://server.com/widget', 'text/html', None, 'utf-8', False, {}, True, 'classic')) + b'\n'
expected_code = self.read_file('test-data/xhtml4-forced-base-expected.html')
self.assertEqual(final_code, expected_code)
开发者ID:Mognom,项目名称:wirecloud,代码行数:5,代码来源:tests.py
示例18: read
def read(self, request, vendor, name, version):
resource = get_object_or_404(CatalogueResource.objects.select_related('widget__xhtml'), vendor=vendor, short_name=name, version=version)
# For now, all widgets are freely accessible/distributable
#if not resource.is_available_for(request.user):
# return build_error_response(request, 403, "Forbidden")
if resource.resource_type() != 'widget':
raise Http404()
mode = request.GET.get('mode', 'classic')
widget_info = json.loads(resource.json_description)
# check if the xhtml code has been cached
if widget_info['contents']['cacheable'] is True:
cache_key = resource.widget.xhtml.get_cache_key(get_current_domain(request), mode)
cache_entry = cache.get(cache_key)
if cache_entry is not None:
response = HttpResponse(cache_entry['code'], content_type=cache_entry['content_type'])
patch_cache_headers(response, cache_entry['timestamp'], cache_entry['timeout'])
return response
# process xhtml
xhtml = resource.widget.xhtml
content_type = widget_info['contents'].get('contenttype', 'text/html')
charset = widget_info['contents'].get('charset', 'utf-8')
force_base = False
base_url = xhtml.url
if not base_url.startswith(('http://', 'https://')):
# Newer versions of Django urlencode urls created using reverse
# Fix double encoding
base_url = urlunquote(base_url)
base_url = get_absolute_reverse_url('wirecloud.showcase_media', args=(base_url.split('/', 4)), request=request)
force_base = True
code = xhtml.code
if not xhtml.cacheable or code == '':
try:
if xhtml.url.startswith(('http://', 'https://')):
code = download_http_content(urljoin(base_url, xhtml.url), user=request.user)
else:
code = download_local_file(os.path.join(showcase_utils.wgt_deployer.root_dir, url2pathname(xhtml.url)))
except Exception as e:
return build_response(request, 502, {'error_msg': _("(X)HTML code is not accessible"), 'details': "%s" % e}, WIDGET_ERROR_FORMATTERS)
else:
# Code contents comes as unicode from persistence, we need bytes
code = code.encode(charset)
if xhtml.cacheable and (xhtml.code == '' or xhtml.code_timestamp is None):
try:
xhtml.code = code.decode(charset)
except UnicodeDecodeError:
msg = _('Widget code was not encoded using the specified charset (%(charset)s as stated in the widget description file).') % {'charset': charset}
return build_response(request, 502, {'error_msg': msg}, WIDGET_ERROR_FORMATTERS)
xhtml.code_timestamp = time.time() * 1000
xhtml.save()
elif not xhtml.cacheable and xhtml.code != '':
xhtml.code = ''
xhtml.code_timestamp = None
xhtml.save()
try:
code = fix_widget_code(code, base_url, content_type, request, charset, xhtml.use_platform_style, process_requirements(widget_info['requirements']), force_base, mode)
except UnicodeDecodeError:
msg = _('Widget code was not encoded using the specified charset (%(charset)s as stated in the widget description file).') % {'charset': charset}
return build_response(request, 502, {'error_msg': msg}, WIDGET_ERROR_FORMATTERS)
except Exception as e:
msg = _('Error processing widget code')
return build_response(request, 502, {'error_msg': msg, 'details':"%s" % e}, WIDGET_ERROR_FORMATTERS)
if xhtml.cacheable:
cache_timeout = 31536000 # 1 year
cache_entry = {
'code': code,
'content_type': '%s; charset=%s' % (content_type, charset),
'timestamp': xhtml.code_timestamp,
'timeout': cache_timeout,
}
cache.set(cache_key, cache_entry, cache_timeout)
else:
cache_timeout = 0
response = HttpResponse(code, content_type='%s; charset=%s' % (content_type, charset))
patch_cache_headers(response, xhtml.code_timestamp, cache_timeout)
return response
开发者ID:GreenIDer-Donati,项目名称:wirecloud,代码行数:89,代码来源:views.py
示例19: test_empty_html
def test_empty_html(self):
initial_code = b''
final_code = self.XML_NORMALIZATION_RE.sub(b'><', fix_widget_code(initial_code, 'http://server.com/widget', 'text/html', None, 'utf-8', False, {}, False, 'classic', 'wirecloud_defaulttheme')) + b'\n'
expected_code = self.read_file('test-data/html-empty-expected.html')
self.assertEqual(final_code, expected_code)
开发者ID:rachmadagitam,项目名称:apps.Wirecloud,代码行数:6,代码来源:tests.py
注:本文中的wirecloud.platform.widget.utils.fix_widget_code函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论