def _next_key_and_value(self): """ Parse a single attribute type and value pair from one or more lines of LDIF data Returns attr_type (text) and attr_value (bytes) """ # Reading new attribute line unfolded_line = self._unfold_lines() # Ignore comments which can also be folded while unfolded_line and unfolded_line[0]=='#': unfolded_line = self._unfold_lines() if not unfolded_line: return None,None if unfolded_line=='-': return '-',None try: colon_pos = unfolded_line.index(':') except ValueError as e: raise ValueError('no value-spec in %s' % (repr(unfolded_line))) attr_type = unfolded_line[0:colon_pos] # if needed attribute value is BASE64 decoded value_spec = unfolded_line[colon_pos:colon_pos+2] if value_spec==': ': attr_value = unfolded_line[colon_pos+2:].lstrip() # All values should be valid ascii; we support UTF-8 as a # non-official, backwards compatibility layer. attr_value = attr_value.encode('utf-8') elif value_spec=='::': # attribute value needs base64-decoding # base64 makes sens only for ascii attr_value = unfolded_line[colon_pos+2:] attr_value = attr_value.encode('ascii') attr_value = self._base64_decodestring(attr_value) elif value_spec==':<': # fetch attribute value from URL url = unfolded_line[colon_pos+2:].strip() attr_value = None if self._process_url_schemes: u = urlparse(url) if u[0] in self._process_url_schemes: attr_value = urllib.urlopen(url).read() else: # All values should be valid ascii; we support UTF-8 as a # non-official, backwards compatibility layer. attr_value = unfolded_line[colon_pos+1:].encode('utf-8') return attr_type,attr_value
def _next_key_and_value(self): """ Parse a single attribute type and value pair from one or more lines of LDIF data Returns attr_type (text) and attr_value (bytes) """ # Reading new attribute line unfolded_line = self._unfold_lines() # Ignore comments which can also be folded while unfolded_line and unfolded_line[0] == '#': unfolded_line = self._unfold_lines() if not unfolded_line: return None, None if unfolded_line == '-': return '-', None try: colon_pos = unfolded_line.index(':') except ValueError as e: raise ValueError('no value-spec in %s' % (repr(unfolded_line))) attr_type = unfolded_line[0:colon_pos] # if needed attribute value is BASE64 decoded value_spec = unfolded_line[colon_pos:colon_pos + 2] if value_spec == ': ': attr_value = unfolded_line[colon_pos + 2:].lstrip() # All values should be valid ascii; we support UTF-8 as a # non-official, backwards compatibility layer. attr_value = attr_value.encode('utf-8') elif value_spec == '::': # attribute value needs base64-decoding # base64 makes sens only for ascii attr_value = unfolded_line[colon_pos + 2:] attr_value = attr_value.encode('ascii') attr_value = self._b64decode(attr_value) elif value_spec == ':<': # fetch attribute value from URL url = unfolded_line[colon_pos + 2:].strip() attr_value = None if self._process_url_schemes: u = urlparse(url) if u[0] in self._process_url_schemes: attr_value = urlopen(url).read() else: # All values should be valid ascii; we support UTF-8 as a # non-official, backwards compatibility layer. attr_value = unfolded_line[colon_pos + 1:].encode('utf-8') return attr_type, attr_value
def _next_key_and_value(self): """ Parse a single attribute type and value pair from one or more lines of LDIF data """ # Reading new attribute line unfolded_line = self._unfold_lines() # Ignore comments which can also be folded while unfolded_line and unfolded_line[0] == '#': unfolded_line = self._unfold_lines() if not unfolded_line: return None, None if unfolded_line == '-': return '-', None colon_pos = unfolded_line.index(':') attr_type = unfolded_line[0:colon_pos] # if needed attribute value is BASE64 decoded value_spec = unfolded_line[colon_pos:colon_pos + 2] if value_spec == ': ': attr_value = unfolded_line[colon_pos + 2:].lstrip() if not isinstance(unfolded_line, bytes): attr_value = attr_value.encode('utf-8') elif value_spec == '::': # attribute value needs base64-decoding attr_value = unfolded_line[colon_pos + 2:] if not isinstance(attr_value, bytes): attr_value = attr_value.encode('ascii') attr_value = base64.decodestring(attr_value) elif value_spec == ':<': # fetch attribute value from URL url = unfolded_line[colon_pos + 2:].strip() attr_value = None if self._process_url_schemes: u = urlparse(url) if u[0] in self._process_url_schemes: attr_value = urllib.urlopen(url).read() else: attr_value = unfolded_line[colon_pos + 1:].encode('utf-8') return attr_type, attr_value
def _next_key_and_value(self): """ Parse a single attribute type and value pair from one or more lines of LDIF data """ # Reading new attribute line unfolded_line = self._unfold_lines() # Ignore comments which can also be folded while unfolded_line and unfolded_line[0]=='#': unfolded_line = self._unfold_lines() if not unfolded_line: return None,None if unfolded_line=='-': return '-',None colon_pos = unfolded_line.index(':') attr_type = unfolded_line[0:colon_pos] # if needed attribute value is BASE64 decoded value_spec = unfolded_line[colon_pos:colon_pos+2] if value_spec==': ': attr_value = unfolded_line[colon_pos+2:].lstrip() if not isinstance(unfolded_line, bytes): attr_value = attr_value.encode('utf-8') elif value_spec=='::': # attribute value needs base64-decoding attr_value = unfolded_line[colon_pos+2:] if not isinstance(attr_value, bytes): attr_value = attr_value.encode('ascii') attr_value = base64.decodestring(attr_value) elif value_spec==':<': # fetch attribute value from URL url = unfolded_line[colon_pos+2:].strip() attr_value = None if self._process_url_schemes: u = urlparse(url) if u[0] in self._process_url_schemes: attr_value = urllib.urlopen(url).read() else: attr_value = unfolded_line[colon_pos+1:].encode('utf-8') return attr_type,attr_value