本文整理汇总了Python中util.get_required_param函数的典型用法代码示例。如果您正苦于以下问题:Python get_required_param函数的具体用法?Python get_required_param怎么用?Python get_required_param使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_required_param函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: post
def post(self):
key = ndb.Key(urlsafe=util.get_required_param(self, 'key'))
module = self.OAUTH_MODULES[key.kind()]
feature = util.get_required_param(self, 'feature')
state = self.encode_state_parameter({
'operation': 'delete',
'feature': feature,
'source': key.urlsafe(),
'callback': self.request.get('callback'),
})
# Google+ and Blogger don't support redirect_url() yet
if module is oauth_googleplus:
return self.redirect('/googleplus/delete/start?state=%s' % state)
if module is oauth_blogger_v2:
return self.redirect('/blogger/delete/start?state=%s' % state)
path = ('/instagram/callback' if module is indieauth
else '/wordpress/add' if module is oauth_wordpress_rest
else '/%s/delete/finish' % key.get().SHORT_NAME)
kwargs = {}
if module is oauth_twitter:
kwargs['access_type'] = 'read' if feature == 'listen' else 'write'
handler = module.StartHandler.to(path, **kwargs)(self.request, self.response)
self.redirect(handler.redirect_url(state=state))
开发者ID:LennonFlores,项目名称:bridgy,代码行数:27,代码来源:app.py
示例2: get
def get(self):
if self.request.get('declined'):
self.messages.add('If you want to disable, please approve the prompt.')
self.redirect('/')
return
parts = self.decode_state_parameter(util.get_required_param(self, 'state'))
if (not isinstance(parts, dict) or 'feature' not in parts
or 'source' not in parts):
self.abort(400, 'state query parameter must include "feature" and "source"')
feature = parts['feature']
if feature not in (Source.FEATURES):
self.abort(400, 'cannot delete unknown feature %s' % feature)
logged_in_as = util.get_required_param(self, 'auth_entity')
source = ndb.Key(urlsafe=parts['source']).get()
if logged_in_as == source.auth_entity.urlsafe():
# TODO: remove credentials
if feature in source.features:
source.features.remove(feature)
source.put()
noun = 'webmentions' if feature == 'webmention' else feature + 'ing'
self.messages.add('Disabled %s for %s. Sorry to see you go!' %
(noun, source.label()))
# util.email_me(subject='Deleted Bridgy %s user: %s %s' %
# (feature, source.label(), source.key.string_id()),
# body=source.bridgy_url(self))
else:
self.messages.add('Please log into %s as %s to disable it here.' %
(source.AS_CLASS.NAME, source.name))
self.redirect(source.bridgy_url(self))
开发者ID:dev511,项目名称:bridgy,代码行数:33,代码来源:app.py
示例3: get
def get(self):
if self.request.get('declined'):
self.messages.add("OK, you're still signed up.")
self.redirect('/')
return
parts = util.get_required_param(self, 'state').split('-', 1)
feature = parts[0]
if len(parts) != 2 or feature not in (Source.FEATURES):
self.abort(400, 'state query parameter must be [FEATURE]-[SOURCE KEY]')
logged_in_as = util.get_required_param(self, 'auth_entity')
source = ndb.Key(urlsafe=parts[1]).get()
if logged_in_as == source.auth_entity.urlsafe():
# TODO: remove credentials
if feature in source.features:
source.features.remove(feature)
source.put()
noun = 'webmentions' if feature == 'webmention' else feature + 'ing'
self.messages.add('Disabled %s for %s. Sorry to see you go!' %
(noun, source.label()))
# util.email_me(subject='Deleted Bridgy %s user: %s %s' %
# (feature, source.label(), source.key.string_id()),
# body=source.bridgy_url(self))
else:
self.messages.add('Please log into %s as %s to disable it here.' %
(source.AS_CLASS.NAME, source.name))
self.redirect(source.bridgy_url(self))
开发者ID:notenoughneon,项目名称:bridgy,代码行数:29,代码来源:app.py
示例4: test_get_required_param
def test_get_required_param(self):
handler = webapp2.RequestHandler(webapp2.Request.blank('/?a=b'), None)
self.assertEqual('b', util.get_required_param(handler, 'a'))
try:
util.get_required_param(handler, 'c')
self.fail('Expected HTTPException')
except exc.HTTPException, e:
self.assertEqual(400, e.status_int)
开发者ID:snarfed,项目名称:webutil,代码行数:8,代码来源:test_util.py
示例5: post
def post(self):
auth_entity_key = util.get_required_param(self, "auth_entity_key")
self.maybe_add_or_delete_source(
Tumblr,
ndb.Key(urlsafe=auth_entity_key).get(),
util.get_required_param(self, "state"),
blog_name=util.get_required_param(self, "blog"),
)
开发者ID:snarfed,项目名称:bridgy,代码行数:8,代码来源:tumblr.py
示例6: post
def post(self):
auth_entity_key = util.get_required_param(self, 'auth_entity_key')
self.maybe_add_or_delete_source(
Blogger,
ndb.Key(urlsafe=auth_entity_key).get(),
util.get_required_param(self, 'state'),
blog_id=util.get_required_param(self, 'blog'),
)
开发者ID:LennonFlores,项目名称:bridgy,代码行数:8,代码来源:blogger.py
示例7: post
def post(self):
state = util.get_required_param(self, 'state')
id = util.get_required_param(self, 'id')
auth_entity_key = util.get_required_param(self, 'auth_entity_key')
auth_entity = ndb.Key(urlsafe=auth_entity_key).get()
if id != auth_entity.key.id():
auth_entity = auth_entity.for_page(id)
auth_entity.put()
self.maybe_add_or_delete_source(FacebookPage, auth_entity, state)
开发者ID:priscila225,项目名称:bridgy,代码行数:12,代码来源:facebook.py
示例8: get
def get(self):
parts = self.decode_state_parameter(util.get_required_param(self, 'state'))
callback = parts and parts.get('callback')
if self.request.get('declined'):
if callback:
# disable declined means no change took place
callback = util.add_query_params(callback, {'result': 'declined'})
else:
self.messages.add('If you want to disable, please approve the prompt.')
self.redirect(callback.encode('utf-8') if callback else '/')
return
if (not parts or 'feature' not in parts or 'source' not in parts):
self.abort(400, 'state query parameter must include "feature" and "source"')
feature = parts['feature']
if feature not in (Source.FEATURES):
self.abort(400, 'cannot delete unknown feature %s' % feature)
logged_in_as = ndb.Key(
urlsafe=util.get_required_param(self, 'auth_entity')).get()
source = ndb.Key(urlsafe=parts['source']).get()
if logged_in_as and logged_in_as.is_authority_for(source.auth_entity):
# TODO: remove credentials
if feature in source.features:
source.features.remove(feature)
source.put()
noun = 'webmentions' if feature == 'webmention' else feature + 'ing'
if callback:
callback = util.add_query_params(callback, {
'result': 'success',
'user': source.bridgy_url(self),
'key': source.key.urlsafe(),
})
else:
self.messages.add('Disabled %s for %s. Sorry to see you go!' %
(noun, source.label()))
# util.email_me(subject='Deleted Bridgy %s user: %s %s' %
# (feature, source.label(), source.key.string_id()),
# body=source.bridgy_url(self))
else:
if callback:
callback = util.add_query_params(callback, {'result': 'failure'})
else:
self.messages.add('Please log into %s as %s to disable it here.' %
(source.GR_CLASS.NAME, source.name))
self.redirect(callback.encode('utf-8') if callback
else source.bridgy_url(self) if source.features
else '/')
开发者ID:Maymanaf,项目名称:bridgy,代码行数:52,代码来源:app.py
示例9: post
def post(self):
features = self.request.get('feature')
features = features.split(',') if features else []
callback = util.get_required_param(self, 'callback')
ia_start = util.oauth_starter(indieauth.StartHandler).to('/instagram/callback')(
self.request, self.response)
try:
self.redirect(ia_start.redirect_url(me=util.get_required_param(self, 'user_url')))
except Exception as e:
if util.is_connection_failure(e) or util.interpret_http_exception(e)[0]:
self.messages.add("Couldn't fetch your web site: %s" % e)
return self.redirect('/')
raise
开发者ID:mblaney,项目名称:bridgy,代码行数:15,代码来源:instagram.py
示例10: post
def post(self):
logging.debug('Params: %s', self.request.params)
type = self.request.get('type')
if type:
assert type in ('event',)
key = util.get_required_param(self, 'source_key')
source = ndb.Key(urlsafe=key).get()
if not source or source.status == 'disabled' or 'listen' not in source.features:
logging.error('Source not found or disabled. Dropping task.')
return
logging.info('Source: %s %s, %s', source.label(), source.key.string_id(),
source.bridgy_url(self))
post_id = util.get_required_param(self, 'post_id')
source.updates = {}
try:
if type == 'event':
activities = [source.gr_source.get_event(post_id)]
else:
activities = source.get_activities(
fetch_replies=True, fetch_likes=True, fetch_shares=True,
activity_id=post_id, user_id=source.key.id())
if not activities or not activities[0]:
logging.info('Post %s not found.', post_id)
return
assert len(activities) == 1, activities
self.backfeed(source, activities={activities[0]['id']: activities[0]})
in_reply_to = util.get_first(activities[0]['object'], 'inReplyTo')
if in_reply_to:
parsed = util.parse_tag_uri(in_reply_to.get('id', '')) # TODO: fall back to url
if parsed:
util.add_discover_task(source, parsed[1])
except Exception, e:
code, body = util.interpret_http_exception(e)
if (code and (code in util.HTTP_RATE_LIMIT_CODES or
code in ('400', '404') or
int(code) / 100 == 5)
or util.is_connection_failure(e)):
logging.error('API call failed; giving up. %s: %s\n%s', code, body, e)
self.abort(util.ERROR_HTTP_RETURN_CODE)
else:
raise
开发者ID:mblaney,项目名称:bridgy,代码行数:48,代码来源:tasks.py
示例11: post
def post(self):
source = self.load_source()
# validate URL, find silo post
url = util.get_required_param(self, 'url')
domain = util.domain_from_link(url)
path = urlparse.urlparse(url).path
msg = 'Discovering now. Refresh in a minute to see the results!'
if domain == source.GR_CLASS.DOMAIN:
post_id = source.GR_CLASS.post_id(url)
if post_id:
type = 'event' if path.startswith('/events/') else None
util.add_discover_task(source, post_id, type=type)
else:
msg = "Sorry, that doesn't look like a %s post URL." % source.GR_CLASS.NAME
elif util.domain_or_parent_in(domain, source.domains):
synd_links = original_post_discovery.process_entry(source, url, {}, False, [])
if synd_links:
for link in synd_links:
util.add_discover_task(source, source.GR_CLASS.post_id(link))
source.updates = {'last_syndication_url': util.now_fn()}
models.Source.put_updates(source)
else:
msg = 'Failed to fetch %s or find a %s syndication link.' % (
util.pretty_link(url), source.GR_CLASS.NAME)
else:
msg = 'Please enter a URL on either your web site or %s.' % source.GR_CLASS.NAME
self.messages.add(msg)
self.redirect(source.bridgy_url(self))
开发者ID:snarfed,项目名称:bridgy,代码行数:33,代码来源:app.py
示例12: get_source
def get_source(self):
if self.source:
return self.source
self.source = ndb.Key(urlsafe=util.get_required_param(self, 'key')).get()
if not self.source:
self.abort(400, 'source not found')
开发者ID:LennonFlores,项目名称:bridgy,代码行数:7,代码来源:app.py
示例13: finish_oauth_flow
def finish_oauth_flow(self, auth_entity, state):
"""Adds or deletes a FacebookPage, or restarts OAuth to get publish permissions.
Args:
auth_entity: FacebookAuth
state: encoded state string
"""
if auth_entity is None:
auth_entity_key = util.get_required_param(self, "auth_entity_key")
auth_entity = ndb.Key(urlsafe=auth_entity_key).get()
if state is None:
state = self.request.get("state")
state_obj = self.decode_state_parameter(state)
id = state_obj.get("id") or self.request.get("id")
if id and id != auth_entity.key.id():
auth_entity = auth_entity.for_page(id)
auth_entity.put()
source = self.maybe_add_or_delete_source(FacebookPage, auth_entity, state)
# If we were already signed up for publish, we had an access token with publish
# permissions. If we then go through the listen signup flow, we'll get a token
# with just the listen permissions. In that case, do the whole OAuth flow again
# to get a token with publish permissions again.
feature = state_obj.get("feature")
if source is not None and feature == "listen" and "publish" in source.features:
logging.info("Restarting OAuth flow to get publish permissions.")
source.features.remove("publish")
source.put()
start = util.oauth_starter(oauth_facebook.StartHandler, feature="publish", id=id)
restart = start.to("/facebook/oauth_handler", scopes=PUBLISH_SCOPES)
restart(self.request, self.response).post()
开发者ID:kylewm,项目名称:bridgy,代码行数:34,代码来源:facebook.py
示例14: post
def post(self):
key = ndb.Key(urlsafe=util.get_required_param(self, 'key'))
module = self.OAUTH_MODULES[key.kind()]
state = '%s-%s' % (util.get_required_param(self, 'feature'), key.urlsafe())
# Google+ and Blogger don't support redirect_url() yet
if module is oauth_googleplus:
self.redirect('/googleplus/delete/start?state=%s' % state)
elif module is oauth_blogger_v2:
self.redirect('/blogger/delete/start?state=%s' % state)
else:
path = ('/instagram/oauth_callback' if module is oauth_instagram
else '/wordpress/add' if module is oauth_wordpress_rest
else '/%s/delete/finish' % key.get().SHORT_NAME)
handler = module.StartHandler.to(path)(self.request, self.response)
self.redirect(handler.redirect_url(state=state))
开发者ID:notenoughneon,项目名称:bridgy,代码行数:16,代码来源:app.py
示例15: post
def post(self):
source = ndb.Key(urlsafe=util.get_required_param(self, 'key')).get()
if not source:
self.abort(400, 'source not found')
util.add_poll_task(source, now=True)
self.messages.add("Polling now. Refresh in a minute to see what's new!")
self.redirect(source.bridgy_url(self))
开发者ID:uniteddiversity,项目名称:bridgy,代码行数:8,代码来源:app.py
示例16: authorize
def authorize(self):
from_source = ndb.Key(urlsafe=util.get_required_param(self, 'source_key'))
if from_source != self.source.key:
self.error('Try publishing that page from <a href="%s">%s</a> instead.' %
(self.source.bridgy_path(), self.source.label()))
return False
return True
开发者ID:lcorbasson,项目名称:bridgy,代码行数:8,代码来源:publish.py
示例17: post
def post(self):
# pass explicit 'write' instead of None for publish so that oauth-dropins
# (and tweepy) don't use signin_with_twitter ie /authorize. this works
# around a twitter API bug: https://dev.twitter.com/discussions/21281
access_type = ('read' if util.get_required_param(self, 'feature')
== 'listen' else 'write')
handler = util.oauth_starter(oauth_twitter.StartHandler).to(
'/twitter/add', access_type=access_type)(self.request, self.response)
return handler.post()
开发者ID:sanduhrs,项目名称:bridgy,代码行数:9,代码来源:twitter.py
示例18: get
def get(self):
auth_entity_str_key = util.get_required_param(self, 'auth_entity')
state = self.request.get('state')
if not state:
# state doesn't currently come through for G+. not sure why. doesn't
# matter for now since we don't plan to implement publish for G+.
state = self.construct_state_param_for_add(feature='listen')
auth_entity = ndb.Key(urlsafe=auth_entity_str_key).get()
self.maybe_add_or_delete_source(GooglePlusPage, auth_entity, state)
开发者ID:paulscallanjr,项目名称:bridgy,代码行数:9,代码来源:googleplus.py
示例19: post
def post(self):
entity = ndb.Key(urlsafe=util.get_required_param(self, 'key')).get()
if not entity:
self.abort(400, 'key not found')
elif not isinstance(entity, Webmentions):
self.abort(400, 'Unexpected key kind %s', entity.key.kind())
# run OPD to pick up any new SyndicatedPosts. note that we don't refetch
# their h-feed, so if they've added a syndication URL since we last crawled,
# retry won't make us pick it up. background in #524.
if entity.key.kind() == 'Response':
source = entity.source.get()
for activity in [json.loads(a) for a in entity.activities_json]:
originals, mentions = original_post_discovery.discover(
source, activity, fetch_hfeed=False, include_redirect_sources=False)
entity.unsent += original_post_discovery.targets_for_response(
json.loads(entity.response_json), originals=originals, mentions=mentions)
entity.restart()
self.messages.add('Retrying. Refresh in a minute to see the results!')
self.redirect(self.request.get('redirect_to').encode('utf-8') or
entity.source.get().bridgy_url(self))
开发者ID:mblaney,项目名称:bridgy,代码行数:22,代码来源:app.py
示例20: source_url
def source_url(self):
return util.get_required_param(self, 'source')
开发者ID:lcorbasson,项目名称:bridgy,代码行数:2,代码来源:publish.py
注:本文中的util.get_required_param函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论