Get an example from a property specification.

        In case there is no "type" key in the root of the dictionary.

        Args:
            prop_spec: property specification you want an example of.

        Returns:
            An example.
179740
def _example_from_complex_def(self, prop_spec):
        
        if 'schema' not in prop_spec:
            return [{}]
        elif 'type' not in prop_spec['schema']:
            definition_name = self.get_definition_name_from_ref(prop_spec['schema']['$ref'])
            if self.build_one_definition_example(definition_name):
                return self.definitions_example[definition_name]
        elif prop_spec['schema']['type'] == 'array':  # Array with definition
            # Get value from definition
            if 'items' in prop_spec.keys():
                definition_name = self.get_definition_name_from_ref(prop_spec['items']['$ref'])
            else:
                if '$ref' in prop_spec['schema']['items']:
                    definition_name = self.get_definition_name_from_ref(prop_spec['schema']['items']['$ref'])
                else:
                    definition_name = self.get_definition_name_from_ref(prop_spec['schema']['items']['type'])
                    return [definition_name]
            return [self.definitions_example[definition_name]]
        else:
            return self.get_example_from_prop_spec(prop_spec['schema'])
1347658
def __definitions_descriptor(self):
    
    # Filter out any keys that aren't 'properties' or 'type'
    result = {}
    for def_key, def_value in self.__parser.schemas().iteritems():
      if 'properties' in def_value or 'type' in def_value:
        key_result = {}
        required_keys = set()
        if 'type' in def_value:
          key_result['type'] = def_value['type']
        if 'properties' in def_value:
          for prop_key, prop_value in def_value['properties'].items():
            if isinstance(prop_value, dict) and 'required' in prop_value:
              required_keys.add(prop_key)
              del prop_value['required']
          key_result['properties'] = def_value['properties']
        # Add in the required fields, if any
        if required_keys:
          key_result['required'] = sorted(required_keys)
        result[def_key] = key_result

    # Add 'type': 'object' to all object properties
    # Also, recursively add relative path to all $ref values
    for def_value in result.itervalues():
      for prop_value in def_value.itervalues():
        if isinstance(prop_value, dict):
          if '$ref' in prop_value:
            prop_value['type'] = 'object'
          self._add_def_paths(prop_value)

    return result
98573
def generate_env(self):
        
        for key in sorted(list(self.spec.keys())):
            if self.spec[key]['type'] in (dict, list):
                value = f"\'{json.dumps(self.spec[key].get('example', ''))}\'"
            else:
                value = f"{self.spec[key].get('example', '')}"
            print(f"export {self.env_prefix}_{key.upper()}={value}")
339511
def get_property(self, key):
        """"""
        _key = DJANGO_CONF[key]
        return getattr(self, _key, CONF_SPEC[_key])
1343655
private TypeContainer getProperty(String propName) {
        TypeContainer container = cache.get(propName);
        if (container == null) {
            container = new TypeContainer(propName, config, version);
            TypeContainer existing = cache.putIfAbsent(propName, container);
            if (existing != null) {
                return existing;
            }
        }

        return container;
    }
1145669
def parse_property_reference(self, tup_tree):
        

        self.check_node(tup_tree, 'PROPERTY.REFERENCE', ('NAME',),
                        ('REFERENCECLASS', 'CLASSORIGIN', 'PROPAGATED'),
                        ('QUALIFIER', 'VALUE.REFERENCE'))

        value = self.list_of_matching(tup_tree, ('VALUE.REFERENCE',))

        if not value:
            value = None
        elif len(value) == 1:
            value = value[0]
        else:
            raise CIMXMLParseError(
                _format("Element {0!A} has more than one child element "
                        "'VALUE.REFERENCE' (allowed are zero or one)",
                        name(tup_tree)),
                conn_id=self.conn_id)

        attrl = attrs(tup_tree)

        qualifiers = self.list_of_matching(tup_tree, ('QUALIFIER',))

        pref = CIMProperty(attrl['NAME'],
                           value,
                           type='reference',
                           is_array=False,
                           qualifiers=qualifiers,
                           reference_class=attrl.get('REFERENCECLASS', None),
                           class_origin=attrl.get('CLASSORIGIN', None),
                           propagated=self.unpack_boolean(
                               attrl.get('PROPAGATED', 'false')),
                           embedded_object=False)

        return pref
1030836
def get_default_properties(self, comp_type):
        
        # Flatten out all the default assignments that apply to the current scope
        # This does not include any default assignments made within the current
        # scope, so exclude those.
        props = {}
        for scope in self.default_property_ns_stack[:-1]:
            props.update(scope)

        # filter out properties that are not relevant
        prop_names = list(props.keys())
        for prop_name in prop_names:
            rule = self.env.property_rules.lookup_property(prop_name)
            if rule is None:
                self.msg.fatal(
                    "Unrecognized property '%s'" % prop_name,
                    props[prop_name][0]
                )
            if comp_type not in rule.bindable_to:
                del props[prop_name]

        return props
978240
def get_matching_property_names(self, regex):
        
        log = logging.getLogger(self.cls_logger + '.get_matching_property_names')
        prop_list_matched = []
        if not isinstance(regex, basestring):
            log.warn('regex arg is not a string, found type: {t}'.format(t=regex.__class__.__name__))
            return prop_list_matched
        log.debug('Finding properties matching regex: {r}'.format(r=regex))
        for prop_name in self.properties.keys():
            match = re.search(regex, prop_name)
            if match:
                prop_list_matched.append(prop_name)
        return prop_list_matched
617339
def get(self, prop):
        
        prop_parts = prop.split(".")
        val = None
        for part in prop_parts:
            if val is None:
                val = self.obj.get(part)
            else:
                val = val.get(part)
        return val
85232
def get_prop_value(name, props, default=None):
    # type: (str, Dict[str, Any], Any) -> Any
    
    if not props:
        return default

    try:
        return props[name]
    except KeyError:
        return default
1348323
def _get_property_for(self, p, indexed=True, depth=0):
    """"""
    parts = p.name().split('.')
    if len(parts) <= depth:
      # Apparently there's an unstructured value here.
      # Assume it is a None written for a missing value.
      # (It could also be that a schema change turned an unstructured
      # value into a structured one.  In that case, too, it seems
      # better to return None than to return an unstructured value,
      # since the latter doesn't match the current schema.)
      return None
    next = parts[depth]
    prop = self._properties.get(next)
    if prop is None:
      prop = self._fake_property(p, next, indexed)
    return prop
431658
def fetch(self, spec=None, *args, **kwargs):
        
        if spec is None:
            spec = {}
        for key in self.structure:
            if key in spec:
                if isinstance(spec[key], dict):
                    spec[key].update({'$exists': True})
            else:
                spec[key] = {'$exists': True}
        return self.find(spec, *args, **kwargs)
1055664
def get_properties(cls_def):
    
    # pdb.set_trace()
    prop_list = {prop: value for prop, value in cls_def.items() \
                 if 'rdf_Property' in value.get('rdf_type', "") or \
                 value.get('rdfs_domain')}

    return prop_list
588426
def _get_prop_infos(self, prop):
        
        info_dict = self.get_info_field(prop)
        main_infos = info_dict.get('export', {}).copy()
        infos = main_infos.get(self.config_key, {})
        main_infos['label'] = self._get_title(prop, main_infos, info_dict)
        main_infos['name'] = prop.key
        main_infos['key'] = prop.key
        main_infos.update(infos)
        main_infos['__col__'] = prop
        return main_infos
839891
def getProperty(self, prop, *args, **kwargs):
        
        f = self.__getAttrs.get(prop)
        if not f:
            raise KeyError('Unknown readable property: %s' % prop)
        return f(self, *args, **kwargs)
860310
def custom_property_prefix_strict(instance):
    
    for prop_name in instance.keys():
        if (instance['type'] in enums.PROPERTIES and
                prop_name not in enums.PROPERTIES[instance['type']] and
                prop_name not in enums.RESERVED_PROPERTIES and
                not CUSTOM_PROPERTY_PREFIX_RE.match(prop_name)):

            yield JSONError("Custom property '%s' should have a type that "
                            "starts with 'x_' followed by a source unique "
                            "identifier (like a domain name with dots "
                            "replaced by hyphen), a hyphen and then the name."
                            % prop_name, instance['id'],
                            'custom-prefix')
885337
def custom_property_prefix_lax(instance):
    
    for prop_name in instance.keys():
        if (instance['type'] in enums.PROPERTIES and
                prop_name not in enums.PROPERTIES[instance['type']] and
                prop_name not in enums.RESERVED_PROPERTIES and
                not CUSTOM_PROPERTY_LAX_PREFIX_RE.match(prop_name)):

            yield JSONError("Custom property '%s' should have a type that "
                            "starts with 'x_' in order to be compatible with "
                            "future versions of the STIX 2 specification." %
                            prop_name, instance['id'],
                            'custom-prefix-lax')