summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/server/xmlrpc.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2013-06-14 16:22:51 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-06-14 17:26:30 +0100
commit441c699acbb4b443c705933c1fccee0d906a1262 (patch)
tree63816b0140acf3052a1b673ecd8d2400f3a528b3 /bitbake/lib/bb/server/xmlrpc.py
parent6c058341f9b0bee6af2554d897a2623a2ea9a479 (diff)
downloadpoky-441c699acbb4b443c705933c1fccee0d906a1262.tar.gz
bitbake: compat/server/utils: Jettison pre python 2.7.3 workarounds
Now we've moved to require python 2.7.3, we can jettison the compatibility workarounds/hacks for older python versions. (Bitbake rev: a51c402304f2080a76720f9b31d6dfdbed393bba) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/server/xmlrpc.py')
-rw-r--r--bitbake/lib/bb/server/xmlrpc.py104
1 files changed, 11 insertions, 93 deletions
diff --git a/bitbake/lib/bb/server/xmlrpc.py b/bitbake/lib/bb/server/xmlrpc.py
index 359d5adb67..5045e55ae2 100644
--- a/bitbake/lib/bb/server/xmlrpc.py
+++ b/bitbake/lib/bb/server/xmlrpc.py
@@ -51,100 +51,18 @@ import inspect, select
51 51
52from . import BitBakeBaseServer, BitBakeBaseServerConnection, BaseImplServer 52from . import BitBakeBaseServer, BitBakeBaseServerConnection, BaseImplServer
53 53
54if sys.hexversion < 0x020600F0: 54class BBTransport(xmlrpclib.Transport):
55 print("Sorry, python 2.6 or later is required for bitbake's XMLRPC mode") 55 def __init__(self):
56 sys.exit(1) 56 self.connection_token = None
57 57 xmlrpclib.Transport.__init__(self)
58##
59# The xmlrpclib.Transport class has undergone various changes in Python 2.7
60# which break BitBake's XMLRPC implementation.
61# To work around this we subclass Transport and have a copy/paste of method
62# implementations from Python 2.6.6's xmlrpclib.
63#
64# Upstream Python bug is #8194 (http://bugs.python.org/issue8194)
65# This bug is relevant for Python 2.7.0 and 2.7.1 but was fixed for
66# Python > 2.7.2
67#
68# To implement a simple form of client control, we use a special transport
69# that adds a HTTP header field ("Bitbake-token") to ensure that a server
70# can communicate with only a client at a given time (the client must use
71# the same token).
72##
73if (2, 7, 0) <= sys.version_info < (2, 7, 2):
74 class BBTransport(xmlrpclib.Transport):
75 def __init__(self):
76 self.connection_token = None
77 xmlrpclib.Transport.__init__(self)
78
79 def request(self, host, handler, request_body, verbose=0):
80 h = self.make_connection(host)
81 if verbose:
82 h.set_debuglevel(1)
83
84 self.send_request(h, handler, request_body)
85 self.send_host(h, host)
86 self.send_user_agent(h)
87 if self.connection_token:
88 h.putheader("Bitbake-token", self.connection_token)
89 self.send_content(h, request_body)
90
91 errcode, errmsg, headers = h.getreply()
92
93 if errcode != 200:
94 raise ProtocolError(
95 host + handler,
96 errcode, errmsg,
97 headers
98 )
99
100 self.verbose = verbose
101 58
102 try: 59 def set_connection_token(self, token):
103 sock = h._conn.sock 60 self.connection_token = token
104 except AttributeError: 61
105 sock = None 62 def send_content(self, h, body):
106 63 if self.connection_token:
107 return self._parse_response(h.getfile(), sock) 64 h.putheader("Bitbake-token", self.connection_token)
108 65 xmlrpclib.Transport.send_content(self, h, body)
109 def make_connection(self, host):
110 import httplib
111 host, extra_headers, x509 = self.get_host_info(host)
112 return httplib.HTTP(host)
113
114 def _parse_response(self, file, sock):
115 p, u = self.getparser()
116
117 while 1:
118 if sock:
119 response = sock.recv(1024)
120 else:
121 response = file.read(1024)
122 if not response:
123 break
124 if self.verbose:
125 print("body:", repr(response))
126 p.feed(response)
127
128 file.close()
129 p.close()
130
131 return u.close()
132
133 def set_connection_token(self, token):
134 self.connection_token = token
135else:
136 class BBTransport(xmlrpclib.Transport):
137 def __init__(self):
138 self.connection_token = None
139 xmlrpclib.Transport.__init__(self)
140
141 def set_connection_token(self, token):
142 self.connection_token = token
143
144 def send_content(self, h, body):
145 if self.connection_token:
146 h.putheader("Bitbake-token", self.connection_token)
147 xmlrpclib.Transport.send_content(self, h, body)
148 66
149def _create_server(host, port): 67def _create_server(host, port):
150 t = BBTransport() 68 t = BBTransport()