Skip to content

Commit

Permalink
Update uses of map() to use list/set comprehensions instead
Browse files Browse the repository at this point in the history
Updates style to modern Python idioms.
  • Loading branch information
Jon Dufresne committed Jan 5, 2018
1 parent 98c535b commit 3ae51ed
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Lib/ldap/controls/deref.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def decodeControlValue(self,encodedControlValue):
for deref_res in decodedValue:
deref_attr,deref_val,deref_vals = deref_res[0],deref_res[1],deref_res[2]
partial_attrs_dict = {
str(tv[0]): map(str,tv[1])
str(tv[0]): [str(v) for v in tv[1]]
for tv in deref_vals or []
}
try:
Expand Down
2 changes: 1 addition & 1 deletion Lib/ldap/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def filter_format(filter_template,assertion_values):
List or tuple of assertion values. Length must match
count of %s in filter_template.
"""
return filter_template % (tuple(map(escape_filter_chars,assertion_values)))
return filter_template % tuple(escape_filter_chars(v) for v in assertion_values)


def time_span_filter(
Expand Down
3 changes: 1 addition & 2 deletions Lib/ldap/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ def escape_str(escape_func,s,*args):
Applies escape_func() to all items of `args' and returns a string based
on format string `s'.
"""
escape_args = map(escape_func,args)
return s % tuple(escape_args)
return s % tuple(escape_func(v) for v in args)


def strf_secs(secs):
Expand Down
10 changes: 5 additions & 5 deletions Lib/ldap/modlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

def addModlist(entry,ignore_attr_types=None):
"""Build modify list for call of method LDAPObject.add()"""
ignore_attr_types = set(map(str.lower,ignore_attr_types or []))
ignore_attr_types = {v.lower() for v in ignore_attr_types or []}
modlist = []
for attrtype in entry.keys():
if attrtype.lower() in ignore_attr_types:
Expand Down Expand Up @@ -46,8 +46,8 @@ def modifyModlist(
List of attribute type names for which comparison will be made
case-insensitive
"""
ignore_attr_types = set(map(str.lower,ignore_attr_types or []))
case_ignore_attr_types = set(map(str.lower,case_ignore_attr_types or []))
ignore_attr_types = {v.lower() for v in ignore_attr_types or []}
case_ignore_attr_types = {v.lower() for v in case_ignore_attr_types or []}
modlist = []
attrtype_lower_map = {}
for a in old_entry.keys():
Expand All @@ -73,8 +73,8 @@ def modifyModlist(
replace_attr_value = len(old_value)!=len(new_value)
if not replace_attr_value:
if attrtype_lower in case_ignore_attr_types:
old_value_set = set(map(str.lower,old_value))
new_value_set = set(map(str.lower,new_value))
old_value_set = {v.lower() for v in old_value}
new_value_set = {v.lower() for v in new_value}
else:
old_value_set = set(old_value)
new_value_set = set(new_value)
Expand Down
2 changes: 1 addition & 1 deletion Lib/ldapurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def values(self):
]

def __str__(self):
return ','.join(map(str,self.values()))
return ','.join(str(v) for v in self.values())

def __repr__(self):
return '<%s.%s instance at %s: %s>' % (
Expand Down

0 comments on commit 3ae51ed

Please sign in to comment.