"""
URI template handling:
Sample code for how to take a URI Template and turn it into the webhook call to send the activity consumer the activity stream location.
"""from template_parser import Parser, URITemplate
import urllib2
import md5
defget_hook_uri(uri_template,params):"""returns a string with the uri params filled in. Will escape feed_uri"""
t =URITemplate(uri_template)if (params['feed_uri']):
params['feed_uri']=urllib2.quote(params['feed_uri'])returnt.sub(params)
template_str ='http://localhost:8001/hooks/add_activity?userid=1234&feed_uri={feed_uri}&format={feed_format}&token={token}'
es='http://localhost:8002/activity?user_id=activity_user'printget_hook_uri(template_str, {'feed_uri':es,'feed_format':'atom','token':md5.new('magic').hexdigest()})