kkpyutil 1.38.1__tar.gz → 1.40.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kkpyutil
3
- Version: 1.38.1
3
+ Version: 1.40.0
4
4
  Summary: Building blocks for sysadmin and DevOps
5
5
  Home-page: https://github.com/kakyoism/kkpyutil/
6
6
  License: MIT
@@ -2936,12 +2936,47 @@ def remove_unsupported_dict_keys(mydict: dict, supported_keys: set):
2936
2936
  return mydict
2937
2937
 
2938
2938
 
2939
+ def json_to_text(obj, use_unicode=True, pretty=False):
2940
+ try:
2941
+ json_str = json.dumps(obj, ensure_ascii=not use_unicode, indent=4 if pretty else None)
2942
+ return json_str, None
2943
+ except TypeError as e:
2944
+ return None, e
2945
+
2946
+
2947
+ def json_from_text(json_str):
2948
+ try:
2949
+ data = json.loads(json_str)
2950
+ return data, None
2951
+ except json.JSONDecodeError as e:
2952
+ return None, e
2953
+
2939
2954
 
2955
+ class OfflineJSON:
2956
+ def __init__(self, file_path):
2957
+ self.path = file_path
2940
2958
 
2959
+ def exists(self):
2960
+ return osp.isfile(self.path)
2961
+
2962
+ def load(self):
2963
+ return load_json(self.path) if self.exists() else None
2964
+
2965
+ def save(self, data: dict):
2966
+ save_json(self.path, data)
2967
+
2968
+ def merge(self, props: dict):
2969
+ data = self.load()
2970
+ if not data:
2971
+ return self.save(props)
2972
+ data.update(props)
2973
+ self.save(data)
2974
+ return data
2941
2975
 
2942
2976
 
2943
2977
  def _test():
2944
- print(say('hello'))
2978
+ # print(say('hello'))
2979
+ print(create_guid())
2945
2980
 
2946
2981
 
2947
2982
  if __name__ == '__main__':
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "kkpyutil"
3
- version = "1.38.1"
3
+ version = "1.40.0"
4
4
  description = "Building blocks for sysadmin and DevOps"
5
5
  authors = ["Beinan Li <li.beinan@gmail.com>"]
6
6
  maintainers = ["Beinan Li <li.beinan@gmail.com>"]
File without changes
File without changes