コード例 #1
0
ファイル: test_resolver.py プロジェクト: JSchwerberg/pyyaml
def test_path_resolver_loader(data_filename, path_filename, verbose=False):
    _make_path_loader_and_dumper()
    nodes1 = list(yaml.compose_all(open(data_filename, "rb").read(), Loader=MyLoader))
    nodes2 = list(yaml.compose_all(open(path_filename, "rb").read()))
    try:
        for node1, node2 in zip(nodes1, nodes2):
            data1 = _convert_node(node1)
            data2 = _convert_node(node2)
            assert data1 == data2, (data1, data2)
    finally:
        if verbose:
            print yaml.serialize_all(nodes1)
コード例 #2
0
def test_path_resolver_loader(data_filename, path_filename, verbose=False):
    _make_path_loader_and_dumper()
    nodes1 = list(
        yaml.compose_all(open(data_filename, 'rb').read(), Loader=MyLoader))
    nodes2 = list(yaml.compose_all(open(path_filename, 'rb').read()))
    try:
        for node1, node2 in zip(nodes1, nodes2):
            data1 = _convert_node(node1)
            data2 = _convert_node(node2)
            assert data1 == data2, (data1, data2)
    finally:
        if verbose:
            print yaml.serialize_all(nodes1)
コード例 #3
0
def index(request):
    yamlcanon = u""; # YAML in canonical form.
    yamlerror = u"" # YAML error messages.
    yamloriginal = u"" # The original text. Shown only for error messages.
    yamlstate = STATE_GET # The state of the page.
    ourmap = {"yamlstate": yamlstate, "yamlcanon": yamlcanon, 
        "yamlerror": yamlerror, "yamloriginal": yamloriginal};
    if request.method == 'GET':
        ourmap.update(csrf(request));
        context = RequestContext(request, ourmap);
    else: # POST request.
        try:
            ourtarget = request.POST.get("yamlarea");
            composition = yaml.compose_all(ourtarget, Loader12);
            yamlcanon = yaml.serialize_all(composition, 
                canonical=True, allow_unicode=True);
            ourmap["yamlstate"] = STATE_POST_YES;
            if len(yamlcanon) == 0:
                ourmap["yamlcanon"] = COMMENTSTR
            else:
                ourmap["yamlcanon"] = yamlcanon;
                
# PKM2014 - AttributeErrors are now caught.                
                
        except (YAMLError, AttributeError) as e:
            ourmap["yamlstate"] = STATE_POST_NO;
            ourmap["yamlerror"] = e.__str__();
            ourmap["yamloriginal"] = ourtarget;
        ourmap.update(csrf(request));
        context = RequestContext(request, ourmap);
    
    return TemplateResponse(request, 'isityaml/isityaml.html', context=context)   
コード例 #4
0
ファイル: views.py プロジェクト: peterkmurphy/isityaml
def index(request):
    yamlcanon = u""; # YAML in canonical form.
    yamlerror = u"" # YAML error messages.
    yamloriginal = u"" # The original text. Shown only for error messages.
    yamlstate = STATE_GET # The state of the page.
    ourmap = {"yamlstate": yamlstate, "yamlcanon": yamlcanon,
        "yamlerror": yamlerror, "yamloriginal": yamloriginal};
    if request.method == 'GET':
        pass; # Everything we need is in ourmap already.
    else: # POST request.
        try:
            ourtarget = request.POST.get("yamlarea");
            composition = compose_all(ourtarget, Loader12);
            yamlcanon = serialize_all(composition,
                canonical=True, allow_unicode=True);
            ourmap["yamlstate"] = STATE_POST_YES;
            if len(yamlcanon) == 0:
                ourmap["yamlcanon"] = COMMENTSTR
            else:
                ourmap["yamlcanon"] = yamlcanon;

# PKM2014 - AttributeErrors are now caught.

        except (YAMLError, AttributeError) as e:
            ourmap["yamlstate"] = STATE_POST_NO;
            ourmap["yamlerror"] = e.__str__();
            ourmap["yamloriginal"] = ourtarget;
    return render(request, 'isityaml/isityaml.html', ourmap)
コード例 #5
0
ファイル: test_resolver.py プロジェクト: JSchwerberg/pyyaml
def test_path_resolver_dumper(data_filename, path_filename, verbose=False):
    _make_path_loader_and_dumper()
    for filename in [data_filename, path_filename]:
        output = yaml.serialize_all(yaml.compose_all(open(filename, "rb")), Dumper=MyDumper)
        if verbose:
            print output
        nodes1 = yaml.compose_all(output)
        nodes2 = yaml.compose_all(open(data_filename, "rb"))
        for node1, node2 in zip(nodes1, nodes2):
            data1 = _convert_node(node1)
            data2 = _convert_node(node2)
            assert data1 == data2, (data1, data2)
コード例 #6
0
def test_path_resolver_dumper(data_filename, path_filename, verbose=False):
    _make_path_loader_and_dumper()
    for filename in [data_filename, path_filename]:
        output = yaml.serialize_all(yaml.compose_all(open(filename, 'rb')),
                                    Dumper=MyDumper)
        if verbose:
            print(output)
        nodes1 = yaml.compose_all(output)
        nodes2 = yaml.compose_all(open(data_filename, 'rb'))
        for node1, node2 in zip(nodes1, nodes2):
            data1 = _convert_node(node1)
            data2 = _convert_node(node2)
            assert data1 == data2, (data1, data2)