How to use the blacksheep.exceptions.InvalidArgument function in blacksheep

To help you get started, we’ve selected a few blacksheep examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RobertoPrevato / BlackSheep / blacksheep / client / pool.py View on Github external
def _ssl_option(self, ssl):
        if self.scheme == b'https':
            if ssl is None:
                return SECURE_SSLCONTEXT
            if ssl is False:
                return INSECURE_SSLCONTEXT
            if isinstance(ssl, SSLContext):
                return ssl
            raise InvalidArgument('Invalid ssl argument, expected one of: '
                                  '{None, False, True, instance of ssl.SSLContext}')
        if ssl:
            raise InvalidArgument('SSL argument specified for non-https scheme.')
        return None
github RobertoPrevato / BlackSheep / blacksheep / server / files / static.py View on Github external
def get_files_to_serve(source_folder, extensions=None, discovery=False, root_folder=None):
    if extensions is None:
        extensions = get_default_extensions()

    if not root_folder:
        root_folder = source_folder

    p = Path(source_folder)

    if not p.exists():
        raise InvalidArgument('given root path does not exist')

    if not p.is_dir():
        raise InvalidArgument('given root path is not a directory')

    items = [x for x in p.iterdir()]
    items.sort(reverse=True)

    for item in items:
        item_path = str(item)

        if os.path.islink(item_path):
            continue

        if item.is_dir():
            if discovery:
                yield {
github RobertoPrevato / BlackSheep / blacksheep / client / pool.py View on Github external
def _ssl_option(self, ssl):
        if self.scheme == b'https':
            if ssl is None:
                return SECURE_SSLCONTEXT
            if ssl is False:
                return INSECURE_SSLCONTEXT
            if isinstance(ssl, SSLContext):
                return ssl
            raise InvalidArgument('Invalid ssl argument, expected one of: '
                                  '{None, False, True, instance of ssl.SSLContext}')
        if ssl:
            raise InvalidArgument('SSL argument specified for non-https scheme.')
        return None
github RobertoPrevato / BlackSheep / blacksheep / server / files / dynamic.py View on Github external
def serve_files(router,
                source_folder,
                extensions=None,
                discovery=False,
                cache_time=10800):
    if extensions is None:
        extensions = get_default_extensions()

    source_folder_path = Path(source_folder)

    if not source_folder_path.exists():
        raise InvalidArgument('given root path does not exist')

    if not source_folder_path.is_dir():
        raise InvalidArgument('given root path is not a directory')

    route = Route(b'*', get_files_handler(source_folder,
                                          os.path.abspath(source_folder),
                                          discovery,
                                          cache_time,
                                          extensions))
    router.add_route('GET', route)
    router.add_route('HEAD', route)
github RobertoPrevato / BlackSheep / blacksheep / server / files / static.py View on Github external
def get_files_to_serve(source_folder, extensions=None, discovery=False, root_folder=None):
    if extensions is None:
        extensions = get_default_extensions()

    if not root_folder:
        root_folder = source_folder

    p = Path(source_folder)

    if not p.exists():
        raise InvalidArgument('given root path does not exist')

    if not p.is_dir():
        raise InvalidArgument('given root path is not a directory')

    items = [x for x in p.iterdir()]
    items.sort(reverse=True)

    for item in items:
        item_path = str(item)

        if os.path.islink(item_path):
            continue

        if item.is_dir():
            if discovery:
                yield {
                    'rel_path': item_path[len(root_folder):],
                    'full_path': item_path,
                    'is_dir': True
github RobertoPrevato / BlackSheep / blacksheep / server / files / dynamic.py View on Github external
def get_files_to_serve(source_folder, extensions=None, recurse=False, root_folder=None):
    if extensions is None:
        extensions = get_default_extensions()

    if not root_folder:
        root_folder = source_folder

    p = Path(source_folder)

    if not p.exists():
        raise InvalidArgument('given root path does not exist')

    if not p.is_dir():
        raise InvalidArgument('given root path is not a directory')

    names = os.listdir(p)
    names.sort()
    dirs, nondirs = [], []

    for name in names:
        full_path = Path(os.path.join(source_folder, name))
        if os.path.isdir(full_path):
            dirs.append(full_path)
        else:
            nondirs.append(full_path)

    items = dirs + nondirs

    for item in items:
        item_path = str(item)
github RobertoPrevato / BlackSheep / blacksheep / server / files / dynamic.py View on Github external
def get_files_to_serve(source_folder, extensions=None, recurse=False, root_folder=None):
    if extensions is None:
        extensions = get_default_extensions()

    if not root_folder:
        root_folder = source_folder

    p = Path(source_folder)

    if not p.exists():
        raise InvalidArgument('given root path does not exist')

    if not p.is_dir():
        raise InvalidArgument('given root path is not a directory')

    names = os.listdir(p)
    names.sort()
    dirs, nondirs = [], []

    for name in names:
        full_path = Path(os.path.join(source_folder, name))
        if os.path.isdir(full_path):
            dirs.append(full_path)
        else:
            nondirs.append(full_path)

    items = dirs + nondirs