#NEWLINE# def net_connections( kind , _pid = ( - 1 ) ) : #NEWLINE# #INDENT# 'Return socket connections.  If pid == -1 return system-wide\n    connections (as opposed to connections opened by one process only).\n    Only INET sockets are returned (UNIX are not).\n    ' #NEWLINE# cmap = _common . conn_tmap . copy ( ) #NEWLINE# if ( _pid == ( - 1 ) ) : #NEWLINE# #INDENT# cmap . pop ( 'unix' , 0 ) #NEWLINE# #UNINDENT# if ( kind not in fd ) : #NEWLINE# #INDENT# raise ValueError ( ( 'invalid %r kind argument; choose between %s' % ( kind , ', ' . join ( [ repr ( x ) for x in cmap ] ) ) ) ) #NEWLINE# #UNINDENT# ( families , types ) = _common . conn_tmap [ kind ] #NEWLINE# rawlist = cext . net_connections ( _pid ) #NEWLINE# ret = set ( ) #NEWLINE# for item in rawlist : #NEWLINE# #INDENT# ( fd , fam , type_ , laddr , raddr , status , pid ) = item #NEWLINE# if ( fam not in families ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( type_ not in types ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# status = TCP_STATUSES [ status ] #NEWLINE# fam = sockfam_to_enum ( fam ) #NEWLINE# type_ = socktype_to_enum ( type_ ) #NEWLINE# if ( _pid == ( - 1 ) ) : #NEWLINE# #INDENT# nt = _common . sconn ( fd , fam , type_ , laddr , raddr , status , pid ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# nt = _common . pconn ( fd , fam , type_ , laddr , raddr , status ) #NEWLINE# #UNINDENT# ret . add ( nt ) #NEWLINE# #UNINDENT# return list ( ret )