Skip to content

Commit f49a044

Browse files
authored
Merge pull request renpy#2017 from wchill/py3_ints
[Py3] Make Python 3 integer related changes
2 parents d337e47 + f452540 commit f49a044

File tree

6 files changed

+40
-30
lines changed

6 files changed

+40
-30
lines changed

launcher/game/package_formats.rpy

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,17 @@ init python in distribute:
2828
import struct
2929
import stat
3030
import shutil
31+
import sys
3132
import threading
3233

34+
from renpy import six
3335
from zipfile import crc32
3436

37+
38+
# Since the long type doesn't exist on py3, define it here
39+
if six.PY3:
40+
long = int
41+
3542
zlib.Z_DEFAULT_COMPRESSION = 5
3643

3744
class ZipFile(zipfile.ZipFile):
@@ -156,9 +163,9 @@ init python in distribute:
156163
zi.create_system = 3
157164

158165
if xbit:
159-
zi.external_attr = long(0100755) << 16
166+
zi.external_attr = long(0o100755) << 16
160167
else:
161-
zi.external_attr = long(0100644) << 16
168+
zi.external_attr = long(0o100644) << 16
162169

163170
self.zipfile.write_with_info(zi, path)
164171

@@ -170,7 +177,7 @@ init python in distribute:
170177
zi.date_time = self.get_date_time(path)
171178
zi.compress_type = zipfile.ZIP_STORED
172179
zi.create_system = 3
173-
zi.external_attr = (long(0040755) << 16) | 0x10
180+
zi.external_attr = (long(0o040755) << 16) | 0x10
174181

175182
self.zipfile.write_with_info(zi, path)
176183

@@ -201,9 +208,9 @@ init python in distribute:
201208
info.type = tarfile.DIRTYPE
202209

203210
if xbit:
204-
info.mode = 0755
211+
info.mode = 0o755
205212
else:
206-
info.mode = 0644
213+
info.mode = 0o644
207214

208215
info.uid = 1000
209216
info.gid = 1000
@@ -267,7 +274,7 @@ init python in distribute:
267274

268275
def mkdir(self, path):
269276
if not os.path.isdir(path):
270-
os.makedirs(path, 0755)
277+
os.makedirs(path, 0o755)
271278

272279
def __init__(self, path):
273280
self.path = path
@@ -282,9 +289,9 @@ init python in distribute:
282289
shutil.copy2(path, fn)
283290

284291
if xbit:
285-
os.chmod(fn, 0755)
292+
os.chmod(fn, 0o755)
286293
else:
287-
os.chmod(fn, 0644)
294+
os.chmod(fn, 0o644)
288295

289296
def add_directory(self, name, path):
290297
fn = os.path.join(self.path, name)
@@ -396,7 +403,3 @@ init python in distribute:
396403
for i in parallel_threads:
397404
if i.done:
398405
i.done()
399-
400-
401-
402-

launcher/game/pefile.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@
5555
import exceptions
5656
import string
5757
import array
58+
from renpy import six
59+
60+
61+
# Since the long type doesn't exist on py3, define it here
62+
if six.PY3:
63+
long = int
64+
5865

5966
sha1, sha256, sha512, md5 = None, None, None, None
6067

@@ -85,8 +92,8 @@
8592
IMAGE_VXD_SIGNATURE = 0x454C
8693
IMAGE_NT_SIGNATURE = 0x00004550
8794
IMAGE_NUMBEROF_DIRECTORY_ENTRIES= 16
88-
IMAGE_ORDINAL_FLAG = 0x80000000L
89-
IMAGE_ORDINAL_FLAG64 = 0x8000000000000000L
95+
IMAGE_ORDINAL_FLAG = 0x80000000
96+
IMAGE_ORDINAL_FLAG64 = long(0x8000000000000000)
9097
OPTIONAL_HEADER_MAGIC_PE = 0x10b
9198
OPTIONAL_HEADER_MAGIC_PE_PLUS = 0x20b
9299

@@ -169,7 +176,7 @@
169176
('IMAGE_SCN_MEM_SHARED', 0x10000000),
170177
('IMAGE_SCN_MEM_EXECUTE', 0x20000000),
171178
('IMAGE_SCN_MEM_READ', 0x40000000),
172-
('IMAGE_SCN_MEM_WRITE', 0x80000000L) ]
179+
('IMAGE_SCN_MEM_WRITE', 0x80000000) ]
173180

174181
SECTION_CHARACTERISTICS = dict([(e[1], e[0]) for e in
175182
section_characteristics]+section_characteristics)
@@ -816,7 +823,7 @@ def dump(self, indentation=0):
816823
for key in keys:
817824

818825
val = getattr(self, key)
819-
if isinstance(val, int) or isinstance(val, long):
826+
if isinstance(val, six.integer_types):
820827
val_str = '0x%-8X' % (val)
821828
if key == 'TimeDateStamp' or key == 'dwTimeStamp':
822829
try:
@@ -1557,7 +1564,7 @@ def __parse__(self, fname, data, fast_load):
15571564
'Normal values are never larger than 0x10, the value is: 0x%x' %
15581565
self.OPTIONAL_HEADER.NumberOfRvaAndSizes )
15591566

1560-
for i in xrange(int(0x7fffffffL & self.OPTIONAL_HEADER.NumberOfRvaAndSizes)):
1567+
for i in xrange(int(0x7fffffff & self.OPTIONAL_HEADER.NumberOfRvaAndSizes)):
15611568

15621569
if len(self.__data__[offset:]) == 0:
15631570
break
@@ -2355,13 +2362,13 @@ def parse_resource_entry(self, rva):
23552362
return None
23562363

23572364
#resource.NameIsString = (resource.Name & 0x80000000L) >> 31
2358-
resource.NameOffset = resource.Name & 0x7FFFFFFFL
2365+
resource.NameOffset = resource.Name & 0x7FFFFFFF
23592366

2360-
resource.__pad = resource.Name & 0xFFFF0000L
2361-
resource.Id = resource.Name & 0x0000FFFFL
2367+
resource.__pad = resource.Name & 0xFFFF0000
2368+
resource.Id = resource.Name & 0x0000FFFF
23622369

2363-
resource.DataIsDirectory = (resource.OffsetToData & 0x80000000L) >> 31
2364-
resource.OffsetToDirectory = resource.OffsetToData & 0x7FFFFFFFL
2370+
resource.DataIsDirectory = (resource.OffsetToData & 0x80000000) >> 31
2371+
resource.OffsetToDirectory = resource.OffsetToData & 0x7FFFFFFF
23652372

23662373
return resource
23672374

@@ -2683,7 +2690,7 @@ def parse_version_information(self, version_struct):
26832690
raw_data[varword_offset+2:varword_offset+4], 0)
26842691
varword_offset += 4
26852692

2686-
if isinstance(word1, (int, long)) and isinstance(word1, (int, long)):
2693+
if isinstance(word1, six.integer_types):
26872694
var_struct.entry = {var_string: '0x%04x 0x%04x' % (word1, word2)}
26882695

26892696
var_offset = self.dword_align(

renpy/common/00updater.rpy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,9 +835,9 @@ init -1500 python in updater:
835835
info.gname = "renpy"
836836

837837
if xbit or directory:
838-
info.mode = 0777
838+
info.mode = 0o777
839839
else:
840-
info.mode = 0666
840+
info.mode = 0o666
841841

842842
if info.isreg():
843843
with open(path, "rb") as f:
@@ -1090,7 +1090,7 @@ init -1500 python in updater:
10901090
umask = os.umask(0)
10911091
os.umask(umask)
10921092

1093-
os.chmod(new_path, 0777 & (~umask))
1093+
os.chmod(new_path, 0o777 & (~umask))
10941094
except:
10951095
pass
10961096

renpy/display/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def get_ordered_image_attributes(tag, attributes=(), sort=None):
229229

230230
for attr in attrcount:
231231
if attr not in rv:
232-
l.append((attrtotalpos[attr] / attrcount[attr], sort(attr), attr))
232+
l.append((attrtotalpos[attr] // attrcount[attr], sort(attr), attr))
233233

234234
l.sort()
235235
for i in l:

renpy/display/swdraw.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,11 @@ def draw_special(what, dest, x, y):
310310
ramp = "\x00" * 256
311311

312312
for i in xrange(0, ramplen):
313-
ramp += chr(255 * i / ramplen)
313+
ramp += chr(255 * i // ramplen)
314314

315315
ramp += "\xff" * 256
316316

317-
step = int( what.operation_complete * (256 + ramplen) )
317+
step = int(what.operation_complete * (256 + ramplen))
318318
ramp = ramp[step:step+256]
319319

320320
renpy.display.module.imageblend(

renpy/loadsave.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def visit(o, path):
116116
size = 1
117117

118118
elif isinstance(o, (str, unicode)):
119-
size = len(o) / 40 + 1
119+
size = len(o) // 40 + 1
120120

121121
elif isinstance(o, (tuple, list)):
122122
size = 1

0 commit comments

Comments
 (0)