Import data from string
349512
def import_from_string(self, text, title=None):
        """"""
        data = self.model.get_data()
        # Check if data is a dict
        if not hasattr(data, "keys"):
            return
        editor = ImportWizard(self, text, title=title,
                              contents_title=_("Clipboard contents"),
                              varname=fix_reference_name("data",
                                                         blacklist=list(data.keys())))
        if editor.exec_():
            var_name, clip_data = editor.get_data()
            self.new_value(var_name, clip_data)
341200
def load(data):
    

    if hasattr(data, 'read') and callable(data.read):
      contents = data.read()
    elif isinstance(data, six.string_types):
      contents = data
    else:
      raise TypeError('Can only process data from a string or a readable object, given: %s' % data)

    return Properties._parse(contents.splitlines())
729974
def from_string(string, section='matrix'):
    
    config = parse_config(StringIO(string), section=section)
    return from_config(config)
1234702
def from_string(cls, s, space):
        """"""

        import hashlib

        hs = hashlib.sha1(s).hexdigest()

        return cls.from_hex(hs, space)
262997
def import_obj_from_str(s):
    
    ast_obj = ast.parse(s).body[0]
    return ast_type_to_import_type[type(ast_obj)](ast_obj)
854155
def _dataToString(self, data):
        
        if self.specialValueText is not None and data == self.minValue:
            return self.specialValueText
        else:
            return "{}{:.{}f}{}".format(self.prefix, data, self.decimals, self.suffix)
1317898
def from_string(cls, s):
        """"""
        tables = []
        seen = set()
        current_table = None
        lines = list(reversed(s.splitlines()))  # to pop() in right order
        while lines:
            line = lines.pop().strip()
            table_m = re.match(r'^(?P<table>\w.+):$', line)
            field_m = re.match(r'\s*(?P<name>\S+)'
                               r'(\s+(?P<attrs>[^#]+))?'
                               r'(\s*#\s*(?P<comment>.*)$)?',
                               line)
            if table_m is not None:
                table_name = table_m.group('table')
                if table_name in seen:
                    raise ItsdbError(
                        'Table {} already defined.'.format(table_name)
                    )
                current_table = (table_name, [])
                tables.append(current_table)
                seen.add(table_name)
            elif field_m is not None and current_table is not None:
                name = field_m.group('name')
                attrs = field_m.group('attrs').split()
                datatype = attrs.pop(0)
                key = ':key' in attrs
                partial = ':partial' in attrs
                comment = field_m.group('comment')
                current_table[1].append(
                    Field(name, datatype, key, partial, comment)
                )
            elif line != '':
                raise ItsdbError('Invalid line: ' + line)
        return cls(tables)
326664
function fixdata(data) {
		var o = '',
			l = 0,
			w = 10240;
		for (; l < data.byteLength / w; ++l)
			o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w, l * w + w)));
		o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w)));
		return o;
	}
325193
def import_object_by_string(namespace):
    """"""
    segments = namespace.split('.')
    module = importlib.import_module('.'.join(segments[:-1]))
    return getattr(module, segments[-1])
1027881
function filterData(str, data) {
  data = data || [];
  var ctx = String(str || '').trim();
  var slashParts = ctx.split('/');
  ctx = slashParts.pop();
  var wordParts = String(ctx).trim().split(' ');
  var res = data.filter(function (item) {
    return (strip(item).slice(0, ctx.length) === ctx);
  });
  res = res.map(function (item) {
    var parts = String(item).trim().split(' ');
    if (parts.length > 1) {
      parts = parts.slice(wordParts.length);
      return parts.join(' ');
    }
    return item;
  });
  return res;
}
1261991
def from_string(cls, s):
        
        # Extract num and unit string.
        s = s.strip()
        for i, char in enumerate(s):
            if char.isalpha() or char.isspace():
                break
        else:
            raise Exception("Unit is missing in string %s" % s)
        num, unit = float(s[:i]), s[i:]

        # Find unit type (set it to None if it cannot be detected)
        for unit_type, d in BASE_UNITS.items():
            if unit in d:
                break
        else:
            unit_type = None

        return cls(num, unit, unit_type=unit_type)
1264211
def load_json_from_string(string):
    """"""
    try:
        json_data = json.loads(string)
    except ValueError as e:
        raise ValueError('Given string is not valid JSON: {}'.format(e))
    else:
        return json_data
883425
def get_plist_data_from_string (data):
    """"""
    if has_biplist:
        return biplist.readPlistFromString(data)
    # fall back to normal plistlist
    try:
        return plistlib.readPlistFromString(data)
    except Exception:
        # not parseable (eg. not well-formed, or binary)
        return {}
994066
def parse(self, string, strict=True):
        '''
        '''
        if isinstance(string, bytes):
            errors = 'strict' if strict else 'replace'
            string = string.decode(self.encoding, errors=errors)

        if not self.raw:
            self.raw = string
        else:
            self.raw += string

        lines = unfold_lines(string).splitlines()
        for line in lines:
            if line:
                if ':' not in line:
                    if strict:
                        raise ValueError('Field missing colon.')
                    else:
                        continue

                name, value = line.split(':', 1)
                name = name.strip()
                value = value.strip()
                self.add(name, value)
108365
def fromString(cls, string):
        
        return cls(level=[int(i) for i in string.split("/") if i])
588277
def from_string(cls, string):
        
        lines = string.split("\n")
        timestep = int(lines[1])
        natoms = int(lines[3])
        box_arr = np.loadtxt(StringIO("\n".join(lines[5:8])))
        bounds = box_arr[:, :2]
        tilt = None
        if "xy xz yz" in lines[4]:
            tilt = box_arr[:, 2]
            x = (0, tilt[0], tilt[1], tilt[0] + tilt[1])
            y = (0, tilt[2])
            bounds -= np.array([[min(x), max(x)], [min(y), max(y)], [0, 0]])
        box = LammpsBox(bounds, tilt)
        data_head = lines[8].replace("ITEM: ATOMS", "").split()
        data = pd.read_csv(StringIO("\n".join(lines[9:])), names=data_head,
                           delim_whitespace=True)
        return cls(timestep, natoms, box, data)
1248890
def from_string(cls, rawstr):
        
        try:
            args = map(float, rawstr.split())
        except Exception as ex:
            import sys
            logger.error("Failed to convert aperture correction: {}".format(ex))
            raise ex
        return cls(*args)