Return the type, e.g. 'package' for a given resource
779431
def resource_type(resource)
      raise_unless_xpath!(resource)
      type = resource.xpath("string(command/ident/@value)")
      if type.empty?
        raise ArgumentError, "Provided AST node is not a resource"
      end
      type
    end
945828
def parent(self):
        
        family = self.repository.get_parent_package_family(self.resource)
        return PackageFamily(family) if family else None
76537
def from_api_repr(cls, resource):
        
        return cls(kind=resource.get("kind"), substeps=resource.get("substeps", ()))
1259907
def get_type(self, name):
        

        # XXX FIXME uhm...how to do all the different types of hidden-services?
        if name.lower() == 'hiddenservices':
            return FilesystemOnionService
        return type(self.parsers[name])
898086
def get_translation_for(package_name: str) -> gettext.NullTranslations:
    """"""
    localedir = None
    for localedir in pkg_resources.resource_filename(package_name, 'i18n'), None:
        localefile = gettext.find(package_name, localedir)  # type: ignore
        if localefile:
            break
    else:
        pass
    return gettext.translation(package_name, localedir=localedir, fallback=True)
311
function getMessageFromPackage(messageType, type, callback) {
  var packageName = getPackageNameFromMessageType(messageType);
  var messageName = getMessageNameFromMessageType(messageType);
  packages.findPackage(packageName, function(error, directory) {
    var filePath;
    filePath = path.join(directory, type, messageName + '.' + type);
    getMessageFromFile(messageType, filePath, type, callback);
  });
}
860904
def _collect_from_package(self, module,
                              type_checker: Optional[FunctionType] = None,
                              ) -> Dict[str, Any]:
        
        type_checker = type_checker or self.type_check
        members = dict(self._get_members(module, type_checker))

        if pkgutil.get_loader(module).is_package(module.__name__):
            for loader, name, is_pkg in pkgutil.walk_packages(module.__path__):
                child_module_name = f'{module.__package__}.{name}'
                child_module = importlib.import_module(child_module_name)
                for key, obj in self._get_members(child_module, type_checker):
                    if key not in members:
                        members[key] = obj

        return members
81014
def detect_type(err, install_rdf=None, xpi_package=None):
    """"""

    # The types in the install.rdf don't pair up 1:1 with the type
    # system that we're using for expectations and the like. This is
    # to help translate between the two.
    translated_types = {'2': PACKAGE_EXTENSION,
                        '4': PACKAGE_THEME,
                        '8': PACKAGE_LANGPACK,
                        '32': PACKAGE_MULTI,
                        '64': PACKAGE_DICTIONARY,
                        # New "experiment" types: see bug 1220097 and
                        # https://github.com/mozilla/addons-server/issues/3315
                        '128': PACKAGE_EXTENSION,
                        '256': PACKAGE_EXTENSION,}

    # If we're missing our install.rdf file, we can try to make some
    # assumptions.
    if install_rdf is None:
        types = {'xpi': PACKAGE_DICTIONARY}

        err.notice(('typedetection',
                    'detect_type',
                    'missing_install_rdf'),
                   'install.rdf was not found.',
                   'The type should be determined by install.rdf if present. '
                   "If it isn't, we still need to know the type.")

        # If we know what the file type might be, return it.
        if xpi_package.extension in types:
            return types[xpi_package.extension]
        # Otherwise, we're out of luck :(
        else:
            return None

    # Attempt to locate the <em:type> node in the RDF doc.
    type_uri = install_rdf.uri('type')
    type_ = install_rdf.get_object(None, type_uri)

    # Dictionaries are weird too, they might not have the obligatory
    # em:type. We can assume that if they have a /dictionaries/ folder,
    # they are a dictionary because even if they aren't, dictionaries
    # have an extraordinarily strict set of rules and file filters that
    # must be passed. It's so crazy secure that it's cool if we use it
    # as kind of a fallback.

    if any(file_ for file_ in xpi_package if
               file_.startswith('dictionaries/')):
        if type_ != '64':
            err.error(('typedetection',
                       'dictionary_valid_type',
                       'invalid_em_type'),
                      'Invalid <em:type> value.',
                      'The package appears to be a dictionary but does not have '
                      'the correct <em:type> set in the install manifest.')
        return PACKAGE_DICTIONARY

    if type_ is not None:
        if type_ in translated_types:
            err.save_resource('is_multipackage', type_ == '32', pushable=True)
            # Make sure we translate back to the normalized version
            return translated_types[type_]
        else:
            err.error(('typedetection',
                       'detect_type',
                       'invalid_em_type'),
                      'Invalid <em:type> value.',
                      'The only valid values for <em:type> are 2, 4, 8, and '
                      '32. Any other values are either invalid or deprecated.',
                      'install.rdf')
            return
    else:
        err.notice(
            err_id=('typedetection',
                    'detect_type',
                    'no_em:type'),
            notice='No <em:type> element found in install.rdf',
            description="It isn't always required, but it is the most reliable "
                        'method for determining add-on type.',
            filename='install.rdf')

    # There's no type element, so the spec says that it's either a
    # theme or an extension. At this point, we know that it isn't
    # a dictionary, language pack, or multiple extension pack.
    extensions = {'jar': '4',
                  'xpi': '2'}

    # If the package's extension is listed in the [tiny] extension
    # dictionary, then just return that. We'll validate against that
    # add-on type's layout later. Better to false positive than to false
    # negative.
    if xpi_package.extension in extensions:
        # Make sure it gets translated back to the normalized version
        install_rdf_type = extensions[xpi_package.extension]
        return translated_types[install_rdf_type]
472634
def package_type(self):
        
        mapping = {'bdist_egg': u'egg', 'bdist_wheel': u'wheel',
                   'sdist': u'source'}
        ptype = self._release['packagetype']
        if ptype in mapping.keys():
            return mapping[ptype]
        return ptype
461423
def getversion(package):
    
    distribution = get_distribution(package)
    if distribution is None:
        raise RuntimeError("Can't find distribution {0}".format(package))
    repo_type = get_repo_type(distribution.location)
    if repo_type is None:
        return distribution.version

    return repo_type.get_version(distribution.location)
245950
def resource_type_type(loader):
    

    def impl(string):
        t_resources = loader.get_models('common.models#ResourceTypes')
        if set(string) - set("sco"):
            raise ValueError
        return t_resources(_str=''.join(set(string)))

    return impl
1219675
def get_package_id_by_type(self, package_type):
        

        mask = "mask[id, name, description, isActive, type[keyName]]"
        package = self.get_package_by_type(package_type, mask)
        if package:
            return package['id']
        else:
            raise ValueError("No package found for type: " + package_type)
400281
def resource_types(self):
        """"""
        rtypes = set()
        for p in self.policies:
            rtypes.add(p.resource_type)
        return rtypes
808472
def get_schema_from_type(resource_type):
    
    for cls_name, cls in class_registry._registry.items():
        try:
            if cls[0].opts.type_ == resource_type:
                return cls[0]
        except Exception:
            pass

    raise Exception("Couldn't find schema for type: {}".format(resource_type))
124741
def get_for_content_type(self, ct):
        """"""
        try:
            return json.loads(self.state)[ct.app_label][ct.model]
        except KeyError:
            return None
208008
def get_type(obj, **kwargs):
    """"""
    t = type(obj)

    s = extract_type(str(t))

    return 'Type: {}'.format(s)
500940
def choose_type(cls, content_type):
        """"""
        return cls.type_cls.SUBDIR if content_type in cls.subdir_types \
            else cls.type_cls.FILE