Пример #1
0
HOST_URL = 'https://brid.gy'
PRIMARY_DOMAIN = 'brid.gy'
OTHER_DOMAINS = (
  'background.brid-gy.appspot.com',
  'default.brid-gy.appspot.com',
  'brid-gy.appspot.com',
  'www.brid.gy',
  'bridgy.org',
  'www.bridgy.org',
)
LOCAL_HOSTS = (
  'localhost:8080',
  'my.dev.com:8080',
)
DOMAINS = (PRIMARY_DOMAIN,) + OTHER_DOMAINS + LOCAL_HOSTS
canonicalize_domain = webutil_handlers.redirect(OTHER_DOMAINS, PRIMARY_DOMAIN)

webutil_handlers.JINJA_ENV.globals.update({
  'naturaltime': humanize.naturaltime,
})

# https://cloud.google.com/appengine/docs/locations
TASKS_LOCATION = 'us-central1'

webmention_endpoint_cache_lock = threading.RLock()
webmention_endpoint_cache = TTLCache(500, 60 * 60 * 2)  # 2h expiration


class CompressedTextProperty(ndb.GenericProperty):
  """Custom ndb property to read compressed TextProperty()s written by Python 2."""
  def __init__(self, *args, **kwargs):
Пример #2
0
FORMATS = {
    'activitystreams': 'application/stream+json',
    'as1': 'application/stream+json',
    'as1-xml': 'application/xml',
    'as2': 'application/activity+json',
    'atom': 'application/atom+xml',
    'html': 'text/html',
    'json': 'application/json',
    'json-mf2': 'application/mf2+json',
    'jsonfeed': 'application/json',
    'mf2-json': 'application/mf2+json',
    'rss': 'application/rss+xml',
    'xml': 'application/xml',
}

canonicalize_domain = handlers.redirect(
    ('granary-demo.appspot.com', 'www.granary.io'), 'granary.io')


class Handler(handlers.ModernHandler):
    """Base class for API handlers.

  Responses are cached for 5m. You can skip the cache by including a cache=false
  query param. Background: https://github.com/snarfed/bridgy/issues/665

  Attributes:
    source: Source subclass
  """
    handle_exception = handlers.handle_exception

    @handlers.cache_response(RESPONSE_CACHE_TIME)
    @canonicalize_domain
Пример #3
0
HTTP_REQUEST_REFUSED_STATUS_CODE = 599

# Unpacked representation of logged in account in the logins cookie.
Login = collections.namedtuple('Login', ('site', 'name', 'path'))

HOST_URL = 'https://brid.gy'
PRIMARY_DOMAIN = 'brid.gy'
OTHER_DOMAINS = (
  'background.brid-gy.appspot.com',
  'default.brid-gy.appspot.com',
  'brid-gy.appspot.com',
  'www.brid.gy',
  'bridgy.org',
  'www.bridgy.org',
)
canonicalize_domain = webutil_handlers.redirect(OTHER_DOMAINS, PRIMARY_DOMAIN)

webutil_handlers.JINJA_ENV.globals.update({
  'naturaltime': humanize.naturaltime,
})


def add_poll_task(source, now=False, **kwargs):
  """Adds a poll task for the given source entity.

  Pass now=True to insert a poll-now task.
  """
  last_polled_str = source.last_polled.strftime(POLL_TASK_DATETIME_FORMAT)
  queue = 'poll-now' if now else 'poll'
  task = taskqueue.add(queue_name=queue,
                       params={'source_key': source.key.urlsafe(),
Пример #4
0
  'http://www.evdemon.org/2015/learning-more-about-quill',
))

# Average HTML page size as of 2015-10-15 is 56K, so this is very generous and
# conservative.
# http://www.sitepoint.com/average-page-weight-increases-15-2014/
# http://httparchive.org/interesting.php#bytesperpage
MAX_HTTP_RESPONSE_SIZE = 500000

# Returned as the HTTP status code when we refuse to make or finish a request.
HTTP_REQUEST_REFUSED_STATUS_CODE = 599

# Unpacked representation of logged in account in the logins cookie.
Login = collections.namedtuple('Login', ('site', 'name', 'path'))

canonicalize_domain = webutil_handlers.redirect(
  ('brid-gy.appspot.com', 'www.brid.gy'), 'brid.gy')


def add_poll_task(source, now=False, **kwargs):
  """Adds a poll task for the given source entity.

  Pass now=True to insert a poll-now task.

  Tasks inserted from a backend (e.g. twitter_streaming) are sent to that
  backend by default, which doesn't work in the dev_appserver. Setting the
  target version to 'default' in queue.yaml doesn't work either, but setting it
  here does.

  Note the constant. The string 'default' works in dev_appserver, but routes to
  default.brid-gy.appspot.com in prod instead of brid.gy, which breaks SSL
  because appspot.com doesn't have a third-level wildcard cert.
Пример #5
0
with open('beta_users.txt') as f:
    BETA_USER_PATHS = util.load_file_lines(f)

# Average HTML page size as of 2015-10-15 is 56K, so this is very generous and
# conservative.
# http://www.sitepoint.com/average-page-weight-increases-15-2014/
# http://httparchive.org/interesting.php#bytesperpage
MAX_HTTP_RESPONSE_SIZE = 500000

# Returned as the HTTP status code when we refuse to make or finish a request.
HTTP_REQUEST_REFUSED_STATUS_CODE = 599

# Unpacked representation of logged in account in the logins cookie.
Login = collections.namedtuple('Login', ('site', 'name', 'path'))

canonicalize_domain = webutil_handlers.redirect(
    ('brid-gy.appspot.com', 'www.brid.gy'), 'brid.gy')


def add_poll_task(source, now=False, **kwargs):
    """Adds a poll task for the given source entity.

  Pass now=True to insert a poll-now task.

  Tasks inserted from a backend (e.g. twitter_streaming) are sent to that
  backend by default, which doesn't work in the dev_appserver. Setting the
  target version to 'default' in queue.yaml doesn't work either, but setting it
  here does.

  Note the constant. The string 'default' works in dev_appserver, but routes to
  default.brid-gy.appspot.com in prod instead of brid.gy, which breaks SSL
  because appspot.com doesn't have a third-level wildcard cert.
Пример #6
0
FORMATS = (
  'activitystreams',
  'as1',
  'as1-xml',
  'as2',
  'atom',
  'html',
  'json',
  'json-mf2',
  'jsonfeed',
  'mf2-json',
  'rss',
  'xml',
)

canonicalize_domain = handlers.redirect(
  ('granary-demo.appspot.com', 'www.granary.io'), 'granary.io')


class Handler(handlers.ModernHandler):
  """Base class for API handlers.

  Responses are cached for 5m. You can skip the cache by including a cache=false
  query param. Background: https://github.com/snarfed/bridgy/issues/665

  Attributes:
    source: Source subclass
  """
  handle_exception = handlers.handle_exception

  @canonicalize_domain
  @handlers.memcache_response(RESPONSE_CACHE_TIME)
Пример #7
0
    'Accept': '%s; q=0.9, %s; q=0.8' % (CONTENT_TYPE_AS2, CONTENT_TYPE_AS2_LD),
}
CONNEG_HEADERS_AS2_HTML = {
    'Accept': CONNEG_HEADERS_AS2['Accept'] + ', %s; q=0.7' % CONTENT_TYPE_HTML,
}

SUPPORTED_VERBS = (
    'checkin',
    'create',
    'like',
    'share',
    'tag',
    'update',
)

canonicalize_domain = handlers.redirect('bridgy-federated.appspot.com', 'fed.brid.gy')


def requests_get(url, **kwargs):
    return _requests_fn(util.requests_get, url, **kwargs)


def requests_post(url, **kwargs):
    return _requests_fn(util.requests_post, url, **kwargs)


def _requests_fn(fn, url, parse_json=False, **kwargs):
    """Wraps requests.* and adds raise_for_status() and User-Agent."""
    kwargs.setdefault('headers', {}).update(HEADERS)

    resp = fn(url, **kwargs)