Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move #expires, #expired, and #ttl to ExpiringObject class. #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

b4hand
Copy link
Contributor

@b4hand b4hand commented May 31, 2018

This is essentially in response to some of the confusion around #86.

I think this is technically a little cleaner from an object oriented analysis standpoint. However, relying on the after_response_hook and the mechanism that I used to set the expires seems a little hacky to me.

I'm curious what others think about this or if there's a better solution. Also, there's definitely some docs in the README that will need to be updated before merging this.

@dlecocq: I'm interested in your thoughts since you looked at the prior issue as well.

@b4hand b4hand requested review from sistawendy and lindseyreno May 31, 2018 18:25
@@ -83,9 +102,17 @@ def allowed(self, url, agent):

def fetch(self, url):
'''Return (expiration, Robots) for the robots.txt at the provided URL.'''
expires = [0]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been a while since I've done python. Is this part of that weird closure thing? As in, it has to be an array for us to be able to save a value in this scope from check_ttl_hook?

Copy link
Contributor Author

@b4hand b4hand Jun 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's correct. We need a mutable object to modify in the closure. A bare assignment will create a new local variable rather than modify the variable in the outer scope.

robots = Robots.fetch(
url, ttl_policy=self.ttl_policy, *self.args, **self.kwargs)
return (robots.expires, robots)
url, after_response_hook=check_ttl_hook, *self.args, **self.kwargs)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this doesn't feel great, but I don't see any reason not to trust it. We could also have a method off of Robots that returns a pair of (response, obj), but I think this is fine as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants