Exemplo n.º 1
0
def serialize_object_2(obj, obj_name):
    elem_maker = ElementMaker(annotate=False)
    root = elem_maker(obj_name)
    for key, val in obj.__dict__.items():
        if val == None:
            attr = elem_maker(key, "")
        else:
            attr = elem_maker(key, val)
        root.append(attr)
    return root
Exemplo n.º 2
0
def serialize_object(obj, obj_name):
    elem_maker = ElementMaker(annotate=False)
    root = elem_maker(obj_name)
    for key, val in obj.__dict__.items():
        if val == None:
            attr = elem_maker(key, "")
        elif type(val) == bool:
            attr = elem_maker(key, val)
        elif not type(val) == str:
            attr = elem_maker(key)
            for elt in val:
                item = elem_maker("item",elt.id)
                if elt.date == None:
                    item.set('date',"")
                else:
                    item.set('date',elt.date)
                attr.append(item)
        else:
            attr = elem_maker(key, val)
        root.append(attr)
    return root
Exemplo n.º 3
0
    def getvalue(self, serialize=True):
        """ Gets the actual payload's value converted to a string representing
        either XML or JSON.
        """
        if self.zato_is_xml:
            if self.zato_output_repeated:
                value = Element('item_list')
            else:
                value = Element('item')
        else:
            if self.zato_output_repeated:
                value = []
            else:
                value = {}

        if self.zato_output_repeated:
            output = self.zato_output
        else:
            output = set(dir(self)) & self.zato_all_attrs
            output = [dict((name, getattr(self, name)) for name in output)]

        if output:

            # All elements must be of the same type so it's OK to do it
            is_sa_namedtuple = isinstance(output[0], KeyedTuple)

            for item in output:
                if self.zato_is_xml:
                    out_item = Element('item')
                else:
                    out_item = {}
                for is_required, name in chain(self.zato_required,
                                               self.zato_optional):
                    leave_as_is = isinstance(name, AsIs)
                    elem_value = self._getvalue(name, item, is_sa_namedtuple,
                                                is_required, leave_as_is)

                    if isinstance(name, ForceType):
                        name = name.name

                    if isinstance(elem_value, basestring):
                        elem_value = elem_value if isinstance(
                            elem_value,
                            unicode) else elem_value.decode('utf-8')

                    if self.zato_is_xml:
                        setattr(out_item, name, elem_value)
                    else:
                        out_item[name] = elem_value

                if self.zato_output_repeated:
                    value.append(out_item)
                else:
                    value = out_item

        if self.zato_is_xml:
            em = ElementMaker(annotate=False,
                              namespace=self.namespace,
                              nsmap={None: self.namespace})
            zato_env = em.zato_env(em.cid(self.zato_cid), em.result(ZATO_OK))
            top = getattr(em, self.response_elem)(zato_env)
            top.append(value)
        else:
            top = {self.response_elem: value}
            search = self.zato_meta.get('search')
            if search:
                top['_meta'] = search

        if serialize:
            if self.zato_is_xml:
                deannotate(top, cleanup_namespaces=True)
                return etree.tostring(top)
            else:
                return dumps(top)
        else:
            return top
Exemplo n.º 4
0
    def getvalue(self, serialize=True):
        """ Gets the actual payload's value converted to a string representing
        either XML or JSON.
        """
        if self.zato_is_xml:
            if self.zato_output_repeated:
                value = Element('item_list')
            else:
                value = Element('item')
        else:
            if self.zato_output_repeated:
                value = []
            else:
                value = {}

        if self.zato_output_repeated:
            output = self.zato_output
        else:
            output = set(dir(self)) & self.zato_all_attrs
            output = [dict((name, getattr(self, name)) for name in output)]

        if output:

            # All elements must be of the same type so it's OK to do it
            is_sa_namedtuple = isinstance(output[0], KeyedTuple)

            for item in output:
                if self.zato_is_xml:
                    out_item = Element('item')
                else:
                    out_item = {}
                for is_required, name in chain(self.zato_required, self.zato_optional):
                    leave_as_is = isinstance(name, AsIs)
                    elem_value = self._getvalue(name, item, is_sa_namedtuple, is_required, leave_as_is)

                    if isinstance(name, ForceType):
                        name = name.name

                    if isinstance(elem_value, basestring):
                        elem_value = elem_value if isinstance(elem_value, unicode) else elem_value.decode('utf-8')

                    if self.zato_is_xml:
                        setattr(out_item, name, elem_value)
                    else:
                        out_item[name] = elem_value

                if self.zato_output_repeated:
                    value.append(out_item)
                else:
                    value = out_item

        if self.zato_is_xml:
            em = ElementMaker(annotate=False, namespace=self.namespace, nsmap={None:self.namespace})
            zato_env = em.zato_env(em.cid(self.zato_cid), em.result(ZATO_OK))
            top = getattr(em, self.response_elem)(zato_env)
            top.append(value)
        else:
            top = {self.response_elem: value}

        if serialize:
            if self.zato_is_xml:
                deannotate(top, cleanup_namespaces=True)
                return etree.tostring(top)
            else:
                return dumps(top)
        else:
            return top
Exemplo n.º 5
0
    metadata_name_shortcut_cache = {}

    @property
    def namespace_map(self):
        # lxml is really dumb with xml using default namespaces.  You have to define a dummy namespace prefix to the
        # default namespace even though that prefix doesn't exist in the raw xml. Define a consistent map for all xpath
        return {'z': 'xmlns://www.fortifysoftware.com/schema/externalMetadata'}

    # in goes a metadata name and out comes a list of shortcuts for that name
    def get_shortcuts_for_name(self, name):
        if name not in self.metadata_name_shortcut_cache:
            self.metadata_name_shortcut_cache[name] = self.xpath(
                "./z:ExternalList[z:Name='%s']/z:Shortcut/text()" % name,
                namespaces=self.namespace_map)

        return self.metadata_name_shortcut_cache[name]


EXTERNALMETADATA_NAMESPACE = ExternalMetadataElementNamespaceClassLookup.get_namespace(
    "xmlns://www.fortifysoftware.com/schema/externalMetadata")

EXTERNALMETADATA_NAMESPACE[
    'ExternalMetadataPack'] = ExternalMetadataPackElement

ExternalMetadataParser.set_element_class_lookup(
    ExternalMetadataElementNamespaceClassLookup)

ExternalMetadataPack = ElementMaker(
    annotate=False,
    namespace='xmlns://www.fortifysoftware.com/schema/externalMetadata',
    nsmap={None: 'xmlns://www.fortifysoftware.com/schema/externalMetadata'})
Exemplo n.º 6
0
from functools import partial
from typing import List, Dict, Any

from genologics.entities import Artifact, Project, Container, Containertype, Researcher
from lxml import etree
from lxml.objectify import ElementMaker, ObjectifiedElement

SMP_MAKER = ElementMaker(
    namespace="http://genologics.com/ri/sample",
    nsmap={
        "smp": "http://genologics.com/ri/sample",
        "udf": "http://genologics.com/ri/userdefined",
    },
)
SMP_DETAILS = partial(SMP_MAKER, "details")
SMP_SAMPLECREATION = partial(SMP_MAKER, "samplecreation")

CON_MAKER = ElementMaker(
    namespace="http://genologics.com/ri/container",
    nsmap={"con": "http://genologics.com/ri/container"},
)
CON_DETAILS = partial(CON_MAKER, "details")
CON_CONTAINER = partial(CON_MAKER, "container")

UDF_MAKER = ElementMaker(namespace="http://genologics.com/ri/userdefined",
                         annotate=False)
UDF_FIELD = partial(UDF_MAKER, "field")

ART_MAKER = ElementMaker(
    namespace="http://genologics.com/ri/artifact",
    nsmap={"art": "http://genologics.com/ri/artifact"},
Exemplo n.º 7
0
    def get_envelope(self, ad_url, auth_uri, username, password):
        NSMAP = {
            's': 'http://www.w3.org/2003/05/soap-envelope',
            'wsse':
            'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd',
            'wsp': 'http://schemas.xmlsoap.org/ws/2004/09/policy',
            'wsu':
            'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd',
            'wsa': 'http://www.w3.org/2005/08/addressing',
            'wst': 'http://schemas.xmlsoap.org/ws/2005/02/trust'
        }

        S = ElementMaker(
            annotate=False,
            namespace=NSMAP['s'],
            nsmap=NSMAP,
        )

        WSSE = ElementMaker(
            annotate=False,
            namespace=NSMAP['wsse'],
            nsmap=NSMAP,
        )

        WSP = ElementMaker(
            annotate=False,
            namespace=NSMAP['wsp'],
            nsmap=NSMAP,
        )

        WSU = ElementMaker(
            annotate=False,
            namespace=NSMAP['wsu'],
            nsmap=NSMAP,
        )

        WSA = ElementMaker(
            annotate=False,
            namespace=NSMAP['wsa'],
            nsmap=NSMAP,
        )

        WST = ElementMaker(
            annotate=False,
            namespace=NSMAP['wst'],
            nsmap=NSMAP,
        )

        envelope = S.Envelope(
            S.Header(
                WSA.Action(
                    'http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue',
                    mustUnderstand='1'),
                WSA.To(ad_url, mustUnderstand='1'),
                WSSE.Security(
                    WSSE.UsernameToken(
                        WSSE.Username(username),
                        WSSE.Password(password),
                    ), ),
            ),
            S.Body(
                WST.RequestSecurityToken(
                    WST.RequestType(
                        'http://schemas.xmlsoap.org/ws/2005/02/trust/Issue'),
                    WSP.AppliesTo(
                        WSA.EndpointReference(WSA.Address(auth_uri), ), ),
                    WST.KeyType(
                        'http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey'
                    ),
                    WST.TokenType('urn:oasis:names:tc:SAML:1.0:assertion'),
                ), ),
        )

        return etree.tostring(envelope)
Exemplo n.º 8
0
from functools import partial
from typing import List, Dict, Any

from genologics.entities import Artifact, Project, Container, Containertype, Researcher
from lxml import etree
from lxml.objectify import ElementMaker, ObjectifiedElement

SMP_MAKER = ElementMaker(namespace='http://genologics.com/ri/sample',
                         nsmap={
                             'smp': 'http://genologics.com/ri/sample',
                             'udf': 'http://genologics.com/ri/userdefined',
                         })
SMP_DETAILS = partial(SMP_MAKER, 'details')
SMP_SAMPLECREATION = partial(SMP_MAKER, 'samplecreation')

CON_MAKER = ElementMaker(namespace='http://genologics.com/ri/container',
                         nsmap={'con': 'http://genologics.com/ri/container'})
CON_DETAILS = partial(CON_MAKER, 'details')
CON_CONTAINER = partial(CON_MAKER, 'container')

UDF_MAKER = ElementMaker(namespace='http://genologics.com/ri/userdefined',
                         annotate=False)
UDF_FIELD = partial(UDF_MAKER, 'field')

ART_MAKER = ElementMaker(namespace='http://genologics.com/ri/artifact',
                         nsmap={'art': 'http://genologics.com/ri/artifact'})
ART_DETAILS = partial(ART_MAKER, 'details')
ART_ARTIFACT = partial(ART_MAKER, 'artifact')

XML = ElementMaker(annotate=False)
# Settings
from django.conf import settings
# 3rd party helpers
from requests.exceptions import HTTPError
from typing import Tuple
from lxml.objectify import ElementMaker
import json
# Views
from .utils import Storage
from .json_view import JsonView
# VDT BE Components
from vdt_python_sdk.views import vdt_python_sdk

E = ElementMaker(namespace="http://xml.vidispine.com/schema/vidispine", annotate=False,
                 nsmap={"vs": "http://xml.vidispine.com/schema/vidispine"})

# Unified responses:
responseBE = Tuple[Storage, int]

__author__ = 'anton'

""" CollectionsView
    do operations to several collections at a time
    
    PUT will search for collections
"""


class CollectionView(JsonView):
    def get(self, request, collection_id: str) -> responseBE:
        try:
Exemplo n.º 10
0
FVDL_NAMESPACE['RuleInfo'] = RuleInfoElement

FILTERTEMPLATE_NAMESPACE['FilterTemplate'] = FilterTemplateElement
FILTERTEMPLATE_NAMESPACE['Filter'] = FilterElement

AuditParser.set_element_class_lookup(
    AuditObjectifiedElementNamespaceClassLookup)

FVDLParser.set_element_class_lookup(FVDLObjectifiedElementNamespaceClassLookup)

FilterTemplateParser.set_element_class_lookup(
    FilterTemplateObjectifiedElementNamespaceClassLookup)

FVDL = ElementMaker(annotate=False,
                    namespace='xmlns://www.fortifysoftware.com/schema/FVDL',
                    nsmap={
                        None: 'xmlns://www.fortifysoftware.com/schema/FVDL',
                        'xsi': 'http://www.w3.org/2001/XMLSchema-instance'
                    })

Audit = ElementMaker(annotate=False,
                     namespace='',
                     nsmap={
                         None: 'xmlns://www.fortify.com/schema/AUDIT',
                         'xsi': 'http://www.w3.org/2001/XMLSchema-instance'
                     })


def parse(source, **kwargs):
    return objectify.parse(source, parser=FVDLParser, **kwargs)