def __init__(self, client):
     self.upload = Queue()
     self.client = client
     Resource.__init__(self)
     t = UploadThread(self)
     t.setDaemon(True)
     t.start()
Ejemplo n.º 2
0
 def __init__(self, rsrc, cookieKey=None):
     Resource.__init__(self)
     self.resource = rsrc
     if cookieKey is None:
         cookieKey = "woven_session_" + _sessionCookie()
     self.cookieKey = cookieKey
     self.sessions = {}
Ejemplo n.º 3
0
    def __init__(self, hs, media_repo):
        Resource.__init__(self)

        self.auth = hs.get_auth()
        self.clock = hs.get_clock()
        self.version_string = hs.version_string
        self.filepaths = media_repo.filepaths
        self.max_spider_size = hs.config.max_spider_size
        self.server_name = hs.hostname
        self.store = hs.get_datastore()
        self.client = SpiderHttpClient(hs)
        self.media_repo = media_repo

        self.url_preview_url_blacklist = hs.config.url_preview_url_blacklist

        # simple memory cache mapping urls to OG metadata
        self.cache = ExpiringCache(
            cache_name="url_previews",
            clock=self.clock,
            # don't spider URLs more often than once an hour
            expiry_ms=60 * 60 * 1000,
        )
        self.cache.start()

        self.downloads = {}
Ejemplo n.º 4
0
def bravo_site(services):
    # extract worlds and non-world services only once at startup
    worlds = {}
    other_services = {}
    for name, service in services.iteritems():
        factory = service.args[1]
        if isinstance(factory, BravoFactory):
            worlds[factory.name] = factory
        else:
            # XXX: do we really need those ?
            other_services[name] = factory
    # add site root
    root = Resource()
    root.putChild('', BravoResource(BravoRootElement(worlds, other_services)))
    # add world sub pages and related plugins
    for world, factory in worlds.iteritems():
        # Discover parameterized plugins.
        plugins = retrieve_plugins(IWorldResource,
                                   parameters={"factory": factory})
        # add sub page
        child = BravoResource(BravoWorldElement(factory, plugins), False)
        root.putChild(world, child)
        # add plugins
        for name, resource in plugins.iteritems():
            # add plugin page
            child.putChild(name, resource)
    # create site
    site = Site(root)
    return site
Ejemplo n.º 5
0
class XMLRPCService(server.Site):

    def __init__(self, port=None):
        self._port = port or get_random_port()
        self._addrs = []
        self._root = Resource()
        self._root.putChild('XMLRPC', XMLRPCResource(self._root))
        server.Site.__init__(self, self._root)

    def log(self, request):
        log.info('%s http://localhost:%d%s' % (request.method,
                                               self._port,
                                               request.uri))

    @property
    def port(self):
        return self._port

    def serve(self):
        log.info('Listening on port %d' % (self._port, ))
        reactor.listenTCP(self._port, self)

    def is_active(self):
        return len(self._addrs)

    def stop(self):
        self._service.stopFactory()
Ejemplo n.º 6
0
 def __init__(self, hs):
     self.hs = hs
     self.version_string = hs.version_string
     self.response_body = encode_canonical_json(
         self.response_json_object(hs.config)
     )
     Resource.__init__(self)
Ejemplo n.º 7
0
    def __init__(self, host, port, path, path_rewrite=None, reactor=reactor,
                 tls=False, headers={}):
        """
        @param host: the host of the web server to proxy.
        @type host: C{str}

        @param port: the port of the web server to proxy.
        @type port: C{port}

        @param path: the base path to fetch data from. Note that you shouldn't
            put any trailing slashes in it, it will be added automatically in
            request. For example, if you put B{/foo}, a request on B{/bar} will
            be proxied to B{/foo/bar}.  Any required encoding of special
            characters (such as " " or "/") should have been done already.

        @param path_rewrite: list of lists with two regexp strings
        used for rewriting the path.

        @param tls: use tls or not

        @type path: C{str}
        """
        Resource.__init__(self)
        self.host = host
        self.port = port
        self.path = path
        self.path_rewrite = path_rewrite
        self.tls = tls
        self.reactor = reactor
        self.headers = headers
Ejemplo n.º 8
0
    def setUp(self):
        super(FlockerDeployTests, self).setUp()
        ca_set, _ = get_credential_sets()
        self.certificate_path = FilePath(self.mktemp())
        self.certificate_path.makedirs()
        ca_set.copy_to(self.certificate_path, user=True)

        self.persistence_service = ConfigurationPersistenceService(
            reactor, FilePath(self.mktemp()))
        self.persistence_service.startService()
        self.cluster_state_service = ClusterStateService(reactor)
        self.cluster_state_service.startService()
        self.cluster_state_service.apply_changes([
            NodeState(uuid=uuid4(), hostname=ip)
            for ip in COMPLEX_DEPLOYMENT_YAML[u"nodes"].keys()
        ])
        self.addCleanup(self.cluster_state_service.stopService)
        self.addCleanup(self.persistence_service.stopService)
        app = ConfigurationAPIUserV1(self.persistence_service,
                                     self.cluster_state_service).app
        api_root = Resource()
        api_root.putChild('v1', app.resource())
        # Simplest possible TLS context that presents correct control
        # service certificate; no need to validate flocker-deploy here.
        self.port = reactor.listenSSL(
            0,
            Site(api_root),
            DefaultOpenSSLContextFactory(
                ca_set.path.child(b"control-127.0.0.1.key").path,
                ca_set.path.child(b"control-127.0.0.1.crt").path),
            interface="127.0.0.1")
        self.addCleanup(self.port.stopListening)
        self.port_number = self.port.getHost().port
 def __init__(self, out=None, *a, **kw):
     Resource.__init__(self, *a, **kw)
     self._log = logging.getLogger(self.__class__.__name__)
     self._log.debug('Initialized.')
     if out is None:
         out = sys.stdout
     self.out = out
Ejemplo n.º 10
0
def create_api_service(persistence_service, cluster_state_service, endpoint,
                       context_factory, clock=reactor):
    """
    Create a Twisted Service that serves the API on the given endpoint.

    :param ConfigurationPersistenceService persistence_service: Service
        for retrieving and setting desired configuration.

    :param ClusterStateService cluster_state_service: Service that
        knows about the current state of the cluster.

    :param endpoint: Twisted endpoint to listen on.

    :param context_factory: TLS context factory.

    :param IReactorTime clock: The clock to use for time. By default
        global reactor.

    :return: Service that will listen on the endpoint using HTTP API server.
    """
    api_root = Resource()
    user = ConfigurationAPIUserV1(persistence_service, cluster_state_service,
                                  clock)
    api_root.putChild('v1', user.app.resource())
    api_root._v1_user = user  # For unit testing purposes, alas

    return StreamServerEndpointService(
        endpoint,
        TLSMemoryBIOFactory(
            context_factory,
            False,
            Site(api_root)
        )
    )
Ejemplo n.º 11
0
    def _testRender(self, uri, expectedURI):
        """
        Check that a request pointing at C{uri} produce a new proxy connection,
        with the path of this request pointing at C{expectedURI}.
        """
        root = Resource()
        reactor = MemoryReactor()
        resource = ReverseProxyResource("127.0.0.1", 1234, "/path", reactor)
        root.putChild("index", resource)
        site = Site(root)

        transport = StringTransportWithDisconnection()
        channel = site.buildProtocol(None)
        channel.makeConnection(transport)
        # Clear the timeout if the tests failed
        self.addCleanup(channel.connectionLost, None)

        channel.dataReceived("GET %s HTTP/1.1\r\nAccept: text/html\r\n\r\n" % (uri,))

        # Check that one connection has been created, to the good host/port
        self.assertEquals(len(reactor.tcpClients), 1)
        self.assertEquals(reactor.tcpClients[0][0], "127.0.0.1")
        self.assertEquals(reactor.tcpClients[0][1], 1234)

        # Check the factory passed to the connect, and its given path
        factory = reactor.tcpClients[0][2]
        self.assertIsInstance(factory, ProxyClientFactory)
        self.assertEquals(factory.rest, expectedURI)
        self.assertEquals(factory.headers["host"], "127.0.0.1:1234")
Ejemplo n.º 12
0
 def __init__(self):
     Resource.__init__(self)
     self.putChild("status", Status())
     self.putChild("follow", Follow())
     self.putChild("delay", Delay())
     self.putChild("partial", Partial())
     self.putChild("drop", Drop())
    def test_posted(self):
        root = Resource()
        collector = Collector()
        root.putChild(b"foo", collector)

        from twisted.internet import reactor
        while True:
            try:
                port = reactor.listenTCP(0, Site(root))
            except:
                pass
            else:
                self.addCleanup(port.stopListening)
                port_number = port.getHost().port
                break

        fluentd_url = URL(
            scheme="http",
            host="127.0.0.1",
            port=port_number,
            path=["foo"],
        )

        agent = Agent(reactor)
        destination = FluentdDestination(agent, fluentd_url)
        destination({"hello": "world"})

        def check():
            self.assertEquals(collector.collected, [b'json={"hello": "world"}'])

        return deferLater(reactor, 0.1, check)
Ejemplo n.º 14
0
def _put_plugin_resources(client_resource):
    # Plugin resources and plugin info
    load_list_css = []
    load_list_js = []
    mode_table = {}
    plugin_resources = Resource()
    client_resource.putChild('plugins', plugin_resources)
    for resource_def in getPlugins(IClientResourceDef, shinysdr.plugins):
        # Add the plugin's resource to static serving
        plugin_resources.putChild(resource_def.key, resource_def.resource)
        plugin_resource_url = '/client/plugins/' + urllib.quote(resource_def.key, safe='') + '/'
        # Tell the client to load the plugins
        # TODO constrain path values to be relative (not on a different origin, to not leak urls)
        if resource_def.load_css_path is not None:
            load_list_css.append(plugin_resource_url + resource_def.load_cs_path)
        if resource_def.load_js_path is not None:
            # TODO constrain value to be in the directory
            load_list_js.append(plugin_resource_url + resource_def.load_js_path)
    for mode_def in get_modes():
        mode_table[mode_def.mode] = {
            u'info_enum_row': mode_def.info.to_json(),
            u'can_transmit': mode_def.mod_class is not None
        }
    # Client gets info about plugins through this resource
    client_resource.putChild('plugin-index.json', static.Data(serialize({
        u'css': load_list_css,
        u'js': load_list_js,
        u'modes': mode_table,
    }).encode('utf-8'), 'application/json'))
Ejemplo n.º 15
0
 def __init__(self, config, port=None):
     super(IdentityServer, self).__init__(config)
     self.plugin_mapping = config["plugin_mapping"]
     self.setupMySQL(config)
     self.setupIdentityQueue(config)
     self.cassandra_cf_identity = config["cassandra_cf_identity"]
     self.cassandra_cf_connections = config["cassandra_cf_connections"]
     self.cassandra_cf_recommendations = config["cassandra_cf_recommendations"]
     self.cassandra_cf_reverse_recommendations = config["cassandra_cf_reverse_recommendations"]
     self.cassandra_client = CassandraClusterPool(
         config["cassandra_servers"],
         keyspace=config["cassandra_keyspace"],
         pool_size=len(config["cassandra_servers"]) * 2)
     self.cassandra_client.startService()
     resource = Resource()
     self.function_resource = Resource()
     resource.putChild("function", self.function_resource)
     if port is None:
         port = config["identity_server_port"]
     self.site_port = reactor.listenTCP(port, server.Site(resource))
     self.expose(self.updateConnections)
     self.expose(self.updateAllConnections)
     self.expose(self.updateAllIdentities)
     self.expose(self.getRecommendations)
     self.expose(self.getReverseRecommendations)
     self.expose(self.updateIdentity)
     # setup manhole
     manhole_namespace = {
         'service': self,
         'globals': globals(),
     }
     reactor.listenTCP(config["manhole_identity_port"], self.getManholeFactory(manhole_namespace, admin=config["manhole_password"]))
Ejemplo n.º 16
0
    def __init__(self, ws, static_path=None):
        self._ws = ws

        if static_path is None:
             static_path = os.path.join(os.path.dirname(__file__), 'static')
        self._static_path = static_path
        Resource.__init__(self)
Ejemplo n.º 17
0
def build_resource():
    root = Resource()

    for key, val in RESOURCE_MAPPING.iteritems():
        root.putChild(key, val)

    return root
Ejemplo n.º 18
0
 def __init__(self, parent):
     """ 
     Initialize
     """
     parent.putChild(self.name, self)
     Renderable.__init__(self, parent)
     Resource.__init__(self)
Ejemplo n.º 19
0
    def __init__(self):
        Resource.__init__(self)

        self.__path = ['']

        self.__controllers = {}
        self.__mapper = routes.Mapper()
 def __init__(self, debug=False, signing_key=None, signing_id=None,
              event_handler=GenericEventHandler):
     Resource.__init__(self)
     self.signing_key = signing_key
     self.signing_id = signing_id
     self.debug = debug # This class acts as a 'factory', debug is used by Protocol
     self.event_handler = event_handler
Ejemplo n.º 21
0
 def __init__(self, get_data_callback, clear_data_callback):
     """
     
     """
     self.get_data_callback = get_data_callback
     self.clear_data_callback = clear_data_callback
     Resource.__init__(self)
Ejemplo n.º 22
0
 def __init__(self, logDirResource, allowedChannels=None):
     Resource.__init__(self)
     self.logDirResource = logDirResource
     allowed = allowedChannels
     if allowed is not None:
         allowed = set(unprefixedChannel(channel) for channel in allowedChannels)
     self.allowed = allowed
Ejemplo n.º 23
0
    def __init__(self, app, chunked=False, max_content_length=2 * 1024 * 1024,
                                           block_length=8 * 1024):
        Resource.__init__(self)

        self.http_transport = TwistedHttpTransport(app, chunked,
                                            max_content_length, block_length)
        self._wsdl = None
Ejemplo n.º 24
0
def run_twisted(apps, port, static_dir='.'):
    """Twisted wrapper for the rpclib.server.wsgi.Application

    Takes a list of tuples containing application, url pairs, and a port to
    to listen to.
    """

    if static_dir != None:
        static_dir = os.path.abspath(static_dir)
        logging.info("registering static folder %r on /" % static_dir)
        root = twisted.web.static.File(static_dir)
    else:
        root = Resource()

    for app, url in apps:
        resource = WSGIResource(reactor, reactor, app)
        logging.info("registering %r on /%s" % (app, url))
        root.putChild(url, resource)

    site = twisted.web.server.Site(root)

    reactor.listenTCP(port, site)
    logging.info("listening on: 0.0.0.0:%d" % port)

    return reactor.run()
Ejemplo n.º 25
0
 def __init__(self, cashier):
     """
     :param cashier: The cashier we talk to
     """
     Resource.__init__(self)
     self.cashier = cashier
     self.compropago = cashier.compropago
Ejemplo n.º 26
0
def run_server(fd=None, port=None, procs=None, verbose=False):
    if args.verbose:
        log.startLogging(stdout)
        environ['SOLEDAD_LOG_TO_STDOUT'] = '1'

    config = get_config()
    path = config["blobs_path"]
    if not port:
        port = int(config["blobs_port"])

    root = Resource()
    root.putChild('blobs', BlobsResource("filesystem", path))
    factory = Site(root)

    if fd is None:
        # Create a new listening port and several other
        # processes to help out.
        if procs is None:
            procs = cpu_count()
        log.msg('A total of %d processes will listen on port %d.' % (procs, port))
        port = reactor.listenTCP(port, factory)
        for i in range(procs - 1):
            reactor.spawnProcess(
                None, executable, [executable, __file__, str(port.fileno())],
                childFDs={0: 0, 1: 1, 2: 2, port.fileno(): port.fileno()},
                env=environ)
    else:
        # Another process created the port, just start listening on it.
        log.msg('Adopting file descriptor %d...' % fd)
        port = reactor.adoptStreamPort(fd, AF_INET, factory)

    reactor.run()
Ejemplo n.º 27
0
 def __init__(self, parent):
    """
    """
    Resource.__init__(self)
    self._parent = parent
    self._debug = self._parent._debug
    self.reactor = self._parent.reactor
Ejemplo n.º 28
0
def create_web_service(trompet, config):
    "Creates the web service. Returns a tuple (service, site)."
    site = Resource()
    trompet.web = site
    site.putChild("", Root())
    service = internet.TCPServer(config["web"]["port"], server.Site(site))
    service.setServiceParent(trompet)
Ejemplo n.º 29
0
    def startService(self):
        app = self._prov_service.app
        dhcp_request_processing_service = self._dhcp_process_service.dhcp_request_processing_service
        if self._config['general.rest_authentication']:
            credentials = (self._config['general.rest_username'],
                           self._config['general.rest_password'])
            server_resource = new_restricted_server_resource(app, dhcp_request_processing_service, credentials)
            logger.info('Authentication is required for REST API')
        else:
            server_resource = new_server_resource(app, dhcp_request_processing_service)
            logger.warning('No authentication is required for REST API')
        root_resource = Resource()
        root_resource.putChild('provd', server_resource)
        rest_site = Site(root_resource)

        port = self._config['general.rest_port']
        interface = self._config['general.rest_ip']
        if interface == '*':
            interface = ''
        logger.info('Binding HTTP REST API service to "%s:%s"', interface, port)
        if self._config['general.rest_ssl']:
            logger.info('SSL enabled for REST API')
            context_factory = ssl.DefaultOpenSSLContextFactory(self._config['general.rest_ssl_keyfile'],
                                                               self._config['general.rest_ssl_certfile'])
            self._tcp_server = internet.SSLServer(port, rest_site, context_factory, interface=interface)
        else:
            self._tcp_server = internet.TCPServer(port, rest_site, interface=interface)
        self._tcp_server.startService()
        Service.startService(self)
Ejemplo n.º 30
0
 def __init__(self, source):
     """
     @param source: The NotificationSource to fetch notifications from.
     """
     Resource.__init__(self)
     self.source = source
     self._finished = {}
 def __init__(self, database, subscription_id):
     Resource.__init__(self)
     self.database = database
     self.subscription_id = subscription_id
Ejemplo n.º 32
0
 def getChild(self, name, request):
     if name == '':
         return self
     return Resource.getChild(self, name, request)
Ejemplo n.º 33
0
from twisted.web.server import Site, NOT_DONE_YET
from twisted.web.resource import Resource
from twisted.internet import reactor
from twisted.internet.task import deferLater
from twisted.python.log import err


# first consume 5, second consume 5 s
class DelayedResource(Resource):

    def _delayRender(self, request):
        request.write("<html><body>Sorry to keep you waiting.</body></html>")
        request.finish()

    def _responseFailed(self, failure, call):
        call.cancel()
        err(failure, "Async response demo interrupted response")

    def render_GET(self, request):
        call = reactor.callLater(5, self._delayRender, request)
        request.notifyFinish().addErrback(self._responseFailed, call)
        return NOT_DONE_YET


root = Resource()
root.putChild("x", DelayedResource())
factory = Site(root)
reactor.listenTCP(8888, factory)
reactor.run()
Ejemplo n.º 34
0
 def __init__(self):
     Resource.__init__(self)
     self.putChild('incoming', IncomingResource())
Ejemplo n.º 35
0
 def __init__(self, enable_blobs=False):
     Resource.__init__(self)
     server_info = ServerInfo(enable_blobs)
     self.putChild('', server_info)
     self.putChild('robots.txt', _Robots())
 def __init__(self, database):
     Resource.__init__(self)
     self.database = database
def broken_client():
    agent = MemoryAgent(Resource())
    return Client(endpoint=b"", agent=agent, cooperator=Uncooperator())
Ejemplo n.º 38
0
 def __init__(self, cell, wcommon):
     Resource.__init__(self)
     self._cell = cell
     self.__note_dirty = wcommon.note_dirty
Ejemplo n.º 39
0
                    uniqueid = %s" % (clicktocall.uid, clicktocall.uid2)
            print query
            df = txdb.execute(query)
            df.addCallback(self.onDb)
            df.addErrback(self.errDb)

    def onDb(self, result):
        print("result db")
        print result
        self.result = result[len(result)-1]
        print("Hello : ", self.result)
        requests.write('''
                      <html><body>
                      <br>CDR : %s <br>
                      </body></html>
                      ''' % self.result)
        requests.finish()

    def errDb(self, error):
        print('error db')
        print(error)


if __name__=="__main__":
    root = Resource()
    root.putChild("form1", FormPage())
    root.putChild("form2", NewPage())
    factory = Site(root)
    reactor.listenTCP(8880, factory)
    reactor.run()
Ejemplo n.º 40
0
                                    storage=storage,
                                    talos_vc=vc_server,
                                    tls_port=args.tls_port)
        if args.bootstrap is None:
            server.bootstrap([("1.2.3.4", args.dhtport)])
        else:
            server.bootstrap([
                (x, int(y))
                for (x, y) in map(lambda tmp: tmp.split(':'), args.bootstrap)
            ])
    else:
        if args.secure:
            server = TalosSecureDHTServer.loadState(args.dht_cache_file,
                                                    storage=storage,
                                                    talos_vc=vc_server)
        else:
            server = TalosDHTServer.loadState(args.dht_cache_file,
                                              storage=storage,
                                              talos_vc=vc_server)

    server.listen(args.dhtport, interface=args.dhtserver)
    server.saveStateRegularly(args.store_state_file)

    root = Resource()
    root.putChild("store_chunk", AddChunk(server))
    root.putChild("chunk_address", GetChunkLoaction(server))

    factory = Site(root)
    reactor.listenTCP(args.restport, factory, interface=args.restserver)
    reactor.run()
Ejemplo n.º 41
0
        )
        if not authenticated:
            debug('Failed HTTP Basic auth, user: '******'__main__':
    # Quick & dirty testing...

    # create the intarweb
    from twisted.web.server import Site
    root = Resource()
    sit = Site(HtPasswdWrapper(root, 'butt', 'head', 'test site'))
    #sit = Site(root)

    root.putChild(
        '',
        static.Data('If you can see this, you are authorized!  Congrats!',
                    'text/plain'))
    root.putChild('blah', static.Data('Bring me a child!!', 'text/plain'))

    # and finally talk to the internat
    from twisted.internet import reactor
    reactor.listenTCP(18080, sit)
    reactor.run()
"""
/*
Ejemplo n.º 42
0
 def __init__(self, reactor, block):
     Resource.__init__(self)
     self.__reactor = reactor
     self.__block = block
Ejemplo n.º 43
0
 def __init__(self, process_service, pg_mgr):
     Resource.__init__(self)
     self._process_service = process_service
     self._pg_mgr = pg_mgr
     self.service_factory = _null_service_factory
Ejemplo n.º 44
0
 def __init__(self, realm, errorPage):
     Resource.__init__(self)
     self.realm = realm
     self.errorPage = errorPage
Ejemplo n.º 45
0
 def __init__(self, callback):
     self.callback = callback
     Resource.__init__(self)
Ejemplo n.º 46
0
 def __init__(self):
     self.webAuthenticated = False
     Resource.__init__(self)
Ejemplo n.º 47
0
from django.core.handlers.wsgi import WSGIHandler


# Environment setup for your Django project files:
#sys.path.append("cib_simulator")
sys.path.append("gameMT")
os.environ['DJANGO_SETTINGS_MODULE'] = 'gameMT.settings'

shared_messages = {}

resource = HttpShare(shared_messages)
factory = Site(resource)
ws_resource = WebSocketsResource(lookupProtocolForFactory(resource.wsFactory))

#Create a resource which will correspond to the root of the URL hierarchy: all URLs are children of this resource.
root = Resource()
root.putChild("",resource) #the http protocol is up at /
root.putChild("ws",ws_resource) #the websocket protocol is at /ws

# Twisted Application Framework setup:
application = service.Application("shareserver")

#This is the port for pass messages
internet.TCPServer(1035, Site(root)).setServiceParent(application)

#serving django over wsgi
# Create and start a thread pool,
wsgiThreadPool = ThreadPool()
wsgiThreadPool.start()

django_application = WSGIHandler()
Ejemplo n.º 48
0
 def getChild(self, name, request):
     if name == '':
         self.isLeaf = True
         return self
     return Resource.getChild(self, name, request)
 def __init__(self, year):
     Resource.__init__(self)
     self.year = year
Ejemplo n.º 50
0
 def __init__(self):
     Resource.__init__(self)
     self.putChild("static", File("data/web_static"))
Ejemplo n.º 51
0
 def __init__(self, coordinator):
     Resource.__init__(self)
     self.coordinator = coordinator
Ejemplo n.º 52
0
from twisted.web.server import Site
from twisted.web.resource import Resource
from twisted.internet import reactor, endpoints

import html


class FormPage(Resource):
    def render_GET(self, request):
        return (b"<!DOCTYPE html><html><head><meta charset='utf-8'>"
                b"<title></title></head><body>"
                b"<form method='POST'><input name='the-field'></form>")

    def render_POST(self, request):
        args = request.args[b"the-field"][0].decode("utf-8")
        escapedArgs = html.escape(args)
        return (b"<!DOCTYPE html><html><head><meta charset='utf-8'>"
                b"<title></title></head><body>"
                b"You submitted: " + escapedArgs.encode('utf-8'))


root = Resource()
root.putChild(b"form", FormPage())
factory = Site(root)
endpoint = endpoints.TCP4ServerEndpoint(reactor, 8880)
endpoint.listen(factory)
reactor.run()
Ejemplo n.º 53
0
 def __init__(self, *args, **kwargs):
     log.msg(
         "DeprecationWarning: DOMController is deprecated; it has been renamed twisted.web.woven.controller.Controller.\n"
     )
     controller.Controller.__init__(self, *args, **kwargs)
     Resource.__init__(self)
Ejemplo n.º 54
0
 def __init__(self, hs):
     Resource.__init__(self)
     self._well_known_builder = WellKnownBuilder(hs)
Ejemplo n.º 55
0
 def __init__(self, factory):
     self.factory = factory
     Resource.__init__(self)
Ejemplo n.º 56
0
 def test_wrapResourceWeb(self):
     from twisted.web.resource import IResource, Resource
     root = Resource()
     wrapped = wrapResource(root, [self.checker])
     self.assertTrue(IResource.providedBy(wrapped))
Ejemplo n.º 57
0
 def __init__(self, registry=None, path=None):
     Resource.__init__(self)
     self.path = path
     self.registry = registry
Ejemplo n.º 58
0
 def __init__(self, get_response_for):
     """
     See :class:`StringStubbingResource`.
     """
     Resource.__init__(self)
     self._get_response_for = get_response_for
Ejemplo n.º 59
0
 def __init__(self, nasmanager):
     Resource.__init__(self)
     self.nm = nasmanager
Ejemplo n.º 60
0
 def __init__(self, path, callback):
     Resource.__init__(self)
     self._path = path.encode('charmap')
     self._callback = callback