"Fossies" - the Fresh Open Source Software Archive

Member "email-reminder-0.8.1/EmailReminder/Utils.py" (19 Sep 2020, 1939 Bytes) of package /linux/privat/email-reminder-0.8.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "Utils.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 0.8.0_vs_0.8.1.

    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 Affero 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 Affero General Public License for more details.
   14 #
   15 # You should have received a copy of the GNU Affero 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)