def iter_pages(self, left_edge=2, left_current=2, right_current=5, right_edge=2): """Iterates over the page numbers in the pagination. The four parameters control the thresholds how many numbers should be produced from the sides. Skipped page numbers are represented as `None`. This is how you could render such a pagination in the templates: .. sourcecode:: html+jinja {% macro render_pagination(pagination, endpoint) %} <div class=pagination> {%- for page in pagination.iter_pages() %} {% if page %} {% if page != pagination.page %} <a href="{{ url_for(endpoint, page=page) }}">{{ page }}</a> {% else %} <strong>{{ page }}</strong> {% endif %} {% else %} <span class=ellipsis>...</span> {% endif %} {%- endfor %} </div> {% endmacro %} """ last = 0 for num in range_type(1, self.pages + 1): # pylint: disable=chained-comparison if num <= left_edge or \ (num > self.page - left_current - 1 and num < self.page + right_current) or \ num > self.pages - right_edge: if last + 1 != num: yield None yield num last = num
def iter_dotted_path_prefixes(dotted_path): pieces = dotted_path.split('.') if len(pieces) == 1: yield dotted_path, None else: for x in range_type(1, len(pieces)): yield '.'.join(pieces[:x]), '.'.join(pieces[x:])
def iter_pages(self, left_edge=2, left_current=2, right_current=5, right_edge=2): """Iterates over the page numbers in the pagination. The four parameters control the thresholds how many numbers should be produced from the sides. Skipped page numbers are represented as `None`. This is how you could render such a pagination in the templates: .. sourcecode:: html+jinja {% macro render_pagination(pagination, endpoint) %} <div class=pagination> {%- for page in pagination.iter_pages() %} {% if page %} {% if page != pagination.page %} <a href="{{ url_for(endpoint, page=page) }}">{{ page }}</a> {% else %} <strong>{{ page }}</strong> {% endif %} {% else %} <span class=ellipsis>...</span> {% endif %} {%- endfor %} </div> {% endmacro %} """ last = 0 for num in range_type(1, self.pages + 1): if num <= left_edge or \ (num > self.page - left_current - 1 and num < self.page + right_current) or \ num > self.pages - right_edge: if last + 1 != num: yield None yield num last = num
def iter_pages(self, left_edge=2, left_current=2, right_current=5, right_edge=2): """Iterate over the page numbers in the pagination, with elision. In the general case, this returns the concatenation of three ranges: 1. A range (always starting at page one) at the beginning of the page number sequence. The length of the this range is specified by the ``left_edge`` argument (which may be zero). 2. A range around the current page. This range will include ``left_current`` pages before, and ``right_current`` pages after the current page. This range always includes the current page. 3. Finally, a range (always ending at the last page) at the end of the page sequence. The length of this range is specified by the ``right_edge`` argument. If any of these ranges overlap, they will be merged. A ``None`` will be inserted between non-overlapping ranges to signify that pages have been elided. This is how you could render such a pagination in the templates: .. sourcecode:: html+jinja {% macro render_pagination(pagination, endpoint) %} <div class=pagination> {%- for page in pagination.iter_pages() %} {% if page %} {% if page != pagination.page %} <a href="{{ url_for(endpoint, page=page) }}">{{ page }}</a> {% else %} <strong>{{ page }}</strong> {% endif %} {% else %} <span class=ellipsis>...</span> {% endif %} {%- endfor %} </div> {% endmacro %} """ last = 0 for num in range_type(1, self.pages + 1): # pylint: disable=chained-comparison if (num <= left_edge or (num >= self.page - left_current and num <= self.page + right_current) or num > self.pages - right_edge): if last + 1 != num: yield None yield num last = num if last != self.pages: yield None
def _write_ssh_key_file(temp_fn, credentials): if credentials: key_file = credentials.get('key_file') if key_file is not None: return key_file key = credentials.get('key') if key: parts = key.split(':', 1) if len(parts) == 1: kt = 'RSA' else: kt, key = parts with open(temp_fn, 'wb') as f: f.write(b'-----BEGIN %s PRIVATE KEY-----\n' % kt.upper()) for x in range_type(0, len(key), 64): f.write(key[x:x + 64].encode('utf-8') + b'\n') f.write(b'-----END %s PRIVATE KEY-----\n' % kt.upper()) os.chmod(temp_fn, 0o600) return temp_fn
def _write_ssh_key_file(temp_fn, credentials): if credentials: key_file = credentials.get('key_file') if key_file is not None: return key_file key = credentials.get('key') if key: parts = key.split(':', 1) if len(parts) == 1: kt = 'RSA' else: kt, key = parts with open(temp_fn, 'w') as f: f.write('-----BEGIN %s PRIVATE KEY-----\n' % kt.upper()) for x in range_type(0, len(key), 64): f.write(key[x:x + 64] + '\n') f.write('-----END %s PRIVATE KEY-----\n' % kt.upper()) os.chmod(temp_fn, 0o600) return temp_fn
def _write_ssh_key_file(temp_fn, credentials): if credentials: key_file = credentials.get("key_file") if key_file is not None: return key_file key = credentials.get("key") if key: parts = key.split(":", 1) if len(parts) == 1: kt = "RSA" else: kt, key = parts with open(temp_fn, "wb") as f: f.write(b"-----BEGIN %s PRIVATE KEY-----\n" % kt.upper()) for x in range_type(0, len(key), 64): f.write(key[x : x + 64].encode("utf-8") + b"\n") f.write(b"-----END %s PRIVATE KEY-----\n" % kt.upper()) os.chmod(temp_fn, 0o600) return temp_fn
def _write_ssh_key_file(temp_fn, credentials): if credentials: key_file = credentials.get("key_file") if key_file is not None: return key_file key = credentials.get("key") if key: parts = key.split(":", 1) if len(parts) == 1: kt = "RSA" else: kt, key = parts with open(temp_fn, "w") as f: f.write("-----BEGIN %s PRIVATE KEY-----\n" % kt.upper()) for x in range_type(0, len(key), 64): f.write(key[x : x + 64] + "\n") f.write("-----END %s PRIVATE KEY-----\n" % kt.upper()) os.chmod(temp_fn, 0o600) return temp_fn return None
def _iter_paginated_children(self): total = self.source.datamodel.pagination_config.count_pages( self.source) for page_num in range_type(1, total + 1): yield Page(self.source.pad, self.source._data, page_num=page_num)
def _iter_paginated_children(self): total = self.source.datamodel.pagination_config.count_pages(self.source) for page_num in range_type(1, total + 1): yield Page(self.source.pad, self.source._data, page_num=page_num)