当前位置: 首页>>代码示例>>Python>>正文


Python utils._resolveDottedName函数代码示例

本文整理汇总了Python中utils._resolveDottedName函数的典型用法代码示例。如果您正苦于以下问题:Python _resolveDottedName函数的具体用法?Python _resolveDottedName怎么用?Python _resolveDottedName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了_resolveDottedName函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _initUtilities

    def _initUtilities(self, node):
        for child in node.childNodes:
            if child.nodeName != 'utility':
                continue

            provided = _resolveDottedName(child.getAttribute('interface'))
            name = unicode(str(child.getAttribute('name')))

            component = child.getAttribute('component')
            component = component and _resolveDottedName(component) or None

            factory = child.getAttribute('factory')
            factory = factory and _resolveDottedName(factory) or None

            obj_path = child.getAttribute('object')
            if obj_path:
                site = self.environ.getSite()
                # we support registering aq_wrapped objects only for now
                if hasattr(site, 'aq_base'):
                    # filter out empty path segments
                    path = [f for f in obj_path.split('/') if f]
                    # support for nested folder
                    obj = self._recurseFolder(site, path)
                    if obj is not None:
                        self.context.registerUtility(obj, provided, name)
                else:
                    # Log an error, not aq_wrapped
                    self._logger.warning("The object %s was not acquisition "
                                         "wrapped. Registering these is not "
                                         "supported right now." % obj_path)
            elif component:
                self.context.registerUtility(component, provided, name)
            else:
                self.context.registerUtility(factory(), provided, name)
开发者ID:goschtl,项目名称:zope,代码行数:34,代码来源:components.py

示例2: _updateImportStepsRegistry

    def _updateImportStepsRegistry( self, encoding ):

        """ Update our import steps registry from our profile.
        """
        context = self._getImportContext(self._import_context_id)
        xml = context.readDataFile(IMPORT_STEPS_XML)

        info_list = self._import_registry.parseXML( xml, encoding )

        for step_info in info_list:

            id = step_info[ 'id' ]
            version = step_info[ 'version' ]
            handler = _resolveDottedName( step_info[ 'handler' ] )

            dependencies = tuple( step_info.get( 'dependencies', () ) )
            title = step_info.get( 'title', id )
            description = ''.join( step_info.get( 'description', [] ) )

            self._import_registry.registerStep( id=id
                                              , version=version
                                              , handler=handler
                                              , dependencies=dependencies
                                              , title=title
                                              , description=description
                                              )
开发者ID:goschtl,项目名称:zope,代码行数:26,代码来源:tool.py

示例3: _updateExportStepsRegistry

    def _updateExportStepsRegistry( self, encoding ):

        """ Update our export steps registry from our profile.
        """
        fq = self._getFullyQualifiedProfileDirectory()

        f = open( os.path.join( fq, EXPORT_STEPS_XML ), 'r' )
        xml = f.read()
        f.close()

        info_list = self._export_registry.parseXML( xml, encoding )

        for step_info in info_list:

            id = step_info[ 'id' ]
            handler = _resolveDottedName( step_info[ 'handler' ] )

            title = step_info.get( 'title', id )
            description = ''.join( step_info.get( 'description', [] ) )

            self._export_registry.registerStep( id=id
                                              , handler=handler
                                              , title=title
                                              , description=description
                                              )
开发者ID:goschtl,项目名称:zope,代码行数:25,代码来源:tool.py

示例4: registerStep

    def registerStep(self, id, handler, title=None, description=None):

        """ Register an export step.

        o 'id' is the unique identifier for this step

        o 'handler' is the dottoed name of a handler which should implement
           IImportPlugin.

        o 'title' is a one-line UI description for this step.
          If None, the first line of the documentation string of the step
          is used, or the id if no docstring can be found.

        o 'description' is a one-line UI description for this step.
          If None, the remaining line of the documentation string of
          the step is used, or default to ''.
        """
        if not isinstance(handler, str):
            handler = _getDottedName(handler)

        if title is None or description is None:

            method = _resolveDottedName(handler)
            if method is None:
                t, d = id, ""
            else:
                t, d = _extractDocstring(method, id, "")

            title = title or t
            description = description or d

        info = {"id": id, "handler": handler, "title": title, "description": description}

        self._registered[id] = info
开发者ID:dtgit,项目名称:dtedu,代码行数:34,代码来源:registry.py

示例5: _initUtilities

    def _initUtilities(self, node):
        for child in node.childNodes:
            if child.nodeName != 'utility':
                continue

            provided = _resolveDottedName(child.getAttribute('interface'))
            name = unicode(str(child.getAttribute('name')))

            component = child.getAttribute('component')
            component = component and _resolveDottedName(component) or None

            factory = child.getAttribute('factory')
            factory = factory and _resolveDottedName(factory) or None

            obj_path = child.getAttribute('object')
            if not component and not factory and obj_path is not None:
                # Get the site by either __parent__ or Acquisition
                site = getattr(self.context, '__parent__', None)
                if site is None:
                    site = aq_parent(self.context)
                # Support for registering the site itself
                if obj_path in ('', '/'):
                    obj = site
                else:
                    # BBB: filter out path segments, we did claim to support
                    # nested paths once
                    id_ = [p for p in obj_path.split('/') if p][0]
                    obj = getattr(site, id_, None)

                if obj is not None:
                    self.context.registerUtility(aq_base(obj), provided, name)
                else:
                    # Log an error, object not found
                    self._logger.warning("The object %s was not found, while "
                                         "trying to register an utility. The "
                                         "provided object definition was %s. "
                                         "The site used was: %s"
                                         % (path, obj_path, repr(site)))
            elif component:
                self.context.registerUtility(component, provided, name)
            elif factory is not None:
                self.context.registerUtility(factory(), provided, name)
            else:
                self._logger.warning("Invalid utility registration for "
                                     "interface %s" % provided)
开发者ID:goschtl,项目名称:zope,代码行数:45,代码来源:components.py

示例6: _initAdapters

    def _initAdapters(self, node):
        for child in node.childNodes:
            if child.nodeName != 'adapter':
                continue

            factory = _resolveDottedName(child.getAttribute('factory'))
            provided = _resolveDottedName(child.getAttribute('provides'))
            name = unicode(str(child.getAttribute('name')))

            for_ = child.getAttribute('for_')
            required = []
            for interface in for_.split(u' '):
                if interface:
                    required.append(_resolveDottedName(interface))

            self.context.registerAdapter(factory,
                                         required=required,
                                         provided=provided,
                                         name=name)
开发者ID:dtgit,项目名称:dtedu,代码行数:19,代码来源:components.py

示例7: importToolset

def importToolset(context):

    """ Import required / forbidden tools from XML file.
    """
    site = context.getSite()
    encoding = context.getEncoding()
    logger = context.getLogger('toolset')

    xml = context.readDataFile(TOOLSET_XML)
    if xml is None:
        logger.info('Nothing to import.')
        return

    setup_tool = context.getSetupTool()
    toolset = setup_tool.getToolsetRegistry()

    toolset.parseXML(xml, encoding)

    existing_ids = site.objectIds()
    existing_values = site.objectValues()

    for tool_id in toolset.listForbiddenTools():

        if tool_id in existing_ids:
            site._delObject(tool_id)

    for info in toolset.listRequiredToolInfo():

        tool_id = str(info['id'])
        tool_class = _resolveDottedName(info['class'])

        existing = getattr(aq_base(site), tool_id, None)
        # Don't even initialize the tool again, if it already exists.
        if existing is None:
            try:
                new_tool = tool_class()
            except TypeError:
                new_tool = tool_class(tool_id)
            else:
                try:
                    new_tool._setId(tool_id)
                except (ConflictError, KeyboardInterrupt):
                    raise
                except:
                    # XXX: ImmutableId raises result of calling MessageDialog
                    pass

            site._setObject(tool_id, new_tool)
        else:
            unwrapped = aq_base(existing)
            if not isinstance(unwrapped, tool_class):
                site._delObject(tool_id)
                site._setObject(tool_id, tool_class())

    logger.info('Toolset imported.')
开发者ID:dtgit,项目名称:dtedu,代码行数:55,代码来源:tool.py

示例8: getStep

    def getStep( self, key, default=None ):

        """ Return the IExportPlugin registered for 'key'.

        o Return 'default' if no such step is registered.
        """
        marker = object()
        info = self._registered.get( key, marker )

        if info is marker:
            return default

        return _resolveDottedName( info[ 'handler' ] )
开发者ID:goschtl,项目名称:zope,代码行数:13,代码来源:registry.py

示例9: importToolset

def importToolset(context):

    """ Import required / forbidden tools from XML file.
    """
    site = context.getSite()
    encoding = context.getEncoding()

    xml = context.readDataFile(TOOLSET_XML)
    if xml is None:
        return 'Toolset: Nothing to import.'

    setup_tool = context.getSetupTool()
    toolset = setup_tool.getToolsetRegistry()

    toolset.parseXML(xml, encoding)

    existing_ids = site.objectIds()
    existing_values = site.objectValues()

    for tool_id in toolset.listForbiddenTools():

        if tool_id in existing_ids:
            site._delObject(tool_id)

    for info in toolset.listRequiredToolInfo():

        tool_id = str(info['id'])
        tool_class = _resolveDottedName(info['class'])

        existing = getattr(site, tool_id, None)
        new_tool = tool_class() # XXX: new_tool = mapply(tool_class, info)

        try:
            new_tool._setId(tool_id)
        except: # XXX:  ImmutableId raises result of calling MessageDialog
            pass

        if existing is None:
            site._setObject(tool_id, new_tool)

        else:
            unwrapped = aq_base(existing)
            if not isinstance(unwrapped, tool_class):
                site._delObject(tool_id)
                site._setObject(tool_id, tool_class())

    return 'Toolset imported.'
开发者ID:goschtl,项目名称:zope,代码行数:47,代码来源:tool.py

示例10: getStepMetadata

    def getStepMetadata( self, key, default=None ):

        """ Return a mapping of metadata for the step identified by 'key'.

        o Return 'default' if no such step is registered.

        o The 'handler' metadata is available via 'getStep'.
        """
        info = self._registered.get( key )

        if info is None:
            return default

        result = info.copy()
        result['invalid'] =  _resolveDottedName( result[ 'handler' ] ) is None

        return result
开发者ID:goschtl,项目名称:zope,代码行数:17,代码来源:registry.py

示例11: importToolset

def importToolset( context ):

    """ Import required / forbidden tools from XML file.
    """
    site = context.getSite()
    encoding = context.getEncoding()

    xml = context.readDataFile(TOOLSET_XML)
    if xml is None:
        return 'Toolset: Nothing to import.'

    setup_tool = getToolByName( site, 'portal_setup' )
    toolset = setup_tool.getToolsetRegistry()

    toolset.parseXML(xml, encoding)

    existing_ids = site.objectIds()
    existing_values = site.objectValues()

    for tool_id in toolset.listForbiddenTools():

        if tool_id in existing_ids:
            site._delObject( tool_id )

    for info in toolset.listRequiredToolInfo():

        tool_id = str( info[ 'id' ] )
        tool_class = _resolveDottedName( info[ 'class' ] )

        existing = getToolByName( site, tool_id, None )
        new_tool = tool_class()

        if not isinstance( new_tool, ImmutableId ):
            new_tool._setId( tool_id )

        if existing is None:
            site._setObject( tool_id, new_tool )

        else:
            unwrapped = aq_base( existing )
            if not isinstance( unwrapped, tool_class ):
                site._delObject( tool_id )
                site._setObject( tool_id, new_tool )

    return 'Toolset imported.'
开发者ID:goschtl,项目名称:zope,代码行数:45,代码来源:tool.py

示例12: _makeInstance

    def _makeInstance(self, instance_id, type_name, subdir, import_context):

        context = self.context
        class _OldStyleClass:
            pass

        if '.' in type_name:

            factory = _resolveDottedName(type_name)

            if getattr(factory, '__bases__', None) is not None:

                def _factory(instance_id,
                             container=self.context,
                             klass=factory):
                    try:
                        instance = klass(instance_id)
                    except (TypeError, ValueError):
                        instance = klass()
                    instance._setId(instance_id)
                    container._setObject(instance_id, instance)

                    return instance

                factory = _factory

        else:
            factory = queryNamedAdapter(self.context,
                                        IContentFactory,
                                        name=type_name,
                                       )
        if factory is None:
            return None

        try:
            instance = factory(instance_id)
        except ValueError: # invalid type
            return None

        if context._getOb(instance_id, None) is None:
            context._setObject(instance_id, instance) 

        return context._getOb(instance_id)
开发者ID:goschtl,项目名称:zope,代码行数:43,代码来源:content.py


注:本文中的utils._resolveDottedName函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。