• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python interfaces.IUserPreferredCharsets类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中zope.i18n.interfaces.IUserPreferredCharsets的典型用法代码示例。如果您正苦于以下问题:Python IUserPreferredCharsets类的具体用法?Python IUserPreferredCharsets怎么用?Python IUserPreferredCharsets使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了IUserPreferredCharsets类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_adapter_registered

 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', '*'])
开发者ID:eaudeweb,项目名称:naaya.i18n,代码行数:7,代码来源:test_charset_negotiator.py


示例2: processInputs

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)])
开发者ID:collective,项目名称:atreal.mailservices,代码行数:26,代码来源:overrides.py


示例3: _setPageEncoding

 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])
开发者ID:goschtl,项目名称:zope,代码行数:8,代码来源:browser.py


示例4: _decode

 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
开发者ID:goschtl,项目名称:zope,代码行数:12,代码来源:browser.py


示例5: setPageEncoding

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])
开发者ID:zopefoundation,项目名称:Zope,代码行数:13,代码来源:decode.py


示例6: getCharsetUsingRequest

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
开发者ID:minddistrict,项目名称:zope.publisher,代码行数:14,代码来源:http.py


示例7: processInputs

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)
开发者ID:Andyvs,项目名称:TrackMonthlyExpenses,代码行数:16,代码来源:decode.py


示例8: processInputs

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) ])
开发者ID:goschtl,项目名称:zope,代码行数:17,代码来源:decode.py


示例9: _decode

 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
开发者ID:zopefoundation,项目名称:zope.publisher,代码行数:19,代码来源:browser.py


示例10: processInputs

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)
开发者ID:zopefoundation,项目名称:Zope,代码行数:20,代码来源:decode.py


示例11: processInputs

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)
开发者ID:asajohnston,项目名称:Zope,代码行数:23,代码来源:decode.py


示例12: getBrowserCharset

def getBrowserCharset(request):
    """ Get charset preferred by the browser.
    """
    envadapter = IUserPreferredCharsets(request)
    charsets = envadapter.getPreferredCharsets() or ['utf-8']
    return charsets[0]
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:6,代码来源:utils.py



注:本文中的zope.i18n.interfaces.IUserPreferredCharsets类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python interfaces.IUserPreferredLanguages类代码示例发布时间:2022-05-26
下一篇:
Python format.parseNumberPattern函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap