Skip to content

Commit

Permalink
module ldif now uses functions b64encode() and b64decode()
Browse files Browse the repository at this point in the history
  • Loading branch information
stroeder authored and Petr Viktorin committed Nov 22, 2017
1 parent e61079a commit 270519e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Lib/
* method .decodeControlValue() of SSSResponseControl and VLVResponseControl
does not set class attribute result_code anymore
* always use bytes() for UUID() constructor in ldap.syncrepl
* module ldif now uses functions b64encode() and b64decode()

Tests/
* scripts do not directly call SlapdTestCase.setUpClass() anymore
Expand Down
11 changes: 7 additions & 4 deletions Lib/ldif.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
'LDIFCopy',
]

import urlparse,urllib,base64,re
import urlparse
import urllib
import re
from base64 import b64encode, b64decode

try:
from cStringIO import StringIO
Expand Down Expand Up @@ -139,7 +142,7 @@ def _unparseAttrTypeandValue(self,attr_type,attr_value):
"""
if self._needs_base64_encoding(attr_type,attr_value):
# Encode with base64
self._unfold_lines(':: '.join([attr_type,base64.encodestring(attr_value).replace('\n','')]))
self._unfold_lines(':: '.join([attr_type, b64encode(attr_value).replace('\n','')]))
else:
self._unfold_lines(': '.join([attr_type,attr_value]))
return # _unparseAttrTypeandValue()
Expand Down Expand Up @@ -277,7 +280,7 @@ def __init__(
self.records_read = 0
self.changetype_counter = {}.fromkeys(CHANGE_TYPES,0)
# Store some symbols for better performance
self._base64_decodestring = base64.decodestring
self._b64decode = b64decode
# Read very first line
try:
self._last_line = self._readline()
Expand Down Expand Up @@ -346,7 +349,7 @@ def _next_key_and_value(self):
attr_value = unfolded_line[colon_pos+2:].lstrip()
elif value_spec=='::':
# attribute value needs base64-decoding
attr_value = self._base64_decodestring(unfolded_line[colon_pos+2:])
attr_value = self._b64decode(unfolded_line[colon_pos+2:])
elif value_spec==':<':
# fetch attribute value from URL
url = unfolded_line[colon_pos+2:].strip()
Expand Down

0 comments on commit 270519e

Please sign in to comment.