Get string representation of memory type
193396
def type_to_string(t):
        """"""
        if t == MemoryElement.TYPE_I2C:
            return 'I2C'
        if t == MemoryElement.TYPE_1W:
            return '1-wire'
        if t == MemoryElement.TYPE_DRIVER_LED:
            return 'LED driver'
        if t == MemoryElement.TYPE_LOCO:
            return 'Loco Positioning'
        if t == MemoryElement.TYPE_TRAJ:
            return 'Trajectory'
        if t == MemoryElement.TYPE_LOCO2:
            return 'Loco Positioning 2'
        return 'Unknown'
164423
def c_str(string):
    """""""
    if not isinstance(string, str):
        string = string.decode('ascii')
    return ctypes.c_char_p(string.encode('utf-8'))
840941
def to_string(self):
        """"""
        suffix = '%s %s' % (self.type, self.name)
        if self.initial_value:
            suffix += ' = ' + self.initial_value
        return suffix
1142095
def parse_memory_value(s):
    
    number, unit = split_number_and_unit(s)
    if not unit or unit == 'B':
        return number
    elif unit == 'kB':
        return number * _BYTE_FACTOR
    elif unit == 'MB':
        return number * _BYTE_FACTOR * _BYTE_FACTOR
    elif unit == 'GB':
        return number * _BYTE_FACTOR * _BYTE_FACTOR * _BYTE_FACTOR
    elif unit == 'TB':
        return number * _BYTE_FACTOR * _BYTE_FACTOR * _BYTE_FACTOR * _BYTE_FACTOR
    else:
        raise ValueError('unknown unit: {} (allowed are B, kB, MB, GB, and TB)'.format(unit))
26258
def formatted_param_type(ptype):
    """"""
    pt_name = ptype["name"]
    if pt_name.startswith("<byname>"):
        pt_name = pt_name.replace("<byname>[", "=> ")[:-1]
    elif pt_name.startswith("<repeated>"):
        pt_name = pt_name.replace("<repeated>[", "")[:-1] + "*"
    return pt_name
325487
function getStringType(str) {
  if (null == str) {
    return -1;
  }

  if (typeof(str) != 'string') {
    return -1;
  }

  if (str.length == 0 || str == "") {
    return -1;
  }

  var i = 0;
  if (str.length == 40) {
    for (; i < 40; i++) {
      var c = str.charAt(i);
      if (!isHexChar(c)) {
        break;
      }
    }
  }
  if (i == 40) {
    return 1;  //40 Hex, Address
  }

  for (i = 0; i < str.length; i++) {
    var c = str.charAt(i);
    if (!isNumber(c)) {
      break;
    }
  }
  if (i == str.length) {
    return 2;  //Alll Decimal number, BlockNumber
  }

  for (i = 0; i < str.length; i++) {
    var c = str.charAt(i);
    if (c > ' ') {
      return 3;   //At least one visible character
    }
  }

  return -1;
}
1283744
def memory_usage(self, string=False):
        
        if string:
            n = getsizeof(self)
            return ' '.join((str(s) for s in convert_bytes(n)))
        return self.info()['size']
973017
def cachedstr(self):
        """"""
        if self._cachedstr is None:
            if self.module is not None:
                refstring = self.module.refstring
                self._cachedstr = refstring.splitlines()
            else:
                self._cachedstr = []

        return self._cachedstr
1005952
def pretty_memory_info():
    '''
    
    '''
    process = psutil.Process(os.getpid())
    return '{}MB memory usage'.format(int(process.memory_info().rss / 2**20))
155822
def _determine_datatype(fields):
    """"""

    # Convert the NRRD type string identifier into a NumPy string identifier using a map
    np_typestring = _TYPEMAP_NRRD2NUMPY[fields['type']]

    # This is only added if the datatype has more than one byte and is not using ASCII encoding
    # Note: Endian is not required for ASCII encoding
    if np.dtype(np_typestring).itemsize > 1 and fields['encoding'] not in ['ASCII', 'ascii', 'text', 'txt']:
        if 'endian' not in fields:
            raise NRRDError('Header is missing required field: "endian".')
        elif fields['endian'] == 'big':
            np_typestring = '>' + np_typestring
        elif fields['endian'] == 'little':
            np_typestring = '<' + np_typestring
        else:
            raise NRRDError('Invalid endian value in header: "%s"' % fields['endian'])

    return np.dtype(np_typestring)
228358
def _get_seqtype_from_ext(handle):
    ''''''
    if isinstance(handle, basestring):
        name = handle
    elif hasattr(handle, 'filename'):
        name = handle.filename
    elif hasattr(handle, 'name'):
        name = handle.name
    else:
        raise ValueError("Unknown datatype for handle!")

    modifier = ''
    dummy, ext = path.splitext(name.lower())
    if ext == ".gz":
        modifier = 'gz-'
        dummy, ext = path.splitext(dummy)

    if not ext:
        ext = "." + dummy

    if ext in (".gbk", ".gb", ".genbank", ".gbff"):
        return modifier + "genbank"
    elif ext in (".embl", ".emb"):
        return modifier + "embl"
    elif ext in (".fa", ".fasta", ".fna", ".faa", ".fas"):
        return modifier + "fasta"
    else:
        raise ValueError("Unknown file format '%s'." % ext)
760049
def get_memory_map_xml(self):
        
        root = ElementTree.Element('memory-map')
        for r in  self._context.core.memory_map:
            # Look up the region type name. Regions default to ram if gdb doesn't
            # have a concept of the region type.
            gdbType = GDB_TYPE_MAP.get(r.type, 'ram')
            
            start = hex(r.start).rstrip("L")
            length = hex(r.length).rstrip("L")
            mem = ElementTree.SubElement(root, 'memory', type=gdbType, start=start, length=length)
            if r.is_flash:
                prop = ElementTree.SubElement(mem, 'property', name='blocksize')
                prop.text = hex(r.blocksize).rstrip("L")
        return MAP_XML_HEADER + ElementTree.tostring(root)
803959
def _paramstr(ins):
    
    (tmp, output) = _str_oper(ins.quad[1])
    output.pop()  # Remove a register flag (useless here)
    tmp = ins.quad[1][0] in ('#', '_')  # Determine if the string must be duplicated

    if tmp:
        output.append('call __LOADSTR')  # Must be duplicated
        REQUIRES.add('loadstr.asm')

    output.append('push hl')
    return output
1193387
def get_bytes(s):
    """"""
    if isinstance(s, bytes):
        b = s
    elif isinstance(s, str):
        b = bytes.fromhex(s)
    else:
        raise TypeError("s must be either 'bytes' or 'str'!")

    return b
1125335
def cachestr_repr(val):
    
    try:
        memview = memoryview(val)
        return memview.tobytes()
    except Exception:
        try:
            return to_json(val)
        except Exception:
            # SUPER HACK
            if repr(val.__class__) == "<class 'ibeis.control.IBEISControl.IBEISController'>":
                return val.get_dbname()
403948
def any2mb(s):
    """"""
    if is_string(s):
        return int(Memory.from_string(s).to("Mb"))
    else:
        return int(s)
980361
def get_type_name(type_):
    

    if type_ is None:
        return ""
    if isinstance(type_, string_types):
        return type_
    elif isinstance(type_, list):
        assert len(type_) == 1
        return "[%s]" % get_type_name(type_[0])
    elif isinstance(type_, dict):
        assert len(type_) == 1
        key, value = list(type_.items())[0]
        return "{%s: %s}" % (get_type_name(key), get_type_name(value))
    elif type_.__module__ in ("__builtin__", "builtins"):
        return type_.__name__
    else:
        return "%s.%s" % (type_.__module__, type_.__name__)