summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3/fixes
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-10-04 21:04:36 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-10-04 21:04:36 (GMT)
commit7d8d9a588c497c627b62bd7fa79bc6fef693aa5f (patch)
treedf45abc91f72533df3891c7ab4087dde67ba2f82 /Lib/lib2to3/fixes
parentb76a2b130584fefa0baa852fef0f572b21cf3039 (diff)
downloadcpython-7d8d9a588c497c627b62bd7fa79bc6fef693aa5f.zip
cpython-7d8d9a588c497c627b62bd7fa79bc6fef693aa5f.tar.gz
cpython-7d8d9a588c497c627b62bd7fa79bc6fef693aa5f.tar.bz2
Merged revisions 66797 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ................ r66797 | benjamin.peterson | 2008-10-04 15:55:50 -0500 (Sat, 04 Oct 2008) | 19 lines Merged revisions 66707,66775,66782 via svnmerge from svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r66707 | benjamin.peterson | 2008-09-30 18:27:10 -0500 (Tue, 30 Sep 2008) | 1 line fix #4001: fix_imports didn't check for __init__.py before converting to relative imports ........ r66775 | collin.winter | 2008-10-03 12:08:26 -0500 (Fri, 03 Oct 2008) | 4 lines Add an alternative iterative pattern matching system that, while slower, correctly parses files that cause the faster recursive pattern matcher to fail with a recursion error. lib2to3 falls back to the iterative matcher if the recursive one fails. Fixes http://bugs.python.org/issue2532. Thanks to Nick Edds. ........ r66782 | benjamin.peterson | 2008-10-03 17:51:36 -0500 (Fri, 03 Oct 2008) | 1 line add Victor Stinner's fixer for os.getcwdu -> os.getcwd #4023 ........ ................
Diffstat (limited to 'Lib/lib2to3/fixes')
-rw-r--r--Lib/lib2to3/fixes/fix_getcwdu.py18
-rw-r--r--Lib/lib2to3/fixes/fix_import.py4
2 files changed, 22 insertions, 0 deletions
diff --git a/Lib/lib2to3/fixes/fix_getcwdu.py b/Lib/lib2to3/fixes/fix_getcwdu.py
new file mode 100644
index 0000000..1175e56
--- /dev/null
+++ b/Lib/lib2to3/fixes/fix_getcwdu.py
@@ -0,0 +1,18 @@
+"""
+Fixer that changes os.getcwdu() to os.getcwd().
+"""
+# Author: Victor Stinner
+
+# Local imports
+from .. import fixer_base
+from ..fixer_util import Name
+
+class FixGetcwdu(fixer_base.BaseFix):
+
+ PATTERN = """
+ power< 'os' trailer< dot='.' name='getcwdu' > any* >
+ """
+
+ def transform(self, node, results):
+ name = results["name"]
+ name.replace(Name("getcwd", prefix=name.get_prefix()))
diff --git a/Lib/lib2to3/fixes/fix_import.py b/Lib/lib2to3/fixes/fix_import.py
index 5612ba6..edd0f42 100644
--- a/Lib/lib2to3/fixes/fix_import.py
+++ b/Lib/lib2to3/fixes/fix_import.py
@@ -54,6 +54,10 @@ def probably_a_local_import(imp_name, file_path):
imp_name = imp_name.split('.', 1)[0].strip()
base_path = dirname(file_path)
base_path = join(base_path, imp_name)
+ # If there is no __init__.py next to the file its not in a package
+ # so can't be a relative import.
+ if not exists(join(dirname(base_path), '__init__.py')):
+ return False
for ext in ['.py', pathsep, '.pyc', '.so', '.sl', '.pyd']:
if exists(base_path + ext):
return True