<s> """<STR_LIT>""" <EOL> from urllib . parse import urljoin <EOL> import json <EOL> import requests <EOL> class BaseClient : <EOL> """<STR_LIT>""" <EOL> BASE_HEADERS = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:true>" , <EOL> } <EOL> def __init__ ( self , host ) : <EOL> self . _host = host <EOL> self . _headers = self . BASE_HEADERS <EOL> self . last_error = { } <EOL> def _get ( self , url , params ) : <EOL> response = requests . get ( url , params = params , headers = self . _headers ) <EOL> data = json . loads ( response . content . decode ( ) ) <EOL> if response . status_code == <NUM_LIT:200> : <EOL> return data <EOL> self . last_error = { <EOL> "<STR_LIT>" : response . status_code , <EOL> "<STR_LIT>" : data . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> } <EOL> return None <EOL> def _post ( self , url , data_dict , params ) : <EOL> rdata = json . dumps ( data_dict ) <EOL> response = requests . post ( url , data = rdata , params = params , headers = self . _headers ) <EOL> if response . status_code in [ <NUM_LIT:200> , <NUM_LIT> ] : <EOL> data = json . loads ( response . content . decode ( ) ) <EOL> return data <EOL> elif response . status_code == <NUM_LIT> : <EOL> return True <EOL> else : <EOL> data = json . loads ( response . content . decode ( ) ) <EOL> self . last_error = { <EOL> "<STR_LIT>" : response . status_code , <EOL> "<STR_LIT>" : data . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> } <EOL> return None <EOL> def _patch ( self , url , data_dict , params ) : <EOL> rdata = json . dumps ( data_dict ) <EOL> response = requests . patch ( url , data = rdata , params = params , headers = self . _headers ) <EOL> data = json . loads ( response . content . decode ( ) ) <EOL> if response . status_code == <NUM_LIT:200> : <EOL> return data <EOL> self . last_error = { <EOL> "<STR_LIT>" : response . status_code , <EOL> "<STR_LIT>" : data . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> } <EOL> return None <EOL> def _delete ( self , url , params ) : <EOL> response = requests . delete ( url , params = params , headers = self . _headers ) <EOL> if response . status_code == <NUM_LIT> : <EOL> return True <EOL> data = json . loads ( response . content . decode ( ) ) <EOL> self . last_error = { <EOL> "<STR_LIT>" : response . status_code , <EOL> "<STR_LIT>" : data . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> } <EOL> return None <EOL> class TaigaClient ( BaseClient ) : <EOL> """<STR_LIT>""" <EOL> URLS = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:user>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> def __init__ ( self , host ) : <EOL> super ( ) . __init__ ( host ) <EOL> @ property <EOL> def is_authenticated ( self ) : <EOL> return "<STR_LIT>" in self . _headers <EOL> def set_auth_token ( self , auth_token ) : <EOL> self . _headers [ "<STR_LIT>" ] = "<STR_LIT>" . format ( auth_token ) <EOL> def login ( self , username , password , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) ) <EOL> data_dict = { <EOL> "<STR_LIT:username>" : username , <EOL> "<STR_LIT:password>" : password , <EOL> "<STR_LIT:type>" : "<STR_LIT>" <EOL> } <EOL> data = self . _post ( url , data_dict , params ) <EOL> if data and "<STR_LIT>" in data : <EOL> self . set_auth_token ( data [ "<STR_LIT>" ] ) <EOL> return data <EOL> def logout ( self ) : <EOL> self . _headers = self . BASE_HEADERS <EOL> return True <EOL> def get_users ( self , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) ) <EOL> return self . _get ( url , params ) <EOL> def update_user ( self , id , data_dict = { } , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT:user>" ) . format ( id ) ) <EOL> return self . _patch ( url , data_dict , params ) <EOL> def get_user ( self , id , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT:user>" ) . format ( id ) ) <EOL> return self . _get ( url , params ) <EOL> def get_projects ( self , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) ) <EOL> return self . _get ( url , params ) <EOL> def create_project ( self , data_dict = { } , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) ) <EOL> return self . _post ( url , data_dict , params ) <EOL> def update_project ( self , id , data_dict = { } , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _patch ( url , data_dict , params ) <EOL> def get_project ( self , id , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _get ( url , params ) <EOL> def delete_project ( self , id , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _delete ( url , params ) <EOL> def get_project_stats ( self , id , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _get ( url , params ) <EOL> def get_project_issues_stats ( self , id , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _get ( url , params ) <EOL> def get_milestones ( self , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) ) <EOL> return self . _get ( url , params ) <EOL> def create_milestone ( self , data_dict = { } , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) ) <EOL> return self . _post ( url , data_dict , params ) <EOL> def update_milestone ( self , id , data_dict = { } , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _patch ( url , data_dict , params ) <EOL> def get_milestone ( self , id , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _get ( url , params ) <EOL> def delete_milestone ( self , id , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _delete ( url , params ) <EOL> def get_milestone_stats ( self , id , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _get ( url , params ) <EOL> def get_user_stories ( self , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) ) <EOL> return self . _get ( url , params ) <EOL> def update_user_stories_order ( self , data_dict = { } , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) ) <EOL> return self . _post ( url , data_dict , params ) <EOL> def create_user_stories_in_bulk ( self , data_dict = { } , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) ) <EOL> return self . _post ( url , data_dict , params ) <EOL> def create_user_story ( self , data_dict = { } , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) ) <EOL> return self . _post ( url , data_dict , params ) <EOL> def update_user_story ( self , id , data_dict = { } , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _patch ( url , data_dict , params ) <EOL> def get_user_story ( self , id , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _get ( url , params ) <EOL> def delete_user_story ( self , id , params = { } , ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _delete ( url , params ) <EOL> def get_tasks ( self , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) ) <EOL> return self . _get ( url , params ) <EOL> def create_task ( self , data_dict = { } , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) ) <EOL> return self . _post ( url , data_dict , params ) <EOL> def update_task ( self , id , data_dict = { } , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _patch ( url , data_dict , params ) <EOL> def get_task ( self , id , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _get ( url , params ) <EOL> def delete_task ( self , id , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _delete ( url , params ) <EOL> def get_issues ( self , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) ) <EOL> return self . _get ( url , params ) <EOL> def create_issue ( self , data_dict = { } , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) ) <EOL> return self . _post ( url , data_dict , params ) <EOL> def update_issue ( self , id , data_dict = { } , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _patch ( url , data_dict , params ) <EOL> def get_issue ( self , id , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _get ( url , params ) <EOL> def delete_issue ( self , id , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _delete ( url , params ) <EOL> def get_wiki_pages ( self , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) ) <EOL> return self . _get ( url , params ) <EOL> def create_wiki_page ( self , data_dict = { } , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) ) <EOL> return self . _post ( url , data_dict , params ) <EOL> def update_wiki_page ( self , id , data_dict = { } , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _patch ( url , data_dict , params ) <EOL> def get_wiki_page ( self , id , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _get ( url , params ) <EOL> def delete_wiki_page ( self , id , params = { } ) : <EOL> url = urljoin ( self . _host , self . URLS . get ( "<STR_LIT>" ) . format ( id ) ) <EOL> return self . _delete ( url , params ) </s>
