def _get_dpi_from(cmd, pattern, func):
 try:
  (out, _) = run_subprocess([cmd])
 except (OSError, CalledProcessError):
  pass
 else:
  match = re.search(pattern, out)
  if match:
   return func(*map(float, match.groups()))

def _get_dpi_from ( cmd , pattern , func ) : try : ( out , _ ) = run_subprocess ( [ cmd ] ) except ( OSError , CalledProcessError ) : pass else : match = re . search ( pattern , out ) if match : return func ( * map ( float , match . groups ( ) ) )
match pattern against the output of func .