How to use str_or_none method in localstack

Best Python code snippet using localstack_python

f21c312af55fd177945ba8c152e10779b50e725capi.py

Source:f21c312af55fd177945ba8c152e10779b50e725capi.py Github

copy

Full Screen

1# Copyright 2014 Hewlett-Packard Development Company, L.P.2#3# Authors: Davide Agnello <davide.agnello@hp.com>4#5# Licensed under the Apache License, Version 2.0 (the "License");6# you may not use this file except in compliance with the License.7# You may obtain a copy of the License at8#9# http://www.apache.org/licenses/LICENSE-2.010#11# Unless required by applicable law or agreed to in writing, software12# distributed under the License is distributed on an "AS IS" BASIS,13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14# See the License for the specific language governing permissions and15# limitations under the License.16# Copyright [2014] Hewlett-Packard Development Company, L.P.17# limitations under the License.18"""19Base classes for storage engines20"""21import abc22from oslo_config import cfg23from oslo_db import api as db_api24import six25_BACKEND_MAPPING = {'sqlalchemy': 'cue.db.sqlalchemy.api'}26IMPL = db_api.DBAPI.from_config(cfg.CONF, backend_mapping=_BACKEND_MAPPING,27 lazy=True)28def get_instance():29 """Return a DB API instance."""30 return IMPL31@six.add_metaclass(abc.ABCMeta)32class Connection(object):33 """Base class for storage system connections."""34 @abc.abstractmethod35 def __init__(self):36 """Constructor."""37 @abc.abstractmethod38 def get_clusters(self, context, *args, **kwargs):39 """Returns a list of Cluster objects for specified project_id.40 :param context: request context object41 :returns: a list of :class:'Cluster' object42 """43 @abc.abstractmethod44 def create_cluster(self, context, cluster_values):45 """Creates a new cluster.46 :param context: request context object47 :param cluster_values: Dictionary of several required items48 ::49 {50 'network_id': obj_utils.str_or_none,51 'project_id': obj_utils.str_or_none,52 'name': obj_utils.str_or_none,53 'flavor': obj_utils.str_or_none,54 'size': obj_utils.int_or_none,55 'volume_size': obj_utils.int_or_none,56 }57 """58 @abc.abstractmethod59 def update_cluster(self, context, cluster_values, cluster_id):60 """Updates values in a cluster record indicated by cluster_id61 :param context: request context object62 :param cluster_values: Dictionary of cluster values to update63 :param cluster_id: UUID of a cluster64 """65 @abc.abstractmethod66 def get_cluster_by_id(self, context, cluster_id):67 """Returns a Cluster objects for specified cluster_id.68 :param context: request context object69 :param cluster_id: UUID of a cluster70 :returns: a :class:'Cluster' object71 """72 @abc.abstractmethod73 def get_nodes_in_cluster(self, context, cluster_id):74 """Returns a list of Node objects for specified cluster.75 :param context: request context object76 :param cluster_id: UUID of the cluster77 :returns: a list of :class:'Node' object78 """79 @abc.abstractmethod80 def get_node_by_id(self, context, node_id):81 """Returns a node for the specified node_id.82 :param context: request context object83 :param node_id: UUID of the node84 :returns: a :class:'Node' object85 """86 @abc.abstractmethod87 def update_node(self, context, node_values, node_id):88 """Updates values in a node record indicated by node_id89 :param context: request context object90 :param node_values: Dictionary of node values to update91 :param node_id:92 :return:93 """94 @abc.abstractmethod95 def get_endpoints_in_node(self, context, node_id):96 """Returns a list of Endpoint objects for specified node.97 :param context: request context object98 :param node_id: UUID of the node99 :returns: a list of :class:'Endpoint' object100 """101 @abc.abstractmethod102 def create_endpoint(self, context, endpoint_values):103 """Creates a new endpoint.104 :param context: request context object105 :param endpoint_values: Dictionary of several required items106 ::107 {108 'id': obj_utils.str_or_none,109 'node_id': obj_utils.str_or_none,110 'uri': obj_utils.str_or_none,111 'type': obj_utils.str_or_none,112 }113 """114 @abc.abstractmethod115 def get_endpoint_by_id(self, context, endpoint_id):116 """Returns an endpoint for the specified endpoint_id.117 :param context: request context object118 :param endpoint_id: UUID of the endpoint119 :returns: a :class:'Endpoint' object120 """121 @abc.abstractmethod122 def update_endpoints_by_node_id(self, context, endpoint_values, node_id):123 """Updates values in all endpoints belonging to a specific node124 :param context: request context object125 :param endpoint_values: Dictionary of endpoint values to update126 :param node_id: node id to query endpoints by127 :return:128 """129 @abc.abstractmethod130 def update_cluster_deleting(self, context, cluster_id):131 """Marks specified cluster to indicate deletion.132 :param context: request context object133 :param cluster_id: UUID of a cluster134 """135 @abc.abstractmethod136 def create_broker(self, context, broker_values):137 """Creates a new broker.138 :param context: request context object139 :param broker_values: Dictionary of several required items140 ::141 {142 'type': obj_utils.str_or_none,143 'active_status': obj_utils.bool_or_none144 }145 """146 @abc.abstractmethod147 def get_brokers(self, context):148 """Returns a list of Broker objects.149 :param context: request context object150 :returns: a list of :class:'Broker' object151 """152 @abc.abstractmethod153 def delete_broker(self, context, broker_id):154 """Deletes a Broker object for specified broker_id.155 :param context: request context object156 :param broker_id: UUID of a broker157 """158 @abc.abstractmethod159 def update_broker(self, context, broker_id, broker_value):160 """Updates a Broker type/status for specified broker_id.161 :param context: request context object162 :param broker_id: UUID of a broker163 :param broker_value: Dictionary of attribute values to be updated164 """165 @abc.abstractmethod166 def create_broker_metadata(self, context, metadata_values):167 """Creates a new broker metadata.168 :param context: request context object169 :param metadata_values: Dictionary of several required items170 ::171 {172 'broker_id': UUID of a broker,173 'key': obj_utils.str_or_none,174 'value': obj_utils.str_or_none175 }176 """177 @abc.abstractmethod178 def get_broker_metadata_by_broker_id(self, context, broker_id):179 """Returns a list of BrokerMetadata objects for specified broker_id.180 :param context: request context object181 :param broker_id: UUID of a broker182 :returns: a list of :class:'BrokerMetadata' object183 """184 @abc.abstractmethod185 def delete_broker_metadata(self, context, broker_metadata_id):186 """Deletes a BrokerMetadata object for specified broker_id.187 :param context: request context object188 :param broker_metadata_id: UUID of a broker metadata189 """190 @abc.abstractmethod191 def get_image_id_by_broker_name(self, context, broker_name):192 """Returns a image_id for the broker193 :param context: request context object194 :param: broker name...

Full Screen

Full Screen

iso8601.py

Source:iso8601.py Github

copy

Full Screen

1import re2from datetime import datetime, timedelta, tzinfo3ISO8601_RE = re.compile(r"""4 (?P<YYYY>\d{2,4})5 (?:-?(?P<MM>[01]\d))?6 (?:-?(?P<DD>[0-3]\d))?7 (?:T8 (?P<hh>[0-2]\d)9 (?::?(?P<mm>[0-5]\d))?10 (?::?(?P<ss>[0-5]\d))?11 (?:[,.](?P<s>\d+))?12 )?13 (?P<TZD>Z|14 (?P<zh>[+-][0-2]\d)15 (?::?(?P<zm>[0-5]\d))?16 )?17 """, re.X18)19def to_int(str_or_none, default=0):20 if str_or_none is not None:21 return int(str_or_none)22 return default23def parse_iso8601(string):24 match = ISO8601_RE.match(string)25 if match is None:26 raise ValueError("Invalid ISO 8601 timestamp")27 d = match.groupdict()28 year, month, day = d['YYYY'], d['MM'], d['DD']29 hour, minute, second, fraction = d['hh'], d['mm'], d['ss'], d['s']30 zone, zone_hours, zone_minutes = d['TZD'], d['zh'], d['zm']31 if zone:32 if zone == 'Z':33 tz = TimeZone("UTC")34 else:35 hours = to_int(zone_hours, 0)36 minutes = to_int(zone_minutes, 0) * -int(hours < 0)37 tz = TimeZone(zone, timedelta(hours=hours, minutes=minutes))38 else:39 tz = None40 timestamp = datetime(41 int(year), to_int(month, 1), to_int(day, 1),42 to_int(hour, 0), to_int(minute, 0), to_int(second, 0), tzinfo=tz43 )44 fraction = fraction and float('.' + fraction) or 045 if fraction:46 if second is not None:47 timestamp += timedelta(seconds=fraction)48 elif minute is not None:49 timestamp += timedelta(minutes=fraction)50 elif hour is not None:51 timestamp += timedelta(hours=fraction)52 return timestamp53class TimeZone(tzinfo):54 def __init__(self, name, offset=timedelta(0)):55 self.__name = name56 self.__offset = offset57 58 def utcoffset(self, dt):59 return self.__offset60 61 def tzname(self, dt):62 return self.__name63 64 def dst(self, dt):...

Full Screen

Full Screen

model.py

Source:model.py Github

copy

Full Screen

...15def load_model(model_path: Optional[str], device: str = 'cpu') -> Text2Speech:16 if model_path is None:17 model = Text2Speech.from_pretrained(18 model_tag="imdanboy/kss_tts_train_jets_raw_phn_null_g2pk_train.total_count.ave",19 vocoder_tag=str_or_none("none"),20 device=device21 )22 else:23 model = Text2Speech.from_pretrained(24 model_file=model_path,25 vocoder_tag=str_or_none("none"),26 device=device27 )...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful