[Python-checkins] CVS: python/dist/src/Lib sched.py,1.11,1.12 sgmllib.py,1.22,1.23 shelve.py,1.13,1.14 shlex.py,1.11,1.12 shutil.py,1.17,1.18 smtplib.py,1.31,1.32 sndhdr.py,1.4,1.5 socket.py,1.5,1.6 stat.py,1.7,1.8 statcache.py,1.8,1.9 statvfs.py,1.4,1.5 string.py,1.54,1.55 sunau.py,1.18,1.19 sunaudio.py,1.6,1.7
Tim Peters
python-dev@python.org
Sun, 14 Jan 2001 17:36:42 -0800
- Previous message: [Python-checkins] CVS: python/dist/src/Lib random.py,1.14,1.15 reconvert.py,1.3,1.4 regex_syntax.py,1.3,1.4 regsub.py,1.9,1.10 repr.py,1.6,1.7 rexec.py,1.26,1.27 rfc822.py,1.52,1.53
- Next message: [Python-checkins] CVS: python/dist/src/Lib tabnanny.py,1.10,1.11 telnetlib.py,1.8,1.9 tempfile.py,1.26,1.27 threading.py,1.10,1.11 toaiff.py,1.8,1.9 tokenize.py,1.15,1.16 traceback.py,1.18,1.19 tty.py,1.2,1.3 tzparse.py,1.8,1.9
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv6599/python/dist/src/lib
Modified Files:
sched.py sgmllib.py shelve.py shlex.py shutil.py smtplib.py
sndhdr.py socket.py stat.py statcache.py statvfs.py string.py
sunau.py sunaudio.py
Log Message:
Whitespace normalization.
Index: sched.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sched.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** sched.py 2000/02/04 15:39:30 1.11
--- sched.py 2001/01/15 01:36:40 1.12
***************
*** 42,49 ****
"""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.
! """
event = time, priority, action, argument
bisect.insort(self.queue, event)
--- 42,49 ----
"""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.
! """
event = time, priority, action, argument
bisect.insort(self.queue, event)
***************
*** 53,59 ****
"""A variant that specifies the time as a relative time.
! This is actually the more commonly used interface.
! """
time = self.timefunc() + delay
return self.enterabs(time, priority, action, argument)
--- 53,59 ----
"""A variant that specifies the time as a relative time.
! This is actually the more commonly used interface.
! """
time = self.timefunc() + delay
return self.enterabs(time, priority, action, argument)
***************
*** 62,69 ****
"""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.
! """
self.queue.remove(event)
--- 62,69 ----
"""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.
! """
self.queue.remove(event)
***************
*** 74,96 ****
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.
! """
q = self.queue
while q:
--- 74,96 ----
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.
!
! """
q = self.queue
while q:
Index: sgmllib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sgmllib.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -r1.22 -r1.23
*** sgmllib.py 2000/12/12 23:20:45 1.22
--- sgmllib.py 2001/01/15 01:36:40 1.23
***************
*** 138,142 ****
if k < 0: break
i = i+k
! continue
match = special.match(rawdata, i)
if match:
--- 138,142 ----
if k < 0: break
i = i+k
! continue
match = special.match(rawdata, i)
if match:
***************
*** 212,216 ****
def get_starttag_text(self):
return self.__starttag_text
!
# Internal -- handle starttag, return length or -1 if not terminated
def parse_starttag(self, i):
--- 212,216 ----
def get_starttag_text(self):
return self.__starttag_text
!
# Internal -- handle starttag, return length or -1 if not terminated
def parse_starttag(self, i):
Index: shelve.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/shelve.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** shelve.py 2000/02/10 17:17:14 1.13
--- shelve.py 2001/01/15 01:36:40 1.14
***************
*** 32,157 ****
try:
! from cPickle import Pickler, Unpickler
except ImportError:
! from pickle import Pickler, Unpickler
try:
! from cStringIO import StringIO
except ImportError:
! 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()
!
class BsdDbShelf(Shelf):
! """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.
! 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.
! """
!
! 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 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 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())
class DbfilenameShelf(Shelf):
! """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.
! """
!
! 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.
! Argument is the filename for the dbm database.
! See the module's __doc__ string for an overview of the interface.
! """
!
! return DbfilenameShelf(filename, flag)
--- 32,157 ----
try:
! from cPickle import Pickler, Unpickler
except ImportError:
! from pickle import Pickler, Unpickler
try:
! from cStringIO import StringIO
except ImportError:
! 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()
+
class BsdDbShelf(Shelf):
! """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.
! 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.
! """
!
! 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 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 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())
class DbfilenameShelf(Shelf):
! """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.
! """
!
! 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.
!
! Argument is the filename for the dbm database.
! See the module's __doc__ string for an overview of the interface.
! """
! return DbfilenameShelf(filename, flag)
Index: shlex.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/shlex.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** shlex.py 2001/01/09 03:01:15 1.11
--- shlex.py 2001/01/15 01:36:40 1.12
***************
*** 1,5 ****
"""A lexical analyzer class for simple shell-like syntaxes."""
! # Module and documentation by Eric S. Raymond, 21 Dec 1998
# Input stacking and error message cleanup added by ESR, March 2000
--- 1,5 ----
"""A lexical analyzer class for simple shell-like syntaxes."""
! # Module and documentation by Eric S. Raymond, 21 Dec 1998
# Input stacking and error message cleanup added by ESR, March 2000
***************
*** 9,13 ****
class shlex:
! "A lexical analyzer class for simple shell-like syntaxes."
def __init__(self, instream=None, infile=None):
if instream:
--- 9,13 ----
class shlex:
! "A lexical analyzer class for simple shell-like syntaxes."
def __init__(self, instream=None, infile=None):
if instream:
***************
*** 89,93 ****
if self.debug >= 3:
print "shlex: in state", repr(self.state), \
! "I see character:", repr(nextchar)
if self.state is None:
self.token = '' # past end of file
--- 89,93 ----
if self.debug >= 3:
print "shlex: in state", repr(self.state), \
! "I see character:", repr(nextchar)
if self.state is None:
self.token = '' # past end of file
***************
*** 182,186 ****
! if __name__ == '__main__':
if len(sys.argv) == 1:
lexer = shlex()
--- 182,186 ----
! if __name__ == '__main__':
if len(sys.argv) == 1:
lexer = shlex()
Index: shutil.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/shutil.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -r1.17 -r1.18
*** shutil.py 2000/07/12 09:55:30 1.17
--- shutil.py 2001/01/15 01:36:40 1.18
***************
*** 18,22 ****
fdst.write(buf)
!
def copyfile(src, dst):
"""Copy data from src to dst"""
--- 18,22 ----
fdst.write(buf)
!
def copyfile(src, dst):
"""Copy data from src to dst"""
***************
*** 49,53 ****
def copy(src, dst):
"""Copy data and mode bits ("cp src dst").
!
The destination may be a directory.
--- 49,53 ----
def copy(src, dst):
"""Copy data and mode bits ("cp src dst").
!
The destination may be a directory.
Index: smtplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/smtplib.py,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -r1.31 -r1.32
*** smtplib.py 2000/12/12 23:20:45 1.31
--- smtplib.py 2001/01/15 01:36:40 1.32
***************
*** 37,41 ****
# 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.
--- 37,41 ----
# 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.
***************
*** 49,53 ****
CRLF="\r\n"
! # Exception classes used by this module.
class SMTPException(Exception):
"""Base class for all exceptions raised by this module."""
--- 49,53 ----
CRLF="\r\n"
! # Exception classes used by this module.
class SMTPException(Exception):
"""Base class for all exceptions raised by this module."""
***************
*** 90,95 ****
"""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.
"""
--- 90,95 ----
"""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.
"""
***************
*** 138,155 ****
"""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
most recent HELO command.
!
ehlo_resp
! This is the message given by the server in response to the
most recent EHLO command. This is usually multiline.
! does_esmtp
This is a True value _after you do an EHLO command_, if the
server supports ESMTP.
! esmtp_features
This is a dictionary, which, if the server supports ESMTP,
will _after you do an EHLO command_, contain the names of the
--- 138,155 ----
"""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
most recent HELO command.
!
ehlo_resp
! This is the message given by the server in response to the
most recent EHLO command. This is usually multiline.
! does_esmtp
This is a True value _after you do an EHLO command_, if the
server supports ESMTP.
! esmtp_features
This is a dictionary, which, if the server supports ESMTP,
will _after you do an EHLO command_, contain the names of the
***************
*** 157,162 ****
parameters (if any).
! Note, all extension names are mapped to lower case in the
! dictionary.
See each method's docstrings for details. In general, there is a
--- 157,162 ----
parameters (if any).
! Note, all extension names are mapped to lower case in the
! dictionary.
See each method's docstrings for details. In general, there is a
***************
*** 184,188 ****
if code != 220:
raise SMTPConnectError(code, msg)
!
def set_debuglevel(self, debuglevel):
"""Set the debug output level.
--- 184,188 ----
if code != 220:
raise SMTPConnectError(code, msg)
!
def set_debuglevel(self, debuglevel):
"""Set the debug output level.
***************
*** 223,227 ****
if self.debuglevel >0 : print "connect:", msg
return (code,msg)
!
def send(self, str):
"""Send `str' to the server."""
--- 223,227 ----
if self.debuglevel >0 : print "connect:", msg
return (code,msg)
!
def send(self, str):
"""Send `str' to the server."""
***************
*** 236,240 ****
else:
raise SMTPServerDisconnected('please run connect() first')
!
def putcmd(self, cmd, args=""):
"""Send a command to the server."""
--- 236,240 ----
else:
raise SMTPServerDisconnected('please run connect() first')
!
def putcmd(self, cmd, args=""):
"""Send a command to the server."""
***************
*** 244,251 ****
str = '%s %s%s' % (cmd, args, CRLF)
self.send(str)
!
def getreply(self):
"""Get a reply from the server.
!
Returns a tuple consisting of:
--- 244,251 ----
str = '%s %s%s' % (cmd, args, CRLF)
self.send(str)
!
def getreply(self):
"""Get a reply from the server.
!
Returns a tuple consisting of:
***************
*** 281,288 ****
errmsg = string.join(resp,"\n")
! 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."""
--- 281,288 ----
errmsg = string.join(resp,"\n")
! 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."""
***************
*** 314,319 ****
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
# that happens -ddm
if code == -1 and len(msg) == 0:
--- 314,319 ----
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
# that happens -ddm
if code == -1 and len(msg) == 0:
***************
*** 369,373 ****
def data(self,msg):
! """SMTP 'DATA' command -- sends message data to server.
Automatically quotes lines beginning with a period per rfc821.
--- 369,373 ----
def data(self,msg):
! """SMTP 'DATA' command -- sends message data to server.
Automatically quotes lines beginning with a period per rfc821.
***************
*** 405,416 ****
# some useful methods
def sendmail(self, from_addr, to_addrs, msg, mail_options=[],
! rcpt_options=[]):
! """This command performs an entire mail transaction.
! 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.
- mail_options : List of ESMTP options (such as 8bitmime) for the
mail command.
--- 405,416 ----
# some useful methods
def sendmail(self, from_addr, to_addrs, msg, mail_options=[],
! rcpt_options=[]):
! """This command performs an entire mail transaction.
! 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.
- mail_options : List of ESMTP options (such as 8bitmime) for the
mail command.
***************
*** 431,435 ****
SMTPHeloError The server didn't reply properly to
! the helo greeting.
SMTPRecipientsRefused The server rejected ALL recipients
(no mail was sent).
--- 431,435 ----
SMTPHeloError The server didn't reply properly to
! the helo greeting.
SMTPRecipientsRefused The server rejected ALL recipients
(no mail was sent).
***************
*** 442,446 ****
Example:
!
>>> import smtplib
>>> s=smtplib.SMTP("localhost")
--- 442,446 ----
Example:
!
>>> import smtplib
>>> s=smtplib.SMTP("localhost")
***************
*** 454,458 ****
{ "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
--- 454,458 ----
{ "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
***************
*** 495,499 ****
raise SMTPDataError(code, resp)
#if we got here then somebody got our mail
! return senderrs
--- 495,499 ----
raise SMTPDataError(code, resp)
#if we got here then somebody got our mail
! return senderrs
Index: sndhdr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sndhdr.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** sndhdr.py 2000/12/12 23:20:45 1.4
--- sndhdr.py 2001/01/15 01:36:40 1.5
***************
*** 33,50 ****
def what(filename):
! """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
--- 33,50 ----
def what(filename):
! """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
***************
*** 56,75 ****
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())
tests.append(test_aifc)
--- 56,75 ----
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())
tests.append(test_aifc)
***************
*** 77,104 ****
def test_au(h, f):
! if h[:4] == '.snd':
! f = get_long_be
! elif h[:4] in ('\0ds.', '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)
--- 77,104 ----
def test_au(h, f):
! if h[:4] == '.snd':
! f = get_long_be
! elif h[:4] in ('\0ds.', '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)
***************
*** 106,113 ****
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
tests.append(test_hcom)
--- 106,113 ----
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
tests.append(test_hcom)
***************
*** 115,126 ****
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
tests.append(test_voc)
--- 115,126 ----
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
tests.append(test_voc)
***************
*** 128,139 ****
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
tests.append(test_wav)
--- 128,139 ----
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
tests.append(test_wav)
***************
*** 141,148 ****
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
tests.append(test_8svx)
--- 141,148 ----
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
tests.append(test_8svx)
***************
*** 150,157 ****
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
tests.append(test_sndt)
--- 150,157 ----
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
tests.append(test_sndt)
***************
*** 159,166 ****
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
tests.append(test_sndr)
--- 159,166 ----
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
tests.append(test_sndr)
***************
*** 172,185 ****
def get_long_be(s):
! 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])
def get_short_be(s):
! return (ord(s[0])<<8) | ord(s[1])
def get_short_le(s):
! return (ord(s[1])<<8) | ord(s[0])
--- 172,185 ----
def get_long_be(s):
! 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])
def get_short_be(s):
! return (ord(s[0])<<8) | ord(s[1])
def get_short_le(s):
! return (ord(s[1])<<8) | ord(s[0])
***************
*** 189,227 ****
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)
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 ***'
if __name__ == '__main__':
! test()
--- 189,227 ----
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)
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 ***'
if __name__ == '__main__':
! test()
Index: socket.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/socket.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** socket.py 2000/09/30 11:34:30 1.5
--- socket.py 2001/01/15 01:36:40 1.6
***************
*** 5,9 ****
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
socket are available as methods of the socket object.
--- 5,9 ----
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
socket are available as methods of the socket object.
Index: stat.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/stat.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** stat.py 2000/02/04 15:28:41 1.7
--- stat.py 2001/01/15 01:36:40 1.8
***************
*** 25,32 ****
def S_IMODE(mode):
! return mode & 07777
def S_IFMT(mode):
! return mode & 0170000
# Constants used as S_IFMT() for various file types
--- 25,32 ----
def S_IMODE(mode):
! return mode & 07777
def S_IFMT(mode):
! return mode & 0170000
# Constants used as S_IFMT() for various file types
***************
*** 44,66 ****
def S_ISDIR(mode):
! return S_IFMT(mode) == S_IFDIR
def S_ISCHR(mode):
! return S_IFMT(mode) == S_IFCHR
def S_ISBLK(mode):
! return S_IFMT(mode) == S_IFBLK
def S_ISREG(mode):
! return S_IFMT(mode) == S_IFREG
def S_ISFIFO(mode):
! return S_IFMT(mode) == S_IFIFO
def S_ISLNK(mode):
! return S_IFMT(mode) == S_IFLNK
def S_ISSOCK(mode):
! return S_IFMT(mode) == S_IFSOCK
# Names for permission bits
--- 44,66 ----
def S_ISDIR(mode):
! return S_IFMT(mode) == S_IFDIR
def S_ISCHR(mode):
! return S_IFMT(mode) == S_IFCHR
def S_ISBLK(mode):
! return S_IFMT(mode) == S_IFBLK
def S_ISREG(mode):
! return S_IFMT(mode) == S_IFREG
def S_ISFIFO(mode):
! return S_IFMT(mode) == S_IFIFO
def S_ISLNK(mode):
! return S_IFMT(mode) == S_IFLNK
def S_ISSOCK(mode):
! return S_IFMT(mode) == S_IFSOCK
# Names for permission bits
Index: statcache.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/statcache.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** statcache.py 2000/12/12 23:20:45 1.8
--- statcache.py 2001/01/15 01:36:40 1.9
***************
*** 14,75 ****
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
def reset():
! """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]
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]
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]
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]
def isdir(path):
! """Check for directory."""
! try:
! st = stat(path)
! except os.error:
! return 0
! return S_ISDIR(st[ST_MODE])
--- 14,75 ----
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
def reset():
! """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]
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]
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]
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]
def isdir(path):
! """Check for directory."""
! try:
! st = stat(path)
! except os.error:
! return 0
! return S_ISDIR(st[ST_MODE])
Index: statvfs.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/statvfs.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** statvfs.py 2000/02/04 15:28:41 1.4
--- statvfs.py 2001/01/15 01:36:40 1.5
***************
*** 4,15 ****
# 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
--- 4,15 ----
# 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
Index: string.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/string.py,v
retrieving revision 1.54
retrieving revision 1.55
diff -C2 -r1.54 -r1.55
*** string.py 2000/12/19 02:39:08 1.54
--- string.py 2001/01/15 01:36:40 1.55
***************
*** 28,32 ****
hexdigits = digits + 'abcdef' + 'ABCDEF'
octdigits = '01234567'
! punctuation = """!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
printable = digits + letters + punctuation + whitespace
--- 28,32 ----
hexdigits = digits + 'abcdef' + 'ABCDEF'
octdigits = '01234567'
! punctuation = """!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
printable = digits + letters + punctuation + whitespace
Index: sunau.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sunau.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -r1.18 -r1.19
*** sunau.py 2000/10/06 20:28:46 1.18
--- sunau.py 2001/01/15 01:36:40 1.19
***************
*** 44,66 ****
This returns an instance of a class with the following public methods:
! getnchannels() -- returns number of audio channels (1 for
! mono, 2 for stereo)
! getsampwidth() -- returns sample width in bytes
! getframerate() -- returns sampling frequency
! getnframes() -- returns number of audio frames
! getcomptype() -- returns compression type ('NONE' or 'ULAW')
! getcompname() -- returns human-readable version of
! compression type ('not compressed' matches 'NONE')
! getparams() -- returns a tuple consisting of all of the
! above in the above order
! getmarkers() -- returns None (for compatibility with the
! aifc module)
! getmark(id) -- raises an error since the mark does not
! exist (for compatibility with the aifc module)
! readframes(n) -- returns at most n frames of audio
! rewind() -- rewind to the beginning of the audio stream
! setpos(pos) -- seek to the specified position
! tell() -- return the current position
! close() -- close the instance (make it unusable)
The position returned by tell() and the position given to setpos()
are compatible and have nothing to do with the actual position in the
--- 44,66 ----
This returns an instance of a class with the following public methods:
! getnchannels() -- returns number of audio channels (1 for
! mono, 2 for stereo)
! getsampwidth() -- returns sample width in bytes
! getframerate() -- returns sampling frequency
! getnframes() -- returns number of audio frames
! getcomptype() -- returns compression type ('NONE' or 'ULAW')
! getcompname() -- returns human-readable version of
! compression type ('not compressed' matches 'NONE')
! getparams() -- returns a tuple consisting of all of the
! above in the above order
! getmarkers() -- returns None (for compatibility with the
! aifc module)
! getmark(id) -- raises an error since the mark does not
! exist (for compatibility with the aifc module)
! readframes(n) -- returns at most n frames of audio
! rewind() -- rewind to the beginning of the audio stream
! setpos(pos) -- seek to the specified position
! tell() -- return the current position
! close() -- close the instance (make it unusable)
The position returned by tell() and the position given to setpos()
are compatible and have nothing to do with the actual position in the
***************
*** 76,95 ****
This returns an instance of a class with the following public methods:
! setnchannels(n) -- set the number of channels
! setsampwidth(n) -- set the sample width
! setframerate(n) -- set the frame rate
! setnframes(n) -- set the number of frames
setcomptype(type, name)
! -- set the compression type and the
! human-readable compression type
setparams(tuple)-- set all parameters at once
! tell() -- return current position in output file
writeframesraw(data)
! -- write audio frames without pathing up the
! file header
writeframes(data)
! -- write audio frames and patch up the file header
! close() -- patch up the file header and close the
! output file
You should set the parameters before the first writeframesraw or
writeframes. The total number of frames does not need to be set,
--- 76,95 ----
This returns an instance of a class with the following public methods:
! setnchannels(n) -- set the number of channels
! setsampwidth(n) -- set the sample width
! setframerate(n) -- set the frame rate
! setnframes(n) -- set the number of frames
setcomptype(type, name)
! -- set the compression type and the
! human-readable compression type
setparams(tuple)-- set all parameters at once
! tell() -- return current position in output file
writeframesraw(data)
! -- write audio frames without pathing up the
! file header
writeframes(data)
! -- write audio frames and patch up the file header
! close() -- patch up the file header and close the
! output file
You should set the parameters before the first writeframesraw or
writeframes. The total number of frames does not need to be set,
***************
*** 120,474 ****
# from <multimedia/audio_hdr.h>
! AUDIO_UNKNOWN_SIZE = 0xFFFFFFFFL # ((unsigned)(~0))
_simple_encodings = [AUDIO_FILE_ENCODING_MULAW_8,
! AUDIO_FILE_ENCODING_LINEAR_8,
! AUDIO_FILE_ENCODING_LINEAR_16,
! AUDIO_FILE_ENCODING_LINEAR_24,
! AUDIO_FILE_ENCODING_LINEAR_32,
! AUDIO_FILE_ENCODING_ALAW_8]
class Error(Exception):
! pass
def _read_u32(file):
! x = 0L
! for i in range(4):
! byte = file.read(1)
! if byte == '':
! raise EOFError
! x = x*256 + ord(byte)
! return x
def _write_u32(file, x):
! data = []
! for i in range(4):
! d, m = divmod(x, 256)
! data.insert(0, m)
! x = d
! for i in range(4):
! file.write(chr(int(data[i])))
class Au_read:
! def __init__(self, f):
! if type(f) == type(''):
! import __builtin__
! f = __builtin__.open(f, 'rb')
! self.initfp(f)
!
! def __del__(self):
! if self._file:
! self.close()
!
! def initfp(self, file):
! self._file = file
! self._soundpos = 0
! magic = int(_read_u32(file))
! if magic != AUDIO_FILE_MAGIC:
! raise Error, 'bad magic number'
! self._hdr_size = int(_read_u32(file))
! if self._hdr_size < 24:
! raise Error, 'header size too small'
! if self._hdr_size > 100:
! raise Error, 'header size ridiculously large'
! self._data_size = _read_u32(file)
! if self._data_size != AUDIO_UNKNOWN_SIZE:
! self._data_size = int(self._data_size)
! self._encoding = int(_read_u32(file))
! if self._encoding not in _simple_encodings:
! raise Error, 'encoding not (yet) supported'
! if self._encoding in (AUDIO_FILE_ENCODING_MULAW_8,
! AUDIO_FILE_ENCODING_ALAW_8):
! self._sampwidth = 2
! self._framesize = 1
! elif self._encoding == AUDIO_FILE_ENCODING_LINEAR_8:
! self._framesize = self._sampwidth = 1
! elif self._encoding == AUDIO_FILE_ENCODING_LINEAR_16:
! self._framesize = self._sampwidth = 2
! elif self._encoding == AUDIO_FILE_ENCODING_LINEAR_24:
! self._framesize = self._sampwidth = 3
! elif self._encoding == AUDIO_FILE_ENCODING_LINEAR_32:
! self._framesize = self._sampwidth = 4
! else:
! raise Error, 'unknown encoding'
! self._framerate = int(_read_u32(file))
! self._nchannels = int(_read_u32(file))
! self._framesize = self._framesize * self._nchannels
! if self._hdr_size > 24:
! self._info = file.read(self._hdr_size - 24)
! for i in range(len(self._info)):
! if self._info[i] == '\0':
! self._info = self._info[:i]
! break
! else:
! self._info = ''
!
! def getfp(self):
! return self._file
!
! def getnchannels(self):
! return self._nchannels
!
! def getsampwidth(self):
! return self._sampwidth
!
! def getframerate(self):
! return self._framerate
!
! def getnframes(self):
! if self._data_size == AUDIO_UNKNOWN_SIZE:
! return AUDIO_UNKNOWN_SIZE
! if self._encoding in _simple_encodings:
! return self._data_size / self._framesize
! return 0 # XXX--must do some arithmetic here
!
! def getcomptype(self):
! if self._encoding == AUDIO_FILE_ENCODING_MULAW_8:
! return 'ULAW'
! elif self._encoding == AUDIO_FILE_ENCODING_ALAW_8:
! return 'ALAW'
! else:
! return 'NONE'
!
! def getcompname(self):
! if self._encoding == AUDIO_FILE_ENCODING_MULAW_8:
! return 'CCITT G.711 u-law'
! elif self._encoding == AUDIO_FILE_ENCODING_ALAW_8:
! return 'CCITT G.711 A-law'
! else:
! return 'not compressed'
!
! def getparams(self):
! return self.getnchannels(), self.getsampwidth(), \
! self.getframerate(), self.getnframes(), \
! self.getcomptype(), self.getcompname()
!
! def getmarkers(self):
! return None
!
! def getmark(self, id):
! raise Error, 'no marks'
!
! def readframes(self, nframes):
! if self._encoding in _simple_encodings:
! if nframes == AUDIO_UNKNOWN_SIZE:
! data = self._file.read()
! else:
! data = self._file.read(nframes * self._framesize * self._nchannels)
! if self._encoding == AUDIO_FILE_ENCODING_MULAW_8:
! import audioop
! data = audioop.ulaw2lin(data, self._sampwidth)
! return data
! return None # XXX--not implemented yet
!
! def rewind(self):
! self._soundpos = 0
! self._file.seek(self._hdr_size)
!
! def tell(self):
! return self._soundpos
!
! def setpos(self, pos):
! if pos < 0 or pos > self.getnframes():
! raise Error, 'position not in range'
! self._file.seek(pos * self._framesize + self._hdr_size)
! self._soundpos = pos
! def close(self):
! self._file = None
class Au_write:
! def __init__(self, f):
! if type(f) == type(''):
! import __builtin__
! f = __builtin__.open(f, 'wb')
! self.initfp(f)
!
! def __del__(self):
! if self._file:
! self.close()
!
! def initfp(self, file):
! self._file = file
! self._framerate = 0
! self._nchannels = 0
! self._sampwidth = 0
! self._framesize = 0
! self._nframes = AUDIO_UNKNOWN_SIZE
! self._nframeswritten = 0
! self._datawritten = 0
! self._datalength = 0
! self._info = ''
! self._comptype = 'ULAW' # default is U-law
!
! def setnchannels(self, nchannels):
! if self._nframeswritten:
! raise Error, 'cannot change parameters after starting to write'
! if nchannels not in (1, 2, 4):
! raise Error, 'only 1, 2, or 4 channels supported'
! self._nchannels = nchannels
!
! def getnchannels(self):
! if not self._nchannels:
! raise Error, 'number of channels not set'
! return self._nchannels
!
! def setsampwidth(self, sampwidth):
! if self._nframeswritten:
! raise Error, 'cannot change parameters after starting to write'
! if sampwidth not in (1, 2, 4):
! raise Error, 'bad sample width'
! self._sampwidth = sampwidth
!
! def getsampwidth(self):
! if not self._framerate:
! raise Error, 'sample width not specified'
! return self._sampwidth
!
! def setframerate(self, framerate):
! if self._nframeswritten:
! raise Error, 'cannot change parameters after starting to write'
! self._framerate = framerate
!
! def getframerate(self):
! if not self._framerate:
! raise Error, 'frame rate not set'
! return self._framerate
!
! def setnframes(self, nframes):
! if self._nframeswritten:
! raise Error, 'cannot change parameters after starting to write'
! if nframes < 0:
! raise Error, '# of frames cannot be negative'
! self._nframes = nframes
!
! def getnframes(self):
! return self._nframeswritten
!
! def setcomptype(self, type, name):
! if type in ('NONE', 'ULAW'):
! self._comptype = type
! else:
! raise Error, 'unknown compression type'
!
! def getcomptype(self):
! return self._comptype
!
! def getcompname(self):
! if self._comptype == 'ULAW':
! return 'CCITT G.711 u-law'
! elif self._comptype == 'ALAW':
! return 'CCITT G.711 A-law'
! else:
! return 'not compressed'
!
! def setparams(self, (nchannels, sampwidth, framerate, nframes, comptype, compname)):
! self.setnchannels(nchannels)
! self.setsampwidth(sampwidth)
! self.setframerate(framerate)
! self.setnframes(nframes)
! self.setcomptype(comptype, compname)
!
! def getparams(self):
! return self.getnchannels(), self.getsampwidth(), \
! self.getframerate(), self.getnframes(), \
! self.getcomptype(), self.getcompname()
!
! def tell(self):
! return self._nframeswritten
!
! def writeframesraw(self, data):
! self._ensure_header_written()
! nframes = len(data) / self._framesize
! if self._comptype == 'ULAW':
! import audioop
! data = audioop.lin2ulaw(data, self._sampwidth)
! self._file.write(data)
! self._nframeswritten = self._nframeswritten + nframes
! self._datawritten = self._datawritten + len(data)
!
! def writeframes(self, data):
! self.writeframesraw(data)
! if self._nframeswritten != self._nframes or \
! self._datalength != self._datawritten:
! self._patchheader()
!
! def close(self):
! self._ensure_header_written()
! if self._nframeswritten != self._nframes or \
! self._datalength != self._datawritten:
! self._patchheader()
! self._file.flush()
! self._file = None
!
! #
! # private methods
! #
!
! def _ensure_header_written(self):
! if not self._nframeswritten:
! if not self._nchannels:
! raise Error, '# of channels not specified'
! if not self._sampwidth:
! raise Error, 'sample width not specified'
! if not self._framerate:
! raise Error, 'frame rate not specified'
! self._write_header()
!
! def _write_header(self):
! if self._comptype == 'NONE':
! if self._sampwidth == 1:
! encoding = AUDIO_FILE_ENCODING_LINEAR_8
! self._framesize = 1
! elif self._sampwidth == 2:
! encoding = AUDIO_FILE_ENCODING_LINEAR_16
! self._framesize = 2
! elif self._sampwidth == 4:
! encoding = AUDIO_FILE_ENCODING_LINEAR_32
! self._framesize = 4
! else:
! raise Error, 'internal error'
! elif self._comptype == 'ULAW':
! encoding = AUDIO_FILE_ENCODING_MULAW_8
! self._framesize = 1
! else:
! raise Error, 'internal error'
! self._framesize = self._framesize * self._nchannels
! _write_u32(self._file, AUDIO_FILE_MAGIC)
! header_size = 25 + len(self._info)
! header_size = (header_size + 7) & ~7
! _write_u32(self._file, header_size)
! if self._nframes == AUDIO_UNKNOWN_SIZE:
! length = AUDIO_UNKNOWN_SIZE
! else:
! length = self._nframes * self._framesize
! _write_u32(self._file, length)
! self._datalength = length
! _write_u32(self._file, encoding)
! _write_u32(self._file, self._framerate)
! _write_u32(self._file, self._nchannels)
! self._file.write(self._info)
! self._file.write('\0'*(header_size - len(self._info) - 24))
!
! def _patchheader(self):
! self._file.seek(8)
! _write_u32(self._file, self._datawritten)
! self._datalength = self._datawritten
! self._file.seek(0, 2)
def open(f, mode=None):
! if mode is None:
! if hasattr(f, 'mode'):
! mode = f.mode
! else:
! mode = 'rb'
! if mode in ('r', 'rb'):
! return Au_read(f)
! elif mode in ('w', 'wb'):
! return Au_write(f)
! else:
! raise Error, "mode must be 'r', 'rb', 'w', or 'wb'"
openfp = open
--- 120,474 ----
# from <multimedia/audio_hdr.h>
! AUDIO_UNKNOWN_SIZE = 0xFFFFFFFFL # ((unsigned)(~0))
_simple_encodings = [AUDIO_FILE_ENCODING_MULAW_8,
! AUDIO_FILE_ENCODING_LINEAR_8,
! AUDIO_FILE_ENCODING_LINEAR_16,
! AUDIO_FILE_ENCODING_LINEAR_24,
! AUDIO_FILE_ENCODING_LINEAR_32,
! AUDIO_FILE_ENCODING_ALAW_8]
class Error(Exception):
! pass
def _read_u32(file):
! x = 0L
! for i in range(4):
! byte = file.read(1)
! if byte == '':
! raise EOFError
! x = x*256 + ord(byte)
! return x
def _write_u32(file, x):
! data = []
! for i in range(4):
! d, m = divmod(x, 256)
! data.insert(0, m)
! x = d
! for i in range(4):
! file.write(chr(int(data[i])))
class Au_read:
! def __init__(self, f):
! if type(f) == type(''):
! import __builtin__
! f = __builtin__.open(f, 'rb')
! self.initfp(f)
!
! def __del__(self):
! if self._file:
! self.close()
!
! def initfp(self, file):
! self._file = file
! self._soundpos = 0
! magic = int(_read_u32(file))
! if magic != AUDIO_FILE_MAGIC:
! raise Error, 'bad magic number'
! self._hdr_size = int(_read_u32(file))
! if self._hdr_size < 24:
! raise Error, 'header size too small'
! if self._hdr_size > 100:
! raise Error, 'header size ridiculously large'
! self._data_size = _read_u32(file)
! if self._data_size != AUDIO_UNKNOWN_SIZE:
! self._data_size = int(self._data_size)
! self._encoding = int(_read_u32(file))
! if self._encoding not in _simple_encodings:
! raise Error, 'encoding not (yet) supported'
! if self._encoding in (AUDIO_FILE_ENCODING_MULAW_8,
! AUDIO_FILE_ENCODING_ALAW_8):
! self._sampwidth = 2
! self._framesize = 1
! elif self._encoding == AUDIO_FILE_ENCODING_LINEAR_8:
! self._framesize = self._sampwidth = 1
! elif self._encoding == AUDIO_FILE_ENCODING_LINEAR_16:
! self._framesize = self._sampwidth = 2
! elif self._encoding == AUDIO_FILE_ENCODING_LINEAR_24:
! self._framesize = self._sampwidth = 3
! elif self._encoding == AUDIO_FILE_ENCODING_LINEAR_32:
! self._framesize = self._sampwidth = 4
! else:
! raise Error, 'unknown encoding'
! self._framerate = int(_read_u32(file))
! self._nchannels = int(_read_u32(file))
! self._framesize = self._framesize * self._nchannels
! if self._hdr_size > 24:
! self._info = file.read(self._hdr_size - 24)
! for i in range(len(self._info)):
! if self._info[i] == '\0':
! self._info = self._info[:i]
! break
! else:
! self._info = ''
!
! def getfp(self):
! return self._file
!
! def getnchannels(self):
! return self._nchannels
!
! def getsampwidth(self):
! return self._sampwidth
!
! def getframerate(self):
! return self._framerate
!
! def getnframes(self):
! if self._data_size == AUDIO_UNKNOWN_SIZE:
! return AUDIO_UNKNOWN_SIZE
! if self._encoding in _simple_encodings:
! return self._data_size / self._framesize
! return 0 # XXX--must do some arithmetic here
!
! def getcomptype(self):
! if self._encoding == AUDIO_FILE_ENCODING_MULAW_8:
! return 'ULAW'
! elif self._encoding == AUDIO_FILE_ENCODING_ALAW_8:
! return 'ALAW'
! else:
! return 'NONE'
!
! def getcompname(self):
! if self._encoding == AUDIO_FILE_ENCODING_MULAW_8:
! return 'CCITT G.711 u-law'
! elif self._encoding == AUDIO_FILE_ENCODING_ALAW_8:
! return 'CCITT G.711 A-law'
! else:
! return 'not compressed'
!
! def getparams(self):
! return self.getnchannels(), self.getsampwidth(), \
! self.getframerate(), self.getnframes(), \
! self.getcomptype(), self.getcompname()
!
! def getmarkers(self):
! return None
!
! def getmark(self, id):
! raise Error, 'no marks'
!
! def readframes(self, nframes):
! if self._encoding in _simple_encodings:
! if nframes == AUDIO_UNKNOWN_SIZE:
! data = self._file.read()
! else:
! data = self._file.read(nframes * self._framesize * self._nchannels)
! if self._encoding == AUDIO_FILE_ENCODING_MULAW_8:
! import audioop
! data = audioop.ulaw2lin(data, self._sampwidth)
! return data
! return None # XXX--not implemented yet
!
! def rewind(self):
! self._soundpos = 0
! self._file.seek(self._hdr_size)
!
! def tell(self):
! return self._soundpos
!
! def setpos(self, pos):
! if pos < 0 or pos > self.getnframes():
! raise Error, 'position not in range'
! self._file.seek(pos * self._framesize + self._hdr_size)
! self._soundpos = pos
! def close(self):
! self._file = None
class Au_write:
! def __init__(self, f):
! if type(f) == type(''):
! import __builtin__
! f = __builtin__.open(f, 'wb')
! self.initfp(f)
!
! def __del__(self):
! if self._file:
! self.close()
!
! def initfp(self, file):
! self._file = file
! self._framerate = 0
! self._nchannels = 0
! self._sampwidth = 0
! self._framesize = 0
! self._nframes = AUDIO_UNKNOWN_SIZE
! self._nframeswritten = 0
! self._datawritten = 0
! self._datalength = 0
! self._info = ''
! self._comptype = 'ULAW' # default is U-law
!
! def setnchannels(self, nchannels):
! if self._nframeswritten:
! raise Error, 'cannot change parameters after starting to write'
! if nchannels not in (1, 2, 4):
! raise Error, 'only 1, 2, or 4 channels supported'
! self._nchannels = nchannels
!
! def getnchannels(self):
! if not self._nchannels:
! raise Error, 'number of channels not set'
! return self._nchannels
!
! def setsampwidth(self, sampwidth):
! if self._nframeswritten:
! raise Error, 'cannot change parameters after starting to write'
! if sampwidth not in (1, 2, 4):
! raise Error, 'bad sample width'
! self._sampwidth = sampwidth
!
! def getsampwidth(self):
! if not self._framerate:
! raise Error, 'sample width not specified'
! return self._sampwidth
!
! def setframerate(self, framerate):
! if self._nframeswritten:
! raise Error, 'cannot change parameters after starting to write'
! self._framerate = framerate
!
! def getframerate(self):
! if not self._framerate:
! raise Error, 'frame rate not set'
! return self._framerate
!
! def setnframes(self, nframes):
! if self._nframeswritten:
! raise Error, 'cannot change parameters after starting to write'
! if nframes < 0:
! raise Error, '# of frames cannot be negative'
! self._nframes = nframes
!
! def getnframes(self):
! return self._nframeswritten
!
! def setcomptype(self, type, name):
! if type in ('NONE', 'ULAW'):
! self._comptype = type
! else:
! raise Error, 'unknown compression type'
!
! def getcomptype(self):
! return self._comptype
!
! def getcompname(self):
! if self._comptype == 'ULAW':
! return 'CCITT G.711 u-law'
! elif self._comptype == 'ALAW':
! return 'CCITT G.711 A-law'
! else:
! return 'not compressed'
!
! def setparams(self, (nchannels, sampwidth, framerate, nframes, comptype, compname)):
! self.setnchannels(nchannels)
! self.setsampwidth(sampwidth)
! self.setframerate(framerate)
! self.setnframes(nframes)
! self.setcomptype(comptype, compname)
!
! def getparams(self):
! return self.getnchannels(), self.getsampwidth(), \
! self.getframerate(), self.getnframes(), \
! self.getcomptype(), self.getcompname()
!
! def tell(self):
! return self._nframeswritten
!
! def writeframesraw(self, data):
! self._ensure_header_written()
! nframes = len(data) / self._framesize
! if self._comptype == 'ULAW':
! import audioop
! data = audioop.lin2ulaw(data, self._sampwidth)
! self._file.write(data)
! self._nframeswritten = self._nframeswritten + nframes
! self._datawritten = self._datawritten + len(data)
!
! def writeframes(self, data):
! self.writeframesraw(data)
! if self._nframeswritten != self._nframes or \
! self._datalength != self._datawritten:
! self._patchheader()
!
! def close(self):
! self._ensure_header_written()
! if self._nframeswritten != self._nframes or \
! self._datalength != self._datawritten:
! self._patchheader()
! self._file.flush()
! self._file = None
!
! #
! # private methods
! #
!
! def _ensure_header_written(self):
! if not self._nframeswritten:
! if not self._nchannels:
! raise Error, '# of channels not specified'
! if not self._sampwidth:
! raise Error, 'sample width not specified'
! if not self._framerate:
! raise Error, 'frame rate not specified'
! self._write_header()
!
! def _write_header(self):
! if self._comptype == 'NONE':
! if self._sampwidth == 1:
! encoding = AUDIO_FILE_ENCODING_LINEAR_8
! self._framesize = 1
! elif self._sampwidth == 2:
! encoding = AUDIO_FILE_ENCODING_LINEAR_16
! self._framesize = 2
! elif self._sampwidth == 4:
! encoding = AUDIO_FILE_ENCODING_LINEAR_32
! self._framesize = 4
! else:
! raise Error, 'internal error'
! elif self._comptype == 'ULAW':
! encoding = AUDIO_FILE_ENCODING_MULAW_8
! self._framesize = 1
! else:
! raise Error, 'internal error'
! self._framesize = self._framesize * self._nchannels
! _write_u32(self._file, AUDIO_FILE_MAGIC)
! header_size = 25 + len(self._info)
! header_size = (header_size + 7) & ~7
! _write_u32(self._file, header_size)
! if self._nframes == AUDIO_UNKNOWN_SIZE:
! length = AUDIO_UNKNOWN_SIZE
! else:
! length = self._nframes * self._framesize
! _write_u32(self._file, length)
! self._datalength = length
! _write_u32(self._file, encoding)
! _write_u32(self._file, self._framerate)
! _write_u32(self._file, self._nchannels)
! self._file.write(self._info)
! self._file.write('\0'*(header_size - len(self._info) - 24))
!
! def _patchheader(self):
! self._file.seek(8)
! _write_u32(self._file, self._datawritten)
! self._datalength = self._datawritten
! self._file.seek(0, 2)
def open(f, mode=None):
! if mode is None:
! if hasattr(f, 'mode'):
! mode = f.mode
! else:
! mode = 'rb'
! if mode in ('r', 'rb'):
! return Au_read(f)
! elif mode in ('w', 'wb'):
! return Au_write(f)
! else:
! raise Error, "mode must be 'r', 'rb', 'w', or 'wb'"
openfp = open
Index: sunaudio.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sunaudio.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** sunaudio.py 2000/12/12 23:20:45 1.6
--- sunaudio.py 2001/01/15 01:36:40 1.7
***************
*** 4,44 ****
class error(Exception):
! 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])
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)
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`
--- 4,44 ----
class error(Exception):
! 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])
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)
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`
- Previous message: [Python-checkins] CVS: python/dist/src/Lib random.py,1.14,1.15 reconvert.py,1.3,1.4 regex_syntax.py,1.3,1.4 regsub.py,1.9,1.10 repr.py,1.6,1.7 rexec.py,1.26,1.27 rfc822.py,1.52,1.53
- Next message: [Python-checkins] CVS: python/dist/src/Lib tabnanny.py,1.10,1.11 telnetlib.py,1.8,1.9 tempfile.py,1.26,1.27 threading.py,1.10,1.11 toaiff.py,1.8,1.9 tokenize.py,1.15,1.16 traceback.py,1.18,1.19 tty.py,1.2,1.3 tzparse.py,1.8,1.9
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]