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

Skip to content

Commit e8d2f55

Browse files
committed
The usual.
1 parent eebb1c6 commit e8d2f55

19 files changed

Lines changed: 511 additions & 262 deletions

Lib/dos-8x3/configpa.py

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@
9191

9292
DEFAULTSECT = "DEFAULT"
9393

94+
MAX_INTERPOLATION_DEPTH = 10
95+
9496

9597

9698
# exception classes
@@ -130,15 +132,16 @@ def __init__(self, reference, option, section, rawval):
130132
self.option = option
131133
self.section = section
132134

133-
class MissingSectionHeaderError(Error):
134-
def __init__(self, filename, lineno, line):
135-
Error.__init__(
136-
self,
137-
'File contains no section headers.\nfile: %s, line: %d\n%s' %
138-
(filename, lineno, line))
139-
self.filename = filename
140-
self.lineno = lineno
141-
self.line = line
135+
class InterpolationDepthError(Error):
136+
def __init__(self, option, section, rawval):
137+
Error.__init__(self,
138+
"Value interpolation too deeply recursive:\n"
139+
"\tsection: [%s]\n"
140+
"\toption : %s\n"
141+
"\trawval : %s\n"
142+
% (section, option, rawval))
143+
self.option = option
144+
self.section = section
142145

143146
class ParsingError(Error):
144147
def __init__(self, filename):
@@ -150,6 +153,16 @@ def append(self, lineno, line):
150153
self.errors.append((lineno, line))
151154
self._msg = self._msg + '\n\t[line %2d]: %s' % (lineno, line)
152155

156+
class MissingSectionHeaderError(ParsingError):
157+
def __init__(self, filename, lineno, line):
158+
Error.__init__(
159+
self,
160+
'File contains no section headers.\nfile: %s, line: %d\n%s' %
161+
(filename, lineno, line))
162+
self.filename = filename
163+
self.lineno = lineno
164+
self.line = line
165+
153166

154167

155168
class ConfigParser:
@@ -183,7 +196,7 @@ def has_section(self, section):
183196
184197
The DEFAULT section is not acknowledged.
185198
"""
186-
return self.__sections.has_key(section)
199+
return section in self.sections()
187200

188201
def options(self, section):
189202
"""Return a list of option names for the given section name."""
@@ -192,15 +205,13 @@ def options(self, section):
192205
except KeyError:
193206
raise NoSectionError(section)
194207
opts.update(self.__defaults)
208+
if opts.has_key('__name__'):
209+
del opts['__name__']
195210
return opts.keys()
196211

197212
def has_option(self, section, option):
198213
"""Return whether the given section has the given option."""
199-
try:
200-
opts = self.__sections[section]
201-
except KeyError:
202-
raise NoSectionError(section)
203-
return opts.has_key(option)
214+
return option in self.options(section)
204215

205216
def read(self, filenames):
206217
"""Read and parse a filename or a list of filenames.
@@ -266,10 +277,11 @@ def get(self, section, option, raw=0, vars=None):
266277
rawval = d[option]
267278
except KeyError:
268279
raise NoOptionError(option, section)
269-
# do the string interpolation
280+
270281
if raw:
271282
return rawval
272283

284+
# do the string interpolation
273285
value = rawval # Make it a pretty variable name
274286
depth = 0
275287
while depth < 10: # Loop through this until it's done
@@ -280,7 +292,10 @@ def get(self, section, option, raw=0, vars=None):
280292
except KeyError, key:
281293
raise InterpolationError(key, option, section, rawval)
282294
else:
283-
return value
295+
break
296+
if value.find("%(") >= 0:
297+
raise InterpolationDepthError(option, section, rawval)
298+
return value
284299

285300
def __get(self, section, conv, option):
286301
return conv(self.get(section, option))
@@ -365,7 +380,7 @@ def remove_section(self, section):
365380
# of \w, _ is allowed in section header names.
366381
SECTCRE = re.compile(
367382
r'\[' # [
368-
r'(?P<header>[-\w_.*,(){}]+)' # a lot of stuff found by IvL
383+
r'(?P<header>[-\w_.*,(){} ]+)' # a lot of stuff found by IvL
369384
r'\]' # ]
370385
)
371386
OPTCRE = re.compile(

Lib/dos-8x3/mimetool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def decode(input, output, encoding):
141141
import uu
142142
return uu.decode(input, output)
143143
if encoding in ('7bit', '8bit'):
144-
output.write(input.read())
144+
return output.write(input.read())
145145
if decodetab.has_key(encoding):
146146
pipethrough(input, decodetab[encoding], output)
147147
else:
@@ -160,7 +160,7 @@ def encode(input, output, encoding):
160160
import uu
161161
return uu.encode(input, output)
162162
if encoding in ('7bit', '8bit'):
163-
output.write(input.read())
163+
return output.write(input.read())
164164
if encodetab.has_key(encoding):
165165
pipethrough(input, encodetab[encoding], output)
166166
else:

Lib/dos-8x3/posixpat.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ def join(a, *p):
5656

5757
def split(p):
5858
"""Split a pathname. Returns tuple "(head, tail)" where "tail" is
59-
everything after the final slash. Either part may be empty"""
60-
import string
61-
i = string.rfind(p, '/') + 1
59+
everything after the final slash. Either part may be empty."""
60+
i = p.rfind('/') + 1
6261
head, tail = p[:i], p[i:]
6362
if head and head <> '/'*len(head):
6463
while head[-1] == '/':
@@ -73,7 +72,7 @@ def split(p):
7372

7473
def splitext(p):
7574
"""Split the extension from a pathname. Extension is everything from the
76-
last dot to the end. Returns "(root, ext)", either part may be empty"""
75+
last dot to the end. Returns "(root, ext)", either part may be empty."""
7776
root, ext = '', ''
7877
for c in p:
7978
if c == '/':
@@ -95,7 +94,7 @@ def splitext(p):
9594

9695
def splitdrive(p):
9796
"""Split a pathname into drive and path. On Posix, drive is always
98-
empty"""
97+
empty."""
9998
return '', p
10099

101100

@@ -255,9 +254,9 @@ def ismount(path):
255254

256255
def walk(top, func, arg):
257256
"""walk(top,func,arg) calls func(arg, d, files) for each directory "d"
258-
in the tree rooted at "top" (including "top" itself). "files" is a list
259-
of all the files and subdirs in directory "d".
260-
"""
257+
in the tree rooted at "top" (including "top" itself). "files" is a list
258+
of all the files and subdirs in directory "d".
259+
"""
261260
try:
262261
names = os.listdir(top)
263262
except os.error:
@@ -281,12 +280,12 @@ def walk(top, func, arg):
281280

282281
def expanduser(path):
283282
"""Expand ~ and ~user constructions. If user or $HOME is unknown,
284-
do nothing"""
283+
do nothing."""
285284
if path[:1] <> '~':
286285
return path
287286
i, n = 1, len(path)
288287
while i < n and path[i] <> '/':
289-
i = i+1
288+
i = i + 1
290289
if i == 1:
291290
if not os.environ.has_key('HOME'):
292291
return path
@@ -298,7 +297,7 @@ def expanduser(path):
298297
except KeyError:
299298
return path
300299
userhome = pwent[5]
301-
if userhome[-1:] == '/': i = i+1
300+
if userhome[-1:] == '/': i = i + 1
302301
return userhome + path[i:]
303302

304303

@@ -310,7 +309,7 @@ def expanduser(path):
310309

311310
def expandvars(path):
312311
"""Expand shell variables of form $var and ${var}. Unknown variables
313-
are left unchanged"""
312+
are left unchanged."""
314313
global _varprog
315314
if '$' not in path:
316315
return path
@@ -344,9 +343,8 @@ def normpath(path):
344343
"""Normalize path, eliminating double slashes, etc."""
345344
if path == '':
346345
return '.'
347-
import string
348346
initial_slash = (path[0] == '/')
349-
comps = string.split(path, '/')
347+
comps = path.split('/')
350348
new_comps = []
351349
for comp in comps:
352350
if comp in ('', '.'):
@@ -357,7 +355,7 @@ def normpath(path):
357355
elif new_comps:
358356
new_comps.pop()
359357
comps = new_comps
360-
path = string.join(comps, '/')
358+
path = '/'.join(comps)
361359
if initial_slash:
362360
path = '/' + path
363361
return path or '.'

Lib/dos-8x3/sre_comp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def _optimize_charset(charset, fixup):
222222
def _simple(av):
223223
# check if av is a "simple" operator
224224
lo, hi = av[2].getwidth()
225-
if lo == 0:
225+
if lo == 0 and hi == MAXREPEAT:
226226
raise error, "nothing to repeat"
227227
return lo == hi == 1 and av[2][0][0] != SUBPATTERN
228228

Lib/dos-8x3/sre_cons.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
# See the sre.py file for information on usage and redistribution.
1010
#
1111

12+
MAXREPEAT = 65535
13+
1214
# should this really be here?
1315

1416
class error(Exception):

Lib/dos-8x3/sre_pars.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
from sre_constants import *
1414

15-
MAXREPEAT = 65535
16-
1715
SPECIAL_CHARS = ".\\[{()*+?^$|"
1816
REPEAT_CHARS = "*+?{"
1917

@@ -393,6 +391,8 @@ def _parse(source, state):
393391
# potential range
394392
this = source.get()
395393
if this == "]":
394+
if code1[0] is IN:
395+
code1 = code1[1][0]
396396
set.append(code1)
397397
set.append((LITERAL, ord("-")))
398398
break
@@ -593,6 +593,11 @@ def parse(str, flags=0, pattern=None):
593593

594594
# p.dump()
595595

596+
if not (flags & SRE_FLAG_VERBOSE) and p.pattern.flags & SRE_FLAG_VERBOSE:
597+
# the VERBOSE flag was switched on inside the pattern. to be
598+
# on the safe side, we'll parse the whole thing again...
599+
return parse(str, p.pattern.flags)
600+
596601
return p
597602

598603
def parse_template(source, pattern):

Lib/dos-8x3/stringio.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
buf = f.read(n) # read up to n bytes
1414
buf = f.readline() # read until end of line ('\n') or EOF
1515
list = f.readlines()# list of f.readline() results until EOF
16+
f.truncate([size]) # truncate file at to at most size (default: current pos)
1617
f.write(buf) # write at current position
1718
f.writelines(list) # for line in list: f.write(line)
1819
f.getvalue() # return whole file's contents as a string
@@ -28,6 +29,7 @@
2829
- There's a simple test set (see end of this file).
2930
"""
3031

32+
import errno
3133
import string
3234

3335
class StringIO:
@@ -102,6 +104,17 @@ def readlines(self, sizehint = 0):
102104
break
103105
line = self.readline()
104106
return lines
107+
def truncate(self, size=None):
108+
if self.closed:
109+
raise ValueError, "I/O operation on closed file"
110+
if size is None:
111+
size = self.pos
112+
elif size < 0:
113+
raise IOError(errno.EINVAL,
114+
"Negative size not allowed")
115+
elif size < self.pos:
116+
self.pos = size
117+
self.buf = self.getvalue()[:size]
105118
def write(self, s):
106119
if self.closed:
107120
raise ValueError, "I/O operation on closed file"

0 commit comments

Comments
 (0)