ethspecify 0.1.2__py3-none-any.whl → 0.1.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.

Potentially problematic release.


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

ethspecify/core.py CHANGED
@@ -278,58 +278,49 @@ 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
+
281
290
  def replacer(match):
291
+ # Always use the tag text from whichever group matched:
282
292
  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:
293
+ original_tag_text = match.group("self")
294
+ else:
295
+ original_tag_text = match.group("long")
296
+
297
+ attributes = extract_attributes(original_tag_text)
298
+ print(f"spec tag: {attributes}")
299
+ preset, fork, style = parse_common_attributes(attributes)
300
+ spec = get_spec(attributes, preset, fork)
301
+ hash_value = hashlib.sha256(spec.encode('utf-8')).hexdigest()[:8]
302
+
303
+ if style == "hash":
304
+ # For hash style, output a self-closing tag.
305
+ if 'hash="' in original_tag_text:
291
306
  updated_tag = re.sub(
292
307
  r'(hash=")[^"]*(")',
293
308
  lambda m: f'{m.group(1)}{hash_value}{m.group(2)}',
294
- tag_text
309
+ original_tag_text
295
310
  )
296
311
  else:
297
- # Insert hash attribute before the trailing '/>'
298
- updated_tag = tag_text[:-2] + f' hash="{hash_value}"' + tag_text[-2:]
312
+ updated_tag = re.sub(r'\s*/>$', f' hash="{hash_value}" />', original_tag_text)
299
313
  return updated_tag
300
314
  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>"
315
+ # For full/diff styles, always rebuild as a long (paired) tag.
316
+ new_opening = rebuild_opening_tag(attributes, hash_value)
317
+ spec_content = get_spec_item(attributes)
318
+ prefix = content[:match.start()].splitlines()[-1]
319
+ prefixed_spec = "\n".join(
320
+ f"{prefix}{line}" if line.rstrip() else prefix.rstrip()
321
+ for line in spec_content.rstrip().split("\n")
322
+ )
323
+ updated_tag = f"{new_opening}\n{prefixed_spec}\n{prefix}</spec>"
333
324
  return updated_tag
334
325
 
335
326
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ethspecify
3
- Version: 0.1.2
3
+ Version: 0.1.3
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
 
@@ -0,0 +1,9 @@
1
+ ethspecify/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ ethspecify/cli.py,sha256=TTKmSGUkuRdYlYS6t-cpVXpdpSKsYCWvmRDy8DcC10E,882
3
+ ethspecify/core.py,sha256=pUybFZnO8nDDQ-7tQjxbUjQHFTV4PEGFWJTyR3gy0hM,12194
4
+ ethspecify-0.1.3.dist-info/LICENSE,sha256=Awxsr73mm9YMBVhBYnzeI7bNdRd-bH6RDtO5ItG0DaM,1071
5
+ ethspecify-0.1.3.dist-info/METADATA,sha256=JI4igGfL54P1EEmtIG-54A1SV5mrhxIbCCOs2WufJmQ,8790
6
+ ethspecify-0.1.3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
7
+ ethspecify-0.1.3.dist-info/entry_points.txt,sha256=09viGkCg9J3h0c9BFRN-BKaJUEaIc4JyULNgBP5EL_g,51
8
+ ethspecify-0.1.3.dist-info/top_level.txt,sha256=0klaMvlVyOkXW09fwZTijJpdybITEp2c9zQKV5v30VM,11
9
+ ethspecify-0.1.3.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- ethspecify/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- ethspecify/cli.py,sha256=TTKmSGUkuRdYlYS6t-cpVXpdpSKsYCWvmRDy8DcC10E,882
3
- ethspecify/core.py,sha256=GHVBP4OjKAy5Rf3z5PIjee9WNhr5-_u7JG3Rt-Zd-4I,12890
4
- ethspecify-0.1.2.dist-info/LICENSE,sha256=Awxsr73mm9YMBVhBYnzeI7bNdRd-bH6RDtO5ItG0DaM,1071
5
- ethspecify-0.1.2.dist-info/METADATA,sha256=H1qF9pQTnFTKmnNnEL1oJjUk-GjGwoHv5slOp9qQ5-g,8786
6
- ethspecify-0.1.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
7
- ethspecify-0.1.2.dist-info/entry_points.txt,sha256=09viGkCg9J3h0c9BFRN-BKaJUEaIc4JyULNgBP5EL_g,51
8
- ethspecify-0.1.2.dist-info/top_level.txt,sha256=0klaMvlVyOkXW09fwZTijJpdybITEp2c9zQKV5v30VM,11
9
- ethspecify-0.1.2.dist-info/RECORD,,