text stringlengths 81 112k |
|---|
Change the stream position to the given byte offset.
Args:
offset: Offset is interpreted relative to the position indicated by
whence.
whence: The default value for whence is SEEK_SET.
Values for whence are:
SEEK_SET or 0 – start of the st... |
Write the given bytes-like object, b, to the underlying raw stream,
and return the number of bytes written.
Args:
b (bytes-like object): Bytes to write.
Returns:
int: The number of bytes written.
def write(self, b):
"""
Write the given bytes-like object... |
When creating a QR code only the content to be encoded is required,
all the other properties of the code will be guessed based on the
contents given. This function will return a :class:`QRCode` object.
Unless you are familiar with QR code's inner workings
it is recommended that you just specify the *co... |
This method tries to auto-detect the type of the data. It first
tries to see if the data is a valid integer, in which case it returns
numeric. Next, it tests the data to see if it is 'alphanumeric.' QR
Codes use a special table with very limited range of ASCII characters.
The code's data... |
This method return the smallest possible QR code version number
that will fit the specified data with the given error level.
def _pick_best_fit(self, content):
"""This method return the smallest possible QR code version number
that will fit the specified data with the given error level.
... |
Displays this QR code.
This method is mainly intended for debugging purposes.
This method saves the output of the :py:meth:`png` method (with a default
scaling factor of 10) to a temporary file and opens it with the
standard PNG viewer application or within the standard webbrowser. The... |
This is method helps users determine what *scale* to use when
creating a PNG of this QR code. It is meant mostly to be used in the
console to help the user determine the pixel size of the code
using various scales.
This method will return an integer representing the width and height of
... |
This method writes the QR code out as an PNG image. The resulting
PNG has a bit depth of 1. The file parameter is used to specify where
to write the image to. It can either be an writable stream or a
file path.
.. note::
This method depends on the pypng module to actually cr... |
This method uses the png render and returns the PNG image encoded as
base64 string. This can be useful for creating dynamic PNG images for
web development, since no file needs to be created.
Example:
>>> code = pyqrcode.create('Are you suggesting coconuts migrate?')
... |
Returns a string representing an XBM image of the QR code.
The XBM format is a black and white image format that looks like a
C header file.
Because displaying QR codes in Tkinter is the
primary use case for this renderer, this method does not take a file
parameter. Ins... |
This method writes the QR code out as an SVG document. The
code is drawn by drawing only the modules corresponding to a 1. They
are drawn using a line, such that contiguous modules in a row
are drawn with a single line.
The *file* parameter is used to specify where to write the document... |
This method writes the QR code out as an EPS document. The
code is drawn by only writing the data modules corresponding to a 1.
They are drawn using a line, such that contiguous modules in a row
are drawn with a single line.
The *file* parameter is used to specify where to write the doc... |
This method returns a string containing ASCII escape codes,
such that if printed to a compatible terminal, it will display
a vaild QR code. The code is printed using ASCII escape
codes that alter the coloring of the background.
The *module_color* parameter sets what color to
use... |
This method returns a tuple containing the stream and a flag to indicate
if the stream should be automatically closed.
The `stream_or_path` parameter is returned if it is an open writable stream.
Otherwise, it treats the `stream_or_path` parameter as a file path and
opens it with the given mode.
I... |
See: QRCode.get_png_size
This function was abstracted away from QRCode to allow for the output of
QR codes during the build process, i.e. for debugging. It works
just the same except you must specify the code's version. This is needed
to calculate the PNG's size.
def _get_png_size(version, scale, quie... |
This method returns a string containing ASCII escape codes,
such that if printed to a terminal, it will display a vaild
QR code. The module_color and the background color should be keys
in the tables.term_colors table for printing using the 8/16
color scheme. Alternatively, they can be a number between ... |
This method returns a text based representation of the QR code.
This is useful for debugging purposes.
def _text(code, quiet_zone=4):
"""This method returns a text based representation of the QR code.
This is useful for debugging purposes.
"""
buf = io.StringIO()
border_row = '0' * (len(code[0... |
This function will format the QR code as a X BitMap.
This can be used to display the QR code with Tkinter.
def _xbm(code, scale=1, quiet_zone=4):
"""This function will format the QR code as a X BitMap.
This can be used to display the QR code with Tkinter.
"""
try:
str = unicode # Python 2
... |
This function writes the QR code out as an SVG document. The
code is drawn by drawing only the modules corresponding to a 1. They
are drawn using a line, such that contiguous modules in a row
are drawn with a single line. The file parameter is used to
specify where to write the document to. It can eithe... |
See: pyqrcode.QRCode.png()
This function was abstracted away from QRCode to allow for the output of
QR codes during the build process, i.e. for debugging. It works
just the same except you must specify the code's version. This is needed
to calculate the PNG's size.
This method will write the given... |
This function writes the QR code out as an EPS document. The
code is drawn by drawing only the modules corresponding to a 1. They
are drawn using a line, such that contiguous modules in a row
are drawn with a single line. The file parameter is used to
specify where to write the document to. It can eithe... |
\
Helper function to convert a color provided in hexadecimal format
as RGB triple.
def _hex_to_rgb(color):
"""\
Helper function to convert a color provided in hexadecimal format
as RGB triple.
"""
if color[0] == '#':
color = color[1:]
if len(color) == 3:
color = color[0]... |
This generator yields a set of tuples, where the
iterable is broken into n sized chunks. If the
iterable is not evenly sized then fillvalue will
be appended to the last tuple to make up the difference.
This function is copied from the standard docs on
itertools.
def grouper(sel... |
QR codes contain a "data length" field. This method creates this
field. A binary string representing the appropriate length is
returned.
def get_data_length(self):
"""QR codes contain a "data length" field. This method creates this
field. A binary string representing the appropriate len... |
This method encodes the data into a binary string using
the appropriate algorithm specified by the mode.
def encode(self):
"""This method encodes the data into a binary string using
the appropriate algorithm specified by the mode.
"""
if self.mode == tables.modes['alphanumeric']... |
This method encodes the QR code's data if its mode is
alphanumeric. It returns the data encoded as a binary string.
def encode_alphanumeric(self):
"""This method encodes the QR code's data if its mode is
alphanumeric. It returns the data encoded as a binary string.
"""
#Convert ... |
This method encodes the QR code's data if its mode is
numeric. It returns the data encoded as a binary string.
def encode_numeric(self):
"""This method encodes the QR code's data if its mode is
numeric. It returns the data encoded as a binary string.
"""
with io.StringIO() as bu... |
This method encodes the QR code's data if its mode is
8 bit mode. It returns the data encoded as a binary string.
def encode_bytes(self):
"""This method encodes the QR code's data if its mode is
8 bit mode. It returns the data encoded as a binary string.
"""
with io.StringIO() a... |
This method encodes the QR code's data if its mode is
kanji. It returns the data encoded as a binary string.
def encode_kanji(self):
"""This method encodes the QR code's data if its mode is
kanji. It returns the data encoded as a binary string.
"""
def two_bytes(data):
... |
This function properly constructs a QR code's data string. It takes
into account the interleaving pattern required by the standard.
def add_data(self):
"""This function properly constructs a QR code's data string. It takes
into account the interleaving pattern required by the standard.
... |
This method adds zeros to the end of the encoded data so that the
encoded data is of the correct length. It returns a binary string
containing the bits to be added.
def terminate_bits(self, payload):
"""This method adds zeros to the end of the encoded data so that the
encoded data is of... |
This method takes the existing encoded binary string
and returns a binary string that will pad it such that
the encoded string contains only full bytes.
def delimit_words(self):
"""This method takes the existing encoded binary string
and returns a binary string that will pad it such tha... |
The data block must fill the entire data capacity of the QR code.
If we fall short, then we must add bytes to the end of the encoded
data field. The value of these bytes are specified in the standard.
def add_words(self):
"""The data block must fill the entire data capacity of the QR code.
... |
This function constructs the error correction block of the
given data block. This is *very complicated* process. To
understand the code you need to read:
* http://www.thonky.com/qr-code-tutorial/part-2-error-correction/
* http://www.matchadesign.com/blog/qr-code-demystified-part-4/
def... |
This method returns the best possible QR code.
def make_code(self):
"""This method returns the best possible QR code."""
from copy import deepcopy
#Get the size of the underlying matrix
matrix_size = tables.version_size[self.version]
#Create a template matrix we will build the... |
This method add the detection patterns to the QR code. This lets
the scanner orient the pattern. It is required for all QR codes.
The detection pattern consists of three boxes located at the upper
left, upper right, and lower left corners of the matrix. Also, two
special lines called the... |
This method draws the position adjustment patterns onto the QR
Code. All QR code versions larger than one require these special boxes
called position adjustment patterns.
def add_position_pattern(self, m):
"""This method draws the position adjustment patterns onto the QR
Code. All QR co... |
For QR codes with a version 7 or higher, a special pattern
specifying the code's version is required.
For further information see:
http://www.thonky.com/qr-code-tutorial/format-version-information/#example-of-version-7-information-string
def add_version_pattern(self, m):
"""For QR code... |
This method generates all seven masks so that the best mask can
be determined. The template parameter is a code matrix that will
server as the base for all the generated masks.
def make_masks(self, template):
"""This method generates all seven masks so that the best mask can
be determin... |
This method returns the index of the "best" mask as defined by
having the lowest total penalty score. The penalty rules are defined
by the standard. The mask with the lowest total score should be the
easiest to read by optical scanners.
def choose_best_mask(self):
"""This method returns... |
This will add the pattern to the QR code that represents the error
level and the type of mask used to make the code.
def add_type_pattern(self, m, type_bits):
"""This will add the pattern to the QR code that represents the error
level and the type of mask used to make the code.
"""
... |
split a list of closed issues into non-PR Issues and Pull Requests
def split_pulls(all_issues, project="arokem/python-matlab-bridge"):
"""split a list of closed issues into non-PR Issues and Pull Requests"""
pulls = []
issues = []
for i in all_issues:
if is_pull_request(i):
pull = g... |
Get all issues closed since a particular point in time. period
can either be a datetime object, or a timedelta object. In the
latter case, it is used as a time before the present.
def issues_closed_since(period=timedelta(days=365), project="arokem/python-matlab-bridge", pulls=False):
"""Get all issues clos... |
Return a list of issues sorted by closing date date.
def sorted_by_field(issues, field='closed_at', reverse=False):
"""Return a list of issues sorted by closing date date."""
return sorted(issues, key = lambda i:i[field], reverse=reverse) |
Summary report about a list of issues, printing number and title.
def report(issues, show_urls=False):
"""Summary report about a list of issues, printing number and title.
"""
# titles may have unicode in them, so we must encode everything below
if show_urls:
for i in issues:
print(... |
Write a numpy array and its shape to base64 buffers
def encode_ndarray(obj):
"""Write a numpy array and its shape to base64 buffers"""
shape = obj.shape
if len(shape) == 1:
shape = (1, obj.shape[0])
if obj.flags.c_contiguous:
obj = obj.T
elif not obj.flags.f_contiguous:
obj ... |
Extract a numpy array from a base64 buffer
def decode_arr(data):
"""Extract a numpy array from a base64 buffer"""
data = data.encode('utf-8')
return frombuffer(base64.b64decode(data), float64) |
Run a function in Matlab and return the result.
Parameters
----------
func_path: str
Name of function to run or a path to an m-file.
func_args: object, optional
Function args to send to the function.
nargout: int, optional
Desired number of re... |
Generate a Matlab function and bind it to the instance
This is where the magic happens. When an unknown attribute of the
Matlab class is requested, it is assumed to be a call to a
Matlab function, and is generated and bound to the instance.
This works because getattr() falls back to __... |
Format a line of Matlab into either a markdown line or a code line.
Parameters
----------
line : str
The line of code to be formatted. Formatting occurs according to the
following rules:
- If the line starts with (at least) two %% signs, a new cell will be
started.
... |
Convert the lines of an m file into an IPython notebook
Parameters
----------
lines : list
A list of strings. Each element is a line in the m file
Returns
-------
notebook : an IPython NotebookNode class instance, containing the
information required to create a file
def lines_to_n... |
Convert a Matlab m-file into a Matlab notebook in ipynb format
Parameters
----------
mfile : string
Full path to a matlab m file to convert
outfile : string (optional)
Full path to the output ipynb file
def convert_mfile(mfile, outfile=None):
"""
Convert a Matlab m-file into a... |
Load the extension in IPython.
def load_ipython_extension(ip, **kwargs):
"""Load the extension in IPython."""
global _loaded
if not _loaded:
ip.register_magics(MatlabMagics(ip, **kwargs))
_loaded = True |
Post some text to a Gist, and return the URL.
def post_gist(content, description='', filename='file', auth=False):
"""Post some text to a Gist, and return the URL."""
post_data = json.dumps({
"description": description,
"public": True,
"files": {
filename: {
"content": conte... |
get pull request info by number
def get_pull_request(project, num, auth=False):
"""get pull request info by number
"""
url = "https://api.github.com/repos/{project}/pulls/{num}".format(project=project, num=num)
if auth:
header = make_auth_header()
else:
header = None
response ... |
get list of files in a pull request
def get_pull_request_files(project, num, auth=False):
"""get list of files in a pull request"""
url = "https://api.github.com/repos/{project}/pulls/{num}/files".format(project=project, num=num)
if auth:
header = make_auth_header()
else:
header = None
... |
get a full list, handling APIv3's paging
def get_paged_request(url, headers=None, **params):
"""get a full list, handling APIv3's paging"""
results = []
params.setdefault("per_page", 100)
while True:
if '?' in url:
params = None
print("fetching %s" % url, file=sys.stderr... |
get pull request list
def get_pulls_list(project, auth=False, **params):
"""get pull request list"""
params.setdefault("state", "closed")
url = "https://api.github.com/repos/{project}/pulls".format(project=project)
if auth:
headers = make_auth_header()
else:
headers = None
pages... |
Encode a dictionary of ``fields`` using the multipart/form-data mime format.
:param fields:
Dictionary of fields or list of (key, value) field tuples. The key is
treated as the field name, and the value as the body of the form-data
bytes. If the value is a tuple of two elements, then the f... |
Upload a file to the GitHub downloads area
def post_download(project, filename, name=None, description=""):
"""Upload a file to the GitHub downloads area"""
if name is None:
name = os.path.basename(filename)
with open(filename, 'rb') as f:
filedata = f.read()
url = "https://api.github.... |
Checks that path is an executable regular file (or a symlink to a file).
This is roughly ``os.path isfile(path) and os.access(path, os.X_OK)``, but
on some platforms :func:`os.access` gives us the wrong answer, so this
checks permission bits directly.
Note
----
This function is taken from the ... |
This takes a given filename; tries to find it in the environment path;
then checks if it is executable. This returns the full path to the filename
if found and executable. Otherwise this returns None.
Note
----
This function is taken from the pexpect module, see module doc-string for
license.
... |
build the messenger mex for MATLAB
static : bool
Determines if the zmq library has been statically linked.
If so, it will append the command line option -DZMQ_STATIC
when compiling the mex so it matches libzmq.
def build_matlab(static=False):
"""build the messenger mex for MATLAB
... |
Add an existing function to a class as a method.
Note: Consider using the extend decorator as a more readable alternative
to using this function directly.
Args:
function: The function to be added to the class klass.
klass: The class to which the new method will be added.
... |
A function decorator for extending an existing class.
Use as a decorator for functions to add to an existing class.
Args:
klass: The class to be decorated.
name: The name the new method is to be given in the klass class.
Returns:
A decorator function which accepts a sin... |
Transforms each element of a sequence into a new form.
Each element of the source is transformed through a selector function
to produce a corresponding element in teh result sequence.
If the selector is identity the method will return self.
Note: This method uses deferred execution.
... |
Transforms each element of a sequence into a new form, incorporating
the index of the element.
Each element is transformed through a selector function which accepts
the element value and its zero-based index in the source sequence. The
generated sequence is lazily evaluated.
No... |
Apply a callable to each element in an input sequence, generating a new
sequence of 2-tuples where the first element is the input value and the
second is the transformed input value.
The generated sequence is lazily evaluated.
Note: This method uses deferred execution.
Args:
... |
Projects each element of a sequence to an intermediate new sequence,
flattens the resulting sequences into one sequence and optionally
transforms the flattened sequence using a selector function.
Note: This method uses deferred execution.
Args:
collection_selector: A unary ... |
Projects each element of a sequence to an intermediate new sequence,
incorporating the index of the element, flattens the resulting sequence
into one sequence and optionally transforms the flattened sequence
using a selector function.
Note: This method uses deferred execution.
... |
Projects each element of a sequence to an intermediate new sequence,
and flattens the resulting sequence, into one sequence and uses a
selector function to incorporate the corresponding source for each item
in the result sequence.
Note: This method uses deferred execution.
Args... |
Groups the elements according to the value of a key extracted by a
selector function.
Note: This method has different behaviour to itertools.groupby in the
Python standard library because it aggregates all items with the
same key, rather than returning groups of consecutive item... |
Filters elements according to whether they match a predicate.
Note: This method uses deferred execution.
Args:
predicate: A unary function which is applied to each element in the
source sequence. Source elements for which the predicate
returns True will be p... |
Filters elements according to whether they are of a certain type.
Note: This method uses deferred execution.
Args:
classinfo: If classinfo is neither a class object nor a type object
it may be a tuple of class or type objects, or may recursively
contain othe... |
Sorts by a key in ascending order.
Introduces a primary sorting order to the sequence. Additional sort
criteria should be specified by subsequent calls to then_by() and
then_by_descending(). Calling order_by() or order_by_descending() on
the results of a call to order_by() will introdu... |
Returns a specified number of elements from the start of a sequence.
If the source sequence contains fewer elements than requested only the
available elements will be returned and no exception will be raised.
Note: This method uses deferred execution.
Args:
count: An optio... |
Returns elements from the start while the predicate is True.
Note: This method uses deferred execution.
Args:
predicate: A function returning True or False with which elements
will be tested.
Returns:
A Queryable over the elements from the beginning of ... |
Skip the first count contiguous elements of the source sequence.
If the source sequence contains fewer than count elements returns an
empty sequence and does not raise an exception.
Note: This method uses deferred execution.
Args:
count: The number of elements to skip from... |
Omit elements from the start for which a predicate is True.
Note: This method uses deferred execution.
Args:
predicate: A single argument predicate function.
Returns:
A Queryable over the sequence of elements beginning with the first
element for which the p... |
Concatenates two sequences.
Note: This method uses deferred execution.
Args:
second_iterable: The sequence to concatenate on to the sequence.
Returns:
A Queryable over the concatenated sequences.
Raises:
ValueError: If the Queryable is closed().
... |
Returns the sequence reversed.
Note: This method uses deferred execution, but the whole source
sequence is consumed once execution commences.
Returns:
The source sequence in reverse order.
Raises:
ValueError: If the Queryable is closed().
def reverse(self)... |
Return the element at ordinal index.
Note: This method uses immediate execution.
Args:
index: The index of the element to be returned.
Returns:
The element at ordinal index in the source sequence.
Raises:
ValueError: If the Queryable is closed().
... |
Return the number of elements (which match an optional predicate).
Note: This method uses immediate execution.
Args:
predicate: An optional unary predicate function used to identify
elements which will be counted. The single positional argument
of the functi... |
Determine if the source sequence contains any elements which satisfy
the predicate.
Only enough of the sequence to satisfy the predicate once is consumed.
Note: This method uses immediate execution.
Args:
predicate: An optional single argument function used to test each
... |
Determine if all elements in the source sequence satisfy a condition.
All of the source sequence will be consumed.
Note: This method uses immediate execution.
Args:
predicate (callable): An optional single argument function used to
test each elements. If omitted, t... |
Return the arithmetic sum of the values in the sequence..
All of the source sequence will be consumed.
Note: This method uses immediate execution.
Args:
selector: An optional single argument function which will be used
to project the elements of the sequence. If om... |
Return the arithmetic mean of the values in the sequence..
All of the source sequence will be consumed.
Note: This method uses immediate execution.
Args:
selector: An optional single argument function which will be used
to project the elements of the sequence. If o... |
Determines whether the sequence contains a particular value.
Execution is immediate. Depending on the type of the sequence, all or
none of the sequence may be consumed by this operation.
Note: This method uses immediate execution.
Args:
value: The value to test for members... |
If the source sequence is empty return a single element sequence
containing the supplied default value, otherwise return the source
sequence unchanged.
Note: This method uses deferred execution.
Args:
default: The element to be returned if the source sequence is empty.
... |
Eliminate duplicate elements from a sequence.
Note: This method uses deferred execution.
Args:
selector: An optional single argument function the result of which
is the value compared for uniqueness against elements already
consumed. If omitted, the element ... |
Returns those elements which are in the source sequence which are not
in the second_iterable.
This method is equivalent to the Except() LINQ operator, renamed to a
valid Python identifier.
Note: This method uses deferred execution, but as soon as execution
commences the ent... |
Returns those elements which are both in the source sequence and in
the second_iterable.
Note: This method uses deferred execution.
Args:
second_iterable: Elements are returned if they are also in the
sequence.
selector: An optional single argument func... |
Returns those elements which are either in the source sequence or in
the second_iterable, or in both.
Note: This method uses deferred execution.
Args:
second_iterable: Elements from this sequence are returns if they
are not also in the source sequence.
... |
Perform an inner join with a second sequence using selected keys.
The order of elements from outer is maintained. For each of these the
order of elements from inner is also preserved.
Note: This method uses deferred execution.
Args:
inner_iterable: The sequence to join wit... |
Match elements of two sequences using keys and group the results.
The group_join() query produces a hierarchical result, with all of the
inner elements in the result grouped against the matching outer
element.
The order of elements from outer is maintained. For each of these the
... |
The first element in a sequence (optionally satisfying a predicate).
If the predicate is omitted or is None this query returns the first
element in the sequence; otherwise, it returns the first element in
the sequence for which the predicate evaluates to True. Exceptions are
raised if t... |
The first element (optionally satisfying a predicate) or a default.
If the predicate is omitted or is None this query returns the first
element in the sequence; otherwise, it returns the first element in
the sequence for which the predicate evaluates to True. If there is no
such element... |
The only element (which satisfies a condition).
If the predicate is omitted or is None this query returns the only
element in the sequence; otherwise, it returns the only element in
the sequence for which the predicate evaluates to True. Exceptions are
raised if there is either no such ... |
The only element (which satisfies a condition) or a default.
If the predicate is omitted or is None this query returns the only
element in the sequence; otherwise, it returns the only element in
the sequence for which the predicate evaluates to True. A default value
is returned if there... |
The last element in a sequence (optionally satisfying a predicate).
If the predicate is omitted or is None this query returns the last
element in the sequence; otherwise, it returns the last element in
the sequence for which the predicate evaluates to True. Exceptions are
raised if ther... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.