Converts a dict of components to the format expected by the Google Maps server. For example: c = {"country": "US", "postal_code": "94043"} convert.components(c) # 'country:US|postal_code:94043' :param arg: The component filter. :type arg: dict :rtype: basestring
(arg)
| 206 | |
| 207 | |
| 208 | def components(arg): |
| 209 | """Converts a dict of components to the format expected by the Google Maps |
| 210 | server. |
| 211 | |
| 212 | For example: |
| 213 | c = {"country": "US", "postal_code": "94043"} |
| 214 | convert.components(c) |
| 215 | # 'country:US|postal_code:94043' |
| 216 | |
| 217 | :param arg: The component filter. |
| 218 | :type arg: dict |
| 219 | |
| 220 | :rtype: basestring |
| 221 | """ |
| 222 | |
| 223 | # Components may have multiple values per type, here we |
| 224 | # expand them into individual key/value items, eg: |
| 225 | # {"country": ["US", "AU"], "foo": 1} -> "country:AU", "country:US", "foo:1" |
| 226 | def expand(arg): |
| 227 | for k, v in arg.items(): |
| 228 | for item in as_list(v): |
| 229 | yield "%s:%s" % (k, item) |
| 230 | |
| 231 | if isinstance(arg, dict): |
| 232 | return "|".join(sorted(expand(arg))) |
| 233 | |
| 234 | raise TypeError( |
| 235 | "Expected a dict for components, " |
| 236 | "but got %s" % type(arg).__name__) |
| 237 | |
| 238 | |
| 239 | def bounds(arg): |