diff -Nru python-bottle-0.11.6/.coveragerc python-bottle-0.12.0/.coveragerc --- python-bottle-0.11.6/.coveragerc 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/.coveragerc 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,10 @@ +[run] +branch = True +parallel = True +data_file = build/.coverage + +[report] +include=bottle.py + +[html] +directory = build/coverage diff -Nru python-bottle-0.11.6/.gitignore python-bottle-0.12.0/.gitignore --- python-bottle-0.11.6/.gitignore 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/.gitignore 2013-12-03 17:16:12.000000000 +0000 @@ -2,8 +2,8 @@ *.pyo *.db *.log +*.mo ._* -.* *.*~ dist/ build/ diff -Nru python-bottle-0.11.6/AUTHORS python-bottle-0.12.0/AUTHORS --- python-bottle-0.11.6/AUTHORS 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/AUTHORS 2013-12-03 17:16:12.000000000 +0000 @@ -37,6 +37,7 @@ * Jonas Haag * Joshua Roesslein * Karl +* Kevin Zuber * Kraken * Kyle Fritz * m35 @@ -45,6 +46,7 @@ * Michael Labbe * Michael Soulier * `reddit `_ +* Nicolas Vanhoren * Robert Rollins * rogererens * rwxrwx @@ -59,4 +61,4 @@ * Tristan Zajonc * voltron * Wieland Hoffmann -* zombat \ No newline at end of file +* zombat diff -Nru python-bottle-0.11.6/Makefile python-bottle-0.12.0/Makefile --- python-bottle-0.11.6/Makefile 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/Makefile 2013-12-03 17:16:12.000000000 +0000 @@ -2,7 +2,7 @@ VERSION = $(shell python setup.py --version) ALLFILES = $(shell echo bottle.py test/*.py test/views/*.tpl) -.PHONY: release install docs test test_all test_25 test_26 test_27 test_31 test_32 test_33 2to3 clean +.PHONY: release coverage install docs test test_all test_25 test_26 test_27 test_31 test_32 test_33 2to3 clean release: test_all python setup.py --version | egrep -q -v '[a-zA-Z]' # Fail on dev/rc versions @@ -12,6 +12,14 @@ git push origin tag $(VERSION) # Fail on dublicate tag python setup.py sdist register upload # Release to pypi +coverage: + -mkdir build/ + coverage erase + COVERAGE_PROCESS_START=.coveragerc test/testall.py + coverage combine + coverage report + coverage html + push: test_all git push origin HEAD @@ -19,7 +27,7 @@ python setup.py install docs: - cd docs/; $(MAKE) html + sphinx-build -b html -d build/docs/doctrees docs build/docs/html test: python test/testall.py @@ -45,10 +53,11 @@ python3.3 test/testall.py clean: + rm -rf build/ dist/ MANIFEST 2>/dev/null || true + find . -name '__pycache__' -exec rm -rf {} + find . -name '*.pyc' -exec rm -f {} + find . -name '*.pyo' -exec rm -f {} + find . -name '*~' -exec rm -f {} + find . -name '._*' -exec rm -f {} + find . -name '.coverage*' -exec rm -f {} + - rm -rf build/ dist/ MANIFEST 2>/dev/null || true diff -Nru python-bottle-0.11.6/README.rst python-bottle-0.12.0/README.rst --- python-bottle-0.11.6/README.rst 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/README.rst 2013-12-03 17:16:12.000000000 +0000 @@ -23,11 +23,11 @@ Example ------- -:: +.. code-block:: python from bottle import route, run - @route('/hello/:name') + @route('/hello/') def hello(name): return '

Hello %s!

' % name.title() diff -Nru python-bottle-0.11.6/bottle.py python-bottle-0.12.0/bottle.py --- python-bottle-0.11.6/bottle.py 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/bottle.py 2013-12-03 17:16:12.000000000 +0000 @@ -9,14 +9,14 @@ Homepage and documentation: http://bottlepy.org/ -Copyright (c) 2012, Marcel Hellkamp. +Copyright (c) 2013, Marcel Hellkamp. License: MIT (see LICENSE for details) """ from __future__ import with_statement __author__ = 'Marcel Hellkamp' -__version__ = '0.11.6' +__version__ = '0.12.0' __license__ = 'MIT' # The gevent server adapter needs to patch some modules before they are imported @@ -36,15 +36,16 @@ import gevent.monkey; gevent.monkey.patch_all() import base64, cgi, email.utils, functools, hmac, imp, itertools, mimetypes,\ - os, re, subprocess, sys, tempfile, threading, time, urllib, warnings + os, re, subprocess, sys, tempfile, threading, time, warnings from datetime import date as datedate, datetime, timedelta from tempfile import TemporaryFile from traceback import format_exc, print_exc +from inspect import getargspec -try: from json import dumps as json_dumps, loads as json_lds +try: from simplejson import dumps as json_dumps, loads as json_lds except ImportError: # pragma: no cover - try: from simplejson import dumps as json_dumps, loads as json_lds + try: from json import dumps as json_dumps, loads as json_lds except ImportError: try: from django.utils.simplejson import dumps as json_dumps, loads as json_lds except ImportError: @@ -58,9 +59,9 @@ # It ain't pretty but it works... Sorry for the mess. py = sys.version_info -py3k = py >= (3,0,0) -py25 = py < (2,6,0) -py31 = (3,1,0) <= py < (3,2,0) +py3k = py >= (3, 0, 0) +py25 = py < (2, 6, 0) +py31 = (3, 1, 0) <= py < (3, 2, 0) # Workaround for the missing "as" keyword in py3k. def _e(): return sys.exc_info()[1] @@ -84,11 +85,13 @@ from collections import MutableMapping as DictMixin import pickle from io import BytesIO + from configparser import ConfigParser basestring = str unicode = str json_loads = lambda s: json_lds(touni(s)) callable = lambda x: hasattr(x, '__call__') imap = map + def _raise(*a): raise a[0](a[1]).with_traceback(a[2]) else: # 2.x import httplib import thread @@ -98,8 +101,9 @@ from itertools import imap import cPickle as pickle from StringIO import StringIO as BytesIO + from ConfigParser import SafeConfigParser as ConfigParser if py25: - msg = "Python 2.5 support may be dropped in future versions of Bottle." + msg = "Python 2.5 support may be dropped in future versions of Bottle." warnings.warn(msg, DeprecationWarning) from UserDict import DictMixin def next(it): return it.next() @@ -107,6 +111,7 @@ else: # 2.6, 2.7 from collections import MutableMapping as DictMixin json_loads = json_lds + eval(compile('def _raise(*a): raise a[0], a[1], a[2]', '', 'exec')) # Some helpers for string/byte handling def tob(s, enc='utf8'): @@ -122,11 +127,6 @@ class NCTextIOWrapper(TextIOWrapper): def close(self): pass # Keep wrapped buffer open. -# File uploads (which are implemented as empty FiledStorage instances...) -# have a negative truth value. That makes no sense, here is a fix. -class FieldStorage(cgi.FieldStorage): - def __nonzero__(self): return bool(self.list or self.file) - if py3k: __bool__ = __nonzero__ # A bug in functools causes it to break if the wrapper is an instance method def update_wrapper(wrapper, wrapped, *a, **ka): @@ -138,7 +138,7 @@ # These helpers are used at module level and need to be defined first. # And yes, I know PEP-8, but sometimes a lower-case classname makes more sense. -def depr(message): +def depr(message, hard=False): warnings.warn(message, DeprecationWarning, stacklevel=3) def makelist(data): # This is just to handy @@ -178,6 +178,7 @@ property. ''' def __init__(self, func): + self.__doc__ = getattr(func, '__doc__') self.func = func def __get__(self, obj, cls): @@ -233,11 +234,19 @@ class RouteSyntaxError(RouteError): - """ The route parser found something not supported by this router """ + """ The route parser found something not supported by this router. """ class RouteBuildError(RouteError): - """ The route could not been built """ + """ The route could not be built. """ + + +def _re_flatten(p): + ''' Turn all capturing groups in a regular expression pattern into + non-capturing groups. ''' + if '(' not in p: return p + return re.sub(r'(\\*)(\(\?P<[^>]+>|\((?!\?))', + lambda m: m.group(0) if len(m.group(1)) % 2 else m.group(1) + '(?:', p) class Router(object): @@ -253,34 +262,27 @@ ''' default_pattern = '[^/]+' - default_filter = 're' - #: Sorry for the mess. It works. Trust me. - rule_syntax = re.compile('(\\\\*)'\ - '(?:(?::([a-zA-Z_][a-zA-Z_0-9]*)?()(?:#(.*?)#)?)'\ - '|(?:<([a-zA-Z_][a-zA-Z_0-9]*)?(?::([a-zA-Z_]*)'\ - '(?::((?:\\\\.|[^\\\\>]+)+)?)?)?>))') + default_filter = 're' + + #: The current CPython regexp implementation does not allow more + #: than 99 matching groups per regular expression. + _MAX_GROUPS_PER_PATTERN = 99 def __init__(self, strict=False): - self.rules = {} # A {rule: Rule} mapping - self.builder = {} # A rule/name->build_info mapping - self.static = {} # Cache for static routes: {path: {method: target}} - self.dynamic = [] # Cache for dynamic routes. See _compile() + self.rules = [] # All rules in order + self._groups = {} # index of regexes to find them in dyna_routes + self.builder = {} # Data structure for the url builder + self.static = {} # Search structure for static routes + self.dyna_routes = {} + self.dyna_regexes = {} # Search structure for dynamic routes #: If true, static routes are no longer checked first. self.strict_order = strict - self.filters = {'re': self.re_filter, 'int': self.int_filter, - 'float': self.float_filter, 'path': self.path_filter} - - def re_filter(self, conf): - return conf or self.default_pattern, None, None - - def int_filter(self, conf): - return r'-?\d+', int, lambda x: str(int(x)) - - def float_filter(self, conf): - return r'-?[\d.]+', float, lambda x: str(float(x)) - - def path_filter(self, conf): - return r'.+?', None, None + self.filters = { + 're': lambda conf: + (_re_flatten(conf or self.default_pattern), None, None), + 'int': lambda conf: (r'-?\d+', int, lambda x: str(int(x))), + 'float': lambda conf: (r'-?[\d.]+', float, lambda x: str(float(x))), + 'path': lambda conf: (r'.+?', None, None)} def add_filter(self, name, func): ''' Add a filter. The provided function is called with the configuration @@ -288,9 +290,12 @@ The first element is a string, the last two are callables or None. ''' self.filters[name] = func - def parse_rule(self, rule): - ''' Parses a rule into a (name, filter, conf) token stream. If mode is - None, name contains a static rule part. ''' + rule_syntax = re.compile('(\\\\*)'\ + '(?:(?::([a-zA-Z_][a-zA-Z_0-9]*)?()(?:#(.*?)#)?)'\ + '|(?:<([a-zA-Z_][a-zA-Z_0-9]*)?(?::([a-zA-Z_]*)'\ + '(?::((?:\\\\.|[^\\\\>]+)+)?)?)?>))') + + def _itertokens(self, rule): offset, prefix = 0, '' for match in self.rule_syntax.finditer(rule): prefix += rule[offset:match.start()] @@ -299,77 +304,95 @@ prefix += match.group(0)[len(g[0]):] offset = match.end() continue - if prefix: yield prefix, None, None - name, filtr, conf = g[1:4] if not g[2] is None else g[4:7] - if not filtr: filtr = self.default_filter - yield name, filtr, conf or None + if prefix: + yield prefix, None, None + name, filtr, conf = g[4:7] if g[2] is None else g[1:4] + yield name, filtr or 'default', conf or None offset, prefix = match.end(), '' if offset <= len(rule) or prefix: yield prefix+rule[offset:], None, None def add(self, rule, method, target, name=None): - ''' Add a new route or replace the target for an existing route. ''' - if rule in self.rules: - self.rules[rule][method] = target - if name: self.builder[name] = self.builder[rule] - return - - target = self.rules[rule] = {method: target} - - # Build pattern and other structures for dynamic routes - anons = 0 # Number of anonymous wildcards - pattern = '' # Regular expression pattern - filters = [] # Lists of wildcard input filters - builder = [] # Data structure for the URL builder + ''' Add a new rule or replace the target for an existing rule. ''' + anons = 0 # Number of anonymous wildcards found + keys = [] # Names of keys + pattern = '' # Regular expression pattern with named groups + filters = [] # Lists of wildcard input filters + builder = [] # Data structure for the URL builder is_static = True - for key, mode, conf in self.parse_rule(rule): + + for key, mode, conf in self._itertokens(rule): if mode: is_static = False + if mode == 'default': mode = self.default_filter mask, in_filter, out_filter = self.filters[mode](conf) - if key: - pattern += '(?P<%s>%s)' % (key, mask) - else: + if not key: pattern += '(?:%s)' % mask - key = 'anon%d' % anons; anons += 1 + key = 'anon%d' % anons + anons += 1 + else: + pattern += '(?P<%s>%s)' % (key, mask) + keys.append(key) if in_filter: filters.append((key, in_filter)) builder.append((key, out_filter or str)) elif key: pattern += re.escape(key) builder.append((None, key)) + self.builder[rule] = builder if name: self.builder[name] = builder if is_static and not self.strict_order: - self.static[self.build(rule)] = target + self.static.setdefault(method, {}) + self.static[method][self.build(rule)] = (target, None) return - def fpat_sub(m): - return m.group(0) if len(m.group(1)) % 2 else m.group(1) + '(?:' - flat_pattern = re.sub(r'(\\*)(\(\?P<[^>]*>|\((?!\?))', fpat_sub, pattern) - try: - re_match = re.compile('^(%s)$' % pattern).match + re_pattern = re.compile('^(%s)$' % pattern) + re_match = re_pattern.match except re.error: raise RouteSyntaxError("Could not add Route: %s (%s)" % (rule, _e())) - def match(path): - """ Return an url-argument dictionary. """ - url_args = re_match(path).groupdict() - for name, wildcard_filter in filters: - try: - url_args[name] = wildcard_filter(url_args[name]) - except ValueError: - raise HTTPError(400, 'Path has wrong format.') - return url_args + if filters: + def getargs(path): + url_args = re_match(path).groupdict() + for name, wildcard_filter in filters: + try: + url_args[name] = wildcard_filter(url_args[name]) + except ValueError: + raise HTTPError(400, 'Path has wrong format.') + return url_args + elif re_pattern.groupindex: + def getargs(path): + return re_match(path).groupdict() + else: + getargs = None - try: - combined = '%s|(^%s$)' % (self.dynamic[-1][0].pattern, flat_pattern) - self.dynamic[-1] = (re.compile(combined), self.dynamic[-1][1]) - self.dynamic[-1][1].append((match, target)) - except (AssertionError, IndexError): # AssertionError: Too many groups - self.dynamic.append((re.compile('(^%s$)' % flat_pattern), - [(match, target)])) - return match + flatpat = _re_flatten(pattern) + whole_rule = (rule, flatpat, target, getargs) + + if (flatpat, method) in self._groups: + if DEBUG: + msg = 'Route <%s %s> overwrites a previously defined route' + warnings.warn(msg % (method, rule), RuntimeWarning) + self.dyna_routes[method][self._groups[flatpat, method]] = whole_rule + else: + self.dyna_routes.setdefault(method, []).append(whole_rule) + self._groups[flatpat, method] = len(self.dyna_routes[method]) - 1 + + self._compile(method) + + def _compile(self, method): + all_rules = self.dyna_routes[method] + comborules = self.dyna_regexes[method] = [] + maxgroups = self._MAX_GROUPS_PER_PATTERN + for x in range(0, len(all_rules), maxgroups): + some = all_rules[x:x+maxgroups] + combined = (flatpat for (_, flatpat, _, _) in some) + combined = '|'.join('(^%s$)' % flatpat for flatpat in combined) + combined = re.compile(combined).match + rules = [(target, getargs) for (_, _, target, getargs) in some] + comborules.append((combined, rules)) def build(self, _name, *anons, **query): ''' Build an URL by filling the wildcards in a rule. ''' @@ -384,30 +407,43 @@ def match(self, environ): ''' Return a (target, url_agrs) tuple or raise HTTPError(400/404/405). ''' - path, targets, urlargs = environ['PATH_INFO'] or '/', None, {} - if path in self.static: - targets = self.static[path] - else: - for combined, rules in self.dynamic: - match = combined.match(path) - if not match: continue - getargs, targets = rules[match.lastindex - 1] - urlargs = getargs(path) if getargs else {} - break - - if not targets: - raise HTTPError(404, "Not found: " + repr(environ['PATH_INFO'])) - method = environ['REQUEST_METHOD'].upper() - if method in targets: - return targets[method], urlargs - if method == 'HEAD' and 'GET' in targets: - return targets['GET'], urlargs - if 'ANY' in targets: - return targets['ANY'], urlargs - allowed = [verb for verb in targets if verb != 'ANY'] - if 'GET' in allowed and 'HEAD' not in allowed: - allowed.append('HEAD') - raise HTTPError(405, "Method not allowed.", Allow=",".join(allowed)) + verb = environ['REQUEST_METHOD'].upper() + path = environ['PATH_INFO'] or '/' + target = None + methods = [verb, 'GET', 'ANY'] if verb == 'HEAD' else [verb, 'ANY'] + + for method in methods: + if method in self.static and path in self.static[method]: + target, getargs = self.static[method][path] + return target, getargs(path) if getargs else {} + elif method in self.dyna_regexes: + for combined, rules in self.dyna_regexes[method]: + match = combined(path) + if match: + target, getargs = rules[match.lastindex - 1] + return target, getargs(path) if getargs else {} + + # No matching route found. Collect alternative methods for 405 response + allowed = set([]) + nocheck = set(methods) + for method in set(self.static) - nocheck: + if path in self.static[method]: + allowed.add(verb) + for method in set(self.dyna_regexes) - allowed - nocheck: + for combined, rules in self.dyna_regexes[method]: + match = combined(path) + if match: + allowed.add(method) + if allowed: + allow_header = ",".join(sorted(allowed)) + raise HTTPError(405, "Method not allowed.", Allow=allow_header) + + # No matching route and no alternative method found. We give up + raise HTTPError(404, "Not found: " + repr(path)) + + + + class Route(object): @@ -435,12 +471,12 @@ #: Additional keyword arguments passed to the :meth:`Bottle.route` #: decorator are stored in this dictionary. Used for route-specific #: plugin configuration and meta-data. - self.config = ConfigDict(config) + self.config = ConfigDict().load_dict(config) def __call__(self, *a, **ka): 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.") + " call Route instances directly.") #0.12 return self.call(*a, **ka) @cached_property @@ -460,7 +496,7 @@ @property def _context(self): - depr('Switch to Plugin API v2 and access the Route object directly.') + 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) @@ -492,8 +528,32 @@ update_wrapper(callback, self.callback) return callback + def get_undecorated_callback(self): + ''' Return the callback. If the callback is a decorated function, try to + recover the original function. ''' + func = self.callback + func = getattr(func, '__func__' if py3k else 'im_func', func) + closure_attr = '__closure__' if py3k else 'func_closure' + while hasattr(func, closure_attr) and getattr(func, closure_attr): + func = getattr(func, closure_attr)[0].cell_contents + return func + + def get_callback_args(self): + ''' Return a list of argument names the callback (most likely) accepts + as keyword arguments. If the callback is a decorated function, try + to recover the original function before inspection. ''' + return getargspec(self.get_undecorated_callback())[0] + + def get_config(key, default=None): + ''' Lookup a config field and return its value, first checking the + route.config, then route.app.config.''' + for conf in (self.config, self.app.conifg): + if key in conf: return conf[key] + return default + def __repr__(self): - return '<%s %r %r>' % (self.method, self.rule, self.callback) + cb = self.get_undecorated_callback() + return '<%s %r %r>' % (self.method, self.rule, cb) @@ -515,15 +575,17 @@ """ def __init__(self, catchall=True, autojson=True): - #: If true, most exceptions are caught and returned as :exc:`HTTPError` - self.catchall = catchall - - #: A :class:`ResourceManager` for application files - self.resources = ResourceManager() #: A :class:`ConfigDict` for app specific configuration. self.config = ConfigDict() - self.config.autojson = autojson + self.config._on_change = functools.partial(self.trigger_hook, 'config') + self.config.meta_set('autojson', 'validate', bool) + self.config.meta_set('catchall', 'validate', bool) + self.config['catchall'] = catchall + self.config['autojson'] = autojson + + #: A :class:`ResourceManager` for application files + self.resources = ResourceManager() self.routes = [] # List of installed :class:`Route` instances. self.router = Router() # Maps requests to :class:`Route` instances. @@ -531,12 +593,53 @@ # Core plugins self.plugins = [] # List of installed plugins. - self.hooks = HooksPlugin() - self.install(self.hooks) - if self.config.autojson: + if self.config['autojson']: self.install(JSONPlugin()) self.install(TemplatePlugin()) + #: If true, most exceptions are caught and returned as :exc:`HTTPError` + catchall = DictProperty('config', 'catchall') + + __hook_names = 'before_request', 'after_request', 'app_reset', 'config' + __hook_reversed = 'after_request' + + @cached_property + def _hooks(self): + return dict((name, []) for name in self.__hook_names) + + def add_hook(self, name, func): + ''' Attach a callback to a hook. Three hooks are currently implemented: + + before_request + Executed once before each request. The request context is + available, but no routing has happened yet. + after_request + Executed once after each request regardless of its outcome. + app_reset + Called whenever :meth:`Bottle.reset` is called. + ''' + if name in self.__hook_reversed: + self._hooks[name].insert(0, func) + else: + self._hooks[name].append(func) + + def remove_hook(self, name, func): + ''' Remove a callback from a hook. ''' + if name in self._hooks and func in self._hooks[name]: + self._hooks[name].remove(func) + return True + + def trigger_hook(self, __name, *args, **kwargs): + ''' Trigger a hook and return a list of results. ''' + return [hook(*args, **kwargs) for hook in self._hooks[__name][:]] + + def hook(self, name): + """ Return a decorator that attaches a callback to a hook. See + :meth:`add_hook` for details.""" + def decorator(func): + self.add_hook(name, func) + return func + return decorator def mount(self, prefix, app, **options): ''' Mount an application (:class:`Bottle` or plain WSGI) to a specific @@ -551,8 +654,7 @@ All other parameters are passed to the underlying :meth:`route` call. ''' if isinstance(app, basestring): - prefix, app = app, prefix - depr('Parameter order of Bottle.mount() changed.') # 0.10 + 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.') @@ -562,7 +664,12 @@ try: request.path_shift(path_depth) rs = HTTPResponse([]) - def start_response(status, headerlist): + def start_response(status, headerlist, exc_info=None): + if exc_info: + try: + _raise(*exc_info) + finally: + exc_info = None rs.status = status for name, value in headerlist: rs.add_header(name, value) return rs.body.append @@ -619,10 +726,6 @@ if removed: self.reset() return removed - def run(self, **kwargs): - ''' Calls :func:`run` with the same parameters. ''' - run(self, **kwargs) - def reset(self, route=None): ''' Reset all routes (force plugins to be re-applied) and clear all caches. If an ID or route object is given, only that specific route @@ -633,7 +736,7 @@ for route in routes: route.reset() if DEBUG: for route in routes: route.prepare() - self.hooks.trigger('app_reset') + self.trigger_hook('app_reset') def close(self): ''' Close the application and all installed plugins. ''' @@ -641,6 +744,10 @@ if hasattr(plugin, 'close'): plugin.close() self.stopped = True + def run(self, **kwargs): + ''' Calls :func:`run` with the same parameters. ''' + run(self, **kwargs) + def match(self, environ): """ Search for a matching route and return a (:class:`Route` , urlargs) tuple. The second value is a dictionary with parameters extracted @@ -725,43 +832,31 @@ return handler return wrapper - def hook(self, name): - """ Return a decorator that attaches a callback to a hook. Three hooks - are currently implemented: - - - before_request: Executed once before each request - - after_request: Executed once after each request - - app_reset: Called whenever :meth:`reset` is called. - """ - def wrapper(func): - self.hooks.add(name, func) - return func - return wrapper - - def handle(self, path, method='GET'): - """ (deprecated) Execute the first matching route callback and return - the result. :exc:`HTTPResponse` exceptions are caught and returned. - If :attr:`Bottle.catchall` is true, other exceptions are caught as - well and returned as :exc:`HTTPError` instances (500). - """ - depr("This method will change semantics in 0.10. Try to avoid it.") - if isinstance(path, dict): - return self._handle(path) - return self._handle({'PATH_INFO': path, 'REQUEST_METHOD': method.upper()}) - def default_error_handler(self, res): return tob(template(ERROR_PAGE_TEMPLATE, e=res)) def _handle(self, environ): + path = environ['bottle.raw_path'] = environ['PATH_INFO'] + if py3k: + try: + environ['PATH_INFO'] = path.encode('latin1').decode('utf8') + except UnicodeError: + return HTTPError(400, 'Invalid path string. Expected UTF-8') + try: environ['bottle.app'] = self request.bind(environ) response.bind() - route, args = self.router.match(environ) - environ['route.handle'] = route - environ['bottle.route'] = route - environ['route.url_args'] = args - return route.call(**args) + try: + self.trigger_hook('before_request') + route, args = self.router.match(environ) + environ['route.handle'] = route + environ['bottle.route'] = route + environ['route.url_args'] = args + return route.call(**args) + finally: + self.trigger_hook('after_request') + except HTTPResponse: return _e() except RouteReset: @@ -818,10 +913,10 @@ # Handle Iterables. We peek into them to detect their inner type. try: - out = iter(out) - first = next(out) + iout = iter(out) + first = next(iout) while not first: - first = next(out) + first = next(iout) except StopIteration: return self._cast('') except HTTPResponse: @@ -835,13 +930,17 @@ # These are the inner types allowed in iterator or generator objects. if isinstance(first, HTTPResponse): return self._cast(first) - if isinstance(first, bytes): - return itertools.chain([first], out) - if isinstance(first, unicode): - return imap(lambda x: x.encode(response.charset), - itertools.chain([first], out)) - return self._cast(HTTPError(500, 'Unsupported response type: %s'\ - % type(first))) + elif isinstance(first, bytes): + new_iter = itertools.chain([first], iout) + elif isinstance(first, unicode): + encoder = lambda x: x.encode(response.charset) + new_iter = imap(encoder, itertools.chain([first], iout)) + else: + msg = 'Unsupported response type: %s' % type(first) + return self._cast(HTTPError(500, msg)) + if hasattr(out, 'close'): + new_iter = _closeiter(new_iter, out.close) + return new_iter def wsgi(self, environ, start_response): """ The bottle WSGI-interface. """ @@ -866,7 +965,7 @@ % (html_escape(repr(_e())), html_escape(format_exc())) environ['wsgi.errors'].write(err) headers = [('Content-Type', 'text/html; charset=UTF-8')] - start_response('500 INTERNAL SERVER ERROR', headers) + start_response('500 INTERNAL SERVER ERROR', headers, sys.exc_info()) return [tob(err)] def __call__(self, environ, start_response): @@ -882,7 +981,6 @@ # HTTP and WSGI Tools ########################################################## ############################################################################### - class BaseRequest(object): """ A wrapper for WSGI environment dictionaries that adds a lot of convenient access methods and properties. Most of them are read-only. @@ -896,8 +994,6 @@ #: Maximum size of memory buffer for :attr:`body` in bytes. MEMFILE_MAX = 102400 - #: Maximum number pr GET or POST parameters per request - MAX_PARAMS = 100 def __init__(self, environ=None): """ Wrap a WSGI environ dictionary. """ @@ -911,6 +1007,16 @@ ''' Bottle application handling this request. ''' raise RuntimeError('This request is not connected to an application.') + @DictProperty('environ', 'bottle.route', read_only=True) + def route(self): + """ The bottle :class:`Route` object that matches this request. """ + raise RuntimeError('This request is not connected to a route.') + + @DictProperty('environ', 'route.url_args', read_only=True) + def url_args(self): + """ The arguments extracted from the URL. """ + raise RuntimeError('This request is not connected to a route.') + @property def path(self): ''' The value of ``PATH_INFO`` with exactly one prefixed slash (to fix @@ -936,8 +1042,7 @@ def cookies(self): """ Cookies parsed into a :class:`FormsDict`. Signed cookies are NOT decoded. Use :meth:`get_cookie` if you expect signed cookies. """ - cookies = SimpleCookie(self.environ.get('HTTP_COOKIE','')) - cookies = list(cookies.values())[:self.MAX_PARAMS] + cookies = SimpleCookie(self.environ.get('HTTP_COOKIE','')).values() return FormsDict((c.key, c.value) for c in cookies) def get_cookie(self, key, default=None, secret=None): @@ -959,19 +1064,19 @@ :class:`Router`. ''' get = self.environ['bottle.get'] = FormsDict() pairs = _parse_qsl(self.environ.get('QUERY_STRING', '')) - for key, value in pairs[:self.MAX_PARAMS]: + for key, value in pairs: get[key] = value return get @DictProperty('environ', 'bottle.request.forms', read_only=True) def forms(self): """ Form values parsed from an `url-encoded` or `multipart/form-data` - encoded POST or PUT request body. The result is retuned as a + encoded POST or PUT request body. The result is returned as a :class:`FormsDict`. All keys and values are strings. File uploads are stored separately in :attr:`files`. """ forms = FormsDict() for name, item in self.POST.allitems(): - if not hasattr(item, 'filename'): + if not isinstance(item, FileUpload): forms[name] = item return forms @@ -988,24 +1093,13 @@ @DictProperty('environ', 'bottle.request.files', read_only=True) def files(self): - """ File uploads parsed from an `url-encoded` or `multipart/form-data` - encoded POST or PUT request body. The values are instances of - :class:`cgi.FieldStorage`. The most important attributes are: - - filename - The filename, if specified; otherwise None; this is the client - side filename, *not* the file name on which it is stored (that's - a temporary file you don't deal with) - file - The file(-like) object from which you can read the data. - value - The value as a *string*; for file uploads, this transparently - reads the file every time you request the value. Do not do this - on big files. + """ File uploads parsed from `multipart/form-data` encoded POST or PUT + request body. The values are instances of :class:`FileUpload`. + """ files = FormsDict() for name, item in self.POST.allitems(): - if hasattr(item, 'filename'): + if isinstance(item, FileUpload): files[name] = item return files @@ -1015,25 +1109,74 @@ property holds the parsed content of the request body. Only requests smaller than :attr:`MEMFILE_MAX` are processed to avoid memory exhaustion. ''' - if 'application/json' in self.environ.get('CONTENT_TYPE', '') \ - and 0 < self.content_length < self.MEMFILE_MAX: - return json_loads(self.body.read(self.MEMFILE_MAX)) + if 'application/json' in self.environ.get('CONTENT_TYPE', ''): + return json_loads(self._get_body_string()) return None - @DictProperty('environ', 'bottle.request.body', read_only=True) - def _body(self): + def _iter_body(self, read, bufsize): maxread = max(0, self.content_length) - stream = self.environ['wsgi.input'] - body = BytesIO() if maxread < self.MEMFILE_MAX else TemporaryFile(mode='w+b') - while maxread > 0: - part = stream.read(min(maxread, self.MEMFILE_MAX)) + while maxread: + part = read(min(maxread, bufsize)) if not part: break - body.write(part) + yield part maxread -= len(part) + + def _iter_chunked(self, read, bufsize): + err = HTTPError(400, 'Error while parsing chunked transfer body.') + rn, sem, bs = tob('\r\n'), tob(';'), tob('') + while True: + header = read(1) + while header[-2:] != rn: + c = read(1) + header += c + if not c: raise err + if len(header) > bufsize: raise err + size, sep, junk = header.partition(sem) + try: + maxread = int(tonat(size.strip()), 16) + except ValueError: + raise err + if maxread == 0: break + buffer = bs + while maxread > 0: + if not buffer: + buffer = read(min(maxread, bufsize)) + part, buffer = buffer[:maxread], buffer[maxread:] + if not part: raise err + yield part + maxread -= len(part) + if read(2) != rn: + raise err + + @DictProperty('environ', 'bottle.request.body', read_only=True) + def _body(self): + body_iter = self._iter_chunked if self.chunked else self._iter_body + read_func = self.environ['wsgi.input'].read + body, body_size, is_temp_file = BytesIO(), 0, False + for part in body_iter(read_func, self.MEMFILE_MAX): + body.write(part) + body_size += len(part) + if not is_temp_file and body_size > self.MEMFILE_MAX: + body, tmp = TemporaryFile(mode='w+b'), body + body.write(tmp.getvalue()) + del tmp + is_temp_file = True self.environ['wsgi.input'] = body body.seek(0) return body + def _get_body_string(self): + ''' read body until content-length or MEMFILE_MAX into a string. Raise + HTTPError(413) on requests that are to large. ''' + clen = self.content_length + if clen > self.MEMFILE_MAX: + raise HTTPError(413, 'Request to large') + if clen < 0: clen = self.MEMFILE_MAX + 1 + data = self.body.read(clen) + if len(data) > self.MEMFILE_MAX: # Fail fast + raise HTTPError(413, 'Request to large') + return data + @property def body(self): """ The HTTP request body as a seek-able file-like object. Depending on @@ -1044,6 +1187,11 @@ self._body.seek(0) return self._body + @property + def chunked(self): + ''' True if Chunked transfer encoding was. ''' + return 'chunked' in self.environ.get('HTTP_TRANSFER_ENCODING', '').lower() + #: An alias for :attr:`query`. GET = query @@ -1057,9 +1205,8 @@ # We default to application/x-www-form-urlencoded for everything that # is not multipart and take the fast path (also: 3.1 workaround) if not self.content_type.startswith('multipart/'): - maxlen = max(0, min(self.content_length, self.MEMFILE_MAX)) - pairs = _parse_qsl(tonat(self.body.read(maxlen), 'latin1')) - for key, value in pairs[:self.MAX_PARAMS]: + pairs = _parse_qsl(tonat(self._get_body_string(), 'latin1')) + for key, value in pairs: post[key] = value return post @@ -1068,22 +1215,21 @@ if key in self.environ: safe_env[key] = self.environ[key] args = dict(fp=self.body, environ=safe_env, keep_blank_values=True) if py31: - args['fp'] = NCTextIOWrapper(args['fp'], encoding='ISO-8859-1', + args['fp'] = NCTextIOWrapper(args['fp'], encoding='latin1', newline='\n') elif py3k: - args['encoding'] = 'ISO-8859-1' - data = FieldStorage(**args) - for item in (data.list or [])[:self.MAX_PARAMS]: - post[item.name] = item if item.filename else item.value + args['encoding'] = 'latin1' + data = cgi.FieldStorage(**args) + data = data.list or [] + for item in data: + if item.filename: + post[item.name] = FileUpload(item.file, item.name, + item.filename, item.headers) + else: + post[item.name] = item.value return post @property - def COOKIES(self): - ''' Alias for :attr:`cookies` (deprecated). ''' - depr('BaseRequest.COOKIES was renamed to BaseRequest.cookies (lowercase).') - return self.cookies - - @property def url(self): """ The full request URI including hostname and scheme. If your app lives behind a reverse proxy or load balancer and you get confusing @@ -1271,6 +1417,14 @@ This class does support dict-like case-insensitive item-access to headers, but is NOT a dict. Most notably, iterating over a response yields parts of the body and not the headers. + + :param body: The response body as one of the supported types. + :param status: Either an HTTP status code (e.g. 200) or a status line + including the reason phrase (e.g. '200 OK'). + :param headers: A dictionary or a list of name-value pairs. + + Additional keyword arguments are added to the list of headers. + Underscores in the header name are replaced with dashes. """ default_status = 200 @@ -1284,20 +1438,30 @@ 'Content-Length', 'Content-Range', 'Content-Type', 'Content-Md5', 'Last-Modified'))} - def __init__(self, body='', status=None, **headers): + def __init__(self, body='', status=None, headers=None, **more_headers): self._cookies = None self._headers = {} self.body = body self.status = status or self.default_status if headers: - for name, value in headers.items(): - self[name] = value + if isinstance(headers, dict): + headers = headers.items() + for name, value in headers: + self.add_header(name, value) + if more_headers: + for name, value in more_headers.items(): + self.add_header(name, value) - def copy(self): + def copy(self, cls=None): ''' Returns a copy of self. ''' - copy = Response() + cls = cls or BaseResponse + assert issubclass(cls, BaseResponse) + copy = cls() copy.status = self.status copy._headers = dict((k, v[:]) for (k, v) in self._headers.items()) + if self._cookies: + copy._cookies = SimpleCookie() + copy._cookies.load(self._cookies.output()) return copy def __iter__(self): @@ -1372,10 +1536,6 @@ allowed with the current response status code. ''' return self.headerlist - def wsgiheader(self): - depr('The wsgiheader method is deprecated. See headerlist.') #0.10 - return self.headerlist - @property def headerlist(self): ''' WSGI conform list of (header, value) tuples. ''' @@ -1394,22 +1554,16 @@ content_type = HeaderProperty('Content-Type') content_length = HeaderProperty('Content-Length', reader=int) + expires = HeaderProperty('Expires', + reader=lambda x: datetime.utcfromtimestamp(parse_date(x)), + writer=lambda x: http_date(x)) @property - def charset(self): + def charset(self, default='UTF-8'): """ Return the charset specified in the content-type header (default: utf8). """ if 'charset=' in self.content_type: return self.content_type.split('charset=')[-1].split(';')[0].strip() - return 'UTF-8' - - @property - def COOKIES(self): - """ A dict-like SimpleCookie instance. This should not be used directly. - See :meth:`set_cookie`. """ - depr('The COOKIES dict is deprecated. Use `set_cookie()` instead.') # 0.10 - if not self._cookies: - self._cookies = SimpleCookie() - return self._cookies + return default def set_cookie(self, name, value, secret=None, **options): ''' Create a new cookie or replace an old one. If the `secret` parameter is @@ -1480,20 +1634,17 @@ out += '%s: %s\n' % (name.title(), value.strip()) return out -#: Thread-local storage for :class:`LocalRequest` and :class:`LocalResponse` -#: attributes. -_lctx = threading.local() -def local_property(name): +def local_property(name=None): + if name: depr('local_property() is deprecated and will be removed.') #0.12 + ls = threading.local() def fget(self): - try: - return getattr(_lctx, name) + try: return ls.var except AttributeError: raise RuntimeError("Request context not initialized.") - def fset(self, value): setattr(_lctx, name, value) - def fdel(self): delattr(_lctx, name) - return property(fget, fset, fdel, - 'Thread-local property stored in :data:`_lctx.%s`' % name) + def fset(self, value): ls.var = value + def fdel(self): del ls.var + return property(fget, fset, fdel, 'Thread-local property') class LocalRequest(BaseRequest): @@ -1503,7 +1654,7 @@ request/response cycle, this instance always refers to the *current* request (even on a multithreaded server). ''' bind = BaseRequest.__init__ - environ = local_property('request_environ') + environ = local_property() class LocalResponse(BaseResponse): @@ -1513,22 +1664,20 @@ to build the HTTP response at the end of the request/response cycle. ''' bind = BaseResponse.__init__ - _status_line = local_property('response_status_line') - _status_code = local_property('response_status_code') - _cookies = local_property('response_cookies') - _headers = local_property('response_headers') - body = local_property('response_body') + _status_line = local_property() + _status_code = local_property() + _cookies = local_property() + _headers = local_property() + body = local_property() + Request = BaseRequest Response = BaseResponse + class HTTPResponse(Response, BottleException): - def __init__(self, body='', status=None, header=None, **headers): - if header or 'output' in headers: - depr('Call signature changed (for the better)') - if header: headers.update(header) - if 'output' in headers: body = headers.pop('output') - super(HTTPResponse, self).__init__(body, status, **headers) + def __init__(self, body='', status=None, headers=None, **more_headers): + super(HTTPResponse, self).__init__(body, status, headers, **more_headers) def apply(self, response): response._status_code = self._status_code @@ -1537,19 +1686,14 @@ response._cookies = self._cookies response.body = self.body - def _output(self, value=None): - depr('Use HTTPResponse.body instead of HTTPResponse.output') - if value is None: return self.body - self.body = value - - output = property(_output, _output, doc='Alias for .body') class HTTPError(HTTPResponse): default_status = 500 - def __init__(self, status=None, body=None, exception=None, traceback=None, header=None, **headers): + def __init__(self, status=None, body=None, exception=None, traceback=None, + **options): self.exception = exception self.traceback = traceback - super(HTTPError, self).__init__(body, status, header, **headers) + super(HTTPError, self).__init__(body, status, **options) @@ -1561,6 +1705,7 @@ class PluginError(BottleException): pass + class JSONPlugin(object): name = 'json' api = 2 @@ -1572,59 +1717,22 @@ dumps = self.json_dumps if not dumps: return callback def wrapper(*a, **ka): - rv = callback(*a, **ka) + try: + rv = callback(*a, **ka) + except HTTPError: + rv = _e() + if isinstance(rv, dict): #Attempt to serialize, raises exception on failure json_response = dumps(rv) #Set content type only if serialization succesful response.content_type = 'application/json' return json_response + elif isinstance(rv, HTTPResponse) and isinstance(rv.body, dict): + rv.body = dumps(rv.body) + rv.content_type = 'application/json' return rv - return wrapper - - -class HooksPlugin(object): - name = 'hooks' - api = 2 - - _names = 'before_request', 'after_request', 'app_reset' - - def __init__(self): - self.hooks = dict((name, []) for name in self._names) - self.app = None - def _empty(self): - return not (self.hooks['before_request'] or self.hooks['after_request']) - - def setup(self, app): - self.app = app - - def add(self, name, func): - ''' Attach a callback to a hook. ''' - was_empty = self._empty() - self.hooks.setdefault(name, []).append(func) - if self.app and was_empty and not self._empty(): self.app.reset() - - def remove(self, name, func): - ''' Remove a callback from a hook. ''' - was_empty = self._empty() - if name in self.hooks and func in self.hooks[name]: - self.hooks[name].remove(func) - if self.app and not was_empty and self._empty(): self.app.reset() - - def trigger(self, name, *a, **ka): - ''' Trigger a hook and return a list of results. ''' - hooks = self.hooks[name] - if ka.pop('reversed', False): hooks = hooks[::-1] - return [hook(*a, **ka) for hook in hooks] - - def apply(self, callback, route): - if self._empty(): return callback - def wrapper(*a, **ka): - self.trigger('before_request') - rv = callback(*a, **ka) - self.trigger('after_request', reversed=True) - return rv return wrapper @@ -1640,9 +1748,6 @@ conf = route.config.get('template') if isinstance(conf, (tuple, list)) and len(conf) == 2: return view(conf[0], **conf[1])(callback) - elif isinstance(conf, str) and 'template_opts' in route.config: - depr('The `template_opts` parameter is deprecated.') #0.9 - return view(conf, **route.config['template_opts'])(callback) elif isinstance(conf, str): return view(conf)(callback) else: @@ -1759,7 +1864,6 @@ getlist = getall - class FormsDict(MultiDict): ''' This :class:`MultiDict` subclass is used to store request form data. Additionally to the normal dict-like item access methods (which return @@ -1776,10 +1880,11 @@ def _fix(self, s, encoding=None): if isinstance(s, unicode) and self.recode_unicode: # Python 3 WSGI - s = s.encode('latin1') - if isinstance(s, bytes): # Python 2 WSGI + return s.encode('latin1').decode(encoding or self.input_encoding) + elif isinstance(s, bytes): # Python 2 WSGI return s.decode(encoding or self.input_encoding) - return s + else: + return s def decode(self, encoding=None): ''' Returns a copy with all keys and values de- or recoded to match @@ -1793,6 +1898,7 @@ return copy def getunicode(self, name, default=None, encoding=None): + ''' Return the value as a unicode string, or the default. ''' try: return self._fix(self[name], encoding) except (UnicodeError, KeyError): @@ -1878,25 +1984,109 @@ def __contains__(self, key): return self._ekey(key) in self.environ + class ConfigDict(dict): - ''' A dict-subclass with some extras: You can access keys like attributes. - Uppercase attributes create new ConfigDicts and act as name-spaces. - Other missing attributes return None. Calling a ConfigDict updates its - values and returns itself. - - >>> cfg = ConfigDict() - >>> cfg.Namespace.value = 5 - >>> cfg.OtherNamespace(a=1, b=2) - >>> cfg - {'Namespace': {'value': 5}, 'OtherNamespace': {'a': 1, 'b': 2}} + ''' A dict-like configuration storage with additional support for + namespaces, validators, meta-data, on_change listeners and more. ''' + __slots__ = ('_meta', '_on_change') + + def __init__(self, *a, **ka): + self._meta = {} + self._on_change = lambda name, value: None + if a or ka: + depr('Constructor does no longer accept parameters.') #0.12 + self.update(*a, **ka) + + def load_config(self, filename): + ''' Load values from an *.ini style config file. + + If the config file contains sections, their names are used as + namespaces for the values within. The two special sections + ``DEFAULT`` and ``bottle`` refer to the root namespace (no prefix). + ''' + conf = ConfigParser() + conf.read(filename) + for section in conf.sections(): + for key, value in conf.items(section): + if section not in ('DEFAULT', 'bottle'): + key = section + '.' + key + self[key] = value + return self + + def load_dict(self, source, namespace=''): + ''' Load values from a dictionary structure. Nesting can be used to + represent namespaces. + + >>> c.load_dict({'some': {'namespace': {'key': 'value'} } }) + {'some.namespace.key': 'value'} + ''' + for key, value in source.items(): + if isinstance(key, str): + nskey = (namespace + '.' + key).strip('.') + if isinstance(value, dict): + self.load_dict(value, namespace=nskey) + else: + self[nskey] = value + else: + raise TypeError('Key has type %r (not a string)' % type(key)) + return self + + def update(self, *a, **ka): + ''' If the first parameter is a string, all keys are prefixed with this + namespace. Apart from that it works just as the usual dict.update(). + Example: ``update('some.namespace', key='value')`` ''' + prefix = '' + if a and isinstance(a[0], str): + prefix = a[0].strip('.') + '.' + a = a[1:] + for key, value in dict(*a, **ka).items(): + self[prefix+key] = value + + def setdefault(self, key, value): + if key not in self: + self[key] = value + + def __setitem__(self, key, value): + if not isinstance(key, str): + raise TypeError('Key has type %r (not a string)' % type(key)) + value = self.meta_get(key, 'filter', lambda x: x)(value) + if key in self and self[key] is value: + return + self._on_change(key, value) + dict.__setitem__(self, key, value) + + def __delitem__(self, key): + self._on_change(key, None) + dict.__delitem__(self, key) + + def meta_get(self, key, metafield, default=None): + ''' Return the value of a meta field for a key. ''' + return self._meta.get(key, {}).get(metafield, default) + + def meta_set(self, key, metafield, value): + ''' Set the meta field for a key to a new value. This triggers the + on-change handler for existing keys. ''' + self._meta.setdefault(key, {})[metafield] = value + if key in self: + self[key] = self[key] + + def meta_list(self, key): + ''' Return an iterable of meta field names defined for a key. ''' + return self._meta.get(key, {}).keys() + + # Deprecated ConfigDict features def __getattr__(self, key): + depr('Attribute access is deprecated.') #0.12 if key not in self and key[0].isupper(): self[key] = ConfigDict() return self.get(key) def __setattr__(self, key, value): + if key in self.__slots__: + return dict.__setattr__(self, key, value) + 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], ConfigDict): @@ -1907,10 +2097,12 @@ if key in self: del self[key] def __call__(self, *a, **ka): - for key, value in dict(*a, **ka).items(): setattr(self, key, value) + depr('Calling ConfDict is deprecated. Use the update() method.') #0.12 + self.update(*a, **ka) return self + class AppStack(list): """ A stack-like list. Calling it returns the head of the stack. """ @@ -1941,6 +2133,22 @@ yield part +class _closeiter(object): + ''' This only exists to be able to attach a .close method to iterators that + do not support attribute assignment (most of itertools). ''' + + def __init__(self, iterator, close=None): + self.iterator = iterator + self.close_callbacks = makelist(close) + + def __iter__(self): + return iter(self.iterator) + + def close(self): + for func in self.close_callbacks: + func() + + class ResourceManager(object): ''' This class manages a list of search paths and helps to find and open application-bound resources (files). @@ -2024,7 +2232,68 @@ ''' Find a resource and return a file object, or raise IOError. ''' fname = self.lookup(name) if not fname: raise IOError("Resource %r not found." % name) - return self.opener(name, mode=mode, *args, **kwargs) + return self.opener(fname, mode=mode, *args, **kwargs) + + +class FileUpload(object): + + def __init__(self, fileobj, name, filename, headers=None): + ''' Wrapper for file uploads. ''' + #: Open file(-like) object (BytesIO buffer or temporary file) + self.file = fileobj + #: Name of the upload form field + self.name = name + #: Raw filename as sent by the client (may contain unsafe characters) + self.raw_filename = filename + #: A :class:`HeaderDict` with additional headers (e.g. content-type) + self.headers = HeaderDict(headers) if headers else HeaderDict() + + content_type = HeaderProperty('Content-Type') + content_length = HeaderProperty('Content-Length', reader=int, default=-1) + + @cached_property + def filename(self): + ''' Name of the file on the client file system, but normalized to ensure + file system compatibility (lowercase, no whitespace, no path + separators, no unsafe characters, ASCII only). An empty filename + is returned as 'empty'. + ''' + from unicodedata import normalize #TODO: Module level import? + fname = self.raw_filename + if isinstance(fname, unicode): + fname = normalize('NFKD', fname).encode('ASCII', 'ignore') + fname = fname.decode('ASCII', 'ignore') + fname = os.path.basename(fname.replace('\\', os.path.sep)) + fname = re.sub(r'[^a-zA-Z0-9-_.\s]', '', fname).strip().lower() + fname = re.sub(r'[-\s]+', '-', fname.strip('.').strip()) + return fname or 'empty' + + def _copy_file(self, fp, chunk_size=2**16): + read, write, offset = self.file.read, fp.write, self.file.tell() + while 1: + buf = read(chunk_size) + if not buf: break + write(buf) + self.file.seek(offset) + + def save(self, destination, overwrite=False, chunk_size=2**16): + ''' Save file to disk or copy its content to an open file(-like) object. + If *destination* is a directory, :attr:`filename` is added to the + path. Existing files are not overwritten by default (IOError). + + :param destination: File path, directory or file(-like) object. + :param overwrite: If True, replace existing files. (default: False) + :param chunk_size: Bytes to read at a time. (default: 64kb) + ''' + if isinstance(destination, basestring): # Except file-likes here + if os.path.isdir(destination): + destination = os.path.join(destination, self.filename) + if not overwrite and os.path.exists(destination): + raise IOError('File exists.') + with open(destination, 'wb') as fp: + self._copy_file(fp, chunk_size) + else: + self._copy_file(destination, chunk_size) @@ -2036,7 +2305,7 @@ ############################################################################### -def abort(code=500, text='Unknown Error: Application stopped.'): +def abort(code=500, text='Unknown Error.'): """ Aborts execution and causes a HTTP error. """ raise HTTPError(code, text) @@ -2044,12 +2313,12 @@ def redirect(url, code=None): """ Aborts execution and causes a 303 or 302 redirect, depending on the HTTP protocol version. """ - if code is None: + if not code: code = 303 if request.get('SERVER_PROTOCOL') == "HTTP/1.1" else 302 - location = urljoin(request.url, url) - res = HTTPResponse("", status=code, Location=location) - if response._cookies: - res._cookies = response._cookies + res = response.copy(cls=HTTPResponse) + res.status = code + res.body = "" + res.set_header('Location', urljoin(request.url, url)) raise res @@ -2063,12 +2332,26 @@ yield part -def static_file(filename, root, mimetype='auto', download=False): +def static_file(filename, root, mimetype='auto', download=False, charset='UTF-8'): """ Open a file in a safe way and return :exc:`HTTPResponse` with status - code 200, 305, 401 or 404. Set Content-Type, Content-Encoding, - Content-Length and Last-Modified header. Obey If-Modified-Since header - and HEAD requests. + code 200, 305, 401 or 404. The ``Content-Type``, ``Content-Encoding``, + ``Content-Length`` and ``Last-Modified`` headers are set if possible. + Special support for ``If-Modified-Since``, ``Range`` and ``HEAD`` + requests. + + :param filename: Name or path of the file to send. + :param root: Root path for file lookups. Should be an absolute directory + path. + :param mimetype: Defines the content-type header (default: guess from + file extension) + :param download: If True, ask the browser to open a `Save as...` dialog + instead of opening the file with the associated program. You can + specify a custom filename as a string. If not specified, the + original filename is used (default: False). + :param charset: The charset to use for files with a ``text/*`` + mime-type. (default: UTF-8) """ + root = os.path.abspath(root) + os.sep filename = os.path.abspath(os.path.join(root, filename.strip('/\\'))) headers = dict() @@ -2082,9 +2365,11 @@ if mimetype == 'auto': mimetype, encoding = mimetypes.guess_type(filename) - if mimetype: headers['Content-Type'] = mimetype if encoding: headers['Content-Encoding'] = encoding - elif mimetype: + + if mimetype: + if mimetype[:5] == 'text/' and charset and 'charset' not in mimetype: + mimetype += '; charset=%s' % charset headers['Content-Type'] = mimetype if download: @@ -2132,8 +2417,17 @@ """ Change the debug level. There is only one debug level supported at the moment.""" global DEBUG + if mode: warnings.simplefilter('default') DEBUG = bool(mode) +def http_date(value): + if isinstance(value, (datedate, datetime)): + value = value.utctimetuple() + elif isinstance(value, (int, float)): + value = time.gmtime(value) + if not isinstance(value, basestring): + value = time.strftime("%a, %d %b %Y %H:%M:%S GMT", value) + return value def parse_date(ims): """ Parse rfc1123, rfc850 and asctime timestamps and return UTC epoch. """ @@ -2143,7 +2437,6 @@ except (TypeError, ValueError, IndexError, OverflowError): return None - def parse_auth(header): """ Parse rfc2617 HTTP authentication header string (basic) and return (user,pass) tuple or None""" try: @@ -2229,18 +2522,17 @@ takes optional keyword arguments. The output is best described by example:: a() -> '/a' - b(x, y) -> '/b/:x/:y' - c(x, y=5) -> '/c/:x' and '/c/:x/:y' - d(x=5, y=6) -> '/d' and '/d/:x' and '/d/:x/:y' + b(x, y) -> '/b//' + c(x, y=5) -> '/c/' and '/c//' + d(x=5, y=6) -> '/d' and '/d/' and '/d//' """ - import inspect # Expensive module. Only import if necessary. path = '/' + func.__name__.replace('__','/').lstrip('/') - spec = inspect.getargspec(func) + spec = getargspec(func) argc = len(spec[0]) - len(spec[3] or []) - path += ('/:%s' * argc) % tuple(spec[0][:argc]) + path += ('/<%s>' * argc) % tuple(spec[0][:argc]) yield path for arg in spec[0][argc:]: - path += '/:%s' % arg + path += '/<%s>' % arg yield path @@ -2275,38 +2567,18 @@ return new_script_name, new_path_info -def validate(**vkargs): - """ - Validates and manipulates keyword arguments by user defined callables. - Handles ValueError and missing arguments by raising HTTPError(403). - """ - depr('Use route wildcard filters instead.') - def decorator(func): - @functools.wraps(func) - def wrapper(*args, **kargs): - for key, value in vkargs.items(): - if key not in kargs: - abort(403, 'Missing parameter: %s' % key) - try: - kargs[key] = value(kargs[key]) - except ValueError: - abort(403, 'Wrong parameter format for: %s' % key) - return func(*args, **kargs) - return wrapper - return decorator - - def auth_basic(check, realm="private", text="Access denied"): ''' Callback decorator to require HTTP auth (basic). TODO: Add route(check_auth=...) parameter. ''' def decorator(func): - def wrapper(*a, **ka): - user, password = request.auth or (None, None) - if user is None or not check(user, password): - response.headers['WWW-Authenticate'] = 'Basic realm="%s"' % realm - return HTTPError(401, text) - return func(*a, **ka) - return wrapper + def wrapper(*a, **ka): + user, password = request.auth or (None, None) + if user is None or not check(user, password): + err = HTTPError(401, text) + err.add_header('WWW-Authenticate', 'Basic realm="%s"' % realm) + return err + return func(*a, **ka) + return wrapper return decorator @@ -2345,8 +2617,8 @@ class ServerAdapter(object): quiet = False - def __init__(self, host='127.0.0.1', port=8080, **config): - self.options = config + def __init__(self, host='127.0.0.1', port=8080, **options): + self.options = options self.host = host self.port = int(port) @@ -2376,20 +2648,49 @@ class WSGIRefServer(ServerAdapter): - def run(self, handler): # pragma: no cover - from wsgiref.simple_server import make_server, WSGIRequestHandler - if self.quiet: - class QuietHandler(WSGIRequestHandler): - def log_request(*args, **kw): pass - self.options['handler_class'] = QuietHandler - srv = make_server(self.host, self.port, handler, **self.options) + def run(self, app): # pragma: no cover + from wsgiref.simple_server import WSGIRequestHandler, WSGIServer + from wsgiref.simple_server import make_server + import socket + + class FixedHandler(WSGIRequestHandler): + def address_string(self): # Prevent reverse DNS lookups please. + return self.client_address[0] + def log_request(*args, **kw): + if not self.quiet: + return WSGIRequestHandler.log_request(*args, **kw) + + handler_cls = self.options.get('handler_class', FixedHandler) + server_cls = self.options.get('server_class', WSGIServer) + + if ':' in self.host: # Fix wsgiref for IPv6 addresses. + if getattr(server_cls, 'address_family') == socket.AF_INET: + class server_cls(server_cls): + address_family = socket.AF_INET6 + + srv = make_server(self.host, self.port, app, server_cls, handler_cls) srv.serve_forever() class CherryPyServer(ServerAdapter): def run(self, handler): # pragma: no cover from cherrypy import wsgiserver - server = wsgiserver.CherryPyWSGIServer((self.host, self.port), handler) + self.options['bind_addr'] = (self.host, self.port) + self.options['wsgi_app'] = handler + + certfile = self.options.get('certfile') + if certfile: + del self.options['certfile'] + keyfile = self.options.get('keyfile') + if keyfile: + del self.options['keyfile'] + + server = wsgiserver.CherryPyWSGIServer(**self.options) + if certfile: + server.ssl_certificate = certfile + if keyfile: + server.ssl_private_key = keyfile + try: server.start() finally: @@ -2405,9 +2706,8 @@ class PasteServer(ServerAdapter): def run(self, handler): # pragma: no cover from paste import httpserver - if not self.quiet: - from paste.translogger import TransLogger - handler = TransLogger(handler) + from paste.translogger import TransLogger + handler = TransLogger(handler, setup_console_handler=(not self.quiet)) httpserver.serve(handler, host=self.host, port=str(self.port), **self.options) @@ -2447,7 +2747,7 @@ import tornado.wsgi, tornado.httpserver, tornado.ioloop container = tornado.wsgi.WSGIContainer(handler) server = tornado.httpserver.HTTPServer(container) - server.listen(port=self.port) + server.listen(port=self.port,address=self.host) tornado.ioloop.IOLoop.instance().start() @@ -2491,15 +2791,28 @@ * `fast` (default: False) uses libevent's http server, but has some issues: No streaming, no pipelining, no SSL. + * See gevent.wsgi.WSGIServer() documentation for more options. """ def run(self, handler): from gevent import wsgi, pywsgi, local - if not isinstance(_lctx, local.local): + if not isinstance(threading.local(), local.local): msg = "Bottle requires gevent.monkey.patch_all() (before import)" raise RuntimeError(msg) - if not self.options.get('fast'): wsgi = pywsgi - log = None if self.quiet else 'default' - wsgi.WSGIServer((self.host, self.port), handler, log=log).serve_forever() + if not self.options.pop('fast', None): wsgi = pywsgi + self.options['log'] = None if self.quiet else 'default' + address = (self.host, self.port) + server = wsgi.WSGIServer(address, handler, **self.options) + if 'BOTTLE_CHILD' in os.environ: + import signal + signal.signal(signal.SIGINT, lambda s, f: server.stop()) + server.serve_forever() + + +class GeventSocketIOServer(ServerAdapter): + def run(self,handler): + from socketio import server + address = (self.host, self.port) + server.SocketIOServer(address, handler, **self.options).serve_forever() class GunicornServer(ServerAdapter): @@ -2573,6 +2886,7 @@ 'gunicorn': GunicornServer, 'eventlet': EventletServer, 'gevent': GeventServer, + 'geventSocketIO':GeventSocketIOServer, 'rocket': RocketServer, 'bjoern' : BjoernServer, 'auto': AutoServer, @@ -2624,7 +2938,7 @@ _debug = debug def run(app=None, server='wsgiref', host='127.0.0.1', port=8080, interval=1, reloader=False, quiet=False, plugins=None, - debug=False, **kargs): + debug=None, **kargs): """ Start a server instance. This method blocks until the server terminates. :param app: WSGI application or target string supported by @@ -2667,7 +2981,7 @@ return try: - _debug(debug) + if debug is not None: _debug(debug) app = app or default_app() if isinstance(app, basestring): app = load_app(app) @@ -2805,11 +3119,11 @@ """ Search name in all directories specified in lookup. First without, then with common extensions. Return first hit. """ if not lookup: - depr('The template lookup path list should not be empty.') + depr('The template lookup path list should not be empty.') #0.12 lookup = ['.'] if os.path.isabs(name) and os.path.isfile(name): - depr('Absolute template path names are deprecated.') + depr('Absolute template path names are deprecated.') #0.12 return os.path.abspath(name) for spath in lookup: @@ -2841,8 +3155,8 @@ """ Render the template with the specified local variables and return a single byte or unicode string. If it is a byte string, the encoding must match self.encoding. This method must be thread-safe! - Local variables may be provided in dictionaries (*args) - or directly, as keywords (**kwargs). + Local variables may be provided in dictionaries (args) + or directly, as keywords (kwargs). """ raise NotImplementedError @@ -2913,184 +3227,240 @@ return f.read().decode(self.encoding) -class SimpleTALTemplate(BaseTemplate): - ''' Deprecated, do not use. ''' - def prepare(self, **options): - depr('The SimpleTAL template handler is deprecated'\ - ' and will be removed in 0.12') - from simpletal import simpleTAL - if self.source: - self.tpl = simpleTAL.compileHTMLTemplate(self.source) - else: - with open(self.filename, 'rb') as fp: - self.tpl = simpleTAL.compileHTMLTemplate(tonat(fp.read())) - - def render(self, *args, **kwargs): - from simpletal import simpleTALES - for dictarg in args: kwargs.update(dictarg) - context = simpleTALES.Context() - for k,v in self.defaults.items(): - context.addGlobal(k, v) - for k,v in kwargs.items(): - context.addGlobal(k, v) - output = StringIO() - self.tpl.expand(context, output) - return output.getvalue() - - class SimpleTemplate(BaseTemplate): - blocks = ('if', 'elif', 'else', 'try', 'except', 'finally', 'for', 'while', - 'with', 'def', 'class') - dedent_blocks = ('elif', 'else', 'except', 'finally') - - @lazy_attribute - def re_pytokens(cls): - ''' This matches comments and all kinds of quoted strings but does - NOT match comments (#...) within quoted strings. (trust me) ''' - return re.compile(r''' - (''(?!')|""(?!")|'{6}|"{6} # Empty strings (all 4 types) - |'(?:[^\\']|\\.)+?' # Single quotes (') - |"(?:[^\\"]|\\.)+?" # Double quotes (") - |'{3}(?:[^\\]|\\.|\n)+?'{3} # Triple-quoted strings (') - |"{3}(?:[^\\]|\\.|\n)+?"{3} # Triple-quoted strings (") - |\#.* # Comments - )''', re.VERBOSE) - def prepare(self, escape_func=html_escape, noescape=False, **kwargs): + def prepare(self, escape_func=html_escape, noescape=False, syntax=None, **ka): self.cache = {} enc = self.encoding self._str = lambda x: touni(x, enc) self._escape = lambda x: escape_func(touni(x, enc)) + self.syntax = syntax if noescape: self._str, self._escape = self._escape, self._str - @classmethod - def split_comment(cls, code): - """ Removes comments (#...) from python code. """ - if '#' not in code: return code - #: Remove comments only (leave quoted strings as they are) - subf = lambda m: '' if m.group(0)[0]=='#' else m.group(0) - return re.sub(cls.re_pytokens, subf, code) - @cached_property def co(self): return compile(self.code, self.filename or '', 'exec') @cached_property def code(self): - stack = [] # Current Code indentation - lineno = 0 # Current line of code - ptrbuffer = [] # Buffer for printable strings and token tuple instances - codebuffer = [] # Buffer for generated python code - multiline = dedent = oneline = False - template = self.source or open(self.filename, 'rb').read() - - def yield_tokens(line): - for i, part in enumerate(re.split(r'\{\{(.*?)\}\}', line)): - if i % 2: - if part.startswith('!'): yield 'RAW', part[1:] - else: yield 'CMD', part - else: yield 'TXT', part - - def flush(): # Flush the ptrbuffer - if not ptrbuffer: return - cline = '' - for line in ptrbuffer: - for token, value in line: - if token == 'TXT': cline += repr(value) - elif token == 'RAW': cline += '_str(%s)' % value - elif token == 'CMD': cline += '_escape(%s)' % value - cline += ', ' - cline = cline[:-2] + '\\\n' - cline = cline[:-2] - if cline[:-1].endswith('\\\\\\\\\\n'): - cline = cline[:-7] + cline[-1] # 'nobr\\\\\n' --> 'nobr' - cline = '_printlist([' + cline + '])' - del ptrbuffer[:] # Do this before calling code() again - code(cline) - - def code(stmt): - for line in stmt.splitlines(): - codebuffer.append(' ' * len(stack) + line.strip()) - - for line in template.splitlines(True): - lineno += 1 - line = touni(line, self.encoding) - sline = line.lstrip() - if lineno <= 2: - m = re.match(r"%\s*#.*coding[:=]\s*([-\w.]+)", sline) - if m: self.encoding = m.group(1) - if m: line = line.replace('coding','coding (removed)') - if sline and sline[0] == '%' and sline[:2] != '%%': - line = line.split('%',1)[1].lstrip() # Full line following the % - cline = self.split_comment(line).strip() - cmd = re.split(r'[^a-zA-Z0-9_]', cline)[0] - flush() # You are actually reading this? Good luck, it's a mess :) - if cmd in self.blocks or multiline: - cmd = multiline or cmd - dedent = cmd in self.dedent_blocks # "else:" - if dedent and not oneline and not multiline: - cmd = stack.pop() - code(line) - oneline = not cline.endswith(':') # "if 1: pass" - multiline = cmd if cline.endswith('\\') else False - if not oneline and not multiline: - stack.append(cmd) - elif cmd == 'end' and stack: - code('#end(%s) %s' % (stack.pop(), line.strip()[3:])) - elif cmd == 'include': - p = cline.split(None, 2)[1:] - if len(p) == 2: - code("_=_include(%s, _stdout, %s)" % (repr(p[0]), p[1])) - elif p: - code("_=_include(%s, _stdout)" % repr(p[0])) - else: # Empty %include -> reverse of %rebase - code("_printlist(_base)") - elif cmd == 'rebase': - p = cline.split(None, 2)[1:] - if len(p) == 2: - code("globals()['_rebase']=(%s, dict(%s))" % (repr(p[0]), p[1])) - elif p: - code("globals()['_rebase']=(%s, {})" % repr(p[0])) - else: - code(line) - else: # Line starting with text (not '%') or '%%' (escaped) - if line.strip().startswith('%%'): - line = line.replace('%%', '%', 1) - ptrbuffer.append(yield_tokens(line)) - flush() - return '\n'.join(codebuffer) + '\n' - - def subtemplate(self, _name, _stdout, *args, **kwargs): - for dictarg in args: kwargs.update(dictarg) + source = self.source or open(self.filename, 'rb').read() + try: + source, encoding = touni(source), 'utf8' + except UnicodeError: + depr('Template encodings other than utf8 are no longer supported.') #0.11 + source, encoding = touni(source, 'latin1'), 'latin1' + parser = StplParser(source, encoding=encoding, syntax=self.syntax) + code = parser.translate() + self.encoding = parser.encoding + return code + + def _rebase(self, _env, _name=None, **kwargs): + if _name is None: + depr('Rebase function called without arguments.' + ' You were probably looking for {{base}}?', True) #0.12 + _env['_rebase'] = (_name, kwargs) + + def _include(self, _env, _name=None, **kwargs): + if _name is None: + 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(_stdout, kwargs) + return self.cache[_name].execute(env['_stdout'], env) - def execute(self, _stdout, *args, **kwargs): - for dictarg in args: kwargs.update(dictarg) + def execute(self, _stdout, kwargs): env = self.defaults.copy() - env.update({'_stdout': _stdout, '_printlist': _stdout.extend, - '_include': self.subtemplate, '_str': self._str, - '_escape': self._escape, 'get': env.get, - 'setdefault': env.setdefault, 'defined': env.__contains__}) env.update(kwargs) + env.update({'_stdout': _stdout, '_printlist': _stdout.extend, + 'include': functools.partial(self._include, env), + 'rebase': functools.partial(self._rebase, env), '_rebase': None, + '_str': self._str, '_escape': self._escape, 'get': env.get, + 'setdefault': env.setdefault, 'defined': env.__contains__ }) eval(self.co, env) - if '_rebase' in env: - subtpl, rargs = env['_rebase'] - rargs['_base'] = _stdout[:] #copy stdout + if env.get('_rebase'): + subtpl, rargs = env.pop('_rebase') + rargs['base'] = ''.join(_stdout) #copy stdout del _stdout[:] # clear stdout - return self.subtemplate(subtpl,_stdout,rargs) + return self._include(env, subtpl, **rargs) return env def render(self, *args, **kwargs): """ Render the template using keyword arguments as local variables. """ - for dictarg in args: kwargs.update(dictarg) - stdout = [] - self.execute(stdout, kwargs) + env = {}; stdout = [] + for dictarg in args: env.update(dictarg) + env.update(kwargs) + self.execute(stdout, env) return ''.join(stdout) +class StplSyntaxError(TemplateError): pass + + +class StplParser(object): + ''' Parser for stpl templates. ''' + _re_cache = {} #: Cache for compiled re patterns + # This huge pile of voodoo magic splits python code into 8 different tokens. + # 1: All kinds of python strings (trust me, it works) + _re_tok = '((?m)[urbURB]?(?:\'\'(?!\')|""(?!")|\'{6}|"{6}' \ + '|\'(?:[^\\\\\']|\\\\.)+?\'|"(?:[^\\\\"]|\\\\.)+?"' \ + '|\'{3}(?:[^\\\\]|\\\\.|\\n)+?\'{3}' \ + '|"{3}(?:[^\\\\]|\\\\.|\\n)+?"{3}))' + _re_inl = _re_tok.replace('|\\n','') # We re-use this string pattern later + # 2: Comments (until end of line, but not the newline itself) + _re_tok += '|(#.*)' + # 3,4: Keywords that start or continue a python block (only start of line) + _re_tok += '|^([ \\t]*(?:if|for|while|with|try|def|class)\\b)' \ + '|^([ \\t]*(?:elif|else|except|finally)\\b)' + # 5: Our special 'end' keyword (but only if it stands alone) + _re_tok += '|((?:^|;)[ \\t]*end[ \\t]*(?=(?:%(block_close)s[ \\t]*)?\\r?$|;|#))' + # 6: A customizable end-of-code-block template token (only end of line) + _re_tok += '|(%(block_close)s[ \\t]*(?=$))' + # 7: And finally, a single newline. The 8th token is 'everything else' + _re_tok += '|(\\r?\\n)' + # Match the start tokens of code areas in a template + _re_split = '(?m)^[ \t]*(\\\\?)((%(line_start)s)|(%(block_start)s))(%%?)' + # Match inline statements (may contain python strings) + _re_inl = '%%(inline_start)s((?:%s|[^\'"\n]*?)+)%%(inline_end)s' % _re_inl + + default_syntax = '<% %> % {{ }}' + + def __init__(self, source, syntax=None, encoding='utf8'): + self.source, self.encoding = touni(source, encoding), encoding + self.set_syntax(syntax or self.default_syntax) + self.code_buffer, self.text_buffer = [], [] + self.lineno, self.offset = 1, 0 + self.indent, self.indent_mod = 0, 0 + + def get_syntax(self): + ''' Tokens as a space separated string (default: <% %> % {{ }}) ''' + return self._syntax + + def set_syntax(self, syntax): + self._syntax = syntax + self._tokens = syntax.split() + if not syntax in self._re_cache: + names = 'block_start block_close line_start inline_start inline_end' + etokens = map(re.escape, self._tokens) + pattern_vars = dict(zip(names.split(), etokens)) + patterns = (self._re_split, self._re_tok, self._re_inl) + patterns = [re.compile(p%pattern_vars) for p in patterns] + self._re_cache[syntax] = patterns + self.re_split, self.re_tok, self.re_inl = self._re_cache[syntax] + + syntax = property(get_syntax, set_syntax) + + 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 + 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) + + def read_code(self, multiline): + code_line, comment, start_line = '', '', self.lineno + while True: + m = self.re_tok.search(self.source[self.offset:]) + if not m: + code_line += self.source[self.offset:] + self.offset = len(self.source) + self.write_code(code_line.strip(), comment) + return + code_line += self.source[self.offset:self.offset+m.start()] + self.offset += m.end() + _str, _com, _blk1, _blk2, _end, _cend, _nl = m.groups() + if _str: # Python string + code_line += _str + elif _com: # Python comment (up to EOL) + comment = _com + if multiline and _com.strip().endswith(self._tokens[1]): + multiline = False # Allow end-of-block in comments + elif _blk1: # Start-block keyword (if/for/while/def/try/...) + code_line, self.indent_mod = _blk1, -1 + self.indent += 1 + elif _blk2: # Continue-block keyword (else/elif/except/...) + code_line, self.indent_mod = _blk2, -1 + elif _end: # The non-standard 'end'-keyword (ends a block) + self.indent -= 1 + elif _cend: # The end-code-block template token (usually '%>') + if multiline: multiline = False + else: code_line += _cend + else: # \n + self.write_code(code_line.strip(), comment) + self.lineno += 1 + code_line, comment, self.indent_mod = '', '', 0 + if not multiline: + break + + def flush_text(self): + text = ''.join(self.text_buffer) + del self.text_buffer[:] + if not text: return + parts, pos, nl = [], 0, '\\\n'+' '*self.indent + for m in self.re_inl.finditer(text): + prefix, pos = text[pos:m.start()], m.end() + if prefix: + parts.append(nl.join(map(repr, prefix.splitlines(True)))) + if prefix.endswith('\n'): parts[-1] += nl + parts.append(self.process_inline(m.group(1).strip())) + if pos < len(text): + prefix = text[pos:] + lines = prefix.splitlines(True) + if lines[-1].endswith('\\\\\n'): lines[-1] = lines[-1][:-3] + parts.append(nl.join(map(repr, lines))) + code = '_printlist((%s,))' % ', '.join(parts) + self.lineno += code.count('\n')+1 + self.write_code(code) + + def process_inline(self, chunk): + if chunk[0] == '!': return '_str(%s)' % chunk[1:] + return '_escape(%s)' % chunk + + def write_code(self, line, comment=''): + line, comment = self.fix_backward_compatibility(line, comment) + code = ' ' * (self.indent+self.indent_mod) + code += line.lstrip() + comment + '\n' + self.code_buffer.append(code) + + def fix_backward_compatibility(self, line, comment): + parts = line.strip().split(None, 2) + if parts and parts[0] in ('include', 'rebase'): + 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 = re.match(r"#.*coding[:=]\s*([-\w.]+)", comment) + if m: + 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 + + def template(*args, **kwargs): ''' Get a rendered template as a string iterator. @@ -3119,7 +3489,6 @@ mako_template = functools.partial(template, template_adapter=MakoTemplate) cheetah_template = functools.partial(template, template_adapter=CheetahTemplate) jinja2_template = functools.partial(template, template_adapter=Jinja2Template) -simpletal_template = functools.partial(template, template_adapter=SimpleTALTemplate) def view(tpl_name, **defaults): @@ -3140,6 +3509,8 @@ tplvars = defaults.copy() tplvars.update(result) return template(tpl_name, **tplvars) + elif result is None: + return template(tpl_name, defaults) return result return wrapper return decorator @@ -3147,7 +3518,6 @@ mako_view = functools.partial(view, template_adapter=MakoTemplate) cheetah_view = functools.partial(view, template_adapter=CheetahTemplate) jinja2_view = functools.partial(view, template_adapter=Jinja2Template) -simpletal_view = functools.partial(view, template_adapter=SimpleTALTemplate) @@ -3244,10 +3614,11 @@ sys.modules.setdefault('bottle', sys.modules['__main__']) host, port = (opt.bind or 'localhost'), 8080 - if ':' in host: + if ':' in host and host.rfind(']') < host.rfind(':'): host, port = host.rsplit(':', 1) + host = host.strip('[]') - run(args[0], host=host, port=port, server=opt.server, + run(args[0], host=host, port=int(port), server=opt.server, reloader=opt.reload, plugins=opt.plugin, debug=opt.debug) diff -Nru python-bottle-0.11.6/debian/changelog python-bottle-0.12.0/debian/changelog --- python-bottle-0.11.6/debian/changelog 2013-05-06 20:05:57.000000000 +0000 +++ python-bottle-0.12.0/debian/changelog 2014-01-06 17:44:57.000000000 +0000 @@ -1,3 +1,10 @@ +python-bottle (0.12.0-1) unstable; urgency=medium + + [ Federico Ceratto ] + * New upstream version + + -- David Paleino Mon, 06 Jan 2014 18:44:50 +0100 + python-bottle (0.11.6-1) unstable; urgency=low * d/changelog: New upstream release 0.11.6 diff -Nru python-bottle-0.11.6/debian/control python-bottle-0.12.0/debian/control --- python-bottle-0.11.6/debian/control 2013-05-06 20:05:57.000000000 +0000 +++ python-bottle-0.12.0/debian/control 2014-01-06 17:44:57.000000000 +0000 @@ -7,6 +7,9 @@ debhelper (>= 9~) Build-Depends-Indep: python-all (>= 2.6.6-3~) + , python3-all + , python-doc + , dh-python , python-sphinx # needed for build-time tests , python-cherrypy @@ -15,18 +18,19 @@ , python-gevent , python-jinja2 , python-mako - , python-nose , python-paste , python-simpletal , python-tornado + , python-tox , python-twisted , python-werkzeug -# , gunicorn + , gunicorn Standards-Version: 3.9.4 Homepage: http://bottlepy.org X-Python-Version: >= 2.5 -Vcs-Git: git://git.debian.org/git/collab-maint/python-bottle.git -Vcs-Browser: http://git.debian.org/?p=collab-maint/python-bottle.git +X-Python3-Version: >= 3.2 +Vcs-Git: git://anonscm.debian.org/collab-maint/python-bottle.git +Vcs-Browser: http://anonscm.debian.org/gitweb/?p=collab-maint/python-bottle.git Package: python-bottle Architecture: all @@ -40,11 +44,24 @@ (routes), templates, key/value databases, a built-in HTTP server and adapters for many third party WSGI/HTTP-server and template engines. +Package: python3-bottle +Architecture: all +Depends: + ${python3:Depends} + , ${misc:Depends} +Provides: ${python3:Provides} +Description: fast and simple WSGI-framework for Python3 + Bottle is a fast and simple WSGI-framework for the Python3 programming + language. It offers request dispatching with url parameter support + (routes), templates, key/value databases, a built-in HTTP server and + adapters for many third party WSGI/HTTP-server and template engines. + Package: python-bottle-doc Architecture: all Section: doc Depends: ${misc:Depends} + , ${sphinxdoc:Depends} , libjs-jquery , libjs-underscore Description: fast and simple WSGI-framework for Python - documentation diff -Nru python-bottle-0.11.6/debian/patches/0001-Remove-bottle.py-from-scripts.patch python-bottle-0.12.0/debian/patches/0001-Remove-bottle.py-from-scripts.patch --- python-bottle-0.11.6/debian/patches/0001-Remove-bottle.py-from-scripts.patch 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/debian/patches/0001-Remove-bottle.py-from-scripts.patch 2014-01-06 17:44:57.000000000 +0000 @@ -0,0 +1,20 @@ +From: Federico Ceratto +Date: Sun, 15 Dec 2013 01:41:56 +0000 +Subject: Remove bottle.py from scripts + +--- + setup.py | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/setup.py b/setup.py +index 8b83522..19392f8 100755 +--- a/setup.py ++++ b/setup.py +@@ -17,7 +17,6 @@ setup(name='bottle', + author_email='marc@gsites.de', + url='http://bottlepy.org/', + py_modules=['bottle'], +- scripts=['bottle.py'], + license='MIT', + platforms = 'any', + classifiers=['Development Status :: 4 - Beta', diff -Nru python-bottle-0.11.6/debian/patches/0002-Add-CLI-manpage.patch python-bottle-0.12.0/debian/patches/0002-Add-CLI-manpage.patch --- python-bottle-0.11.6/debian/patches/0002-Add-CLI-manpage.patch 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/debian/patches/0002-Add-CLI-manpage.patch 2014-01-06 17:44:57.000000000 +0000 @@ -0,0 +1,76 @@ +From: Federico Ceratto +Date: Sun, 15 Dec 2013 18:07:11 +0000 +Subject: Add CLI manpage + +--- + docs/cli.rst | 46 ++++++++++++++++++++++++++++++++++++++++++++++ + docs/conf.py | 6 ++++++ + 2 files changed, 52 insertions(+) + create mode 100755 docs/cli.rst + +diff --git a/docs/cli.rst b/docs/cli.rst +new file mode 100755 +index 0000000..39e2d2c +--- /dev/null ++++ b/docs/cli.rst +@@ -0,0 +1,46 @@ ++Command Line Interface ++-------------------------------------------------------------------------------- ++ ++.. versionadded: 0.10 ++ ++Starting with version 0.10 you can use bottle as a command-line tool: ++ ++.. code-block:: console ++ ++ $ python -m bottle ++ ++ Usage: bottle.py [options] package.module:app ++ ++ Options: ++ -h, --help show this help message and exit ++ --version show version number. ++ -b ADDRESS, --bind=ADDRESS ++ bind socket to ADDRESS. ++ -s SERVER, --server=SERVER ++ use SERVER as backend. ++ -p PLUGIN, --plugin=PLUGIN ++ install additional plugin/s. ++ --debug start server in debug mode. ++ --reload auto-reload on file changes. ++ ++The `ADDRESS` field takes an IP address or an IP:PORT pair and defaults to ``localhost:8080``. The other parameters should be self-explanatory. ++ ++Both plugins and applications are specified via import expressions. These consist of an import path (e.g. ``package.module``) and an expression to be evaluated in the namespace of that module, separated by a colon. See :func:`load` for details. Here are some examples: ++ ++.. code-block:: console ++ ++ # Grab the 'app' object from the 'myapp.controller' module and ++ # start a paste server on port 80 on all interfaces. ++ python -m bottle -server paste -bind 0.0.0.0:80 myapp.controller:app ++ ++ # Start a self-reloading development server and serve the global ++ # default application. The routes are defined in 'test.py' ++ python -m bottle --debug --reload test ++ ++ # Install a custom debug plugin with some parameters ++ python -m bottle --debug --reload --plugin 'utils:DebugPlugin(exc=True)'' test ++ ++ # Serve an application that is created with 'myapp.controller.make_app()' ++ # on demand. ++ python -m bottle 'myapp.controller:make_app()'' ++ +diff --git a/docs/conf.py b/docs/conf.py +index 4ede58a..ded2274 100644 +--- a/docs/conf.py ++++ b/docs/conf.py +@@ -20,3 +20,9 @@ intersphinx_mapping = {'python': ('http://docs.python.org/', None), + + autodoc_member_order = 'bysource' + ++man_pages = [ ++ ('cli', 'bottle', u'command line interface', [ ++ u'Marcel Hellkamp', ++ u'Federico Ceratto', ++ ], 1) ++] diff -Nru python-bottle-0.11.6/debian/patches/01-fix_quiet_parsing.patch python-bottle-0.12.0/debian/patches/01-fix_quiet_parsing.patch --- python-bottle-0.11.6/debian/patches/01-fix_quiet_parsing.patch 2013-05-06 20:05:57.000000000 +0000 +++ python-bottle-0.12.0/debian/patches/01-fix_quiet_parsing.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,19 +0,0 @@ -From: Enrico Zini -Subject: remove "quiet" from the args passed to the server adapter -Forwarded: no - ---- - bottle.py | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - ---- python-bottle.orig/bottle.py -+++ python-bottle/bottle.py -@@ -1225,7 +1225,7 @@ def run(app=None, server=AutoServer, hos - interval=1, reloader=False, **kargs): - """ Runs bottle as a web server. """ - app = app if app else default_app() -- quiet = bool(kargs.get('quiet', False)) -+ quiet = bool(kargs.pop('quiet', False)) - # Instantiate server, if it is a class instead of an instance - if isinstance(server, type): - server = server(host=host, port=port, **kargs) diff -Nru python-bottle-0.11.6/debian/patches/02-fix_autoserver_ordering.patch python-bottle-0.12.0/debian/patches/02-fix_autoserver_ordering.patch --- python-bottle-0.11.6/debian/patches/02-fix_autoserver_ordering.patch 2013-05-06 20:05:57.000000000 +0000 +++ python-bottle-0.12.0/debian/patches/02-fix_autoserver_ordering.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,21 +0,0 @@ -From: David Paleino -Subject: move CherryPyServer later in the list, given - that it sucks more. -Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=586316 -Forwarded: no - ---- - bottle.py | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - ---- python-bottle.orig/bottle.py -+++ python-bottle/bottle.py -@@ -1850,7 +1850,7 @@ class BjoernServer(ServerAdapter): - - class AutoServer(ServerAdapter): - """ Untested. """ -- adapters = [PasteServer, CherryPyServer, TwistedServer, WSGIRefServer] -+ adapters = [PasteServer, TwistedServer, CherryPyServer, WSGIRefServer] - def run(self, handler): - for sa in self.adapters: - try: diff -Nru python-bottle-0.11.6/debian/patches/03-fix_tests.patch python-bottle-0.12.0/debian/patches/03-fix_tests.patch --- python-bottle-0.11.6/debian/patches/03-fix_tests.patch 2013-05-06 20:05:57.000000000 +0000 +++ python-bottle-0.12.0/debian/patches/03-fix_tests.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,66 +0,0 @@ -From: David Paleino -Subject: fix various issues in the testsuite -Origin: vendor -Forwarded: no - ---- - run_tests.sh | 1 - - test/test_environ.py | 8 ++++---- - test/test_sendfile.py | 2 +- - test/test_server.py | 5 +++-- - 4 files changed, 8 insertions(+), 8 deletions(-) - ---- python-bottle.orig/test/test_server.py -+++ python-bottle/test/test_server.py -@@ -45,7 +45,7 @@ class TestServer(unittest.TestCase): - if not self.p.poll() is None: break - rv = self.p.poll() - if rv is None: -- raise AssertionError("Server took to long to start up.") -+ raise AssertionError("Server took too long to start up.") - if rv is 128: # Import error - tools.warn("Skipping %r test (ImportError)." % self.server) - self.skip = True -@@ -69,7 +69,7 @@ class TestServer(unittest.TestCase): - if tob('warning') in line.lower(): - tools.warn(line.strip().decode('utf8')) - elif tob('error') in line.lower(): -- raise AssertionError(line.strip().decode('utf8')) -+ raise AssertionError("%s: %s" % (self.server, line.strip().decode('utf8'))) - - def fetch(self, url): - try: ---- python-bottle.orig/run_tests.sh -+++ python-bottle/run_tests.sh -@@ -26,7 +26,6 @@ function runtest { - - - --runtest python2.5 test - runtest python2.6 test - runtest python2.7 test - ---- python-bottle.orig/test/test_environ.py -+++ python-bottle/test/test_environ.py -@@ -78,8 +78,8 @@ class TestRequest(unittest.TestCase): - request.bind(e) - request['HTTP_SOME_OTHER_HEADER'] = 'some other value' - self.assertTrue('Some-Header' in request.headers) -- self.assertTrue(request.header['Some-Header'] == 'some value') -- self.assertTrue(request.header['Some-Other-Header'] == 'some other value') -+ self.assertTrue(request.headers['Some-Header'] == 'some value') -+ self.assertTrue(request.headers['Some-Other-Header'] == 'some other value') - - def test_header_access_special(self): - e = {} -@@ -87,8 +87,8 @@ class TestRequest(unittest.TestCase): - request.bind(e) - request['CONTENT_TYPE'] = 'test' - request['CONTENT_LENGTH'] = '123' -- self.assertEqual(request.header['Content-Type'], 'test') -- self.assertEqual(request.header['Content-Length'], '123') -+ self.assertEqual(request.headers['Content-Type'], 'test') -+ self.assertEqual(request.headers['Content-Length'], '123') - - def test_cookie(self): - """ Environ: COOKIES """ diff -Nru python-bottle-0.11.6/debian/patches/series python-bottle-0.12.0/debian/patches/series --- python-bottle-0.11.6/debian/patches/series 2013-05-06 20:05:57.000000000 +0000 +++ python-bottle-0.12.0/debian/patches/series 2014-01-06 17:44:57.000000000 +0000 @@ -1,3 +1,2 @@ -#01-fix_quiet_parsing.patch -#02-fix_autoserver_ordering.patch -#03-fix_tests.patch +0001-Remove-bottle.py-from-scripts.patch +0002-Add-CLI-manpage.patch diff -Nru python-bottle-0.11.6/debian/python-bottle-doc.doc-base python-bottle-0.12.0/debian/python-bottle-doc.doc-base --- python-bottle-0.11.6/debian/python-bottle-doc.doc-base 2013-05-06 20:05:57.000000000 +0000 +++ python-bottle-0.12.0/debian/python-bottle-doc.doc-base 2014-01-06 17:44:57.000000000 +0000 @@ -4,5 +4,5 @@ Section: Programming/Python Format: HTML -Index: /usr/share/doc/python-bottle-doc/api/index.html -Files: /usr/share/doc/python-bottle-doc/api +Index: /usr/share/doc/python-bottle-doc/html/index.html +Files: /usr/share/doc/python-bottle-doc/html diff -Nru python-bottle-0.11.6/debian/python-bottle-doc.docs python-bottle-0.12.0/debian/python-bottle-doc.docs --- python-bottle-0.11.6/debian/python-bottle-doc.docs 2013-05-06 20:05:57.000000000 +0000 +++ python-bottle-0.12.0/debian/python-bottle-doc.docs 2014-01-06 17:44:57.000000000 +0000 @@ -1 +1 @@ -build/docs/dirhtml +build/html diff -Nru python-bottle-0.11.6/debian/python-bottle-doc.links python-bottle-0.12.0/debian/python-bottle-doc.links --- python-bottle-0.11.6/debian/python-bottle-doc.links 2013-05-06 20:05:57.000000000 +0000 +++ python-bottle-0.12.0/debian/python-bottle-doc.links 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -/usr/share/javascript/jquery/jquery.js usr/share/doc/python-bottle-doc/api/_static/jquery.js -/usr/share/javascript/underscore/underscore.js usr/share/doc/python-bottle-doc/api/_static/underscore.js diff -Nru python-bottle-0.11.6/debian/python-bottle-doc.manpages python-bottle-0.12.0/debian/python-bottle-doc.manpages --- python-bottle-0.11.6/debian/python-bottle-doc.manpages 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/debian/python-bottle-doc.manpages 2014-01-06 17:44:57.000000000 +0000 @@ -0,0 +1 @@ +build/man/bottle.1 diff -Nru python-bottle-0.11.6/debian/python-bottle.install python-bottle-0.12.0/debian/python-bottle.install --- python-bottle-0.11.6/debian/python-bottle.install 2013-05-06 20:05:57.000000000 +0000 +++ python-bottle-0.12.0/debian/python-bottle.install 2014-01-06 17:44:57.000000000 +0000 @@ -1 +0,0 @@ -usr/lib/python* diff -Nru python-bottle-0.11.6/debian/rules python-bottle-0.12.0/debian/rules --- python-bottle-0.11.6/debian/rules 2013-05-06 20:05:57.000000000 +0000 +++ python-bottle-0.12.0/debian/rules 2014-01-06 17:44:57.000000000 +0000 @@ -1,43 +1,22 @@ #!/usr/bin/make -f # -*- makefile -*- +export PYBUILD_NAME=bottle export DH_VERBOSE=1 -override_dh_auto_test: -ifeq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),) - for python in $(shell pyversions -r); do \ - echo "Running unit tests with $$python"; \ - $$python test/testall.py; \ - done -endif +%: + dh $@ --with python2,python3,sphinxdoc --buildsystem=pybuild --test-tox override_dh_auto_build: - dh_auto_build -Spython_distutils - for i in plugins/*; do \ - dh_auto_build -Spython_distutils -D$$i -Bbuild/; \ - done - $(MAKE) -C docs dirhtml - -override_dh_auto_install: - dh_auto_install -Spython_distutils - rm -rf $(CURDIR)/debian/python-bottle-doc/usr/share/doc/python-bottle-doc/api/_images/myface_small.png - -override_dh_installdocs: - dh_installdocs - mv $(CURDIR)/debian/python-bottle-doc/usr/share/doc/python-bottle-doc/dirhtml/ \ - $(CURDIR)/debian/python-bottle-doc/usr/share/doc/python-bottle-doc/api/ - -override_dh_compress: - dh_compress -Xpython-bottle-doc/api - -override_dh_auto_clean: - dh_auto_clean -Spython_distutils - $(MAKE) -C docs clean + dh_auto_build + PYTHONPATH=. http_proxy='http://127.0.0.1:9/' sphinx-build -N -bhtml docs/ build/html + PYTHONPATH=. http_proxy='http://127.0.0.1:9/' sphinx-build -N -bman docs/ build/man + rm -rf ./build/html/.doctrees override_dh_installchangelogs: dh_installchangelogs docs/changelog.rst - -%: - dh $@ \ - --with python2 +override_dh_auto_test: + #PYBUILD_SYSTEM=custom PYBUILD_TEST_ARGS="nosetests" dh_auto_test + #PYBUILD_SYSTEM=custom PYBUILD_TEST_ARGS="{interpreter} test/testall.py" dh_auto_test + python test/testall.py diff -Nru python-bottle-0.11.6/docs/Makefile python-bottle-0.12.0/docs/Makefile --- python-bottle-0.11.6/docs/Makefile 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/docs/Makefile 1970-01-01 00:00:00.000000000 +0000 @@ -1,156 +0,0 @@ -# Makefile for Sphinx documentation -# - -# You can set these variables from the command line. -SPHINXOPTS = -SPHINXBUILD = sphinx-build -PAPER = a4 -BUILDDIR = ../build/docs -SCRDIR = . - -# Internal variables. -PAPEROPT_a4 = -D latex_paper_size=a4 -PAPEROPT_letter = -D latex_paper_size=letter -ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) $(SCRDIR) -# the i18n builder cannot share the environment and doctrees with the others -I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) $(SCRDIR) - - -.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext - -help: - @echo "Please use \`make ' where is one of" - @echo " html to make standalone HTML files" - @echo " dirhtml to make HTML files named index.html in directories" - @echo " singlehtml to make a single large HTML file" - @echo " pickle to make pickle files" - @echo " json to make JSON files" - @echo " htmlhelp to make HTML files and a HTML help project" - @echo " qthelp to make HTML files and a qthelp project" - @echo " devhelp to make HTML files and a Devhelp project" - @echo " epub to make an epub" - @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" - @echo " latexpdf to make LaTeX files and run them through pdflatex" - @echo " text to make text files" - @echo " man to make manual pages" - @echo " texinfo to make Texinfo files" - @echo " info to make Texinfo files and run them through makeinfo" - @echo " gettext to make PO message catalogs" - @echo " changes to make an overview of all changed/added/deprecated items" - @echo " linkcheck to check all external links for integrity" - @echo " doctest to run all doctests embedded in the documentation (if enabled)" - -clean: - -rm -rf $(BUILDDIR)/* - -html: - $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html - @echo - @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." - -dirhtml: - $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml - @echo - @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." - -singlehtml: - $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml - @echo - @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." - -pickle: - $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle - @echo - @echo "Build finished; now you can process the pickle files." - -json: - $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json - @echo - @echo "Build finished; now you can process the JSON files." - -htmlhelp: - $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp - @echo - @echo "Build finished; now you can run HTML Help Workshop with the" \ - ".hhp project file in $(BUILDDIR)/htmlhelp." - -qthelp: - $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp - @echo - @echo "Build finished; now you can run "qcollectiongenerator" with the" \ - ".qhcp project file in $(BUILDDIR)/qthelp, like this:" - @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/%(project_fn)s.qhcp" - @echo "To view the help file:" - @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/%(project_fn)s.qhc" - -devhelp: - $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp - @echo - @echo "Build finished." - @echo "To view the help file:" - @echo "# mkdir -p $$HOME/.local/share/devhelp/%(project_fn)s" - @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/%(project_fn)s" - @echo "# devhelp" - -epub: - $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub - @echo - @echo "Build finished. The epub file is in $(BUILDDIR)/epub." - -latex: - $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex - @echo - @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." - @echo "Run \`make' in that directory to run these through (pdf)latex" \ - "(use \`make latexpdf' here to do that automatically)." - -latexpdf: - $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex - @echo "Running LaTeX files through pdflatex..." - make -C $(BUILDDIR)/latex all-pdf - @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." - -text: - $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text - @echo - @echo "Build finished. The text files are in $(BUILDDIR)/text." - -man: - $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man - @echo - @echo "Build finished. The manual pages are in $(BUILDDIR)/man." - -texinfo: - $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo - @echo - @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." - @echo "Run \`make' in that directory to run these through makeinfo" \ - "(use \`make info' here to do that automatically)." - -info: - $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo - @echo "Running Texinfo files through makeinfo..." - make -C $(BUILDDIR)/texinfo info - @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." - -gettext: - $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale - @echo - @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." - -changes: - $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes - @echo - @echo "The overview file is in $(BUILDDIR)/changes." - -linkcheck: - $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck - @echo - @echo "Link check complete; look for any errors in the above output " \ - "or in $(BUILDDIR)/linkcheck/output.txt." - -doctest: - $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest - @echo "Testing of doctests in the sources finished, look at the " \ - "results in $(BUILDDIR)/doctest/output.txt." - diff -Nru python-bottle-0.11.6/docs/_locale/README.txt python-bottle-0.12.0/docs/_locale/README.txt --- python-bottle-0.11.6/docs/_locale/README.txt 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/docs/_locale/README.txt 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,21 @@ +====================== +Requirements and Setup +====================== + +You need python-sphinx (pip install sphinx) and gettext (for msgmerge and msgfmt). +A translation file editor (e.g. poedit) helps a lot. + +Translation Workflow +==================== + +Run docs/_locale/update.sh before and after editing *.po files to merge new +sentences and check for errors. + +Do not add *.mo files to the repository, even if your editor creates them. +We only need the *.po files. + +Add a new language +================== + +Add your language (two-letter code) to 'update.sh' and run it. A new +two-letter directory will appear with all the *.po files in it. diff -Nru python-bottle-0.11.6/docs/_locale/update.sh python-bottle-0.12.0/docs/_locale/update.sh --- python-bottle-0.11.6/docs/_locale/update.sh 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/docs/_locale/update.sh 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,19 @@ +#!/bin/bash +cd "$( cd "$( dirname "$0" )" && pwd )" + +LANGUAGES='zh_CN' + +echo 'Generating new POT files ...' +sphinx-build -q -b gettext -E .. _pot + +echo 'Merging and compiling *.po files ...' +for LANG in $LANGUAGES; do + for POT in _pot/*.pot; do + DOC=`basename $POT .pot` + echo $LANG/$DOC.po + test -d $LANG/LC_MESSAGES || mkdir -p $LANG/LC_MESSAGES + test -f $LANG/$DOC.po || cp $POT $LANG/$DOC.po + msgmerge --quiet --backup=none -U $LANG/$DOC.po $POT + msgfmt $LANG/$DOC.po -o "$LANG/LC_MESSAGES/$DOC.mo" + done +done diff -Nru python-bottle-0.11.6/docs/_locale/zh_CN/api.po python-bottle-0.12.0/docs/_locale/zh_CN/api.po --- python-bottle-0.11.6/docs/_locale/zh_CN/api.po 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/docs/_locale/zh_CN/api.po 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,1417 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) 2009-2012, Marcel Hellkamp +# This file is distributed under the same license as the Bottle package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Bottle 0.12-dev\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-08-09 17:22\n" +"PO-Revision-Date: 2012-11-09 16:39+0800\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +# fbe35ab019974025ade6c7afb67ec0e9 +#: ../../api.rst:3 +msgid "API Reference" +msgstr "API参考" + +# 07f8bab761f04aea8b9c9ecd467acdff +#: ../../api.rst:10 +msgid "" +"This is a mostly auto-generated API. If you are new to bottle, you might " +"find the narrative :doc:`tutorial` more helpful." +msgstr "" +"这份文档几乎是全自动生成的。如果你刚接触bottle,也许 :doc:`tutorial` 会更有帮" +"助。" + +# 60b4c8f092624c28907f8e014404266e +#: ../../api.rst:17 +msgid "Module Contents" +msgstr "" + +# 623845929cb84fb3922263ab0e1cf6d6 +#: ../../api.rst:19 +msgid "The module defines several functions, constants, and an exception." +msgstr "" + +# 0360779739fe41d19735b61aa7654001 +#: ../../../bottle.py:docstring of bottle.debug:1 +msgid "" +"Change the debug level. There is only one debug level supported at the " +"moment." +msgstr "" + +# 644c0a8eb325483696b60bed16c2df4a +#: ../../../bottle.py:docstring of bottle.run:1 +msgid "" +"Start a server instance. This method blocks until the server terminates." +msgstr "" + +# ba4e497a63924813b2ab8457a1916492 +#: ../../../bottle.py:docstring of bottle.load:1 +msgid "Import a module or fetch an object from a module." +msgstr "" + +# 4d283ca03c2b4fdf8cfcd08dc8ade89f +#: ../../../bottle.py:docstring of bottle.load:3 +msgid "``package.module`` returns `module` as a module object." +msgstr "" + +# a4770e87e7f64c6e8ea511221fdda6d6 +#: ../../../bottle.py:docstring of bottle.load:4 +msgid "``pack.mod:name`` returns the module variable `name` from `pack.mod`." +msgstr "" + +# 8de14751c87f4652902fa858c868c1e2 +#: ../../../bottle.py:docstring of bottle.load:5 +msgid "``pack.mod:func()`` calls `pack.mod.func()` and returns the result." +msgstr "" + +# 0f4be93ee77340c89bd64e958f9522dd +#: ../../../bottle.py:docstring of bottle.load:7 +msgid "" +"The last form accepts not only function calls, but any type of expression. " +"Keyword arguments passed to this function are available as local variables. " +"Example: ``import_string('re:compile(x)', x='[a-z]')``" +msgstr "" + +# 8a6e30706f344350b925379e177df002 +#: ../../../bottle.py:docstring of bottle.load_app:1 +msgid "" +"Load a bottle application from a module and make sure that the import does " +"not affect the current default application, but returns a separate " +"application object. See :func:`load` for the target parameter." +msgstr "" + +# e0839bf597c5432d98d9ff1364b794c6 +#: ../../../bottle.py:docstring of bottle.request:1 +msgid "" +"A thread-safe instance of :class:`LocalRequest`. If accessed from within a " +"request callback, this instance always refers to the *current* request (even " +"on a multithreaded server)." +msgstr "" + +# 301be6b4c0db45d9828169e666cb4a87 +#: ../../../bottle.py:docstring of bottle.response:1 +msgid "" +"A thread-safe instance of :class:`LocalResponse`. It is used to change the " +"HTTP response for the *current* request." +msgstr "" + +# 2182bbf9e89a407aa0fd3505735347c4 +#: ../../../bottle.py:docstring of bottle.HTTP_CODES:1 +msgid "" +"A dict to map HTTP status codes (e.g. 404) to phrases (e.g. 'Not Found')" +msgstr "" + +# 4e6bc011ddb0490c8f82636be99ccb9a +#: ../../api.rst:38 +msgid "" +"Return the current :ref:`default-app`. Actually, these are callable " +"instances of :class:`AppStack` and implement a stack-like API." +msgstr "" + +# 993cefb361da4f4f8d2888d9eb460653 +#: ../../api.rst:42 +msgid "Routing" +msgstr "" + +# b5505727f5cf4beea9f751b5f60e64c4 +#: ../../api.rst:44 +msgid "" +"Bottle maintains a stack of :class:`Bottle` instances (see :func:`app` and :" +"class:`AppStack`) and uses the top of the stack as a *default application* " +"for some of the module-level functions and decorators." +msgstr "" + +# 825650775f864ee19fa78603d427bdba +#: ../../api.rst:53 +msgid "" +"Decorator to install a route to the current default application. See :meth:" +"`Bottle.route` for details." +msgstr "" + +# e714829c069d4e138db734ab96085e8a +#: ../../api.rst:58 +msgid "" +"Decorator to install an error handler to the current default application. " +"See :meth:`Bottle.error` for details." +msgstr "" + +# 8f769dab5b9442e6ad49d3cb9f4754ef +#: ../../api.rst:62 +msgid "WSGI and HTTP Utilities" +msgstr "" + +# 34b4f8fb4f8e442aa28d8477a30d99a4 +#: ../../../bottle.py:docstring of bottle.parse_date:1 +msgid "Parse rfc1123, rfc850 and asctime timestamps and return UTC epoch." +msgstr "" + +# 001de5f591de4f378d902641f9a03e90 +#: ../../../bottle.py:docstring of bottle.parse_auth:1 +msgid "" +"Parse rfc2617 HTTP authentication header string (basic) and return (user," +"pass) tuple or None" +msgstr "" + +# 2675c3c439fc45818d55c0fdbb191683 +#: ../../../bottle.py:docstring of bottle.cookie_encode:1 +msgid "Encode and sign a pickle-able object. Return a (byte) string" +msgstr "" + +# 9eb5a61979b54811805b6fe53e3d3ee3 +#: ../../../bottle.py:docstring of bottle.cookie_decode:1 +msgid "Verify and decode an encoded string. Return an object or None." +msgstr "" + +# 13f13118209b4b67b7894b428db9bde8 +#: ../../../bottle.py:docstring of bottle.cookie_is_encoded:1 +msgid "Return True if the argument looks like a encoded cookie." +msgstr "" + +# 7d33d97d4fdb41398aef0d56d4a49250 +#: ../../../bottle.py:docstring of bottle.yieldroutes:1 +msgid "" +"Return a generator for routes that match the signature (name, args) of the " +"func parameter. This may yield more than one route if the function takes " +"optional keyword arguments. The output is best described by example::" +msgstr "" + +# 1f2dbbce55f942beb1a0000a82f29c06 +#: ../../../bottle.py:docstring of bottle.path_shift:1 +msgid "Shift path fragments from PATH_INFO to SCRIPT_NAME and vice versa." +msgstr "" + +# cbffed2b48824bb0b4fe9f26b454a260 +#: ../../api.rst:80 +msgid "Data Structures" +msgstr "" + +# 7585a471a000456eb2970b4039f17ff6 +#: ../../../bottle.py:docstring of bottle.MultiDict:1 +msgid "" +"This dict stores multiple values per key, but behaves exactly like a normal " +"dict in that it returns only the newest value for any given key. There are " +"special methods available to access the full list of values." +msgstr "" + +# 48ce9646c309413192f0cded0189750f +#: ../../../bottle.py:docstring of bottle.MultiDict.get:1 +msgid "Return the most recent value for a key." +msgstr "" + +# 6bc19fc65e4f475083fd1eb47c28bd51 +#: ../../../bottle.py:docstring of bottle.MultiDict.append:1 +msgid "Add a new value to the list of values for this key." +msgstr "" + +# 76d54d9bb2fa476a9ba3e1fb47c48f75 +#: ../../../bottle.py:docstring of bottle.MultiDict.replace:1 +msgid "Replace the list of values with a single value." +msgstr "" + +# 6b739bda1f2d47dead2c240ce156a52c +# 408d04186344473197fdfda230a11a43 +#: ../../../bottle.py:docstring of bottle.MultiDict.getall:1 +#: bottle.MultiDict.getlist:1 +msgid "Return a (possibly empty) list of values for a key." +msgstr "" + +# 096a32b3920840ae81aeb1b74df13937 +#: ../../../bottle.py:docstring of bottle.MultiDict.getone:1 +msgid "Aliases for WTForms to mimic other multi-dict APIs (Django)" +msgstr "" + +# 568f7d1aa3de48b3b585c2ce4f507364 +#: ../../../bottle.py:docstring of bottle.HeaderDict:1 +msgid "" +"A case-insensitive version of :class:`MultiDict` that defaults to replace " +"the old value instead of appending it." +msgstr "" + +# 33192248b67945f6ab3bdfaae1022853 +#: ../../../bottle.py:docstring of bottle.FormsDict:1 +msgid "" +"This :class:`MultiDict` subclass is used to store request form data. " +"Additionally to the normal dict-like item access methods (which return " +"unmodified data as native strings), this container also supports attribute-" +"like access to its values. Attributes are automatically de- or recoded to " +"match :attr:`input_encoding` (default: 'utf8'). Missing attributes default " +"to an empty string." +msgstr "" + +# 5767896f774f4c0cbc60b12de9ebe4b4 +#: ../../../bottle.py:docstring of bottle.FormsDict.input_encoding:1 +msgid "Encoding used for attribute values." +msgstr "" + +# 0f6a6fd12b4e432b85a28dc0cb33e6f5 +#: ../../../bottle.py:docstring of bottle.FormsDict.recode_unicode:1 +msgid "" +"If true (default), unicode strings are first encoded with `latin1` and then " +"decoded to match :attr:`input_encoding`." +msgstr "" + +# bfe4e448783b491a90d44d940c065e06 +#: ../../../bottle.py:docstring of bottle.FormsDict.decode:1 +msgid "" +"Returns a copy with all keys and values de- or recoded to match :attr:" +"`input_encoding`. Some libraries (e.g. WTForms) want a unicode dictionary." +msgstr "" + +# 7fc82cc9c0834b7da08e3b3860e1a9d6 +#: ../../../bottle.py:docstring of bottle.FormsDict.getunicode:1 +msgid "Return the value as a unicode string, or the default." +msgstr "" + +# 19ac58e686224a19b67845c5061582f2 +#: ../../../bottle.py:docstring of bottle.WSGIHeaderDict:1 +msgid "" +"This dict-like class wraps a WSGI environ dict and provides convenient " +"access to HTTP_* fields. Keys and values are native strings (2.x bytes or 3." +"x unicode) and keys are case-insensitive. If the WSGI environment contains " +"non-native string values, these are de- or encoded using a lossless 'latin1' " +"character set." +msgstr "" + +# eec339b8e4ac4faca373130a77190a85 +#: ../../../bottle.py:docstring of bottle.WSGIHeaderDict:7 +msgid "" +"The API will remain stable even on changes to the relevant PEPs. Currently " +"PEP 333, 444 and 3333 are supported. (PEP 444 is the only one that uses non-" +"native strings.)" +msgstr "" + +# 693b370f02d74df0b1e7851290f831ed +#: ../../../bottle.py:docstring of bottle.WSGIHeaderDict.cgikeys:1 +msgid "List of keys that do not have a ``HTTP_`` prefix." +msgstr "" + +# 0c70f44ff2a543bc92035a4a1578505b +#: ../../../bottle.py:docstring of bottle.WSGIHeaderDict.raw:1 +msgid "Return the header value as is (may be bytes or unicode)." +msgstr "" + +# bd725bbc2a0c4b508fe46abf350a0661 +#: ../../../bottle.py:docstring of bottle.AppStack:1 +msgid "A stack-like list. Calling it returns the head of the stack." +msgstr "" + +# 379355eb37684a51837275ae5bcf062c +#: ../../api.rst:99 +msgid "Return the current default application and remove it from the stack." +msgstr "" + +# 1650474558c047ae8ce151129af31a3e +#: ../../../bottle.py:docstring of bottle.AppStack.push:1 +msgid "Add a new :class:`Bottle` instance to the stack" +msgstr "" + +# 19a9f2b2e67a4983a1c300631f14ad2c +#: ../../../bottle.py:docstring of bottle.ResourceManager:1 +msgid "" +"This class manages a list of search paths and helps to find and open " +"application-bound resources (files)." +msgstr "" + +# 2196cd941c6646f586f7c4990cc9e99d +#: ../../../bottle.py:docstring of bottle.ResourceManager.path:1 +msgid "A list of search paths. See :meth:`add_path` for details." +msgstr "" + +# 25c2e942f3174e4080e1051805eef350 +#: ../../../bottle.py:docstring of bottle.ResourceManager.cache:1 +msgid "A cache for resolved paths. ``res.cache.clear()`` clears the cache." +msgstr "" + +# 84f7c5ef07074d959c37d62815af0f71 +#: ../../../bottle.py:docstring of bottle.ResourceManager.add_path:1 +msgid "" +"Add a new path to the list of search paths. Return False if the path does " +"not exist." +msgstr "" + +# d5787be650274ae99b6d45a61dbeb300 +#: ../../../bottle.py:docstring of bottle.ResourceManager.add_path:12 +msgid "" +"The `base` parameter makes it easy to reference files installed along with a " +"python module or package::" +msgstr "" + +# 6aaae04bb6304323bed63f45614eb041 +#: ../../../bottle.py:docstring of bottle.ResourceManager.lookup:1 +msgid "Search for a resource and return an absolute file path, or `None`." +msgstr "" + +# 88d250b10df24f0aa72ae15640d2f274 +#: ../../../bottle.py:docstring of bottle.ResourceManager.lookup:3 +msgid "" +"The :attr:`path` list is searched in order. The first match is returend. " +"Symlinks are followed. The result is cached to speed up future lookups." +msgstr "" + +# ffc785d1770d40aa872ea22d52233c02 +#: ../../../bottle.py:docstring of bottle.ResourceManager.open:1 +msgid "Find a resource and return a file object, or raise IOError." +msgstr "" + +# fcec5a93e13a48b68e251a6a8f94d74f +#: ../../../bottle.py:docstring of bottle.FileUpload.file:1 +msgid "Open file(-like) object (BytesIO buffer or temporary file)" +msgstr "" + +# 48ffa5c976f245d0becc21a9e2c62bb6 +#: ../../../bottle.py:docstring of bottle.FileUpload.name:1 +msgid "Name of the upload form field" +msgstr "" + +# 2a94d248a0804134b8b2950ee6872a16 +#: ../../../bottle.py:docstring of bottle.FileUpload.raw_filename:1 +msgid "Raw filename as sent by the client (may contain unsafe characters)" +msgstr "" + +# e6845621bb9d42ccba141441bc8a5bc5 +#: ../../../bottle.py:docstring of bottle.FileUpload.headers:1 +msgid "A :class:`HeaderDict` with additional headers (e.g. content-type)" +msgstr "" + +# ec33f9a869df439ab4ca59a460350271 +#: ../../../bottle.py:docstring of bottle.FileUpload.content_type:1 +#: bottle.BaseResponse.content_type:1 +msgid "Current value of the 'Content-Type' header." +msgstr "" + +# 001c6d13b2db4841b81f6b23b55a4fcb +#: ../../../bottle.py:docstring of bottle.FileUpload.content_length:1 +#: bottle.BaseResponse.content_length:1 +msgid "Current value of the 'Content-Length' header." +msgstr "" + +# 44d2df642fd545b08b622a73a84bd9e6 +#: ../../../bottle.py:docstring of bottle.FileUpload.filename:1 +msgid "" +"Name of the file on the client file system, but normalized to ensure file " +"system compatibility (lowercase, no whitespace, no path separators, no " +"unsafe characters, ASCII only). An empty filename is returned as 'empty'." +msgstr "" + +# ba76ee38fe954b458ba7e961b3caad15 +#: ../../../bottle.py:docstring of bottle.FileUpload.save:1 +msgid "" +"Save file to disk or copy its content to an open file(-like) object. If " +"*destination* is a directory, :attr:`filename` is added to the path. " +"Existing files are not overwritten by default (IOError)." +msgstr "" + +# 841c0e821e284d91b7b014ab046f0b29 +#: ../../api.rst:108 +msgid "Exceptions" +msgstr "" + +# 2fd091069448414fa46126c820382bb2 +#: ../../../bottle.py:docstring of bottle.BottleException:1 +msgid "A base class for exceptions used by bottle." +msgstr "" + +# acafc1e6403e44b4bd5821201cdb82fa +#: ../../api.rst:116 +msgid "The :class:`Bottle` Class" +msgstr "" + +# a3d6dd8f70bf4874a14cea66590f4096 +#: ../../../bottle.py:docstring of bottle.Bottle:1 +msgid "" +"Each Bottle object represents a single, distinct web application and " +"consists of routes, callbacks, plugins, resources and configuration. " +"Instances are callable WSGI applications." +msgstr "" + +# e316cd279454454186fd767fe6663083 +#: ../../../bottle.py:docstring of bottle.Bottle.config:1 +msgid "A :class:`ConfigDict` for app specific configuration." +msgstr "" + +# a54618bbe184416ea06fe641e3bc581f +#: ../../../bottle.py:docstring of bottle.Bottle.resources:1 +msgid "A :class:`ResourceManager` for application files" +msgstr "" + +# c85fb189289d4452994f37a93d29aa04 +#: ../../../bottle.py:docstring of bottle.Bottle.catchall:1 +msgid "If true, most exceptions are caught and returned as :exc:`HTTPError`" +msgstr "" + +# a153859ed6604e65ba9a9681e700a76f +#: ../../../bottle.py:docstring of bottle.Bottle.add_hook:1 +msgid "Attach a callback to a hook. Three hooks are currently implemented:" +msgstr "" + +# 6dc152c60013420abdb297caa28a3813 +#: ../../../bottle.py:docstring of bottle.Bottle.add_hook:4 +msgid "before_request" +msgstr "" + +# 70abd3193e50425e82f98b3f68d4e4dc +#: ../../../bottle.py:docstring of bottle.Bottle.add_hook:4 +msgid "" +"Executed once before each request. The request context is available, but no " +"routing has happened yet." +msgstr "" + +# b8d91a10af2343399eaa8574f904e5d9 +#: ../../../bottle.py:docstring of bottle.Bottle.add_hook:6 +msgid "after_request" +msgstr "" + +# 0e85cfc0a3bb4d9b97b68ae264a44ee3 +#: ../../../bottle.py:docstring of bottle.Bottle.add_hook:7 +msgid "Executed once after each request regardless of its outcome." +msgstr "" + +# b580af375d614432bd1ac5e0f35f18fd +#: ../../../bottle.py:docstring of bottle.Bottle.add_hook:8 +msgid "app_reset" +msgstr "" + +# 9ce7e89d4e41419e85f0d9c338117c8c +#: ../../../bottle.py:docstring of bottle.Bottle.add_hook:9 +msgid "Called whenever :meth:`Bottle.reset` is called." +msgstr "" + +# 145ccba16d8f47729e885aa264b33a8f +#: ../../../bottle.py:docstring of bottle.Bottle.remove_hook:1 +msgid "Remove a callback from a hook." +msgstr "" + +# 55678852dd1541bda6a38d2d4f7902c0 +#: ../../../bottle.py:docstring of bottle.Bottle.trigger_hook:1 +msgid "Trigger a hook and return a list of results." +msgstr "" + +# ec7d6127e3f44524bf25ce39f47a1fc8 +#: ../../../bottle.py:docstring of bottle.Bottle.hook:1 +msgid "" +"Return a decorator that attaches a callback to a hook. See :meth:`add_hook` " +"for details." +msgstr "" + +# c071e835d9914cd1a24b606e57fc6e12 +#: ../../../bottle.py:docstring of bottle.Bottle.mount:1 +msgid "" +"Mount an application (:class:`Bottle` or plain WSGI) to a specific URL " +"prefix. Example::" +msgstr "" + +# 9cc033bb984f4703867893d82058b6b5 +#: ../../../bottle.py:docstring of bottle.Bottle.mount:10 +msgid "All other parameters are passed to the underlying :meth:`route` call." +msgstr "" + +# ee990c4498394cb0acea5c9be5e7923f +#: ../../../bottle.py:docstring of bottle.Bottle.merge:1 +msgid "" +"Merge the routes of another :class:`Bottle` application or a list of :class:" +"`Route` objects into this application. The routes keep their 'owner', " +"meaning that the :data:`Route.app` attribute is not changed." +msgstr "" + +# 522ef1b9d92149f99b4eb66e81700835 +#: ../../../bottle.py:docstring of bottle.Bottle.install:1 +msgid "" +"Add a plugin to the list of plugins and prepare it for being applied to all " +"routes of this application. A plugin may be a simple decorator or an object " +"that implements the :class:`Plugin` API." +msgstr "" + +# 1f920e670f1f42bdb182fa5ee6892b9d +#: ../../../bottle.py:docstring of bottle.Bottle.uninstall:1 +msgid "" +"Uninstall plugins. Pass an instance to remove a specific plugin, a type " +"object to remove all plugins that match that type, a string to remove all " +"plugins with a matching ``name`` attribute or ``True`` to remove all " +"plugins. Return the list of removed plugins." +msgstr "" + +# b0f6b824b5bb48f5a73ce8df7cf1ecd2 +#: ../../../bottle.py:docstring of bottle.Bottle.reset:1 +msgid "" +"Reset all routes (force plugins to be re-applied) and clear all caches. If " +"an ID or route object is given, only that specific route is affected." +msgstr "" + +# ea0b9e9a1cd845499900b9ae0650c1c9 +#: ../../../bottle.py:docstring of bottle.Bottle.close:1 +msgid "Close the application and all installed plugins." +msgstr "" + +# 9d904857add44dacbd2351fa34a9416d +#: ../../../bottle.py:docstring of bottle.Bottle.run:1 +msgid "Calls :func:`run` with the same parameters." +msgstr "" + +# 579b86a9a0e74698b0bfa8685ae73562 +#: ../../../bottle.py:docstring of bottle.Bottle.match:1 +msgid "" +"Search for a matching route and return a (:class:`Route` , urlargs) tuple. " +"The second value is a dictionary with parameters extracted from the URL. " +"Raise :exc:`HTTPError` (404/405) on a non-match." +msgstr "" + +# 8c65d88c42384c8fbe1461b738be7328 +#: ../../../bottle.py:docstring of bottle.Bottle.get_url:1 +msgid "Return a string that matches a named route" +msgstr "" + +# f53b92832d0e44f38c78840aa20acd93 +#: ../../../bottle.py:docstring of bottle.Bottle.add_route:1 +msgid "Add a route object, but do not change the :data:`Route.app` attribute." +msgstr "" + +# 5855345f15e54935b5961c491f4df1c8 +#: ../../../bottle.py:docstring of bottle.Bottle.route:1 +msgid "A decorator to bind a function to a request URL. Example::" +msgstr "" + +# a6a690e885a849a1b6784d0271d763a0 +#: ../../../bottle.py:docstring of bottle.Bottle.route:7 +msgid "" +"The ``:name`` part is a wildcard. See :class:`Router` for syntax details." +msgstr "" + +# bf69fcb9e82e4aba84d8b46bb8f44c10 +#: ../../../bottle.py:docstring of bottle.Bottle.route:23 +msgid "" +"Any additional keyword arguments are stored as route-specific configuration " +"and passed to plugins (see :meth:`Plugin.apply`)." +msgstr "" + +# aaa09cd9b5654107b3550272d034b590 +#: ../../../bottle.py:docstring of bottle.Bottle.get:1 +msgid "Equals :meth:`route`." +msgstr "" + +# c3b3f1634a874a0791c7bc2e3e15d45a +#: ../../../bottle.py:docstring of bottle.Bottle.post:1 +msgid "Equals :meth:`route` with a ``POST`` method parameter." +msgstr "" + +# 2178c890ba6445439171493fef9e111f +#: ../../../bottle.py:docstring of bottle.Bottle.put:1 +msgid "Equals :meth:`route` with a ``PUT`` method parameter." +msgstr "" + +# da82d3802c7944eb99c426e6a86596a7 +#: ../../../bottle.py:docstring of bottle.Bottle.delete:1 +msgid "Equals :meth:`route` with a ``DELETE`` method parameter." +msgstr "" + +# be193cc1118748e588bda1eb93dc0b18 +#: ../../../bottle.py:docstring of bottle.Bottle.error:1 +msgid "Decorator: Register an output handler for a HTTP error code" +msgstr "" + +# ae4266c2a37f43f1b1fd10db27745ebf +#: ../../../bottle.py:docstring of bottle.Bottle.handle:1 +msgid "" +"(deprecated) Execute the first matching route callback and return the " +"result. :exc:`HTTPResponse` exceptions are caught and returned. If :attr:" +"`Bottle.catchall` is true, other exceptions are caught as well and returned " +"as :exc:`HTTPError` instances (500)." +msgstr "" + +# 505b97c9c9f74ed8a9cfdbfc5d39e9fe +#: ../../../bottle.py:docstring of bottle.Bottle.wsgi:1 +msgid "The bottle WSGI-interface." +msgstr "" + +# 6dbe117230bb473fafbf45d5a7c1a6bb +#: ../../../bottle.py:docstring of bottle.Route:1 +msgid "" +"This class wraps a route callback along with route specific metadata and " +"configuration and applies Plugins on demand. It is also responsible for " +"turing an URL path rule into a regular expression usable by the Router." +msgstr "" + +# a4b55c71f2544e7ea88dec1b381f5bd1 +#: ../../../bottle.py:docstring of bottle.Route.app:1 +msgid "The application this route is installed to." +msgstr "" + +# 96261d8a5d9845afa58ce6187e958ee9 +#: ../../../bottle.py:docstring of bottle.Route.rule:1 +msgid "The path-rule string (e.g. ``/wiki/:page``)." +msgstr "" + +# 524c69435594465b9c01e66ec6e366e4 +#: ../../../bottle.py:docstring of bottle.Route.method:1 +msgid "The HTTP method as a string (e.g. ``GET``)." +msgstr "" + +# bf67f447b9c84beca14f9a581bbee99b +#: ../../../bottle.py:docstring of bottle.Route.callback:1 +msgid "" +"The original callback with no plugins applied. Useful for introspection." +msgstr "" + +# ced088a30a0c4bfabc944af22e2f5d30 +#: ../../../bottle.py:docstring of bottle.Route.name:1 +msgid "The name of the route (if specified) or ``None``." +msgstr "" + +# f949e89c75fe47229c191f89c17196d0 +#: ../../../bottle.py:docstring of bottle.Route.plugins:1 +msgid "A list of route-specific plugins (see :meth:`Bottle.route`)." +msgstr "" + +# c0cb7ea593dc4db5b0e279da0fe5ef42 +#: ../../../bottle.py:docstring of bottle.Route.skiplist:1 +msgid "" +"A list of plugins to not apply to this route (see :meth:`Bottle.route`)." +msgstr "" + +# 8bb3cca930af481f8ca44da2c39ceefc +#: ../../../bottle.py:docstring of bottle.Route.config:1 +msgid "" +"Additional keyword arguments passed to the :meth:`Bottle.route` decorator " +"are stored in this dictionary. Used for route-specific plugin configuration " +"and meta-data." +msgstr "" + +# 0943215c952f4b53b91d4630599c798c +#: ../../../bottle.py:docstring of bottle.Route.call:1 +msgid "" +"The route callback with all plugins applied. This property is created on " +"demand and then cached to speed up subsequent requests." +msgstr "" + +# 498d6f0a85a541eba29a8f48855750f7 +#: ../../../bottle.py:docstring of bottle.Route.reset:1 +msgid "" +"Forget any cached values. The next time :attr:`call` is accessed, all " +"plugins are re-applied." +msgstr "" + +# f873381927a84bceaf58eee4ff90c5d6 +#: ../../../bottle.py:docstring of bottle.Route.prepare:1 +msgid "Do all on-demand work immediately (useful for debugging)." +msgstr "" + +# d63a0238d0634d47b8e5aec45248be7c +#: ../../../bottle.py:docstring of bottle.Route.all_plugins:1 +msgid "Yield all Plugins affecting this route." +msgstr "" + +# 1ec3c38fbcb849b1b43263e370ffd136 +#: ../../../bottle.py:docstring of bottle.Route.get_undecorated_callback:1 +msgid "" +"Return the callback. If the callback is a decorated function, try to recover " +"the original function." +msgstr "" + +# d3c5328a4cab44989c52d2127b3544b4 +#: ../../../bottle.py:docstring of bottle.Route.get_callback_args:1 +msgid "" +"Return a list of argument names the callback (most likely) accepts as " +"keyword arguments. If the callback is a decorated function, try to recover " +"the original function before inspection." +msgstr "" + +# 96aa046ca3da4f6e8ee873d30bba2a36 +#: ../../../bottle.py:docstring of bottle.Route.get_config:1 +msgid "" +"Lookup a config field and return its value, first checking the route.config, " +"then route.app.config." +msgstr "" + +# 62603aa4019e4732a6caa0083f27ceee +#: ../../api.rst:126 +msgid "The :class:`Request` Object" +msgstr "" + +# 39128b7c74ed400e9a103a6b37e84b43 +#: ../../api.rst:128 +msgid "" +"The :class:`Request` class wraps a WSGI environment and provides helpful " +"methods to parse and access form data, cookies, file uploads and other " +"metadata. Most of the attributes are read-only." +msgstr "" + +# da1e3ca7fd8143bd99c098bd62ce6f1b +#: ../../../bottle.py:docstring of bottle.BaseRequest:1 +msgid "" +"A wrapper for WSGI environment dictionaries that adds a lot of convenient " +"access methods and properties. Most of them are read-only." +msgstr "" + +# 145f7050a42a494f9dbc28a25c402150 +#: ../../../bottle.py:docstring of bottle.BaseRequest:4 +msgid "" +"Adding new attributes to a request actually adds them to the environ " +"dictionary (as 'bottle.request.ext.'). This is the recommended way to " +"store and access request-specific data." +msgstr "" + +# 199355247ef144f4ba61954e5936825d +#: ../../../bottle.py:docstring of bottle.BaseRequest.MEMFILE_MAX:1 +msgid "Maximum size of memory buffer for :attr:`body` in bytes." +msgstr "" + +# e0bbf2db8195408a977035a5a884d0da +#: ../../../bottle.py:docstring of bottle.BaseRequest.MAX_PARAMS:1 +msgid "Maximum number pr GET or POST parameters per request" +msgstr "" + +# ef1ff6ae9a0541e8b9d7e7f747f57b3d +#: ../../../bottle.py:docstring of bottle.BaseRequest.environ:1 +msgid "" +"The wrapped WSGI environ dictionary. This is the only real attribute. All " +"other attributes actually are read-only properties." +msgstr "" + +# af4ebeade1b94633be302638a1c5d543 +#: ../../../bottle.py:docstring of bottle.BaseRequest.app:1 +msgid "Bottle application handling this request." +msgstr "" + +# c41f7380550042b4ac7111a188a88f77 +#: ../../../bottle.py:docstring of bottle.BaseRequest.route:1 +msgid "The bottle :class:`Route` object that matches this request." +msgstr "" + +# 0aeb079900744334aebdf19893cc043c +#: ../../../bottle.py:docstring of bottle.BaseRequest.url_args:1 +msgid "The arguments extracted from the URL." +msgstr "" + +# 037aee056fb248628a52cf2447ab4c82 +#: ../../../bottle.py:docstring of bottle.BaseRequest.path:1 +msgid "" +"The value of ``PATH_INFO`` with exactly one prefixed slash (to fix broken " +"clients and avoid the \"empty path\" edge case)." +msgstr "" + +# e40998f41ff342d09e6699927a460971 +#: ../../../bottle.py:docstring of bottle.BaseRequest.method:1 +msgid "The ``REQUEST_METHOD`` value as an uppercase string." +msgstr "" + +# e6845621bb9d42ccba141441bc8a5bc5 +#: ../../../bottle.py:docstring of bottle.BaseRequest.headers:1 +msgid "" +"A :class:`WSGIHeaderDict` that provides case-insensitive access to HTTP " +"request headers." +msgstr "" + +# 7fc82cc9c0834b7da08e3b3860e1a9d6 +#: ../../../bottle.py:docstring of bottle.BaseRequest.get_header:1 +msgid "Return the value of a request header, or a given default value." +msgstr "" + +# a4b6f975aa094fbdb49980bca6a4740c +#: ../../../bottle.py:docstring of bottle.BaseRequest.cookies:1 +msgid "" +"Cookies parsed into a :class:`FormsDict`. Signed cookies are NOT decoded. " +"Use :meth:`get_cookie` if you expect signed cookies." +msgstr "" + +# c715b1e442094837a714589e3798186f +#: ../../../bottle.py:docstring of bottle.BaseRequest.get_cookie:1 +msgid "" +"Return the content of a cookie. To read a `Signed Cookie`, the `secret` must " +"match the one used to create the cookie (see :meth:`BaseResponse." +"set_cookie`). If anything goes wrong (missing cookie or wrong signature), " +"return a default value." +msgstr "" + +# 92a7554d93d54dd4a8bba31a0067114b +#: ../../../bottle.py:docstring of bottle.BaseRequest.query:1 +msgid "" +"The :attr:`query_string` parsed into a :class:`FormsDict`. These values are " +"sometimes called \"URL arguments\" or \"GET parameters\", but not to be " +"confused with \"URL wildcards\" as they are provided by the :class:`Router`." +msgstr "" + +# 6e38df25852449a29bd683f33364b48f +#: ../../../bottle.py:docstring of bottle.BaseRequest.forms:1 +msgid "" +"Form values parsed from an `url-encoded` or `multipart/form-data` encoded " +"POST or PUT request body. The result is returned as a :class:`FormsDict`. " +"All keys and values are strings. File uploads are stored separately in :attr:" +"`files`." +msgstr "" + +# 521472a4de8345f98bc3c787393ad395 +#: ../../../bottle.py:docstring of bottle.BaseRequest.params:1 +msgid "" +"A :class:`FormsDict` with the combined values of :attr:`query` and :attr:" +"`forms`. File uploads are stored in :attr:`files`." +msgstr "" + +# 7e4b95b0b3054f54a33b518c161f0f86 +#: ../../../bottle.py:docstring of bottle.BaseRequest.files:1 +msgid "" +"File uploads parsed from `multipart/form-data` encoded POST or PUT request " +"body. The values are instances of :class:`FileUpload`." +msgstr "" + +# 0d0624fb0853462aab441d63adc1a3be +#: ../../../bottle.py:docstring of bottle.BaseRequest.json:1 +msgid "" +"If the ``Content-Type`` header is ``application/json``, this property holds " +"the parsed content of the request body. Only requests smaller than :attr:" +"`MEMFILE_MAX` are processed to avoid memory exhaustion." +msgstr "" + +# e365ed3beb1d44c4af25f40b7f4a8226 +#: ../../../bottle.py:docstring of bottle.BaseRequest.body:1 +msgid "" +"The HTTP request body as a seek-able file-like object. Depending on :attr:" +"`MEMFILE_MAX`, this is either a temporary file or a :class:`io.BytesIO` " +"instance. Accessing this property for the first time reads and replaces the " +"``wsgi.input`` environ variable. Subsequent accesses just do a `seek(0)` on " +"the file object." +msgstr "" + +# 0f818e4e9be54445a5d849f282fbb91a +#: ../../../bottle.py:docstring of bottle.BaseRequest.GET:1 +msgid "An alias for :attr:`query`." +msgstr "" + +# 1cb7905e16964d0781a080367f6c4355 +#: ../../../bottle.py:docstring of bottle.BaseRequest.POST:1 +msgid "" +"The values of :attr:`forms` and :attr:`files` combined into a single :class:" +"`FormsDict`. Values are either strings (form values) or instances of :class:" +"`cgi.FieldStorage` (file uploads)." +msgstr "" + +# 19474bb856ea4df983d033e944c07d91 +#: ../../../bottle.py:docstring of bottle.BaseRequest.COOKIES:1 +msgid "Alias for :attr:`cookies` (deprecated)." +msgstr "" + +# 7a59ab7b57544482a2b7d0207c28b2cb +#: ../../../bottle.py:docstring of bottle.BaseRequest.url:1 +msgid "" +"The full request URI including hostname and scheme. If your app lives behind " +"a reverse proxy or load balancer and you get confusing results, make sure " +"that the ``X-Forwarded-Host`` header is set correctly." +msgstr "" + +# 6abcd81bc21d439a895207e630f97c52 +#: ../../../bottle.py:docstring of bottle.BaseRequest.urlparts:1 +msgid "" +"The :attr:`url` string as an :class:`urlparse.SplitResult` tuple. The tuple " +"contains (scheme, host, path, query_string and fragment), but the fragment " +"is always empty because it is not visible to the server." +msgstr "" + +# f392bad831ff4fa88c9ea744d8bc950c +#: ../../../bottle.py:docstring of bottle.BaseRequest.fullpath:1 +msgid "Request path including :attr:`script_name` (if present)." +msgstr "" + +# aab6198ddcfc4e65bc1ab4b782683370 +#: ../../../bottle.py:docstring of bottle.BaseRequest.query_string:1 +msgid "" +"The raw :attr:`query` part of the URL (everything in between ``?`` and " +"``#``) as a string." +msgstr "" + +# 946709194f5344eb842770c997f68202 +#: ../../../bottle.py:docstring of bottle.BaseRequest.script_name:1 +msgid "" +"The initial portion of the URL's `path` that was removed by a higher level " +"(server or routing middleware) before the application was called. This " +"script path is returned with leading and tailing slashes." +msgstr "" + +# 42adec892f1849f18d69527e9fe788b7 +#: ../../../bottle.py:docstring of bottle.BaseRequest.path_shift:1 +msgid "" +"Shift path segments from :attr:`path` to :attr:`script_name` and vice versa." +msgstr "" + +# 76e85971464548518acd9810d924f387 +#: ../../../bottle.py:docstring of bottle.BaseRequest.content_length:1 +msgid "" +"The request body length as an integer. The client is responsible to set this " +"header. Otherwise, the real length of the body is unknown and -1 is " +"returned. In this case, :attr:`body` will be empty." +msgstr "" + +# 8dc2def91405473fbfd3e904686be740 +#: ../../../bottle.py:docstring of bottle.BaseRequest.content_type:1 +msgid "The Content-Type header as a lowercase-string (default: empty)." +msgstr "" + +# 4d564e1fd934434181981c12030c784f +#: ../../../bottle.py:docstring of bottle.BaseRequest.is_xhr:1 +msgid "" +"True if the request was triggered by a XMLHttpRequest. This only works with " +"JavaScript libraries that support the `X-Requested-With` header (most of the " +"popular libraries do)." +msgstr "" + +# f42ba086381c4735b07013b78beabbe0 +#: ../../../bottle.py:docstring of bottle.BaseRequest.is_ajax:1 +msgid "Alias for :attr:`is_xhr`. \"Ajax\" is not the right term." +msgstr "" + +# deb53a1c59ed428688d2ff4250cac9b2 +#: ../../../bottle.py:docstring of bottle.BaseRequest.auth:1 +msgid "" +"HTTP authentication data as a (user, password) tuple. This implementation " +"currently supports basic (not digest) authentication only. If the " +"authentication happened at a higher level (e.g. in the front web-server or a " +"middleware), the password field is None, but the user field is looked up " +"from the ``REMOTE_USER`` environ variable. On any errors, None is returned." +msgstr "" + +# a6336e9837814b37a483c52185795a82 +#: ../../../bottle.py:docstring of bottle.BaseRequest.remote_route:1 +msgid "" +"A list of all IPs that were involved in this request, starting with the " +"client IP and followed by zero or more proxies. This does only work if all " +"proxies support the ```X-Forwarded-For`` header. Note that this information " +"can be forged by malicious clients." +msgstr "" + +# 38ce3f106a16450e943f25ff7a586069 +#: ../../../bottle.py:docstring of bottle.BaseRequest.remote_addr:1 +msgid "" +"The client IP as a string. Note that this information can be forged by " +"malicious clients." +msgstr "" + +# 259ef70a0d7b421ca8e468d9f1b71899 +#: ../../../bottle.py:docstring of bottle.BaseRequest.copy:1 +msgid "Return a new :class:`Request` with a shallow :attr:`environ` copy." +msgstr "" + +# 21846efc4aa7410cbe609eaf42910736 +#: ../../api.rst:136 +msgid "" +"The module-level :data:`bottle.request` is a proxy object (implemented in :" +"class:`LocalRequest`) and always refers to the `current` request, or in " +"other words, the request that is currently processed by the request handler " +"in the current thread. This `thread locality` ensures that you can safely " +"use a global instance in a multi-threaded environment." +msgstr "" + +# 10dd41c5686147648141a87cc6e82f77 +#: ../../../bottle.py:docstring of bottle.LocalRequest:1 +msgid "" +"A thread-local subclass of :class:`BaseRequest` with a different set of " +"attribues for each thread. There is usually only one global instance of this " +"class (:data:`request`). If accessed during a request/response cycle, this " +"instance always refers to the *current* request (even on a multithreaded " +"server)." +msgstr "" + +# f7b6c6f51a9f412985f867be926b555d +#: ../../../bottle.py:docstring of bottle.LocalRequest.bind:1 +msgid "Wrap a WSGI environ dictionary." +msgstr "" + +# 3b6cc79779f144989921ddb4d71d4cb0 +#: ../../../bottle.py:docstring of bottle.LocalRequest.environ:1 +msgid "Thread-local property stored in :data:`_lctx.request_environ`" +msgstr "" + +# 106092478f51479997b74ebeccd2ea06 +#: ../../api.rst:145 +msgid "The :class:`Response` Object" +msgstr "" + +# bde46b3aad08469aa59a263616041959 +#: ../../api.rst:147 +msgid "" +"The :class:`Response` class stores the HTTP status code as well as headers " +"and cookies that are to be sent to the client. Similar to :data:`bottle." +"request` there is a thread-local :data:`bottle.response` instance that can " +"be used to adjust the `current` response. Moreover, you can instantiate :" +"class:`Response` and return it from your request handler. In this case, the " +"custom instance overrules the headers and cookies defined in the global one." +msgstr "" + +# bc428c10813347058ee3eaefb7889f2b +#: ../../../bottle.py:docstring of bottle.BaseResponse:1 +msgid "Storage class for a response body as well as headers and cookies." +msgstr "" + +# 442a16db61924e0aa362afa4a37cefcd +#: ../../../bottle.py:docstring of bottle.BaseResponse:3 +msgid "" +"This class does support dict-like case-insensitive item-access to headers, " +"but is NOT a dict. Most notably, iterating over a response yields parts of " +"the body and not the headers." +msgstr "" + +# 83d9a04c39784dba9c1c644d8aa82ccd +#: ../../../bottle.py:docstring of bottle.BaseResponse:12 +msgid "" +"Additional keyword arguments are added to the list of headers. Underscores " +"in the header name are replaced with dashes." +msgstr "" + +# 4b9d3e8a27d24baeb19851f986eb9053 +#: ../../../bottle.py:docstring of bottle.BaseResponse.copy:1 +msgid "Returns a copy of self." +msgstr "" + +# 20dd731104a14134b1cb816272da6bff +#: ../../../bottle.py:docstring of bottle.BaseResponse.status_line:1 +msgid "The HTTP status line as a string (e.g. ``404 Not Found``)." +msgstr "" + +# 24f7622dd04d43ca8cffb16b093785a1 +#: ../../../bottle.py:docstring of bottle.BaseResponse.status_code:1 +msgid "The HTTP status code as an integer (e.g. 404)." +msgstr "" + +# e4b4d153add948bfa41eafc92be7b5b0 +#: ../../../bottle.py:docstring of bottle.BaseResponse.status:1 +msgid "" +"A writeable property to change the HTTP response status. It accepts either a " +"numeric code (100-999) or a string with a custom reason phrase (e.g. \"404 " +"Brain not found\"). Both :data:`status_line` and :data:`status_code` are " +"updated accordingly. The return value is always a status string." +msgstr "" + +# 1c0fa51fff2f46b3ab5dbc423cd5b1ad +#: ../../../bottle.py:docstring of bottle.BaseResponse.headers:1 +msgid "" +"An instance of :class:`HeaderDict`, a case-insensitive dict-like view on the " +"response headers." +msgstr "" + +# 69dbca79c72646da9d204b40422bc2d9 +#: ../../../bottle.py:docstring of bottle.BaseResponse.get_header:1 +msgid "" +"Return the value of a previously defined header. If there is no header with " +"that name, return a default value." +msgstr "" + +# c75d39ca206a4355ba6573abe3ccca7c +#: ../../../bottle.py:docstring of bottle.BaseResponse.set_header:1 +msgid "" +"Create a new response header, replacing any previously defined headers with " +"the same name." +msgstr "" + +# 800ed6de5292405980d7f0b42a2241b6 +#: ../../../bottle.py:docstring of bottle.BaseResponse.add_header:1 +msgid "Add an additional response header, not removing duplicates." +msgstr "" + +# ea08ec78e270408ebd927b40ed16e915 +#: ../../../bottle.py:docstring of bottle.BaseResponse.iter_headers:1 +msgid "" +"Yield (header, value) tuples, skipping headers that are not allowed with the " +"current response status code." +msgstr "" + +# 91f79c216555439f871d6ef43f6bda9f +#: ../../../bottle.py:docstring of bottle.BaseResponse.headerlist:1 +msgid "WSGI conform list of (header, value) tuples." +msgstr "" + +# 899832cd9ab0434481ab7dfa4a482d79 +#: ../../../bottle.py:docstring of bottle.BaseResponse.expires:1 +msgid "Current value of the 'Expires' header." +msgstr "" + +# c9a8f8c5c29c4dfdbd5c77e910133ed9 +#: ../../../bottle.py:docstring of bottle.BaseResponse.charset:1 +msgid "" +"Return the charset specified in the content-type header (default: utf8)." +msgstr "" + +# 3741634227334c49bc1c44bde23035ab +#: ../../../bottle.py:docstring of bottle.BaseResponse.COOKIES:1 +msgid "" +"A dict-like SimpleCookie instance. This should not be used directly. See :" +"meth:`set_cookie`." +msgstr "" + +# faf6b57b146a42399bbfada0234bf0b8 +#: ../../../bottle.py:docstring of bottle.BaseResponse.set_cookie:1 +msgid "" +"Create a new cookie or replace an old one. If the `secret` parameter is set, " +"create a `Signed Cookie` (described below)." +msgstr "" + +# f24ed8fe5dc64069af63525064bfc57f +#: ../../../bottle.py:docstring of bottle.BaseResponse.set_cookie:8 +msgid "" +"Additionally, this method accepts all RFC 2109 attributes that are supported " +"by :class:`cookie.Morsel`, including:" +msgstr "" + +# 16e1167be236401f91bfc40593afdd71 +#: ../../../bottle.py:docstring of bottle.BaseResponse.set_cookie:20 +msgid "" +"If neither `expires` nor `max_age` is set (default), the cookie will expire " +"at the end of the browser session (as soon as the browser window is closed)." +msgstr "" + +# 13a85a16b98a4e00b6567058431481ea +#: ../../../bottle.py:docstring of bottle.BaseResponse.set_cookie:24 +msgid "" +"Signed cookies may store any pickle-able object and are cryptographically " +"signed to prevent manipulation. Keep in mind that cookies are limited to 4kb " +"in most browsers." +msgstr "" + +# fd074f58f7a446bcb51b788462b67465 +#: ../../../bottle.py:docstring of bottle.BaseResponse.set_cookie:28 +msgid "" +"Warning: Signed cookies are not encrypted (the client can still see the " +"content) and not copy-protected (the client can restore an old cookie). The " +"main intention is to make pickling and unpickling save, not to store secret " +"information at client side." +msgstr "" + +# 5ad4fdb60e0146d7bdecb10b8f3e05cb +#: ../../../bottle.py:docstring of bottle.BaseResponse.delete_cookie:1 +msgid "" +"Delete a cookie. Be sure to use the same `domain` and `path` settings as " +"used to create the cookie." +msgstr "" + +# ae8c905c87694bf3a2ea42d09cfea02c +#: ../../../bottle.py:docstring of bottle.LocalResponse:1 +msgid "" +"A thread-local subclass of :class:`BaseResponse` with a different set of " +"attribues for each thread. There is usually only one global instance of this " +"class (:data:`response`). Its attributes are used to build the HTTP response " +"at the end of the request/response cycle." +msgstr "" + +# f6ace90a9670484d8a866dea8cd8b38a +#: ../../../bottle.py:docstring of bottle.LocalResponse.body:1 +msgid "Thread-local property stored in :data:`_lctx.response_body`" +msgstr "" + +# 8ca709f8313b482da65c7268859ae250 +#: ../../api.rst:159 +msgid "" +"The following two classes can be raised as an exception. The most noticeable " +"difference is that bottle invokes error handlers for :class:`HTTPError`, but " +"not for :class:`HTTPResponse` or other response types." +msgstr "" + +# d3a8f15c0c9c4c8697fdb8ae365c3b21 +#: ../../../bottle.py:docstring of bottle.HTTPResponse.output:1 +msgid "Alias for .body" +msgstr "" + +# 50180b5649a744c987ed84c266b7a9bd +#: ../../api.rst:171 +msgid "Templates" +msgstr "" + +# b4f775e4de0b4249b8e33108e33a7a49 +#: ../../api.rst:173 +msgid "" +"All template engines supported by :mod:`bottle` implement the :class:" +"`BaseTemplate` API. This way it is possible to switch and mix template " +"engines without changing the application code at all." +msgstr "" + +# 975585fd7dca4b0a8572be0fafcda6be +#: ../../../bottle.py:docstring of bottle.BaseTemplate:1 +msgid "Base class and minimal API for template adapters" +msgstr "" + +# a89e857e507644bdaf8d55dc717c5d68 +#: ../../../bottle.py:docstring of bottle.BaseTemplate.__init__:1 +msgid "" +"Create a new template. If the source parameter (str or buffer) is missing, " +"the name argument is used to guess a template filename. Subclasses can " +"assume that self.source and/or self.filename are set. Both are strings. The " +"lookup, encoding and settings parameters are stored as instance variables. " +"The lookup parameter stores a list containing directory paths. The encoding " +"parameter should be used to decode byte strings or files. The settings " +"parameter contains a dict for engine-specific settings." +msgstr "" + +# 2490a05b3cfe487a9cd697defe07282d +#: ../../../bottle.py:docstring of bottle.BaseTemplate.search:1 +msgid "" +"Search name in all directories specified in lookup. First without, then with " +"common extensions. Return first hit." +msgstr "" + +# 680a8fe096e741d9bfa6fe53086209dd +#: ../../../bottle.py:docstring of bottle.BaseTemplate.global_config:1 +msgid "This reads or sets the global settings stored in class.settings." +msgstr "" + +# 55ecc208fadd4c089c872170477a9f0c +#: ../../../bottle.py:docstring of bottle.BaseTemplate.prepare:1 +msgid "" +"Run preparations (parsing, caching, ...). It should be possible to call this " +"again to refresh a template or to update settings." +msgstr "" + +# 0ab4a6d80b044ddf87397b0f587d9fe0 +#: ../../../bottle.py:docstring of bottle.BaseTemplate.render:1 +msgid "" +"Render the template with the specified local variables and return a single " +"byte or unicode string. If it is a byte string, the encoding must match self." +"encoding. This method must be thread-safe! Local variables may be provided " +"in dictionaries (args) or directly, as keywords (kwargs)." +msgstr "" + +# 6b1c141cf449499b9ae972b7975d2a3b +#: ../../../bottle.py:docstring of bottle.view:1 +msgid "" +"Decorator: renders a template for a handler. The handler can control its " +"behavior like that:" +msgstr "" + +# 89e057215ad24a5f97966f920f26ff3c +#: ../../../bottle.py:docstring of bottle.view:4 +msgid "return a dict of template vars to fill out the template" +msgstr "" + +# 688fd6bb93f348a287e476ec16da2180 +#: ../../../bottle.py:docstring of bottle.view:5 +msgid "" +"return something other than a dict and the view decorator will not process " +"the template, but return the handler result as is. This includes returning a " +"HTTPResponse(dict) to get, for instance, JSON with autojson or other " +"castfilters." +msgstr "" + +# c30940ff52eb4578a46ebaa485189c2f +#: ../../../bottle.py:docstring of bottle.template:1 +msgid "" +"Get a rendered template as a string iterator. You can use a name, a filename " +"or a template string as first parameter. Template rendering arguments can be " +"passed as dictionaries or directly (as keyword arguments)." +msgstr "" + +# 24d18841c1104f21bc1e523a11d37f9b +#: ../../api.rst:184 +msgid "" +"You can write your own adapter for your favourite template engine or use one " +"of the predefined adapters. Currently there are four fully supported " +"template engines:" +msgstr "" + +# 0b18f89b92bd47cea75484f063b4a305 +#: ../../api.rst:187 +msgid "Class" +msgstr "" + +# e61c4e15bcac42e4b82f9dca7f257058 +#: ../../api.rst:187 +msgid "URL" +msgstr "" + +# 1d62c00724264840af5a38445a2f2046 +#: ../../api.rst:187 +msgid "Decorator" +msgstr "" + +# f358c8038cb54d25a612ce662ac57e66 +#: ../../api.rst:187 +msgid "Render function" +msgstr "" + +# b53044adf2c64defa1fc407003b81f86 +#: ../../api.rst:189 +msgid ":class:`SimpleTemplate`" +msgstr "" + +# a1a04a507e14417ab3539197b18afa4b +#: ../../api.rst:189 +msgid ":doc:`stpl`" +msgstr "" + +# 33dca0a76e23412abee840c3dbd6dcf6 +#: ../../api.rst:189 +msgid ":func:`view`" +msgstr "" + +# 1e86243291384e2d92ed890830d4d338 +#: ../../api.rst:189 +msgid ":func:`template`" +msgstr "" + +# 4d3a8eb5e32d40fda44342622bba81b8 +#: ../../api.rst:190 +msgid ":class:`MakoTemplate`" +msgstr "" + +# 6c423025f4cb4d4a801b605bafecb026 +#: ../../api.rst:190 +msgid "http://www.makotemplates.org" +msgstr "" + +# bc162e8800634503978fee1cfc325f3c +#: ../../api.rst:190 +msgid ":func:`mako_view`" +msgstr "" + +# e777be7d76044134b1b534e5612a397f +#: ../../api.rst:190 +msgid ":func:`mako_template`" +msgstr "" + +# 1169be7e540d4b028108f0437d1fb791 +#: ../../api.rst:191 +msgid ":class:`CheetahTemplate`" +msgstr "" + +# 81026d25ce3948468a6e4f7ff2eb49ac +#: ../../api.rst:191 +msgid "http://www.cheetahtemplate.org/" +msgstr "" + +# a5003711086e4b729b97068f1d5e3d93 +#: ../../api.rst:191 +msgid ":func:`cheetah_view`" +msgstr "" + +# 41355d3738e145589e85992557dd818e +#: ../../api.rst:191 +msgid ":func:`cheetah_template`" +msgstr "" + +# 4cecefe7caf84f7bbbf14deba520fd62 +#: ../../api.rst:192 +msgid ":class:`Jinja2Template`" +msgstr "" + +# a2dc200da35848f5b9b36d8d0cea1f33 +#: ../../api.rst:192 +msgid "http://jinja.pocoo.org/" +msgstr "" + +# 19500baf956c445fac89420ee8b30d57 +#: ../../api.rst:192 +msgid ":func:`jinja2_view`" +msgstr "" + +# 1a5f61a4b9aa4aa0a2933ef65e5cb88f +#: ../../api.rst:192 +msgid ":func:`jinja2_template`" +msgstr "" + +# a113494ab5c348cdbb1d5c7b9533f062 +#: ../../api.rst:195 +msgid "" +"To use :class:`MakoTemplate` as your default template engine, just import " +"its specialised decorator and render function::" +msgstr "" diff -Nru python-bottle-0.11.6/docs/_locale/zh_CN/async.po python-bottle-0.12.0/docs/_locale/zh_CN/async.po --- python-bottle-0.11.6/docs/_locale/zh_CN/async.po 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/docs/_locale/zh_CN/async.po 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,294 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) 2009-2012, Marcel Hellkamp +# This file is distributed under the same license as the Bottle package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Bottle 0.12-dev\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-11-09 18:23\n" +"PO-Revision-Date: 2012-11-09 15:37+0800\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +# 444d3f0f105f47b887bb0ba9822e1a1c +#: ../../async.rst:2 +msgid "Primer to Asynchronous Applications" +msgstr "异步应用入门" + +# 8d2cd170d03742b38a49e16d0f8b767f +#: ../../async.rst:4 +msgid "" +"Asynchronous design patterns don't mix well with the synchronous nature of " +"`WSGI `_. This is why most " +"asynchronous frameworks (tornado, twisted, ...) implement a specialized API " +"to expose their asynchronous features. Bottle is a WSGI framework and shares " +"the synchronous nature of WSGI, but thanks to the awesome `gevent project " +"`_, it is still possible to write asynchronous " +"applications with bottle. This article documents the usage of Bottle with " +"Asynchronous WSGI." +msgstr "" +"异步设计模式和 `WSGI `_ 的同步本质" +"并不能很好地兼容。这就是为什么大部分的异步框架(tornado, twisted, ...)都实现了" +"专有的API来暴露它们的异步特征。Bottle是一个WSGI框架,也继承了WSGI的同步本质," +"但是谢谢优秀的 `gevent项目 `_ ,我们可以使用Bottle来" +"编写异步应用。这份文档介绍了在Bottle中如何使用异步WSGI。" + +# 9ba83091544148ce9ac672d1a4d08308 +#: ../../async.rst:7 +msgid "The Limits of Synchronous WSGI" +msgstr "同步WSGI的限制" + +# d44c90a8c3454394a657b911f1ec85fc +#: ../../async.rst:9 +msgid "" +"Briefly worded, the `WSGI specification (pep 3333) `_ defines a request/response circle as follows: The " +"application callable is invoked once for each request and must return a body " +"iterator. The server then iterates over the body and writes each chunk to " +"the socket. As soon as the body iterator is exhausted, the client connection " +"is closed." +msgstr "" +"简单来说, `WSGI标准 (pep 3333) `_ " +"定义了下面这一个request/response的循环:每次请求到达的时候,应用中的callable" +"会被调用一次,返回一个主体iterator。接着服务器会遍历该主体,分块写入socket。" +"遍历完整个主体,就关闭客户端的连接。" + +# 2ad0d26fdfa044e595ce3b9ea29d94be +#: ../../async.rst:11 +msgid "" +"Simple enough, but there is a snag: All this happens synchronously. If your " +"application needs to wait for data (IO, sockets, databases, ...), it must " +"either yield empty strings (busy wait) or block the current thread. Both " +"solutions occupy the handling thread and prevent it from answering new " +"requests. There is consequently only one ongoing request per thread." +msgstr "" +"足够简单,但是存在一个小问题:所有这些都是同步的。如果你的应用需要等待数据" +"(IO, socket, 数据库, ...),除了返回一个空字符串(忙等),就只能阻塞当前线程。两" +"种办法都会占用当前线程,导致线程不能处理新的请求,只能处理当前的一个请求。" + +# efb55442c2a049e4a4b41f47636975d5 +#: ../../async.rst:13 +msgid "" +"Most servers limit the number of threads to avoid their relatively high " +"overhead. Pools of 20 or less threads are common. As soon as all threads are " +"occupied, any new connection is stalled. The server is effectively dead for " +"everyone else. If you want to implement a chat that uses long-polling ajax " +"requests to get real-time updates, you'd reach the limited at 20 concurrent " +"connections. That's a pretty small chat." +msgstr "" +"大部分服务器都限制了线程的数量,避免伴随它们而来的资源消耗。常见的是一个线程" +"池,内有20个或更少数量的线程。一旦所有的线程都被占用了,任何新的请求都会阻" +"塞。事实上,对于其他人来说,服务器已经宕机了。如果你想实现一个聊天程序,使用" +"ajax轮询来获取实时消息,很快你就会受到线程数量的限制。这样能同时服务的用户就" +"太少了。" + +# 84d8e03c7dcf45699f0880f591ce42a1 +#: ../../async.rst:16 +msgid "Greenlets to the rescue" +msgstr "救星,Greenlet" + +# a608984f3b0648d2acb892828a6c0f1a +#: ../../async.rst:18 +msgid "" +"Most servers limit the size of their worker pools to a relatively low number " +"of concurrent threads, due to the high overhead involved in switching " +"between and creating new threads. While threads are cheap compared to " +"processes (forks), they are still expensive to create for each new " +"connection." +msgstr "" +"大多数服务器的线程池都限制了线程池中线程的数量,避免创建和切换线程的代价。尽" +"管和创建进程(fork)的代价比起来,线程还是挺便宜的。但是也没便宜到可以接受为每" +"一个请求创建一个线程。" + +# 715dab2ec22040969dc0826db174d77d +#: ../../async.rst:20 +msgid "" +"The `gevent `_ module adds *greenlets* to the mix. " +"Greenlets behave similar to traditional threads, but are very cheap to " +"create. A gevent-based server can spawn thousands of greenlets (one for each " +"connection) with almost no overhead. Blocking individual greenlets has no " +"impact on the servers ability to accept new requests. The number of " +"concurrent connections is virtually unlimited." +msgstr "" +"`gevent `_ 模块添加了 *greenlet* 的支持。greenlet和传" +"统的线程类似,但其创建只需消耗很少的资源。基于gevent的服务器可以生成成千上万" +"的greenlet,为每个连接分配一个greenlet也毫无压力。阻塞greenlet,也不会影响到" +"服务器接受新的请求。同时处理的连接数理论上是没有限制的。" + +# 1c816479188a4c71995d01d1ca2d70d3 +#: ../../async.rst:22 +msgid "" +"This makes creating asynchronous applications incredibly easy, because they " +"look and feel like synchronous applications. A gevent-based server is " +"actually not asynchronous, but massively multi-threaded. Here is an example::" +msgstr "" +"这令创建异步应用难以置信的简单,因为它们看起来很想同步程序。基于gevent服务器" +"实际上不是异步的,是大规模多线程。下面是一个例子。" + +# 71732a6c95b64c75af73cd0e090c3d25 +#: ../../async.rst:39 +msgid "" +"The first line is important. It causes gevent to monkey-patch most of " +"Python's blocking APIs to not block the current thread, but pass the CPU to " +"the next greenlet instead. It actually replaces Python's threading with " +"gevent-based pseudo-threads. This is why you can still use ``time.sleep()`` " +"which would normally block the whole thread. If you don't feel comfortable " +"with monkey-patching python built-ins, you can use the corresponding gevent " +"functions (``gevent.sleep()`` in this case)." +msgstr "" +"第一行很重要。它让gevent monkey-patch了大部分Python的阻塞API,让它们不阻塞当" +"前线程,将CPU让给下一个greenlet。它实际上用基于gevent的伪线程替换了Python的线" +"程。这就是你依然可以使用 ``time.sleep()`` 这个照常来说会阻塞线程的函数。如果" +"这种monkey-patch的方式感令你感到不舒服,你依然可以使用gevent中相应的函数 " +"``gevent.sleep()`` 。" + +# 926721db7acd4a2485edfa8d60ad76e7 +#: ../../async.rst:41 +msgid "" +"If you run this script and point your browser to ``http://localhost:8080/" +"stream``, you should see `START`, `MIDDLE`, and `END` show up one by one " +"(rather than waiting 8 seconds to see them all at once). It works exactly as " +"with normal threads, but now your server can handle thousands of concurrent " +"requests without any problems." +msgstr "" +"如果你运行了上面的代码,接着访问 ``http://localhost:8080/stream`` ,你可看到 " +"`START`, `MIDDLE`, 和 `END` 这几个字样依次出现(用时大约8秒)。它像普通的线程一" +"样工作,但是现在你的服务器能同时处理成千上万的连接了。" + +# b4f28934ee8344eb9e56ac7e4eb25c95 +#: ../../async.rst:45 +msgid "" +"Some browsers buffer a certain amount of data before they start rendering a " +"page. You might need to yield more than a few bytes to see an effect in " +"these browsers. Additionally, many browsers have a limit of one concurrent " +"connection per URL. If this is the case, you can use a second browser or a " +"benchmark tool (e.g. `ab` or `httperf`) to measure performance." +msgstr "" +"一些浏览器在开始渲染一个页面之前,会缓存确定容量的数据。在这些浏览器上,你需" +"要返回更多的数据才能看到效果。另外,很多浏览器限制一个URL只使用一个连接。在这" +"种情况下,你可以使用另外的浏览器,或性能测试工具(例如: `ab` 或 `httperf` )来" +"测试性能。" + +# d05ad991545847cbb4200f76a4e8ec53 +#: ../../async.rst:52 +msgid "Event Callbacks" +msgstr "事件回调函数" + +# 555abf8c45d04c9f8bf27aa654774f9b +#: ../../async.rst:54 +msgid "" +"A very common design pattern in asynchronous frameworks (including tornado, " +"twisted, node.js and friends) is to use non-blocking APIs and bind callbacks " +"to asynchronous events. The socket object is kept open until it is closed " +"explicitly to allow callbacks to write to the socket at a later point. Here " +"is an example based on the `tornado library `_::" +msgstr "" +"异步框架的常见设计模式(包括 tornado, twisted, node.js 和 friends),是使用非阻" +"塞的API,绑定回调函数到异步事件上面。在显式地关闭之前,socket会保持打开,以便" +"稍后回调函数往socket里面写东西。下面是一个基于 `tornado `_ 的例子。" + +# ff3f82109f784c47b1707ac9e3a5f831 +#: ../../async.rst:63 +msgid "" +"The main benefit is that the request handler terminates early. The handling " +"thread can move on and accept new requests while the callbacks continue to " +"write to sockets of previous requests. This is how these frameworks manage " +"to process a lot of concurrent requests with only a small number of OS " +"threads." +msgstr "" +"主要的好处就是MainHandler能早早结束,在回调函数继续写socket来响应之前的请求的" +"时候,当前线程能继续接受新的请求。这样就是为什么这类框架能同时处理很多请求," +"只使用很少的操作系统线程。" + +# 5e39762fd5df49a39faab304e9a290b1 +#: ../../async.rst:65 +msgid "" +"With Gevent+WSGI, things are different: First, terminating early has no " +"benefit because we have an unlimited pool of (pseudo)threads to accept new " +"connections. Second, we cannot terminate early because that would close the " +"socket (as required by WSGI). Third, we must return an iterable to conform " +"to WSGI." +msgstr "" +"对于Gevent和WSGI来说,情况就不一样了:首先,早早结束没有好处,因为我们的(伪)" +"线程池已经没有限制了。第二,我们不能早早结束,因为这样会关闭socket(WSGI要求如" +"此)。第三,我们必须返回一个iterator,以遵守WSGI的约定。" + +# 0d083ebaebd841c1b677840fbb7e1829 +#: ../../async.rst:67 +msgid "" +"In order to conform to the WSGI standard, all we have to do is to return a " +"body iterable that we can write to asynchronously. With the help of `gevent." +"queue `_, we can *simulate* a " +"detached socket and rewrite the previous example as follows::" +msgstr "" +"为了遵循WSGI规范,我们只需返回一个iterable的实体,异步地将其写回客户端。在 " +"`gevent.queue `_ 的帮助下,我们可以 " +"*模拟* 一个脱管的socket,上面的例子可写成这样。" + +# c2dc80f344ff438dae10bf531b546f54 +#: ../../async.rst:77 +msgid "" +"From the server perspective, the queue object is iterable. It blocks if " +"empty and stops as soon as it reaches ``StopIteration``. This conforms to " +"WSGI. On the application side, the queue object behaves like a non-blocking " +"socket. You can write to it at any time, pass it around and even start a new " +"(pseudo)thread that writes to it asynchronously. This is how long-polling is " +"implemented most of the time." +msgstr "" +"从服务器的角度来看,queue对象是iterable的。如果为空,则阻塞,一旦遇到 " +"``StopIteration`` 则停止。这符合WSGI规范。从应用的角度来看,queue对象表现的像" +"一个不会阻塞socket。你可以在任何时刻写入数据,pass it around,甚至启动一个新" +"的(伪)线程,异步写入。这是在大部分情况下,实现长轮询。" + +# 8fbf44264bb54dca80871e505abd6fa2 +#: ../../async.rst:81 +msgid "Finally: WebSockets" +msgstr "最后: WebSockets" + +# 07ae2daba04a4d888fbee239cbfdbbee +#: ../../async.rst:83 +msgid "" +"Lets forget about the low-level details for a while and speak about " +"WebSockets. Since you are reading this article, you probably know what " +"WebSockets are: A bidirectional communication channel between a browser " +"(client) and a web application (server)." +msgstr "" +"让我们暂时忘记底层的细节,来谈谈WebSocket。既然你正在阅读这篇文章,你有可能已" +"经知道什么是WebSocket了,一个在浏览器(客户端)和Web应用(服务端)的双向的交流通" +"道。" + +# 66508ae9eb304f00960be55668071c01 +#: ../../async.rst:85 +msgid "" +"Thankfully the `gevent-websocket `_ package does all the hard work for us. Here is a simple " +"WebSocket endpoint that receives messages and just sends them back to the " +"client::" +msgstr "" +"感谢 `gevent-websocket `_ 包帮" +"我们做的工作。下面是一个WebSocket的简单例子,接受消息然后将其发回客户端。" + +# 0e40e6a944d144f7bffce3b8696fbcae +#: ../../async.rst:109 +msgid "" +"The while-loop runs until the client closes the connection. You get the " +"idea :)" +msgstr "while循环直到客户端关闭连接的时候才会终止。You get the idea :)" + +# 79623942975c406d9beb3f23fa1191ea +#: ../../async.rst:111 +msgid "The client-site JavaScript API is really straight forward, too::" +msgstr "客户端的JavaScript API也十分简洁明了::" + +# 14e90902f8e64556adcf90b146d2bd97 +#, fuzzy +#~ msgid "new added linnnnnnne" +#~ msgstr "新加的一行" diff -Nru python-bottle-0.11.6/docs/_locale/zh_CN/changelog.po python-bottle-0.12.0/docs/_locale/zh_CN/changelog.po --- python-bottle-0.11.6/docs/_locale/zh_CN/changelog.po 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/docs/_locale/zh_CN/changelog.po 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,867 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) 2009-2012, Marcel Hellkamp +# This file is distributed under the same license as the Bottle package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Bottle 0.12-dev\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-08-09 17:22\n" +"PO-Revision-Date: 2012-11-09 16:39+0800\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +# e3b13e4c346c4c4987654e4efa0d199b +#: ../../changelog.rst:6 +msgid "Release Notes and Changelog" +msgstr "发布摘要和更改历史(不译)" + +# 5ecfd3788a134d88916d9e28aac8ad2e +#: ../../changelog.rst:11 +msgid "Release 0.12" +msgstr "" + +# 5e23fcb10b5f47fda6e625beec56df44 +#: ../../changelog.rst:15 +msgid "" +"New SimpleTemplate parser implementation * Support for multi-line code " +"blocks (`<% ... %>`). * The keywords `include` and `rebase` are functions " +"now and can accept variable template names." +msgstr "" + +# a109362aa7f44d64adb92bb0b9823353 +#: ../../changelog.rst:18 +msgid "" +"The new :meth:`BaseRequest.route` property returns the :class:`Route` that " +"matched the request." +msgstr "" + +# a97673c7116a4c3b8743eebe4b2d5a3e +#: ../../changelog.rst:21 +msgid "Release 0.11" +msgstr "" + +# 6731700ec87a44e788d995610cedd01c +#: ../../changelog.rst:25 +msgid "" +"Native support for Python 2.x and 3.x syntax. No need to run 2to3 anymore." +msgstr "" + +# 6b9ce1b8ed83434ab1f16a966e20e8f9 +#: ../../changelog.rst:26 +msgid "" +"Support for partial downloads (``Range`` header) in :func:`static_file`." +msgstr "" + +# e5bb007545f84215afaeabbf80c32589 +#: ../../changelog.rst:27 +msgid "" +"The new :class:`ResourceManager` interface helps locating files bundled with " +"an application." +msgstr "" + +# db95b112ec664973b25c1651b6b599d0 +#: ../../changelog.rst:28 +msgid "" +"Added a server adapter for `waitress `_." +msgstr "" + +# f5b8dfb81e8446ac8133d757d683d667 +#: ../../changelog.rst:29 +msgid "" +"New :meth:`Bottle.merge` method to install all routes from one application " +"into another." +msgstr "" + +# a109362aa7f44d64adb92bb0b9823353 +#: ../../changelog.rst:30 +msgid "" +"New :attr:`BaseRequest.app` property to get the application object that " +"handles a request." +msgstr "" + +# 6b57a33990c64361b1ad2db50f53b000 +#: ../../changelog.rst:31 +msgid "" +"Added :meth:`FormsDict.decode()` to get an all-unicode version (needed by " +"WTForms)." +msgstr "" + +# c20daa7d47b54d8a822c0bf71decf822 +#: ../../changelog.rst:32 +msgid ":class:`MultiDict` and subclasses are now pickle-able." +msgstr "" + +# e86dad3a34f6465c89f5637165bc312c +#: ../../changelog.rst:35 +msgid "API Changes" +msgstr "" + +# 73bb02534f0b49ec9c08de53ccbd60a8 +#: ../../changelog.rst:36 +msgid "" +":attr:`Response.status` is a read-write property that can be assigned either " +"a numeric status code or a status string with a reason phrase (``200 OK``). " +"The return value is now a string to better match existing APIs (WebOb, " +"werkzeug). To be absolutely clear, you can use the read-only properties :" +"attr:`BaseResponse.status_code` and :attr:`BaseResponse.status_line`." +msgstr "" + +# 5772862eb6624e688fbc4af59dd1988c +#: ../../changelog.rst:39 +msgid "API Deprecations" +msgstr "" + +# b4e888031c9e4efabda02834f1f21867 +#: ../../changelog.rst:40 +msgid "" +":class:`SimpleTALTemplate` is now deprecating. There seems to be no demand." +msgstr "" + +# 44359592bf86402aa2d88d227a948cff +#: ../../changelog.rst:43 +msgid "Release 0.10" +msgstr "" + +# 4dec1a937025421dbc41cc67f1f57bf5 +#: ../../changelog.rst:45 +msgid "Plugin API v2" +msgstr "" + +# a23578035d494816ab995e2fea0cc4a8 +#: ../../changelog.rst:47 +msgid "To use the new API, set :attr:`Plugin.api` to ``2``." +msgstr "" + +# 9b6f06b4607c4a83b128c436635c0e7b +#: ../../changelog.rst:48 +msgid "" +":meth:`Plugin.apply` receives a :class:`Route` object instead of a context " +"dictionary as second parameter. The new object offers some additional " +"information and may be extended in the future." +msgstr "" + +# 736de72390b847b0b094c61446e3b83d +#: ../../changelog.rst:49 +msgid "" +"Plugin names are considered unique now. The topmost plugin with a given name " +"on a given route is installed, all other plugins with the same name are " +"silently ignored." +msgstr "" + +# 065c1f375b0d47f8a8851d6df581722c +#: ../../changelog.rst:51 +msgid "The Request/Response Objects" +msgstr "" + +# 566c0eab00e54295939eef631f59d2f8 +#: ../../changelog.rst:53 +msgid "" +"Added :attr:`BaseRequest.json`, :attr:`BaseRequest.remote_route`, :attr:" +"`BaseRequest.remote_addr`, :attr:`BaseRequest.query` and :attr:`BaseRequest." +"script_name`." +msgstr "" + +# c830c4ee4ad848f1b1f205ed53e05870 +#: ../../changelog.rst:54 +msgid "" +"Added :attr:`BaseResponse.status_line` and :attr:`BaseResponse.status_code` " +"attributes. In future releases, :attr:`BaseResponse.status` will return a " +"string (e.g. ``200 OK``) instead of an integer to match the API of other " +"common frameworks. To make the transition as smooth as possible, you should " +"use the verbose attributes from now on." +msgstr "" + +# 45f4cc97a9fc4d4c88ede6131214b378 +#: ../../changelog.rst:55 +msgid "" +"Replaced :class:`MultiDict` with a specialized :class:`FormsDict` in many " +"places. The new dict implementation allows attribute access and handles " +"unicode form values transparently." +msgstr "" + +# 9ed871a4ef814b268c9e32e6a0a98493 +#: ../../changelog.rst:57 +msgid "Templates" +msgstr "" + +# 55e66477c8414856a940b14cc9fbf01f +#: ../../changelog.rst:59 +msgid "" +"Added three new functions to the SimpleTemplate default namespace that " +"handle undefined variables: :func:`stpl.defined`, :func:`stpl.get` and :func:" +"`stpl.setdefault`." +msgstr "" + +# 6231999b3223400281c6f121c3ec9539 +#: ../../changelog.rst:60 +msgid "" +"The default escape function for SimpleTemplate now additionally escapes " +"single and double quotes." +msgstr "" + +# d5da0048d0e54adcbf4a6eca77d24b03 +#: ../../changelog.rst:62 +msgid "Routing" +msgstr "" + +# 4f100bf5c0244f6b844b9c80458afd78 +#: ../../changelog.rst:64 +msgid "" +"A new route syntax (e.g. ``/object/``) and support for route " +"wildcard filters." +msgstr "" + +# 76bf73f4d1154f699127453d3305cf41 +#: ../../changelog.rst:65 +msgid "Four new wildcard filters: `int`, `float`, `path` and `re`." +msgstr "" + +# 453b79ee2f6847459a473af285884aa7 +#: ../../changelog.rst:67 +msgid "Other changes" +msgstr "" + +# 4e05013ef2554d89b298d321a0c130bf +#: ../../changelog.rst:69 +msgid "Added command line interface to load applications and start servers." +msgstr "" + +# 0d60ba54697545d6b867c274f4d05833 +#: ../../changelog.rst:70 +msgid "" +"Introduced a :class:`ConfigDict` that makes accessing configuration a lot " +"easier (attribute access and auto-expanding namespaces)." +msgstr "" + +# 124fc7cd3d784edc8c2a4cd522393e85 +#: ../../changelog.rst:71 +msgid "Added support for raw WSGI applications to :meth:`Bottle.mount`." +msgstr "" + +# 83811d6a04d544c18508b3dd75c18391 +#: ../../changelog.rst:72 +msgid ":meth:`Bottle.mount` parameter order changed." +msgstr "" + +# 85e4e2d1c2c2476ca6125a5f4cfb467c +#: ../../changelog.rst:73 +msgid "" +":meth:`Bottle.route` now accpets an import string for the ``callback`` " +"parameter." +msgstr "" + +# 824284a34edd4f99ad16418c4ab77790 +#: ../../changelog.rst:74 +msgid "Dropped Gunicorn 0.8 support. Current supported version is 0.13." +msgstr "" + +# 8ff0d29768f34cf3b525c2330139e146 +#: ../../changelog.rst:75 +msgid "Added custom options to Gunicorn server." +msgstr "" + +# 9deeaef2ec5a4b7a803c705792b9dda8 +#: ../../changelog.rst:76 +msgid "" +"Finally dropped support for type filters. Replace with a custom plugin of " +"needed." +msgstr "" + +# 4f1fed330d1d47168ae311e0e3a8f8ac +#: ../../changelog.rst:80 +msgid "Release 0.9" +msgstr "" + +# d5d0f375fb4749a69c9403412a7eb5ae +#: ../../changelog.rst:83 +msgid "Whats new?" +msgstr "" + +# 8b8a0a81954b4ba1b74a6ee31ca3a53c +#: ../../changelog.rst:84 +msgid "" +"A brand new plugin-API. See :ref:`plugins` and :doc:`plugindev` for details." +msgstr "" + +# 7507729af5ec4cb88c6e5cf549cc93e3 +#: ../../changelog.rst:85 +msgid "" +"The :func:`route` decorator got a lot of new features. See :meth:`Bottle." +"route` for details." +msgstr "" + +# 207cf445fdd34b639c2ae07ac6a85090 +#: ../../changelog.rst:86 +msgid "" +"New server adapters for `gevent `_, `meinheld " +"`_ and `bjoern `_." +msgstr "" + +# daa55ce0e10f45d183c1b365dc2ccba0 +#: ../../changelog.rst:87 +msgid "Support for SimpleTAL templates." +msgstr "" + +# 1905b888cb7b4a1b9d3ebe3c0ef7a66f +#: ../../changelog.rst:88 +msgid "Better runtime exception handling for mako templates in debug mode." +msgstr "" + +# 9a81aa701ae24a6aa4a26e0aa3567d32 +#: ../../changelog.rst:89 +msgid "Lots of documentation, fixes and small improvements." +msgstr "" + +# 4321fbe631844b8d84ca43fad60e8b27 +#: ../../changelog.rst:90 +msgid "A new :data:`Request.urlparts` property." +msgstr "" + +# 4e839c60c903480690fd424f143c3757 +#: ../../changelog.rst:93 +msgid "Performance improvements" +msgstr "" + +# 85fe44152baa4daca39a7b1e93c00ad4 +#: ../../changelog.rst:94 +msgid "" +"The :class:`Router` now special-cases ``wsgi.run_once`` environments to " +"speed up CGI." +msgstr "" + +# b909340087724797bd7bf31da068edaa +#: ../../changelog.rst:95 +msgid "" +"Reduced module load time by ~30% and optimized template parser. See `8ccb2d " +"`_, `f72a7c `_ and `b14b9a `_ for details." +msgstr "" + +# 72e73bff954c4217a09e2401bac9674c +#: ../../changelog.rst:96 +msgid "" +"Support for \"App Caching\" on Google App Engine. See `af93ec `_." +msgstr "" + +# d9923a5832b142f6afaa67f61a3d3fcf +#: ../../changelog.rst:97 +msgid "" +"Some of the rarely used or deprecated features are now plugins that avoid " +"overhead if the feature is not used." +msgstr "" + +# 1139037ba4c74e8dbacb963e86b1734a +# 70b7ae6d681745ec8f6d7bae78a2d9b3 +#: ../../changelog.rst:100 ../../changelog.rst:111 +msgid "API changes" +msgstr "" + +# 7a0ea9dcf798416e8870410cf7c67aef +#: ../../changelog.rst:101 +msgid "" +"This release is mostly backward compatible, but some APIs are marked " +"deprecated now and will be removed for the next release. Most noteworthy:" +msgstr "" + +# 5e21a9d02a434dd582e322125054fd88 +#: ../../changelog.rst:103 +msgid "" +"The ``static`` route parameter is deprecated. You can escape wild-cards with " +"a backslash." +msgstr "" + +# 1b6da094ff5d4e7f9aa311c9b7b3491b +#: ../../changelog.rst:104 +msgid "" +"Type-based output filters are deprecated. They can easily be replaced with " +"plugins." +msgstr "" + +# b0f7b728309c4b7690e2e4225a4b8a2e +#: ../../changelog.rst:108 +msgid "Release 0.8" +msgstr "" + +# 5c282c9843094792a4307b3034967be9 +#: ../../changelog.rst:112 +msgid "These changes may break compatibility with previous versions." +msgstr "" + +# 684f663e070f4b09b48180ca47839c75 +#: ../../changelog.rst:114 +msgid "" +"The built-in Key/Value database is not available anymore. It is marked " +"deprecated since 0.6.4" +msgstr "" + +# ab818cf68d8a4e9ba07ffbabfd3339de +#: ../../changelog.rst:115 +msgid "The Route syntax and behaviour changed." +msgstr "" + +# 1e6b6b4d1d3a42a09840dd65a3329a8f +#: ../../changelog.rst:117 +msgid "" +"Regular expressions must be encapsulated with ``#``. In 0.6 all non-" +"alphanumeric characters not present in the regular expression were allowed." +msgstr "" + +# 71c8af4451404191b1f0d4cbe8c5e4ec +#: ../../changelog.rst:118 +msgid "" +"Regular expressions not part of a route wildcard are escaped automatically. " +"You don't have to escape dots or other regular control characters anymore. " +"In 0.6 the whole URL was interpreted as a regular expression. You can use " +"anonymous wildcards (``/index:#(\\.html)?#``) to achieve a similar behaviour." +msgstr "" + +# 27f16af5e0ca47a5a555d1b193780839 +#: ../../changelog.rst:120 +msgid "" +"The ``BreakTheBottle`` exception is gone. Use :class:`HTTPResponse` instead." +msgstr "" + +# a4d29013e8bd4e0d8ab3a69f2d215b0c +#: ../../changelog.rst:121 +msgid "" +"The :class:`SimpleTemplate` engine escapes HTML special characters in " +"``{{bad_html}}`` expressions automatically. Use the new ``{{!good_html}}`` " +"syntax to get old behaviour (no escaping)." +msgstr "" + +# 0ca575ecd26446f981bedadf96ca4075 +#: ../../changelog.rst:122 +msgid "" +"The :class:`SimpleTemplate` engine returns unicode strings instead of lists " +"of byte strings." +msgstr "" + +# 44edac6789ef4e09a8ce012c161b5143 +#: ../../changelog.rst:123 +msgid "``bottle.optimize()`` and the automatic route optimization is obsolete." +msgstr "" + +# 9d76cc1eee7d4ffc8856e7cc36b03afb +#: ../../changelog.rst:124 +msgid "Some functions and attributes were renamed:" +msgstr "" + +# 2476d07cfb614c1589d293b030ead391 +#: ../../changelog.rst:126 +msgid ":attr:`Request._environ` is now :attr:`Request.environ`" +msgstr "" + +# 078eea95ecef4111a9c366da245647bb +#: ../../changelog.rst:127 +msgid ":attr:`Response.header` is now :attr:`Response.headers`" +msgstr "" + +# 521c767a85e748848aa22a37b85824b0 +#: ../../changelog.rst:128 +msgid ":func:`default_app` is obsolete. Use :func:`app` instead." +msgstr "" + +# c06f82820b6647a69b2ba0a5bf7fc709 +#: ../../changelog.rst:130 +msgid "The default :func:`redirect` code changed from 307 to 303." +msgstr "" + +# 023b03a59c374d43b8abfd0b2c67985a +#: ../../changelog.rst:131 +msgid "Removed support for ``@default``. Use ``@error(404)`` instead." +msgstr "" + +# 0f3f04e5fb1f4e8abddb03e2420cbdfe +#: ../../changelog.rst:135 +msgid "New features" +msgstr "" + +# 68ec57e76d7c464fa97c2adb8fa7782a +#: ../../changelog.rst:136 +msgid "This is an incomplete list of new features and improved functionality." +msgstr "" + +# a371732ab6744c0f9dfa6d9ac04e5f83 +#: ../../changelog.rst:138 +msgid "" +"The :class:`Request` object got new properties: :attr:`Request.body`, :attr:" +"`Request.auth`, :attr:`Request.url`, :attr:`Request.header`, :attr:`Request." +"forms`, :attr:`Request.files`." +msgstr "" + +# c21e44bb8b464528ac46f154770df091 +#: ../../changelog.rst:139 +msgid "" +"The :meth:`Response.set_cookie` and :meth:`Request.get_cookie` methods are " +"now able to encode and decode python objects. This is called a *secure " +"cookie* because the encoded values are signed and protected from changes on " +"client side. All pickle-able data structures are allowed." +msgstr "" + +# a87aa779e91b44ca985910e27559bb56 +#: ../../changelog.rst:140 +msgid "" +"The new :class:`Router` class drastically improves performance for setups " +"with lots of dynamic routes and supports named routes (named route + dict = " +"URL string)." +msgstr "" + +# 3dcf1f0ad1684a1bbeec83c1432f51cc +#: ../../changelog.rst:141 +msgid "" +"It is now possible (and recommended) to return :exc:`HTTPError` and :exc:" +"`HTTPResponse` instances or other exception objects instead of raising them." +msgstr "" + +# 5bbedf45b10e4286a457b982a9be595f +#: ../../changelog.rst:142 +msgid "" +"The new function :func:`static_file` equals :func:`send_file` but returns a :" +"exc:`HTTPResponse` or :exc:`HTTPError` instead of raising it. :func:" +"`send_file` is deprecated." +msgstr "" + +# a25f7ad0c1c94ddaa447da64fe73c796 +#: ../../changelog.rst:143 +msgid "" +"New :func:`get`, :func:`post`, :func:`put` and :func:`delete` decorators." +msgstr "" + +# 569fa16a63714dddb16fe9d53f06dec4 +#: ../../changelog.rst:144 +msgid "The :class:`SimpleTemplate` engine got full unicode support." +msgstr "" + +# 981b75a9f823425cb1ad7f074d56570d +#: ../../changelog.rst:145 +msgid "Lots of non-critical bugfixes." +msgstr "" + +# 29d64452b9d54e018ffb4749c7a406cf +#: ../../changelog.rst:151 +msgid "Contributors" +msgstr "" + +# 3d3c594c340c4de0bff6b459a58406ba +#: ../../../AUTHORS:1 +msgid "" +"Bottle is written and maintained by Marcel Hellkamp ." +msgstr "" + +# 54e9ee881fd6495c8b23f616e0406769 +#: ../../../AUTHORS:3 +msgid "" +"Thanks to all the people who found bugs, sent patches, spread the word, " +"helped each other on the mailing-list and made this project possible. I hope " +"the following (alphabetically sorted) list is complete. If you miss your " +"name on that list (or want your name removed) please :doc:`tell me " +"` or add it yourself." +msgstr "" + +# 0980c1626a8447c6b813c2829f9677ad +#: ../../../AUTHORS:5 +msgid "acasajus" +msgstr "" + +# 7e09ffa00aa947148c0011dd33888fd9 +#: ../../../AUTHORS:6 +msgid "Adam R. Smith" +msgstr "" + +# 6eb2f1d5d1a34670a4d411d0d58af6f8 +#: ../../../AUTHORS:7 +msgid "Alexey Borzenkov" +msgstr "" + +# c0ef5ea8c83d4cb481e49273f090b7bd +#: ../../../AUTHORS:8 +msgid "Alexis Daboville" +msgstr "" + +# 7a83e67a90b54ba19296f5691f497f5a +#: ../../../AUTHORS:9 +msgid "Anton I. Sipos" +msgstr "" + +# cf41f70b82454d2f900cd67c7bf4859f +#: ../../../AUTHORS:10 +msgid "Anton Kolechkin" +msgstr "" + +# aaff5287411f4076b41c503b294423c3 +#: ../../../AUTHORS:11 +msgid "apexi200sx" +msgstr "" + +# e1981576d3064a1d9fd0ee7d6c83c116 +#: ../../../AUTHORS:12 +msgid "apheage" +msgstr "" + +# c83c4dcc9ddf44918a4d7b3f849e6920 +#: ../../../AUTHORS:13 +msgid "BillMa" +msgstr "" + +# bdaa82d9c0fd4bffaef7c55e3e32bed5 +#: ../../../AUTHORS:14 +msgid "Brad Greenlee" +msgstr "" + +# ed51155ae7f14b5f92c925d5fa8311f7 +#: ../../../AUTHORS:15 +msgid "Brandon Gilmore" +msgstr "" + +# d0e6c599c71343b69cbdb40252364e19 +#: ../../../AUTHORS:16 +msgid "Branko Vukelic" +msgstr "" + +# 703a026e74a64faabfa4b504272b57f5 +#: ../../../AUTHORS:17 +msgid "Brian Sierakowski" +msgstr "" + +# b58c5a07eeb840e19be4f380d66a5ee1 +#: ../../../AUTHORS:18 +msgid "Brian Wickman" +msgstr "" + +# 12879f4bf9bd460d94519f3cd9885b11 +#: ../../../AUTHORS:19 +msgid "Carl Scharenberg" +msgstr "" + +# bb0bb95e445143288452a8c513af8769 +#: ../../../AUTHORS:20 +msgid "Damien Degois" +msgstr "" + +# d8f9bba29e0e42e6bdda59792350c6fb +#: ../../../AUTHORS:21 +msgid "David Buxton" +msgstr "" + +# cc4e0bd070384814ba6f7f676379dfe9 +#: ../../../AUTHORS:22 +msgid "Duane Johnson" +msgstr "" + +# 2532fe296cb54e65bcb3b922af4c3fe1 +#: ../../../AUTHORS:23 +msgid "fcamel" +msgstr "" + +# 5c9cc99c634746e5997832a08952b471 +#: ../../../AUTHORS:24 +msgid "Frank Murphy" +msgstr "" + +# 68194afa7d5c4ac3aa6a1922a3e209ef +#: ../../../AUTHORS:25 +msgid "Frederic Junod" +msgstr "" + +# 7adefaece3f649b88f4f55201e0f7ba7 +#: ../../../AUTHORS:26 +msgid "goldfaber3012" +msgstr "" + +# b5d811568c4943499f00e1204087f181 +#: ../../../AUTHORS:27 +msgid "Greg Milby" +msgstr "" + +# 41816fb927c74b3c87a99e7df2117d32 +#: ../../../AUTHORS:28 +msgid "gstein" +msgstr "" + +# 2095ce633cc84e539d6b82bf8a62eb37 +#: ../../../AUTHORS:29 +msgid "Ian Davis" +msgstr "" + +# d364ee9c173244829fcd7ed5a11025e4 +#: ../../../AUTHORS:30 +msgid "Itamar Nabriski" +msgstr "" + +# 74d0129175cf4e6fbd34675523a82c70 +#: ../../../AUTHORS:31 +msgid "Iuri de Silvio" +msgstr "" + +# 87f66bf393c44d08ae2d268ba591339c +#: ../../../AUTHORS:32 +msgid "Jaimie Murdock" +msgstr "" + +# c55c4c1c4b81437b8cfdff60bd0c1f31 +#: ../../../AUTHORS:33 +msgid "Jeff Nichols" +msgstr "" + +# 0c2886a875204f7c8defe46bdedcbdb6 +#: ../../../AUTHORS:34 +msgid "Jeremy Kelley" +msgstr "" + +# 988c4fb0e4854b8d923228060aee7433 +#: ../../../AUTHORS:35 +msgid "joegester" +msgstr "" + +# 46ef0c492f5e4241bcb7fd2ebb6b4566 +#: ../../../AUTHORS:36 +msgid "Johannes Krampf" +msgstr "" + +# 4783b01715ac4923b56fc45a2702dfe0 +#: ../../../AUTHORS:37 +msgid "Jonas Haag" +msgstr "" + +# d306e7acdea84aacbe0ba7a3a15d192a +#: ../../../AUTHORS:38 +msgid "Joshua Roesslein" +msgstr "" + +# b7c3438ca6b3409fad9c56521b6829fb +#: ../../../AUTHORS:39 +msgid "Karl" +msgstr "" + +# 16e8c8a3acd941df86d72027380dfb04 +#: ../../../AUTHORS:40 +msgid "Kevin Zuber" +msgstr "" + +# dd30a7419cdb43e8a3b3d7df3284674c +#: ../../../AUTHORS:41 +msgid "Kraken" +msgstr "" + +# a8b48d487cc8410baf152e2fb6d4fb01 +#: ../../../AUTHORS:42 +msgid "Kyle Fritz" +msgstr "" + +# c681593665c243338c860eb7bb56c1ed +#: ../../../AUTHORS:43 +msgid "m35" +msgstr "" + +# aeb1e664f1f6451b94ddebf2000fdf2d +#: ../../../AUTHORS:44 +msgid "Marcos Neves" +msgstr "" + +# ec8999946da6404bbdb7b4fa5b0ed337 +#: ../../../AUTHORS:45 +msgid "masklinn" +msgstr "" + +# fbe852481e8b4138a6cef43692ea4062 +#: ../../../AUTHORS:46 +msgid "Michael Labbe" +msgstr "" + +# fb17691b091948fab45cae8c61fbcf68 +#: ../../../AUTHORS:47 +msgid "Michael Soulier" +msgstr "" + +# 042352794f4948448ca9ae9829a8422b +#: ../../../AUTHORS:48 +msgid "`reddit `_" +msgstr "" + +# ab1ec82972f34bb790e729cbf8b98f3b +#: ../../../AUTHORS:49 +msgid "Nicolas Vanhoren" +msgstr "" + +# b574d39c3b054efcb935495e828c1b13 +#: ../../../AUTHORS:50 +msgid "Robert Rollins" +msgstr "" + +# d0930b5536d6409fba2d2a3c58831cd0 +#: ../../../AUTHORS:51 +msgid "rogererens" +msgstr "" + +# 9ec46b40921b4b60bd626f483591f11c +#: ../../../AUTHORS:52 +msgid "rwxrwx" +msgstr "" + +# 2fdc813656f4497ea4965094ee51bba4 +#: ../../../AUTHORS:53 +msgid "Santiago Gala" +msgstr "" + +# a9c955e0e585492ba574bb32a2bb9e79 +#: ../../../AUTHORS:54 +msgid "Sean M. Collins" +msgstr "" + +# e138be55fec543c588bf70059416a825 +#: ../../../AUTHORS:55 +msgid "Sebastian Wollrath" +msgstr "" + +# 9e3e792a9ec341d291935a15b52cb90b +#: ../../../AUTHORS:56 +msgid "Seth" +msgstr "" + +# b51dd60ad0534314892b22af5c0db5e4 +#: ../../../AUTHORS:57 +msgid "Sigurd Høgsbro" +msgstr "" + +# 74b5a20b53ed4401ac3207a0a7bf8cd5 +#: ../../../AUTHORS:58 +msgid "Stuart Rackham" +msgstr "" + +# 0a6e3ab504794cb8a2e97d3445765ef1 +#: ../../../AUTHORS:59 +msgid "Sun Ning" +msgstr "" + +# 609e3dc7fb6a48d087dfd3088f3c4868 +#: ../../../AUTHORS:60 +msgid "Tomás A. Schertel" +msgstr "" + +# d613389827534583a72af33bb7e2665e +#: ../../../AUTHORS:61 +msgid "Tristan Zajonc" +msgstr "" + +# f2429875afcd40cdb26fc89dc3862aa0 +#: ../../../AUTHORS:62 +msgid "voltron" +msgstr "" + +# b80391cec11646ed9e134e30fe1d3daa +#: ../../../AUTHORS:63 +msgid "Wieland Hoffmann" +msgstr "" + +# 4085ae7ae8f643c98689be3a5860b3b6 +#: ../../../AUTHORS:64 +msgid "zombat" +msgstr "" diff -Nru python-bottle-0.11.6/docs/_locale/zh_CN/configuration.po python-bottle-0.12.0/docs/_locale/zh_CN/configuration.po --- python-bottle-0.11.6/docs/_locale/zh_CN/configuration.po 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/docs/_locale/zh_CN/configuration.po 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,297 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) 2009-2013, Marcel Hellkamp +# This file is distributed under the same license as the Bottle package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Bottle 0.12-dev\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-08-09 18:12\n" +"PO-Revision-Date: 2013-08-09 18:10+0800\n" +"Last-Translator: \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.5.7\n" + +# c1741ba1cf24423d937ac8eb7155aa10 +#: ../../configuration.rst:3 +msgid "Configuration (DRAFT)" +msgstr "配置文件(初稿)" + +# 95c5c5957b604396a280c4987b0be08d +#: ../../configuration.rst:8 +msgid "" +"This is a draft for a new API. `Tell us `_ " +"what you think." +msgstr "" +"这是一个新的API, 可以 `告诉我们 `_ 你的想" +"法" + +# abf17b8e32a84f119f89fd9e54ae738a +#: ../../configuration.rst:10 +msgid "" +"Bottle applications can store their configuration in :attr:`Bottle.config`, " +"a dict-like object and central place for application specific settings. This " +"dictionary controls many aspects of the framework, tells (newer) plugins " +"what to do, and can be used to store your own configuration as well." +msgstr "" +"Bottle应用可以在 :attr:`Bottle.config` 这个类似于字典的对象中,存储它们的配" +"置。这个对象在很多方面,影响着Bottle框架和相应的插件。你也可以在这个对象中," +"存储你的自定义配置。" + +# d94af1e48ef146a3bf4b94258003de0f +#: ../../configuration.rst:13 +msgid "Configuration Basics" +msgstr "基础知识" + +# 8fa8b5ac47fb42ac93f250472bf34ba3 +#: ../../configuration.rst:15 +msgid "" +"The :attr:`Bottle.config` object behaves a lot like an ordinary dictionary. " +"All the common dict methods work as expected. Let us start with some " +"examples::" +msgstr "" +" :attr:`Bottle.config` 这个对象,可以当成一个字典来使用,让我们举个例子::" + +# a10e871f1f0a42fd9e88a00777e031f8 +#: ../../configuration.rst:44 +msgid "" +"The app object is not always available, but as long as you are within a " +"request context, you can use the `request` object to get the current " +"application and its configuration::" +msgstr "" +"app对象不一定总是可用的,但只要你在处理一个请求,你可以使用 `request` 对象来" +"获得当前的应用对象和它的配置::" + +# 4510b753e1f843ae839da666fa8a96ea +#: ../../configuration.rst:51 +msgid "Naming Convention" +msgstr "命名约定" + +# f71bac781b854687aa55c961bb0cd7c3 +#: ../../configuration.rst:53 +msgid "" +"To make life easier, plugins and applications should follow some simple " +"rules when it comes to config parameter names:" +msgstr "" +"方便起见,插件和应用应该遵循一些简单的规则,特别是在给配置参数命名的时候:" + +# 4e47f429092a4402b928c616e1052bcd +#: ../../configuration.rst:55 +msgid "" +"All keys should be lowercase strings and follow the rules for python " +"identifiers (no special characters but the underscore)." +msgstr "" +"所有的key都应该是小写的字符串,并符合Python的变量命名规则(除了下划线外,没有" +"特殊字符)。" + +# 9162c80192d34a239d49822fde8ff2d5 +#: ../../configuration.rst:56 +msgid "" +"Namespaces are separated by dots (e.g. ``namespace.field`` or ``namespace." +"subnamespace.field``)." +msgstr "" +"命名空间通过点来区分(例如: ``namespace.field`` 或 ``namespace.subnamespacew." +"field`` )。" + +# dc379020b8a7404fa4606731b772d9f8 +#: ../../configuration.rst:57 +msgid "" +"Bottle uses the root namespace for its own configuration. Plugins should " +"store all their variables in their own namespace (e.g. ``sqlite.db`` or " +"``werkzeug.use_debugger``)." +msgstr "" +"Bottle框架,使用根命名空间来存储它的配置。插件应该在它们自己的命名空间中存储" +"它们的变量(例如: `sqlite.db`` 或 ``werkzeug.use_debugger`` )。" + +# 93d339420982447bb137607a1b05aa4e +#: ../../configuration.rst:58 +msgid "" +"Your own application should use a separate namespace (e.g. ``myapp.*``)." +msgstr "你的应用应该使用一个独立的命名空间(例如: ``myapp.*`` )。" + +# aff46481cbe04391926ec015d7aada17 +#: ../../configuration.rst:62 +msgid "Loading Configuration from a File" +msgstr "从文件中加载配置" + +# 09f7f030d1054a308f955bd4f54221e6 +#: ../../configuration.rst:66 +msgid "" +"Configuration files are useful if you want to enable non-programmers to " +"configure your application, or just don't want to hack python module files " +"just to change the database port. A very common syntax for configuration " +"files is shown here:" +msgstr "" +"在你不想通过修改代码来修改配置的时候,配置文件是非常有用的。常见的配置文件语" +"法如下:" + +# 7376404326fe4ae18113d7aa57c417a8 +#: ../../configuration.rst:78 +msgid "" +"With :meth:`ConfigDict.load_config` you can load these ``*.ini`` style " +"configuration files from disk and import their values into your existing " +"configuration::" +msgstr "" +"通过 :meth:`ConfigDict.load_config` 方法,你可以从一些ini文件中导入配置::" + +# 7349ce363a5b424c97634c49c54c8f94 +#: ../../configuration.rst:84 +msgid "Loading Configuration from a nested :class:`dict`" +msgstr "从字典中加载配置" + +# 5477eb75b0e54baf9afdd7013f946012 +#: ../../configuration.rst:88 +msgid "" +"Another useful method is :meth:`ConfigDict.load_dict`. This method takes an " +"entire structure of nested dictionaries and turns it into a flat list of " +"keys and values with namespaced keys::" +msgstr "" +"另外一个有用的方法,是 :meth:`ConfigDict.load_dict` 。将字典中的配置,放到各" +"自的命名空间下面::" + +# d8ac42150deb4bf8a3417f70f15e7452 +#: ../../configuration.rst:109 +msgid "Listening to configuration changes" +msgstr "监听配置的变更" + +# 0130fae477d3494cb5f90534260ac3a2 +#: ../../configuration.rst:113 +msgid "" +"The ``config`` hook on the application object is triggered each time a value " +"in :attr:`Bottle.config` is changed. This hook can be used to react on " +"configuration changes at runtime, for example reconnect to a new database, " +"change the debug settings on a background service or resize worker thread " +"pools. The hook callback receives two arguments (key, new_value) and is " +"called before the value is actually changed in the dictionary. Raising an " +"exception from a hook callback cancels the change and the old value is " +"preserved." +msgstr "" +"每次 :attr:`Bottle.config` 中的值有变更的时候,会触发 ``config`` 这个钩子。" +"这个钩子可以用于在运行时,对配置的改动做出响应,例如连接到一个新的数据库,改" +"变后台服务的debug配置,或更改线程池的大小。这个钩子接收两个参数(key, " +"new_value),在 :attr:`Bottle.config` 中的值被改动之前触发。如果这个钩子抛出了" +"异常,那么 :attr:`Bottle.config` 中的值将不会被改动。" + +# 649c3d1653274f2b8447ff2e4c83e0d2 +#: ../../configuration.rst:122 +msgid "" +"The hook callbacks cannot *change* the value that is to be stored to the " +"dictionary. That is what filters are for." +msgstr "" +"这个钩子不能 *改变* 将要存到 :attr:`Bottle.config` 对象中的值。做这件事的是" +"filter(过滤器)。" + +# c6eb3585a3214eaca881fbcc36bd6719 +#: ../../configuration.rst:128 +msgid "Filters and other Meta Data" +msgstr "过滤器和其它元数据" + +# 5009754fd0a34a9baf4dddb9427176b1 +#: ../../configuration.rst:132 +msgid "" +":class:`ConfigDict` allows you to store meta data along with configuration " +"keys. Two meta fields are currently defined:" +msgstr "" +":class:`ConfigDict` 对象允许你给配置中每个key定义元数据。当前定义了help和" +"filter:" + +# 3c150dd27a0343d3b27b76a2c497761a +#: ../../configuration.rst:136 +msgid "help" +msgstr "" + +# 6400abfe8a1046a1b8fc2d88411ed45e +#: ../../configuration.rst:135 +msgid "" +"A help or description string. May be used by debugging, introspection or " +"admin tools to help the site maintainer configuring their application." +msgstr "一个描述字符串。可以被debug或管理工具利用,来帮助网站管理员填写配置。" + +# e1fa67475b744125be6c8fd53881d5fd +#: ../../configuration.rst:139 +msgid "filter" +msgstr "" + +# 44aed643e8794ef59dcd36e1535562aa +#: ../../configuration.rst:139 +msgid "" +"A callable that accepts and returns a single value. If a filter is defined " +"for a key, any new value stored to that key is first passed through the " +"filter callback. The filter can be used to cast the value to a different " +"type, check for invalid values (throw a ValueError) or trigger side effects." +msgstr "" +"一个可运行的对象,接受和返回一个值。如果一个key定义了一个filter,任何将要存到" +"这个key中的值,都会先传给filter的相应回调函数。在回调函数中,可做类型转换,有" +"效性检验等工作。" + +# 75aca8a53b774765a6190e7113f09250 +#: ../../configuration.rst:141 +msgid "" +"This feature is most useful for plugins. They can validate their config " +"parameters or trigger side effects using filters and document their " +"configuration via ``help`` fields::" +msgstr "" +"这个功能比较适合被插件使用。它们可以检查它们的配置参数,或触发其它动作,或在 " +"``help`` 字段中,给配置添加说明::" + +# 07ed111dcdf9476b9cc95fac5ca0826d +#: ../../configuration.rst:163 +msgid "API Documentation" +msgstr "" + +# 453a6899724348d887f2d5bd14a4e8c4 +#: ../../../bottle.py:docstring of bottle.ConfigDict:1 +msgid "" +"A dict-like configuration storage with additional support for namespaces, " +"validators, meta-data, on_change listeners and more." +msgstr "" + +# 51f80fe3a49e49bb91e974a35ddfd599 +#: ../../../bottle.py:docstring of bottle.ConfigDict.load_config:1 +msgid "Load values from an *.ini style config file." +msgstr "" + +# f43ab902d9dd4a5fb9cdffc36e0f0751 +#: ../../../bottle.py:docstring of bottle.ConfigDict.load_config:3 +msgid "" +"If the config file contains sections, their names are used as namespaces for " +"the values within. The two special sections ``DEFAULT`` and ``bottle`` refer " +"to the root namespace (no prefix)." +msgstr "" + +# 73c203a5f128460ca20ed9c837cf2321 +#: ../../../bottle.py:docstring of bottle.ConfigDict.load_dict:1 +msgid "" +"Load values from a dictionary structure. Nesting can be used to represent " +"namespaces." +msgstr "" + +# dfc61134b7e942749147859f5df7c3f9 +#: ../../../bottle.py:docstring of bottle.ConfigDict.update:1 +msgid "" +"If the first parameter is a string, all keys are prefixed with this " +"namespace. Apart from that it works just as the usual dict.update(). " +"Example: ``update('some.namespace', key='value')``" +msgstr "" + +# fe2a8757060f427aab7545ff5ca638c2 +#: ../../../bottle.py:docstring of bottle.ConfigDict.meta_get:1 +msgid "Return the value of a meta field for a key." +msgstr "" + +# aa48b60c60d94d0588afade295f2576d +#: ../../../bottle.py:docstring of bottle.ConfigDict.meta_set:1 +msgid "" +"Set the meta field for a key to a new value. This triggers the on-change " +"handler for existing keys." +msgstr "" + +# 75344d95f5874a6d89c05b64723ebf5d +#: ../../../bottle.py:docstring of bottle.ConfigDict.meta_list:1 +msgid "Return an iterable of meta field names defined for a key." +msgstr "" diff -Nru python-bottle-0.11.6/docs/_locale/zh_CN/contact.po python-bottle-0.12.0/docs/_locale/zh_CN/contact.po --- python-bottle-0.11.6/docs/_locale/zh_CN/contact.po 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/docs/_locale/zh_CN/contact.po 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,98 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) 2009-2012, Marcel Hellkamp +# This file is distributed under the same license as the Bottle package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Bottle 0.12-dev\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-11-09 18:23\n" +"PO-Revision-Date: 2012-11-09 15:38+0800\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +# f4707b618d7b443f85b8f842370cb1e1 +#: ../../contact.rst:3 +msgid "Contact" +msgstr "联系方式" + +# d122ed5151f54e3489fad9c7753f799f +#: ../../contact.rst:6 +msgid "About the Autor" +msgstr "" + +# 7e41b0691bdb4e19b2b09ecafeac593b +#: ../../contact.rst:11 +msgid "" +"Hi, I'm *Marcel Hellkamp* (aka *defnull*), author of Bottle and the guy " +"behind this website. I'm 27 years old and studying computer science at the " +"Georg-August-University in Göttingen, Germany. Python is my favorite " +"language, but I also code in ruby and JavaScript a lot. Watch me on `twitter " +"`_ or visit my profile at `GitHub `_ to get in contact. A `mailinglist `_ is open for Bottle related questions, too." +msgstr "" + +# 5f6e942bf2fe4511802f58da1e762996 +#: ../../contact.rst:14 +msgid "About Bottle" +msgstr "" + +# dddfc8ac04dc4b6fa9919ae61b2b0542 +#: ../../contact.rst:15 +msgid "" +"This is my first open source project so far. It started and a small " +"experiment but soon got so much positive feedback I decided to make " +"something real out of it. Here it is." +msgstr "" + +# 37534297e1d145afbd8687385d35769e +#: ../../contact.rst:18 +msgid "Impressum und Kontaktdaten" +msgstr "" + +# 0b2be9f1bbe149b59b5218ba0bab3657 +#: ../../contact.rst:19 +msgid "" +"(This is required by `German law `_)" +msgstr "" + +# bb4cda2c571e4d4d9f95c83dea349a44 +#: ../../contact.rst:21 +msgid "" +"Die Nutzung der folgenden Kontaktdaten ist ausschließlich für die " +"Kontaktaufnahme mit dem Betreiber dieser Webseite bei rechtlichen Problemen " +"vorgesehen. Insbesondere die Nutzung zu Werbe- oder ähnlichen Zwecken ist " +"ausdrücklich untersagt." +msgstr "" + +# a68aba235abf46ad9da80f849585f0a0 +#: ../../contact.rst:26 +msgid "**Betreiber**: Marcel Hellkamp" +msgstr "" + +# d89eb5fcd19a4cb897d2b83b6d00e97a +#: ../../contact.rst:27 +msgid "**Ort**: D - 37075 Göttingen" +msgstr "" + +# 05e1a92f52fb43a3a654c82a21f6c651 +#: ../../contact.rst:28 +msgid "**Strasse**: Theodor-Heuss Strasse 13" +msgstr "" + +# 6c28fcf7c51e406f8049b547b9c4d439 +#: ../../contact.rst:29 +msgid "**Telefon**: +49 (0) 551 20005915" +msgstr "" + +# c53635e76e854d45870d9ae45b9c124f +#: ../../contact.rst:30 +msgid "**E-Mail**: marc at gsites dot de" +msgstr "" diff -Nru python-bottle-0.11.6/docs/_locale/zh_CN/deployment.po python-bottle-0.12.0/docs/_locale/zh_CN/deployment.po --- python-bottle-0.11.6/docs/_locale/zh_CN/deployment.po 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/docs/_locale/zh_CN/deployment.po 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,568 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) 2009-2012, Marcel Hellkamp +# This file is distributed under the same license as the Bottle package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Bottle 0.12-dev\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-11-09 18:23\n" +"PO-Revision-Date: 2012-11-09 16:46+0800\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +# e79a5ecbd44d4b95b285c0c15aa604b5 +#: ../../deployment.rst:27 +msgid "Deployment" +msgstr "部署" + +# 90d5d3c767a840e98624f37fe00e495a +#: ../../deployment.rst:29 +msgid "" +"The bottle :func:`run` function, when called without any parameters, starts " +"a local development server on port 8080. You can access and test your " +"application via http://localhost:8080/ if you are on the same host." +msgstr "" +"不添加任何参数,直接运行Bottle的 :func:`run` 函数,会启动一个本地的开发服务" +"器,监听8080端口。你可在同一部主机上访问http://localhost:8080/来测试你的应" +"用。" + +# be20533847e944aba27d3501a407c78b +#: ../../deployment.rst:31 +msgid "" +"To get your application available to the outside world, specify the IP of " +"the interface the server should listen to (e.g. ``run(host='192.168.0.1')``) " +"or let the server listen to all interfaces at once (e.g. ``run" +"(host='0.0.0.0')``). The listening port can be changed in a similar way, but " +"you need root or admin rights to choose a port below 1024. Port 80 is the " +"standard for HTTP servers::" +msgstr "" +"可更改服务器监听的IP地址(例如: ``run(host='192.168.0.1')`` ),来让应用对其可" +"访问,或者让服务器接受所有地址的请求(例如: ``run(host='0.0.0.0')`` )。可通过" +"类似的方法改变服务器监听的端口,但如果你选择了一个小于1024的端口,则需要root" +"权限。HTTP服务器的标准端口是80端口::" + +# 69e830c825454c2fbf350c56a6576300 +#: ../../deployment.rst:36 +msgid "Server Options" +msgstr "可选服务器" + +# ef9d03fa6f634c1d858b1ba8e82f0bf8 +#: ../../deployment.rst:38 +msgid "" +"The built-in default server is based on `wsgiref WSGIServer `_. This non-" +"threading HTTP server is perfectly fine for development and early " +"production, but may become a performance bottleneck when server load " +"increases. There are three ways to eliminate this bottleneck:" +msgstr "" +"内置的服务器基于 `wsgiref WSGIServer `_ 。这个单线程的HTTP服务器很适合用于开发," +"但当服务器的负载上升的时候,会成为一个性能瓶颈。有三种方法可消除这一瓶颈:" + +# ed2cadfab77a43b58b41257af4e1d365 +#: ../../deployment.rst:40 +msgid "Use a different server that is either multi-threaded or asynchronous." +msgstr "使用多线程或异步的服务器" + +# 45dbb890ad694ccab24ebebe15d0272e +#: ../../deployment.rst:41 +msgid "" +"Start multiple server processes and spread the load with a load-balancer." +msgstr "运行多个服务器,使用负载均衡" + +# 6d7e312467b649c39d095bce6eec1751 +#: ../../deployment.rst:42 +msgid "Do both." +msgstr "同时使用上面两种方法" + +# 1fa254c00fa4404a8ad6a599375d0b8c +#: ../../deployment.rst:44 +msgid "" +"**Multi-threaded** servers are the 'classic' way to do it. They are very " +"robust, reasonably fast and easy to manage. As a drawback, they can only " +"handle a limited number of connections at the same time and utilize only one " +"CPU core due to the \"Global Interpreter Lock\" (GIL). This does not hurt " +"most applications, they are waiting for network IO most of the time anyway, " +"but may slow down CPU intensive tasks (e.g. image processing)." +msgstr "" +"**多线程** 服务器是经典的解决方法。它们非常鲁棒(稳定),快速和易于管理。但它们" +"也有缺点,同时只能处理固定数量的请求,因为全局解释器锁(GIL)的存在,所有只能利" +"用一个CPU核心。对于大部分的应用而言,这无伤大雅,也许它们大部分时间都在等待网" +"络IO。但对于一些比较耗CPU的应用(例如图像处理),就要考虑性能问题了。" + +# 41ca69b13f1c4182905d274e18a5b298 +#: ../../deployment.rst:46 +msgid "" +"**Asynchronous** servers are very fast, can handle a virtually unlimited " +"number of concurrent connections and are easy to manage, but can get a bit " +"tricky. To take full advantage of their potential, you need to design your " +"application accordingly and understand the concepts of the specific server." +msgstr "" +"**异步** 服务器非常快,同时处理的请求数无上限,也方便管理。为了充分利用它们的" +"潜力,你需要根据异步的原理来设计你的应用,了解它们的工作机制。" + +# 6b274d7997da4dbab0ad352a0b6af597 +#: ../../deployment.rst:48 +msgid "" +"**Multi-processing** (forking) servers are not limited by the GIL and " +"utilize more than one CPU core, but make communication between server " +"instances more expensive. You need a database or external message query to " +"share state between processes, or design your application so that it does " +"not need any shared state. The setup is also a bit more complicated, but " +"there are good tutorials available." +msgstr "" +"**多进程** (forking) 服务器就没有受到GIL的限制,能利用多个CPU核心,但服务器实" +"例之间的交流代价比较高昂。你需要一个数据库或消息队列来在进程之间共享状态,或" +"将你的应用设计成根本不需要共享状态。多进程服务器的安装也比较负责,但已经有很" +"多好的教程了。" + +# 7950fbc4dbe849af9b6e8fcbc7fbad8c +#: ../../deployment.rst:51 +msgid "Switching the Server Backend" +msgstr "更改服务器后端" + +# 5e77521d11344f92a28053e59281eff6 +#: ../../deployment.rst:53 +msgid "" +"The easiest way to increase performance is to install a multi-threaded " +"server library like paste_ or cherrypy_ and tell Bottle to use that instead " +"of the single-threaded server::" +msgstr "" +"提高性能最简单的办法,是安装一个多线程的服务器库,例如 paste_ 和 cherrypy_ ," +"然后告诉Bottle使用它们。" + +# 06a336e02f474466b2ced7bc0d1f7847 +#: ../../deployment.rst:57 +msgid "" +"Bottle ships with a lot of ready-to-use adapters for the most common WSGI " +"servers and automates the setup process. Here is an incomplete list:" +msgstr "" +"Bottle为很多常见的WSGI服务器都编写了适配器,能自动化安装过程。下面是一个不完" +"整的清单:" + +# 1aa1ab9777c84fa3b40112b866976d2c +#: ../../deployment.rst:60 +msgid "Name" +msgstr "名称" + +# a9840552bf3248acb79506092785a343 +#: ../../deployment.rst:60 +msgid "Homepage" +msgstr "主页" + +# 2b35d4918e0f4386aa7ad7b857486c67 +#: ../../deployment.rst:60 +msgid "Description" +msgstr "描述" + +# d5996a4c22e448af81100e2762b8e852 +#: ../../deployment.rst:62 +msgid "cgi" +msgstr "" + +# da5c8bd6130b4a2ab82cc8ed2c66a17c +#: ../../deployment.rst:62 +msgid "Run as CGI script" +msgstr "" + +# 611871b28f1349a7811638c538fc3eb1 +#: ../../deployment.rst:63 +msgid "flup" +msgstr "" + +# b6ca7e7cc7d84786b66f3a66b1dac28c +#: ../../deployment.rst:63 +msgid "flup_" +msgstr "" + +# 8730e1384f3c4ca5bd4ae22a205254b9 +#: ../../deployment.rst:63 +msgid "Run as FastCGI process" +msgstr "" + +# 0618b584d4cc49909da1ba31777c181b +#: ../../deployment.rst:64 +msgid "gae" +msgstr "" + +# 747662cc00794894970a3ac8ce7e04d3 +#: ../../deployment.rst:64 +msgid "gae_" +msgstr "" + +# 9dc8135f97ba416187e21da3265bf6a6 +#: ../../deployment.rst:64 +msgid "Helper for Google App Engine deployments" +msgstr "用于Google App Engine" + +# 1cfd09034d7e4d7780ec0ada01cc1bc6 +#: ../../deployment.rst:65 +msgid "wsgiref" +msgstr "" + +# f1227078c6fc487bb5ac4b6f0ec36468 +#: ../../deployment.rst:65 +msgid "wsgiref_" +msgstr "" + +# f250f65fdf9b4f9bbc9d6a5955590ed5 +#: ../../deployment.rst:65 +msgid "Single-threaded default server" +msgstr "默认的单线程服务器" + +# 01d364e912d04e3c8e293f5a2e8961b3 +#: ../../deployment.rst:66 +msgid "cherrypy" +msgstr "" + +# fa5d69dde84a42cf835a41d99b6956fb +#: ../../deployment.rst:66 +msgid "cherrypy_" +msgstr "" + +# 0f31f5406dd342adbfe7fce1412bda34 +#: ../../deployment.rst:66 +msgid "Multi-threaded and very stable" +msgstr "多线程,稳定" + +# 1e7de22115ad4ae69df9b6a8324ab8cd +#: ../../deployment.rst:67 +msgid "paste" +msgstr "" + +# 2663f8370e1548e48310eda696f6b7a1 +#: ../../deployment.rst:67 +msgid "paste_" +msgstr "" + +# 7799c8e33cc4411fb9c8b3cf5f5cb011 +#: ../../deployment.rst:67 +msgid "Multi-threaded, stable, tried and tested" +msgstr "多线程,稳定,久经考验,充分测试" + +# 1ec1f0afa1944692af933626c83e1e59 +#: ../../deployment.rst:68 +msgid "rocket" +msgstr "" + +# 021f3f12795f4be688799b34b6f56e9d +#: ../../deployment.rst:68 +msgid "rocket_" +msgstr "" + +# 51b02f23b9a14accbba41e59aacd4bf4 +#: ../../deployment.rst:68 +msgid "Multi-threaded" +msgstr "多线程" + +# e10f6b047c6144c0bfd0543b1e9a8d26 +#: ../../deployment.rst:69 +msgid "waitress" +msgstr "" + +# eaa5c14173e642568041d89317456cda +#: ../../deployment.rst:69 +msgid "waitress_" +msgstr "" + +# 52a0ea00e1314e85a34af85cc67dc611 +#: ../../deployment.rst:69 +msgid "Multi-threaded, poweres Pyramid" +msgstr "多线程,源于Pyramid" + +# a40591f82b0b4586b8deb5e1cb8958f7 +#: ../../deployment.rst:70 +msgid "gunicorn" +msgstr "" + +# 54bda396687149e38384c16f7e1602cd +#: ../../deployment.rst:70 +msgid "gunicorn_" +msgstr "" + +# be07f75ddcfa46b39c1c4a012091ed4a +#: ../../deployment.rst:70 +msgid "Pre-forked, partly written in C" +msgstr "" + +# ccab55aeedef4b9a8b27724b90e9147e +#: ../../deployment.rst:71 +msgid "eventlet" +msgstr "" + +# c75912557c7443e39686a53a0d50f310 +#: ../../deployment.rst:71 +msgid "eventlet_" +msgstr "" + +# dcd1301f85fc4f508edfb145936a8981 +#: ../../deployment.rst:71 +msgid "Asynchronous framework with WSGI support." +msgstr "支持WSGI的异步框架" + +# e74b58a9d7d54b1b94bbc7a1ffa40195 +#: ../../deployment.rst:72 +msgid "gevent" +msgstr "" + +# 2beea95f00d144f7921a885d8c27539d +#: ../../deployment.rst:72 +msgid "gevent_" +msgstr "" + +# a80c773e08fa4a8999e1b880e595cdfc +# a2c352eaf5234afea0a8dbbd39c8d95c +#: ../../deployment.rst:72 ../../deployment.rst:73 +msgid "Asynchronous (greenlets)" +msgstr "异步 (greenlets)" + +# e4239c25b7c243a8a65c3376b6324657 +#: ../../deployment.rst:73 +msgid "diesel" +msgstr "" + +# f1f4d6225de948728236ff63a6061b8b +#: ../../deployment.rst:73 +msgid "diesel_" +msgstr "" + +# 47bf711ccf4c4bc3a27294ffac85012b +#: ../../deployment.rst:74 +msgid "fapws3" +msgstr "" + +# 6c2749281ce54842b60dfdd8102f0760 +#: ../../deployment.rst:74 +msgid "fapws3_" +msgstr "" + +# bbd374f295eb4cd5837e348023187fa1 +#: ../../deployment.rst:74 +msgid "Asynchronous (network side only), written in C" +msgstr "异步 (network side only), written in C" + +# 38e55f3ef23b453ca4be59de80a86a58 +#: ../../deployment.rst:75 +msgid "tornado" +msgstr "" + +# b68f024f752143fea2d3551f06535724 +#: ../../deployment.rst:75 +msgid "tornado_" +msgstr "" + +# 127ad8b4a945499b8e03e3eac662e96e +#: ../../deployment.rst:75 +msgid "Asynchronous, powers some parts of Facebook" +msgstr "异步,支撑Facebook的部分应用" + +# c319318ff0e747249048d1492ff9d468 +#: ../../deployment.rst:76 +msgid "twisted" +msgstr "" + +# 474bfbaf4c4b471ca12ff95d43b72fc5 +#: ../../deployment.rst:76 +msgid "twisted_" +msgstr "" + +# fded1b2c80334bf7b8d62fef6a3cc106 +#: ../../deployment.rst:76 +msgid "Asynchronous, well tested but... twisted" +msgstr "异步, well tested but... twisted" + +# a51d20d8c07a4d6593dd44141d90df6a +#: ../../deployment.rst:77 +msgid "meinheld" +msgstr "" + +# a5d7d4a87937454c817bd6b4954c780b +#: ../../deployment.rst:77 +msgid "meinheld_" +msgstr "" + +# 1c4d989fa3aa4dbbbd435c88308f85c3 +#: ../../deployment.rst:77 +msgid "Asynchronous, partly written in C" +msgstr "异步,部分用C语言编写" + +# 9accb12067ce403e958cb544323edc95 +#: ../../deployment.rst:78 +msgid "bjoern" +msgstr "" + +# bef5c69cc89647d19caa34443bf05be2 +#: ../../deployment.rst:78 +msgid "bjoern_" +msgstr "" + +# b3658d3992e94bee930a3c902f320b7c +#: ../../deployment.rst:78 +msgid "Asynchronous, very fast and written in C" +msgstr "异步,用C语言编写,非常快" + +# 6d5ee7b287ce47199e1eb806df41da12 +#: ../../deployment.rst:79 +msgid "auto" +msgstr "" + +# 06a3e02e1e4449fba32bbc704e180011 +#: ../../deployment.rst:79 +msgid "Automatically selects an available server adapter" +msgstr "自动选择一个可用的服务器" + +# 584162cdf6474670a29f2fcadd147b13 +#: ../../deployment.rst:82 +msgid "The full list is available through :data:`server_names`." +msgstr "完整的列表在 :data:`server_names` 。" + +# cc5a1335e0c64f6399dd070a1f6ef5bd +#: ../../deployment.rst:84 +msgid "" +"If there is no adapter for your favorite server or if you need more control " +"over the server setup, you may want to start the server manually. Refer to " +"the server documentation on how to run WSGI applications. Here is an example " +"for paste_::" +msgstr "" +"如果没有适合你的服务器的适配器,或者你需要更多地控制服务器的安装,你也许需要" +"手动启动服务器。可参考你的服务器的文档,看看是如何运行一个WSGI应用。下面是一" +"个使用 paste_ 的例子。" + +# 8c6a91e237a24498b5c3223a616e1254 +#: ../../deployment.rst:93 +msgid "Apache mod_wsgi" +msgstr "" + +# a72769ad7e8a42bfa796f3b995a70e4b +#: ../../deployment.rst:95 +msgid "" +"Instead of running your own HTTP server from within Bottle, you can attach " +"Bottle applications to an `Apache server `_ using mod_wsgi_." +msgstr "" +"除了直接在Bottle里面运行HTTP服务器,你也可以将你的应用部署到一个Apache服务器" +"上,使用 mod_wsgi_ 来运行。" + +# 935849b733614fc58e5463e5c6ba69bf +#: ../../deployment.rst:97 +msgid "" +"All you need is an ``app.wsgi`` file that provides an ``application`` " +"object. This object is used by mod_wsgi to start your application and should " +"be a WSGI-compatible Python callable." +msgstr "" +"你需要的只是提供一个 ``application`` 对象的 ``app.wsgi`` 文件。mod_wsgi会使用" +"这个对象来启动你的应用,这个对象必须是兼容WSGI的 callable对象。" + +# 28f009fc7c0f42a39d30b818126dc74d +#: ../../deployment.rst:99 +msgid "File ``/var/www/yourapp/app.wsgi``::" +msgstr " ``/var/www/yourapp/app.wsgi`` 文件 " + +# a76a11ae64834882baa0ee1d0e2c723d +#: ../../deployment.rst:109 +msgid "The Apache configuration may look like this::" +msgstr "Apache的配置" + +# 7620c70255014ffe8840ca0709d76c7a +#: ../../deployment.rst:128 +msgid "Google AppEngine" +msgstr "" + +# d4ace9ef663f42bb9357a450ce95320b +#: ../../deployment.rst:132 +msgid "" +"The ``gae`` server adapter is used to run applications on Google App Engine. " +"It works similar to the ``cgi`` adapter in that it does not start a new HTTP " +"server, but prepares and optimizes your application for Google App Engine " +"and makes sure it conforms to their API::" +msgstr "" +"``gae`` 这个服务器适配器可在Google App Engine上运行你的应用。它的工作方式和 " +"``cgi`` 适配器类似,并没有启动一个HTTP服务器,只是针对做了一下准备和优化工" +"作。确保你的应用遵守Google App Engine的API。" + +# 7c4fa384b251470eb198fc0f0b1816fe +#: ../../deployment.rst:136 +msgid "" +"It is always a good idea to let GAE serve static files directly. Here is " +"example for a working ``app.yaml``::" +msgstr "" +"直接让GAE来提供静态文件服务总是一个好主意。类似的可工作的 ``app.yaml`` 文件如" +"下。" + +# 98b002b7a9b542a19a83b81fe317239d +#: ../../deployment.rst:152 +msgid "Load Balancer (Manual Setup)" +msgstr "负载均衡 (手动安装)" + +# 442149987ce2410b9d03f1a48248af9c +#: ../../deployment.rst:154 +msgid "" +"A single Python process can utilize only one CPU at a time, even if there " +"are more CPU cores available. The trick is to balance the load between " +"multiple independent Python processes to utilize all of your CPU cores." +msgstr "" +"单一的Python进程一次只能使用一个CPU内核,即使CPU是多核的。我们的方法就是在多" +"核CPU的机器上,使用多线程来实现负载均衡。" + +# 10fef6601a4048f3a0604fc672fb8fb6 +#: ../../deployment.rst:156 +msgid "" +"Instead of a single Bottle application server, you start one instance for " +"each CPU core available using different local port (localhost:8080, 8081, " +"8082, ...). You can choose any server adapter you want, even asynchronous " +"ones. Then a high performance load balancer acts as a reverse proxy and " +"forwards each new requests to a random port, spreading the load between all " +"available back-ends. This way you can use all of your CPU cores and even " +"spread out the load between different physical servers." +msgstr "" +"不只是启动一个应用服务器,你需要同时启动多个应用服务器,监听不同的端口" +"(localhost:8080, 8081, 8082, ...)。你可选择任何服务器,甚至那些异步服务器。然" +"后一个高性能的负载均衡器,像一个反向代理那样工作,将新的请求发送到一个随机端" +"口,在多个服务器之间分散压力。这样你就可以利用所有的CPU核心,甚至在多个机器上" +"实现负载均衡。" + +# d77aec94ad8a4986bb0ae2761ebcffa4 +#: ../../deployment.rst:158 +msgid "" +"One of the fastest load balancers available is Pound_ but most common web " +"servers have a proxy-module that can do the work just fine." +msgstr "" +" Pound_ 是最快的负载均衡器之一,但是只要有代理模块的Web服务器,也可以充当这一" +"角色。" + +# fcbb45ba206244d893de7e13415b56d7 +#: ../../deployment.rst:160 +msgid "Pound example::" +msgstr "Pound的例子::" + +# fab06de93eed468ebdfa731b5407a43e +#: ../../deployment.rst:178 +msgid "Apache example::" +msgstr "Apache的例子::" + +# 3cdac45e435942a09076cf399934985e +#: ../../deployment.rst:186 +msgid "Lighttpd example::" +msgstr "Lighttpd的例子::" + +# e4f5617ee96b4550b47db6fd041c819c +#: ../../deployment.rst:198 +msgid "Good old CGI" +msgstr "CGI这个老好人" + +# a62b689e2ad0402a9d9acba6458e4781 +#: ../../deployment.rst:200 +msgid "" +"A CGI server starts a new process for each request. This adds a lot of " +"overhead but is sometimes the only option, especially on cheap hosting " +"packages. The `cgi` server adapter does not actually start a CGI server, but " +"transforms your bottle application into a valid CGI application::" +msgstr "" +"CGI服务器会为每个请求启动一个进程。虽然这样代价高昂,但有时这是唯一的选择。 " +"`cgi` 这个适配器实际上并没有启动一个CGI服务器,只是将你的Bottle应用转换成了一" +"个有效的CGI应用。" diff -Nru python-bottle-0.11.6/docs/_locale/zh_CN/development.po python-bottle-0.12.0/docs/_locale/zh_CN/development.po --- python-bottle-0.11.6/docs/_locale/zh_CN/development.po 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/docs/_locale/zh_CN/development.po 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,615 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) 2009-2012, Marcel Hellkamp +# This file is distributed under the same license as the Bottle package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Bottle 0.12-dev\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-08-09 17:22\n" +"PO-Revision-Date: 2012-11-09 15:47+0800\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +# fceef0fe030847a3ad15a1e4c2170f73 +#: ../../development.rst:2 +msgid "Developer Notes" +msgstr "开发者笔记" + +# d3e13035992f45fd95b61393243684ee +#: ../../development.rst:4 +msgid "" +"This document is intended for developers and package maintainers interested " +"in the bottle development and release workflow. If you want to contribute, " +"you are just right!" +msgstr "" +"这份文档是为那些对Bottle的开发和发布流程感兴趣的开发者和软件包维护者准备的。" +"如果你想要做贡献,看它是对的!" + +# 30f3868bc0844a4a8b88af77404b74c7 +#: ../../development.rst:8 +msgid "Get involved" +msgstr "参与进来" + +# fe54a53c2a0e42bd8879bd637d2ab8f2 +#: ../../development.rst:10 +msgid "" +"There are several ways to join the community and stay up to date. Here are " +"some of them:" +msgstr "有多种加入社区的途径,保持消息的灵通。这里是一些方法:" + +# 86979d888abb4906be52cef53ce13943 +#: ../../development.rst:12 +msgid "" +"**Mailing list**: Join our mailing list by sending an email to `bottlepy" +"+subscribe@googlegroups.com `_ " +"(no google account required)." +msgstr "" +"**邮件列表**: 发送邮件到 `bottlepy+subscribe@googlegroups.com `_ 以加入我们的邮件列表(无需Google账户)" + +# 299c6cbd3e914ff69dbd911da9f360dd +#: ../../development.rst:13 +msgid "" +"**Twitter**: `Follow us on Twitter `_ or search for " +"the `#bottlepy `_ tag." +msgstr "" +"**Twitter**: 在 `Twitter `_ 上关注我们或搜索 " +"`bottlepy `_ 标签" + +# 537fe6f4bc1e4176a7f129ac427ec843 +#: ../../development.rst:14 +msgid "" +"**IRC**: Join `#bottlepy on irc.freenode.net `_ or use the `web chat interface `_." +msgstr "" +"**IRC**: 加入 `#irc.freenode.net上的bottlepy频道 `_ 或使用 `web聊天界面 `_ " + +# 9d8e88ce624b476293d01a9b38d5560c +#: ../../development.rst:15 +msgid "" +"**Google plus**: We sometimes `blog about Bottle, releases and technical " +"stuff `_ on our Google+ page." +msgstr "" +"**Google plus**: 有时我们会在Google+页面上发表一些 `与Bottle有关的博客 " +"`_ " + +# ca28316b3e2242e78f43944829c1a603 +#: ../../development.rst:19 +msgid "Get the Sources" +msgstr "获取源代码" + +# 94af39778f4a450c8e6b485247e41890 +#: ../../development.rst:21 +msgid "" +"The bottle `development repository `_ and " +"the `issue tracker `_ are both " +"hosted at `github `_. If you plan to " +"contribute, it is a good idea to create an account there and fork the main " +"repository. This way your changes and ideas are visible to other developers " +"and can be discussed openly. Even without an account, you can clone the " +"repository or just download the latest development version as a source " +"archive." +msgstr "" +"Bottle的 `开发仓库 `_ 和 `问题追踪 " +"`_ 都搭建在 `github `_ 上面。如果你打算做贡献,创建一个github帐号然后" +"fork一下吧。你做出的更改或建议都可被其他开发者看到,可以一起讨论。即使没有" +"github帐号,你也可以clone代码仓库,或下载最新开发版本的压缩包。" + +# d38ec2e3482c4399827e822ca8d24462 +#: ../../development.rst:23 +msgid "**git:** ``git clone git://github.com/defnull/bottle.git``" +msgstr "**git:** ``git clone git://github.com/defnull/bottle.git``" + +# d97bf4077a5245568712e25474970ae7 +#: ../../development.rst:24 +msgid "**git/https:** ``git clone https://github.com/defnull/bottle.git``" +msgstr "**git/https:** ``git clone https://github.com/defnull/bottle.git``" + +# 2f508c13f6744d71b7d1721d42c6fb50 +#: ../../development.rst:25 +msgid "" +"**Download:** Development branch as `tar archive `_ or `zip file `_." +msgstr "" +"**Download:** Development branch as `tar archive `_ or `zip file `_." + +# 7acb921ae73c4b8d903e7e7812eab5c2 +#: ../../development.rst:29 +msgid "Releases and Updates" +msgstr "发布和更新" + +# 60a5c2362c9446f1bd2139b978dc1089 +#: ../../development.rst:31 +#, fuzzy +msgid "" +"Bottle is released at irregular intervals and distributed through `PyPI " +"`_. Release candidates and bugfix-" +"revisions of outdated releases are only available from the git repository " +"mentioned above. Some Linux distributions may offer packages for outdated " +"releases, though." +msgstr "" +"Bottle不定时发布正式版本,通过 `PyPI `_ " +"来分发。RC版或bugfix版本只会在github上面发布。一些Linux发行版也许会提供一些过" +"时的版本。" + +# d3be4ddb8f6c493f89ac06de4e856409 +#: ../../development.rst:33 +msgid "" +"The Bottle version number splits into three parts (**major.minor." +"revision**). These are *not* used to promote new features but to indicate " +"important bug-fixes and/or API changes. Critical bugs are fixed in at least " +"the two latest minor releases and announced in all available channels " +"(mailinglist, twitter, github). Non-critical bugs or features are not " +"guaranteed to be backported. This may change in the future, through." +msgstr "" +"Bottle的版本号分隔为三个部分(**major.minor.revision**)。版本号 *不会* 用于引" +"入新特征,只是为了指出重要的bug-fix或API的改动。关键的bug会在近两个新的版本中" +"修复,然后通过所有渠道发布(邮件列表, twitter, github)。不重要的bug修复或特征" +"不保证添加到旧版本中。这个情况在未来也许会改变。" + +# 9ecb2ba91a264d909f35e766e4526450 +#: ../../development.rst:36 +msgid "Major Release (x.0)" +msgstr "" + +# 03d00f16fb6b4214899a04cba5c35a6d +#: ../../development.rst:36 +msgid "" +"The major release number is increased on important milestones or updates " +"that completely break backward compatibility. You probably have to work over " +"your entire application to use a new release. These releases are very rare, " +"through." +msgstr "" +"在重要的里程碑达成或新的更新和旧版本彻底不兼容时,会增加major版本号。为了使用" +"新版本,你也许需要修改整个应用,但major版本号极少会改变。" + +# c9620f52ec754a4aab875fdb2137c0cc +#: ../../development.rst:39 +msgid "Minor Release (x.y)" +msgstr "" + +# 7a1a1638c40e43e0b01af3627996a080 +#: ../../development.rst:39 +msgid "" +"The minor release number is increased on updates that change the API or " +"behaviour in some way. You might get some depreciation warnings any may have " +"to tweak some configuration settings to restore the old behaviour, but in " +"most cases these changes are designed to be backward compatible for at least " +"one minor release. You should update to stay up do date, but don't have to. " +"An exception is 0.8, which *will* break backward compatibility hard. (This " +"is why 0.7 was skipped). Sorry about that." +msgstr "" +"在更改了API之后,或增加minor版本号。你可能会收到一些API已过时的警告,调整设置" +"以继续使用旧的特征,但在大多数情况下,这些更新都会对旧版本兼容。你应当保持更" +"新,但这不是必须的。0.8版本是一个特例,它 *不兼容* 旧版本(所以我们跳过了0.7版" +"本直接发布0.8版本),不好意思。" + +# c1cd34f3caf846dab76881dac14c53e2 +#: ../../development.rst:42 +msgid "Revision (x.y.z)" +msgstr "" + +# ba5728b974e14b75911cbbea41cbe6d7 +#: ../../development.rst:42 +msgid "" +"The revision number is increased on bug-fixes and other patches that do not " +"change the API or behaviour. You can safely update without editing your " +"application code. In fact, you really should as soon as possible, because " +"important security fixes are released this way." +msgstr "" +"在修复了一些bug,和改动不会修改API的时候,会增加revision版本号。你可以放心更" +"新,而不用修改你应用的代码。事实上,你确实应该更新这类版本,因为它常常修复一" +"些安全问题。" + +# 7629abe7b2f144bc9f1de10aad83d468 +#: ../../development.rst:46 +msgid "Pre-Release Versions" +msgstr "" + +# e7d78ebc45b147989ff9c8cb1ae39a91 +#: ../../development.rst:45 +msgid "" +"Release candidates are marked by an ``rc`` in their revision number. These " +"are API stable most of the time and open for testing, but not officially " +"released yet. You should not use these for production." +msgstr "" +"RC版本会在版本号中添加 ``rc`` 字样。API已基本稳定,已经开放测试,但还没正式发" +"布。你不应该在生产环境中使用rc版本。" + +# 37a6506ab67e48568ddafdeed98b426f +#: ../../development.rst:49 +msgid "Repository Structure" +msgstr "代码仓库结构" + +# c0a3036c46fb46bb82bd09a17f350e78 +#: ../../development.rst:51 +msgid "The source repository is structured as follows:" +msgstr "代码仓库的结构如下:" + +# 7dcc7cc36e324c829aebbafe37c3796f +#: ../../development.rst:54 +msgid "``master`` branch" +msgstr "" + +# d116d802a64e43788fceb4041ce2a7a2 +#: ../../development.rst:54 +msgid "" +"This is the integration, testing and development branch. All changes that " +"are planned to be part of the next release are merged and tested here." +msgstr "" +"该分支用于集成,测试和开发。所有计划添加到下一版本的改动,会在这里合并和测" +"试。" + +# 6abfeb26070147c09c19c10a7090f44a +#: ../../development.rst:57 +msgid "``release-x.y`` branches" +msgstr "" + +# bc12377068154a19a6f9a3bffda6d913 +#: ../../development.rst:57 +msgid "" +"As soon as the master branch is (almost) ready for a new release, it is " +"branched into a new release branch. This \"release candidate\" is feature-" +"frozen but may receive bug-fixes and last-minute changes until it is " +"considered production ready and officially released. From that point on it " +"is called a \"support branch\" and still receives bug-fixes, but only " +"important ones. The revision number is increased on each push to these " +"branches, so you can keep up with important changes." +msgstr "" +"只要master分支已经可以用来发布一个新的版本,它会被安排到一个新的发行分支里" +"面。在RC阶段,不再添加或删除特征,只接受bug-fix和小改动,直到认为它可以用于生" +"产环境和正式发布。基于这点考虑,我们称之为“支持分支(support branch)”,依然接" +"受bug-fix,但仅限关键的bug-fix。每次更改后,版本号都会更新,这样你就能及时获" +"取重要的改动了。" + +# 30902a4eb31141c4b9e2e99195dc69df +#: ../../development.rst:60 +msgid "``bugfix_name-x.y`` branches" +msgstr "" + +# 6724eda55b8a4e02a39d970badc69f0b +#: ../../development.rst:60 +msgid "" +"These branches are only temporary and used to develop and share non-trivial " +"bug-fixes for existing releases. They are merged into the corresponding " +"release branch and deleted soon after that." +msgstr "" +"这些分支是临时性的,用于修复现有发布版本的bug。在合并到其他分支后,它们就会被" +"删除。" + +# 1c189971e0b846d8935a5c9f4fcf6374 +#: ../../development.rst:64 +msgid "Feature branches" +msgstr "" + +# 23e018316a6343b88a255c80f908693f +#: ../../development.rst:63 +msgid "" +"All other branches are feature branches. These are based on the master " +"branch and only live as long as they are still active and not merged back " +"into ``master``." +msgstr "" +"所有这类分支都是用于新增特征的。基于master分支,在开发、合并完毕后,就会被删" +"除。" + +# f508aeb780ef487f9b8c0c8b101e938d +#: ../../development.rst:67 +msgid "What does this mean for a developer?" +msgstr "对于开发者,这意味着什么?" + +# 4479eb5ed8e3489c9ccece20b97f1550 +#: ../../development.rst:68 +msgid "" +"If you want to add a feature, create a new branch from ``master``. If you " +"want to fix a bug, branch ``release-x.y`` for each affected release. Please " +"use a separate branch for each feature or bug to make integration as easy as " +"possible. Thats all. There are git workflow examples at the bottom of this " +"page." +msgstr "" +"如果你想添加一个特征,可以从 ``master`` 分支创建一个分支。如果你想修复一个" +"bug,可从 ``release-x.y`` 这类分支创建一个分支。无论是添加特征还是修复bug,都" +"建议在一个独立的分支上进行,这样合并工作就简单了。就这些了!在页面底部会有git" +"工作流程的例子。" + +# fa0d3d6e1f4949249b3e2425e21e20a8 +#: ../../development.rst:70 +msgid "" +"Oh, and never ever change the release number. We'll do that on integration. " +"You never know in which order we pull pending requests anyway :)" +msgstr "" +"Oh,请不要修改版本号。我们会在集成的时候进行修改。因为你不知道我们什么时候会" +"将你的request pull下来:)" + +# 25faeb743adc4255b58282d1237d72ad +#: ../../development.rst:74 +msgid "What does this mean for a maintainer ?" +msgstr "对于软件包维护者,这意味着什么?" + +# 4ae0e7b8a5b640e093e107b49488dfa8 +#: ../../development.rst:75 +msgid "" +"Watch the tags (and the mailing list) for bug-fixes and new releases. If you " +"want to fetch a specific release from the git repository, trust the tags, " +"not the branches. A branch may contain changes that are not released yet, " +"but a tag marks the exact commit which changed the version number." +msgstr "" +"关注那些bugfix和新版本的tag,还有邮件列表。如果你想从代码仓库中获取特定的版" +"本,请使用tag,而不是分支。分支中也许会包含一些未发布的改动,但tag会标记是那" +"个commit更改了版本号。" + +# fa118217a6214b51a9379ee1ffad7eee +#: ../../development.rst:79 +msgid "Submitting Patches" +msgstr "提交补丁" + +# 180644a82d724b588590db66a5cbd7d1 +#: ../../development.rst:81 +msgid "" +"The best way to get your changes integrated into the main development branch " +"is to fork the main repository at github, create a new feature-branch, apply " +"your changes and send a pull-request. Further down this page is a small " +"collection of git workflow examples that may guide you. Submitting git-" +"compatible patches to the mailing list is fine too. In any case, please " +"follow some basic rules:" +msgstr "" +"让你的补丁被集成进来的最好方法,是在github上面fork整个项目,创建一个新的分" +"支,修改代码,然后发送一个pull-request。页面下方是git工作流程的例子,也许会有" +"帮助。提交git兼容的补丁文件到邮件列表也是可以的。无论使用什么方法,请遵守以下" +"的基本规则:" + +# 1fdf564478e84e86acf6b5c8359f93ca +#: ../../development.rst:83 +msgid "" +"**Documentation:** Tell us what your patch does. Comment your code. If you " +"introduced a new feature, add to the documentation so others can learn about " +"it." +msgstr "" +"**文档:** 告诉我们你的补丁做了什么。注释你的代码。如果你添加了新的特征,请添" +"加相应的使用方法。" + +# a71e9f2cfb09461d9220e634d31290b9 +#: ../../development.rst:84 +msgid "" +"**Test:** Write tests to prove that your code works as expected and does not " +"break anything. If you fixed a bug, write at least one test-case that " +"triggers the bug. Make sure that all tests pass before you submit a patch." +msgstr "" +"**测试:** 编写测试以证明你的补丁如期工作,且没有破坏任何东西。如果你修复了一" +"个bug,至少写一个测试用例来触发这个bug。在提交补丁之前,请确保所有测试已通" +"过。" + +# 937fed88ebeb41fcb46f611cf8fec3fe +#: ../../development.rst:85 +msgid "" +"**One patch at a time:** Only fix one bug or add one feature at a time. " +"Design your patches so that they can be applyed as a whole. Keep your " +"patches clean, small and focused." +msgstr "" +"**一次只提交一个补丁:** 一次只修改一个bug,一次只添加一个新特征。保持补丁的" +"干净。" + +# 95f236a80eab41a58eca653457e4bc8a +#: ../../development.rst:86 +msgid "" +"**Sync with upstream:** If the ``upstream/master`` branch changed while you " +"were working on your patch, rebase or pull to make sure that your patch " +"still applies without conflicts." +msgstr "" +"**与上流同步:** 如果在你编写补丁的时候, ``upstream/master`` 分支被修改了," +"那么先rebase或将新的修改pull下来,确保你的补丁在合并的时候不会造成冲突。" + +# 5f35856dea7946d1bdc41a8e42e2b680 +#: ../../development.rst:90 +msgid "Building the Documentation" +msgstr "生成文档" + +# 67268edaae4e4477ba178f851bc57f5e +#: ../../development.rst:92 +msgid "" +"You need a recent version of Sphinx to build the documentation. The " +"recommended way is to install :command:`virtualenv` using your distribution " +"package repository and install sphinx manually to get an up-to-date version." +msgstr "" +"你需要一个Sphinx的新版本来生产整份文档。建议将Sphinx安装到一个 :command:" +"`virtualenv` 环境。" + +# 7e3c4956169141a891c8b5964e6d2d16 +#: ../../development.rst:123 +msgid "GIT Workflow Examples" +msgstr "GIT工作流程" + +# 57ff734a0eec4180a46ad56305721b00 +#: ../../development.rst:125 +msgid "" +"The following examples assume that you have an (free) `github account " +"`_. This is not mandatory, but makes things a lot easier." +msgstr "" +"接下来的例子都假设你已经有一个 `git的免费帐号 `_ 。虽然不" +"是必须的,但可简单化很多东西。" + +# db5fbce9655c4762868c4d9647f363f9 +#: ../../development.rst:127 +msgid "" +"First of all you need to create a fork (a personal clone) of the official " +"repository. To do this, you simply click the \"fork\" button on the `bottle " +"project page `_. When the fork is done, " +"you will be presented with a short introduction to your new repository." +msgstr "" +"首先,你需要从官方代码仓库创建一个fork。只需在 `bottle项目页面 `_ 点击一下\"fork\"按钮就行了。创建玩fork之后,会得" +"到一个关于这个新仓库的简介。" + +# 2f59f7bd45db4611a0137da8ca0fa908 +#: ../../development.rst:129 +msgid "" +"The fork you just created is hosted at github and read-able by everyone, but " +"write-able only by you. Now you need to clone the fork locally to actually " +"make changes to it. Make sure you use the private (read-write) URL and *not* " +"the public (read-only) one::" +msgstr "" +"你刚刚创建的fork托管在github上面,对所有人都是可见的,但只有你有修改的权限。" +"现在你需要将其从线上clone下面,做出实际的修改。确保你使用的是(可写-可读)的私" +"有URL,而不是(只读)的公开URL。" + +# 223ea87b5a554fd89f7ede06778ab871 +#: ../../development.rst:133 +msgid "" +"Once the clone is complete your repository will have a remote named \"origin" +"\" that points to your fork on github. Don’t let the name confuse you, this " +"does not point to the original bottle repository, but to your own fork. To " +"keep track of the official repository, add another remote named \"upstream" +"\"::" +msgstr "" +"在你将代码仓库clone下来后,就有了一个\"origin\"分支,指向你在github上的fork。" +"不要让名字迷惑了你,它并不指向bottle的官方代码仓库,只是指向你自己的fork。为" +"了追踪官方的代码仓库,可添加一个新的\"upstream\"远程分支。" + +# 743410f393fc4f03bdf60ada16ddb7f3 +#: ../../development.rst:139 +msgid "" +"Note that \"upstream\" is a public clone URL, which is read-only. You cannot " +"push changes directly to it. Instead, we will pull from your public " +"repository. This is described later." +msgstr "" +"注意,\"upstream\"分支使用的是公开的URL,是只读的。你不能直接往该分支push东" +"西,而是由我们来你的公开代码仓库pull,后面会讲到。" + +# dfbfc3eaa1e046abb71629f0bf42dda4 +#: ../../development.rst:142 +msgid "Submit a Feature" +msgstr "提交一个特征" + +# feb4b8363a88499296dea581af2e22f4 +#: ../../development.rst:143 +msgid "" +"New features are developed in separate feature-branches to make integration " +"easy. Because they are going to be integrated into the ``master`` branch, " +"they must be based on ``upstream/master``. To create a new feature-branch, " +"type the following::" +msgstr "" +"在独立的特征分支内开发新的特征,会令集成工作更简单。因为它们会被合并到 " +"``master`` 分支,所有它们必须是基于 ``upstream/master`` 的分支。下列命令创建" +"一个特征分支。" + +# 48f697f0a0414c619a5b398b7550be2f +#: ../../development.rst:147 +msgid "" +"Now implement your feature, write tests, update the documentation, make sure " +"that all tests pass and commit your changes::" +msgstr "" +"现在可开始写代码,写测试,更新文档。在提交更改之前,记得确保所有测试已经通" +"过。" + +# c078d583a76e43ad9810a1decc689310 +#: ../../development.rst:151 +msgid "" +"If the ``upstream/master`` branch changed in the meantime, there may be " +"conflicts with your changes. To solve these, 'rebase' your feature-branch " +"onto the top of the updated ``upstream/master`` branch::" +msgstr "" +"与此同时,如果 ``upstream/master`` 这个分支有改动,那么你的提交就有可能造成冲" +"突,可通过rebase操作来解决。" + +# feaa374dd9e046f2ad084430ad9e2486 +#: ../../development.rst:156 +msgid "" +"This is equivalent to undoing all your changes, updating your branch to the " +"latest version and reapplying all your patches again. If you released your " +"branch already (see next step), this is not an option because it rewrites " +"your history. You can do a normal pull instead. Resolve any conflicts, run " +"the tests again and commit." +msgstr "" +"这相当于先撤销你的所有改动,更新你的分支到最新版本,再重做你的所有改动。如果" +"你已经发布了你的分支(下一步会提及),这就不是一个好主意了,因为会覆写你的提交" +"历史。这种情况下,你应该先将最新版本pull下来,手动解决所有冲突,运行测试,再" +"提交。" + +# e33bb725165744c8a9ad4b3a9fa1da05 +#: ../../development.rst:158 +msgid "" +"Now you are almost ready to send a pull request. But first you need to make " +"your feature-branch public by pushing it to your github fork::" +msgstr "" +"现在,你已经做好准备发一个pull-request了。但首先你应该公开你的特征分支,很简" +"单,将其push到你github的fork上面就行了。" + +# a0c0ddf4322b4aa69536289f0db98255 +#: ../../development.rst:162 +msgid "" +"After you’ve pushed your commit(s) you need to inform us about the new " +"feature. One way is to send a pull-request using github. Another way would " +"be to start a thread in the mailing-list, which is recommended. It allows " +"other developers to see and discuss your patches and you get some feedback " +"for free :)" +msgstr "" +"在你push完你所有的commit之后,你需要告知我们这个新特征。一种办法是通过github" +"发一个pull-request。另一种办法是把这个消息发到邮件列表,这也是我们推荐的方" +"式,这样其他开发者就能看到和讨论你的补丁,你也能免费得到一些反馈 :)" + +# 0637523cf497469eb4dfb0252b23349b +#: ../../development.rst:164 +msgid "" +"If we accept your patch, we will integrate it into the official development " +"branch and make it part of the next release." +msgstr "" +"如果我们接受了你的补丁,我们会将其集成到官方的开发分支中,它将成为下个发布版" +"本的一部分。" + +# b02f5f82ac5344c491143043c8403f99 +#: ../../development.rst:167 +msgid "Fix a Bug" +msgstr "修复Bug" + +# 0d1c4d649ea54b32b00cc65ae38fc994 +#: ../../development.rst:168 +msgid "" +"The workflow for bug-fixes is very similar to the one for features, but " +"there are some differences:" +msgstr "修复Bug和添加一个特征差不多,下面是一些不同点:" + +# 563fa0f629bc4f78ab6381cce3440d06 +#: ../../development.rst:170 +msgid "" +"Branch off of the affected release branches instead of just the development " +"branch." +msgstr "" +"修复所有受影响的分支,而不仅仅是开发分支(Branch off of the affected release " +"branches instead of just the development branch)。" + +# 73c5c25f2ec74ce5b2c08942f35dfc27 +#: ../../development.rst:171 +msgid "Write at least one test-case that triggers the bug." +msgstr "至少编写一个触发该Bug的测试用例。" + +# 8bc4839c9f2e477186907c097eeb3c18 +#: ../../development.rst:172 +msgid "" +"Do this for each affected branch including ``upstream/master`` if it is " +"affected. ``git cherry-pick`` may help you reducing repetitive work." +msgstr "" +"修复所有受影响的分支,包括 ``upstream/master`` ,如果它也受影响。 ``git " +"cherry-pick`` 可帮你完成一些重复工作。" + +# ca794ae9ce34456d984e43dea10fef14 +#: ../../development.rst:173 +msgid "" +"Name your branch after the release it is based on to avoid confusion. " +"Examples: ``my_bugfix-x.y`` or ``my_bugfix-dev``." +msgstr "" +"字后面要加上其修复的版本号,以防冲突。例子: ``my_bugfix-x.y`` 或 ``my_bugfix-" +"dev`` 。" diff -Nru python-bottle-0.11.6/docs/_locale/zh_CN/faq.po python-bottle-0.12.0/docs/_locale/zh_CN/faq.po --- python-bottle-0.11.6/docs/_locale/zh_CN/faq.po 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/docs/_locale/zh_CN/faq.po 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,119 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) 2009-2012, Marcel Hellkamp +# This file is distributed under the same license as the Bottle package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Bottle 0.12-dev\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-11-09 18:23\n" +"PO-Revision-Date: 2012-11-09 16:47+0800\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +# 7422025ba87c41df91aa766602d3562b +#: ../../faq.rst:10 +msgid "Frequently Asked Questions" +msgstr "常见问题" + +# 7b350c11f4bc4ff6a80dbab624890041 +#: ../../faq.rst:13 +msgid "About Bottle" +msgstr "关于Bottle" + +# b3bd6fdbb6a24d22aaf160f45bdb69dd +#: ../../faq.rst:16 +msgid "Is bottle suitable for complex applications?" +msgstr "Bottle适合用于复杂的应用吗?" + +# 94af81a76cfd4133b6d2ba7794605511 +#: ../../faq.rst:18 +msgid "" +"Bottle is a *micro* framework designed for prototyping and building small " +"web applications and services. It stays out of your way and allows you to " +"get things done fast, but misses some advanced features and ready-to-use " +"solutions found in other frameworks (MVC, ORM, form validation, scaffolding, " +"XML-RPC). Although it *is* possible to add these features and build complex " +"applications with Bottle, you should consider using a full-stack Web " +"framework like pylons_ or paste_ instead." +msgstr "" +"Bottle是一个 *迷你* 框架,被设计来提供原型开发和创建小的Web应用和服务。它能快" +"速上手,并帮助你快速完成任务,但缺少一些高级功能和一些其他框架已提供的已知问" +"题解决方法(例如:MVC, ORM,表单验证,手脚架,XML-RPC)。尽管 *可以* 添加这些功" +"能,然后通过Bottle来开发复杂的应用,但我们还是建议你使用一些功能完备的Web框" +"架,例如 pylons_ 或 paste_ 。" + +# 7cd9fb83437548a7a76a53a369052dd3 +#: ../../faq.rst:22 +msgid "Common Problems and Pitfalls" +msgstr "常见的,意料之外的问题" + +# 8b95ed13f0554348813619adb56c61e6 +#: ../../faq.rst:29 +msgid "\"Template Not Found\" in mod_wsgi/mod_python" +msgstr "在mod_wsgi/mod_python中的 \"Template Not Found\" 错误" + +# 966c583dc9144d6596cebc06f9240f1c +#: ../../faq.rst:31 +msgid "" +"Bottle searches in ``./`` and ``./views/`` for templates. In a mod_python_ " +"or mod_wsgi_ environment, the working directory (``./``) depends on your " +"Apache settings. You should add an absolute path to the template search " +"path::" +msgstr "" +"Bottle会在 ``./`` 和 ``./views/`` 目录中搜索模板。在一个 mod_python_ 或 " +"mod_wsgi_ 环境,当前工作目录( ``./`` )是由Apache的设置决定的。你应该在模板的" +"搜索路径中添加一个绝对路径。" + +# 915f4819cc2b414da8453921d84d0eda +#: ../../faq.rst:35 +msgid "so bottle searches the right paths." +msgstr "这样,Bottle就能在正确的目录下搜索模板了" + +# 0c24d7df42734c08a1a401c59692d47e +#: ../../faq.rst:38 +msgid "Dynamic Routes and Slashes" +msgstr "动态route和反斜杠" + +# ac001cb8786f475987c1cb542f5537cb +#: ../../faq.rst:40 +msgid "" +"In :ref:`dynamic route syntax `, a placeholder " +"token (``:name``) matches everything up to the next slash. This equals to ``" +"[^/]+`` in regular expression syntax. To accept slashes too, you have to add " +"a custom regular pattern to the placeholder. An example: ``/images/:" +"filepath#.*#`` would match ``/images/icons/error.png`` but ``/images/:" +"filename`` won't." +msgstr "" +"在 :ref:`dynamic route syntax ` 中, ``:name`` 匹配" +"任何字符,直到出现一个反斜杠。工作方式相当与 ``[^/]+`` 这样一个正则表达式。为" +"了将反斜杠包涵进来,你必须在 ``:name`` 中添加一个自定义的正则表达式。例如: " +"``/images/:filepath#.*#`` 会匹配 ``/images/icons/error.png`` ,但不匹配 ``/" +"images/:filename`` 。" + +# a88283ebbbe04b81b894882c8e4b6c02 +#: ../../faq.rst:43 +msgid "Problems with reverse proxies" +msgstr "反向代理的问题" + +# 7aa118afe3be43ccb06933b955801d4b +#: ../../faq.rst:45 +msgid "" +"Redirects and url-building only works if bottle knows the public address and " +"location of your application. If you run bottle locally behind a reverse " +"proxy or load balancer, some information might get lost along the way. For " +"example, the ``wsgi.url_scheme`` value or the ``Host`` header might reflect " +"the local request by your proxy, not the real request by the client. Here is " +"a small WSGI middleware snippet that helps to fix these values::" +msgstr "" +"只用Bottle知道公共地址和应用位置的情况下,重定向和url-building才会起作用。(译" +"者注:保留原文)Redirects and url-building only works if bottle knows the " +"public address and location of your application.如果Bottle应用运行在反向代理" +"或负载均衡后面,一些信息也许会丢失。例如, ``wsgi.url_scheme`` 的值或 " +"``Host`` 头或许只能获取到代理的请求信息,而不是真实的用户请求。下面是一个简单" +"的中间件代码片段,处理上面的问题,获取正确的值。" diff -Nru python-bottle-0.11.6/docs/_locale/zh_CN/index.po python-bottle-0.12.0/docs/_locale/zh_CN/index.po --- python-bottle-0.11.6/docs/_locale/zh_CN/index.po 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/docs/_locale/zh_CN/index.po 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,171 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) 2009-2012, Marcel Hellkamp +# This file is distributed under the same license as the Bottle package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Bottle 0.12-dev\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-08-09 18:12\n" +"PO-Revision-Date: 2013-08-09 17:25+0800\n" +"Last-Translator: \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.5.7\n" + +# 982a9ff09f57469ea201f9681c77d2c3 +#: ../../index.rst:20 +msgid "Bottle: Python Web Framework" +msgstr "Bottle: Python Web框架" + +# 4c5d800e46c2412a9f777bdcf45828bc +#: ../../index.rst:22 +msgid "" +"Bottle is a fast, simple and lightweight WSGI_ micro web-framework for " +"Python_. It is distributed as a single file module and has no dependencies " +"other than the `Python Standard Library `_." +msgstr "" +"Bottle是一个快速,简单,轻量级的 Python_ WSGI_ Web框架。单一文件,只依赖 " +"`Python标准库 `_ 。" + +# 87fb9bd30b3b41448aa966e6f47b3495 +#: ../../index.rst:25 +msgid "" +"**Routing:** Requests to function-call mapping with support for clean and " +"dynamic URLs." +msgstr "" +"**URL映射(Routing):** 将URL请求映射到Python函数,支持动态URL,且URL更简洁。" + +# 3d7f52b05cb741c99ec48b8ff29f9b73 +#: ../../index.rst:26 +msgid "" +"**Templates:** Fast and pythonic :ref:`built-in template engine ` and support for mako_, jinja2_ and cheetah_ templates." +msgstr "" +"**模板(Templates):** 快速且pythonic的 :ref:`内置模板引擎 ` ,同时支持 mako_ , jinja2_ 和 cheetah_ 等模板。" + +# 1ef9c634d3b148dbb49d21228a9cddaf +#: ../../index.rst:27 +msgid "" +"**Utilities:** Convenient access to form data, file uploads, cookies, " +"headers and other HTTP-related metadata." +msgstr "" +"**基础功能(Utilities):** 方便地访问表单数据,上传文件,使用cookie,查看HTTP元" +"数据。" + +# a9afd6291c9745d48c909e1cfa96b62c +#: ../../index.rst:28 +msgid "" +"**Server:** Built-in HTTP development server and support for paste_, " +"fapws3_, bjoern_, `Google App Engine `_, cherrypy_ or any other WSGI_ capable HTTP server." +msgstr "" +"**开发服务器(Server):** 内置了开发服务器,且支持 paste_, fapws3_ , bjoern_, " +"`Google App Engine `_, " +"cherrypy_ 等符合 WSGI_ 标准的HTTP服务器。" + +# 17ee65d0e5434da2971dad90262f8998 +#: ../../index.rst:31 +msgid "Example: \"Hello World\" in a bottle" +msgstr "示例: \"Hello World\"" + +# 576fbd7f466749fea3553b0c70cded4a +#: ../../index.rst:42 +msgid "" +"Run this script or paste it into a Python console, then point your browser " +"to ``_. That's it." +msgstr "" +"将其保存为py文件并执行,用浏览器访问 ``_ " +"即可看到效果。就这么简单!" + +# 2e1347a5473444f7b5c95be5ece49b80 +#: ../../index.rst:45 +msgid "Download and Install" +msgstr "下载和安装" + +# da4edbc4bf894ed09f69ff20784f656c +#: ../../index.rst:50 +msgid "" +"Install the latest stable release via PyPI_ (``easy_install -U bottle``) or " +"download `bottle.py`__ (unstable) into your project directory. There are no " +"hard [1]_ dependencies other than the Python standard library. Bottle runs " +"with **Python 2.5+ and 3.x**." +msgstr "" +"通过 PyPI_ (``easy_install -U bottle``)安装最新的稳定版,或下载 `bottle." +"py`__ (开发版)到你的项目文件夹。 Bottle除了Python标准库无任何依赖 [1]_ ,同时" +"支持 **Python 2.5+ and 3.x** 。" + +# e4e0c283078a4bc7b60281c8c96116f3 +#: ../../index.rst:53 +msgid "User's Guide" +msgstr "用户指南" + +# 0fb51b23ecd3442599753dde04753b38 +#: ../../index.rst:54 +msgid "" +"Start here if you want to learn how to use the bottle framework for web " +"development. If you have any questions not answered here, feel free to ask " +"the `mailing list `_." +msgstr "" +"如果你有将Bottle用于Web开发的打算,请继续看下去。如果这份文档没有解决你遇到的" +"问题,尽管在 `邮件列表 `_ 中吼出来吧(译者" +"注:用英文哦)。" + +# cfb536e857dc41b0bf43f0e185d47e98 +#: ../../index.rst:68 +msgid "Knowledge Base" +msgstr "知识库" + +# baeb4c393ec246b690500089c6647096 +#: ../../index.rst:69 +msgid "A collection of articles, guides and HOWTOs." +msgstr "收集文章,使用指南和HOWTO" + +# 7c0f6a746c0f4a5da9fb8da7dec405da +#: ../../index.rst:81 +msgid "Development and Contribution" +msgstr "开发和贡献" + +# 8c7445707fd945a4a8e0fdf6e5055edd +#: ../../index.rst:83 +msgid "" +"These chapters are intended for developers interested in the bottle " +"development and release workflow." +msgstr "这些章节是为那些对Bottle的开发和发布流程感兴趣的开发者准备的。" + +# 5dc3afd489cb4053a42ab582b40e2985 +#: ../../index.rst:99 +msgid "License" +msgstr "许可证" + +# 04840f1a47654598a640bc3fd44bdb10 +#: ../../index.rst:101 +msgid "Code and documentation are available according to the MIT License:" +msgstr "代码和文件皆使用MIT许可证:" + +# 4eaa7176213e47189636c52b21aa9d0d +#: ../../index.rst:106 +msgid "" +"The Bottle logo however is *NOT* covered by that license. It is allowed to " +"use the logo as a link to the bottle homepage or in direct context with the " +"unmodified library. In all other cases please ask first." +msgstr "" +"然而,许可证 *不包含* Bottle的logo。logo用作指向Bottle主页的连接,或未修改过" +"的类库。如要用于其它用途,请先请求许可。" + +# 9ede3f752bd74e2280f3b15cdbbe0796 +#: ../../index.rst:111 +msgid "Footnotes" +msgstr "脚注" + +# a8762741595242a89d72fa712bcf95dc +#: ../../index.rst:112 +msgid "" +"Usage of the template or server adapter classes of course requires the " +"corresponding template or server modules." +msgstr "如果使用了第三方的模板或HTTP服务器,则需要安装相应的第三方模块。" diff -Nru python-bottle-0.11.6/docs/_locale/zh_CN/plugindev.po python-bottle-0.12.0/docs/_locale/zh_CN/plugindev.po --- python-bottle-0.11.6/docs/_locale/zh_CN/plugindev.po 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/docs/_locale/zh_CN/plugindev.po 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,543 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) 2009-2012, Marcel Hellkamp +# This file is distributed under the same license as the Bottle package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Bottle 0.12-dev\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-11-09 18:23\n" +"PO-Revision-Date: 2012-11-09 16:53+0800\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +# bb43bbad2c9f40409a2e100421b6f131 +#: ../../plugindev.rst:6 +msgid "Plugin Development Guide" +msgstr "插件开发指南" + +# 3bcf439c643c4b428db9ea0e85ab54b1 +#: ../../plugindev.rst:8 +msgid "" +"This guide explains the plugin API and how to write custom plugins. I " +"suggest reading :ref:`plugins` first if you have not done that already. You " +"might also want to have a look at the :doc:`/plugins/index` for some " +"practical examples." +msgstr "" +"这份指南介绍了插件的API,以及如何编写自己的插件。我建议先阅读 :ref:`plugins` " +"这一部分,再看这份指南。 :doc:`/plugins/index` 这里也有一些实际的例子。" + +# 9c93905a1e12432a98c28594f77466d5 +#: ../../plugindev.rst:12 +msgid "" +"This is a draft. If you see any errors or find that a specific part is not " +"explained clear enough, please tell the `mailing-list `_ or file a `bug report `_." +msgstr "" +"这是一份初稿。如果你发现了任何错误,或某些部分解释的不够清楚,请通过 `邮件列" +"表 `_ 或 `bug report `_ 告知。" + +# 070f3ff0fa644258b9d14ac422645f9d +#: ../../plugindev.rst:16 +msgid "How Plugins Work: The Basics" +msgstr "插件工作方式:基础知识" + +# b7e6c02814fb4f45bd66a4a8be53ff56 +#: ../../plugindev.rst:18 +msgid "" +"The plugin API builds on the concept of `decorators `_. To put it briefly, a plugin is a decorator " +"applied to every single route callback of an application." +msgstr "" +"插件的API是通过Python的 `修饰器 `_ 来实现的。简单来说,一个插件就是应用在route回调函数上的修饰器。" + +# 2ce1e4f3e1c04fdcb045acfd0f9a244f +#: ../../plugindev.rst:20 +msgid "" +"Of course, this is just a simplification. Plugins can do a lot more than " +"just decorating route callbacks, but it is a good starting point. Lets have " +"a look at some code::" +msgstr "" +"当然,例子被我们简化了,除了作为route的回调函数修饰器,插件还可以做更多的事" +"情,先看看代码吧。" + +# 52348d8e4b494550ab5b1cf67636a17b +#: ../../plugindev.rst:36 +msgid "" +"This plugin measures the execution time for each request and adds an " +"appropriate ``X-Exec-Time`` header to the response. As you can see, the " +"plugin returns a wrapper and the wrapper calls the original callback " +"recursively. This is how decorators usually work." +msgstr "" +"这个插件计算每次请求的响应时间,并在响应头中添加了 ``X-Exec-Time`` 字段。如你" +"所见,插件返回了一个wrapper函数,由它来调用原先的回调函数。这就是修饰器的常见" +"工作方式了。" + +# b242da547a104cd09501d97a847d95cc +#: ../../plugindev.rst:38 +msgid "" +"The last line tells Bottle to install the plugin to the default application. " +"This causes the plugin to be automatically applied to all routes of that " +"application. In other words, ``stopwatch()`` is called once for each route " +"callback and the return value is used as a replacement for the original " +"callback." +msgstr "" +"最后一行,将该插件安装到Bottle的默认应用里面。这样,应用中的所有route都会应用" +"这个插件了。就是说,每次请求都会调用 ``stopwatch()`` ,更改了route的默认行" +"为。" + +# e0b29127180945cbaf760ce3209d567f +#: ../../plugindev.rst:40 +msgid "" +"Plugins are applied on demand, that is, as soon as a route is requested for " +"the first time. For this to work properly in multi-threaded environments, " +"the plugin should be thread-safe. This is not a problem most of the time, " +"but keep it in mind." +msgstr "" +"插件是按需加载的,就是在route第一次被访问的时候加载。为了在多线程环境下工作," +"插件应该是线程安全的。在大多数情况下,这都不是一个问题,但务必提高警惕。" + +# 514e9d27690249f48c823fb987b2e687 +#: ../../plugindev.rst:42 +msgid "" +"Once all plugins are applied to a route, the wrapped callback is cached and " +"subsequent requests are handled by the cached version directly. This means " +"that a plugin is usually applied only once to a specific route. That cache, " +"however, is cleared every time the list of installed plugins changes. Your " +"plugin should be able to decorate the same route more than once." +msgstr "" +"一旦route中使用了插件后,插件中的回调函数会被缓存起来,接下来都是直接使用缓存" +"中的版本来响应请求。意味着每个route只会请求一次插件。在应用的插件列表变化的时" +"候,这个缓存会被清空。你的插件应当可以多次修饰同一个route。" + +# a05a3b4288e44bdba23f95d396019402 +#: ../../plugindev.rst:44 +msgid "" +"The decorator API is quite limited, though. You don't know anything about " +"the route being decorated or the associated application object and have no " +"way to efficiently store data that is shared among all routes. But fear not! " +"Plugins are not limited to just decorator functions. Bottle accepts anything " +"as a plugin as long as it is callable or implements an extended API. This " +"API is described below and gives you a lot of control over the whole process." +msgstr "" +"这种修饰器般的API受到种种限制。你不知道route或相应的应用对象是如何被修饰的," +"也不知道如何有效地存储那些在route之间共享的数据。但别怕!插件不仅仅是修饰器函" +"数。只要一个插件是callable的或实现了一个扩展的API(后面会讲到),Bottle都可接" +"受。扩展的API给你更多的控制权。" + +# 69f3793594344919a10ec0f685d0ea0b +#: ../../plugindev.rst:48 +msgid "Plugin API" +msgstr "插件API" + +# b751b860e5d14e4f9a8f0c69bcb99dd4 +#: ../../plugindev.rst:50 +msgid "" +":class:`Plugin` is not a real class (you cannot import it from :mod:" +"`bottle`) but an interface that plugins are expected to implement. Bottle " +"accepts any object of any type as a plugin, as long as it conforms to the " +"following API." +msgstr "" +"``Plugin`` 类不是一个真正的类(你不能从bottle中导入它),它只是一个插件需要实现" +"的接口。只要一个对象实现了以下接口,Bottle就认可它作为一个插件。" + +# 074bb64c69e34d9692518ab96751d7d5 +#: ../../plugindev.rst:54 +msgid "" +"Plugins must be callable or implement :meth:`apply`. If :meth:`apply` is " +"defined, it is always preferred over calling the plugin directly. All other " +"methods and attributes are optional." +msgstr "" +"插件应该是callable的,或实现了 :meth:`apply` 方法。如果定义了 :meth:`apply` " +"方法,那么会优先调用,而不是直接调用插件。其它的方法和属性都是可选的。" + +# 1c36097519c8436792e560b415027012 +#: ../../plugindev.rst:58 +msgid "" +"Both :meth:`Bottle.uninstall` and the `skip` parameter of :meth:`Bottle.route" +"()` accept a name string to refer to a plugin or plugin type. This works " +"only for plugins that have a name attribute." +msgstr "" +":meth:`Bottle.uninstall` 方法和 :meth:`Bottle.route()` 中的 `skip` 参数都接受" +"一个与名字有关的字符串,对应插件或其类型。只有插件中有一个name属性的时候,这" +"才会起作用。" + +# 7519c49ad1c4476686d46bdcd9521e43 +#: ../../plugindev.rst:62 +msgid "" +"The Plugin API is still evolving. This integer attribute tells bottle which " +"version to use. If it is missing, bottle defaults to the first version. The " +"current version is ``2``. See :ref:`plugin-changelog` for details." +msgstr "" +"插件的API还在逐步改进。这个整形数告诉Bottle使用哪个版本的插件。如果没有这个属" +"性,Bottle默认使用第一个版本。当前版本是 ``2`` 。详见 :ref:`plugin-" +"changelog` 。" + +# b0b3c33b82d54bc8b46810a2fb4c09f4 +#: ../../plugindev.rst:66 +msgid "" +"Called as soon as the plugin is installed to an application (see :meth:" +"`Bottle.install`). The only parameter is the associated application object." +msgstr "" +"插件被安装的时候调用(见 :meth:`Bottle.install` )。唯一的参数是相应的应用对" +"象。" + +# 5db19fb886794c80b812675bff866360 +#: ../../plugindev.rst:70 +msgid "" +"As long as :meth:`apply` is not defined, the plugin itself is used as a " +"decorator and applied directly to each route callback. The only parameter is " +"the callback to decorate. Whatever is returned by this method replaces the " +"original callback. If there is no need to wrap or replace a given callback, " +"just return the unmodified callback parameter." +msgstr "" +"如果没有定义 :meth:`apply` 方法,插件本身会被直接当成一个修饰器使用(译者注:" +"Python的Magic Method,调用一个类即是调用类的__call__函数),应用到各个route。" +"唯一的参数就是其所修饰的函数。这个方法返回的东西会直接替换掉原先的回调函数。" +"如果无需如此,则直接返回未修改过的回调函数即可。" + +# 1efb205aaea44987b177c52065696000 +#: ../../plugindev.rst:74 +msgid "" +"If defined, this method is used in favor of :meth:`__call__` to decorate " +"route callbacks. The additional `route` parameter is an instance of :class:" +"`Route` and provides a lot of meta-information and context for that route. " +"See :ref:`route-context` for details." +msgstr "" +"如果存在,会优先调用,而不调用 :meth:`__call__` 。额外的 `route` 参数是 :" +"class:`Route` 类的一个实例,提供很多该route信息和上下文。详见 :ref:`route-" +"context` 。" + +# 3219b6a79df74090b7f27f64ccd457c3 +#: ../../plugindev.rst:78 +msgid "" +"Called immediately before the plugin is uninstalled or the application is " +"closed (see :meth:`Bottle.uninstall` or :meth:`Bottle.close`)." +msgstr "" +"插件被卸载或应用关闭的时候被调用,详见 :meth:`Bottle.uninstall` 或 :meth:" +"`Bottle.close` 。" + +# e7506f2c8ba14320a7c83c27edee146a +#: ../../plugindev.rst:81 +msgid "" +"Both :meth:`Plugin.setup` and :meth:`Plugin.close` are *not* called for " +"plugins that are applied directly to a route via the :meth:`Bottle.route()` " +"decorator, but only for plugins installed to an application." +msgstr "" +":meth:`Plugin.setup` 方法和 :meth:`Plugin.close` 方法 *不* 会被调用,如果插件" +"是通过 :meth:`Bottle.route` 方法来应用到route上面的,但会在安装插件的时候被调" +"用。" + +# 23cd89defb0347bfafc861737f2a6391 +#: ../../plugindev.rst:87 +msgid "Plugin API changes" +msgstr "插件API的改动" + +# 64d02d035ad84cf58ad3e685f4b5d664 +#: ../../plugindev.rst:89 +msgid "" +"The Plugin API is still evolving and changed with Bottle 0.10 to address " +"certain issues with the route context dictionary. To ensure backwards " +"compatibility with 0.9 Plugins, we added an optional :attr:`Plugin.api` " +"attribute to tell bottle which API to use. The API differences are " +"summarized here." +msgstr "" +"插件的API还在不断改进中。在Bottle 0.10版本中的改动,定位了route上下文字典中已" +"确定的问题。为了保持对0.9版本插件的兼容,我们添加了一个可选的 :attr:`Plugin." +"api` 属性,告诉Bottle使用哪个版本的API。API之间的不同点总结如下。" + +# 5cfb3972268a46bcac7737574cf28d30 +#: ../../plugindev.rst:91 +msgid "**Bottle 0.9 API 1** (:attr:`Plugin.api` not present)" +msgstr "**Bottle 0.9 API 1** (无 :attr:`Plugin.api` 属性)" + +# 10220570c5a948b6bbc9370c234c2ca6 +#: ../../plugindev.rst:93 +msgid "Original Plugin API as described in the 0.9 docs." +msgstr "" + +# abb3757c12b34c44928fe38108781f7c +#: ../../plugindev.rst:95 +msgid "**Bottle 0.10 API 2** (:attr:`Plugin.api` equals 2)" +msgstr "**Bottle 0.10 API 2** ( :attr:`Plugin.api` 属性为2)" + +# 744b13efbf7c4e759fe842d390846ad5 +#: ../../plugindev.rst:97 +msgid "" +"The `context` parameter of the :meth:`Plugin.apply` method is now an " +"instance of :class:`Route` instead of a context dictionary." +msgstr "" +" :meth:`Plugin.apply` 方法中的 `context` 参数,现在是 :class:`Route` 类的一个" +"实例,不再是一个上下文字典。" + +# 1d073dfc21c14a66b6e374e4f1c50912 +#: ../../plugindev.rst:103 +msgid "The Route Context" +msgstr "Route上下文" + +# a89bc18faad44164bc54d2fc4ca2cd7b +#: ../../plugindev.rst:105 +msgid "" +"The :class:`Route` instance passed to :meth:`Plugin.apply` provides detailed " +"informations about the associated route. The most important attributes are " +"summarized here:" +msgstr "" +":class:`Route` 的实例被传递给 :meth:`Plugin.apply` 函数,以提供更多该route的" +"相关信息。最重要的属性总结如下。" + +# b4bc9d029439417ab59cf1f8c91af888 +#: ../../plugindev.rst:108 +msgid "Attribute" +msgstr "属性" + +# 1bbff8f6d1b048659dff891d4498f7f6 +#: ../../plugindev.rst:108 +msgid "Description" +msgstr "描述" + +# c7fc4520c531481586ae783da17010ac +#: ../../plugindev.rst:110 +msgid "app" +msgstr "" + +# b6c4971342654f0db83ee30c69e1459e +#: ../../plugindev.rst:110 +msgid "The application object this route is installed to." +msgstr "安装该route的应用对象" + +# 51140a3d362a4b1ab54f78a8a0178872 +#: ../../plugindev.rst:111 +msgid "rule" +msgstr "" + +# b753acc47aa34713809385ecc448577c +#: ../../plugindev.rst:111 +msgid "The rule string (e.g. ``/wiki/:page``)." +msgstr "route规则的字符串 (例如: ``/wiki/:page``)" + +# 294f892e7a4445888a6d62fcdc03934a +#: ../../plugindev.rst:112 +msgid "method" +msgstr "" + +# fe67b10550a24e8ea7d3e736c270b74b +#: ../../plugindev.rst:112 +msgid "The HTTP method as a string (e.g. ``GET``)." +msgstr "HTTP方法的字符串(例如: ``GET``)" + +# 22065ffdd5e348c18b22bd1b3b4fabde +#: ../../plugindev.rst:113 +msgid "callback" +msgstr "" + +# 4a518bf76c4b440d81457e7c89fb1cd8 +#: ../../plugindev.rst:113 +msgid "" +"The original callback with no plugins applied. Useful for introspection." +msgstr "未应用任何插件的原始回调函数,用于内省。" + +# 82c51209242e4659b6cff3066407ade1 +#: ../../plugindev.rst:115 +msgid "name" +msgstr "" + +# 6608162803a84149b0d3209e83c529c0 +#: ../../plugindev.rst:115 +msgid "The name of the route (if specified) or ``None``." +msgstr "route的名字,如未指定则为 ``None``" + +# cccace76be07444d8614e3c5f6ac7521 +#: ../../plugindev.rst:116 +msgid "plugins" +msgstr "" + +# cd12629c455c4df8a5599035f319bfe7 +#: ../../plugindev.rst:116 +msgid "" +"A list of route-specific plugins. These are applied in addition to " +"application-wide plugins. (see :meth:`Bottle.route`)." +msgstr "" +"route安装的插件列表,除了整个应用范围内的插件,额外添加的(见 :meth:`Bottle." +"route` )" + +# f9a190553313428e8ba02708c2ccc56e +#: ../../plugindev.rst:118 +msgid "skiplist" +msgstr "" + +# 7b16003235de4feeae9147f1755ec0cd +#: ../../plugindev.rst:118 +msgid "" +"A list of plugins to not apply to this route (again, see :meth:`Bottle." +"route`)." +msgstr "应用安装了,但该route没安装的插件列表(见 meth:`Bottle.route` )" + +# 2a5007f96ecd49a78c8c865d1bc412e6 +#: ../../plugindev.rst:120 +msgid "config" +msgstr "" + +# 7f0133c15d084d8597693a976205b123 +#: ../../plugindev.rst:120 +msgid "" +"Additional keyword arguments passed to the :meth:`Bottle.route` decorator " +"are stored in this dictionary. Used for route-specific configuration and " +"meta-data." +msgstr "" +"传递给 :meth:`Bottle.route` 修饰器的额外参数,存在一个字典中,用于特定的设置" +"和元数据" + +# 722fd7ed4f4248f28e64465ba4d119c5 +#: ../../plugindev.rst:125 +msgid "" +"For your plugin, :attr:`Route.config` is probably the most important " +"attribute. Keep in mind that this dictionary is local to the route, but " +"shared between all plugins. It is always a good idea to add a unique prefix " +"or, if your plugin needs a lot of configuration, store it in a separate " +"namespace within the `config` dictionary. This helps to avoid naming " +"collisions between plugins." +msgstr "" +"对你的应用而言, :attr:`Route.config` 也许是最重要的属性了。记住,这个字典会" +"在所有插件中共享,建议添加一个独一无二的前缀。如果你的插件需要很多设置,将其" +"保存在 `config` 字典的一个独立的命名空间吧。防止插件之间的命名冲突。" + +# f53449a4621e49b4bdb0770323ae2daf +#: ../../plugindev.rst:129 +msgid "Changing the :class:`Route` object" +msgstr "改变 :class:`Route` 对象" + +# cc764000ca1748e9b38e144cf7a7643f +#: ../../plugindev.rst:131 +msgid "" +"While some :class:`Route` attributes are mutable, changes may have unwanted " +"effects on other plugins. It is most likely a bad idea to monkey-patch a " +"broken route instead of providing a helpful error message and let the user " +"fix the problem." +msgstr "" +":class:`Route` 的一些属性是不可变的,改动也许会影响到其它插件。坏主意就是," +"monkey-patch一个损坏的route,而不是提供有效的帮助信息来让用户修复问题。" + +# a5af5533b77e44128e361293f2fc3798 +#: ../../plugindev.rst:133 +msgid "" +"In some rare cases, however, it might be justifiable to break this rule. " +"After you made your changes to the :class:`Route` instance, raise :exc:" +"`RouteReset` as an exception. This removes the current route from the cache " +"and causes all plugins to be re-applied. The router is not updated, however. " +"Changes to `rule` or `method` values have no effect on the router, but only " +"on plugins. This may change in the future, though." +msgstr "" +"在极少情况下,破坏规则也许是恰当的。在你更改了 :class:`Route` 实例后,抛一" +"个 :exc:`RouteReset` 异常。这会从缓存中删除当前的route,并重新应用所有插件。" +"无论如何,router没有被更新。改变 `rule` 或 `method` 的值并不会影响到router," +"只会影响到插件。这个情况在将来也许会改变。" + +# 16a7151b384c4a81b570969ad3f018e6 +#: ../../plugindev.rst:137 +msgid "Runtime optimizations" +msgstr "运行时优化" + +# ace532d31ea54a1cbdd96d04188d7146 +#: ../../plugindev.rst:139 +msgid "" +"Once all plugins are applied to a route, the wrapped route callback is " +"cached to speed up subsequent requests. If the behavior of your plugin " +"depends on configuration, and you want to be able to change that " +"configuration at runtime, you need to read the configuration on each " +"request. Easy enough." +msgstr "" +"插件应用到route以后,被插件封装起来的回调函数会被缓存,以加速后续的访问。如果" +"你的插件的行为依赖一些设置,你需要在运行时更改这些设置,你需要在每次请求的时" +"候读取设置信息。够简单了吧。" + +# 37245e265807499ba47e14eeab14292e +#: ../../plugindev.rst:141 +msgid "" +"For performance reasons, however, it might be worthwhile to choose a " +"different wrapper based on current needs, work with closures, or enable or " +"disable a plugin at runtime. Let's take the built-in HooksPlugin as an " +"example: If no hooks are installed, the plugin removes itself from all " +"affected routes and has virtaully no overhead. As soon as you install the " +"first hook, the plugin activates itself and takes effect again." +msgstr "" +"然而,为了性能考虑,也许值得根据当前需求,选择一个不同的封装,通过闭包,或在" +"运行时使用、禁用一个插件。让我们拿内置的HooksPlugin作为一个例子(译者注:可在" +"bottle.py搜索该实现):如果没有安装任何钩子,这个插件会从所有受影响的route中删" +"除自身,不做任何工作。一旦你安装了第一个钩子,这个插件就会激活自身,再次工" +"作。" + +# 803ca8d55e454df6a779d4eb1ae1de0d +#: ../../plugindev.rst:143 +msgid "" +"To achieve this, you need control over the callback cache: :meth:`Route." +"reset` clears the cache for a single route and :meth:`Bottle.reset` clears " +"all caches for all routes of an application at once. On the next request, " +"all plugins are re-applied to the route as if it were requested for the " +"first time." +msgstr "" +"为了达到这个目的,你需要控制回调函数的缓存: :meth:`Route.reset` 函数清空单一" +"route的缓存, :meth:`Bottle.reset` 函数清空所有route的缓存。在下一次请求的时" +"候,所有插件被重新应用到route上面,就像第一次请求时那样。" + +# 95ff1566945744208456697719c29729 +#: ../../plugindev.rst:145 +msgid "" +"Both methods won't affect the current request if called from within a route " +"callback, of cause. To force a restart of the current request, raise :exc:" +"`RouteReset` as an exception." +msgstr "" +"如果在route的回调函数里面调用,两种方法都不会影响当前的请求。当然,可以抛出一" +"个 :exc:`RouteReset` 异常,来改变当前的请求。" + +# 3a5a604634d34978b9efbadf27c6c967 +#: ../../plugindev.rst:149 +msgid "Plugin Example: SQLitePlugin" +msgstr "插件例子: SQLitePlugin" + +# e140667bf1044ef4954b957439f727af +#: ../../plugindev.rst:151 +msgid "" +"This plugin provides an sqlite3 database connection handle as an additional " +"keyword argument to wrapped callbacks, but only if the callback expects it. " +"If not, the route is ignored and no overhead is added. The wrapper does not " +"affect the return value, but handles plugin-related exceptions properly. :" +"meth:`Plugin.setup` is used to inspect the application and search for " +"conflicting plugins." +msgstr "" +"这个插件提供对sqlite3数据库的访问,如果route的回调函数提供了关键字参数(默认是" +"\"db\"),则\"db\"可做为数据库连接,如果route的回调函数没有提供该参数,则忽略" +"该route。wrapper不会影响返回值,但是会处理插件相关的异常。 :meth:`Plugin." +"setup` 方法用于检查应用,查找冲突的插件。" + +# 1b725ab04fbf4386a18d8a002b9d02a1 +#: ../../plugindev.rst:218 +msgid "" +"This plugin is actually useful and very similar to the version bundled with " +"Bottle. Not bad for less than 60 lines of code, don't you think? Here is a " +"usage example::" +msgstr "" +"这个插件十分有用,已经和Bottle提供的那个版本很类似了(译者注:=。= 一模一样)。" +"只要60行代码,还不赖嘛!下面是一个使用例子。" + +# f4afab875e984003b5469bce2fd4236a +#: ../../plugindev.rst:239 +msgid "" +"The first route needs a database connection and tells the plugin to create a " +"handle by requesting a ``db`` keyword argument. The second route does not " +"need a database and is therefore ignored by the plugin. The third route does " +"expect a 'db' keyword argument, but explicitly skips the sqlite plugin. This " +"way the argument is not overruled by the plugin and still contains the value " +"of the same-named url argument." +msgstr "" +"第一个route提供了一个\"db\"参数,告诉插件它需要一个数据库连接。第二个route不" +"需要一个数据库连接,所以会被插件忽略。第三个route确实有一个\"db\"参数,但显式" +"的禁用了sqlite插件,这样,\"db\"参数不会被插件修改,还是包含URL传过来的那个" +"值。" diff -Nru python-bottle-0.11.6/docs/_locale/zh_CN/plugins.po python-bottle-0.12.0/docs/_locale/zh_CN/plugins.po --- python-bottle-0.11.6/docs/_locale/zh_CN/plugins.po 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/docs/_locale/zh_CN/plugins.po 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,405 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) 2009-2012, Marcel Hellkamp +# This file is distributed under the same license as the Bottle package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Bottle 0.12-dev\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-02-16 21:45\n" +"PO-Revision-Date: 2012-11-09 15:59+0800\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +# 7f8e01d2a2e94efeaa90c3e429b1f67d +#: ../../plugins/index.rst:5 +msgid "List of available Plugins" +msgstr "可用插件列表" + +# 926c3d34f06a4efba51f28337c68f55a +#: ../../plugins/index.rst:7 +msgid "" +"This is a list of third-party plugins that add extend Bottles core " +"functionality or integrate other libraries with the Bottle framework." +msgstr "这是一份第三方插件的列表,扩展Bottle的核心功能,或集成其它类库。" + +# 998551b35dae49c4baf3844f3803ebbd +#: ../../plugins/index.rst:9 +msgid "" +"Have a look at :ref:`plugins` for general questions about plugins " +"(installation, usage). If you plan to develop a new plugin, the :doc:`/" +"plugindev` may help you." +msgstr "" +"在 :ref:`plugins` 查看常见的插件问题(安装,使用)。如果你计划开发一个新的插" +"件, :doc:`/plugindev` 也许对你有帮助。" + +# fb445e42b73949198b058b1f52f5258b +#: ../../plugins/index.rst:12 +msgid "`Bottle-Cork `_" +msgstr "" + +# 58f41b1d6aac4800bd5312e03b93c028 +#: ../../plugins/index.rst:12 +msgid "" +"Cork provides a simple set of methods to implement Authentication and " +"Authorization in web applications based on Bottle." +msgstr "Cork插件基于Bottle,提供了一些简单的方法来实现Web应用的权限验证。" + +# fe631d4ca8544947ae22feafb3125dcb +#: ../../plugins/index.rst:15 +msgid "`Bottle-Extras `_" +msgstr "" + +# aff1d22e623a4776bcc5be08a0f5c569 +#: ../../plugins/index.rst:15 +msgid "Meta package to install the bottle plugin collection." +msgstr "安装Bottle插件的集合" + +# 938a054fadf54609b09fadca18915629 +#: ../../plugins/index.rst:18 +msgid "`Bottle-Flash `_" +msgstr "" + +# 746812f7a019498e87758355943a3193 +#: ../../plugins/index.rst:18 +msgid "flash plugin for bottle" +msgstr "Bottle的flash插件" + +# dd53dc05c1e84435b86efb8411a5c41a +#: ../../plugins/index.rst:21 +msgid "`Bottle-Hotqueue `_" +msgstr "" + +# 535e939a040146ae8fab322db9025380 +#: ../../plugins/index.rst:21 +msgid "FIFO Queue for Bottle built upon redis" +msgstr "基于redis的FIFO队列服务" + +# afafe43d5de6451a96b6b32ccb99fd00 +#: ../../plugins/index.rst:24 +msgid "`Macaron `_" +msgstr "" + +# f6272745bb7a4b5286ad41059624da3c +#: ../../plugins/index.rst:24 +msgid "Macaron is an object-relational mapper (ORM) for SQLite." +msgstr "Macaron是用于SQLite的ORM" + +# 68c2f103e32d43fb952f052d3cb3a4e6 +#: ../../plugins/index.rst:27 +msgid "`Bottle-Memcache `_" +msgstr "" + +# 02a84e17b8c6429984ebb78334ee31a5 +#: ../../plugins/index.rst:27 +msgid "Memcache integration for Bottle." +msgstr "Memcache集成" + +# 64780d9112694cd09aab9de5283c5a3a +#: ../../plugins/index.rst:30 +msgid "`Bottle-MongoDB `_" +msgstr "" + +# e0e067d5ae414b7395a2192ca8b35cd3 +#: ../../plugins/index.rst:30 +msgid "MongoDB integration for Bottle" +msgstr "MongoDB集成" + +# e2e6dc5ed6e44dd19b6d381c21ce4274 +#: ../../plugins/index.rst:33 +msgid "`Bottle-Redis `_" +msgstr "" + +# 68bc58b5015c402d90ae0d5350260080 +#: ../../plugins/index.rst:33 +msgid "Redis integration for Bottle." +msgstr "Redis集成" + +# c74f6cb622be491aa618c25d819a17dd +#: ../../plugins/index.rst:36 +msgid "`Bottle-Renderer `_" +msgstr "" + +# 2213271856294ba184e3d73817e7306d +#: ../../plugins/index.rst:36 +msgid "Renderer plugin for bottle" +msgstr "Renderer插件" + +# 4287e3df39264e7baab8f046b7b3353b +#: ../../plugins/index.rst:39 +msgid "`Bottle-Servefiles `_" +msgstr "" + +# e63027f3c7594930be7b6a2d3d9c8af1 +#: ../../plugins/index.rst:39 +msgid "A reusable app that serves static files for bottle apps" +msgstr "一个可重用的APP,为Bottle应用提供静态文件服务。" + +# ea6c00ae10624fffa161c35bc588e09b +#: ../../plugins/index.rst:42 +msgid "`Bottle-Sqlalchemy `_" +msgstr "" + +# 2a76b62faec84b3684c2d8747fe06c35 +#: ../../plugins/index.rst:42 +msgid "SQLAlchemy integration for Bottle." +msgstr "SQLAlchemy集成" + +# cab6769882cf4596bb782cb657b17f49 +#: ../../plugins/index.rst:45 +msgid "`Bottle-Sqlite `_" +msgstr "" + +# ef35627e5de14711a12f782786de93d4 +#: ../../plugins/index.rst:45 +msgid "SQLite3 database integration for Bottle." +msgstr "SQLite3数据库集成" + +# c3eb03bbe1ef4bc1b97c2eb850aed3c4 +#: ../../plugins/index.rst:48 +msgid "`Bottle-Web2pydal `_" +msgstr "" + +# f01e53ed49544cd487224b2ae784236a +#: ../../plugins/index.rst:48 +msgid "Web2py Dal integration for Bottle." +msgstr "Wbe2py的Dal集成" + +# e1260f9c9c4d4ba5b5b0b6e67b853da1 +#: ../../plugins/index.rst:51 +msgid "`Bottle-Werkzeug `_" +msgstr "" + +# ceb2ae912be74561b44d9b9a4a38d9b1 +#: ../../plugins/index.rst:51 +msgid "" +"Integrates the `werkzeug` library (alternative request and response objects, " +"advanced debugging middleware and more)." +msgstr "" +"集成 `werkzeug` (可选的request和response对象,更高级的调试中间件等等)" + +# 8ec7fd1656ac47e0b2221f7cd28a3848 +#: ../../plugins/index.rst:53 +msgid "" +"Plugins listed here are not part of Bottle or the Bottle project, but " +"developed and maintained by third parties." +msgstr "这里列出的插件不属于Bottle或Bottle项目,是第三方开发并维护的。" + +# 6f41cb4bdcdd4dbeb70a201ce81eb7f2 +#: ../../../plugins/sqlite/README:3 +msgid "Bottle-SQLite" +msgstr "" + +# fe329bbcfc1c4bfba89ff822056ab5bd +#: ../../../plugins/sqlite/README:5 +msgid "" +"SQLite is a self-contained SQL database engine that runs locally and does " +"not require any additional server software or setup. The sqlite3 module is " +"part of the Python standard library and already installed on most systems. " +"It it very useful for prototyping database-driven applications that are " +"later ported to larger databases such as PostgreSQL or MySQL." +msgstr "" +"SQLite是一个\"自包含\"的SQL数据库引擎,不需要任何其它服务器软件或安装过程。" +"sqlite3模块是Python标准库的一部分,在大部分系统上面已经安装了。在开发依赖数据" +"库的应用原型的时候,它是非常有用的,可在部署的时候再使用PostgreSQL或MySQL。" + +# adebbc2b5b1b49b99c5d6c0451ffa759 +#: ../../../plugins/sqlite/README:11 +msgid "" +"This plugin simplifies the use of sqlite databases in your Bottle " +"applications. Once installed, all you have to do is to add a ``db`` keyword " +"argument (configurable) to route callbacks that need a database connection." +msgstr "" +"这个插件让在Bottle应用中使用sqlite数据库更简单了。一旦安装了,你只要在route的" +"回调函数里添加一个\"db\"参数(可更改为其它字符),就能使用数据库链接了。" + +# 84f7e9a1e50149baacb76346df6e5508 +# 3e410718c8d941eda9f78406a7d42e5d +#: ../../../plugins/sqlite/README:16 ../../../plugins/werkzeug/README:17 +msgid "Installation" +msgstr "安装" + +# 0f0622674c7648ce83878a26ca64bfbb +# 4c4bd042eeef48eb8fd0773aeb1ab132 +#: ../../../plugins/sqlite/README:18 ../../../plugins/werkzeug/README:19 +msgid "Install with one of the following commands::" +msgstr "下面两个命令任选一个" + +# 42ea2e3ca2974198bb9d13e5fe2abf7f +# 695262e42ae143e396f0b49460772d9f +#: ../../../plugins/sqlite/README:23 ../../../plugins/werkzeug/README:24 +msgid "or download the latest version from github::" +msgstr "或从github下载最新版本" + +# d977670f6ce442f2b4fcf04e770f46ef +# 3b0cc3afff774774ae5f20510bda9c13 +#: ../../../plugins/sqlite/README:30 ../../../plugins/werkzeug/README:33 +msgid "Usage" +msgstr "使用" + +# a4b8d2a6012f45babb7111735bc436a3 +#: ../../../plugins/sqlite/README:32 +msgid "" +"Once installed to an application, the plugin passes an open :class:`sqlite3." +"Connection` instance to all routes that require a ``db`` keyword argument::" +msgstr "" +"一旦安装到应用里面,如果route的回调函数包含一个名为\"db\"的参数,该插件会给该" +"参数传一个 :class:`sqlite3.Connection` 类的实例。" + +# 2db3342cda76424583c6834397f8d47f +#: ../../../plugins/sqlite/README:49 +msgid "Routes that do not expect a ``db`` keyword argument are not affected." +msgstr "不包含\"db\"参数的route不会受影响。" + +# 17e3ad45eace4b15a012c8015862ed70 +#: ../../../plugins/sqlite/README:51 +msgid "" +"The connection handle is configured so that :class:`sqlite3.Row` objects can " +"be accessed both by index (like tuples) and case-insensitively by name. At " +"the end of the request cycle, outstanding transactions are committed and the " +"connection is closed automatically. If an error occurs, any changes to the " +"database since the last commit are rolled back to keep the database in a " +"consistent state." +msgstr "" +"可通过下标(像元组)来访问 :class:`sqlite3.Row` 对象,且对命名的大小写敏感。在" +"请求结束后,自动提交事务和关闭连接。如果出现任何错误,自上次提交后的所有更改" +"都会被回滚,以保证数据库的一致性。" + +# 0a90c8f1724b4956ab9a1c7cacdce967 +# de779571d3b3420bac73033b2017dbf5 +#: ../../../plugins/sqlite/README:58 ../../../plugins/werkzeug/README:73 +msgid "Configuration" +msgstr "配置" + +# f1e6e51d894a466bbac469605d31dc81 +# 274dd7703c074319a7be90073bf49ab6 +#: ../../../plugins/sqlite/README:60 ../../../plugins/werkzeug/README:75 +msgid "The following configuration options exist for the plugin class:" +msgstr "有下列可配置的选项:" + +# de6b7d40dacd47fdb02ce3bceba09ff2 +#: ../../../plugins/sqlite/README:62 +msgid "**dbfile**: Database filename (default: in-memory database)." +msgstr "**dbfile**: 数据库文件 (默认: 存在在内存中)。" + +# 079314db1cbb4547aa9cb1a6c1ce93cd +#: ../../../plugins/sqlite/README:63 +msgid "" +"**keyword**: The keyword argument name that triggers the plugin (default: " +"'db')." +msgstr "**keyword**: route中使用数据库连接的参数 (默认: 'db')。" + +# 63957028a426442ea914af5c5e5c268c +#: ../../../plugins/sqlite/README:64 +msgid "" +"**autocommit**: Whether or not to commit outstanding transactions at the end " +"of the request cycle (default: True)." +msgstr "**autocommit**: 是否在请求结束后提交事务 (默认: True)。" + +# fa70c63aea9b46e1bd63202184cc56b6 +#: ../../../plugins/sqlite/README:65 +msgid "" +"**dictrows**: Whether or not to support dict-like access to row objects " +"(default: True)." +msgstr "**dictrows**: 是否可像字典那样访问row对象 (默认: True)。" + +# 4c44e12a0db14e85b99a84e543d99bf8 +#: ../../../plugins/sqlite/README:67 +msgid "You can override each of these values on a per-route basis::" +msgstr "你可在route里面覆盖这些默认值。" + +# ae3acd995886447bb8cacadc3bf78584 +#: ../../../plugins/sqlite/README:73 +msgid "" +"or install two plugins with different ``keyword`` settings to the same " +"application::" +msgstr "或在同一个应用里面安装 ``keyword`` 参数不同的两个插件。" + +# 4a92aa81a21345b5834f7bad349424df +#: ../../../plugins/werkzeug/README:3 +msgid "Bottle-Werkzeug" +msgstr "" + +# 740576d3ed414027a83492c42a850981 +#: ../../../plugins/werkzeug/README:5 +msgid "" +"`Werkzeug `_ is a powerful WSGI utility library " +"for Python. It includes an interactive debugger and feature-packed request " +"and response objects." +msgstr "" +"`Werkzeug `_ 是一个强大的WSGI类库。它包含一个交互" +"式的调试器和包装好的request和response对象。" + +# f6d80c0515d9452ebc778f45c2f26156 +#: ../../../plugins/werkzeug/README:9 +msgid "" +"This plugin integrates :class:`werkzeug.wrappers.Request` and :class:" +"`werkzeug.wrappers.Response` as an alternative to the built-in " +"implementations, adds support for :mod:`werkzeug.exceptions` and replaces " +"the default error page with an interactive debugger." +msgstr "" +"这个插件集成了 :class:`werkzeug.wrappers.Request` 和 :class:`werkzeug." +"wrappers.Response` 用于取代内置的相应实现,支持 :mod:`werkzeug.exceptions` ," +"用交互式的调试器替换了默认的错误页面。" + +# 3fc241ca6b5647c095c06fd0cb51a9f4 +#: ../../../plugins/werkzeug/README:35 +msgid "" +"Once installed to an application, this plugin adds support for :class:" +"`werkzeug.wrappers.Response`, all kinds of :mod:`werkzeug.exceptions` and " +"provides a thread-local instance of :class:`werkzeug.wrappers.Request` that " +"is updated with each request. The plugin instance itself doubles as a " +"werkzeug module object, so you don't have to import werkzeug in your " +"application. Here is an example::" +msgstr "" +"一旦安装到应用中,该插件将支持 :class:`werkzeug.wrappers.Response` ,所有类型" +"的 :mod:`werkzeug.exceptions` 和thread-local的 :class:`werkzeug.wrappers." +"Request` 的实例(每次请求都更新)。插件它本身还扮演着werkzeug模块的角色,所以你" +"无需在应用中导入werkzeug。下面是一个例子。" + +# 8ca3622eb42a4c2e8745f63cfc852b19 +#: ../../../plugins/werkzeug/README:62 +msgid "Using the Debugger" +msgstr "使用调试器" + +# 48d4c47e99e94dc6b040641659af2e47 +#: ../../../plugins/werkzeug/README:64 +msgid "" +"This plugin replaces the default error page with an advanced debugger. If " +"you have the `evalex` feature enabled, you will get an interactive console " +"that allows you to inspect the error context in the browser. Please read " +"`Debugging Applications with werkzeug `_ before you enable " +"this feature." +msgstr "" +"该插件用一个更高级的调试器替换了默认的错误页面。如果你启用了 `evalex` 特性," +"你可在浏览器中使用一个交互式的终端来检查错误。在你启用该特性之前,请看 `通过" +"werkzeug来调试 `_ 。" + +# 4dd4d57c159f41028ce088a05dfaf886 +#: ../../../plugins/werkzeug/README:77 +msgid "" +"**evalex**: Enable the exception evaluation feature (interactive debugging). " +"This requires a non-forking server and is a security risk. Please read " +"`Debugging Applications with werkzeug `_. (default: False)" +msgstr "" +"**evalex**: 启用交互式的调试器。要求一个单进程的服务器,且有安全隐患。请看 `" +"通过werkzeug来调试 `_ (默认: False)" + +# f7025d633d12487eb3075443df743bff +#: ../../../plugins/werkzeug/README:78 +msgid "**request_class**: Defaults to :class:`werkzeug.wrappers.Request`" +msgstr "**request_class**: 默认是 :class:`werkzeug.wrappers.Request` 的实例" + +# 565565f6d3884db196c5be214580f8a3 +#: ../../../plugins/werkzeug/README:79 +msgid "" +"**debugger_class**: Defaults to a subclass of :class:`werkzeug.debug." +"DebuggedApplication` which obeys the :data:`bottle.DEBUG` setting." +msgstr "" +"**debugger_class**: 默认是 :class:`werkzeug.debug.DebuggedApplication` 的子" +"类,遵守 :data:`bottle.DEBUG` 中的设置" diff -Nru python-bottle-0.11.6/docs/_locale/zh_CN/recipes.po python-bottle-0.12.0/docs/_locale/zh_CN/recipes.po --- python-bottle-0.11.6/docs/_locale/zh_CN/recipes.po 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/docs/_locale/zh_CN/recipes.po 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,381 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) 2009-2012, Marcel Hellkamp +# This file is distributed under the same license as the Bottle package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Bottle 0.12-dev\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-02-17 01:11\n" +"PO-Revision-Date: 2013-02-17 01:52+0800\n" +"Last-Translator: \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.5.4\n" + +# 8487026bb92949c197608691e0682922 +#: ../../recipes.rst:16 +msgid "Recipes" +msgstr "秘诀" + +# cfd0882653594f1eae8a9bef70324bc4 +#: ../../recipes.rst:18 +msgid "" +"This is a collection of code snippets and examples for common use cases." +msgstr "这里收集了一些常见用例的代码片段和例子." + +# faa7771e7cda4492b891ae26152c932e +#: ../../recipes.rst:21 +msgid "Keeping track of Sessions" +msgstr "使用Session" + +# e3a652f4923841fbbdadcb5f3dc5f90d +#: ../../recipes.rst:23 +msgid "" +"There is no built-in support for sessions because there is no *right* way to " +"do it (in a micro framework). Depending on requirements and environment you " +"could use beaker_ middleware with a fitting backend or implement it " +"yourself. Here is an example for beaker sessions with a file-based backend::" +msgstr "" +"Bottle自身并没有提供Session的支持,因为在一个迷你框架里面,没有合适的方法来实" +"现。根据需求和使用环境,你可以使用 beaker_ 中间件或自己来实现。下面是一个使用" +"beaker的例子,Session数据存放在\"./data\"目录里面::" + +# a2d14fa0a98f44d4982d9d0b96fcbe80 +#: ../../recipes.rst:46 +msgid "Debugging with Style: Debugging Middleware" +msgstr "Debugging with Style: 调试中间件" + +# 9cd203576e7043b484ee096450fed53d +#: ../../recipes.rst:48 +msgid "" +"Bottle catches all Exceptions raised in your app code to prevent your WSGI " +"server from crashing. If the built-in :func:`debug` mode is not enough and " +"you need exceptions to propagate to a debugging middleware, you can turn off " +"this behaviour::" +msgstr "" +"Bottle捕获所有应用抛出的异常,防止异常导致WSGI服务器崩溃。如果内置的 :func:" +"`debug` 模式不能满足你的要求,你想在你自己写的中间件里面处理这些异常,那么你" +"可以关闭这个功能。" + +# fbc746186f784972877b51c923365560 +#: ../../recipes.rst:56 +msgid "" +"Now, bottle only catches its own exceptions (:exc:`HTTPError`, :exc:" +"`HTTPResponse` and :exc:`BottleException`) and your middleware can handle " +"the rest." +msgstr "" +"现在,Bottle仅会捕获并处理它自己抛出的异常( :exc:`HTTPError` , :exc:" +"`HTTPResponse` 和 :exc:`BottleException` ),你的中间件可以处理剩下的那些异" +"常。" + +# 36c1c52ece8c4f268a7dc278b274b829 +#: ../../recipes.rst:58 +msgid "" +"The werkzeug_ and paste_ libraries both ship with very powerful debugging " +"WSGI middleware. Look at :class:`werkzeug.debug.DebuggedApplication` for " +"werkzeug_ and :class:`paste.evalexception.middleware.EvalException` for " +"paste_. They both allow you do inspect the stack and even execute python " +"code within the stack context, so **do not use them in production**." +msgstr "" +"werkzeug_ 和 paste_ 这两个第三方库都提供了非常强大的调试中间件。如果是 " +"werkzeug_ ,可看看 :class:`werkzeug.debug.DebuggedApplication` ,如果是 " +"paste_ ,可看看 :class:`paste.evalexception.middleware.EvalException` 。它们" +"都可让你检查运行栈,甚至在保持运行栈上下文的情况下,执行Python代码。所以 **不" +"要在生产环境中使用它们** 。" + +# 0bca874b50014d1aa55d3d5a122dad91 +#: ../../recipes.rst:62 +msgid "Unit-Testing Bottle Applications" +msgstr "" + +# abb049c14147472ab7095e6a92438c68 +#: ../../recipes.rst:64 +msgid "" +"Unit-testing is usually performed against methods defined in your web " +"application without running a WSGI environment." +msgstr "Unit测试一般用于测试应用中的函数,但不需要一个WSGI环境。" + +# 8db4441496bf46629c01f66929c54221 +#: ../../recipes.rst:66 +msgid "A simple example using `Nose `_::" +msgstr "使用 `Nose `_ 的简单例子。" + +# 5215a5269ce1494b8bb619b73916b610 +#: ../../recipes.rst:77 +msgid "Test script::" +msgstr "测试代码::" + +# 8fb6ca337895400991fdb334c3ef1659 +#: ../../recipes.rst:84 +msgid "" +"In the example the Bottle route() method is never executed - only index() is " +"tested." +msgstr "在这个例子中,Bottle的route()函数没有被执行,仅测试了index()函数。" + +# 62f71facf6464ca68babf9bef0a0160a +#: ../../recipes.rst:88 +msgid "Functional Testing Bottle Applications" +msgstr "功能测试" + +# 39f2c3a094f84d1bb0974af018beaa6a +#: ../../recipes.rst:90 +msgid "" +"Any HTTP-based testing system can be used with a running WSGI server, but " +"some testing frameworks work more intimately with WSGI, and provide the " +"ability the call WSGI applications in a controlled environment, with " +"tracebacks and full use of debugging tools. `Testing tools for WSGI `_ is a good starting point." +msgstr "" +"任何基于HTTP的测试系统都可用于测试WSGI服务器,但是有些测试框架与WSGI服务器工" +"作得更好。它们可以在一个可控环境里运行WSGI应用,充分利用traceback和调试工" +"具。 `Testing tools for WSGI `_ " +"是一个很好的上手工具。" + +# 56ee442ef6714be38dcf951e95112c22 +#: ../../recipes.rst:92 +msgid "" +"Example using `WebTest `_ and `Nose `_::" +msgstr "" +"使用 `WebTest `_ 和 `Nose `_ 的例子。" + +# 58fd7a3ba2494e059ba1f0157788af13 +#: ../../recipes.rst:112 +msgid "Embedding other WSGI Apps" +msgstr "嵌入其他WSGI应用" + +# 5f0f337aca4e43a6ac2ad2d8dcb771c0 +#: ../../recipes.rst:114 +msgid "" +"This is not the recommend way (you should use a middleware in front of " +"bottle to do this) but you can call other WSGI applications from within your " +"bottle app and let bottle act as a pseudo-middleware. Here is an example::" +msgstr "" +"并不建议你使用这个方法,你应该在Bottle前面使用一个中间件来做这样的事情。但你" +"确实可以在Bottle里面调用其他WSGI应用,让Bottle扮演一个中间件的角色。下面是一" +"个例子。" + +# a196f1d227dd4d5fbc2ad6f293b24b0e +#: ../../recipes.rst:130 +msgid "" +"Again, this is not the recommend way to implement subprojects. It is only " +"here because many people asked for this and to show how bottle maps to WSGI." +msgstr "" +"再次强调,并不建议使用这种方法。之所以介绍这种方法,是因为很多人问起,如何在" +"Bottle中调用WSGI应用。" + +# f25d4e33503c43148073e9f81decbf72 +#: ../../recipes.rst:134 +msgid "Ignore trailing slashes" +msgstr "忽略尾部的反斜杠" + +# d28129334ef24183a739ec177f3a322a +#: ../../recipes.rst:136 +msgid "" +"For Bottle, ``/example`` and ``/example/`` are two different routes [1]_. To " +"treat both URLs the same you can add two ``@route`` decorators::" +msgstr "" +"在Bottle看来, ``/example`` 和 ``/example/`` 是两个不同的route [1]_ 。为了一" +"致对待这两个URL,你应该添加两个route。" + +# 2a6abd0a87e24a6e92fef547a4e3f0b4 +#: ../../recipes.rst:142 +msgid "or add a WSGI middleware that strips trailing slashes from all URLs::" +msgstr "或者添加一个WSGI中间件来处理这种情况。" + +# ff6aaa5c70994fa3955888819121dfa3 +#: ../../recipes.rst:156 +msgid "Footnotes" +msgstr "脚注" + +# 81148a89616b4d358ace32d79e576043 +#: ../../recipes.rst:157 +msgid "Because they are. See " +msgstr "因为确实如此,见 " + +# 33f68df31e094ac2b967015004250f28 +#: ../../recipes.rst:161 +msgid "Keep-alive requests" +msgstr "Keep-alive 请求" + +# 548edbc8dabe4ce4a00458bd74d72d74 +#: ../../recipes.rst:165 +msgid "For a more detailed explanation, see :doc:`async`." +msgstr "详见 :doc:`async` 。" + +# 1ab0b644d6da4fcf943b67f77b19c330 +#: ../../recipes.rst:167 +msgid "" +"Several \"push\" mechanisms like XHR multipart need the ability to write " +"response data without closing the connection in conjunction with the " +"response header \"Connection: keep-alive\". WSGI does not easily lend itself " +"to this behavior, but it is still possible to do so in Bottle by using the " +"gevent_ async framework. Here is a sample that works with either the gevent_ " +"HTTP server or the paste_ HTTP server (it may work with others, but I have " +"not tried). Just change ``server='gevent'`` to ``server='paste'`` to use the " +"paste_ server::" +msgstr "" +"像XHR这样的\"push\"机制,需要在HTTP响应头中加入 \"Connection: keep-alive\" ," +"以便在不关闭连接的情况下,写入响应数据。WSGI并不支持这种行为,但如果在Bottle" +"中使用 gevent_ 这个异步框架,还是可以实现的。下面是一个例子,可配合 gevent_ " +"HTTP服务器或 paste_ HTTP服务器使用(也许支持其他服务器,但是我没试过)。在run()" +"函数里面使用 ``server='gevent'`` 或 ``server='paste'`` 即可使用这两种服务器。" + +# c7a5e20a91054b07ae82effa317c5b34 +#: ../../recipes.rst:184 +msgid "" +"If you browse to ``http://localhost:8080/stream``, you should see 'START', " +"'MIDDLE', and 'END' show up one at a time (rather than waiting 8 seconds to " +"see them all at once)." +msgstr "" +"通过浏览器访问 ``http://localhost:8080/stream`` ,可看到'START','MIDDLE'," +"和'END'这三个字眼依次出现,一共用了8秒。" + +# fef7a41bbeb84056b2c0cd48f54b78bc +#: ../../recipes.rst:187 +msgid "Gzip Compression in Bottle" +msgstr "Gzip压缩" + +# cc030b164fa1422fbb0e7c605479a883 +#: ../../recipes.rst:190 +msgid "For a detailed discussion, see compression_" +msgstr "详见 compression_" + +# a0873b5a4e4c4c71937843850c69f371 +#: ../../recipes.rst:192 +msgid "" +"A common feature request is for Bottle to support Gzip compression, which " +"speeds up sites by compressing static resources (like CSS and JS files) " +"during a request." +msgstr "" +"Gzip压缩,可加速网站静态资源(例如CSS和JS文件)的访问。人们希望Bottle支持Gzip压" +"缩,(但是不支持)......" + +# 0cfc5b1cfe7b4f9a90907a25fd6655ca +#: ../../recipes.rst:194 +msgid "" +"Supporting Gzip compression is not a straightforward proposition, due to a " +"number of corner cases that crop up frequently. A proper Gzip implementation " +"must:" +msgstr "支持Gzip压缩并不简单,一个合适的Gzip实现应该满足以下条件。" + +# 43396b35b1eb43d0875bc745e4adbb6e +#: ../../recipes.rst:196 +msgid "Compress on the fly and be fast doing so." +msgstr "压缩速度要快" + +# 65c1fd4a55404e008c4a06f0666ab9a8 +#: ../../recipes.rst:197 +msgid "Do not compress for browsers that don't support it." +msgstr "如果浏览器不支持,则不压缩" + +# 73e6653b779e443f9edfc0ec0bfffece +#: ../../recipes.rst:198 +msgid "Do not compress files that are compressed already (images, videos)." +msgstr "不压缩那些已经充分压缩的文件(图像,视频)" + +# b4c5eaedfa1843deb7bed64b690da0df +#: ../../recipes.rst:199 +msgid "Do not compress dynamic files." +msgstr "不压缩动态文件" + +# dcf512d9530e4c0a9f82b8b6acef1d99 +#: ../../recipes.rst:200 +msgid "Support two differed compression algorithms (gzip and deflate)." +msgstr "支持两种压缩算法(gzip和deflate)" + +# 8f7b2d1ea78c4c54ad76f0c6e45c4b2c +#: ../../recipes.rst:201 +msgid "Cache compressed files that don't change often." +msgstr "缓存那些不经常变化的压缩文件" + +# 6a123a9ffb9d404c97b6fe7148082cc8 +#: ../../recipes.rst:202 +msgid "De-validate the cache if one of the files changed anyway." +msgstr "" +"不验证缓存中那些已经变化的文件(De-validate the cache if one of the files " +"changed anyway)" + +# 31ba480ff2e64ac8809f2b5a8ba4d84f +#: ../../recipes.rst:203 +msgid "Make sure the cache does not get to big." +msgstr "确保缓存不太大" + +# 9cca12e96a2a46d1b0f50d0e191527a4 +#: ../../recipes.rst:204 +msgid "" +"Do not cache small files because a disk seek would take longer than on-the-" +"fly compression." +msgstr "不缓存小文件,因为寻道时间或许比压缩时间还长" + +# fd7d6ff9d37f43a48ccaf1153bb6abbf +#: ../../recipes.rst:206 +msgid "" +"Because of these requirements, it is the recommendation of the Bottle " +"project that Gzip compression is best handled by the WSGI server Bottle runs " +"on top of. WSGI servers such as cherrypy_ provide a GzipFilter_ middleware " +"that can be used to accomplish this." +msgstr "" +"因为有上述种种限制,建议由WSGI服务器来处理Gzip压缩而不是Bottle。像 cherrypy_ " +"就提供了一个 GzipFilter_ 中间件来处理Gzip压缩。" + +# fa5e82e498e34c77bf4ce53402982640 +#: ../../recipes.rst:210 +msgid "Using the hooks plugin" +msgstr "使用钩子" + +# 69f3eb65c7424b8fa5fafc5bbd19c280 +#: ../../recipes.rst:212 +msgid "" +"For example, if you want to allow Cross-Origin Resource Sharing for the " +"content returned by all of your URL, you can use the hook decorator and " +"setup a callback function::" +msgstr "例如,你想提供跨域资源共享,可参考下面的例子。" + +# 27f25eeca0c140c881b5a82396063aaa +#: ../../recipes.rst:230 +msgid "" +"You can also use the ``before_request`` to take an action before every " +"function gets called." +msgstr "" +"你也可以使用 ``before_request`` ,这样在route的回调函数被调用之前,都会调用你" +"的钩子函数。" + +# 5882be32dd4040c8a642ff5f40a20229 +#: ../../recipes.rst:235 +msgid "Using Bottle with Heroku" +msgstr "在Heroku中使用Bottle" + +# 2800373fd0754dc4adc7ebbb487dcdc3 +#: ../../recipes.rst:237 +msgid "" +"Heroku_, a popular cloud application platform now provides support for " +"running Python applications on their infastructure." +msgstr "Heroku_ ,一个流行的云应用平台,提供Python支持。" + +# 6aa7d15dbd67437aad2028d56dae34f7 +#: ../../recipes.rst:240 +msgid "" +"This recipe is based upon the `Heroku Quickstart `_, with Bottle specific code replacing the `Write " +"Your App `_ " +"section of the `Getting Started with Python on Heroku/Cedar `_ guide::" +msgstr "" +"这份教程基于 `Heroku Quickstart `_, 用Bottle特有的代码替换了 `Getting Started with Python on " +"Heroku/Cedar `_ 中的`Write Your " +"App `_ 这部分::" + +# 526acffa7fd4482db514db6e6da16ee5 +#: ../../recipes.rst:256 +msgid "" +"Heroku's app stack passes the port that the application needs to listen on " +"for requests, using the `os.environ` dictionary." +msgstr "Heroku使用 `os.environ` 字典来提供Bottle应用需要监听的端口。" diff -Nru python-bottle-0.11.6/docs/_locale/zh_CN/routing.po python-bottle-0.12.0/docs/_locale/zh_CN/routing.po --- python-bottle-0.11.6/docs/_locale/zh_CN/routing.po 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/docs/_locale/zh_CN/routing.po 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,365 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) 2009-2012, Marcel Hellkamp +# This file is distributed under the same license as the Bottle package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Bottle 0.12-dev\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-08-09 17:22\n" +"PO-Revision-Date: 2012-11-09 16:09+0800\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +# 537f3d5bfa4d4be08a712f4f7175e73a +#: ../../routing.rst:3 +msgid "Request Routing" +msgstr "URL映射" + +# 38a02f16d2ac46c8ad2167320cb71856 +#: ../../routing.rst:5 +msgid "" +"Bottle uses a powerful routing engine to find the right callback for each " +"request. The :ref:`tutorial ` shows you the basics. This " +"document covers advanced techniques and rule mechanics in detail." +msgstr "" +"Bottle内置一个强大的route引擎,可以给每个浏览器请求找到正确的回调函数。 :ref:" +"`tutorial ` 中已经介绍了一些基础知识。接下来是一些进阶知识" +"和route的规则。" + +# d5bcbcf2c51c4aed93a005830610b16e +#: ../../routing.rst:8 +msgid "Rule Syntax" +msgstr "route的语法" + +# 5731b172abca42c18ddae8b9338c0db8 +#: ../../routing.rst:10 +msgid "" +"The :class:`Router` distinguishes between two basic types of routes: " +"**static routes** (e.g. ``/contact``) and **dynamic routes** (e.g. ``/hello/" +"``). A route that contains one or more *wildcards* it is considered " +"dynamic. All other routes are static." +msgstr "" +":class:`Router` 类中明确区分两种类型的route: **静态route** (例如 ``/" +"contact`` )和 **动态route** (例如 ``/hello/`` )。包含了 *通配符* 的" +"route即是动态route,除此之外的都是静态的。" + +# 4fb306e63b844e86b7bd02f84f79496c +#: ../../routing.rst:14 +msgid "" +"The simplest form of a wildcard consists of a name enclosed in angle " +"brackets (e.g. ````). The name should be unique for a given route and " +"form a valid python identifier (alphanumeric, starting with a letter). This " +"is because wildcards are used as keyword arguments for the request callback " +"later." +msgstr "" +"包含通配符,最简单的形式就是将其放到一对<>里面(例如 ```` )。在同一个" +"route里面,这个变量名需要是唯一的。因为稍后会将其当作参数传给回调函数,所以这" +"个变量名的第一个字符应该是字母。" + +# 8f5cfd74cc954f25a6343efe2af186f2 +#: ../../routing.rst:16 +msgid "" +"Each wildcard matches one or more characters, but stops at the first slash " +"(``/``). This equals a regular expression of ``[^/]+`` and ensures that only " +"one path segment is matched and routes with more than one wildcard stay " +"unambiguous." +msgstr "" +"每一个通配符匹配一个或多个字符,直到遇到 ``/`` 。类似于 ``[^/]+`` 这样一个正" +"则表达式,确保在route包含多个通配符的时候不出现歧义。" + +# 4995515dd3614738adead1dfdc1e21d1 +#: ../../routing.rst:18 +msgid "The rule ``//`` matches as follows:" +msgstr "``//`` 这个规则匹配的情况如下" + +# 360827cedc9d41e780960b5898bb411a +#: ../../routing.rst:21 +msgid "Path" +msgstr "路径" + +# 936e7668dd0d428c969ba695167d7ad0 +#: ../../routing.rst:21 +msgid "Result" +msgstr "结果" + +# 6cb05a32a5ba4c9c80fccf2ebf3feb55 +#: ../../routing.rst:23 +msgid "/save/123" +msgstr "" + +# db0ca094c764454ba849802125c154d0 +#: ../../routing.rst:23 +msgid "``{'action': 'save', 'item': '123'}``" +msgstr "" + +# 07aed175dbd64f62b841c4a0641efd4a +#: ../../routing.rst:24 +msgid "/save/123/" +msgstr "" + +# b13e940c425e4a7fb9862bff885e1379 +# 4edcee5dd1104375afb1609664f60df6 +# dcc8aeb405894ddf8386b936b2758388 +#: ../../routing.rst:24 ../../routing.rst:25 ../../routing.rst:26 +msgid "`No Match`" +msgstr "不匹配" + +# e9c41614ba83410f9ac0ceaea8c6a162 +#: ../../routing.rst:25 +msgid "/save/" +msgstr "" + +# bb2bc503fab04bd1bf9df0cb0dbce8e5 +#: ../../routing.rst:26 +msgid "//123" +msgstr "" + +# c4f0ba8b334445cbb018b7df7a08ff82 +#: ../../routing.rst:29 +msgid "" +"You can change the exact behaviour in many ways using filters. This is " +"described in the next section." +msgstr "你可通过过滤器来改变这一行为,稍后会介绍。" + +# da4ca1ab94694467b37e1ccae2f43873 +#: ../../routing.rst:32 +msgid "Wildcard Filters" +msgstr "通配符过滤器" + +# 841d41d86e4848a49c1adddb668a0eac +#: ../../routing.rst:36 +msgid "" +"Filters are used to define more specific wildcards, and/or transform the " +"matched part of the URL before it is passed to the callback. A filtered " +"wildcard is declared as ```` or ````. The " +"syntax for the optional config part depends on the filter used." +msgstr "" +"过滤器被用于定义更特殊的通配符,可在URL中\"被匹配到的部分\"被传递给回调函数之" +"前,处理其内容。可通过 ```` 或 ```` 这样的语" +"句来声明一个过滤器。\"config\"部分的语法由被使用的过滤器决定。" + +# 4546a3f376d6472299ea23de51c86fb2 +#: ../../routing.rst:38 +msgid "The following standard filters are implemented:" +msgstr "Bottle中已实现以下过滤器:" + +# 9649286b48c846909d6837918e4afe22 +#: ../../routing.rst:40 +msgid "**:int** matches (signed) digits and converts the value to integer." +msgstr "**:int** 匹配一个整形数,并将其转换为int" + +# 1fd36dafc30a444294ef178e778a6c9b +#: ../../routing.rst:41 +msgid "**:float** similar to :int but for decimal numbers." +msgstr "**:float** 同上,匹配一个浮点数" + +# 44c9df4f4cda41fabd0dd204d6ef6ccb +#: ../../routing.rst:42 +msgid "" +"**:path** matches all characters including the slash character in a non-" +"greedy way and may be used to match more than one path segment." +msgstr "**:path** 匹配所有字符,包括'/'" + +# 6d04d52e808847ddbc4856bcd9c83741 +#: ../../routing.rst:43 +msgid "" +"**:re[:exp]** allows you to specify a custom regular expression in the " +"config field. The matched value is not modified." +msgstr "**:re[:exp]** 允许在exp中写一个正则表达式" + +# a60af85c82874c5e960dd90455b2882e +#: ../../routing.rst:45 +msgid "" +"You can add your own filters to the router. All you need is a function that " +"returns three elements: A regular expression string, a callable to convert " +"the URL fragment to a python value, and a callable that does the opposite. " +"The filter function is called with the configuration string as the only " +"parameter and may parse it as needed::" +msgstr "" +"你可在route中添加自己写的过滤器。过滤器是一个有三个返回值的函数:一个正则表达" +"式,一个callable的对象(转换URL片段为Python对象),另一个callable对象(转换" +"Python对象为URL片段)。过滤器仅接受一个参数,就是设置字符串(译者注:例如re过滤" +"器的exp部分)。" + +# f92df6b1308c4b03856c4a086a7f2dd1 +#: ../../routing.rst:71 +msgid "Legacy Syntax" +msgstr "旧语法" + +# b105532cd9db4a2d81e6f7dd0d0f9f52 +#: ../../routing.rst:75 +msgid "" +"The new rule syntax was introduce in **Bottle 0.10** to simplify some common " +"use cases, but the old syntax still works and you can find lot code examples " +"still using it. The differences are best described by example:" +msgstr "" +"在 **Bottle 0.10** 版本中引入了新的语法,来简单化一些常见用例,但依然兼容旧的" +"语法。新旧语法的区别如下。" + +# 0f54e0bcc13c4c779b5c463dc38e9764 +#: ../../routing.rst:78 +msgid "Old Syntax" +msgstr "旧语法" + +# 8d2fdc1e4e31450d939aa14c9b6ec038 +#: ../../routing.rst:78 +msgid "New Syntax" +msgstr "新语法" + +# dfcd81acea5746aaa54619b1869735a3 +#: ../../routing.rst:80 +msgid "``:name``" +msgstr "" + +# 0fc15b4c779d418a9bb3491821d15bbf +#: ../../routing.rst:80 +msgid "````" +msgstr "" + +# 6844e4035cbe487397c7d1ce0daaa376 +#: ../../routing.rst:81 +msgid "``:name#regexp#``" +msgstr "" + +# 578c280850204789b9ac06383e5c6835 +#: ../../routing.rst:81 +msgid "````" +msgstr "" + +# 1e17245e5d634d658365fef94c51b494 +#: ../../routing.rst:82 +msgid "``:#regexp#``" +msgstr "" + +# 4927c487703e4e4a81e3e16d4e0d17e7 +#: ../../routing.rst:82 +msgid "``<:re:regexp>``" +msgstr "" + +# 6788154d67da4210ba2a49d9f4d27a8c +#: ../../routing.rst:83 +msgid "``:##``" +msgstr "" + +# 7c26c9d95ce14f6c8412d5809de5928d +#: ../../routing.rst:83 +msgid "``<:re>``" +msgstr "" + +# 2f5886822d674eb9a42febdb5872a30f +#: ../../routing.rst:86 +msgid "" +"Try to avoid the old syntax in future projects if you can. It is not " +"currently deprecated, but will be eventually." +msgstr "请尽量在新项目中避免使用旧的语法,虽然它现在还没被废弃,但终究会的。" + +# 37c609a0f4764f848e31917094d031be +#: ../../routing.rst:91 +msgid "Explicit routing configuration" +msgstr "显式的route配置" + +# 77437235365e4d40943f7fa62801f7c1 +#: ../../routing.rst:93 +msgid "" +"Route decorator can also be directly called as method. This way provides " +"flexibility in complex setups, allowing you to directly control, when and " +"how routing configuration done." +msgstr "" +"route修饰器也可以直接当作函数来调用。在复杂的部署中,这种方法或许更灵活,直接" +"由你来控制“何时”及“如何”配置route。" + +# 499e79b080ea49afbe682e5b737f8674 +#: ../../routing.rst:95 +msgid "" +"Here is a basic example of explicit routing configuration for default bottle " +"application::" +msgstr "下面是一个简单的例子" + +# 6b60a336206e4c7dabf70f7cceca7a30 +#: ../../routing.rst:101 +msgid "" +"In fact, any :class:`Bottle` instance routing can be configured same way::" +msgstr "实际上,bottle可以是任何 :class:`Bottle` 类的实例" + +# b368ae000c2a471c859da22a34176591 +#~ msgid "Routing Order" +#~ msgstr "route的顺序 (URL映射的顺序)" + +# 9b457321443a4d62b7751efd260d21a9 +#~ msgid "" +#~ "With the power of wildcards and regular expressions it is possible to " +#~ "define overlapping routes. If multiple routes match the same URL, things " +#~ "get a bit tricky. To fully understand what happens in this case, you need " +#~ "to know in which order routes are checked by the router." +#~ msgstr "" +#~ "在通配符和正则表达式的支持下,我们是可以定义重叠的route的。如果多个route匹" +#~ "配同一个URL,它们的行为也许会变得难以琢磨。为了了解这里面究竟发生了什么事" +#~ "情,你需要了解route被执行的顺序。(译者注:router会检查route的顺序)" + +# 992fd1ac2f7047c5944584ce8b539ddd +#~ msgid "" +#~ "First you should know that routes are grouped by their path rule. Two " +#~ "routes with the same path rule but different methods are grouped together " +#~ "and the first route determines the position of both routes. Fully " +#~ "identical routes (same path rule and method) replace previously defined " +#~ "routes, but keep the position of their predecessor." +#~ msgstr "" +#~ "首先,route是按照它们的路径规则来分组的。两个规则相同但回调函数不同的route" +#~ "分到同一组,第一个route决定这两个route的位置。如果两个route完全相同(同样的" +#~ "规则,同样的回调函数),则先定义的route会被后来的route替换掉,但它们的先后" +#~ "顺序会被保留下来。" + +# 105f6ae2a6a8429db8f4acc8d2d0609a +#~ msgid "" +#~ "Static routes are checked first. This is mostly for performance reasons " +#~ "and can be switched off, but is currently the default. If no static route " +#~ "matches the request, the dynamic routes are checked in the order they " +#~ "were defined. The first hit ends the search. If no rule matched, a \"404 " +#~ "Page not found\" error is returned." +#~ msgstr "" +#~ "基于性能考虑,默认先查找静态route,这个默认设置可以被改掉。如果没有静态" +#~ "route匹配浏览器请求,则会按route被定义的顺序,去查找动态route,只要找到一" +#~ "个匹配的动态route,便不会继续查找。如果也找不到匹配请求的动态route,则返回" +#~ "一个404错误。" + +# 5be98f36dfec4d3d84562510d59569bf +#~ msgid "" +#~ "In a second step, the request method is checked. If no exact match is " +#~ "found, and the request method is HEAD, the router checks for a GET route. " +#~ "Otherwise, it checks for an ANY route. If that fails too, a \"405 Method " +#~ "not allowed\" error is returned." +#~ msgstr "" +#~ "第二步,会检查浏览器请求的HTTP方法。如果不能精确匹配,且浏览器发的是HEAD请" +#~ "求,那个router会按照GET方法去查找相应的route,否则便按照ANY方法去查找" +#~ "route。如果都失败了,则返回一个405错误。" + +# 9e5a42e18b2949a2b91e3f7b929318dd +#~ msgid "Here is an example where this might bite you::" +#~ msgstr "下面这个例子也许会令你迷惑" + +# 9da489b5d4d94eeba231d11e48577619 +#~ msgid "" +#~ "The second route will never hit. Even POST requests don't arrive at the " +#~ "second route because the request method is checked in a separate step. " +#~ "The router stops at the first route which matches the request path, then " +#~ "checks for a valid request method, can't find one and raises a 405 error." +#~ msgstr "" +#~ "第二个route永远不会被命中,因为第一个route已经能匹配该URL,所以router会在" +#~ "查找到第一个route后停止查找,接着按照浏览器请求的HTTP方法来查找,如果找不" +#~ "到则返回405错误。" + +# 99ce58b0d94d48eba1fe52fc4e9a2b2d +#~ msgid "" +#~ "Sounds complicated, and it is. That is the price for performance. It is " +#~ "best to avoid ambiguous routes at all and choose unique prefixes for each " +#~ "route. This implementation detail may change in the future, though. We " +#~ "are working on it." +#~ msgstr "" +#~ "看起来挺复杂的,确实很复杂。这是为了性能而付出的代价。最好是避免创建容易造" +#~ "成歧义的route。将来或许会改变route实现的细节,我们在慢慢改善中。" diff -Nru python-bottle-0.11.6/docs/_locale/zh_CN/stpl.po python-bottle-0.12.0/docs/_locale/zh_CN/stpl.po --- python-bottle-0.11.6/docs/_locale/zh_CN/stpl.po 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/docs/_locale/zh_CN/stpl.po 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,350 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) 2009-2012, Marcel Hellkamp +# This file is distributed under the same license as the Bottle package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Bottle 0.12-dev\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-08-09 17:22\n" +"PO-Revision-Date: 2013-04-20 16:43+0800\n" +"Last-Translator: \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.5.5\n" + +# 5fc6bab7b7204b6ca1f300b3b00efa24 +#: ../../stpl.rst:3 +msgid "SimpleTemplate Engine" +msgstr "SimpleTemplate 模板引擎" + +# 2d5c4dee0d97442daf778fcc0790930d +#: ../../stpl.rst:7 +msgid "" +"Bottle comes with a fast, powerful and easy to learn built-in template " +"engine called *SimpleTemplate* or *stpl* for short. It is the default engine " +"used by the :func:`view` and :func:`template` helpers but can be used as a " +"stand-alone general purpose template engine too. This document explains the " +"template syntax and shows examples for common use cases." +msgstr "" +"Bottle自带了一个快速,强大,易用的模板引擎,名为 *SimpleTemplate* 或简称为 " +"*stpl* 。它是 :func:`view` 和 :func:`template` 两个函数默认调用的模板引擎。接" +"下来会介绍该引擎的模板语法和一些常见用例。" + +# a3590cf972a44a07996a3cffabbaaf17 +#: ../../stpl.rst:10 +msgid "Basic API Usage:" +msgstr "基础API :" + +# 2957a430c3f0401cb93c6a495696ee0f +#: ../../stpl.rst:11 +msgid ":class:`SimpleTemplate` implements the :class:`BaseTemplate` API::" +msgstr ":class:`SimpleTemplate` 类实现了 :class:`BaseTemplate` 接口" + +# 76093537f2404ef1bed6a7669a33ea85 +#: ../../stpl.rst:18 +msgid "" +"In this document we use the :func:`template` helper in examples for the sake " +"of simplicity::" +msgstr "简单起见,我们在例子中使用 :func:`template` 函数" + +# f8681cd955714e8689971c9d04ca50db +#: ../../stpl.rst:24 +msgid "" +"Just keep in mind that compiling and rendering templates are two different " +"actions, even if the :func:`template` helper hides this fact. Templates are " +"usually compiled only once and cached internally, but rendered many times " +"with different keyword arguments." +msgstr "" +"注意,编译模板和渲染模板是两件事情,尽管 :func:`template` 函数隐藏了这一事" +"实。通常,模板只会被编译一次,然后会被缓存起来,但是会根据不同的参数,被多次" +"渲染。" + +# dbbbb8f7a9f44a509c6679a8530ded31 +#: ../../stpl.rst:27 +msgid ":class:`SimpleTemplate` Syntax" +msgstr ":class:`SimpleTemplate` 的语法" + +# ceece3998fa24734ae64c9830b09a271 +#: ../../stpl.rst:29 +msgid "" +"Python is a very powerful language but its whitespace-aware syntax makes it " +"difficult to use as a template language. SimpleTemplate removes some of " +"these restrictions and allows you to write clean, readable and maintainable " +"templates while preserving full access to the features, libraries and speed " +"of the Python language." +msgstr "" +"虽然Python是一门强大的语言,但它对空白敏感的语法令其很难作为一个模板语言。" +"SimpleTemplate移除了一些限制,允许你写出干净的,有可读性的,可维护的模板,且" +"保留了Python的强大功能。" + +# 5a7cdb21e3fc428880cf986470fc17b8 +#: ../../stpl.rst:33 +msgid "" +"The :class:`SimpleTemplate` syntax compiles directly to python bytecode and " +"is executed on each :meth:`SimpleTemplate.render` call. Do not render " +"untrusted templates! They may contain and execute harmful python code." +msgstr "" +" :class:`SimpleTemplate` 模板会被编译为Python字节码,且在每次通过 :meth:" +"`SimpleTemplate.render` 渲染的时候执行。请不要渲染不可靠的模板!它们也许包含" +"恶意代码。" + +# a95aa9022b2d4506aa82abe27d1a6c54 +#: ../../stpl.rst:36 +msgid "Inline Expressions" +msgstr "内嵌表达式" + +# f6b4616dd997461dbbc1ef9592dd8c0c +#: ../../stpl.rst:38 +msgid "" +"You already learned the use of the ``{{...}}`` syntax from the \"Hello World!" +"\" example above, but there is more: any python expression is allowed within " +"the curly brackets as long as it returns a string or something that has a " +"string representation::" +msgstr "" +"你已经在上面的\"Hello World!\"例子中学习到了 ``{{...}}`` 语句的用法。只要在 " +"``{{...}}`` 中的Python语句返回一个字符串或有一个字符串的表达形式,它就是一个" +"有效的语句。" + +# af95d092b454488a870691b150c8d99b +#: ../../stpl.rst:47 +msgid "" +"The contained python expression is executed at render-time and has access to " +"all keyword arguments passed to the :meth:`SimpleTemplate.render` method. " +"HTML special characters are escaped automatically to prevent `XSS `_ attacks. You can start the " +"expression with an exclamation mark to disable escaping for that expression::" +msgstr "" +"{{}}中的Python语句会在渲染的时候被执行,可访问传递给 :meth:`SimpleTemplate." +"render` 方法的所有参数。默认情况下,自动转义HTML标签以防止 `XSS `_ 攻击。可在语句前加上\"!\"来关闭自" +"动转义。" + +# 219189873cc441e6b70064bac98d4269 +#: ../../stpl.rst:57 +msgid "Embedded python code" +msgstr "嵌入Pyhton代码" + +# 219eaf58440a432d822e7ae0c7d34856 +#: ../../stpl.rst:59 +msgid "" +"The ``%`` character marks a line of python code. The only difference between " +"this and real python code is that you have to explicitly close blocks with " +"an ``%end`` statement. In return you can align the code with the surrounding " +"template and don't have to worry about correct indentation of blocks. The " +"*SimpleTemplate* parser handles that for you. Lines *not* starting with a ``" +"%`` are rendered as text as usual::" +msgstr "" +"一行以 ``%`` 开头,表明这一行是Python代码。它和真正的Python代码唯一的区别,在" +"于你需要显式地在末尾添加 ``%end`` 语句,表明一个代码块结束。这样你就不必担心" +"Python代码中的缩进问题, *SimpleTemplate* 模板引擎的parser帮你处理了。不以 ``" +"%`` 开头的行,被当作普通文本来渲染::" + +# 835cfd3f9abb473295acd970b1d4db48 +#: ../../stpl.rst:67 +msgid "" +"The ``%`` character is only recognised if it is the first non-whitespace " +"character in a line. To escape a leading ``%`` you can add a second one. ``%" +"%`` is replaced by a single ``%`` in the resulting template::" +msgstr "只有在行首的 ``%`` 字符才有意义,可以使用 ``%%`` 来转义。" + +# 186f77670bf845e88d2b1e2b9cc088e2 +#: ../../stpl.rst:74 +msgid "Suppressing line breaks" +msgstr "防止换行" + +# ae704a6087814ba783495f1313adccb2 +#: ../../stpl.rst:76 +msgid "" +"You can suppress the line break in front of a code-line by adding a double " +"backslash at the end of the line::" +msgstr "你可以在一行代码前面加上 ``\\`` 来防止换行 ::" + +# 6a8217b810154fd49c6953739042465b +#: ../../stpl.rst:84 +msgid "This template produces the following output::" +msgstr "该模板的输出::" + +# 47b3b914fe874add85a570309194581b +#: ../../stpl.rst:89 +msgid "The ``%include`` Statement" +msgstr "``%include`` 语句" + +# e7434e79b2724e0aba6628a54f4805c2 +#: ../../stpl.rst:91 +msgid "" +"You can include other templates using the ``%include sub_template [kwargs]`` " +"statement. The ``sub_template`` parameter specifies the name or path of the " +"template to be included. The rest of the line is interpreted as a comma-" +"separated list of ``key=statement`` pairs similar to keyword arguments in " +"function calls. They are passed to the sub-template analogous to a :meth:" +"`SimpleTemplate.render` call. The ``**kwargs`` syntax for passing a dict is " +"allowed too::" +msgstr "" +"你可以使用 ``%include sub_template [kwargs]`` 语句来包含其他模板。 " +"``sub_template`` 参数是模板的文件名或路径。 ``[kwargs]`` 部分是以逗号分开的键" +"值对,是传给其他模板的参数。 ``**kwargs`` 这样的语法来传递一个字典也是允许" +"的。" + +# 335f7d7ba9d54925848f7ab73133604d +#: ../../stpl.rst:98 +msgid "The ``%rebase`` Statement" +msgstr "``%rebase`` 语句" + +# febe4bbe39794c80b091f79785cc296b +#: ../../stpl.rst:100 +msgid "" +"The ``%rebase base_template [kwargs]`` statement causes ``base_template`` to " +"be rendered instead of the original template. The base-template then " +"includes the original template using an empty ``%include`` statement and has " +"access to all variables specified by ``kwargs``. This way it is possible to " +"wrap a template with another template or to simulate the inheritance feature " +"found in some other template engines." +msgstr "" +"``%rebase base_template [kwargs]`` 语句会渲染 ``base_template`` 这个模板,而" +"不是原先的模板。然后base_template中使用一个空 ``%include`` 语句来包含原先的模" +"板,并可访问所有通过 ``kwargs`` 传过来的参数。这样就可以使用模板来封装另一个" +"模板,或者是模拟某些模板引擎中的继承机制。" + +# 8ef160400e504cbfabc0c5d6f9992175 +#: ../../stpl.rst:102 +msgid "" +"Let's say you have a content template and want to wrap it with a common HTML " +"layout frame. Instead of including several header and footer templates, you " +"can use a single base-template to render the layout frame." +msgstr "" +"让我们假设,你现在有一个与内容有关的模板,想在它上面加上一层普通的HTML层。为" +"了避免include一堆模板,你可以使用一个基础模板。" + +# 7ad4a7d8bf22490c8c84d8c963eb6c0f +#: ../../stpl.rst:104 +msgid "Base-template named ``layout.tpl``::" +msgstr "名为 ``layout.tpl`` 的基础模板::" + +# 9879a17dc3e545fd95469706cb53f265 +#: ../../stpl.rst:115 +msgid "Main-template named ``content.tpl``::" +msgstr "名为 ``content.tpl`` 的主模板" + +# cfcf68af997a4c0db33ab9ea5b5e797a +#: ../../stpl.rst:120 +msgid "Now you can render ``content.tpl``:" +msgstr "渲染 ``content.tpl``" + +# d233dcb3a966484887e6ad8887c8588f +#: ../../stpl.rst:137 +msgid "" +"A more complex scenario involves chained rebases and multiple content " +"blocks. The ``block_content.tpl`` template defines two functions and passes " +"them to a ``columns.tpl`` base template::" +msgstr "" +"一个更复杂的使用场景involves chained rebases and multiple content blocks. " +"``block_content.tpl`` 模板定义了两个函数,然后将它们传给 ``columns.tpl`` 这个" +"基础模板。" + +# 090e914a15304125b733012a3e3fae5b +#: ../../stpl.rst:147 +msgid "" +"The ``columns.tpl`` base-template uses the two callables to render the " +"content of the left and right column. It then wraps itself with the ``layout." +"tpl`` template defined earlier::" +msgstr "" +"``columns.tpl`` 这个基础模板使用两个callable(译者注:Python中除了函数是" +"callable的,类也可以是callable的,在这个例子里,是函数)来渲染分别位于左边和右" +"边的两列。然后将其自身封装在之前定义的 ``layout.tpl`` 模板里面。" + +# 3e003ecb08ac4ebbb458ce62560fbacd +#: ../../stpl.rst:157 +msgid "Lets see how ``block_content.tpl`` renders:" +msgstr "让我们看一看 ``block_content.tpl`` 模板的输出" + +# 567b6630a554497e8cc365713174f327 +#: ../../stpl.rst:180 +msgid "Namespace Functions" +msgstr "模板内置函数 (Namespace Functions)" + +# 009fc91a499645c59e164feb6071b248 +#: ../../stpl.rst:182 +msgid "" +"Accessing undefined variables in a template raises :exc:`NameError` and " +"stops rendering immediately. This is standard python behavior and nothing " +"new, but vanilla python lacks an easy way to check the availability of a " +"variable. This quickly gets annoying if you want to support flexible inputs " +"or use the same template in different situations. SimpleTemplate helps you " +"out here: The following three functions are defined in the default namespace " +"and accessible from anywhere within a template:" +msgstr "" +"在模板中访问一个未定义的变量会导致 :exc:`NameError` 异常,并立即终止模板的渲" +"染。这是Python的正常行为,并不奇怪。在抛出异常之前,你无法检查变量是否被定" +"义。这在你想让输入更灵活,或想在不同情况下使用同一个模板的时候,就很烦人了。" +"SimpleTemplate模板引擎内置了三个函数来帮你解决这个问题,可以在模板的任何地方" +"使用它们。" + +# 51e90c2ce045474e87e5572855d05b09 +#: ../../stpl.rst:194 +msgid "" +"Return True if the variable is defined in the current template namespace, " +"False otherwise." +msgstr "如果变量已定义则返回True,反之返回False。" + +# a5092292ca484cc4b5ddcdedd084c3ce +#: ../../stpl.rst:199 +msgid "Return the variable, or a default value." +msgstr "返回该变量,或一个默认值" + +# df4a180859de40b3992e693b92335898 +#: ../../stpl.rst:203 +msgid "" +"If the variable is not defined, create it with the given default value. " +"Return the variable." +msgstr "如果该变量未定义,则定义它,赋一个默认值,返回该变量" + +# 99ab3af3116143cb81482d94e2765d4f +#: ../../stpl.rst:206 +msgid "" +"Here is an example that uses all three functions to implement optional " +"template variables in different ways::" +msgstr "下面是使用了这三个函数的例子,实现了模板中的可选参数。" + +# 9d5e28dff3aa46608cf5025c2a4da88b +#: ../../stpl.rst:220 +msgid ":class:`SimpleTemplate` API" +msgstr ":class:`SimpleTemplate` API" + +# ba13c2fdbe9d454282446d03080fb37b +#: ../../../bottle.py:docstring of bottle.SimpleTemplate.render:1 +msgid "Render the template using keyword arguments as local variables." +msgstr "" + +# 49cff8297b4f4092914eae820141d229 +#: ../../stpl.rst:226 +msgid "Known bugs" +msgstr "已知Bug" + +# ca8cb753300042ed8d4dd7d554c04924 +#: ../../stpl.rst:228 +msgid "" +"Some syntax constructions allowed in python are problematic within a " +"template. The following syntaxes won't work with SimpleTemplate:" +msgstr "不兼容某些Python语法,例子如下:" + +# fe81e27342e04c18b17a9f1fdb7eacb8 +#: ../../stpl.rst:230 +msgid "" +"Multi-line statements must end with a backslash (``\\``) and a comment, if " +"present, must not contain any additional ``#`` characters." +msgstr "" +"多行语句语句必须以 ``\\`` 结束, 如果出现了注释, 则不能再包含其他 ``#`` 字符." + +# 404c1aa1c5d4489688aaeeeb8abfdff1 +#: ../../stpl.rst:231 +msgid "Multi-line strings are not supported yet." +msgstr "不支持多行字符串" + +# 1db7677ae77c44f4ae0d6e63772af22e +#~ msgid "Removes comments (#...) from python code." +#~ msgstr "从python代码中去除注释(#...)" diff -Nru python-bottle-0.11.6/docs/_locale/zh_CN/tutorial.po python-bottle-0.12.0/docs/_locale/zh_CN/tutorial.po --- python-bottle-0.11.6/docs/_locale/zh_CN/tutorial.po 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/docs/_locale/zh_CN/tutorial.po 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,2088 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) 2009-2012, Marcel Hellkamp +# This file is distributed under the same license as the Bottle package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Bottle 0.12-dev\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-08-09 18:12\n" +"PO-Revision-Date: 2013-08-09 17:27+0800\n" +"Last-Translator: \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.5.7\n" + +# 2cfce930fec043468539792502c72326 +#: ../../tutorial.rst:24 +msgid "Tutorial" +msgstr "教程" + +# 0c236f89c90b4a3a9a21281e710524c0 +#: ../../tutorial.rst:26 +msgid "" +"This tutorial introduces you to the concepts and features of the Bottle web " +"framework and covers basic and advanced topics alike. You can read it from " +"start to end, or use it as a reference later on. The automatically " +"generated :doc:`api` may be interesting for you, too. It covers more " +"details, but explains less than this tutorial. Solutions for the most common " +"questions can be found in our :doc:`recipes` collection or on the :doc:`faq` " +"page. If you need any help, join our `mailing list `_ or visit us in our `IRC channel `_." +msgstr "" +"这份教程将向你介绍Bottle的开发理念和功能特性。既介绍Bottle的基本用法,也包含" +"了进阶用法。你可以从头到尾通读一遍,也可当做开发时的参考。你也许对自动生成" +"的 :doc:`api` 感兴趣。它包含了更多的细节,但解释没有这份教程详细。在 :doc:" +"`recipes` 或 :doc:`faq` 可找到常见问题的解决办法。如果需要任何帮助,可加入我" +"们的 `邮件列表 `_ 或在 `IRC频道 `_ 和我们交流。" + +# 0ec6fe51620140ad9382936c9de05314 +#: ../../tutorial.rst:31 +msgid "Installation" +msgstr "安装" + +# 568892e9dee44a7e9037426bf4d0aee0 +#: ../../tutorial.rst:33 +msgid "" +"Bottle does not depend on any external libraries. You can just download " +"`bottle.py `_ into your project directory and start coding:" +msgstr "" +"Bottle不依赖其他库,你需要做的仅是下载 `bottle.py `_ (开发版)到你" +"的项目文件夹,然后开始写代码。" + +# 00ba13db53314514a6c6f6af77210c46 +#: ../../tutorial.rst:39 +msgid "" +"This will get you the latest development snapshot that includes all the new " +"features. If you prefer a more stable environment, you should stick with the " +"stable releases. These are available on `PyPI `_ and can be installed via :command:`pip` (recommended), :command:" +"`easy_install` or your package manager:" +msgstr "" +"在终端运行以上命令,即可下载到Bottle的最新开发版,包含了所有新功能特性。如果" +"更需要稳定性,你应该坚持使用Bottle的稳定版本。可在 `PyPI `_ 下载稳定版本,然后通过 :command:`pip` (推荐), :command:" +"`easy_install` 或你的包管理软件安装。" + +# b99a73f45a24406dbde64204f2ceb385 +#: ../../tutorial.rst:47 +msgid "" +"Either way, you'll need Python 2.5 or newer (including 3.x) to run bottle " +"applications. If you do not have permissions to install packages system-wide " +"or simply don't want to, create a `virtualenv `_ first:" +msgstr "" +"你需要Python 2.5或以上版本(包括3.x)来运行bottle应用。如果你没有管理员权限或" +"你不想将Bottle安装为整个系统范围内可用,可先创建一个 `virtualenv `_ :" + +# 36a9cfdae7c3425ea112e9b4f4340db3 +#: ../../tutorial.rst:55 +msgid "Or, if virtualenv is not installed on your system:" +msgstr "如果还未安装virtualenv:" + +# 28ef5dd33f0f42da9dcbb4b808ff8ef6 +#: ../../tutorial.rst:67 +msgid "Quickstart: \"Hello World\"" +msgstr "" + +# 63ae84f2a3ec45ae994f1ad1fd3dca8b +#: ../../tutorial.rst:69 +msgid "" +"This tutorial assumes you have Bottle either :ref:`installed ` " +"or copied into your project directory. Let's start with a very basic \"Hello " +"World\" example::" +msgstr "" +"到目前为止,我假设你已经 :ref:`安装 ` 好了bottle或已将bottle.py" +"拷贝到你的项目文件夹。接下来我们就可以写一个非常简单的\"Hello World\"了::" + +# 56a3e1b859df44d8838a1f879dc6edef +#: ../../tutorial.rst:79 +msgid "" +"This is it. Run this script, visit http://localhost:8080/hello and you will " +"see \"Hello World!\" in your browser. Here is how it works:" +msgstr "" +"就这么简单!保存为py文件并执行,用浏览器访问 http://localhost:8080/hello 就可" +"以看到\"Hello World!\"。它的执行流程大致如下:" + +# 9de9930646be4df7ab8a12f9759574db +#: ../../tutorial.rst:81 +msgid "" +"The :func:`route` decorator binds a piece of code to an URL path. In this " +"case, we link the ``/hello`` path to the ``hello()`` function. This is " +"called a `route` (hence the decorator name) and is the most important " +"concept of this framework. You can define as many routes as you want. " +"Whenever a browser requests an URL, the associated function is called and " +"the return value is sent back to the browser. Its as simple as that." +msgstr "" +":func:`route` 函数将一段代码绑定到一个URL,在这个例子中, 我们将 ``hello()`` " +"函数绑定给了 ``/hello`` 。我们称之为 `route` (也是该修饰器的函数名) ,这是" +"Bottle框架最重要的开发理念。你可以根据需要定义任意多的 `route` 。在浏览器请求" +"一个URL的时候,框架自动调用与之相应的函数,接着将函数的返回值发送给浏览器。就" +"这么简单!" + +# 66de45a278fd457e9f68b2847b841118 +#: ../../tutorial.rst:83 +msgid "" +"The :func:`run` call in the last line starts a built-in development server. " +"It runs on ``localhost`` port ``8080`` and serves requests until you hit :" +"kbd:`Control-c`. You can switch the server backend later, but for now a " +"development server is all we need. It requires no setup at all and is an " +"incredibly painless way to get your application up and running for local " +"tests." +msgstr "" +"最后一行调用的 :func:`run` 函数启动了内置的开发服务器。它监听 `localhost` 的" +"8080端口并响应请求, :kbd:`Control-c` 可将其关闭。到目前为止,这个内置的开发" +"服务器已经足够用于日常的开发测试了。它根本不需要安装,就可以让你的应用跑起" +"来。在教程的后面,你将学会如何让你的应用跑在其他服务器上面(译者注:内置服务" +"器不能满足生产环境的要求)" + +# 58b30c8abcee451e80f9fc3d0b79d180 +#: ../../tutorial.rst:85 +msgid "" +"The :ref:`tutorial-debugging` is very helpful during early development, but " +"should be switched off for public applications. Keep that in mind." +msgstr "" +":ref:`tutorial-debugging` 在早期开发的时候非常有用,但请务必记得,在生产环境" +"中将其关闭。" + +# 717a9032a00a46b8b4845025571cafb4 +#: ../../tutorial.rst:87 +msgid "" +"Of course this is a very simple example, but it shows the basic concept of " +"how applications are built with Bottle. Continue reading and you'll see what " +"else is possible." +msgstr "" +"毫无疑问,这是一个十分简单例子,但它展示了用Bottle做应用开发的基本理念。接下" +"来你将了解到其他开发方式。" + +# 7c5ad76ca2ab4a3fbf06a891d59fc47b +#: ../../tutorial.rst:92 +msgid "The Default Application" +msgstr "`默认应用`" + +# ec04f7c314a04d51a1f5a5d7fa1585d0 +#: ../../tutorial.rst:94 +msgid "" +"For the sake of simplicity, most examples in this tutorial use a module-" +"level :func:`route` decorator to define routes. This adds routes to a global " +"\"default application\", an instance of :class:`Bottle` that is " +"automatically created the first time you call :func:`route`. Several other " +"module-level decorators and functions relate to this default application, " +"but if you prefer a more object oriented approach and don't mind the extra " +"typing, you can create a separate application object and use that instead of " +"the global one::" +msgstr "" +"基于简单性考虑,这份教程中的大部分例子都使用一个模块层面的 :func:`route` 修饰" +"器函数来定义route。这样的话,所有route都添加到了一个全局的“默认应用”里面,即" +"是在第一次调用 :func:`route` 函数时,创建的一个 :class:`Bottle` 类的实例。其" +"他几个模块层面的修饰器函数都与这个“默认应用”有关,如果你偏向于面向对象的做法" +"且不介意多打点字,你可以创建一个独立的应用对象,这样就可避免使用全局范围的“默" +"认应用”。" + +# b3de36e15f504e4099b98ad3421a8a3d +#: ../../tutorial.rst:106 +msgid "" +"The object-oriented approach is further described in the :ref:`default-app` " +"section. Just keep in mind that you have a choice." +msgstr "" +"接下来的 :ref:`default-app` 章节中将更详细地介绍这种做法。现在,你只需知道不" +"止有一种选择就好了。" + +# 3c4ef0c7652d427db62949755a6c40b3 +#: ../../tutorial.rst:114 +msgid "Request Routing" +msgstr "URL映射" + +# def96408b0aa4043965308a19be3984c +#: ../../tutorial.rst:116 +msgid "" +"In the last chapter we built a very simple web application with only a " +"single route. Here is the routing part of the \"Hello World\" example again::" +msgstr "" +"在上一章中,我们实现了一个十分简单的web应用,只有一个URL映射(route)。让我们再" +"来看一下“Hello World”中与routing有关的部分::" + +# 349b072faacd4906b20c28de17c17b2c +#: ../../tutorial.rst:122 +msgid "" +"The :func:`route` decorator links an URL path to a callback function, and " +"adds a new route to the :ref:`default application `. An " +"application with just one route is kind of boring, though. Let's add some " +"more::" +msgstr "" +":func:`route` 函数将一个URL路径与一个回调函数关联了起来,然后在 :ref:" +"`default application ` 中添加了一个URL映射(route)。但只有一" +"个route的应用未免太无聊了,让我们试着再添加几个route吧。::" + +# e0fcfc8632d74f1c829909f7ec493047 +#: ../../tutorial.rst:129 +msgid "" +"This example demonstrates two things: You can bind more than one route to a " +"single callback, and you can add wildcards to URLs and access them via " +"keyword arguments." +msgstr "" +"这个例子说明了两件事情,一个回调函数可绑定多个route,你也可以在URL中添加通配" +"符,然后在回调函数中使用它们。" + +# dabaff12e29b40abbd26c784abd18696 +#: ../../tutorial.rst:136 +msgid "Dynamic Routes" +msgstr "动态URL映射" + +# 988f03163d7b4112863628e580d3ec24 +#: ../../tutorial.rst:138 +msgid "" +"Routes that contain wildcards are called `dynamic routes` (as opposed to " +"`static routes`) and match more than one URL at the same time. A simple " +"wildcard consists of a name enclosed in angle brackets (e.g. ````) and " +"accepts one or more characters up to the next slash (``/``). For example, " +"the route ``/hello/`` accepts requests for ``/hello/alice`` as well as " +"``/hello/bob``, but not for ``/hello``, ``/hello/`` or ``/hello/mr/smith``." +msgstr "" +"包含通配符的route,我们称之为动态route(与之对应的是静态route),它能匹配多个" +"URL地址。一个通配符包含在一对尖括号里面(像这样 ```` ),通配符之间用\"/" +"\"分隔开来。如果我们将URL定义为 ``/hello/`` 这样,那么它就能匹配 ``/" +"hello/alice`` 和 ``/hello/bob`` 这样的浏览器请求,但不能匹配 ``/hello`` , ``/" +"hello/`` 和 ``/hello/mr/smith`` 。" + +# 3d1bccff797843218d755217b1a64025 +#: ../../tutorial.rst:140 +msgid "" +"Each wildcard passes the covered part of the URL as a keyword argument to " +"the request callback. You can use them right away and implement RESTful, " +"nice-looking and meaningful URLs with ease. Here are some other examples " +"along with the URLs they'd match::" +msgstr "" +"URL中的通配符都会当作参数传给回调函数,直接在回调函数中使用。这样可以漂亮地实" +"现RESTful形式的URL。例子如下::" + +# 39b80f89f2e24b88a48f4fde1f066d5f +#: ../../tutorial.rst:152 +msgid "" +"Filters are used to define more specific wildcards, and/or transform the " +"covered part of the URL before it is passed to the callback. A filtered " +"wildcard is declared as ```` or ````. The " +"syntax for the optional config part depends on the filter used." +msgstr "" +"过滤器(Filter)可被用来定义特殊类型的通配符,在传通配符给回调函数之前,先自动" +"转换通配符类型。包含过滤器的通配符定义一般像 ```` 或 ```` 这样。config部分是可选的,其语法由你使用的过滤器决定。" + +# f0f981dd9d6c485c88ceffbb7145caab +#: ../../tutorial.rst:154 +msgid "The following filters are implemented by default and more may be added:" +msgstr "已实现下面几种形式的过滤器,后续可能会继续添加:" + +# ea5726150090430fb51657407ba183c3 +#: ../../tutorial.rst:156 +msgid "" +"**:int** matches (signed) digits only and converts the value to integer." +msgstr "**:int** 匹配一个数字,自动将其转换为int类型。" + +# d6b0d5f1a9c241a6b29dec4e65e890d6 +#: ../../tutorial.rst:157 +msgid "**:float** similar to :int but for decimal numbers." +msgstr "**:float** 与:int类似,用于浮点数。" + +# b6a7efae1777408299795041cd226806 +#: ../../tutorial.rst:158 +msgid "" +"**:path** matches all characters including the slash character in a non-" +"greedy way and can be used to match more than one path segment." +msgstr "**:path** 匹配一个路径(包含\"/\")" + +# e84964d6d43f4fe1afae7ba6bc7032a0 +#: ../../tutorial.rst:159 +msgid "" +"**:re** allows you to specify a custom regular expression in the config " +"field. The matched value is not modified." +msgstr "**:re** 匹配config部分的一个正则表达式,不更改被匹配到的值" + +# 69650355e34d4716a450d9f712b88fd8 +#: ../../tutorial.rst:161 +msgid "Let's have a look at some practical examples::" +msgstr "让我们来看看具体的使用例子::" + +# f2d03c373c8a4ada93e344985fb6cee7 +#: ../../tutorial.rst:175 +msgid "You can add your own filters as well. See :doc:`Routing` for details." +msgstr "你可以添加自己的过滤器。详见 :doc:`routing` 。" + +# ce116c2df52344fc8ef6ab0dc85198fd +#: ../../tutorial.rst:179 +msgid "" +"The new rule syntax was introduced in **Bottle 0.10** to simplify some " +"common use cases, but the old syntax still works and you can find a lot of " +"code examples still using it. The differences are best described by example:" +msgstr "" +"从 **Bottle 0.10** 版本开始,可以用新的语法来在URL中定义通配符,更简单了。新" +"旧语法之间的对比如下:" + +# 4f170d5d120f4cb0a5576bcc352b6e81 +#: ../../tutorial.rst:182 +msgid "Old Syntax" +msgstr "旧语法" + +# d98e5579e3c7481aacf83ee066cfa826 +#: ../../tutorial.rst:182 +msgid "New Syntax" +msgstr "新语法" + +# 3ef58345079544b8a954099b097d5583 +#: ../../tutorial.rst:184 +msgid "``:name``" +msgstr "" + +# ca2dfc00260445eba77bacd64e89f4e2 +#: ../../tutorial.rst:184 +msgid "````" +msgstr "" + +# 24034e67d3194c6ea694d522ff118743 +#: ../../tutorial.rst:185 +msgid "``:name#regexp#``" +msgstr "" + +# 9b40ae713f9a4c2182ab7666bd77e4fe +#: ../../tutorial.rst:185 +msgid "````" +msgstr "" + +# 47f26059d42b48ae8372c47a9c1cff3c +#: ../../tutorial.rst:186 +msgid "``:#regexp#``" +msgstr "" + +# 831629c77fb5421e8857371ed9b28751 +#: ../../tutorial.rst:186 +msgid "``<:re:regexp>``" +msgstr "" + +# 2c0f1748c68a42829971f32f109f95a9 +#: ../../tutorial.rst:187 +msgid "``:##``" +msgstr "" + +# 1191242878fd4759988a1717eeaa8d4f +#: ../../tutorial.rst:187 +msgid "``<:re>``" +msgstr "" + +# d866a2106ce5412795d39e31231da875 +#: ../../tutorial.rst:190 +msgid "" +"Try to avoid the old syntax in future projects if you can. It is not " +"currently deprecated, but will be eventually." +msgstr "" +"请尽可能在新项目中使用新的语法。虽然现在依然兼容旧语法,但终究会将其废弃的。" + +# facb8eac8d394a2595b3745e4c2a67b4 +#: ../../tutorial.rst:194 +msgid "HTTP Request Methods" +msgstr "HTTP请求方法" + +# 5cdb148bc56047629b19cac6c211ccba +#: ../../tutorial.rst:198 +msgid "" +"The HTTP protocol defines several `request methods`__ (sometimes referred to " +"as \"verbs\") for different tasks. GET is the default for all routes with no " +"other method specified. These routes will match GET requests only. To handle " +"other methods such as POST, PUT or DELETE, add a ``method`` keyword argument " +"to the :func:`route` decorator or use one of the four alternative " +"decorators: :func:`get`, :func:`post`, :func:`put` or :func:`delete`." +msgstr "" +"HTTP协议定义了多个 `request methods`__ (请求方法)来满足不同的需求。所有" +"route默认使用GET方法,只响应GET请求。可给 :func:`route` 函数指定 ``method`` " +"参数。或用 :func:`get` , :func:`post` , :func:`put` 或 :func:`delete` 等" +"函数来代替 :func:`route` 函数。" + +# 7278fe2bf62a4b3fb8abc0d391fd50e5 +#: ../../tutorial.rst:200 +msgid "" +"The POST method is commonly used for HTML form submission. This example " +"shows how to handle a login form using POST::" +msgstr "" +"POST方法一般用于HTML表单的提交。下面是一个使用POST来实现用户登录的例子::" + +# d24dc377bdd6407eb5caaa912bf71dcb +#: ../../tutorial.rst:223 +msgid "" +"In this example the ``/login`` URL is linked to two distinct callbacks, one " +"for GET requests and another for POST requests. The first one displays a " +"HTML form to the user. The second callback is invoked on a form submission " +"and checks the login credentials the user entered into the form. The use of :" +"attr:`Request.forms` is further described in the :ref:`tutorial-request` " +"section." +msgstr "" +"在这个例子中, ``/login`` 绑定了两个回调函数,一个回调函数响应GET请求,一个回" +"调函数响应POST请求。如果浏览器使用GET请求访问 ``/login`` ,则调用login_form()" +"函数来返回登录页面,浏览器使用POST方法提交表单后,调用login_submit()函数来检" +"查用户有效性,并返回登录结果。接下来的 :ref:`tutorial-request` 章节中,会详细" +"介绍 :attr:`Request.forms` 的用法。" + +# 9a3d93e1646a48779d3cc9bef9713c21 +#: ../../tutorial.rst:226 +msgid "Special Methods: HEAD and ANY" +msgstr "特殊请求方法: HEAD 和 ANY" + +# 78e1a7741c96447f912f8dd10cbc3aa4 +#: ../../tutorial.rst:227 +msgid "" +"The HEAD method is used to ask for the response identical to the one that " +"would correspond to a GET request, but without the response body. This is " +"useful for retrieving meta-information about a resource without having to " +"download the entire document. Bottle handles these requests automatically by " +"falling back to the corresponding GET route and cutting off the request " +"body, if present. You don't have to specify any HEAD routes yourself." +msgstr "" +"HEAD方法类似于GET方法,但服务器不会返回HTTP响应正文,一般用于获取HTTP原数据而" +"不用下载整个页面。Bottle像处理GET请求那样处理HEAD请求,但是会自动去掉HTTP响应" +"正文。你无需亲自处理HEAD请求。" + +# 3628c8206bcb4b229d4e875e41a44e6b +#: ../../tutorial.rst:229 +msgid "" +"Additionally, the non-standard ANY method works as a low priority fallback: " +"Routes that listen to ANY will match requests regardless of their HTTP " +"method but only if no other more specific route is defined. This is helpful " +"for *proxy-routes* that redirect requests to more specific sub-applications." +msgstr "" +"另外,非标准的ANY方法做为一个低优先级的fallback:在没有其它route的时候,监听" +"ANY方法的route会匹配所有请求,而不管请求的方法是什么。这对于用做代理的route很" +"有用,可将所有请求都重定向给子应用。" + +# 1f0764c8a13a457bb5673ab0bfae1bf8 +#: ../../tutorial.rst:231 +msgid "" +"To sum it up: HEAD requests fall back to GET routes and all requests fall " +"back to ANY routes, but only if there is no matching route for the original " +"request method. It's as simple as that." +msgstr "" +"总而言之:HEAD请求被响应GET请求的route来处理,响应ANY请求的route处理所有请" +"求,但仅限于没有其它route来匹配原先的请求的情况。就这么简单。" + +# 680955ebae544b4189d61a3ec93b13de +#: ../../tutorial.rst:236 +msgid "Routing Static Files" +msgstr "静态文件映射" + +# be9beea7a5c54379ae3b73c2f21b16e2 +#: ../../tutorial.rst:238 +msgid "" +"Static files such as images or CSS files are not served automatically. You " +"have to add a route and a callback to control which files get served and " +"where to find them::" +msgstr "" +"Bottle不会处理像图片或CSS文件的静态文件请求。你需要给静态文件提供一个route," +"一个回调函数(用于查找和控制静态文件的访问)。" + +# e174df21a55d4aaf9f92b14124f03538 +#: ../../tutorial.rst:245 +msgid "" +"The :func:`static_file` function is a helper to serve files in a safe and " +"convenient way (see :ref:`tutorial-static-files`). This example is limited " +"to files directly within the ``/path/to/your/static/files`` directory " +"because the ```` wildcard won't match a path with a slash in it. " +"To serve files in subdirectories, change the wildcard to use the `path` " +"filter::" +msgstr "" +":func:`static_file` 函数用于响应静态文件的请求。 (详见 :ref:`tutorial-static-" +"files` )这个例子只能响应在 ``/path/to/your/static/files`` 目录下的文件请求," +"因为 ```` 这样的通配符定义不能匹配一个路径(路径中包含\"/\")。 为了" +"响应子目录下的文件请求,我们需要更改 `path` 过滤器的定义::" + +# a42ae34a52d64603ad51dd2ac3e65ad1 +#: ../../tutorial.rst:251 +msgid "" +"Be careful when specifying a relative root-path such as ``root='./static/" +"files'``. The working directory (``./``) and the project directory are not " +"always the same." +msgstr "" +"使用 ``root='./static/files'`` 这样的相对路径的时候,请注意当前工作目录 (``./" +"``) 不一定是项目文件夹。" + +# 22950a221ee24d8bb93f2202e7f5a843 +#: ../../tutorial.rst:259 +msgid "Error Pages" +msgstr "错误页面" + +# e84b29f5921f42c487cd7409490d5026 +#: ../../tutorial.rst:261 +msgid "" +"If anything goes wrong, Bottle displays an informative but fairly plain " +"error page. You can override the default for a specific HTTP status code " +"with the :func:`error` decorator::" +msgstr "" +"如果出错了,Bottle会显示一个默认的错误页面,提供足够的debug信息。你也可以使" +"用 :func:`error` 函数来自定义你的错误页面::" + +# 4bf4e85c95bd4b56b431ca5191f8f08d +#: ../../tutorial.rst:268 +msgid "" +"From now on, `404 File not Found` errors will display a custom error page to " +"the user. The only parameter passed to the error-handler is an instance of :" +"exc:`HTTPError`. Apart from that, an error-handler is quite similar to a " +"regular request callback. You can read from :data:`request`, write to :data:" +"`response` and return any supported data-type except for :exc:`HTTPError` " +"instances." +msgstr "" +"从现在开始,在遇到404错误的时候,将会返回你在上面自定义的页面。传给error404函" +"数的唯一参数,是一个 :exc:`HTTPError` 对象的实例。除此之外,这个回调函数与我" +"们用来响应普通请求的回调函数没有任何不同。你可以从 :data:`request` 中读取数" +"据, 往 :data:`response` 中写入数据和返回所有支持的数据类型,除了 :exc:" +"`HTTPError` 的实例。" + +# f3020bad30b147e9a86f81a825a379e9 +#: ../../tutorial.rst:270 +msgid "" +"Error handlers are used only if your application returns or raises an :exc:" +"`HTTPError` exception (:func:`abort` does just that). Changing :attr:" +"`Request.status` or returning :exc:`HTTPResponse` won't trigger the error " +"handler." +msgstr "" +"只有在你的应用返回或raise一个 :exc:`HTTPError` 异常的时候(就像 :func:`abort` " +"函数那样),处理Error的函数才会被调用。更改 :attr:`Request.status` 或返回 :" +"exc:`HTTPResponse` 不会触发错误处理函数。" + +# 9112d2478be94ef8a880cea1dabce53a +#: ../../tutorial.rst:280 +msgid "Generating content" +msgstr "生成内容" + +# 8415bb3259f54aceab2160438457d486 +#: ../../tutorial.rst:282 +msgid "" +"In pure WSGI, the range of types you may return from your application is " +"very limited. Applications must return an iterable yielding byte strings. " +"You may return a string (because strings are iterable) but this causes most " +"servers to transmit your content char by char. Unicode strings are not " +"allowed at all. This is not very practical." +msgstr "" +"在纯WSGI环境里,你的应用能返回的内容类型相当有限。应用必须返回一个iterable的" +"字节型字符串。你可以返回一个字符串(因为字符串是iterable的),但这会导致服务器" +"按字符来传输你的内容。Unicode字符串根本不允许。这不是很实用。" + +# 0c5e8549b2c14b10b64c1030888a9f11 +#: ../../tutorial.rst:284 +msgid "" +"Bottle is much more flexible and supports a wide range of types. It even " +"adds a ``Content-Length`` header if possible and encodes unicode " +"automatically, so you don't have to. What follows is a list of data types " +"you may return from your application callbacks and a short description of " +"how these are handled by the framework:" +msgstr "" +"Bottle支持返回更多的内容类型,更具弹性。它甚至能在合适的情况下,在HTTP头中添" +"加 `Content-Length` 字段和自动转换unicode编码。下面列出了所有你能返回的内容类" +"型,以及框架处理方式的一个简述。" + +# cd50167d8d094ecf947bb272905d75b7 +#: ../../tutorial.rst:287 +msgid "Dictionaries" +msgstr "" + +# 05aa98461f2e434f81e050cbcc756f6a +#: ../../tutorial.rst:287 +msgid "" +"As mentioned above, Python dictionaries (or subclasses thereof) are " +"automatically transformed into JSON strings and returned to the browser with " +"the ``Content-Type`` header set to ``application/json``. This makes it easy " +"to implement json-based APIs. Data formats other than json are supported " +"too. See the :ref:`tutorial-output-filter` to learn more." +msgstr "" +"上面已经提及,Python中的字典类型(或其子类)会被自动转换为JSON字符串。返回给浏" +"览器的时候,HTTP头的 ``Content-Type`` 字段被自动设置为 `` application/" +"json`` 。可十分简单地实现基于JSON的API。Bottle同时支持json之外的数据类型,详" +"见 :ref:`tutorial-output-filter` 。" + +# fef9f9cdcf174200a8c9d34fe40ec6a8 +#: ../../tutorial.rst:290 +msgid "Empty Strings, ``False``, ``None`` or other non-true values:" +msgstr "" + +# 947fe77a24c4436f92b3de6ac018bfb8 +#: ../../tutorial.rst:290 +msgid "" +"These produce an empty output with the ``Content-Length`` header set to 0." +msgstr "输出为空, ``Content-Length`` 设为0。" + +# 53831a3d134a4bcc8b1553ff0e8ef190 +#: ../../tutorial.rst:293 +msgid "Unicode strings" +msgstr "Unicode的问题" + +# 6b454d4e4ee04af1809c42870727aeab +#: ../../tutorial.rst:293 +msgid "" +"Unicode strings (or iterables yielding unicode strings) are automatically " +"encoded with the codec specified in the ``Content-Type`` header (utf8 by " +"default) and then treated as normal byte strings (see below)." +msgstr "" +"Unicode字符串 (or iterables yielding unicode strings) 被自动转码, ``Content-" +"Type`` 被默认设置为utf8,接着视之为普通字符串(见下文)。" + +# e8ae5fa61f0942cd9fe48e03fa9351e9 +#: ../../tutorial.rst:296 +msgid "Byte strings" +msgstr "" + +# e20b8cfb4e7a434c9a95dc125561a7f0 +#: ../../tutorial.rst:296 +msgid "" +"Bottle returns strings as a whole (instead of iterating over each char) and " +"adds a ``Content-Length`` header based on the string length. Lists of byte " +"strings are joined first. Other iterables yielding byte strings are not " +"joined because they may grow too big to fit into memory. The ``Content-" +"Length`` header is not set in this case." +msgstr "" +"Bottle将字符串当作一个整体来返回(而不是按字符来遍历),并根据字符串长度添加 " +"``Content-Length`` 字段。包含字节型字符串的列表先被合并。其它iterable的字节型" +"字符串不会被合并,因为它们也许太大来,耗内存。在这种情况下, ``Content-" +"Length`` 字段不会被设置。" + +# c0b5bc13bd1f456ea06c9ec8c0ae332e +#: ../../tutorial.rst:299 +msgid "Instances of :exc:`HTTPError` or :exc:`HTTPResponse`" +msgstr "" + +# 4b231556398548d6804429d660fe8f90 +#: ../../tutorial.rst:299 +msgid "" +"Returning these has the same effect as when raising them as an exception. In " +"case of an :exc:`HTTPError`, the error handler is applied. See :ref:" +"`tutorial-errorhandling` for details." +msgstr "" +"返回它们和直接raise出来有一样的效果。对于 :exc:`HTTPError` 来说,会调用错误处" +"理程序。详见 :ref:`tutorial-errorhandling` 。" + +# 8ec78edc24634cb19d9d3fe68fff214f +#: ../../tutorial.rst:302 +msgid "File objects" +msgstr "" + +# 84bf9373fcf148a0b17af9a22e9473d7 +#: ../../tutorial.rst:302 +msgid "" +"Everything that has a ``.read()`` method is treated as a file or file-like " +"object and passed to the ``wsgi.file_wrapper`` callable defined by the WSGI " +"server framework. Some WSGI server implementations can make use of optimized " +"system calls (sendfile) to transmit files more efficiently. In other cases " +"this just iterates over chunks that fit into memory. Optional headers such " +"as ``Content-Length`` or ``Content-Type`` are *not* set automatically. Use :" +"func:`send_file` if possible. See :ref:`tutorial-static-files` for details." +msgstr "" +"任何有 ``.read()`` 方法的对象都被当成一个file-like对象来对待,会被传给 WSGI " +"Server 框架定义的 ``wsgi.file_wrapper`` callable对象来处理。一些WSGI Server实" +"现会利用优化过的系统调用(sendfile)来更有效地传输文件,另外就是分块遍历。可选" +"的HTTP头,例如 ``Content-Length`` 和 ``Content-Type`` 不会被自动设置。尽可能" +"使用 :func:`send_file` 。详见 :ref:`tutorial-static-files` 。" + +# 5a4011401e1b4adfa5dc9114b1491c26 +#: ../../tutorial.rst:305 +msgid "Iterables and generators" +msgstr "" + +# 134e34ab7165436b8232fe79d85d695e +#: ../../tutorial.rst:305 +msgid "" +"You are allowed to use ``yield`` within your callbacks or return an " +"iterable, as long as the iterable yields byte strings, unicode strings, :exc:" +"`HTTPError` or :exc:`HTTPResponse` instances. Nested iterables are not " +"supported, sorry. Please note that the HTTP status code and the headers are " +"sent to the browser as soon as the iterable yields its first non-empty " +"value. Changing these later has no effect." +msgstr "" +"你可以在回调函数中使用 ``yield`` 语句,或返回一个iterable的对象,只要该对象返" +"回的是字节型字符串,unicode字符串, :exc:`HTTPError` 或 :exc:`HTTPResponse` " +"实例。不支持嵌套iterable对象,不好意思。注意,在iterable对象返回第一个非空值" +"的时候,就会把HTTP状态码和HTTP头发送给浏览器。稍后再更改它们就起不到什么作用" +"了。" + +# 465e3afd48064a6aa286d3b5428b038b +#: ../../tutorial.rst:307 +msgid "" +"The ordering of this list is significant. You may for example return a " +"subclass of :class:`str` with a ``read()`` method. It is still treated as a " +"string instead of a file, because strings are handled first." +msgstr "" +"以上列表的顺序非常重要。在你返回一个 :class:`str` 类的子类的时候,即使它有 " +"``.read()`` 方法,它依然会被当成一个字符串对待,而不是文件,因为字符串先被处" +"理。" + +# 2fc6610bcc9f406f8b368ef74e8b26f9 +#: ../../tutorial.rst:310 +msgid "Changing the Default Encoding" +msgstr "改变默认编码" + +# 23b6daa9751f4ba5920edfff5246fbc0 +#: ../../tutorial.rst:311 +msgid "" +"Bottle uses the `charset` parameter of the ``Content-Type`` header to decide " +"how to encode unicode strings. This header defaults to ``text/html; " +"charset=UTF8`` and can be changed using the :attr:`Response.content_type` " +"attribute or by setting the :attr:`Response.charset` attribute directly. " +"(The :class:`Response` object is described in the section :ref:`tutorial-" +"response`.)" +msgstr "" +"Bottle使用 ``Content-Type`` 的 `charset` 参数来决定编码unicode字符串的方式。" +"默认的 ``Content-Type`` 是 ``text/html;charset=UTF8`` ,可在 :attr:`Response." +"content_type` 属性中修改,或直接设置 :attr:`Response.charset` 的值。关于 :" +"class:`Response` 对象的介绍,详见 :ref:`tutorial-response` 。" + +# 2bd0c5aa83bb43b1ad029c4a8f8a19d9 +#: ../../tutorial.rst:326 +msgid "" +"In some rare cases the Python encoding names differ from the names supported " +"by the HTTP specification. Then, you have to do both: first set the :attr:" +"`Response.content_type` header (which is sent to the client unchanged) and " +"then set the :attr:`Response.charset` attribute (which is used to encode " +"unicode)." +msgstr "" +"在极少情况下,Python中定义的编码名字和HTTP标准中的定义不一样。这样,你就必须" +"同时修改 :attr:`Response.content_type`` (发送给客户端的)和设置 :attr:" +"`Response.charset` 属性 (用于编码unicode)。" + +# e3e2fb4d1ee847ca84245ed5a5729071 +#: ../../tutorial.rst:331 +msgid "Static Files" +msgstr "静态文件" + +# 4a4c82922fbf4478886571051b910204 +#: ../../tutorial.rst:333 +msgid "" +"You can directly return file objects, but :func:`static_file` is the " +"recommended way to serve static files. It automatically guesses a mime-type, " +"adds a ``Last-Modified`` header, restricts paths to a ``root`` directory for " +"security reasons and generates appropriate error responses (401 on " +"permission errors, 404 on missing files). It even supports the ``If-Modified-" +"Since`` header and eventually generates a ``304 Not Modified`` response. You " +"can pass a custom MIME type to disable guessing." +msgstr "" +"你可直接返回文件对象。但我们更建议你使用 :func:`static_file` 来提供静态文件服" +"务。它会自动猜测文件的mime-type,添加 ``Last-Modified`` 头,将文件路径限制在" +"一个root文件夹下面来保证安全,且返回合适的HTTP状态码(由于权限不足导致的401错" +"误,由于文件不存在导致的404错误)。它甚至支持 ``If-Modified-Since`` 头,如果文" +"件未被修改,则直接返回 ``304 Not Modified`` 。你可指定MIME类型来避免其自动猜" +"测。" + +# 3d6989c4599c4f9d9fcdd6cba03e29aa +#: ../../tutorial.rst:346 +msgid "" +"You can raise the return value of :func:`static_file` as an exception if you " +"really need to." +msgstr "如果确实需要,你可将 :func:`static_file` 的返回值当作异常raise出来。" + +# 8d57af8994bd44cd8dd00013b3a71231 +#: ../../tutorial.rst:349 +msgid "Forced Download" +msgstr "强制下载" + +# 23ef7011528a4bf9a2b181d2427f0b21 +#: ../../tutorial.rst:350 +msgid "" +"Most browsers try to open downloaded files if the MIME type is known and " +"assigned to an application (e.g. PDF files). If this is not what you want, " +"you can force a download dialog and even suggest a filename to the user::" +msgstr "" +"大多数浏览器在知道MIME类型的时候,会尝试直接调用相关程序来打开文件(例如PDF文" +"件)。如果你不想这样,你可强制浏览器只是下载该文件,甚至提供文件名。::" + +# 2b57ebda0b8b47c09d4cebcc702835e3 +#: ../../tutorial.rst:356 +msgid "" +"If the ``download`` parameter is just ``True``, the original filename is " +"used." +msgstr "如果 ``download`` 参数的值为 ``True`` ,会使用原始的文件名。" + +# 3abd91e08f5c439481852f8eced8b1de +#: ../../tutorial.rst:361 +msgid "HTTP Errors and Redirects" +msgstr "HTTP错误和重定向" + +# 4ef454163f78497fa8f0c3b112e02a6c +#: ../../tutorial.rst:363 +msgid "" +"The :func:`abort` function is a shortcut for generating HTTP error pages." +msgstr ":func:`abort` 函数是生成HTTP错误页面的一个捷径。" + +# 65a2e1ed20634574932f8c39c8ac2d13 +#: ../../tutorial.rst:372 +msgid "" +"To redirect a client to a different URL, you can send a ``303 See Other`` " +"response with the ``Location`` header set to the new URL. :func:`redirect` " +"does that for you::" +msgstr "" +"为了将用户访问重定向到其他URL,你在 ``Location`` 中设置新的URL,接着返回一个 " +"``303 See Other`` 。 :func:`redirect` 函数可以帮你做这件事情。" + +# 50ab2a7b353a41c39c7fdcb9456630e3 +#: ../../tutorial.rst:379 +msgid "You may provide a different HTTP status code as a second parameter." +msgstr "你可以在第二个参数中提供另外的HTTP状态码。" + +# 757d4047c42d4e71a774a63b020fbb42 +#: ../../tutorial.rst:382 +msgid "" +"Both functions will interrupt your callback code by raising an :exc:" +"`HTTPError` exception." +msgstr "这两个函数都会抛出 :exc:`HTTPError` 异常,终止回调函数的执行。" + +# 2ee3e09d1528432294fcead9239e99b6 +#: ../../tutorial.rst:385 +msgid "Other Exceptions" +msgstr "其他异常" + +# 72ce4695e46c40d0a2f4aad019108612 +#: ../../tutorial.rst:386 +msgid "" +"All exceptions other than :exc:`HTTPResponse` or :exc:`HTTPError` will " +"result in a ``500 Internal Server Error`` response, so they won't crash your " +"WSGI server. You can turn off this behavior to handle exceptions in your " +"middleware by setting ``bottle.app().catchall`` to ``False``." +msgstr "" +"除了 :exc:`HTTPResponse` 或 :exc:`HTTPError` 以外的其他异常,都会导致500错" +"误,所以不会造成WSGI服务器崩溃。你将 ``bottle.app().catchall`` 的值设为 " +"``False`` 来关闭这种行为,以便在你的中间件中处理异常。" + +# 49ba8af1eacf4ca6b5eef9f290d09a94 +#: ../../tutorial.rst:392 +msgid "The :class:`Response` Object" +msgstr ":class:`Response` 对象" + +# 8ff2b5057b384d199aa9e15374ca37d4 +#: ../../tutorial.rst:394 +msgid "" +"Response metadata such as the HTTP status code, response headers and cookies " +"are stored in an object called :data:`response` up to the point where they " +"are transmitted to the browser. You can manipulate these metadata directly " +"or use the predefined helper methods to do so. The full API and feature list " +"is described in the API section (see :class:`Response`), but the most common " +"use cases and features are covered here, too." +msgstr "" +"诸如HTTP状态码,HTTP响应头,用户cookie等元数据都保存在一个名字为 :data:" +"`response` 的对象里面,接着被传输给浏览器。你可直接操作这些元数据或使用一些更" +"方便的函数。在API章节可查到所有相关API(详见 :class:`Response` ),这里主要介绍" +"一些常用方法。" + +# a4837fc6a70147fa9abce539af78cda0 +#: ../../tutorial.rst:397 +msgid "Status Code" +msgstr "状态码" + +# 16869c8c17d54323ab7486f66efdc860 +#: ../../tutorial.rst:398 +msgid "" +"The `HTTP status code `_ controls the behavior of the browser and " +"defaults to ``200 OK``. In most scenarios you won't need to set the :attr:" +"`Response.status` attribute manually, but use the :func:`abort` helper or " +"return an :exc:`HTTPResponse` instance with the appropriate status code. Any " +"integer is allowed, but codes other than the ones defined by the `HTTP " +"specification `_ will only confuse the browser and break " +"standards." +msgstr "" +"`HTTP状态码 `_ 控制着浏览器的行为,默认为 ``200 OK`` 。多数情况" +"下,你不必手动修改 :attr:`Response.status` 的值,可使用 :func:`abort` 函数或" +"return一个 :exc:`HTTPResponse` 实例(带有合适的状态码)。虽然所有整数都可当作状" +"态码返回,但浏览器不知道如何处理 `HTTP标准 `_ 中定义的那些状态码之" +"外的数字,你也破坏了大家约定的标准。" + +# fad4d415e6b34d8da4915371819dad0b +#: ../../tutorial.rst:401 +msgid "Response Header" +msgstr "响应头" + +# 6837d7afd10c499e84b15229465f8a3a +#: ../../tutorial.rst:402 +msgid "" +"Response headers such as ``Cache-Control`` or ``Location`` are defined via :" +"meth:`Response.set_header`. This method takes two parameters, a header name " +"and a value. The name part is case-insensitive::" +msgstr "" +"``Cache-Control`` 和 ``Location`` 之类的响应头通过 :meth:`Response." +"set_header` 来定义。这个方法接受两个参数,一个是响应头的名字,一个是它的值," +"名字是大小写敏感的。" + +# 6414dd7a448b45f998147a61ce167933 +#: ../../tutorial.rst:409 +msgid "" +"Most headers are unique, meaning that only one header per name is send to " +"the client. Some special headers however are allowed to appear more than " +"once in a response. To add an additional header, use :meth:`Response." +"add_header` instead of :meth:`Response.set_header`::" +msgstr "" +"大多数的响应头是唯一的,meaning that only one header per name is send to the " +"client。一些特殊的响应头在一次response中允许出现多次。使用 :meth:`Response." +"add_header` 来添加一个额外的响应头,而不是 :meth:`Response.set_header` ::" + +# cc64c4d2b8f541728562d60b69e95246 +#: ../../tutorial.rst:414 +msgid "" +"Please note that this is just an example. If you want to work with cookies, " +"read :ref:`ahead `." +msgstr "" +"请注意,这只是一个例子。如果你想使用cookie,详见 :ref:`ahead ` 。" + +# 1ffb76e4eada4039b6633e13cdb49c6a +# 35303652d16f422bacde561fb6912852 +#: ../../tutorial.rst:420 ../../tutorial.rst:549 +msgid "Cookies" +msgstr "" + +# 6b9e5c6de2f0499b9483fc1f2e666aa4 +#: ../../tutorial.rst:422 +msgid "" +"A cookie is a named piece of text stored in the user's browser profile. You " +"can access previously defined cookies via :meth:`Request.get_cookie` and set " +"new cookies with :meth:`Response.set_cookie`::" +msgstr "" +"Cookie是储存在浏览器配置文件里面的一小段文本。你可通过 :meth:`Request." +"get_cookie` 来访问已存在的Cookie,或通过 :meth:`Response.set_cookie` 来设置新" +"的Cookie。" + +# 89a73e9549444c0ba012c873a5f82ad5 +#: ../../tutorial.rst:432 +msgid "" +"The :meth:`Response.set_cookie` method accepts a number of additional " +"keyword arguments that control the cookies lifetime and behavior. Some of " +"the most common settings are described here:" +msgstr "" +":meth:`Response.set_cookie` 方法接受一系列额外的参数,来控制Cookie的生命周期" +"及行为。一些常用的设置如下:" + +# f4b185b380fd44129a1c9e606627d9cd +#: ../../tutorial.rst:434 +msgid "**max_age:** Maximum age in seconds. (default: ``None``)" +msgstr "**max_age:** 最大有效时间,以秒为单位 (默认: ``None``)" + +# 5f7ec5d053de45c1b7f018e4a77a5100 +#: ../../tutorial.rst:435 +msgid "" +"**expires:** A datetime object or UNIX timestamp. (default: ``None``)" +msgstr "**expires:** 一个datetime对象或一个UNIX timestamp (默认: ``None``)" + +# 93366621f0de4592872fbbd675ccfe9b +#: ../../tutorial.rst:436 +msgid "" +"**domain:** The domain that is allowed to read the cookie. (default: " +"current domain)" +msgstr "**domain:** 可访问该Cookie的域名 (默认: 当前域名)" + +# 6011fc5e6dfa4c70a3fb228d7632dbe7 +#: ../../tutorial.rst:437 +msgid "**path:** Limit the cookie to a given path (default: ``/``)" +msgstr "**path:** 限制cookie的访问路径 (默认: ``/``)" + +# 54a3f9e2aabb4fcf8f9fe532ed8c5ea4 +#: ../../tutorial.rst:438 +msgid "**secure:** Limit the cookie to HTTPS connections (default: off)." +msgstr "**secure:** 只允许在HTTPS链接中访问cookie (默认: off)" + +# 52488fc9830349e0ad2a586ef39ce369 +#: ../../tutorial.rst:439 +msgid "" +"**httponly:** Prevent client-side javascript to read this cookie (default: " +"off, requires Python 2.6 or newer)." +msgstr "" +"**httponly:** 防止客户端的javascript读取cookie (默认: off, 要求python 2.6或" +"以上版本)" + +# 01244742811543388b079c56b8927022 +#: ../../tutorial.rst:441 +msgid "" +"If neither `expires` nor `max_age` is set, the cookie expires at the end of " +"the browser session or as soon as the browser window is closed. There are " +"some other gotchas you should consider when using cookies:" +msgstr "" +"如果 `expires` 和 `max_age` 两个值都没设置,cookie会在当前的浏览器session失效" +"或浏览器窗口关闭后失效。在使用cookie的时候,应该注意一下几个陷阱。" + +# 6cbd22399dd348bea70e2e80ee49110c +#: ../../tutorial.rst:443 +msgid "Cookies are limited to 4 KB of text in most browsers." +msgstr "在大多数浏览器中,cookie的最大容量为4KB。" + +# 14572986849c49978df7a87343a71ab3 +#: ../../tutorial.rst:444 +msgid "" +"Some users configure their browsers to not accept cookies at all. Most " +"search engines ignore cookies too. Make sure that your application still " +"works without cookies." +msgstr "" +"一些用户将浏览器设置为不接受任何cookie。大多数搜索引擎也忽略cookie。确保你的" +"应用在无cookie的时候也能工作。" + +# 5dca7f9d829541ddbe8d5e168938dffa +#: ../../tutorial.rst:445 +msgid "" +"Cookies are stored at client side and are not encrypted in any way. Whatever " +"you store in a cookie, the user can read it. Worse than that, an attacker " +"might be able to steal a user's cookies through `XSS `_ vulnerabilities " +"on your side. Some viruses are known to read the browser cookies, too. Thus, " +"never store confidential information in cookies." +msgstr "" +"cookie被储存在客户端,也没被加密。你在cookie中储存的任何数据,用户都可以读" +"取。更坏的情况下,cookie会被攻击者通过 `XSS `_ 偷走,一些已知病毒也会读取" +"浏览器的cookie。既然如此,就不要在cookie中储存任何敏感信息。" + +# d7e20326f4d8418697a0f9d697149837 +#: ../../tutorial.rst:446 +msgid "Cookies are easily forged by malicious clients. Do not trust cookies." +msgstr "cookie可以被伪造,不要信任cookie!" + +# f9d19c03dc70462badd8b0b5493a9c5c +#: ../../tutorial.rst:451 +msgid "Signed Cookies" +msgstr "Cookie签名" + +# 269d39ae6e4f413ca3221424985aa0c4 +#: ../../tutorial.rst:452 +msgid "" +"As mentioned above, cookies are easily forged by malicious clients. Bottle " +"can cryptographically sign your cookies to prevent this kind of " +"manipulation. All you have to do is to provide a signature key via the " +"`secret` keyword argument whenever you read or set a cookie and keep that " +"key a secret. As a result, :meth:`Request.get_cookie` will return ``None`` " +"if the cookie is not signed or the signature keys don't match::" +msgstr "" +"上面提到,cookie容易被客户端伪造。Bottle可通过加密cookie来防止此类攻击。你只" +"需在读取和设置cookie的时候,通过 `secret` 参数来提供一个密钥。如果cookie未签" +"名或密钥不匹配, :meth:`Request.get_cookie` 方法返回 ``None`` " + +# 99cbc28ea5f240cba38b5f2cd2fc7518 +#: ../../tutorial.rst:472 +msgid "" +"In addition, Bottle automatically pickles and unpickles any data stored to " +"signed cookies. This allows you to store any pickle-able object (not only " +"strings) to cookies, as long as the pickled data does not exceed the 4 KB " +"limit." +msgstr "" +"例外,Bottle自动序列化储存在签名cookie里面的数据。你可在cookie中储存任何可序" +"列化的对象(不仅仅是字符串),只要对象大小不超过4KB。" + +# a3e875cbc84a440488152c627190d081 +#: ../../tutorial.rst:474 +msgid "" +"Signed cookies are not encrypted (the client can still see the content) and " +"not copy-protected (the client can restore an old cookie). The main " +"intention is to make pickling and unpickling safe and prevent manipulation, " +"not to store secret information at client side." +msgstr "" +"签名cookie在客户端不加密(译者注:即在客户端没有经过二次加密),也没有写保护(客" +"户端可使用之前的cookie)。给cookie签名的主要意义在于在cookie中存储序列化对象和" +"防止伪造cookie,依然不要在cookie中存储敏感信息。" + +# 4655322431dd449193c8c18eeb8cdf95 +#: ../../tutorial.rst:487 +msgid "Request Data" +msgstr "请求数据 (Request Data)" + +# 5bf5d62b2bae4266b7c48345f157eda7 +#: ../../tutorial.rst:489 +msgid "" +"Cookies, HTTP header, HTML ``
`` fields and other request data is " +"available through the global :data:`request` object. This special object " +"always refers to the *current* request, even in multi-threaded environments " +"where multiple client connections are handled at the same time::" +msgstr "" +"可通过全局的 :data:`request` 对象来访问Cookies,HTTP头,HTML的 ```` 字" +"段,以及其它的请求数据。这个特殊的对象总是指向 *当前* 的请求,即使在同时处理" +"多个客户端连接的多线程情况下。" + +# 8466f755a5544bdd95621e346d6c0a60 +#: ../../tutorial.rst:498 +msgid "" +"The :data:`request` object is a subclass of :class:`BaseRequest` and has a " +"very rich API to access data. We only cover the most commonly used features " +"here, but it should be enough to get started." +msgstr "" +":data:`request` 对象继承自 :class:`BaseRequest` ,提供了丰富的API来访问数据。" +"虽然我们只介绍最常用的特性,也足够入门了。" + +# 0ca3e35753434dba85029c1e93ea2bde +#: ../../tutorial.rst:503 +msgid "Introducing :class:`FormsDict`" +msgstr "介绍 :class:`FormsDict` " + +# d1385d18bbf148fc9547cfeadc3fe627 +#: ../../tutorial.rst:505 +msgid "" +"Bottle uses a special type of dictionary to store form data and cookies. :" +"class:`FormsDict` behaves like a normal dictionary, but has some additional " +"features to make your life easier." +msgstr "" +"Bottle使用了一个特殊的字典来储存表单数据和cookies。 :class:`FormsDict` 表现得" +"像一个普通的字典,但提供了更方便的额外功能。" + +# 36ea0be70fe44886bfec49f8263868e1 +#: ../../tutorial.rst:507 +msgid "" +"**Attribute access**: All values in the dictionary are also accessible as " +"attributes. These virtual attributes return unicode strings, even if the " +"value is missing or unicode decoding fails. In that case, the string is " +"empty, but still present::" +msgstr "" +"**属性访问** :字典中所有的值都可以当做属性来访问。这些虚拟的属性返回unicode" +"字符串。在字典中缺少对应的值,或unicode解码失败的情况下,属性返回的字符串为" +"空。" + +# c6d66b38537f4c93a5aea83e2d90096d +#: ../../tutorial.rst:522 +msgid "" +"**Multiple values per key:** :class:`FormsDict` is a subclass of :class:" +"`MultiDict` and can store more than one value per key. The standard " +"dictionary access methods will only return a single value, but the :meth:" +"`~MultiDict.getall` method returns a (possibly empty) list of all values for " +"a specific key::" +msgstr "" +"**一个key对应多个value:** :class:`FormsDict` 是 :class:`MutilDict` 的子类," +"一个key可存储多个value。标准的字典访问方法只返回一个值,但 :meth:`~MultiDict." +"getall` 方法会返回一个包含了所有value的一个list(也许为空)。" + +# bc6adb59e0714314b37551f7db353571 +#: ../../tutorial.rst:527 +msgid "" +"**WTForms support:** Some libraries (e.g. `WTForms `_) want all-unicode dictionaries as input. :meth:" +"`FormsDict.decode` does that for you. It decodes all values and returns a " +"copy of itself, while preserving multiple values per key and all the other " +"features." +msgstr "" +"**WTForms支持:** 一些第三方库(例如 `WTForms `_ )希望输入中的所有字典都是unicode的。 :meth:`FormsDict.decode` 帮你做" +"了这件事情。它将所有value重新编码,并返回原字典的一个拷贝,同时保留所有特性," +"例如一个key对应多个value。" + +# 424fca94acab45129e4592ae1c4c5fee +#: ../../tutorial.rst:531 +msgid "" +"In **Python 2** all keys and values are byte-strings. If you need unicode, " +"you can call :meth:`FormsDict.getunicode` or fetch values via attribute " +"access. Both methods try to decode the string (default: utf8) and return an " +"empty string if that fails. No need to catch :exc:`UnicodeError`::" +msgstr "" +"在 **Python2** 中,所有的key和value都是byte-string。如果你需要unicode,可使" +"用 :meth:`FormsDict.getunicode` 方法或像访问属性那样访问。这两种方法都试着将" +"字符串转码(默认: utf8),如果失败,将返回一个空字符串。无需捕获 :exc:" +"`UnicodeError` 异常。" + +# 16daaaa718454e58a8a143d05119bac1 +#: ../../tutorial.rst:538 +msgid "" +"In **Python 3** all strings are unicode, but HTTP is a byte-based wire " +"protocol. The server has to decode the byte strings somehow before they are " +"passed to the application. To be on the safe side, WSGI suggests ISO-8859-1 " +"(aka latin1), a reversible single-byte codec that can be re-encoded with a " +"different encoding later. Bottle does that for :meth:`FormsDict.getunicode` " +"and attribute access, but not for the dict-access methods. These return the " +"unchanged values as provided by the server implementation, which is probably " +"not what you want." +msgstr "" +"在 **Python3** 中,所有的字符串都是unicode。但HTTP是基于字节的协议,在byte-" +"string被传给应用之前,服务器必须将其转码。安全起见,WSGI协议建议使用" +"ISO-8859-1 (即是latin1),一个可反转的单字节编码,可被转换为其他编码。Bottle通" +"过 :meth:`FormsDict.getunicode` 和属性访问实现了转码,但不支持字典形式的访" +"问。通过字典形式的访问,将直接返回服务器返回的字符串,未经处理,这或许不是你" +"想要的。" + +# eaa8c0117ce043d3a561cedacf73885d +#: ../../tutorial.rst:545 +msgid "" +"If you need the whole dictionary with correctly decoded values (e.g. for " +"WTForms), you can call :meth:`FormsDict.decode` to get a re-encoded copy." +msgstr "" +"如果你整个字典包含正确编码后的值(e.g. for WTForms),可通过 :meth:`FormsDict." +"decode` 方法来获取一个转码后的拷贝(译者注:一个新的实例)。" + +# 8dc1b5cc26104144bb0774207d410442 +#: ../../tutorial.rst:551 +msgid "" +"Cookies are small pieces of text stored in the clients browser and sent back " +"to the server with each request. They are useful to keep some state around " +"for more than one request (HTTP itself is stateless), but should not be used " +"for security related stuff. They can be easily forged by the client." +msgstr "" +"Cookie是客户端浏览器存储的一些文本数据,在每次请求的时候发送回给服务器。" +"Cookie被用于在多次请求间保留状态信息(HTTP本身是无状态的),但不应该用于保存" +"安全相关信息。因为客户端很容易伪造Cookie。" + +# 7e7760b24bf44ea38c8234dba8b229bd +#: ../../tutorial.rst:553 +msgid "" +"All cookies sent by the client are available through :attr:`BaseRequest." +"cookies` (a :class:`FormsDict`). This example shows a simple cookie-based " +"view counter::" +msgstr "" +"可通过 :attr:`BaseRequest.cookies` (一个 :class:`FormsDict`) 来访问所有客户端" +"发来的Cookie。下面的是一个基于Cookie的访问计数。" + +# 7e7760b24bf44ea38c8234dba8b229bd +#: ../../tutorial.rst:563 +msgid "" +"The :meth:`BaseRequest.get_cookie` method is a different way do access " +"cookies. It supports decoding :ref:`signed cookies ` as described in a separate section." +msgstr "" +":meth:`BaseRequest.get_cookie` 是访问cookie的另一种方法。它支持解析 :ref:" +"`signed cookies ` 。" + +# 100ecfb0ffa34da8a18ba10859ec5203 +#: ../../tutorial.rst:566 +msgid "HTTP Headers" +msgstr "HTTP头" + +# 2883f57c0e824a8a9b8d2213e2ff5cf5 +#: ../../tutorial.rst:568 +msgid "" +"All HTTP headers sent by the client (e.g. ``Referer``, ``Agent`` or ``Accept-" +"Language``) are stored in a :class:`WSGIHeaderDict` and accessible through " +"the :attr:`BaseRequest.headers` attribute. A :class:`WSGIHeaderDict` is " +"basically a dictionary with case-insensitive keys::" +msgstr "" +"所有客户端发送过来的HTTP头(例如 ``Referer``, ``Agent`` 和 ``Accept-" +"Language``)存储在一个 :class:`WSGIHeaderDict` 中,可通过 :attr:`BaseRequest." +"headers` 访问。 :class:`WSGIHeaderDict` 基本上是一个字典,其key大小写敏感。" + +# a04a46af8ede416dbc96fa3067dce003 +#: ../../tutorial.rst:580 +msgid "Query Variables" +msgstr "查询变量" + +# 3c909f2249c94ee3b61c99e1ac5d8fa7 +#: ../../tutorial.rst:582 +msgid "" +"The query string (as in ``/forum?id=1&page=5``) is commonly used to transmit " +"a small number of key/value pairs to the server. You can use the :attr:" +"`BaseRequest.query` attribute (a :class:`FormsDict`) to access these values " +"and the :attr:`BaseRequest.query_string` attribute to get the whole string." +msgstr "" +"查询字符串(例如 ``/forum?id=1&page=5`` )一般用于向服务器传输键值对。你可通" +"过 :attr:`BaseRequest.query` ( :class:`FormsDict` 类的实例) 来访问,和通过 :" +"attr:`BaseRequest.query_string` 来获取整个字符串。" + +# 25526928151e427cab403bbea63ec097 +#: ../../tutorial.rst:595 +msgid "HTML `` Handling" +msgstr "处理HTML的 `` 标签" + +# 0c4a8b2fc4ea421bb0d7726d2760fe1d +#: ../../tutorial.rst:597 +msgid "" +"Let us start from the beginning. In HTML, a typical ```` looks " +"something like this:" +msgstr "让我们从头开始。在HTML中,一个典型的 ```` 标签看起来是这样的。" + +# 7c5b1ec7c6254562abeca801783f66fb +#: ../../tutorial.rst:607 +msgid "" +"The ``action`` attribute specifies the URL that will receive the form data. " +"``method`` defines the HTTP method to use (``GET`` or ``POST``). With " +"``method=\"get\"`` the form values are appended to the URL and available " +"through :attr:`BaseRequest.query` as described above. This is considered " +"insecure and has other limitations, so we use ``method=\"post\"`` here. If " +"in doubt, use ``POST`` forms." +msgstr "" +"``action`` 属性指定了用于接收表单数据的URL, ``method`` 定义了使用的HTTP方法" +"( ``GET`` 或 ``POST`` )。如果使用GET方法,表单中的数据会附加到URL后面,可通" +"过 :attr:`BaseRequest.query` 来访问。这被认为是不安全的,且有其它限制。所以这" +"里我们使用POST方法。如果有疑惑,就使用 ``POST`` 吧。" + +# c4f2495ac4dd45d3bbc265d8a9d002a9 +#: ../../tutorial.rst:609 +msgid "" +"Form fields transmitted via ``POST`` are stored in :attr:`BaseRequest.forms` " +"as a :class:`FormsDict`. The server side code may look like this::" +msgstr "" +"通过POST方法传输的表单字段,作为一个 :class:`FormsDict` 存储在 :attr:" +"`BaseRequest.forms` 中。服务器端的代码看起来是这样的。" + +# 3632962199094482870c7ba2f03610d6 +#: ../../tutorial.rst:632 +msgid "" +"There are several other attributes used to access form data. Some of them " +"combine values from different sources for easier access. The following table " +"should give you a decent overview." +msgstr "" +"有其它一些属性也可以用来访问表单数据。为了方便,一些属性包含了多个来源的数" +"据。下面的表格可给你一个直观的印象。" + +# 65f70c00c85047bf916aa04636146b14 +#: ../../tutorial.rst:635 +msgid "Attribute" +msgstr "" + +# 62ba54597de54af58b7f60aa96fee29a +#: ../../tutorial.rst:635 +msgid "GET Form fields" +msgstr "" + +# 62ba54597de54af58b7f60aa96fee29a +#: ../../tutorial.rst:635 +msgid "POST Form fields" +msgstr "POST表单数据" + +# 62ba54597de54af58b7f60aa96fee29a +#: ../../tutorial.rst:635 +msgid "File Uploads" +msgstr "" + +# fbb89b2e85a64af5bf161bc80547f380 +#: ../../tutorial.rst:637 +msgid ":attr:`BaseRequest.query`" +msgstr "" + +# 3fa195bb296e4164898b421bf4ab5beb +# c6d6540237ad435093a041f8e4b572fa +# 62d96ea440a94a76bea224714c15b2e0 +# 125f34a989e74405b622c1b4cc5b9187 +# 8dfdfc246dea4016a058c8ca3280bd17 +# 4128d67e776043cebf97371702197b62 +# 60adb7f041ff490bbd446b0ea9a3d1ad +# c34b8f3630e84e4ebdfec44f28b10ef2 +#: ../../tutorial.rst:637 ../../tutorial.rst:638 ../../tutorial.rst:639 +#: ../../tutorial.rst:640 ../../tutorial.rst:641 ../../tutorial.rst:642 +msgid "yes" +msgstr "" + +# 240b3fdc10284f7b9f59a74491c83ab3 +# 572c131bbc5642af91df787f99052a9a +# 92b9d86b3b2449b48eb7a3c321c67fa5 +# 19810dec53b741b2ba22f75f80c0bfb1 +# 3e17dd823315419cab1bef1f88a67ad5 +# 439f7330871b4aaf8397140cf3dd2804 +# 56c8061c0c4043bda4e634c7e76185fc +# 90bfbc27826a43619a7cf39cc6f4ab1b +# b3b34c96477e42fc9eab9cbf0239d94e +# 24bb8d5dda2e436b9f3b007fa342124a +#: ../../tutorial.rst:637 ../../tutorial.rst:638 ../../tutorial.rst:639 +#: ../../tutorial.rst:640 ../../tutorial.rst:641 ../../tutorial.rst:642 +msgid "no" +msgstr "" + +# 1f5cb4f69ac34c82bc39345f183c3fff +#: ../../tutorial.rst:638 +msgid ":attr:`BaseRequest.forms`" +msgstr "" + +# 09e1fea933664ebea0954efe295a1184 +#: ../../tutorial.rst:639 +msgid ":attr:`BaseRequest.files`" +msgstr "" + +# 1f5cb4f69ac34c82bc39345f183c3fff +#: ../../tutorial.rst:640 +msgid ":attr:`BaseRequest.params`" +msgstr "" + +# d6ac10bbc1db4db5aff2ff6fcf62265e +#: ../../tutorial.rst:641 +msgid ":attr:`BaseRequest.GET`" +msgstr "" + +# d6ac10bbc1db4db5aff2ff6fcf62265e +#: ../../tutorial.rst:642 +msgid ":attr:`BaseRequest.POST`" +msgstr "" + +# 633e196fad4e4e8298aa83a76d0a7caf +#: ../../tutorial.rst:647 +msgid "File uploads" +msgstr "文件上传" + +# 6792263598664f43ac6070fef7d4d55f +#: ../../tutorial.rst:649 +msgid "" +"To support file uploads, we have to change the ```` tag a bit. First, " +"we tell the browser to encode the form data in a different way by adding an " +"``enctype=\"multipart/form-data\"`` attribute to the ```` tag. Then, " +"we add ```` tags to allow the user to select a file. " +"Here is an example:" +msgstr "" +"为了支持文件上传,我们需要小改一下上面 ```` 标签,加上 ``enctype=" +"\"multipart/form-data\"`` 属性,告诉浏览器用另一种方式编码表单数据。接下来," +"我们添加 ```` 标签,让用户可以选择需要上传的文件。例子" +"如下。" + +# 3c68df7ebfa84e12b277facd8dafc58d +#: ../../tutorial.rst:659 +msgid "" +"Bottle stores file uploads in :attr:`BaseRequest.files` as :class:" +"`FileUpload` instances, along with some metadata about the upload. Let us " +"assume you just want to save the file to disk::" +msgstr "" +"Bottle将上传的文件当做一个 :class:`FileUpload` 实例存储在 :attr:`BaseRequest." +"files` 中,伴随着一些这次上传的元数据。我们假设你仅是想把上传的文件保存到磁盘" +"中。" + +# 3a1c322545d341d7b32789db4fe0e9ef +#: ../../tutorial.rst:673 +msgid "" +":attr:`FileUpload.filename` contains the name of the file on the clients " +"file system, but is cleaned up and normalized to prevent bugs caused by " +"unsupported characters or path segments in the filename. If you need the " +"unmodified name as sent by the client, have a look at :attr:`FileUpload." +"raw_filename`." +msgstr "" +":attr:`FileUpload.filename` 包含客户端传上来的文件的文件名,但为了防止异常字" +"符带来的bug,这里的文件名已经被处理过。如果你需要未经改动的文件名,看看 :" +"attr:`FileUpload.raw_filename` 。" + +# 0edcb379b65c4a3da31b48439db2d3ec +#: ../../tutorial.rst:675 +msgid "" +"The :attr:`FileUpload.save` method is highly recommended if you want to " +"store the file to disk. It prevents some common errors (e.g. it does not " +"overwrite existing files unless you tell it to) and stores the file in a " +"memory efficient way. You can access the file object directly via :attr:" +"`FileUpload.file`. Just be careful." +msgstr "" +"如果你想将文件保存到磁盘,强烈建议你使用 :attr:`FileUpload.save` 方法。它避免" +"了一些常见的错误(例如,它不会覆盖已经存在的文件,除非你告诉它可以覆盖),并" +"且更有效地使用内存。你可以通过 :attr:`FileUpload.file` 来直接访问文件对象,但" +"是要谨慎。" + +# 00ebd6fbc91944adbb2f8ed5eba530c9 +#: ../../tutorial.rst:679 +msgid "JSON Content" +msgstr "JSON内容" + +# 2b4bc0434c3647aab955774d47087a57 +#: ../../tutorial.rst:681 +msgid "" +"Some JavaScript or REST clients send ``application/json`` content to the " +"server. The :attr:`BaseRequest.json` attribute contains the parsed data " +"structure, if available." +msgstr "" +"一些JavaScript或支持REST的客户端会发送 ``application/json`` 内容给服务器。如" +"果可用(合法的JSON), :attr:`BaseRequest.json` 会包含解析后的数据结构。" + +# 04eb97e955474ed785db0dc3ef77ad21 +#: ../../tutorial.rst:685 +msgid "The raw request body" +msgstr "原始的请求数据" + +# 1cc8541629fd442d829484ac6676626a +#: ../../tutorial.rst:687 +msgid "" +"You can access the raw body data as a file-like object via :attr:" +"`BaseRequest.body`. This is a :class:`BytesIO` buffer or a temporary file " +"depending on the content length and :attr:`BaseRequest.MEMFILE_MAX` setting. " +"In both cases the body is completely buffered before you can access the " +"attribute. If you expect huge amounts of data and want to get direct " +"unbuffered access to the stream, have a look at ``request['wsgi.input']``." +msgstr "" +"你可以把 :attr:`BaseRequest.body` 当做一个file-like 对象来访问。根据内容的长" +"度,以及 :attr:`BaseRequest.MEMFILE_MAX` 中的设置,它可以是一个 :class:" +"`BytesIO` 缓存或一个磁盘上的临时文件。无论如何,它都是被缓存的。如果你无需缓" +"存,想直接访问文件流,可看看 ``request['wsgi.input']`` 。" + +# 00ebd6fbc91944adbb2f8ed5eba530c9 +#: ../../tutorial.rst:692 +msgid "WSGI Environment" +msgstr "WSGI环境" + +# 02742224d5ad42bb8ff01b10de6ab5e7 +#: ../../tutorial.rst:694 +msgid "" +"Each :class:`BaseRequest` instance wraps a WSGI environment dictionary. The " +"original is stored in :attr:`BaseRequest.environ`, but the request object " +"itself behaves like a dictionary, too. Most of the interesting data is " +"exposed through special methods or attributes, but if you want to access " +"`WSGI environ variables `_ directly, you can do so::" +msgstr "" +"每一个 :class:`BaseRequest` 类的实例都包含一个WSGI环境的字典。最初存储在 :" +"attr:`BaseRequest.environ` 中,但request对象也表现的像一个字典。大多数有用的" +"数据都通过特定的方法或属性暴露了出来,但如果你想直接访问 `WSGI环境变量 `_ ,可以这样做::" + +# c12824d94b3a4fbdbcaebc6618897d10 +#: ../../tutorial.rst:712 +msgid "Templates" +msgstr "模板" + +# 3ee2e726eac14d9c994dde9fdaee5b39 +#: ../../tutorial.rst:714 +msgid "" +"Bottle comes with a fast and powerful built-in template engine called :doc:" +"`stpl`. To render a template you can use the :func:`template` function or " +"the :func:`view` decorator. All you have to do is to provide the name of the " +"template and the variables you want to pass to the template as keyword " +"arguments. Here’s a simple example of how to render a template::" +msgstr "" +"Bottle内置了一个快速的,强大的模板引擎,称为 :doc:`stpl` 。可通过 :func:" +"`template` 函数或 :func:`view` 修饰器来渲染一个模板。只需提供模板的名字和传递" +"给模板的变量。下面是一个渲染模板的简单例子::" + +# a262870d7851494299ca7357419668b0 +#: ../../tutorial.rst:721 +msgid "" +"This will load the template file ``hello_template.tpl`` and render it with " +"the ``name`` variable set. Bottle will look for templates in the ``./views/" +"`` folder or any folder specified in the ``bottle.TEMPLATE_PATH`` list." +msgstr "" +"这会加载 ``hello_template.tpl`` 模板文件,并提供 ``name`` 变量。默认情况," +"Bottle会在 ``./views/`` 目录查找模板文件(译者注:或当前目录)。可在 ``bottle." +"TEMPLATE_PATH`` 这个列表中添加更多的模板路径。" + +# ed78b45085864fe7b5a0f6f708355177 +#: ../../tutorial.rst:723 +msgid "" +"The :func:`view` decorator allows you to return a dictionary with the " +"template variables instead of calling :func:`template`::" +msgstr "" +":func:`view` 修饰器允许你在回调函数中返回一个字典,并将其传递给模板,和 :" +"func:`template` 函数做同样的事情。" + +# 99ab9dcde99e4d43a3990c3ad34f5c59 +#: ../../tutorial.rst:732 +msgid "Syntax" +msgstr "语法" + +# 09cd302595e74ff8b713bc4f8bd96577 +#: ../../tutorial.rst:735 +msgid "" +"The template syntax is a very thin layer around the Python language. Its " +"main purpose is to ensure correct indentation of blocks, so you can format " +"your template without worrying about indentation. Follow the link for a full " +"syntax description: :doc:`stpl`" +msgstr "" +"模板语法类似于Python的语法。它要确保语句块的正确缩进,所以你在写模板的时候无" +"需担心会出现缩进问题。详细的语法描述可看 :doc:`stpl` 。" + +# 6bba819ce04040a7a4075b08513d3914 +#: ../../tutorial.rst:737 +msgid "Here is an example template::" +msgstr "简单的模板例子::" + +# f4e568a17e6e4a029d785713c1c10e4f +#: ../../tutorial.rst:748 +msgid "Caching" +msgstr "缓存" + +# 6abf5d3fe8704e84a667b3f7b35a92fb +#: ../../tutorial.rst:749 +msgid "" +"Templates are cached in memory after compilation. Modifications made to the " +"template files will have no affect until you clear the template cache. Call " +"``bottle.TEMPLATES.clear()`` to do so. Caching is disabled in debug mode." +msgstr "" +"模板在经过编译后被缓存在内存里。你在修改模板文件后,要调用 ``bottle." +"TEMPLATES.clear()`` 函数清除缓存才能看到效果。在debug模式下,缓存被禁用了,无" +"需手动清除缓存。" + +# a23c78bf8a2a4f27925d654bed8a8bb5 +#: ../../tutorial.rst:759 +msgid "Plugins" +msgstr "插件" + +# 88060d08b1a949b898df6761368281fe +#: ../../tutorial.rst:763 +msgid "" +"Bottle's core features cover most common use-cases, but as a micro-framework " +"it has its limits. This is where \"Plugins\" come into play. Plugins add " +"missing functionality to the framework, integrate third party libraries, or " +"just automate some repetitive work." +msgstr "" +"Bottle的核心功能覆盖了常见的使用情况,但是作为一个迷你框架,它有它的局限性。" +"所以我们引入了插件机制,插件可以给框架添加其缺少的功能,集成第三方的库,或是" +"自动化一些重复性的工作。" + +# 38149a02d0a5465da9a9852e284a4f28 +#: ../../tutorial.rst:765 +msgid "" +"We have a growing :doc:`/plugins/index` and most plugins are designed to be " +"portable and re-usable across applications. The chances are high that your " +"problem has already been solved and a ready-to-use plugin exists. If not, " +"the :doc:`/plugindev` may help you." +msgstr "" +"我们有一个不断增长的 :doc:`/plugins/index` 插件列表,大多数插件都被设计为可插" +"拔的。有很大可能,你的问题已经被解决,而且已经有现成的插件可以使用了。如果没" +"有现成的插件, :doc:`/plugindev` 有介绍如何开发一个插件。" + +# f2e682f4d04b4b8ebc16edcb8caf47a4 +#: ../../tutorial.rst:767 +msgid "" +"The effects and APIs of plugins are manifold and depend on the specific " +"plugin. The ``SQLitePlugin`` plugin for example detects callbacks that " +"require a ``db`` keyword argument and creates a fresh database connection " +"object every time the callback is called. This makes it very convenient to " +"use a database::" +msgstr "" +"插件扮演着各种各样的角色。例如, ``SQLitePlugin`` 插件给每个route的回调函数都" +"添加了一个 ``db`` 参数,在回调函数被调用的时候,会新建一个数据库连接。这样," +"使用数据库就非常简单了。" + +# 8ba3a92375604cd1bc2c55e8fe88b7c6 +#: ../../tutorial.rst:787 +msgid "" +"Other plugin may populate the thread-safe :data:`local` object, change " +"details of the :data:`request` object, filter the data returned by the " +"callback or bypass the callback completely. An \"auth\" plugin for example " +"could check for a valid session and return a login page instead of calling " +"the original callback. What happens exactly depends on the plugin." +msgstr "" +"其它插件或许在线程安全的 :data:`local` 对象里面发挥作用,改变 :data:" +"`request` 对象的细节,过滤回调函数返回的数据或完全绕开回调函数。举个例子,一" +"个用于登录验证的插件会在调用原先的回调函数响应请求之前,验证用户的合法性,如" +"果是非法访问,则返回登录页面而不是调用回调函数。具体的做法要看插件是如何实现" +"的。" + +# 9679a5cc51d944af9e76e1e461c73a0b +#: ../../tutorial.rst:791 +msgid "Application-wide Installation" +msgstr "整个应用的范围内安装插件" + +# 216747200f3146418ab3633e0f2e1e13 +#: ../../tutorial.rst:793 +msgid "" +"Plugins can be installed application-wide or just to some specific routes " +"that need additional functionality. Most plugins can safely be installed to " +"all routes and are smart enough to not add overhead to callbacks that do not " +"need their functionality." +msgstr "" +"可以在整个应用的范围内安装插件,也可以只是安装给某些route。大多数插件都可安全" +"地安装给所有route,也足够智能,可忽略那些并不需要它们的route。" + +# 9764f2ecd5594b57b040ec177c1460da +#: ../../tutorial.rst:795 +msgid "" +"Let us take the ``SQLitePlugin`` plugin for example. It only affects route " +"callbacks that need a database connection. Other routes are left alone. " +"Because of this, we can install the plugin application-wide with no " +"additional overhead." +msgstr "" +"让我们拿 ``SQLitePlugin`` 插件举例,它只会影响到那些需要数据库连接的route,其" +"它route都被忽略了。正因为如此,我们可以放心地在整个应用的范围内安装这个插件。" + +# ffcfd7ecba4841939dade7327353c8dc +#: ../../tutorial.rst:797 +msgid "" +"To install a plugin, just call :func:`install` with the plugin as first " +"argument::" +msgstr "调用 :func:`install` 函数来安装一个插件::" + +# 43812d9787b84f90a4a0102fd4a48431 +#: ../../tutorial.rst:802 +msgid "" +"The plugin is not applied to the route callbacks yet. This is delayed to " +"make sure no routes are missed. You can install plugins first and add routes " +"later, if you want to. The order of installed plugins is significant, " +"though. If a plugin requires a database connection, you need to install the " +"database plugin first." +msgstr "" +"插件没有马上应用到所有route上面,它被延迟执行来确保没有遗漏任何route。你可以" +"先安装插件,再添加route。有时,插件的安装顺序很重要,如果另外一个插件需要连接" +"数据库,那么你就需要先安装操作数据库的插件。" + +# a24315f350254ca1b76d8cef343326c3 +#: ../../tutorial.rst:806 +msgid "Uninstall Plugins" +msgstr "卸载插件" + +# 74aefe2ba5704f2d86ec09a12d1e8c93 +#: ../../tutorial.rst:807 +msgid "" +"You can use a name, class or instance to :func:`uninstall` a previously " +"installed plugin::" +msgstr "调用 :func:`uninstall` 函数来卸载已经安装的插件" + +# a8e7d4f099d1483d9e837c9ebae15229 +#: ../../tutorial.rst:817 +msgid "" +"Plugins can be installed and removed at any time, even at runtime while " +"serving requests. This enables some neat tricks (installing slow debugging " +"or profiling plugins only when needed) but should not be overused. Each time " +"the list of plugins changes, the route cache is flushed and all plugins are " +"re-applied." +msgstr "" +"在任何时候,插件都可以被安装或卸载,即使是在服务器正在运行的时候。一些小技巧" +"应用到了这个特征,例如在需要的时候安装一些供debug和性能测试的插件,但不可滥用" +"这个特性。每一次安装或卸载插件的时候,route缓存都会被刷新,所有插件被重新加" +"载。" + +# d653b077c8cd432b9dea61f859deaf2a +#: ../../tutorial.rst:820 +msgid "" +"The module-level :func:`install` and :func:`uninstall` functions affect the :" +"ref:`default-app`. To manage plugins for a specific application, use the " +"corresponding methods on the :class:`Bottle` application object." +msgstr "" +"模块层面的 :func:`install` 和 :func:`unistall` 函数会影响 :ref:`default-" +"app` 。针对应用来管理插件,可使用 :class:`Bottle` 应用对象的相应方法。" + +# 243f252439a14fd980528d11dc2a5ef3 +#: ../../tutorial.rst:824 +msgid "Route-specific Installation" +msgstr "安装给特定的route" + +# 838aae12dff54ecca70e4b9929c377a7 +#: ../../tutorial.rst:826 +msgid "" +"The ``apply`` parameter of the :func:`route` decorator comes in handy if you " +"want to install plugins to only a small number of routes::" +msgstr ":func:`route` 修饰器的 ``apply`` 参数可以给指定的route安装插件" + +# 9a84759774fe4f40a9ca78198ee213a5 +#: ../../tutorial.rst:836 +msgid "Blacklisting Plugins" +msgstr "插件黑名单" + +# 6a0ab06186804e1d8bbe63a231a7c5d0 +#: ../../tutorial.rst:838 +msgid "" +"You may want to explicitly disable a plugin for a number of routes. The :" +"func:`route` decorator has a ``skip`` parameter for this purpose::" +msgstr "" +"如果你想显式地在一些route上面禁用某些插件,可使用 :func:`route` 修饰器的 " +"``skip`` 参数::" + +# 4f2c00ad89e74770be416ad7bbae1bee +#: ../../tutorial.rst:860 +msgid "" +"The ``skip`` parameter accepts a single value or a list of values. You can " +"use a name, class or instance to identify the plugin that is to be skipped. " +"Set ``skip=True`` to skip all plugins at once." +msgstr "" +"``skip`` 参数接受单一的值或是一个list。你可使用插件的名字,类,实例来指定你想" +"要禁用的插件。如果 ``skip`` 的值为True,则禁用所有插件。" + +# d87dd978a89d43868cb463a1a2190830 +#: ../../tutorial.rst:863 +msgid "Plugins and Sub-Applications" +msgstr "插件和子应用" + +# 3d4b2c7941c849f7909c988ec94594b9 +#: ../../tutorial.rst:865 +msgid "" +"Most plugins are specific to the application they were installed to. " +"Consequently, they should not affect sub-applications mounted with :meth:" +"`Bottle.mount`. Here is an example::" +msgstr "" +"大多数插件只会影响到安装了它们的应用。因此,它们不应该影响通过 :meth:`Bottle." +"mount` 方法挂载上来的子应用。这里有一个例子。" + +# 4b73aeba0920406595cca49309022d40 +#: ../../tutorial.rst:876 +msgid "" +"Whenever you mount an application, Bottle creates a proxy-route on the main-" +"application that forwards all requests to the sub-application. Plugins are " +"disabled for this kind of proxy-route by default. As a result, our " +"(fictional) `WTForms` plugin affects the ``/contact`` route, but does not " +"affect the routes of the ``/blog`` sub-application." +msgstr "" +"在你挂载一个应用的时候,Bottle在主应用上面创建一个代理route,将所有请求转接给" +"子应用。在代理route上,默认禁用了插件。如上所示,我们的 ``WTForms`` 插件影响" +"了 ``/contact`` route,但不会影响挂载在root上面的 ``/blog`` 。" + +# b7358bc6de3141de8ee22c6f437c05e2 +#: ../../tutorial.rst:878 +msgid "" +"This behavior is intended as a sane default, but can be overridden. The " +"following example re-activates all plugins for a specific proxy-route::" +msgstr "" +"这个是一个合理的行为,但可被改写。下面的例子,在指定的代理route上面应用了插" +"件。" + +# e3e8120e6e2f4f0caa98e2facc17f5f9 +#: ../../tutorial.rst:882 +msgid "" +"But there is a snag: The plugin sees the whole sub-application as a single " +"route, namely the proxy-route mentioned above. In order to affect each " +"individual route of the sub-application, you have to install the plugin to " +"the mounted application explicitly." +msgstr "" +"这里存在一个小难题: 插件会整个子应用当作一个route看待,即是上面提及的代理" +"route。如果想在子应用的每个route上面应用插件,你必须显式地在子应用上面安装插" +"件。" + +# 6a3062e368f74a49bcd5a9aee9c27f1d +#: ../../tutorial.rst:887 +msgid "Development" +msgstr "开发" + +# f171d35ca9c640958adf39b6600ef7d1 +#: ../../tutorial.rst:889 +msgid "" +"So you have learned the basics and want to write your own application? Here " +"are some tips that might help you to be more productive." +msgstr "" +"到目前为止,你已经学到一些开发的基础,并想写你自己的应用了吧?这里有一些小技" +"巧可提高你的生产力。" + +# f08de7bd8585473ba505d5471a1f4b95 +#: ../../tutorial.rst:895 +msgid "Default Application" +msgstr "默认应用" + +# b08fcbe75c2740baa96374ade2061c40 +#: ../../tutorial.rst:897 +msgid "" +"Bottle maintains a global stack of :class:`Bottle` instances and uses the " +"top of the stack as a default for some of the module-level functions and " +"decorators. The :func:`route` decorator, for example, is a shortcut for " +"calling :meth:`Bottle.route` on the default application::" +msgstr "" +"Bottle维护一个全局的 :class:`Bottle` 实例的栈,模块层面的函数和修饰器使用栈顶" +"实例作为默认应用。例如 :func:`route` 修饰器,相当于在默认应用上面调用了 :" +"meth:`Bottle.route` 方法。" + +# 8115e9c107c64e50a46fa7dbbcebafd8 +#: ../../tutorial.rst:903 +msgid "" +"This is very convenient for small applications and saves you some typing, " +"but also means that, as soon as your module is imported, routes are " +"installed to the global application. To avoid this kind of import side-" +"effects, Bottle offers a second, more explicit way to build applications::" +msgstr "" +"对于小应用来说,这样非常方便,可节约你的工作量。但这同时意味着,在你的模块导" +"入的时候,你定义的route就被安装到全局的默认应用中了。为了避免这种模块导入的副" +"作用,Bottle提供了另外一种方法,显式地管理应用。" + +# 564c8e3eee454f6e99c594739eadda07 +#: ../../tutorial.rst:911 +msgid "" +"Separating the application object improves re-usability a lot, too. Other " +"developers can safely import the ``app`` object from your module and use :" +"meth:`Bottle.mount` to merge applications together." +msgstr "" +"分离应用对象,大大提高了可重用性。其他开发者可安全地从你的应用中导入 ``app`` " +"对象,然后通过 :meth:`Bottle.mount` 方法来合并到其它应用中。" + +# 8d144a16824c4b9badfac96807f984a3 +#: ../../tutorial.rst:913 +msgid "" +"As an alternative, you can make use of the application stack to isolate your " +"routes while still using the convenient shortcuts::" +msgstr "" +"作为一种选择,你可通过应用栈来隔离你的route,依然使用方便的 ``route`` 修饰" +"器。" + +# de0c34efbab94c38be0a30cdce342f7a +#: ../../tutorial.rst:923 +msgid "" +"Both :func:`app` and :func:`default_app` are instance of :class:`AppStack` " +"and implement a stack-like API. You can push and pop applications from and " +"to the stack as needed. This also helps if you want to import a third party " +"module that does not offer a separate application object::" +msgstr "" +":func:`app` 和 :func:`default_app` 都是 :class:`AppStack` 类的一个实例,实现" +"了栈形式的API操作。你可push应用到栈里面,也可将栈里面的应用pop出来。在你需要" +"导入一个第三方模块,但它不提供一个独立的应用对象的时候,尤其有用。" + +# ba511473ecbf415392b54d39a5b0f8fa +#: ../../tutorial.rst:936 +msgid "Debug Mode" +msgstr "调试模式" + +# beddc97c3d3a46128d1d358fa9860a4f +#: ../../tutorial.rst:938 +msgid "During early development, the debug mode can be very helpful." +msgstr "在开发的早期阶段,调试模式非常有用。" + +# 4d067f735f6849c69b69f7092ced9f3d +#: ../../tutorial.rst:946 +msgid "" +"In this mode, Bottle is much more verbose and provides helpful debugging " +"information whenever an error occurs. It also disables some optimisations " +"that might get in your way and adds some checks that warn you about possible " +"misconfiguration." +msgstr "" +"在调试模式下,当错误发生的时候,Bottle会提供更多的调试信息。同时禁用一些可能" +"妨碍你的优化措施,检查你的错误设置。" + +# 88a7c01d66fa4d00a6179489511b3c08 +#: ../../tutorial.rst:948 +msgid "Here is an incomplete list of things that change in debug mode:" +msgstr "下面是调试模式下会发生改变的东西,但这份列表不完整:" + +# f198b02a8b9e4bcba922758c41b795a0 +#: ../../tutorial.rst:950 +msgid "The default error page shows a traceback." +msgstr "默认的错误页面会打印出运行栈。" + +# 0c8afe5235804e03ba1bfbb6eb3345a9 +#: ../../tutorial.rst:951 +msgid "Templates are not cached." +msgstr "模板不会被缓存。" + +# c606f72bfa8d4612baecaa76fa2c6a03 +#: ../../tutorial.rst:952 +msgid "Plugins are applied immediately." +msgstr "插件马上生效。" + +# 36c92c3f00344262bb9ec61582c0a45a +#: ../../tutorial.rst:954 +msgid "Just make sure not to use the debug mode on a production server." +msgstr "请确保不要在生产环境中使用调试模式。" + +# 633e196fad4e4e8298aa83a76d0a7caf +#: ../../tutorial.rst:957 +msgid "Auto Reloading" +msgstr "自动加载" + +# 06cefa78a7b0460db417d659b6de9d0c +#: ../../tutorial.rst:959 +msgid "" +"During development, you have to restart the server a lot to test your recent " +"changes. The auto reloader can do this for you. Every time you edit a module " +"file, the reloader restarts the server process and loads the newest version " +"of your code." +msgstr "" +"在开发的时候,你需要不断地重启服务器来验证你最新的改动。自动加载功能可以替你" +"做这件事情。在你编辑完一个模块文件后,它会自动重启服务器进程,加载最新版本的" +"代码。" + +# e1789e3508fc4464bc48179d68195f5d +#: ../../tutorial.rst:969 +msgid "" +"How it works: the main process will not start a server, but spawn a new " +"child process using the same command line arguments used to start the main " +"process. All module-level code is executed at least twice! Be careful." +msgstr "" +"它的工作原理,主进程不会启动服务器,它使用相同的命令行参数,创建一个子进程来" +"启动服务器。请注意,所有模块级别的代码都被执行了至少两次。" + +# 0371ddb9c20e4305af0b378bd25be6a5 +#: ../../tutorial.rst:974 +msgid "" +"The child process will have ``os.environ['BOTTLE_CHILD']`` set to ``True`` " +"and start as a normal non-reloading app server. As soon as any of the loaded " +"modules changes, the child process is terminated and re-spawned by the main " +"process. Changes in template files will not trigger a reload. Please use " +"debug mode to deactivate template caching." +msgstr "" +"子进程中 ``os.environ['BOOTLE_CHILD']`` 变量的值被设为 ``True`` ,它运行一个" +"不会自动加载的服务器。在代码改变后,主进程会终止掉子进程,并创建一个新的子进" +"程。更改模板文件不会触发自动重载,请使用debug模式来禁用模板缓存。" + +# a0aa2201b61c42e98e5ee42ef24c4190 +#: ../../tutorial.rst:980 +msgid "" +"The reloading depends on the ability to stop the child process. If you are " +"running on Windows or any other operating system not supporting ``signal." +"SIGINT`` (which raises ``KeyboardInterrupt`` in Python), ``signal.SIGTERM`` " +"is used to kill the child. Note that exit handlers and finally clauses, " +"etc., are not executed after a ``SIGTERM``." +msgstr "" +"自动加载需要终止子进程。如果你运行在Windows等不支持 ``signal.SIGINT`` (会在" +"Python中raise ``KeyboardInterrupt`` 异常)的系统上,会使用 ``signal.SIGTERM`` " +"来杀掉子进程。在子进程被 ``SIGTERM`` 杀掉的时候,exit handlers和finally等语句" +"不会被执行。" + +# f8ff70c41030429b97bbe90c183aa69d +#: ../../tutorial.rst:988 +msgid "Command Line Interface" +msgstr "命令行接口" + +# fffbd64ca6b24cbfaa416c3041d9e0b1 +#: ../../tutorial.rst:992 +msgid "Starting with version 0.10 you can use bottle as a command-line tool:" +msgstr "从0.10版本开始,你可像一个命令行工具那样使用Bottle:" + +# a8137a8b8a854600add6c7567b68a739 +#: ../../tutorial.rst:1012 +msgid "" +"The `ADDRESS` field takes an IP address or an IP:PORT pair and defaults to " +"``localhost:8080``. The other parameters should be self-explanatory." +msgstr "" +"`ADDRESS` 参数接受一个IP地址或IP:端口,其默认为 ``localhost:8080`` 。其它参数" +"都很好地自我解释了。" + +# 228d8cb4991f41f4b4d8b33ccde95c44 +#: ../../tutorial.rst:1014 +msgid "" +"Both plugins and applications are specified via import expressions. These " +"consist of an import path (e.g. ``package.module``) and an expression to be " +"evaluated in the namespace of that module, separated by a colon. See :func:" +"`load` for details. Here are some examples:" +msgstr "" +"插件和应用都通过一个导入表达式来指定。包含了导入的路径(例如: ``package." +"module`` )和模块命名空间内的一个表达式,两者用\":\"分开。下面是一个简单例子," +"详见 :func:`load` 。" + +# 3311bcf9b73946988bec85594383ecc6 +#: ../../tutorial.rst:1035 +msgid "Deployment" +msgstr "部署" + +# 2af7083bba10428a97d840be3af4a90f +#: ../../tutorial.rst:1037 +msgid "" +"Bottle runs on the built-in `wsgiref WSGIServer `_ by default. This non-" +"threading HTTP server is perfectly fine for development and early " +"production, but may become a performance bottleneck when server load " +"increases." +msgstr "" +"Bottle默认运行在内置的 `wsgiref `_ 服务器上面。这个单线程的HTTP服务器在开" +"发的时候特别有用,但其性能低下,在服务器负载不断增加的时候也许会是性能瓶颈。" + +# 3b8f093cb75247ba98703d3f6a53b38e +#: ../../tutorial.rst:1039 +msgid "" +"The easiest way to increase performance is to install a multi-threaded " +"server library like paste_ or cherrypy_ and tell Bottle to use that instead " +"of the single-threaded server::" +msgstr "最早的解决办法是让Bottle使用 paste_ 或 cherrypy_ 等多线程的服务器。" + +# 2dab1b2ba89e4d33992277160d0591bf +#: ../../tutorial.rst:1043 +msgid "" +"This, and many other deployment options are described in a separate " +"article: :doc:`deployment`" +msgstr "在 :doc:`deployment` 章节中,会介绍更多部署的选择。" + +# f6100b0c14874bf28a2fe2009fae3846 +#: ../../tutorial.rst:1051 +msgid "Glossary" +msgstr "词汇表" + +# c6dd388daca143bfbebc280aeb9ea3f2 +#: ../../tutorial.rst:1056 +msgid "" +"Programmer code that is to be called when some external action happens. In " +"the context of web frameworks, the mapping between URL paths and application " +"code is often achieved by specifying a callback function for each URL." +msgstr "" + +# bea77197d67b495893c30d13330807de +#: ../../tutorial.rst:1062 +msgid "" +"A function returning another function, usually applied as a function " +"transformation using the ``@decorator`` syntax. See `python documentation " +"for function definition `_ for more about decorators." +msgstr "" + +# 4e70beaf89764630a38c322f4ae47a54 +#: ../../tutorial.rst:1065 +msgid "" +"A structure where information about all documents under the root is saved, " +"and used for cross-referencing. The environment is pickled after the " +"parsing stage, so that successive runs only need to read and parse new and " +"changed documents." +msgstr "" + +# b7f08dcc64534616abcba37e70692e71 +#: ../../tutorial.rst:1071 +msgid "" +"A function to handle some specific event or situation. In a web framework, " +"the application is developed by attaching a handler function as callback for " +"each specific URL comprising the application." +msgstr "" + +# 1693168184a043dc8b28ea6fc35aa2aa +#: ../../tutorial.rst:1076 +msgid "" +"The directory which, including its subdirectories, contains all source files " +"for one Sphinx project." +msgstr "" diff -Nru python-bottle-0.11.6/docs/_locale/zh_CN/tutorial_app.po python-bottle-0.12.0/docs/_locale/zh_CN/tutorial_app.po --- python-bottle-0.11.6/docs/_locale/zh_CN/tutorial_app.po 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/docs/_locale/zh_CN/tutorial_app.po 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,1243 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) 2009-2012, Marcel Hellkamp +# This file is distributed under the same license as the Bottle package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Bottle 0.12-dev\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-04-18 23:40\n" +"PO-Revision-Date: 2013-04-20 16:33+0800\n" +"Last-Translator: \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.5.5\n" + +# 33f6efd9369c46beb47afc690cadc6aa +#: ../../tutorial_app.rst:20 +msgid "Tutorial: Todo-List Application" +msgstr "Tutorial: Todo-List 应用" + +# 5e02cba798564557bbd71005f24eb16e +#: ../../tutorial_app.rst:24 +msgid "" +"This tutorial is a work in progess and written by `noisefloor `_." +msgstr "" +"这份教程是 `noisefloor `_ 编写的,并在不断完善" +"中。" + +# 6003a13ead9a4d758573f70028bd6f60 +#: ../../tutorial_app.rst:27 +msgid "" +"This tutorial should give a brief introduction to the Bottle_ WSGI " +"Framework. The main goal is to be able, after reading through this tutorial, " +"to create a project using Bottle. Within this document, not all abilities " +"will be shown, but at least the main and important ones like routing, " +"utilizing the Bottle template abilities to format output and handling GET / " +"POST parameters." +msgstr "" +"这份教程简单介绍了Bottle框架,目的是让你看完后能在项目中使用Bottle。它没有涵" +"盖所有东西,但介绍了URL映射,模板,处理GET/POST请求等基础知识。" + +# 22bf2cadd46d4378808435ba0be98287 +#: ../../tutorial_app.rst:29 +msgid "" +"To understand the content here, it is not necessary to have a basic " +"knowledge of WSGI, as Bottle tries to keep WSGI away from the user anyway. " +"You should have a fair understanding of the Python_ programming language. " +"Furthermore, the example used in the tutorial retrieves and stores data in a " +"SQL databse, so a basic idea about SQL helps, but is not a must to " +"understand the concepts of Bottle. Right here, SQLite_ is used. The output " +"of Bottle sent to the browser is formatted in some examples by the help of " +"HTML. Thus, a basic idea about the common HTML tags does help as well." +msgstr "" +"读懂这份教程,你不需要事先了解WSGI标准,Bottle也一直避免用户直接接触WSGI标" +"准。但你需要了解 Python_ 这门语言。更进一步,这份教程中的例子需要从SQL数据库" +"中读写数据,所以事先了解一点SQL知识是很有帮助的。例子中使用了 SQLite_ 来保存" +"数据。因为是网页应用,所以事先了解一点HTML的知识也很有帮助。" + +# 2b6a3a7d250b4913bc353df9a12ade2c +#: ../../tutorial_app.rst:31 +msgid "" +"For the sake of introducing Bottle, the Python code \"in between\" is kept " +"short, in order to keep the focus. Also all code within the tutorial is " +"working fine, but you may not necessarily use it \"in the wild\", e.g. on a " +"public web server. In order to do so, you may add e.g. more error handling, " +"protect the database with a password, test and escape the input etc." +msgstr "" +"作为一份教程,我们的代码尽可能做到了简明扼要。尽管教程中的代码能够工作,但是" +"我们还是不建议你在公共服务器中使用教程中的代码。如果你想要这样做,你应该添加" +"足够的错误处理,并且加密你的数据库,处理用户的输入。" + +# 6a190d7af9be4d54967f33e24602f9dc +#: ../../tutorial_app.rst:36 +msgid "Goals" +msgstr "目标" + +# 61aed1ec611441218bf18445689ee07a +#: ../../tutorial_app.rst:38 +msgid "" +"At the end of this tutorial, we will have a simple, web-based ToDo list. The " +"list contains a text (with max 100 characters) and a status (0 for closed, 1 " +"for open) for each item. Through the web-based user interface, open items " +"can be view and edited and new items can be added." +msgstr "" +"在这份教程结束的时候,我们将完成一个简单的,基于Web的ToDo list(待办事项列" +"表)。列表中的每一个待办事项都包含一条文本(最长100个字符)和一个状态(0表示关" +"闭,1表示开启)。通过网页,已开启的待办事项可以被查看和编辑,可添加待办事项到" +"列表中。" + +# 1e835235e608458f802217fcf7e23895 +#: ../../tutorial_app.rst:40 +msgid "" +"During development, all pages will be available on ``localhost`` only, but " +"later on it will be shown how to adapt the application for a \"real\" " +"server, including how to use with Apache's mod_wsgi." +msgstr "" +"在开发过程中,所有的页面都只可以通过 ``localhost`` 来访问,完了会介绍如何将应" +"用部署到\"真实\"服务器的服务器上面,包括使用mod_wsgi来部署到Apache服务器上" +"面。" + +# 6c65124252a9440ab2df2e1bd221f375 +#: ../../tutorial_app.rst:42 +msgid "" +"Bottle will do the routing and format the output, with the help of " +"templates. The items of the list will be stored inside a SQLite database. " +"Reading and writing the database will be done by Python code." +msgstr "" +"Bottle会负责URL映射,通过模板来输出页面。待办事项列表被存储在一个SQLite数据库" +"中,通过Python代码来读写数据库。" + +# 0944d70a1997491caff38dd5d93aebe3 +#: ../../tutorial_app.rst:44 +msgid "" +"We will end up with an application with the following pages and " +"functionality:" +msgstr "我们会完成以下页面和功能:" + +# c523c5db9f3f44b8a19cfe5de6f134df +#: ../../tutorial_app.rst:46 +msgid "start page ``http://localhost:8080/todo``" +msgstr "首页 ``http://localhost:8080/todo``" + +# fbca5f7daa22435b8dcb3eabdbcce7ac +#: ../../tutorial_app.rst:47 +msgid "adding new items to the list: ``http://localhost:8080/new``" +msgstr "添加待办事项: ``http://localhost:8080/new``" + +# 121068a736f148a181737468820d2f9b +#: ../../tutorial_app.rst:48 +msgid "page for editing items: ``http://localhost:8080/edit/:no``" +msgstr "编辑待办事项: ``http://localhost:8080/edit/:no``" + +# ca05034317a74dd18209b177cd1fc435 +#: ../../tutorial_app.rst:49 +msgid "validating data assigned by dynamic routes with the @validate decorator" +msgstr "通过 @validate 修饰器来验证数据合法性" + +# 22ddb4e4ee0f48fdac8d0e318fb02d6a +#: ../../tutorial_app.rst:50 +msgid "catching errors" +msgstr "捕获错误" + +# 16b50abf41ca4af9a7dfa2190e0b4353 +#: ../../tutorial_app.rst:53 +msgid "Before We Start..." +msgstr "开始之前..." + +# 88685e43902242e79b72e32f78a21807 +#: ../../tutorial_app.rst:57 +msgid "Install Bottle" +msgstr "安装Bottle" + +# 54e8fafdb3604508bc4a8890efedcf74 +#: ../../tutorial_app.rst:58 +msgid "" +"Assuming that you have a fairly new installation of Python (version 2.5 or " +"higher), you only need to install Bottle in addition to that. Bottle has no " +"other dependencies than Python itself." +msgstr "" +"假设你已经安装好了Python (2.5或更改版本),接下来你只需要下载Bottle就行了。除" +"了Python标准库,Bottle没有其他依赖。" + +# 28c00a8e7a454bf7ae1ae555c13f8968 +#: ../../tutorial_app.rst:60 +msgid "" +"You can either manually install Bottle or use Python's easy_install: " +"``easy_install bottle``" +msgstr "你可通过Python的esay_install命令来安装Bottle: ``easy_install bottle``" + +# e7572cbb352b4b6099677a411624333b +#: ../../tutorial_app.rst:64 +msgid "Further Software Necessities" +msgstr "其它软件" + +# 586d64a3734045e998e88bd43971379a +#: ../../tutorial_app.rst:65 +msgid "" +"As we use SQLite3 as a database, make sure it is installed. On Linux " +"systems, most distributions have SQLite3 installed by default. SQLite is " +"available for Windows and MacOS X as well and the `sqlite3` module is part " +"of the python standard library." +msgstr "" +"因为我们使用SQLite3来做数据库,请确保它已安装。如果是Linux系统,大多数的发行" +"版已经默认安装了SQLite3。SQLite同时可工作在Windows系统和MacOS X系统上面。" +"Pyhton标准库中,已经包含了 `sqlite3` 模块。" + +# 72c5dfc6ac694092875803468c604fde +#: ../../tutorial_app.rst:68 +msgid "Create An SQL Database" +msgstr "创建一个SQL数据库" + +# 65ded72179ed4705a81737de75409869 +#: ../../tutorial_app.rst:69 +msgid "" +"First, we need to create the database we use later on. To do so, save the " +"following script in your project directory and run it with python. You can " +"use the interactive interpreter too::" +msgstr "" +"首先,我们需要先创建一个数据库,稍后会用到。在你的项目文件夹执行以下脚本即" +"可,你也可以在Python解释器逐条执行。" + +# 150ebaeb8a3c4d2ca1e42616c9ca9e75 +#: ../../tutorial_app.rst:80 +msgid "" +"This generates a database-file `todo.db` with tables called ``todo`` and " +"three columns ``id``, ``task``, and ``status``. ``id`` is a unique id for " +"each row, which is used later on to reference the rows. The column ``task`` " +"holds the text which describes the task, it can be max 100 characters long. " +"Finally, the column ``status`` is used to mark a task as open (value 1) or " +"closed (value 0)." +msgstr "" +"现在,我们已经创建了一个名字为 `todo.db` 的数据库文件,数据库中有一张名为 " +"``todo`` 的表,表中有 ``id`` , ``task`` , 及 ``status`` 这三列。每一行的 " +"``id`` 都是唯一的,稍后会根据id来获取数据。 ``task`` 用于保存待办事项的文本," +"最大长度为100个字符。最后 ``status`` 用于标明待办事项的状态,0为开启,1为关" +"闭。" + +# 7be5bf82c1cb4eb69c77b151a92ae734 +#: ../../tutorial_app.rst:83 +msgid "Using Bottle for a Web-Based ToDo List" +msgstr "基于Bottle的待办事项列表" + +# 0f6daaf3308a46198eff9a049aa842ce +#: ../../tutorial_app.rst:85 +msgid "" +"Now it is time to introduce Bottle in order to create a web-based " +"application. But first, we need to look into a basic concept of Bottle: " +"routes." +msgstr "" +"为了创建我们的Web应用,我们先来介绍一下Bottle框架。首先,我们需要了解Bottle中" +"的route,即URL映射。" + +# 5b94e765fa7d4218a7b8ad3af776d386 +#: ../../tutorial_app.rst:89 +msgid "Understanding routes" +msgstr "route URL映射" + +# 8f81852706e7447fac6053f38705ed10 +#: ../../tutorial_app.rst:90 +msgid "" +"Basically, each page visible in the browser is dynamically generated when " +"the page address is called. Thus, there is no static content. That is " +"exactly what is called a \"route\" within Bottle: a certain address on the " +"server. So, for example, when the page ``http://localhost:8080/todo`` is " +"called from the browser, Bottle \"grabs\" the call and checks if there is " +"any (Python) function defined for the route \"todo\". If so, Bottle will " +"execute the corresponding Python code and return its result." +msgstr "" +"基本上,浏览器访问的每一页面都是动态生成的。Bottle通过route,将浏览器访问的" +"URL映射到具体的Python函数。例如,在我们访问 ``http://localhost:8080/todo`` " +"的时候,Bottle会查找 ``todo`` 这个route映射到了哪个函数上面,接着调用该函数来" +"响应浏览器请求。" + +# 5534b80b80e548808db820371f387aab +#: ../../tutorial_app.rst:94 +msgid "First Step - Showing All Open Items" +msgstr "第一步 - 显示所有已开启的待办事项" + +# 532c3ca7275841f7a96378be03723bc2 +#: ../../tutorial_app.rst:95 +msgid "" +"So, after understanding the concept of routes, let's create the first one. " +"The goal is to see all open items from the ToDo list::" +msgstr "" +"在我们了解什么是route后,让我们来试着写一个。访问它即可查看所有已开启的待办事" +"项 ::" + +# cdffb14736c64dab93796dccf44aa407 +#: ../../tutorial_app.rst:110 +msgid "" +"Save the code a ``todo.py``, preferably in the same directory as the file " +"``todo.db``. Otherwise, you need to add the path to ``todo.db`` in the " +"``sqlite3.connect()`` statement." +msgstr "" +"将上面的代码保存为 ``todo.py`` ,放到 ``todo.db`` 文件所在的目录。如果你想将" +"它们分开放,则需要在 ``sqlite3.connect()`` 函数中写上 ``todo.db`` 文件的路" +"径。" + +# 4450c8afe80341b880e89cd44531dc76 +#: ../../tutorial_app.rst:112 +msgid "" +"Let's have a look what we just did: We imported the necessary module " +"``sqlite3`` to access to SQLite database and from Bottle we imported " +"``route`` and ``run``. The ``run()`` statement simply starts the web server " +"included in Bottle. By default, the web server serves the pages on localhost " +"and port 8080. Furthermore, we imported ``route``, which is the function " +"responsible for Bottle's routing. As you can see, we defined one function, " +"``todo_list()``, with a few lines of code reading from the database. The " +"important point is the `decorator statement`_ ``@route('/todo')`` right " +"before the ``def todo_list()`` statement. By doing this, we bind this " +"function to the route ``/todo``, so every time the browsers calls ``http://" +"localhost:8080/todo``, Bottle returns the result of the function " +"``todo_list()``. That is how routing within bottle works." +msgstr "" +"来看看我们写的代码。导入了必须的 ``sqlite3`` 模块,从Bottle中导入 ``route`` " +"和 ``run`` 。``run()`` 函数启动了Bottle的内置开发服务器,默认情况下,开发服务" +"器在监听本地的8080端口。``route`` 是Bottle实现URL映射功能的修饰器。你可以看" +"到,我们定义了一个 ``todo_list()`` 函数,读取了数据库中的数据。然后我们使用 " +"``@route('/todo')`` 来将 ``todo_list()`` 函数和``todo`` 这个route绑定在一起。" +"每一次浏览器访问 ``http://localhost:8080/todo`` 的时候,Bottle都会调用 " +"``todo_list()`` 函数来响应请求,并返回页面,这就是route的工作方式了。" + +# 79bfb2ad57754b6e929e29ae17fe965b +#: ../../tutorial_app.rst:114 +msgid "" +"Actually you can bind more than one route to a function. So the following " +"code::" +msgstr "事实上,你可以给一个函数添加多个route。" + +# bd1d1738e2774b9ba3ab4c73a13e7fdf +#: ../../tutorial_app.rst:121 +msgid "" +"will work fine, too. What will not work is to bind one route to more than " +"one function." +msgstr "这样是正确的。但是反过来,你不能将一个route和多个函数绑定在一起。" + +# 7b8c8d0300ea44a6a7b3b98a2c52d96b +#: ../../tutorial_app.rst:123 +msgid "" +"What you will see in the browser is what is returned, thus the value given " +"by the ``return`` statement. In this example, we need to convert ``result`` " +"in to a string by ``str()``, as Bottle expects a string or a list of strings " +"from the return statement. But here, the result of the database query is a " +"list of tuples, which is the standard defined by the `Python DB API`_." +msgstr "" +"你在浏览器中看到的即是你在 ``todo_list()`` 函数中返回的页面。在这个例子中,我" +"们通过 ``str()`` 函数将结果转换成字符串,因为Bottle期望函数的返回值是一个字符" +"串或一个字符串的列表。但 `Python DB API`_ 中规定了,数据库查询的返回值是一个" +"元组的列表。" + +# 3eb85b613f0e419b9278913da80adc27 +#: ../../tutorial_app.rst:125 +msgid "" +"Now, after understanding the little script above, it is time to execute it " +"and watch the result yourself. Remember that on Linux- / Unix-based systems " +"the file ``todo.py`` needs to be executable first. Then, just run ``python " +"todo.py`` and call the page ``http://localhost:8080/todo`` in your browser. " +"In case you made no mistake writing the script, the output should look like " +"this::" +msgstr "" +"现在,我们已经了解上面的代码是如何工作的,是时候运行它来看看效果了。记得在" +"Linux或Unix系统中, ``todo.py`` 文件需要标记为可执行(译者注:没有必要)。然" +"后,通过 ``python todo.py`` 命令来执行该脚本,接着用浏览器访问 ``http://" +"localhost:8080/todo`` 来看看效果。如果代码没有写错,你应该会在页面看到以下输" +"出 ::" + +# 24d491d21b02450394da44957aa3f106 +#: ../../tutorial_app.rst:129 +msgid "" +"If so - congratulations! You are now a successful user of Bottle. In case it " +"did not work and you need to make some changes to the script, remember to " +"stop Bottle serving the page, otherwise the revised version will not be " +"loaded." +msgstr "" +"如果是这样,那么恭喜你!如果出现错误,那么你需要检查代码时候写错,修改完后记" +"得重启HTTP服务器,要不新的版本不会生效。" + +# c382bdb5320442b7a7a5b9f92017bef4 +#: ../../tutorial_app.rst:131 +msgid "" +"Actually, the output is not really exciting nor nice to read. It is the raw " +"result returned from the SQL query." +msgstr "实际上,这个输出很难看,只是SQL查询的结果。" + +# 6eb7e9c0101b450493e3a27d7fe59da9 +#: ../../tutorial_app.rst:133 +msgid "" +"So, in the next step we format the output in a nicer way. But before we do " +"that, we make our life easier." +msgstr "所以,下一步我们会把它变得更好看。" + +# 59206fc4b0c246ac83eaa6ee2c7a3f53 +#: ../../tutorial_app.rst:137 +msgid "Debugging and Auto-Reload" +msgstr "调试和自动加载" + +# 85f588398f4c45ee913545fa8e744178 +#: ../../tutorial_app.rst:138 +msgid "" +"Maybe you already noticed that Bottle sends a short error message to the " +"browser in case something within the script is wrong, e.g. the connection to " +"the database is not working. For debugging purposes it is quite helpful to " +"get more details. This can be easily achieved by adding the following " +"statement to the script::" +msgstr "" +"或许你已经注意到了,如果代码出错的话,Bottle会在页面上显示一个简短的错误信" +"息。例如,连接数据库失败。为了方便调试, 我们希望错误信息更加具体,可加上以下" +"语句。" + +# c57a72336d574acf8102bf72b5a7c989 +#: ../../tutorial_app.rst:146 +msgid "" +"By enabling \"debug\", you will get a full stacktrace of the Python " +"interpreter, which usually contains useful information for finding bugs. " +"Furthermore, templates (see below) are not cached, thus changes to templates " +"will take effect without stopping the server." +msgstr "" +"开启调试模式后,出错时页面会打印出完整的Python运行栈。另外,在调试模式下,模" +"板也不会被缓存,任何对模板的修改会马上生效,而不用重启服务器。" + +# fe2e51b6779a4da3a62748c753690c01 +#: ../../tutorial_app.rst:150 +msgid "" +"That ``debug(True)`` is supposed to be used for development only, it should " +"*not* be used in production environments." +msgstr "" +"``debug(True)`` 是为开发时的调试服务的, *不应* 在生产环境中开启调试模式。" + +# 480e31a5104a47d896b7b97d9b67039b +#: ../../tutorial_app.rst:154 +msgid "" +"Another quite nice feature is auto-reloading, which is enabled by modifying " +"the ``run()`` statement to" +msgstr "另外一个十分有用的功能是自动加载,可修改 ``run()`` 语句来开启。" + +# 071cfe7d8836472487497e32f1640e30 +#: ../../tutorial_app.rst:160 +msgid "" +"This will automatically detect changes to the script and reload the new " +"version once it is called again, without the need to stop and start the " +"server." +msgstr "这样会自动检测对脚本的修改,并自动重启服务器来使其生效。" + +# 456c2314e499418181dc936efc631ae6 +#: ../../tutorial_app.rst:162 +msgid "" +"Again, the feature is mainly supposed to be used while developing, not on " +"production systems." +msgstr "同上,这个功能并不建议在生产环境中使用。" + +# 13bb322f8d344ecea4c265986221d2bb +#: ../../tutorial_app.rst:166 +msgid "Bottle Template To Format The Output" +msgstr "使用模板来格式化输出" + +# 0a99c9684d44461ab1b5c3642ae6da87 +#: ../../tutorial_app.rst:167 +msgid "" +"Now let's have a look at casting the output of the script into a proper " +"format." +msgstr "现在我们试着格式化脚本的输出,使其更适合查看。" + +# 9ae9be05bf6e49db8b7a45882d39b16b +#: ../../tutorial_app.rst:169 +msgid "" +"Actually Bottle expects to receive a string or a list of strings from a " +"function and returns them by the help of the built-in server to the browser. " +"Bottle does not bother about the content of the string itself, so it can be " +"text formatted with HTML markup, too." +msgstr "" +"实际上,Bottle期望route的回调函数返回一个字符串或一个字符串列表,通过内置的" +"HTTP服务器将其返回给浏览器。Bottle不关心字符串的内容,所以我们可以将其格式化" +"成HTML格式。" + +# 0c17f1f618884dfdbf0a539a2da7e6af +#: ../../tutorial_app.rst:171 +msgid "" +"Bottle brings its own easy-to-use template engine with it. Templates are " +"stored as separate files having a ``.tpl`` extension. The template can be " +"called then from within a function. Templates can contain any type of text " +"(which will be most likely HTML-markup mixed with Python statements). " +"Furthermore, templates can take arguments, e.g. the result set of a database " +"query, which will be then formatted nicely within the template." +msgstr "" +"Bottle内置了独创的模板引擎。模板是后缀名为 ``.tpl`` 的文本文件。模板的内容混" +"合着HTML标签和Python语句,模板也可以接受参数。例如数据库的查询结果,我们可以" +"在模板内将其漂亮地格式化。" + +# 97a2c49b81994568933da9e6203217b5 +#: ../../tutorial_app.rst:173 +msgid "" +"Right here, we are going to cast the result of our query showing the open " +"ToDo items into a simple table with two columns: the first column will " +"contain the ID of the item, the second column the text. The result set is, " +"as seen above, a list of tuples, each tuple contains one set of results." +msgstr "" +"接下来,我们要将数据库的查询结果格式化为一个两列的表格。表格的第一列为待办事" +"项的ID,第二列为待办事项的内容。查询结果是一个元组的列表,列表中的每个元组后" +"包含一个结果。" + +# 4a3105cdfd8c481cbff0599b533f145e +#: ../../tutorial_app.rst:175 +msgid "To include the template in our example, just add the following lines::" +msgstr "在例子中使用模板,只需要添加以下代码。" + +# e2a9433c9fe9426aa01d5e27299705b3 +#: ../../tutorial_app.rst:185 +msgid "" +"So we do here two things: first, we import ``template`` from Bottle in order " +"to be able to use templates. Second, we assign the output of the template " +"``make_table`` to the variable ``output``, which is then returned. In " +"addition to calling the template, we assign ``result``, which we received " +"from the database query, to the variable ``rows``, which is later on used " +"within the template. If necessary, you can assign more than one variable / " +"value to a template." +msgstr "" +"我们添加了两样东西。首先我们从Bottle中导入了 ``template`` 函数以使用模板功" +"能,接着,我们渲染 ``make_table`` 这个模板(参数是rows=result),把模板函数的返" +"回值赋予 ``output`` 变量,并返回 ``output`` 。如有必要,我们可添加更多的参" +"数。" + +# 545f68345a424c89ad435116fdc482d4 +#: ../../tutorial_app.rst:187 +msgid "" +"Templates always return a list of strings, thus there is no need to convert " +"anything. Of course, we can save one line of code by writing ``return " +"template('make_table', rows=result)``, which gives exactly the same result " +"as above." +msgstr "" +"模板总是返回一个字符串的列表,所以我们无须转换任何东西。当然,我们可以将返回" +"写为一行以减少代码量。" + +# 0269d21c4f24477aa7ce270cd93056bd +#: ../../tutorial_app.rst:189 +msgid "" +"Now it is time to write the corresponding template, which looks like this::" +msgstr "对应的模板文件。" + +# 24ba324725984083890dd3551b8b9c42 +#: ../../tutorial_app.rst:203 +msgid "" +"Save the code as ``make_table.tpl`` in the same directory where ``todo.py`` " +"is stored." +msgstr "" +"将上面的代码保存为 ``make_table.tpl`` 文件,和 ``todo.py`` 放在同一个目录。" + +# eba0a675db304d9bb085206d3725575f +#: ../../tutorial_app.rst:205 +msgid "" +"Let's have a look at the code: every line starting with % is interpreted as " +"Python code. Please note that, of course, only valid Python statements are " +"allowed, otherwise the template will raise an exception, just as any other " +"Python code. The other lines are plain HTML markup." +msgstr "" +"看看上面的代码,以%开头的行被当作Python代码来执行。请注意,只有正确的Python语" +"句才能通过编译,要不模板就会抛出一个异常。除了Python语句,其它都是普通的HTML" +"标记。" + +# dc25591c1bcd42f4a0df95eeb495ac67 +#: ../../tutorial_app.rst:207 +msgid "" +"As you can see, we use Python's ``for`` statement two times, in order to go " +"through ``rows``. As seen above, ``rows`` is a variable which holds the " +"result of the database query, so it is a list of tuples. The first ``for`` " +"statement accesses the tuples within the list, the second one the items " +"within the tuple, which are put each into a cell of the table. It is " +"important that you close all ``for``, ``if``, ``while`` etc. statements with " +"``%end``, otherwise the output may not be what you expect." +msgstr "" +"如你所见,为了遍历 ``rows`` ,我们两次使用了Python的 ``for`` 语句。 ``rows``" +"是持有查询结果的变量,一个元组的列表。第一个 ``for`` 语句遍历了列表中所有的元" +"组,第二个 ``for`` 语句遍历了元组中的元素,将其放进表格中。 ``for`` , " +"``if`` , ``while`` 语句都需要通过 ``%end`` 来关闭,要不会得到不正确的结果。" + +# 34fdad98dea542aea3e88022d685ac98 +#: ../../tutorial_app.rst:209 +msgid "" +"If you need to access a variable within a non-Python code line inside the " +"template, you need to put it into double curly braces. This tells the " +"template to insert the actual value of the variable right in place." +msgstr "" +"如果想要在不以%开头的行中访问变量,则需要把它放在两个大括号中间。这告诉模板," +"需要用变量的实际值将其替换掉。" + +# 2864ce8ac7e5418da07d68ddffc20787 +#: ../../tutorial_app.rst:211 +msgid "" +"Run the script again and look at the output. Still not really nice, but at " +"least more readable than the list of tuples. Of course, you can spice-up the " +"very simple HTML markup above, e.g. by using in-line styles to get a better " +"looking output." +msgstr "" +"再次运行这个脚本,页面输出依旧不是很好看,但是更具可读性了。当然,你可给模板" +"中的HTML标签加上CSS样式,使其更好看。" + +# ff8121af37f7485896b4956951e0813b +#: ../../tutorial_app.rst:215 +msgid "Using GET and POST Values" +msgstr "使用GET和POST" + +# f6c9315f251e498194f0b25bf0204f9e +#: ../../tutorial_app.rst:216 +msgid "" +"As we can review all open items properly, we move to the next step, which is " +"adding new items to the ToDo list. The new item should be received from a " +"regular HTML-based form, which sends its data by the GET method." +msgstr "" +"能够查看所有代码事项后,让我们进入到下一步,添加新的待办事项到列表中。新的待" +"办事项应该在一个常规的HTML表单中,通过GET方式提交。" + +# c3af488757174457ac7ec8657f97879b +#: ../../tutorial_app.rst:218 +msgid "" +"To do so, we first add a new route to our script and tell the route that it " +"should get GET data::" +msgstr "让我们先来添加一个接受GET请求的route。" + +# 2a9392c169a346b7bcb493d1b453938b +#: ../../tutorial_app.rst:241 +msgid "" +"To access GET (or POST) data, we need to import ``request`` from Bottle. To " +"assign the actual data to a variable, we use the statement ``request.GET." +"get('task','').strip()`` statement, where ``task`` is the name of the GET " +"data we want to access. That's all. If your GET data has more than one " +"variable, multiple ``request.GET.get()`` statements can be used and assigned " +"to other variables." +msgstr "" +"为了访问GET(或POST)中的数据,我们需要从Bottle中导入 ``request`` ,通过 " +"``request.GET.get('task', '').strip()`` 来获取表单中 ``task`` 字段的数据。可" +"多次使用 ``request.GET.get()`` 来获取表单中所有字段的数据。" + +# e9e17b587008432aaf88d25622ad7e5b +#: ../../tutorial_app.rst:243 +msgid "" +"The rest of this piece of code is just processing of the gained data: " +"writing to the database, retrieve the corresponding id from the database and " +"generate the output." +msgstr "接下来是对数据的操作:写入数据库,获取返回的ID,生成页面。" + +# d2067817a8c948c19ef29cf2edb8d328 +#: ../../tutorial_app.rst:245 +msgid "" +"But where do we get the GET data from? Well, we can use a static HTML page " +"holding the form. Or, what we do right now, is to use a template which is " +"output when the route ``/new`` is called without GET data." +msgstr "" +"因为我们是从HTML表单中获取数据,所以现在让我们来创建这个表单吧。我们通过 ``/" +"new`` 这个URL来添加待办事项。" + +# 20a5622fd4194f51b94c1f841711b79c +#: ../../tutorial_app.rst:247 +msgid "The code needs to be extended to::" +msgstr "代码需要扩展如下::" + +# b4c548eda6e74186b888e6bda5838b2c +#: ../../tutorial_app.rst:270 +msgid "``new_task.tpl`` looks like this::" +msgstr "对应的 ``new_task.tpl`` 模板如下。" + +# 949416e9e08a40718188beecd6e075e3 +#: ../../tutorial_app.rst:278 +msgid "That's all. As you can see, the template is plain HTML this time." +msgstr "如你所见,这个模板只是纯HTML的,不包含Python代码。" + +# 235fdb2fa17e416e93578ff297d8ec3e +#: ../../tutorial_app.rst:280 +msgid "Now we are able to extend our to do list." +msgstr "这样,我们就完成了添加待办事项这个功能。" + +# 0bee824f8fb042149632f02ac6844c99 +#: ../../tutorial_app.rst:282 +msgid "" +"By the way, if you prefer to use POST data: this works exactly the same way, " +"just use ``request.POST.get()`` instead." +msgstr "" +"如果你想通过POST来获取数据,那么用 ``request.POST.get()`` 来代替 ``request." +"GET.get()`` 就行了。" + +# c0eb38c6227e4e1e805e656c91d557aa +#: ../../tutorial_app.rst:286 +msgid "Editing Existing Items" +msgstr "修改已有待办事项" + +# 0b4637ba1c1a4b95ad03d35a4b2f5c12 +#: ../../tutorial_app.rst:287 +msgid "The last point to do is to enable editing of existing items." +msgstr "最后,我们需要做的是修改已有待办事项。" + +# 380878bd9d2a4488818c6d0bd6f26819 +#: ../../tutorial_app.rst:289 +msgid "" +"By using only the routes we know so far it is possible, but may be quite " +"tricky. But Bottle knows something called \"dynamic routes\", which makes " +"this task quite easy." +msgstr "" +"仅使用我们当前了解到的route类型,是可以完成这个任务的,但太取巧了。Bottle还提" +"供了一种 ``动态route`` ,可以更简单地实现。" + +# 8aa8d7b4876e408a86292035c6d93ded +#: ../../tutorial_app.rst:291 +msgid "The basic statement for a dynamic route looks like this::" +msgstr "基本的动态route声明如下::" + +# f36d97bf043647a4b454c6f2a789a1fc +#: ../../tutorial_app.rst:295 +msgid "" +"The key point here is the colon. This tells Bottle to accept for ``:" +"something`` any string up to the next slash. Furthermore, the value of " +"``something`` will be passed to the function assigned to that route, so the " +"data can be processed within the function." +msgstr "" +"关键的区别在于那个冒号。它告诉了Bottle,在下一个 ``/`` 之前, ``:something`` " +"可以匹配任何字符串。 ``:something`` 匹配到的字符串会传递给回调函数,进一步地" +"处理。" + +# 4999fb90d3b743deb982a1abe7d9771f +#: ../../tutorial_app.rst:297 +msgid "" +"For our ToDo list, we will create a route ``@route('/edit/:no)``, where " +"``no`` is the id of the item to edit." +msgstr "" +"在我们的待办事项应用里,我们创建一个route( ``@route('edit/:no')`` ), ``no`` " +"是待办事项在数据库里面的ID。" + +# 2ecc9a1563ab426fb68c6299e886a128 +#: ../../tutorial_app.rst:299 +msgid "The code looks like this::" +msgstr "对应的代码如下。" + +# f732d8247ed24ab8a800e66cd42df2b9 +#: ../../tutorial_app.rst:327 +msgid "" +"It is basically pretty much the same what we already did above when adding " +"new items, like using ``GET`` data etc. The main addition here is using the " +"dynamic route ``:no``, which here passes the number to the corresponding " +"function. As you can see, ``no`` is used within the function to access the " +"right row of data within the database." +msgstr "" +"这和之前的添加待办事项类似,主要的不同点在于使用了动态的route( ``:no`` ),它" +"可将ID传给route对应的回调函数。如你所见,我们在 ``edit_item`` 函数中使用了 " +"``no`` ,从数据库中获取数据。" + +# ad9992e34da14bd7baeaed15518f3489 +#: ../../tutorial_app.rst:329 +msgid "" +"The template ``edit_task.tpl`` called within the function looks like this::" +msgstr "对应的 ``edit_task.tpl`` 模板如下。" + +# e0f6865889c54cd6bc8f1b5be0655eec +#: ../../tutorial_app.rst:344 +msgid "" +"Again, this template is a mix of Python statements and HTML, as already " +"explained above." +msgstr "再一次,模板中混合了HTML代码和Python代码,之前已解释过。" + +# aab99f56f12c4e138a2edb22f7084a83 +#: ../../tutorial_app.rst:346 +msgid "" +"A last word on dynamic routes: you can even use a regular expression for a " +"dynamic route, as demonstrated later." +msgstr "你也可在动态route中使用正则表达式,稍后会提及。" + +# 923e0a3748a948b18a3ba4f2247638ca +#: ../../tutorial_app.rst:350 +msgid "Validating Dynamic Routes" +msgstr "验证动态route" + +# ffee65c793f84aa88663c1a97fdc4068 +#: ../../tutorial_app.rst:351 +msgid "" +"Using dynamic routes is fine, but for many cases it makes sense to validate " +"the dynamic part of the route. For example, we expect an integer number in " +"our route for editing above. But if a float, characters or so are received, " +"the Python interpreter throws an exception, which is not what we want." +msgstr "" +"在某些场景下,需要验证route中的可变部分。例如,在上面的例子中,我们的 ``no`` " +"需要是一个整形数,如果我们的输入是一个浮点数,或字符串,Python解释器将会抛出" +"一个异常,这并不是我们想要的结果。" + +# 29e1484f1af446d5b7bcc106ad614ef3 +#: ../../tutorial_app.rst:353 +msgid "" +"For those cases, Bottle offers the ``@validate`` decorator, which validates " +"the \"input\" prior to passing it to the function. In order to apply the " +"validator, extend the code as follows::" +msgstr "" +"对应上述情况,Bottle提供了一个 ``@validate`` 修饰器,可在用户输入被传递给回调" +"函数之前,检验用户数据的合法性。代码例子如下。" + +# c0a2df587e2f4047859737a31f36c673 +#: ../../tutorial_app.rst:362 +msgid "" +"At first, we imported ``validate`` from the Bottle framework, than we apply " +"the @validate-decorator. Right here, we validate if ``no`` is an integer. " +"Basically, the validation works with all types of data like floats, lists " +"etc." +msgstr "" +"首先,我们从Bottle中导入了 ``validate`` ,然后在route中使用了。在这里,我们验" +"证 ``no`` 是否是一个整形数。基本上, ``validate`` 可用于其它类型,例如浮点" +"数,列表等等。" + +# 5591d095ba054eaaa647e21284a6763c +#: ../../tutorial_app.rst:364 +msgid "" +"Save the code and call the page again using a \"403 forbidden\" value for ``:" +"no``, e.g. a float. You will receive not an exception, but a \"403 - " +"Forbidden\" error, saying that an integer was expected." +msgstr "" +"保存更改,如果用户提供的 ``:no`` 不是一个整形数,而是一个浮点数或其他类型,将" +"返回一个\"403 forbidden\"页面,而不是抛出异常。" + +# 54de0a9c2bc94b41b9dadd76c39464f3 +#: ../../tutorial_app.rst:367 +msgid "Dynamic Routes Using Regular Expressions" +msgstr "在动态route中使用正则表达式" + +# ccab93ff8c0c47e0a176fb7a0c7627f1 +#: ../../tutorial_app.rst:368 +msgid "" +"Bottle can also handle dynamic routes, where the \"dynamic part\" of the " +"route can be a regular expression." +msgstr "Bottle允许在动态route中使用正则表达式。" + +# dfb8297508ff4b2097b5ea4a7ef1fc46 +#: ../../tutorial_app.rst:370 +msgid "" +"So, just to demonstrate that, let's assume that all single items in our ToDo " +"list should be accessible by their plain number, by a term like e.g. " +"\"item1\". For obvious reasons, you do not want to create a route for every " +"item. Furthermore, the simple dynamic routes do not work either, as part of " +"the route, the term \"item\" is static." +msgstr "" +"我们假设需要通过 ``item1`` 这样的形式来访问数据库中id为1的待办事项。显然,我" +"们不想为每个待办事项都创建一个route。鉴于route中的\"item\"部分是固定的,简单" +"的route就无法满足需求了,我们需要在route中使用正则表达式。" + +# 20e841ae29e34531b875732af4ca53c8 +#: ../../tutorial_app.rst:372 +msgid "As said above, the solution is a regular expression::" +msgstr "使用正则表达式的解决方法如下。" + +# d558ba77788843fa889a565704221a3a +#: ../../tutorial_app.rst:386 +msgid "" +"Of course, this example is somehow artificially constructed - it would be " +"easier to use a plain dynamic route only combined with a validation. " +"Nevertheless, we want to see how regular expression routes work: the line " +"``@route(/item:item_#[0-9]+#)`` starts like a normal route, but the part " +"surrounded by # is interpreted as a regular expression, which is the dynamic " +"part of the route. So in this case, we want to match any digit between 0 and " +"9. The following function \"show_item\" just checks whether the given item " +"is present in the database or not. In case it is present, the corresponding " +"text of the task is returned. As you can see, only the regular expression " +"part of the route is passed forward. Furthermore, it is always forwarded as " +"a string, even if it is a plain integer number, like in this case." +msgstr "" +"当然,这个例子是我们想象出来的,去掉\"item1\"中的\"item\",直接使用\"1\"会更" +"简单。虽然如此,我们还是想为你展示在route的正则表达式: ``@route(/item:" +"item_#[1-9]+#)`` 和一个普通的route差不多,但是在两个\"#\"中的字符就是一个正则" +"表达式,是该route中的动态部分,匹配从0到9的数字。在处理\"/item9\"这样的请求的" +"时候,正则表达式会匹配到\"9\",然后将\"9\"做为item参数传递给show_item函数,而" +"不是\"item9\"。注意,这里传给show_item函数的\"9\",是一个字符串。" + +# d81b6fe2653d46959569c07980a6e833 +#: ../../tutorial_app.rst:390 +msgid "Returning Static Files" +msgstr "返回静态文件" + +# c7aff4fc3709401e982ffbf3c0c5a8a3 +#: ../../tutorial_app.rst:391 +msgid "" +"Sometimes it may become necessary to associate a route not to a Python " +"function, but just return a static file. So if you have for example a help " +"page for your application, you may want to return this page as plain HTML. " +"This works as follows::" +msgstr "" +"有时候,我们只是想返回已有的静态文件。例如我们的应用中有个静态的帮助页面help." +"html,我们不希望每次访问帮助页面的时候都动态生成。" + +# a05ed3a50c994f2fa09661004631e476 +#: ../../tutorial_app.rst:399 +msgid "" +"At first, we need to import the ``static_file`` function from Bottle. As you " +"can see, the ``return static_file`` statement replaces the ``return`` " +"statement. It takes at least two arguments: the name of the file to be " +"returned and the path to the file. Even if the file is in the same directory " +"as your application, the path needs to be stated. But in this case, you can " +"use ``'.'`` as a path, too. Bottle guesses the MIME-type of the file " +"automatically, but in case you like to state it explicitly, add a third " +"argument to ``static_file``, which would be here ``mimetype='text/html'``. " +"``static_file`` works with any type of route, including the dynamic ones." +msgstr "" +"首先,我们需要从Bottle中导入 ``static_file`` 函数。它接受至少两个参数,一个是" +"需要返回的文件的文件名,一个是该文件的路径。即使该文件和你的应用在同一个目录" +"下,还是要指定文件路径(可以使用\".\")。Bottle会猜测文件的MIME类型,并自动设" +"置。如果你想显式指定MIME类型,可以在static_file函数里面加上例如 " +"``mimetype='text/html'`` 这样的参数。 ``static_file`` 函数可和任何route配合使" +"用,包括动态route。" + +# 4bf16b9b2cd2469c9efebd835e6497d1 +#: ../../tutorial_app.rst:403 +msgid "Returning JSON Data" +msgstr "返回JSON数据" + +# 55b43779d8ea44ef82cdf11a2a65a171 +#: ../../tutorial_app.rst:404 +msgid "" +"There may be cases where you do not want your application to generate the " +"output directly, but return data to be processed further on, e.g. by " +"JavaScript. For those cases, Bottle offers the possibility to return JSON " +"objects, which is sort of standard for exchanging data between web " +"applications. Furthermore, JSON can be processed by many programming " +"languages, including Python" +msgstr "" +"有时我们希望返回JSON,以便在客户端使用JavaScript来生成页面,Bottle直接支持返" +"回JSON数据。JSON似乎已经是Web应用之间交换数据的标准格式了。更进一步,JSON可以" +"被很多语言解析处理,包括Python。" + +# d4c9a7a89b5544d7b8c5802155b87922 +#: ../../tutorial_app.rst:406 +msgid "" +"So, let's assume we want to return the data generated in the regular " +"expression route example as a JSON object. The code looks like this::" +msgstr "我们假设现在需要返回JSON数据。" + +# 1d92695da2234fa9933222061ee8d597 +#: ../../tutorial_app.rst:421 +msgid "" +"As you can, that is fairly simple: just return a regular Python dictionary " +"and Bottle will convert it automatically into a JSON object prior to " +"sending. So if you e.g. call \"http://localhost/json1\" Bottle should in " +"this case return the JSON object ``{\"Task\": [\"Read A-byte-of-python to " +"get a good introduction into Python\"]}``." +msgstr "" +"很简单,只需要返回一个Python中的字典就可以了,Bottle会自动将其转换为JSON,再" +"传输到客户端。如果你访问\"http://localhost/json1\",你应能得到 ``{\"Task\": " +"[\"Read A-byte-of-python to get a good introduction into Python\"]}`` 类型的" +"JSON数据。" + +# 94c8f9571b104a259a57b3839edf0bda +#: ../../tutorial_app.rst:426 +msgid "Catching Errors" +msgstr "捕获错误" + +# d0b235a517264c128849868924fdb2a9 +#: ../../tutorial_app.rst:427 +msgid "" +"The next step may is to catch the error with Bottle itself, to keep away any " +"type of error message from the user of your application. To do that, Bottle " +"has an \"error-route\", which can be a assigned to a HTML-error." +msgstr "" +"为了避免用户看到出错信息,我们需要捕获应用运行时出现的错误,以提供更友好的错" +"误提示。Bottle提供了专门用于捕获错误的route。" + +# b7bf92b392eb4ec1a1f9a9536d3a22b2 +#: ../../tutorial_app.rst:429 +msgid "In our case, we want to catch a 403 error. The code is as follows::" +msgstr "例如,我们想捕获403错误。" + +# 77476693cda84cb9aad3fc4b2a458b3f +#: ../../tutorial_app.rst:437 +msgid "" +"So, at first we need to import ``error`` from Bottle and define a route by " +"``error(403)``, which catches all \"403 forbidden\" errors. The function " +"\"mistake\" is assigned to that. Please note that ``error()`` always passes " +"the error-code to the function - even if you do not need it. Thus, the " +"function always needs to accept one argument, otherwise it will not work." +msgstr "" +"首先,我们需要从Bottle中导入 ``error`` ,然后通过 ``error(403)`` 来定义创建一" +"个route,用于捕获所有\"403 forbidden\"错误。注意,该route总是会将error-code传" +"给 ``mistake()`` 函数,即使你不需要它。所以回调函数至少要接受一个参数,否则会" +"失效。" + +# 43ef1229ce6144b4883cade232fbb8b2 +#: ../../tutorial_app.rst:439 +msgid "" +"Again, you can assign more than one error-route to a function, or catch " +"various errors with one function each. So this code::" +msgstr "一样的,同一个回调函数可以捕获多种错误。" + +# c6f33824705649cbb2efda28916b6c43 +#: ../../tutorial_app.rst:446 +msgid "works fine, the following one as well::" +msgstr "效果和下面一样。" + +# c552032229ad48258e7c65d89a035989 +#: ../../tutorial_app.rst:458 +msgid "Summary" +msgstr "总结" + +# ed3eef94cce9405a9c99535fc96da2bc +#: ../../tutorial_app.rst:459 +msgid "" +"After going through all the sections above, you should have a brief " +"understanding how the Bottle WSGI framework works. Furthermore you have all " +"the knowledge necessary to use Bottle for your applications." +msgstr "" +"通过以上章节,你应该对Bottle框架有了一个大致的了解,可以使用Bottle进行开发" +"了。" + +# 311308ed4ce24fa3972b3e5c5b5be7f4 +#: ../../tutorial_app.rst:461 +msgid "" +"The following chapter give a short introduction how to adapt Bottle for " +"larger projects. Furthermore, we will show how to operate Bottle with web " +"servers which perform better on a higher load / more web traffic than the " +"one we used so far." +msgstr "" +"接下来的章节会简单介绍一下,如何在大型项目中使用Bottle。此外,我们还会介绍如" +"何将Bottle部署到更高性能的Web服务器上。" + +# 395bff6a6a6d4e64bc96c25a344119c3 +#: ../../tutorial_app.rst:464 +msgid "Server Setup" +msgstr "安装服务器" + +# 524d2c0a5dba48b6b07fe94053fe92a1 +#: ../../tutorial_app.rst:466 +msgid "" +"So far, we used the standard server used by Bottle, which is the `WSGI " +"reference Server`_ shipped along with Python. Although this server is " +"perfectly suitable for development purposes, it is not really suitable for " +"larger applications. But before we have a look at the alternatives, let's " +"have a look how to tweak the settings of the standard server first." +msgstr "" +"到目前为止,我们还是使用Bottle内置的,随Python一起发布的 `WSGI reference " +"Server`_ 服务器。尽管该服务器十分适合用于开发环境,但是它确实不适用于大项目。" +"在我们介绍其他服务器之前,我们先看看如何优化内置服务器的设置。" + +# f3f9b9a3d7264e8bb4516ccd253de289 +#: ../../tutorial_app.rst:470 +msgid "Running Bottle on a different port and IP" +msgstr "更改服务器的端口和IP" + +# 20448df4935d4221830cdcc26460e9b0 +#: ../../tutorial_app.rst:471 +msgid "" +"As standard, Bottle serves the pages on the IP adress 127.0.0.1, also known " +"as ``localhost``, and on port ``8080``. To modify the setting is pretty " +"simple, as additional parameters can be passed to Bottle's ``run()`` " +"function to change the port and the address." +msgstr "默认的,Bottle会监听127.0.0.1(即 ``localhost`` )的 ``8080`` 端口。" + +# fb636580bc26405097be05571ac2681b +#: ../../tutorial_app.rst:473 +msgid "" +"To change the port, just add ``port=portnumber`` to the run command. So, for " +"example::" +msgstr "如果要更改该设置,更改 ``run`` 函数的参数即可。" + +# c2fbc06be29c42709df7469512b71edc +#: ../../tutorial_app.rst:477 +msgid "would make Bottle listen to port 80." +msgstr "更改端口,监听80端口" + +# d0212932258c4dc89fd5a25efeee9e10 +#: ../../tutorial_app.rst:479 +msgid "To change the IP address where Bottle is listening::" +msgstr "更改监听的IP地址" + +# 39ee873d337e4c2e81661fe325a26934 +#: ../../tutorial_app.rst:483 +msgid "Of course, both parameters can be combined, like::" +msgstr "可同时使用" + +# e2e9eac7999848ce9e451b3838205219 +#: ../../tutorial_app.rst:487 +msgid "" +"The ``port`` and ``host`` parameter can also be applied when Bottle is " +"running with a different server, as shown in the following section." +msgstr "" +"当Bottle运行在其他服务器上面时, ``port`` 和 ``host`` 参数依然适用,稍后会介" +"绍。" + +# 71a7fa8ce05645e7a0c9d09068339265 +#: ../../tutorial_app.rst:491 +msgid "Running Bottle with a different server" +msgstr "在其他服务器上运行" + +# 366930a6459a4761a95af5a3bd5b6290 +#: ../../tutorial_app.rst:492 +msgid "" +"As said above, the standard server is perfectly suitable for development, " +"personal use or a small group of people only using your application based on " +"Bottle. For larger tasks, the standard server may become a bottleneck, as it " +"is single-threaded, thus it can only serve one request at a time." +msgstr "" +"在大型项目上,Bottle自带的服务器会成为一个性能瓶颈,因为它是单线程的,一次只" +"能响应一个请求。" + +# 7d0313cbeef54778855ea9e6afc6e998 +#: ../../tutorial_app.rst:494 +msgid "" +"But Bottle has already various adapters to multi-threaded servers on board, " +"which perform better on higher load. Bottle supports Cherrypy_, Fapws3_, " +"Flup_ and Paste_." +msgstr "" +"Bottle已经可以工作在很多多线程的服务器上面了,例如 Cherrypy_, Fapws3_, Flup_ " +"和 Paste_ ,所以我们建议在大型项目上使用高性能的服务器。" + +# ceeb5b687ca549dfa84034aeea023aaf +#: ../../tutorial_app.rst:496 +msgid "" +"If you want to run for example Bottle with the Paste server, use the " +"following code::" +msgstr "如果想运行在Paste服务器上面,代码如下(译者注:需要先安装Paste)。" + +# faf0a875357a4617845347f9a24c3332 +#: ../../tutorial_app.rst:502 +msgid "" +"This works exactly the same way with ``FlupServer``, ``CherryPyServer`` and " +"``FapwsServer``." +msgstr "" +"其他服务器如 ``FlupServer``, ``CherryPyServer`` 和 ``FapwsServer`` 也类似。" + +# 2c6c36914b8e468e9f50ead4a9c59fbf +#: ../../tutorial_app.rst:506 +msgid "Running Bottle on Apache with mod_wsgi" +msgstr "使用 mod_wsgi_ 运行在Apache上" + +# 14b2f40d86e34ca4a7c7b654e00e91e1 +#: ../../tutorial_app.rst:507 +msgid "" +"Maybe you already have an Apache_ or you want to run a Bottle-based " +"application large scale - then it is time to think about Apache with " +"mod_wsgi_." +msgstr "或许你已经有了一个 Apache_ 服务器,那么可以考虑使用 mod_wsgi_ 。" + +# 67741e7b16d448ada12672b987a58132 +#: ../../tutorial_app.rst:509 +msgid "" +"We assume that your Apache server is up and running and mod_wsgi is working " +"fine as well. On a lot of Linux distributions, mod_wsgi can be easily " +"installed via whatever package management system is in use." +msgstr "" +"我们假设你的Apache已经能跑起来,且mod_wsgi也能工作了。在很多Linux发行版上,都" +"能通过包管理软件简单地安装mod_wsgi。" + +# 7eb6330d0b614f0ebd900a48a6b06b23 +#: ../../tutorial_app.rst:511 +msgid "" +"Bottle brings an adapter for mod_wsgi with it, so serving your application " +"is an easy task." +msgstr "" +"Bottle已经自带用于mod_wsgi的适配器,所以让Bottle跑在mod_wsgi上面是很简单的。" + +# 42e86b7acebf49a7ad63d2a02905c85f +#: ../../tutorial_app.rst:513 +msgid "" +"In the following example, we assume that you want to make your application " +"\"ToDo list\" accessible through ``http://www.mypage.com/todo`` and your " +"code, templates and SQLite database are stored in the path ``/var/www/todo``." +msgstr "" +"接下来的例子里,我们假设你希望通过 ``http://www.mypage.com/todo`` 来访问" +"\"ToDo list\"这个应用,且代码、模板、和SQLite数据库存放在 ``/var/www/todo`` " +"目录。" + +# 1521ff2d90f24688a9e0191d48d8998d +#: ../../tutorial_app.rst:515 +msgid "" +"When you run your application via mod_wsgi, it is imperative to remove the " +"``run()`` statement from your code, otherwise it won't work here." +msgstr "如果通过mod_wsgi来运行你应用,那么必须从代码中移除 ``run()`` 函数。" + +# 241ba86ed7bf42a487401830597ecdad +#: ../../tutorial_app.rst:517 +msgid "" +"After that, create a file called ``adapter.wsgi`` with the following " +"content::" +msgstr "然后,创建一个 ``adapter.wsgi`` 文件,内容如下。" + +# 97093e54523c4ba99458b884f5cf56ef +#: ../../tutorial_app.rst:528 +msgid "" +"and save it in the same path, ``/var/www/todo``. Actually the name of the " +"file can be anything, as long as the extension is ``.wsgi``. The name is " +"only used to reference the file from your virtual host." +msgstr "" +"将其保存到 ``/var/www/todo`` 目录下面。其实,可以给该文件起任何名字,只要后缀" +"名为 ``.wsgi`` 即可。" + +# acc0c57728cf4a1680a814d155bcc61c +#: ../../tutorial_app.rst:530 +msgid "" +"Finally, we need to add a virtual host to the Apache configuration, which " +"looks like this::" +msgstr "最后,我们需要在Apache的配置中添加一个虚拟主机。" + +# 2beb148e346348b5bf3d527f746f7869 +#: ../../tutorial_app.rst:546 +msgid "" +"After restarting the server, your ToDo list should be accessible at ``http://" +"www.mypage.com/todo``" +msgstr "" +"重启Apache服务器后,即可通过 ``http://www.mypage.com/todo`` 来访问你的应用。" + +# 732c5f47d6154f91bd9f6bd3a3dc826b +#: ../../tutorial_app.rst:549 +msgid "Final Words" +msgstr "结语" + +# ee1bab3bc99e466aa5ef6a2bc8dca1d0 +#: ../../tutorial_app.rst:551 +msgid "" +"Now we are at the end of this introduction and tutorial to Bottle. We " +"learned about the basic concepts of Bottle and wrote a first application " +"using the Bottle framework. In addition to that, we saw how to adapt Bottle " +"for large tasks and serve Bottle through an Apache web server with mod_wsgi." +msgstr "" +"现在,我们这个教程已经结束了。我们学习了Bottle的基础知识,然后使用Bottle来写" +"了第一个应用。另外,我们还介绍了如何在大型项目中使用Bottle,以及使用mod_wsgi" +"在Apache中运行Bottle应用。" + +# 097a787683e14a9b8d9cdc101f407304 +#: ../../tutorial_app.rst:553 +msgid "" +"As said in the introduction, this tutorial is not showing all shades and " +"possibilities of Bottle. What we skipped here is e.g. receiving file objects " +"and streams and how to handle authentication data. Furthermore, we did not " +"show how templates can be called from within another template. For an " +"introduction into those points, please refer to the full `Bottle " +"documentation`_ ." +msgstr "" +"我们并没有在这份教程里介绍Bottle的方方面面。我们没有介绍如何上传文件,验证数" +"据的可靠性。还有,我们也没介绍如何在模板中调用另一个模板。以上,可以在 " +"`Bottle documentation`_ 中找到答案。" + +# bbc99b031d27493d9eebe9bd0b228867 +#: ../../tutorial_app.rst:556 +msgid "Complete Example Listing" +msgstr "完整代码" + +# 6ee1c23d3506437d9980c6d523600303 +#: ../../tutorial_app.rst:558 +msgid "" +"As the ToDo list example was developed piece by piece, here is the complete " +"listing:" +msgstr "我们是一步一步地开发待办事项列表的,这里是完整的代码。" + +# d020e81790a4479890fb5f2e224de9e7 +#: ../../tutorial_app.rst:560 +msgid "Main code for the application ``todo.py``::" +msgstr "``todo.py``" + +# a46a44631fe24bf0b1dcaf916a9e2691 +#: ../../tutorial_app.rst:675 +msgid "Template ``make_table.tpl``::" +msgstr "``make_table.tpl``模板" + +# 0fbb6043fcd84599bfd558d318a7c273 +#: ../../tutorial_app.rst:689 +msgid "Template ``edit_task.tpl``::" +msgstr " ``edit_task.tpl`` 模板" + +# 8850a5ca39bb4e7986590e6fd8e3c01d +#: ../../tutorial_app.rst:704 +msgid "Template ``new_task.tpl``::" +msgstr "``new_task.tpl`` 模板" diff -Nru python-bottle-0.11.6/docs/_static/bottle.css_t python-bottle-0.12.0/docs/_static/bottle.css_t --- python-bottle-0.11.6/docs/_static/bottle.css_t 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/docs/_static/bottle.css_t 1970-01-01 00:00:00.000000000 +0000 @@ -1,254 +0,0 @@ -{% set page_width = '940px' %} -{% set sidebar_width = '230px' %} -{% set color_body = '#E8EFEF' %} -{% set color_border = '#697983' %} -{% set color_document = '#ffffff' %} -{% set textcolor_body = '#000' %} -{% set textcolor_border = '#fff' %} -{% set textcolor_document = '#111' %} -{% set linkcolor_body = '#002a32' %} -{% set linkcolor_border = 'white' %} -{% set linkcolor_document = '#005566' %} - - -@import url("basic.css"); - -/* Positional Layout */ - -body { - width: {{ page_width }}; - margin: 0 auto 0 auto; - padding: 15px; -} - -div.document { -} - -div.documentwrapper { - float: left; - width: 100%; -} - -div.bodywrapper { - margin: 0 0 0 {{ sidebar_width }}; -} - -div.sphinxsidebar { - width: {{ sidebar_width }}; -} - -div.sphinxsidebarwrapper { - margin: 0 15px; - padding: 0; -} - -div.related { - line-height: 30px; - display: none; -} - -/* Design and Colors */ - -body { - background-color: {{ color_body }}; - font-family: 'Veranda', sans-serif; - font-size: 16px; -} - -div.body { - border: 1px solid {{ color_border }}; - background-color: {{ color_document }}; - padding: 0 15px 15px 15px; - color: {{ textcolor_document }}; - line-height: 1.4em; -} - -div.body h2 { - background-color: {{ color_border }}; - color: {{ textcolor_border }}; - margin: 2em -15px 1em -30px; - padding: 7px 15px 5px 15px; - border-top-left-radius: 15px; - -moz-border-radius-topleft: 15px; - -webkit-border-top-left-radius: 15px; - border-bottom-left-radius: 15px; - -moz-border-radius-bottomleft: 15px; - -webkit-border-bottom-left-radius: 15px; -} - -div.body h3 { - margin: 2em 0 1em 0; -} - -div.body h2 a { - color: {{ linkcolor_border }}; -} - -a { - color: {{ linkcolor_document }}; - text-decoration: none; -} - -a:hover { - color: black; - text-decoration: underline; -} - -/* Notes and Codes */ - -pre { - background-color: {{ color_body }}; - margin: 1em 2em; - padding: 0.5em; -} - -dd pre, dd div.admonition { - margin: 1em 0; - padding: 5px 5px; - border: 1px solid #ccc; -} - -div.admonition p.last { - margin-bottom: 0; -} - -div.admonition { - border: 1px solid {{ color_border }}; - margin: 1em 2em; - padding: 0.5em; - font-size: 0.9em; - line-height: 1.3em; -} - -div.admonition p.admonition-title { - margin: 0; -} - -div.admonition p.admonition-title:after { - content:":"; -} - -div.warning { - background-color: #fee; -} - -div.note { - background-color: #ffc; -} - -div.highlight { - background: transparent; -} - -pre { - font-size: 12px; - line-height: 1.2em; -} - -code, tt.docutils { - font-size: 0.9em; - padding: 0 0.2em; -} - -tt.xref { - border: 0 !important; - background-color: transparent !important; -} - -/* Misc */ - -img.floatright { - float: right; - margin: 0.5em 1em; -} - -div.body { - border-radius: 10px; - -moz-border-radius: 10px; - -webkit-border-radius: 10px; -} - -div.sphinxsidebar ul { - margin: 15px 0; - padding: 0 0 0.5em 0; - color: #000; -} - -div.sphinxsidebar li { - line-height: 1.3em; -} - -div.sphinxsidebar ul ul ul { - font-size: 0.9em; -} - -div.sphinxsidebar h3 { - background-color: {{ color_border }}; - color: {{ textcolor_border }}; - margin: 0 -15px 0 -5px; - padding: 3px 10px 1px 10px; - border-top-left-radius: 10px; - -moz-border-radius-topleft: 10px; - -webkit-border-top-left-radius: 10px; - border-bottom-left-radius: 10px; - -moz-border-radius-bottomleft: 10px; - -webkit-border-bottom-left-radius: 10px; -} - -div.sphinxsidebar a { - color: {{ linkcolor_body }}; -} - -div.sphinxsidebar h3 a { - color: {{ linkcolor_border }}; -} - -div.sphinxsidebar ul ul { - list-style: disc outside none; -} - -div.sphinxsidebar input { - border: 1px solid grey; -} - -div.sphinxsidebar input:hover { - border: 1px solid black; -} - -div.sphinxsidebar input:focus { - border: 1px solid black; -} - -div.footer { - text-align: center; - font-size: 75%; - padding: 1em; - opacity: 0.5; -} - -/* Fancy Legend */ - -.sidelegend { - position: fixed; - overflow: hidden; - font-size: small; - background: url('link_icon.png') no-repeat 5px center; - padding: 0px 0px 0px 20px; -} - -.sidelegend a { - border-top-left-radius: 10px; - -moz-border-radius-topleft: 10px; - -webkit-border-top-left-radius: 10px; - border-bottom-left-radius: 10px; - -moz-border-radius-bottomleft: 10px; - -webkit-border-bottom-left-radius: 10px; - padding: 2px 10px 2px 10px; - background: {{ color_border }}; - color: {{ linkcolor_border }}; - display: block; -} - -.sidelegend a:hover { - text-decoration: none; -} \ No newline at end of file diff -Nru python-bottle-0.11.6/docs/_static/default.js python-bottle-0.12.0/docs/_static/default.js --- python-bottle-0.11.6/docs/_static/default.js 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/docs/_static/default.js 1970-01-01 00:00:00.000000000 +0000 @@ -1,137 +0,0 @@ -// Awesome scrollbar navigaion - -POI = function(anchor, title, options) { - // Create a Point-Of-Interest, a named position within the document. - // @param anchor is the point of interest (HTML or jquery node). This MUST - // have an ID attribute. - // @param title is the name of the POI (string) - POI.all.push(this); - - //: Number of pixels the handle should be visible - options = options || {}; - this.peak = options.peak || POI.peak; - this.delay = options.delay || POI.delay; - this.css = options.css || POI.css; - - this.pinned = false; - this.visible = false; - this.hide_timeout = null; - - this.anchor = $(anchor); - this.id = this.anchor.attr('id'); - this.title = title || $(anchor).text(); - this.node = $('
').addClass(this.css).appendTo('body'); - this.link = $('').text(this.title) - .attr('href', '#'+this.id) - .appendTo(this.node); - this.node.css('right', '-'+(this.node.outerWidth()-this.peak)+'px'); - this.refresh(); - this.node.mouseenter(function() { POI.show(); }); - this.node.mouseleave(function() { POI.hide(POI.delay); }); -} - -POI.prototype.refresh = function() { - // Re-arrange the anchors - var dsize = $(document).height(); - var wsize = $(window).height(); - var pos = this.anchor.offset().top; - var hpos = Math.round(wsize*(pos/dsize)); - this.node.css('top', hpos+'px'); -} - -POI.prototype.show = function() { - // Show the handle - if(this.visible) return; - this.node.stop(true).animate({'right': '0px'}, 250); - this.visible = true; -} - -POI.prototype.hide = function() { - // Hide the handle - if(this.pinned) return; - if(! this.visible) return; - this.node.stop(true).animate({ - 'right': '-'+(this.node.outerWidth()-this.peak)+'px' - }, 250); - this.visible = false; -} - - - -// Static attributes and methods. - -POI.all = Array(); -POI.peak = 20; -POI.delay = 2000; -POI.css = 'sidelegend'; -POI.hide_timeout = null; - -POI.refresh = function() { - // Refresh all at once - jQuery.each(POI.all, function() { - this.refresh(); - }) -} - -POI.show = function() { - // Show all at once - if(POI.hide_timeout) window.clearTimeout(POI.hide_timeout); - POI.hide_timeout = null; - jQuery.each(POI.all, function() { - this.show(); - }) -} - -POI.hide = function(delay) { - // Hide all at once after a specific delay - if(POI.hide_timeout) window.clearTimeout(POI.hide_timeout); - if(delay) { - POI.hide_timeout = window.setTimeout(function() { - POI.hide_timeout = null; - POI.hide(); - }, delay) - } else { - jQuery.each(POI.all, function() { - this.hide(); - }) - } -} - -POI.whereami = function() { - // Show and pin the currently viewed POI - var position = $(window).scrollTop() + $(window).height() / 2; - var last = null; - jQuery.each(POI.all, function() { - if(position < this.anchor.offset().top) return false; - last = this; - }) - if(last) { - last.pinned = true; - last.show(); - } - jQuery.each(POI.all, function() { - if(this != last) { - this.pinned = false; - this.hide(); - } - }) -} - - - -$(document).resize(POI.refresh); -$(window).resize(POI.refresh); -$(window).scroll(POI.whereami); - -// Global events that affect all POIs -$(document).ready(function() { - $('.section > h1 > a.headerlink, .section > h2 > a.headerlink').each(function(index){ - var lnk = $(this); - var title = lnk.parent().text().replace('¶','') - var anchor = lnk.parent().parent() - new POI(anchor, title) - }) - POI.whereami(); -}) - - Binary files /tmp/FY_uVtv6GB/python-bottle-0.11.6/docs/_static/favicon.ico and /tmp/iqLSYgoWDB/python-bottle-0.12.0/docs/_static/favicon.ico differ Binary files /tmp/FY_uVtv6GB/python-bottle-0.11.6/docs/_static/link_icon.png and /tmp/iqLSYgoWDB/python-bottle-0.12.0/docs/_static/link_icon.png differ Binary files /tmp/FY_uVtv6GB/python-bottle-0.11.6/docs/_static/logo_bg.png and /tmp/iqLSYgoWDB/python-bottle-0.12.0/docs/_static/logo_bg.png differ Binary files /tmp/FY_uVtv6GB/python-bottle-0.11.6/docs/_static/logo_full.png and /tmp/iqLSYgoWDB/python-bottle-0.12.0/docs/_static/logo_full.png differ Binary files /tmp/FY_uVtv6GB/python-bottle-0.11.6/docs/_static/logo_icon.png and /tmp/iqLSYgoWDB/python-bottle-0.12.0/docs/_static/logo_icon.png differ Binary files /tmp/FY_uVtv6GB/python-bottle-0.11.6/docs/_static/logo_nav.png and /tmp/iqLSYgoWDB/python-bottle-0.12.0/docs/_static/logo_nav.png differ Binary files /tmp/FY_uVtv6GB/python-bottle-0.11.6/docs/_static/logo_reddit.png and /tmp/iqLSYgoWDB/python-bottle-0.12.0/docs/_static/logo_reddit.png differ Binary files /tmp/FY_uVtv6GB/python-bottle-0.11.6/docs/_static/myface.png and /tmp/iqLSYgoWDB/python-bottle-0.12.0/docs/_static/myface.png differ Binary files /tmp/FY_uVtv6GB/python-bottle-0.11.6/docs/_static/myface_small.png and /tmp/iqLSYgoWDB/python-bottle-0.12.0/docs/_static/myface_small.png differ Binary files /tmp/FY_uVtv6GB/python-bottle-0.11.6/docs/_static/paypal.png and /tmp/iqLSYgoWDB/python-bottle-0.12.0/docs/_static/paypal.png differ diff -Nru python-bottle-0.11.6/docs/_templates/donation.html python-bottle-0.12.0/docs/_templates/donation.html --- python-bottle-0.11.6/docs/_templates/donation.html 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/docs/_templates/donation.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,14 +0,0 @@ -

Like it?

-
diff -Nru python-bottle-0.11.6/docs/_templates/layout.html python-bottle-0.12.0/docs/_templates/layout.html --- python-bottle-0.11.6/docs/_templates/layout.html 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/docs/_templates/layout.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,39 +0,0 @@ -{% extends "!layout.html" %} - -{% block extrahead %} - - - - {% if pagename == 'index' -%} - - {% endif %} - {{ super() }} -{% endblock %} - -{% block rootrellink %} -
  • Project Home »
  • - {{ super() }} -{% endblock %} - -{% block footer %} -
    - - -{% endblock %} - diff -Nru python-bottle-0.11.6/docs/_templates/page.html python-bottle-0.12.0/docs/_templates/page.html --- python-bottle-0.11.6/docs/_templates/page.html 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/docs/_templates/page.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,9 +0,0 @@ -{% extends "!page.html" %} - -{% block body %} - {% if 'dev' in release or 'rc' in release %} -

    Warning: This is a preview for Bottle-{{release}}, which is - not released yet. Switch to the latest stable release?

    - {% endif %} - {{ super() }} -{% endblock %} \ No newline at end of file diff -Nru python-bottle-0.11.6/docs/_templates/sidebar-intro.html python-bottle-0.12.0/docs/_templates/sidebar-intro.html --- python-bottle-0.11.6/docs/_templates/sidebar-intro.html 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/docs/_templates/sidebar-intro.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,33 +0,0 @@ -

    - Bottle is a fast, simple and lightweight WSGI micro web-framework for Python. -

    -

    Some Links

    - -

    Installation

    -

    Install Bottle with pip install bottle or download the source package at PyPI.

    -

    Documentation

    -

    - Download this documentation as PDF or HTML (zip) for offline use. -

    -

    Sources

    -

    Browse the sources at GitHub.

    -

    Other Releases

    -
      - {% for v, name in releases %} - {% if v == version %} -
    • Bottle {{v}} ({{name}})
    • - {% else %} -
    • Bottle {{v}} ({{name}})
    • - {% endif %} - {% endfor %} -
    - - diff -Nru python-bottle-0.11.6/docs/api.rst python-bottle-0.12.0/docs/api.rst --- python-bottle-0.11.6/docs/api.rst 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/docs/api.rst 2013-12-03 17:16:12.000000000 +0000 @@ -101,6 +101,9 @@ .. autoclass:: ResourceManager :members: +.. autoclass:: FileUpload + :members: + Exceptions --------------- @@ -136,6 +139,8 @@ :members: +.. autodata:: request + The :class:`Response` Object =================================================== diff -Nru python-bottle-0.11.6/docs/async.rst python-bottle-0.12.0/docs/async.rst --- python-bottle-0.11.6/docs/async.rst 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/docs/async.rst 2013-12-03 17:16:12.000000000 +0000 @@ -70,8 +70,9 @@ def fetch(): body = gevent.queue.Queue() worker = SomeAsyncWorker() - worker.on_data(lambda chunk: body.put(chunk)) + worker.on_data(body.put) worker.on_finish(lambda: body.put(StopIteration)) + worker.start() return body From the server perspective, the queue object is iterable. It blocks if empty and stops as soon as it reaches ``StopIteration``. This conforms to WSGI. On the application side, the queue object behaves like a non-blocking socket. You can write to it at any time, pass it around and even start a new (pseudo)thread that writes to it asynchronously. This is how long-polling is implemented most of the time. diff -Nru python-bottle-0.11.6/docs/changelog.rst python-bottle-0.12.0/docs/changelog.rst --- python-bottle-0.11.6/docs/changelog.rst 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/docs/changelog.rst 2013-12-03 17:16:12.000000000 +0000 @@ -5,6 +5,19 @@ Release Notes and Changelog =========================== + + +Release 0.12 +============== + +.. warning: Not released yet. + +* New SimpleTemplate parser implementation + * Support for multi-line code blocks (`<% ... %>`). + * The keywords `include` and `rebase` are functions now and can accept variable template names. +* The new :meth:`BaseRequest.route` property returns the :class:`Route` that matched the request. +* Removed the ``BaseRequest.MAX_PARAMS`` limit. The hash collision bug in CPythons dict() implementation was fixed over a year ago. If you are still using Python 2.5 in production, consider upgrading or at least make sure that you get security fixed from your distributor. + Release 0.11 ============== @@ -52,7 +65,7 @@ * A new route syntax (e.g. ``/object/``) and support for route wildcard filters. * Four new wildcard filters: `int`, `float`, `path` and `re`. -* Oher changes +* Other changes * Added command line interface to load applications and start servers. * Introduced a :class:`ConfigDict` that makes accessing configuration a lot easier (attribute access and auto-expanding namespaces). diff -Nru python-bottle-0.11.6/docs/conf.py python-bottle-0.12.0/docs/conf.py --- python-bottle-0.11.6/docs/conf.py 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/docs/conf.py 2013-12-03 17:16:12.000000000 +0000 @@ -1,218 +1,22 @@ # -*- coding: utf-8 -*- -# -# Bottle documentation build configuration file, created by -# sphinx-quickstart on Thu Feb 18 18:09:50 2010. -# -# This file is execfile()d with the current directory set to its containing dir. -# -# Note that not all possible configuration values are present in this -# autogenerated file. -# -# All configuration values have a default; values that are commented out -# serve to show the default. import sys, os, time -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. - bottle_dir = os.path.abspath(os.path.join(os.path.dirname(__file__),'../')) sys.path.insert(0, bottle_dir) import bottle -# -- General configuration ----------------------------------------------------- - -# Add any Sphinx extension module names here, as strings. They can be extensions -# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.viewcode'] - -# Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] - -# The suffix of source filenames. -source_suffix = '.rst' - -# The encoding of source files. -#source_encoding = 'utf-8' - -# The master toctree document. master_doc = 'index' - -# General information about the project. project = u'Bottle' copyright = unicode('2009-%s, %s' % (time.strftime('%Y'), bottle.__author__)) - -# The version info for the project you're documenting, acts as replacement for -# |version| and |release|, also used in various other places throughout the -# built documents. - -# The short X.Y version. version = ".".join(bottle.__version__.split(".")[:2]) -# The full version, including alpha/beta/rc tags. release = bottle.__version__ - -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -language = 'en' - -# There are two options for replacing |today|: either, you set today to some -# non-false value, then it is used: -#today = '' -# Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' - -# List of documents that shouldn't be included in the build. -#unused_docs = [] - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -exclude_patterns = ['_build'] - -# The reST default role (used for this markup: `text`) to use for all documents. -#default_role = None - -# If true, '()' will be appended to :func: etc. cross-reference text. add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). add_module_names = False - -# If true, sectionauthor and moduleauthor directives will be shown in the -# output. They are ignored by default. -#show_authors = False - -# The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' - -# A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] - - -# -- Options for HTML output --------------------------------------------------- - -# The theme to use for HTML and HTML Help pages. Major themes that come with -# Sphinx are currently 'default' and 'sphinxdoc'. -html_theme = 'default' - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -#html_theme_options = {} - -# Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] - -# The name for this set of Sphinx documents. If None, it defaults to -# " v documentation". -#html_title = None - -# A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None - -# The name of an image file (relative to this directory) to place at the top -# of the sidebar. -html_logo = "_static/logo_nav.png" - -# The name of an image file (within the static path) to use as favicon of the -# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 -# pixels large. -html_favicon = "favicon.ico" - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] - -html_style="bottle.css" - -# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, -# using the given strftime format. -html_last_updated_fmt = '%b %d, %Y' - -# If true, SmartyPants will be used to convert quotes and dashes to -# typographically correct entities. -#html_use_smartypants = True - -# Custom sidebar templates, maps document names to template names. -html_sidebars = { - 'index': ['sidebar-intro.html', 'sourcelink.html', 'donation.html', 'searchbox.html'], - '**': ['localtoc.html', 'relations.html', 'sourcelink.html', 'donation.html', 'searchbox.html'] -} - -html_context = { - 'releases': [('dev', 'development'), - ('0.10', 'stable'), - ('0.9', 'old stable') - ] -} - -# Additional templates that should be rendered to pages, maps page names to -# template names. -#html_additional_pages = {} - -# If false, no module index is generated. -html_use_modindex = True - -# If false, no index is generated. -#html_use_index = True - -# If true, the index is split into individual pages for each letter. -#html_split_index = False - -# If true, links to the reST sources are added to the pages. -html_show_sourcelink = True - -# If true, an OpenSearch description file will be output, and all pages will -# contain a tag referring to it. The value of this option must be the -# base URL from which the finished HTML is served. -#html_use_opensearch = '' - -# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = '' - -# Output file base name for HTML help builder. -htmlhelp_basename = 'Bottledoc' - - -# -- Options for LaTeX output -------------------------------------------------- - -# The paper size ('letter' or 'a4'). -#latex_paper_size = 'letter' - -# The font size ('10pt', '11pt' or '12pt'). -#latex_font_size = '10pt' - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, author, documentclass [howto/manual]). -latex_documents = [ - ('index', 'Bottle.tex', u'Bottle Documentation', - bottle.__author__, 'manual'), -] - -# The name of an image file (relative to this directory) to place at the top of -# the title page. -latex_logo = "_static/logo_nav.png" - -# For "manual" documents, if this is true, then toplevel headings are parts, -# not chapters. -#latex_use_parts = False - -# Additional stuff for the LaTeX preamble. -#latex_preamble = '' - -# Documents to append as an appendix to all manuals. -#latex_appendices = [] - -# If false, no module index is generated. -#latex_use_modindex = True - - -# Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = {'python': ('http://docs.python.org/', None), 'werkzeug': ('http://werkzeug.pocoo.org/docs/', None)} autodoc_member_order = 'bysource' -locale_dirs = ['./locale'] diff -Nru python-bottle-0.11.6/docs/configuration.rst python-bottle-0.12.0/docs/configuration.rst --- python-bottle-0.11.6/docs/configuration.rst 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/docs/configuration.rst 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,168 @@ +===================== +Configuration (DRAFT) +===================== + +.. currentmodule:: bottle + +.. warning:: + This is a draft for a new API. `Tell us `_ what you think. + +Bottle applications can store their configuration in :attr:`Bottle.config`, a dict-like object and central place for application specific settings. This dictionary controls many aspects of the framework, tells (newer) plugins what to do, and can be used to store your own configuration as well. + +Configuration Basics +==================== + +The :attr:`Bottle.config` object behaves a lot like an ordinary dictionary. All the common dict methods work as expected. Let us start with some examples:: + + import bottle + app = bottle.default_app() # or bottle.Bottle() if you prefer + + app.config['autojson'] = False # Turns off the "autojson" feature + app.config['sqlite.db'] = ':memory:' # Tells the sqlite plugin which db to use + app.config['myapp.param'] = 'value' # Example for a custom config value. + + # Change many values at once + app.config.update({ + 'autojson': False, + 'sqlite.db': ':memory:', + 'myapp.param': 'value' + }) + + # Add default values + app.config.setdefault('myapp.param2', 'some default') + + # Receive values + param = app.config['myapp.param'] + param2 = app.config.get('myapp.param2', 'fallback value') + + # An example route using configuration values + @app.route('/about', view='about.rst') + def about(): + email = app.config.get('my.email', 'nomail@example.com') + return {'email': email} + +The app object is not always available, but as long as you are within a request context, you can use the `request` object to get the current application and its configuration:: + + from bottle import request + def is_admin(user): + return user == request.app.config['myapp.admin_user'] + +Naming Convention +================= + +To make life easier, plugins and applications should follow some simple rules when it comes to config parameter names: + +- All keys should be lowercase strings and follow the rules for python identifiers (no special characters but the underscore). +- Namespaces are separated by dots (e.g. ``namespace.field`` or ``namespace.subnamespace.field``). +- Bottle uses the root namespace for its own configuration. Plugins should store all their variables in their own namespace (e.g. ``sqlite.db`` or ``werkzeug.use_debugger``). +- Your own application should use a separate namespace (e.g. ``myapp.*``). + + +Loading Configuration from a File +================================= + +.. versionadded 0.12 + +Configuration files are useful if you want to enable non-programmers to configure your application, +or just don't want to hack python module files just to change the database port. A very common syntax for configuration files is shown here: + +.. code-block:: ini + + [sqlite] + db = /tmp/test.db + commit = auto + + [myapp] + admin_user = defnull + +With :meth:`ConfigDict.load_config` you can load these ``*.ini`` style configuration +files from disk and import their values into your existing configuration:: + + app.config.load_config('/etc/myapp.conf') + +Loading Configuration from a nested :class:`dict` +================================================= + +.. versionadded 0.12 + +Another useful method is :meth:`ConfigDict.load_dict`. This method takes +an entire structure of nested dictionaries and turns it into a flat list of keys and values with namespaced keys:: + + # Load an entire dict structure + app.config.load_dict({ + 'autojson': False, + 'sqlite': { 'db': ':memory:' }, + 'myapp': { + 'param': 'value', + 'param2': 'value2' + } + }) + + assert app.config['myapp.param'] == 'value' + + # Load configuration from a json file + with open('/etc/myapp.json') as fp: + app.config.load_dict(json.load(fp)) + + +Listening to configuration changes +================================== + +.. versionadded 0.12 + +The ``config`` hook on the application object is triggered each time a value in :attr:`Bottle.config` is changed. This hook can be used to react on configuration changes at runtime, for example reconnect to a new database, change the debug settings on a background service or resize worker thread pools. The hook callback receives two arguments (key, new_value) and is called before the value is actually changed in the dictionary. Raising an exception from a hook callback cancels the change and the old value is preserved. + +:: + + @app.hook('config') + def on_config_change(key, value): + if key == 'debug': + switch_own_debug_mode_to(value) + +The hook callbacks cannot *change* the value that is to be stored to the dictionary. That is what filters are for. + + +.. conf-meta: + +Filters and other Meta Data +=========================== + +.. versionadded 0.12 + +:class:`ConfigDict` allows you to store meta data along with configuration keys. Two meta fields are currently defined: + +help + A help or description string. May be used by debugging, introspection or + admin tools to help the site maintainer configuring their application. + +filter + A callable that accepts and returns a single value. If a filter is defined for a key, any new value stored to that key is first passed through the filter callback. The filter can be used to cast the value to a different type, check for invalid values (throw a ValueError) or trigger side effects. + +This feature is most useful for plugins. They can validate their config parameters or trigger side effects using filters and document their configuration via ``help`` fields:: + + class SomePlugin(object): + def setup(app): + app.config.meta_set('some.int', 'filter', int) + app.config.meta_set('some.list', 'filter', + lambda val: str(val).split(';')) + app.config.meta_set('some.list', 'help', + 'A semicolon separated list.') + + def apply(self, callback, route): + ... + + import bottle + app = bottle.default_app() + app.install(SomePlugin()) + + app.config['some.list'] = 'a;b;c' # Actually stores ['a', 'b', 'c'] + app.config['some.int'] = 'not an int' # raises ValueError + + +API Documentation +================= + +.. versionadded 0.12 + +.. autoclass:: ConfigDict + :members: diff -Nru python-bottle-0.11.6/docs/development.rst python-bottle-0.12.0/docs/development.rst --- python-bottle-0.11.6/docs/development.rst 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/docs/development.rst 2013-12-03 17:16:12.000000000 +0000 @@ -28,7 +28,7 @@ Releases and Updates -------------------- -Bottle is released at irregular intervals and distributed through `PyPi `_. Release candidates and bugfix-revisions of outdated releases are only available from the git repository mentioned above. Some Linux distributions may offer packages for outdated releases, though. +Bottle is released at irregular intervals and distributed through `PyPI `_. Release candidates and bugfix-revisions of outdated releases are only available from the git repository mentioned above. Some Linux distributions may offer packages for outdated releases, though. The Bottle version number splits into three parts (**major.minor.revision**). These are *not* used to promote new features but to indicate important bug-fixes and/or API changes. Critical bugs are fixed in at least the two latest minor releases and announced in all available channels (mailinglist, twitter, github). Non-critical bugs or features are not guaranteed to be backported. This may change in the future, through. diff -Nru python-bottle-0.11.6/docs/index.rst python-bottle-0.12.0/docs/index.rst --- python-bottle-0.11.6/docs/index.rst 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/docs/index.rst 2013-12-03 17:16:12.000000000 +0000 @@ -3,23 +3,23 @@ .. _mako: http://www.makotemplates.org/ .. _cheetah: http://www.cheetahtemplate.org/ -.. _jinja2: http://jinja.pocoo.org/2/ +.. _jinja2: http://jinja.pocoo.org/ .. _paste: http://pythonpaste.org/ .. _fapws3: https://github.com/william-os4y/fapws3 .. _bjoern: https://github.com/jonashaag/bjoern .. _flup: http://trac.saddi.com/flup .. _cherrypy: http://www.cherrypy.org/ -.. _WSGI: http://www.wsgi.org/wsgi/ +.. _WSGI: http://www.wsgi.org/ .. _Python: http://python.org/ .. _testing: https://github.com/defnull/bottle/raw/master/bottle.py .. _issue_tracker: https://github.com/defnull/bottle/issues -.. _PyPi: http://pypi.python.org/pypi/bottle +.. _PyPI: http://pypi.python.org/pypi/bottle ============================ Bottle: Python Web Framework ============================ -Bottle is a fast, simple and lightweight WSGI_ micro web-framework for Python_. It is distributed as a single file module and has no dependencies other than the `Python Standard Library `_. +Bottle is a fast, simple and lightweight WSGI_ micro web-framework for Python_. It is distributed as a single file module and has no dependencies other than the `Python Standard Library `_. * **Routing:** Requests to function-call mapping with support for clean and dynamic URLs. @@ -33,8 +33,8 @@ from bottle import route, run, template - @route('/hello/:name') - def index(name='World'): + @route('/hello/') + def index(name): return template('Hello {{name}}!', name=name) run(host='localhost', port=8080) @@ -47,7 +47,7 @@ .. __: https://github.com/defnull/bottle/raw/master/bottle.py -Install the latest stable release via PyPi_ (``easy_install -U bottle``) or download `bottle.py`__ (unstable) into your project directory. There are no hard [1]_ dependencies other than the Python standard library. Bottle runs with **Python 2.5+ and 3.x**. +Install the latest stable release via PyPI_ (``easy_install -U bottle``) or download `bottle.py`__ (unstable) into your project directory. There are no hard [1]_ dependencies other than the Python standard library. Bottle runs with **Python 2.5+ and 3.x**. User's Guide =============== @@ -57,6 +57,7 @@ :maxdepth: 2 tutorial + configuration routing stpl api @@ -93,7 +94,7 @@ :hidden: plugins/index - + License ================== diff -Nru python-bottle-0.11.6/docs/plugins/index.rst python-bottle-0.12.0/docs/plugins/index.rst --- python-bottle-0.11.6/docs/plugins/index.rst 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/docs/plugins/index.rst 2013-12-03 17:16:12.000000000 +0000 @@ -8,6 +8,9 @@ Have a look at :ref:`plugins` for general questions about plugins (installation, usage). If you plan to develop a new plugin, the :doc:`/plugindev` may help you. +`Bottle-Cork `_ + Cork provides a simple set of methods to implement Authentication and Authorization in web applications based on Bottle. + `Bottle-Extras `_ Meta package to install the bottle plugin collection. diff -Nru python-bottle-0.11.6/docs/recipes.rst python-bottle-0.12.0/docs/recipes.rst --- python-bottle-0.11.6/docs/recipes.rst 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/docs/recipes.rst 2013-12-03 17:16:12.000000000 +0000 @@ -116,7 +116,7 @@ from bottle import request, response, route subproject = SomeWSGIApplication() - @route('/subproject/:subpath#.*#', method='ALL') + @route('/subproject/:subpath#.*#', method='ANY') def call_wsgi(subpath): new_environ = request.environ.copy() new_environ['SCRIPT_NAME'] = new_environ.get('SCRIPT_NAME','') + '/subproject' @@ -227,7 +227,7 @@ def say_bar(): return {'type': 'friendly', 'content': 'Hi!'} -You can also use the ``before_callback`` to take an action before +You can also use the ``before_request`` to take an action before every function gets called. diff -Nru python-bottle-0.11.6/docs/routing.rst python-bottle-0.12.0/docs/routing.rst --- python-bottle-0.11.6/docs/routing.rst 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/docs/routing.rst 2013-12-03 17:16:12.000000000 +0000 @@ -86,26 +86,6 @@ Try to avoid the old syntax in future projects if you can. It is not currently deprecated, but will be eventually. -Routing Order --------------------------------------------------------------------------------- - -With the power of wildcards and regular expressions it is possible to define overlapping routes. If multiple routes match the same URL, things get a bit tricky. To fully understand what happens in this case, you need to know in which order routes are checked by the router. - -First you should know that routes are grouped by their path rule. Two routes with the same path rule but different methods are grouped together and the first route determines the position of both routes. Fully identical routes (same path rule and method) replace previously defined routes, but keep the position of their predecessor. - -Static routes are checked first. This is mostly for performance reasons and can be switched off, but is currently the default. If no static route matches the request, the dynamic routes are checked in the order they were defined. The first hit ends the search. If no rule matched, a "404 Page not found" error is returned. - -In a second step, the request method is checked. If no exact match is found, and the request method is HEAD, the router checks for a GET route. Otherwise, it checks for an ANY route. If that fails too, a "405 Method not allowed" error is returned. - -Here is an example where this might bite you:: - - @route('//', method='GET') - @route('/save/', method='POST') - -The second route will never hit. Even POST requests don't arrive at the second route because the request method is checked in a separate step. The router stops at the first route which matches the request path, then checks for a valid request method, can't find one and raises a 405 error. - -Sounds complicated, and it is. That is the price for performance. It is best to avoid ambiguous routes at all and choose unique prefixes for each route. This implementation detail may change in the future, though. We are working on it. - Explicit routing configuration -------------------------------------------------------------------------------- @@ -115,14 +95,14 @@ Here is a basic example of explicit routing configuration for default bottle application:: def setup_routing(): - bottle.route('/', method='GET', index) - bottle.route('/edit', method=['GET', 'POST'], edit) + bottle.route('/', 'GET', index) + bottle.route('/edit', ['GET', 'POST'], edit) In fact, any :class:`Bottle` instance routing can be configured same way:: def setup_routing(app): - app.route('/new', method=['GET', 'POST'], form_new) - app.route('/edit', method=['GET', 'POST'], form_edit) + app.route('/new', ['GET', 'POST'], form_new) + app.route('/edit', ['GET', 'POST'], form_edit) app = Bottle() setup_routing(app) diff -Nru python-bottle-0.11.6/docs/stpl.rst python-bottle-0.12.0/docs/stpl.rst --- python-bottle-0.11.6/docs/stpl.rst 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/docs/stpl.rst 2013-12-03 17:16:12.000000000 +0000 @@ -32,10 +32,10 @@ The :class:`SimpleTemplate` syntax compiles directly to python bytecode and is executed on each :meth:`SimpleTemplate.render` call. Do not render untrusted templates! They may contain and execute harmful python code. -Inline Statements ------------------ +Inline Expressions +------------------ -You already learned the use of the ``{{...}}`` statement from the "Hello World!" example above, but there is more: any python statement is allowed within the curly brackets as long as it returns a string or something that has a string representation:: +You already learned the use of the ``{{...}}`` syntax from the "Hello World!" example above, but there is more: any python expression is allowed within the curly brackets as long as it evaluates to a string or something that has a string representation:: >>> template('Hello {{name}}!', name='World') u'Hello World!' @@ -44,150 +44,123 @@ >>> template('Hello {{name.title() if name else "stranger"}}!', name='mArC') u'Hello Marc!' -The contained python statement is executed at render-time and has access to all keyword arguments passed to the :meth:`SimpleTemplate.render` method. HTML special characters are escaped automatically to prevent `XSS `_ attacks. You can start the statement with an exclamation mark to disable escaping for that statement:: +The contained python expression is executed at render-time and has access to all keyword arguments passed to the :meth:`SimpleTemplate.render` method. HTML special characters are escaped automatically to prevent `XSS `_ attacks. You can start the expression with an exclamation mark to disable escaping for that expression:: >>> template('Hello {{name}}!', name='World') u'Hello <b>World</b>!' >>> template('Hello {{!name}}!', name='World') u'Hello World!' -.. highlight:: html+django - Embedded python code -------------------- -The ``%`` character marks a line of python code. The only difference between this and real python code is that you have to explicitly close blocks with an ``%end`` statement. In return you can align the code with the surrounding template and don't have to worry about correct indentation of blocks. The *SimpleTemplate* parser handles that for you. Lines *not* starting with a ``%`` are rendered as text as usual:: - - %if name: - Hi {{name}} - %else: - Hello stranger - %end - -The ``%`` character is only recognised if it is the first non-whitespace character in a line. To escape a leading ``%`` you can add a second one. ``%%`` is replaced by a single ``%`` in the resulting template:: - - This line contains a % but no python code. - %% This text-line starts with '%' - %%% This text-line starts with '%%' - -Suppressing line breaks ------------------------ - -You can suppress the line break in front of a code-line by adding a double backslash at the end of the line:: +.. highlight:: html+django - \\ - %if True: - nobreak\\ - %end - +The template engine allows you to embed lines or blocks of python code within your template. Code lines start with ``%`` and code blocks are surrounded by ``<%`` and ``%>`` tokens:: -This template produces the following output:: + % name = "Bob" # a line of python code +

    Some plain text in between

    + <% + # A block of python code + name = name.title().strip() + %> +

    More plain text

    + +Embedded python code follows regular python syntax, but with two additional syntax rules: + +* **Indentation is ignored.** You can put as much whitespace in front of statements as you want. This allows you to align your code with the surrounding markup and can greatly improve readability. +* Blocks that are normally indented now have to be closed explicitly with an ``end`` keyword. + +:: + +
      + % for item in basket: +
    • {{item}}
    • + % end +
    - nobreak +Both the ``%`` and the ``<%`` tokens are only recognized if they are the first non-whitespace characters in a line. You don't have to escape them if they appear mid-text in your template markup. Only if a line of text starts with one of these tokens, you have to escape it with a backslash. In the rare case where the backslash + token combination appears in your markup at the beginning of a line, you can always help yourself with a string literal in an inline expression:: -The ``%include`` Statement --------------------------- + This line contains % and <% but no python code. + \% This text-line starts with the '%' token. + \<% Another line that starts with a token but is rendered as text. + {{'\\%'}} this line starts with an escaped token. -You can include other templates using the ``%include sub_template [kwargs]`` statement. The ``sub_template`` parameter specifies the name or path of the template to be included. The rest of the line is interpreted as a comma-separated list of ``key=statement`` pairs similar to keyword arguments in function calls. They are passed to the sub-template analogous to a :meth:`SimpleTemplate.render` call. The ``**kwargs`` syntax for passing a dict is allowed too:: +If you find yourself to escape a lot, consider using :ref:`custom tokens `. - %include header_template title='Hello World' -

    Hello World

    - %include footer_template +Whitespace Control +----------------------- -The ``%rebase`` Statement -------------------------- +Code blocks and code lines always span the whole line. Whitespace in front of after a code segment is stripped away. You won't see empty lines or dangling whitespace in your template because of embedded code:: -The ``%rebase base_template [kwargs]`` statement causes ``base_template`` to be rendered instead of the original template. The base-template then includes the original template using an empty ``%include`` statement and has access to all variables specified by ``kwargs``. This way it is possible to wrap a template with another template or to simulate the inheritance feature found in some other template engines. +
    + % if True: + content + % end +
    -Let's say you have a content template and want to wrap it with a common HTML layout frame. Instead of including several header and footer templates, you can use a single base-template to render the layout frame. +This snippet renders to clean and compact html:: -Base-template named ``layout.tpl``:: +
    + content +
    - - - {{title or 'No title'}} - - - %include - - +But embedding code still requires you to start a new line, which may not what you want to see in your rendered template. To skip the newline in front of a code segment, end the text line with a double-backslash:: -Main-template named ``content.tpl``:: +
    \\ + %if True: + content\\ + %end +
    - This is the page content: {{content}} - %rebase layout title='Content Title' +THis time the rendered template looks like this:: -Now you can render ``content.tpl``: +
    content
    -.. code-block:: python +This only works directly in front of code segments. In all other places you can control the whitespace yourself and don't need any special syntax. - >>> print template('content', content='Hello World!') +Template Functions +================== -.. code-block:: html +Each template is preloaded with a bunch of functions that help with the most common use cases. These functions are always available. You don't have to import or provide them yourself. For everything not covered here there are probably good python libraries available. Remember that you can ``import`` anything you want within your templates. They are python programs after all. - - - Content Title - - - This is the page content: Hello World! - - +.. currentmodule:: stpl -A more complex scenario involves chained rebases and multiple content blocks. The ``block_content.tpl`` template defines two functions and passes them to a ``columns.tpl`` base template:: +.. versionchanged:: 0.12 + Prior to this release, :func:`include` and :func:`rebase` were sytnax keywords, not functions. - %def leftblock(): - Left block content. - %end - %def rightblock(): - Right block content. - %end - %rebase columns leftblock=leftblock, rightblock=rightblock, title=title +.. function:: include(sub_template, **variables) -The ``columns.tpl`` base-template uses the two callables to render the content of the left and right column. It then wraps itself with the ``layout.tpl`` template defined earlier:: + Render a sub-template with the specified variables and insert the resulting text into the current template. The function returns a dictionary containing the local variables passed to or defined within the sub-template:: - %rebase layout title=title -
    - %leftblock() -
    -
    - %rightblock() -
    + % include('header.tpl', title='Page Title') + Page Content + % include('foother.tpl') -Lets see how ``block_content.tpl`` renders: +.. function:: rebase(name, **variables) -.. code-block:: python + Mark the current template to be later included into a different template. After the current template is rendered, its resulting text is stored in a variable named ``base`` and passed to the base-template, which is then rendered. This can be used to `wrap` a template with surrounding text, or simulate the inheritance feature found in other template engines:: - >>> print template('block_content', title='Hello World!') + % rebase('base.tpl', title='Page Title') +

    Page Content ...

    -.. code-block:: html + This can be combined with the following ``base.tpl``:: - - - Hello World - - -
    - Left block content. -
    -
    - Right block content. -
    - - + + + {{title or 'No title'}} + + + {{base}} + + -Namespace Functions -------------------- Accessing undefined variables in a template raises :exc:`NameError` and stops rendering immediately. This is standard python behavior and nothing new, but vanilla python lacks an easy way to check the availability of a variable. This quickly gets annoying if you want to support flexible inputs or use the -same template in different situations. SimpleTemplate helps you out here: The -following three functions are defined in the default namespace and accessible -from anywhere within a template: - -.. currentmodule:: stpl +same template in different situations. These functions may help: .. function:: defined(name) @@ -222,10 +195,3 @@ .. autoclass:: SimpleTemplate :members: -Known bugs -============================== - -Some syntax constructions allowed in python are problematic within a template. The following syntaxes won't work with SimpleTemplate: - - * Multi-line statements must end with a backslash (``\``) and a comment, if present, must not contain any additional ``#`` characters. - * Multi-line strings are not supported yet. diff -Nru python-bottle-0.11.6/docs/tutorial.rst python-bottle-0.12.0/docs/tutorial.rst --- python-bottle-0.11.6/docs/tutorial.rst 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/docs/tutorial.rst 2013-12-03 17:16:12.000000000 +0000 @@ -13,7 +13,7 @@ .. _mod_wsgi: http://code.google.com/p/modwsgi/ .. _Paste: http://pythonpaste.org/ .. _Pound: http://www.apsis.ch/pound/ -.. _`WSGI Specification`: http://www.wsgi.org/wsgi/ +.. _`WSGI Specification`: http://www.wsgi.org/ .. _issue: http://github.com/defnull/bottle/issues .. _Python: http://python.org/ .. _SimpleCookie: http://docs.python.org/library/cookie.html#morsel-objects @@ -36,7 +36,7 @@ $ wget http://bottlepy.org/bottle.py -This will get you the latest development snapshot that includes all the new features. If you prefer a more stable environment, you should stick with the stable releases. These are available on `PyPi `_ and can be installed via :command:`pip` (recommended), :command:`easy_install` or your package manager: +This will get you the latest development snapshot that includes all the new features. If you prefer a more stable environment, you should stick with the stable releases. These are available on `PyPI `_ and can be installed via :command:`pip` (recommended), :command:`easy_install` or your package manager: .. code-block:: bash @@ -78,9 +78,9 @@ This is it. Run this script, visit http://localhost:8080/hello and you will see "Hello World!" in your browser. Here is how it works: -The :func:`route` decorator binds a piece of code to an URL path. In this case, we link the ``/hello`` URL to the ``hello()`` function. This is called a `route` (hence the decorator name) and is the most important concept of this framework. You can define as many routes as you want. Whenever a browser requests an URL, the associated function is called and the return value is sent back to the browser. Its as simple as that. +The :func:`route` decorator binds a piece of code to an URL path. In this case, we link the ``/hello`` path to the ``hello()`` function. This is called a `route` (hence the decorator name) and is the most important concept of this framework. You can define as many routes as you want. Whenever a browser requests an URL, the associated function is called and the return value is sent back to the browser. Its as simple as that. -The :func:`run` call in the last line starts a built-in development server. It runs on `localhost` port 8080 and serves requests until you hit :kbd:`Control-c`. You can switch the server backend later, but for now a development server is all we need. It requires no setup at all and is an incredibly painless way to get your application up and running for local tests. +The :func:`run` call in the last line starts a built-in development server. It runs on ``localhost`` port ``8080`` and serves requests until you hit :kbd:`Control-c`. You can switch the server backend later, but for now a development server is all we need. It requires no setup at all and is an incredibly painless way to get your application up and running for local tests. The :ref:`tutorial-debugging` is very helpful during early development, but should be switched off for public applications. Keep that in mind. @@ -88,12 +88,12 @@ .. _tutorial-default: -The `Default Application` +The Default Application ------------------------------------------------------------------------------ For the sake of simplicity, most examples in this tutorial use a module-level :func:`route` decorator to define routes. This adds routes to a global "default application", an instance of :class:`Bottle` that is automatically created the first time you call :func:`route`. Several other module-level decorators and functions relate to this default application, but if you prefer a more object oriented approach and don't mind the extra typing, you can create a separate application object and use that instead of the global one:: - from bottle import Bottle, run, template + from bottle import Bottle, run app = Bottle() @@ -199,24 +199,26 @@ The POST method is commonly used for HTML form submission. This example shows how to handle a login form using POST:: - from bottle import get, post, request + from bottle import get, post, request # or route @get('/login') # or @route('/login') - def login_form(): - return '''
    - - - -
    ''' + def login(): + return ''' +
    + Username: + Password: + +
    + ''' @post('/login') # or @route('/login', method='POST') - def login_submit(): - name = request.forms.get('name') + def do_login(): + username = request.forms.get('username') password = request.forms.get('password') - if check_login(name, password): - return "

    Your login was correct

    " + if check_login(username, password): + return "

    Your login information was correct.

    " else: - return "

    Login failed

    " + return "

    Login failed.

    " In this example the ``/login`` URL is linked to two distinct callbacks, one for GET requests and another for POST requests. The first one displays a HTML form to the user. The second callback is invoked on a form submission and checks the login credentials the user entered into the form. The use of :attr:`Request.forms` is further described in the :ref:`tutorial-request` section. @@ -333,7 +335,7 @@ :: from bottle import static_file - @route('/images/#') + @route('/images/') def send_image(filename): return static_file(filename, root='/path/to/image/files', mimetype='image/png') @@ -450,20 +452,20 @@ As mentioned above, cookies are easily forged by malicious clients. Bottle can cryptographically sign your cookies to prevent this kind of manipulation. All you have to do is to provide a signature key via the `secret` keyword argument whenever you read or set a cookie and keep that key a secret. As a result, :meth:`Request.get_cookie` will return ``None`` if the cookie is not signed or the signature keys don't match:: @route('/login') - def login(): + def do_login(): username = request.forms.get('username') password = request.forms.get('password') - if check_user_credentials(username, password): + if check_login(username, password): response.set_cookie("account", username, secret='some-secret-key') - return "Welcome %s! You are now logged in." % username + return template("

    Welcome {{name}}! You are now logged in.

    ", name=username) else: - return "Login failed." + return "

    Login failed.

    " @route('/restricted') def restricted_area(): username = request.get_cookie("account", secret='some-secret-key') if username: - return "Hello %s. Welcome back." % username + return template("Hello {{name}}. Welcome back.", name=username) else: return "You are not logged in. Access denied." @@ -484,21 +486,71 @@ Request Data ============================================================================== -Bottle provides access to HTTP-related metadata such as cookies, headers and POST form data through a global ``request`` object. This object always contains information about the *current* request, as long as it is accessed from within a callback function. This works even in multi-threaded environments where multiple requests are handled at the same time. For details on how a global object can be thread-safe, see :doc:`contextlocal`. +Cookies, HTTP header, HTML ``
    `` fields and other request data is available through the global :data:`request` object. This special object always refers to the *current* request, even in multi-threaded environments where multiple client connections are handled at the same time:: + + from bottle import request, route, template + + @route('/hello') + def hello(): + name = request.cookies.username or 'Guest' + return template('Hello {{name}}', name=name) + +The :data:`request` object is a subclass of :class:`BaseRequest` and has a very rich API to access data. We only cover the most commonly used features here, but it should be enough to get started. + + + +Introducing :class:`FormsDict` +-------------------------------------------------------------------------------- + +Bottle uses a special type of dictionary to store form data and cookies. :class:`FormsDict` behaves like a normal dictionary, but has some additional features to make your life easier. + +**Attribute access**: All values in the dictionary are also accessible as attributes. These virtual attributes return unicode strings, even if the value is missing or unicode decoding fails. In that case, the string is empty, but still present:: + + name = request.cookies.name + + # is a shortcut for: + + name = request.cookies.getunicode('name') # encoding='utf-8' (default) + + # which basically does this: + + try: + name = request.cookies.get('name', '').decode('utf-8') + except UnicodeError: + name = u'' + +**Multiple values per key:** :class:`FormsDict` is a subclass of :class:`MultiDict` and can store more than one value per key. The standard dictionary access methods will only return a single value, but the :meth:`~MultiDict.getall` method returns a (possibly empty) list of all values for a specific key:: + + for choice in request.forms.getall('multiple_choice'): + do_something(choice) + +**WTForms support:** Some libraries (e.g. `WTForms `_) want all-unicode dictionaries as input. :meth:`FormsDict.decode` does that for you. It decodes all values and returns a copy of itself, while preserving multiple values per key and all the other features. .. note:: - Bottle stores most of the parsed HTTP metadata in :class:`FormsDict` instances. These behave like normal dictionaries, but have some additional features: All values in the dictionary are available as attributes. These virtual attributes always return a unicode string, even if the value is missing. In that case, the string is empty. + In **Python 2** all keys and values are byte-strings. If you need unicode, you can call :meth:`FormsDict.getunicode` or fetch values via attribute access. Both methods try to decode the string (default: utf8) and return an empty string if that fails. No need to catch :exc:`UnicodeError`:: + + >>> request.query['city'] + 'G\xc3\xb6ttingen' # A utf8 byte string + >>> request.query.city + u'Göttingen' # The same string as unicode + + In **Python 3** all strings are unicode, but HTTP is a byte-based wire protocol. The server has to decode the byte strings somehow before they are passed to the application. To be on the safe side, WSGI suggests ISO-8859-1 (aka latin1), a reversible single-byte codec that can be re-encoded with a different encoding later. Bottle does that for :meth:`FormsDict.getunicode` and attribute access, but not for the dict-access methods. These return the unchanged values as provided by the server implementation, which is probably not what you want. - :class:`FormsDict` is a subclass of :class:`MultiDict` and can store more than one value per key. The standard dictionary access methods will only return a single value, but the :meth:`MultiDict.getall` method returns a (possibly empty) list of all values for a specific key. + >>> request.query['city'] + 'Göttingen' # An utf8 string provisionally decoded as ISO-8859-1 by the server + >>> request.query.city + 'Göttingen' # The same string correctly re-encoded as utf8 by bottle -The full API and feature list is described in the API section (see :class:`Request`), but the most common use cases and features are covered here, too. + If you need the whole dictionary with correctly decoded values (e.g. for WTForms), you can call :meth:`FormsDict.decode` to get a re-encoded copy. Cookies -------------------------------------------------------------------------------- -Cookies are stored in :attr:`BaseRequest.cookies` as a :class:`FormsDict`. The :meth:`BaseRequest.get_cookie` method allows access to :ref:`signed cookies ` as described in a separate section. This example shows a simple cookie-based view counter:: +Cookies are small pieces of text stored in the clients browser and sent back to the server with each request. They are useful to keep some state around for more than one request (HTTP itself is stateless), but should not be used for security related stuff. They can be easily forged by the client. + +All cookies sent by the client are available through :attr:`BaseRequest.cookies` (a :class:`FormsDict`). This example shows a simple cookie-based view counter:: from bottle import route, request, response @route('/counter') @@ -508,11 +560,12 @@ response.set_cookie('counter', str(count)) return 'You visited this page %d times' % count +The :meth:`BaseRequest.get_cookie` method is a different way do access cookies. It supports decoding :ref:`signed cookies ` as described in a separate section. HTTP Headers -------------------------------------------------------------------------------- -All HTTP headers sent by the client (e.g. ``Referer``, ``Agent`` or ``Accept-Language``) are stored in a :class:`WSGIHeaderDict` and accessible through :attr:`BaseRequest.headers`. A :class:`WSGIHeaderDict` is basically a dictionary with case-insensitive keys:: +All HTTP headers sent by the client (e.g. ``Referer``, ``Agent`` or ``Accept-Language``) are stored in a :class:`WSGIHeaderDict` and accessible through the :attr:`BaseRequest.headers` attribute. A :class:`WSGIHeaderDict` is basically a dictionary with case-insensitive keys:: from bottle import route, request @route('/is_ajax') @@ -526,64 +579,113 @@ Query Variables -------------------------------------------------------------------------------- -The query string (as in ``/forum?id=1&page=5``) is commonly used to transmit a small number of key/value pairs to the server. You can use the :attr:`BaseRequest.query` (a :class:`FormsDict`) to access these values and the :attr:`BaseRequest.query_string` attribute to get the whole string. +The query string (as in ``/forum?id=1&page=5``) is commonly used to transmit a small number of key/value pairs to the server. You can use the :attr:`BaseRequest.query` attribute (a :class:`FormsDict`) to access these values and the :attr:`BaseRequest.query_string` attribute to get the whole string. :: - from bottle import route, request, response + from bottle import route, request, response, template @route('/forum') def display_forum(): forum_id = request.query.id page = request.query.page or '1' - return 'Forum ID: %s (page %s)' % (forum_id, page) + return template('Forum ID: {{id}} (page {{page}})', id=forum_id, page=page) + + +HTML `` Handling +---------------------- + +Let us start from the beginning. In HTML, a typical ```` looks something like this: + +.. code-block:: html + + + Username: + Password: + + + +The ``action`` attribute specifies the URL that will receive the form data. ``method`` defines the HTTP method to use (``GET`` or ``POST``). With ``method="get"`` the form values are appended to the URL and available through :attr:`BaseRequest.query` as described above. This is considered insecure and has other limitations, so we use ``method="post"`` here. If in doubt, use ``POST`` forms. + +Form fields transmitted via ``POST`` are stored in :attr:`BaseRequest.forms` as a :class:`FormsDict`. The server side code may look like this:: + + from bottle import route, request + @route('/login') + def login(): + return ''' +
    + Username: + Password: + +
    + ''' + + @route('/login', method='POST') + def do_login(): + username = request.forms.get('username') + password = request.forms.get('password') + if check_login(username, password): + return "

    Your login information was correct.

    " + else: + return "

    Login failed.

    " -POST Form Data and File Uploads -------------------------------- +There are several other attributes used to access form data. Some of them combine values from different sources for easier access. The following table should give you a decent overview. -The request body of ``POST`` and ``PUT`` requests may contain form data encoded in various formats. The :attr:`BaseRequest.forms` dictionary contains parsed textual form fields, :attr:`BaseRequest.files` stores file uploads and :attr:`BaseRequest.POST` combines both dictionaries into one. All three are :class:`FormsDict` instances and are created on demand. File uploads are saved as special :class:`cgi.FieldStorage` objects along with some metadata. Finally, you can access the raw body data as a file-like object via :attr:`BaseRequest.body`. +============================== =============== ================ ============ +Attribute GET Form fields POST Form fields File Uploads +============================== =============== ================ ============ +:attr:`BaseRequest.query` yes no no +:attr:`BaseRequest.forms` no yes no +:attr:`BaseRequest.files` no no yes +:attr:`BaseRequest.params` yes yes no +:attr:`BaseRequest.GET` yes no no +:attr:`BaseRequest.POST` no yes yes +============================== =============== ================ ============ -Here is an example for a simple file upload form: + +File uploads +------------ + +To support file uploads, we have to change the ``
    `` tag a bit. First, we tell the browser to encode the form data in a different way by adding an ``enctype="multipart/form-data"`` attribute to the ```` tag. Then, we add ```` tags to allow the user to select a file. Here is an example: .. code-block:: html - - + Category: + Select a file: +
    -:: +Bottle stores file uploads in :attr:`BaseRequest.files` as :class:`FileUpload` instances, along with some metadata about the upload. Let us assume you just want to save the file to disk:: - from bottle import route, request @route('/upload', method='POST') def do_upload(): - name = request.forms.name - data = request.files.data - if name and data and data.file: - raw = data.file.read() # This is dangerous for big files - filename = data.filename - return "Hello %s! You uploaded %s (%d bytes)." % (name, filename, len(raw)) - return "You missed a field." + category = request.forms.get('category') + upload = request.files.get('upload') + name, ext = os.path.splitext(upload.filename) + if ext not in ('.png','.jpg','.jpeg'): + return 'File extension not allowed.' + + save_path = get_save_path_for_category(category) + upload.save(save_path) # appends upload.filename automatically + return 'OK' + +:attr:`FileUpload.filename` contains the name of the file on the clients file system, but is cleaned up and normalized to prevent bugs caused by unsupported characters or path segments in the filename. If you need the unmodified name as sent by the client, have a look at :attr:`FileUpload.raw_filename`. +The :attr:`FileUpload.save` method is highly recommended if you want to store the file to disk. It prevents some common errors (e.g. it does not overwrite existing files unless you tell it to) and stores the file in a memory efficient way. You can access the file object directly via :attr:`FileUpload.file`. Just be careful. -Unicode issues ------------------------ -In **Python 2** all keys and values are byte-strings. If you need unicode, you can call :meth:`FormsDict.getunicode` or fetch values via attribute access. Both methods try to decode the string (default: utf8) and return an empty string if that fails. No need to catch :exc:`UnicodeError`:: +JSON Content +-------------------- - >>> request.query['city'] - 'G\xc3\xb6ttingen' # A utf8 byte string - >>> request.query.city - u'Göttingen' # The same string as unicode +Some JavaScript or REST clients send ``application/json`` content to the server. The :attr:`BaseRequest.json` attribute contains the parsed data structure, if available. -In **Python 3** all strings are unicode, but HTTP is a byte-based wire protocol. The server has to decode the byte strings somehow before they are passed to the application. To be on the safe side, WSGI suggests ISO-8859-1 (aka latin1), a reversible single-byte codec that can be re-encoded with a different encoding later. Bottle does that for :meth:`FormsDict.getunicode` and attribute access, but not for the dict-access methods. These return the unchanged values as provided by the server implementation, which is probably not what you want. - >>> request.query['city'] - 'Göttingen' # An utf8 string provisionally decoded as ISO-8859-1 by the server - >>> request.query.city - 'Göttingen' # The same string correctly re-encoded as utf8 by bottle +The raw request body +-------------------- + +You can access the raw body data as a file-like object via :attr:`BaseRequest.body`. This is a :class:`BytesIO` buffer or a temporary file depending on the content length and :attr:`BaseRequest.MEMFILE_MAX` setting. In both cases the body is completely buffered before you can access the attribute. If you expect huge amounts of data and want to get direct unbuffered access to the stream, have a look at ``request['wsgi.input']``. -If you need the whole dictionary with correctly decoded values (e.g. for WTForms), you can call :meth:`FormsDict.decode` to get a re-encoded copy. WSGI Environment @@ -596,7 +698,7 @@ ip = request.environ.get('REMOTE_ADDR') # or ip = request.get('REMOTE_ADDR') # or ip = request['REMOTE_ADDR'] - return "Your IP is: %s" % ip + return template("Your IP is: {{ip}}", ip=ip) @@ -735,17 +837,25 @@ You may want to explicitly disable a plugin for a number of routes. The :func:`route` decorator has a ``skip`` parameter for this purpose:: - sqlite_plugin = SQLitePlugin(dbfile='/tmp/test.db') + sqlite_plugin = SQLitePlugin(dbfile='/tmp/test1.db') install(sqlite_plugin) + dbfile1 = '/tmp/test1.db' + dbfile2 = '/tmp/test2.db' + @route('/open/', skip=[sqlite_plugin]) def open_db(db): # The 'db' keyword argument is not touched by the plugin this time. - if db in ('test', 'test2'): - # The plugin handle can be used for runtime configuration, too. - sqlite_plugin.dbfile = '/tmp/%s.db' % db - return "Database File switched to: /tmp/%s.db" % db - abort(404, "No such database.") + + # The plugin handle can be used for runtime configuration, too. + if db == 'test1': + sqlite_plugin.dbfile = dbfile1 + elif db == 'test2': + sqlite_plugin.dbfile = dbfile2 + else: + abort(404, "No such database.") + + return "Database File switched to: " + sqlite_plugin.dbfile The ``skip`` parameter accepts a single value or a list of values. You can use a name, class or instance to identify the plugin that is to be skipped. Set ``skip=True`` to skip all plugins at once. diff -Nru python-bottle-0.11.6/docs/tutorial_app.rst python-bottle-0.12.0/docs/tutorial_app.rst --- python-bottle-0.11.6/docs/tutorial_app.rst 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/docs/tutorial_app.rst 2013-12-03 17:16:12.000000000 +0000 @@ -151,7 +151,7 @@ -A further quiet nice feature is auto-reloading, which is enabled by modifying the ``run()`` statement to +Another quite nice feature is auto-reloading, which is enabled by modifying the ``run()`` statement to :: @@ -159,7 +159,7 @@ This will automatically detect changes to the script and reload the new version once it is called again, without the need to stop and start the server. -Again, the feature is mainly supposed to be used while development, not on productive systems. +Again, the feature is mainly supposed to be used while developing, not on production systems. .. rubric:: Bottle Template To Format The Output @@ -371,7 +371,7 @@ As said above, the solution is a regular expression:: - @route('/item:item#[1-9]+#') + @route('/item:item#[0-9]+#') def show_item(item): conn = sqlite3.connect('todo.db') c = conn.cursor() @@ -383,7 +383,7 @@ else: return 'Task: %s' %result[0] -Of course, this example is somehow artificially constructed - it would be easier to use a plain dynamic route only combined with a validation. Nevertheless, we want to see how regular expression routes work: the line ``@route(/item:item_#[1-9]+#)`` starts like a normal route, but the part surrounded by # is interpreted as a regular expression, which is the dynamic part of the route. So in this case, we want to match any digit between 0 and 9. The following function "show_item" just checks whether the given item is present in the database or not. In case it is present, the corresponding text of the task is returned. As you can see, only the regular expression part of the route is passed forward. Furthermore, it is always forwarded as a string, even if it is a plain integer number, like in this case. +Of course, this example is somehow artificially constructed - it would be easier to use a plain dynamic route only combined with a validation. Nevertheless, we want to see how regular expression routes work: the line ``@route(/item:item_#[0-9]+#)`` starts like a normal route, but the part surrounded by # is interpreted as a regular expression, which is the dynamic part of the route. So in this case, we want to match any digit between 0 and 9. The following function "show_item" just checks whether the given item is present in the database or not. In case it is present, the corresponding text of the task is returned. As you can see, only the regular expression part of the route is passed forward. Furthermore, it is always forwarded as a string, even if it is a plain integer number, like in this case. .. rubric:: Returning Static Files @@ -405,7 +405,7 @@ So, let's assume we want to return the data generated in the regular expression route example as a JSON object. The code looks like this:: - @route('/json:json#[1-9]+#') + @route('/json:json#[0-9]+#') def show_json(json): conn = sqlite3.connect('todo.db') c = conn.cursor() @@ -625,7 +625,7 @@ return template('edit_task', old = cur_data, no = no) - @route('/item:item#[1-9]+#') + @route('/item:item#[0-9]+#') def show_item(item): conn = sqlite3.connect('todo.db') @@ -644,7 +644,7 @@ static_file('help.html', root='.') - @route('/json:json#[1-9]+#') + @route('/json:json#[0-9]+#') def show_json(json): conn = sqlite3.connect('todo.db') diff -Nru python-bottle-0.11.6/setup.py python-bottle-0.12.0/setup.py --- python-bottle-0.11.6/setup.py 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/setup.py 2013-12-03 17:16:12.000000000 +0000 @@ -33,7 +33,10 @@ 'Programming Language :: Python :: 2.5', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3'], + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.2', + 'Programming Language :: Python :: 3.3', + ], ) diff -Nru python-bottle-0.11.6/test/.coveragerc python-bottle-0.12.0/test/.coveragerc --- python-bottle-0.11.6/test/.coveragerc 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/test/.coveragerc 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,7 @@ +[run] +branch = True +parallel = True +data_file = ../build/.coverage + +[html] +directory = build/coverage diff -Nru python-bottle-0.11.6/test/build_python.sh python-bottle-0.12.0/test/build_python.sh --- python-bottle-0.11.6/test/build_python.sh 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/test/build_python.sh 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,57 @@ +#!/bin/bash -e +# This script builds a specific python release to a prefix directory + +# Stop on any errors +trap exit ERR + +VERSION=$1 +PREFIX=$2 + +test -d $PREFIX || mkdir -p $PREFIX || die "ERROR: Could not find/create $PREFIX" +PREFIX=`cd $PREFIX; pwd` + +PATH="$PREFIX/bin:$PATH" + +# Add ubuntus special lib and include dirs so python can find them. +export arch=$(dpkg-architecture -qDEB_HOST_MULTIARCH) +export LDFLAGS="-L/usr/lib/$arch -L/lib/$arch" +export CFLAGS="-I/usr/include/$arch" +export CPPFLAGS="-I/usr/include/$arch" + +if [ -x $PREFIX/bin/python$VERSION ]; then + echo "Found Python executable. Skipping build" + exit 0 +fi + +pushd $PREFIX || exit 1 + echo "Downloading source ..." + wget -N http://hg.python.org/cpython/archive/$VERSION.tar.gz || exit 1 + + echo "Extracting source ..." + tar -xzf $VERSION.tar.gz || exit 1 + + pushd cpython-$VERSION || exit 1 + echo "Running ./configure --prefix=$PREFIX ..." + ./configure --prefix=$PREFIX || exit 1 + + echo "Running make && make install ..." + (make -j8 && make install) || exit 1 + + echo "Installing distribute and pip..." + hash -r + wget -N -O $PREFIX/distribute_setup.py \ + http://python-distribute.org/distribute_setup.py || exit 1 + + $PREFIX/bin/python$VERSION $PREFIX/distribute_setup.py || exit 1 + if [ $VERSION = "2.5" ]; then + $PREFIX/bin/easy_install-$VERSION simplejson || exit 1 + fi + + popd + + echo "Cleaning up..." + rm -rf $VERSION.tar.gz distribute_setup.py cpython-$VERSION +popd + + + diff -Nru python-bottle-0.11.6/test/servertest.py python-bottle-0.12.0/test/servertest.py --- python-bottle-0.11.6/test/servertest.py 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/test/servertest.py 2013-12-03 17:16:12.000000000 +0000 @@ -1,17 +1,18 @@ if __name__ != '__main__': raise ImportError('This is not a module, but a script.') +try: + import coverage + coverage.process_startup() +except ImportError: + pass + import sys, os, socket test_root = os.path.dirname(os.path.abspath(__file__)) os.chdir(test_root) sys.path.insert(0, os.path.dirname(test_root)) sys.path.insert(0, test_root) -if 'coverage' in sys.argv: - import coverage - cov = coverage.coverage(data_suffix=True, branch=True) - cov.start() - try: server = sys.argv[1] port = int(sys.argv[2]) @@ -25,13 +26,9 @@ run(port=port, server=server, quiet=True) except socket.error: - sys.exit(1) + sys.exit(3) except ImportError: sys.exit(128) except KeyboardInterrupt: pass -finally: - if 'coverage' in sys.argv: - cov.stop() - cov.save() diff -Nru python-bottle-0.11.6/test/test_auth.py python-bottle-0.12.0/test/test_auth.py --- python-bottle-0.11.6/test/test_auth.py 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/test/test_auth.py 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +import bottle +from tools import ServerTestBase + +class TestBasicAuth(ServerTestBase): + + def test__header(self): + @bottle.route('/') + @bottle.auth_basic(lambda x, y: False) + def test(): return {} + self.assertStatus(401) + self.assertHeader('Www-Authenticate', 'Basic realm="private"') diff -Nru python-bottle-0.11.6/test/test_config.py python-bottle-0.12.0/test/test_config.py --- python-bottle-0.11.6/test/test_config.py 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/test/test_config.py 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,45 @@ +import unittest +from bottle import ConfigDict + +class TestConfDict(unittest.TestCase): + def test_write(self): + c = ConfigDict() + c['key'] = 'value' + self.assertEqual(c['key'], 'value') + self.assertTrue('key' in c) + c['key'] = 'value2' + self.assertEqual(c['key'], 'value2') + + def test_update(self): + c = ConfigDict() + c['key'] = 'value' + c.update(key='value2', key2='value3') + self.assertEqual(c['key'], 'value2') + self.assertEqual(c['key2'], 'value3') + + def test_namespaces(self): + c = ConfigDict() + c.update('a.b', key='value') + self.assertEqual(c['a.b.key'], 'value') + + def test_meta(self): + c = ConfigDict() + c.meta_set('bool', 'filter', bool) + c.meta_set('int', 'filter', int) + c['bool'] = 'I am so true!' + c['int'] = '6' + self.assertTrue(c['bool'] is True) + self.assertEquals(c['int'], 6) + self.assertRaises(ValueError, lambda: c.update(int='not an int')) + + def test_load_dict(self): + c = ConfigDict() + d = dict(a=dict(b=dict(foo=5, bar=6), baz=7)) + c.load_dict(d) + self.assertEquals(c['a.b.foo'], 5) + self.assertEquals(c['a.b.bar'], 6) + self.assertEquals(c['a.baz'], 7) + +if __name__ == '__main__': #pragma: no cover + unittest.main() + diff -Nru python-bottle-0.11.6/test/test_environ.py python-bottle-0.12.0/test/test_environ.py --- python-bottle-0.11.6/test/test_environ.py 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/test/test_environ.py 2013-12-03 17:16:12.000000000 +0000 @@ -2,25 +2,36 @@ ''' Tests for the BaseRequest and BaseResponse objects and their subclasses. ''' import unittest -import sys, os.path +import sys import bottle -from bottle import request, response, tob, touni, tonat, json_dumps, _e +from bottle import request, tob, touni, tonat, json_dumps, _e, HTTPError, parse_date import tools import wsgiref.util -import threading import base64 from bottle import BaseRequest, BaseResponse, LocalRequest class TestRequest(unittest.TestCase): - def test_app(self): + def test_app_property(self): e = {} r = BaseRequest(e) self.assertRaises(RuntimeError, lambda: r.app) e.update({'bottle.app': 5}) self.assertEqual(r.app, 5) + def test_route_property(self): + e = {'bottle.route': 5} + r = BaseRequest(e) + self.assertEqual(r.route, 5) + + def test_url_for_property(self): + e = {} + r = BaseRequest(e) + self.assertRaises(RuntimeError, lambda: r.url_args) + e.update({'route.url_args': {'a': 5}}) + self.assertEqual(r.url_args, {'a': 5}) + def test_path(self): """ PATH_INFO normalization. """ # Legal paths @@ -268,6 +279,40 @@ self.assertEqual(42, len(request.body.readline())) self.assertEqual(42, len(request.body.readline(1024))) + def _test_chunked(self, body, expect): + e = {} + wsgiref.util.setup_testing_defaults(e) + e['wsgi.input'].write(tob(body)) + e['wsgi.input'].seek(0) + e['HTTP_TRANSFER_ENCODING'] = 'chunked' + if isinstance(expect, str): + self.assertEquals(tob(expect), BaseRequest(e).body.read()) + else: + self.assertRaises(expect, lambda: BaseRequest(e).body) + + def test_chunked(self): + self._test_chunked('1\r\nx\r\nff\r\n' + 'y'*255 + '\r\n0\r\n', + 'x' + 'y'*255) + self._test_chunked('8\r\nxxxxxxxx\r\n0\r\n','xxxxxxxx') + self._test_chunked('0\r\n', '') + + def test_chunked_meta_fields(self): + self._test_chunked('8 ; foo\r\nxxxxxxxx\r\n0\r\n','xxxxxxxx') + self._test_chunked('8;foo\r\nxxxxxxxx\r\n0\r\n','xxxxxxxx') + self._test_chunked('8;foo=bar\r\nxxxxxxxx\r\n0\r\n','xxxxxxxx') + + def test_chunked_not_terminated(self): + self._test_chunked('1\r\nx\r\n', HTTPError) + + def test_chunked_wrong_size(self): + self._test_chunked('2\r\nx\r\n', HTTPError) + + def test_chunked_illegal_size(self): + self._test_chunked('x\r\nx\r\n', HTTPError) + + def test_chunked_not_chunked_at_all(self): + self._test_chunked('abcdef', HTTPError) + def test_multipart(self): """ Environ: POST (multipart files and multible values per key) """ fields = [('field1','value1'), ('field2','value2'), ('field2','value3')] @@ -328,7 +373,7 @@ e['wsgi.input'].write(tob(json_dumps(test))) e['wsgi.input'].seek(0) e['CONTENT_LENGTH'] = str(len(json_dumps(test))) - self.assertEqual(BaseRequest(e).json, None) + self.assertRaises(HTTPError, lambda: BaseRequest(e).json) def test_json_valid(self): """ Environ: Request.json property. """ @@ -381,27 +426,6 @@ del r.environ['HTTP_X_FORWARDED_FOR'] self.assertEqual(r.remote_addr, ips[1]) - def test_maxparam(self): - ips = ['1.2.3.4', '2.3.4.5', '3.4.5.6'] - e = {} - wsgiref.util.setup_testing_defaults(e) - e['wsgi.input'].write(tob('a=a&b=b&c=c')) - e['wsgi.input'].seek(0) - e['CONTENT_LENGTH'] = '11' - e['REQUEST_METHOD'] = "POST" - e['HTTP_COOKIE'] = 'a=1,b=1,c=1;d=1' - e['QUERY_STRING'] = 'a&b&c&d' - old_value = BaseRequest.MAX_PARAMS - r = BaseRequest(e) - try: - BaseRequest.MAX_PARAMS = 2 - self.assertEqual(len(list(r.query.allitems())), 2) - self.assertEqual(len(list(r.cookies.allitems())), 2) - self.assertEqual(len(list(r.forms.allitems())), 2) - self.assertEqual(len(list(r.params.allitems())), 4) - finally: - BaseRequest.MAX_PARAMS = old_value - def test_user_defined_attributes(self): for cls in (BaseRequest, LocalRequest): r = cls() @@ -418,6 +442,40 @@ class TestResponse(unittest.TestCase): + def test_constructor_body(self): + self.assertEqual('', + BaseResponse('').body) + + self.assertEqual('YAY', + BaseResponse('YAY').body) + + def test_constructor_status(self): + self.assertEqual(200, + BaseResponse('YAY', 200).status_code) + + self.assertEqual('200 OK', + BaseResponse('YAY', 200).status_line) + + self.assertEqual('200 YAY', + BaseResponse('YAY', '200 YAY').status_line) + + self.assertEqual('200 YAY', + BaseResponse('YAY', '200 YAY').status_line) + + def test_constructor_headerlist(self): + from functools import partial + make_res = partial(BaseResponse, '', 200) + + self.assertTrue('yay', + make_res([('x-test','yay')])['x-test']) + + def test_constructor_headerlist(self): + from functools import partial + make_res = partial(BaseResponse, '', 200) + + self.assertTrue('yay', make_res(x_test='yay')['x-test']) + + def test_set_status(self): rs = BaseResponse() @@ -580,7 +638,20 @@ response['x-test'] = None self.assertEqual('None', response['x-test']) - + def test_expires_header(self): + import datetime + response = BaseResponse() + now = datetime.datetime.now() + response.expires = now + + def seconds(a, b): + td = max(a,b) - min(a,b) + return td.days*360*24 + td.seconds + + self.assertEqual(0, seconds(response.expires, now)) + now2 = datetime.datetime.utcfromtimestamp( + parse_date(response.headers['Expires'])) + self.assertEqual(0, seconds(now, now2)) class TestRedirect(unittest.TestCase): @@ -592,6 +663,7 @@ del args[key] env.update(args) request.bind(env) + bottle.response.bind() try: bottle.redirect(target, **(query or {})) except bottle.HTTPResponse: @@ -678,6 +750,17 @@ 'http://example.com/a%20a/b%20b/te st.html', HTTP_HOST='example.com', SCRIPT_NAME='/a a/', PATH_INFO='/b b/') + def test_redirect_preserve_cookies(self): + env = {'SERVER_PROTOCOL':'HTTP/1.1'} + request.bind(env) + bottle.response.bind() + try: + bottle.response.set_cookie('xxx', 'yyy') + bottle.redirect('...') + except bottle.HTTPResponse: + h = [v for (k, v) in _e().headerlist if k == 'Set-Cookie'] + self.assertEqual(h, ['xxx=yyy']) + class TestWSGIHeaderDict(unittest.TestCase): def setUp(self): self.env = {} diff -Nru python-bottle-0.11.6/test/test_fileupload.py python-bottle-0.12.0/test/test_fileupload.py --- python-bottle-0.11.6/test/test_fileupload.py 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/test/test_fileupload.py 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +''' Tests for the FileUpload wrapper. ''' + +import unittest +import sys, os.path +import bottle +from bottle import FileUpload, BytesIO +import tempfile + +class TestFileUpload(unittest.TestCase): + def test_name(self): + self.assertEqual(FileUpload(None, 'abc', None).name, 'abc') + + def test_raw_filename(self): + self.assertEqual(FileUpload(None, None, 'x/x').raw_filename, 'x/x') + + def assertFilename(self, bad, good): + fu = FileUpload(None, None, bad) + self.assertEqual(fu.filename, good) + + def test_filename(self): + self.assertFilename('with space', 'with-space') + self.assertFilename('with more \t\n\r space', 'with-more-space') + self.assertFilename('UpperCase', 'uppercase') + self.assertFilename('with/path', 'path') + self.assertFilename('../path', 'path') + self.assertFilename('..\\path', 'path') + self.assertFilename('..', 'empty') + self.assertFilename('.name.', 'name') + self.assertFilename(' . na me . ', 'na-me') + self.assertFilename('path/', 'empty') + self.assertFilename(bottle.tob('ümläüts$'), 'mlts') + self.assertFilename(bottle.touni('ümläüts$'), 'umlauts') + self.assertFilename('', 'empty') + + def test_save_buffer(self): + fu = FileUpload(open(__file__, 'rb'), 'testfile', __file__) + buff = BytesIO() + fu.save(buff) + buff.seek(0) + self.assertEqual(fu.file.read(), buff.read()) + + def test_save_file(self): + fu = FileUpload(open(__file__, 'rb'), 'testfile', __file__) + buff = tempfile.TemporaryFile() + fu.save(buff) + buff.seek(0) + self.assertEqual(fu.file.read(), buff.read()) + + def test_save_overwrite_lock(self): + fu = FileUpload(open(__file__, 'rb'), 'testfile', __file__) + self.assertRaises(IOError, fu.save, __file__) + + def test_save_dir(self): + fu = FileUpload(open(__file__, 'rb'), 'testfile', __file__) + dirpath = tempfile.mkdtemp() + filepath = os.path.join(dirpath, fu.filename) + fu.save(dirpath) + self.assertEqual(fu.file.read(), open(filepath, 'rb').read()) + os.unlink(filepath) + os.rmdir(dirpath) + diff -Nru python-bottle-0.11.6/test/test_mount.py python-bottle-0.12.0/test/test_mount.py --- python-bottle-0.11.6/test/test_mount.py 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/test/test_mount.py 2013-12-03 17:16:12.000000000 +0000 @@ -1,6 +1,6 @@ import bottle from tools import ServerTestBase -from bottle import Bottle, response +from bottle import response class TestAppMounting(ServerTestBase): def setUp(self): @@ -23,10 +23,10 @@ def test_mount_meta(self): self.app.mount('/test/', self.subapp) self.assertEqual( - self.app.routes[0].config.mountpoint['prefix'], + self.app.routes[0].config['mountpoint.prefix'], '/test/') self.assertEqual( - self.app.routes[0].config.mountpoint['target'], + self.app.routes[0].config['mountpoint.target'], self.subapp) def test_no_slash_prefix(self): diff -Nru python-bottle-0.11.6/test/test_outputfilter.py python-bottle-0.12.0/test/test_outputfilter.py --- python-bottle-0.11.6/test/test_outputfilter.py 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/test/test_outputfilter.py 2013-12-03 17:16:12.000000000 +0000 @@ -87,6 +87,23 @@ except ImportError: warn("Skipping JSON tests.") + def test_json_HTTPResponse(self): + self.app.route('/')(lambda: bottle.HTTPResponse({'a': 1}, 500)) + try: + self.assertBody(bottle.json_dumps({'a': 1})) + self.assertHeader('Content-Type','application/json') + except ImportError: + warn("Skipping JSON tests.") + + def test_json_HTTPError(self): + self.app.error(400)(lambda e: e.body) + self.app.route('/')(lambda: bottle.HTTPError(400, {'a': 1})) + try: + self.assertBody(bottle.json_dumps({'a': 1})) + self.assertHeader('Content-Type','application/json') + except ImportError: + warn("Skipping JSON tests.") + def test_generator_callback(self): @self.app.route('/') def test(): @@ -145,6 +162,23 @@ self.assertStatus(500) self.assertInBody('Unsupported response type') + def test_iterator_with_close(self): + class MyIter(object): + def __init__(self, data): + self.data = data + self.closed = False + def close(self): self.closed = True + def __iter__(self): return iter(self.data) + + byte_iter = MyIter([tob('abc'), tob('def')]) + unicode_iter = MyIter([touni('abc'), touni('def')]) + + for test_iter in (byte_iter, unicode_iter): + @self.app.route('/') + def test(): return test_iter + self.assertInBody('abcdef') + self.assertTrue(byte_iter.closed) + def test_cookie(self): """ WSGI: Cookies """ @bottle.route('/cookie') diff -Nru python-bottle-0.11.6/test/test_plugins.py python-bottle-0.12.0/test/test_plugins.py --- python-bottle-0.11.6/test/test_plugins.py 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/test/test_plugins.py 2013-12-03 17:16:12.000000000 +0000 @@ -1,10 +1,9 @@ # -*- coding: utf-8 -*- import unittest -import bottle import tools -class MyTestPlugin(object): +class MyPlugin(object): def __init__(self): self.app = None self.add_args = {} @@ -21,7 +20,7 @@ return wrapper -def my_test_decorator(func): +def my_decorator(func): def wrapper(*a, **ka): return list(func(*a, **ka))[-1] @@ -36,49 +35,49 @@ self.assertTrue(plugin in self.app.plugins) def test_install_plugin(self): - plugin = MyTestPlugin() + plugin = MyPlugin() installed = self.app.install(plugin) self.assertEqual(plugin, installed) self.assertTrue(plugin in self.app.plugins) def test_install_decorator(self): - installed = self.app.install(my_test_decorator) - self.assertEqual(my_test_decorator, installed) - self.assertTrue(my_test_decorator in self.app.plugins) + installed = self.app.install(my_decorator) + self.assertEqual(my_decorator, installed) + self.assertTrue(my_decorator in self.app.plugins) def test_install_non_plugin(self): self.assertRaises(TypeError, self.app.install, 'I am not a plugin') def test_uninstall_by_instance(self): - plugin = self.app.install(MyTestPlugin()) - plugin2 = self.app.install(MyTestPlugin()) + plugin = self.app.install(MyPlugin()) + plugin2 = self.app.install(MyPlugin()) self.app.uninstall(plugin) self.assertTrue(plugin not in self.app.plugins) self.assertTrue(plugin2 in self.app.plugins) def test_uninstall_by_type(self): - plugin = self.app.install(MyTestPlugin()) - plugin2 = self.app.install(MyTestPlugin()) - self.app.uninstall(MyTestPlugin) + plugin = self.app.install(MyPlugin()) + plugin2 = self.app.install(MyPlugin()) + self.app.uninstall(MyPlugin) self.assertTrue(plugin not in self.app.plugins) self.assertTrue(plugin2 not in self.app.plugins) def test_uninstall_by_name(self): - plugin = self.app.install(MyTestPlugin()) - plugin2 = self.app.install(MyTestPlugin()) + plugin = self.app.install(MyPlugin()) + plugin2 = self.app.install(MyPlugin()) plugin.name = 'myplugin' self.app.uninstall('myplugin') self.assertTrue(plugin not in self.app.plugins) self.assertTrue(plugin2 in self.app.plugins) def test_uninstall_all(self): - plugin = self.app.install(MyTestPlugin()) - plugin2 = self.app.install(MyTestPlugin()) + plugin = self.app.install(MyPlugin()) + plugin2 = self.app.install(MyPlugin()) self.app.uninstall(True) self.assertFalse(self.app.plugins) def test_route_plugin(self): - plugin = MyTestPlugin() + plugin = MyPlugin() plugin.add_content = ';foo' @self.app.route('/a') @self.app.route('/b', apply=[plugin]) @@ -87,11 +86,11 @@ self.assertBody('plugin;foo', '/b') def test_plugin_oder(self): - self.app.install(MyTestPlugin()).add_content = ';global-1' - self.app.install(MyTestPlugin()).add_content = ';global-2' - l1 = MyTestPlugin() + self.app.install(MyPlugin()).add_content = ';global-1' + self.app.install(MyPlugin()).add_content = ';global-2' + l1 = MyPlugin() l1.add_content = ';local-1' - l2 = MyTestPlugin() + l2 = MyPlugin() l2.add_content = ';local-2' @self.app.route('/a') @self.app.route('/b', apply=[l1, l2]) @@ -100,13 +99,13 @@ self.assertBody('plugin;local-2;local-1;global-2;global-1', '/b') def test_skip_by_instance(self): - g1 = self.app.install(MyTestPlugin()) + g1 = self.app.install(MyPlugin()) g1.add_content = ';global-1' - g2 = self.app.install(MyTestPlugin()) + g2 = self.app.install(MyPlugin()) g2.add_content = ';global-2' - l1 = MyTestPlugin() + l1 = MyPlugin() l1.add_content = ';local-1' - l2 = MyTestPlugin() + l2 = MyPlugin() l2.add_content = ';local-2' @self.app.route('/a', skip=[g2, l2]) @self.app.route('/b', apply=[l1, l2], skip=[g2, l2]) @@ -115,16 +114,16 @@ self.assertBody('plugin;local-1;global-1', '/b') def test_skip_by_class(self): - g1 = self.app.install(MyTestPlugin()) + g1 = self.app.install(MyPlugin()) g1.add_content = ';global-1' @self.app.route('/a') - @self.app.route('/b', skip=[MyTestPlugin]) + @self.app.route('/b', skip=[MyPlugin]) def a(): return 'plugin' self.assertBody('plugin;global-1', '/a') self.assertBody('plugin', '/b') def test_skip_by_name(self): - g1 = self.app.install(MyTestPlugin()) + g1 = self.app.install(MyPlugin()) g1.add_content = ';global-1' g1.name = 'test' @self.app.route('/a') @@ -134,7 +133,7 @@ self.assertBody('plugin', '/b') def test_skip_all(self): - g1 = self.app.install(MyTestPlugin()) + g1 = self.app.install(MyPlugin()) g1.add_content = ';global-1' @self.app.route('/a') @self.app.route('/b', skip=[True]) @@ -143,7 +142,7 @@ self.assertBody('plugin', '/b') def test_skip_nonlist(self): - g1 = self.app.install(MyTestPlugin()) + g1 = self.app.install(MyPlugin()) g1.add_content = ';global-1' @self.app.route('/a') @self.app.route('/b', skip=g1) diff -Nru python-bottle-0.11.6/test/test_resources.py python-bottle-0.12.0/test/test_resources.py --- python-bottle-0.11.6/test/test_resources.py 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/test/test_resources.py 2013-12-03 17:16:12.000000000 +0000 @@ -1,10 +1,8 @@ -import bottle -from tools import ServerTestBase from bottle import ResourceManager import os.path import unittest -class TestResouceManager(unittest.TestCase): +class TestResourceManager(unittest.TestCase): def test_path_normalize(self): tests = ('/foo/bar/', '/foo/bar/baz', '/foo/baz/../bar/blub') @@ -74,7 +72,7 @@ def test_open(self): rm = ResourceManager() rm.add_path(__file__) - fp = rm.open(os.path.basename(__file__)) + fp = rm.open(__file__) self.assertEqual(fp.read(), open(__file__).read()) diff -Nru python-bottle-0.11.6/test/test_route.py python-bottle-0.12.0/test/test_route.py --- python-bottle-0.11.6/test/test_route.py 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/test/test_route.py 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1,30 @@ +import unittest +import bottle +from tools import api + + +class TestRoute(unittest.TestCase): + + @api('0.12') + def test_callback_inspection(self): + def x(a, b): pass + def d(f): + def w(): + return f() + return w + + route = bottle.Route(None, None, None, d(x)) + self.assertEqual(route.get_undecorated_callback(), x) + self.assertEqual(set(route.get_callback_args()), set(['a', 'b'])) + + def d2(foo): + def d(f): + def w(): + return f() + return w + return d + + route = bottle.Route(None, None, None, d2('foo')(x)) + self.assertEqual(route.get_undecorated_callback(), x) + self.assertEqual(set(route.get_callback_args()), set(['a', 'b'])) + diff -Nru python-bottle-0.11.6/test/test_router.py python-bottle-0.12.0/test/test_router.py --- python-bottle-0.11.6/test/test_router.py 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/test/test_router.py 2013-12-03 17:16:12.000000000 +0000 @@ -1,8 +1,9 @@ import unittest import bottle + class TestRouter(unittest.TestCase): - CGI=False + CGI = False def setUp(self): self.r = bottle.Router() @@ -82,6 +83,7 @@ def testErrorInPattern(self): self.assertRaises(Exception, self.assertMatches, '/:bug#(#/', '/foo/') + self.assertRaises(Exception, self.assertMatches, '/<:re:(>/', '/foo/') def testBuild(self): add, build = self.add, self.r.build @@ -119,15 +121,38 @@ # RouteBuildError: Missing URL argument: anon0. self.assertRaises(ValueError, build, 'introute', 'hello') - def test_method(self): - #TODO Test method handling. This is done in the router now. - pass - + def test_dynamic_before_static_any(self): + ''' Static ANY routes have lower priority than dynamic GET routes. ''' + self.add('/foo', 'foo', 'ANY') + self.assertEqual(self.match('/foo')[0], 'foo') + self.add('/<:>', 'bar', 'GET') + self.assertEqual(self.match('/foo')[0], 'bar') + + def test_any_static_before_dynamic(self): + ''' Static ANY routes have higher priority than dynamic ANY routes. ''' + self.add('/<:>', 'bar', 'ANY') + self.assertEqual(self.match('/foo')[0], 'bar') + self.add('/foo', 'foo', 'ANY') + self.assertEqual(self.match('/foo')[0], 'foo') + + def test_dynamic_any_if_method_exists(self): + ''' Check dynamic ANY routes if the matching method is known, + but not matched.''' + self.add('/bar<:>', 'bar', 'GET') + self.assertEqual(self.match('/barx')[0], 'bar') + self.add('/foo<:>', 'foo', 'ANY') + self.assertEqual(self.match('/foox')[0], 'foo') + + def test_lots_of_routes(self): + n = bottle.Router._MAX_GROUPS_PER_PATTERN+10 + for i in range(n): + self.add('/<:>/'+str(i), str(i), 'GET') + self.assertEqual(self.match('/foo/'+str(n-1))[0], str(n-1)) class TestRouterInCGIMode(TestRouter): ''' Makes no sense since the default route does not optimize CGI anymore.''' CGI = True -if __name__ == '__main__': #pragma: no cover +if __name__ == '__main__': # pragma: no cover unittest.main() diff -Nru python-bottle-0.11.6/test/test_securecookies.py python-bottle-0.12.0/test/test_securecookies.py --- python-bottle-0.11.6/test/test_securecookies.py 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/test/test_securecookies.py 2013-12-03 17:16:12.000000000 +0000 @@ -1,5 +1,6 @@ #coding: utf-8 import unittest + import bottle from bottle import tob, touni diff -Nru python-bottle-0.11.6/test/test_sendfile.py python-bottle-0.12.0/test/test_sendfile.py --- python-bottle-0.11.6/test/test_sendfile.py 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/test/test_sendfile.py 2013-12-03 17:16:12.000000000 +0000 @@ -1,8 +1,7 @@ import unittest -from bottle import static_file, HTTPError, HTTPResponse, request, response, parse_date, parse_range_header, Bottle, tob +from bottle import static_file, request, response, parse_date, parse_range_header, Bottle, tob import wsgiref.util import os -import os.path import tempfile import time @@ -59,9 +58,13 @@ def test_mime(self): """ SendFile: Mime Guessing""" f = static_file(os.path.basename(__file__), root='./') - self.assertTrue(f.headers['Content-Type'] in ('application/x-python-code', 'text/x-python')) + self.assertTrue(f.headers['Content-Type'].split(';')[0] in ('application/x-python-code', 'text/x-python')) f = static_file(os.path.basename(__file__), root='./', mimetype='some/type') self.assertEqual('some/type', f.headers['Content-Type']) + f = static_file(os.path.basename(__file__), root='./', mimetype='text/foo') + self.assertEqual('text/foo; charset=UTF-8', f.headers['Content-Type']) + f = static_file(os.path.basename(__file__), root='./', mimetype='text/foo', charset='latin1') + self.assertEqual('text/foo; charset=latin1', f.headers['Content-Type']) def test_ims(self): """ SendFile: If-Modified-Since""" diff -Nru python-bottle-0.11.6/test/test_server.py python-bottle-0.12.0/test/test_server.py --- python-bottle-0.11.6/test/test_server.py 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/test/test_server.py 2013-12-03 17:16:12.000000000 +0000 @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- import unittest -import bottle import time from tools import tob import sys @@ -57,6 +56,7 @@ return if rv is 3: # Port in use continue + raise AssertionError("Server exited with error code %d" % rv) raise AssertionError("Could not find a free port to test server.") def tearDown(self): @@ -119,7 +119,7 @@ class TestFapwsServer(TestServer): server = 'fapws3' -class TestFapwsServer(TestServer): +class MeinheldServer(TestServer): server = 'meinheld' class TestBjoernServer(TestServer): diff -Nru python-bottle-0.11.6/test/test_stpl.py python-bottle-0.12.0/test/test_stpl.py --- python-bottle-0.11.6/test/test_stpl.py 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/test/test_stpl.py 2013-12-03 17:16:12.000000000 +0000 @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- import unittest from bottle import SimpleTemplate, TemplateError, view, template, touni, tob +import re +import traceback class TestSimpleTemplate(unittest.TestCase): def assertRenders(self, tpl, to, *args, **vars): @@ -11,7 +13,7 @@ def test_string(self): """ Templates: Parse string""" self.assertRenders('start {{var}} end', 'start var end', var='var') - + def test_self_as_variable_name(self): self.assertRenders('start {{self}} end', 'start var end', {'self':'var'}) @@ -93,10 +95,10 @@ def test_dedentbug(self): ''' One-Line dednet blocks should not change indention ''' - t = '%if x: a="if"\n%else: a="else"\n{{a}}' + t = '%if x: a="if"\n%else: a="else"\n%end\n{{a}}' self.assertRenders(t, "if", x=True) self.assertRenders(t, "else", x=False) - t = '%if x:\n%a="if"\n%else: a="else"\n{{a}}' + t = '%if x:\n%a="if"\n%else: a="else"\n%end\n{{a}}' self.assertRenders(t, "if", x=True) self.assertRenders(t, "else", x=False) t = SimpleTemplate('%if x: a="if"\n%else: a="else"\n%end') @@ -106,7 +108,7 @@ ''' One-Line blocks should not change indention ''' t = '%if x:\n%a=1\n%end\n{{a}}' self.assertRenders(t, "1", x=True) - t = '%if x: a=1\n{{a}}' + t = '%if x: a=1; end\n{{a}}' self.assertRenders(t, "1", x=True) t = '%if x:\n%a=1\n%else:\n%a=2\n%end\n{{a}}' self.assertRenders(t, "1", x=True) @@ -114,27 +116,29 @@ t = '%if x: a=1\n%else:\n%a=2\n%end\n{{a}}' self.assertRenders(t, "1", x=True) self.assertRenders(t, "2", x=False) - t = '%if x:\n%a=1\n%else: a=2\n{{a}}' + t = '%if x:\n%a=1\n%else: a=2; end\n{{a}}' self.assertRenders(t, "1", x=True) self.assertRenders(t, "2", x=False) - t = '%if x: a=1\n%else: a=2\n{{a}}' + t = '%if x: a=1\n%else: a=2; end\n{{a}}' self.assertRenders(t, "1", x=True) self.assertRenders(t, "2", x=False) def test_onelineblocks(self): """ Templates: one line code blocks """ - t = "start\n%a=''\n%for i in l: a += str(i)\n{{a}}\nend" + t = "start\n%a=''\n%for i in l: a += str(i); end\n{{a}}\nend" self.assertRenders(t, 'start\n123\nend', l=[1,2,3]) self.assertRenders(t, 'start\n\nend', l=[]) def test_escaped_codelines(self): self.assertRenders('%% test', '% test') self.assertRenders('%%% test', '%% test') + self.assertRenders('\\% test', '% test') + self.assertRenders('\\%% test', '%% test') def test_nobreak(self): """ Templates: Nobreak statements""" self.assertRenders("start\\\\\n%pass\nend", 'startend') - + def test_nonobreak(self): """ Templates: Escaped nobreak statements""" self.assertRenders("start\\\\\n\\\\\n%pass\nend", 'start\\\\\nend') @@ -171,20 +175,27 @@ """ Templates: Exceptions""" self.assertRaises(SyntaxError, lambda: SimpleTemplate('%for badsyntax').co) self.assertRaises(IndexError, SimpleTemplate('{{i[5]}}').render, i=[0]) - + def test_winbreaks(self): """ Templates: Test windows line breaks """ self.assertRenders('%var+=1\r\n{{var}}\r\n', '6\r\n', var=5) + def test_winbreaks_end_bug(self): + d = { 'test': [ 1, 2, 3 ] } + self.assertRenders('%for i in test:\n{{i}}\n%end\n', '1\n2\n3\n', **d) + self.assertRenders('%for i in test:\n{{i}}\r\n%end\n', '1\r\n2\r\n3\r\n', **d) + self.assertRenders('%for i in test:\r\n{{i}}\n%end\r\n', '1\n2\n3\n', **d) + self.assertRenders('%for i in test:\r\n{{i}}\r\n%end\r\n', '1\r\n2\r\n3\r\n', **d) + def test_commentonly(self): """ Templates: Commentd should behave like code-lines (e.g. flush text-lines) """ t = SimpleTemplate('...\n%#test\n...') - self.failIfEqual('#test', t.code.splitlines()[0]) + self.assertNotEqual('#test', t.code.splitlines()[0]) def test_detect_pep263(self): ''' PEP263 strings in code-lines change the template encoding on the fly ''' t = SimpleTemplate(touni('%#coding: iso8859_15\nöäü?@€').encode('utf8')) - self.failIfEqual(touni('öäü?@€'), t.render()) + self.assertNotEqual(touni('öäü?@€'), t.render()) self.assertEqual(t.encoding, 'iso8859_15') t = SimpleTemplate(touni('%#coding: iso8859_15\nöäü?@€').encode('iso8859_15')) self.assertEqual(touni('öäü?@€'), t.render()) @@ -193,14 +204,12 @@ def test_ignore_pep263_in_textline(self): ''' PEP263 strings in text-lines have no effect ''' - self.assertRaises(UnicodeError, lambda: SimpleTemplate(touni('#coding: iso8859_15\nöäü?@€').encode('iso8859_15')).co) t = SimpleTemplate(touni('#coding: iso8859_15\nöäü?@€').encode('utf8')) self.assertEqual(touni('#coding: iso8859_15\nöäü?@€'), t.render()) self.assertEqual(t.encoding, 'utf8') def test_ignore_late_pep263(self): ''' PEP263 strings must appear within the first two lines ''' - self.assertRaises(UnicodeError, lambda: SimpleTemplate(touni('\n\n%#coding: iso8859_15\nöäü?@€').encode('iso8859_15')).co) t = SimpleTemplate(touni('\n\n%#coding: iso8859_15\nöäü?@€').encode('utf8')) self.assertEqual(touni('\n\nöäü?@€'), t.render()) self.assertEqual(t.encoding, 'utf8') @@ -220,11 +229,143 @@ return dict(var='middle') self.assertEqual(touni('start middle end'), test()) + def test_view_decorator_issue_407(self): + @view('stpl_no_vars') + def test(): + pass + self.assertEqual(touni('hihi'), test()) + @view('aaa {{x}}', x='bbb') + def test2(): + pass + self.assertEqual(touni('aaa bbb'), test2()) + def test_global_config(self): SimpleTemplate.global_config('meh', 1) t = SimpleTemplate('anything') self.assertEqual(touni('anything'), t.render()) + def test_bug_no_whitespace_before_stmt(self): + self.assertRenders('\n{{var}}', '\nx', var='x') + + +class TestSTPLDir(unittest.TestCase): + def fix_ident(self, string): + lines = string.splitlines(True) + if not lines: return string + if not lines[0].strip(): lines.pop(0) + whitespace = re.match('([ \t]*)', lines[0]).group(0) + if not whitespace: return string + for i in range(len(lines)): + lines[i] = lines[i][len(whitespace):] + return lines[0][:0].join(lines) + + def assertRenders(self, source, result, syntax=None, *args, **vars): + source = self.fix_ident(source) + result = self.fix_ident(result) + tpl = SimpleTemplate(source, syntax=syntax) + try: + tpl.co + self.assertEqual(touni(result), tpl.render(*args, **vars)) + except SyntaxError: + self.fail('Syntax error in template:\n%s\n\nTemplate code:\n##########\n%s\n##########' % + (traceback.format_exc(), tpl.code)) + + def test_old_include(self): + t1 = SimpleTemplate('%include foo') + t1.cache['foo'] = SimpleTemplate('foo') + self.assertEqual(t1.render(), 'foo') + + def test_old_include_with_args(self): + t1 = SimpleTemplate('%include foo x=y') + t1.cache['foo'] = SimpleTemplate('foo{{x}}') + self.assertEqual(t1.render(y='bar'), 'foobar') + + def test_defect_coding(self): + t1 = SimpleTemplate('%#coding comment\nfoo{{y}}') + self.assertEqual(t1.render(y='bar'), 'foobar') + + def test_multiline_block(self): + source = ''' + <% a = 5 + b = 6 + c = 7 %> + {{a+b+c}} + '''; result = ''' + 18 + ''' + self.assertRenders(source, result) + + def test_multiline_ignore_eob_in_string(self): + source = ''' + <% x=5 # a comment + y = '%>' # a string + # this is still code + # lets end this %> + {{x}}{{!y}} + '''; result = ''' + 5%> + ''' + self.assertRenders(source, result) + + def test_multiline_find_eob_in_comments(self): + source = ''' + <% # a comment + # %> ignore because not end of line + # this is still code + x=5 + # lets end this here %> + {{x}} + '''; result = ''' + 5 + ''' + self.assertRenders(source, result) + + def test_multiline_indention(self): + source = ''' + <% if True: + a = 2 + else: + a = 0 + end + %> + {{a}} + '''; result = ''' + 2 + ''' + self.assertRenders(source, result) + + def test_multiline_eob_after_end(self): + source = ''' + <% if True: + a = 2 + end %> + {{a}} + '''; result = ''' + 2 + ''' + self.assertRenders(source, result) + + def test_multiline_eob_in_single_line_code(self): + # eob must be a valid python expression to allow this test. + source = ''' + cline eob=5; eob + xxx + '''; result = ''' + xxx + ''' + self.assertRenders(source, result, syntax='sob eob cline foo bar') + + def test_multiline_strings_in_code_line(self): + source = ''' + % a = """line 1 + line 2""" + {{a}} + '''; result = ''' + line 1 + line 2 + ''' + self.assertRenders(source, result) + if __name__ == '__main__': #pragma: no cover unittest.main() diff -Nru python-bottle-0.11.6/test/test_wsgi.py python-bottle-0.12.0/test/test_wsgi.py --- python-bottle-0.11.6/test/test_wsgi.py 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/test/test_wsgi.py 2013-12-03 17:16:12.000000000 +0000 @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- import unittest -import sys, os.path import bottle from tools import ServerTestBase from bottle import tob @@ -39,6 +38,17 @@ self.assertStatus(200, '/get', method='HEAD') self.assertBody('', '/get', method='HEAD') + def test_request_attrs(self): + """ WSGI: POST routes""" + @bottle.route('/') + def test(): + self.assertEqual(bottle.request.app, + bottle.default_app()) + self.assertEqual(bottle.request.route, + bottle.default_app().routes[0]) + return 'foo' + self.assertBody('foo', '/') + def get304(self): """ 304 responses must not return entity headers """ bad = ('allow', 'content-encoding', 'content-language', @@ -78,10 +88,10 @@ self.assertStatus(500, '/') def test_utf8_url(self): - """ WSGI: Exceptions within handler code (HTTP 500) """ - @bottle.route('/my/:string') + """ WSGI: UTF-8 Characters in the URL """ + @bottle.route('/my-öäü/:string') def test(string): return string - self.assertBody(tob('urf8-öäü'), '/my/urf8-öäü') + self.assertBody(tob('urf8-öäü'), '/my-öäü/urf8-öäü') def test_utf8_404(self): self.assertStatus(404, '/not-found/urf8-öäü') @@ -239,7 +249,7 @@ self.assertBody('test 5 6', '/test') def test_template_opts(self): - @bottle.route(template='test {{a}} {{b}}', template_opts={'b': 6}) + @bottle.route(template=('test {{a}} {{b}}', {'b': 6})) def test(): return dict(a=5) self.assertBody('test 5 6', '/test') @@ -315,10 +325,10 @@ def d(x, y=5): pass def e(x=5, y=6): pass self.assertEqual(['/a'],list(bottle.yieldroutes(a))) - self.assertEqual(['/b/:x'],list(bottle.yieldroutes(b))) - self.assertEqual(['/c/:x/:y'],list(bottle.yieldroutes(c))) - self.assertEqual(['/d/:x','/d/:x/:y'],list(bottle.yieldroutes(d))) - self.assertEqual(['/e','/e/:x','/e/:x/:y'],list(bottle.yieldroutes(e))) + self.assertEqual(['/b/'],list(bottle.yieldroutes(b))) + self.assertEqual(['/c//'],list(bottle.yieldroutes(c))) + self.assertEqual(['/d/','/d//'],list(bottle.yieldroutes(d))) + self.assertEqual(['/e','/e/','/e//'],list(bottle.yieldroutes(e))) diff -Nru python-bottle-0.11.6/test/testall.py python-bottle-0.12.0/test/testall.py --- python-bottle-0.11.6/test/testall.py 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/test/testall.py 2013-12-03 17:16:12.000000000 +0000 @@ -1,6 +1,12 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +try: + import coverage + coverage.process_startup() +except ImportError: + pass + import unittest import sys, os, glob @@ -16,43 +22,22 @@ sys.stdout.write('''Command line arguments: fast: Skip server adapter tests. verbose: Print tests even if they pass. - coverage: Measure code coverage. - html: Create a html coverage report. Requires 'coverage' - clean: Delete coverage or temporary files ''') sys.exit(0) - if 'fast' in sys.argv: sys.stderr.write("Warning: The 'fast' keyword skipps server tests.\n") test_names.remove('test_server') -cov = None -if 'coverage' in sys.argv: - import coverage - cov = coverage.coverage(data_suffix=True, branch=True) - cov.start() - suite = unittest.defaultTestLoader.loadTestsFromNames(test_names) def run(): import bottle + bottle.debug(True) vlevel = 2 if 'verbose' in sys.argv else 0 result = unittest.TextTestRunner(verbosity=vlevel).run(suite) - if cov: - cov.stop() - cov.save() - # Recreate coverage object so new files created in other processes are - # recognized - cnew = coverage.coverage(data_suffix=True, branch=True) - cnew.combine() - cnew.report(morfs=['bottle.py']+test_files, show_missing=False) - if 'html' in sys.argv: - print - cnew.html_report(morfs=['bottle.py']+test_files, directory='../build/coverage') - sys.exit((result.errors or result.failures) and 1 or 0) if __name__ == '__main__': diff -Nru python-bottle-0.11.6/test/tools.py python-bottle-0.12.0/test/tools.py --- python-bottle-0.11.6/test/tools.py 2013-02-01 19:21:06.000000000 +0000 +++ python-bottle-0.12.0/test/tools.py 2013-12-03 17:16:12.000000000 +0000 @@ -1,18 +1,15 @@ # -*- coding: utf-8 -*- import bottle -import threading import sys -import time import unittest import wsgiref -import wsgiref.simple_server import wsgiref.util import wsgiref.validate import mimetypes import uuid -from bottle import tob, BytesIO +from bottle import tob, tonat, BytesIO, py3k def warn(msg): sys.stderr.write('WARNING: %s\n' % msg.strip()) @@ -21,6 +18,32 @@ ''' Transforms bytes or unicode into a byte stream. ''' return BytesIO(tob(data)) +def api(introduced, deprecated=None, removed=None): + current = tuple(map(int, bottle.__version__.split('-')[0].split('.'))) + introduced = tuple(map(int, introduced.split('.'))) + deprecated = tuple(map(int, deprecated.split('.'))) if deprecated else (99,99) + removed = tuple(map(int, removed.split('.'))) if removed else (99,100) + assert introduced < deprecated < removed + + def decorator(func): + if current < introduced: + return None + elif current < deprecated: + return func + elif current < removed: + func.__doc__ = '(deprecated) ' + (func.__doc__ or '') + return func + else: + return None + return decorator + + +def wsgistr(s): + if py3k: + return s.encode('utf8').decode('latin1') + else: + return s + class ServerTestBase(unittest.TestCase): def setUp(self): ''' Create a new Bottle app set it as default_app ''' @@ -42,9 +65,9 @@ result['header'][name] = value env = env if env else {} wsgiref.util.setup_testing_defaults(env) - env['REQUEST_METHOD'] = method.upper().strip() - env['PATH_INFO'] = path - env['QUERY_STRING'] = '' + env['REQUEST_METHOD'] = wsgistr(method.upper().strip()) + env['PATH_INFO'] = wsgistr(path) + env['QUERY_STRING'] = wsgistr('') if post: env['REQUEST_METHOD'] = 'POST' env['CONTENT_LENGTH'] = str(len(tob(post))) diff -Nru python-bottle-0.11.6/test/views/stpl_no_vars.tpl python-bottle-0.12.0/test/views/stpl_no_vars.tpl --- python-bottle-0.11.6/test/views/stpl_no_vars.tpl 1970-01-01 00:00:00.000000000 +0000 +++ python-bottle-0.12.0/test/views/stpl_no_vars.tpl 2013-12-03 17:16:12.000000000 +0000 @@ -0,0 +1 @@ +hihi \ No newline at end of file