mirror of
https://github.com/valitydev/salt.git
synced 2024-11-09 01:36:48 +00:00
Add namespaced_function function
This will allow for imported functions to live under the new global namespace. Copied directly from saltcloud.utils
This commit is contained in:
parent
70a8ce42d3
commit
54201c9fa9
@ -1119,3 +1119,20 @@ def get_hash(path, form='md5', chunk_size=4096):
|
||||
if not chunk:
|
||||
return hash_obj.hexdigest()
|
||||
hash_obj.update(chunk)
|
||||
|
||||
|
||||
def namespaced_function(function, global_dict, defaults=None):
|
||||
'''
|
||||
Redefine(clone) a function under a different globals() namespace scope
|
||||
'''
|
||||
if defaults is None:
|
||||
defaults = function.__defaults__
|
||||
|
||||
new_namespaced_function = types.FunctionType(
|
||||
function.__code__,
|
||||
global_dict,
|
||||
name=function.__name__,
|
||||
argdefs=defaults
|
||||
)
|
||||
new_namespaced_function.__dict__.update(function.__dict__)
|
||||
return new_namespaced_function
|
||||
|
Loading…
Reference in New Issue
Block a user