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
495ad3c8
Commit
495ad3c8
authored
Jan 15, 2001
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Whitespace normalization.
parent
0c9886d5
Changes
14
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
743 additions
and
743 deletions
+743
-743
Lib/sched.py
Lib/sched.py
+27
-27
Lib/sgmllib.py
Lib/sgmllib.py
+2
-2
Lib/shelve.py
Lib/shelve.py
+98
-98
Lib/shlex.py
Lib/shlex.py
+4
-4
Lib/shutil.py
Lib/shutil.py
+2
-2
Lib/smtplib.py
Lib/smtplib.py
+31
-31
Lib/sndhdr.py
Lib/sndhdr.py
+120
-120
Lib/socket.py
Lib/socket.py
+1
-1
Lib/stat.py
Lib/stat.py
+9
-9
Lib/statcache.py
Lib/statcache.py
+42
-42
Lib/statvfs.py
Lib/statvfs.py
+10
-10
Lib/string.py
Lib/string.py
+1
-1
Lib/sunau.py
Lib/sunau.py
+366
-366
Lib/sunaudio.py
Lib/sunaudio.py
+30
-30
No files found.
Lib/sched.py
View file @
495ad3c8
...
...
@@ -41,10 +41,10 @@ class scheduler:
def
enterabs
(
self
,
time
,
priority
,
action
,
argument
):
"""Enter a new event in the queue at an absolute time.
Returns an ID for the event which can be used to remove it,
if necessary.
Returns an ID for the event which can be used to remove it,
if necessary.
"""
"""
event
=
time
,
priority
,
action
,
argument
bisect
.
insort
(
self
.
queue
,
event
)
return
event
# The ID
...
...
@@ -52,19 +52,19 @@ class scheduler:
def
enter
(
self
,
delay
,
priority
,
action
,
argument
):
"""A variant that specifies the time as a relative time.
This is actually the more commonly used interface.
This is actually the more commonly used interface.
"""
"""
time
=
self
.
timefunc
()
+
delay
return
self
.
enterabs
(
time
,
priority
,
action
,
argument
)
def
cancel
(
self
,
event
):
"""Remove an event from the queue.
This must be presented the ID as returned by enter().
If the event is not in the queue, this raises RuntimeError.
This must be presented the ID as returned by enter().
If the event is not in the queue, this raises RuntimeError.
"""
"""
self
.
queue
.
remove
(
event
)
def
empty
(
self
):
...
...
@@ -73,25 +73,25 @@ class scheduler:
def
run
(
self
):
"""Execute events until the queue is empty.
When there is a positive delay until the first event, the
delay function is called and the event is left in the queue;
otherwise, the event is removed from the queue and executed
(its action function is called, passing it the argument). If
the delay function returns prematurely, it is simply
restarted.
It is legal for both the delay function and the action
function to to modify the queue or to raise an exception;
exceptions are not caught but the scheduler's state remains
well-defined so run() may be called again.
A questionably hack is added to allow other threads to run:
just after an event is executed, a delay of 0 is executed, to
avoid monopolizing the CPU when other threads are also
runnable.
"""
When there is a positive delay until the first event, the
delay function is called and the event is left in the queue;
otherwise, the event is removed from the queue and executed
(its action function is called, passing it the argument). If
the delay function returns prematurely, it is simply
restarted.
It is legal for both the delay function and the action
function to to modify the queue or to raise an exception;
exceptions are not caught but the scheduler's state remains
well-defined so run() may be called again.
A questionably hack is added to allow other threads to run:
just after an event is executed, a delay of 0 is executed, to
avoid monopolizing the CPU when other threads are also
runnable.
"""
q
=
self
.
queue
while
q
:
time
,
priority
,
action
,
argument
=
q
[
0
]
...
...
Lib/sgmllib.py
View file @
495ad3c8
...
...
@@ -137,7 +137,7 @@ class SGMLParser:
k
=
self
.
parse_pi
(
i
)
if
k
<
0
:
break
i
=
i
+
k
continue
continue
match
=
special
.
match
(
rawdata
,
i
)
if
match
:
if
self
.
literal
:
...
...
@@ -211,7 +211,7 @@ class SGMLParser:
__starttag_text
=
None
def
get_starttag_text
(
self
):
return
self
.
__starttag_text
# Internal -- handle starttag, return length or -1 if not terminated
def
parse_starttag
(
self
,
i
):
self
.
__starttag_text
=
None
...
...
Lib/shelve.py
View file @
495ad3c8
...
...
@@ -31,127 +31,127 @@ or may not be necessary to flush changes to disk.
# Try using cPickle and cStringIO if available.
try
:
from
cPickle
import
Pickler
,
Unpickler
from
cPickle
import
Pickler
,
Unpickler
except
ImportError
:
from
pickle
import
Pickler
,
Unpickler
from
pickle
import
Pickler
,
Unpickler
try
:
from
cStringIO
import
StringIO
from
cStringIO
import
StringIO
except
ImportError
:
from
StringIO
import
StringIO
from
StringIO
import
StringIO
class
Shelf
:
"""Base class for shelf implementations.
This is initialized with a dictionary-like object.
See the module's __doc__ string for an overview of the interface.
"""
def
__init__
(
self
,
dict
):
self
.
dict
=
dict
def
keys
(
self
):
return
self
.
dict
.
keys
()
def
__len__
(
self
):
return
len
(
self
.
dict
)
def
has_key
(
self
,
key
):
return
self
.
dict
.
has_key
(
key
)
def
get
(
self
,
key
,
default
=
None
):
if
self
.
dict
.
has_key
(
key
):
return
self
[
key
]
return
default
def
__getitem__
(
self
,
key
):
f
=
StringIO
(
self
.
dict
[
key
])
return
Unpickler
(
f
).
load
()
def
__setitem__
(
self
,
key
,
value
):
f
=
StringIO
()
p
=
Pickler
(
f
)
p
.
dump
(
value
)
self
.
dict
[
key
]
=
f
.
getvalue
()
def
__delitem__
(
self
,
key
):
del
self
.
dict
[
key
]
def
close
(
self
):
try
:
self
.
dict
.
close
()
except
:
pass
self
.
dict
=
0
def
__del__
(
self
):
self
.
close
()
def
sync
(
self
):
if
hasattr
(
self
.
dict
,
'sync'
):
self
.
dict
.
sync
()
"""Base class for shelf implementations.
This is initialized with a dictionary-like object.
See the module's __doc__ string for an overview of the interface.
"""
def
__init__
(
self
,
dict
):
self
.
dict
=
dict
def
keys
(
self
):
return
self
.
dict
.
keys
()
def
__len__
(
self
):
return
len
(
self
.
dict
)
def
has_key
(
self
,
key
):
return
self
.
dict
.
has_key
(
key
)
def
get
(
self
,
key
,
default
=
None
):
if
self
.
dict
.
has_key
(
key
):
return
self
[
key
]
return
default
def
__getitem__
(
self
,
key
):
f
=
StringIO
(
self
.
dict
[
key
])
return
Unpickler
(
f
).
load
()
def
__setitem__
(
self
,
key
,
value
):
f
=
StringIO
()
p
=
Pickler
(
f
)
p
.
dump
(
value
)
self
.
dict
[
key
]
=
f
.
getvalue
()
def
__delitem__
(
self
,
key
):
del
self
.
dict
[
key
]
def
close
(
self
):
try
:
self
.
dict
.
close
()
except
:
pass
self
.
dict
=
0
def
__del__
(
self
):
self
.
close
()
def
sync
(
self
):
if
hasattr
(
self
.
dict
,
'sync'
):
self
.
dict
.
sync
()
class
BsdDbShelf
(
Shelf
):
"""Shelf implementation using the "BSD" db interface.
"""Shelf implementation using the "BSD" db interface.
This adds methods first(), next(), previous(), last() and
set_location() that have no counterpart in [g]dbm databases.
This adds methods first(), next(), previous(), last() and
set_location() that have no counterpart in [g]dbm databases.
The actual database must be opened using one of the "bsddb"
modules "open" routines (i.e. bsddb.hashopen, bsddb.btopen or
bsddb.rnopen) and passed to the constructor.
The actual database must be opened using one of the "bsddb"
modules "open" routines (i.e. bsddb.hashopen, bsddb.btopen or
bsddb.rnopen) and passed to the constructor.
See the module's __doc__ string for an overview of the interface.
"""
See the module's __doc__ string for an overview of the interface.
"""
def
__init__
(
self
,
dict
):
Shelf
.
__init__
(
self
,
dict
)
def
__init__
(
self
,
dict
):
Shelf
.
__init__
(
self
,
dict
)
def
set_location
(
self
,
key
):
(
key
,
value
)
=
self
.
dict
.
set_location
(
key
)
f
=
StringIO
(
value
)
return
(
key
,
Unpickler
(
f
).
load
())
def
set_location
(
self
,
key
):
(
key
,
value
)
=
self
.
dict
.
set_location
(
key
)
f
=
StringIO
(
value
)
return
(
key
,
Unpickler
(
f
).
load
())
def
next
(
self
):
(
key
,
value
)
=
self
.
dict
.
next
()
f
=
StringIO
(
value
)
return
(
key
,
Unpickler
(
f
).
load
())
def
next
(
self
):
(
key
,
value
)
=
self
.
dict
.
next
()
f
=
StringIO
(
value
)
return
(
key
,
Unpickler
(
f
).
load
())
def
previous
(
self
):
(
key
,
value
)
=
self
.
dict
.
previous
()
f
=
StringIO
(
value
)
return
(
key
,
Unpickler
(
f
).
load
())
def
previous
(
self
):
(
key
,
value
)
=
self
.
dict
.
previous
()
f
=
StringIO
(
value
)
return
(
key
,
Unpickler
(
f
).
load
())
def
first
(
self
):
(
key
,
value
)
=
self
.
dict
.
first
()
f
=
StringIO
(
value
)
return
(
key
,
Unpickler
(
f
).
load
())
def
first
(
self
):
(
key
,
value
)
=
self
.
dict
.
first
()
f
=
StringIO
(
value
)
return
(
key
,
Unpickler
(
f
).
load
())
def
last
(
self
):
(
key
,
value
)
=
self
.
dict
.
last
()
f
=
StringIO
(
value
)
return
(
key
,
Unpickler
(
f
).
load
())
def
last
(
self
):
(
key
,
value
)
=
self
.
dict
.
last
()
f
=
StringIO
(
value
)
return
(
key
,
Unpickler
(
f
).
load
())
class
DbfilenameShelf
(
Shelf
):
"""Shelf implementation using the "anydbm" generic dbm interface.
"""Shelf implementation using the "anydbm" generic dbm interface.
This is initialized with the filename for the dbm database.
See the module's __doc__ string for an overview of the interface.
"""
This is initialized with the filename for the dbm database.
See the module's __doc__ string for an overview of the interface.
"""
def
__init__
(
self
,
filename
,
flag
=
'c'
):
import
anydbm
Shelf
.
__init__
(
self
,
anydbm
.
open
(
filename
,
flag
))
def
__init__
(
self
,
filename
,
flag
=
'c'
):
import
anydbm
Shelf
.
__init__
(
self
,
anydbm
.
open
(
filename
,
flag
))
def
open
(
filename
,
flag
=
'c'
):
"""Open a persistent dictionary for reading and writing.
"""Open a persistent dictionary for reading and writing.
Argument is the filename for the dbm database.
See the module's __doc__ string for an overview of the interface.
"""
Argument is the filename for the dbm database.
See the module's __doc__ string for an overview of the interface.
"""
return
DbfilenameShelf
(
filename
,
flag
)
return
DbfilenameShelf
(
filename
,
flag
)
Lib/shlex.py
View file @
495ad3c8
"""A lexical analyzer class for simple shell-like syntaxes."""
# Module and documentation by Eric S. Raymond, 21 Dec 1998
# Module and documentation by Eric S. Raymond, 21 Dec 1998
# Input stacking and error message cleanup added by ESR, March 2000
import
os.path
...
...
@@ -8,7 +8,7 @@ import sys
class
shlex
:
"A lexical analyzer class for simple shell-like syntaxes."
"A lexical analyzer class for simple shell-like syntaxes."
def
__init__
(
self
,
instream
=
None
,
infile
=
None
):
if
instream
:
self
.
instream
=
instream
...
...
@@ -88,7 +88,7 @@ class shlex:
self
.
lineno
=
self
.
lineno
+
1
if
self
.
debug
>=
3
:
print
"shlex: in state"
,
repr
(
self
.
state
),
\
"I see character:"
,
repr
(
nextchar
)
"I see character:"
,
repr
(
nextchar
)
if
self
.
state
is
None
:
self
.
token
=
''
# past end of file
break
...
...
@@ -181,7 +181,7 @@ class shlex:
return
"
\
"
%s
\
"
, line %d: "
%
(
infile
,
lineno
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
if
len
(
sys
.
argv
)
==
1
:
lexer
=
shlex
()
else
:
...
...
Lib/shutil.py
View file @
495ad3c8
...
...
@@ -17,7 +17,7 @@ def copyfileobj(fsrc, fdst, length=16*1024):
break
fdst
.
write
(
buf
)
def
copyfile
(
src
,
dst
):
"""Copy data from src to dst"""
fsrc
=
None
...
...
@@ -48,7 +48,7 @@ def copystat(src, dst):
def
copy
(
src
,
dst
):
"""Copy data and mode bits ("cp src dst").
The destination may be a directory.
"""
...
...
Lib/smtplib.py
View file @
495ad3c8
...
...
@@ -36,7 +36,7 @@ Example:
# Eric S. Raymond <esr@thyrsus.com>
# Better RFC 821 compliance (MAIL and RCPT, and CRLF in data)
# by Carey Evans <c.evans@clear.net.nz>, for picky mail servers.
#
#
# This was modified from the Python 1.5 library HTTP lib.
import
socket
...
...
@@ -48,7 +48,7 @@ import types
SMTP_PORT
=
25
CRLF
=
"
\
r
\
n
"
# Exception classes used by this module.
# Exception classes used by this module.
class
SMTPException
(
Exception
):
"""Base class for all exceptions raised by this module."""
...
...
@@ -89,8 +89,8 @@ class SMTPSenderRefused(SMTPResponseException):
class
SMTPRecipientsRefused
(
SMTPException
):
"""All recipient addresses refused.
The errors for each recipient are accessible through the attribute
'recipients', which is a dictionary of exactly the same sort as
SMTP.sendmail() returns.
'recipients', which is a dictionary of exactly the same sort as
SMTP.sendmail() returns.
"""
def
__init__
(
self
,
recipients
):
...
...
@@ -137,27 +137,27 @@ def quotedata(data):
class SMTP:
"""This class manages a connection to an SMTP or ESMTP server.
SMTP Objects:
SMTP objects have the following attributes:
helo_resp
This is the message given by the server in response to the
SMTP objects have the following attributes:
helo_resp
This is the message given by the server in response to the
most recent HELO command.
ehlo_resp
This is the message given by the server in response to the
This is the message given by the server in response to the
most recent EHLO command. This is usually multiline.
does_esmtp
does_esmtp
This is a True value _after you do an EHLO command_, if the
server supports ESMTP.
esmtp_features
esmtp_features
This is a dictionary, which, if the server supports ESMTP,
will _after you do an EHLO command_, contain the names of the
SMTP service extensions this server supports, and their
parameters (if any).
Note, all extension names are mapped to lower case in the
dictionary.
Note, all extension names are mapped to lower case in the
dictionary.
See each method'
s
docstrings
for
details
.
In
general
,
there
is
a
method
of
the
same
name
to
perform
each
SMTP
command
.
There
is
also
a
...
...
@@ -183,7 +183,7 @@ class SMTP:
(code, msg) = self.connect(host, port)
if code != 220:
raise SMTPConnectError(code, msg)
def set_debuglevel(self, debuglevel):
"""
Set
the
debug
output
level
.
...
...
@@ -222,7 +222,7 @@ class SMTP:
(code,msg)=self.getreply()
if self.debuglevel >0 : print "connect:", msg
return (code,msg)
def send(self, str):
"""Send `str'
to
the
server
.
"""
if self.debuglevel > 0: print 'send:', `str`
...
...
@@ -235,7 +235,7 @@ class SMTP:
raise SMTPServerDisconnected('Server not connected')
else:
raise SMTPServerDisconnected('please run connect() first')
def putcmd(self, cmd, args=""):
"""
Send
a
command
to
the
server
.
"""
if args == "":
...
...
@@ -243,10 +243,10 @@ class SMTP:
else:
str = '%s %s%s' % (cmd, args, CRLF)
self.send(str)
def getreply(self):
"""
Get
a
reply
from
the
server
.
Returns
a
tuple
consisting
of
:
-
server
response
code
(
e
.
g
.
'250'
,
or
such
,
if
all
goes
well
)
...
...
@@ -280,10 +280,10 @@ class SMTP:
break
errmsg
=
string
.
join
(
resp
,
"
\
n
"
)
if
self
.
debuglevel
>
0
:
if
self
.
debuglevel
>
0
:
print
'reply: retcode (%s); Msg: %s'
%
(
errcode
,
errmsg
)
return
errcode
,
errmsg
def
docmd
(
self
,
cmd
,
args
=
""
):
"""Send a command, and return its response code."""
self
.
putcmd
(
cmd
,
args
)
...
...
@@ -313,8 +313,8 @@ class SMTP:
else
:
self
.
putcmd
(
"ehlo"
,
socket
.
getfqdn
())
(
code
,
msg
)
=
self
.
getreply
()
# According to RFC1869 some (badly written)
# MTA's will disconnect on an ehlo. Toss an exception if
# According to RFC1869 some (badly written)
# MTA's will disconnect on an ehlo. Toss an exception if
# that happens -ddm
if
code
==
-
1
and
len
(
msg
)
==
0
:
raise
SMTPServerDisconnected
(
"Server not connected"
)
...
...
@@ -368,7 +368,7 @@ class SMTP:
return self.getreply()
def data(self,msg):
"""
SMTP
'DATA'
command
--
sends
message
data
to
server
.
"""
SMTP
'DATA'
command
--
sends
message
data
to
server
.
Automatically
quotes
lines
beginning
with
a
period
per
rfc821
.
Raises
SMTPDataError
if
there
is
an
unexpected
reply
to
the
...
...
@@ -404,14 +404,14 @@ class SMTP:
# some useful methods
def sendmail(self, from_addr, to_addrs, msg, mail_options=[],
rcpt_options=[]):
"""
This
command
performs
an
entire
mail
transaction
.
rcpt_options=[]):
"""
This
command
performs
an
entire
mail
transaction
.
The
arguments
are
:
The
arguments
are
:
-
from_addr
:
The
address
sending
this
mail
.
-
to_addrs
:
A
list
of
addresses
to
send
this
mail
to
.
A
bare
string
will
be
treated
as
a
list
with
1
address
.
-
msg
:
The
message
to
send
.
-
msg
:
The
message
to
send
.
-
mail_options
:
List
of
ESMTP
options
(
such
as
8
bitmime
)
for
the
mail
command
.
-
rcpt_options
:
List
of
ESMTP
options
(
such
as
DSN
commands
)
for
...
...
@@ -430,7 +430,7 @@ class SMTP:
This
method
may
raise
the
following
exceptions
:
SMTPHeloError
The
server
didn
't reply properly to
the helo greeting.
the helo greeting.
SMTPRecipientsRefused The server rejected ALL recipients
(no mail was sent).
SMTPSenderRefused The server didn'
t
accept
the
from_addr
.
...
...
@@ -441,7 +441,7 @@ class SMTP:
Note
:
the
connection
will
be
open
even
after
an
exception
is
raised
.
Example
:
>>>
import
smtplib
>>>
s
=
smtplib
.
SMTP
(
"localhost"
)
>>>
tolist
=
[
"one@one.org"
,
"two@two.org"
,
"three@three.org"
,
"four@four.org"
]
...
...
@@ -453,7 +453,7 @@ class SMTP:
>>>
s
.
sendmail
(
"me@my.org"
,
tolist
,
msg
)
{
"three@three.org"
:
(
550
,
"User unknown"
)
}
>>>
s
.
quit
()
In
the
above
example
,
the
message
was
accepted
for
delivery
to
three
of
the
four
addresses
,
and
one
was
rejected
,
with
the
error
code
550.
If
all
addresses
are
accepted
,
then
the
method
will
return
an
...
...
@@ -494,7 +494,7 @@ class SMTP:
self.rset()
raise SMTPDataError(code, resp)
#if we got here then somebody got our mail
return senderrs
return senderrs
def close(self):
...
...
Lib/sndhdr.py
View file @
495ad3c8
...
...
@@ -32,20 +32,20 @@ explicitly given directories.
def
what
(
filename
):
"""Guess the type of a sound file"""
res
=
whathdr
(
filename
)
return
res
"""Guess the type of a sound file"""
res
=
whathdr
(
filename
)
return
res
def
whathdr
(
filename
):
"""Recognize sound headers"""
f
=
open
(
filename
,
'r'
)
h
=
f
.
read
(
512
)
for
tf
in
tests
:
res
=
tf
(
h
,
f
)
if
res
:
return
res
return
None
"""Recognize sound headers"""
f
=
open
(
filename
,
'r'
)
h
=
f
.
read
(
512
)
for
tf
in
tests
:
res
=
tf
(
h
,
f
)
if
res
:
return
res
return
None
#-----------------------------------#
...
...
@@ -55,113 +55,113 @@ def whathdr(filename):
tests
=
[]
def
test_aifc
(
h
,
f
):
import
aifc
if
h
[:
4
]
!=
'FORM'
:
return
None
if
h
[
8
:
12
]
==
'AIFC'
:
fmt
=
'aifc'
elif
h
[
8
:
12
]
==
'AIFF'
:
fmt
=
'aiff'
else
:
return
None
f
.
seek
(
0
)
try
:
a
=
aifc
.
openfp
(
f
,
'r'
)
except
(
EOFError
,
aifc
.
Error
):
return
None
return
(
fmt
,
a
.
getframerate
(),
a
.
getnchannels
(),
\
a
.
getnframes
(),
8
*
a
.
getsampwidth
())
import
aifc
if
h
[:
4
]
!=
'FORM'
:
return
None
if
h
[
8
:
12
]
==
'AIFC'
:
fmt
=
'aifc'
elif
h
[
8
:
12
]
==
'AIFF'
:
fmt
=
'aiff'
else
:
return
None
f
.
seek
(
0
)
try
:
a
=
aifc
.
openfp
(
f
,
'r'
)
except
(
EOFError
,
aifc
.
Error
):
return
None
return
(
fmt
,
a
.
getframerate
(),
a
.
getnchannels
(),
\
a
.
getnframes
(),
8
*
a
.
getsampwidth
())
tests
.
append
(
test_aifc
)
def
test_au
(
h
,
f
):
if
h
[:
4
]
==
'.snd'
:
f
=
get_long_be
elif
h
[:
4
]
in
(
'
\
0
ds.'
,
'dns.'
):
f
=
get_long_le
else
:
return
None
type
=
'au'
hdr_size
=
f
(
h
[
4
:
8
])
data_size
=
f
(
h
[
8
:
12
])
encoding
=
f
(
h
[
12
:
16
])
rate
=
f
(
h
[
16
:
20
])
nchannels
=
f
(
h
[
20
:
24
])
sample_size
=
1
# default
if
encoding
==
1
:
sample_bits
=
'U'
elif
encoding
==
2
:
sample_bits
=
8
elif
encoding
==
3
:
sample_bits
=
16
sample_size
=
2
else
:
sample_bits
=
'?'
frame_size
=
sample_size
*
nchannels
return
type
,
rate
,
nchannels
,
data_size
/
frame_size
,
sample_bits
if
h
[:
4
]
==
'.snd'
:
f
=
get_long_be
elif
h
[:
4
]
in
(
'
\
0
ds.'
,
'dns.'
):
f
=
get_long_le
else
:
return
None
type
=
'au'
hdr_size
=
f
(
h
[
4
:
8
])
data_size
=
f
(
h
[
8
:
12
])
encoding
=
f
(
h
[
12
:
16
])
rate
=
f
(
h
[
16
:
20
])
nchannels
=
f
(
h
[
20
:
24
])
sample_size
=
1
# default
if
encoding
==
1
:
sample_bits
=
'U'
elif
encoding
==
2
:
sample_bits
=
8
elif
encoding
==
3
:
sample_bits
=
16
sample_size
=
2
else
:
sample_bits
=
'?'
frame_size
=
sample_size
*
nchannels
return
type
,
rate
,
nchannels
,
data_size
/
frame_size
,
sample_bits
tests
.
append
(
test_au
)
def
test_hcom
(
h
,
f
):
if
h
[
65
:
69
]
!=
'FSSD'
or
h
[
128
:
132
]
!=
'HCOM'
:
return
None
divisor
=
get_long_be
(
h
[
128
+
16
:
128
+
20
])
return
'hcom'
,
22050
/
divisor
,
1
,
-
1
,
8
if
h
[
65
:
69
]
!=
'FSSD'
or
h
[
128
:
132
]
!=
'HCOM'
:
return
None
divisor
=
get_long_be
(
h
[
128
+
16
:
128
+
20
])
return
'hcom'
,
22050
/
divisor
,
1
,
-
1
,
8
tests
.
append
(
test_hcom
)
def
test_voc
(
h
,
f
):
if
h
[:
20
]
!=
'Creative Voice File
\
032
'
:
return
None
sbseek
=
get_short_le
(
h
[
20
:
22
])
rate
=
0
if
0
<=
sbseek
<
500
and
h
[
sbseek
]
==
'
\
1
'
:
ratecode
=
ord
(
h
[
sbseek
+
4
])
rate
=
int
(
1000000.0
/
(
256
-
ratecode
))
return
'voc'
,
rate
,
1
,
-
1
,
8
if
h
[:
20
]
!=
'Creative Voice File
\
032
'
:
return
None
sbseek
=
get_short_le
(
h
[
20
:
22
])
rate
=
0
if
0
<=
sbseek
<
500
and
h
[
sbseek
]
==
'
\
1
'
:
ratecode
=
ord
(
h
[
sbseek
+
4
])
rate
=
int
(
1000000.0
/
(
256
-
ratecode
))
return
'voc'
,
rate
,
1
,
-
1
,
8
tests
.
append
(
test_voc
)
def
test_wav
(
h
,
f
):
# 'RIFF' <len> 'WAVE' 'fmt ' <len>
if
h
[:
4
]
!=
'RIFF'
or
h
[
8
:
12
]
!=
'WAVE'
or
h
[
12
:
16
]
!=
'fmt '
:
return
None
style
=
get_short_le
(
h
[
20
:
22
])
nchannels
=
get_short_le
(
h
[
22
:
24
])
rate
=
get_long_le
(
h
[
24
:
28
])
sample_bits
=
get_short_le
(
h
[
34
:
36
])
return
'wav'
,
rate
,
nchannels
,
-
1
,
sample_bits
# 'RIFF' <len> 'WAVE' 'fmt ' <len>
if
h
[:
4
]
!=
'RIFF'
or
h
[
8
:
12
]
!=
'WAVE'
or
h
[
12
:
16
]
!=
'fmt '
:
return
None
style
=
get_short_le
(
h
[
20
:
22
])
nchannels
=
get_short_le
(
h
[
22
:
24
])
rate
=
get_long_le
(
h
[
24
:
28
])
sample_bits
=
get_short_le
(
h
[
34
:
36
])
return
'wav'
,
rate
,
nchannels
,
-
1
,
sample_bits
tests
.
append
(
test_wav
)
def
test_8svx
(
h
,
f
):
if
h
[:
4
]
!=
'FORM'
or
h
[
8
:
12
]
!=
'8SVX'
:
return
None
# Should decode it to get #channels -- assume always 1
return
'8svx'
,
0
,
1
,
0
,
8
if
h
[:
4
]
!=
'FORM'
or
h
[
8
:
12
]
!=
'8SVX'
:
return
None
# Should decode it to get #channels -- assume always 1
return
'8svx'
,
0
,
1
,
0
,
8
tests
.
append
(
test_8svx
)
def
test_sndt
(
h
,
f
):
if
h
[:
5
]
==
'SOUND'
:
nsamples
=
get_long_le
(
h
[
8
:
12
])
rate
=
get_short_le
(
h
[
20
:
22
])
return
'sndt'
,
rate
,
1
,
nsamples
,
8
if
h
[:
5
]
==
'SOUND'
:
nsamples
=
get_long_le
(
h
[
8
:
12
])
rate
=
get_short_le
(
h
[
20
:
22
])
return
'sndt'
,
rate
,
1
,
nsamples
,
8
tests
.
append
(
test_sndt
)
def
test_sndr
(
h
,
f
):
if
h
[:
2
]
==
'
\
0
\
0
'
:
rate
=
get_short_le
(
h
[
2
:
4
])
if
4000
<=
rate
<=
25000
:
return
'sndr'
,
rate
,
1
,
-
1
,
8
if
h
[:
2
]
==
'
\
0
\
0
'
:
rate
=
get_short_le
(
h
[
2
:
4
])
if
4000
<=
rate
<=
25000
:
return
'sndr'
,
rate
,
1
,
-
1
,
8
tests
.
append
(
test_sndr
)
...
...
@@ -171,16 +171,16 @@ tests.append(test_sndr)
#---------------------------------------------#
def
get_long_be
(
s
):
return
(
ord
(
s
[
0
])
<<
24
)
|
(
ord
(
s
[
1
])
<<
16
)
|
(
ord
(
s
[
2
])
<<
8
)
|
ord
(
s
[
3
])
return
(
ord
(
s
[
0
])
<<
24
)
|
(
ord
(
s
[
1
])
<<
16
)
|
(
ord
(
s
[
2
])
<<
8
)
|
ord
(
s
[
3
])
def
get_long_le
(
s
):
return
(
ord
(
s
[
3
])
<<
24
)
|
(
ord
(
s
[
2
])
<<
16
)
|
(
ord
(
s
[
1
])
<<
8
)
|
ord
(
s
[
0
])
return
(
ord
(
s
[
3
])
<<
24
)
|
(
ord
(
s
[
2
])
<<
16
)
|
(
ord
(
s
[
1
])
<<
8
)
|
ord
(
s
[
0
])
def
get_short_be
(
s
):
return
(
ord
(
s
[
0
])
<<
8
)
|
ord
(
s
[
1
])
return
(
ord
(
s
[
0
])
<<
8
)
|
ord
(
s
[
1
])
def
get_short_le
(
s
):
return
(
ord
(
s
[
1
])
<<
8
)
|
ord
(
s
[
0
])
return
(
ord
(
s
[
1
])
<<
8
)
|
ord
(
s
[
0
])
#--------------------#
...
...
@@ -188,40 +188,40 @@ def get_short_le(s):
#--------------------#
def
test
():
import
sys
recursive
=
0
if
sys
.
argv
[
1
:]
and
sys
.
argv
[
1
]
==
'-r'
:
del
sys
.
argv
[
1
:
2
]
recursive
=
1
try
:
if
sys
.
argv
[
1
:]:
testall
(
sys
.
argv
[
1
:],
recursive
,
1
)
else
:
testall
([
'.'
],
recursive
,
1
)
except
KeyboardInterrupt
:
sys
.
stderr
.
write
(
'
\
n
[Interrupted]
\
n
'
)
sys
.
exit
(
1
)
import
sys
recursive
=
0
if
sys
.
argv
[
1
:]
and
sys
.
argv
[
1
]
==
'-r'
:
del
sys
.
argv
[
1
:
2
]
recursive
=
1
try
:
if
sys
.
argv
[
1
:]:
testall
(
sys
.
argv
[
1
:],
recursive
,
1
)
else
:
testall
([
'.'
],
recursive
,
1
)
except
KeyboardInterrupt
:
sys
.
stderr
.
write
(
'
\
n
[Interrupted]
\
n
'
)
sys
.
exit
(
1
)
def
testall
(
list
,
recursive
,
toplevel
):
import
sys
import
os
for
filename
in
list
:
if
os
.
path
.
isdir
(
filename
):
print
filename
+
'/:'
,
if
recursive
or
toplevel
:
print
'recursing down:'
import
glob
names
=
glob
.
glob
(
os
.
path
.
join
(
filename
,
'*'
))
testall
(
names
,
recursive
,
0
)
else
:
print
'*** directory (use -r) ***'
else
:
print
filename
+
':'
,
sys
.
stdout
.
flush
()
try
:
print
what
(
filename
)
except
IOError
:
print
'*** not found ***'
import
sys
import
os
for
filename
in
list
:
if
os
.
path
.
isdir
(
filename
):
print
filename
+
'/:'
,
if
recursive
or
toplevel
:
print
'recursing down:'
import
glob
names
=
glob
.
glob
(
os
.
path
.
join
(
filename
,
'*'
))
testall
(
names
,
recursive
,
0
)
else
:
print
'*** directory (use -r) ***'
else
:
print
filename
+
':'
,
sys
.
stdout
.
flush
()
try
:
print
what
(
filename
)
except
IOError
:
print
'*** not found ***'
if
__name__
==
'__main__'
:
test
()
test
()
Lib/socket.py
View file @
495ad3c8
...
...
@@ -4,7 +4,7 @@
"""
\
This module provides socket operations and some related functions.
On Unix, it supports IP (Internet Protocol) and Unix domain sockets.
On other systems, it only supports IP. Functions specific for a
On other systems, it only supports IP. Functions specific for a
socket are available as methods of the socket object.
Functions:
...
...
Lib/stat.py
View file @
495ad3c8
...
...
@@ -24,10 +24,10 @@ ST_CTIME = 9
# Extract bits from the mode
def
S_IMODE
(
mode
):
return
mode
&
07777
return
mode
&
07777
def
S_IFMT
(
mode
):
return
mode
&
0170000
return
mode
&
0170000
# Constants used as S_IFMT() for various file types
# (not all are implemented on all systems)
...
...
@@ -43,25 +43,25 @@ S_IFSOCK = 0140000
# Functions to test for each file type
def
S_ISDIR
(
mode
):
return
S_IFMT
(
mode
)
==
S_IFDIR
return
S_IFMT
(
mode
)
==
S_IFDIR
def
S_ISCHR
(
mode
):
return
S_IFMT
(
mode
)
==
S_IFCHR
return
S_IFMT
(
mode
)
==
S_IFCHR
def
S_ISBLK
(
mode
):
return
S_IFMT
(
mode
)
==
S_IFBLK
return
S_IFMT
(
mode
)
==
S_IFBLK
def
S_ISREG
(
mode
):
return
S_IFMT
(
mode
)
==
S_IFREG
return
S_IFMT
(
mode
)
==
S_IFREG
def
S_ISFIFO
(
mode
):
return
S_IFMT
(
mode
)
==
S_IFIFO
return
S_IFMT
(
mode
)
==
S_IFIFO
def
S_ISLNK
(
mode
):
return
S_IFMT
(
mode
)
==
S_IFLNK
return
S_IFMT
(
mode
)
==
S_IFLNK
def
S_ISSOCK
(
mode
):
return
S_IFMT
(
mode
)
==
S_IFSOCK
return
S_IFMT
(
mode
)
==
S_IFSOCK
# Names for permission bits
...
...
Lib/statcache.py
View file @
495ad3c8
...
...
@@ -13,63 +13,63 @@ cache = {}
def
stat
(
path
):
"""Stat a file, possibly out of the cache."""
if
cache
.
has_key
(
path
):
return
cache
[
path
]
cache
[
path
]
=
ret
=
os
.
stat
(
path
)
return
ret
"""Stat a file, possibly out of the cache."""
if
cache
.
has_key
(
path
):
return
cache
[
path
]
cache
[
path
]
=
ret
=
os
.
stat
(
path
)
return
ret
def
reset
():
"""Reset the cache completely."""
global
cache
cache
=
{}
"""Reset the cache completely."""
global
cache
cache
=
{}
def
forget
(
path
):
"""Remove a given item from the cache, if it exists."""
if
cache
.
has_key
(
path
):
del
cache
[
path
]
"""Remove a given item from the cache, if it exists."""
if
cache
.
has_key
(
path
):
del
cache
[
path
]
def
forget_prefix
(
prefix
):
"""Remove all pathnames with a given prefix."""
n
=
len
(
prefix
)
for
path
in
cache
.
keys
():
if
path
[:
n
]
==
prefix
:
del
cache
[
path
]
"""Remove all pathnames with a given prefix."""
n
=
len
(
prefix
)
for
path
in
cache
.
keys
():
if
path
[:
n
]
==
prefix
:
del
cache
[
path
]
def
forget_dir
(
prefix
):
"""Forget about a directory and all entries in it, but not about
entries in subdirectories."""
if
prefix
[
-
1
:]
==
'/'
and
prefix
!=
'/'
:
prefix
=
prefix
[:
-
1
]
forget
(
prefix
)
if
prefix
[
-
1
:]
!=
'/'
:
prefix
=
prefix
+
'/'
n
=
len
(
prefix
)
for
path
in
cache
.
keys
():
if
path
[:
n
]
==
prefix
:
rest
=
path
[
n
:]
if
rest
[
-
1
:]
==
'/'
:
rest
=
rest
[:
-
1
]
if
'/'
not
in
rest
:
del
cache
[
path
]
"""Forget about a directory and all entries in it, but not about
entries in subdirectories."""
if
prefix
[
-
1
:]
==
'/'
and
prefix
!=
'/'
:
prefix
=
prefix
[:
-
1
]
forget
(
prefix
)
if
prefix
[
-
1
:]
!=
'/'
:
prefix
=
prefix
+
'/'
n
=
len
(
prefix
)
for
path
in
cache
.
keys
():
if
path
[:
n
]
==
prefix
:
rest
=
path
[
n
:]
if
rest
[
-
1
:]
==
'/'
:
rest
=
rest
[:
-
1
]
if
'/'
not
in
rest
:
del
cache
[
path
]
def
forget_except_prefix
(
prefix
):
"""Remove all pathnames except with a given prefix.
Normally used with prefix = '/' after a chdir()."""
n
=
len
(
prefix
)
for
path
in
cache
.
keys
():
if
path
[:
n
]
!=
prefix
:
del
cache
[
path
]
"""Remove all pathnames except with a given prefix.
Normally used with prefix = '/' after a chdir()."""
n
=
len
(
prefix
)
for
path
in
cache
.
keys
():
if
path
[:
n
]
!=
prefix
:
del
cache
[
path
]
def
isdir
(
path
):
"""Check for directory."""
try
:
st
=
stat
(
path
)
except
os
.
error
:
return
0
return
S_ISDIR
(
st
[
ST_MODE
])
"""Check for directory."""
try
:
st
=
stat
(
path
)
except
os
.
error
:
return
0
return
S_ISDIR
(
st
[
ST_MODE
])
Lib/statvfs.py
View file @
495ad3c8
...
...
@@ -3,13 +3,13 @@
# Indices for statvfs struct members in the tuple returned by
# os.statvfs() and os.fstatvfs().
F_BSIZE
=
0
# Preferred file system block size
F_FRSIZE
=
1
# Fundamental file system block size
F_BLOCKS
=
2
# Total number of file system blocks (FRSIZE)
F_BFREE
=
3
# Total number of free blocks
F_BAVAIL
=
4
# Free blocks available to non-superuser
F_FILES
=
5
# Total number of file nodes
F_FFREE
=
6
# Total number of free file nodes
F_FAVAIL
=
7
# Free nodes available to non-superuser
F_FLAG
=
8
# Flags (see your local statvfs man page)
F_NAMEMAX
=
9
# Maximum file name length
F_BSIZE
=
0
# Preferred file system block size
F_FRSIZE
=
1
# Fundamental file system block size
F_BLOCKS
=
2
# Total number of file system blocks (FRSIZE)
F_BFREE
=
3
# Total number of free blocks
F_BAVAIL
=
4
# Free blocks available to non-superuser
F_FILES
=
5
# Total number of file nodes
F_FFREE
=
6
# Total number of free file nodes
F_FAVAIL
=
7
# Free nodes available to non-superuser
F_FLAG
=
8
# Flags (see your local statvfs man page)
F_NAMEMAX
=
9
# Maximum file name length
Lib/string.py
View file @
495ad3c8
...
...
@@ -27,7 +27,7 @@ letters = lowercase + uppercase
digits
=
'0123456789'
hexdigits
=
digits
+
'abcdef'
+
'ABCDEF'
octdigits
=
'01234567'
punctuation
=
"""!"#$%&'()*+,-./:;<=>?@[
\
]^_`{|}~
"
""
punctuation
=
"""!"#$%&'()*+,-./:;<=>?@[
\
]^_`{|}~
"
""
printable = digits + letters + punctuation + whitespace
# Case conversion helpers
...
...
Lib/sunau.py
View file @
495ad3c8
This diff is collapsed.
Click to expand it.
Lib/sunaudio.py
View file @
495ad3c8
...
...
@@ -3,42 +3,42 @@
MAGIC
=
'.snd'
class
error
(
Exception
):
pass
pass
def
get_long_be
(
s
):
"""Convert a 4-char value to integer."""
return
(
ord
(
s
[
0
])
<<
24
)
|
(
ord
(
s
[
1
])
<<
16
)
|
(
ord
(
s
[
2
])
<<
8
)
|
ord
(
s
[
3
])
"""Convert a 4-char value to integer."""
return
(
ord
(
s
[
0
])
<<
24
)
|
(
ord
(
s
[
1
])
<<
16
)
|
(
ord
(
s
[
2
])
<<
8
)
|
ord
(
s
[
3
])
def
gethdr
(
fp
):
"""Read a sound header from an open file."""
if
fp
.
read
(
4
)
!=
MAGIC
:
raise
error
,
'gethdr: bad magic word'
hdr_size
=
get_long_be
(
fp
.
read
(
4
))
data_size
=
get_long_be
(
fp
.
read
(
4
))
encoding
=
get_long_be
(
fp
.
read
(
4
))
sample_rate
=
get_long_be
(
fp
.
read
(
4
))
channels
=
get_long_be
(
fp
.
read
(
4
))
excess
=
hdr_size
-
24
if
excess
<
0
:
raise
error
,
'gethdr: bad hdr_size'
if
excess
>
0
:
info
=
fp
.
read
(
excess
)
else
:
info
=
''
return
(
data_size
,
encoding
,
sample_rate
,
channels
,
info
)
"""Read a sound header from an open file."""
if
fp
.
read
(
4
)
!=
MAGIC
:
raise
error
,
'gethdr: bad magic word'
hdr_size
=
get_long_be
(
fp
.
read
(
4
))
data_size
=
get_long_be
(
fp
.
read
(
4
))
encoding
=
get_long_be
(
fp
.
read
(
4
))
sample_rate
=
get_long_be
(
fp
.
read
(
4
))
channels
=
get_long_be
(
fp
.
read
(
4
))
excess
=
hdr_size
-
24
if
excess
<
0
:
raise
error
,
'gethdr: bad hdr_size'
if
excess
>
0
:
info
=
fp
.
read
(
excess
)
else
:
info
=
''
return
(
data_size
,
encoding
,
sample_rate
,
channels
,
info
)
def
printhdr
(
file
):
"""Read and print the sound header of a named file."""
hdr
=
gethdr
(
open
(
file
,
'r'
))
data_size
,
encoding
,
sample_rate
,
channels
,
info
=
hdr
while
info
[
-
1
:]
==
'
\
0
'
:
info
=
info
[:
-
1
]
print
'File name: '
,
file
print
'Data size: '
,
data_size
print
'Encoding: '
,
encoding
print
'Sample rate:'
,
sample_rate
print
'Channels: '
,
channels
print
'Info: '
,
`info`
"""Read and print the sound header of a named file."""
hdr
=
gethdr
(
open
(
file
,
'r'
))
data_size
,
encoding
,
sample_rate
,
channels
,
info
=
hdr
while
info
[
-
1
:]
==
'
\
0
'
:
info
=
info
[:
-
1
]
print
'File name: '
,
file
print
'Data size: '
,
data_size
print
'Encoding: '
,
encoding
print
'Sample rate:'
,
sample_rate
print
'Channels: '
,
channels
print
'Info: '
,
`info`
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