def __str__(self): try: return super(Contact, self).__str__() except ResourceAttrError: if not getattr(self, 'last_name', False): return '{0}'.format(to_string(self.first_name)) else: return '{0} {1}'.format(to_string(self.first_name), to_string(self.last_name))
def __repr__(self): try: return super(User, self).__repr__() except ResourceAttrError: return '<{0}.{1} #{2} "{3} {4}">'.format(self.__class__.__module__, self.__class__.__name__, self.id, to_string(self.firstname), to_string(self.lastname))
def __repr__(self): try: return super(User, self).__repr__() except ResourceAttrError: return '<{0}.{1} #{2} "{3} {4}">'.format( self.__class__.__module__, self.__class__.__name__, self.id, to_string(self.firstname), to_string(self.lastname) )
def __repr__(self): return '<{0}.{1} #{2} "{3}">'.format( self.__class__.__module__, self.__class__.__name__, self.id, to_string(self.title) )
def __repr__(self): try: return super(Contact, self).__repr__() except ResourceAttrError: if not getattr(self, 'last_name', False): return '<{0}.{1} #{2} "{3}">'.format( self.__class__.__module__, self.__class__.__name__, self.id, to_string(self.first_name), ) else: return '<{0}.{1} #{2} "{3} {4}">'.format( self.__class__.__module__, self.__class__.__name__, self.id, to_string(self.first_name), to_string(self.last_name))
def request(self, method, url, headers=None, params=None, data=None, raw_response=False): """Make requests to Redmine and returns result in json format.""" kwargs = dict(self.requests, **{ 'headers': headers or {}, 'params': params or {}, 'data': data or {}, }) if ('Content-Type' not in kwargs['headers'] and method in ('post', 'put')): kwargs['data'] = json.dumps(data) kwargs['headers']['Content-Type'] = 'application/json' if self.impersonate is not None: kwargs['headers']['X-Redmine-Switch-User'] = self.impersonate # We would like to be authenticated by API key by default if 'key' not in kwargs['params'] and self.key is not None: kwargs['params']['key'] = self.key else: kwargs['auth'] = (self.username, self.password) api_url = join(self.url, url + '.json') response = yield from aiohttp.request(method, api_url, **kwargs) if response.status in (200, 201): if raw_response: return response text = yield from response.text() if not text.strip(): return True else: try: return json.loads(text) except (ValueError, TypeError): raise JSONDecodeError elif response.status == 401: raise AuthError elif response.status == 403: raise ForbiddenError elif response.status == 404: raise ResourceNotFoundError elif response.status == 409: raise ConflictError elif response.status == 412 and self.impersonate is not None: raise ImpersonateError elif response.status == 413: raise RequestEntityTooLargeError elif response.status == 422: response_json = yield from response.json() errors = json_response(response_json)['errors'] raise ValidationError(to_string(', '.join(e if is_string(e) else ': '.join(e) for e in errors))) elif response.status == 500: raise ServerError raise UnknownError(response.status)
def __repr__(self): """Official representation of the Redmine resource object""" return '<{0}.{1} #{2} "{3}">'.format( self.__class__.__module__, self.__class__.__name__, self.id, to_string(self.name) )
def __repr__(self): try: return '<{0}.{1} #{2} "{3}">'.format(self.__class__.__module__, self.__class__.__name__, self.id, to_string(self.subject)) except ResourceAttrError: return '<{0}.{1} #{2}>'.format(self.__class__.__module__, self.__class__.__name__, self.id)
def request(self, method, url, headers=None, params=None, data=None, raw_response=False): """Makes requests to Redmine and returns result in json format""" kwargs = dict( self.requests, **{ 'headers': headers or {}, 'params': params or {}, 'data': data or {}, }) if 'Content-Type' not in kwargs['headers'] and method in ('post', 'put'): kwargs['data'] = json.dumps(data) kwargs['headers']['Content-Type'] = 'application/json' if self.impersonate is not None: kwargs['headers']['X-Redmine-Switch-User'] = self.impersonate # We would like to be authenticated by API key by default if 'key' not in kwargs['params'] and self.key is not None: kwargs['params']['key'] = self.key else: kwargs['auth'] = (self.username, self.password) response = getattr(requests, method)(url, **kwargs) if response.status_code in (200, 201): if raw_response: return response elif not response.content.strip(): return True else: return json_response(response.json) elif response.status_code == 401: raise AuthError elif response.status_code == 404: raise ResourceNotFoundError elif response.status_code == 409: raise ConflictError elif response.status_code == 412 and self.impersonate is not None: raise ImpersonateError elif response.status_code == 413: raise RequestEntityTooLargeError elif response.status_code == 422: errors = json_response(response.json)['errors'] raise ValidationError( to_string(', '.join(e if is_string(e) else ': '.join(e) for e in errors))) elif response.status_code == 500: raise ServerError raise UnknownError(response.status_code)
def __repr__(self): try: return super(Contact, self).__repr__() except ResourceAttrError: if not getattr(self, 'last_name', False): return '<{0}.{1} #{2} "{3}">'.format( self.__class__.__module__, self.__class__.__name__, self.id, to_string(self.first_name), ) else: return '<{0}.{1} #{2} "{3} {4}">'.format( self.__class__.__module__, self.__class__.__name__, self.id, to_string(self.first_name), to_string(self.last_name) )
def request(self, method, url, headers=None, params=None, data=None, raw_response=False): """Makes requests to Redmine and returns result in json format""" kwargs = dict(self.requests, **{ 'headers': headers or {}, 'params': params or {}, 'data': data or {}, }) if 'Content-Type' not in kwargs['headers'] and method in ('post', 'put'): kwargs['data'] = json.dumps(data) kwargs['headers']['Content-Type'] = 'application/json' if self.impersonate is not None: kwargs['headers']['X-Redmine-Switch-User'] = self.impersonate # We would like to be authenticated by API key by default if self.key is not None: kwargs['params']['key'] = self.key if self.username and self.password: kwargs['auth'] = (self.username, self.password) if self.auth_cookie: kwargs['cookies'] = dict(auth_pubtkt=self.auth_cookie) response = getattr(requests, method)(url, **kwargs) if response.status_code in (200, 201): if raw_response: return response elif not response.content.strip(): return True else: return response.json() elif response.status_code == 401: raise AuthError elif response.status_code == 404: raise ResourceNotFoundError elif response.status_code == 409: raise ConflictError elif response.status_code == 412 and self.impersonate is not None: raise ImpersonateError elif response.status_code == 413: raise RequestEntityTooLargeError elif response.status_code == 422: raise ValidationError(to_string(', '.join( response.json()['errors']))) elif response.status_code == 500: raise ServerError raise UnknownError(response.status_code)
def __repr__(self): try: return '<{0}.{1} #{2} "{3}">'.format( self.__class__.__module__, self.__class__.__name__, self.id, to_string(self.subject) ) except ResourceAttrError: return '<{0}.{1} #{2}>'.format( self.__class__.__module__, self.__class__.__name__, self.id )
def request(self, method, url, headers=None, params=None, data=None): """Makes requests to Redmine and returns result in json format""" kwargs = dict(self.requests, **{ 'headers': headers or {}, 'params': params or {}, 'data': data or {}, }) if not 'Content-Type' in kwargs['headers'] and method in ('post', 'put'): kwargs['data'] = json.dumps(data) kwargs['headers']['Content-Type'] = 'application/json' if self.impersonate is not None: kwargs['headers']['X-Redmine-Switch-User'] = self.impersonate # We would like to be authenticated by API key by default if 'key' not in kwargs['params'] and self.key is not None: kwargs['params']['key'] = self.key else: kwargs['auth'] = (self.username, self.password) if 'from_date' in kwargs['params']: kwargs['params']['from'] = kwargs['params'].pop('from_date') if 'to_date' in kwargs['params']: kwargs['params']['to'] = kwargs['params'].pop('to_date') response = getattr(requests, method)(url, **kwargs) if response.status_code in (200, 201): if response.status_code == 200: if method == 'put': return response.text elif method == 'delete': return True return response.json() elif response.status_code == 401: raise AuthError() elif response.status_code == 404: raise ResourceNotFoundError elif response.status_code == 412 and self.impersonate is not None: raise ImpersonateError() elif response.status_code == 422: raise ValidationError(to_string(', '.join(response.json()['errors']))) elif response.status_code == 500: raise ServerError() return None
def __repr__(self): """Official representation of the Redmine resource object""" return '<{0}.{1} #{2} "{3}">'.format(self.__class__.__module__, self.__class__.__name__, self.id, to_string(self.name))
def __str__(self): try: return super(User, self).__str__() except ResourceAttrError: return '{0} {1}'.format(to_string(self.firstname), to_string(self.lastname))
def __str__(self): return to_string(self.title)
def __str__(self): return to_string(self.filename)
def __str__(self): try: return to_string(self.subject) except ResourceAttrError: return str(self.id)
def __str__(self): """Informal representation of the Redmine resource object""" return to_string(self.name)
def internal_id(self): return to_string(self.title)
def __str__(self): try: return to_string(self.filename) except ResourceAttrError: return str(self.id)
def __repr__(self): return '<{0}.{1} #{2} "{3}">'.format(self.__class__.__module__, self.__class__.__name__, self.id, to_string(self.title))