Get a string version of the given attribute's value, like repr() might.
963145
def get_attribute_value(item, field, context, force=False, skip_autofield=True):
    
    # Find the value of the field, catching any database issues
    try:
        value = getattr(item, field.name)
    except ObjectDoesNotExist:
        raise SkipValue('Could not find object for %s.%s, ignoring.\n' % (item.__class__.__name__, field.name))

    # AutoField: We don't include the auto fields, they'll be automatically recreated
    if skip_autofield and isinstance(field, AutoField):
        raise SkipValue()

    # Some databases (eg MySQL) might store boolean values as 0/1, this needs to be cast as a bool
    elif isinstance(field, BooleanField) and value is not None:
        return repr(bool(value))

    # Post file-storage-refactor, repr() on File/ImageFields no longer returns the path
    elif isinstance(field, FileField):
        return repr(force_text(value))

    # ForeignKey fields, link directly using our stored python variable name
    elif isinstance(field, ForeignKey) and value is not None:

        # Special case for contenttype foreign keys: no need to output any
        # content types in this script, as they can be generated again
        # automatically.
        # NB: Not sure if "is" will always work
        if field.remote_field.model is ContentType:
            return 'ContentType.objects.get(app_label="%s", model="%s")' % (value.app_label, value.model)

        # Generate an identifier (key) for this foreign object
        pk_name = value._meta.pk.name
        key = '%s_%s' % (value.__class__.__name__, getattr(value, pk_name))

        if key in context:
            variable_name = context[key]
            # If the context value is set to None, this should be skipped.
            # This identifies models that have been skipped (inheritance)
            if variable_name is None:
                raise SkipValue()
            # Return the variable name listed in the context
            return "%s" % variable_name
        elif value.__class__ not in context["__avaliable_models"] or force:
            context["__extra_imports"][value._meta.object_name] = value.__module__
            item_locator = orm_item_locator(value)
            return item_locator
        else:
            raise DoLater('(FK) %s.%s\n' % (item.__class__.__name__, field.name))

    elif isinstance(field, (DateField, DateTimeField)) and value is not None:
        return "dateutil.parser.parse(\"%s\")" % value.isoformat()

    # A normal field (e.g. a python built-in)
    else:
        return repr(value)
922796
def _short_repr(obj):
  """"""
  stringified = pprint.saferepr(obj)
  if len(stringified) > 200:
    return '%s... (%d bytes)' % (stringified[:200], len(stringified))
  return stringified
25554
def getstr_data(self, name, vals):
        """"""
        fld2val = self.get_fld2val(name, vals)
        return self.fmt.format(**fld2val)
754618
def igetattr(self, name, context=None):
        """"""
        try:
            return bases._infer_stmts(self.getattr(name, context), context, frame=self)
        except exceptions.AttributeInferenceError as error:
            raise exceptions.InferenceError(
                error.message, target=self, attribute=name, context=context
            ) from error
348577
def _str_to_version(version_str, allow_wildcard=False):
  """"""
  reg = _VERSION_WILDCARD_REG if allow_wildcard else _VERSION_RESOLVED_REG
  res = reg.match(version_str)
  if not res:
    msg = "Invalid version '{}'. Format should be x.y.z".format(version_str)
    if allow_wildcard:
      msg += " with {x,y,z} being digits or wildcard."
    else:
      msg += " with {x,y,z} being digits."
    raise ValueError(msg)
  return tuple(
      v if v == "*" else int(v)
      for v in [res.group("major"), res.group("minor"), res.group("patch")])
1354403
public Integer get(String name) throws IOException {
        if (name.equalsIgnoreCase(VERSION)) {
            return(new Integer(getVersion()));
        } else {
            throw new IOException("Attribute name not recognized by " +
                                  "CertAttrSet: CertificateVersion.");
        }
    }
1020913
def handle_attribute_value(self, value):
        """"""
        if self.re_js.match(value) or self.re_vb.match(value):
            return ''
        return value
650855
public String readString(String attribute)
    {
        final String value = getValue(attribute);
        if (NULL.equals(value))
        {
            return null;
        }
        return value;
    }
168170
def make_attrgetter(environment, attribute, postprocess=None):
    
    if attribute is None:
        attribute = []
    elif isinstance(attribute, string_types):
        attribute = [int(x) if x.isdigit() else x for x in attribute.split('.')]
    else:
        attribute = [attribute]

    def attrgetter(item):
        for part in attribute:
            item = environment.getitem(item, part)

        if postprocess is not None:
            item = postprocess(item)

        return item

    return attrgetter
323155
def dmp(self, thing):
        """"""

        def safe_getattr(key):
            """Avoid crash on getattr"""
            try:
                return getattr(thing, key)
            except Exception as e:
                return 'Error getting attr "%s" from "%s" (%s: %s)' % (
                    key, thing, type(e).__name__, e
                )

        return dict((
            escape(key), {
                'val': self.safe_better_repr(safe_getattr(key)),
                'type': type(safe_getattr(key)).__name__
            }
        ) for key in dir(thing))
800723
private String getString(DerValue attribute) throws IOException {
        if (attribute == null)
            return null;
        String  value = attribute.getAsString();

        if (value == null)
            throw new IOException("not a DER string encoding, "
                    + attribute.tag);
        else
            return value;
    }
140956
def _serialize(self, value, attr, obj, **kwargs):
        """"""
        ret = self._validated(value)
        return (
            self._to_string(ret)
            if (self.as_string and ret not in (None, missing_))
            else ret
        )
1085801
def query_string_attribute(self, target, display_mask, attr):
    """"""
    reply = NVCtrlQueryStringAttributeReplyRequest(display=self.display,
                                                   opcode=self.display.get_extension_major(extname),
                                                   target_id=target.id(),
                                                   target_type=target.type(),
                                                   display_mask=display_mask,
                                                   attr=attr)
    if not reply._data.get('flags'):
        return None
    return str(reply._data.get('string')).strip('\0')
1094850
def rgetattr(obj, attr, *args):
  """"""
  def _getattr(obj, attr):
    return getattr(obj, attr, *args)
  return functools.reduce(_getattr, [obj] + attr.split("."))
98611
def _extract(self, attribute) -> str:
        """"""
        attr_data = self.journey.JourneyAttributeList.JourneyAttribute[
            self.attr_types.index(attribute)
        ].Attribute
        attr_variants = attr_data.xpath("AttributeVariant/@type")
        data = attr_data.AttributeVariant[attr_variants.index("NORMAL")].Text.pyval
        return str(data)
638432
public Object getattr(String attr) throws PickleException, PyroException, IOException {
		return this.internal_call("__getattr__", null, 0, false, attr);
	}
253199
def get_attribute(self, name):
        
        assert isinstance(name, basestring)
        value = None
        if self.__attributes and name in self.__attributes.keys():
            value = self.__attributes[name]
        return value