def __init__(self, request, db, dates, postcodes): Element.__init__(self) self.request = request self.db = db self.dates = dates self.postcodes = postcodes self.data = self.load_data()
def test_missingRenderMethod(self): """ Flattening an L{Element} with a C{loader} which has a tag with a render directive fails with L{FlattenerError} if there is no available render method to satisfy that directive. """ element = Element(loader=XMLString(""" <p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1" t:render="unknownMethod" /> """)) return self.assertFlatteningRaises(element, MissingRenderMethod)
def test_transparentRendering(self): """ A C{transparent} element should be eliminated from the DOM and rendered as only its children. """ element = Element(loader=XMLString( '<t:transparent ' 'xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1">' 'Hello, world.' '</t:transparent>')) return self.assertFlattensTo(element, "Hello, world.")
def test_lenientPrefixBehavior(self) -> None: """ If the parser sees a prefix it doesn't recognize on an attribute, it will pass it on through to serialization. """ theInput = ( '<hello:world hello:sample="testing" ' 'xmlns:hello="http://made-up.example.com/ns/not-real">' "This is a made-up tag.</hello:world>" ) element = Element(loader=XMLString(theInput)) self.assertFlattensTo(element, theInput.encode("utf8"))
def test_attrRendering(self): """ An Element with an attr tag renders the vaule of its attr tag as an attribute of its containing tag. """ element = Element(loader=XMLString( '<a xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1">' '<t:attr name="href">http://example.com</t:attr>' "Hello, world." "</a>")) return self.assertFlattensTo( element, b'<a href="http://example.com">Hello, world.</a>')
def test_transparentRendering(self) -> None: """ A C{transparent} element should be eliminated from the DOM and rendered as only its children. """ element = Element( loader=XMLString( "<t:transparent " 'xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1">' "Hello, world." "</t:transparent>" ) ) self.assertFlattensImmediately(element, b"Hello, world.")
def defaultValidationFailureHandler( instance, # type: Optional[object] request, # type: IRequest fieldValues, # type: FieldValues ): # type: (...) -> Element """ This is the default validation failure handler, which will be used by form handlers (i.e. any routes which use L{klein.Requirer} to require a field) in the case of any input validation failure when no other validation failure handler is registered via L{Form.onValidationFailureFor}. Its behavior is to simply return an HTML rendering of the form object, which includes inline information about fields which failed to validate. @param instance: The instance associated with the router that the form handler was handled on. @type instance: L{object} @param request: The request including the form submission. @type request: L{twisted.web.iweb.IRequest} @return: Any object acceptable from a Klein route. """ session = request.getComponent(ISession) # type: ignore[misc] request.setResponseCode(400) enctype = ( ( request.getHeader(b"content-type") or RenderableForm.ENCTYPE_URL_ENCODED.encode("ascii") ) .split(b";")[0] .decode("charmap") ) renderable = RenderableForm( fieldValues.form, session, "/".join( segment.decode("utf-8", errors="replace") for segment in request.prepath ), request.method, enctype, "utf-8", fieldValues.prevalidationValues, fieldValues.validationErrors, ) return Element(TagLoader(renderable))
def test_roundTrip(self) -> None: """ Given a series of parsable XML strings, verify that L{twisted.web._flatten.flatten} will flatten the L{Element} back to the input when sent on a round trip. """ fragments = [ b"<p>Hello, world.</p>", b"<p><!-- hello, world --></p>", b"<p><![CDATA[Hello, world.]]></p>", b'<test1 xmlns:test2="urn:test2">' b"<test2:test3></test2:test3></test1>", b'<test1 xmlns="urn:test2"><test3></test3></test1>', b"<p>\xe2\x98\x83</p>", ] for xml in fragments: self.assertFlattensImmediately(Element(loader=XMLString(xml)), xml)
def test_roundTrip(self): """ Given a series of parsable XML strings, verify that L{twisted.web._flatten.flatten} will flatten the L{Element} back to the input when sent on a round trip. """ fragments = [ b"<p>Hello, world.</p>", b"<p><!-- hello, world --></p>", b"<p><![CDATA[Hello, world.]]></p>", b'<test1 xmlns:test2="urn:test2">' b'<test2:test3></test2:test3></test1>', b'<test1 xmlns="urn:test2"><test3></test3></test1>', b'<p>\xe2\x98\x83</p>', ] deferreds = [ self.assertFlattensTo(Element(loader=XMLString(xml)), xml) for xml in fragments] return gatherResults(deferreds)
def __init__(self, loader, number, source): Element.__init__(self, loader) self.number = number self.source = source
def __init__(self, loader, stackFrames): Element.__init__(self, loader) self.stackFrames = stackFrames
def __init__(self, sketch_id): Element.__init__(self) self.sketch_id = sketch_id
def __init__(self, experiment): Element.__init__(self) self.experiment = experiment
def __init__(self, factory, plugins): Element.__init__(self) self.factory = factory self.plugins = plugins
def footer(self, request: IRequest, tag: Tag) -> IRenderable: return Element(self.template_lookup.get_loader('footer.html'))
def __init__(self, alertType, text): Element.__init__(self) self.alertType = alertType self.alertText = text
def __init__(self, loader, docgetter, ob, child): Element.__init__(self, loader) self.docgetter = docgetter self.ob = ob self.child = child
def __init__(self, data): self.loader = XMLString(data) Element.__init__(self)
def __init__(self, user): Element.__init__(self) self.user = user
def __init__(self, title, user, body=None): Element.__init__(self) self.titleText = title self.user = user self.bodyElement = body
def __init__(self, datastore): Element.__init__(self) self.datastore = datastore
def renderMethod( self, request: Optional[IRequest], tag: Tag ) -> Flattenable: return tag(Element(loader=XMLString("<em>Hello, world.</em>")))
def __init__(self, loader, name): Element.__init__(self, loader) self._name = name
def __init__(self, automaton): Element.__init__(self) self.automaton = automaton
def __init__(self, baseurl='', revurl='', row={}): Element.__init__(self) self.baseurl = baseurl self.revurl = revurl self.row = row
def __init__(self): Element.__init__(self, loader=sample) self.deferred = Deferred()
def __init__(self, worlds, services): Element.__init__(self) self.services = services self.worlds = worlds
def __init__(self, service, content): Element.__init__(self) self.content_element = content self.service = service
def __init__(self, loader, docgetter, has_lineno_col, ob, child): Element.__init__(self, loader) self.docgetter = docgetter self.has_lineno_col = has_lineno_col self.ob = ob self.child = child
def __init__(self, service): Element.__init__(self) self.service = service
def __init__(self, loader, initials, letter): Element.__init__(self, loader) self.initials = initials self.my_letter = letter
def test_missingTemplateLoader(self): """ Rendering an Element without a loader attribute raises the appropriate exception. """ return self.assertFlatteningRaises(Element(), MissingTemplateLoader)
def __init__(self, expt): Element.__init__(self) self.expt = expt self._load = expt.load()
def __init__(self, running_experiments, past_experiments, saved_sketches): Element.__init__(self) self.running_experiments = running_experiments self.past_experiments = past_experiments self.saved_sketches = saved_sketches
def __init__(self, loader, frame): Element.__init__(self, loader) self.frame = frame
def __init__(self, failure, loader=None): Element.__init__(self, loader) self.failure = failure
def __init__(self, request, db, dates): Element.__init__(self) self.request = request self.db = db self.dates = dates
def renderMethod(self, request, tag): return tag(Element( loader=XMLString("<em>Hello, world.</em>")))
def __init__(self, loader, field): Element.__init__(self, loader) self.f = field
def __init__(self, content): Element.__init__(self) self._content = content
def render(self, request): request.write("<!doctype html>\n") return Element.render(self, request)