def get_system_tor_version(tor_cmd='tor'):
 if (tor_cmd not in VERSION_CACHE):
  version_cmd = ('%s --version' % tor_cmd)
  try:
   version_output = stem.util.system.call(version_cmd)
  except OSError as exc:
   if ('No such file or directory' in str(exc)):
    if os.path.isabs(tor_cmd):
     exc = ("Unable to check tor's version. '%s' doesn't exist." % tor_cmd)
    else:
     exc = ("Unable to run '%s'. Mabye tor isn't in your PATH?" % version_cmd)
   raise IOError(exc)
  if version_output:
   last_line = version_output[(-1)]
   if (last_line.startswith('Tor version ') and last_line.endswith('.')):
    try:
     version_str = last_line[12:(-1)]
     VERSION_CACHE[tor_cmd] = Version(version_str)
    except ValueError as exc:
     raise IOError(exc)
   else:
    raise IOError(("Unexpected response from '%s': %s" % (version_cmd, last_line)))
  else:
   raise IOError(("'%s' didn't have any output" % version_cmd))
 return VERSION_CACHE[tor_cmd]

def get_system_tor_version ( tor_cmd = 'tor' ) : if ( tor_cmd not in VERSION_CACHE ) : version_cmd = ( '%s --version' % tor_cmd ) try : version_output = stem . util . system . call ( version_cmd ) except OSError as exc : if ( 'No such file or directory' in str ( exc ) ) : if os . path . isabs ( tor_cmd ) : exc = ( "Unable to check tor's version. '%s' doesn't exist." % tor_cmd ) else : exc = ( "Unable to run '%s'. Mabye tor isn't in your PATH?" % version_cmd ) raise IOError ( exc ) if version_output : last_line = version_output [ ( - 1 ) ] if ( last_line . startswith ( 'Tor version ' ) and last_line . endswith ( '.' ) ) : try : version_str = last_line [ 12 : ( - 1 ) ] VERSION_CACHE [ tor_cmd ] = Version ( version_str ) except ValueError as exc : raise IOError ( exc ) else : raise IOError ( ( "Unexpected response from '%s': %s" % ( version_cmd , last_line ) ) ) else : raise IOError ( ( "'%s' didn't have any output" % version_cmd ) ) return VERSION_CACHE [ tor_cmd ]
queries tor for its version .