xpra icon
Bug tracker and wiki

Ticket #851: rencode.diff

File rencode.diff, 18.4 KB (added by Antoine Martin, 4 years ago)

diff between upstream on github and our copy

  • rencode-1.0

    diff -urN rencode-1.0/COPYING rencode-1.0.3/COPYING
    old new  
    1                     GNU GENERAL PUBLIC LICENSE
    2                        Version 3, 29 June 2007
     1
     2                    GNU GENERAL PUBLIC LICENSE
     3                       Version 3, 29 June 2007
    34
    45 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
    56 Everyone is permitted to copy and distribute verbatim copies
    67 of this license document, but changing it is not allowed.
    78
    8                             Preamble
     9                            Preamble
    910
    1011  The GNU General Public License is a free, copyleft license for
    1112software and other kinds of works.
     
    6869  The precise terms and conditions for copying, distribution and
    6970modification follow.
    7071
    71                        TERMS AND CONDITIONS
     72                       TERMS AND CONDITIONS
    7273
    7374  0. Definitions.
    7475
     
    7677
    7778  "Copyright" also means copyright-like laws that apply to other kinds of
    7879works, such as semiconductor masks.
    79 
     80 
    8081  "The Program" refers to any copyrightable work licensed under this
    8182License.  Each licensee is addressed as "you".  "Licensees" and
    8283"recipients" may be individuals or organizations.
     
    509510covered work in a country, or your recipient's use of the covered work
    510511in a country, would infringe one or more identifiable patents in that
    511512country that you have reason to believe are valid.
    512 
     513 
    513514  If, pursuant to or in connection with a single transaction or
    514515arrangement, you convey, or propagate by procuring conveyance of, a
    515516covered work, and grant a patent license to some of the parties
     
    618619Program, unless a warranty or assumption of liability accompanies a
    619620copy of the Program in return for a fee.
    620621
    621                      END OF TERMS AND CONDITIONS
     622                     END OF TERMS AND CONDITIONS
    622623
    623             How to Apply These Terms to Your New Programs
     624            How to Apply These Terms to Your New Programs
    624625
    625626  If you develop a new program, and you want it to be of the greatest
    626627possible use to the public, the best way to achieve this is to make it
     
    672673the library.  If this is what you want to do, use the GNU Lesser General
    673674Public License instead of this License.  But first, please read
    674675<http://www.gnu.org/philosophy/why-not-lgpl.html>.
     676
  • rencode-1.0

    diff -urN rencode-1.0/README rencode-1.0.3/README
    old new  
     1The rencode module is similar to bencode from the BitTorrent? project. For
     2complex, heterogeneous data structures with many small elements, r-encodings
     3take up significantly less space than b-encodings:
     4
     5>>> len(rencode.dumps({'a':0, 'b':[1,2], 'c':99}))
     613
     7
     8>>> len(bencode.bencode({'a':0, 'b':[1,2], 'c':99}))
     926
     10
     11This version of rencode is a complete rewrite in Cython to attempt to increase
     12the performance over the pure Python module written by Petru Paler,
     13Connelly Barnes et al.
     14
     15Author: Andrew Resch <andrewresch@gmail.com>
     16Website: http://code.google.com/p/rencode/
     17
     18See COPYING for license information.
  • rencode-1.0

    diff -urN rencode-1.0/README.md rencode-1.0.3/README.md
    old new  
    1 #rencode
    2 
    3 The rencode module is similar to bencode from the BitTorrent project.  For complex, heterogeneous data structures with many small elements, r-encodings take up significantly less space than b-encodings:
    4 
    5 ```
    6 >>> len(rencode.dumps({'a':0, 'b':[1,2], 'c':99}))
    7 13
    8 
    9 >>> len(bencode.bencode({'a':0, 'b':[1,2], 'c':99}))
    10 26
    11 ```
    12 
    13 This version of rencode is a complete rewrite in Cython to attempt to increase the performance over the pure Python module written by Petru Paler, Connelly Barnes et al.
    14 
    15 
    16 ##Performance Comparison
    17 The test program used for these results is included in the repository:
    18 https://github.com/aresch/rencode/blob/master/tests/timetest.py
    19 
    20 ###Encode functions
    21 ```
    22 test_encode_fixed_pos_int:
    23         rencode.pyx: 0.003s (+0.013s) 589.17%
    24         rencode.py:  0.016s
    25 
    26 test_encode_int_int_size:
    27         rencode.pyx: 0.006s (+0.032s) 625.99%
    28         rencode.py:  0.038s
    29 
    30 test_encode_int_long_long_size:
    31         rencode.pyx: 0.014s (+0.026s) 279.96%
    32         rencode.py:  0.040s
    33 
    34 test_encode_int_short_size:
    35         rencode.pyx: 0.006s (+0.030s) 629.80%
    36         rencode.py:  0.036s
    37 
    38 test_encode_str:
    39         rencode.pyx: 0.006s (+0.010s) 263.96%
    40         rencode.py:  0.017s
    41 
    42 test_encode_dict:
    43         rencode.pyx: 0.135s (+0.302s) 324.68%
    44         rencode.py:  0.437s
    45 
    46 test_encode_fixed_list:
    47         rencode.pyx: 0.012s (+0.025s) 307.78%
    48         rencode.py:  0.037s
    49 
    50 test_encode_fixed_neg_int:
    51         rencode.pyx: 0.003s (+0.012s) 536.97%
    52         rencode.py:  0.015s
    53 
    54 test_encode_fixed_dict:
    55         rencode.pyx: 0.046s (+0.105s) 331.07%
    56         rencode.py:  0.151s
    57 
    58 test_encode_int_char_size:
    59         rencode.pyx: 0.005s (+0.029s) 687.64%
    60         rencode.py:  0.034s
    61 
    62 test_encode_fixed_str:
    63         rencode.pyx: 0.003s (+0.011s) 438.07%
    64         rencode.py:  0.015s
    65 
    66 test_encode_list:
    67         rencode.pyx: 0.148s (+0.228s) 253.68%
    68         rencode.py:  0.376s
    69 
    70 test_encode_none:
    71         rencode.pyx: 0.004s (+0.011s) 386.06%
    72         rencode.py:  0.014s
    73 
    74 test_encode_int_big_number:
    75         rencode.pyx: 0.011s (+0.019s) 264.32%
    76         rencode.py:  0.030s
    77 
    78 test_encode_float_64bit:
    79         rencode.pyx: 0.003s (+0.011s) 416.19%
    80         rencode.py:  0.014s
    81 
    82 test_encode_bool:
    83         rencode.pyx: 0.004s (+0.014s) 447.57%
    84         rencode.py:  0.018s
    85 
    86 test_encode_float_32bit:
    87         rencode.pyx: 0.003s (+0.010s) 417.86%
    88         rencode.py:  0.014s
    89 
    90 Encode functions totals:
    91         rencode.pyx: 0.412s (+0.888s) 315.49%
    92         rencode.py:  1.301s
    93 ```
    94 ###Decode functions
    95 
    96 ```
    97 test_decode_fixed_list:
    98         rencode.pyx: 0.003s (+0.020s) 848.67%
    99         rencode.py:  0.022s
    100 
    101 test_decode_int_long_long_size:
    102         rencode.pyx: 0.003s (+0.013s) 484.80%
    103         rencode.py:  0.016s
    104 
    105 test_decode_dict:
    106         rencode.pyx: 0.267s (+0.406s) 251.81%
    107         rencode.py:  0.673s
    108 
    109 test_decode_fixed_dict:
    110         rencode.pyx: 0.087s (+0.123s) 241.32%
    111         rencode.py:  0.211s
    112 
    113 test_decode_float_32bit:
    114         rencode.pyx: 0.002s (+0.007s) 536.88%
    115         rencode.py:  0.009s
    116 
    117 test_decode_int_big_number:
    118         rencode.pyx: 0.007s (+0.010s) 256.05%
    119         rencode.py:  0.017s
    120 
    121 test_decode_int_char_size:
    122         rencode.pyx: 0.002s (+0.014s) 754.12%
    123         rencode.py:  0.016s
    124 
    125 test_decode_fixed_neg_int:
    126         rencode.pyx: 0.001s (+0.004s) 389.03%
    127         rencode.py:  0.006s
    128 
    129 test_decode_fixed_str:
    130         rencode.pyx: 0.009s (+0.009s) 199.78%
    131         rencode.py:  0.019s
    132 
    133 test_decode_float_64bit:
    134         rencode.pyx: 0.002s (+0.007s) 540.17%
    135         rencode.py:  0.009s
    136 
    137 test_decode_bool:
    138         rencode.pyx: 0.002s (+0.004s) 369.49%
    139         rencode.py:  0.006s
    140 
    141 test_decode_fixed_pos_int:
    142         rencode.pyx: 0.002s (+0.004s) 368.96%
    143         rencode.py:  0.006s
    144 
    145 test_decode_list:
    146         rencode.pyx: 0.019s (+0.247s) 1403.77%
    147         rencode.py:  0.266s
    148 
    149 test_decode_none:
    150         rencode.pyx: 0.002s (+0.004s) 367.05%
    151         rencode.py:  0.006s
    152 
    153 test_decode_int_short_size:
    154         rencode.pyx: 0.002s (+0.014s) 716.47%
    155         rencode.py:  0.016s
    156 
    157 test_decode_str:
    158         rencode.pyx: 0.010s (+0.026s) 364.51%
    159         rencode.py:  0.036s
    160 
    161 test_decode_int_int_size:
    162         rencode.pyx: 0.002s (+0.014s) 705.92%
    163         rencode.py:  0.016s
    164 
    165 Decode functions totals:
    166         rencode.pyx: 0.421s (+0.926s) 319.79%
    167         rencode.py:  1.348s
    168 ```
    169 
    170 ###Overall functions
    171 
    172 ```
    173 test_overall_encode:
    174         rencode.pyx: 0.069s (+0.120s) 274.42%
    175         rencode.py:  0.189s
    176 
    177 test_overall_decode:
    178         rencode.pyx: 0.051s (+0.153s) 400.57%
    179         rencode.py:  0.204s
    180 
    181 Overall functions totals:
    182         rencode.pyx: 0.120s (+0.273s) 327.98%
    183         rencode.py:  0.393s
    184 ```
    185 
    186 
    187 ##Author
    188 * Andrew Resch <andrewresch@gmail.com>
    189 * Website: https://github.com/aresch/rencode
    190 
    191 ##License
    192 See [COPYING] (https://github.com/aresch/rencode/blob/master/COPYING)  for license information.
  • rencode/__init__.py

    diff -urN rencode-1.0/rencode/__init__.py rencode-1.0.3/rencode/__init__.py
    old new  
    11try:
    22    from rencode._rencode import *
     3    from rencode._rencode import __version__
    34except ImportError:
    45    import rencode.rencode_orig
    56    prev_all = rencode.rencode_orig.__all__[:]
    67    del rencode.rencode_orig.__all__
    78    from rencode.rencode_orig import *
     9    from rencode.rencode_orig import __version__
    810    rencode.rencode_orig.__all__ = prev_all
    911
    1012__all__ = ['dumps', 'loads']
  • rencode/rencode_orig.py

    diff -urN rencode-1.0/rencode/rencode_orig.py rencode-1.0.3/rencode/rencode_orig.py
    old new  
    1919same rencode version throughout your project.
    2020"""
    2121
    22 __version__ = '1.0.2'
     22__version__ = ("Python", 1, 0, 3)
    2323__all__ = ['dumps', 'loads']
    2424
    2525# Original bencode module by Petru Paler, et al.
     
    6464
    6565import sys
    6666
    67 py3 = False
    68 if sys.version_info.major >= 3:
    69     py3 = True
    70     long = int
    71     unicode = str
    72    
    73 def int2byte(c):
    74     if py3:
     67py3 = sys.version >= '3'
     68if py3:
     69    long = int          #@ReservedAssignment
     70    unicode = str       #@ReservedAssignment
     71    def int2byte(c):
    7572        return bytes([c])
    76     else:
     73else:
     74    def int2byte(c):
    7775        return chr(c)
    78        
     76
    7977import struct
    8078from threading import Lock
    8179
     
    196194    return (r, f + 1)
    197195
    198196def decode_true(x, f):
    199   return (True, f+1)
     197    return (True, f+1)
    200198
    201199def decode_false(x, f):
    202   return (False, f+1)
     200    return (False, f+1)
    203201
    204202def decode_none(x, f):
    205   return (None, f+1)
     203    return (None, f+1)
    206204
    207205decode_func = {}
    208206decode_func[b'0'] = decode_string
     
    245243    def make_decoder(slen):
    246244        def f(x, f):
    247245            r, f = [], f+1
    248             for i in range(slen):
     246            for _ in range(slen):
    249247                v, f = decode_func[x[f:f+1]](x, f)
    250248                r.append(v)
    251249            return (tuple(r), f)
     
    271269    def make_decoder(slen):
    272270        def f(x, f):
    273271            r, f = {}, f+1
    274             for j in range(slen):
     272            for _ in range(slen):
    275273                k, f = decode_func[x[f:f+1]](x, f)
    276274                r[k], f = decode_func[x[f:f+1]](x, f)
    277275            return (r, f)
     
    309307        s = str(x)
    310308        if py3:
    311309            s = bytes(s, "ascii")
    312            
     310
    313311        if len(s) >= MAX_INT_LENGTH:
    314312            raise ValueError('overflow')
    315313        r.extend((CHR_INT, s, CHR_TERM))
     
    381379
    382380    Here float_bits is either 32 or 64.
    383381    """
    384     lock.acquire()
    385     try:
     382    with lock:
    386383        if float_bits == 32:
    387384            encode_func[float] = encode_float32
    388385        elif float_bits == 64:
     
    391388            raise ValueError('Float bits (%d) is not 32 or 64' % float_bits)
    392389        r = []
    393390        encode_func[type(x)](x, r)
    394     finally:
    395         lock.release()
    396        
    397391    return b''.join(r)
    398392
    399393def test():
     
    433427
    434428
    435429if __name__ == '__main__':
    436   test()
     430    test()
  • rencode/rencode.pyx

    diff -urN rencode-1.0/rencode/rencode.pyx rencode-1.0.3/rencode/rencode.pyx
    old new  
    2424
    2525import sys
    2626
    27 py3 = False
    28 if sys.version_info.major >= 3:
    29     py3 = True
     27py3 = sys.version >= '3'
     28if py3:
    3029    unicode = str
    31    
     30
    3231from cpython cimport bool
    3332from libc.stdlib cimport realloc, malloc, free
    3433from libc.string cimport memcpy
    3534
    36 __version__ = "1.0.2"
     35__version__ = ("Cython", 1, 0, 3)
    3736
    3837cdef long long data_length = 0
    3938cdef bool _decode_utf8 = False
     
    261260            encode(buf, pos, v)
    262261        write_buffer_char(buf, pos, CHR_TERM)
    263262
     263cdef object MAX_SIGNED_INT = 2**31
     264cdef object MIN_SIGNED_INT = -MAX_SIGNED_INT
     265#note: negating the Python value avoids compiler problems
     266#(negating the "long long" constant can make it unsigned with some compilers!)
     267cdef object MAX_SIGNED_LONGLONG = int(2**63)
     268cdef object MIN_SIGNED_LONGLONG = -MAX_SIGNED_LONGLONG
     269
    264270cdef encode(char **buf, int *pos, data):
    265271    t = type(data)
    266272    if t == int or t == long:
     
    268274            encode_char(buf, pos, data)
    269275        elif -32768 <= data < 32768:
    270276            encode_short(buf, pos, data)
    271         elif -2147483648 <= data < 2147483648:
     277        elif MIN_SIGNED_INT <= data < MAX_SIGNED_INT:
    272278            encode_int(buf, pos, data)
    273         elif -9223372036854775808 <= data < 9223372036854775808:
     279        elif MIN_SIGNED_LONGLONG <= data < MAX_SIGNED_LONGLONG:
    274280            encode_long_long(buf, pos, data)
    275281        else:
    276282            s = str(data)
     
    306312    elif t == dict:
    307313        encode_dict(buf, pos, data)
    308314
     315    else:
     316        raise Exception("type %s not handled" % t)
    309317
    310318def dumps(data, float_bits=DEFAULT_FLOAT_BITS):
    311319    """
     
    331339    return c
    332340
    333341cdef decode_short(char *data, int *pos):
    334     cdef short s
     342    cdef short s        #@DuplicatedSignature
    335343    memcpy(&s, &data[pos[0]+1], 2)
    336344    pos[0] += 3
    337345    if not big_endian:
     
    339347    return s
    340348
    341349cdef decode_int(char *data, int *pos):
    342     cdef int i
     350    cdef int i          #@DuplicatedSignature
    343351    memcpy(&i, &data[pos[0]+1], 4)
    344352    pos[0] += 5
    345353    if not big_endian:
     
    347355    return i
    348356
    349357cdef decode_long_long(char *data, int *pos):
    350     cdef long long l
     358    cdef long long l    #@DuplicatedSignature
    351359    memcpy(&l, &data[pos[0]+1], 8)
    352360    pos[0] += 9
    353361    if not big_endian:
     
    376384    return big_number
    377385
    378386cdef decode_float32(char *data, int *pos):
    379     cdef float f
     387    cdef float f        #@DuplicatedSignature
    380388    memcpy(&f, &data[pos[0]+1], 4)
    381389    pos[0] += 5
    382390    if not big_endian:
     
    384392    return f
    385393
    386394cdef decode_float64(char *data, int *pos):
    387     cdef double d
     395    cdef double d       #@DuplicatedSignature
    388396    memcpy(&d, &data[pos[0]+1], 8)
    389397    pos[0] += 9
    390398    if not big_endian:
     
    412420    l = []
    413421    size = <unsigned char>data[pos[0]] - LIST_FIXED_START
    414422    pos[0] += 1
    415     cdef int i
     423    cdef int i      #@DuplicatedSignature
    416424    for i in range(size):
    417425        l.append(decode(data, pos))
    418426    return tuple(l)
     
    429437    d = {}
    430438    size = <unsigned char>data[pos[0]] - DICT_FIXED_START
    431439    pos[0] += 1
    432     cdef int i
     440    cdef int i      #@DuplicatedSignature
    433441    for i in range(size):
    434442        key = decode(data, pos)
    435443        value = decode(data, pos)
     
    508516    :type decode_utf8: bool
    509517
    510518    """
    511     cdef int pos = 0
     519    cdef int pos = 0        #@DuplicatedSignature
    512520    global data_length
    513521    data_length = len(data)
    514522    global _decode_utf8
  • rencode-1.0

    diff -urN rencode-1.0/setup.py rencode-1.0.3/setup.py
    old new  
    7272
    7373setup(
    7474  name="rencode",
    75   version="1.0.2",
     75  version="1.0.3",
    7676  packages=["rencode"],
    7777  description=description,
    7878  author="Andrew Resch",
  • tests/test_rencode.py

    diff -urN rencode-1.0/tests/test_rencode.py rencode-1.0.3/tests/test_rencode.py
    old new  
    44#
    55# Copyright (C) 2010 Andrew Resch <andrewresch@gmail.com>
    66#
    7 # rencode is free software.
     7# Deluge is free software.
    88#
    99# You may redistribute it and/or modify it under the terms of the
    1010# GNU General Public License, as published by the Free Software
    1111# Foundation; either version 3 of the License, or (at your option)
    1212# any later version.
    1313#
    14 # rencode is distributed in the hope that it will be useful,
     14# deluge is distributed in the hope that it will be useful,
    1515# but WITHOUT ANY WARRANTY; without even the implied warranty of
    1616# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    1717# See the GNU General Public License for more details.
    1818#
    1919# You should have received a copy of the GNU General Public License
    20 # along with rencode.    If not, write to:
     20# along with deluge.    If not, write to:
    2121#     The Free Software Foundation, Inc.,
    2222#     51 Franklin Street, Fifth Floor
    2323#     Boston, MA  02110-1301, USA.
     
    3636    def u(x):
    3737        return codecs.unicode_escape_decode(x)[0]
    3838else:
    39     unicode = str
     39    unicode = str           #@ReservedAssignment
    4040    def u(x):
    4141        return x
    4242
     
    196196
    197197    def test_decode_utf8(self):
    198198        s = b"foobarbaz"
    199         self.assertIsInstance(rencode.loads(rencode.dumps(s), decode_utf8=True), unicode)
     199        #no assertIsInstance with python2.6
     200        d = rencode.loads(rencode.dumps(s), decode_utf8=True)
     201        if not isinstance(d, unicode):
     202            self.fail('%s is not an instance of %r' % (repr(d), unicode))
    200203        s = rencode.dumps(b"\x56\xe4foo\xc3")
    201204        self.assertRaises(UnicodeDecodeError, rencode.loads, s, decode_utf8=True)
    202        
     205
     206    def test_version_exposed(self):
     207        assert rencode.__version__
     208        assert rencode_orig.__version__
     209        self.assertEqual(rencode.__version__[1:], rencode_orig.__version__[1:], "version number does not match")
     210
    203211if __name__ == '__main__':
    204212    unittest.main()
  • tests/timetest.py

    diff -urN rencode-1.0/tests/timetest.py rencode-1.0.3/tests/timetest.py
    old new  
    44#
    55# Copyright (C) 2010 Andrew Resch <andrewresch@gmail.com>
    66#
    7 # rencode is free software.
     7# Deluge is free software.
    88#
    99# You may redistribute it and/or modify it under the terms of the
    1010# GNU General Public License, as published by the Free Software
    1111# Foundation; either version 3 of the License, or (at your option)
    1212# any later version.
    1313#
    14 # rencode is distributed in the hope that it will be useful,
     14# deluge is distributed in the hope that it will be useful,
    1515# but WITHOUT ANY WARRANTY; without even the implied warranty of
    1616# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    1717# See the GNU General Public License for more details.
    1818#
    1919# You should have received a copy of the GNU General Public License
    20 # along with rencode.    If not, write to:
     20# along with deluge.    If not, write to:
    2121#     The Free Software Foundation, Inc.,
    2222#     51 Franklin Street, Fifth Floor
    2323#     Boston, MA  02110-1301, USA.
     
    3333    def u(x):
    3434        return codecs.unicode_escape_decode(x)[0]
    3535else:
    36     unicode = str
     36    unicode = str           #@ReservedAssignment
    3737    def u(x):
    3838        return x
    39        
     39
    4040# Encode functions
    4141
    4242def test_encode_fixed_pos_int():
     
    310310
    311311if __name__ == "__main__":
    312312    import timeit
    313     import sys
    314313
    315314    iterations = 10000
    316315    # ANSI escape codes