Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
4d29986e
Commit
4d29986e
authored
Aug 12, 1998
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
The usual.
parent
3bbd006a
Changes
25
Show whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
363 additions
and
181 deletions
+363
-181
Lib/dos-8x3/cgihttps.py
Lib/dos-8x3/cgihttps.py
+4
-1
Lib/dos-8x3/configpa.py
Lib/dos-8x3/configpa.py
+99
-45
Lib/dos-8x3/exceptio.py
Lib/dos-8x3/exceptio.py
+32
-3
Lib/dos-8x3/fileinpu.py
Lib/dos-8x3/fileinpu.py
+1
-0
Lib/dos-8x3/macurl2p.py
Lib/dos-8x3/macurl2p.py
+10
-4
Lib/dos-8x3/mimetool.py
Lib/dos-8x3/mimetool.py
+3
-4
Lib/dos-8x3/mimetype.py
Lib/dos-8x3/mimetype.py
+25
-2
Lib/dos-8x3/mimewrit.py
Lib/dos-8x3/mimewrit.py
+1
-1
Lib/dos-8x3/multifil.py
Lib/dos-8x3/multifil.py
+52
-29
Lib/dos-8x3/posixpat.py
Lib/dos-8x3/posixpat.py
+18
-0
Lib/dos-8x3/py_compi.py
Lib/dos-8x3/py_compi.py
+0
-1
Lib/dos-8x3/queue.py
Lib/dos-8x3/queue.py
+25
-25
Lib/dos-8x3/rlcomple.py
Lib/dos-8x3/rlcomple.py
+4
-1
Lib/dos-8x3/socketse.py
Lib/dos-8x3/socketse.py
+7
-2
Lib/dos-8x3/test_arr.py
Lib/dos-8x3/test_arr.py
+28
-1
Lib/dos-8x3/test_fcn.py
Lib/dos-8x3/test_fcn.py
+1
-1
Lib/dos-8x3/test_img.py
Lib/dos-8x3/test_img.py
+1
-9
Lib/dos-8x3/test_rgb.py
Lib/dos-8x3/test_rgb.py
+1
-14
Lib/dos-8x3/test_sun.py
Lib/dos-8x3/test_sun.py
+1
-14
Lib/dos-8x3/test_sup.py
Lib/dos-8x3/test_sup.py
+12
-0
Lib/dos-8x3/test_thr.py
Lib/dos-8x3/test_thr.py
+8
-8
Lib/dos-8x3/test_tok.py
Lib/dos-8x3/test_tok.py
+1
-13
Lib/dos-8x3/test_typ.py
Lib/dos-8x3/test_typ.py
+25
-0
Lib/dos-8x3/test_zli.py
Lib/dos-8x3/test_zli.py
+3
-3
Lib/dos-8x3/userlist.py
Lib/dos-8x3/userlist.py
+1
-0
No files found.
Lib/dos-8x3/cgihttps.py
View file @
4d29986e
...
...
@@ -133,7 +133,10 @@ class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
# AUTH_TYPE
# REMOTE_USER
# REMOTE_IDENT
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
...
...
Lib/dos-8x3/configpa.py
View file @
4d29986e
...
...
@@ -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-Z
a
-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
"
"
\
t
section: [%s]
\
n
"
"
\
t
option : %s
\
n
"
"
\
t
key : %s
\
n
"
"
\
t
rawval : %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.
\
n
file: %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
<
header
>
[
-
\
w
]
+
)
' # `-'
,
`
_
' or any alphanum
r'
\
]
' # ]
)
__OPTCRE = re.compile(
r'
(
?
P
<
option
>
[
-
.
\
w
]
+
)
' # - . _ alphanum
r'
[
\
t
]
*
[:
=
][
\
t
]
*
' # any number of space/tab,
# followed by separator
# (either : or =), followed
# by any # space/tab
r'
(
?
P
<
value
>
.
*
)
$
' # everything up to eol
)
def __read(self, fp):
"""Parse a sectioned setup file.
...
...
@@ -214,6 +251,7 @@ class ConfigParser:
cursect = None # None, or a dictionary
optname = None
lineno = 0
e = None # None, or an exception
while 1:
line = fp.readline()
if not line:
...
...
@@ -226,31 +264,47 @@ class ConfigParser:
and line[0] == "r": # no leading whitespace
continue
# continuation line?
if line[0] in '
\
t
' and cursect
<>
None and optname:
if line[0] in '
\
t
' and cursect
is not
None and optname:
value = string.strip(line)
if value:
cursect = cursect[optname] + '
\
n
' + value
# a section header?
elif secthead_cre.match(line) >= 0:
sectname = secthead_cre.group(1)
cursect[optname] = cursect[optname] + '
\
n
' + value
# a section header or option header?
else:
# is it a section header?
mo = self.__SECTCRE.match(line)
if mo:
sectname = mo.group('header')
if self.__sections.has_key(sectname):
cursect = self.__sections[sectname]
elif sectname == DEFAULTSECT:
cursect = self.__defaults
else:
cursect = {'name
': sectname}
cursect = {'__name__
': sectname}
self.__sections[sectname] = cursect
# So sections can't start with a continuation line.
# So sections can't start with a continuation line
optname = None
# no section header in the file?
elif cursect is None:
raise MissingSectionHeaderError(fp.name, lineno, `line`)
# an option line?
elif option_cre.match(line) >= 0:
optname, optval = option_cre.group(1, 3)
else:
mo = self.__OPTCRE.match(line)
if mo:
optname, optval = mo.group('option', 'value')
optname = string.lower(optname)
optval = string.strip(optval)
# allow empty values
if optval == '""':
optval = ''
cursect[optname] = optval
# an error
else:
print 'Error in %s at %d: %s', (fp.name, lineno, `line`)
# a non-fatal parsing error occurred. set up the
# exception but keep going. the exception will be
# raised at the end of the file and will contain a
# list of all bogus lines
if not e:
e = ParsingError(fp.name)
e.append(lineno, `line`)
# if any parsing errors occurred, raise an exception
if e:
raise e
Lib/dos-8x3/exceptio.py
View file @
4d29986e
...
...
@@ -80,15 +80,44 @@ class SyntaxError(StandardError):
def
__str__
(
self
):
return
str
(
self
.
msg
)
class
IOError
(
StandardError
):
class
EnvironmentError
(
StandardError
):
"""Base class for exceptions that occur outside the Python system.
Primarily used as a base class for OSError and IOError."""
def
__init__
(
self
,
*
args
):
self
.
args
=
args
self
.
errno
=
None
self
.
strerror
=
None
self
.
filename
=
None
if
len
(
args
)
==
3
:
# open() errors give third argument which is the filename. BUT,
# so common in-place unpacking doesn't break, e.g.:
#
# except IOError, (errno, strerror):
#
# we hack args so that it only contains two items. This also
# means we need our own __str__() which prints out the filename
# when it was supplied.
self
.
errno
,
self
.
strerror
,
self
.
filename
=
args
self
.
args
=
args
[
0
:
2
]
if
len
(
args
)
==
2
:
# common case: PyErr_SetFromErrno()
self
.
errno
=
args
[
0
]
self
.
strerror
=
args
[
1
]
self
.
errno
,
self
.
strerror
=
args
def
__str__
(
self
):
if
self
.
filename
is
not
None
:
return
'[Errno %s] %s: %s'
%
(
self
.
errno
,
self
.
strerror
,
repr
(
self
.
filename
))
elif
self
.
errno
and
self
.
strerror
:
return
'[Errno %s] %s'
%
(
self
.
errno
,
self
.
strerror
)
else
:
return
StandardError
.
__str__
(
self
)
class
IOError
(
EnvironmentError
):
pass
class
OSError
(
EnvironmentError
):
"""Used by the posix module."""
pass
class
RuntimeError
(
StandardError
):
pass
...
...
Lib/dos-8x3/fileinpu.py
View file @
4d29986e
...
...
@@ -142,6 +142,7 @@ class FileInput:
self
.
_filelineno
=
0
self
.
_file
=
None
self
.
_isstdin
=
0
self
.
_backupfilename
=
None
def
__del__
(
self
):
self
.
close
()
...
...
Lib/dos-8x3/macurl2p.py
View file @
4d29986e
...
...
@@ -29,7 +29,7 @@ def url2pathname(pathname):
i
=
i
+
1
if
not
components
[
0
]:
# Absolute unix path, don't start with colon
r
eturn
string
.
join
(
components
[
1
:],
':'
)
r
v
=
string
.
join
(
components
[
1
:],
':'
)
else
:
# relative unix path, start with colon. First replace
# leading .. by empty strings (giving ::file)
...
...
@@ -37,7 +37,9 @@ def url2pathname(pathname):
while
i
<
len
(
components
)
and
components
[
i
]
==
'..'
:
components
[
i
]
=
''
i
=
i
+
1
return
':'
+
string
.
join
(
components
,
':'
)
rv
=
':'
+
string
.
join
(
components
,
':'
)
# and finally unquote slashes and other funny characters
return
urllib
.
unquote
(
rv
)
def
pathname2url
(
pathname
):
"convert mac pathname to /-delimited pathname"
...
...
@@ -54,13 +56,17 @@ def pathname2url(pathname):
if
components
[
i
]
==
''
:
components
[
i
]
=
'..'
# Truncate names longer than 31 bytes
components
=
map
(
lambda
x
:
x
[:
31
]
,
components
)
components
=
map
(
_pncomp2url
,
components
)
if
os
.
path
.
isabs
(
pathname
):
return
'/'
+
string
.
join
(
components
,
'/'
)
else
:
return
string
.
join
(
components
,
'/'
)
def
_pncomp2url
(
component
):
component
=
urllib
.
quote
(
component
[:
31
],
safe
=
''
)
# We want to quote slashes
return
component
def
test
():
for
url
in
[
"index.html"
,
"bar/index.html"
,
...
...
Lib/dos-8x3/mimetool.py
View file @
4d29986e
...
...
@@ -109,7 +109,7 @@ _prefix = None
def
choose_boundary
():
global
_prefix
import
time
import
rand
import
rand
om
if
_prefix
==
None
:
import
socket
import
os
...
...
@@ -122,10 +122,9 @@ def choose_boundary():
pid
=
`os.getpid()`
except
:
pid
=
'1'
seed
=
`rand.rand()`
_prefix
=
hostid
+
'.'
+
uid
+
'.'
+
pid
timestamp
=
`int(time.time())`
seed
=
`rand
.rand(
)`
timestamp
=
'%.3f'
%
time
.
time
()
seed
=
`rand
om.randint(0, 32767
)`
return
_prefix
+
'.'
+
timestamp
+
'.'
+
seed
...
...
Lib/dos-8x3/mimetype.py
View file @
4d29986e
"""Guess the MIME type of a file.
This module defines
one useful function
:
This module defines
two useful functions
:
guess_type(url) -- guess the MIME type and encoding of a URL.
guess_extension(type) -- guess the extension for a given MIME type.
It also contains the following, for tuning the behavior:
Data:
...
...
@@ -27,6 +29,8 @@ import posixpath
knownfiles
=
[
"/usr/local/etc/httpd/conf/mime.types"
,
"/usr/local/lib/netscape/mime.types"
,
"/usr/local/etc/httpd/conf/mime.types"
,
# Apache 1.2
"/usr/local/etc/mime.types"
,
# Apache 1.3
]
inited
=
0
...
...
@@ -44,7 +48,7 @@ def guess_type(url):
The suffixes .tgz, .taz and .tz (case sensitive!) are all mapped
to ".tar.gz". (This is table-driven too, using the dictionary
suffix
es
_map).
suffix_map).
"""
if
not
inited
:
...
...
@@ -64,6 +68,24 @@ def guess_type(url):
else
:
return
None
,
encoding
def
guess_extension
(
type
):
"""Guess the extension for a file based on its MIME type.
Return value is a string giving a filename extension, including the
leading dot ('.'). The extension is not guaranteed to have been
associated with any particular data stream, but would be mapped to the
MIME type `type' by guess_type(). If no extension can be guessed for
`type', None is returned.
"""
global
inited
if
not
inited
:
init
()
type
=
string
.
lower
(
type
)
for
ext
,
stype
in
types_map
.
items
():
if
type
==
stype
:
return
ext
return
None
def
init
(
files
=
None
):
global
inited
for
file
in
files
or
knownfiles
:
...
...
@@ -184,6 +206,7 @@ types_map = {
'.ustar'
:
'application/x-ustar'
,
'.wav'
:
'audio/x-wav'
,
'.xbm'
:
'image/x-xbitmap'
,
'.xml'
:
'text/xml'
,
'.xpm'
:
'image/x-xpixmap'
,
'.xwd'
:
'image/x-xwindowdump'
,
'.zip'
:
'application/zip'
,
...
...
Lib/dos-8x3/mimewrit.py
View file @
4d29986e
...
...
@@ -125,4 +125,4 @@ class MimeWriter:
if
__name__
==
'__main__'
:
print
"To test the MimeWriter module, run TestMimeWriter.py."
import
test.test_MimeWriter
Lib/dos-8x3/multifil.py
View file @
4d29986e
...
...
@@ -18,24 +18,28 @@
#
# The latter sequence may be used recursively at (A).
# It is also allowed to use multiple push()...pop() sequences.
# Note that if a nested multipart message is terminated by a separator
# for an outer message, this is not reported, even though it is really
# illegal input.
#
# If seekable is given as 0, the class code will not do the bookeeping
# it normally attempts in order to make seeks relative to the beginning of the
# current file part. This may be useful when using MultiFile with a non-
# seekable stream object.
import
sys
import
string
err
=
sys
.
stderr
.
write
Error
=
'multifile.Error'
class
MultiFile
:
#
def
__init__
(
self
,
fp
):
seekable
=
0
#
def
__init__
(
self
,
fp
,
seekable
=
1
):
self
.
fp
=
fp
self
.
stack
=
[]
# Grows down
self
.
level
=
0
self
.
last
=
0
if
seekable
:
self
.
seekable
=
1
self
.
start
=
self
.
fp
.
tell
()
self
.
posstack
=
[]
# Grows down
#
...
...
@@ -62,36 +66,44 @@ class MultiFile:
self
.
last
=
0
#
def
readline
(
self
):
if
self
.
level
>
0
:
return
''
if
self
.
level
>
0
:
return
''
line
=
self
.
fp
.
readline
()
# Real EOF?
if
not
line
:
self
.
level
=
len
(
self
.
stack
)
self
.
last
=
(
self
.
level
>
0
)
if
self
.
last
:
err
(
'*** Sudden EOF in MultiFile.readline()
\
n
'
)
raise
Error
,
'sudden EOF in MultiFile.readline()'
return
''
if
line
[:
2
]
<>
'--'
:
return
line
n
=
len
(
line
)
k
=
n
while
k
>
0
and
line
[
k
-
1
]
in
string
.
whitespace
:
k
=
k
-
1
mark
=
line
[
2
:
k
]
if
mark
[
-
2
:]
==
'--'
:
mark1
=
mark
[:
-
2
]
else
:
mark1
=
None
assert
self
.
level
==
0
# Fast check to see if this is just data
if
self
.
is_data
(
line
):
return
line
else
:
# Ignore trailing whitespace on marker lines
k
=
len
(
line
)
-
1
;
while
line
[
k
]
in
string
.
whitespace
:
k
=
k
-
1
marker
=
line
[:
k
+
1
]
# No? OK, try to match a boundary.
# Return the line (unstripped) if we don't.
for
i
in
range
(
len
(
self
.
stack
)):
sep
=
self
.
stack
[
i
]
if
sep
==
mark
:
if
marker
==
self
.
section_divider
(
sep
)
:
self
.
last
=
0
break
elif
mark
1
<>
None
and
sep
==
mark1
:
elif
mark
er
==
self
.
end_marker
(
sep
)
:
self
.
last
=
1
break
else
:
return
line
# Get here after break out of loop
# We only get here if we see a section divider or EOM line
if
self
.
seekable
:
self
.
lastpos
=
self
.
tell
()
-
len
(
line
)
self
.
level
=
i
+
1
if
self
.
level
>
1
:
err
(
'*** Missing endmarker in MultiFile.readline()
\
n
'
)
raise
Error
,
'Missing endmarker in MultiFile.readline()'
return
''
#
def
readlines
(
self
):
...
...
@@ -111,6 +123,7 @@ class MultiFile:
return
0
self
.
level
=
0
self
.
last
=
0
if
self
.
seekable
:
self
.
start
=
self
.
fp
.
tell
()
return
1
#
...
...
@@ -118,6 +131,7 @@ class MultiFile:
if
self
.
level
>
0
:
raise
Error
,
'bad MultiFile.push() call'
self
.
stack
.
insert
(
0
,
sep
)
if
self
.
seekable
:
self
.
posstack
.
insert
(
0
,
self
.
start
)
self
.
start
=
self
.
fp
.
tell
()
#
...
...
@@ -130,8 +144,17 @@ class MultiFile:
abslastpos
=
self
.
lastpos
+
self
.
start
self
.
level
=
max
(
0
,
self
.
level
-
1
)
del
self
.
stack
[
0
]
if
self
.
seekable
:
self
.
start
=
self
.
posstack
[
0
]
del
self
.
posstack
[
0
]
if
self
.
level
>
0
:
self
.
lastpos
=
abslastpos
-
self
.
start
#
def
is_data
(
self
,
line
):
return
line
[:
2
]
<>
'--'
#
def
section_divider
(
self
,
str
):
return
"--"
+
str
#
def
end_marker
(
self
,
str
):
return
"--"
+
str
+
"--"
Lib/dos-8x3/posixpat.py
View file @
4d29986e
...
...
@@ -128,6 +128,24 @@ def commonprefix(m):
return
prefix
# Get size, mtime, atime of files.
def
getsize
(
filename
):
"""Return the size of a file, reported by os.stat()."""
st
=
os
.
stat
(
filename
)
return
st
[
stat
.
ST_SIZE
]
def
getmtime
(
filename
):
"""Return the last modification time of a file, reported by os.stat()."""
st
=
os
.
stat
(
filename
)
return
st
[
stat
.
ST_MTIME
]
def
getatime
(
filename
):
"""Return the last access time of a file, reported by os.stat()."""
st
=
os
.
stat
(
filename
)
return
st
[
stat
.
ST_MTIME
]
# Is a path a symbolic link?
# This will always return false on systems where os.lstat doesn't exist.
...
...
Lib/dos-8x3/py_compi.py
View file @
4d29986e
...
...
@@ -65,4 +65,3 @@ def compile(file, cfile=None, dfile=None):
if
os
.
name
==
'mac'
:
import
macfs
macfs
.
FSSpec
(
cfile
).
SetCreatorType
(
'Pyth'
,
'PYC '
)
macfs
.
FSSpec
(
file
).
SetCreatorType
(
'Pyth'
,
'TEXT'
)
Lib/dos-8x3/queue.py
View file @
4d29986e
...
...
@@ -19,28 +19,28 @@ class Queue:
self
.
_init
(
maxsize
)
self
.
mutex
=
thread
.
allocate_lock
()
self
.
esema
=
thread
.
allocate_lock
()
self
.
esema
.
acquire
_lock
()
self
.
esema
.
acquire
()
self
.
fsema
=
thread
.
allocate_lock
()
def
qsize
(
self
):
"""Returns the approximate size of the queue (not reliable!)."""
self
.
mutex
.
acquire
_lock
()
self
.
mutex
.
acquire
()
n
=
self
.
_qsize
()
self
.
mutex
.
release
_lock
()
self
.
mutex
.
release
()
return
n
def
empty
(
self
):
"""Returns 1 if the queue is empty, 0 otherwise (not reliable!)."""
self
.
mutex
.
acquire
_lock
()
self
.
mutex
.
acquire
()
n
=
self
.
_empty
()
self
.
mutex
.
release
_lock
()
self
.
mutex
.
release
()
return
n
def
full
(
self
):
"""Returns 1 if the queue is full, 0 otherwise (not reliable!)."""
self
.
mutex
.
acquire
_lock
()
self
.
mutex
.
acquire
()
n
=
self
.
_full
()
self
.
mutex
.
release
_lock
()
self
.
mutex
.
release
()
return
n
def
put
(
self
,
item
):
...
...
@@ -48,30 +48,30 @@ class Queue:
If the queue is full, block until a free slot is avaiable.
"""
self
.
fsema
.
acquire
_lock
()
self
.
mutex
.
acquire
_lock
()
self
.
fsema
.
acquire
()
self
.
mutex
.
acquire
()
was_empty
=
self
.
_empty
()
self
.
_put
(
item
)
if
was_empty
:
self
.
esema
.
release
_lock
()
self
.
esema
.
release
()
if
not
self
.
_full
():
self
.
fsema
.
release
_lock
()
self
.
mutex
.
release
_lock
()
self
.
fsema
.
release
()
self
.
mutex
.
release
()
def
get
(
self
):
"""Gets and returns an item from the queue.
This method blocks if necessary until an item is available.
"""
self
.
esema
.
acquire
_lock
()
self
.
mutex
.
acquire
_lock
()
self
.
esema
.
acquire
()
self
.
mutex
.
acquire
()
was_full
=
self
.
_full
()
item
=
self
.
_get
()
if
was_full
:
self
.
fsema
.
release
_lock
()
self
.
fsema
.
release
()
if
not
self
.
_empty
():
self
.
esema
.
release
_lock
()
self
.
mutex
.
release
_lock
()
self
.
esema
.
release
()
self
.
mutex
.
release
()
return
item
# Get an item from the queue if one is immediately available,
...
...
@@ -83,27 +83,27 @@ class Queue:
this raises the Empty exception if the queue is empty or
temporarily unavailable.
"""
locked
=
self
.
esema
.
acquire
_lock
(
0
)
self
.
mutex
.
acquire
_lock
()
locked
=
self
.
esema
.
acquire
(
0
)
self
.
mutex
.
acquire
()
if
self
.
_empty
():
# The queue is empty -- we can't have esema
self
.
mutex
.
release
_lock
()
self
.
mutex
.
release
()
raise
Empty
if
not
locked
:
locked
=
self
.
esema
.
acquire
_lock
(
0
)
locked
=
self
.
esema
.
acquire
(
0
)
if
not
locked
:
# Somebody else has esema
# but we have mutex --
# go out of their way
self
.
mutex
.
release
_lock
()
self
.
mutex
.
release
()
raise
Empty
was_full
=
self
.
_full
()
item
=
self
.
_get
()
if
was_full
:
self
.
fsema
.
release
_lock
()
self
.
fsema
.
release
()
if
not
self
.
_empty
():
self
.
esema
.
release
_lock
()
self
.
mutex
.
release
_lock
()
self
.
esema
.
release
()
self
.
mutex
.
release
()
return
item
# XXX Need to define put_nowait() as well.
...
...
Lib/dos-8x3/rlcomple.py
View file @
4d29986e
...
...
@@ -58,7 +58,10 @@ class Completer:
self
.
matches
=
self
.
attr_matches
(
text
)
else
:
self
.
matches
=
self
.
global_matches
(
text
)
try
:
return
self
.
matches
[
state
]
except
IndexError
:
return
None
def
global_matches
(
self
,
text
):
"""Compute matches when text is a simple name.
...
...
Lib/dos-8x3/socketse.py
View file @
4d29986e
...
...
@@ -265,7 +265,12 @@ class UDPServer(TCPServer):
max_packet_size
=
8192
def
get_request
(
self
):
return
self
.
socket
.
recvfrom
(
self
.
max_packet_size
)
data
,
client_addr
=
self
.
socket
.
recvfrom
(
self
.
max_packet_size
)
return
(
data
,
self
.
socket
),
client_addr
def
server_activate
(
self
):
# No need to call listen() for UDP.
pass
if
hasattr
(
socket
,
'AF_UNIX'
):
...
...
@@ -411,4 +416,4 @@ class DatagramRequestHandler(BaseRequestHandler):
self
.
wfile
=
StringIO
.
StringIO
(
self
.
packet
)
def
finish
(
self
):
self
.
socket
.
send
(
self
.
wfile
.
getvalue
()
)
self
.
socket
.
send
to
(
self
.
wfile
.
getvalue
(),
self
.
client_address
)
Lib/dos-8x3/test_arr.py
View file @
4d29986e
...
...
@@ -3,7 +3,7 @@
Roger E. Masse
"""
import
array
from
test_support
import
verbose
,
TESTFN
,
unlink
from
test_support
import
verbose
,
TESTFN
,
unlink
,
TestFailed
def
main
():
...
...
@@ -54,6 +54,33 @@ def testtype(type, example):
print
'array of %s converted to a string: '
\
%
a
.
typecode
,
`a.tostring()`
if
type
==
'c'
:
a
=
array
.
array
(
type
,
"abcde"
)
a
[:
-
1
]
=
a
if
a
!=
array
.
array
(
type
,
"abcdee"
):
raise
TestFailed
,
"array(%s) self-slice-assign (head)"
%
`type`
a
=
array
.
array
(
type
,
"abcde"
)
a
[
1
:]
=
a
if
a
!=
array
.
array
(
type
,
"aabcde"
):
raise
TestFailed
,
"array(%s) self-slice-assign (tail)"
%
`type`
a
=
array
.
array
(
type
,
"abcde"
)
a
[
1
:
-
1
]
=
a
if
a
!=
array
.
array
(
type
,
"aabcdee"
):
raise
TestFailed
,
"array(%s) self-slice-assign (cntr)"
%
`type`
else
:
a
=
array
.
array
(
type
,
[
1
,
2
,
3
,
4
,
5
])
a
[:
-
1
]
=
a
if
a
!=
array
.
array
(
type
,
[
1
,
2
,
3
,
4
,
5
,
5
]):
raise
TestFailed
,
"array(%s) self-slice-assign (head)"
%
`type`
a
=
array
.
array
(
type
,
[
1
,
2
,
3
,
4
,
5
])
a
[
1
:]
=
a
if
a
!=
array
.
array
(
type
,
[
1
,
1
,
2
,
3
,
4
,
5
]):
raise
TestFailed
,
"array(%s) self-slice-assign (tail)"
%
`type`
a
=
array
.
array
(
type
,
[
1
,
2
,
3
,
4
,
5
])
a
[
1
:
-
1
]
=
a
if
a
!=
array
.
array
(
type
,
[
1
,
1
,
2
,
3
,
4
,
5
,
5
]):
raise
TestFailed
,
"array(%s) self-slice-assign (cntr)"
%
`type`
main
()
Lib/dos-8x3/test_fcn.py
View file @
4d29986e
...
...
@@ -16,7 +16,7 @@ rv = fcntl.fcntl(f.fileno(), FCNTL.F_SETFL, os.O_NONBLOCK)
if
verbose
:
print
'Status from fnctl with O_NONBLOCK: '
,
rv
if
sys
.
platform
in
(
'netbsd1'
,
'freebsd2'
,
'freebsd3'
):
if
sys
.
platform
in
(
'netbsd1'
,
'freebsd2'
,
'freebsd3'
,
'bsdos2'
,
'bsdos3'
):
lockdata
=
struct
.
pack
(
'lxxxxlxxxxlhh'
,
0
,
0
,
0
,
FCNTL
.
F_WRLCK
,
0
)
elif
sys
.
platform
in
[
'aix3'
,
'aix4'
]:
lockdata
=
struct
.
pack
(
'hhlllii'
,
FCNTL
.
F_WRLCK
,
0
,
0
,
0
,
0
,
0
,
0
)
...
...
Lib/dos-8x3/test_img.py
View file @
4d29986e
...
...
@@ -4,7 +4,7 @@
Roger E. Masse
"""
from
test_support
import
verbose
,
unlink
from
test_support
import
verbose
,
unlink
,
findfile
import
imgfile
,
uu
,
os
...
...
@@ -23,14 +23,6 @@ def main():
unlink
(
'test.rgb'
)
unlink
(
'greytest.rgb'
)
def
findfile
(
file
):
if
os
.
path
.
isabs
(
file
):
return
file
import
sys
for
dn
in
sys
.
path
:
fn
=
os
.
path
.
join
(
dn
,
file
)
if
os
.
path
.
exists
(
fn
):
return
fn
return
file
def
testimage
(
name
):
"""Run through the imgfile's battery of possible methods
on the image passed in name.
...
...
Lib/dos-8x3/test_rgb.py
View file @
4d29986e
...
...
@@ -2,25 +2,12 @@
import
rgbimg
,
os
,
uu
from
test_support
import
verbose
,
unlink
from
test_support
import
verbose
,
unlink
,
findfile
error
=
'test_rgbimg.error'
print
'RGBimg test suite:'
def
findfile
(
file
):
if
os
.
path
.
isabs
(
file
):
return
file
import
sys
path
=
sys
.
path
try
:
path
=
[
os
.
path
.
dirname
(
__file__
)]
+
path
except
NameError
:
pass
for
dn
in
path
:
fn
=
os
.
path
.
join
(
dn
,
file
)
if
os
.
path
.
exists
(
fn
):
return
fn
return
file
def
testimg
(
rgb_file
,
raw_file
):
rgb_file
=
findfile
(
rgb_file
)
raw_file
=
findfile
(
raw_file
)
...
...
Lib/dos-8x3/test_sun.py
View file @
4d29986e
from
test_support
import
verbose
,
TestFailed
from
test_support
import
verbose
,
findfile
,
TestFailed
import
sunaudiodev
import
os
def
findfile
(
file
):
if
os
.
path
.
isabs
(
file
):
return
file
import
sys
path
=
sys
.
path
try
:
path
=
[
os
.
path
.
dirname
(
__file__
)]
+
path
except
NameError
:
pass
for
dn
in
path
:
fn
=
os
.
path
.
join
(
dn
,
file
)
if
os
.
path
.
exists
(
fn
):
return
fn
return
file
def
play_sound_file
(
path
):
fp
=
open
(
path
,
'r'
)
data
=
fp
.
read
()
...
...
Lib/dos-8x3/test_sup.py
View file @
4d29986e
...
...
@@ -41,3 +41,15 @@ def fcmp(x, y): # fuzzy comparison function
TESTFN
=
'@test'
# Filename used for testing
from
os
import
unlink
def
findfile
(
file
,
here
=
__file__
):
import
os
if
os
.
path
.
isabs
(
file
):
return
file
import
sys
path
=
sys
.
path
path
=
[
os
.
path
.
dirname
(
here
)]
+
path
for
dn
in
path
:
fn
=
os
.
path
.
join
(
dn
,
file
)
if
os
.
path
.
exists
(
fn
):
return
fn
return
file
Lib/dos-8x3/test_thr.py
View file @
4d29986e
...
...
@@ -3,12 +3,12 @@
# Create a bunch of threads, let each do some work, wait until all are done
from
test_support
import
verbose
import
wh
random
import
random
import
thread
import
time
mutex
=
thread
.
allocate_lock
()
whmutex
=
thread
.
allocate_lock
()
# for calls to wh
random
rmutex
=
thread
.
allocate_lock
()
# for calls to
random
running
=
0
done
=
thread
.
allocate_lock
()
done
.
acquire
()
...
...
@@ -17,9 +17,9 @@ numtasks = 10
def
task
(
ident
):
global
running
wh
mutex
.
acquire
()
delay
=
wh
random
.
random
()
*
numtasks
wh
mutex
.
release
()
r
mutex
.
acquire
()
delay
=
random
.
random
()
*
numtasks
r
mutex
.
release
()
if
verbose
:
print
'task'
,
ident
,
'will run for'
,
round
(
delay
,
1
),
'sec'
time
.
sleep
(
delay
)
...
...
@@ -85,9 +85,9 @@ def task2(ident):
# of the current one
delay
=
0.001
else
:
wh
mutex
.
acquire
()
delay
=
wh
random
.
random
()
*
numtasks
wh
mutex
.
release
()
r
mutex
.
acquire
()
delay
=
random
.
random
()
*
numtasks
r
mutex
.
release
()
if
verbose
:
print
'task'
,
ident
,
'will run for'
,
round
(
delay
,
1
),
'sec'
time
.
sleep
(
delay
)
...
...
Lib/dos-8x3/test_tok.py
View file @
4d29986e
from
test_support
import
verbose
from
test_support
import
verbose
,
findfile
import
tokenize
,
os
,
sys
def
findfile
(
file
):
if
os
.
path
.
isabs
(
file
):
return
file
path
=
sys
.
path
try
:
path
=
[
os
.
path
.
dirname
(
__file__
)]
+
path
except
NameError
:
pass
for
dn
in
path
:
fn
=
os
.
path
.
join
(
dn
,
file
)
if
os
.
path
.
exists
(
fn
):
return
fn
return
file
if
verbose
:
print
'starting...'
file
=
open
(
findfile
(
'tokenize_tests.py'
))
...
...
Lib/dos-8x3/test_typ.py
View file @
4d29986e
...
...
@@ -78,6 +78,18 @@ if (-12L) + 24L <> 12L: raise TestFailed, 'long op'
if
(
-
12L
)
+
(
-
24L
)
<>
-
36L
:
raise
TestFailed
,
'long op'
if
not
12L
<
24L
:
raise
TestFailed
,
'long op'
if
not
-
24L
<
-
12L
:
raise
TestFailed
,
'long op'
x
=
sys
.
maxint
if
int
(
long
(
x
))
!=
x
:
raise
TestFailed
,
'long op'
try
:
int
(
long
(
x
)
+
1L
)
except
OverflowError
:
pass
else
:
raise
TestFailed
,
'long op'
x
=
-
x
if
int
(
long
(
x
))
!=
x
:
raise
TestFailed
,
'long op'
x
=
x
-
1
if
int
(
long
(
x
))
!=
x
:
raise
TestFailed
,
'long op'
try
:
int
(
long
(
x
)
-
1L
)
except
OverflowError
:
pass
else
:
raise
TestFailed
,
'long op'
print
'6.4.3 Floating point numbers'
if
12.0
+
24.0
<>
36.0
:
raise
TestFailed
,
'float op'
if
12.0
+
(
-
24.0
)
<>
-
12.0
:
raise
TestFailed
,
'float op'
...
...
@@ -122,6 +134,19 @@ if 0*[1,2,3] <> []: raise TestFailed, 'list repetition 0*'
if
min
([
1
,
2
])
<>
1
or
max
([
1
,
2
])
<>
2
:
raise
TestFailed
,
'min/max list'
if
0
in
[
0
,
1
,
2
]
and
1
in
[
0
,
1
,
2
]
and
2
in
[
0
,
1
,
2
]
and
3
not
in
[
0
,
1
,
2
]:
pass
else
:
raise
TestFailed
,
'in/not in list'
a
=
[
1
,
2
,
3
,
4
,
5
]
a
[:
-
1
]
=
a
if
a
!=
[
1
,
2
,
3
,
4
,
5
,
5
]:
raise
TestFailed
,
"list self-slice-assign (head)"
a
=
[
1
,
2
,
3
,
4
,
5
]
a
[
1
:]
=
a
if
a
!=
[
1
,
1
,
2
,
3
,
4
,
5
]:
raise
TestFailed
,
"list self-slice-assign (tail)"
a
=
[
1
,
2
,
3
,
4
,
5
]
a
[
1
:
-
1
]
=
a
if
a
!=
[
1
,
1
,
2
,
3
,
4
,
5
,
5
]:
raise
TestFailed
,
"list self-slice-assign (center)"
print
'6.5.3a Additional list operations'
a
=
[
0
,
1
,
2
,
3
,
4
]
...
...
Lib/dos-8x3/test_zli.py
View file @
4d29986e
...
...
@@ -11,9 +11,9 @@ except ImportError:
buf
=
file
.
read
()
*
8
file
.
close
()
# test the chucksums
print
zlib
.
crc32
(
'penguin'
),
zlib
.
crc32
(
'penguin'
,
1
)
print
zlib
.
adler32
(
'penguin'
),
zlib
.
adler32
(
'penguin'
,
1
)
# test the chucksums
(hex so the test doesn't break on 64-bit machines)
print
hex
(
zlib
.
crc32
(
'penguin'
)),
hex
(
zlib
.
crc32
(
'penguin'
,
1
)
)
print
hex
(
zlib
.
adler32
(
'penguin'
)),
hex
(
zlib
.
adler32
(
'penguin'
,
1
)
)
# make sure we generate some expected errors
try
:
...
...
Lib/dos-8x3/userlist.py
View file @
4d29986e
...
...
@@ -43,6 +43,7 @@ class UserList:
__rmul__
=
__mul__
def
append
(
self
,
item
):
self
.
data
.
append
(
item
)
def
insert
(
self
,
i
,
item
):
self
.
data
.
insert
(
i
,
item
)
def
pop
(
self
,
i
=-
1
):
return
self
.
data
.
pop
(
i
)
def
remove
(
self
,
item
):
self
.
data
.
remove
(
item
)
def
count
(
self
,
item
):
return
self
.
data
.
count
(
item
)
def
index
(
self
,
item
):
return
self
.
data
.
index
(
item
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment