CMS 3D CMS Logo

Classes | Functions | Variables
visDQMUpload Namespace Reference

Classes

class  HTTPSCertAuth
 
class  HTTPSCertAuthenticate
 

Functions

def encode (args, files)
 
def filetype (filename)
 
def marshall (args, files, request)
 
def upload (url, args, files)
 

Variables

 classification_ok
 
 classification_result
 
 data
 
 headers
 
 HTTPS
 
 ssl_cert_file
 
 ssl_key_file
 
 status
 
 uid
 
 x509_path
 

Function Documentation

def visDQMUpload.encode (   args,
  files 
)
  Encode form (name, value) and (name, filename, type) elements into
  multi-part/form-data. We don't actually need to know what we are
  uploading here, so just claim it's all text/plain.

Definition at line 40 of file visDQMUpload.py.

References filetype(), and str.

Referenced by marshall().

40 def encode(args, files):
41  """
42  Encode form (name, value) and (name, filename, type) elements into
43  multi-part/form-data. We don't actually need to know what we are
44  uploading here, so just claim it's all text/plain.
45  """
46  boundary = '----------=_DQM_FILE_BOUNDARY_=-----------'
47  (body, crlf) = ('', '\r\n')
48  for (key, value) in args.items():
49  payload = str(value)
50  body += '--' + boundary + crlf
51  body += ('Content-Disposition: form-data; name="%s"' % key) + crlf
52  body += crlf + payload + crlf
53  for (key, filename) in files.items():
54  body += '--' + boundary + crlf
55  body += ('Content-Disposition: form-data; name="%s"; filename="%s"'
56  % (key, os.path.basename(filename))) + crlf
57  body += ('Content-Type: %s' % filetype(filename)) + crlf
58  body += ('Content-Length: %d' % os.stat(filename)[ST_SIZE]) + crlf
59  body += crlf + open(filename, "r").read() + crlf
60  body += '--' + boundary + '--' + crlf + crlf
61  return ('multipart/form-data; boundary=' + boundary, body)
62 
def filetype(filename)
Definition: visDQMUpload.py:37
def encode(args, files)
Definition: visDQMUpload.py:40
#define str(s)
def visDQMUpload.filetype (   filename)

Definition at line 37 of file visDQMUpload.py.

Referenced by encode().

37 def filetype(filename):
38  return mimetypes.guess_type(filename)[0] or 'application/octet-stream'
39 
def filetype(filename)
Definition: visDQMUpload.py:37
def visDQMUpload.marshall (   args,
  files,
  request 
)
  Marshalls the arguments to the CGI script as multi-part/form-data,
  not the default application/x-www-form-url-encoded.  This improves
  the transfer of the large inputs and eases command line invocation
  of the CGI script.

Definition at line 63 of file visDQMUpload.py.

References encode(), and str.

Referenced by upload().

63 def marshall(args, files, request):
64  """
65  Marshalls the arguments to the CGI script as multi-part/form-data,
66  not the default application/x-www-form-url-encoded. This improves
67  the transfer of the large inputs and eases command line invocation
68  of the CGI script.
69  """
70  (type, body) = encode(args, files)
71  request.add_header('Content-Type', type)
72  request.add_header('Content-Length', str(len(body)))
73  request.add_data(body)
74 
def encode(args, files)
Definition: visDQMUpload.py:40
def marshall(args, files, request)
Definition: visDQMUpload.py:63
#define str(s)
def visDQMUpload.upload (   url,
  args,
  files 
)

Definition at line 75 of file visDQMUpload.py.

References marshall().

75 def upload(url, args, files):
76  ident = "visDQMUpload DQMGUI/%s python/%s" % \
77  (os.getenv('DQMGUI_VERSION', '?'), "%d.%d.%d" % sys.version_info[:3])
78  datareq = urllib2.Request(url + '/data/put')
79  datareq.add_header('Accept-encoding', 'gzip')
80  datareq.add_header('User-agent', ident)
81  marshall(args, files, datareq)
82  if 'https://' in url:
83  result = urllib2.build_opener(HTTPSCertAuthenticate()).open(datareq)
84  else:
85  result = urllib2.build_opener(urllib2.ProxyHandler({})).open(datareq)
86 
87  data = result.read()
88  if result.headers.get ('Content-encoding', '') == 'gzip':
89  data = gzip.GzipFile (fileobj=StringIO(data)).read ()
90  return (result.headers, data)
91 
def upload(url, args, files)
Definition: visDQMUpload.py:75
def marshall(args, files, request)
Definition: visDQMUpload.py:63

Variable Documentation

visDQMUpload.classification_ok

Definition at line 133 of file visDQMUpload.py.

visDQMUpload.classification_result

Definition at line 133 of file visDQMUpload.py.

visDQMUpload.data

Definition at line 142 of file visDQMUpload.py.

visDQMUpload.headers

Definition at line 142 of file visDQMUpload.py.

visDQMUpload.HTTPS

Definition at line 22 of file visDQMUpload.py.

visDQMUpload.ssl_cert_file

Definition at line 27 of file visDQMUpload.py.

visDQMUpload.ssl_key_file

Definition at line 26 of file visDQMUpload.py.

visDQMUpload.status

Definition at line 107 of file visDQMUpload.py.

visDQMUpload.uid

Definition at line 107 of file visDQMUpload.py.

visDQMUpload.x509_path

Definition at line 92 of file visDQMUpload.py.