[Twisted-Python] AMPBox as an Argument?

Hi,
Apparently AMPBoxes aren't Arguments. However, I kind of want an AMPBox (like an AMPList, but only one).
Use case: my responses have a "location", but a location is composed of several sub-things: place name, country and postal code. {"location": {"placeName": "Krakow", "countryCode": "PL", postalCode: "30-015"}} would be a lot nicer than having those keys in the top level namespace :)
cheers lvh

On Jul 20, 2012, at 1:11 AM, Laurens Van Houtven _@lvh.cc wrote:
Hi,
Apparently AMPBoxes aren't Arguments. However, I kind of want an AMPBox (like an AMPList, but only one).
Use case: my responses have a "location", but a location is composed of several sub-things: place name, country and postal code. {"location": {"placeName": "Krakow", "countryCode": "PL", postalCode: "30-015"}} would be a lot nicer than having those keys in the top level namespace :)
cheers lvh
Seems like an easy enough thing to write. Given that AMPList doesn't use a length prefix (it uses null-key box-termination, just like the rest of the protocol) the representation would be exactly the same. Just add a trivial wrapper that uses AMPList, unpacks its argument, and assert that there's only one of them?
-glyph

Sure, I just ended up doing that.
Would it be worth creating a ticket, or am I seriously the first person to want this?
cheers lvh
On 20 Jul 2012, at 10:35, Glyph wrote:
On Jul 20, 2012, at 1:11 AM, Laurens Van Houtven _@lvh.cc wrote:
Hi,
Apparently AMPBoxes aren't Arguments. However, I kind of want an AMPBox (like an AMPList, but only one).
Use case: my responses have a "location", but a location is composed of several sub-things: place name, country and postal code. {"location": {"placeName": "Krakow", "countryCode": "PL", postalCode: "30-015"}} would be a lot nicer than having those keys in the top level namespace :)
cheers lvh
Seems like an easy enough thing to write. Given that AMPList doesn't use a length prefix (it uses null-key box-termination, just like the rest of the protocol) the representation would be exactly the same. Just add a trivial wrapper that uses AMPList, unpacks its argument, and assert that there's only one of them?
-glyph
Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

On 12:48 pm, _@lvh.cc wrote:
Sure, I just ended up doing that.
Would it be worth creating a ticket, or am I seriously the first person to want this?
Some general dict argument types would be great. The kind represented by AMPList included. Note that once we have this, AMPList can actually be implemented in like ListOf(Dict()) instead of being a special case. This argues against implementing Dict in terms of AMPList, though. ;)
Jean-Paul
cheers lvh
On 20 Jul 2012, at 10:35, Glyph wrote:
On Jul 20, 2012, at 1:11 AM, Laurens Van Houtven _@lvh.cc wrote:
Hi,
Apparently AMPBoxes aren't Arguments. However, I kind of want an AMPBox (like an AMPList, but only one).
Use case: my responses have a "location", but a location is composed of several sub-things: place name, country and postal code. {"location": {"placeName": "Krakow", "countryCode": "PL", postalCode: "30-015"}} would be a lot nicer than having those keys in the top level namespace :)
cheers lvh
Seems like an easy enough thing to write. Given that AMPList doesn't use a length prefix (it uses null-key box-termination, just like the rest of the protocol) the representation would be exactly the same. Just add a trivial wrapper that uses AMPList, unpacks its argument, and assert that there's only one of them?
-glyph
Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

That might be a preferable general case yes :)
For future reference here's the NestedAMPBox I wrote as Glyph suggested:
https://gist.github.com/3263629
cheers lvh
On 24 Jul 2012, at 15:29, exarkun@twistedmatrix.com wrote:
On 12:48 pm, _@lvh.cc wrote:
Sure, I just ended up doing that.
Would it be worth creating a ticket, or am I seriously the first person to want this?
Some general dict argument types would be great. The kind represented by AMPList included. Note that once we have this, AMPList can actually be implemented in like ListOf(Dict()) instead of being a special case. This argues against implementing Dict in terms of AMPList, though. ;)
Jean-Paul
cheers lvh
On 20 Jul 2012, at 10:35, Glyph wrote:
On Jul 20, 2012, at 1:11 AM, Laurens Van Houtven _@lvh.cc wrote:
Hi,
Apparently AMPBoxes aren't Arguments. However, I kind of want an AMPBox (like an AMPList, but only one).
Use case: my responses have a "location", but a location is composed of several sub-things: place name, country and postal code. {"location": {"placeName": "Krakow", "countryCode": "PL", postalCode: "30-015"}} would be a lot nicer than having those keys in the top level namespace :)
cheers lvh
Seems like an easy enough thing to write. Given that AMPList doesn't use a length prefix (it uses null-key box-termination, just like the rest of the protocol) the representation would be exactly the same. Just add a trivial wrapper that uses AMPList, unpacks its argument, and assert that there's only one of them?
-glyph
Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

On Tue, Jul 24, 2012 at 01:29:51PM -0000, exarkun@twistedmatrix.com wrote:
On 12:48 pm, _@lvh.cc wrote:
Sure, I just ended up doing that.
Would it be worth creating a ticket, or am I seriously the first person to want this?
Some general dict argument types would be great. The kind represented by AMPList included. Note that once we have this, AMPList can actually be implemented in like ListOf(Dict()) instead of being a special case. This argues against implementing Dict in terms of AMPList, though. ;)
That sounds really useful.
-E
Jean-Paul
cheers lvh
On 20 Jul 2012, at 10:35, Glyph wrote:
On Jul 20, 2012, at 1:11 AM, Laurens Van Houtven _@lvh.cc wrote:
Hi,
Apparently AMPBoxes aren't Arguments. However, I kind of want an AMPBox (like an AMPList, but only one).
Use case: my responses have a "location", but a location is composed of several sub-things: place name, country and postal code. {"location": {"placeName": "Krakow", "countryCode": "PL", postalCode: "30-015"}} would be a lot nicer than having those keys in the top level namespace :)
cheers lvh
Seems like an easy enough thing to write. Given that AMPList doesn't use a length prefix (it uses null-key box-termination, just like the rest of the protocol) the representation would be exactly the same. Just add a trivial wrapper that uses AMPList, unpacks its argument, and assert that there's only one of them?
-glyph
Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Hi Lauren
On Fri, Jul 20, 2012 at 10:11:17AM +0200, Laurens Van Houtven wrote:
Hi,
Apparently AMPBoxes aren't Arguments. However, I kind of want an AMPBox (like an AMPList, but only one).
Yes it's a pretty common use-case.
Right now you may use an AMPList with a single element. This is perfectly fine. Perhaps a wrapper class that restricts it to a single value would suffice?
It would be easy to commit to Twisted probably.
just a thought
Use case: my responses have a "location", but a location is composed of several sub-things: place name, country and postal code. {"location": {"placeName": "Krakow", "countryCode": "PL", postalCode: "30-015"}} would be a lot nicer than having those keys in the top level namespace :)
I do not necessarily agree. I think namespace prefixing, if well defined, is fine on AMP arguments appearing in the top-level packet. Alternatively the AMPList approach is there.
(JSON in AMP Arguments works pretty well I hear, too).
-- Cheers, -E
cheers lvh
Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
participants (4)
-
Eric P. Mangold
-
exarkun@twistedmatrix.com
-
Glyph
-
Laurens Van Houtven