Skip to content
This repository has been archived by the owner on Jan 11, 2025. It is now read-only.

Commit

Permalink
Merge branch 'remove-py2' into pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
booxter committed May 24, 2019
2 parents 820ff1e + 7cbfc21 commit b4f53e2
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 92 deletions.
1 change: 0 additions & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
httplib2==0.12.3
urwid==2.0.1
tweepy==3.7.0
future==0.17.1
5 changes: 0 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@
REQUIREMENTS = [
"urwid==2.0.1",
"tweepy==3.7.0",
"future==0.17.1",
]
if version_info[:2] == (2, 6):
REQUIREMENTS.append("argparse")

TEST_REQUIREMENTS = list(REQUIREMENTS)
TEST_REQUIREMENTS.extend(["mock", "pytest", "coverage", "tox"])
Expand Down Expand Up @@ -76,8 +73,6 @@
"Natural Language :: English",
"Operating System :: POSIX :: Linux",
"Operating System :: MacOS",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)


class Args(object):
class Args:
"""
Represents the arguments.
"""
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# and then run "tox" from this directory.

[tox]
envlist = py26, py27, py33, py34, py37, pypy, pep8
envlist = py33,py34,py37,pypy,pep8

[testenv]
passenv = HOME
Expand Down
7 changes: 1 addition & 6 deletions turses/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
function to authorize `turses` to use a Twitter account obtaining the OAuth
tokens.
"""
from __future__ import print_function
from builtins import input
from builtins import object

from abc import ABCMeta, abstractmethod
from gettext import gettext as _

Expand All @@ -20,7 +16,6 @@
from turses.models import is_DM
from turses.utils import encode
from turses.meta import async_thread, wrap_exceptions
from future.utils import with_metaclass


TWITTER_CONSUMER_KEY = 'OEn4hrNGknVz9ozQytoR0A'
Expand Down Expand Up @@ -75,7 +70,7 @@ def get_authorization_tokens():
return None


class ApiAdapter(with_metaclass(ABCMeta, object)):
class ApiAdapter(metaclass=ABCMeta):
"""
A simplified version of the API to use as an adapter for a real
implementation.
Expand Down
8 changes: 1 addition & 7 deletions turses/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@
$ turses -g /path/to/file
"""
from __future__ import print_function
from future import standard_library
standard_library.install_aliases()
from builtins import str
from builtins import object

from sys import exit
from configparser import RawConfigParser
from os import getenv, path, mkdir, remove
Expand Down Expand Up @@ -422,7 +416,7 @@ def invert_command_map(bindings):
return command_map


class Configuration(object):
class Configuration:
"""
Generate and parse configuration files. When instantiated, it loads the
defaults.
Expand Down
4 changes: 1 addition & 3 deletions turses/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
"""
This module contains the controller and key handling logic of turses.
"""
from builtins import object

import signal
import logging
from gettext import gettext as _
Expand Down Expand Up @@ -40,7 +38,7 @@ def merge_dicts(*args):
return result


class InputHandler(object):
class InputHandler:
"""
Maps user input to calls to :class:`Controller` functions.
"""
Expand Down
13 changes: 4 additions & 9 deletions turses/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
"""
This module contains abstract classes and decorators.
"""
from future import standard_library
standard_library.install_aliases()
from builtins import object

import logging
from abc import ABCMeta, abstractmethod, abstractproperty
from functools import wraps
from threading import Thread
from future.utils import with_metaclass


# - Decorators ----------------------------------------------------------------
Expand Down Expand Up @@ -75,7 +70,7 @@ def wrapper(*args, **kwargs):
# - Abstract classes ----------------------------------------------------------

# FIXME: Use urwid.MonitoredFocusList
class ActiveList(with_metaclass(ABCMeta, object)):
class ActiveList(metaclass=ABCMeta):
"""
A list that contains an *active* element.
Expand Down Expand Up @@ -157,7 +152,7 @@ def shift_active_end(self):
pass


class Updatable(with_metaclass(ABCMeta, object)):
class Updatable(metaclass=ABCMeta):
"""
An abstract class for making a class *updatable*.
Expand Down Expand Up @@ -231,7 +226,7 @@ def wrapper(self, *args, **kwargs):
return wrapper


class Observable(object):
class Observable:
"""
An implementation of the *observer* pattern.
Expand All @@ -254,7 +249,7 @@ def notify(self):
observer.update()


class Observer(with_metaclass(ABCMeta, object)):
class Observer(metaclass=ABCMeta):
"""
An abstract class that can subscribe to updates from
:class:`~turses.meta.Observable` instances.
Expand Down
12 changes: 4 additions & 8 deletions turses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
import time
from bisect import insort
from calendar import timegm

try:
from functools import total_ordering
except ImportError:
from turses.utils import total_ordering
from functools import total_ordering

from turses.meta import (ActiveList, UnsortedActiveList, Updatable, Observable,
notify)
Expand Down Expand Up @@ -396,7 +392,7 @@ def update_callback(self, result):
self.add_statuses(result)


class User(object):
class User:
"""
A Twitter user.
"""
Expand Down Expand Up @@ -425,7 +421,7 @@ def __init__(self,


@total_ordering
class Status(object):
class Status:
"""
A Twitter status.
"""
Expand Down Expand Up @@ -588,7 +584,7 @@ def url(self):
return None


class List(object):
class List:
"""
A Twitter list.
"""
Expand Down
6 changes: 1 addition & 5 deletions turses/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@
# or, alternatively
$ turses --session interactions
"""
from future import standard_library
standard_library.install_aliases()
from builtins import object

import re
import logging
from configparser import RawConfigParser
Expand Down Expand Up @@ -99,7 +95,7 @@ def clean_timeline_list_string(timeline_list_string):
for name in timeline_names if not invalid_name_re.match(name)]


class Session(object):
class Session:
"""Loads and saves sessions."""

def __init__(self, api):
Expand Down
22 changes: 7 additions & 15 deletions turses/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
"""
This module contains the curses UI widgets.
"""
from __future__ import division
from future import standard_library
standard_library.install_aliases()
from builtins import str
from past.utils import old_div
from builtins import object

import os
import logging
import re
Expand All @@ -35,7 +28,6 @@
configuration)
from turses.models import is_DM, TWEET_MAXIMUM_CHARACTERS
from turses.utils import encode, is_hashtag, is_username, is_url
from future.utils import with_metaclass


def surround_with_spaces(s):
Expand Down Expand Up @@ -546,7 +538,7 @@ def _insert_line(self, line):
# - Editors -------------------------------------------------------------------


class BaseEditor(with_metaclass(signals.MetaSignals, WidgetWrap)):
class BaseEditor(WidgetWrap, metaclass=signals.MetaSignals):
"""Base class for editors."""
signals = ['done']

Expand Down Expand Up @@ -610,7 +602,7 @@ def emit_done_signal(self, content=None):
emit_signal(self, 'done', content)


class TextEditor(with_metaclass(signals.MetaSignals, BaseEditor)):
class TextEditor(BaseEditor, metaclass=signals.MetaSignals):
"""Editor for creating arbitrary text."""
signals = ['done']

Expand All @@ -626,7 +618,7 @@ def __init__(self,
self._wrap(self.editor)


class TweetEditor(with_metaclass(signals.MetaSignals, BaseEditor)):
class TweetEditor(BaseEditor, metaclass=signals.MetaSignals):
"""Editor for creating tweets."""
signals = ['done']

Expand Down Expand Up @@ -659,7 +651,7 @@ def submit(self):
self.emit_done_signal(self.editor.get_edit_text())


class DmEditor(with_metaclass(signals.MetaSignals, TweetEditor)):
class DmEditor(TweetEditor, metaclass=signals.MetaSignals):
"""Editor for creating DMs."""
signals = ['done']

Expand Down Expand Up @@ -773,7 +765,7 @@ def clear(self):
# - Base list widgets ---------------------------------------------------------


class Scrollable(object):
class Scrollable:
"""A interface that makes widgets *scrollable*."""
def scroll_up(self):
raise NotImplementedError
Expand Down Expand Up @@ -876,7 +868,7 @@ def __init__(self):
self.items = []
self.create_help_buffer()

offset = int(old_div(len(self.items), 5))
offset = int(len(self.items) // 5)
ScrollableWidgetWrap.__init__(self,
ScrollableListBox(self.items,
offset=offset,))
Expand Down Expand Up @@ -1184,7 +1176,7 @@ def __init__(self, original_widget, title="",
# - User ----------------------------------------------------------------------


class UserInfo(with_metaclass(signals.MetaSignals, WidgetWrap)):
class UserInfo(WidgetWrap, metaclass=signals.MetaSignals):
"""
A widget for displaying a Twitter user info.
"""
Expand Down
31 changes: 0 additions & 31 deletions turses/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,3 @@ def encode(string):
return string
else:
return string


# For Python < 2.7
# Code borrowed from python 2.7.3 stdlib
def total_ordering(cls):
"""Class decorator that fills in missing ordering methods"""
convert = {
'__lt__': [('__gt__', lambda self, other: not (self < other or self == other)),
('__le__', lambda self, other: self < other or self == other),
('__ge__', lambda self, other: not self < other)],
'__le__': [('__ge__', lambda self, other: not self <= other or self == other),
('__lt__', lambda self, other: self <= other and not self == other),
('__gt__', lambda self, other: not self <= other)],
'__gt__': [('__lt__', lambda self, other: not (self > other or self == other)),
('__ge__', lambda self, other: self > other or self == other),
('__le__', lambda self, other: not self > other)],
'__ge__': [('__le__', lambda self, other: (not self >= other) or self == other),
('__gt__', lambda self, other: self >= other and not self == other),
('__lt__', lambda self, other: not self >= other)]
}
roots = set(dir(cls)) & set(convert)
if not roots:
raise ValueError(
'must define at least one ordering operation: < > <= >=')
root = max(roots) # prefer __lt__ to __le__ to __gt__ to __ge__
for opname, opfunc in convert[root]:
if opname not in roots:
opfunc.__name__ = opname
opfunc.__doc__ = getattr(int, opname).__doc__
setattr(cls, opname, opfunc)
return cls

0 comments on commit b4f53e2

Please sign in to comment.