Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

compare.py 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. """
  2. """
  3. # Created on 2013.05.31
  4. #
  5. # Author: Giovanni Cannata
  6. #
  7. # Copyright 2013 - 2018 Giovanni Cannata
  8. #
  9. # This file is part of ldap3.
  10. #
  11. # ldap3 is free software: you can redistribute it and/or modify
  12. # it under the terms of the GNU Lesser General Public License as published
  13. # by the Free Software Foundation, either version 3 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # ldap3 is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU Lesser General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU Lesser General Public License
  22. # along with ldap3 in the COPYING and COPYING.LESSER files.
  23. # If not, see <http://www.gnu.org/licenses/>.
  24. from ..protocol.convert import validate_attribute_value, prepare_for_sending
  25. from ..protocol.rfc4511 import CompareRequest, AttributeValueAssertion, AttributeDescription, LDAPDN, AssertionValue, ResultCode
  26. from ..operation.search import ava_to_dict
  27. from ..operation.bind import referrals_to_list
  28. def compare_operation(dn,
  29. attribute,
  30. value,
  31. auto_encode,
  32. schema=None,
  33. validator=None,
  34. check_names=False):
  35. # CompareRequest ::= [APPLICATION 14] SEQUENCE {
  36. # entry LDAPDN,
  37. # ava AttributeValueAssertion }
  38. ava = AttributeValueAssertion()
  39. ava['attributeDesc'] = AttributeDescription(attribute)
  40. ava['assertionValue'] = AssertionValue(prepare_for_sending(validate_attribute_value(schema, attribute, value, auto_encode, validator, check_names=check_names)))
  41. request = CompareRequest()
  42. request['entry'] = LDAPDN(dn)
  43. request['ava'] = ava
  44. return request
  45. def compare_request_to_dict(request):
  46. ava = ava_to_dict(request['ava'])
  47. return {'entry': str(request['entry']),
  48. 'attribute': ava['attribute'],
  49. 'value': ava['value']}
  50. def compare_response_to_dict(response):
  51. return {'result': int(response['resultCode']),
  52. 'description': ResultCode().getNamedValues().getName(response['resultCode']),
  53. 'dn': str(response['matchedDN']), 'message': str(response['diagnosticMessage']),
  54. 'referrals': referrals_to_list(response['referral'])}