Advertisement
Guest User

storage._find

a guest
Feb 21st, 2014
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. else:
  2. # If marker is not none and basestring we query it.
  3. # Otherwise, return all matching records
  4. if marker is not None:
  5. try:
  6. marker = self._find(model, context, {'id': marker},
  7. one=True)
  8. except exceptions.NotFound:
  9. raise exceptions.MarkerNotFound(
  10. 'Marker %s could not be found' % marker)
  11. # Malformed UUIDs return StatementError
  12. except sqlalchemy_exc.StatementError as value_error:
  13. raise exceptions.InvalidMarker(value_error.message)
  14. sort_key = sort_key or 'created_at'
  15. sort_dir = sort_dir or 'asc'
  16.  
  17. # sort_dir is checked in paginate_query.
  18. # We duplicate the sort_dir check here to throw a more specific
  19. # exception than ValueError.
  20. if (sort_dir not in ['asc', 'desc']):
  21. raise exceptions.InvalidSortDir(_("Unknown sort direction, "
  22. "must be 'desc' or 'asc'"))
  23.  
  24. try:
  25. query = paginate_query(
  26. query, model, limit,
  27. [sort_key, 'id', 'created_at'], marker=marker,
  28. sort_dir=sort_dir)
  29.  
  30. return query.all()
  31. except InvalidSortKey as sort_key_error:
  32. raise exceptions.InvalidSortKey(sort_key_error.message)
  33. # Any ValueErrors are propagated back to the user as is.
  34. # Limits are checked at the API layer. If however central or
  35. # storage is called directly, invalid limits show up as
  36. # ValueError
  37. except ValueError as value_error:
  38. raise exceptions.ValueError(value_error.message)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement