From: Wade Berrier Date: Sun, 20 Jan 2013 01:02:10 +0000 (-0700) Subject: Fix for python 2.6: add position indexes to format strings X-Git-Tag: v0.1~27^2~5 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a3b37d62a2c44533ecb9e2280e43da161f380ff3;p=mutt-ldap.git Fix for python 2.6: add position indexes to format strings Turns out that omitting the indexes is only supported in python >= 2.7 It's possible this script would work with python < 2.6 but the old format strings would be necessary --- diff --git a/mutt-ldap.py b/mutt-ldap.py index 94e44b9..7029b60 100755 --- a/mutt-ldap.py +++ b/mutt-ldap.py @@ -62,7 +62,7 @@ def connect(): protocol = 'ldap' if CONFIG.getboolean('connection', 'ssl'): protocol = 'ldaps' - url = '{}://{}:{}'.format( + url = '{0}://{1}:{2}'.format( protocol, CONFIG.get('connection', 'server'), CONFIG.get('connection', 'port')) @@ -88,12 +88,12 @@ def search(query, connection=None): post = '' if query: post = '*' - filterstr = u'(|{})'.format( - u' '.join([u'({}=*{}{})'.format(field, query, post) + filterstr = u'(|{0})'.format( + u' '.join([u'({0}=*{1}{2})'.format(field, query, post) for field in ['cn', 'displayName', 'uid', 'mail']])) query_filter = CONFIG.get('query', 'filter') if query_filter: - filterstr = u'(&({}){})'.format(query_filter, filterstr) + filterstr = u'(&({0}){1})'.format(query_filter, filterstr) r = connection.search_s( CONFIG.get('connection', 'basedn'), ldap.SCOPE_SUBTREE, @@ -120,5 +120,5 @@ if __name__ == '__main__': entries = search(query) addresses = list(itertools.chain( *[format_entry(e) for e in sorted(entries)])) - print('{} addresses found:'.format(len(addresses))) + print('{0} addresses found:'.format(len(addresses))) print('\n'.join(addresses))