Add file PyProject;
Support display of a single pubsub node item; Update document README; Modularize code;
This commit is contained in:
parent
37aa7e8f40
commit
5e495579c2
32 changed files with 2431 additions and 2059 deletions
30
jabbercard/utilities/toml.py
Normal file
30
jabbercard/utilities/toml.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import tomli_w
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
try:
|
||||
import tomllib
|
||||
except:
|
||||
import tomli as tomllib
|
||||
|
||||
class Toml:
|
||||
|
||||
def open_file_toml(filename: str) -> dict:
|
||||
with open(filename, mode="rb") as fn:
|
||||
data = tomllib.load(fn)
|
||||
return data
|
||||
|
||||
def save_to_toml(filename: str, data: dict) -> None:
|
||||
with open(filename, 'w') as fn:
|
||||
data_as_string = tomli_w.dumps(data)
|
||||
fn.write(data_as_string)
|
||||
|
||||
def open_file_xml(filename: str) -> ET.ElementTree:
|
||||
data = ET.parse(filename)
|
||||
return data
|
||||
|
||||
def save_to_file(filename: str, data: str) -> None:
|
||||
with open(filename, 'w') as fn:
|
||||
fn.write(data)
|
Loading…
Add table
Add a link
Reference in a new issue