How to use the rules.Rules function in rules

To help you get started, we’ve selected a few rules examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github metalshark / lesscss-python / test_parse.py View on Github external
def setUp(self):
        less = '''
@constant: 10px;

* {
    @constant: 20px;

    a {
        @constant: 30px;
    }
}'''
        self.parsed = Rules(code=less)
        parse(less=less, parent=self.parsed)
github metalshark / lesscss-python / media.py View on Github external
raise ValueError()

    media = [media.strip() for media in match.group('media').split(',')]

    matched_length = len(match.group())

    remaining_less = less[matched_length:]

    contents = parse_nested(remaining_less)

    code = match.group() + contents + '}'

    return Media(code=code, media=media, contents=contents, parent=parent)


class Media(Rules):

    __slots__ = ('__media',)

    def __init__(self, parent, code, media, contents=None):
        Rules.__init__(self, parent=parent, code=code, contents=contents)

        self.__media = media
        
    def __get_media(self):
        return self.__media

    media = property(fget=__get_media)
github nesfit / fitcrack / webadmin / fitcrackAPI / src / src / api / fitcrack / endpoints / pcfg / pcfg_mower / pcfg_mower.py View on Github external
def pcfg_mower(config):
    print = logging.info
    iprint = logging.warning
    logging.basicConfig(level=logging.WARNING if config.quiet else logging.INFO,
                        format="%(message)s")

    rules = Rules(config)
    debug = Debug()

    if rules.load_grammar():
        iprint("ERROR: load_grammar", file=sys.stderr)
        return 1

    if rules.load_capitalization():
        iprint("ERROR: load_capitalization", file=sys.stderr)
        return 1

    if rules.load_alpha():
        iprint("ERROR: load_alpha", file=sys.stderr)
        return 1

    if rules.load_terminals_cnt():
        iprint("ERROR: load_terminals_cnt", file=sys.stderr)
github arne-cl / pypolibox / src / pypolibox / debug.py View on Github external
def find_applicable_rules(messages):
    """    
    debugging: find out which rules are directly (i.e. without forming ConstituentSets first) applicable to your messages
    
    :type messages: ``list`` of ``Message``s or
                    ``Messages``
    """
    if type(messages) is list: # is 'messages' a list of Message() instances?
        pass
    elif isinstance(messages, Messages):
        messages = messages.messages.values()
        
    for name, rule in Rules().rule_dict.iteritems():
        try:
            if rule.get_options(messages) != []:
                nuc_candidates = \
                    [rulename for (rulename, msg) in rule.nucleus]
                sat_candidates = \
                    [rulename for (rulename, msg) in rule.satellite]
                print "{0}: {1} - {2}, {3} - is directly applicable and results in \n\t{4}\n\n".format(name, rule.ruleType, nuc_candidates, sat_candidates, rule.get_options(messages))
        except:
            print "ERROR: Could not check if rule {0} is applicable. Possible solution: test if the rule's conditions are specified appropriately.\n\n".format(name)
github kimchi-project / ginger / control / audit.py View on Github external
def __init__(self, model, id=None):
        super(Audit, self).__init__(model, id)
        self.conf = Conf(model)
        self.graphs = Graphs(model)
        self.logs = Logs(model)
        self.reports = Reports(model)
        self.rules = Rules(model)
        self.syscall = Syscall(model)
        self.uri_fmt = '/audit/%s'
        self.load_rules = self.generate_action_handler('load_rules',
                                                       ['auditrule_file'])
        self.log_map = AUDIT_REQUESTS
github qtile / qtile-examples / osimplex / config.py View on Github external
from bindings import Keys, Mouses
from groups import Groups
from scratchpad import Scratchpad, DropDown_Keys
from rules import Rules
from screens import Screens
from aesthetics import Layout_Aesthetics, Widget_Aesthetics, Extension_Aesthetics

##### INIT #####

if __name__ in ["config", "__main__"]:

	# Init objects
	obj_keys = Keys()
	obj_mouse_touch = Mouses()
	obj_groups = Groups()
	obj_rules = Rules()
	obj_screens = Screens()

	obj_scratchpad = Scratchpad()
	obj_dd_keys = DropDown_Keys()

	obj_widget_aesthetics = Widget_Aesthetics()
	obj_layout_aesthetics = Layout_Aesthetics()
	obj_extension_aesthetics = Extension_Aesthetics()

	# Init qtile variables
	keys = obj_keys.init_keys()
	mouse = obj_mouse_touch.init_mouse()

	floating_layout = obj_layout_aesthetics.floating_layout

	groups = obj_groups.init_groups()
github arne-cl / pypolibox / src / pypolibox / debug.py View on Github external
def findrule(ruletype="", attribute="", value=""):
    """
    debugging: find rules that have a certain ruleType and some 
    attribute-value pair
    
    Example: findrule("Concession", "nucleus", "usermodel_match") finds 
    rules of type 'Concession' where rule.nucleus == 'usermodel_match'.
    """
    rules = Rules().rule_dict
    matching_rules = {}
    
    if ruletype == "":
        for index, (name, rule) in enumerate(rules.iteritems()):
            if getattr(rule, attribute) is value:
                print "rule {0} - {1}:\n{2}".format(index, name, rule)
                matching_rules[name] = rule
    elif attribute == "":
        for index, (name, rule) in enumerate(rules.iteritems()):
            if rule.ruleType is ruletype:
                print "rule {0} - {1}:\n{2}".format(index, name, rule)
                matching_rules[name] = rule
    else:
        for index, (name, rule) in enumerate(rules.iteritems()):
            if rule.ruleType is ruletype and getattr(rule, attribute) is value:
                print "rule {0} - {1}:\n{2}".format(index, name, rule)
github mantidproject / mantid / Code / Mantid / scripts / lib1to2 / rules / stringreplace.py View on Github external
def __init__(self):
        rules.Rules.__init__(self)
        self._rules = __STRINGREPLACEMENTS__
github guiqiqi / AllRename / functions.py View on Github external
bigDir = 1024 ** 3
hname = "help"
infoKey = {
	"modifyTime" : "修改时间",
	"createTime" : "创建时间",
	"fileLength" : "文件大小",
	"parentDir" : "上级目录",
	"fileName" : "文件名",
	"fileType" : "文件类型"
}
arguments = deque(maxlen = 1)
analyser = rules.Analyser('', []) # 文件分析器
opreators = rules.opreators.functions # 所有注册操作
opreatorList = list(opreators.keys()) # 显示用操作列表
division = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'] # 文件单位
rulefunctions = rules.Rules() # 操作函数实例
opreatorList.sort()


webOpen = lambda target : webbrowser.open(target)
cleanTree = lambda treeview : treeview.delete(*treeview.get_children())
removeSelect = lambda treeview : [treeview.delete(treeview.selection()[0]) if treeview.focus() else None]
getSelectValue = lambda treeview : treeview.item(treeview.focus())
openDir = lambda location : os.system("explorer.exe %s" % location)

# author : guiqiqi187@gmail.com
# 返回文件详情页面需要的字符
def fileInfo(location, fileName):
	fileLocation = location + "/" + fileName
	fileInfo = basic.getFileInfo(fileLocation)
	string = list()
	for key, value in fileInfo.items():