您的位置:首页 > 编程语言 > Python开发

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

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息