当前位置: 首页>>代码示例>>Python>>正文


Python monocle.init函数代码示例

本文整理汇总了Python中monocle.init函数的典型用法代码示例。如果您正苦于以下问题:Python init函数的具体用法?Python init怎么用?Python init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了init函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: hello_http

import sys

import monocle
from monocle import _o, Return
monocle.init(sys.argv[1])

from monocle.stack import eventloop
from monocle.stack.network import add_service
from monocle.stack.network.http import HttpHeaders, HttpServer


@_o
def hello_http(req):
    content = "Hello, World!"
    headers = HttpHeaders()
    headers.add('Content-Length', len(content))
    headers.add('Content-Type', 'text/plain')
    headers.add('Connection', 'close')
    headers.add('Set-Cookie', 'test0=blar; Path=/')
    headers.add('Set-Cookie', 'test1=blar; Path=/')
    yield Return(200, headers, content)

add_service(HttpServer(hello_http, 8088))
eventloop.run()
开发者ID:sah,项目名称:monocle,代码行数:24,代码来源:http_server.py

示例2: pump

import sys
import time

import monocle
from monocle import _o
monocle.init('tornado')

from monocle.stack import eventloop
from monocle.stack.network import add_service, Service, Client, ConnectionLost

@_o
def pump(input, output):
  while True:
    try:
      message = yield input.read(1)
      yield output.write(message)
    except ConnectionLost:
      output.close()
      break

@_o
def handle_socks(conn):
  client = Client()
  yield client.connect('localhost', 8050)
  monocle.launch(pump, conn, client)
  yield pump(client, conn)

add_service(Service(handle_socks, port=7050))
eventloop.run_multicore(1)
开发者ID:blanu,项目名称:Dust,代码行数:29,代码来源:tcp_proxy.py

示例3: make_pumper

#! /usr/bin/env python

import sys
import time

import monocle
from monocle import _o
monocle.init("twisted")

from monocle.stack import eventloop
from monocle.stack.network import add_service, Service, Client, ConnectionLost

def make_pumper(direction):
    @_o
    def pump(input, output):
        while True:
            try:
                message = yield input.read_some()
                print "==== %s says: =======================================" % direction
                print message
                yield output.write(message)
            except ConnectionLost:
                output.close()
                break
    return pump

def make_proxy(backend_host, backend_port):
    @_o
    def proxy(conn):
        client = Client()
        yield client.connect(backend_host, backend_port)
开发者ID:justnoise,项目名称:bcox_utils,代码行数:31,代码来源:tcp_proxy.py

示例4: hello_http

import monocle
from monocle import _o, Return
monocle.init("tornado")

from monocle.stack import eventloop
from monocle.stack.network import add_service
from monocle.stack.network.http import HttpHeaders, HttpServer

@_o
def hello_http(req):
    content = "Hello, World!"
    headers = HttpHeaders()
    headers['Content-Length'] = len(content)
    headers['Content-Type'] = 'text/plain'
    yield Return(200, headers, content)

add_service(HttpServer(hello_http, 8088))
eventloop.run()
开发者ID:dnslj,项目名称:python-labs,代码行数:18,代码来源:http.py

示例5: WebSocket

import sys
import new
import simplejson

import monocle
from monocle import _o, Return
monocle.init('tornado') # Only works with Tornado right now

from monocle.stack import eventloop
from monocle.stack.network import add_service, Service
from monocle.stack.network.http import HttpHeaders, WebSocketServer

SOCKET_HTML = """
<!doctype html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>WebSocket Echo</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  </head>
  <body>
    <h1>WebSocket Reverse Echo</h1>
    <section>Your message backwards: <span id="content"></span></section>
    <input id="message" type="text" style="margin: 20px 0px;"/>
    <section>(You typed: <span id="realContent"></span>)</section>

    <script>
        var ws = new WebSocket('ws://localhost:8088/ws/');
        ws.onopen = function(event) { console.log("Opened socket conn"); };
        ws.onclose = function(event) { console.log("Closed socket conn"); };
        ws.onmessage = function(event) {
开发者ID:jlipps,项目名称:monocle,代码行数:31,代码来源:websockets.py

示例6: main

def main(args):
    parser = argparse.ArgumentParser(
        description="runs monocle tests")
    parser.add_argument('--verbose', '-v', action='store_true', default=False,
                        help="verbose mode")
    parser.add_argument('stack', help="monocle stack to use")
    parser.add_argument('paths', nargs=argparse.REMAINDER, help="args for nosetests")
    args = parser.parse_args()

    monocle.init(args.stack)
    from monocle.stack import eventloop

    import rewrite
    hook = rewrite.AssertionRewritingHook()
    sys.meta_path.insert(0, hook)

    class State(object):
        debug = False
        def trace(self, msg):
            if self.debug:
                print msg

    class Config(object):
        _assertstate = State()

    class Session(object):
        config = Config()
        def isinitpath(self, fn):
            return False

    hook.session = Session()

    paths = set()
    all_tests = []
    test_files = []

    for path in args.paths:
        if os.path.isfile(path):
            paths.add(os.path.dirname(path))
            file = os.path.basename(path)
            all_tests.append(file[:-3])
            test_files.append(path)
        elif os.path.isdir(path):
            for top, dirs, files in os.walk(path):
                for file in files:
                    if file.endswith(".py"):
                        paths.add(top)
                        all_tests.append(file[:-3])
                        test_files.append(os.path.join(top, file))
        else:
            print "Unknown file or directory", path
            return

        sys.path.extend(paths)
        imported_tests = []
        hook.fnpats = test_files

        for test in all_tests:
            try:
                m = __import__(test, globals(), locals())
                if hasattr(m, "test"):
                    imported_tests.extend(m.test.func_globals['_tests'])
            except Exception, e:
                print test, str(e)
        _tests.extend(set(imported_tests))
开发者ID:miketwo,项目名称:monocle,代码行数:65,代码来源:o_test.py

示例7: o

import functools
import os

INIT = os.environ.get('BACKEND', 'twisted')
HOST = '127.0.0.1'
PORT = 5555

import monocle
monocle.init(INIT)

from monocle.twisted_stack.utils import cb_to_df
from twisted.trial.unittest import TestCase

def o(f):
    oroutine = monocle._o(f)
    return functools.update_wrapper(
        lambda *a, **k: cb_to_df(oroutine(*a, **k)), oroutine)
开发者ID:ChrisWren,项目名称:monocle,代码行数:17,代码来源:helper.py


注:本文中的monocle.init函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。