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

Correctly handle Resources #30

Merged
merged 29 commits into from
Jan 4, 2014

Conversation

hawkowl
Copy link
Member

@hawkowl hawkowl commented Nov 26, 2013

This fixes issue #28.

@@ -25,6 +25,12 @@ def ensure_utf8_bytes(v):
return v


class StandInResource(object):
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be private.

Copy link
Member Author

Choose a reason for hiding this comment

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

Noted, changed in the next patch.

@hawkowl
Copy link
Member Author

hawkowl commented Dec 4, 2013

@dreid Incorporated your review comments!



class MockProducer(object):

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't generally put an empty line here unless it's between a docstring and the first method definition.

@hawkowl
Copy link
Member Author

hawkowl commented Dec 5, 2013

@dreid okay, gone through and fixed up those things. Unfortunately it looks like I'll have to use a reactor, since you're right about task.Clock not doing what I intended to do.


def resumeProducing(self):
self.count += 1
if self.count <= 3:
Copy link
Contributor

Choose a reason for hiding this comment

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

What's special about the number 3? Can we make the number a param passed in through ProducingResource.__init__ and MockProducer.__init__ so that the number 3 is closer to the assertion of it being called 3 times?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not 1! :) It's just a number I picked from random, really.

@hawkowl
Copy link
Member Author

hawkowl commented Dec 20, 2013

Unless anyone else has any other comments, I think this is good to go.

producer.resumeProducing()
producer.resumeProducing()
request.producer = producer
for x in xrange(1,3):
Copy link
Member

Choose a reason for hiding this comment

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

xrange is for supporting ancient versions of Python and large ranges. range(2) is what you want here, I think.

@hawkowl
Copy link
Member Author

hawkowl commented Dec 20, 2013

Thanks @exarkun , I've made those changes.

@@ -102,18 +111,20 @@ def _execute():
d = defer.maybeDeferred(_execute)

def write_response(r):
if isinstance(r, unicode):
r = r.encode('utf-8')
if not r is _StandInResource:
Copy link
Contributor

Choose a reason for hiding this comment

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

This would typically be written as:

if r is not _StandInResource:

@hawkowl
Copy link
Member Author

hawkowl commented Jan 1, 2014

Thanks @dreid , fixed those two things.

producer.resumeProducing()
producer.resumeProducing()
request.producer = producer
for x in range(1,3):
Copy link
Member

Choose a reason for hiding this comment

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

you really want just range(2) here as jp wrote. :)

Copy link
Member Author

Choose a reason for hiding this comment

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

herp derp fixed that

dreid added a commit that referenced this pull request Jan 4, 2014
@dreid dreid merged commit 418a3bf into twisted:master Jan 4, 2014
@iffy iffy mentioned this pull request Jan 4, 2014
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.

6 participants