def run(): host, port, directory = sys.argv[1:4] app = Cling(directory) try: from wsgiref.simple_server import make_server make_server(host, int(port), app).serve_forever() except KeyboardInterrupt: print("Cio, baby!")
def __init__(self, filename, options, overrides): from static import Cling self.filename = filename self.options = options self.overrides = overrides manifest = Manifest.from_json(filename.text()) self.static_app = Cling(manifest.output_dir)
class StaticApp(transaction_app): def __init__(self): super(StaticApp, self).__init__() self.static = Cling(os.path.dirname(__file__) + '/static/') def __call__(self, environ, start_response): request = self.request(environ) response = self.publish(request) if response.status_code == 404: response = self.static.__call__(environ, start_response) return response return response(environ, start_response)
def register_static_path(self, url_root, path, cache_length=31): """Register a folder to serve as a static path. Specify optional cache length of asset in days. """ from static import Cling headers = [] if cache_length and not self.development: # 1 year in seconds cache_time = cache_length * 86400 headers.append({ 'prefix': '', HTTP_HEADER_CACHE_CONTROL: "public, max-age={}".format(cache_time) }) self.register_wsgi_app(url_root, Cling(path, headers=headers))
def _cling(): from static import Cling return Cling(root="testdata/pub")
def get(headers, url='/index.html'): app = webtest.TestApp(Cling(root="testdata/pub", headers=headers)) return app.get(url)
import os from django.core.wsgi import get_wsgi_application from django.conf import settings from static import Cling os.environ.setdefault("DJANGO_SETTINGS_MODULE", "idocsapp.settings") STATIC_ROOT = settings.STATIC_ROOT STATIC_URL = settings.STATIC_URL MEDIA_ROOT = settings.MEDIA_ROOT MEDIA_URL = settings.MEDIA_URL static_cling = Cling(STATIC_ROOT + '/') media_cling = Cling(MEDIA_ROOT + '/') class ServeStaticMiddleware(object): def __init__(self, application): self.application = application def __call__(self, environ, start_response): path = environ.get('PATH_INFO', '') if path.startswith(STATIC_URL) and not settings.DEBUG: environ['PATH_INFO'] = path.replace(STATIC_URL, '') return static_cling(environ, start_response) elif path.startswith(MEDIA_URL) and not settings.DEBUG: environ['PATH_INFO'] = path.replace(MEDIA_URL, '') return media_cling(environ, start_response)
from optparse import OptionParser import sys,logging,logging.handlers,traceback #3rd party from static import Cling from daemon import DaemonContext from gevent import wsgi #fix path sys.path.append(sep.join(path.dirname(path.abspath(__file__)).split(sep)[:-1])) #shaveet from shaveet import config,api,gc from shaveet.utils import maxfd,setprocname BASE_PATH = path.dirname(path.abspath(__file__)) logger_wsgi = logging.getLogger("wsgi_jsonrpc") logger = logging.getLogger("shaveet.gc") static_app = Cling(path.dirname(path.abspath(__file__))) def wsgi_main(env, start_response): try: if env['PATH_INFO'] == '/': return api.handle(env,start_response) elif env['PATH_INFO'].startswith('/message_updates'): return [api.message_updates(env,start_response)] elif env['PATH_INFO'].startswith('/static'): return static_app(env, start_response) else: start_response('404 Not Found', [('Content-Type', 'text/plain')]) return 'Not Found\r\n' except GeneratorExit:#Python 2.5 fix pass except Exception,e:
def __init__(self, fallback): from static import Cling from settings import BASE_PATH self.app = Cling(BASE_PATH) self.fallback = fallback
import os from static import Cling app = Cling(os.path.dirname(__file__) + "/static")
def __init__(self): super(StaticApp, self).__init__() self.static = Cling(os.path.dirname(__file__) + '/static/')