CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes | Static Public Attributes
uploadConditions.HTTP Class Reference
Inheritance diagram for uploadConditions.HTTP:

Public Member Functions

def __init__
 
def discardCookies
 
def getCookies
 
def getToken
 
def query
 
def setBaseUrl
 
def setProxy
 
def setRetries
 
def setTimeout
 

Public Attributes

 baseUrl
 
 curl
 
 retries
 
 token
 

Static Public Attributes

tuple retryCodes = frozenset([502, 503])
 

Detailed Description

Class used for querying URLs using the HTTP protocol.

Definition at line 222 of file uploadConditions.py.

Constructor & Destructor Documentation

def uploadConditions.HTTP.__init__ (   self)

Definition at line 228 of file uploadConditions.py.

References upload_popcon.HTTP.setBaseUrl(), uploadConditions.HTTP.setBaseUrl(), uploadConditions.HTTP.setRetries(), and upload_popcon.HTTP.setRetries().

229  def __init__(self):
230  self.setBaseUrl()
231  self.setRetries()
233  self.curl = pycurl.Curl()
234  self.curl.setopt(self.curl.COOKIEFILE, '') # in memory
235 
236  #-toDo: make sure we have the right options set here to use ssl
237  #-review(2015-09-25): check and see - action: AP
238  # self.curl.setopt(self.curl.SSL_VERIFYPEER, 1)
239  self.curl.setopt(self.curl.SSL_VERIFYPEER, 0)
240  self.curl.setopt(self.curl.SSL_VERIFYHOST, 2)
242  self.baseUrl = None
244  self.token = None

Member Function Documentation

def uploadConditions.HTTP.discardCookies (   self)
Discards cookies.

Definition at line 250 of file uploadConditions.py.

Referenced by uploadConditions.HTTP.query().

251  def discardCookies(self):
252  '''Discards cookies.
253  '''
254  self.curl.setopt(self.curl.COOKIELIST, 'ALL')
255 
def uploadConditions.HTTP.getCookies (   self)
Returns the list of cookies.

Definition at line 245 of file uploadConditions.py.

246  def getCookies(self):
247  '''Returns the list of cookies.
248  '''
249  return self.curl.getinfo(self.curl.INFO_COOKIELIST)
def uploadConditions.HTTP.getToken (   self,
  username,
  password 
)

Definition at line 290 of file uploadConditions.py.

References uploadConditions.HTTP.baseUrl, upload_popcon.HTTP.baseUrl, cond::TagInfo_t.token, and uploadConditions.HTTP.token.

291  def getToken(self, username, password):
292 
293  url = self.baseUrl + 'token'
294 
295  self.curl.setopt(pycurl.URL, url)
296  self.curl.setopt(pycurl.VERBOSE, 0)
297 
298  #-toDo: check if/why these are needed ...
299  #-ap: hmm ...
300  # self.curl.setopt(pycurl.DNS_CACHE_TIMEOUT, 0)
301  # self.curl.setopt(pycurl.IPRESOLVE, pycurl.IPRESOLVE_V4)
302  #-end hmmm ...
303  #-review(2015-09-25): check and see - action: AP
304 
305 
306  self.curl.setopt(pycurl.HTTPHEADER, ['Accept: application/json'])
307  # self.curl.setopt( self.curl.POST, {})
308  self.curl.setopt(self.curl.HTTPGET, 0)
309 
310  response = cStringIO.StringIO()
311  self.curl.setopt(pycurl.WRITEFUNCTION, response.write)
312  self.curl.setopt(pycurl.USERPWD, '%s:%s' % (username, password) )
313 
314  logging.debug('going to connect to server at: %s' % url )
315 
316  self.curl.perform()
317  code = self.curl.getinfo(pycurl.RESPONSE_CODE)
318  logging.debug('got: %s ', str(code))
319 
320  try:
321  self.token = json.loads( response.getvalue() )['token']
322  except Exception as e:
323  logging.error('http::getToken> got error from server: %s ', str(e) )
324  if 'No JSON object could be decoded' in str(e):
325  return None
326  logging.error("error getting token: %s", str(e))
327  return None
328 
329  logging.debug('token: %s', self.token)
330  logging.debug('returning: %s', response.getvalue())
331 
332  return response.getvalue()
def uploadConditions.HTTP.query (   self,
  url,
  data = None,
  files = None,
  keepCookies = True 
)
Queries a URL, optionally with some data (dictionary).

If no data is specified, a GET request will be used.
If some data is specified, a POST request will be used.

If files is specified, it must be a dictionary like data but
the values are filenames.

By default, cookies are kept in-between requests.

A HTTPError exception is raised if the response's HTTP code is not 200.

Definition at line 333 of file uploadConditions.py.

References uploadConditions.HTTP.baseUrl, upload_popcon.HTTP.baseUrl, upload_popcon.HTTP.discardCookies(), uploadConditions.HTTP.discardCookies(), list(), uploadConditions.HTTP.retries, upload_popcon.HTTP.retries, uploadConditions.HTTP.retryCodes, upload_popcon.HTTP.retryCodes, cond::TagInfo_t.token, and uploadConditions.HTTP.token.

Referenced by production_tasks.BaseDataset.run(), and edmIntegrityCheck.IntegrityCheck.test().

334  def query(self, url, data = None, files = None, keepCookies = True):
335  '''Queries a URL, optionally with some data (dictionary).
336 
337  If no data is specified, a GET request will be used.
338  If some data is specified, a POST request will be used.
339 
340  If files is specified, it must be a dictionary like data but
341  the values are filenames.
342 
343  By default, cookies are kept in-between requests.
344 
345  A HTTPError exception is raised if the response's HTTP code is not 200.
346  '''
347 
348  if not keepCookies:
349  self.discardCookies()
350 
351  url = self.baseUrl + url
352 
353  # make sure the logs are safe ... at least somewhat :)
354  data4log = copy.copy(data)
355  if data4log:
356  if 'password' in data4log.keys():
357  data4log['password'] = '*'
358 
359  retries = [0] + list(self.retries)
360 
361  while True:
362  logging.debug('Querying %s with data %s and files %s (retries left: %s, current sleep: %s)...', url, data4log, files, len(retries), retries[0])
363 
364  time.sleep(retries.pop(0))
365 
366  try:
367  self.curl.setopt(self.curl.URL, url)
368  self.curl.setopt(self.curl.HTTPGET, 1)
369 
370  # from now on we use the token we got from the login
371  self.curl.setopt(pycurl.USERPWD, '%s:""' % ( str(self.token), ) )
372  self.curl.setopt(pycurl.HTTPHEADER, ['Accept: application/json'])
373 
374  if data is not None or files is not None:
375  # If there is data or files to send, use a POST request
376 
377  finalData = {}
378 
379  if data is not None:
380  finalData.update(data)
381 
382  if files is not None:
383  for (key, fileName) in files.items():
384  finalData[key] = (self.curl.FORM_FILE, fileName)
385  self.curl.setopt( self.curl.HTTPPOST, finalData.items() )
386 
387  self.curl.setopt(pycurl.VERBOSE, 0)
388 
389  response = cStringIO.StringIO()
390  self.curl.setopt(self.curl.WRITEFUNCTION, response.write)
391  self.curl.perform()
392 
393  code = self.curl.getinfo(self.curl.RESPONSE_CODE)
394 
395  if code in self.retryCodes and len(retries) > 0:
396  logging.debug('Retrying since we got the %s error code...', code)
397  continue
398 
399  if code != 200:
400  raise HTTPError(code, response.getvalue())
401 
402  return response.getvalue()
403 
404  except pycurl.error as e:
405  if len(retries) == 0:
406  raise e
407  logging.debug('Retrying since we got the %s pycurl exception...', str(e))
408 
409 # common/http.py end
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
def uploadConditions.HTTP.setBaseUrl (   self,
  baseUrl = '' 
)
Allows to set a base URL which will be prefixed to all the URLs
that will be queried later.

Definition at line 256 of file uploadConditions.py.

References uploadConditions.HTTP.baseUrl, and upload_popcon.HTTP.baseUrl.

Referenced by uploadConditions.HTTP.__init__().

257  def setBaseUrl(self, baseUrl = ''):
258  '''Allows to set a base URL which will be prefixed to all the URLs
259  that will be queried later.
260  '''
261  self.baseUrl = baseUrl
262 
def uploadConditions.HTTP.setProxy (   self,
  proxy = '' 
)
Allows to set a proxy.

Definition at line 263 of file uploadConditions.py.

264  def setProxy(self, proxy = ''):
265  '''Allows to set a proxy.
266  '''
267  self.curl.setopt(self.curl.PROXY, proxy)
268 
def uploadConditions.HTTP.setRetries (   self,
  retries = () 
)
Allows to set retries.

The retries are a sequence of the seconds to wait per retry.

The retries are done on:
    * PyCurl errors (includes network problems, e.g. not being able
      to connect to the host).
    * 502 Bad Gateway (for the moment, to avoid temporary
      Apache-CherryPy issues).
    * 503 Service Temporarily Unavailable (for when we update
      the frontends).

Definition at line 275 of file uploadConditions.py.

Referenced by uploadConditions.HTTP.__init__().

276  def setRetries(self, retries = ()):
277  '''Allows to set retries.
278 
279  The retries are a sequence of the seconds to wait per retry.
280 
281  The retries are done on:
282  * PyCurl errors (includes network problems, e.g. not being able
283  to connect to the host).
284  * 502 Bad Gateway (for the moment, to avoid temporary
285  Apache-CherryPy issues).
286  * 503 Service Temporarily Unavailable (for when we update
287  the frontends).
288  '''
289  self.retries = retries
def uploadConditions.HTTP.setTimeout (   self,
  timeout = 0 
)
Allows to set a timeout.

Definition at line 269 of file uploadConditions.py.

270  def setTimeout(self, timeout = 0):
271  '''Allows to set a timeout.
272  '''
273  self.curl.setopt(self.curl.TIMEOUT, timeout)
274 

Member Data Documentation

uploadConditions.HTTP.baseUrl

Definition at line 241 of file uploadConditions.py.

Referenced by uploadConditions.HTTP.getToken(), uploadConditions.HTTP.query(), and uploadConditions.HTTP.setBaseUrl().

uploadConditions.HTTP.curl

Definition at line 232 of file uploadConditions.py.

uploadConditions.HTTP.retries

Definition at line 288 of file uploadConditions.py.

Referenced by uploadConditions.HTTP.query().

tuple uploadConditions.HTTP.retryCodes = frozenset([502, 503])
static

Definition at line 226 of file uploadConditions.py.

Referenced by uploadConditions.HTTP.query().

uploadConditions.HTTP.token

Definition at line 243 of file uploadConditions.py.

Referenced by uploadConditions.HTTP.getToken(), uploadConditions.HTTP.query(), and uploadConditions.ConditionsUploader.signOut().