summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/compiler/misc.py4
-rw-r--r--Lib/compiler/pyassem.py6
-rw-r--r--Lib/compiler/symbols.py18
-rw-r--r--Lib/compiler/transformer.py4
-rw-r--r--Lib/compiler/visitor.py2
-rw-r--r--Lib/distutils/ccompiler.py2
-rw-r--r--Lib/lib2to3/main.py3
-rw-r--r--Lib/logging/__init__.py2
-rw-r--r--Lib/test/test_textwrap.py10
-rw-r--r--Lib/test/test_urllib2.py48
-rw-r--r--Lib/textwrap.py14
11 files changed, 84 insertions, 29 deletions
diff --git a/Lib/compiler/misc.py b/Lib/compiler/misc.py
index 8d91770..588c7fb 100644
--- a/Lib/compiler/misc.py
+++ b/Lib/compiler/misc.py
@@ -14,13 +14,13 @@ class Set:
def __len__(self):
return len(self.elts)
def __contains__(self, elt):
- return self.elts.has_key(elt)
+ return elt in self.elts
def add(self, elt):
self.elts[elt] = elt
def elements(self):
return self.elts.keys()
def has_elt(self, elt):
- return self.elts.has_key(elt)
+ return elt in self.elts
def remove(self, elt):
del self.elts[elt]
def copy(self):
diff --git a/Lib/compiler/pyassem.py b/Lib/compiler/pyassem.py
index 893fa64..6efec28 100644
--- a/Lib/compiler/pyassem.py
+++ b/Lib/compiler/pyassem.py
@@ -210,7 +210,7 @@ def dfs_postorder(b, seen):
order = []
seen[b] = b
for c in b.get_children():
- if seen.has_key(c):
+ if c in seen:
continue
order = order + dfs_postorder(c, seen)
order.append(b)
@@ -406,7 +406,7 @@ class PyFlowGraph(FlowGraph):
seen = {}
def max_depth(b, d):
- if seen.has_key(b):
+ if b in seen:
return d
seen[b] = 1
d = d + depth[b]
@@ -482,7 +482,7 @@ class PyFlowGraph(FlowGraph):
for name in self.cellvars:
cells[name] = 1
self.cellvars = [name for name in self.varnames
- if cells.has_key(name)]
+ if name in cells]
for name in self.cellvars:
del cells[name]
self.cellvars = self.cellvars + cells.keys()
diff --git a/Lib/compiler/symbols.py b/Lib/compiler/symbols.py
index 8f62980..0e660ae 100644
--- a/Lib/compiler/symbols.py
+++ b/Lib/compiler/symbols.py
@@ -49,9 +49,9 @@ class Scope:
def add_global(self, name):
name = self.mangle(name)
- if self.uses.has_key(name) or self.defs.has_key(name):
+ if name in self.uses or name in self.defs:
pass # XXX warn about global following def/use
- if self.params.has_key(name):
+ if name in self.params:
raise SyntaxError, "%s in %s is global and parameter" % \
(name, self.name)
self.globals[name] = 1
@@ -88,14 +88,13 @@ class Scope:
The scope of a name could be LOCAL, GLOBAL, FREE, or CELL.
"""
- if self.globals.has_key(name):
+ if name in self.globals:
return SC_GLOBAL
- if self.cells.has_key(name):
+ if name in self.cells:
return SC_CELL
- if self.defs.has_key(name):
+ if name in self.defs:
return SC_LOCAL
- if self.nested and (self.frees.has_key(name) or
- self.uses.has_key(name)):
+ if self.nested and (name in self.frees or name in self.uses):
return SC_FREE
if self.nested:
return SC_UNKNOWN
@@ -108,8 +107,7 @@ class Scope:
free = {}
free.update(self.frees)
for name in self.uses.keys():
- if not (self.defs.has_key(name) or
- self.globals.has_key(name)):
+ if name not in self.defs and name not in self.globals:
free[name] = 1
return free.keys()
@@ -134,7 +132,7 @@ class Scope:
free.
"""
self.globals[name] = 1
- if self.frees.has_key(name):
+ if name in self.frees:
del self.frees[name]
for child in self.children:
if child.check_name(name) == SC_FREE:
diff --git a/Lib/compiler/transformer.py b/Lib/compiler/transformer.py
index eccade3..f5fe582 100644
--- a/Lib/compiler/transformer.py
+++ b/Lib/compiler/transformer.py
@@ -81,7 +81,7 @@ def extractLineNo(ast):
def Node(*args):
kind = args[0]
- if nodes.has_key(kind):
+ if kind in nodes:
try:
return nodes[kind](*args[1:])
except TypeError:
@@ -120,7 +120,7 @@ class Transformer:
def transform(self, tree):
"""Transform an AST into a modified parse tree."""
if not (isinstance(tree, tuple) or isinstance(tree, list)):
- tree = parser.ast2tuple(tree, line_info=1)
+ tree = parser.st2tuple(tree, line_info=1)
return self.compile_node(tree)
def parsesuite(self, text):
diff --git a/Lib/compiler/visitor.py b/Lib/compiler/visitor.py
index 9e39d36..f10f560 100644
--- a/Lib/compiler/visitor.py
+++ b/Lib/compiler/visitor.py
@@ -84,7 +84,7 @@ class ExampleASTVisitor(ASTVisitor):
meth(node, *args)
elif self.VERBOSE > 0:
klass = node.__class__
- if not self.examples.has_key(klass):
+ if klass not in self.examples:
self.examples[klass] = klass
print
print self.visitor
diff --git a/Lib/distutils/ccompiler.py b/Lib/distutils/ccompiler.py
index 0ed9a40..87d6e27 100644
--- a/Lib/distutils/ccompiler.py
+++ b/Lib/distutils/ccompiler.py
@@ -1041,7 +1041,7 @@ main (int argc, char **argv) {
return move_file (src, dst, dry_run=self.dry_run)
def mkpath (self, name, mode=0777):
- mkpath (name, mode, self.dry_run)
+ mkpath (name, mode, dry_run=self.dry_run)
# class CCompiler
diff --git a/Lib/lib2to3/main.py b/Lib/lib2to3/main.py
index a4d148d..0d65a2e 100644
--- a/Lib/lib2to3/main.py
+++ b/Lib/lib2to3/main.py
@@ -40,7 +40,8 @@ class StdoutRefactoringTool(refactor.RefactoringTool):
# Actually write the new file
super(StdoutRefactoringTool, self).write_file(new_text,
filename, old_text)
- shutil.copymode(filename, backup)
+ if not self.nobackups:
+ shutil.copymode(filename, backup)
def print_output(self, lines):
for line in lines:
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 7b790d2..6776500 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -846,7 +846,7 @@ class PlaceHolder:
Add the specified logger as a child of this placeholder.
"""
#if alogger not in self.loggers:
- if not self.loggerMap.has_key(alogger):
+ if alogger not in self.loggerMap:
#self.loggers.append(alogger)
self.loggerMap[alogger] = None
diff --git a/Lib/test/test_textwrap.py b/Lib/test/test_textwrap.py
index 1eab90c..c91e242 100644
--- a/Lib/test/test_textwrap.py
+++ b/Lib/test/test_textwrap.py
@@ -174,7 +174,7 @@ What a mess!
text = ("Python 1.0.0 was released on 1994-01-26. Python 1.0.1 was\n"
"released on 1994-02-15.")
- self.check_wrap(text, 30, ['Python 1.0.0 was released on',
+ self.check_wrap(text, 35, ['Python 1.0.0 was released on',
'1994-01-26. Python 1.0.1 was',
'released on 1994-02-15.'])
self.check_wrap(text, 40, ['Python 1.0.0 was released on 1994-01-26.',
@@ -353,6 +353,14 @@ What a mess!
otext = self.wrapper.fill(text)
assert isinstance(otext, unicode)
+ def test_no_split_at_umlaut(self):
+ text = u"Die Empf\xe4nger-Auswahl"
+ self.check_wrap(text, 13, [u"Die", u"Empf\xe4nger-", u"Auswahl"])
+
+ def test_umlaut_followed_by_dash(self):
+ text = u"aa \xe4\xe4-\xe4\xe4"
+ self.check_wrap(text, 7, [u"aa \xe4\xe4-", u"\xe4\xe4"])
+
def test_split(self):
# Ensure that the standard _split() method works as advertised
# in the comments
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index e28ee71..ff164c2 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -1104,6 +1104,51 @@ class MiscTests(unittest.TestCase):
else:
self.assert_(False)
+class RequestTests(unittest.TestCase):
+
+ def setUp(self):
+ self.get = urllib2.Request("http://www.python.org/~jeremy/")
+ self.post = urllib2.Request("http://www.python.org/~jeremy/",
+ "data",
+ headers={"X-Test": "test"})
+
+ def test_method(self):
+ self.assertEqual("POST", self.post.get_method())
+ self.assertEqual("GET", self.get.get_method())
+
+ def test_add_data(self):
+ self.assert_(not self.get.has_data())
+ self.assertEqual("GET", self.get.get_method())
+ self.get.add_data("spam")
+ self.assert_(self.get.has_data())
+ self.assertEqual("POST", self.get.get_method())
+
+ def test_get_full_url(self):
+ self.assertEqual("http://www.python.org/~jeremy/",
+ self.get.get_full_url())
+
+ def test_selector(self):
+ self.assertEqual("/~jeremy/", self.get.get_selector())
+ req = urllib2.Request("http://www.python.org/")
+ self.assertEqual("/", req.get_selector())
+
+ def test_get_type(self):
+ self.assertEqual("http", self.get.get_type())
+
+ def test_get_host(self):
+ self.assertEqual("www.python.org", self.get.get_host())
+
+ def test_get_host_unquote(self):
+ req = urllib2.Request("http://www.%70ython.org/")
+ self.assertEqual("www.python.org", req.get_host())
+
+ def test_proxy(self):
+ self.assert_(not self.get.has_proxy())
+ self.get.set_proxy("www.perl.org", "http")
+ self.assert_(self.get.has_proxy())
+ self.assertEqual("www.python.org", self.get.get_origin_req_host())
+ self.assertEqual("www.perl.org", self.get.get_host())
+
def test_main(verbose=None):
from test import test_urllib2
@@ -1112,7 +1157,8 @@ def test_main(verbose=None):
tests = (TrivialTests,
OpenerDirectorTests,
HandlerTests,
- MiscTests)
+ MiscTests,
+ RequestTests)
test_support.run_unittest(*tests)
if __name__ == "__main__":
diff --git a/Lib/textwrap.py b/Lib/textwrap.py
index 53f2f1b..192b43b 100644
--- a/Lib/textwrap.py
+++ b/Lib/textwrap.py
@@ -84,16 +84,16 @@ class TextWrapper:
# splits into
# Hello/ /there/ /--/ /you/ /goof-/ball,/ /use/ /the/ /-b/ /option!
# (after stripping out empty strings).
- wordsep_re = re.compile(
+ wordsep_re = (
r'(\s+|' # any whitespace
- r'[^\s\w]*\w+[a-zA-Z]-(?=\w+[a-zA-Z])|' # hyphenated words
+ r'[^\s\w]*\w+[^0-9\W]-(?=\w+[^0-9\W])|' # hyphenated words
r'(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))') # em-dash
# This less funky little regex just split on recognized spaces. E.g.
# "Hello there -- you goof-ball, use the -b option!"
# splits into
# Hello/ /there/ /--/ /you/ /goof-ball,/ /use/ /the/ /-b/ /option!/
- wordsep_simple_re = re.compile(r'(\s+)')
+ wordsep_simple_re = r'(\s+)'
# XXX this is not locale- or charset-aware -- string.lowercase
# is US-ASCII only (and therefore English-only)
@@ -160,10 +160,12 @@ class TextWrapper:
'use', ' ', 'the', ' ', '-b', ' ', option!'
otherwise.
"""
- if self.break_on_hyphens is True:
- chunks = self.wordsep_re.split(text)
+ flags = re.UNICODE if isinstance(text, unicode) else 0
+ if self.break_on_hyphens:
+ pat = self.wordsep_re
else:
- chunks = self.wordsep_simple_re.split(text)
+ pat = self.wordsep_simple_re
+ chunks = re.compile(pat, flags).split(text)
chunks = filter(None, chunks) # remove empty chunks
return chunks