예제 #1
0
 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()
예제 #2
0
 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)
예제 #3
0
 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.")
예제 #4
0
 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"))
예제 #5
0
 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>')
예제 #6
0
 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.")
예제 #7
0
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))
예제 #8
0
 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)
예제 #9
0
 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)
예제 #10
0
 def __init__(self, loader, number, source):
     Element.__init__(self, loader)
     self.number = number
     self.source = source
예제 #11
0
 def __init__(self, loader, stackFrames):
     Element.__init__(self, loader)
     self.stackFrames = stackFrames
예제 #12
0
파일: template.py 프로젝트: dcambie/octopus
 def __init__(self, sketch_id):
     Element.__init__(self)
     self.sketch_id = sketch_id
예제 #13
0
파일: template.py 프로젝트: dcambie/octopus
 def __init__(self, experiment):
     Element.__init__(self)
     self.experiment = experiment
예제 #14
0
파일: web.py 프로젝트: tazjel/bravo
 def __init__(self, factory, plugins):
     Element.__init__(self)
     self.factory = factory
     self.plugins = plugins
예제 #15
0
파일: __init__.py 프로젝트: igraph/pydoctor
 def footer(self, request: IRequest, tag: Tag) -> IRenderable:
     return Element(self.template_lookup.get_loader('footer.html'))
예제 #16
0
 def __init__(self, alertType, text):
     Element.__init__(self)
     self.alertType = alertType
     self.alertText = text
예제 #17
0
 def __init__(self, loader, docgetter, ob, child):
     Element.__init__(self, loader)
     self.docgetter = docgetter
     self.ob = ob
     self.child = child
예제 #18
0
 def __init__(self, data):
     self.loader = XMLString(data)
     Element.__init__(self)
예제 #19
0
 def __init__(self, user):
     Element.__init__(self)
     self.user = user
예제 #20
0
 def __init__(self, title, user, body=None):
     Element.__init__(self)
     self.titleText = title
     self.user = user
     self.bodyElement = body
예제 #21
0
 def __init__(self, datastore):
     Element.__init__(self)
     self.datastore = datastore
예제 #22
0
 def renderMethod(
     self, request: Optional[IRequest], tag: Tag
 ) -> Flattenable:
     return tag(Element(loader=XMLString("<em>Hello, world.</em>")))
예제 #23
0
 def __init__(self, loader, name):
     Element.__init__(self, loader)
     self._name = name
예제 #24
0
 def __init__(self, automaton):
     Element.__init__(self)
     self.automaton = automaton
예제 #25
0
 def __init__(self, baseurl='', revurl='', row={}):
     Element.__init__(self)
     self.baseurl = baseurl
     self.revurl  = revurl
     self.row = row
예제 #26
0
 def __init__(self):
     Element.__init__(self, loader=sample)
     self.deferred = Deferred()
예제 #27
0
파일: web.py 프로젝트: tazjel/bravo
 def __init__(self, worlds, services):
     Element.__init__(self)
     self.services = services
     self.worlds = worlds
예제 #28
0
 def __init__(self, service, content):
     Element.__init__(self)
     self.content_element = content
     self.service = service
예제 #29
0
파일: table.py 프로젝트: chevah/pydoctor
 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
예제 #30
0
 def __init__(self, service):
     Element.__init__(self)
     self.service = service
예제 #31
0
 def __init__(self, loader, initials, letter):
     Element.__init__(self, loader)
     self.initials = initials
     self.my_letter = letter
예제 #32
0
 def test_missingTemplateLoader(self):
     """
     Rendering an Element without a loader attribute raises the appropriate
     exception.
     """
     return self.assertFlatteningRaises(Element(), MissingTemplateLoader)
예제 #33
0
파일: template.py 프로젝트: dcambie/octopus
 def __init__(self, expt):
     Element.__init__(self)
     self.expt = expt
     self._load = expt.load()
예제 #34
0
파일: web_base.py 프로젝트: calston/pitool
 def __init__(self, service, content):
     Element.__init__(self)
     self.content_element = content
     self.service = service
예제 #35
0
파일: template.py 프로젝트: dcambie/octopus
 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
예제 #36
0
 def __init__(self, loader, number, source):
     Element.__init__(self, loader)
     self.number = number
     self.source = source
예제 #37
0
 def __init__(self, loader, frame):
     Element.__init__(self, loader)
     self.frame = frame
예제 #38
0
 def __init__(self, loader, stackFrames):
     Element.__init__(self, loader)
     self.stackFrames = stackFrames
예제 #39
0
 def __init__(self, failure, loader=None):
     Element.__init__(self, loader)
     self.failure = failure
예제 #40
0
 def __init__(self, loader, initials, letter):
     Element.__init__(self, loader)
     self.initials = initials
     self.my_letter = letter
예제 #41
0
 def __init__(self, datastore):
     Element.__init__(self)
     self.datastore = datastore
예제 #42
0
 def __init__(self, request, db, dates):
   Element.__init__(self)
   self.request = request
   self.db = db
   self.dates = dates
예제 #43
0
 def renderMethod(self, request, tag):
     return tag(Element(
         loader=XMLString("<em>Hello, world.</em>")))
예제 #44
0
파일: hoorj.py 프로젝트: veloutin/txwtf
 def __init__(self, loader, field):
     Element.__init__(self, loader)
     self.f = field
예제 #45
0
파일: web_base.py 프로젝트: calston/pitool
 def __init__(self, service):
     Element.__init__(self)
     self.service = service
예제 #46
0
파일: hoorj.py 프로젝트: veloutin/txwtf
 def __init__(self, content):
     Element.__init__(self)
     self._content = content
예제 #47
0
 def __init__(self, loader, frame):
     Element.__init__(self, loader)
     self.frame = frame
예제 #48
0
 def __init__(self, loader, name):
     Element.__init__(self, loader)
     self._name = name
예제 #49
0
 def __init__(self, failure, loader=None):
     Element.__init__(self, loader)
     self.failure = failure
예제 #50
0
파일: app.py 프로젝트: Fugiman/destiny
 def render(self, request):
   request.write("<!doctype html>\n")
   return Element.render(self, request)