|
|
@ -102,21 +102,6 @@ try:
|
|
|
|
except ImportError:
|
|
|
|
except ImportError:
|
|
|
|
cProfile = None
|
|
|
|
cProfile = None
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
import thread
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
|
|
import threading as thread
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
import cPickle as pickle
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
|
|
import pickle
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
from cStringIO import StringIO as BytesIO
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
|
|
from io import BytesIO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
BaseException
|
|
|
|
BaseException
|
|
|
|
except NameError:
|
|
|
|
except NameError:
|
|
|
@ -169,31 +154,35 @@ STUB_CALL_SERVICE = 111
|
|
|
|
#: :meth:`mitogen.core.Router.add_handler` callbacks to clean up.
|
|
|
|
#: :meth:`mitogen.core.Router.add_handler` callbacks to clean up.
|
|
|
|
IS_DEAD = 999
|
|
|
|
IS_DEAD = 999
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
BaseException
|
|
|
|
|
|
|
|
except NameError:
|
|
|
|
|
|
|
|
BaseException = Exception
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PY24 = sys.version_info < (2, 5)
|
|
|
|
PY24 = sys.version_info < (2, 5)
|
|
|
|
PY3 = sys.version_info > (3,)
|
|
|
|
PY3 = sys.version_info > (3,)
|
|
|
|
if PY3:
|
|
|
|
if PY3:
|
|
|
|
|
|
|
|
import pickle
|
|
|
|
|
|
|
|
import _thread as thread
|
|
|
|
|
|
|
|
from io import BytesIO
|
|
|
|
b = str.encode
|
|
|
|
b = str.encode
|
|
|
|
BytesType = bytes
|
|
|
|
BytesType = bytes
|
|
|
|
UnicodeType = str
|
|
|
|
UnicodeType = str
|
|
|
|
FsPathTypes = (str,)
|
|
|
|
FsPathTypes = (str,)
|
|
|
|
BufferType = lambda buf, start: memoryview(buf)[start:]
|
|
|
|
BufferType = lambda buf, start: memoryview(buf)[start:]
|
|
|
|
long = int
|
|
|
|
integer_types = (int,)
|
|
|
|
|
|
|
|
iteritems, iterkeys, itervalues = dict.items, dict.keys, dict.values
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|
|
|
|
import cPickle as pickle
|
|
|
|
|
|
|
|
import thread
|
|
|
|
|
|
|
|
from cStringIO import StringIO as BytesIO
|
|
|
|
b = str
|
|
|
|
b = str
|
|
|
|
BytesType = str
|
|
|
|
BytesType = str
|
|
|
|
FsPathTypes = (str, unicode)
|
|
|
|
FsPathTypes = (str, unicode)
|
|
|
|
BufferType = buffer
|
|
|
|
BufferType = buffer
|
|
|
|
UnicodeType = unicode
|
|
|
|
UnicodeType = unicode
|
|
|
|
|
|
|
|
integer_types = (int, long)
|
|
|
|
|
|
|
|
iteritems, iterkeys, itervalues = dict.iteritems, dict.iterkeys, dict.itervalues
|
|
|
|
|
|
|
|
|
|
|
|
AnyTextType = (BytesType, UnicodeType)
|
|
|
|
AnyTextType = (BytesType, UnicodeType)
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
next
|
|
|
|
next = next
|
|
|
|
except NameError:
|
|
|
|
except NameError:
|
|
|
|
next = lambda it: it.next()
|
|
|
|
next = lambda it: it.next()
|
|
|
|
|
|
|
|
|
|
|
@ -400,12 +389,19 @@ now = getattr(time, 'monotonic', time.time)
|
|
|
|
|
|
|
|
|
|
|
|
# Python 2.4
|
|
|
|
# Python 2.4
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
any
|
|
|
|
all, any = all, any
|
|
|
|
except NameError:
|
|
|
|
except NameError:
|
|
|
|
|
|
|
|
def all(it):
|
|
|
|
|
|
|
|
for elem in it:
|
|
|
|
|
|
|
|
if not elem:
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def any(it):
|
|
|
|
def any(it):
|
|
|
|
for elem in it:
|
|
|
|
for elem in it:
|
|
|
|
if elem:
|
|
|
|
if elem:
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _partition(s, sep, find):
|
|
|
|
def _partition(s, sep, find):
|
|
|
@ -1065,8 +1061,8 @@ class Sender(object):
|
|
|
|
|
|
|
|
|
|
|
|
def _unpickle_sender(router, context_id, dst_handle):
|
|
|
|
def _unpickle_sender(router, context_id, dst_handle):
|
|
|
|
if not (isinstance(router, Router) and
|
|
|
|
if not (isinstance(router, Router) and
|
|
|
|
isinstance(context_id, (int, long)) and context_id >= 0 and
|
|
|
|
isinstance(context_id, integer_types) and context_id >= 0 and
|
|
|
|
isinstance(dst_handle, (int, long)) and dst_handle > 0):
|
|
|
|
isinstance(dst_handle, integer_types) and dst_handle > 0):
|
|
|
|
raise TypeError('cannot unpickle Sender: bad input or missing router')
|
|
|
|
raise TypeError('cannot unpickle Sender: bad input or missing router')
|
|
|
|
return Sender(Context(router, context_id), dst_handle)
|
|
|
|
return Sender(Context(router, context_id), dst_handle)
|
|
|
|
|
|
|
|
|
|
|
@ -2508,7 +2504,7 @@ class Context(object):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _unpickle_context(context_id, name, router=None):
|
|
|
|
def _unpickle_context(context_id, name, router=None):
|
|
|
|
if not (isinstance(context_id, (int, long)) and context_id >= 0 and (
|
|
|
|
if not (isinstance(context_id, integer_types) and context_id >= 0 and (
|
|
|
|
(name is None) or
|
|
|
|
(name is None) or
|
|
|
|
(isinstance(name, UnicodeType) and len(name) < 100))
|
|
|
|
(isinstance(name, UnicodeType) and len(name) < 100))
|
|
|
|
):
|
|
|
|
):
|
|
|
|