mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-02 06:36:15 +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:
|
||||
raise PGException(_("Invalid version") + " %d" % ver)
|
||||
|
||||
def next(self):
|
||||
def __next__(self):
|
||||
# Skip over the string
|
||||
buf = -1
|
||||
while buf != 0:
|
||||
@ -64,5 +64,8 @@ class PGReader(object):
|
||||
|
||||
return (start, end)
|
||||
|
||||
# Python 2 compatibility
|
||||
next = __next__
|
||||
|
||||
def close(self):
|
||||
self.fd.close()
|
||||
|
@ -50,7 +50,7 @@ def todo_test(caller):
|
||||
# Without the delugereporter the todo would print a stack trace, so in
|
||||
# that case we rely only on skipTest
|
||||
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])
|
||||
funcname = traceback.extract_stack(None, 2)[0][2]
|
||||
|
@ -1,4 +1,5 @@
|
||||
import base64
|
||||
import sys
|
||||
from hashlib import sha1 as sha
|
||||
|
||||
import pytest
|
||||
@ -259,7 +260,11 @@ class CoreTestCase(BaseTestCase):
|
||||
|
||||
def test_get_free_space(self):
|
||||
space = self.core.get_free_space(".")
|
||||
self.assertTrue(isinstance(space, (int, long)))
|
||||
# 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(space >= 0)
|
||||
self.assertEquals(self.core.get_free_space("/someinvalidpath"), -1)
|
||||
|
||||
|
@ -178,7 +178,7 @@ class Win32IcoFile(object):
|
||||
# bitmap row data is aligned to word boundaries
|
||||
w += 32 - (im.size[0] % 32)
|
||||
# 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)
|
||||
|
||||
self.buf.seek(and_mask_offset)
|
||||
|
@ -20,16 +20,16 @@ from deluge.ui.console.main import BaseCommand
|
||||
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"""
|
||||
if token[1] == "(":
|
||||
out = []
|
||||
token = _next()
|
||||
token = next(src)
|
||||
while token[1] != ")":
|
||||
out.append(atom(_next, token))
|
||||
token = _next()
|
||||
out.append(atom(src, token))
|
||||
token = next(src)
|
||||
if token[1] == ",":
|
||||
token = _next()
|
||||
token = next(src)
|
||||
return tuple(out)
|
||||
elif token[0] is tokenize.NUMBER or token[1] == "-":
|
||||
try:
|
||||
@ -58,7 +58,7 @@ def simple_eval(source):
|
||||
src = cStringIO.StringIO(source).readline
|
||||
src = tokenize.generate_tokens(src)
|
||||
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
|
||||
|
||||
|
||||
|
@ -274,7 +274,7 @@ class PeersTab(Tab):
|
||||
import binascii
|
||||
# Split out the :port
|
||||
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])
|
||||
|
||||
if peer["seed"]:
|
||||
|
Loading…
x
Reference in New Issue
Block a user