]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/vint.py
Streamline output: Exception messages
[bup.git] / lib / bup / vint.py
index 8f7f58a6698ddc22a3d9a3959190c323d03e69dd..57be65b45462bb3b1bc02faa3acdd8cb416a7103 100644 (file)
@@ -11,7 +11,7 @@ from cStringIO import StringIO
 
 def write_vuint(port, x):
     if x < 0:
-        raise Exception("vuints must not be negative")
+        raise Exception("vuint's must not be negative")
     elif x == 0:
         port.write('\0')
     else:
@@ -27,7 +27,7 @@ def write_vuint(port, x):
 def read_vuint(port):
     c = port.read(1)
     if c == '':
-        raise EOFError('encountered EOF while reading vuint');
+        raise EOFError('Encountered EOF while reading vuint');
     result = 0
     offset = 0
     while c:
@@ -64,7 +64,7 @@ def write_vint(port, x):
 def read_vint(port):
     c = port.read(1)
     if c == '':
-        raise EOFError('encountered EOF while reading vint');
+        raise EOFError('Encountered EOF while reading vint');
     negative = False
     result = 0
     offset = 0
@@ -77,8 +77,10 @@ def read_vint(port):
         if b & 0x80:
             offset += 6
             c = port.read(1)
+        elif negative:
+            return -result
         else:
-            return -result if negative else result
+            return result
     while c:
         b = ord(c)
         if b & 0x80:
@@ -88,7 +90,10 @@ def read_vint(port):
         else:
             result |= (b << offset)
             break
-    return -result if negative else result
+    if negative:
+        return -result
+    else:
+        return result
 
 
 def write_bvec(port, x):
@@ -107,7 +112,7 @@ def skip_bvec(port):
 
 def pack(types, *args):
     if len(types) != len(args):
-        raise Exception('number of arguments does not match format string')
+        raise Exception('Number of arguments does not match format string')
     port = StringIO()
     for (type, value) in zip(types, args):
         if type == 'V':
@@ -117,7 +122,7 @@ def pack(types, *args):
         elif type == 's':
             write_bvec(port, value)
         else:
-            raise Exception('unknown xpack format string item "' + type + '"')
+            raise Exception('Unknown xpack format string item "' + type + '"')
     return port.getvalue()
 
 
@@ -132,5 +137,5 @@ def unpack(types, data):
         elif type == 's':
             result.append(read_bvec(port))
         else:
-            raise Exception('unknown xunpack format string item "' + type + '"')
+            raise Exception('Unknown xunpack format string item "' + type + '"')
     return result