original_docstring:  Allocate a task's resources to a Mesos offer
  
      :param task: the specification for the task to allocate
      :param offer_resources: a mapping of resource name -> available resources
          (should come from :func:`get_offer_resources`)
      :returns: a pair of (`prepared_task_config`, `remaining_resources`), where
          `prepared_task_config` is the task_config object modified with the
          actual resources consumed
      
docstring: Allocate a task's resources to a Mesos offer
docstring_tokens: Allocate a task ' s resources to a Mesos offer
code: def allocate_task_resources(
      task_config: MesosTaskConfig,
      offer_resources: ResourceSet,
  ) -> Tuple[MesosTaskConfig, ResourceSet]:
      """ Allocate a task's resources to a Mesos offer
  
      :param task: the specification for the task to allocate
      :param offer_resources: a mapping of resource name -> available resources
          (should come from :func:`get_offer_resources`)
      :returns: a pair of (`prepared_task_config`, `remaining_resources`), where
          `prepared_task_config` is the task_config object modified with the
          actual resources consumed
      """
      for res, val in offer_resources.items():
          if res not in _NUMERIC_RESOURCES:
              continue
          offer_resources = offer_resources.set(res, val - task_config[res])
  
      port = offer_resources.ports[0]['begin']
      if offer_resources.ports[0]['begin'] == offer_resources.ports[0]['end']:
          avail_ports = offer_resources.ports[1:]
      else:
          new_port_range = offer_resources.ports[0].set('begin', port + 1)
          avail_ports = offer_resources.ports.set(0, new_port_range)
      offer_resources = offer_resources.set('ports', avail_ports)
      task_config = task_config.set('ports', v(m(begin=port, end=port)))
      return task_config, offer_resources
code_tokens: def allocate_task_resources ( task_config : MesosTaskConfig , offer_resources : ResourceSet , ) -> Tuple [ MesosTaskConfig , ResourceSet ] : for res , val in offer_resources . items ( ) : if res not in _NUMERIC_RESOURCES : continue offer_resources = offer_resources . set ( res , val - task_config [ res ] ) port = offer_resources . ports [ 0 ] [ 'begin' ] if offer_resources . ports [ 0 ] [ 'begin' ] == offer_resources . ports [ 0 ] [ 'end' ] : avail_ports = offer_resources . ports [ 1 : ] else : new_port_range = offer_resources . ports [ 0 ] . set ( 'begin' , port + 1 ) avail_ports = offer_resources . ports . set ( 0 , new_port_range ) offer_resources = offer_resources . set ( 'ports' , avail_ports ) task_config = task_config . set ( 'ports' , v ( m ( begin = port , end = port ) ) ) return task_config , offer_resources
short_docstring: Allocate a task's resources to a Mesos offer
short_docstring_tokens: Allocate a task ' s resources to a Mesos offer
comment: """ Allocate a task's resources to a Mesos offer
  
      :param task: the specification for the task to allocate
      :param offer_resources: a mapping of resource name -> available resources
          (should come from :func:`get_offer_resources`)
      :returns: a pair of (`prepared_task_config`, `remaining_resources`), where
          `prepared_task_config` is the task_config object modified with the
          actual resources consumed
      """