1818import ipaddress
1919from typing import Callable , Tuple , Union , Optional , Dict , Any , Sequence , Set
2020from . import config , core , errors , serializers , socketutil , protocol , client
21-
21+ from . callcontext import current_context
2222
2323__all__ = ["Daemon" , "DaemonObject" , "callback" , "expose" , "behavior" , "oneway" , "serve" ]
2424
@@ -175,7 +175,7 @@ def get_next_stream_item(self, streamId):
175175 client , timestamp , linger_timestamp , stream = self .daemon .streaming_responses [streamId ]
176176 if client is None :
177177 # reset client connection association (can be None if proxy disconnected)
178- self .daemon .streaming_responses [streamId ] = (core . current_context .client , timestamp , 0 , stream )
178+ self .daemon .streaming_responses [streamId ] = (current_context .client , timestamp , 0 , stream )
179179 try :
180180 return next (stream )
181181 except Exception :
@@ -331,9 +331,9 @@ def _handshake(self, conn, denied_reason=None):
331331 if config .LOGWIRE :
332332 protocol .log_wiredata (log , "daemon handshake received" , msg )
333333 if msg .flags & protocol .FLAGS_CORR_ID :
334- core . current_context .correlation_id = uuid .UUID (bytes = msg .corr_id )
334+ current_context .correlation_id = uuid .UUID (bytes = msg .corr_id )
335335 else :
336- core . current_context .correlation_id = uuid .uuid4 ()
336+ current_context .correlation_id = uuid .uuid4 ()
337337 serializer_id = msg .serializer_id
338338 serializer = serializers .serializers_by_id [serializer_id ]
339339 data = serializer .loads (msg .data )
@@ -397,9 +397,9 @@ def handleRequest(self, conn):
397397 request_seq = msg .seq
398398 request_serializer_id = msg .serializer_id
399399 if msg .flags & protocol .FLAGS_CORR_ID :
400- core . current_context .correlation_id = uuid .UUID (bytes = msg .corr_id )
400+ current_context .correlation_id = uuid .UUID (bytes = msg .corr_id )
401401 else :
402- core . current_context .correlation_id = uuid .uuid4 ()
402+ current_context .correlation_id = uuid .uuid4 ()
403403 if config .LOGWIRE :
404404 protocol .log_wiredata (log , "daemon wiredata received" , msg )
405405 if msg .type == protocol .MSG_PING :
@@ -416,16 +416,16 @@ def handleRequest(self, conn):
416416 else :
417417 # normal deserialization of remote call arguments
418418 objId , method , vargs , kwargs = serializer .loadsCall (msg .data )
419- core . current_context .client = conn
419+ current_context .client = conn
420420 try :
421421 # store, because on oneway calls, socket will be disconnected:
422- core . current_context .client_sock_addr = conn .sock .getpeername ()
422+ current_context .client_sock_addr = conn .sock .getpeername ()
423423 except socket .error :
424- core . current_context .client_sock_addr = None # sometimes getpeername() doesn't work...
425- core . current_context .seq = msg .seq
426- core . current_context .annotations = msg .annotations
427- core . current_context .msg_flags = msg .flags
428- core . current_context .serializer_id = msg .serializer_id
424+ current_context .client_sock_addr = None # sometimes getpeername() doesn't work...
425+ current_context .seq = msg .seq
426+ current_context .annotations = msg .annotations
427+ current_context .msg_flags = msg .flags
428+ current_context .serializer_id = msg .serializer_id
429429 del msg # invite GC to collect the object, don't wait for out-of-scope
430430 obj = self .objectsById .get (objId )
431431 if obj is not None :
@@ -489,7 +489,7 @@ def handleRequest(self, conn):
489489 response_flags |= protocol .FLAGS_BATCH
490490 msg = protocol .SendingMessage (protocol .MSG_RESULT , response_flags , request_seq , serializer .serializer_id , data ,
491491 annotations = self .__annotations ())
492- core . current_context .response_annotations = {}
492+ current_context .response_annotations = {}
493493 if config .LOGWIRE :
494494 protocol .log_wiredata (log , "daemon wiredata sending" , msg )
495495 conn .send (msg .data )
@@ -753,7 +753,7 @@ def combine(self, daemon):
753753 self .transportServer .combine_loop (daemon .transportServer )
754754
755755 def __annotations (self ):
756- annotations = core . current_context .response_annotations
756+ annotations = current_context .response_annotations
757757 annotations .update (self .annotations ())
758758 return annotations
759759
@@ -965,15 +965,15 @@ class _OnewayCallThread(threading.Thread):
965965 def __init__ (self , pyro_method , vargs , kwargs , pyro_daemon , pyro_client_sock ):
966966 super (_OnewayCallThread , self ).__init__ (target = self ._methodcall , name = "oneway-call" )
967967 self .daemon = True
968- self .parent_context = core . current_context .to_global ()
968+ self .parent_context = current_context .to_global ()
969969 self .pyro_daemon = pyro_daemon
970970 self .pyro_client_sock = pyro_client_sock
971971 self .pyro_method = pyro_method
972972 self .pyro_vargs = vargs
973973 self .pyro_kwars = kwargs
974974
975975 def run (self ):
976- core . current_context .from_global (self .parent_context )
976+ current_context .from_global (self .parent_context )
977977 super (_OnewayCallThread , self ).run ()
978978
979979 def _methodcall (self ):
0 commit comments