当前位置: 首页>>代码示例>>Python>>正文


Python moves.range方法代码示例

本文整理汇总了Python中django.utils.six.moves.range方法的典型用法代码示例。如果您正苦于以下问题:Python moves.range方法的具体用法?Python moves.range怎么用?Python moves.range使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.utils.six.moves的用法示例。


在下文中一共展示了moves.range方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: deleted_forms

# 需要导入模块: from django.utils.six import moves [as 别名]
# 或者: from django.utils.six.moves import range [as 别名]
def deleted_forms(self):
        """
        Returns a list of forms that have been marked for deletion.
        """
        if not self.is_valid() or not self.can_delete:
            return []
        # construct _deleted_form_indexes which is just a list of form indexes
        # that have had their deletion widget set to True
        if not hasattr(self, '_deleted_form_indexes'):
            self._deleted_form_indexes = []
            for i in range(0, self.total_form_count()):
                form = self.forms[i]
                # if this is an extra form and hasn't changed, don't consider it
                if i >= self.initial_form_count() and not form.has_changed():
                    continue
                if self._should_delete_form(form):
                    self._deleted_form_indexes.append(i)
        return [self.forms[i] for i in self._deleted_form_indexes] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:20,代码来源:formsets.py

示例2: is_valid

# 需要导入模块: from django.utils.six import moves [as 别名]
# 或者: from django.utils.six.moves import range [as 别名]
def is_valid(self):
        """
        Returns True if every form in self.forms is valid.
        """
        if not self.is_bound:
            return False
        # We loop over every form.errors here rather than short circuiting on the
        # first failure to make sure validation gets triggered for every form.
        forms_valid = True
        # This triggers a full clean.
        self.errors
        for i in range(0, self.total_form_count()):
            form = self.forms[i]
            if self.can_delete:
                if self._should_delete_form(form):
                    # This form is going to be deleted so any of its errors
                    # should not cause the entire formset to be invalid.
                    continue
            forms_valid &= form.is_valid()
        return forms_valid and not self.non_form_errors() 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:22,代码来源:formsets.py

示例3: as_sql

# 需要导入模块: from django.utils.six import moves [as 别名]
# 或者: from django.utils.six.moves import range [as 别名]
def as_sql(self, compiler, connection):
        max_in_list_size = connection.ops.max_in_list_size()
        if self.rhs_is_direct_value() and (max_in_list_size and
                                           len(self.rhs) > max_in_list_size):
            # This is a special case for Oracle which limits the number of elements
            # which can appear in an 'IN' clause.
            lhs, lhs_params = self.process_lhs(compiler, connection)
            rhs, rhs_params = self.batch_process_rhs(compiler, connection)
            in_clause_elements = ['(']
            params = []
            for offset in range(0, len(rhs_params), max_in_list_size):
                if offset > 0:
                    in_clause_elements.append(' OR ')
                in_clause_elements.append('%s IN (' % lhs)
                params.extend(lhs_params)
                sqls = rhs[offset: offset + max_in_list_size]
                sqls_params = rhs_params[offset: offset + max_in_list_size]
                param_group = ', '.join(sqls)
                in_clause_elements.append(param_group)
                in_clause_elements.append(')')
                params.extend(sqls_params)
            in_clause_elements.append(')')
            return ''.join(in_clause_elements), params
        else:
            return super(In, self).as_sql(compiler, connection) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:27,代码来源:lookups.py

示例4: create

# 需要导入模块: from django.utils.six import moves [as 别名]
# 或者: from django.utils.six.moves import range [as 别名]
def create(self):
        # Because a cache can fail silently (e.g. memcache), we don't know if
        # we are failing to create a new session because of a key collision or
        # because the cache is missing. So we try for a (large) number of times
        # and then raise an exception. That's the risk you shoulder if using
        # cache backing.
        for i in range(10000):
            self._session_key = self._get_new_session_key()
            try:
                self.save(must_create=True)
            except CreateError:
                continue
            self.modified = True
            return
        raise RuntimeError(
            "Unable to create a new session key. "
            "It is likely that the cache is unavailable.") 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:19,代码来源:cache.py

示例5: __delitem__

# 需要导入模块: from django.utils.six import moves [as 别名]
# 或者: from django.utils.six.moves import range [as 别名]
def __delitem__(self, index):
        "Delete the item(s) at the specified index/slice."
        if not isinstance(index, six.integer_types + (slice,)):
            raise TypeError("%s is not a legal index" % index)

        # calculate new length and dimensions
        origLen = len(self)
        if isinstance(index, six.integer_types):
            index = self._checkindex(index)
            indexRange = [index]
        else:
            indexRange = range(*index.indices(origLen))

        newLen = origLen - len(indexRange)
        newItems = (self._get_single_internal(i)
                    for i in range(origLen)
                    if i not in indexRange)

        self._rebuild(newLen, newItems) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:21,代码来源:mutable_list.py

示例6: __lt__

# 需要导入模块: from django.utils.six import moves [as 别名]
# 或者: from django.utils.six.moves import range [as 别名]
def __lt__(self, other):
        olen = len(other)
        for i in range(olen):
            try:
                c = self[i] < other[i]
            except self._IndexError:
                # self must be shorter
                return True
            if c:
                return c
            elif other[i] < self[i]:
                return False
        return len(self) < olen

    # ### Public list interface Methods ###
    # ## Non-mutating ## 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:18,代码来源:mutable_list.py

示例7: _assign_extended_slice_rebuild

# 需要导入模块: from django.utils.six import moves [as 别名]
# 或者: from django.utils.six.moves import range [as 别名]
def _assign_extended_slice_rebuild(self, start, stop, step, valueList):
        'Assign an extended slice by rebuilding entire list'
        indexList = range(start, stop, step)
        # extended slice, only allow assigning slice of same size
        if len(valueList) != len(indexList):
            raise ValueError('attempt to assign sequence of size %d '
                             'to extended slice of size %d'
                             % (len(valueList), len(indexList)))

        # we're not changing the length of the sequence
        newLen = len(self)
        newVals = dict(zip(indexList, valueList))

        def newItems():
            for i in range(newLen):
                if i in newVals:
                    yield newVals[i]
                else:
                    yield self._get_single_internal(i)

        self._rebuild(newLen, newItems()) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:23,代码来源:mutable_list.py

示例8: _assign_simple_slice

# 需要导入模块: from django.utils.six import moves [as 别名]
# 或者: from django.utils.six.moves import range [as 别名]
def _assign_simple_slice(self, start, stop, valueList):
        'Assign a simple slice; Can assign slice of any length'
        origLen = len(self)
        stop = max(start, stop)
        newLen = origLen - stop + start + len(valueList)

        def newItems():
            for i in range(origLen + 1):
                if i == start:
                    for val in valueList:
                        yield val

                if i < origLen:
                    if i < start or i >= stop:
                        yield self._get_single_internal(i)

        self._rebuild(newLen, newItems()) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:19,代码来源:mutable_list.py

示例9: __init__

# 需要导入模块: from django.utils.six import moves [as 别名]
# 或者: from django.utils.six.moves import range [as 别名]
def __init__(self, num_zoom=19, tilesize=256):
        "Initializes the Google Zoom object."
        # Google's tilesize is 256x256, square tiles are assumed.
        self._tilesize = tilesize

        # The number of zoom levels
        self._nzoom = num_zoom

        # Initializing arrays to hold the parameters for each one of the
        # zoom levels.
        self._degpp = []  # Degrees per pixel
        self._radpp = []  # Radians per pixel
        self._npix = []  # 1/2 the number of pixels for a tile at the given zoom level

        # Incrementing through the zoom levels and populating the parameter arrays.
        z = tilesize  # The number of pixels per zoom level.
        for i in range(num_zoom):
            # Getting the degrees and radians per pixel, and the 1/2 the number of
            # for every zoom level.
            self._degpp.append(z / 360.)  # degrees per pixel
            self._radpp.append(z / (2 * pi))  # radians per pixel
            self._npix.append(z / 2)  # number of pixels to center of tile

            # Multiplying `z` by 2 for the next iteration.
            z *= 2 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:27,代码来源:zoom.py

示例10: get_zoom

# 需要导入模块: from django.utils.six import moves [as 别名]
# 或者: from django.utils.six.moves import range [as 别名]
def get_zoom(self, geom):
        "Returns the optimal Zoom level for the given geometry."
        # Checking the input type.
        if not isinstance(geom, GEOSGeometry) or geom.srid != 4326:
            raise TypeError('get_zoom() expects a GEOS Geometry with an SRID of 4326.')

        # Getting the envelope for the geometry, and its associated width, height
        # and centroid.
        env = geom.envelope
        env_w, env_h = self.get_width_height(env.extent)
        center = env.centroid

        for z in range(self._nzoom):
            # Getting the tile at the zoom level.
            tile_w, tile_h = self.get_width_height(self.tile(center, z).extent)

            # When we span more than one tile, this is an approximately good
            # zoom level.
            if (env_w > tile_w) or (env_h > tile_h):
                if z == 0:
                    raise GoogleMapException('Geometry width and height should not exceed that of the Earth.')
                return z - 1

        # Otherwise, we've zoomed in to the max.
        return self._nzoom - 1 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:27,代码来源:zoom.py

示例11: get_random_string

# 需要导入模块: from django.utils.six import moves [as 别名]
# 或者: from django.utils.six.moves import range [as 别名]
def get_random_string(length=12,
                      allowed_chars='abcdefghijklmnopqrstuvwxyz'
                                    'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'):
    """
    Returns a securely generated random string.

    The default length of 12 with the a-z, A-Z, 0-9 character set returns
    a 71-bit value. log_2((26+26+10)^12) =~ 71 bits
    """
    if not using_sysrandom:
        # This is ugly, and a hack, but it makes things better than
        # the alternative of predictability. This re-seeds the PRNG
        # using a value that is hard for an attacker to predict, every
        # time a random string is required. This may change the
        # properties of the chosen random sequence slightly, but this
        # is better than absolute predictability.
        random.seed(
            hashlib.sha256(
                ("%s%s%s" % (
                    random.getstate(),
                    time.time(),
                    settings.SECRET_KEY)).encode('utf-8')
            ).digest())
    return ''.join(random.choice(allowed_chars) for i in range(length)) 
开发者ID:Yeah-Kun,项目名称:python,代码行数:26,代码来源:crypto.py

示例12: split_parameter_list_as_sql

# 需要导入模块: from django.utils.six import moves [as 别名]
# 或者: from django.utils.six.moves import range [as 别名]
def split_parameter_list_as_sql(self, compiler, connection):
        # This is a special case for databases which limit the number of
        # elements which can appear in an 'IN' clause.
        max_in_list_size = connection.ops.max_in_list_size()
        lhs, lhs_params = self.process_lhs(compiler, connection)
        rhs, rhs_params = self.batch_process_rhs(compiler, connection)
        in_clause_elements = ['(']
        params = []
        for offset in range(0, len(rhs_params), max_in_list_size):
            if offset > 0:
                in_clause_elements.append(' OR ')
            in_clause_elements.append('%s IN (' % lhs)
            params.extend(lhs_params)
            sqls = rhs[offset: offset + max_in_list_size]
            sqls_params = rhs_params[offset: offset + max_in_list_size]
            param_group = ', '.join(sqls)
            in_clause_elements.append(param_group)
            in_clause_elements.append(')')
            params.extend(sqls_params)
        in_clause_elements.append(')')
        return ''.join(in_clause_elements), params 
开发者ID:Yeah-Kun,项目名称:python,代码行数:23,代码来源:lookups.py

示例13: forms

# 需要导入模块: from django.utils.six import moves [as 别名]
# 或者: from django.utils.six.moves import range [as 别名]
def forms(self):
        """
        Instantiate forms at first property access.
        """
        # DoS protection is included in total_form_count()
        forms = [self._construct_form(i) for i in range(self.total_form_count())]
        return forms 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:9,代码来源:formsets.py

示例14: ordered_forms

# 需要导入模块: from django.utils.six import moves [as 别名]
# 或者: from django.utils.six.moves import range [as 别名]
def ordered_forms(self):
        """
        Returns a list of form in the order specified by the incoming data.
        Raises an AttributeError if ordering is not allowed.
        """
        if not self.is_valid() or not self.can_order:
            raise AttributeError("'%s' object has no attribute 'ordered_forms'" % self.__class__.__name__)
        # Construct _ordering, which is a list of (form_index, order_field_value)
        # tuples. After constructing this list, we'll sort it by order_field_value
        # so we have a way to get to the form indexes in the order specified
        # by the form data.
        if not hasattr(self, '_ordering'):
            self._ordering = []
            for i in range(0, self.total_form_count()):
                form = self.forms[i]
                # if this is an extra form and hasn't changed, don't consider it
                if i >= self.initial_form_count() and not form.has_changed():
                    continue
                # don't add data marked for deletion to self.ordered_data
                if self.can_delete and self._should_delete_form(form):
                    continue
                self._ordering.append((i, form.cleaned_data[ORDERING_FIELD_NAME]))
            # After we're done populating self._ordering, sort it.
            # A sort function to order things numerically ascending, but
            # None should be sorted below anything else. Allowing None as
            # a comparison value makes it so we can leave ordering fields
            # blank.

            def compare_ordering_key(k):
                if k[1] is None:
                    return (1, 0)  # +infinity, larger than any number
                return (0, k[1])
            self._ordering.sort(key=compare_ordering_key)
        # Return a list of form.cleaned_data dicts in the order specified by
        # the form data.
        return [self.forms[i[0]] for i in self._ordering] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:38,代码来源:formsets.py

示例15: full_clean

# 需要导入模块: from django.utils.six import moves [as 别名]
# 或者: from django.utils.six.moves import range [as 别名]
def full_clean(self):
        """
        Cleans all of self.data and populates self._errors and
        self._non_form_errors.
        """
        self._errors = []
        self._non_form_errors = self.error_class()

        if not self.is_bound:  # Stop further processing.
            return
        for i in range(0, self.total_form_count()):
            form = self.forms[i]
            self._errors.append(form.errors)
        try:
            if (self.validate_max and
                    self.total_form_count() - len(self.deleted_forms) > self.max_num) or \
                    self.management_form.cleaned_data[TOTAL_FORM_COUNT] > self.absolute_max:
                raise ValidationError(ungettext(
                    "Please submit %d or fewer forms.",
                    "Please submit %d or fewer forms.", self.max_num) % self.max_num,
                    code='too_many_forms',
                )
            if (self.validate_min and
                    self.total_form_count() - len(self.deleted_forms) < self.min_num):
                raise ValidationError(ungettext(
                    "Please submit %d or more forms.",
                    "Please submit %d or more forms.", self.min_num) % self.min_num,
                    code='too_few_forms')
            # Give self.clean() a chance to do cross-form validation.
            self.clean()
        except ValidationError as e:
            self._non_form_errors = self.error_class(e.error_list) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:34,代码来源:formsets.py


注:本文中的django.utils.six.moves.range方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。