3692656
From 8ed3bb621d123b13e434a198a90aa5b1d6452669 Mon Sep 17 00:00:00 2001
3692656
From: Ralph Bean <rbean@redhat.com>
3692656
Date: Mon, 2 Jul 2012 12:47:20 -0400
a4a352a
Subject: [PATCH 1/2] Py3-support.
3692656
3692656
---
3692656
 tablib/packages/xlrd/__init__.py    |    6 +++---
3692656
 tablib/packages/xlrd/biffh.py       |    4 ++--
3692656
 tablib/packages/xlrd/formatting.py  |   18 +++++++++---------
3692656
 tablib/packages/xlrd/formula.py     |    4 ++--
3692656
 tablib/packages/xlrd/sheet.py       |    6 +++---
3692656
 tablib/packages/xlrd/timemachine.py |    6 ------
3692656
 6 files changed, 19 insertions(+), 25 deletions(-)
3692656
3692656
diff --git a/tablib/packages/xlrd/__init__.py b/tablib/packages/xlrd/__init__.py
3692656
index 9097d9d..00fe65a 100644
3692656
--- a/tablib/packages/xlrd/__init__.py
3692656
+++ b/tablib/packages/xlrd/__init__.py
3692656
@@ -1087,7 +1087,7 @@ class Book(BaseObject):
3692656
                     fprintf(self.logfile, "*** No CODEPAGE record; assuming 1200 (utf_16_le)\n")
3692656
         else:
3692656
             codepage = self.codepage
3692656
-            if encoding_from_codepage.has_key(codepage):
3692656
+            if encoding_from_codepage.__contains__(codepage):
3692656
                 encoding = encoding_from_codepage[codepage]
3692656
             elif 300 <= codepage <= 1999:
3692656
                 encoding = 'cp' + str(codepage)
3692656
@@ -1338,7 +1338,7 @@ class Book(BaseObject):
3692656
             nobj = self.name_obj_list[namex]
3692656
             name_lcase = nobj.name.lower()
3692656
             key = (name_lcase, nobj.scope)
3692656
-            if name_and_scope_map.has_key(key):
3692656
+            if name_and_scope_map.__contains__(key):
3692656
                 msg = 'Duplicate entry %r in name_and_scope_map' % (key, )
3692656
                 if 0:
3692656
                     raise XLRDError(msg)
3692656
@@ -1346,7 +1346,7 @@ class Book(BaseObject):
3692656
                     if self.verbosity:
3692656
                         print >> f, msg
3692656
             name_and_scope_map[key] = nobj
3692656
-            if name_map.has_key(name_lcase):
3692656
+            if name_map.__contains__(name_lcase):
3692656
                 name_map[name_lcase].append((nobj.scope, nobj))
3692656
             else:
3692656
                 name_map[name_lcase] = [(nobj.scope, nobj)]
3692656
diff --git a/tablib/packages/xlrd/biffh.py b/tablib/packages/xlrd/biffh.py
3692656
index ba3b26c..5602aa9 100644
3692656
--- a/tablib/packages/xlrd/biffh.py
3692656
+++ b/tablib/packages/xlrd/biffh.py
3692656
@@ -222,7 +222,7 @@ _cell_opcode_list = [
3692656
 _cell_opcode_dict = {}
3692656
 for _cell_opcode in _cell_opcode_list:
3692656
     _cell_opcode_dict[_cell_opcode] = 1
3692656
-is_cell_opcode = _cell_opcode_dict.has_key
3692656
+is_cell_opcode = _cell_opcode_dict.__contains__
3692656
 
3692656
 # def fprintf(f, fmt, *vargs): f.write(fmt % vargs)
3692656
 
3692656
@@ -604,7 +604,7 @@ def biff_count_records(mem, stream_offset, stream_len, fout=sys.stdout):
3692656
             recname = biff_rec_name_dict.get(rc, None)
3692656
             if recname is None:
3692656
                 recname = "Unknown_0x%04X" % rc
3692656
-        if tally.has_key(recname):
3692656
+        if tally.__contains__(recname):
3692656
             tally[recname] += 1
3692656
         else:
3692656
             tally[recname] = 1
3692656
diff --git a/tablib/packages/xlrd/formatting.py b/tablib/packages/xlrd/formatting.py
3692656
index 302764b..b9e2fb5 100644
3692656
--- a/tablib/packages/xlrd/formatting.py
3692656
+++ b/tablib/packages/xlrd/formatting.py
3692656
@@ -470,7 +470,7 @@ def is_date_format_string(book, fmt):
3692656
     # TODO: u'[h]\\ \\h\\o\\u\\r\\s' ([h] means don't care about hours > 23)
3692656
     state = 0
3692656
     s = ''
3692656
-    ignorable = skip_char_dict.has_key
3692656
+    ignorable = skip_char_dict.__contains__
3692656
     for c in fmt:
3692656
         if state == 0:
3692656
             if c == u'"':
3692656
@@ -491,16 +491,16 @@ def is_date_format_string(book, fmt):
3692656
     if book.verbosity >= 4:
3692656
         print "is_date_format_string: reduced format is %r" % s
3692656
     s = fmt_bracketed_sub('', s)
3692656
-    if non_date_formats.has_key(s):
3692656
+    if non_date_formats.__contains__(s):
3692656
         return False
3692656
     state = 0
3692656
     separator = ";"
3692656
     got_sep = 0
3692656
     date_count = num_count = 0
3692656
     for c in s:
3692656
-        if date_char_dict.has_key(c):
3692656
+        if date_char_dict.__contains__(c):
3692656
             date_count += date_char_dict[c]
3692656
-        elif num_char_dict.has_key(c):
3692656
+        elif num_char_dict.__contains__(c):
3692656
             num_count += num_char_dict[c]
3692656
         elif c == separator:
3692656
             got_sep = 1
3692656
@@ -618,7 +618,7 @@ def palette_epilogue(book):
3692656
         cx = font.colour_index
3692656
         if cx == 0x7fff: # system window text colour
3692656
             continue
3692656
-        if book.colour_map.has_key(cx):
3692656
+        if book.colour_map.__contains__(cx):
3692656
             book.colour_indexes_used[cx] = 1
3692656
         else:
3692656
             print "Size of colour table:", len(book.colour_map)
3692656
@@ -675,7 +675,7 @@ def check_colour_indexes_in_obj(book, obj, orig_index):
3692656
         if hasattr(nobj, 'dump'):
3692656
             check_colour_indexes_in_obj(book, nobj, orig_index)
3692656
         elif attr.find('colour_index') >= 0:
3692656
-            if book.colour_map.has_key(nobj):
3692656
+            if book.colour_map.__contains__(nobj):
3692656
                 book.colour_indexes_used[nobj] = 1
3692656
                 continue
3692656
             oname = obj.__class__.__name__
3692656
@@ -704,7 +704,7 @@ def handle_xf(self, data):
3692656
     if bv >= 50 and not self.xfcount:
3692656
         # i.e. do this once before we process the first XF record
3692656
         for x in std_format_code_types.keys():
3692656
-            if not self.format_map.has_key(x):
3692656
+            if not self.format_map.__contains__(x):
3692656
                 ty = std_format_code_types[x]
3692656
                 fmt_str = std_format_strings[x]
3692656
                 fmtobj = Format(x, ty, fmt_str)
3692656
@@ -951,7 +951,7 @@ def handle_xf(self, data):
3692656
             msg = "WARNING *** XF[%d] is a style XF but parent_style_index is 0x%04x, not 0x0fff\n"
3692656
             fprintf(self.logfile, msg, xf.xf_index, xf.parent_style_index)
3692656
         check_colour_indexes_in_obj(self, xf, xf.xf_index)
3692656
-    if not self.format_map.has_key(xf.format_key):
3692656
+    if not self.format_map.__contains__(xf.format_key):
3692656
         msg = "WARNING *** XF[%d] unknown (raw) format key (%d, 0x%04x)\n"
3692656
         fprintf(self.logfile, msg,
3692656
                 xf.xf_index, xf.format_key, xf.format_key)
3692656
@@ -975,7 +975,7 @@ def xf_epilogue(self):
3692656
 
3692656
     for xfx in xrange(num_xfs):
3692656
         xf = self.xf_list[xfx]
3692656
-        if not self.format_map.has_key(xf.format_key):
3692656
+        if not self.format_map.__contains__(xf.format_key):
3692656
             msg = "ERROR *** XF[%d] unknown format key (%d, 0x%04x)\n"
3692656
             fprintf(self.logfile, msg,
3692656
                     xf.xf_index, xf.format_key, xf.format_key)
3692656
diff --git a/tablib/packages/xlrd/formula.py b/tablib/packages/xlrd/formula.py
3692656
index 4edbc29..28c4651 100644
3692656
--- a/tablib/packages/xlrd/formula.py
3692656
+++ b/tablib/packages/xlrd/formula.py
3692656
@@ -328,7 +328,7 @@ tAttrNames = {
3692656
 _error_opcodes = {}
3692656
 for _x in [0x07, 0x08, 0x0A, 0x0B, 0x1C, 0x1D, 0x2F]:
3692656
     _error_opcodes[_x] = 1
3692656
-is_error_opcode = _error_opcodes.has_key
3692656
+is_error_opcode = _error_opcodes.__contains__
3692656
 
3692656
 tRangeFuncs = (min, max, min, max, min, max)
3692656
 tIsectFuncs = (max, min, max, min, max, min)
3692656
@@ -672,7 +672,7 @@ binop_rules = {
3692656
     tAdd:   (_arith_argdict, oNUM, opr.add,  30, '+'),
3692656
     tSub:   (_arith_argdict, oNUM, opr.sub,  30, '-'),
3692656
     tMul:   (_arith_argdict, oNUM, opr.mul,  40, '*'),
3692656
-    tDiv:   (_arith_argdict, oNUM, opr.div,  40, '/'),
3692656
+    tDiv:   (_arith_argdict, oNUM, opr.truediv,  40, '/'),
3692656
     tPower: (_arith_argdict, oNUM, _opr_pow, 50, '^',),
3692656
     tConcat:(_strg_argdict, oSTRG, opr.add,  20, '&'),
3692656
     tLT:    (_cmp_argdict, oBOOL, _opr_lt,   10, '<'),
3692656
diff --git a/tablib/packages/xlrd/sheet.py b/tablib/packages/xlrd/sheet.py
3692656
index 70f7779..a8fc2af 100644
3692656
--- a/tablib/packages/xlrd/sheet.py
3692656
+++ b/tablib/packages/xlrd/sheet.py
3692656
@@ -1162,7 +1162,7 @@ class Sheet(BaseObject):
3692656
                             % (first_colx, last_colx)
3692656
                         continue
3692656
                     for colx in xrange(first_colx, last_colx+1):
3692656
-                        if self.colinfo_map.has_key(colx):
3692656
+                        if self.colinfo_map.__contains__(colx):
3692656
                             c = self.colinfo_map[colx]
3692656
                         else:
3692656
                             c = Colinfo()
3692656
@@ -1194,7 +1194,7 @@ class Sheet(BaseObject):
3692656
                         offset = 4 + 3 * (colx - first_colx)
3692656
                         cell_attr = data[offset:offset+3]
3692656
                         xf_index = self.fixed_BIFF2_xfindex(cell_attr, rowx=-1, colx=colx)
3692656
-                        if self.colinfo_map.has_key(colx):
3692656
+                        if self.colinfo_map.__contains__(colx):
3692656
                             c = self.colinfo_map[colx]
3692656
                         else:
3692656
                             c = Colinfo()
3692656
@@ -1245,7 +1245,7 @@ class Sheet(BaseObject):
3692656
         book.xf_list.append(xf)
3692656
         if blah:
3692656
             xf.dump(self.logfile, header="=== Faked XF %d ===" % xfx, footer="======")
3692656
-        if not book.format_map.has_key(xf.format_key):
3692656
+        if not book.format_map.__contains__(xf.format_key):
3692656
             msg = "ERROR *** XF[%d] unknown format key (%d, 0x%04x)\n"
3692656
             fprintf(self.logfile, msg,
3692656
                     xf.xf_index, xf.format_key, xf.format_key)
3692656
diff --git a/tablib/packages/xlrd/timemachine.py b/tablib/packages/xlrd/timemachine.py
3692656
index 1718c03..2478887 100644
3692656
--- a/tablib/packages/xlrd/timemachine.py
3692656
+++ b/tablib/packages/xlrd/timemachine.py
3692656
@@ -22,12 +22,6 @@ if sys.version.find("IronPython") >= 0:
3692656
 else:
3692656
     from array import array as array_array
3692656
 
3692656
-if python_version < (2, 2):
3692656
-    class object:
3692656
-        pass
3692656
-    False = 0
3692656
-    True = 1
3692656
-
3692656
 def int_floor_div(x, y):
3692656
     return divmod(x, y)[0]
3692656
 
3692656
-- 
3692656
1.7.10.4
3692656