Advertisement
NickG

Untitled

Dec 23rd, 2012
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. SERVER_TO_CLIENT = 0x01
  2. CLIENT_TO_SERVER = 0x02
  3.  
  4. structs = {
  5.     #lots of packet structures in here
  6.     }
  7.  
  8. #Normalize data structures
  9. for key, val in structs.iteritems():
  10.     if isinstance(val, dict):
  11.         for k in (SERVER_TO_CLIENT, CLIENT_TO_SERVER):
  12.             if len(val[k]) and not isinstance(val[k][0], tuple):
  13.                 structs[key][k] = (val[k],)
  14.         continue
  15.     elif len(val) and not isinstance(val[0], tuple):
  16.         val = (val,)
  17.     val = {
  18.         CLIENT_TO_SERVER: val,
  19.         SERVER_TO_CLIENT: val}
  20.     structs[key] = val
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement