I'm working on https://jira.secondlife.com/browse/SVC-2682, and wanted
to execute the exact urllib commands from the python command line in
order to repro it, but couldn't figure out from these changes where all
the network code went. Where is the actual library code that's sending
the request?
Tess
Christian Scholz wrote:
Hi!
Right now we use the networking layer like this:
client = getUtility(IRESTClient)
client.GET(url)
client.POST(url, data)
After a discussion with Locklainn if his UDPClient shouldn't rather be
a connection and store it's socket inside the instance instead of
passing it I was wondering if the same shouldn't be true for the REST
client.
So instead writing it like this:
resource = IRESTResource(url)
resource.GET()
resource.POST(data)
(headers are in both cases optional parameters to the call)
This would have the following benefits:
- it models more what REST is about (you call a method on a resource)
- it models how Capabilities in pyogp are used already (they also have
POST() and GET() methods and the capability basically is the resource).
How the resource get's instantiated in the above example is by using
an adapter which adapts to a string (the url) for the IRESTResource
interface. A factory utility maybe would be a different way of doing it:
factory = getUtility(IRESTResourceFactory)
resource = factory(url)
The first solution might be more flexible though if you want to
instantiate a resource from something different than a string as in
your client code you do not need to care. In the second case though if
the url is not a string but some sort of object with an interface you
would need to also change the getUtility call and use some
IRESTResourceFromAnotherObjectFactory.
But what do you think of the general idea? I think it would make usage
of resources and caps similar and you'd only need to learn once how
you do GET and POST and the cap would be more or less a wrapper around
the resource.
-- Christian
PS: Of course this means changing of code but it's pretty clear how to
do that and it might show if all our tests really notice such changes.
And we should try to refactor things where possible IMHO. Merciless
refactoring FTW! :-)
_______________________________________________
Click here to unsubscribe or manage your list subscription:
https://lists.secondlife.com/cgi-bin/mailman/listinfo/pyogp