text
stringlengths
0
828
""""""Move the cursor to this item.""""""
cu = self.scraper.current_item
# Already here?
if self is cu:
return
# A child?
if cu.items and self in cu.items:
self.scraper.move_to(self)
return
# A parent?
if self is cu.parent:
self.scraper.move_up()
# A sibling?
if self.parent and self in self.parent.items:
self.scraper.move_up()
self.scraper.move_to(self)
return
# Last resort: Move to top and all the way down again
self.scraper.move_to_top()
for step in self.path:
self.scraper.move_to(step)"
3821,"def items(self):
""""""ItemList of children.""""""
if self.scraper.current_item is not self:
self._move_here()
if self._items is None:
self._items = ItemList()
self._items.scraper = self.scraper
self._items.collection = self
for i in self.scraper._fetch_itemslist(self):
i.parent = self
if i.type == TYPE_DATASET and i.dialect is None:
i.dialect = self.scraper.dialect
self._items.append(i)
return self._items"
3822,"def _hash(self):
""""""Return a hash for the current query.
This hash is _not_ a unique representation of the dataset!
""""""
dump = dumps(self.query, sort_keys=True)
if isinstance(dump, str):
dump = dump.encode('utf-8')
return md5(dump).hexdigest()"
3823,"def fetch_next(self, query=None, **kwargs):
""""""Generator to yield data one row at a time.
Yields a Result, not the entire ResultSet. The containing ResultSet
can be accessed through `Result.resultset`, but be careful not to
manipulate the ResultSet until it is populated (when this generator
is empty), or you may see unexpected results.
""""""
if query:
self.query = query
hash_ = self._hash
if hash_ in self._data:
for result in self._data[hash_]:
yield result
if self.scraper.current_item is not self:
self._move_here()
self._data[hash_] = ResultSet()
self._data[hash_].dialect = self.dialect
self._data[hash_].dataset = self
for result in self.scraper._fetch_data(self,
query=self.query,
**kwargs):
self._data[hash_].append(result)
yield result"
3824,"def dimensions(self):
""""""Available dimensions, if defined.""""""
# First of all: Select this dataset
if self.scraper.current_item is not self:
self._move_here()
if self._dimensions is None:
self._dimensions = DimensionList()
for d in self.scraper._fetch_dimensions(self):
d.dataset = self
d.scraper = self.scraper
self._dimensions.append(d)
return self._dimensions"
3825,"def shape(self):
""""""Compute the shape of the dataset as (rows, cols).""""""
if not self.data:
return (0, 0)
return (len(self.data), len(self.dimensions))"
3826,"def on(cls, hook):
""""""Hook decorator.""""""
def decorator(function_):
cls._hooks[hook].append(function_)
return function_
return decorator"
3827,"def move_to_top(self):
""""""Move to root item.""""""
self.current_item = self.root
for f in self._hooks[""top""]:
f(self)