class media(xsc.Element): xmlns = xmlns model = sims.Elements(ld, dvd) def convert(self, converter): def namekey(node): return str(node[name][0].content) dvds = xsc.Frag(self[dvd]).sorted(key=namekey) lds = xsc.Frag(self[ld]).sorted(key=namekey) with xsc.build(): with xsc.Frag() as e: +xml.XML() +html.DocTypeXHTML10transitional() with html.html(): with html.head(): +meta.contenttype() +html.title("Media") +meta.stylesheet(href="Media.css") with htmlspecials.plainbody(): +html.h1("Media") if lds: +html.h2(len(lds), " LDs") +html.ol(lds) if dvds: +html.h2(len(dvds), " DVDs") +html.ol(dvds) return e.convert(converter)
class quotation(xsc.Element): xmlns = xmlns model = sims.Elements(author, source, note) class Attrs(xsc.Element.Attrs): class date(xsc.TextAttr): pass class id(xsc.IDAttr): pass def convert(self, converter): content = xsc.Frag() authors = xsc.Frag() sources = xsc.Frag() for child in self: if isinstance(child, author): authors.append(child) elif isinstance(child, source): sources.append(child) else: content.append(child) if authors: if sources: footer = html.div(authors, " ", chars.mdash(), " ", sources, class_="source") else: footer = html.div(authors, class_="source") else: if sources: footer = html.div(sources, class_="source") else: footer = None e = html.div(content, footer, class_="quotation") return e.convert(converter)
class dl(list): """ A list in which each entry is marked with a label. """ xmlns = xmlns model = sims.Elements(dt, dd) def convert_docbook(self, converter): e = converter.target.variablelist() collect = converter.target.varlistentry() for child in self.content: collect.append(child) if isinstance(child, dd): e.append(collect) collect = converter.target.varlistentry() if collect: e.append(collect) return e.convert(converter) def convert_html(self, converter): with _stack(converter[self], self): return converter.target.dl(self.content.convert(converter)) def convert_fo(self, converter): context = converter[self] context.lists.append(["dl", 0]) e = self.content.convert(converter) del context.lists[-1] return e
class example(block): """ A formal example. """ xmlns = xmlns model = sims.Elements(h, block) def convert_docbook(self, converter): e = converter.target.example(self.content) return e.convert(converter) def convert_html(self, converter): target = converter.target ts = xsc.Frag() e = xsc.Frag() for child in self: if isinstance(child, h): ts.append(child) else: e.append(child) if ts: e.append(target.div(ts, class_="example-title")) with _stack(converter[self], self): return e.convert(converter) def convert_fo(self, converter): # FIXME: handle title e = xsc.Frag() for child in self.content: if not isinstance(child, h): e.append(child) return e.convert(converter)
class rtc(xsc.Element): """ The :class:`rtc` ("ruby text component") element is the container for :class:`rt` elements. """ xmlns = xmlns model = sims.Elements(rt)
class rbc(xsc.Element): """ The :class:`rbc` (ruby base component) element is the container for :class:`rb` elements. """ xmlns = xmlns model = sims.Elements(rb)
class ruby(xsc.Element): """ The :class:`ruby` element is an inline (or text-level) element that serves as the container for either the :class:`rb`, :class:`rt` and optional :class:`rp` elements or the :class:`rbc` and :class:`rtc` elements. """ xmlns = xmlns model = sims.Elements(rb, rt, rp, rbc, rtc)
class nsName(base): """ Allows any name in a specific namespace. """ xmlns = xmlns model = sims.Elements(except_) class Attrs(base.Attrs): class ns(xsc.URLAttr): pass
class ld(xsc.Element): xmlns = xmlns model = sims.Elements(name, duration, purchase) def convert(self, converter): e = html.li(html.span(self[name], class_="name")) for e2 in self[duration]: e.append(" (", e2, ")") e.append(self[purchase]) return e.convert(converter)
class purchase(xsc.Element): xmlns = xmlns model = sims.Elements(place, date, price) def convert(self, converter): e = html.div(self[place], class_="purchase") for e2 in self[price]: e.append(": ", e2) e.append(" ") for e2 in self[date]: e.append("(", e2, ")") return e.convert(converter)
def test_elements(): with xsc.Pool(): class el11(xsc.Element): xmlname = "el1" xmlns = "ns1" class el12(xsc.Element): xmlname = "el2" xmlns = "ns1" class el21(xsc.Element): xmlname = "el1" xmlns = "ns2" class el22(xsc.Element): xmlname = "el2" xmlns = "ns2" el11.model = sims.Elements(el11, el21) e = el11() e.bytes(validate=True) e = el11("foo") with warnings.catch_warnings(record=True) as w: e.bytes(validate=True) assert len(w) == 1 assert issubclass(w[-1].category, sims.IllegalTextWarning) e = el11(php.php("gurk")) e.bytes(validate=True) e = el11(xsc.Comment("gurk")) e.bytes(validate=True) e = el11(el11()) e.bytes(validate=True) e = el11(el21()) e.bytes(validate=True) e = el11(el12()) with warnings.catch_warnings(record=True) as w: e.bytes(validate=True) assert len(w) == 1 assert issubclass(w[-1].category, sims.WrongElementWarning) e = el11(el22()) with warnings.catch_warnings(record=True) as w: e.bytes(validate=True) assert len(w) == 1 assert issubclass(w[-1].category, sims.WrongElementWarning)
class fodoc(base): xmlns = xmlns model = sims.Elements(block) def convert(self, converter): context = converter[self] e = self.content converter.push(target=sys.modules[__name__]) # our own module e = e.convert(converter) converter.pop() converter.push(target=fo) e = e.convert(converter) converter.pop() e = xsc.Frag( xml.XML(), "\n", fo.root(fo.layout_master_set( fo.simple_page_master( fo.region_body(region_name="xsl-region-body", margin_bottom="3cm"), fo.region_after(region_name="xsl-region-after", extent="2cm"), master_name="default", page_height="29.7cm", page_width="21cm", margin_top="1cm", margin_bottom="1cm", margin_left="2.5cm", margin_right="1cm")), fo.page_sequence(fo.static_content( fo.block(fo.page_number(), border_before_width="0.1pt", border_before_color="#000", border_before_style="solid", padding_before="4pt", text_align="center"), flow_name="xsl-region-after"), fo.flow(e, flow_name="xsl-region-body"), master_reference="default"), font_family=context.font, font_size="10pt", text_align="justify", line_height="normal", language="en", orphans=2, widows=3)) return e
class dvd(xsc.Element): xmlns = xmlns model = sims.Elements(name, rc, duration, purchase) def convert(self, converter): e = html.li(html.span(self[name], class_="name")) durations = xsc.Frag(self[duration]) rcs = xsc.Frag(self[rc]) if len(durations) or len(rcs): e.append(" (") if len(durations): e.append(durations[0]) if len(rcs): e.append("; ") if len(rcs): e.append("RC ", rcs.withsep(", ")) e.append(")") e.append(self[purchase]) return e.convert(converter)
class quotations(xsc.Element): xmlns = xmlns model = sims.Elements(title, editor, description, quotation) def convert(self, converter): with xsc.build(): with xsc.Frag() as e: +html.DocTypeXHTML10transitional() with html.html(): with html.head(): +meta.contenttype() +html.title(self[title][0].content) +meta.stylesheet(href="root:python-quotes.css") +html.body( self[title], self[editor], self[description], self[quotation] ) return e.convert(converter)
class ol(list): """ A list in which each entry is marked with a sequentially incremented label. """ xmlns = xmlns model = sims.Elements(li) def convert_docbook(self, converter): e = converter.target.orderedlist(self.content.convert(converter)) return e.convert(converter) def convert_html(self, converter): with _stack(converter[self], self): return converter.target.ol(self.content.convert(converter)) def convert_fo(self, converter): context = converter[self] context.lists.append(["ol", 0]) e = converter.target.list_block(self.content, line_height="130%") e = e.convert(converter) del context.lists[-1] return e
class ul(list): """ A list in which each entry is marked with a bullet or other dingbat. """ xmlns = xmlns model = sims.Elements(li) def convert_docbook(self, converter): e = converter.target.itemizedlist(self.content.convert(converter)) return e.convert(converter) def convert_html(self, converter): with _stack(converter[self], self): return converter.target.ul(self.content.convert(converter)) def convert_fo(self, converter): context = converter[self] context.lists.append(["ul", 0]) e = converter.target.list_block(self.content, line_height="130%") e = e.convert(converter) del context.lists[-1] return e
author, authors, organization, address, contact, version, revision, status, date, copyright, field, ) PE_structure_model = (topic, sidebar, transition) + PE_section_elements document.model = sims.Elements( *(title, subtitle, decoration, docinfo, transition) + PE_structure_model) title.model = sims.ElementsOrText(*PE_inline_elements) subtitle.model = sims.ElementsOrText(*PE_inline_elements) docinfo.model = sims.Elements(*PE_bibliographic_elements) author.model = sims.ElementsOrText(*PE_inline_elements) authors.model = sims.Elements(author, organization, address, contact) organization.model = sims.ElementsOrText(*PE_inline_elements) address.model = sims.ElementsOrText(*PE_inline_elements) contact.model = sims.ElementsOrText(*PE_inline_elements) version.model = sims.ElementsOrText(*PE_inline_elements) revision.model = sims.ElementsOrText(*PE_inline_elements) status.model = sims.ElementsOrText(*PE_inline_elements) date.model = sims.ElementsOrText(*PE_inline_elements) copyright.model = sims.ElementsOrText(*PE_inline_elements) decoration.model = sims.Elements(header, footer) header.model = sims.Elements(*PE_body_elements)
class webMaster(xsc.Element): """ The email address of the webmaster for the site, the person to contact if there are technical problems with the channel. """ xmlns = xmlns class width(xsc.Element): """ Specifies the width of an :class:`image`. Should be an integer value. """ xmlns = xmlns rss.model = sims.Elements(channel) skipDays.model = sims.Elements(day) skipHours.model = sims.Elements(hour) textinput.model = sims.Elements(link, description, name, title) item.model = sims.Elements(link, description, title) channel.model = sims.Elements(rating, skipHours, description, language, title, docs, image, pubDate, webMaster, item, link, skipDays, lastBuildDate, copyright, managingEditor, textinput) image.model = sims.Elements(width, link, description, title, url, height) copyright.model = \ day.model = \ description.model = \ docs.model = \ height.model = \ hour.model = \ language.model = \ lastBuildDate.model = \ link.model = \
class isPermaLink(xsc.TextAttr): values = ("false", "true") class source(xsc.Element): """ The RSS channel that the item came from. """ xmlns = xmlns class Attrs(xsc.Element.Attrs): class url(xsc.URLAttr): required = True rss.model = sims.Elements(channel) channel.model = sims.Elements(title, link, description, language, copyright, managingEditor, webMaster, pubDate, lastBuildDate, category, generator, docs, cloud, ttl, image, textInput, skipHours, skipDays, item) image.model = sims.Elements(url, title, link, width, height) enclosure.model = \ cloud.model = sims.Empty() ttl.model = sims.NoElements() textInput.model = sims.Elements(title, description, name, link) item.model = sims.Elements(title, link, description, author, category, comments, enclosure, guid, pubDate, source) skipDays.model = sims.Elements(day) skipHours.model = sims.Elements(hour) copyright.model = \ day.model = \
class Attrs(coreattrs): class type(xsc.TextAttr): pass class pre(xsc.Element): """ Preformatted text """ xmlns = xmlns class Attrs(coreattrs): pass head.model = sims.Elements(access, meta) template.model = sims.Elements(do, onevent) do.model = \ onevent.model = sims.Elements(go, prev, noop, refresh) wml.model = sims.Elements(head, card, template) optgroup.model = \ select.model = sims.Elements(optgroup, option) go.model = sims.Elements(postfield, setvar) card.model = sims.Elements(pre, do, timer, onevent, p) prev.model = \ refresh.model = sims.Elements(setvar) tr.model = sims.Elements(td) table.model = sims.Elements(tr) pre.model = sims.ElementsOrText(a, do, b, i, u, br, input, em, strong, anchor, select) anchor.model = sims.ElementsOrText(br, img, go, prev, refresh)
model = sims.NoElements() class Attrs(base.Attrs): class type(xsc.TextAttr): pass class zeroOrMore(base): """ There can be zero or more recurrence of the enclosed pattern. """ xmlns = xmlns # modeltype definitions anyName.model = sims.Elements(except_) attribute.model = sims.ElementsOrText(choice, data, empty, externalRef, grammar, group, interleave, list, mixed, name, notAllowed, nsName, oneOrMore, optional, parentRef, ref, text, value, zeroOrMore) choice.model = sims.Elements(anyName, attribute, choice, data, element_, empty, externalRef, grammar, group, interleave, list, mixed, name, notAllowed, nsName, oneOrMore, optional, parentRef, ref, text, value, zeroOrMore) data.model = sims.Elements(except_, param) define.model = sims.Elements(attribute, choice, data, element_, empty, externalRef, grammar, group, interleave, list, mixed, notAllowed, oneOrMore, optional, parentRef, ref, text, value, zeroOrMore) div.model = sims.Elements(define, div, include, start)
class name(xsc.Element): """ The :class:`name` element's content conveys a human-readable name for the person. """ xmlns = xmlns link.model = \ category.model = sims.Empty() content.model = sims.ElementsOrText(html.div) source.model = sims.ElementsOrText(author, category, contributor, generator, icon, id, link, logo, rights, subtitle, title, updated) feed.model = sims.Elements(author, category, contributor, generator, icon, logo, id, link, rights, subtitle, title, updated, entry) entry.model = sims.Elements(author, category, content, contributor, id, link, published, rights, source, summary, title, updated) contributor.model = \ author.model = sims.Elements(name, uri, email) title.model = \ summary.model = \ subtitle.model = \ rights.model = sims.ElementsOrText(html.div) updated.model = \ published.model = \ logo.model = \ id.model = \ icon.model = \ generator.model = \
class section(block): """ A recursive section. """ xmlns = xmlns model = sims.Elements(h, block) class Attrs(xsc.Element.Attrs): class role(xsc.TextAttr): pass class id(xsc.IDAttr): pass def convert_docbook(self, converter): e = converter.target.section(self.content, role=self.attrs.role, id=self.attrs.id) return e.convert(converter) def convert_html(self, converter): target = converter.target context = converter[self] context.sections[-1] += 1 level = len(context.sections) context.sections.append(0) # for numbering the subsections ts = xsc.Frag() cs = html.div(class_="content") for child in self: if isinstance(child, h): ts.append(child) else: cs.append(child) e = target.div(class_=("section level", level), id=self.attrs.id) if "role" in self.attrs: e.attrs.class_.append(" ", self.attrs.role) #if "id" in self.attrs: # e.append(target.a(name=self.attrs.id, id=self.attrs.id)) hclass = getattr(target, f"h{level}", target.h6) for t in ts: e.append(hclass(t.content)) e.append(cs) with _stack(context, self): # make sure to call the inner convert() before popping the number off of the stack e = e.convert(converter) del context.sections[-1] return e def convert_fo(self, converter): context = converter[self] context.sections[-1] += 1 context.sections.append(0) ts = xsc.Frag() cs = xsc.Frag() props = [ # size, before, after ("30pt", "30pt", "2pt"), ("22pt", "20pt", "2pt"), ("16pt", "15pt", "2pt"), ("12pt", "15pt", "2pt") ] for child in self.content: if isinstance(child, h): ts.append(child.content) else: cs.append(child) p = props[min(len(context.sections) - 1, len(props) - 1)] isref = str(self.attrs.role.convert(converter)) in ("class", "method", "property", "function", "module") number = None if isref: context.indentcount += 1 text_indent = context.dedent() else: if len(context.sections) > 1: number = (".".join(str(s) for s in context.sections[:-1]), ". ") text_indent = None tattrs = fo.block.Attrs(font_size=p[0], color=context.llblue, space_before=p[1], space_after=p[2], text_align="left", font_family=context.hdfont, keep_with_next_within_page="always", text_indent=text_indent) e = fo.block(fo.block(number, ts, tattrs), cs, start_indent=context.indent()) e = e.convert(converter) del context.sections[-1] if isref: context.indentcount -= 1 return e
class License(xsc.Element): xmlns = xmlns model = sims.Elements(permits, requires)
class Work(xsc.Element): xmlns = xmlns model = sims.Elements(license)
class property(xsc.TextAttr): required = True class value(xsc.TextAttr): required = True class small_icon(ElementWithID): xmlname = "small-icon" class struts_config(ElementWithID): xmlname = "struts-config" action_mappings.model = sims.Elements(action) data_sources.model = sims.Elements(data_source) exception.model = \ forward.model = sims.Elements(display_name, description, set_property, icon) global_exceptions.model = sims.Elements(exception) action.model = sims.Elements(exception, description, forward, display_name, set_property, icon) form_beans.model = sims.Elements(form_bean) form_bean.model = sims.Elements(form_property, display_name, description, set_property, icon) global_forwards.model = sims.Elements(forward) struts_config.model = sims.Elements(global_exceptions, controller, message_resources, data_sources, plug_in, action_mappings, form_beans, global_forwards) controller.model = \
class Attrs(IdAttrs): pass class uri(xsc.Element): """ Defines a public URI that uniquely identifies this version of the taglibrary. Leave it empty if it does not apply. """ xmlns = xmlns class Attrs(IdAttrs): pass taglib.model = sims.Elements(info, tag, jspversion, shortname, tlibversion, uri) attribute.model = sims.Elements(rtexprvalue, required, name) tag.model = sims.Elements(tagclass, info, name, bodycontent, attribute, teiclass) bodycontent.model = \ info.model = \ jspversion.model = \ name.model = \ required.model = \ rtexprvalue.model = \ shortname.model = \ tagclass.model = \ teiclass.model = \ tlibversion.model = \ uri.model = sims.NoElements()
dd.model = \ blockquote.model = \ blink.model = \ plaintext.model = \ marquee.model = \ center.model = sims.ElementsOrText(*pe_Flow) p.model = \ h1.model = \ h2.model = \ h3.model = \ h4.model = \ h5.model = \ h6.model = \ dt.model = \ font.model = sims.ElementsOrText(*pe_Inline) ul.model = \ ol.model = \ menu.model = \ dir.model = sims.Elements(li) title.model = \ option.model = \ textarea.model = sims.NoElements() object.model = sims.ElementsOrText(*(pe_block + (form, ) + pe_inline)) dl.model = sims.Elements(dt, dd) html.model = sims.Elements(head, body) select.model = sims.Elements(option) head.model = sims.Elements(title, base, meta, object) pre.model = sims.ElementsOrText(*((a, ) + pe_special_basic + pe_inline_forms)) form.model = sims.ElementsOrText(*(pe_block + pe_inline)) a.model = sims.ElementsOrText(*(pe_special + pe_fontstyle + pe_inline_forms))