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


Python uu.decode方法代码示例

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


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

示例1: decode

# 需要导入模块: import uu [as 别名]
# 或者: from uu import decode [as 别名]
def decode(input, output, encoding):
    """Decode common content-transfer-encodings (base64, quopri, uuencode)."""
    if encoding == 'base64':
        import base64
        return base64.decode(input, output)
    if encoding == 'quoted-printable':
        import quopri
        return quopri.decode(input, output)
    if encoding in ('uuencode', 'x-uuencode', 'uue', 'x-uue'):
        import uu
        return uu.decode(input, output)
    if encoding in ('7bit', '8bit'):
        return output.write(input.read())
    if encoding in decodetab:
        pipethrough(input, decodetab[encoding], output)
    else:
        raise ValueError, \
              'unknown Content-Transfer-Encoding: %s' % encoding 
开发者ID:glmcdona,项目名称:meddle,代码行数:20,代码来源:mimetools.py

示例2: test_garbage_padding

# 需要导入模块: import uu [as 别名]
# 或者: from uu import decode [as 别名]
def test_garbage_padding(self):
        # Issue #22406
        encodedtext = (
            "begin 644 file\n"
            # length 1; bits 001100 111111 111111 111111
            "\x21\x2C\x5F\x5F\x5F\n"
            "\x20\n"
            "end\n"
        )
        plaintext = "\x33"  # 00110011

        inp = cStringIO.StringIO(encodedtext)
        out = cStringIO.StringIO()
        uu.decode(inp, out, quiet=True)
        self.assertEqual(out.getvalue(), plaintext)

        import codecs
        decoded = codecs.decode(encodedtext, "uu_codec")
        self.assertEqual(decoded, plaintext) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_uu.py

示例3: test_decode

# 需要导入模块: import uu [as 别名]
# 或者: from uu import decode [as 别名]
def test_decode(self):
        f = None
        try:
            test_support.unlink(self.tmpin)
            f = open(self.tmpin, 'w')
            f.write(encodedtextwrapped % (0644, self.tmpout))
            f.close()

            f = open(self.tmpin, 'r')
            uu.decode(f)
            f.close()

            f = open(self.tmpout, 'r')
            s = f.read()
            f.close()
            self.assertEqual(s, plaintext)
            # XXX is there an xp way to verify the mode?
        finally:
            self._kill(f) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:21,代码来源:test_uu.py

示例4: test_decode_filename

# 需要导入模块: import uu [as 别名]
# 或者: from uu import decode [as 别名]
def test_decode_filename(self):
        f = None
        try:
            test_support.unlink(self.tmpin)
            f = open(self.tmpin, 'w')
            f.write(encodedtextwrapped % (0644, self.tmpout))
            f.close()

            uu.decode(self.tmpin)

            f = open(self.tmpout, 'r')
            s = f.read()
            f.close()
            self.assertEqual(s, plaintext)
        finally:
            self._kill(f) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:18,代码来源:test_uu.py

示例5: set_payload

# 需要导入模块: import uu [as 别名]
# 或者: from uu import decode [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

示例6: test_garbage_padding

# 需要导入模块: import uu [as 别名]
# 或者: from uu import decode [as 别名]
def test_garbage_padding(self):
        # Issue #22406
        encodedtext = (
            b"begin 644 file\n"
            # length 1; bits 001100 111111 111111 111111
            b"\x21\x2C\x5F\x5F\x5F\n"
            b"\x20\n"
            b"end\n"
        )
        plaintext = b"\x33"  # 00110011

        with self.subTest("uu.decode()"):
            inp = io.BytesIO(encodedtext)
            out = io.BytesIO()
            uu.decode(inp, out, quiet=True)
            self.assertEqual(out.getvalue(), plaintext)

        with self.subTest("uu_codec"):
            import codecs
            decoded = codecs.decode(encodedtext, "uu_codec")
            self.assertEqual(decoded, plaintext) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_uu.py

示例7: test_decode

# 需要导入模块: import uu [as 别名]
# 或者: from uu import decode [as 别名]
def test_decode(self):
        f = None
        try:
            support.unlink(self.tmpin)
            f = open(self.tmpin, 'wb')
            f.write(encodedtextwrapped(0o644, self.tmpout))
            f.close()

            f = open(self.tmpin, 'rb')
            uu.decode(f)
            f.close()

            f = open(self.tmpout, 'rb')
            s = f.read()
            f.close()
            self.assertEqual(s, plaintext)
            # XXX is there an xp way to verify the mode?
        finally:
            self._kill(f) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_uu.py

示例8: test_decode_filename

# 需要导入模块: import uu [as 别名]
# 或者: from uu import decode [as 别名]
def test_decode_filename(self):
        f = None
        try:
            support.unlink(self.tmpin)
            f = open(self.tmpin, 'wb')
            f.write(encodedtextwrapped(0o644, self.tmpout))
            f.close()

            uu.decode(self.tmpin)

            f = open(self.tmpout, 'rb')
            s = f.read()
            f.close()
            self.assertEqual(s, plaintext)
        finally:
            self._kill(f) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:test_uu.py

示例9: get_content_charset

# 需要导入模块: import uu [as 别名]
# 或者: from uu import decode [as 别名]
def get_content_charset(self, failobj=None):
        """Return the charset parameter of the Content-Type header.

        The returned string is always coerced to lower case.  If there is no
        Content-Type header, or if that header has no charset parameter,
        failobj is returned.
        """
        missing = object()
        charset = self.get_param('charset', missing)
        if charset is missing:
            return failobj
        if isinstance(charset, tuple):
            # RFC 2231 encoded, so decode it, and it better end up as ascii.
            pcharset = charset[0] or 'us-ascii'
            try:
                # LookupError will be raised if the charset isn't known to
                # Python.  UnicodeError will be raised if the encoded text
                # contains a character not in the charset.
                as_bytes = charset[2].encode('raw-unicode-escape')
                charset = str(as_bytes, pcharset)
            except (LookupError, UnicodeError):
                charset = charset[2]
        # charset characters must be in us-ascii range
        try:
            charset.encode('us-ascii')
        except UnicodeError:
            return failobj
        # RFC 2046, $4.1.2 says charsets are not case sensitive
        return charset.lower() 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:31,代码来源:message.py

示例10: get_content_charset

# 需要导入模块: import uu [as 别名]
# 或者: from uu import decode [as 别名]
def get_content_charset(self, failobj=None):
        """Return the charset parameter of the Content-Type header.

        The returned string is always coerced to lower case.  If there is no
        Content-Type header, or if that header has no charset parameter,
        failobj is returned.
        """
        missing = object()
        charset = self.get_param('charset', missing)
        if charset is missing:
            return failobj
        if isinstance(charset, tuple):
            # RFC 2231 encoded, so decode it, and it better end up as ascii.
            pcharset = charset[0] or 'us-ascii'
            try:
                # LookupError will be raised if the charset isn't known to
                # Python.  UnicodeError will be raised if the encoded text
                # contains a character not in the charset.
                charset = unicode(charset[2], pcharset).encode('us-ascii')
            except (LookupError, UnicodeError):
                charset = charset[2]
        # charset character must be in us-ascii range
        try:
            if isinstance(charset, str):
                charset = unicode(charset, 'us-ascii')
            charset = charset.encode('us-ascii')
        except UnicodeError:
            return failobj
        # RFC 2046, $4.1.2 says charsets are not case sensitive
        return charset.lower() 
开发者ID:glmcdona,项目名称:meddle,代码行数:32,代码来源:message.py

示例11: test_main

# 需要导入模块: import uu [as 别名]
# 或者: from uu import decode [as 别名]
def test_main():

    uu.decode(findfile('testrgb.uue'), 'test.rgb')
    uu.decode(findfile('greyrgb.uue'), 'greytest.rgb')

    # Test a 3 byte color image
    testimage('test.rgb')

    # Test a 1 byte greyscale image
    testimage('greytest.rgb')

    unlink('test.rgb')
    unlink('greytest.rgb') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_imgfile.py

示例12: test_decode

# 需要导入模块: import uu [as 别名]
# 或者: from uu import decode [as 别名]
def test_decode(self):
        inp = cStringIO.StringIO(encodedtextwrapped % (0666, "t1"))
        out = cStringIO.StringIO()
        uu.decode(inp, out)
        self.assertEqual(out.getvalue(), plaintext)
        inp = cStringIO.StringIO(
            "UUencoded files may contain many lines,\n" +
            "even some that have 'begin' in them.\n" +
            encodedtextwrapped % (0666, "t1")
        )
        out = cStringIO.StringIO()
        uu.decode(inp, out)
        self.assertEqual(out.getvalue(), plaintext) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_uu.py


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