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 @@
## vim:ts=4:et:nowrap
"""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.
"""
from
types
import
StringType
,
UnicodeType
...
...
@@ -14,7 +14,7 @@ class UserString:
self
.
data
=
seq
elif
isinstance
(
seq
,
UserString
):
self
.
data
=
seq
.
data
[:]
else
:
else
:
self
.
data
=
str
(
seq
)
def
__str__
(
self
):
return
str
(
self
.
data
)
def
__repr__
(
self
):
return
repr
(
self
.
data
)
...
...
@@ -76,15 +76,15 @@ class UserString:
return
self
.
__class__
(
self
.
data
.
encode
(
encoding
,
errors
))
else
:
return
self
.
__class__
(
self
.
data
.
encode
(
encoding
))
else
:
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
):
def
expandtabs
(
self
,
tabsize
=
8
):
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
)
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
)
def
isalpha
(
self
):
return
self
.
data
.
isalpha
()
def
isalnum
(
self
):
return
self
.
data
.
isalnum
()
...
...
@@ -99,23 +99,23 @@ class UserString:
def
ljust
(
self
,
width
):
return
self
.
__class__
(
self
.
data
.
ljust
(
width
))
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
):
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
):
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
):
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
):
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
):
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
):
def
translate
(
self
,
*
args
):
return
self
.
__class__
(
self
.
data
.
translate
(
*
args
))
def
upper
(
self
):
return
self
.
__class__
(
self
.
data
.
upper
())
...
...
@@ -136,7 +136,7 @@ class MutableString(UserString):
A faster and better solution is to rewrite your program using lists."""
def
__init__
(
self
,
string
=
""
):
self
.
data
=
string
def
__hash__
(
self
):
def
__hash__
(
self
):
raise
TypeError
,
"unhashable type (it is mutable)"
def
__setitem__
(
self
,
index
,
sub
):
if
index
<
0
or
index
>=
len
(
self
.
data
):
raise
IndexError
...
...
@@ -157,7 +157,7 @@ class MutableString(UserString):
self
.
data
=
self
.
data
[:
start
]
+
self
.
data
[
end
:]
def
immutable
(
self
):
return
UserString
(
self
.
data
)
if
__name__
==
"__main__"
:
# execute the regression test to stdout, if called as a script:
import
os
...
...
Lib/urllib.py
View file @
e119006e
...
...
@@ -551,11 +551,11 @@ class FancyURLopener(URLopener):
if
match
:
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
)
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
):
host
,
selector
=
splithost
(
url
)
...
...
@@ -571,14 +571,14 @@ class FancyURLopener(URLopener):
return
self
.
open
(
newurl
,
data
)
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
)
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
):
key
=
realm
+
'@'
+
host
.
lower
()
...
...
Lib/urllib2.py
View file @
e119006e
"""An extensible library for opening URLs using a variety of protocols
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
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
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
HTTPHandler performs HTTP GET and POST requests and deals with
...
...
@@ -16,7 +16,7 @@ with digest authentication.
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
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
treated as a valid response.
...
...
@@ -42,7 +42,7 @@ exceptions:
URLError-- a subclass of IOError, individual protocols have their own
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
internals:
...
...
@@ -57,7 +57,7 @@ import urllib2
authinfo = urllib2.HTTPBasicAuthHandler()
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)
# install it
...
...
@@ -73,7 +73,7 @@ f = urllib2.urlopen('http://www.python.org/')
# authentication for some reason but fails, how should the error be
# 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
# that hash algo that requested in the challenge, it would be good to
# pass that information along to the client, too.
# XXX to do:
...
...
@@ -141,7 +141,7 @@ def install_opener(opener):
_opener
=
opener
# 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.
class
URLError
(
IOError
):
...
...
@@ -165,7 +165,7 @@ class HTTPError(URLError, addinfourl):
self
.
fp
=
fp
# XXX
self
.
filename
=
url
def
__str__
(
self
):
return
'HTTP Error %s: %s'
%
(
self
.
code
,
self
.
msg
)
...
...
@@ -192,7 +192,7 @@ class Request:
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
# methods getting called in a non-standard order. this may be
# too complicated and/or unnecessary.
# XXX should the __r_XXX attributes be public?
if
attr
[:
12
]
==
'_Request__r_'
:
...
...
@@ -259,7 +259,7 @@ class OpenerDirector:
for
meth
in
get_methods
(
handler
):
if
meth
[
-
5
:]
==
'_open'
:
protocol
=
meth
[:
-
5
]
if
self
.
handle_open
.
has_key
(
protocol
):
if
self
.
handle_open
.
has_key
(
protocol
):
self
.
handle_open
[
protocol
].
append
(
handler
)
else
:
self
.
handle_open
[
protocol
]
=
[
handler
]
...
...
@@ -285,7 +285,7 @@ class OpenerDirector:
if
added
:
self
.
handlers
.
append
(
handler
)
handler
.
add_parent
(
self
)
def
__del__
(
self
):
self
.
close
()
...
...
@@ -314,9 +314,9 @@ class OpenerDirector:
if
data
is
not
None
:
req
.
add_data
(
data
)
assert
isinstance
(
req
,
Request
)
# really only care about interface
result
=
self
.
_call_chain
(
self
.
handle_open
,
'default'
,
'default_open'
,
req
)
'default_open'
,
req
)
if
result
:
return
result
...
...
@@ -381,7 +381,7 @@ def get_methods(inst):
# XXX probably also want an abstract factory that knows things like
# 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
# a subclass and when it might make sense to include both
def
build_opener
(
*
handlers
):
"""Create an opener object from a list of handlers.
...
...
@@ -393,7 +393,7 @@ def build_opener(*handlers):
If any of the handlers passed as arguments are subclasses of the
default handlers, the default handlers will not be used.
"""
opener
=
OpenerDirector
()
default_classes
=
[
ProxyHandler
,
UnknownHandler
,
HTTPHandler
,
HTTPDefaultErrorHandler
,
HTTPRedirectHandler
,
...
...
@@ -472,7 +472,7 @@ class ProxyHandler(BaseHandler):
assert
hasattr
(
proxies
,
'has_key'
),
"proxies must be a mapping"
self
.
proxies
=
proxies
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
:
\
meth
(
r
,
proxy
,
type
))
...
...
@@ -574,7 +574,7 @@ class HTTPPasswordMgr:
if
len
(
common
)
==
len
(
base
[
1
]):
return
1
return
0
class
HTTPBasicAuthHandler
(
BaseHandler
):
rx
=
re
.
compile
(
'[
\
t
]*([^
\
t
]+)[
\
t
]+realm="([^"]*)"'
)
...
...
@@ -590,8 +590,8 @@ class HTTPBasicAuthHandler(BaseHandler):
# if __current_realm is not None, then the server must have
# refused our name/password and is asking for authorization
# again. must be careful to set it to None on successful
# return.
# return.
def
http_error_401
(
self
,
req
,
fp
,
code
,
msg
,
headers
):
# XXX could be mult. headers
authreq
=
headers
.
get
(
'www-authenticate'
,
None
)
...
...
@@ -674,7 +674,7 @@ class HTTPDigestAuthHandler(BaseHandler):
return
None
user
,
pw
=
self
.
passwd
.
find_user_password
(
realm
,
req
.
get_full_url
())
req
.
get_full_url
())
if
user
is
None
:
return
None
...
...
@@ -724,8 +724,8 @@ def encode_digest(digest):
n
=
ord
(
c
)
&
0xf
hexrep
.
append
(
hex
(
n
)[
-
1
])
return
string
.
join
(
hexrep
,
''
)
class
HTTPHandler
(
BaseHandler
):
def
http_open
(
self
,
req
):
# XXX devise a new mechanism to specify user/password
...
...
@@ -745,7 +745,7 @@ class HTTPHandler(BaseHandler):
h
.
putrequest
(
'GET'
,
req
.
get_selector
())
except
socket
.
error
,
err
:
raise
URLError
(
err
)
# XXX proxies would have different host here
h
.
putheader
(
'Host'
,
host
)
for
args
in
self
.
parent
.
addheaders
:
...
...
@@ -813,7 +813,7 @@ def parse_http_list(s):
start
=
i
inquote
=
0
else
:
i
=
i
+
q
i
=
i
+
q
else
:
if
c
<
q
:
list
.
append
(
s
[
start
:
i
+
c
])
...
...
@@ -838,7 +838,7 @@ class FileHandler(BaseHandler):
names
=
None
def
get_names
(
self
):
if
FileHandler
.
names
is
None
:
FileHandler
.
names
=
(
socket
.
gethostbyname
(
'localhost'
),
FileHandler
.
names
=
(
socket
.
gethostbyname
(
'localhost'
),
socket
.
gethostbyname
(
socket
.
gethostname
()))
return
FileHandler
.
names
...
...
@@ -967,7 +967,7 @@ class GopherHandler(BaseHandler):
class
OpenerFactory
:
default_handlers
=
[
UnknownHandler
,
HTTPHandler
,
HTTPDefaultErrorHandler
,
HTTPRedirectHandler
,
HTTPDefaultErrorHandler
,
HTTPRedirectHandler
,
FTPHandler
,
FileHandler
]
proxy_handlers
=
[
ProxyHandler
]
handlers
=
[]
...
...
@@ -990,7 +990,7 @@ class OpenerFactory:
opener
.
add_handler
(
ph
)
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
# right authentication configuration for test purposes.
if
socket
.
gethostname
()
==
'bitdiddle'
:
...
...
@@ -1030,11 +1030,11 @@ if __name__ == "__main__":
bauth
=
HTTPBasicAuthHandler
()
bauth
.
add_password
(
'basic_test_realm'
,
localhost
,
'jhylton'
,
'password'
)
'password'
)
dauth
=
HTTPDigestAuthHandler
()
dauth
.
add_password
(
'digest_test_realm'
,
localhost
,
'jhylton'
,
dauth
.
add_password
(
'digest_test_realm'
,
localhost
,
'jhylton'
,
'password'
)
cfh
=
CacheFTPHandler
()
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 @@
# Copyright 1994 by Lance Ellinghouse
# 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,
# 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
# 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
# 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
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
...
...
@@ -154,7 +154,7 @@ def test():
print
' -d: Decode (in stead of encode)'
print
' -t: data is text, encoded format unix-compatible text'
sys
.
exit
(
1
)
for
o
,
a
in
optlist
:
if
o
==
'-d'
:
dopt
=
1
if
o
==
'-t'
:
topt
=
1
...
...
Lib/warnings.py
View file @
e119006e
...
...
@@ -131,29 +131,29 @@ def _processoptions(args):
# 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
)
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()
def
_getaction
(
action
):
...
...
Lib/wave.py
View file @
e119006e
...
...
@@ -395,7 +395,7 @@ class Wave_write:
def
getmarkers
(
self
):
return
None
def
tell
(
self
):
return
self
.
_nframeswritten
...
...
Lib/webbrowser.py
View file @
e119006e
...
...
@@ -122,7 +122,7 @@ class Konqueror:
return
not
rc
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
)
def
open_new
(
self
,
url
):
...
...
Lib/whrandom.py
View file @
e119006e
"""Wichman-Hill random number generator.
Wichmann, B. A. & Hill, I. D. (1982)
Algorithm AS 183:
Algorithm AS 183:
An efficient and portable pseudo-random number generator
Applied Statistics 31 (1982) 188-190
see also:
see also:
Correction to Algorithm AS 183
Applied Statistics 33 (1984) 123
Applied Statistics 33 (1984) 123
McLeod, A. I. (1985)
A remark on Algorithm AS 183
A remark on Algorithm AS 183
Applied Statistics 34 (1985),198-200
USE:
whrandom.random() yields double precision random numbers
whrandom.random() yields double precision random numbers
uniformly distributed between 0 and 1.
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.)
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
)
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
)
# Initialize from the current time
...
...
Lib/xdrlib.py
View file @
e119006e
...
...
@@ -29,7 +29,7 @@ class ConversionError(Error):
pass
class
Packer
:
"""Pack various data representations into a buffer."""
...
...
@@ -106,7 +106,7 @@ class Packer:
self
.
pack_farray
(
n
,
list
,
pack_item
)
class
Unpacker
:
"""Unpacks various data representations from the given buffer."""
...
...
@@ -220,7 +220,7 @@ class Unpacker:
n
=
self
.
unpack_uint
()
return
self
.
unpack_farray
(
n
,
unpack_item
)
# test suite
def
_test
():
p
=
Packer
()
...
...
@@ -274,6 +274,6 @@ def _test():
print
'ConversionError:'
,
var
.
msg
count
=
count
+
1
if
__name__
==
'__main__'
:
_test
()
Lib/xmllib.py
View file @
e119006e
...
...
@@ -250,9 +250,9 @@ class XMLParser:
break
res
=
interesting
.
search
(
rawdata
,
i
)
if
res
:
j
=
res
.
start
(
0
)
j
=
res
.
start
(
0
)
else
:
j
=
n
j
=
n
if
i
<
j
:
data
=
rawdata
[
i
:
j
]
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