code stringlengths 52 7.75k | docs stringlengths 1 5.85k |
|---|---|
def delete_tax_rate_by_id(cls, tax_rate_id, **kwargs):
kwargs['_return_http_data_only'] = True
if kwargs.get('async'):
return cls._delete_tax_rate_by_id_with_http_info(tax_rate_id, **kwargs)
else:
(data) = cls._delete_tax_rate_by_id_with_http_info(tax_rate_id, **... | Delete TaxRate
Delete an instance of TaxRate by its ID.
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.delete_tax_rate_by_id(tax_rate_id, async=True)
>>> result = thread.get()
:param... |
def get_tax_rate_by_id(cls, tax_rate_id, **kwargs):
kwargs['_return_http_data_only'] = True
if kwargs.get('async'):
return cls._get_tax_rate_by_id_with_http_info(tax_rate_id, **kwargs)
else:
(data) = cls._get_tax_rate_by_id_with_http_info(tax_rate_id, **kwargs)
... | Find TaxRate
Return single instance of TaxRate by its ID.
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.get_tax_rate_by_id(tax_rate_id, async=True)
>>> result = thread.get()
:param ... |
def list_all_tax_rates(cls, **kwargs):
kwargs['_return_http_data_only'] = True
if kwargs.get('async'):
return cls._list_all_tax_rates_with_http_info(**kwargs)
else:
(data) = cls._list_all_tax_rates_with_http_info(**kwargs)
return data | List TaxRates
Return a list of TaxRates
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.list_all_tax_rates(async=True)
>>> result = thread.get()
:param async bool
:param int p... |
def replace_tax_rate_by_id(cls, tax_rate_id, tax_rate, **kwargs):
kwargs['_return_http_data_only'] = True
if kwargs.get('async'):
return cls._replace_tax_rate_by_id_with_http_info(tax_rate_id, tax_rate, **kwargs)
else:
(data) = cls._replace_tax_rate_by_id_with_ht... | Replace TaxRate
Replace all attributes of TaxRate
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.replace_tax_rate_by_id(tax_rate_id, tax_rate, async=True)
>>> result = thread.get()
:... |
def update_tax_rate_by_id(cls, tax_rate_id, tax_rate, **kwargs):
kwargs['_return_http_data_only'] = True
if kwargs.get('async'):
return cls._update_tax_rate_by_id_with_http_info(tax_rate_id, tax_rate, **kwargs)
else:
(data) = cls._update_tax_rate_by_id_with_http_... | Update TaxRate
Update attributes of TaxRate
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.update_tax_rate_by_id(tax_rate_id, tax_rate, async=True)
>>> result = thread.get()
:param a... |
def build_append_file_task(urllocation, filelocation):
config = file_utils.get_celcius_config()
basename = filelocation.split('/')[-1]
tmp_filelocation = filelocation.replace(basename, 'tmp_'+basename)
new_filelocation = filelocation.replace(basename, 'new_'+basename)
if config['retrieve_comm... | Build a task to watch a specific remote url and
append that data to the file. This method should be used
when you would like to keep all of the information stored
on the local machine, but also append the new information
found at the url.
For instance, if the local file is:
```
foo
```
And the remote file is:
```
b... |
def get_authentic_node_name(self, node_name: str) -> Optional[str]:
# Is there a node with the given name?
vertex: IGraphVertex = None
try:
vertex: IGraphVertex = self._wrapped_graph.vs.find(node_name)
except ValueError:
pass
# Is node_name a nod... | Returns the exact, authentic node name for the given node name if a node corresponding to
the given name exists in the graph (maybe not locally yet) or `None` otherwise.
By default, this method checks whether a node with the given name exists locally in the
graph and return `node_name` if it do... |
def _create_memory_database_interface(self) -> GraphDatabaseInterface:
Base = declarative_base()
engine = sqlalchemy.create_engine("sqlite://", poolclass=StaticPool)
Session = sessionmaker(bind=engine)
dbi: GraphDatabaseInterface = create_graph_database_interface(
s... | Creates and returns the in-memory database interface the graph will use. |
def _load_neighbors_from_external_source(self) -> None:
graph: IGraphWrapper = self._graph
ig_vertex: IGraphVertex = graph.wrapped_graph.vs[self._igraph_index]
ig_neighbors: List[IGraphVertex] = ig_vertex.neighbors()
for ig_neighbor in ig_neighbors:
try:
... | Loads the neighbors of the node from the igraph `Graph` instance that is
wrapped by the graph that has this node. |
def _create_node(self, index: int, name: str, external_id: Optional[str] = None) -> IGraphNode:
return IGraphNode(graph=self._graph, index=index, name=name, external_id=external_id) | Returns a new `IGraphNode` instance with the given index and name.
Arguments:
index (int): The index of the node to create.
name (str): The name of the node to create.
external_id (Optional[str]): The external ID of the node. |
def parse(self):
self.parse_fields()
records = []
for line in self.t['data'].split('\n'):
if EMPTY_ROW.match(line):
continue
row = [self.autoconvert(line[start_field:end_field+1])
for start_field, end_field in self.fields]
... | Parse the table data string into records. |
def recarray(self):
if self.records is None:
self.parse()
try:
# simple (should this also be subjected to convert.to_int64() ?)
return numpy.rec.fromrecords(self.records, names=self.names)
except ValueError:
# complicated because fromreco... | Return a recarray from the (parsed) string. |
def parse_fields(self):
rule = self.t['toprule'].rstrip() # keep leading space for correct columns!!
if not (rule == self.t['midrule'].rstrip() and rule == self.t['botrule'].rstrip()):
raise ParseError("Table rules differ from each other (check white space).")
names = self... | Determine the start and end columns and names of the fields. |
def email_quote_txt(text,
indent_txt='>>',
linebreak_input="\n",
linebreak_output="\n"):
if (text == ""):
return ""
lines = text.split(linebreak_input)
text = ""
for line in lines:
text += indent_txt + line + linebreak_outp... | Takes a text and returns it in a typical mail quoted format, e.g.::
C'est un lapin, lapin de bois.
>>Quoi?
Un cadeau.
>>What?
A present.
>>Oh, un cadeau.
will return::
>>C'est un lapin, lapin de bois.
>>>>Quoi?
>>Un cadeau.
>>>>What?
... |
def escape_email_quoted_text(text, indent_txt='>>', linebreak_txt='\n'):
washer = HTMLWasher()
lines = text.split(linebreak_txt)
output = ''
for line in lines:
line = line.strip()
nb_indent = 0
while True:
if line.startswith(indent_txt):
nb_indent... | Escape text using an email-like indenting rule.
As an example, this text::
>>Brave Sir Robin ran away...
<img src="malicious_script />*No!*
>>bravely ran away away...
I didn't!*<script>malicious code</script>
>>When danger reared its ugly head, he bravely turned his tail and ... |
def _print(self, text, color=None, **kwargs):
COLORS = {
'red': '\033[91m{}\033[00m',
'green': '\033[92m{}\033[00m',
'yellow': '\033[93m{}\033[00m',
'cyan': '\033[96m{}\033[00m'
}
_ = COLORS[color]
six.print_(_.format(text), **kwar... | print text with given color to terminal |
def _is_unique(self, name, path):
project = None
try:
project = Project.select().where(
(Project.name == name) |
(Project.path == path)
)[0]
except:
pass
return project is None | verify if there is a project with given name or path
on the database |
def _path_is_valid(self, path):
VALIDATORS = [
(os.path.isabs, self._ERROR_PATH_NOT_ABSOLUTE),
(os.path.exists, self._ERROR_PATH_DOESNT_EXISTS),
(os.path.isdir, self._ERROR_PATH_NOT_A_DIR),
]
for validator in VALIDATORS:
func, str_err = v... | validates if a given path is:
- absolute,
- exists on current machine
- is a directory |
def add(self, name, path=None, **kwargs):
path = path or kwargs.pop('default_path', None)
if not self._path_is_valid(path):
return
if not self._is_unique(name, path):
p = Project.select().where(
(Project.name == name) |
(Project.... | add new project with given name and path to database
if the path is not given, current working directory will be taken
...as default |
def list(self, **kwargs):
projects = Project.select().order_by(Project.name)
if len(projects) == 0:
self._print('No projects available', 'yellow')
return
for project in projects:
project_repr = self._PROJECT_ITEM.format(project.name, project.path)
... | displays all projects on database |
def parent_tags(self):
tags = set()
for addr in self._addresses:
if addr.attr == 'text':
tags.add(addr.element.tag)
tags.update(el.tag for el in addr.element.iterancestors())
tags.discard(HTMLFragment._root_tag)
return frozenset(tags) | Provides tags of all parent HTML elements. |
def involved_tags(self):
if len(self._addresses) < 2:
# there can't be a tag boundary if there's only 1 or 0 characters
return frozenset()
# creating 'parent_sets' mapping, where the first item in tuple
# is the address of character and the second is set
... | Provides all HTML tags directly involved in this string. |
def _parse(self, html):
if self._has_body_re.search(html):
tree = lxml.html.document_fromstring(html).find('.//body')
self.has_body = True
else:
tree = lxml.html.fragment_fromstring(html,
create_parent=self._ro... | Parse given string as HTML and return it's etree representation. |
def _iter_texts(self, tree):
skip = (
not isinstance(tree, lxml.html.HtmlElement) # comments, etc.
or tree.tag in self.skipped_tags
)
if not skip:
if tree.text:
yield Text(tree.text, tree, 'text')
for child in tree:
... | Iterates over texts in given HTML tree. |
def _analyze_tree(self, tree):
addresses = []
for text in self._iter_texts(tree):
for i, char in enumerate(text.content):
if char in whitespace:
char = ' '
addresses.append(CharAddress(char, text.element, text.attr, i))
# ... | Analyze given tree and create mapping of indexes to character
addresses. |
def _validate_index(self, index):
if isinstance(index, slice):
if index.step and index.step != 1:
raise IndexError('Step is not allowed.')
indexes = (index.start, index.stop)
else:
indexes = (index,)
for index in indexes:
i... | Validates given index, eventually raises errors. |
def _find_pivot_addr(self, index):
if not self.addresses or index.start == 0:
return CharAddress('', self.tree, 'text', -1) # string beginning
if index.start > len(self.addresses):
return self.addresses[-1]
return self.addresses[index.start] | Inserting by slicing can lead into situation where no addresses are
selected. In that case a pivot address has to be chosen so we know
where to add characters. |
def apply_connectivity_changes(request, add_vlan_action, remove_vlan_action, logger=None):
if not logger:
logger = logging.getLogger("apply_connectivity_changes")
if request is None or request == '':
raise Exception('ConnectivityOperations', 'request is None or empty')
holder = conne... | Standard implementation for the apply_connectivity_changes operation
This function will accept as an input the actions to perform for add/remove vlan. It implements
the basic flow of decoding the JSON connectivity changes requests, and combining the results
of the add/remove vlan functions into a result obj... |
def check_api_key(email, api_key):
table = boto3.resource("dynamodb").Table(os.environ['people'])
user = table.get_item(Key={'email': email})
if not user:
return False
user = user.get("Item")
if api_key != user.get('api_key', None):
return False
return user | Check the API key of the user. |
def lambda_handler(event, context):
email = event.get('email', None)
api_key = event.get('api_key', None)
if not (api_key or email):
msg = "Missing authentication parameters in your request"
return {'success': False, 'message': msg}
indicators = list(set(event.get('indicators', list... | Main handler. |
def parse_email_url(url):
conf = {}
url = urlparse.urlparse(url)
# Remove query strings
path = url.path[1:]
path = path.split('?', 2)[0]
# Update with environment configuration
conf.update({
'EMAIL_FILE_PATH': path,
'EMAIL_HOST_USER': url.username,
'EMAIL_HOS... | Parses an email URL. |
def config(name='EMAIL_URL', default='console://'):
conf = {}
s = env(name, default)
if s:
conf = parse_email_url(s)
return conf | Returns a dictionary with EMAIL_* settings from EMAIL_URL. |
def replace(html, replacements=None):
if not replacements:
return html # no replacements
html = HTMLFragment(html)
for r in replacements:
r.replace(html)
return unicode(html) | Performs replacements on given HTML string. |
def _is_replacement_allowed(self, s):
if any(tag in s.parent_tags for tag in self.skipped_tags):
return False
if any(tag not in self.textflow_tags for tag in s.involved_tags):
return False
return True | Tests whether replacement is allowed on given piece of HTML text. |
def replace(self, html):
self.html = html
text = html.text()
positions = []
def perform_replacement(match):
offset = sum(positions)
start, stop = match.start() + offset, match.end() + offset
s = self.html[start:stop]
if self._is_... | Perform replacements on given HTML fragment. |
def read_relative_file(filename, relative_to=None):
if relative_to is None:
relative_to = os.path.dirname(__file__)
with open(os.path.join(os.path.dirname(relative_to), filename)) as f:
return f.read() | Returns contents of the given file, which path is supposed relative
to this package. |
def get_events(self):
to_send = {'limit': 50}
response = self._send_data('POST', 'admin', 'get-events', to_send)
output = {'message': ""}
for event in response['events']:
desc = "Source IP: {ip}\n"
desc += "Datetime: {time}\n"
desc += "Indica... | Get events from the cloud node. |
def flush_events(self):
response = self._send_data('DELETE', 'admin', 'flush-events', {})
if response['success']:
msg = "Events flushed"
else:
msg = "Flushing of events failed"
output = {'message': msg}
return output | Flush events from the cloud node. |
def put(self):
try:
self.cloudwatch.put_metric_data(
Namespace=self.namespace,
MetricData=[{
'MetricName': self.name,
'Value': self.value,
'Timestamp': self.timestamp
... | Push the info represented by this ``Metric`` to CloudWatch. |
def log(self, message, level=logging.INFO, *args, **kwargs):
msg = "{}.{}: {}[{}]: {}".format(
self.__class__.__name__, self.status, self.__class__.path,
self.uuid, message
)
extra = kwargs.pop("extra", dict())
extra.update(dict(kmsg=Message(
... | Send log entry
:param str message: log message
:param int level: `Logging level <https://docs.python.org/3/library/logging.html#levels>`_
:param list args: log record arguments
:param dict kwargs: log record key argument |
def setFocus(self, reason=None):
self.formLayout.itemAt(0, QFormLayout.FieldRole).widget().setFocus() | Sets focus to first field. Note: reason is ignored. |
def _connect(self):
logger.info("Connecting to rabbit")
for url in self._urls:
try:
self._connection = pika.BlockingConnection(pika.URLParameters(url))
self._channel = self._connection.channel()
self._declare()
if self.... | Connect to a RabbitMQ instance
:returns: Boolean corresponding to success of connection
:rtype: bool |
def _disconnect(self):
try:
self._connection.close()
logger.debug("Disconnected from rabbit")
except Exception:
logger.exception("Unable to close connection") | Cleanly close a RabbitMQ connection.
:returns: None |
def publish_message(self, message, content_type=None, headers=None, mandatory=False, immediate=False):
logger.debug("Publishing message")
try:
self._connect()
return self._do_publish(mandatory=mandatory,
immediate=immediate,
... | Publish a response message to a RabbitMQ instance.
:param message: Response message
:param content_type: Pika BasicProperties content_type value
:param headers: Message header properties
:param mandatory: The mandatory flag
:param immediate: The immediate flag
:returns:... |
def on_execute__set_surface_alphas(self, request):
'''
.. versionchanged:: 0.12
Queue redraw after setting surface alphas.
'''
data = decode_content_data(request)
logger.debug('[on_execute__set_surface_alphas] %s',
data['surface_alphas'])
... | .. versionchanged:: 0.12
Queue redraw after setting surface alphas. |
def on_execute__set_dynamic_electrode_states(self, request):
'''
.. versionadded:: 0.15
Set dynamic electrode states.
'''
data = decode_content_data(request)
self.parent.on_dynamic_electrode_states_set(data['electrode_states']f on_execute__set_dynamic_electrode_states(se... | .. versionadded:: 0.15
Set dynamic electrode states. |
def on_connect_button__clicked(self, event):
'''
Connect to Zero MQ plugin hub (`zmq_plugin.hub.Hub`) using the settings
from the text entry fields (e.g., hub URI, plugin name).
Emit `plugin-connected` signal with the new plugin instance after hub
connection has been established... | Connect to Zero MQ plugin hub (`zmq_plugin.hub.Hub`) using the settings
from the text entry fields (e.g., hub URI, plugin name).
Emit `plugin-connected` signal with the new plugin instance after hub
connection has been established. |
def create_quali_api_instance(context, logger):
if hasattr(context, 'reservation') and context.reservation:
domain = context.reservation.domain
elif hasattr(context, 'remote_reservation') and context.remote_reservation:
domain = context.remote_reservation.domain
else:
domain = N... | Get needed attributes from context and create instance of QualiApiHelper
:param context:
:param logger:
:return: |
def login(self):
uri = 'API/Auth/Login'
if self._token:
json_data = {'token': self._token, 'domain': self._domain}
else:
json_data = {'username': self._username, 'password': self._password, 'domain': self._domain}
result = self.__rest_client.request_put(u... | Login
:return: |
def run_migrations_offline():
url = winchester_config['database']['url']
context.configure(url=url)
with context.begin_transaction():
context.run_migrations() | Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output. |
def run_migrations_online():
engine = engine_from_config(
winchester_config['database'],
prefix='',
poolclass=pool.NullPool)
connection = engine.connect()
context.configure(
connection=connection,
target_metadata=target_metadata
)
try:
with cont... | Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context. |
def follow_cf(save, Uspan, target_cf, nup, n_tot=5.0, slsp=None):
if slsp == None:
slsp = Spinon(slaves=6, orbitals=3, avg_particles=n_tot,
hopping=[0.5]*6, populations = np.asarray([n_tot]*6)/6)
zet, lam, mu, mean_f = [], [], [], []
for co in Uspan:
print('U='... | Calculates the quasiparticle weight in single
site spin hamiltonian under with N degenerate half-filled orbitals |
def targetpop(upper_density, coul, target_cf, slsp, n_tot):
if upper_density < 0.503: return 0.
trypops=population_distri(upper_density, n_tot)
slsp.set_filling(trypops)
slsp.selfconsistency(coul,0)
efm_free = dos_bethe_find_crystalfield(trypops, slsp.param['hopping'])
orb_ener = slsp.param... | restriction on finding the right populations that leave the crystal
field same |
def produce_pdf(rst_content=None, doctree_content=None, filename=None):
if filename is None:
filename = os.path.join(
"/tmp", ''.join([random.choice(string.ascii_letters +
string.digits) for n in range(15)]) + '.pdf')
r2p = RstToPdf(stylesheets=['pdf.style'],
... | produce a pdf content based of a given rst content
If filename is given, it will store the result using the given filename
if no filename is given, it will generate a pdf in /tmp/ with a random
name |
def load(self, filename=None):
DataFile.load(self, filename)
self.spectrum.filename = filename | Method was overriden to set spectrum.filename as well |
def _do_save_as(self, filename):
if len(self.spectrum.x) < 2:
raise RuntimeError("Spectrum must have at least two points")
if os.path.isfile(filename):
os.unlink(filename) # PyFITS does not overwrite file
hdu = self.spectrum.to_hdu()
overwrite_fits(hdu... | Saves spectrum back to FITS file. |
def alternator(*pipes):
''' a lot like zip, just instead of:
(a,b),(a,b),(a,b)
it works more like:
a,b,a,b,a,b,a
until one of the pipes ends '''
try:
for p in cycle(map(iter, pipes)):
yield next(p)
except StopIteration:
pasf alternator(*pip... | a lot like zip, just instead of:
(a,b),(a,b),(a,b)
it works more like:
a,b,a,b,a,b,a
until one of the pipes ends |
def matches():
wvw_matches = get_cached("wvw/matches.json", False).get("wvw_matches")
for match in wvw_matches:
match["start_time"] = parse_datetime(match["start_time"])
match["end_time"] = parse_datetime(match["end_time"])
return wvw_matches | This resource returns a list of the currently running WvW matches, with
the participating worlds included in the result. Further details about a
match can be requested using the ``match_details`` function.
The response is a list of match objects, each of which contains the
following properties:
wv... |
def objective_names(lang="en"):
params = {"lang": lang}
cache_name = "objective_names.%(lang)s.json" % params
data = get_cached("wvw/objective_names.json", cache_name, params=params)
return dict([(objective["id"], objective["name"]) for objective in data]) | This resource returns a list of the localized WvW objective names for
the specified language.
:param lang: The language to query the names for.
:return: A dictionary mapping the objective Ids to the names.
*Note that these are not the names displayed in the game, but rather the
abstract type.* |
def _parse_data(self, data, charset):
builder = TreeBuilder(numbermode=self._numbermode)
if isinstance(data,basestring):
xml.sax.parseString(data, builder)
else:
xml.sax.parse(data, builder)
return builder.root[self._root_element_name()] | Parse the xml data into dictionary. |
def _format_data(self, data, charset):
if data is None or data == '':
return u''
stream = StringIO.StringIO()
xml = SimplerXMLGenerator(stream, charset)
xml.startDocument()
xml.startElement(self._root_element_name(), {})
self._to_xml(xml, data)
... | Format data into XML. |
def _to_xml(self, xml, data, key=None):
if isinstance(data, (list, tuple)):
for item in data:
elemname = self._list_item_element_name(key)
xml.startElement(elemname, {})
self._to_xml(xml, item)
xml.endElement(elemname)
... | Recursively convert the data into xml.
This function was originally copied from the
`Piston project <https://bitbucket.org/jespern/django-piston/>`_
It has been modified since.
:param xml: the xml document
:type xml: SimplerXMLGenerator
:param data: data to be formatted... |
def startElement(self, name, attrs):
self.stack.append((self.current, self.chardata))
self.current = {}
self.chardata = [] | Initialize new node and store current node into stack. |
def endElement(self, name):
if self.current:
# we have nested elements
obj = self.current
else:
# text only node
text = ''.join(self.chardata).strip()
obj = self._parse_node_data(text)
newcurrent, self.chardata = self.stack.pop... | End current xml element, parse and add to to parent node. |
def _parse_node_data(self, data):
data = data or ''
if self.numbermode == 'basic':
return self._try_parse_basic_number(data)
elif self.numbermode == 'decimal':
return self._try_parse_decimal(data)
else:
return data | Parse the value of a node. Override to provide your own parsing. |
def _try_parse_basic_number(self, data):
# try int first
try:
return int(data)
except ValueError:
pass
# try float next
try:
return float(data)
except ValueError:
pass
# no luck, return data as it is
... | Try to convert the data into ``int`` or ``float``.
:returns: ``Decimal`` or ``data`` if conversion fails. |
def _element_to_node(self, node, name, value):
# is the target node a list?
try:
node.append(value)
except AttributeError:
pass
else:
return node
# target node is a dict
if name in node:
# there's already an eleme... | Insert the parsed element (``name``, ``value`` pair) into the node.
You should always use the returned node and forget the one
that was given in parameter.
:param node: the node where the is added to
:returns: the node. Note that this may be a new node instance. |
def _get_programs_dict(pkgname_only, flag_protected, flag_no_pfant=False):
allinfo = f311.get_programs_dict(pkgname_only, flag_protected)
if not flag_no_pfant and "pyfant" in allinfo:
_add_PFANT(allinfo)
return allinfo | Returns dictionary {(package description): [ExeInfo0, ...], ...} |
def apize_raw(url, method='GET'):
def decorator(func):
def wrapper(*args, **kwargs):
elem = func(*args, **kwargs)
if type(elem) is not dict:
raise BadReturnVarType(func.__name__)
response = send_request(url, method,
elem.get('data', {}),
elem.get('args', {}),
elem.get('params', {}),
... | Convert data and params dict -> json. |
def extract_version(path):
# Regular expression for the version
_version_re = re.compile(r'__version__\s+=\s+(.*)')
with open(path + '__init__.py', 'r', encoding='utf-8') as f:
version = f.read()
if version:
version = _version_re.search(version)
if version:
ve... | Reads the file at the specified path and returns the version contained in it.
This is meant for reading the __init__.py file inside a package, and so it
expects a version field like:
__version__ = '1.0.0'
:param path: path to the Python file
:return: the version inside the file |
def _make_connect(module, args, kwargs):
# pylint: disable-msg=W0142
return functools.partial(module.connect, *args, **kwargs) | Returns a function capable of making connections with a particular
driver given the supplied credentials. |
def connect(module, *args, **kwargs):
mdr = SingleConnectionMediator(
module, _make_connect(module, args, kwargs))
return Context(module, mdr) | Connect to a database using the given DB-API driver module. Returns
a database context representing that connection. Any arguments or
keyword arguments are passed the module's :py:func:`connect` function. |
def create_pool(module, max_conns, *args, **kwargs):
if not hasattr(module, 'threadsafety'):
raise NotSupported("Cannot determine driver threadsafety.")
if max_conns < 1:
raise ValueError("Minimum number of connections is 1.")
if module.threadsafety >= 2:
return Pool(module, max... | Create a connection pool appropriate to the driver module's capabilities. |
def transactional(wrapped):
# pylint: disable-msg=C0111
def wrapper(*args, **kwargs):
with Context.current().transaction():
return wrapped(*args, **kwargs)
return functools.update_wrapper(wrapper, wrapped) | A decorator to denote that the content of the decorated function or
method is to be ran in a transaction.
The following code is equivalent to the example for
:py:func:`dbkit.transaction`::
import sqlite3
import sys
from dbkit import connect, transactional, query_value, execute
... |
def execute(stmt, args=()):
ctx = Context.current()
with ctx.mdr:
cursor = ctx.execute(stmt, args)
row_count = cursor.rowcount
_safe_close(cursor)
return row_count | Execute an SQL statement. Returns the number of affected rows. |
def query(stmt, args=(), factory=None):
ctx = Context.current()
factory = ctx.default_factory if factory is None else factory
with ctx.mdr:
return factory(ctx.execute(stmt, args), ctx.mdr) | Execute a query. This returns an iterator of the result set. |
def query_row(stmt, args=(), factory=None):
for row in query(stmt, args, factory):
return row
return None | Execute a query. Returns the first row of the result set, or `None`. |
def query_value(stmt, args=(), default=None):
for row in query(stmt, args, TupleFactory):
return row[0]
return default | Execute a query, returning the first value in the first row of the
result set. If the query returns no result set, a default value is
returned, which is `None` by default. |
def execute_proc(procname, args=()):
ctx = Context.current()
with ctx.mdr:
cursor = ctx.execute_proc(procname, args)
row_count = cursor.rowcount
_safe_close(cursor)
return row_count | Execute a stored procedure. Returns the number of affected rows. |
def query_proc(procname, args=(), factory=None):
ctx = Context.current()
factory = ctx.default_factory if factory is None else factory
with ctx.mdr:
return factory(ctx.execute_proc(procname, args), ctx.mdr) | Execute a stored procedure. This returns an iterator of the result set. |
def query_proc_row(procname, args=(), factory=None):
for row in query_proc(procname, args, factory):
return row
return None | Execute a stored procedure. Returns the first row of the result set,
or `None`. |
def query_proc_value(procname, args=(), default=None):
for row in query_proc(procname, args, TupleFactory):
return row[0]
return default | Execute a stored procedure, returning the first value in the first row
of the result set. If it returns no result set, a default value is
returned, which is `None` by default. |
def make_placeholders(seq, start=1):
if len(seq) == 0:
raise ValueError('Sequence must have at least one element.')
param_style = Context.current().param_style
placeholders = None
if isinstance(seq, dict):
if param_style in ('named', 'pyformat'):
template = ':%s' if para... | Generate placeholders for the given sequence. |
def make_file_object_logger(fh):
def logger_func(stmt, args, fh=fh):
"""
A logger that logs everything sent to a file object.
"""
now = datetime.datetime.now()
six.print_("Executing (%s):" % now.isoformat(), file=fh)
six.print_(textwrap.dedent(stmt), file=fh)
... | Make a logger that logs to the given file object. |
def current(cls, with_exception=True):
if with_exception and len(cls.stack) == 0:
raise NoContext()
return cls.stack.top() | Returns the current database context. |
def transaction(self):
# The idea here is to fake the nesting of transactions. Only when
# we've gotten back to the topmost transaction context do we actually
# commit or rollback.
with self.mdr:
try:
self._depth += 1
yield self
... | Sets up a context where all the statements within it are ran within
a single database transaction. For internal use only. |
def cursor(self):
cursor = self.mdr.cursor()
with self.transaction():
try:
yield cursor
if cursor.rowcount != -1:
self.last_row_count = cursor.rowcount
self.last_row_id = getattr(cursor, 'lastrowid', None)
... | Get a cursor for the current connection. For internal use only. |
def execute(self, stmt, args):
self.logger(stmt, args)
with self.cursor() as cursor:
cursor.execute(stmt, args)
return cursor | Execute a statement, returning a cursor. For internal use only. |
def execute_proc(self, procname, args):
self.logger(procname, args)
with self.cursor() as cursor:
cursor.callproc(procname, args)
return cursor | Execute a stored procedure, returning a cursor. For internal use
only. |
def close(self):
self.logger = None
for exc in _EXCEPTIONS:
setattr(self, exc, None)
try:
self.mdr.close()
finally:
self.mdr = None | Close the connection this context wraps. |
def connect(self):
ctx = Context(self.module, self.create_mediator())
ctx.logger = self.logger
ctx.default_factory = self.default_factory
return ctx | Returns a context that uses this pool as a connection source. |
def close(self):
if self.mdr is None:
return
exc = (None, None, None)
try:
self.cursor.close()
except:
exc = sys.exc_info()
try:
if self.mdr.__exit__(*exc):
exc = (None, None, None)
except:
... | Release all resources associated with this factory. |
def add_item(cls, item, **kwargs):
kwargs['_return_http_data_only'] = True
if kwargs.get('async'):
return cls._add_item_with_http_info(item, **kwargs)
else:
(data) = cls._add_item_with_http_info(item, **kwargs)
return data | Add item.
Add new item to the shopping cart.
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.add_item(item, async=True)
>>> result = thread.get()
:param async bool
:param Line... |
def checkout(cls, order, **kwargs):
kwargs['_return_http_data_only'] = True
if kwargs.get('async'):
return cls._checkout_with_http_info(order, **kwargs)
else:
(data) = cls._checkout_with_http_info(order, **kwargs)
return data | Checkout cart.
Checkout cart, Making an order.
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.checkout(order, async=True)
>>> result = thread.get()
:param async bool
:param O... |
def delete_item(cls, item_id, **kwargs):
kwargs['_return_http_data_only'] = True
if kwargs.get('async'):
return cls._delete_item_with_http_info(item_id, **kwargs)
else:
(data) = cls._delete_item_with_http_info(item_id, **kwargs)
return data | Remove item.
Remove item from shopping cart
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.delete_item(item_id, async=True)
>>> result = thread.get()
:param async bool
:param... |
def empty(cls, **kwargs):
kwargs['_return_http_data_only'] = True
if kwargs.get('async'):
return cls._empty_with_http_info(**kwargs)
else:
(data) = cls._empty_with_http_info(**kwargs)
return data | Empty cart.
Empty the shopping cart.
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.empty(async=True)
>>> result = thread.get()
:param async bool
:return: ShoppingCart
... |
def get(cls, **kwargs):
kwargs['_return_http_data_only'] = True
if kwargs.get('async'):
return cls._get_with_http_info(**kwargs)
else:
(data) = cls._get_with_http_info(**kwargs)
return data | Get cart.
Retrieve the shopping cart of the current session.
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.get(async=True)
>>> result = thread.get()
:param async bool
:retur... |
def update_item(cls, item_id, item, **kwargs):
kwargs['_return_http_data_only'] = True
if kwargs.get('async'):
return cls._update_item_with_http_info(item_id, item, **kwargs)
else:
(data) = cls._update_item_with_http_info(item_id, item, **kwargs)
retu... | Update cart.
Update cart item.
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async=True
>>> thread = api.update_item(item_id, item, async=True)
>>> result = thread.get()
:param async bool
:param str it... |
def get_perm_names(cls, resource):
return [cls.get_perm_name(resource, method) for method in cls.METHODS] | Return all permissions supported by the resource.
This is used for auto-generating missing permissions rows into
database in syncdb. |
def get_perm_name(cls, resource, method):
return '%s_%s_%s' % (
cls.PREFIX,
cls._get_resource_name(resource),
method.lower()) | Compose permission name
@param resource the resource
@param method the request method (case doesn't matter). |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.