示例#1
0
    def __enter__(self):

        host, port, ssl = parse.host(self.host)
        http = httplib.HTTPSConnection if ssl else httplib.HTTPConnection

        self.con = http(host, port, timeout=self.timeout)

        try:
            self.con.request(self.method, self.path)
        except (httplib.HTTPException, socket.error):
            return None

        return self.con.getresponse()
示例#2
0
文件: http.py 项目: zaxklone/isso
    def __enter__(self):

        host, port, ssl = parse.host(self.host)
        http = httplib.HTTPSConnection if ssl else httplib.HTTPConnection

        self.con = http(host, port, timeout=self.timeout)

        try:
            self.con.request(self.method, self.path)
        except (httplib.HTTPException, socket.error):
            return None

        return self.con.getresponse()
示例#3
0
文件: __init__.py 项目: eroen/isso
def main():

    parser = ArgumentParser(description="a blog comment hosting service")
    subparser = parser.add_subparsers(help="commands", dest="command")

    parser.add_argument('--version', action='version', version='%(prog)s ' + dist.version)
    parser.add_argument("-c", dest="conf", default="/etc/isso.conf",
            metavar="/etc/isso.conf", help="set configuration file")

    imprt = subparser.add_parser('import', help="import Disqus XML export")
    imprt.add_argument("dump", metavar="FILE")
    imprt.add_argument("-n", "--dry-run", dest="dryrun", action="store_true",
                       help="perform a trial run with no changes made")

    serve = subparser.add_parser("run", help="run server")

    args = parser.parse_args()
    conf = Config.load(args.conf)

    if args.command == "import":
        xxx = tempfile.NamedTemporaryFile()
        dbpath = conf.get("general", "dbpath") if not args.dryrun else xxx.name

        conf.set("guard", "enabled", "off")
        migrate.disqus(db.SQLite3(dbpath, conf), args.dump)
        sys.exit(0)

    if conf.get("server", "listen").startswith("http://"):
        host, port, _ = parse.host(conf.get("server", "listen"))
        try:
            from gevent.pywsgi import WSGIServer
            WSGIServer((host, port), make_app(conf)).serve_forever()
        except ImportError:
            run_simple(host, port, make_app(conf), threaded=True,
                       use_reloader=conf.getboolean('server', 'reload'))
    else:
        sock = conf.get("server", "listen").partition("unix://")[2]
        try:
            os.unlink(sock)
        except OSError as ex:
            if ex.errno != errno.ENOENT:
                raise
        wsgi.SocketHTTPServer(sock, make_app(conf)).serve_forever()