@@ -899,6 +899,63 @@ def from_native(cls, string):
899899 return cls (constraints = constraints )
900900
901901
902+ vers_by_github_native_comparators = {
903+ "==" : "=" ,
904+ "<=" : "<=" ,
905+ ">=" : ">=" ,
906+ "<" : "<" ,
907+ ">" : ">" ,
908+ }
909+
910+
911+ def build_constraint_from_github_advisory_string (scheme : str , string : str ):
912+ """
913+ Return a VersionConstraint built from a single github-native version
914+ relationship ``string``.
915+
916+ >>> vr = build_constraint_from_github_advisory_string("gem","<= 2.24")
917+ >>> assert str(vr) == "<=2.24", str(vr)
918+ >>> vr = build_constraint_from_github_advisory_string("pypi","< 9.0")
919+ >>> assert str(vr) == "<9.0", str(vr)
920+ """
921+ vrc = RANGE_CLASS_BY_SCHEMES [scheme ]
922+ comparator , version = split_req (
923+ string = string ,
924+ comparators = vers_by_github_native_comparators ,
925+ )
926+ version = vrc .version_class (version )
927+ return VersionConstraint (comparator = comparator , version = version )
928+
929+
930+ def build_range_from_github_advisory_constraint (scheme : str , string : str ):
931+ """
932+ Github has a special syntax for version ranges.
933+ For example:
934+ Maven native version range looks like:
935+ ``[1.0.0,1.0.1)``
936+ Github native version range looks like:
937+ ``>= 1.0.0, < 1.0.1``
938+
939+ Return a VersionRange built from a ``string`` single github-native
940+ version relationship string.
941+
942+ For example::
943+
944+ >>> vr = build_range_from_github_advisory_constraint("maven", ">= 2.13.0, < 2.16.0")
945+ >>> assert str(vr) == "vers:maven/>=2.13.0|<2.16.0"
946+ >>> vr = build_range_from_github_advisory_constraint("gem", ">= 2.13.0, < 2.16.0")
947+ >>> assert str(vr) == "vers:gem/>=2.13.0|<2.16.0"
948+ >>> vr = build_range_from_github_advisory_constraint("pypi","< 9.0")
949+ >>> assert str(vr) == "vers:pypi/<9.0"
950+ """
951+ constraint_strings = string .split ("," )
952+ constraints = []
953+ vrc = RANGE_CLASS_BY_SCHEMES [scheme ]
954+ for constraint in constraint_strings :
955+ constraints .append (build_constraint_from_github_advisory_string (scheme , constraint ))
956+ return vrc (constraints = constraints )
957+
958+
902959def is_even (s ):
903960 """
904961 Return True if the string "s" is an even number and False if this is an odd
0 commit comments