Annotation of /linden_release/linden/indra/lib/python/indra/ipc/llsdhttp.py
Parent Directory
|
Revision Log
Revision 100 - (view) (download) (as text)
| 1 : | mjm | 57 | """\ |
| 2 : | @file llsdhttp.py | ||
| 3 : | @brief Functions to ease moving llsd over http | ||
| 4 : | |||
| 5 : | $LicenseInfo:firstyear=2006&license=mit$ | ||
| 6 : | |||
| 7 : | mjm | 100 | Copyright (c) 2006-2009, Linden Research, Inc. |
| 8 : | mjm | 57 | |
| 9 : | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 10 : | of this software and associated documentation files (the "Software"), to deal | ||
| 11 : | in the Software without restriction, including without limitation the rights | ||
| 12 : | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 13 : | copies of the Software, and to permit persons to whom the Software is | ||
| 14 : | furnished to do so, subject to the following conditions: | ||
| 15 : | |||
| 16 : | The above copyright notice and this permission notice shall be included in | ||
| 17 : | all copies or substantial portions of the Software. | ||
| 18 : | |||
| 19 : | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 20 : | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 21 : | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 22 : | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 23 : | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 24 : | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| 25 : | THE SOFTWARE. | ||
| 26 : | $/LicenseInfo$ | ||
| 27 : | """ | ||
| 28 : | |||
| 29 : | import os.path | ||
| 30 : | import os | ||
| 31 : | import urlparse | ||
| 32 : | |||
| 33 : | from indra.base import llsd | ||
| 34 : | |||
| 35 : | from eventlet import httpc | ||
| 36 : | |||
| 37 : | suite = httpc.HttpSuite(llsd.format_xml, llsd.parse, 'application/llsd+xml') | ||
| 38 : | delete = suite.delete | ||
| 39 : | delete_ = suite.delete_ | ||
| 40 : | get = suite.get | ||
| 41 : | get_ = suite.get_ | ||
| 42 : | head = suite.head | ||
| 43 : | head_ = suite.head_ | ||
| 44 : | post = suite.post | ||
| 45 : | post_ = suite.post_ | ||
| 46 : | put = suite.put | ||
| 47 : | put_ = suite.put_ | ||
| 48 : | request = suite.request | ||
| 49 : | request_ = suite.request_ | ||
| 50 : | |||
| 51 : | # import every httpc error exception into our namespace for convenience | ||
| 52 : | for x in httpc.status_to_error_map.itervalues(): | ||
| 53 : | globals()[x.__name__] = x | ||
| 54 : | mjm | 100 | ConnectionError = httpc.ConnectionError |
| 55 : | Retriable = httpc.Retriable | ||
| 56 : | mjm | 57 | |
| 57 : | for x in (httpc.ConnectionError,): | ||
| 58 : | globals()[x.__name__] = x | ||
| 59 : | |||
| 60 : | |||
| 61 : | def postFile(url, filename): | ||
| 62 : | f = open(filename) | ||
| 63 : | body = f.read() | ||
| 64 : | f.close() | ||
| 65 : | llsd_body = llsd.parse(body) | ||
| 66 : | return post_(url, llsd_body) | ||
| 67 : | |||
| 68 : | |||
| 69 : | # deprecated in favor of get_ | ||
| 70 : | def getStatus(url, use_proxy=False): | ||
| 71 : | status, _headers, _body = get_(url, use_proxy=use_proxy) | ||
| 72 : | return status | ||
| 73 : | |||
| 74 : | # deprecated in favor of put_ | ||
| 75 : | def putStatus(url, data): | ||
| 76 : | status, _headers, _body = put_(url, data) | ||
| 77 : | return status | ||
| 78 : | |||
| 79 : | # deprecated in favor of delete_ | ||
| 80 : | def deleteStatus(url): | ||
| 81 : | status, _headers, _body = delete_(url) | ||
| 82 : | return status | ||
| 83 : | |||
| 84 : | # deprecated in favor of post_ | ||
| 85 : | def postStatus(url, data): | ||
| 86 : | status, _headers, _body = post_(url, data) | ||
| 87 : | return status | ||
| 88 : | |||
| 89 : | |||
| 90 : | def postFileStatus(url, filename): | ||
| 91 : | status, _headers, body = postFile(url, filename) | ||
| 92 : | return status, body | ||
| 93 : | |||
| 94 : | |||
| 95 : | def getFromSimulator(path, use_proxy=False): | ||
| 96 : | return get('http://' + simulatorHostAndPort + path, use_proxy=use_proxy) | ||
| 97 : | |||
| 98 : | |||
| 99 : | def postToSimulator(path, data=None): | ||
| 100 : | return post('http://' + simulatorHostAndPort + path, data) |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

