Esempio n. 1
0
    def testMemorySafety(self):
        # This is meant to be run with ASAN and checks that
        # certain use-after-frees are not present.
        cgi = neo_cgi.CGI()
        hdf = cgi.hdf
        del cgi
        hdf.getValue("x", "y")
        del hdf

        cgi = neo_cgi.CGI()
        cs = cgi.cs()
        del cgi
        cs.parseStr("x")
        del cs

        hdf = neo_util.HDF()
        hdf.setValue("y.z", "1")
        child = hdf.getChild("y")
        del hdf
        child.getValue("x", "y")
        del child

        hdf = neo_util.HDF()
        cs = neo_cs.CS(hdf)
        del hdf
        cs.parseStr("x")
        del cs
Esempio n. 2
0
    def __init__(self,
                 context,
                 pagename=0,
                 readDefaultHDF=1,
                 israwpage=0,
                 **parms):
        if pagename == 0:
            raise NoPageName, "missing pagename"
        self.pagename = pagename
        self.readDefaultHDF = readDefaultHDF
        self._israwpage = israwpage
        self.context = context
        self._pageparms = parms

        self._error_template = None

        self.page_start_time = time.time()
        neo_cgi.cgiWrap(context.stdin, context.stdout, context.environ)
        neo_cgi.IgnoreEmptyFormVars(1)
        self.ncgi = neo_cgi.CGI()
        self.ncgi.parse()
        self._path_num = 0
        domain = self.ncgi.hdf.getValue("CGI.ServerName", "")
        domain = self.ncgi.hdf.getValue("HTTP.Host", domain)
        self.domain = domain
        self.subclassinit()
        self.setPaths([self.ncgi.hdf.getValue("CGI.DocumentRoot", "")])
Esempio n. 3
0
def main(argv, environ):
    # log ("starting")
    cgi = neo_cgi.CGI("")

    try:
        hdf_file = cgi.hdf.getValue("CGI.PathTranslated", "")
        if hdf_file == "":
            cgi.error("No PATH_TRANSLATED var")
            return

        x = string.rfind(hdf_file, '/')
        if x != -1:
            cgi.hdf.setValue("hdf.loadpaths.0", hdf_file[:x])

        cgi.hdf.readFile(hdf_file)
        content = cgi.hdf.getValue("Content", "")
        if content == "":
            cgi.error("No Content var specified in HDF file %s" % hdf_file)
            return

        cgi.display(content)

    except neo_cgi.CGIFinished:
        return
    except Exception, Reason:
        log("Python Exception: %s" % (str(repr(Reason))))
        s = neo_cgi.text2html("Python Exception: %s" % exceptionString())
        cgi.error(s)
Esempio n. 4
0
 def testValidateErrorString(self):
     fake_stdin = StringIO.StringIO("")
     fake_stdout = StringIO.StringIO()
     fake_env = {}
     neo_cgi.cgiWrap(fake_stdin, fake_stdout, fake_env)
     ncgi = neo_cgi.CGI()
     ncgi.error("%s")
     assert fake_stdout.getvalue().find("%s") != -1
Esempio n. 5
0
    def __init__(self,
                 context,
                 pagename=None,
                 readDefaultHDF=1,
                 israwpage=0,
                 parseCGI=1,
                 makePUT=0,
                 **parms):
        if pagename is None: pagename = self._pagename
        if not pagename: raise NoPageName("missing pagename")
        self.pagename = pagename
        self.readDefaultHDF = readDefaultHDF
        self._israwpage = israwpage
        self.context = context
        self._pageparms = parms

        self._error_template = None

        self.page_start_time = time.time()

        if makePUT:
            context.environ['REQUEST_METHOD'] = 'PUT'

        neo_cgi.cgiWrap(context.stdin, context.stdout, context.environ)
        neo_cgi.IgnoreEmptyFormVars(1)
        self.ncgi = neo_cgi.CGI()

        if parseCGI:
            self.ncgi.parse()

        self._path_num = 0
        domain = self.ncgi.hdf.getValue("CGI.ServerName", "")
        domain = self.ncgi.hdf.getValue("HTTP.Host", domain)
        self.domain = domain

        self.setPaths([self.ncgi.hdf.getValue("CGI.DocumentRoot", "")])

        self._sent_headers = 0
        self._reply_headers = {}
        self._reply_code = 200

        if self.ncgi.hdf.getValue("CGI.HTTPS", ""):
            self.http = "https://"
        else:
            self.http = "http://"

        try:
            self.subclassinit()
        except:
            SHOULD_DISPLAY = 0
            DISPLAY_ERROR = 1

            import handle_error
            handle_error.handleException("Display Failed!")
            ERROR_MESSAGE = handle_error.exceptionString()
            return
Esempio n. 6
0
 def run_neo_cgi(self, filename):
     stdin = cStringIO.StringIO("")
     stdout = cStringIO.StringIO()
     neo_cgi.cgiWrap(stdin, stdout, {})
     neo_cgi.IgnoreEmptyFormVars(1)
     ncgi = neo_cgi.CGI()
     path = os.path.dirname(filename)
     ncgi.hdf.setValue("hdf.loadpaths.path", path)
     ncgi.display(filename)
     return
Esempio n. 7
0
def main():
  neo_cgi.cgiWrap(sys.stdin, sys.stdout, os.environ)
  neo_cgi.IgnoreEmptyFormVars(1)
  ncgi = neo_cgi.CGI()
  ncgi.parse()

  ret = receive(ncgi)

  print "Content-type: text/plain"
  print
  if ret:
    print "success", ret
  else:
    print "fail"
Esempio n. 8
0
def main(argv, environ):
    # log ("starting")
    cgi = neo_cgi.CGI("")

    try:
        fp = cgi.filehandle("file")
        print "Content-Type: text/plain\r\n\r\n"
        data = fp.read()
        print data

        f = open("/tmp/file", "w")
        f.write(data)

    except neo_cgi.CGIFinished:
        return
    except Exception, Reason:
        log("Python Exception: %s" % (str(repr(Reason))))
        s = neo_cgi.text2html("Python Exception: %s" % exceptionString())
        cgi.error(s)