Ejemplo n.º 1
0
def submit_form_locally(instance, domain, max_wait=..., **kwargs):
    """
    :param instance: XML instance (as a string) to submit
    :param domain: The domain to submit the form to
    :param max_wait: Maximum time (in seconds) to allow the process to be delayed if
    the project is over its submission rate limit.
    The value None means "do not throttle".
    The special value ... (Ellipsis) means "The caller did not pass in a value".
    (This was chosen because of the special meaning already assumed by None.)
    """

    if max_wait is ...:
        max_wait = 0.1
    if max_wait is not None:
        rate_limit_submission(domain,
                              delay_rather_than_reject=True,
                              max_wait=max_wait)
    # intentionally leave these unauth'd for now
    kwargs['auth_context'] = kwargs.get('auth_context') or DefaultAuthContext()
    result = SubmissionPost(domain=domain, instance=instance, **kwargs).run()
    if not 200 <= result.response.status_code < 300:
        raise LocalSubmissionError('Error submitting (status code %s): %s' % (
            result.response.status_code,
            result.response.content.decode('utf-8', errors='backslashreplace'),
        ))
    return result
Ejemplo n.º 2
0
def submit_form_locally(instance, domain, **kwargs):
    # intentionally leave these unauth'd for now
    kwargs['auth_context'] = kwargs.get('auth_context') or DefaultAuthContext()
    result = SubmissionPost(domain=domain, instance=instance, **kwargs).run()
    if not 200 <= result.response.status_code < 300:
        raise LocalSubmissionError('Error submitting (status code %s): %s' % (
            result.response.status_code,
            result.response.content,
        ))
    return result