Пример #1
0
def __convert_args(args, shell, cmd_encoding):
    if isinstance(args, six.string_types):
        # input as string
        if not SHOULD_NOT_ENCODE_ARGS:
            args = to_bytes(args, cmd_encoding)
        if SHOULD_NOT_USE_BYTES:
            args = [args]
    else:
        # input as list
        if shell and sys.platform != 'win32':
            args = [to_bytes(subprocess.list2cmdline(args), cmd_encoding)]
        else:
            if not SHOULD_NOT_ENCODE_ARGS:
                args = [to_bytes(a, cmd_encoding) for a in args]
    return args
Пример #2
0
def __convert_args(args, shell, cmd_encoding):
    if isinstance(args, six.string_types):
        # input as string
        if not SHOULD_NOT_ENCODE_ARGS:
            args = to_bytes(args, cmd_encoding)
        if SHOULD_NOT_USE_BYTES:
            args = [args]
    else:
        # input as list
        if shell and sys.platform != 'win32':
            args = [to_bytes(subprocess.list2cmdline(args), cmd_encoding)]
        else:
            if not SHOULD_NOT_ENCODE_ARGS:
                args = [to_bytes(a, cmd_encoding) for a in args]
    return args
Пример #3
0
    def to_hash_string(self):
        # ignore work directory
        data = b''.join(
            to_bytes(s)
            for s in [self.cmd, sorted(self.meta.env.items())])

        return hashlib.md5(data).hexdigest()
Пример #4
0
def print_safe(str_or_bytes, encoding='utf-8', errors='ignore', output=sys.stdout, newline='\n'):
    """
    Print unicode or bytes universally.

    :param str_or_bytes: string
    :param encoding: encoding
    :param output: output file handler
    :param errors: error handling scheme. Refer to codecs.register_error.
    """
    writer = output.buffer if hasattr(output, 'buffer') else output

    # When the input type is bytes, verify it can be decoded with the specified encoding.
    decoded = str_or_bytes if is_unicode(str_or_bytes) else to_unicode(str_or_bytes, encoding, errors)
    encoded = to_bytes(decoded, encoding, errors)

    writer.write(encoded + to_bytes(newline, encoding, errors))
    output.flush()
Пример #5
0
def print_safe(str_or_bytes,
               encoding='utf-8',
               errors='ignore',
               output=sys.stdout,
               newline='\n'):
    """
    Print unicode or bytes universally.

    :param str_or_bytes: string
    :param encoding: encoding
    :param output: output file handler
    :param errors: error handling scheme. Refer to codecs.register_error.
    """
    writer = output.buffer if hasattr(output, 'buffer') else output

    # When the input type is bytes, verify it can be decoded with the specified encoding.
    decoded = str_or_bytes if is_unicode(str_or_bytes) else to_unicode(
        str_or_bytes, encoding, errors)
    encoded = to_bytes(decoded, encoding, errors)

    writer.write(encoded + to_bytes(newline, encoding, errors))
    output.flush()
Пример #6
0
 def write(self, s, encoding='utf-8', errors='strict'):
     six.BytesIO.write(self, to_bytes(s, encoding, errors))
Пример #7
0
 def writelines(self, lines, encoding='utf-8', errors='strict'):
     self._buffer += b''.join(to_bytes(s, encoding, errors) for s in lines)
Пример #8
0
 def write(self, s, encoding='utf-8', errors='strict'):
     self._buffer += to_bytes(s, encoding, errors)
Пример #9
0
    def to_hash_string(self):
        # ignore work directory
        data = b''.join(to_bytes(s) for s in [self.cmd, sorted(self.meta.env.items())])

        return hashlib.md5(data).hexdigest()
Пример #10
0
 def write(self, s, encoding='utf-8', errors='strict'):
     six.BytesIO.write(self, to_bytes(s, encoding, errors))
Пример #11
0
 def writelines(self, lines, encoding='utf-8', errors='strict'):
     self._buffer += b''.join(to_bytes(s, encoding, errors) for s in lines)
Пример #12
0
 def write(self, s, encoding='utf-8', errors='strict'):
     self._buffer += to_bytes(s, encoding, errors)
Пример #13
0
 def test_to_bytes(self):
     self.assertEqual(string.to_bytes(b'abc'), b'abc')
     self.assertEqual(string.to_bytes('あいう'), 'あいう'.encode('utf-8'))
     self.assertEqual(string.to_bytes(1.23), b'1.23')
Пример #14
0
 def test_to_bytes(self):
     self.assertEqual(string.to_bytes(b'abc'), b'abc')
     self.assertEqual(string.to_bytes('あいう'), 'あいう'.encode('utf-8'))
     self.assertEqual(string.to_bytes(1.23), b'1.23')