fmtr.tools 1.3.14__py3-none-any.whl → 1.3.15__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.

Potentially problematic release.


This version of fmtr.tools might be problematic. Click here for more details.

@@ -3,6 +3,7 @@ from dataclasses import dataclass
3
3
  from dns import query
4
4
  from functools import cached_property
5
5
  from httpx_retries import Retry, RetryTransport
6
+ from typing import Optional
6
7
 
7
8
  from fmtr.tools import http_tools as http
8
9
  from fmtr.tools.dns_tools.dm import Exchange, Response
@@ -38,14 +39,17 @@ class Plain:
38
39
  """
39
40
  host: str
40
41
  port: int = 53
42
+ ttl_min: Optional[int] = None
41
43
 
42
44
  def resolve(self, exchange: Exchange):
43
45
 
44
46
  with logger.span(f'UDP {self.host}:{self.port}'):
45
47
  response_plain = query.udp(q=exchange.query_last, where=self.host, port=self.port)
46
48
  response = Response.from_message(response_plain)
49
+ for answer in response.message.answer:
50
+ answer.ttl = max(answer.ttl, self.ttl_min or answer.ttl)
47
51
 
48
- exchange.response.message.answer += response.message.answer
52
+ exchange.response = response
49
53
 
50
54
 
51
55
  @dataclass
@@ -86,7 +90,7 @@ class HTTP:
86
90
  response_doh = self.CLIENT.post(url, headers=headers, content=exchange.query_last.to_wire())
87
91
  response_doh.raise_for_status()
88
92
  response = Response.from_http(response_doh)
89
- exchange.response.message.answer += response.message.answer
93
+ exchange.response = response
90
94
 
91
95
  except Exception as exception:
92
96
  exchange.response.message.set_rcode(dnspython.rcode.SERVFAIL)
@@ -1,12 +1,12 @@
1
1
  import dns
2
2
  import httpx
3
- from dataclasses import dataclass
3
+ from dataclasses import dataclass, field
4
4
  from dns import rcode as dnsrcode
5
5
  from dns import reversename
6
6
  from dns.message import Message, QueryMessage
7
7
  from dns.rrset import RRset
8
8
  from functools import cached_property
9
- from typing import Self, Optional
9
+ from typing import Self, Optional, List
10
10
 
11
11
  from fmtr.tools.string_tools import join
12
12
 
@@ -37,7 +37,6 @@ class Response(BaseDNSData):
37
37
  """
38
38
 
39
39
  http: Optional[httpx.Response] = None
40
- is_complete: bool = False
41
40
  blocked_by: Optional[str] = None
42
41
 
43
42
  @classmethod
@@ -144,9 +143,10 @@ class Exchange:
144
143
 
145
144
  request: Request
146
145
  response: Optional[Response] = None
146
+ answers_pre: List[RRset] = field(default_factory=list)
147
147
  is_internal: bool = False
148
148
  client_name: Optional[str] = None
149
-
149
+ is_complete: bool = False
150
150
 
151
151
 
152
152
  @classmethod
@@ -166,8 +166,8 @@ class Exchange:
166
166
  Contrive an RRset representing the latest/current question. This can be the original question - or a hybrid one if we've injected our own answers into the exchange.
167
167
 
168
168
  """
169
- if self.response.answer:
170
- rrset = self.response.answer
169
+ if self.answers_pre:
170
+ rrset = self.answers_pre[-1]
171
171
  ty = self.request.type
172
172
  ttl = self.request.question.ttl
173
173
  rdclass = self.request.question.rdclass
@@ -178,7 +178,6 @@ class Exchange:
178
178
  ttl=ttl,
179
179
  rdtype=ty,
180
180
  rdclass=rdclass,
181
-
182
181
  )
183
182
 
184
183
  return rrset_contrived
@@ -194,7 +193,7 @@ class Exchange:
194
193
  """
195
194
 
196
195
  question_last = self.question_last
197
- query = dns.message.make_query(qname=question_last.name, rdclass=question_last.rdclass, rdtype=question_last.rdtype)
196
+ query = dns.message.make_query(qname=question_last.name, rdclass=question_last.rdclass, rdtype=question_last.rdtype, id=self.request.message.id)
198
197
  return query
199
198
 
200
199
  @property
@@ -31,6 +31,14 @@ class Proxy(server.Plain):
31
31
  """
32
32
  return
33
33
 
34
+ def finalize(self, exchange: Exchange):
35
+ """
36
+
37
+ Finalize a still open exchange.
38
+
39
+ """
40
+ exchange.is_complete = True
41
+
34
42
  def resolve(self, exchange: Exchange) -> Exchange:
35
43
  """
36
44
 
@@ -38,20 +46,21 @@ class Proxy(server.Plain):
38
46
  Subclasses can override the relevant processing methods to implement custom behaviour.
39
47
 
40
48
  """
41
-
42
49
  with logger.span(f'Processing question...'):
43
50
  self.process_question(exchange)
44
- if exchange.response.is_complete:
51
+ if exchange.is_complete:
45
52
  return exchange
46
53
 
47
54
  with logger.span(f'Making upstream request...'):
48
55
  self.client.resolve(exchange)
49
- if exchange.response.is_complete:
56
+ if exchange.is_complete:
50
57
  return exchange
51
58
 
52
59
  with logger.span(f'Processing upstream response...'):
53
60
  self.process_upstream(exchange)
54
- if exchange.response.is_complete:
61
+ if exchange.is_complete:
55
62
  return exchange
56
63
 
64
+ self.finalize(exchange)
65
+
57
66
  return exchange
@@ -66,7 +66,7 @@ class Plain:
66
66
  logger.info(f'Request found in cache.')
67
67
  exchange.response = self.cache[exchange.key]
68
68
  exchange.response.message.id = exchange.request.message.id
69
- exchange.response.is_complete = True
69
+ exchange.is_complete = True
70
70
 
71
71
  def get_span(self, exchange: Exchange):
72
72
  """
@@ -90,7 +90,7 @@ class Plain:
90
90
  response = exchange.response
91
91
 
92
92
  logger.info(
93
- f'Resolution complete {exchange.client_name=} {request.message.id=} {request.type_text} {request.name_text} {request.question=} {response.is_complete=} {response.rcode=} {response.rcode_text=} {response.answer=} {response.blocked_by=}...'
93
+ f'Resolution complete {exchange.client_name=} {request.message.id=} {request.type_text} {request.name_text} {request.question=} {exchange.is_complete=} {response.rcode=} {response.rcode_text=} {response.answer=} {response.blocked_by=}...'
94
94
  )
95
95
 
96
96
 
@@ -116,9 +116,9 @@ class Plain:
116
116
  with logger.span(f'Checking cache...'):
117
117
  self.check_cache(exchange)
118
118
 
119
- if not exchange.response.is_complete:
119
+ if not exchange.is_complete:
120
120
  exchange = self.resolve(exchange)
121
- exchange.response.is_complete = True
121
+ exchange.is_complete = True
122
122
 
123
123
  self.cache[exchange.key] = exchange.response
124
124
  self.log_response(exchange)
fmtr/tools/version CHANGED
@@ -1 +1 @@
1
- 1.3.14
1
+ 1.3.15
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fmtr.tools
3
- Version: 1.3.14
3
+ Version: 1.3.15
4
4
  Summary: Collection of high-level tools to simplify everyday development tasks, with a focus on AI/ML
5
5
  Home-page: https://github.com/fmtr/fmtr.tools
6
6
  Author: Frontmatter
@@ -126,61 +126,61 @@ Requires-Dist: logfire[httpx]; extra == "http"
126
126
  Provides-Extra: setup
127
127
  Requires-Dist: setuptools; extra == "setup"
128
128
  Provides-Extra: all
129
- Requires-Dist: sentence_transformers; extra == "all"
130
- Requires-Dist: Unidecode; extra == "all"
131
- Requires-Dist: peft; extra == "all"
132
- Requires-Dist: tinynetrc; extra == "all"
129
+ Requires-Dist: logfire[fastapi]; extra == "all"
130
+ Requires-Dist: json_repair; extra == "all"
131
+ Requires-Dist: flet-webview; extra == "all"
132
+ Requires-Dist: google-auth-oauthlib; extra == "all"
133
+ Requires-Dist: httpx_retries; extra == "all"
134
+ Requires-Dist: pandas; extra == "all"
135
+ Requires-Dist: google-auth; extra == "all"
136
+ Requires-Dist: yamlscript; extra == "all"
137
+ Requires-Dist: pydantic-ai[logfire,openai]; extra == "all"
138
+ Requires-Dist: pydantic; extra == "all"
139
+ Requires-Dist: setuptools; extra == "all"
140
+ Requires-Dist: google-auth-httplib2; extra == "all"
141
+ Requires-Dist: diskcache; extra == "all"
142
+ Requires-Dist: pymupdf; extra == "all"
143
+ Requires-Dist: flet-video; extra == "all"
133
144
  Requires-Dist: contexttimer; extra == "all"
134
- Requires-Dist: torchaudio; extra == "all"
135
- Requires-Dist: uvicorn[standard]; extra == "all"
136
- Requires-Dist: openpyxl; extra == "all"
145
+ Requires-Dist: faker; extra == "all"
146
+ Requires-Dist: pytest-cov; extra == "all"
147
+ Requires-Dist: logfire; extra == "all"
148
+ Requires-Dist: bokeh; extra == "all"
137
149
  Requires-Dist: pydantic-settings; extra == "all"
138
- Requires-Dist: sre_yield; extra == "all"
139
- Requires-Dist: distributed; extra == "all"
150
+ Requires-Dist: logfire[httpx]; extra == "all"
151
+ Requires-Dist: appdirs; extra == "all"
152
+ Requires-Dist: openpyxl; extra == "all"
153
+ Requires-Dist: pyyaml; extra == "all"
140
154
  Requires-Dist: semver; extra == "all"
141
- Requires-Dist: tokenizers; extra == "all"
142
- Requires-Dist: pydevd-pycharm~=251.25410.159; extra == "all"
143
155
  Requires-Dist: fastapi; extra == "all"
144
- Requires-Dist: pydantic-ai[logfire,openai]; extra == "all"
145
- Requires-Dist: httpx_retries; extra == "all"
146
- Requires-Dist: flet[all]; extra == "all"
147
- Requires-Dist: pymupdf4llm; extra == "all"
148
- Requires-Dist: filetype; extra == "all"
149
- Requires-Dist: pytest-cov; extra == "all"
150
- Requires-Dist: flet-webview; extra == "all"
151
- Requires-Dist: pymupdf; extra == "all"
152
- Requires-Dist: json_repair; extra == "all"
153
- Requires-Dist: openai; extra == "all"
154
- Requires-Dist: google-auth; extra == "all"
155
- Requires-Dist: huggingface_hub; extra == "all"
156
+ Requires-Dist: torchaudio; extra == "all"
156
157
  Requires-Dist: ollama; extra == "all"
157
- Requires-Dist: faker; extra == "all"
158
- Requires-Dist: dnspython[doh]; extra == "all"
159
- Requires-Dist: logfire[fastapi]; extra == "all"
160
- Requires-Dist: httpx; extra == "all"
161
- Requires-Dist: google-api-python-client; extra == "all"
162
- Requires-Dist: docker; extra == "all"
163
- Requires-Dist: google-auth-oauthlib; extra == "all"
164
- Requires-Dist: torchvision; extra == "all"
165
- Requires-Dist: regex; extra == "all"
166
158
  Requires-Dist: dask[bag]; extra == "all"
167
- Requires-Dist: appdirs; extra == "all"
168
- Requires-Dist: html2text; extra == "all"
159
+ Requires-Dist: torchvision; extra == "all"
169
160
  Requires-Dist: deepmerge; extra == "all"
170
- Requires-Dist: logfire[httpx]; extra == "all"
171
- Requires-Dist: pandas; extra == "all"
172
- Requires-Dist: flet-video; extra == "all"
173
- Requires-Dist: tabulate; extra == "all"
174
- Requires-Dist: google-auth-httplib2; extra == "all"
175
- Requires-Dist: bokeh; extra == "all"
176
- Requires-Dist: logfire; extra == "all"
161
+ Requires-Dist: tokenizers; extra == "all"
177
162
  Requires-Dist: cachetools; extra == "all"
178
- Requires-Dist: setuptools; extra == "all"
179
- Requires-Dist: yamlscript; extra == "all"
180
- Requires-Dist: pydantic; extra == "all"
163
+ Requires-Dist: uvicorn[standard]; extra == "all"
164
+ Requires-Dist: sentence_transformers; extra == "all"
165
+ Requires-Dist: openai; extra == "all"
166
+ Requires-Dist: distributed; extra == "all"
167
+ Requires-Dist: filetype; extra == "all"
168
+ Requires-Dist: regex; extra == "all"
169
+ Requires-Dist: pydevd-pycharm~=251.25410.159; extra == "all"
170
+ Requires-Dist: docker; extra == "all"
171
+ Requires-Dist: tinynetrc; extra == "all"
172
+ Requires-Dist: google-api-python-client; extra == "all"
173
+ Requires-Dist: peft; extra == "all"
181
174
  Requires-Dist: transformers[sentencepiece]; extra == "all"
182
- Requires-Dist: pyyaml; extra == "all"
183
- Requires-Dist: diskcache; extra == "all"
175
+ Requires-Dist: flet[all]; extra == "all"
176
+ Requires-Dist: html2text; extra == "all"
177
+ Requires-Dist: Unidecode; extra == "all"
178
+ Requires-Dist: huggingface_hub; extra == "all"
179
+ Requires-Dist: sre_yield; extra == "all"
180
+ Requires-Dist: dnspython[doh]; extra == "all"
181
+ Requires-Dist: pymupdf4llm; extra == "all"
182
+ Requires-Dist: tabulate; extra == "all"
183
+ Requires-Dist: httpx; extra == "all"
184
184
  Dynamic: author
185
185
  Dynamic: author-email
186
186
  Dynamic: description
@@ -44,16 +44,16 @@ fmtr/tools/tabular_tools.py,sha256=tpIpZzYku1HcJrHZJL6BC39LmN3WUWVhFbK2N7nDVmE,1
44
44
  fmtr/tools/tokenization_tools.py,sha256=me-IBzSLyNYejLybwjO9CNB6Mj2NYfKPaOVThXyaGNg,4268
45
45
  fmtr/tools/tools.py,sha256=CAsApa1YwVdNE6H66Vjivs_mXYvOas3rh7fPELAnTpk,795
46
46
  fmtr/tools/unicode_tools.py,sha256=yS_9wpu8ogNoiIL7s1G_8bETFFO_YQlo4LNPv1NLDeY,52
47
- fmtr/tools/version,sha256=GG4QPlY_pdWNhfbn575pBPL9Qt2zJ_Kt1m89Ii4ieks,6
47
+ fmtr/tools/version,sha256=mv8tnhpePoHazD4Fsoh-tA0aqi5t684gOq6SnQNd-oE,6
48
48
  fmtr/tools/yaml_tools.py,sha256=Bhhyd6GQVKO72Lp8ky7bAUjIB_65Hdh0Q45SKIEe6S8,1901
49
49
  fmtr/tools/ai_tools/__init__.py,sha256=JZrLuOFNV1A3wvJgonxOgz_4WS-7MfCuowGWA5uYCjs,372
50
50
  fmtr/tools/ai_tools/agentic_tools.py,sha256=acSEPFS-aguDXanWGs3fAAlRyJSYPZW7L-Kb2qDLm-I,4300
51
51
  fmtr/tools/ai_tools/inference_tools.py,sha256=2UP2gXEyOJUjyyV6zmFIYmIxUsh1rXkRH0IbFvr2bRs,11908
52
52
  fmtr/tools/dns_tools/__init__.py,sha256=PjD3Og6D5yvDVpKmsUsrnSpz_rjXpl4zBtvMqm8xKWU,237
53
- fmtr/tools/dns_tools/client.py,sha256=zAPJbQZIuNJPTA-HDBtrVZHvHRP_7QYWLgH7D73g5LU,2598
54
- fmtr/tools/dns_tools/dm.py,sha256=_G3ELId69SDMm0YciWQCW9-cTwt1l6cMVCt5-3T9V58,5177
55
- fmtr/tools/dns_tools/proxy.py,sha256=b3TdSwRO7IwcNjrWg1e8jVQb-YxJhT377rdVkeDc8_I,1466
56
- fmtr/tools/dns_tools/server.py,sha256=yL76rbYesdr1kHqLis5q1bxc3nzq68Utx-_PWA3Vu9U,3656
53
+ fmtr/tools/dns_tools/client.py,sha256=uUFoFRwoPtetPVH6PZ3ssHmx3WEquT6UW4FCBKq4n74,2722
54
+ fmtr/tools/dns_tools/dm.py,sha256=_kjsJx9cyEH7qWDjSGj6C54KRvi21h1em5FZCagrFgk,5271
55
+ fmtr/tools/dns_tools/proxy.py,sha256=0lgn1pq5KLoGA4644ZXYs2lPjXjRB-ibFb7JHzlMY9o,1618
56
+ fmtr/tools/dns_tools/server.py,sha256=zLZIXJil6_FeZjIyBytkpaavkoQGN4e9lEjQdOWnazc,3629
57
57
  fmtr/tools/entrypoints/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
58
58
  fmtr/tools/entrypoints/cache_hfh.py,sha256=fQNs4J9twQuZH_Yj98-oOvEX7-LrSUP3kO8nzw2HrHs,60
59
59
  fmtr/tools/entrypoints/ep_test.py,sha256=B8HfWISfSgw_xVX475CbJGh_QnpOe9MH65H8qGjTWbY,46
@@ -76,9 +76,9 @@ fmtr/tools/tests/test_path.py,sha256=AkZQa6_8BQ-VaCyL_J-iKmdf2ZaM-xFYR37Kun3k4_g
76
76
  fmtr/tools/tests/test_yaml.py,sha256=jc0TwwKu9eC0LvFGNMERdgBue591xwLxYXFbtsRwXVM,287
77
77
  fmtr/tools/version_tools/__init__.py,sha256=pg4iLtmIr5HtyEW_j0fMFoIdzqi_w9xH8-grQaXLB28,318
78
78
  fmtr/tools/version_tools/version_tools.py,sha256=Hcc6yferZS1hHbugRTdiHhSNmXEEG0hjCiTTXKna-YY,1127
79
- fmtr_tools-1.3.14.dist-info/licenses/LICENSE,sha256=FW9aa6vVN5IjRQWLT43hs4_koYSmpcbIovlKeAJ0_cI,10757
80
- fmtr_tools-1.3.14.dist-info/METADATA,sha256=Yj9yReion57e01vzQDF85BNGZVVLXHOUxfv8KQWYj1o,15938
81
- fmtr_tools-1.3.14.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
82
- fmtr_tools-1.3.14.dist-info/entry_points.txt,sha256=h-r__Xh5njtFqreMLg6cGuTFS4Qh-QqJPU1HB-_BS-Q,357
83
- fmtr_tools-1.3.14.dist-info/top_level.txt,sha256=LXem9xCgNOD72tE2gRKESdiQTL902mfFkwWb6-dlwEE,5
84
- fmtr_tools-1.3.14.dist-info/RECORD,,
79
+ fmtr_tools-1.3.15.dist-info/licenses/LICENSE,sha256=FW9aa6vVN5IjRQWLT43hs4_koYSmpcbIovlKeAJ0_cI,10757
80
+ fmtr_tools-1.3.15.dist-info/METADATA,sha256=63hO7H6HYE93QoQ0Osr-VPu6NUnkgdpz21Gt6-ifylM,15938
81
+ fmtr_tools-1.3.15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
82
+ fmtr_tools-1.3.15.dist-info/entry_points.txt,sha256=h-r__Xh5njtFqreMLg6cGuTFS4Qh-QqJPU1HB-_BS-Q,357
83
+ fmtr_tools-1.3.15.dist-info/top_level.txt,sha256=LXem9xCgNOD72tE2gRKESdiQTL902mfFkwWb6-dlwEE,5
84
+ fmtr_tools-1.3.15.dist-info/RECORD,,