code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
return self._system.stat(
path=self._path, client_kwargs=self._client_kwargs,
header=self._header) | def stat(self, follow_symlinks=True) | Return a stat_result object for this entry.
The result is cached on the os.DirEntry object.
Args:
follow_symlinks (bool): Follow symlinks.
Not supported on cloud storage objects.
Returns:
os.stat_result: Stat result object | 10.862972 | 13.115683 | 0.828243 |
if self._writable and not self._closed:
self._closed = True
with self._seek_lock:
self._flush_raw_or_buffered()
if self._seek:
with handle_os_exceptions():
self._close_writable() | def close(self) | Flush the write buffers of the stream if applicable and
close the object. | 9.718738 | 9.101398 | 1.067829 |
if self._writable:
with self._seek_lock:
self._flush_raw_or_buffered()
# Clear the buffer
self._write_buffer = bytearray(self._buffer_size)
self._buffer_seek = 0 | def flush(self) | Flush the write buffers of the stream if applicable. | 7.60307 | 6.536467 | 1.163177 |
# Flush only if bytes written
# This avoid no required process/thread
# creation and network call.
# This step is performed by raw stream.
if self._buffer_seek and self._seek:
self._seek += 1
with handle_os_exceptions():
self._flus... | def _flush_raw_or_buffered(self) | Flush using raw of buffered methods. | 12.861297 | 12.024209 | 1.069617 |
if not self._readable:
raise UnsupportedOperation('read')
with self._seek_lock:
self._raw.seek(self._seek)
return self._raw._peek(size) | def peek(self, size=-1) | Return bytes from the stream without advancing the position.
Args:
size (int): Number of bytes to read. -1 to read the full
stream.
Returns:
bytes: bytes read | 6.827673 | 7.571839 | 0.901719 |
queue = self._read_queue
size = self._buffer_size
start = self._seek
end = int(start + size * self._max_buffers)
workers_submit = self._workers.submit
indexes = tuple(range(start, end, size))
# Drops buffer out of current range
for seek in tuple(... | def _preload_range(self) | Preload data for reading | 5.700174 | 5.550688 | 1.026931 |
if not self._readable:
raise UnsupportedOperation('read')
# Checks if EOF
if self._seek == self._size:
return b''
# Returns existing buffer with no copy
if size == self._buffer_size:
queue_index = self._seek
# Starts ini... | def read(self, size=-1) | Read and return up to size bytes,
with at most one call to the underlying raw stream’s.
Use at most one call to the underlying raw stream’s read method.
Args:
size (int): Number of bytes to read. -1 to read the
stream until end.
Returns:
bytes: ... | 5.404082 | 5.505923 | 0.981503 |
if not self._readable:
raise UnsupportedOperation('read')
with self._seek_lock:
# Gets seek
seek = self._seek
# Initializes queue
queue = self._read_queue
if seek == 0:
# Starts initial preloading on first... | def readinto(self, b) | Read bytes into a pre-allocated, writable bytes-like object b,
and return the number of bytes read.
Args:
b (bytes-like object): buffer.
Returns:
int: number of bytes read | 4.653591 | 4.768183 | 0.975967 |
if not self._seekable:
raise UnsupportedOperation('seek')
# Only read mode is seekable
with self._seek_lock:
# Set seek using raw method and
# sync buffered seek with raw seek
self.raw.seek(offset, whence)
self._seek = seek = ... | def seek(self, offset, whence=SEEK_SET) | 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... | 10.896214 | 12.662985 | 0.860477 |
if not self._writable:
raise UnsupportedOperation('write')
size = len(b)
b_view = memoryview(b)
size_left = size
buffer_size = self._buffer_size
max_buffers = self._max_buffers
with self._seek_lock:
end = self._buffer_seek
... | def write(self, b) | 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. | 4.294665 | 4.336339 | 0.990389 |
return QRCode(content, error, version, mode, encoding) | def create(content, error='H', version=None, mode=None, encoding=None) | 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... | 6.314869 | 7.580431 | 0.833049 |
def two_bytes(c):
def next_byte(b):
if not isinstance(b, int):
return ord(b)
else:
return b
#Go through the data by looping to every other character
for i in range(... | def _detect_content_type(self, content, encoding) | 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... | 4.226954 | 3.888252 | 1.087109 |
import math
for version in range(1, 41):
#Get the maximum possible capacity
capacity = tables.data_capacity[version][self.error][self.mode_num]
#Check the capacity
#Kanji's count in the table is "characters" which are two byt... | 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. | 11.073543 | 7.005245 | 1.58075 |
import os
import time
import tempfile
import webbrowser
try: # Python 2
from urlparse import urljoin
from urllib import pathname2url
except ImportError: # Python 3
from urllib.parse import urljoin
from urllib.re... | def show(self, wait=1.2, scale=10, module_color=(0, 0, 0, 255),
background=(255, 255, 255, 255), quiet_zone=4) | 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... | 2.125496 | 1.993683 | 1.066116 |
return builder._get_png_size(self.version, scale, quiet_zone) | def get_png_size(self, scale=1, quiet_zone=4) | 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
... | 10.960533 | 14.778095 | 0.741674 |
builder._png(self.code, self.version, file, scale,
module_color, background, quiet_zone) | def png(self, file, scale=1, module_color=(0, 0, 0, 255),
background=(255, 255, 255, 255), quiet_zone=4) | 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... | 7.640063 | 12.394327 | 0.616416 |
import io
import base64
with io.BytesIO() as virtual_file:
self.png(file=virtual_file, scale=scale, module_color=module_color,
background=background, quiet_zone=quiet_zone)
image_as_str = base64.b64encode(virtual_file.getvalue()).dec... | def png_as_base64_str(self, scale=1, module_color=(0, 0, 0, 255),
background=(255, 255, 255, 255), quiet_zone=4) | 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?')
... | 2.253713 | 2.294464 | 0.982239 |
return builder._xbm(self.code, scale, quiet_zone) | def xbm(self, scale=1, quiet_zone=4) | 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... | 13.746835 | 22.431137 | 0.612846 |
builder._svg(self.code, self.version, file, scale=scale,
module_color=module_color, background=background,
quiet_zone=quiet_zone, xmldecl=xmldecl, svgns=svgns,
title=title, svgclass=svgclass, lineclass=lineclass,
omit... | def svg(self, file, scale=1, module_color='#000', background=None,
quiet_zone=4, xmldecl=True, svgns=True, title=None,
svgclass='pyqrcode', lineclass='pyqrline', omithw=False,
debug=False) | 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... | 1.965167 | 2.347727 | 0.837051 |
builder._eps(self.code, self.version, file, scale, module_color,
background, quiet_zone) | def eps(self, file, scale=1, module_color=(0, 0, 0),
background=None, quiet_zone=4) | 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... | 7.911827 | 11.705716 | 0.675894 |
return builder._terminal(self.code, module_color, background,
quiet_zone) | def terminal(self, module_color='default', background='reverse',
quiet_zone=4) | 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... | 9.36119 | 15.225003 | 0.614856 |
is_stream = hasattr(stream_or_path, 'write')
if not is_stream:
# No stream provided, treat "stream_or_path" as path
stream_or_path = open(stream_or_path, mode)
return stream_or_path, not is_stream | def _get_writable(stream_or_path, mode) | 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... | 3.077188 | 3.338154 | 0.921823 |
#Formula: scale times number of modules plus the border on each side
return (int(scale) * tables.version_size[version]) + (2 * quiet_zone * int(scale)) | def _get_png_size(version, scale, quiet_zone=4) | 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. | 13.279163 | 12.56605 | 1.056749 |
buf = io.StringIO()
def draw_border():
for i in range(quiet_zone):
buf.write(background)
if module_color in tables.term_colors:
data = '\033[{0}m \033[0m'.format(
tables.term_colors[module_color])
elif 0 <= module_color <= 256:
data = '\033[48;5;{0... | def _terminal(code, module_color='default', background='reverse', quiet_zone=4) | 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 ... | 2.833622 | 2.713433 | 1.044294 |
buf = io.StringIO()
border_row = '0' * (len(code[0]) + (quiet_zone*2))
#Every QR code start with a quiet zone at the top
for b in range(quiet_zone):
buf.write(border_row)
buf.write('\n')
for row in code:
#Draw the starting quiet zone
for b in range(quiet_zone)... | def _text(code, quiet_zone=4) | This method returns a text based representation of the QR code.
This is useful for debugging purposes. | 2.950949 | 2.844257 | 1.037511 |
try:
str = unicode # Python 2
except NameError:
str = __builtins__['str']
buf = io.StringIO()
# Calculate the width in pixels
pixel_width = (len(code[0]) + quiet_zone * 2) * scale
# Add the size information and open the pixel data section
buf.write('#... | 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. | 2.607074 | 2.589373 | 1.006836 |
if color[0] == '#':
color = color[1:]
if len(color) == 3:
color = color[0] * 2 + color[1] * 2 + color[2] * 2
if len(color) != 6:
raise ValueError('Input #{0} is not in #RRGGBB format'.format(color))
return [int(n, 16) for n in (color[:2], color[2:4], color[4:])] | def _hex_to_rgb(color) | \
Helper function to convert a color provided in hexadecimal format
as RGB triple. | 1.802282 | 1.88545 | 0.95589 |
args = [iter(iterable)] * n
if hasattr(itertools, 'zip_longest'):
return itertools.zip_longest(*args, fillvalue=fillvalue)
return itertools.izip_longest(*args, fillvalue=fillvalue) | def grouper(self, n, iterable, fillvalue=None) | 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. | 2.413598 | 2.616344 | 0.922508 |
#The "data length" field varies by the type of code and its mode.
#discover how long the "data length" field should be.
if 1 <= self.version <= 9:
max_version = 9
elif 10 <= self.version <= 26:
max_version = 26
elif 27 <= self.version <= 40:
... | def get_data_length(self) | QR codes contain a "data length" field. This method creates this
field. A binary string representing the appropriate length is
returned. | 4.62617 | 3.872008 | 1.194773 |
if self.mode == tables.modes['alphanumeric']:
encoded = self.encode_alphanumeric()
elif self.mode == tables.modes['numeric']:
encoded = self.encode_numeric()
elif self.mode == tables.modes['binary']:
encoded = self.encode_bytes()
elif self.mod... | def encode(self) | This method encodes the data into a binary string using
the appropriate algorithm specified by the mode. | 2.536746 | 2.382794 | 1.06461 |
#Convert the string to upper case
self.data = self.data.upper()
#Change the data such that it uses a QR code ascii table
ascii = []
for char in self.data:
if isinstance(char, int):
ascii.append(tables.ascii_codes[chr(char)])
else:... | 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. | 5.351328 | 5.14007 | 1.0411 |
with io.StringIO() as buf:
#Break the number into groups of three digits
for triplet in self.grouper(3, self.data):
number = ''
for digit in triplet:
if isinstance(digit, int):
digit = chr(digit)
... | 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. | 3.272632 | 3.066704 | 1.06715 |
with io.StringIO() as buf:
for char in self.data:
if not isinstance(char, int):
buf.write('{{0:0{0}b}}'.format(8).format(ord(char)))
else:
buf.write('{{0:0{0}b}}'.format(8).format(char))
return buf.getvalue(... | 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. | 2.508618 | 2.492884 | 1.006312 |
def two_bytes(data):
def next_byte(b):
if not isinstance(b, int):
return ord(b)
else:
return b
#Go through the data by looping to every other character
for i in ran... | 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. | 3.925568 | 3.954068 | 0.992792 |
data_capacity = tables.data_capacity[self.version][self.error][0]
if len(payload) > data_capacity:
raise ValueError('The supplied data will not fit '
'within this version of a QR code.')
#We must add up to 4 zeros to make up for any shortfall i... | def terminate_bits(self, payload) | 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. | 7.31836 | 6.240892 | 1.172646 |
bits_short = 8 - (len(self.buffer.getvalue()) % 8)
#The string already falls on an byte boundary do nothing
if bits_short == 0 or bits_short == 8:
return None
else:
return self.binary_string(0, bits_short) | def delimit_words(self) | 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. | 8.625132 | 7.53128 | 1.145241 |
data_blocks = len(self.buffer.getvalue()) // 8
total_blocks = tables.data_capacity[self.version][self.error][0] // 8
needed_blocks = total_blocks - data_blocks
if needed_blocks == 0:
return None
#This will return item1, item2, item1, item2, etc.
bl... | def add_words(self) | 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. | 6.514796 | 4.824933 | 1.350235 |
#Get the error information from the standards table
error_info = tables.eccwbi[self.version][self.error]
#This is the number of 8-bit words per block
if block_number < error_info[1]:
code_words_per_block = error_info[2]
else:
code_words_per_block... | def make_error_block(self, block, block_number) | 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/ | 3.601097 | 3.526589 | 1.021127 |
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 codes with
row = [' ' for x in range(matrix_size)]
template = [deepcopy(row) for x in range(matrix_size)... | def make_code(self) | This method returns the best possible QR code. | 5.735061 | 4.980171 | 1.151579 |
#Draw outer black box
for i in range(7):
inv = -(i+1)
for j in [0,6,-1,-7]:
m[j][i] = 1
m[i][j] = 1
m[inv][j] = 1
m[j][inv] = 1
#Draw inner white box
for i in range(1, 6):
inv =... | def add_detection_pattern(self, m) | 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... | 2.567007 | 2.440731 | 1.051737 |
#Version 1 does not have a position adjustment pattern
if self.version == 1:
return
#Get the coordinates for where to place the boxes
coordinates = tables.position_adjustment[self.version]
#Get the max and min coordinates to handle special cases
min... | def add_position_pattern(self, m) | 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. | 3.029483 | 2.724644 | 1.111882 |
if self.version < 7:
return
#Get the bit fields for this code's version
#We will iterate across the string, the bit string
#needs the least significant digit in the zero-th position
field = iter(tables.version_pattern[self.version][::-1])
#Where to ... | def add_version_pattern(self, m) | 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 | 11.098355 | 10.002134 | 1.109599 |
from copy import deepcopy
nmasks = len(tables.mask_patterns)
masks = [''] * nmasks
count = 0
for n in range(nmasks):
cur_mask = deepcopy(template)
masks[n] = cur_mask
#Add the type pattern bits to the code
self.add_type_... | def make_masks(self, template) | 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. | 5.598959 | 5.526898 | 1.013038 |
field = iter(type_bits)
for i in range(7):
bit = int(next(field))
#Skip the timing bits
if i < 6:
m[8][i] = bit
else:
m[8][i+1] = bit
if -8 < -(i+1):
m[-(i+1)][8] = bit
for i i... | 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. | 4.251395 | 3.943637 | 1.078039 |
pulls = []
issues = []
for i in all_issues:
if is_pull_request(i):
pull = get_pull_request(project, i['number'], auth=True)
pulls.append(pull)
else:
issues.append(i)
return issues, pulls | def split_pulls(all_issues, project="arokem/python-matlab-bridge") | split a list of closed issues into non-PR Issues and Pull Requests | 2.741843 | 2.439835 | 1.123782 |
which = 'pulls' if pulls else 'issues'
if isinstance(period, timedelta):
since = round_hour(datetime.utcnow() - period)
else:
since = period
url = "https://api.github.com/repos/%s/%s?state=closed&sort=updated&since=%s&per_page=%i" % (project, which, since.strftime(ISO8601), PER_PA... | def issues_closed_since(period=timedelta(days=365), project="arokem/python-matlab-bridge", pulls=False) | 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. | 3.259373 | 3.256297 | 1.000945 |
return sorted(issues, key = lambda i:i[field], reverse=reverse) | def sorted_by_field(issues, field='closed_at', reverse=False) | Return a list of issues sorted by closing date date. | 3.691568 | 3.354238 | 1.100569 |
# titles may have unicode in them, so we must encode everything below
if show_urls:
for i in issues:
print(u'#%d: %s' % (i['number'],
i['title'].replace(u'`', u'``')))
else:
for i in issues:
print(u'* %d: %s' % (i['number'], ... | def report(issues, show_urls=False) | Summary report about a list of issues, printing number and title. | 4.350245 | 4.056463 | 1.072423 |
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 = asfortranarray(obj.T)
else:
obj = obj.T
try:
data = obj.astype(float64).tobytes()
except AttributeError:
... | def encode_ndarray(obj) | Write a numpy array and its shape to base64 buffers | 2.486757 | 2.299355 | 1.081502 |
data = data.encode('utf-8')
return frombuffer(base64.b64decode(data), float64) | def decode_arr(data) | Extract a numpy array from a base64 buffer | 5.098563 | 3.698209 | 1.378657 |
if not self.started:
raise ValueError('Session not started, use start()')
nargout = kwargs.pop('nargout', 1)
func_args += tuple(item for pair in zip(kwargs.keys(), kwargs.values())
for item in pair)
dname = os.path.dirname(func_path)
... | def run_func(self, func_path, *func_args, **kwargs) | 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... | 3.601788 | 3.551149 | 1.01426 |
# TODO: This does not work if the function is a mex function inside a folder of the same name
exists = self.run_func('exist', name)['result'] in [2, 3, 5]
if not unconditionally and not exists:
raise AttributeError("'Matlab' object has no attribute '%s'" % name)
# c... | def _bind_method(self, name, unconditionally=False) | 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 __... | 5.24849 | 5.179437 | 1.013332 |
if line.startswith('%%'):
md = True
new_cell = True
source = line.split('%%')[1] + '\n' # line-breaks in md require a line
# gap!
elif line.startswith('%'):
md = True
new_cell = False
source = line.split('%')[1] ... | def format_line(line) | 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.
... | 4.985978 | 4.253138 | 1.172306 |
source = []
md = np.empty(len(lines), dtype=object)
new_cell = np.empty(len(lines), dtype=object)
for idx, l in enumerate(lines):
new_cell[idx], md[idx], this_source = format_line(l)
# Transitions between markdown and code and vice-versa merit a new
# cell, even if no newlin... | def lines_to_notebook(lines, name=None) | 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 | 3.892023 | 3.914027 | 0.994378 |
lines = mfile_to_lines(mfile)
nb = lines_to_notebook(lines)
if outfile is None:
outfile = mfile.split('.m')[0] + '.ipynb'
with open(outfile, 'w') as fid:
nbwrite(nb, fid) | def convert_mfile(mfile, outfile=None) | 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 | 3.060495 | 3.571588 | 0.8569 |
global _loaded
if not _loaded:
ip.register_magics(MatlabMagics(ip, **kwargs))
_loaded = True | def load_ipython_extension(ip, **kwargs) | Load the extension in IPython. | 4.320414 | 4.311434 | 1.002083 |
post_data = json.dumps({
"description": description,
"public": True,
"files": {
filename: {
"content": content
}
}
}).encode('utf-8')
headers = make_auth_header() if auth else {}
response = requests.post("https://api.github.com/gists", data=post_da... | def post_gist(content, description='', filename='file', auth=False) | Post some text to a Gist, and return the URL. | 1.824305 | 1.812312 | 1.006617 |
url = "https://api.github.com/repos/{project}/pulls/{num}".format(project=project, num=num)
if auth:
header = make_auth_header()
else:
header = None
response = requests.get(url, headers=header)
response.raise_for_status()
return json.loads(response.text, object_hook=Obj) | def get_pull_request(project, num, auth=False) | get pull request info by number | 2.072472 | 2.024074 | 1.023911 |
url = "https://api.github.com/repos/{project}/pulls/{num}/files".format(project=project, num=num)
if auth:
header = make_auth_header()
else:
header = None
return get_paged_request(url, headers=header) | def get_pull_request_files(project, num, auth=False) | get list of files in a pull request | 2.343924 | 2.268286 | 1.033346 |
results = []
params.setdefault("per_page", 100)
while True:
if '?' in url:
params = None
print("fetching %s" % url, file=sys.stderr)
else:
print("fetching %s with %s" % (url, params), file=sys.stderr)
response = requests.get(url, headers=heade... | def get_paged_request(url, headers=None, **params) | get a full list, handling APIv3's paging | 2.152494 | 2.095614 | 1.027142 |
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 = get_paged_request(url, headers=headers, **params)
return pages | def get_pulls_list(project, auth=False, **params) | get pull request list | 2.539707 | 2.431602 | 1.044458 |
# copy requests imports in here:
from io import BytesIO
from requests.packages.urllib3.filepost import (
choose_boundary, six, writer, b, get_content_type
)
body = BytesIO()
if boundary is None:
boundary = choose_boundary()
for fieldname, value in iter_fields(fields):
... | def encode_multipart_formdata(fields, boundary=None) | 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... | 2.176367 | 2.236743 | 0.973007 |
if name is None:
name = os.path.basename(filename)
with open(filename, 'rb') as f:
filedata = f.read()
url = "https://api.github.com/repos/{project}/downloads".format(project=project)
payload = json.dumps(dict(name=name, size=len(filedata),
description=descript... | def post_download(project, filename, name=None, description="") | Upload a file to the GitHub downloads area | 2.806033 | 2.72315 | 1.030437 |
# follow symlinks,
fpath = os.path.realpath(path)
# return False for non-files (directories, fifo, etc.)
if not os.path.isfile(fpath):
return False
# On Solaris, etc., "If the process has appropriate privileges, an
# implementation may indicate success for X_OK even if none of the... | def is_executable_file(path) | 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 ... | 4.285139 | 4.261193 | 1.00562 |
'''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
lic... | def which(filename) | 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. | 3.424883 | 2.0974 | 1.632918 |
cfg = get_config()
# To deal with spaces, remove quotes now, and add
# to the full commands themselves.
if 'matlab_bin' in cfg and cfg['matlab_bin'] != '.':
matlab_bin = cfg['matlab_bin'].strip('"')
else: # attempt to autodetect MATLAB filepath
matlab_bin = which_matlab()
... | def build_matlab(static=False) | 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. | 6.049672 | 5.566442 | 1.086811 |
def add_method(function, klass, name=None):
'''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: Th... | 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.
... | null | null | null | |
def extend(klass, name=None):
'''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 ... | 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... | null | null | null | |
'''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 e... | def select(
self,
selector) | 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.
... | 5.788726 | 1.902606 | 3.042526 |
'''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.
... | def select_with_index(
self,
selector=IndexedElement,
transform=identity) | 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... | 4.601578 | 1.652829 | 2.784062 |
'''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.
... | def select_with_correspondence(
self,
selector,
result_selector=KeyedElement) | 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:
... | 4.603434 | 1.465805 | 3.14055 |
'''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_selecto... | def select_many(
self,
collection_selector=identity,
result_selector=identity) | 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 ... | 3.751013 | 1.547628 | 2.423718 |
'''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... | def select_many_with_index(
self,
collection_selector=IndexedElement,
result_selector=lambda source_element,
collection_element: collection_element) | 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.
... | 4.615156 | 1.35142 | 3.415043 |
'''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.
... | def select_many_with_correspondence(
self,
collection_selector=identity,
result_selector=KeyedElement) | 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... | 4.231113 | 1.368875 | 3.090943 |
'''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 conse... | def group_by(self, key_selector=identity,
element_selector=identity,
result_selector=lambda key, grouping: grouping) | 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... | 3.609087 | 1.342637 | 2.688059 |
'''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 Tru... | def where(self, predicate) | 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... | 5.098214 | 2.231574 | 2.284582 |
'''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
c... | def of_type(self, classinfo) | 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... | 5.603566 | 1.941739 | 2.885849 |
'''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() w... | def order_by(self, key_selector=identity) | 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... | 5.188416 | 1.74239 | 2.977758 |
'''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:
coun... | def take(self, count=1) | 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... | 5.877511 | 1.695111 | 3.467331 |
'''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 be... | def take_while(self, predicate) | 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 ... | 5.174687 | 2.369102 | 2.18424 |
'''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 t... | def skip(self, count=1) | 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... | 4.572901 | 2.188288 | 2.089716 |
'''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 ... | def skip_while(self, predicate) | 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... | 5.730977 | 2.42263 | 2.365601 |
'''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 c... | def concat(self, second_iterable) | 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().
... | 5.077194 | 2.51184 | 2.021305 |
'''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) | 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(). | 8.186271 | 3.030715 | 2.701103 |
'''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 ... | def element_at(self, index) | 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().
... | 3.806784 | 2.249823 | 1.692037 |
'''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... | def count(self, predicate=None) | 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... | 5.52564 | 1.739309 | 3.176917 |
'''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 t... | def any(self, predicate=None) | 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
... | 4.830928 | 1.890429 | 2.555466 |
'''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... | def all(self, predicate=bool) | 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... | 5.795256 | 1.875025 | 3.090762 |
'''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 sequ... | def sum(self, selector=identity) | 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... | 5.79021 | 2.028883 | 2.853891 |
'''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 seq... | def average(self, selector=identity) | 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... | 4.603804 | 1.933543 | 2.38102 |
'''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 ... | def contains(self, value, equality_comparer=operator.eq) | 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... | 4.661563 | 2.146589 | 2.171614 |
'''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 ... | def default_if_empty(self, default) | 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.
... | 5.187251 | 1.945642 | 2.666086 |
'''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, t... | def distinct(self, selector=identity) | 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 ... | 6.517891 | 2.059947 | 3.164107 |
'''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
commen... | def difference(self, second_iterable, selector=identity) | 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... | 6.436937 | 1.83754 | 3.503019 |
'''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 ar... | def intersect(self, second_iterable, selector=identity) | 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... | 4.866744 | 2.088106 | 2.330698 |
'''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.
... | def union(self, second_iterable, selector=identity) | 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.
... | 5.253438 | 1.906989 | 2.754833 |
'''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 ... | def join(self, inner_iterable, outer_key_selector=identity,
inner_key_selector=identity,
result_selector=lambda outer, inner: (outer, inner)) | 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... | 2.913945 | 1.450034 | 2.00957 |
'''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
... | def first(self, predicate=None) | 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... | 4.278712 | 1.399837 | 3.056579 |
'''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
s... | def first_or_default(self, default, predicate=None) | 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... | 4.006271 | 1.393608 | 2.874746 |
'''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 eith... | def single(self, predicate=None) | 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 ... | 5.215819 | 1.381148 | 3.776436 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.