Fix for python 2.6: add position indexes to format strings
authorWade Berrier <wberrier@gmail.com>
Sun, 20 Jan 2013 01:02:10 +0000 (18:02 -0700)
committerWade Berrier <wberrier@gmail.com>
Sun, 20 Jan 2013 01:07:22 +0000 (18:07 -0700)
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

mutt-ldap.py

index 94e44b9d894952664e32246df5f46ffb2bc87d8a..7029b60ec2a134a8115e5ae16c6de92d02af008d 100755 (executable)
@@ -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))