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