PageRenderTime 17ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/lib/python/indra/ipc/llsdhttp.py

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