<s> """<STR_LIT>""" <EOL> __all__ = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> import calendar <EOL> import datetime <EOL> import math <EOL> import os <EOL> import re <EOL> import time <EOL> import urllib <EOL> import urlparse <EOL> from google . appengine . api import apiproxy_stub_map <EOL> from google . appengine . api import namespace_manager <EOL> from google . appengine . api import urlfetch <EOL> from google . appengine . api . labs . taskqueue import taskqueue_service_pb <EOL> from google . appengine . runtime import apiproxy_errors <EOL> class Error ( Exception ) : <EOL> """<STR_LIT>""" <EOL> class UnknownQueueError ( Error ) : <EOL> """<STR_LIT>""" <EOL> class TransientError ( Error ) : <EOL> """<STR_LIT>""" <EOL> class InternalError ( Error ) : <EOL> """<STR_LIT>""" <EOL> class InvalidTaskError ( Error ) : <EOL> """<STR_LIT>""" <EOL> class InvalidTaskNameError ( InvalidTaskError ) : <EOL> """<STR_LIT>""" <EOL> class TaskTooLargeError ( InvalidTaskError ) : <EOL> """<STR_LIT>""" <EOL> class TaskAlreadyExistsError ( InvalidTaskError ) : <EOL> """<STR_LIT>""" <EOL> class TombstonedTaskError ( InvalidTaskError ) : <EOL> """<STR_LIT>""" <EOL> class InvalidUrlError ( InvalidTaskError ) : <EOL> """<STR_LIT>""" <EOL> class BadTaskStateError ( Error ) : <EOL> """<STR_LIT>""" <EOL> class InvalidQueueError ( Error ) : <EOL> """<STR_LIT>""" <EOL> class InvalidQueueNameError ( InvalidQueueError ) : <EOL> """<STR_LIT>""" <EOL> class _RelativeUrlError ( Error ) : <EOL> """<STR_LIT>""" <EOL> class PermissionDeniedError ( Error ) : <EOL> """<STR_LIT>""" <EOL> class DuplicateTaskNameError ( Error ) : <EOL> """<STR_LIT>""" <EOL> class TooManyTasksError ( Error ) : <EOL> """<STR_LIT>""" <EOL> class DatastoreError ( Error ) : <EOL> """<STR_LIT>""" <EOL> class BadTransactionStateError ( Error ) : <EOL> """<STR_LIT>""" <EOL> class InvalidTaskRetryOptionsError ( Error ) : <EOL> """<STR_LIT>""" <EOL> BadTransactionState = BadTransactionStateError <EOL> MAX_QUEUE_NAME_LENGTH = <NUM_LIT:100> <EOL> MAX_TASK_NAME_LENGTH = <NUM_LIT> <EOL> MAX_TASK_SIZE_BYTES = <NUM_LIT:10> * ( <NUM_LIT:2> ** <NUM_LIT:10> ) <EOL> MAX_TASKS_PER_ADD = <NUM_LIT:100> <EOL> MAX_URL_LENGTH = <NUM_LIT> <EOL> _DEFAULT_QUEUE = '<STR_LIT:default>' <EOL> _DEFAULT_QUEUE_PATH = '<STR_LIT>' <EOL> _METHOD_MAP = { <EOL> '<STR_LIT:GET>' : taskqueue_service_pb . TaskQueueAddRequest . GET , <EOL> '<STR_LIT:POST>' : taskqueue_service_pb . TaskQueueAddRequest . POST , <EOL> '<STR_LIT>' : taskqueue_service_pb . TaskQueueAddRequest . HEAD , <EOL> '<STR_LIT>' : taskqueue_service_pb . TaskQueueAddRequest . PUT , <EOL> '<STR_LIT>' : taskqueue_service_pb . TaskQueueAddRequest . DELETE , <EOL> } <EOL> _NON_POST_METHODS = frozenset ( [ '<STR_LIT:GET>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> _BODY_METHODS = frozenset ( [ '<STR_LIT:POST>' , '<STR_LIT>' ] ) <EOL> _TASK_NAME_PATTERN = r'<STR_LIT>' % MAX_TASK_NAME_LENGTH <EOL> _TASK_NAME_RE = re . compile ( _TASK_NAME_PATTERN ) <EOL> _QUEUE_NAME_PATTERN = r'<STR_LIT>' % MAX_QUEUE_NAME_LENGTH <EOL> _QUEUE_NAME_RE = re . compile ( _QUEUE_NAME_PATTERN ) <EOL> _ERROR_MAPPING = { <EOL> taskqueue_service_pb . TaskQueueServiceError . UNKNOWN_QUEUE : UnknownQueueError , <EOL> taskqueue_service_pb . TaskQueueServiceError . TRANSIENT_ERROR : <EOL> TransientError , <EOL> taskqueue_service_pb . TaskQueueServiceError . INTERNAL_ERROR : InternalError , <EOL> taskqueue_service_pb . TaskQueueServiceError . TASK_TOO_LARGE : <EOL> TaskTooLargeError , <EOL> taskqueue_service_pb . TaskQueueServiceError . INVALID_TASK_NAME : <EOL> InvalidTaskNameError , <EOL> taskqueue_service_pb . TaskQueueServiceError . INVALID_QUEUE_NAME : <EOL> InvalidQueueNameError , <EOL> taskqueue_service_pb . TaskQueueServiceError . INVALID_URL : InvalidUrlError , <EOL> taskqueue_service_pb . TaskQueueServiceError . INVALID_QUEUE_RATE : <EOL> InvalidQueueError , <EOL> taskqueue_service_pb . TaskQueueServiceError . PERMISSION_DENIED : <EOL> PermissionDeniedError , <EOL> taskqueue_service_pb . TaskQueueServiceError . TASK_ALREADY_EXISTS : <EOL> TaskAlreadyExistsError , <EOL> taskqueue_service_pb . TaskQueueServiceError . TOMBSTONED_TASK : <EOL> TombstonedTaskError , <EOL> taskqueue_service_pb . TaskQueueServiceError . INVALID_ETA : InvalidTaskError , <EOL> taskqueue_service_pb . TaskQueueServiceError . INVALID_REQUEST : Error , <EOL> taskqueue_service_pb . TaskQueueServiceError . UNKNOWN_TASK : Error , <EOL> taskqueue_service_pb . TaskQueueServiceError . TOMBSTONED_QUEUE : Error , <EOL> taskqueue_service_pb . TaskQueueServiceError . DUPLICATE_TASK_NAME : <EOL> DuplicateTaskNameError , <EOL> taskqueue_service_pb . TaskQueueServiceError . TOO_MANY_TASKS : <EOL> TooManyTasksError , <EOL> } <EOL> _PRESERVE_ENVIRONMENT_HEADERS = ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , ) <EOL> class _UTCTimeZone ( datetime . tzinfo ) : <EOL> """<STR_LIT>""" <EOL> ZERO = datetime . timedelta ( <NUM_LIT:0> ) <EOL> def utcoffset ( self , dt ) : <EOL> return self . ZERO <EOL> def dst ( self , dt ) : <EOL> return self . ZERO <EOL> def tzname ( self , dt ) : <EOL> return '<STR_LIT>' <EOL> _UTC = _UTCTimeZone ( ) <EOL> def _parse_relative_url ( relative_url ) : <EOL> """<STR_LIT>""" <EOL> if not relative_url : <EOL> raise _RelativeUrlError ( '<STR_LIT>' ) <EOL> ( scheme , netloc , path , query , fragment ) = urlparse . urlsplit ( relative_url ) <EOL> if scheme or netloc : <EOL> raise _RelativeUrlError ( '<STR_LIT>' ) <EOL> if fragment : <EOL> raise _RelativeUrlError ( '<STR_LIT>' ) <EOL> if not path or path [ <NUM_LIT:0> ] != '<STR_LIT:/>' : <EOL> raise _RelativeUrlError ( '<STR_LIT>' ) <EOL> return path , query <EOL> def _flatten_params ( params ) : <EOL> """<STR_LIT>""" <EOL> def get_string ( value ) : <EOL> if isinstance ( value , unicode ) : <EOL> return unicode ( value ) . encode ( '<STR_LIT:utf-8>' ) <EOL> else : <EOL> return str ( value ) <EOL> param_list = [ ] <EOL> for key , value in params . iteritems ( ) : <EOL> key = get_string ( key ) <EOL> if isinstance ( value , basestring ) : <EOL> param_list . append ( ( key , get_string ( value ) ) ) <EOL> else : <EOL> try : <EOL> iterator = iter ( value ) <EOL> except TypeError : <EOL> param_list . append ( ( key , str ( value ) ) ) <EOL> else : <EOL> param_list . extend ( ( key , get_string ( v ) ) for v in iterator ) <EOL> return param_list <EOL> class TaskRetryOptions ( object ) : <EOL> """<STR_LIT>""" <EOL> __CONSTRUCTOR_KWARGS = frozenset ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def __init__ ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> args_diff = set ( kwargs . iterkeys ( ) ) - self . __CONSTRUCTOR_KWARGS <EOL> if args_diff : <EOL> raise TypeError ( '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( args_diff ) ) <EOL> self . __min_backoff_seconds = kwargs . get ( '<STR_LIT>' ) <EOL> if ( self . __min_backoff_seconds is not None and <EOL> self . __min_backoff_seconds < <NUM_LIT:0> ) : <EOL> raise InvalidTaskRetryOptionsError ( <EOL> '<STR_LIT>' ) <EOL> self . __max_backoff_seconds = kwargs . get ( '<STR_LIT>' ) <EOL> if ( self . __max_backoff_seconds is not None and <EOL> self . __max_backoff_seconds < <NUM_LIT:0> ) : <EOL> raise InvalidTaskRetryOptionsError ( <EOL> '<STR_LIT>' ) <EOL> if ( self . __min_backoff_seconds is not None and <EOL> self . __max_backoff_seconds is not None and <EOL> self . __max_backoff_seconds < self . __min_backoff_seconds ) : <EOL> raise InvalidTaskRetryOptionsError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . __max_doublings = kwargs . get ( '<STR_LIT>' ) <EOL> if self . __max_doublings is not None and self . __max_doublings < <NUM_LIT:0> : <EOL> raise InvalidTaskRetryOptionsError ( <EOL> '<STR_LIT>' ) <EOL> self . __task_retry_limit = kwargs . get ( '<STR_LIT>' ) <EOL> if self . __task_retry_limit is not None and self . __task_retry_limit < <NUM_LIT:0> : <EOL> raise InvalidTaskRetryOptionsError ( <EOL> '<STR_LIT>' ) <EOL> self . __task_age_limit = kwargs . get ( '<STR_LIT>' ) <EOL> if self . __task_age_limit is not None : <EOL> if self . __task_age_limit < <NUM_LIT:0> : <EOL> raise InvalidTaskRetryOptionsError ( <EOL> '<STR_LIT>' ) <EOL> self . __task_age_limit = int ( math . ceil ( self . __task_age_limit ) ) <EOL> @ property <EOL> def min_backoff_seconds ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __min_backoff_seconds <EOL> @ property <EOL> def max_backoff_seconds ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __max_backoff_seconds <EOL> @ property <EOL> def task_age_limit ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __task_age_limit <EOL> @ property <EOL> def max_doublings ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __max_doublings <EOL> @ property <EOL> def task_retry_limit ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __task_retry_limit <EOL> class Task ( object ) : <EOL> """<STR_LIT>""" <EOL> __CONSTRUCTOR_KWARGS = frozenset ( [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:url>' ] ) <EOL> __eta_posix = None <EOL> def __init__ ( self , payload = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> args_diff = set ( kwargs . iterkeys ( ) ) - self . __CONSTRUCTOR_KWARGS <EOL> if args_diff : <EOL> raise TypeError ( '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( args_diff ) ) <EOL> self . __name = kwargs . get ( '<STR_LIT:name>' ) <EOL> if self . __name and not _TASK_NAME_RE . match ( self . __name ) : <EOL> raise InvalidTaskNameError ( <EOL> '<STR_LIT>' % <EOL> ( _TASK_NAME_PATTERN , self . __name ) ) <EOL> self . __default_url , self . __relative_url , query = Task . __determine_url ( <EOL> kwargs . get ( '<STR_LIT:url>' , '<STR_LIT>' ) ) <EOL> self . __headers = urlfetch . _CaselessDict ( ) <EOL> self . __headers . update ( kwargs . get ( '<STR_LIT>' , { } ) ) <EOL> self . __method = kwargs . get ( '<STR_LIT>' , '<STR_LIT:POST>' ) . upper ( ) <EOL> self . __payload = None <EOL> params = kwargs . get ( '<STR_LIT>' , { } ) <EOL> for header_name , environ_name in _PRESERVE_ENVIRONMENT_HEADERS : <EOL> value = os . environ . get ( environ_name ) <EOL> if value is not None : <EOL> self . __headers . setdefault ( header_name , value ) <EOL> self . __headers . setdefault ( '<STR_LIT>' , <EOL> namespace_manager . get_namespace ( ) ) <EOL> if query and params : <EOL> raise InvalidTaskError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if self . __method == '<STR_LIT:POST>' : <EOL> if payload and params : <EOL> raise InvalidTaskError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> elif query : <EOL> raise InvalidTaskError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> elif params : <EOL> self . __payload = Task . __encode_params ( params ) <EOL> self . __headers . setdefault ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif payload is not None : <EOL> self . __payload = Task . __convert_payload ( payload , self . __headers ) <EOL> elif self . __method in _NON_POST_METHODS : <EOL> if payload and self . __method not in _BODY_METHODS : <EOL> raise InvalidTaskError ( '<STR_LIT>' % <EOL> '<STR_LIT:U+002CU+0020>' . join ( _BODY_METHODS ) ) <EOL> if payload : <EOL> self . __payload = Task . __convert_payload ( payload , self . __headers ) <EOL> if params : <EOL> query = Task . __encode_params ( params ) <EOL> if query : <EOL> self . __relative_url = '<STR_LIT>' % ( self . __relative_url , query ) <EOL> else : <EOL> raise InvalidTaskError ( '<STR_LIT>' % self . __method ) <EOL> self . __headers_list = _flatten_params ( self . __headers ) <EOL> self . __eta_posix = Task . __determine_eta_posix ( <EOL> kwargs . get ( '<STR_LIT>' ) , kwargs . get ( '<STR_LIT>' ) ) <EOL> self . __eta = None <EOL> self . __retry_options = kwargs . get ( '<STR_LIT>' ) <EOL> self . __enqueued = False <EOL> if self . size > MAX_TASK_SIZE_BYTES : <EOL> raise TaskTooLargeError ( '<STR_LIT>' % <EOL> ( MAX_TASK_SIZE_BYTES , self . size ) ) <EOL> @ staticmethod <EOL> def __determine_url ( relative_url ) : <EOL> """<STR_LIT>""" <EOL> if not relative_url : <EOL> default_url , query = True , '<STR_LIT>' <EOL> else : <EOL> default_url = False <EOL> try : <EOL> relative_url , query = _parse_relative_url ( relative_url ) <EOL> except _RelativeUrlError , e : <EOL> raise InvalidUrlError ( e ) <EOL> if len ( relative_url ) > MAX_URL_LENGTH : <EOL> raise InvalidUrlError ( <EOL> '<STR_LIT>' % <EOL> ( MAX_URL_LENGTH , len ( relative_url ) ) ) <EOL> return ( default_url , relative_url , query ) <EOL> @ staticmethod <EOL> def __determine_eta_posix ( eta = None , countdown = None , current_time = time . time ) : <EOL> """<STR_LIT>""" <EOL> if eta is not None and countdown is not None : <EOL> raise InvalidTaskError ( '<STR_LIT>' ) <EOL> elif eta is not None : <EOL> if not isinstance ( eta , datetime . datetime ) : <EOL> raise InvalidTaskError ( '<STR_LIT>' ) <EOL> elif eta . tzinfo is None : <EOL> return time . mktime ( eta . timetuple ( ) ) + eta . microsecond * <NUM_LIT> <EOL> else : <EOL> return calendar . timegm ( eta . utctimetuple ( ) ) + eta . microsecond * <NUM_LIT> <EOL> elif countdown is not None : <EOL> try : <EOL> countdown = float ( countdown ) <EOL> except ValueError : <EOL> raise InvalidTaskError ( '<STR_LIT>' ) <EOL> except OverflowError : <EOL> raise InvalidTaskError ( '<STR_LIT>' ) <EOL> else : <EOL> return current_time ( ) + countdown <EOL> else : <EOL> return current_time ( ) <EOL> @ staticmethod <EOL> def __encode_params ( params ) : <EOL> """<STR_LIT>""" <EOL> return urllib . urlencode ( _flatten_params ( params ) ) <EOL> @ staticmethod <EOL> def __convert_payload ( payload , headers ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( payload , unicode ) : <EOL> headers . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> payload = payload . encode ( '<STR_LIT:utf-8>' ) <EOL> elif not isinstance ( payload , str ) : <EOL> raise InvalidTaskError ( <EOL> '<STR_LIT>' % payload ) <EOL> return payload <EOL> @ property <EOL> def on_queue_url ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __default_url <EOL> @ property <EOL> def eta_posix ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . __eta_posix is None and self . __eta is not None : <EOL> self . __eta_posix = Task . __determine_eta_posix ( self . __eta ) <EOL> return self . __eta_posix <EOL> @ property <EOL> def eta ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . __eta is None and self . __eta_posix is not None : <EOL> self . __eta = datetime . datetime . fromtimestamp ( self . __eta_posix , _UTC ) <EOL> return self . __eta <EOL> @ property <EOL> def headers ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __headers . copy ( ) <EOL> @ property <EOL> def method ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __method <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __name <EOL> @ property <EOL> def payload ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __payload <EOL> @ property <EOL> def size ( self ) : <EOL> """<STR_LIT>""" <EOL> HEADER_SEPERATOR = len ( '<STR_LIT>' ) <EOL> header_size = sum ( ( len ( key ) + len ( value ) + HEADER_SEPERATOR ) <EOL> for key , value in self . __headers_list ) <EOL> return ( len ( self . __method ) + len ( self . __payload or '<STR_LIT>' ) + <EOL> len ( self . __relative_url ) + header_size ) <EOL> @ property <EOL> def url ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __relative_url <EOL> @ property <EOL> def retry_options ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __retry_options <EOL> @ property <EOL> def was_enqueued ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __enqueued <EOL> def add ( self , queue_name = _DEFAULT_QUEUE , transactional = False ) : <EOL> """<STR_LIT>""" <EOL> return Queue ( queue_name ) . add ( self , transactional = transactional ) <EOL> class Queue ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name = _DEFAULT_QUEUE ) : <EOL> """<STR_LIT>""" <EOL> if not _QUEUE_NAME_RE . match ( name ) : <EOL> raise InvalidQueueNameError ( <EOL> '<STR_LIT>' % <EOL> ( _QUEUE_NAME_PATTERN , name ) ) <EOL> self . __name = name <EOL> self . __url = '<STR_LIT>' % ( _DEFAULT_QUEUE_PATH , self . __name ) <EOL> self . _app = None <EOL> def purge ( self ) : <EOL> """<STR_LIT>""" <EOL> request = taskqueue_service_pb . TaskQueuePurgeQueueRequest ( ) <EOL> response = taskqueue_service_pb . TaskQueuePurgeQueueResponse ( ) <EOL> request . set_queue_name ( self . __name ) <EOL> if self . _app : <EOL> request . set_app_id ( self . _app ) <EOL> try : <EOL> apiproxy_stub_map . MakeSyncCall ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> request , <EOL> response ) <EOL> except apiproxy_errors . ApplicationError , e : <EOL> raise self . __TranslateError ( e . application_error , e . error_detail ) <EOL> def add ( self , task , transactional = False ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> tasks = list ( iter ( task ) ) <EOL> except TypeError : <EOL> tasks = [ task ] <EOL> multiple = False <EOL> else : <EOL> multiple = True <EOL> self . __AddTasks ( tasks , transactional ) <EOL> if multiple : <EOL> return tasks <EOL> else : <EOL> assert len ( tasks ) == <NUM_LIT:1> <EOL> return tasks [ <NUM_LIT:0> ] <EOL> def __AddTasks ( self , tasks , transactional ) : <EOL> """<STR_LIT>""" <EOL> if len ( tasks ) > MAX_TASKS_PER_ADD : <EOL> raise TooManyTasksError ( <EOL> '<STR_LIT>' % <EOL> MAX_TASKS_PER_ADD ) <EOL> request = taskqueue_service_pb . TaskQueueBulkAddRequest ( ) <EOL> response = taskqueue_service_pb . TaskQueueBulkAddResponse ( ) <EOL> task_names = set ( ) <EOL> for task in tasks : <EOL> if task . name : <EOL> if task . name in task_names : <EOL> raise DuplicateTaskNameError ( <EOL> '<STR_LIT>' % <EOL> task . name ) <EOL> task_names . add ( task . name ) <EOL> self . __FillAddRequest ( task , request . add_add_request ( ) , transactional ) <EOL> try : <EOL> apiproxy_stub_map . MakeSyncCall ( '<STR_LIT>' , '<STR_LIT>' , request , response ) <EOL> except apiproxy_errors . ApplicationError , e : <EOL> raise self . __TranslateError ( e . application_error , e . error_detail ) <EOL> assert response . taskresult_size ( ) == len ( tasks ) , ( <EOL> '<STR_LIT>' % ( <EOL> len ( tasks ) , response . taskresult_size ( ) ) ) <EOL> exception = None <EOL> for task , task_result in zip ( tasks , response . taskresult_list ( ) ) : <EOL> if task_result . result ( ) == taskqueue_service_pb . TaskQueueServiceError . OK : <EOL> if task_result . has_chosen_task_name ( ) : <EOL> task . _Task__name = task_result . chosen_task_name ( ) <EOL> task . _Task__enqueued = True <EOL> elif ( task_result . result ( ) == <EOL> taskqueue_service_pb . TaskQueueServiceError . SKIPPED ) : <EOL> pass <EOL> elif exception is None : <EOL> exception = self . __TranslateError ( task_result . result ( ) ) <EOL> if exception is not None : <EOL> raise exception <EOL> return tasks <EOL> def __FillTaskQueueRetryParameters ( self , <EOL> retry_options , <EOL> retry_retry_parameters ) : <EOL> """<STR_LIT>""" <EOL> if retry_options . min_backoff_seconds is not None : <EOL> retry_retry_parameters . set_min_backoff_sec ( <EOL> retry_options . min_backoff_seconds ) <EOL> if retry_options . max_backoff_seconds is not None : <EOL> retry_retry_parameters . set_max_backoff_sec ( <EOL> retry_options . max_backoff_seconds ) <EOL> if retry_options . task_retry_limit is not None : <EOL> retry_retry_parameters . set_retry_limit ( retry_options . task_retry_limit ) <EOL> if retry_options . task_age_limit is not None : <EOL> retry_retry_parameters . set_age_limit_sec ( retry_options . task_age_limit ) <EOL> if retry_options . max_doublings is not None : <EOL> retry_retry_parameters . set_max_doublings ( retry_options . max_doublings ) <EOL> def __FillAddRequest ( self , task , task_request , transactional ) : <EOL> """<STR_LIT>""" <EOL> if task . was_enqueued : <EOL> raise BadTaskStateError ( '<STR_LIT>' ) <EOL> adjusted_url = task . url <EOL> if task . on_queue_url : <EOL> adjusted_url = self . __url + task . url <EOL> task_request . set_queue_name ( self . __name ) <EOL> task_request . set_eta_usec ( long ( task . eta_posix * <NUM_LIT> ) ) <EOL> task_request . set_method ( _METHOD_MAP . get ( task . method ) ) <EOL> task_request . set_url ( adjusted_url ) <EOL> if task . name : <EOL> task_request . set_task_name ( task . name ) <EOL> else : <EOL> task_request . set_task_name ( '<STR_LIT>' ) <EOL> if task . payload : <EOL> task_request . set_body ( task . payload ) <EOL> for key , value in _flatten_params ( task . headers ) : <EOL> header = task_request . add_header ( ) <EOL> header . set_key ( key ) <EOL> header . set_value ( value ) <EOL> if task . retry_options : <EOL> self . __FillTaskQueueRetryParameters ( <EOL> task . retry_options , task_request . mutable_retry_parameters ( ) ) <EOL> if self . _app : <EOL> task_request . set_app_id ( self . _app ) <EOL> if transactional : <EOL> from google . appengine . api import datastore <EOL> if not datastore . _MaybeSetupTransaction ( task_request , [ ] ) : <EOL> raise BadTransactionStateError ( <EOL> '<STR_LIT>' ) <EOL> if task_request . has_transaction ( ) and task . name : <EOL> raise InvalidTaskNameError ( <EOL> '<STR_LIT>' ) <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __name <EOL> @ staticmethod <EOL> def __TranslateError ( error , detail = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if ( error >= taskqueue_service_pb . TaskQueueServiceError . DATASTORE_ERROR <EOL> and isinstance ( error , int ) ) : <EOL> from google . appengine . api import datastore <EOL> datastore_exception = datastore . _DatastoreExceptionFromErrorCodeAndDetail ( <EOL> error - taskqueue_service_pb . TaskQueueServiceError . DATASTORE_ERROR , <EOL> detail ) <EOL> class JointException ( datastore_exception . __class__ , DatastoreError ) : <EOL> """<STR_LIT>""" <EOL> __msg = ( u'<STR_LIT>' % <EOL> ( datastore_exception . __class__ , detail ) ) <EOL> def __str__ ( self ) : <EOL> return JointException . __msg <EOL> return JointException ( ) <EOL> else : <EOL> exception_class = _ERROR_MAPPING . get ( error , None ) <EOL> if exception_class : <EOL> return exception_class ( detail ) <EOL> else : <EOL> return Error ( '<STR_LIT>' % ( error , detail ) ) <EOL> def add ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> transactional = kwargs . pop ( '<STR_LIT>' , False ) <EOL> queue_name = kwargs . pop ( '<STR_LIT>' , _DEFAULT_QUEUE ) <EOL> return Task ( * args , ** kwargs ) . add ( <EOL> queue_name = queue_name , transactional = transactional ) </s>
