Ejemplo n.º 1
0
 def write_titles(self, file, tag, languages, per_language_titles, indent):
     if languages and per_language_titles:
         for lang in languages:
             title = per_language_titles.get(lang, '')
             title_xml = '<%s xml:lang="%s">%s</%s>\n' % (
                 tag, lang, xml_escape(title), tag)
             file.write(indent + title_xml.encode('utf-8'))
Ejemplo n.º 2
0
 def write_titles(self, file, tag, languages, per_language_titles, indent):
     if languages and per_language_titles:
         for lang in languages:
             title = per_language_titles.get(lang, '')
             title_xml = '<%s xml:lang="%s">%s</%s>\n' % (
                 tag, lang, xml_escape(title), tag)
             file.write(indent + title_xml.encode('utf-8'))
Ejemplo n.º 3
0
 def write_note_feed(self, file, notes, url, title, subtitle, updated):
     """Takes a list of notes and writes a PFIF Atom feed to a file."""
     file.write('<?xml version="1.0" encoding="UTF-8"?>\n')
     file.write('<feed xmlns="http://www.w3.org/2005/Atom"\n')
     file.write('      xmlns:pfif="%s">\n' % self.pfif_version.ns)
     write_element(file, 'id', url, '  ')
     write_element(file, 'title', title, '  ')
     write_element(file, 'subtitle', subtitle, '  ')
     write_element(file, 'updated', format_utc_datetime(updated), '  ')
     file.write('  <link rel="self">%s</link>\n' % xml_escape(url))
     for note in notes:
         self.write_note_entry(file, note, '  ')
     file.write('</feed>\n')
Ejemplo n.º 4
0
 def write_note_feed(self, file, notes, url, title, subtitle, updated):
     """Takes a list of notes and writes a PFIF Atom feed to a file."""
     file.write('<?xml version="1.0" encoding="UTF-8"?>\n')
     file.write('<feed xmlns="http://www.w3.org/2005/Atom"\n')
     file.write('      xmlns:pfif="%s">\n' % self.pfif_version.ns)
     write_element(file, 'id', url, '  ')
     write_element(file, 'title', title, '  ')
     write_element(file, 'subtitle', subtitle, '  ')
     write_element(file, 'updated', format_utc_datetime(updated), '  ')
     file.write('  <link rel="self">%s</link>\n' % xml_escape(url))
     for note in notes:
         self.write_note_entry(file, note, '  ')
     file.write('</feed>\n')
Ejemplo n.º 5
0
 def write_person_feed(self, file, persons, get_notes_for_person,
                       url, title, subtitle, updated):
   """Takes a list of person records and a function that gets the list of note
   records for each person, and writes a PFIF Atom feed to the given file."""
   file.write('<?xml version="1.0" encoding="UTF-8"?>\n')
   file.write('<feed xmlns="http://www.w3.org/2005/Atom"\n')
   file.write('      xmlns:pfif="%s">\n' % self.pfif_version.ns)
   write_element(file, 'id', url, '  ')
   write_element(file, 'title', title, '  ')
   write_element(file, 'subtitle', subtitle, '  ')
   write_element(file, 'updated', format_utc_datetime(updated), '  ')
   file.write('  <link rel="self">%s</link>\n' % xml_escape(url))
   for person in persons:
     self.write_person_entry(
         file, person, get_notes_for_person(person), title, '  ')
   file.write('</feed>\n')
Ejemplo n.º 6
0
 def write_person_feed(self, file, persons, get_notes_for_person, url,
                       title, subtitle, updated):
     """Takes a list of person records and a function that gets the list
     of note records for each person, and writes a PFIF Atom feed to the
     given file."""
     file.write('<?xml version="1.0" encoding="UTF-8"?>\n')
     file.write('<feed xmlns="http://www.w3.org/2005/Atom"\n')
     file.write('      xmlns:pfif="%s">\n' % self.pfif_version.ns)
     write_element(file, 'id', url, '  ')
     write_element(file, 'title', title, '  ')
     write_element(file, 'subtitle', subtitle, '  ')
     write_element(file, 'updated', format_utc_datetime(updated), '  ')
     file.write('  <link rel="self">%s</link>\n' % xml_escape(url))
     for person in persons:
         self.write_person_entry(file, person, get_notes_for_person(person),
                                 title, '  ')
     file.write('</feed>\n')
Ejemplo n.º 7
0
def write_element(file, tag, contents, indent=''):
    """Writes a single XML element with the given contents, if non-empty."""
    if contents:
        file.write(indent + '<%s>%s</%s>\n' %
                   (tag, xml_escape(contents).encode('utf-8'), tag))
Ejemplo n.º 8
0
def write_element(file, tag, contents, indent=''):
    """Writes a single XML element with the given contents, if non-empty."""
    if contents:
        file.write(indent + '<%s>%s</%s>\n' %
                   (tag, xml_escape(contents).encode('utf-8'), tag))