This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ContextLocal(object): | |
__slots__ = ('_local_init_args', '_local_contexts', '_local_context_ident') | |
def __new__(cls, *args, **kwargs): | |
self = object.__new__(cls) | |
object.__setattr__(self, '_local_init_args', (args, kwargs)) | |
object.__setattr__(self, '_local_contexts', {}) | |
object.__setattr__(self, '_local_context_ident', lambda: 0) | |
return self | |
def set_context_ident(self, func): | |
object.__setattr__(self, '_local_context_ident', func) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import sys | |
import StringIO | |
class Bench(object): | |
def __init__(self, flags=None): | |
''' Flags: | |
* cgi: Build a new app every time. | |
* dny: Return the :name part of a /hello/:name url. | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import bottle | |
from time import time | |
app = bottle.Bottle() | |
@app.route('/') | |
def hello(): | |
return 'Hello World!' | |
def bench(n): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import bottle | |
from time import time | |
app = bottle.Bottle() | |
@app.route('/') | |
def hello(): | |
return 'Hello World!' | |
def bench(n): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewPlugin(object): | |
''' Automatically renders a template for callbacks that return a dictionary. | |
Subclasses may overrule some methods to implement engine specific | |
features. They must implement :meth:`prepare_file` and | |
:meth:`prepare_source`, should implement :meth:`prepare_factory` and may | |
implement :meth:`assemble_config`, :meth:`is_source`, :meth:`locate` and | |
additional methods. | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir heroku | |
cd heroku/ | |
virtualenv --no-site-packages env | |
source env/bin/activate | |
pip install bottle gevent | |
pip freeze > requirements.txt | |
cat >app.py <<EOF | |
import bottle | |
import os |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ping(server, port): | |
''' Check if a server accepts connections on a specific TCP port ''' | |
try: | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect((server, port)) | |
s.close() | |
return True | |
except socket.error: | |
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bottle | |
app = bottle.Bottle() | |
# Template configuration | |
app.views.adapter = Jinja2Adapter | |
app.views.options['extensions'] = ['jinja2.ext.i18n'] | |
app.views.globals['some_variable'] = 'some_value' | |
app.views.add_path('templates/', root=__file__) | |
# Shortcut to render templates directly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bottle import Bottle | |
app = Bottle() | |
# Resource configuration (relative to current file) | |
app.resources.add_path('./data/', base=__file__) | |
# Override default resources with files in test directory | |
app.resources.add_path('/home/marc/dev/test_data/', index=0) |
OlderNewer