Skip to content
This repository was archived by the owner on Mar 21, 2019. It is now read-only.

Test: schema: test_urlfetch from file #81

Closed
wants to merge 111 commits into from
Closed

Test: schema: test_urlfetch from file #81

wants to merge 111 commits into from

Conversation

MartinBasti
Copy link

Testing of attributetypes and objectclasses parsing from file

Fixes: #79

I inspired by test_tokenizer, and I'm not sure if that was the best idea, I miss asserts there, so let me know if that test should be done in different way.

@MartinBasti
Copy link
Author

Well obliviously it needs some better error reporting, asserts instead of print? (see #82)

@encukou
Copy link
Contributor

encukou commented Feb 14, 2017

This belongs to python-ldap, so it'll need to be converted to the style that will be used there.

When test_tokenizer et al. are updated there, I'll modify this patch to match and submit it.

@MartinBasti
Copy link
Author

Thanks, let me know if any help with this is needed

@encukou
Copy link
Contributor

encukou commented Feb 14, 2017

I've added Samba's sambaHomePath attribute type to the test to also check for an issue #58 solves.

stroeder and others added 26 commits April 26, 2017 16:52
Those were introduced in 3c46166; however, we strive to be absolutely
explicit on the return type of our functions:

- with `bytes_mode=True` (legacy behavior), we use bytes (Py2 'str')
  on every Distinguished Name like attributes
- with `bytes_mode=False` or under Py3, we always use text (Py2
  'unicode' or Py3 'str') for those attributes

=> `ldap.search_subschemasubentry_s` should return values according to
   those rules.
This is a backport from python-ldap 2.4.37

Fixes: #90
This is a backport from python-ldap 2.4.39+

Fixes: #90
_unbytesify_value is a no-op in Python 3, so add a new function that actually
decodes bytes to text when bytes_mode is set to False, reagrdless of Python
version.

To match the other bytesify functions, the type assertion is only run under
Python 2.
Rework how pyldap handles converting Unicode to UTF-8 encoded byte-strings to
avoid inconsistencies between Python 2 and Python 3 in how Python's C API
handles the "s" format unit. The inconsistencies result in Python 2 raising
UnicodeEncodeErrors when Unicode strings with non-ASCII characters are passed
to the C bindings.

- In Python 3, the "s" format expects the argument to be a unicode string, and
  it encodes it using UTF-8 (unconditionally).
- In Python 2, the "s" format tries to encode unicode strings using the
  default encoding (sys.getdefaultencoding(), which defaults to 'ascii').

Avoid these inconsistencies (while preserving the warnings/error handling) by
explicitly encoding values to UTF-8 bytes, instead of passing passing unicode
objects to C. Doing this addresses the issue, while still relying on Python
for GC/memory management. The alternatives (e.g. using the "es" format unit)
would require more invasive changes in the C bindings, including explicit
memory management.

Also update `attrs_from_List` to align with these changes:

- In Python 2, assume a sequence of bytes objects (encoded to UTF-8)
- In Python 3, assume a sequence of string (Unicode) objects and rely on
  Python to encode to UTF-8 and handle the memory allocations.

This simplification of attrs_from_List also fixes a leak of the bytes objects;
previously, the new object returned by PyUnicode_AsUTF8String was leaked.

Fixes #4
Fixes #39
Fixes #54
The original comparison made python3 sad with
"BytesWarning: Comparison between bytes and string"
warning.
PEP8-styling accidentally snuck into parts of _unbytesify_result.  Also
comment a commented-out bind test.
Remove usage of dict.keys().pop().

Closes #84.
Improve unicode handling in Python 2
- Improve docstrings
- Rename helpers to clarify their role
- Merge _bytesify_value and _unbytesify_encoded_text
A call to 'result4' returns properly typed entries for Py3, we have to
convert it back to bytes only under Py2 bytes_mode.

Converting from bytes to text should only occur when decoding attribute
*values*.
@encukou
Copy link
Contributor

encukou commented Jun 19, 2017

I've updated this to the current master, so the tests still pass. Sorry for what it looks like on GitHub.

@MartinBasti
Copy link
Author

Ok, no problem

@tiran
Copy link
Contributor

tiran commented Nov 29, 2017

I have written tests in upstream PR python-ldap/python-ldap#52

@tiran tiran closed this Nov 29, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy