python如何使用firefox的xpcom组件的

    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()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值