Commits

Anonymous committed a431c1c

Deduplicates code.

  • Participants
  • Parent commits 4e358b4

Comments (0)

Files changed (1)

File adu/generator.py

 from datatypes import to_adu
 
 def _writeline(fp, data):
-    for field in ADUFORMAT:
-        name=field[0]
-        length, datatype=field[2:4]
-        value=to_adu(datatype, data.get(name), length)
-        value=value.rjust(length)
-        if len(value)!=length:
-            raise ValueError(
-                "value too long for field %s (expected %d): %s" \
-                % (name, value, length))
+    for value in _tolist(data):
         fp.write(value)
     fp.write('\n')
 
 
 def _tolist(data):
-    res=[]
+    res = []
     for field in ADUFORMAT:
-        name=field[0]
-        length, datatype=field[2:4]
-        value=to_adu(datatype, data.get(name), length)
-        value=value.rjust(length)
-        if len(value)!=length:
+        name = field[0]
+        length, datatype = field[2:4]
+        value = to_adu(datatype, data.get(name), length)
+        value = value.rjust(length)
+        if len(value) != length:
             raise ValueError(
                 "value too long for field %s (expected %d): %s" \
                 % (name, value, length))