예제 #1
0
    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
예제 #2
0
파일: mls.py 프로젝트: pombredanne/mls
    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
예제 #3
0
파일: base.py 프로젝트: anujkumar93/stor
    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)
예제 #4
0
 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
예제 #5
0
파일: core.py 프로젝트: CivicSpleen/rowpipe
    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)
예제 #6
0
    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)
예제 #7
0
    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
예제 #8
0
    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
예제 #9
0
 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)
예제 #10
0
파일: path.py 프로젝트: Anlim/sphinx
 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)
예제 #11
0
파일: path.py 프로젝트: mgeier/sphinx
 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
예제 #12
0
 def __new__(cls):
     new = text_type.__new__(cls, u'')
     return new
예제 #13
0
 def __new__(cls, formatting, normal):
     new = text_type.__new__(cls, formatting)
     new._normal = normal
     return new
예제 #14
0
 def __new__(cls, content):
     if not cls.pattern.match(content):
         raise ValueError(content)
     return text_type.__new__(cls, content)
예제 #15
0
 def __new__(cls, value):
     try:
         rt = text_type.__new__(cls, value)
     except UnicodeDecodeError:
         rt = text_type.__new__(cls, value, 'utf-8')
     return rt
예제 #16
0
 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
예제 #17
0
 def __new__(cls, text):
     return text_type.__new__(cls, text)
예제 #18
0
파일: languoids.py 프로젝트: clld/glottolog
 def __new__(cls, content):
     if not cls.pattern.match(content):
         raise ValueError(content)
     return text_type.__new__(cls, content)
예제 #19
0
 def __new__(cls):
     new = text_type.__new__(cls, u'')
     return new
예제 #20
0
 def __new__(cls, formatting, normal):
     new = text_type.__new__(cls, formatting)
     new._normal = normal
     return new