Commit a67ed840 by Piotr Mitros

argspec munging works

parent 9af28bfa
...@@ -8,10 +8,11 @@ a good way to make this clean, but the ugliness here will save a lot ...@@ -8,10 +8,11 @@ a good way to make this clean, but the ugliness here will save a lot
of ugliness for the API caller. of ugliness for the API caller.
''' '''
import decorator
import inspect
import json
import requests import requests
import urllib import urllib
import json
import decorator
schema = None schema = None
...@@ -93,6 +94,7 @@ class embed(): ...@@ -93,6 +94,7 @@ class embed():
raise AttributeError(function) raise AttributeError(function)
category = rpcspec['category'] category = rpcspec['category']
# TODO: Category should be a list, not a string
def_params = category.replace('+',',') # Is this still needed? def_params = category.replace('+',',') # Is this still needed?
if def_params: if def_params:
call_params = ",".join(["{p}={p}".format(p=p) for p in category.split('+')]) call_params = ",".join(["{p}={p}".format(p=p) for p in category.split('+')])
...@@ -128,7 +130,22 @@ class transform_embed: ...@@ -128,7 +130,22 @@ class transform_embed:
for arg in stripped_args: for arg in stripped_args:
args[arg] = context[arg] args[arg] = context[arg]
return function(**args) return function(**args)
## TODO: Update argspec ## TODO: Use common logic with
args = [a for a in inspect.getargspec(function).args if a not in stripped_args]
if args:
def_params = ",".join(args)
call_params = ",".join(["{p}={p}".format(p=p) for p in args])
else:
def_params = ""
call_params = ""
funcspec = "{name}({params})".format(name=function.__name__,
params=def_params)
callspec = "return helper({params})".format(params=call_params)
return decorator.FunctionMaker.create(funcspec,
callspec,
{'helper':new_helper},
doc=function.__doc__)
return new_helper return new_helper
def __getattr__(self, attr): def __getattr__(self, attr):
...@@ -167,21 +184,24 @@ class djobject(): ...@@ -167,21 +184,24 @@ class djobject():
if __name__ == "__main__": if __name__ == "__main__":
djo = djobject(baseurl = "http://127.0.0.1:8000/") djo = djobject(baseurl = "http://127.0.0.1:8000/")
# print djo.query.djt_event_count() if False: # djanalytics
# print djo.query.djt_user_event_count(user = "bob") print djo.query.djt_event_count()
# print djo.query.__dir__() print djo.query.djt_user_event_count(user = "bob")
print djo.query.__dir__()
transform_policy = {'name': 'test',
'default' : 'deny', if True: # edxanalytics
'policy' : { 'total_user_count' : 'allow', transform_policy = {'name': 'test',
'user_count' : 'allow', 'default' : 'deny',
'dash' : 'deny', 'policy' : { 'total_user_count' : 'allow',
'page_count' : ['user'] } 'user_count' : 'allow',
} 'dash' : 'deny',
'page_count' : ['user'] }
context = { 'user' : 'bob', }
'course' : '6.002x' }
context = { 'user' : 'bob',
secure_view = transform_embed(transform_policy, context, djo.view) 'course' : '6.002x' }
print secure_view.__dir__()
print secure_view.page_count(course = '6.002x') secure_view = transform_embed(transform_policy, context, djo.view)
print secure_view.__dir__()
print secure_view.page_count(course = '6.002x')
print inspect.getargspec(secure_view.page_count)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment