@@ -26,6 +26,7 @@ class BuildbotConnection(Singleton):
26
26
user = ""
27
27
password = ""
28
28
max_request_try = 2
29
+ pre_path = ""
29
30
30
31
def __init__ (self , url = None ):
31
32
if url :
@@ -40,21 +41,22 @@ def connect_to(self, url):
40
41
self .reconnect ()
41
42
42
43
def reconnect (self ):
43
- match = re .match ("(.* )://(.*) " , self .url )
44
+ match = re .match ("(.+ )://([^/]+)(?:/(.+))? " , self .url )
44
45
if match :
45
- protocol , server = match .groups ()
46
+ protocol , server , pre_path = match .groups ()
46
47
if protocol == "http" :
47
48
self .connection = httplib .HTTPConnection (server )
48
49
elif protocol == "https" :
49
50
self .connection = httplib .HTTPSConnection (server )
50
51
else :
51
52
raise BuildbotException ("Request failed - unknown protocol" )
53
+ self .pre_path = pre_path if pre_path else ""
52
54
53
- def _request (self , request_msg , method = "GET" , ** kwagrs ):
55
+ def _request (self , path , method = "GET" , ** kwagrs ):
54
56
if not self .connection :
55
57
raise BuildbotException ("Request failed - connection not initialized" )
56
58
57
- request_msg = urllib .quote (request_msg )
59
+ path = urllib .quote (path )
58
60
59
61
if kwagrs :
60
62
kwagrs = urllib .urlencode (kwagrs )
@@ -66,20 +68,20 @@ def _request(self, request_msg, method="GET", **kwagrs):
66
68
request_try += 1
67
69
r = None
68
70
try :
69
- self .connection .request (method , request_msg , kwagrs , self .headers )
71
+ self .connection .request (method , self . pre_path + path , kwagrs , self .headers )
70
72
r = self .connection .getresponse ()
71
73
72
74
except (socket .error , httplib .CannotSendRequest , httplib .ResponseNotReady ) as e :
73
75
if not request_try < self .max_request_try :
74
- raise BuildbotException ("Request %s failed %s: %s" % (request_msg , "%s.%s" % (e .__module__ , type (e ).__name__ ), e ))
76
+ raise BuildbotException ("Request %s failed %s: %s" % (path , "%s.%s" % (e .__module__ , type (e ).__name__ ), e ))
75
77
else :
76
78
time .sleep (1 )
77
79
self .reconnect ()
78
80
continue
79
81
80
82
if not (200 <= r .status < 400 ):
81
83
if not request_try < self .max_request_try :
82
- raise BuildbotException ("Request %s failed (%s %s)" % (request_msg , r .status , r .reason ))
84
+ raise BuildbotException ("Request %s failed (%s %s)" % (path , r .status , r .reason ))
83
85
else :
84
86
time .sleep (1 )
85
87
self .reconnect ()
0 commit comments