code: def sort(self, key, reverse=False):
          if isinstance(key, (basestring, list, tuple)):
              if isinstance(key, basestring):
                  attrdefs = [s.strip() for s in key.split(',')]
                  attr_orders = [(a.split()+['asc', ])[:2] for a in attrdefs]
              else:
                  if isinstance(key[0], basestring):
                      attr_orders = [(a.split()+['asc', ])[:2] for a in key]
                  else:
                      attr_orders = key
              attrs = [attr for attr, order in attr_orders]
              if all(order == 'asc' for attr, order in attr_orders):
                  self.obs.sort(key=attrgetter(*attrs), reverse=reverse)
              elif all(order == 'desc' for attr, order in attr_orders):
                  self.obs.sort(key=attrgetter(*attrs), reverse=not reverse)
              else:
                  do_all(self.obs.sort(key=attrgetter(attr), reverse=(order == "desc"))
                         for attr, order in reversed(attr_orders))
          else:
              keyfn = key
              self.obs.sort(key=keyfn, reverse=reverse)
          return self