Skip to content

Commit 6ac2667

Browse files
authored
chore: python 3.x syntax migration (#314)
2 parents 73d2bc5 + f42469d commit 6ac2667

18 files changed

+38
-124
lines changed

docs/conf.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import inspect
32
import os
43
import sys
@@ -109,8 +108,8 @@ def setup(app):
109108
latex_documents = [
110109
(
111110
'index',
112-
'{0}.tex'.format(about['__package_name__']),
113-
'{0} Documentation'.format(about['__title__']),
111+
'{}.tex'.format(about['__package_name__']),
112+
'{} Documentation'.format(about['__title__']),
114113
about['__author__'],
115114
'manual',
116115
)
@@ -120,7 +119,7 @@ def setup(app):
120119
(
121120
'index',
122121
about['__package_name__'],
123-
'{0} Documentation'.format(about['__title__']),
122+
'{} Documentation'.format(about['__title__']),
124123
about['__author__'],
125124
1,
126125
)
@@ -129,8 +128,8 @@ def setup(app):
129128
texinfo_documents = [
130129
(
131130
'index',
132-
'{0}'.format(about['__package_name__']),
133-
'{0} Documentation'.format(about['__title__']),
131+
'{}'.format(about['__package_name__']),
132+
'{} Documentation'.format(about['__title__']),
134133
about['__author__'],
135134
about['__package_name__'],
136135
about['__description__'],

libtmux/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# flake8: NOQA
32
from .__about__ import (
43
__author__,

libtmux/_compat.py

+30-74
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,54 @@
11
# -*- coding: utf8 -*-
22
# flake8: NOQA
3+
import configparser
4+
import pickle
35
import sys
6+
import urllib.parse as urlparse
7+
from collections.abc import MutableMapping
8+
from io import BytesIO, StringIO
9+
from string import ascii_lowercase
10+
from urllib.request import urlretrieve
411

512
PY2 = sys.version_info[0] == 2
613

714
_identity = lambda x: x
815

916

10-
if PY2:
11-
unichr = unichr
12-
text_type = unicode
13-
string_types = (str, unicode)
14-
integer_types = (int, long)
15-
from urllib import urlretrieve
17+
unichr = chr
18+
text_type = str
19+
string_types = (str,)
20+
integer_types = (int,)
1621

17-
text_to_native = lambda s, enc: s.encode(enc)
22+
text_to_native = lambda s, enc: s
1823

19-
iterkeys = lambda d: d.iterkeys()
20-
itervalues = lambda d: d.itervalues()
21-
iteritems = lambda d: d.iteritems()
24+
iterkeys = lambda d: iter(d.keys())
25+
itervalues = lambda d: iter(d.values())
26+
iteritems = lambda d: iter(d.items())
2227

23-
from itertools import imap, izip
2428

25-
import ConfigParser as configparser
26-
import cPickle as pickle
27-
from cStringIO import StringIO as BytesIO
28-
from StringIO import StringIO
29+
izip = zip
30+
imap = map
31+
range_type = range
2932

30-
range_type = xrange
33+
cmp = lambda a, b: (a > b) - (a < b)
3134

32-
cmp = cmp
35+
console_encoding = sys.__stdout__.encoding
3336

34-
input = raw_input
35-
from collections import MutableMapping
36-
from string import lower as ascii_lowercase
37+
implements_to_string = _identity
3738

38-
import urlparse
3939

40-
exec('def reraise(tp, value, tb=None):\n raise tp, value, tb')
41-
42-
def implements_to_string(cls):
43-
cls.__unicode__ = cls.__str__
44-
cls.__str__ = lambda x: x.__unicode__().encode('utf-8')
45-
return cls
46-
47-
def console_to_str(s):
40+
def console_to_str(s):
41+
""" From pypa/pip project, pip.backwardwardcompat. License MIT. """
42+
try:
43+
return s.decode(console_encoding, 'ignore')
44+
except UnicodeDecodeError:
4845
return s.decode('utf_8', 'ignore')
4946

5047

51-
else:
52-
unichr = chr
53-
text_type = str
54-
string_types = (str,)
55-
integer_types = (int,)
56-
57-
text_to_native = lambda s, enc: s
58-
59-
iterkeys = lambda d: iter(d.keys())
60-
itervalues = lambda d: iter(d.values())
61-
iteritems = lambda d: iter(d.items())
62-
63-
import configparser
64-
import pickle
65-
from io import BytesIO, StringIO
66-
67-
izip = zip
68-
imap = map
69-
range_type = range
70-
71-
cmp = lambda a, b: (a > b) - (a < b)
72-
73-
input = input
74-
import urllib.parse as urllib
75-
import urllib.parse as urlparse
76-
from string import ascii_lowercase
77-
from urllib.request import urlretrieve
78-
79-
console_encoding = sys.__stdout__.encoding
80-
81-
implements_to_string = _identity
82-
83-
from collections.abc import MutableMapping
84-
85-
def console_to_str(s):
86-
""" From pypa/pip project, pip.backwardwardcompat. License MIT. """
87-
try:
88-
return s.decode(console_encoding, 'ignore')
89-
except UnicodeDecodeError:
90-
return s.decode('utf_8', 'ignore')
91-
92-
def reraise(tp, value, tb=None):
93-
if value.__traceback__ is not tb:
94-
raise (value.with_traceback(tb))
95-
raise value
48+
def reraise(tp, value, tb=None):
49+
if value.__traceback__ is not tb:
50+
raise (value.with_traceback(tb))
51+
raise value
9652

9753

9854
number_types = integer_types + (float,)

libtmux/common.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# flake8: NOQA W605
32
"""Helper methods and mixins.
43

libtmux/exc.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
# -*- coding: utf-8 -*-
21
"""libtmux exceptions.
32
43
libtmux.exc
54
~~~~~~~~~~~
65
76
"""
8-
from __future__ import absolute_import, unicode_literals, with_statement
97

108

119
class LibTmuxException(Exception):

libtmux/formats.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""Format variables for tmux objects.
32
43
libtmux.formats
@@ -8,8 +7,6 @@
87
98
"""
109

11-
from __future__ import absolute_import, unicode_literals, with_statement
12-
1310
SESSION_FORMATS = [
1411
'session_name',
1512
'session_windows',

libtmux/pane.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
# -*- coding: utf-8 -*-
21
# flake8: NOQA W605
32
"""Pythonization of the :ref:`tmux(1)` pane.
43
54
libtmux.pane
65
~~~~~~~~~~~~
76
87
"""
9-
from __future__ import absolute_import, unicode_literals, with_statement
10-
118
import logging
129

1310
from . import exc

libtmux/server.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
# -*- coding: utf-8 -*-
21
"""Pythonization of the :term:`tmux(1)` server.
32
43
libtmux.server
54
~~~~~~~~~~~~~~
65
76
"""
8-
from __future__ import absolute_import, unicode_literals, with_statement
9-
107
import logging
118
import os
129

@@ -113,11 +110,11 @@ def cmd(self, *args, **kwargs):
113110

114111
args = list(args)
115112
if self.socket_name:
116-
args.insert(0, '-L{0}'.format(self.socket_name))
113+
args.insert(0, '-L{}'.format(self.socket_name))
117114
if self.socket_path:
118-
args.insert(0, '-S{0}'.format(self.socket_path))
115+
args.insert(0, '-S{}'.format(self.socket_path))
119116
if self.config_file:
120-
args.insert(0, '-f{0}'.format(self.config_file))
117+
args.insert(0, '-f{}'.format(self.config_file))
121118
if self.colors:
122119
if self.colors == 256:
123120
args.insert(0, '-2')

libtmux/session.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
# -*- coding: utf-8 -*-
21
"""Pythonization of the :term:`tmux(1)` session.
32
43
libtmux.session
54
~~~~~~~~~~~~~~~
65
76
"""
8-
from __future__ import absolute_import, unicode_literals, with_statement
9-
107
import logging
118
import os
129

libtmux/test.py

-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
# -*- coding: utf-8 -*-
21
"""Helper methods for libtmux and downstream libtmux libraries."""
3-
4-
from __future__ import absolute_import, unicode_literals, with_statement
5-
62
import contextlib
73
import logging
84
import os

libtmux/window.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
# -*- coding: utf-8 -*-
21
"""Pythonization of the :term:`tmux(1)` window.
32
43
libtmux.window
54
~~~~~~~~~~~~~~
65
76
"""
8-
from __future__ import absolute_import, unicode_literals, with_statement
9-
107
import logging
118
import os
129
import shlex

tests/conftest.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
import logging
42
import os
53

tests/test_common.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""Tests for utility functions in tmux."""
32

43
import re

tests/test_pane.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# -*- coding: utf-8 -*-
21
"""Test for tmuxp Pane object."""
3-
from __future__ import absolute_import, unicode_literals, with_statement
4-
52
import logging
63

74
logger = logging.getLogger(__name__)

tests/test_server.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# -*- coding: utf-8 -*-
21
"""Test for tmuxp Server object."""
3-
from __future__ import absolute_import, unicode_literals, with_statement
4-
52
import logging
63

74
from libtmux import Server

tests/test_session.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# -*- coding: utf-8 -*-
21
"""Test for tmuxp Session object."""
3-
from __future__ import absolute_import, unicode_literals, with_statement
4-
52
import logging
63

74
import pytest

tests/test_tmuxobject.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# -*- coding: utf-8 -*-
21
"""Test for tmuxp TmuxRelationalObject and TmuxMappingObject."""
3-
from __future__ import absolute_import, unicode_literals, with_statement
4-
52
import logging
63

74
from libtmux import Pane, Session, Window

tests/test_window.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# -*- coding: utf-8 -*-
21
"""Test for tmuxp Window object."""
3-
from __future__ import absolute_import, unicode_literals, with_statement
4-
52
import logging
63

74
import pytest

0 commit comments

Comments
 (0)