예제 #1
0
def main(args):
    """ main() of this module """

    method = "GET"
    use_stdout = True
    noisy = logging.INFO
    try:
        options, arguments = getopt.getopt(args[1:], "OPv")
    except getopt.error:
        sys.exit("usage: example/http_client.py [-OPv] URI")
    for name, _ in options:
        if name == "-O":
            use_stdout = False
        elif name == "-P":
            method = "PUT"
        elif name == "-v":
            noisy = logging.DEBUG
    if len(arguments) != 1:
        sys.exit("usage: example/http_client.py [-OPv] URI")
    uri = arguments[0]

    logging.basicConfig(format="%(message)s", level=noisy)
    poller = Poller()
    client = ExampleHttpClient(poller, method, uri, use_stdout)
    client.connect_uri(uri)
    poller.loop()
예제 #2
0
def main(args):
    ''' main() of this module '''

    method = "GET"
    use_stdout = True
    noisy = logging.INFO
    try:
        options, arguments = getopt.getopt(args[1:], "OPv")
    except getopt.error:
        sys.exit("usage: example/http_client.py [-OPv] URI")
    for name, _ in options:
        if name == "-O":
            use_stdout = False
        elif name == "-P":
            method = "PUT"
        elif name == "-v":
            noisy = logging.DEBUG
    if len(arguments) != 1:
        sys.exit("usage: example/http_client.py [-OPv] URI")
    uri = arguments[0]

    logging.basicConfig(format="%(message)s", level=noisy)
    poller = Poller()
    client = ExampleHttpClient(poller, method, uri, use_stdout)
    client.connect_uri(uri)
    poller.loop()
예제 #3
0
def main(args):
    ''' main() function of this module '''
    rootdir = "."
    noisy = logging.INFO
    try:
        options, _ = getopt.getopt(args[1:], "d:v")
    except getopt.error:
        sys.exit("usage: examples/http_server.py [-v] [-d rootdir]")
    for name, value in options:
        if name == "-d":
            rootdir = value
        elif name == "-v":
            noisy = logging.DEBUG
    logging.basicConfig(format="%(message)s", level=noisy)
    poller = Poller()
    server = ServeFilesystem(poller, rootdir)
    server.listen(("127.0.0.1", 8080))
    poller.loop()
예제 #4
0
def main(args):
    """ Main function """
    address = "127.0.0.1"
    handler = EchoHandler
    listen = False
    port = "54321"
    noisy = logging.INFO

    try:
        options, _ = getopt.getopt(args[1:], "A:CDlp:v")
    except getopt.error:
        sys.exit("usage: example/stream.py [-CDlv] [-A address] [-p port]")
    for name, value in options:
        if name == "-A":
            address = value
        elif name == "-C":
            handler = ChargenHandler
        elif name == "-D":
            handler = DiscardHandler
        elif name == "-l":
            listen = True
        elif name == "-p":
            port = value
        elif name == "-v":
            noisy = logging.DEBUG

    logging.basicConfig(format="%(message)s", level=noisy)

    poller = Poller()
    instance = handler(poller)
    if not listen:
        instance.connect((address, port))
    else:
        instance.listen((address, port))

    poller.loop()