Ensure `self.path` has one of the extensions in `self.allowed_formats`.
197589
def validate(self):
        
        assert self.path, "{} must have a path".format(self.__class__.__name__)
        _, dotext = os.path.splitext(self.path)
        ext = dotext.lstrip('.')
        # don't validate for single-digit extension, or no extension
        if len(ext) > 1:
            assert ext in self.allowed_formats, "{} must have one of the following"
            "extensions: {} (instead, got '{}' from '{}')".format(
            self.__class__.__name__, self.allowed_formats, ext, self.path)
59383
def file_extension(path):
    
    if path is None:
        return None
    ext = os.path.splitext(os.path.basename(path))[1]
    if ext.startswith("."):
        ext = ext[1:]
    return ext
8311
def ensure_directory(path):
    
    dirname = os.path.dirname(path)
    if not os.path.exists(dirname):
        os.makedirs(dirname)
573914
def ensurepath(path_, verbose=None):
    
    if verbose is None:
        verbose = VERYVERBOSE
    return ensuredir(path_, verbose=verbose)
1211396
def _paths_must_exists(path):
    
    path = to_unicode(path)
    if not os.path.exists(path):
        raise argparse.ArgumentTypeError("{} is not a valid file/folder.".format(path))
    return path
246048
def optional_file_like(path):
    
    if (os.path.exists(path) and not (os.path.isfile(path) or
                                      stat.S_ISFIFO(os.stat(path).st_mode) or
                                      stat.S_ISCHR(os.stat(path).st_mode))):
        raise ValidationFailed(
            '{} is not a valid file, character device, or fifo.'.format(path))
551496
def specific_path_check(path, opt):
    """"""
    if opt.exclude:
        if path in opt.exclude:
            return False

    if opt.include:
        if path not in opt.include:
            return False

    return True
662737
def get_ext(path_name, *, if_all_ext=False):
    
    if has_ext(path_name):
        return os.path.splitext(path_name)[EXTENSION]
    elif if_all_ext and has_ext(path_name, if_all_ext=True):
        return os.path.splitext(path_name)[NAME]
    else:
        return ''
1367696
def __is_file_to_be_busted(self, filepath):
        
        if not self.extensions:
            return True
        return Path(filepath).suffix in self.extensions if filepath else False
485536
def check_path_allowed(path):
    

    config = Config.instance().get_section_config("Server")

    project_directory = get_default_project_directory()
    if len(os.path.commonprefix([project_directory, path])) == len(project_directory):
        return

    if "local" in config and config.getboolean("local") is False:
        raise aiohttp.web.HTTPForbidden(text="The path is not allowed")
1310944
def _ensure_tree(path):
    
    try:
        os.makedirs(path)
    except OSError as e:
        if e.errno == errno.EEXIST:
            if not os.path.isdir(path):
                raise
            else:
                return False
        elif e.errno == errno.EISDIR:
            return False
        else:
            raise
    else:
        return True
507051
def valid_file(path: str) -> bool:
    
    path = Path(path).expanduser()
    log.debug("checking if %s is a valid file", path)
    return path.exists() and path.is_file()
154406
def extender(path=None, cache=None):
    """"""
    old_path = sys.path[:]
    extend(path, cache=None)

    try:
        yield
    finally:
        sys.path = old_path
865444
def _inform_if_path_does_not_exist(path):
    
    expanded_path = get_expanded_path(path)
    if not os.path.exists(expanded_path):
        print('Could not find custom path at: {}'.format(expanded_path))
461706
def walk_files_for(paths, supported_extensions):
        
        for path in paths:
            for root, _, files in os.walk(path):
                if Application.ignore_path(root.replace(path, '')):
                    continue

                for filename in files:
                    extension = os.path.splitext(filename)[1]
                    if extension in supported_extensions:
                        yield path, os.path.join(root, filename), extension
808329
def old_path(self, full_path):
        """"""
        if self.matches(full_path):
            return full_path[:-len(self.extension)]
        else:
            raise MagicError("Path does not match this magic.")
1219937
def is_valid_dir(path):
    '''  '''
    return os.path.exists(path) and os.path.isdir(path)