source: sandbox/filemanager/tp/fckeditor/editor/filemanager/connectors/py/fckoutput.py @ 1575

Revision 1575, 3.9 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Implentação, melhorias do modulo gerenciador de arquivos

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2
3"""
4FCKeditor - The text editor for Internet - http://www.fckeditor.net
5Copyright (C) 2003-2009 Frederico Caldeira Knabben
6
7== BEGIN LICENSE ==
8
9Licensed under the terms of any of the following licenses at your
10choice:
11
12- GNU General Public License Version 2 or later (the "GPL")
13http://www.gnu.org/licenses/gpl.html
14
15- GNU Lesser General Public License Version 2.1 or later (the "LGPL")
16http://www.gnu.org/licenses/lgpl.html
17
18- Mozilla Public License Version 1.1 or later (the "MPL")
19http://www.mozilla.org/MPL/MPL-1.1.html
20
21== END LICENSE ==
22
23Connector for Python (CGI and WSGI).
24
25"""
26
27from time import gmtime, strftime
28import string
29
30def escape(text, replace=string.replace):
31        """
32        Converts the special characters '<', '>', and '&'.
33
34        RFC 1866 specifies that these characters be represented
35        in HTML as &lt; &gt; and &amp; respectively. In Python
36        1.5 we use the new string.replace() function for speed.
37        """
38        text = replace(text, '&', '&amp;') # must be done 1st
39        text = replace(text, '<', '&lt;')
40        text = replace(text, '>', '&gt;')
41        text = replace(text, '"', '&quot;')
42        return text
43
44def convertToXmlAttribute(value):
45        if (value is None):
46                value = ""
47        return escape(value)
48
49class BaseHttpMixin(object):
50        def setHttpHeaders(self, content_type='text/xml'):
51                "Purpose: to prepare the headers for the xml to return"
52                # Prevent the browser from caching the result.
53                # Date in the past
54                self.setHeader('Expires','Mon, 26 Jul 1997 05:00:00 GMT')
55                # always modified
56                self.setHeader('Last-Modified',strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime()))
57                # HTTP/1.1
58                self.setHeader('Cache-Control','no-store, no-cache, must-revalidate')
59                self.setHeader('Cache-Control','post-check=0, pre-check=0')
60                # HTTP/1.0
61                self.setHeader('Pragma','no-cache')
62
63                # Set the response format.
64                self.setHeader( 'Content-Type', content_type + '; charset=utf-8' )
65                return
66
67class BaseXmlMixin(object):
68        def createXmlHeader(self, command, resourceType, currentFolder, url):
69                "Purpose: returns the xml header"
70                self.setHttpHeaders()
71                # Create the XML document header
72                s =  """<?xml version="1.0" encoding="utf-8" ?>"""
73                # Create the main connector node
74                s += """<Connector command="%s" resourceType="%s">""" % (
75                                command,
76                                resourceType
77                                )
78                # Add the current folder node
79                s += """<CurrentFolder path="%s" url="%s" />""" % (
80                                convertToXmlAttribute(currentFolder),
81                                convertToXmlAttribute(url),
82                                )
83                return s
84
85        def createXmlFooter(self):
86                "Purpose: returns the xml footer"
87                return """</Connector>"""
88
89        def sendError(self, number, text):
90                "Purpose: in the event of an error, return an xml based error"
91                self.setHttpHeaders()
92                return ("""<?xml version="1.0" encoding="utf-8" ?>""" +
93                                """<Connector>""" +
94                                self.sendErrorNode (number, text) +
95                                """</Connector>""" )
96
97        def sendErrorNode(self, number, text):
98                if number != 1:
99                        return """<Error number="%s" />""" % (number)
100                else:
101                        return """<Error number="%s" text="%s" />""" % (number, convertToXmlAttribute(text))
102
103class BaseHtmlMixin(object):
104        def sendUploadResults( self, errorNo = 0, fileUrl = '', fileName = '', customMsg = '' ):
105                self.setHttpHeaders("text/html")
106                "This is the function that sends the results of the uploading process"
107
108                "Minified version of the document.domain automatic fix script (#1919)."
109                "The original script can be found at _dev/domain_fix_template.js"
110                return """<script type="text/javascript">
111                        (function(){var d=document.domain;while (true){try{var A=window.parent.document.domain;break;}catch(e) {};d=d.replace(/.*?(?:\.|$)/,'');if (d.length==0) break;try{document.domain=d;}catch (e){break;}}})();
112
113                        window.parent.OnUploadCompleted(%(errorNumber)s,"%(fileUrl)s","%(fileName)s","%(customMsg)s");
114                        </script>""" % {
115                        'errorNumber': errorNo,
116                        'fileUrl': fileUrl.replace ('"', '\\"'),
117                        'fileName': fileName.replace ( '"', '\\"' ) ,
118                        'customMsg': customMsg.replace ( '"', '\\"' ),
119                        }
Note: See TracBrowser for help on using the repository browser.