llsdhttp.py

Go to the documentation of this file.
00001 """\
00002 @file llsdhttp.py
00003 @brief Functions to ease moving llsd over http
00004  
00005 $LicenseInfo:firstyear=2006&license=mit$
00006 
00007 Copyright (c) 2006-2008, Linden Research, Inc.
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 $/LicenseInfo$
00027 """
00028  
00029 import os.path
00030 import os
00031 import urlparse
00032 
00033 from indra.base import llsd
00034 
00035 from eventlet import httpc
00036 
00037 suite = httpc.HttpSuite(llsd.format_xml, llsd.parse, 'application/llsd+xml')
00038 delete = suite.delete
00039 delete_ = suite.delete_
00040 get = suite.get
00041 get_ = suite.get_
00042 head = suite.head
00043 head_ = suite.head_
00044 post = suite.post
00045 post_ = suite.post_
00046 put = suite.put
00047 put_ = suite.put_
00048 request = suite.request
00049 request_ = suite.request_
00050 
00051 for x in (httpc.ConnectionError, httpc.NotFound, httpc.Forbidden):
00052     globals()[x.__name__] = x
00053 
00054 
00055 def postFile(url, filename):
00056     f = open(filename)
00057     body = f.read()
00058     f.close()
00059     llsd_body = llsd.parse(body)
00060     return post_(url, llsd_body)
00061 
00062 
00063 # deprecated in favor of get_
00064 def getStatus(url, use_proxy=False):
00065     status, _headers, _body = get_(url, use_proxy=use_proxy)
00066     return status
00067 
00068 # deprecated in favor of put_
00069 def putStatus(url, data):
00070     status, _headers, _body = put_(url, data)
00071     return status
00072 
00073 # deprecated in favor of delete_
00074 def deleteStatus(url):
00075     status, _headers, _body = delete_(url)
00076     return status
00077 
00078 # deprecated in favor of post_
00079 def postStatus(url, data):
00080     status, _headers, _body = post_(url, data)
00081     return status
00082 
00083 
00084 def postFileStatus(url, filename):
00085     status, _headers, body = postFile(url, filename)
00086     return status, body
00087 
00088 
00089 def getFromSimulator(path, use_proxy=False):
00090     return get('http://' + simulatorHostAndPort + path, use_proxy=use_proxy)
00091 
00092 
00093 def postToSimulator(path, data=None):
00094     return post('http://' + simulatorHostAndPort + path, data)

Generated on Fri May 16 08:31:53 2008 for SecondLife by  doxygen 1.5.5