How to use the publ.utils.CallableProxy 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 / publ / view.py View on Github external
for record in self._entries:
                if count is not None and len(result) >= count:
                    break

                auth = record.is_authorized(cur_user)
                if auth or unauthorized:
                    result.append(Entry.load(record))
                    if not auth and unauthorized is not True:
                        unauthorized -= 1

                if not auth:
                    tokens.request(cur_user)

            return result

        return utils.CallableProxy(_entries)
github PlaidWeb / Publ / publ / entry.py View on Github external
def link(self) -> typing.Callable[..., str]:
        """ Get a link to this entry. Accepts the same parameters as permalink;
        may be pre-redirected. """
        def _link(*args, **kwargs) -> str:
            """ Returns a link, potentially pre-redirected """
            if self._record.redirect_url:
                return links.resolve(self._record.redirect_url,
                                     self.search_path, kwargs.get('absolute', False))

            return self.permalink(*args, **kwargs)

        return CallableProxy(_link)
github PlaidWeb / Publ / publ / utils.py View on Github external
def __hash__(self):
        return hash((CallableProxy, self._func))
github PlaidWeb / Publ / publ / category.py View on Github external
all markup (default: True)
        no_smartquotes -- if True, preserve quotes and other characters as originally
            presented
        markdown_extensions -- a list of markdown extensions to use
        """
        if self._meta and self._meta.get('name'):
            # get it from the meta file
            name = self._meta.get('name')
        else:
            # infer it from the basename
            name = self.basename.replace('_', ' ').title()

        def _name(markup=True, no_smartquotes=False, markdown_extensions=None) -> str:
            return markdown.render_title(name, markup, no_smartquotes,
                                         markdown_extensions)
        return utils.CallableProxy(_name)
github PlaidWeb / Publ / publ / utils.py View on Github external
if isinstance(attrs, dict):
        attr_list = attrs.items()
    elif isinstance(attrs, list):
        attr_list = attrs
    elif attrs is not None:
        raise TypeError("Unhandled attrs type " + str(type(attrs)))

    for key, val in attr_list:
        if val is not False:
            text += f' {key}'
            if val is not None:
                import markupsafe
                escaped = html.escape(str(val), False).replace('"', '"')

                if isinstance(val, CallableProxy):
                    val = val()
                if isinstance(val, markupsafe.Markup):
                    # We just double-escaped all entities...
                    escaped = re.sub(r'&([a-zA-Z0-9.\-_\:]+;)', r'&\1', val)
                text += f'="{escaped}"'
    if start_end:
        text += ' /' if attrs else '/'
    text += '>'
    return text
github PlaidWeb / Publ / publ / __init__.py View on Github external
'asset', rendering.retrieve_asset)

        self.add_url_rule('/_token', 'token', tokens.token_endpoint, methods=['POST'])

        self.config['TRAP_HTTP_EXCEPTIONS'] = True
        self.register_error_handler(
            werkzeug.exceptions.HTTPException, rendering.render_exception)

        self.jinja_env.globals.update(  # pylint: disable=no-member
            get_view=view.get_view,
            arrow=arrow,
            static=utils.static_url,
            get_template=rendering.get_template,
            login=utils.auth_link('login'),
            logout=utils.auth_link('logout'),
            token_endpoint=utils.CallableProxy(lambda: utils.secure_link('token')),
            secure_url=utils.secure_link,
        )

        self.jinja_env.filters['strip_html'] = html_entry.strip_html  # pylint: disable=no-member

        caching.init_app(self, self.publ_config.cache)

        self.authl = authl.flask.AuthlFlask(self, self.publ_config.auth,
                                            login_path='/_login',
                                            login_name='login',
                                            callback_path='/_cb',
                                            tester_path='/_ct',
                                            force_ssl=auth_force_https,
                                            login_render_func=rendering.render_login_form)

        def logout(redir=''):
github PlaidWeb / Publ / publ / category.py View on Github external
def tags(self) -> typing.Callable[..., typing.List[TagCount]]:
        """ Get the list of tags associated with this category's entries.

        Takes optional view arguments (including recurse)

        Returns a list of category.TagCount tuples like `(tag='foo', count=5)`
        """
        def _tags(**spec) -> typing.List[TagCount]:
            entries = self._entries(spec)
            tags = orm.select((tag.name, orm.count(tag.key, distinct=False))
                              for e in entries for tag in e.tags)
            return [TagCount(key, count) for (key, count) in tags]
        return utils.CallableProxy(_tags)
github PlaidWeb / Publ / publ / entry.py View on Github external
def login(self) -> typing.Callable[..., str]:
        """ Get a link specifically for logging in to the entry. Not intended for general use;
        might be useful for some future authentication flow. """
        def _loginlink(absolute=False, **kwargs) -> str:
            pagelink = flask.url_for('entry', entry_id=self._record.id, **kwargs)
            return flask.url_for('login', redir=pagelink[1:], _external=absolute)
        return CallableProxy(_loginlink)