mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-09 01:55:04 +00:00
[Py2to3] A group of small compatiblity code changes
* Replace the uses of long with int. * Replace im_func with __func__ as it has been provided for Python 3 forward-compatibility. * Fix next/__next__ for Python 3 compatibility. * Remove the long number literal * Ensure freespace() returns int
This commit is contained in:
parent
837dae242c
commit
da51e3a3d5
@ -47,7 +47,7 @@ class PGReader(object):
|
|||||||
if ver != 1 and ver != 2:
|
if ver != 1 and ver != 2:
|
||||||
raise PGException(_("Invalid version") + " %d" % ver)
|
raise PGException(_("Invalid version") + " %d" % ver)
|
||||||
|
|
||||||
def next(self):
|
def __next__(self):
|
||||||
# Skip over the string
|
# Skip over the string
|
||||||
buf = -1
|
buf = -1
|
||||||
while buf != 0:
|
while buf != 0:
|
||||||
@ -64,5 +64,8 @@ class PGReader(object):
|
|||||||
|
|
||||||
return (start, end)
|
return (start, end)
|
||||||
|
|
||||||
|
# Python 2 compatibility
|
||||||
|
next = __next__
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.fd.close()
|
self.fd.close()
|
||||||
|
@ -50,7 +50,7 @@ def todo_test(caller):
|
|||||||
# Without the delugereporter the todo would print a stack trace, so in
|
# Without the delugereporter the todo would print a stack trace, so in
|
||||||
# that case we rely only on skipTest
|
# that case we rely only on skipTest
|
||||||
if os.environ.get("DELUGE_REPORTER", None):
|
if os.environ.get("DELUGE_REPORTER", None):
|
||||||
getattr(caller, caller._testMethodName).im_func.todo = "To be fixed"
|
getattr(caller, caller._testMethodName).__func__.todo = "To be fixed"
|
||||||
|
|
||||||
filename = os.path.basename(traceback.extract_stack(None, 2)[0][0])
|
filename = os.path.basename(traceback.extract_stack(None, 2)[0][0])
|
||||||
funcname = traceback.extract_stack(None, 2)[0][2]
|
funcname = traceback.extract_stack(None, 2)[0][2]
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import base64
|
import base64
|
||||||
|
import sys
|
||||||
from hashlib import sha1 as sha
|
from hashlib import sha1 as sha
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -259,6 +260,10 @@ class CoreTestCase(BaseTestCase):
|
|||||||
|
|
||||||
def test_get_free_space(self):
|
def test_get_free_space(self):
|
||||||
space = self.core.get_free_space(".")
|
space = self.core.get_free_space(".")
|
||||||
|
# get_free_space returns long on Python 2 (32-bit).
|
||||||
|
if sys.version_info >= (3, 0):
|
||||||
|
self.assertTrue(isinstance(space, int))
|
||||||
|
else:
|
||||||
self.assertTrue(isinstance(space, (int, long)))
|
self.assertTrue(isinstance(space, (int, long)))
|
||||||
self.assertTrue(space >= 0)
|
self.assertTrue(space >= 0)
|
||||||
self.assertEquals(self.core.get_free_space("/someinvalidpath"), -1)
|
self.assertEquals(self.core.get_free_space("/someinvalidpath"), -1)
|
||||||
|
@ -178,7 +178,7 @@ class Win32IcoFile(object):
|
|||||||
# bitmap row data is aligned to word boundaries
|
# bitmap row data is aligned to word boundaries
|
||||||
w += 32 - (im.size[0] % 32)
|
w += 32 - (im.size[0] % 32)
|
||||||
# the total mask data is padded row size * height / bits per char
|
# the total mask data is padded row size * height / bits per char
|
||||||
total_bytes = long((w * im.size[1]) / 8)
|
total_bytes = int((w * im.size[1]) / 8)
|
||||||
log.debug("tot=%d, off=%d, w=%d, size=%d", len(data), and_mask_offset, w, total_bytes)
|
log.debug("tot=%d, off=%d, w=%d, size=%d", len(data), and_mask_offset, w, total_bytes)
|
||||||
|
|
||||||
self.buf.seek(and_mask_offset)
|
self.buf.seek(and_mask_offset)
|
||||||
|
@ -20,16 +20,16 @@ from deluge.ui.console.main import BaseCommand
|
|||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def atom(_next, token):
|
def atom(src, token):
|
||||||
"""taken with slight modifications from http://effbot.org/zone/simple-iterator-parser.htm"""
|
"""taken with slight modifications from http://effbot.org/zone/simple-iterator-parser.htm"""
|
||||||
if token[1] == "(":
|
if token[1] == "(":
|
||||||
out = []
|
out = []
|
||||||
token = _next()
|
token = next(src)
|
||||||
while token[1] != ")":
|
while token[1] != ")":
|
||||||
out.append(atom(_next, token))
|
out.append(atom(src, token))
|
||||||
token = _next()
|
token = next(src)
|
||||||
if token[1] == ",":
|
if token[1] == ",":
|
||||||
token = _next()
|
token = next(src)
|
||||||
return tuple(out)
|
return tuple(out)
|
||||||
elif token[0] is tokenize.NUMBER or token[1] == "-":
|
elif token[0] is tokenize.NUMBER or token[1] == "-":
|
||||||
try:
|
try:
|
||||||
@ -58,7 +58,7 @@ def simple_eval(source):
|
|||||||
src = cStringIO.StringIO(source).readline
|
src = cStringIO.StringIO(source).readline
|
||||||
src = tokenize.generate_tokens(src)
|
src = tokenize.generate_tokens(src)
|
||||||
src = (token for token in src if token[0] is not tokenize.NL)
|
src = (token for token in src if token[0] is not tokenize.NL)
|
||||||
res = atom(src.next, src.next())
|
res = atom(src, next(src))
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ class PeersTab(Tab):
|
|||||||
import binascii
|
import binascii
|
||||||
# Split out the :port
|
# Split out the :port
|
||||||
ip = ":".join(peer["ip"].split(":")[:-1])
|
ip = ":".join(peer["ip"].split(":")[:-1])
|
||||||
ip_int = long(binascii.hexlify(socket.inet_pton(socket.AF_INET6, ip)), 16)
|
ip_int = int(binascii.hexlify(socket.inet_pton(socket.AF_INET6, ip)), 16)
|
||||||
peer_ip = "[%s]:%s" % (ip, peer["ip"].split(":")[-1])
|
peer_ip = "[%s]:%s" % (ip, peer["ip"].split(":")[-1])
|
||||||
|
|
||||||
if peer["seed"]:
|
if peer["seed"]:
|
||||||
|
@ -86,7 +86,7 @@ def generate():
|
|||||||
voffsets += [l2, o2 + valuestart]
|
voffsets += [l2, o2 + valuestart]
|
||||||
offsets = koffsets + voffsets
|
offsets = koffsets + voffsets
|
||||||
output = struct.pack("Iiiiiii",
|
output = struct.pack("Iiiiiii",
|
||||||
0x950412deL, # Magic
|
0x950412de, # Magic
|
||||||
0, # Version
|
0, # Version
|
||||||
len(keys), # # of entries
|
len(keys), # # of entries
|
||||||
7 * 4, # start of key index
|
7 * 4, # start of key index
|
||||||
|
Loading…
x
Reference in New Issue
Block a user