| 29 | # Note that you can also pass an IP:port (or hostname:port) for 'pid' |
| 30 | # (i.e., you can omit the ID component of the PID, e.g., 'foo@'). |
| 31 | def get(pid, path, query=None): |
| 32 | import urllib2 |
| 33 | |
| 34 | from contextlib import closing |
| 35 | |
| 36 | url = 'http://' + pid[(pid.find('@') + 1):] + path |
| 37 | |
| 38 | if query is not None and len(query) > 0: |
| 39 | url += '?' + '&'.join( |
| 40 | ['%s=%s' % (urllib2.quote(str(key)), urllib2.quote(str(value))) |
| 41 | for (key, value) in query.items()]) |
| 42 | |
| 43 | with closing(urllib2.urlopen(url)) as file: |
| 44 | return file.read() |