Exemplo n.º 1
0
def create_handler(app):
    h_caching = Caching(app.cache, duration=app.cfg.CACHE_TIME)

    return cases(
        static_files(app.cfg.STATIC_DIR, app.cfg.STATIC_URL),
        static_files(app.cfg.FRONT_MEDIA_DIR, app.cfg.MEDIA_URL),
        h_caching | cache(enable=app.cfg.CACHE_ENABLED) | cases(
            prefix('/en') | app.i18n.handler('en') | h_index,
            app.i18n.handler('ru') | h_index,
        ),
        HTTPNotFound,
    )
Exemplo n.º 2
0
def create_handler(app):
    h_caching = Caching(app.cache, duration=app.cfg.CACHE_TIME)

    return cases(
        static_files(app.cfg.STATIC_DIR, app.cfg.STATIC_URL),
        static_files(app.cfg.FRONT_MEDIA_DIR, app.cfg.MEDIA_URL),

        h_caching | cache(enable=app.cfg.CACHE_ENABLED) | cases(
            prefix('/en') | app.i18n.handler('en') | h_index,
            app.i18n.handler('ru') | h_index,
        ),
        HTTPNotFound,
)
Exemplo n.º 3
0
    def test_serve(self):
        static = web.static_files(self.root, self.url)
        app = TA(Application(static))

        with open(os.path.join(self.root, 'x.html'), 'w') as f:
            f.write('x')

        self.assertEqual(app.get('/media/x.html').body, 'x')
        self.assertEqual(app.get('/media/x.html').content_type, 'text/html')
        app.get('/media/404.txt', status=404)
        app.get('/nomedia/x.txt', status=404)
Exemplo n.º 4
0
 def test_repr(self):
     # for coverage
     '%r' % web.WebHandler()
     '%r' % web.cases()
     '%r' % web.request_filter(lambda e, d, n: None)
     '%r' % web.match('/', 'index')
     '%r' % web.method('GET')
     '%r' % web.static_files('/prefix')
     '%r' % web.prefix('/prefix')
     '%r' % web.subdomain('name')
     '%r' % web.namespace('name')
Exemplo n.º 5
0
    def test_serve(self):
        static = web.static_files(self.root, self.url)
        app = TA(Application(static))

        with open(os.path.join(self.root, 'x.html'), 'w') as f:
            f.write('x')

        self.assertEqual(app.get('/media/x.html').body, b'x')
        self.assertEqual(app.get('/media/x.html').content_type, 'text/html')
        app.get('/media/404.txt', status=404)
        app.get('/nomedia/x.txt', status=404)
Exemplo n.º 6
0
 def test_repr(self):
     # for coverage
     '%r' % web.WebHandler()
     '%r' % web.cases()
     '%r' % web.request_filter(lambda e, d, n: None)
     '%r' % web.match('/', 'index')
     '%r' % web.method('GET')
     '%r' % web.static_files('/prefix')
     '%r' % web.prefix('/prefix')
     '%r' % web.subdomain('name')
     '%r' % web.namespace('name')
Exemplo n.º 7
0
 def test_repr(self):
     # for coverage
     "%r" % web.WebHandler()
     "%r" % web.cases()
     "%r" % web.request_filter(lambda e, d, n: None)
     "%r" % web.match("/", "index")
     "%r" % web.method("GET")
     "%r" % web.static_files("/prefix")
     "%r" % web.prefix("/prefix")
     "%r" % web.subdomain("name")
     "%r" % web.namespace("name")
Exemplo n.º 8
0
def create_handler(app):
    h_caching = Caching(app.cache, duration=app.cfg.CACHE_TIME)
    h_sections_ru = app.sections['ru'].handler()
    h_sections_en = app.sections['en'].handler()

    return cases(
        static_files(app.cfg.STATIC_DIR, app.cfg.STATIC_URL),
        static_files(app.cfg.FRONT_MEDIA_DIR, app.cfg.MEDIA_URL),
        h_caching | cache(enable=app.cfg.CACHE_ENABLED) | cases(
            prefix('/en') | app.i18n.handler('en') | cases(
                match('/', name='index') | h_index,
                h_sections_en,
            ),
            app.i18n.handler('ru') | cases(
                match('/', name='index') | h_index,
                h_sections_ru,
            ),
        ),
        HTTPNotFound,
    )
Exemplo n.º 9
0
def create_handler(app):
    h_caching = Caching(app.cache, duration=app.cfg.CACHE_TIME)
    h_sections_ru = app.sections['ru'].handler()
    h_sections_en = app.sections['en'].handler()

    return cases(
        static_files(app.cfg.STATIC_DIR, app.cfg.STATIC_URL),
        static_files(app.cfg.FRONT_MEDIA_DIR, app.cfg.MEDIA_URL),

        h_caching | cache(enable=app.cfg.CACHE_ENABLED) | cases(
            prefix('/en') | app.i18n.handler('en') | cases(
                match('/', name='index') | h_index,
                h_sections_en,
            ),
            app.i18n.handler('ru') | cases(
                match('/', name='index') | h_index,
                h_sections_ru,
            ),
        ),
        HTTPNotFound,
    )
Exemplo n.º 10
0
    def test_secure(self):
        static = web.static_files(self.root, self.url)
        app = TA(Application(static))

        with open(os.path.join(self.root, 'x.html'), 'w') as f:
            f.write('x')

        with open(os.path.join(self.xroot, 'x.html'), 'w') as f:
            f.write('secret')

        os.mkdir(os.path.join(self.root, 'x'))

        with open(os.path.join(self.root, 'x/y.html'), 'w') as f:
            f.write('y')

        app.get('/media/x\\y.html', status=404)
        app.get('/media/z/../x.html', status=404)
        app.get('/media/../x.html', status=404)
        app.get('/media/', status=404)
        app.get('/media/x', status=404)
        app.get('/media/x/', status=404)
Exemplo n.º 11
0
    def test_secure(self):
        static = web.static_files(self.root, self.url)
        app = TA(Application(static))

        with open(os.path.join(self.root, 'x.html'), 'w') as f:
            f.write('x')

        with open(os.path.join(self.xroot, 'x.html'), 'w') as f:
            f.write('secret')

        os.mkdir(os.path.join(self.root, 'x'))

        with open(os.path.join(self.root, 'x/y.html'), 'w') as f:
            f.write('y')

        app.get('/media/x\\y.html', status=404)
        app.get('/media/z/../x.html', status=404)
        app.get('/media/../x.html', status=404)
        app.get('/media/', status=404)
        app.get('/media/x', status=404)
        app.get('/media/x/', status=404)
Exemplo n.º 12
0
    def test_reverse(self):
        static = web.static_files(self.root, self.url)
        reverse = static.url_for_static

        self.assertEqual(reverse('text.txt'), '/media/text.txt')
        self.assertEqual(reverse('//text.txt'), '/media/text.txt')
Exemplo n.º 13
0
    def test_reverse(self):
        static = web.static_files(self.root, self.url)
        reverse = static.url_for_static

        self.assertEqual(reverse('text.txt'), '/media/text.txt')
        self.assertEqual(reverse('//text.txt'), '/media/text.txt')
Exemplo n.º 14
0
# -*- coding: utf-8 -*-

import logging
from iktomi import web
from iktomi.templates import Template, BoundTemplate as BaseBoundTemplate
from iktomi.templates.jinja2 import TemplateEngine
from iktomi.utils.storage import storage_cached_property
from iktomi.utils import cached_property
#from jinja2 import Markup

import cfg


logger = logging.getLogger(__name__)

static = web.static_files('static')
jinja_loader = TemplateEngine(cfg.TEMPLATES)
template_loader = Template(engines={'html': jinja_loader},
                           *cfg.TEMPLATES)

class Environment(web.AppEnvironment):
    cfg = cfg

    @cached_property
    def url_for(self):
        return self.root.build_url

    @cached_property
    def url_for_static(self):
        return static.construct_reverse()
Exemplo n.º 15
0
# -*- coding: utf-8 -*-

import logging
from iktomi import web
from iktomi.unstable.db.files import FileManager
from iktomi.templates import Template, BoundTemplate as BaseBoundTemplate
from iktomi.templates.jinja2 import TemplateEngine
from iktomi.utils.storage import storage_cached_property
from iktomi.utils import cached_property
#from jinja2 import Markup

import cfg

logger = logging.getLogger(__name__)

static = web.static_files('static')
jinja_loader = TemplateEngine(cfg.TEMPLATES)
template_loader = Template(engines={'html': jinja_loader}, *cfg.TEMPLATES)
file_manager = FileManager(cfg.FORM_TEMP, cfg.MEDIA_DIR, cfg.FORM_TEMP_URL,
                           cfg.MEDIA_URL)


class Environment(web.AppEnvironment):
    cfg = cfg
    file_manager = file_manager

    @cached_property
    def url_for(self):
        return self.root.build_url

    @cached_property