Mercurial > cpython-lru_cache-weakref
annotate Lib/test/testcodec.py @ 74006:88198b93ff2f
Issue #13560: Add PyUnicode_EncodeLocale()
* Use PyUnicode_EncodeLocale() in time.strftime() if wcsftime() is not
available
* Document my last changes in Misc/NEWS
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Sat, 17 Dec 2011 04:13:41 +0100 |
| parents | 0d462d789b18 |
| children |
| rev | line source |
|---|---|
|
15795
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
1 """ Test Codecs (used by test_charmapcodec) |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
2 |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
3 Written by Marc-Andre Lemburg (mal@lemburg.com). |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
4 |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
5 (c) Copyright 2000 Guido van Rossum. |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
6 |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
7 """#" |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
8 import codecs |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
9 |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
10 ### Codec APIs |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
11 |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
12 class Codec(codecs.Codec): |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
13 |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
14 def encode(self,input,errors='strict'): |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
15 |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
16 return codecs.charmap_encode(input,errors,encoding_map) |
|
15977
f16545f58345
Whitespace normalization. Leaving tokenize_tests.py alone for now.
Tim Peters <tim.peters@gmail.com>
parents:
15795
diff
changeset
|
17 |
|
15795
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
18 def decode(self,input,errors='strict'): |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
19 |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
20 return codecs.charmap_decode(input,errors,decoding_map) |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
21 |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
22 class StreamWriter(Codec,codecs.StreamWriter): |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
23 pass |
|
15977
f16545f58345
Whitespace normalization. Leaving tokenize_tests.py alone for now.
Tim Peters <tim.peters@gmail.com>
parents:
15795
diff
changeset
|
24 |
|
15795
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
25 class StreamReader(Codec,codecs.StreamReader): |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
26 pass |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
27 |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
28 ### encodings module API |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
29 |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
30 def getregentry(): |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
31 |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
32 return (Codec().encode,Codec().decode,StreamReader,StreamWriter) |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
33 |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
34 ### Decoding Map |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
35 |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
36 decoding_map = codecs.make_identity_dict(range(256)) |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
37 decoding_map.update({ |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
15977
diff
changeset
|
38 0x78: "abc", # 1-n decoding mapping |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43664
diff
changeset
|
39 b"abc": 0x0078,# 1-n encoding mapping |
|
15795
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
40 0x01: None, # decoding mapping to <undefined> |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
15977
diff
changeset
|
41 0x79: "", # decoding mapping to <remove character> |
|
15795
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
42 }) |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
43 |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
44 ### Encoding Map |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
45 |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
46 encoding_map = {} |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
47 for k,v in decoding_map.items(): |
|
63c0483eff68
Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents:
diff
changeset
|
48 encoding_map[v] = k |
