def automate(self, line): """Handle parsing while inside an automation block.""" if line == "}": return self.no_macro try: attr, value = re.split(": ?", line, maxsplit=1) except ValueError: raise Invalid("config colon") if attr not in self.automate_dict: raise Invalid("config attr", attr) if attr == "id": int_at_least(value, 0, "Trial id " + attr) self.automate_dict[attr] = value return self.automate
def automate(self, line): '''Handle parsing while inside an automation block.''' if line == "}": return self.no_macro try: attr, value = re.split(": ?", line, maxsplit=1) except ValueError: raise Invalid("config colon") if attr not in self.automate_dict: raise Invalid("config attr", attr) if attr == "id": int_at_least(value, 0, "Trial id " + attr) self.automate_dict[attr] = value return self.automate
def parse_file(): '''Parses the selector file.''' lines = extract_data(file_name) try: if len(lines) != 10: raise Invalid("selector length") except Invalid: print(sys.exc_info()[1].message.format( "end of file", file_name)) terminate() try: for i, string in enumerate([ "USERNAME:"******"PASSWORD:"******"DIRECTORY:", "TRIAL_ID:", "MAX_ERRORS:"]): if string != lines[2*i]: raise Invalid("selector", string) except Invalid: print(sys.exc_info()[1].message.format( "line {}".format(2*i+1), file_name)) terminate() try: max_err = int_at_least(lines[9], 1, "Maximum errors allowable") except Invalid: print(sys.exc_info()[1].message.format("line 10", file_name)) terminate() return lines[5], { "username": lines[1], "password": lines[3], "trial_id": lines[7] }, max_err
def config(self, line): """Handle parsing while inside a configuration block.""" if line == "}": return self.no_macro try: attr, value = re.split(": ?", line, maxsplit=1) except ValueError: raise Invalid("config colon") if attr not in self.config_dict: raise Invalid("config attr", attr) # Now we actually set the configuration attribute. if attr in {"autopause", "autowrap", "autoquote"}: self.config_dict[attr] = not self.config_dict[attr] else: self.config_dict[attr] = int_at_least(value, 0, "Configuration attribute " + attr) return self.config
def config(self, line): '''Handle parsing while inside a configuration block.''' if line == "}": return self.no_macro try: attr, value = re.split(": ?", line, maxsplit=1) except ValueError: raise Invalid("config colon") if attr not in self.config_dict: raise Invalid("config attr", attr) # Now we actually set the configuration attribute. if attr in {"autopause", "autowrap", "autoquote"}: self.config_dict[attr] = not self.config_dict[attr] else: self.config_dict[attr] = int_at_least( value, 0, "Configuration attribute " + attr) return self.config
def config(self, line): '''Handle parsing while inside a configuration block.''' if line == "}": return self.no_macro try: attr, value = line.rsplit(":", maxsplit=1) value = value.strip() attr, value = attr.lower(), value.lower() except ValueError: raise Invalid("config colon") if attr not in self.config_dict: raise Invalid("config attr", attr) if attr in self.customization_dict: self.config_dict[attr] = key_or_value( value, self.customization_dict[attr], attr) elif attr == "autoescape": self.config_dict[attr].update(value.split()) else: self.config_dict[attr] = int_at_least( value, 0, "Configuration attribute " + attr) return self.config
def new_volume(self, volume): '''Change the volume to an integer at least 1.''' self.data["volume"] = int_at_least(volume, 1, "Volume")
def new_loop_start(self, loop_start): '''Set the loop start time to an integer at last 0.''' self.data["loop_start"] = int_at_least(loop_start, 0, "Loop start time")
def set_duration(self, duration): '''Property that defines the duration. Startup sprite unneeded''' self.data["startup_duration"] = int_at_least(duration, 0, "Duration")
def new_loop_start(self, loop_start): '''Set the loop start time to an integer at last 0.''' self.data["loop_start"] = int_at_least( loop_start, 0, "Loop start time")