Пример #1
0
    def get_urlmap(cls):
        cls._endpoint_map = {}
        urls = []

        for comp in ctx.get_implementations(cls, instances=True):

            # check if url rules are for build only
            if comp.build_only:
                new_map = []
                for rule in comp.url_rules:
                    rule.build_only = True
                    new_map.append(rule)
                comp.url_rules = new_map

            name = comp.name
            # Give subclasses of UrlMixin a way to further modify the rules.
            rules = cls.modify_urlrules(comp)
            if name:
                subdomain, mount = ctx.cfg['routing.urls.' + name].split(':', 1)
                if not comp.ignore_prefix:
                    prefix = name
                    rules = [EndpointPrefix('%s/' % prefix, rules)]

                val = Submount(mount, rules)
                if subdomain != '':
                    val = Subdomain(subdomain, [val])
                urls.append(val)
            else:
                urls.extend(rules)

            cls._endpoint_map.setdefault(name, {}).update(comp.get_endpoint_map())

        return urls
Пример #2
0
 def iter_middlewares(cls):
     """Return all middlewares ordered by priority."""
     if not cls._middlewares:
         cls._middlewares = sorted(
             ctx.get_implementations(cls, instances=True),
             key=lambda x: (- x.priority))
     ret = cls._middlewares
     return ret
Пример #3
0
 def get_search_indexes(cls):
     """
     Generates a name -> `SearchIndex` mapping of all search indexes.
     """
     dct = {}
     for component in ctx.get_implementations(cls, instances=True):
         for index in component.search_indexes:
             dct[index.name] = index
     return dct
Пример #4
0
 def get_search_indexes(cls):
     """
     Generates a name -> `SearchIndex` mapping of all search indexes.
     """
     dct = {}
     for component in ctx.get_implementations(cls, instances=True):
         for index in component.search_indexes:
             dct[index.name] = index
     return dct
Пример #5
0
    def __init__(self, string, transformers=None):
        """
        In theory you never have to instanciate this parser yourself because
        the high level `parse()` function encapsulates this.  However for the
        unittests it's important to be able to disable and enable the
        `transformers` by hand.  If you don't provide any transformers the
        default transformers are used.
        """
        self.string = string
        self.lexer = Lexer()
        self.stack_depth = 0
        if transformers is None:
            transformers = ctx.get_implementations(ITransformer,
                                                   instances=True)
        self.transformers = transformers

        #: node dispatchers
        self._handlers = {
            'text': self.parse_text,
            'raw': self.parse_raw,
            'nl': self.parse_nl,
            'highlighted_begin': self.parse_highlighted,
            'conflict_begin': self.parse_conflict_left,
            'conflict_switch': self.parse_conflict_middle,
            'conflict_end': self.parse_conflict_end,
            'metadata_begin': self.parse_metadata,
            'headline_begin': self.parse_headline,
            'strong_begin': self.parse_strong,
            'emphasized_begin': self.parse_emphasized,
            'escaped_code_begin': self.parse_escaped_code,
            'code_begin': self.parse_code,
            'underline_begin': self.parse_underline,
            'stroke_begin': self.parse_stroke,
            'small_begin': self.parse_small,
            'big_begin': self.parse_big,
            'sub_begin': self.parse_sub,
            'sup_begin': self.parse_sup,
            'footnote_begin': self.parse_footnote,
            'color_begin': self.parse_color,
            'size_begin': self.parse_size,
            'font_begin': self.parse_font,
            'quote_begin': self.parse_quote,
            'list_item_begin': self.parse_list,
            'definition_begin': self.parse_definition,
            'external_link_begin': self.parse_external_link,
            'free_link': self.parse_free_link,
            'ruler': self.parse_ruler,
            'pre_begin': self.parse_pre_block,
            'table_row_begin': self.parse_table,
            'box_begin': self.parse_box,
            'sourcelink': self.parse_source_link
        }

        #: runtime information
        self.is_dirty = False
Пример #6
0
 def get_search_providers(cls):
     """
     Generates a dictionary whose keys are the search index names and whose
     values are dictionaries of the search providers belonging to them.
     """
     dct = {}
     for component in ctx.get_implementations(cls, instances=True):
         for provider in component.search_providers:
             dct.setdefault(provider.index, {})
             dct[provider.index][provider.name] = provider
     return dct
Пример #7
0
    def __init__(self, string, transformers=None):
        """
        In theory you never have to instanciate this parser yourself because
        the high level `parse()` function encapsulates this.  However for the
        unittests it's important to be able to disable and enable the
        `transformers` by hand.  If you don't provide any transformers the
        default transformers are used.
        """
        self.string = string
        self.lexer = Lexer()
        self.stack_depth = 0
        if transformers is None:
            transformers = ctx.get_implementations(ITransformer, instances=True)
        self.transformers = transformers

        #: node dispatchers
        self._handlers = {
            'text':                 self.parse_text,
            'raw':                  self.parse_raw,
            'nl':                   self.parse_nl,
            'highlighted_begin':    self.parse_highlighted,
            'conflict_begin':       self.parse_conflict_left,
            'conflict_switch':      self.parse_conflict_middle,
            'conflict_end':         self.parse_conflict_end,
            'metadata_begin':       self.parse_metadata,
            'headline_begin':       self.parse_headline,
            'strong_begin':         self.parse_strong,
            'emphasized_begin':     self.parse_emphasized,
            'escaped_code_begin':   self.parse_escaped_code,
            'code_begin':           self.parse_code,
            'underline_begin':      self.parse_underline,
            'stroke_begin':         self.parse_stroke,
            'small_begin':          self.parse_small,
            'big_begin':            self.parse_big,
            'sub_begin':            self.parse_sub,
            'sup_begin':            self.parse_sup,
            'footnote_begin':       self.parse_footnote,
            'color_begin':          self.parse_color,
            'size_begin':           self.parse_size,
            'font_begin':           self.parse_font,
            'quote_begin':          self.parse_quote,
            'list_item_begin':      self.parse_list,
            'definition_begin':     self.parse_definition,
            'external_link_begin':  self.parse_external_link,
            'free_link':            self.parse_free_link,
            'ruler':                self.parse_ruler,
            'pre_begin':            self.parse_pre_block,
            'table_row_begin':      self.parse_table,
            'box_begin':            self.parse_box,
            'sourcelink':           self.parse_source_link
        }

        #: runtime information
        self.is_dirty = False
Пример #8
0
 def get_search_providers(cls):
     """
     Generates a dictionary whose keys are the search index names and whose
     values are dictionaries of the search providers belonging to them.
     """
     dct = {}
     for component in ctx.get_implementations(cls, instances=True):
         for provider in component.search_providers:
             dct.setdefault(provider.index, {})
             dct[provider.index][provider.name] = provider
     return dct
Пример #9
0
    def __init__(self):
        loaders = {}
        for resource in ctx.get_implementations(IResourceManager, instances=True):
            loaders[resource.resource_name] = FileSystemLoader(resource.templates_path)

        loader = ChoiceLoader([FileSystemLoader(ctx.cfg['templates.path']),
                               PrefixLoader(loaders)])

        cache_obj = None
        if ctx.cfg['templates.use_cache']:
            if ctx.cfg['templates.use_memcached_cache']:
                cache_obj = MemcachedBytecodeCache(
                    client=inyoka_cache,
                    timeout=ctx.cfg['caching.timeout']
                )
            elif ctx.cfg['templates.use_filesystem_cache']:
                cache_obj = FileSystemBytecodeCache(
                    directory=ctx.cfg['caching.filesystem_cache_path'],
                )

        Environment.__init__(self,
            loader=loader,
            extensions=['jinja2.ext.i18n', 'jinja2.ext.do', 'jinja2.ext.with_',
                        'jinja2.ext.autoescape'],
            auto_reload=ctx.cfg['templates.auto_reload'],
            undefined=StrictUndefined,
            cache_size=-1,
            bytecode_cache=cache_obj,
            autoescape=True
        )

        self.globals.update(
            INYOKA_REVISION=INYOKA_REVISION,
            PYTHON_VERSION='%d.%d.%d' % sys.version_info[:3],
            DEBUG=ctx.cfg['debug'],
            href=href,
        )
        self.filters.update(
            jsonencode=json.dumps,
            datetimeformat=l10n.format_datetime,
            dateformat=l10n.format_date,
            timeformat=l10n.format_time,
            timedelta=l10n.timedeltaformat,
            monthformat=l10n.format_month,
            dayformatshort=l10n.format_day_short,
            humanize=l10n.humanize_number,
        )
        self.install_gettext_translations(
            i18n.get_translations(),
            newstyle=True
        )
Пример #10
0
    def get_models(cls, tables=False):
        """Generator that yields all registered models.  Yields tables
        if `tables` is set to True.
        """
        for component in ctx.get_implementations(cls, instances=True):
            for model in component.models:
                is_table = isinstance(model, Table)
                if is_table and not tables:
                    continue

                if is_table and tables:
                    yield model
                else:
                    yield model.__table__ if tables else model
Пример #11
0
    def get_models(cls, tables=False):
        """Generator that yields all registered models.  Yields tables
        if `tables` is set to True.
        """
        for component in ctx.get_implementations(cls, instances=True):
            for model in component.models:
                is_table = isinstance(model, Table)
                if is_table and not tables:
                    continue

                if is_table and tables:
                    yield model
                else:
                    yield model.__table__ if tables else model
Пример #12
0
    def tag(self, request, slug):
        tag = Tag.query.filter_by(slug=slug).one()
        providers = ctx.get_implementations(ITaggableContentProvider, instances=True)
        content = []
        for provider in providers:
            content.append({
                'item_list': provider.get_taggable_content(tag).all(),
                'list_class': provider.type,
                'name': provider.name
            })

        return {
            'tag': tag,
            'content': content,
        }
Пример #13
0
 def __init__(self, ctx):
     IController.__init__(self, ctx)
     self.extensions = dict((ext.ext_key, ext.ext_name)
         for ext in ctx.get_implementations(UserCPExtension))