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

Python ua.get函数代码示例

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

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



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

示例1: test_real_does_not_use_cached_httplib2_client

    def test_real_does_not_use_cached_httplib2_client(self):
        """
        When we use this slumber in Wimbledon project, we found that the request
        is occationally error on IE9 (got 500 response in return bcoz of the empty
        request). We are not sure if the root cause was in IE9 or in the httplib2,
        but stop caching httplib2's client fixed it (reset client everytime).

        The downside is we cannot use caching features of the httplib2's client,
        but until we understand this problem in more details, we'll stick with
        resetting client every time.

        juacompe, 2nd November 2011

        ref: http://proteus.eidos.proteus-tech.com/project/BBG/story/BBG-251/card/
        """
        self.callers = []
        class response:
            status = 200
            content = '''{"apps":{}}'''
        def _request(_self, url, headers={}):
            self.callers.append(_self)
            r = response()
            return r, r.content
        with patch('slumber.connector.ua.Http.request',_request):
            get(self.cache_url)
            get(self.cache_url)
            self.assertNotEqual(self.callers[0], self.callers[1])
开发者ID:nuimk-proteus,项目名称:django-slumber,代码行数:27,代码来源:ua.py


示例2: test_cache_ttl

 def test_cache_ttl(self):
     def _request(_self, url, headers={}):
         r = _response_httplib2()
         return r, r.content
     with patch('slumber.connector.ua.Http.request', _request):
         get(self.cache_url, 2)
     with patch('slumber.connector.ua.Http.request', self.fail):
         get(self.cache_url, 2)
开发者ID:nuimk-proteus,项目名称:django-slumber,代码行数:8,代码来源:ua.py


示例3: test_retry_get_still_can_fail

 def test_retry_get_still_can_fail(self):
     class _response:
         content = ''
         status = 500
     def _request(_self, url, headers={}):
         r = _response()
         return r, r.content
     with patch('slumber.connector.ua.Http.request',_request):
         with self.assertRaises(AssertionError):
             get(self.cache_url)
开发者ID:nuimk-proteus,项目名称:django-slumber,代码行数:10,代码来源:ua.py


示例4: test_get_retries

 def test_get_retries(self):
     class _response:
         content = '''{"apps":{}}'''
         def __init__(self, counter):
             self.status = 200 if counter == 1 else 404
     counter = []
     def _request(_self, url, headers={}):
         r = _response(len(counter))
         counter.append(True)
         return r, r.content
     with patch('slumber.connector.ua.Http.request', _request):
         get(self.cache_url)
     self.assertEqual(len(counter), 2)
开发者ID:nuimk-proteus,项目名称:django-slumber,代码行数:13,代码来源:ua.py


示例5: get_all_permissions

 def get_all_permissions(self):
     """Forward access to all of the permissions.
     """
     # We're accessing attributes that are provided by the  other types
     # pylint: disable = E1101
     _, json = get(self._operations['get-permissions'], self._CACHE_TTL)
     return set(json['all_permissions'])
开发者ID:KayEss,项目名称:django-slumber,代码行数:7,代码来源:proxies.py


示例6: __getattr__

 def __getattr__(self, name):
     _, json = get(self._url)
     for k, v in json['fields'].items():
         setattr(self, k, from_json_data(self._url, v))
     if name in json['fields'].keys():
         return getattr(self, name)
     return _return_data_array(self._url, json['data_arrays'], self, name)
开发者ID:juacompe,项目名称:django-slumber-1,代码行数:7,代码来源:instance.py


示例7: test_mount_point

 def test_mount_point(self):
     response, json = get('/slumber/shops/mount1/')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(json, dict(_meta={'message': 'OK', 'status': 200},
         shops=[{
             'name': 'Hard Coded Pizza Parlour'
         }]))
开发者ID:alexef,项目名称:django-slumber,代码行数:7,代码来源:operations.py


示例8: test_mount_point

 def test_mount_point(self):
     shop = Shop.objects.create(name="Test One")
     with patch("slumber.connector._get_slumber_authn_name", lambda: "service"):
         response, json = get("/slumber/pizzas/shop/%s/" % shop.pk)
     self.assertEqual(response.status_code, 200)
     self.assertTrue(json["operations"].has_key("data"), json)
     self.assertEqual(json["operations"]["data"], "/slumber/pizzas/shop/%s/" % shop.pk)
开发者ID:merlian,项目名称:django-slumber,代码行数:7,代码来源:operations.py


示例9: test_fifteen_shops

    def test_fifteen_shops(self):
        for s in xrange(1, 16):
            Shop.objects.create(name="Shop %d" % s, slug="shop%2d" % s)
        response, json = get('/slumber/shops/mount2/')

        self.assertEqual(response.status_code, 200)
        self.assertFalse(json.has_key('instances'))

        self.assertTrue(json.has_key('_links'))
        links = json['_links']
        self.assertEqual(links['self']['href'], '/slumber/shops/mount2/')
        self.assertEqual(links['model']['href'], '/slumber/slumber_examples/Shop/')
        self.assertTrue(links.has_key('next'), links)

        self.assertTrue(json.has_key('_embedded'))
        self.assertTrue(json['_embedded'].has_key('page'))
        page = json['_embedded']['page']

        self.assertEqual(len(page), 10)
        self.assertEqual(page[0], dict(
            _links={'self': dict(href='/slumber/pizzas/shop/15/')},
            display="Shop 15"))

        self.assertEqual(links['next']['href'],
            '/slumber/shops/mount2/?lpk=6')
开发者ID:KayEss,项目名称:django-slumber,代码行数:25,代码来源:hal.py


示例10: pull_monitor

def pull_monitor(model_url, callback, delay=dict(minutes=1),
        page_url=None, floor=0, pull_priority=5, job_priority=5):
    """Used to look for instances that need to be pulled.

    This only works with models who use an auto-incremented primary key.
    """
    if not page_url:
        model = get_model(model_url)
        instances_url = model._operations['instances']
    else:
        instances_url = page_url
    _, json = get(instances_url or page_url)
    latest, highest = None, floor
    for item in json['page']:
        highest = max(item['pk'], highest)
        latest = item['pk']
        if latest > floor:
            schedule(callback, args=[urljoin(instances_url, item['data'])], priority=job_priority)
    if json.has_key('next_page') and latest > floor:
        schedule('pubsubpull.async.pull_monitor', args=[model_url, callback],
            kwargs=dict(delay=delay, floor=floor,
                page_url=urljoin(instances_url, json['next_page']),
                pull_priority=pull_priority, job_priority=job_priority),
            priority=pull_priority)
        print("Got another page to process", json['next_page'], floor)
    if not page_url:
        run_after = timezone.now() + timedelta(**delay)
        schedule('pubsubpull.async.pull_monitor', run_after=run_after,
            args=[model_url, callback], kwargs=dict(delay=delay, floor=highest,
                pull_priority=pull_priority, job_priority=job_priority),
            priority=pull_priority)
        print("Looking for new instances above", highest)
开发者ID:nuimk-proteus,项目名称:django-pubsubpull,代码行数:32,代码来源:async.py


示例11: __getattr__

 def __getattr__(self, attr_name):
     """Fetch the application list from the Slumber directory on request.
     """
     _, json = get(self._directory)
     apps = {}
     for app in json['apps'].keys():
         root = apps
         for k in app.split('.'):
             if not root.has_key(k):
                 root[k] = {}
             root = root[k]
     def recurse_apps(loc, this_level, name):
         """Recursively build the application connectors.
         """
         current_appname = '.'.join(name)
         if json['apps'].has_key(current_appname):
             loc._url = urljoin(self._directory,
                 json['apps'][current_appname])
         for k, v in this_level.items():
             app_cnx = AppConnector()
             setattr(loc, k, app_cnx)
             recurse_apps(app_cnx, v, name + [k])
     recurse_apps(self, apps, [])
     if attr_name in apps.keys():
         return getattr(self, attr_name)
     else:
         raise AttributeError(attr_name)
开发者ID:juacompe,项目名称:django-slumber-1,代码行数:27,代码来源:__init__.py


示例12: get_profile

 def get_profile(self):
     """Forward access to the profile.
     """
     # We're accessing attributes that are provided by the  other types
     # pylint: disable = E1101
     base_url = self._operations['get-profile']
     _, json = get(base_url, self._CACHE_TTL)
     return get_instance_from_data(base_url, json)
开发者ID:KayEss,项目名称:django-slumber,代码行数:8,代码来源:proxies.py


示例13: has_perm

 def has_perm(self, permission):
     """Forward the permission check.
     """
     # We're accessing attributes that are provided by the  other types
     # pylint: disable = E1101
     url = urljoin(self._operations['has-permission'], permission)
     _, json = get(url, self._CACHE_TTL)
     return json['is-allowed']
开发者ID:KayEss,项目名称:django-slumber,代码行数:8,代码来源:proxies.py


示例14: get

 def get(self, **kwargs):
     """Implements the client side for the model 'get' operator.
     """
     assert len(kwargs), \
         "You must supply kwargs to filter on to fetch the instance"
     url = urljoin(self._url, 'get/')
     _, json = get(url + '?' + urlencode(kwargs), self._CACHE_TTL)
     return get_instance_from_data(url, json)
开发者ID:KayEss,项目名称:django-slumber,代码行数:8,代码来源:api.py


示例15: test_model_operation_with_mock_ua

 def test_model_operation_with_mock_ua(self, expect):
     expect.get('http://pizzas/app/Model/test-op/', {'test': 'item'})
     expect.post('http://pizzas/app/Model/test-op/', {'test': 'item'}, {'item': 'test'})
     self.assertEqual(len(expect.expectations), 2)
     response1, json1 = get(client.pizzas.app.Model._operations['test-op'])
     self.assertEqual(json1, dict(test='item'))
     response2, json2 = post(client.pizzas.app.Model._operations['test-op'], json1)
     self.assertEqual(json2, dict(item='test'))
开发者ID:jiitoey,项目名称:django-slumber,代码行数:8,代码来源:mock_client.py


示例16: test_xml

    def test_xml(self):
        response, _ = get('/slumber/shops/mount2/?lpk=6',
            headers=dict(Accept='application/xml'))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-Type'], 'application/xml; charset=utf-8')

        xml = parseString(response.content)
        self.assertEqual(xml.documentElement.tagName, 'instances')
开发者ID:KayEss,项目名称:django-slumber,代码行数:8,代码来源:hal.py


示例17: test_directory

 def test_directory(self):
     request, json = get("http://localhost:8000/slumber/")
     self.assertEquals(
         json["services"],
         {
             "auth": "http://localhost:8000/slumber/pizzas/django/contrib/auth/",
             "pizzas": "http://localhost:8000/slumber/pizzas/",
         },
     )
开发者ID:nuimk-proteus,项目名称:django-slumber,代码行数:9,代码来源:client.py


示例18: test_cache

 def test_cache(self):
     try:
         r1, j1 = get('http://urquell-fn.appspot.com/lib/echo/?__=', 2)
         r2, j2 = get('http://urquell-fn.appspot.com/lib/echo/?__=', 2)
         r3, j3 = get('http://urquell-fn.appspot.com/lib/echo/?dummy=&__=', 2)
         self.assertFalse(hasattr(r1, 'from_cache'))
         self.assertTrue(hasattr(r2, 'from_cache'))
         self.assertTrue(r2.from_cache)
         self.assertFalse(hasattr(r3, 'from_cache'))
     except ServerNotFoundError:
         # If we get a server error then we presume that there is no good
         # Internet connection and don't fail the test
         pass
     except socket.error:
         pass
     except Exception, e:
         print type(e)
         raise e
开发者ID:nuimk-proteus,项目名称:django-slumber,代码行数:18,代码来源:ua.py


示例19: __getattr__

 def __getattr__(self, name):
     attrs = ['name', 'module']
     if name in attrs:
         _, json = get(self._url)
         for attr in attrs:
             setattr(self, attr, json[attr])
         return getattr(self, name)
     else:
         raise AttributeError(name)
开发者ID:juacompe,项目名称:django-slumber-1,代码行数:9,代码来源:model.py


示例20: has_module_perms

 def has_module_perms(self, module):
     """Forward the permission check.
     """
     # We're accessing attributes that are provided by the  other types
     # pylint: disable = E1101
     _, json = get(
         urljoin(self._operations['module-permissions'], module),
         self._CACHE_TTL)
     return json['has_module_perms']
开发者ID:KayEss,项目名称:django-slumber,代码行数:9,代码来源:proxies.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python models.Pizza类代码示例发布时间:2022-05-27
下一篇:
Python slumber.url_join函数代码示例发布时间: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