当前位置: 首页>>代码示例>>Python>>正文


Python _encoded_words.encode方法代码示例

本文整理汇总了Python中future.backports.email._encoded_words.encode方法的典型用法代码示例。如果您正苦于以下问题:Python _encoded_words.encode方法的具体用法?Python _encoded_words.encode怎么用?Python _encoded_words.encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在future.backports.email._encoded_words的用法示例。


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

示例1: cte_encode

# 需要导入模块: from future.backports.email import _encoded_words [as 别名]
# 或者: from future.backports.email._encoded_words import encode [as 别名]
def cte_encode(self, charset, policy):
        res = []
        last_ew = None
        for part in self:
            spart = str(part)
            try:
                spart.encode('us-ascii')
                res.append(spart)
            except UnicodeEncodeError:
                if last_ew is None:
                    res.append(part.cte_encode(charset, policy))
                    last_ew = len(res)
                else:
                    tl = get_unstructured(''.join(res[last_ew:] + [spart]))
                    res.append(tl.as_encoded_word())
        return ''.join(res) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:18,代码来源:_header_value_parser.py

示例2: as_encoded_word

# 需要导入模块: from future.backports.email import _encoded_words [as 别名]
# 或者: from future.backports.email._encoded_words import encode [as 别名]
def as_encoded_word(self, charset):
        # This works only for things returned by 'parts', which include
        # the leading fws, if any, that should be used.
        res = []
        ws = self.pop_leading_fws()
        if ws:
            res.append(ws)
        trailer = self.pop(-1) if self[-1].token_type=='fws' else ''
        res.append(_ew.encode(str(self), charset))
        res.append(trailer)
        return ''.join(res) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:13,代码来源:_header_value_parser.py

示例3: _fold

# 需要导入模块: from future.backports.email import _encoded_words [as 别名]
# 或者: from future.backports.email._encoded_words import encode [as 别名]
def _fold(self, folded):
        for part in self.parts:
            tstr = str(part)
            tlen = len(tstr)
            try:
                str(part).encode('us-ascii')
            except UnicodeEncodeError:
                if any(isinstance(x, errors.UndecodableBytesDefect)
                        for x in part.all_defects):
                    charset = 'unknown-8bit'
                else:
                    # XXX: this should be a policy setting
                    charset = 'utf-8'
                tstr = part.cte_encode(charset, folded.policy)
                tlen = len(tstr)
            if folded.append_if_fits(part, tstr):
                continue
            # Peel off the leading whitespace if any and make it sticky, to
            # avoid infinite recursion.
            ws = part.pop_leading_fws()
            if ws is not None:
                # Peel off the leading whitespace and make it sticky, to
                # avoid infinite recursion.
                folded.stickyspace = str(part.pop(0))
                if folded.append_if_fits(part):
                    continue
            if part.has_fws:
                part._fold(folded)
                continue
            # There are no fold points in this one; it is too long for a single
            # line and can't be split...we just have to put it on its own line.
            folded.append(tstr)
            folded.newline() 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:35,代码来源:_header_value_parser.py

示例4: encoded

# 需要导入模块: from future.backports.email import _encoded_words [as 别名]
# 或者: from future.backports.email._encoded_words import encode [as 别名]
def encoded(self):
        if self.cte is not None:
            return self.cte
        _ew.encode(str(self), self.charset) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:6,代码来源:_header_value_parser.py

示例5: get_local_part

# 需要导入模块: from future.backports.email import _encoded_words [as 别名]
# 或者: from future.backports.email._encoded_words import encode [as 别名]
def get_local_part(value):
    """ local-part = dot-atom / quoted-string / obs-local-part

    """
    local_part = LocalPart()
    leader = None
    if value[0] in CFWS_LEADER:
        leader, value = get_cfws(value)
    if not value:
        raise errors.HeaderParseError(
            "expected local-part but found '{}'".format(value))
    try:
        token, value = get_dot_atom(value)
    except errors.HeaderParseError:
        try:
            token, value = get_word(value)
        except errors.HeaderParseError:
            if value[0] != '\\' and value[0] in PHRASE_ENDS:
                raise
            token = TokenList()
    if leader is not None:
        token[:0] = [leader]
    local_part.append(token)
    if value and (value[0]=='\\' or value[0] not in PHRASE_ENDS):
        obs_local_part, value = get_obs_local_part(str(local_part) + value)
        if obs_local_part.token_type == 'invalid-obs-local-part':
            local_part.defects.append(errors.InvalidHeaderDefect(
                "local-part is not dot-atom, quoted-string, or obs-local-part"))
        else:
            local_part.defects.append(errors.ObsoleteHeaderDefect(
                "local-part is not a dot-atom (contains CFWS)"))
        local_part[0] = obs_local_part
    try:
        local_part.value.encode('ascii')
    except UnicodeEncodeError:
        local_part.defects.append(errors.NonASCIILocalPartDefect(
                "local-part contains non-ASCII characters)"))
    return local_part, value 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:40,代码来源:_header_value_parser.py


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