def get_name(name_or_obj): """ Returns the 'name' attribute of 'name_or_obj' if present; if not, returns 'name_or_obj'. """ if isinstance(name_or_obj, six.string_types): # It's a name return name_or_obj try: return name_or_obj.name except AttributeError: raise exc.MissingName(name_or_obj)
def get_container(self, container): cname = self._resolve_name(container) if not cname: raise exc.MissingName("No container name specified") cont = self._container_cache.get(cname) if not cont: hdrs = self.connection.head_container(cname) cont = Container(self, name=cname, object_count=hdrs.get("x-container-object-count"), total_bytes=hdrs.get("x-container-bytes-used")) self._container_cache[cname] = cont return cont
def _get_name(self, name_or_obj): """ For convenience, many methods accept either an object or the name of the object as a parameter, but need the name to send to the API. This method handles that conversion. """ if isinstance(name_or_obj, basestring): return name_or_obj try: return name_or_obj.name except AttributeError: msg = "The object '%s' does not have a 'name' attribute." % name_or_obj raise exc.MissingName(msg)