Skip to content

Commit b4805ef

Browse files
committed
better code style(flake8) and better test
1 parent 11b6411 commit b4805ef

File tree

11 files changed

+130
-306
lines changed

11 files changed

+130
-306
lines changed

examples/epoll_server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def loop(cls, srv):
103103
epobj.unregister(fileno)
104104
connections[fileno].close()
105105
del connections[fileno]
106-
else:
106+
else:
107107
raise Exception()
108108

109109
def parse_cmd_args():

pyfstack/_compat.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
# flake8: noqa
23
"""
34
internal python 2/python 3 bridges. Not for external use.
45
"""

pyfstack/_util.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
"""
3-
internal gevent utilities, not for external use.
3+
internal utilities, not for external use.
44
"""
55

66
from __future__ import print_function, absolute_import, division
@@ -19,15 +19,19 @@ class _NONE(object):
1919
def __repr__(self):
2020
return '<default value>'
2121

22+
2223
_NONE = _NONE()
2324

25+
2426
def copy_globals(source,
2527
globs,
2628
only_names=None,
2729
ignore_missing_names=False,
2830
names_to_ignore=(),
29-
dunder_names_to_keep=('__implements__', '__all__', '__imports__'),
30-
cleanup_globs=True):
31+
names_to_include=(),
32+
dunder_names_to_keep=('__all__', '__imports__'),
33+
cleanup_globs=True,
34+
key_check_fn=None):
3135
"""
3236
Copy attributes defined in `source.__dict__` to the dictionary in globs
3337
(which should be the caller's globals()).
@@ -37,8 +41,8 @@ def copy_globals(source,
3741
also ignored.
3842
3943
If *only_names* is given, only those attributes will be considered.
40-
In this case, *ignore_missing_names* says whether or not to raise an AttributeError
41-
if one of those names can't be found.
44+
In this case, *ignore_missing_names* says whether or not to raise an
45+
AttributeError if one of those names can't be found.
4246
4347
If cleanup_globs has a true value, then common things imported but not used
4448
at runtime are removed, including this function.
@@ -61,6 +65,10 @@ def copy_globals(source,
6165
continue
6266
if key.startswith("__") and key not in dunder_names_to_keep:
6367
continue
68+
if key_check_fn and \
69+
key_check_fn(key) is False and \
70+
key not in names_to_include:
71+
continue
6472
globs[key] = value
6573
copied.append(key)
6674

pyfstack/fcntl.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def fcntl(fd, cmd, arg=0):
2525
sz = len(arg)
2626
if sz > 1024:
2727
raise ValueError("fcntl string arg too long")
28-
c_arg = ffi.new("char[%d]"%len(arg), arg)
28+
c_arg = ffi.new("char[%d]" % len(arg), arg)
2929
else:
3030
raise ValueError("need integer or bytes")
3131
res = lib.ff_fcntl(fd, cmd, c_arg)
@@ -50,7 +50,7 @@ def ioctl(fd, request, arg=0, mutable_flag=True):
5050
sz = len(arg)
5151
if sz > 1024:
5252
raise ValueError("fcntl string arg too long")
53-
c_arg = ffi.new("char[%d]"%len(arg), arg)
53+
c_arg = ffi.new("char[%d]" % len(arg), arg)
5454

5555
res = lib.ff_ioctl(fd, request, c_arg)
5656
if res < 0:

pyfstack/fstack.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
"""
77
from __future__ import print_function, division, absolute_import
88
import sys
9-
import os
109

11-
from ._compat import integer_types, binary_type
10+
from ._compat import integer_types
1211
from ._fstack import ffi, lib
1312

1413

pyfstack/select.py

+41-39
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,43 @@
77
from __future__ import print_function, division, absolute_import
88
import math
99
from collections import defaultdict
10-
import select as _select
10+
# import select as _select
1111

1212
from ._compat import integer_types
1313
from ._fstack import ffi, lib
1414

1515

16-
EPOLLERR = lib.EPOLLERR
17-
EPOLLET = lib.EPOLLET
18-
EPOLLHUP = lib.EPOLLHUP
19-
EPOLLIN = lib.EPOLLIN
20-
EPOLLMSG = lib.EPOLLMSG
21-
EPOLLONESHOT = lib.EPOLLONESHOT
22-
EPOLLOUT = lib.EPOLLOUT
23-
EPOLLPRI = lib.EPOLLPRI
24-
EPOLLRDBAND = lib.EPOLLRDBAND
25-
EPOLLRDNORM = lib.EPOLLRDNORM
26-
EPOLLWRBAND = lib.EPOLLWRBAND
27-
EPOLLWRNORM = lib.EPOLLWRNORM
16+
EPOLLERR = lib.EPOLLERR
17+
EPOLLET = lib.EPOLLET
18+
EPOLLHUP = lib.EPOLLHUP
19+
EPOLLIN = lib.EPOLLIN
20+
EPOLLMSG = lib.EPOLLMSG
21+
EPOLLONESHOT = lib.EPOLLONESHOT
22+
EPOLLOUT = lib.EPOLLOUT
23+
EPOLLPRI = lib.EPOLLPRI
24+
EPOLLRDBAND = lib.EPOLLRDBAND
25+
EPOLLRDNORM = lib.EPOLLRDNORM
26+
EPOLLWRBAND = lib.EPOLLWRBAND
27+
EPOLLWRNORM = lib.EPOLLWRNORM
2828
# EPOLL_CLOEXEC = _select.EPOLL_CLOEXEC
29-
PIPE_BUF = lib.PIPE_BUF
30-
POLLERR = lib.POLLERR
31-
POLLHUP = lib.POLLHUP
32-
POLLIN = lib.POLLIN
33-
POLLMSG = lib.POLLMSG
34-
POLLNVAL = lib.POLLNVAL
35-
POLLOUT = lib.POLLOUT
36-
POLLPRI = lib.POLLPRI
37-
POLLRDBAND = lib.POLLRDBAND
38-
POLLRDNORM = lib.POLLRDNORM
39-
POLLWRBAND = lib.POLLWRBAND
40-
POLLWRNORM = lib.POLLWRNORM
29+
PIPE_BUF = lib.PIPE_BUF
30+
POLLERR = lib.POLLERR
31+
POLLHUP = lib.POLLHUP
32+
POLLIN = lib.POLLIN
33+
POLLMSG = lib.POLLMSG
34+
POLLNVAL = lib.POLLNVAL
35+
POLLOUT = lib.POLLOUT
36+
POLLPRI = lib.POLLPRI
37+
POLLRDBAND = lib.POLLRDBAND
38+
POLLRDNORM = lib.POLLRDNORM
39+
POLLWRBAND = lib.POLLWRBAND
40+
POLLWRNORM = lib.POLLWRNORM
4141

4242
# fliters
4343
KQ_FILTER_READ = lib.EVFILT_READ
44-
KQ_FILTER_WRITE = lib.EVFILT_WRITE
44+
KQ_FILTER_WRITE = lib.EVFILT_WRITE
4545
KQ_FILTER_AIO = lib.EVFILT_AIO
46-
KQ_FILTER_VNODE = lib.EVFILT_VNODE
46+
KQ_FILTER_VNODE = lib.EVFILT_VNODE
4747
KQ_FILTER_PROC = lib.EVFILT_PROC
4848
# KQ_FILTER_NETDEV = lib.EVFILT_NETDEV
4949
KQ_FILTER_SIGNAL = lib.EVFILT_SIGNAL
@@ -66,22 +66,22 @@
6666

6767

6868
NOTE_DELETE = lib.NOTE_DELETE
69-
NOTE_WRITE = lib.NOTE_WRITE
69+
NOTE_WRITE = lib.NOTE_WRITE
7070
NOTE_EXTEND = lib.NOTE_EXTEND
7171
NOTE_ATTRIB = lib.NOTE_ATTRIB
72-
NOTE_LINK = lib.NOTE_LINK
72+
NOTE_LINK = lib.NOTE_LINK
7373
NOTE_RENAME = lib.NOTE_RENAME
7474
NOTE_REVOKE = lib.NOTE_REVOKE
7575

7676

77-
NOTE_EXIT = lib.NOTE_EXIT
78-
NOTE_FORK = lib.NOTE_FORK
79-
NOTE_EXEC = lib.NOTE_EXEC
80-
NOTE_PCTRLMASK = lib.NOTE_PCTRLMASK
81-
NOTE_PDATAMASK = lib.NOTE_PDATAMASK
82-
NOTE_TRACK = lib.NOTE_TRACK
83-
NOTE_TRACKERR = lib.NOTE_TRACKERR
84-
NOTE_CHILD = lib.NOTE_CHILD
77+
NOTE_EXIT = lib.NOTE_EXIT
78+
NOTE_FORK = lib.NOTE_FORK
79+
NOTE_EXEC = lib.NOTE_EXEC
80+
NOTE_PCTRLMASK = lib.NOTE_PCTRLMASK
81+
NOTE_PDATAMASK = lib.NOTE_PDATAMASK
82+
NOTE_TRACK = lib.NOTE_TRACK
83+
NOTE_TRACKERR = lib.NOTE_TRACKERR
84+
NOTE_CHILD = lib.NOTE_CHILD
8585

8686

8787
class error(Exception):
@@ -116,7 +116,8 @@ def select(rlist, wlist, xlist, timeout=None):
116116
tvp = ffi.NULL
117117
else:
118118
t1, t2 = math.modf(timeout)
119-
tvp = ffi.new("struct timeval*", {"tv_sec":t1, "tv_usec":int(t2*1000)})
119+
tv = {"tv_sec": t1, "tv_usec": int(t2*1000)}
120+
tvp = ffi.new("struct timeval*", tv)
120121
ret = lib.ff_select(maxfd1, rfdset, wfdset, xfdset, tvp)
121122
if ret < 0:
122123
raise error("select: ")
@@ -196,7 +197,8 @@ def poll(self, timeout=-1, maxevents=-1):
196197
if maxevents != self.maxevents:
197198
self.events = ffi.new("struct epoll_event[]", maxevents)
198199
self.maxevents = maxevents
199-
nfds = lib.ff_epoll_wait(self.epfd, self.events, self.maxevents, timeout)
200+
nfds = lib.ff_epoll_wait(self.epfd, self.events,
201+
self.maxevents, timeout)
200202
if nfds < 0:
201203
raise error("poll: ")
202204
res = []

0 commit comments

Comments
 (0)