def getIntegral(keyword): if keyword in MoguString.ReservedWords: return str(syntax.as_integer(keyword)) elif keyword in MoguString.Operators: return str(syntax.MoguOperators[keyword]) else: return 0
def convert_policy(self, result_dict): """ The result_dict is the OrderedDict instance returned from using the POLICY_BLOCK.parse method, and contains the building blocks of a storage policy. """ def init_default(master,key): if key not in master: master[key] = OrderedDict() master_dict = OrderedDict() redis_objects = [] identifier = result_dict["identifier"] master_key = "policy.%s" % identifier default_key = "%s.%d" % (master_key, syntax.as_integer("default")) master_dict[master_key] = OrderedDict() params = result_dict["policy_def"] for param in params: o_dict = param[0] parsemap = param[1] if parsemap is lex_base.POLICY_MODE: master_dict[master_key][syntax.as_integer("mode")] = \ o_dict["mode"] elif parsemap is lex_base.POLICY_DATA: master_dict[master_key][syntax.as_integer("type")] = \ o_dict["datatype"] elif parsemap is lex_base.POLICY_ENCRYPTION: master_dict[master_key][syntax.as_integer("encrypted")] = \ o_dict["encrypted"] elif parsemap is lex_base.POLICY_DEFAULT: init_default(master_dict,default_key) master_dict[default_key] = o_dict["default"] elif parsemap is Lex.HASH_BLOCK: init_default(master_dict,default_key) master_dict[default_key] = self.convert_hash_block(o_dict) elif parsemap is Lex.LIST_BLOCK: init_default(master_dict, default_key) master_dict[default_key] = self.convert_list_block(o_dict) for entry in master_dict: redis_objects.append( self.convert_to_redis_object(entry, master_dict[entry])) return redis_objects
def setUp(self): ambiguous = ("css", "text") prefs = {} for word in ambiguous: prefs[syntax.as_integer(word)] = word self.mogustrA = MoguString('script', "set widget foo content to widget bar css", prefs) self.mogustrB = MoguString('script', "set own css to \"someClass anotherClass\"", prefs) self.mogustrC = MoguString('script', "set own content to ((100 + user dob year) - 2013)", prefs)
def convert_widget(self, result_dict, prefix="widget"): """ The result_dict is the OrderedDict instance returned from using the WIDGET_BLOCK.parse method, and contains all of the building blocks of a widget. """ master_dict = OrderedDict() redis_objects = [] identifier = result_dict["identifier"] master_key = "%s.%s" % (prefix,identifier) master_dict[master_key] = OrderedDict() # Contains information about the widget, and # is a list of other result dicts. key = "widget_def" if prefix == "widget" else "template_def" params = result_dict[key] for param in params: o_dict = param[0] parsemap = param[1] if parsemap is lex_base.WIDGET_TYPE: master_dict[master_key][syntax.as_integer("type")] = o_dict["type"] elif parsemap is lex_base.WIDGET_CONTENT: master_dict[master_key][syntax.as_integer("content")] = o_dict["content"] elif parsemap is lex_base.WIDGET_SOURCE: master_dict[master_key][syntax.as_integer("source")] = o_dict["source"] elif parsemap is lex_base.WIDGET_SORT: master_dict[master_key][syntax.as_integer("sort")] = o_dict["declaration"] elif parsemap is lex_base.WIDGET_LOCATION: master_dict[master_key][syntax.as_integer("location")] = o_dict["location"] elif parsemap is lex_base.WIDGET_TEMPLATE: master_dict[master_key][syntax.as_integer("template")] = o_dict["template"] elif parsemap is lex_base.WIDGET_STYLE: master_dict[master_key][syntax.as_integer("css")] = o_dict["css_classes"] elif parsemap is lex_base.WIDGET_TOOLTIP: master_dict[master_key][syntax.as_integer("tooltip")] = o_dict["tooltip"] elif parsemap is Lex.EVENT_BLOCK: event_o_dict = self.convert_events(master_key, o_dict["block"]) master_dict.update(event_o_dict) elif parsemap is Lex.WIDGET_VALIDATOR: master_dict[master_key][syntax.as_integer("validator")] = o_dict["validator"] elif parsemap is lex_base.CHILDREN_BLOCK: master_dict["%s.children" % master_key] = [val for val in o_dict['block'] if val] for entry in master_dict: redis_objects.append(self.convert_to_redis_object(entry, master_dict[entry])) return redis_objects
def convert_validator(self, result_dict): """ The result_dict is the OrderedDict instance returned from using the VALIDATOR_BLOCK.parse method, and contains the building blocks of a validator. """ master_dict = OrderedDict() redis_objects = [] identifier = result_dict["identifier"] master_key = "validator.%s" % identifier master_dict[master_key] = OrderedDict() params = result_dict["validator_def"] for param in params: o_dict = param[0] parsemap = param[1] if parsemap is lex_base.VALIDATOR_TEST: master_dict[master_key][syntax.as_integer("test")] = o_dict["test"] elif parsemap is lex_base.VALIDATOR_TYPE: master_dict[master_key][syntax.as_integer("type")] = o_dict["type"] for entry in master_dict: redis_objects.append(self.convert_to_redis_object(entry, master_dict[entry])) return redis_objects
NEWLINES ],help="action [object [identifier|attribute]] [preposition value] (on one line)") ################################# # BEGIN NEXT TIER OF PARSE MAPS # ################################# t = "perspective" PERSPECTIVE_BLOCK = Lexer.ParseMap (( ("begin", "\s*%s\s+"%t, IGNORE), ("identifier", regexlib["identifier"], LITERAL), ("block", everything_until(r"end\s+%s"%t), WhenConsumer.parse), ("end", r"end\s+%s"%t, IGNORE) )) t = syntax.as_integer("hash") HASH_BLOCK = Lexer.ParseMap (( ("begin", "\s*%s"%t, IGNORE), ("hash_def", everything_until("end %s"%t), HashConsumer.parse), ("end", "end %s" %t, IGNORE) )) t = syntax.as_integer("list") LIST_BLOCK = Lexer.ParseMap (( ("begin", r"\s*%s"%t, IGNORE), ("list_def", everything_until(r"end %s"%t), ListConsumer.parse), ("end", r"end %s"%t, IGNORE) )) VALUE_DEFINITION = Lexer.ParseMap(( ("begin", "\s*" , IGNORE),
"math_begin" : r'''(\(|\-)''', "math_end" : r'''(\))''', "reserved" : "(%s)" % "|".join(syntax.MoguSyntax.keys()), "event_triggers": option_list("event trigger"), "widget_types" : option_list("widget type"), "datatype" : option_list("datatype"), "validator_type": option_list("validator type"), "action" : option_list("action"), "object" : option_list("object"), "attribute" : option_list("attribute"), "preposition" : option_list("preposition"), "comment" : r"#.*\n", "math_gen_expr" : r"%d.*%d" % (syntax.MoguOperators["("],syntax.MoguOperators[")"]), # "math_gen_expr" : r"\(.*\)", "comment" : "^#.*\n", "location" : str(syntax.as_integer("location")), } regexlib["math_oper"] = "(%(*)d|%(+)d|%(-)d|%(/)d)" % syntax.MoguOperators regexlib["op_paren"] = str(syntax.MoguOperators["("]) regexlib["cl_paren"] = str(syntax.MoguOperators[")"]) # OBJECT SET # An object set is a phrase which can resolve to an # object within the system, consisting of an object # type, an identifier, and an attribute of that object # # There are some exceptions, for example the keyword 'own', # which acts upon the object using it, and does not require # an identifier. # Examples of valid object sets: