本文整理汇总了Python中blogger.Blogger类的典型用法代码示例。如果您正苦于以下问题:Python Blogger类的具体用法?Python Blogger怎么用?Python Blogger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Blogger类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createPublisher
def createPublisher(domain, service, node, username, password, blog, author=None, debug=False):
factory = client.DeferredClientFactory(jid.internJID(username), password)
factory.streamManager.logTraffic = debug
blogger = Blogger(jid.internJID(service), node)
blogger.blog = blog
if author is not None:
blogger.author_name = author
blogger.setHandlerParent(factory.streamManager)
yield client.clientCreator(factory)
示例2: test_new
def test_new(self):
b = Blogger.new(self.handler, auth_entity=self.auth_entity)
self.assertEquals(self.auth_entity.key, b.auth_entity)
self.assertEquals('name', b.name)
self.assertEquals(['http://my.blawg/'], b.domain_urls)
self.assertEquals(['my.blawg'], b.domains)
self.assertEquals('http://pic', b.picture)
示例3: test_create_comment
def test_create_comment(self):
self.expect_get_posts()
self.client.add_comment('111', '222', '<a href="http://who">who</a>: foo bar'
).AndReturn(self.comment)
self.mox.ReplayAll()
b = Blogger.new(self.handler, auth_entity=self.auth_entity)
resp = b.create_comment('http://blawg/path/to/post', 'who', 'http://who',
'foo bar', client=self.client)
self.assert_equals({'id': '333', 'response': '<foo></foo>'}, resp)
示例4: test_new_oauth_dropins_error
def test_new_oauth_dropins_error(self):
"""Blogger is special cased in oauth-dropins: when login succeeds but then
an authenticated API call fails, it returns an empty auth entity key, which
we can differentiate from a user decline because oauth-dropins can't
currently intercept Blogger declines.
"""
resp = blogger.application.get_response('/blogger/oauth_handler')
self.assertIn("Couldn't fetch your blogs",
urllib.unquote(urlparse.urlparse(resp.headers['Location']).fragment))
self.assertEquals(0, BloggerV2Auth.query().count())
self.assertEquals(0, Blogger.query().count())
示例5: test_create_too_long_comment
def test_create_too_long_comment(self):
"""Blogger caps totally HTML comment length at 4096 chars."""
self.expect_get_posts()
self.client.add_comment(
'111', '222', u'<a href="http://who">Degenève</a>: foo Degenève bar'
).AndReturn(self.comment)
self.mox.ReplayAll()
b = Blogger.new(self.handler, auth_entity=self.auth_entity)
resp = b.create_comment('http://blawg/path/to/post', u'Degenève', 'http://who',
u'foo Degenève bar', client=self.client)
示例6: test_create_comment_gives_up_on_internal_error_bX2i87au
def test_create_comment_gives_up_on_internal_error_bX2i87au(self):
# see https://github.com/snarfed/bridgy/issues/175
self.expect_get_posts()
self.client.add_comment('111', '222', '<a href="http://who">who</a>: foo bar'
).AndRaise(RequestError('500, Internal error: bX-2i87au'))
self.mox.ReplayAll()
b = Blogger.new(self.handler, auth_entity=self.auth_entity)
resp = b.create_comment('http://blawg/path/to/post', 'who', 'http://who',
'foo bar', client=self.client)
# the key point is that create_comment doesn't raise an exception
self.assert_equals({'error': '500, Internal error: bX-2i87au'}, resp)
示例7: test_create_comment_with_unicode_chars
def test_create_comment_with_unicode_chars(self):
# TODO: this just checks the arguments passed to client.add_comment(). we
# should test that the blogger client itself encodes as UTF-8.
self.expect_get_posts()
prefix = u'<a href="http://who">Degenève</a>: '
content = prefix + 'x' * (blogger.MAX_COMMENT_LENGTH - len(prefix) - 3) + '...'
self.client.add_comment('111', '222', content).AndReturn(self.comment)
self.mox.ReplayAll()
b = Blogger.new(self.handler, auth_entity=self.auth_entity)
resp = b.create_comment('http://blawg/path/to/post', u'Degenève', 'http://who',
'x' * blogger.MAX_COMMENT_LENGTH, client=self.client)
示例8: test_new_no_blogs
def test_new_no_blogs(self):
self.auth_entity.blog_hostnames = []
self.assertIsNone(Blogger.new(self.handler, auth_entity=self.auth_entity))
self.assertIn('Blogger blog not found', next(iter(self.handler.messages)))
示例9: test_feed_url
def test_feed_url(self):
self.assertEquals(
'http://my.blawg/feeds/posts/default',
Blogger.new(self.handler, auth_entity=self.auth_entity).feed_url())
示例10: template_vars
def template_vars(self):
vars = super(UserHandler, self).template_vars()
vars.update({
'source': self.source,
'EPOCH': util.EPOCH,
'REFETCH_HFEED_TRIGGER': models.REFETCH_HFEED_TRIGGER,
'RECENT_PRIVATE_POSTS_THRESHOLD': RECENT_PRIVATE_POSTS_THRESHOLD,
})
if not self.source:
return vars
if isinstance(self.source, instagram.Instagram):
auth = self.source.auth_entity
vars['indieauth_me'] = (
auth.id if isinstance(auth, indieauth.IndieAuth)
else self.source.domain_urls[0] if self.source.domain_urls
else None)
# Blog webmention promos
if 'webmention' not in self.source.features:
if self.source.SHORT_NAME in ('blogger', 'tumblr', 'wordpress'):
vars[self.source.SHORT_NAME + '_promo'] = True
else:
for domain in self.source.domains:
if ('.blogspot.' in domain and # Blogger uses country TLDs
not Blogger.query(Blogger.domains == domain).get()):
vars['blogger_promo'] = True
elif (domain.endswith('tumblr.com') and
not Tumblr.query(Tumblr.domains == domain).get()):
vars['tumblr_promo'] = True
elif (domain.endswith('wordpress.com') and
not WordPress.query(WordPress.domains == domain).get()):
vars['wordpress_promo'] = True
# Responses
if 'listen' in self.source.features:
vars['responses'] = []
query = Response.query().filter(Response.source == self.source.key)
# if there's a paging param (responses_before or responses_after), update
# query with it
def get_paging_param(param):
val = self.request.get(param)
try:
return util.parse_iso8601(val) if val else None
except:
msg = "Couldn't parse %s %r as ISO8601" % (param, val)
logging.exception(msg)
self.abort(400, msg)
before = get_paging_param('responses_before')
after = get_paging_param('responses_after')
if before and after:
self.abort(400, "can't handle both responses_before and responses_after")
elif after:
query = query.filter(Response.updated > after).order(Response.updated)
elif before:
query = query.filter(Response.updated < before).order(-Response.updated)
else:
query = query.order(-Response.updated)
query_iter = query.iter()
for i, r in enumerate(query_iter):
r.response = json.loads(r.response_json)
r.activities = [json.loads(a) for a in r.activities_json]
if (not self.source.is_activity_public(r.response) or
not all(self.source.is_activity_public(a) for a in r.activities)):
continue
elif r.type == 'post':
r.activities = []
r.actor = r.response.get('author') or r.response.get('actor', {})
for a in r.activities + [r.response]:
if not a.get('content'):
a['content'] = a.get('object', {}).get('content')
if not r.response.get('content'):
phrases = {
'like': 'liked this',
'repost': 'reposted this',
'rsvp-yes': 'is attending',
'rsvp-no': 'is not attending',
'rsvp-maybe': 'might attend',
'rsvp-interested': 'is interested',
'invite': 'is invited',
}
r.response['content'] = '%s %s.' % (
r.actor.get('displayName') or '',
phrases.get(r.type) or phrases.get(r.response.get('verb')))
# convert image URL to https if we're serving over SSL
image_url = r.actor.setdefault('image', {}).get('url')
if image_url:
r.actor['image']['url'] = util.update_scheme(image_url, self)
# generate original post links
r.links = self.process_webmention_links(r)
r.original_links = [util.pretty_link(url, new_tab=True)
#.........这里部分代码省略.........
示例11: template_vars
def template_vars(self):
if not self.source:
return {}
vars = super(UserHandler, self).template_vars()
vars.update({
'source': self.source,
'epoch': util.EPOCH,
})
# Blog webmention promos
if 'webmention' not in self.source.features:
if self.source.SHORT_NAME in ('blogger', 'tumblr', 'wordpress'):
vars[self.source.SHORT_NAME + '_promo'] = True
else:
for domain in self.source.domains:
if ('.blogspot.' in domain and # Blogger uses country TLDs
not Blogger.query(Blogger.domains == domain).get()):
vars['blogger_promo'] = True
elif (domain.endswith('tumblr.com') and
not Tumblr.query(Tumblr.domains == domain).get()):
vars['tumblr_promo'] = True
elif (domain.endswith('wordpress.com') and
not WordPress.query(WordPress.domains == domain).get()):
vars['wordpress_promo'] = True
# Responses
if 'listen' in self.source.features:
vars['responses'] = []
for i, r in enumerate(Response.query()
.filter(Response.source == self.source.key)\
.order(-Response.updated)):
r.response = json.loads(r.response_json)
if r.activity_json: # handle old entities
r.activities_json.append(r.activity_json)
r.activities = [json.loads(a) for a in r.activities_json]
if (not gr_source.Source.is_public(r.response) or
not all(gr_source.Source.is_public(a) for a in r.activities)):
continue
r.actor = r.response.get('author') or r.response.get('actor', {})
if not r.response.get('content'):
phrases = {
'like': 'liked this',
'repost': 'reposted this',
'rsvp-yes': 'is attending',
'rsvp-no': 'is not attending',
'rsvp-maybe': 'might attend',
'invite': 'is invited',
}
r.response['content'] = '%s %s.' % (
r.actor.get('displayName') or '',
phrases.get(r.type) or phrases.get(r.response.get('verb')))
# convert image URL to https if we're serving over SSL
image_url = r.actor.setdefault('image', {}).get('url')
if image_url:
r.actor['image']['url'] = util.update_scheme(image_url, self)
# generate original post links
r.links = self.process_webmention_links(r)
vars['responses'].append(r)
if len(vars['responses']) >= 10 or i > 200:
break
# Publishes
if 'publish' in self.source.features:
publishes = Publish.query().filter(Publish.source == self.source.key)\
.order(-Publish.updated)\
.fetch(10)
for p in publishes:
p.pretty_page = util.pretty_link(
p.key.parent().id(), a_class='original-post', new_tab=True)
vars['publishes'] = publishes
if 'webmention' in self.source.features:
# Blog posts
blogposts = BlogPost.query().filter(BlogPost.source == self.source.key)\
.order(-BlogPost.created)\
.fetch(10)
for b in blogposts:
b.links = self.process_webmention_links(b)
try:
text = b.feed_item.get('title')
except ValueError:
text = None
b.pretty_url = util.pretty_link(b.key.id(), text=text,
a_class='original-post', max_length=40,
new_tab=True)
# Blog webmentions
webmentions = BlogWebmention.query()\
.filter(BlogWebmention.source == self.source.key)\
.order(-BlogWebmention.updated)\
.fetch(10)
for w in webmentions:
w.pretty_source = util.pretty_link(w.source_url(), a_class='original-post',
#.........这里部分代码省略.........