Code Monkey home page Code Monkey logo

Comments (7)

etingof avatar etingof commented on June 9, 2024

Hi Giovanni!

I think this is the same regression as we discussed lately. Can you please add the .hasValue() check in addition to is None you have like this:

    'saslCreds': bytes(response['serverSaslCreds']) if response['serverSaslCreds'] is not None and response['serverSaslCreds'].hasValue() else None}

I'm here to fix whatever regression the latest release may have caused. %-\

from pyasn1.

cannatag avatar cannatag commented on June 9, 2024

I'm adding a lot of if request['xxx'] is not None and request['xxx'].hasValue() else None to the ldap3 code. I think that there should be a better way to do this. With the previous pyasn1 versions the uninitialized value were all None. There is a way to have the same behaviour?

from pyasn1.

etingof avatar etingof commented on June 9, 2024

Well, I'm not sure how to handle this in a backward compatible way... The ultimate goal is to make the whole API more "automatic" and compact. For example, imagine a nested structure like this:

    LDAPMessage ::= SEQUENCE {
             messageID       MessageID,
             protocolOp      CHOICE {
                  bindRequest           BindRequest,
                  ...
                  intermediateResponse  IntermediateResponse },
             controls       [0] Controls OPTIONAL }

    BindRequest ::= [APPLICATION 0] SEQUENCE {
             version                 INTEGER (1 ..  127),
             name                    LDAPDN,
             authentication          AuthenticationChoice }

Now you want to initialize it. With previous pyasn1 API you could only do that in multiple steps, from outer to inner elements:

    ldap = LDAPMessage()
    ldap.setComponentByName('protocolOp')  # this instantiates CHOICE
    ldap['protocolOp'].setComponentByName('bindRequest')  # this instantiates BindRequest
    ldap['protocolOp']['bindRequest'].setComponentByName('version', 1)  # this instantiates INTEGER

The new API is more compact and intuitive:

    ldap = LDAPMessage()
    ldap['protocolOp']['bindRequest']['version'] = 1

The compact version can only work if ldap['protocolOp'] returns CHOICE instance, not None for uninitialized field.

WDIT? Your advise is much appreciated!

BTW, if you make pyasn1 >= 0.3.1 a requirement, you could omit the request['xxx'] is not None part and leave just request['xxx'] if request['xxx'].isValue else None . The is not None part is only required if you want the code to work with both pyasn1 API flavours.

from pyasn1.

cannatag avatar cannatag commented on June 9, 2024

Thanks Ilya, I've been able to fix all errors in ldap3 tests. Now my codes works with pyasn1 froom version 0.1.8 up to 0.3.1. Prior to 0.1.8 the hasValue() method is absent.

from pyasn1.

etingof avatar etingof commented on June 9, 2024

Thank you, Giovanni! And sorry for the trouble. ;)

I'd also appreciate if you run your test with the current pyasn1 master (which is about to be released as 0.3.2). I do not expect any breakage there though.

Prior to 0.1.8 the hasValue() method is absent.

I believe 0.1.8 is so much historical now days. I can potentially propose a compatibility measure to make ldap3 running with older pysn1. Let me know if you need that.

from pyasn1.

cannatag avatar cannatag commented on June 9, 2024

I've tested the 0.3.2 branch, everything is ok, all tests pass!

from pyasn1.

etingof avatar etingof commented on June 9, 2024

Great, thank you!

from pyasn1.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.