本文整理汇总了Python中validate_jsonp.is_valid_jsonp_callback_value函数的典型用法代码示例。如果您正苦于以下问题:Python is_valid_jsonp_callback_value函数的具体用法?Python is_valid_jsonp_callback_value怎么用?Python is_valid_jsonp_callback_value使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_valid_jsonp_callback_value函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
def render(self, request):
cb = request.GET.get('callback', None)
seria = simplejson.dumps(self.construct(), cls=DateTimeAwareJSONEncoder, ensure_ascii=False, indent=4)
# Callback
if cb and is_valid_jsonp_callback_value(cb):
return '%s(%s)' % (cb, seria)
return seria
示例2: write
def write(self, outfile, encoding):
request = self.feed['request']
# Check for a callback param, validate it before use
callback = request.GET.get('callback', None)
if callback is not None:
if not validate_jsonp.is_valid_jsonp_callback_value(callback):
callback = None
items_out = []
for item in self.items:
document = item['obj']
# Include some of the simple elements from the preprocessed item
item_out = dict((x, item[x]) for x in (
'link', 'title', 'pubdate', 'author_name', 'author_link',
))
# HACK: DocumentFeed is the superclass of RevisionFeed. In this
# case, current_revision is the revision itself.
# TODO: Refactor this out into separate DocumentFeed and
# RevisionFeed subclasses of Feed.
if hasattr(document, 'current_revision'):
revision = document.current_revision
else:
revision = document
profile = UserProfile.objects.get(user=revision.creator)
if hasattr(profile, 'gravatar'):
item_out['author_avatar'] = profile.gravatar
summary = revision.summary
if summary:
item_out['summary'] = summary
# Linkify the tags used in the feed item
categories = dict(
(x, request.build_absolute_uri(
reverse('wiki.views.list_documents',
kwargs={'tag': x})))
for x in item['categories']
)
if categories:
item_out['categories'] = categories
#TODO: What else might be useful in a JSON feed of documents?
items_out.append(item_out)
data = items_out
if callback:
outfile.write('%s(' % callback)
outfile.write(json.dumps(data, default=self._encode_complex))
if callback:
outfile.write(')')
示例3: write
def write(self, outfile, encoding):
# Check for a callback param, validate it before use
callback = self.feed['request'].GET.get('callback', None)
if callback is not None:
if not validate_jsonp.is_valid_jsonp_callback_value(callback):
callback = None
items_out = []
for item in self.items:
avatar_href = avatar_url(item['obj'].claimed_by, 64)
if avatar_href.startswith('/'):
avatar_href = self.request.build_absolute_uri(avatar_href)
a_object = item['activity']['object']
item_out = {
'postedTime': item['pubdate'],
'verb': item['activity']['verb'],
'actor': {
'objectType': 'http://activitystrea.ms/schema/1.0/person',
'id': get_tag_uri(item['author_link'], item['pubdate']),
'displayName': item['author_name'],
'permalinkUrl': item['author_link'],
'image': {
'url': avatar_href,
'width':'64',
'height':'64',
}
},
'object': {
'objectType': a_object['object-type'],
'id': get_tag_uri(a_object['link'], item['pubdate']),
'displayName': a_object['name'],
'permalinkUrl': a_object['link'],
'image': {
'url': a_object['preview']['href'],
'width': a_object['preview']['width'],
'height': a_object['preview']['height'],
}
},
}
items_out.append(item_out)
data = {
"items": items_out
}
if callback: outfile.write('%s(' % callback)
outfile.write(json.dumps(data, default=self._encode_complex))
if callback: outfile.write(')')
示例4: write
def write(self, outfile, encoding):
request = self.feed['request']
# Check for a callback param, validate it before use
callback = request.GET.get('callback', None)
if callback is not None:
if not validate_jsonp.is_valid_jsonp_callback_value(callback):
callback = None
items_out = []
for item in self.items:
# Include some of the simple elements from the preprocessed feed item
item_out = dict( (x, item[x]) for x in (
'link', 'title', 'pubdate', 'author_name', 'author_link',
))
item_out['author_avatar'] = item['obj'].creator.get_profile().gravatar
# Linkify the tags used in the feed item
item_out['categories'] = dict(
(x, request.build_absolute_uri(reverse('demos_tag', kwargs={'tag':x})))
for x in item['categories']
)
# Include a few more, raw from the submission object itself.
item_out.update( (x, unicode(getattr(item['obj'], x))) for x in (
'summary', 'description',
))
item_out['featured'] = item['obj'].featured
# Include screenshot as an absolute URL.
item_out['screenshot'] = request.build_absolute_uri(
item['obj'].screenshot_url(1))
# HACK: This .replace() should probably be done in the model
item_out['thumbnail'] = request.build_absolute_uri(
item['obj'].thumbnail_url(1))
#TODO: What else might be useful in a JSON feed of demo submissions?
# Comment, like, view counts may change too much for caching to be useful
items_out.append(item_out)
data = items_out
if callback: outfile.write('%s(' % callback)
outfile.write(json.dumps(data, default=self._encode_complex))
if callback: outfile.write(')')