Python cgitb 模块,enable() 实例源码

我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用cgitb.enable()

项目:yt    作者:yt-project    | 项目源码 | 文件源码
def __call__(self, parser, namespace, values, option_string = None):
        # If we recognize one of the arguments on the command line as indicating a
        # different mechanism for handling tracebacks, we attach one of those handlers
        # and remove the argument from sys.argv.
        #
        if self.dest == "paste":
            sys.excepthook = paste_traceback
            mylog.debug("Enabling traceback pasting")
        elif self.dest == "paste-detailed":
            sys.excepthook = paste_traceback_detailed
            mylog.debug("Enabling detailed traceback pasting")
        elif self.dest == "detailed":
            import cgitb
            cgitb.enable(format="text")
            mylog.debug("Enabling detailed traceback reporting")
        elif self.dest == "rpdb":
            sys.excepthook = rpdb.rpdb_excepthook
            mylog.debug("Enabling remote debugging")
项目:gvacli    作者:nbarrientos    | 项目源码 | 文件源码
def main():
  global args
  args = parse_arguments()

  last_sync = ""
  if not args.all:
    now = datetime.now()
    last_sync = (now - timedelta(hours=3)).strftime("%Y-%m-%d %H:%M:%S")
    last_sync = urllib.quote_plus(last_sync)

  connection = httplib.HTTPConnection(WSHOST, 80)
  uri = WSURI % last_sync
  connection.request("GET", uri)
  response = connection.getresponse()

  if response.status != httplib.OK:
    logging.error("The webservice didn't return OK :(")
    return 1

  json = response.read()
  data = anyjson.deserialize(json)
  departures = fetch_departures(data)

  cgitb.enable()

  table = PrettyTable(['Scheduled',
    'Expected', 'Destination',
    'Flight', 'Airline', 'Gate',
    'Aircraft', 'Reg', 'Status'])
  table.align = 'l'
  for departure in sorted(departures):
    table.add_row(departure)
  print table

  return 0
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_syshook_no_logdir_default_format(self):
        with temp_dir() as tracedir:
            rc, out, err = assert_python_failure(
                  '-c',
                  ('import cgitb; cgitb.enable(logdir=%s); '
                   'raise ValueError("Hello World")') % repr(tracedir))
        out = out.decode(sys.getfilesystemencoding())
        self.assertIn("ValueError", out)
        self.assertIn("Hello World", out)
        # By default we emit HTML markup.
        self.assertIn('<p>', out)
        self.assertIn('</p>', out)
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_syshook_no_logdir_text_format(self):
        # Issue 12890: we were emitting the <p> tag in text mode.
        with temp_dir() as tracedir:
            rc, out, err = assert_python_failure(
                  '-c',
                  ('import cgitb; cgitb.enable(format="text", logdir=%s); '
                   'raise ValueError("Hello World")') % repr(tracedir))
        out = out.decode(sys.getfilesystemencoding())
        self.assertIn("ValueError", out)
        self.assertIn("Hello World", out)
        self.assertNotIn('<p>', out)
        self.assertNotIn('</p>', out)
项目:Cloud-Data-Center    作者:iadi7ya    | 项目源码 | 文件源码
def create_obj() :

   os.system("iptables -F")
   os.system("setenforce 0")
   flav=form.getvalue('obj')
   if flav == 'flavour1' :
      size='1'
   elif flav == 'flavour2' :
      size='2'
   else :
      size='5'
   user=os.environ.get("HTTP_COOKIE")
   os.system("lvcreate --size "+size+"G --name "+user+" staas_vg")
   os.system("mkfs.ext4 /dev/staas_vg/"+user)
   os.system("mkdir -p /staas/"+user)
   os.system("mount /dev/staas_vg/"+user+" /staas/"+user)
   f1=open("/etc/exports","a+")
   f1.write("/staas/"+user+"  *(rw,no_root_squash)\n")
   f1.close()
   os.system("service nfs restart")
   f2=open("/var/www/cgi-bin/scripts/mountobj_"+user+".py","a+")
   f2.write("#!/usr/bin/python\nimport os\n\import cgi\nimport cgitb\ncgitb.enable()\nprint 'Content-type: application/download'\nprint ''\n\n")
   f2.write("print '#!/usr/bin/python\nimport os'\n")
   f2.write("user = '%s'\n" % (user))
   f2.write("print \"os.system('iptables -F')\"\nprint \"os.system('setenforce 0')\"\nprint \"os.system('mkdir /media/\"+user+\"')\"\n")
   f2.write("print \"os.system('mount 192.168.0.100:/staas/\"+user+\" /media/\"+user+\"')\"\n")
   f2.close()
   os.system("chmod 555 /var/www/cgi-bin/scripts/mountobj_"+user+".py")
   db=MySQLdb.connect("192.168.0.100","clouduser","maestro","cloud")
   cursor=db.cursor()
   cursor.execute("update cloudsignup set statusobj=\"1\" where email='%s'" % (user))
   print "Status: 303 See other"
   print "Location: http://192.168.0.100/cgi-bin/objmount.py"
   print ""
项目:Cloud-Data-Center    作者:iadi7ya    | 项目源码 | 文件源码
def snap() :
   user=os.environ.get("HTTP_COOKIE")
   if user:
     flag=0
     for item in os.listdir("/var/www/cgi-bin/scripts") :
        if item == "mountobjsnap_"+user+".py" :
          flag=1
          break

   name=form.getvalue('snap')
   os.system("lvcreate --size +1G  --name "+name+"/dev/staas_vg/"+user)
   os.system("mkfs.ext4 /dev/staas_vg/"+user)
   os.system("mkdir -p /staas/"+user+"_"+name)
   os.system("mount /dev/staas_vg/"+name+" /staas/"+user+"_"+name)
   f1=open("/etc/exports","a+")
   f1.write("/staas/"+user+"_"+name+"  *(rw,no_root_squash)\n")
   f1.close()
   os.system("service nfs restart")
   if flag==0:
     f2=open("/var/www/cgi-bin/scripts/mountobjsnap_"+user+".py","a+")
     f2.write("#!/usr/bin/python\nimport os\n\import cgi\nimport cgitb\ncgitb.enable()\nprint 'Content-type: application/download'\nprint ''\n\n")
     f2.write("print '#!/usr/bin/python\nimport os'\n")
     f2.write("user = '%s'\n" % (user))
     f2.write("name = '%s'\n" % (name))
     f2.write("print \"os.system('iptables -F')\"\nprint \"os.system('setenforce 0')\"\nprint \"os.system('mkdir /media/\"+user+\"/\"+name+\"')\"\n")
     f2.write("print \"os.system('mount 192.168.0.100:/staas/\"+user+\"/\"+name+\" /media/\"+user+\"/\"+name+\"')\"\n")
     f2.close()

     os.system("chmod 555 /var/www/cgi-bin/scripts/mountobjsnap_"+user+".py")
   print "Status: 303 See other"
   print "Location: http://192.168.0.100/cgi-bin/objsnapmount.py"
   print ""
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_syshook_no_logdir_default_format(self):
        with temp_dir() as tracedir:
            rc, out, err = assert_python_failure(
                  '-c',
                  ('import cgitb; cgitb.enable(logdir=%s); '
                   'raise ValueError("Hello World")') % repr(tracedir))
        out = out.decode(sys.getfilesystemencoding())
        self.assertIn("ValueError", out)
        self.assertIn("Hello World", out)
        # By default we emit HTML markup.
        self.assertIn('<p>', out)
        self.assertIn('</p>', out)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_syshook_no_logdir_text_format(self):
        # Issue 12890: we were emitting the <p> tag in text mode.
        with temp_dir() as tracedir:
            rc, out, err = assert_python_failure(
                  '-c',
                  ('import cgitb; cgitb.enable(format="text", logdir=%s); '
                   'raise ValueError("Hello World")') % repr(tracedir))
        out = out.decode(sys.getfilesystemencoding())
        self.assertIn("ValueError", out)
        self.assertIn("Hello World", out)
        self.assertNotIn('<p>', out)
        self.assertNotIn('</p>', out)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_syshook_no_logdir_default_format(self):
        with temp_dir() as tracedir:
            rc, out, err = assert_python_failure(
                  '-c',
                  ('import cgitb; cgitb.enable(logdir=%s); '
                   'raise ValueError("Hello World")') % repr(tracedir))
        out = out.decode(sys.getfilesystemencoding())
        self.assertIn("ValueError", out)
        self.assertIn("Hello World", out)
        # By default we emit HTML markup.
        self.assertIn('<p>', out)
        self.assertIn('</p>', out)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_syshook_no_logdir_text_format(self):
        # Issue 12890: we were emitting the <p> tag in text mode.
        with temp_dir() as tracedir:
            rc, out, err = assert_python_failure(
                  '-c',
                  ('import cgitb; cgitb.enable(format="text", logdir=%s); '
                   'raise ValueError("Hello World")') % repr(tracedir))
        out = out.decode(sys.getfilesystemencoding())
        self.assertIn("ValueError", out)
        self.assertIn("Hello World", out)
        self.assertNotIn('<p>', out)
        self.assertNotIn('</p>', out)
项目:ipv6excuses.com    作者:detobate    | 项目源码 | 文件源码
def main():
    cgitb.enable()
    print("Content-Type: text/html;charset=utf-8\r\n\r\n")
    with open(excusefile, encoding="utf-8") as infile:
        terms = infile.readlines()
    print(header)
    random.shuffle(terms)
    print(generateTable(terms[:total]))
    print(footer)
项目:Cloud-Data-Center    作者:iadi7ya    | 项目源码 | 文件源码
def create_bl() :
   os.system("iptables -F")
   os.system("setenforce 0")
   flav=form.getvalue('block')
   if flav == 'flavour1' :
      size="3"
   elif flav == 'flavour2' :
      size="5"
   else :
      size="8"
   count=1
   user=os.environ.get('HTTP_COOKIE')
  # os.system("lvcreate --size "+size+"G --name "+user+" staas_blockvg")
  # for item in os.listdir("/dev/staas_blockvg"):
    #   count=count+1
   tid=str(count)
   os.system("sudo tgtadm --lld iscsi --mode target --op new --tid 1  --targetname "+user)
   os.system("sudo tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL")
   os.system("sudo tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 1  --backing-store /dev/sda6")
   os.system("sudo tgt-admin --dump 2>"+user+".txt")
   f4=open("/etc/tgt/targets.conf","a+")
   (a,b)=commands.getstatusoutput("cat "+user+".txt")
   f4.write(b)
   f4.close()
   os.system("service tgtd restart")
   os.system("rm -f "+user+".txt")
   f2=open("scripts/bl_connect_"+user+".py","a+")
   f2.write("#!/usr/bin/python\nimport os\nimport cgi\nimport cgitb\ncgitb.enable()\nprint 'Content-type: application/download'\nprint ''\n\n")
   f2.write("print '#!/usr/bin/python'\nprint 'import os'\nprint 'import cgi'\nprint 'import cgitb'\nprint 'cgitb.enable()'\n")
   f2.write("user= '%s'\n" % (user))
   f2.write("print \"os.system('iptables -F')\"\nprint \"os.system('setenforce 0')\"\nprint \"os.system('service iscsi restart')\"\n")
   f2.write("print \"os.system('iscsiadm --mode discoverydb --types sendtargets --portal 192.168.0.29 --discover')\"\n")
   f2.write("print \"os.system('iscsiadm --mode node --targetname \"+user+\" --portal 192.168.0.100:3260 --login')\"")
   f2.close()
   os.system("chmod 555 /var/www/cgi-bin/scripts/bl_connect_"+user+".py")
   f3=open("/var/www/cgi-bin/scripts/bl_logout_"+user+".py","a+")
   f3.write("#!/usr/bin/python\nimport os\nimport cgi\nimport cgitb\ncgitb.enable()\nprint 'Content-type: application/download'\nprint ''\n\n")
   f3.write("print '#!/usr/bin/python'\nprint 'import os'\nprint 'import cgi'\nprint 'import cgitb'\nprint 'cgitb.enable()'\nprint ''\n\n")
   f3.write("user = '%s'" % (user))
   f3.write("print \"os.system('iptables -F')\"\nprint \"os.system('setenforce 0')\"\n\n")
   f3.write("print  \"os.system('iscsiadm --mode node --targetname \"+user+\" --portal 192.168.0.100:3260 --logout')\"")
   f3.close()
   os.system("chmod 555 /var/www/cgi-bin/scripts/bl_logout_"+user+".py")
   db=MySQLdb.connect("192.168.0.100","clouduser","maestro","cloud")
   cursor=db.cursor()
   cursor.execute("update cloudsignup set statusbl='1' where email= '%s'" % (user)) 
   print "Status: 303 See other"
   print "Location: http://192.168.0.100/cgi-bin/blclient.py"
   print ""
项目:useradm    作者:redbrick    | 项目源码 | 文件源码
def main():
    """Program entry function."""

    # XXX: Stupid Apache on shrapnel has TZ set to US/Eastern, no idea why!
    os.environ['TZ'] = 'Eire'

    print("Content-type: text/html")
    print()

    atexit.register(shutdown)

    # Sets up an exception handler for uncaught exceptions and saves
    # traceback information locally.
    #
    cgitb.enable(logdir='%s/tracebacks' % os.getcwd())

    global form
    form = cgi.FieldStorage()

    opt.mode = form.getfirst('mode')
    if opt.mode not in cmds:
        opt.mode = 'card'
    opt.action = form.getfirst('action')
    # XXX remove usr.override
    # usr.override = opt.override = form.getfirst('override') == '1'
    opt.override = form.getfirst('override') == '1'

    # Start HTML now only for modes that print output *before* html_form is
    # called (which calls start_html itself). We delay the printing of the
    # header for all other modes as mode switching may occur (e.g.
    # cardid <-> add/renew).
    #
    if opt.mode in cmds_noform or (opt.mode in cmds_custom and opt.action):
        html_start()

    global udb
    udb = RBUserDB()
    udb.setopt(opt)

    # Open database and call function for specific command only if action
    # is required or the command needs no user input (i.e. no blank form
    # stage).
    #
    if opt.mode in cmds_noform or opt.action:
        try:
            udb.connect()
        except ldap.LDAPError as err:
            error(err, 'Could not connect to user database')
            # not reached
        try:
            eval(opt.mode + '()')
        except (ldap.LDAPError, RBError) as err:
            error(err)
            # not reached
    html_form()
    sys.exit(0)