def test_xmlheader():
    assert xml.XML().bytes(
        encoding="utf-8") == b'<?xml version="1.0" encoding="utf-8"?>'
    assert xml.XML().bytes(
        encoding="latin-1") == b'<?xml version="1.0" encoding="latin-1"?>'
    assert html.div(xml.XML()).bytes(
        encoding="latin-1"
    ) == b'<div><?xml version="1.0" encoding="latin-1"?></div>'
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
	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
Exemplo n.º 4
0
def test_pickle():
	e = xsc.Frag(
		xml.XML(),
		html.DocTypeXHTML10transitional(),
		xsc.Comment("foo"),
		html.html(xml.Attrs(lang="de"), lang="de"),
		php.expression("$foo"),
		chars.nbsp(),
		abbr.xml(),
	)
	e.append(e[3])
	e2 = pickle.loads(pickle.dumps(e, 2))
	assert e == e2
	assert e2[3] is e2[-1]
Exemplo n.º 5
0
def createfrag():
    return xsc.Frag(
        xml.XML(),
        html.DocTypeHTML401transitional(), xsc.Comment("gurk"), "hurz",
        specials.tab(), abbr.xist(), None, True, False, 1, 2.0, "3", "4",
        (5, 6), [7, 8], html.div(align="left"),
        url.URL("http://www.python.org/"),
        html.span(1,
                  2,
                  class_="gurk",
                  id=(1, 2, (3, 4)),
                  lang=(True, False, url.URL("http://www.python.org/"),
                        html.abbr(xml.XML(),
                                  "hurz",
                                  specials.tab(),
                                  abbr.xist(),
                                  None,
                                  1,
                                  2.0,
                                  "3",
                                  "4", (5, 6), [7, 8],
                                  html.span("gurk"),
                                  title="hurz"))))
Exemplo n.º 6
0
def createattrs():
    return html.span.Attrs(lang=(True, False,
                                 url.URL("http://www.python.org/"),
                                 html.abbr(xml.XML(),
                                           "hurz",
                                           specials.tab(),
                                           abbr.xist(),
                                           None,
                                           1,
                                           2.0,
                                           "3",
                                           "4", (5, 6), [7, 8],
                                           html.span("gurk"),
                                           title="hurz")))
Exemplo n.º 7
0
def dump_comments(cert: model.Certificate,
                  comments: typing.Iterable[model.Comment]):
    title = "{.name} / {.isin}".format(cert, cert)
    items = []
    for comment in comments:
        items.append(
            rss20.item(
                rss20.title("Kommentar: " + title),
                rss20.author(comment.author),
                rss20.pubDate(
                    time.strftime("%a, %d %b %Y %T %z", comment.pubDate)),
                rss20.guid(comment.guid), rss20.link(comment.link),
                rss20.description(comment.description)))
    return xsc.Frag(xml.XML(),
                    rss20.rss(rss20.channel(rss20.title(title),
                                            *items))).string('utf-8')
Exemplo n.º 8
0
def createelement():
    return html.span(1,
                     2,
                     class_="gurk",
                     id=(1, 2, (3, 4)),
                     lang=(True, False, url.URL("http://www.python.org/"),
                           html.abbr(xml.XML(),
                                     "hurz",
                                     specials.tab(),
                                     abbr.xist(),
                                     None,
                                     1,
                                     2.0,
                                     "3",
                                     "4", (5, 6), [7, 8],
                                     html.span("gurk"),
                                     title="hurz")))
Exemplo n.º 9
0
def dump_trades(cert: model.Certificate, trades: typing.Iterable[model.Trade]):
    title = "{.name} / {.isin}".format(cert, cert)
    items = []
    for trade in trades:
        trade_title = trade.typ + " " + str(trade.volume) + "@" + str(
            trade.quote) + " " + trade.share_name
        description = trade.typ + " " + str(trade.volume) + "@" + str(
            trade.quote) + " " + trade.share_name
        description += " ( " + trade.share_isin + " ) "

        items.append(
            rss20.item(
                rss20.title(trade_title), rss20.author(cert.name),
                rss20.pubDate(trade.timestamp.strftime("%a, %d %b %Y %T %z")),
                rss20.guid(trade.timestamp.strftime("%a, %d %b %Y %T %z")),
                rss20.link(cert.make_url()), rss20.description(description)))
    return xsc.Frag(xml.XML(),
                    rss20.rss(rss20.channel(rss20.title(title),
                                            *items))).string('utf-8')
Exemplo n.º 10
0
    def index(self):
        def isimg(name):
            if name.endswith(".gif") or name.endswith(".jpg") or name.endswith(
                    ".png"):
                return os.path.isfile(os.path.join(self.directory, name))
            return False

        names = [name for name in os.listdir(self.directory) if isimg(name)]
        names.sort()

        collect = xsc.Frag()
        i = 0

        with xsc.build():
            with xsc.Frag() as e:
                +xml.XML()
                +html.DocTypeXHTML10transitional()
                with html.html():
                    with html.head():
                        +meta.contenttype()
                        +html.title("All images from ", doc.z(self.directory))
                        +html.link(rel="stylesheet",
                                   type="text/css",
                                   href="images.css")
                    with html.body():
                        with htmlspecials.plaintable():
                            for name in names:
                                collect.append(
                                    html.td(
                                        htmlspecials.autoimg(src=("/images/",
                                                                  name)),
                                        html.br(),
                                        name,
                                        align="center"))
                                i += 1
                                if i == cols:
                                    +html.tr(collect)
                                    collect = xsc.Frag()
                                    i = 0
                            if collect:
                                +html.tr(collect)

        return e.conv().bytes()
Exemplo n.º 11
0
	def xmldecl(self, data):
		node = xml.XML(version=data["version"], encoding=data["encoding"], standalone=data["standalone"])
		if self.loc:
			node.startloc = xsc.Location(self._url, *self._position)
		return ("xmldeclnode", node)
 def convert(self, converter):
     e = xsc.Frag(xml.XML(), "\n", DocType(), "\n",
                  struts_config(self.content))
     return e.convert(converter)