diff options
| author | Nick Mathewson <nickm@torproject.org> | 2009-01-22 10:54:34 -0500 | 
|---|---|---|
| committer | Nick Mathewson <nickm@torproject.org> | 2009-01-22 10:56:31 -0500 | 
| commit | b64339f48280872deec7bb980a61e494f6f38c92 (patch) | |
| tree | fe8262b8a6e7ca572cfe8c5c26720670697d8f8d | |
| parent | 2068158fd08ca042b874422ee3826f40803f31d8 (diff) | |
Fix multiple pychecker-spotted typos.
These are mostly typos in methods that don't get used in the current
Thandy, error in error-handling paths, modules we imported
unnecessarily, etc.
| -rw-r--r-- | lib/thandy/ClientCLI.py | 3 | ||||
| -rw-r--r-- | lib/thandy/ServerCLI.py | 2 | ||||
| -rw-r--r-- | lib/thandy/download.py | 2 | ||||
| -rw-r--r-- | lib/thandy/encodeToXML.py | 5 | ||||
| -rw-r--r-- | lib/thandy/formats.py | 24 | ||||
| -rw-r--r-- | lib/thandy/keys.py | 5 | ||||
| -rw-r--r-- | lib/thandy/packagesys/ExePackages.py | 4 | ||||
| -rw-r--r-- | lib/thandy/packagesys/PackageDB.py | 6 | ||||
| -rw-r--r-- | lib/thandy/packagesys/PackageSystem.py | 6 | ||||
| -rw-r--r-- | lib/thandy/packagesys/RPMPackages.py | 4 | ||||
| -rw-r--r-- | lib/thandy/repository.py | 17 | ||||
| -rw-r--r-- | lib/thandy/socksurls.py | 2 | ||||
| -rw-r--r-- | lib/thandy/util.py | 2 | 
13 files changed, 29 insertions, 53 deletions
| diff --git a/lib/thandy/ClientCLI.py b/lib/thandy/ClientCLI.py index 14a149a..1994049 100644 --- a/lib/thandy/ClientCLI.py +++ b/lib/thandy/ClientCLI.py @@ -32,7 +32,7 @@ class ControlLogFormatter:                                  thandy.util.formatLogString(m))      def formatException(self, exc_info): -        return repr(traceback.print_exception()) +        return repr(traceback.format_exception(*exc_info))  class RegularLogFilter:      def filter(self, record): @@ -76,7 +76,6 @@ def update(args):      use_packagesys = True      install = False      socksPort = None -    logLevel = logging.INFO      forceCheck = False      for o, v in options: diff --git a/lib/thandy/ServerCLI.py b/lib/thandy/ServerCLI.py index aa39aa1..d9c0f04 100644 --- a/lib/thandy/ServerCLI.py +++ b/lib/thandy/ServerCLI.py @@ -144,7 +144,7 @@ def timestamp(args):              try:                  bObj = snarfObj(fn)              except (ValueError, OSError, IOError), e: -                print "(Couldn't read bundle-like %s)"%fn +                print "(Couldn't read bundle-like %s: %s)"%(fn, e)                  continue              try:                  _, r, _ = thandy.formats.checkSignedObj(bObj) diff --git a/lib/thandy/download.py b/lib/thandy/download.py index 1d969e5..f715a23 100644 --- a/lib/thandy/download.py +++ b/lib/thandy/download.py @@ -4,11 +4,9 @@ import httplib  import logging  import os  import Queue -import random  import sys  import threading  import time -import traceback  import urllib2  import thandy.util diff --git a/lib/thandy/encodeToXML.py b/lib/thandy/encodeToXML.py index 4387c88..c563d77 100644 --- a/lib/thandy/encodeToXML.py +++ b/lib/thandy/encodeToXML.py @@ -1,6 +1,7 @@  # Copyright 2008 The Tor Project, Inc.  See LICENSE for licensing information.  import re +import thandy  def xml_str_encoder(s):      s = s.replace("&", "&") @@ -23,7 +24,7 @@ def isAsciiName(s):      """      return re.match(r'^[A-Za-z\_\:][A-Za-z0-9\_\:\-\.]*$', s) != None -def _encodeToXML(obj, outf, indent=0): +def _encodeToXML(obj, outf):      if isinstance(obj, basestring):          outf(xml_str_encoder(obj))      elif obj is True: @@ -35,7 +36,6 @@ def _encodeToXML(obj, outf, indent=0):      elif isinstance(obj, (int,long)):          outf(str(obj))      elif isinstance(obj, (tuple, list)): -        istr = " "*indent          outf("<list>\n")          for item in obj:              outf("<item>") @@ -62,6 +62,7 @@ def encodeToXML(obj, outf=None):      """Convert a json-encodable object to a quick-and-dirty XML equivalent."""      result = None      if outf == None: +        result = []          outf = result.append      _encodeToXML(obj, outf) diff --git a/lib/thandy/formats.py b/lib/thandy/formats.py index f87128b..b82bf05 100644 --- a/lib/thandy/formats.py +++ b/lib/thandy/formats.py @@ -141,7 +141,7 @@ def checkSignatures(signed, keyDB, role=None, path=None):          except thandy.UnknownMethod:              continue -        if result == True: +        if result:              if role is not None:                  for r,p in key.getRoles():                      if r == role and rolePathMatches(p, path): @@ -326,7 +326,7 @@ def parseTime(s):      try:          return calendar.timegm(time.strptime(s, "%Y-%m-%d %H:%M:%S"))      except ValueError: -        raise thandy.FormatError("Malformed time %r", s) +        raise thandy.FormatException("Malformed time %r", s)  def formatBase64(h):      """Return the base64 encoding of h with whitespace and = signs omitted.""" @@ -343,12 +343,12 @@ def parseBase64(s):      try:          return binascii.a2b_base64(s)      except binascii.Error: -        raise thandy.FormatError("Invalid base64 encoding") +        raise thandy.FormatException("Invalid base64 encoding")  def parseHash(s):      h = parseBase64(s)      if len(h) != Crypto.Hash.SHA256.digest_size: -        raise thandy.FormatError("Bad hash length") +        raise thandy.FormatException("Bad hash length")      return h  S = thandy.checkJson @@ -533,11 +533,6 @@ class Key:          keytype = obj['_keytype']          if keytype == 'rsa':              return Key(thandy.keys.RSAKey.fromJSon(obj)) - -        if typeattr == 'rsa': -            key = thandy.keys.RSAKey.fromSExpression(sexpr) -            if key is not None: -                return Key(key)          else:              return None @@ -547,10 +542,10 @@ class Key:      def getKeyID(self):          return self.key.getKeyID() -    def sign(self, sexpr=None, digest=None): -        return self.key.sign(sexpr, digest=digest) +    def sign(self, obj=None, digest=None): +        return self.key.sign(obj, digest=digest) -    def checkSignature(self, method, data, signatute): +    def checkSignature(self, method, data, signature):          ok = self.key.checkSignature(method, data, signature)          # XXXX CACHE HERE.          return ok @@ -651,7 +646,7 @@ def readConfigFile(fname, needKeys=(), optKeys=(), preload={}):          try:              result[k] = parsed[k]          except KeyError: -            raise thandy.FormatError("Missing value for %s in %s"%k,fname) +            raise thandy.FormatException("Missing value for %s in %s"%k,fname)      for k in optKeys:          try: @@ -916,8 +911,7 @@ def checkSignedObj(obj, keydb=None):          role = 'package'          path = obj['signed']['location']      else: -        print tp -        raise "Foo" +        raise ValueError("Unkown signed object type %r"%tp)      ss = None      if keydb is not None: diff --git a/lib/thandy/keys.py b/lib/thandy/keys.py index 56273e8..211150a 100644 --- a/lib/thandy/keys.py +++ b/lib/thandy/keys.py @@ -5,7 +5,6 @@ import Crypto.PublicKey.RSA  import Crypto.Hash.SHA256  import Crypto.Cipher.AES -import cPickle as pickle  import binascii  import logging  import os @@ -24,7 +23,7 @@ class PublicKey:          self._roles = []      def format(self):          raise NotImplemented() -    def sign(self, data): +    def sign(self, data=None, digest=None):          # returns a list of method,signature tuples.          raise NotImplemented()      def checkSignature(self, method, data, signature): @@ -213,7 +212,7 @@ class RSAKey(PublicKey):      def checkSignature(self, method, sig, obj=None, digest=None):          assert _xor(obj == None, digest == None)          if method != "sha256-pkcs1": -            raise UnknownMethod(method) +            raise thandy.UnknownMethod(method)          if digest == None:              digest = thandy.formats.getDigest(obj)          sig = base64ToInt(sig) diff --git a/lib/thandy/packagesys/ExePackages.py b/lib/thandy/packagesys/ExePackages.py index 59be63e..1928ef3 100644 --- a/lib/thandy/packagesys/ExePackages.py +++ b/lib/thandy/packagesys/ExePackages.py @@ -36,8 +36,8 @@ class CommandInstaller(PS.Installer):      def __repr__(self):          parts = [ "CommandInstaller(%r, %r" %(self._relPath,                                                self._installCommand) ] -        if self.removeCommand: -            parts.append(", %r"%self.removeCommand) +        if self._removeCommand: +            parts.append(", %r"%self._removeCommand)          parts.append(")")          return "".join(parts) diff --git a/lib/thandy/packagesys/PackageDB.py b/lib/thandy/packagesys/PackageDB.py index 94a5ad9..7420868 100644 --- a/lib/thandy/packagesys/PackageDB.py +++ b/lib/thandy/packagesys/PackageDB.py @@ -42,7 +42,7 @@ class SimplePackageDB:          return self._db.get('pi_%s'%str(package))      def getManifest(self, package): -        return self._db.get('mf_%'%str(package), {}) +        return self._db.get('mf_%s'%str(package), {})      def removeAll(self, package):          for template in ["pv_%s", "ip_%s", "mf_%s"]: @@ -59,7 +59,7 @@ def getPackageDBInstance():          fname = thandy.util.userFilename("db/packages")          logging.info("Opening package database in %s", fname)          _DB_INSTANCE = SimplePackageDB(fname) -    return _DB_INSTANCEx +    return _DB_INSTANCE  class _DBMixin:      def setDB(self, db): @@ -110,7 +110,7 @@ class DBChecker(PS.Checker, _DBMixin):          return [ self.getDB().getCurVersion(self._name) ]      def isInstalled(self): -        return self._version in self.getInstalledVersions(transaction) +        return self._version in self.getInstalledVersions()  class DBInstaller(PS.Installer, _DBMixin):      def __init__(self, name, version, relPath, installer): diff --git a/lib/thandy/packagesys/PackageSystem.py b/lib/thandy/packagesys/PackageSystem.py index a521ca8..41d75e5 100644 --- a/lib/thandy/packagesys/PackageSystem.py +++ b/lib/thandy/packagesys/PackageSystem.py @@ -124,7 +124,7 @@ class PackageItem:      def setTransaction(self, transaction):          """Set the transaction context for this item to 'transaction'.          """ -        if self._cheker is not None: +        if self._checker is not None:              self._checker.setTransaction(transaction)          if self._installer is not None:              self._installer.setTransaction(transaction) @@ -174,12 +174,12 @@ class Checker:             installed.  Version types are item-dependent: a tuple or a             string is most common.          """ -        raise NotImplemented +        raise NotImplemented()      def isInstalled(self):          """Return true iff this particular version of this item is installed.          """ -        raise NotImplemented +        raise NotImplemented()  class Installer:      """Abstract base class.  An Installer knows how to install or remove an diff --git a/lib/thandy/packagesys/RPMPackages.py b/lib/thandy/packagesys/RPMPackages.py index c710b8d..2c793e3 100644 --- a/lib/thandy/packagesys/RPMPackages.py +++ b/lib/thandy/packagesys/RPMPackages.py @@ -106,7 +106,7 @@ def checkRPMInstall(name, version, ts=None):          for fname, flags, md5sum in zip(h['filenames'], h['fileflags'], h['filemd5s']):              haveMD5 = fileMD5(fname)              if not haveMD5: -                if flags & RPMFILE_MISSINGOK: +                if (flags & rpm.RPMFILE_MISSINGOK):                      logging.info("%s is missing or unreadable from %s %s; "                                   "that's ok.", fname, name, h['version'])                  else: @@ -118,7 +118,7 @@ def checkRPMInstall(name, version, ts=None):                               fname, name, h['version'])              else:                  # file changed.  If it's not configuration, that's a problem. -                if not flags & RPMFILE_CONFIG: +                if not (flags & rpm.RPMFILE_CONFIG):                      logging.warn("%s changed from installed version of %s %s",                                   fname, name, h['version'])                      all_ok = False diff --git a/lib/thandy/repository.py b/lib/thandy/repository.py index bce79fb..6d1ece3 100644 --- a/lib/thandy/repository.py +++ b/lib/thandy/repository.py @@ -8,7 +8,6 @@ json = thandy.util.importJSON()  import logging  import os -import threading  import time  MAX_TIMESTAMP_AGE = 3*60*60 @@ -90,20 +89,6 @@ class RepositoryFile:          self._main_obj = main_obj          self._mtime = mtime -    def _save(self, content=None): -        """Helper: Flush this object's contents to disk.""" -        if content == None: -            content = sexpr.encode - -        signed_obj,main_obj = self._checkContent(content) - -        fname = self.getPath() -        thandy.util.replaceFile(fname, contents) - -        self._signed_obj = signed_obj -        self._main_obj = main_obj -        self._mtime = time.time() -      def _checkContent(self, content):          """Helper.  Check whether 'content' matches SIGNED_SCHEMA, and             self._schema (as appropraite).  Return a tuple of the @@ -279,7 +264,7 @@ class LocalRepository:                  needRole='bundle')              return pkg -    def getRequestedFile(self, relPath, pkgSystems=None): +    def getRequestedFile(self, relPath):          """DOCDOC"""          for f in self._metaFiles:              if f.getRelativePath() == relPath: diff --git a/lib/thandy/socksurls.py b/lib/thandy/socksurls.py index d035a6c..ee556ab 100644 --- a/lib/thandy/socksurls.py +++ b/lib/thandy/socksurls.py @@ -70,7 +70,7 @@ class SocksHTTPConnection(httplib.HTTPConnection):  class SocksHTTPSConnection(httplib.HTTPSConnection):      def connect(self):          socket = socks_connect(self.host, self.port) -        ssl = socket.ssl(sock, None, None) +        ssl = socket.ssl(socket, None, None)          self.sock = socket.FakeSocket(socket, ssl)  # URL handlers for HTTP and HTTPS urls that use socks instead of direct diff --git a/lib/thandy/util.py b/lib/thandy/util.py index e9db10a..90f251f 100644 --- a/lib/thandy/util.py +++ b/lib/thandy/util.py @@ -191,7 +191,7 @@ def getRegistryValue(keyname):          try:              settings = _winreg.OpenKey(base, key)              return _winreg.QueryValueEx(settings, value)[0] -        except (WindowsError, ValueError, TypeError): +        except (OSError, ValueError, TypeError):              return None      finally:          if settings is not None: | 
