Back to index

python3.2  3.2.2
Public Member Functions
encodings.idna.Codec Class Reference

Codec APIs. More...

Inheritance diagram for encodings.idna.Codec:
Inheritance graph
[legend]
Collaboration diagram for encodings.idna.Codec:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def encode
def decode

Detailed Description

Codec APIs.

Definition at line 146 of file idna.py.


Member Function Documentation

def encodings.idna.Codec.decode (   self,
  input,
  errors = 'strict' 
)
Decodes the object input and returns a tuple (output
    object, length consumed).

    input must be an object which provides the bf_getreadbuf
    buffer slot. Python strings, buffer objects and memory
    mapped files are examples of objects providing this slot.

    errors defines the error handling to apply. It defaults to
    'strict' handling.

    The method may not store state in the Codec instance. Use
    StreamCodec for codecs which have to keep state in order to
    make encoding/decoding efficient.

    The decoder must be able to handle zero length input and
    return an empty object of the output object type in this
    situation.

Reimplemented from codecs.Codec.

Definition at line 170 of file idna.py.

00170 
00171     def decode(self, input, errors='strict'):
00172 
00173         if errors != 'strict':
00174             raise UnicodeError("Unsupported error handling "+errors)
00175 
00176         if not input:
00177             return "", 0
00178 
00179         # IDNA allows decoding to operate on Unicode strings, too.
00180         if not isinstance(input, bytes):
00181             # XXX obviously wrong, see #3232
00182             input = bytes(input)
00183         labels = input.split(b".")
00184 
00185         if labels and len(labels[-1]) == 0:
00186             trailing_dot = '.'
00187             del labels[-1]
00188         else:
00189             trailing_dot = ''
00190 
00191         result = []
00192         for label in labels:
00193             result.append(ToUnicode(label))
00194 
00195         return ".".join(result)+trailing_dot, len(input)

Here is the call graph for this function:

Here is the caller graph for this function:

def encodings.idna.Codec.encode (   self,
  input,
  errors = 'strict' 
)
Encodes the object input and returns a tuple (output
    object, length consumed).

    errors defines the error handling to apply. It defaults to
    'strict' handling.

    The method may not store state in the Codec instance. Use
    StreamCodec for codecs which have to keep state in order to
    make encoding/decoding efficient.

    The encoder must be able to handle zero length input and
    return an empty object of the output object type in this
    situation.

Reimplemented from codecs.Codec.

Definition at line 147 of file idna.py.

00147 
00148     def encode(self, input, errors='strict'):
00149 
00150         if errors != 'strict':
00151             # IDNA is quite clear that implementations must be strict
00152             raise UnicodeError("unsupported error handling "+errors)
00153 
00154         if not input:
00155             return b'', 0
00156 
00157         result = bytearray()
00158         labels = dots.split(input)
00159         if labels and not labels[-1]:
00160             trailing_dot = b'.'
00161             del labels[-1]
00162         else:
00163             trailing_dot = b''
00164         for label in labels:
00165             if result:
00166                 # Join with U+002E
00167                 result.extend(b'.')
00168             result.extend(ToASCII(label))
00169         return bytes(result+trailing_dot), len(input)

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file: