assume str is formatted correctly as a shard string
485321
private static Shard createShardFromString(String str) {
    int first = str.indexOf("@");
    int second = str.indexOf("@", first + 1);
    long version = Long.parseLong(str.substring(0, first));
    String dir = str.substring(first + 1, second);
    long gen = Long.parseLong(str.substring(second + 1));
    return new Shard(version, dir, gen);
  }
1212353
def prepare_string_for_hashing(obj, ignore_string_type_changes=False, ignore_string_case=False):
    
    original_type = obj.__class__.__name__
    if isinstance(obj, bytes):
        obj = obj.decode('utf-8')
    if not ignore_string_type_changes:
        obj = KEY_TO_VAL_STR.format(original_type, obj)
    if ignore_string_case:
        obj = obj.lower()
    return obj
328521
def ensure_str(s, encoding='utf-8', errors='strict'):
    
    if not isinstance(s, (text_type, binary_type)):
        raise TypeError("not expecting type '%s'" % type(s))
    if PY2 and isinstance(s, text_type):
        s = s.encode(encoding, errors)
    elif PY3 and isinstance(s, binary_type):
        s = s.decode(encoding, errors)
    return s
9089
def smart_str(s, encoding='utf-8', errors='strict'):
    
    if not isinstance(s, basestring):
        try:
            return str(s)
        except UnicodeEncodeError:
            if isinstance(s, Exception):
                # An Exception subclass containing non-ASCII data that doesn't
                # know how to print itself properly. We shouldn't raise a
                # further exception.
                return ' '.join([smart_str(arg, encoding, errors) for arg in s])
            return unicode(s).encode(encoding, errors)
    elif isinstance(s, unicode):
        return s.encode(encoding, errors)
    elif s and encoding != 'utf-8':
        return s.decode('utf-8', errors).encode(encoding, errors)
    else:
        return s
310273
def eval_string(stri):
    ''
    tokens = shlex.split(stri)

    return run_write_read(['plash', 'eval'], '\n'.join(tokens).encode()).decode()
1032934
def cast_str(s, encoding='utf8', errors='strict'):
    """"""
    if isinstance(s, bytes):
        return s.decode(encoding, errors)
    elif isinstance(s, str):
        return s
    else:
        raise TypeError("Expected unicode or bytes, got %r" % s)
822089
def to_s
      str = ''
      if @scheme
        str << @scheme
        str << ':'
      end

      if @opaque
        str << @opaque

      else
        if @registry
          str << @registry
        else
          if @host
            str << '//'
          end
          if self.userinfo
            str << self.userinfo
            str << '@'
          end
          if @host
            str << @host
          end
          if @port && @port != self.default_port
            str << ':'
            str << @port.to_s
          end
        end

        str << path_query
      end

      if @fragment
        str << '#'
        str << @fragment
      end

      str
    end
412245
def _str(val):
    
    if str == bytes:
        if isinstance(val, str):
            return val
        else:
            return str(val)
    else:
        if isinstance(val, str):
            return val
        else:
            return str(val, 'ascii')
580168
def str(self,local=False,ifempty=None):
        
        ts = self.get(local)
        if not ts: return ifempty
        return ts.strftime('%Y-%m-%d %H:%M:%S')
537887
def _raw(s):
    """"""

    if isinstance(s, list):
        s = "\n".join(_raw(item) for item in s)

    if s == EOF:
        return "EOF"

    s = repr(s)  # Get raw representation of string
    s = s[1:-1]  # Strip away quotation marks
    if len(s) > 15:
        s = s[:15] + "..."  # Truncate if too long
    return s
171777
public static function determineShard($string, int $shards = 256): int
    {
        // first 4 chars of md5 give us a 16 bit keyspace (0-65535)
        $num = hexdec(substr(md5((string)$string), 0, 4));
        return $num % $shards;
    }
788174
def formatted_str(self, format):
        
        assert(format in ('json', 'csv'))
        ret_str_list = []
        for rec in self._records:
            if format == 'json':
                ret_str_list.append('{')
                for i in xrange(len(rec)):
                    colname, colval = self._rdef[i].name, rec[i]
                    ret_str_list.append('"%s":"%s"' % (colname, str(colval).replace('"', r'\"')))
                    ret_str_list.append(',')
                ret_str_list.pop()  # drop last comma
                ret_str_list.append('}%s' % (os.linesep))
            elif format == 'csv':
                for i in xrange(len(rec)):
                    colval = rec[i]
                    ret_str_list.append('"%s"' % (str(colval).replace('"', r'\"')))
                    ret_str_list.append(',')
                ret_str_list.pop()  # drop last comma
                ret_str_list.append('%s' % (os.linesep))
            else:
                assert(False)
        return ''.join(ret_str_list)
1032991
def as_format(item, format_str='.2f'):
    
    if isinstance(item, pd.Series):
        return item.map(lambda x: format(x, format_str))
    elif isinstance(item, pd.DataFrame):
        return item.applymap(lambda x: format(x, format_str))
171330
def str_(name):
  """"""
  if isinstance(name, bytes) and not isinstance(name, str):
    return name.decode('utf8')
  else:
    return name
1108928
def to_str(s):
    
    if bytes != str:
        """
        这里的比较在python2中是True，在Python3中是False
        """
        if type(s) == bytes:
            return s.decode('utf-8')
    return s
1314250
def sharded_filenames(filename_prefix, num_shards):
  """"""
  shard_suffix = "%05d-of-%05d"
  return [
      "%s-%s" % (filename_prefix, shard_suffix % (i, num_shards))
      for i in range(num_shards)
  ]
710843
def _format_str(string):
    """"""
    if isinstance(string, _STRTYPES):
        if _IS_PYTHON3:
            array = _array.array('I')
            array.frombytes(string.encode(_utf32_codec))
        else: # Python 2
            if isinstance(string, unicode):
                array = _array.array(b'I')
                array.fromstring(string.encode(_utf32_codec))
            else:
                array = _array.array(b'B')
                array.fromstring(string)
        return array
    return string