示例#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
    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
 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