예제 #1
0
    def test_urlsplit(self):

        examples = [("http://example.tld/", ('example.tld', 80, False)),
                    ("https://example.tld/", ('example.tld', 443, True)),
                    ("example.tld", ('example.tld', 80, False)),
                    ("example.tld:42", ('example.tld', 42, False)),
                    ("https://example.tld:80/", ('example.tld', 80, True))]

        for (hostname, result) in examples:
            self.assertEqual(wsgi.urlsplit(hostname), result)
예제 #2
0
파일: __init__.py 프로젝트: Nildeala/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")
    imprt.add_argument("-t", "--type", dest="type", default=None,
                       choices=["disqus", "wordpress"], help="export type")

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

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

    if args.command == "import":
        conf.set("guard", "enabled", "off")

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

        mydb = db.SQLite3(dbpath, conf)
        migrate.dispatch(args.type, mydb, args.dump)

        sys.exit(0)

    if not any(conf.getiter("general", "host")):
        logger.error("No website(s) configured, Isso won't work.")
        sys.exit(1)

    if conf.get("server", "listen").startswith("http://"):
        host, port, _ = urlsplit(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()
예제 #3
0
파일: test_wsgi.py 프로젝트: posativ/isso
    def test_urlsplit(self):

        examples = [
            ("http://example.tld/", ('example.tld', 80, False)),
            ("https://example.tld/", ('example.tld', 443, True)),
            ("example.tld", ('example.tld', 80, False)),
            ("example.tld:42", ('example.tld', 42, False)),
            ("https://example.tld:80/", ('example.tld', 80, True))]

        for (hostname, result) in examples:
            self.assertEqual(wsgi.urlsplit(hostname), result)
예제 #4
0
파일: http.py 프로젝트: GSI/isso
    def __enter__(self):

        host, port, ssl = urlsplit(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()
예제 #5
0
    def __enter__(self):

        host, port, ssl = urlsplit(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()
예제 #6
0
파일: http.py 프로젝트: panta82/isso
    def __enter__(self):
        host, port, ssl = urlsplit(self.host)
        http = httplib.HTTPSConnection if ssl else httplib.HTTPConnection

        for _ in range(MAX_RETRY_COUNT):
            self.con = http(host, port, timeout=self.timeout)
            try:
                self.con.request(self.method, self.path, headers=self.headers)
            except (httplib.HTTPException, socket.error):
                return None

            try:
                resp = self.con.getresponse()
                if resp.status == 301:
                    location = resp.getheader('Location')
                    if location:
                        self.con.close()
                        self.path = urlparse(location).path
                    else:
                        return None
                else:
                    return resp
            except (httplib.HTTPException, socket.timeout, socket.error):
                return None
예제 #7
0
    def __enter__(self):
        host, port, ssl = urlsplit(self.host)
        http = httplib.HTTPSConnection if ssl else httplib.HTTPConnection

        for _ in range(MAX_RETRY_COUNT):
            self.con = http(host, port, timeout=self.timeout)
            try:
                self.con.request(self.method, self.path, headers=self.headers)
            except (httplib.HTTPException, socket.error):
                return None

            try:
                resp = self.con.getresponse()
                if resp.status == 301:
                    location = resp.getheader('Location')
                    if location:
                        self.con.close()
                        self.path = urlparse(location).path
                    else:
                        return None
                else:
                    return resp
            except (httplib.HTTPException, socket.timeout, socket.error):
                return None
예제 #8
0
파일: __init__.py 프로젝트: oodavy41/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")
    imprt.add_argument("-t",
                       "--type",
                       dest="type",
                       default=None,
                       choices=["disqus", "wordpress"],
                       help="export type")
    imprt.add_argument("--empty-id",
                       dest="empty_id",
                       action="store_true",
                       help="workaround for weird Disqus XML exports, #135")

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

    args = parser.parse_args()
    conf = config.load(join(dist.location, dist.project_name, "defaults.ini"),
                       args.conf)

    if args.command == "import":
        conf.set("guard", "enabled", "off")

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

        mydb = db.SQLite3(dbpath, conf)
        migrate.dispatch(args.type, mydb, args.dump, args.empty_id)

        sys.exit(0)

    if conf.get("general", "log-file"):
        handler = logging.FileHandler(conf.get("general", "log-file"))

        logger.addHandler(handler)
        logging.getLogger("werkzeug").addHandler(handler)

        logger.propagate = False
        logging.getLogger("werkzeug").propagate = False

    if not any(conf.getiter("general", "host")):
        logger.error("No website(s) configured, Isso won't work.")
        sys.exit(1)

    if conf.get("server", "listen").startswith("http://"):
        host, port, _ = urlsplit(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()
예제 #9
0
파일: __init__.py 프로젝트: ix5/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.cfg",
                        metavar="/etc/isso.cfg", 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")
    imprt.add_argument("-t", "--type", dest="type", default=None,
                       choices=["disqus", "wordpress", "generic"], help="export type")
    imprt.add_argument("--empty-id", dest="empty_id", action="store_true",
                       help="workaround for weird Disqus XML exports, #135")

    # run Isso as stand-alone server
    subparser.add_parser("run", help="run server")

    args = parser.parse_args()

    # ISSO_SETTINGS env var takes precedence over `-c` flag
    conf_file = os.environ.get('ISSO_SETTINGS') or args.conf

    if not conf_file:
        logger.error("No configuration file specified! Exiting.")
        sys.exit(1)
    if exists(conf_file):
        logger.info("Using configuration file '%s'", abspath(conf_file))
    else:
        logger.error("Specified config '%s' does not exist! Exiting.",
                     abspath(conf_file))
        sys.exit(1)

    conf = config.load(config.default_file(), conf_file)

    if args.command == "import":
        conf.set("guard", "enabled", "off")

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

        mydb = db.SQLite3(dbpath, conf)
        migrate.dispatch(args.type, mydb, args.dump, args.empty_id)

        sys.exit(0)

    if conf.get("general", "log-file"):
        handler = logging.FileHandler(conf.get("general", "log-file"))

        logger.addHandler(handler)
        logging.getLogger("werkzeug").addHandler(handler)

        logger.propagate = False
        logging.getLogger("werkzeug").propagate = False

    if conf.get("server", "listen").startswith("http://"):
        host, port, _ = urlsplit(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()