Example #1
0
 def inner(self, *argv, **kwargv):
   if modules.get_current_module_name() != tap.config.BACKEND_NAME:
     cache = yield self.has_cache_async(expire, temporary=temporary)
     if cache:
       return
   ndb.toplevel(func)(self, *argv, **kwargv)
   if self.response.status_int == 200:
     if empty or len(self.response.body) > 0:
       self.put_cache(period, temporary=temporary)
Example #2
0
 def inner(self, *argv, **kwargv):
   ndb.toplevel(func)(self, *argv, **kwargv)
   if self.response._app_iter is None:
     index = 0
   else:
     index = len(self.response._app_iter)
   self.response.write(AHEAD_HTML5)
   if len(packages):
     self.response.write(get_resource_code(packages))
     if self.response._app_iter is not None:
       self.response._app_iter = self.response._app_iter[index:] + self.response._app_iter[:index]
Example #3
0
  def test_is_acceptable(self):
    with pytest.raises(ValueError):
      utils.TokenBucket(rate=3, size=10)

    b = utils.TokenBucket(rate=1, size=2)
    b.is_acceptable = ndb.toplevel(utils.make_synctasklet(b.is_acceptable_async))
    assert b.is_acceptable() is True
    assert b.is_acceptable() is True
    assert b.is_acceptable() is False

    b = utils.TokenBucket(rate=1, size=1, prefix="test")
    b.is_acceptable = ndb.toplevel(utils.make_synctasklet(b.is_acceptable_async))
    assert b.is_acceptable() is True
    assert b.is_acceptable() is False
    assert b.is_acceptable(key="test") is True
    assert b.is_acceptable(key="test") is False
Example #4
0
  def test_is_acceptable(self):
    with pytest.raises(ValueError):
      tap.TokenBucket(rate=3, size=10)

    b = tap.TokenBucket(rate=1, size=2)
    b.is_acceptable = ndb.toplevel(tap.make_synctasklet(b.is_acceptable_async))
    assert b.is_acceptable() is True
    assert b.is_acceptable() is True
    assert b.is_acceptable() is False

    b = tap.TokenBucket(rate=1, size=1, prefix="test")
    b.is_acceptable = ndb.toplevel(tap.make_synctasklet(b.is_acceptable_async))
    assert b.is_acceptable() is True
    assert b.is_acceptable() is False
    assert b.is_acceptable(key="test") is True
    assert b.is_acceptable(key="test") is False
Example #5
0
def run_wsgi_app(application_or_mapping):
    """This wrapped version of run_wsgi_app accepts an instance of either WSGIApplication or list"""
    from google.appengine.ext.webapp import WSGIApplication as _WSGIApplication
    if isinstance(application_or_mapping, list):
        application = _WSGIApplication(application_or_mapping, debug=True)
    from google.appengine.ext.webapp.util import run_wsgi_app as _run_wsgi_app
    from google.appengine.ext import ndb
    _run_wsgi_app(ndb.toplevel(application))
def run_wsgi_app(application_or_mapping):
    """This wrapped version of run_wsgi_app accepts an instance of either WSGIApplication or list"""
    from google.appengine.ext.webapp import WSGIApplication as _WSGIApplication
    if isinstance(application_or_mapping, list):
        application = _WSGIApplication(application_or_mapping, debug=True)
    from google.appengine.ext.webapp.util import run_wsgi_app as _run_wsgi_app
    from google.appengine.ext import ndb
    _run_wsgi_app(ndb.toplevel(application))
Example #7
0
 def inner(self, *argv, **kwargv):
   ndb.toplevel(func)(self, *argv, **kwargv)
   if origin is None:
     allow_origin = self.request.headers.get("Origin")
     if allow_origin is None and self.request.referer:
       allow_origin = "{0}://{1}".format(*urlparse(self.request.referer)[:2])
   else:
     if callable(origin):
       allow_origin = origin()
   if allow_origin:
     self.response.headers["Access-Control-Allow-Origin"] = allow_origin
   if security.compare_hashes(self.request.method, "OPTIONS"):
     self.response.headers["Access-Control-Max-Age"] = tap.config.CORS_Access_Control_Max_Age
     method = self.request.headers.get("Access-Control-Request-Method")
     if method:
       self.response.headers["Access-Control-Allow-Methods"] = method
     headers = self.request.headers.get("Access-Control-Request-Headers")
     if headers:
       self.response.headers["Access-Control-Allow-Headers"] = headers
Example #8
0
    def decorator(fn):
        fn = adapt_exceptions(fn)
        fn = auth.public(fn)
        fn = endpoints_decorator(fn)

        ts_mon_time = lambda: utils.datetime_to_timestamp(utils.utcnow()) / 1e6
        fn = gae_ts_mon.instrument_endpoint(time_fn=ts_mon_time)(fn)
        # ndb.toplevel must be the last one.
        # See also the comment in endpoint decorator in api.py
        return ndb.toplevel(fn)
Example #9
0
    def decorator(fn):
        fn = catch_errors(fn, response_message_class)
        fn = endpoints_decorator(fn)
        fn = ndb.toplevel(fn)

        def ts_mon_time():
            return utils.datetime_to_timestamp(utils.utcnow()) / 1000000.0

        fn = gae_ts_mon.instrument_endpoint(time_fn=ts_mon_time)(fn)
        return fn
Example #10
0
    def decorator(fn):
        fn = auth.public(fn)
        fn = endpoints_decorator(fn)
        fn = ndb.toplevel(fn)

        def ts_mon_time():
            return utils.datetime_to_timestamp(utils.utcnow()) / 1000000.0

        fn = gae_ts_mon.instrument_endpoint(time_fn=ts_mon_time)(fn)
        return fn
def toplevel_wrapper(*args, **kwargs):
    """Enables a WSGI application to not exit until all its asynchronous
    requests have finished.

    For more information, see
    https://developers.google.com/appengine/docs/python/ndb/async#intro

    Args:
        *args: Variable length argument list.
        **kwargs: Arbitrary keyword arguments.
    """
    return ndb.toplevel(*args, **kwargs)
Example #12
0
    def decorator(fn):
        fn = catch_errors(fn, response_message_class)
        fn = init_auth(fn)

        ts_mon_time = lambda: utils.datetime_to_timestamp(utils.utcnow()) / 1e6
        fn = gae_ts_mon.instrument_endpoint(time_fn=ts_mon_time)(fn)

        # ndb.toplevel must be the last one.
        # We use it because codebase uses the following pattern:
        #   results = [f.get_result() for f in futures]
        # without ndb.Future.wait_all.
        # If a future has an exception, get_result won't be called successive
        # futures, and thus may be left running.
        return ndb.toplevel(fn)
Example #13
0
 def __init__(self, *argv, **kwargv):
   for method_name in METHOD_NAMES:
     method = getattr(self, method_name, None)
     if method:
       method = ndb.toplevel(method)
       setattr(self, method_name, method)
   super(RequestHandler, self).__init__(*argv, **kwargv)
   if self.use_zipfile:
     setattr(self.response, "flush", self._response_flush)
     setattr(self.response, "tell", self._response_tell)
   self.dispatch = tap.set_urlfetch_deadline(self.urlfetch_deadline)(self.dispatch)
   namespace = inspect.getmodule(self).__dict__.get(tap.NAMESPACE_KEY)
   if namespace is not None:
     self.dispatch = tap.in_namespace(namespace)(self.dispatch)
   self.context["USERS"] = self.users = Users(self)
Example #14
0
def clear_event_queue(app):
    """Clear ndb event queue.

    Some Futures complete and get their job done, triggering completion
    callbacks to be stuck in the event queue. However, since we just writing
    regular NDB code (not tasklets), there is no guarantee that the event queue
    will be emptied when the request finishes. This leaves Futures stuck in the
    thread-local cache, in each thread, uselessly between requests.

    There is no way to disable this like with an NDB cache.

    However, You can solve this by wrapping *any* code that uses NDB objects
    with `@ndb.toplevel`. The documentation mentions this only in the context
    of being useful for tasklet code this should be run for *ALL* code that
    uses NDB libraries. In fact, given the nature of what it does, can be done
    in a wrapper around the wsgi library in the appengine runtime, similar to
    what is done with the threadlocal variables in `appengine.runtime`’s
    management of `request_environment.current_request`.
    """
    return ndb.toplevel(app)
Example #15
0
app = ndb.toplevel(
    webapp2.WSGIApplication(
        [
            ('/', MainHandler),
            ('(.*)/$', SlashMurdererApp),
            ('/privacy', PrivacyHandler),
            ('/privacy-policy', PrivacyHandler),
            ('/terms', TermsHandler),
            ('/facebook', FbHandler),
            ('/about', AboutHandler),
            ('/contact', ContactHandler),
            ('/versus', VersusHandler),
            ('/timed', TimedHandler),
            ('/multiplayer', FriendsHandler),
            ('/games-multiplayer', GameMultiplayerHandler),
            ('/games', GamesHandler),
            ('/learn-english', LearnEnglishHandler),
            ('/learn-english/(.*)', EnglishLevelHandler),
            ('/campaign', CampaignHandler),

            # need js rendering
            (r'/campaign/..*', MainHandler),
            (r'/campaign/..*/..*', MainHandler),
            (r'/versus/..*', MainHandler),
            (r'/tests', TestsHandler),
            ('/buy', BuyHandler),
            ('/sitemap', SitemapHandler),
        ] + gameon.routes,
        debug=ws.debug,
        config=config))
Example #16
0
    #             if result_msg != '':
    #               row_log_msg.append(result_msg)
    #             if result_vcmsg is not None:
    #               for key, value in result_vcmsg.iteritems():
    #                 #row_log_msg.extend(value)
    #                 row_log_msg.extend(['[' + key + ']' + msg for msg in value])
    #
    #             # オペレーションログ出力
    #             operation_log_detail = {}
    #             operation_log_detail['fields'] = [{'key':'user_id', 'before':src_user_id, 'after':dst_user_id}]
    #             UCFMDLOperationLog.addLog(login_operator_mail_address, login_operator_unique_id, UcfConfig.SCREEN_USER, UcfConfig.OPERATION_TYPE_CHANGEID, vo.get('user_id', ''), vo.get('unique_id', ''), login_operator_client_ip, JSONEncoder().encode(operation_log_detail), is_async=True)
    #
    #
    #   except BaseException, e:
    #     self.outputErrorLog(e)
    #     code = '500'
    #     row_log_msg.append(self._formatLogRecord('system error.'))
    #
    #   # エラーメッセージ処理
    #   if code != '':
    #     #row_log_msg.append(self._formatLogRecord('[row:' + UcfUtil.nvl(record_cnt) + ',code=' + code + ']'))
    #     row_log_msg.insert(0, self._formatLogRecord('[row:' + UcfUtil.nvl(record_cnt) + ',code=' + code + ']'))
    #   return deal_type, code, row_log_msg


#app = webapp2.WSGIApplication([('/a/([^/]*)/([^/]*)/queue_csv_import', Page)], debug=sateraito_inc.debug_mode, config=sateraito_func.wsgi_config)
app = ndb.toplevel(
    webapp2.WSGIApplication([('/a/([^/]*)/([^/]*)/queue_csv_import', Page)],
                            debug=sateraito_inc.debug_mode,
                            config=sateraito_func.wsgi_config))
Example #17
0
            # temporary image for location report from android until I figure out how to upload an image from android
            image_url = 'https://00e9e64baca7129fd93c9b3c8fae1d3ae5001f077dd61bb04b-apidata.googleusercontent.com/download/storage/v1/b/pick-up-sports-images/o/android-p1.jpg?qk=AD5uMEuOyI7kIsV5921fxnl-gWsfZOKuVbNlQ0Lw7LKG2rLUpSqfQ_ZjHI4SP_N-qxx9SwFXvYFeY2UHR6teOmaFpbnbAlxefv_QNBTITsAd_cZAN9uFhEmS4UIn902NXs0tkffM3cpqLGIEd6tGuDXZXWRVhcpRKbhDzFCKrsV3k-EXamjkg1nJpghP2qD97tgcUSZ_2SPeGpWSpxHP8GXpb-035YggBqcNFQg0g3feGprHlIEWBgdogaggLIrnURw25xif4ZeRNuntjt1qGHvaqr5UJ-FGxannzHDze963-nxCnLPCNpPFFmLFcEP6I8TuT2zg9gzCKo_T-V6SgxpDbqsop3tDBiKllOF916BcA1CNoJz-GmIBZuWh0R1YilaLGLItENa_NrUtLo4yW86ZipTiXH9lAccvQv44Zw1cr-CukEOo639n-evNOMCNTRqAWzkNTeSsT3CrAtunzzwcMF1B3_D8M1M6Vq-n9Dnv9qMOpPcpe8DhqqHyjFrd_p2-vlenyTXda8SLapI0i77hTfVfSBQMOUn6p5mL-OaoSb_a9xUFIom6ey8fehPVIFClvkNGeAR833Y8vu6DCeifvoUlZnI5tjRKjLTy4AR7Y3umvRUEznJOFJfD9r_txOjI4emW_7pYPn78SxoSMZfro4zqQlrWMKWJ0sC-DlJgIjANvVEKA6dkcGoBKGHNoq9bM9Noz1aCeA-X_MK_bP0n9xK6nZLrGbDsSwAzTofEqV8Scd2dhs4'
            location_name = self.request.get('location_name')
            address = self.request.get('address')
            sport_theme_name = self.request.get('sport_theme_name')
            tag_names_string = self.request.get('tags')
            tag_name_list = tag_names_string.split()

            create_location_report(location_name, address, sport_theme_name,
                                   email, tag_name_list, image_url)

        else:
            self.response.write('signed in user is ' + email + result)


# [START app]
app = ndb.toplevel(
    webapp2.WSGIApplication([('/', HomePage),
                             ('/add_location_report', HomePage),
                             ('/mobile/home_page', HomePageMobile)],
                            debug=True))


def main():
    app.run()


if __name__ == "__main__":
    main()
# [END app]
Example #18
0
    def get(self):
        self.render('templates/contact.jinja2')


class TermsHandler(BaseHandler):
    def get(self):
        self.render('templates/terms.jinja2')


class SitemapHandler(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/xml'
        template_values = {}
        template = JINJA_ENVIRONMENT.get_template('templates/sitemap.xml')
        self.response.write(template.render(template_values))


app = ndb.toplevel(
    webapp2.WSGIApplication(
        [
            ('/', MainHandler),
            ('/tests', TestHandler),
            ('/privacy', PrivacyHandler),
            ('/terms', TermsHandler),
            # ('/about', AboutHandler),
            ('/contact', ContactHandler),
            ('/sitemap', SitemapHandler),
        ] + gameon.routes,
        debug=ws.debug,
        config=config))
Example #19
0
    zip_file = fetch_as_zip(zip_path)
    posts = [post for post in _extract_posts(zip_file)]
    Post.delete_all()
    Post.put_all(posts)

def serve_post(request):
    post_url = request.path_info
    post = Post.get_by_id(post_url)
    if not post: webapp.abort(404)
    return render('post.html', dict(post = post))

def tagged(request, tag):
    return render('index.html', dict(posts = Post.query(Post.tags == tag).order(-Post.date), without_intro = True))

def feed(request):
    response = render('feed.xml', dict(posts = Post.query().order(-Post.date)))
    response.headers['Content-Type'] = 'application/rss+xml'
    return response

def index(request):
    return render('index.html', dict(posts = Post.query().order(-Post.date)))

application = ndb.toplevel(webapp.WSGIApplication([
    webapp.SimpleRoute('/_refresh/', handler = refresh),
    webapp.Route('/tags/<tag>', handler = tagged, name = 'by-tag'), 
    webapp.SimpleRoute('/_ah/warmup', handler = index), 
    webapp.SimpleRoute('/feed', handler = feed), 
    webapp.SimpleRoute('/', handler = index), 
    webapp.SimpleRoute('/.*', handler = serve_post)
], debug=True).__call__)
Example #20
0
 def inner(self, *argv, **kwargv):
   self.set_session_store()
   ndb.toplevel(func)(self, *argv, **kwargv)
        # read upload data, save it in GCS and a zip archive
        file_data = self.request.get("file", default_value=None)
        if file_data:

            filename = self.request.POST["file"].filename
            bf = blob_files.BlobFiles.new(filename, folder=GCS_UPLOAD_FOLDER)
            if bf:
                bf.blob_write(file_data)
                bf.put_async()
                logging.info('Uploaded and saved in default GCS bucket : ' + bf.gcs_filename)

                # update zip archive. make sure this (new) bf will be archived
                bzf = blob_files.blob_archive(new_bf=bf)

                context.update(dict(failed=None, bzf_url=bzf.serving_url, bzf_name=bzf.filename,
                                    bf_url=bf.serving_url, bf_name=bf.filename))
            else:
                context.update(dict(failed='Overwrite blocked. The GCS file already exists in another bucket and/or folder'))
        else:
            logging.warning('No file data')

        self.render_template('blob_links.html', **context)

routes = [
    webapp2.Route(r'/blob_upload', handler=BlobUpload),
    webapp2.Route(r'/readme', handler='blob_upload.BlobUpload:readme'),
    ('/use_blobstore/([^/]+)?', blob_serve.UseBlobstore),
]
app = ndb.toplevel(webapp2.WSGIApplication(routes=routes, debug=True))
Example #22
0
'''
Created on Apr 26, 2016

@author: abhi
'''

import webapp2
from google.appengine.ext import ndb

from recording import RecordingsAPI
from recording import RecordingsDownloadAPI
from recording import RecordingsListAPI

app = ndb.toplevel(
    webapp2.WSGIApplication([('/recording', RecordingsAPI),
                             ('/recording/list', RecordingsListAPI),
                             ('/recording/download', RecordingsDownloadAPI)],
                            debug=False))
Example #23
0
            # self.add_topic(topics, snapshots)
            ndb.put_multi_async(topics)
            ndb.put_multi_async(snapshots)
            memcache.set(counting_mc_key, counting)
            # memcache.set(last_id_mc_key, str(item['last_id_current_page']))
            task.last_id = str(item['last_id_current_page'])
            task.counting = counting
            task.put_async()
            # page += 1 # not implement yet, counting is hard
            payload[0] = (payload[0][0], task.last_id)
            # payload[-1] = (payload[-1][0], page)
            res = requests.post(url, payload, headers=headers)
            j = res.json()
            item = j['item']
        # counted = memcache.get(counting_mc_key)
        # tag_key = ndb.Key(Tag, tag)
        # tag = tag_key.get()
        # tag.counting = counted
        # tag.put()
        # memcache.delete(counting_mc_key)
        memcache.delete(last_id_mc_key)
        memcache.delete(item_mc_key)


app = ndb.toplevel(
    webapp2.WSGIApplication(
        [('/crons/set_announcement', SetAnnouncementHandler),
         ('/tasks/send_confirmation_email', SendConfirmationEmailHandler),
         ('/tasks/collect_topic_tag', CollectTopicTagHandler)],
        debug=True))
Example #24
0
template_path = os.path.dirname(__file__) + '/templates'
locale_path = os.path.dirname(__file__) + '/locale'

logging.info('setting template path to %s' % template_path)

webapp2_config['webapp2_extras.jinja2'] = {
                                            'template_path': template_path,
                                            'filters': jinja_filters,
                                            'environment_args': jinja_environment_args
                                            } 

webapp2_config['webapp2_extras.i18n'] = {
                                         'translations_path': locale_path,
                                         'default_locale': 'en',
                                         'default_timezone': 'America/Montreal',
                                         }

webapp2_config['webapp2_extras.sessions'] = {
                                             'secret_key': '82374y6ii899hy8-89308847-21u9x676',
                                             }

webapp2_config['webapp2_extras.auth'] = {
                                         'user_model': User,
                                         }


routes = create_routes()

application = ndb.toplevel(webapp2.WSGIApplication(routes, debug=True, config=webapp2_config))
Example #25
0
#!/usr/bin/env python

from sys import path
from os import listdir
path.append('./')

import webapp2
from google.appengine.ext import ndb

from lib.utils import DEBUG

routes = []
for file_name in listdir('api'):
    if not file_name.startswith('.') and file_name.endswith(
            '.py') and file_name != '__init__.py':
        api_name = file_name[:-3]
        api_module = __import__('api.%s' % api_name).__getattribute__(api_name)
        routes += api_module.routes

app = ndb.toplevel(webapp2.WSGIApplication(routes, debug=DEBUG))
Example #26
0
class uploadPixel(webapp2.RequestHandler):
  """Upload an image handler used in the /upload-image form"""
  def get(self):
        upload_url = blobstore.create_upload_url('/upload-image2')
        template_values = {'upload_url' : upload_url }

        template = JINJA_ENVIRONMENT.get_template('upload-image.html')
        self.response.write(template.render(template_values))

class BlobStoreHandler(blobstore_handlers.BlobstoreUploadHandler):
  """ get the image upload to datastore, called on submit of /upload-image form"""
  def post(self):
        image   = self.get_uploads('img')
        blob_info = image[0]
        print blob_info

        pixel = Pixel(id="image")
        pixel.img = blob_info.key()
        pixel.put()

        self.redirect('/')


application = ndb.toplevel(webapp2.WSGIApplication([
    ('/', MainPage),
    ('/main.png', ImageRequest),
    ('/landing-page', LandingPage),
    ('/upload-image', uploadPixel),
    ('/upload-image2',BlobStoreHandler)
], debug=True))
Example #27
0
        and statistic about this click is saved. All invalid clicks (e.g. for non
        existing campaigns, platforms) users are redirected to http://outfit7.com.
        """
        # cast campaign_id, type checking is done through route definition
        try:
            campaign_id = int(campaign_id)
        except ValueError:
            return webapp2.redirect("http://outfit7.com", permanent=True)

        platform_id = "%d-%s" % (campaign_id, platform_name)
        platform = Platform.get_by_id(platform_id)
        if platform:
            memcache.incr(platform_id, 1, namespace="counters", initial_value=0)
            try:
                deferred.defer(Platform.increment, platform_id, _countdown=TRACKER_COUNTER_UPDATE_INTERVAL_LENGTH,
                               _name="%s-%d" % (platform_id, get_interval_index()))
            except (taskqueue.TaskAlreadyExistsError, taskqueue.TombstonedTaskError), e:
                pass
            # TODO: optimize with async operations
            campaign = Campaign.get_by_id(campaign_id)
            return webapp2.redirect(campaign.link.encode("utf8"))
        else:
            return webapp2.redirect("http://outfit7.com", permanent=True)


app = ndb.toplevel(webapp2.WSGIApplication([
    routes.PathPrefixRoute('/api', [
        webapp2.Route(r'/campaign/<campaign_id>/platform/<platform_name>', ClickHandler),
    ])
], debug=False))
Example #28
0
            self.write_column(stat.victory_points_yesterday)
            self.write_column(stat.victory_points_last_week)
            self.write_column(stat.victory_points_total)
            self.response.out.write('\n')
        
    def totals(self):
        # For now just spit out CSV
        self.response.headers['Content-Type'] = 'text/plain'
        
        qry = TotalStat.query().order(-TotalStat.date)
        
        self.response.out.write("date,killsYesterday,killsLastWeek,killsTotal,victoryPointsYesterday,victoryPointsLastWeek,victoryPointsTotal\n")
        
        for stat in qry.fetch():
            self.response.out.write(stat.date)
            self.write_column(stat.kills_yesterday)
            self.write_column(stat.kills_last_week)
            self.write_column(stat.kills_total)
            self.write_column(stat.victory_points_yesterday)
            self.write_column(stat.victory_points_last_week)
            self.write_column(stat.victory_points_total)
            self.response.out.write('\n')
    
app = ndb.toplevel(webapp2.WSGIApplication([
        ('/', MainHandler),
        ('/cron', CronHandler),
        ('/cruncher', CruncherHandler),
        webapp2.Route('/feed/factions', handler='main.FeedHandler:factions'),
        webapp2.Route('/feed/totals', handler='main.FeedHandler:totals'),
    ],
    debug=True))
Example #29
0
import logging
import webapp2
from webapp2_extras.routes import PathPrefixRoute
from google.appengine.ext import ndb

import app.config
from app import tasks
from app.tasks import webhooks

config = {}
config['webapp2_extras.sessions'] = {
    'secret_key': 'ezAK4re16aXlKG80cAMz'
}
application = ndb.toplevel(webapp2.WSGIApplication([
    PathPrefixRoute('/_webhooks', [
        webapp2.Route('/thonkify', webhooks.ThonkifyEndpoint),
        webapp2.Route('/debug', tasks.LogParams)
    ]),
    (r'.*', tasks.NotFound),
], debug=app.config.DEBUG, config=config))


def main():
    logging.getLogger().setLevel(logging.INFO)
    application.run()


if __name__ == "__main__":
    main()
# NOTICE: THIS FILE HAS BEEN MODIFIED BY MOBICAGE NV IN ACCORDANCE WITH THE APACHE LICENSE VERSION 2.0
# Copyright 2018 GIG Technology NV
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# @@license_version:1.5@@

import webapp2
from google.appengine.ext import ndb

from framework.handlers.login import AuthenticationRequiredHandler
from framework.utils.plugins import get_handlers_for_auth, Handler
from framework.wsgi import WSGIApplication, AUTH_LVL_PRIVATE

handlers = [
    webapp2.Route('/login_required', AuthenticationRequiredHandler)
]
handlers.extend(get_handlers_for_auth(Handler.AUTH_AUTHENTICATED))

app = ndb.toplevel(WSGIApplication(handlers, name="main_authenticated", auth=AUTH_LVL_PRIVATE))
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from google.appengine.api import users
from google.appengine.ext import ndb
import webapp2


class Account(ndb.Model):
    view_counter = ndb.IntegerProperty()


class MyRequestHandler(webapp2.RequestHandler):
    @ndb.toplevel
    def get(self):
        acct = Account.get_by_id(users.get_current_user().user_id())
        acct.view_counter += 1
        acct.put_async()  # Ignoring the Future this returns

        # ...read something else from Datastore...

        self.response.out.write('Content of the page')


# This is actually redundant, since the `get` decorator already handles it, but
# for demonstration purposes, you can also make the entire app toplevel with
# the following.
app = ndb.toplevel(webapp2.WSGIApplication([('/', MyRequestHandler)]))
Example #32
0
                              vote=t['votes'],
                              comment=t['comments'],
                              author=t['author'],
                              disp_topic=t['disp_topic'],
                              topic_type=str(t['topic_type']),
                              utime=datetime.strptime(t['utime'],
                                                      '%m/%d/%Y %H:%M:%S'),
                              tags=tags)
                topics.append(topic)
                # counting += 1
            ndb.put_multi_async(topics)
            # task.put_async()
            looping += 1
            last_id = str(item['last_id_current_page'])
            payload[0] = (payload[0][0], last_id)
            res = requests.post(url, payload, headers=headers)
            j = res.json()
            item = j['item']


class TestHandler(webapp2.RequestHandler):
    def post(self):
        pass


app = ndb.toplevel(
    webapp2.WSGIApplication(
        [('/collect_topics/forum', CollectTopicsForumHandler),
         ('/collect_topics/tag', CollectTopicsTagHandler),
         ('/test', TestHandler)],
        debug=True))
# ndb.toplevel makes sure that all *_async() functions that we didn't wait for
# with get_result() finish before the handler returns.
application = ndb.toplevel(
    webapp2.WSGIApplication(
        [
            ('/rest/ratingHistory', RatingHistoryHandler),
            ('/rest/rate', RateHandler),
            ('/rest/extendedPageDetails', ExtendedPageDetailsHandler),
            ('/rest/recommendations', RecommendationsHandler),
            ('/rest/pastRecommendations', PastRecommendationsHandler),
            ('/rest/markUnread', MarkUnreadHandler),
            ('/rest/popularPages', PopularPagesHandler),
            ('/rest/deleteRating', DeleteRatingHandler),
            ('/rest/getConfig', GetConfigHandler),
            ('/rest/categories', CategoriesHandler),
            ('/rest/addCategory', AddCategoryHandler),
            ('/rest/renameCategory', RenameCategoryHandler),
            ('/rest/removeCategory', RemoveCategoryHandler),
            ('/rest/suggestCategory', SuggestCategoryHandler),
            ('/rest/setPageCategory', SetPageCategoryHandler),
            ('/rest/requestExportRatings', RequestExportRatingsHandler),
            ('/rest/exportStatus', ExportStatusHandler),
            ('/rest/deleteAccount', DeleteAccountHandler),
            # Admin actions.
            ('/rest/admin/actions', AdminActionsHandler),
            ('/rest/admin/executeAction', AdminExecuteActionHandler),
            ('/download_history', DownloadHistoryHandler),
            ('/', MainPageHandler)
        ],
        debug=config.IsDev()))
Example #34
0
 def decorator(fn):
   fn = catch_errors(fn, response_message_class)
   fn = endpoints_decorator(fn)
   fn = ndb.toplevel(fn)
   return fn
Example #35
0
        # central tree end #

        # if not 'COE' in analyze_value_map:
        #     return 'forms/analyze/coe.html'

        # COE = analyze_value_map['COE']

        # if COE == VALUE_UP:
        #     return 'forms/result/ahz.html'

        # if not 'RBC' in analyze_value_map:
        #     return 'forms/analyze/rbc.html'

        # RBC = analyze_value_map['RBC']

        # if RBC == VALUE_DOWN:
        #     return 'forms/result/aplastich_anemia.html'

        return 'forms/result/unknown.html'

application = ndb.toplevel(webapp2.WSGIApplication([
    ('/', HomePage),
    ('/pacients', PacientsPage),
    ('/stats', AppPage),
    ('/cabinet', AppPage),
    ('/pacient-create', PacientCreate),
    ('/pacient/(\d+)', PacientPage),
    ('/save-analyze', SaveAnalyzePage),
    ('/remove-analyze/(\d+)/(\w+)', RemoveAnalyzePage),
], debug=True))
Example #36
0
File: app.py Project: cage1016/test
from handler.dumps import DumperHandler


class TasksHandler(webapp2.RequestHandler):
    def get(self):
        logging.info("Get request to notification page.")
        self.response.write("Welcome to the tasks module.")


routes = [
    (r'/tasks/parsecsv', ParseCSVHandler),
    (r'/tasks/schedule', ScheduleHandler),
    (r'/tasks/delete_resources', GCSResourcesDeleteHandler),
    (r'/tasks/delete_schedule', ScheduleDeleteHandler),
    (r'/tasks/check_schedule_delete', ScheduleDeleteCheckHandler),
    (r'/tasks/retry_check', RetryCheckHandler),

    # (r'/tasks/recipient_queue_data_health_check', RecipientQueueDataHealthCheckHandler),
    webapp2.Route('/tasks/_cb/deferred/<module>/<name>',
                  tasks.DeferredHandler),

    # debug only
    (r'/tasks/clear_retry', ClearReTryHandler),
    (r'/tasks/clear_recipient_queue_data', ClearRecipientQueueDataHandler),
    (r'/tasks/dump', DumperHandler),
    (r'/.*', TasksHandler)
]

router = ndb.toplevel(webapp2.WSGIApplication(routes, debug=True))
Example #37
0

application = ndb.toplevel(webapp2.WSGIApplication([
  webapp2.Route('/', app.views.user.Landing, 'landing'),

  webapp2.Route('/login',  app.views.simple.Login,  'login'),
  webapp2.Route('/logout', app.views.simple.Logout, 'logout'),

  webapp2.Route('/signup', app.views.user.Signup, 'signup'),
  webapp2.Route('/guidelines', app.views.user.Guidelines, 'guidelines'),

  webapp2.Route('/missions/create', app.views.mission.Create, 'create_mission'),
  webapp2.Route('/missions/<guid>', app.views.mission.View, 'view_mission'),
  webapp2.Route('/missions/<guid>/update', app.views.mission.Update, 'update_mission'),

  webapp2.Route('/queue', app.views.mission.Queue, 'mission_queue'),

  webapp2.Route('/manage', app.views.manage.Root, 'manage_root'),
  webapp2.Route('/manage/', app.views.manage.Root, 'manage_root_s'),
  webapp2.Route('/manage/users', app.views.manage.Users, 'manage_users'),
  webapp2.Route('/manage/users/', app.views.manage.Users, 'manage_users_s'),

  webapp2.Route('/_cron/reap-empty-missions', app.cron.ReapEmptyMissions, 'cron_reap'),

  #webapp2.Route('/_tasks/geocode-mission', app.tasks.GeocodeMission, 'task_geocode'),
  webapp2.Route('/_tasks/reap-empty-missions', app.tasks.ReapEmptyMissions, 'task_reap'),

  (r'.*', app.views.simple.NotFound),
], debug=DEBUG_MODE))

Example #38
0
		if user:
			ndb.Key(urlsafe=userUrlSafe).delete()
			self.redirect('/customers')
		else:
			self.redirect('/customers')


app = ndb.toplevel(webapp2.WSGIApplication([
    ('/', DashboardHandler),
    ('/stores/delete/(.*?)', StoresDeleteHandler),
    ('/users/delete/(.*?)', DbUsersDeleteHandler),
    ('/customers/delete/(.*?)', CustomersDeleteHandler),
    ('/stores', StoresHandler),
    ('/users', DbUsersHandler),
    ('/customers', CustomersHandler),
    ('/items', ItemsHandler),
    ('/transactions/invoices', TransactionInvoicesHandler),
    ('/transactions/loans', TransactionLoansHandler),
    ('/transactions/receipts', TransactionReceiptsHandler),
    ('/transactions/redeems', TransactionRedeemsHandler),
    ('/transactions/stocks', TransactionStocksHandler),
    ('/transactions', TransactionsHandler),
    ('/reports', ReportsHandler),
    ('/settings', SettingsHandler),
], debug=True))






Example #39
0
"""Main.py for twittertorss app."""

import logging
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

# Force Django to reload its settings.
from django.conf import settings
from django.core.handlers import wsgi
from django.core import signals
from django import db
from django import dispatch
from google.appengine.ext import ndb


def log_exception(*args, **kwargs):
  logging.exception('Exception in request:')

signal = dispatch.Signal()

# Log errors.
signal.connect(log_exception, signals.got_request_exception)

# Unregister the rollback event handler.
signal.disconnect(db._rollback_on_exception, signals.got_request_exception)

# Wrapping the WSGI application in ndb.toplevel ensures that all async
# operations complete before returning.
app = ndb.toplevel(wsgi.WSGIHandler())
Example #40
0
from web import errors
from lib import basehandler

app = webapp2.WSGIApplication(debug=basehandler.IS_DEV, config=config.webapp2_config, routes=routes.get_routes())


# If you want dynamic custom error handlers use below
# or just comment it out. This is useful for gracefully showing errors to users
# with all your layout in place
if not basehandler.IS_BACKEND:

    # defined custom error handlers
    class Webapp2HandlerAdapter(webapp2.BaseHandlerAdapter):

        def __call__(self, request, response, exception):
            request.route_args = {
                'exception': exception
            }
            logging.exception(exception)
            handler = self.handler(request, response)

            return handler.get()

    app.error_handlers[403] = Webapp2HandlerAdapter(errors.Error403Handler)
    app.error_handlers[404] = Webapp2HandlerAdapter(errors.Error404Handler)
    app.error_handlers[503] = Webapp2HandlerAdapter(errors.Error503Handler)
    app.error_handlers[500] = Webapp2HandlerAdapter(errors.Error500Handler)

# Make sure all ndb async futures finish
app = ndb.toplevel(app)
Example #41
0
template_path = os.path.dirname(__file__) + '/templates'
locale_path = os.path.dirname(__file__) + '/locale'

logging.info('setting template path to %s' % template_path)

webapp2_config['webapp2_extras.jinja2'] = {
    'template_path': template_path,
    'filters': jinja_filters,
    'environment_args': jinja_environment_args
}

webapp2_config['webapp2_extras.i18n'] = {
    'translations_path': locale_path,
    'default_locale': 'en',
    'default_timezone': 'America/Montreal',
}

webapp2_config['webapp2_extras.sessions'] = {
    'secret_key': '82374y6ii899hy8-89308847-21u9x676',
}

webapp2_config['webapp2_extras.auth'] = {
    'user_model': User,
}

routes = create_routes()

application = ndb.toplevel(
    webapp2.WSGIApplication(routes, debug=True, config=webapp2_config))
Example #42
0
# -*- coding:utf-8 -*-

import os
import webapp2

from google.appengine.ext import ndb

from naziscore.handlers import (
    RefreshOutdatedProfileHandler,
    CleanupRepeatedProfileHandler,
)

DEBUG = os.environ.get('SERVER_SOFTWARE', '').startswith('Dev')

app = webapp2.WSGIApplication([
    webapp2.Route('/_ah/cron/refresh',
                  RefreshOutdatedProfileHandler,
                  name='calculation_handler_legacy_v1'),
    webapp2.Route('/_ah/cron/cleanup',
                  CleanupRepeatedProfileHandler,
                  name='cleanup_handler_v1'),
],
                              debug=DEBUG)

app = ndb.toplevel(app)
Example #43
0
        self.response.headers['Content-Type'] = 'text/plain'

        if not users.is_current_user_admin():
            self.response.set_status(401)
            self.response.out.write('unauthorized')
            return

        user = users.get_current_user()
        desc = user.email()
        token = auth.create_auth_token(desc)

        lines = [
            'save the following to .fileset.json:',
            '',
            '{"token": "%s"}' % token,
            '',
        ]
        payload = '\n'.join(lines)
        self.response.out.write(payload)


app = ndb.toplevel(webapp2.WSGIApplication([
    webapp2.Route('/_fs/api/blob.exists', handler=BlobExistsHandler),
    webapp2.Route('/_fs/api/blob.upload', handler=BlobUploadHandler),
    webapp2.Route('/_fs/api/branch.get_manifest', handler=BranchGetManifestHandler),
    webapp2.Route('/_fs/api/branch.set_manifest', handler=BranchSetManifestHandler),
    webapp2.Route('/_fs/api/cron.timed_deploy', handler=CronTimedDeployHandler),
    webapp2.Route('/_fs/api/manifest.upload', handler=ManifestUploadHandler),
    webapp2.Route('/_fs/token', handler=TokenHandler),
]))
Example #44
0
        for timeseries in data['timeseries']:
            points = []
            fields = []
            for point in timeseries['points']:
                points.append(
                    Point(time=float(point['time']),
                          value=float(point['value'])))
            for field in timeseries['fields']:
                fields.append(Field(key=field['key'], value=field['value']))
            tsList.append(
                TimeSeries(points=points,
                           fields=fields,
                           metric=timeseries['metric']))
        futures = [timeseries_query(t) for t in tsList]
        ndb.Future.wait_all(futures)
        for future in futures:
            future.get_result()
        return message_types.VoidMessage()


handlers = [
    ('/tasks/clean_outdated_graphs', CronHandler),
    ('/timeseries_update', TimeSeriesHandler),
]

WEBAPP = add_appstats(webapp2.WSGIApplication(handlers, debug=True))

APPLICATION = add_appstats(
    ndb.toplevel(endpoints.api_server([ConsoleAppApi, UIApi,
                                       config.ConfigApi])))
Example #45
0
			self.response.out.write("<em>* Indicates a Type with multiple parent Types</em>")
			global treeline
			if not HelpCache.get('Tree'):
				logging.debug("HelpCache MISS: Tree")
				self.getTypesAndTree()
			self.response.out.write("<table class=\"type-table\">\n")
			if not HelpCache.get('DataType'):
				treeline = ""
				walkTree("http://schema.org/DataType",0,True)
				HelpCache['DataType'] = treeline
			self.response.out.write(HelpCache['DataType'])
			self.response.out.write("</table>\n")
			self.response.out.write("<table class=\"type-table\">\n")
			if not HelpCache.get('Thing'):
				treeline = ""
				walkTree("http://schema.org/Thing",0,True)
				HelpCache['Thing'] = treeline
			self.response.out.write(HelpCache.get('Thing'))
			self.response.out.write("</table>\n")
		
		else:
			self.error(404)
			self.response.out.write("<h3>Sorry, the page you requested isn't available.</h2>")
			self.response.out.write("<h3>You can <a href='/schemas'>browse the Schemas page </a> as a way to get started using the site.</h3>")

		self.response.out.write("<br/><hr width='80%'/>")
		self.response.out.write(api.ShowUnit.getVersion())
		self.response.out.write(headers.footers)

app = ndb.toplevel(webapp2.WSGIApplication([("/(.*)", MainPage)]))
Example #46
0
class SendActivity(webapp2.RequestHandler):
    def get(self):
        for ui in UserInfo.query():
            if ui.daily:
                deferred.defer(util.daily_digest, ui.key)


class cron_trash(webapp2.RequestHandler):
    def get(self):
        delta = datetime.timedelta(days=7)
        now = datetime.datetime.now()
        period = now - delta
        bmq = Bookmarks.query(Bookmarks.trashed == True,
                              Bookmarks.data < period)
        ndb.delete_multi([bm.key for bm in bmq])


app = ndb.toplevel(webapp2.WSGIApplication([
    routes.RedirectRoute('/admin/', AdminPage, name='Admin', strict_slash=True),
    routes.PathPrefixRoute('/admin', [
        webapp2.Route('/digest', SendDigest),
        webapp2.Route('/activity', SendActivity),
        webapp2.Route('/check', CheckFeeds),
        webapp2.Route('/cron_trash', cron_trash),
        ])
    ], debug=util.debug, config=util.config))

if __name__ == "__main__":
    app.run()
Example #47
0
class ContactHandler(BaseHandler):
    def get(self):
        self.render('templates/contact.jinja2')


class TermsHandler(BaseHandler):
    def get(self):
        self.render('templates/terms.jinja2')


class SitemapHandler(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/xml'
        template_values = {
        }
        template = JINJA_ENVIRONMENT.get_template('templates/sitemap.xml')
        self.response.write(template.render(template_values))


app = ndb.toplevel(webapp2.WSGIApplication([
                                               ('/', MainHandler),
                                               ('/tests', TestHandler),
                                               ('/privacy', PrivacyHandler),
                                               ('/terms', TermsHandler),
                                               # ('/about', AboutHandler),
                                               ('/contact', ContactHandler),
                                               ('/sitemap', SitemapHandler),

                                           ] + gameon.routes, debug=ws.debug, config=config))
Example #48
0
                logging.debug("HelpCache MISS: Tree")
                self.getTypesAndTree()
            self.response.out.write("<table class=\"type-table\">\n")
            if not HelpCache.get('DataType'):
                treeline = ""
                walkTree("http://schema.org/DataType", 0, True)
                HelpCache['DataType'] = treeline
            self.response.out.write(HelpCache['DataType'])
            self.response.out.write("</table>\n")
            self.response.out.write("<table class=\"type-table\">\n")
            if not HelpCache.get('Thing'):
                treeline = ""
                walkTree("http://schema.org/Thing", 0, True)
                HelpCache['Thing'] = treeline
            self.response.out.write(HelpCache.get('Thing'))
            self.response.out.write("</table>\n")

        else:
            self.error(404)
            self.response.out.write(
                "<h3>Sorry, the page you requested isn't available.</h2>")
            self.response.out.write(
                "<h3>You can <a href='/schemas'>browse the Schemas page </a> as a way to get started using the site.</h3>"
            )

        self.response.out.write("<br/><hr width='80%'/>")
        self.response.out.write(api.ShowUnit.getVersion())
        self.response.out.write(headers.footers)

app = ndb.toplevel(webapp2.WSGIApplication([("/(.*)", MainPage)]))
Example #49
0
application = ndb.toplevel(webapp2.WSGIApplication(
    [('/', MainPage),

     ### /appointment/make/POST_DATA
     ('/appointment/make/', MakeAppointment),

     ### /appointment/query/timeline/DOCTOR/DATE
     ('/appointment/query/timeline/(.*)/(.*)', ShowAvailableTimeline),

     ### /api/query/token
     ('/api/query/(.*)', GetPatientInfo),

     ### mockup
     ('/mockup', MockData),

     ### /snail_admin
     ('/snail_admin', MainAdmin),

     ### /snail_admin/appointment/modify/urlsafe_entity_key/appointment_status/value
     ('/snail_admin/appointment/modify/(.*)/(.*)/(.*)', ModifyAppointment),

     ### /snail_admin/search/patient/email/[email protected]
     ('/snail_admin/search/patient/(.*)', GetPatient),

     ### /snail_admin/modify/patient/check_in/patient_uuid
     ('/snail_admin/modify/patient/check_in/(.*)', ModifyPatientCheckIn),

     ### /snail_admin/create/patient
     ('/snail_admin/create/patient', AddPatient),


    ],
    debug=True, config=session_config))
Example #50
0
    def __unicode__(self):
        return (u'%s: %s' % (self.designator, self.summary))[:40]

    def get_absolute_url(self):
        return "/tasks/o%s/" % self.key.id()

    @property
    def designator(self):
        return 'o%s' % self.key.id()


class TasklistHandler(gaetk.handler.BasicHandler):
    def get(self):
        user = users.get_current_user()
        tasks = Task.query().fetch(100)
        Task(account=user, summary='Software screiben', description='Unklar', to='*****@*****.**').put()
        self.render(dict(title=u"Tasks",
                         tasks=tasks,
                         ), 'taskmaster2/main.html')

urls = [('^/tasks/$', TasklistHandler)]

app = ndb.toplevel(webapp.WSGIApplication(urls))


def main():
    util.run_wsgi_app(app)

if __name__ == '__main__':
    main()
Example #51
0
schemasInitialized = False


def read_schemas():
    """Read/parse/ingest schemas from data/*.rdfa. Also alsodata/*examples.txt"""
    import os.path
    import glob
    global schemasInitialized
    if (not schemasInitialized):
        files = glob.glob("data/*.rdfa")
        file_paths = []
        for f in files:
            file_paths.append(full_path(f))

        parser = parsers.MakeParserOfType('rdfa', None)
        items = parser.parse(file_paths)

        files = glob.glob("data/*examples.txt")
        example_contents = []
        for f in files:
            example_content = read_file(f)
            example_contents.append(example_content)
        parser = parsers.ParseExampleFile(None)
        parser.parse(example_contents)
        schemasInitialized = True


read_schemas()

app = ndb.toplevel(webapp2.WSGIApplication([("/(.*)", ShowUnit)]))
Example #52
0
#!/usr/bin/env python

from sys import path
from os import listdir
path.append('./')

import webapp2
from google.appengine.ext import ndb

from lib.utils import DEBUG


routes = []
for file_name in listdir('api'):
    if not file_name.startswith('.') and file_name.endswith('.py') and file_name != '__init__.py':
        api_name = file_name[:-3]
        api_module = __import__('api.%s' % api_name).__getattribute__(api_name)
        routes += api_module.routes

app = ndb.toplevel(webapp2.WSGIApplication(routes, debug=DEBUG))
Example #53
0
#!/usr/bin/python2.7

""" Web module
"""

__author__ = '[email protected] (Abhijit Kalamkar)'

import webapp2
from google.appengine.ext import ndb

from web.chart import EventChart
from web.poll import Poll

app = ndb.toplevel(webapp2.WSGIApplication([
    ('/chart/events', EventChart),
    ('/poll/.*', Poll)
], debug=False))
Example #54
0
        self.response.write(self.AddCachedText(node, self.outputStrings))


def read_file (filename):
    import os.path
    folder = os.path.dirname(os.path.realpath(__file__))
    file_path = os.path.join(folder, filename)
    strs = []
    for line in open(file_path, 'r').readlines():
        strs.append(line)
    return "".join(strs)

schemasInitialized = False

def read_schemas():
    import os.path
    global schemasInitialized
    if (not schemasInitialized):
        schema_content = read_file('data/schema.rdfa')
        example_content = read_file('data/examples.txt')
        ft = 'rdfa'
        parser = parsers.MakeParserOfType(ft, None)
        items = parser.parse(schema_content)
        parser = parsers.ParseExampleFile(None)
        parser.parse(example_content)
        schemasInitialized = True

read_schemas()

app = ndb.toplevel(webapp2.WSGIApplication([("/(.*)", ShowUnit)]))
Example #55
0
 def inner(self, *argv, **kwargv):
   self.set_session_store()
   try:
     ndb.toplevel(func)(self, *argv, **kwargv)
   finally:
     self.session_store.save_sessions(self.response)
Example #56
0
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Login'

        # create dictionary that we pass to the template
        template_values = {
            'user': current_user,
            'location_reports': location_reports,
            'url': url,
            'url_linktext': url_linktext,
            'all_tag_names': json.dumps(all_tag_names),
            # 'addresses': json.dumps(addresses)
            'location_reports_list': json.dumps(location_reports_lists)
        }
        template = JINJA_ENVIRONMENT.get_template('views/map.html')
        self.response.write(template.render(template_values))


# [START app]
app = ndb.toplevel(webapp2.WSGIApplication([
    ('/map', MapPage),
], debug=True))


def main():
    app.run()


if __name__ == "__main__":
    main()
# [END app]
Example #57
0
import urls

allowed = (
    re.compile("^.*$"),  # Match a regex
)

cors = CrossOriginResourceSharing(app)
cors.set_allowed_origins(*allowed)
# GAEMiniProfiler(app)

# Flask-DebugToolbar (only enabled when DEBUG=True)
# toolbar = DebugToolbarExtension(app)

ADNTokenAuthMiddleware(app)

# Werkzeug Debugger (only enabled when DEBUG=True)
if app.debug:
    app.wsgi_app = DebuggedApplication(app.wsgi_app, evalex=True)
else:
    import logging
    # import email_logger
    root_logger = logging.getLogger()
    root_logger.setLevel(logging.INFO)
    #requests_log = logging.getLogger("requests")
    #requests_log.setLevel(logging.WARNING)
    #email_logger.register_logger(app.config['ADMIN_EMAIL'])

app.wsgi_app = recording.appstats_wsgi_middleware(app.wsgi_app)

app.__call__ = ndb.toplevel(app.__call__)