Ejemplo n.º 1
0
  def Tap(self, resource):
    """Returns the next slice item in resource.

    Args:
      resource: The resource to flatten.

    Returns:
      True if the next slice is not a list, False if there are no more items,
      or Injector(resource) which is the resource with the next slice flattened.
    """
    if self._items is None:
      # Modify a serialized copy of resource.
      self._resource = resource_projector.MakeSerializable(resource)
      self._items = resource_property.Get(self._resource, self._key)
      if not isinstance(self._items, list):
        item = self._items
        self._items = None
        return peek_iterable.TapInjector(item, replace=True)
    if not self._items:
      self._items = None
      return False
    item = self._items.pop(0)
    if self._parent_key:
      parent = resource_property.Get(self._resource, self._parent_key)
    else:
      parent = self._resource
    parent[self._child_name] = item
    return peek_iterable.TapInjector(self._resource)
Ejemplo n.º 2
0
  def Tap(self, resource):
    """Replaces resource with its URI or skips the resource if it has no URI.

    Args:
      resource: The resource to replace with its URI.

    Returns:
      TapInjector(URI, replace=True) if the resource has a URI or False to skip
      the resource.
    """
    if resource_printer_base.IsResourceMarker(resource):
      return True
    uri = self._transform_uri(resource, undefined=None)
    if not uri:
      return False
    return peek_iterable.TapInjector(uri, replace=True)
Ejemplo n.º 3
0
  def Tap(self, resource):
    """Injects a PageMarker if the current page limit has been reached.

    Args:
      resource: The resource to limit.

    Returns:
      TapInjector(PageMarker) if the page current page limit has been reached,
      otherwise True to retain the current resource.
    """
    if resource_printer_base.IsResourceMarker(resource):
      return True
    self._count += 1
    if self._count > self._page_size:
      self._count = 0
      return peek_iterable.TapInjector(resource_printer_base.PageMarker())
    return True