Ejemplo n.º 1
0
    def execute(self, chain, request, env={}):
        if "payload" in env:
            marshaller = Converters.marshaller_for(request.headers.get("Content-type"))
            env["body"] = marshaller.marshal(env["payload"])
            del (env["payload"])

        return chain.follow(request, env)
Ejemplo n.º 2
0
    def execute(self, chain, request, env={}):
        if "payload" in env:
            content_type = request.headers.get("Content-Type")
            marshaller = Converters.marshaller_for(content_type)
            env["body"] = marshaller.marshal(env["payload"])
            del (env["payload"])

        return chain.follow(request, env)
Ejemplo n.º 3
0
    def resource(self):

        if 'content-type' in self.response[0]:
            contenttype = self.response[0]['content-type'].split(';')[0]
        else:
            contenttype = None

        converter = Converters.marshaller_for(contenttype)
        return converter.unmarshal(self.body)
Ejemplo n.º 4
0
    def test_single_style(self):
        html = "<div style='background-color: blue;'></div>"
        expected_html = '<div class="newClass1">\n</div>'
        expected_css = '.newClass1 {\n\tbackground-color:blue,\n}\n\n'

        cssClasses, newHtml = Converters().convertStyleToClass(html)

        self.assertEqual(newHtml, expected_html)
        self.assertEqual(cssClasses, expected_css)
Ejemplo n.º 5
0
    def resource(self):

        if "content-type" in self.response[0]:
            contenttype = self.response[0]["content-type"].split(";")[0]
        else:
            contenttype = None

        converter = Converters.marshaller_for(contenttype)
        return converter.unmarshal(self.body)
Ejemplo n.º 6
0
    def resource(self):

        if 'content-type' in self.response[0]:
            contenttype = self.response[0]['content-type'].split(';')[0]
        else:
            contenttype = None

        converter = Converters.marshaller_for(contenttype)
        return converter.unmarshal(self.body)
Ejemplo n.º 7
0
    def test_duplicate_unordered_classes(self):
        html = "<div style='text-align: center; background-color: blue;'><div style='background-color: blue; text-align: center;'></div></div>"
        expected_html = '<div class="newClass1">\n <div class="newClass1">\n </div>\n</div>'
        expected_css = '.newClass1 {\n\tbackground-color:blue,\n\ttext-align:center,\n}\n\n'

        cssClasses, newHtml = Converters().convertStyleToClass(html)

        self.assertEqual(newHtml, expected_html)
        self.assertEqual(cssClasses, expected_css)
Ejemplo n.º 8
0
    def resource(self):
        """
        Returns the unmarshalled object of the response body
        """
        if 'content-type' in self.response[0]:
            contenttype = self.response[0]['content-type'].split(';')[0]
        else:
            contenttype = None

        converter = Converters.marshaller_for(contenttype)
        return converter.unmarshal(self.body)
Ejemplo n.º 9
0
    def resource(self):
        """
        Returns the unmarshalled object of the response body
        """
        if 'content-type' in self.response[0]:
            contenttype = self.response[0]['content-type'].split(';')[0]
        else:
            contenttype = None

        converter = Converters.marshaller_for(contenttype)
        return converter.unmarshal(self.body)
Ejemplo n.º 10
0
from lxml import objectify
from converters import Converters

class LXMLConverter(object):

    def marshal(self, dictionary):
        '''from dictionary'''
        output = ""
        for key, value in dictionary.iteritems():
            output += "<%s>" % key
            if isinstance(value, dict):
                output += self.marshal(value)
            else:
                output += str(value)
            output += "</%s>" % key
        return output

    def unmarshal(self, xml_content):
        '''to object'''
        BlankSlate = type('object', (object,), {})
        result = BlankSlate()
        xml = objectify.fromstring(xml_content)
        child_tag = xml.iterchildren().next().tag
        setattr(result, xml.tag, getattr(xml, child_tag))
        return result

Converters.register("application/xml", XmlConverter())
Ejemplo n.º 11
0
class American(Converter[Base]):
    date: str = Converters.from_datetime("date", "%m/%d/%y %H:%M")
    start: str = Converters.from_datetime("range.start", "%m/%d/%y %H:%M")
    end: str = Converters.from_datetime("range.end", "%m/%d/%y %H:%M")
Ejemplo n.º 12
0
class International(Converter[Base]):
    date: str = Converters.from_datetime("date", "%d/%m/%y %H:%M")
    start: str = Converters.from_datetime("range.start", "%d/%m/%y %H:%M")
    end: str = Converters.from_datetime("range.end", "%d/%m/%y %H:%M")