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
463a4d72
Commit
463a4d72
authored
Jan 14, 2001
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Whitespace normalization.
parent
93fd3db8
Changes
18
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
1991 additions
and
1994 deletions
+1991
-1994
Lib/MimeWriter.py
Lib/MimeWriter.py
+1
-1
Lib/getpass.py
Lib/getpass.py
+75
-76
Lib/gettext.py
Lib/gettext.py
+7
-7
Lib/glob.py
Lib/glob.py
+41
-41
Lib/gzip.py
Lib/gzip.py
+25
-25
Lib/htmlentitydefs.py
Lib/htmlentitydefs.py
+252
-252
Lib/htmllib.py
Lib/htmllib.py
+1
-1
Lib/httplib.py
Lib/httplib.py
+17
-17
Lib/ihooks.py
Lib/ihooks.py
+2
-2
Lib/imaplib.py
Lib/imaplib.py
+818
-819
Lib/imghdr.py
Lib/imghdr.py
+2
-2
Lib/imputil.py
Lib/imputil.py
+6
-6
Lib/macurl2path.py
Lib/macurl2path.py
+5
-5
Lib/mailcap.py
Lib/mailcap.py
+3
-3
Lib/mimetools.py
Lib/mimetools.py
+176
-176
Lib/mimify.py
Lib/mimify.py
+398
-399
Lib/multifile.py
Lib/multifile.py
+130
-130
Lib/mutex.py
Lib/mutex.py
+32
-32
No files found.
Lib/MimeWriter.py
View file @
463a4d72
...
@@ -30,7 +30,7 @@ class MimeWriter:
...
@@ -30,7 +30,7 @@ class MimeWriter:
amounts of buffer space, so you have to write the parts in the
amounts of buffer space, so you have to write the parts in the
order they should occur on the output file. It does buffer the
order they should occur on the output file. It does buffer the
headers you add, allowing you to rearrange their order.
headers you add, allowing you to rearrange their order.
General usage is:
General usage is:
f = <open the output file>
f = <open the output file>
...
...
Lib/getpass.py
View file @
463a4d72
...
@@ -14,106 +14,105 @@ On the Mac EasyDialogs.AskPassword is used, if available.
...
@@ -14,106 +14,105 @@ On the Mac EasyDialogs.AskPassword is used, if available.
import
sys
import
sys
def
unix_getpass
(
prompt
=
'Password: '
):
def
unix_getpass
(
prompt
=
'Password: '
):
"""Prompt for a password, with echo turned off.
"""Prompt for a password, with echo turned off.
Restore terminal settings at end.
Restore terminal settings at end.
"""
"""
try
:
try
:
fd
=
sys
.
stdin
.
fileno
()
fd
=
sys
.
stdin
.
fileno
()
except
:
except
:
return
default_getpass
(
prompt
)
return
default_getpass
(
prompt
)
getpass
=
default_getpass
getpass
=
default_getpass
old
=
termios
.
tcgetattr
(
fd
)
# a copy to save
old
=
termios
.
tcgetattr
(
fd
)
# a copy to save
new
=
old
[:]
new
=
old
[:]
new
[
3
]
=
new
[
3
]
&
~
TERMIOS
.
ECHO
# 3 == 'lflags'
new
[
3
]
=
new
[
3
]
&
~
TERMIOS
.
ECHO
# 3 == 'lflags'
try
:
try
:
termios
.
tcsetattr
(
fd
,
TERMIOS
.
TCSADRAIN
,
new
)
termios
.
tcsetattr
(
fd
,
TERMIOS
.
TCSADRAIN
,
new
)
passwd
=
_raw_input
(
prompt
)
passwd
=
_raw_input
(
prompt
)
finally
:
finally
:
termios
.
tcsetattr
(
fd
,
TERMIOS
.
TCSADRAIN
,
old
)
termios
.
tcsetattr
(
fd
,
TERMIOS
.
TCSADRAIN
,
old
)
sys
.
stdout
.
write
(
'
\
n
'
)
sys
.
stdout
.
write
(
'
\
n
'
)
return
passwd
return
passwd
def
win_getpass
(
prompt
=
'Password: '
):
def
win_getpass
(
prompt
=
'Password: '
):
"""Prompt for password with echo off, using Windows getch()."""
"""Prompt for password with echo off, using Windows getch()."""
import
msvcrt
import
msvcrt
for
c
in
prompt
:
for
c
in
prompt
:
msvcrt
.
putch
(
c
)
msvcrt
.
putch
(
c
)
pw
=
""
pw
=
""
while
1
:
while
1
:
c
=
msvcrt
.
getch
()
c
=
msvcrt
.
getch
()
if
c
==
'
\
r
'
or
c
==
'
\
n
'
:
if
c
==
'
\
r
'
or
c
==
'
\
n
'
:
break
break
if
c
==
'
\
003
'
:
if
c
==
'
\
003
'
:
raise
KeyboardInterrupt
raise
KeyboardInterrupt
if
c
==
'
\
b
'
:
if
c
==
'
\
b
'
:
pw
=
pw
[:
-
1
]
pw
=
pw
[:
-
1
]
else
:
else
:
pw
=
pw
+
c
pw
=
pw
+
c
msvcrt
.
putch
(
'
\
r
'
)
msvcrt
.
putch
(
'
\
r
'
)
msvcrt
.
putch
(
'
\
n
'
)
msvcrt
.
putch
(
'
\
n
'
)
return
pw
return
pw
def
default_getpass
(
prompt
=
'Password: '
):
def
default_getpass
(
prompt
=
'Password: '
):
print
"Warning: Problem with getpass. Passwords may be echoed."
print
"Warning: Problem with getpass. Passwords may be echoed."
return
_raw_input
(
prompt
)
return
_raw_input
(
prompt
)
def
_raw_input
(
prompt
=
""
):
def
_raw_input
(
prompt
=
""
):
# A raw_input() replacement that doesn't save the string in the
# A raw_input() replacement that doesn't save the string in the
# GNU readline history.
# GNU readline history.
import
sys
import
sys
prompt
=
str
(
prompt
)
prompt
=
str
(
prompt
)
if
prompt
:
if
prompt
:
sys
.
stdout
.
write
(
prompt
)
sys
.
stdout
.
write
(
prompt
)
line
=
sys
.
stdin
.
readline
()
line
=
sys
.
stdin
.
readline
()
if
not
line
:
if
not
line
:
raise
EOFError
raise
EOFError
if
line
[
-
1
]
==
'
\
n
'
:
if
line
[
-
1
]
==
'
\
n
'
:
line
=
line
[:
-
1
]
line
=
line
[:
-
1
]
return
line
return
line
def
getuser
():
def
getuser
():
"""Get the username from the environment or password database.
"""Get the username from the environment or password database.
First try various environment variables, then the password
First try various environment variables, then the password
database. This works on Windows as long as USERNAME is set.
database. This works on Windows as long as USERNAME is set.
"""
"""
import
os
import
os
for
name
in
(
'LOGNAME'
,
'USER'
,
'LNAME'
,
'USERNAME'
):
for
name
in
(
'LOGNAME'
,
'USER'
,
'LNAME'
,
'USERNAME'
):
user
=
os
.
environ
.
get
(
name
)
user
=
os
.
environ
.
get
(
name
)
if
user
:
if
user
:
return
user
return
user
# If this fails, the exception will "explain" why
# If this fails, the exception will "explain" why
import
pwd
import
pwd
return
pwd
.
getpwuid
(
os
.
getuid
())[
0
]
return
pwd
.
getpwuid
(
os
.
getuid
())[
0
]
# Bind the name getpass to the appropriate function
# Bind the name getpass to the appropriate function
try
:
try
:
import
termios
,
TERMIOS
import
termios
,
TERMIOS
except
ImportError
:
except
ImportError
:
try
:
try
:
import
msvcrt
import
msvcrt
except
ImportError
:
except
ImportError
:
try
:
try
:
from
EasyDialogs
import
AskPassword
from
EasyDialogs
import
AskPassword
except
ImportError
:
except
ImportError
:
getpass
=
default_getpass
getpass
=
default_getpass
else
:
else
:
getpass
=
AskPassword
getpass
=
AskPassword
else
:
else
:
getpass
=
win_getpass
getpass
=
win_getpass
else
:
else
:
getpass
=
unix_getpass
getpass
=
unix_getpass
Lib/gettext.py
View file @
463a4d72
...
@@ -51,7 +51,7 @@ from errno import ENOENT
...
@@ -51,7 +51,7 @@ from errno import ENOENT
_default_localedir
=
os
.
path
.
join
(
sys
.
prefix
,
'share'
,
'locale'
)
_default_localedir
=
os
.
path
.
join
(
sys
.
prefix
,
'share'
,
'locale'
)
def
_expand_lang
(
locale
):
def
_expand_lang
(
locale
):
from
locale
import
normalize
from
locale
import
normalize
locale
=
normalize
(
locale
)
locale
=
normalize
(
locale
)
...
@@ -94,7 +94,7 @@ def _expand_lang(locale):
...
@@ -94,7 +94,7 @@ def _expand_lang(locale):
return
ret
return
ret
class
NullTranslations
:
class
NullTranslations
:
def
__init__
(
self
,
fp
=
None
):
def
__init__
(
self
,
fp
=
None
):
self
.
_info
=
{}
self
.
_info
=
{}
...
@@ -192,7 +192,7 @@ class GNUTranslations(NullTranslations):
...
@@ -192,7 +192,7 @@ class GNUTranslations(NullTranslations):
return
unicode
(
tmsg
,
self
.
_charset
)
return
unicode
(
tmsg
,
self
.
_charset
)
# Locate a .mo file using the gettext strategy
# Locate a .mo file using the gettext strategy
def
find
(
domain
,
localedir
=
None
,
languages
=
None
):
def
find
(
domain
,
localedir
=
None
,
languages
=
None
):
# Get some reasonable defaults for arguments that were not supplied
# Get some reasonable defaults for arguments that were not supplied
...
@@ -223,7 +223,7 @@ def find(domain, localedir=None, languages=None):
...
@@ -223,7 +223,7 @@ def find(domain, localedir=None, languages=None):
return
None
return
None
# a mapping between absolute .mo file path and Translation object
# a mapping between absolute .mo file path and Translation object
_translations
=
{}
_translations
=
{}
...
@@ -243,12 +243,12 @@ def translation(domain, localedir=None, languages=None, class_=None):
...
@@ -243,12 +243,12 @@ def translation(domain, localedir=None, languages=None, class_=None):
return
t
return
t
def
install
(
domain
,
localedir
=
None
,
unicode
=
0
):
def
install
(
domain
,
localedir
=
None
,
unicode
=
0
):
translation
(
domain
,
localedir
).
install
(
unicode
)
translation
(
domain
,
localedir
).
install
(
unicode
)
# a mapping b/w domains and locale directories
# a mapping b/w domains and locale directories
_localedirs
=
{}
_localedirs
=
{}
# current global domain, `messages' used for compatibility w/ GNU gettext
# current global domain, `messages' used for compatibility w/ GNU gettext
...
@@ -275,7 +275,7 @@ def dgettext(domain, message):
...
@@ -275,7 +275,7 @@ def dgettext(domain, message):
except
IOError
:
except
IOError
:
return
message
return
message
return
t
.
gettext
(
message
)
return
t
.
gettext
(
message
)
def
gettext
(
message
):
def
gettext
(
message
):
return
dgettext
(
_current_domain
,
message
)
return
dgettext
(
_current_domain
,
message
)
...
...
Lib/glob.py
View file @
463a4d72
...
@@ -6,51 +6,51 @@ import re
...
@@ -6,51 +6,51 @@ import re
def
glob
(
pathname
):
def
glob
(
pathname
):
"""Return a list of paths matching a pathname pattern.
"""Return a list of paths matching a pathname pattern.
The pattern may contain simple shell-style wildcards a la fnmatch.
The pattern may contain simple shell-style wildcards a la fnmatch.
"""
"""
if
not
has_magic
(
pathname
):
if
not
has_magic
(
pathname
):
if
os
.
path
.
exists
(
pathname
):
if
os
.
path
.
exists
(
pathname
):
return
[
pathname
]
return
[
pathname
]
else
:
else
:
return
[]
return
[]
dirname
,
basename
=
os
.
path
.
split
(
pathname
)
dirname
,
basename
=
os
.
path
.
split
(
pathname
)
if
has_magic
(
dirname
):
if
has_magic
(
dirname
):
list
=
glob
(
dirname
)
list
=
glob
(
dirname
)
else
:
else
:
list
=
[
dirname
]
list
=
[
dirname
]
if
not
has_magic
(
basename
):
if
not
has_magic
(
basename
):
result
=
[]
result
=
[]
for
dirname
in
list
:
for
dirname
in
list
:
if
basename
or
os
.
path
.
isdir
(
dirname
):
if
basename
or
os
.
path
.
isdir
(
dirname
):
name
=
os
.
path
.
join
(
dirname
,
basename
)
name
=
os
.
path
.
join
(
dirname
,
basename
)
if
os
.
path
.
exists
(
name
):
if
os
.
path
.
exists
(
name
):
result
.
append
(
name
)
result
.
append
(
name
)
else
:
else
:
result
=
[]
result
=
[]
for
dirname
in
list
:
for
dirname
in
list
:
sublist
=
glob1
(
dirname
,
basename
)
sublist
=
glob1
(
dirname
,
basename
)
for
name
in
sublist
:
for
name
in
sublist
:
result
.
append
(
os
.
path
.
join
(
dirname
,
name
))
result
.
append
(
os
.
path
.
join
(
dirname
,
name
))
return
result
return
result
def
glob1
(
dirname
,
pattern
):
def
glob1
(
dirname
,
pattern
):
if
not
dirname
:
dirname
=
os
.
curdir
if
not
dirname
:
dirname
=
os
.
curdir
try
:
try
:
names
=
os
.
listdir
(
dirname
)
names
=
os
.
listdir
(
dirname
)
except
os
.
error
:
except
os
.
error
:
return
[]
return
[]
result
=
[]
result
=
[]
for
name
in
names
:
for
name
in
names
:
if
name
[
0
]
!=
'.'
or
pattern
[
0
]
==
'.'
:
if
name
[
0
]
!=
'.'
or
pattern
[
0
]
==
'.'
:
if
fnmatch
.
fnmatch
(
name
,
pattern
):
if
fnmatch
.
fnmatch
(
name
,
pattern
):
result
.
append
(
name
)
result
.
append
(
name
)
return
result
return
result
magic_check
=
re
.
compile
(
'[*?[]'
)
magic_check
=
re
.
compile
(
'[*?[]'
)
def
has_magic
(
s
):
def
has_magic
(
s
):
return
magic_check
.
search
(
s
)
is
not
None
return
magic_check
.
search
(
s
)
is
not
None
Lib/gzip.py
View file @
463a4d72
...
@@ -15,7 +15,7 @@ READ, WRITE = 1, 2
...
@@ -15,7 +15,7 @@ READ, WRITE = 1, 2
def
write32
(
output
,
value
):
def
write32
(
output
,
value
):
output
.
write
(
struct
.
pack
(
"<l"
,
value
))
output
.
write
(
struct
.
pack
(
"<l"
,
value
))
def
write32u
(
output
,
value
):
def
write32u
(
output
,
value
):
output
.
write
(
struct
.
pack
(
"<L"
,
value
))
output
.
write
(
struct
.
pack
(
"<L"
,
value
))
...
@@ -29,7 +29,7 @@ class GzipFile:
...
@@ -29,7 +29,7 @@ class GzipFile:
myfileobj
=
None
myfileobj
=
None
def
__init__
(
self
,
filename
=
None
,
mode
=
None
,
def
__init__
(
self
,
filename
=
None
,
mode
=
None
,
compresslevel
=
9
,
fileobj
=
None
):
compresslevel
=
9
,
fileobj
=
None
):
if
fileobj
is
None
:
if
fileobj
is
None
:
fileobj
=
self
.
myfileobj
=
__builtin__
.
open
(
filename
,
mode
or
'rb'
)
fileobj
=
self
.
myfileobj
=
__builtin__
.
open
(
filename
,
mode
or
'rb'
)
...
@@ -42,8 +42,8 @@ class GzipFile:
...
@@ -42,8 +42,8 @@ class GzipFile:
if
mode
[
0
:
1
]
==
'r'
:
if
mode
[
0
:
1
]
==
'r'
:
self
.
mode
=
READ
self
.
mode
=
READ
# Set flag indicating start of a new member
# Set flag indicating start of a new member
self
.
_new_member
=
1
self
.
_new_member
=
1
self
.
extrabuf
=
""
self
.
extrabuf
=
""
self
.
extrasize
=
0
self
.
extrasize
=
0
self
.
filename
=
filename
self
.
filename
=
filename
...
@@ -52,7 +52,7 @@ class GzipFile:
...
@@ -52,7 +52,7 @@ class GzipFile:
self
.
mode
=
WRITE
self
.
mode
=
WRITE
self
.
_init_write
(
filename
)
self
.
_init_write
(
filename
)
self
.
compress
=
zlib
.
compressobj
(
compresslevel
,
self
.
compress
=
zlib
.
compressobj
(
compresslevel
,
zlib
.
DEFLATED
,
zlib
.
DEFLATED
,
-
zlib
.
MAX_WBITS
,
-
zlib
.
MAX_WBITS
,
zlib
.
DEF_MEM_LEVEL
,
zlib
.
DEF_MEM_LEVEL
,
0
)
0
)
...
@@ -110,7 +110,7 @@ class GzipFile:
...
@@ -110,7 +110,7 @@ class GzipFile:
if
flag
&
FEXTRA
:
if
flag
&
FEXTRA
:
# Read & discard the extra field, if present
# Read & discard the extra field, if present
xlen
=
ord
(
self
.
fileobj
.
read
(
1
))
xlen
=
ord
(
self
.
fileobj
.
read
(
1
))
xlen
=
xlen
+
256
*
ord
(
self
.
fileobj
.
read
(
1
))
xlen
=
xlen
+
256
*
ord
(
self
.
fileobj
.
read
(
1
))
self
.
fileobj
.
read
(
xlen
)
self
.
fileobj
.
read
(
xlen
)
if
flag
&
FNAME
:
if
flag
&
FNAME
:
...
@@ -158,7 +158,7 @@ class GzipFile:
...
@@ -158,7 +158,7 @@ class GzipFile:
except
EOFError
:
except
EOFError
:
if
size
>
self
.
extrasize
:
if
size
>
self
.
extrasize
:
size
=
self
.
extrasize
size
=
self
.
extrasize
chunk
=
self
.
extrabuf
[:
size
]
chunk
=
self
.
extrabuf
[:
size
]
self
.
extrabuf
=
self
.
extrabuf
[
size
:]
self
.
extrabuf
=
self
.
extrabuf
[
size
:]
self
.
extrasize
=
self
.
extrasize
-
size
self
.
extrasize
=
self
.
extrasize
-
size
...
@@ -171,11 +171,11 @@ class GzipFile:
...
@@ -171,11 +171,11 @@ class GzipFile:
def
_read
(
self
,
size
=
1024
):
def
_read
(
self
,
size
=
1024
):
if
self
.
fileobj
is
None
:
raise
EOFError
,
"Reached EOF"
if
self
.
fileobj
is
None
:
raise
EOFError
,
"Reached EOF"
if
self
.
_new_member
:
if
self
.
_new_member
:
# If the _new_member flag is set, we have to
# If the _new_member flag is set, we have to
# jump to the next member, if there is one.
# jump to the next member, if there is one.
#
#
# First, check if we're at the end of the file;
# First, check if we're at the end of the file;
# if so, it's time to stop; no more members to read.
# if so, it's time to stop; no more members to read.
pos
=
self
.
fileobj
.
tell
()
# Save current position
pos
=
self
.
fileobj
.
tell
()
# Save current position
...
@@ -183,27 +183,27 @@ class GzipFile:
...
@@ -183,27 +183,27 @@ class GzipFile:
if
pos
==
self
.
fileobj
.
tell
():
if
pos
==
self
.
fileobj
.
tell
():
self
.
fileobj
=
None
self
.
fileobj
=
None
raise
EOFError
,
"Reached EOF"
raise
EOFError
,
"Reached EOF"
else
:
else
:
self
.
fileobj
.
seek
(
pos
)
# Return to original position
self
.
fileobj
.
seek
(
pos
)
# Return to original position
self
.
_init_read
()
self
.
_init_read
()
self
.
_read_gzip_header
()
self
.
_read_gzip_header
()
self
.
decompress
=
zlib
.
decompressobj
(
-
zlib
.
MAX_WBITS
)
self
.
decompress
=
zlib
.
decompressobj
(
-
zlib
.
MAX_WBITS
)
self
.
_new_member
=
0
self
.
_new_member
=
0
# Read a chunk of data from the file
# Read a chunk of data from the file
buf
=
self
.
fileobj
.
read
(
size
)
buf
=
self
.
fileobj
.
read
(
size
)
# If the EOF has been reached, flush the decompression object
# If the EOF has been reached, flush the decompression object
# and mark this object as finished.
# and mark this object as finished.
if
buf
==
""
:
if
buf
==
""
:
uncompress
=
self
.
decompress
.
flush
()
uncompress
=
self
.
decompress
.
flush
()
self
.
_read_eof
()
self
.
_read_eof
()
self
.
fileobj
=
None
self
.
fileobj
=
None
self
.
_add_read_data
(
uncompress
)
self
.
_add_read_data
(
uncompress
)
raise
EOFError
,
'Reached EOF'
raise
EOFError
,
'Reached EOF'
uncompress
=
self
.
decompress
.
decompress
(
buf
)
uncompress
=
self
.
decompress
.
decompress
(
buf
)
self
.
_add_read_data
(
uncompress
)
self
.
_add_read_data
(
uncompress
)
...
@@ -216,11 +216,11 @@ class GzipFile:
...
@@ -216,11 +216,11 @@ class GzipFile:
self
.
fileobj
.
seek
(
-
len
(
self
.
decompress
.
unused_data
)
+
8
,
1
)
self
.
fileobj
.
seek
(
-
len
(
self
.
decompress
.
unused_data
)
+
8
,
1
)
# Check the CRC and file size, and set the flag so we read
# Check the CRC and file size, and set the flag so we read
# a new member on the next call
# a new member on the next call
self
.
_read_eof
()
self
.
_read_eof
()
self
.
_new_member
=
1
self
.
_new_member
=
1
def
_add_read_data
(
self
,
data
):
def
_add_read_data
(
self
,
data
):
self
.
crc
=
zlib
.
crc32
(
data
,
self
.
crc
)
self
.
crc
=
zlib
.
crc32
(
data
,
self
.
crc
)
self
.
extrabuf
=
self
.
extrabuf
+
data
self
.
extrabuf
=
self
.
extrabuf
+
data
self
.
extrasize
=
self
.
extrasize
+
len
(
data
)
self
.
extrasize
=
self
.
extrasize
+
len
(
data
)
...
@@ -228,7 +228,7 @@ class GzipFile:
...
@@ -228,7 +228,7 @@ class GzipFile:
def
_read_eof
(
self
):
def
_read_eof
(
self
):
# We've read to the end of the file, so we have to rewind in order
# We've read to the end of the file, so we have to rewind in order
# to reread the 8 bytes containing the CRC and the file size.
# to reread the 8 bytes containing the CRC and the file size.
# We check the that the computed CRC and size of the
# We check the that the computed CRC and size of the
# uncompressed data matches the stored values.
# uncompressed data matches the stored values.
self
.
fileobj
.
seek
(
-
8
,
1
)
self
.
fileobj
.
seek
(
-
8
,
1
)
...
@@ -238,7 +238,7 @@ class GzipFile:
...
@@ -238,7 +238,7 @@ class GzipFile:
raise
ValueError
,
"CRC check failed"
raise
ValueError
,
"CRC check failed"
elif
isize
!=
self
.
size
:
elif
isize
!=
self
.
size
:
raise
ValueError
,
"Incorrect length of data produced"
raise
ValueError
,
"Incorrect length of data produced"
def
close
(
self
):
def
close
(
self
):
if
self
.
mode
==
WRITE
:
if
self
.
mode
==
WRITE
:
self
.
fileobj
.
write
(
self
.
compress
.
flush
())
self
.
fileobj
.
write
(
self
.
compress
.
flush
())
...
@@ -259,7 +259,7 @@ class GzipFile:
...
@@ -259,7 +259,7 @@ class GzipFile:
except
AttributeError
:
except
AttributeError
:
return
return
self
.
close
()
self
.
close
()
def
flush
(
self
):
def
flush
(
self
):
self
.
fileobj
.
flush
()
self
.
fileobj
.
flush
()
...
@@ -285,7 +285,7 @@ class GzipFile:
...
@@ -285,7 +285,7 @@ class GzipFile:
i
=
string
.
find
(
c
,
'
\
n
'
)
i
=
string
.
find
(
c
,
'
\
n
'
)
if
size
is
not
None
:
if
size
is
not
None
:
# We set i=size to break out of the loop under two
# We set i=size to break out of the loop under two
# conditions: 1) there's no newline, and the chunk is
# conditions: 1) there's no newline, and the chunk is
# larger than size, or 2) there is a newline, but the
# larger than size, or 2) there is a newline, but the
# resulting line would be longer than 'size'.
# resulting line would be longer than 'size'.
if
i
==-
1
and
len
(
c
)
>
size
:
i
=
size
-
1
if
i
==-
1
and
len
(
c
)
>
size
:
i
=
size
-
1
...
@@ -300,7 +300,7 @@ class GzipFile:
...
@@ -300,7 +300,7 @@ class GzipFile:
bufs
.
append
(
c
)
bufs
.
append
(
c
)
size
=
size
-
len
(
c
)
size
=
size
-
len
(
c
)
readsize
=
min
(
size
,
readsize
*
2
)
readsize
=
min
(
size
,
readsize
*
2
)
def
readlines
(
self
,
sizehint
=
0
):
def
readlines
(
self
,
sizehint
=
0
):
# Negative numbers result in reading all the lines
# Negative numbers result in reading all the lines
if
sizehint
<=
0
:
sizehint
=
sys
.
maxint
if
sizehint
<=
0
:
sizehint
=
sys
.
maxint
...
...
Lib/htmlentitydefs.py
View file @
463a4d72
This diff is collapsed.
Click to expand it.
Lib/htmllib.py
View file @
463a4d72
...
@@ -411,7 +411,7 @@ def test(args = None):
...
@@ -411,7 +411,7 @@ def test(args = None):
if
f
is
not
sys
.
stdin
:
if
f
is
not
sys
.
stdin
:
f
.
close
()
f
.
close
()
if
silent
:
if
silent
:
f
=
formatter
.
NullFormatter
()
f
=
formatter
.
NullFormatter
()
else
:
else
:
...
...
Lib/httplib.py
View file @
463a4d72
...
@@ -93,14 +93,14 @@ class HTTPResponse:
...
@@ -93,14 +93,14 @@ class HTTPResponse:
self
.
msg
=
None
self
.
msg
=
None
# from the Status-Line of the response
# from the Status-Line of the response
self
.
version
=
_UNKNOWN
# HTTP-Version
self
.
version
=
_UNKNOWN
# HTTP-Version
self
.
status
=
_UNKNOWN
# Status-Code
self
.
status
=
_UNKNOWN
# Status-Code
self
.
reason
=
_UNKNOWN
# Reason-Phrase
self
.
reason
=
_UNKNOWN
# Reason-Phrase
self
.
chunked
=
_UNKNOWN
# is "chunked" being used?
self
.
chunked
=
_UNKNOWN
# is "chunked" being used?
self
.
chunk_left
=
_UNKNOWN
# bytes left to read in current chunk
self
.
chunk_left
=
_UNKNOWN
# bytes left to read in current chunk
self
.
length
=
_UNKNOWN
# number of bytes left in response
self
.
length
=
_UNKNOWN
# number of bytes left in response
self
.
will_close
=
_UNKNOWN
# conn will close at end of response
self
.
will_close
=
_UNKNOWN
# conn will close at end of response
def
begin
(
self
):
def
begin
(
self
):
if
self
.
msg
is
not
None
:
if
self
.
msg
is
not
None
:
...
@@ -130,7 +130,7 @@ class HTTPResponse:
...
@@ -130,7 +130,7 @@ class HTTPResponse:
if
version
==
'HTTP/1.0'
:
if
version
==
'HTTP/1.0'
:
self
.
version
=
10
self
.
version
=
10
elif
version
.
startswith
(
'HTTP/1.'
):
elif
version
.
startswith
(
'HTTP/1.'
):
self
.
version
=
11
# use HTTP/1.1 code for HTTP/1.x where x>=1
self
.
version
=
11
# use HTTP/1.1 code for HTTP/1.x where x>=1
elif
version
==
'HTTP/0.9'
:
elif
version
==
'HTTP/0.9'
:
self
.
version
=
9
self
.
version
=
9
else
:
else
:
...
@@ -186,9 +186,9 @@ class HTTPResponse:
...
@@ -186,9 +186,9 @@ class HTTPResponse:
self
.
length
=
None
self
.
length
=
None
# does the body have a fixed length? (of zero)
# does the body have a fixed length? (of zero)
if
(
status
==
204
or
# No Content
if
(
status
==
204
or
# No Content
status
==
304
or
# Not Modified
status
==
304
or
# Not Modified
100
<=
status
<
200
):
# 1xx codes
100
<=
status
<
200
):
# 1xx codes
self
.
length
=
0
self
.
length
=
0
# if the connection remains open, and we aren't using chunked, and
# if the connection remains open, and we aren't using chunked, and
...
@@ -225,7 +225,7 @@ class HTTPResponse:
...
@@ -225,7 +225,7 @@ class HTTPResponse:
line
=
self
.
fp
.
readline
()
line
=
self
.
fp
.
readline
()
i
=
line
.
find
(
';'
)
i
=
line
.
find
(
';'
)
if
i
>=
0
:
if
i
>=
0
:
line
=
line
[:
i
]
# strip chunk-extensions
line
=
line
[:
i
]
# strip chunk-extensions
chunk_left
=
int
(
line
,
16
)
chunk_left
=
int
(
line
,
16
)
if
chunk_left
==
0
:
if
chunk_left
==
0
:
break
break
...
@@ -237,7 +237,7 @@ class HTTPResponse:
...
@@ -237,7 +237,7 @@ class HTTPResponse:
return
value
return
value
elif
amt
==
chunk_left
:
elif
amt
==
chunk_left
:
value
=
value
+
self
.
_safe_read
(
amt
)
value
=
value
+
self
.
_safe_read
(
amt
)
self
.
_safe_read
(
2
)
# toss the CRLF at the end of the chunk
self
.
_safe_read
(
2
)
# toss the CRLF at the end of the chunk
self
.
chunk_left
=
None
self
.
chunk_left
=
None
return
value
return
value
else
:
else
:
...
@@ -245,7 +245,7 @@ class HTTPResponse:
...
@@ -245,7 +245,7 @@ class HTTPResponse:
amt
=
amt
-
chunk_left
amt
=
amt
-
chunk_left
# we read the whole chunk, get another
# we read the whole chunk, get another
self
.
_safe_read
(
2
)
# toss the CRLF at the end of the chunk
self
.
_safe_read
(
2
)
# toss the CRLF at the end of the chunk
chunk_left
=
None
chunk_left
=
None
# read and discard trailer up to the CRLF terminator
# read and discard trailer up to the CRLF terminator
...
@@ -266,7 +266,7 @@ class HTTPResponse:
...
@@ -266,7 +266,7 @@ class HTTPResponse:
s
=
self
.
fp
.
read
()
s
=
self
.
fp
.
read
()
else
:
else
:
s
=
self
.
_safe_read
(
self
.
length
)
s
=
self
.
_safe_read
(
self
.
length
)
self
.
close
()
# we read everything
self
.
close
()
# we read everything
return
s
return
s
if
self
.
length
is
not
None
:
if
self
.
length
is
not
None
:
...
@@ -355,7 +355,7 @@ class HTTPConnection:
...
@@ -355,7 +355,7 @@ class HTTPConnection:
def
close
(
self
):
def
close
(
self
):
"""Close the connection to the HTTP server."""
"""Close the connection to the HTTP server."""
if
self
.
sock
:
if
self
.
sock
:
self
.
sock
.
close
()
# close it manually... there may be other refs
self
.
sock
.
close
()
# close it manually... there may be other refs
self
.
sock
=
None
self
.
sock
=
None
if
self
.
__response
:
if
self
.
__response
:
self
.
__response
.
close
()
self
.
__response
.
close
()
...
@@ -380,7 +380,7 @@ class HTTPConnection:
...
@@ -380,7 +380,7 @@ class HTTPConnection:
try
:
try
:
self
.
sock
.
send
(
str
)
self
.
sock
.
send
(
str
)
except
socket
.
error
,
v
:
except
socket
.
error
,
v
:
if
v
[
0
]
==
32
:
# Broken pipe
if
v
[
0
]
==
32
:
# Broken pipe
self
.
close
()
self
.
close
()
raise
raise
...
...
Lib/ihooks.py
View file @
463a4d72
...
@@ -109,7 +109,7 @@ class BasicModuleLoader(_Verbose):
...
@@ -109,7 +109,7 @@ class BasicModuleLoader(_Verbose):
"""
"""
def
find_module
(
self
,
name
,
path
=
None
):
def
find_module
(
self
,
name
,
path
=
None
):
if
path
is
None
:
if
path
is
None
:
path
=
[
None
]
+
self
.
default_path
()
path
=
[
None
]
+
self
.
default_path
()
for
dir
in
path
:
for
dir
in
path
:
stuff
=
self
.
find_module_in_dir
(
name
,
dir
)
stuff
=
self
.
find_module_in_dir
(
name
,
dir
)
...
@@ -390,7 +390,7 @@ class BasicModuleImporter(_Verbose):
...
@@ -390,7 +390,7 @@ class BasicModuleImporter(_Verbose):
class
ModuleImporter
(
BasicModuleImporter
):
class
ModuleImporter
(
BasicModuleImporter
):
"""A module importer that supports packages."""
"""A module importer that supports packages."""
def
import_module
(
self
,
name
,
globals
=
None
,
locals
=
None
,
fromlist
=
None
):
def
import_module
(
self
,
name
,
globals
=
None
,
locals
=
None
,
fromlist
=
None
):
parent
=
self
.
determine_parent
(
globals
)
parent
=
self
.
determine_parent
(
globals
)
q
,
tail
=
self
.
find_head_package
(
parent
,
name
)
q
,
tail
=
self
.
find_head_package
(
parent
,
name
)
...
...
Lib/imaplib.py
View file @
463a4d72
This diff is collapsed.
Click to expand it.
Lib/imghdr.py
View file @
463a4d72
...
@@ -14,7 +14,7 @@ def what(file, h=None):
...
@@ -14,7 +14,7 @@ def what(file, h=None):
location
=
file
.
tell
()
location
=
file
.
tell
()
h
=
file
.
read
(
32
)
h
=
file
.
read
(
32
)
file
.
seek
(
location
)
file
.
seek
(
location
)
f
=
None
f
=
None
else
:
else
:
f
=
None
f
=
None
try
:
try
:
...
@@ -103,7 +103,7 @@ tests.append(test_jpeg)
...
@@ -103,7 +103,7 @@ tests.append(test_jpeg)
def
test_bmp
(
h
,
f
):
def
test_bmp
(
h
,
f
):
if
h
[:
2
]
==
'BM'
:
if
h
[:
2
]
==
'BM'
:
return
'bmp'
return
'bmp'
tests
.
append
(
test_bmp
)
tests
.
append
(
test_bmp
)
def
test_png
(
h
,
f
):
def
test_png
(
h
,
f
):
...
...
Lib/imputil.py
View file @
463a4d72
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
### docco needed here and in Docs/ ...
### docco needed here and in Docs/ ...
# note: avoid importing non-builtin modules
# note: avoid importing non-builtin modules
import
imp
### not available in JPython?
import
imp
### not available in JPython?
import
sys
import
sys
import
strop
import
strop
import
__builtin__
import
__builtin__
...
@@ -15,7 +15,7 @@ import struct
...
@@ -15,7 +15,7 @@ import struct
import
marshal
import
marshal
_StringType
=
type
(
''
)
_StringType
=
type
(
''
)
_ModuleType
=
type
(
sys
)
### doesn't work in JPython...
_ModuleType
=
type
(
sys
)
### doesn't work in JPython...
class
ImportManager
:
class
ImportManager
:
"Manage the import process."
"Manage the import process."
...
@@ -663,7 +663,7 @@ def _test_revamp():
...
@@ -663,7 +663,7 @@ def _test_revamp():
#
#
#
#
# Guido's comments on sys.path caching:
# Guido's comments on sys.path caching:
#
#
# We could cache this in a dictionary: the ImportManager can have a
# We could cache this in a dictionary: the ImportManager can have a
# cache dict mapping pathnames to importer objects, and a separate
# cache dict mapping pathnames to importer objects, and a separate
# method for coming up with an importer given a pathname that's not yet
# method for coming up with an importer given a pathname that's not yet
...
@@ -679,16 +679,16 @@ def _test_revamp():
...
@@ -679,16 +679,16 @@ def _test_revamp():
# My/Guido's comments on factoring ImportManager and Importer:
# My/Guido's comments on factoring ImportManager and Importer:
#
#
# > However, we still have a tension occurring here:
# > However, we still have a tension occurring here:
# >
# >
# > 1) implementing policy in ImportManager assists in single-point policy
# > 1) implementing policy in ImportManager assists in single-point policy
# > changes for app/rexec situations
# > changes for app/rexec situations
# > 2) implementing policy in Importer assists in package-private policy
# > 2) implementing policy in Importer assists in package-private policy
# > changes for normal, operating conditions
# > changes for normal, operating conditions
# >
# >
# > I'll see if I can sort out a way to do this. Maybe the Importer class will
# > I'll see if I can sort out a way to do this. Maybe the Importer class will
# > implement the methods (which can be overridden to change policy) by
# > implement the methods (which can be overridden to change policy) by
# > delegating to ImportManager.
# > delegating to ImportManager.
#
#
# Maybe also think about what kind of policies an Importer would be
# Maybe also think about what kind of policies an Importer would be
# likely to want to change. I have a feeling that a lot of the code
# likely to want to change. I have a feeling that a lot of the code
# there is actually not so much policy but a *necessity* to get things
# there is actually not so much policy but a *necessity* to get things
...
...
Lib/macurl2path.py
View file @
463a4d72
...
@@ -16,7 +16,7 @@ def url2pathname(pathname):
...
@@ -16,7 +16,7 @@ def url2pathname(pathname):
raise
RuntimeError
,
'Cannot convert non-local URL to pathname'
raise
RuntimeError
,
'Cannot convert non-local URL to pathname'
# Turn starting /// into /, an empty hostname means current host
# Turn starting /// into /, an empty hostname means current host
if
pathname
[:
3
]
==
'///'
:
if
pathname
[:
3
]
==
'///'
:
pathname
=
pathname
[
2
:]
pathname
=
pathname
[
2
:]
elif
pathname
[:
2
]
==
'//'
:
elif
pathname
[:
2
]
==
'//'
:
raise
RuntimeError
,
'Cannot convert non-local URL to pathname'
raise
RuntimeError
,
'Cannot convert non-local URL to pathname'
components
=
string
.
split
(
pathname
,
'/'
)
components
=
string
.
split
(
pathname
,
'/'
)
...
@@ -68,11 +68,11 @@ def pathname2url(pathname):
...
@@ -68,11 +68,11 @@ def pathname2url(pathname):
return
'/'
+
string
.
join
(
components
,
'/'
)
return
'/'
+
string
.
join
(
components
,
'/'
)
else
:
else
:
return
string
.
join
(
components
,
'/'
)
return
string
.
join
(
components
,
'/'
)
def
_pncomp2url
(
component
):
def
_pncomp2url
(
component
):
component
=
urllib
.
quote
(
component
[:
31
],
safe
=
''
)
# We want to quote slashes
component
=
urllib
.
quote
(
component
[:
31
],
safe
=
''
)
# We want to quote slashes
return
component
return
component
def
test
():
def
test
():
for
url
in
[
"index.html"
,
for
url
in
[
"index.html"
,
"bar/index.html"
,
"bar/index.html"
,
...
...
Lib/mailcap.py
View file @
463a4d72
...
@@ -8,7 +8,7 @@ import string
...
@@ -8,7 +8,7 @@ import string
def
getcaps
():
def
getcaps
():
"""Return a dictionary containing the mailcap database.
"""Return a dictionary containing the mailcap database.
The dictionary maps a MIME type (in all lowercase, e.g. 'text/plain')
The dictionary maps a MIME type (in all lowercase, e.g. 'text/plain')
to a list of dictionaries corresponding to mailcap entries. The list
to a list of dictionaries corresponding to mailcap entries. The list
collects all the entries for that MIME type from all available mailcap
collects all the entries for that MIME type from all available mailcap
...
@@ -137,7 +137,7 @@ def parsefield(line, i, n):
...
@@ -137,7 +137,7 @@ def parsefield(line, i, n):
def
findmatch
(
caps
,
MIMEtype
,
key
=
'view'
,
filename
=
"/dev/null"
,
plist
=
[]):
def
findmatch
(
caps
,
MIMEtype
,
key
=
'view'
,
filename
=
"/dev/null"
,
plist
=
[]):
"""Find a match for a mailcap entry.
"""Find a match for a mailcap entry.
Return a tuple containing the command line, and the mailcap entry
Return a tuple containing the command line, and the mailcap entry
used; (None, None) if no match is found. This may invoke the
used; (None, None) if no match is found. This may invoke the
'test' command of several matching entries before deciding which
'test' command of several matching entries before deciding which
...
@@ -145,7 +145,7 @@ def findmatch(caps, MIMEtype, key='view', filename="/dev/null", plist=[]):
...
@@ -145,7 +145,7 @@ def findmatch(caps, MIMEtype, key='view', filename="/dev/null", plist=[]):
"""
"""
entries
=
lookup
(
caps
,
MIMEtype
,
key
)
entries
=
lookup
(
caps
,
MIMEtype
,
key
)
# XXX This code should somehow check for the needsterminal flag.
# XXX This code should somehow check for the needsterminal flag.
for
e
in
entries
:
for
e
in
entries
:
if
e
.
has_key
(
'test'
):
if
e
.
has_key
(
'test'
):
test
=
subst
(
e
[
'test'
],
filename
,
plist
)
test
=
subst
(
e
[
'test'
],
filename
,
plist
)
...
...
Lib/mimetools.py
View file @
463a4d72
This diff is collapsed.
Click to expand it.
Lib/mimify.py
View file @
463a4d72
This diff is collapsed.
Click to expand it.
Lib/multifile.py
View file @
463a4d72
...
@@ -13,8 +13,8 @@ fp = MultiFile(real_fp)
...
@@ -13,8 +13,8 @@ fp = MultiFile(real_fp)
"read some lines from fp"
"read some lines from fp"
fp.push(separator)
fp.push(separator)
while 1:
while 1:
"read lines from fp until it returns an empty string" (A)
"read lines from fp until it returns an empty string" (A)
if not fp.next(): break
if not fp.next(): break
fp.pop()
fp.pop()
"read remaining lines from fp until it returns an empty string"
"read remaining lines from fp until it returns an empty string"
...
@@ -31,134 +31,134 @@ import sys
...
@@ -31,134 +31,134 @@ import sys
import
string
import
string
class
Error
(
Exception
):
class
Error
(
Exception
):
pass
pass
class
MultiFile
:
class
MultiFile
:
seekable
=
0
seekable
=
0
def
__init__
(
self
,
fp
,
seekable
=
1
):
def
__init__
(
self
,
fp
,
seekable
=
1
):
self
.
fp
=
fp
self
.
fp
=
fp
self
.
stack
=
[]
# Grows down
self
.
stack
=
[]
# Grows down
self
.
level
=
0
self
.
level
=
0
self
.
last
=
0
self
.
last
=
0
if
seekable
:
if
seekable
:
self
.
seekable
=
1
self
.
seekable
=
1
self
.
start
=
self
.
fp
.
tell
()
self
.
start
=
self
.
fp
.
tell
()
self
.
posstack
=
[]
# Grows down
self
.
posstack
=
[]
# Grows down
def
tell
(
self
):
def
tell
(
self
):
if
self
.
level
>
0
:
if
self
.
level
>
0
:
return
self
.
lastpos
return
self
.
lastpos
return
self
.
fp
.
tell
()
-
self
.
start
return
self
.
fp
.
tell
()
-
self
.
start
def
seek
(
self
,
pos
,
whence
=
0
):
def
seek
(
self
,
pos
,
whence
=
0
):
here
=
self
.
tell
()
here
=
self
.
tell
()
if
whence
:
if
whence
:
if
whence
==
1
:
if
whence
==
1
:
pos
=
pos
+
here
pos
=
pos
+
here
elif
whence
==
2
:
elif
whence
==
2
:
if
self
.
level
>
0
:
if
self
.
level
>
0
:
pos
=
pos
+
self
.
lastpos
pos
=
pos
+
self
.
lastpos
else
:
else
:
raise
Error
,
"can't use whence=2 yet"
raise
Error
,
"can't use whence=2 yet"
if
not
0
<=
pos
<=
here
or
\
if
not
0
<=
pos
<=
here
or
\
self
.
level
>
0
and
pos
>
self
.
lastpos
:
self
.
level
>
0
and
pos
>
self
.
lastpos
:
raise
Error
,
'bad MultiFile.seek() call'
raise
Error
,
'bad MultiFile.seek() call'
self
.
fp
.
seek
(
pos
+
self
.
start
)
self
.
fp
.
seek
(
pos
+
self
.
start
)
self
.
level
=
0
self
.
level
=
0
self
.
last
=
0
self
.
last
=
0
def
readline
(
self
):
def
readline
(
self
):
if
self
.
level
>
0
:
if
self
.
level
>
0
:
return
''
return
''
line
=
self
.
fp
.
readline
()
line
=
self
.
fp
.
readline
()
# Real EOF?
# Real EOF?
if
not
line
:
if
not
line
:
self
.
level
=
len
(
self
.
stack
)
self
.
level
=
len
(
self
.
stack
)
self
.
last
=
(
self
.
level
>
0
)
self
.
last
=
(
self
.
level
>
0
)
if
self
.
last
:
if
self
.
last
:
raise
Error
,
'sudden EOF in MultiFile.readline()'
raise
Error
,
'sudden EOF in MultiFile.readline()'
return
''
return
''
assert
self
.
level
==
0
assert
self
.
level
==
0
# Fast check to see if this is just data
# Fast check to see if this is just data
if
self
.
is_data
(
line
):
if
self
.
is_data
(
line
):
return
line
return
line
else
:
else
:
# Ignore trailing whitespace on marker lines
# Ignore trailing whitespace on marker lines
k
=
len
(
line
)
-
1
k
=
len
(
line
)
-
1
while
line
[
k
]
in
string
.
whitespace
:
while
line
[
k
]
in
string
.
whitespace
:
k
=
k
-
1
k
=
k
-
1
marker
=
line
[:
k
+
1
]
marker
=
line
[:
k
+
1
]
# No? OK, try to match a boundary.
# No? OK, try to match a boundary.
# Return the line (unstripped) if we don't.
# Return the line (unstripped) if we don't.
for
i
in
range
(
len
(
self
.
stack
)):
for
i
in
range
(
len
(
self
.
stack
)):
sep
=
self
.
stack
[
i
]
sep
=
self
.
stack
[
i
]
if
marker
==
self
.
section_divider
(
sep
):
if
marker
==
self
.
section_divider
(
sep
):
self
.
last
=
0
self
.
last
=
0
break
break
elif
marker
==
self
.
end_marker
(
sep
):
elif
marker
==
self
.
end_marker
(
sep
):
self
.
last
=
1
self
.
last
=
1
break
break
else
:
else
:
return
line
return
line
# We only get here if we see a section divider or EOM line
# We only get here if we see a section divider or EOM line
if
self
.
seekable
:
if
self
.
seekable
:
self
.
lastpos
=
self
.
tell
()
-
len
(
line
)
self
.
lastpos
=
self
.
tell
()
-
len
(
line
)
self
.
level
=
i
+
1
self
.
level
=
i
+
1
if
self
.
level
>
1
:
if
self
.
level
>
1
:
raise
Error
,
'Missing endmarker in MultiFile.readline()'
raise
Error
,
'Missing endmarker in MultiFile.readline()'
return
''
return
''
def
readlines
(
self
):
def
readlines
(
self
):
list
=
[]
list
=
[]
while
1
:
while
1
:
line
=
self
.
readline
()
line
=
self
.
readline
()
if
not
line
:
break
if
not
line
:
break
list
.
append
(
line
)
list
.
append
(
line
)
return
list
return
list
def
read
(
self
):
# Note: no size argument -- read until EOF only!
def
read
(
self
):
# Note: no size argument -- read until EOF only!
return
string
.
joinfields
(
self
.
readlines
(),
''
)
return
string
.
joinfields
(
self
.
readlines
(),
''
)
def
next
(
self
):
def
next
(
self
):
while
self
.
readline
():
pass
while
self
.
readline
():
pass
if
self
.
level
>
1
or
self
.
last
:
if
self
.
level
>
1
or
self
.
last
:
return
0
return
0
self
.
level
=
0
self
.
level
=
0
self
.
last
=
0
self
.
last
=
0
if
self
.
seekable
:
if
self
.
seekable
:
self
.
start
=
self
.
fp
.
tell
()
self
.
start
=
self
.
fp
.
tell
()
return
1
return
1
def
push
(
self
,
sep
):
def
push
(
self
,
sep
):
if
self
.
level
>
0
:
if
self
.
level
>
0
:
raise
Error
,
'bad MultiFile.push() call'
raise
Error
,
'bad MultiFile.push() call'
self
.
stack
.
insert
(
0
,
sep
)
self
.
stack
.
insert
(
0
,
sep
)
if
self
.
seekable
:
if
self
.
seekable
:
self
.
posstack
.
insert
(
0
,
self
.
start
)
self
.
posstack
.
insert
(
0
,
self
.
start
)
self
.
start
=
self
.
fp
.
tell
()
self
.
start
=
self
.
fp
.
tell
()
def
pop
(
self
):
def
pop
(
self
):
if
self
.
stack
==
[]:
if
self
.
stack
==
[]:
raise
Error
,
'bad MultiFile.pop() call'
raise
Error
,
'bad MultiFile.pop() call'
if
self
.
level
<=
1
:
if
self
.
level
<=
1
:
self
.
last
=
0
self
.
last
=
0
else
:
else
:
abslastpos
=
self
.
lastpos
+
self
.
start
abslastpos
=
self
.
lastpos
+
self
.
start
self
.
level
=
max
(
0
,
self
.
level
-
1
)
self
.
level
=
max
(
0
,
self
.
level
-
1
)
del
self
.
stack
[
0
]
del
self
.
stack
[
0
]
if
self
.
seekable
:
if
self
.
seekable
:
self
.
start
=
self
.
posstack
[
0
]
self
.
start
=
self
.
posstack
[
0
]
del
self
.
posstack
[
0
]
del
self
.
posstack
[
0
]
if
self
.
level
>
0
:
if
self
.
level
>
0
:
self
.
lastpos
=
abslastpos
-
self
.
start
self
.
lastpos
=
abslastpos
-
self
.
start
def
is_data
(
self
,
line
):
def
is_data
(
self
,
line
):
return
line
[:
2
]
!=
'--'
return
line
[:
2
]
!=
'--'
def
section_divider
(
self
,
str
):
def
section_divider
(
self
,
str
):
return
"--"
+
str
return
"--"
+
str
def
end_marker
(
self
,
str
):
def
end_marker
(
self
,
str
):
return
"--"
+
str
+
"--"
return
"--"
+
str
+
"--"
Lib/mutex.py
View file @
463a4d72
...
@@ -13,39 +13,39 @@ for lock, where a function is called once the lock is aquired.
...
@@ -13,39 +13,39 @@ for lock, where a function is called once the lock is aquired.
"""
"""
class
mutex
:
class
mutex
:
def
__init__
(
self
):
def
__init__
(
self
):
"""Create a new mutex -- initially unlocked."""
"""Create a new mutex -- initially unlocked."""
self
.
locked
=
0
self
.
locked
=
0
self
.
queue
=
[]
self
.
queue
=
[]
def
test
(
self
):
def
test
(
self
):
"""Test the locked bit of the mutex."""
"""Test the locked bit of the mutex."""
return
self
.
locked
return
self
.
locked
def
testandset
(
self
):
def
testandset
(
self
):
"""Atomic test-and-set -- grab the lock if it is not set,
"""Atomic test-and-set -- grab the lock if it is not set,
return true if it succeeded."""
return true if it succeeded."""
if
not
self
.
locked
:
if
not
self
.
locked
:
self
.
locked
=
1
self
.
locked
=
1
return
1
return
1
else
:
else
:
return
0
return
0
def
lock
(
self
,
function
,
argument
):
def
lock
(
self
,
function
,
argument
):
"""Lock a mutex, call the function with supplied argument
"""Lock a mutex, call the function with supplied argument
when it is acquired. If the mutex is already locked, place
when it is acquired. If the mutex is already locked, place
function and argument in the queue."""
function and argument in the queue."""
if
self
.
testandset
():
if
self
.
testandset
():
function
(
argument
)
function
(
argument
)
else
:
else
:
self
.
queue
.
append
((
function
,
argument
))
self
.
queue
.
append
((
function
,
argument
))
def
unlock
(
self
):
def
unlock
(
self
):
"""Unlock a mutex. If the queue is not empty, call the next
"""Unlock a mutex. If the queue is not empty, call the next
function with its argument."""
function with its argument."""
if
self
.
queue
:
if
self
.
queue
:
function
,
argument
=
self
.
queue
[
0
]
function
,
argument
=
self
.
queue
[
0
]
del
self
.
queue
[
0
]
del
self
.
queue
[
0
]
function
(
argument
)
function
(
argument
)
else
:
else
:
self
.
locked
=
0
self
.
locked
=
0
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