%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/2/cwd/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/
Upload File :
Create Path :
Current File : //proc/2/cwd/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyc

�
�SK\c@s3dZddlmZmZmZddlZddlZdZdZdZ	dZ
dZd	Zd
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
interfacestnsILocalFiletinitWithPatht
getServicetnsIIOServicet
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	threadingtLocktlockobtNonetinputStreamtoutputStreamtinit(tselftname_thingytmode((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyt__init___scCs|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����cCsQ|jdk	std��|j�zt|jj|��SWd|j�XdS(NsNot setup for read!(RRtAssertionErrorR#tstrtreadR%(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"
cCsT|jdk	std��|j�z|jj|t|��Wd|j�XdS(NsNot setup for write!(RRR&R#twriteR+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.pyR2�s

N(t__name__t
__module__RRR!R#R%R(R.R/R R2(((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	thasattrtnewURIRtschemetspectnewChannelFromURIR1topenR(RRRRturl_ob((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyR�s

		(R3R4R(((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyR5�st	LocalFilecBs2eZd�Zdd�Zd�Zdd�ZRS(cGsd|_tj||�dS(N(RtfileIORR(Rtargs((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyR�s	RcCsetjj|�}|j�tjdjd�}|j|�|dkr�tjdjd�|_|dkr�|j	�r�|j
d�nttB}n'|dkr�t
}nds�td��|jj||d	d�|j|_ny|d
krUtjdjd�|_|jj|td	d�tjd
jd�|_|jj|j�ntd��dS(Ns@mozilla.org/file/local;1Rtwtas)@mozilla.org/network/file-output-stream;1tnsIFileOutputStreamis
Can't happen!i����Rs(@mozilla.org/network/file-input-stream;1tnsIFileInputStreams$@mozilla.org/scriptableinputstream;1tnsIScriptableInputStreamsUnknown mode(RARB(tostpathtabspathR RRRRR?texiststremovetNS_CREATE_FILEt	NS_WRONLYt	NS_APPENDR&RRt	NS_RDONLYRR6(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(R3R4RRR 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(tRuntimeErrorR+(R
texpectedtgot((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyt_DoTestRead�scCs�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'RQR+(R
RRtbufferRStnum((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyt_DoTestBufferRead�scCs�ddl}ddl}|j�}d}t|d�}ze|j|�|j�t|d�}|j�|ks�td��|j�|j	|d�t
|j��}||ks�t|��|j�t|d�}|jd�|j�}||kst|��|j�|jj|�s@t
d|f��nt|d�}|j|�|j�t|d�}|j�|ks�td��|j�Wd|j|�XdS(	Ni����sHello from PythonRARs5Eeek - Python could not read the data back correctly!i
sYThe file '%s' does not exist, but we are explicitly testing create semantics when it doessWEeek - Python could not read the data back correctly after recreating an existing file!(ttempfileRFtmktempR>R/R R<R(R&RR'RGtisfileRQtunlink(RZRFtfnameR0t	test_filetfRS((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyt_TestLocalFile�s6






cCs�tj}|ddkr&|d }nt|d�j�}t|�}tt|j�|�tt|�|�tt|�|�tt	|�|�t
�dS(Ni����tcCoOtrb(Rt__file__R<R(RRTR5R:RYR>Ra(R^RRR((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(R5R(R+R (RR_RS((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__txpcomRRRRFRRNRLtNS_RDWRRKRMtNS_TRUNCATEtNS_SYNCtNS_EXCLRRR5R>RTRYRaReRfR3tsysR+targv(((s;/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/file.pyt<module>>s4	<-				%		


Zerion Mini Shell 1.0