python如何使用firefox的xpcom组件的
2007-03-14 19:01
591 查看
xpcom是firefox跨平台的组建。他可以通过其他语言(比如说python java javascrip)调用c/c++写的组建。 而IDL文件就是一种中间语言。python java javascript只能使用idl中定义的接口。下面代码演示如何通过python使用xpcom组建。
from xpcom import components, Exception, _xpcom
#constant variable
STORE_IN_MEMORY=components.interfaces.nsICache.STORE_IN_MEMORY
STREAM_BASED=components.interfaces.nsICache.STREAM_BASED
ACCESS_WRITE=components.interfaces.nsICache.ACCESS_WRITE
ACCESS_READ=components.interfaces.nsICache.ACCESS_READ
BLOCKING=components.interfaces.nsICache.BLOCKING
offset=0;
cacheservice_instance=components.classes["@mozilla.org/network/cache-service;1"].createInstance()
cacheservice=cacheservice_instance.queryInterface(components.interfaces.nsICacheService)
cacheKey="http://www.mozilla.org/somekey"
data="dajiahaoyahehe"
def write_data():
session=cacheservice.createSession("ucflyimage",STORE_IN_MEMORY,STREAM_BASED)
#write data;
descriptor=session.openCacheEntry(cacheKey,ACCESS_WRITE,BLOCKING)
output=descriptor.openOutputStream(offset)
output.write(data,len(data))
descriptor.bind()
descriptor.close()
write_data()
from xpcom import components, Exception, _xpcom
#constant variable
STORE_IN_MEMORY=components.interfaces.nsICache.STORE_IN_MEMORY
STREAM_BASED=components.interfaces.nsICache.STREAM_BASED
ACCESS_WRITE=components.interfaces.nsICache.ACCESS_WRITE
ACCESS_READ=components.interfaces.nsICache.ACCESS_READ
BLOCKING=components.interfaces.nsICache.BLOCKING
offset=0;
cacheservice_instance=components.classes["@mozilla.org/network/cache-service;1"].createInstance()
cacheservice=cacheservice_instance.queryInterface(components.interfaces.nsICacheService)
cacheKey="http://www.mozilla.org/somekey"
data="dajiahaoyahehe"
def write_data():
session=cacheservice.createSession("ucflyimage",STORE_IN_MEMORY,STREAM_BASED)
#write data;
descriptor=session.openCacheEntry(cacheKey,ACCESS_WRITE,BLOCKING)
output=descriptor.openOutputStream(offset)
output.write(data,len(data))
descriptor.bind()
descriptor.close()
write_data()
相关文章推荐
- firefox附加组件开发者指南(四)——使用XPCOM:实现高级处理
- FireFox插件和扩展开发(二)——编写和使用XPCOM组件
- FireFox插件开发(二) --- 编写和使用XPCOM组件
- 使用python写的如何自动提交和抓取网页
- Python下使用help(dict),显示'more'不是内部或外部命令,也不是可运行的程序或批处理文件,该如何处理?
- 在Python的一段程序中如何使用多次事件循环详解
- python - pip 如何使用代理安装库
- web Servlet中如何使用上传组件FileUpload
- 如何使用Eclipse最简单地配置其他语言的IDE环境:例子-Python
- 青少年如何使用 Python 开始游戏开发
- python 6-3 如何解析简单的xml文档 使用标准库中的xml.etree.ElementTree,其中parse函数可以解析xml文档
- python 6-4 如何构建xml文档使用标准库中的xml.etree.ElementTree 构建ElementTree,使用write方法写入文档
- 如何使用一个不错的图表组件WebChart(免费)
- Linux下Python安装完成后如何使用pip命令
- python 8-4 如何使用线程本地数据,threading.local函数可以创建线程本地数据空间,属性对每个线程独立存在
- Debian9(8)下python3和python2同时安装如何使用pip
- 多版本python如何使用pip
- [Python系列实用教程]一、Python如何使用urllib2获取网络资源
- 我是如何使用 Python 优雅的薅到网易uu的羊毛的
- Visual C#如何使用Active X组件