exonware-xwsystem 0.0.1.411__py3-none-any.whl → 0.1.0.3__py3-none-any.whl
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.
- exonware/__init__.py +2 -1
- exonware/conf.py +2 -2
- exonware/xwsystem/__init__.py +115 -43
- exonware/xwsystem/base.py +30 -0
- exonware/xwsystem/caching/__init__.py +39 -13
- exonware/xwsystem/caching/base.py +24 -6
- exonware/xwsystem/caching/bloom_cache.py +2 -2
- exonware/xwsystem/caching/cache_manager.py +2 -1
- exonware/xwsystem/caching/conditional.py +2 -2
- exonware/xwsystem/caching/contracts.py +85 -139
- exonware/xwsystem/caching/decorators.py +6 -19
- exonware/xwsystem/caching/defs.py +2 -1
- exonware/xwsystem/caching/disk_cache.py +2 -1
- exonware/xwsystem/caching/distributed.py +2 -1
- exonware/xwsystem/caching/errors.py +2 -1
- exonware/xwsystem/caching/events.py +110 -27
- exonware/xwsystem/caching/eviction_strategies.py +2 -2
- exonware/xwsystem/caching/external_caching_python.py +701 -0
- exonware/xwsystem/caching/facade.py +253 -0
- exonware/xwsystem/caching/factory.py +300 -0
- exonware/xwsystem/caching/fluent.py +14 -12
- exonware/xwsystem/caching/integrity.py +21 -6
- exonware/xwsystem/caching/lfu_cache.py +2 -1
- exonware/xwsystem/caching/lfu_optimized.py +18 -6
- exonware/xwsystem/caching/lru_cache.py +7 -4
- exonware/xwsystem/caching/memory_bounded.py +2 -2
- exonware/xwsystem/caching/metrics_exporter.py +2 -2
- exonware/xwsystem/caching/observable_cache.py +2 -2
- exonware/xwsystem/caching/pluggable_cache.py +2 -2
- exonware/xwsystem/caching/rate_limiter.py +2 -2
- exonware/xwsystem/caching/read_through.py +2 -2
- exonware/xwsystem/caching/secure_cache.py +81 -28
- exonware/xwsystem/caching/serializable.py +9 -7
- exonware/xwsystem/caching/stats.py +2 -2
- exonware/xwsystem/caching/tagging.py +2 -2
- exonware/xwsystem/caching/ttl_cache.py +4 -3
- exonware/xwsystem/caching/two_tier_cache.py +6 -3
- exonware/xwsystem/caching/utils.py +30 -12
- exonware/xwsystem/caching/validation.py +2 -2
- exonware/xwsystem/caching/warming.py +6 -3
- exonware/xwsystem/caching/write_behind.py +15 -6
- exonware/xwsystem/config/__init__.py +11 -17
- exonware/xwsystem/config/base.py +5 -5
- exonware/xwsystem/config/contracts.py +93 -153
- exonware/xwsystem/config/defaults.py +3 -2
- exonware/xwsystem/config/defs.py +3 -2
- exonware/xwsystem/config/errors.py +2 -5
- exonware/xwsystem/config/logging.py +12 -8
- exonware/xwsystem/config/logging_setup.py +3 -2
- exonware/xwsystem/config/performance.py +73 -391
- exonware/xwsystem/config/performance_modes.py +9 -8
- exonware/xwsystem/config/version_manager.py +1 -0
- exonware/xwsystem/config.py +27 -0
- exonware/xwsystem/console/__init__.py +53 -0
- exonware/xwsystem/console/base.py +133 -0
- exonware/xwsystem/console/cli/__init__.py +61 -0
- exonware/xwsystem/{cli → console/cli}/args.py +27 -24
- exonware/xwsystem/{cli → console/cli}/base.py +18 -87
- exonware/xwsystem/{cli → console/cli}/colors.py +15 -13
- exonware/xwsystem/console/cli/console.py +98 -0
- exonware/xwsystem/{cli → console/cli}/contracts.py +51 -69
- exonware/xwsystem/console/cli/defs.py +87 -0
- exonware/xwsystem/console/cli/encoding.py +69 -0
- exonware/xwsystem/{cli → console/cli}/errors.py +8 -3
- exonware/xwsystem/console/cli/event_logger.py +166 -0
- exonware/xwsystem/{cli → console/cli}/progress.py +25 -21
- exonware/xwsystem/{cli → console/cli}/prompts.py +3 -2
- exonware/xwsystem/{cli → console/cli}/tables.py +27 -24
- exonware/xwsystem/console/contracts.py +113 -0
- exonware/xwsystem/console/defs.py +154 -0
- exonware/xwsystem/console/errors.py +34 -0
- exonware/xwsystem/console/event_logger.py +385 -0
- exonware/xwsystem/console/writer.py +132 -0
- exonware/xwsystem/contracts.py +28 -0
- exonware/xwsystem/data_structures/__init__.py +23 -0
- exonware/xwsystem/data_structures/trie.py +34 -0
- exonware/xwsystem/data_structures/union_find.py +144 -0
- exonware/xwsystem/defs.py +17 -0
- exonware/xwsystem/errors.py +23 -0
- exonware/xwsystem/facade.py +62 -0
- exonware/xwsystem/http_client/__init__.py +22 -1
- exonware/xwsystem/http_client/advanced_client.py +8 -5
- exonware/xwsystem/http_client/base.py +3 -2
- exonware/xwsystem/http_client/client.py +7 -4
- exonware/xwsystem/http_client/contracts.py +42 -56
- exonware/xwsystem/http_client/defs.py +2 -1
- exonware/xwsystem/http_client/errors.py +2 -1
- exonware/xwsystem/http_client/facade.py +156 -0
- exonware/xwsystem/io/__init__.py +22 -3
- exonware/xwsystem/io/archive/__init__.py +8 -2
- exonware/xwsystem/io/archive/archive.py +1 -1
- exonware/xwsystem/io/archive/archive_files.py +4 -7
- exonware/xwsystem/io/archive/archivers.py +120 -10
- exonware/xwsystem/io/archive/base.py +4 -5
- exonware/xwsystem/io/archive/codec_integration.py +1 -2
- exonware/xwsystem/io/archive/compression.py +1 -2
- exonware/xwsystem/io/archive/facade.py +263 -0
- exonware/xwsystem/io/archive/formats/__init__.py +2 -3
- exonware/xwsystem/io/archive/formats/brotli_format.py +20 -7
- exonware/xwsystem/io/archive/formats/lz4_format.py +20 -7
- exonware/xwsystem/io/archive/formats/rar.py +11 -5
- exonware/xwsystem/io/archive/formats/sevenzip.py +12 -6
- exonware/xwsystem/io/archive/formats/squashfs_format.py +1 -2
- exonware/xwsystem/io/archive/formats/tar.py +52 -7
- exonware/xwsystem/io/archive/formats/wim_format.py +11 -5
- exonware/xwsystem/io/archive/formats/zip.py +1 -2
- exonware/xwsystem/io/archive/formats/zpaq_format.py +1 -2
- exonware/xwsystem/io/archive/formats/zstandard.py +20 -7
- exonware/xwsystem/io/base.py +119 -115
- exonware/xwsystem/io/codec/__init__.py +4 -2
- exonware/xwsystem/io/codec/base.py +19 -13
- exonware/xwsystem/io/codec/contracts.py +59 -2
- exonware/xwsystem/io/codec/registry.py +67 -21
- exonware/xwsystem/io/common/__init__.py +1 -1
- exonware/xwsystem/io/common/atomic.py +29 -16
- exonware/xwsystem/io/common/base.py +11 -10
- exonware/xwsystem/io/common/lock.py +6 -5
- exonware/xwsystem/io/common/path_manager.py +2 -1
- exonware/xwsystem/io/common/watcher.py +1 -2
- exonware/xwsystem/io/contracts.py +301 -433
- exonware/xwsystem/io/contracts_1.py +1180 -0
- exonware/xwsystem/io/data_operations.py +279 -14
- exonware/xwsystem/io/defs.py +4 -3
- exonware/xwsystem/io/errors.py +3 -2
- exonware/xwsystem/io/facade.py +87 -61
- exonware/xwsystem/io/file/__init__.py +1 -1
- exonware/xwsystem/io/file/base.py +8 -9
- exonware/xwsystem/io/file/conversion.py +2 -3
- exonware/xwsystem/io/file/file.py +61 -18
- exonware/xwsystem/io/file/paged_source.py +8 -8
- exonware/xwsystem/io/file/paging/__init__.py +1 -2
- exonware/xwsystem/io/file/paging/byte_paging.py +4 -5
- exonware/xwsystem/io/file/paging/line_paging.py +2 -3
- exonware/xwsystem/io/file/paging/record_paging.py +2 -3
- exonware/xwsystem/io/file/paging/registry.py +1 -2
- exonware/xwsystem/io/file/source.py +13 -17
- exonware/xwsystem/io/filesystem/__init__.py +1 -1
- exonware/xwsystem/io/filesystem/base.py +1 -2
- exonware/xwsystem/io/filesystem/local.py +3 -4
- exonware/xwsystem/io/folder/__init__.py +1 -1
- exonware/xwsystem/io/folder/base.py +1 -2
- exonware/xwsystem/io/folder/folder.py +16 -7
- exonware/xwsystem/io/indexing/__init__.py +14 -0
- exonware/xwsystem/io/indexing/facade.py +443 -0
- exonware/xwsystem/io/path_parser.py +98 -0
- exonware/xwsystem/io/serialization/__init__.py +21 -3
- exonware/xwsystem/io/serialization/auto_serializer.py +146 -20
- exonware/xwsystem/io/serialization/base.py +84 -34
- exonware/xwsystem/io/serialization/contracts.py +50 -73
- exonware/xwsystem/io/serialization/defs.py +2 -1
- exonware/xwsystem/io/serialization/errors.py +2 -1
- exonware/xwsystem/io/serialization/flyweight.py +154 -7
- exonware/xwsystem/io/serialization/format_detector.py +15 -14
- exonware/xwsystem/io/serialization/formats/__init__.py +8 -5
- exonware/xwsystem/io/serialization/formats/binary/bson.py +15 -6
- exonware/xwsystem/io/serialization/formats/binary/cbor.py +5 -5
- exonware/xwsystem/io/serialization/formats/binary/marshal.py +5 -5
- exonware/xwsystem/io/serialization/formats/binary/msgpack.py +5 -5
- exonware/xwsystem/io/serialization/formats/binary/pickle.py +5 -5
- exonware/xwsystem/io/serialization/formats/binary/plistlib.py +5 -5
- exonware/xwsystem/io/serialization/formats/database/dbm.py +7 -7
- exonware/xwsystem/io/serialization/formats/database/shelve.py +7 -7
- exonware/xwsystem/io/serialization/formats/database/sqlite3.py +7 -7
- exonware/xwsystem/io/serialization/formats/tabular/__init__.py +27 -0
- exonware/xwsystem/io/serialization/formats/tabular/base.py +89 -0
- exonware/xwsystem/io/serialization/formats/tabular/csv.py +319 -0
- exonware/xwsystem/io/serialization/formats/tabular/df.py +249 -0
- exonware/xwsystem/io/serialization/formats/tabular/excel.py +291 -0
- exonware/xwsystem/io/serialization/formats/tabular/googlesheets.py +374 -0
- exonware/xwsystem/io/serialization/formats/text/__init__.py +1 -1
- exonware/xwsystem/io/serialization/formats/text/append_only_log.py +199 -0
- exonware/xwsystem/io/serialization/formats/text/configparser.py +5 -5
- exonware/xwsystem/io/serialization/formats/text/csv.py +7 -5
- exonware/xwsystem/io/serialization/formats/text/formdata.py +5 -5
- exonware/xwsystem/io/serialization/formats/text/json.py +65 -33
- exonware/xwsystem/io/serialization/formats/text/json5.py +8 -4
- exonware/xwsystem/io/serialization/formats/text/jsonlines.py +113 -25
- exonware/xwsystem/io/serialization/formats/text/multipart.py +5 -5
- exonware/xwsystem/io/serialization/formats/text/toml.py +8 -6
- exonware/xwsystem/io/serialization/formats/text/xml.py +25 -20
- exonware/xwsystem/io/serialization/formats/text/yaml.py +8 -6
- exonware/xwsystem/io/serialization/parsers/__init__.py +16 -0
- exonware/xwsystem/io/serialization/parsers/base.py +60 -0
- exonware/xwsystem/io/serialization/parsers/hybrid_parser.py +62 -0
- exonware/xwsystem/io/serialization/parsers/msgspec_parser.py +48 -0
- exonware/xwsystem/io/serialization/parsers/orjson_direct_parser.py +54 -0
- exonware/xwsystem/io/serialization/parsers/orjson_parser.py +62 -0
- exonware/xwsystem/io/serialization/parsers/pysimdjson_parser.py +55 -0
- exonware/xwsystem/io/serialization/parsers/rapidjson_parser.py +53 -0
- exonware/xwsystem/io/serialization/parsers/registry.py +91 -0
- exonware/xwsystem/io/serialization/parsers/standard.py +44 -0
- exonware/xwsystem/io/serialization/parsers/ujson_parser.py +53 -0
- exonware/xwsystem/io/serialization/registry.py +4 -4
- exonware/xwsystem/io/serialization/serializer.py +168 -79
- exonware/xwsystem/io/serialization/universal_options.py +367 -0
- exonware/xwsystem/io/serialization/utils/__init__.py +1 -2
- exonware/xwsystem/io/serialization/utils/path_ops.py +5 -6
- exonware/xwsystem/io/source_reader.py +223 -0
- exonware/xwsystem/io/stream/__init__.py +1 -1
- exonware/xwsystem/io/stream/async_operations.py +61 -14
- exonware/xwsystem/io/stream/base.py +1 -2
- exonware/xwsystem/io/stream/codec_io.py +6 -7
- exonware/xwsystem/ipc/__init__.py +1 -0
- exonware/xwsystem/ipc/async_fabric.py +4 -4
- exonware/xwsystem/ipc/base.py +6 -5
- exonware/xwsystem/ipc/contracts.py +41 -66
- exonware/xwsystem/ipc/defs.py +2 -1
- exonware/xwsystem/ipc/errors.py +2 -1
- exonware/xwsystem/ipc/message_queue.py +5 -2
- exonware/xwsystem/ipc/pipes.py +70 -34
- exonware/xwsystem/ipc/process_manager.py +7 -5
- exonware/xwsystem/ipc/process_pool.py +6 -5
- exonware/xwsystem/ipc/shared_memory.py +64 -11
- exonware/xwsystem/monitoring/__init__.py +7 -0
- exonware/xwsystem/monitoring/base.py +11 -8
- exonware/xwsystem/monitoring/contracts.py +86 -144
- exonware/xwsystem/monitoring/defs.py +2 -1
- exonware/xwsystem/monitoring/error_recovery.py +16 -3
- exonware/xwsystem/monitoring/errors.py +2 -1
- exonware/xwsystem/monitoring/facade.py +183 -0
- exonware/xwsystem/monitoring/memory_monitor.py +1 -0
- exonware/xwsystem/monitoring/metrics.py +1 -0
- exonware/xwsystem/monitoring/performance_manager_generic.py +7 -7
- exonware/xwsystem/monitoring/performance_monitor.py +1 -0
- exonware/xwsystem/monitoring/performance_validator.py +1 -0
- exonware/xwsystem/monitoring/system_monitor.py +6 -5
- exonware/xwsystem/monitoring/tracing.py +18 -16
- exonware/xwsystem/monitoring/tracker.py +2 -1
- exonware/xwsystem/operations/__init__.py +5 -50
- exonware/xwsystem/operations/base.py +3 -44
- exonware/xwsystem/operations/contracts.py +25 -15
- exonware/xwsystem/operations/defs.py +1 -1
- exonware/xwsystem/operations/diff.py +5 -4
- exonware/xwsystem/operations/errors.py +1 -1
- exonware/xwsystem/operations/merge.py +6 -4
- exonware/xwsystem/operations/patch.py +5 -4
- exonware/xwsystem/patterns/__init__.py +1 -0
- exonware/xwsystem/patterns/base.py +2 -1
- exonware/xwsystem/patterns/context_manager.py +2 -1
- exonware/xwsystem/patterns/contracts.py +215 -256
- exonware/xwsystem/patterns/defs.py +2 -1
- exonware/xwsystem/patterns/dynamic_facade.py +1 -0
- exonware/xwsystem/patterns/errors.py +2 -4
- exonware/xwsystem/patterns/handler_factory.py +2 -3
- exonware/xwsystem/patterns/import_registry.py +1 -0
- exonware/xwsystem/patterns/object_pool.py +1 -0
- exonware/xwsystem/patterns/registry.py +4 -43
- exonware/xwsystem/plugins/__init__.py +2 -1
- exonware/xwsystem/plugins/base.py +6 -5
- exonware/xwsystem/plugins/contracts.py +94 -158
- exonware/xwsystem/plugins/defs.py +2 -1
- exonware/xwsystem/plugins/errors.py +2 -1
- exonware/xwsystem/py.typed +3 -0
- exonware/xwsystem/query/__init__.py +36 -0
- exonware/xwsystem/query/contracts.py +56 -0
- exonware/xwsystem/query/errors.py +22 -0
- exonware/xwsystem/query/registry.py +128 -0
- exonware/xwsystem/runtime/__init__.py +2 -1
- exonware/xwsystem/runtime/base.py +4 -3
- exonware/xwsystem/runtime/contracts.py +39 -60
- exonware/xwsystem/runtime/defs.py +2 -1
- exonware/xwsystem/runtime/env.py +11 -9
- exonware/xwsystem/runtime/errors.py +2 -1
- exonware/xwsystem/runtime/reflection.py +3 -2
- exonware/xwsystem/security/__init__.py +68 -11
- exonware/xwsystem/security/audit.py +167 -0
- exonware/xwsystem/security/base.py +121 -24
- exonware/xwsystem/security/contracts.py +91 -146
- exonware/xwsystem/security/crypto.py +17 -16
- exonware/xwsystem/security/defs.py +2 -1
- exonware/xwsystem/security/errors.py +2 -1
- exonware/xwsystem/security/facade.py +321 -0
- exonware/xwsystem/security/file_security.py +330 -0
- exonware/xwsystem/security/hazmat.py +11 -8
- exonware/xwsystem/security/monitor.py +372 -0
- exonware/xwsystem/security/path_validator.py +140 -18
- exonware/xwsystem/security/policy.py +357 -0
- exonware/xwsystem/security/resource_limits.py +1 -0
- exonware/xwsystem/security/validator.py +455 -0
- exonware/xwsystem/shared/__init__.py +14 -1
- exonware/xwsystem/shared/base.py +285 -2
- exonware/xwsystem/shared/contracts.py +415 -126
- exonware/xwsystem/shared/defs.py +2 -1
- exonware/xwsystem/shared/errors.py +2 -2
- exonware/xwsystem/shared/xwobject.py +316 -0
- exonware/xwsystem/structures/__init__.py +1 -0
- exonware/xwsystem/structures/base.py +3 -2
- exonware/xwsystem/structures/circular_detector.py +15 -14
- exonware/xwsystem/structures/contracts.py +53 -76
- exonware/xwsystem/structures/defs.py +2 -1
- exonware/xwsystem/structures/errors.py +2 -1
- exonware/xwsystem/structures/tree_walker.py +2 -1
- exonware/xwsystem/threading/__init__.py +21 -4
- exonware/xwsystem/threading/async_primitives.py +6 -5
- exonware/xwsystem/threading/base.py +3 -2
- exonware/xwsystem/threading/contracts.py +87 -143
- exonware/xwsystem/threading/defs.py +2 -1
- exonware/xwsystem/threading/errors.py +2 -1
- exonware/xwsystem/threading/facade.py +175 -0
- exonware/xwsystem/threading/locks.py +1 -0
- exonware/xwsystem/threading/safe_factory.py +1 -0
- exonware/xwsystem/utils/__init__.py +40 -0
- exonware/xwsystem/utils/base.py +22 -21
- exonware/xwsystem/utils/contracts.py +50 -73
- exonware/xwsystem/utils/dt/__init__.py +19 -3
- exonware/xwsystem/utils/dt/base.py +5 -4
- exonware/xwsystem/utils/dt/contracts.py +22 -29
- exonware/xwsystem/utils/dt/defs.py +2 -1
- exonware/xwsystem/utils/dt/errors.py +2 -5
- exonware/xwsystem/utils/dt/formatting.py +88 -2
- exonware/xwsystem/utils/dt/humanize.py +10 -9
- exonware/xwsystem/utils/dt/parsing.py +56 -5
- exonware/xwsystem/utils/dt/timezone_utils.py +2 -24
- exonware/xwsystem/utils/errors.py +2 -4
- exonware/xwsystem/utils/paths.py +1 -0
- exonware/xwsystem/utils/string.py +49 -0
- exonware/xwsystem/utils/test_runner.py +139 -480
- exonware/xwsystem/utils/utils_contracts.py +2 -1
- exonware/xwsystem/utils/web.py +110 -0
- exonware/xwsystem/validation/__init__.py +25 -1
- exonware/xwsystem/validation/base.py +6 -5
- exonware/xwsystem/validation/contracts.py +29 -41
- exonware/xwsystem/validation/data_validator.py +1 -0
- exonware/xwsystem/validation/declarative.py +11 -8
- exonware/xwsystem/validation/defs.py +2 -1
- exonware/xwsystem/validation/errors.py +2 -1
- exonware/xwsystem/validation/facade.py +198 -0
- exonware/xwsystem/validation/fluent_validator.py +22 -19
- exonware/xwsystem/validation/schema_discovery.py +210 -0
- exonware/xwsystem/validation/type_safety.py +2 -1
- exonware/xwsystem/version.py +4 -4
- {exonware_xwsystem-0.0.1.411.dist-info → exonware_xwsystem-0.1.0.3.dist-info}/METADATA +71 -4
- exonware_xwsystem-0.1.0.3.dist-info/RECORD +337 -0
- exonware/xwsystem/caching/USAGE_GUIDE.md +0 -779
- exonware/xwsystem/cli/__init__.py +0 -43
- exonware/xwsystem/cli/console.py +0 -113
- exonware/xwsystem/cli/defs.py +0 -134
- exonware/xwsystem/conf.py +0 -44
- exonware/xwsystem/security/auth.py +0 -484
- exonware_xwsystem-0.0.1.411.dist-info/RECORD +0 -274
- {exonware_xwsystem-0.0.1.411.dist-info → exonware_xwsystem-0.1.0.3.dist-info}/WHEEL +0 -0
- {exonware_xwsystem-0.0.1.411.dist-info → exonware_xwsystem-0.1.0.3.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
#exonware/xwsystem/src/exonware/xwsystem/io/serialization/serializer.py
|
|
1
2
|
"""
|
|
2
3
|
Company: eXonware.com
|
|
3
4
|
Author: Eng. Muhammad AlShehri
|
|
4
5
|
Email: connect@exonware.com
|
|
5
|
-
Version: 0.0.
|
|
6
|
+
Version: 0.1.0.3
|
|
6
7
|
Generation Date: September 04, 2025
|
|
7
8
|
|
|
8
9
|
XWSerializer - Unified intelligent serializer with I/O integration and auto-serialization.
|
|
@@ -11,7 +12,7 @@ XWSerializer - Unified intelligent serializer with I/O integration and auto-seri
|
|
|
11
12
|
import os
|
|
12
13
|
import time
|
|
13
14
|
from pathlib import Path
|
|
14
|
-
from typing import Any, Optional,
|
|
15
|
+
from typing import Any, Optional, Callable
|
|
15
16
|
|
|
16
17
|
from .base import ASerialization
|
|
17
18
|
from .contracts import ISerialization
|
|
@@ -48,25 +49,40 @@ class XWSerializer(ASerialization):
|
|
|
48
49
|
This replaces both XWSerialization and the old XWSerializer concept.
|
|
49
50
|
"""
|
|
50
51
|
|
|
51
|
-
def __init__(self, confidence_threshold: float = 0.7, **config):
|
|
52
|
+
def __init__(self, format: Optional[str] = None, confidence_threshold: float = 0.7, **config):
|
|
52
53
|
"""
|
|
53
54
|
Initialize unified XWSerializer.
|
|
54
55
|
|
|
55
56
|
Args:
|
|
57
|
+
format: Optional format name ("json", "yaml", etc.) - auto-detected if None
|
|
56
58
|
confidence_threshold: Minimum confidence for format detection
|
|
57
59
|
**config: Configuration options for serialization and I/O
|
|
58
60
|
"""
|
|
59
61
|
super().__init__()
|
|
60
62
|
|
|
63
|
+
# Store format for later use
|
|
64
|
+
self._requested_format = format.lower() if format else None
|
|
65
|
+
|
|
61
66
|
# Initialize format detection (from XWSerialization)
|
|
62
67
|
self._detector = FormatDetector(confidence_threshold)
|
|
63
68
|
self._specialized_serializer: Optional[ISerialization] = None
|
|
64
69
|
self._detected_format: Optional[str] = None
|
|
65
70
|
self._confidence_threshold = confidence_threshold
|
|
66
71
|
|
|
72
|
+
# If format specified, create specialized serializer immediately
|
|
73
|
+
if self._requested_format:
|
|
74
|
+
try:
|
|
75
|
+
from .flyweight import create_serializer
|
|
76
|
+
self._specialized_serializer = create_serializer(self._requested_format)
|
|
77
|
+
self._detected_format = self._requested_format
|
|
78
|
+
except Exception as e:
|
|
79
|
+
logger.warning(f"Could not create serializer for format '{format}': {e}")
|
|
80
|
+
|
|
67
81
|
# Initialize I/O components (from XWSerializer)
|
|
68
|
-
|
|
69
|
-
self.
|
|
82
|
+
# Use XWIO facade - file_manager and unified_io features are optional
|
|
83
|
+
self._io = XWIO(**config) if config.get('use_io', True) else None
|
|
84
|
+
self._file_manager = None # Optional - not implemented yet
|
|
85
|
+
self._unified_io = None # Optional - not implemented yet
|
|
70
86
|
|
|
71
87
|
# Initialize xwsystem utilities
|
|
72
88
|
self._path_validator = PathValidator()
|
|
@@ -75,8 +91,8 @@ class XWSerializer(ASerialization):
|
|
|
75
91
|
# Configuration
|
|
76
92
|
self.auto_serialize = config.get('auto_serialize', True)
|
|
77
93
|
self.auto_detect_format = config.get('auto_detect_format', True)
|
|
78
|
-
self.use_file_manager = config.get('use_file_manager',
|
|
79
|
-
self.use_unified_io = config.get('use_unified_io',
|
|
94
|
+
self.use_file_manager = config.get('use_file_manager', False) # Disabled - not implemented
|
|
95
|
+
self.use_unified_io = config.get('use_unified_io', False) # Disabled - not implemented
|
|
80
96
|
self.enable_backups = config.get('enable_backups', True)
|
|
81
97
|
self.use_atomic_operations = config.get('use_atomic_operations', True)
|
|
82
98
|
self.validate_paths = config.get('validate_paths', True)
|
|
@@ -147,8 +163,8 @@ class XWSerializer(ASerialization):
|
|
|
147
163
|
def _transform_to_specialized(
|
|
148
164
|
self,
|
|
149
165
|
format_name: str,
|
|
150
|
-
file_path: Optional[
|
|
151
|
-
content: Optional[
|
|
166
|
+
file_path: Optional[str | Path] = None,
|
|
167
|
+
content: Optional[str | bytes] = None,
|
|
152
168
|
data: Optional[bytes] = None
|
|
153
169
|
) -> None:
|
|
154
170
|
"""Transform this instance into a specialized serializer."""
|
|
@@ -181,8 +197,8 @@ class XWSerializer(ASerialization):
|
|
|
181
197
|
def _detect_and_transform(
|
|
182
198
|
self,
|
|
183
199
|
data: Optional[Any] = None,
|
|
184
|
-
file_path: Optional[
|
|
185
|
-
content: Optional[
|
|
200
|
+
file_path: Optional[str | Path] = None,
|
|
201
|
+
content: Optional[str | bytes] = None,
|
|
186
202
|
binary_data: Optional[bytes] = None,
|
|
187
203
|
format_hint: Optional[str] = None
|
|
188
204
|
) -> None:
|
|
@@ -210,7 +226,7 @@ class XWSerializer(ASerialization):
|
|
|
210
226
|
elif isinstance(data, str):
|
|
211
227
|
format_name = 'JSON' # Assume JSON string
|
|
212
228
|
elif isinstance(data, bytes):
|
|
213
|
-
format_name = 'MessagePack' #
|
|
229
|
+
format_name = 'MessagePack' # Binary format default
|
|
214
230
|
else:
|
|
215
231
|
format_name = 'JSON' # Safe default
|
|
216
232
|
else:
|
|
@@ -232,7 +248,7 @@ class XWSerializer(ASerialization):
|
|
|
232
248
|
# AUTO-SERIALIZATION METHODS (Enhanced)
|
|
233
249
|
# ============================================================================
|
|
234
250
|
|
|
235
|
-
def auto_serialize(self, data: Any, file_path:
|
|
251
|
+
def auto_serialize(self, data: Any, file_path: str | Path,
|
|
236
252
|
format_hint: Optional[str] = None) -> bool:
|
|
237
253
|
"""Automatically serialize data to file with format detection."""
|
|
238
254
|
if not self.auto_serialize:
|
|
@@ -264,22 +280,27 @@ class XWSerializer(ASerialization):
|
|
|
264
280
|
logger.debug(f"Auto-serialized to {target_path} as {format_hint}")
|
|
265
281
|
return True
|
|
266
282
|
else:
|
|
267
|
-
# Use
|
|
268
|
-
if self.
|
|
269
|
-
self.
|
|
270
|
-
logger.debug(f"Auto-saved to {target_path} using
|
|
283
|
+
# Use XWIO for other formats
|
|
284
|
+
if self._io:
|
|
285
|
+
self._io.save_file(data, target_path)
|
|
286
|
+
logger.debug(f"Auto-saved to {target_path} using XWIO")
|
|
271
287
|
return True
|
|
272
288
|
else:
|
|
273
|
-
# Fallback to
|
|
274
|
-
self.
|
|
275
|
-
|
|
289
|
+
# Fallback to specialized serializer
|
|
290
|
+
specialized = self._ensure_specialized(
|
|
291
|
+
data=data,
|
|
292
|
+
file_path=target_path,
|
|
293
|
+
format_hint=format_hint
|
|
294
|
+
)
|
|
295
|
+
specialized.save_file(data, target_path)
|
|
296
|
+
logger.debug(f"Auto-saved to {target_path} using specialized serializer")
|
|
276
297
|
return True
|
|
277
298
|
|
|
278
299
|
except Exception as e:
|
|
279
300
|
logger.error(f"Auto-serialization failed for {target_path}: {e}")
|
|
280
301
|
return False
|
|
281
302
|
|
|
282
|
-
def auto_deserialize(self, file_path:
|
|
303
|
+
def auto_deserialize(self, file_path: str | Path,
|
|
283
304
|
format_hint: Optional[str] = None) -> Any:
|
|
284
305
|
"""Automatically deserialize data from file with format detection."""
|
|
285
306
|
if not self.auto_serialize:
|
|
@@ -310,15 +331,19 @@ class XWSerializer(ASerialization):
|
|
|
310
331
|
logger.debug(f"Auto-deserialized from {target_path} as {format_hint}")
|
|
311
332
|
return data
|
|
312
333
|
else:
|
|
313
|
-
# Use
|
|
314
|
-
if self.
|
|
315
|
-
data = self.
|
|
316
|
-
logger.debug(f"Auto-loaded from {target_path} using
|
|
334
|
+
# Use XWIO for other formats
|
|
335
|
+
if self._io:
|
|
336
|
+
data = self._io.load_file(target_path)
|
|
337
|
+
logger.debug(f"Auto-loaded from {target_path} using XWIO")
|
|
317
338
|
return data
|
|
318
339
|
else:
|
|
319
|
-
# Fallback to
|
|
320
|
-
|
|
321
|
-
|
|
340
|
+
# Fallback to specialized serializer
|
|
341
|
+
specialized = self._ensure_specialized(
|
|
342
|
+
file_path=target_path,
|
|
343
|
+
format_hint=format_hint
|
|
344
|
+
)
|
|
345
|
+
data = specialized.load_file(target_path)
|
|
346
|
+
logger.debug(f"Auto-loaded from {target_path} using specialized serializer")
|
|
322
347
|
return data
|
|
323
348
|
|
|
324
349
|
except Exception as e:
|
|
@@ -359,12 +384,29 @@ class XWSerializer(ASerialization):
|
|
|
359
384
|
|
|
360
385
|
return format_mappings.get(ext)
|
|
361
386
|
|
|
387
|
+
# ============================================================================
|
|
388
|
+
# ABSTRACT METHOD IMPLEMENTATIONS (encode/decode)
|
|
389
|
+
# ============================================================================
|
|
390
|
+
|
|
391
|
+
def encode(self, value: Any, *, options: Optional[Any] = None) -> bytes | str:
|
|
392
|
+
"""Encode data - delegates to specialized serializer."""
|
|
393
|
+
specialized = self._ensure_specialized(data=value)
|
|
394
|
+
return specialized.encode(value, options=options)
|
|
395
|
+
|
|
396
|
+
def decode(self, repr: bytes | str, *, options: Optional[Any] = None) -> Any:
|
|
397
|
+
"""Decode data - delegates to specialized serializer."""
|
|
398
|
+
specialized = self._ensure_specialized(
|
|
399
|
+
content=repr if isinstance(repr, str) else None,
|
|
400
|
+
binary_data=repr if isinstance(repr, bytes) else None
|
|
401
|
+
)
|
|
402
|
+
return specialized.decode(repr, options=options)
|
|
403
|
+
|
|
362
404
|
# ============================================================================
|
|
363
405
|
# CORE SERIALIZATION METHODS (Unified)
|
|
364
406
|
# ============================================================================
|
|
365
407
|
|
|
366
|
-
def dumps(self, data: Any, file_path: Optional[
|
|
367
|
-
format_hint: Optional[str] = None) ->
|
|
408
|
+
def dumps(self, data: Any, file_path: Optional[str | Path] = None,
|
|
409
|
+
format_hint: Optional[str] = None) -> str | bytes:
|
|
368
410
|
"""Unified serialize with I/O integration."""
|
|
369
411
|
if file_path and self.auto_serialize:
|
|
370
412
|
# Use auto-serialization for file operations
|
|
@@ -379,7 +421,7 @@ class XWSerializer(ASerialization):
|
|
|
379
421
|
)
|
|
380
422
|
return specialized.dumps(data)
|
|
381
423
|
|
|
382
|
-
def loads(self, data:
|
|
424
|
+
def loads(self, data: str | bytes, format_hint: Optional[str] = None) -> Any:
|
|
383
425
|
"""Unified deserialize with I/O integration."""
|
|
384
426
|
specialized = self._ensure_specialized(
|
|
385
427
|
content=data,
|
|
@@ -388,7 +430,7 @@ class XWSerializer(ASerialization):
|
|
|
388
430
|
)
|
|
389
431
|
return specialized.loads(data)
|
|
390
432
|
|
|
391
|
-
def save_file(self, data: Any, file_path:
|
|
433
|
+
def save_file(self, data: Any, file_path: str | Path,
|
|
392
434
|
format_hint: Optional[str] = None) -> None:
|
|
393
435
|
"""Enhanced save file with backup and atomic operations."""
|
|
394
436
|
target_path = Path(file_path)
|
|
@@ -401,13 +443,17 @@ class XWSerializer(ASerialization):
|
|
|
401
443
|
|
|
402
444
|
with performance_monitor("save_file"):
|
|
403
445
|
try:
|
|
404
|
-
# Create backup if enabled
|
|
405
|
-
if self.enable_backups and target_path.exists():
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
446
|
+
# Create backup if enabled (using XWIO if available)
|
|
447
|
+
if self.enable_backups and target_path.exists() and self._io:
|
|
448
|
+
try:
|
|
449
|
+
backup_dir = target_path.parent / '.backups'
|
|
450
|
+
backup_dir.mkdir(exist_ok=True)
|
|
451
|
+
backup_path = backup_dir / f"{target_path.name}.backup"
|
|
452
|
+
import shutil
|
|
453
|
+
shutil.copy2(target_path, backup_path)
|
|
410
454
|
logger.debug(f"Created backup: {backup_path}")
|
|
455
|
+
except Exception as e:
|
|
456
|
+
logger.warning(f"Backup creation failed: {e}")
|
|
411
457
|
|
|
412
458
|
# Use auto-serialization if enabled
|
|
413
459
|
if self.auto_serialize:
|
|
@@ -426,7 +472,7 @@ class XWSerializer(ASerialization):
|
|
|
426
472
|
logger.error(f"Save file failed for {target_path}: {e}")
|
|
427
473
|
raise SerializationError(f"Save file failed: {e}")
|
|
428
474
|
|
|
429
|
-
def load_file(self, file_path:
|
|
475
|
+
def load_file(self, file_path: str | Path,
|
|
430
476
|
format_hint: Optional[str] = None) -> Any:
|
|
431
477
|
"""Enhanced load file with validation and monitoring."""
|
|
432
478
|
target_path = Path(file_path)
|
|
@@ -454,6 +500,24 @@ class XWSerializer(ASerialization):
|
|
|
454
500
|
logger.error(f"Load file failed for {target_path}: {e}")
|
|
455
501
|
raise SerializationError(f"Load file failed: {e}")
|
|
456
502
|
|
|
503
|
+
# ============================================================================
|
|
504
|
+
# ABSTRACT PROPERTY IMPLEMENTATIONS
|
|
505
|
+
# ============================================================================
|
|
506
|
+
|
|
507
|
+
@property
|
|
508
|
+
def codec_id(self) -> str:
|
|
509
|
+
"""Codec identifier - delegates to specialized serializer."""
|
|
510
|
+
if self._specialized_serializer is None:
|
|
511
|
+
return "auto-detect"
|
|
512
|
+
return self._specialized_serializer.codec_id
|
|
513
|
+
|
|
514
|
+
@property
|
|
515
|
+
def media_types(self) -> list[str]:
|
|
516
|
+
"""Supported MIME types - delegates to specialized serializer."""
|
|
517
|
+
if self._specialized_serializer is None:
|
|
518
|
+
return ["application/octet-stream"] # Generic until detection
|
|
519
|
+
return self._specialized_serializer.media_types
|
|
520
|
+
|
|
457
521
|
# ============================================================================
|
|
458
522
|
# PROPERTY DELEGATION (from XWSerialization)
|
|
459
523
|
# ============================================================================
|
|
@@ -497,27 +561,43 @@ class XWSerializer(ASerialization):
|
|
|
497
561
|
# FILE MANAGER INTEGRATION
|
|
498
562
|
# ============================================================================
|
|
499
563
|
|
|
500
|
-
def process_file(self, file_path:
|
|
501
|
-
"""Process file using
|
|
502
|
-
|
|
564
|
+
def process_file(self, file_path: str | Path, operation: str = 'info') -> dict[str, Any]:
|
|
565
|
+
"""Process file using XWIO."""
|
|
566
|
+
if self._io:
|
|
567
|
+
return self._io.get_file_info(file_path)
|
|
568
|
+
return {"path": str(file_path), "operation": operation}
|
|
503
569
|
|
|
504
|
-
def get_file_info(self, file_path:
|
|
570
|
+
def get_file_info(self, file_path: str | Path) -> dict[str, Any]:
|
|
505
571
|
"""Get comprehensive file information."""
|
|
506
|
-
|
|
572
|
+
if self._io:
|
|
573
|
+
return self._io.get_file_info(file_path)
|
|
574
|
+
path = Path(file_path)
|
|
575
|
+
return {
|
|
576
|
+
"path": str(path),
|
|
577
|
+
"exists": path.exists(),
|
|
578
|
+
"size": path.stat().st_size if path.exists() else 0,
|
|
579
|
+
}
|
|
507
580
|
|
|
508
|
-
def detect_file_type(self, file_path:
|
|
509
|
-
"""Detect file type."""
|
|
510
|
-
|
|
581
|
+
def detect_file_type(self, file_path: str | Path) -> str:
|
|
582
|
+
"""Detect file type from extension."""
|
|
583
|
+
path = Path(file_path)
|
|
584
|
+
return path.suffix.lower() or "unknown"
|
|
511
585
|
|
|
512
|
-
def is_safe_to_process(self, file_path:
|
|
586
|
+
def is_safe_to_process(self, file_path: str | Path) -> bool:
|
|
513
587
|
"""Check if file is safe to process."""
|
|
514
|
-
|
|
588
|
+
if self.validate_paths:
|
|
589
|
+
try:
|
|
590
|
+
self._path_validator.validate_path(file_path)
|
|
591
|
+
return True
|
|
592
|
+
except Exception:
|
|
593
|
+
return False
|
|
594
|
+
return True
|
|
515
595
|
|
|
516
596
|
# ============================================================================
|
|
517
597
|
# UNIFIED I/O INTEGRATION
|
|
518
598
|
# ============================================================================
|
|
519
599
|
|
|
520
|
-
def atomic_save(self, data: Any, file_path:
|
|
600
|
+
def atomic_save(self, data: Any, file_path: str | Path,
|
|
521
601
|
backup: bool = True) -> OperationResult:
|
|
522
602
|
"""Atomically save data with backup."""
|
|
523
603
|
target_path = Path(file_path)
|
|
@@ -538,13 +618,21 @@ class XWSerializer(ASerialization):
|
|
|
538
618
|
else:
|
|
539
619
|
data_bytes = str(data).encode('utf-8')
|
|
540
620
|
|
|
541
|
-
|
|
621
|
+
# Use XWIO atomic write or specialized serializer
|
|
622
|
+
if self._io:
|
|
623
|
+
from ..common.atomic import safe_write_bytes
|
|
624
|
+
safe_write_bytes(target_path, data_bytes)
|
|
625
|
+
return OperationResult.SUCCESS
|
|
626
|
+
else:
|
|
627
|
+
# Fallback to direct write
|
|
628
|
+
target_path.write_bytes(data_bytes)
|
|
629
|
+
return OperationResult.SUCCESS
|
|
542
630
|
|
|
543
631
|
except Exception as e:
|
|
544
632
|
logger.error(f"Atomic save failed for {target_path}: {e}")
|
|
545
633
|
return OperationResult.FAILED
|
|
546
634
|
|
|
547
|
-
def atomic_load(self, file_path:
|
|
635
|
+
def atomic_load(self, file_path: str | Path) -> Any:
|
|
548
636
|
"""Atomically load data."""
|
|
549
637
|
target_path = Path(file_path)
|
|
550
638
|
|
|
@@ -556,8 +644,11 @@ class XWSerializer(ASerialization):
|
|
|
556
644
|
|
|
557
645
|
with performance_monitor("atomic_load"):
|
|
558
646
|
try:
|
|
559
|
-
# Load data
|
|
560
|
-
|
|
647
|
+
# Load data using XWIO or direct read
|
|
648
|
+
if self._io:
|
|
649
|
+
data = self._io.read_file(target_path)
|
|
650
|
+
else:
|
|
651
|
+
data = target_path.read_bytes()
|
|
561
652
|
|
|
562
653
|
# Try to deserialize if it's a supported format
|
|
563
654
|
if self.auto_serialize:
|
|
@@ -581,7 +672,7 @@ class XWSerializer(ASerialization):
|
|
|
581
672
|
|
|
582
673
|
def atomic_update_path(
|
|
583
674
|
self,
|
|
584
|
-
file_path:
|
|
675
|
+
file_path: str | Path,
|
|
585
676
|
path: str,
|
|
586
677
|
value: Any,
|
|
587
678
|
**options
|
|
@@ -628,7 +719,7 @@ class XWSerializer(ASerialization):
|
|
|
628
719
|
|
|
629
720
|
def atomic_read_path(
|
|
630
721
|
self,
|
|
631
|
-
file_path:
|
|
722
|
+
file_path: str | Path,
|
|
632
723
|
path: str,
|
|
633
724
|
**options
|
|
634
725
|
) -> Any:
|
|
@@ -681,7 +772,7 @@ class XWSerializer(ASerialization):
|
|
|
681
772
|
|
|
682
773
|
def query(
|
|
683
774
|
self,
|
|
684
|
-
file_path:
|
|
775
|
+
file_path: str | Path,
|
|
685
776
|
query_expr: str,
|
|
686
777
|
**options
|
|
687
778
|
) -> Any:
|
|
@@ -733,7 +824,7 @@ class XWSerializer(ASerialization):
|
|
|
733
824
|
|
|
734
825
|
def merge(
|
|
735
826
|
self,
|
|
736
|
-
file_path:
|
|
827
|
+
file_path: str | Path,
|
|
737
828
|
updates: dict[str, Any],
|
|
738
829
|
**options
|
|
739
830
|
) -> None:
|
|
@@ -782,7 +873,7 @@ class XWSerializer(ASerialization):
|
|
|
782
873
|
|
|
783
874
|
def stream_read_record(
|
|
784
875
|
self,
|
|
785
|
-
file_path:
|
|
876
|
+
file_path: str | Path,
|
|
786
877
|
match: callable,
|
|
787
878
|
projection: Optional[list[Any]] = None,
|
|
788
879
|
**options: Any,
|
|
@@ -823,7 +914,7 @@ class XWSerializer(ASerialization):
|
|
|
823
914
|
|
|
824
915
|
def stream_update_record(
|
|
825
916
|
self,
|
|
826
|
-
file_path:
|
|
917
|
+
file_path: str | Path,
|
|
827
918
|
match: callable,
|
|
828
919
|
updater: callable,
|
|
829
920
|
*,
|
|
@@ -868,7 +959,7 @@ class XWSerializer(ASerialization):
|
|
|
868
959
|
|
|
869
960
|
def get_record_page(
|
|
870
961
|
self,
|
|
871
|
-
file_path:
|
|
962
|
+
file_path: str | Path,
|
|
872
963
|
page_number: int,
|
|
873
964
|
page_size: int,
|
|
874
965
|
**options: Any,
|
|
@@ -909,7 +1000,7 @@ class XWSerializer(ASerialization):
|
|
|
909
1000
|
|
|
910
1001
|
def get_record_by_id(
|
|
911
1002
|
self,
|
|
912
|
-
file_path:
|
|
1003
|
+
file_path: str | Path,
|
|
913
1004
|
id_value: Any,
|
|
914
1005
|
*,
|
|
915
1006
|
id_field: str = "id",
|
|
@@ -952,7 +1043,7 @@ class XWSerializer(ASerialization):
|
|
|
952
1043
|
# BATCH OPERATIONS
|
|
953
1044
|
# ============================================================================
|
|
954
1045
|
|
|
955
|
-
def batch_save(self, data_dict: dict[
|
|
1046
|
+
def batch_save(self, data_dict: dict[str | Path, Any],
|
|
956
1047
|
format_hint: Optional[str] = None) -> dict[str, bool]:
|
|
957
1048
|
"""Save multiple files in batch."""
|
|
958
1049
|
results = {}
|
|
@@ -968,7 +1059,7 @@ class XWSerializer(ASerialization):
|
|
|
968
1059
|
|
|
969
1060
|
return results
|
|
970
1061
|
|
|
971
|
-
def batch_load(self, file_paths: list[
|
|
1062
|
+
def batch_load(self, file_paths: list[str | Path],
|
|
972
1063
|
format_hint: Optional[str] = None) -> dict[str, Any]:
|
|
973
1064
|
"""Load multiple files in batch."""
|
|
974
1065
|
results = {}
|
|
@@ -1004,19 +1095,17 @@ class XWSerializer(ASerialization):
|
|
|
1004
1095
|
'auto_serialize_extensions': self.auto_serialize_extensions,
|
|
1005
1096
|
'detected_format': self._detected_format,
|
|
1006
1097
|
'is_transformed': self.is_transformed(),
|
|
1007
|
-
'file_manager_info':
|
|
1008
|
-
'unified_io_info': self.
|
|
1098
|
+
'file_manager_info': None, # Not implemented
|
|
1099
|
+
'unified_io_info': {'io_available': self._io is not None}
|
|
1009
1100
|
}
|
|
1010
1101
|
|
|
1011
1102
|
def cleanup_all_resources(self) -> int:
|
|
1012
1103
|
"""Cleanup all resources."""
|
|
1013
1104
|
cleaned_count = 0
|
|
1014
1105
|
|
|
1015
|
-
# Cleanup
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
# Cleanup unified I/O resources
|
|
1019
|
-
cleaned_count += self._unified_io.cleanup_all_resources()
|
|
1106
|
+
# Cleanup is handled by specialized serializer if needed
|
|
1107
|
+
if self._specialized_serializer and hasattr(self._specialized_serializer, 'cleanup_all_resources'):
|
|
1108
|
+
cleaned_count += self._specialized_serializer.cleanup_all_resources()
|
|
1020
1109
|
|
|
1021
1110
|
logger.debug(f"XWSerializer cleaned up {cleaned_count} resources")
|
|
1022
1111
|
return cleaned_count
|
|
@@ -1139,34 +1228,34 @@ def _get_global_serializer() -> XWSerializer:
|
|
|
1139
1228
|
return _global_xw_serializer
|
|
1140
1229
|
|
|
1141
1230
|
# Static functions - clean API without prefixes
|
|
1142
|
-
def auto_serialize(data: Any, file_path:
|
|
1231
|
+
def auto_serialize(data: Any, file_path: str | Path, format_hint: Optional[str] = None) -> bool:
|
|
1143
1232
|
"""Auto-serialize data to file with format detection."""
|
|
1144
1233
|
return _get_global_serializer().auto_serialize(data, file_path, format_hint)
|
|
1145
1234
|
|
|
1146
|
-
def auto_deserialize(file_path:
|
|
1235
|
+
def auto_deserialize(file_path: str | Path, format_hint: Optional[str] = None) -> Any:
|
|
1147
1236
|
"""Auto-deserialize data from file with format detection."""
|
|
1148
1237
|
return _get_global_serializer().auto_deserialize(file_path, format_hint)
|
|
1149
1238
|
|
|
1150
|
-
def atomic_save(data: Any, file_path:
|
|
1239
|
+
def atomic_save(data: Any, file_path: str | Path, backup: bool = True) -> OperationResult:
|
|
1151
1240
|
"""Atomically save data with backup."""
|
|
1152
1241
|
return _get_global_serializer().atomic_save(data, file_path, backup)
|
|
1153
1242
|
|
|
1154
|
-
def atomic_load(file_path:
|
|
1243
|
+
def atomic_load(file_path: str | Path) -> Any:
|
|
1155
1244
|
"""Atomically load data."""
|
|
1156
1245
|
return _get_global_serializer().atomic_load(file_path)
|
|
1157
1246
|
|
|
1158
|
-
def dumps(data: Any, file_path: Optional[
|
|
1247
|
+
def dumps(data: Any, file_path: Optional[str | Path] = None, format_hint: Optional[str] = None) -> str | bytes:
|
|
1159
1248
|
"""Smart serialization function that auto-detects format."""
|
|
1160
1249
|
return _get_global_serializer().dumps(data, file_path, format_hint)
|
|
1161
1250
|
|
|
1162
|
-
def loads(data:
|
|
1251
|
+
def loads(data: str | bytes, format_hint: Optional[str] = None) -> Any:
|
|
1163
1252
|
"""Smart deserialization function that auto-detects format."""
|
|
1164
1253
|
return _get_global_serializer().loads(data, format_hint)
|
|
1165
1254
|
|
|
1166
|
-
def save_file(data: Any, file_path:
|
|
1255
|
+
def save_file(data: Any, file_path: str | Path, format_hint: Optional[str] = None) -> None:
|
|
1167
1256
|
"""Smart file saving that auto-detects format from extension."""
|
|
1168
1257
|
return _get_global_serializer().save_file(data, file_path, format_hint)
|
|
1169
1258
|
|
|
1170
|
-
def load_file(file_path:
|
|
1259
|
+
def load_file(file_path: str | Path, format_hint: Optional[str] = None) -> Any:
|
|
1171
1260
|
"""Smart file loading that auto-detects format from extension and content."""
|
|
1172
1261
|
return _get_global_serializer().load_file(file_path, format_hint)
|