예제 #1
0
    def configure(self, options, conf):
        """Configure, based on the parsed options.

        :attention: This is part of the Nose plugin contract.
        """
        super().configure(options, conf)
        if self.enabled:
            import crochet

            # Remove deprecated crochet APIs.
            if hasattr(crochet, "wait_for_reactor"):
                del crochet.wait_for_reactor
            if hasattr(crochet.EventLoop, "wait_for_reactor"):
                del crochet.EventLoop.wait_for_reactor
            if hasattr(crochet, "DeferredResult"):
                del crochet.DeferredResult

            # Make a default timeout forbidden.
            class EventualResult(crochet.EventualResult):
                def _result(self, timeout=None):
                    if timeout is None:
                        raise AssertionError("A time-out must be specified.")
                    else:
                        return super()._result(timeout)

            # Patch it back into crochet.
            crochet._eventloop.EventualResult = EventualResult
            crochet.EventualResult = EventualResult

            if getattr(options, self.option_no_setup):
                crochet.no_setup()
            else:
                crochet.setup()
예제 #2
0
def app(request):
    from gluuengine.app import create_app
    from crochet import no_setup

    no_setup()
    os.environ["API_ENV"] = "test"
    app = create_app()
    return app
예제 #3
0
파일: conftest.py 프로젝트: albertvo15/test
def app(request):
    from gluuapi.app import create_app
    from crochet import no_setup

    os.environ["API_ENV"] = "test"
    app = create_app()
    no_setup()
    return app
예제 #4
0
파일: core.py 프로젝트: bitbyt3r/mapthree
def _init_crochet(in_twisted=False):
    global crochet_initialized
    if crochet_initialized:
        return
    if in_twisted:
        crochet.no_setup()
    else:
        crochet.setup()
    crochet_initialized = True
예제 #5
0
def _init_crochet(in_twisted=False):
    global crochet_initialized
    if crochet_initialized:
        return
    if in_twisted:
        crochet.no_setup()
    else:
        crochet.setup()
    crochet_initialized = True
예제 #6
0
파일: plugin.py 프로젝트: tjjh89017/maas
 def _configureCrochet(self):
     # Prevent other libraries from starting the reactor via crochet.
     # In other words, this makes crochet.setup() a no-op.
     import crochet
     crochet.no_setup()
예제 #7
0
from . import comm
from . import config
from . import context
from . import http
from . import plugin
from . import proxy
from . import requestcache
from .console import ProxyCmd
from twisted.enterprise import adbapi
from twisted.internet import reactor, defer
from twisted.internet.error import CannotListenError
from twisted.internet.protocol import ServerFactory
from twisted.internet.threads import deferToThread

crochet.no_setup()
server_factory = None
main_context = context.Context()
all_contexts = [main_context]
plugin_loader = None
cons = None

def parse_args():
    # parses sys.argv and returns a settings dictionary

    parser = argparse.ArgumentParser(description='An intercepting proxy for testing web applications.')
    parser.add_argument('-l', '--lite', help='Run the proxy in "lite" mode', action='store_true')

    args = parser.parse_args(sys.argv[1:])
    settings = {}
예제 #8
0
#!/usr/bin/python
"""
An example of using Crochet from a normal Twisted application.
"""

import time
import threading
import sys

from crochet import no_setup, run_in_reactor, wait_for_reactor, TimeoutError
# Tell Crochet not to run the reactor:
no_setup()

from twisted.internet import reactor
from twisted.web.client import getPage


# Blocking API:
@run_in_reactor
def _download_page(url):
    return getPage(url)

def time_page_download(url):
    start = time.time()
    _download_page(url).wait(1)
    return time.time() - start


def main(url):
    def blockingCode():
        print "Downloading", url
예제 #9
0
from . import comm
from . import config
from . import compress
from . import context
from . import crypto
from . import http
from .console import ProxyCmd
from .util import PappyException
from twisted.enterprise import adbapi
from twisted.internet import reactor, defer
from twisted.internet.error import CannotListenError
from twisted.internet.protocol import ServerFactory
from twisted.internet.threads import deferToThread

crochet.no_setup()
main_context = context.Context()
all_contexts = [main_context]

session = None
quit_confirm_time = None

try:
    from guppy import hpy
    heapstats = hpy()
    heapstats.setref()
except ImportError:
    heapstats = None


class PappySession(object):