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


Python builtins.range方法代码示例

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


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

示例1: body_encode

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import range [as 别名]
def body_encode(s, maxlinelen=76, eol=NL):
    r"""Encode a string with base64.

    Each line will be wrapped at, at most, maxlinelen characters (defaults to
    76 characters).

    Each line of encoded text will end with eol, which defaults to "\n".  Set
    this to "\r\n" if you will be using the result of this function directly
    in an email.
    """
    if not s:
        return s

    encvec = []
    max_unencoded = maxlinelen * 3 // 4
    for i in range(0, len(s), max_unencoded):
        # BAW: should encode() inherit b2a_base64()'s dubious behavior in
        # adding a newline to the encoded string?
        enc = b2a_base64(s[i:i + max_unencoded]).decode("ascii")
        if enc.endswith(NL) and eol != NL:
            enc = enc[:-1] + eol
        encvec.append(enc)
    return EMPTYSTRING.join(encvec) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:25,代码来源:base64mime.py

示例2: push

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import range [as 别名]
def push(self, data):
        """Push some new data into this object."""
        # Handle any previous leftovers
        data, self._partial = self._partial + data, ''
        # Crack into lines, but preserve the newlines on the end of each
        parts = NLCRE_crack.split(data)
        # The *ahem* interesting behaviour of re.split when supplied grouping
        # parentheses is that the last element of the resulting list is the
        # data after the final RE.  In the case of a NL/CR terminated string,
        # this is the empty string.
        self._partial = parts.pop()
        #GAN 29Mar09  bugs 1555570, 1721862  Confusion at 8K boundary ending with \r:
        # is there a \n to follow later?
        if not self._partial and parts and parts[-1].endswith('\r'):
            self._partial = parts.pop(-2)+parts.pop()
        # parts is a list of strings, alternating between the line contents
        # and the eol character(s).  Gather up a list of lines after
        # re-attaching the newlines.
        lines = []
        for i in range(len(parts) // 2):
            lines.append(parts[i*2] + parts[i*2+1])
        self.pushlines(lines) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:24,代码来源:feedparser.py

示例3: replace_header

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import range [as 别名]
def replace_header(self, _name, _value):
        """Replace a header.

        Replace the first matching header found in the message, retaining
        header order and case.  If no matching header was found, a KeyError is
        raised.
        """
        _name = _name.lower()
        for i, (k, v) in zip(range(len(self._headers)), self._headers):
            if k.lower() == _name:
                self._headers[i] = self.policy.header_store_parse(k, _value)
                break
        else:
            raise KeyError(_name)

    #
    # Use these three methods instead of the three above.
    # 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:20,代码来源:message.py

示例4: unquote

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import range [as 别名]
def unquote(string, encoding='utf-8', errors='replace'):
    """Replace %xx escapes by their single-character equivalent. The optional
    encoding and errors parameters specify how to decode percent-encoded
    sequences into Unicode characters, as accepted by the bytes.decode()
    method.
    By default, percent-encoded sequences are decoded with UTF-8, and invalid
    sequences are replaced by a placeholder character.

    unquote('abc%20def') -> 'abc def'.
    """
    if '%' not in string:
        string.split
        return string
    if encoding is None:
        encoding = 'utf-8'
    if errors is None:
        errors = 'replace'
    bits = _asciire.split(string)
    res = [bits[0]]
    append = res.append
    for i in range(1, len(bits), 2):
        append(unquote_to_bytes(bits[i]).decode(encoding, errors))
        append(bits[i + 1])
    return ''.join(res) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:26,代码来源:parse.py

示例5: run_pipeline

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import range [as 别名]
def run_pipeline():
    for label, subdir in [(VAL_SPLIT, 'SeqVal'), (TRAIN_SPLIT, 'SeqTrain')]:

        # get list of h5 files to preprocess
        h5_files = get_files(subdir, data_dir=FLAGS.data_dir, num_files=FLAGS.h5_files_per_split)
        random.shuffle(h5_files)

        for index in range(0, len(h5_files), BATCHSIZE):

            output_filename = '{}-{:05d}.tfrecord.gz'.format(label, index / BATCHSIZE)
            output_filepath = os.path.join(FLAGS.preproc_output_dir, output_filename)

            upper_index = min(index + BATCHSIZE, len(h5_files))
            some_h5_files = h5_files[index:upper_index]

            write_tfrecord_file(output_filepath, some_h5_files) 
开发者ID:merantix,项目名称:imitation-learning,代码行数:18,代码来源:preprocessor.py

示例6: _bulker

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import range [as 别名]
def _bulker(self, bulk_size):
        """
        Example:
            u = bulker()
            u.send(None)  #for generator initialize
            u.send(json_str)  # input json item
            u.send(another_json_str)  # input json item
            ...
            u.send(None) force finish bulk and post
        """
        while True:
            data = ""
            for i in range(bulk_size):
                item = yield
                if item:
                    data = data + item + "\n"
                else:
                    break
            # print(data)
            print('-'*10)
            if data:
                self._post_to_es(data) 
开发者ID:zhongbiaodev,项目名称:py-mysql-elasticsearch-sync,代码行数:24,代码来源:__init__.py

示例7: contains

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import range [as 别名]
def contains(self, other):
        if isinstance(other, self.__class__):
            if self.is_full() or other.is_empty():
                return True
            return (self.angle().radians >=
                    self.axis().angle(other.axis()) + other.angle().radians)
        elif isinstance(other, Point):
            assert is_unit_length(other)
            return (self.axis() - other).norm2() <= 2 * self.height()
        elif isinstance(other, Cell):
            vertices = []
            for k in range(4):
                vertices.append(other.get_vertex(k))
                if not self.contains(vertices[k]):
                    return False
            return not self.complement().intersects(other, vertices)
        else:
            raise NotImplementedError() 
开发者ID:sidewalklabs,项目名称:s2sphere,代码行数:20,代码来源:sphere.py

示例8: _init_lookup_cell

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import range [as 别名]
def _init_lookup_cell(level, i, j, orig_orientation, pos, orientation):
    if level == LOOKUP_BITS:
        ij = (i << LOOKUP_BITS) + j
        LOOKUP_POS[(ij << 2) + orig_orientation] = (pos << 2) + orientation
        LOOKUP_IJ[(pos << 2) + orig_orientation] = (ij << 2) + orientation
    else:
        level = level + 1
        i <<= 1
        j <<= 1
        pos <<= 2
        r = POS_TO_IJ[orientation]
        for index in range(4):
            _init_lookup_cell(
                level, i + (r[index] >> 1),
                j + (r[index] & 1), orig_orientation,
                pos + index, orientation ^ POS_TO_ORIENTATION[index],
            ) 
开发者ID:sidewalklabs,项目名称:s2sphere,代码行数:19,代码来源:sphere.py

示例9: __get_initial_candidates

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import range [as 别名]
def __get_initial_candidates(self):
        if self.__max_cells >= 4:
            cap = self.__region.get_cap_bound()
            level = min(CellId.min_width().get_max_level(
                        2 * cap.angle().radians),
                        min(self.__max_level, CellId.MAX_LEVEL - 1))

            if self.__level_mod > 1 and level > self.__min_level:
                level -= (level - self.__min_level) % self.__level_mod

            if level > 0:
                cell_id = CellId.from_point(cap.axis())
                vertex_neighbors = cell_id.get_vertex_neighbors(level)
                for neighbor in vertex_neighbors:
                    self.__add_candidate(self.__new_candidate(Cell(neighbor)))
                return

        for face in range(6):
            self.__add_candidate(self.__new_candidate(FACE_CELLS[face])) 
开发者ID:sidewalklabs,项目名称:s2sphere,代码行数:21,代码来源:sphere.py

示例10: download

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import range [as 别名]
def download(self):
        logger.info('Starting to download doujinshi: %s' % self.name)
        if self.downloader:
            download_queue = []

            if len(self.ext) != self.pages:
                logger.warning('Page count and ext count do not equal')

            for i in range(1, min(self.pages, len(self.ext)) + 1):
                download_queue.append('%s/%d/%d.%s' % (IMAGE_URL, int(self.img_id), i, self.ext[i-1]))

            self.downloader.download(download_queue, self.filename)

            '''
            for i in range(len(self.ext)):
                download_queue.append('%s/%d/%d.%s' % (IMAGE_URL, int(self.img_id), i+1, EXT_MAP[self.ext[i]]))
            '''

        else:
            logger.critical('Downloader has not been loaded') 
开发者ID:RicterZ,项目名称:nhentai,代码行数:22,代码来源:doujinshi.py

示例11: test_slice_range

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import range [as 别名]
def test_slice_range(self):
        r = range(8)
        self.assertEqual(r[:], range(8))
        self.assertEqual(r[:2], range(2))
        self.assertEqual(r[:-2], range(6))
        self.assertEqual(r[2:], range(2, 8))
        self.assertEqual(r[-2:], range(6, 8))
        self.assertEqual(r[2:-2], range(2, 6))
        self.assertEqual(r[-2:2:-1], range(6, 2, -1))
        r = r[::-1]
        self.assertEqual(r, range(7, -1, -1))
        self.assertEqual(r[:], range(7, -1, -1))
        self.assertEqual(r[:2], range(7, 5, -1))
        self.assertEqual(r[:-2], range(7, 1, -1))
        self.assertEqual(r[2:], range(5, -1, -1))
        self.assertEqual(r[-2:], range(1, -1, -1))
        self.assertEqual(r[2:-2], range(5, 1, -1))
        self.assertEqual(r[-2:2:-1], range(1, 5)) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:20,代码来源:test_range.py

示例12: test_unquoting

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import range [as 别名]
def test_unquoting(self):
        # Make sure unquoting of all ASCII values works
        escape_list = []
        for num in range(128):
            given = hexescape(chr(num))
            expect = chr(num)
            result = urllib_parse.unquote(given)
            self.assertEqual(expect, result,
                             "using unquote(): %r != %r" % (expect, result))
            result = urllib_parse.unquote_plus(given)
            self.assertEqual(expect, result,
                             "using unquote_plus(): %r != %r" %
                             (expect, result))
            escape_list.append(given)
        escape_string = ''.join(escape_list)
        del escape_list
        result = urllib_parse.unquote(escape_string)
        self.assertEqual(result.count('%'), 1,
                         "using unquote(): not all characters escaped: "
                         "%s" % result)
        self.assertRaises((TypeError, AttributeError), urllib_parse.unquote, None)
        self.assertRaises((TypeError, AttributeError), urllib_parse.unquote, ())
        with support.check_warnings(('', BytesWarning), quiet=True):
            self.assertRaises((TypeError, AttributeError), urllib_parse.unquote, bytes(b'')) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:26,代码来源:test_urllib.py

示例13: test_escape_path

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import range [as 别名]
def test_escape_path(self):
        cases = [
            # quoted safe
            ("/foo%2f/bar", "/foo%2F/bar"),
            ("/foo%2F/bar", "/foo%2F/bar"),
            # quoted %
            ("/foo%%/bar", "/foo%%/bar"),
            # quoted unsafe
            ("/fo%19o/bar", "/fo%19o/bar"),
            ("/fo%7do/bar", "/fo%7Do/bar"),
            # unquoted safe
            ("/foo/bar&", "/foo/bar&"),
            ("/foo//bar", "/foo//bar"),
            ("\176/foo/bar", "\176/foo/bar"),
            # unquoted unsafe
            ("/foo\031/bar", "/foo%19/bar"),
            ("/\175foo/bar", "/%7Dfoo/bar"),
            # unicode, latin-1 range
            ("/foo/bar\u00fc", "/foo/bar%C3%BC"),     # UTF-8 encoded
            # unicode
            ("/foo/bar\uabcd", "/foo/bar%EA%AF%8D"),  # UTF-8 encoded
            ]
        for arg, result in cases:
            self.assertEqual(escape_path(arg), result) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:26,代码来源:test_http_cookiejar.py

示例14: _append_chunk

# 需要导入模块: from future import builtins [as 别名]
# 或者: from future.builtins import range [as 别名]
def _append_chunk(self, fws, string):
        self._current_line.push(fws, string)
        if len(self._current_line) > self._maxlen:
            # Find the best split point, working backward from the end.
            # There might be none, on a long first line.
            for ch in self._splitchars:
                for i in range(self._current_line.part_count()-1, 0, -1):
                    if ch.isspace():
                        fws = self._current_line[i][0]
                        if fws and fws[0]==ch:
                            break
                    prevpart = self._current_line[i-1][1]
                    if prevpart and prevpart[-1]==ch:
                        break
                else:
                    continue
                break
            else:
                fws, part = self._current_line.pop()
                if self._current_line._initial_size > 0:
                    # There will be a header, so leave it on a line by itself.
                    self.newline()
                    if not fws:
                        # We don't use continuation_ws here because the whitespace
                        # after a header should always be a space.
                        fws = ' '
                self._current_line.push(fws, part)
                return
            remainder = self._current_line.pop_from(i)
            self._lines.append(str(self._current_line))
            self._current_line.reset(remainder) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:33,代码来源:header.py


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