# copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following # conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. # # ================================================================= """ A CGI wrapper for pycsw that reuses code from the wsgi wrapper. """ from wsgiref.handlers import CGIHandler from pycsw.wsgi import application handler = CGIHandler() handler.run(application)
def __init__(self): self.os_environ = {} CGIHandler.__init__(self)
def init(self): self.os_environ = {} CGIHandler.init(self)
def start_response(self, status, headers, exc_info=None): protocol = self.environ.get('SERVER_PROTOCOL', 'HTTP/1.0') sys.stdout.write('%s %s\r\n' % (protocol, status)) return CGIHandler.start_response(self, status, headers, exc_info=exc_info)
#!/usr/bin/env python3 import json import os from wsgiref.handlers import CGIHandler from philologic.runtime import (WebConfig, WSGIHandler, landing_page_bibliography) def get_bibliography(environ, start_response): status = '200 OK' headers = [('Content-type', 'application/json; charset=UTF-8'), ("Access-Control-Allow-Origin", "*")] start_response(status, headers) config = WebConfig(os.path.abspath(os.path.dirname(__file__)).replace('scripts', '')) request = WSGIHandler(environ, config) results = landing_page_bibliography(request, config) yield json.dumps(results).encode('utf8') if __name__ == "__main__": CGIHandler().run(get_bibliography)
#!/usr/local/haproxy/env/bin/python from application.auth import requires_auth from application.direct import Base from flask import Flask, request, Response from pyextdirect.api import create_api from pyextdirect.router import Router from wsgiref.handlers import CGIHandler app = Flask('haproxy') @app.route('/direct/router', methods=['POST']) @requires_auth(groups=['administrators']) def route(): router = Router(Base) return Response(router.route(request.json or dict((k, v[0] if len(v) == 1 else v) for k, v in request.form.to_dict(False).iteritems())), mimetype='application/json') @app.route('/direct/api') @requires_auth(groups=['administrators']) def api(): return create_api(Base) if __name__ == '__main__': CGIHandler().run(app)
pages = [] page_width = q_end - q_start + 1 for p_start in range(q_end + 1, l, page_width): page_metadata = dict(query_metadata.items()) page_metadata["field"] = "collocates" page_metadata["format"] = "json" page_metadata["report"] = "frequency" p_end = min(l, p_start + page_width - 1) p_url = make_link(qs, query_method, query_arg, start=p_start, end=p_end, **page_metadata) pages.append(p_url) wrapper = { "result": results, "remaining_pages": pages, "length": l, "q_start": q_start, "q_end": q_end, "total_words": total_words, "field": "word" } yield json.dumps(wrapper, indent=1) if __name__ == "__main__": CGIHandler().run(colloc_service)
#!./venv/bin/python3 from flask_mail import Mail import app_holder from app import create_app, create_redirect_app from wsgiref.handlers import CGIHandler import os os.environ['SCRIPT_NAME'] = '' app = create_app('prod') mail = Mail(app) app_holder.mail_instance = mail @app.context_processor def context_processor(): from start_dev import context_dict return context_dict use_redirect = False if use_redirect: CGIHandler().run(create_redirect_app()) else: CGIHandler().run(app)
def nav_query(obj, db): conn = db.dbh c = conn.cursor() doc_id = int(obj.philo_id[0]) next_doc_id = doc_id + 1 # find the starting rowid for this doc c.execute('select rowid from toms where philo_id="%d 0 0 0 0 0 0"' % doc_id) start_rowid = c.fetchone()[0] # find the starting rowid for the next doc c.execute('select rowid from toms where philo_id="%d 0 0 0 0 0 0"' % next_doc_id) try: end_rowid = c.fetchone()[0] except TypeError: # if this is the last doc, just get the last rowid in the table. c.execute('select max(rowid) from toms;') end_rowid = c.fetchone()[0] # use start_rowid and end_rowid to fetch every div in the document. c.execute( "select * from toms where rowid >= ? and rowid <=? and philo_type>='div' and philo_type<='div3'", (start_rowid, end_rowid)) for o in c.fetchall(): philo_id = [int(n) for n in o["philo_id"].split(" ")] i = HitWrapper.ObjectWrapper(philo_id, db, row=o) yield i if __name__ == "__main__": CGIHandler().run(resolve_cite_service)
from wsgiref.handlers import CGIHandler import simplejson from philologic.runtime import generate_text_object from philologic.DB import DB from philologic.HitWrapper import ObjectWrapper from philologic.runtime import WebConfig from philologic.runtime import WSGIHandler def get_text_object(environ, start_response): status = '200 OK' headers = [('Content-type', 'application/json; charset=UTF-8'), ("Access-Control-Allow-Origin", "*")] start_response(status, headers) config = WebConfig(os.path.abspath(os.path.dirname(__file__)).replace('scripts', '')) db = DB(config.db_path + '/data/') request = WSGIHandler(environ, config) path = config.db_path zeros = 7 - len(request.philo_id) if zeros: request.philo_id += zeros * " 0" obj = ObjectWrapper(request['philo_id'].split(), db) text_object = generate_text_object(request, config) yield simplejson.dumps(text_object) if __name__ == "__main__": CGIHandler().run(get_text_object)
def get_web_config(environ, start_response): status = '200 OK' headers = [('Content-type', 'application/json; charset=UTF-8'), ("Access-Control-Allow-Origin", "*")] start_response(status, headers) db_path = os.path.abspath(os.path.dirname(__file__)).replace('scripts', '') config = WebConfig(db_path) config.time_series_status = time_series_tester(config) db_locals = MakeDBConfig(os.path.join(db_path, "data/db.locals.py")) config.data["available_metadata"] = db_locals.metadata_fields yield config.to_json() def time_series_tester(config): db = DB(config.db_path + '/data/') c = db.dbh.cursor() try: c.execute("SELECT COUNT(*) FROM toms WHERE %s IS NOT NULL" % config.time_series_year_field) count = c.fetchone()[0] if count > 0: return True else: return False except sqlite3.OperationalError: return False if __name__ == "__main__": CGIHandler().run(get_web_config)
# Display own logs on console console = logging.StreamHandler() log.addHandler(console) RunningType.set_scgi_wsgi() log.info("Start SCGI server on %s:%s" % address) from flup.server.scgi import WSGIServer ret = WSGIServer(info_app, bindAddress=address, debug=True).run() sys.exit(ret and 42 or 0) # FIXME: How can we differentiate CGI, fast_CGI and fcgid better? if "CGI" in os.environ.get("GATEWAY_INTERFACE", ""): # normal CGI RunningType.set_cgi() from wsgiref.handlers import CGIHandler CGIHandler().run(info_app) elif "PATH" in os.environ: # New libapache2-mod-fcgid Apache module RunningType.set_fcgid() else: # Old libapache2-mod-fastcgi Apache module RunningType.set_fastcgi() from flup.server.fcgi import WSGIServer WSGIServer(info_app).run() else: log.error("Unknown __name__ value!") except: log.error(traceback.format_exc()) raise
def cgi(app, address=None, **options): from wsgiref.handlers import CGIHandler CGIHandler().run(app) # Just ignore host and port here