Skip to content

Commit

Permalink
Flake8 & isort. Also updated six.py while on it.
Browse files Browse the repository at this point in the history
  • Loading branch information
apollo13 committed Jan 21, 2017
1 parent 07d8e43 commit f2798d0
Show file tree
Hide file tree
Showing 251 changed files with 1,309 additions and 1,033 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Expand Up @@ -30,6 +30,10 @@ matrix:
language: generic
env: TOXENV=pypy
before_install: brew install pypy
- python: 3.6
script: flake8
- python: 3.6
script: isort -c --diff

install:
- pip install tox-travis
Expand Down
9 changes: 4 additions & 5 deletions circuits/__init__.py
Expand Up @@ -18,11 +18,10 @@
except ImportError:
__version__ = "unknown"

from .core import Event
from .core import ipc, Bridge
from .core import sleep, task, Worker
from .core import handler, reprhandler, BaseComponent, Component
from .core import Debugger, Loader, Manager, Timer, TimeoutError
from .core import (
BaseComponent, Bridge, Component, Debugger, Event, Loader, Manager,
TimeoutError, Timer, Worker, handler, ipc, reprhandler, sleep, task,
)

# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
Expand Down
10 changes: 5 additions & 5 deletions circuits/app/daemon.py
Expand Up @@ -6,14 +6,14 @@
"""


from os import closerange
from os import (
_exit, chdir, closerange, dup2, fork, getpid, remove, setsid, umask,
)
from os.path import isabs
from resource import RLIM_INFINITY, RLIMIT_NOFILE, getrlimit
from sys import stderr, stdin, stdout
from resource import getrlimit, RLIM_INFINITY, RLIMIT_NOFILE
from os import _exit, chdir, dup2, setsid, fork, getpid, remove, umask


from circuits.core import handler, Component, Event
from circuits.core import Component, Event, handler


class daemonize(Event):
Expand Down
9 changes: 4 additions & 5 deletions circuits/app/dropprivileges.py
@@ -1,10 +1,9 @@
from pwd import getpwnam
from grp import getgrnam
from os import getuid, setgid, setgroups, setuid, umask
from pwd import getpwnam
from traceback import format_exc
from os import getuid, setgroups, setgid, setuid, umask


from circuits.core import handler, BaseComponent
from circuits.core import BaseComponent, handler


class DropPrivileges(BaseComponent):
Expand Down Expand Up @@ -37,7 +36,7 @@ def drop_privileges(self):
setuid(uid)

if self.umask is not None:
umask(self.umask)
umask(self.umask)
except Exception as error:
print("ERROR: Could not drop privileges {0:s}".format(error))
print(format_exc())
Expand Down
18 changes: 7 additions & 11 deletions circuits/core/__init__.py
Expand Up @@ -4,20 +4,16 @@
"""


from .bridge import Bridge, ipc
from .components import BaseComponent, Component
from .debugger import Debugger
from .events import Event
from .loader import Loader
from .bridge import ipc, Bridge
from .handlers import handler, reprhandler
from .components import BaseComponent, Component
from .manager import sleep, Manager, TimeoutError

from .values import Value

from .loader import Loader
from .manager import Manager, TimeoutError, sleep
from .timers import Timer

from .workers import task, Worker

from .debugger import Debugger
from .values import Value
from .workers import Worker, task

__all__ = (
"handler", "BaseComponent", "Component", "Event", "task",
Expand Down
13 changes: 6 additions & 7 deletions circuits/core/bridge.py
Expand Up @@ -10,19 +10,18 @@

import traceback

from ..six import b
from .components import BaseComponent
from .events import Event, exception
from .handlers import handler
from .values import Value

try:
from cPickle import dumps, loads
except ImportError:
from pickle import dumps, loads # NOQA


from ..six import b
from .values import Value
from .handlers import handler
from .events import Event, exception
from .components import BaseComponent


_sentinel = b('~~~')


Expand Down
11 changes: 6 additions & 5 deletions circuits/core/components.py
Expand Up @@ -2,14 +2,14 @@
This module defines the BaseComponent and its subclass Component.
"""

from collections import Callable
from inspect import getmembers
from itertools import chain
from types import MethodType
from inspect import getmembers
from collections import Callable

from .manager import Manager
from .handlers import handler, HandlerMetaClass
from .events import Event, registered, unregistered
from .handlers import HandlerMetaClass, handler
from .manager import Manager


class prepare_unregister(Event):
Expand Down Expand Up @@ -89,7 +89,8 @@ def __new__(cls, *args, **kwargs):
if getattr(v, "handler", False)]
)

overridden = lambda x: x in handlers and handlers[x].override
def overridden(x):
return x in handlers and handlers[x].override

for base in cls.__bases__:
if issubclass(cls, base):
Expand Down
3 changes: 1 addition & 2 deletions circuits/core/debugger.py
Expand Up @@ -6,9 +6,8 @@

import os
import sys
from traceback import format_exc, format_exception_only
from signal import SIGINT, SIGTERM

from traceback import format_exc, format_exception_only

from .components import BaseComponent
from .handlers import handler, reprhandler
Expand Down
4 changes: 2 additions & 2 deletions circuits/core/events.py
Expand Up @@ -193,6 +193,7 @@ def __init__(self, type, value, traceback, handler=None, fevent=None):
super(exception, self).__init__(type, value,
self.format_traceback(traceback),
handler=handler, fevent=fevent)

def format_traceback(self, traceback):
return format_tb(traceback)

Expand Down Expand Up @@ -325,8 +326,7 @@ def reduce_time_left(self, time_left):
"""

with self._lock:
if time_left >= 0 and (self._time_left < 0
or self._time_left > time_left):
if time_left >= 0 and (self._time_left < 0 or self._time_left > time_left):
self._time_left = time_left
if self._time_left == 0 and self.handler is not None:
m = getattr(
Expand Down
2 changes: 1 addition & 1 deletion circuits/core/handlers.py
Expand Up @@ -2,8 +2,8 @@
This module define the @handler decorator/function and the HandlesType type.
"""

from inspect import getargspec
from collections import Callable
from inspect import getargspec


def handler(*names, **kwargs):
Expand Down
7 changes: 4 additions & 3 deletions circuits/core/helpers.py
Expand Up @@ -2,15 +2,16 @@
.. codeauthor: mnl
"""

from signal import SIGINT, SIGTERM
from sys import stderr
from threading import Event
from signal import SIGINT, SIGTERM
from traceback import format_exception_only

from .handlers import handler
from .components import BaseComponent
from circuits.core.handlers import reprhandler

from .components import BaseComponent
from .handlers import handler


class FallBackGenerator(BaseComponent):

Expand Down
7 changes: 3 additions & 4 deletions circuits/core/loader.py
Expand Up @@ -7,9 +7,9 @@
import sys
from inspect import getmembers, getmodule, isclass

from .components import BaseComponent
from .handlers import handler
from .utils import safeimport
from .components import BaseComponent


class Loader(BaseComponent):
Expand Down Expand Up @@ -41,9 +41,8 @@ def load(self, name):
module = safeimport(name)
if module is not None:

test = lambda x: isclass(x) \
and issubclass(x, BaseComponent) \
and getmodule(x) is module
def test(x):
return isclass(x) and issubclass(x, BaseComponent) and getmodule(x) is module
components = [x[1] for x in getmembers(module, test)]

if components:
Expand Down
35 changes: 16 additions & 19 deletions circuits/core/manager.py
Expand Up @@ -4,35 +4,32 @@


import atexit
from time import time
from os import getpid, kill
from heapq import heappop, heappush
from inspect import isfunction
from uuid import uuid4 as uuid
from operator import attrgetter
from types import GeneratorType
from itertools import chain, count
from signal import SIGINT, SIGTERM
from heapq import heappush, heappop
from traceback import format_exc
from multiprocessing import Process, current_process
from operator import attrgetter
from os import getpid, kill
from signal import SIGINT, SIGTERM, signal as set_signal_handler
from sys import exc_info as _exc_info, stderr
from signal import signal as set_signal_handler
from threading import current_thread, Thread, RLock
from multiprocessing import current_process, Process
from threading import RLock, Thread, current_thread
from time import time
from traceback import format_exc
from types import GeneratorType
from uuid import uuid4 as uuid

from ..six import Iterator, create_bound_method, next
from ..tools import tryimport
from .events import Event, exception, generate_events, signal, started, stopped
from .handlers import handler
from .values import Value

try:
from signal import SIGKILL
except ImportError:
SIGKILL = SIGTERM


from .values import Value
from ..tools import tryimport
from .handlers import handler
from ..six import create_bound_method, next, Iterator
from .events import exception, generate_events, signal, started, stopped, Event


thread = tryimport(("thread", "_thread"))


Expand Down Expand Up @@ -450,7 +447,7 @@ def _fire(self, event, channel, priority=0):
handling = self._currently_handling

heappush(self._queue,
(priority, next(self._counter), (event, channel)))
(priority, next(self._counter), (event, channel)))
if isinstance(handling, generate_events):
handling.reduce_time_left(0)

Expand Down
19 changes: 9 additions & 10 deletions circuits/core/pollers.py
Expand Up @@ -8,17 +8,19 @@
"""

import os
import select
import platform
import select
from errno import EBADF, EINTR
from select import error as SelectError
from socket import error as SocketError, create_connection, \
socket as create_socket, AF_INET, SOCK_STREAM, socket
from socket import (
AF_INET, SOCK_STREAM, create_connection, error as SocketError, socket,
)
from threading import Thread

from circuits.core.handlers import handler

from .events import Event
from .components import BaseComponent
from .events import Event


class _read(Event):
Expand Down Expand Up @@ -57,7 +59,7 @@ def __init__(self, channel=channel):
def _create_control_con(self):
if platform.system() == "Linux":
return os.pipe()
server = create_socket(AF_INET, SOCK_STREAM)
server = socket(AF_INET, SOCK_STREAM)
server.bind(("localhost", 0))
server.listen(1)
res_list = []
Expand Down Expand Up @@ -225,11 +227,7 @@ def __init__(self, channel=channel):
self._map = {}
self._poller = select.poll()

self._disconnected_flag = (
select.POLLHUP
| select.POLLERR
| select.POLLNVAL
)
self._disconnected_flag = (select.POLLHUP | select.POLLERR | select.POLLNVAL)

self._read.append(self._ctrl_recv)
self._updateRegistration(self._ctrl_recv)
Expand Down Expand Up @@ -548,6 +546,7 @@ def _process(self, event):
elif event.filter == select.KQ_FILTER_READ:
self.fire(_read(sock), self.getTarget(sock))


Poller = Select

__all__ = ("BasePoller", "Poller", "Select", "Poll", "EPoll", "KQueue")
6 changes: 3 additions & 3 deletions circuits/core/timers.py
@@ -1,9 +1,9 @@
"""Timer component to facilitate timed events."""

from circuits.core.handlers import handler

from time import time, mktime
from datetime import datetime
from time import mktime, time

from circuits.core.handlers import handler

from .components import BaseComponent

Expand Down
4 changes: 2 additions & 2 deletions circuits/core/utils.py
Expand Up @@ -4,7 +4,6 @@
"""

import sys

from imp import reload


Expand Down Expand Up @@ -40,6 +39,7 @@ def findtype(root, component, all=False):
if components:
return components[0]


findcmp = findtype


Expand All @@ -59,5 +59,5 @@ def safeimport(name):
return __import__(name, globals(), locals(), [""])
except:
for name in sys.modules.copy():
if not name in modules:
if name not in modules:
del sys.modules[name]
2 changes: 1 addition & 1 deletion circuits/core/values.py
Expand Up @@ -3,8 +3,8 @@
"""


from .events import Event
from ..six import string_types
from .events import Event


class Value(object):
Expand Down

0 comments on commit f2798d0

Please sign in to comment.