Current File : //proc/self/root/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyo
�
�SK\c@s3dZddlmZmZmZddlZddlZdZdZdZ dZ
dZd Zd
Z
dZd�Zd
dd��YZdefd��YZdefd��YZd�Zd�Zd�Zd�Zd�Zedkr/ddlZeej�dkrdGHe�q/eejd�ndS(s�Implementation of Python file objects for Mozilla/xpcom.
Introduction:
This module defines various class that are implemented using
Mozilla streams. This allows you to open Mozilla URI's, and
treat them as Python file object.
Example:
>>> file = URIFile("chrome://whatever")
>>> data = file.read(5) # Pass no arg to read everything.
Known Limitations:
* Not all URL schemes will work from "python.exe" - most notably
"chrome://" and "http://" URLs - this is because a simple initialization of
xpcom by Python does not load up the full set of Mozilla URL handlers.
If you can work out how to correctly initialize the chrome registry and
setup a message queue.
Known Bugs:
* Only read ("r") mode is supported. Although write ("w") mode doesnt make
sense for HTTP type URLs, it potentially does for file:// etc type ones.
* No concept of text mode vs binary mode. It appears Mozilla takes care of
this internally (ie, all "text/???" mime types are text, rest are binary)
i����(t
componentst Exceptiont_xpcomNiiiiii i@i�cCsptjdjtjj�}|j|�tjdjtjj�}|j|�j tjj
�}||_|S(s1Convert a filename to an XPCOM nsIFileURL object.s@mozilla.org/file/local;1s!@mozilla.org/network/io-service;1(RtclassestcreateInstancet
interfacestnsILocalFiletinitWithPatht
getServicetnsIIOServicet
newFileURItqueryInterfacet
nsIFileURLtfile(t
localFileNamet localFilet
io_serviceturl((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pytLocalFileToURLNs
t_FilecBsbeZddd�Zd�Zd�Zd�Zdd�Zd�Zd�Z d �Z
d
�ZRS(trcCsBtj�|_d|_|_|dk r>|j||�ndS(N(t threadingtLocktlockobtNonetinputStreamtoutputStreamtinit(tselftname_thingytmode((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyt__init___scCs|j�dS(N(tclose(R((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyt__del__escCs|jj�dS(N(Rtacquire(R((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyt_lockiscCs|jj�dS(N(Rtrelease(R((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyt_releaseksi����cCs6|j�zt|jj|��SWd|j�XdS(N(R#tstrRtreadR%(Rtn((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyR'ms
cCs_|j�jd�}t|�rDt|d�dkrD|d }ng|D]}|d^qKS(Ns
i����i(R'tsplittlen(Rtlinests((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyt readlinesus"
cCs9|j�z|jj|t|��Wd|j�XdS(N(R#RtwriteR*R%(Rtdata((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyR.}s
cCsy|j�z]|jdk r5|jj�d|_n|jdk r]|jj�d|_nd|_Wd|j�XdS(N(R#RRR RtchannelR%(R((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyR �s
cCs?|j�z#|jdk r,|jj�nWd|j�XdS(N(R#RRtflushR%(R((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyR1�s
N(t__name__t
__module__RRR!R#R%R'R-R.R R1(((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyR^s
tURIFilecBseZdd�ZRS(RcCs�|j�|dkr%td��ntjdjtjj�}t|d�rY|}n|j|dd�}|j
s�td|jf��n|j|�|_
|j
j�|_dS(NRsonly 'r' mode supporteds!@mozilla.org/network/io-service;1Rs#The URI '%s' is invalid (no scheme)(R t
ValueErrorRRRRR thasattrtnewURIRtschemetspectnewChannelFromURIR0topenR(RRRRturl_ob((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyR�s
(R2R3R(((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyR4�st LocalFilecBs2eZd�Zdd�Zd�Zdd�ZRS(cGsd|_tj||�dS(N(RtfileIORR(Rtargs((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyR�s RcCsStjj|�}|j�tjdjd�}|j|�|dkr�tjdjd�|_|dkr�|j �r�|j
d�nttB}n|dkr�t
}n|jj||dd�|j|_ny|d krCtjd
jd�|_|jj|tdd�tjdjd
�|_|jj|j�ntd��dS(Ns@mozilla.org/file/local;1Rtwtas)@mozilla.org/network/file-output-stream;1tnsIFileOutputStreamii����Rs(@mozilla.org/network/file-input-stream;1tnsIFileInputStreams$@mozilla.org/scriptableinputstream;1tnsIScriptableInputStreamsUnknown mode(R@RA(tostpathtabspathR RRRRR>texiststremovetNS_CREATE_FILEt NS_WRONLYt NS_APPENDRRt NS_RDONLYRR5(RtnameRR
tmoz_mode((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyR�s(
cCs9|jdk r(|jj�d|_ntj|�dS(N(R>RR R(R((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyR �s
i����cCstj||�S(N(RR'(RR(((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyR'�s(R2R3RRR R'(((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyR=�s cCs}|jd�}||jd�}||jd�}||j�}||krytd|t|�t|�f��ndS(Nii,is9Reading '%s' failed - got %d bytes, but expected %d bytes(R'tRuntimeErrorR*(R
texpectedtgot((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyt_DoTestRead�scCs�tjd�}d}x9|jj|�}|dkr:Pn|t|| �}q||kr�td|t|�t|�f��ndS(Ni2tis9Reading '%s' failed - got %d bytes, but expected %d bytes(RtAllocateBufferRR'R&RPR*(R
RQtbufferRRtnum((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyt_DoTestBufferRead�scCsGddl}ddl}|j�}d}t|d�}z�|j|�|j�t|d�}|j�|j|d�t|j ��}|j�t|d�}|j d�|j �}|j�|j
j|�s�td|f��nt|d�}|j|�|j�t|d�}|j�Wd|j
|�XdS(Ni����sHello from PythonR@Ri
sYThe file '%s' does not exist, but we are explicitly testing create semantics when it does(ttempfileREtmktempR=R.R R;RR&R'RFtisfileRPtunlink(RYREtfnameR/t test_filetfRR((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyt_TestLocalFile�s.
cCs�tj}|ddkr&|d }nt|d�j�}t|�}tt|j�|�tt|�|�tt|�|�tt |�|�t
�dS(Ni����tcCoOtrb(Rt__file__R;R'RRSR4R9RXR=R`(R]RQR((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyt_TestAlls
cCsFt|�}d|fGH|j�}dt|�|fGH|j�dS(NsOpened file issRead %d bytes of data from %r(R4R'R*R (RR^RR((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyt_TestURI1s
t__main__s7No URL specified on command line - performing self-test((t__doc__txpcomRRRRERRMRKtNS_RDWRRJRLtNS_TRUNCATEtNS_SYNCtNS_EXCLRRR4R=RSRXR`RdReR2tsysR*targv(((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyt<module>>s4 <- %