tesseract v5.3.3.20231005
upload.AbstractRpcServer Class Reference
Inheritance diagram for upload.AbstractRpcServer:
upload.HttpRpcServer

Public Member Functions

def __init__ (self, host, auth_function, host_override=None, extra_headers={}, save_cookies=False)
 
def Send (self, request_path, payload=None, content_type="application/octet-stream", timeout=None, **kwargs)
 

Public Attributes

 host
 
 host_override
 
 auth_function
 
 authenticated
 
 extra_headers
 
 save_cookies
 
 opener
 

Detailed Description

Provides a common interface for a simple RPC server.

Definition at line 139 of file upload.py.

Constructor & Destructor Documentation

◆ __init__()

def upload.AbstractRpcServer.__init__ (   self,
  host,
  auth_function,
  host_override = None,
  extra_headers = {},
  save_cookies = False 
)
Creates a new HttpRpcServer.

Args:
  host: The host to send requests to.
  auth_function: A function that takes no arguments and returns an
    (email, password) tuple when called. Will be called if authentication
    is required.
  host_override: The host header to send to the server (defaults to host).
  extra_headers: A dict of extra headers to append to every request.
  save_cookies: If True, save the authentication cookies to local disk.
    If False, use an in-memory cookiejar instead.  Subclasses must
    implement this functionality.  Defaults to False.

Definition at line 142 of file upload.py.

143 save_cookies=False):
144 """Creates a new HttpRpcServer.
145
146 Args:
147 host: The host to send requests to.
148 auth_function: A function that takes no arguments and returns an
149 (email, password) tuple when called. Will be called if authentication
150 is required.
151 host_override: The host header to send to the server (defaults to host).
152 extra_headers: A dict of extra headers to append to every request.
153 save_cookies: If True, save the authentication cookies to local disk.
154 If False, use an in-memory cookiejar instead. Subclasses must
155 implement this functionality. Defaults to False.
156 """
157 self.host = host
158 self.host_override = host_override
159 self.auth_function = auth_function
160 self.authenticated = False
161 self.extra_headers = extra_headers
162 self.save_cookies = save_cookies
163 self.opener = self._GetOpener()
164 if self.host_override:
165 logging.info("Server: %s; Host: %s", self.host, self.host_override)
166 else:
167 logging.info("Server: %s", self.host)
168

Member Function Documentation

◆ Send()

def upload.AbstractRpcServer.Send (   self,
  request_path,
  payload = None,
  content_type = "application/octet-stream",
  timeout = None,
**  kwargs 
)
Sends an RPC and returns the response.

Args:
  request_path: The path to send the request to, eg /api/appversion/create.
  payload: The body of the request, or None to send an empty request.
  content_type: The Content-Type header to use.
  timeout: timeout in seconds; default None i.e. no timeout.
    (Note: for large requests on OS X, the timeout doesn't work right.)
  kwargs: Any keyword arguments are converted into query string parameters.

Returns:
  The response body, as a string.

Definition at line 306 of file upload.py.

309 **kwargs):
310 """Sends an RPC and returns the response.
311
312 Args:
313 request_path: The path to send the request to, eg /api/appversion/create.
314 payload: The body of the request, or None to send an empty request.
315 content_type: The Content-Type header to use.
316 timeout: timeout in seconds; default None i.e. no timeout.
317 (Note: for large requests on OS X, the timeout doesn't work right.)
318 kwargs: Any keyword arguments are converted into query string parameters.
319
320 Returns:
321 The response body, as a string.
322 """
323 # TODO: Don't require authentication. Let the server say
324 # whether it is necessary.
325 if not self.authenticated:
326 self._Authenticate()
327
328 old_timeout = socket.getdefaulttimeout()
329 socket.setdefaulttimeout(timeout)
330 try:
331 tries = 0
332 while True:
333 tries += 1
334 args = dict(kwargs)
335 url = "http://%s%s" % (self.host, request_path)
336 if args:
337 url += "?" + urllib.urlencode(args)
338 req = self._CreateRequest(url=url, data=payload)
339 req.add_header("Content-Type", content_type)
340 try:
341 f = self.opener.open(req)
342 response = f.read()
343 f.close()
344 return response
345 except urllib2.HTTPError, e:
346 if tries > 3:
347 raise
348 elif e.code == 401:
349 self._Authenticate()

Member Data Documentation

◆ auth_function

upload.AbstractRpcServer.auth_function

Definition at line 159 of file upload.py.

◆ authenticated

upload.AbstractRpcServer.authenticated

Definition at line 160 of file upload.py.

◆ extra_headers

upload.AbstractRpcServer.extra_headers

Definition at line 161 of file upload.py.

◆ host

upload.AbstractRpcServer.host

Definition at line 157 of file upload.py.

◆ host_override

upload.AbstractRpcServer.host_override

Definition at line 158 of file upload.py.

◆ opener

upload.AbstractRpcServer.opener

Definition at line 163 of file upload.py.

◆ save_cookies

upload.AbstractRpcServer.save_cookies

Definition at line 162 of file upload.py.


The documentation for this class was generated from the following file: