Esempio n. 1
0
    def __init__(self, _text, _subtype='plain', _charset=None):
        """Create a text/* type MIME document.

        _text is the string for this message object.

        _subtype is the MIME sub content type, defaulting to "plain".

        _charset is the character set parameter added to the Content-Type
        header.  This defaults to "us-ascii".  Note that as a side-effect, the
        Content-Transfer-Encoding header will also be set.
        """

        # If no _charset was specified, check to see if there are non-ascii
        # characters present. If not, use 'us-ascii', otherwise use utf-8.
        # XXX: This can be removed once #7304 is fixed.
        if _charset is None:
            try:
                _text.encode('us-ascii')
                _charset = 'us-ascii'
            except UnicodeEncodeError:
                _charset = 'utf-8'

        MIMENonMultipart.__init__(self, 'text', _subtype,
                                  **{'charset': _charset})

        self.set_payload(_text, _charset)
Esempio n. 2
0
 def __init__(self, _audiodata, _subtype = None, _encoder = encoders.encode_base64, **_params):
     """Create an audio/* type MIME document.
     
     _audiodata is a string containing the raw audio data.  If this data
     can be decoded by the standard Python `sndhdr' module, then the
     subtype will be automatically included in the Content-Type header.
     Otherwise, you can specify  the specific audio subtype via the
     _subtype parameter.  If _subtype is not given, and no subtype can be
     guessed, a TypeError is raised.
     
     _encoder is a function which will perform the actual encoding for
     transport of the image data.  It takes one argument, which is this
     Image instance.  It should use get_payload() and set_payload() to
     change the payload to the encoded form.  It should also add any
     Content-Transfer-Encoding or other headers to the message as
     necessary.  The default encoding is Base64.
     
     Any additional keyword arguments are passed to the base class
     constructor, which turns them into parameters on the Content-Type
     header.
     """
     if _subtype is None:
         _subtype = _whatsnd(_audiodata)
     if _subtype is None:
         raise TypeError('Could not find audio MIME subtype')
     MIMENonMultipart.__init__(self, 'audio', _subtype, **_params)
     self.set_payload(_audiodata)
     _encoder(self)
     return
 def __init__(self, _text, _subtype="plain", _charset="utf-8"):
     if not isinstance(_charset, Charset):
         _charset = Charset(_charset)
     if isinstance(_text, unicode):
         _text = _text.encode(_charset.input_charset)
     MIMENonMultipart.__init__(self, "text", _subtype, **{"charset": _charset.input_charset})
     self.set_payload(_text, _charset)
Esempio n. 4
0
 def __init__(self, message):
     MIMENonMultipart.__init__(self, 'text', 'plain',
                               charset='utf-8')
     utf8qp = email.charset.Charset('utf-8')
     utf8qp.body_encoding = email.charset.QP
     payload = message.get_payload(decode=True)
     self.set_payload(payload, charset=utf8qp)
Esempio n. 5
0
    def __init__(self, _imagedata, _subtype=None,
                 _encoder=encoders.encode_base64, *, policy=None, **_params):
        """Create an image/* type MIME document.

        _imagedata is a string containing the raw image data.  If the data
        type can be detected (jpeg, png, gif, tiff, rgb, pbm, pgm, ppm,
        rast, xbm, bmp, webp, and exr attempted), then the subtype will be
        automatically included in the Content-Type header. Otherwise, you can
        specify the specific image subtype via the _subtype parameter.

        _encoder is a function which will perform the actual encoding for
        transport of the image data.  It takes one argument, which is this
        Image instance.  It should use get_payload() and set_payload() to
        change the payload to the encoded form.  It should also add any
        Content-Transfer-Encoding or other headers to the message as
        necessary.  The default encoding is Base64.

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        """
        _subtype = _what(_imagedata) if _subtype is None else _subtype
        if _subtype is None:
            raise TypeError('Could not guess image MIME subtype')
        MIMENonMultipart.__init__(self, 'image', _subtype, policy=policy,
                                  **_params)
        self.set_payload(_imagedata)
        _encoder(self)
Esempio n. 6
0
 def __init__(self,
              _data,
              _subtype='octet-stream',
              _encoder=encoders.encode_base64,
              **_params):
     """Create an application/* type MIME document.
     
     _data is a string containing the raw application data.
     
     _subtype is the MIME content type subtype, defaulting to
     'octet-stream'.
     
     _encoder is a function which will perform the actual encoding for
     transport of the application data, defaulting to base64 encoding.
     
     Any additional keyword arguments are passed to the base class
     constructor, which turns them into parameters on the Content-Type
     header.
     """
     if _subtype is None:
         raise TypeError('Invalid application MIME subtype')
     MIMENonMultipart.__init__(self, 'application', _subtype, **_params)
     self.set_payload(_data)
     _encoder(self)
     return
Esempio n. 7
0
    def __init__(self, _text, _subtype='plain', _charset=None):
        """Create a text/* type MIME document.

        _text is the string for this message object.

        _subtype is the MIME sub content type, defaulting to "plain".

        _charset is the character set parameter added to the Content-Type
        header.  This defaults to "us-ascii".  Note that as a side-effect, the
        Content-Transfer-Encoding header will also be set.
        """

        # If no _charset was specified, check to see if there are non-ascii
        # characters present. If not, use 'us-ascii', otherwise use utf-8.
        # XXX: This can be removed once #7304 is fixed.
        if _charset is None:
            try:
                _text.encode('us-ascii')
                _charset = 'us-ascii'
            except UnicodeEncodeError:
                _charset = 'utf-8'

        MIMENonMultipart.__init__(self, 'text', _subtype,
                                  **{'charset': _charset})

        self.set_payload(_text, _charset)
Esempio n. 8
0
 def __init__(self, _text, _subtype='plain', _charset='utf-8'):
     if not isinstance(_charset, Charset):
             _charset = Charset(_charset)
     if isinstance(_text,unicode):
         _text = _text.encode(_charset.input_charset)
     MIMENonMultipart.__init__(self, 'text', _subtype,
                                    **{'charset': _charset.input_charset})
     self.set_payload(_text, _charset)
Esempio n. 9
0
 def __init__(self, _audiodata, _subtype = None, _encoder = encoders.encode_base64, **_params):
     if _subtype is None:
         _subtype = _whatsnd(_audiodata)
     if _subtype is None:
         raise TypeError('Could not find audio MIME subtype')
     MIMENonMultipart.__init__(self, 'audio', _subtype, **_params)
     self.set_payload(_audiodata)
     _encoder(self)
Esempio n. 10
0
 def __init__(self, _imagedata, _subtype = None, _encoder = encoders.encode_base64, **_params):
     if _subtype is None:
         _subtype = imghdr.what(None, _imagedata)
     if _subtype is None:
         raise TypeError('Could not guess image MIME subtype')
     MIMENonMultipart.__init__(self, 'image', _subtype, **_params)
     self.set_payload(_imagedata)
     _encoder(self)
Esempio n. 11
0
 def __init__(self, _imagedata, _subtype = None, _encoder = encoders.encode_base64, **_params):
     if _subtype is None:
         _subtype = imghdr.what(None, _imagedata)
     if _subtype is None:
         raise TypeError('Could not guess image MIME subtype')
     MIMENonMultipart.__init__(self, 'image', _subtype, **_params)
     self.set_payload(_imagedata)
     _encoder(self)
Esempio n. 12
0
 def __init__(self, _text, _subtype='plain', _charset='utf-8'):
     if not isinstance(_charset, Charset):
         _charset = Charset(_charset)
     if isinstance(_text, unicode):
         _text = _text.encode(_charset.input_charset)
     MIMENonMultipart.__init__(self, 'text', _subtype,
                               **{'charset': _charset.input_charset})
     self.set_payload(_text, _charset)
Esempio n. 13
0
 def __init__(self,
              _data,
              _type,
              _subtype,
              _encoder=encoders.encode_base64,
              **_params):
     MIMENonMultipart.__init__(self, _type, _subtype, **_params)
     self.set_payload(_data)
     _encoder(self)
Esempio n. 14
0
    def __init__(self, text, charset='utf-8'):
        """
        Based on email.mime.text.MIMEText but adds format=flowed
        to the content type.  Also defaults to UTF-8.
        """

        MIMENonMultipart.__init__(self, 'text', 'plain',
                                  charset=charset, format='flowed')
        self.set_payload(text, charset)
Esempio n. 15
0
 def __init__(self, _text, _subtype='plain', _charset=None):
     if _charset is None:
         try:
             _text.encode('us-ascii')
             _charset = 'us-ascii'
         except UnicodeEncodeError:
             _charset = 'utf-8'
     MIMENonMultipart.__init__(self, 'text', _subtype, **{'charset': _charset})
     self.set_payload(_text, _charset)
Esempio n. 16
0
 def __init__(self, _text, _subtype='plain', _charset=None):
     if _charset is None:
         try:
             _text.encode('us-ascii')
             _charset = 'us-ascii'
         except UnicodeEncodeError:
             _charset = 'utf-8'
     MIMENonMultipart.__init__(self, 'text', _subtype,
                               **{'charset': _charset})
     self.set_payload(_text, _charset)
Esempio n. 17
0
 def __init__(self,
              _data,
              _subtype='octet-stream',
              _encoder=encoders.encode_base64,
              **_params):
     if _subtype is None:
         raise TypeError('Invalid application MIME subtype')
     MIMENonMultipart.__init__(self, 'application', _subtype, **_params)
     self.set_payload(_data)
     _encoder(self)
Esempio n. 18
0
 def __init__(self,
              _audiodata,
              _subtype=None,
              _encoder=encoders.encode_base64,
              **_params):
     if _subtype is None:
         _subtype = _whatsnd(_audiodata)
     if _subtype is None:
         raise TypeError('Could not find audio MIME subtype')
     MIMENonMultipart.__init__(self, 'audio', _subtype, **_params)
     self.set_payload(_audiodata)
     _encoder(self)
Esempio n. 19
0
    def __init__(self, text, charset='utf-8'):
        """
        Based on email.mime.text.MIMEText but adds format=flowed
        to the content type.  Also defaults to UTF-8.
        """

        MIMENonMultipart.__init__(self,
                                  'text',
                                  'plain',
                                  charset=charset,
                                  format='flowed')
        self.set_payload(text, charset)
Esempio n. 20
0
 def __init__(self, _text, _subtype = 'plain', _charset = 'us-ascii'):
     """Create a text/* type MIME document.
     
     _text is the string for this message object.
     
     _subtype is the MIME sub content type, defaulting to "plain".
     
     _charset is the character set parameter added to the Content-Type
     header.  This defaults to "us-ascii".  Note that as a side-effect, the
     Content-Transfer-Encoding header will also be set.
     """
     MIMENonMultipart.__init__(self, 'text', _subtype, **{'charset': _charset})
     self.set_payload(_text, _charset)
Esempio n. 21
0
 def __init__(self, attache_name, _attachement_data,
              _encoder=encoders.encode_base64, *, policy=None, **_params):
     """
     """
     ctype, encoding = mimetypes.guess_type(attache_name)
     if ctype is None or encoding is not None:
         ctype = 'application/octet-stream'
     _maintype, _subtype = ctype.split('/', 1)
     # if _subtype is None:
     #     raise TypeError('Could not guess image MIME subtype')
     MIMENonMultipart.__init__(self, _maintype, _subtype, policy=policy,
                               **_params)
     self.set_payload(_attachement_data)
     _encoder(self)
Esempio n. 22
0
    def __init__(self, _msg, _subtype='rfc822', *, policy=None):
        """Create a message/* type MIME document.

        _msg is a message object and must be an instance of Message, or a
        derived class of Message, otherwise a TypeError is raised.

        Optional _subtype defines the subtype of the contained message.  The
        default is "rfc822" (this is defined by the MIME standard, even though
        the term "rfc822" is technically outdated by RFC 2822).
        """
        MIMENonMultipart.__init__(self, 'message', _subtype, policy=policy)
        if not isinstance(_msg, message.Message):
            raise TypeError('Argument is not an instance of Message')
        message.Message.attach(self, _msg)
        self.set_default_type('message/rfc822')
Esempio n. 23
0
 def __init__(self, _msg, _subtype = 'rfc822'):
     """Create a message/* type MIME document.
     
     _msg is a message object and must be an instance of Message, or a
     derived class of Message, otherwise a TypeError is raised.
     
     Optional _subtype defines the subtype of the contained message.  The
     default is "rfc822" (this is defined by the MIME standard, even though
     the term "rfc822" is technically outdated by RFC 2822).
     """
     MIMENonMultipart.__init__(self, 'message', _subtype)
     if not isinstance(_msg, message.Message):
         raise TypeError('Argument is not an instance of Message')
     message.Message.attach(self, _msg)
     self.set_default_type('message/rfc822')
Esempio n. 24
0
    def __init__(self, _msg, _subtype='rfc822', *, policy=None):
        """Create a message/* type MIME document.

        _msg is a message object and must be an instance of Message, or a
        derived class of Message, otherwise a TypeError is raised.

        Optional _subtype defines the subtype of the contained message.  The
        default is "rfc822" (this is defined by the MIME standard, even though
        the term "rfc822" is technically outdated by RFC 2822).
        """
        MIMENonMultipart.__init__(self, 'message', _subtype, policy=policy)
        if not isinstance(_msg, message.Message):
            raise TypeError('Argument is not an instance of Message')
        # It's convenient to use this base class method.  We need to do it
        # this way or we'll get an exception
        message.Message.attach(self, _msg)
        # And be sure our default type is set correctly
        self.set_default_type('message/rfc822')
Esempio n. 25
0
    def __init__(self, _msg, _subtype='rfc822'):
        """Create a message/* type MIME document.

        _msg is a message object and must be an instance of Message, or a
        derived class of Message, otherwise a TypeError is raised.

        Optional _subtype defines the subtype of the contained message.  The
        default is "rfc822" (this is defined by the MIME standard, even though
        the term "rfc822" is technically outdated by RFC 2822).
        """
        MIMENonMultipart.__init__(self, 'message', _subtype)
        if not isinstance(_msg, message.Message):
            raise TypeError('Argument is not an instance of Message')
        # It's convenient to use this base class method.  We need to do it
        # this way or we'll get an exception
        message.Message.attach(self, _msg)
        # And be sure our default type is set correctly
        self.set_default_type('message/rfc822')
Esempio n. 26
0
 def __init__(self, *args, **kwargs):
     """
     Create a MIME part, JSON-serializing the given object.  The object
     may be given as the only positional argument or as keyword arguments.
     The object may be a list or a dict.  If it is a list, the assumption
     is that this is a batch and the filename reflects that.
     """
     MIMENonMultipart.__init__(self, 'application', 'json', charset='utf-8')
     try:
         obj = args[0]
     except IndexError:
         obj = kwargs
     try:
         name = obj['name']
     except TypeError:
         name = 'batch'
     self.add_header('Content-Disposition',
                     'attachment',
                     filename='{0}.json'.format(name))
     self.set_payload(json.dumps(obj))
Esempio n. 27
0
    def __init__(self, _data, _subtype='octet-stream',
                 _encoder=encoders.encode_base64, **_params):
        """Create an application/* type MIME document.

        _data is a string containing the raw applicatoin data.

        _subtype is the MIME content type subtype, defaulting to
        'octet-stream'.

        _encoder is a function which will perform the actual encoding for
        transport of the application data, defaulting to base64 encoding.

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type
        header.
        """
        if _subtype is None:
            raise TypeError('Invalid application MIME subtype')
        MIMENonMultipart.__init__(self, 'application', _subtype, **_params)
        self.set_payload(_data)
        _encoder(self)
Esempio n. 28
0
    def __init__(self, _text, _subtype='plain', _charset=None, *, policy=None):
        """Create a text/* type MIME document.

        _text is the string for this message object.

        _subtype is the MIME sub content type, defaulting to "plain".

        _charset is the character set parameter added to the Content-Type
        header.  This defaults to "us-ascii".  Note that as a side-effect, the
        Content-Transfer-Encoding header will also be set.
        """
        if _charset is None:
            try:
                _text.encode('us-ascii')
                _charset = 'us-ascii'
            except UnicodeEncodeError:
                _charset = 'utf-8'
        MIMENonMultipart.__init__(self,
                                  'text',
                                  _subtype,
                                  policy=policy,
                                  **{'charset': str(_charset)})
        self.set_payload(_text, _charset)
Esempio n. 29
0
 def __init__(self, _text, _subtype = 'plain', _charset = 'us-ascii'):
     MIMENonMultipart.__init__(self, 'text', _subtype, **{'charset': _charset})
     self.set_payload(_text, _charset)
Esempio n. 30
0
    def __init__(self, payload, charset='utf-8'):
        MIMENonMultipart.__init__(self, 'text', 'plain', charset=charset)

        utf8qp = Charset(charset)
        utf8qp.body_encoding = QP
        self.set_payload(payload, charset=utf8qp)
Esempio n. 31
0
	def __init__(self, _data, _type, _subtype, _encoder=encoders.encode_base64, **_params):
		MIMENonMultipart.__init__(self, _type, _subtype, **_params)
		self.set_payload(_data)
		_encoder(self)
Esempio n. 32
0
 def __init__(self, payload, content):
     MIMENonMultipart.__init__(self, 'text', content, charset='utf-8')
     utf8qp = charset.Charset('utf-8')
     utf8qp.body_encoding = charset.QP
     self.set_payload(payload, charset=utf8qp)
Esempio n. 33
0
File: text.py Progetto: Reve/eve
 def __init__(self, _text, _subtype="plain", _charset="us-ascii"):
     MIMENonMultipart.__init__(self, "text", _subtype, **{"charset": _charset})
     self.set_payload(_text, _charset)
Esempio n. 34
0
 def __init__(self, _data, _subtype = 'octet-stream', _encoder = encoders.encode_base64, **_params):
     if _subtype is None:
         raise TypeError('Invalid application MIME subtype')
     MIMENonMultipart.__init__(self, 'application', _subtype, **_params)
     self.set_payload(_data)
     _encoder(self)
Esempio n. 35
0
 def __init__(self, _text):
     MIMENonMultipart.__init__(self, 'text', 'plain',
                               **{'charset': self.patch_charset})
     self.set_payload(_text.encode(self.patch_charset))
     encode_7or8bit(self)
Esempio n. 36
0
 def __init__(self, _text):
     MIMENonMultipart.__init__(self, "text", "plain", **{"charset": self.patch_charset})
     self.set_payload(_text.encode(self.patch_charset))
     encode_7or8bit(self)
Esempio n. 37
0
 def __init__(self, _text, _subtype='plain', _charset='us-ascii'):
     MIMENonMultipart.__init__(self, 'text', _subtype,
                               **{'charset': _charset})
     self.set_payload(_text, _charset)
Esempio n. 38
0
 def __init__(self, _msg, _subtype = 'rfc822'):
     MIMENonMultipart.__init__(self, 'message', _subtype)
     if not isinstance(_msg, message.Message):
         raise TypeError('Argument is not an instance of Message')
     message.Message.attach(self, _msg)
     self.set_default_type('message/rfc822')
Esempio n. 39
0
 def __init__(self, _msg, _subtype = 'rfc822'):
     MIMENonMultipart.__init__(self, 'message', _subtype)
     if not isinstance(_msg, message.Message):
         raise TypeError('Argument is not an instance of Message')
     message.Message.attach(self, _msg)
     self.set_default_type('message/rfc822')
Esempio n. 40
0
 def __init__(self, _text):
     MIMENonMultipart.__init__(self, 'text', 'plain',
                               **{'charset': self.patch_charset})
     self.set_payload(_text.encode(self.patch_charset))
     encode_7or8bit(self)
Esempio n. 41
0
 def __init__(self, message):
     MIMENonMultipart.__init__(self, 'text', 'plain', charset='utf-8')
     utf8qp = email.charset.Charset('utf-8')
     utf8qp.body_encoding = email.charset.QP
     payload = message.get_payload(decode=True)
     self.set_payload(payload, charset=utf8qp)