Skip to content

Commit

Permalink
Merge dev into main
Browse files Browse the repository at this point in the history
  • Loading branch information
DinisCruz committed Oct 31, 2024
2 parents 10c5df8 + ee92f29 commit ad2a406
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Powerful Python util methods and classes that simplify common apis and tasks.

![Current Release](https://img.shields.io/badge/release-v1.68.0-blue)
![Current Release](https://img.shields.io/badge/release-v1.68.2-blue)
[![codecov](https://codecov.io/gh/owasp-sbot/OSBot-Utils/graph/badge.svg?token=GNVW0COX1N)](https://codecov.io/gh/owasp-sbot/OSBot-Utils)


Expand Down
9 changes: 8 additions & 1 deletion osbot_utils/base_classes/Type_Safe.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from osbot_utils.helpers.Random_Guid_Short import Random_Guid_Short
from osbot_utils.helpers.Timestamp_Now import Timestamp_Now
from osbot_utils.utils.Dev import pprint
from osbot_utils.utils.Json import json_parse
from osbot_utils.utils.Json import json_parse, json_to_bytes, json_to_gz
from osbot_utils.utils.Misc import list_set
from osbot_utils.utils.Objects import default_value, value_type_matches_obj_annotation_for_attr, \
raise_exception_on_obj_type_annotation_mismatch, obj_is_attribute_annotation_of_type, enum_from_value, \
Expand Down Expand Up @@ -230,9 +230,16 @@ def __schema__(cls):
# global methods added to any class that base classes this
# todo: see if there should be a prefix on these methods, to make it easier to spot them
# of if these are actually that useful that they should be added like this
def bytes(self):
return json_to_bytes(self.json())

def bytes_gz(self):
return json_to_gz(self.json())

def json(self):
return self.serialize_to_dict()


def merge_with(self, target):
original_attrs = {k: v for k, v in self.__dict__.items() if k not in target.__dict__} # Store the original attributes of self that should be retained.
self.__dict__ = target.__dict__ # Set the target's __dict__ to self, now self and target share the same __dict__.
Expand Down
4 changes: 4 additions & 0 deletions osbot_utils/utils/Json.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from osbot_utils.utils.Files import file_create_gz, file_create, load_file_gz, file_contents, file_lines, file_lines_gz
from osbot_utils.utils.Zip import str_to_gz, gz_to_str

def bytes_to_json_loads(data):
return json.loads(data.decode())

def json_dumps(python_object, indent=4, pretty=True, sort_keys=False, default=str, raise_exception=False):
if python_object:
Expand Down Expand Up @@ -135,6 +137,7 @@ def save_file_pretty_gz(python_object, path=None):
def json_save_tmp_file(python_object, pretty=True):
return Json.save_file(python_object=python_object, pretty=pretty, path=None)

bytes_to_json = bytes_to_json_loads
file_create_json = Json.save_file_pretty
file_contents_json = Json.load_file

Expand All @@ -158,6 +161,7 @@ def json_save_tmp_file(python_object, pretty=True):
json_lines_loads = Json.loads_json_lines
json_parse = Json.loads
json_lines_parse = Json.loads_json_lines
json_to_bytes = json_dumps_to_bytes
json_to_str = json_dumps
json_round_trip = Json.round_trip
json_save = Json.save_file
Expand Down
2 changes: 1 addition & 1 deletion osbot_utils/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.68.0
v1.68.2
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "osbot_utils"
version = "v1.68.0"
version = "v1.68.2"
description = "OWASP Security Bot - Utils"
authors = ["Dinis Cruz <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit ad2a406

Please sign in to comment.