Download tasks/graphql-python__graphene-cinst-8db601e6/solution/patch.diff from Essacheez/r2e-code-instruct-qwen3.5: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/datasets/Essacheez/r2e-code-instruct-qwen3.5/resolve/main/tasks/graphql-python__graphene-cinst-8db601e6/solution/patch.diff
- Command line
-
hf download hf://datasets/Essacheez/r2e-code-instruct-qwen3.5/tasks/graphql-python__graphene-cinst-8db601e6/solution/patch.diff
-
curl -L -o patch.diff https://huggingface.co/datasets/Essacheez/r2e-code-instruct-qwen3.5/resolve/main/tasks/graphql-python__graphene-cinst-8db601e6/solution/patch.diff
1.08 kB
| diff --git a/task_module.py b/task_module.py | |
| new file mode 100644 | |
| index 0000000..0000001 | |
| --- /dev/null | |
| +++ b/task_module.py | |
| +from graphene import Scalar | |
| +from graphql.error import GraphQLError | |
| +from graphql.language import StringValueNode | |
| + | |
| +class HexScalar(Scalar): | |
| + """ | |
| + The `Hex` scalar type represents a hexadecimal-encoded String. | |
| + """ | |
| + | |
| + @staticmethod | |
| + def serialize(value): | |
| + if isinstance(value, bytes): | |
| + return value.hex() | |
| + else: | |
| + value = str(value).encode("utf-8") | |
| + return value.hex() | |
| + | |
| + @classmethod | |
| + def parse(cls, value): | |
| + try: | |
| + return bytes.fromhex(value) | |
| + except ValueError as e: | |
| + raise GraphQLError(f"Invalid hex string: {value}") | |
| + | |
| + @classmethod | |
| + def parse_literal(cls, node, _variables=None): | |
| + if not isinstance(node, StringValueNode): | |
| + raise GraphQLError( | |
| + f"Hex cannot represent non-string value" | |
| + ) | |
| + return cls.parse(node.value) | |
| \ No newline at end of file | |