假设的python库.is api

python-hypothesis的Python项目详细描述


这个包提供了到假设api的python绑定。

低级访问

api子模块是Hypothesis API的低级实现。

此模块的内容反映了api的其余性质:

  • api调用是由函数进行的。
  • 输入和输出数据是未解释的数据(例如,json字符串,而不是 解释json产生的对象)。
  • 参数检查是最小的,当api 返回一个错误(如果服务器不返回200,则引发APIError)。
  • 参数auth总是首先给出(除了root(),它 不接受授权)。auth当前可以是none或string 包含开发人员令牌。

示例:

>>> h_annot.api.read(None, '53LMZGVCEemN4zOvm3oFEQ')
u'{"updated": "2019-04-22T21:09:23.352503+00:00", "group": "__world__", ...
>>> h_annot.api.read(None, 'bogusannotationid')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "h_annot/api.py", line 39, in read
    raise APIError(r)
h_annot.exceptions.APIError: API call returned 404 (Not Found): not_found

高级访问

注释类是注释的对象抽象。使用load()class方法从其id:

>>> annot = h_annot.Annotation.load('53LMZGVCEemN4zOvm3oFEQ')
>>> annot.text
u"I'm imagining!!!"

例外情况更为严重:

>>> h_annot.Annotation.load('somebogusannotid')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "h_annot/annotation.py", line 97, in load
    raise KeyError('annotation ID %s not found' % annot_id)
KeyError: 'annotation ID somebogusannotid not found'

不应直接调用注释构造函数。

可以更新某些属性;为此,请使用h_annot.auth()上下文管理器设置身份验证令牌:

>>> with h_annot.auth(authentication_token):
...     annot.text = 'new text'

批注没有固有的身份验证概念,因此以前声明批注身份验证的方式:

>>> annot = h_annot.Annotation.load('someannotationid', 'somedevelkey')
>>> annot.text = 'new text'

已弃用。

通过tags属性访问和更改标记。此属性的行为类似于不区分大小写的集合(就像假设本身处理标记一样)。

>>> print annot.tags
TagSet(objectives, interwebs)
>>> for tag in annot.tags:
...     print tag
objectives
interwebs
>>> with h_annot.auth(authentication_token):
...     annot.tags = ['all', 'new', 'tags']
...     annot.tags.add('and one more')
...     annot.tags.remove('new')

不赞成通过Annotation.search()进行搜索。此搜索仅将api.search()的结果包装在批注构造函数中,因此api.search()现在应用于使用Annotation.search()的搜索。对于高级搜索界面,请使用h_annot.search()。它接受关键字参数uriusertagstext。注意,tags由and连接,text中的单独单词由or连接,这是Hypothesis search API的行为。h_annot.search()尊重由h_annot.auth()上下文管理器设置的身份验证。

h_annot.search()返回一个SearchResults实例。SearchResults实例正确响应len(),迭代将导致注释:

>>> results = h_annot.search()
800765
>>> len(results)
>>> for annotation in results:
...     print(annotation)
...     break
<Hypothesis annotation WcxuNG0CEemcl4_d0fJoaw>

SearchResults对象将根据需要加载来自假设的更多结果,但在每次后续查询之前都有一秒的延迟,以避免在完成类似于list(h_annot.search())的简单且看似无害的操作时快速重复命中假设。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使用(BluetoothGattCharacteristic)特性中的数据创建、写入和保存csv文件。getValue()   java如何使用groupBy创建一个值为BigDecimal字段平均值的映射?   日期时间Java将iso_即时格式的字符串转换为日期   java如何检索和显示Android firebase的配置文件?   scala AWSJAVASDK:解压缩大小必须小于262144000字节   要应用于列表的java JSTL if条件   java在3个点之间画一个正方形   Kotlin java抽象类IllegaAccessError   java原语双值相等取决于大小?   java有没有一种方法可以对数据集使用compareTo()方法,而不必遍历数据集的每个元素?   java为什么我发送的每个UDP消息都会改变端口源?   重新选择文件时swing Java JTree冻结   java不知道我的游戏是怎么回事   Motif L&F中自定义组合框渲染器中的Java Swing消失文本   java Trade Me API访问前的OAuth