Skip to content

Commit

Permalink
Remove Python 2.x support
Browse files Browse the repository at this point in the history
  • Loading branch information
firecat53 committed Jan 9, 2020
1 parent ee79b33 commit a6cd2ee
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 95 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
*Version 1.4.4 2020/01/09*

- Remove Python 2.x support
- Add note about Visidata and minimal maintenance
- Add file URI scheme support
- Fix flake8 errors
- Remove python 3.3 support
- Update travis.yml for newer python versions and fix flake8 command
- Add sample text with long/wide characters

*Version 1.4.3 2017/11/13*

- Added an additional parse step for space-delimited files:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Scott Hansen <firecat four one five three at gmail dot com>

Based on code contributed by A.M. Kuchling <amk at amk dot ca>

Copyright (c) 2019, Scott Hansen
Copyright (c) 2020, Scott Hansen

Copyright (c) 2010, Andrew M. Kuchling

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ it are shown the contents of that cell.

Features:
---------
* Python 2.7 and 3.4+
* Python 3.4+
* Spreadsheet-like view for easily visualizing tabular data
* Vim-like navigation (h,j,k,l, g(top), G(bottom), 12G goto line 12, m - mark,
' - goto mark, etc.)
Expand All @@ -62,7 +62,7 @@ Features:
Requires:
---------

* Python 2.7 or 3.4+
* Python 3.4+
* Xsel or xclip (Optional - only required for 'yank' to clipboard)

Installation:
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
Expand Down
104 changes: 20 additions & 84 deletions tabview/tabview.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
Based on code contributed by A.M. Kuchling <amk at amk dot ca>
"""
from __future__ import print_function, division, unicode_literals

import csv
import _curses
import curses
Expand All @@ -23,48 +21,24 @@
from subprocess import Popen, PIPE
from textwrap import wrap
import unicodedata
from urllib.parse import urlparse
import shlex

if sys.version_info.major < 3:
from urlparse import urlparse
else:
from urllib.parse import urlparse


if sys.version_info.major < 3:
# Python 2.7 shim
str = unicode # noqa

def KEY_CTRL(key):
return curses.ascii.ctrl(bytes(key))

def addstr(*args):
scr, args = args[0], list(args[1:])
x = 2 if len(args) > 2 else 0
args[x] = args[x].encode(sys.stdout.encoding)
return scr.addstr(*args)
basestring = str
file = io.FileIO

def insstr(*args):
scr, args = args[0], list(args[1:])
x = 2 if len(args) > 2 else 0
args[x] = args[x].encode(sys.stdout.encoding)
return scr.insstr(*args)
# Python 3 wrappers
def KEY_CTRL(key):
return curses.ascii.ctrl(key)

else:
basestring = str
file = io.FileIO
def addstr(*args):
scr, args = args[0], args[1:]
return scr.addstr(*args)

# Python 3 wrappers
def KEY_CTRL(key):
return curses.ascii.ctrl(key)

def addstr(*args):
scr, args = args[0], args[1:]
return scr.addstr(*args)

def insstr(*args):
scr, args = args[0], args[1:]
return scr.insstr(*args)
def insstr(*args):
scr, args = args[0], args[1:]
return scr.insstr(*args)


class ReloadException(Exception):
Expand Down Expand Up @@ -655,8 +629,6 @@ def yank_cell(self):
yp = self.y + self.win_y
xp = self.x + self.win_x
s = self.data[yp][xp]
if sys.version_info.major < 3:
s = s.encode(sys.stdout.encoding or 'utf-8')
# Bail out if not running in X
try:
os.environ['DISPLAY']
Expand Down Expand Up @@ -1154,12 +1126,8 @@ def fix_newlines(data):
without messing up Unicode support.
"""
if sys.version_info.major < 3:
if len(data) == 1 and '\r' in data[0]:
data = data[0].split('\r')
else:
if len(data) == 1 and b'\r' in data[0]:
data = data[0].split(b'\r')
if len(data) == 1 and b'\r' in data[0]:
data = data[0].split(b'\r')
return data


Expand Down Expand Up @@ -1187,8 +1155,6 @@ def process_data(data, enc=None, delim=None, quoting=None, quote_char=str('"')):
data = fix_newlines(data)
if data_list_or_file(data) == 'list':
# If data is from an object (list of lists) instead of a file
if sys.version_info.major < 3:
data = py2_list_to_unicode(data)
return pad_data(data)
if enc is None:
enc = detect_encoding(data)
Expand All @@ -1201,44 +1167,18 @@ def process_data(data, enc=None, delim=None, quoting=None, quote_char=str('"')):
else:
quoting = csv.QUOTE_MINIMAL
csv_data = []
if sys.version_info.major < 3:
csv_obj = csv.reader(data, delimiter=delim.encode(enc),
quoting=quoting, quotechar=quote_char.encode(enc))
for row in csv_obj:
row = [str(x, enc) for x in row]
csv_data.append(row)
else:
data = [i.decode(enc) for i in data]
csv_obj = csv.reader(data, delimiter=delim, quoting=quoting,
quotechar=quote_char)
for row in csv_obj:
csv_data.append(row)
data = [i.decode(enc) for i in data]
csv_obj = csv.reader(data, delimiter=delim, quoting=quoting,
quotechar=quote_char)
for row in csv_obj:
csv_data.append(row)
return pad_data(csv_data)


def py2_list_to_unicode(data):
"""Convert strings/int to unicode for python 2
"""
enc = detect_encoding()
csv_data = []
for row in data:
r = []
for x in row:
try:
r.append(str(x, enc))
except TypeError:
# The 'enc' parameter fails with int values
r.append(str(x))
csv_data.append(r)
return csv_data


def data_list_or_file(data):
"""Determine if 'data' is a list of lists or list of strings/bytes
Python 3 - reading a file returns a list of byte strings
Python 2 - reading a file returns a list of strings
Both - list of lists is just a list
Returns: 'file' if data was from a file, 'list' if from a python list/tuple
Expand Down Expand Up @@ -1349,11 +1289,7 @@ def view(data, enc=None, start_pos=(0, 0), column_width=20, column_gap=2,
or "" if input was not from a file
"""
if sys.version_info.major < 3:
lc_all = locale.getlocale(locale.LC_ALL)
locale.setlocale(locale.LC_ALL, '')
else:
lc_all = None
lc_all = None
if info is None:
info = ""
try:
Expand Down
8 changes: 2 additions & 6 deletions test/test_tabview.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,14 @@ def tabview_file(self, info):
"""
fn, _, sample_data = info
code = 'utf-8' # Per top line of file
res = t.process_data(self.data(fn))
# Check that process_file returns a list of lists
self.assertEqual(type(res), list)
self.assertEqual(type(res[0]), list)
# Have to decode res1 and res2 from utf-8 so they can be compared to
# the results from the file, which are unicode (py2) or string (py3)
# the results from the file, which are string (py3)
for j, i in enumerate(sample_data):
try:
i = i.decode(code)
except AttributeError:
i = str(i)
i = str(i)
self.assertEqual(i, res[-1][j])

def test_tabview_file_unicode(self):
Expand Down

0 comments on commit a6cd2ee

Please sign in to comment.