PyAMF Pylons Question

View: New views
4 Messages — Rating Filter:   Alert me  

PyAMF Pylons Question

by snorkel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
Does anyone know if it is possible to tab into the request object and the
pylons global object?

I want to use the dbutils connection pool and be able to grab the IP of the
client connecting to the gateway.

Thanks,

--

Tony
_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

Re: PyAMF Pylons Question

by Nick Joyce :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

If you add expose_request=True to the gateway object, then all calls  
to service methods will have the request object as the first argument.

Hth,

Nick

On 28 May 2009, at 03:51, Tony Caduto wrote:

> Hi,
> Does anyone know if it is possible to tab into the request object  
> and the
> pylons global object?
>
> I want to use the dbutils connection pool and be able to grab the IP  
> of the
> client connecting to the gateway.
>
> Thanks,
>
> --
>
> Tony
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

Re: PyAMF Pylons Question

by snorkel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Nick Joyce wrote:

> Hi,
>
> If you add expose_request=True to the gateway object, then all calls
> to service methods will have the request object as the first argument.
>
> Hth,
>
> Nick
>
> On 28 May 2009, at 03:51, Tony Caduto wrote:
>

Hi Nick,

I tried the code below, but it errors out.
It does not like the request.environ part.

(<type 'exceptions.AttributeError'>, AttributeError("'dict' object has
no attrib
ute 'environ'",), <traceback object at 0x03806468>)

from flex_gateway.lib import helpers as h

def login(request,username,password):
    try:
        remote_addr = request.environ["REMOTE_ADDR"]
        return username,password,remote_addr
    except:
        print sys.exc_info()
 

def echo(data):
   # echo data back to the client
   return data

def sum(a, b):
    return a + b

def scramble(text):
    from random import shuffle
    s = [x for x in text]
    shuffle(s)
    return ''.join(s)


services = {
    'services.echo': echo,
    'services.sum': sum,
    'services.scramble': scramble,
    'services.login':login
}
GatewayController = h.WSGIGateway(services,expose_request=True)
_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users

Re: PyAMF Pylons Question

by Nick Joyce :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Anthony,

Since you are using WSGIGateway, the request object is the environ  
object, so your login function becomes:

def login(request, username,password):
   try:
       remote_addr = request["REMOTE_ADDR"]
       return username,password,remote_addr
   except:
       print sys.exc_info()

Hope that makes sense.

Cheers,

Nick

On 28 May 2009, at 16:06, Anthony Caduto wrote:

> Nick Joyce wrote:
>> Hi,
>>
>> If you add expose_request=True to the gateway object, then all  
>> calls to service methods will have the request object as the first  
>> argument.
>>
>> Hth,
>>
>> Nick
>>
>> On 28 May 2009, at 03:51, Tony Caduto wrote:
>>
>
> Hi Nick,
>
> I tried the code below, but it errors out.
> It does not like the request.environ part.
>
> (<type 'exceptions.AttributeError'>, AttributeError("'dict' object  
> has no attrib
> ute 'environ'",), <traceback object at 0x03806468>)
>
> from flex_gateway.lib import helpers as h
>
> def login(request,username,password):
>   try:
>       remote_addr = request.environ["REMOTE_ADDR"]
>       return username,password,remote_addr
>   except:
>       print sys.exc_info()
>
> def echo(data):
>  # echo data back to the client
>  return data
>
> def sum(a, b):
>   return a + b
>
> def scramble(text):
>   from random import shuffle
>   s = [x for x in text]
>   shuffle(s)
>   return ''.join(s)
>
>
> services = {
>   'services.echo': echo,
>   'services.sum': sum,
>   'services.scramble': scramble,
>   'services.login':login
> }
> GatewayController = h.WSGIGateway(services,expose_request=True)
> _______________________________________________
> PyAMF users mailing list - users@...
> http://lists.pyamf.org/mailman/listinfo/users

_______________________________________________
PyAMF users mailing list - users@...
http://lists.pyamf.org/mailman/listinfo/users