Commit 0f1bbe6a authored by Mark Peek's avatar Mark Peek

pep8

parent 3c50e63b
......@@ -53,8 +53,8 @@ def default_exception_notifier():
me.id,
me.name,
compact_traceback(),
)
)
)
set_exception_notifier (default_exception_notifier)
......@@ -104,7 +104,7 @@ def in_parallel (fun_arg_list):
# InParallelError, [(SUCCESS, result0), (FAILURE, exc_info1), ...]
n = len(fun_arg_list)
if n==0:
if n == 0:
return []
result_list = [None] * n
sem = inverted_semaphore(n)
......@@ -115,11 +115,11 @@ def in_parallel (fun_arg_list):
i,
sem,
fun_arg_list[i]
)
)
sem.block_till_zero()
for i in xrange (n):
if result_list[i][0] is FAILURE:
raise InParallelError, result_list
raise InParallelError(result_list)
# no errors, convert to a simple result list
return [x[1] for x in result_list]
......@@ -230,7 +230,7 @@ def spawn (fun, *args, **kwargs):
:returns: The new coroutine object.
"""
if kwargs.has_key('thread_name'):
if 'thread_name' in kwargs:
thread_name = kwargs['thread_name']
del kwargs['thread_name']
else:
......@@ -253,7 +253,7 @@ def new (fun, *args, **kwargs):
:returns: The new coroutine object.
"""
if kwargs.has_key('thread_name'):
if 'thread_name' in kwargs:
thread_name = kwargs['thread_name']
del kwargs['thread_name']
else:
......
......@@ -59,9 +59,9 @@ class backdoor:
self.global_dict = global_dict
# allow the user to change the prompts:
if not sys.__dict__.has_key('ps1'):
if 'ps1' not in sys.__dict__:
sys.ps1 = '>>> '
if not sys.__dict__.has_key('ps2'):
if 'ps2' not in sys.__dict__:
sys.ps2 = '... '
def send (self, data):
......@@ -199,7 +199,7 @@ def serve (port=None, ip='', unix_path=None, welcome_message=None, global_dict=N
try:
os.remove (unix_path)
except OSError, why:
if why[0]==errno.ENOENT:
if why[0] == errno.ENOENT:
pass
else:
raise
......@@ -223,9 +223,9 @@ def serve (port=None, ip='', unix_path=None, welcome_message=None, global_dict=N
break
except OSError, why:
if why[0] != errno.EADDRINUSE:
raise OSError, why
raise OSError(why)
else:
raise Exception, "couldn't bind a port (try not specifying a port)"
raise Exception("couldn't bind a port (try not specifying a port)")
if client_class is None:
client_class = client
......@@ -268,15 +268,15 @@ class ssh_server:
self.server_key = server_key
self.authenticators = authenticators
coro.spawn (self.serve)
def serve (self):
serve (self.port, self.addr, client_class=self.new_connection)
def new_connection (self, conn, addr, welcome_message, global_dict):
#debug = coro.ssh.util.debug.Debug()
#debug.level = coro.ssh.util.debug.DEBUG_3
# debug = coro.ssh.util.debug.Debug()
# debug.level = coro.ssh.util.debug.DEBUG_3
transport = coro.ssh.l4_transport.coro_socket_transport.coro_socket_transport(sock=conn)
server = coro.ssh.transport.server.SSH_Server_Transport (self.server_key) #, debug=debug)
server = coro.ssh.transport.server.SSH_Server_Transport (self.server_key) # , debug=debug)
authenticator = coro.ssh.auth.userauth.Authenticator (server, self.authenticators)
server.connect (transport, authenticator)
service = coro.ssh.connection.connect.Connection_Service (server, ssh_repl)
......
......@@ -41,21 +41,21 @@ class stdin (coro.sock):
coro.sock.__init__ (self, fd=0)
self.fd = 0
self.old = termios.tcgetattr (self.fd)
#print 'old=%r' % (self.old,)
# print 'old=%r' % (self.old,)
self.new = termios.tcgetattr (self.fd)
self.new[LFLAG] &= ~(termios.ICANON | termios.ECHO | termios.IEXTEN)
self.new[IFLAG] &= ~(termios.IGNBRK | termios.IXOFF | termios.IXON)
self.new[CC][termios.VMIN] = 1
self.new[CC][termios.VTIME] = 0
self.new[CC][termios.CINTR] = 254 # block ctrl-c? doesn't work.
#print 'new=%r' % (self.new,)
self.new[CC][termios.CINTR] = 254 # block ctrl-c? doesn't work.
# print 'new=%r' % (self.new,)
termios.tcsetattr (self.fd, termios.TCSANOW, self.new)
def __dealloc__ (self):
self.restore()
def restore (self):
#print '[restoring stdin to %r]' % (self.old,)
# print '[restoring stdin to %r]' % (self.old,)
termios.tcsetattr (self.fd, termios.TCSAFLUSH, self.old)
def read (self, size):
......
......@@ -31,8 +31,6 @@ TODO
"""
import urllib
import cgi
import sys
......@@ -137,9 +135,15 @@ function ts_resortTable(lnk,clid) {
// We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
// don't do sortbottom rows
for (i=0;i<newRows.length;i++) { if (!newRows[i].className || (newRows[i].className && (newRows[i].className.indexOf('sortbottom') == -1))) table.tBodies[0].appendChild(newRows[i]);}
for (i=0;i<newRows.length;i++) {
if (!newRows[i].className || (newRows[i].className && (newRows[i].className.indexOf('sortbottom') == -1)))
table.tBodies[0].appendChild(newRows[i]);
}
// do sortbottom rows only
for (i=0;i<newRows.length;i++) { if (newRows[i].className && (newRows[i].className.indexOf('sortbottom') != -1)) table.tBodies[0].appendChild(newRows[i]);}
for (i=0;i<newRows.length;i++) {
if (newRows[i].className && (newRows[i].className.indexOf('sortbottom') != -1))
table.tBodies[0].appendChild(newRows[i]);
}
// Delete any other arrows there may be showing
var allspans = document.getElementsByTagName("span");
......@@ -156,7 +160,8 @@ function ts_resortTable(lnk,clid) {
function getParent(el, pTagName) {
if (el == null) return null;
else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase()) // Gecko bug, supposed to be uppercase
else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())
// Gecko bug, supposed to be uppercase
return el;
else
return getParent(el.parentNode, pTagName);
......@@ -251,7 +256,7 @@ def _mapfuns(d1, d2):
m1 = [(_name(f), f) for f in d1]
m2 = dict([(_name(f), f) for f in d2])
return dict([(v, m2[k]) for k,v in m1 if k in m2])
return dict([(v, m2[k]) for k, v in m1 if k in m2])
class profile_data:
......@@ -296,8 +301,8 @@ class profile_data:
# Find any columns that have all zeros and skip them.
has_nonzero = {}
# Also determine the sum for the column.
column_sums = [0]*len(self.headings)
empty_cols = [0]*len(self.headings)
column_sums = [0] * len(self.headings)
empty_cols = [0] * len(self.headings)
for heading in self.headings:
has_nonzero[heading] = False
......@@ -332,21 +337,21 @@ class profile_data:
try:
calls2, data_tuple2, aggregate_data_tuple2 = other_profile[m[function_string]]
except KeyError:
calls2, data_tuple2, aggregate_data_tuple2 = 0,empty_cols, empty_cols
calls2, data_tuple2, aggregate_data_tuple2 = 0, empty_cols, empty_cols
print ' <tr align=right>'
print ' <td>%s</td>' % (calls-calls2,)
print ' <td>%s</td>' % (calls - calls2, )
for i, heading in enumerate(self.headings):
if heading not in skip_headings:
if aggregate:
data_item = aggregate_data_tuple[i]-aggregate_data_tuple2[i]
data_item = aggregate_data_tuple[i] - aggregate_data_tuple2[i]
else:
data_item = data_tuple[i]-data_tuple2[i]
data_item = data_tuple[i] - data_tuple2[i]
if isinstance(data_item, float):
value = '%.6f' % (data_item,)
else:
value = data_item
if data_item and function_string != '<wait>':
pct = ' (%.2f%%)' % ((float(data_item)/column_sums[i])*100,)
pct = ' (%.2f%%)' % ((float(data_item) / column_sums[i]) * 100,)
else:
pct = ''
print ' <td>%s%s</td>' % (value, pct)
......@@ -355,15 +360,15 @@ class profile_data:
per = data_item
else:
if isinstance(data_item, float):
per = '%.6f' % (data_item/calls,)
per = '%.6f' % (data_item / calls,)
else:
per = data_item/calls
print ' <td>%s</td>' % (per,)
per = data_item / calls
print ' <td>%s</td>' % (per, )
print ' <td align=left><a name="tt_%s"></a><a href="#cg_%s">%s</a></td>' % (
urllib.quote_plus(function_string),
urllib.quote_plus(function_string),
cgi.escape(function_string, quote=True)
)
urllib.quote_plus(function_string),
urllib.quote_plus(function_string),
cgi.escape(function_string, quote=True)
)
print ' </tr>'
print '</table>'
print '<p><tt>/call</tt> columns represent the time spent in that function per call <b>on average</b>.'
......@@ -374,7 +379,7 @@ class profile_data:
rg = {}
for caller_string, callees in self.call_data.iteritems():
for callee_string, call_count in callees:
if rg.has_key(callee_string):
if callee_string in rg:
rg[callee_string].append((caller_string, call_count))
else:
rg[callee_string] = [(caller_string, call_count)]
......@@ -394,23 +399,21 @@ class profile_data:
print '</tt>'
print '<pre>'
# Print callers.
if rg.has_key(function_string):
if function_string in rg:
l = []
for caller, count in rg[function_string]:
l.append((caller, count))
l.sort(lambda a,b: cmp(a[1], b[1]))
l.sort(lambda a, b: cmp(a[1], b[1]))
for caller, count in l:
print '%10i/%-10i (%04.1f%%) <a href="#tt_%s">%s</a>' % (
count,
calls,
(float(count)/calls) * 100,
(float(count) / calls) * 100,
urllib.quote_plus(caller),
cgi.escape(caller, quote=True)
)
)
print '%15i <b>%s</b>' % (calls,
function_string
)
print '%15i <b>%s</b>' % (calls, function_string)
# Print callees.
callees2 = []
......@@ -418,15 +421,15 @@ class profile_data:
for callee_string, call_count in callees:
callee_calls = self.profile_data.get(callee_string, [1])[0]
callees2.append((callee_string, call_count, callee_calls))
callees2.sort(lambda a,b: cmp(a[1], b[1]))
callees2.sort(lambda a, b: cmp(a[1], b[1]))
for callee_string, call_count, callee_calls in callees2:
print '%10i/%-10i (%04.1f%%) <a href="#tt_%s">%s</a>' % (
call_count,
callee_calls,
(float(call_count)/callee_calls) * 100,
(float(call_count) / callee_calls) * 100,
urllib.quote_plus(callee_string),
cgi.escape(callee_string, quote=True)
)
)
print '</pre>'
print '<hr>'
......@@ -446,7 +449,6 @@ class profile_data:
print
print 'Profile data values of 0 are not displayed.'
def _print_header(self):
print '<html><head><title>Shrapnel Profile</title></head><body bgcolor="#ffffff">'
print '<script type="text/javascript"><!--'
......@@ -493,4 +495,3 @@ if __name__ == '__main__':
baseline = sys.argv[1]
otherfile = sys.argv[2] if len(sys.argv) == 3 else None
main(baseline, otherfile)
......@@ -107,13 +107,13 @@ def go (fun, *args, **kwargs):
:keyword profile_bench: The bench object type to use. Defaults to
:class:`coro.rusage_bench`.
"""
if kwargs.has_key('profile_filename'):
if 'profile_filename' in kwargs:
profile_filename = kwargs['profile_filename']
del kwargs['profile_filename']
else:
profile_filename = '/tmp/coro_profile.bin'
if kwargs.has_key('profile_bench'):
if 'profile_bench' in kwargs:
profile_bench = kwargs['profile_bench']
del kwargs['profile_bench']
else:
......@@ -146,25 +146,25 @@ def stop(filename='/tmp/coro_profile.bin'):
p.stop()
_dump(p, filename)
def tak1 (x,y,z):
def tak1 (x, y, z):
if y >= x:
return z
else:
return tak1 (
tak1 (x-1, y, z),
tak2 (y-1, z, x),
tak2 (z-1, x, y)
)
tak1 (x - 1, y, z),
tak2 (y - 1, z, x),
tak2 (z - 1, x, y)
)
def tak2 (x,y,z):
def tak2 (x, y, z):
if y >= x:
return z
else:
return tak2 (
tak2 (x-1, y, z),
tak1 (y-1, z, x),
tak1 (z-1, x, y)
)
tak2 (x - 1, y, z),
tak1 (y - 1, z, x),
tak1 (z - 1, x, y)
)
if __name__ == '__main__':
go (tak2, 18, 12, 6)
......
......@@ -4,6 +4,7 @@ class socket_producer:
def __init__ (self, conn, buffer_size=8000):
self.conn = conn
self.buffer_size = buffer_size
def next (self):
return self.conn.recv (self.buffer_size)
......@@ -32,7 +33,7 @@ class buffered_stream:
if self.buffer[i] == delim[m]:
m += 1
if m == ld:
result, self.buffer = self.buffer[:i+1], self.buffer[i+1:]
result, self.buffer = self.buffer[:i + 1], self.buffer[i + 1:]
yield result
return
else:
......@@ -54,7 +55,7 @@ class buffered_stream:
i = 0
while i < len (self.buffer):
if dfa.consume (self.buffer[i]):
result, self.buffer = self.buffer[:i+1], self.buffer[i+1:]
result, self.buffer = self.buffer[:i + 1], self.buffer[i + 1:]
yield result
return
i += 1
......@@ -80,7 +81,7 @@ class buffered_stream:
def read_until (self, delim, join=True):
"read until <delim>. return a list of parts unless <join> is True"
result = ( x for x in self.gen_read_until (delim) )
result = (x for x in self.gen_read_until (delim))
if join:
return ''.join (result)
else:
......@@ -88,7 +89,7 @@ class buffered_stream:
def read_exact (self, size, join=True):
"read exactly <size> bytes. return a list of parts unless <join> is True"
result = ( x for x in self.gen_read_exact (size) )
result = (x for x in self.gen_read_exact (size))
if join:
return ''.join (result)
else:
......@@ -113,4 +114,3 @@ class buffered_stream:
return
else:
yield block
......@@ -33,7 +33,7 @@ def _get_module_name(n):
try:
path, filename = os.path.split(n)
path, directory = os.path.split(path)
#name, ext = os.path.splitext(filename)
# name, ext = os.path.splitext(filename)
if directory:
return '/'.join((directory, filename))
else:
......@@ -62,9 +62,9 @@ def stack_string(f=None):
_get_module_name(f.f_code.co_filename) + ' ' +
f.f_code.co_name + '|' +
str(f.f_lineno)
)
)
f = f.f_back
return '[' + ('] ['.join(stack))+ ']'
return '[' + ('] ['.join(stack)) + ']'
def traceback_string(t=None, v=None, tb=None):
"""Returns a compact string representing the current exception.
......@@ -81,7 +81,7 @@ def traceback_string(t=None, v=None, tb=None):
Returns a string of the current exception and stack trace.
"""
if t is None:
t,v,tb = sys.exc_info()
t, v, tb = sys.exc_info()
tbinfo = []
if tb is None:
# this should never happen, but then again, lots of things
......@@ -92,7 +92,7 @@ def traceback_string(t=None, v=None, tb=None):
_get_module_name (tb.tb_frame.f_code.co_filename) + ' ' +
tb.tb_frame.f_code.co_name + '|' +
str(tb.tb_lineno)
)
)
tb = tb.tb_next
# just to be safe
......
# $Header: //prod/main/ap/shrapnel/setup.py#17 $
#!/usr/bin/env python
import sys
......@@ -17,7 +16,7 @@ except ImportError:
'\nThe Cython compiler is required to build Shrapnel.\n'
' Try "pip install cython"\n'
' *or* "easy_install cython"\n'
)
)
sys.exit (-1)
include_dir = os.getcwd()
......@@ -59,15 +58,15 @@ USE_LINUX_AIO = check_linux_aio()
compile_time_env = {
'COMPILE_LIO': check_lio(),
'COMPILE_LINUX_AIO': USE_LINUX_AIO,
'COMPILE_NETDEV' : False,
'COMPILE_LZO' : False,
'COMPILE_LZ4' : False,
'COMPILE_NETDEV': False,
'COMPILE_LZO': False,
'COMPILE_LZ4': False,
'CORO_DEBUG': False,
}
}
#--------------------------------------------------------------------------------
# --------------------------------------------------------------------------
# OpenSSL support
#--------------------------------------------------------------------------------
# --------------------------------------------------------------------------
# If you need NPN support (for SPDY), you most likely will have to link against
# newer openssl than the one that came with your OS. (this is circa 2012).
......@@ -78,7 +77,7 @@ compile_time_env = {
# statically link is a bit tricky
# Note: be sure to remove coro/ssl/openssl.c if you change this, see NPN probe below.
#ossl_base = '/Users/rushing/src/openssl-1.0.1c'
# ossl_base = '/Users/rushing/src/openssl-1.0.1c'
#
# OS X: as of 10.9, openssl seems to have been completely removed. You'll need
# to install from the sources. Once this is done, use '/usr/local/ssl/' for ossl_base.
......@@ -101,15 +100,15 @@ OpenSSL_Extension = Extension (
['coro/ssl/openssl.pyx'],
depends=['coro/ssl/openssl.pxi'],
# manual static link
#extra_link_args = [ O('libcrypto.a'), O('libssl.a') ],
# extra_link_args = [O('libcrypto.a'), O('libssl.a')],
# link to an absolute location
#extra_link_args = [ '-L %s -lcrypto -lssl' % (ossl_base,) ]
# extra_link_args = ['-L %s -lcrypto -lssl' % (ossl_base,)]
# 'normal' link
libraries = ['crypto', 'ssl'],
include_dirs = [ O('include') ],
cython_compile_time_env = {'NPN' : USE_NPN},
)
#--------------------------------------------------------------------------------
libraries=['crypto', 'ssl'],
include_dirs=[O('include')],
cython_compile_time_env={'NPN': USE_NPN},
)
# --------------------------------------------------------------------------
setup (
name='coro',
......@@ -117,23 +116,23 @@ setup (
description='IronPort Coroutine/Threading Library',
author='Sam Rushing, Eric Huss, IronPort Engineering',
author_email='sam-coro@rushing.nightmare.com',
license = "MIT",
url = "http://github.com/ironport/shrapnel",
ext_modules = [
license="MIT",
url="http://github.com/ironport/shrapnel",
ext_modules=[
Extension(
'coro.event_queue',
['coro/event_queue.pyx'],
language='c++',
depends=[os.path.join(include_dir, 'pyrex', 'python.pxi'),],
depends=[os.path.join(include_dir, 'pyrex', 'python.pxi'), ],
pyrex_include_dirs=[
os.path.join(include_dir, '.'),
os.path.join(include_dir, 'pyrex'),
],),
],),
Extension (
'coro._coro',
['coro/_coro.pyx', 'coro/swap.c'],
extra_compile_args = ['-Wno-unused-function'],
depends = (
extra_compile_args=['-Wno-unused-function'],
depends=(
glob.glob('coro/*.pyx') +
glob.glob('coro/*.pxi') +
glob.glob('coro/*.pxd') + [
......@@ -143,31 +142,32 @@ setup (
os.path.join(include_dir, 'pyrex', 'tsc_time_include.pyx'),
os.path.join(include_dir, 'include', 'tsc_time.h'),
os.path.join(include_dir, 'pyrex', 'libc.pxd'),
]
),
]
),
pyrex_include_dirs=[
os.path.join(include_dir, '.'),
os.path.join(include_dir, 'pyrex'),
],
],
include_dirs=[
os.path.join(include_dir, '.'),
os.path.join(include_dir, 'include'),
],
pyrex_compile_time_env = compile_time_env,
],
pyrex_compile_time_env=compile_time_env,
# to enable LZO|LZ4 for stack compression, set COMPILE_LZO|COMPILE_LZ4 above
# and uncomment one of the following:
#libraries=['lzo2', 'z']
#libraries=['lz4', 'z'],
# libraries=['lzo2', 'z']
# libraries=['lz4', 'z'],
libraries=['z'] + (['aio'] if USE_LINUX_AIO else [])
),
Extension ('coro.oserrors', ['coro/oserrors.pyx', ],),
Extension ('coro.dns.packet', ['coro/dns/packet.pyx', ],),
Extension ('coro.dns.surf', ['coro/dns/surf.pyx',],),
),
Extension ('coro.oserrors', ['coro/oserrors.pyx', ], ),
Extension ('coro.dns.packet', ['coro/dns/packet.pyx', ], ),
Extension ('coro.dns.surf', ['coro/dns/surf.pyx', ], ),
Extension ('coro.lru', ['coro/lru.pyx'], ),
Extension ('coro.asn1.ber', ['coro/asn1/ber.pyx'],),
Extension ('coro.db.postgres.proto', ['coro/db/postgres/proto.pyx'],),
Extension ('coro.asn1.ber', ['coro/asn1/ber.pyx'], ),
Extension ('coro.db.postgres.proto', ['coro/db/postgres/proto.pyx'], ),
Extension ('coro.ldap.query', ['coro/ldap/query.pyx'],),
Extension ('coro.http.zspdy', ['coro/http/zspdy.pyx'], include_dirs=['coro'], libraries=['z'], depends=['coro/zlib.pxd']),
Extension ('coro.http.zspdy', ['coro/http/zspdy.pyx'],
include_dirs=['coro'], libraries=['z'], depends=['coro/zlib.pxd']),
Extension (
'coro.clocks.tsc_time',
['coro/clocks/tsc_time.pyx', ],
......@@ -175,13 +175,13 @@ setup (
include_dirs=[
os.path.join(include_dir, '.'),
os.path.join(include_dir, 'include'),
],
),
],
),
# the pre-computed openssl extension from above
OpenSSL_Extension,
],
],
packages= find_packages(),
py_modules = ['backdoor', 'coro.read_stream', 'coro_process', 'coro_unittest',],
py_modules = ['backdoor', 'coro.read_stream', 'coro_process', 'coro_unittest', ],
download_url = 'http://github.com/ironport/shrapnel/tarball/master#egg=coro-1.0.2',
install_requires = ['cython>=0.12.1', 'distribute>=0.6.16', 'pycrypto'],
cmdclass={'build_ext': build_ext},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment