def data2toml(self,mapper, connection, target): if target._totoml and self.tomlpath!="": data=target.getDataAsDict() out=contoml.dumps(data) path=target._tomlpath(self) j.sal.fs.createDir(j.sal.fs.getDirName(path)) j.sal.fs.writeFile(filename=path,contents=out)
def write_toml(self, data, path=None): """Writes the given data structure out as TOML.""" if path is None: path = self.pipfile_location try: formatted_data = contoml.dumps(data).rstrip() except Exception: for section in ('packages', 'dev-packages'): for package in data.get(section, {}): # Convert things to inline tables — fancy :) if hasattr(data[section][package], 'keys'): _data = data[section][package] data[section][package] = toml._get_empty_inline_table( dict) data[section][package].update(_data) formatted_data = toml.dumps(data).rstrip() if Path(path).absolute() == Path(self.pipfile_location).absolute(): newlines = self._pipfile_newlines else: newlines = DEFAULT_NEWLINES formatted_data = cleanup_toml(formatted_data) with io.open(path, 'w', newline=newlines) as f: f.write(formatted_data) # pipfile is mutated! self.clear_pipfile_cache()
def write_toml(self, data, path=None): """Writes the given data structure out as TOML.""" if path is None: path = self.pipfile_location try: formatted_data = contoml.dumps(data) except RuntimeError: import toml for section in ('packages', 'dev-packages'): for package in data[section]: # Convert things to inline tables — fancy :) if hasattr(data[section][package], 'keys'): _data = data[section][package] data[section][package] = toml._get_empty_inline_table( dict) data[section][package].update(_data) formatted_data = toml.dumps(data) else: pass finally: pass with open(path, 'w') as f: f.write(formatted_data)
def write_toml(self, data, path=None): """Writes the given data structure out as TOML.""" if path is None: path = self.pipfile_location try: formatted_data = contoml.dumps(data).rstrip() except Exception: for section in ("packages", "dev-packages"): for package in data.get(section, {}): # Convert things to inline tables — fancy :) if hasattr(data[section][package], "keys"): _data = data[section][package] data[section][package] = toml._get_empty_inline_table(dict) data[section][package].update(_data) formatted_data = toml.dumps(data).rstrip() if Path(path).absolute() == Path(self.pipfile_location).absolute(): newlines = self._pipfile_newlines else: newlines = DEFAULT_NEWLINES formatted_data = cleanup_toml(formatted_data) with io.open(path, "w", newline=newlines) as f: f.write(formatted_data) # pipfile is mutated! self.clear_pipfile_cache()
def dump(self, to_dict=False): """Dumps the pipfile to a toml string """ _dict = self.get_sources() _dict.update(self.get_sections()) _dict.update(self.get_dict()) _dict.update(self.get_pipenv()) _dict.update(self.get_requires()) if to_dict: return _dict return contoml.dumps(_dict)
def write_toml(self, data, path=None): """Writes the given data structure out as TOML.""" if path is None: path = self.pipfile_location try: formatted_data = contoml.dumps(data).rstrip() except Exception: for section in ('packages', 'dev-packages'): for package in data[section]: # Convert things to inline tables — fancy :) if hasattr(data[section][package], 'keys'): _data = data[section][package] data[section][package] = toml._get_empty_inline_table( dict) data[section][package].update(_data) formatted_data = toml.dumps(data).rstrip() formatted_data = cleanup_toml(formatted_data) with open(path, 'w') as f: f.write(formatted_data) # pipfile is mutated! self.clear_pipfile_cache()
def write_toml(self, data, path=None): """Writes the given data structure out as TOML.""" if path is None: path = self.pipfile_location try: formatted_data = contoml.dumps(data).rstrip() except Exception: for section in ('packages', 'dev-packages'): for package in data[section]: # Convert things to inline tables — fancy :) if hasattr(data[section][package], 'keys'): _data = data[section][package] data[section][package] = toml._get_empty_inline_table(dict) data[section][package].update(_data) formatted_data = toml.dumps(data).rstrip() formatted_data = cleanup_toml(formatted_data) with open(path, 'w') as f: f.write(formatted_data)
def test_dump_nonascii_string(): content = 'name = "Stažené"\n' toml_content = contoml.dumps(contoml.loads(content)) assert toml_content == content
def to_string(self) -> str: """Convert representation of Pipfile to actual Pipfile file content.""" _LOGGER.debug("Converting Pipfile to toml") return toml.dumps(self.to_dict())