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