m .Ec@s=dZdkZdklZdklZdklZdklZdkl Z dk l Z dk l Z d k lZd k lZd k lZd k lZd klZdklZdklZdklZdklZdklZdklZdk l Z dk!l"Z"dk#l$Z$dk%l&Z&dk'l(Z(dk)l*Z*dk+l,Z,dk-l.Z.dk/Z/ede0dddd Z1d!d!d!d!e2d"Z3deeee ee"fd#YZ4ede0dd$dd%Z5d!d!d!e2d&Z6d'Z7d$e4fd(YZ8d)Z9d*eefd+YZ:dS(,s=Image object $Id: Image.py 69771 2006-08-24 16:52:47Z shh $ N(sguess_content_type(sDTMLFile(sInitializeClass(sPropertyManager(sClassSecurityInfo(s RoleManager(schange_images_and_files(sview_management_screens(sview(s ftp_access(sdelete_objects(s rfc1123_date(sResourceLockedError(sWriteLockInterface(sItem_w__name__(sStringIO(s Persistent(sImplicit(sDateTime(s Cacheable(schoose_boundary(sHTTPRangeSupport(s FileUpload(sfilestream_iterator(sRedirect(sescapes dtml/imageAddtKindtFiletkindtfiletcCst|}t|}t|}t|}t|||\}}|i}|i |t ||d|||o|i |i |n|o||i |_n|dj o|di|idndS(sVAdd a new File object. Creates a new File object 'id' with the contents of 'file'RtRESPONSEs /manage_mainN(tstrtidttitlet content_typet preconditiontcookIdRtselftthist _setObjectRt_getObt manage_uploadtREQUESTtNonetredirectt absolute_url(R RRRR R R((t(/data/zmath/zope/lib/python/OFS/Image.pytmanage_addFile/s     " cBstZdZeeifZdZeZ e i e dZ e ZededdddZeide iede ied eZZeZhd d <d d <d d6|} t.| t/|i0}||}x|dj ot |i}||}|| jon||| }|djo d}n||jo'|||}|i"|||!Pn|i"||n|i'}|||}t|to7t|} | |jo|| fSnt|}nt|to| o tdnt |do*|i t jot|} || fSn|i }|i }|dd|i} }| d|joE|d| |jo|| | fSnt || | fSntidt|idjo$|dt || | fSnd}x|djo||}||jo d}n||t |||}|ii|||_tidt|i|idj pt|idjpt|}|}qW|| fS( NiisFile not specifiedt __class__iit optimistici(tnRHRRRAR%tStringIOt FileUploadt ValueErrorR^RztPdatatseektreadttellRFt transactiont savepointR7R t_p_jarRRNRJR$taddt _p_deactivatet_p_oidtAssertionErrort_p_state( R RRFRR|RNRJR$RR%((RR#sR                    tDELETEtPUTcCs|i|||i||dd|idd}|d}|i |\}}|i |||i |p|i}|i||||id|S(sHandle HTTP PUT requeststrefreshis content-typetBODYFILEiN(R t dav__initRRtdav__simpleifhandlerR+RR RR#R$R%R&R"R R'R6(R RRR R$RR R%((RR0s  tget_sizecCs-|i}|djot|i}n|S(sYGet the size of a file or image. Returns the size of the file or image. N(R R%RRAR$(R R%((RRAs   tgetContentTypecCs|iS(ssGet the content type of a file or image. Returns the content type (MIME type) of a file or image. N(R R (R ((RRNscCs t|iS(N(RR R$(R ((Rt__str__VscCsdS(Ni((R ((Rt__len__Wstmanage_FTPstattmanage_FTPlistt manage_FTPgetcCs|ii}|io>|idd}|dj o|id|i|SqWn|i }t |t o|i d|Snx+|dj o|i |i |i}qWdS(sReturn body for ftp.R\sContent-LengthRN(R RRRaRbRRcR4R%R$RHRRdRIRN(R RcR$R((RR]s        (Rs File_Edit.stx(Rs File_View.stx(5R"t __module__t__doc__tWriteLockInterfaceR>tHTTPRangeInterfacet__implements__t meta_typetClassSecurityInfotsecuritytdeclareObjectProtectedRR RR%tDTMLFiletglobalsRt_setNametdeclareProtectedtview_management_screensRRtmanage_uploadFormtPropertyManagertmanage_optionst RoleManagertItem_w__name__t Cacheablet _propertiesR(RR8RXRYReRhtdeclarePrivateR'tchange_images_and_filesRnRR&R#tdelete_objectsRRtgetSizeRRRt ftp_accessR(((RRLs`      ^ 0    ;     C     tImagetimagecCst|}t|}t|}t|}t|||\}}|i}|i |t ||d|||o|i |i |n|o||i |_n|dj o<y|i}Wn|d}nX|iid|n|S(sc Add a new Image object. Creates a new Image object 'id' with the contents of 'file'. RRgs%s/manage_mainN(RRRR R R RR R RRRRRRtDestinationURLturlRR(R RRRR R RR((Rtmanage_addImageys&     " c Cst|}t|}d}d}d}|djoR|d djoAd}tid|dd!\}}t |}t |}nW|d jof|d d joU|d d !djoAd}tid|d d !\}}t |}t |}n|d joR|d d joAd}tid|d d !\}}t |}t |}n|djow|d djofd}t |}|id|id}y*x |ot|djox't|djo|id}qWx't|djo|id}qWt|djoFt|djo3|idtid|id\}}Pn1|it tid|iddd|id}qWt |}t |}WqqXn|||fS(NiRi itGIF87atGIF89as image/gifsLLiss image/jpegiiiiiis>HHis>Hi(RR(RR$RAR%theighttwidthR tstructtunpacktwthtintR}tjpegRtbtord( R$RR RRRRRR%((Rt getImageInfosZ   2    & !0 c BstZdZefZdZeZeie dZ dZ dZ ei edei edei edei e dei e dei e dei ed ei ed ei ed ei ed hd d<ddN(RRR RtxscaletscaletxdeltatyscaletydeltaRRtroundRRcRR_tescapeRt css_classtargsRWtkeytgettvalue(R RRRRRRRRRRRRRcR((RR*s<    &&    (sOFSPsImage_Edit.stx(sOFSPsImage_View.stx(%R"RRRRRRRRRRRRRRRRRRRRRRRRRRReRRRRRRR'RR(((RRsD    x^     cCsq| o_t|doO|i}|p|}|t|id|id|idd}n||fS(NRut/s\t:i(RR^RRuRRVtrfind(RRRRu((RR fs   RcBs2tZdZdZdZdZdZRS(NcCs ||_dS(N(R$R (R R$((RR(uscCs|i||!S(N(R R$titj(R RR((Rt __getslice__xscCst|}t|S(N(RR R$RA(R R$((RR{s cCsn|i}|djo |iSn|ig}x1|dj o#|}|i|i|i}q0Wdi|S(NR(R RNRR$trtappendtjoin(R RRN((RRs    (R"RRRNR(RRR(((RRps    (;RRtzope.contenttypeRxtGlobalsRtInitializeClassRt AccessControlRtAccessControl.RoleRtAccessControl.PermissionsRRtviewRRRt webdav.commonR5twebdav.LockableRqtwebdav.WriteLockInterfaceRt SimpleItemRt cStringIOR}t Persistentt AcquisitiontImplicitR/tCacheRt mimetoolsROt ZPublisherR>tZPublisher.HTTPRequestR~tZPublisher.Iteratorstfilestream_iteratort zExceptionsRftcgiRRRtmanage_addFileFormRRRtmanage_addImageFormRRRR R(%RfRRR/RRRRRRRRR R>RRRRR~RRqRORRRRRR5RRR}RxRRRRR((Rt?sP                            %- " 9