1- #!/usr/bin/env python
1+ #!/usr/bin/env python3
22# -*- coding: utf-8 -*-
33
44"""
@@ -21,13 +21,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2121import sys
2222import ldap
2323import logging
24- import psycopg2
25- import psycopg2 .extras # noqa: F401
2624
2725LOG_FILENAME = '/tmp/ast4ucs-number2name.log'
2826
2927# read options from config file
30- config = open ("/etc/asterisk4ucs.ldapconfig" ).read ().split ( " \n " )
28+ config = open ("/etc/asterisk4ucs.ldapconfig" ).read ().splitlines ( )
3129LDAP_IP = config [0 ]
3230LDAP_SEARCH_BASE = config [1 ]
3331ADMIN_DN = config [2 ]
@@ -44,7 +42,7 @@ logging.basicConfig(
4442)
4543
4644# Read and ignore AGI environment (read until blank line)
47- env = dict ()
45+ env = {}
4846while len (sys .argv ) < 2 :
4947 line = sys .stdin .readline ().strip ()
5048 if not line :
@@ -92,25 +90,24 @@ if not result:
9290 sys .exit (0 )
9391
9492result = result [0 ][1 ]
95- unwrap = lambda x : x [0 ] if x else None # noqa: E731
9693
97- orga = unwrap ( result .get ('o' ) )
98- last = unwrap ( result .get ('ast4ucsContactLastname' ) )
99- first = unwrap ( result .get ('ast4ucsContactFirstname' ) )
94+ orga = result .get ('o' , [ b'' ])[ 0 ]. decode ( 'UTF-8' )
95+ last = result .get ('ast4ucsContactLastname' , [ b'' ])[ 0 ]. decode ( 'UTF-8' )
96+ first = result .get ('ast4ucsContactFirstname' , [ b'' ])[ 0 ]. decode ( 'UTF-8' )
10097
10198if first and last :
10299 name = "%s %s" % (first , last )
103100elif last :
104101 name = last
105102else :
106- name = first # could be string or None
103+ name = first
107104
108105if orga and name :
109106 cn = "%s (%s)" % (name , orga )
110107elif orga :
111108 cn = orga
112109else :
113- cn = name # could be string or None
110+ cn = name
114111
115112if not cn :
116113 logging .info ("Kontakt hat weder Name noch Organisation, exit" )
@@ -135,7 +132,7 @@ for rule in rules:
135132
136133# Namen an Asterisk senden
137134logging .info ("Setze Variable CALLERID auf " + cname )
138- #cname = unicode( cname, 'utf-8') .encode('iso-8859-1')
135+ #cname = cname.encode('iso-8859-1')
139136sys .stdout .write ('SET CALLERID "%s"\n ' % (cname ))
140137sys .stdout .flush ()
141138
0 commit comments