假设的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如何拆分字符串(基于各种分隔符),但不保留空格?   解析。Json格式的txt文件和knime中的java   java Spring rest api为什么在rest api调用的响应中更改了数据类型   升华文本3抛出java。lang.ClassNotFoundException,而记事本++不存在   java Android指纹扫描仪在尝试5次后停止工作?   java Android如何设置精确的重复报警?   java如何使用HTTPGET connect为access API输入用户名和密码   java当测试报告显示没有测试失败时,Gradle为什么说“有失败的测试”?   用Gson实现java获取响应   MapReduce程序中函数错误的java不可映射参数   java spring安全性不符合自动代理的条件   java GWT使用异步回调进行同步/阻塞调用   java奇怪的类数组问题无法在jsp中显示   如何在java中使用PrinterJob使用epl打印条形码   java如何在JTable中居中单元格   将Java Mockito测试转换为Kotlin   html Java正则表达式模式匹配到多个相同标记   testCompile中缺少java Gradle(Android)多项目依赖项   在输入提示后输入字符串时发生java FileNotFoundException