def dump(self): """ Dump a representation of self to its YAML data file """ as_yaml = saneyaml.dump(self.to_dict()) with io.open(self.data_file, 'w', encoding='utf-8') as df: df.write(as_yaml)
def dump(self, check_exists=False): """ Dump a representation of self to a .yml data_file in YAML block format. """ as_yaml = saneyaml.dump(self.to_dict()) if check_exists and os.path.exists(self.data_file): raise Exception(self.data_file) with io.open(self.data_file, 'w', encoding='utf-8') as df: df.write(as_yaml)
def dump(self): """ Dump a representation of self as multiple files named this way: - <key>.yml : the license data in YAML - <key>.LICENSE: the license text """ as_yaml = saneyaml.dump(self.to_dict()) self._write(self.data_file, as_yaml) if self.text: self._write(self.text_file, self.text)
def dump(self): """ Dump a representation of self to tgt_dir as two files: - a .yml for the rule data in YAML block format - a .RULE: the rule text as a UTF-8 file """ if self.data_file: as_yaml = saneyaml.dump(self.to_dict()) with codecs.open(self.data_file, 'wb', encoding='utf-8') as df: df.write(as_yaml) text = self.text() with codecs.open(self.text_file, 'wb', encoding='utf-8') as tf: tf.write(text)
def dump(self): """ Dump a representation of this license as two files: - <key>.yml : the license data in YAML - <key>.LICENSE: the license text """ def write(location, byte_string): # we write as binary because rules and licenses texts and data are UTF-8-encoded bytes with io.open(location, 'wb') as of: of.write(byte_string) as_yaml = saneyaml.dump(self.to_dict(), indent=4, encoding='utf-8') write(self.data_file, as_yaml) if self.text: write(self.text_file, self.text.encode('utf-8'))
def dump(self): """ Dump a representation of this rule as two files: - a .yml for the rule data in YAML (self.data_file) - a .RULE: the rule text as a UTF-8 file (self.text_file) Does nothing if this rule was created from a License (e.g. `is_license` is True) """ if self.is_license: return def write(location, byte_string): # we write as binary because rules and licenses texts and data are UTF-8-encoded bytes with io.open(location, 'wb') as of: of.write(byte_string) if self.data_file: as_yaml = saneyaml.dump(self.to_dict(), indent=4, encoding='utf-8') write(self.data_file, as_yaml) write(self.text_file, self.text().encode('utf-8'))
def dumps(self): """ Return a string representation of self in YAML block format. """ return saneyaml.dump(self.to_dict())