def _req(self, method, url, body=None, ignore_status=None, content_type=None, accept_header=None): headers = self.headers headers = headers.copy() if method == 'PUT' or method == 'POST': if content_type is None: content_type = 'application/xml; charset=UTF-8' headers['Content-Type'] = content_type headers['Content-Length'] = str(len(body)) if body else '0' if accept_header is not None: headers['Accept'] = accept_header response, content = self.http.request(self.base_url + url, method, headers=headers, body=body) content = content.translate(None, '\0'.encode('utf-8')) _illegal_unichrs = [(0x00, 0x08), (0x0B, 0x0C), (0x0E, 0x1F), (0x7F, 0x84), (0x86, 0x9F), (0xFDD0, 0xFDDF), (0xFFFE, 0xFFFF)] _illegal_ranges = ["%s-%s" % (chr(low), chr(high)) for (low, high) in _illegal_unichrs] _illegal_xml_chars_re = re.compile('[%s]' % ''.join(_illegal_ranges)) content = re.sub(_illegal_xml_chars_re, '', content.decode('utf-8')).encode('utf-8') if response.status != 200 and response.status != 201 and (ignore_status != response.status): raise youtrack.YouTrackException(url, response, content) return response, content
def _login(self, login, password): response, content = self.http.request( self.baseUrl + "/user/login?login="******"&password=" + urllib.quote_plus(password), 'POST', headers={'Content-Length': '0', 'Connection': 'keep-alive'}) if response.status != 200: raise youtrack.YouTrackException('/user/login', response, content) self.headers = {'Cookie': response['set-cookie'], 'Cache-Control': 'no-cache'}
def _login(self, login, password): response, content = self.http.request( self.baseUrl + "/user/login?login="******"&password=" + password, 'POST', headers={'Content-Length': '0'}) if response.status != 200: raise youtrack.YouTrackException('/user/login', response, content) self.headers = { 'Cookie': response['set-cookie'], 'Cache-Control': 'no-cache' }
def _req(self, method, url, body=None, ignoreStatus=None, content_type=None): headers = self.headers if method == 'PUT' or method == 'POST': headers = headers.copy() if content_type is None: content_type = 'application/xml; charset=UTF-8' headers['Content-Type'] = content_type headers['Content-Length'] = str(len(body)) if body else '0' response, content = self.http.request((self.baseUrl + url).encode('utf-8'), method, headers=headers, body=body) content = content.translate(None, '\0') if response.status != 200 and response.status != 201 and (ignoreStatus != response.status): raise youtrack.YouTrackException(url, response, content) return response, content