Esempio n. 1
0
def university_add(request):
    if request.method == 'POST':
        cloudinary.config(
            cloud_name="universusimages",
            api_key="421689719673152",
            api_secret="E3pIIQne8HbWnxnJiyNm9NFGCxY"
        )
        client = Client('http://www.universus-webservice.ru/WebService1.asmx?WSDL')
        University = client.factory.create('University')
        auth = Element("AuthHeader").append((
            Element('Email').setText(request.session.get('email', '')),
        Element('Password').setText(request.session.get('password', '')),
        Attribute('xmlns', 'http://universus-webservice.ru/'))
        )
        client.set_options(soapheaders=auth)
        University['Id'] = 0;
        University['FullName'] = request.POST.get('full_name')
        University['ShortName'] = request.POST.get('short_name')
        University['Address'] = request.POST.get('address')
        University['WebSite'] = request.POST.get('web_site')
        University['Description'] = request.POST.get('description', '')
        logo_url = cloudinary.uploader.upload(
              request.FILES['logo'].read(),
              crop = 'fit',
              width = 500,
              height = 500
        )['url']
        University['LogoURL'] = logo_url
        client.service.addUniversity(University)
        return render(request, 'university/university_add.html', {'added' : True})
    return render(request, 'university/university_add.html', locals())


# ,eager=[{"width": 400, "height": 300, "crop": "fit"}]
Esempio n. 2
0
    def marshalled(self, context):
        userid = self.userid
        timestamp = rfc3339(datetime.datetime.now())
        secret = self.secret
        signature = sign(secret, timestamp + userid)
        auth = self.authfragment % locals()
        envelope = context.envelope

        #Set the right ns prefixes
        envelope.nsprefixes['ns1'] = envelope.nsprefixes['ns0']
        envelope.clearPrefix('ns0')

        #Add our auth to the header element
        header = envelope.getChild('Header')
        authns = Element('ns1:AuthenticationHeader')
        authns.append(Element('mktowsUserId').setText(self.userid))
        authns.append(Element('requestSignature').setText(signature))
        authns.append(Element('requestTimestamp').setText(timestamp))
        header.append(authns)

        #Set the proper body prefixes
        body = envelope.getChild('Body')
        body.prefix = 'SOAP-ENV'
        body.children[0].prefix = 'ns1'

        if self.debug:
            with open("/tmp/envelope.txt", "w") as f:
                f.write(envelope.str())
Esempio n. 3
0
 def xml(self):
     """
     Get xml representation of the object.
     @return: The root node.
     @rtype: L{Element}
     """
     root = Element('UsernameToken', ns=wssens)
     u = Element('Username', ns=wssens)
     u.setText(self.username)
     root.append(u)
     p = Element('Password', ns=wssens)
     p.setText(self.password)
     p.set(
         'Type', 'http://docs.oasis-open.org/wss/2004/01/'
         'oasis-200401-wss-username-token-profile-1.0#' +
         ('PasswordDigest' if self.digest else 'PasswordText'))
     root.append(p)
     if self.nonce is not None:
         n = Element('Nonce', ns=wssens)
         if self.digest:
             n.set(
                 'EncodingType', 'http://docs.oasis-open.org/wss/2004'
                 '/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary'
             )
             n.setText(b64encode(self.nonce))
         else:
             n.setText(self.nonce)
         root.append(n)
     if self.created is not None:
         n = Element('Created', ns=wsuns)
         n.setText(str(UTC(self.created)))
         root.append(n)
     return root
Esempio n. 4
0
    def xml(self):
        """
        Get xml representation of the object.
        @return: The root node.
        @rtype: L{Element}
        """
        root = Element('UsernameToken', ns=wssens)

        u = Element('Username', ns=wssens)
        u.setText(self.username)
        root.append(u)

        p = Element('Password', ns=wssens)
        p.setText(self.generate_digest())
        p.set(wspassd[0], wspassd[1])
        root.append(p)

        n = Element('Nonce', ns=wssens)
        n.setText(base64.encodestring(self.nonce)[:-1])
        n.set(wsenctype[0], wsenctype[1])
        root.append(n)

        n = Element('Created', ns=wsuns)
        n.setText(self.created)
        root.append(n)

        self.reset()
        return root
Esempio n. 5
0
 def xml(self):
     if self.digest and self.password is None:
         raise RuntimeError(
             "Cannot generate password digest without the password.")
     if self.autosetnonce:
         self.setnonce()
     if self.autosetcreated:
         self.setcreated()
     root = Element('UsernameToken', ns=WSSENS)
     u = Element('Username', ns=WSSENS)
     u.setText(self.username)
     root.append(u)
     if self.password is not None:
         password = self.password
         if self.digest:
             password = self.get_digest().decode('utf-8')
         p = Element('Password', ns=WSSENS)
         p.setText(password)
         p.set('Type', DIGEST_TYPE if self.digest else TEXT_TYPE)
         root.append(p)
     if self.nonce is not None:
         n = Element('Nonce', ns=WSSENS)
         n.setText(
             base64.b64encode(bytes(self.nonce, 'utf-8')).decode('utf-8'))
         n.set('EncodingType', BASE64_ENC_TYPE)
         root.append(n)
     if self.created:
         c = Element('Created', ns=WSUNS)
         c.setText(iso_utc(self.created))
         root.append(c)
     return root
Esempio n. 6
0
    def build_soap_client(self):
        if self.soap_endpoint is None or not self.soap_endpoint:
            self.soap_endpoint = self.get_soap_endpoint()

        self.soap_client = suds.client.Client(self.wsdl_file_url,
                                              faults=False,
                                              cachingpolicy=1)
        self.soap_client.set_options(location=self.soap_endpoint)
        self.soap_client.set_options(
            headers={'user-agent': 'FuelSDK-Python-v1.2.0'})

        if self.use_oAuth2_authentication == 'True':
            element_oAuth = Element('fueloauth',
                                    ns=('etns', 'http://exacttarget.com'))
            element_oAuth.setText(self.authToken)
            self.soap_client.set_options(soapheaders=(element_oAuth))
        else:
            element_oAuth = Element('oAuth',
                                    ns=('etns', 'http://exacttarget.com'))
            element_oAuthToken = Element('oAuthToken').setText(
                self.internalAuthToken)
            element_oAuth.append(element_oAuthToken)
            self.soap_client.set_options(soapheaders=(element_oAuth))

            security = suds.wsse.Security()
            token = suds.wsse.UsernameToken('*', '*')
            security.tokens.append(token)
            self.soap_client.set_options(wsse=security)
Esempio n. 7
0
    def build_soap_client(self):
        if self.endpoint is None:
            self.endpoint = self.determineStack()

        self.authObj = {'oAuth': {'oAuthToken': self.internalAuthToken}}
        self.authObj['attributes'] = {
            'oAuth': {
                'xmlns': 'http://exacttarget.com'
            }
        }

        self.soap_client = suds.client.Client(self.wsdl_file_url,
                                              faults=False,
                                              cachingpolicy=1)
        self.soap_client.set_options(location=self.endpoint)

        element_oAuth = Element('oAuth', ns=('etns', 'http://exacttarget.com'))
        element_oAuthToken = Element('oAuthToken').setText(
            self.internalAuthToken)
        element_oAuth.append(element_oAuthToken)
        self.soap_client.set_options(soapheaders=(element_oAuth))

        security = suds.wsse.Security()
        token = suds.wsse.UsernameToken(getattr(self, 'username', '*'),
                                        getattr(self, 'password', '*'))
        security.tokens.append(token)
        self.soap_client.set_options(wsse=security)
Esempio n. 8
0
def event_data(environ, start_response):
    form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
    event_name = str(form.getvalue("event"))
    event_date = str(form.getvalue("dt"))

    client = Client('http://localhost:7786/?wsdl')

    wsans = ('wsa', 'http://namespaces/sessionid')
    wsa = Element('wsa', ns=wsans)
    to_elem = Element('To', ns=wsans).setText('http://localhost:7786/?wsdl')
    from_elem = Element('From',
                        ns=wsans).setText('http://localhost:8080/?wsdl')
    replyto_elem = Element('ReplyTo',
                           ns=wsans).setText('http://localhost:7785/?wsdl')
    wsa.append(to_elem)
    wsa.append(from_elem)
    wsa.append(replyto_elem)
    client.set_options(
        soapheaders=wsa
    )  # Adding the created WSAddr headers to the soap request

    result = client.service.eventScheduler(event_name, event_date)

    #header = "<h1> Available Events </h1>"
    home_header = "<div><a href='/index.html'>Home</a></div>"
    start_response("200 OK", [('content-type', 'text/html')])
    return ["<html><body>", str(result), home_header, "</body></html>"]
Esempio n. 9
0
    def xml(self):
        """
		Get xml representation of the object.
		@return: The root node.
		@rtype: L{Element}
		"""
        root = Element('UsernameToken', ns=wssens)

        u = Element('Username', ns=wssens)
        u.setText(self.username)
        root.append(u)

        p = Element('Password', ns=wssens)
        p.setText(self.generate_digest().decode('ascii'))
        p.set(wspassd[0], wspassd[1])
        root.append(p)

        n = Element('Nonce', ns=wssens)
        nonce_bytes = self.nonce
        if not isinstance(self.nonce, bytes):
            nonce_bytes = self.nonce.encode('utf-8')

        n.setText((base64.encodebytes(nonce_bytes)[:-1]).decode('ascii'))
        n.set(wsenctype[0], wsenctype[1])
        root.append(n)

        n = Element('Created', ns=wsuns)
        n.setText(self.created)
        root.append(n)

        self.reset()
        return root
Esempio n. 10
0
    def _ensure_service(self):
        """Trying to add service if no one definied explicitly. EWS workaround."""
        if (self.services or not self.bindings or len(self.bindings) > 1
                or not self.bindings.keys()[0][0].startswith('Exchange')):
            return

        service = Element('service')
        service.set('name', 'ExchangeServices')

        port = Element('port', service)
        port.set('name', 'ExchangeServicePort')
        port.set('binding', self.bindings.keys()[0][0])

        address = Element('address', port)
        address.set('location', urljoin(self.url, 'exchange.asmx'))

        port.append(address)
        service.append(port)

        service = Factory.create(service, self)
        service.resolve(self)

        self.children.append(service)
        self.services.append(service)

        log.debug('Auto created service: %s', service)
Esempio n. 11
0
 def xml(self):
     """
     Get xml representation of the object.
     @return: The root node.
     @rtype: L{Element}
     """
     root = Element('UsernameToken', ns=wssens)
     u = Element('Username', ns=wssens)
     u.setText(self.username)
     root.append(u)
     p = Element('Password', ns=wssens)
     p.setText(self.password)
     root.append(p)
     if self.nonce is not None:
         n = Element('Nonce', ns=wssens)
         n.setText(self.nonce)
         root.append(n)
     if self.created is not None:
         n = Element('Created', ns=wsuns)
         n.setText(
             str(
                 UTC(self.created -
                     timedelta(microseconds=self.created.microsecond))))
         root.append(n)
     return root
Esempio n. 12
0
    def __init__(self, **kwargs):
        '''
        Constructor
        '''
        self.kwargs = kwargs
        if 'client' in kwargs:
            self.client = kwargs['client']
        else:
            options = kwargs.get('client_options', {})
            try:
                self.client = suds.client.Client(**options)

                if 'integrationcode' in kwargs:
                    headerURL = AUTOTASK_API_SOAP_HEADER_URL
                    if 'apiversion' in kwargs and kwargs['apiversion'] == 1.6:
                        headerURL = AUTOTASK_API_V1_6_SOAP_HEADER_URL
                    integrationCode = Element("AutotaskIntegrations") \
                        .append(Attribute('xmlns', headerURL)) \
                        .append(Element('IntegrationCode').setText( kwargs['integrationcode']))
                    self.client.set_options(soapheaders=integrationCode)
            except SAXParseException as err:
                # ATWS does not report welformed SOAP responses on authentication failures,
                # so a parseexception at this point is most likely an auth failure
                raise ATWSAuthException(
                    "AutoTask webservice call failed due to authentication or privilege settings"
                )
Esempio n. 13
0
    def make(self, authenticator: Authenticator):
        """Build and configure soap client"""
        if self._client is None:
            self._client = SoapClient(self._local_url, faults=False, cachingpolicy=0)

            if self.debug:
                logging.basicConfig(level=logging.INFO)
                logging.getLogger('suds.client').setLevel(logging.DEBUG)
                logging.getLogger('suds.transport').setLevel(logging.DEBUG)
                logging.getLogger('suds.xsd.schema').setLevel(logging.DEBUG)
                logging.getLogger('suds.wsdl').setLevel(logging.DEBUG)
            else:
                logging.getLogger('suds').setLevel(logging.INFO)

        # FIXME
        # Need make copy by suds.client.clone() method,
        # but now got this issue https://bitbucket.org/jurko/suds/issues/7/recursion-depth-reached
        # cl = self._client.clone()

        cl = self._client

        cl.set_options(location=authenticator.endpoint)

        security = Security()
        token = UsernameToken('*', '*')
        security.tokens.append(token)
        cl.set_options(wsse=security)

        element_oauth = Element('oAuth', ns=('etns', 'http://exacttarget.com'))
        element_oauth_token = Element('oAuthToken').setText(authenticator.auth_legacy_token)
        element_oauth.append(element_oauth_token)
        cl.set_options(soapheaders=[element_oauth])

        return cl
Esempio n. 14
0
    def build_soap_client(self):
        if self.soap_endpoint is None or not self.soap_endpoint:
            self.soap_endpoint = self.get_soap_endpoint()

        self.soap_client = suds.client.Client(self.wsdl_file_url,
                                              faults=False,
                                              cachingpolicy=1)
        self.soap_client.set_options(location=self.soap_endpoint)
        self.soap_client.set_options(
            headers={"user-agent": "FuelSDK-Python-v1.3.0"})

        if self.use_oAuth2_authentication == "True":
            element_oAuth = Element("fueloauth",
                                    ns=("etns", "http://exacttarget.com"))
            element_oAuth.setText(self.authToken)
            self.soap_client.set_options(soapheaders=(element_oAuth))
        else:
            element_oAuth = Element("oAuth",
                                    ns=("etns", "http://exacttarget.com"))
            element_oAuthToken = Element("oAuthToken").setText(
                self.internalAuthToken)
            element_oAuth.append(element_oAuthToken)
            self.soap_client.set_options(soapheaders=(element_oAuth))

            security = suds.wsse.Security()
            token = suds.wsse.UsernameToken("*", "*")
            security.tokens.append(token)
            self.soap_client.set_options(wsse=security)
Esempio n. 15
0
def my_groups(request):
    client = Client('http://www.universus-webservice.ru/WebService1.asmx?WSDL')
    auth = Element("AuthHeader").append(
        (Element('Email').setText(request.session.get('email', '')),
         Element('Password').setText(request.session.get('password', '')),
         Attribute('xmlns', 'http://universus-webservice.ru/')))
    client.set_options(soapheaders=auth)
    account = client.service.getAccount()
    groups = []
    if account.RoleId == 1:  # if student
        groups = client.service.getAllGroupsByStudentId(account.Id)
    if account.RoleId == 2:  # if teacher
        groups = client.service.getAllGroupsByTeacherId(account.Id)
    data = []
    dept = []
    uni = []
    if groups:
        if len(groups.StudentGroup) == 1:
            return HttpResponseRedirect('/studentgroup_body/show/' +
                                        str(groups.StudentGroup[0].Id) + '/')
        for group in groups.StudentGroup:
            d = client.service.getDepartmentByIdLite(group.DepartmentID)
            dept.append(d)
            uni.append(client.service.getUniversityByIdLite(d.UniversityId))
        data = zip(groups.StudentGroup, dept, uni)
    return render(request, 'student_group/group_list.html', {'data': data})
Esempio n. 16
0
File: wsse.py Progetto: ichux/suds
 def xml(self):
     """
     Get xml representation of the object.
     @return: The root node.
     @rtype: L{Element}
     """
     root = Element('UsernameToken', ns=wssens)
     u = Element('Username', ns=wssens)
     u.setText(self.username)
     root.append(u)
     p = Element('Password', ns=wssens)
     p.setText(self.password)
     if self.password_digest:
         p.set("Type", wsdigest)
         p.setText(self.password_digest)
     else:
         p.set("Type", wstext)
     root.append(p)
     if self.nonce is not None:
         n = Element('Nonce', ns=wssens)
         if self.nonce_has_encoding:
             n.set("EncodingType", nonce_encoding_type)
         n.setText(self.nonce)
         root.append(n)
     if self.created is not None:
         n = Element('Created', ns=wsuns)
         n.setText(str(DateTime(self.created)))
         root.append(n)
     return root
Esempio n. 17
0
 def resolve(self, definitions):
     """
     Resolve named references to other WSDL objects.
     @param definitions: A definitions object.
     @type definitions: L{Definitions}
     """
     for op in self.operations.values():
         if op.input is None:
             op.input = Message(Element('no-input'), definitions)
         else:
             qref = qualify(op.input, self.root, definitions.tns)
             msg = definitions.messages.get(qref)
             if msg is None:
                 raise Exception("msg '%s', not-found" % op.input)
             else:
                 op.input = msg
         if op.output is None:
             op.output = Message(Element('no-output'), definitions)
         else:
             qref = qualify(op.output, self.root, definitions.tns)
             msg = definitions.messages.get(qref)
             if msg is None:
                 raise Exception("msg '%s', not-found" % op.output)
             else:
                 op.output = msg
         for f in op.faults:
             qref = qualify(f.message, self.root, definitions.tns)
             msg = definitions.messages.get(qref)
             if msg is None:
                 raise Exception, "msg '%s', not-found" % f.message
             f.message = msg
Esempio n. 18
0
def init_client(faults=True):
    ENTREPRISE_WSDL = getattr(settings,     'SALESFORCE_ENTERPRISE_WSDL')
    DJANGO_WSDL = getattr(settings,         'SALESFORCE_DJANGO_WSDL')
    SALESFORCE_ENDPOINT = getattr(settings, 'SALESFORCE_ENDPOINT')
    
    SALESFORCE_USER = getattr(settings,     'SALESFORCE_USER')
    SALESFORCE_PASS = getattr(settings,     'SALESFORCE_PASS')
    SALESFORCE_TOKEN = getattr(settings,    'SALESFORCE_TOKEN')
    
    # Use the entreprise login to get a session id
    entreprise_client = Client(ENTREPRISE_WSDL)
    #entreprise_client.wsdl.url = SALESFORCE_ENDPOINT
    
    login_result = entreprise_client.service.login(SALESFORCE_USER, 
                                                   SALESFORCE_PASS+SALESFORCE_TOKEN)
    

    # our client specific methods are in this specific       
   
    # NOTE we have to create the endpoint url using values from the serverUrl in the loginResponse plus 
    # the djangoAdapter schema
    
    options = urlparse(login_result.serverUrl)
    
    #DJANGO_SF_ENDPOINT = '%s://%s/services/Soap/class/dJangoAdapter' % (options.scheme, options.netloc)
    
    django_client = Client(DJANGO_WSDL, location = SALESFORCE_ENDPOINT, faults=faults)
         
    session_name_space = ('djan', 'http://soap.sforce.com/schemas/class/dJangoAdapter')
    session = Element('sessionId').setText(login_result.sessionId)
    wrapper = Element('SessionHeader')
    wrapper.append(session)
    
    django_client.set_options(soapheaders=wrapper)
    return django_client
Esempio n. 19
0
    def xml(self):
        usernametoken = Element('UsernameToken', ns=wssens)

        username = Element('Username', ns=wssens)
        username.setText(self.username)
        usernametoken.append(username)

        password = Element('Password', ns=wssens)
        s = hashlib.sha1()
        s.update(self.nonce)
        s.update(self._print_datetime(self.created).encode('utf-8'))
        s.update(self.password.encode('utf-8'))
        password.setText(b64encode(s.digest()).decode('utf-8'))
        password.set(
            'Type', 'http://docs.oasis-open.org/wss/2004/01/'
            'oasis-200401-wss-username-token-profile-1.0'
            '#PasswordDigest')
        usernametoken.append(password)

        nonce = Element('Nonce', ns=wssens)
        nonce.setText(b64encode(self.nonce).decode('utf-8'))
        nonce.set(
            'EncodingType', 'http://docs.oasis-open.org/wss/2004'
            '/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary')
        usernametoken.append(nonce)

        created = Element('Created', ns=wsuns)
        created.setText(self._print_datetime(self.created))
        usernametoken.append(created)

        return usernametoken
Esempio n. 20
0
def university(request, university_id):
    client = Client('http://www.universus-webservice.ru/WebService1.asmx?WSDL')
    auth = Element("AuthHeader").append((
        Element('Email').setText(request.session.get('email', '')),
        Element('Password').setText(request.session.get('password', '')),
        Attribute('xmlns', 'http://universus-webservice.ru/'))
    )
    client.set_options(soapheaders=auth)
    if request.method == 'POST':
        data = request.body.decode('utf-8')
        uni = json.loads(data)
        univer = client.service.getUniversityByIdLite(university_id)
        univer.FullName = uni['FullName']
        univer.ShortName = uni['ShortName']
        univer.Description = uni['Description']
        univer.Address = uni['Address']
        univer.WebSite = uni['WebSite']
        result = client.service.updateUniversity(univer)
    university = client.service.getUniversityById(int(university_id))
    departments = client.service.getAllDepartmentsByUniversityIdLite(int(university_id))
    role_id = request.session.get('role_id', 0)
    return render(request, 'university/university.html', {
        'university': university,
        'departments': departments.Department if departments else None,
        'role_id': role_id})
Esempio n. 21
0
    def payuMeaGetTransactionApiCall(self, args):

        #urlToQuery = 'https://secure.payu.co.za/service/PayUAPI?wsdl'
        if (args['store']['environment'] == 'staging'):
            urlToQuery = 'https://staging.payu.co.za/service/PayUAPI?wsdl'
        else:
            urlToQuery = 'https://secure.payu.co.za/service/PayUAPI?wsdl'
        plugin = MyPlugin()
        client = Client(urlToQuery, plugins=[plugin])
        #client = Client(urlToQuery, faults=False)
        #------------------------------------- CREATING CUSTOM HEADER--------------------------------------
        wsse = (
            'wsse',
            'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'
        )

        mustAttributeSecurity = Attribute('SOAP-ENV:mustUnderstand', '1')
        addressAttributeSecurity = Attribute(
            'xmlns:wsse',
            'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'
        )
        AttributeUsernameToken1 = Attribute('wsu:Id', 'UsernameToken-9')
        addressAttributeUsernameToken = Attribute(
            'xmlns:wsu',
            'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'
        )
        addressAttributePassword = Attribute(
            'Type',
            'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'
        )

        msgUsername = Element('Username',
                              ns=wsse).setText(args['store']['soapUsername'])
        msgPassword = Element('Password', ns=wsse).setText(
            args['store']['soapPassword']).append(addressAttributePassword)

        msgUsernameToken = Element('UsernameToken', ns=wsse)
        msgUsernameToken.append(AttributeUsernameToken1)
        msgUsernameToken.append(addressAttributeUsernameToken)
        msgUsernameToken.insert(msgPassword).insert(msgUsername)

        msgSecurity = Element('Security', ns=wsse).addPrefix(
            p='SOAP-ENC', u='http://www.w3.org/2003/05/soap-encoding')
        msgSecurity.append(mustAttributeSecurity)
        msgSecurity.append(addressAttributeSecurity)
        msgSecurity.insert(msgUsernameToken)

        client.set_options(soapheaders=[msgSecurity])

        #------------------------------------- CREATING SOAP CALL DETAILS HERE--------------------------------------
        transaction = {}
        transaction['Api'] = 'ONE_ZERO'
        transaction['Safekey'] = args['store']['safekey']
        transaction['AdditionalInformation'] = args['additionalInformation']
        #------------------------------------- DOING SOAP CALL HERE--------------------------------------
        try:
            setTransaction = client.service.getTransaction(**transaction)
        except Exception, e:
            print_exc()
Esempio n. 22
0
 def GenerateSoapHeader(self):
     wataniyaAuth = ('wataniya', 'http://osb.wataniya.com')
     token = Element('auth', ns=wataniyaAuth)
     username = Element('username').setText(self.username)
     password = Element('password').setText(self.password)
     token.append(username)
     token.append(password)
     return token
Esempio n. 23
0
 def get_stock_xml(self, products):
     stock = Element("stock")
     for product in products:
         item = Element("item")
         stock.append(item)
         sku = Element("sku").setText(product.barcode)
         item.append(sku)
     return stock
Esempio n. 24
0
 def _build_mouser_header(self):
     header_partnerid = Element('PartnerID').setText(self._api_key)
     header_accountinfo = Element('AccountInfo')
     header_accountinfo.insert(header_partnerid)
     header = Element('MouserHeader')
     header.insert(header_accountinfo)
     header.set('xmlns', 'http://api.mouser.com/service')
     return header
Esempio n. 25
0
 def xml(self):
     root = Element("Timestamp", ns=wsuns)
     created = Element('Created', ns=wsuns)
     created.setText(str(UTC(self.created)))
     expires = Element('Expires', ns=wsuns)
     expires.setText(str(UTC(self.expires)))
     root.append(created)
     root.append(expires)
     return root
Esempio n. 26
0
 def _setupNationalRailClient(self):
     logging.info('Setting up national rail client')
     token = Element('AccessToken', ns=DARWIN_WEBSERVICE_NAMESPACE)
     val = Element('TokenValue', ns=DARWIN_WEBSERVICE_NAMESPACE)
     val.setText(DARWIN_TOKEN)
     token.append(val)
     client = Client(LDBWS_URL)
     client.set_options(soapheaders=token)
     self.nationalRailClient = client
Esempio n. 27
0
 def __init__(self, client, username, password):
     tns = ('tns', 'http://services.tripolis.com/')
     self.__auth_info = Element('authInfo', ns=tns)
     client = Element('client').setText(client)
     username = Element('username').setText(username)
     password = Element('password').setText(password)
     self.__auth_info.append(client)
     self.__auth_info.append(username)
     self.__auth_info.append(password)
Esempio n. 28
0
    def createHeaders(self):
        ssn = [
            Element('apikey').setText(self.apikey),
            Element('username').setText(self.username),
            Element('password').setText(self.password)
        ]

        self._authClient = Client(self.WSDL_AUTH_URL, soapheaders=ssn)
        self._signClient = Client(self.WSDL_SIGN_URL, soapheaders=ssn)
        self._archClient = Client(self.WSDL_ARCH_URL, soapheaders=ssn)
Esempio n. 29
0
 def getItem(self, item_id, viewName=None):
     """ Return all list items without further filtering """
     query0 = Element('ns1:query')
     query = Element('Query')
     query0.append(query)
     where = Element('Where')
     query.append(where)
     eq = Element('Eq')
     where.append(eq)
     fieldref = Element('FieldRef').append(
         Attribute('Name', self.primary_key))
     value = Element('Value').append(Attribute('Type',
                                               'Number')).setText(item_id)
     eq.append(fieldref)
     eq.append(value)
     viewfields = Element('ViewFields')
     viewfields.append(
         Element('FieldRef').append(Attribute('Name', self.primary_key)))
     queryOptions = Element('queryOptions')
     result = self.service.GetListItems(self.list_id,
                                        viewName=viewName or self.viewName,
                                        query=query0,
                                        viewFields=viewfields,
                                        queryOptions=queryOptions,
                                        rowLimit=1)
     if int(result.listitems.data._ItemCount) > 0:
         return self._serializeListItem(result.listitems.data.row)
     return []
Esempio n. 30
0
 def xml(self):
     self.created = datetime.utcnow()
     root = Element("Timestamp", ns=WSUNS)
     created = Element('Created', ns=WSUNS)
     created.setText(iso_utc(self.created))
     root.append(created)
     if self.validity is not None:
         self.expires = self.created + timedelta(seconds=self.validity)
         expires = Element('Expires', ns=WSUNS)
         expires.setText(iso_utc(self.expires))
         root.append(expires)
     return root