@@ -381,7 +381,10 @@ def fetchItems(self, ekey, cls=None, container_start=None, container_size=None,
381381 data = self ._server .query (ekey , params = url_kw )
382382
383383 if '/all' in ekey :
384- self ._total_size = utils .cast (int , data .attrib .get ("totalSize" ))
384+ # totalSize is only included in the xml response
385+ # if container size is used.
386+ total_size = data .attrib .get ("totalSize" ) or data .attrib .get ("size" )
387+ self ._total_size = utils .cast (int , total_size )
385388
386389 items = self .findItems (data , cls , ekey , ** kwargs )
387390
@@ -585,25 +588,30 @@ def search(self, title=None, sort=None, maxresults=None,
585588
586589 results = []
587590 subresults = []
591+ offset = container_start
588592
589593 if maxresults is not None :
590594 container_size = min (container_size , maxresults )
591595 while True :
592596 key = '/library/sections/%s/all%s' % (self .key , utils .joinArgs (args ))
593597 subresults = self .fetchItems (key , container_start = container_start ,
594598 container_size = container_size )
599+ if not len (subresults ):
600+ if offset > self .totalSize :
601+ log .info ("container_start is higher then the number of items in the library" )
602+ break
603+
595604 results .extend (subresults )
596605
597606 # self.totalSize is not used as a condition in the while loop as
598607 # this require a additional http request.
599608 # self.totalSize is updated from .fetchItems
609+ wanted_number_of_items = self .totalSize - offset
600610 if maxresults is not None :
601- res = min (maxresults , self . totalSize )
611+ wanted_number_of_items = min (maxresults , wanted_number_of_items )
602612 container_size = min (container_size , maxresults - len (results ))
603- else :
604- res = self .totalSize
605613
606- if res <= len (results ):
614+ if wanted_number_of_items <= len (results ):
607615 break
608616
609617 container_start += container_size
0 commit comments