Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from yay import ast
class GraphExternalAction(ast.PythonClass):
def test(self):
pass
def destroy(self):
pass
def _resolve(self):
# FIXME: There is a nicer way to do this without resolve, but more yay
# refactoring required
root = self.root
if self not in root.actors:
root.actors.append(self)
return super(GraphExternalAction, self)._resolve()
elif self.type == 'boolean':
if isinstance(value, type(True)):
# might already be boolean
return value
if value.lower() in ('no', '0', 'off', 'false'):
return False
elif value.lower() in ('yes', '1', 'on', 'true'):
return True
raise ArgParseError(
"Cannot parse boolean from %r for argument %r" % (value, self.name))
else:
raise ArgParseError(
"Don't understand %r as a type for argument %r" % (self.type, self.name))
class YaybuArgv(ast.PythonClass):
def __init__(self, **args):
super(YaybuArgv, self).__init__(ast.PythonDict({}))
self.schema = {}
self.args = args
self.anchor = None
@classmethod
def from_argv(cls, argv):
arguments = {}
for arg in argv:
name, value = arg.split("=", 1)
if name in arguments:
raise ArgParseError(
"Duplicate argument %r specified" % (name,))
arguments[name] = value