perky 03/01/12 15:22:32
Modified: korean mac_korean.py
Log:
Remove ksc5601, uhc pure python mappings.
We save 1000KB now! :)
Revision Changes Path
1.2 +12 -48 KoreanCodecs/korean/mac_korean.py
Index: mac_korean.py
===================================================================
RCS file: /cvsroot/koco/KoreanCodecs/korean/mac_korean.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- mac_korean.py 12 Jan 2003 23:04:56 -0000 1.1
+++ mac_korean.py 12 Jan 2003 23:22:32 -0000 1.2
@@ -17,15 +17,15 @@
# along with KoreanCodecs; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
-# $Id: mac_korean.py,v 1.1 2003/01/12 23:04:56 perky Exp $
+# $Id: mac_korean.py,v 1.2 2003/01/12 23:22:32 perky Exp $
#
import codecs
-from korean.mappings import ksc5601_hangul, appleextension
-encmap_hangul, decmap_hangul = ksc5601_hangul.encoding_map, ksc5601_hangul.decoding_map
-encmap_apple, decmap_apple = appleextension.encoding_map, appleextension.decoding_map
-encmap_ideo, decmap_ideo = {}, {}
-encmap_misc, decmap_misc = {}, {}
+from korean.mappings import appleextension
+encmap_apple = appleextension.encoding_map
+decmap_apple = appleextension.decoding_map
+
+KSC5601_CODEC = 'korean.euc-kr'
class Codec(codecs.Codec):
@@ -55,30 +55,10 @@
if c < u'\u0080':
buffer.append(c.encode("ascii", errors))
- elif encmap_hangul.has_key(c):
- buffer.append(encmap_hangul[c])
elif encmap_apple.has_key(c):
buffer.append(encmap_apple[c])
else:
- if not encmap_misc:
- from korean.mappings import ksc5601_misc
- encmap_misc = ksc5601_misc.encoding_map
- if encmap_misc.has_key(c):
- buffer.append(encmap_misc[c])
- continue
-
- if not encmap_ideo:
- from korean.mappings import ksc5601_ideograph
- encmap_ideo = ksc5601_ideograph.encoding_map
- if encmap_ideo.has_key(c):
- buffer.append(encmap_ideo[c])
- continue
-
- if errors == 'replace':
- buffer.append('\xa1\xa1')
- elif errors == 'strict':
- raise UnicodeError, ("cannot map "
- "\\u%04x to MacKorean") % ord(c)
+ buffer.append(c.encode(KSC5601_CODEC, errors))
return (''.join(buffer), len(data))
@@ -113,28 +93,11 @@
c = data[p:p+2]
p += 2
if len(c) == 2:
- if decmap_hangul.has_key(c):
- buffer.append(decmap_hangul[c])
- continue
- elif decmap_apple.has_key(c):
+ if decmap_apple.has_key(c):
buffer.append(decmap_apple[c])
- continue
-
- if not decmap_misc:
- from korean.mappings import ksc5601_misc
- decmap_misc = ksc5601_misc.decoding_map
- if decmap_misc.has_key(c):
- buffer.append(decmap_misc[c])
- continue
-
- if not decmap_ideo:
- from korean.mappings import ksc5601_ideograph
- decmap_ideo = ksc5601_ideograph.decoding_map
- if decmap_ideo.has_key(c):
- buffer.append(decmap_ideo[c])
- continue
-
- if errors == 'replace':
+ else:
+ buffer.append(unicode(c, KSC5601_CODEC, errors))
+ elif errors == 'replace':
buffer.append(u'\uFFFD') # REPLACEMENT CHARACTER
elif errors == 'strict':
raise UnicodeError, "unexpected byte 0x%s found" % (
@@ -192,6 +155,7 @@
buffer.append(data[end:pos+1])
end = pos+1
return buffer
+
def reset(self):
self.data = ''
|