Skip to content

Commit

Permalink
deploy: 71d68a6
Browse files Browse the repository at this point in the history
  • Loading branch information
mieskolainen committed Jul 25, 2024
1 parent 8ac4bab commit 0084965
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions _modules/icenet/tools/aux.html
Original file line number Diff line number Diff line change
Expand Up @@ -563,13 +563,13 @@ <h1>Source code for icenet.tools.aux</h1><div class="highlight"><pre>
<span class="k">def</span> <span class="nf">block_style_dict_representer</span><span class="p">(</span><span class="n">dumper</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="k">return</span> <span class="n">dumper</span><span class="o">.</span><span class="n">represent_mapping</span><span class="p">(</span><span class="s1">&#39;tag:yaml.org,2002:map&#39;</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">flow_style</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>

<span class="c1"># Register the custom representers</span>
<span class="n">yaml</span><span class="o">.</span><span class="n">add_representer</span><span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="n">flow_style_list_representer</span><span class="p">)</span>
<span class="n">yaml</span><span class="o">.</span><span class="n">add_representer</span><span class="p">(</span><span class="nb">dict</span><span class="p">,</span> <span class="n">block_style_dict_representer</span><span class="p">)</span>

<span class="k">class</span> <span class="nc">NoSortDumper</span><span class="p">(</span><span class="n">yaml</span><span class="o">.</span><span class="n">Dumper</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">represent_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">represent_mapping</span><span class="p">(</span><span class="s1">&#39;tag:yaml.org,2002:map&#39;</span><span class="p">,</span> <span class="n">data</span><span class="o">.</span><span class="n">items</span><span class="p">(),</span> <span class="n">flow_style</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>

<span class="c1"># Register the custom representers with NoSortDumper</span>
<span class="n">NoSortDumper</span><span class="o">.</span><span class="n">add_representer</span><span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="n">flow_style_list_representer</span><span class="p">)</span>
<span class="n">NoSortDumper</span><span class="o">.</span><span class="n">add_representer</span><span class="p">(</span><span class="nb">dict</span><span class="p">,</span> <span class="n">block_style_dict_representer</span><span class="p">)</span>

<span class="c1"># Save the YAML string with mixed styles to a file</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">yaml_file</span><span class="p">:</span>
Expand Down

0 comments on commit 0084965

Please sign in to comment.