def test_applystylesheets_media():
    # Check that media="screen" picks up the media stylesheet
    with xsc.build():
        with html.html() as e:
            with html.head():
                +html.style("p {color: red;}", type="text/css", media="screen")
            with html.body():
                +html.p("gurk")

    css.applystylesheets(e, media="screen")

    assert str(e.walknodes(html.p)[0].attrs.style) == "color: red;"

    # Check that media="screen" doesn't pick up the print stylesheet
    with xsc.build():
        with html.html() as e:
            with html.head():
                +html.style("p {color: red;}", type="text/css", media="screen")
            with html.body():
                +html.p("gurk")

    css.applystylesheets(e, media="print")

    assert str(e.walknodes(html.p)[0].attrs.style) == ""

    # Check that @media rules are treated properly
    with xsc.build():
        with html.html() as e:
            with html.head():
                +html.style("@media screen { p {color: red;}}",
                            type="text/css")
            with html.body():
                +html.p("gurk")

    css.applystylesheets(e, media="screen")

    assert str(e.walknodes(html.p)[0].attrs.style) == "color: red;"

    with xsc.build():
        with html.html() as e:
            with html.head():
                +html.style("@media screen { p {color: red;}}",
                            type="text/css")
            with html.body():
                +html.p("gurk")

    css.applystylesheets(e, media="print")

    assert str(e.walknodes(html.p)[0].attrs.style) == ""
Ejemplo n.º 2
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()
Ejemplo n.º 3
0
	def convert(self, converter):
		e = xsc.Frag(
			xml.XML(), "\n",
			html.DocTypeXHTML10transitional(), "\n",
			html.html(
				html.head(
					meta.contenttype(),
					html.title(
						"Python code coverage",
						ul4.if_("filename"),
							": ", ul4.printx("filename"),
						ul4.else_(),
							" (", ul4.print_("format(timestamp, '%Y-%m-%d')"), ")",
						ul4.end("if"),
					),
					meta.stylesheet(href="/coverage.css"),
					meta.stylesheet(href="/coverage_sortfilelist.css"),
					htmlspecials.javascript(src="/coverage.js"),
				),
				html.body(
					html.div(
						html.div(
							html.a(
								htmlspecials.autoimg(src="http://www.python.org/images/python-logo.gif", alt="Python", border=0),
								href="http://www.python.org/",
							),
							class_="logo",
						),
						html.div(
							ul4.for_("(i, item) in enumerate(crumbs)"),
								html.span(
									html.span(
										ul4.if_("i"),
											">",
										ul4.else_(),
											"\xbb",
										ul4.end("if"),
										class_="bullet",
									),
									ul4.if_("item.href"),
										html.a(ul4.printx("item.title"), href=ul4.printx("item.href")),
									ul4.else_(),
										html.span(ul4.printx("item.title"), class_="here"),
									ul4.end("if"),
								ul4.end("for"),
								class_="crumb",
							),
							class_="crumbs",
						),
						class_="header",
					),
					html.div(
						self.content,
						class_="content",
					),
					onload=ul4.attr_if(ul4.printx("onload"), cond="onload"),
				),
			),
		)
		return e.convert(converter)
def test_applystylesheets_media():
	# Check that media="screen" picks up the media stylesheet
	with xsc.build():
		with html.html() as e:
			with html.head():
				+html.style("p {color: red;}", type="text/css", media="screen")
			with html.body():
				+html.p("gurk")

	css.applystylesheets(e, media="screen")

	assert str(e.walknodes(html.p)[0].attrs.style) == "color: red;"

	# Check that media="screen" doesn't pick up the print stylesheet
	with xsc.build():
		with html.html() as e:
			with html.head():
				+html.style("p {color: red;}", type="text/css", media="screen")
			with html.body():
				+html.p("gurk")

	css.applystylesheets(e, media="print")

	assert str(e.walknodes(html.p)[0].attrs.style) == ""

	# Check that @media rules are treated properly
	with xsc.build():
		with html.html() as e:
			with html.head():
				+html.style("@media screen { p {color: red;}}", type="text/css")
			with html.body():
				+html.p("gurk")

	css.applystylesheets(e, media="screen")

	assert str(e.walknodes(html.p)[0].attrs.style) == "color: red;"

	with xsc.build():
		with html.html() as e:
			with html.head():
				+html.style("@media screen { p {color: red;}}", type="text/css")
			with html.body():
				+html.p("gurk")

	css.applystylesheets(e, media="print")

	assert str(e.walknodes(html.p)[0].attrs.style) == ""
	def makenode():
		with xsc.build():
			with html.html() as e:
				with html.head():
					+html.style("p {color: red;}", type="text/css")
					+html.style("p {color: blue;}", type="text/css", title="blue")
				with html.body():
					+html.p("gurk")
		return e
 def makenode():
     with xsc.build():
         with html.html() as e:
             with html.head():
                 +html.style("p {color: red;}", type="text/css")
                 +html.style(
                     "p {color: blue;}", type="text/css", title="blue")
             with html.body():
                 +html.p("gurk")
     return e
def test_applystylesheets1():
	with xsc.build():
		with html.html() as e:
			with html.head():
				+html.style("p {color: red;}", type="text/css")
			with html.body():
				+html.p("gurk")

	css.applystylesheets(e)

	assert str(e.walknodes(html.p)[0].attrs.style) == "color: red;"
	assert list(e.walknodes(html.style)) == []
def test_applystylesheets1():
    with xsc.build():
        with html.html() as e:
            with html.head():
                +html.style("p {color: red;}", type="text/css")
            with html.body():
                +html.p("gurk")

    css.applystylesheets(e)

    assert str(e.walknodes(html.p)[0].attrs.style) == "color: red;"
    assert list(e.walknodes(html.style)) == []
def test_applystylesheets4():
	with xsc.build():
		with html.html() as e:
			with html.head():
				+html.style("#id42 {color: red;}", type="text/css")
			with html.body():
				+html.p("gurk", id="id42", style="color: blue;")

	css.applystylesheets(e)

	# style attribute wins
	assert str(e.walknodes(html.p)[0].attrs.style) == "color: blue;"
	assert list(e.walknodes(html.style)) == []
Ejemplo n.º 10
0
def test_applystylesheets4():
    with xsc.build():
        with html.html() as e:
            with html.head():
                +html.style("#id42 {color: red;}", type="text/css")
            with html.body():
                +html.p("gurk", id="id42", style="color: blue;")

    css.applystylesheets(e)

    # style attribute wins
    assert str(e.walknodes(html.p)[0].attrs.style) == "color: blue;"
    assert list(e.walknodes(html.style)) == []
Ejemplo n.º 11
0
def test_applystylesheets5():
    with xsc.build():
        with html.html() as e:
            with html.head():
                +html.style("p#id42 {color: red;}", type="text/css")
            with html.body():
                +html.p("gurk", id="id42", style="color: blue;")

    css.applystylesheets(e)

    # stylesheet always wins (at least in CSS 2.1 and 3)
    assert str(e.walknodes(html.p)[0].attrs.style) == "color: blue;"
    assert list(e.walknodes(html.style)) == []
def test_applystylesheets5():
	with xsc.build():
		with html.html() as e:
			with html.head():
				+html.style("p#id42 {color: red;}", type="text/css")
			with html.body():
				+html.p("gurk", id="id42", style="color: blue;")

	css.applystylesheets(e)

	# stylesheet always wins (at least in CSS 2.1 and 3)
	assert str(e.walknodes(html.p)[0].attrs.style) == "color: blue;"
	assert list(e.walknodes(html.style)) == []
Ejemplo n.º 13
0
def xsc2txt(instream, outstream, title, width):
    e = parse.tree(parse.Stream(instream), parse.SGMLOP(), parse.NS(doc),
                   parse.Node(pool=xsc.docpool()))

    if title is None:
        title = xsc.Null
    else:
        title = doc.title(title)
    e = html.html(html.body(doc.section(title, e)))

    e = e.conv()

    outstream.write(html.astext(e, width=width))
Ejemplo n.º 14
0
def xsc2txt(instream, outstream, title, width):
	e = parse.tree(parse.Stream(instream), parse.SGMLOP(), parse.NS(doc), parse.Node(pool=xsc.docpool()))

	if title is None:
		title = xsc.Null
	else:
		title = doc.title(title)
	e = html.html(
		html.body(
			doc.section(title, e)
		)
	)

	e = e.conv()

	outstream.write(html.astext(e, width=width))
Ejemplo n.º 15
0
	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)
Ejemplo n.º 16
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()
	def convert(self, converter):
		e = html_.body(self.content, self.attrs)
		return e.convert(converter)
Ejemplo n.º 18
0
 def convert(self, converter):
     e = html_.body(self.content, self.attrs)
     return e.convert(converter)
Ejemplo n.º 19
0
    border: 1px solid #eee;
    background-color: #fafafa;
    padding: 1px 5px 2px 5px;
    overflow: auto;
}
"""

now = datetime.datetime.now()

node = xsc.Frag(
    html.h1(
        "Cronjobs ",
        html.span("(generated at %s)" % now.strftime("%d.%m.%Y %H:%M"),
                  class_="note")))

for host in hosts:
    node.append(html.h2(host.name))
    for (user, crontab) in sorted(host.getcrontabs()):
        node.append(html.h3(user, "@", host.name))
        node.append(html.pre(crontab.decode("latin-1").strip()))

node = xsc.Frag(
    xml.XML10(), "\n",
    html.head(
        meta.contenttype(),
        html.title("Cronjobs"),
        html.style(style, type="text/css"),
    ), html.body(node))

print e.asBytes(encoding="iso-8859-1")
Ejemplo n.º 20
0
    font-size: 11px;
    line-height: 18px;
    border: 1px solid #eee;
    background-color: #fafafa;
    padding: 1px 5px 2px 5px;
    overflow: auto;
}
"""

now = datetime.datetime.now()

node = xsc.Frag(html.h1("Cronjobs ", html.span("(generated at %s)" % now.strftime("%d.%m.%Y %H:%M"), class_="note")))

for host in hosts:
    node.append(html.h2(host.name))
    for (user, crontab) in sorted(host.getcrontabs()):
        node.append(html.h3(user, "@", host.name))
        node.append(html.pre(crontab.decode("latin-1").strip()))

node = xsc.Frag(
    xml.XML10(), "\n",
    html.head(
        meta.contenttype(),
        html.title("Cronjobs"),
        html.style(style, type="text/css"),
    ),
    html.body(node)
)

print e.asBytes(encoding="iso-8859-1")