diff options
author | Joshua Lock <josh@linux.intel.com> | 2010-12-01 14:40:21 +0000 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2010-12-07 12:51:59 +0000 |
commit | b9617bf6e15fe75f850fe5644eea4b7f04eed792 (patch) | |
tree | 9073766b2f9d6874808cd8ca1d17e410b86d1b43 /bitbake/lib/bb/server | |
parent | 84384aa8a9b052a4740fd266694ecb4990b6edf5 (diff) | |
download | poky-b9617bf6e15fe75f850fe5644eea4b7f04eed792.tar.gz |
bitbake/xmlrpc: Modify xmlrpc server to work with Python 2.7
Python 2.7's library changes some of xmlrpclib's internal implementation such
that interacting with a proxy to BitBakes SimpleXMLRPCServer would cause
BitBake to crash.
The issue was traced to changes in the xmlrpclib.Transport implementation and
Python bug #8194 (http://bugs.python.org/issue8194).
This patch introduces a workaround by create a subclass of
xmlrpclib.Transport, which overrides the offending methods with the Python
2.6.6 implementation copy and pasted from the Python 2.6.6 xmlrpclib, and
using this BBTransport implementation for both xmlrpclib.Server objects we
create.
Signed-off-by: Joshua Lock <josh@linux.intel.com>
Diffstat (limited to 'bitbake/lib/bb/server')
-rw-r--r-- | bitbake/lib/bb/server/xmlrpc.py | 68 |
1 files changed, 66 insertions, 2 deletions
diff --git a/bitbake/lib/bb/server/xmlrpc.py b/bitbake/lib/bb/server/xmlrpc.py index 5d3cc3e106..c2bfe12176 100644 --- a/bitbake/lib/bb/server/xmlrpc.py +++ b/bitbake/lib/bb/server/xmlrpc.py | |||
@@ -45,6 +45,68 @@ if sys.hexversion < 0x020600F0: | |||
45 | print("Sorry, python 2.6 or later is required for bitbake's XMLRPC mode") | 45 | print("Sorry, python 2.6 or later is required for bitbake's XMLRPC mode") |
46 | sys.exit(1) | 46 | sys.exit(1) |
47 | 47 | ||
48 | ## | ||
49 | # The xmlrpclib.Transport class has undergone various changes in Python 2.7 | ||
50 | # which break BitBake's XMLRPC implementation. | ||
51 | # To work around this we subclass Transport and have a copy/paste of method | ||
52 | # implementations from Python 2.6.6's xmlrpclib. | ||
53 | # | ||
54 | # Upstream Python bug is #8194 (http://bugs.python.org/issue8194) | ||
55 | ## | ||
56 | |||
57 | class BBTransport(xmlrpclib.Transport): | ||
58 | def request(self, host, handler, request_body, verbose=0): | ||
59 | h = self.make_connection(host) | ||
60 | if verbose: | ||
61 | h.set_debuglevel(1) | ||
62 | |||
63 | self.send_request(h, handler, request_body) | ||
64 | self.send_host(h, host) | ||
65 | self.send_user_agent(h) | ||
66 | self.send_content(h, request_body) | ||
67 | |||
68 | errcode, errmsg, headers = h.getreply() | ||
69 | |||
70 | if errcode != 200: | ||
71 | raise ProtocolError( | ||
72 | host + handler, | ||
73 | errcode, errmsg, | ||
74 | headers | ||
75 | ) | ||
76 | |||
77 | self.verbose = verbose | ||
78 | |||
79 | try: | ||
80 | sock = h._conn.sock | ||
81 | except AttributeError: | ||
82 | sock = None | ||
83 | |||
84 | return self._parse_response(h.getfile(), sock) | ||
85 | |||
86 | def make_connection(self, host): | ||
87 | import httplib | ||
88 | host, extra_headers, x509 = self.get_host_info(host) | ||
89 | return httplib.HTTP(host) | ||
90 | |||
91 | def _parse_response(self, file, sock): | ||
92 | p, u = self.getparser() | ||
93 | |||
94 | while 1: | ||
95 | if sock: | ||
96 | response = sock.recv(1024) | ||
97 | else: | ||
98 | response = file.read(1024) | ||
99 | if not response: | ||
100 | break | ||
101 | if self.verbose: | ||
102 | print "body:", repr(response) | ||
103 | p.feed(response) | ||
104 | |||
105 | file.close() | ||
106 | p.close() | ||
107 | |||
108 | return u.close() | ||
109 | |||
48 | class BitBakeServerCommands(): | 110 | class BitBakeServerCommands(): |
49 | def __init__(self, server, cooker): | 111 | def __init__(self, server, cooker): |
50 | self.cooker = cooker | 112 | self.cooker = cooker |
@@ -54,7 +116,8 @@ class BitBakeServerCommands(): | |||
54 | """ | 116 | """ |
55 | Register a remote UI Event Handler | 117 | Register a remote UI Event Handler |
56 | """ | 118 | """ |
57 | s = xmlrpclib.Server("http://%s:%d" % (host, port), allow_none=True) | 119 | t = BBTransport() |
120 | s = xmlrpclib.Server("http://%s:%d/" % (host, port), transport=t, allow_none=True) | ||
58 | return bb.event.register_UIHhandler(s) | 121 | return bb.event.register_UIHhandler(s) |
59 | 122 | ||
60 | def unregisterEventHandler(self, handlerNum): | 123 | def unregisterEventHandler(self, handlerNum): |
@@ -177,7 +240,8 @@ class BitbakeUILauch(): | |||
177 | 240 | ||
178 | class BitBakeServerConnection(): | 241 | class BitBakeServerConnection(): |
179 | def __init__(self, serverinfo): | 242 | def __init__(self, serverinfo): |
180 | self.connection = xmlrpclib.Server("http://%s:%s" % (serverinfo.host, serverinfo.port), allow_none=True) | 243 | t = BBTransport() |
244 | self.connection = xmlrpclib.Server("http://%s:%s" % (serverinfo.host, serverinfo.port), transport=t, allow_none=True) | ||
181 | self.events = uievent.BBUIEventQueue(self.connection) | 245 | self.events = uievent.BBUIEventQueue(self.connection) |
182 | 246 | ||
183 | def terminate(self): | 247 | def terminate(self): |