@@ -70,8 +70,7 @@ def delete(self, uri):
7070
7171 """
7272 LOGGER .debug ("DELETE %s" , uri )
73- return self ._process_response (
74- self .session .delete (uri , timeout = self .timeout ))
73+ return api .Response (self .session .delete (uri , timeout = self .timeout ))
7574
7675 def get (self , uri , timeout = None ):
7776 """Perform a HTTP get
@@ -84,9 +83,9 @@ def get(self, uri, timeout=None):
8483 """
8584 LOGGER .debug ("GET %s" , uri )
8685 try :
87- return self ._process_response (
88- self . session . get ( uri , timeout = timeout or self .timeout ))
89- except (requests .exceptions .ConnectionError ,
86+ return api . Response ( self .session . get (
87+ uri , timeout = timeout or self .timeout ))
88+ except (requests .exceptions .RequestException ,
9089 OSError , socket .error ) as err :
9190 raise exceptions .RequestError (str (err ))
9291
@@ -100,15 +99,12 @@ def get_stream(self, uri):
10099 LOGGER .debug ("GET Stream from %s" , uri )
101100 try :
102101 response = self .session .get (uri , stream = True )
103- except (requests .exceptions .ConnectionError ,
102+ except (requests .exceptions .RequestException ,
104103 OSError , socket .error ) as err :
105104 raise exceptions .RequestError (str (err ))
106- if response .encoding is None :
107- response .encoding = 'utf-8'
108105 if utils .response_ok (response ):
109- for line in response .iter_lines ():
110- if line :
111- yield line .decode ('utf-8' )
106+ for line in response .iter_lines (): # pragma: no cover
107+ yield line .decode ('utf-8' )
112108
113109 @prepare_data
114110 def put (self , uri , data = None , timeout = None ):
@@ -127,31 +123,16 @@ def put(self, uri, data=None, timeout=None):
127123 if utils .is_string (data ) else CONTENT_JSON
128124 }
129125 try :
130- return self . _process_response (
126+ return api . Response (
131127 self .session .put (
132128 uri , data = data , headers = headers ,
133129 timeout = timeout or self .timeout ))
134- except (requests .exceptions .ConnectionError ,
130+ except (requests .exceptions .RequestException ,
135131 OSError , socket .error ) as err :
136132 raise exceptions .RequestError (str (err ))
137133
138- @staticmethod
139- def _process_response (response ):
140- """Build an api.Response object based upon the requests response
141- object.
142-
143- :param requests.response response: The requests response
144- :rtype: consulate.api.Response
145-
146- """
147- try :
148- return api .Response (
149- response .status_code , response .content , response .headers )
150- except (requests .exceptions .HTTPError , OSError , socket .error ) as err :
151- raise exceptions .RequestError (str (err ))
152-
153134
154- class UnixSocketRequest (Request ):
135+ class UnixSocketRequest (Request ): # pragma: no cover
155136 """Use to communicate with Consul over a Unix socket"""
156137
157138 def __init__ (self , timeout = None ):
0 commit comments