Return the primary catalog for the given brain or object
346920
def get_catalog_for(self, brain_or_object):
        
        if not api.is_object(brain_or_object):
            raise TypeError("Invalid object type %r" % brain_or_object)
        catalogs = api.get_catalogs_for(brain_or_object, default="uid_catalog")
        return catalogs[0]
956741
def get_catalog_by_name(name):
    
    kwargs = {
            'name' : name,
        }
    result = util.callm("%s/%s" % ('catalog', 'profile'), kwargs)
    return Catalog(**util.fix(result['response']['catalog']))
394925
def get_object(self, catalog, portal_type, title=None, **kwargs):
        
        if not title and not kwargs:
            return None
        contentFilter = {"portal_type": portal_type}
        if title:
            contentFilter['title'] = to_unicode(title)
        contentFilter.update(kwargs)
        brains = catalog(contentFilter)
        if len(brains) > 1:
            logger.info("More than one object found for %s" % contentFilter)
            return None
        elif len(brains) == 0:
            if portal_type == 'AnalysisService':
                brains = catalog(portal_type=portal_type, getKeyword=title)
                if brains:
                    return brains[0].getObject()
            logger.info("No objects found for %s" % contentFilter)
            return None
        else:
            return brains[0].getObject()
1089732
def get_catalogue_header_value(cls, catalog, key):
        """"""
        header_value = None
        if '' in catalog:
            for line in catalog[''].split('\n'):
                if line.startswith('%s:' % key):
                    header_value = line.split(':', 1)[1].strip()

        return header_value
694199
def get_catalog(self, locale):
        """"""
        with translation.override(locale):
            translation_engine = DjangoTranslation(locale, domain=self.domain, localedirs=self.paths)

            trans_cat = translation_engine._catalog
            trans_fallback_cat = translation_engine._fallback._catalog if translation_engine._fallback else {}

            return trans_cat, trans_fallback_cat
1305945
def get_data_record(self, brain, field_names):
        
        record = {}
        model = None

        for field_name in field_names:
            # First try to get the value directly from the brain
            value = getattr(brain, field_name, None)

            # No metadata for this column name
            if value is None:
                logger.warn("Not a metadata field: {}".format(field_name))
                model = model or SuperModel(brain)
                value = model.get(field_name, None)
                if callable(value):
                    value = value()

            # '&nbsp;' instead of '' because empty div fields don't render
            # correctly in combo results table
            record[field_name] = value or "&nbsp;"

        return record
85886
def get_brain_info(brain):
    
    icon = api.get_icon(brain)
    # avoid 404 errors with these guys
    if "document_icon.gif" in icon:
        icon = ""

    id = api.get_id(brain)
    url = api.get_url(brain)
    title = api.get_title(brain)
    description = api.get_description(brain)
    parent = api.get_parent(brain)
    parent_title = api.get_title(parent)
    parent_url = api.get_url(parent)

    return {
        "id": id,
        "title": title,
        "title_or_id": title or id,
        "description": description,
        "url": url,
        "parent_title": parent_title,
        "parent_url": parent_url,
        "icon": icon,
    }
1212238
def get_uid(brain_or_object):
    
    if is_portal(brain_or_object):
        return '0'
    if is_brain(brain_or_object) and base_hasattr(brain_or_object, "UID"):
        return brain_or_object.UID
    return get_object(brain_or_object).UID()
1196349
def get_brain_by_uid(uid, default=None):
    
    if not is_uid(uid):
        return default

    # we try to find the object with the UID catalog
    uc = get_tool("uid_catalog")

    # try to find the object with the reference catalog first
    brains = uc(UID=uid)
    if len(brains) != 1:
        return default
    return brains[0]
1284709
def get_index(self, name):
        
        catalog = self.get_catalog()
        index = catalog._catalog.getIndex(name)
        logger.debug("get_index={} of catalog '{}' --> {}".format(
            name, catalog.__name__, index))
        return index
139804
def get_fields(brain_or_object):
    
    obj = get_object(brain_or_object)
    schema = get_schema(obj)
    if is_dexterity_content(obj):
        names = schema.names()
        fields = map(lambda name: schema.get(name), names)
        return dict(zip(names, fields))
    return dict(zip(schema.keys(), schema.fields()))
571928
def get_creation_date(brain_or_object):
    
    created = getattr(brain_or_object, "created", None)
    if created is None:
        fail("Object {} has no creation date ".format(
             repr(brain_or_object)))
    if callable(created):
        return created()
    return created
390798
def get_object(brain_object_uid, default=_marker):
    
    if is_uid(brain_object_uid):
        return get_object_by_uid(brain_object_uid)
    if not is_object(brain_object_uid):
        if default is _marker:
            fail("{} is not supported.".format(repr(brain_object_uid)))
        return default
    if is_brain(brain_object_uid):
        return brain_object_uid.getObject()
    return brain_object_uid
370034
def get_primary(self):
        """"""
        # Implemented here in Topology instead of MongoClient, so it can lock.
        with self._lock:
            topology_type = self._description.topology_type
            if topology_type != TOPOLOGY_TYPE.ReplicaSetWithPrimary:
                return None

            return writable_server_selector(self._new_selection())[0].address
1165846
def get_object_by_uid(uid, default=_marker):
    

    # nothing to do here
    if not uid:
        if default is not _marker:
            return default
        fail("get_object_by_uid requires UID as first argument; got {} instead"
             .format(uid))

    # we defined the portal object UID to be '0'::
    if uid == '0':
        return get_portal()

    # we try to find the object with both catalogs
    pc = get_portal_catalog()
    uc = get_tool("uid_catalog")

    # try to find the object with the reference catalog first
    brains = uc(UID=uid)
    if brains:
        return brains[0].getObject()

    # try to find the object with the portal catalog
    res = pc(UID=uid)
    if not res:
        if default is not _marker:
            return default
        fail("No object found for UID {}".format(uid))

    return get_object(res[0])
1186011
def get_endpoint(brain_or_object, default=DEFAULT_ENDPOINT):
    
    portal_type = get_portal_type(brain_or_object)
    resource = portal_type_to_resource(portal_type)

    # Try to get the right namespaced endpoint
    endpoints = router.DefaultRouter.view_functions.keys()
    if resource in endpoints:
        return resource  # exact match
    endpoint_candidates = filter(lambda e: e.endswith(resource), endpoints)
    if len(endpoint_candidates) == 1:
        # only return the namespaced endpoint, if we have an exact match
        return endpoint_candidates[0]

    return default
486656
def collections(record, key, value):
    """"""
    return {
        'primary': value.get('a'),
        'secondary': value.get('b'),
        'deleted': value.get('c'),
    }