예제 #1
0
def make_body(raw, headers=None, content_type=WWWFORM):
    if not isinstance(raw, bytes):
        raw = raw.encode('ascii')
    if headers is None:
        defaults = { FORMDATA: b"multipart/form-data; boundary=AaB03x",
                     WWWFORM: b"application/x-www-form-urlencoded" }
        headers = {b"Content-Type": defaults.get(content_type, content_type)}
    if not b'Content-Length' in headers:
        headers[b'Content-Length'] = str(len(raw)).encode('ascii')
    headers[b'Host'] = b'Blah'
    website = Website()
    request = Request(website, body=BytesIO(raw), headers=headers)
    return request.body
예제 #2
0
from pando.website import Website

website = Website()
예제 #3
0
    if env.log_dir is None:
        env.missing.append(var_name + ' (referenced by LOG_DIR)')

if env.malformed:
    plural = len(env.malformed) != 1 and 's' or ''
    print("=" * 42)
    print("Malformed environment variable%s:" % plural)
    for key, err in env.malformed:
        print("  {} ({})".format(key, err))

if env.missing:
    plural = len(env.missing) != 1 and 's' or ''
    keys = ', '.join([key for key in env.missing])
    print("Missing envvar{}: {}.".format(plural, keys))

website = Website()
website.env = env

# Common Jinja configuration
# ==========================


class CustomUndefined(StrictUndefined):
    __bool__ = __nonzero__ = lambda self: False

    def __str__(self):
        try:
            self._fail_with_undefined_error()
        except Exception as e:
            website.tell_sentry(e, {})
        return ''
예제 #4
0
if env.malformed:
    plural = len(env.malformed) != 1 and 's' or ''
    print("=" * 42)
    print("Malformed environment variable%s:" % plural)
    for key, err in env.malformed:
        print("  {} ({})".format(key, err))

if env.missing:
    plural = len(env.missing) != 1 and 's' or ''
    keys = ', '.join([key for key in env.missing])
    print("Missing envvar{}: {}.".format(plural, keys))

website = Website(
    changes_reload=env.aspen_changes_reload,
    project_root=env.aspen_project_root,
    show_tracebacks=env.aspen_show_tracebacks,
    www_root=env.aspen_www_root,
)
website.env = env

# Common Jinja configuration
# ==========================


class CustomUndefined(StrictUndefined):
    __bool__ = __nonzero__ = lambda self: False

    def __str__(self):
        try:
            self._fail_with_undefined_error()
        except Exception as e:
예제 #5
0
def test_basic():
    website = Website()
    expected = os.getcwd()
    actual = website.www_root
    assert actual == expected
예제 #6
0
"""Configuration script for the http://aspen.io/ website.
"""
import os
import os.path
from pando.configuration import parse
from pando.website import Website

distribution_root = os.path.dirname(__file__)
website = Website( www_root=os.path.join(distribution_root, 'doc')
                 , project_root=os.path.join(distribution_root, 'doc', '.aspen')
                  )
opts = {}

def add_stuff_to_request_context(website, dispatch_result):

    # Define some closures for generating image markup.
    # =================================================

    def translate(src):
        if src[0] != '/':
            rel = os.path.dirname(dispatch_result.match)[len(website.www_root):]
            src = '/'.join([rel, src])
        src = opts['base'] + src
        return src

    def img(src):
        src = translate(src)
        html = '<img src="%s" />' % src
        return html

    def screenshot(short, imgtype='png', href=''):
예제 #7
0
if env.malformed:
    plural = len(env.malformed) != 1 and 's' or ''
    print("=" * 42)
    print("Malformed environment variable%s:" % plural)
    for key, err in env.malformed:
        print("  {} ({})".format(key, err))

if env.missing:
    plural = len(env.missing) != 1 and 's' or ''
    keys = ', '.join([key for key in env.missing])
    print("Missing envvar{}: {}.".format(plural, keys))


website = Website(
    changes_reload=env.aspen_changes_reload,
    project_root=env.aspen_project_root,
    show_tracebacks=env.aspen_show_tracebacks,
    www_root=env.aspen_www_root,
)
website.env = env


# Common Jinja configuration
# ==========================

class CustomUndefined(StrictUndefined):
    __bool__ = __nonzero__ = lambda self: False

    def __str__(self):
        try:
            self._fail_with_undefined_error()
        except Exception as e:
예제 #8
0
def test_basic():
    website = Website(www_root='pando/www')
    expected = os.path.join(os.getcwd(), 'pando', 'www')
    actual = website.www_root
    assert actual == expected
예제 #9
0
"""Configuration script for the http://aspen.io/ website.
"""
import os
import os.path
from pando.configuration import parse
from pando.website import Website

distribution_root = os.path.dirname(__file__)
website = Website(www_root=os.path.join(distribution_root, 'doc'),
                  project_root=os.path.join(distribution_root, 'doc',
                                            '.aspen'))
opts = {}


def add_stuff_to_request_context(website, dispatch_result):

    # Define some closures for generating image markup.
    # =================================================

    def translate(src):
        if src[0] != '/':
            rel = os.path.dirname(
                dispatch_result.match)[len(website.www_root):]
            src = '/'.join([rel, src])
        src = opts['base'] + src
        return src

    def img(src):
        src = translate(src)
        html = '<img src="%s" />' % src
        return html