Example #1
0
 def __getattr__(self, key):
     settings.depr('Attribute access is deprecated.')  #0.12
     if key not in self and key[0].isupper():
         self[key] = self.Namespace(self, key)
     if key not in self and key.startswith('__'):
         raise AttributeError(key)
     return self.get(key)
Example #2
0
 def translate(self):
     if self.offset: raise RuntimeError('Parser is a one time instance.')
     while True:
         m = self.re_split.search(self.source[self.offset:])
         if m:
             text = self.source[self.offset:self.offset + m.start()]
             self.text_buffer.append(text)
             self.offset += m.end()
             if m.group(1):  # New escape syntax
                 line, sep, _ = self.source[self.offset:].partition('\n')
                 self.text_buffer.append(
                     m.group(2) + m.group(5) + line + sep)
                 self.offset += len(line + sep) + 1
                 continue
             elif m.group(5):  # Old escape syntax
                 env_settings.depr(
                     'Escape code lines with a backslash.')  #0.12
                 line, sep, _ = self.source[self.offset:].partition('\n')
                 self.text_buffer.append(m.group(2) + line + sep)
                 self.offset += len(line + sep) + 1
                 continue
             self.flush_text()
             self.read_code(multiline=bool(m.group(4)))
         else:
             break
     self.text_buffer.append(self.source[self.offset:])
     self.flush_text()
     return ''.join(self.code_buffer)
Example #3
0
 def __init__(self, *a, **ka):
     self._meta = {}
     self._on_change = lambda name, value: None
     if a or ka:
         settings.depr(
             'Constructor does no longer accept parameters.')  #0.12
         self.update(*a, **ka)
Example #4
0
 def __setattr__(self, key, value):
     if key in self.__slots__:
         return dict.__setattr__(self, key, value)
     settings.depr('Attribute assignment is deprecated.')  #0.12
     if hasattr(dict, key):
         raise AttributeError('Read-only attribute.')
     if key in self and self[key] and isinstance(self[key], self.Namespace):
         raise AttributeError('Non-empty namespace attribute.')
     self[key] = value
Example #5
0
 def _include(self, _env, _name=None, **kwargs):
     if _name is None:
         env_settings.depr('Rebase function called without arguments.'
                           ' You were probably looking for {{base}}?',
                           True)  #0.12
     env = _env.copy()
     env.update(kwargs)
     if _name not in self.cache:
         self.cache[_name] = self.__class__(name=_name, lookup=self.lookup)
     return self.cache[_name].execute(env['_stdout'], env)
Example #6
0
 def __setattr__(self, key, value):
     if key in ('_config', '_prefix'):
         self.__dict__[key] = value
         return
     settings.depr('Attribute assignment is deprecated.')  #0.12
     if hasattr(settings.DictMixin, key):
         raise AttributeError('Read-only attribute.')
     if key in self and self[key] and isinstance(
             self[key], self.__class__):
         raise AttributeError('Non-empty namespace attribute.')
     self[key] = value
Example #7
0
 def _context(self):
     settings.depr(
         'Switch to Plugin API v2 and access the Route object directly.'
     )  #0.12
     return dict(rule=self.rule,
                 method=self.method,
                 callback=self.callback,
                 name=self.name,
                 app=self.app,
                 config=self.config,
                 apply=self.plugins,
                 skip=self.skiplist)
Example #8
0
    def mount(self, prefix, app, **options):
        ''' Mount an application (:class:`Bottle` or plain WSGI) to a specific
            URL prefix. Example::

                root_app.mount('/admin/', admin_app)

            :param prefix: path prefix or `mount-point`. If it ends in a slash,
                that slash is mandatory.
            :param app: an instance of :class:`Bottle` or a WSGI application.

            All other parameters are passed to the underlying :meth:`route` call.
        '''
        if isinstance(app, settings.basestring):
            settings.depr('Parameter order of Bottle.mount() changed.',
                          True)  # 0.10

        segments = [p for p in prefix.split('/') if p]
        if not segments: raise ValueError('Empty path prefix.')
        path_depth = len(segments)

        def mountpoint_wrapper():
            try:
                http_wsgi.request.path_shift(path_depth)
                rs = http_wsgi.HTTPResponse([])

                def start_response(status, headerlist, exc_info=None):
                    if exc_info:
                        try:
                            settings._raise(*exc_info)
                        finally:
                            exc_info = None
                    rs.status = status
                    for name, value in headerlist:
                        rs.add_header(name, value)
                    return rs.body.append

                body = app(http_wsgi.request.environ, start_response)
                if body and rs.body:
                    body = settings.itertools.chain(rs.body, body)
                rs.body = body or rs.body
                return rs
            finally:
                http_wsgi.request.path_shift(-path_depth)

        options.setdefault('skip', True)
        options.setdefault('method', 'PROXY')
        options.setdefault('mountpoint', {'prefix': prefix, 'target': app})
        options['callback'] = mountpoint_wrapper

        self.route('/%s/<:re:.*>' % '/'.join(segments), **options)
        if not prefix.endswith('/'):
            self.route('/' + '/'.join(segments), **options)
Example #9
0
 def code(self):
     source = self.source
     if not source:
         with open(self.filename, 'rb') as f:
             source = f.read()
     try:
         source, encoding = env_settings.touni(source), 'utf8'
     except UnicodeError:
         env_settings.depr(
             'Template encodings other than utf8 are no longer supported.'
         )  #0.11
         source, encoding = env_settings.touni(source, 'latin1'), 'latin1'
     parser = StplParser(source, encoding=encoding, syntax=self.syntax)
     code = parser.translate()
     self.encoding = parser.encoding
     return code
Example #10
0
def local_property(name=None):
    if name:
        settings.depr(
            'local_property() is deprecated and will be removed.')  #0.12
    ls = settings.threading.local()

    def fget(self):
        try:
            return ls.var
        except AttributeError:
            raise RuntimeError("Request context not initialized.")

    def fset(self, value):
        ls.var = value

    def fdel(self):
        del ls.var

    return property(fget, fset, fdel, 'Thread-local property')
Example #11
0
    def search(cls, name, lookup=[]):
        """ Search name in all directories specified in lookup.
        First without, then with common extensions. Return first hit. """
        if not lookup:
            env_settings.depr(
                'The template lookup path list should not be empty.')  #0.12
            lookup = ['.']

        if os.path.isabs(name) and os.path.isfile(name):
            env_settings.depr(
                'Absolute template path names are deprecated.')  #0.12
            return os.path.abspath(name)

        for spath in lookup:
            spath = os.path.abspath(spath) + os.sep
            fname = os.path.abspath(os.path.join(spath, name))
            if not fname.startswith(spath): continue
            if os.path.isfile(fname): return fname
            for ext in cls.extensions:
                if os.path.isfile('%s.%s' % (fname, ext)):
                    return '%s.%s' % (fname, ext)
Example #12
0
 def fix_backward_compatibility(self, line, comment):
     parts = line.strip().split(None, 2)
     if parts and parts[0] in ('include', 'rebase'):
         env_settings.depr(
             'The include and rebase keywords are functions now.')  #0.12
         if len(parts) == 1:
             return "_printlist([base])", comment
         elif len(parts) == 2:
             return "_=%s(%r)" % tuple(parts), comment
         else:
             return "_=%s(%r, %s)" % tuple(parts), comment
     if self.lineno <= 2 and not line.strip() and 'coding' in comment:
         m = env_settings.re.match(r"#.*coding[:=]\s*([-\w.]+)", comment)
         if m:
             env_settings.depr(
                 'PEP263 encoding strings in templates are deprecated.'
             )  #0.12
             enc = m.group(1)
             self.source = self.source.encode(self.encoding).decode(enc)
             self.encoding = enc
             return line, comment.replace('coding', 'coding*')
     return line, comment
Example #13
0
 def __call__(self, *a, **ka):
     settings.depr("Some APIs changed to return Route() instances instead of"\
          " callables. Make sure to use the Route.call method and not to"\
          " call Route instances directly.") #0.12
     return self.call(*a, **ka)
Example #14
0
 def __call__(self, *a, **ka):
     settings.depr(
         'Calling ConfDict is deprecated. Use the update() method.')  #0.12
     self.update(*a, **ka)
     return self
Example #15
0
 def __getitem__(self, key):
     settings.depr(
         'Accessing namespaces as dicts is discouraged. '
         'Only use flat item access: '
         'cfg["names"]["pace"]["key"] -> cfg["name.space.key"]')  #0.12
     return self._config[self._prefix + '.' + key]
Example #16
0
 def _rebase(self, _env, _name=None, **kwargs):
     if _name is None:
         env_settings.depr('Rebase function called without arguments.'
                           ' You were probably looking for {{base}}?',
                           True)  #0.12
     _env['_rebase'] = (_name, kwargs)