def construct_streamreader_callback(process, handler):
 implied_arg = 0
 partial_args = 0
 handler_to_inspect = handler
 if isinstance(handler, partial):
  partial_args = len(handler.args)
  handler_to_inspect = handler.func
 if inspect.ismethod(handler_to_inspect):
  implied_arg = 1
  num_args = get_num_args(handler_to_inspect)
 elif inspect.isfunction(handler_to_inspect):
  num_args = get_num_args(handler_to_inspect)
 else:
  implied_arg = 1
  num_args = get_num_args(handler_to_inspect.__call__)
 net_args = ((num_args - implied_arg) - partial_args)
 handler_args = ()
 if (net_args == 1):
  handler_args = ()
 if (net_args == 2):
  handler_args = (process.stdin,)
 elif (net_args == 3):
  handler_args = (process.stdin, weakref.ref(process))
 def fn(chunk):
  args = handler_args
  if (len(args) == 2):
   args = (handler_args[0], handler_args[1]())
  return handler(chunk, *args)
 return fn

def construct_streamreader_callback ( process , handler ) : implied_arg = 0 partial_args = 0 handler_to_inspect = handler if isinstance ( handler , partial ) : partial_args = len ( handler . args ) handler_to_inspect = handler . func if inspect . ismethod ( handler_to_inspect ) : implied_arg = 1 num_args = get_num_args ( handler_to_inspect ) elif inspect . isfunction ( handler_to_inspect ) : num_args = get_num_args ( handler_to_inspect ) else : implied_arg = 1 num_args = get_num_args ( handler_to_inspect . __call__ ) net_args = ( ( num_args - implied_arg ) - partial_args ) handler_args = ( ) if ( net_args == 1 ) : handler_args = ( ) if ( net_args == 2 ) : handler_args = ( process . stdin , ) elif ( net_args == 3 ) : handler_args = ( process . stdin , weakref . ref ( process ) ) def fn ( chunk ) : args = handler_args if ( len ( args ) == 2 ) : args = ( handler_args [ 0 ] , handler_args [ 1 ] ( ) ) return handler ( chunk , * args ) return fn
here were constructing a closure for our streamreader callback .