Rev 3536: (jam) Use lazy importing for bzrlib.smart.medium, in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Sun Jul 13 18:01:36 BST 2008
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 3536
revision-id:pqm at pqm.ubuntu.com-20080713170123-90yv7a7n8hqp4yjr
parent: pqm at pqm.ubuntu.com-20080709135859-wq3r1d1fjcafelgw
parent: john at arbash-meinel.com-20080713164514-egymxjcqijpo1sqt
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sun 2008-07-13 18:01:23 +0100
message:
(jam) Use lazy importing for bzrlib.smart.medium,
helps remove dependencies that aren't used
modified:
bzrlib/smart/medium.py medium.py-20061103051856-rgu2huy59fkz902q-1
------------------------------------------------------------
revno: 3530.1.2
revision-id:john at arbash-meinel.com-20080713164514-egymxjcqijpo1sqt
parent: john at arbash-meinel.com-20080712180848-34lm6j0zthd8k3t9
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: lazy_medium
timestamp: Sun 2008-07-13 11:45:14 -0500
message:
missed one of the imports
modified:
bzrlib/smart/medium.py medium.py-20061103051856-rgu2huy59fkz902q-1
------------------------------------------------------------
revno: 3530.1.1
revision-id:john at arbash-meinel.com-20080712180848-34lm6j0zthd8k3t9
parent: pqm at pqm.ubuntu.com-20080707230506-82h5w03vc72dyf1a
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: lazy_medium
timestamp: Sat 2008-07-12 13:08:48 -0500
message:
Make bzrlib.smart use lazy imports.
It saves us an import of ssh.py that we aren't using, which
on windows saves us an import of paramiko, which saves us from
creating a Crypto.util.randompool.RandomPool, which spends
1.5s measuring the delta between ticks of time.time()
Mostly, this just means when you run a single test, it takes 100ms,
rather than 1.5s of setup time, to spend 100ms running the actual
test.
modified:
bzrlib/smart/medium.py medium.py-20061103051856-rgu2huy59fkz902q-1
=== modified file 'bzrlib/smart/medium.py'
--- a/bzrlib/smart/medium.py 2008-06-25 05:21:31 +0000
+++ b/bzrlib/smart/medium.py 2008-07-13 16:45:14 +0000
@@ -29,21 +29,17 @@
import sys
import urllib
+from bzrlib.lazy_import import lazy_import
+lazy_import(globals(), """
from bzrlib import (
errors,
osutils,
symbol_versioning,
urlutils,
)
-from bzrlib.smart.protocol import (
- MESSAGE_VERSION_THREE,
- REQUEST_VERSION_TWO,
- SmartClientRequestProtocolOne,
- SmartServerRequestProtocolOne,
- SmartServerRequestProtocolTwo,
- build_server_protocol_three
- )
+from bzrlib.smart import protocol
from bzrlib.transport import ssh
+""")
def _get_protocol_factory_for_bytes(bytes):
@@ -67,14 +63,14 @@
root_client_path. unused_bytes are any bytes that were not part of a
protocol version marker.
"""
- if bytes.startswith(MESSAGE_VERSION_THREE):
- protocol_factory = build_server_protocol_three
- bytes = bytes[len(MESSAGE_VERSION_THREE):]
- elif bytes.startswith(REQUEST_VERSION_TWO):
- protocol_factory = SmartServerRequestProtocolTwo
- bytes = bytes[len(REQUEST_VERSION_TWO):]
+ if bytes.startswith(protocol.MESSAGE_VERSION_THREE):
+ protocol_factory = protocol.build_server_protocol_three
+ bytes = bytes[len(protocol.MESSAGE_VERSION_THREE):]
+ elif bytes.startswith(protocol.REQUEST_VERSION_TWO):
+ protocol_factory = protocol.SmartServerRequestProtocolTwo
+ bytes = bytes[len(protocol.REQUEST_VERSION_TWO):]
else:
- protocol_factory = SmartServerRequestProtocolOne
+ protocol_factory = protocol.SmartServerRequestProtocolOne
return protocol_factory, bytes
@@ -489,7 +485,7 @@
medium_request = self.get_request()
# Send a 'hello' request in protocol version one, for maximum
# backwards compatibility.
- client_protocol = SmartClientRequestProtocolOne(medium_request)
+ client_protocol = protocol.SmartClientRequestProtocolOne(medium_request)
client_protocol.query_version()
self._done_hello = True
except errors.SmartProtocolError, e:
More information about the bazaar-commits
mailing list