Use the print function everywhere

python modernize.py --no-six -f libmodernize.fixes.fix_print -w

With manual fixes as the import was put always on top.
This commit is contained in:
Laurent Bachelier 2014-10-06 14:23:20 +02:00
commit 74a4ef6723
73 changed files with 499 additions and 442 deletions

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import hashlib
import sys
@ -92,13 +93,13 @@ class Tile(object):
self.map.append(pxls)
def display(self):
print '-' * (len(self.map) * 2 + 2)
print('-' * (len(self.map) * 2 + 2))
for y in xrange(len(self.map[0])):
sys.stdout.write('|')
for x in xrange(len(self.map)):
sys.stdout.write('%s' % ('XX' if self.map[x][y] else ' '))
print '|'
print '-' * (len(self.map) * 2 + 2)
print('|')
print('-' * (len(self.map) * 2 + 2))
def checksum(self):
s = ''
@ -113,9 +114,9 @@ class Tile(object):
try:
return self.hash[checksum]
except KeyError:
print 'Unable te resolve:'
print('Unable te resolve:')
self.display()
print 'hash: %s' % checksum
print('hash: %s' % checksum)
raise CaptchaError()
@ -175,11 +176,11 @@ class Decoder(object):
checksum = tile.checksum()
if checksum in self.hash:
print 'Skipping %s' % self.hash[checksum]
print('Skipping %s' % self.hash[checksum])
continue
tile.display()
print 'Checksum: %s' % checksum
print('Checksum: %s' % checksum)
ntry = 2
while ntry:
sys.stdout.write('Enter the letter: ')
@ -187,9 +188,9 @@ class Decoder(object):
ntry -= 1
if len(l) != 1:
print 'Error: please enter only one letter'
print('Error: please enter only one letter')
elif l in self.hash.itervalues():
print 'Warning! This letter has already been catched!'
print('Warning! This letter has already been catched!')
else:
ntry = 0
@ -200,13 +201,13 @@ class Decoder(object):
while True:
self.process()
except KeyboardInterrupt:
print ''
print 'hash = {'
print('')
print('hash = {')
l = sorted(self.hash.iteritems(), key=lambda (k,v): (v,k))
for hash, value in l:
print ' \'%s\': %s' % (hash, value)
print(' \'%s\': %s' % (hash, value))
print '}'
print('}')
if __name__ == '__main__':
d = Decoder()

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
from random import randint
@ -93,7 +94,7 @@ class ProfilesWalker(Optimization):
self.profiles_queue.add(id)
return
except Exception as e:
print e
print(e)
finally:
if self.view_cron is not None:
self.view_cron = self.sched.schedule(randint(5, 10), self.view_profile)

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
from weboob.tools.browser import BrowserUnavailable
from weboob.capabilities.dating import Optimization
@ -45,5 +46,5 @@ class Visibility(Optimization):
with self.browser:
self.browser.login()
except BrowserUnavailable as e:
print str(e)
print(str(e))
pass

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
from weboob.tools.browser import Page, BrowserIncorrectPassword
import urllib2
@ -121,4 +122,4 @@ class AuthenticationPage(Page):
def print_cookies(self):
for c in self.browser._ua_handlers["_cookies"].cookiejar:
print "%s : %s" % (c.name, c.value)
print("%s : %s" % (c.name, c.value))

View file

@ -17,6 +17,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import re
from decimal import Decimal
@ -217,8 +219,8 @@ class CardsPage(Page):
try:
t.id = t.unique_id(seen)
except UnicodeEncodeError:
print t
print t.label
print(t)
print(t.label)
raise
yield t

View file

@ -18,6 +18,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
from weboob.tools.mech import ClientForm
ControlNotFoundError = ClientForm.ControlNotFoundError
@ -73,7 +75,7 @@ class VideoPage(Page):
obj = self.parser.select(self.document.getroot(), 'meta[name=available]', 1)
if obj is not None:
value = obj.attrib['content']
print value
print(value)
m = re.match('(\d\d)-(\d\d)-(\d\d\d\d)\s*(\d\d):(\d\d)', value)
if not m:
raise BrokenPageError('Unable to parse datetime: %r' % value)

View file

@ -18,6 +18,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import urllib
from weboob.tools.browser import Browser, BrowserIncorrectPassword, BrowserUnavailable,\
@ -149,7 +151,7 @@ class GDCVaultBrowser(Browser):
return self.page.iter_videos()
def latest_videos(self):
print "browser:latest_videos()"
print("browser:latest_videos()")
#self.home()
self.location('/free')
assert self.is_on_page(IndexPage)

View file

@ -18,6 +18,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import urllib
import mechanize
@ -85,7 +86,7 @@ class HelloBank(Browser):
accounts = self.page.get_accounts()
if len(accounts) == 0:
print 'no accounts'
print('no accounts')
# oops, no accounts? check if we have not exhausted the allowed use
# of this password
for img in self.document.getroot().cssselect('img[align="middle"]'):

View file

@ -18,6 +18,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
from decimal import Decimal
@ -66,7 +67,7 @@ class AccountsList(Page):
l.append(account)
if len(l) == 0:
print 'no accounts'
print('no accounts')
# oops, no accounts? check if we have not exhausted the allowed use
# of this password
for img in self.document.getroot().cssselect('img[align="middle"]'):

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
from random import randint
@ -100,7 +101,7 @@ class ProfilesWalker(Optimization):
self.profiles_queue.add(id)
return
except Exception as e:
print e
print(e)
finally:
if self.view_cron is not None:
self.view_cron = self.sched.schedule(randint(5, 10), self.view_profile)

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import hashlib
@ -133,7 +134,7 @@ class Tile(object):
raise TileError('Tile not found ' + sum, self)
def display(self):
print self.checksum()
print(self.checksum())
#im = Image.new('RGB', (24, 23))
#im.putdata(self.map)
#im.save('/tmp/%s.png' % self.checksum())

View file

@ -18,6 +18,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import re
from weboob.browser2.page import JsonPage, HTMLPage, method
@ -142,7 +144,7 @@ class DeparturesPage2(HTMLPage):
form['moiHoraire'] = '%s|%s' % (date.month, date.year)
form['heureHoraire'] = date.hour
form['minuteHoraire'] = date.minute
print form
print(form)
form.submit()