def extract_files(params):
    """
    Extract filenames from the "photo" parameter so they can be uploaded,
    returning (updated_params, files).
    Uses the same technique as the Trovebox PHP commandline tool:
      * Filename can only be in the "photo" parameter
      * Filename must be prefixed with "@"
      * Filename must exist
    ...otherwise the parameter is not extracted
    """
    files = {}
    updated_params = {}
    for name in params:
        if name == "photo" and params[name].startswith("@"):
            filename = params[name][1:]

            # Python2 uses encoded commandline parameters.
            # Decode to Unicode if necessary.
            if isinstance(filename, bytes):
                filename = filename.decode(sys.getfilesystemencoding())

            files[name] = open(os.path.expanduser(filename), 'rb')
        else:
            updated_params[name] = params[name]

    return updated_params, files
Extract filenames from the "photo" parameter so they can be uploaded,
    returning (updated_params, files).
    Uses the same technique as the Trovebox PHP commandline tool:
      * Filename can only be in the "photo" parameter
      * Filename must be prefixed with "@"
      * Filename must exist
    ...otherwise the parameter is not extracted