~ibmcharmers/charms/xenial/ibm-db2/trunk

« back to all changes in this revision

Viewing changes to .tox/py35/lib/python3.5/encodings/quopri_codec.py

  • Committer: Rajith Venkata
  • Date: 2017-02-22 09:37:48 UTC
  • Revision ID: rajith.pv@in.ibm.com-20170222093748-fibtdsahuug31ra5
2ndcheckin for IBM-DB2 charm

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Codec for quoted-printable encoding.
 
2
 
 
3
This codec de/encodes from bytes to bytes.
 
4
"""
 
5
 
 
6
import codecs
 
7
import quopri
 
8
from io import BytesIO
 
9
 
 
10
def quopri_encode(input, errors='strict'):
 
11
    assert errors == 'strict'
 
12
    f = BytesIO(input)
 
13
    g = BytesIO()
 
14
    quopri.encode(f, g, quotetabs=True)
 
15
    return (g.getvalue(), len(input))
 
16
 
 
17
def quopri_decode(input, errors='strict'):
 
18
    assert errors == 'strict'
 
19
    f = BytesIO(input)
 
20
    g = BytesIO()
 
21
    quopri.decode(f, g)
 
22
    return (g.getvalue(), len(input))
 
23
 
 
24
class Codec(codecs.Codec):
 
25
    def encode(self, input, errors='strict'):
 
26
        return quopri_encode(input, errors)
 
27
    def decode(self, input, errors='strict'):
 
28
        return quopri_decode(input, errors)
 
29
 
 
30
class IncrementalEncoder(codecs.IncrementalEncoder):
 
31
    def encode(self, input, final=False):
 
32
        return quopri_encode(input, self.errors)[0]
 
33
 
 
34
class IncrementalDecoder(codecs.IncrementalDecoder):
 
35
    def decode(self, input, final=False):
 
36
        return quopri_decode(input, self.errors)[0]
 
37
 
 
38
class StreamWriter(Codec, codecs.StreamWriter):
 
39
    charbuffertype = bytes
 
40
 
 
41
class StreamReader(Codec, codecs.StreamReader):
 
42
    charbuffertype = bytes
 
43
 
 
44
# encodings module API
 
45
 
 
46
def getregentry():
 
47
    return codecs.CodecInfo(
 
48
        name='quopri',
 
49
        encode=quopri_encode,
 
50
        decode=quopri_decode,
 
51
        incrementalencoder=IncrementalEncoder,
 
52
        incrementaldecoder=IncrementalDecoder,
 
53
        streamwriter=StreamWriter,
 
54
        streamreader=StreamReader,
 
55
        _is_text_encoding=False,
 
56
    )