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

Skip to content

Commit 2e7840f

Browse files
committed
The usual.
1 parent 01b7ced commit 2e7840f

4 files changed

Lines changed: 131 additions & 71 deletions

File tree

Lib/dos-8x3/configpa.py

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,37 @@
2424
2525
methods:
2626
27-
__init__(defaults=None) -- create the parser and specify a
28-
dictionary of intrinsic defaults. The
29-
keys must be strings, the values must
30-
be appropriate for %()s string
31-
interpolation. Note that `__name__' is
32-
always an intrinsic default; it's value
33-
is the section's name.
27+
__init__(defaults=None)
28+
create the parser and specify a dictionary of intrinsic defaults. The
29+
keys must be strings, the values must be appropriate for %()s string
30+
interpolation. Note that `__name__' is always an intrinsic default;
31+
it's value is the section's name.
3432
35-
sections() -- return all the configuration section names, sans DEFAULT
33+
sections()
34+
return all the configuration section names, sans DEFAULT
3635
37-
options(section) -- return list of configuration options for the named
38-
section
36+
options(section)
37+
return list of configuration options for the named section
3938
40-
read(*filenames) -- read and parse the list of named configuration files
39+
read(filenames)
40+
read and parse the list of named configuration files
4141
42-
get(section, option, raw=0) -- return a string value for the named
43-
option. All % interpolations are
44-
expanded in the return values, based on
45-
the defaults passed into the constructor
46-
and the DEFAULT section.
42+
get(section, option, raw=0, vars=None)
43+
return a string value for the named option. All % interpolations are
44+
expanded in the return values, based on the defaults passed into the
45+
constructor and the DEFAULT section. Additional substitutions may be
46+
provided using the `vars' argument, which must be a dictionary whose
47+
contents override any pre-existing defaults.
4748
48-
getint(section, options) -- like get(), but convert value to an integer
49+
getint(section, options)
50+
like get(), but convert value to an integer
4951
50-
getfloat(section, options) -- like get(), but convert value to a float
52+
getfloat(section, options)
53+
like get(), but convert value to a float
5154
52-
getboolean(section, options) -- like get(), but convert value to
53-
a boolean (currently defined as 0
54-
or 1, only)
55+
getboolean(section, options)
56+
like get(), but convert value to a boolean (currently defined as 0 or
57+
1, only)
5558
"""
5659

5760
import sys
@@ -173,12 +176,14 @@ def read(self, filenames):
173176
except IOError:
174177
pass
175178

176-
def get(self, section, option, raw=0):
179+
def get(self, section, option, raw=0, vars=None):
177180
"""Get an option value for a given section.
178181
179-
All % interpolations are expanded in the return values, based
180-
on the defaults passed into the constructor, unless the optional
181-
argument `raw' is true.
182+
All % interpolations are expanded in the return values, based on the
183+
defaults passed into the constructor, unless the optional argument
184+
`raw' is true. Additional substitutions may be provided using the
185+
`vars' argument, which must be a dictionary whose contents overrides
186+
any pre-existing defaults.
182187
183188
The section DEFAULT is special.
184189
"""
@@ -191,6 +196,9 @@ def get(self, section, option, raw=0):
191196
raise NoSectionError(section)
192197
d = self.__defaults.copy()
193198
d.update(sectdict)
199+
# Update with the entry specific variables
200+
if vars:
201+
d.update(vars)
194202
option = string.lower(option)
195203
try:
196204
rawval = d[option]
@@ -199,11 +207,17 @@ def get(self, section, option, raw=0):
199207
# do the string interpolation
200208
if raw:
201209
return rawval
202-
try:
203-
return rawval % d
204-
except KeyError, key:
205-
raise InterpolationError(key, option, section, rawval)
206210

211+
value = rawval # Make it a pretty variable name
212+
while 1: # Loop through this until it's done
213+
if not string.find(value, "%("):
214+
try:
215+
value = value % d
216+
except KeyError, key:
217+
raise InterpolationError(key, option, section, rawval)
218+
else:
219+
return value
220+
207221
def __get(self, section, conv, option):
208222
return conv(self.get(section, option))
209223

Lib/dos-8x3/posixpat.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,3 +367,10 @@ def normpath(path):
367367
if not comps and not slashes:
368368
comps.append('.')
369369
return slashes + string.joinfields(comps, '/')
370+
371+
372+
# Return an absolute path.
373+
def abspath(path):
374+
if not isabs(path):
375+
path = join(os.getcwd(), path)
376+
return normpath(path)

Lib/dos-8x3/queue.py

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
try:
66
class Empty(Exception):
77
pass
8+
class Full(Exception):
9+
pass
810
except TypeError:
911
# string based exceptions
10-
Empty = 'Queue.Empty' # Exception raised by get_nowait()
12+
# exception raised by get(block=0)/get_nowait()
13+
Empty = 'Queue.Empty'
14+
# exception raised by put(block=0)/put_nowait()
15+
Full = 'Queue.Full'
1116

1217
class Queue:
1318
def __init__(self, maxsize):
@@ -23,32 +28,38 @@ def __init__(self, maxsize):
2328
self.fsema = thread.allocate_lock()
2429

2530
def qsize(self):
26-
"""Returns the approximate size of the queue (not reliable!)."""
31+
"""Return the approximate size of the queue (not reliable!)."""
2732
self.mutex.acquire()
2833
n = self._qsize()
2934
self.mutex.release()
3035
return n
3136

3237
def empty(self):
33-
"""Returns 1 if the queue is empty, 0 otherwise (not reliable!)."""
38+
"""Return 1 if the queue is empty, 0 otherwise (not reliable!)."""
3439
self.mutex.acquire()
3540
n = self._empty()
3641
self.mutex.release()
3742
return n
3843

3944
def full(self):
40-
"""Returns 1 if the queue is full, 0 otherwise (not reliable!)."""
45+
"""Return 1 if the queue is full, 0 otherwise (not reliable!)."""
4146
self.mutex.acquire()
4247
n = self._full()
4348
self.mutex.release()
4449
return n
4550

46-
def put(self, item):
51+
def put(self, item, block=1):
4752
"""Put an item into the queue.
4853
49-
If the queue is full, block until a free slot is avaiable.
50-
"""
51-
self.fsema.acquire()
54+
If optional arg 'block' is 1 (the default), block if
55+
necessary until a free slot is available. Otherwise (block
56+
is 0), put an item on the queue if a free slot is immediately
57+
available, else raise the Full exception.
58+
"""
59+
if block:
60+
self.fsema.acquire()
61+
elif not self.fsema.acquire(0):
62+
raise Full
5263
self.mutex.acquire()
5364
was_empty = self._empty()
5465
self._put(item)
@@ -58,45 +69,27 @@ def put(self, item):
5869
self.fsema.release()
5970
self.mutex.release()
6071

61-
def get(self):
62-
"""Gets and returns an item from the queue.
72+
def put_nowait(self, item):
73+
"""Put an item into the queue without blocking.
6374
64-
This method blocks if necessary until an item is available.
75+
Only enqueue the item if a free slot is immediately available.
76+
Otherwise raise the Full exception.
6577
"""
66-
self.esema.acquire()
67-
self.mutex.acquire()
68-
was_full = self._full()
69-
item = self._get()
70-
if was_full:
71-
self.fsema.release()
72-
if not self._empty():
73-
self.esema.release()
74-
self.mutex.release()
75-
return item
78+
return self.put(item, 0)
7679

77-
# Get an item from the queue if one is immediately available,
78-
# raise Empty if the queue is empty or temporarily unavailable
79-
def get_nowait(self):
80-
"""Gets and returns an item from the queue.
80+
def get(self, block=1):
81+
"""Remove and return an item from the queue.
8182
82-
Only gets an item if one is immediately available, Otherwise
83-
this raises the Empty exception if the queue is empty or
84-
temporarily unavailable.
83+
If optional arg 'block' is 1 (the default), block if
84+
necessary until an item is available. Otherwise (block is 0),
85+
return an item if one is immediately available, else raise the
86+
Empty exception.
8587
"""
86-
locked = self.esema.acquire(0)
87-
self.mutex.acquire()
88-
if self._empty():
89-
# The queue is empty -- we can't have esema
90-
self.mutex.release()
88+
if block:
89+
self.esema.acquire()
90+
elif not self.esema.acquire(0):
9191
raise Empty
92-
if not locked:
93-
locked = self.esema.acquire(0)
94-
if not locked:
95-
# Somebody else has esema
96-
# but we have mutex --
97-
# go out of their way
98-
self.mutex.release()
99-
raise Empty
92+
self.mutex.acquire()
10093
was_full = self._full()
10194
item = self._get()
10295
if was_full:
@@ -106,8 +99,13 @@ def get_nowait(self):
10699
self.mutex.release()
107100
return item
108101

109-
# XXX Need to define put_nowait() as well.
102+
def get_nowait(self):
103+
"""Remove and return an item from the queue without blocking.
110104
105+
Only get an item if one is immediately available. Otherwise
106+
raise the Empty exception.
107+
"""
108+
return self.get(0)
111109

112110
# Override these methods to implement other queue organizations
113111
# (e.g. stack or priority queue).

Lib/dos-8x3/test_ntp.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import ntpath
2+
import string
3+
4+
errors = 0
5+
6+
def tester(fn, wantResult):
7+
fn = string.replace(fn, "\\", "\\\\")
8+
gotResult = eval(fn)
9+
if wantResult != gotResult:
10+
print "error!"
11+
print "evaluated: " + str(fn)
12+
print "should be: " + str(wantResult)
13+
print " returned: " + str(gotResult)
14+
print ""
15+
global errors
16+
errors = errors + 1
17+
18+
tester('ntpath.splitdrive("c:\\foo\\bar")', ('c:', '\\foo\\bar'))
19+
tester('ntpath.splitdrive("\\\\conky\\mountpoint\\foo\\bar")', ('\\\\conky\\mountpoint', '\\foo\\bar'))
20+
tester('ntpath.splitdrive("c:/foo/bar")', ('c:', '/foo/bar'))
21+
tester('ntpath.splitdrive("//conky/mountpoint/foo/bar")', ('//conky/mountpoint', '/foo/bar'))
22+
23+
tester('ntpath.split("c:\\foo\\bar")', ('c:\\foo', 'bar'))
24+
tester('ntpath.split("\\\\conky\\mountpoint\\foo\\bar")', ('\\\\conky\\mountpoint\\foo', 'bar'))
25+
26+
tester('ntpath.split("c:\\")', ('c:\\', ''))
27+
tester('ntpath.split("\\\\conky\\mountpoint\\")', ('\\\\conky\\mountpoint\\', ''))
28+
29+
tester('ntpath.split("c:/")', ('c:/', ''))
30+
tester('ntpath.split("//conky/mountpoint/")', ('//conky/mountpoint/', ''))
31+
32+
tester('ntpath.isabs("c:\\")', 1)
33+
tester('ntpath.isabs("\\\\conky\\mountpoint\\")', 1)
34+
tester('ntpath.isabs("\\foo")', 1)
35+
tester('ntpath.isabs("\\foo\\bar")', 1)
36+
37+
if errors:
38+
print str(errors) + " errors."
39+
else:
40+
print "No errors. Thank your lucky stars."
41+

0 commit comments

Comments
 (0)