Beispiel #1
0
 def test_import(self):
     from nine import (IS_PYTHON2, str, basestring, native_str,
         integer_types, class_types, range, range_list, reraise,
         iterkeys, itervalues, iteritems, map, zip, filter, input,
         implements_iterator, implements_to_string, implements_repr, nine,
         nimport, _moved)
     for key in _moved:
         if key == 'tkinter':
             continue  # travis does not have tk installed :p
         assert nimport(key)
Beispiel #2
0
other frameworks.
"""

from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
from collections import OrderedDict
from nine import IS_PYTHON2, nimport, nine, range, str, basestring
from json import dumps
from re import compile

try:
    from bag.web.pyramid import _
except ImportError:
    _ = str  # and i18n is disabled.

urlencode = nimport('urllib.parse:urlencode')


class Page(object):
    """Class that represents a web page in burla.

    A page is comprised of a descriptive name, a URL template (from which
    parameters are discovered) and possibly documentation strings.
    The instance is able to generate its URL.

    A URL template looks like this (params are preceded by a colon)::

        /cities/:city/streets/:street
    """

    def __init__(self, op_name, url_templ, fn=None, permission=None,
Beispiel #3
0
      you may omit this setting and override the _set_bucket() method.
    '''

from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
import base64
import hmac
from time import time
from hashlib import sha1
from bag import dict_subset
# http://botocore.readthedocs.org/en/latest/
from boto3.session import Session  # easy_install -UZ boto3
from keepluggable import read_setting
from . import BasePayloadStorage
from nine import nimport
quote = nimport('urllib.parse:quote')

DAY = 60 * 60 * 24


class AmazonS3Storage(BasePayloadStorage):
    __doc__ = __doc__

    def __init__(self, settings):
        self.access_key_id = read_setting(settings, 's3.access_key_id')
        self.secret_access_key = read_setting(settings, 's3.secret_access_key')
        session = Session(aws_access_key_id=self.access_key_id,
                          aws_secret_access_key=self.secret_access_key,
                          region_name=read_setting(settings, 's3.region_name'))
        # self.s3 = resource('s3')
        self.s3 = session.resource('s3')
Beispiel #4
0
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
import re
from nine import chr, nimport
name2codepoint = nimport('html.entities:name2codepoint')


def encode_xml_char_refs(s):
    # http://mail.python.org/pipermail/python-list/2007-January/424262.html
    return s.encode('ascii', 'xmlcharrefreplace')


def _substitute_entity(match):
    ent = match.group(3)
    if match.group(1) == "#":        # decode by number
        if match.group(2) == '':     # number is decimal
            return chr(int(ent))
        elif match.group(2) == 'x':  # number is hex
            return chr(int('0x' + ent, 16))
    else:
        cp = name2codepoint.get(ent)  # decode by name
        if cp:
            return chr(cp)
        else:
            return match.group()


def decode_entities(txt):
    return entity_re.subn(_substitute_entity, txt)[0]
entity_re = re.compile(r'&(#?)(x?)(\w+);', flags=re.IGNORECASE)
Beispiel #5
0
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
import re
from nine import chr, nimport
name2codepoint = nimport('html.entities:name2codepoint')


def encode_xml_char_refs(s):
    # http://mail.python.org/pipermail/python-list/2007-January/424262.html
    return s.encode('ascii', 'xmlcharrefreplace')


def _substitute_entity(match):
    ent = match.group(3)
    if match.group(1) == "#":  # decode by number
        if match.group(2) == '':  # number is decimal
            return chr(int(ent))
        elif match.group(2) == 'x':  # number is hex
            return chr(int('0x' + ent, 16))
    else:
        cp = name2codepoint.get(ent)  # decode by name
        if cp:
            return chr(cp)
        else:
            return match.group()


def decode_entities(txt):
    return entity_re.subn(_substitute_entity, txt)[0]