File: //proc/3/root/proc/3/cwd/usr/lib/python2.4/Tools/scripts/gencodec.pyo
mς
=5Dc @ s
d Z d k Z d k Z d k Z d k Z d Z e i d Z e e e
d Z d Z d Z
d Z d Z d d Z d d
Z d Z d d d
Z d d d Z e d j oE d k Z e e e e i d qe e e e i d n d S( sG Unicode Mapping Parser and Codec Generator.
This script parses Unicode mapping files as available from the Unicode
site (ftp://ftp.unicode.org/Public/MAPPINGS/) and creates Python codec
modules from them. The codecs use the standard character mapping codec
to actually apply the mapping.
Synopsis: gencodec.py dir codec_prefix
All files in dir are scanned and those producing non-empty mappings
will be written to <codec_prefix><mapname>.py with <mapname> being the
first part of the map's filename ('a' in a.b.c.txt) converted to
lowercase with hyphens replaced by underscores.
The tool also writes marshalled versions of the mapping tables to the
same location (with .mapping extension).
Written by Marc-Andre Lemburg (mal@lemburg.com).
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
(c) Copyright Guido van Rossum, 2000.
Ni sL ((?:0x[0-9a-fA-F]+\+?)+)\s+((?:(?:0x[0-9a-fA-Z]+|<[A-Za-z]+>)\+?)*)\s*(#.+)?c C sέ | p d Sn | i d } | | d j o t | d d Sn xU | | | D]A } y t | | d | | <WqY t j
o d | | <qY XqY W| d | } | | d j o | d Sn t
| Sd S( sο Converts code combinations to either a single code integer
or a tuple of integers.
meta-codes (in angular brackets, e.g. <LR> and <RL>) are
ignored.
Empty codes or illegal ones are returned as None.
t +i i i c C s
| d j S( N( t xt None( R ( ( t, /usr/lib/python2.4/Tools/scripts/gencodec.pyt <lambda>: s N( t codesR t splitt lt lent intt ranget it
ValueErrort filtert tuple( R R R
R
R R ( ( R t
parsecodes$ s c C s’ t | d } | i } | i h }
g } t d } x t d D] } | | | <qJ Wxϋ | D]σ } | i } | p | d d j o qe n t
i | } | p qe n | i \ } } } t | } t | } | p
d } n | d } | d j o? | i | | | j o | i | qX| | f |
| <qe | | f |
| <qe Wt | t | j o) x | D] } d |
| <q|Wd |
d <n |
S( Nt ri i t #t i t IDENTITY( NR ( t opent filenamet ft readlinest linest closet enc2unit identityR
t unmappedR t linet stript mapREt matcht mt groupst enct unit commentR t removet appendR R ( R R% R# R R R! R R R$ R R R ( ( R t readmap@ sF
c C sV | d j o d Sn y t | Wn d | Sn Xd d i t d | d S( NR s 0x%04xt (s , c C s d | S( Ns 0x%04x( t t( R* ( ( R R s s t )( R* R R t joint map( R* ( ( R t hexreprk s
c C sr | d j o d Sn t o t | SnE y t | Wn t t | Sn Xt d i t t | Sd S( NR R ( R* R t numericR. R t reprt unichrR, R- ( R* ( ( R t unicoderepru s
c C s | d j o d Sn t o t | Snf y t | Wn8 | d j o t t | Sqs t t | Sn Xt d i t t | Sd S( NR i R (
R* R R/ R. R R0 t chrR1 R, R- ( R* ( ( R t keyrepr s
c
C sΌ d | g } | i d o3 | i d | d | i d d } | d =n | i d d } | i } | i | i } d } xυ | D]ν \ } } y | \ } } Wn t j
o | } d } n Xt | }
| o( | o! | d |
t | | f n | d
|
t | f | d 7} | d j oC | d j o | d n | d
| d d } | d } q q W| d j o | d n | d
| d d i | S( s| Returns Python source for the given map.
Comments are included in the source, if comments is true (default).
s_ """ Python Character Mapping Codec generated from '%s' with gencodec.py.
"""#"
import codecs
### Codec APIs
class Codec(codecs.Codec):
def encode(self,input,errors='strict'):
return codecs.charmap_encode(input,errors,encoding_map)
def decode(self,input,errors='strict'):
return codecs.charmap_decode(input,errors,decoding_map)
class StreamWriter(Codec,codecs.StreamWriter):
pass
class StreamReader(Codec,codecs.StreamReader):
pass
### encodings module API
def getregentry():
return (Codec().encode,Codec().decode,StreamReader,StreamWriter)
### Decoding Map
R s3 decoding_map = codecs.make_identity_dict(range(%d))s decoding_map.update({i s decoding_map = {i R s
%s: %s, # %ss %s: %s,i t }s })sI
### Encoding Map
encoding_map = codecs.make_encoding_map(decoding_map)
s
N( t nameR R- t has_keyR' t splitst itemst mappingst sortR t et valuet ut ct TypeErrorR4 t keyt commentsR2 R, (
R6 R- RB R? R<