LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File BitTorrent-4.0.4-encode-float.patch of Package BitTorrent (Project home:fschuett)

diff -up BitTorrent-4.0.4/BitTorrent/bencode.py.orig BitTorrent-4.0.4/BitTorrent/bencode.py
--- BitTorrent-4.0.4/BitTorrent/bencode.py.orig	2005-08-17 20:24:40.000000000 +0200
+++ BitTorrent-4.0.4/BitTorrent/bencode.py	2017-10-26 17:42:56.000000000 +0200
@@ -25,6 +25,12 @@ def decode_int(x, f):
         raise ValueError
     return (n, newf+1)
 
+def decode_float(x, f):
+    f += 1
+    newf = x.index('e', f)
+    n = float(x[f:newf])
+    return (n, newf+1)
+
 def decode_string(x, f):
     colon = x.index(':', f)
     n = int(x[f:colon])
@@ -55,6 +61,7 @@ decode_func = {}
 decode_func['l'] = decode_list
 decode_func['d'] = decode_dict
 decode_func['i'] = decode_int
+decode_func['f'] = decode_float
 decode_func['0'] = decode_string
 decode_func['1'] = decode_string
 decode_func['2'] = decode_string
@@ -75,7 +82,7 @@ def bdecode(x):
         raise BTFailure, 'invalid bencoded value (data after valid prefix)'
     return r
 
-from types import StringType, IntType, LongType, DictType, ListType, TupleType
+from types import StringType, IntType, LongType, DictType, ListType, TupleType, FloatType
 
 
 class Bencached(object):
@@ -91,6 +98,9 @@ def encode_bencached(x,r):
 def encode_int(x, r):
     r.extend(('i', str(x), 'e'))
 
+def encode_float(x, r):
+    r.extend(('f',str(x), 'e'))
+
 def encode_string(x, r):
     r.extend((str(len(x)), ':', x))
 
@@ -117,6 +127,7 @@ encode_func[StringType] = encode_string
 encode_func[ListType] = encode_list
 encode_func[TupleType] = encode_list
 encode_func[DictType] = encode_dict
+encode_func[FloatType] = encode_float
 
 try:
     from types import BooleanType