sgn.bottle
¶
Bottle is a fast and simple micro-framework for small web applications. It offers request dispatching (Routes) with URL parameter support, templates, a built-in HTTP Server and adapters for many third party WSGI/HTTP-server and template engines - all in a single file and with no dependencies other than the Python Standard Library.
Homepage and documentation: http://bottlepy.org/
Copyright (c) 2009-2024, Marcel Hellkamp. License: MIT (see LICENSE for details)
AiohttpServer
¶
Bases: AsyncioServerAdapter
flowchart TD
sgn.bottle.AiohttpServer[AiohttpServer]
sgn.bottle.AsyncioServerAdapter[AsyncioServerAdapter]
sgn.bottle.ServerAdapter[ServerAdapter]
sgn.bottle.AsyncioServerAdapter --> sgn.bottle.AiohttpServer
sgn.bottle.ServerAdapter --> sgn.bottle.AsyncioServerAdapter
click sgn.bottle.AiohttpServer href "" "sgn.bottle.AiohttpServer"
click sgn.bottle.AsyncioServerAdapter href "" "sgn.bottle.AsyncioServerAdapter"
click sgn.bottle.ServerAdapter href "" "sgn.bottle.ServerAdapter"
Asynchronous HTTP client/server framework for asyncio https://pypi.python.org/pypi/aiohttp/ https://pypi.org/project/aiohttp-wsgi/
Source code in src/sgn/bottle.py
AiohttpUVLoopServer
¶
Bases: AiohttpServer
flowchart TD
sgn.bottle.AiohttpUVLoopServer[AiohttpUVLoopServer]
sgn.bottle.AiohttpServer[AiohttpServer]
sgn.bottle.AsyncioServerAdapter[AsyncioServerAdapter]
sgn.bottle.ServerAdapter[ServerAdapter]
sgn.bottle.AiohttpServer --> sgn.bottle.AiohttpUVLoopServer
sgn.bottle.AsyncioServerAdapter --> sgn.bottle.AiohttpServer
sgn.bottle.ServerAdapter --> sgn.bottle.AsyncioServerAdapter
click sgn.bottle.AiohttpUVLoopServer href "" "sgn.bottle.AiohttpUVLoopServer"
click sgn.bottle.AiohttpServer href "" "sgn.bottle.AiohttpServer"
click sgn.bottle.AsyncioServerAdapter href "" "sgn.bottle.AsyncioServerAdapter"
click sgn.bottle.ServerAdapter href "" "sgn.bottle.ServerAdapter"
uvloop https://github.com/MagicStack/uvloop
Source code in src/sgn/bottle.py
AppEngineServer
¶
Bases: ServerAdapter
flowchart TD
sgn.bottle.AppEngineServer[AppEngineServer]
sgn.bottle.ServerAdapter[ServerAdapter]
sgn.bottle.ServerAdapter --> sgn.bottle.AppEngineServer
click sgn.bottle.AppEngineServer href "" "sgn.bottle.AppEngineServer"
click sgn.bottle.ServerAdapter href "" "sgn.bottle.ServerAdapter"
Adapter for Google App Engine.
Source code in src/sgn/bottle.py
AppStack
¶
Bases: list
flowchart TD
sgn.bottle.AppStack[AppStack]
click sgn.bottle.AppStack href "" "sgn.bottle.AppStack"
A stack-like list. Calling it returns the head of the stack.
Source code in src/sgn/bottle.py
__call__()
¶
AsyncioServerAdapter
¶
Bases: ServerAdapter
flowchart TD
sgn.bottle.AsyncioServerAdapter[AsyncioServerAdapter]
sgn.bottle.ServerAdapter[ServerAdapter]
sgn.bottle.ServerAdapter --> sgn.bottle.AsyncioServerAdapter
click sgn.bottle.AsyncioServerAdapter href "" "sgn.bottle.AsyncioServerAdapter"
click sgn.bottle.ServerAdapter href "" "sgn.bottle.ServerAdapter"
Extend ServerAdapter for adding custom event loop
Source code in src/sgn/bottle.py
AutoServer
¶
Bases: ServerAdapter
flowchart TD
sgn.bottle.AutoServer[AutoServer]
sgn.bottle.ServerAdapter[ServerAdapter]
sgn.bottle.ServerAdapter --> sgn.bottle.AutoServer
click sgn.bottle.AutoServer href "" "sgn.bottle.AutoServer"
click sgn.bottle.ServerAdapter href "" "sgn.bottle.ServerAdapter"
Untested.
Source code in src/sgn/bottle.py
BaseRequest
¶
Bases: object
flowchart TD
sgn.bottle.BaseRequest[BaseRequest]
click sgn.bottle.BaseRequest href "" "sgn.bottle.BaseRequest"
A wrapper for WSGI environment dictionaries that adds a lot of convenient access methods and properties. Most of them are read-only.
Adding new attributes to a request actually adds them to the environ
dictionary (as 'bottle.request.ext.
Source code in src/sgn/bottle.py
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 | |
auth
property
¶
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.
body
property
¶
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.
chunked
property
¶
True if Chunked transfer encoding was.
content_length
property
¶
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.
content_type
property
¶
The Content-Type header as a lowercase-string (default: empty).
fullpath
property
¶
Request path including :attr:script_name (if present).
is_ajax
property
¶
Alias for :attr:is_xhr. "Ajax" is not the right term.
is_xhr
property
¶
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).
method
property
¶
The REQUEST_METHOD value as an uppercase string.
path
property
¶
The value of PATH_INFO with exactly one prefixed slash (to fix
broken clients and avoid the "empty path" edge case).
query_string
property
¶
The raw :attr:query part of the URL (everything in between ?
and #) as a string.
remote_addr
property
¶
The client IP as a string. Note that this information can be forged by malicious clients.
remote_route
property
¶
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.
script_name
property
¶
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.
url
property
¶
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.
POST()
¶
The values of :attr:forms and :attr:files combined into a single
:class:FormsDict. Values are either strings (form values) or
instances of :class:FileUpload.
Source code in src/sgn/bottle.py
__getattr__(name)
¶
Search in self.environ for additional user defined attributes.
Source code in src/sgn/bottle.py
__init__(environ=None)
¶
Wrap a WSGI environ dictionary.
Source code in src/sgn/bottle.py
__setattr__(name, value)
¶
Define new attributes that are local to the bound request environment.
Source code in src/sgn/bottle.py
__setitem__(key, value)
¶
Change an environ value and clear all caches that depend on it.
Source code in src/sgn/bottle.py
app()
¶
cookies()
¶
Cookies parsed into a :class:FormsDict. Signed cookies are NOT
decoded. Use :meth:get_cookie if you expect signed cookies.
Source code in src/sgn/bottle.py
copy()
¶
files()
¶
File uploads parsed from multipart/form-data encoded POST or PUT
request body. The values are instances of :class:FileUpload.
Source code in src/sgn/bottle.py
forms()
¶
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.
Source code in src/sgn/bottle.py
get_cookie(key, default=None, secret=None, digestmod=hashlib.sha256)
¶
Return the content of a cookie. To read a Signed Cookie, the
secret must match the one used to create the cookie (see
:meth:Response.set_cookie <BaseResponse.set_cookie>). If anything goes wrong (missing
cookie or wrong signature), return a default value.
Source code in src/sgn/bottle.py
get_header(name, default=None)
¶
headers()
¶
A :class:WSGIHeaderDict that provides case-insensitive access to
HTTP request headers.
json()
¶
If the Content-Type header is application/json or
application/json-rpc, this property holds the parsed content
of the request body. Only requests smaller than :attr:MEMFILE_MAX
are processed to avoid memory exhaustion.
Invalid JSON raises a 400 error response.
Source code in src/sgn/bottle.py
params()
¶
A :class:FormsDict with the combined values of :attr:query and
:attr:forms. File uploads are stored in :attr:files.
Source code in src/sgn/bottle.py
path_shift(shift=1)
¶
Shift path segments from :attr:path to :attr:script_name and
vice versa.
:param shift: The number of path segments to shift. May be negative to change the shift direction. (default: 1)
Source code in src/sgn/bottle.py
query()
¶
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.
Source code in src/sgn/bottle.py
route()
¶
The bottle :class:Route object that matches this request.
url_args()
¶
urlparts()
¶
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.
Source code in src/sgn/bottle.py
BaseResponse
¶
Bases: object
flowchart TD
sgn.bottle.BaseResponse[BaseResponse]
click sgn.bottle.BaseResponse href "" "sgn.bottle.BaseResponse"
Storage class for a response body as well as headers and cookies.
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.
Source code in src/sgn/bottle.py
1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 | |
charset
property
¶
Return the charset specified in the content-type header (default: utf8).
headerlist
property
¶
WSGI conform list of (header, value) tuples.
headers
property
¶
An instance of :class:HeaderDict, a case-insensitive dict-like
view on the response headers.
status_code
property
¶
The HTTP status code as an integer (e.g. 404).
status_line
property
¶
The HTTP status line as a string (e.g. 404 Not Found).
__init__(body='', status=None, headers=None, **more_headers)
¶
Create a new response object.
: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.
Source code in src/sgn/bottle.py
add_header(name, value)
¶
copy(cls=None)
¶
Returns a copy of self.
Source code in src/sgn/bottle.py
delete_cookie(key, **kwargs)
¶
Delete a cookie. Be sure to use the same domain and path
settings as used to create the cookie.
get_header(name, default=None)
¶
Return the value of a previously defined header. If there is no header with that name, return a default value.
iter_headers()
¶
Yield (header, value) tuples, skipping headers that are not allowed with the current response status code.
set_cookie(name, value, secret=None, digestmod=hashlib.sha256, **options)
¶
Create a new cookie or replace an old one. If the secret parameter is
set, create a Signed Cookie (described below).
:param name: the name of the cookie. :param value: the value of the cookie. :param secret: a signature key required for signed cookies.
Additionally, this method accepts all RFC 2109 attributes that are
supported by :class:cookie.Morsel, including:
:param maxage: maximum age in seconds. (default: None)
:param expires: a datetime object or UNIX timestamp. (default: None)
:param domain: the domain that is allowed to read the cookie.
(default: current domain)
:param path: limits the cookie to a given path (default: current path)
:param secure: limit the cookie to HTTPS connections (default: off).
:param httponly: prevents client-side javascript to read this cookie
(default: off, requires Python 2.6 or newer).
:param samesite: Control or disable third-party use for this cookie.
Possible values: lax, strict or none (default).
If neither expires nor maxage is set (default), the cookie will
expire at the end of the browser session (as soon as the browser
window is closed).
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.
Warning: Pickle is a potentially dangerous format. If an attacker gains access to the secret key, he could forge cookies that execute code on server side if unpickled. Using pickle is discouraged and support for it will be removed in later versions of bottle.
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.
Source code in src/sgn/bottle.py
1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 | |
set_header(name, value)
¶
Create a new response header, replacing any previously defined headers with the same name.
BaseTemplate
¶
Bases: object
flowchart TD
sgn.bottle.BaseTemplate[BaseTemplate]
click sgn.bottle.BaseTemplate href "" "sgn.bottle.BaseTemplate"
Base class and minimal API for template adapters
Source code in src/sgn/bottle.py
4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 | |
__init__(source=None, name=None, lookup=None, encoding='utf8', **settings)
¶
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.
Source code in src/sgn/bottle.py
global_config(key, *args)
classmethod
¶
This reads or sets the global settings stored in class.settings.
Source code in src/sgn/bottle.py
prepare(**options)
¶
Run preparations (parsing, caching, ...). It should be possible to call this again to refresh a template or to update settings.
render(*args, **kwargs)
¶
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).
Source code in src/sgn/bottle.py
search(name, lookup=None)
classmethod
¶
Search name in all directories specified in lookup. First without, then with common extensions. Return first hit.
Source code in src/sgn/bottle.py
BjoernServer
¶
Bases: ServerAdapter
flowchart TD
sgn.bottle.BjoernServer[BjoernServer]
sgn.bottle.ServerAdapter[ServerAdapter]
sgn.bottle.ServerAdapter --> sgn.bottle.BjoernServer
click sgn.bottle.BjoernServer href "" "sgn.bottle.BjoernServer"
click sgn.bottle.ServerAdapter href "" "sgn.bottle.ServerAdapter"
Fast server written in C: https://github.com/jonashaag/bjoern
Source code in src/sgn/bottle.py
Bottle
¶
Bases: object
flowchart TD
sgn.bottle.Bottle[Bottle]
click sgn.bottle.Bottle href "" "sgn.bottle.Bottle"
Each Bottle object represents a single, distinct web application and consists of routes, callbacks, plugins, resources and configuration. Instances are callable WSGI applications.
:param catchall: If true (default), handle all exceptions. Turn off to let debugging middleware handle exceptions.
Source code in src/sgn/bottle.py
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 | |
__call__(environ, start_response)
¶
__enter__()
¶
add_hook(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.
Source code in src/sgn/bottle.py
add_route(route)
¶
Add a route object, but do not change the :data:Route.app
attribute.
close()
¶
delete(path=None, method='DELETE', **options)
¶
error(code=500, callback=None)
¶
Register an output handler for a HTTP error code. Can be used as a decorator or called directly ::
def error_handler_500(error):
return 'error_handler_500'
app.error(code=500, callback=error_handler_500)
@app.error(404)
def error_handler_404(error):
return 'error_handler_404'
Source code in src/sgn/bottle.py
get(path=None, method='GET', **options)
¶
get_url(routename, **kargs)
¶
Return a string that matches a named route
Source code in src/sgn/bottle.py
hook(name)
¶
Return a decorator that attaches a callback to a hook. See
:meth:add_hook for details.
install(plugin)
¶
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.
Source code in src/sgn/bottle.py
match(environ)
¶
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.
Source code in src/sgn/bottle.py
merge(routes)
¶
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.
Source code in src/sgn/bottle.py
mount(prefix, app, **options)
¶
Mount an application (:class:Bottle or plain WSGI) to a specific
URL prefix. Example::
parent_app.mount('/prefix/', child_app)
:param prefix: path prefix or mount-point.
:param app: an instance of :class:Bottle or a WSGI application.
Plugins from the parent application are not applied to the routes of the mounted child application. If you need plugins in the child application, install them separately.
While it is possible to use path wildcards within the prefix path
(:class:Bottle childs only), it is highly discouraged.
The prefix path must end with a slash. If you want to access the
root of the child application via /prefix in addition to
/prefix/, consider adding a route with a 307 redirect to the
parent application.
Source code in src/sgn/bottle.py
patch(path=None, method='PATCH', **options)
¶
post(path=None, method='POST', **options)
¶
put(path=None, method='PUT', **options)
¶
remove_hook(name, func)
¶
reset(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 is affected.
Source code in src/sgn/bottle.py
route(path=None, method='GET', callback=None, name=None, apply=None, skip=None, **config)
¶
A decorator to bind a function to a request URL. Example::
@app.route('/hello/<name>')
def hello(name):
return 'Hello %s' % name
The <name> part is a wildcard. See :class:Router for syntax
details.
:param path: Request path or a list of paths to listen to. If no
path is specified, it is automatically generated from the
signature of the function.
:param method: HTTP method (GET, POST, PUT, ...) or a list of
methods to listen to. (default: GET)
:param callback: An optional shortcut to avoid the decorator
syntax. route(..., callback=func) equals route(...)(func)
:param name: The name for this route. (default: None)
:param apply: A decorator or plugin or a list of plugins. These are
applied to the route callback in addition to installed plugins.
:param skip: A list of plugins, plugin classes or names. Matching
plugins are not installed to this route. True skips all.
Any additional keyword arguments are stored as route-specific
configuration and passed to plugins (see :meth:Plugin.apply).
Source code in src/sgn/bottle.py
run(**kwargs)
¶
trigger_hook(__name, *args, **kwargs)
¶
uninstall(plugin)
¶
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.
Source code in src/sgn/bottle.py
wsgi(environ, start_response)
¶
The bottle WSGI-interface.
Source code in src/sgn/bottle.py
BottleException
¶
Bases: Exception
flowchart TD
sgn.bottle.BottleException[BottleException]
click sgn.bottle.BottleException href "" "sgn.bottle.BottleException"
A base class for exceptions used by bottle.
ConfigDict
¶
Bases: dict
flowchart TD
sgn.bottle.ConfigDict[ConfigDict]
click sgn.bottle.ConfigDict href "" "sgn.bottle.ConfigDict"
A dict-like configuration storage with additional support for namespaces, validators, meta-data and overlays.
This dict-like class is heavily optimized for read access. Read-only methods and item access should be as fast as a native dict.
Source code in src/sgn/bottle.py
2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 | |
load_config(filename, **options)
¶
Load values from *.ini style config files using configparser.
INI style sections (e.g. [section]) are used as namespace for
all keys within that section. Both section and key names may contain
dots as namespace separators and are converted to lower-case.
The special sections [bottle] and [ROOT] refer to the root
namespace and the [DEFAULT] section defines default values for all
other sections.
:param filename: The path of a config file, or a list of paths.
:param options: All keyword parameters are passed to the underlying
:class:python:configparser.ConfigParser constructor call.
Source code in src/sgn/bottle.py
load_dict(source, namespace='')
¶
Load values from a dictionary structure. Nesting can be used to represent namespaces.
c = ConfigDict() c.load_dict({'some': {'namespace': {'key': 'value'} } }) {'some.namespace.key': 'value'}
Source code in src/sgn/bottle.py
load_module(name, squash=True)
¶
Load values from a Python module.
Import a python module by name and add all upper-case module-level variables to this config dict.
:param name: Module name to import and load.
:param squash: If true (default), nested dicts are assumed to
represent namespaces and flattened (see :meth:load_dict).
Source code in src/sgn/bottle.py
meta_get(key, metafield, default=None)
¶
meta_list(key)
¶
meta_set(key, metafield, value)
¶
Set the meta field for a key to a new value.
Meta-fields are shared between all members of an overlay tree.
update(*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().
c = ConfigDict() c.update('some.namespace', key='value')
Source code in src/sgn/bottle.py
DictProperty
¶
Bases: object
flowchart TD
sgn.bottle.DictProperty[DictProperty]
click sgn.bottle.DictProperty href "" "sgn.bottle.DictProperty"
Property that maps to a key in a local dict-like attribute.
Source code in src/sgn/bottle.py
DieselServer
¶
Bases: ServerAdapter
flowchart TD
sgn.bottle.DieselServer[DieselServer]
sgn.bottle.ServerAdapter[ServerAdapter]
sgn.bottle.ServerAdapter --> sgn.bottle.DieselServer
click sgn.bottle.DieselServer href "" "sgn.bottle.DieselServer"
click sgn.bottle.ServerAdapter href "" "sgn.bottle.ServerAdapter"
Untested.
Source code in src/sgn/bottle.py
EventletServer
¶
Bases: ServerAdapter
flowchart TD
sgn.bottle.EventletServer[EventletServer]
sgn.bottle.ServerAdapter[ServerAdapter]
sgn.bottle.ServerAdapter --> sgn.bottle.EventletServer
click sgn.bottle.EventletServer href "" "sgn.bottle.EventletServer"
click sgn.bottle.ServerAdapter href "" "sgn.bottle.ServerAdapter"
Untested. Options:
backlogadjust the eventlet backlog parameter which is the maximum number of queued connections. Should be at least 1; the maximum value is system-dependent.family: (default is 2) socket family, optional. See socket documentation for available families.
Source code in src/sgn/bottle.py
FapwsServer
¶
Bases: ServerAdapter
flowchart TD
sgn.bottle.FapwsServer[FapwsServer]
sgn.bottle.ServerAdapter[ServerAdapter]
sgn.bottle.ServerAdapter --> sgn.bottle.FapwsServer
click sgn.bottle.FapwsServer href "" "sgn.bottle.FapwsServer"
click sgn.bottle.ServerAdapter href "" "sgn.bottle.ServerAdapter"
Extremely fast webserver using libev. See https://github.com/william-os4y/fapws3
Source code in src/sgn/bottle.py
FileCheckerThread
¶
Bases: Thread
flowchart TD
sgn.bottle.FileCheckerThread[FileCheckerThread]
click sgn.bottle.FileCheckerThread href "" "sgn.bottle.FileCheckerThread"
Interrupt main-thread as soon as a changed module file is detected, the lockfile gets deleted or gets too old.
Source code in src/sgn/bottle.py
FileUpload
¶
Bases: object
flowchart TD
sgn.bottle.FileUpload[FileUpload]
click sgn.bottle.FileUpload href "" "sgn.bottle.FileUpload"
Source code in src/sgn/bottle.py
2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 | |
__init__(fileobj, name, filename, headers=None)
¶
Wrapper for a single file uploaded via multipart/form-data.
Source code in src/sgn/bottle.py
filename()
¶
Name of the file on the client file system, but normalized to ensure file system compatibility. An empty filename is returned as 'empty'.
Only ASCII letters, digits, dashes, underscores and dots are allowed in the final filename. Accents are removed, if possible. Whitespace is replaced by a single dash. Leading or tailing dots or dashes are removed. The filename is limited to 255 characters.
Source code in src/sgn/bottle.py
get_header(name, default=None)
¶
save(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)
Source code in src/sgn/bottle.py
FormsDict
¶
Bases: MultiDict
flowchart TD
sgn.bottle.FormsDict[FormsDict]
sgn.bottle.MultiDict[MultiDict]
sgn.bottle.MultiDict --> sgn.bottle.FormsDict
click sgn.bottle.FormsDict href "" "sgn.bottle.FormsDict"
click sgn.bottle.MultiDict href "" "sgn.bottle.MultiDict"
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.
Source code in src/sgn/bottle.py
decode(encoding=None)
¶
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.
Source code in src/sgn/bottle.py
getunicode(name, default=None, encoding=None)
¶
Return the value as a unicode string, or the default.
GeventServer
¶
Bases: ServerAdapter
flowchart TD
sgn.bottle.GeventServer[GeventServer]
sgn.bottle.ServerAdapter[ServerAdapter]
sgn.bottle.ServerAdapter --> sgn.bottle.GeventServer
click sgn.bottle.GeventServer href "" "sgn.bottle.GeventServer"
click sgn.bottle.ServerAdapter href "" "sgn.bottle.ServerAdapter"
Untested. Options:
- See gevent.wsgi.WSGIServer() documentation for more options.
Source code in src/sgn/bottle.py
GunicornServer
¶
Bases: ServerAdapter
flowchart TD
sgn.bottle.GunicornServer[GunicornServer]
sgn.bottle.ServerAdapter[ServerAdapter]
sgn.bottle.ServerAdapter --> sgn.bottle.GunicornServer
click sgn.bottle.GunicornServer href "" "sgn.bottle.GunicornServer"
click sgn.bottle.ServerAdapter href "" "sgn.bottle.ServerAdapter"
Untested. See http://gunicorn.org/configure.html for options.
Source code in src/sgn/bottle.py
HTTPError
¶
Bases: HTTPResponse
flowchart TD
sgn.bottle.HTTPError[HTTPError]
sgn.bottle.HTTPResponse[HTTPResponse]
sgn.bottle.BottleException[BottleException]
sgn.bottle.HTTPResponse --> sgn.bottle.HTTPError
sgn.bottle.Response --> sgn.bottle.HTTPResponse
sgn.bottle.BottleException --> sgn.bottle.HTTPResponse
click sgn.bottle.HTTPError href "" "sgn.bottle.HTTPError"
click sgn.bottle.HTTPResponse href "" "sgn.bottle.HTTPResponse"
click sgn.bottle.BottleException href "" "sgn.bottle.BottleException"
A subclass of :class:HTTPResponse that triggers error handlers.
Source code in src/sgn/bottle.py
HTTPResponse
¶
Bases: Response, BottleException
flowchart TD
sgn.bottle.HTTPResponse[HTTPResponse]
sgn.bottle.BottleException[BottleException]
sgn.bottle.Response --> sgn.bottle.HTTPResponse
sgn.bottle.BottleException --> sgn.bottle.HTTPResponse
click sgn.bottle.HTTPResponse href "" "sgn.bottle.HTTPResponse"
click sgn.bottle.BottleException href "" "sgn.bottle.BottleException"
A subclass of :class:Response that can be raised or returned from request
handlers to short-curcuit request processing and override changes made to the
global :data:request object. This bypasses error handlers, even if the status
code indicates an error. Return or raise :class:HTTPError to trigger error
handlers.
Source code in src/sgn/bottle.py
apply(other)
¶
Copy the state of this response to a different :class:Response object.
Source code in src/sgn/bottle.py
HeaderDict
¶
Bases: MultiDict
flowchart TD
sgn.bottle.HeaderDict[HeaderDict]
sgn.bottle.MultiDict[MultiDict]
sgn.bottle.MultiDict --> sgn.bottle.HeaderDict
click sgn.bottle.HeaderDict href "" "sgn.bottle.HeaderDict"
click sgn.bottle.MultiDict href "" "sgn.bottle.MultiDict"
A case-insensitive version of :class:MultiDict that defaults to
replace the old value instead of appending it.
Source code in src/sgn/bottle.py
LocalRequest
¶
Bases: BaseRequest
flowchart TD
sgn.bottle.LocalRequest[LocalRequest]
sgn.bottle.BaseRequest[BaseRequest]
sgn.bottle.BaseRequest --> sgn.bottle.LocalRequest
click sgn.bottle.LocalRequest href "" "sgn.bottle.LocalRequest"
click sgn.bottle.BaseRequest href "" "sgn.bottle.BaseRequest"
A thread-local subclass of :class:BaseRequest with a different
set of attributes 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).
Source code in src/sgn/bottle.py
LocalResponse
¶
Bases: BaseResponse
flowchart TD
sgn.bottle.LocalResponse[LocalResponse]
sgn.bottle.BaseResponse[BaseResponse]
sgn.bottle.BaseResponse --> sgn.bottle.LocalResponse
click sgn.bottle.LocalResponse href "" "sgn.bottle.LocalResponse"
click sgn.bottle.BaseResponse href "" "sgn.bottle.BaseResponse"
A thread-local subclass of :class:BaseResponse with a different
set of attributes 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.
Source code in src/sgn/bottle.py
MultiDict
¶
Bases: MutableMapping
flowchart TD
sgn.bottle.MultiDict[MultiDict]
click sgn.bottle.MultiDict href "" "sgn.bottle.MultiDict"
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.
Source code in src/sgn/bottle.py
2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 | |
append(key, value)
¶
get(key, default=None, index=-1, type=None)
¶
Return the most recent value for a key.
:param default: The default value to be returned if the key is not present or the type conversion fails. :param index: An index for the list of available values. :param type: If defined, this callable is used to cast the value into a specific type. Exception are suppressed and result in the default value to be returned.
Source code in src/sgn/bottle.py
getall(key)
¶
ResourceManager
¶
Bases: object
flowchart TD
sgn.bottle.ResourceManager[ResourceManager]
click sgn.bottle.ResourceManager href "" "sgn.bottle.ResourceManager"
This class manages a list of search paths and helps to find and open application-bound resources (files).
:param base: default value for :meth:add_path calls.
:param opener: callable used to open resources.
:param cachemode: controls which lookups are cached. One of 'all',
'found' or 'none'.
Source code in src/sgn/bottle.py
2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 | |
__iter__()
¶
Iterate over all existing files in all registered paths.
Source code in src/sgn/bottle.py
add_path(path, base=None, index=None, create=False)
¶
Add a new path to the list of search paths. Return False if the path does not exist.
:param path: The new search path. Relative paths are turned into
an absolute and normalized form. If the path looks like a file
(not ending in /), the filename is stripped off.
:param base: Path used to absolutize relative search paths.
Defaults to :attr:base which defaults to os.getcwd().
:param index: Position within the list of search paths. Defaults
to last index (appends to the list).
The base parameter makes it easy to reference files installed
along with a python module or package::
res.add_path('./resources/', __file__)
Source code in src/sgn/bottle.py
lookup(name)
¶
Search for a resource and return an absolute file path, or None.
The :attr:path list is searched in order. The first match is
returned. Symlinks are followed. The result is cached to speed up
future lookups.
Source code in src/sgn/bottle.py
open(name, mode='r', *args, **kwargs)
¶
Find a resource and return a file object, or raise IOError.
Source code in src/sgn/bottle.py
Route
¶
Bases: object
flowchart TD
sgn.bottle.Route[Route]
click sgn.bottle.Route href "" "sgn.bottle.Route"
This class wraps a route callback along with route specific metadata and configuration and applies Plugins on demand. It is also responsible for turning an URL path rule into a regular expression usable by the Router.
Source code in src/sgn/bottle.py
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 | |
all_plugins()
¶
Yield all Plugins affecting this route.
Source code in src/sgn/bottle.py
call()
¶
The route callback with all plugins applied. This property is created on demand and then cached to speed up subsequent requests.
get_callback_args()
¶
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.
Source code in src/sgn/bottle.py
get_config(key, default=None)
¶
Lookup a config field and return its value, first checking the route.config, then route.app.config.
Source code in src/sgn/bottle.py
get_undecorated_callback()
¶
Return the callback. If the callback is a decorated function, try to recover the original function.
Source code in src/sgn/bottle.py
prepare()
¶
RouteBuildError
¶
Bases: RouteError
flowchart TD
sgn.bottle.RouteBuildError[RouteBuildError]
sgn.bottle.RouteError[RouteError]
sgn.bottle.BottleException[BottleException]
sgn.bottle.RouteError --> sgn.bottle.RouteBuildError
sgn.bottle.BottleException --> sgn.bottle.RouteError
click sgn.bottle.RouteBuildError href "" "sgn.bottle.RouteBuildError"
click sgn.bottle.RouteError href "" "sgn.bottle.RouteError"
click sgn.bottle.BottleException href "" "sgn.bottle.BottleException"
The route could not be built.
RouteError
¶
Bases: BottleException
flowchart TD
sgn.bottle.RouteError[RouteError]
sgn.bottle.BottleException[BottleException]
sgn.bottle.BottleException --> sgn.bottle.RouteError
click sgn.bottle.RouteError href "" "sgn.bottle.RouteError"
click sgn.bottle.BottleException href "" "sgn.bottle.BottleException"
This is a base class for all routing related exceptions
RouteSyntaxError
¶
Bases: RouteError
flowchart TD
sgn.bottle.RouteSyntaxError[RouteSyntaxError]
sgn.bottle.RouteError[RouteError]
sgn.bottle.BottleException[BottleException]
sgn.bottle.RouteError --> sgn.bottle.RouteSyntaxError
sgn.bottle.BottleException --> sgn.bottle.RouteError
click sgn.bottle.RouteSyntaxError href "" "sgn.bottle.RouteSyntaxError"
click sgn.bottle.RouteError href "" "sgn.bottle.RouteError"
click sgn.bottle.BottleException href "" "sgn.bottle.BottleException"
The route parser found something not supported by this router.
Router
¶
Bases: object
flowchart TD
sgn.bottle.Router[Router]
click sgn.bottle.Router href "" "sgn.bottle.Router"
A Router is an ordered collection of route->target pairs. It is used to efficiently match WSGI requests against a number of routes and return the first target that satisfies the request. The target may be anything, usually a string, ID or callable object. A route consists of a path-rule and a HTTP method.
The path-rule is either a static path (e.g. /contact) or a dynamic
path that contains wildcards (e.g. /wiki/<page>). The wildcard syntax
and details on the matching order are described in docs:routing.
Source code in src/sgn/bottle.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
add(rule, method, target, name=None)
¶
Add a new rule or replace the target for an existing rule.
Source code in src/sgn/bottle.py
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 | |
add_filter(name, func)
¶
Add a filter. The provided function is called with the configuration string as parameter and must return a (regexp, to_python, to_url) tuple. The first element is a string, the last two are callables or None.
Source code in src/sgn/bottle.py
build(_name, *anons, **query)
¶
Build an URL by filling the wildcards in a rule.
Source code in src/sgn/bottle.py
match(environ)
¶
Return a (target, url_args) tuple or raise HTTPError(400/404/405).
Source code in src/sgn/bottle.py
SimpleTemplate
¶
Bases: BaseTemplate
flowchart TD
sgn.bottle.SimpleTemplate[SimpleTemplate]
sgn.bottle.BaseTemplate[BaseTemplate]
sgn.bottle.BaseTemplate --> sgn.bottle.SimpleTemplate
click sgn.bottle.SimpleTemplate href "" "sgn.bottle.SimpleTemplate"
click sgn.bottle.BaseTemplate href "" "sgn.bottle.BaseTemplate"
Source code in src/sgn/bottle.py
4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 | |
render(*args, **kwargs)
¶
Render the template using keyword arguments as local variables.
Source code in src/sgn/bottle.py
StplParser
¶
Bases: object
flowchart TD
sgn.bottle.StplParser[StplParser]
click sgn.bottle.StplParser href "" "sgn.bottle.StplParser"
Parser for stpl templates.
Source code in src/sgn/bottle.py
4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 | |
TemplatePlugin
¶
Bases: object
flowchart TD
sgn.bottle.TemplatePlugin[TemplatePlugin]
click sgn.bottle.TemplatePlugin href "" "sgn.bottle.TemplatePlugin"
This plugin applies the :func:view decorator to all routes with a
template config parameter. If the parameter is a tuple, the second
element must be a dict with additional options (e.g. template_engine)
or default variables for the template.
Source code in src/sgn/bottle.py
TornadoServer
¶
Bases: ServerAdapter
flowchart TD
sgn.bottle.TornadoServer[TornadoServer]
sgn.bottle.ServerAdapter[ServerAdapter]
sgn.bottle.ServerAdapter --> sgn.bottle.TornadoServer
click sgn.bottle.TornadoServer href "" "sgn.bottle.TornadoServer"
click sgn.bottle.ServerAdapter href "" "sgn.bottle.ServerAdapter"
The super hyped asynchronous server by facebook. Untested.
Source code in src/sgn/bottle.py
TwistedServer
¶
Bases: ServerAdapter
flowchart TD
sgn.bottle.TwistedServer[TwistedServer]
sgn.bottle.ServerAdapter[ServerAdapter]
sgn.bottle.ServerAdapter --> sgn.bottle.TwistedServer
click sgn.bottle.TwistedServer href "" "sgn.bottle.TwistedServer"
click sgn.bottle.ServerAdapter href "" "sgn.bottle.ServerAdapter"
Untested.
Source code in src/sgn/bottle.py
WSGIHeaderDict
¶
Bases: MutableMapping
flowchart TD
sgn.bottle.WSGIHeaderDict[WSGIHeaderDict]
click sgn.bottle.WSGIHeaderDict href "" "sgn.bottle.WSGIHeaderDict"
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.
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.)
Source code in src/sgn/bottle.py
cached_property
¶
Bases: object
flowchart TD
sgn.bottle.cached_property[cached_property]
click sgn.bottle.cached_property href "" "sgn.bottle.cached_property"
A property that is only computed once per instance and then replaces itself with an ordinary attribute. Deleting the attribute resets the property.
Source code in src/sgn/bottle.py
lazy_attribute
¶
Bases: object
flowchart TD
sgn.bottle.lazy_attribute[lazy_attribute]
click sgn.bottle.lazy_attribute href "" "sgn.bottle.lazy_attribute"
A property that caches itself to the class object.
Source code in src/sgn/bottle.py
abort(code=500, text='Unknown Error.')
¶
auth_basic(check, realm='private', text='Access denied')
¶
Callback decorator to require HTTP auth (basic). TODO: Add route(check_auth=...) parameter.
Source code in src/sgn/bottle.py
cookie_decode(data, key, digestmod=None)
¶
Verify and decode an encoded string. Return an object or None.
Source code in src/sgn/bottle.py
cookie_encode(data, key, digestmod=None)
¶
Encode and sign a pickle-able object. Return a (byte) string
Source code in src/sgn/bottle.py
cookie_is_encoded(data)
¶
Return True if the argument looks like a encoded cookie.
Source code in src/sgn/bottle.py
debug(mode=True)
¶
Change the debug level. There is only one debug level supported at the moment.
html_escape(string)
¶
Escape HTML special characters &<> and quotes '".
html_quote(string)
¶
Escape and quote a string to be used as an HTTP attribute.
load(target, **namespace)
¶
Import a module or fetch an object from a module.
package.modulereturnsmoduleas a module object.pack.mod:namereturns the module variablenamefrompack.mod.pack.mod:func()callspack.mod.func()and returns the result.
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]')
Source code in src/sgn/bottle.py
load_app(target)
¶
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.
Source code in src/sgn/bottle.py
make_default_app_wrapper(name)
¶
Return a callable that relays calls to the current default app.
parse_auth(header)
¶
Parse rfc2617 HTTP authentication header string (basic) and return (user,pass) tuple or None
Source code in src/sgn/bottle.py
parse_date(ims)
¶
Parse rfc1123, rfc850 and asctime timestamps and return UTC epoch.
Source code in src/sgn/bottle.py
parse_range_header(header, maxlen=0)
¶
Yield (start, end) ranges parsed from a HTTP Range header. Skip unsatisfiable ranges. The end index is non-inclusive.
Source code in src/sgn/bottle.py
path_shift(script_name, path_info, shift=1)
¶
Shift path fragments from PATH_INFO to SCRIPT_NAME and vice versa.
:return: The modified paths. :param script_name: The SCRIPT_NAME path. :param script_name: The PATH_INFO path. :param shift: The number of path fragments to shift. May be negative to change the shift direction. (default: 1)
Source code in src/sgn/bottle.py
redirect(url, code=None)
¶
Aborts execution and causes a 303 or 302 redirect, depending on the HTTP protocol version.
Source code in src/sgn/bottle.py
run(app=None, server='wsgiref', host='127.0.0.1', port=8080, interval=1, reloader=False, quiet=False, plugins=None, debug=None, config=None, **kargs)
¶
Start a server instance. This method blocks until the server terminates.
:param app: WSGI application or target string supported by
:func:load_app. (default: :func:default_app)
:param server: Server adapter to use. See :data:server_names keys
for valid names or pass a :class:ServerAdapter subclass.
(default: wsgiref)
:param host: Server address to bind to. Pass 0.0.0.0 to listens on
all interfaces including the external one. (default: 127.0.0.1)
:param port: Server port to bind to. Values below 1024 require root
privileges. (default: 8080)
:param reloader: Start auto-reloading server? (default: False)
:param interval: Auto-reloader interval in seconds (default: 1)
:param quiet: Suppress output to stdout and stderr? (default: False)
:param options: Options passed to the server adapter.
Source code in src/sgn/bottle.py
4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 | |
static_file(filename, root, mimetype=True, download=False, charset='UTF-8', etag=None, headers=None)
¶
Open a file in a safe way and return an instance of :exc:HTTPResponse
that can be sent back to the client.
:param filename: Name or path of the file to send, relative to root.
:param root: Root path for file lookups. Should be an absolute directory
path.
:param mimetype: Provide 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 for files with a text/* mime-type.
(default: UTF-8)
:param etag: Provide a pre-computed ETag header. If set to False,
ETag handling is disabled. (default: auto-generate ETag header)
:param headers: Additional headers dict to add to the response.
While checking user input is always a good idea, this function provides
additional protection against malicious filename parameters from
breaking out of the root directory and leaking sensitive information
to an attacker.
Read-protected files or files outside of the root directory are
answered with 403 Access Denied. Missing files result in a
404 Not Found response. Conditional requests (If-Modified-Since,
If-None-Match) are answered with 304 Not Modified whenever
possible. HEAD and Range requests (used by download managers to
check or continue partial downloads) are also handled automatically.
Source code in src/sgn/bottle.py
3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 | |
template(*args, **kwargs)
¶
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).
Source code in src/sgn/bottle.py
view(tpl_name, **defaults)
¶
Decorator: renders a template for a handler. The handler can control its behavior like that:
- return a dict of template vars to fill out the template
- 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.
Source code in src/sgn/bottle.py
yieldroutes(func)
¶
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::
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>'