annotate Lib/test/testcodec.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 0d462d789b18
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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