switch from webutil.util.memcache_response to cache_response

python3
Ryan Barrett 2019-11-12 21:28:44 -08:00
rodzic 035050a7aa
commit 99a5c35ae3
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
11 zmienionych plików z 25 dodań i 19 usunięć

Wyświetl plik

@ -9,7 +9,7 @@ from google.appengine.ext import ndb
from granary import as2, microformats2
import mf2util
from oauth_dropins.webutil import util
from oauth_dropins.webutil.handlers import memcache_response
from oauth_dropins.webutil.handlers import cache_response
import ujson as json
import webapp2
@ -70,7 +70,7 @@ def send(activity, inbox_url, user_domain):
class ActorHandler(webapp2.RequestHandler):
"""Serves /[DOMAIN], fetches its mf2, converts to AS Actor, and serves it."""
@memcache_response(CACHE_TIME)
@cache_response(CACHE_TIME)
def get(self, domain):
mf2 = util.fetch_mf2('http://%s/' % domain, gateway=True,
headers=common.HEADERS)

Wyświetl plik

@ -5,7 +5,7 @@ import urllib
import appengine_config
from oauth_dropins.webutil.handlers import memcache_response
from oauth_dropins.webutil.handlers import cache_response
import requests
import webapp2
@ -19,7 +19,7 @@ CACHE_TIME = datetime.timedelta(seconds=15)
class AddWebmentionHandler(webapp2.RequestHandler):
"""Proxies HTTP requests and adds Link header to our webmention endpoint."""
@memcache_response(CACHE_TIME)
@cache_response(CACHE_TIME)
def get(self, url):
url = urllib.unquote(url)
if not url.startswith('http://') and not url.startswith('https://'):

Wyświetl plik

@ -14,8 +14,6 @@ import ujson as json
from webmentiontools import send
from webob import exc
from google.appengine.api import memcache
import appengine_config
import common
from models import Response
@ -383,7 +381,6 @@ def redirect_unwrap(val):
return val[len(REDIRECT_PREFIX):]
elif val.startswith(appengine_config.HOST_URL):
return util.follow_redirects(
util.domain_from_link(urlparse.urlparse(val).path.strip('/')),
cache=memcache).url
util.domain_from_link(urlparse.urlparse(val).path.strip('/'))).url
return val

Wyświetl plik

@ -14,7 +14,7 @@ import logging
from granary import as2, microformats2
import mf2util
from oauth_dropins.webutil import util
from oauth_dropins.webutil.handlers import memcache_response
from oauth_dropins.webutil.handlers import cache_response
import ujson as json
import webapp2
@ -30,7 +30,7 @@ class RedirectHandler(webapp2.RequestHandler):
e.g. redirects /r/https://foo.com/bar?baz to https://foo.com/bar?baz
"""
@memcache_response(CACHE_TIME)
@cache_response(CACHE_TIME)
def get(self):
assert self.request.path_qs.startswith('/r/')
to = self.request.path_qs[3:]

Wyświetl plik

@ -5,7 +5,7 @@ import datetime
import appengine_config
from granary import as2, atom, microformats2
from oauth_dropins.webutil.handlers import memcache_response, ModernHandler
from oauth_dropins.webutil.handlers import cache_response, ModernHandler
from oauth_dropins.webutil import util
import ujson as json
import webapp2
@ -18,7 +18,7 @@ CACHE_TIME = datetime.timedelta(minutes=15)
class RenderHandler(ModernHandler):
"""Fetches a stored Response and renders it as HTML."""
@memcache_response(CACHE_TIME)
@cache_response(CACHE_TIME)
def get(self):
source = util.get_required_param(self, 'source')
target = util.get_required_param(self, 'target')

Wyświetl plik

@ -14,7 +14,7 @@ import requests
import ujson as json
import activitypub
from activitypub import app
from activitypub import ActorHandler, app
import common
from models import Follower, MagicKey, Response
import testutil
@ -138,6 +138,10 @@ UNDO_FOLLOW_WRAPPED = {
@patch('requests.head')
class ActivityPubTest(testutil.TestCase):
def setUp(self):
super(ActivityPubTest, self).setUp()
ActorHandler.get.cache_clear()
def test_actor_handler(self, _, mock_get, __):
mock_get.return_value = requests_response("""
<body>

Wyświetl plik

@ -6,13 +6,17 @@ from mock import patch
from oauth_dropins.webutil.testutil import requests_response
import common
from redirect import app
from redirect import app, RedirectHandler
from test_webmention import REPOST_HTML, REPOST_AS2
import testutil
class RedirectTest(testutil.TestCase):
def setUp(self):
super(RedirectTest, self).setUp()
RedirectHandler.get.cache_clear()
def test_redirect(self):
got = app.get_response('/r/https://foo.com/bar?baz=baj&biff')
self.assertEqual(302, got.status_int)

Wyświetl plik

@ -6,14 +6,14 @@ import ujson as json
from models import Response
import testutil
from render import app
from render import app, RenderHandler
class RenderTest(testutil.TestCase):
def setUp(self):
super(RenderTest, self).setUp()
RenderHandler.get.cache_clear()
self.as2 = {
'@context': 'https://www.w3.org/ns/activitystreams',
'type': 'Note',

Wyświetl plik

@ -15,7 +15,7 @@ import ujson as json
import common
import models
import testutil
from webfinger import app
from webfinger import app, UserHandler, WebfingerHandler
USER = 'foo.com@foo.com'
@ -24,6 +24,8 @@ class WebFingerTest(testutil.TestCase):
def setUp(self):
super(WebFingerTest, self).setUp()
UserHandler.get.cache_clear()
WebfingerHandler.get.cache_clear()
self.html = """
<body class="h-card">
<a class="u-url" rel="me" href="/about-me">

Wyświetl plik

@ -34,7 +34,7 @@ class UserHandler(handlers.XrdOrJrdHandler):
"""Fetches a site's home page, converts its mf2 to WebFinger, and serves."""
JRD_TEMPLATE = False
@handlers.memcache_response(CACHE_TIME)
@handlers.cache_response(CACHE_TIME)
def get(self, *args, **kwargs):
return super(UserHandler, self).get(*args, **kwargs)

Wyświetl plik

@ -13,7 +13,6 @@ import appengine_config
import django_salmon
from django_salmon import magicsigs
import feedparser
from google.appengine.api import mail
from google.appengine.ext.ndb import Key
from granary import as2, atom, microformats2, source
import mf2util