本文整理汇总了Python中models.BlogWebmention类的典型用法代码示例。如果您正苦于以下问题:Python BlogWebmention类的具体用法?Python BlogWebmention怎么用?Python BlogWebmention使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BlogWebmention类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_domain_not_found
def test_domain_not_found(self):
# no source
msg = 'Could not find FakeSource account for foo.com.'
self.source.key.delete()
self.assert_error(msg)
self.assertEquals(0, BlogWebmention.query().count())
# source without webmention feature
self.source.features = ['listen']
self.source.put()
self.assert_error(msg)
self.assertEquals(0, BlogWebmention.query().count())
# source without domain
self.source.features = ['webmention']
self.source.domains = ['asdfoo.com', 'foo.comedy']
self.source.put()
self.assert_error(msg)
self.assertEquals(0, BlogWebmention.query().count())
# source is disabled
self.source.domains = ['foo.com']
self.source.status = 'disabled'
self.source.put()
self.assert_error(msg)
self.assertEquals(0, BlogWebmention.query().count())
开发者ID:mblaney,项目名称:bridgy,代码行数:26,代码来源:test_blog_webmention.py
示例2: test_domain_not_found
def test_domain_not_found(self):
self.expect_requests_get('http://foo.com/post/1', status_code=404)
for i in range(4):
self.expect_requests_get('http://foo.com/post/1', '')
self.mox.ReplayAll()
# couldn't fetch source URL
self.source.key.delete()
self.assert_error('Could not fetch source URL http://foo.com/post/1')
self.assertEquals(0, BlogWebmention.query().count())
# no source
msg = 'Could not find FakeSource account for foo.com.'
self.assert_error(msg)
self.assertEquals(0, BlogWebmention.query().count())
# source without webmention feature
self.source.features = ['listen']
self.source.put()
self.assert_error(msg)
self.assertEquals(0, BlogWebmention.query().count())
# source without domain
self.source.features = ['webmention']
self.source.domains = ['asdfoo.com', 'foo.comedy']
self.source.put()
self.assert_error(msg)
self.assertEquals(0, BlogWebmention.query().count())
# source is disabled
self.source.domains = ['foo.com']
self.source.status = 'disabled'
self.source.put()
self.assert_error(msg)
self.assertEquals(0, BlogWebmention.query().count())
开发者ID:snarfed,项目名称:bridgy,代码行数:35,代码来源:test_blog_webmention.py
示例3: test_rel_canonical_different_domain
def test_rel_canonical_different_domain(self):
self.expect_requests_get('http://foo.zz/post/1', """
<head>
<link href='http://foo.com/post/1' rel='canonical'/>
</head>
foo bar""")
html = """
<article class="h-entry"><p class="e-content">
<a href="http://bar.com/mention">this post</a>
i hereby <a href="http://foo.zz/post/1">mention</a>
</p></article>"""
self.expect_requests_get('http://bar.com/mention', html)
testutil.FakeSource.create_comment(
'http://foo.zz/post/1', 'foo.zz', 'http://foo.zz/',
'mentioned this in <a href="http://bar.com/mention">bar.com/mention</a>. <br /> <a href="http://bar.com/mention">via bar.com</a>')
self.mox.ReplayAll()
resp = self.get_response('http://bar.com/mention', 'http://foo.zz/post/1')
self.assertEquals(200, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/mention http://foo.zz/post/1')
self.assertEquals('complete', bw.status)
self.assertEquals(html, bw.html)
开发者ID:snarfed,项目名称:bridgy,代码行数:25,代码来源:test_blog_webmention.py
示例4: test_source_link_not_found
def test_source_link_not_found(self):
html = '<article class="h-entry"></article>'
self.expect_requests_get('http://bar.com/reply', html)
self.mox.ReplayAll()
self.assert_error('Could not find target URL')
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('failed', bw.status)
开发者ID:notenoughneon,项目名称:bridgy,代码行数:7,代码来源:blog_webmention_test.py
示例5: test_success
def test_success(self):
html = """
<article class="h-entry">
<p class="p-author">my name</p>
<p class="e-content">
i hereby reply
<a class="u-in-reply-to" href="http://foo.com/post/1"></a>
</p></article>"""
self.expect_requests_get('http://bar.com/reply', html)
testutil.FakeSource.create_comment(
'http://foo.com/post/1', 'my name', 'http://foo.com/',
'i hereby reply\n<a class="u-in-reply-to" href="http://foo.com/post/1"></a>'
' <br /> <a href="http://bar.com/reply">via bar.com</a>'
).AndReturn({'id': 'fake id'})
self.mox.ReplayAll()
resp = self.get_response()
self.assertEquals(200, resp.status_int, resp.body)
self.assertEquals({'id': 'fake id'}, json.loads(resp.body))
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals(self.source.key, bw.source)
self.assertEquals('complete', bw.status)
self.assertEquals('comment', bw.type)
self.assertEquals(html, bw.html)
self.assertEquals({'id': 'fake id'}, bw.published)
开发者ID:mblaney,项目名称:bridgy,代码行数:27,代码来源:test_blog_webmention.py
示例6: test_source_missing_mf2
def test_source_missing_mf2(self):
html = 'no microformats here, run along'
self.expect_requests_get('http://bar.com/reply', html)
self.mox.ReplayAll()
self.assert_error('No microformats2 data found')
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('failed', bw.status)
self.assertEquals(html, bw.html)
开发者ID:mblaney,项目名称:bridgy,代码行数:8,代码来源:test_blog_webmention.py
示例7: test_create_comment_exception
def test_create_comment_exception(self):
self.expect_mention().AndRaise(exc.HTTPPaymentRequired())
self.mox.ReplayAll()
resp = self.get_response()
self.assertEquals(402, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('failed', bw.status)
self.assertEquals(self.mention_html, bw.html)
开发者ID:mblaney,项目名称:bridgy,代码行数:9,代码来源:test_blog_webmention.py
示例8: test_create_comment_404s
def test_create_comment_404s(self):
self.expect_mention().AndRaise(exc.HTTPNotFound('gone baby gone'))
self.mox.ReplayAll()
self.assert_error('gone baby gone', status=404)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('failed', bw.status)
self.assertEquals(self.mention_html, bw.html)
开发者ID:mblaney,项目名称:bridgy,代码行数:9,代码来源:test_blog_webmention.py
示例9: test_strip_utm_query_params
def test_strip_utm_query_params(self):
"""utm_* query params should be stripped from target URLs."""
self.expect_mention()
self.mox.ReplayAll()
resp = self.get_response(target=urllib.quote(
'http://foo.com/post/1?utm_source=x&utm_medium=y'))
self.assertEquals(200, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('complete', bw.status)
开发者ID:mblaney,项目名称:bridgy,代码行数:10,代码来源:test_blog_webmention.py
示例10: test_create_comment_401_disables_source
def test_create_comment_401_disables_source(self):
self.expect_mention().AndRaise(exc.HTTPUnauthorized('no way'))
self.mox.ReplayAll()
self.assert_error('no way', status=401)
source = self.source.key.get()
self.assertEquals('disabled', source.status)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('failed', bw.status)
self.assertEquals(self.mention_html, bw.html)
开发者ID:mblaney,项目名称:bridgy,代码行数:11,代码来源:test_blog_webmention.py
示例11: test_repeated
def test_repeated(self):
# 1) first a failure
self.expect_requests_get('http://bar.com/reply', '')
# 2) should allow retrying, this one will succeed
self.expect_requests_get('http://bar.com/reply', """
<article class="h-entry">
<a class="u-url" href="http://bar.com/reply"></a>
<a class="u-repost-of" href="http://foo.com/post/1"></a>
</article>""")
testutil.FakeSource.create_comment(
'http://foo.com/post/1', 'foo.com', 'http://foo.com/',
'reposted this. <br /> <a href="http://bar.com/reply">via bar.com</a>')
# 3) after success, another is a noop and returns 200
# TODO: check for "updates not supported" message
self.mox.ReplayAll()
# now the webmention requests. 1) failure
self.assert_error('No microformats2 data found')
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('failed', bw.status)
# 2) success
resp = self.get_response()
self.assertEquals(200, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('complete', bw.status)
self.assertEquals('repost', bw.type)
# 3) noop repeated success
# source without webmention feature
resp = self.get_response()
self.assertEquals(200, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('complete', bw.status)
开发者ID:mblaney,项目名称:bridgy,代码行数:36,代码来源:test_blog_webmention.py
示例12: test_source_link_check_ignores_fragment
def test_source_link_check_ignores_fragment(self):
html = """\
<article class="h-entry"><p class="e-content">
<span class="p-name">my post</span>
<a href="http://foo.com/post/1"></a>
</p></article>"""
self.expect_requests_get('http://bar.com/reply', html)
testutil.FakeSource.create_comment(
'http://foo.com/post/1', 'foo.com', 'http://foo.com/',
'mentioned this in <a href="http://bar.com/reply">my post</a>. <br /> <a href="http://bar.com/reply">via bar.com</a>')
self.mox.ReplayAll()
resp = self.get_response()
self.assertEquals(200, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('complete', bw.status)
开发者ID:mblaney,项目名称:bridgy,代码行数:16,代码来源:test_blog_webmention.py
示例13: test_target_redirects
def test_target_redirects(self):
html = """\
<article class="h-entry"><p class="e-content">
http://second/
</p></article>"""
redirects = ['http://second/', 'http://foo.com/final']
self.expect_requests_head('http://first/', redirected_url=redirects)
self.expect_requests_get('http://bar.com/reply', html)
testutil.FakeSource.create_comment(
'http://foo.com/final', 'foo.com', 'http://foo.com/', mox.IgnoreArg())
self.mox.ReplayAll()
resp = self.get_response(target='http://first/')
self.assertEquals(200, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/final')
self.assertEquals('complete', bw.status)
self.assertEquals(['http://first/', 'http://second/'], bw.redirected_target_urls)
开发者ID:mblaney,项目名称:bridgy,代码行数:17,代码来源:test_blog_webmention.py
示例14: test_create_comment_exception
def test_create_comment_exception(self):
html = """\
<article class="h-entry"><p class="e-content">
<span class="p-name">my post</span>
http://foo.com/post/1
</p></article>"""
self.expect_requests_get('http://bar.com/reply', html)
testutil.FakeSource.create_comment(
'http://foo.com/post/1', 'foo.com', 'http://foo.com/', mox.IgnoreArg()
).AndRaise(exc.HTTPPaymentRequired())
self.mox.ReplayAll()
resp = self.get_response()
self.assertEquals(402, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('failed', bw.status)
self.assertEquals(html, bw.html)
开发者ID:dev511,项目名称:bridgy,代码行数:17,代码来源:blog_webmention_test.py
示例15: test_strip_utm_query_params
def test_strip_utm_query_params(self):
"""utm_* query params should be stripped from target URLs."""
html = """\
<article class="h-entry"><p class="e-content">
<span class="p-name">my post</span>
http://foo.com/post/1
</p></article>"""
self.expect_requests_get('http://bar.com/reply', html)
testutil.FakeSource.create_comment(
'http://foo.com/post/1', 'foo.com', 'http://foo.com/',
'mentioned this in <a href="http://bar.com/reply">my post</a>. <br /> <a href="http://bar.com/reply">via bar.com</a>')
self.mox.ReplayAll()
resp = self.get_response(target=urllib.quote(
'http://foo.com/post/1?utm_source=x&utm_medium=y'))
self.assertEquals(200, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('complete', bw.status)
开发者ID:dev511,项目名称:bridgy,代码行数:18,代码来源:blog_webmention_test.py
示例16: test_reply_outside_e_content
def test_reply_outside_e_content(self):
html = """
<article class="h-entry">
<p class="p-author">my name</p>
<p class="p-in-reply-to h-cite"><a href="http://foo.com/post/1"></a></p>
<div class="e-content">
i hereby reply
</div></article>"""
self.expect_requests_get('http://bar.com/reply', html)
testutil.FakeSource.create_comment(
'http://foo.com/post/1', 'my name', 'http://foo.com/',
'i hereby reply <br /> <a href="http://bar.com/reply">via bar.com</a>'
).AndReturn({'id': 'fake id'})
self.mox.ReplayAll()
resp = self.get_response()
self.assertEquals(200, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('complete', bw.status)
self.assertEquals({'id': 'fake id'}, bw.published)
开发者ID:notenoughneon,项目名称:bridgy,代码行数:22,代码来源:blog_webmention_test.py
示例17: test_unicode_in_target_and_source_urls
def test_unicode_in_target_and_source_urls(self):
"""Unicode chars in target and source URLs should work."""
# note the … and ✁ chars
target = u'http://foo.com/2014/11/23/england-german…iendly-wembley'
source = u'http://bar.com/✁/1'
html = u"""\
<meta charset="utf-8">
<article class="h-entry"><p class="e-content">
<span class="p-name">my post</span>
%s
</p></article>""" % target
self.expect_requests_get(source, html)
comment = u'mentioned this in <a href="%s">my post</a>. <br /> <a href="%s">via bar.com</a>' % (source, source)
testutil.FakeSource.create_comment(target, 'foo.com', 'http://foo.com/', comment)
self.mox.ReplayAll()
resp = self.get_response(source=source, target=target)
self.assertEquals(200, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id(' '.join((source, target)))
self.assertEquals('complete', bw.status)
开发者ID:mblaney,项目名称:bridgy,代码行数:22,代码来源:test_blog_webmention.py
示例18: test_u_url
def test_u_url(self):
html = """
<article class="h-entry">
<p class="p-name"></p> <!-- empty -->
<p class="p-author">my name</p>
<p class="e-content">
i hereby mention
<a href="http://foo.com/post/1"></a>
<a class="u-url" href="http://barzz.com/u/url"></a>
</p></article>"""
self.expect_requests_get('http://bar.com/reply', html)
testutil.FakeSource.create_comment(
'http://foo.com/post/1', 'my name', 'http://foo.com/', """mentioned this in <a href="http://barzz.com/u/url">barzz.com/u/url</a>. <br /> <a href="http://barzz.com/u/url">via barzz.com</a>"""
).AndReturn({'id': 'fake id'})
self.mox.ReplayAll()
resp = self.get_response()
self.assertEquals(200, resp.status_int, resp.body)
bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1')
self.assertEquals('complete', bw.status)
self.assertEquals('post', bw.type)
self.assertEquals('http://barzz.com/u/url', bw.u_url)
self.assertEquals('http://barzz.com/u/url', bw.source_url())
开发者ID:mblaney,项目名称:bridgy,代码行数:24,代码来源:test_blog_webmention.py
示例19: template_vars
#.........这里部分代码省略.........
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)
for url in r.original_posts]
vars['responses'].append(r)
if len(vars['responses']) >= 10 or i > 200:
break
vars['responses'].sort(key=lambda r: r.updated, reverse=True)
# calculate new paging param(s)
new_after = (
before if before else
vars['responses'][0].updated if
vars['responses'] and query_iter.probably_has_next() and (before or after)
else None)
if new_after:
vars['responses_after_link'] = ('?responses_after=%s#responses' %
new_after.isoformat())
new_before = (
after if after else
vars['responses'][-1].updated if
vars['responses'] and query_iter.probably_has_next()
else None)
if new_before:
vars['responses_before_link'] = ('?responses_before=%s#responses' %
new_before.isoformat())
vars['next_poll'] = max(
self.source.last_poll_attempt + self.source.poll_period(),
# lower bound is 1 minute from now
util.now_fn() + datetime.timedelta(seconds=90))
# 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(), attrs={'class': 'original-post u-url u-name'},
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, attrs={'class': 'original-post u-url u-name'},
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(), attrs={'class': 'original-post'}, new_tab=True)
try:
target_is_source = (urlparse.urlparse(w.target_url()).netloc in
self.source.domains)
except BaseException:
target_is_source = False
w.pretty_target = util.pretty_link(
w.target_url(), attrs={'class': 'original-post'}, new_tab=True,
keep_host=target_is_source)
vars.update({'blogposts': blogposts, 'webmentions': webmentions})
return vars
开发者ID:LennonFlores,项目名称:bridgy,代码行数:101,代码来源:app.py
示例20: post
def post(self, source_short_name):
logging.info('Params: %self', self.request.params.items())
# strip fragments from source and target url
self.source_url = urlparse.urldefrag(util.get_required_param(self, 'source'))[0]
self.target_url = urlparse.urldefrag(util.get_required_param(self, 'target'))[0]
# follow target url through any redirects, strip utm_* query params
resp = util.follow_redirects(self.target_url)
redirected_target_urls = [r.url for r in resp.history]
self.target_url = util.clean_url(resp.url)
# parse and validate target URL
domain = util.domain_from_link(self.target_url)
if not domain:
return self.error('Could not parse target URL %s' % self.target_url)
# look up source by domain
source_cls = models.sources[source_short_name]
domain = domain.lower()
self.source = (source_cls.query()
.filter(source_cls.domains == domain)
.filter(source_cls.features == 'webmention')
.filter(source_cls.status == 'enabled')
.get())
if not self.source:
return self.error(
'Could not find %s account for %s. Is it registered with Bridgy?' %
(source_cls.GR_CLASS.NAME, domain))
if urlparse.urlparse(self.target_url).path in ('', '/'):
return self.error('Home page webmentions are not currently supported.')
# create BlogWebmention entity
id = u'%s %s' % (self.source_url, self.target_url)
self.entity = BlogWebmention.get_or_insert(
id, source=self.source.key, redirected_target_urls=redirected_target_urls)
if self.entity.status == 'complete':
# TODO: response message saying update isn't supported
self.response.write(self.entity.published)
return
logging.debug('BlogWebmention entity: %s', self.entity.key.urlsafe())
# fetch source page
resp = self.fetch_mf2(self.source_url)
if not resp:
return
self.fetched, data = resp
item = self.find_mention_item(data)
if not item:
return self.error('Could not find target URL %s in source page %s' %
(self.target_url, self.fetched.url),
data=data, log_exception=False)
# default author to target domain
author_name = domain
author_url = 'http://%s/' % domain
# extract author name and URL from h-card, if any
props = item['properties']
author = first_value(props, 'author')
if author:
if isinstance(author, basestring):
author_name = author
else:
author_props = author.get('properties', {})
author_name = first_value(author_props, 'name')
author_url = first_value(author_props, 'url')
# if present, u-url overrides source url
u_url = first_value(props, 'url')
if u_url:
self.entity.u_url = u_url
# generate content
content = props['content'][0] # find_mention_item() guaranteed this is here
text = (content.get('html') or content.get('value')).strip()
source_url = self.entity.source_url()
text += ' <br /> <a href="%s">via %s</a>' % (
source_url, util.domain_from_link(source_url))
# write comment
try:
self.entity.published = self.source.create_comment(
self.target_url, author_name, author_url, text)
except Exception, e:
code, body = util.interpret_http_exception(e)
msg = 'Error: %s %s; %s' % (code, e, body)
if code == '401':
logging.warning('Disabling source!')
self.source.status = 'disabled'
self.source.put()
return self.error(msg, status=code, mail=False)
elif code == '404':
# post is gone
return self.error(msg, status=code, mail=False)
elif code or body:
return self.error(msg, status=code, mail=True)
else:
raise
开发者ID:LennonFlores,项目名称:bridgy,代码行数:100,代码来源:blog_webmention.py
注:本文中的models.BlogWebmention类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论