#NEWLINE# def _suggest_normalized_version( s ) : #NEWLINE# #INDENT# "Suggest a normalized version close to the given version string.\n\n    If you have a version string that isn't rational (i.e. NormalizedVersion\n    doesn't like it) then you might be able to get an equivalent (or close)\n    rational version from this function.\n\n    This does a number of simple normalizations to the given string, based\n    on observation of versions currently in use on PyPI. Given a dump of\n    those version during PyCon 2009, 4287 of them:\n    - 2312 (53.93%) match NormalizedVersion without change\n      with the automatic suggestion\n    - 3474 (81.04%) match when using this suggestion method\n\n    @param s {str} An irrational version string.\n    @returns A rational version string, or None, if couldn't determine one.\n    " #NEWLINE# try : #NEWLINE# #INDENT# _normalized_key ( s ) #NEWLINE# return orig #NEWLINE# #UNINDENT# except UnsupportedVersionError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# rs = s . lower ( ) #NEWLINE# for ( orig , repl ) in ( ( '-alpha' , 'a' ) , ( '-beta' , 'b' ) , ( 'alpha' , 'a' ) , ( 'beta' , 'b' ) , ( 'rc' , 'c' ) , ( '-final' , '' ) , ( '-pre' , 'c' ) , ( '-release' , '' ) , ( '.release' , '' ) , ( '-stable' , '' ) , ( '+' , '.' ) , ( '_' , '.' ) , ( ' ' , '' ) , ( '.final' , '' ) , ( 'final' , '' ) ) : #NEWLINE# #INDENT# rs = rs . replace ( orig , repl ) #NEWLINE# #UNINDENT# rs = re . sub ( 'pre$' , 'pre0' , rs ) #NEWLINE# rs = re . sub ( 'dev$' , 'dev0' , rs ) #NEWLINE# rs = re . sub ( '([abc]|rc)[\\-\\.](\\d+)$' , '\\1\\2' , rs ) #NEWLINE# rs = re . sub ( '[\\-\\.](dev)[\\-\\.]?r?(\\d+)$' , '.\\1\\2' , rs ) #NEWLINE# rs = re . sub ( '[.~]?([abc])\\.?' , '\\1' , rs ) #NEWLINE# if rs . startswith ( 'v' ) : #NEWLINE# #INDENT# rs = rs [ 1 : ] #NEWLINE# #UNINDENT# rs = re . sub ( '\\b0+(\\d+)(?!\\d)' , '\\1' , rs ) #NEWLINE# rs = re . sub ( '(\\d+[abc])$' , '\\g<1>0' , rs ) #NEWLINE# rs = re . sub ( '\\.?(dev-r|dev\\.r)\\.?(\\d+)$' , '.dev\\2' , rs ) #NEWLINE# rs = re . sub ( '-(a|b|c)(\\d+)$' , '\\1\\2' , rs ) #NEWLINE# rs = re . sub ( '[\\.\\-](dev|devel)$' , '.dev0' , rs ) #NEWLINE# rs = re . sub ( '(?![\\.\\-])dev$' , '.dev0' , rs ) #NEWLINE# rs = re . sub ( '(final|stable)$' , '' , rs ) #NEWLINE# rs = re . sub ( '\\.?(r|-|-r)\\.?(\\d+)$' , '.post\\2' , rs ) #NEWLINE# rs = re . sub ( '\\.?(dev|git|bzr)\\.?(\\d+)$' , '.dev\\2' , rs ) #NEWLINE# rs = re . sub ( '\\.?(pre|preview|-c)(\\d+)$' , 'c\\g<2>' , rs ) #NEWLINE# rs = re . sub ( 'p(\\d+)$' , '.post\\1' , rs ) #NEWLINE# try : #NEWLINE# #INDENT# _normalized_key ( rs ) #NEWLINE# #UNINDENT# except UnsupportedVersionError : #NEWLINE# #INDENT# rs = None #NEWLINE# #UNINDENT# return rs