Thread: [KoCo-CVS] [Commit] KoreanCodecs/korean error_callback.py
Brought to you by:
perky
From: Hye-Shik C. <pe...@us...> - 2003-01-13 07:25:27
|
perky 03/01/12 23:25:26 Added: korean error_callback.py Log: Add PEP293 emulation codes. Revision Changes Path 1.1 KoreanCodecs/korean/error_callback.py Index: error_callback.py =================================================================== # # This file is part of KoreanCodecs. # # Copyright(C) 2002-2003 Hye-Shik Chang <pe...@Fr...>. # # KoreanCodecs is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published # by the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # KoreanCodecs is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with KoreanCodecs; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # $Id: error_callback.py,v 1.1 2003/01/13 07:25:26 perky Exp $ # try: from __builtin__ import UnicodeEncodeError, UnicodeDecodeError from codecs import lookup_error except: # implementations from PEP293 for ancient systems class UnicodeEncodeError(UnicodeError): def __init__(self, encoding, object, start, end, reason): UnicodeError.__init__(self, "encoding '%s' can't encode characters " + "in positions %d-%d: %s" % (encoding, start, end-1, reason)) self.encoding = encoding self.object = object self.start = start self.end = end self.reason = reason class UnicodeDecodeError(UnicodeError): def __init__(self, encoding, object, start, end, reason): UnicodeError.__init__(self, "encoding '%s' can't decode characters " + "in positions %d-%d: %s" % (encoding, start, end-1, reason)) self.encoding = encoding self.object = object self.start = start self.end = end self.reason = reason def errcb_strict(exc): raise exc def errcb_ignore(exc): if isinstance(exc, UnicodeError): return (u"", exc.end) else: raise TypeError("can't handle %s" % exc.__name__) def errcb_replace(exc): if isinstance(exc, UnicodeEncodeError): return ((exc.end-exc.start)*u"?", exc.end) elif isinstance(exc, UnicodeDecodeError): return (u"\ufffd", exc.end) else: raise TypeError("can't handle %s" % exc.__name__) error_callbacks = { 'strict': errcb_strict, 'ignore': errcb_ignore, 'replace': errcb_replace, } def lookup_error(name): cb = error_callbacks.get(name) if cb: return cb else: raise LookupError, "unknown error handler name '%s'" % name # ex: ts=8 sts=4 et |
From: Hye-Shik C. <pe...@us...> - 2003-01-13 07:37:58
|
perky 03/01/12 23:37:57 Modified: korean error_callback.py Log: Hide internal symbols from 'from import *' Revision Changes Path 1.2 +8 -8 KoreanCodecs/korean/error_callback.py Index: error_callback.py =================================================================== RCS file: /cvsroot/koco/KoreanCodecs/korean/error_callback.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- error_callback.py 13 Jan 2003 07:25:26 -0000 1.1 +++ error_callback.py 13 Jan 2003 07:37:57 -0000 1.2 @@ -17,7 +17,7 @@ # along with KoreanCodecs; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# $Id: error_callback.py,v 1.1 2003/01/13 07:25:26 perky Exp $ +# $Id: error_callback.py,v 1.2 2003/01/13 07:37:57 perky Exp $ # try: @@ -48,24 +48,24 @@ self.end = end self.reason = reason - def errcb_strict(exc): + def _errcb_strict(exc): raise exc - def errcb_ignore(exc): + def _errcb_ignore(exc): if isinstance(exc, UnicodeError): return (u"", exc.end) else: raise TypeError("can't handle %s" % exc.__name__) - def errcb_replace(exc): + def _errcb_replace(exc): if isinstance(exc, UnicodeEncodeError): return ((exc.end-exc.start)*u"?", exc.end) elif isinstance(exc, UnicodeDecodeError): return (u"\ufffd", exc.end) else: raise TypeError("can't handle %s" % exc.__name__) - error_callbacks = { - 'strict': errcb_strict, - 'ignore': errcb_ignore, - 'replace': errcb_replace, + _error_callbacks = { + 'strict': _errcb_strict, + 'ignore': _errcb_ignore, + 'replace': _errcb_replace, } def lookup_error(name): |
From: Hye-Shik C. <pe...@us...> - 2003-01-13 07:52:48
|
perky 03/01/12 23:52:47 Modified: korean error_callback.py Log: Fix one missing _ Revision Changes Path 1.3 +2 -2 KoreanCodecs/korean/error_callback.py Index: error_callback.py =================================================================== RCS file: /cvsroot/koco/KoreanCodecs/korean/error_callback.py,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- error_callback.py 13 Jan 2003 07:37:57 -0000 1.2 +++ error_callback.py 13 Jan 2003 07:52:47 -0000 1.3 @@ -17,7 +17,7 @@ # along with KoreanCodecs; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# $Id: error_callback.py,v 1.2 2003/01/13 07:37:57 perky Exp $ +# $Id: error_callback.py,v 1.3 2003/01/13 07:52:47 perky Exp $ # try: @@ -69,7 +69,7 @@ } def lookup_error(name): - cb = error_callbacks.get(name) + cb = _error_callbacks.get(name) if cb: return cb else: |
From: Hye-Shik C. <pe...@us...> - 2003-01-14 15:13:49
|
perky 03/01/14 07:13:48 Modified: korean error_callback.py Log: Fix syntax error on wrong parenthesis Revision Changes Path 1.5 +6 -5 KoreanCodecs/korean/error_callback.py Index: error_callback.py =================================================================== RCS file: /cvsroot/koco/KoreanCodecs/korean/error_callback.py,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- error_callback.py 13 Jan 2003 09:09:56 -0000 1.4 +++ error_callback.py 14 Jan 2003 15:13:44 -0000 1.5 @@ -17,7 +17,7 @@ # along with KoreanCodecs; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# $Id: error_callback.py,v 1.4 2003/01/13 09:09:56 perky Exp $ +# $Id: error_callback.py,v 1.5 2003/01/14 15:13:44 perky Exp $ # try: @@ -27,8 +27,8 @@ class UnicodeEncodeError(UnicodeError): def __init__(self, encoding, object, start, end, reason): UnicodeError.__init__(self, - "encoding '%s' can't encode characters " + - "in positions %d-%d: %s" % (encoding, + ("encoding '%s' can't encode characters " + "in positions %d-%d: %s") % (encoding, start, end-1, reason)) self.encoding = encoding self.object = object @@ -38,9 +38,10 @@ class UnicodeDecodeError(UnicodeError): def __init__(self, encoding, object, start, end, reason): + print repr((encoding, object, start, end, reason)) UnicodeError.__init__(self, - "encoding '%s' can't decode characters " + - "in positions %d-%d: %s" % (encoding, + ("encoding '%s' can't decode characters " + "in positions %d-%d: %s") % (encoding, start, end-1, reason)) self.encoding = encoding self.object = object |
From: Hye-Shik C. <pe...@us...> - 2003-01-14 15:20:43
|
perky 03/01/14 07:20:40 Modified: korean error_callback.py Log: Remove debugging routine. Revision Changes Path 1.6 +1 -2 KoreanCodecs/korean/error_callback.py Index: error_callback.py =================================================================== RCS file: /cvsroot/koco/KoreanCodecs/korean/error_callback.py,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- error_callback.py 14 Jan 2003 15:13:44 -0000 1.5 +++ error_callback.py 14 Jan 2003 15:20:35 -0000 1.6 @@ -17,7 +17,7 @@ # along with KoreanCodecs; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# $Id: error_callback.py,v 1.5 2003/01/14 15:13:44 perky Exp $ +# $Id: error_callback.py,v 1.6 2003/01/14 15:20:35 perky Exp $ # try: @@ -38,7 +38,6 @@ class UnicodeDecodeError(UnicodeError): def __init__(self, encoding, object, start, end, reason): - print repr((encoding, object, start, end, reason)) UnicodeError.__init__(self, ("encoding '%s' can't decode characters " "in positions %d-%d: %s") % (encoding, |