예제 #1
0
파일: am.py 프로젝트: dgilman/atom_maker
def cli():
   if len(sys.argv) < 2:
      print "Give the name of a feed to generate"
      sys.exit()

   # hack to support old-style from cmd line
   if "&" not in sys.argv[1]:
      sys.argv[1] = "feed=%s" % sys.argv[1]

   os.environ['SERVER_NAME'] = "cli/"
   os.environ['REQUEST_URI'] = sys.argv[1]
   os.environ['QUERY_STRING'] = sys.argv[1]

   args = cgi.parse()

   feed = feed_cache(args, flush=True)

   if not lxml:
      print feed
   else:
      feed = etree.tostring(etree.fromstring(feed), pretty_print = True, encoding="UTF-8", xml_declaration=True)
      print feed

   try:
      import feedvalidator
      from feedvalidator.formatter.text_plain import Formatter
      from feedvalidator import compatibility
      from feedvalidator.logging import ValidValue
      events = (x for x in feedvalidator.validateString(feed, firstOccurrenceOnly=True, base=self_url())['loggedEvents'] if not isinstance(x, ValidValue))
      print "\n".join(Formatter(events)).encode("UTF-8")
   except ImportError:
      pass
예제 #2
0
 def do_POST(self):
     length = self.headers.get('content-length')
     if not length:
         return self._bad_request()
     if hasattr(self.headers, 'get_content_type'):
         ctype = self.headers.get_content_type()
     elif self.headers.typeheader is None:
         ctype = self.headers.type
     else:
         ctype = self.headers.typeheader
     bare_ctype = ctype.split(";", 1)[0].strip()
     if bare_ctype in ("application/x-www-form-urlencoded",
                       "multipart/form-data"):
         env = {
             "CONTENT_LENGTH": length,
             "CONTENT_TYPE": ctype,
             "REQUEST_METHOD": "POST"
         }
         cgi_args = cgi.parse(self.rfile,
                              environ=env,
                              keep_blank_values=True)
     else:
         cgi_args = {None: [self.rfile.read(int(length))]}
     self.is_head = False
     self._do_req2(self.path, cgi_args)
예제 #3
0
    def __init__(self, request, response, script_name):
        """
        Expects two parameters;

        Parameters::
         - `request`: The `request` object your view receives.
         - `response`: An instance of `Httpresponse`.
        """
        self.django_request = request
        self.env = request.META
        self._response = response
        # Remove the prefix so HG will think it's running on its own.
        self.env['SCRIPT_NAME'] = script_name 
        self.env['PATH_INFO'] = self.env['PATH_INFO'].replace(self.env['SCRIPT_NAME'], "", 1)

        # Make sure there's a content-length.
        if not self.env.has_key('CONTENT_LENGTH'):
            self.env['CONTENT_LENGTH'] = 0

        self.err = self.env['wsgi.errors']
        self.inp = self.env['wsgi.input']
        self.headers = [ ]
        self.out = [ ]

        self.form = cgi.parse(self.inp, self.env, keep_blank_values=1)
예제 #4
0
			def treat(self):
				# Format path
				from urlparse import urlparse, parse_qs
				url = urlparse(self.path)
				path = url.path[1:] # Remove the starting slash
				try:
					method = methods["%s_%s" % (self.command, path)]
				except KeyError:
					self.send_error(404, '%s not found' % self.path)
					return
				# args = parse_qs(url.query)
				env = {"REQUEST_METHOD": self.command, "QUERY_STRING": url.query, 
					"CONTENT_LENGTH": self.headers.get('Content-Length', -1),
					"CONTENT_TYPE": self.headers.get('Content-Type', None) }
				parsed = cgi.parse(self.rfile, env)
				print >> sys.stderr, "Parsed: %s, %s" % (str(parsed), str(self.headers))
				args = {}
				for (k, v) in parsed.iteritems():
					print >> sys.stderr, "Found %s=%s" % (k, v)
					args[k] = v[0]
				if args.has_key('token'):
					# Check the authentication token
					try:
						t = tokens[args['token']]
						args['token'] = t
					except KeyError:
						self.send_error(403, 'The authentication token is invalid')
						return
				try:
					r = method(**args)
				except HttpException, e:
					self.send_response(e.code, e.message)
예제 #5
0
def pyro_app(environ, start_response):
    """
    The WSGI app function that is used to process the requests.
    You can stick this into a wsgi server of your choice, or use the main() method
    to use the default wsgiref server.
    """

    config.SERIALIZER = "json"  # we only talk json through the http proxy
    config.COMMTIMEOUT = pyro_app.comm_timeout
    method = environ.get("REQUEST_METHOD")
    path = environ.get('PATH_INFO', '').lstrip('/')

    if not path:
        return redirect(start_response, "/pyro/")

    if path.startswith("pyro/"):
        if method in ("GET", "POST", "OPTIONS"):
            parameters = singlyfy_parameters(
                cgi.parse(environ['wsgi.input'], environ))
            return process_pyro_request(environ, path[5:], parameters,
                                        start_response)
        else:
            return invalid_request(start_response)

    return not_found(start_response)
예제 #6
0
    def __init__(self, request, response, script_name):
        """
        Expects two parameters;

        Parameters::
         - `request`: The `request` object your view receives.
         - `response`: An instance of `Httpresponse`.
        """
        self.django_request = request
        self.env = request.META
        self._response = response
        # Remove the prefix so HG will think it's running on its own.
        self.env['SCRIPT_NAME'] = script_name
        self.env['PATH_INFO'] = self.env['PATH_INFO'].replace(
            self.env['SCRIPT_NAME'], "", 1)

        # Make sure there's a content-length.
        if not self.env.has_key('CONTENT_LENGTH'):
            self.env['CONTENT_LENGTH'] = 0

        self.err = self.env['wsgi.errors']
        self.inp = self.env['wsgi.input']
        self.headers = []
        self.out = []

        self.form = cgi.parse(self.inp, self.env, keep_blank_values=1)
예제 #7
0
def read_cgi():
    """TODO"""
    received = cgi.parse()
    final_dictionary = {}
    for ok_key in form_keys:
        if received.has_key(ok_key):
            final_dictionary[ok_key] = received[ok_key][0]
    return final_dictionary
예제 #8
0
파일: account.py 프로젝트: shaunix/blip
def output_account_login (response, **kw):
    data = cgi.parse ()
    for key in data.keys():
        data[key] = pulse.utils.utf8dec (data[key][0])
    username = data.get ('username', u'')
    password = data.get ('password', u'')
    admon = None
    if username != u'' and password != u'':
        account = pulse.db.Account.get (username)
        try:
            if account is None:
                raise pulse.utils.PulseException()
            if account.check_type == 'new':
                admon = pulse.html.AdmonBox (pulse.html.AdmonBox.error,
                                             pulse.utils.gettext('You have not yet verified your email address'))
                raise pulse.utils.PulseException()
            if account.password != crypt.crypt (password, 'pu'):
                raise pulse.utils.PulseException()
            token = pulse.utils.get_token ()
            login = pulse.db.Login.set_login (account, token, os.getenv ('REMOTE_ADDR'))
            response.redirect (pulse.config.web_root + 'home')
            response.set_cookie ('pulse_auth', token)
        except:
            pulse.db.rollback (pulse.db.Account)
            if admon == None:
                admon = pulse.html.AdmonBox (pulse.html.AdmonBox.error,
                                             pulse.utils.gettext('Invalid username or password'))
        else:
            pulse.db.flush (pulse.db.Account)
            pulse.db.commit (pulse.db.Account)
            return
        
    page = pulse.html.Page (url=(pulse.config.web_root + 'account/login'))
    page.set_title (pulse.utils.gettext ('Log In'))
    response.set_contents (page)

    if admon != None:
        page.add_content (admon)

    form = pulse.html.Form ('POST', pulse.config.web_root + 'account/login')
    page.add_content (form)

    table = pulse.html.Table ()
    form.add_content (table)

    table.add_row (
        pulse.utils.gettext ('Username:'******'username') )
    table.add_row (
        pulse.utils.gettext ('Password:'******'password', password=True) )
    span = pulse.html.Span ()
    span.add_content (pulse.html.SubmitButton ('login', 'Log In'))
    span.add_content (pulse.utils.gettext (' or '))
    span.add_content (pulse.html.Link (pulse.config.web_root + 'account/new',
                                      pulse.utils.gettext ('create an account')))
    table.add_row ('', span)
예제 #9
0
파일: am.py 프로젝트: dgilman/atom_maker
def page():
   args = cgi.parse()
   flush = False

   print "Content-Type: application/atom+xml;charset=UTF-8"
   print ""
   if "flush" in args:
      flush = True
   print feed_cache(args, flush)
예제 #10
0
def getCGIOptions():
    
    odict = cgi.parse()
    args = []
    
    if not odict.has_key("e"):
        raise UsageError.UsageError("No experiment specified")
    odict["e"] = odict["e"][0]
    
    return (odict, args)
 def do_POST(self):
     ctype, pdict = parse_header(self.headers.getheader('content-type'))
     if ctype == 'multipart/form-data':
         postvars = parse_multipart(self.rfile, pdict)
     elif ctype == 'application/x-www-form-urlencoded':
         length = int(self.headers.getheader('content-length'))
         postvars = parse(self.rfile.read(length), keep_blank_values=1)
     else:
         postvars = {}
     return
예제 #12
0
def submit():
    form = cgi.parse()
    if 'pkg' not in form:
        error('Invalid Form')
    pkg = form['pkg'][0]
    try:
        r = urllib2.urlopen('http://pypi.python.org/simple/'+pkg)
    except urllib2.HTTPError, e:
        if e.code == 404:
            error("The package %s does not exist. Please verify the package name" % pkg)
예제 #13
0
def getCGIOptions():
    
    odict = cgi.parse()
    args = []
    
    for opt in ["e", "c", "n", "p", "s3"]:
        if odict.has_key(opt):
            odict[opt] = odict[opt][0]
    
    return (odict, args)
예제 #14
0
파일: queryParam.py 프로젝트: weijia/ufs
 def getGetFieldStorage(self):
     '''
     Only get the fields sent in URL
     '''
     if self.httpFieldData is None:
         #print 'environment:',os.environ.get('QUERY_STRING','')
         s = StringIO.StringIO('')
         self.httpFieldData = cgi.parse(s)
         #print 'first return:', self.httpFieldData
         self.getDataFlag = True
     return self.httpFieldData
예제 #15
0
    def _get_post_data(self):
        ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))
        if ctype == 'multipart/form-data':
            postvars = cgi.parse_multipart(self.rfile, pdict)
        elif ctype == 'application/x-www-form-urlencoded':
            length = int(self.headers.getheader('content-length'))
            postvars = cgi.parse(self.rfile.read(length), keep_blank_values=1)
        else:
            postvars = {}

        return postvars
예제 #16
0
 def handle_request(self, msg):
     hid = (msg.host, msg.port)
     if msg.host == 'feelinsonice-hrd.appspot.com' and msg.path == '/bq/upload':
         env = {}
         env['REQUEST_METHOD'] = msg.method
         env['CONTENT_TYPE'] = msg.get_content_type()
         env['CONTENT_LENGTH'] = len(msg.content)
         c = cgi.parse(environ=env, fp=StringIO(msg.content))
         if c.has_key('username'):
             print 'Upload from %s' % c['username'][0]
             self.process_snapchat(c['data'][0])
     msg.reply()
예제 #17
0
파일: util.py 프로젝트: lcrees/wsgiauth
def extract(environ, empty=False, err=False):
    '''Extracts strings in form data and returns a dict.

    @param environ WSGI environ
    @param empty Stops on empty fields (default: Fault)
    @param err Stops on errors in fields (default: Fault)
    '''
    formdata = cgi.parse(environ['wsgi.input'], environ, empty, err)    
    # Remove single entries from lists
    for key, value in formdata.iteritems():
        if len(value) == 1: formdata[key] = value[0]
    return formdata
예제 #18
0
파일: wsgi.py 프로젝트: zart/sashok-crawler
def request_torrents(environment):
    if debug.local_run():
        return open('pull_torrents', 'rb').read()
    else:
        import cgi
        query = cgi.parse(None, environment)
        if 'num_days' in query.keys() and 'offset' in query.keys():
            from pull_torrents import pull_torrents
            return pull_torrents(int(query['num_days'][0]), int(query['offset'][0])).encode('utf-8')
        else:
            # fix me
            return '{"0":[{"title":"Failed to pull torrents from the database, somehow."}]}'.encode('utf-8')
예제 #19
0
def extract(environ, empty=False, err=False):
    """Extracts strings in form data and returns a dict.

    :param environ: WSGI environ
    :param empty: Stops on empty fields (default: Fault)
    :param err: Stops on errors in fields (default: Fault)
    """
    formdata = cgi.parse(environ['wsgi.input'], environ, empty, err)
    # Remove single entries from lists
    for key, value in iter(formdata.items()):
        if len(value) == 1:
            formdata[key] = value[0]
    return formdata
예제 #20
0
파일: httputil.py 프로젝트: HaToHo/pysaml2
def extract(environ, empty=False, err=False):
    """Extracts strings in form data and returns a dict.

    :param environ: WSGI environ
    :param empty: Stops on empty fields (default: Fault)
    :param err: Stops on errors in fields (default: Fault)
    """
    formdata = cgi.parse(environ['wsgi.input'], environ, empty, err)
    # Remove single entries from lists
    for key, value in iter(formdata.items()):
        if len(value) == 1:
            formdata[key] = value[0]
    return formdata
예제 #21
0
    def process(self, environ, startResponse):
        if self.processorIsShared:
            processor = self.processor
        else:
            processor = self.createTreeProcessor()

        uri = environ.get("PATH_INFO")
        if uri and uri.startswith("/"):
            uri = uri[1:]

        params = dict([(k, v[0])
            for k, v in cgi.parse(environ.get("wsgi.input"), environ, keep_blank_values=True, strict_parsing=False).items()])

        req = HttpRequest(uri, params)
        req.formEncoding = self.params.get("form-encoding")
        req.method = environ.get("REQUEST_METHOD")

        env = Environment(req, environ=environ)
        env.changeContext("", self.contextPath)

        try:
            if processor.process(env):
                responseHeaders = []
                if env.contentType:
                    responseHeaders.append(("content-type", env.contentType))
                if not env.response.exceptionAware and env.response.status / 100 not in [2, 3]:
                    raise Exception("Exception not processed by sitemap: HTTP %d\n%s" % (env.response.status, env.response.body))
                if env.response.status in self.httpStatusCodes:
                    message = self.httpStatusCodes[env.response.status]
                else:
                    message = self.httpStatusCodes.get(env.response.status / 100, "Unknows Status Message")
                status = "%d %s" % (env.response.status, message)
                self.logStatusInfo(environ, env.response.status)
                if env.response.status / 100 == 5:
                    self.logInternalError(status, environ, env.response.body)
                if env.response.body:
                    responseHeaders.append(("content-length", str(len(env.response.body))))
                responseHeaders += env.response.headers
                startResponse(status, responseHeaders)
                if env.response.body: return [env.response.body]
                else: return []
            else:
                raise Exception("Sitemap is returned False, but no exception was raised")
        except ResourceNotFoundException, e:
            processor.log.error(e.args[0])
            status = "404 Not Found"
            response = [status]
            response.append('\n\nResource "%(uri)s" not found. Reported by built-in error handler' % self.getRequestInfo(environ))
            self.logStatusInfo(environ, 404)
            startResponse(status, [("content-type", "text/plain")])
            return response
예제 #22
0
 def __init__(self, wsgienv, start_response):
     version = wsgienv["wsgi.version"]
     if (version < (1, 0)) or (version >= (2, 0)):
         raise RuntimeError("Unknown and unsupported WSGI version %d.%d" % version)
     self.inp = wsgienv["wsgi.input"]
     self.err = wsgienv["wsgi.errors"]
     self.threaded = wsgienv["wsgi.multithread"]
     self.multiprocess = wsgienv["wsgi.multiprocess"]
     self.run_once = wsgienv["wsgi.run_once"]
     self.env = wsgienv
     self.form = normalize(cgi.parse(self.inp, self.env, keep_blank_values=1))
     self._start_response = start_response
     self.server_write = None
     self.headers = []
예제 #23
0
파일: request.py 프로젝트: mitrandir77/eden
 def __init__(self, wsgienv, start_response):
     version = wsgienv[r"wsgi.version"]
     if (version < (1, 0)) or (version >= (2, 0)):
         raise RuntimeError("Unknown and unsupported WSGI version %d.%d" % version)
     self.inp = wsgienv[r"wsgi.input"]
     self.err = wsgienv[r"wsgi.errors"]
     self.threaded = wsgienv[r"wsgi.multithread"]
     self.multiprocess = wsgienv[r"wsgi.multiprocess"]
     self.run_once = wsgienv[r"wsgi.run_once"]
     self.env = wsgienv
     self.form = normalize(cgi.parse(self.inp, self.env, keep_blank_values=1))
     self._start_response = start_response
     self.server_write = None
     self.headers = []
예제 #24
0
def main():
    sort = ""
    term = ""

    # Try to fetch query from URI
    try:
        query = os.environ["REQUEST_URI"]
        pos = string.find(query, "/pub/")
        if pos >= 0:
            query = query[pos + 5:]
        pos = string.find(query, "?")
        if pos >= 0:
            sort = query[pos + 1:]
            query = query[:pos]
            if sort[:3] == "by=":
                sort = sort[3:]
        term = query
    except:
        pass

    # Now try the QUERY_STRING
    try:
        query = os.environ["QUERY_STRING_UNESCAPED"]
        if query[:3] == "by=":
            query = query[3:]
            while query[:1] not in ['&', '']:
                sort = sort + query[:1]
                query = query[1:]
        if query[:1] == '&':
            query = query[1:]
        if query[:4] == "get=":
            term = query[4:]
    except:
        try:
            dict = cgi.parse()
            if "get" in dict.keys():
                term = dict["get"][0]
            if "by" in dict.keys():
                sort = dict["by"][0]
        except:
            pass

    if term == "" or term[-1] == '/':
        print_list(term, sort)
    else:
        base = get_base_dir()
        if term[:len(base)] != base:
            term = base + term
        extract_file(term)
예제 #25
0
    def answer_query(self):
        """
            answer data query by parsing the request, 
            handing it to runquery() and sending the
            json-encoded data back.
        """
        length = int(self.headers['content-length'])
        quer = self.rfile.read(length)
        self.quer = parse(quer)
        self.log_message("""post data is: %s""" % str(self.quer))
        self.send_response(200)
        #self.send_header('Content-type','text/html')
        self.send_header('Content-type', 'application/json')
        self.end_headers()

        j.dump(self.runquery(), self.wfile)
예제 #26
0
 def answer_query(self):
     """
         answer data query by parsing the request, 
         handing it to runquery() and sending the
         json-encoded data back.
     """
     length= int( self.headers['content-length'] )
     quer=self.rfile.read( length )
     self.quer=parse(quer)
     self.log_message("""post data is: %s"""%str(self.quer))
     self.send_response(200)
     #self.send_header('Content-type','text/html')
     self.send_header('Content-type','application/json')
     self.end_headers()
     
     j.dump(self.runquery(),self.wfile)
예제 #27
0
    def parse_env(self):
        """Converts environment variables to instance attributes"""
        env = self.env

        self.accept_charset = env.get('HTTP_ACCEPT_CHARSET', '')
        self.accept_encoding = env.get('HTTP_ACCEPT_ENCODING', '')
        self.accept_language = env.get('HTTP_ACCEPT_LANGUAGE', '')
        self.host = env.get('HTTP_HOST', '')
        self.user_agent = env.get('HTTP_USER_AGENT', '')

        self.remote_addr = env.get('REMOTE_ADDR', '')
        self.request_uri = env.get('REQUEST_URI', '')
        self.script_name = env.get('SCRIPT_NAME', '')

        import cgi
        self.query = dict(cgi.parse(self.file, self.env))
예제 #28
0
    def do_request(self, environ=os.environ):
        #print('Content-Type: text/html')
        #print()
        #for (key, value) in sorted(environ.items()):
        #    print(key, value)

        reqtype = environ['REQUEST_METHOD']
        scheme = environ['REQUEST_SCHEME']
        servername = environ['SERVER_NAME']
        path = environ['REQUEST_URI']
        uri = urllib.parse.urlunsplit((scheme, servername, path, '', ''))
        postvars = cgi.parse(environ=environ)

        headers = {}
        for (key, value) in environ.items():
            if key.startswith('HTTP_'):
                name = key[5:].lower().replace('_', '-')
                headers[name] = value

        request = nerve.Request(self,
                                None,
                                reqtype,
                                uri,
                                postvars,
                                headers=headers)
        controller = self.make_controller(request)
        controller.handle_request(request)

        redirect = controller.get_redirect()
        error = controller.get_error()
        headers = controller.get_headers()
        mimetype = controller.get_mimetype()
        output = controller.get_output()

        if redirect:
            self.send_content(302, mimetype, output,
                              [('Location', redirect)] + headers)
        elif error:
            if type(error) == nerve.users.UserPermissionsRequired:
                self.send_401(str(error))
            else:
                self.send_content(
                    404 if type(error) is nerve.NotFoundError else 500,
                    mimetype, output, headers)
        else:
            self.send_content(200, mimetype, output, headers)
        return
예제 #29
0
def do_test(buf, method):
    env = {}
    if method == "GET":
        fp = None
        env["REQUEST_METHOD"] = "GET"
        env["QUERY_STRING"] = buf
    elif method == "POST":
        fp = StringIO(buf)
        env["REQUEST_METHOD"] = "POST"
        env["CONTENT_TYPE"] = "application/x-www-form-urlencoded"
        env["CONTENT_LENGTH"] = str(len(buf))
    else:
        raise ValueError("unknown method: %s" % method)
    try:
        return cgi.parse(fp, env, strict_parsing=1)
    except Exception as err:
        return ComparableException(err)
예제 #30
0
def do_test(buf, method):
    env = {}
    if method == "GET":
        fp = None
        env['REQUEST_METHOD'] = 'GET'
        env['QUERY_STRING'] = buf
    elif method == "POST":
        fp = BytesIO(buf.encode('latin-1'))  # FieldStorage expects bytes
        env['REQUEST_METHOD'] = 'POST'
        env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'
        env['CONTENT_LENGTH'] = str(len(buf))
    else:
        raise ValueError("unknown method: %s" % method)
    try:
        return cgi.parse(fp, env, strict_parsing=1)
    except Exception as err:
        return ComparableException(err)
예제 #31
0
파일: main.py 프로젝트: eniac111/scaicha
def run_CGI(s):
    args = cgi.parse()
    
    username = args['name'][0]
    if not username:
        raise RuntimeError, 'no username specified'
    else:
        s.set_username(username)

    if 'period' in args:
        s.set_period(args['period'][0])
    
    if 'ignore' in args:
        s.set_ignore_tags(split_ignore_tags(args['ignore'][0]))

    if 'join' in args:
        s.set_combine_tags(split_combine_tags(args['join'][0]))
    
    if 'minTagPerc' in args:
        s.set_min_tag_perc(float(args['minTagPerc'][0]))
    
    if 'colorScheme' in args:
        s.set_color_scheme(args['colorScheme'][0])
    
    if 'baseColor' in args:
        s.set_base_color(args['baseColor'][0])
    
    if 'lighten' in args:
        s.set_color_lighten_fac(float(args['lighten'][0]))

    if 'size' in args:
        s.set_size(args['size'][0])
    
    if 'score' in args:
        s.set_score()

    if DEV \
       or os.path.exists(s.get_filename()) == False \
       or (time.time() - os.path.getmtime(s.get_filename())) > cache_time \
       or os.path.getsize(s.get_filename()) == 0:
        s.run()

    image = open(s.get_filename(), 'r')
    print 'Content-Type: image/png\r\n'
    print image.read()
    image.close()
예제 #32
0
def do_test(buf, method):
    env = {}
    if method == "GET":
        fp = None
        env['REQUEST_METHOD'] = 'GET'
        env['QUERY_STRING'] = buf
    elif method == "POST":
        fp = BytesIO(buf.encode('latin-1')) # FieldStorage expects bytes
        env['REQUEST_METHOD'] = 'POST'
        env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'
        env['CONTENT_LENGTH'] = str(len(buf))
    else:
        raise ValueError("unknown method: %s" % method)
    try:
        return cgi.parse(fp, env, strict_parsing=1)
    except Exception as err:
        return ComparableException(err)
예제 #33
0
def do_test(buf, method):
    env = {}
    if method == "GET":
        fp = None
        env['REQUEST_METHOD'] = 'GET'
        env['QUERY_STRING'] = buf
    elif method == "POST":
        fp = StringIO(buf)
        env['REQUEST_METHOD'] = 'POST'
        env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'
        env['CONTENT_LENGTH'] = str(len(buf))
    else:
        raise ValueError, "unknown method: %s" % method
    try:
        return cgi.parse(fp, env, strict_parsing=1)
    except StandardError, err:
        return ComparableException(err)
예제 #34
0
파일: http_util.py 프로젝트: zack53/pyoidc
def extract(environ, empty=False, err=False):
    """
    Extract strings in form data and returns a dict.

    :param environ: WSGI environ
    :param empty: Stops on empty fields (default: Fault)
    :param err: Stops on errors in fields (default: Fault)
    """
    warnings.warn("This function is deprecated.", DeprecationWarning)
    formdata = cgi.parse(environ["wsgi.input"], environ, empty, err)
    # Remove single entries from lists
    new_formdata = {}  # type: Dict[str, Union[str, List[str]]]
    for key, value in formdata.items():
        if len(value) == 1:
            new_formdata[key] = value[0]
        else:
            new_formdata[key] = value
    return new_formdata
예제 #35
0
def pyro_app(environ, start_response):
    """
    The WSGI app function that is used to process the requests.
    You can stick this into a wsgi server of your choice, or use the main() method
    to use the default wsgiref server.
    """
    Pyro4.config.SERIALIZER = "json"     # we only talk json through the http proxy
    Pyro4.config.COMMTIMEOUT = pyro_app.comm_timeout
    method = environ.get("REQUEST_METHOD")
    path = environ.get('PATH_INFO', '').lstrip('/')
    if not path:
        return redirect(start_response, "/pyro/")
    if path.startswith("pyro/"):
        if method in ("GET", "POST"):
            parameters = singlyfy_parameters(cgi.parse(environ['wsgi.input'], environ))
            return process_pyro_request(environ, path[5:], parameters, start_response)
        else:
            return invalid_request(start_response)
    return not_found(start_response)
예제 #36
0
def formparse(env):
    '''Extracts data from form submissions.

    @param environ Environment dictionary
    @param strict Stops on errors (default: False)
    '''
    winput = env['wsgi.input']
    # Non-destructively retrieve string
    if hasattr(winput, 'getvalue'):
        tinput = winput.getvalue()
    # Recreate wsgi.input as fallback
    else:
        tinput = winput.read()
        env['wsgi.input'] = StringIO(tinput)
    # Parse form submission
    qdict = cgi.parse(fp=StringIO(tinput), environ=env)
    # Remove invididual entries from list and store as naked string
    for key, value in qdict.iteritems():
        if len(value) == 1: qdict[key] = value[0]
    return qdict
예제 #37
0
파일: queryParam.py 프로젝트: weijia/ufs
 def getAllFieldStorage(self):
     '''
     Get the fields in URL and POST
     '''
     #print 'getAllFieldStorage called'
     self.getPostData()
     if self.httpFieldData is None:
         s = StringIO.StringIO(self.httpPostData)
         self.httpFieldData = cgi.parse(s)
         #print 'first return:', self.httpFieldData
         #The following is not needed as the parse function will automatically include query string
         #s = StringIO.StringIO(os.environ.get('QUERY_STRING',''))
         #self.httpFieldData = cgi.parse(s)
         #print 'second return:',self.httpFieldData
         for i in self.httpFieldData:
             r = []
             for j in self.httpFieldData[i]:
                 r.append(decode(j))
             self.unicodeFieldData[i.decode(encodingTools.getPageEncoding())] = r
         self.postDataFlag = True
     return self.httpFieldData
예제 #38
0
파일: web.py 프로젝트: shaunix/blinq
    def __init__ (self, **kw):
        self.http = kw.pop ('http', True)
        self.path_info = kw.pop ('path_info', None)
        self.query_string = kw.pop ('query_string', None)
        self.stdin = kw.pop ('stdin', sys.stdin)
        cookies = kw.pop('http_cookie', None)

        super (WebRequest, self).__init__(**kw)

        if self.path_info is None:
            self.path_info = self.getenv ('PATH_INFO')
        if self.query_string is None:
            self.query_string = self.getenv ('QUERY_STRING')
        if cookies is None:
            cookies = self.getenv('HTTP_COOKIE') or ''

        self.path = []
        if self.path_info is not None:
            path = blinq.utils.utf8dec (self.path_info).split ('/')
            for part in path:
                if part != '':
                    self.path.append (part)

        self.post_data = {}
        if self.getenv('REQUEST_METHOD') == 'POST':
            environ = self.environ.copy()
            environ.pop('QUERY_STRING')
            data = cgi.parse(fp=self.stdin, environ=environ)
            for key in data.keys():
                self.post_data[key] = blinq.utils.utf8dec(data[key][0])

        self.query = {}
        if self.query_string is not None:
            query = cgi.parse_qs (self.query_string, True)
            for key in query.keys():
                self.query[key] = blinq.utils.utf8dec (query[key][0])

        self.cookies = Cookie.SimpleCookie ()
        self.cookies.load (cookies)
예제 #39
0
파일: misc.py 프로젝트: rbe/dmerce
  def processForm(self):

    try:
      # Make instance of MISC
      m = MISC()

      # Check REQUEST_METHOD: GET
      if m.env('REQUEST_METHOD') == 'GET':
        # Parse QUERY_STRING
        qs = cgi.parse_qs(m.env('QUERY_STRING'))

      # Check REQUEST_METHOD: POST
      elif m.env('REQUEST_METHOD') == 'POST':
        # Parse sys.stdin
        qs = cgi.parse()

      # If no error occured
      return qs, '', ''

    # Any error
    except:
      return {}, sys.exc_info()[0], sys.exc_info()[1]
예제 #40
0
파일: cgi.py 프로젝트: transistorfet/nerve
    def do_request(self, environ=os.environ):
        #print('Content-Type: text/html')
        #print()
        #for (key, value) in sorted(environ.items()):
        #    print(key, value)

        reqtype = environ['REQUEST_METHOD']
        scheme = environ['REQUEST_SCHEME']
        servername = environ['SERVER_NAME']
        path = environ['REQUEST_URI']
        uri = urllib.parse.urlunsplit( (scheme, servername, path, '', '') )
        postvars = cgi.parse(environ=environ)

        headers = { }
        for (key, value) in environ.items():
            if key.startswith('HTTP_'):
                name = key[5:].lower().replace('_', '-')
                headers[name] = value

        request = nerve.Request(self, None, reqtype, uri, postvars, headers=headers)
        controller = self.make_controller(request)
        controller.handle_request(request)

        redirect = controller.get_redirect()
        error = controller.get_error()
        headers = controller.get_headers()
        mimetype = controller.get_mimetype()
        output = controller.get_output()

        if redirect:
            self.send_content(302, mimetype, output, [ ('Location', redirect) ] + headers)
        elif error:
            if type(error) == nerve.users.UserPermissionsRequired:
                self.send_401(str(error))
            else:
                self.send_content(404 if type(error) is nerve.NotFoundError else 500, mimetype, output, headers)
        else:
            self.send_content(200, mimetype, output, headers)
        return
예제 #41
0
def getCGIOptions():
    
    odict = cgi.parse()
    args = []
    
    if int(odict.get("s3", [0])[0]):
        odict["s3"] = True
    else:
        odict["s3"] = False
    
    if int(odict.get("tile-mode", [0])[0]):
        odict["tile-mode"] = True
    else:
        odict["tile-mode"] = False
    
    if int(odict.get("reflect-mode", [0])[0]):
        odict["reflect-mode"] = True
    else:
        odict["reflect-mode"] = False
    
    if int(odict.get("grid-mode", [0])[0]):
        odict["grid-mode"] = True
    else:
        odict["grid-mode"] = False
    
    if int(odict.get("no-op", [0])[0]):
        odict["no-op"] = True
    else:
        odict["no-op"] = False

    if int(odict.get("debug", [0])[0]):
        odict["debug"] = True
    else:
        odict["debug"] = False

    return (odict, args)
예제 #42
0
#!/usr/bin/python
''' Python testing file

'''
import platform

print 'Content-type: text/html\n\n'
print 'Hello from python %s<br>' % platform.python_version()

try:
    import _mysql
    print 'Got MySql, woo!'
except Exception:
    print 'No MySql :('

print '<p>__name__ = %s</p>' % __name__

try:
    import os
    envs = ['%s = %s' % (k, v) for k, v in os.environ.iteritems()]
    print '<br>'.join(envs)

    import cgi
    form = cgi.parse()
    print '<p>%s</p>' % form

except Exception, e:
    print '%s' % e
예제 #43
0
def main():
    # DIR_OF_THIS_SCRIPT = p.abspath(p.dirname(__file__))
    # config_path = p.join(DIR_OF_THIS_SCRIPT, '.config.json')
    config_path = p.expanduser('~/.config/waterwave_ddm/config.json')
    try:
        with open(config_path, 'r') as config_file:
            config: dict = json.load(config_file)
    except FileNotFoundError:
        print('Status: 500 Server Error')
        print()
        print('No config file')
        return
    cgitb.enable(display=0, logdir=config.get('log_path', p.expanduser('~/.log/waterwave_ddm.log')))
    ddm_data_map: dict = config['data_map']
    default_interval = config.get('default_interval', 200)
    default_max_ti = config.get('default_max_ti', 50)
    default_angular_bins = config.get('default_angular_bins', 18)
    default_radial_bin_size = config.get('default_radial_bin_size', 2)

    params = cgi.parse()
    dataid = get_cgi_param(params, 'dataid')
    data_path: str = ddm_data_map.get(dataid)
    if data_path is None:
        print('Status: 404 Not Found')
        print()
        print('Data not found')
        return
    interval = get_cgi_param(params, 'interval', default_interval, int)
    max_ti = get_cgi_param(params, 'max_ti', default_max_ti, int)
    angular_bins = get_cgi_param(params, 'angular_bins', default_angular_bins, int)
    radial_bin_size = get_cgi_param(params, 'radial_bin_size', default_radial_bin_size, int)
    ai = get_cgi_param(params, 'angle', None, int)
    ri = get_cgi_param(params, 'radius', None, int)
    if ai is None and ri is not None:
        rai = ri
        mode = 'a'
    elif ai is not None and ri is None:
        rai = ai
        mode = 'r'
    else:
        print('Status: 400 Bad Request')
        print()
        print('Please provide either engle or radius')
        return

    ddm_array = np.load(data_path)
    result, median_angle, median_radius, average_angle, average_radius = \
        map_to_polar(ddm_array, angular_bins, radial_bin_size, ddm_array.shape[1] - 1)
    animation, fig, _, _, _ = \
        ddm_polar_inspection_animation(mode, rai, average_angle, average_radius, result, max_ti, interval)
    angular_bins = result.shape[0]
    radial_bins = result.shape[1]

    html_viewer = animation.to_jshtml(default_mode='loop')
    print('Content-Type: text/html')
    print()
    print('<p>Polar ddm shape: {}</p>'.format(result.shape))
    print('<p>After applying the binning setting this data set has {} angle and {} radius values available</p>'
          .format(angular_bins, radial_bins))
    if mode == 'a':
        print('<p>You are viewing angular distribution of this data at median radius = {} varying over lag time</p>'
              .format(median_radius[ri]))
    else:
        print('<p>You are viewing radial distribution of this data at median angle = {} varying over lag time</p>'
              .format(median_angle[ai]))
    print(html_viewer)
예제 #44
0
#tifile.close()

if __name__ == '__main__':
    root_dir = GlobalConfig.ROOT_DIR

    sys.stderr = open("%s/delete_error.txt" % GlobalConfig.DEBUG_DIR, 'w')
    sys.stdout = open("%s/delete_output.txt" % GlobalConfig.DEBUG_DIR, 'w')

    fields = cgi.FieldStorage()
    utils.printToServer('Content-type: text/json\n\n')
    print 'fields: ', fields

    if not fields:
        donor = sys.argv[1]
        query_name = sys.argv[2]
        removeQuery(donor, query_name, delete=True)
    else:
        fields = cgi.parse()
        #utils.printToServer('<html><body><textarea>')
        #try :
        (status, message) = removeQuery(fields["project"][0],
                                        fields["donor"][0],
                                        fields["query_name"][0],
                                        delete=True)
        utils.printToServer('{"status":"%s", "message":"%s"}' %
                            (status, message))
        #except Exception :
        #utils.printToServer( '{"status":"error", "message":"Something went wrong, check the logs"}' )

        #utils.printToServer('</textarea></body></html>')
예제 #45
0
파일: evalssf.py 프로젝트: snoopyjc/ssf
#!/home/jorost/venv/bin/python
from ssf import SSF
import cgi
import cgitb
import json
#import base64
from urllib.parse import quote
cgitb.enable()
#cgi.test()
cgi.parse()
form = cgi.FieldStorage()
ssf = SSF(color_pre="<span style='color: #{rgb};'>", color_post="</span>")
locale = form.getfirst('locale', default=None)
if locale == 'None':
    locale = None
getfmt = form.getfirst('getfmt', default=None)
if getfmt is not None:
    places = None
    thousands_sep = None
    negative = None
    positive_sign_exponent = False
    for key in form.keys():
        if 'places' in key:
            places = form.getfirst(key, default=None)
            if places is not None and places.isdigit():
                places = int(places)
        elif 'thousands' in key:
            thousands_sep = True
        elif 'negative' in key:
            negative = form.getfirst(key, default=None)
        elif 'positive' in key:
예제 #46
0
파일: getip.py 프로젝트: TonisPiip/lino
print "Content-Type: text/plain"
print  # blank line, end of headers
# print "<TITLE>getip.py</TITLE>"
# print "<body>"
# print "<H1>This is my first CGI script</H1>"
# print "Hello, world!"

#~ cgi.print_environ_usage()
#~ cgi.print_environ()
# cgi.test()

f = file('/var/log/getip/getip.log', 'w')

#form = cgi.FieldStorage()
now = datetime.datetime.now()
q = cgi.parse()
# print repr(q)
#name = form['name'].getvalue()
name = q['name'][0]
if name:
    msg = "%s - %s IP address is %s" % (now, name,
                                        os.environ.get('REMOTE_ADDR', None))
    f.write(msg)
    # print msg
    print os.environ.get('REMOTE_ADDR', None)
else:
    f.write("%s - invalid request:\n" % now)
    for kv in os.environ.items():
        f.write("  %s = %s\n" % kv)
    print "Sorry"
예제 #47
0
def application(environ, startResponse):
    _l = []
    w = _l.append

    args = cgi.parse(environ=environ)
    #print('GOT ARGS: %s' % str(args))
    if 'text' in args:
        text = args['text'][0]
    else:
        text = None

    w('<html>')
    w('<body>')
    w('<h2>Analyzer</h2>')
    if text is None:
        text = 'the dog runs quickly and barks'

    w('<table>')
    w('<tr>')
    w('<td valign=top>')
    w('<form method=GET action="/tokenize.py">')
    w('<textarea name="terms" cols=50 rows=10>')
    if text is not None:
        w(text)
    w('</textarea>')
    w('<br>')
    w('<input type=submit name=cmd value="Tokenize!">')
    w('</form>')
    w('</td>')
    w('<td valign=top>')
    w('<ul>')
    w('</ul>')
    w('</tr>')
    w('</table>')

    if text is not None:

        l = terms.split()

        p = subprocess.Popen([
            'java', '-cp',
            '%s:%s' %
            (localconstants.STAGE_TOKENIZER_PATH, localconstants.LUCENE_JAR),
            'StageTokenizer'
        ] + l,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        result, err = p.communicate()
        if p.returncode != 0:
            w('<br>')
            w('Sorry, StageTokenizer failed:<br>')
            w('<pre>%s</pre>' % err.decode('utf-8'))
        else:
            #print('got dot: %s' % dotString.decode('ascii'))
            p = subprocess.Popen(['dot', '-Tpng'],
                                 stdin=subprocess.PIPE,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
            pngData, err = p.communicate(result)
            if p.returncode != 0:
                w('<br>')
                w('Sorry, dot failed:<br>')
                w('<pre>%s</pre>' % err.decode('utf-8'))
            else:
                w('<br><br>')
                w('<img src="data:image/png;base64,%s">' %
                  base64.b64encode(pngData).decode('ascii'))
    w('</body>')
    w('</html>')

    html = ''.join(_l)

    headers = []
    headers.append(('Content-Type', 'text/html'))
    headers.append(('Content-Length', str(len(html))))

    startResponse('200 OK', headers)
    return [html.encode('utf-8')]
예제 #48
0
#!C:\Users\rolim\AppData\Local\Programs\Python\Python37-32\python.exe
#Formulários insertar
#CGi

import cgi #importante pare html

def printHeader():#escopo do cabeçalho
    print("Content-type: text/html")
    print()
    print("<html>")
    print("<head><title>Forms whit CGI Python - GET -</title></head>")
    print("<body>")

def printFooter():
    print("</body></html>")

printHeader()

print("<h2>Método post em video</h2>")

print("<form method='POST' action='aula22.Ex2.py'><p><input type='radio' name='rblSex' value='Male'>Male<br><input type='radio' name='rblSex' value='Famale'>Famale<br><input type='submit' value='Submit'/></p></form>")

pairs = cgi.parse()

if "rblSex" in pairs:
    print("<p><h2>Your sex is: %s</h2></p>" % (cgi.escape( pairs ["rblSex"][0] )))

printFooter()
예제 #49
0
    else:
        title = articleName
    sock.close()

    return {
        'date': date,
        'year': year,
        'mainSubject': mainSubject,
        'subSubject': subSubject,
        'title': title
    }


print "Content-Type: text/xml"
print
article_url = cgi.parse()['url'][0]
url = URL_PREFIX + article_url
tags = tag_Detect(url)
result = u"""<?xml version="1.0" encoding="UTF-8" ?>
<result xmlns="http://opencorpora.org/chaskorNewsParsingResult">
    <year>%s</year>
    <date>%s</date>
    <mainSubject>%s</mainSubject>
    <subSubject>%s</subSubject>
    <title>%s</title>
    <url>%s</url>
</result>""" % \
        (tags["year"], tags["date"], tags["mainSubject"],
         tags["subSubject"], tags["title"], url)
print result.encode('utf-8')
예제 #50
0
 def getParameters(self):
     return cgi.parse(keep_blank_values=True);
예제 #51
0
from test_support import verify, verbose
예제 #52
0
def init(traceback=False):
    global params
    if traceback:
        cgitb.enable()
    params = cgi.parse()
예제 #53
0
파일: sapi.py 프로젝트: nabuzir/viewvc
 def params(self):
   return cgi.parse()
예제 #54
0
파일: sapi.py 프로젝트: nabuzir/viewvc
 def params(self):
   return cgi.parse(environ=self._environ, fp=self._environ["wsgi.input"])
예제 #55
0
import cgi #, cgitb; cgitb.enable(logdir='/tmp/quickprint')
import MySQLdb
from ipplib import IPPRequest
import ipplib

from tempfile import mkstemp
from shutil import move

authfail = False
try:
    printer_uri = 'http://%s%s' % (os.environ['SERVER_NAME'], os.environ['REQUEST_URI'])
except:
    pass
try:
    argv = cgi.parse(os.environ['QUERY_STRING'])
    webauth = argv['BASIC']
    if type(webauth) is list:
        webauth = webauth[0]
    webauth = webauth.split(' ')[1]
    if not len(webauth):
        authfail = True
    else:
        (authu, authp) = webauth.decode('base64').split(':')
        db=MySQLdb.connect(read_default_file="/mit/quickprint/.my.cnf")
        c = db.cursor()
        c.execute("SELECT 1 FROM auth WHERE auser=%s AND apass=%s LIMIT 1", (authu,authp,))
        if c.fetchone() is None:
            authfail = True
except Exception, e:
    authfail = True
예제 #56
0
 def getGET():
   """
    _GET vars
    @return Dict
   """
   return cgi.parse()
예제 #57
0
        'host': remote_host
    })
    return state


def check_csrf_state(tbl, remote_host, returned_state):
    r = tbl.remove({'_id': returned_state, 'host': remote_host})
    if r and r['ok'] and r.get('n', 0) >= 1: return True
    return False


if __name__ == "__main__":
    if (not SpinConfig.config.get('secure_mode', False)):
        cgitb.enable()

    args = cgi.parse() or {}
    remote_addr = os.getenv('REMOTE_ADDR') or 'local'
    MY_DOMAIN = SpinConfig.config[
        'spin_token_domain']  # domain used for cookie
    time_now = int(time.time())
    url_parts = urlparse.urlparse(os.getenv('REQUEST_URI'))
    path = url_parts.path.split('/')
    if not path[0]: path = path[1:]
    if not path[-1]: path = path[:-1]
    assert len(path) == 1
    assert path[0] == 'AUTH'

    my_endpoint = 'https://' + SpinConfig.config['proxyserver'][
        'external_listen_host'] + ':' + str(
            SpinConfig.config['proxyserver']['external_ssl_port']) + '/AUTH'
예제 #58
0
#!/usr/bin/env python

from yattag import Doc
from yattag import indent
import cgi
import os
import subprocess

query = cgi.parse()

OPENVPN_PATH = "/etc/openvpn/"
OPENVPN_SETUP_SCRIPT = os.getcwd() + "/openvpn_setup"

def set_server(server):
    command = "sudo %s %s" % (OPENVPN_SETUP_SCRIPT, OPENVPN_PATH + server)
    try:
        return subprocess.Popen(command, shell=True, stdout=subprocess.PIPE).stdout.read()
    except:
        return "Failed"

# get current server
try:
    out = subprocess.check_output(['pgrep', '-af', 'openvpn'])
    config_path = (out.split("\n")[0]).split("--config ")[1]
    config_file = config_path.split("/")
    current_server = config_file[-1]
    doc, tag, text = Doc(
        defaults = {'server': current_server}
    ).tagtext()
except:
    current_server = 'none'
예제 #59
0
    def do_POST(self):
        print("path: ", self.path)
        host = self.headers.get("Host")

        if not host:
            self.wfile.write(
                "<h1> Error, requested page not found </h1>".encode("utf-8"))
        elif host.count('.') <= 1:
            self._set_response()
            self.wfile.write(
                file_get_contents("./signup.html").encode("utf-8"))
        else:
            username = host.split('.')[-3]
            print('Request =>', username)
            user = get_online_user(username)
            if user:
                full_request = {}
                headers = {}
                params = {}
                print(str(type(self.headers)))
                for k, v in self.headers.items():
                    headers[k] = v
                full_request["headers"] = headers
                full_request["path"] = self.path
                full_request["method"] = "POST"

                ctype, pdict = cgi.parse_header(
                    self.headers.get('content-type'))
                if ctype == 'multipart/form-data':
                    params = cgi.parse_multipart(self.rfile, pdict)
                elif ctype == 'application/x-www-form-urlencoded':
                    length = int(self.headers.get('content-length'))
                    params = cgi.parse(self.rfile.read(length))
                full_request["params"] = params
                rid = secrets.token_hex()
                full_request["id"] = rid
                full_request_json = json.dumps({
                    "type": "request",
                    "data": full_request
                })
                try:
                    asyncio.run(user.ws.send(full_request_json))
                    now = datetime.datetime.now()
                    while True:
                        if response_dict.get(rid):
                            break
                        if (datetime.datetime.now() - now).seconds > 6:
                            raise Exception("Not responding")

                    self.send_response(response_dict[rid]["code"])
                    for head, value in response_dict[rid]["headers"].items():
                        self.send_header(head, value)
                    self.end_headers()

                    self.wfile.write(
                        base64.b64decode(
                            response_dict[rid]["content"].encode("ascii")))
                    del response_dict[rid]

                except Exception as e:
                    print(str(type(e)) + " " + str(e))
                    self._set_response()
                    self.wfile.write(
                        f"<h1> There is a problem in {user.username} </h1>".
                        encode("utf-8"))

            else:
                self._set_response()
                self.wfile.write(
                    "<h1> Error, requested server not found </h1>".encode(
                        "utf-8"))