<s> from __future__ import absolute_import <EOL> from os . path import join as pjoin <EOL> class RepoBrowser ( object ) : <EOL> '''<STR_LIT>''' <EOL> def tag ( self , name , tag_sha = None , obj_sha = None ) : <EOL> '''<STR_LIT>''' <EOL> raise NotImplementedError <EOL> def commit ( self , sha ) : <EOL> '''<STR_LIT>''' <EOL> raise NotImplementedError <EOL> def branch ( self , ref , shortref ) : <EOL> '''<STR_LIT>''' <EOL> raise NotImplementedError <EOL> def diff ( self , diffspec ) : <EOL> '''<STR_LIT>''' <EOL> raise NotImplementedError <EOL> def tree ( self , sha ) : <EOL> '''<STR_LIT>''' <EOL> raise NotImplementedError <EOL> def path ( self , path , tree , commit ) : <EOL> '''<STR_LIT>''' <EOL> raise NotImplementedError <EOL> def blob ( self , sha , path , tree , commit , raw ) : <EOL> '''<STR_LIT>''' <EOL> raise NotImplementedError <EOL> def join ( self , * args ) : <EOL> l = [ self . url ] <EOL> l . extend ( args ) <EOL> return pjoin ( * l ) <EOL> class GitwebBrowser ( RepoBrowser ) : <EOL> '''<STR_LIT>''' <EOL> options = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> } , <EOL> } <EOL> def __init__ ( self , url , <EOL> head_view = '<STR_LIT>' , <EOL> commit_view = '<STR_LIT>' , <EOL> tag_view = '<STR_LIT>' ) : <EOL> self . url = url . rstrip ( '<STR_LIT:/>' ) <EOL> self . tag_view = tag_view <EOL> self . head_view = head_view <EOL> self . commit_view = commit_view <EOL> def commit ( self , sha ) : <EOL> l = ( self . url , '<STR_LIT>' % self . commit_view , '<STR_LIT>' % sha ) <EOL> return '<STR_LIT:;>' . join ( l ) <EOL> def tree ( self , sha , path = None ) : <EOL> l = [ self . url , '<STR_LIT>' , '<STR_LIT>' % sha ] <EOL> if path : l . append ( '<STR_LIT>' % path ) <EOL> return '<STR_LIT:;>' . join ( l ) <EOL> def branch ( self , ref , shortref ) : <EOL> l = ( self . url , '<STR_LIT>' % self . head_view , '<STR_LIT>' % shortref ) <EOL> return '<STR_LIT:;>' . join ( l ) <EOL> def tag ( self , name , tag_sha = None , obj_sha = None ) : <EOL> l = ( self . url , '<STR_LIT>' % self . tag_view , '<STR_LIT>' % name ) <EOL> return '<STR_LIT:;>' . join ( l ) <EOL> def blob ( self , sha , path , tree = None , commit = None , raw = False ) : <EOL> if tree and tree == '<STR_LIT>' : <EOL> tree = None <EOL> l = [ self . url , '<STR_LIT>' , '<STR_LIT>' % sha ] <EOL> if path : <EOL> l . append ( '<STR_LIT>' % path ) <EOL> url = '<STR_LIT:;>' . join ( l ) <EOL> if raw : <EOL> url = url . replace ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> return url <EOL> def path ( self , path , tree = None , commit = None ) : <EOL> l = ( self . url , '<STR_LIT>' , '<STR_LIT>' % path , '<STR_LIT>' % tree ) <EOL> return '<STR_LIT:;>' . join ( l ) <EOL> class GithubBrowser ( RepoBrowser ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , url ) : <EOL> self . url = url <EOL> def commit ( self , sha ) : <EOL> return self . join ( '<STR_LIT>' , sha ) <EOL> def tree ( self , sha ) : <EOL> '''<STR_LIT>''' <EOL> def branch ( self , ref , shortref ) : <EOL> return self . join ( '<STR_LIT>' , shortref ) <EOL> def tag ( self , name , tag_sha = None , obj_sha = None ) : <EOL> return self . join ( '<STR_LIT>' , name ) <EOL> def blob ( self , sha , path , tree = None , commit = None , raw = False ) : <EOL> url = self . join ( '<STR_LIT>' , commit , path ) <EOL> if raw : <EOL> url = url . replace ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> url = url . replace ( '<STR_LIT>' , '<STR_LIT:/>' , <NUM_LIT:1> ) <EOL> return url <EOL> def path ( self , path , tree , commit ) : <EOL> return self . join ( '<STR_LIT>' , commit , path ) <EOL> class GithubPrivateBrowser ( GithubBrowser ) : <EOL> '''<STR_LIT>''' <EOL> class CgitBrowser ( RepoBrowser ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , url ) : <EOL> self . url = url <EOL> def commit ( self , sha ) : <EOL> return self . join ( '<STR_LIT>' , '<STR_LIT>' % sha ) <EOL> def tree ( self , sha ) : <EOL> return self . join ( '<STR_LIT>' , '<STR_LIT>' % sha ) <EOL> def branch ( self , ref , shortref ) : <EOL> if not shortref : return None <EOL> return self . join ( '<STR_LIT>' , '<STR_LIT>' % shortref ) <EOL> def tag ( self , name , tag_sha = None , obj_sha = None ) : <EOL> return self . join ( '<STR_LIT>' , '<STR_LIT>' % name ) <EOL> def blob ( self , sha , path , tree = None , commit = None , raw = False ) : <EOL> if tree and tree == '<STR_LIT>' : <EOL> tree = None <EOL> url = self . path ( path , tree ) <EOL> if raw : <EOL> url = url . replace ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> return url <EOL> def path ( self , path , tree = None , commit = None ) : <EOL> url = [ self . url , '<STR_LIT>' , path ] <EOL> if tree : <EOL> url . append ( '<STR_LIT>' % tree ) <EOL> return pjoin ( * url ) <EOL> class LinkType ( object ) : <EOL> unknown = <NUM_LIT> <EOL> commit = <NUM_LIT> <EOL> tree = <NUM_LIT> <EOL> tag = <NUM_LIT> <EOL> branch = <NUM_LIT> <EOL> diff = <NUM_LIT> <EOL> blob = <NUM_LIT> <EOL> path = <NUM_LIT> <EOL> repobrowsers = { <EOL> '<STR_LIT>' : CgitBrowser , <EOL> '<STR_LIT>' : GitwebBrowser , <EOL> '<STR_LIT>' : GithubBrowser , <EOL> '<STR_LIT>' : GithubPrivateBrowser , <EOL> } </s>
