由于python没有接口概念,所以zope 提供了个第三方库开源使用,下面简单介绍zope.interface.implementer的使用

直接看例子,下面例子是在twisted里摘录的

接口IResolverSimple

class IResolverSimple(Interface):
def getHostByName(name, timeout = (1, 3, 11, 45)):
"""
Resolve the domain name C{name} into an IP address.
"""

实现BlockingResolver

@implementer(IResolverSimple)
class BlockingResolver: def getHostByName(self, name, timeout = (, , , )):
try:
address = socket.gethostbyname(name)
except socket.error:
msg = "address %r not found" % (name,)
err = error.DNSLookupError(msg)
return defer.fail(err)
else:
return defer.succeed(address)

可以通过

IResolverSimple.implementedBy

IResolverSimple.providedBy

对实现进行检测

foo = BlockingResolver()

IResolverSimple.implementedBy(BlockingResolver) #display True

IResolverSimple.implementedBy(foo) #display True

zope.interface 库学习一的更多相关文章

  1. python:面向对象编程之Zope.interface安装使用

    持续学习python+django中... 一.接口简述 在我们所熟知的面向对象编程语言中,大多提供了接口(interface)的概念.接口在编程语言中指的是一个抽象类型,是抽象方法的集合:它的特点如 ...

  2. python 操作exls学习之路1-openpyxl库学习

    这篇要讲到的就是如何利用Python与openpyxl结合来处理xlsx表格数据.Python处理表格的库有很多,这里的openpyxl就是其中之一,但是它是处理excel2007/2010的格式,也 ...

  3. twisted 安装时,安装顺序为 zope.interface ->twisted

    最近想学 twisted ,就去下载 twisted 的windows版本,并且 安装.运行 twisted 例子后,发现出现了问题: ImportError: Twisted requires zo ...

  4. dlib库学习之一

    dlib库学习之一 1.介绍 跨平台 C++ 通用库 Dlib 发布 ,带来了一些新特性,包括概率 CKY 解析器,使用批量同步并行计算模型来创建应用的工具,新增两个聚合算法:中国低语 (Chines ...

  5. No module named zope.interface error的解决

    明明安装了 zope.interface,还是出现标题错误,错误语句是 from zope.interface import ooxx 根据 http://stackoverflow.com/ques ...

  6. python_库学习_01

    一.python的库学习之 财经数据接口包 1.安装ThShare 直接pip install tushare 可能会出现缺少依赖库的情况,依次安装,大概有lxml,pandas,bs4,reques ...

  7. numpy, matplotlib库学习笔记

    Numpy库学习笔记: 1.array()   创建数组或者转化数组 例如,把列表转化为数组 >>>Np.array([1,2,3,4,5]) Array([1,2,3,4,5]) ...

  8. python爬虫解析库学习

    一.xpath库使用: 1.基本规则: 2.将文件转为HTML对象: html = etree.parse('./test.html', etree.HTMLParser()) result = et ...

  9. 【mmall】Guava库学习Collections

    参考链接 Guava库学习:学习Collections(三)Sets

随机推荐

  1. [leetcode]Rotate List @ Python

    原题地址:https://oj.leetcode.com/problems/rotate-list/ 题意: Given a list, rotate the list to the right by ...

  2. 如何使用IconFont 图标

    第一步:使用font-face声明字体 @font-face {font-family: 'iconfont'; src: url('iconfont.eot'); /* IE9*/ src: url ...

  3. Linux系统中安装使用百度云网盘

    百度云没有Linux客户端,于是有大神用Go语言写出来一个叫BaiduPCS-Go的命令行盘客户端,可以通过终端操作百度云盘,在Linux上实现上传下载.但是因为是命令行版本的,对没有命令行使用基础的 ...

  4. WPF获取当前用户控件的父级窗体

    方式一.通过当前控件名获取父级窗体 Window targetWindow = Window.GetWindow(button); 方式二.通过当前控件获取父级窗体 Window parentWind ...

  5. 【Android】Android传感器

    1.加速度传感器2.磁场传感器3.方向传感器4.陀螺仪传感器5.重力传感器6.线性加速度传感器7.温度传感器8.光线传感器9.距离传感器10.压力传感器11.计步传感器 首先先查看测试的安卓机拥有的传 ...

  6. tar加密

    # tar -czvf - file_name|openssl des3 -salt -k |dd of=file_name.des3 # ls flie_name file_name.des3 # ...

  7. .NET+MVC+ORACLE存储分页查询一后端实现

    MemberController:public ActionResult UserList() { UserBll userBll = new UserBll(); string keyWords = ...

  8. 【Linux高级驱动】I2C驱动框架分析

    1.i2c-dev.c(i2c设备驱动组件层) 功能:1)给用户提供接口 i2c_dev_init  //入口函数 /*申请主设备号*/ register_chrdev(I2C_MAJOR(), &q ...

  9. elk问题,求教各位大虾!

    [filebeat --> kafka --> logstash-->MongoDB|磁盘]架构进行日志收集 但是当logstash写入MongoDB有延迟,然后正常之后,会导致lo ...

  10. stm32+rx8025

    // 设备读写地址 #define        RX8025_ADDR_READ                0x65 #define        RX8025_ADDR_WRITE       ...