Ejemplo n.º 1
0
 def test_specifying_cookie_jar(self):
     cookie_jar = ocookie.CookieJar()
     s = webracer.Agent(cookie_jar=cookie_jar, **base_config)
     s.get('/set_cookie')
     s.assert_status(200)
     s.assert_response_cookie('visited', value='yes')
     assert 'visited' in cookie_jar
     self.assertEqual('yes', cookie_jar['visited'].value)
Ejemplo n.º 2
0
 def copy(self):
     '''Creates a copy of this agent.
     
     The new agent has the same configuration as the current agent
     and the same cookie jar as the current agent, if a cookie jar
     is being used.
     
     The new agent will use its own HTTP client instance to perform
     requests.
     
     The new agent does not share any state with the current agent.
     Current agent's values are only used to initialize the new agent.
     
     The intent of this method is to create agents usable in other threads
     that start with the current agent's present state.
     '''
     
     config = Config(self.config)
     cookie_jar = ocookie.CookieJar(self._cookie_jar)
     return Agent(config=config, cookie_jar=cookie_jar)
Ejemplo n.º 3
0
 def __init__(self, config=None, cookie_jar=None, **kwargs):
     '''Creates a new agent.
     
     Configuration options may be given as a Config instance in
     config argument and in keyword arguments. Keyword arguments
     override parameters in config.
     
     If cookie_jar is provided, it is used as the cookie jar.
     Note that cookie jar will not be copied. Supplied cookie jar
     will be mutated as requests are performed.
     '''
     
     if config is None:
         config = Config(**kwargs)
     self.config = config or Config()
     if cookie_jar is not None:
         self._cookie_jar = cookie_jar
     else:
         self._cookie_jar = ocookie.CookieJar()
     self.__client = None
Ejemplo n.º 4
0
 def clear_cookie_jar(self):
     self._cookie_jar = ocookie.CookieJar()