@@ -2739,9 +2739,7 @@ def _epd_operations(self, operations: Mapping[str, Union[None, str, int, float,
2739
2739
first_op = True
2740
2740
2741
2741
for opcode , operand in operations .items ():
2742
- assert opcode != "-" , "dash (-) is not a valid epd opcode"
2743
- for blacklisted in [" " , "\n " , "\t " , "\r " ]:
2744
- assert blacklisted not in opcode , f"invalid character { blacklisted !r} in epd opcode: { opcode !r} "
2742
+ self ._validate_epd_opcode (opcode )
2745
2743
2746
2744
if not first_op :
2747
2745
epd .append (" " )
@@ -2819,6 +2817,17 @@ def epd(self, *, shredder: bool = False, en_passant: EnPassantSpec = "legal", pr
2819
2817
2820
2818
return " " .join (epd )
2821
2819
2820
+ def _validate_epd_opcode (self , opcode : str ) -> None :
2821
+ if not opcode :
2822
+ raise ValueError ("empty string is not a valid epd opcode" )
2823
+ if opcode == "-" :
2824
+ raise ValueError ("dash (-) is not a valid epd opcode" )
2825
+ if not opcode [0 ].isalpha ():
2826
+ raise ValueError (f"expected epd opcode to start with a letter, got: { opcode !r} " )
2827
+ for blacklisted in [" " , "\n " , "\t " , "\r " ]:
2828
+ if blacklisted in opcode :
2829
+ raise ValueError (f"invalid character { blacklisted !r} in epd opcode: { opcode !r} " )
2830
+
2822
2831
def _parse_epd_ops (self : BoardT , operation_part : str , make_board : Callable [[], BoardT ]) -> Dict [str , Union [None , str , int , float , Move , List [Move ]]]:
2823
2832
operations : Dict [str , Union [None , str , int , float , Move , List [Move ]]] = {}
2824
2833
state = "opcode"
@@ -2832,6 +2841,7 @@ def _parse_epd_ops(self: BoardT, operation_part: str, make_board: Callable[[], B
2832
2841
if opcode == "-" :
2833
2842
opcode = ""
2834
2843
elif opcode :
2844
+ self ._validate_epd_opcode (opcode )
2835
2845
state = "after_opcode"
2836
2846
elif ch is None or ch == ";" :
2837
2847
if opcode == "-" :
0 commit comments