nlbone 0.8.3__py3-none-any.whl → 0.8.4__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.
@@ -1,6 +1,7 @@
1
1
  import json
2
+ import re
2
3
  from math import ceil
3
- from typing import Any, List, Optional
4
+ from typing import Any, List, Optional, Dict, Union
4
5
 
5
6
  from fastapi import Query
6
7
 
@@ -53,36 +54,58 @@ class PaginateRequest:
53
54
  return result
54
55
 
55
56
  @staticmethod
56
- def _parse_filters(filters: str) -> dict[str, Any]:
57
+ def _parse_filters(filters: str) -> Dict[str, Any]:
57
58
  if not filters:
58
59
  return {}
59
- # JSON object or array
60
- try:
61
- if filters.strip().startswith(("{", "[")):
62
- data = json.loads(filters)
60
+
61
+ stripped_filters = filters.strip()
62
+
63
+ if stripped_filters.startswith(("{", "[")):
64
+ try:
65
+ data = json.loads(stripped_filters)
63
66
  return dict(data) if isinstance(data, dict) else {"$": data}
64
- except Exception:
65
- pass
67
+ except (json.JSONDecodeError, TypeError):
68
+ pass
69
+
70
+ pattern = re.compile(r"(?P<key>[^:,]+):\s*(?P<value>\[.*?\]|[^,]+)")
71
+ filters_dict: Dict[str, Any] = {}
72
+
73
+ for match in pattern.finditer(stripped_filters):
74
+ key = match.group("key").strip().strip("'\"")
75
+ value_raw = match.group("value").strip()
76
+
77
+ filters_dict[key] = PaginateRequest._process_value(value_raw)
66
78
 
67
- # CSV key:value pairs
68
- filters_dict: dict[str, Any] = {}
69
- for part in filters.split(","):
70
- part = part.strip()
71
- if not part or ":" not in part:
72
- continue
73
- key, value = part.split(":", 1)
74
- key = key.strip().strip("'\"")
75
- value_raw = value.strip().strip("'\"")
76
- # cast common primitives
77
- if value_raw.isdigit():
78
- value_cast: Any = int(value_raw)
79
- elif value_raw.lower() in {"true", "false"}:
80
- value_cast = value_raw.lower() == "true"
81
- else:
82
- value_cast = value_raw
83
- filters_dict[key] = value_cast
84
79
  return filters_dict
85
80
 
81
+ @staticmethod
82
+ def _process_value(value: str) -> Any:
83
+ if value.startswith("[") and value.endswith("]"):
84
+ content = value[1:-1]
85
+ if not content.strip():
86
+ return []
87
+ return [PaginateRequest._cast_primitive(item.strip()) for item in content.split(",")]
88
+
89
+ return PaginateRequest._cast_primitive(value)
90
+
91
+ @staticmethod
92
+ def _cast_primitive(value: str) -> Union[int, float, bool, str]:
93
+ clean_value = value.strip("'\"")
94
+ lower_value = clean_value.lower()
95
+
96
+ if lower_value == "true":
97
+ return True
98
+ if lower_value == "false":
99
+ return False
100
+
101
+ if clean_value.isdigit():
102
+ return int(clean_value)
103
+
104
+ try:
105
+ return float(clean_value)
106
+ except ValueError:
107
+ return clean_value
108
+
86
109
  def remove_deleted(self, deleted_at_field: str = "deleted_at"):
87
110
  self.filters = self.filters | {"deleted_at": None}
88
111
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nlbone
3
- Version: 0.8.3
3
+ Version: 0.8.4
4
4
  Summary: Backbone package for interfaces and infrastructure in Python projects
5
5
  Author-email: Amir Hosein Kahkbazzadeh <a.khakbazzadeh@gmail.com>
6
6
  License: MIT
@@ -91,7 +91,7 @@ nlbone/interfaces/api/middleware/access_log.py,sha256=vIkxxxfy2HcjqqKb8XCfGCcSri
91
91
  nlbone/interfaces/api/middleware/add_request_context.py,sha256=o8mdo-D6fODM9OyHunE5UodkVxsh4F__5tDv8ju8Sxg,1952
92
92
  nlbone/interfaces/api/middleware/authentication.py,sha256=Bt6sYu4KtXAyUQnSIp-Z2Z1yKNNtfRy9Y3rOZcYTFhw,3299
93
93
  nlbone/interfaces/api/pagination/__init__.py,sha256=pA1uC4rK6eqDI5IkLVxmgO2B6lExnOm8Pje2-hifJZw,431
94
- nlbone/interfaces/api/pagination/offset_base.py,sha256=60X8a9uDOSd3qG45M49dqNG_FUjSxEDrgEyb9JD9V-o,4113
94
+ nlbone/interfaces/api/pagination/offset_base.py,sha256=pdfNgmP99eFC5qCWyY1JgW8hNhOuEGnmrlvQPGArdj8,4709
95
95
  nlbone/interfaces/api/schema/__init__.py,sha256=LAqgynfupeqOQ6u0I5ucrcYnojRMZUg9yW8IjKSQTNI,119
96
96
  nlbone/interfaces/api/schema/adaptive_schema.py,sha256=bdWBNpP2NfOJ_in4btXn0lrZOK70x-OqfmZ-NpIJdoQ,3347
97
97
  nlbone/interfaces/api/schema/base_response_model.py,sha256=EpbxolYLeWgtmXaMbYuL-9FcRQdDtT0d8n_8SOXcoyk,1062
@@ -116,8 +116,8 @@ nlbone/utils/normalize_mobile.py,sha256=sGH4tV9gX-6eVKozviNWJhm1DN1J28Nj-ERldCYk
116
116
  nlbone/utils/read_files.py,sha256=mx8dfvtaaARQFRp_U7OOiERg-GT62h09_lpTzIQsVhs,291
117
117
  nlbone/utils/redactor.py,sha256=-V4HrHmHwPi3Kez587Ek1uJlgK35qGSrwBOvcbw8Jas,1279
118
118
  nlbone/utils/time.py,sha256=DjjyQ9GLsfXoT6NK8RDW2rOlJg3e6sF04Jw6PBUrSvg,1268
119
- nlbone-0.8.3.dist-info/METADATA,sha256=b7l7LGRljEWHWYG8N-qglOOfhmjfsOQfoJOpAA6_Og8,2294
120
- nlbone-0.8.3.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
121
- nlbone-0.8.3.dist-info/entry_points.txt,sha256=CpIL45t5nbhl1dGQPhfIIDfqqak3teK0SxPGBBr7YCk,59
122
- nlbone-0.8.3.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
123
- nlbone-0.8.3.dist-info/RECORD,,
119
+ nlbone-0.8.4.dist-info/METADATA,sha256=MzTXTMT3XbPIK5o3RH0uy28AQpzn-vj1dXRbZBFqa4I,2294
120
+ nlbone-0.8.4.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
121
+ nlbone-0.8.4.dist-info/entry_points.txt,sha256=CpIL45t5nbhl1dGQPhfIIDfqqak3teK0SxPGBBr7YCk,59
122
+ nlbone-0.8.4.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
123
+ nlbone-0.8.4.dist-info/RECORD,,
File without changes