How to use the publ.utils.as_list function in Publ

To help you get started, we’ve selected a few Publ 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 PlaidWeb / Publ / tests / test_utils.py View on Github external
""" test functions involving the ListLike inference class """
    assert utils.is_list((1, 2, 3))
    assert utils.is_list([])
    assert utils.is_list([1, 2, 3])
    assert utils.is_list({1, 2, 3})
    assert utils.is_list(frozenset((1, 2, 3)))
    assert utils.is_list(utils.TagSet(('1', '2', 'A', 'a')))
    assert not utils.is_list("")
    assert not utils.is_list("foo")
    assert not utils.is_list(123)
    assert not utils.is_list(True)
    assert not utils.is_list(None)

    assert utils.as_list([1, 2, 3]) == [1, 2, 3]
    assert utils.as_list((1, 2, 3)) == (1, 2, 3)
    assert utils.as_list("foo") == ("foo",)
    assert utils.as_list(True) == (True,)
    assert utils.as_list(None) == ()
github PlaidWeb / Publ / tests / test_utils.py View on Github external
assert utils.is_list([])
    assert utils.is_list([1, 2, 3])
    assert utils.is_list({1, 2, 3})
    assert utils.is_list(frozenset((1, 2, 3)))
    assert utils.is_list(utils.TagSet(('1', '2', 'A', 'a')))
    assert not utils.is_list("")
    assert not utils.is_list("foo")
    assert not utils.is_list(123)
    assert not utils.is_list(True)
    assert not utils.is_list(None)

    assert utils.as_list([1, 2, 3]) == [1, 2, 3]
    assert utils.as_list((1, 2, 3)) == (1, 2, 3)
    assert utils.as_list("foo") == ("foo",)
    assert utils.as_list(True) == (True,)
    assert utils.as_list(None) == ()
github PlaidWeb / Publ / publ / queries.py View on Github external
def where_entry_tag(query, tags, operation: FilterCombiner):
    """ Generate a where clause for entries with the given tags """
    tags = [t.lower() for t in utils.as_list(tags)]

    if operation == FilterCombiner.ANY:
        return query.filter(lambda e: orm.exists(t for t in e.tags if t.key in tags))

    if operation == FilterCombiner.ALL:
        for tag in tags:
            query = query.filter(lambda e: orm.exists(t for t in e.tags if t.key == tag))
        return query

    if operation == FilterCombiner.NONE:
        for tag in tags:
            query = query.filter(lambda e: not orm.exists(t for t in e.tags if t.key == tag))
        return query

    raise InvalidQueryError("Unsupported FilterCombiner " + str(operation))
github PlaidWeb / Publ / publ / image / __init__.py View on Github external
def get_image(path: str, search_path: typing.Union[str, utils.ListLike[str]]) -> Image:
    """ Get an Image object. If the path is given as absolute, it will be
    relative to the content directory; otherwise it will be relative to the
    search path.

    path -- the image's filename
    search_path -- a search path for the image (string or list of strings)
    """
    return _get_image(path, tuple(utils.as_list(search_path)))
github PlaidWeb / Publ / publ / rendering.py View on Github external
error_codes -- The applicable HTTP error code(s). Will usually be an
        integer or a list of integers; the HTTP error response will always
        be the first error code in the list, and the others are alternates
        for looking up the error template to use.
    exception -- Any exception that led to this error page

    Returns a tuple of (rendered_text, status_code, headers)
    """

    LOGGER.info("Rendering error: category=%s error_message='%s' error_codes=%s exception=%s",
                category,
                error_message,
                error_codes,
                exception)

    error_codes = utils.as_list(error_codes)

    error_code = error_codes[0]
    template_list = [str(code) for code in error_codes]
    template_list.append(str(int(error_code / 100) * 100))
    template_list.append('error')

    template = map_template(category, template_list)
    if template:
        return render_publ_template(
            template,
            category=Category.load(category),
            error={'code': error_code, 'message': error_message},
            exception=exception)[0], error_code, headers

    return '%d %s' % (error_code, error_message), error_code, headers
github PlaidWeb / Publ / publ / html_entry.py View on Github external
def __init__(self,
                 allowed_tags: typing.Iterable[str] = None,
                 allowed_attrs: typing.Iterable[str] = None,
                 remove_elements: typing.Iterable[str] = None):
        super().__init__()
        self._allowed_tags = set(utils.as_list(allowed_tags))
        self._allowed_attrs = set(utils.as_list(allowed_attrs))
        self._remove_elements = set(utils.as_list(remove_elements))
        self._remove_depth = 0