Ticket #6238: 6238_v1.diff

File 6238_v1.diff, 2.7 KB (added by borko, 19 months ago)
  • twisted/web/_flatten.py

    diff --git a/twisted/web/_flatten.py b/twisted/web/_flatten.py
    index bfdc776..35195f4 100644
    a b from twisted.web.error import UnfilledSlot, UnsupportedType, FlattenerError 
    1818from twisted.web.iweb import IRenderable 
    1919from twisted.web._stan import ( 
    2020    Tag, slot, voidElements, Comment, CDATA, CharRef) 
     21from twisted.python import urlpath 
    2122 
    2223 
    2324 
    def _getSlotValue(name, slotData, default=None): 
    9697 
    9798def _flattenElement(request, root, slotData, renderFactory, inAttribute): 
    9899    """ 
    99     Make C{root} slightly more flat by yielding all its immediate contents  
     100    Make C{root} slightly more flat by yielding all its immediate contents 
    100101    as strings, deferreds or generators that are recursive calls to itself. 
    101102 
    102103    @param request: A request object which will be passed to 
    def _flattenElement(request, root, slotData, renderFactory, inAttribute): 
    179180        yield root.addCallback( 
    180181            lambda result: (result, _flattenElement(request, result, slotData, 
    181182                                             renderFactory, inAttribute))) 
     183    elif isinstance(root, urlpath.URLPath): 
     184        yield str(root) 
    182185    elif IRenderable.providedBy(root): 
    183186        result = root.render(request) 
    184187        yield _flattenElement(request, result, slotData, root, inAttribute) 
  • twisted/web/test/test_flatten.py

    diff --git a/twisted/web/test/test_flatten.py b/twisted/web/test/test_flatten.py
    index c843a61..42777b6 100644
    a b from twisted.web.error import UnfilledSlot, UnsupportedType, FlattenerError 
    1515from twisted.web.template import tags, Comment, CDATA, CharRef, slot 
    1616from twisted.web.iweb import IRenderable 
    1717from twisted.web.test._util import FlattenTestCase 
    18  
     18from twisted.python import urlpath 
    1919 
    2020class TestSerialization(FlattenTestCase): 
    2121    """ 
    class TestSerialization(FlattenTestCase): 
    202202        return self.assertFlattensTo(t, '<p><em>four&gt;</em></p>') 
    203203 
    204204 
     205    def test_serializeURLPath(self): 
     206        """ 
     207        Test that url path is properly serialized 
     208        """ 
     209        t = urlpath.URLPath.fromString("http://example.com/") 
     210        return self.assertFlattensTo(t, "http://example.com/" ) 
     211 
     212 
     213    def test_serializeURLPath2(self): 
     214        """ 
     215        Test that url path is properly serialized 
     216        """ 
     217        t = urlpath.URLPath.fromString("http://example.com/foo/bar?yes=no&no=yes#footer") 
     218        return self.assertFlattensTo(t,"http://example.com/foo/bar?yes=no&no=yes#footer" ) 
     219 
     220 
    205221    def test_unknownTypeRaises(self): 
    206222        """ 
    207223        Test that flattening an unknown type of thing raises an exception.