From e03c05059534b4783c5631517cb16f79531358e8 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 12 Aug 1998 02:38:11 +0000 Subject: The usual. --- Lib/dos-8x3/cgihttps.py | 5 +- Lib/dos-8x3/configpa.py | 144 +++++++++++++++++++++++++++++++++--------------- Lib/dos-8x3/exceptio.py | 35 +++++++++++- Lib/dos-8x3/fileinpu.py | 1 + Lib/dos-8x3/macurl2p.py | 14 +++-- Lib/dos-8x3/mimetool.py | 7 +-- Lib/dos-8x3/mimetype.py | 27 ++++++++- Lib/dos-8x3/mimewrit.py | 2 +- Lib/dos-8x3/multifil.py | 81 +++++++++++++++++---------- Lib/dos-8x3/posixpat.py | 18 ++++++ Lib/dos-8x3/py_compi.py | 1 - Lib/dos-8x3/queue.py | 50 ++++++++--------- Lib/dos-8x3/rlcomple.py | 5 +- Lib/dos-8x3/socketse.py | 9 ++- Lib/dos-8x3/test_arr.py | 29 +++++++++- Lib/dos-8x3/test_fcn.py | 2 +- Lib/dos-8x3/test_img.py | 10 +--- Lib/dos-8x3/test_rgb.py | 15 +---- Lib/dos-8x3/test_sun.py | 15 +---- Lib/dos-8x3/test_sup.py | 12 ++++ Lib/dos-8x3/test_thr.py | 16 +++--- Lib/dos-8x3/test_tok.py | 14 +---- Lib/dos-8x3/test_typ.py | 25 +++++++++ Lib/dos-8x3/test_zli.py | 6 +- Lib/dos-8x3/userlist.py | 1 + 25 files changed, 363 insertions(+), 181 deletions(-) diff --git a/Lib/dos-8x3/cgihttps.py b/Lib/dos-8x3/cgihttps.py index bb8cb2d..24bdeef 100755 --- a/Lib/dos-8x3/cgihttps.py +++ b/Lib/dos-8x3/cgihttps.py @@ -133,7 +133,10 @@ class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): # AUTH_TYPE # REMOTE_USER # REMOTE_IDENT - env['CONTENT_TYPE'] = self.headers.type + if self.headers.typeheader is None: + env['CONTENT_TYPE'] = self.headers.type + else: + env['CONTENT_TYPE'] = self.headers.typeheader length = self.headers.getheader('content-length') if length: env['CONTENT_LENGTH'] = length diff --git a/Lib/dos-8x3/configpa.py b/Lib/dos-8x3/configpa.py index 957222c..89e2d85 100644 --- a/Lib/dos-8x3/configpa.py +++ b/Lib/dos-8x3/configpa.py @@ -2,10 +2,11 @@ A setup file consists of sections, lead by a "[section]" header, and followed by "name: value" entries, with continuations and such in -the style of rfc822. +the style of RFC 822. + +The option values can contain format strings which refer to other values in +the same section, or values in a special [DEFAULT] section. -The option values can contain format strings which refer to other -values in the same section, or values in a special [DEFAULT] section. For example: something: %(dir)s/whatever @@ -27,7 +28,7 @@ ConfigParser -- responsible for for parsing a list of dictionary of intrinsic defaults. The keys must be strings, the values must be appropriate for %()s string - interpolation. Note that `name' is + interpolation. Note that `__name__' is always an intrinsic default; it's value is the section's name. @@ -55,14 +56,7 @@ ConfigParser -- responsible for for parsing a list of import sys import string -import regex -from types import ListType - - -SECTHEAD_RE = "^\[\([-A-Za-z0-9]*\)\][" + string.whitespace + "]*$" -secthead_cre = regex.compile(SECTHEAD_RE) -OPTION_RE = "^\([-A-Za-z0-9.]+\)\(:\|[" + string.whitespace + "]*=\)\(.*\)$" -option_cre = regex.compile(OPTION_RE) +import re DEFAULTSECT = "DEFAULT" @@ -71,9 +65,9 @@ DEFAULTSECT = "DEFAULT" # exception classes class Error: def __init__(self, msg=''): - self.__msg = msg + self._msg = msg def __repr__(self): - return self.__msg + return self._msg class NoSectionError(Error): def __init__(self, section): @@ -93,14 +87,38 @@ class NoOptionError(Error): self.section = section class InterpolationError(Error): - def __init__(self, reference, option, section): + def __init__(self, reference, option, section, rawval): Error.__init__(self, - "Bad value substitution: sect `%s', opt `%s', ref `%s'" - % (section, option, reference)) + "Bad value substitution:\n" + "\tsection: [%s]\n" + "\toption : %s\n" + "\tkey : %s\n" + "\trawval : %s\n" + % (section, option, reference, rawval)) self.reference = reference self.option = option self.section = section +class MissingSectionHeaderError(Error): + def __init__(self, filename, lineno, line): + Error.__init__( + self, + 'File contains no section headers.\nfile: %s, line: %d\n%s' % + (filename, lineno, line)) + self.filename = filename + self.lineno = lineno + self.line = line + +class ParsingError(Error): + def __init__(self, filename): + Error.__init__(self, 'File contains parsing errors: %s' % filename) + self.filename = filename + self.errors = [] + + def append(self, lineno, line): + self.errors.append((lineno, line)) + self._msg = self._msg + '\n\t[line %2d]: %s' % (lineno, line) + class ConfigParser: @@ -159,7 +177,8 @@ class ConfigParser: """Get an option value for a given section. All % interpolations are expanded in the return values, based - on the defaults passed into the constructor. + on the defaults passed into the constructor, unless the optional + argument `raw' is true. The section DEFAULT is special. """ @@ -183,7 +202,7 @@ class ConfigParser: try: return rawval % d except KeyError, key: - raise InterpolationError(key, option, section) + raise InterpolationError(key, option, section, rawval) def __get(self, section, conv, option): return conv(self.get(section, option)) @@ -201,6 +220,24 @@ class ConfigParser: raise ValueError, 'Not a boolean: %s' % v return val + # + # Regular expressions for parsing section headers and options. Note a + # slight semantic change from the previous version, because of the use + # of \w, _ is allowed in section header names. + __SECTCRE = re.compile( + r'\[' # [ + r'(?P
[-\w]+)' # `-', `_' or any alphanum + r'\]' # ] + ) + __OPTCRE = re.compile( + r'(?P