Skip to content

Instantly share code, notes, and snippets.

@johngag
Last active December 16, 2015 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johngag/5349715 to your computer and use it in GitHub Desktop.
Save johngag/5349715 to your computer and use it in GitHub Desktop.
# Roles Dictionary Values Example (1,2,4,8,16,32...) Up to 32 values
roles = {"addUsers": 1, "updatePermissions": 2, "uploadAttachments": 4, "createPosts": 8}
# Check if permission 9 has updatePermissions
# bitand will return 0 if False and a number if True
>>> 9&roles['updatePermissions']
0
# Check if permission 9 has addUsers
>>> 9&roles['addUsers']
1
# Check if permission 6 has addUsers
>>> 6&roles['addUsers']
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment