Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for name in dir(val):
if name == "args":
for a in val.args:
if brine.dumpable(a):
args.append(a)
else:
args.append(repr(a))
elif name.startswith("_") or name in ignored_attrs:
continue
else:
try:
attrval = getattr(val, name)
except AttributeError:
# skip this attr. see issue #108
continue
if not brine.dumpable(attrval):
attrval = repr(attrval)
attrs.append((name, attrval))
return (typ.__module__, typ.__name__), tuple(args), tuple(attrs), tbtext
def _box(self, obj):
"""store a local object in such a way that it could be recreated on
the remote party either by-value or by-reference"""
if brine.dumpable(obj):
return consts.LABEL_VALUE, obj
if type(obj) is tuple:
return consts.LABEL_TUPLE, tuple(self._box(item) for item in obj)
elif isinstance(obj, netref.BaseNetref) and obj.____conn__() is self:
return consts.LABEL_LOCAL_REF, obj.____oid__
else:
self._local_objects.add(obj)
cls = getattr(obj, "__class__", type(obj))
return consts.LABEL_REMOTE_REF, (id(obj), cls.__name__, cls.__module__)
def _box(self, obj):
"""store a local object in such a way that it could be recreated on
the remote party either by-value or by-reference"""
if brine.dumpable(obj):
return consts.LABEL_VALUE, obj
if type(obj) is tuple:
return consts.LABEL_TUPLE, tuple(self._box(item) for item in obj)
elif isinstance(obj, netref.BaseNetref) and obj.____conn__() is self:
return consts.LABEL_LOCAL_REF, obj.____oid__
else:
self._local_objects.add(obj)
try:
cls = obj.__class__
except Exception:
# see issue #16
cls = type(obj)
if not isinstance(cls, type):
cls = type(obj)
return consts.LABEL_REMOTE_REF, (id(obj), cls.__name__, cls.__module__)
if is_py38x:
# Constructor was changed in 3.8 to support "advanced" programming styles
exported = (cobj.co_argcount, cobj.co_posonlyargcount, cobj.co_kwonlyargcount, cobj.co_nlocals,
cobj.co_stacksize, cobj.co_flags, cobj.co_code, tuple(consts2), cobj.co_names, cobj.co_varnames,
cobj.co_filename, cobj.co_name, cobj.co_firstlineno, cobj.co_lnotab, cobj.co_freevars,
cobj.co_cellvars)
elif is_py3k:
exported = (cobj.co_argcount, cobj.co_kwonlyargcount, cobj.co_nlocals, cobj.co_stacksize, cobj.co_flags,
cobj.co_code, tuple(consts2), cobj.co_names, cobj.co_varnames, cobj.co_filename,
cobj.co_name, cobj.co_firstlineno, cobj.co_lnotab, cobj.co_freevars, cobj.co_cellvars)
else:
exported = (cobj.co_argcount, cobj.co_nlocals, cobj.co_stacksize, cobj.co_flags,
cobj.co_code, tuple(consts2), cobj.co_names, cobj.co_varnames, cobj.co_filename,
cobj.co_name, cobj.co_firstlineno, cobj.co_lnotab, cobj.co_freevars, cobj.co_cellvars)
assert brine.dumpable(exported)
return (CODEOBJ_MAGIC, exported)
def export_function(func):
if is_py3k:
func_closure = func.__closure__
func_code = func.__code__
func_defaults = func.__defaults__
else:
func_closure = func.func_closure
func_code = func.func_code
func_defaults = func.func_defaults
if func_closure:
raise TypeError("Cannot export a function closure")
if not brine.dumpable(func_defaults):
raise TypeError("Cannot export a function with non-brinable defaults (func_defaults)")
return func.__name__, func.__module__, func_defaults, _export_codeobj(func_code)[1]
def _export_codeobj(cobj):
consts2 = []
for const in cobj.co_consts:
if brine.dumpable(const):
consts2.append(const)
elif isinstance(const, CodeType):
consts2.append(_export_codeobj(const))
else:
raise TypeError("Cannot export a function with non-brinable constants: %r" % (const,))
for op, arg in decode_codeobj(cobj):
if op in ("LOAD_GLOBAL", "STORE_GLOBAL", "DELETE_GLOBAL"):
if arg not in __builtin__.__dict__:
raise TypeError("Cannot export a function with non-builtin globals: %r" % (arg,))
if is_py3k:
exported = (cobj.co_argcount, cobj.co_kwonlyargcount, cobj.co_nlocals, cobj.co_stacksize, cobj.co_flags,
cobj.co_code, tuple(consts2), cobj.co_names, cobj.co_varnames, cobj.co_filename,
cobj.co_name, cobj.co_firstlineno, cobj.co_lnotab, cobj.co_freevars, cobj.co_cellvars)
else:
def _box(self, obj):
"""store a local object in such a way that it could be recreated on
the remote party either by-value or by-reference"""
if brine.dumpable(obj):
return consts.LABEL_VALUE, obj
if type(obj) is tuple:
return consts.LABEL_TUPLE, tuple(self._box(item) for item in obj)
elif isinstance(obj, netref.BaseNetref) and obj.____conn__() is self:
return consts.LABEL_LOCAL_REF, obj.____oid__
else:
self._local_objects.add(obj)
try:
cls = obj.__class__
except Exception:
# see issue #16
cls = type(obj)
if not isinstance(cls, type):
cls = type(obj)
return consts.LABEL_REMOTE_REF, (id(obj), cls.__name__, cls.__module__)
for name in dir(val):
if name == "args":
for a in val.args:
if brine.dumpable(a):
args.append(a)
else:
args.append(repr(a))
elif name.startswith("_") or name in ignored_attrs:
continue
else:
try:
attrval = getattr(val, name)
except AttributeError:
# skip this attr. see issue #108
continue
if not brine.dumpable(attrval):
attrval = repr(attrval)
attrs.append((name, attrval))
if include_local_version:
attrs.append(("_remote_version", version.version_string))
else:
attrs.append(("_remote_version", ""))
return (typ.__module__, typ.__name__), tuple(args), tuple(attrs), tbtext