import string
import sys
import os
+import urllib
+import regsub
+import mimetools
+import rfc822
+from StringIO import StringIO
# Logging support
If false (the default), errors are silently ignored.
If true, errors raise a ValueError exception.
"""
- import urllib, regsub
name_value_pairs = string.splitfields(qs, '&')
dict = {}
for name_value in name_value_pairs:
point in having two implementations of the same parsing algorithm.
"""
- import mimetools
if pdict.has_key('boundary'):
boundary = pdict['boundary']
else:
def __init__(self, name, value):
"""Constructor from field name and value."""
- from StringIO import StringIO
self.name = name
self.value = value
# self.file = StringIO(value)
qs = sys.argv[1]
else:
qs = ""
- from StringIO import StringIO
fp = StringIO(qs)
if headers is None:
headers = {'content-type':
def read_multi(self):
"""Internal: read a part that is itself multipart."""
- import rfc822
self.list = []
part = self.__class__(self.fp, {}, self.innerboundary)
# Throw first part away
self.done = 1
break
- def make_file(self, binary):
+ def make_file(self, binary=None):
"""Overridable: return a readable & writable file.
The file will be used as follows:
- seek(0)
- data is read from it
- The 'binary' argument is 'b' if the file should be created in
- binary mode (on non-Unix systems), '' otherwise.
+ The 'binary' argument is unused -- the file is always opened
+ in binary mode.
This version opens a temporary file for reading and writing,
and immediately deletes (unlinks) it. The trick (on Unix!) is
"""
import tempfile
- tfn = tempfile.mktemp()
- f = open(tfn, "w%s+" % binary)
- os.unlink(tfn)
- return f
+ return tempfile.TemporaryFile("w+b")
+
# Backwards Compatibility Classes
def escape(s, quote=None):
"""Replace special characters '&', '<' and '>' by SGML entities."""
- import regsub
s = regsub.gsub("&", "&", s) # Must be done first!
s = regsub.gsub("<", "<", s)
s = regsub.gsub(">", ">", s)