예제 #1
0
    def test_item_with_common_elements(self):
        item = (
            <rss.item>
                <rss.title>Item Title</rss.title>
                <rss.description>
                    {html.rawhtml('<![CDATA[ ')}
                    This is a really interesting description
                    {html.rawhtml(']]>')}
                </rss.description>
                <rss.link>https://www.dropbox.com/somewhere</rss.link>
            </rss.item>
        )

        expected = """
<item>
    <title>Item Title</title>
    <description><![CDATA[  This is a really interesting description ]]></description>
    <link>https://www.dropbox.com/somewhere</link>
</item>
"""

        expected = u''.join(l.strip() for l in expected.splitlines())
        self.assertEqual(item.to_string(), expected)
예제 #2
0
    def test_item_with_common_elements(self):
        item = (
            <rss.item>
                <rss.title>Item Title</rss.title>
                <rss.description>
                    {html.rawhtml('<![CDATA[ ')}
                    This is a really interesting description
                    {html.rawhtml(']]>')}
                </rss.description>
                <rss.link>https://www.dropbox.com/somewhere</rss.link>
            </rss.item>
        )

        expected = """
<item>
    <title>Item Title</title>
    <description><![CDATA[  This is a really interesting description ]]></description>
    <link>https://www.dropbox.com/somewhere</link>
</item>
"""

        expected = u''.join(l.strip() for l in expected.splitlines())
        self.assertEqual(item.to_string(), expected)
예제 #3
0
        def asset_fragment(self):
            fragment = super().asset_fragment()
            context = cve.RequestContext.get()

            if context and 'user' in context and context.user:
                user_serialization = cv.serialize_json(cv.dictize(context.user))
            else:
                user_serialization = 'null'
            
            fragment.append(
                <script type="text/javascript">
                    { html.rawhtml(''.join((
                        'window.user = '******';'
                    ))) }
                </script>
            )
            return fragment
예제 #4
0
    def test_rss_document(self):
        dt = datetime.datetime(2013, 12, 17, 23, 54, 14)
        dt2 = datetime.datetime(2013, 12, 18, 11, 54, 14)
        doc = (
            <frag>
                <rss.rss_decl_standalone />
                <rss.rss version="2.0">
                    <rss.channel>
                        <rss.title>A Title</rss.title>
                        <rss.link>https://www.dropbox.com</rss.link>
                        <rss.description>A detailed description</rss.description>
                        <rss.ttl>60</rss.ttl>
                        <rss.language>en-us</rss.language>
                        <rss.lastBuildDate date="{dt}" />
                        <rss.item>
                            <rss.title>Item Title</rss.title>
                            <rss.description>
                                {html.rawhtml('<![CDATA[ ')}
                                This is a really interesting description
                                {html.rawhtml(']]>')}
                            </rss.description>
                            <rss.link>https://www.dropbox.com/somewhere</rss.link>
                            <rss.pubDate date="{dt}" />
                            <rss.guid is-perma-link="{False}">123456789</rss.guid>
                        </rss.item>
                        <rss.item>
                            <rss.title>Another Item</rss.title>
                            <rss.description>
                                {html.rawhtml('<![CDATA[ ')}
                                This is another really interesting description
                                {html.rawhtml(']]>')}
                            </rss.description>
                            <rss.link>https://www.dropbox.com/nowhere</rss.link>
                            <rss.pubDate date="{dt2}" />
                            <rss.guid is-perma-link="{False}">ABCDEFGHIJ</rss.guid>
                        </rss.item>
                    </rss.channel>
                </rss.rss>
            </frag>
        )

        expected = """
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0">
    <channel>
        <title>A Title</title>
        <link>https://www.dropbox.com</link>
        <description>A detailed description</description>
        <ttl>60</ttl>
        <language>en-us</language>
        <lastBuildDate>Tue, 17 Dec 2013 23:54:14 GMT</lastBuildDate>
        <item>
            <title>Item Title</title>
            <description><![CDATA[  This is a really interesting description ]]></description>
            <link>https://www.dropbox.com/somewhere</link>
            <pubDate>Tue, 17 Dec 2013 23:54:14 GMT</pubDate>
            <guid isPermaLink="false">123456789</guid>
        </item>
        <item>
            <title>Another Item</title>
            <description><![CDATA[  This is another really interesting description ]]></description>
            <link>https://www.dropbox.com/nowhere</link>
            <pubDate>Wed, 18 Dec 2013 11:54:14 GMT</pubDate>
            <guid isPermaLink="false">ABCDEFGHIJ</guid>
        </item>
    </channel>
</rss>
"""

        expected = ''.join(l.strip() for l in expected.splitlines())

        self.assertEqual(doc.to_string(), expected)
예제 #5
0
    def test_rss_document(self):
        dt = datetime.datetime(2013, 12, 17, 23, 54, 14)
        dt2 = datetime.datetime(2013, 12, 18, 11, 54, 14)
        doc = (
            <frag>
                <rss.rss_decl_standalone />
                <rss.rss version="2.0">
                    <rss.channel>
                        <rss.title>A Title</rss.title>
                        <rss.link>https://www.dropbox.com</rss.link>
                        <rss.description>A detailed description</rss.description>
                        <rss.ttl>60</rss.ttl>
                        <rss.language>en-us</rss.language>
                        <rss.lastBuildDate date="{dt}" />
                        <rss.item>
                            <rss.title>Item Title</rss.title>
                            <rss.description>
                                {html.rawhtml('<![CDATA[ ')}
                                This is a really interesting description
                                {html.rawhtml(']]>')}
                            </rss.description>
                            <rss.link>https://www.dropbox.com/somewhere</rss.link>
                            <rss.pubDate date="{dt}" />
                            <rss.guid is-perma-link="{False}">123456789</rss.guid>
                        </rss.item>
                        <rss.item>
                            <rss.title>Another Item</rss.title>
                            <rss.description>
                                {html.rawhtml('<![CDATA[ ')}
                                This is another really interesting description
                                {html.rawhtml(']]>')}
                            </rss.description>
                            <rss.link>https://www.dropbox.com/nowhere</rss.link>
                            <rss.pubDate date="{dt2}" />
                            <rss.guid is-perma-link="{False}">ABCDEFGHIJ</rss.guid>
                        </rss.item>
                    </rss.channel>
                </rss.rss>
            </frag>
        )

        expected = """
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0">
    <channel>
        <title>A Title</title>
        <link>https://www.dropbox.com</link>
        <description>A detailed description</description>
        <ttl>60</ttl>
        <language>en-us</language>
        <lastBuildDate>Tue, 17 Dec 2013 23:54:14 GMT</lastBuildDate>
        <item>
            <title>Item Title</title>
            <description><![CDATA[  This is a really interesting description ]]></description>
            <link>https://www.dropbox.com/somewhere</link>
            <pubDate>Tue, 17 Dec 2013 23:54:14 GMT</pubDate>
            <guid isPermaLink="false">123456789</guid>
        </item>
        <item>
            <title>Another Item</title>
            <description><![CDATA[  This is another really interesting description ]]></description>
            <link>https://www.dropbox.com/nowhere</link>
            <pubDate>Wed, 18 Dec 2013 11:54:14 GMT</pubDate>
            <guid isPermaLink="false">ABCDEFGHIJ</guid>
        </item>
    </channel>
</rss>
"""

        expected = ''.join(l.strip() for l in expected.splitlines())

        self.assertEqual(doc.to_string(), expected)
예제 #6
0
 def test_escaping(self):
     self.assertEqual(<div class="&">&{'&'}</div>.to_string(), '<div class="&amp;">&&amp;</div>')
     self.assertEqual(<div>{html.rawhtml('&')}</div>.to_string(), '<div>&</div>')
예제 #7
0
def compile(filename, mainContents, title=None, stylesheet=None, scripts=[]):
  gaScript1 = <script src="https://www.googletagmanager.com/gtag/js?id=UA-123337994-2"></script>
  gaScript2 = <script>{html.rawhtml("""window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-123337994-2');""")}</script>
  
  gaScript1.set_attr("async", "") # async is a Python keyword, so we have to set this attribute manually
  
  if stylesheet == None:
    stylesheetLink = None
  else:
    stylesheetLink = <link rel="stylesheet" href="{stylesheet}" />
  
  scriptElement = <frag></frag>
  for script in scripts:
    scriptElement.append(<script src="{script}"></script>)
  
  doc = (
    <html lang="en">
      <head>
        <meta charset="utf-8" />
        {gaScript1}
        {gaScript2}
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>
          {title + " | " if title != None else None}Alicia Torres and William Hoza's Wedding Website
        </title>
        <link href="https://fonts.googleapis.com/css?family=PT+Sans|Quicksand:300,400&display=swap" rel="stylesheet" />
        <link rel="stylesheet" href="/assets/index4.css" />
        {stylesheetLink}
      </head>
      <body>
        <div id="flow">
          <header>
            <div id="header-event-basics">
              <time datetime="2019-11-08" style="margin-right:20px;">November 8, 2019</time>
              Austin, TX
              <span style="float:right;">
                &num;cavemanandwife2019
              </span>
            </div>
            <div id="h1-line">
              <h1>
                ALICIA &amp; WILLIAM
              </h1>
              <button id="nav-show-button" onclick="showNav();">Menu</button>
            </div>
            <nav>
              <div><button id="nav-hide-button" onclick="hideNav();">Hide</button></div>
              <div><a href="/">HOME</a></div>
              <div><a href="/schedule/">SCHEDULE</a></div>
              <div><a href="/rsvp/">RSVP</a></div>
              <div><a href="/travel/">TRAVEL</a></div>
              <div><a href="/wedding-party/">WEDDING PARTY</a></div>
              <div><a href="/photos/">PHOTOS</a></div>
              <div><a href="/our-catholic-wedding/">OUR CATHOLIC WEDDING</a></div>
              <div><a href="/places-of-interest/">PLACES OF INTEREST</a></div>
              <div><a href="https://www.zola.com/registry/alicia-william">REGISTRY</a></div>
            </nav>
          </header>
          <main>
            {mainContents}
          </main>
        </div>
        
        {scriptElement}
        <script src="/assets/index.js"></script>
      </body>
    </html>
  )
  
  file = open(filename, "w", encoding="utf-8")
  file.write("<!DOCTYPE html>" + str(doc))
예제 #8
0
def test_escaping():
    assert str(<div class="&">&{'&'}</div>) == '<div class="&amp;">&&amp;</div>'
    assert str(<div>{html.rawhtml('&')}</div>) == '<div>&</div>'