def __new__(cls, mapping=None, language=None, **kwargs): # pylint: disable=W0212 if isinstance(mapping, MultiLingualString): language = language or mapping.language instance = text_type.__new__(cls, text_type(mapping >> language)) instance._mapping = mapping._mapping instance.language = language return instance language = _extract_language(language or _get_system_locale()) if language not in LANGUAGES: raise ValueError("Unknown language: {}".format(language)) if mapping is None: mapping = u("") if not isinstance(mapping, dict): mapping = {language: _convert_to_unicode(mapping)} mapping.update(kwargs) for key in mapping: if key not in LANGUAGES: raise ValueError("Unknown mutation mapping: {}".format(key)) value = mapping.get( language, mapping.get(_extract_language(_get_system_locale()), u(""))) instance = text_type.__new__(cls, value) instance._mapping = mapping instance.language = language return instance
def __new__(cls, mapping=None, language=None, **kwargs): # pylint: disable=W0212 if isinstance(mapping, MultiLingualString): language = language or mapping.language instance = text_type.__new__(cls, text_type(mapping >> language)) instance._mapping = mapping._mapping instance.language = language return instance language = _extract_language(language or _get_system_locale()) if language not in LANGUAGES: raise ValueError("Unknown language: {}".format(language)) if mapping is None: mapping = u("") if not isinstance(mapping, dict): mapping = {language: _convert_to_unicode(mapping)} mapping.update(kwargs) for key in mapping: if key not in LANGUAGES: raise ValueError("Unknown mutation mapping: {}".format(key)) value = mapping.get(language, mapping.get( _extract_language(_get_system_locale()), u(""))) instance = text_type.__new__(cls, value) instance._mapping = mapping instance.language = language return instance
def __new__(cls, path): if cls is Path: if not hasattr(path, 'startswith'): raise TypeError('must be a string like') if utils.is_dx_path(path): cls = utils.find_dx_class(path) elif utils.is_swift_path(path): from stor.swift import SwiftPath cls = SwiftPath elif utils.is_s3_path(path): from stor.s3 import S3Path cls = S3Path elif os.path == ntpath: from stor.windows import WindowsPath cls = WindowsPath elif os.path == posixpath: from stor.posix import PosixPath cls = PosixPath else: # pragma: no cover assert False, 'path is not compatible with stor' return text_type.__new__(cls, path)
def __new__(cls, arg='', *args, **kwargs): if not isinstance(arg, str): raise TypeError("%r is not a str" % arg) # obj = str.__new__(cls, arg) obj = str.__new__(cls,arg) object.__setattr__(obj, '__initialized', False) return obj
def __new__(cls, v): if v is None or v is NoneValue or v == '': return NoneValue try: return text_type.__new__(cls, v) except Exception as e: return FailedValue(v, e)
def __new__(cls, v): if v is None or v is NoneValue or v == '': return NoneValue try: return text_type.__new__(cls, v) except Exception as e: return FailedValue(v, e)
def __new__(cls, formatting, normal=None): """Instantiate. :arg normal: If non-None, indicates that, once parametrized, this can be used as a ``FormattingString``. The value is used as the "normal" capability. """ new = text_type.__new__(cls, formatting) new._normal = normal return new
def __new__(cls, formatting, normal=None): """Instantiate. :arg normal: If non-None, indicates that, once parametrized, this can be used as a ``FormattingString``. The value is used as the "normal" capability. """ new = text_type.__new__(cls, formatting) new._normal = normal return new
def __new__(cls, s, encoding=FILESYSTEMENCODING, errors='strict'): if isinstance(s, str): s = s.decode(encoding, errors) return text_type.__new__(cls, s) return text_type.__new__(cls, s)
def __new__(cls, s, encoding=FILESYSTEMENCODING, errors='strict'): if isinstance(s, str): s = s.decode(encoding, errors) return text_type.__new__(cls, s) return text_type.__new__(cls, s)
def __new__(cls, s, encoding=FILESYSTEMENCODING, errors='strict'): # type: (unicode, unicode, unicode) -> path if isinstance(s, str): s = s.decode(encoding, errors) return text_type.__new__(cls, s) return text_type.__new__(cls, s) # type: ignore
def __new__(cls): new = text_type.__new__(cls, u'') return new
def __new__(cls, formatting, normal): new = text_type.__new__(cls, formatting) new._normal = normal return new
def __new__(cls, content): if not cls.pattern.match(content): raise ValueError(content) return text_type.__new__(cls, content)
def __new__(cls, value): try: rt = text_type.__new__(cls, value) except UnicodeDecodeError: rt = text_type.__new__(cls, value, 'utf-8') return rt
def __new__(cls, s, encoding=FILESYSTEMENCODING, errors='strict'): # type: (unicode, unicode, unicode) -> path if isinstance(s, str): s = s.decode(encoding, errors) return text_type.__new__(cls, s) # type: ignore return text_type.__new__(cls, s) # type: ignore
def __new__(cls, text): return text_type.__new__(cls, text)
def __new__(cls, content): if not cls.pattern.match(content): raise ValueError(content) return text_type.__new__(cls, content)
def __new__(cls): new = text_type.__new__(cls, u'') return new
def __new__(cls, formatting, normal): new = text_type.__new__(cls, formatting) new._normal = normal return new