�
��c@sAdZddkZddkZyddkTWn%ej
oZede��nXddddd d
ddd
dddddddddddddddgZdZdZ Z
dZZd Z
d!Zeid"joe
ZZe
ZneZZeZe
ZeZe
ZeZd#efd$��YZd%dNd&��YZd'efd(��YZd)efd*��YZd+efd,��YZd-efd.��YZd/efd0��YZd1efd2��YZ d3dOd4��YZ!d5dPd6��YZ"d7dd8d9d:�Z$dd8d;�Z%d<�Z&d=�Z'd>�Z(d?�Z)d@�Z*dA�Z+d8dB�Z,d8dC�Z-dD�Z.dE�Z/y@e0d8�Z1e0dF�Z2e0dG�Z3e0dH�Z4e0dI�Z5Wn1e6j
o%dZ1dZ2dZ3dZ4dZ5nXdJZ7e7oddk8Z8ne9dKjo4e%ei:dLdM�e_:e%ei;dMdL�e_;ndS(Qs� codecs -- Python Codec Registry, API and helpers.
Written by Marc-Andre Lemburg ([email protected]).
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
i�N(t*s%Failed to load the builtin codecs: %stregistertlookuptopentEncodedFiletBOMtBOM_BEtBOM_LEtBOM32_BEtBOM32_LEtBOM64_BEtBOM64_LEtBOM_UTF8t BOM_UTF16tBOM_UTF16_LEtBOM_UTF16_BEt BOM_UTF32tBOM_UTF32_LEtBOM_UTF32_BEt
strict_errorst
ignore_errorstreplace_errorstxmlcharrefreplace_errorstregister_errortlookup_errorss���t�littlet CodecInfocBs)eZdddddd�Zd�ZRS(c Csati|||||f�}||_||_||_||_||_||_||_|S(N( ttuplet__new__tnametencodetdecodetincrementalencodertincrementaldecodertstreamwritertstreamreader( tclsRR R$R#R!R"Rtself((s/sys/lib/python/codecs.pyRMs cCs)d|ii|ii|it|�fS(Ns&<%s.%s object for encoding %s at 0x%x>(t __class__t
__module__t__name__Rtid(R&((s/sys/lib/python/codecs.pyt__repr__YsN(R)R(tNoneRR+(((s/sys/lib/python/codecs.pyRKstCodeccBs&eZdZdd�Zdd�ZRS(s� Defines the interface for stateless encoders/decoders.
The .encode()/.decode() methods may use different error
handling schemes by providing the errors argument. These
string values are predefined:
'strict' - raise a ValueError error (or a subclass)
'ignore' - ignore the character and continue with the next
'replace' - replace with a suitable replacement character;
Python will use the official U+FFFD REPLACEMENT
CHARACTER for the builtin Unicode codecs on
decoding and '?' on encoding.
'xmlcharrefreplace' - Replace with the appropriate XML
character reference (only for encoding).
'backslashreplace' - Replace with backslashed escape sequences
(only for encoding).
The set of allowed values can be extended via register_error.
tstrictcCs
t�dS(s+ 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.
N(tNotImplementedError(R&tinputterrors((s/sys/lib/python/codecs.pyRrscCs
t�dS(s� 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.
N(R/(R&R0R1((s/sys/lib/python/codecs.pyR �s(R)R(t__doc__RR (((s/sys/lib/python/codecs.pyR-\stIncrementalEncodercBs/eZdZdd�Zed�Zd�ZRS(s�
An IncrementalEncoder encodes an input in multiple steps. The input can be
passed piece by piece to the encode() method. The IncrementalEncoder remembers
the state of the Encoding process between calls to encode().
R.cCs||_d|_dS(s�
Creates an IncrementalEncoder instance.
The IncrementalEncoder may use different error handling schemes by
providing the errors keyword argument. See the module docstring
for a list of possible values.
tN(R1tbuffer(R&R1((s/sys/lib/python/codecs.pyt__init__�s cCs
t�dS(sA
Encodes input and returns the resulting object.
N(R/(R&R0tfinal((s/sys/lib/python/codecs.pyR�scCsdS(s:
Resets the encoder to the initial state.
N((R&((s/sys/lib/python/codecs.pytreset�s(R)R(R2R6tFalseRR8(((s/sys/lib/python/codecs.pyR3�stBufferedIncrementalEncodercBs8eZdZdd�Zd�Zed�Zd�ZRS(s�
This subclass of IncrementalEncoder can be used as the baseclass for an
incremental encoder if the encoder must keep some of the output in a
buffer between calls to encode().
R.cCsti||�d|_dS(NR4(R3R6R5(R&R1((s/sys/lib/python/codecs.pyR6�scCs
t�dS(N(R/(R&R0R1R7((s/sys/lib/python/codecs.pyt_buffer_encode�scCs<|i|}|i||i|�\}}|||_|S(N(R5R;R1(R&R0R7tdatatresulttconsumed((s/sys/lib/python/codecs.pyR�s
cCsti|�d|_dS(NR4(R3R8R5(R&((s/sys/lib/python/codecs.pyR8�s
(R)R(R2R6R;R9RR8(((s/sys/lib/python/codecs.pyR:�s
tIncrementalDecodercBs/eZdZdd�Zed�Zd�ZRS(s�
An IncrementalDecoder decodes an input in multiple steps. The input can be
passed piece by piece to the decode() method. The IncrementalDecoder
remembers the state of the decoding process between calls to decode().
R.cCs
||_dS(s�
Creates a IncrementalDecoder instance.
The IncrementalDecoder may use different error handling schemes by
providing the errors keyword argument. See the module docstring
for a list of possible values.
N(R1(R&R1((s/sys/lib/python/codecs.pyR6�scCs
t�dS(sA
Decodes input and returns the resulting object.
N(R/(R&R0R7((s/sys/lib/python/codecs.pyR �scCsdS(s:
Resets the decoder to the initial state.
N((R&((s/sys/lib/python/codecs.pyR8�s(R)R(R2R6R9R R8(((s/sys/lib/python/codecs.pyR?�s
tBufferedIncrementalDecodercBs8eZdZdd�Zd�Zed�Zd�ZRS(s�
This subclass of IncrementalDecoder can be used as the baseclass for an
incremental decoder if the decoder must be able to handle incomplete byte
sequences.
R.cCsti||�d|_dS(NR4(R?R6R5(R&R1((s/sys/lib/python/codecs.pyR6�scCs
t�dS(N(R/(R&R0R1R7((s/sys/lib/python/codecs.pyt_buffer_decode�scCs<|i|}|i||i|�\}}|||_|S(N(R5RAR1(R&R0R7R<R=R>((s/sys/lib/python/codecs.pyR �s
cCsti|�d|_dS(NR4(R?R8R5(R&((s/sys/lib/python/codecs.pyR8s
(R)R(R2R6RAR9R R8(((s/sys/lib/python/codecs.pyR@�s
tStreamWritercBsMeZdd�Zd�Zd�Zd�Zed�Zd�Zd�Z RS(R.cCs||_||_dS(s[ Creates a StreamWriter instance.
stream must be a file-like object open for writing
(binary) data.
The StreamWriter may use different error handling
schemes by providing the errors keyword argument. These
parameters are predefined:
'strict' - raise a ValueError (or a subclass)
'ignore' - ignore the character and continue with the next
'replace'- replace with a suitable replacement character
'xmlcharrefreplace' - Replace with the appropriate XML
character reference.
'backslashreplace' - Replace with backslashed escape
sequences (only for encoding).
The set of allowed parameter values can be extended via
register_error.
N(tstreamR1(R&RCR1((s/sys/lib/python/codecs.pyR6s cCs/|i||i�\}}|ii|�dS(s> Writes the object's contents encoded to self.stream.
N(RR1RCtwrite(R&tobjectR<R>((s/sys/lib/python/codecs.pyRD+scCs|idi|��dS(s[ Writes the concatenated list of strings to the stream
using .write().
R4N(RDtjoin(R&tlist((s/sys/lib/python/codecs.pyt
writelines2scCsdS(s5 Flushes and resets the codec buffers used for keeping state.
Calling this method should ensure that the data on the
output is put into a clean state, that allows appending
of new fresh data without having to rescan the whole
stream to recover state.
N((R&((s/sys/lib/python/codecs.pyR89s
cCs||i|�S(s? Inherit all other methods from the underlying stream.
(RC(R&Rtgetattr((s/sys/lib/python/codecs.pyt__getattr__EscCs|S(N((R&((s/sys/lib/python/codecs.pyt __enter__LscCs|ii�dS(N(RCtclose(R&ttypetvaluettb((s/sys/lib/python/codecs.pyt__exit__Os(
R)R(R6RDRHR8RIRJRKRP(((s/sys/lib/python/codecs.pyRBs
tStreamReadercBs�eZdd�Zdd�Zdded�Zded�Zded�Z d�Z
dd �Zd
�Zd�Z
ed�Zd
�Zd�ZRS(R.cCs1||_||_d|_d|_d|_dS(s[ Creates a StreamReader instance.
stream must be a file-like object open for reading
(binary) data.
The StreamReader may use different error handling
schemes by providing the errors keyword argument. These
parameters are predefined:
'strict' - raise a ValueError (or a subclass)
'ignore' - ignore the character and continue with the next
'replace'- replace with a suitable replacement character;
The set of allowed parameter values can be extended via
register_error.
R4N(RCR1t
bytebuffert
charbufferR,t
linebuffer(R&RCR1((s/sys/lib/python/codecs.pyR6Vs
cCs
t�dS(N(R/(R&R0R1((s/sys/lib/python/codecs.pyR psi�cCs�|io"di|i�|_d|_nxjtob|djo?|djo|ioPq~q�t|i�|joPq�nt|i�|joPn|djo|ii�}n|ii|�}|i|}y|i ||i
�\}}Wnntj
ob}|oO|i ||i |i
�\}}|i
t�} t| �djo�qgql�nX|||_|i|7_|pPq/q/W|djo|i}
d|_n|i| }
|i||_|
S(s Decodes data from the stream self.stream and returns the
resulting object.
chars indicates the number of characters to read from the
stream. read() will never return more than chars
characters, but it might return less, if there are not enough
characters available.
size indicates the approximate maximum number of bytes to
read from the stream for decoding purposes. The decoder
can modify this setting as appropriate. The default value
-1 indicates to read and decode as much as possible. size
is intended to prevent having to decode huge files in one
step.
If firstline is true, and a UnicodeDecodeError happens
after the first line terminator in the input only the first line
will be returned, the rest of the input will be kept until the
next call to read().
The method should use a greedy read strategy meaning that
it should read as much data as is allowed within the
definition of the encoding and the given size, e.g. if
optional encoding endings or state markers are available
on the stream, these should be read too.
R4iiN(RTRFRSR,tTruetlenRCtreadRRR R1tUnicodeDecodeErrortstartt
splitlines(R&tsizetcharst firstlinetnewdataR<tnewcharstdecodedbytestexctlinesR=((s/sys/lib/python/codecs.pyRWssF
"
c Csm|iop|id}|id=t|i�djo|id|_d|_n|p|it�d}n|Sn|pd}d}x�to�|i|dt�}|o4|id�o ||idddd�7}q�n||7}|it�}|ot|�djo�|d}|d=t|�djo)|d c|i7<||_d|_n|d|i|_|p|it�d}nPn|d}|dit�d}||jo9di |d�|i|_|o
|}n|}Pq n|p
|dj o+|o|o|it�d}nPn|d
jo|d9}q�q�W|S(
s� Read one line from the input stream and return the
decoded data.
size, if given, is passed as size argument to the
read() method.
iiiHR4R]s
R[R\i�i@iN(
RTRVRSR,RZR9RURWtendswithRF( R&R[tkeependstlinetreadsizeR<Rbtline0withendtline0withoutend((s/sys/lib/python/codecs.pytreadline�sZ
$
cCs|i�}|i|�S(sZ Read all lines available on the input stream
and return them as list of lines.
Line breaks are implemented using the codec's decoder
method and are included in the list entries.
sizehint, if given, is ignored since there is no efficient
way to finding the true end-of-line.
(RWRZ(R&tsizehintRdR<((s/sys/lib/python/codecs.pyt readlinesscCsd|_d|_d|_dS(s� Resets the codec buffers used for keeping state.
Note that no stream repositioning should take place.
This method is primarily intended to be able to recover
from decoding errors.
R4uN(RRRSR,RT(R&((s/sys/lib/python/codecs.pyR8s icCs!|i�|ii||�dS(sp Set the input stream's current position.
Resets the codec buffers used for keeping state.
N(R8RCtseek(R&toffsettwhence((s/sys/lib/python/codecs.pyRl's
cCs%|i�}|o|Snt�dS(s4 Return the next decoded line from the input stream.N(Rit
StopIteration(R&Re((s/sys/lib/python/codecs.pytnext/scCs|S(N((R&((s/sys/lib/python/codecs.pyt__iter__7scCs||i|�S(s? Inherit all other methods from the underlying stream.
(RC(R&RRI((s/sys/lib/python/codecs.pyRJ:scCs|S(N((R&((s/sys/lib/python/codecs.pyRKAscCs|ii�dS(N(RCRL(R&RMRNRO((s/sys/lib/python/codecs.pyRPDsN(R)R(R6R R9RWR,RURiRkR8RlRpRqRIRJRKRP(((s/sys/lib/python/codecs.pyRQTsOI
tStreamReaderWritercBs�eZdZdZdd�Zdd�Zdd�Zdd�Zd�Z d �Z
d
�Zd�Zd�Z
ed
�Zd�Zd�ZRS(s StreamReaderWriter instances allow wrapping streams which
work in both read and write modes.
The design is such that one can use the factory functions
returned by the codec.lookup() function to construct the
instance.
tunknownR.cCs:||_|||�|_|||�|_||_dS(sR Creates a StreamReaderWriter instance.
stream must be a Stream-like object.
Reader, Writer must be factory functions or classes
providing the StreamReader, StreamWriter interface resp.
Error handling is done in the same way as defined for the
StreamWriter/Readers.
N(RCtreadertwriterR1(R&RCtReadertWriterR1((s/sys/lib/python/codecs.pyR6Vs
i�cCs|ii|�S(N(RtRW(R&R[((s/sys/lib/python/codecs.pyRWhscCs|ii|�S(N(RtRi(R&R[((s/sys/lib/python/codecs.pyRilscCs|ii|�S(N(RtRk(R&Rj((s/sys/lib/python/codecs.pyRkpscCs
|ii�S(s4 Return the next decoded line from the input stream.(RtRp(R&((s/sys/lib/python/codecs.pyRptscCs|S(N((R&((s/sys/lib/python/codecs.pyRqyscCs|ii|�S(N(RuRD(R&R<((s/sys/lib/python/codecs.pyRD|scCs|ii|�S(N(RuRH(R&RG((s/sys/lib/python/codecs.pyRH�scCs|ii�|ii�dS(N(RtR8Ru(R&((s/sys/lib/python/codecs.pyR8�s
cCs||i|�S(s? Inherit all other methods from the underlying stream.
(RC(R&RRI((s/sys/lib/python/codecs.pyRJ�scCs|S(N((R&((s/sys/lib/python/codecs.pyRK�scCs|ii�dS(N(RCRL(R&RMRNRO((s/sys/lib/python/codecs.pyRP�sN(R)R(R2tencodingR6RWR,RiRkRpRqRDRHR8RIRJRKRP(((s/sys/lib/python/codecs.pyRrIs t
StreamRecodercBs�eZdZdZdZdd�Zdd�Zdd�Zdd�Z d�Z
d �Zd
�Zd�Z
d�Zed
�Zd�Zd�ZRS(sE StreamRecoder instances provide a frontend - backend
view of encoding data.
They use the complete set of APIs returned by the
codecs.lookup() function to implement their task.
Data written to the stream is first decoded into an
intermediate format (which is dependent on the given codec
combination) and then written to the stream using an instance
of the provided Writer class.
In the other direction, data is read from the stream using a
Reader instance and then return encoded data to the caller.
RsR.cCsL||_||_||_|||�|_|||�|_||_dS(s� Creates a StreamRecoder instance which implements a two-way
conversion: encode and decode work on the frontend (the
input to .read() and output of .write()) while
Reader and Writer work on the backend (reading and
writing to the stream).
You can use these objects to do transparent direct
recodings from e.g. latin-1 to utf-8 and back.
stream must be a file-like object.
encode, decode must adhere to the Codec interface, Reader,
Writer must be factory functions or classes providing the
StreamReader, StreamWriter interface resp.
encode and decode are needed for the frontend translation,
Reader and Writer for the backend translation. Unicode is
used as intermediate encoding.
Error handling is done in the same way as defined for the
StreamWriter/Readers.
N(RCRR RtRuR1(R&RCRR RvRwR1((s/sys/lib/python/codecs.pyR6�s i�cCs1|ii|�}|i||i�\}}|S(N(RtRWRR1(R&R[R<tbytesencoded((s/sys/lib/python/codecs.pyRW�scCsQ|djo|ii�}n|ii|�}|i||i�\}}|S(N(R,RtRiRR1(R&R[R<Rz((s/sys/lib/python/codecs.pyRi�s
cCs7|ii�}|i||i�\}}|id�S(Ni(RtRWRR1RZ(R&RjR<Rz((s/sys/lib/python/codecs.pyRk�scCs.|ii�}|i||i�\}}|S(s4 Return the next decoded line from the input stream.(RtRpRR1(R&R<Rz((s/sys/lib/python/codecs.pyRp�scCs|S(N((R&((s/sys/lib/python/codecs.pyRq�scCs+|i||i�\}}|ii|�S(N(R R1RuRD(R&R<tbytesdecoded((s/sys/lib/python/codecs.pyRD�scCs:di|�}|i||i�\}}|ii|�S(NR4(RFR R1RuRD(R&RGR<R{((s/sys/lib/python/codecs.pyRH�scCs|ii�|ii�dS(N(RtR8Ru(R&((s/sys/lib/python/codecs.pyR8�s
cCs||i|�S(s? Inherit all other methods from the underlying stream.
(RC(R&RRI((s/sys/lib/python/codecs.pyRJ�scCs|S(N((R&((s/sys/lib/python/codecs.pyRKscCs|ii�dS(N(RCRL(R&RMRNRO((s/sys/lib/python/codecs.pyRP sN(R)R(R2t
data_encodingt
file_encodingR6RWR,RiRkRpRqRDRHR8RIRJRKRP(((s/sys/lib/python/codecs.pyRy�s trbR.icCs�|dj od|jo|d}nti|||�}|djo|Snt|�}t||i|i|�}||_|S(s� Open an encoded file using the given mode and return
a wrapped version providing transparent encoding/decoding.
Note: The wrapped version will only accept the object format
defined by the codecs, i.e. Unicode objects for most builtin
codecs. Output is also codec dependent and will usually be
Unicode as well.
Files are always opened in binary mode, even if no binary mode
was specified. This is done to avoid data loss due to encodings
using 8-bit values. The default file mode is 'rb' meaning to
open the file in binary read mode.
encoding specifies the encoding which is to be used for the
file.
errors may be given to define the error handling. It defaults
to 'strict' which causes ValueErrors to be raised in case an
encoding error occurs.
buffering has the same meaning as for the builtin open() API.
It defaults to line buffered.
The returned wrapped file object provides an extra attribute
.encoding which allows querying the used encoding. This
attribute is only available if an encoding was specified as
parameter.
tbN(R,t__builtin__RRRrR$R#Rx(tfilenametmodeRxR1t bufferingtfiletinfotsrw((s/sys/lib/python/codecs.pyRs
cCsl|djo
|}nt|�}t|�}t||i|i|i|i|�}||_||_|S(s� Return a wrapped version of file which provides transparent
encoding translation.
Strings written to the wrapped file are interpreted according
to the given data_encoding and then written to the original
file as string using file_encoding. The intermediate encoding
will usually be Unicode but depends on the specified codecs.
Strings are read from the file using file_encoding and then
passed back to the caller as string using data_encoding.
If file_encoding is not given, it defaults to data_encoding.
errors may be given to define the error handling. It defaults
to 'strict' which causes ValueErrors to be raised in case an
encoding error occurs.
The returned wrapped file object provides two extra attributes
.data_encoding and .file_encoding which reflect the given
parameters of the same name. The attributes can be used for
introspection by Python programs.
N( R,RRyRR R$R#R|R}(R�R|R}R1t data_infot file_infotsr((s/sys/lib/python/codecs.pyR:s
cCs
t|�iS(s� Lookup up the codec for the given encoding and return
its encoder function.
Raises a LookupError in case the encoding cannot be found.
(RR(Rx((s/sys/lib/python/codecs.pyt
getencoder`scCs
t|�iS(s� Lookup up the codec for the given encoding and return
its decoder function.
Raises a LookupError in case the encoding cannot be found.
(RR (Rx((s/sys/lib/python/codecs.pyt
getdecoderjscCs0t|�i}|djot|��n|S(s� Lookup up the codec for the given encoding and return
its IncrementalEncoder class or factory function.
Raises a LookupError in case the encoding cannot be found
or the codecs doesn't provide an incremental encoder.
N(RR!R,tLookupError(Rxtencoder((s/sys/lib/python/codecs.pytgetincrementalencoderts
cCs0t|�i}|djot|��n|S(s� Lookup up the codec for the given encoding and return
its IncrementalDecoder class or factory function.
Raises a LookupError in case the encoding cannot be found
or the codecs doesn't provide an incremental decoder.
N(RR"R,R�(Rxtdecoder((s/sys/lib/python/codecs.pytgetincrementaldecoder�s
cCs
t|�iS(s� Lookup up the codec for the given encoding and return
its StreamReader class or factory function.
Raises a LookupError in case the encoding cannot be found.
(RR$(Rx((s/sys/lib/python/codecs.pyt getreader�scCs
t|�iS(s� Lookup up the codec for the given encoding and return
its StreamWriter class or factory function.
Raises a LookupError in case the encoding cannot be found.
(RR#(Rx((s/sys/lib/python/codecs.pyt getwriter�sckskt|�||�}x-|D]%}|i|�}|o |VqqW|idt�}|o |VndS(s�
Encoding iterator.
Encodes the input strings from the iterator using a IncrementalEncoder.
errors and kwargs are passed through to the IncrementalEncoder
constructor.
R4N(R�RRU(titeratorRxR1tkwargsR�R0toutput((s/sys/lib/python/codecs.pyt
iterencode�s
ckskt|�||�}x-|D]%}|i|�}|o |VqqW|idt�}|o |VndS(s�
Decoding iterator.
Decodes the input strings from the iterator using a IncrementalDecoder.
errors and kwargs are passed through to the IncrementalDecoder
constructor.
R4N(R�R RU(R�RxR1R�R�R0R�((s/sys/lib/python/codecs.pyt
iterdecode�s
cCs%h}x|D]}|||<q
W|S(s� make_identity_dict(rng) -> dict
Return a dictionary where elements of the rng sequence are
mapped to themselves.
((trngtresti((s/sys/lib/python/codecs.pytmake_identity_dict�s
cCsLh}x?|i�D]1\}}||jo|||<qd||<qW|S(s� Creates an encoding map from a decoding map.
If a target mapping in the decoding map occurs multiple
times, then that target is mapped to None (undefined mapping),
causing an exception when encountered by the charmap codec
during translation.
One example where this happens is cp875.py which decodes
multiple character to \u001a.
N(titemsR,(tdecoding_maptmtktv((s/sys/lib/python/codecs.pytmake_encoding_map�s
tignoretreplacetxmlcharrefreplacetbackslashreplaceit__main__slatin-1sutf-8((((<R2R�tsyst_codecstImportErrortwhytSystemErrort__all__RRRRRRRt byteorderRR
RR RRR
RRR-RER3R:R?R@RBRQRrRyR,RRR�R�R�R�R�R�R�R�R�R�RRRRRtbackslashreplace_errorsR�t_falset encodingsR)tstdouttstdin(((s/sys/lib/python/codecs.pys<module>s�
@"D�t,&
|