Debian Codegraph @

EmailReminder/Utils.py

raw symbols SCIP
1 # This file is part of Email-Reminder.
2 #
3 # Copyright (C) 2020 by Francois Marier
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18 import re
19
20 EMAIL_REGEX = re.compile(r"[^@]+@[^@]+\.[^@]+")
21
22
23 def readXMLValue(parent, name):
24 element = None
25 for candidate in parent.getElementsByTagName(name):
26 element = candidate
27 if candidate.parentNode == parent:
28 break # found the right node
29 element = None # keep looking
30
31 if not element:
32 return None
33 if not element.firstChild:
34 return None
35 return element.firstChild.nodeValue
36
37
38 def writeXMLValue(document, parent, name, value):
39 element = None
40 for candidate in parent.getElementsByTagName(name):
41 element = candidate
42 if candidate.parentNode == parent:
43 break # found the right node
44 element = None # keep looking
45
46 if not value:
47 if element:
48 parent.removeChild(element)
49 return
50
51 if not element:
52 element = document.createElement(name)
53 element.appendChild(
54 document.createTextNode(str(value)))
55 parent.appendChild(element)
56 return
57
58 if not element.hasChildNodes():
59 element.appendChild(
60 document.createTextNode(str(value)))
61 return
62
63 element.firstChild.nodeValue = str(value)