Exemplo n.º 1
0
    def testSpecialAttributeDecoding(self):
        '''unmung some xoxo with <a href=' rel= etc in and check result is right'''
        xoxoSample= '''<ol class='xoxo'> 
  <li>
    <dl>
        <dt>text</dt>
        <dd>item 1</dd>
        <dt>url</dt>
        <dd>http://example.com/more.xoxo</dd>
        <dt>title</dt>
        <dd>title of item 1</dd>
        <dt>type</dt>
        <dd>text/xml</dd>
        <dt>rel</dt>
        <dd>help</dd>
    </dl>
  </li>
</ol>'''
        d = xoxo.fromXOXO(xoxoSample)
        smartxoxoSample= '''<ol class='xoxo'> 
  <li><a href="http://example.com/more.xoxo"
         title="title of item 1"
         type="text/xml"
         rel="help">item 1</a> 
<!-- note how the "text" property is simply the contents of the <a> element -->
  </li>
</ol>'''
        d2 = xoxo.fromXOXO(smartxoxoSample)
        self.assertEqual(d,d2)
Exemplo n.º 2
0
    def testSpecialAttributeAndDLDecoding(self):
        '''unmung some xoxo with <a href=' rel= etc in plus a <dl> in the same item and check result is right'''
        xoxoSample= '''<ol class="xoxo"> 
  <li>
    <dl>
        <dt>text</dt>
        <dd>item 1</dd>
        <dt>description</dt>
        <dd> This item represents the main point we're trying to make.</dd>
        <dt>url</dt>
        <dd>http://example.com/more.xoxo</dd>
        <dt>title</dt>
        <dd>title of item 1</dd>
        <dt>type</dt>
        <dd>text/xml</dd>
        <dt>rel</dt>
        <dd>help</dd>
    </dl>
  </li>
</ol>'''
        d = xoxo.fromXOXO(xoxoSample)
        smartxoxoSample= '''<ol class="xoxo"> 
  <li><a href="http://example.com/more.xoxo"
         title="title of item 1"
         type="text/xml"
         rel="help">item 1</a> 
<!-- note how the "text" property is simply the contents of the <a> element -->
      <dl>
        <dt>description</dt>
          <dd> This item represents the main point we're trying to make.</dd>
      </dl>
  </li>
</ol>'''
        d2 = xoxo.fromXOXO(smartxoxoSample)
        self.assertEqual(d,d2)
Exemplo n.º 3
0
 def testAttentionRoundTrip(self):
     '''check nested <a> and <dl> and <a> are preserved'''
     kmattn='''<ol class="xoxo"><li><a href="http://www.boingboing.net/" title="Boing Boing Blog" >Boing Boing Blog</a><dl><dt>alturls</dt><dd><ol><li><a href="http://boingboing.net/rss.xml" >xmlurl</a></li></ol></dd><dt>description</dt><dd>Boing Boing Blog</dd></dl></li><li><a href="http://www.financialcryptography.com/" title="Financial Cryptography" >Financial Cryptography</a><dl><dt>alturls</dt><dd><ol><li><a href="http://www.financialcryptography.com/mt/index.rdf" >xmlurl</a></li></ol></dd><dt>description</dt><dd>Financial Cryptography</dd></dl></li><li><a href="http://hublog.hubmed.org/" title="HubLog" >HubLog</a><dl><dt>alturls</dt><dd><ol><li><a href="http://hublog.hubmed.org/index.xml" >xmlurl</a></li><li><a href="http://hublog.hubmed.org/foaf.rdf" >foafurl</a></li></ol></dd><dt>description</dt><dd>HubLog</dd></dl></li></ol>''';
     d = xoxo.fromXOXO(kmattn)
     newattn = xoxo.toXOXO(d)
     d2 = xoxo.fromXOXO(newattn)
     self.assertEqual(newattn,xoxo.toXOXO(d2))
     self.assertEqual(d,d2)
     self.assertEqual(kmattn,newattn)
Exemplo n.º 4
0
    def testXOXOWithSpacesAndNewlines(self):
        '''unmung some xoxo with spaces in and check result is right'''
        xoxoSample= '''<ol class='xoxo'> 
  <li>
    <dl>
        <dt>text</dt>
        <dd>item 1</dd>
        <dt>description</dt>
        <dd> This item represents the main point we're trying to make.</dd>
        <dt>url</dt>
        <dd>http://example.com/more.xoxo</dd>
        <dt>title</dt>
        <dd>title of item 1</dd>
        <dt>type</dt>
        <dd>text/xml</dd>
        <dt>rel</dt>
        <dd>help</dd>
    </dl>
  </li>
</ol>'''
        d = xoxo.fromXOXO(xoxoSample)
        d2={'text':'item 1',
            'description':" This item represents the main point we're trying to make.",
            'url':'http://example.com/more.xoxo',
            'title':'title of item 1',
            'type':'text/xml',
            'rel':'help'
            }
        xoxoAgain = xoxo.toXOXO(d)
        self.assertEqual(d,d2)
Exemplo n.º 5
0
 def testDictofListsRoundTrip(self):
     ''' make a dict with lists in into a xoxo file and back again; check it is the same'''
     d = {'test':['1','2'],
     'name':'Kevin',
     'nestlist':['a',['b','c']],
     'nestdict':{'e':'6','f':'7'}}
     html = xoxo.toXOXO(d)
     newd = xoxo.fromXOXO(html)
     self.assertEqual(d,newd)
Exemplo n.º 6
0
 def get(self):
     url = fixurl(self.request.get('url'))
     prettyText = self.request.get('pretty','')
     pretty = prettyText == 'on'
     result = urlfetch.fetch(url)
     if result.status_code == 200:
         data= xoxo.fromXOXO(result.content)
         if pretty:
             xoxojson = json.dumps(data,indent=4, separators=(', ', ': '))
         else:
             xoxojson = json.dumps(data)
         self.response.headers['Content-Type'] = 'application/json'
         self.response.write(xoxojson)
     else:
         html= "Error %i %s" % (result.status_code,result.content)
         self.response.write(html)
Exemplo n.º 7
0
 def testListofDictsRoundTrip(self):
     ''' make a list of Dicts into a xoxo file and back again; check it is the same'''
     l = ['3', {'a': '2'}, {'b': '1', 'c': '4'}]
     html = xoxo.toXOXO(l)
     newdl = xoxo.fromXOXO(html)
     self.assertEqual(l, newdl)
Exemplo n.º 8
0
 def testListofDictsRoundTrip(self):
     ''' make a list of Dicts into a xoxo file and back again; check it is the same'''
     l = ['3',{'a':'2'},{'b':'1','c':'4'}]
     html = xoxo.toXOXO(l)
     newdl= xoxo.fromXOXO(html)
     self.assertEqual(l,newdl)
Exemplo n.º 9
0
 def testListRoundTrip(self):
     ''' make a list into a xoxo file and back again; check it is the same'''
     l = ['3', '2', '1']
     html = xoxo.toXOXO(l)
     newdl = xoxo.fromXOXO(html)
     self.assertEqual(l, newdl)
Exemplo n.º 10
0
 def testNestedDictionariesWithURLsRoundTrip(self):
     ''' make a dictionary with an url and a dict with an url into a xoxo file and back again; check it is the same'''
     d = {'url':'http://example.com','inner':{'name':'Kevin','url':'http://slashdot.org'}}
     html = xoxo.toXOXO(d)
     newd = xoxo.fromXOXO(html)
     self.assertEqual(d,newd)
Exemplo n.º 11
0
 def testListRoundTrip(self):
     ''' make a list into a xoxo file and back again; check it is the same'''
     l = ['3','2','1']
     html = xoxo.toXOXO(l)
     newdl= xoxo.fromXOXO(html)
     self.assertEqual(l,newdl)
Exemplo n.º 12
0
 def testNestedDictionaryRoundTrip(self):
     ''' make a dictionary with a dict in into a xoxo file and back again; check it is the same'''
     d = {'test': '1', 'inner': {'name': 'Kevin'}}
     html = xoxo.toXOXO(d)
     newd = xoxo.fromXOXO(html)
     self.assertEqual(d, newd)
Exemplo n.º 13
0
 def testListofListsRoundTrip(self):
     ''' make a list of Lists into a xoxo file and back again; check it is the same'''
     l = ['3',['a','2'],['b',['1',['c','4']]]]
     html = xoxo.toXOXO(l)
     newdl= xoxo.fromXOXO(html)
     self.assertEqual(l,newdl)
Exemplo n.º 14
0
 def testXOXOjunkInElements(self):
     '''make sure text within <li> but outside a subcontainer is ignored'''
     l = xoxo.fromXOXO(
         '<ol><li>bad<dl><dt>good</dt><dd>buy</dd></dl>worse</li><li>bag<ol><li>OK</li></ol>fish</li></ol>'
     )
     self.assertEqual(l, [{'good': 'buy'}, ['OK']])
Exemplo n.º 15
0
 def testUtf8Roundtrip(self):
     '''check utf8 characters can go to xoxo and back'''
     src = 'Tantek \xc3\x87elik and a snowman \xe2\x98\x83'
     html = xoxo.toXOXO(src)
     self.assertEqual(src, xoxo.fromXOXO(html).encode('utf-8'))
Exemplo n.º 16
0
 def testListofListsRoundTrip(self):
     ''' make a list of Lists into a xoxo file and back again; check it is the same'''
     l = ['3', ['a', '2'], ['b', ['1', ['c', '4']]]]
     html = xoxo.toXOXO(l)
     newdl = xoxo.fromXOXO(html)
     self.assertEqual(l, newdl)
Exemplo n.º 17
0
 def testSpecialAttributeRoundTripNoTextOrTitle(self):
     '''check it makes an <a href with a url parameter and no text or title attribute'''
     d={'url':'http://example.com/more.xoxo'}
     html=xoxo.toXOXO(d)
     self.assertEqual(d,xoxo.fromXOXO(html))
Exemplo n.º 18
0
 def testSpecialAttributeRoundTripNoText(self):
     '''check it makes an <a href with a url parameter and no text attribute'''
     d={'url':'http://example.com/more.xoxo','title':'sample url','type':"text/xml",'rel':'help'}
     html=xoxo.toXOXO(d)
     self.assertEqual(d,xoxo.fromXOXO(html))
Exemplo n.º 19
0
 def testXOXOjunkInContainers(self):
     '''make sure text outside <li> etc is ignored'''
     d=xoxo.fromXOXO('<ol>bad<li><dl>worse<dt>good</dt><dd>buy</dd> now</dl></li></ol>')
     self.assertEqual(d,{'good': 'buy'})
Exemplo n.º 20
0
 def testXOXOjunkInElements(self):
     '''make sure text within <li> but outside a subcontainer is ignored'''
     l=xoxo.fromXOXO('<ol><li>bad<dl><dt>good</dt><dd>buy</dd></dl>worse</li><li>bag<ol><li>OK</li></ol>fish</li></ol>')
     self.assertEqual(l,[{'good': 'buy'},['OK']])
Exemplo n.º 21
0
 def testXOXOjunkInContainers(self):
     '''make sure text outside <li> etc is ignored'''
     d = xoxo.fromXOXO(
         '<ol>bad<li><dl>worse<dt>good</dt><dd>buy</dd> now</dl></li></ol>')
     self.assertEqual(d, {'good': 'buy'})
Exemplo n.º 22
0
 def testUtf8Roundtrip(self):
     '''check utf8 characters can go to xoxo and back'''
     src='Tantek \xc3\x87elik and a snowman \xe2\x98\x83'
     html = xoxo.toXOXO(src)
     self.assertEqual(src,xoxo.fromXOXO(html).encode('utf-8'))
Exemplo n.º 23
0
 def testSpecialAttributeRoundTripNoTextOrTitle(self):
     '''check it makes an <a href with a url parameter and no text or title attribute'''
     d = {'url': 'http://example.com/more.xoxo'}
     html = xoxo.toXOXO(d)
     self.assertEqual(d, xoxo.fromXOXO(html))
Exemplo n.º 24
0
 def testWindows1252Roundtrip(self):
     '''check 1252 characters can go to xoxo and back'''
     src='This is an evil\xa0space'
     html = xoxo.toXOXO(src)
     self.assertEqual(src,xoxo.fromXOXO(html).encode('windows-1252'))
Exemplo n.º 25
0
 def testWindows1252Roundtrip(self):
     '''check 1252 characters can go to xoxo and back'''
     src = 'This is an evil\xa0space'
     html = xoxo.toXOXO(src)
     self.assertEqual(src, xoxo.fromXOXO(html).encode('windows-1252'))
Exemplo n.º 26
0
 def testDictionaryWithURLRoundTrip(self):
     ''' make a dictionary wiht an url in into a xoxo file and back again; check it is the same'''
     d = {'url':'http://example.com','name':'Kevin'}
     html = xoxo.toXOXO(d)
     newd = xoxo.fromXOXO(html)
     self.assertEqual(d,newd)    
Exemplo n.º 27
0
 def testNestedDictionaryWithURLRoundTrip(self):
     ''' make a dictionary with an url and a dict into a xoxo file and back again; check it is the same'''
     d = {'url': 'http://example.com', 'inner': {'name': 'Kevin'}}
     html = xoxo.toXOXO(d)
     newd = xoxo.fromXOXO(html)
     self.assertEqual(d, newd)
Exemplo n.º 28
0
 def testNestedDictionaryRoundTrip(self):
     ''' make a dictionary with a dict in into a xoxo file and back again; check it is the same'''
     d = {'test':'1','inner':{'name':'Kevin'}}
     html = xoxo.toXOXO(d)
     newd = xoxo.fromXOXO(html)
     self.assertEqual(d,newd)