Back to index

python3.2  3.2.2
Classes | Functions
encodings.uu_codec Namespace Reference

Classes

class  Codec
class  IncrementalEncoder
class  IncrementalDecoder
class  StreamWriter
class  StreamReader

Functions

def uu_encode
 Codec APIs.
def uu_decode
def getregentry

Detailed Description

Python 'uu_codec' Codec - UU content transfer encoding.

This codec de/encodes from bytes to bytes and is therefore usable with
bytes.transform() and bytes.untransform().

Written by Marc-Andre Lemburg (mal@lemburg.com). Some details were
adapted from uu.py which was written by Lance Ellinghouse and
modified by Jack Jansen and Fredrik Lundh.

Function Documentation

Definition at line 90 of file uu_codec.py.

00090 
00091 def getregentry():
00092     return codecs.CodecInfo(
00093         name='uu',
00094         encode=uu_encode,
00095         decode=uu_decode,
00096         incrementalencoder=IncrementalEncoder,
00097         incrementaldecoder=IncrementalDecoder,
00098         streamreader=StreamReader,
00099         streamwriter=StreamWriter,
00100     )
def encodings.uu_codec.uu_decode (   input,
  errors = 'strict' 
)

Definition at line 34 of file uu_codec.py.

00034 
00035 def uu_decode(input, errors='strict'):
00036     assert errors == 'strict'
00037     infile = BytesIO(input)
00038     outfile = BytesIO()
00039     readline = infile.readline
00040     write = outfile.write
00041 
00042     # Find start of encoded data
00043     while 1:
00044         s = readline()
00045         if not s:
00046             raise ValueError('Missing "begin" line in input data')
00047         if s[:5] == b'begin':
00048             break
00049 
00050     # Decode
00051     while True:
00052         s = readline()
00053         if not s or s == b'end\n':
00054             break
00055         try:
00056             data = binascii.a2b_uu(s)
00057         except binascii.Error as v:
00058             # Workaround for broken uuencoders by /Fredrik Lundh
00059             nbytes = (((ord(s[0])-32) & 63) * 4 + 5) / 3
00060             data = binascii.a2b_uu(s[:nbytes])
00061             #sys.stderr.write("Warning: %s\n" % str(v))
00062         write(data)
00063     if not s:
00064         raise ValueError('Truncated input data')
00065 
00066     return (outfile.getvalue(), len(input))

Here is the call graph for this function:

Here is the caller graph for this function:

def encodings.uu_codec.uu_encode (   input,
  errors = 'strict',
  filename = '<data>',
  mode = 0o666 
)

Codec APIs.

Definition at line 17 of file uu_codec.py.

00017 
00018 def uu_encode(input, errors='strict', filename='<data>', mode=0o666):
00019     assert errors == 'strict'
00020     infile = BytesIO(input)
00021     outfile = BytesIO()
00022     read = infile.read
00023     write = outfile.write
00024 
00025     # Encode
00026     write(('begin %o %s\n' % (mode & 0o777, filename)).encode('ascii'))
00027     chunk = read(45)
00028     while chunk:
00029         write(binascii.b2a_uu(chunk))
00030         chunk = read(45)
00031     write(b' \nend\n')
00032 
00033     return (outfile.getvalue(), len(input))

Here is the call graph for this function:

Here is the caller graph for this function: