From e41f1ce2a8e44178438bb9356e7d0d2934356999 Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Fri, 16 Aug 2013 22:21:29 +1000 Subject: [PATCH 01/21] Create README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..4ed6e04 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +xlwt +==== + +Fork of https://github.com/python-excel/xlwt for Python 3 support. The original claims to support Python 2.3 to 2.6 only. + +Library to create spreadsheet files compatible with MS Excel 97/2000/XP/2003 XLS files, on any platform, with Python 2.7 and Python 3.3. From 036ca124f466df27d99fa04e60132d716d52072b Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Sat, 17 Aug 2013 00:47:26 +1000 Subject: [PATCH 02/21] Add Py3 patches. * Currently uses the future module for py2k compatibility. Only a couple of functions (just ``range`` and ``str``, I think) are used, so this dependency could be removed easily enough. --- xlwt/BIFFRecords.py | 66 +++++++++++++++++----------------- xlwt/Cell.py | 15 ++++---- xlwt/Column.py | 4 ++- xlwt/CompoundDoc.py | 72 ++++++++++++++++++++------------------ xlwt/ExcelFormula.py | 14 +++++--- xlwt/ExcelFormulaLexer.py | 13 ++++--- xlwt/ExcelFormulaParser.py | 35 +++++++++--------- xlwt/ExcelMagic.py | 2 ++ xlwt/Formatting.py | 4 ++- xlwt/Row.py | 26 ++++++++------ xlwt/Style.py | 27 ++++++++------ xlwt/UnicodeUtils.py | 14 ++++---- xlwt/Utils.py | 6 ++-- xlwt/Workbook.py | 34 +++++++++--------- xlwt/Worksheet.py | 44 ++++++++++++----------- xlwt/__init__.py | 17 ++++----- 16 files changed, 213 insertions(+), 180 deletions(-) diff --git a/xlwt/BIFFRecords.py b/xlwt/BIFFRecords.py index 5867bf8..f2c6cbe 100644 --- a/xlwt/BIFFRecords.py +++ b/xlwt/BIFFRecords.py @@ -1,6 +1,10 @@ # -*- coding: cp1252 -*- +from __future__ import absolute_import +from __future__ import division +from __future__ import unicode_literals from struct import pack -from UnicodeUtils import upack1, upack2, upack2rt +from .UnicodeUtils import upack1, upack2, upack2rt +from future.builtins import * class SharedStringTable(object): _SST_ID = 0x00FC @@ -20,8 +24,8 @@ def __init__(self, encoding): self._current_piece = None def add_str(self, s): - if self.encoding != 'ascii' and not isinstance(s, unicode): - s = unicode(s, self.encoding) + if self.encoding != 'ascii' and not isinstance(s, str): + s = str(s, self.encoding) self._add_calls += 1 if s not in self._str_indexes: idx = len(self._str_indexes) + len(self._rt_indexes) @@ -35,8 +39,8 @@ def add_str(self, s): def add_rt(self, rt): rtList = [] for s, xf in rt: - if self.encoding != 'ascii' and not isinstance(s, unicode): - s = unicode(s, self.encoding) + if self.encoding != 'ascii' and not isinstance(s, str): + s = str(s, self.encoding) rtList.append((s, xf)) rt = tuple(rtList) self._add_calls += 1 @@ -63,16 +67,16 @@ def rt_index(self, rt): return self._rt_indexes[rt] def get_biff_record(self): - self._sst_record = '' + self._sst_record = b'' self._continues = [None, None] self._current_piece = pack(' portion_counter: + if str_chunk_num != portion_counter: portion_counter = str_chunk_num abs_stream_pos += portions_len[portion_counter-1] #print hex(abs_stream_pos) @@ -1300,11 +1300,11 @@ def __init__(self, options, first_visible_row, first_visible_col, grid_colour, 0x00, preview_magn, normal_magn, - 0x00L) + 0x00) if scl_magn is not None: self._scl_rec = pack('<4H', 0x00A0, 4, scl_magn, 100) else: - self._scl_rec = '' + self._scl_rec = b'' def get(self): return self.get_rec_header() + self._rec_data + self._scl_rec @@ -1491,7 +1491,7 @@ def __init__(self, merged_list): i = len(merged_list) - 1 while i >= 0: j = 0 - merged = '' + merged = b'' while (i >= 0) and (j < 0x403): r1, r2, c1, c2 = merged_list[i] merged += pack('<4H', r1, r2, c1, c2) @@ -2378,7 +2378,7 @@ def __init__(self, refs): def get(self): res = [] nrefs = len(self.refs) - for idx in xrange(0, nrefs, _maxRefPerRecord): + for idx in range(0, nrefs, _maxRefPerRecord): chunk = self.refs[idx:idx+_maxRefPerRecord] krefs = len(chunk) if idx: # CONTINUE record @@ -2387,7 +2387,7 @@ def get(self): header = pack("> 9 dir_sect_count = len(self.dir_stream) >> 9 - + total_sect_count = book_sect_count + dir_sect_count SAT_sect_count = 0 MSAT_sect_count = 0 @@ -154,7 +156,7 @@ def __build_sat(self): sect += 1 while sect < book_sect_count + MSAT_sect_count + SAT_sect_count: - self.SAT_sect.append(sect) + self.SAT_sect.append(sect) SAT[sect] = self.SID_USED_BY_SAT sect += 1 @@ -205,17 +207,17 @@ def __build_sat(self): def __build_header(self): - doc_magic = '\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1' - file_uid = '\x00'*16 - rev_num = '\x3E\x00' - ver_num = '\x03\x00' - byte_order = '\xFE\xFF' + doc_magic = b'\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1' + file_uid = b'\x00'*16 + rev_num = b'\x3E\x00' + ver_num = b'\x03\x00' + byte_order = b'\xFE\xFF' log_sect_size = struct.pack(' >= <= """): - print t - except TokenStreamException, e: - print "error:", e + print(t) + except TokenStreamException as e: + print("error:", e) diff --git a/xlwt/ExcelFormulaParser.py b/xlwt/ExcelFormulaParser.py index 2c261b4..27f3469 100644 --- a/xlwt/ExcelFormulaParser.py +++ b/xlwt/ExcelFormulaParser.py @@ -1,18 +1,15 @@ ### $ANTLR 2.7.7 (20060930): "xlwt/excel-formula.g" -> "ExcelFormulaParser.py"$ ### import antlr and other modules .. +from __future__ import absolute_import import sys -import antlr - -version = sys.version.split()[0] -if version < '2.2.1': - False = 0 -if version < '2.3': - True = not False -### header action >>> import struct -import Utils -from UnicodeUtils import upack1 -from ExcelMagic import * + +from future import * + +from . import antlr +from . import Utils +from .UnicodeUtils import upack1 +from .ExcelMagic import * _RVAdelta = {"R": 0, "V": 0x20, "A": 0x40} _RVAdeltaRef = {"R": 0, "V": 0x20, "A": 0x40, "D": 0x20} @@ -76,7 +73,7 @@ def __init__(self, *args, **kwargs): antlr.LLkParser.__init__(self, *args, **kwargs) self.tokenNames = _tokenNames ### __init__ header action >>> - self.rpn = "" + self.rpn = b"" self.sheet_references = [] self.xcall_references = [] ### __init__ header action <<< @@ -388,21 +385,21 @@ def primary(self, chunklens = [len(chunk) for chunk in rpn_chunks] skiplens = [0] * nc skiplens[-1] = 3 - for ic in xrange(nc-1, 0, -1): + for ic in range(nc-1, 0, -1): skiplens[ic-1] = skiplens[ic] + chunklens[ic] + 4 jump_pos = [2 * nc + 2] - for ic in xrange(nc): + for ic in range(nc): jump_pos.append(jump_pos[-1] + chunklens[ic] + 4) chunk_shift = 2 * nc + 6 # size of tAttrChoose - for ic in xrange(nc): - for refx in xrange(ref_markers[ic], ref_markers[ic+1]): + for ic in range(nc): + for refx in range(ref_markers[ic], ref_markers[ic+1]): ref = self.sheet_references[refx] self.sheet_references[refx] = (ref[0], ref[1], ref[2] + chunk_shift) chunk_shift += 4 # size of tAttrSkip choose_rpn = [] choose_rpn.append(struct.pack(" max_argc or arg_count < min_argc: - raise Exception, "%d parameters for function: %s" % (arg_count, func_tok.text) + raise Exception("%d parameters for function: %s" % (arg_count, func_tok.text)) if xcall: func_ptg = ptgFuncVarR + _RVAdelta[func_type] self.rpn += struct.pack("<2BH", func_ptg, arg_count + 1, 255) # 255 is magic XCALL function @@ -669,7 +666,7 @@ def expr_list(self, ### generate bit set def mk_tokenSet_0(): ### var1 - data = [ 37681618946L, 0L] + data = [ 37681618946, 0] return data _tokenSet_0 = antlr.BitSet(mk_tokenSet_0()) diff --git a/xlwt/ExcelMagic.py b/xlwt/ExcelMagic.py index 2c29262..c10778a 100644 --- a/xlwt/ExcelMagic.py +++ b/xlwt/ExcelMagic.py @@ -2,6 +2,8 @@ """ lots of Excel Magic Numbers """ +from __future__ import absolute_import, unicode_literals +from future import * # Boundaries BIFF8+ diff --git a/xlwt/Formatting.py b/xlwt/Formatting.py index 76b8e8f..6ae1946 100644 --- a/xlwt/Formatting.py +++ b/xlwt/Formatting.py @@ -28,7 +28,9 @@ ''' -import BIFFRecords +from __future__ import absolute_import + +from . import BIFFRecords class Font(object): diff --git a/xlwt/Row.py b/xlwt/Row.py index 5664e87..ad0676d 100644 --- a/xlwt/Row.py +++ b/xlwt/Row.py @@ -1,12 +1,15 @@ # -*- coding: windows-1252 -*- -import BIFFRecords -import Style -from Cell import StrCell, BlankCell, NumberCell, FormulaCell, MulBlankCell, BooleanCell, ErrorCell, \ +from __future__ import absolute_import +from __future__ import division +from . import BIFFRecords +from . import Style +from .Cell import StrCell, BlankCell, NumberCell, FormulaCell, MulBlankCell, BooleanCell, ErrorCell, \ _get_cells_biff_data_mul -import ExcelFormula +from . import ExcelFormula import datetime as dt -from Formatting import Font +from .Formatting import Font +from future.builtins import * try: from decimal import Decimal @@ -165,11 +168,11 @@ def insert_cell(self, col_index, cell_obj): def insert_mulcells(self, colx1, colx2, cell_obj): self.insert_cell(colx1, cell_obj) - for col_index in xrange(colx1+1, colx2+1): + for col_index in range(colx1+1, colx2+1): self.insert_cell(col_index, None) def get_cells_biff_data(self): - cell_items = [item for item in self.__cells.iteritems() if item[1] is not None] + cell_items = [item for item in self.__cells.items() if item[1] is not None] cell_items.sort() # in column order return _get_cells_biff_data_mul(self.__idx, cell_items) # previously: @@ -234,7 +237,7 @@ def write(self, col, label, style=Style.default_style): self.__adjust_height(style) self.__adjust_bound_col_idx(col) style_index = self.__parent_wb.add_style(style) - if isinstance(label, basestring): + if isinstance(label, bytes) or isinstance(label, str): if len(label) > 0: self.insert_cell(col, StrCell(self.__idx, col, style_index, self.__parent_wb.add_str(label)) @@ -243,7 +246,7 @@ def write(self, col, label, style=Style.default_style): self.insert_cell(col, BlankCell(self.__idx, col, style_index)) elif isinstance(label, bool): # bool is subclass of int; test bool first self.insert_cell(col, BooleanCell(self.__idx, col, style_index, label)) - elif isinstance(label, (float, int, long, Decimal)): + elif isinstance(label, (float, int, Decimal)): self.insert_cell(col, NumberCell(self.__idx, col, style_index, label)) elif isinstance(label, (dt.datetime, dt.date, dt.time)): date_number = self.__excel_date_dt(label) @@ -271,11 +274,12 @@ def __rich_text_helper(self, col, rich_text_list, style, style_index=None): default_font = None rt = [] for data in rich_text_list: - if isinstance(data, basestring): + if isinstance(data, str) or isinstance(data, bytes): s = data font = default_font elif isinstance(data, (list, tuple)): - if not isinstance(data[0], basestring) or not isinstance(data[1], Font): + if not (isinstance(data[0], str) or isinstance(data[0], bytes)) \ + or not isinstance(data[1], Font): raise Exception ("Unexpected data type %r, %r" % (type(data[0]), type(data[1]))) s = data[0] font = self.__parent_wb.add_font(data[1]) diff --git a/xlwt/Style.py b/xlwt/Style.py index 2ebcffd..7ad2c88 100644 --- a/xlwt/Style.py +++ b/xlwt/Style.py @@ -1,7 +1,12 @@ # -*- coding: windows-1252 -*- -import Formatting -from BIFFRecords import NumberFormatRecord, XFRecord, StyleRecord +from __future__ import print_function +from __future__ import absolute_import +# -*- coding: windows-1252 -*- + +from . import Formatting +from .BIFFRecords import NumberFormatRecord, XFRecord, StyleRecord +from future import * FIRST_USER_DEFINED_NUM_FORMAT_IDX = 164 @@ -178,7 +183,7 @@ def _add_font(self, font): def get_biff_data(self): - result = '' + result = b'' result += self._all_fonts() result += self._all_num_formats() result += self._all_cell_styles() @@ -186,9 +191,9 @@ def get_biff_data(self): return result def _all_fonts(self): - result = '' + result = b'' if self.style_compression: - alist = self._font_x2id.items() + alist = list(self._font_x2id.items()) else: alist = [(x, o) for o, x in self._font_id2x.items()] alist.sort() @@ -197,7 +202,7 @@ def _all_fonts(self): return result def _all_num_formats(self): - result = '' + result = b'' alist = [ (v, k) for k, v in self._num_formats.items() @@ -209,11 +214,11 @@ def _all_num_formats(self): return result def _all_cell_styles(self): - result = '' + result = b'' for i in range(0, 16): result += XFRecord(self._default_xf, 'style').get() if self.style_compression == 2: - alist = self._xf_x2id.items() + alist = list(self._xf_x2id.items()) else: alist = [(x, o) for o, x in self._xf_id2x.items()] alist.sort() @@ -658,11 +663,11 @@ def _parse_strg_to_obj(strg, obj, parse_dict, v = ' '.join(guff[1:]) if not v: raise EasyXFCallerError("no value supplied for %s.%s" % (section, k)) - for counter in xrange(2): + for counter in range(2): result = section_dict.get(k) if result is None: raise EasyXFCallerError('%s.%s is not a known attribute' % (section, k)) - if not isinstance(result, basestring): + if not (isinstance(result, bytes) or isinstance(result, str)): break # synonym old_k = k @@ -691,7 +696,7 @@ def _parse_strg_to_obj(strg, obj, parse_dict, orig = getattr(section_obj, k) except AttributeError: raise EasyXFAuthorError('%s.%s in dictionary but not in supplied object' % (section, k)) - if debug: print "+++ %s.%s = %r # %s; was %r" % (section, k, value, v, orig) + if debug: print("+++ %s.%s = %r # %s; was %r" % (section, k, value, v, orig)) setattr(section_obj, k, value) def easyxf(strg_to_parse="", num_format_str=None, diff --git a/xlwt/UnicodeUtils.py b/xlwt/UnicodeUtils.py index 9d5a266..5a88c4c 100644 --- a/xlwt/UnicodeUtils.py +++ b/xlwt/UnicodeUtils.py @@ -40,14 +40,16 @@ ''' +from __future__ import absolute_import from struct import pack +from future.builtins import * def upack2(s, encoding='ascii'): # If not unicode, make it so. - if isinstance(s, unicode): + if isinstance(s, str): us = s else: - us = unicode(s, encoding) + us = str(s, encoding) # Limit is based on number of content characters # (not on number of bytes in packed result) len_us = len(us) @@ -77,8 +79,8 @@ def upack2rt(rt, encoding='ascii'): # convert rt strings to unicode if not already unicode # also generate the formatting run for the styles added for s, fontx in rt: - if not isinstance(s, unicode): - s = unicode(s, encoding) + if not isinstance(s, str): + s = str(s, encoding) us += s if fontx is not None: # code in Rows.py ensures that @@ -104,10 +106,10 @@ def upack2rt(rt, encoding='ascii'): def upack1(s, encoding='ascii'): # Same as upack2(), but with a one-byte length field. - if isinstance(s, unicode): + if isinstance(s, str): us = s else: - us = unicode(s, encoding) + us = str(s, encoding) len_us = len(us) if len_us > 255: raise Exception('String longer than 255 characters') diff --git a/xlwt/Utils.py b/xlwt/Utils.py index 4ef94da..099adc4 100644 --- a/xlwt/Utils.py +++ b/xlwt/Utils.py @@ -2,8 +2,10 @@ # Utilities for work with reference to cells and with sheetnames +from __future__ import absolute_import, unicode_literals import re -from ExcelMagic import MAX_ROW, MAX_COL +from .ExcelMagic import MAX_ROW, MAX_COL +from future import * _re_cell_ex = re.compile(r"(\$?)([A-I]?[A-Z])(\$?)(\d+)", re.IGNORECASE) _re_row_range = re.compile(r"\$?(\d+):\$?(\d+)") @@ -17,7 +19,7 @@ def col_by_name(colname): """ col = 0 power = 1 - for i in xrange(len(colname)-1, -1, -1): + for i in range(len(colname)-1, -1, -1): ch = colname[i] col += (ord(ch) - ord('A') + 1) * power power *= 26 diff --git a/xlwt/Workbook.py b/xlwt/Workbook.py index fecb957..88603b5 100644 --- a/xlwt/Workbook.py +++ b/xlwt/Workbook.py @@ -40,8 +40,10 @@ EOF ''' -import BIFFRecords -import Style +from __future__ import absolute_import +from . import BIFFRecords +from . import Style +from future import * class Workbook(object): @@ -338,8 +340,8 @@ def rt_index(self, rt): return self.__sst.rt_index(rt) def add_sheet(self, sheetname, cell_overwrite_ok=False): - import Worksheet, Utils - if not isinstance(sheetname, unicode): + from xlwt import Worksheet, Utils + if not isinstance(sheetname, str): sheetname = sheetname.decode(self.encoding) if not Utils.valid_sheet_name(sheetname): raise Exception("invalid worksheet name %r" % sheetname) @@ -347,7 +349,7 @@ def add_sheet(self, sheetname, cell_overwrite_ok=False): if lower_name in self.__worksheet_idx_from_name: raise Exception("duplicate worksheet name %r" % sheetname) self.__worksheet_idx_from_name[lower_name] = len(self.__worksheets) - self.__worksheets.append(Worksheet.Worksheet(sheetname, self, cell_overwrite_ok)) + self.__worksheets.append(Worksheet(sheetname, self, cell_overwrite_ok)) return self.__worksheets[-1] def get_sheet(self, sheetnum): @@ -430,7 +432,7 @@ def add_sheet_reference(self, formula): self.setup_xcall() # print funcname, self._supbook_xref patches.append((offset, self._xcall_supbook_ref)) - if not isinstance(funcname, unicode): + if not isinstance(funcname, str): funcname = funcname.decode(self.encoding) if funcname in self._xcall_xref: idx = self._xcall_xref[funcname] @@ -505,7 +507,7 @@ def __codepage_rec(self): def __country_rec(self): if not self.__country_code: - return '' + return b'' return BIFFRecords.CountryRecord(self.__country_code, self.__country_code).get() def __dsf_rec(self): @@ -534,7 +536,7 @@ def __all_fonts_num_formats_xf_styles_rec(self): def __palette_rec(self): if self.__custom_palette_b8 is None: - return '' + return b'' info = BIFFRecords.PaletteRecord(self.__custom_palette_b8).get() return info @@ -553,12 +555,12 @@ def __boundsheets_rec(self, data_len_before, data_len_after, sheet_biff_lens): boundsheets_len = 0 for sheet in self.__worksheets: boundsheets_len += len(BIFFRecords.BoundSheetRecord( - 0x00L, sheet.visibility, sheet.name, self.encoding + 0x00, sheet.visibility, sheet.name, self.encoding ).get()) start = data_len_before + boundsheets_len + data_len_after - result = '' + result = b'' for sheet_biff_len, sheet in zip(sheet_biff_lens, self.__worksheets): result += BIFFRecords.BoundSheetRecord( start, sheet.visibility, sheet.name, self.encoding @@ -588,23 +590,23 @@ def __all_links_rec(self): raise Exception('unknown supbook stype %r' % stype) if len(self.__sheet_refs) > 0: # get references in index order - temp = [(idx, ref) for ref, idx in self.__sheet_refs.items()] + temp = [(idx, ref) for ref, idx in list(self.__sheet_refs.items())] temp.sort() temp = [ref for idx, ref in temp] externsheet_record = BIFFRecords.ExternSheetRecord(temp).get() pieces.append(externsheet_record) - return ''.join(pieces) + return b''.join(pieces) def __sst_rec(self): return self.__sst.get_biff_record() def __ext_sst_rec(self, abs_stream_pos): - return '' + return b'' #return BIFFRecords.ExtSSTRecord(abs_stream_pos, self.sst_record.str_placement, #self.sst_record.portions_len).get() def get_biff_data(self): - before = '' + before = b'' before += self.__bof_rec() before += self.__intf_hdr_rec() before += self.__intf_mms_rec() @@ -641,7 +643,7 @@ def get_biff_data(self): eof = self.__eof_rec() self.__worksheets[self.__active_sheet].selected = True - sheets = '' + sheets = b'' sheet_biff_lens = [] for sheet in self.__worksheets: data = sheet.get_biff_data() @@ -656,7 +658,7 @@ def get_biff_data(self): return before + bundlesheets + after + ext_sst + eof + sheets def save(self, filename): - import CompoundDoc + from . import CompoundDoc doc = CompoundDoc.XlsDoc() doc.save(filename, self.get_biff_data()) diff --git a/xlwt/Worksheet.py b/xlwt/Worksheet.py index cd90ccd..1c47485 100644 --- a/xlwt/Worksheet.py +++ b/xlwt/Worksheet.py @@ -34,10 +34,12 @@ EOF ''' -import BIFFRecords -import Bitmap -import Style +from __future__ import absolute_import +from . import BIFFRecords +from . import Bitmap +from . import Style import tempfile +from future import * class Worksheet(object): @@ -48,11 +50,11 @@ class Worksheet(object): ## Constructor ################################################################# def __init__(self, sheetname, parent_book, cell_overwrite_ok=False): - import Row - self.Row = Row.Row + from xlwt import Row + self.Row = Row - import Column - self.Column = Column.Column + from xlwt import Column + self.Column = Column self.__name = sheetname self.__parent = parent_book @@ -61,7 +63,7 @@ def __init__(self, sheetname, parent_book, cell_overwrite_ok=False): self.__rows = {} self.__cols = {} self.__merged_ranges = [] - self.__bmp_rec = '' + self.__bmp_rec = b'' self.__show_formulas = 0 self.__show_grid = 1 @@ -187,7 +189,7 @@ def __init__(self, sheetname, parent_book, cell_overwrite_ok=False): self.__obj_protect = 0 self.__protect = 0 self.__scen_protect = 0 - self.__password = '' + self.__password = b'' self.last_used_row = 0 self.first_used_row = 65535 @@ -719,7 +721,7 @@ def get_horz_page_breaks(self): def set_header_str(self, value): if isinstance(value, str): - value = unicode(value, self.__parent.encoding) + value = str(value, self.__parent.encoding) self.__header_str = value def get_header_str(self): @@ -731,7 +733,7 @@ def get_header_str(self): def set_footer_str(self, value): if isinstance(value, str): - value = unicode(value, self.__parent.encoding) + value = str(value, self.__parent.encoding) self.__footer_str = value def get_footer_str(self): @@ -1143,7 +1145,7 @@ def __eof_rec(self): return BIFFRecords.EOFRecord().get() def __colinfo_rec(self): - result = '' + result = b'' for col in self.__cols: result += self.__cols[col].get_biff_record() return result @@ -1194,7 +1196,7 @@ def __window2_rec(self): def __panes_rec(self): if self.__vert_split_pos is None and self.__horz_split_pos is None: - return "" + return b"" if self.__vert_split_pos is None: self.__vert_split_pos = 0 @@ -1231,22 +1233,22 @@ def __panes_rec(self): # when split, the active pain can be set as required: active_pane = self.active_pane - result = BIFFRecords.PanesRecord(*map(int, ( + result = BIFFRecords.PanesRecord(*list(map(int, ( self.__vert_split_pos, self.__horz_split_pos, self.__horz_split_first_visible, self.__vert_split_first_visible, active_pane - ))).get() + )))).get() return result def __row_blocks_rec(self): result = [] - for row in self.__rows.itervalues(): + for row in self.__rows.values(): result.append(row.get_row_biff_data()) result.append(row.get_cells_biff_data()) - return ''.join(result) + return b''.join(result) def __merged_rec(self): return BIFFRecords.MergedCellsRecord(self.__merged_ranges).get() @@ -1255,7 +1257,7 @@ def __bitmaps_rec(self): return self.__bmp_rec def __calc_settings_rec(self): - result = '' + result = b'' result += BIFFRecords.CalcModeRecord(self.__calc_mode & 0x01).get() result += BIFFRecords.CalcCountRecord(self.__calc_count & 0xFFFF).get() result += BIFFRecords.RefModeRecord(self.__RC_ref_mode & 0x01).get() @@ -1265,7 +1267,7 @@ def __calc_settings_rec(self): return result def __print_settings_rec(self): - result = '' + result = b'' result += BIFFRecords.PrintHeadersRecord(self.__print_headers).get() result += BIFFRecords.PrintGridLinesRecord(self.__print_grid).get() result += BIFFRecords.GridSetRecord(self.__grid_set).get() @@ -1305,7 +1307,7 @@ def __print_settings_rec(self): return result def __protection_rec(self): - result = '' + result = b'' result += BIFFRecords.ProtectRecord(self.__protect).get() result += BIFFRecords.ScenProtectRecord(self.__scen_protect).get() result += BIFFRecords.WindowProtectRecord(self.__wnd_protect).get() @@ -1342,7 +1344,7 @@ def get_biff_data(self): self.__panes_rec(), self.__eof_rec(), ]) - return ''.join(result) + return b''.join(result) def flush_row_data(self): if self.row_tempfile is None: diff --git a/xlwt/__init__.py b/xlwt/__init__.py index a0fd772..da15f43 100644 --- a/xlwt/__init__.py +++ b/xlwt/__init__.py @@ -1,9 +1,10 @@ -__VERSION__ = '0.7.5' +from __future__ import absolute_import +__VERSION__ = '0.8-pre' -from Workbook import Workbook -from Worksheet import Worksheet -from Row import Row -from Column import Column -from Formatting import Font, Alignment, Borders, Pattern, Protection -from Style import XFStyle, easyxf, easyfont, add_palette_colour -from ExcelFormula import * +from .Workbook import Workbook +from .Worksheet import Worksheet +from .Row import Row +from .Column import Column +from .Formatting import Font, Alignment, Borders, Pattern, Protection +from .Style import XFStyle, easyxf, easyfont, add_palette_colour +from .ExcelFormula import * From 38dea5e75d025d42d8ecba7951cd4b4611ada040 Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Sat, 17 Aug 2013 00:51:15 +1000 Subject: [PATCH 03/21] Add RKbug.py fixes * Why is the diff so noisy?? --- tests/RKbug.py | 302 +++++++++++++++++++++++++------------------------ 1 file changed, 155 insertions(+), 147 deletions(-) diff --git a/tests/RKbug.py b/tests/RKbug.py index df2e85e..3b80706 100644 --- a/tests/RKbug.py +++ b/tests/RKbug.py @@ -1,147 +1,155 @@ -from xlwt import * -import sys -from struct import pack, unpack - -def cellname(rowx, colx): - # quick kludge, works up to 26 cols :-) - return chr(ord('A') + colx) + str(rowx + 1) - -def RK_pack_check(num, anint, case=None): - if not(-0x7fffffff - 1 <= anint <= 0x7fffffff): - print "RK_pack_check: not a signed 32-bit int: %r (%r); case: %r" \ - % (anint, hex(anint), case) - pstr = pack(">= 2 # div by 4 to drop the 2 flag bits - if flags & 1: - return i / 100.0 - return float(i) - else: - # It's the most significant 30 bits of an IEEE 754 64-bit FP number - d, = unpack('>= 2 # div by 4 to drop the 2 flag bits + if flags & 1: + return i / 100.0 + return float(i) + else: + # It's the most significant 30 bits of an IEEE 754 64-bit FP number + d, = unpack(' Date: Sat, 17 Aug 2013 01:03:13 +1000 Subject: [PATCH 04/21] More fixes on Py3, including the examples --- xlwt/Bitmap.py | 7 +- xlwt/antlr.py | 136 +++++++++++++++++--------------- xlwt/examples/big-16Mb.py | 18 +++-- xlwt/examples/big-35Mb.py | 12 +-- xlwt/examples/formula_names.py | 8 +- xlwt/examples/panes.py | 12 +-- xlwt/examples/panes2.py | 2 +- xlwt/examples/parse-fmla.py | 1 + xlwt/examples/sst.py | 2 +- xlwt/examples/unicode0.py | 4 +- xlwt/examples/unicode2.py | 5 +- xlwt/examples/wsprops.py | 140 +++++++++++++++++---------------- 12 files changed, 184 insertions(+), 163 deletions(-) diff --git a/xlwt/Bitmap.py b/xlwt/Bitmap.py index ef50d2a..f088ad7 100644 --- a/xlwt/Bitmap.py +++ b/xlwt/Bitmap.py @@ -4,8 +4,11 @@ # Portions are Copyright (c) 2004 Evgeny Filatov # Portions are Copyright (c) 2002-2004 John McNamara (Perl Spreadsheet::WriteExcel) -from BIFFRecords import BiffRecord +from __future__ import absolute_import +from __future__ import division +from .BIFFRecords import BiffRecord from struct import pack, unpack +from future import * def _size_col(sheet, col): @@ -192,7 +195,7 @@ def _process_bitmap(bitmap): """ # Open file and binmode the data in case the platform needs it. - fh = file(bitmap, "rb") + fh = open(bitmap, "rb") try: # Slurp the file into a string. data = fh.read() diff --git a/xlwt/antlr.py b/xlwt/antlr.py index f77314f..4b7126e 100644 --- a/xlwt/antlr.py +++ b/xlwt/antlr.py @@ -41,13 +41,12 @@ ## End of contents of the ANTLR 2.7.7 LICENSE.txt ######################## ## get sys module +from __future__ import print_function +from __future__ import absolute_import +from __future__ import division import sys - -version = sys.version.split()[0] -if version < '2.2.1': - False = 0 -if version < '2.3': - True = not False +from future.builtins import * +from future.utils import PY2, PY3 ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx### ### global symbols ### @@ -84,7 +83,7 @@ def version(): def error(fmt,*args): if fmt: - print "error: ", fmt % tuple(args) + print("error: ", fmt % tuple(args)) def ifelse(cond,_then,_else): if cond : @@ -96,7 +95,9 @@ def ifelse(cond,_then,_else): def is_string_type(x): # return (isinstance(x,str) or isinstance(x,unicode)) # Simplify; xlwt doesn't support Python < 2.3 - return isinstance(basestring) + # return isinstance(x, basestr) + # Complicate again: xlwt does support Python 3.x + return (isinstance(x, bytes) or isinstance(x, str)) def assert_string_type(x): assert is_string_type(x) @@ -590,9 +591,9 @@ def toString(self): Token.badToken = Token( type=INVALID_TYPE, text="") if __name__ == "__main__": - print "testing .." + print("testing ..") T = Token.badToken - print T + print(T) ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx### ### CommonToken ### @@ -663,16 +664,16 @@ def toString(self): if __name__ == '__main__' : T = CommonToken() - print T + print(T) T = CommonToken(col=15,line=1,text="some text", type=5) - print T + print(T) T = CommonToken() T.setLine(1).setColumn(15).setText("some text").setType(5) - print T - print T.getLine() - print T.getColumn() - print T.getText() - print T.getType() + print(T) + print(T.getLine()) + print(T.getColumn()) + print(T.getText()) + print(T.getType()) ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx### ### CommonHiddenStreamToken ### @@ -852,7 +853,7 @@ def fill(self,amount): ### use unicode chars instead of ASCII .. self.queue.append(c) - except Exception,e: + except Exception as e: raise CharStreamIOException(e) ##except: # (mk) Cannot happen ... ##error ("unexpected exception caught ..") @@ -907,7 +908,7 @@ def __init__(self,inst): return raise TypeError("TokenStreamIterator requires TokenStream object") - def next(self): + def __next__(self): assert self.inst item = self.inst.nextToken() if not item or item.isEOF(): @@ -942,7 +943,7 @@ def nextToken(self): while 1: try: return self._input.nextToken() - except TokenStreamRetryException,r: + except TokenStreamRetryException as r: ### just retry "forever" pass @@ -1383,23 +1384,23 @@ def tab(self) : self.setColumn(nc) def panic(self,s='') : - print "CharScanner: panic: " + s + print("CharScanner: panic: " + s) sys.exit(1) def reportError(self,ex) : - print ex + print(ex) def reportError(self,s) : if not self.getFilename(): - print "error: " + str(s) + print("error: " + str(s)) else: - print self.getFilename() + ": error: " + str(s) + print(self.getFilename() + ": error: " + str(s)) def reportWarning(self,s) : if not self.getFilename(): - print "warning: " + str(s) + print("warning: " + str(s)) else: - print self.getFilename() + ": warning: " + str(s) + print(self.getFilename() + ": warning: " + str(s)) def resetText(self) : self.text.setLength(0) @@ -1459,16 +1460,16 @@ def toLower(self,c): return c.__class__.lower() def traceIndent(self): - print ' ' * self.traceDepth + print(' ' * self.traceDepth) def traceIn(self,rname): self.traceDepth += 1 self.traceIndent() - print "> lexer %s c== %s" % (rname,self.LA(1)) + print("> lexer %s c== %s" % (rname,self.LA(1))) def traceOut(self,rname): self.traceIndent() - print "< lexer %s c== %s" % (rname,self.LA(1)) + print("< lexer %s c== %s" % (rname,self.LA(1))) self.traceDepth -= 1 def uponEOF(self): @@ -1532,8 +1533,8 @@ def filterdefault(self,la1,*args): try: func=args[0] args=args[1:] - apply(func,args) - except RecognitionException, e: + func(*args) + except RecognitionException as e: ## catastrophic failure self.reportError(e); self.consume(); @@ -1566,7 +1567,7 @@ def __init__(self,inst): return raise TypeError("CharScannerIterator requires CharScanner object") - def next(self): + def __next__(self): assert self.inst item = self.inst.nextToken() if not item or item.isEOF(): @@ -1589,19 +1590,24 @@ class BitSet(object): def __init__(self,data=None): if not data: - BitSet.__init__(self,[long(0)]) - return - if isinstance(data,int): - BitSet.__init__(self,[long(data)]) - return - if isinstance(data,long): - BitSet.__init__(self,[data]) + BitSet.__init__(self,[int(0)]) return + if PY2: + if isinstance(data,int): + BitSet.__init__(self,[long(data)]) + return + if isinstance(data,long): + BitSet.__init__(self,[data]) + return + else: + if isinstance(data,int): + BitSet.__init__(self,[data]) + return if not isinstance(data,list): raise TypeError("BitSet requires integer, long, or " + "list argument") for x in data: - if not isinstance(x,long): + if (PY3 and not isinstance(x,int)) or (PY2 and not isinstance(x, long)): raise TypeError(self,"List argument item is " + "not a long: %s" % (x)) self.data = data @@ -1609,7 +1615,7 @@ def __init__(self,data=None): def __str__(self): bits = len(self.data) * BitSet.BITS s = "" - for i in xrange(0,bits): + for i in range(0,bits): if self.at(i): s += "1" else: @@ -1648,7 +1654,7 @@ def wordNumber(self,bit): def bitMask(self,bit): pos = bit & BitSet.MOD_MASK ## bit mod BITS - return (1L << pos) + return (1 << pos) def set(self,bit,on=True): # grow bitset as required (use with care!) @@ -1656,8 +1662,8 @@ def set(self,bit,on=True): mask = self.bitMask(bit) if i>=len(self.data): d = i - len(self.data) + 1 - for x in xrange(0,d): - self.data.append(0L) + for x in range(0,d): + self.data.append(0) assert len(self.data) == i+1 if on: self.data[i] |= mask @@ -1684,12 +1690,12 @@ def at(self,bit): def illegalarg_ex(func): raise ValueError( "%s is only valid if parser is built for debugging" % - (func.func_name)) + (func.__name__)) def runtime_ex(func): raise RuntimeException( "%s is only valid if parser is built for debugging" % - (func.func_name)) + (func.__name__)) ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx### ### TokenBuffer ### @@ -1949,16 +1955,16 @@ def reportError(self,x) : col = x.getLine() text = x.getText() fmt = fmt + 'unexpected symbol at line %s (column %s) : "%s"' - print >>sys.stderr, fmt % (line,col,text) + print(fmt % (line,col,text), file=sys.stderr) else: - print >>sys.stderr, fmt,str(x) + print(fmt,str(x), file=sys.stderr) def reportWarning(self,s): f = self.getFilename() if f: - print "%s:warning: %s" % (f,str(x)) + print("%s:warning: %s" % (f,str(x))) else: - print "warning: %s" % (str(x)) + print("warning: %s" % (str(x))) def rewind(self, pos) : self.inputState.input.rewind(pos) @@ -1986,7 +1992,7 @@ def setTokenBuffer(self, t) : self.inputState.input = t def traceIndent(self): - print " " * self.traceDepth + print(" " * self.traceDepth) def traceIn(self,rname): self.traceDepth += 1 @@ -2075,20 +2081,20 @@ def set_k(self,index,*args): self.k = 1 def trace(self,ee,rname): - print type(self) + print(type(self)) self.traceIndent() guess = "" if self.inputState.guessing > 0: guess = " [guessing]" - print(ee + rname + guess) - for i in xrange(1,self.k+1): + print((ee + rname + guess)) + for i in range(1,self.k+1): if i != 1: print(", ") if self.LT(i) : v = self.LT(i).getText() else: v = "null" - print "LA(%s) == %s" % (i,v) + print("LA(%s) == %s" % (i,v)) print("\n") def traceIn(self,rname): @@ -2149,10 +2155,10 @@ def matchNot(self,t, ttype) : raise MismatchedTokenException(getTokenNames(), t, ttype, True) def reportError(self,ex): - print >>sys.stderr,"error:",ex + print("error:",ex, file=sys.stderr) def reportWarning(self, s): - print "warning:",s + print("warning:",s) def setASTFactory(self,f): self.astFactory = f @@ -2164,20 +2170,20 @@ def setASTNodeClass(self,nodeType): self.astFactory.setASTNodeType(nodeType) def traceIndent(self): - print " " * self.traceDepth + print(" " * self.traceDepth) def traceIn(self,rname,t): self.traceDepth += 1 self.traceIndent() - print("> " + rname + "(" + + print(("> " + rname + "(" + ifelse(t,str(t),"null") + ")" + - ifelse(self.inputState.guessing>0,"[guessing]","")) + ifelse(self.inputState.guessing>0,"[guessing]",""))) def traceOut(self,rname,t): self.traceIndent() - print("< " + rname + "(" + + print(("< " + rname + "(" + ifelse(t,str(t),"null") + ")" + - ifelse(self.inputState.guessing>0,"[guessing]","")) + ifelse(self.inputState.guessing>0,"[guessing]",""))) self.traceDepth -= 1 ### wh: moved from ASTFactory to TreeParser @@ -2724,7 +2730,7 @@ def setTokenTypeToASTClassMap(self,amap): def error(self, e): import sys - print >> sys.stderr, e + print(e, file=sys.stderr) def setTokenTypeASTNodeType(self, tokenType, className): """ @@ -2811,7 +2817,7 @@ def make(*nodes): if not nodes: return None - for i in xrange(0,len(nodes)): + for i in range(0,len(nodes)): node = nodes[i] if node: assert isinstance(node,AST) @@ -2821,7 +2827,7 @@ def make(*nodes): if root: root.setFirstChild(None) - for i in xrange(1,len(nodes)): + for i in range(1,len(nodes)): if not nodes[i]: continue if not root: diff --git a/xlwt/examples/big-16Mb.py b/xlwt/examples/big-16Mb.py index 91db123..d4a7665 100644 --- a/xlwt/examples/big-16Mb.py +++ b/xlwt/examples/big-16Mb.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # tries stress SST, SAT and MSAT +from __future__ import print_function +from __future__ import absolute_import from time import * from xlwt.Workbook import * from xlwt.Style import * @@ -14,22 +16,22 @@ rowcount = 6000 + 1 t0 = time() -print "\nstart: %s" % ctime(t0) +print("\nstart: %s" % ctime(t0)) -print "Filling..." -for col in xrange(colcount): - print "[%d]" % col, - for row in xrange(rowcount): +print("Filling...") +for col in range(colcount): + print("[%d]" % col, end=' ') + for row in range(rowcount): #ws0.write(row, col, "BIG(%d, %d)" % (row, col)) ws0.write(row, col, "BIG") t1 = time() - t0 -print "\nsince starting elapsed %.2f s" % (t1) +print("\nsince starting elapsed %.2f s" % (t1)) -print "Storing..." +print("Storing...") wb.save('big-16Mb.xls') t2 = time() - t0 -print "since starting elapsed %.2f s" % (t2) +print("since starting elapsed %.2f s" % (t2)) diff --git a/xlwt/examples/big-35Mb.py b/xlwt/examples/big-35Mb.py index 837a6df..dc5463d 100644 --- a/xlwt/examples/big-35Mb.py +++ b/xlwt/examples/big-35Mb.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # tries stress SST, SAT and MSAT +from __future__ import print_function +from __future__ import absolute_import from time import * from xlwt import * @@ -14,17 +16,17 @@ t0 = time() -for col in xrange(colcount): - for row in xrange(rowcount): +for col in range(colcount): + for row in range(rowcount): ws0.write(row, col, "BIG(%d, %d)" % (row, col)) t1 = time() - t0 -print "\nsince starting elapsed %.2f s" % (t1) +print("\nsince starting elapsed %.2f s" % (t1)) -print "Storing..." +print("Storing...") wb.save('big-35Mb.xls') t2 = time() - t0 -print "since starting elapsed %.2f s" % (t2) +print("since starting elapsed %.2f s" % (t2)) diff --git a/xlwt/examples/formula_names.py b/xlwt/examples/formula_names.py index f0354bc..69a2292 100644 --- a/xlwt/examples/formula_names.py +++ b/xlwt/examples/formula_names.py @@ -2,6 +2,8 @@ # -*- coding: windows-1251 -*- # Copyright (C) 2005 Kiseliov Roman +from __future__ import print_function +from __future__ import absolute_import from xlwt import * from xlwt.ExcelFormulaParser import FormulaParseException @@ -21,8 +23,8 @@ text = n + "($A$1)" try: formula = Formula(text) - except FormulaParseException,e: - print "Could not parse %r: %s" % (text,e.args[0]) + except FormulaParseException as e: + print("Could not parse %r: %s" % (text,e.args[0])) fail_count += 1 else: ws.write(i, 3, formula) @@ -31,4 +33,4 @@ w.save('formula_names.xls') -print "succeeded with %i functions, failed with %i" % (succeed_count,fail_count) +print("succeeded with %i functions, failed with %i" % (succeed_count,fail_count)) diff --git a/xlwt/examples/panes.py b/xlwt/examples/panes.py index 9fd83b0..c086ae3 100644 --- a/xlwt/examples/panes.py +++ b/xlwt/examples/panes.py @@ -13,22 +13,22 @@ ws6 = w.add_sheet('sheet 6') for i in range(0x100): - ws1.write(i/0x10, i%0x10, i) + ws1.write(i//0x10, i%0x10, i) for i in range(0x100): - ws2.write(i/0x10, i%0x10, i) + ws2.write(i//0x10, i%0x10, i) for i in range(0x100): - ws3.write(i/0x10, i%0x10, i) + ws3.write(i//0x10, i%0x10, i) for i in range(0x100): - ws4.write(i/0x10, i%0x10, i) + ws4.write(i//0x10, i%0x10, i) for i in range(0x100): - ws5.write(i/0x10, i%0x10, i) + ws5.write(i//0x10, i%0x10, i) for i in range(0x100): - ws6.write(i/0x10, i%0x10, i) + ws6.write(i//0x10, i%0x10, i) ws1.panes_frozen = True ws1.horz_split_pos = 2 diff --git a/xlwt/examples/panes2.py b/xlwt/examples/panes2.py index 09f8719..26f2a1f 100644 --- a/xlwt/examples/panes2.py +++ b/xlwt/examples/panes2.py @@ -5,7 +5,7 @@ import xlwt w = xlwt.Workbook() -sheets = [w.add_sheet('sheet ' + str(sheetx+1)) for sheetx in xrange(7)] +sheets = [w.add_sheet('sheet ' + str(sheetx+1)) for sheetx in range(7)] ws1, ws2, ws3, ws4, ws5, ws6, ws7 = sheets for sheet in sheets: for i in range(0x100): diff --git a/xlwt/examples/parse-fmla.py b/xlwt/examples/parse-fmla.py index 06f68eb..ba6a72e 100644 --- a/xlwt/examples/parse-fmla.py +++ b/xlwt/examples/parse-fmla.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import from xlwt import ExcelFormulaParser, ExcelFormula import sys diff --git a/xlwt/examples/sst.py b/xlwt/examples/sst.py index b91c2f5..01960a4 100644 --- a/xlwt/examples/sst.py +++ b/xlwt/examples/sst.py @@ -44,7 +44,7 @@ wb.add_style(st3) ws0 = wb.add_sheet('0') -ws0.write(0, 0, 'Olya'*0x4000, st0) +ws0.write(0, 0, b'Olya'*0x1000, st0) #for i in range(0, 0x10): # ws0.write(i, 2, ('%d'%i)*0x4000, st1) diff --git a/xlwt/examples/unicode0.py b/xlwt/examples/unicode0.py index 3651ec9..dd0e79a 100644 --- a/xlwt/examples/unicode0.py +++ b/xlwt/examples/unicode0.py @@ -2,11 +2,11 @@ import xlwt # Strings passed to (for example) Worksheet.write can be unicode objects, -# or str (8-bit) objects, which are then decoded into unicode. +# or bytes (8-bit) objects, which are then decoded into unicode. # The encoding to be used defaults to 'ascii'. This can be overridden # when the Workbook instance is created: book = xlwt.Workbook(encoding='cp1251') sheet = book.add_sheet('cp1251-demo') -sheet.write(0, 0, '\xce\xeb\xff') +sheet.write(0, 0, b'\xce\xeb\xff') book.save('unicode0.xls') diff --git a/xlwt/examples/unicode2.py b/xlwt/examples/unicode2.py index 18904b0..942a6e5 100644 --- a/xlwt/examples/unicode2.py +++ b/xlwt/examples/unicode2.py @@ -2,7 +2,10 @@ # -*- coding: windows-1251 -*- # Copyright (C) 2005 Kiseliov Roman +from __future__ import absolute_import +from __future__ import division from xlwt import * +from future import * w = Workbook() ws1 = w.add_sheet(u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK SMALL LETTER BETA}\N{GREEK SMALL LETTER GAMMA}\u2665\u041e\u041b\u042f\u2665') @@ -13,7 +16,7 @@ style.font = fnt for i in range(0x10000): - ws1.write(i/0x10, i%0x10, unichr(i), style) + ws1.write(i//0x10, i%0x10, chr(i), style) w.save('unicode2.xls') diff --git a/xlwt/examples/wsprops.py b/xlwt/examples/wsprops.py index adc5a04..5601977 100644 --- a/xlwt/examples/wsprops.py +++ b/xlwt/examples/wsprops.py @@ -1,3 +1,5 @@ +from __future__ import print_function +from __future__ import absolute_import props = \ [ 'name', @@ -80,76 +82,76 @@ wb = Workbook() ws = wb.add_sheet('sheet') -print ws.name -print ws.parent -print ws.rows -print ws.cols -print ws.merged_ranges -print ws.bmp_rec -print ws.show_formulas -print ws.show_grid -print ws.show_headers -print ws.panes_frozen -print ws.show_empty_as_zero -print ws.auto_colour_grid -print ws.cols_right_to_left -print ws.show_outline -print ws.remove_splits -print ws.selected +print(ws.name) +print(ws.parent) +print(ws.rows) +print(ws.cols) +print(ws.merged_ranges) +print(ws.bmp_rec) +print(ws.show_formulas) +print(ws.show_grid) +print(ws.show_headers) +print(ws.panes_frozen) +print(ws.show_empty_as_zero) +print(ws.auto_colour_grid) +print(ws.cols_right_to_left) +print(ws.show_outline) +print(ws.remove_splits) +print(ws.selected) # print ws.hidden -print ws.page_preview -print ws.first_visible_row -print ws.first_visible_col -print ws.grid_colour -print ws.preview_magn -print ws.normal_magn +print(ws.page_preview) +print(ws.first_visible_row) +print(ws.first_visible_col) +print(ws.grid_colour) +print(ws.preview_magn) +print(ws.normal_magn) #print ws.row_gut_width #print ws.col_gut_height -print ws.show_auto_page_breaks -print ws.dialogue_sheet -print ws.auto_style_outline -print ws.outline_below -print ws.outline_right -print ws.fit_num_pages -print ws.show_row_outline -print ws.show_col_outline -print ws.alt_expr_eval -print ws.alt_formula_entries -print ws.row_default_height -print ws.col_default_width -print ws.calc_mode -print ws.calc_count -print ws.RC_ref_mode -print ws.iterations_on -print ws.delta -print ws.save_recalc -print ws.print_headers -print ws.print_grid +print(ws.show_auto_page_breaks) +print(ws.dialogue_sheet) +print(ws.auto_style_outline) +print(ws.outline_below) +print(ws.outline_right) +print(ws.fit_num_pages) +print(ws.show_row_outline) +print(ws.show_col_outline) +print(ws.alt_expr_eval) +print(ws.alt_formula_entries) +print(ws.row_default_height) +print(ws.col_default_width) +print(ws.calc_mode) +print(ws.calc_count) +print(ws.RC_ref_mode) +print(ws.iterations_on) +print(ws.delta) +print(ws.save_recalc) +print(ws.print_headers) +print(ws.print_grid) #print ws.grid_set -print ws.vert_page_breaks -print ws.horz_page_breaks -print ws.header_str -print ws.footer_str -print ws.print_centered_vert -print ws.print_centered_horz -print ws.left_margin -print ws.right_margin -print ws.top_margin -print ws.bottom_margin -print ws.paper_size_code -print ws.print_scaling -print ws.start_page_number -print ws.fit_width_to_pages -print ws.fit_height_to_pages -print ws.print_in_rows -print ws.portrait -print ws.print_colour -print ws.print_draft -print ws.print_notes -print ws.print_notes_at_end -print ws.print_omit_errors -print ws.print_hres -print ws.print_vres -print ws.header_margin -print ws.footer_margin -print ws.copies_num +print(ws.vert_page_breaks) +print(ws.horz_page_breaks) +print(ws.header_str) +print(ws.footer_str) +print(ws.print_centered_vert) +print(ws.print_centered_horz) +print(ws.left_margin) +print(ws.right_margin) +print(ws.top_margin) +print(ws.bottom_margin) +print(ws.paper_size_code) +print(ws.print_scaling) +print(ws.start_page_number) +print(ws.fit_width_to_pages) +print(ws.fit_height_to_pages) +print(ws.print_in_rows) +print(ws.portrait) +print(ws.print_colour) +print(ws.print_draft) +print(ws.print_notes) +print(ws.print_notes_at_end) +print(ws.print_omit_errors) +print(ws.print_hres) +print(ws.print_vres) +print(ws.header_margin) +print(ws.footer_margin) +print(ws.copies_num) From e9302bfe795d421de09dbc8ac9b56a31551016c3 Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Sat, 17 Aug 2013 01:11:58 +1000 Subject: [PATCH 05/21] Mention Py3 compatibility in setup.py. * Also add future==0.4.0 to requirements.txt. This is not currently read; it is for the user's info only ... --- requirements.txt | 1 + setup.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d67c049 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +future==0.4.0 diff --git a/setup.py b/setup.py index 9d3f5fa..b856f0b 100644 --- a/setup.py +++ b/setup.py @@ -6,10 +6,12 @@ DESCRIPTION = ( 'Library to create spreadsheet files compatible with ' 'MS Excel 97/2000/XP/2003 XLS files, ' - 'on any platform, with Python 2.3 to 2.7' + 'on any platform, with Python 2.7 to 3.3' ) LONG_DESCRIPTION = """\ +Py2.7 and Py3.3+ fork of xlwt. + xlwt is a library for generating spreadsheet files that are compatible with Excel 97/2000/XP/2003, OpenOffice.org Calc, and Gnumeric. xlwt has full support for Unicode. Excel spreadsheets can be generated on any @@ -20,6 +22,9 @@ CLASSIFIERS = [ 'Operating System :: OS Independent', 'Programming Language :: Python', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.3', 'License :: OSI Approved :: BSD License', 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', From 7179c98f7e883222961b3537f089d6b7cc446a51 Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Sat, 17 Aug 2013 01:30:31 +1000 Subject: [PATCH 06/21] Update README and HISTORY a little bit * Mention Py3 compatibility and dependency on ``future`` --- HISTORY.html | 4 ++++ README.html | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/HISTORY.html b/HISTORY.html index 760599d..b35b5b2 100644 --- a/HISTORY.html +++ b/HISTORY.html @@ -5,6 +5,10 @@ xlwt HISTORY +

Version 0.8.0-pre: Py3k support added, 2013-08-17 +

+

Version 0.7.5, released 2013-04 +

Version 0.7.2, released to the general public via PyPI -- 2009-06-01


Revision: 3844 diff --git a/README.html b/README.html index d7c9bb9..3c2c66c 100644 --- a/README.html +++ b/README.html @@ -14,15 +14,15 @@

Licence: BSD-style (see licences.py)

-

Version of xlwt: 0.7.2 +

Version of xlwt: 0.8.0-pre

-

Version of Python required: 2.3 to 2.6 +

Version of Python required: 2.7 or 3.3

-

External modules required: None +

External modules required: future

-The package itself is pure Python with no dependencies on modules or packages -outside the standard Python distribution. +The package itself is pure Python with only one dependency outside the standard +Python distribution (the future package for Py2/3 compatibility).

Quick start:

From 999fdb5e3d66d83725cf76debce1b2822b7d939a Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Sat, 17 Aug 2013 01:31:31 +1000 Subject: [PATCH 07/21] Compatible iterator support on Py2 / Py3 --- xlwt/antlr.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xlwt/antlr.py b/xlwt/antlr.py index 4b7126e..ec030fd 100644 --- a/xlwt/antlr.py +++ b/xlwt/antlr.py @@ -46,7 +46,7 @@ from __future__ import division import sys from future.builtins import * -from future.utils import PY2, PY3 +from future.utils import PY2, PY3, implements_iterator ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx### ### global symbols ### @@ -901,6 +901,7 @@ def __iter__(self): ### TokenStreamIterator ### ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx### +@implements_iterator class TokenStreamIterator(object): def __init__(self,inst): if isinstance(inst,TokenStream): @@ -1559,6 +1560,7 @@ def set_return_token(self,_create,_token,_ttype,_offset): ### CharScannerIterator ### ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx### +@implements_iterator class CharScannerIterator: def __init__(self,inst): From 2a78ad900c0709d9edb9053f41ea79d27807dff6 Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Sat, 17 Aug 2013 01:43:29 +1000 Subject: [PATCH 08/21] Revert RKbug.py for now * The diff was way too big. Why?? --- tests/RKbug.py | 302 ++++++++++++++++++++++++------------------------- 1 file changed, 147 insertions(+), 155 deletions(-) diff --git a/tests/RKbug.py b/tests/RKbug.py index 3b80706..df2e85e 100644 --- a/tests/RKbug.py +++ b/tests/RKbug.py @@ -1,155 +1,147 @@ -from __future__ import print_function -from __future__ import absolute_import -from __future__ import division - -import sys -from struct import pack, unpack - -from future import * - -from xlwt import * - - -def cellname(rowx, colx): - # quick kludge, works up to 26 cols :-) - return chr(ord('A') + colx) + str(rowx + 1) - -def RK_pack_check(num, anint, case=None): - if not(-0x7fffffff - 1 <= anint <= 0x7fffffff): - print("RK_pack_check: not a signed 32-bit int: %r (%r); case: %r" \ - % (anint, hex(anint), case)) - pstr = pack(">= 2 # div by 4 to drop the 2 flag bits - if flags & 1: - return i / 100.0 - return float(i) - else: - # It's the most significant 30 bits of an IEEE 754 64-bit FP number - d, = unpack('>= 2 # div by 4 to drop the 2 flag bits + if flags & 1: + return i / 100.0 + return float(i) + else: + # It's the most significant 30 bits of an IEEE 754 64-bit FP number + d, = unpack(' Date: Sat, 17 Aug 2013 01:46:58 +1000 Subject: [PATCH 09/21] Add back patch to RKbug.py * Ah ... this file has CRLF line terminators ;) --- tests/RKbug.py | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/tests/RKbug.py b/tests/RKbug.py index df2e85e..5a0522c 100644 --- a/tests/RKbug.py +++ b/tests/RKbug.py @@ -1,20 +1,28 @@ -from xlwt import * +from __future__ import print_function +from __future__ import absolute_import +from __future__ import division + import sys from struct import pack, unpack +from future import * + +from xlwt import * + + def cellname(rowx, colx): # quick kludge, works up to 26 cols :-) return chr(ord('A') + colx) + str(rowx + 1) def RK_pack_check(num, anint, case=None): if not(-0x7fffffff - 1 <= anint <= 0x7fffffff): - print "RK_pack_check: not a signed 32-bit int: %r (%r); case: %r" \ - % (anint, hex(anint), case) + print("RK_pack_check: not a signed 32-bit int: %r (%r); case: %r" \ + % (anint, hex(anint), case)) pstr = pack(" Date: Wed, 23 Oct 2013 18:41:09 +0200 Subject: [PATCH 10/21] Add a requirement --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index b856f0b..2e52fed 100644 --- a/setup.py +++ b/setup.py @@ -59,4 +59,5 @@ 'tests/*.*', ], }, + install_requires=['future>=0.6.0'] ) From a4a2cc7e232e59f28a96453e2f097654fffff556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Mart=C3=ADn?= Date: Wed, 23 Oct 2013 19:03:15 +0200 Subject: [PATCH 11/21] Move the version. I got an error because future package --- setup.py | 2 +- xlwt/__init__.py | 1 - xlwt/version.py | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 xlwt/version.py diff --git a/setup.py b/setup.py index 2e52fed..7121be8 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ #!/usr/bin/env python from distutils.core import setup -from xlwt import __VERSION__ +from xlwt.version import __VERSION__ DESCRIPTION = ( 'Library to create spreadsheet files compatible with ' diff --git a/xlwt/__init__.py b/xlwt/__init__.py index da15f43..207c443 100644 --- a/xlwt/__init__.py +++ b/xlwt/__init__.py @@ -1,5 +1,4 @@ from __future__ import absolute_import -__VERSION__ = '0.8-pre' from .Workbook import Workbook from .Worksheet import Worksheet diff --git a/xlwt/version.py b/xlwt/version.py new file mode 100644 index 0000000..a40364b --- /dev/null +++ b/xlwt/version.py @@ -0,0 +1 @@ +__VERSION__ = '0.8-pre' \ No newline at end of file From 31c991c5bc049537e34e0fe2026a982108b8da29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Mart=C3=ADn?= Date: Wed, 23 Oct 2013 19:05:34 +0200 Subject: [PATCH 12/21] Move the version... I try to fix a import error --- setup.py | 2 +- xlwt/version.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 xlwt/version.py diff --git a/setup.py b/setup.py index 7121be8..7678377 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ #!/usr/bin/env python from distutils.core import setup -from xlwt.version import __VERSION__ +__VERSION__ = '0.8-pre' DESCRIPTION = ( 'Library to create spreadsheet files compatible with ' diff --git a/xlwt/version.py b/xlwt/version.py deleted file mode 100644 index a40364b..0000000 --- a/xlwt/version.py +++ /dev/null @@ -1 +0,0 @@ -__VERSION__ = '0.8-pre' \ No newline at end of file From 394285b183e022566373831c0109e045e90a4b99 Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Tue, 29 Oct 2013 22:38:29 +1100 Subject: [PATCH 13/21] Use setuptools if available; update future package to v0.8.1 --- requirements.txt | 2 +- setup.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index d67c049..7c95b8e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -future==0.4.0 +future>=0.8.1 diff --git a/setup.py b/setup.py index 7678377..70ce6b8 100644 --- a/setup.py +++ b/setup.py @@ -1,27 +1,32 @@ #!/usr/bin/env python -from distutils.core import setup +try: + from setuptools import setup +except ImportError: + from distutils.core import setup + __VERSION__ = '0.8-pre' DESCRIPTION = ( 'Library to create spreadsheet files compatible with ' 'MS Excel 97/2000/XP/2003 XLS files, ' - 'on any platform, with Python 2.7 to 3.3' + 'on any platform, with Python 2.6 to 3.3' ) LONG_DESCRIPTION = """\ -Py2.7 and Py3.3+ fork of xlwt. +Py2.6+ and Py3.3+ fork of xlwt. xlwt is a library for generating spreadsheet files that are compatible with Excel 97/2000/XP/2003, OpenOffice.org Calc, and Gnumeric. xlwt has full support for Unicode. Excel spreadsheets can be generated on any platform without needing Excel or a COM server. The only requirement is -Python 2.3 to 2.7. +Python 2.6, 2.7, or 3.3. """ CLASSIFIERS = [ 'Operating System :: OS Independent', 'Programming Language :: Python', + 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', @@ -59,5 +64,5 @@ 'tests/*.*', ], }, - install_requires=['future>=0.6.0'] + install_requires=['future>=0.8.1'] ) From b4c8edce5a04a8359b80fb1dbf4f9561c5da7465 Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Tue, 29 Oct 2013 22:43:39 +1100 Subject: [PATCH 14/21] Initial fixes for ANTLR module --- xlwt/antlr.py | 62 +++++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/xlwt/antlr.py b/xlwt/antlr.py index ec030fd..d90e5bb 100644 --- a/xlwt/antlr.py +++ b/xlwt/antlr.py @@ -41,12 +41,17 @@ ## End of contents of the ANTLR 2.7.7 LICENSE.txt ######################## ## get sys module -from __future__ import print_function -from __future__ import absolute_import -from __future__ import division -import sys +from __future__ import (absolute_import, division, print_function) from future.builtins import * -from future.utils import PY2, PY3, implements_iterator +from future.utils import PY2, PY3, implements_iterator, isbytes, istext +import sys + +try: + # We need ``long`` on Python 2. future versions < 0.7 + # overwrite ``long`` + del long +except NameError: + pass ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx### ### global symbols ### @@ -95,9 +100,9 @@ def ifelse(cond,_then,_else): def is_string_type(x): # return (isinstance(x,str) or isinstance(x,unicode)) # Simplify; xlwt doesn't support Python < 2.3 - # return isinstance(x, basestr) + # return isinstance(x, basestring) # Complicate again: xlwt does support Python 3.x - return (isinstance(x, bytes) or isinstance(x, str)) + return isbytes(x) or istext(x) def assert_string_type(x): assert is_string_type(x) @@ -1584,6 +1589,26 @@ def __next__(self): ### a long is of any size. That means we can use a single long as the ### bitset (!), ie. Python would do almost all the work (TBD). +def longify(data): + """ + Turns data (a list or int or long) into a list of longs + """ + if not data: + if PY3: + return [0] + else: + return [long(0)] + if not isinstance(data,list): + if PY3: + return [int(data)] + else: + return [long(data)] + if PY3: + return list(map(int, data)) # same as returning data, but safer (data must be int-like + else: + return list(map(long, data)) + + class BitSet(object): BITS = 64 NIBBLE = 4 @@ -1591,28 +1616,11 @@ class BitSet(object): MOD_MASK = BITS -1 def __init__(self,data=None): - if not data: - BitSet.__init__(self,[int(0)]) - return - if PY2: - if isinstance(data,int): - BitSet.__init__(self,[long(data)]) - return - if isinstance(data,long): - BitSet.__init__(self,[data]) - return - else: - if isinstance(data,int): - BitSet.__init__(self,[data]) - return - if not isinstance(data,list): + try: + self.data = longify(data) + except ValueError: raise TypeError("BitSet requires integer, long, or " + "list argument") - for x in data: - if (PY3 and not isinstance(x,int)) or (PY2 and not isinstance(x, long)): - raise TypeError(self,"List argument item is " + - "not a long: %s" % (x)) - self.data = data def __str__(self): bits = len(self.data) * BitSet.BITS From d8ea26dbd8c30c5a335242f30655677e304ff74e Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Tue, 29 Oct 2013 22:45:12 +1100 Subject: [PATCH 15/21] Streamline antlr.py using new (long) int object in python-future >= 0.7 --- xlwt/antlr.py | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/xlwt/antlr.py b/xlwt/antlr.py index d90e5bb..b8a97e4 100644 --- a/xlwt/antlr.py +++ b/xlwt/antlr.py @@ -46,12 +46,6 @@ from future.utils import PY2, PY3, implements_iterator, isbytes, istext import sys -try: - # We need ``long`` on Python 2. future versions < 0.7 - # overwrite ``long`` - del long -except NameError: - pass ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx### ### global symbols ### @@ -1594,19 +1588,10 @@ def longify(data): Turns data (a list or int or long) into a list of longs """ if not data: - if PY3: - return [0] - else: - return [long(0)] + return [int(0)] if not isinstance(data,list): - if PY3: - return [int(data)] - else: - return [long(data)] - if PY3: - return list(map(int, data)) # same as returning data, but safer (data must be int-like - else: - return list(map(long, data)) + return [int(data)] + return list(map(int, data)) # same as returning data, but safer (data must be int-like class BitSet(object): From 5c1b740ba7e31c86926b923f1ca6a3b057947521 Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Wed, 30 Oct 2013 18:32:18 +1100 Subject: [PATCH 16/21] More fixes from ``future`` upgrade --- tests/RKbug.py | 5 ++--- xlwt/BIFFRecords.py | 3 ++- xlwt/Bitmap.py | 7 +++---- xlwt/Column.py | 4 ++-- xlwt/CompoundDoc.py | 2 +- xlwt/ExcelFormula.py | 2 +- xlwt/ExcelFormulaLexer.py | 2 +- xlwt/ExcelFormulaParser.py | 4 ++-- xlwt/ExcelMagic.py | 2 +- xlwt/Row.py | 3 ++- xlwt/Style.py | 5 ++--- xlwt/UnicodeUtils.py | 5 +++-- xlwt/Utils.py | 23 ++++++++++++++++++++++- xlwt/Workbook.py | 5 +++-- xlwt/Worksheet.py | 5 +++-- xlwt/__init__.py | 2 ++ xlwt/antlr.py | 4 ++-- xlwt/examples/unicode2.py | 3 ++- 18 files changed, 56 insertions(+), 30 deletions(-) diff --git a/tests/RKbug.py b/tests/RKbug.py index 5a0522c..54aacd7 100644 --- a/tests/RKbug.py +++ b/tests/RKbug.py @@ -1,13 +1,12 @@ from __future__ import print_function from __future__ import absolute_import from __future__ import division +from future.builtins import * import sys -from struct import pack, unpack - -from future import * from xlwt import * +from xlwt.Utils import pack, unpack def cellname(rowx, colx): diff --git a/xlwt/BIFFRecords.py b/xlwt/BIFFRecords.py index f2c6cbe..c1b5954 100644 --- a/xlwt/BIFFRecords.py +++ b/xlwt/BIFFRecords.py @@ -2,9 +2,10 @@ from __future__ import absolute_import from __future__ import division from __future__ import unicode_literals -from struct import pack from .UnicodeUtils import upack1, upack2, upack2rt +from .Utils import pack, unpack from future.builtins import * +from future import utils class SharedStringTable(object): _SST_ID = 0x00FC diff --git a/xlwt/Bitmap.py b/xlwt/Bitmap.py index f088ad7..b57daf3 100644 --- a/xlwt/Bitmap.py +++ b/xlwt/Bitmap.py @@ -4,11 +4,10 @@ # Portions are Copyright (c) 2004 Evgeny Filatov # Portions are Copyright (c) 2002-2004 John McNamara (Perl Spreadsheet::WriteExcel) -from __future__ import absolute_import -from __future__ import division +from __future__ import (absolute_import, division, unicode_literals) from .BIFFRecords import BiffRecord -from struct import pack, unpack -from future import * +from .Utils import pack, unpack +from future.builtins import * def _size_col(sheet, col): diff --git a/xlwt/Column.py b/xlwt/Column.py index 2959a62..6a393e4 100644 --- a/xlwt/Column.py +++ b/xlwt/Column.py @@ -1,8 +1,8 @@ # -*- coding: windows-1252 -*- -from __future__ import absolute_import +from __future__ import absolute_import, division from .BIFFRecords import ColInfoRecord -from future import * +from future.builtins import * class Column(object): def __init__(self, colx, parent_sheet): diff --git a/xlwt/CompoundDoc.py b/xlwt/CompoundDoc.py index 6c08d73..c861b62 100644 --- a/xlwt/CompoundDoc.py +++ b/xlwt/CompoundDoc.py @@ -2,7 +2,7 @@ from __future__ import absolute_import import struct -from future import * +from future.builtins import * # This implementation writes only 'Root Entry', 'Workbook' streams # and 2 empty streams for aligning directory stream on sector boundary diff --git a/xlwt/ExcelFormula.py b/xlwt/ExcelFormula.py index f8d92fe..6b78494 100644 --- a/xlwt/ExcelFormula.py +++ b/xlwt/ExcelFormula.py @@ -3,7 +3,7 @@ from __future__ import absolute_import import struct -from future import * +from future.builtins import * from . import ExcelFormulaParser, ExcelFormulaLexer from .antlr import ANTLRException diff --git a/xlwt/ExcelFormulaLexer.py b/xlwt/ExcelFormulaLexer.py index 66e3eef..830338b 100644 --- a/xlwt/ExcelFormulaLexer.py +++ b/xlwt/ExcelFormulaLexer.py @@ -5,7 +5,7 @@ from .antlr import EOF, CommonToken as Tok, TokenStream, TokenStreamException from . import ExcelFormulaParser from re import compile as recompile, LOCALE, IGNORECASE, VERBOSE -from future import * +from future.builtins import * int_const_pattern = r"\d+\b" diff --git a/xlwt/ExcelFormulaParser.py b/xlwt/ExcelFormulaParser.py index 27f3469..c404dfa 100644 --- a/xlwt/ExcelFormulaParser.py +++ b/xlwt/ExcelFormulaParser.py @@ -1,11 +1,11 @@ ### $ANTLR 2.7.7 (20060930): "xlwt/excel-formula.g" -> "ExcelFormulaParser.py"$ ### import antlr and other modules .. from __future__ import absolute_import +from future.builtins import * + import sys import struct -from future import * - from . import antlr from . import Utils from .UnicodeUtils import upack1 diff --git a/xlwt/ExcelMagic.py b/xlwt/ExcelMagic.py index c10778a..1643075 100644 --- a/xlwt/ExcelMagic.py +++ b/xlwt/ExcelMagic.py @@ -3,7 +3,7 @@ lots of Excel Magic Numbers """ from __future__ import absolute_import, unicode_literals -from future import * +from future.builtins import * # Boundaries BIFF8+ diff --git a/xlwt/Row.py b/xlwt/Row.py index ad0676d..a3f16b5 100644 --- a/xlwt/Row.py +++ b/xlwt/Row.py @@ -9,6 +9,7 @@ from . import ExcelFormula import datetime as dt from .Formatting import Font + from future.builtins import * try: @@ -246,7 +247,7 @@ def write(self, col, label, style=Style.default_style): self.insert_cell(col, BlankCell(self.__idx, col, style_index)) elif isinstance(label, bool): # bool is subclass of int; test bool first self.insert_cell(col, BooleanCell(self.__idx, col, style_index, label)) - elif isinstance(label, (float, int, Decimal)): + elif isinstance(label, (float, Decimal)) or isinstance(label, int): self.insert_cell(col, NumberCell(self.__idx, col, style_index, label)) elif isinstance(label, (dt.datetime, dt.date, dt.time)): date_number = self.__excel_date_dt(label) diff --git a/xlwt/Style.py b/xlwt/Style.py index 7ad2c88..039e3d6 100644 --- a/xlwt/Style.py +++ b/xlwt/Style.py @@ -1,12 +1,11 @@ # -*- coding: windows-1252 -*- -from __future__ import print_function -from __future__ import absolute_import +from __future__ import absolute_import, print_function, unicode_literals # -*- coding: windows-1252 -*- from . import Formatting from .BIFFRecords import NumberFormatRecord, XFRecord, StyleRecord -from future import * +from future.builtins import * FIRST_USER_DEFINED_NUM_FORMAT_IDX = 164 diff --git a/xlwt/UnicodeUtils.py b/xlwt/UnicodeUtils.py index 5a88c4c..9d0077f 100644 --- a/xlwt/UnicodeUtils.py +++ b/xlwt/UnicodeUtils.py @@ -40,10 +40,11 @@ ''' -from __future__ import absolute_import -from struct import pack +from __future__ import absolute_import, division, unicode_literals from future.builtins import * +from .Utils import pack, unpack + def upack2(s, encoding='ascii'): # If not unicode, make it so. if isinstance(s, str): diff --git a/xlwt/Utils.py b/xlwt/Utils.py index 099adc4..3934dcc 100644 --- a/xlwt/Utils.py +++ b/xlwt/Utils.py @@ -3,9 +3,12 @@ # Utilities for work with reference to cells and with sheetnames from __future__ import absolute_import, unicode_literals +from future.builtins import * +from future import utils + import re +import struct from .ExcelMagic import MAX_ROW, MAX_COL -from future import * _re_cell_ex = re.compile(r"(\$?)([A-I]?[A-Z])(\$?)(\d+)", re.IGNORECASE) _re_row_range = re.compile(r"\$?(\d+):\$?(\d+)") @@ -14,6 +17,24 @@ _re_cell_ref = re.compile(r"\$?([A-I]?[A-Z]\$?\d+)", re.IGNORECASE) +def pack(*args, **kwargs): + """struct.pack() must take a native string as its first argument. So we + wrap it: + """ + fmt = args[0] + rest = args[1:] + return struct.pack(utils.native_str(fmt), *rest, **kwargs) + + +def unpack(*args, **kwargs): + """struct.unpack() must take a native string as its first argument. So we + wrap it: + """ + fmt = args[0] + rest = args[1:] + return struct.unpack(utils.native_str(fmt), *rest, **kwargs) + + def col_by_name(colname): """'A' -> 0, 'Z' -> 25, 'AA' -> 26, etc """ diff --git a/xlwt/Workbook.py b/xlwt/Workbook.py index 88603b5..9163c9b 100644 --- a/xlwt/Workbook.py +++ b/xlwt/Workbook.py @@ -40,10 +40,11 @@ EOF ''' -from __future__ import absolute_import +from __future__ import absolute_import, unicode_literals +from future.builtins import * + from . import BIFFRecords from . import Style -from future import * class Workbook(object): diff --git a/xlwt/Worksheet.py b/xlwt/Worksheet.py index 1c47485..acafc03 100644 --- a/xlwt/Worksheet.py +++ b/xlwt/Worksheet.py @@ -34,12 +34,13 @@ EOF ''' -from __future__ import absolute_import +from __future__ import absolute_import, unicode_literals +from future.builtins import * + from . import BIFFRecords from . import Bitmap from . import Style import tempfile -from future import * class Worksheet(object): diff --git a/xlwt/__init__.py b/xlwt/__init__.py index 207c443..b742235 100644 --- a/xlwt/__init__.py +++ b/xlwt/__init__.py @@ -7,3 +7,5 @@ from .Formatting import Font, Alignment, Borders, Pattern, Protection from .Style import XFStyle, easyxf, easyfont, add_palette_colour from .ExcelFormula import * + +__VERSION__ = '0.8-pre' diff --git a/xlwt/antlr.py b/xlwt/antlr.py index b8a97e4..1aaf269 100644 --- a/xlwt/antlr.py +++ b/xlwt/antlr.py @@ -43,7 +43,7 @@ ## get sys module from __future__ import (absolute_import, division, print_function) from future.builtins import * -from future.utils import PY2, PY3, implements_iterator, isbytes, istext +from future.utils import PY2, PY3, implements_iterator import sys @@ -96,7 +96,7 @@ def is_string_type(x): # Simplify; xlwt doesn't support Python < 2.3 # return isinstance(x, basestring) # Complicate again: xlwt does support Python 3.x - return isbytes(x) or istext(x) + return isinstance(x, str) or isinstance(x, bytes) def assert_string_type(x): assert is_string_type(x) diff --git a/xlwt/examples/unicode2.py b/xlwt/examples/unicode2.py index 942a6e5..cc31ba1 100644 --- a/xlwt/examples/unicode2.py +++ b/xlwt/examples/unicode2.py @@ -4,8 +4,9 @@ from __future__ import absolute_import from __future__ import division +from future.builtins import * + from xlwt import * -from future import * w = Workbook() ws1 = w.add_sheet(u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK SMALL LETTER BETA}\N{GREEK SMALL LETTER GAMMA}\u2665\u041e\u041b\u042f\u2665') From c0744cff70cdc4881a66e37d77f4588ed6aee913 Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Fri, 1 Nov 2013 18:40:32 +1100 Subject: [PATCH 17/21] Update version to v0.8.0 and update docs --- HISTORY.html | 67 ++---------------------------------------------- README.md | 10 +++++--- setup.py | 10 ++++---- xlwt/__init__.py | 2 +- 4 files changed, 14 insertions(+), 75 deletions(-) diff --git a/HISTORY.html b/HISTORY.html index b35b5b2..cfe6f18 100644 --- a/HISTORY.html +++ b/HISTORY.html @@ -2,78 +2,15 @@ -xlwt HISTORY +xlwt-future history -

Version 0.8.0-pre: Py3k support added, 2013-08-17 +

Version 0.8.0: Fork of github.com/python-excel/xlwt that adds Python 3 support via python-future: 2013-11-01. Home of the fork: github.com/PythonCharmers/xlwt-future

Version 0.7.5, released 2013-04

Version 0.7.2, released to the general public via PyPI -- 2009-06-01

-
Revision: 3844 -
Author: sjmachin -
Date: 11:02:54 AM, Wednesday, 20 May 2009 -
Message: -
Added function Utils.rowcol_pair_to_cellrange. (0, 0, 65535, 255) -> "A1:IV65536" -
---- -
Modified : /xlwt/trunk/xlwt/Utils.py -
-
Revision: 3843 -
Author: sjmachin -
Date: 1:46:05 AM, Tuesday, 19 May 2009 -
Message: -
Removed Worksheet property show_empty_as_zero, -
and added attribute show_zero_values (default: 1 == True). -
---- -
Modified : /xlwt/trunk/xlwt/Worksheet.py -
-
Revision: 3841 -
Author: sjmachin -
Date: 11:58:51 AM, Wednesday, 13 May 2009 -
Message: -
Fixed formula code generation problem with formulas -
including MAX/SUM/etc functions with arguments like A1+123. -
Updated version to 0.7.2alpha. -
---- -
Modified : /xlwt/trunk/README.html -
Modified : /xlwt/trunk/setup.py -
Modified : /xlwt/trunk/xlwt/ExcelFormulaParser.py -
Modified : /xlwt/trunk/xlwt/ExcelMagic.py -
Modified : /xlwt/trunk/xlwt/__init__.py -
Modified : /xlwt/trunk/xlwt/excel-formula.g -
-
Revision: 3816 -
Author: sjmachin -
Date: 8:31:39 PM, Tuesday, 24 March 2009 -
Message: -
Added .../doc/pattern_examples.xls and put a pointer to it -
in the easyxf part of Style.py. -
---- -
Modified : /xlwt/trunk/xlwt/Style.py -
Added : /xlwt/trunk/xlwt/doc/pattern_examples.xls -
-
Revision: 3815 -
Author: sjmachin -
Date: 7:54:52 PM, Tuesday, 24 March 2009 -
Message: -
Fixed Row.set_cell_formula() bug introduced in 0.7.1. -
Fixed bug(?) with SCL/magnification handling causing(?) Excel -
to raise a dialogue box if sheet is set to open in page preview mode -
and user then switches to normal view. -
Added color and colour as synonyms for font.colour_index in easyxf. -
Removed unused attribute Row.__has_default_format. -
---- -
Modified : /xlwt/trunk/xlwt/Row.py -
Modified : /xlwt/trunk/xlwt/Style.py -
Modified : /xlwt/trunk/xlwt/Worksheet.py -
- - - - - -

Version 0.7.1, released to the general public via PyPI -- 2009-03-04

Version 0.7.0, released to the general public via PyPI diff --git a/README.md b/README.md index 4ed6e04..f4ec003 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ -xlwt -==== +xlwt-future +=========== -Fork of https://github.com/python-excel/xlwt for Python 3 support. The original claims to support Python 2.3 to 2.6 only. +Fork of https://github.com/python-excel/xlwt that supports both Python 3.3 and +Python 2.6/2.7. The original supports Python 2.3 to 2.6 only. -Library to create spreadsheet files compatible with MS Excel 97/2000/XP/2003 XLS files, on any platform, with Python 2.7 and Python 3.3. +Library to create spreadsheet files compatible with MS Excel 97/2000/XP/2003 +XLS files, on any platform. diff --git a/setup.py b/setup.py index 70ce6b8..ff6971c 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ except ImportError: from distutils.core import setup -__VERSION__ = '0.8-pre' +__VERSION__ = '0.8.0' DESCRIPTION = ( 'Library to create spreadsheet files compatible with ' @@ -44,12 +44,12 @@ ) setup( - name = 'xlwt', + name = 'xlwt-future', version = __VERSION__, - maintainer = 'John Machin', - maintainer_email = 'sjmachin@lexicon.net', + maintainer = 'Python Charmers Pty Ltd, Australia', + maintainer_email = 'help@pythoncharmers.com', url = 'http://www.python-excel.org/', - download_url = 'http://pypi.python.org/pypi/xlwt', + download_url = 'http://pypi.python.org/pypi/xlwt-future', description = DESCRIPTION, long_description = LONG_DESCRIPTION, license = 'BSD', diff --git a/xlwt/__init__.py b/xlwt/__init__.py index b742235..6c3b5fe 100644 --- a/xlwt/__init__.py +++ b/xlwt/__init__.py @@ -8,4 +8,4 @@ from .Style import XFStyle, easyxf, easyfont, add_palette_colour from .ExcelFormula import * -__VERSION__ = '0.8-pre' +__VERSION__ = '0.8.0' From c97721b609b82e41edc45260c9ee38a9cdec1b12 Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Fri, 1 Nov 2013 18:42:52 +1100 Subject: [PATCH 18/21] Bump ``future`` version requirement to v0.8.2 - Needed for isinstance() --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ff6971c..47532b6 100644 --- a/setup.py +++ b/setup.py @@ -64,5 +64,5 @@ 'tests/*.*', ], }, - install_requires=['future>=0.8.1'] + install_requires=['future>=0.8.2'] ) From f53703023f59e0d59890029f778506cb95699ead Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Fri, 1 Nov 2013 19:02:11 +1100 Subject: [PATCH 19/21] Also bump ``future`` version requirement in requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7c95b8e..3e14c5e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -future>=0.8.1 +future>=0.8.2 From 2bac9b3b49a49973ec3f63f1a546247182970dd7 Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Fri, 1 Nov 2013 19:13:37 +1100 Subject: [PATCH 20/21] Update version in README.html --- README.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.html b/README.html index 3c2c66c..8e31247 100644 --- a/README.html +++ b/README.html @@ -14,7 +14,7 @@

Licence: BSD-style (see licences.py)

-

Version of xlwt: 0.8.0-pre +

Version of xlwt: 0.8.0

Version of Python required: 2.7 or 3.3

From 2a7589279a38f22a41ac56531d435aea9ba8e5b1 Mon Sep 17 00:00:00 2001 From: Ed Schofield Date: Fri, 1 Nov 2013 19:17:24 +1100 Subject: [PATCH 21/21] Add back John Machin as maintainer in setup.py for pull request --- README.html | 2 +- setup.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.html b/README.html index 8e31247..4431018 100644 --- a/README.html +++ b/README.html @@ -16,7 +16,7 @@

Version of xlwt: 0.8.0

-

Version of Python required: 2.7 or 3.3 +

Version of Python required: 2.6/2.7 or 3.3

External modules required: future

diff --git a/setup.py b/setup.py index 47532b6..48efa3e 100644 --- a/setup.py +++ b/setup.py @@ -46,8 +46,8 @@ setup( name = 'xlwt-future', version = __VERSION__, - maintainer = 'Python Charmers Pty Ltd, Australia', - maintainer_email = 'help@pythoncharmers.com', + maintainer = 'John Machin', + maintainer_email = 'sjmachin@lexicon.net', url = 'http://www.python-excel.org/', download_url = 'http://pypi.python.org/pypi/xlwt-future', description = DESCRIPTION,