Skip to content

Commit

Permalink
Move hooks into internal event loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Reitz committed Oct 23, 2011
1 parent 4916b1c commit 491a3c0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions requests/models.py
Expand Up @@ -16,6 +16,7 @@
from urlparse import urlparse, urlunparse, urljoin
from datetime import datetime

from .hooks import dispatch_hook
from .structures import CaseInsensitiveDict
from .packages.poster.encode import multipart_encode
from .packages.poster.streaminghttp import register_openers, get_handlers
Expand Down Expand Up @@ -121,6 +122,10 @@ def __init__(self,

self.headers = headers

# Pre-request hook.
r = dispatch_hook('pre_request', hooks, self)
self.__dict__.update(r.__dict__)


def __repr__(self):
return '<Request [%s]>' % (self.method)
Expand Down Expand Up @@ -386,6 +391,13 @@ def send(self, anyway=False):

self.sent = self.response.ok

# Response manipulation hook.
self.response = dispatch_hook('response', self.hooks, self.response)

# Post-request hook.
r = dispatch_hook('post_request', self.hooks, self)
self.__dict__.update(r.__dict__)

return self.sent


Expand Down

0 comments on commit 491a3c0

Please sign in to comment.