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


Python base.Object类代码示例

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


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

示例1: update_neighborhood_acl

def update_neighborhood_acl(neighborhood_doc, init_doc):
    '''Convert nbhd admins users to --init-- project admins'''
    if options.test: log.info('Update nbhd %s', neighborhood_doc['name'])
    if 'acl' not in neighborhood_doc:
        log.warning('Neighborhood %s already updated', neighborhood_doc['name'])
        return
    p = Object(init_doc)
    p.root_project=p
    r_anon = _project_role(init_doc['_id'], '*anonymous')
    r_auth = _project_role(init_doc['_id'], '*authenticated')
    r_admin = _project_role(init_doc['_id'], 'Admin')
    acl = neighborhood_doc['acl']
    new_acl = list(init_doc['acl'])
    assert acl['read'] == [None] # nbhd should be public
    for uid in acl['admin'] + acl['moderate']:
        u = c_user.find(dict(_id=uid)).next()
        if options.test:
            log.info('... grant nbhd admin to: %s', u['username'])
            continue
        role =  _project_role(init_doc['_id'], user_id=uid)
        if r_admin['_id'] not in role['roles']:
            role['roles'].append(r_admin['_id'])
            c_project_role.save(role)
    _grant(new_acl, 'read', r_anon['_id'])
    _grant(new_acl, 'admin', r_admin['_id'])
    _grant(new_acl, 'register', r_admin['_id'])
    if acl['create'] == [ ]:
        if options.test: log.info('grant register to auth')
        _grant(new_acl, 'register', r_auth['_id'])
    del neighborhood_doc['acl']
    if options.test:
        log.info('--- new init acl:\n%s\n%s\n---',
                 pformat(_format_acd(init_doc['acl'])),
                 pformat(map(_format_ace, new_acl)))
    init_doc['acl'] = new_acl
开发者ID:Bitergia,项目名称:allura,代码行数:35,代码来源:007-update-acls.py

示例2: refresh_tree_info

 def refresh_tree_info(self, tree, seen, lazy=True):
     from allura.model.repository import TreeDoc
     if lazy and tree.binsha in seen:
         return
     seen.add(tree.binsha)
     doc = TreeDoc(dict(
         _id=tree.hexsha,
         tree_ids=[],
         blob_ids=[],
         other_ids=[]))
     for o in tree:
         if o.type == 'submodule':
             continue
         obj = Object(
             name=h.really_unicode(o.name),
             id=o.hexsha)
         if o.type == 'tree':
             self.refresh_tree_info(o, seen, lazy)
             doc.tree_ids.append(obj)
         elif o.type == 'blob':
             doc.blob_ids.append(obj)
         else:
             obj.type = o.type
             doc.other_ids.append(obj)
     doc.m.save(safe=False)
     return doc
开发者ID:joequant,项目名称:allura,代码行数:26,代码来源:git_repo.py

示例3: by_name

 def by_name(self):
     d = Object((x.name, x) for x in self.other_ids)
     d.update(
         (x.name, Object(x, type='tree'))
         for x in self.tree_ids)
     d.update(
         (x.name, Object(x, type='blob'))
         for x in self.blob_ids)
     return d
开发者ID:AsylumCorp,项目名称:incubator-allura,代码行数:9,代码来源:repo.py

示例4: test_get_set

 def test_get_set(self):
     d = dict(a=1, b=2)
     obj = Object(d, c=3)
     self.assertEqual(1, obj.a)
     self.assertEqual(1, obj['a'])
     self.assertEqual(3, obj.c)
     self.assertEqual(3, obj['c'])
     obj.d = 5
     self.assertEqual(5, obj['d'])
     self.assertEqual(5, obj.d)
     self.assertEqual(obj, dict(a=1, b=2, c=3, d=5))
     self.assertRaises(AttributeError, getattr, obj, 'e')
开发者ID:jaivikram,项目名称:Ming_the_merciless,代码行数:12,代码来源:test_base.py

示例5: test_convert_post_content

def test_convert_post_content():
    nbhd = Object()
    nbhd.url_prefix = '/motorola/'
    text = '''rel100? or ?rel101 or rel102 or rel103a or rel104'''
    mapping = dict(
        rel100='rel/100/',
        rel101='rel/101/',
        rel102='rel/102/',
        rel103='rel/103/',
        rel104='rel/104/')
    converted = convert_post_content(mapping, 'foo', text, nbhd)
    assert 'href="/projects/foo.motorola/files/rel/100' in converted, converted
    assert 'href="/projects/foo.motorola/files/rel/101' in converted, converted
    assert 'href="/projects/foo.motorola/files/rel/102' in converted, converted
    assert 'href="/projects/foo.motorola/files/rel/103' not in converted, converted
    assert 'href="/projects/foo.motorola/files/rel/104' in converted, converted
开发者ID:abhinavthomas,项目名称:allura,代码行数:16,代码来源:teamforge-import.py

示例6: test_safe

    def test_safe(self):
        now = datetime.now()
        oid = ObjectId()
        safe_obj = Object(
            a=[1,2,3],
            b=dict(a=12),
            c=[ 'foo', 1, 1L, 1.0, now, 
                Decimal('0.3'), None, oid ])
        safe_obj.make_safe()
        self.assertEqual(safe_obj, dict(
                a=[1,2,3], b=dict(a=12),
                c=[ 'foo', 1, 1L, 1.0, now,
                    0.3, None, oid ]))

        unsafe_obj = Object(
            my_tuple=(1,2,3))
        self.assertRaises(AssertionError, unsafe_obj.make_safe)
开发者ID:jaivikram,项目名称:Ming_the_merciless,代码行数:17,代码来源:test_base.py

示例7: __init__

 def __init__(self, session, cls, ming_cursor, refresh=False, decorate=None):
     self.session = session
     self.cls = cls
     self.mapper = mapper(cls)
     self.ming_cursor = ming_cursor
     self._options = Object(
         refresh=refresh,
         decorate=decorate,
         instrument=True)
开发者ID:apendleton,项目名称:Ming,代码行数:9,代码来源:odmsession.py

示例8: test_safe

    def test_safe(self):
        now = datetime.now()
        oid = ObjectId()

        c = [ 'foo', 1, 1.0, now,
              Decimal('0.3'), None, oid ]

        if six.PY2:
            c = [ 'foo', 1, long(1), 1.0, now,
                  Decimal('0.3'), None, oid ]

        safe_obj = Object(
            a=[1,2,3],
            b=dict(a=12),
            c=c)
        safe_obj.make_safe()
        expected = Object(
                a=[1,2,3], b=dict(a=12),
                c=c)
        self.assertTrue(expected, safe_obj)

        unsafe_obj = Object(
            my_tuple=(1,2,3))
        self.assertRaises(AssertionError, unsafe_obj.make_safe)
开发者ID:vzhz,项目名称:function_generator,代码行数:24,代码来源:test_base.py

示例9: ODMCursor

class ODMCursor(object):

    def __init__(self, session, cls, ming_cursor, refresh=False, decorate=None):
        self.session = session
        self.cls = cls
        self.mapper = mapper(cls)
        self.ming_cursor = ming_cursor
        self._options = Object(
            refresh=refresh,
            decorate=decorate,
            instrument=True)

    def __iter__(self):
        return self

    def __len__(self):
        return self.count()

    @property
    def extensions(self):
        return self.session.extensions

    def count(self):
        return self.ming_cursor.count()

    def _next_impl(self):
        doc = self.ming_cursor.next()
        obj = self.session.imap.get(self.cls, doc['_id'])
        if obj is None:
            obj = self.mapper.create(doc, self._options)
            state(obj).status = ObjectState.clean
            self.session.save(obj)
        elif self._options.refresh:
            # Refresh object
            state(obj).update(doc)
            state(obj).status = ObjectState.clean
        else:
            # Never refresh objects from the DB unless explicitly requested
            pass
        other_session = session(obj)
        if other_session is not None and other_session != self:
            other_session.expunge(obj)
            self.session.save(obj)
        if self._options.decorate is not None:
            return self._options.decorate(obj)
        else:
            return obj

    def next(self):
        call_hook(self, 'before_cursor_next', self)
        try:
            return self._next_impl()
        finally:
            call_hook(self, 'after_cursor_next', self)

    def options(self, **kwargs):
        odm_cursor = ODMCursor(self.session, self.cls,self.ming_cursor)
        odm_cursor._options = Object(self._options, **kwargs)
        call_hook(self, 'cursor_created', odm_cursor, 'options', self, **kwargs)
        return odm_cursor

    def limit(self, limit):
        odm_cursor = ODMCursor(self.session, self.cls,
                               self.ming_cursor.limit(limit))
        call_hook(self, 'cursor_created', odm_cursor, 'limit', self, limit)
        return odm_cursor

    def skip(self, skip):
        odm_cursor = ODMCursor(self.session, self.cls,
                               self.ming_cursor.skip(skip))
        call_hook(self, 'cursor_created', odm_cursor, 'skip', self, skip)
        return odm_cursor

    def hint(self, index_or_name):
        odm_cursor = ODMCursor(self.session, self.cls,
                               self.ming_cursor.hint(index_or_name))
        call_hook(self, 'cursor_created', odm_cursor, 'hint', self, index_or_name)
        return odm_cursor

    def sort(self, *args, **kwargs):
        odm_cursor = ODMCursor(self.session, self.cls,
                               self.ming_cursor.sort(*args, **kwargs))
        call_hook(self, 'cursor_created', odm_cursor, 'sort', self, *args, **kwargs)
        return odm_cursor

    def one(self):
        try:
            result = self.next()
        except StopIteration:
            raise ValueError, 'Less than one result from .one()'
        try:
            self.next()
        except StopIteration:
            return result
        raise ValueError, 'More than one result from .one()'

    def first(self):
        try:
            return self.next()
        except StopIteration:
#.........这里部分代码省略.........
开发者ID:apendleton,项目名称:Ming,代码行数:101,代码来源:odmsession.py

示例10: test_from_bson

 def test_from_bson(self):
     bson = dict(
         a=[1,2,3],
         b=dict(c=5))
     obj = Object.from_bson(bson)
     self.assertEqual(obj, dict(a=[1,2,3], b=dict(c=5)))
开发者ID:jaivikram,项目名称:Ming_the_merciless,代码行数:6,代码来源:test_base.py

示例11: ODMCursor

class ODMCursor(object):
    """Represents the results of query.

    The cursors can be iterated over to retrieve the
    results one by one.
    """
    def __bool__(self):
        raise MingException('Cannot evaluate ODMCursor to a boolean')
    __nonzero__ = __bool__  # python 2

    def __init__(self, session, cls, ming_cursor, refresh=False, decorate=None, fields=None):
        self.session = session
        self.cls = cls
        self.mapper = mapper(cls)
        self.ming_cursor = ming_cursor
        self._options = Object(
            refresh=refresh,
            decorate=decorate,
            fields=fields,
            instrument=True)

    def __iter__(self):
        return self

    @property
    def extensions(self):
        return self.session.extensions

    def count(self):
        """Get the number of objects retrieved by the query"""
        return self.ming_cursor.count()

    def _next_impl(self):
        doc = next(self.ming_cursor)
        obj = self.session.imap.get(self.cls, doc['_id'])
        if obj is None:
            obj = self.mapper.create(doc, self._options, remake=False)
            state(obj).status = ObjectState.clean
            self.session.save(obj)
        elif self._options.refresh:
            # Refresh object
            state(obj).update(doc)
            state(obj).status = ObjectState.clean
        else:
            # Never refresh objects from the DB unless explicitly requested
            pass
        other_session = session(obj)
        if other_session is not None and other_session != self:
            other_session.expunge(obj)
            self.session.save(obj)
        if self._options.decorate is not None:
            return self._options.decorate(obj)
        else:
            return obj

    def next(self):
        _call_hook(self, 'before_cursor_next', self)
        try:
            return self._next_impl()
        finally:
            _call_hook(self, 'after_cursor_next', self)

    __next__ = next

    def options(self, **kwargs):
        odm_cursor = ODMCursor(self.session, self.cls,self.ming_cursor)
        odm_cursor._options = Object(self._options, **kwargs)
        _call_hook(self, 'cursor_created', odm_cursor, 'options', self, **kwargs)
        return odm_cursor

    def limit(self, limit):
        """Limit the number of entries retrieved by the query"""
        odm_cursor = ODMCursor(self.session, self.cls,
                               self.ming_cursor.limit(limit))
        _call_hook(self, 'cursor_created', odm_cursor, 'limit', self, limit)
        return odm_cursor

    def skip(self, skip):
        """Skip the first ``skip`` entries retrieved by the query"""
        odm_cursor = ODMCursor(self.session, self.cls,
                               self.ming_cursor.skip(skip))
        _call_hook(self, 'cursor_created', odm_cursor, 'skip', self, skip)
        return odm_cursor

    def hint(self, index_or_name):
        odm_cursor = ODMCursor(self.session, self.cls,
                               self.ming_cursor.hint(index_or_name))
        _call_hook(self, 'cursor_created', odm_cursor, 'hint', self, index_or_name)
        return odm_cursor

    def sort(self, *args, **kwargs):
        """Sort results of the query.

        See :meth:`pymongo.cursor.Cursor.sort` for details on the available
        arguments.
        """
        odm_cursor = ODMCursor(self.session, self.cls,
                               self.ming_cursor.sort(*args, **kwargs))
        _call_hook(self, 'cursor_created', odm_cursor, 'sort', self, *args, **kwargs)
        return odm_cursor
#.........这里部分代码省略.........
开发者ID:vzhz,项目名称:function_generator,代码行数:101,代码来源:odmsession.py

示例12: refresh_commit_info

 def refresh_commit_info(self, oid, seen_object_ids, lazy=True):
     from allura.model.repository import CommitDoc
     ci_doc = CommitDoc.m.get(_id=oid)
     if ci_doc and lazy:
         return False
     revno = self._revno(oid)
     rev = self._revision(oid)
     try:
         log_entry = self._svn.log(
             self._url,
             revision_start=rev,
             limit=1,
             discover_changed_paths=True)[0]
     except pysvn.ClientError:
         log.info('ClientError processing %r %r, treating as empty',
                  oid, self._repo, exc_info=True)
         log_entry = Object(date='', message='', changed_paths=[])
     log_date = None
     if hasattr(log_entry, 'date'):
         log_date = datetime.utcfromtimestamp(log_entry.date)
     user = Object(
         name=h.really_unicode(log_entry.get('author', '--none--')),
         email='',
         date=log_date)
     args = dict(
         tree_id=None,
         committed=user,
         authored=user,
         message=h.really_unicode(log_entry.get("message", "--none--")),
         parent_ids=[],
         child_ids=[])
     if revno > 1:
         args['parent_ids'] = [self._oid(revno - 1)]
     if ci_doc:
         ci_doc.update(**args)
         ci_doc.m.save()
     else:
         ci_doc = CommitDoc(dict(args, _id=oid))
         try:
             ci_doc.m.insert(safe=True)
         except DuplicateKeyError:
             if lazy:
                 return False
     return True
开发者ID:apache,项目名称:allura,代码行数:44,代码来源:svn.py

示例13: refresh_commit_info

 def refresh_commit_info(self, oid, seen_object_ids, lazy=True):
     from allura.model.repo import CommitDoc, DiffInfoDoc
     ci_doc = CommitDoc.m.get(_id=oid)
     if ci_doc and lazy:
         return False
     revno = self._revno(oid)
     rev = self._revision(oid)
     try:
         log_entry = self._svn.log(
             self._url,
             revision_start=rev,
             limit=1,
             discover_changed_paths=True)[0]
     except pysvn.ClientError:
         log.info('ClientError processing %r %r, treating as empty',
                  oid, self._repo, exc_info=True)
         log_entry = Object(date='', message='', changed_paths=[])
     log_date = None
     if hasattr(log_entry, 'date'):
         log_date = datetime.utcfromtimestamp(log_entry.date)
     user = Object(
         name=h.really_unicode(log_entry.get('author', '--none--')),
         email='',
         date=log_date)
     args = dict(
         tree_id=None,
         committed=user,
         authored=user,
         message=h.really_unicode(log_entry.get("message", "--none--")),
         parent_ids=[],
         child_ids=[])
     if revno > 1:
         args['parent_ids'] = [self._oid(revno - 1)]
     if ci_doc:
         ci_doc.update(**args)
         ci_doc.m.save()
     else:
         ci_doc = CommitDoc(dict(args, _id=oid))
         try:
             ci_doc.m.insert(safe=True)
         except DuplicateKeyError:
             if lazy:
                 return False
     # Save diff info
     di = DiffInfoDoc.make(dict(_id=ci_doc._id, differences=[]))
     for path in log_entry.changed_paths:
         if path.action in ('A', 'M', 'R'):
             try:
                 rhs_info = self._svn.info2(
                     self._url + h.really_unicode(path.path),
                     revision=self._revision(ci_doc._id),
                     recurse=False)[0][1]
                 rhs_id = self._obj_oid(ci_doc._id, rhs_info)
             except pysvn.ClientError, e:
                 # pysvn will sometimes misreport deleted files (D) as
                 # something else (like A), causing info2() to raise a
                 # ClientError since the file doesn't exist in this
                 # revision. Set lrhs_id = None to treat like a deleted file
                 log.info('This error was handled gracefully and logged '
                          'for informational purposes only:\n' + str(e))
                 rhs_id = None
         else:
             rhs_id = None
         if ci_doc.parent_ids and path.action in ('D', 'M', 'R'):
             try:
                 lhs_info = self._svn.info2(
                     self._url + h.really_unicode(path.path),
                     revision=self._revision(ci_doc.parent_ids[0]),
                     recurse=False)[0][1]
                 lhs_id = self._obj_oid(ci_doc._id, lhs_info)
             except pysvn.ClientError, e:
                 # pysvn will sometimes report new files as 'M'odified,
                 # causing info2() to raise ClientError since the file
                 # doesn't exist in the parent revision. Set lhs_id = None
                 # to treat like a newly added file.
                 log.info('This error was handled gracefully and logged '
                          'for informational purposes only:\n' + str(e))
                 lhs_id = None
开发者ID:AsylumCorp,项目名称:incubator-allura,代码行数:78,代码来源:svn.py


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