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


Python policy.default方法代码示例

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


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

示例1: set_payload

# 需要导入模块: from email import policy [as 别名]
# 或者: from email.policy import default [as 别名]
def set_payload(self, payload, charset=None):
        """Set the payload to the given value.

        Optional charset sets the message's default character set.  See
        set_charset() for details.
        """
        if hasattr(payload, 'encode'):
            if charset is None:
                self._payload = payload
                return
            if not isinstance(charset, Charset):
                charset = Charset(charset)
            payload = payload.encode(charset.output_charset)
        if hasattr(payload, 'decode'):
            self._payload = payload.decode('ascii', 'surrogateescape')
        else:
            self._payload = payload
        if charset is not None:
            self.set_charset(charset) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:message.py

示例2: get_content_type

# 需要导入模块: from email import policy [as 别名]
# 或者: from email.policy import default [as 别名]
def get_content_type(self):
        """Return the message's content type.

        The returned string is coerced to lower case of the form
        `maintype/subtype'.  If there was no Content-Type header in the
        message, the default type as given by get_default_type() will be
        returned.  Since according to RFC 2045, messages always have a default
        type this will always return a value.

        RFC 2045 defines a message's default type to be text/plain unless it
        appears inside a multipart/digest container, in which case it would be
        message/rfc822.
        """
        missing = object()
        value = self.get('content-type', missing)
        if value is missing:
            # This should have no parameters
            return self.get_default_type()
        ctype = _splitparam(value)[0].lower()
        # RFC 2045, section 5.2 says if its invalid, use text/plain
        if ctype.count('/') != 1:
            return 'text/plain'
        return ctype 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:25,代码来源:message.py

示例3: content_type_as_value

# 需要导入模块: from email import policy [as 别名]
# 或者: from email.policy import default [as 别名]
def content_type_as_value(self,
                              source,
                              content_type,
                              maintype,
                              subtype,
                              *args):
        l = len(args)
        parmdict = args[0] if l>0 else {}
        defects =  args[1] if l>1 else []
        decoded =  args[2] if l>2 and args[2] is not DITTO else source
        header = 'Content-Type:' + ' ' if source else ''
        folded = args[3] if l>3 else header + source + '\n'
        h = self.make_header('Content-Type', source)
        self.assertEqual(h.content_type, content_type)
        self.assertEqual(h.maintype, maintype)
        self.assertEqual(h.subtype, subtype)
        self.assertEqual(h.params, parmdict)
        with self.assertRaises(TypeError):
            h.params['abc'] = 'xyz'   # params is read-only.
        self.assertDefectsEqual(h.defects, defects)
        self.assertEqual(h, decoded)
        self.assertEqual(h.fold(policy=policy.default), folded) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:test_headerregistry.py

示例4: content_disp_as_value

# 需要导入模块: from email import policy [as 别名]
# 或者: from email.policy import default [as 别名]
def content_disp_as_value(self,
                              source,
                              content_disposition,
                              *args):
        l = len(args)
        parmdict = args[0] if l>0 else {}
        defects =  args[1] if l>1 else []
        decoded =  args[2] if l>2 and args[2] is not DITTO else source
        header = 'Content-Disposition:' + ' ' if source else ''
        folded = args[3] if l>3 else header + source + '\n'
        h = self.make_header('Content-Disposition', source)
        self.assertEqual(h.content_disposition, content_disposition)
        self.assertEqual(h.params, parmdict)
        self.assertDefectsEqual(h.defects, defects)
        self.assertEqual(h, decoded)
        self.assertEqual(h.fold(policy=policy.default), folded) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:test_headerregistry.py

示例5: test_set_content_default_cm_comes_from_policy

# 需要导入模块: from email import policy [as 别名]
# 或者: from email.policy import default [as 别名]
def test_set_content_default_cm_comes_from_policy(self):
        cm = self._TestContentManager()
        p = policy.default.clone(content_manager=cm)
        m = self._str_msg('', policy=p)
        m.set_content()
        self.assertEqual(cm.msg, m)
        self.assertEqual(cm.args, ())
        self.assertEqual(cm.kw, {})
        m.set_content('foo', bar=1, k=2)
        self.assertEqual(cm.msg, m)
        self.assertEqual(cm.args, ('foo',))
        self.assertEqual(cm.kw, dict(bar=1, k=2))

    # outcome is whether xxx_method should raise ValueError error when called
    # on multipart/subtype.  Blank outcome means it depends on xxx (add
    # succeeds, make raises).  Note: 'none' means there are content-type
    # headers but payload is None...this happening in practice would be very
    # unusual, so treating it as if there were content seems reasonable.
    #    method          subtype           outcome 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_message.py

示例6: process_data

# 需要导入模块: from email import policy [as 别名]
# 或者: from email.policy import default [as 别名]
def process_data(data, browser):
    for response_part in data:
        if isinstance(response_part, tuple):
            msg = email.message_from_string(response_part[1].decode('utf-8'), policy=policy.default)
            email_subject = str(msg['subject'])
            if email_subject.find('TradingView Alert') >= 0:
                log.info('Processing: {} - {}'.format(msg['date'], email_subject))
                # get email body
                if msg.is_multipart():
                    for part in msg.walk():
                        ctype = part.get_content_type()
                        cdispo = str(part.get('Content-Disposition'))
                        # only use parts that are text/plain and not an attachment
                        if ctype == 'text/plain' and 'attachment' not in cdispo:
                            # noinspection PyTypeChecker
                            process_body(part, browser)
                            break
                else:
                    # noinspection PyTypeChecker
                    process_body(msg, browser) 
开发者ID:timelyart,项目名称:Kairos,代码行数:22,代码来源:mail.py

示例7: version_string_as_MIME_Version

# 需要导入模块: from email import policy [as 别名]
# 或者: from email.policy import default [as 别名]
def version_string_as_MIME_Version(self,
                                       source,
                                       decoded,
                                       version,
                                       major,
                                       minor,
                                       defects):
        h = self.make_header('MIME-Version', source)
        self.assertEqual(h, decoded)
        self.assertEqual(h.version, version)
        self.assertEqual(h.major, major)
        self.assertEqual(h.minor, minor)
        self.assertDefectsEqual(h.defects, defects)
        if source:
            source = ' ' + source
        self.assertEqual(h.fold(policy=policy.default),
                        'MIME-Version:' + source + '\n') 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:19,代码来源:test_headerregistry.py

示例8: get_default_type

# 需要导入模块: from email import policy [as 别名]
# 或者: from email.policy import default [as 别名]
def get_default_type(self):
        """Return the `default' content type.

        Most messages have a default content type of text/plain, except for
        messages that are subparts of multipart/digest containers.  Such
        subparts have a default content type of message/rfc822.
        """
        return self._default_type 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:message.py

示例9: set_default_type

# 需要导入模块: from email import policy [as 别名]
# 或者: from email.policy import default [as 别名]
def set_default_type(self, ctype):
        """Set the `default' content type.

        ctype should be either "text/plain" or "message/rfc822", although this
        is not enforced.  The default content type is not stored in the
        Content-Type header.
        """
        self._default_type = ctype 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:message.py

示例10: set_type

# 需要导入模块: from email import policy [as 别名]
# 或者: from email.policy import default [as 别名]
def set_type(self, type, header='Content-Type', requote=True):
        """Set the main type and subtype for the Content-Type header.

        type must be a string in the form "maintype/subtype", otherwise a
        ValueError is raised.

        This method replaces the Content-Type header, keeping all the
        parameters in place.  If requote is False, this leaves the existing
        header's quoting as is.  Otherwise, the parameters will be quoted (the
        default).

        An alternative header can be specified in the header argument.  When
        the Content-Type header is set, we'll always also add a MIME-Version
        header.
        """
        # BAW: should we be strict?
        if not type.count('/') == 1:
            raise ValueError
        # Set the Content-Type, you get a MIME-Version
        if header.lower() == 'content-type':
            del self['mime-version']
            self['MIME-Version'] = '1.0'
        if header not in self:
            self[header] = type
            return
        params = self.get_params(header=header, unquote=requote)
        del self[header]
        self[header] = type
        # Skip the first param; it's the old type.
        for p, v in params[1:]:
            self.set_param(p, v, header, requote) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:33,代码来源:message.py

示例11: string_as_value

# 需要导入模块: from email import policy [as 别名]
# 或者: from email.policy import default [as 别名]
def string_as_value(self,
                        source,
                        decoded,
                        *args):
        l = len(args)
        defects = args[0] if l>0 else []
        header = 'Subject:' + (' ' if source else '')
        folded = header + (args[1] if l>1 else source) + '\n'
        h = self.make_header('Subject', source)
        self.assertEqual(h, decoded)
        self.assertDefectsEqual(h.defects, defects)
        self.assertEqual(h.fold(policy=policy.default), folded) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_headerregistry.py

示例12: test_set_date_header_from_datetime

# 需要导入模块: from email import policy [as 别名]
# 或者: from email.policy import default [as 别名]
def test_set_date_header_from_datetime(self):
        m = Message(policy=policy.default)
        m['Date'] = self.dt
        self.assertEqual(m['Date'], self.datestring)
        self.assertEqual(m['Date'].datetime, self.dt) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_headerregistry.py

示例13: cte_as_value

# 需要导入模块: from email import policy [as 别名]
# 或者: from email.policy import default [as 别名]
def cte_as_value(self,
                     source,
                     cte,
                     *args):
        l = len(args)
        defects =  args[0] if l>0 else []
        decoded =  args[1] if l>1 and args[1] is not DITTO else source
        header = 'Content-Transfer-Encoding:' + ' ' if source else ''
        folded = args[2] if l>2 else header + source + '\n'
        h = self.make_header('Content-Transfer-Encoding', source)
        self.assertEqual(h.cte, cte)
        self.assertDefectsEqual(h.defects, defects)
        self.assertEqual(h, decoded)
        self.assertEqual(h.fold(policy=policy.default), folded) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:16,代码来源:test_headerregistry.py

示例14: test_set_from_Address_and_Group_list

# 需要导入模块: from email import policy [as 别名]
# 或者: from email.policy import default [as 别名]
def test_set_from_Address_and_Group_list(self):
        h = self.make_header('to', [Address('me', 'foo', 'example.com'),
                                    Group('bing', [Address('fiz', 'z', 'b.com'),
                                                   Address('zif', 'f', 'c.com')]),
                                    Address('you', 'bar', 'example.com')])
        self.assertEqual(h, 'me <foo@example.com>, bing: fiz <z@b.com>, '
                            'zif <f@c.com>;, you <bar@example.com>')
        self.assertEqual(h.fold(policy=policy.default.clone(max_line_length=40)),
                        'to: me <foo@example.com>,\n'
                        ' bing: fiz <z@b.com>, zif <f@c.com>;,\n'
                        ' you <bar@example.com>\n') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:13,代码来源:test_headerregistry.py

示例15: test_set_message_header_from_address

# 需要导入模块: from email import policy [as 别名]
# 或者: from email.policy import default [as 别名]
def test_set_message_header_from_address(self):
        a = Address('foo', 'bar', 'example.com')
        m = Message(policy=policy.default)
        m['To'] = a
        self.assertEqual(m['to'], 'foo <bar@example.com>')
        self.assertEqual(m['to'].addresses, (a,)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_headerregistry.py


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