[python-tablib] Initial import (#837686)

Ralph Bean ralph at fedoraproject.org
Thu Jul 5 19:22:38 UTC 2012


commit 36926561a91888f3bae6cc8f52cd2ba16fcebd92
Author: Ralph Bean <rbean at redhat.com>
Date:   Thu Jul 5 15:22:33 2012 -0400

    Initial import (#837686)

 .gitignore             |    1 +
 0001-Py3-support.patch |  218 ++++++++++++++++++++++++++++++++++++++++++++++++
 python-tablib.spec     |  139 ++++++++++++++++++++++++++++++
 sources                |    1 +
 4 files changed, 359 insertions(+), 0 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index e69de29..e97839e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/tablib-0.9.11.20120702git752443f.tar.gz
diff --git a/0001-Py3-support.patch b/0001-Py3-support.patch
new file mode 100644
index 0000000..f3c578c
--- /dev/null
+++ b/0001-Py3-support.patch
@@ -0,0 +1,218 @@
+From 8ed3bb621d123b13e434a198a90aa5b1d6452669 Mon Sep 17 00:00:00 2001
+From: Ralph Bean <rbean at redhat.com>
+Date: Mon, 2 Jul 2012 12:47:20 -0400
+Subject: [PATCH] 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
+
diff --git a/python-tablib.spec b/python-tablib.spec
new file mode 100644
index 0000000..1d8a63a
--- /dev/null
+++ b/python-tablib.spec
@@ -0,0 +1,139 @@
+%if 0%{?fedora} > 12 || 0%{?rhel} > 6
+%global with_python3 1
+%endif
+
+%global modname tablib
+%global raw_version 0.9.11
+%global checkout 20120702git752443f
+
+Name:             python-tablib
+Version:          %{raw_version}.%{checkout}
+Release:          3%{?dist}
+Summary:          Format agnostic tabular data library (XLS, JSON, YAML, CSV)
+
+Group:            Development/Libraries
+License:          MIT
+URL:              http://github.com/kennethreitz/tablib
+Source0:          %{modname}-%{version}.tar.gz
+# https://github.com/kennethreitz/tablib/pull/68
+Patch0:           0001-Py3-support.patch
+
+BuildArch:        noarch
+
+
+BuildRequires:    python2-devel
+Requires:         PyYAML
+
+%if 0%{?with_python3}
+BuildRequires:    python-tools
+BuildRequires:    python3-devel
+%endif
+
+%description
+Tablib is a format-agnostic tabular dataset library, written in Python.
+
+Output formats supported:
+
+ - Excel (Sets + Books)
+ - JSON (Sets + Books)
+ - YAML (Sets + Books)
+ - HTML (Sets)
+ - TSV (Sets)
+ - CSV (Sets)
+
+%if 0%{?with_python3}
+%package -n python3-tablib
+Summary:        Format agnostic tabular data library (XLS, JSON, YAML, CSV)
+Group:          Development/Libraries
+
+Requires:         python3-PyYAML
+
+%description -n python3-tablib
+Tablib is a format-agnostic tabular dataset library, written in Python.
+
+Output formats supported:
+
+ - Excel (Sets + Books)
+ - JSON (Sets + Books)
+ - YAML (Sets + Books)
+ - HTML (Sets)
+ - TSV (Sets)
+ - CSV (Sets)
+
+%endif
+
+%prep
+%setup -q -n %{modname}
+%patch0 -p1 -b .py3_support
+
+# Remove shebangs
+for lib in $(find . -name "*.py"); do
+ sed '/\/usr\/bin\/env/d' $lib > $lib.new &&
+ touch -r $lib $lib.new &&
+ mv $lib.new $lib
+done
+
+%if 0%{?with_python3}
+rm -rf %{py3dir}
+cp -a . %{py3dir}
+pushd %{py3dir}
+sed -i 's/xlwt/xlwt3/' setup.py
+sed -i 's/openpyxl/openpyxl3/' setup.py
+sed -i 's/\.yaml/.yaml3/' setup.py
+
+rm -rf tablib/packages/odf
+rm -rf tablib/packages/openpyxl
+rm -rf tablib/packages/xlwt
+rm -rf tablib/packages/yaml
+
+find . -name "*.py" | grep -v 3 | xargs 2to3 -w
+
+popd
+
+%endif
+
+
+%build
+%{__python} setup.py build
+
+%if 0%{?with_python3}
+pushd %{py3dir}
+%{__python3} setup.py build
+popd
+%endif
+
+
+
+%install
+%if 0%{?with_python3}
+pushd %{py3dir}
+%{__python3} setup.py install -O1 --skip-build --root=%{buildroot}
+popd
+%endif
+
+%{__python} setup.py install -O1 --skip-build --root=%{buildroot}
+
+
+%files
+%doc README.rst LICENSE AUTHORS HACKING HISTORY.rst NOTICE TODO.rst
+%{python_sitelib}/%{modname}
+%{python_sitelib}/%{modname}-%{raw_version}*
+
+%if 0%{?with_python3}
+%files -n python3-%{modname}
+%doc README.rst LICENSE AUTHORS HACKING HISTORY.rst NOTICE TODO.rst
+%{python3_sitelib}/%{modname}
+%{python3_sitelib}/%{modname}-%{raw_version}-*
+
+%endif
+
+
+%changelog
+* Wed Jul 04 2012 Ralph Bean <rbean at redhat.com> - 0.9.11.20120702git752443f-3
+- Removed shebangs.
+
+* Wed Jul 04 2012 Ralph Bean <rbean at redhat.com> - 0.9.11.20120702git752443f-2
+- Added link to upstream bug for patch.
+
+* Thu Jun 28 2012 Ralph Bean <rbean at redhat.com> - 0.9.11.20120702git752443f-1
+- Initial package for Fedora
diff --git a/sources b/sources
index e69de29..d40453e 100644
--- a/sources
+++ b/sources
@@ -0,0 +1 @@
+9cd081ef7715e8b0a19378b0c4eeb4f3  tablib-0.9.11.20120702git752443f.tar.gz


More information about the scm-commits mailing list