From 73609a0277106a25446514f35cd617a488e9fca9 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Wed, 9 Mar 2011 20:52:30 +0000 Subject: [PATCH] Updated to newer Python syntax where possible These are changes that are needed for Python 3, but which still work on Python 2.5. The command used was: 2to3 -wn -f apply -f future -f has_key -f import -f long -f paren -f reduce -f repr -f sys_exc -f tuple_params zeroinstall 0launch 0store 0alias 0desktop 0store-secure-add 0install --- zeroinstall/gtkui/addbox.py | 2 +- zeroinstall/gtkui/cache.py | 2 +- zeroinstall/injector/fetch.py | 2 +- zeroinstall/injector/iface_cache.py | 12 ++++++------ zeroinstall/injector/model.py | 8 ++++---- zeroinstall/injector/packagekit.py | 2 +- zeroinstall/injector/trust.py | 2 +- zeroinstall/support/tasks.py | 2 +- zeroinstall/zerostore/__init__.py | 4 ++-- zeroinstall/zerostore/cli.py | 2 +- zeroinstall/zerostore/manifest.py | 2 +- zeroinstall/zerostore/optimise.py | 4 ++-- 12 files changed, 22 insertions(+), 22 deletions(-) diff --git a/zeroinstall/gtkui/addbox.py b/zeroinstall/gtkui/addbox.py index b76c39e..24d4975 100644 --- a/zeroinstall/gtkui/addbox.py +++ b/zeroinstall/gtkui/addbox.py @@ -110,7 +110,7 @@ class AddBox: self.window.set_response_sensitive(_RESPONSE_PREV, True) def finish(): - import xdgutils + from . import xdgutils iface = iface_cache.get_interface(model.canonical_iface_uri(uri.get_text())) try: diff --git a/zeroinstall/gtkui/cache.py b/zeroinstall/gtkui/cache.py index ad2d9cc..cbf9173 100644 --- a/zeroinstall/gtkui/cache.py +++ b/zeroinstall/gtkui/cache.py @@ -49,7 +49,7 @@ def get_size(path): size = os.path.getsize(man) for line in file(man, 'rb'): if line[:1] in "XF": - size += long(line.split(' ', 4)[3]) + size += int(line.split(' ', 4)[3]) else: size = 0 for root, dirs, files in os.walk(path): diff --git a/zeroinstall/injector/fetch.py b/zeroinstall/injector/fetch.py index 6f924a7..edd7a43 100644 --- a/zeroinstall/injector/fetch.py +++ b/zeroinstall/injector/fetch.py @@ -179,7 +179,7 @@ class Fetcher(object): @type feed_url: str @param iface_cache: (deprecated) @param force: whether to abort and restart an existing download""" - from download import DownloadAborted + from .download import DownloadAborted assert iface_cache is None or iface_cache is self.config.iface_cache diff --git a/zeroinstall/injector/iface_cache.py b/zeroinstall/injector/iface_cache.py index 3635aa4..e7efe01 100644 --- a/zeroinstall/injector/iface_cache.py +++ b/zeroinstall/injector/iface_cache.py @@ -147,7 +147,7 @@ class PendingFeed(object): def recheck(self): """Set new_xml and sigs by reading signed_data. You need to call this when previously-missing keys are added to the GPG keyring.""" - import gpg + from . import gpg try: self.signed_data.seek(0) stream, sigs = gpg.check_stream(self.signed_data) @@ -225,7 +225,7 @@ class IfaceCache(object): @rtype: bool @since: 0.48 """ - import trust + from . import trust updated = self._oldest_trusted(sigs, trust.domain_from_url(feed_url)) if updated is None: return False # None are trusted @@ -271,8 +271,8 @@ class IfaceCache(object): feed = self.get_feed(feed_url) - import writer - feed.last_checked = long(time.time()) + from . import writer + feed.last_checked = int(time.time()) writer.save_feed(feed) info(_("Updated feed cache entry for %(interface)s (modified %(time)s)"), @@ -407,7 +407,7 @@ class IfaceCache(object): @return: a list of signatures, or None @rtype: [L{gpg.Signature}] or None @since: 0.25""" - import gpg + from . import gpg if os.path.isabs(uri): old_iface = uri else: @@ -423,7 +423,7 @@ class IfaceCache(object): def _get_signature_date(self, uri): """Read the date-stamp from the signature of the cached interface. If the date-stamp is unavailable, returns None.""" - import trust + from . import trust sigs = self.get_cached_signatures(uri) if sigs: return self._oldest_trusted(sigs, trust.domain_from_url(uri)) diff --git a/zeroinstall/injector/model.py b/zeroinstall/injector/model.py index 29296ed..aa5d89b 100644 --- a/zeroinstall/injector/model.py +++ b/zeroinstall/injector/model.py @@ -728,7 +728,7 @@ def _get_long(elem, attr_name): val = elem.getAttribute(attr_name) if val is not None: try: - val = long(val) + val = int(val) except ValueError: raise SafeException(_("Invalid value for integer attribute '%(attribute_name)s': %(value)s") % {'attribute_name': attr_name, 'value': val}) return val @@ -934,7 +934,7 @@ class ZeroInstallFeed(object): size = item.getAttribute('size') if size: - impl.size = long(size) + impl.size = int(size) impl.arch = item_attrs.get('arch', None) try: stability = stability_levels[str(item_attrs['stability'])] @@ -959,7 +959,7 @@ class ZeroInstallFeed(object): size = elem.getAttribute('size') if not size: raise InvalidInterface(_("Missing size attribute on ")) - impl.add_download_source(url = url, size = long(size), + impl.add_download_source(url = url, size = int(size), extract = elem.getAttribute('extract'), start_offset = _get_long(elem, 'start-offset'), type = elem.getAttribute('type')) @@ -977,7 +977,7 @@ class ZeroInstallFeed(object): size = recipe_step.getAttribute('size') if not size: raise InvalidInterface(_("Missing size attribute on ")) - recipe.steps.append(DownloadSource(None, url = url, size = long(size), + recipe.steps.append(DownloadSource(None, url = url, size = int(size), extract = recipe_step.getAttribute('extract'), start_offset = _get_long(recipe_step, 'start-offset'), type = recipe_step.getAttribute('type'))) diff --git a/zeroinstall/injector/packagekit.py b/zeroinstall/injector/packagekit.py index e3b2919..325f388 100644 --- a/zeroinstall/injector/packagekit.py +++ b/zeroinstall/injector/packagekit.py @@ -309,7 +309,7 @@ class _PackageKitTransaction(object): 'group': str(group), 'detail': str(detail), 'url': str(url), - 'size': long(size)} + 'size': int(size)} _logger_pk.debug(_('Details: %s %r'), id, details) self.details[id] = details diff --git a/zeroinstall/injector/trust.py b/zeroinstall/injector/trust.py index e972f1c..776d6c8 100644 --- a/zeroinstall/injector/trust.py +++ b/zeroinstall/injector/trust.py @@ -14,7 +14,7 @@ from zeroinstall import _ import os from zeroinstall.support import basedir -from namespaces import config_site, config_prog, XMLNS_TRUST +from .namespaces import config_site, config_prog, XMLNS_TRUST class TrustDB(object): """A database of trusted keys. diff --git a/zeroinstall/support/tasks.py b/zeroinstall/support/tasks.py index 6a4d0ef..302b0ee 100644 --- a/zeroinstall/support/tasks.py +++ b/zeroinstall/support/tasks.py @@ -164,7 +164,7 @@ class TimeoutBlocker(Blocker): def __init__(self, timeout, name): """Trigger after 'timeout' seconds (may be a fraction).""" Blocker.__init__(self, name) - gobject.timeout_add(long(timeout * 1000), self._timeout) + gobject.timeout_add(int(timeout * 1000), self._timeout) def _timeout(self): self.trigger() diff --git a/zeroinstall/zerostore/__init__.py b/zeroinstall/zerostore/__init__.py index ea38e87..9c7186f 100644 --- a/zeroinstall/zerostore/__init__.py +++ b/zeroinstall/zerostore/__init__.py @@ -85,7 +85,7 @@ class Store: raise NonwritableStore(str(ex)) def add_archive_to_cache(self, required_digest, data, url, extract = None, type = None, start_offset = 0, try_helper = False): - import unpack + from . import unpack info(_("Caching new implementation (digest %s) in %s"), required_digest, self.dir) if self.lookup(required_digest): @@ -180,7 +180,7 @@ class Store: else: extracted = tmp - import manifest + from . import manifest manifest.fixup_permissions(extracted) diff --git a/zeroinstall/zerostore/cli.py b/zeroinstall/zerostore/cli.py index 9d6f1d9..5f99349 100644 --- a/zeroinstall/zerostore/cli.py +++ b/zeroinstall/zerostore/cli.py @@ -99,7 +99,7 @@ def do_optimise(args): print _("Optimising"), cache_dir - import optimise + from . import optimise uniq_size, dup_size, already_linked, man_size = optimise.optimise(cache_dir) print _("Original size : %(size)s (excluding the %(manifest_size)s of manifests)") % {'size': support.pretty_size(uniq_size + dup_size), 'manifest_size': support.pretty_size(man_size)} print _("Already saved : %s") % support.pretty_size(already_linked) diff --git a/zeroinstall/zerostore/manifest.py b/zeroinstall/zerostore/manifest.py index 7aa6144..410ef8c 100644 --- a/zeroinstall/zerostore/manifest.py +++ b/zeroinstall/zerostore/manifest.py @@ -24,7 +24,7 @@ A top-level ".manifest" file is ignored. # Copyright (C) 2009, Thomas Leonard # See the README file for details, or visit http://0install.net. -from __future__ import generators + import os, stat from zeroinstall import SafeException, _ from zeroinstall.zerostore import BadDigest diff --git a/zeroinstall/zerostore/optimise.py b/zeroinstall/zerostore/optimise.py index fd648a5..5a9d023 100644 --- a/zeroinstall/zerostore/optimise.py +++ b/zeroinstall/zerostore/optimise.py @@ -87,14 +87,14 @@ def optimise(impl_dir): if line[0] == "S": itype, digest, size, rest = line.split(' ', 3) - uniq_size += long(size) + uniq_size += int(size) continue assert line[0] in "FX" itype, digest, mtime, size, path = line.split(' ', 4) path = path[:-1] # Strip newline - size = long(size) + size = int(size) key = (itype, digest, mtime, size) loc_path = (impl, dir, path) -- 2.11.4.GIT