Exemple #1
0
def dump_edn(l):
    out = "["
    for item in l:
        out += "{"
        for k, v in item.items():
            out += "" + edn_format.dumps(k) + " " + edn_format.dumps(
                v) + ",\n  "
        if out[-4:] == ",\n  ":
            out = out[:-4]
        out += "}\n "
    if out[-2:] == "\n ":
        out = out[:-2]
    out += "]\n"
    return out
Exemple #2
0
def compare_file(output: str, f: File) -> List[dto.Assertion]:
    with open(output) as out:
        out_text = out.read()
        loaded_edn = edn_format.loads_all(out_text)
    parsed_edn = to_edn(f)

    results = []

    for (l, p) in zip(loaded_edn, parsed_edn):
        parsed_typed = edn_format.loads(edn_format.dumps(p))

        results.append(
            dto.Assertion(l, parsed_typed, edn_format.dumps(l),
                          edn_format.dumps(p)))
    return results
Exemple #3
0
def route_configs_file():
    global config_root
    path = "{}/{}".format(config_root, request.args.get('path'))
    if request.method == 'GET':
        txt = open(path).read()
        return edn.dumps({"contents": txt})
    elif request.method == 'PUT':
        fp = open(path, 'w')
        fp.write(request.form.get('contents'))
        return edn.dumps({})
    elif request.method == 'OPTIONS': # http/delete calls options then delete
        return edn.dumps({})
    elif request.method == 'DELETE':
        os.remove(path)
        return edn.dumps({})
Exemple #4
0
 def test_round_trip_inst_short(self):
     step1 = '#inst "2011"'
     step2 = loads(step1)
     step3 = dumps(step2)
     step4 = loads(step3)
     self.assertEqual('#inst "2011-01-01"', step3)
     self.assertEqual(datetime.date(2011, 1, 1), step4)
Exemple #5
0
    def test_discard_all(self):
        for edn_data in (
                '42',
                '-1',
                'nil',
                'true',
                'false',
                '"foo"',
                '\\space',
                '\\a',
                ':foo',
                ':foo/bar',
                '[]',
                '{}',
                '#{}',
                '()',
                '(a)',
                '(a b)',
                '[a [[[b] c]] 2]',
                '#inst "2017"',
        ):
            self.assertEqual([1], loads('[1 #_ {}]'.format(edn_data)),
                             edn_data)
            self.assertEqual([1], loads('[#_ {} 1]'.format(edn_data)),
                             edn_data)

            self.assertEqual(None, loads('#_ {}'.format(edn_data)))

            for coll in ('[%s]', '(%s)', '{%s}', '#{%s}'):
                expected = coll % ""
                edn_data = coll % '#_ {}'.format(edn_data)
                self.assertEqual(expected, dumps(loads(edn_data)), edn_data)
Exemple #6
0
    def test_round_trip_same(self):
        EDN_LITERALS = ("nil", "true", "false", '"hello world"', ":keyword",
                        ":+", ":!", ":-", ":_", ":$", ":&", ":=", ":.",
                        ":abc/def", "symbol", "123", "-123", "32.23", "32.23M",
                        "-32.23M", "-3.903495E-73M", "3.23e-10", "3e+20",
                        "3E+20M", '["abc"]', '[1]', '[1 "abc"]',
                        '[1 "abc" true]', '[:ghi]', '(:ghi)',
                        '[1 "abc" true :ghi]', '(1 "abc" true :ghi)',
                        '{"a" 2}', '#inst "1985-04-12T23:20:50.000000Z"',
                        '#inst "2011-10-09"',
                        '#uuid "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"',
                        '#date "19/07/1984"', '#{{"a" 1}}',
                        '#{{"a" #{{:b 2}}}}', '"|"')

        class TagDate(TaggedElement):
            def __init__(self, value):
                super(TagDate, self).__init__()
                self.name = 'date'
                self.value = datetime.datetime.strptime(value,
                                                        "%d/%m/%Y").date()

            def __str__(self):
                return '#{} "{}"'.format(self.name,
                                         self.value.strftime("%d/%m/%Y"))

        add_tag('date', TagDate)

        for literal in EDN_LITERALS:
            step1 = literal
            step2 = loads(step1)
            step3 = dumps(step2)
            self.assertEqual(step1, step3)
Exemple #7
0
def route_measure():
    global sim_pos
    t = time.time() / 1000.0
    sim_pos += 0.1
    if sim_pos > 1.0:
        sim_pos = 0.0
    return edn.dumps({"t": t,
                      "Ext-0": random.random(),
                      "Ext-1": random.random() + 1.0,
                      "Ext-2": random.random() + 2.0,
                      "Axis-0-x": sim_pos,
                      "Axis-0-y": 0.0,
                      "Axis-0-z": 0.0,
                      "Axis-0-a": 0.0,
                      "Axis-1-x": -sim_pos,
                      "Axis-1-y": 0.0,
                      "Axis-1-z": 0.0,
                      "Axis-1-a": 0.0,
                      "Axis-2-x": 0.0,
                      "Axis-2-y": sim_pos,
                      "Axis-2-z": 0.0,
                      "Axis-2-a": 0.0,
                      "Axis-3-x": 0.2*(random.random() - 0.5),
                      "Axis-3-y": 0.2*(random.random() - 0.5),
                      "Axis-3-z": max(0.0, 0.2*(random.random() - 0.5)),
                      "Axis-3-a": 0.0})
Exemple #8
0
 def test_round_trip_inst_short(self):
     step1 = '#inst "2011"'
     step2 = loads(step1)
     step3 = dumps(step2)
     step4 = loads(step3)
     self.assertEqual('#inst "2011-01-01"', step3)
     self.assertEqual(datetime.date(2011, 1, 1), step4)
Exemple #9
0
def run_mk():
    global mklauncher
    global configserver
    global linuxcnc
    cmd1 = 'configserver /home/machinekit/Desktop -d'.split()
    configserver = subprocess.Popen(cmd1)
    return edn.dumps(status)
Exemple #10
0
 def __init__(self):
     self.output = "{:date " + edn_format.dumps(datetime.datetime.now(pytz.utc)) + " "
     git = subprocess.Popen(["git log --pretty=format:'%h'  -n 1"], shell=True, stdout=subprocess.PIPE).communicate()[0]
     self.output += ":git-hash \"" + git.decode("ascii") + "\" "
     self.remove_keys = ["real_path"]
     self.explict_remap = [["displayname", "display-name"]]
     self.vehicle_name = None
Exemple #11
0
 def test_chained_discards(self):
     for expected, edn_data in (
         ('[]', '[#_ 1 #_ 2 #_ 3]'),
         ('[]', '[#_ #_ 1 2 #_ 3]'),
         ('[]', '[#_ #_ #_ 1 2 3]'),
     ):
         self.assertEqual(expected, dumps(loads(edn_data)), edn_data)
def run():
    item_pages = api.query_category("Items")
    for name, page in item_pages.items():
        try:
            code = mw.parse(page, skip_style_tags=True)
            has_recipes = False
            craftable = Craftable(name)

            for recipe in filter_templates(code, "Recipe"):
                has_recipes = True
                craftable.add_recipe(template_params_to_dict(recipe))

            if not has_recipes:
                continue

            has_price = False
            for infobox_item in filter_templates(code, "Infobox Item"):
                has_price = True
                craftable.add_infobox(template_params_to_dict(infobox_item))

            if not has_price:
                continue

            target_dir = "resources/generated/scraped-craftable"
            if not os.path.exists(target_dir):
                os.makedirs(target_dir)
            with open(f"{target_dir}/{name}.edn", "w") as f:
                f.write(edn_format.dumps(craftable.to_dict()))

        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            print("Craftable {} failed:".format(name))
            traceback.print_exc()
Exemple #13
0
 def test_chained_discards(self):
     for expected, edn_data in (
         ('[]', '[#_ 1 #_ 2 #_ 3]'),
         ('[]', '[#_ #_ 1 2 #_ 3]'),
         ('[]', '[#_ #_ #_ 1 2 3]'),
     ):
         self.assertEqual(expected, dumps(loads(edn_data)), edn_data)
Exemple #14
0
def _ontology_to_edn(cur_o):
    """Map an ontology specification to datomic schemas and inputs.
    """
    schema = []
    vals = []
    for okey, val in cur_o:
        cur_id = K(okey["term"])
        schema.append({
            "ident": cur_id,
            "valueType": K("db.type/%s" % okey["value_type"]),
            "cardinality": K("db.cardinality/one"),
            "doc": okey.get("doc", "")
        })
        vals.append((cur_id, val))
    return (edn_format.dumps(schema, keyword_keys=True, sort_keys=True),
            edn_format.dumps(vals, keyword_keys=True, sort_keys=True))
Exemple #15
0
    def test_round_trip_conversion(self):
        EDN_LITERALS = [
            [r"\c", '"c"'],
            ["[ :ghi ]", "[:ghi]"],
            ["[:a #_foo 42]", "[:a 42]"],
            ["123N", "123"],
            ["-123N", "-123"],
            ["+123", "123"],
            ["+123N", "123"],
            ["123.2", "123.2"],
            ["+32.23M", "32.23M"],
            ["3.23e10", "32300000000.0"],
            ['#{:a (1 2 3) :b}', ['#{:a (1 2 3) :b}',
                                  '#{(1 2 3) :a :b}',
                                  '#{:a :b (1 2 3)}',
                                  '#{:b :a (1 2 3)}']]
        ]

        for literal in EDN_LITERALS:
            step1 = literal[0]
            step2 = loads(step1)
            step3 = dumps(step2)
#            print step1, "->", step2, "->", step3
            if isinstance(literal[1], list):
                self.assertIn(step3, literal[1])
            else:
                self.assertEqual(literal[1], step3)
Exemple #16
0
    def test_round_trip_same(self):
        EDN_LITERALS = (
            "nil",
            "true",
            "false",
            '"hello world"',
            ":keyword",
            ":+",
            ":!",
            ":-",
            ":_",
            ":$",
            ":&",
            ":=",
            ":.",
            ":abc/def",
            "symbol",
            "123",
            "-123",
            "32.23",
            "32.23M",
            "-32.23M",
            "3.23e-10",
            '["abc"]',
            '[1]',
            '[1 "abc"]',
            '[1 "abc" true]',
            '[:ghi]',
            '(:ghi)',
            '[1 "abc" true :ghi]',
            '(1 "abc" true :ghi)',
            '{"a" 2}',
            '#inst "1985-04-12T23:20:50Z"',
            '#uuid "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"',
            '#date "19/07/1984"',
            '#{{"a" 1}}',
            '#{{"a" #{{:b 2}}}}',
            '"|"'
        )

        class TagDate(TaggedElement):
            def __init__(self, value):
                self.name = 'date'
                self.value = datetime.datetime.strptime(
                    value,
                    "%d/%m/%Y").date()

            def __str__(self):
                return '#{} "{}"'.format(
                    self.name,
                    self.value.strftime("%d/%m/%Y"))

        add_tag('date', TagDate)

        for literal in EDN_LITERALS:
            step1 = literal
            step2 = loads(step1)
            step3 = dumps(step2)
#            print step1, "->", step2, "->", step3
            self.assertEqual(step1, step3)
Exemple #17
0
 def test_round_trip_sets(self):
     step1 = '#{:a (1 2 3) :b}'
     step2 = loads(step1)
     step3 = dumps(step2)
     step4 = loads(step3)
     self.assertIn(Keyword("a"), step4)
     self.assertIn(Keyword("b"), step4)
     self.assertIn((1, 2, 3), step4)
Exemple #18
0
def dump_edn_val(v):
  " edn simple value dump"
  if isinstance(v, (str, unicode)): 
    return json.dumps(v)
  elif isinstance(v, E):            
    return unicode(v)
  else:                             
    return dumps(v)
Exemple #19
0
 def test_round_trip_sets(self):
     step1 = '#{:a (1 2 3) :b}'
     step2 = loads(step1)
     step3 = dumps(step2)
     step4 = loads(step3)
     self.assertIn(Keyword("a"), step4)
     self.assertIn(Keyword("b"), step4)
     self.assertIn((1, 2, 3), step4)
Exemple #20
0
def route_login():
    global status
    if request.method == 'OPTIONS':
        return edn.dumps({})
    if request.method == 'POST':
        if request.form.get('password') == login_password:
            return '{:authenticated true :username ' + login_username + '}'
        else:
            return '{:authenticated false}'
Exemple #21
0
 def test_set_roundtrip(self):
     rt_value = dumps(loads('#{:a (1 2 3) :b}'))
     possible_vals = ['#{:a (1 2 3) :b}',
                      '#{:a :b (1 2 3)}',
                      '#{(1 2 3) :a :b}',
                      '#{(1 2 3) :b :a}',
                      '#{:b (1 2 3) :a}',
                      '#{:b :a (1 2 3)}']
     self.assertIn(rt_value, possible_vals)
Exemple #22
0
    def emit(self, g):
        for param in g.params:
            output_dict = dict()
            # lowercase all keywords
            for key in param.__dict__.keys():
                output_dict[key.lower()] = param.__dict__[key]

            # strip off any leading sillyness on the param name
            split_name = param.__dict__["name"].split(":")
            if len(split_name) == 2:
                self.vehicle_name = split_name[0]
            name = param.__dict__["name"].split(":")[-1]
            output_dict["name"] = name

            # remove any keys we don't really care to share
            for key in self.remove_keys:
                output_dict.pop(key, None)

            # rearrange bitmasks to be a vector with nil's if the bit doesn't have meaning
            if "bitmask" in output_dict:
                highest_set_bit = 0
                bits = []
                for bit in output_dict["bitmask"].split(","):
                    bit_parts = bit.split(":")
                    bit_number = int(bit_parts[0])
                    bit_parts[0] = bit_number
                    bits.append(bit_parts)
                    if bit_number > highest_set_bit:
                        highest_set_bit = bit_number
                output_bits = (highest_set_bit + 1) * [None]
                for bit in bits:
                    output_bits[bit[0]] = bit[1]
                output_dict["bitmask"] = output_bits

            # rearrange values into a float indexed map
            if "values" in output_dict:
                values = dict()
                for value in output_dict["values"].split(","):
                    index, description = value.split(":")
                    values[float(index)] = description
                output_dict["values"] = values

            # remap range to be a map of floats
            if "range" in output_dict:
                low, high = output_dict["range"].split()
                output_dict["range"] = {"low": float(low), "high": float(high)}

            # remap the string to a float
            if "increment" in output_dict:
                output_dict["increment"] = float(output_dict["increment"])

            # do any name changing desired
            for remap in self.explict_remap:
                output_dict[remap[1]] = output_dict.pop(remap[0])

            self.output += "\"" + name + "\" " + edn_format.dumps(
                output_dict, keyword_keys=True)
Exemple #23
0
def route_resolve():
    global service_log
    global resolver
    cmd = 'python /home/machinekit/Desktop/resolve.py'.split()
    stop_process(resolver)
    resolver = subprocess.Popen(cmd, stdout=service_log, stderr=service_log)
    if not status['resolving_services']:
        status['resolving_services'] = True
    return edn.dumps(status)
Exemple #24
0
def route_configs():
    global config_root
    config_dirs = glob("{}/*/".format(config_root))
    files = map(lambda d: glob("{}*".format(d)), config_dirs)
    get_f = lambda s: s.split('/')[-1]
    m_keys = map(lambda p: p.split('/')[-2]+'/', config_dirs)
    m_vals = map(lambda fs: map(get_f, fs), files)
    m = dict(zip(m_keys, m_vals))
    return edn.dumps(m)
Exemple #25
0
    def emit(self, g):
        for param in g.params:
            output_dict = dict()
            # lowercase all keywords
            for key in param.__dict__.keys():
                output_dict[key.lower()] = param.__dict__[key]

            # strip off any leading sillyness on the param name
            split_name = param.__dict__["name"].split(":")
            if len(split_name) == 2:
                self.vehicle_name = split_name[0]
            name = param.__dict__["name"].split(":")[-1]
            output_dict["name"] = name

            # remove any keys we don't really care to share
            for key in self.remove_keys:
                output_dict.pop(key, None)

            # rearrange bitmasks to be a vector with nil's if the bit doesn't have meaning
            if "bitmask" in output_dict:
                highest_set_bit = 0
                bits = []
                for bit in output_dict["bitmask"].split(","):
                    bit_parts = bit.split(":")
                    bit_number = int(bit_parts[0])
                    bit_parts[0] = bit_number
                    bits.append(bit_parts)
                    if bit_number > highest_set_bit:
                        highest_set_bit = bit_number
                output_bits = (highest_set_bit+1)*[None]
                for bit in bits:
                    output_bits[bit[0]] = bit[1]
                output_dict["bitmask"] = output_bits

            # rearrange values into a float indexed map
            if "values" in output_dict:
                values = dict()
                for value in output_dict["values"].split(","):
                    index, description = value.split(":")
                    values[float(index)] = description
                output_dict["values"] = values

            # remap range to be a map of floats
            if "range" in output_dict:
                low, high = output_dict["range"].split()
                output_dict["range"] = {"low": float(low), "high": float(high)}

            # remap the string to a float
            if "increment" in output_dict:
                output_dict["increment"] = float(output_dict["increment"])

            # do any name changing desired
            for remap in self.explict_remap:
                output_dict[remap[1]] = output_dict.pop(remap[0])

            self.output += "\"" + name + "\" " + edn_format.dumps(output_dict, keyword_keys=True)
Exemple #26
0
 def test_fractions(self):
     for edn_data in (
         '0/1',
         '1/1',
         '1/2',
         '1/3',
         '-5/3',
         '99999999999999999999999999999999999/999999999999999999999999991',
     ):
         self.assertEqual(edn_data, dumps(loads(edn_data)), edn_data)
Exemple #27
0
 def __init__(self):
     self.output = "{:date " + edn_format.dumps(
         datetime.datetime.now(pytz.utc)) + " "
     git = subprocess.Popen(["git log --pretty=format:'%h'  -n 1"],
                            shell=True,
                            stdout=subprocess.PIPE).communicate()[0]
     self.output += ":git-hash \"" + git.decode("ascii") + "\" "
     self.remove_keys = ["real_path"]
     self.explict_remap = [["displayname", "display-name"]]
     self.vehicle_name = None
Exemple #28
0
 def test_fractions(self):
     for edn_data in (
             '0/1',
             '1/1',
             '1/2',
             '1/3',
             '-5/3',
             '99999999999999999999999999999999999/999999999999999999999999991',
     ):
         self.assertEqual(edn_data, dumps(loads(edn_data)), edn_data)
Exemple #29
0
    def test_round_trip_same(self):
        EDN_LITERALS = (
            "nil",
            "true",
            "false",
            '"hello world"',
            ":keyword",
            ":+",
            ":!",
            ":-",
            ":_",
            ":$",
            ":&",
            ":=",
            ":.",
            ":abc/def",
            #"symbol",
            "123",
            "-123",
            "32.23",
            "32.23M",
            "-32.23M",
            "3.23e-10",
            '["abc"]',
            '[1]',
            '[1 "abc"]',
            '[1 "abc" true]',
            '[:ghi]',
            '(:ghi)',
            '[1 "abc" true :ghi]',
            '(1 "abc" true :ghi)',
            #'#myapp/Person {:first "Fred" :last "Mertz',
            '#inst "1985-04-12T23:20:50Z"',
            '#uuid "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"',
            '#date "19/07/1984"')

        class TagDate(TaggedElement):
            def __init__(self, value):
                self.name = 'date'
                self.value = datetime.datetime.strptime(value,
                                                        "%d/%m/%Y").date()

            def __str__(self):
                return '#{} "{}"'.format(self.name,
                                         self.value.strftime("%d/%m/%Y"))

        add_tag('date', TagDate)

        for literal in EDN_LITERALS:
            step1 = literal
            step2 = loads(step1)
            step3 = dumps(step2)
            #            print step1, "->", step2, "->", step3
            self.assertEqual(step1, step3)
Exemple #30
0
def route_stop_mk():
    global status
    global mklauncher
    global configserver
    global linuxcnc
    stop_process(mklauncher)
    stop_process(configserver)
    stop_process(linuxcnc)
    stop_process(resolver)
    if status["mk_running"]:
        status["mk_running"] = False
    return edn.dumps(status)
Exemple #31
0
def parse_recipe(recipe_str):
    parsed = edn.loads('{' + recipe_str + '}')
    parse_kws = lambda d: {k.name: d.dict[k] for k in d.dict.keys()}
    recipe = parse_kws(parsed)
    ings = parse_ingredients(recipe['ingredients'])
    title = edn.dumps(recipe['title'])

    return {
        'title': title,
        'ingredients': ings,
        'description': recipe['description']
    }
Exemple #32
0
def dump_edn_val(v):
  " edn simple value dump"
  print(v, type(v), repr(E), type(E), isinstance(v, E), isinstance(v, collections.Mapping))
  if isinstance(v, str):
    return json.dumps(v)
  elif isinstance(v, list):
  #   print('list:map::', list(map(dump_edn_val, v)), repr(list(map(dump_edn_val, v))))
  #   return json.dumps(list(map(dump_edn_val, v)))#str(v)#json.dumps(list(map(str, v)))
    print('list:map::', list(map(dump_edn_val, v)), json.dumps(list(map(dump_edn_val, v))), dumps(list(map(dump_edn_val, v))))
    return json.dumps(list(map(dump_edn_val, v)))
  elif isinstance(v, bool):
    return json.dumps(v)
  elif isinstance(v, E):#(E, collections.Mapping)):
    print("E", v, repr(v), v.eid, u':db/id #db/id[:db.part/user %(e)s' % {'e': v.eid})
    # return u'#db/id[:db.part/user %(e)s]' % {'e': v.eid}
    return str(v)
  elif isinstance(v, int):
    return v
  else:
    print("else", dumps(v))
    return dumps(v)
 def send_stuff(self, port, painload):
     self.logger.info("Sending %s", str(painload))
     sock = socket(AF_INET, SOCK_STREAM)
     sock.connect((self._ip, port))
     sock.sendall(edn_format.dumps(
         {Keyword(k): v for k, v in painload.items()}).encode('utf8'))
     response = sock.recv(65535)
     self.logger.info('begin response')
     self.logger.info(response.decode('utf8'))
     self.logger.info('end response')
     val = edn_format.loads(response.decode('utf8') + " ")
     sock.close()
     return val
Exemple #34
0
    def test_keyword_keys(self):
        unchanged = (
            None,
            True,
            1,
            "foo",
            {},
            {True: 42},
            {25: 42},
            {3.14: "test"},
            {Keyword("foo"): "something"},
            {Symbol("foo"): "something"},
            ["foo", "bar"],
            ("foo", "bar"),
            {1: {2: 3}},
            ImmutableDict({1: 2}),
        )

        for case in unchanged:
            self.check_roundtrip(case, keyword_keys=True)

        keyworded_keys = (
            ("{:foo 42}", {"foo": 42}),
            ("{:a {:b {:c 42} :d 1}}", {"a": {"b": {"c": 42}, "d": 1}}),
            ("[{:a 42} {:b 25}]", [{"a": 42}, {"b": 25}]),
            ("({:a 42} {:b 25})", ({"a": 42}, {"b": 25})),
            ("{1 [{:a 42}]}", {1: [{"a": 42}]}),
            ("{:foo 1}", ImmutableDict({"foo": 1})),
        )

        for expected, data in keyworded_keys:
            self.assertEqual(expected, dumps(data, keyword_keys=True))

        self.assertEqual(
                {Keyword("a"): {Keyword("b"): 2}, 3: 4},
                loads(dumps({Keyword("a"): {"b": 2}, 3: 4}, keyword_keys=True)))
Exemple #35
0
    def test_discard_all(self):
        for edn_data in (
            '42', '-1', 'nil', 'true', 'false', '"foo"', '\\space', '\\a',
            ':foo', ':foo/bar', '[]', '{}', '#{}', '()', '(a)', '(a b)',
            '[a [[[b] c]] 2]', '#inst "2017"',
        ):
            self.assertEqual([1], loads('[1 #_ {}]'.format(edn_data)), edn_data)
            self.assertEqual([1], loads('[#_ {} 1]'.format(edn_data)), edn_data)

            self.check_eof('#_ {}'.format(edn_data))

            for coll in ('[%s]', '(%s)', '{%s}', '#{%s}'):
                expected = coll % ""
                edn_data = coll % '#_ {}'.format(edn_data)
                self.assertEqual(expected, dumps(loads(edn_data)), edn_data)
Exemple #36
0
    def test_keyword_keys(self):
        unchanged = (
            None,
            True,
            1,
            "foo",
            {},
            {True: 42},
            {25: 42},
            {3.14: "test"},
            {Keyword("foo"): "something"},
            {Symbol("foo"): "something"},
            ["foo", "bar"],
            ("foo", "bar"),
            {1: {2: 3}},
            ImmutableDict({1: 2}),
        )

        for case in unchanged:
            self.check_roundtrip(case, keyword_keys=True)

        keyworded_keys = (
            ("{:foo 42}", {"foo": 42}),
            ("{:a {:b {:c 42} :d 1}}", {"a": {"b": {"c": 42}, "d": 1}}),
            ("[{:a 42} {:b 25}]", [{"a": 42}, {"b": 25}]),
            ("({:a 42} {:b 25})", ({"a": 42}, {"b": 25})),
            ("{1 [{:a 42}]}", {1: [{"a": 42}]}),
            ("{:foo 1}", ImmutableDict({"foo": 1})),
        )

        for expected, data in keyworded_keys:
            self.assertEqual(expected, dumps(data, keyword_keys=True))

        self.assertEqual(
                {Keyword("a"): {Keyword("b"): 2}, 3: 4},
                loads(dumps({Keyword("a"): {"b": 2}, 3: 4}, keyword_keys=True)))
Exemple #37
0
    def test_round_trip_conversion(self):
        edn_literals = [
            ["[ :ghi ]", "[:ghi]"],
            ["[:a #_foo 42]", "[:a 42]"],
            ["123N", "123"],
            ["-123N", "-123"],
            ["+123", "123"],
            ["+123N", "123"],
            ["123.2", "123.2"],
            ["+32.23M", "32.23M"],
            ["3.23e10", "32300000000.0"],
            ["3e10", "30000000000.0"],
        ]

        for literal in edn_literals:
            step1 = literal[0]
            step2 = loads(step1)
            step3 = dumps(step2)
            self.assertEqual(literal[1], step3)
Exemple #38
0
    def generate(self, joint_dict, changed_joint_names, enabled_joint_names,
                 is_blocking=False, keyframe_duration=None, **kwargs):
        if changed_joint_names:
            changed_joints = {}
            for j in changed_joint_names:
                changed_joints[j] = joint_dict[j]

            state = {}
            for j in enabled_joint_names:
                state[j] = joint_dict[j]

            edn_map = { "is_blocking" : is_blocking,
                         "state" : state,
                         "changes" : changed_joints }

            if keyframe_duration:
                edn_map["duration"] = keyframe_duration

            return edn_format.dumps(edn_map)
        else:
            return ''
Exemple #39
0
 def test_discard(self):
     for expected, edn_data in (
         ('[x]', '[x #_ z]'),
         ('[z]', '[#_ x z]'),
         ('[x z]', '[x #_ y z]'),
         ('{1 4}', '{1 #_ 2 #_ 3 4}'),
         ('[1 2]', '[1 #_ [ #_ [ #_ [ #_ [ #_ 42 ] ] ] ] 2 ]'),
         ('[1 2 11]', '[1 2 #_ #_ #_ #_ 4 5 6 #_ 7 #_ #_ 8 9 10 11]'),
         ('()', '(#_(((((((1))))))))'),
         ('[6]', '[#_ #_ #_ #_ #_ 1 2 3 4 5 6]'),
         ('[4]', '[#_ #_ 1 #_ 2 3 4]'),
         ('{:a 1}', '{:a #_:b 1}'),
         ('[42]', '[42 #_ {:a [1 2 3 4] true false 1 #inst "2017"}]'),
         ('#{1}', '#{1 #_foo}'),
         ('"#_ foo"', '"#_ foo"'),
         ('["#" _]', r'[\#_]'),
         ('[_]', r'[#_\#_]'),
         ('[1]', '[1 #_\n\n42]'),
         ('{}', '{#_ 1}'),
     ):
         self.assertEqual(expected, dumps(loads(edn_data)), edn_data)
Exemple #40
0
 def test_discard(self):
     for expected, edn_data in (
         ('[x]', '[x #_ z]'),
         ('[z]', '[#_ x z]'),
         ('[x z]', '[x #_ y z]'),
         ('{1 4}', '{1 #_ 2 #_ 3 4}'),
         ('[1 2]', '[1 #_ [ #_ [ #_ [ #_ [ #_ 42 ] ] ] ] 2 ]'),
         ('[1 2 11]', '[1 2 #_ #_ #_ #_ 4 5 6 #_ 7 #_ #_ 8 9 10 11]'),
         ('()', '(#_(((((((1))))))))'),
         ('[6]', '[#_ #_ #_ #_ #_ 1 2 3 4 5 6]'),
         ('[4]', '[#_ #_ 1 #_ 2 3 4]'),
         ('{:a 1}', '{:a #_:b 1}'),
         ('[42]', '[42 #_ {:a [1 2 3 4] true false 1 #inst "2017"}]'),
         ('#{1}', '#{1 #_foo}'),
         ('"#_ foo"', '"#_ foo"'),
         (r'[\# _]', r'[\#_]'),
         ('[_]', r'[#_\#_]'),
         ('[1]', '[1 #_\n\n42]'),
         ('{}', '{#_ 1}'),
     ):
         self.assertEqual(expected, dumps(loads(edn_data)), edn_data)
Exemple #41
0
def expand_rules(rule_file, params):
    """Expand rules with ontology lookups to avoid need for SciGraph during runs.
    """
    rules = _read_rules(rule_file)
    out_rules = []
    for r in rules:
        term = _term_from_rule(r, params["scigraph"], params.get("lookup_db"))
        term["pat"] = r["pat"].replace("?P<", "?<")
        if term["pat"] == term["term"]:
            term["pat"] = "^%s$" % term["pat"]
        for inherit in ["ns", "units-in-val", "common-key", "chemical"]:
            if r.get(inherit):
                term[inherit] = r[inherit]
        out_rules.append(term)
    out_file = "%s-finalized.edn" % os.path.splitext(rule_file)[0]
    with open(out_file, "w") as out_handle:
        out_handle.write("{:rules\n[\n")
        for r in out_rules:
            out_handle.write(edn_format.dumps(r, keyword_keys=True, sort_keys=True) + "\n")
        out_handle.write("]}")
    return out_rules
Exemple #42
0
    def test_round_trip_conversion(self):
        EDN_LITERALS = [
            [r"\c", '"c"'],
            ["[ :ghi ]", "[:ghi]"],
            ["[:a #_foo 42]", "[:a 42]"],
            ["123N", "123"],
            ["-123N", "-123"],
            ["+123", "123"],
            ["+123N", "123"],
            ["123.2", "123.2"],
            ["+32.23M", "32.23M"],
            ["3.23e10", "32300000000.0"],
            ["3e10", "30000000000.0"],
        ]

        for literal in EDN_LITERALS:
            step1 = literal[0]
            step2 = loads(step1)
            step3 = dumps(step2)
            if isinstance(literal[1], list):
                self.assertIn(step3, literal[1])
            else:
                self.assertEqual(literal[1], step3)
Exemple #43
0
 def check_roundtrip(self, data_input, **kw):
     self.assertEqual(data_input, loads(dumps(data_input, **kw)))
Exemple #44
0
  def __str__(self): 
     return "#myapp/Person " + edn_format.dump(self.value)

edn_format.add_tag("myapp/Person", MyappPerson)

validEdnDir = "../../../../valid-edn"
results = {}

for ednFile in [f for f in listdir(validEdnDir) if isfile(join(validEdnDir, f))]:
  ednFileName = ednFile.split(".")[0]
  validEdn = open(join(validEdnDir, ednFileName + ".edn"), "r").read()
  expectedPy = open(join("..", ednFileName + ".py"), "r").read()
  if debug: 
    print ednFileName
  try: 
    expected = eval(expectedPy)
    parsed = edn_format.loads(validEdn)
    result = expected == parsed
    if not result and debug:
      print "Values did not match", "\n\tEXPECTED: ", edn_format.dumps(expected), "\n\tPARSED: ", edn_format.dumps(parsed), "\n\tEDN: ", validEdn
    results[edn_format.Symbol(ednFileName)] = result
  except:
    e = sys.exc_info()[0] 
    results[edn_format.Symbol(ednFileName)] = False
    if debug:
      print "\tFailed to parse.", validEdn, e

print edn_format.dumps(results)

import requests
import edn_format as edn
'''
r = requests.get('http://localhost:3001')
print(r.text)
print(r.content)
#print(r.json())
print(edn_format.loads(r.text))


r = requests.post(
    'http://localhost:3001',
    data = edn_format.dumps(
        {1: [1,2,3,4,5], "asdf": 123}
    )
)
'''
import sys

dat = edn.dumps({
    1: sys.argv[1],
    "asdf": 123,
    edn.Symbol("sym"): edn.Keyword(123)
})
#print(dir(edn))

for _ in range(10):
    r = requests.post('http://localhost:3001', data=sys.argv[1])
Exemple #46
0
                          "</a>")
                print("</td>")
                # Version
                print("<td>")
                if db_version_file is not None:
                    print("<a href='" + cpath + "?version-details=1&path=" + urllib.parse.quote_plus(db_version_file) +
                          "' class='btn btn-%s btn-xs'>" % status + db_thisver + 
                          " <span class='glyphicon glyphicon-info-sign'></span></a>")
                print("</td>")
                # Details
                print("<td>")
                dtk = edn_format.Keyword('details')
                if dtk not in r:
                    dtk = edn_format.Keyword('error')
                if dtk in r:
                    dstr = edn_format.dumps(r[dtk])
                    if len(dstr) > 60:
                        dstr = dstr[:60] + "... <a href='" + cpath + "?path=" + urllib.parse.quote_plus(ednpath) + "'>(more)</a>"
                    print("<tt class='small'>" + dstr + "</tt>")
                print("</td>")

                # Node logs
                print("<td>")
                print("<a href='" + cpath + "?path=" + urllib.parse.quote_plus(dpath) + "&merge-logs=1' class='btn btn-%s btn-xs'>" % status +
                      "<span class='glyphicon glyphicon-filter'></span></a>")
                logs = sorted(glob.glob(os.path.join(dpath, "*/cockroach.stderr")))
                if len(logs) > 0:
                    for log in logs:
                        print("<a href='" + cpath + "?path=" + urllib.parse.quote_plus(log) + "' class='btn btn-%s btn-xs'>" % status +
                              "<span class='glyphicon glyphicon-info-sign'></span></a>")
                print("</td>")
Exemple #47
0
    def printer(obj, add_end_unit=True):
        out.write(edn_format.dumps(obj))

        if add_end_unit:
            out.write(END_UNIT)
Exemple #48
0
def parse_ingredients(ings):
    Quant = namedtuple('Quant', 'quant unit keyword')
    parse_ing = lambda ing: [edn.dumps(item) for item in ing]

    return [Quant(*parse_ing(i)) for i in ings]
Exemple #49
0
 def __str__(self):
     return "#y.E {}".format(edn_format.dumps(self.value))
Exemple #50
0
def running():
    status['mk_running'] = (configserver != None and configserver.poll() == None)
    return edn.dumps(status['mk_running'])
Exemple #51
0
def ping(port):
    send_data(port, MT_PING)
    return edn.dumps(status)
Exemple #52
0
def print_error(reason, status, out):
    err = Error(dict(reason=reason, status=status))
    out.write(edn_format.dumps(err))
    out.write(END_UNIT)
Exemple #53
0
 def __str__(self):
     return "#y.File {}".format(edn_format.dumps(self.to_dict()))
Exemple #54
0
def route_run_mk():
    global status
    run_mk()
    if not status["mk_running"]:
        status["mk_running"] = True
    return edn.dumps(status)
Exemple #55
0
def route_services_log():
    global service_log_path
    text = open(service_log_path).read()
    return edn.dumps({"log": text})
Exemple #56
0
def route_status():
    global status
    return edn.dumps(status)
Exemple #57
0
def serialize(data):
    return edn_format.dumps(data)
Exemple #58
0
 def check_dump(self, expected_output, actual_input):
     if isinstance(expected_output, list):
         self.assertIn(dumps(actual_input), expected_output)
     else:
         self.assertEqual(expected_output, dumps(actual_input))