132132# Standard Unix uses /dev/null
133133DEV_NULL = '/dev/null'
134134
135+ # Helper for comparing two version number strings.
136+ # Based on the description of the PHP's version_compare():
137+ # http://php.net/manual/en/function.version-compare.php
138+
139+ _ver_stages = {
140+ # any string not found in this dict, will get 0 assigned
141+ 'dev' :10 ,
142+ 'alpha' :20 ,'a' :20 ,
143+ 'beta' :30 ,'b' :30 ,
144+ 'c' :40 ,
145+ 'RC' :50 ,'rc' :50 ,
146+ # number, will get 100 assigned
147+ 'pl' :200 ,'p' :200 ,
148+ }
149+
150+ _component_re = re .compile (r'([0-9]+|[._+-])' )
151+
152+ def _comparable_version (version ):
153+ result = []
154+ for v in _component_re .split (version ):
155+ if v not in '._+-' :
156+ try :
157+ v = int (v ,10 )
158+ t = 100
159+ except ValueError :
160+ t = _ver_stages .get (v ,0 )
161+ result .extend ((t ,v ))
162+ return result
163+
135164### Platform specific APIs
136165
137166_libc_search = re .compile (b'(__libc_init)'
@@ -155,7 +184,7 @@ def libc_ver(executable=sys.executable, lib='', version='', chunksize=16384):
155184 The file is read and scanned in chunks of chunksize bytes.
156185
157186 """
158- from distutils . version import LooseVersion as V
187+ V = _comparable_version
159188if hasattr (os .path ,'realpath' ):
160189# Python 2.2 introduced os.path.realpath(); it is used
161190# here to work around problems with Cygwin not being