<s> from __future__ import unicode_literals <EOL> import logging <EOL> from django . core . exceptions import ObjectDoesNotExist , ValidationError <EOL> from django . db . models import Q <EOL> from django . utils import six <EOL> from djblets . util . decorators import augment_method_from <EOL> from djblets . webapi . decorators import ( webapi_login_required , <EOL> webapi_response_errors , <EOL> webapi_request_fields ) <EOL> from djblets . webapi . errors import ( DOES_NOT_EXIST , INVALID_FORM_DATA , <EOL> NOT_LOGGED_IN , PERMISSION_DENIED ) <EOL> from reviewboard . scmtools . errors import ( AuthenticationError , <EOL> SCMError , <EOL> RepositoryNotFoundError , <EOL> UnverifiedCertificateError ) <EOL> from reviewboard . scmtools . models import Repository , Tool <EOL> from reviewboard . ssh . client import SSHClient <EOL> from reviewboard . ssh . errors import ( SSHError , <EOL> BadHostKeyError , <EOL> UnknownHostKeyError ) <EOL> from reviewboard . webapi . base import WebAPIResource <EOL> from reviewboard . webapi . decorators import ( webapi_check_login_required , <EOL> webapi_check_local_site ) <EOL> from reviewboard . webapi . errors import ( BAD_HOST_KEY , <EOL> MISSING_REPOSITORY , <EOL> MISSING_USER_KEY , <EOL> REPO_AUTHENTICATION_ERROR , <EOL> REPO_INFO_ERROR , <EOL> REPOSITORY_ALREADY_EXISTS , <EOL> SERVER_CONFIG_ERROR , <EOL> UNVERIFIED_HOST_CERT , <EOL> UNVERIFIED_HOST_KEY ) <EOL> from reviewboard . webapi . resources import resources <EOL> class RepositoryResource ( WebAPIResource ) : <EOL> """<STR_LIT>""" <EOL> model = Repository <EOL> name_plural = '<STR_LIT>' <EOL> fields = { <EOL> '<STR_LIT:id>' : { <EOL> '<STR_LIT:type>' : int , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT:name>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT:path>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : bool , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> } <EOL> uri_object_key = '<STR_LIT>' <EOL> item_child_resources = [ <EOL> resources . diff_file_attachment , <EOL> resources . repository_branches , <EOL> resources . repository_commits , <EOL> resources . repository_info , <EOL> ] <EOL> allowed_methods = ( '<STR_LIT:GET>' , '<STR_LIT:POST>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ webapi_check_login_required <EOL> def get_queryset ( self , request , is_list = False , local_site_name = None , <EOL> show_invisible = False , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> local_site = self . _get_local_site ( local_site_name ) <EOL> if is_list : <EOL> queryset = self . model . objects . accessible ( <EOL> request . user , <EOL> visible_only = not show_invisible , <EOL> local_site = local_site ) <EOL> q = Q ( ) <EOL> if '<STR_LIT:name>' in request . GET : <EOL> q = q & Q ( name__in = request . GET . get ( '<STR_LIT:name>' ) . split ( '<STR_LIT:U+002C>' ) ) <EOL> if '<STR_LIT:path>' in request . GET : <EOL> paths = request . GET [ '<STR_LIT:path>' ] . split ( '<STR_LIT:U+002C>' ) <EOL> q = q & ( Q ( path__in = paths ) | Q ( mirror_path__in = paths ) ) <EOL> if '<STR_LIT>' in request . GET : <EOL> name_or_paths = request . GET [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) <EOL> q = q & ( Q ( name__in = name_or_paths ) | <EOL> Q ( path__in = name_or_paths ) | <EOL> Q ( mirror_path__in = name_or_paths ) ) <EOL> if '<STR_LIT>' in request . GET : <EOL> q = q & Q ( tool__name__in = request . GET [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) ) <EOL> if '<STR_LIT>' in request . GET : <EOL> q = q & Q ( hosting_account__service_name__in = <EOL> request . GET [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) ) <EOL> if '<STR_LIT:username>' in request . GET : <EOL> usernames = request . GET [ '<STR_LIT:username>' ] . split ( '<STR_LIT:U+002C>' ) <EOL> q = q & ( Q ( username__in = usernames ) | <EOL> Q ( hosting_account__username__in = usernames ) ) <EOL> return queryset . filter ( q ) . distinct ( ) <EOL> else : <EOL> return self . model . objects . filter ( local_site = local_site ) <EOL> def serialize_tool_field ( self , obj , ** kwargs ) : <EOL> return obj . tool . name <EOL> def has_access_permissions ( self , request , repository , * args , ** kwargs ) : <EOL> return repository . is_accessible_by ( request . user ) <EOL> def has_modify_permissions ( self , request , repository , * args , ** kwargs ) : <EOL> return repository . is_mutable_by ( request . user ) <EOL> def has_delete_permissions ( self , request , repository , * args , ** kwargs ) : <EOL> return repository . is_mutable_by ( request . user ) <EOL> @ webapi_check_login_required <EOL> @ webapi_check_local_site <EOL> @ webapi_request_fields ( <EOL> optional = dict ( { <EOL> '<STR_LIT:name>' : { <EOL> '<STR_LIT:type>' : str , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT:path>' : { <EOL> '<STR_LIT:type>' : str , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : str , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : str , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : str , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT:username>' : { <EOL> '<STR_LIT:type>' : str , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : bool , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> } , ** WebAPIResource . get_list . optional_fields ) , <EOL> required = WebAPIResource . get_list . required_fields , <EOL> allow_unknown = True <EOL> ) <EOL> def get_list ( self , request , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> show_invisible = request . GET . get ( '<STR_LIT>' , False ) <EOL> return super ( RepositoryResource , self ) . get_list ( <EOL> request , show_invisible = show_invisible , * args , ** kwargs ) <EOL> @ webapi_check_local_site <EOL> @ augment_method_from ( WebAPIResource ) <EOL> def get ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> @ webapi_check_local_site <EOL> @ webapi_login_required <EOL> @ webapi_response_errors ( BAD_HOST_KEY , INVALID_FORM_DATA , NOT_LOGGED_IN , <EOL> PERMISSION_DENIED , REPO_AUTHENTICATION_ERROR , <EOL> REPO_INFO_ERROR , REPOSITORY_ALREADY_EXISTS , <EOL> SERVER_CONFIG_ERROR , UNVERIFIED_HOST_CERT , <EOL> UNVERIFIED_HOST_KEY ) <EOL> @ webapi_request_fields ( <EOL> required = { <EOL> '<STR_LIT:name>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT:path>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> } , <EOL> optional = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT:password>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : bool , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : bool , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT:username>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : bool , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> } , <EOL> ) <EOL> def create ( self , request , name , path , tool , trust_host = False , <EOL> bug_tracker = None , encoding = None , mirror_path = None , <EOL> password = None , public = None , raw_file_url = None , username = None , <EOL> visible = True , local_site_name = None , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> local_site = self . _get_local_site ( local_site_name ) <EOL> if not Repository . objects . can_create ( request . user , local_site ) : <EOL> return self . get_no_access_error ( request ) <EOL> try : <EOL> scmtool = Tool . objects . get ( name = tool ) <EOL> except Tool . DoesNotExist : <EOL> return INVALID_FORM_DATA , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> } <EOL> } <EOL> cert = { } <EOL> error_result = self . _check_repository ( scmtool . get_scmtool_class ( ) , <EOL> path , username , password , <EOL> local_site , trust_host , cert , <EOL> request ) <EOL> if error_result is not None : <EOL> return error_result <EOL> if public is None : <EOL> public = True <EOL> repository = Repository ( <EOL> name = name , <EOL> path = path , <EOL> mirror_path = mirror_path or '<STR_LIT>' , <EOL> raw_file_url = raw_file_url or '<STR_LIT>' , <EOL> username = username or '<STR_LIT>' , <EOL> password = password or '<STR_LIT>' , <EOL> tool = scmtool , <EOL> bug_tracker = bug_tracker or '<STR_LIT>' , <EOL> encoding = encoding or '<STR_LIT>' , <EOL> public = public , <EOL> visible = visible , <EOL> local_site = local_site ) <EOL> if cert : <EOL> repository . extra_data [ '<STR_LIT>' ] = cert <EOL> try : <EOL> repository . full_clean ( ) <EOL> except ValidationError as e : <EOL> if hasattr ( e , '<STR_LIT>' ) and '<STR_LIT>' in e . params : <EOL> return INVALID_FORM_DATA , { <EOL> '<STR_LIT>' : { <EOL> e . params [ '<STR_LIT>' ] : e . message , <EOL> } , <EOL> } <EOL> else : <EOL> return REPOSITORY_ALREADY_EXISTS <EOL> repository . save ( ) <EOL> return <NUM_LIT> , { <EOL> self . item_result_key : repository , <EOL> } <EOL> @ webapi_check_local_site <EOL> @ webapi_login_required <EOL> @ webapi_response_errors ( DOES_NOT_EXIST , NOT_LOGGED_IN , PERMISSION_DENIED , <EOL> INVALID_FORM_DATA , SERVER_CONFIG_ERROR , <EOL> BAD_HOST_KEY , UNVERIFIED_HOST_KEY , <EOL> UNVERIFIED_HOST_CERT , REPO_AUTHENTICATION_ERROR , <EOL> REPO_INFO_ERROR ) <EOL> @ webapi_request_fields ( <EOL> optional = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT:name>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT:password>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT:path>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : bool , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : bool , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT:username>' : { <EOL> '<STR_LIT:type>' : six . text_type , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : bool , <EOL> '<STR_LIT:description>' : "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : bool , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> } , <EOL> ) <EOL> def update ( self , request , trust_host = False , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> repository = self . get_object ( request , * args , ** kwargs ) <EOL> except ObjectDoesNotExist : <EOL> return DOES_NOT_EXIST <EOL> if not self . has_modify_permissions ( request , repository ) : <EOL> return self . get_no_access_error ( request ) <EOL> for field in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:name>' , <EOL> '<STR_LIT:password>' , '<STR_LIT:path>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:username>' , '<STR_LIT>' ) : <EOL> value = kwargs . get ( field , None ) <EOL> if value is not None : <EOL> setattr ( repository , field , value ) <EOL> if '<STR_LIT:path>' in kwargs or '<STR_LIT:username>' in kwargs or '<STR_LIT:password>' in kwargs : <EOL> cert = { } <EOL> error_result = self . _check_repository ( <EOL> repository . tool . get_scmtool_class ( ) , <EOL> repository . path , <EOL> repository . username , <EOL> repository . password , <EOL> repository . local_site , <EOL> trust_host , <EOL> cert , <EOL> request ) <EOL> if error_result is not None : <EOL> return error_result <EOL> if cert : <EOL> repository . extra_data [ '<STR_LIT>' ] = cert <EOL> if kwargs . get ( '<STR_LIT>' , False ) : <EOL> repository . archive ( save = False ) <EOL> try : <EOL> repository . full_clean ( ) <EOL> except ValidationError as e : <EOL> return INVALID_FORM_DATA , { <EOL> '<STR_LIT>' : { <EOL> e . params [ '<STR_LIT>' ] : e . message , <EOL> } , <EOL> } <EOL> repository . save ( ) <EOL> return <NUM_LIT:200> , { <EOL> self . item_result_key : repository , <EOL> } <EOL> @ webapi_check_local_site <EOL> @ webapi_login_required <EOL> @ webapi_response_errors ( DOES_NOT_EXIST , NOT_LOGGED_IN , PERMISSION_DENIED ) <EOL> def delete ( self , request , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> repository = self . get_object ( request , * args , ** kwargs ) <EOL> except ObjectDoesNotExist : <EOL> return DOES_NOT_EXIST <EOL> if not self . has_delete_permissions ( request , repository ) : <EOL> return self . get_no_access_error ( request ) <EOL> if not repository . review_requests . exists ( ) : <EOL> repository . delete ( ) <EOL> else : <EOL> repository . visible = False <EOL> repository . save ( ) <EOL> return <NUM_LIT> , { } <EOL> def _check_repository ( self , scmtool_class , path , username , password , <EOL> local_site , trust_host , ret_cert , request ) : <EOL> if local_site : <EOL> local_site_name = local_site . name <EOL> else : <EOL> local_site_name = None <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> scmtool_class . check_repository ( path , username , password , <EOL> local_site_name ) <EOL> return None <EOL> except RepositoryNotFoundError : <EOL> return MISSING_REPOSITORY <EOL> except BadHostKeyError as e : <EOL> if trust_host : <EOL> try : <EOL> client = SSHClient ( namespace = local_site_name ) <EOL> client . replace_host_key ( e . hostname , <EOL> e . raw_expected_key , <EOL> e . raw_key ) <EOL> except IOError as e : <EOL> return SERVER_CONFIG_ERROR , { <EOL> '<STR_LIT>' : six . text_type ( e ) , <EOL> } <EOL> else : <EOL> return BAD_HOST_KEY , { <EOL> '<STR_LIT>' : e . hostname , <EOL> '<STR_LIT>' : e . raw_expected_key . get_base64 ( ) , <EOL> '<STR_LIT:key>' : e . raw_key . get_base64 ( ) , <EOL> } <EOL> except UnknownHostKeyError as e : <EOL> if trust_host : <EOL> try : <EOL> client = SSHClient ( namespace = local_site_name ) <EOL> client . add_host_key ( e . hostname , e . raw_key ) <EOL> except IOError as e : <EOL> return SERVER_CONFIG_ERROR , { <EOL> '<STR_LIT>' : six . text_type ( e ) , <EOL> } <EOL> else : <EOL> return UNVERIFIED_HOST_KEY , { <EOL> '<STR_LIT>' : e . hostname , <EOL> '<STR_LIT:key>' : e . raw_key . get_base64 ( ) , <EOL> } <EOL> except UnverifiedCertificateError as e : <EOL> if trust_host : <EOL> try : <EOL> cert = scmtool_class . accept_certificate ( <EOL> path , local_site_name ) <EOL> if cert : <EOL> ret_cert . update ( cert ) <EOL> except IOError as e : <EOL> return SERVER_CONFIG_ERROR , { <EOL> '<STR_LIT>' : six . text_type ( e ) , <EOL> } <EOL> else : <EOL> return UNVERIFIED_HOST_CERT , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : e . certificate . failures , <EOL> '<STR_LIT>' : e . certificate . fingerprint , <EOL> '<STR_LIT>' : e . certificate . hostname , <EOL> '<STR_LIT>' : e . certificate . issuer , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : e . certificate . valid_from , <EOL> '<STR_LIT>' : e . certificate . valid_until , <EOL> } , <EOL> } , <EOL> } <EOL> except AuthenticationError as e : <EOL> if '<STR_LIT>' in e . allowed_types and e . user_key is None : <EOL> return MISSING_USER_KEY <EOL> else : <EOL> return REPO_AUTHENTICATION_ERROR , { <EOL> '<STR_LIT>' : six . text_type ( e ) , <EOL> } <EOL> except SSHError as e : <EOL> logging . error ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> % e , exc_info = <NUM_LIT:1> , request = request ) <EOL> return REPO_INFO_ERROR , { <EOL> '<STR_LIT:error>' : six . text_type ( e ) , <EOL> } <EOL> except SCMError as e : <EOL> logging . error ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> % e , exc_info = <NUM_LIT:1> , request = request ) <EOL> return REPO_INFO_ERROR , { <EOL> '<STR_LIT:error>' : six . text_type ( e ) , <EOL> } <EOL> except Exception as e : <EOL> logging . error ( '<STR_LIT>' , <EOL> path , e , exc_info = <NUM_LIT:1> , request = request ) <EOL> raise <EOL> repository_resource = RepositoryResource ( ) </s>
