Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e119006e
Commit
e119006e
authored
Jan 15, 2001
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Whitespace normalization. Top level of Lib now fixed-point for reindent.py!
parent
b90f89a4
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
432 additions
and
432 deletions
+432
-432
Lib/UserString.py
Lib/UserString.py
+14
-14
Lib/urllib.py
Lib/urllib.py
+13
-13
Lib/urllib2.py
Lib/urllib2.py
+30
-30
Lib/urlparse.py
Lib/urlparse.py
+185
-185
Lib/uu.py
Lib/uu.py
+5
-5
Lib/warnings.py
Lib/warnings.py
+23
-23
Lib/wave.py
Lib/wave.py
+1
-1
Lib/webbrowser.py
Lib/webbrowser.py
+1
-1
Lib/whrandom.py
Lib/whrandom.py
+95
-95
Lib/xdrlib.py
Lib/xdrlib.py
+4
-4
Lib/xmllib.py
Lib/xmllib.py
+2
-2
Lib/zipfile.py
Lib/zipfile.py
+59
-59
No files found.
Lib/UserString.py
View file @
e119006e
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
## vim:ts=4:et:nowrap
## vim:ts=4:et:nowrap
"""A user-defined wrapper around string objects
"""A user-defined wrapper around string objects
Note: string objects have grown methods in Python 1.6
Note: string objects have grown methods in Python 1.6
This module requires Python 1.6 or later.
This module requires Python 1.6 or later.
"""
"""
from
types
import
StringType
,
UnicodeType
from
types
import
StringType
,
UnicodeType
...
@@ -14,7 +14,7 @@ class UserString:
...
@@ -14,7 +14,7 @@ class UserString:
self
.
data
=
seq
self
.
data
=
seq
elif
isinstance
(
seq
,
UserString
):
elif
isinstance
(
seq
,
UserString
):
self
.
data
=
seq
.
data
[:]
self
.
data
=
seq
.
data
[:]
else
:
else
:
self
.
data
=
str
(
seq
)
self
.
data
=
str
(
seq
)
def
__str__
(
self
):
return
str
(
self
.
data
)
def
__str__
(
self
):
return
str
(
self
.
data
)
def
__repr__
(
self
):
return
repr
(
self
.
data
)
def
__repr__
(
self
):
return
repr
(
self
.
data
)
...
@@ -76,15 +76,15 @@ class UserString:
...
@@ -76,15 +76,15 @@ class UserString:
return
self
.
__class__
(
self
.
data
.
encode
(
encoding
,
errors
))
return
self
.
__class__
(
self
.
data
.
encode
(
encoding
,
errors
))
else
:
else
:
return
self
.
__class__
(
self
.
data
.
encode
(
encoding
))
return
self
.
__class__
(
self
.
data
.
encode
(
encoding
))
else
:
else
:
return
self
.
__class__
(
self
.
data
.
encode
())
return
self
.
__class__
(
self
.
data
.
encode
())
def
endswith
(
self
,
suffix
,
start
=
0
,
end
=
sys
.
maxint
):
def
endswith
(
self
,
suffix
,
start
=
0
,
end
=
sys
.
maxint
):
return
self
.
data
.
endswith
(
suffix
,
start
,
end
)
return
self
.
data
.
endswith
(
suffix
,
start
,
end
)
def
expandtabs
(
self
,
tabsize
=
8
):
def
expandtabs
(
self
,
tabsize
=
8
):
return
self
.
__class__
(
self
.
data
.
expandtabs
(
tabsize
))
return
self
.
__class__
(
self
.
data
.
expandtabs
(
tabsize
))
def
find
(
self
,
sub
,
start
=
0
,
end
=
sys
.
maxint
):
def
find
(
self
,
sub
,
start
=
0
,
end
=
sys
.
maxint
):
return
self
.
data
.
find
(
sub
,
start
,
end
)
return
self
.
data
.
find
(
sub
,
start
,
end
)
def
index
(
self
,
sub
,
start
=
0
,
end
=
sys
.
maxint
):
def
index
(
self
,
sub
,
start
=
0
,
end
=
sys
.
maxint
):
return
self
.
data
.
index
(
sub
,
start
,
end
)
return
self
.
data
.
index
(
sub
,
start
,
end
)
def
isalpha
(
self
):
return
self
.
data
.
isalpha
()
def
isalpha
(
self
):
return
self
.
data
.
isalpha
()
def
isalnum
(
self
):
return
self
.
data
.
isalnum
()
def
isalnum
(
self
):
return
self
.
data
.
isalnum
()
...
@@ -99,23 +99,23 @@ class UserString:
...
@@ -99,23 +99,23 @@ class UserString:
def
ljust
(
self
,
width
):
return
self
.
__class__
(
self
.
data
.
ljust
(
width
))
def
ljust
(
self
,
width
):
return
self
.
__class__
(
self
.
data
.
ljust
(
width
))
def
lower
(
self
):
return
self
.
__class__
(
self
.
data
.
lower
())
def
lower
(
self
):
return
self
.
__class__
(
self
.
data
.
lower
())
def
lstrip
(
self
):
return
self
.
__class__
(
self
.
data
.
lstrip
())
def
lstrip
(
self
):
return
self
.
__class__
(
self
.
data
.
lstrip
())
def
replace
(
self
,
old
,
new
,
maxsplit
=-
1
):
def
replace
(
self
,
old
,
new
,
maxsplit
=-
1
):
return
self
.
__class__
(
self
.
data
.
replace
(
old
,
new
,
maxsplit
))
return
self
.
__class__
(
self
.
data
.
replace
(
old
,
new
,
maxsplit
))
def
rfind
(
self
,
sub
,
start
=
0
,
end
=
sys
.
maxint
):
def
rfind
(
self
,
sub
,
start
=
0
,
end
=
sys
.
maxint
):
return
self
.
data
.
rfind
(
sub
,
start
,
end
)
return
self
.
data
.
rfind
(
sub
,
start
,
end
)
def
rindex
(
self
,
sub
,
start
=
0
,
end
=
sys
.
maxint
):
def
rindex
(
self
,
sub
,
start
=
0
,
end
=
sys
.
maxint
):
return
self
.
data
.
rindex
(
sub
,
start
,
end
)
return
self
.
data
.
rindex
(
sub
,
start
,
end
)
def
rjust
(
self
,
width
):
return
self
.
__class__
(
self
.
data
.
rjust
(
width
))
def
rjust
(
self
,
width
):
return
self
.
__class__
(
self
.
data
.
rjust
(
width
))
def
rstrip
(
self
):
return
self
.
__class__
(
self
.
data
.
rstrip
())
def
rstrip
(
self
):
return
self
.
__class__
(
self
.
data
.
rstrip
())
def
split
(
self
,
sep
=
None
,
maxsplit
=-
1
):
def
split
(
self
,
sep
=
None
,
maxsplit
=-
1
):
return
self
.
data
.
split
(
sep
,
maxsplit
)
return
self
.
data
.
split
(
sep
,
maxsplit
)
def
splitlines
(
self
,
keepends
=
0
):
return
self
.
data
.
splitlines
(
keepends
)
def
splitlines
(
self
,
keepends
=
0
):
return
self
.
data
.
splitlines
(
keepends
)
def
startswith
(
self
,
prefix
,
start
=
0
,
end
=
sys
.
maxint
):
def
startswith
(
self
,
prefix
,
start
=
0
,
end
=
sys
.
maxint
):
return
self
.
data
.
startswith
(
prefix
,
start
,
end
)
return
self
.
data
.
startswith
(
prefix
,
start
,
end
)
def
strip
(
self
):
return
self
.
__class__
(
self
.
data
.
strip
())
def
strip
(
self
):
return
self
.
__class__
(
self
.
data
.
strip
())
def
swapcase
(
self
):
return
self
.
__class__
(
self
.
data
.
swapcase
())
def
swapcase
(
self
):
return
self
.
__class__
(
self
.
data
.
swapcase
())
def
title
(
self
):
return
self
.
__class__
(
self
.
data
.
title
())
def
title
(
self
):
return
self
.
__class__
(
self
.
data
.
title
())
def
translate
(
self
,
*
args
):
def
translate
(
self
,
*
args
):
return
self
.
__class__
(
self
.
data
.
translate
(
*
args
))
return
self
.
__class__
(
self
.
data
.
translate
(
*
args
))
def
upper
(
self
):
return
self
.
__class__
(
self
.
data
.
upper
())
def
upper
(
self
):
return
self
.
__class__
(
self
.
data
.
upper
())
...
@@ -136,7 +136,7 @@ class MutableString(UserString):
...
@@ -136,7 +136,7 @@ class MutableString(UserString):
A faster and better solution is to rewrite your program using lists."""
A faster and better solution is to rewrite your program using lists."""
def
__init__
(
self
,
string
=
""
):
def
__init__
(
self
,
string
=
""
):
self
.
data
=
string
self
.
data
=
string
def
__hash__
(
self
):
def
__hash__
(
self
):
raise
TypeError
,
"unhashable type (it is mutable)"
raise
TypeError
,
"unhashable type (it is mutable)"
def
__setitem__
(
self
,
index
,
sub
):
def
__setitem__
(
self
,
index
,
sub
):
if
index
<
0
or
index
>=
len
(
self
.
data
):
raise
IndexError
if
index
<
0
or
index
>=
len
(
self
.
data
):
raise
IndexError
...
@@ -157,7 +157,7 @@ class MutableString(UserString):
...
@@ -157,7 +157,7 @@ class MutableString(UserString):
self
.
data
=
self
.
data
[:
start
]
+
self
.
data
[
end
:]
self
.
data
=
self
.
data
[:
start
]
+
self
.
data
[
end
:]
def
immutable
(
self
):
def
immutable
(
self
):
return
UserString
(
self
.
data
)
return
UserString
(
self
.
data
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
# execute the regression test to stdout, if called as a script:
# execute the regression test to stdout, if called as a script:
import
os
import
os
...
...
Lib/urllib.py
View file @
e119006e
...
@@ -551,11 +551,11 @@ class FancyURLopener(URLopener):
...
@@ -551,11 +551,11 @@ class FancyURLopener(URLopener):
if
match
:
if
match
:
scheme
,
realm
=
match
.
groups
()
scheme
,
realm
=
match
.
groups
()
if
scheme
.
lower
()
==
'basic'
:
if
scheme
.
lower
()
==
'basic'
:
name
=
'retry_'
+
self
.
type
+
'_basic_auth'
name
=
'retry_'
+
self
.
type
+
'_basic_auth'
if
data
is
None
:
if
data
is
None
:
return
getattr
(
self
,
name
)(
url
,
realm
)
return
getattr
(
self
,
name
)(
url
,
realm
)
else
:
else
:
return
getattr
(
self
,
name
)(
url
,
realm
,
data
)
return
getattr
(
self
,
name
)(
url
,
realm
,
data
)
def
retry_http_basic_auth
(
self
,
url
,
realm
,
data
=
None
):
def
retry_http_basic_auth
(
self
,
url
,
realm
,
data
=
None
):
host
,
selector
=
splithost
(
url
)
host
,
selector
=
splithost
(
url
)
...
@@ -571,14 +571,14 @@ class FancyURLopener(URLopener):
...
@@ -571,14 +571,14 @@ class FancyURLopener(URLopener):
return
self
.
open
(
newurl
,
data
)
return
self
.
open
(
newurl
,
data
)
def
retry_https_basic_auth
(
self
,
url
,
realm
,
data
=
None
):
def
retry_https_basic_auth
(
self
,
url
,
realm
,
data
=
None
):
host
,
selector
=
splithost
(
url
)
host
,
selector
=
splithost
(
url
)
i
=
host
.
find
(
'@'
)
+
1
i
=
host
.
find
(
'@'
)
+
1
host
=
host
[
i
:]
host
=
host
[
i
:]
user
,
passwd
=
self
.
get_user_passwd
(
host
,
realm
,
i
)
user
,
passwd
=
self
.
get_user_passwd
(
host
,
realm
,
i
)
if
not
(
user
or
passwd
):
return
None
if
not
(
user
or
passwd
):
return
None
host
=
user
+
':'
+
passwd
+
'@'
+
host
host
=
user
+
':'
+
passwd
+
'@'
+
host
newurl
=
'//'
+
host
+
selector
newurl
=
'//'
+
host
+
selector
return
self
.
open_https
(
newurl
)
return
self
.
open_https
(
newurl
)
def
get_user_passwd
(
self
,
host
,
realm
,
clear_cache
=
0
):
def
get_user_passwd
(
self
,
host
,
realm
,
clear_cache
=
0
):
key
=
realm
+
'@'
+
host
.
lower
()
key
=
realm
+
'@'
+
host
.
lower
()
...
...
Lib/urllib2.py
View file @
e119006e
"""An extensible library for opening URLs using a variety of protocols
"""An extensible library for opening URLs using a variety of protocols
The simplest way to use this module is to call the urlopen function,
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
which accepts a string containing a URL or a Request object (described
below). It opens the URL and returns the results as file-like
below). It opens the URL and returns the results as file-like
object; the returned object has some extra methods described below.
object; the returned object has some extra methods described below.
The OpenerDirectory manages a collection of Handler objects that do
The OpenerDirectory manages a collection of Handler objects that do
all the actual work. Each Handler implements a particular protocol or
all the actual work. Each Handler implements a particular protocol or
option. The OpenerDirector is a composite object that invokes the
option. The OpenerDirector is a composite object that invokes the
Handlers needed to open the requested URL. For example, the
Handlers needed to open the requested URL. For example, the
HTTPHandler performs HTTP GET and POST requests and deals with
HTTPHandler performs HTTP GET and POST requests and deals with
...
@@ -16,7 +16,7 @@ with digest authentication.
...
@@ -16,7 +16,7 @@ with digest authentication.
urlopen(url, data=None) -- basic usage is that same as original
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
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
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
a Request instance instead of URL. Raises a URLError (subclass of
IOError); for HTTP errors, raises an HTTPError, which can also be
IOError); for HTTP errors, raises an HTTPError, which can also be
treated as a valid response.
treated as a valid response.
...
@@ -42,7 +42,7 @@ exceptions:
...
@@ -42,7 +42,7 @@ exceptions:
URLError-- a subclass of IOError, individual protocols have their own
URLError-- a subclass of IOError, individual protocols have their own
specific subclass
specific subclass
HTTPError-- also a valid HTTP response, so you can treat an HTTP error
HTTPError-- also a valid HTTP response, so you can treat an HTTP error
as an exceptional event or valid response
as an exceptional event or valid response
internals:
internals:
...
@@ -57,7 +57,7 @@ import urllib2
...
@@ -57,7 +57,7 @@ import urllib2
authinfo = urllib2.HTTPBasicAuthHandler()
authinfo = urllib2.HTTPBasicAuthHandler()
authinfo.add_password('realm', 'host', 'username', 'password')
authinfo.add_password('realm', 'host', 'username', 'password')
# build a new opener that adds authentication and caching FTP handlers
# build a new opener that adds authentication and caching FTP handlers
opener = urllib2.build_opener(authinfo, urllib2.CacheFTPHandler)
opener = urllib2.build_opener(authinfo, urllib2.CacheFTPHandler)
# install it
# install it
...
@@ -73,7 +73,7 @@ f = urllib2.urlopen('http://www.python.org/')
...
@@ -73,7 +73,7 @@ f = urllib2.urlopen('http://www.python.org/')
# authentication for some reason but fails, how should the error be
# authentication for some reason but fails, how should the error be
# signalled? The client needs to know the HTTP error code. But if
# 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
# 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
# that hash algo that requested in the challenge, it would be good to
# pass that information along to the client, too.
# pass that information along to the client, too.
# XXX to do:
# XXX to do:
...
@@ -141,7 +141,7 @@ def install_opener(opener):
...
@@ -141,7 +141,7 @@ def install_opener(opener):
_opener
=
opener
_opener
=
opener
# do these error classes make sense?
# do these error classes make sense?
# make sure all of the IOError stuff is overridden. we just want to be
# make sure all of the IOError stuff is overridden. we just want to be
# subtypes.
# subtypes.
class
URLError
(
IOError
):
class
URLError
(
IOError
):
...
@@ -165,7 +165,7 @@ class HTTPError(URLError, addinfourl):
...
@@ -165,7 +165,7 @@ class HTTPError(URLError, addinfourl):
self
.
fp
=
fp
self
.
fp
=
fp
# XXX
# XXX
self
.
filename
=
url
self
.
filename
=
url
def
__str__
(
self
):
def
__str__
(
self
):
return
'HTTP Error %s: %s'
%
(
self
.
code
,
self
.
msg
)
return
'HTTP Error %s: %s'
%
(
self
.
code
,
self
.
msg
)
...
@@ -192,7 +192,7 @@ class Request:
...
@@ -192,7 +192,7 @@ class Request:
def
__getattr__
(
self
,
attr
):
def
__getattr__
(
self
,
attr
):
# XXX this is a fallback mechanism to guard against these
# XXX this is a fallback mechanism to guard against these
# methods getting called in a non-standard order. this may be
# methods getting called in a non-standard order. this may be
# too complicated and/or unnecessary.
# too complicated and/or unnecessary.
# XXX should the __r_XXX attributes be public?
# XXX should the __r_XXX attributes be public?
if
attr
[:
12
]
==
'_Request__r_'
:
if
attr
[:
12
]
==
'_Request__r_'
:
...
@@ -259,7 +259,7 @@ class OpenerDirector:
...
@@ -259,7 +259,7 @@ class OpenerDirector:
for
meth
in
get_methods
(
handler
):
for
meth
in
get_methods
(
handler
):
if
meth
[
-
5
:]
==
'_open'
:
if
meth
[
-
5
:]
==
'_open'
:
protocol
=
meth
[:
-
5
]
protocol
=
meth
[:
-
5
]
if
self
.
handle_open
.
has_key
(
protocol
):
if
self
.
handle_open
.
has_key
(
protocol
):
self
.
handle_open
[
protocol
].
append
(
handler
)
self
.
handle_open
[
protocol
].
append
(
handler
)
else
:
else
:
self
.
handle_open
[
protocol
]
=
[
handler
]
self
.
handle_open
[
protocol
]
=
[
handler
]
...
@@ -285,7 +285,7 @@ class OpenerDirector:
...
@@ -285,7 +285,7 @@ class OpenerDirector:
if
added
:
if
added
:
self
.
handlers
.
append
(
handler
)
self
.
handlers
.
append
(
handler
)
handler
.
add_parent
(
self
)
handler
.
add_parent
(
self
)
def
__del__
(
self
):
def
__del__
(
self
):
self
.
close
()
self
.
close
()
...
@@ -314,9 +314,9 @@ class OpenerDirector:
...
@@ -314,9 +314,9 @@ class OpenerDirector:
if
data
is
not
None
:
if
data
is
not
None
:
req
.
add_data
(
data
)
req
.
add_data
(
data
)
assert
isinstance
(
req
,
Request
)
# really only care about interface
assert
isinstance
(
req
,
Request
)
# really only care about interface
result
=
self
.
_call_chain
(
self
.
handle_open
,
'default'
,
result
=
self
.
_call_chain
(
self
.
handle_open
,
'default'
,
'default_open'
,
req
)
'default_open'
,
req
)
if
result
:
if
result
:
return
result
return
result
...
@@ -381,7 +381,7 @@ def get_methods(inst):
...
@@ -381,7 +381,7 @@ def get_methods(inst):
# XXX probably also want an abstract factory that knows things like
# XXX probably also want an abstract factory that knows things like
# the fact that a ProxyHandler needs to get inserted first.
# the fact that a ProxyHandler needs to get inserted first.
# would also know when it makes sense to skip a superclass in favor of
# 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
# a subclass and when it might make sense to include both
def
build_opener
(
*
handlers
):
def
build_opener
(
*
handlers
):
"""Create an opener object from a list of handlers.
"""Create an opener object from a list of handlers.
...
@@ -393,7 +393,7 @@ def build_opener(*handlers):
...
@@ -393,7 +393,7 @@ def build_opener(*handlers):
If any of the handlers passed as arguments are subclasses of the
If any of the handlers passed as arguments are subclasses of the
default handlers, the default handlers will not be used.
default handlers, the default handlers will not be used.
"""
"""
opener
=
OpenerDirector
()
opener
=
OpenerDirector
()
default_classes
=
[
ProxyHandler
,
UnknownHandler
,
HTTPHandler
,
default_classes
=
[
ProxyHandler
,
UnknownHandler
,
HTTPHandler
,
HTTPDefaultErrorHandler
,
HTTPRedirectHandler
,
HTTPDefaultErrorHandler
,
HTTPRedirectHandler
,
...
@@ -472,7 +472,7 @@ class ProxyHandler(BaseHandler):
...
@@ -472,7 +472,7 @@ class ProxyHandler(BaseHandler):
assert
hasattr
(
proxies
,
'has_key'
),
"proxies must be a mapping"
assert
hasattr
(
proxies
,
'has_key'
),
"proxies must be a mapping"
self
.
proxies
=
proxies
self
.
proxies
=
proxies
for
type
,
url
in
proxies
.
items
():
for
type
,
url
in
proxies
.
items
():
setattr
(
self
,
'%s_open'
%
type
,
setattr
(
self
,
'%s_open'
%
type
,
lambda
r
,
proxy
=
url
,
type
=
type
,
meth
=
self
.
proxy_open
:
\
lambda
r
,
proxy
=
url
,
type
=
type
,
meth
=
self
.
proxy_open
:
\
meth
(
r
,
proxy
,
type
))
meth
(
r
,
proxy
,
type
))
...
@@ -574,7 +574,7 @@ class HTTPPasswordMgr:
...
@@ -574,7 +574,7 @@ class HTTPPasswordMgr:
if
len
(
common
)
==
len
(
base
[
1
]):
if
len
(
common
)
==
len
(
base
[
1
]):
return
1
return
1
return
0
return
0
class
HTTPBasicAuthHandler
(
BaseHandler
):
class
HTTPBasicAuthHandler
(
BaseHandler
):
rx
=
re
.
compile
(
'[
\
t
]*([^
\
t
]+)[
\
t
]+realm="([^"]*)"'
)
rx
=
re
.
compile
(
'[
\
t
]*([^
\
t
]+)[
\
t
]+realm="([^"]*)"'
)
...
@@ -590,8 +590,8 @@ class HTTPBasicAuthHandler(BaseHandler):
...
@@ -590,8 +590,8 @@ class HTTPBasicAuthHandler(BaseHandler):
# if __current_realm is not None, then the server must have
# if __current_realm is not None, then the server must have
# refused our name/password and is asking for authorization
# refused our name/password and is asking for authorization
# again. must be careful to set it to None on successful
# again. must be careful to set it to None on successful
# return.
# return.
def
http_error_401
(
self
,
req
,
fp
,
code
,
msg
,
headers
):
def
http_error_401
(
self
,
req
,
fp
,
code
,
msg
,
headers
):
# XXX could be mult. headers
# XXX could be mult. headers
authreq
=
headers
.
get
(
'www-authenticate'
,
None
)
authreq
=
headers
.
get
(
'www-authenticate'
,
None
)
...
@@ -674,7 +674,7 @@ class HTTPDigestAuthHandler(BaseHandler):
...
@@ -674,7 +674,7 @@ class HTTPDigestAuthHandler(BaseHandler):
return
None
return
None
user
,
pw
=
self
.
passwd
.
find_user_password
(
realm
,
user
,
pw
=
self
.
passwd
.
find_user_password
(
realm
,
req
.
get_full_url
())
req
.
get_full_url
())
if
user
is
None
:
if
user
is
None
:
return
None
return
None
...
@@ -724,8 +724,8 @@ def encode_digest(digest):
...
@@ -724,8 +724,8 @@ def encode_digest(digest):
n
=
ord
(
c
)
&
0xf
n
=
ord
(
c
)
&
0xf
hexrep
.
append
(
hex
(
n
)[
-
1
])
hexrep
.
append
(
hex
(
n
)[
-
1
])
return
string
.
join
(
hexrep
,
''
)
return
string
.
join
(
hexrep
,
''
)
class
HTTPHandler
(
BaseHandler
):
class
HTTPHandler
(
BaseHandler
):
def
http_open
(
self
,
req
):
def
http_open
(
self
,
req
):
# XXX devise a new mechanism to specify user/password
# XXX devise a new mechanism to specify user/password
...
@@ -745,7 +745,7 @@ class HTTPHandler(BaseHandler):
...
@@ -745,7 +745,7 @@ class HTTPHandler(BaseHandler):
h
.
putrequest
(
'GET'
,
req
.
get_selector
())
h
.
putrequest
(
'GET'
,
req
.
get_selector
())
except
socket
.
error
,
err
:
except
socket
.
error
,
err
:
raise
URLError
(
err
)
raise
URLError
(
err
)
# XXX proxies would have different host here
# XXX proxies would have different host here
h
.
putheader
(
'Host'
,
host
)
h
.
putheader
(
'Host'
,
host
)
for
args
in
self
.
parent
.
addheaders
:
for
args
in
self
.
parent
.
addheaders
:
...
@@ -813,7 +813,7 @@ def parse_http_list(s):
...
@@ -813,7 +813,7 @@ def parse_http_list(s):
start
=
i
start
=
i
inquote
=
0
inquote
=
0
else
:
else
:
i
=
i
+
q
i
=
i
+
q
else
:
else
:
if
c
<
q
:
if
c
<
q
:
list
.
append
(
s
[
start
:
i
+
c
])
list
.
append
(
s
[
start
:
i
+
c
])
...
@@ -838,7 +838,7 @@ class FileHandler(BaseHandler):
...
@@ -838,7 +838,7 @@ class FileHandler(BaseHandler):
names
=
None
names
=
None
def
get_names
(
self
):
def
get_names
(
self
):
if
FileHandler
.
names
is
None
:
if
FileHandler
.
names
is
None
:
FileHandler
.
names
=
(
socket
.
gethostbyname
(
'localhost'
),
FileHandler
.
names
=
(
socket
.
gethostbyname
(
'localhost'
),
socket
.
gethostbyname
(
socket
.
gethostname
()))
socket
.
gethostbyname
(
socket
.
gethostname
()))
return
FileHandler
.
names
return
FileHandler
.
names
...
@@ -967,7 +967,7 @@ class GopherHandler(BaseHandler):
...
@@ -967,7 +967,7 @@ class GopherHandler(BaseHandler):
class
OpenerFactory
:
class
OpenerFactory
:
default_handlers
=
[
UnknownHandler
,
HTTPHandler
,
default_handlers
=
[
UnknownHandler
,
HTTPHandler
,
HTTPDefaultErrorHandler
,
HTTPRedirectHandler
,
HTTPDefaultErrorHandler
,
HTTPRedirectHandler
,
FTPHandler
,
FileHandler
]
FTPHandler
,
FileHandler
]
proxy_handlers
=
[
ProxyHandler
]
proxy_handlers
=
[
ProxyHandler
]
handlers
=
[]
handlers
=
[]
...
@@ -990,7 +990,7 @@ class OpenerFactory:
...
@@ -990,7 +990,7 @@ class OpenerFactory:
opener
.
add_handler
(
ph
)
opener
.
add_handler
(
ph
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
# XXX some of the test code depends on machine configurations that
# XXX some of the test code depends on machine configurations that
# are internal to CNRI. Need to set up a public server with the
# are internal to CNRI. Need to set up a public server with the
# right authentication configuration for test purposes.
# right authentication configuration for test purposes.
if
socket
.
gethostname
()
==
'bitdiddle'
:
if
socket
.
gethostname
()
==
'bitdiddle'
:
...
@@ -1030,11 +1030,11 @@ if __name__ == "__main__":
...
@@ -1030,11 +1030,11 @@ if __name__ == "__main__":
bauth
=
HTTPBasicAuthHandler
()
bauth
=
HTTPBasicAuthHandler
()
bauth
.
add_password
(
'basic_test_realm'
,
localhost
,
'jhylton'
,
bauth
.
add_password
(
'basic_test_realm'
,
localhost
,
'jhylton'
,
'password'
)
'password'
)
dauth
=
HTTPDigestAuthHandler
()
dauth
=
HTTPDigestAuthHandler
()
dauth
.
add_password
(
'digest_test_realm'
,
localhost
,
'jhylton'
,
dauth
.
add_password
(
'digest_test_realm'
,
localhost
,
'jhylton'
,
'password'
)
'password'
)
cfh
=
CacheFTPHandler
()
cfh
=
CacheFTPHandler
()
cfh
.
setTimeout
(
1
)
cfh
.
setTimeout
(
1
)
...
...
Lib/urlparse.py
View file @
e119006e
This diff is collapsed.
Click to expand it.
Lib/uu.py
View file @
e119006e
...
@@ -3,12 +3,12 @@
...
@@ -3,12 +3,12 @@
# Copyright 1994 by Lance Ellinghouse
# Copyright 1994 by Lance Ellinghouse
# Cathedral City, California Republic, United States of America.
# Cathedral City, California Republic, United States of America.
# All Rights Reserved
# All Rights Reserved
# Permission to use, copy, modify, and distribute this software and its
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of Lance Ellinghouse
# supporting documentation, and that the name of Lance Ellinghouse
# not be used in advertising or publicity pertaining to distribution
# not be used in advertising or publicity pertaining to distribution
# of the software without specific, written prior permission.
# of the software without specific, written prior permission.
# LANCE ELLINGHOUSE DISCLAIMS ALL WARRANTIES WITH REGARD TO
# LANCE ELLINGHOUSE DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
...
@@ -154,7 +154,7 @@ def test():
...
@@ -154,7 +154,7 @@ def test():
print
' -d: Decode (in stead of encode)'
print
' -d: Decode (in stead of encode)'
print
' -t: data is text, encoded format unix-compatible text'
print
' -t: data is text, encoded format unix-compatible text'
sys
.
exit
(
1
)
sys
.
exit
(
1
)
for
o
,
a
in
optlist
:
for
o
,
a
in
optlist
:
if
o
==
'-d'
:
dopt
=
1
if
o
==
'-d'
:
dopt
=
1
if
o
==
'-t'
:
topt
=
1
if
o
==
'-t'
:
topt
=
1
...
...
Lib/warnings.py
View file @
e119006e
...
@@ -131,29 +131,29 @@ def _processoptions(args):
...
@@ -131,29 +131,29 @@ def _processoptions(args):
# Helper for _processoptions()
# Helper for _processoptions()
def
_setoption
(
arg
):
def
_setoption
(
arg
):
parts
=
arg
.
split
(
':'
)
parts
=
arg
.
split
(
':'
)
if
len
(
parts
)
>
5
:
if
len
(
parts
)
>
5
:
raise
_OptionError
(
"too many fields (max 5): %s"
%
`arg`
)
raise
_OptionError
(
"too many fields (max 5): %s"
%
`arg`
)
while
len
(
parts
)
<
5
:
while
len
(
parts
)
<
5
:
parts
.
append
(
''
)
parts
.
append
(
''
)
action
,
message
,
category
,
module
,
lineno
=
[
s
.
strip
()
action
,
message
,
category
,
module
,
lineno
=
[
s
.
strip
()
for
s
in
parts
]
for
s
in
parts
]
action
=
_getaction
(
action
)
action
=
_getaction
(
action
)
message
=
re
.
escape
(
message
)
message
=
re
.
escape
(
message
)
category
=
_getcategory
(
category
)
category
=
_getcategory
(
category
)
module
=
re
.
escape
(
module
)
module
=
re
.
escape
(
module
)
if
module
:
if
module
:
module
=
module
+
'$'
module
=
module
+
'$'
if
lineno
:
if
lineno
:
try
:
try
:
lineno
=
int
(
lineno
)
lineno
=
int
(
lineno
)
if
lineno
<
0
:
if
lineno
<
0
:
raise
ValueError
raise
ValueError
except
(
ValueError
,
OverflowError
):
except
(
ValueError
,
OverflowError
):
raise
_OptionError
(
"invalid lineno %s"
%
`lineno`
)
raise
_OptionError
(
"invalid lineno %s"
%
`lineno`
)
else
:
else
:
lineno
=
0
lineno
=
0
filterwarnings
(
action
,
message
,
category
,
module
,
lineno
)
filterwarnings
(
action
,
message
,
category
,
module
,
lineno
)
# Helper for _setoption()
# Helper for _setoption()
def
_getaction
(
action
):
def
_getaction
(
action
):
...
...
Lib/wave.py
View file @
e119006e
...
@@ -395,7 +395,7 @@ class Wave_write:
...
@@ -395,7 +395,7 @@ class Wave_write:
def
getmarkers
(
self
):
def
getmarkers
(
self
):
return
None
return
None
def
tell
(
self
):
def
tell
(
self
):
return
self
.
_nframeswritten
return
self
.
_nframeswritten
...
...
Lib/webbrowser.py
View file @
e119006e
...
@@ -122,7 +122,7 @@ class Konqueror:
...
@@ -122,7 +122,7 @@ class Konqueror:
return
not
rc
return
not
rc
def
open
(
self
,
url
,
new
=
1
):
def
open
(
self
,
url
,
new
=
1
):
# XXX currently I know no way to prevent KFM from opening a new win.
# XXX currently I know no way to prevent KFM from opening a new win.
self
.
open_new
(
url
)
self
.
open_new
(
url
)
def
open_new
(
self
,
url
):
def
open_new
(
self
,
url
):
...
...
Lib/whrandom.py
View file @
e119006e
"""Wichman-Hill random number generator.
"""Wichman-Hill random number generator.
Wichmann, B. A. & Hill, I. D. (1982)
Wichmann, B. A. & Hill, I. D. (1982)
Algorithm AS 183:
Algorithm AS 183:
An efficient and portable pseudo-random number generator
An efficient and portable pseudo-random number generator
Applied Statistics 31 (1982) 188-190
Applied Statistics 31 (1982) 188-190
see also:
see also:
Correction to Algorithm AS 183
Correction to Algorithm AS 183
Applied Statistics 33 (1984) 123
Applied Statistics 33 (1984) 123
McLeod, A. I. (1985)
McLeod, A. I. (1985)
A remark on Algorithm AS 183
A remark on Algorithm AS 183
Applied Statistics 34 (1985),198-200
Applied Statistics 34 (1985),198-200
USE:
USE:
whrandom.random() yields double precision random numbers
whrandom.random() yields double precision random numbers
uniformly distributed between 0 and 1.
uniformly distributed between 0 and 1.
whrandom.seed(x, y, z) must be called before whrandom.random()
whrandom.seed(x, y, z) must be called before whrandom.random()
...
@@ -38,96 +38,96 @@ down in the serial case by using a lock here.)
...
@@ -38,96 +38,96 @@ down in the serial case by using a lock here.)
class
whrandom
:
class
whrandom
:
def
__init__
(
self
,
x
=
0
,
y
=
0
,
z
=
0
):
def
__init__
(
self
,
x
=
0
,
y
=
0
,
z
=
0
):
"""Initialize an instance.
"""Initialize an instance.
Without arguments, initialize from current time.
Without arguments, initialize from current time.
With arguments (x, y, z), initialize from them."""
With arguments (x, y, z), initialize from them."""
self
.
seed
(
x
,
y
,
z
)
self
.
seed
(
x
,
y
,
z
)
def
seed
(
self
,
x
=
0
,
y
=
0
,
z
=
0
):
def
seed
(
self
,
x
=
0
,
y
=
0
,
z
=
0
):
"""Set the seed from (x, y, z).
"""Set the seed from (x, y, z).
These must be integers in the range [0, 256)."""
These must be integers in the range [0, 256)."""
if
not
type
(
x
)
==
type
(
y
)
==
type
(
z
)
==
type
(
0
):
if
not
type
(
x
)
==
type
(
y
)
==
type
(
z
)
==
type
(
0
):
raise
TypeError
,
'seeds must be integers'
raise
TypeError
,
'seeds must be integers'
if
not
(
0
<=
x
<
256
and
0
<=
y
<
256
and
0
<=
z
<
256
):
if
not
(
0
<=
x
<
256
and
0
<=
y
<
256
and
0
<=
z
<
256
):
raise
ValueError
,
'seeds must be in range(0, 256)'
raise
ValueError
,
'seeds must be in range(0, 256)'
if
0
==
x
==
y
==
z
:
if
0
==
x
==
y
==
z
:
# Initialize from current time
# Initialize from current time
import
time
import
time
t
=
long
(
time
.
time
()
*
256
)
t
=
long
(
time
.
time
()
*
256
)
t
=
int
((
t
&
0xffffff
)
^
(
t
>>
24
))
t
=
int
((
t
&
0xffffff
)
^
(
t
>>
24
))
t
,
x
=
divmod
(
t
,
256
)
t
,
x
=
divmod
(
t
,
256
)
t
,
y
=
divmod
(
t
,
256
)
t
,
y
=
divmod
(
t
,
256
)
t
,
z
=
divmod
(
t
,
256
)
t
,
z
=
divmod
(
t
,
256
)
# Zero is a poor seed, so substitute 1
# Zero is a poor seed, so substitute 1
self
.
_seed
=
(
x
or
1
,
y
or
1
,
z
or
1
)
self
.
_seed
=
(
x
or
1
,
y
or
1
,
z
or
1
)
def
random
(
self
):
def
random
(
self
):
"""Get the next random number in the range [0.0, 1.0)."""
"""Get the next random number in the range [0.0, 1.0)."""
# This part is thread-unsafe:
# This part is thread-unsafe:
# BEGIN CRITICAL SECTION
# BEGIN CRITICAL SECTION
x
,
y
,
z
=
self
.
_seed
x
,
y
,
z
=
self
.
_seed
#
#
x
=
(
171
*
x
)
%
30269
x
=
(
171
*
x
)
%
30269
y
=
(
172
*
y
)
%
30307
y
=
(
172
*
y
)
%
30307
z
=
(
170
*
z
)
%
30323
z
=
(
170
*
z
)
%
30323
#
#
self
.
_seed
=
x
,
y
,
z
self
.
_seed
=
x
,
y
,
z
# END CRITICAL SECTION
# END CRITICAL SECTION
#
#
return
(
x
/
30269.0
+
y
/
30307.0
+
z
/
30323.0
)
%
1.0
return
(
x
/
30269.0
+
y
/
30307.0
+
z
/
30323.0
)
%
1.0
def
uniform
(
self
,
a
,
b
):
def
uniform
(
self
,
a
,
b
):
"""Get a random number in the range [a, b)."""
"""Get a random number in the range [a, b)."""
return
a
+
(
b
-
a
)
*
self
.
random
()
return
a
+
(
b
-
a
)
*
self
.
random
()
def
randint
(
self
,
a
,
b
):
def
randint
(
self
,
a
,
b
):
"""Get a random integer in the range [a, b] including
"""Get a random integer in the range [a, b] including
both end points.
both end points.
(Deprecated; use randrange below.)"""
(Deprecated; use randrange below.)"""
return
self
.
randrange
(
a
,
b
+
1
)
return
self
.
randrange
(
a
,
b
+
1
)
def
choice
(
self
,
seq
):
def
choice
(
self
,
seq
):
"""Choose a random element from a non-empty sequence."""
"""Choose a random element from a non-empty sequence."""
return
seq
[
int
(
self
.
random
()
*
len
(
seq
))]
return
seq
[
int
(
self
.
random
()
*
len
(
seq
))]
def
randrange
(
self
,
start
,
stop
=
None
,
step
=
1
,
int
=
int
,
default
=
None
):
def
randrange
(
self
,
start
,
stop
=
None
,
step
=
1
,
int
=
int
,
default
=
None
):
"""Choose a random item from range(start, stop[, step]).
"""Choose a random item from range(start, stop[, step]).
This fixes the problem with randint() which includes the
This fixes the problem with randint() which includes the
endpoint; in Python this is usually not what you want.
endpoint; in Python this is usually not what you want.
Do not supply the 'int' and 'default' arguments."""
Do not supply the 'int' and 'default' arguments."""
# This code is a bit messy to make it fast for the
# This code is a bit messy to make it fast for the
# common case while still doing adequate error checking
# common case while still doing adequate error checking
istart
=
int
(
start
)
istart
=
int
(
start
)
if
istart
!=
start
:
if
istart
!=
start
:
raise
ValueError
,
"non-integer arg 1 for randrange()"
raise
ValueError
,
"non-integer arg 1 for randrange()"
if
stop
is
default
:
if
stop
is
default
:
if
istart
>
0
:
if
istart
>
0
:
return
int
(
self
.
random
()
*
istart
)
return
int
(
self
.
random
()
*
istart
)
raise
ValueError
,
"empty range for randrange()"
raise
ValueError
,
"empty range for randrange()"
istop
=
int
(
stop
)
istop
=
int
(
stop
)
if
istop
!=
stop
:
if
istop
!=
stop
:
raise
ValueError
,
"non-integer stop for randrange()"
raise
ValueError
,
"non-integer stop for randrange()"
if
step
==
1
:
if
step
==
1
:
if
istart
<
istop
:
if
istart
<
istop
:
return
istart
+
int
(
self
.
random
()
*
return
istart
+
int
(
self
.
random
()
*
(
istop
-
istart
))
(
istop
-
istart
))
raise
ValueError
,
"empty range for randrange()"
raise
ValueError
,
"empty range for randrange()"
istep
=
int
(
step
)
istep
=
int
(
step
)
if
istep
!=
step
:
if
istep
!=
step
:
raise
ValueError
,
"non-integer step for randrange()"
raise
ValueError
,
"non-integer step for randrange()"
if
istep
>
0
:
if
istep
>
0
:
n
=
(
istop
-
istart
+
istep
-
1
)
/
istep
n
=
(
istop
-
istart
+
istep
-
1
)
/
istep
elif
istep
<
0
:
elif
istep
<
0
:
n
=
(
istop
-
istart
+
istep
+
1
)
/
istep
n
=
(
istop
-
istart
+
istep
+
1
)
/
istep
else
:
else
:
raise
ValueError
,
"zero step for randrange()"
raise
ValueError
,
"zero step for randrange()"
if
n
<=
0
:
if
n
<=
0
:
raise
ValueError
,
"empty range for randrange()"
raise
ValueError
,
"empty range for randrange()"
return
istart
+
istep
*
int
(
self
.
random
()
*
n
)
return
istart
+
istep
*
int
(
self
.
random
()
*
n
)
# Initialize from the current time
# Initialize from the current time
...
...
Lib/xdrlib.py
View file @
e119006e
...
@@ -29,7 +29,7 @@ class ConversionError(Error):
...
@@ -29,7 +29,7 @@ class ConversionError(Error):
pass
pass
class
Packer
:
class
Packer
:
"""Pack various data representations into a buffer."""
"""Pack various data representations into a buffer."""
...
@@ -106,7 +106,7 @@ class Packer:
...
@@ -106,7 +106,7 @@ class Packer:
self
.
pack_farray
(
n
,
list
,
pack_item
)
self
.
pack_farray
(
n
,
list
,
pack_item
)
class
Unpacker
:
class
Unpacker
:
"""Unpacks various data representations from the given buffer."""
"""Unpacks various data representations from the given buffer."""
...
@@ -220,7 +220,7 @@ class Unpacker:
...
@@ -220,7 +220,7 @@ class Unpacker:
n
=
self
.
unpack_uint
()
n
=
self
.
unpack_uint
()
return
self
.
unpack_farray
(
n
,
unpack_item
)
return
self
.
unpack_farray
(
n
,
unpack_item
)
# test suite
# test suite
def
_test
():
def
_test
():
p
=
Packer
()
p
=
Packer
()
...
@@ -274,6 +274,6 @@ def _test():
...
@@ -274,6 +274,6 @@ def _test():
print
'ConversionError:'
,
var
.
msg
print
'ConversionError:'
,
var
.
msg
count
=
count
+
1
count
=
count
+
1
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
_test
()
_test
()
Lib/xmllib.py
View file @
e119006e
...
@@ -250,9 +250,9 @@ class XMLParser:
...
@@ -250,9 +250,9 @@ class XMLParser:
break
break
res
=
interesting
.
search
(
rawdata
,
i
)
res
=
interesting
.
search
(
rawdata
,
i
)
if
res
:
if
res
:
j
=
res
.
start
(
0
)
j
=
res
.
start
(
0
)
else
:
else
:
j
=
n
j
=
n
if
i
<
j
:
if
i
<
j
:
data
=
rawdata
[
i
:
j
]
data
=
rawdata
[
i
:
j
]
if
self
.
__at_start
and
space
.
match
(
data
)
is
None
:
if
self
.
__at_start
and
space
.
match
(
data
)
is
None
:
...
...
Lib/zipfile.py
View file @
e119006e
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment