#NEWLINE# @ classmethod #NEWLINE# def _from_pip_string_unsafe( klass , version_string ) : #NEWLINE# #INDENT# if ( not version_string [ : 1 ] . isdigit ( ) ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Invalid version %r' % version_string ) ) #NEWLINE# #UNINDENT# input_components = version_string . split ( '.' ) #NEWLINE# components = [ c for c in input_components if c . isdigit ( ) ] #NEWLINE# digit_len = len ( components ) #NEWLINE# if ( digit_len == 0 ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Invalid version %r' % version_string ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( digit_len < 3 ) : #NEWLINE# #INDENT# if ( ( digit_len < len ( input_components ) ) and input_components [ digit_len ] [ 0 ] . isdigit ( ) ) : #NEWLINE# #INDENT# mixed_component = input_components [ digit_len ] #NEWLINE# last_component = '' . join ( itertools . takewhile ( ( lambda x : x . isdigit ( ) ) , mixed_component ) ) #NEWLINE# components . append ( last_component ) #NEWLINE# input_components [ digit_len : ( digit_len + 1 ) ] = [ last_component , mixed_component [ len ( last_component ) : ] ] #NEWLINE# digit_len += 1 #NEWLINE# #UNINDENT# components . extend ( ( [ 0 ] * ( 3 - digit_len ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# components . extend ( input_components [ digit_len : ] ) #NEWLINE# major = int ( components [ 0 ] ) #NEWLINE# minor = int ( components [ 1 ] ) #NEWLINE# dev_count = None #NEWLINE# post_count = None #NEWLINE# prerelease_type = None #NEWLINE# prerelease = None #NEWLINE# def _parse_type( segment ) : #NEWLINE# #INDENT# isdigit = operator . methodcaller ( 'isdigit' ) #NEWLINE# segment = '' . join ( itertools . dropwhile ( isdigit , segment ) ) #NEWLINE# isalpha = operator . methodcaller ( 'isalpha' ) #NEWLINE# prerelease_type = '' . join ( itertools . takewhile ( isalpha , segment ) ) #NEWLINE# prerelease = segment [ len ( prerelease_type ) : ] #NEWLINE# return ( prerelease_type , int ( prerelease ) ) #NEWLINE# #UNINDENT# if _is_int ( components [ 2 ] ) : #NEWLINE# #INDENT# patch = int ( components [ 2 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# patch = 0 #NEWLINE# components [ 2 : 2 ] = [ 0 ] #NEWLINE# #UNINDENT# remainder = components [ 3 : ] #NEWLINE# remainder_starts_with_int = False #NEWLINE# try : #NEWLINE# #INDENT# if ( remainder and int ( remainder [ 0 ] ) ) : #NEWLINE# #INDENT# remainder_starts_with_int = True #NEWLINE# #UNINDENT# #UNINDENT# except ValueError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# if remainder_starts_with_int : #NEWLINE# #INDENT# dev_count = int ( remainder [ 0 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( remainder and ( ( remainder [ 0 ] [ 0 ] == '0' ) or ( remainder [ 0 ] [ 0 ] in ( 'a' , 'b' , 'r' ) ) ) ) : #NEWLINE# #INDENT# ( prerelease_type , prerelease ) = _parse_type ( remainder [ 0 ] ) #NEWLINE# remainder = remainder [ 1 : ] #NEWLINE# #UNINDENT# while remainder : #NEWLINE# #INDENT# component = remainder [ 0 ] #NEWLINE# if component . startswith ( 'dev' ) : #NEWLINE# #INDENT# dev_count = int ( component [ 3 : ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if component . startswith ( 'post' ) : #NEWLINE# #INDENT# dev_count = None #NEWLINE# post_count = int ( component [ 4 : ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( ( 'Unknown remainder %r in %r' % ( remainder , version_string ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# remainder = remainder [ 1 : ] #NEWLINE# #UNINDENT# #UNINDENT# result = SemanticVersion ( major , minor , patch , prerelease_type = prerelease_type , prerelease = prerelease , dev_count = dev_count ) #NEWLINE# if post_count : #NEWLINE# #INDENT# if dev_count : #NEWLINE# #INDENT# raise ValueError ( ( 'Cannot combine postN and devN - no mapping in %r' % ( version_string , ) ) ) #NEWLINE# #UNINDENT# result = result . increment ( ) . to_dev ( post_count ) #NEWLINE# #UNINDENT# return result