Wraps a scrapy Request class with methods defined by urllib2.Request class to interact with CookieJar class see http://docs.python.org/library/urllib2.html#urllib2.Request
| 136 | |
| 137 | |
| 138 | class WrappedRequest: |
| 139 | """Wraps a scrapy Request class with methods defined by urllib2.Request class to interact with CookieJar class |
| 140 | |
| 141 | see http://docs.python.org/library/urllib2.html#urllib2.Request |
| 142 | """ |
| 143 | |
| 144 | def __init__(self, request: Request): |
| 145 | self.request = request |
| 146 | |
| 147 | def get_full_url(self) -> str: |
| 148 | return self.request.url |
| 149 | |
| 150 | def get_host(self) -> str: |
| 151 | return urlparse_cached(self.request).netloc |
| 152 | |
| 153 | def get_type(self) -> str: |
| 154 | return urlparse_cached(self.request).scheme |
| 155 | |
| 156 | def is_unverifiable(self) -> bool: |
| 157 | """Unverifiable should indicate whether the request is unverifiable, as defined by RFC 2965. |
| 158 | |
| 159 | It defaults to False. An unverifiable request is one whose URL the user did not have the |
| 160 | option to approve. For example, if the request is for an image in an |
| 161 | HTML document, and the user had no option to approve the automatic |
| 162 | fetching of the image, this should be true. |
| 163 | """ |
| 164 | return cast("bool", self.request.meta.get("is_unverifiable", False)) |
| 165 | |
| 166 | @property |
| 167 | def full_url(self) -> str: |
| 168 | return self.get_full_url() |
| 169 | |
| 170 | @property |
| 171 | def host(self) -> str: |
| 172 | return self.get_host() |
| 173 | |
| 174 | @property |
| 175 | def type(self) -> str: |
| 176 | return self.get_type() |
| 177 | |
| 178 | @property |
| 179 | def unverifiable(self) -> bool: |
| 180 | return self.is_unverifiable() |
| 181 | |
| 182 | @property |
| 183 | def origin_req_host(self) -> str: |
| 184 | return cast("str", urlparse_cached(self.request).hostname) |
| 185 | |
| 186 | def has_header(self, name: str) -> bool: |
| 187 | return name in self.request.headers |
| 188 | |
| 189 | def get_header(self, name: str, default: str | None = None) -> str | None: |
| 190 | value = self.request.headers.get(name, default) |
| 191 | return to_unicode(value, errors="replace") if value is not None else None |
| 192 | |
| 193 | def header_items(self) -> list[tuple[str, list[str]]]: |
| 194 | return [ |
| 195 | ( |
no outgoing calls