Ejemplo n.º 1
0
 def render_POST(self, request):
     if request.path != self._path:
         page = NoResource(
             message="API path %s is not supported" % request.URLPath())
         return page.render(request)
     if request.getHeader(b"Content-Type") != b"application/json":
         page = NoResource(
             message="Unsupported Content-Type (must be \"application/json"
                     "\")" % request.URLPath())
         return page.render(request)
     request.setHeader(b"Content-Type", b"application/json")
     self._callback(request)
     return NOT_DONE_YET
Ejemplo n.º 2
0
 def render_POST(self, request):
     if request.path != self._path:
         page = NoResource(message="API path %s is not supported" %
                           request.URLPath())
         return page.render(request)
     if request.getHeader(b"Content-Type") != b"application/json":
         page = NoResource(
             message="Unsupported Content-Type (must be \"application/json"
             "\")" % request.URLPath())
         return page.render(request)
     request.setHeader(b"Content-Type", b"application/json")
     self._callback(request)
     return NOT_DONE_YET
Ejemplo n.º 3
0
    class CgiDirectory(Resource, FilePath):

        cgiscript = CgiScript

        def __init__(self, pathname, filter, childNotFound=None):
            Resource.__init__(self)
            FilePath.__init__(self, pathname)
            self.filter = filter
            if childNotFound:
                self.childNotFound = childNotFound
            else:
                self.childNotFound = NoResource(
                    "CGI directories do not support directory listing.")

        def getChild(self, path, request):
            fnp = self.child(path)
            if not fnp.exists():
                return File.childNotFound
            elif fnp.isdir():
                return CgiDirectory(fnp.path, self.filter, self.childNotFound)
            else:
                return self.cgiscript(fnp.path, self.filter)
            return NoResource()

        def render(self, request):
            return self.childNotFound.render(request)
Ejemplo n.º 4
0
    class CgiDirectory(Resource, FilePath):

        cgiscript = CgiScript

        def __init__(self, pathname, filter, childNotFound=None):
            Resource.__init__(self)
            FilePath.__init__(self, pathname)
            self.filter = filter
            if childNotFound:
                self.childNotFound = childNotFound
            else:
                self.childNotFound = NoResource("CGI directories do not support directory listing.")

        def getChild(self, path, request):
            fnp = self.child(path)
            if not fnp.exists():
                return File.childNotFound
            elif fnp.isdir():
                return CgiDirectory(fnp.path, self.filter, self.childNotFound)
            else:
                return self.cgiscript(fnp.path, self.filter)
            return NoResource()

        def render(self, request):
            return self.childNotFound.render(request)
Ejemplo n.º 5
0
 def render(self, request):
     if self.type == self.types.REDIRECT:
         return ""
     elif self.type == self.types.QUEUE:
         return NOT_DONE_YET
     else:
         return NoResource.render(self, request)
Ejemplo n.º 6
0
 def render(self, request):
     if self.type == self.types.REDIRECT:
         return ""
     elif self.type == self.types.QUEUE:
         return NOT_DONE_YET
     else:
         return NoResource.render(self, request)
Ejemplo n.º 7
0
    def render(self, request: Request) -> bytes:
        request.extra_info = RequestExtraInfo()

        try:
            action: Optional[str] = request.postpath[0].decode()
        except IndexError:
            action = None

        if action:
            request.extra_info.action = action

        if action == 'send':
            return self.send(request)

        elif action == 'recv':
            return self.recv(request)

        elif action == 'publish':
            return self.publish(request)

        elif action == 'subscribe':
            return self.subscribe(request)

        else:
            res = NoResource(message="invalid command to channel.")
            return res.render(request)
Ejemplo n.º 8
0
    class Server(Resource):
        def __init__(self):
            Resource.__init__(self)
            self.isLeaf = True
            self.r404 = NoResource()

            fp = file(sys.argv[0])
            self.src = fp.read()
            fp.close()

            from subprocess import PIPE, Popen
            try:
                self.src_syn = Popen(
                    ['pandoc', '-s'], stdin=PIPE, stdout=PIPE,
                    stderr=PIPE).communicate("~~~~ {.python}\n" + self.src +
                                             "~~~~\n")[0]
            except OSError:
                sys.stderr.write(
                    "pandoc not found; /src/ will default to plain text rather than syntax highlighted code\n"
                )
                self.src_syn = None

        def render_GET(self, request):
            host, path = request.client.host, request.path
            print_flush_log("R %s %s" % (host, path))
            request.setHeader("content-type", "text/plain")

            if path == "/":
                return "%s %s\n%s\n/tcp/[port]\n/udp/[port]\n/src/\n/src/raw\n/src/get\n" % (
                    NAME, VERSION, __doc__)

            try:
                type, port = path[1:].split('/', 2)

                if type == "src":
                    if port == "raw":
                        return self.src
                    elif port == "get":
                        request.setHeader("content-type", "text/x-python")
                        request.setHeader(
                            "content-disposition",
                            "attachment; filename=\"%s\"" % FNAME)
                        return self.src
                    elif self.src_syn is not None:
                        request.setHeader("content-type", "text/html")
                        return self.src_syn
                    else:
                        return self.src

                elif type not in PROTOCOL:
                    raise KeyError

                port = int(port)

            except (ValueError, KeyError):
                return self.r404.render(request)

            else:
                start_connect(host, type, port, reactor.callLater)
                return "awaiting connection to %s %s %s" % (host, type, port)
Ejemplo n.º 9
0
    def return_404(self, request):
        """Return a 404 HTTP response.
        :param request: The request to which we are responding.
        :returns: NoResource's rendering of the request.

        Performed if a request tries to access a nonexistent table.
        """
        page = NoResource(message="Table %s could not be found" %
                          self.table_name)
        return page.render(request)
    def return_404(self, request):
        """Return a 404 HTTP response.
        :param request: The request to which we are responding.
        :returns: NoResource's rendering of the request.

        Performed if a request tries to access a nonexistent table.
        """
        page = NoResource(message="Table %s could not be found" %
                          self.table_name)
        return page.render(request)
Ejemplo n.º 11
0
	class Server(Resource):

		def __init__(self):
			Resource.__init__(self)
			self.isLeaf = True
			self.r404 = NoResource()

			fp = file(sys.argv[0])
			self.src = fp.read()
			fp.close()

			from subprocess import PIPE, Popen
			try:
				self.src_syn = Popen(['pandoc', '-s'], stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate("~~~~ {.python}\n" + self.src + "~~~~\n")[0]
			except OSError:
				sys.stderr.write("pandoc not found; /src/ will default to plain text rather than syntax highlighted code\n")
				self.src_syn = None

		def render_GET(self, request):
			host, path = request.client.host, request.path
			print_flush_log("R %s %s" % (host, path))
			request.setHeader("content-type", "text/plain")

			if path == "/":
				return "%s %s\n%s\n/tcp/[port]\n/udp/[port]\n/src/\n/src/raw\n/src/get\n" % (NAME, VERSION, __doc__)

			try:
				type, port = path[1:].split('/', 2)

				if type == "src":
					if port == "raw":
						return self.src
					elif port == "get":
						request.setHeader("content-type", "text/x-python")
						request.setHeader("content-disposition", "attachment; filename=\"%s\"" % FNAME);
						return self.src
					elif self.src_syn is not None:
						request.setHeader("content-type", "text/html")
						return self.src_syn
					else:
						return self.src

				elif type not in PROTOCOL:
					raise KeyError

				port = int(port)

			except (ValueError, KeyError):
				return self.r404.render(request)

			else:
				start_connect(host, type, port, reactor.callLater)
				return "awaiting connection to %s %s %s" % (host, type, port)
Ejemplo n.º 12
0
    def render_DELETE(self, request):
        # print "KeyResource.render_DELETE"
        if not self.isRemovable():
            epage = NoResource(
                "deleting collection %s failed." % request.uri)
            return epage.render(request)
            
        if self.isdir():
            depth = get_depth(request)
            if not depth:
                epage = BadRequestResource(
                    "deleting collection %s failed."
                    "because depth is not "infinity""
                    % request.uri)
                return epage.render(request)

            self.rmtree()
        else:
            self.remove()

        epage = NoContentResource("%s deleted" % request.uri)
        return epage.render(request)
Ejemplo n.º 13
0
    def render(self, request: Request) -> bytes:
        try:
            action: bytes = request.postpath[0]
            action: Optional[str] = action.decode()

        except IndexError:
            action = None

        if action == 'channels':
            return self.channels(request).encode()

        else:
            res = NoResource(message="invalid command to server.")
            return res.render(request)
Ejemplo n.º 14
0
 def render(self, request):
    notFound = NoResource("CGI directories do not support directory listing.")
    return notFound.render(request)
Ejemplo n.º 15
0
 def render(self, request):
     notFound = NoResource(
         "CGI directories do not support directory listing.")
     return notFound.render(request)
Ejemplo n.º 16
0
Archivo: site.py Proyecto: dir01/lrcs
 def responseNotFound(self, request, failure):
     errorPage = NoResource(message=failure.getErrorMessage())
     request.write(errorPage.render(request))
     request.finish()