本文整理匯總了Python中zope.i18n.interfaces.IUserPreferredCharsets.getPreferredCharsets方法的典型用法代碼示例。如果您正苦於以下問題:Python IUserPreferredCharsets.getPreferredCharsets方法的具體用法?Python IUserPreferredCharsets.getPreferredCharsets怎麽用?Python IUserPreferredCharsets.getPreferredCharsets使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類zope.i18n.interfaces.IUserPreferredCharsets
的用法示例。
在下文中一共展示了IUserPreferredCharsets.getPreferredCharsets方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_adapter_registered
# 需要導入模塊: from zope.i18n.interfaces import IUserPreferredCharsets [as 別名]
# 或者: from zope.i18n.interfaces.IUserPreferredCharsets import getPreferredCharsets [as 別名]
def test_adapter_registered(self):
""" test naaya.i18n's IPreferredCharset adapter is registered """
req = create_request()
adapter = IUserPreferredCharsets(req)
self.assertTrue(isinstance(adapter, NyHTTPCharsets))
self.assertEqual(adapter.getPreferredCharsets(),
['utf-8', 'iso-8859-1', '*'])
示例2: processInputs
# 需要導入模塊: from zope.i18n.interfaces import IUserPreferredCharsets [as 別名]
# 或者: from zope.i18n.interfaces.IUserPreferredCharsets import getPreferredCharsets [as 別名]
def processInputs(request, charsets=None):
""" Override Products.Five.browser.decode.processInputs
"""
if charsets is None:
envadapter = IUserPreferredCharsets(request)
charsets = envadapter.getPreferredCharsets() or ['utf-8']
for name, value in request.form.items():
if not (isCGI_NAME(name) or name.startswith('HTTP_')):
# XXX => really dirty
if name=='groups' or name=='users':
request.form[name] = value
elif isinstance(value, str):
request.form[name] = _decode(value, charsets)
elif isinstance(value, list):
request.form[name] = [_decode(val, charsets)
for val in value
if isinstance(val, str)]
elif isinstance(value, tuple):
request.form[name] = tuple([_decode(val, charsets)
for val in value
if isinstance(val, str)])
示例3: _setPageEncoding
# 需要導入模塊: from zope.i18n.interfaces import IUserPreferredCharsets [as 別名]
# 或者: from zope.i18n.interfaces.IUserPreferredCharsets import getPreferredCharsets [as 別名]
def _setPageEncoding(self):
"""Set the encoding of the form page via the Content-Type header.
ZPublisher uses the value of this header to determine how to
encode unicode data for the browser."""
envadapter = IUserPreferredCharsets(self.request)
charsets = envadapter.getPreferredCharsets() or ['utf-8']
self.request.RESPONSE.setHeader(
'Content-Type', 'text/html; charset=%s' % charsets[0])
示例4: _decode
# 需要導入模塊: from zope.i18n.interfaces import IUserPreferredCharsets [as 別名]
# 或者: from zope.i18n.interfaces.IUserPreferredCharsets import getPreferredCharsets [as 別名]
def _decode(self, text):
"""Try to decode the text using one of the available charsets."""
if self.charsets is None:
envadapter = IUserPreferredCharsets(self.request)
self.charsets = envadapter.getPreferredCharsets() or ['utf-8']
for charset in self.charsets:
try:
text = unicode(text, charset)
break
except UnicodeError:
pass
return text
示例5: setPageEncoding
# 需要導入模塊: from zope.i18n.interfaces import IUserPreferredCharsets [as 別名]
# 或者: from zope.i18n.interfaces.IUserPreferredCharsets import getPreferredCharsets [as 別名]
def setPageEncoding(request):
"""Set the encoding of the form page via the Content-Type header.
ZPublisher uses the value of this header to determine how to
encode unicode data for the browser.
"""
warn(u'setPageEncoding() is deprecated and will be removed in Zope 5.0. '
u'It is recommended to let the ZPublisher use the default_encoding. '
u'Please consider setting default-zpublisher-encoding to utf-8.',
DeprecationWarning, stacklevel=2)
envadapter = IUserPreferredCharsets(request)
charsets = envadapter.getPreferredCharsets() or ['utf-8']
request.RESPONSE.setHeader(
'Content-Type', 'text/html; charset=%s' % charsets[0])
示例6: getCharsetUsingRequest
# 需要導入模塊: from zope.i18n.interfaces import IUserPreferredCharsets [as 別名]
# 或者: from zope.i18n.interfaces.IUserPreferredCharsets import getPreferredCharsets [as 別名]
def getCharsetUsingRequest(request):
'See IHTTPResponse'
envadapter = IUserPreferredCharsets(request, None)
if envadapter is None:
return
try:
charset = envadapter.getPreferredCharsets()[0]
except IndexError:
# Exception caused by empty list! This is okay though, since the
# browser just could have sent a '*', which means we can choose
# the encoding, which we do here now.
charset = 'utf-8'
return charset
示例7: processInputs
# 需要導入模塊: from zope.i18n.interfaces import IUserPreferredCharsets [as 別名]
# 或者: from zope.i18n.interfaces.IUserPreferredCharsets import getPreferredCharsets [as 別名]
def processInputs(request, charsets=None):
"""Process the values in request.form to decode strings to unicode, using
the passed-in list of charsets. If none are passed in, look up the user's
preferred charsets. The default is to use utf-8.
"""
if charsets is None:
envadapter = IUserPreferredCharsets(request, None)
if envadapter is None:
charsets = ['utf-8']
else:
charsets = envadapter.getPreferredCharsets() or ['utf-8']
for name, value in request.form.items():
if not (name in isCGI_NAMEs or name.startswith('HTTP_')):
request.form[name] = processInputValue(value, charsets)
示例8: processInputs
# 需要導入模塊: from zope.i18n.interfaces import IUserPreferredCharsets [as 別名]
# 或者: from zope.i18n.interfaces.IUserPreferredCharsets import getPreferredCharsets [as 別名]
def processInputs(request, charsets=None):
if charsets is None:
envadapter = IUserPreferredCharsets(request)
charsets = envadapter.getPreferredCharsets() or ['utf-8']
for name, value in request.form.items():
if not (isCGI_NAME(name) or name.startswith('HTTP_')):
if isinstance(value, str):
request.form[name] = _decode(value, charsets)
elif isinstance(value, list):
request.form[name] = [ _decode(val, charsets)
for val in value
if isinstance(val, str) ]
elif isinstance(value, tuple):
request.form[name] = tuple([ _decode(val, charsets)
for val in value
if isinstance(val, str) ])
示例9: _decode
# 需要導入模塊: from zope.i18n.interfaces import IUserPreferredCharsets [as 別名]
# 或者: from zope.i18n.interfaces.IUserPreferredCharsets import getPreferredCharsets [as 別名]
def _decode(self, text):
"""Try to decode the text using one of the available charsets."""
# According to PEP-3333, in python-3, QUERY_STRING is a string,
# representing 'latin-1' encoded byte array. So, if we are in python-3
# context, encode text as 'latin-1' first, to try to decode
# resulting byte array using user-supplied charset.
if not isinstance(text, bytes):
text = text.encode('latin-1')
if self.charsets is None:
envadapter = IUserPreferredCharsets(self)
self.charsets = envadapter.getPreferredCharsets() or ['utf-8']
self.charsets = [c for c in self.charsets if c != '*']
for charset in self.charsets:
try:
text = _u(text, charset)
break
except UnicodeError:
pass
return text
示例10: processInputs
# 需要導入模塊: from zope.i18n.interfaces import IUserPreferredCharsets [as 別名]
# 或者: from zope.i18n.interfaces.IUserPreferredCharsets import getPreferredCharsets [as 別名]
def processInputs(request, charsets=None):
"""Process the values in request.form to decode binary_type to text_type,
using the passed-in list of charsets. If none are passed in, look up the
user's preferred charsets. The default is to use utf-8.
"""
warn(u'processInputs() is deprecated and will be removed in Zope 5.0. If '
u'your view implements IBrowserPage, similar processing is now '
u'executed automatically.',
DeprecationWarning, stacklevel=2)
if charsets is None:
envadapter = IUserPreferredCharsets(request, None)
if envadapter is None:
charsets = ['utf-8']
else:
charsets = envadapter.getPreferredCharsets() or ['utf-8']
for name, value in list(request.form.items()):
if not (name in isCGI_NAMEs or name.startswith('HTTP_')):
request.form[name] = processInputValue(value, charsets)
示例11: processInputs
# 需要導入模塊: from zope.i18n.interfaces import IUserPreferredCharsets [as 別名]
# 或者: from zope.i18n.interfaces.IUserPreferredCharsets import getPreferredCharsets [as 別名]
def processInputs(request, charsets=None):
"""Process the values in request.form to decode strings to unicode, using
the passed-in list of charsets. If none are passed in, look up the user's
preferred charsets. The default is to use utf-8.
"""
warn(
u"processInputs() is deprecated and will be removed in Zope 2.16. If "
u"your view implements IBrowserPage, similar processing is now "
u"executed automatically.",
DeprecationWarning,
stacklevel=2,
)
if charsets is None:
envadapter = IUserPreferredCharsets(request, None)
if envadapter is None:
charsets = ["utf-8"]
else:
charsets = envadapter.getPreferredCharsets() or ["utf-8"]
for name, value in request.form.items():
if not (name in isCGI_NAMEs or name.startswith("HTTP_")):
request.form[name] = processInputValue(value, charsets)
示例12: getBrowserCharset
# 需要導入模塊: from zope.i18n.interfaces import IUserPreferredCharsets [as 別名]
# 或者: from zope.i18n.interfaces.IUserPreferredCharsets import getPreferredCharsets [as 別名]
def getBrowserCharset(request):
""" Get charset preferred by the browser.
"""
envadapter = IUserPreferredCharsets(request)
charsets = envadapter.getPreferredCharsets() or ['utf-8']
return charsets[0]