summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-01-21 20:36:10 (GMT)
committerGeorg Brandl <georg@python.org>2008-01-21 20:36:10 (GMT)
commit86def6cb2b8d6d8c7f239795fa7af57c97a5890d (patch)
treeb4c1860eabc4fa30e6fb9f01af21a78a12e11cbb /Lib
parente1c981161c49ce6bc232b62f85ca222530491dae (diff)
downloadcpython-86def6cb2b8d6d8c7f239795fa7af57c97a5890d.zip
cpython-86def6cb2b8d6d8c7f239795fa7af57c97a5890d.tar.gz
cpython-86def6cb2b8d6d8c7f239795fa7af57c97a5890d.tar.bz2
Merged revisions 60151-60159,60161-60168,60170,60172-60173,60175 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r60151 | christian.heimes | 2008-01-21 14:11:15 +0100 (Mon, 21 Jan 2008) | 1 line A bunch of header files were not listed as dependencies for object files. Changes to files like Parser/parser.h weren't picked up by make. ........ r60152 | georg.brandl | 2008-01-21 15:16:46 +0100 (Mon, 21 Jan 2008) | 3 lines #1087741: make mmap.mmap the type of mmap objects, not a factory function. Allow it to be subclassed. ........ r60153 | georg.brandl | 2008-01-21 15:18:14 +0100 (Mon, 21 Jan 2008) | 2 lines mmap is an extension module. ........ r60154 | georg.brandl | 2008-01-21 17:28:13 +0100 (Mon, 21 Jan 2008) | 2 lines Fix example. ........ r60155 | georg.brandl | 2008-01-21 17:34:07 +0100 (Mon, 21 Jan 2008) | 2 lines #1555501: document plistlib and move it to the general library. ........ r60156 | georg.brandl | 2008-01-21 17:36:00 +0100 (Mon, 21 Jan 2008) | 2 lines Add a stub for bundlebuilder documentation. ........ r60157 | georg.brandl | 2008-01-21 17:46:58 +0100 (Mon, 21 Jan 2008) | 2 lines Removing bundlebuilder docs again -- it's not to be used anymore (see #779825). ........ r60158 | georg.brandl | 2008-01-21 17:51:51 +0100 (Mon, 21 Jan 2008) | 2 lines #997912: acknowledge nested scopes in tutorial. ........ r60159 | vinay.sajip | 2008-01-21 18:02:26 +0100 (Mon, 21 Jan 2008) | 1 line Fix: #1836: Off-by-one bug in TimedRotatingFileHandler rollover calculation. Patch thanks to Kathryn M. Kowalski. ........ r60161 | georg.brandl | 2008-01-21 18:13:03 +0100 (Mon, 21 Jan 2008) | 2 lines Adapt pydoc to new doc URLs. ........ r60162 | georg.brandl | 2008-01-21 18:17:00 +0100 (Mon, 21 Jan 2008) | 2 lines Fix old link. ........ r60163 | georg.brandl | 2008-01-21 18:22:06 +0100 (Mon, 21 Jan 2008) | 2 lines #1726198: replace while 1: fp.readline() with file iteration. ........ r60164 | georg.brandl | 2008-01-21 18:29:23 +0100 (Mon, 21 Jan 2008) | 2 lines Clarify $ behavior in re docstring. #1631394. ........ r60165 | vinay.sajip | 2008-01-21 18:39:22 +0100 (Mon, 21 Jan 2008) | 1 line Minor documentation change - hyperlink tidied up. ........ r60166 | georg.brandl | 2008-01-21 18:42:40 +0100 (Mon, 21 Jan 2008) | 2 lines #1530959: change distutils build dir for --with-pydebug python builds. ........ r60167 | vinay.sajip | 2008-01-21 19:16:05 +0100 (Mon, 21 Jan 2008) | 1 line Updated to include news on recent logging fixes and documentation changes. ........ r60168 | georg.brandl | 2008-01-21 19:35:49 +0100 (Mon, 21 Jan 2008) | 3 lines Issue #1882: when compiling code from a string, encoding cookies in the second line of code were not always recognized correctly. ........ r60170 | georg.brandl | 2008-01-21 19:36:51 +0100 (Mon, 21 Jan 2008) | 2 lines Add NEWS entry for #1882. ........ r60172 | georg.brandl | 2008-01-21 19:41:24 +0100 (Mon, 21 Jan 2008) | 2 lines Use original location of document, which has translations. ........ r60173 | walter.doerwald | 2008-01-21 21:18:04 +0100 (Mon, 21 Jan 2008) | 2 lines Follow PEP 8 in module docstring. ........ r60175 | georg.brandl | 2008-01-21 21:20:53 +0100 (Mon, 21 Jan 2008) | 2 lines Adapt to latest doctools refactoring. ........
Diffstat (limited to 'Lib')
-rw-r--r--Lib/distutils/command/build.py6
-rw-r--r--Lib/formatter.py5
-rwxr-xr-xLib/keyword.py4
-rw-r--r--Lib/logging/handlers.py7
-rw-r--r--Lib/plistlib.py (renamed from Lib/plat-mac/plistlib.py)99
-rwxr-xr-xLib/pydoc.py13
-rw-r--r--Lib/re.py9
-rw-r--r--Lib/test/test_pep263.py8
-rw-r--r--Lib/urlparse.py4
9 files changed, 84 insertions, 71 deletions
diff --git a/Lib/distutils/command/build.py b/Lib/distutils/command/build.py
index 1f2ce06..4fe95b0 100644
--- a/Lib/distutils/command/build.py
+++ b/Lib/distutils/command/build.py
@@ -66,6 +66,12 @@ class build(Command):
def finalize_options(self):
plat_specifier = ".%s-%s" % (get_platform(), sys.version[0:3])
+ # Make it so Python 2.x and Python 2.x with --with-pydebug don't
+ # share the same build directories. Doing so confuses the build
+ # process for C modules
+ if hasattr(sys, 'gettotalrefcount'):
+ plat_specifier += '-pydebug'
+
# 'build_purelib' and 'build_platlib' just default to 'lib' and
# 'lib.<plat>' under the base build directory. We only use one of
# them for a given distribution, though --
diff --git a/Lib/formatter.py b/Lib/formatter.py
index 99b4740..bb8ad20 100644
--- a/Lib/formatter.py
+++ b/Lib/formatter.py
@@ -433,10 +433,7 @@ def test(file = None):
fp = open(sys.argv[1])
else:
fp = sys.stdin
- while 1:
- line = fp.readline()
- if not line:
- break
+ for line in fp:
if line == '\n':
f.end_paragraph(1)
else:
diff --git a/Lib/keyword.py b/Lib/keyword.py
index 9c49cd2..a7abe2b 100755
--- a/Lib/keyword.py
+++ b/Lib/keyword.py
@@ -64,9 +64,7 @@ def main():
fp = open(iptfile)
strprog = re.compile('"([^"]+)"')
lines = []
- while 1:
- line = fp.readline()
- if not line: break
+ for line in fp:
if '{1, "' in line:
match = strprog.search(line)
if match:
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index b53262e..08bebbd 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -226,13 +226,16 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
# Days to rollover is 6 - 5 + 3, or 4. In this case, it's the
# number of days left in the current week (1) plus the number
# of days in the next week until the rollover day (3).
+ # The calculations described in 2) and 3) above need to have a day added.
+ # This is because the above time calculation takes us to midnight on this
+ # day, i.e. the start of the next day.
if when.startswith('W'):
day = t[6] # 0 is Monday
if day != self.dayOfWeek:
if day < self.dayOfWeek:
- daysToWait = self.dayOfWeek - day - 1
+ daysToWait = self.dayOfWeek - day
else:
- daysToWait = 6 - day + self.dayOfWeek
+ daysToWait = 6 - day + self.dayOfWeek + 1
self.rolloverAt = self.rolloverAt + (daysToWait * (60 * 60 * 24))
#print "Will rollover at %d, %d seconds from now" % (self.rolloverAt, self.rolloverAt - currentTime)
diff --git a/Lib/plat-mac/plistlib.py b/Lib/plistlib.py
index db5eea1..9cd1c8e 100644
--- a/Lib/plat-mac/plistlib.py
+++ b/Lib/plistlib.py
@@ -1,6 +1,6 @@
"""plistlib.py -- a tool to generate and parse MacOSX .plist files.
-The PropertList (.plist) file format is a simple XML pickle supporting
+The PropertyList (.plist) file format is a simple XML pickle supporting
basic object types, like dictionaries, lists, numbers and strings.
Usually the top level object is a dictionary.
@@ -12,8 +12,8 @@ To parse a plist from a file, use the readPlist(pathOrFile) function,
with a file name or a (readable) file object as the only argument. It
returns the top level object (again, usually a dictionary).
-To work with plist data in bytes objects, you can use readPlistFromBytes()
-and writePlistToBytes().
+To work with plist data in strings, you can use readPlistFromString()
+and writePlistToString().
Values can be strings, integers, floats, booleans, tuples, lists,
dictionaries, Data or datetime.datetime objects. String values (including
@@ -21,24 +21,24 @@ dictionary keys) may be unicode strings -- they will be written out as
UTF-8.
The <data> plist type is supported through the Data class. This is a
-thin wrapper around a Python bytes object.
+thin wrapper around a Python string.
Generate Plist example:
pl = dict(
aString="Doodah",
aList=["A", "B", 12, 32.1, [1, 2, 3]],
- aFloat = 0.1,
- anInt = 728,
+ aFloat=0.1,
+ anInt=728,
aDict=dict(
anotherString="<hello & hi there!>",
aUnicodeValue=u'M\xe4ssig, Ma\xdf',
aTrueValue=True,
aFalseValue=False,
),
- someData = Data(b"<binary gunk>"),
- someMoreData = Data(b"<lots of binary gunk>" * 10),
- aDate = datetime.datetime.fromtimestamp(time.mktime(time.gmtime())),
+ someData=Data("<binary gunk>"),
+ someMoreData=Data("<lots of binary gunk>" * 10),
+ aDate=datetime.datetime.fromtimestamp(time.mktime(time.gmtime())),
)
# unicode keys are possible, but a little awkward to use:
pl[u'\xc5benraa'] = "That was a unicode key."
@@ -52,7 +52,7 @@ Parse Plist example:
__all__ = [
- "readPlist", "writePlist", "readPlistFromBytes", "writePlistToBytes",
+ "readPlist", "writePlist", "readPlistFromString", "writePlistToString",
"readPlistFromResource", "writePlistToResource",
"Plist", "Data", "Dict"
]
@@ -60,7 +60,7 @@ __all__ = [
import binascii
import datetime
-from io import BytesIO
+from io import StringIO
import re
@@ -69,10 +69,10 @@ def readPlist(pathOrFile):
(readable) file object. Return the unpacked root object (which
usually is a dictionary).
"""
- didOpen = False
+ didOpen = 0
if isinstance(pathOrFile, str):
- pathOrFile = open(pathOrFile, 'rb')
- didOpen = True
+ pathOrFile = open(pathOrFile)
+ didOpen = 1
p = PlistParser()
rootObject = p.parse(pathOrFile)
if didOpen:
@@ -84,10 +84,10 @@ def writePlist(rootObject, pathOrFile):
"""Write 'rootObject' to a .plist file. 'pathOrFile' may either be a
file name or a (writable) file object.
"""
- didOpen = False
+ didOpen = 0
if isinstance(pathOrFile, str):
- pathOrFile = open(pathOrFile, 'wb')
- didOpen = True
+ pathOrFile = open(pathOrFile, "w")
+ didOpen = 1
writer = PlistWriter(pathOrFile)
writer.writeln("<plist version=\"1.0\">")
writer.writeValue(rootObject)
@@ -96,16 +96,16 @@ def writePlist(rootObject, pathOrFile):
pathOrFile.close()
-def readPlistFromBytes(data):
- """Read a plist data from a bytes object. Return the root object.
+def readPlistFromString(data):
+ """Read a plist data from a string. Return the root object.
"""
- return readPlist(BytesIO(data))
+ return readPlist(StringIO(data))
-def writePlistToBytes(rootObject):
- """Return 'rootObject' as a plist-formatted bytes object.
+def writePlistToString(rootObject):
+ """Return 'rootObject' as a plist-formatted string.
"""
- f = BytesIO()
+ f = StringIO()
writePlist(rootObject, f)
return f.getvalue()
@@ -145,6 +145,7 @@ def writePlistToResource(rootObject, path, restype='plst', resid=0):
class DumbXMLWriter:
+
def __init__(self, file, indentLevel=0, indent="\t"):
self.file = file
self.stack = []
@@ -164,19 +165,16 @@ class DumbXMLWriter:
def simpleElement(self, element, value=None):
if value is not None:
- value = _escape(value)
+ value = _escapeAndEncode(value)
self.writeln("<%s>%s</%s>" % (element, value, element))
else:
self.writeln("<%s/>" % element)
def writeln(self, line):
if line:
- # plist has fixed encoding of utf-8
- if isinstance(line, str):
- line = line.encode('utf-8')
- self.file.write(self.indentLevel * self.indent)
- self.file.write(line)
- self.file.write(b'\n')
+ self.file.write(self.indentLevel * self.indent + line + "\n")
+ else:
+ self.file.write("\n")
# Contents should conform to a subset of ISO 8601
@@ -207,7 +205,7 @@ _controlCharPat = re.compile(
r"[\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f"
r"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f]")
-def _escape(text):
+def _escapeAndEncode(text):
m = _controlCharPat.search(text)
if m is not None:
raise ValueError("strings can't contains control characters; "
@@ -217,17 +215,17 @@ def _escape(text):
text = text.replace("&", "&amp;") # escape '&'
text = text.replace("<", "&lt;") # escape '<'
text = text.replace(">", "&gt;") # escape '>'
- return text
+ return text.encode("utf-8") # encode as UTF-8
-PLISTHEADER = b"""\
+PLISTHEADER = """\
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
"""
class PlistWriter(DumbXMLWriter):
- def __init__(self, file, indentLevel=0, indent=b"\t", writeHeader=1):
+ def __init__(self, file, indentLevel=0, indent="\t", writeHeader=1):
if writeHeader:
file.write(PLISTHEADER)
DumbXMLWriter.__init__(self, file, indentLevel, indent)
@@ -260,9 +258,9 @@ class PlistWriter(DumbXMLWriter):
def writeData(self, data):
self.beginElement("data")
self.indentLevel -= 1
- maxlinelength = 76 - len(self.indent.replace(b"\t", b" " * 8) *
+ maxlinelength = 76 - len(self.indent.replace("\t", " " * 8) *
self.indentLevel)
- for line in data.asBase64(maxlinelength).split(b"\n"):
+ for line in data.asBase64(maxlinelength).split("\n"):
if line:
self.writeln(line)
self.indentLevel += 1
@@ -270,7 +268,8 @@ class PlistWriter(DumbXMLWriter):
def writeDict(self, d):
self.beginElement("dict")
- items = sorted(d.items())
+ items = list(d.items())
+ items.sort()
for key, value in items:
if not isinstance(key, str):
raise TypeError("keys must be strings")
@@ -322,7 +321,7 @@ class Dict(_InternalDict):
from warnings import warn
warn("The plistlib.Dict class is deprecated, use builtin dict instead",
PendingDeprecationWarning)
- super().__init__(**kwargs)
+ super(Dict, self).__init__(**kwargs)
class Plist(_InternalDict):
@@ -335,7 +334,7 @@ class Plist(_InternalDict):
from warnings import warn
warn("The Plist class is deprecated, use the readPlist() and "
"writePlist() functions instead", PendingDeprecationWarning)
- super().__init__(**kwargs)
+ super(Plist, self).__init__(**kwargs)
def fromFile(cls, pathOrFile):
"""Deprecated. Use the readPlist() function instead."""
@@ -357,33 +356,31 @@ def _encodeBase64(s, maxlinelength=76):
for i in range(0, len(s), maxbinsize):
chunk = s[i : i + maxbinsize]
pieces.append(binascii.b2a_base64(chunk))
- return b''.join(pieces)
+ return "".join(pieces)
class Data:
"""Wrapper for binary data."""
def __init__(self, data):
- if not isinstance(data, bytes):
- raise TypeError("data must be as bytes")
self.data = data
- @classmethod
def fromBase64(cls, data):
# base64.decodestring just calls binascii.a2b_base64;
# it seems overkill to use both base64 and binascii.
return cls(binascii.a2b_base64(data))
+ fromBase64 = classmethod(fromBase64)
def asBase64(self, maxlinelength=76):
return _encodeBase64(self.data, maxlinelength)
- def __eq__(self, other):
+ def __cmp__(self, other):
if isinstance(other, self.__class__):
- return self.data == other.data
+ return cmp(self.data, other.data)
elif isinstance(other, str):
- return self.data == other
+ return cmp(self.data, other)
else:
- return id(self) == id(other)
+ return cmp(id(self), id(other))
def __repr__(self):
return "%s(%s)" % (self.__class__.__name__, repr(self.data))
@@ -430,7 +427,11 @@ class PlistParser:
self.stack[-1].append(value)
def getData(self):
- data = ''.join(self.data)
+ data = "".join(self.data)
+ try:
+ data = data.encode("ascii")
+ except UnicodeError:
+ pass
self.data = []
return data
@@ -464,6 +465,6 @@ class PlistParser:
def end_string(self):
self.addObject(self.getData())
def end_data(self):
- self.addObject(Data.fromBase64(self.getData().encode("utf-8")))
+ self.addObject(Data.fromBase64(self.getData()))
def end_date(self):
self.addObject(_dateFromString(self.getData()))
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 2a1e98f..d5fb91b 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -27,7 +27,7 @@ to a file named "<name>.html".
Module docs for core modules are assumed to be in
- http://www.python.org/doc/current/lib/
+ http://docs.python.org/library/
This can be overridden by setting the PYTHONDOCS environment variable
to a different URL or to a local directory containing the Library
@@ -341,7 +341,7 @@ class Doc:
file = '(built-in)'
docloc = os.environ.get("PYTHONDOCS",
- "http://www.python.org/doc/current/lib")
+ "http://docs.python.org/library")
basedir = os.path.join(sys.exec_prefix, "lib",
"python"+sys.version[0:3])
if (isinstance(object, type(os)) and
@@ -350,11 +350,10 @@ class Doc:
'thread', 'zipimport') or
(file.startswith(basedir) and
not file.startswith(os.path.join(basedir, 'site-packages'))))):
- htmlfile = "module-%s.html" % object.__name__
if docloc.startswith("http://"):
- docloc = "%s/%s" % (docloc.rstrip("/"), htmlfile)
+ docloc = "%s/%s" % (docloc.rstrip("/"), object.__name__)
else:
- docloc = os.path.join(docloc, htmlfile)
+ docloc = os.path.join(docloc, object.__name__ + ".html")
else:
docloc = None
return docloc
@@ -537,7 +536,7 @@ class HTMLDoc(Doc):
url = 'http://www.rfc-editor.org/rfc/rfc%d.txt' % int(rfc)
results.append('<a href="%s">%s</a>' % (url, escape(all)))
elif pep:
- url = 'http://www.python.org/peps/pep-%04d.html' % int(pep)
+ url = 'http://www.python.org/peps/pep-%04d' % int(pep)
results.append('<a href="%s">%s</a>' % (url, escape(all)))
elif text[end:end+1] == '(':
results.append(self.namelink(name, methods, funcs, classes))
@@ -1729,7 +1728,7 @@ has the same effect as typing a particular string at the help> prompt.
Welcome to Python %s! This is the online help utility.
If this is your first time using Python, you should definitely check out
-the tutorial on the Internet at http://www.python.org/doc/tut/.
+the tutorial on the Internet at http://docs.python.org/tutorial/.
Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
diff --git a/Lib/re.py b/Lib/re.py
index 1e0c468..91b119c 100644
--- a/Lib/re.py
+++ b/Lib/re.py
@@ -29,7 +29,8 @@ concatenate ordinary characters, so last matches the string 'last'.
The special characters are:
"." Matches any character except a newline.
"^" Matches the start of the string.
- "$" Matches the end of the string.
+ "$" Matches the end of the string or just before the newline at
+ the end of the string.
"*" Matches 0 or more (greedy) repetitions of the preceding RE.
Greedy means that it will match as many repetitions as possible.
"+" Matches 1 or more (greedy) repetitions of the preceding RE.
@@ -83,8 +84,10 @@ This module exports the following functions:
Some of the functions in this module takes flags as optional parameters:
I IGNORECASE Perform case-insensitive matching.
L LOCALE Make \w, \W, \b, \B, dependent on the current locale.
- M MULTILINE "^" matches the beginning of lines as well as the string.
- "$" matches the end of lines as well as the string.
+ M MULTILINE "^" matches the beginning of lines (after a newline)
+ as well as the string.
+ "$" matches the end of lines (before a newline) as well
+ as the end of the string.
S DOTALL "." matches any character at all, including the newline.
X VERBOSE Ignore whitespace and comments for nicer looking RE's.
U UNICODE Make \w, \W, \b, \B, dependent on the Unicode locale.
diff --git a/Lib/test/test_pep263.py b/Lib/test/test_pep263.py
index dd13558..cacf1d6 100644
--- a/Lib/test/test_pep263.py
+++ b/Lib/test/test_pep263.py
@@ -16,6 +16,14 @@ class PEP263Test(unittest.TestCase):
b'\\\xd0\x9f'
)
+ def test_compilestring(self):
+ # see #1882
+ c = compile("\n# coding: utf-8\nu = '\xc3\xb3'\n", "dummy", "exec")
+ d = {}
+ exec(c, d)
+ self.assertEqual(d['u'], '\xf3')
+
+
def test_main():
test_support.run_unittest(PEP263Test)
diff --git a/Lib/urlparse.py b/Lib/urlparse.py
index 0c05dfe..30de699 100644
--- a/Lib/urlparse.py
+++ b/Lib/urlparse.py
@@ -305,9 +305,7 @@ def test():
else:
from io import StringIO
fp = StringIO(test_input)
- while 1:
- line = fp.readline()
- if not line: break
+ for line in fp:
words = line.split()
if not words:
continue