[Patches] [ python-Patches-1176578 ] Clarify unicode.(en|de)code.()
docstrings
SourceForge.net
noreply at sourceforge.net
Tue Apr 5 04:56:03 CEST 2005
Patches item #1176578, was opened at 2005-04-05 04:47
Message generated for change (Comment added) made by perky
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1176578&group_id=5470
Category: Core (C code)
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: Brett Cannon (bcannon)
Assigned to: Nobody/Anonymous (nobody)
Summary: Clarify unicode.(en|de)code.() docstrings
Initial Comment:
I was reading the docstrings for unicode.encode() and
unicode.decode() and they were making no sense to me
since I kept expecting ``unicode("hi",
"utf-8").encode("utf-16")`` to return a unicode object,
just with an internal representation of UTF-16. Then I
started playing with them some more and I realized the
methods encoded and decoded into and out of a byte
stream. Then it made sense.
Attached is a patch to mention that they are working
with byte streams. I also capitalized the first words
in all the sentences.
----------------------------------------------------------------------
>Comment By: Hye-Shik Chang (perky)
Date: 2005-04-05 11:56
Message:
Logged In: YES
user_id=55188
That's not true. While the most unicode codecs are doing
such, some doesn't. It's up to each codec's design what it
gets in its unicode.decode and what it returns in its
unicode.encode.
eg:
>>> u'hello, \uAC00!'.encode('breaker')
u'hello, \xea\xb0\x80!'
>>> _.decode('breaker')
u'hello, \uac00!'
class Codec(codecs.Codec):
....def encode(self, data, errors='strict'):
........return
data.encode('utf-8').decode('iso8859-1'),len(data)
....def decode(self, data, errors='strict'):
........return data.encode('iso8859-1').decode('utf-8'),
len(data)
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1176578&group_id=5470
More information about the Patches
mailing list