Mercurial > libervia-web
comparison src/browser/nativedom.py @ 449:981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
- browser_side --> src/browser
- public --> src/browser_side/public
- libervia.py --> src/browser/libervia_main.py
- libervia_server --> src/server
- libervia_server/libervia.sh --> src/libervia.sh
- twisted --> src/twisted
- new module src/common
- split constants.py in 3 files:
- src/common/constants.py
- src/browser/constants.py
- src/server/constants.py
- output --> html (generated by pyjsbuild during the installation)
- new option/parameter "data_dir" (-d) to indicates the directory containing html and server_css
- setup.py installs libervia to the following paths:
- src/common --> <LIB>/libervia/common
- src/server --> <LIB>/libervia/server
- src/twisted --> <LIB>/twisted
- html --> <SHARE>/libervia/html
- server_side --> <SHARE>libervia/server_side
- LIBERVIA_INSTALL environment variable takes 2 new options with prompt confirmation:
- clean: remove previous installation directories
- purge: remove building and previous installation directories
You may need to update your sat.conf and/or launching script to update the following options/parameters:
- ssl_certificate
- data_dir
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 20 May 2014 06:41:16 +0200 |
parents | browser_side/nativedom.py@ce5b33f499c5 |
children | 1a0cec9b0f1e |
comparison
equal
deleted
inserted
replaced
448:14c35f7f1ef5 | 449:981ed669d3b3 |
---|---|
1 #!/usr/bin/python | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # Libervia: a Salut à Toi frontend | |
5 # Copyright (C) 2011, 2012, 2013, 2014 Jérôme Poisson <goffi@goffi.org> | |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 """ | |
21 This class provide basic DOM parsing based on native javascript parser | |
22 __init__ code comes from Tim Down at http://stackoverflow.com/a/8412989 | |
23 """ | |
24 | |
25 from __pyjamas__ import JS | |
26 | |
27 | |
28 class Node(): | |
29 | |
30 def __init__(self, js_node): | |
31 self._node = js_node | |
32 | |
33 def _jsNodesList2List(self, js_nodes_list): | |
34 ret=[] | |
35 for i in range(len(js_nodes_list)): | |
36 #ret.append(Element(js_nodes_list.item(i))) | |
37 ret.append(self.__class__(js_nodes_list.item(i))) # XXX: Ugly, but used to word around a Pyjamas's bug | |
38 return ret | |
39 | |
40 @property | |
41 def nodeName(self): | |
42 return self._node.nodeName | |
43 | |
44 @property | |
45 def wholeText(self): | |
46 return self._node.wholeText | |
47 | |
48 @property | |
49 def childNodes(self): | |
50 return self._jsNodesList2List(self._node.childNodes) | |
51 | |
52 def getAttribute(self, attr): | |
53 return self._node.getAttribute(attr) | |
54 | |
55 def setAttribute(self, attr, value): | |
56 return self._node.setAttribute(attr, value) | |
57 | |
58 def hasAttribute(self, attr): | |
59 return self._node.hasAttribute(attr) | |
60 | |
61 def toxml(self): | |
62 return JS("""this._node.outerHTML || new XMLSerializer().serializeToString(this._node);""") | |
63 | |
64 | |
65 class Element(Node): | |
66 | |
67 def __init__(self, js_node): | |
68 Node.__init__(self, js_node) | |
69 | |
70 def getElementsByTagName(self, tagName): | |
71 return self._jsNodesList2List(self._node.getElementsByTagName(tagName)) | |
72 | |
73 | |
74 class Document(Node): | |
75 | |
76 def __init__(self, js_document): | |
77 Node.__init__(self, js_document) | |
78 | |
79 @property | |
80 def documentElement(self): | |
81 return Element(self._node.documentElement) | |
82 | |
83 | |
84 class NativeDOM: | |
85 | |
86 def __init__(self): | |
87 JS(""" | |
88 | |
89 if (typeof window.DOMParser != "undefined") { | |
90 this.parseXml = function(xmlStr) { | |
91 return ( new window.DOMParser() ).parseFromString(xmlStr, "text/xml"); | |
92 }; | |
93 } else if (typeof window.ActiveXObject != "undefined" && | |
94 new window.ActiveXObject("Microsoft.XMLDOM")) { | |
95 this.parseXml = function(xmlStr) { | |
96 var xmlDoc = new window.ActiveXObject("Microsoft.XMLDOM"); | |
97 xmlDoc.async = "false"; | |
98 xmlDoc.loadXML(xmlStr); | |
99 return xmlDoc; | |
100 }; | |
101 } else { | |
102 throw new Error("No XML parser found"); | |
103 } | |
104 """) | |
105 | |
106 def parseString(self, xml): | |
107 return Document(self.parseXml(xml)) | |
108 |