def data():
    """Returns the data sent with the request."""
    if 'data' not in ctx:
        cl = intget(ctx.env.get('CONTENT_LENGTH'), 0)
        ctx.data = ctx.env['wsgi.input'].read(cl)
    
    return ctx.data
Ejemplo n.º 2
0
def runwsgi(func):
    """
    Runs a WSGI-compatible `func` using FCGI, SCGI, or a simple web server,
    as appropriate based on context and `sys.argv`.
    """

    if os.environ.has_key('SERVER_SOFTWARE'):  # cgi
        os.environ['FCGI_FORCE_CGI'] = 'Y'

    if (os.environ.has_key('PHP_FCGI_CHILDREN')  #lighttpd fastcgi
            or os.environ.has_key('SERVER_SOFTWARE')):
        return runfcgi(func, None)

    if 'fcgi' in sys.argv or 'fastcgi' in sys.argv:
        args = sys.argv[1:]
        if 'fastcgi' in args: args.remove('fastcgi')
        elif 'fcgi' in args: args.remove('fcgi')
        if args:
            return runfcgi(func, validaddr(args[0]))
        else:
            return runfcgi(func, None)

    if 'scgi' in sys.argv:
        args = sys.argv[1:]
        args.remove('scgi')
        if args:
            return runscgi(func, validaddr(args[0]))
        else:
            return runscgi(func)

    server_addr = validip(listget(sys.argv, 1, ''))
    if os.environ.has_key('PORT'):  # e.g. Heroku
        server_addr = ('0.0.0.0', intget(os.environ['PORT']))

    return httpserver.runsimple(func, server_addr)
Ejemplo n.º 3
0
def runwsgi(func):
    """
    Runs a WSGI-compatible `func` using FCGI, SCGI, or a simple web server,
    as appropriate based on context and `sys.argv`.
    """
    print func
    server_addr = validip(listget(sys.argv, 1, ''))
    if os.environ.has_key('PORT'):
        server_addr = ('0.0.0.0', intget(os.environ['PORT']))
    return httpserver.runsimple(func, server_addr)
Ejemplo n.º 4
0
    def object(self):
        """
        by default this requires key_name to look up object
        If id is provided in url kwargs, it MUST be an integer/long
        """
        key_name = self.kwargs.get('key_name')
        id = self.kwargs.get('id')

        obj = None
        if key_name is not None:
            obj = self.model.get_by_key_name(key_name)
        elif id is not None:
            obj = self.model.get_by_id(intget(id, -1))
        else:
            raise ImproperlyConfigured(
                u'Generic detail view %s must have a url parameter of '
                u'either key_name or id.' % self.__class__.__name__)

        if obj:
            return obj
        else:
            self.abort(404, 'Requested object not found')
Ejemplo n.º 5
0
def runwsgi(func):
    """
    Runs a WSGI-compatible `func` using FCGI, SCGI, or a simple web server,
    as appropriate based on context and `sys.argv`.
    """
    # get args from os.environ & sys.argv to init server
    if os.environ.has_key('SERVER_SOFTWARE'):  # cgi
        os.environ['FCGI_FORCE_CGI'] = 'Y'

    if (os.environ.has_key('PHP_FCGI_CHILDREN')  #lighttpd fastcgi
            or os.environ.has_key('SERVER_SOFTWARE')):
        return runfcgi(func, None)

    if 'fcgi' in sys.argv or 'fastcgi' in sys.argv:
        args = sys.argv[1:]
        if 'fastcgi' in args: args.remove('fastcgi')
        elif 'fcgi' in args: args.remove('fcgi')
        if args:
            return runfcgi(func, validaddr(args[0]))
        else:
            return runfcgi(func, None)

    if 'scgi' in sys.argv:
        args = sys.argv[1:]
        args.remove('scgi')
        if args:
            return runscgi(func, validaddr(args[0]))
        else:
            return runscgi(func)

    server_addr = validip(listget(sys.argv, 1, ''))
    if os.environ.has_key('PORT'):  # e.g. Heroku
        server_addr = ('0.0.0.0', intget(os.environ['PORT']))

    # ==================================================================================
    # app.run() => wsgi server starts here
    # func = wsgi_app function = wsgifunc(*middleware) in application.py line 268
    return httpserver.runsimple(func, server_addr)
Ejemplo n.º 6
0
def runwsgi(func):
    """
    Runs a WSGI-compatible `func` using FCGI, SCGI, or a simple web server,
    as appropriate based on context and `sys.argv`.
    """
    
    if os.environ.has_key('SERVER_SOFTWARE'): # cgi
        os.environ['FCGI_FORCE_CGI'] = 'Y'

    if (os.environ.has_key('PHP_FCGI_CHILDREN') #lighttpd fastcgi
      or os.environ.has_key('SERVER_SOFTWARE')):
        return runfcgi(func, None)
    
    if 'fcgi' in sys.argv or 'fastcgi' in sys.argv:
        args = sys.argv[1:]
        if 'fastcgi' in args: args.remove('fastcgi')
        elif 'fcgi' in args: args.remove('fcgi')
        if args:
            return runfcgi(func, validaddr(args[0]))
        else:
            return runfcgi(func, None)
    
    if 'scgi' in sys.argv:
        args = sys.argv[1:]
        args.remove('scgi')
        if args:
            return runscgi(func, validaddr(args[0]))
        else:
            return runscgi(func)
    
    # ('0.0.0.0', 8080)
    server_addr = validip(listget(sys.argv, 1, ''))
    if os.environ.has_key('PORT'): # e.g. Heroku
        server_addr = ('0.0.0.0', intget(os.environ['PORT']))
    
    return httpserver.runsimple(func, server_addr)
Ejemplo n.º 7
0
def data():
    """Returns the data sent with the request."""
    if 'data' not in ctx:
        cl = intget(ctx.env.get('CONTENT_LENGTH'), 0)
        ctx.data = ctx.env['wsgi.input'].read(cl)
    return ctx.data
Ejemplo n.º 8
0
 def test_returns_default_when_val_is_not_integer_and_default_given(self):
     self.assertEqual(0, utils.intget("ABC", 0))
Ejemplo n.º 9
0
 def test_returns_none_when_val_is_not_integer(self):
     self.assertEqual(None, utils.intget("10.32"))
Ejemplo n.º 10
0
 def test_returns_int_val_when_possible(self):
     self.assertEqual(10, utils.intget("10"))
Ejemplo n.º 11
0
def data():
    """Returns the data sent with the request."""
    if "data" not in ctx:
        cl = intget(ctx.env.get("CONTENT_LENGTH"), 0)
        ctx.data = ctx.env["wsgi.input"].read(cl)
    return ctx.data
Ejemplo n.º 12
0
def data():
    if 'data' not in ctx:
        cl = intget(ctx.env.get('CONTENT_LENGTH'), 0)
        ctx.data = ctx.env['wsgi.input'].read(cl)
    return ctx.data