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

Python util.IDObfuscator类代码示例

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

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



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

示例1: test_update_dependencies_accept

    def test_update_dependencies_accept(self, john_doe, normalized_data_id):
        graph = ChangeGraph([{
            '@id': IDObfuscator.encode(john_doe),
            '@type': 'person',
            'given_name': 'Jane',
        }, {
            '@id': '_:456',
            '@type': 'Creator',
            'agent': {'@id': IDObfuscator.encode(john_doe), '@type': 'person'},
            'creative_work': {'@id': '_:789', '@type': 'preprint'},
        }, {
            '@id': '_:789',
            '@type': 'preprint',
            'title': 'All About Cats',
        }])

        change_set = models.ChangeSet.objects.from_graph(graph, normalized_data_id)

        change_set.accept()

        john_doe.refresh_from_db()

        assert john_doe.given_name == 'Jane'
        assert models.Preprint.objects.filter(agent_relations__agent=john_doe).count() == 1
        assert models.Preprint.objects.filter(agent_relations__agent=john_doe).first().title == 'All About Cats'
开发者ID:Stevenholloway,项目名称:SHARE,代码行数:25,代码来源:test_change.py


示例2: test_no_icon

    def test_no_icon(self):
        x = factories.AbstractCreativeWorkFactory()
        source = factories.SourceFactory(icon='')
        x.sources.add(source.user)

        # Have to use % formats because of {}s everywhere
        result = schema.execute('''
            query {
                creativeWork(id: "%s") {
                    id,
                    title,
                    description,
                    sources {
                        title
                    }
                }
            }
        ''' % (IDObfuscator.encode(x), ))

        assert not result.errors

        assert result.data == OrderedDict([
            ('creativeWork', OrderedDict([
                ('id', IDObfuscator.encode(x)),
                ('title', x.title),
                ('description', x.description),
                ('sources', [])
            ]))
        ])
开发者ID:leb2dg,项目名称:SHARE,代码行数:29,代码来源:test_graphql.py


示例3: test_by_id

    def test_by_id(self, client):
        source = Source.objects.first()
        resp = client.get('{}{}/'.format(self.endpoint, IDObfuscator.encode(source)))

        assert resp.status_code == 200
        assert IDObfuscator.load(resp.json()['data']['id']) == source
        assert resp.json()['data']['type'] == 'Source'
        assert resp.json()['data']['attributes'] == {
            'name': source.name,
            'icon': 'http://testserver{}'.format(source.icon.url),
            'homePage': source.home_page,
            'longTitle': source.long_title,
        }
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:13,代码来源:test_sources_endpoint.py


示例4: get_object

    def get_object(self):
        queryset = self.filter_queryset(self.get_queryset())

        # Perform the lookup filtering.
        lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field

        assert lookup_url_kwarg in self.kwargs, (
            'Expected view %s to be called with a URL keyword argument '
            'named "%s". Fix your URL conf, or set the `.lookup_field` '
            'attribute on the view correctly.' %
            (self.__class__.__name__, lookup_url_kwarg)
        )

        try:
            (model, decoded_pk) = IDObfuscator.decode(self.kwargs[lookup_url_kwarg])
            concrete_model = self.serializer_class.Meta.model._meta.concrete_model
            if model is not concrete_model:
                raise serializers.ValidationError('The specified ID refers to an {}. Expected {}'.format(model._meta.model_name, concrete_model._meta.model_name))
        except InvalidID:
            raise serializers.ValidationError('Invalid ID')

        filter_kwargs = {self.lookup_field: decoded_pk}
        obj = get_object_or_404(queryset, **filter_kwargs)

        # May raise a permission denied
        self.check_object_permissions(self.request, obj)

        return obj
开发者ID:leb2dg,项目名称:SHARE,代码行数:28,代码来源:share.py


示例5: test_get_record

 def test_get_record(self, post, all_about_anteaters):
     ant_id = 'oai:share.osf.io:{}'.format(IDObfuscator.encode(all_about_anteaters))
     parsed = oai_request({'verb': 'GetRecord', 'metadataPrefix': 'oai_dc', 'identifier': ant_id}, post)
     records = parsed.xpath('//ns0:GetRecord/ns0:record', namespaces=NAMESPACES)
     assert len(records) == 1
     assert all_about_anteaters.title == records[0].xpath('ns0:metadata/oai_dc:dc/dc:title', namespaces=NAMESPACES)[0].text
     assert ant_id == records[0].xpath('ns0:header/ns0:identifier', namespaces=NAMESPACES)[0].text
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:7,代码来源:test_oaipmh.py


示例6: test_list_with_items

 def test_list_with_items(self, client):
     user = ShareUserFactory()
     banner = SiteBanner.objects.create(
         title='Why wasnt I there',
         description='I could have saved them',
         created_by=user,
         last_modified_by=user,
     )
     resp = client.get('/api/v2/site_banners/')
     assert resp.status_code == 200
     assert resp.json() == {
         'data': [{
             'id': IDObfuscator.encode(banner),
             'type': 'SiteBanner',
             'attributes': {
                 'color': 'info',
                 'icon': 'exclamation',
                 'title': 'Why wasnt I there',
                 'description': 'I could have saved them',
             }
         }],
         'links': {
             'first': 'http://testserver/api/v2/site_banners/?page=1',
             'last': 'http://testserver/api/v2/site_banners/?page=1',
             'next': None,
             'prev': None,
         },
         'meta': {
             'pagination': {'count': 1, 'pages': 1, 'page': 1},
         }
     }
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:31,代码来源:test_sitebanners.py


示例7: test_update_dependencies_accept

    def test_update_dependencies_accept(self, john_doe, normalized_data):
        john_doe_id = IDObfuscator.encode(john_doe)
        graph = MutableGraph.from_jsonld([{
            '@id': john_doe_id,
            '@type': 'person',
            'given_name': 'Jane',
        }, {
            '@id': '_:456',
            '@type': 'Creator',
            'agent': {'@id': john_doe_id, '@type': 'person'},
            'creative_work': {'@id': '_:789', '@type': 'preprint'},
        }, {
            '@id': '_:789',
            '@type': 'preprint',
            'title': 'All About Cats',
        }])

        change_set = ChangeSetBuilder(graph, normalized_data, matches={
            john_doe_id: john_doe,
        }).build_change_set()

        change_set.accept()

        john_doe.refresh_from_db()

        assert john_doe.given_name == 'Jane'
        assert models.Preprint.objects.filter(agent_relations__agent=john_doe).count() == 1
        assert models.Preprint.objects.filter(agent_relations__agent=john_doe).first().title == 'All About Cats'
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:28,代码来源:test_change.py


示例8: refs

 def refs(n):
     if isinstance(n, list):
         return [refs(node) for node in n]
     instance = self._get_match(n)
     return {
         '@id': IDObfuscator.encode(instance) if instance else n.id,
         '@type': n.type,
     }
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:8,代码来源:change_builder.py


示例9: test_list_records

 def test_list_records(self, post, all_about_anteaters, django_assert_num_queries):
     with django_assert_num_queries(2):
         parsed = oai_request({'verb': 'ListRecords', 'metadataPrefix': 'oai_dc'}, post)
     records = parsed.xpath('//ns0:ListRecords/ns0:record', namespaces=NAMESPACES)
     assert len(records) == 1
     assert all_about_anteaters.title == records[0].xpath('ns0:metadata/oai_dc:dc/dc:title', namespaces=NAMESPACES)[0].text
     ant_id = 'oai:share.osf.io:{}'.format(IDObfuscator.encode(all_about_anteaters))
     assert ant_id == records[0].xpath('ns0:header/ns0:identifier', namespaces=NAMESPACES)[0].text
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:8,代码来源:test_oaipmh.py


示例10: resolve_oai_identifier

 def resolve_oai_identifier(self, identifier):
     try:
         splid = identifier.split(self.IDENTIFER_DELIMITER)
         if len(splid) != 3 or splid[:2] != ['oai', self.REPOSITORY_IDENTIFIER]:
             raise InvalidID(identifier)
         return IDObfuscator.resolve(splid[-1])
     except (AbstractCreativeWork.DoesNotExist, InvalidID):
         self.errors.append(oai_errors.BadRecordID(identifier))
         return None
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:9,代码来源:repository.py


示例11: initial_pass

 def initial_pass(self, nodes):
     for node in nodes:
         if str(node.id).startswith('_:'):
             continue
         try:
             match = IDObfuscator.resolve(node.id)
             self.add_match(node, match)
         except InvalidID:
             pass
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:9,代码来源:database.py


示例12: test_ignore_generic_work_type

    def test_ignore_generic_work_type(self, change_factory, all_about_anteaters):
        cs = change_factory.from_graph({
            '@graph': [{
                '@id': IDObfuscator.encode(all_about_anteaters),
                '@type': 'creativework'
            }]
        }, disambiguate=True)

        assert cs is None
开发者ID:Stevenholloway,项目名称:SHARE,代码行数:9,代码来源:test_change.py


示例13: assert_indexed

 def assert_indexed(self):
     encoded_id = IDObfuscator.encode(self.work)
     doc = self.elastic.es_client.get(
         index=self.elastic.es_index,
         doc_type='creativeworks',
         id=encoded_id
     )
     assert doc['found'] is True
     assert doc['_id'] == encoded_id
     return doc
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:10,代码来源:test_elastic.py


示例14: get_raws

def get_raws(obj):
    if isinstance(obj, str):
        model, id = IDObfuscator.decode(obj)
    else:
        model = obj._meta.model
        id = obj.id
    return RawData.objects.filter(
        normalizeddata__changeset__changes__target_id=id,
        normalizeddata__changeset__changes__target_type=ContentType.objects.get_for_model(model, for_concrete_model=True)
    )
开发者ID:Stevenholloway,项目名称:SHARE,代码行数:10,代码来源:shell_util.py


示例15: populate_types

def populate_types(data):
    model = apps.get_model(data['type'])
    data['id'] = IDObfuscator.encode_id(data['id'], model)
    data['type'] = model._meta.verbose_name
    data['types'] = []
    for parent in model.mro():
        if not parent._meta.proxy:
            break
        data['types'].append(parent._meta.verbose_name)

    return data
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:11,代码来源:util.py


示例16: __init__

    def __init__(self, graph, id, type, attrs, namespace=None):
        self.graph = graph
        self._id = id
        self._type = type.lower()
        self.instance = None
        self.attrs = attrs
        self.extra = attrs.pop('extra', {})
        self.context = attrs.pop('@context', {})
        self.namespace = namespace

        if not self.is_blank:
            self.instance = IDObfuscator.load(self.id, None)
            if not self.instance or self.instance._meta.concrete_model is not self.model._meta.concrete_model:
                raise UnresolvableReference((self.id, self.type))
开发者ID:Stevenholloway,项目名称:SHARE,代码行数:14,代码来源:change.py


示例17: _resolve_ref

 def _resolve_ref(self, ref):
     model = apps.get_model('share', model_name=ref['@type'])
     ct = ContentType.objects.get_for_model(model, for_concrete_model=True)
     try:
         if ref['@id'].startswith('_:'):
             return next(
                 change.target
                 for change in self._changes_cache
                 if change.target_type == ct
                 and change.node_id == ref['@id']
                 and change.target
             )
         return model._meta.concrete_model.objects.get(pk=IDObfuscator.decode_id(ref['@id']))
     except (StopIteration, model.DoesNotExist) as ex:
         raise Exception('Could not resolve reference {}'.format(ref)) from ex
开发者ID:Stevenholloway,项目名称:SHARE,代码行数:15,代码来源:change.py


示例18: get_search_results

    def get_search_results(self, request, queryset, search_term):
        try:
            return queryset.filter(id=IDObfuscator.decode_id(search_term)), False
        except InvalidID:
            pass

        # Overriden because there is no way to opt out of a case insensitive search
        search_fields = self.get_search_fields(request)
        use_distinct = bool(search_term)
        if search_fields and search_term:
            orm_lookups = ['{}__startswith'.format(search_field) for search_field in search_fields]
            for bit in search_term.split():
                or_queries = [models.Q(**{orm_lookup: bit}) for orm_lookup in orm_lookups]
                queryset = queryset.filter(reduce(operator.or_, or_queries))

        return queryset, use_distinct
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:16,代码来源:share_objects.py


示例19: test_work_type_stays_nongeneric

    def test_work_type_stays_nongeneric(self, change_factory, all_about_anteaters):
        new_title = 'Some about Anteaters'
        cs = change_factory.from_graph({
            '@graph': [{
                '@id': IDObfuscator.encode(all_about_anteaters),
                '@type': 'creativework',
                'title': new_title
            }]
        }, disambiguate=True)

        assert all_about_anteaters.type == 'share.article'
        assert models.Publication.objects.count() == 1

        cs.accept()
        all_about_anteaters.refresh_from_db()

        assert all_about_anteaters.type == 'share.article'
        assert all_about_anteaters.title == new_title
开发者ID:Stevenholloway,项目名称:SHARE,代码行数:18,代码来源:test_change.py


示例20: test_change_agent_type

    def test_change_agent_type(self, change_factory, university_of_whales):
        cs = change_factory.from_graph({
            '@graph': [{
                '@id': IDObfuscator.encode(university_of_whales),
                '@type': 'consortium'
            }]
        }, disambiguate=True)

        assert models.Institution.objects.count() == 1
        assert models.Consortium.objects.count() == 0

        (org,) = cs.accept()

        assert org.type == 'share.consortium'
        assert org.id == university_of_whales.id
        assert org.name == university_of_whales.name
        assert models.Institution.objects.count() == 0
        assert models.Consortium.objects.count() == 1
开发者ID:Stevenholloway,项目名称:SHARE,代码行数:18,代码来源:test_change.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python share_helpers.validate_share函数代码示例发布时间:2022-05-27
下一篇:
Python operations.multishard_find函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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