示例#1
0
    def zonemgr(self, value):
        # validate the value first
        if six.PY3:
            bindinstance.validate_zonemgr_str(value)
        else:
            try:
                # IDNA support requires unicode
                encoding = getattr(sys.stdin, 'encoding', None)
                if encoding is None:
                    encoding = 'utf-8'

                # value is string in py2 and py3
                if not isinstance(value, unicode):
                    value = value.decode(encoding)

                bindinstance.validate_zonemgr_str(value)
            except ValueError as e:
                # FIXME we can do this in better way
                # https://fedorahosted.org/freeipa/ticket/4804
                # decode to proper stderr encoding
                stderr_encoding = getattr(sys.stderr, 'encoding', None)
                if stderr_encoding is None:
                    stderr_encoding = 'utf-8'
                error = unicode(e).encode(stderr_encoding)
                raise ValueError(error)
示例#2
0
文件: dns.py 项目: encukou/freeipa
    def zonemgr(self, value):
        # validate the value first
        if six.PY3:
            bindinstance.validate_zonemgr_str(value)
        else:
            try:
                # IDNA support requires unicode
                encoding = getattr(sys.stdin, 'encoding', None)
                if encoding is None:
                    encoding = 'utf-8'

                # value is string in py2 and py3
                if not isinstance(value, unicode):
                    value = value.decode(encoding)

                bindinstance.validate_zonemgr_str(value)
            except ValueError as e:
                # FIXME we can do this in better way
                # https://fedorahosted.org/freeipa/ticket/4804
                # decode to proper stderr encoding
                stderr_encoding = getattr(sys.stderr, 'encoding', None)
                if stderr_encoding is None:
                    stderr_encoding = 'utf-8'
                error = unicode(e).encode(stderr_encoding)
                raise ValueError(error)