Parses portable object (PO) format using polib

        @type resource: str
        @param resource: resource

        @rtype: list
766277
def _load_contents(self, polib, resource):
        
        try:
            return polib.pofile(resource)
        except (ValueError, AttributeError) as e:
            self.rethrow(
                "Invalid resource {0}".format(resource),
                InvalidResourceException)
24004
def parse_obj(o):
    
    r = {}
    for k, v in o.items():
        if is_unable_to_connect(v):
            r[k] = None

        try:
            r[k] = parse_value(k, v)
        except (ObdPidParserUnknownError, AttributeError, TypeError):
            r[k] = None
    return r
1085864
def resource(ref: str, delimiter: str = None) -> str:
    

    return ref.split(delimiter if delimiter else '#')[0]
1075421
def corelinkformat(resource):
        
        msg = "<" + resource.path + ">;"
        assert(isinstance(resource, Resource))
        keys = sorted(list(resource.attributes.keys()))
        for k in keys:
            method = getattr(resource, defines.corelinkformat[k], None)
            if method is not None and method != "":
                v = method
                msg = msg[:-1] + ";" + str(v) + ","
            else:
                v = resource.attributes[k]
                if v is not None:
                    msg = msg[:-1] + ";" + k + "=" + v + ","
        return msg
181429
def from_api_repr(cls, resource):
        
        name = resource.get("name")
        type_ = resource["parameterType"]["type"]
        value = resource["parameterValue"]["value"]
        converted = _QUERY_PARAMS_FROM_JSON[type_](value, None)
        return cls(name, type_, converted)
599760
def _get_sorted(self, resources):
        
        tmp = []
        for resource in resources:
            path = resource._path
            # Each slash counts as 10 priority, each variable takes one away
            priority = path.count('/') * 10 - path.count('{')
            tmp.append((priority, resource))
        return [resource for prio, resource in reversed(sorted(tmp))]
76537
def from_api_repr(cls, resource):
        
        return cls(kind=resource.get("kind"), substeps=resource.get("substeps", ()))
1014110
def parse_item(self, location: str, item_type: Type[T], item_name_for_log: str = None,
                   file_mapping_conf: FileMappingConfiguration = None, options: Dict[str, Dict[str, Any]] = None) -> T:
        

        # -- item_name_for_log
        item_name_for_log = item_name_for_log or ''
        check_var(item_name_for_log, var_types=str, var_name='item_name_for_log')

        if len(item_name_for_log) > 0:
            item_name_for_log = item_name_for_log + ' '
        self.logger.debug('**** Starting to parse single object ' + item_name_for_log + 'of type <'
                          + get_pretty_type_str(item_type) + '> at location ' + location + ' ****')

        # common steps
        return self._parse__item(item_type, location, file_mapping_conf, options=options)
1333198
def parse(self, body):
        

        self._parse_top_level(body)
        self._parse_resource(body['data'])

        resource = body['data']

        if 'attributes' in resource:
            self._parse_attributes(resource['attributes'])
        if 'relationships' in resource:
            self._parse_relationships(resource['relationships'])
135688
Document getResourceAsDoc(String resource) throws Exception {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        InputStream is = cl.getResourceAsStream(resource);
        if (is != null) {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setNamespaceAware(true);
            // Fortify Mod: prevent external entity injection
            dbf.setExpandEntityReferences(false);
            DocumentBuilder db = dbf.newDocumentBuilder();
            // Fortify Mod: prevent external entity injection 
            TransformerFactory tf = TransformerFactory.newInstance();
            tf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
            Transformer t = tf.newTransformer();
            //Transformer t = TransformerFactory.newInstance().newTransformer();
	       // End Fortify Mod
            Document doc = db.newDocument();
            t.transform(new StreamSource(is), new DOMResult(doc));
            // Fortify Mod: Close the InputStream and release its resources
            is.close();
            return doc;
        } else {
            return null;
        }
    }
433572
def select_parser(self, request, resource):
        

        # 1. get from resource
        if resource.mapper:
            return resource.mapper
        # 2. get from content type
        mapper_name = self._get_name_from_content_type(request)
        if mapper_name:
            return self._get_mapper(mapper_name)
        # 3. get from url
        mapper_name = self._get_name_from_url(request)
        if mapper_name:
            return self._get_mapper(mapper_name)
        # 4. use resource's default
        if resource.default_mapper:
            return resource.default_mapper
        # 5. use manager's default
        return self._get_default_mapper()
284567
def wrapped_resource(response):
    
    # decode response text, assuming utf-8 if unset
    response_content = response.content.decode(response.encoding or 'utf-8')

    try:
        content = json.loads(response_content)
    except ValueError:
        # not JSON
        content = response_content
    if isinstance(content, list):
        result = ResourceList(content)
    else:
        result = Resource(content)
        if hasattr(result, 'collection'):
            result.collection = ResourceList(result.collection)
    result.raw_data = response_content

    for attr in ('encoding', 'url', 'status_code', 'reason'):
        setattr(result, attr, getattr(response, attr))

    return result
190807
def resource_list(cls):
        
        items = cls.list()
        ret = [vlan['name'] for vlan in items]
        ret.extend([str(vlan['id']) for vlan in items])
        return ret
1199308
def _response_item_to_object(self, resp_item):
        
        item_cls = resources.get_model_class(self.resource_type)
        properties_dict = resp_item[self.resource_type]
        new_dict = helpers.remove_properties_containing_None(properties_dict)
        # raises exception if something goes wrong
        obj = item_cls(new_dict)
        return obj
1286070
def _parse__item(self, item_type: Type[T], item_file_prefix: str,
                     file_mapping_conf: FileMappingConfiguration = None,
                     options: Dict[str, Dict[str, Any]] = None) -> T:
        

        # for consistency : if options is None, default to the default values of create_parser_options
        options = options or create_parser_options()

        # creating the persisted object (this performs required checks)
        file_mapping_conf = file_mapping_conf or WrappedFileMappingConfiguration()
        obj = file_mapping_conf.create_persisted_object(item_file_prefix, logger=self.logger)
        # print('')
        self.logger.debug('')

        # create the parsing plan
        pp = self.create_parsing_plan(item_type, obj, logger=self.logger)
        # print('')
        self.logger.debug('')

        # parse
        res = pp.execute(logger=self.logger, options=options)
        # print('')
        self.logger.debug('')

        return res
750106
def from_api_repr(cls, resource):
        
        name = resource.get("name")
        instance = cls(name)
        type_resources = {}
        types = instance.struct_types
        for item in resource["parameterType"]["structTypes"]:
            types[item["name"]] = item["type"]["type"]
            type_resources[item["name"]] = item["type"]
        struct_values = resource["parameterValue"]["structValues"]
        for key, value in struct_values.items():
            type_ = types[key]
            converted = None
            if type_ == "STRUCT":
                struct_resource = {
                    "name": key,
                    "parameterType": type_resources[key],
                    "parameterValue": value,
                }
                converted = StructQueryParameter.from_api_repr(struct_resource)
            elif type_ == "ARRAY":
                struct_resource = {
                    "name": key,
                    "parameterType": type_resources[key],
                    "parameterValue": value,
                }
                converted = ArrayQueryParameter.from_api_repr(struct_resource)
            else:
                value = value["value"]
                converted = _QUERY_PARAMS_FROM_JSON[type_](value, None)
            instance.struct_values[key] = converted
        return instance
508310
def get_listing_api(self, resource):
        

        get_all_params = self.get_listing_parameters(resource)

        get_all_api = {
            'path': '/%s/' % resource.get_api_name(),
            'description': 'Operations on %s' % resource.model.__name__,
            'operations': [
                {
                    'httpMethod': 'GET',
                    'nickname': 'list%ss' % resource.model
                    .__name__,
                    'summary': 'Find %ss' % resource.model.__name__,
                    'parameters': get_all_params,
                }
            ]
        }

        return get_all_api