#NEWLINE# @ classmethod #NEWLINE# def parse( self , spec ) : #NEWLINE# #INDENT# "Parse a spec string into a populated Spec instance.\n\n        Raise BadSpecError if couldn't parse.\n        " #NEWLINE# if ( spec . startswith ( 'http://' ) or spec . startswith ( 'https://' ) ) : #NEWLINE# #INDENT# return Spec ( url = spec ) #NEWLINE# #UNINDENT# if spec . startswith ( 'file://' ) : #NEWLINE# #INDENT# try_file = urllib . unquote_plus ( spec [ len ( 'file://' ) : ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( os . sep in spec ) : #NEWLINE# #INDENT# try_file = spec #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try_file = None #NEWLINE# #UNINDENT# #UNINDENT# if try_file : #NEWLINE# #INDENT# if os . path . isdir ( try_file ) : #NEWLINE# #INDENT# return Spec ( dirname = try_file ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if os . path . exists ( try_file ) : #NEWLINE# #INDENT# return Spec ( filename = try_file ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ResourceNotFound ( ( _ ( "cannot find '%s'" ) % ver ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# m = re . match ( '(.+?)(?:(==|=|>=|>|<=|<)(.*))?$' , spec ) #NEWLINE# if ( m is None ) : #NEWLINE# #INDENT# raise BadSpecError ( _ ( "bad format for version specification: '%s'" ) , spec ) #NEWLINE# #UNINDENT# name = Term ( m . group ( 1 ) ) #NEWLINE# op = m . group ( 2 ) #NEWLINE# if ( op == '=' ) : #NEWLINE# #INDENT# op = '==' #NEWLINE# #UNINDENT# if ( op is not None ) : #NEWLINE# #INDENT# ver = SemVer . clean ( m . group ( 3 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ver = None #NEWLINE# #UNINDENT# return Spec ( name , op , ver )