[tor-commits] [bridgedb/develop] Change attr and fmtstr types in b.p.v.Version to be comparable.

isis at torproject.org isis at torproject.org
Wed Apr 23 05:23:11 UTC 2014


commit 1462ee5c8c0deb14321beac8a530d108ea22d051
Author: Isis Lovecruft <isis at torproject.org>
Date:   Tue Apr 22 21:14:50 2014 +0000

    Change attr and fmtstr types in b.p.v.Version to be comparable.
    
    We should use ints for the `major`, `minor`, and `minor` attributes,
    just like the parent class in Twisted does.
---
 lib/bridgedb/parse/versions.py |   32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/lib/bridgedb/parse/versions.py b/lib/bridgedb/parse/versions.py
index 0aefe43..e71df97 100644
--- a/lib/bridgedb/parse/versions.py
+++ b/lib/bridgedb/parse/versions.py
@@ -72,19 +72,21 @@ class Version(txutil.Version):
         if version.find('.') == -1:
             raise InvalidVersionStringFormat(
                 "Invalid delimiters in version string: %r" % version)
-        major, minor, micro, prerelease = ['' for x in xrange(4)]
 
+        package = package if package is not None else str()
+        major, minor, micro = [int() for _ in range(3)]
+        prerelease = str()
         components = version.split('.')
         if len(components) > 0:
             try:
-                prerelease = components.pop()
-                micro      = components.pop()
-                minor      = components.pop()
-                major      = components.pop()
+                prerelease = str(components.pop())
+                micro      = int(components.pop())
+                minor      = int(components.pop())
+                major      = int(components.pop())
             except IndexError:
                 pass
         super(Version, self).__init__(package, major, minor, micro, prerelease)
-        
+
     def base(self):
         """Get the base version number (with prerelease).
 
@@ -92,8 +94,8 @@ class Version(txutil.Version):
         :returns: A version number, without the package/program name, and with
             the prefix (if available). For example: '0.2.5.1-alpha'.
         """
-        prerelease = getPrefixedPrerelease()
-        return '%d.%d.%d%s' % (self.major, self.minor, self.micro, prerelease)
+        pre = self.getPrefixedPrerelease()
+        return '%s.%s.%s%s' % (self.major, self.minor, self.micro, pre)
 
     def getPrefixedPrerelease(self, separator='.'):
         """Get the prerelease string, prefixed by the separator ``prefix``.
@@ -105,11 +107,15 @@ class Version(txutil.Version):
         """
         pre = ''
         if self.prerelease is not None:
-            pre = prefix + self.prerelease
+            pre = separator + self.prerelease
         return pre
 
     def __repr__(self):
-        prerelease = getPrefixedPrerelease('')
-        return '%s(package=%r, major=%d, minor=%d, micro=%d, prerelease=%s)' \
-            % (self.__class__.__name__, str(self.package),
-               self.major, self.minor, self.micro, self.prerelease)
+        prerelease = self.getPrefixedPrerelease('')
+        return '%s(package=%s, major=%s, minor=%s, micro=%s, prerelease=%s)' \
+            % (str(self.__class__.__name__),
+               str(self.package),
+               str(self.major),
+               str(self.minor),
+               str(self.micro),
+               str(prerelease))





More information about the tor-commits mailing list