def clean_expired_tokens(opts):
 serializer = salt.payload.Serial(opts)
 for (dirpath, dirnames, filenames) in os.walk(opts['token_dir']):
  for token in filenames:
   token_path = os.path.join(dirpath, token)
   with salt.utils.fopen(token_path) as token_file:
    try:
     token_data = serializer.loads(token_file.read())
    except msgpack.UnpackValueError:
     os.remove(token_path)
     return
    if (('expire' not in token_data) or (token_data.get('expire', 0) < time.time())):
     try:
      os.remove(token_path)
     except (IOError, OSError):
      pass

def clean_expired_tokens ( opts ) : serializer = salt . payload . Serial ( opts ) for ( dirpath , dirnames , filenames ) in os . walk ( opts [ 'token_dir' ] ) : for token in filenames : token_path = os . path . join ( dirpath , token ) with salt . utils . fopen ( token_path ) as token_file : try : token_data = serializer . loads ( token_file . read ( ) ) except msgpack . UnpackValueError : os . remove ( token_path ) return if ( ( 'expire' not in token_data ) or ( token_data . get ( 'expire' , 0 ) < time . time ( ) ) ) : try : os . remove ( token_path ) except ( IOError , OSError ) : pass
clean expired tokens from the master .