Example #1
0
 def get(self, path):
     try:
         if path == '/robots.txt':
             return webapp2.Response(
                 template.get(configuration.get_robots_txt()))
         elif path == '/favicon.ico':
             return webapp2.Response(configuration.get_favicon_ico())
         else:
             response = webapp2.Response(
                 unicode(section.get_section(self, path)))
             response.headers['Connection'] = 'Keep-Alive'
             return response
     except Exception as inst:
         if inst[0] == 'Redirect':
             return self.redirect(str(inst[1]))
         elif inst[0] == 'SendFileBlob':
             response = webapp2.Response(inst[1])
             if inst[2]: response.content_type = str(inst[2])
             response.headers['Connection'] = 'Keep-Alive'
             response.headers['Date'] = datetime.utcnow().strftime(
                 "%a, %d %b %Y %H:%M:%S GMT")
             last_modified = datetime.utcnow(
             )  # TODO: Store when this actually happened
             response.headers['Last-Modified'] = last_modified.strftime(
                 "%a, %d %b %Y %H:%M:%S GMT")
             response.headers['Expires'] = (
                 last_modified +
                 timedelta(8)).strftime("%a, %d %b %Y %H:%M:%S GMT")
             response.cache_control.no_cache = None
             response.cache_control.public = True
             response.cache_control.max_age = 604800000  # One week
             return response
         elif inst[0] == 'NotFound':
             err = 404
             main = 'Page not found'
         elif inst[0] == 'BadRequest':
             err = 400
             main = 'Bad Request'
         elif inst[0] == 'Forbidden':
             err = 403
             main = 'Forbidden'
         elif inst[0] == 'AccessDenied':
             err = 403
             main = 'Access Denied'
         elif configuration.debug_mode():
             err = 400
             main = 'RouterError: ' + unicode(
                 inst) + '<div class="traceback">' + traceback.format_exc(
                 ).replace('\n', '<br><br>') + '</div>'
         else:
             err = 400
             main = 'An error has occurred.'
         default_section = section.get_section(None, '')
         response = webapp2.Response(
             unicode(
                 template.html(
                     default_section,
                     '<div class="status error">' + main + '</div>')))
         response.set_status(err)
         return response
Example #2
0
 def get(self, path):
     try:
         if path == '/robots.txt':
             return webapp2.Response(template.get(configuration.get_robots_txt()))
         elif path == '/favicon.ico':
             return webapp2.Response(configuration.get_favicon_ico())
         else:
             response = webapp2.Response(unicode(section.get_section(self, path)))
             response.headers['Connection'] = 'Keep-Alive'
             return response
     except Exception as inst:
         if inst[0] == 'Redirect':
             return self.redirect(str(inst[1]))
         elif inst[0] == 'SendFileBlob':
             response = webapp2.Response(inst[1])
             if inst[2]: response.content_type = str(inst[2])
             response.headers['Connection'] = 'Keep-Alive'
             response.headers['Date'] = datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT")
             last_modified = datetime.utcnow() # TODO: Store when this actually happened
             response.headers['Last-Modified'] = last_modified.strftime("%a, %d %b %Y %H:%M:%S GMT")
             response.headers['Expires'] = (last_modified + timedelta(8)).strftime("%a, %d %b %Y %H:%M:%S GMT")
             response.cache_control.no_cache = None
             response.cache_control.public = True
             response.cache_control.max_age = 604800000 # One week
             return response
         elif inst[0] == 'NotFound':
             err = 404
             main = 'Page not found'
         elif inst[0] == 'BadRequest':
             err = 400
             main = 'Bad Request'
         elif inst[0] == 'Forbidden':
             err = 403
             main = 'Forbidden'
         elif inst[0] == 'AccessDenied':
             err = 403
             main = 'Access Denied'
         elif configuration.debug_mode():
             err = 400
             main = 'RouterError: ' + unicode(inst) + '<div class="traceback">' + traceback.format_exc().replace('\n', '<br><br>') + '</div>'
         else:
             err = 400
             main = 'An error has occurred.'
         default_section = section.get_section(None, '')
         response = webapp2.Response(unicode(template.html(default_section, '<div class="status error">' + main + '</div>')))
         response.set_status(err)
         return response
Example #3
0
def parse_content(content, css_minify=False, namespace=None):
    default_section = section.get_section(None, '')
    if namespace:
        content = content.replace(
            NAMESPACE_REPLACER, '/%s/themes/get/%s/' %
            (default_section.path, namespace.replace(' ', '%20')))
    content = (content if not css_minify else cssmin(content)).strip()
    return content
Example #4
0
def parse_content(content, css_minify=False, namespace=None):
    default_section = section.get_section(None, '')
    if namespace: content = content.replace(NAMESPACE_REPLACER, '/%s/themes/get/%s/' % (default_section.path, namespace.replace(' ', '%20')))
    content = (content if not css_minify else cssmin(content)).strip()
    return content