| Conditions | 7 |
| Total Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | ''' |
||
| 114 | def execute(self): |
||
| 115 | |||
| 116 | self.endpoint = APIOperationBase.__environment |
||
| 117 | |||
| 118 | logging.debug('Executing http post to url: %s', self.endpoint) |
||
| 119 | |||
| 120 | self.beforeexecute() |
||
| 121 | |||
| 122 | proxyDictionary = {'http' : utility.helper.getproperty("http"), |
||
| 123 | 'https' : utility.helper.getproperty("https"), |
||
| 124 | 'ftp' : utility.helper.getproperty("ftp")} |
||
| 125 | |||
| 126 | #requests is http request |
||
| 127 | try: |
||
| 128 | self.setClientId() |
||
| 129 | xmlRequest = self.buildrequest() |
||
| 130 | self._httpResponse = requests.post(self.endpoint, data=xmlRequest, headers=constants.headers, proxies=proxyDictionary) |
||
| 131 | except Exception as httpException: |
||
| 132 | logging.error( 'Error retrieving http response from: %s for request: %s', self.endpoint, self.getprettyxmlrequest()) |
||
| 133 | logging.error( 'Exception: %s, %s', type(httpException), httpException.args ) |
||
| 134 | |||
| 135 | |||
| 136 | if self._httpResponse: |
||
| 137 | self._httpResponse.encoding = constants.response_encoding |
||
| 138 | self._httpResponse = self._httpResponse.text[3:] #strip BOM |
||
| 139 | self.afterexecute() |
||
| 140 | try: |
||
| 141 | self._response = apicontractsv1.CreateFromDocument(self._httpResponse) |
||
| 142 | #objectify code |
||
| 143 | xmlResponse= self._response.toxml(encoding=constants.xml_encoding, element_name=self.getrequesttype()) |
||
| 144 | xmlResponse = xmlResponse.replace(constants.nsNamespace1, b'') |
||
| 145 | xmlResponse = xmlResponse.replace(constants.nsNamespace2, b'') |
||
| 146 | self._mainObject = objectify.fromstring(xmlResponse) |
||
| 147 | |||
| 148 | except Exception as objectifyexception: |
||
| 149 | logging.error( 'Create Document Exception: %s, %s', type(objectifyexception), objectifyexception.args ) |
||
| 150 | pyxb.GlobalValidationConfig._setForBinding(False) |
||
| 151 | self._response = apicontractsv1.CreateFromDocument(self._httpResponse) |
||
| 152 | #objectify code |
||
| 153 | xmlResponse= self._response.toxml(encoding=constants.xml_encoding, element_name=self.getrequesttype()) |
||
| 154 | xmlResponse = xmlResponse.replace(constants.nsNamespace1, b'') |
||
| 155 | xmlResponse = xmlResponse.replace(constants.nsNamespace2, b'') |
||
| 156 | self._mainObject = objectify.fromstring(xmlResponse) |
||
| 157 | else: |
||
| 158 | #if type(self.getresponseclass()) == type(self._response): |
||
| 159 | if type(self.getresponseclass()) != type(self._mainObject): |
||
| 160 | if self._response.messages.resultCode == "Error": |
||
| 161 | logging.debug("Response error") |
||
| 162 | domResponse = xml.dom.minidom.parseString(self._httpResponse) |
||
| 163 | logging.debug('Received response: %s' % domResponse.toprettyxml()) |
||
| 164 | else: |
||
| 165 | #Need to handle ErrorResponse |
||
| 166 | logging.debug('Error retrieving response for request: %s' % self._request) |
||
| 167 | else: |
||
| 168 | logging.debug("Did not receive http response") |
||
| 169 | return |
||
| 170 | |||
| 254 |