forked from ros/ros_comm
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for ros#610: Added python-requests which provides a clean http li…
…brary for HTTP/1.1 requests
- Loading branch information
Showing
14 changed files
with
102 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -*- coding: utf-8 -*- | ||
"""A replacement transport for Python xmlrpc library.""" | ||
|
||
try: | ||
import xmlrpc.client as xmlrpc | ||
except ImportError: | ||
import xmlrpclib as xmlrpc | ||
|
||
import requests | ||
|
||
|
||
class RequestsTransport(xmlrpc.Transport): | ||
"""Drop in Transport for xmlrpclib that uses Requests instead of httplib""" | ||
|
||
user_agent = "Python XMLRPC with Requests (python-requests.org)" | ||
|
||
def __init__(self, scheme, use_datetime=0): | ||
xmlrpc.Transport.__init__(self, use_datetime) | ||
self._scheme = scheme | ||
|
||
def request(self, host, handler, request_body, verbose=0): | ||
"""Make a xmlrpc request.""" | ||
headers = {'User-Agent': self.user_agent, 'Content-Type': 'text/xml'} | ||
url = '{scheme}://{host}{handler}'.format(scheme=self._scheme, | ||
host=host, | ||
handler=handler) | ||
try: | ||
resp = requests.post(url, data=request_body, headers=headers) | ||
except (ValueError, Exception): | ||
raise | ||
else: | ||
try: | ||
resp.raise_for_status() | ||
except requests.RequestException as exc: | ||
raise xmlrpc.ProtocolError(url, resp.status_code, | ||
str(exc), resp.headers) | ||
else: | ||
return self.parse_response(resp) | ||
|
||
def parse_response(self, resp): | ||
""" | ||
Parse the xmlrpc response. | ||
""" | ||
p, u = self.getparser() | ||
p.feed(resp.text) | ||
p.close() | ||
return u.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters