mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 21:02:50 +00:00
225cb4b364
It just does a 1:1 charmap conversion of quake text, purely to allow python to read arbitrary qc code.
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
# vim:ts=4:et
|
|
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'):
|
|
return codecs.charmap_decode(input,errors,decoding_table)
|
|
|
|
class IncrementalEncoder(codecs.IncrementalEncoder):
|
|
def encode(self, input, final=False):
|
|
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
|
|
|
|
class IncrementalDecoder(codecs.IncrementalDecoder):
|
|
def decode(self, input, final=False):
|
|
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
|
|
|
|
class StreamWriter(Codec,codecs.StreamWriter):
|
|
pass
|
|
|
|
class StreamReader(Codec,codecs.StreamReader):
|
|
pass
|
|
|
|
def search_function(encoding):
|
|
if encoding != "idquake":
|
|
return None
|
|
return codecs.CodecInfo(
|
|
name='idquake',
|
|
encode=Codec().encode,
|
|
decode=Codec().decode,
|
|
incrementalencoder=IncrementalEncoder,
|
|
incrementaldecoder=IncrementalDecoder,
|
|
streamreader=StreamReader,
|
|
streamwriter=StreamWriter,
|
|
)
|
|
|
|
decoding_table = [None]*256
|
|
for i in range(256):
|
|
decoding_table[i] = i
|
|
decoding_table = tuple(decoding_table)
|
|
|
|
encoding_map = codecs.make_identity_dict(range(256))
|
|
|
|
codecs.register(search_function)
|