Merge pull request #592 from tahoe-lafs/3020-remove-long-literals

updated python2 long numeric literals for python3 compatibility
This commit is contained in:
heartsucker 2019-04-04 11:52:44 +02:00 committed by GitHub
commit ef6cc501f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 59 additions and 32 deletions

1
newsfragments/3020.other Normal file
View File

@ -0,0 +1 @@
Updated Python2 long numeric literals for Python3 compatibility.

View File

@ -1,4 +1,4 @@
import six
import sys, os
import os.path
from errno import EEXIST
@ -56,11 +56,14 @@ from allmydata.util.time_format import format_time
from allmydata.immutable.upload import FileName, Data
from allmydata import magicfolderdb, magicpath
if six.PY3:
long = int
# Mask off all non-owner permissions for magic-folders files by default.
_DEFAULT_DOWNLOAD_UMASK = 0o077
IN_EXCL_UNLINK = 0x04000000L
IN_EXCL_UNLINK = long(0x04000000)
class ConfigurationError(Exception):

View File

@ -1,4 +1,4 @@
import six
import heapq, traceback, array, stat, struct
from types import NoneType
from stat import S_IFREG, S_IFDIR
@ -42,6 +42,9 @@ noisy = True
from allmydata.util.log import NOISY, OPERATIONAL, WEIRD, \
msg as logmsg, PrefixingLogMixin
if six.PY3:
long = int
def eventually_callback(d):
return lambda res: eventually(d.callback, res)
@ -61,7 +64,7 @@ def _to_sftp_time(t):
"""SFTP times are unsigned 32-bit integers representing UTC seconds
(ignoring leap seconds) since the Unix epoch, January 1 1970 00:00 UTC.
A Tahoe time is the corresponding float."""
return long(t) & 0xFFFFFFFFL
return long(t) & long(0xFFFFFFFF)
def _convert_error(res, request):

View File

@ -1,5 +1,5 @@
"""Tests for the dirnode module."""
import six
import time
import unicodedata
from zope.interface import implementer
@ -27,6 +27,10 @@ from allmydata.nodemaker import NodeMaker
from base64 import b32decode
import allmydata.test.common_util as testutil
if six.PY3:
long = int
@implementer(IConsumer)
class MemAccum(object):
def registerProducer(self, producer, streaming):
@ -1794,7 +1798,7 @@ class DeepStats(testutil.ReallyEqualMixin, unittest.TestCase):
(101, 316, 216),
(317, 1000, 684),
(1001, 3162, 99),
(3162277660169L, 10000000000000L, 1),
(long(3162277660169), long(10000000000000), 1),
])
class UCWEingMutableFileNode(MutableFileNode):

View File

@ -4,6 +4,7 @@ from __future__ import print_function
# a previous run. This asserts that the current code is capable of decoding
# shares from a previous version.
import six
import os
from twisted.trial import unittest
from twisted.internet import defer, reactor
@ -23,6 +24,9 @@ from allmydata.immutable.downloader.fetcher import SegmentFetcher
from allmydata.codec import CRSDecoder
from foolscap.eventual import eventually, fireEventually, flushEventualQueue
if six.PY3:
long = int
plaintext = "This is a moderate-sized file.\n" * 10
mutable_plaintext = "This is a moderate-sized mutable file.\n" * 10
@ -328,7 +332,7 @@ class DownloadTest(_Base, unittest.TestCase):
n = self.c0.create_node_from_uri(immutable_uri)
c = MemoryConsumer()
d = n.read(c, 0L, 10L)
d = n.read(c, long(0), long(10))
d.addCallback(lambda c: len("".join(c.chunks)))
d.addCallback(lambda size: self.failUnlessEqual(size, 10))
return d
@ -521,8 +525,8 @@ class DownloadTest(_Base, unittest.TestCase):
n._cnode._node._build_guessed_tables(u.max_segment_size)
con1 = MemoryConsumer()
con2 = MemoryConsumer()
d = n.read(con1, 0L, 20)
d2 = n.read(con2, 140L, 20)
d = n.read(con1, long(0), long(20))
d2 = n.read(con2, long(140), long(20))
# con2 will be cancelled, so d2 should fail with DownloadStopped
def _con2_should_not_succeed(res):
self.fail("the second read should not have succeeded")
@ -562,8 +566,8 @@ class DownloadTest(_Base, unittest.TestCase):
n._cnode._node._build_guessed_tables(u.max_segment_size)
con1 = MemoryConsumer()
con2 = MemoryConsumer()
d = n.read(con1, 0L, 20)
d2 = n.read(con2, 140L, 20)
d = n.read(con1, long(0), long(20))
d2 = n.read(con2, long(140), long(20))
# con2 should wait for con1 to fail and then con2 should succeed.
# In particular, we should not lose progress. If this test fails,
# it will fail with a timeout error.

View File

@ -3,6 +3,7 @@ from __future__ import print_function
def foo(): pass # keep the line number constant
import six
import os, time, sys
import yaml
from six.moves import StringIO
@ -21,6 +22,9 @@ from allmydata.util import log as tahoe_log
from allmydata.util.spans import Spans, overlap, DataSpans
from allmydata.test.common_util import ReallyEqualMixin, TimezoneMixin
if six.PY3:
long = int
class Base32(unittest.TestCase):
def test_b2a_matches_Pythons(self):
@ -54,7 +58,7 @@ class HumanReadable(unittest.TestCase):
self.failUnlessEqual(hr(foo), "<foo() at test_util.py:4>")
self.failUnlessEqual(hr(self.test_repr),
"<bound method HumanReadable.test_repr of <allmydata.test.test_util.HumanReadable testMethod=test_repr>>")
self.failUnlessEqual(hr(1L), "1")
self.failUnlessEqual(hr(long(1)), "1")
self.failUnlessEqual(hr(10**40),
"100000000000000000...000000000000000000")
self.failUnlessEqual(hr(self), "<allmydata.test.test_util.HumanReadable testMethod=test_repr>")
@ -1706,7 +1710,7 @@ class ByteSpans(unittest.TestCase):
s1 = Spans(3, 4) # 3,4,5,6
self._check1(s1)
s1 = Spans(3L, 4L) # 3,4,5,6
s1 = Spans(long(3), long(4)) # 3,4,5,6
self._check1(s1)
s2 = Spans(s1)
@ -2033,9 +2037,9 @@ class StringSpans(unittest.TestCase):
self.failUnlessEqual(ds.get(2, 4), "fear")
ds = klass()
ds.add(2L, "four")
ds.add(3L, "ea")
self.failUnlessEqual(ds.get(2L, 4L), "fear")
ds.add(long(2), "four")
ds.add(long(3), "ea")
self.failUnlessEqual(ds.get(long(2), long(4)), "fear")
def do_scan(self, klass):

View File

@ -2,24 +2,28 @@
# Most of this is copied from Twisted 11.0. The reason for this hack is that
# twisted.internet.inotify can't be imported when the platform does not support inotify.
import six
if six.PY3:
long = int
# from /usr/src/linux/include/linux/inotify.h
IN_ACCESS = 0x00000001L # File was accessed
IN_MODIFY = 0x00000002L # File was modified
IN_ATTRIB = 0x00000004L # Metadata changed
IN_CLOSE_WRITE = 0x00000008L # Writeable file was closed
IN_CLOSE_NOWRITE = 0x00000010L # Unwriteable file closed
IN_OPEN = 0x00000020L # File was opened
IN_MOVED_FROM = 0x00000040L # File was moved from X
IN_MOVED_TO = 0x00000080L # File was moved to Y
IN_CREATE = 0x00000100L # Subfile was created
IN_DELETE = 0x00000200L # Subfile was delete
IN_DELETE_SELF = 0x00000400L # Self was deleted
IN_MOVE_SELF = 0x00000800L # Self was moved
IN_UNMOUNT = 0x00002000L # Backing fs was unmounted
IN_Q_OVERFLOW = 0x00004000L # Event queued overflowed
IN_IGNORED = 0x00008000L # File was ignored
IN_ACCESS = long(0x00000001) # File was accessed
IN_MODIFY = long(0x00000002) # File was modified
IN_ATTRIB = long(0x00000004) # Metadata changed
IN_CLOSE_WRITE = long(0x00000008) # Writeable file was closed
IN_CLOSE_NOWRITE = long(0x00000010) # Unwriteable file closed
IN_OPEN = long(0x00000020) # File was opened
IN_MOVED_FROM = long(0x00000040) # File was moved from X
IN_MOVED_TO = long(0x00000080) # File was moved to Y
IN_CREATE = long(0x00000100) # Subfile was created
IN_DELETE = long(0x00000200) # Subfile was delete
IN_DELETE_SELF = long(0x00000400) # Self was deleted
IN_MOVE_SELF = long(0x00000800) # Self was moved
IN_UNMOUNT = long(0x00002000) # Backing fs was unmounted
IN_Q_OVERFLOW = long(0x00004000) # Event queued overflowed
IN_IGNORED = long(0x00008000) # File was ignored
IN_ONLYDIR = 0x01000000 # only watch the path if it is a directory
IN_DONT_FOLLOW = 0x02000000 # don't follow a sym link

View File

@ -4,6 +4,7 @@
from __future__ import print_function
import six
import os, sys
from eliot import (
@ -39,6 +40,9 @@ from ctypes import WINFUNCTYPE, WinError, windll, POINTER, byref, create_string_
addressof, get_last_error
from ctypes.wintypes import BOOL, HANDLE, DWORD, LPCWSTR, LPVOID
if six.PY3:
long = int
# <http://msdn.microsoft.com/en-us/library/gg258116%28v=vs.85%29.aspx>
FILE_LIST_DIRECTORY = 1
@ -210,7 +214,7 @@ def medium_test():
notifier = INotify()
notifier.set_pending_delay(1.0)
IN_EXCL_UNLINK = 0x04000000L
IN_EXCL_UNLINK = long(0x04000000)
mask = ( IN_CREATE
| IN_CLOSE_WRITE
| IN_MOVED_TO