diff options
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/unicode/Makefile | 2 | ||||
-rw-r--r-- | Tools/unicode/gencodec.py | 51 | ||||
-rwxr-xr-x | Tools/webchecker/webchecker.py | 4 |
3 files changed, 29 insertions, 28 deletions
diff --git a/Tools/unicode/Makefile b/Tools/unicode/Makefile index fbd3557..35744ad 100644 --- a/Tools/unicode/Makefile +++ b/Tools/unicode/Makefile @@ -78,7 +78,7 @@ cjk: build/ ### Cleanup clean: - $(RM) build/* + $(RM) -f build/* distclean: clean $(RM) -rf MAPPINGS/ diff --git a/Tools/unicode/gencodec.py b/Tools/unicode/gencodec.py index 0aef207..dabcd72 100644 --- a/Tools/unicode/gencodec.py +++ b/Tools/unicode/gencodec.py @@ -270,6 +270,11 @@ def codegen(name, map, encodingname, comments=1): comments=comments, precisions=(4, 2)) + if decoding_table_code: + suffix = 'table' + else: + suffix = 'map' + l = [ '''\ """ Python Character Mapping Codec %s generated from '%s' with gencodec.py. @@ -283,30 +288,20 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) - - def decode(self,input,errors='strict'):''' % (encodingname, name) - ] - if decoding_table_code: - l.append('''\ - return codecs.charmap_decode(input,errors,decoding_table)''') - else: - l.append('''\ - return codecs.charmap_decode(input,errors,decoding_map)''') + return codecs.charmap_encode(input,errors,encoding_%s) - l.append(''' + def decode(self,input,errors='strict'): + return codecs.charmap_decode(input,errors,decoding_%s) +''' % (encodingname, name, suffix, suffix)] + l.append('''\ class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_%s)[0] class IncrementalDecoder(codecs.IncrementalDecoder): - def decode(self, input, final=False):''') - if decoding_table_code: - l.append('''\ - return codecs.charmap_decode(input,self.errors,decoding_table)[0]''') - else: - l.append('''\ - return codecs.charmap_decode(input,self.errors,decoding_map)[0]''') + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_%s)[0]''' % + (suffix, suffix)) l.append(''' class StreamWriter(Codec,codecs.StreamWriter): @@ -319,13 +314,13 @@ class StreamReader(Codec,codecs.StreamReader): def getregentry(): return codecs.CodecInfo( - Codec().encode, - Codec().decode, name=%r, - streamwriter=StreamWriter, - streamreader=StreamReader, + encode=Codec().encode, + decode=Codec().decode, incrementalencoder=IncrementalEncoder, incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, ) ''' % encodingname.replace('_', '-')) @@ -342,10 +337,16 @@ def getregentry(): l.extend(decoding_table_code) # Add encoding map - l.append(''' + if decoding_table_code: + l.append(''' +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) +''') + else: + l.append(''' ### Encoding Map ''') - l.extend(encoding_map_code) + l.extend(encoding_map_code) # Final new-line l.append('') diff --git a/Tools/webchecker/webchecker.py b/Tools/webchecker/webchecker.py index 990159c..7199da8 100755 --- a/Tools/webchecker/webchecker.py +++ b/Tools/webchecker/webchecker.py @@ -784,7 +784,7 @@ class MyHTMLParser(sgmllib.SGMLParser): self.url = url sgmllib.SGMLParser.__init__(self) - def check_name_id( self, attributes ): + def check_name_id(self, attributes): """ Check the name or id attributes on an element. """ # We must rescue the NAME or id (name is deprecated in XHTML) @@ -799,7 +799,7 @@ class MyHTMLParser(sgmllib.SGMLParser): else: self.names.append(value) break - def unknown_starttag( self, tag, attributes ): + def unknown_starttag(self, tag, attributes): """ In XHTML, you can have id attributes on any element. """ self.check_name_id(attributes) |