Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 54480d3

Browse files
committed
New codec which always raises an exception when used. This
codec can be used to effectively switch off string coercion to Unicode.
1 parent d1a65ff commit 54480d3

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lib/encodings/undefined.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
""" Python 'undefined' Codec
2+
3+
This codec will always raise a ValueError exception when being
4+
used. It is intended for use by the site.py file to switch off
5+
automatic string to Unicode coercion.
6+
7+
Written by Marc-Andre Lemburg ([email protected]).
8+
9+
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
10+
11+
"""
12+
import codecs
13+
14+
### Codec APIs
15+
16+
class Codec(codecs.Codec):
17+
18+
def encode(self,input,errors='strict'):
19+
raise UnicodeError, "undefined encoding"
20+
21+
def decode(self,input,errors='strict'):
22+
raise UnicodeError, "undefined encoding"
23+
24+
class StreamWriter(Codec,codecs.StreamWriter):
25+
pass
26+
27+
class StreamReader(Codec,codecs.StreamReader):
28+
pass
29+
30+
### encodings module API
31+
32+
def getregentry():
33+
34+
return (Codec().encode,Codec().decode,StreamReader,StreamWriter)

0 commit comments

Comments
 (0)