[Python-checkins] CVS: python/dist/src/Lib UserString.py,1.7,1.8 urllib.py,1.110,1.111 urllib2.py,1.6,1.7 urlparse.py,1.27,1.28 uu.py,1.14,1.15 warnings.py,1.3,1.4 wave.py,1.13,1.14 webbrowser.py,1.6,1.7 whrandom.py,1.17,1.18 xdrlib.py,1.10,1.11 xmllib.py,1.25,1.26 zipfile.py,1.4,1.5
Tim Peters
python-dev@python.org
Sun, 14 Jan 2001 19:34:40 -0800
- Previous 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
- Next message: [Python-checkins] CVS: python/dist/src/Misc NEWS,1.94,1.95
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv16609/python/dist/src/lib
Modified Files:
UserString.py urllib.py urllib2.py urlparse.py uu.py
warnings.py wave.py webbrowser.py whrandom.py xdrlib.py
xmllib.py zipfile.py
Log Message:
Whitespace normalization. Top level of Lib now fixed-point for reindent.py!
Index: UserString.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/UserString.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** UserString.py 2000/10/25 21:58:20 1.7
--- UserString.py 2001/01/15 03:34:38 1.8
***************
*** 3,7 ****
"""A user-defined wrapper around string objects
! Note: string objects have grown methods in Python 1.6
This module requires Python 1.6 or later.
"""
--- 3,7 ----
"""A user-defined wrapper around string objects
! Note: string objects have grown methods in Python 1.6
This module requires Python 1.6 or later.
"""
***************
*** 15,19 ****
elif isinstance(seq, UserString):
self.data = seq.data[:]
! else:
self.data = str(seq)
def __str__(self): return str(self.data)
--- 15,19 ----
elif isinstance(seq, UserString):
self.data = seq.data[:]
! else:
self.data = str(seq)
def __str__(self): return str(self.data)
***************
*** 77,89 ****
else:
return self.__class__(self.data.encode(encoding))
! else:
return self.__class__(self.data.encode())
def endswith(self, suffix, start=0, end=sys.maxint):
return self.data.endswith(suffix, start, end)
! def expandtabs(self, tabsize=8):
return self.__class__(self.data.expandtabs(tabsize))
! def find(self, sub, start=0, end=sys.maxint):
return self.data.find(sub, start, end)
! def index(self, sub, start=0, end=sys.maxint):
return self.data.index(sub, start, end)
def isalpha(self): return self.data.isalpha()
--- 77,89 ----
else:
return self.__class__(self.data.encode(encoding))
! else:
return self.__class__(self.data.encode())
def endswith(self, suffix, start=0, end=sys.maxint):
return self.data.endswith(suffix, start, end)
! def expandtabs(self, tabsize=8):
return self.__class__(self.data.expandtabs(tabsize))
! def find(self, sub, start=0, end=sys.maxint):
return self.data.find(sub, start, end)
! def index(self, sub, start=0, end=sys.maxint):
return self.data.index(sub, start, end)
def isalpha(self): return self.data.isalpha()
***************
*** 100,120 ****
def lower(self): return self.__class__(self.data.lower())
def lstrip(self): return self.__class__(self.data.lstrip())
! def replace(self, old, new, maxsplit=-1):
return self.__class__(self.data.replace(old, new, maxsplit))
! def rfind(self, sub, start=0, end=sys.maxint):
return self.data.rfind(sub, start, end)
! def rindex(self, sub, start=0, end=sys.maxint):
return self.data.rindex(sub, start, end)
def rjust(self, width): return self.__class__(self.data.rjust(width))
def rstrip(self): return self.__class__(self.data.rstrip())
! def split(self, sep=None, maxsplit=-1):
return self.data.split(sep, maxsplit)
def splitlines(self, keepends=0): return self.data.splitlines(keepends)
! def startswith(self, prefix, start=0, end=sys.maxint):
return self.data.startswith(prefix, start, end)
def strip(self): return self.__class__(self.data.strip())
def swapcase(self): return self.__class__(self.data.swapcase())
def title(self): return self.__class__(self.data.title())
! def translate(self, *args):
return self.__class__(self.data.translate(*args))
def upper(self): return self.__class__(self.data.upper())
--- 100,120 ----
def lower(self): return self.__class__(self.data.lower())
def lstrip(self): return self.__class__(self.data.lstrip())
! def replace(self, old, new, maxsplit=-1):
return self.__class__(self.data.replace(old, new, maxsplit))
! def rfind(self, sub, start=0, end=sys.maxint):
return self.data.rfind(sub, start, end)
! def rindex(self, sub, start=0, end=sys.maxint):
return self.data.rindex(sub, start, end)
def rjust(self, width): return self.__class__(self.data.rjust(width))
def rstrip(self): return self.__class__(self.data.rstrip())
! def split(self, sep=None, maxsplit=-1):
return self.data.split(sep, maxsplit)
def splitlines(self, keepends=0): return self.data.splitlines(keepends)
! def startswith(self, prefix, start=0, end=sys.maxint):
return self.data.startswith(prefix, start, end)
def strip(self): return self.__class__(self.data.strip())
def swapcase(self): return self.__class__(self.data.swapcase())
def title(self): return self.__class__(self.data.title())
! def translate(self, *args):
return self.__class__(self.data.translate(*args))
def upper(self): return self.__class__(self.data.upper())
***************
*** 137,141 ****
def __init__(self, string=""):
self.data = string
! def __hash__(self):
raise TypeError, "unhashable type (it is mutable)"
def __setitem__(self, index, sub):
--- 137,141 ----
def __init__(self, string=""):
self.data = string
! def __hash__(self):
raise TypeError, "unhashable type (it is mutable)"
def __setitem__(self, index, sub):
***************
*** 158,162 ****
def immutable(self):
return UserString(self.data)
!
if __name__ == "__main__":
# execute the regression test to stdout, if called as a script:
--- 158,162 ----
def immutable(self):
return UserString(self.data)
!
if __name__ == "__main__":
# execute the regression test to stdout, if called as a script:
Index: urllib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/urllib.py,v
retrieving revision 1.110
retrieving revision 1.111
diff -C2 -r1.110 -r1.111
*** urllib.py 2001/01/08 07:09:25 1.110
--- urllib.py 2001/01/15 03:34:38 1.111
***************
*** 552,560 ****
scheme, realm = match.groups()
if scheme.lower() == 'basic':
! name = 'retry_' + self.type + '_basic_auth'
! if data is None:
! return getattr(self,name)(url, realm)
! else:
! return getattr(self,name)(url, realm, data)
def retry_http_basic_auth(self, url, realm, data=None):
--- 552,560 ----
scheme, realm = match.groups()
if scheme.lower() == 'basic':
! name = 'retry_' + self.type + '_basic_auth'
! if data is None:
! return getattr(self,name)(url, realm)
! else:
! return getattr(self,name)(url, realm, data)
def retry_http_basic_auth(self, url, realm, data=None):
***************
*** 572,583 ****
def retry_https_basic_auth(self, url, realm, data=None):
! host, selector = splithost(url)
! i = host.find('@') + 1
! host = host[i:]
! user, passwd = self.get_user_passwd(host, realm, i)
! if not (user or passwd): return None
! host = user + ':' + passwd + '@' + host
! newurl = '//' + host + selector
! return self.open_https(newurl)
def get_user_passwd(self, host, realm, clear_cache = 0):
--- 572,583 ----
def retry_https_basic_auth(self, url, realm, data=None):
! host, selector = splithost(url)
! i = host.find('@') + 1
! host = host[i:]
! user, passwd = self.get_user_passwd(host, realm, i)
! if not (user or passwd): return None
! host = user + ':' + passwd + '@' + host
! newurl = '//' + host + selector
! return self.open_https(newurl)
def get_user_passwd(self, host, realm, clear_cache = 0):
Index: urllib2.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/urllib2.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** urllib2.py 2000/10/12 18:54:18 1.6
--- urllib2.py 2001/01/15 03:34:38 1.7
***************
*** 2,11 ****
The simplest way to use this module is to call the urlopen function,
! which accepts a string containing a URL or a Request object (described
below). It opens the URL and returns the results as file-like
object; the returned object has some extra methods described below.
The OpenerDirectory manages a collection of Handler objects that do
! all the actual work. Each Handler implements a particular protocol or
option. The OpenerDirector is a composite object that invokes the
Handlers needed to open the requested URL. For example, the
--- 2,11 ----
The simplest way to use this module is to call the urlopen function,
! which accepts a string containing a URL or a Request object (described
below). It opens the URL and returns the results as file-like
object; the returned object has some extra methods described below.
The OpenerDirectory manages a collection of Handler objects that do
! all the actual work. Each Handler implements a particular protocol or
option. The OpenerDirector is a composite object that invokes the
Handlers needed to open the requested URL. For example, the
***************
*** 17,21 ****
urlopen(url, data=None) -- basic usage is that same as original
urllib. pass the url and optionally data to post to an HTTP URL, and
! get a file-like object back. One difference is that you can also pass
a Request instance instead of URL. Raises a URLError (subclass of
IOError); for HTTP errors, raises an HTTPError, which can also be
--- 17,21 ----
urlopen(url, data=None) -- basic usage is that same as original
urllib. pass the url and optionally data to post to an HTTP URL, and
! get a file-like object back. One difference is that you can also pass
a Request instance instead of URL. Raises a URLError (subclass of
IOError); for HTTP errors, raises an HTTPError, which can also be
***************
*** 43,47 ****
specific subclass
! HTTPError-- also a valid HTTP response, so you can treat an HTTP error
as an exceptional event or valid response
--- 43,47 ----
specific subclass
! HTTPError-- also a valid HTTP response, so you can treat an HTTP error
as an exceptional event or valid response
***************
*** 58,62 ****
authinfo.add_password('realm', 'host', 'username', 'password')
! # build a new opener that adds authentication and caching FTP handlers
opener = urllib2.build_opener(authinfo, urllib2.CacheFTPHandler)
--- 58,62 ----
authinfo.add_password('realm', 'host', 'username', 'password')
! # build a new opener that adds authentication and caching FTP handlers
opener = urllib2.build_opener(authinfo, urllib2.CacheFTPHandler)
***************
*** 74,78 ****
# signalled? The client needs to know the HTTP error code. But if
# the handler knows that the problem was, e.g., that it didn't know
! # that hash algo that requested in the challenge, it would be good to
# pass that information along to the client, too.
--- 74,78 ----
# signalled? The client needs to know the HTTP error code. But if
# the handler knows that the problem was, e.g., that it didn't know
! # that hash algo that requested in the challenge, it would be good to
# pass that information along to the client, too.
***************
*** 142,146 ****
# do these error classes make sense?
! # make sure all of the IOError stuff is overridden. we just want to be
# subtypes.
--- 142,146 ----
# do these error classes make sense?
! # make sure all of the IOError stuff is overridden. we just want to be
# subtypes.
***************
*** 166,170 ****
# XXX
self.filename = url
!
def __str__(self):
return 'HTTP Error %s: %s' % (self.code, self.msg)
--- 166,170 ----
# XXX
self.filename = url
!
def __str__(self):
return 'HTTP Error %s: %s' % (self.code, self.msg)
***************
*** 193,197 ****
def __getattr__(self, attr):
# XXX this is a fallback mechanism to guard against these
! # methods getting called in a non-standard order. this may be
# too complicated and/or unnecessary.
# XXX should the __r_XXX attributes be public?
--- 193,197 ----
def __getattr__(self, attr):
# XXX this is a fallback mechanism to guard against these
! # methods getting called in a non-standard order. this may be
# too complicated and/or unnecessary.
# XXX should the __r_XXX attributes be public?
***************
*** 260,264 ****
if meth[-5:] == '_open':
protocol = meth[:-5]
! if self.handle_open.has_key(protocol):
self.handle_open[protocol].append(handler)
else:
--- 260,264 ----
if meth[-5:] == '_open':
protocol = meth[:-5]
! if self.handle_open.has_key(protocol):
self.handle_open[protocol].append(handler)
else:
***************
*** 286,290 ****
self.handlers.append(handler)
handler.add_parent(self)
!
def __del__(self):
self.close()
--- 286,290 ----
self.handlers.append(handler)
handler.add_parent(self)
!
def __del__(self):
self.close()
***************
*** 315,321 ****
req.add_data(data)
assert isinstance(req, Request) # really only care about interface
!
result = self._call_chain(self.handle_open, 'default',
! 'default_open', req)
if result:
return result
--- 315,321 ----
req.add_data(data)
assert isinstance(req, Request) # really only care about interface
!
result = self._call_chain(self.handle_open, 'default',
! 'default_open', req)
if result:
return result
***************
*** 382,386 ****
# the fact that a ProxyHandler needs to get inserted first.
# would also know when it makes sense to skip a superclass in favor of
! # a subclass and when it might make sense to include both
def build_opener(*handlers):
--- 382,386 ----
# the fact that a ProxyHandler needs to get inserted first.
# would also know when it makes sense to skip a superclass in favor of
! # a subclass and when it might make sense to include both
def build_opener(*handlers):
***************
*** 394,398 ****
default handlers, the default handlers will not be used.
"""
!
opener = OpenerDirector()
default_classes = [ProxyHandler, UnknownHandler, HTTPHandler,
--- 394,398 ----
default handlers, the default handlers will not be used.
"""
!
opener = OpenerDirector()
default_classes = [ProxyHandler, UnknownHandler, HTTPHandler,
***************
*** 473,477 ****
self.proxies = proxies
for type, url in proxies.items():
! setattr(self, '%s_open' % type,
lambda r, proxy=url, type=type, meth=self.proxy_open: \
meth(r, proxy, type))
--- 473,477 ----
self.proxies = proxies
for type, url in proxies.items():
! setattr(self, '%s_open' % type,
lambda r, proxy=url, type=type, meth=self.proxy_open: \
meth(r, proxy, type))
***************
*** 575,579 ****
return 1
return 0
!
class HTTPBasicAuthHandler(BaseHandler):
--- 575,579 ----
return 1
return 0
!
class HTTPBasicAuthHandler(BaseHandler):
***************
*** 591,596 ****
# refused our name/password and is asking for authorization
# again. must be careful to set it to None on successful
! # return.
!
def http_error_401(self, req, fp, code, msg, headers):
# XXX could be mult. headers
--- 591,596 ----
# refused our name/password and is asking for authorization
# again. must be careful to set it to None on successful
! # return.
!
def http_error_401(self, req, fp, code, msg, headers):
# XXX could be mult. headers
***************
*** 675,679 ****
user, pw = self.passwd.find_user_password(realm,
! req.get_full_url())
if user is None:
return None
--- 675,679 ----
user, pw = self.passwd.find_user_password(realm,
! req.get_full_url())
if user is None:
return None
***************
*** 725,730 ****
hexrep.append(hex(n)[-1])
return string.join(hexrep, '')
!
!
class HTTPHandler(BaseHandler):
def http_open(self, req):
--- 725,730 ----
hexrep.append(hex(n)[-1])
return string.join(hexrep, '')
!
!
class HTTPHandler(BaseHandler):
def http_open(self, req):
***************
*** 746,750 ****
except socket.error, err:
raise URLError(err)
!
# XXX proxies would have different host here
h.putheader('Host', host)
--- 746,750 ----
except socket.error, err:
raise URLError(err)
!
# XXX proxies would have different host here
h.putheader('Host', host)
***************
*** 814,818 ****
inquote = 0
else:
! i = i + q
else:
if c < q:
--- 814,818 ----
inquote = 0
else:
! i = i + q
else:
if c < q:
***************
*** 839,843 ****
def get_names(self):
if FileHandler.names is None:
! FileHandler.names = (socket.gethostbyname('localhost'),
socket.gethostbyname(socket.gethostname()))
return FileHandler.names
--- 839,843 ----
def get_names(self):
if FileHandler.names is None:
! FileHandler.names = (socket.gethostbyname('localhost'),
socket.gethostbyname(socket.gethostname()))
return FileHandler.names
***************
*** 968,972 ****
default_handlers = [UnknownHandler, HTTPHandler,
! HTTPDefaultErrorHandler, HTTPRedirectHandler,
FTPHandler, FileHandler]
proxy_handlers = [ProxyHandler]
--- 968,972 ----
default_handlers = [UnknownHandler, HTTPHandler,
! HTTPDefaultErrorHandler, HTTPRedirectHandler,
FTPHandler, FileHandler]
proxy_handlers = [ProxyHandler]
***************
*** 991,995 ****
if __name__ == "__main__":
! # XXX some of the test code depends on machine configurations that
# are internal to CNRI. Need to set up a public server with the
# right authentication configuration for test purposes.
--- 991,995 ----
if __name__ == "__main__":
! # XXX some of the test code depends on machine configurations that
# are internal to CNRI. Need to set up a public server with the
# right authentication configuration for test purposes.
***************
*** 1031,1039 ****
bauth = HTTPBasicAuthHandler()
bauth.add_password('basic_test_realm', localhost, 'jhylton',
! 'password')
dauth = HTTPDigestAuthHandler()
! dauth.add_password('digest_test_realm', localhost, 'jhylton',
'password')
!
cfh = CacheFTPHandler()
--- 1031,1039 ----
bauth = HTTPBasicAuthHandler()
bauth.add_password('basic_test_realm', localhost, 'jhylton',
! 'password')
dauth = HTTPDigestAuthHandler()
! dauth.add_password('digest_test_realm', localhost, 'jhylton',
'password')
!
cfh = CacheFTPHandler()
Index: urlparse.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/urlparse.py,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -r1.27 -r1.28
*** urlparse.py 2001/01/05 05:54:41 1.27
--- urlparse.py 2001/01/15 03:34:38 1.28
***************
*** 7,29 ****
# A classification of schemes ('' means apply by default)
uses_relative = ['ftp', 'http', 'gopher', 'nntp', 'wais', 'file',
! 'https', 'shttp',
! 'prospero', 'rtsp', 'rtspu', '']
uses_netloc = ['ftp', 'http', 'gopher', 'nntp', 'telnet', 'wais',
! 'file',
! 'https', 'shttp', 'snews',
! 'prospero', 'rtsp', 'rtspu', '']
non_hierarchical = ['gopher', 'hdl', 'mailto', 'news', 'telnet', 'wais',
! 'snews', 'sip',
! ]
uses_params = ['ftp', 'hdl', 'prospero', 'http',
! 'https', 'shttp', 'rtsp', 'rtspu', 'sip',
! '']
uses_query = ['http', 'wais',
! 'https', 'shttp',
! 'gopher', 'rtsp', 'rtspu', 'sip',
! '']
uses_fragment = ['ftp', 'hdl', 'http', 'gopher', 'news', 'nntp', 'wais',
! 'https', 'shttp', 'snews',
! 'file', 'prospero', '']
# Characters valid in scheme names
--- 7,29 ----
# A classification of schemes ('' means apply by default)
uses_relative = ['ftp', 'http', 'gopher', 'nntp', 'wais', 'file',
! 'https', 'shttp',
! 'prospero', 'rtsp', 'rtspu', '']
uses_netloc = ['ftp', 'http', 'gopher', 'nntp', 'telnet', 'wais',
! 'file',
! 'https', 'shttp', 'snews',
! 'prospero', 'rtsp', 'rtspu', '']
non_hierarchical = ['gopher', 'hdl', 'mailto', 'news', 'telnet', 'wais',
! 'snews', 'sip',
! ]
uses_params = ['ftp', 'hdl', 'prospero', 'http',
! 'https', 'shttp', 'rtsp', 'rtspu', 'sip',
! '']
uses_query = ['http', 'wais',
! 'https', 'shttp',
! 'gopher', 'rtsp', 'rtspu', 'sip',
! '']
uses_fragment = ['ftp', 'hdl', 'http', 'gopher', 'news', 'nntp', 'wais',
! 'https', 'shttp', 'snews',
! 'file', 'prospero', '']
# Characters valid in scheme names
***************
*** 37,192 ****
def clear_cache():
! """Clear the parse cache."""
! global _parse_cache
! _parse_cache = {}
def urlparse(url, scheme = '', allow_fragments = 1):
! """Parse a URL into 6 components:
! <scheme>://<netloc>/<path>;<params>?<query>#<fragment>
! Return a 6-tuple: (scheme, netloc, path, params, query, fragment).
! Note that we don't break the components up in smaller bits
! (e.g. netloc is a single string) and we don't expand % escapes."""
! key = url, scheme, allow_fragments
! cached = _parse_cache.get(key, None)
! if cached:
! return cached
! if len(_parse_cache) >= MAX_CACHE_SIZE: # avoid runaway growth
! clear_cache()
! netloc = path = params = query = fragment = ''
! i = url.find(':')
! if i > 0:
! if url[:i] == 'http': # optimize the common case
! scheme = url[:i].lower()
! url = url[i+1:]
! if url[:2] == '//':
! i = url.find('/', 2)
! if i < 0:
! i = len(url)
! netloc = url[2:i]
! url = url[i:]
! if allow_fragments:
! i = url.rfind('#')
! if i >= 0:
! fragment = url[i+1:]
! url = url[:i]
! i = url.find('?')
! if i >= 0:
! query = url[i+1:]
! url = url[:i]
! i = url.find(';')
! if i >= 0:
! params = url[i+1:]
! url = url[:i]
! tuple = scheme, netloc, url, params, query, fragment
! _parse_cache[key] = tuple
! return tuple
! for c in url[:i]:
! if c not in scheme_chars:
! break
! else:
! scheme, url = url[:i].lower(), url[i+1:]
! if scheme in uses_netloc:
! if url[:2] == '//':
! i = url.find('/', 2)
! if i < 0:
! i = len(url)
! netloc, url = url[2:i], url[i:]
! if allow_fragments and scheme in uses_fragment:
! i = url.rfind('#')
! if i >= 0:
! url, fragment = url[:i], url[i+1:]
! if scheme in uses_query:
! i = url.find('?')
! if i >= 0:
! url, query = url[:i], url[i+1:]
! if scheme in uses_params:
! i = url.find(';')
! if i >= 0:
! url, params = url[:i], url[i+1:]
! tuple = scheme, netloc, url, params, query, fragment
! _parse_cache[key] = tuple
! return tuple
def urlunparse((scheme, netloc, url, params, query, fragment)):
! """Put a parsed URL back together again. This may result in a
! slightly different, but equivalent URL, if the URL that was parsed
! originally had redundant delimiters, e.g. a ? with an empty query
! (the draft states that these are equivalent)."""
! if netloc or (scheme in uses_netloc and url[:2] == '//'):
! if url and url[:1] != '/': url = '/' + url
! url = '//' + (netloc or '') + url
! if scheme:
! url = scheme + ':' + url
! if params:
! url = url + ';' + params
! if query:
! url = url + '?' + query
! if fragment:
! url = url + '#' + fragment
! return url
def urljoin(base, url, allow_fragments = 1):
! """Join a base URL and a possibly relative URL to form an absolute
! interpretation of the latter."""
! if not base:
! return url
! if not url:
! return base
! bscheme, bnetloc, bpath, bparams, bquery, bfragment = \
! urlparse(base, '', allow_fragments)
! scheme, netloc, path, params, query, fragment = \
! urlparse(url, bscheme, allow_fragments)
! if scheme != bscheme or scheme not in uses_relative:
! return url
! if scheme in uses_netloc:
! if netloc:
! return urlunparse((scheme, netloc, path,
! params, query, fragment))
! netloc = bnetloc
! if path[:1] == '/':
! return urlunparse((scheme, netloc, path,
! params, query, fragment))
! if not path:
! if not params:
! params = bparams
! if not query:
! query = bquery
! return urlunparse((scheme, netloc, bpath,
! params, query, fragment))
! segments = bpath.split('/')[:-1] + path.split('/')
! # XXX The stuff below is bogus in various ways...
! if segments[-1] == '.':
! segments[-1] = ''
! while '.' in segments:
! segments.remove('.')
! while 1:
! i = 1
! n = len(segments) - 1
! while i < n:
! if (segments[i] == '..'
! and segments[i-1] not in ('', '..')):
! del segments[i-1:i+1]
! break
! i = i+1
! else:
! break
! if segments == ['', '..']:
! segments[-1] = ''
! elif len(segments) >= 2 and segments[-1] == '..':
! segments[-2:] = ['']
! return urlunparse((scheme, netloc, '/'.join(segments),
! params, query, fragment))
def urldefrag(url):
! """Removes any existing fragment from URL.
! Returns a tuple of the defragmented URL and the fragment. If
! the URL contained no fragments, the second element is the
! empty string.
! """
! s, n, p, a, q, frag = urlparse(url)
! defrag = urlunparse((s, n, p, a, q, ''))
! return defrag, frag
--- 37,192 ----
def clear_cache():
! """Clear the parse cache."""
! global _parse_cache
! _parse_cache = {}
def urlparse(url, scheme = '', allow_fragments = 1):
! """Parse a URL into 6 components:
! <scheme>://<netloc>/<path>;<params>?<query>#<fragment>
! Return a 6-tuple: (scheme, netloc, path, params, query, fragment).
! Note that we don't break the components up in smaller bits
! (e.g. netloc is a single string) and we don't expand % escapes."""
! key = url, scheme, allow_fragments
! cached = _parse_cache.get(key, None)
! if cached:
! return cached
! if len(_parse_cache) >= MAX_CACHE_SIZE: # avoid runaway growth
! clear_cache()
! netloc = path = params = query = fragment = ''
! i = url.find(':')
! if i > 0:
! if url[:i] == 'http': # optimize the common case
! scheme = url[:i].lower()
! url = url[i+1:]
! if url[:2] == '//':
! i = url.find('/', 2)
! if i < 0:
! i = len(url)
! netloc = url[2:i]
! url = url[i:]
! if allow_fragments:
! i = url.rfind('#')
! if i >= 0:
! fragment = url[i+1:]
! url = url[:i]
! i = url.find('?')
! if i >= 0:
! query = url[i+1:]
! url = url[:i]
! i = url.find(';')
! if i >= 0:
! params = url[i+1:]
! url = url[:i]
! tuple = scheme, netloc, url, params, query, fragment
! _parse_cache[key] = tuple
! return tuple
! for c in url[:i]:
! if c not in scheme_chars:
! break
! else:
! scheme, url = url[:i].lower(), url[i+1:]
! if scheme in uses_netloc:
! if url[:2] == '//':
! i = url.find('/', 2)
! if i < 0:
! i = len(url)
! netloc, url = url[2:i], url[i:]
! if allow_fragments and scheme in uses_fragment:
! i = url.rfind('#')
! if i >= 0:
! url, fragment = url[:i], url[i+1:]
! if scheme in uses_query:
! i = url.find('?')
! if i >= 0:
! url, query = url[:i], url[i+1:]
! if scheme in uses_params:
! i = url.find(';')
! if i >= 0:
! url, params = url[:i], url[i+1:]
! tuple = scheme, netloc, url, params, query, fragment
! _parse_cache[key] = tuple
! return tuple
def urlunparse((scheme, netloc, url, params, query, fragment)):
! """Put a parsed URL back together again. This may result in a
! slightly different, but equivalent URL, if the URL that was parsed
! originally had redundant delimiters, e.g. a ? with an empty query
! (the draft states that these are equivalent)."""
! if netloc or (scheme in uses_netloc and url[:2] == '//'):
! if url and url[:1] != '/': url = '/' + url
! url = '//' + (netloc or '') + url
! if scheme:
! url = scheme + ':' + url
! if params:
! url = url + ';' + params
! if query:
! url = url + '?' + query
! if fragment:
! url = url + '#' + fragment
! return url
def urljoin(base, url, allow_fragments = 1):
! """Join a base URL and a possibly relative URL to form an absolute
! interpretation of the latter."""
! if not base:
! return url
! if not url:
! return base
! bscheme, bnetloc, bpath, bparams, bquery, bfragment = \
! urlparse(base, '', allow_fragments)
! scheme, netloc, path, params, query, fragment = \
! urlparse(url, bscheme, allow_fragments)
! if scheme != bscheme or scheme not in uses_relative:
! return url
! if scheme in uses_netloc:
! if netloc:
! return urlunparse((scheme, netloc, path,
! params, query, fragment))
! netloc = bnetloc
! if path[:1] == '/':
! return urlunparse((scheme, netloc, path,
! params, query, fragment))
! if not path:
! if not params:
! params = bparams
! if not query:
! query = bquery
! return urlunparse((scheme, netloc, bpath,
! params, query, fragment))
! segments = bpath.split('/')[:-1] + path.split('/')
! # XXX The stuff below is bogus in various ways...
! if segments[-1] == '.':
! segments[-1] = ''
! while '.' in segments:
! segments.remove('.')
! while 1:
! i = 1
! n = len(segments) - 1
! while i < n:
! if (segments[i] == '..'
! and segments[i-1] not in ('', '..')):
! del segments[i-1:i+1]
! break
! i = i+1
! else:
! break
! if segments == ['', '..']:
! segments[-1] = ''
! elif len(segments) >= 2 and segments[-1] == '..':
! segments[-2:] = ['']
! return urlunparse((scheme, netloc, '/'.join(segments),
! params, query, fragment))
def urldefrag(url):
! """Removes any existing fragment from URL.
! Returns a tuple of the defragmented URL and the fragment. If
! the URL contained no fragments, the second element is the
! empty string.
! """
! s, n, p, a, q, frag = urlparse(url)
! defrag = urlunparse((s, n, p, a, q, ''))
! return defrag, frag
***************
*** 227,259 ****
def test():
! import sys
! base = ''
! if sys.argv[1:]:
! fn = sys.argv[1]
! if fn == '-':
! fp = sys.stdin
! else:
! fp = open(fn)
! else:
! import StringIO
! fp = StringIO.StringIO(test_input)
! while 1:
! line = fp.readline()
! if not line: break
! words = line.split()
! if not words:
! continue
! url = words[0]
! parts = urlparse(url)
! print '%-10s : %s' % (url, parts)
! abs = urljoin(base, url)
! if not base:
! base = abs
! wrapped = '<URL:%s>' % abs
! print '%-10s = %s' % (url, wrapped)
! if len(words) == 3 and words[1] == '=':
! if wrapped != words[2]:
! print 'EXPECTED', words[2], '!!!!!!!!!!'
if __name__ == '__main__':
! test()
--- 227,259 ----
def test():
! import sys
! base = ''
! if sys.argv[1:]:
! fn = sys.argv[1]
! if fn == '-':
! fp = sys.stdin
! else:
! fp = open(fn)
! else:
! import StringIO
! fp = StringIO.StringIO(test_input)
! while 1:
! line = fp.readline()
! if not line: break
! words = line.split()
! if not words:
! continue
! url = words[0]
! parts = urlparse(url)
! print '%-10s : %s' % (url, parts)
! abs = urljoin(base, url)
! if not base:
! base = abs
! wrapped = '<URL:%s>' % abs
! print '%-10s = %s' % (url, wrapped)
! if len(words) == 3 and words[1] == '=':
! if wrapped != words[2]:
! print 'EXPECTED', words[2], '!!!!!!!!!!'
if __name__ == '__main__':
! test()
Index: uu.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/uu.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -r1.14 -r1.15
*** uu.py 2001/01/10 19:14:28 1.14
--- uu.py 2001/01/15 03:34:38 1.15
***************
*** 4,13 ****
# Cathedral City, California Republic, United States of America.
# All Rights Reserved
! # Permission to use, copy, modify, and distribute this software and its
! # documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
! # both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of Lance Ellinghouse
! # not be used in advertising or publicity pertaining to distribution
# of the software without specific, written prior permission.
# LANCE ELLINGHOUSE DISCLAIMS ALL WARRANTIES WITH REGARD TO
--- 4,13 ----
# Cathedral City, California Republic, United States of America.
# All Rights Reserved
! # Permission to use, copy, modify, and distribute this software and its
! # documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
! # both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of Lance Ellinghouse
! # not be used in advertising or publicity pertaining to distribution
# of the software without specific, written prior permission.
# LANCE ELLINGHOUSE DISCLAIMS ALL WARRANTIES WITH REGARD TO
***************
*** 155,159 ****
print ' -t: data is text, encoded format unix-compatible text'
sys.exit(1)
!
for o, a in optlist:
if o == '-d': dopt = 1
--- 155,159 ----
print ' -t: data is text, encoded format unix-compatible text'
sys.exit(1)
!
for o, a in optlist:
if o == '-d': dopt = 1
Index: warnings.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/warnings.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** warnings.py 2001/01/14 14:08:40 1.3
--- warnings.py 2001/01/15 03:34:38 1.4
***************
*** 132,158 ****
# Helper for _processoptions()
def _setoption(arg):
! parts = arg.split(':')
! if len(parts) > 5:
! raise _OptionError("too many fields (max 5): %s" % `arg`)
! while len(parts) < 5:
! parts.append('')
! action, message, category, module, lineno = [s.strip()
! for s in parts]
! action = _getaction(action)
! message = re.escape(message)
! category = _getcategory(category)
! module = re.escape(module)
! if module:
! module = module + '$'
! if lineno:
! try:
! lineno = int(lineno)
! if lineno < 0:
! raise ValueError
! except (ValueError, OverflowError):
! raise _OptionError("invalid lineno %s" % `lineno`)
! else:
! lineno = 0
! filterwarnings(action, message, category, module, lineno)
# Helper for _setoption()
--- 132,158 ----
# Helper for _processoptions()
def _setoption(arg):
! parts = arg.split(':')
! if len(parts) > 5:
! raise _OptionError("too many fields (max 5): %s" % `arg`)
! while len(parts) < 5:
! parts.append('')
! action, message, category, module, lineno = [s.strip()
! for s in parts]
! action = _getaction(action)
! message = re.escape(message)
! category = _getcategory(category)
! module = re.escape(module)
! if module:
! module = module + '$'
! if lineno:
! try:
! lineno = int(lineno)
! if lineno < 0:
! raise ValueError
! except (ValueError, OverflowError):
! raise _OptionError("invalid lineno %s" % `lineno`)
! else:
! lineno = 0
! filterwarnings(action, message, category, module, lineno)
# Helper for _setoption()
Index: wave.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/wave.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** wave.py 2000/10/09 23:43:55 1.13
--- wave.py 2001/01/15 03:34:38 1.14
***************
*** 396,400 ****
def getmarkers(self):
return None
!
def tell(self):
return self._nframeswritten
--- 396,400 ----
def getmarkers(self):
return None
!
def tell(self):
return self._nframeswritten
Index: webbrowser.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/webbrowser.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** webbrowser.py 2001/01/14 23:09:35 1.6
--- webbrowser.py 2001/01/15 03:34:38 1.7
***************
*** 123,127 ****
def open(self, url, new=1):
! # XXX currently I know no way to prevent KFM from opening a new win.
self.open_new(url)
--- 123,127 ----
def open(self, url, new=1):
! # XXX currently I know no way to prevent KFM from opening a new win.
self.open_new(url)
Index: whrandom.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/whrandom.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -r1.17 -r1.18
*** whrandom.py 2000/06/30 19:33:35 1.17
--- whrandom.py 2001/01/15 03:34:38 1.18
***************
*** 2,20 ****
Wichmann, B. A. & Hill, I. D. (1982)
! Algorithm AS 183:
An efficient and portable pseudo-random number generator
Applied Statistics 31 (1982) 188-190
! see also:
Correction to Algorithm AS 183
! Applied Statistics 33 (1984) 123
McLeod, A. I. (1985)
! A remark on Algorithm AS 183
Applied Statistics 34 (1985),198-200
USE:
! whrandom.random() yields double precision random numbers
uniformly distributed between 0 and 1.
--- 2,20 ----
Wichmann, B. A. & Hill, I. D. (1982)
! Algorithm AS 183:
An efficient and portable pseudo-random number generator
Applied Statistics 31 (1982) 188-190
! see also:
Correction to Algorithm AS 183
! Applied Statistics 33 (1984) 123
McLeod, A. I. (1985)
! A remark on Algorithm AS 183
Applied Statistics 34 (1985),198-200
USE:
! whrandom.random() yields double precision random numbers
uniformly distributed between 0 and 1.
***************
*** 39,132 ****
class whrandom:
! def __init__(self, x = 0, y = 0, z = 0):
! """Initialize an instance.
! Without arguments, initialize from current time.
! With arguments (x, y, z), initialize from them."""
! self.seed(x, y, z)
!
! def seed(self, x = 0, y = 0, z = 0):
! """Set the seed from (x, y, z).
! These must be integers in the range [0, 256)."""
! if not type(x) == type(y) == type(z) == type(0):
! raise TypeError, 'seeds must be integers'
! if not (0 <= x < 256 and 0 <= y < 256 and 0 <= z < 256):
! raise ValueError, 'seeds must be in range(0, 256)'
! if 0 == x == y == z:
! # Initialize from current time
! import time
! t = long(time.time() * 256)
! t = int((t&0xffffff) ^ (t>>24))
! t, x = divmod(t, 256)
! t, y = divmod(t, 256)
! t, z = divmod(t, 256)
! # Zero is a poor seed, so substitute 1
! self._seed = (x or 1, y or 1, z or 1)
!
! def random(self):
! """Get the next random number in the range [0.0, 1.0)."""
! # This part is thread-unsafe:
! # BEGIN CRITICAL SECTION
! x, y, z = self._seed
! #
! x = (171 * x) % 30269
! y = (172 * y) % 30307
! z = (170 * z) % 30323
! #
! self._seed = x, y, z
! # END CRITICAL SECTION
! #
! return (x/30269.0 + y/30307.0 + z/30323.0) % 1.0
!
! def uniform(self, a, b):
! """Get a random number in the range [a, b)."""
! return a + (b-a) * self.random()
!
! def randint(self, a, b):
! """Get a random integer in the range [a, b] including
! both end points.
!
! (Deprecated; use randrange below.)"""
! return self.randrange(a, b+1)
!
! def choice(self, seq):
! """Choose a random element from a non-empty sequence."""
! return seq[int(self.random() * len(seq))]
!
! def randrange(self, start, stop=None, step=1, int=int, default=None):
! """Choose a random item from range(start, stop[, step]).
!
! This fixes the problem with randint() which includes the
! endpoint; in Python this is usually not what you want.
! Do not supply the 'int' and 'default' arguments."""
! # This code is a bit messy to make it fast for the
! # common case while still doing adequate error checking
! istart = int(start)
! if istart != start:
! raise ValueError, "non-integer arg 1 for randrange()"
! if stop is default:
! if istart > 0:
! return int(self.random() * istart)
! raise ValueError, "empty range for randrange()"
! istop = int(stop)
! if istop != stop:
! raise ValueError, "non-integer stop for randrange()"
! if step == 1:
! if istart < istop:
! return istart + int(self.random() *
! (istop - istart))
! raise ValueError, "empty range for randrange()"
! istep = int(step)
! if istep != step:
! raise ValueError, "non-integer step for randrange()"
! if istep > 0:
! n = (istop - istart + istep - 1) / istep
! elif istep < 0:
! n = (istop - istart + istep + 1) / istep
! else:
! raise ValueError, "zero step for randrange()"
!
! if n <= 0:
! raise ValueError, "empty range for randrange()"
! return istart + istep*int(self.random() * n)
--- 39,132 ----
class whrandom:
! def __init__(self, x = 0, y = 0, z = 0):
! """Initialize an instance.
! Without arguments, initialize from current time.
! With arguments (x, y, z), initialize from them."""
! self.seed(x, y, z)
!
! def seed(self, x = 0, y = 0, z = 0):
! """Set the seed from (x, y, z).
! These must be integers in the range [0, 256)."""
! if not type(x) == type(y) == type(z) == type(0):
! raise TypeError, 'seeds must be integers'
! if not (0 <= x < 256 and 0 <= y < 256 and 0 <= z < 256):
! raise ValueError, 'seeds must be in range(0, 256)'
! if 0 == x == y == z:
! # Initialize from current time
! import time
! t = long(time.time() * 256)
! t = int((t&0xffffff) ^ (t>>24))
! t, x = divmod(t, 256)
! t, y = divmod(t, 256)
! t, z = divmod(t, 256)
! # Zero is a poor seed, so substitute 1
! self._seed = (x or 1, y or 1, z or 1)
!
! def random(self):
! """Get the next random number in the range [0.0, 1.0)."""
! # This part is thread-unsafe:
! # BEGIN CRITICAL SECTION
! x, y, z = self._seed
! #
! x = (171 * x) % 30269
! y = (172 * y) % 30307
! z = (170 * z) % 30323
! #
! self._seed = x, y, z
! # END CRITICAL SECTION
! #
! return (x/30269.0 + y/30307.0 + z/30323.0) % 1.0
!
! def uniform(self, a, b):
! """Get a random number in the range [a, b)."""
! return a + (b-a) * self.random()
!
! def randint(self, a, b):
! """Get a random integer in the range [a, b] including
! both end points.
!
! (Deprecated; use randrange below.)"""
! return self.randrange(a, b+1)
!
! def choice(self, seq):
! """Choose a random element from a non-empty sequence."""
! return seq[int(self.random() * len(seq))]
!
! def randrange(self, start, stop=None, step=1, int=int, default=None):
! """Choose a random item from range(start, stop[, step]).
!
! This fixes the problem with randint() which includes the
! endpoint; in Python this is usually not what you want.
! Do not supply the 'int' and 'default' arguments."""
! # This code is a bit messy to make it fast for the
! # common case while still doing adequate error checking
! istart = int(start)
! if istart != start:
! raise ValueError, "non-integer arg 1 for randrange()"
! if stop is default:
! if istart > 0:
! return int(self.random() * istart)
! raise ValueError, "empty range for randrange()"
! istop = int(stop)
! if istop != stop:
! raise ValueError, "non-integer stop for randrange()"
! if step == 1:
! if istart < istop:
! return istart + int(self.random() *
! (istop - istart))
! raise ValueError, "empty range for randrange()"
! istep = int(step)
! if istep != step:
! raise ValueError, "non-integer step for randrange()"
! if istep > 0:
! n = (istop - istart + istep - 1) / istep
! elif istep < 0:
! n = (istop - istart + istep + 1) / istep
! else:
! raise ValueError, "zero step for randrange()"
!
! if n <= 0:
! raise ValueError, "empty range for randrange()"
! return istart + istep*int(self.random() * n)
Index: xdrlib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xdrlib.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** xdrlib.py 2000/12/12 23:20:45 1.10
--- xdrlib.py 2001/01/15 03:34:38 1.11
***************
*** 30,34 ****
!
class Packer:
"""Pack various data representations into a buffer."""
--- 30,34 ----
!
class Packer:
"""Pack various data representations into a buffer."""
***************
*** 106,111 ****
self.pack_farray(n, list, pack_item)
-
class Unpacker:
"""Unpacks various data representations from the given buffer."""
--- 106,111 ----
self.pack_farray(n, list, pack_item)
+
class Unpacker:
"""Unpacks various data representations from the given buffer."""
***************
*** 221,225 ****
return self.unpack_farray(n, unpack_item)
!
# test suite
def _test():
--- 221,225 ----
return self.unpack_farray(n, unpack_item)
!
# test suite
def _test():
***************
*** 274,279 ****
print 'ConversionError:', var.msg
count = count + 1
-
if __name__ == '__main__':
_test()
--- 274,279 ----
print 'ConversionError:', var.msg
count = count + 1
+
if __name__ == '__main__':
_test()
Index: xmllib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xmllib.py,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -r1.25 -r1.26
*** xmllib.py 2000/12/12 23:20:45 1.25
--- xmllib.py 2001/01/15 03:34:38 1.26
***************
*** 251,257 ****
res = interesting.search(rawdata, i)
if res:
! j = res.start(0)
else:
! j = n
if i < j:
data = rawdata[i:j]
--- 251,257 ----
res = interesting.search(rawdata, i)
if res:
! j = res.start(0)
else:
! j = n
if i < j:
data = rawdata[i:j]
Index: zipfile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/zipfile.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** zipfile.py 2000/10/02 21:14:52 1.4
--- zipfile.py 2001/01/15 03:34:38 1.5
***************
*** 7,11 ****
try:
! import zlib # We may need its compression method
except:
zlib = None
--- 7,11 ----
try:
! import zlib # We may need its compression method
except:
zlib = None
***************
*** 13,17 ****
class BadZipfile(Exception):
pass
! error = BadZipfile # The exception raised by this module
# constants for Zip file compression methods
--- 13,17 ----
class BadZipfile(Exception):
pass
! error = BadZipfile # The exception raised by this module
# constants for Zip file compression methods
***************
*** 36,44 ****
try:
fpin = open(filename, "rb")
! fpin.seek(-22, 2) # Seek to end-of-file record
endrec = fpin.read()
fpin.close()
if endrec[0:4] == "PK\005\006" and endrec[-2:] == "\000\000":
! return 1 # file has correct magic number
except:
pass
--- 36,44 ----
try:
fpin = open(filename, "rb")
! fpin.seek(-22, 2) # Seek to end-of-file record
endrec = fpin.read()
fpin.close()
if endrec[0:4] == "PK\005\006" and endrec[-2:] == "\000\000":
! return 1 # file has correct magic number
except:
pass
***************
*** 49,72 ****
def __init__(self, filename="NoName", date_time=(1980,1,1,0,0,0)):
! self.filename = filename # Name of the file in the archive
! self.date_time = date_time # year, month, day, hour, min, sec
# Standard values:
! self.compress_type = ZIP_STORED # Type of compression for the file
! self.comment = "" # Comment for each file
! self.extra = "" # ZIP extra data
! self.create_system = 0 # System which created ZIP archive
! self.create_version = 20 # Version which created ZIP archive
! self.extract_version = 20 # Version needed to extract archive
! self.reserved = 0 # Must be zero
! self.flag_bits = 0 # ZIP flag bits
! self.volume = 0 # Volume number of file header
! self.internal_attr = 0 # Internal attributes
! self.external_attr = 0 # External file attributes
# Other attributes are set by class ZipFile:
! # header_offset Byte offset to the file header
! # file_offset Byte offset to the start of the file data
! # CRC CRC-32 of the uncompressed file
! # compress_size Size of the compressed file
! # file_size Size of the uncompressed file
def FileHeader(self):
--- 49,72 ----
def __init__(self, filename="NoName", date_time=(1980,1,1,0,0,0)):
! self.filename = filename # Name of the file in the archive
! self.date_time = date_time # year, month, day, hour, min, sec
# Standard values:
! self.compress_type = ZIP_STORED # Type of compression for the file
! self.comment = "" # Comment for each file
! self.extra = "" # ZIP extra data
! self.create_system = 0 # System which created ZIP archive
! self.create_version = 20 # Version which created ZIP archive
! self.extract_version = 20 # Version needed to extract archive
! self.reserved = 0 # Must be zero
! self.flag_bits = 0 # ZIP flag bits
! self.volume = 0 # Volume number of file header
! self.internal_attr = 0 # Internal attributes
! self.external_attr = 0 # External file attributes
# Other attributes are set by class ZipFile:
! # header_offset Byte offset to the file header
! # file_offset Byte offset to the start of the file data
! # CRC CRC-32 of the uncompressed file
! # compress_size Size of the compressed file
! # file_size Size of the uncompressed file
def FileHeader(self):
***************
*** 76,85 ****
dostime = dt[3] << 11 | dt[4] << 5 | dt[5] / 2
if self.flag_bits & 0x08:
! # Set these to zero because we write them after the file data
! CRC = compress_size = file_size = 0
else:
! CRC = self.CRC
! compress_size = self.compress_size
! file_size = self.file_size
header = struct.pack(structFileHeader, stringFileHeader,
self.extract_version, self.reserved, self.flag_bits,
--- 76,85 ----
dostime = dt[3] << 11 | dt[4] << 5 | dt[5] / 2
if self.flag_bits & 0x08:
! # Set these to zero because we write them after the file data
! CRC = compress_size = file_size = 0
else:
! CRC = self.CRC
! compress_size = self.compress_size
! file_size = self.file_size
header = struct.pack(structFileHeader, stringFileHeader,
self.extract_version, self.reserved, self.flag_bits,
***************
*** 103,110 ****
else:
raise RuntimeError, "That compression method is not supported"
! self.debug = 0 # Level of printing: 0 through 3
! self.NameToInfo = {} # Find file info given name
! self.filelist = [] # List of ZipInfo instances for archive
! self.compression = compression # Method of compression
self.filename = filename
self.mode = key = mode[0]
--- 103,110 ----
else:
raise RuntimeError, "That compression method is not supported"
! self.debug = 0 # Level of printing: 0 through 3
! self.NameToInfo = {} # Find file info given name
! self.filelist = [] # List of ZipInfo instances for archive
! self.compression = compression # Method of compression
self.filename = filename
self.mode = key = mode[0]
***************
*** 116,127 ****
elif key == 'a':
fp = self.fp = open(filename, "r+b")
! fp.seek(-22, 2) # Seek to end-of-file record
endrec = fp.read()
if endrec[0:4] == stringEndArchive and \
endrec[-2:] == "\000\000":
! self._GetContents() # file is a zip file
# seek to start of directory and overwrite
fp.seek(self.start_dir, 0)
! else: # file is not a zip file, just append
fp.seek(0, 2)
else:
--- 116,127 ----
elif key == 'a':
fp = self.fp = open(filename, "r+b")
! fp.seek(-22, 2) # Seek to end-of-file record
endrec = fp.read()
if endrec[0:4] == stringEndArchive and \
endrec[-2:] == "\000\000":
! self._GetContents() # file is a zip file
# seek to start of directory and overwrite
fp.seek(self.start_dir, 0)
! else: # file is not a zip file, just append
fp.seek(0, 2)
else:
***************
*** 131,137 ****
"""Read in the table of contents for the ZIP file."""
fp = self.fp
! fp.seek(-22, 2) # Start of end-of-archive record
! filesize = fp.tell() + 22 # Get file size
! endrec = fp.read(22) # Archive must not end with a comment!
if endrec[0:4] != stringEndArchive or endrec[-2:] != "\000\000":
raise BadZipfile, "File is not a zip file, or ends with a comment"
--- 131,137 ----
"""Read in the table of contents for the ZIP file."""
fp = self.fp
! fp.seek(-22, 2) # Start of end-of-archive record
! filesize = fp.tell() + 22 # Get file size
! endrec = fp.read(22) # Archive must not end with a comment!
if endrec[0:4] != stringEndArchive or endrec[-2:] != "\000\000":
raise BadZipfile, "File is not a zip file, or ends with a comment"
***************
*** 139,144 ****
if self.debug > 1:
print endrec
! size_cd = endrec[5] # bytes in central directory
! offset_cd = endrec[6] # offset of central directory
x = filesize - 22 - size_cd
# "concat" is zero, unless zip was concatenated to another file
--- 139,144 ----
if self.debug > 1:
print endrec
! size_cd = endrec[5] # bytes in central directory
! offset_cd = endrec[6] # offset of central directory
x = filesize - 22 - size_cd
# "concat" is zero, unless zip was concatenated to another file
***************
*** 212,216 ****
for zinfo in self.filelist:
try:
! self.read(zinfo.filename) # Check CRC-32
except:
return zinfo.filename
--- 212,216 ----
for zinfo in self.filelist:
try:
! self.read(zinfo.filename) # Check CRC-32
except:
return zinfo.filename
***************
*** 257,261 ****
"""Check for errors before writing a file to the archive."""
if self.NameToInfo.has_key(zinfo.filename):
! if self.debug: # Warning for duplicate names
print "Duplicate name:", zinfo.filename
if self.mode not in ("w", "a"):
--- 257,261 ----
"""Check for errors before writing a file to the archive."""
if self.NameToInfo.has_key(zinfo.filename):
! if self.debug: # Warning for duplicate names
print "Duplicate name:", zinfo.filename
if self.mode not in ("w", "a"):
***************
*** 279,296 ****
# Create ZipInfo instance to store file information
if arcname is None:
! zinfo = ZipInfo(filename, date_time)
else:
! zinfo = ZipInfo(arcname, date_time)
! zinfo.external_attr = st[0] << 16 # Unix attributes
if compress_type is None:
! zinfo.compress_type = self.compression
else:
! zinfo.compress_type = compress_type
self._writecheck(zinfo)
fp = open(filename, "rb")
zinfo.flag_bits = 0x08
! zinfo.header_offset = self.fp.tell() # Start of header bytes
self.fp.write(zinfo.FileHeader())
! zinfo.file_offset = self.fp.tell() # Start of file bytes
CRC = 0
compress_size = 0
--- 279,296 ----
# Create ZipInfo instance to store file information
if arcname is None:
! zinfo = ZipInfo(filename, date_time)
else:
! zinfo = ZipInfo(arcname, date_time)
! zinfo.external_attr = st[0] << 16 # Unix attributes
if compress_type is None:
! zinfo.compress_type = self.compression
else:
! zinfo.compress_type = compress_type
self._writecheck(zinfo)
fp = open(filename, "rb")
zinfo.flag_bits = 0x08
! zinfo.header_offset = self.fp.tell() # Start of header bytes
self.fp.write(zinfo.FileHeader())
! zinfo.file_offset = self.fp.tell() # Start of file bytes
CRC = 0
compress_size = 0
***************
*** 331,351 ****
'bytes'."""
self._writecheck(zinfo)
! zinfo.file_size = len(bytes) # Uncompressed size
! zinfo.CRC = binascii.crc32(bytes) # CRC-32 checksum
if zinfo.compress_type == ZIP_DEFLATED:
co = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION,
zlib.DEFLATED, -15)
bytes = co.compress(bytes) + co.flush()
! zinfo.compress_size = len(bytes) # Compressed size
else:
zinfo.compress_size = zinfo.file_size
! zinfo.header_offset = self.fp.tell() # Start of header bytes
self.fp.write(zinfo.FileHeader())
! zinfo.file_offset = self.fp.tell() # Start of file bytes
self.fp.write(bytes)
if zinfo.flag_bits & 0x08:
! # Write CRC and file sizes after the file data
! self.fp.write(struct.pack("<lll", zinfo.CRC, zinfo.compress_size,
! zinfo.file_size))
self.filelist.append(zinfo)
self.NameToInfo[zinfo.filename] = zinfo
--- 331,351 ----
'bytes'."""
self._writecheck(zinfo)
! zinfo.file_size = len(bytes) # Uncompressed size
! zinfo.CRC = binascii.crc32(bytes) # CRC-32 checksum
if zinfo.compress_type == ZIP_DEFLATED:
co = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION,
zlib.DEFLATED, -15)
bytes = co.compress(bytes) + co.flush()
! zinfo.compress_size = len(bytes) # Compressed size
else:
zinfo.compress_size = zinfo.file_size
! zinfo.header_offset = self.fp.tell() # Start of header bytes
self.fp.write(zinfo.FileHeader())
! zinfo.file_offset = self.fp.tell() # Start of file bytes
self.fp.write(bytes)
if zinfo.flag_bits & 0x08:
! # Write CRC and file sizes after the file data
! self.fp.write(struct.pack("<lll", zinfo.CRC, zinfo.compress_size,
! zinfo.file_size))
self.filelist.append(zinfo)
self.NameToInfo[zinfo.filename] = zinfo
***************
*** 360,367 ****
"""Close the file, and for mode "w" and "a" write the ending
records."""
! if self.mode in ("w", "a"): # write ending records
count = 0
pos1 = self.fp.tell()
! for zinfo in self.filelist: # write central directory
count = count + 1
dt = zinfo.date_time
--- 360,367 ----
"""Close the file, and for mode "w" and "a" write the ending
records."""
! if self.mode in ("w", "a"): # write ending records
count = 0
pos1 = self.fp.tell()
! for zinfo in self.filelist: # write central directory
count = count + 1
dt = zinfo.date_time
***************
*** 469,473 ****
if os.path.isfile(file_pyo) and \
os.stat(file_pyo)[8] >= os.stat(file_py)[8]:
! fname = file_pyo # Use .pyo file
elif not os.path.isfile(file_pyc) or \
os.stat(file_pyc)[8] < os.stat(file_py)[8]:
--- 469,473 ----
if os.path.isfile(file_pyo) and \
os.stat(file_pyo)[8] >= os.stat(file_py)[8]:
! fname = file_pyo # Use .pyo file
elif not os.path.isfile(file_pyc) or \
os.stat(file_pyc)[8] < os.stat(file_py)[8]:
- Previous 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
- Next message: [Python-checkins] CVS: python/dist/src/Misc NEWS,1.94,1.95
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]