當前位置: 首頁>>代碼示例>>Python>>正文


Python six.PY3屬性代碼示例

本文整理匯總了Python中django.utils.six.PY3屬性的典型用法代碼示例。如果您正苦於以下問題:Python six.PY3屬性的具體用法?Python six.PY3怎麽用?Python six.PY3使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在django.utils.six的用法示例。


在下文中一共展示了six.PY3屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import PY3 [as 別名]
def __init__(self, field, request, params, model, admin_view, field_path):
        self.field = field
        self.field_path = field_path
        self.title = getattr(field, 'verbose_name', field_path)
        self.context_params = {}

        super(FieldFilter, self).__init__(request, params, model, admin_view)

        for name, format in self.lookup_formats.items():
            p = format % field_path
            self.context_params["%s_name" % name] = FILTER_PREFIX + p
            if p in params:
                value = prepare_lookup_value(p, params.pop(p))
                self.used_params[p] = value
                self.context_params["%s_val" % name] = value
            else:
                self.context_params["%s_val" % name] = ''

        arr = map(
                lambda kv: setattr(self, 'lookup_' + kv[0], kv[1]),
                self.context_params.items()
                )
        if six.PY3:
            list(arr) 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:26,代碼來源:filters.py

示例2: post

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import PY3 [as 別名]
def post(self, request, *args, **kwargs):
        self.instance_forms()
        self.setup_forms()

        if self.valid_forms():
            self.save_forms()
            self.save_models()
            self.save_related()
            response = self.post_response()
            cls_str = str if six.PY3 else basestring
            if isinstance(response, cls_str):
                return HttpResponseRedirect(response)
            else:
                return response

        return self.get_response() 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:18,代碼來源:edit.py

示例3: unquote

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import PY3 [as 別名]
def unquote(s):
    """
    Undo the effects of quote(). Based heavily on urllib.unquote().
    """
    cls_str = str if six.PY3 else basestring
    if not isinstance(s, cls_str):
        return s
    mychr = chr
    myatoi = int
    list = s.split('_')
    res = [list[0]]
    myappend = res.append
    del list[0]
    for item in list:
        if item[1:2]:
            try:
                myappend(mychr(myatoi(item[:2], 16)) + item[2:])
            except ValueError:
                myappend('_' + item)
        else:
            myappend('_' + item)
    return "".join(res) 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:24,代碼來源:util.py

示例4: view_block

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import PY3 [as 別名]
def view_block(context, block_name, *args, **kwargs):
    if 'admin_view' not in context:
        return ""

    admin_view = context['admin_view']
    nodes = []
    method_name = 'block_%s' % block_name

    cls_str = str if six.PY3 else basestring
    for view in [admin_view] + admin_view.plugins:
        if hasattr(view, method_name) and callable(getattr(view, method_name)):
            block_func = getattr(view, method_name)
            result = block_func(context, nodes, *args, **kwargs)
            if result and isinstance(result, cls_str):
                nodes.append(result)
    if nodes:
        return mark_safe(''.join(nodes))
    else:
        return "" 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:21,代碼來源:xadmin_tags.py

示例5: get_actions

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import PY3 [as 別名]
def get_actions(self):
        if self.actions is None:
            return OrderedDict()

        actions = [self.get_action(action) for action in self.global_actions]

        for klass in self.admin_view.__class__.mro()[::-1]:
            class_actions = getattr(klass, 'actions', [])
            if not class_actions:
                continue
            actions.extend(
                [self.get_action(action) for action in class_actions])

        # get_action might have returned None, so filter any of those out.
        actions = filter(None, actions)
        if six.PY3:
            actions = list(actions)

        # Convert the actions into a OrderedDict keyed by name.
        actions = OrderedDict([
            (name, (ac, name, desc, icon))
            for ac, name, desc, icon in actions
        ])

        return actions 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:27,代碼來源:actions.py

示例6: constant_time_compare

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import PY3 [as 別名]
def constant_time_compare(val1, val2):
        """
        Returns True if the two strings are equal, False otherwise.

        The time taken is independent of the number of characters that match.

        For the sake of simplicity, this function executes in constant time only
        when the two strings have the same length. It short-circuits when they
        have different lengths. Since Django only uses it to compare hashes of
        known expected length, this is acceptable.
        """
        if len(val1) != len(val2):
            return False
        result = 0
        if six.PY3 and isinstance(val1, bytes) and isinstance(val2, bytes):
            for x, y in zip(val1, val2):
                result |= x ^ y
        else:
            for x, y in zip(val1, val2):
                result |= ord(x) ^ ord(y)
        return result == 0 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:23,代碼來源:crypto.py

示例7: _ask_default

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import PY3 [as 別名]
def _ask_default(self):
        print("Please enter the default value now, as valid Python")
        print("The datetime and django.utils.timezone modules are available, so you can do e.g. timezone.now()")
        while True:
            if six.PY3:
                # Six does not correctly abstract over the fact that
                # py3 input returns a unicode string, while py2 raw_input
                # returns a bytestring.
                code = input(">>> ")
            else:
                code = input(">>> ").decode(sys.stdin.encoding)
            if not code:
                print("Please enter some code, or 'exit' (with no quotes) to exit.")
            elif code == "exit":
                sys.exit(1)
            else:
                try:
                    return eval(code, {}, {"datetime": datetime_safe, "timezone": timezone})
                except (SyntaxError, NameError) as e:
                    print("Invalid input: %s" % e) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:22,代碼來源:questioner.py

示例8: _get_queryset_methods

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import PY3 [as 別名]
def _get_queryset_methods(cls, queryset_class):
        def create_method(name, method):
            def manager_method(self, *args, **kwargs):
                return getattr(self.get_queryset(), name)(*args, **kwargs)
            manager_method.__name__ = method.__name__
            manager_method.__doc__ = method.__doc__
            return manager_method

        new_methods = {}
        # Refs http://bugs.python.org/issue1785.
        predicate = inspect.isfunction if six.PY3 else inspect.ismethod
        for name, method in inspect.getmembers(queryset_class, predicate=predicate):
            # Only copy missing methods.
            if hasattr(cls, name):
                continue
            # Only copy public methods or methods with the attribute `queryset_only=False`.
            queryset_only = getattr(method, 'queryset_only', None)
            if queryset_only or (queryset_only is None and name.startswith('_')):
                continue
            # Copy the method onto the manager.
            new_methods[name] = create_method(name, method)
        return new_methods 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:24,代碼來源:manager.py

示例9: gettext_popen_wrapper

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import PY3 [as 別名]
def gettext_popen_wrapper(args, os_err_exc_type=CommandError, stdout_encoding="utf-8"):
    """
    Makes sure text obtained from stdout of gettext utilities is Unicode.
    """
    # This both decodes utf-8 and cleans line endings. Simply using
    # popen_wrapper(universal_newlines=True) doesn't properly handle the
    # encoding. This goes back to popen's flaky support for encoding:
    # https://bugs.python.org/issue6135. This is a solution for #23271, #21928.
    # No need to do anything on Python 2 because it's already a byte-string there.
    manual_io_wrapper = six.PY3 and stdout_encoding != DEFAULT_LOCALE_ENCODING

    stdout, stderr, status_code = popen_wrapper(args, os_err_exc_type=os_err_exc_type,
                                                universal_newlines=not manual_io_wrapper)
    if manual_io_wrapper:
        stdout = io.TextIOWrapper(io.BytesIO(stdout), encoding=stdout_encoding).read()
    if six.PY2:
        stdout = stdout.decode(stdout_encoding)
    return stdout, stderr, status_code 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:20,代碼來源:makemessages.py

示例10: get_environ

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import PY3 [as 別名]
def get_environ(self):
        # Strip all headers with underscores in the name before constructing
        # the WSGI environ. This prevents header-spoofing based on ambiguity
        # between underscores and dashes both normalized to underscores in WSGI
        # env vars. Nginx and Apache 2.4+ both do this as well.
        for k, v in self.headers.items():
            if '_' in k:
                del self.headers[k]

        env = super(WSGIRequestHandler, self).get_environ()

        path = self.path
        if '?' in path:
            path = path.partition('?')[0]

        path = uri_to_iri(path).encode(UTF_8)
        # Under Python 3, non-ASCII values in the WSGI environ are arbitrarily
        # decoded with ISO-8859-1. We replicate this behavior here.
        # Refs comment in `get_bytes_from_wsgi()`.
        env['PATH_INFO'] = path.decode(ISO_8859_1) if six.PY3 else path

        return env 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:24,代碼來源:basehttp.py

示例11: __init__

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import PY3 [as 別名]
def __init__(self, field, request, params, model, admin_view, field_path):
        self.field = field
        self.field_path = field_path
        self.title = getattr(field, 'verbose_name', field_path)
        self.context_params = {}

        super(FieldFilter, self).__init__(request, params, model, admin_view)

        for name, format in self.lookup_formats.items():
            p = format % field_path
            self.context_params["%s_name" % name] = FILTER_PREFIX + p
            if p in params:
                value = prepare_lookup_value(p, params.pop(p))
                self.used_params[p] = value
                self.context_params["%s_val" % name] = value
            else:
                self.context_params["%s_val" % name] = ''

        arr = map(
            lambda kv: setattr(self, 'lookup_' + kv[0], kv[1]),
            self.context_params.items()
        )
        if six.PY3:
            list(arr) 
開發者ID:Superbsco,項目名稱:weibo-analysis-system,代碼行數:26,代碼來源:filters.py

示例12: form_params

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import PY3 [as 別名]
def form_params(self):
        arr = map(lambda k: FILTER_PREFIX + k, self.used_params.keys())
        if six.PY3:
            arr = list(arr)
        return self.admin_view.get_form_params(remove=arr) 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:7,代碼來源:filters.py

示例13: get_context

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import PY3 [as 別名]
def get_context(self):
        context = super(FieldFilter, self).get_context()
        context.update(self.context_params)
        obj = map(lambda k: FILTER_PREFIX + k, self.used_params.keys())
        if six.PY3:
            obj = list(obj)
        context['remove_url'] = self.query_string({}, obj)
        return context 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:10,代碼來源:filters.py

示例14: inclusion_tag

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import PY3 [as 別名]
def inclusion_tag(file_name, context_class=Context, takes_context=False):
    def wrap(func):
        @functools.wraps(func)
        def method(self, context, nodes, *arg, **kwargs):
            _dict = func(self, context, nodes, *arg, **kwargs)
            from django.template.loader import get_template, select_template
            cls_str = str if six.PY3 else basestring
            if isinstance(file_name, Template):
                t = file_name
            elif not isinstance(file_name, cls_str) and is_iterable(file_name):
                t = select_template(file_name)
            else:
                t = get_template(file_name)

            _dict['autoescape'] = context.autoescape
            _dict['use_l10n'] = context.use_l10n
            _dict['use_tz'] = context.use_tz
            _dict['admin_view'] = context['admin_view']

            csrf_token = context.get('csrf_token', None)
            if csrf_token is not None:
                _dict['csrf_token'] = csrf_token
            nodes.append(t.render(_dict))

        return method
    return wrap 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:28,代碼來源:base.py

示例15: post

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import PY3 [as 別名]
def post(self, request, object_id):
        if self.perms_needed:
            raise PermissionDenied

        self.delete_model()

        response = self.post_response()
        cls_str = str if six.PY3 else basestring
        if isinstance(response, cls_str):
            response = HttpResponseRedirect(response)
        return response 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:13,代碼來源:delete.py


注:本文中的django.utils.six.PY3屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。