Reviewers: ,


Please review this at http://codereview.tryton.org/52002/

Affected files:
  M doc/installation.rst
  M setup.py
  M tryton/common/common.py
  M tryton/fingerprints.py
  M tryton/gui/main.py
  M tryton/gui/window/dbcreate.py
  M tryton/gui/window/form.py
  M tryton/gui/window/view_board/action.py
  M tryton/gui/window/view_form/model/record.py
  M tryton/gui/window/view_form/view/form.py
  M tryton/gui/window/view_form/view/form_gtk/parser.py
  M tryton/gui/window/view_form/view/form_gtk/reference.py
  M tryton/gui/window/view_form/view/form_gtk/selection.py
  M tryton/gui/window/view_form/view/graph_gtk/graph.py
  M tryton/gui/window/view_form/view/list_gtk/parser.py
  M tryton/gui/window/view_form/widget_search/selection.py
  M tryton/gui/window/win_export.py
  M tryton/pyson.py
  M tryton/rpc.py


Index: doc/installation.rst
===================================================================

--- a/doc/installation.rst
+++ b/doc/installation.rst
@@ -4,7 +4,7 @@
 Prerequisites
 -------------

- * Python 2.4 or later (http://www.python.org/)
+ * Python 2.6 or later (http://www.python.org/)
  * pygtk 2.0 or later (http://www.pygtk.org/)
  * librsvg (http://librsvg.sourceforge.net/)
  * python-dateutil (http://labix.org/python-dateutil)

Index: setup.py
===================================================================

--- a/setup.py
+++ b/setup.py
@@ -113,14 +113,6 @@

 execfile(os.path.join('tryton', 'version.py'))

-EXTRAS = {
-    'timezone': ['pytz'],
-}
-SIMPLEJSON = []
-if sys.version_info < (2, 6):
-    SIMPLEJSON = ['simplejson']
-    EXTRAS['ssl'] = ['ssl']
-
 dist = setup(name=PACKAGE,
     version=VERSION,
     description='Tryton client',
@@ -149,7 +141,6 @@
         'Natural Language :: Slovenian',
         'Natural Language :: Japanese',
         'Operating System :: OS Independent',
-        'Programming Language :: Python :: 2.5',
         'Programming Language :: Python :: 2.6',
         'Programming Language :: Python :: 2.7',
         'Topic :: Office/Business',
@@ -158,8 +149,10 @@
     install_requires=[
 #        "pygtk >= 2.0",
         "python-dateutil",
-    ] + SIMPLEJSON,
-    extras_require=EXTRAS,
+    ],
+    extras_require={
+        'timezone': ['pytz'],
+    },
     **args
 )


Index: tryton/common/common.py
===================================================================

--- a/tryton/common/common.py
+++ b/tryton/common/common.py
@@ -98,7 +98,8 @@
             self.load_icons(refresh=True)
         icon_ref = (self._name2id[iconname], iconname)
         idx = self._tryton_icons.index(icon_ref)
-        to_load = slice(max(0, idx-self.batchnum/2), idx+self.batchnum/2)
+        to_load = slice(max(0, idx - self.batchnum // 2),
+            idx + self.batchnum // 2)
         ids = [e[0] for e in self._tryton_icons[to_load]]
         try:
             icons = rpc.execute('model', 'ir.ui.icon', 'read', ids,
@@ -1101,7 +1102,7 @@
             dbs = refresh_dblist(self.host, self.port)
             createdb = True
         except TrytonServerError, exception:
-            if exception[0] == 'AccessDenied':
+            if exception.args[0] == 'AccessDenied':
                 dbs, createdb = [], False
             else:
                 raise

Index: tryton/fingerprints.py
===================================================================

--- a/tryton/fingerprints.py
+++ b/tryton/fingerprints.py
@@ -17,7 +17,7 @@
         if not os.path.isfile(KNOWN_HOSTS_PATH):
             return
         with open(KNOWN_HOSTS_PATH) as known_hosts:
-            for line in known_hosts.xreadlines():
+            for line in known_hosts:
                 line = line.strip()
                 try:
                     key, sha1 = line.split(' ')

Index: tryton/gui/main.py
===================================================================

--- a/tryton/gui/main.py
+++ b/tryton/gui/main.py
@@ -1439,7 +1439,7 @@
         hbox.pack_start(label, expand=True, fill=True)
         layout = label.get_layout()
         w, h = layout.get_size()
-        if (w / pango.SCALE) > 120 - noise_size:
+        if (w // pango.SCALE) > 120 - noise_size:
             label2 = gtk.Label('...')
             self.tooltips.set_tip(label2, page.name)
             hbox.pack_start(label2, expand=False, fill=False)
@@ -1605,14 +1605,14 @@
             rpcprogress.run()
         except TrytonServerError, exception:
             self.refresh_ssl()
-            if exception[0] == "AccessDenied":
+            if exception.args[0] == "AccessDenied":
                 common.warning(_("Wrong Tryton Server Password" \
                         "\nPlease try again."), self.window,
                         _('Access denied!'))
                 self.sig_db_drop(self.window)
             else:
                 common.warning(_('Database drop failed with ' \
-                        'error message:\n') + str(exception[0]), \
+                        'error message:\n') + str(exception.args[0]), \
                         self.window, _('Database drop failed!'))
             return
         self.refresh_ssl()
@@ -1638,21 +1638,21 @@
                 res = rpcprogress.run()
             except TrytonServerError, exception:
                 self.refresh_ssl()
-                if exception[0] == \
+                if exception.args[0] == \
                         "Couldn't restore database with password":
                     common.warning(_("It is not possible to restore a " \
                             "password protected database.\n" \
                             "Backup and restore needed to be proceed " \
                             "manual."), self.window, \
                             _('Database is password protected!'))
-                elif exception[0] == "AccessDenied":
+                elif exception.args[0] == "AccessDenied":
                     common.warning(_("Wrong Tryton Server Password.\n" \
                             "Please try again."), self.window, \
                             _('Access denied!'))
                     self.sig_db_restore(self.window)
                 else:
                     common.warning(_('Database restore failed with ' \
-                            'error message:\n') + str(exception[0]), \
+                            'error message:\n') + str(exception.args[0]), \
                             self.window, _('Database restore failed!'))
                 return
             self.refresh_ssl()
@@ -1680,19 +1680,19 @@
         try:
             dump_b64 = rpcprogress.run()
         except TrytonServerError, exception:
-            if exception[0] == "Couldn't dump database with password":
+            if exception.args[0] == "Couldn't dump database with password":
                 common.warning(_("It is not possible to dump a password " \
                         "protected Database.\nBackup and restore " \
                         "needed to be proceed manual."),
                         self.window, _('Database is password protected!'))
-            elif exception[0] == "AccessDenied":
+            elif exception.args[0] == "AccessDenied":
                 common.warning(_("Wrong Tryton Server Password.\n" \
                         "Please try again."), self.window,
                         _('Access denied!'))
                 self.sig_db_dump(self.window)
             else:
                 common.warning(_('Database dump failed with ' \
-                        'error message:\n') + str(exception[0]), \
+                        'error message:\n') + str(exception.args[0]), \
                         self.window, _('Database dump failed!'))
             rpc.logout()
             Main.get_main().refresh_ssl()

Index: tryton/gui/window/dbcreate.py
===================================================================

--- a/tryton/gui/window/dbcreate.py
+++ b/tryton/gui/window/dbcreate.py
@@ -373,7 +373,7 @@
                                     self.dialog)
                             rpcprogress.run()
                         except TrytonServerError, exception:
-                            if str(exception[0]) == "AccessDenied":
+                            if str(exception.args[0]) == "AccessDenied":
common.warning(_("Sorry, wrong password for " \ "the Tryton server. Please try again."),
                                     self.dialog, _("Access denied!"))
@@ -387,7 +387,7 @@
"be broken. Maybe drop this database! " \
                                     "Please check the error message for " \
                                     "possible informations.\n" \
- "Error message:\n") + str(exception[0]), + "Error message:\n") + str(exception.args[0]), self.dialog, _("Error creating database!"))
                             parent.present()
                             self.dialog.destroy()

Index: tryton/gui/window/form.py
===================================================================

--- a/tryton/gui/window/form.py
+++ b/tryton/gui/window/form.py
@@ -438,7 +438,7 @@

     def _record_message(self, screen, signal_data):
         name = '_'
-        if signal_data[0] >= 0:
+        if signal_data[0]:
             name = str(signal_data[0])
         msg = name + ' / ' + str(signal_data[1])
         if signal_data[1] < signal_data[2]:

Index: tryton/gui/window/view_board/action.py
===================================================================

--- a/tryton/gui/window/view_board/action.py
+++ b/tryton/gui/window/view_board/action.py
@@ -199,7 +199,7 @@

     def _sig_label(self, screen, signal_data):
         name = '_'
-        if signal_data[0] >= 0:
+        if signal_data[0]:
             name = str(signal_data[0])
         line = '(%s/%s)' % (name, signal_data[1])
         self.label.set_text(line)

Index: tryton/gui/window/view_form/model/record.py
===================================================================

--- a/tryton/gui/window/view_form/model/record.py
+++ b/tryton/gui/window/view_form/model/record.py
@@ -8,6 +8,7 @@
 import datetime
 import logging
 import time
+from functools import reduce
 from tryton.exceptions import TrytonServerError



Index: tryton/gui/window/view_form/view/form.py
===================================================================

--- a/tryton/gui/window/view_form/view/form.py
+++ b/tryton/gui/window/view_form/view/form.py
@@ -1,5 +1,7 @@
 #This file is part of Tryton.  The COPYRIGHT file at the top level of
 #this repository contains the full copyright notices and license terms.
+import operator
+from functools import reduce
 import gtk
 import gettext
 from tryton.common import message, TRYTON_ICON
@@ -229,7 +231,7 @@
             # Get first the lazy one to reduce number of requests
             fields = [(name, field.attrs.get('loading', 'eager'))
                     for name, field in record.group.fields.iteritems()]
-            fields.sort(lambda x, y: cmp(y[1], x[1]))
+            fields.sort(key=operator.itemgetter(1))
             for field, _ in fields:
                 record[field].get(record, check_load=False)
         for name, widgets in self.widgets.iteritems():

Index: tryton/gui/window/view_form/view/form_gtk/parser.py
===================================================================

--- a/tryton/gui/window/view_form/view/form_gtk/parser.py
+++ b/tryton/gui/window/view_form/view/form_gtk/parser.py
@@ -439,7 +439,8 @@
                         pos = gtk.POS_BOTTOM
                 notebook.set_tab_pos(pos)
                 notebook.set_border_width(3)
- container.wid_add(notebook, colspan=attrs.get('colspan', 4),
+                container.wid_add(notebook,
+                        colspan=int(attrs.get('colspan', 4)),
                         expand=True, fill=True)
widget, widgets, buttons, spam, notebook_list2, cursor_widget2 = \
                         self.parse(model_name, node, fields, notebook,

Index: tryton/gui/window/view_form/view/form_gtk/reference.py
===================================================================

--- a/tryton/gui/window/view_form/view/form_gtk/reference.py
+++ b/tryton/gui/window/view_form/view/form_gtk/reference.py
@@ -1,5 +1,6 @@
 #This file is part of Tryton.  The COPYRIGHT file at the top level of
 #this repository contains the full copyright notices and license terms.
+import operator
 import gtk
 import gobject
 import gettext
@@ -84,7 +85,7 @@
             except TrytonServerError, exception:
                 common.process_exception(exception, self.window)
                 selection = []
-        selection.sort(lambda x, y: cmp(x[1], y[1]))
+        selection.sort(key=operator.itemgetter(1))
         self.set_popdown(selection)

         self.last_key = (None, 0)

Index: tryton/gui/window/view_form/view/form_gtk/selection.py
===================================================================

--- a/tryton/gui/window/view_form/view/form_gtk/selection.py
+++ b/tryton/gui/window/view_form/view/form_gtk/selection.py
@@ -1,5 +1,6 @@
 #This file is part of Tryton.  The COPYRIGHT file at the top level of
 #this repository contains the full copyright notices and license terms.
+import operator
 import gtk
 import gobject
 from interface import WidgetInterface
@@ -48,7 +49,7 @@
                 selection = []
         self.selection = selection[:]
         if self.attrs.get('sort', True):
-            selection.sort(lambda x, y: cmp(x[1], y[1]))
+            selection.sort(key=operator.itemgetter(1))
         self.set_popdown(selection)

     def update_selection(self, record):

Index: tryton/gui/window/view_form/view/graph_gtk/graph.py
===================================================================

--- a/tryton/gui/window/view_form/view/graph_gtk/graph.py
+++ b/tryton/gui/window/view_form/view/graph_gtk/graph.py
@@ -2,6 +2,7 @@
 #this repository contains the full copyright notices and license terms.
#This code is inspired by the pycha project (http://www.lorenzogil.com/projects/pycha/)
 import gtk
+from functools import reduce
 from tryton.common import hex2rgb, generateColorscheme, DT_FORMAT, \
         DHM_FORMAT, COLOR_SCHEMES, datetime_strftime
 from tryton.pyson import PYSONDecoder
@@ -35,11 +36,11 @@
         widget_x, widget_y = widget.window.get_origin()
         width, height = widget.window.get_size()
         popup_width, popup_height = self.win.get_size()
-        if x < popup_width / 2:
-            x = popup_width / 2
-        if x > width - popup_width / 2:
-            x = width - popup_width / 2
-        pos_x = widget_x + x - popup_width / 2
+        if x < popup_width // 2:
+            x = popup_width // 2
+        if x > width - popup_width // 2:
+            x = width - popup_width // 2
+        pos_x = widget_x + x - popup_width // 2
         if pos_x < 0:
             pos_x = 0
         if y < popup_height + 5:
@@ -147,7 +148,7 @@
         # Fill the background
         cr.save()
         r, g, b = hex2rgb(self.attrs.get('background', '#d5d5d5'))
-        linear = cairo.LinearGradient(width / 2, 0, width / 2, height)
+        linear = cairo.LinearGradient(width // 2, 0, width // 2, height)
         linear.add_color_stop_rgb(0, 1, 1, 1)
         linear.add_color_stop_rgb(1, r, g, b)
         cr.set_source(linear)

Index: tryton/gui/window/view_form/view/list_gtk/parser.py
===================================================================

--- a/tryton/gui/window/view_form/view/list_gtk/parser.py
+++ b/tryton/gui/window/view_form/view/list_gtk/parser.py
@@ -28,6 +28,7 @@
 import datetime
 import time
 import gettext
+import operator

 _ = gettext.gettext

@@ -701,7 +702,7 @@
                     args) or [])
         self.selection = selection[:]
         if self.attrs.get('sort', True):
-            selection.sort(lambda x, y: cmp(x[1], y[1]))
+            selection.sort(key=operator.itemgetter(1))
         self.renderer.set_property('model', self.get_model(selection))
         self.renderer.set_property('text-column', 0)

@@ -786,7 +787,7 @@
             except TrytonServerError, exception:
                 common.process_exception(exception, self.window)
                 selection = []
-        selection.sort(lambda x, y: cmp(x[1], y[1]))
+        selection.sort(key=operator.itemgetter(1))
         for i, j in selection:
             self._selection[i] = str(j)


Index: tryton/gui/window/view_form/widget_search/selection.py
===================================================================

--- a/tryton/gui/window/view_form/widget_search/selection.py
+++ b/tryton/gui/window/view_form/widget_search/selection.py
@@ -1,6 +1,7 @@
 #This file is part of Tryton.  The COPYRIGHT file at the top level of
 #this repository contains the full copyright notices and license terms.
 import gtk
+import operator
 from interface import Interface
 import tryton.rpc as rpc
 import tryton.common as common
@@ -62,7 +63,7 @@
                 except TrytonServerError, exception:
                     common.process_exception(exception, parent)
                     selection = []
-        selection.sort(lambda x, y: cmp(x[1], y[1]))
+        selection.sort(key=operator.itemgetter(1))
         self.attrs['selection'] = selection
         self.set_popdown(selection)
         self.widget.pack_start(self.entry, True, True)

Index: tryton/gui/window/win_export.py
===================================================================

--- a/tryton/gui/window/win_export.py
+++ b/tryton/gui/window/win_export.py
@@ -437,7 +437,7 @@
             return True
         except IOError, exception:
             common.warning(_("Operation failed!\nError message:\n%s") \
-                     % (exception[0],), self.parent, _('Error'))
+                     % (exception.args[0],), self.parent, _('Error'))
             return False

     def datas_read(self, ids, model, fields, context=None):

Index: tryton/pyson.py
===================================================================

--- a/tryton/pyson.py
+++ b/tryton/pyson.py
@@ -6,6 +6,7 @@
 else:
     import json
 import datetime
+from functools import reduce


 class PYSON(object):

Index: tryton/rpc.py
===================================================================

--- a/tryton/rpc.py
+++ b/tryton/rpc.py
@@ -39,7 +39,7 @@
             try:
                 _SOCK.send(args)
             except socket.error, exception:
-                if exception[0] == 32:
+                if exception.args[0] == 32:
                     _SOCK.reconnect()
                     _SOCK.send(args)
                 else:
@@ -51,7 +51,7 @@
         logging.getLogger('rpc.result').debug(repr(res))
         return res
     except TrytonServerError, exception:
-        if exception[0] == 'AccessDenied':
+        if exception.args[0] == 'AccessDenied':
             raise
         else:
             logging.getLogger('rpc.result').debug(repr(None))
@@ -73,7 +73,7 @@
         try:
             _SOCK.send(args)
         except socket.error, exception:
-            if exception[0] == 32:
+            if exception.args[0] == 32:
                 _SOCK.reconnect()
                 _SOCK.send(args)
             else:
@@ -102,7 +102,7 @@
             try:
                 _SOCK.send(args)
             except socket.error, exception:
-                if exception[0] == 32:
+                if exception.args[0] == 32:
                     _SOCK.reconnect()
                     _SOCK.send(args)
                 else:



--
[email protected] mailing list

Reply via email to