ethspecify 0.1.2__tar.gz → 0.1.4__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.

Potentially problematic release.


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

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ethspecify
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: A utility for processing Ethereum specification tags.
5
5
  Home-page: https://github.com/jtraglia/ethspecify
6
6
  Author: Justin Traglia
@@ -45,13 +45,13 @@ In your client, add HTML tags like this:
45
45
 
46
46
  ```
47
47
  /*
48
- * <spec fn="is_fully_withdrawable_validator" fork="deneb">
48
+ * <spec fn="is_fully_withdrawable_validator" fork="deneb" />
49
49
  */
50
50
  ```
51
51
 
52
52
  ```
53
53
  /*
54
- * <spec ssz_object="BeaconState" fork="electra" style="diff">
54
+ * <spec ssz_object="BeaconState" fork="electra" style="diff" />
55
55
  */
56
56
  ```
57
57
 
@@ -21,13 +21,13 @@ In your client, add HTML tags like this:
21
21
 
22
22
  ```
23
23
  /*
24
- * <spec fn="is_fully_withdrawable_validator" fork="deneb">
24
+ * <spec fn="is_fully_withdrawable_validator" fork="deneb" />
25
25
  */
26
26
  ```
27
27
 
28
28
  ```
29
29
  /*
30
- * <spec ssz_object="BeaconState" fork="electra" style="diff">
30
+ * <spec ssz_object="BeaconState" fork="electra" style="diff" />
31
31
  */
32
32
  ```
33
33
 
@@ -278,58 +278,58 @@ def replace_spec_tags(file_path):
278
278
  re.DOTALL
279
279
  )
280
280
 
281
+ def rebuild_opening_tag(attributes, hash_value):
282
+ # Rebuild a fresh opening tag from attributes, overriding any existing hash.
283
+ new_opening = "<spec"
284
+ for key, val in attributes.items():
285
+ if key != "hash":
286
+ new_opening += f' {key}="{val}"'
287
+ new_opening += f' hash="{hash_value}">'
288
+ return new_opening
289
+
290
+ def rebuild_self_closing_tag(attributes, hash_value):
291
+ # Build a self-closing tag from attributes, forcing a single space before the slash.
292
+ new_tag = "<spec"
293
+ for key, val in attributes.items():
294
+ if key != "hash":
295
+ new_tag += f' {key}="{val}"'
296
+ new_tag += f' hash="{hash_value}" />'
297
+ return new_tag
298
+
281
299
  def replacer(match):
300
+ # Always use the tag text from whichever group matched:
282
301
  if match.group("self") is not None:
283
- # Process self-closing tag
284
- tag_text = match.group("self")
285
- attributes = extract_attributes(tag_text)
286
- print(f"spec tag: {attributes}")
287
- preset, fork, style = parse_common_attributes(attributes)
288
- spec = get_spec(attributes, preset, fork)
289
- hash_value = hashlib.sha256(spec.encode('utf-8')).hexdigest()[:8]
290
- if 'hash="' in tag_text:
291
- updated_tag = re.sub(
292
- r'(hash=")[^"]*(")',
293
- lambda m: f'{m.group(1)}{hash_value}{m.group(2)}',
294
- tag_text
295
- )
296
- else:
297
- # Insert hash attribute before the trailing '/>'
298
- updated_tag = tag_text[:-2] + f' hash="{hash_value}"' + tag_text[-2:]
302
+ original_tag_text = match.group("self")
303
+ else:
304
+ original_tag_text = match.group("long")
305
+ # Determine the original opening tag (ignore inner content)
306
+ if match.group("self") is not None:
307
+ original_tag_text = match.group("self")
308
+ else:
309
+ long_tag_text = match.group("long")
310
+ opening_tag_match = re.search(r'<spec\b[^>]*>', long_tag_text)
311
+ original_tag_text = opening_tag_match.group(0) if opening_tag_match else long_tag_text
312
+
313
+ attributes = extract_attributes(original_tag_text)
314
+ print(f"spec tag: {attributes}")
315
+ preset, fork, style = parse_common_attributes(attributes)
316
+ spec = get_spec(attributes, preset, fork)
317
+ hash_value = hashlib.sha256(spec.encode('utf-8')).hexdigest()[:8]
318
+
319
+ if style == "hash":
320
+ # Rebuild a fresh self-closing tag.
321
+ updated_tag = rebuild_self_closing_tag(attributes, hash_value)
299
322
  return updated_tag
300
323
  else:
301
- # Process long (paired) tag
302
- tag_text = match.group("long")
303
- # Extract the opening tag from the long tag (everything up to the first '>')
304
- opening_match = re.match(r'(<spec\b[^>]*>)([\s\S]*)(</spec>)', tag_text, re.DOTALL)
305
- if not opening_match:
306
- return tag_text
307
- opening_tag_full = opening_match.group(1)
308
- attributes = extract_attributes(opening_tag_full)
309
- print(f"spec tag: {attributes}")
310
- preset, fork, style = parse_common_attributes(attributes)
311
- spec = get_spec(attributes, preset, fork)
312
- hash_value = hashlib.sha256(spec.encode('utf-8')).hexdigest()[:8]
313
- if 'hash="' in opening_tag_full:
314
- updated_opening = re.sub(
315
- r'(hash=")[^"]*(")',
316
- lambda m: f'{m.group(1)}{hash_value}{m.group(2)}',
317
- opening_tag_full
318
- )
319
- else:
320
- updated_opening = opening_tag_full[:-1] + f' hash="{hash_value}">'
321
- if style == "hash":
322
- updated_tag = re.sub(r'\s*</spec>\s*$', '', updated_opening)
323
- updated_tag = re.sub(r'\s*>$', '', updated_tag) + " />"
324
- else:
325
- spec_content = get_spec_item(attributes)
326
- prefix = content[:match.start()].splitlines()[-1]
327
- prefixed_spec = "\n".join(
328
- f"{prefix}{line}" if line.rstrip() else prefix.rstrip()
329
- for line in spec_content.rstrip().split("\n")
330
- )
331
- long_opening = updated_opening.rstrip(">/") + ">"
332
- updated_tag = f"{long_opening}\n{prefixed_spec}\n{prefix}</spec>"
324
+ # For full/diff styles, rebuild as a long (paired) tag.
325
+ new_opening = rebuild_opening_tag(attributes, hash_value)
326
+ spec_content = get_spec_item(attributes)
327
+ prefix = content[:match.start()].splitlines()[-1]
328
+ prefixed_spec = "\n".join(
329
+ f"{prefix}{line}" if line.rstrip() else prefix.rstrip()
330
+ for line in spec_content.rstrip().split("\n")
331
+ )
332
+ updated_tag = f"{new_opening}\n{prefixed_spec}\n{prefix}</spec>"
333
333
  return updated_tag
334
334
 
335
335
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ethspecify
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: A utility for processing Ethereum specification tags.
5
5
  Home-page: https://github.com/jtraglia/ethspecify
6
6
  Author: Justin Traglia
@@ -45,13 +45,13 @@ In your client, add HTML tags like this:
45
45
 
46
46
  ```
47
47
  /*
48
- * <spec fn="is_fully_withdrawable_validator" fork="deneb">
48
+ * <spec fn="is_fully_withdrawable_validator" fork="deneb" />
49
49
  */
50
50
  ```
51
51
 
52
52
  ```
53
53
  /*
54
- * <spec ssz_object="BeaconState" fork="electra" style="diff">
54
+ * <spec ssz_object="BeaconState" fork="electra" style="diff" />
55
55
  */
56
56
  ```
57
57
 
@@ -8,7 +8,7 @@ long_description = (this_directory / "README.md").read_text(encoding="utf-8")
8
8
 
9
9
  setup(
10
10
  name="ethspecify",
11
- version="0.1.2",
11
+ version="0.1.4",
12
12
  description="A utility for processing Ethereum specification tags.",
13
13
  long_description=long_description,
14
14
  long_description_content_type="text/markdown",
File without changes
File without changes
File without changes