# Bazaar revision bundle v0.8 # # message: # remove usage of hasattr # committer: Robey Pointer # date: Sat 2006-09-02 17:13:54.339999914 -0700 === modified file bzrlib/branch.py // last-changed:robey@lag.net-20060902222155 ... -1d1ed3d3c31120ee --- bzrlib/branch.py +++ bzrlib/branch.py @@ -138,13 +138,14 @@ """ return bzrdir.BzrDir.create_standalone_workingtree(base).branch + @deprecated_function(zero_eight) def setup_caching(self, cache_root): """Subclasses that care about caching should override this, and set up cached stores located under cache_root. + + NOTE: This is unused. """ - # seems to be unused, 2006-01-13 mbp - warn('%s is deprecated' % self.setup_caching) - self.cache_root = cache_root + pass def get_config(self): return bzrlib.config.BranchConfig(self) @@ -958,21 +959,6 @@ __repr__ = __str__ - def __del__(self): - # TODO: It might be best to do this somewhere else, - # but it is nice for a Branch object to automatically - # cache it's information. - # Alternatively, we could have the Transport objects cache requests - # See the earlier discussion about how major objects (like Branch) - # should never expect their __del__ function to run. - # XXX: cache_root seems to be unused, 2006-01-13 mbp - if hasattr(self, 'cache_root') and self.cache_root is not None: - try: - osutils.rmtree(self.cache_root) - except: - pass - self.cache_root = None - def _get_base(self): return self._base === modified file bzrlib/builtins.py --- bzrlib/builtins.py +++ bzrlib/builtins.py @@ -2479,12 +2479,12 @@ import bzrlib.plugin from inspect import getdoc for name, plugin in bzrlib.plugin.all_plugins().items(): - if hasattr(plugin, '__path__'): + if getattr(plugin, '__path__', None) != None: print plugin.__path__[0] - elif hasattr(plugin, '__file__'): + elif getattr(plugin, '__file__', None) != None: print plugin.__file__ else: - print `plugin` + print repr(plugin) d = getdoc(plugin) if d: === modified file bzrlib/bundle/bundle_data.py --- bzrlib/bundle/bundle_data.py +++ bzrlib/bundle/bundle_data.py @@ -539,7 +539,7 @@ return None if old_path in self.deleted: return None - if hasattr(self.base_tree, 'path2id'): + if getattr(self.base_tree, 'path2id', None) != None: return self.base_tree.path2id(old_path) else: return self.base_tree.inventory.path2id(old_path) === modified file bzrlib/bundle/serializer/__init__.py --- bzrlib/bundle/serializer/__init__.py +++ bzrlib/bundle/serializer/__init__.py @@ -37,9 +37,7 @@ def _get_filename(f): - if hasattr(f, 'name'): - return f.name - return '' + return getattr(f, 'name', '') def read_bundle(f): === modified file bzrlib/bundle/serializer/v08.py --- bzrlib/bundle/serializer/v08.py +++ bzrlib/bundle/serializer/v08.py @@ -411,7 +411,7 @@ return revision_info = self.info.revisions[-1] - if hasattr(revision_info, key): + if key in revision_info.__dict__: if getattr(revision_info, key) is None: setattr(revision_info, key, value) else: === modified file bzrlib/bzrdir.py --- bzrlib/bzrdir.py +++ bzrlib/bzrdir.py @@ -1566,7 +1566,7 @@ entries = inv.iter_entries() entries.next() for path, ie in entries: - assert hasattr(ie, 'revision'), \ + assert getattr(ie, 'revision', None) != None, \ 'no revision on {%s} in {%s}' % \ (file_id, rev.revision_id) new_inv_xml = bzrlib.xml5.serializer_v5.write_inventory_to_string(inv) === modified file bzrlib/commands.py --- bzrlib/commands.py +++ bzrlib/commands.py @@ -585,7 +585,7 @@ sys.stdout.flush() return result except IOError, e: - if not hasattr(e, 'errno'): + if getattr(e, 'errno', None) == None: raise if e.errno != errno.EPIPE: # Win32 raises IOError with errno=0 on a broken pipe === modified file bzrlib/lsprof.py --- bzrlib/lsprof.py +++ bzrlib/lsprof.py @@ -165,7 +165,7 @@ for k, v in sys.modules.items(): if v is None: continue - if not hasattr(v, '__file__'): + if getattr(v, '__file__', None) == None: continue if not isinstance(v.__file__, str): continue === modified file bzrlib/osutils.py --- bzrlib/osutils.py +++ bzrlib/osutils.py @@ -150,7 +150,7 @@ if lexists is None: def lexists(f): try: - if hasattr(os, 'lstat'): + if getattr(os, 'lstat') != None: os.lstat(f) else: os.stat(f) @@ -195,7 +195,7 @@ if e.errno not in (None, errno.ENOENT, errno.ENOTDIR): raise except Exception, e: - if (not hasattr(e, 'errno') + if (getattr(e, 'errno', None) == None or e.errno not in (errno.ENOENT, errno.ENOTDIR)): raise else: @@ -370,7 +370,7 @@ def normalizepath(f): - if hasattr(os.path, 'realpath'): + if getattr(os.path, 'realpath', None) != None: F = realpath else: F = abspath @@ -505,7 +505,7 @@ def sha_file(f): - if hasattr(f, 'tell'): + if getattr(f, 'tell', None) != None: assert f.tell() == 0 s = sha.new() BUFSIZE = 128<<10 @@ -726,7 +726,7 @@ def has_symlinks(): - if hasattr(os, 'symlink'): + if getattr(os, 'symlink', None) != None: return True else: return False === modified file bzrlib/store/__init__.py --- bzrlib/store/__init__.py +++ bzrlib/store/__init__.py @@ -87,7 +87,7 @@ def listable(self): """Return True if this store is able to be listed.""" - return hasattr(self, "__iter__") + return (getattr(self, "__iter__", None) != None) def copy_all_ids(self, store_from, pb=None): """Copy all the file ids from store_from into self.""" === modified file bzrlib/store/text.py --- bzrlib/store/text.py +++ bzrlib/store/text.py @@ -114,7 +114,7 @@ # gzip.GzipFile.read() requires a tell() function # but some transports return objects that cannot seek # so buffer them in a StringIO instead - if hasattr(f, 'tell'): + if getattr(f, 'tell', None) != None: return gzip.GzipFile(mode='rb', fileobj=f) else: from cStringIO import StringIO === modified file bzrlib/tests/stub_sftp.py --- bzrlib/tests/stub_sftp.py +++ bzrlib/tests/stub_sftp.py @@ -153,8 +153,7 @@ def open(self, path, flags, attr): path = self._realpath(path) try: - if hasattr(os, 'O_BINARY'): - flags |= os.O_BINARY + flags |= getattr(os, 'O_BINARY', 0) if getattr(attr, 'st_mode', None): fd = os.open(path, flags, attr.st_mode) else: === modified file bzrlib/tests/test_bad_files.py --- bzrlib/tests/test_bad_files.py +++ bzrlib/tests/test_bad_files.py @@ -58,7 +58,7 @@ # put some bogus stuff in the tree # We can only continue if we have mkfifo - if not hasattr(os, 'mkfifo'): + if getattr(os, 'mkfifo', None) == None: # TODO: Ultimately this should be TestSkipped # or PlatformDeficiency return === modified file bzrlib/tests/test_hashcache.py --- bzrlib/tests/test_hashcache.py +++ bzrlib/tests/test_hashcache.py @@ -112,7 +112,7 @@ def test_hashcache_raise(self): """check that hashcache can raise BzrError""" hc = self.make_hashcache() - if not hasattr(os, 'mkfifo'): + if getattr(os, 'mkfifo', None) == None: raise TestSkipped('filesystem fifos not supported on this system') os.mkfifo('a') # It's possible that the system supports fifos but the filesystem === modified file bzrlib/tests/test_transport_implementations.py --- bzrlib/tests/test_transport_implementations.py +++ bzrlib/tests/test_transport_implementations.py @@ -67,8 +67,10 @@ except excClass: return else: - if hasattr(excClass,'__name__'): excName = excClass.__name__ - else: excName = str(excClass) + if getattr(excClass,'__name__', None) != None: + excName = excClass.__name__ + else: + excName = str(excClass) raise self.failureException, "%s not raised" % excName def test_has(self): === modified file bzrlib/trace.py --- bzrlib/trace.py +++ bzrlib/trace.py @@ -93,7 +93,7 @@ def mutter(fmt, *args): if _trace_file is None: return - if hasattr(_trace_file, 'closed') and _trace_file.closed: + if (getattr(_trace_file, 'closed', None) != None) and _trace_file.closed: return if isinstance(fmt, unicode): === modified file bzrlib/transport/__init__.py --- bzrlib/transport/__init__.py +++ bzrlib/transport/__init__.py @@ -211,7 +211,7 @@ This handles things like ENOENT, ENOTDIR, EEXIST, and EACCESS """ - if hasattr(e, 'errno'): + if getattr(e, 'errno', None) != None: if e.errno in (errno.ENOENT, errno.ENOTDIR): raise errors.NoSuchFile(path, extra=e) # I would rather use errno.EFOO, but there doesn't seem to be @@ -882,7 +882,7 @@ def get_transport_test_permutations(self, module): """Get the permutations module wants to have tested.""" - if not hasattr(module, 'get_test_permutations'): + if getattr(module, 'get_test_permutations', None) == None: warning("transport module %s doesn't provide get_test_permutations()" % module.__name__) return [] === modified file bzrlib/transport/ftp.py --- bzrlib/transport/ftp.py +++ bzrlib/transport/ftp.py @@ -307,7 +307,7 @@ abspath = self._abspath(relpath) tmp_abspath = '%s.tmp.%.9f.%d.%d' % (abspath, time.time(), os.getpid(), random.randint(0,0x7FFFFFFF)) - if not hasattr(fp, 'read'): + if getattr(fp, 'read', None) == None: fp = StringIO(fp) try: mutter("FTP put: %s", abspath) === modified file bzrlib/transport/http/__init__.py --- bzrlib/transport/http/__init__.py +++ bzrlib/transport/http/__init__.py @@ -446,7 +446,7 @@ if not self.parse_request(): # An error code has been sent, just exit return mname = 'do_' + self.command - if not hasattr(self, mname): + if getattr(self, mname, None) == None: self.send_error(501, "Unsupported method (%r)" % self.command) return method = getattr(self, mname) === modified file bzrlib/transport/http/_urllib.py --- bzrlib/transport/http/_urllib.py +++ bzrlib/transport/http/_urllib.py @@ -67,7 +67,7 @@ raise NoSuchFile(path, extra=e) raise except (BzrError, IOError), e: - if hasattr(e, 'errno'): + if getattr(e, 'errno', None) != None: mutter('io error: %s %s for has url: %r', e.errno, errno.errorcode.get(e.errno), path) if e.errno == errno.ENOENT: === modified file bzrlib/transport/sftp.py --- bzrlib/transport/sftp.py +++ bzrlib/transport/sftp.py @@ -648,7 +648,7 @@ """ # paramiko seems to generate detailless errors. self._translate_error(e, path, raise_generic=False) - if hasattr(e, 'args'): + if getattr(e, 'args', None) != None: if (e.args == ('No such file or directory',) or e.args == ('No such file',)): raise NoSuchFile(path, str(e) + more_info) @@ -658,7 +658,7 @@ if (e.args == ('Failure',)): raise failure_exc(path, str(e) + more_info) mutter('Raising exception with args %s', e.args) - if hasattr(e, 'errno'): + if getattr(e, 'errno', None) != None: mutter('Raising exception with errno %s', e.errno) raise e === modified file bzrlib/util/configobj/configobj.py --- bzrlib/util/configobj/configobj.py +++ bzrlib/util/configobj/configobj.py @@ -1024,7 +1024,7 @@ else: self.configspec = None return - elif hasattr(infile, 'read'): + elif getattr(infile, 'read', None) != None: # This supports file like objects infile = infile.read() or [] # needs splitting into lines - but needs doing *after* decoding === modified file bzrlib/util/elementtree/ElementTree.py --- bzrlib/util/elementtree/ElementTree.py +++ bzrlib/util/elementtree/ElementTree.py @@ -572,7 +572,7 @@ # @defreturn Element def parse(self, source, parser=None): - if not hasattr(source, "read"): + if getattr(source, "read", None) == None: source = open(source, "rb") if not parser: parser = XMLTreeBuilder() @@ -651,7 +651,7 @@ def write(self, file, encoding="us-ascii"): assert self._root is not None - if not hasattr(file, "write"): + if getattr(file, "write", None) == None: file = open(file, "wb") if not encoding: encoding = "us-ascii" @@ -723,7 +723,7 @@ def iselement(element): # FIXME: not sure about this; might be a better idea to look # for tag/attrib/text attributes - return isinstance(element, _ElementInterface) or hasattr(element, "tag") + return isinstance(element, _ElementInterface) or (getattr(element, "tag", None) != None) ## # Writes an element tree or element structure to sys.stdout. This @@ -871,7 +871,7 @@ class iterparse: def __init__(self, source, events=None): - if not hasattr(source, "read"): + if getattr(source, "read", None) == None: source = open(source, "rb") self._file = source self._events = [] === modified file setup.py --- setup.py +++ setup.py @@ -58,7 +58,7 @@ print >>sys.stderr, "bzr: error: cannot find a suitable python interpreter" print >>sys.stderr, " (need %d.%d or later)" % NEED_VERS sys.exit(1) -if hasattr(os, "unsetenv"): +if getattr(os, "unsetenv", None) != None: os.unsetenv(REINVOKE) # revision id: robey@lag.net-20060903001354-1f596a529c9c4934 # sha1: 31624143f7b0de3a6c7a5a0260709b5fa96b3e62 # inventory sha1: e806d68141040d0d72e939e0f6d6abc0729ef242 # parent ids: # robey@lag.net-20060902222155-1d1ed3d3c31120ee # base id: robey@lag.net-20060830022017-53f9005cacd0b1e2 # properties: # branch-nick: bzr.dev.no_has_key # message: # be explicit about the deprecation of setup_caching and remove no-op destructor # committer: Robey Pointer # date: Sat 2006-09-02 15:21:55.171999931 -0700 === modified file bzrlib/branch.py // encoding:base64 LS0tIGJ6cmxpYi9icmFuY2gucHkKKysrIGJ6cmxpYi9icmFuY2gucHkKQEAgLTEzOCwxMyArMTM4 LDE0IEBACiAgICAgICAgICIiIgogICAgICAgICByZXR1cm4gYnpyZGlyLkJ6ckRpci5jcmVhdGVf c3RhbmRhbG9uZV93b3JraW5ndHJlZShiYXNlKS5icmFuY2gKIAorICAgIEBkZXByZWNhdGVkX2Z1 bmN0aW9uKHplcm9fZWlnaHQpCiAgICAgZGVmIHNldHVwX2NhY2hpbmcoc2VsZiwgY2FjaGVfcm9v dCk6CiAgICAgICAgICIiIlN1YmNsYXNzZXMgdGhhdCBjYXJlI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Ci0gICAgICAgICMgWFhYOiBjYWNoZV9yb290IHNlZW1zIHRvIGJlIHVudXNlZCwg MjAwNi0wMS0xMyBtYnAKLSAgICAgICAgaWYgaGFzYXR0cihzZWxmLCAnY2FjaGVfcm9vdCcpIGFu ZCBzZWxmLmNhY2hlX3Jvb3QgaXMgbm90IE5vbmU6Ci0gICAgICAgICAgICB0cnk6Ci0gICAgICAg ICAgICAgICAgb3N1dGlscy5ybXRyZWUoc2VsZi5jYWNoZV9yb290KQotICAgICAgICAgICAgZXhj ZXB0OgotICAgICAgICAgICAgICAgIHBhc3MKLSAgICAgICAgICAgIHNlbGYuY2FjaGVfcm9vdCA9 IE5vbmUKLQogICAgIGRlZiBfZ2V0X2Jhc2Uoc2VsZik6CiAgICAgICAgIHJldHVybiBzZWxmLl9i YXNlCiAKCg== # revision id: robey@lag.net-20060902222155-1d1ed3d3c31120ee # sha1: cdaba75087d83c02bc58383c097c9b1448ad00d1 # inventory sha1: b081ef3d6c322f6a52b4a6a9a9bb822f2915bf11 # parent ids: # robey@lag.net-20060830022017-53f9005cacd0b1e2 # properties: # branch-nick: bzr.dev.no_has_key