• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python ObjectManager.bad_id函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: prepareContents

 def prepareContents(self, registry, register_subdirs=0):
     # Creates objects for each file.
     fp = expandpath(self.filepath)
     data = {}
     l = listdir(fp)
     types = self._readTypesFile()
     for entry in l:
         if not self._isAllowableFilename(entry):
             continue
         e_filepath = path.join(self.filepath, entry)
         e_fp = expandpath(e_filepath)
         if path.isdir(e_fp):
             # Add a subdirectory only if it was previously registered,
             # unless register_subdirs is set.
             info = registry.getDirectoryInfo(e_filepath)
             if info is None and register_subdirs:
                 # Register unknown subdirs
                 if entry not in ('CVS', 'SVN', '.', '..'):
                     registry.registerDirectoryByPath(e_fp)
                     info = registry.getDirectoryInfo(e_filepath)
             if info is not None:
                 mt = types.get(entry)
                 t = None
                 if mt is not None:
                     t = registry.getTypeByMetaType(mt)
                 if t is None:
                     t = DirectoryView
                 ob = t(entry, e_filepath)
                 data[ob.getId()] = ob
         else:
             pos = rfind(entry, '.')
             if pos >= 0:
                 name = entry[:pos]
                 ext = normalize(entry[pos + 1:])
             else:
                 name = entry
                 ext = ''
             if not name or bad_id(entry) != -1 or name == 'REQUEST':
                 # Not an allowable id.
                 continue
             t = None
             mt = types.get(entry, None)
             if mt is None:
                 mt = types.get(name, None)
             if mt is not None:
                 t = registry.getTypeByMetaType(mt)
             if t is None:
                 t = registry.getTypeByExtension(ext)
             if t is not None:
                 ob = t(name, e_filepath, fullname=entry)
                 data[ob.getId()] = ob
     return data
开发者ID:goschtl,项目名称:zope,代码行数:52,代码来源:DirectoryView.py


示例2: _checkId

 def _checkId(self, id):
     """See if an id is valid CMF/Plone id"""
     portal = getToolByName(self, 'portal_url').getPortalObject()
     if not id:
         return 'Empty id'
     s = bad_id(id)
     if s:
         return '\'%s\' is not a valid id' % (id)
     # extra checks for Plone sites
     if portal.__class__.__name__ == 'PloneSite':
         if hasattr(portal, 'portal_properties') and \
             hasattr(portal.portal_properties, 'site_properties') and \
             hasattr(portal.portal_properties.site_properties, 'invalid_ids'):
             if id in portal.portal_properties.site_properties.invalid_ids:
                 return '\'%s\' is a reserved id' % (id)
开发者ID:dtgit,项目名称:dtedu,代码行数:15,代码来源:FormController.py


示例3: good_id

 def good_id(self, id):
     # Exposes ObjectManager's bad_id test to skin scripts.
     m = bad_id(id)
     if m is not None:
         return 0
     return 1
开发者ID:erral,项目名称:Products.CMFPlone,代码行数:6,代码来源:PloneTool.py


示例4: prepareContents

    def prepareContents(self, registry, register_subdirs=0):
        # Creates objects for each file.
        data = {}
        objects = []
        types = self._readTypesFile()
        for entry in _filtered_listdir(self._filepath, ignore=self.ignore):
            if not self._isAllowableFilename(entry):
                continue
            entry_filepath = path.join(self._filepath, entry)
            if path.isdir(entry_filepath):
                # Add a subdirectory only if it was previously registered,
                # unless register_subdirs is set.
                entry_minimal_fp = '/'.join( (self._minimal_fp, entry) )
                info = registry.getDirectoryInfo(entry_minimal_fp)
                if info is None and register_subdirs:
                    # Register unknown subdirs
                    registry.registerDirectoryByPath(entry_filepath)
                    info = registry.getDirectoryInfo(entry_minimal_fp)
                if info is not None:
                    # Folders on the file system have no extension or
                    # meta_type, as a crutch to enable customizing what gets
                    # created to represent a filesystem folder in a
                    # DirectoryView we use a fake type "FOLDER". That way
                    # other implementations can register for that type and
                    # circumvent the hardcoded assumption that all filesystem
                    # directories will turn into DirectoryViews.
                    mt = types.get(entry) or 'FOLDER'
                    t = registry.getTypeByMetaType(mt)
                    if t is None:
                        t = DirectoryView
                    metadata = FSMetadata(entry_filepath)
                    metadata.read()
                    ob = t( entry
                          , entry_minimal_fp
                          , properties=metadata.getProperties()
                          )
                    ob_id = ob.getId()
                    data[ob_id] = ob
                    objects.append({'id': ob_id, 'meta_type': ob.meta_type})
            else:
                pos = entry.rfind('.')
                if pos >= 0:
                    name = entry[:pos]
                    ext = path.normcase(entry[pos + 1:])
                else:
                    name = entry
                    ext = ''
                if not name or name == 'REQUEST':
                    # Not an allowable id.
                    continue
                mo = bad_id(name)
                if mo is not None and mo != -1:  # Both re and regex formats
                    # Not an allowable id.
                    continue
                t = None
                mt = types.get(entry, None)
                if mt is None:
                    mt = types.get(name, None)
                if mt is not None:
                    t = registry.getTypeByMetaType(mt)
                if t is None:
                    t = registry.getTypeByExtension(ext)

                if t is not None:
                    metadata = FSMetadata(entry_filepath)
                    metadata.read()
                    try:
                        ob = t(name, entry_filepath, fullname=entry,
                               properties=metadata.getProperties())
                    except:
                        import sys
                        import traceback
                        typ, val, tb = sys.exc_info()
                        try:
                            logger.exception("prepareContents")

                            exc_lines = traceback.format_exception( typ,
                                                                    val,
                                                                    tb )
                            ob = BadFile( name,
                                          entry_filepath,
                                          exc_str='\r\n'.join(exc_lines),
                                          fullname=entry )
                        finally:
                            tb = None   # Avoid leaking frame!

                    # FS-based security
                    permissions = metadata.getSecurity()
                    if permissions is not None:
                        for name in permissions.keys():
                            acquire, roles = permissions[name]
                            try:
                                ob.manage_permission(name,roles,acquire)
                            except ValueError:
                                logger.exception("Error setting permissions")

                    # only DTML Methods and Python Scripts can have proxy roles
                    if hasattr(ob, '_proxy_roles'):
                        try:
                            ob._proxy_roles = tuple(metadata.getProxyRoles())
#.........这里部分代码省略.........
开发者ID:goschtl,项目名称:zope,代码行数:101,代码来源:DirectoryView.py


示例5: checkId

def checkId(id):
    res = bad_id(id)
    if res != -1 and res is not None:
        raise ValueError, 'Illegal ID'
    return 1
开发者ID:goschtl,项目名称:zope,代码行数:5,代码来源:DCWorkflow.py


示例6: prepareContents

    def prepareContents(self, registry, register_subdirs=0):
        # Creates objects for each file.
        fp = expandpath(self.filepath)
        data = {}
        objects = []
        types = self._readTypesFile()
        for entry in _filtered_listdir(fp):
            if not self._isAllowableFilename(entry):
                continue
            e_filepath = path.join(self.filepath, entry)
            e_fp = expandpath(e_filepath)
            if path.isdir(e_fp):
                # Add a subdirectory only if it was previously registered,
                # unless register_subdirs is set.
                info = registry.getDirectoryInfo(e_filepath)
                if info is None and register_subdirs:
                    # Register unknown subdirs
                    registry.registerDirectoryByPath(e_fp)
                    info = registry.getDirectoryInfo(e_filepath)
                if info is not None:
                    mt = types.get(entry)
                    t = None
                    if mt is not None:
                        t = registry.getTypeByMetaType(mt)
                    if t is None:
                        t = DirectoryView
                    ob = t(entry, e_filepath)
                    ob_id = ob.getId()
                    data[ob_id] = ob
                    objects.append({'id': ob_id, 'meta_type': ob.meta_type})
            else:
                pos = rfind(entry, '.')
                if pos >= 0:
                    name = entry[:pos]
                    ext = path.normcase(entry[pos + 1:])
                else:
                    name = entry
                    ext = ''
                if not name or name == 'REQUEST':
                    # Not an allowable id.
                    continue
                mo = bad_id(name)
                if mo is not None and mo != -1:  # Both re and regex formats
                    # Not an allowable id.
                    continue
                t = None
                mt = types.get(entry, None)
                if mt is None:
                    mt = types.get(name, None)
                if mt is not None:
                    t = registry.getTypeByMetaType(mt)
                if t is None:
                    t = registry.getTypeByExtension(ext)
                
                if t is not None:
                    properties = self._readProperties(
                        e_fp + '.properties')
                    try:
                        ob = t(name, e_filepath, fullname=entry,
                               properties=properties)
                    except:
                        import traceback
                        typ, val, tb = exc_info()
                        try:
                            exc_lines = traceback.format_exception( typ,
                                                                    val,
                                                                    tb )
                            LOG( 'DirectoryView',
                                 ERROR,
                                 join( exc_lines, '\n' ) )
                            
                            ob = BadFile( name,
                                          e_filepath,
                                          exc_str=join( exc_lines, '\r\n' ),
                                          fullname=entry )
                        finally:
                            tb = None   # Avoid leaking frame!
                            
                    # FS-based security
                    try:
                        permissions = self._readSecurity(e_fp + '.security')
                        if permissions is not None:
                            for name in permissions.keys():
                                acquire,roles = permissions[name]
                                ob.manage_permission(name,roles,acquire)
                    except:
                        LOG('DirectoryView',
                            ERROR,
                            'Error setting permission from .security file information',
                            error=exc_info())

                    ob_id = ob.getId()
                    data[ob_id] = ob
                    objects.append({'id': ob_id, 'meta_type': ob.meta_type})
                    
        return data, tuple(objects)
开发者ID:goschtl,项目名称:zope,代码行数:96,代码来源:DirectoryView.py


示例7: prepareContents

    def prepareContents(self, registry, register_subdirs=0):
        # Creates objects for each file.
        data = {}
        objects = []
        types = self._readTypesFile()
        for entry in _filtered_listdir(self._filepath):
            if not self._isAllowableFilename(entry):
                continue
            entry_minimal_fp = '/'.join( (self._minimal_fp, entry) )
            entry_filepath = path.join(self._filepath, entry)
            if path.isdir(entry_filepath):
                # Add a subdirectory only if it was previously registered,
                # unless register_subdirs is set.
                info = registry.getDirectoryInfo(entry_minimal_fp)
                if info is None and register_subdirs:
                    # Register unknown subdirs
                    registry.registerDirectoryByPath(entry_filepath)
                    info = registry.getDirectoryInfo(entry_minimal_fp)
                if info is not None:
                    mt = types.get(entry)
                    t = None
                    if mt is not None:
                        t = registry.getTypeByMetaType(mt)
                    if t is None:
                        t = DirectoryView
                    ob = t(entry, entry_minimal_fp)
                    ob_id = ob.getId()
                    data[ob_id] = ob
                    objects.append({'id': ob_id, 'meta_type': ob.meta_type})
            else:
                pos = entry.rfind('.')
                if pos >= 0:
                    name = entry[:pos]
                    ext = path.normcase(entry[pos + 1:])
                else:
                    name = entry
                    ext = ''
                if not name or name == 'REQUEST':
                    # Not an allowable id.
                    continue
                mo = bad_id(name)
                if mo is not None and mo != -1:  # Both re and regex formats
                    # Not an allowable id.
                    continue
                t = None
                mt = types.get(entry, None)
                if mt is None:
                    mt = types.get(name, None)
                if mt is not None:
                    t = registry.getTypeByMetaType(mt)
                if t is None:
                    t = registry.getTypeByExtension(ext)

                if t is not None:
                    metadata = FSMetadata(entry_filepath)
                    metadata.read()
                    try:
                        ob = t(name, entry_minimal_fp, fullname=entry,
                               properties=metadata.getProperties())
                    except:
                        import traceback
                        typ, val, tb = exc_info()
                        try:
                            exc_lines = traceback.format_exception( typ,
                                                                    val,
                                                                    tb )
                            LOG( 'DirectoryView', ERROR,
                                 '\n'.join(exc_lines) )

                            ob = BadFile( name,
                                          entry_minimal_fp,
                                          exc_str='\r\n'.join(exc_lines),
                                          fullname=entry )
                        finally:
                            tb = None   # Avoid leaking frame!

                    # FS-based security
                    permissions = metadata.getSecurity()
                    if permissions is not None:
                        for name in permissions.keys():
                            acquire, roles = permissions[name]
                            try:
                                ob.manage_permission(name,roles,acquire)
                            except ValueError:
                                LOG('DirectoryView',
                                    ERROR,
                                    'Error setting permissions',
                                    error=exc_info())

                    # only DTML Methods can have proxy roles
                    if hasattr(ob, '_proxy_roles'):
                        try:
                            ob._proxy_roles = tuple(metadata.getProxyRoles())
                        except:
                            LOG('DirectoryView',
                                ERROR,
                                'Error setting proxy role',
                                error=exc_info())

                    ob_id = ob.getId()
#.........这里部分代码省略.........
开发者ID:goschtl,项目名称:zope,代码行数:101,代码来源:DirectoryView.py


示例8: __iter__

    def __iter__(self):
        for item in self.previous:
            yield item

        filename = os.path.join(self.source, 'wp_posts.csv')
        assert os.path.isfile(filename), 'Missing file: ' + filename

        with open(filename) as csvfile:
            csv.field_size_limit(self.field_size_limit)
            reader = csv.DictReader(csvfile, **csv_options)
            for row in reader:

                if _skip(row, self.skip):  # should we process this row?
                    continue

                item = dict()
                post_type = row['post_type']

                if post_type == 'post':
                    # posts are imported as portal_type
                    item['portal_type'] = self.portal_type
                elif post_type == 'page':
                    # pages are imported as Page
                    item['portal_type'] = 'Page'
                elif post_type == 'attachment':
                    # attachments are imported as Image or File
                    is_image = row['post_mime_type'].startswith('image')
                    item['portal_type'] = 'Image' if is_image else 'File'
                    item['_mimetype'] = row['post_mime_type']
                    item['_guid'] = row['guid']  # store for later

                if post_type != 'attachment':
                    # for posts and pages the id is the post name
                    item_id = row['post_name']
                    # Zope ids need to be ASCII
                    item_id = fix_id(item_id)
                    item['title'] = strip_tags(row['post_title'])
                else:
                    # for attachments we need to parse the guid
                    # and use the file name as title
                    url = urlparse(row['guid'])
                    item_id = item['title'] = url.path.split('/')[-1]
                    item_id = fix_id(item_id)

                # on Zope ids can't start with "_"
                if bad_id(item_id) is not None:
                    logger.warn('Invalid object id on row ID: ' + row['ID'])
                    continue

                # WordPress stores only publication and modification times
                # we use publication date as creation date
                item['creation_date'] = item['effective_date'] = row['post_date']
                item['modification_date'] = row['post_modified']

                try:
                    item['_path'] = self.get_path(row['ID'], item_id, post_type, item)
                except KeyError:
                    # files defining taxonomies are probably outdated
                    logger.warn('No taxonomies found for row ID: ' + row['ID'])
                    continue

                item['description'] = row['post_excerpt']

                # quotes are escaped; we need to fix that
                item['text'] = row['post_content'].replace('\\"', '"')
                # TODO: validate HTML to avoid post-processing surprises

                # use display_name instead of author_id, if match found
                author_id = row['post_author']
                item['creators'] = self.display_names.get(author_id, author_id)

                if row['post_status'] == 'publish':
                    item['_transitions'] = 'publish'

                item['_pinged'] = row['pinged']  # store for later

                yield item
开发者ID:collective,项目名称:transmogrify.wordpress,代码行数:77,代码来源:csvsource.py


示例9: prepareContents

 def prepareContents(self, registry, register_subdirs=0):
     # Creates objects for each file.
     fp = expandpath(self.filepath)
     data = {}
     objects = []
     l = listdir(fp)
     types = self._readTypesFile()
     for entry in l:
         if not self._isAllowableFilename(entry):
             continue
         e_filepath = path.join(self.filepath, entry)
         e_fp = expandpath(e_filepath)
         if path.isdir(e_fp):
             # Add a subdirectory only if it was previously registered,
             # unless register_subdirs is set.
             info = registry.getDirectoryInfo(e_filepath)
             if info is None and register_subdirs:
                 # Register unknown subdirs
                 if entry not in ('CVS', 'SVN', '.', '..'):
                     registry.registerDirectoryByPath(e_fp)
                     info = registry.getDirectoryInfo(e_filepath)
             if info is not None:
                 mt = types.get(entry)
                 t = None
                 if mt is not None:
                     t = registry.getTypeByMetaType(mt)
                 if t is None:
                     t = DirectoryView
                 ob = t(entry, e_filepath)
                 ob_id = ob.getId()
                 data[ob_id] = ob
                 objects.append({'id': ob_id, 'meta_type': ob.meta_type})
         else:
             pos = rfind(entry, '.')
             if pos >= 0:
                 name = entry[:pos]
                 ext = path.normcase(entry[pos + 1:])
             else:
                 name = entry
                 ext = ''
             if not name or name == 'REQUEST':
                 # Not an allowable id.
                 continue
             mo = bad_id(name)
             if mo is not None and mo != -1:  # Both re and regex formats
                 # Not an allowable id.
                 continue
             t = None
             mt = types.get(entry, None)
             if mt is None:
                 mt = types.get(name, None)
             if mt is not None:
                 t = registry.getTypeByMetaType(mt)
             if t is None:
                 t = registry.getTypeByExtension(ext)
             if t is not None:
                 try:
                     ob = t(name, e_filepath, fullname=entry)
                 except:
                     from zLOG import LOG, ERROR
                     import sys, traceback
                     typ, val, tb = sys.exc_info()
                     exc_lines = traceback.format_exception( typ, val, tb )
                     LOG( 'DirectoryView', ERROR, join( exc_lines, '\n' ) )
                     ob = BadFile( name
                                 , e_filepath
                                 , exc_str=join( exc_lines, '\r\n' )
                                 , fullname=entry
                                 )
                 ob_id = ob.getId()
                 data[ob_id] = ob
                 objects.append({'id': ob_id, 'meta_type': ob.meta_type})
     return data, tuple(objects)
开发者ID:goschtl,项目名称:zope,代码行数:73,代码来源:DirectoryView.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ObjectManager.ObjectManager类代码示例发布时间:2022-05-24
下一篇:
Python Image.File类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap