Catch the case where attributes that are not declared as an array value have more...
[mirror/userdir-ldap.git] / UDLdap.py
index 447368d..9f8a0fd 100644 (file)
--- a/UDLdap.py
+++ b/UDLdap.py
@@ -1,5 +1,6 @@
 import ldap
 import time
+import userdir_ldap
 
 class Account:
     array_values = ['keyFingerPrint']
@@ -30,7 +31,10 @@ class Account:
             if key in self.array_values:
                 return self.attributes[key]
             elif key in self.int_values:
-                return int(self.attributes[key][0])
+                if len(self.attributes[key]) == 1:
+                    return int(self.attributes[key][0])
+                else:
+                    raise ValueError, 'non-array value has not exactly one value'
             else:
                 return self.attributes[key][0]
         elif key in self.defaults:
@@ -62,6 +66,11 @@ class Account:
     def numkeys(self):
         return len(self['keyFingerPrint'])
 
+    def latitude_dec(self, anonymized=False):
+        return userdir_ldap.DecDegree(self['latitude'], anonymized)
+    def longitude_dec(self, anonymized=False):
+        return userdir_ldap.DecDegree(self['longitude'], anonymized)
+
     def verbose_status(self):
         status = []
         status.append('mail: %s'  %(['disabled', 'active'][ self.has_mail() ]))