當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。