Esempio n. 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()
Esempio n. 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
Esempio n. 3
0
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
Esempio n. 4
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
Esempio n. 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
Esempio n. 6
0
 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()
Esempio n. 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 = {}
Esempio n. 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
Esempio n. 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):