Skip to content

Commit 080625a

Browse files
Daniel NunesInfernio
authored andcommitted
Prepare divisions for py3
Changes division to use py3's division. Converts the required divisions to floor divisions to keep the result as integers. This will need to be double- and triple-checked to make sure everything is correct. Infernio: No fun allowed. Comment removed. It is a syntax error to write Python while not wearing a blue tie. Also dropped the __div__ in ScriptParser, doesn't exist in py3. Infernio: Updated for inf-wx-begone
1 parent 3f6a0d6 commit 080625a

21 files changed

Lines changed: 45 additions & 25 deletions

Mopy/bash/ScriptParser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
# TokensToRPN
6161
# ExecuteRPN
6262
#==================================================
63+
from __future__ import division
6364
from string import digits, whitespace
6465
import types
6566
#--------------------------------------------------
@@ -383,7 +384,6 @@ def __ge__(self, other):
383384
def __add__(self, other): return Parser.Token(self.tkn + other.tkn)
384385
def __sub__(self, other): return Parser.Token(self.tkn - other.tkn)
385386
def __mul__(self, other): return Parser.Token(self.tkn * other.tkn)
386-
def __div__(self, other): return Parser.Token(self.tkn / other.tkn)
387387
def __mod__(self, other): return Parser.Token(self.tkn % other.tkn)
388388
def __truediv__(self, other): return Parser.Token(self.tkn / other.tkn)
389389
def __floordiv__(self, other): return Parser.Token(self.tkn // other.tkn)

Mopy/bash/balt.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# =============================================================================
2424

2525
# Imports ---------------------------------------------------------------------
26+
from __future__ import division
2627
import re
2728
import bass # for dirs - try to avoid
2829
#--Localization
@@ -2894,7 +2895,7 @@ def _getButtonIndex(self, mouseEvent):
28942895
for i, button in enumerate(self.buttons):
28952896
if button._native_widget.GetId() == id_:
28962897
x = mouseEvent.GetPosition()[0]
2897-
delta = x / self.iconsSize
2898+
delta = x // self.iconsSize
28982899
if abs(x) % self.iconsSize > self.iconsSize:
28992900
delta += x / abs(x)
29002901
i += delta

Mopy/bash/basher/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
# Imports ---------------------------------------------------------------------
5454
#--Python
55+
from __future__ import division
5556
import StringIO
5657
import collections
5758
import os
@@ -1844,8 +1845,8 @@ def _headInfo(saveInfo, attr):
18441845
@staticmethod
18451846
def _playTime(saveInfo):
18461847
if not saveInfo.header: return u'-'
1847-
playMinutes = saveInfo.header.gameTicks / 60000
1848-
return u'%d:%02d' % (playMinutes/60, (playMinutes % 60))
1848+
playMinutes = saveInfo.header.gameTicks // 60000
1849+
return u'%d:%02d' % (playMinutes//60, (playMinutes % 60))
18491850
labels = OrderedDict([
18501851
('File', lambda self, p: p.s),
18511852
('Modified', lambda self, p: format_date(self.data_store[p].mtime)),
@@ -1954,7 +1955,7 @@ def __init__(self,parent):
19541955
self._set_player_info_label()
19551956
self.gCoSaves = Label(top, u'--\n--')
19561957
#--Picture
1957-
self.picture = balt.Picture(top, textWidth, 192 * textWidth / 256,
1958+
self.picture = balt.Picture(top, textWidth, 192 * textWidth // 256,
19581959
background=colors['screens.bkgd.image']) #--Native: 256x192
19591960
#--Save Info
19601961
self.gInfo = TextArea(self._bottom_low_panel, max_length=2048)
@@ -1994,7 +1995,7 @@ def SetFile(self,fileName='SAME'):
19941995
self.playerNameStr = saveInfo.header.pcName
19951996
self.curCellStr = saveInfo.header.pcLocation
19961997
self.gameDays = saveInfo.header.gameDays
1997-
self.playMinutes = saveInfo.header.gameTicks/60000
1998+
self.playMinutes = saveInfo.header.gameTicks//60000
19981999
self.playerLevel = saveInfo.header.pcLevel
19992000
self.coSaves = saveInfo.get_cosave_tags()
20002001
#--Set Fields
@@ -2019,7 +2020,7 @@ def _set_player_info_label(self):
20192020
self.playerInfo.label_text = (self.playerNameStr + u'\n' +
20202021
_(u'Level') + u' %d, ' + _(u'Day') + u' %d, ' +
20212022
_(u'Play') + u' %d:%02d\n%s') % (
2022-
self.playerLevel, int(self.gameDays), self.playMinutes / 60,
2023+
self.playerLevel, int(self.gameDays), self.playMinutes // 60,
20232024
(self.playMinutes % 60), self.curCellStr)
20242025

20252026
def OnInfoEdit(self, new_text):

Mopy/bash/basher/app_buttons.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# https://github.com/wrye-bash
2222
#
2323
# =============================================================================
24+
from __future__ import division
2425
import subprocess
2526
import webbrowser
2627
from . import BashStatusBar, BashFrame
@@ -199,7 +200,7 @@ def IsPresent(self):
199200
def GetBitmapButton(self, window, image=None, onRClick=None):
200201
if not self.IsPresent(): return None
201202
size = bass.settings['bash.statusbar.iconSize'] # 16, 24, 32
202-
idex = (size / 8) - 2 # 0, 1, 2, duh
203+
idex = (size // 8) - 2 # 0, 1, 2, duh
203204
super(App_Button, self).GetBitmapButton(
204205
window, self.images[idex].GetBitmap(), onRClick)
205206
if self.obseTip is not None:

Mopy/bash/basher/gui_patchers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# https://github.com/wrye-bash
2222
#
2323
# =============================================================================
24+
from __future__ import division
2425
import copy
2526
import string
2627
import re

Mopy/bash/basher/saves_links.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"""Menu items for the main and item menus of the saves tab - their window
2626
attribute points to BashFrame.saveList singleton."""
2727

28+
from __future__ import division
2829
import StringIO
2930
import re
3031
import shutil

Mopy/bash/belt.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# =============================================================================
2424

2525
"""Specific parser for Wrye Bash."""
26+
from __future__ import division
2627
from collections import OrderedDict
2728
from functools import partial
2829
import os

Mopy/bash/bolt.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
# Imports ---------------------------------------------------------------------
2626
#--Standard
27+
from __future__ import division
2728
import StringIO
2829
import cPickle
2930
import codecs
@@ -175,7 +176,7 @@ def timestamp(): return datetime.datetime.now().strftime(u'%Y-%m-%d %H.%M.%S')
175176

176177
def round_size(kbytes):
177178
"""Round non zero sizes to 1 KB."""
178-
return u'%u KB' % (0 if kbytes == 0 else max(kbytes, 1024) / 1024)
179+
return u'%u KB' % (0 if kbytes == 0 else max(kbytes, 1024) // 1024)
179180

180181
# Helpers ---------------------------------------------------------------------
181182
def sortFiles(files, __split=os.path.split):
@@ -2248,7 +2249,7 @@ def subLink(match):
22482249
text = maList.group(3)
22492250
if bullet == u'.': bullet = u' '
22502251
elif bullet == u'*': bullet = u'•'
2251-
level = len(spaces)/2 + 1
2252+
level = len(spaces)//2 + 1
22522253
line = spaces+u'<p class="list-%i">'%level+bullet+u'&nbsp; '
22532254
line = line + text + u'</p>\n'
22542255
#--Empty line

Mopy/bash/bosh/_saves.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
Oblivion only . We need this split into cosaves and proper saves module and
2626
coded for rest of the games."""
2727
# TODO: Oblivion only - we need to support rest of games - help needed
28+
from __future__ import division
2829
from collections import Counter
2930
from itertools import starmap, repeat
3031
from operator import attrgetter
@@ -529,7 +530,7 @@ def getMaster(modIndex):
529530
id_created[citem.fid] = citem
530531
for type in sorted(createdHisto.keys()):
531532
count,size = createdHisto[type]
532-
log(u' %d\t%d kb\t%s' % (count,size/1024,type))
533+
log(u' %d\t%d kb\t%s' % (count,size//1024,type))
533534
#--Fids
534535
lostRefs = 0
535536
idHist = [0]*256
@@ -608,7 +609,7 @@ def getMaster(modIndex):
608609
parentid = iref
609610
else:
610611
parentid = self.fids[iref]
611-
log(u'%6d %08X %08X %6d kb' % (count,iref,parentid,cumSize/1024))
612+
log(u'%6d %08X %08X %6d kb' % (count,iref,parentid,cumSize//1024))
612613

613614
def findBloating(self,progress=None):
614615
"""Analyzes file for bloating. Returns (createdCounts,nullRefCount)."""
@@ -833,8 +834,8 @@ def setCastWhenUsedEnchantmentNumberOfUses(self,uses):
833834
if record.enchantCost == 0: continue
834835
record.enchantCost = 0
835836
else:
836-
if record.enchantCost == max(record.chargeAmount/uses,1): continue
837-
record.enchantCost = max(record.chargeAmount/uses,1)
837+
if record.enchantCost == max(record.chargeAmount//uses,1): continue
838+
record.enchantCost = max(record.chargeAmount//uses,1)
838839
record.setChanged()
839840
record.getSize()
840841
count += 1

Mopy/bash/bosh/converters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# =============================================================================
2424
"""BAIN Converters aka BCFs"""
2525

26+
from __future__ import division
2627
import cPickle
2728
import re
2829
import sys

0 commit comments

Comments
 (0)