<commit_before>"""This module contains a tile cache handler."""

__author__ = '<NAME>'

# MOL imports
import cache

# Standard Python imports
import logging
import os
import urllib
import webapp2

# Google App Engine imports
from google.appengine.api import urlfetch
from google.appengine.ext.webapp.util import run_wsgi_app

if 'SERVER_SOFTWARE' in os.environ:
    PROD = not os.environ['SERVER_SOFTWARE'].startswith('Development')
else:
    PROD = True

app_id = os.environ['CURRENT_VERSION_ID']
if PROD:
    app_host = 'http://%s.map-of-life.appspot.com' % app_id
else:
    app_host = 'http://localhost:8080'

class TileHandler(webapp2.RequestHandler):
    """Request handler for cache requests."""

    def get(self):
        logging.info('request: %s' % self.request.url)
        tile_url = self.request.url.replace(app_host, 'http://mol.cartodb.com')
        logging.info('cdb request: %s' % tile_url)        
        tile_png = cache.get(tile_url, value_type='blob')
        if not tile_png:
            logging.info('Tile cache miss on %s' % tile_url)
            tile_png = urlfetch.fetch(tile_url, deadline=60).content
            cache.add(tile_url, tile_png, value_type='blob')
        self.response.headers["Content-Type"] = "image/png"
        self.response.out.write(tile_png)

class GridHandler(webapp2.RequestHandler):
    """Request handler for cache requests."""

    def get(self):
        logging.info('request: %s' % self.request.url)
        grid_url = self.request.url.replace(app_host, 'http://mol.cartodb.com')
        logging.info('cdb request: %s' % grid_url)        
        grid_json = cache.get(grid_url)
        if not grid_json:
            logging.info('Grid cache miss on %s' % grid_url)
            grid_json = urlfetch.fetch(grid_url, deadline=60).content
            cache.add(grid_url, grid_json)
        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(grid_json)                    
                    
application = webapp2.WSGIApplication(
    [('/tiles/[a-zA-Z0-9_-]+/[\d]+/[\d]+/[\d]+.png?.*', TileHandler),
     ('/tiles/[a-zA-Z0-9_-]+/[\d]+/[\d]+/[\d]+.grid.json?.*', GridHandler),], 
    debug=True)
         
def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()<commit_msg>Fix app id.<commit_after>"""This module contains a tile cache handler."""

__author__ = '<NAME>'

# MOL imports
import cache

# Standard Python imports
import logging
import os
import urllib
import webapp2

# Google App Engine imports
from google.appengine.api import urlfetch
from google.appengine.ext.webapp.util import run_wsgi_app

if 'SERVER_SOFTWARE' in os.environ:
    PROD = not os.environ['SERVER_SOFTWARE'].startswith('Development')
else:
    PROD = True

app_id = os.environ['CURRENT_VERSION_ID'].split('.')[0]
if PROD:
    app_host = 'http://%s.map-of-life.appspot.com' % app_id
else:
    app_host = 'http://localhost:8080'

class TileHandler(webapp2.RequestHandler):
    """Request handler for cache requests."""

    def get(self):
        tile_url = self.request.url.replace(app_host, 'http://mol.cartodb.com')
        tile_png = cache.get(tile_url, value_type='blob')
        if not tile_png:
            tile_png = urlfetch.fetch(tile_url, deadline=60).content
            cache.add(tile_url, tile_png, value_type='blob')
        self.response.headers["Content-Type"] = "image/png"
        self.response.out.write(tile_png)

class GridHandler(webapp2.RequestHandler):
    """Request handler for cache requests."""

    def get(self):
        grid_url = self.request.url.replace(app_host, 'http://mol.cartodb.com')
        grid_json = cache.get(grid_url)
        if not grid_json:
            grid_json = urlfetch.fetch(grid_url, deadline=60).content
            cache.add(grid_url, grid_json)
        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(grid_json)                    
                    
application = webapp2.WSGIApplication(
    [('/tiles/[a-zA-Z0-9_-]+/[\d]+/[\d]+/[\d]+.png?.*', TileHandler),
     ('/tiles/[a-zA-Z0-9_-]+/[\d]+/[\d]+/[\d]+.grid.json?.*', GridHandler),], 
    debug=True)
         
def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.14854048964218455, 'fraction_numerical': 0.007768361581920904, 'mean_word_length': 2.9710280373831774, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '765071', 'n_tokens_mistral': 1437, 'n_tokens_neox': 1396, 'n_words': 271}