GithubHelp home page GithubHelp logo

redocnib / bitbooleanflags Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 15 KB

Bit boolean flag wrapper written in python, allows you to store multiple flags inside a single number.

License: MIT License

Makefile 1.59% Python 98.41%
python-library python-lib

bitbooleanflags's Introduction

BitBooleanFlags - Wrapper Syntax'ed #

Bit boolean flag wrapper, allows you to store flags inside a single number. Each flag uses powers of two, and the number of flags you can store depends on the capacity of the numeric data type. You can do combined and or operations on the flag as per your requirement, refer examples.

Installation

Use the package manager pip.

pip install bit-boolean-flags

Sample

from BitBooleanFlags import BitBooleanFlags
#initialize with a set of static flags which are available to set
BBF = BitBooleanFlags("CREATE_FOLDER","CREATE_FILE","DELETE_FILE","DELETE_FOLDER","KILL_PROCESS","ROOT_ACCESS")
#For example's sake
process1 = 0;
process2 = 0;
process3 = 0;
#add Permissions
process1 = BBF(process1).add("CREATE_FILE","DELETE_FILE")
#Inherit process1 flags and add new ones
process2 = BBF(process2).add("DELETE_FOLDER","CREATE_FOLDER")
#in addition to process 1 and two flags
process3 = BBF(process1,process2).add("KILL_PROCESS","ROOT_ACCESS","ROOT_ACCESS")

print("Permission List with Basic has: ")
for flag in BBF.mappedFlags():
    print("Process 1 => " + flag + " : " + str(BBF(process1).has(flag)))


for flag in BBF.mappedFlags():
    print("Process 2 => "  + flag + " : " + str(BBF(process2).has(flag)))

for flag in BBF.mappedFlags():
    print("Process 3 => "  + flag + " : " + str(BBF(process3).has(flag)))


print("orHas(): ")
print("Process 1 =>  ROOT_ACCESS or CREATE_FILE : "+ str(BBF(process1).orHas("ROOT_ACCESS","CREATE_FILE")))

print("has(): and operation")
print("Process 2 =>  DELETE_FOLDER and CREATE_FOLDER : "+ str(BBF(process2).has("DELETE_FOLDER","CREATE_FOLDER")))

#store process1,process2,process3 in db or another storage medium as it is a number.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Contributors

Vysakh

License

MIT

bitbooleanflags's People

Contributors

redocnib avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.