Commit 3d1f397f authored by Barry Warsaw's avatar Barry Warsaw

Update to Python 2.3, getting rid of backward compatiblity crud. Get rid of a

bunch of module globals that aren't used.
parent 36112f2d
# Copyright (C) 2002 Python Software Foundation # Copyright (C) 2002-2004 Python Software Foundation
# Author: che@debian.org (Ben Gertzfield), barry@zope.com (Barry Warsaw) # Author: che@debian.org (Ben Gertzfield), barry@python.org (Barry Warsaw)
"""Header encoding and decoding functionality.""" """Header encoding and decoding functionality."""
import re import re
import binascii import binascii
from types import StringType, UnicodeType
import email.quopriMIME import email.quopriMIME
import email.base64MIME import email.base64MIME
from email.Errors import HeaderParseError from email.Errors import HeaderParseError
from email.Charset import Charset from email.Charset import Charset
try:
from email._compat22 import _floordiv
except SyntaxError:
# Python 2.1 spells integer division differently
from email._compat21 import _floordiv
try:
True, False
except NameError:
True = 1
False = 0
CRLFSPACE = '\r\n '
CRLF = '\r\n'
NL = '\n' NL = '\n'
SPACE = ' ' SPACE = ' '
USPACE = u' ' USPACE = u' '
SPACE8 = ' ' * 8 SPACE8 = ' ' * 8
EMPTYSTRING = ''
UEMPTYSTRING = u'' UEMPTYSTRING = u''
MAXLINELEN = 76 MAXLINELEN = 76
ENCODE = 1
DECODE = 2
USASCII = Charset('us-ascii') USASCII = Charset('us-ascii')
UTF8 = Charset('utf-8') UTF8 = Charset('utf-8')
...@@ -52,8 +33,6 @@ ecre = re.compile(r''' ...@@ -52,8 +33,6 @@ ecre = re.compile(r'''
\?= # literal ?= \?= # literal ?=
''', re.VERBOSE | re.IGNORECASE) ''', re.VERBOSE | re.IGNORECASE)
pcre = re.compile('([,;])')
# Field name regexp, including trailing colon, but not separating whitespace, # Field name regexp, including trailing colon, but not separating whitespace,
# according to RFC 2822. Character range is from tilde to exclamation mark. # according to RFC 2822. Character range is from tilde to exclamation mark.
# For use with .match() # For use with .match()
...@@ -244,8 +223,8 @@ class Header: ...@@ -244,8 +223,8 @@ class Header:
constructor is used. constructor is used.
s may be a byte string or a Unicode string. If it is a byte string s may be a byte string or a Unicode string. If it is a byte string
(i.e. isinstance(s, StringType) is true), then charset is the encoding (i.e. isinstance(s, str) is true), then charset is the encoding of
of that byte string, and a UnicodeError will be raised if the string that byte string, and a UnicodeError will be raised if the string
cannot be decoded with that charset. If s is a Unicode string, then cannot be decoded with that charset. If s is a Unicode string, then
charset is a hint specifying the character set of the characters in charset is a hint specifying the character set of the characters in
the string. In this case, when producing an RFC 2822 compliant header the string. In this case, when producing an RFC 2822 compliant header
...@@ -265,7 +244,7 @@ class Header: ...@@ -265,7 +244,7 @@ class Header:
# We need to test that the string can be converted to unicode and # We need to test that the string can be converted to unicode and
# back to a byte string, given the input and output codecs of the # back to a byte string, given the input and output codecs of the
# charset. # charset.
if isinstance(s, StringType): if isinstance(s, str):
# Possibly raise UnicodeError if the byte string can't be # Possibly raise UnicodeError if the byte string can't be
# converted to a unicode with the input codec of the charset. # converted to a unicode with the input codec of the charset.
incodec = charset.input_codec or 'us-ascii' incodec = charset.input_codec or 'us-ascii'
...@@ -275,7 +254,7 @@ class Header: ...@@ -275,7 +254,7 @@ class Header:
# than the iput coded. Still, use the original byte string. # than the iput coded. Still, use the original byte string.
outcodec = charset.output_codec or 'us-ascii' outcodec = charset.output_codec or 'us-ascii'
ustr.encode(outcodec, errors) ustr.encode(outcodec, errors)
elif isinstance(s, UnicodeType): elif isinstance(s, unicode):
# Now we have to be sure the unicode string can be converted # Now we have to be sure the unicode string can be converted
# to a byte string with a reasonable output codec. We want to # to a byte string with a reasonable output codec. We want to
# use the byte string in the chunk. # use the byte string in the chunk.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment