<s> from __future__ import unicode_literals <EOL> from django . core . exceptions import ObjectDoesNotExist <EOL> from django . utils import six <EOL> from djblets . webapi . decorators import webapi_response_errors <EOL> from djblets . webapi . errors import DOES_NOT_EXIST <EOL> from reviewboard . scmtools . errors import SCMError <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 REPO_INFO_ERROR , REPO_NOT_IMPLEMENTED <EOL> from reviewboard . webapi . resources import resources <EOL> class RepositoryBranchesResource ( WebAPIResource ) : <EOL> """<STR_LIT>""" <EOL> added_in = '<STR_LIT>' <EOL> name = '<STR_LIT>' <EOL> policy_id = '<STR_LIT>' <EOL> singleton = True <EOL> allowed_methods = ( '<STR_LIT:GET>' , ) <EOL> mimetype_item_resource_name = '<STR_LIT>' <EOL> @ webapi_check_local_site <EOL> @ webapi_check_login_required <EOL> @ webapi_response_errors ( DOES_NOT_EXIST , REPO_INFO_ERROR , <EOL> REPO_NOT_IMPLEMENTED ) <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> repository = resources . repository . get_object ( request , * args , <EOL> ** kwargs ) <EOL> except ObjectDoesNotExist : <EOL> return DOES_NOT_EXIST <EOL> try : <EOL> branches = [ ] <EOL> for branch in repository . get_branches ( ) : <EOL> branches . append ( { <EOL> '<STR_LIT:id>' : branch . id , <EOL> '<STR_LIT:name>' : branch . name , <EOL> '<STR_LIT>' : branch . commit , <EOL> '<STR_LIT:default>' : branch . default , <EOL> } ) <EOL> return <NUM_LIT:200> , { <EOL> self . item_result_key : branches , <EOL> } <EOL> except SCMError as e : <EOL> return REPO_INFO_ERROR . with_message ( six . text_type ( e ) ) <EOL> except NotImplementedError : <EOL> return REPO_NOT_IMPLEMENTED <EOL> repository_branches_resource = RepositoryBranchesResource ( ) </s>
