harbor run -t openthoughts/tasktrove-mix-h4-binary-easy-mix-h4-binary-easy-1162harbor download openthoughts/tasktrove-mix-h4-binary-easy-mix-h4-binary-easy-1162solution file
"""
Rules to manage validation using HTTP properties
"""
from ..exceptions import XRobotsTagNoParam, TDMRepNoParam
from .base import HttpRule
class XRobotsTagHeader(HttpRule):
"""
This class wraps logic to read the X-Robots-Tag header.
"""
AI_DISALLOWED_VALUES = ["noai", "noimageai"]
INDEX_DISALLOWED_VALUES = ["noindex", "none", "noimageindex", "noai", "noimageai"]
HEADER_NAME = "X-Robots-Tag"
def __init__(self, user_agent=None, respect_noindex=False):
"""Create a new XRobotsTagHeader instance.
Args:
user_agent (str): The user agent to use when making requests to the Spawning AI API.
respect_noindex (bool): If True, index rules will be respected alongside AI rules.
"""
super().__init__(user_agent=user_agent)
# index rules aren't for AI, so we ignore them by default.
# They could have been delivered/found by any number of other means, even for internal use
if respect_noindex:
self.disallowed_headers = self.INDEX_DISALLOWED_VALUES
else:
self.disallowed_headers = self.AI_DISALLOWED_VALUES
def is_allowed(self, url=None, response=None, headers=None, **kwargs):
"""Check if the X-Robots-Tag header allows the user agent to access the resource.
Args:
url: (str): The URL of the resource.
response (http.client.HTTPResponse|requests.Response, optional): The response object. Defaults to None
headers (dict|http.client.HTTPMessage, optional): The headers dictionary. Defaults to None.
Returns:
bool: True if the user agent is allowed to access the resource, False otherwise.
"""
if headers:
header_value = self.get_header_value(headers, self.HEADER_NAME)
elif response:
header_value = self.
Complete the code above, taking into account the cross-file context provided. Your solution must work correctly with the related files in the project.
Place your complete solution in /app/solution.py