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)
Example #2
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)
Example #3
0
    def dump_hdf(self, directory, owner):
        global QUIET
        sys.path.insert(0, "../python")
        sys.path.insert(0, "python")
        import neo_cgi, neo_util
        hdf = neo_util.HDF()
        date = time.strftime("%d %B %Y", time.localtime(time.time()))
        if not self._funcs.items(): return
        for name, f in self._funcs.items():
            if f._title is None and f._desc is None and f._args is None and f._retr is None:
                if not QUIET:
                    sys.stderr.write('-W- No info for function "%s()"\n' %
                                     name)
                continue
            if f._defn is None:
                if not QUIET:
                    sys.stderr.write('-W- No defn for function "%s()"\n' %
                                     name)
            hdf.setValue("Code.%s" % name, name)
            obj = hdf.getObj("Code.%s" % name)
            obj.setValue("Name", name)
            obj.setValue("filename", self._filename)
            if f._title: obj.setValue("Title", f._title)
            if f._defn: obj.setValue("Define", neo_cgi.text2html(f._defn))
            if f._args: obj.setValue("Args", neo_cgi.text2html(f._args))
            if f._desc: obj.setValue("Desc", neo_cgi.text2html(f._desc))
            if string.strip(f._other):
                obj.setValue("Other",
                             neo_cgi.text2html(string.strip(f._other)))
            if f._output: obj.setValue("Output", neo_cgi.text2html(f._output))
            n = 0
            for func in self._funcs.keys():
                obj.setValue("related.%d" % n, func)
                n = n + 1

        fname = self._filename
        x = string.rindex(fname, "/")
        if x != -1: fname = fname[x + 1:]
        x = string.rindex(fname, '.')
        if x != -1: fname = fname[:x]

        hdf.writeFile("%s/%s.hdf" % (directory, fname))
  def dump_hdf (self, directory, owner):
    global QUIET
    sys.path.insert (0, "../python")
    sys.path.insert (0, "python")
    import neo_cgi, neo_util
    hdf = neo_util.HDF()
    date = time.strftime("%d %B %Y", time.localtime(time.time()))
    if not self._funcs.items(): return
    for name, f in self._funcs.items():
      if f._title is None and f._desc is None and f._args is None and f._retr is None:
        if not QUIET:
          sys.stderr.write('-W- No info for function "%s()"\n' % name)
        continue
      if f._defn is None:
        if not QUIET:
          sys.stderr.write('-W- No defn for function "%s()"\n' % name)
      hdf.setValue ("Code.%s" % name, name)
      obj = hdf.getObj ("Code.%s" % name)
      obj.setValue ("Name", name)
      obj.setValue ("filename", self._filename)
      if f._title: obj.setValue ("Title", f._title)
      if f._defn: obj.setValue ("Define", neo_cgi.text2html(f._defn))
      if f._args: obj.setValue ("Args", neo_cgi.text2html(f._args))
      if f._desc: obj.setValue ("Desc", neo_cgi.text2html(f._desc))
      if string.strip(f._other): obj.setValue ("Other", neo_cgi.text2html(string.strip(f._other)))
      if f._output: obj.setValue ("Output", neo_cgi.text2html(f._output))
      n = 0
      for func in self._funcs.keys():
        obj.setValue ("related.%d" % n, func)
        n = n + 1

    fname = self._filename
    x = string.rindex (fname, "/")
    if x != -1: fname = fname[x+1:]
    x = string.rindex (fname, '.')
    if x != -1: fname = fname[:x]

    hdf.writeFile ("%s/%s.hdf" % (directory, fname))
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)
Example #6
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)
Example #7
0
    def hdfExport(self, prefix, hdf, tz="US/Pacific", subj_prefix=None):
        hdf.setValue(prefix, "1")
        obj = hdf.getObj(prefix)
        obj.setValue("doc_id", str(self.doc_id))
        obj.setValue("thread_id", str(self.thread_id))
        obj.setValue("parent_id", str(self.parent_id))
        obj.setValue("next_id", str(self.next_id))
        obj.setValue("child_id", str(self.child_id))
        if self.date:
            neo_cgi.exportDate(obj, "date", tz, self.date)

        subject = self.subject
        if subj_prefix:
            subject = subject.replace(subj_prefix, '')
        obj.setValue("subject", neo_cgi.htmlEscape(subject))
        obj.setValue("subject_strip", neo_cgi.htmlEscape(strip_re(subject, subj_prefix=subj_prefix)))
        obj.setValue("subject_reduced", reduce_subject(subject, subj_prefix=subj_prefix))

        obj.setValue("author", neo_cgi.htmlEscape(self.author))
        obj.setValue("email", neo_cgi.htmlEscape(self.email))
        if self.summary is not None:
            obj.setValue("summary", neo_cgi.text2html(self.summary))
        if self.snippet is not None:
            obj.setValue("snippet", self.snippet)
Example #8
0
def BASIC_renderPlainTextToHtml(raw_body):
    raw_body = fixbody(string.strip(raw_body))
    body = neo_cgi.text2html(string.strip(raw_body))
    return body
Example #9
0
 def export_part (self, m, prefix, hdf):
   punct = " ~`!@#$%^&*()-+=|}{[]\<>?,./:\";'" 
   trans = string.maketrans(punct, "_" * len(punct))
   n = 0
   for k, v in m.items():
       kn = string.upper(string.translate(k, trans))
       hdf.setValue("%s.Headers.%s" % (prefix, kn), v)
       hdf.setValue("%s.Headers.%s.name" % (prefix, kn), k)
       hdf.setValue("%s.Headers.%s.html" % (prefix, kn), neo_cgi.text2html(v))
       n = n + 1
   hdf.setValue("%s.HName" % (prefix), str(n))
   if m.ismultipart():
     if m.getsubtype("mixed") == "alternative":
       sub = []
       for sm in m.get_payload():
         st = sm.gettype("text/plain")
         if st == "text/html":
           sub.insert(0, sm)
         else:
           sub.append(sm)
       if sub:
         if sub[0].gettype("text/plain") == "text/html":
           body = SafeHtmlString(self.decode_part(sub[0], as_utf8 = 1), map_urls = self._urls)
           hdf.setValue ("%s.body" % prefix, body)
         elif sub[0].getmaintype("text") == "text":
           raw_body = self.decode_part(sub[0], as_utf8 = 1)
           raw_body = self.fixbody(raw_body)
           # body = neo_cgi.text2html(string.strip(raw_body))
           body = self.textrenderer.renderPlainTextToHtml(raw_body)
           hdf.setValue ("%s.body" % prefix, body)
     else:
       hdf.setValue ("%s.b_type" % prefix, "multipart")
       num = 0
       for sm in m.get_payload():
         hdf.setValue("%s.parts.%d.num" % (prefix,num),"%s" % num)
         self.export_part (sm, "%s.parts.%d" % (prefix, num), hdf)
         num = num+1
   else:
     ct = m.getmaintype("text")
     st = m.getsubtype("plain")
     filename = self.part_name (m)
     if filename:
       hdf.setValue ("%s.name" % prefix, urllib.quote(filename))
     if ct == "multipart":
       # annoying case where there aren't actually multiple parts in a 
       # multipart
       hdf.setValue ("%s.b_type" % prefix, "multipart")
       sm = m.get_payload()
       # I'm not entirely certain how this doesn't work...
       if type(sm) == type(m):
         hdf.setValue("%s.parts.0.num" % (prefix),"0")
         self.export_part (sm, "%s.parts.0" % (prefix), hdf)
     elif ct == "message":
       hdf.setValue ("%s.b_type" % prefix, "message")
       sm = m.get_payload()
       if type(sm) == StringType:
         p = Parser.Parser()
         sm = p.parsestr(sm)
       if type(sm) == type(m):
         hdf.setValue("%s.parts.0.num" % (prefix),"0")
         self.export_message ("%s.parts.0" % (prefix), hdf, sm)
     elif ct == "text":
       b = self.decode_part(m, as_utf8 = 1)
       if len(b) < 50000 and st == "html":
         body = SafeHtmlString(b, map_urls = self._urls)
         hdf.setValue ("%s.b_type" % prefix, "text")
         hdf.setValue ("%s.body" % prefix, body)
       elif len(b) < 50000 and st == "plain":
         hdf.setValue ("%s.b_type" % prefix, "text")
         b = self.fixbody(b)
         # converted_body = neo_cgi.text2html(string.strip(b))
         converted_body = self.textrenderer.renderPlainTextToHtml(b)
         if not converted_body is None:
           hdf.setValue ("%s.body" % prefix, converted_body)
       else:
         hdf.setValue ("%s.b_type" % prefix, "attach")
     elif ct == "image":
       hdf.setValue ("%s.b_type" % prefix, "image")
     else:
       hdf.setValue ("%s.b_type" % prefix, "attach")