Python __builtin__.str() Examples
The following are 30
code examples of __builtin__.str().
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 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 #2
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 #3
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 #4
Source File: enums.py From olympe with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __new__(mcls, enum_type, *args, **kwds): """ Creates an ArsdkBitfield type from its associated enum type """ if ArsdkBitfieldMeta._base is None: cls = type.__new__( ArsdkBitfieldMeta, builtin_str("ArsdkBitfield"), *args, **kwds) mcls._base = cls else: cls = mcls._classes.get(enum_type) if cls is not None: return cls cls = type.__new__( mcls, builtin_str(enum_type.__name__ + "_Bitfield"), (mcls._base,), dict(_enum_type_=enum_type)) mcls._classes[enum_type] = cls return cls
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 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 #7
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 #8
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 #9
Source File: casper.py From python-jss with GNU General Public License v3.0 | 6 votes |
def __init__(self, jss): """Initialize a Casper object. Args: jss: A JSS object to request the casper page from. """ self.jss = jss self.url = "%s/casper.jxml" % self.jss.base_url # This may be incorrect, but the assumption here is that this # request wants the auth information as urlencoded data; and # urlencode needs bytes. # TODO: If we can just pass in bytes rather than # urlencoded-bytes, we can remove this and let the request # adapter handle the outgoing data encoding. user = text(self.jss.user) password = text(self.jss.password) self.auth = urlencode( {"username": user, "password": password}) super(Casper, self).__init__("Casper") self.update()
Example #10
Source File: fypp.py From fypp with BSD 2-Clause "Simplified" License | 5 votes |
def handle_include(self, span, fname): '''Called when parser starts to process a new file. It is a dummy methond and should be overridden for actual use. Args: span (tuple of int): Start and end line of the include directive or None if called the first time for the main input. fname (str): Name of the file. ''' self._log_event('include', span, filename=fname)
Example #11
Source File: fypp.py From fypp with BSD 2-Clause "Simplified" License | 5 votes |
def handle_if(self, span, cond): '''Called when parser encounters an if directive. It is a dummy method and should be overridden for actual use. Args: span (tuple of int): Start and end line of the directive. cond (str): String representation of the branching condition. ''' self._log_event('if', span, condition=cond)
Example #12
Source File: fypp.py From fypp with BSD 2-Clause "Simplified" License | 5 votes |
def handle_del(self, span, name): '''Called when parser encounters a del directive. It is a dummy method and should be overridden for actual use. Args: span (tuple of int): Start and end line of the directive. name (str): Name of the variable to delete. ''' self._log_event('del', span, name=name)
Example #13
Source File: fypp.py From fypp with BSD 2-Clause "Simplified" License | 5 votes |
def handle_enddef(self, span, name): '''Called when parser encounters an enddef directive. It is a dummy method and should be overridden for actual use. Args: span (tuple of int): Start and end line of the directive. name (str): Name found after the enddef directive. ''' self._log_event('enddef', span, name=name)
Example #14
Source File: fypp.py From fypp with BSD 2-Clause "Simplified" License | 5 votes |
def handle_def(self, span, name, args): '''Called when parser encounters a def directive. It is a dummy method and should be overridden for actual use. Args: span (tuple of int): Start and end line of the directive. name (str): Name of the macro to be defined. argexpr (str): String with argument definition (or None) ''' self._log_event('def', span, name=name, arguments=args)
Example #15
Source File: fypp.py From fypp with BSD 2-Clause "Simplified" License | 5 votes |
def handle_endinclude(self, span, fname): '''Called when parser finished processing a file. It is a dummy method and should be overridden for actual use. Args: span (tuple of int): Start and end line of the include directive or None if called the first time for the main input. fname (str): Name of the file. ''' self._log_event('endinclude', span, filename=fname)
Example #16
Source File: setup.py From pyprover with Apache License 2.0 | 5 votes |
def makedata(data_type, *args): """Construct an object of the given data_type containing the given arguments.""" if _coconut.hasattr(data_type, "_make") and _coconut.issubclass(data_type, _coconut.tuple): return data_type._make(args) if _coconut.issubclass(data_type, (_coconut.map, _coconut.range, _coconut.abc.Iterator)): return args if _coconut.issubclass(data_type, _coconut.str): return "".join(args) return data_type(args)
Example #17
Source File: fypp.py From fypp with BSD 2-Clause "Simplified" License | 5 votes |
def parse(self, txt): '''Parses string. Args: txt (str): Text to parse. ''' self._curfile = STRING self._curdir = '' self._parse_txt(None, self._curfile, txt)
Example #18
Source File: __coconut__.py From pyprover with Apache License 2.0 | 5 votes |
def makedata(data_type, *args): """Construct an object of the given data_type containing the given arguments.""" if _coconut.hasattr(data_type, "_make") and _coconut.issubclass(data_type, _coconut.tuple): return data_type._make(args) if _coconut.issubclass(data_type, (_coconut.map, _coconut.range, _coconut.abc.Iterator)): return args if _coconut.issubclass(data_type, _coconut.str): return "".join(args) return data_type(args)
Example #19
Source File: setup.py From pyprover with Apache License 2.0 | 5 votes |
def __call__(self, *args, **kwargs): callargs = [] argind = 0 for i in _coconut.range(self._arglen): if i in self._argdict: callargs.append(self._argdict[i]) elif argind >= _coconut.len(args): raise _coconut.TypeError("expected at least " + _coconut.str(self._arglen - _coconut.len(self._argdict)) + " argument(s) to " + _coconut.repr(self)) else: callargs.append(args[argind]) argind += 1 callargs += self._stargs callargs += args[argind:] kwargs.update(self.keywords) return self.func(*callargs, **kwargs)
Example #20
Source File: __coconut__.py From pyprover with Apache License 2.0 | 5 votes |
def __call__(self, *args, **kwargs): callargs = [] argind = 0 for i in _coconut.range(self._arglen): if i in self._argdict: callargs.append(self._argdict[i]) elif argind >= _coconut.len(args): raise _coconut.TypeError("expected at least " + _coconut.str(self._arglen - _coconut.len(self._argdict)) + " argument(s) to " + _coconut.repr(self)) else: callargs.append(args[argind]) argind += 1 callargs += self._stargs callargs += args[argind:] kwargs.update(self.keywords) return self.func(*callargs, **kwargs)
Example #21
Source File: fypp.py From fypp with BSD 2-Clause "Simplified" License | 5 votes |
def parsefile(self, fobj): '''Parses file or a file like object. Args: fobj (str or file): Name of a file or a file like object. ''' if isinstance(fobj, str): if fobj == STDIN: self._includefile(None, sys.stdin, STDIN, os.getcwd()) else: inpfp = _open_input_file(fobj, self._encoding) self._includefile(None, inpfp, fobj, os.path.dirname(fobj)) inpfp.close() else: self._includefile(None, fobj, FILEOBJ, os.getcwd())
Example #22
Source File: _iotools.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def str2bool(value): """ Tries to transform a string supposed to represent a boolean to a boolean. Parameters ---------- value : str The string that is transformed to a boolean. Returns ------- boolval : bool The boolean representation of `value`. Raises ------ ValueError If the string is not 'True' or 'False' (case independent) Examples -------- >>> np.lib._iotools.str2bool('TRUE') True >>> np.lib._iotools.str2bool('false') False """ value = value.upper() if value == b'TRUE': return True elif value == b'FALSE': return False else: raise ValueError("Invalid boolean")
Example #23
Source File: _iotools.py From pySINDy with MIT License | 5 votes |
def str2bool(value): """ Tries to transform a string supposed to represent a boolean to a boolean. Parameters ---------- value : str The string that is transformed to a boolean. Returns ------- boolval : bool The boolean representation of `value`. Raises ------ ValueError If the string is not 'True' or 'False' (case independent) Examples -------- >>> np.lib._iotools.str2bool('TRUE') True >>> np.lib._iotools.str2bool('false') False """ value = value.upper() if value == 'TRUE': return True elif value == 'FALSE': return False else: raise ValueError("Invalid boolean")
Example #24
Source File: _iotools.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def str2bool(value): """ Tries to transform a string supposed to represent a boolean to a boolean. Parameters ---------- value : str The string that is transformed to a boolean. Returns ------- boolval : bool The boolean representation of `value`. Raises ------ ValueError If the string is not 'True' or 'False' (case independent) Examples -------- >>> np.lib._iotools.str2bool('TRUE') True >>> np.lib._iotools.str2bool('false') False """ value = value.upper() if value == asbytes('TRUE'): return True elif value == asbytes('FALSE'): return False else: raise ValueError("Invalid boolean")
Example #25
Source File: numerictypes.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def issubsctype(arg1, arg2): """ Determine if the first argument is a subclass of the second argument. Parameters ---------- arg1, arg2 : dtype or dtype specifier Data-types. Returns ------- out : bool The result. See Also -------- issctype, issubdtype,obj2sctype Examples -------- >>> np.issubsctype('S8', str) True >>> np.issubsctype(np.array([1]), int) True >>> np.issubsctype(np.array([1]), float) False """ return issubclass(obj2sctype(arg1), obj2sctype(arg2))
Example #26
Source File: _iotools.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def str2bool(value): """ Tries to transform a string supposed to represent a boolean to a boolean. Parameters ---------- value : str The string that is transformed to a boolean. Returns ------- boolval : bool The boolean representation of `value`. Raises ------ ValueError If the string is not 'True' or 'False' (case independent) Examples -------- >>> np.lib._iotools.str2bool('TRUE') True >>> np.lib._iotools.str2bool('false') False """ value = value.upper() if value == 'TRUE': return True elif value == 'FALSE': return False else: raise ValueError("Invalid boolean")
Example #27
Source File: test_utils.py From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 | 5 votes |
def test_ensure_new_type(self): s = u'abcd' s2 = str(s) self.assertEqual(ensure_new_type(s), s2) self.assertEqual(type(ensure_new_type(s)), str) b = b'xyz' b2 = bytes(b) self.assertEqual(ensure_new_type(b), b2) self.assertEqual(type(ensure_new_type(b)), bytes) i = 10000000000000 i2 = int(i) self.assertEqual(ensure_new_type(i), i2) self.assertEqual(type(ensure_new_type(i)), int)
Example #28
Source File: test_utils.py From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 | 5 votes |
def test_raise_(self): """ The with_value() test currently fails on Py3 """ def valerror(): try: raise ValueError("Apples!") except Exception as e: raise_(e) self.assertRaises(ValueError, valerror) def with_value(): raise_(IOError, "This is an error") self.assertRaises(IOError, with_value) try: with_value() except IOError as e: self.assertEqual(str(e), "This is an error") def with_traceback(): try: raise ValueError("An error") except Exception as e: _, _, traceback = sys.exc_info() raise_(IOError, str(e), traceback) self.assertRaises(IOError, with_traceback) try: with_traceback() except IOError as e: self.assertEqual(str(e), "An error")
Example #29
Source File: test_utils.py From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 | 5 votes |
def test_native(self): a = int(10**20) # long int b = native(a) self.assertEqual(a, b) if PY2: self.assertEqual(type(b), long) else: self.assertEqual(type(b), int) c = bytes(b'ABC') d = native(c) self.assertEqual(c, d) if PY2: self.assertEqual(type(d), type(b'Py2 byte-string')) else: self.assertEqual(type(d), bytes) s = str(u'ABC') t = native(s) self.assertEqual(s, t) if PY2: self.assertEqual(type(t), unicode) else: self.assertEqual(type(t), str) d1 = dict({'a': 1, 'b': 2}) d2 = native(d1) self.assertEqual(d1, d2) self.assertEqual(type(d2), type({}))
Example #30
Source File: test_utils.py From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 | 5 votes |
def test_native_str(self): """ Tests whether native_str is really equal to the platform str. """ if PY2: import __builtin__ builtin_str = __builtin__.str else: import builtins builtin_str = builtins.str inputs = [b'blah', u'blah', 'blah'] for s in inputs: self.assertEqual(native_str(s), builtin_str(s)) self.assertTrue(isinstance(native_str(s), builtin_str))