Python __builtin__.unicode() Examples
The following are 30
code examples of __builtin__.unicode().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
__builtin__
, or try the search function
.
Example #1
Source File: _iotools.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def __init__(self, delimiter=None, comments=b'#', autostrip=True): self.comments = comments # Delimiter is a character if isinstance(delimiter, unicode): delimiter = delimiter.encode('ascii') if (delimiter is None) or _is_bytes_like(delimiter): delimiter = delimiter or None _handyman = self._delimited_splitter # Delimiter is a list of field widths elif hasattr(delimiter, '__iter__'): _handyman = self._variablewidth_splitter idx = np.cumsum([0] + list(delimiter)) delimiter = [slice(i, j) for (i, j) in zip(idx[:-1], idx[1:])] # Delimiter is a single integer elif int(delimiter): (_handyman, delimiter) = ( self._fixedwidth_splitter, int(delimiter)) else: (_handyman, delimiter) = (self._delimited_splitter, None) self.delimiter = delimiter if autostrip: self._handyman = self.autostrip(_handyman) else: self._handyman = _handyman #
Example #2
Source File: _iotools.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def _decode_line(line, encoding=None): """Decode bytes from binary input streams. Defaults to decoding from 'latin1'. That differs from the behavior of np.compat.asunicode that decodes from 'ascii'. Parameters ---------- line : str or bytes Line to be decoded. Returns ------- decoded_line : unicode Unicode in Python 2, a str (unicode) in Python 3. """ if type(line) is bytes: if encoding is None: line = line.decode('latin1') else: line = line.decode(encoding) return line
Example #3
Source File: _iotools.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _decode_line(line, encoding=None): """Decode bytes from binary input streams. Defaults to decoding from 'latin1'. That differs from the behavior of np.compat.asunicode that decodes from 'ascii'. Parameters ---------- line : str or bytes Line to be decoded. Returns ------- decoded_line : unicode Unicode in Python 2, a str (unicode) in Python 3. """ if type(line) is bytes: if encoding is None: line = line.decode('latin1') else: line = line.decode(encoding) return line
Example #4
Source File: _iotools.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def _decode_line(line, encoding=None): """Decode bytes from binary input streams. Defaults to decoding from 'latin1'. That differs from the behavior of np.compat.asunicode that decodes from 'ascii'. Parameters ---------- line : str or bytes Line to be decoded. Returns ------- decoded_line : unicode Unicode in Python 2, a str (unicode) in Python 3. """ if type(line) is bytes: if encoding is None: line = line.decode('latin1') else: line = line.decode(encoding) return line
Example #5
Source File: _iotools.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def _decode_line(line, encoding=None): """Decode bytes from binary input streams. Defaults to decoding from 'latin1'. That differs from the behavior of np.compat.asunicode that decodes from 'ascii'. Parameters ---------- line : str or bytes Line to be decoded. Returns ------- decoded_line : unicode Unicode in Python 2, a str (unicode) in Python 3. """ if type(line) is bytes: if encoding is None: line = line.decode('latin1') else: line = line.decode(encoding) return line
Example #6
Source File: _iotools.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
def _decode_line(line, encoding=None): """Decode bytes from binary input streams. Defaults to decoding from 'latin1'. That differs from the behavior of np.compat.asunicode that decodes from 'ascii'. Parameters ---------- line : str or bytes Line to be decoded. Returns ------- decoded_line : unicode Unicode in Python 2, a str (unicode) in Python 3. """ if type(line) is bytes: if encoding is None: line = line.decode('latin1') else: line = line.decode(encoding) return line
Example #7
Source File: _iotools.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def __init__(self, delimiter=None, comments=asbytes('#'), autostrip=True): self.comments = comments # Delimiter is a character if isinstance(delimiter, unicode): delimiter = delimiter.encode('ascii') if (delimiter is None) or _is_bytes_like(delimiter): delimiter = delimiter or None _handyman = self._delimited_splitter # Delimiter is a list of field widths elif hasattr(delimiter, '__iter__'): _handyman = self._variablewidth_splitter idx = np.cumsum([0] + list(delimiter)) delimiter = [slice(i, j) for (i, j) in zip(idx[:-1], idx[1:])] # Delimiter is a single integer elif int(delimiter): (_handyman, delimiter) = ( self._fixedwidth_splitter, int(delimiter)) else: (_handyman, delimiter) = (self._delimited_splitter, None) self.delimiter = delimiter if autostrip: self._handyman = self.autostrip(_handyman) else: self._handyman = _handyman #
Example #8
Source File: _iotools.py From Computable with MIT License | 6 votes |
def __init__(self, delimiter=None, comments=asbytes('#'), autostrip=True): self.comments = comments # Delimiter is a character if isinstance(delimiter, unicode): delimiter = delimiter.encode('ascii') if (delimiter is None) or _is_bytes_like(delimiter): delimiter = delimiter or None _handyman = self._delimited_splitter # Delimiter is a list of field widths elif hasattr(delimiter, '__iter__'): _handyman = self._variablewidth_splitter idx = np.cumsum([0] + list(delimiter)) delimiter = [slice(i, j) for (i, j) in zip(idx[:-1], idx[1:])] # Delimiter is a single integer elif int(delimiter): (_handyman, delimiter) = (self._fixedwidth_splitter, int(delimiter)) else: (_handyman, delimiter) = (self._delimited_splitter, None) self.delimiter = delimiter if autostrip: self._handyman = self.autostrip(_handyman) else: self._handyman = _handyman #
Example #9
Source File: _iotools.py From pySINDy with MIT License | 6 votes |
def _decode_line(line, encoding=None): """Decode bytes from binary input streams. Defaults to decoding from 'latin1'. That differs from the behavior of np.compat.asunicode that decodes from 'ascii'. Parameters ---------- line : str or bytes Line to be decoded. Returns ------- decoded_line : unicode Unicode in Python 2, a str (unicode) in Python 3. """ if type(line) is bytes: if encoding is None: line = line.decode('latin1') else: line = line.decode(encoding) return line
Example #10
Source File: _iotools.py From coffeegrindsize with MIT License | 6 votes |
def _decode_line(line, encoding=None): """Decode bytes from binary input streams. Defaults to decoding from 'latin1'. That differs from the behavior of np.compat.asunicode that decodes from 'ascii'. Parameters ---------- line : str or bytes Line to be decoded. Returns ------- decoded_line : unicode Unicode in Python 2, a str (unicode) in Python 3. """ if type(line) is bytes: if encoding is None: line = line.decode('latin1') else: line = line.decode(encoding) return line
Example #11
Source File: _iotools.py From twitter-stock-recommendation with MIT License | 6 votes |
def _decode_line(line, encoding=None): """Decode bytes from binary input streams. Defaults to decoding from 'latin1'. That differs from the behavior of np.compat.asunicode that decodes from 'ascii'. Parameters ---------- line : str or bytes Line to be decoded. Returns ------- decoded_line : unicode Unicode in Python 2, a str (unicode) in Python 3. """ if type(line) is bytes: if encoding is None: line = line.decode('latin1') else: line = line.decode(encoding) return line
Example #12
Source File: _iotools.py From vnpy_crypto with MIT License | 6 votes |
def _decode_line(line, encoding=None): """Decode bytes from binary input streams. Defaults to decoding from 'latin1'. That differs from the behavior of np.compat.asunicode that decodes from 'ascii'. Parameters ---------- line : str or bytes Line to be decoded. Returns ------- decoded_line : unicode Unicode in Python 2, a str (unicode) in Python 3. """ if type(line) is bytes: if encoding is None: line = line.decode('latin1') else: line = line.decode(encoding) return line
Example #13
Source File: _iotools.py From recruit with Apache License 2.0 | 6 votes |
def _decode_line(line, encoding=None): """Decode bytes from binary input streams. Defaults to decoding from 'latin1'. That differs from the behavior of np.compat.asunicode that decodes from 'ascii'. Parameters ---------- line : str or bytes Line to be decoded. Returns ------- decoded_line : unicode Unicode in Python 2, a str (unicode) in Python 3. """ if type(line) is bytes: if encoding is None: line = line.decode('latin1') else: line = line.decode(encoding) return line
Example #14
Source File: _iotools.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def __init__(self, delimiter=None, comments=asbytes('#'), autostrip=True): self.comments = comments # Delimiter is a character if isinstance(delimiter, unicode): delimiter = delimiter.encode('ascii') if (delimiter is None) or _is_bytes_like(delimiter): delimiter = delimiter or None _handyman = self._delimited_splitter # Delimiter is a list of field widths elif hasattr(delimiter, '__iter__'): _handyman = self._variablewidth_splitter idx = np.cumsum([0] + list(delimiter)) delimiter = [slice(i, j) for (i, j) in zip(idx[:-1], idx[1:])] # Delimiter is a single integer elif int(delimiter): (_handyman, delimiter) = ( self._fixedwidth_splitter, int(delimiter)) else: (_handyman, delimiter) = (self._delimited_splitter, None) self.delimiter = delimiter if autostrip: self._handyman = self.autostrip(_handyman) else: self._handyman = _handyman #
Example #15
Source File: _iotools.py From lambda-packs with MIT License | 6 votes |
def __init__(self, delimiter=None, comments=asbytes('#'), autostrip=True): self.comments = comments # Delimiter is a character if isinstance(delimiter, unicode): delimiter = delimiter.encode('ascii') if (delimiter is None) or _is_bytes_like(delimiter): delimiter = delimiter or None _handyman = self._delimited_splitter # Delimiter is a list of field widths elif hasattr(delimiter, '__iter__'): _handyman = self._variablewidth_splitter idx = np.cumsum([0] + list(delimiter)) delimiter = [slice(i, j) for (i, j) in zip(idx[:-1], idx[1:])] # Delimiter is a single integer elif int(delimiter): (_handyman, delimiter) = ( self._fixedwidth_splitter, int(delimiter)) else: (_handyman, delimiter) = (self._delimited_splitter, None) self.delimiter = delimiter if autostrip: self._handyman = self.autostrip(_handyman) else: self._handyman = _handyman #
Example #16
Source File: _iotools.py From keras-lambda with MIT License | 6 votes |
def __init__(self, delimiter=None, comments=asbytes('#'), autostrip=True): self.comments = comments # Delimiter is a character if isinstance(delimiter, unicode): delimiter = delimiter.encode('ascii') if (delimiter is None) or _is_bytes_like(delimiter): delimiter = delimiter or None _handyman = self._delimited_splitter # Delimiter is a list of field widths elif hasattr(delimiter, '__iter__'): _handyman = self._variablewidth_splitter idx = np.cumsum([0] + list(delimiter)) delimiter = [slice(i, j) for (i, j) in zip(idx[:-1], idx[1:])] # Delimiter is a single integer elif int(delimiter): (_handyman, delimiter) = ( self._fixedwidth_splitter, int(delimiter)) else: (_handyman, delimiter) = (self._delimited_splitter, None) self.delimiter = delimiter if autostrip: self._handyman = self.autostrip(_handyman) else: self._handyman = _handyman #
Example #17
Source File: _iotools.py From ImageFusion with MIT License | 6 votes |
def __init__(self, delimiter=None, comments=asbytes('#'), autostrip=True): self.comments = comments # Delimiter is a character if isinstance(delimiter, unicode): delimiter = delimiter.encode('ascii') if (delimiter is None) or _is_bytes_like(delimiter): delimiter = delimiter or None _handyman = self._delimited_splitter # Delimiter is a list of field widths elif hasattr(delimiter, '__iter__'): _handyman = self._variablewidth_splitter idx = np.cumsum([0] + list(delimiter)) delimiter = [slice(i, j) for (i, j) in zip(idx[:-1], idx[1:])] # Delimiter is a single integer elif int(delimiter): (_handyman, delimiter) = ( self._fixedwidth_splitter, int(delimiter)) else: (_handyman, delimiter) = (self._delimited_splitter, None) self.delimiter = delimiter if autostrip: self._handyman = self.autostrip(_handyman) else: self._handyman = _handyman #
Example #18
Source File: _iotools.py From lambda-packs with MIT License | 6 votes |
def _decode_line(line, encoding=None): """Decode bytes from binary input streams. Defaults to decoding from 'latin1'. That differs from the behavior of np.compat.asunicode that decodes from 'ascii'. Parameters ---------- line : str or bytes Line to be decoded. Returns ------- decoded_line : unicode Unicode in Python 2, a str (unicode) in Python 3. """ if type(line) is bytes: if encoding is None: line = line.decode('latin1') else: line = line.decode(encoding) return line
Example #19
Source File: _iotools.py From mxnet-lambda with Apache License 2.0 | 6 votes |
def __init__(self, delimiter=None, comments=b'#', autostrip=True): self.comments = comments # Delimiter is a character if isinstance(delimiter, unicode): delimiter = delimiter.encode('ascii') if (delimiter is None) or _is_bytes_like(delimiter): delimiter = delimiter or None _handyman = self._delimited_splitter # Delimiter is a list of field widths elif hasattr(delimiter, '__iter__'): _handyman = self._variablewidth_splitter idx = np.cumsum([0] + list(delimiter)) delimiter = [slice(i, j) for (i, j) in zip(idx[:-1], idx[1:])] # Delimiter is a single integer elif int(delimiter): (_handyman, delimiter) = ( self._fixedwidth_splitter, int(delimiter)) else: (_handyman, delimiter) = (self._delimited_splitter, None) self.delimiter = delimiter if autostrip: self._handyman = self.autostrip(_handyman) else: self._handyman = _handyman #
Example #20
Source File: _iotools.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def __init__(self, delimiter=None, comments=b'#', autostrip=True): self.comments = comments # Delimiter is a character if isinstance(delimiter, unicode): delimiter = delimiter.encode('ascii') if (delimiter is None) or _is_bytes_like(delimiter): delimiter = delimiter or None _handyman = self._delimited_splitter # Delimiter is a list of field widths elif hasattr(delimiter, '__iter__'): _handyman = self._variablewidth_splitter idx = np.cumsum([0] + list(delimiter)) delimiter = [slice(i, j) for (i, j) in zip(idx[:-1], idx[1:])] # Delimiter is a single integer elif int(delimiter): (_handyman, delimiter) = ( self._fixedwidth_splitter, int(delimiter)) else: (_handyman, delimiter) = (self._delimited_splitter, None) self.delimiter = delimiter if autostrip: self._handyman = self.autostrip(_handyman) else: self._handyman = _handyman #
Example #21
Source File: test_api.py From python-netsurv with MIT License | 5 votes |
def test_retrieves_version_of_self(self): pkg_version = version('egginfo-pkg') assert isinstance(pkg_version, text) assert re.match(self.version_pattern, pkg_version)
Example #22
Source File: test_api.py From pipenv with MIT License | 5 votes |
def test_retrieves_version_of_distinfo_pkg(self): pkg_version = version('distinfo-pkg') assert isinstance(pkg_version, text) assert re.match(self.version_pattern, pkg_version)
Example #23
Source File: misc_ops.py From jarvis with GNU General Public License v2.0 | 5 votes |
def unicode(text): if sys.version_info < (3, 0): if isinstance(text, str): text = text.decode('utf-8') import __builtin__ return __builtin__.unicode(text) elif not isinstance(text, str): return text.decode('utf-8') else: return text
Example #24
Source File: __init__.py From jarvis with GNU General Public License v2.0 | 5 votes |
def uascii_to_str(s): assert isinstance(s, unicode) return s.encode("ascii")
Example #25
Source File: compat.py From btcrecover with GNU General Public License v2.0 | 5 votes |
def uascii_to_str(s): assert isinstance(s, unicode) return s.encode("ascii")
Example #26
Source File: compat.py From btcrecover with GNU General Public License v2.0 | 5 votes |
def uascii_to_str(s): assert isinstance(s, unicode) return s
Example #27
Source File: __init__.py From jarvis with GNU General Public License v2.0 | 5 votes |
def uascii_to_str(s): assert isinstance(s, unicode) return s
Example #28
Source File: compat.py From accelerator with Apache License 2.0 | 5 votes |
def uni(s): if s is None: return None if isinstance(s, bytes): try: return s.decode('utf-8') except UnicodeDecodeError: return s.decode('iso-8859-1') return unicode(s) # This is used in the method launcher to set different titles for each # phase/slice. You can use it in the method to override that if you want.
Example #29
Source File: py3compat.py From yapf with Apache License 2.0 | 5 votes |
def unicode(s): # pylint: disable=invalid-name """Force conversion of s to unicode.""" return __builtin__.unicode(s, 'utf-8') # In Python 3.2+, readfp is deprecated in favor of read_file, which doesn't # exist in Python 2 yet. To avoid deprecation warnings, subclass ConfigParser to # fix this - now read_file works across all Python versions we care about.
Example #30
Source File: py3compat.py From python-scripts with GNU General Public License v3.0 | 5 votes |
def unicode(s): """Force conversion of s to unicode.""" if PY3: return s else: return __builtin__.unicode(s, 'utf-8') # In Python 3.2+, readfp is deprecated in favor of read_file, which doesn't # exist in Python 2 yet. To avoid deprecation warnings, subclass ConfigParser to # fix this - now read_file works across all Python versions we care about.