當前位置: 首頁>>代碼示例>>Python>>正文


Python utils._has_surrogates方法代碼示例

本文整理匯總了Python中email.utils._has_surrogates方法的典型用法代碼示例。如果您正苦於以下問題:Python utils._has_surrogates方法的具體用法?Python utils._has_surrogates怎麽用?Python utils._has_surrogates使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在email.utils的用法示例。


在下文中一共展示了utils._has_surrogates方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _handle_text

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import _has_surrogates [as 別名]
def _handle_text(self, msg):
        payload = msg.get_payload()
        if payload is None:
            return
        if not isinstance(payload, str):
            raise TypeError('string payload expected: %s' % type(payload))
        if _has_surrogates(msg._payload):
            charset = msg.get_param('charset')
            if charset is not None:
                # XXX: This copy stuff is an ugly hack to avoid modifying the
                # existing message.
                msg = deepcopy(msg)
                del msg['content-transfer-encoding']
                msg.set_payload(payload, charset)
                payload = msg.get_payload()
                self._munge_cte = (msg['content-transfer-encoding'],
                                   msg['content-type'])
        if self._mangle_from_:
            payload = fcre.sub('>From ', payload)
        self._write_lines(payload)

    # Default body handler 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:24,代碼來源:generator.py

示例2: __new__

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import _has_surrogates [as 別名]
def __new__(cls, name, value):
        kwds = {'defects': []}
        cls.parse(value, kwds)
        if utils._has_surrogates(kwds['decoded']):
            kwds['decoded'] = utils._sanitize(kwds['decoded'])
        self = str.__new__(cls, kwds['decoded'])
        del kwds['decoded']
        self.init(name, **kwds)
        return self 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:11,代碼來源:headerregistry.py

示例3: _sanitize_header

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import _has_surrogates [as 別名]
def _sanitize_header(self, name, value):
        # If the header value contains surrogates, return a Header using
        # the unknown-8bit charset to encode the bytes as encoded words.
        if not isinstance(value, str):
            # Assume it is already a header object
            return value
        if _has_surrogates(value):
            return header.Header(value, charset=_charset.UNKNOWN8BIT,
                                 header_name=name)
        else:
            return value 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:13,代碼來源:_policybase.py

示例4: _fold

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import _has_surrogates [as 別名]
def _fold(self, name, value, sanitize):
        parts = []
        parts.append('%s: ' % name)
        if isinstance(value, str):
            if _has_surrogates(value):
                if sanitize:
                    h = header.Header(value,
                                      charset=_charset.UNKNOWN8BIT,
                                      header_name=name)
                else:
                    # If we have raw 8bit data in a byte string, we have no idea
                    # what the encoding is.  There is no safe way to split this
                    # string.  If it's ascii-subset, then we could do a normal
                    # ascii split, but if it's multibyte then we could break the
                    # string.  There's no way to know so the least harm seems to
                    # be to not split the string and risk it being too long.
                    parts.append(value)
                    h = None
            else:
                h = header.Header(value, header_name=name)
        else:
            # Assume it is a Header-like object.
            h = value
        if h is not None:
            parts.append(h.encode(linesep=self.linesep,
                                  maxlinelen=self.max_line_length))
        parts.append(self.linesep)
        return ''.join(parts) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:30,代碼來源:_policybase.py

示例5: _fold

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import _has_surrogates [as 別名]
def _fold(self, name, value, refold_binary=False):
        if hasattr(value, 'name'):
            return value.fold(policy=self)
        maxlen = self.max_line_length if self.max_line_length else float('inf')
        lines = value.splitlines()
        refold = (self.refold_source == 'all' or
                  self.refold_source == 'long' and
                    (lines and len(lines[0])+len(name)+2 > maxlen or
                     any(len(x) > maxlen for x in lines[1:])))
        if refold or refold_binary and _has_surrogates(value):
            return self.header_factory(name, ''.join(lines)).fold(policy=self)
        return name + ': ' + self.linesep.join(lines) + self.linesep 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:14,代碼來源:policy.py

示例6: _validate_xtext

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import _has_surrogates [as 別名]
def _validate_xtext(xtext):
    """If input token contains ASCII non-printables, register a defect."""

    non_printables = _non_printable_finder(xtext)
    if non_printables:
        xtext.defects.append(errors.NonPrintableDefect(non_printables))
    if utils._has_surrogates(xtext):
        xtext.defects.append(errors.UndecodableBytesDefect(
            "Non-ASCII characters found in header token")) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:11,代碼來源:_header_value_parser.py

示例7: _fold

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import _has_surrogates [as 別名]
def _fold(self, name, value, sanitize):
        parts = []
        parts.append('%s: ' % name)
        if isinstance(value, str):
            if _has_surrogates(value):
                if sanitize:
                    h = header.Header(value,
                                      charset=_charset.UNKNOWN8BIT,
                                      header_name=name)
                else:
                    # If we have raw 8bit data in a byte string, we have no idea
                    # what the encoding is.  There is no safe way to split this
                    # string.  If it's ascii-subset, then we could do a normal
                    # ascii split, but if it's multibyte then we could break the
                    # string.  There's no way to know so the least harm seems to
                    # be to not split the string and risk it being too long.
                    parts.append(value)
                    h = None
            else:
                h = header.Header(value, header_name=name)
        else:
            # Assume it is a Header-like object.
            h = value
        if h is not None:
            # The Header class interprets a value of None for maxlinelen as the
            # default value of 78, as recommended by RFC 2822.
            maxlinelen = 0
            if self.max_line_length is not None:
                maxlinelen = self.max_line_length
            parts.append(h.encode(linesep=self.linesep, maxlinelen=maxlinelen))
        parts.append(self.linesep)
        return ''.join(parts) 
開發者ID:CedricGuillemet,項目名稱:Imogen,代碼行數:34,代碼來源:_policybase.py


注:本文中的email.utils._has_surrogates方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。