Module Import alias Import alias Import alias Import alias Import alias Import alias Import alias Import alias Expr Str ClassDef bases NameLoad body Pass decorator_list ClassDef bases NameLoad body Pass decorator_list ClassDef bases NameLoad body Pass decorator_list ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam defaults NameLoad body Expr Str Assign NameStore Str Assign NameStore Call AttributeLoad NameLoad attr If BoolOpOr CompareIs NameLoad NameLoad UnaryOpNot Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad body Assign NameStore NameLoad TryExcept body With Call NameLoad NameLoad NameStore body Expr Call AttributeLoad NameLoad attr NameLoad handlers ExceptHandler type NameLoad body Raise Call NameLoad BinOpMod Str NameLoad TryExcept body Assign NameStore Call AttributeLoad NameLoad attr Str Str Assign NameStore Call AttributeLoad NameLoad attr Str Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Str Assign NameStore Call AttributeLoad NameLoad attr Str Str Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr NameLoad handlers ExceptHandler type AttributeLoad NameLoad attr name NameStore body Raise Call NameLoad BinOpMod Str NameLoad ExceptHandler type AttributeLoad NameLoad attr name NameStore body Raise Call NameLoad BinOpMod Str NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad Expr Call AttributeLoad NameLoad attr BinOpMod Str NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad keyword Str Expr Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam defaults body Expr Str TryExcept body Expr Call AttributeLoad AttributeLoad NameLoad attr attr Str Expr Call AttributeLoad AttributeLoad NameLoad attr attr Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad If NameLoad body If SubscriptLoad NameLoad Index Str body Expr Call AttributeLoad AttributeLoad NameLoad attr attr Str Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad BinOpAdd SubscriptLoad NameLoad Index Str Num Num Raise Call NameLoad Str orelse If CompareGtE SubscriptLoad NameLoad Index Str NameLoad body Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Call NameLoad SubscriptLoad NameLoad Index Str Assign NameStore BinOpAdd NameLoad Call AttributeLoad NameLoad attr keyword NameLoad If CompareLt Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad body Expr Call AttributeLoad AttributeLoad NameLoad attr attr Str Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad BinOpAdd SubscriptLoad NameLoad Index Str Num Num Raise Call NameLoad Str orelse Expr Call AttributeLoad AttributeLoad NameLoad attr attr Str Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad Num Num orelse Expr Call AttributeLoad AttributeLoad NameLoad attr attr Str Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad BinOpAdd SubscriptLoad NameLoad Index Str Num Num orelse Expr Call AttributeLoad AttributeLoad NameLoad attr attr Str Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad Num handlers ExceptHandler type AttributeLoad NameLoad attr name NameStore body Expr Call AttributeLoad AttributeLoad NameLoad attr attr Str Raise Call NameLoad BinOpMod Str Call NameLoad NameLoad ExceptHandler type NameLoad name NameStore body Raise Call NameLoad NameLoad decorator_list decorator_list
N/A N/A os N/A time N/A logging N/A sqlite3 N/A datetime N/A ConfigParser N/A db N/A utils N/A Blacklist module for managing blacklisting of users. BlacklistError N/A Exception N/A N/A N/A ConfigError N/A Exception N/A N/A N/A InternalError N/A Exception N/A N/A N/A Blacklist N/A object N/A N/A Manage blacklisting of users.

    Public methods:

        is_blacklisted(): Check if someone is blacklisted.

    Exceptions:

         ConfigurationError: Bad configuration.
         BlacklistError: User is blacklisted.
         InternalError: Something went wrong internally.

     __init__ N/A N/A self cfg N/A None N/A N/A Create new object by reading a configuration file.

        :param: cfg (string) path of the configuration file.

         N/A default_cfg blacklist.cfg N/A config N/A N/A ConfigParser ConfigParser N/A N/A N/A cfg None N/A N/A N/A N/A os path isfile cfg N/A N/A cfg default_cfg N/A N/A N/A N/A open cfg f N/A N/A N/A N/A config readfp f N/A N/A N/A IOError N/A N/A N/A ConfigError N/A File %s not found! cfg N/A N/A N/A dbname N/A N/A config get general db N/A logdir N/A N/A config get log dir N/A logfile N/A N/A N/A os path join logdir blacklist.log N/A loglevel N/A N/A config get log level N/A N/A self db N/A N/A db DB dbname N/A N/A N/A N/A ConfigParser Error N/A e N/A N/A N/A ConfigError N/A %s e N/A N/A N/A db Exception N/A e N/A N/A N/A ConfigError N/A %s e N/A log N/A N/A logging getLogger __name__ N/A logging_format N/A N/A utils get_logging_format N/A date_format N/A N/A utils get_date_format N/A formatter N/A N/A logging Formatter logging_format date_format N/A N/A N/A log info N/A Redirecting BLACKLIST logging to %s logfile N/A logfileh N/A N/A logging FileHandler logfile mode a+ N/A N/A N/A logfileh setFormatter formatter N/A N/A N/A logfileh setLevel N/A N/A logging getLevelName loglevel N/A N/A N/A log addHandler logfileh N/A N/A log propagate False N/A N/A self log log N/A is_blacklisted N/A N/A self user service max_req wait_time N/A N/A N/A Check if a user is blacklisted.

        The user is blacklisted if:

        a) The 'blocked' field is set to one, meaning that is permanently
        blacklisted.

        b) Does too many requests on a short period of time. For now, a user
        that makes more than 'max_req' requests should wait 'wait_time'
        minutes to make a new request.

        :param: user (string) the hashed user.
        :param: service (string) the service the user is making a request to.
        :param: max_req (int) maximum number of requests a user can make
                in a row.
        :param: wait_time (int) amount of time the user must wait before
                making requests again after 'max_req' requests is reached.
                For now this is considered in minutes.

        :raise: BlacklistError if the user is blacklisted

         N/A N/A N/A N/A N/A N/A self log info Trying to get info from user N/A N/A N/A N/A self db connect N/A r N/A N/A N/A self db get_user user service N/A r N/A N/A N/A r N/A blocked N/A N/A N/A N/A N/A self log warning Request from user permanently blocked N/A N/A N/A N/A self db update_user user service N/A N/A r N/A times 1 1 N/A N/A BlacklistError Blocked user N/A N/A N/A N/A r N/A times max_req N/A N/A last N/A N/A N/A datetime datetime fromtimestamp N/A float N/A r N/A last_request N/A next N/A last N/A N/A datetime timedelta minutes wait_time N/A N/A N/A N/A N/A datetime datetime now next N/A N/A N/A N/A N/A self log warning Too many requests from same user N/A N/A N/A N/A self db update_user user service N/A N/A r N/A times 1 0 N/A N/A BlacklistError Too many requests N/A N/A N/A N/A N/A self log info Updating counter for existing user N/A N/A N/A N/A self db update_user user service 1 0 N/A N/A N/A N/A N/A self log info Request from existing user N/A N/A N/A N/A self db update_user user service N/A N/A r N/A times 1 0 N/A N/A N/A N/A N/A self log info Request from new user N/A N/A N/A N/A self db add_user user service 0 N/A N/A N/A N/A db DBError N/A e N/A N/A N/A N/A N/A self log error Something failed! N/A N/A InternalError N/A Error with database (%s) N/A str e N/A N/A BlacklistError N/A e N/A N/A N/A BlacklistError e N/A N/A