Rev 6385: (jelmer) Only allow absolute imports using lazy_import. (Jelmer Vernooij) in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
Patch Queue Manager
pqm at pqm.ubuntu.com
Mon Dec 19 13:30:31 UTC 2011
At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 6385 [merge]
revision-id: pqm at pqm.ubuntu.com-20111219133031-97tc08321g9zz6dd
parent: pqm at pqm.ubuntu.com-20111219111738-g3ldsov4alx2jalx
parent: jelmer at canonical.com-20111219130430-tevx6nq9x2mpikew
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2011-12-19 13:30:31 +0000
message:
(jelmer) Only allow absolute imports using lazy_import. (Jelmer Vernooij)
modified:
bzrlib/ignores.py ignores.py-20060712153832-2von9l0t7p43ixsv-1
bzrlib/lazy_import.py lazy_import.py-20060910203832-f77c54gf3n232za0-1
bzrlib/tests/test_lazy_import.py test_lazy_import.py-20060910203832-f77c54gf3n232za0-2
doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/ignores.py'
--- a/bzrlib/ignores.py 2011-04-07 10:36:24 +0000
+++ b/bzrlib/ignores.py 2011-12-19 13:04:30 +0000
@@ -27,9 +27,8 @@
atomicfile,
config,
globbing,
+ trace,
)
-
-from trace import warning
""")
# ~/.bazaar/ignore will be filled out using
@@ -72,7 +71,8 @@
unicode_lines.append(line.decode('utf-8'))
except UnicodeDecodeError:
# report error about line (idx+1)
- warning('.bzrignore: On Line #%d, malformed utf8 character. '
+ trace.warning(
+ '.bzrignore: On Line #%d, malformed utf8 character. '
'Ignoring line.' % (line_number+1))
# Append each line to ignore list if it's not a comment line
=== modified file 'bzrlib/lazy_import.py'
--- a/bzrlib/lazy_import.py 2011-08-19 18:02:37 +0000
+++ b/bzrlib/lazy_import.py 2011-12-12 13:26:48 +0000
@@ -208,10 +208,10 @@
module_path = object.__getattribute__(self, '_module_path')
module_python_path = '.'.join(module_path)
if member is not None:
- module = __import__(module_python_path, scope, scope, [member])
+ module = __import__(module_python_path, scope, scope, [member], level=0)
return getattr(module, member)
else:
- module = __import__(module_python_path, scope, scope, [])
+ module = __import__(module_python_path, scope, scope, [], level=0)
for path in module_path[1:]:
module = getattr(module, path)
=== modified file 'bzrlib/tests/test_lazy_import.py'
--- a/bzrlib/tests/test_lazy_import.py 2011-08-19 18:19:31 +0000
+++ b/bzrlib/tests/test_lazy_import.py 2011-12-19 12:14:20 +0000
@@ -483,9 +483,9 @@
self.addCleanup(sys.path.remove, base_path)
original_import = __import__
- def instrumented_import(mod, scope1, scope2, fromlist):
- self.actions.append(('import', mod, fromlist))
- return original_import(mod, scope1, scope2, fromlist)
+ def instrumented_import(mod, scope1, scope2, fromlist, level):
+ self.actions.append(('import', mod, fromlist, level))
+ return original_import(mod, scope1, scope2, fromlist, level)
def cleanup():
__builtins__['__import__'] = original_import
self.addCleanup(cleanup)
@@ -561,18 +561,18 @@
"""Test that a real import of these modules works"""
sub_mod_path = '.'.join([self.root_name, self.sub_name,
self.submoda_name])
- root = __import__(sub_mod_path, globals(), locals(), [])
+ root = __import__(sub_mod_path, globals(), locals(), [], 0)
self.assertEqual(1, root.var1)
self.assertEqual(3, getattr(root, self.sub_name).var3)
self.assertEqual(4, getattr(getattr(root, self.sub_name),
self.submoda_name).var4)
mod_path = '.'.join([self.root_name, self.mod_name])
- root = __import__(mod_path, globals(), locals(), [])
+ root = __import__(mod_path, globals(), locals(), [], 0)
self.assertEqual(2, getattr(root, self.mod_name).var2)
- self.assertEqual([('import', sub_mod_path, []),
- ('import', mod_path, []),
+ self.assertEqual([('import', sub_mod_path, [], 0),
+ ('import', mod_path, [], 0),
], self.actions)
@@ -601,7 +601,7 @@
self.assertEqual([('__getattribute__', 'var1'),
'_replace',
('_import', 'root1'),
- ('import', self.root_name, []),
+ ('import', self.root_name, [], 0),
], self.actions)
def test_import_mod(self):
@@ -627,7 +627,7 @@
self.assertEqual([('__getattribute__', 'var2'),
'_replace',
('_import', 'mod1'),
- ('import', mod_path, []),
+ ('import', mod_path, [], 0),
], self.actions)
def test_import_mod_from_root(self):
@@ -652,7 +652,7 @@
self.assertEqual([('__getattribute__', 'var2'),
'_replace',
('_import', 'mod2'),
- ('import', self.root_name, [self.mod_name]),
+ ('import', self.root_name, [self.mod_name], 0),
], self.actions)
def test_import_root_and_mod(self):
@@ -685,11 +685,11 @@
self.assertEqual([('__getattribute__', 'var1'),
'_replace',
('_import', 'root3'),
- ('import', self.root_name, []),
+ ('import', self.root_name, [], 0),
('__getattribute__', 'var2'),
'_replace',
('_import', 'mod3'),
- ('import', mod_path, []),
+ ('import', mod_path, [], 0),
], self.actions)
def test_import_root_and_root_mod(self):
@@ -729,11 +729,11 @@
self.assertEqual([('__getattribute__', 'mod4'),
'_replace',
('_import', 'root4'),
- ('import', self.root_name, []),
+ ('import', self.root_name, [], 0),
('__getattribute__', 'var2'),
'_replace',
('_import', 'mod4'),
- ('import', mod_path, []),
+ ('import', mod_path, [], 0),
], self.actions)
def test_import_root_sub_submod(self):
@@ -794,23 +794,23 @@
self.assertEqual([('__getattribute__', 'mod5'),
'_replace',
('_import', 'root5'),
- ('import', self.root_name, []),
+ ('import', self.root_name, [], 0),
('__getattribute__', 'submoda5'),
'_replace',
('_import', 'sub5'),
- ('import', sub_path, []),
+ ('import', sub_path, [], 0),
('__getattribute__', 'var2'),
'_replace',
('_import', 'mod5'),
- ('import', mod_path, []),
+ ('import', mod_path, [], 0),
('__getattribute__', 'var4'),
'_replace',
('_import', 'submoda5'),
- ('import', submoda_path, []),
+ ('import', submoda_path, [], 0),
('__getattribute__', 'var5'),
'_replace',
('_import', 'submodb5'),
- ('import', submodb_path, []),
+ ('import', submodb_path, [], 0),
], self.actions)
@@ -1106,7 +1106,7 @@
self.assertEqual([('__getattribute__', 'var1'),
'_replace',
('_import', 'root6'),
- ('import', self.root_name, []),
+ ('import', self.root_name, [], 0),
], self.actions)
def test_import_deep(self):
@@ -1142,7 +1142,7 @@
self.assertEqual([('__getattribute__', 'var4'),
'_replace',
('_import', 'submoda7'),
- ('import', submoda_path, []),
+ ('import', submoda_path, [], 0),
], self.actions)
def test_lazy_import(self):
@@ -1167,7 +1167,7 @@
self.assertEqual([('__getattribute__', 'var1'),
'_replace',
('_import', 'root8'),
- ('import', self.root_name, []),
+ ('import', self.root_name, [], 0),
], self.actions)
=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt 2011-12-19 11:17:38 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt 2011-12-19 12:09:27 +0000
@@ -102,16 +102,23 @@
.. Major internal changes, unlikely to be visible to users or plugin
developers, but interesting for bzr developers.
+* ``bzrlib.urlutils`` now includes ``quote`` and ``unquote`` functions,
+ rather than importing them from ``urllib``. This prevents loading
+ of the ``socket``, ``ssl`` and ``urllib`` modules for
+ local bzr operations. (Jelmer Vernooij)
+
* ControlDir now has a get_branches method that returns a dictionary
whose keys are the names of the branches and whose values are the
branches themselves. The active branch uses the key None.
(Neil Martinsen-Burrell)
+* Helper ``osutils.path_from_environ`` added for extracting a unicode path
+ from an environment variable. (Martin Packman, #832028)
+
* Helper ``win32utils.get_environ_unicode`` added for avoiding encoding
problems with ``os.environ.get`` use. (Martin Packman, #262874)
-* Helper ``osutils.path_from_environ`` added for extracting a unicode path
- from an environment variable. (Martin Packman, #832028)
+* Lazy imports can now only be absolute. (Jelmer Vernooij)
* New HPSS call ``BzrDir.checkout_metadir``. (Jelmer Vernooij, #894459)
@@ -119,11 +126,6 @@
speeding up various commands including ``bzr export``,
``bzr checkout`` and ``bzr cat``. (Jelmer Vernooij, #608640)
-* ``bzrlib.urlutils`` now includes ``quote`` and ``unquote`` functions,
- rather than importing them from ``urllib``. This prevents loading
- of the ``socket``, ``ssl`` and ``urllib`` modules for
- local bzr operations. (Jelmer Vernooij)
-
Testing
*******
More information about the bazaar-commits
mailing list