def test_parse_boolean(): y = parse_properties("should_work=true") eq_(2, len(y)) eq_('true', y['should_work']) eq_('Boolean', y['should_work@TypeHint']) y = parse_properties("should_work={Boolean}true") eq_(2, len(y)) eq_('true', y['should_work']) eq_('Boolean', y['should_work@TypeHint']) y = parse_properties("should_work={bool}true") eq_(2, len(y)) eq_('true', y['should_work']) eq_('Boolean', y['should_work@TypeHint']) y = parse_properties("should_work={String}true") eq_(2, len(y)) eq_('true', y['should_work']) eq_('String', y['should_work@TypeHint'])
def execute(server, argv): options, args = parser.parse_args(argv) props = parse_properties(args[1]) if len(args) >= 3: path = args[2] return set_node_properties(server, options, path, props) else: for line in sys.stdin: path = line.strip() set_node_properties(server, options, path, props) return OK
def execute(server, argv): options, args = parser.parse_args(argv) action = get_action(args, 'list') actionarg = get_argument(args) if action == 'list' or action == 'ls': return list_users(server, options) elif action == 'create': return create_user(server, options, actionarg) elif action == 'setprop': username = actionarg propstring = get_argument(argv, 3) props = parse_properties(propstring) return set_profile_properties(server, options, username, props) else: parser.print_help() return USER_ERROR
def test_parser_properties(): x = 'key=value' props = parse_properties(x) eq_(1, len(props)) eq_('value', props['key']) x = 'key0=value0,key1=value1' props = parse_properties(x) eq_(2, len(props)) eq_('value0', props['key0']) eq_('value1', props['key1']) x = 'key0="value0",key1="value1"' props = parse_properties(x) eq_('value0', props['key0']) eq_('String', props['key0@TypeHint']) eq_('value1', props['key1']) eq_('String', props['key1@TypeHint']) eq_(4, len(props)) x = 'key0="value0",key1="Sentence with \\"quotes in it\\""' props = parse_properties(x) eq_(4, len(props)) eq_('value0', props['key0']) eq_('String', props['key0@TypeHint']) eq_('Sentence with \\"quotes in it\\"', props['key1']) eq_('String', props['key1@TypeHint']) x = 'key0="value0",key1="Sentence, with comma in it"' props = parse_properties(x) eq_(4, len(props)) eq_('value0', props['key0']) eq_('String', props['key0@TypeHint']) eq_('Sentence, with comma in it', props['key1']) eq_('String', props['key1@TypeHint']) x = 'ary=[foo,bar,baz]' props = parse_properties(x) eq_(2, len(props)) eq_(['foo', 'bar', 'baz'], props['ary']) eq_('String[]', props['ary@TypeHint'])
def test_parse_quoted_number(): y = parse_properties("answer=\"42\"") eq_(2, len(y)) eq_('42', y['answer']) eq_('String', y['answer@TypeHint'])
def test_parse_simple_prop(): y = parse_properties("foobar=baz") eq_(1, len(y)) eq_('baz', y['foobar'])
def test_parse_integer(): y = parse_properties("nbr_dwarves=7") eq_(2, len(y)) eq_('7', y['nbr_dwarves']) eq_('Long', y['nbr_dwarves@TypeHint'])
def test_parse_multi_props(): y = parse_properties("first=John,last=Doe") eq_(2, len(y)) eq_('John', y['first']) eq_('Doe', y['last'])
def test_parse_double_quoted_prop(): y = parse_properties('name="John \\"The machine\\" Doe"') eq_(2, len(y)) eq_('John \\"The machine\\" Doe', y['name']) eq_('String', y['name@TypeHint'])
def test_parse_quoted_prop(): y = parse_properties("name=\"John Doe\"") eq_(2, len(y)) eq_('John Doe', y['name']) eq_('String', y['name@TypeHint'])