Annotation of ExtFile/ExtImage.pyc, revision 1.1

1.1     ! dwinter     1: m
        !             2: [ Ec@s~&dZd&ZdZ&dkZdkTdklZlZlZ&dklZ&dk l
        !             3: Z
        !             4: &dkZdkZdk
Z
dkZdklZlZ&d klZ&d
        !             5: klZ&dklZ&dkTdZd
ZydklZ&Wnej
        !             6: o
&&&&dZn&XdklZ&d
Z dZ!dZ"dZ#ede$Z%ddddddd
ddd
d
d
e&d
Z'de(f&dYZ)ee)&&dS(sExtImage product module.sExtImage product module.
        !             7:     The ExtImage-Product works like the Zope Image-product, but stores the 
        !             8:     uploaded image externally in a repository-direcory. It creates a preview
        !             9:     of the image (requires PIL).s1.5.4N(&t&*(sHTMLFiles
MessageDialogsInitializeClass(&sClassSecurityInfo(&sResourceLockedError(sjoinsisfile(&s
TemporaryFile(&sWriteLockInterface(&s   IExtImagetExtImagei(&sRedirecttRedirect(&sREPOSITORY_UMASKi&iisdtml/extImageAddtcCsW&|&o}&t&|d&d    d   j  od&|i}&|&tti|&dti|&dti|&dd}&|p&|&}t  |&&}&n&&t
        !            10: |&||||}|i|&|&|djo,&|i|&&i||d||| |
        !            11: &n&&|tjp
&|tjo,&|i|&&i||d||| |
        !            12: &n&&|
d  j  o&|i||
dd&Sn&&|&S(
        !            13: s Add an ExtImage to a folder. tfilenamet&/s&\t&:i&Ritupdate_menuN(tidtgetattrtfiletNoneRtmaxtstringtrfindttitletnormalize_idR&tdescrtpermission_checktredirect_default_viewttempExtImagetselft
        !            14: _setObjectt_getObtmanage_file_uploadtcontent_typetcreate_prevtmaxxtmaxytratiotUPLOAD_NORESIZEt
UPLOAD_RESIZEtpreviewtREQUESTtmanage_main(RRRRR
        !            15: R RRRRRRRR!R((t0/usr/local/testzope/Products/ExtFile/ExtImage.pytmanage_addExtImageNs"&! &&&&
&&&&
&,&&,&
&&cBstZ&dZeefZeZd&Zhdd<dd<dd<Z e  dZ
        !            16: e dZddd d  d
        !            17: ZdZ
eied&d  d  eeed d  d  d
ed
        !            18: Zeied&dZeied&dZeied&dZeied&dZeied&dZeied&dZeied&dZeied&dZeied&d Zeied!&d"Zeied#&d$Zeied%&d&Zeied'&d(Zeied)&d*Z eied+&e!d,e"Z#eie$d-&ed.&Z%eie$d/&d  d  d  ed0Z&eied1&e!d2e"Z'eie$d3&ddd  e(ddd ed4Z)eie$d5&ddd    e(ddd ed6Z*eie$d7&d  ed8Z+eie$d9&d:Z,d;Z-d<Z.d=Z/d>Z0d?Z1ed@&Z2ei3dA&&dBZ4ei3dC&&dDZ5ei3dE&&dFZ6dGZ7dHZ8RS(Is The ExtImage-Product works like the Zope Image-product, but stores the 
        !            19:         uploaded image externally in a repository-direcory. It can create a 
        !            20:         preview of the image (requires PIL).R&tdefaulti&tmini&RiRicCsJti&d&&||&||||&g|_d|_    d|_
        !            21: d|_dS(s' Initialize a new instance of ExtImage t__init__Ri&iN(R&tinheritedAttributeRRRRRRt
prev_filenametprev_content_typet
        !            22: prev_ratiothas_preview(RRRRRR((R#R'}s&&"&    &   &   &c&&&Cs
        !            23: |i&S(&N(Rttag(&R((R#t__str__s&R-t&0cKs
|i&p
        !            24: &d&}&n&&|ip
        !            25: &d&}&n&&|&o&|io
        !            26: &d&}n&&|o"&|idd&&}d\}}
nZ&|&o.&|idd&&}|i
        !            27: |i&\}}
n%&|i}|i
        !            28: |i&\}}
|p&|
}|p&|}|p&|}|p&|}|o'&|djo&tt|&|&}n&&|o'&|djo&tt|&|&}n&&|djo&|ip&d}n&&d||    |f}|o&d||f}n&&|o&d||f}n&&x6|iD](}|i|&}d    |||f}q&Wd
        !            29: |}|S(
s= Generate an HTML IMG tag for this image, with customization.
        !            30:             Arguments to self.tag() can be any valid attributes of an IMG tag.
        !            31:             'src' will always be an absolute pathname, to prevent redundant
        !            32:             downloading of images. Defaults are applied intelligently for
        !            33:             'height', 'width', and 'alt'. If specified, the 'scale', 'xscale',
        !            34:             and 'yscale' keyword arguments will be used to automatically adjust
        !            35:             the output height and width values of the image tag.
        !            36:             Adopted and adapted from OFS/Image.py
        !            37:         i&ticoni R Rs"<img src="%s" border="%s" alt="%s"s%s height="%s"s
%s width="%s"s
        !            38: %s %s="%s"s%s />N(i i ( Rtis_webviewableR t_access_permittedR,R0t_static_urlturlt img_widtht
        !            39: img_heightt
_getImageSizeR)RtheighttwidthtxscaletscaletxdeltatyscaletydeltaRtstrtinttaltRtbordertstrgtargstkeystkeytgettvalue(RR R0R8R9RAR;R:R=RBR!RDR5R6R<RFR>R4RHRC((R#R-sH
        !            40: &
&
        !            41: &
&
        !            42: &&
        !            43: &&&&&&&&
&

&
&&&&
&&&
&&&
        !            44: &R c&&Cst|id&d&dS(s Return a preview of the image R i&N(RRR3(&R((R#R s&&tpreview_tagc&&Cs|i&d&d&S(s2 Generates the HTML IMG tag for the preview image R i&N(RR-(&R((R#RIs&&tpreview_htmlc&&&Cs
        !            45: |i&S(s Same as preview_tag N(RRI(&R((R#RJs&&t   is_brokenc&&CsO|i&o2&|i|ijo&|i|i&p&d&Sq<&n&&tid&|&S(s@ Check if external file exists and return true (1) or false (0) i&RKN(RR,RR)t_get_fsnameR&R((&R((R#RKs
        !            46: &&&&&R1c&CsC|i&}&|&d&jp&|&djp
&|&djo&dSn&dSdS(s< Return 1 for GIF, JPEG, and PNG images, otherwise return 0 tJPEGtGIFtPNGi&iN(Rtformat(RRP((R#R1s
        !            47: &&&'&t
get_prev_sizec&Cs2|i&|i&}&|&o&ti|&&d&Sn&&dS(s& Returns the size of the preview file iiN(RRLR)tfntoststat(RRR((R#RQs
        !            48: &&&&&tprev_rawsizec&&&Cs
        !            49: |i&S(s Same as get_prev_size N(RRQ(&R((R#RUs&&t prev_sizec&&Cs|i&|i&S(s= Returns a formatted stringified version of the preview size N(Rt
_bytetostringRQ(&R((R#RVs&&R9c&&Cs|i&|i&d&S(s Pixel width of the image iN(RR7R(&R((R#R9s&&R8c&&Cs|i&|i&d&S(s Pixel height of the image i&N(RR7R(&R((R#R8s&&t
        !            50: prev_widthc&&Cs|i&|i&d&S(s Pixel width of the preview iN(RR7R)(&R((R#RXs&&tprev_heightc&&Cs|i&|i&d&S(s Pixel height of the preview i&N(RR7R)(&R((R#RYs&&RPc&CsK|i&|i&}y'd&kl}&|i|&}&|&iSWn&&&dSn&XdS(s& Get the PIL file format of the image (&sImagetunknownN(RRLRtPILtImagetopentimRP(RR^R\R((R#RP&s&&&&
&&&&tget_prev_filenamec&&Cs|i&|i&S(s+ Returns the preview file name for display N(Rt_fsnameR)(&R((R#R_&s&&R"sdtml/extImageEdittmanage_del_prevcCs1&|i&o&|i|ijo&|i|i&}|i|i&}t|&oY&yt i
        !            51: ||d&&Wntj
        !            52: o&&&&q&Xyt  i|&&Wqtj
        !            53: o&&&&q&Xq&t|&o2&yt i
        !            54: ||d&&Wqtj
        !            55: o&&&&q&Xq&n&&d|_
d|_&|i&|&dj   o&|i||&dd&Sn&&dS(s Delete the Preview Image s.undoRitmanage_tabs_messagesPreview deleted.N(RR,RR)t_temp_fsnamettmp_fnR`RRtisfileRStrenametOSErrortremoveR*tZCacheable_invalidateR!RR"(RR!RdRR((R#Ra&s.&&&&&
&&&    &
&&
& &   
        !            56: 
&tmanage_create_prevcCs&|i&|&|\}&}|&d&joa&|d&joT&|i&z8|i|idd&&}|i|i  ||&||&Wd|i&Xn&&|djo&|iSnu&|io&|i||dd&SnQ&|&djo*&|djo&tdd   d
        !            57: ddd
Sn&tddd
        !            58: ddd
SdS(s Create a preview Image iRs
        !            59: image/jpegNRbsPreview created.R/Rt    AttentiontmessagesYou must enter a value > 0tactions
./manage_maintWarnings/An error occurred while generating the preview.(Rt_formatDimensionsRRt _registert_get_ufnR)tnew_fnt_createPreviewRRt_dir__unlockR!RR,R"t
MessageDialog(RRRRR!Rr((R#Rj3&s(&&&&
        !            60: &&& &&&
&
        !            61: &&&  &   &tmanage_uploadFormsdtml/extImageUploadt
manage_uploadc    
        !            62:     Cs|i&o
&td&n&&t|&&tijo'&t} |  i  |&&&|   i
        !            63: d&&n&|&}   |i|    |||||||S(s0 Upload image from file handle or string buffer sFile is locked via WebDAViN(Rtwl_isLockedtResourceLockedErrorttypeR
        !            64: ttypest
        !            65: StringTypet
TemporaryFilet   temp_filetwritetseekRRt
        !            66: is_previewRRRRR!(
        !            67: RR
        !            68: RRRRRRR!R~((R#RwR&s&
&
& &
&&&Rc Cs|i&o
&td&n&&|o&&t|&&tijo0&d}
        !            69: yt  |&d}&Wqg&&&|
        !            70: |&qgXn&&|i
        !            71: ||\}}|tjo&|djow&|djoj&|i&z5|i|idd&&}  |i|&|i|   &&Wd|i&X|i|  |  |||&qx&|o&t|&|}&n&&|i|&|&id&|i|i|_|&id&&|i&z8|i|id|i&&}   |i|&|i|   &&Wd|i&X|    |_|i&n&t i!d    &||&|&|t"jo&|i
        !            72: ||\}}|djoa&|djoT&|i&z8|i|idd&&}   |i|i#|  |||&Wd|i&Xqx&n&&|dj    o&|i&||d
        !            73: d&Sn&&dS(s2 Upload image from file handle or local directory sFile is locked via WebDAVsCan't open: trbiRs
        !            74: image/jpegNidRRbsUpload complete.('RRxRyRRzR
        !            75: R{R|t
cant_read_excR]RoRRRRRpRqR)Rrt_update_dataRcRtRsRRt
        !            76: HTTPUploadt_get_content_typetreadRR*Rt_initPreviewR&R(tGENERATERR!RR"(RR
        !            77: RRRRRRR!RrR((R#Rc&sX&
&
&&&&&&'&
        !            78: &&&&&&&&&&
&
        !            79: &&&&&&    &&
&&&
        !            80: &&& &&&
&tmanage_http_uploadcCsJ&|i&o
&td&n&&|o&ti|&d}&d}yti|&&}Wn&&&||&n&Xt
        !            81: |&}|i||id&|i
|i|_|id&&|i&z8|i|id|i&&}|i||i|&&Wd|i&X||_|i&n&tid&||&&|dj  o&|i||d  d
        !            82: &Sn&&dS(s Upload image from http-server sFile is locked via WebDAVs/:sCan't open: idiRNRRbsUpload complete.(RRxRyRturllibtquoteR4RturlopenR
        !            83: RRRRR*RRpRqR)RrRRcRtRR&R(R!RR"(RR4RR!R
        !            84: RRr((R#R&s2&&
&
&&&&
&&&&
&
        !            85: &&&&&&    &    
&tPUTcCsti&d&&||&|}|io&|i|i|i\}}|i&z~y|i&Wn)t
j
        !            86: o&&&&|i|&id&}n&Xd}|i|iddd|&}|i|i||||i&Wd|i&Xn&&|S(s Handle HTTP PUT requests RiRs
        !            87: image/jpegtpathN(R&R(RR!tRESPONSER,Rot   prev_maxxt   prev_maxyRRRpt    aq_parentt
AttributErrort_get_zodb_pathtPARENTSRRRqR)RrRsRR+Rt(RR!RRRRrR((R#R&s &&&
        !            88: &&
        !            89: &&&&&&#&&&cCsY|i&|&&}&y8d&kl}&|i|&&}|id|idfSWn&&&dSn&XdS(s& Return width, height tuple using PIL (&sImageii&N(ii(RRLRR[R\R]R^tsize(RRR^R\((R#R7&s&&&&
&&&&cCs&yd&kl&}&Wntj
        !            90: o&&&&nq&&X|i|&&}|oY&&|i|&}
        !            91: |
        !            92: i djo&|
        !            93: i
        !            94: d&}
        !            95: n&&|i}t
|do
&|i}n&&|o&|
        !            96: i||f|&n&|
        !            97: i||f|}
        !            98: tit&}|i|&}  y|
        !            99: i|  ddd&&WnO&&&ti|&&t|  &o+&yti|  &&WqQ&tj
        !           100: o&&&&qQ&&Xn&&nXti|&&d|_||_||_ ||_!||_"n&&|i#&dS(  s Generate a preview using PIL (&sImagetRGBt  ANTIALIASRMtqualityiUs
        !           101: image/jpegN($R[R\tImportErrorRRLt
from_filenametimfileR]R^tmodetconverttBICUBICtfilterthasattrRRt  thumbnailRRtresizeRStumasktREPOSITORY_UMASKRctto_filenametoutfiletsaveReRhRgR*R)RRR+R(RRRRRRRRRRR^R\((R#Rs&sF&&&&&&&&&&    &&
&&&&&&&&
&
&& &
&   &   &   &   &
&c&CsV|i&&|i|i&\}}&|d&j&p
&|&d&j&o
&d&|_n
        !           102: &d|_dS(s Verify the preview ii&N(RRiR7R)RXRYR,(RRYRX((R#Rs&&
        !           103: &&
cCsV&t|&&tijo7&yt|&&}&WqMtj
        !           104: o&&&&|id&}&qM&Xn&&t|&tijo7&yt|&}Wqtj
        !           105: o&&&&|id&}q&Xn&&|&djo&|djo&|&|idjo&|id}&n&&|&|idjo&|id}&n&&||idjo&|id}qL&&||idjo&|id}qL&&n&&|&|fS(s+ Make sure, the dimensions are valid int's R%iR&RN(  RzRR{R|R@t
        !           106: ValueErrorRt_image_sizeR(RRR((R#Ros*&&&&&&&&&&&&&c&Cs|i&ov&|i|ijoc&|i|i&}&t|&&o?&t|&d&&o.&|i&ti   |&d&|i
        !           107: |i&&q&n&&tid&|&S(s- Restore filename after delete or copy-paste s.undot_undoN(
RR,RR)R`RRReRpRSRfRcR&R((RRR((R#Rs&&&&&
        !           108: &(&c   CsXd&kl&}&||&\}}}|o
        !           109: &|}n"&tid&||&|||}|S(s Determine the mime-type (&sgetImageInfoRN(t OFS.ImagetgetImageInfotbodytctt&wt&hRR&R(RR
        !           110: R(  RR
        !           111: RRRRRRR((R#R$s&&
&&&
        !           112: &&tmanage_afterClonecCs<&y|i&&Wntj
        !           113: o&&&&n&&Xtid&&||&}|i&z|id|i    &}|ioh&|i|i
joU&|i|i
&}|o&&|i||i|&&||_
q&&g|_
d|_nG&|io3&|i|i&}|p&g|_
d|_q&&n
        !           114: &g|_
Wd|i&X|Stid&&||&S(s When a copy of the object is created (zope copy-paste-operation),
        !           115:             this function is called by CopySupport.py. A copy of the external 
        !           116:             file is created and self.filename is changed.
        !           117:         RRiN(RRtAttributeErrorR&R(titemtresultRpt_get_new_ufnR*tnew_prev_fnR,RR)RLtold_prev_fnRRctold_fnRt(RRRRRR((R#R4s4&&&&&
        !           118: &&&&&&&
    &
&
        !           119: &&  &
&&&&tmanage_afterAddcCsti&d&&||&|S(s When a copy of the object is created (zope copy-paste-operation),
        !           120:             this function is called by CopySupport.py. A copy of the external 
        !           121:             file is created and self.filename is changed.
        !           122:         RN(R&R(RRt   container(RRR((R#RXs&tmanage_beforeDeletecCs&|i&o&|i|ijo&|i|i&}|i|i&}t|&oY&yt   i
        !           123: ||d&&Wntj
        !           124: o&&&&q&Xyt  i|&&Wqtj
        !           125: o&&&&q&Xq&t|&o2&yt i
        !           126: ||d&&Wqtj
        !           127: o&&&&q&Xq&n&&t
id&||&|S(s`& This method is called, when the object is deleted. To support 
        !           128:             undo-functionality and because this happens too, when the object 
        !           129:             is moved (cut-paste) or renamed, the external file is not deleted. 
        !           130:             It is just renamed to filename.undo and remains in the 
        !           131:             repository, until it is deleted manually.
        !           132:         s.undoRN(RR,RR)RcRdR`RRReRSRfRgRhR&R(RR(RRRRdRR((R#R`s&&&&&
&&&    &
&&
&c&Cs|i&o&|i|i&jo&|i|i&&}&to&tttd&|&&n&&t    |&&ol&to&tttd|&&n&&|i
        !           133: |i&&}yti
|&&Wntj
        !           134: o&&&&n&Xti|&|&q&n&&tid&|&&dS(s Commits the temporary file sfinishing %ss   isfile %st_finishN(RR)RRcRdt_debugtLOGt_SUBSYStINFOReR`RRRSRhRgRfR&R((RRdRR((R#Rys&&&&&
&&&&&&c&Cs|i&o&|i|i&jo&|i|i&&}&to&tttd&|&&n&&t    |&&oJ&to&tttd|&&n&&yt
        !           135: i|&&&Wqtj
        !           136: o&&&&q&Xq&n&&t
id&|&&dS(s Deletes the temporary file saborting %ss    isfile %st_abortN(RR)RRcRdRRRRReRSRhRgR&R((RRd((R#Rs&&&&&
&&&
&(9t__name__t
        !           137: __module__t__doc__t IExtImagetWriteLockInterfacet__implements__tClassSecurityInfotsecurityt  meta_typeRRRR'R.tdeclareProtectedtViewPermissionRR-R RIRJRKR1RQRURVR9R8RXRYRPtAccessPermissionR_tHTMLFiletglobalsR"tChangePermissionRaRjRvt
        !           138: NO_PREVIEWRwRRRR7RsRRoRRtdeclarePrivateRRRRR(((R#R&fs    !
        !           139: &
        !           140:     &'0& & & & & & & & & & & & & 
        !           141: &     &&&&&!&!1&#&     
        !           142:    &   
        !           143:           
&    #
& 
&    
(*Rt__version__tGlobalstProducts.ExtFile.ExtFileRRutInitializeClasst
AccessControlRtwebdav.LockableRyRRSR
R{tos.pathtjoinRettempfileR}twebdav.WriteLockInterfaceRtIExtFileRtzLOGRRtzExceptionsRRtConfigRRRRRRtmanage_addExtImageFormRR$tExtFileR&(RRRRRRReRRRR{RRRR
RyRRRuRR}R$RRRR&RRS((R#t&?&s<)    &&&
&
&$&&

&
&&&
&&&0.

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>