gitlab-pygments.rb 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +2 -0
- data/README.md +91 -0
- data/Rakefile +78 -0
- data/bench.rb +22 -0
- data/cache-lexers.rb +8 -0
- data/lexers +0 -0
- data/lib/pygments/lexer.rb +148 -0
- data/lib/pygments/mentos.py +344 -0
- data/lib/pygments/popen.rb +389 -0
- data/lib/pygments/version.rb +3 -0
- data/lib/pygments.rb +8 -0
- data/pygments.rb.gemspec +24 -0
- data/test/test_data.c +2581 -0
- data/test/test_data.py +514 -0
- data/test/test_data_generated +2582 -0
- data/test/test_pygments.rb +276 -0
- data/vendor/custom_formatters/gitlab.py +171 -0
- data/vendor/custom_lexers/github.py +362 -0
- data/vendor/pygments-main/AUTHORS +115 -0
- data/vendor/pygments-main/CHANGES +762 -0
- data/vendor/pygments-main/LICENSE +25 -0
- data/vendor/pygments-main/MANIFEST.in +6 -0
- data/vendor/pygments-main/Makefile +59 -0
- data/vendor/pygments-main/REVISION +1 -0
- data/vendor/pygments-main/TODO +15 -0
- data/vendor/pygments-main/docs/generate.py +472 -0
- data/vendor/pygments-main/docs/pygmentize.1 +94 -0
- data/vendor/pygments-main/docs/src/api.txt +270 -0
- data/vendor/pygments-main/docs/src/authors.txt +5 -0
- data/vendor/pygments-main/docs/src/changelog.txt +5 -0
- data/vendor/pygments-main/docs/src/cmdline.txt +147 -0
- data/vendor/pygments-main/docs/src/filterdevelopment.txt +70 -0
- data/vendor/pygments-main/docs/src/filters.txt +42 -0
- data/vendor/pygments-main/docs/src/formatterdevelopment.txt +169 -0
- data/vendor/pygments-main/docs/src/formatters.txt +48 -0
- data/vendor/pygments-main/docs/src/index.txt +69 -0
- data/vendor/pygments-main/docs/src/installation.txt +71 -0
- data/vendor/pygments-main/docs/src/integrate.txt +43 -0
- data/vendor/pygments-main/docs/src/lexerdevelopment.txt +551 -0
- data/vendor/pygments-main/docs/src/lexers.txt +67 -0
- data/vendor/pygments-main/docs/src/moinmoin.txt +39 -0
- data/vendor/pygments-main/docs/src/plugins.txt +93 -0
- data/vendor/pygments-main/docs/src/quickstart.txt +202 -0
- data/vendor/pygments-main/docs/src/rstdirective.txt +22 -0
- data/vendor/pygments-main/docs/src/styles.txt +143 -0
- data/vendor/pygments-main/docs/src/tokens.txt +349 -0
- data/vendor/pygments-main/docs/src/unicode.txt +49 -0
- data/vendor/pygments-main/external/markdown-processor.py +67 -0
- data/vendor/pygments-main/external/moin-parser.py +112 -0
- data/vendor/pygments-main/external/pygments.bashcomp +38 -0
- data/vendor/pygments-main/external/rst-directive-old.py +77 -0
- data/vendor/pygments-main/external/rst-directive.py +83 -0
- data/vendor/pygments-main/ez_setup.py +276 -0
- data/vendor/pygments-main/pygmentize +7 -0
- data/vendor/pygments-main/pygments/__init__.py +91 -0
- data/vendor/pygments-main/pygments/cmdline.py +433 -0
- data/vendor/pygments-main/pygments/console.py +74 -0
- data/vendor/pygments-main/pygments/filter.py +74 -0
- data/vendor/pygments-main/pygments/filters/__init__.py +357 -0
- data/vendor/pygments-main/pygments/formatter.py +92 -0
- data/vendor/pygments-main/pygments/formatters/__init__.py +68 -0
- data/vendor/pygments-main/pygments/formatters/_mapping.py +94 -0
- data/vendor/pygments-main/pygments/formatters/bbcode.py +109 -0
- data/vendor/pygments-main/pygments/formatters/gitlab.py +171 -0
- data/vendor/pygments-main/pygments/formatters/html.py +750 -0
- data/vendor/pygments-main/pygments/formatters/img.py +553 -0
- data/vendor/pygments-main/pygments/formatters/latex.py +378 -0
- data/vendor/pygments-main/pygments/formatters/other.py +117 -0
- data/vendor/pygments-main/pygments/formatters/rtf.py +136 -0
- data/vendor/pygments-main/pygments/formatters/svg.py +154 -0
- data/vendor/pygments-main/pygments/formatters/terminal.py +112 -0
- data/vendor/pygments-main/pygments/formatters/terminal256.py +222 -0
- data/vendor/pygments-main/pygments/lexer.py +697 -0
- data/vendor/pygments-main/pygments/lexers/__init__.py +229 -0
- data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1645 -0
- data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +232 -0
- data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +249 -0
- data/vendor/pygments-main/pygments/lexers/_mapping.py +298 -0
- data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +3787 -0
- data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +232 -0
- data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +29 -0
- data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +3 -0
- data/vendor/pygments-main/pygments/lexers/agile.py +1803 -0
- data/vendor/pygments-main/pygments/lexers/asm.py +360 -0
- data/vendor/pygments-main/pygments/lexers/compiled.py +2891 -0
- data/vendor/pygments-main/pygments/lexers/dotnet.py +636 -0
- data/vendor/pygments-main/pygments/lexers/functional.py +1832 -0
- data/vendor/pygments-main/pygments/lexers/github.py +362 -0
- data/vendor/pygments-main/pygments/lexers/hdl.py +356 -0
- data/vendor/pygments-main/pygments/lexers/jvm.py +847 -0
- data/vendor/pygments-main/pygments/lexers/math.py +1072 -0
- data/vendor/pygments-main/pygments/lexers/other.py +3339 -0
- data/vendor/pygments-main/pygments/lexers/parsers.py +695 -0
- data/vendor/pygments-main/pygments/lexers/shell.py +361 -0
- data/vendor/pygments-main/pygments/lexers/special.py +100 -0
- data/vendor/pygments-main/pygments/lexers/sql.py +559 -0
- data/vendor/pygments-main/pygments/lexers/templates.py +1631 -0
- data/vendor/pygments-main/pygments/lexers/text.py +1753 -0
- data/vendor/pygments-main/pygments/lexers/web.py +2864 -0
- data/vendor/pygments-main/pygments/plugin.py +74 -0
- data/vendor/pygments-main/pygments/scanner.py +104 -0
- data/vendor/pygments-main/pygments/style.py +117 -0
- data/vendor/pygments-main/pygments/styles/__init__.py +70 -0
- data/vendor/pygments-main/pygments/styles/autumn.py +65 -0
- data/vendor/pygments-main/pygments/styles/borland.py +51 -0
- data/vendor/pygments-main/pygments/styles/bw.py +49 -0
- data/vendor/pygments-main/pygments/styles/colorful.py +81 -0
- data/vendor/pygments-main/pygments/styles/default.py +73 -0
- data/vendor/pygments-main/pygments/styles/emacs.py +72 -0
- data/vendor/pygments-main/pygments/styles/friendly.py +72 -0
- data/vendor/pygments-main/pygments/styles/fruity.py +42 -0
- data/vendor/pygments-main/pygments/styles/manni.py +75 -0
- data/vendor/pygments-main/pygments/styles/monokai.py +106 -0
- data/vendor/pygments-main/pygments/styles/murphy.py +80 -0
- data/vendor/pygments-main/pygments/styles/native.py +65 -0
- data/vendor/pygments-main/pygments/styles/pastie.py +75 -0
- data/vendor/pygments-main/pygments/styles/perldoc.py +69 -0
- data/vendor/pygments-main/pygments/styles/rrt.py +33 -0
- data/vendor/pygments-main/pygments/styles/tango.py +141 -0
- data/vendor/pygments-main/pygments/styles/trac.py +63 -0
- data/vendor/pygments-main/pygments/styles/vim.py +63 -0
- data/vendor/pygments-main/pygments/styles/vs.py +38 -0
- data/vendor/pygments-main/pygments/token.py +195 -0
- data/vendor/pygments-main/pygments/unistring.py +130 -0
- data/vendor/pygments-main/pygments/util.py +232 -0
- data/vendor/pygments-main/scripts/check_sources.py +242 -0
- data/vendor/pygments-main/scripts/detect_missing_analyse_text.py +30 -0
- data/vendor/pygments-main/scripts/epydoc.css +280 -0
- data/vendor/pygments-main/scripts/find_codetags.py +205 -0
- data/vendor/pygments-main/scripts/find_error.py +171 -0
- data/vendor/pygments-main/scripts/get_vimkw.py +43 -0
- data/vendor/pygments-main/scripts/pylintrc +301 -0
- data/vendor/pygments-main/scripts/reindent.py +291 -0
- data/vendor/pygments-main/scripts/vim2pygments.py +933 -0
- data/vendor/pygments-main/setup.cfg +6 -0
- data/vendor/pygments-main/setup.py +88 -0
- data/vendor/pygments-main/tests/dtds/HTML4-f.dtd +37 -0
- data/vendor/pygments-main/tests/dtds/HTML4-s.dtd +869 -0
- data/vendor/pygments-main/tests/dtds/HTML4.dcl +88 -0
- data/vendor/pygments-main/tests/dtds/HTML4.dtd +1092 -0
- data/vendor/pygments-main/tests/dtds/HTML4.soc +9 -0
- data/vendor/pygments-main/tests/dtds/HTMLlat1.ent +195 -0
- data/vendor/pygments-main/tests/dtds/HTMLspec.ent +77 -0
- data/vendor/pygments-main/tests/dtds/HTMLsym.ent +241 -0
- data/vendor/pygments-main/tests/examplefiles/ANTLRv3.g +608 -0
- data/vendor/pygments-main/tests/examplefiles/AcidStateAdvanced.hs +209 -0
- data/vendor/pygments-main/tests/examplefiles/AlternatingGroup.mu +102 -0
- data/vendor/pygments-main/tests/examplefiles/CPDictionary.j +611 -0
- data/vendor/pygments-main/tests/examplefiles/Constants.mo +158 -0
- data/vendor/pygments-main/tests/examplefiles/DancingSudoku.lhs +411 -0
- data/vendor/pygments-main/tests/examplefiles/Errors.scala +18 -0
- data/vendor/pygments-main/tests/examplefiles/File.hy +174 -0
- data/vendor/pygments-main/tests/examplefiles/Intro.java +1660 -0
- data/vendor/pygments-main/tests/examplefiles/Makefile +1131 -0
- data/vendor/pygments-main/tests/examplefiles/Object.st +4394 -0
- data/vendor/pygments-main/tests/examplefiles/OrderedMap.hx +584 -0
- data/vendor/pygments-main/tests/examplefiles/SmallCheck.hs +378 -0
- data/vendor/pygments-main/tests/examplefiles/Sorting.mod +470 -0
- data/vendor/pygments-main/tests/examplefiles/Sudoku.lhs +382 -0
- data/vendor/pygments-main/tests/examplefiles/addressbook.proto +30 -0
- data/vendor/pygments-main/tests/examplefiles/antlr_throws +1 -0
- data/vendor/pygments-main/tests/examplefiles/apache2.conf +393 -0
- data/vendor/pygments-main/tests/examplefiles/as3_test.as +143 -0
- data/vendor/pygments-main/tests/examplefiles/as3_test2.as +46 -0
- data/vendor/pygments-main/tests/examplefiles/as3_test3.as +3 -0
- data/vendor/pygments-main/tests/examplefiles/aspx-cs_example +27 -0
- data/vendor/pygments-main/tests/examplefiles/badcase.java +2 -0
- data/vendor/pygments-main/tests/examplefiles/batchfile.bat +49 -0
- data/vendor/pygments-main/tests/examplefiles/boot-9.scm +1557 -0
- data/vendor/pygments-main/tests/examplefiles/cells.ps +515 -0
- data/vendor/pygments-main/tests/examplefiles/ceval.c +2604 -0
- data/vendor/pygments-main/tests/examplefiles/cheetah_example.html +13 -0
- data/vendor/pygments-main/tests/examplefiles/classes.dylan +40 -0
- data/vendor/pygments-main/tests/examplefiles/condensed_ruby.rb +10 -0
- data/vendor/pygments-main/tests/examplefiles/coq_RelationClasses +447 -0
- data/vendor/pygments-main/tests/examplefiles/database.pytb +20 -0
- data/vendor/pygments-main/tests/examplefiles/de.MoinMoin.po +2461 -0
- data/vendor/pygments-main/tests/examplefiles/demo.ahk +181 -0
- data/vendor/pygments-main/tests/examplefiles/demo.cfm +38 -0
- data/vendor/pygments-main/tests/examplefiles/django_sample.html+django +68 -0
- data/vendor/pygments-main/tests/examplefiles/dwarf.cw +17 -0
- data/vendor/pygments-main/tests/examplefiles/erl_session +10 -0
- data/vendor/pygments-main/tests/examplefiles/escape_semicolon.clj +1 -0
- data/vendor/pygments-main/tests/examplefiles/evil_regex.js +48 -0
- data/vendor/pygments-main/tests/examplefiles/example.c +2080 -0
- data/vendor/pygments-main/tests/examplefiles/example.cls +15 -0
- data/vendor/pygments-main/tests/examplefiles/example.cpp +2363 -0
- data/vendor/pygments-main/tests/examplefiles/example.gs +106 -0
- data/vendor/pygments-main/tests/examplefiles/example.gst +7 -0
- data/vendor/pygments-main/tests/examplefiles/example.kt +47 -0
- data/vendor/pygments-main/tests/examplefiles/example.lua +250 -0
- data/vendor/pygments-main/tests/examplefiles/example.moo +26 -0
- data/vendor/pygments-main/tests/examplefiles/example.moon +629 -0
- data/vendor/pygments-main/tests/examplefiles/example.nim +1010 -0
- data/vendor/pygments-main/tests/examplefiles/example.ns2 +69 -0
- data/vendor/pygments-main/tests/examplefiles/example.p +34 -0
- data/vendor/pygments-main/tests/examplefiles/example.pas +2708 -0
- data/vendor/pygments-main/tests/examplefiles/example.rb +1852 -0
- data/vendor/pygments-main/tests/examplefiles/example.rhtml +561 -0
- data/vendor/pygments-main/tests/examplefiles/example.sh-session +19 -0
- data/vendor/pygments-main/tests/examplefiles/example.sml +156 -0
- data/vendor/pygments-main/tests/examplefiles/example.snobol +15 -0
- data/vendor/pygments-main/tests/examplefiles/example.tea +34 -0
- data/vendor/pygments-main/tests/examplefiles/example.u +548 -0
- data/vendor/pygments-main/tests/examplefiles/example.weechatlog +9 -0
- data/vendor/pygments-main/tests/examplefiles/example.xhtml +376 -0
- data/vendor/pygments-main/tests/examplefiles/example.yaml +302 -0
- data/vendor/pygments-main/tests/examplefiles/example2.aspx +29 -0
- data/vendor/pygments-main/tests/examplefiles/example_elixir.ex +363 -0
- data/vendor/pygments-main/tests/examplefiles/example_file.fy +128 -0
- data/vendor/pygments-main/tests/examplefiles/firefox.mak +586 -0
- data/vendor/pygments-main/tests/examplefiles/flipflop.sv +19 -0
- data/vendor/pygments-main/tests/examplefiles/foo.sce +6 -0
- data/vendor/pygments-main/tests/examplefiles/format.ml +1213 -0
- data/vendor/pygments-main/tests/examplefiles/fucked_up.rb +77 -0
- data/vendor/pygments-main/tests/examplefiles/function.mu +1 -0
- data/vendor/pygments-main/tests/examplefiles/functional.rst +1472 -0
- data/vendor/pygments-main/tests/examplefiles/genclass.clj +510 -0
- data/vendor/pygments-main/tests/examplefiles/genshi_example.xml+genshi +193 -0
- data/vendor/pygments-main/tests/examplefiles/genshitext_example.genshitext +33 -0
- data/vendor/pygments-main/tests/examplefiles/glsl.frag +7 -0
- data/vendor/pygments-main/tests/examplefiles/glsl.vert +13 -0
- data/vendor/pygments-main/tests/examplefiles/html+php_faulty.php +1 -0
- data/vendor/pygments-main/tests/examplefiles/http_request_example +14 -0
- data/vendor/pygments-main/tests/examplefiles/http_response_example +27 -0
- data/vendor/pygments-main/tests/examplefiles/import.hs +4 -0
- data/vendor/pygments-main/tests/examplefiles/intro.ik +24 -0
- data/vendor/pygments-main/tests/examplefiles/ints.php +10 -0
- data/vendor/pygments-main/tests/examplefiles/intsyn.fun +675 -0
- data/vendor/pygments-main/tests/examplefiles/intsyn.sig +286 -0
- data/vendor/pygments-main/tests/examplefiles/irb_heredoc +8 -0
- data/vendor/pygments-main/tests/examplefiles/irc.lsp +214 -0
- data/vendor/pygments-main/tests/examplefiles/java.properties +16 -0
- data/vendor/pygments-main/tests/examplefiles/jbst_example1.jbst +28 -0
- data/vendor/pygments-main/tests/examplefiles/jbst_example2.jbst +45 -0
- data/vendor/pygments-main/tests/examplefiles/jinjadesignerdoc.rst +713 -0
- data/vendor/pygments-main/tests/examplefiles/lighttpd_config.conf +13 -0
- data/vendor/pygments-main/tests/examplefiles/linecontinuation.py +47 -0
- data/vendor/pygments-main/tests/examplefiles/ltmain.sh +2849 -0
- data/vendor/pygments-main/tests/examplefiles/main.cmake +42 -0
- data/vendor/pygments-main/tests/examplefiles/markdown.lsp +679 -0
- data/vendor/pygments-main/tests/examplefiles/matlab_noreturn +3 -0
- data/vendor/pygments-main/tests/examplefiles/matlab_sample +27 -0
- data/vendor/pygments-main/tests/examplefiles/matlabsession_sample.txt +37 -0
- data/vendor/pygments-main/tests/examplefiles/minimal.ns2 +4 -0
- data/vendor/pygments-main/tests/examplefiles/moin_SyntaxReference.txt +340 -0
- data/vendor/pygments-main/tests/examplefiles/multiline_regexes.rb +38 -0
- data/vendor/pygments-main/tests/examplefiles/nasm_aoutso.asm +96 -0
- data/vendor/pygments-main/tests/examplefiles/nasm_objexe.asm +30 -0
- data/vendor/pygments-main/tests/examplefiles/nemerle_sample.n +87 -0
- data/vendor/pygments-main/tests/examplefiles/nginx_nginx.conf +118 -0
- data/vendor/pygments-main/tests/examplefiles/numbers.c +12 -0
- data/vendor/pygments-main/tests/examplefiles/objc_example.m +25 -0
- data/vendor/pygments-main/tests/examplefiles/objc_example2.m +24 -0
- data/vendor/pygments-main/tests/examplefiles/perl_misc +62 -0
- data/vendor/pygments-main/tests/examplefiles/perl_perl5db +998 -0
- data/vendor/pygments-main/tests/examplefiles/perl_regex-delims +120 -0
- data/vendor/pygments-main/tests/examplefiles/perlfunc.1 +856 -0
- data/vendor/pygments-main/tests/examplefiles/phpcomplete.vim +567 -0
- data/vendor/pygments-main/tests/examplefiles/pleac.in.rb +1223 -0
- data/vendor/pygments-main/tests/examplefiles/postgresql_test.txt +47 -0
- data/vendor/pygments-main/tests/examplefiles/pppoe.applescript +10 -0
- data/vendor/pygments-main/tests/examplefiles/psql_session.txt +122 -0
- data/vendor/pygments-main/tests/examplefiles/py3_test.txt +2 -0
- data/vendor/pygments-main/tests/examplefiles/pycon_test.pycon +14 -0
- data/vendor/pygments-main/tests/examplefiles/pytb_test2.pytb +2 -0
- data/vendor/pygments-main/tests/examplefiles/python25-bsd.mak +234 -0
- data/vendor/pygments-main/tests/examplefiles/qsort.prolog +13 -0
- data/vendor/pygments-main/tests/examplefiles/r-console-transcript.Rout +38 -0
- data/vendor/pygments-main/tests/examplefiles/ragel-cpp_rlscan +280 -0
- data/vendor/pygments-main/tests/examplefiles/ragel-cpp_snippet +2 -0
- data/vendor/pygments-main/tests/examplefiles/regex.js +22 -0
- data/vendor/pygments-main/tests/examplefiles/reversi.lsp +427 -0
- data/vendor/pygments-main/tests/examplefiles/ruby_func_def.rb +11 -0
- data/vendor/pygments-main/tests/examplefiles/scilab.sci +30 -0
- data/vendor/pygments-main/tests/examplefiles/sibling.prolog +19 -0
- data/vendor/pygments-main/tests/examplefiles/simple.md +747 -0
- data/vendor/pygments-main/tests/examplefiles/smarty_example.html +209 -0
- data/vendor/pygments-main/tests/examplefiles/source.lgt +343 -0
- data/vendor/pygments-main/tests/examplefiles/sources.list +62 -0
- data/vendor/pygments-main/tests/examplefiles/sphere.pov +18 -0
- data/vendor/pygments-main/tests/examplefiles/sqlite3.sqlite3-console +27 -0
- data/vendor/pygments-main/tests/examplefiles/squid.conf +30 -0
- data/vendor/pygments-main/tests/examplefiles/string.jl +1031 -0
- data/vendor/pygments-main/tests/examplefiles/string_delimiters.d +21 -0
- data/vendor/pygments-main/tests/examplefiles/stripheredoc.sh +3 -0
- data/vendor/pygments-main/tests/examplefiles/test.R +119 -0
- data/vendor/pygments-main/tests/examplefiles/test.adb +211 -0
- data/vendor/pygments-main/tests/examplefiles/test.asy +131 -0
- data/vendor/pygments-main/tests/examplefiles/test.awk +121 -0
- data/vendor/pygments-main/tests/examplefiles/test.bas +29 -0
- data/vendor/pygments-main/tests/examplefiles/test.bmx +145 -0
- data/vendor/pygments-main/tests/examplefiles/test.boo +39 -0
- data/vendor/pygments-main/tests/examplefiles/test.bro +250 -0
- data/vendor/pygments-main/tests/examplefiles/test.cs +374 -0
- data/vendor/pygments-main/tests/examplefiles/test.css +54 -0
- data/vendor/pygments-main/tests/examplefiles/test.d +135 -0
- data/vendor/pygments-main/tests/examplefiles/test.dart +23 -0
- data/vendor/pygments-main/tests/examplefiles/test.dtd +89 -0
- data/vendor/pygments-main/tests/examplefiles/test.ec +605 -0
- data/vendor/pygments-main/tests/examplefiles/test.ecl +58 -0
- data/vendor/pygments-main/tests/examplefiles/test.eh +315 -0
- data/vendor/pygments-main/tests/examplefiles/test.erl +169 -0
- data/vendor/pygments-main/tests/examplefiles/test.evoque +33 -0
- data/vendor/pygments-main/tests/examplefiles/test.fan +818 -0
- data/vendor/pygments-main/tests/examplefiles/test.flx +57 -0
- data/vendor/pygments-main/tests/examplefiles/test.gdc +13 -0
- data/vendor/pygments-main/tests/examplefiles/test.groovy +97 -0
- data/vendor/pygments-main/tests/examplefiles/test.html +339 -0
- data/vendor/pygments-main/tests/examplefiles/test.ini +10 -0
- data/vendor/pygments-main/tests/examplefiles/test.java +653 -0
- data/vendor/pygments-main/tests/examplefiles/test.jsp +24 -0
- data/vendor/pygments-main/tests/examplefiles/test.maql +45 -0
- data/vendor/pygments-main/tests/examplefiles/test.mod +374 -0
- data/vendor/pygments-main/tests/examplefiles/test.moo +51 -0
- data/vendor/pygments-main/tests/examplefiles/test.myt +166 -0
- data/vendor/pygments-main/tests/examplefiles/test.nim +93 -0
- data/vendor/pygments-main/tests/examplefiles/test.pas +743 -0
- data/vendor/pygments-main/tests/examplefiles/test.php +505 -0
- data/vendor/pygments-main/tests/examplefiles/test.plot +333 -0
- data/vendor/pygments-main/tests/examplefiles/test.ps1 +108 -0
- data/vendor/pygments-main/tests/examplefiles/test.pypylog +1839 -0
- data/vendor/pygments-main/tests/examplefiles/test.r3 +94 -0
- data/vendor/pygments-main/tests/examplefiles/test.rb +177 -0
- data/vendor/pygments-main/tests/examplefiles/test.rhtml +43 -0
- data/vendor/pygments-main/tests/examplefiles/test.scaml +8 -0
- data/vendor/pygments-main/tests/examplefiles/test.ssp +12 -0
- data/vendor/pygments-main/tests/examplefiles/test.tcsh +830 -0
- data/vendor/pygments-main/tests/examplefiles/test.vb +407 -0
- data/vendor/pygments-main/tests/examplefiles/test.vhdl +161 -0
- data/vendor/pygments-main/tests/examplefiles/test.xqy +138 -0
- data/vendor/pygments-main/tests/examplefiles/test.xsl +23 -0
- data/vendor/pygments-main/tests/examplefiles/truncated.pytb +15 -0
- data/vendor/pygments-main/tests/examplefiles/type.lisp +1202 -0
- data/vendor/pygments-main/tests/examplefiles/underscore.coffee +603 -0
- data/vendor/pygments-main/tests/examplefiles/unicode.applescript +5 -0
- data/vendor/pygments-main/tests/examplefiles/unicodedoc.py +11 -0
- data/vendor/pygments-main/tests/examplefiles/webkit-transition.css +3 -0
- data/vendor/pygments-main/tests/examplefiles/while.pov +13 -0
- data/vendor/pygments-main/tests/examplefiles/wiki.factor +384 -0
- data/vendor/pygments-main/tests/examplefiles/xml_example +1897 -0
- data/vendor/pygments-main/tests/examplefiles/zmlrpc.f90 +798 -0
- data/vendor/pygments-main/tests/old_run.py +138 -0
- data/vendor/pygments-main/tests/run.py +48 -0
- data/vendor/pygments-main/tests/support.py +15 -0
- data/vendor/pygments-main/tests/test_basic_api.py +294 -0
- data/vendor/pygments-main/tests/test_clexer.py +31 -0
- data/vendor/pygments-main/tests/test_cmdline.py +105 -0
- data/vendor/pygments-main/tests/test_examplefiles.py +97 -0
- data/vendor/pygments-main/tests/test_html_formatter.py +162 -0
- data/vendor/pygments-main/tests/test_latex_formatter.py +55 -0
- data/vendor/pygments-main/tests/test_perllexer.py +137 -0
- data/vendor/pygments-main/tests/test_regexlexer.py +47 -0
- data/vendor/pygments-main/tests/test_token.py +46 -0
- data/vendor/pygments-main/tests/test_using_api.py +40 -0
- data/vendor/pygments-main/tests/test_util.py +116 -0
- data/vendor/simplejson/.gitignore +10 -0
- data/vendor/simplejson/.travis.yml +5 -0
- data/vendor/simplejson/CHANGES.txt +291 -0
- data/vendor/simplejson/LICENSE.txt +19 -0
- data/vendor/simplejson/MANIFEST.in +5 -0
- data/vendor/simplejson/README.rst +19 -0
- data/vendor/simplejson/conf.py +179 -0
- data/vendor/simplejson/index.rst +628 -0
- data/vendor/simplejson/scripts/make_docs.py +18 -0
- data/vendor/simplejson/setup.py +104 -0
- data/vendor/simplejson/simplejson/__init__.py +510 -0
- data/vendor/simplejson/simplejson/_speedups.c +2745 -0
- data/vendor/simplejson/simplejson/decoder.py +425 -0
- data/vendor/simplejson/simplejson/encoder.py +567 -0
- data/vendor/simplejson/simplejson/ordered_dict.py +119 -0
- data/vendor/simplejson/simplejson/scanner.py +77 -0
- data/vendor/simplejson/simplejson/tests/__init__.py +67 -0
- data/vendor/simplejson/simplejson/tests/test_bigint_as_string.py +55 -0
- data/vendor/simplejson/simplejson/tests/test_check_circular.py +30 -0
- data/vendor/simplejson/simplejson/tests/test_decimal.py +66 -0
- data/vendor/simplejson/simplejson/tests/test_decode.py +83 -0
- data/vendor/simplejson/simplejson/tests/test_default.py +9 -0
- data/vendor/simplejson/simplejson/tests/test_dump.py +67 -0
- data/vendor/simplejson/simplejson/tests/test_encode_basestring_ascii.py +46 -0
- data/vendor/simplejson/simplejson/tests/test_encode_for_html.py +32 -0
- data/vendor/simplejson/simplejson/tests/test_errors.py +34 -0
- data/vendor/simplejson/simplejson/tests/test_fail.py +91 -0
- data/vendor/simplejson/simplejson/tests/test_float.py +19 -0
- data/vendor/simplejson/simplejson/tests/test_indent.py +86 -0
- data/vendor/simplejson/simplejson/tests/test_item_sort_key.py +20 -0
- data/vendor/simplejson/simplejson/tests/test_namedtuple.py +121 -0
- data/vendor/simplejson/simplejson/tests/test_pass1.py +76 -0
- data/vendor/simplejson/simplejson/tests/test_pass2.py +14 -0
- data/vendor/simplejson/simplejson/tests/test_pass3.py +20 -0
- data/vendor/simplejson/simplejson/tests/test_recursion.py +67 -0
- data/vendor/simplejson/simplejson/tests/test_scanstring.py +117 -0
- data/vendor/simplejson/simplejson/tests/test_separators.py +42 -0
- data/vendor/simplejson/simplejson/tests/test_speedups.py +20 -0
- data/vendor/simplejson/simplejson/tests/test_tuple.py +49 -0
- data/vendor/simplejson/simplejson/tests/test_unicode.py +109 -0
- data/vendor/simplejson/simplejson/tool.py +39 -0
- metadata +492 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
from unittest import TestCase
|
2
|
+
from cStringIO import StringIO
|
3
|
+
|
4
|
+
import simplejson as json
|
5
|
+
|
6
|
+
class TestDump(TestCase):
|
7
|
+
def test_dump(self):
|
8
|
+
sio = StringIO()
|
9
|
+
json.dump({}, sio)
|
10
|
+
self.assertEquals(sio.getvalue(), '{}')
|
11
|
+
|
12
|
+
def test_dumps(self):
|
13
|
+
self.assertEquals(json.dumps({}), '{}')
|
14
|
+
|
15
|
+
def test_encode_truefalse(self):
|
16
|
+
self.assertEquals(json.dumps(
|
17
|
+
{True: False, False: True}, sort_keys=True),
|
18
|
+
'{"false": true, "true": false}')
|
19
|
+
self.assertEquals(json.dumps(
|
20
|
+
{2: 3.0, 4.0: 5L, False: 1, 6L: True, "7": 0}, sort_keys=True),
|
21
|
+
'{"false": 1, "2": 3.0, "4.0": 5, "6": true, "7": 0}')
|
22
|
+
|
23
|
+
def test_ordered_dict(self):
|
24
|
+
# http://bugs.python.org/issue6105
|
25
|
+
items = [('one', 1), ('two', 2), ('three', 3), ('four', 4), ('five', 5)]
|
26
|
+
s = json.dumps(json.OrderedDict(items))
|
27
|
+
self.assertEqual(s, '{"one": 1, "two": 2, "three": 3, "four": 4, "five": 5}')
|
28
|
+
|
29
|
+
def test_indent_unknown_type_acceptance(self):
|
30
|
+
"""
|
31
|
+
A test against the regression mentioned at `github issue 29`_.
|
32
|
+
|
33
|
+
The indent parameter should accept any type which pretends to be
|
34
|
+
an instance of int or long when it comes to being multiplied by
|
35
|
+
strings, even if it is not actually an int or long, for
|
36
|
+
backwards compatibility.
|
37
|
+
|
38
|
+
.. _github issue 29:
|
39
|
+
http://github.com/simplejson/simplejson/issue/29
|
40
|
+
"""
|
41
|
+
|
42
|
+
class AwesomeInt(object):
|
43
|
+
"""An awesome reimplementation of integers"""
|
44
|
+
|
45
|
+
def __init__(self, *args, **kwargs):
|
46
|
+
if len(args) > 0:
|
47
|
+
# [construct from literals, objects, etc.]
|
48
|
+
# ...
|
49
|
+
|
50
|
+
# Finally, if args[0] is an integer, store it
|
51
|
+
if isinstance(args[0], int):
|
52
|
+
self._int = args[0]
|
53
|
+
|
54
|
+
# [various methods]
|
55
|
+
|
56
|
+
def __mul__(self, other):
|
57
|
+
# [various ways to multiply AwesomeInt objects]
|
58
|
+
# ... finally, if the right-hand operand is not awesome enough,
|
59
|
+
# try to do a normal integer multiplication
|
60
|
+
if hasattr(self, '_int'):
|
61
|
+
return self._int * other
|
62
|
+
else:
|
63
|
+
raise NotImplementedError("To do non-awesome things with"
|
64
|
+
" this object, please construct it from an integer!")
|
65
|
+
|
66
|
+
s = json.dumps(range(3), indent=AwesomeInt(3))
|
67
|
+
self.assertEqual(s, '[\n 0,\n 1,\n 2\n]')
|
@@ -0,0 +1,46 @@
|
|
1
|
+
from unittest import TestCase
|
2
|
+
|
3
|
+
import simplejson.encoder
|
4
|
+
|
5
|
+
CASES = [
|
6
|
+
(u'/\\"\ucafe\ubabe\uab98\ufcde\ubcda\uef4a\x08\x0c\n\r\t`1~!@#$%^&*()_+-=[]{}|;:\',./<>?', '"/\\\\\\"\\ucafe\\ubabe\\uab98\\ufcde\\ubcda\\uef4a\\b\\f\\n\\r\\t`1~!@#$%^&*()_+-=[]{}|;:\',./<>?"'),
|
7
|
+
(u'\u0123\u4567\u89ab\ucdef\uabcd\uef4a', '"\\u0123\\u4567\\u89ab\\ucdef\\uabcd\\uef4a"'),
|
8
|
+
(u'controls', '"controls"'),
|
9
|
+
(u'\x08\x0c\n\r\t', '"\\b\\f\\n\\r\\t"'),
|
10
|
+
(u'{"object with 1 member":["array with 1 element"]}', '"{\\"object with 1 member\\":[\\"array with 1 element\\"]}"'),
|
11
|
+
(u' s p a c e d ', '" s p a c e d "'),
|
12
|
+
(u'\U0001d120', '"\\ud834\\udd20"'),
|
13
|
+
(u'\u03b1\u03a9', '"\\u03b1\\u03a9"'),
|
14
|
+
('\xce\xb1\xce\xa9', '"\\u03b1\\u03a9"'),
|
15
|
+
(u'\u03b1\u03a9', '"\\u03b1\\u03a9"'),
|
16
|
+
('\xce\xb1\xce\xa9', '"\\u03b1\\u03a9"'),
|
17
|
+
(u'\u03b1\u03a9', '"\\u03b1\\u03a9"'),
|
18
|
+
(u'\u03b1\u03a9', '"\\u03b1\\u03a9"'),
|
19
|
+
(u"`1~!@#$%^&*()_+-={':[,]}|;.</>?", '"`1~!@#$%^&*()_+-={\':[,]}|;.</>?"'),
|
20
|
+
(u'\x08\x0c\n\r\t', '"\\b\\f\\n\\r\\t"'),
|
21
|
+
(u'\u0123\u4567\u89ab\ucdef\uabcd\uef4a', '"\\u0123\\u4567\\u89ab\\ucdef\\uabcd\\uef4a"'),
|
22
|
+
]
|
23
|
+
|
24
|
+
class TestEncodeBaseStringAscii(TestCase):
|
25
|
+
def test_py_encode_basestring_ascii(self):
|
26
|
+
self._test_encode_basestring_ascii(simplejson.encoder.py_encode_basestring_ascii)
|
27
|
+
|
28
|
+
def test_c_encode_basestring_ascii(self):
|
29
|
+
if not simplejson.encoder.c_encode_basestring_ascii:
|
30
|
+
return
|
31
|
+
self._test_encode_basestring_ascii(simplejson.encoder.c_encode_basestring_ascii)
|
32
|
+
|
33
|
+
def _test_encode_basestring_ascii(self, encode_basestring_ascii):
|
34
|
+
fname = encode_basestring_ascii.__name__
|
35
|
+
for input_string, expect in CASES:
|
36
|
+
result = encode_basestring_ascii(input_string)
|
37
|
+
#self.assertEquals(result, expect,
|
38
|
+
# '{0!r} != {1!r} for {2}({3!r})'.format(
|
39
|
+
# result, expect, fname, input_string))
|
40
|
+
self.assertEquals(result, expect,
|
41
|
+
'%r != %r for %s(%r)' % (result, expect, fname, input_string))
|
42
|
+
|
43
|
+
def test_sorted_dict(self):
|
44
|
+
items = [('one', 1), ('two', 2), ('three', 3), ('four', 4), ('five', 5)]
|
45
|
+
s = simplejson.dumps(dict(items), sort_keys=True)
|
46
|
+
self.assertEqual(s, '{"five": 5, "four": 4, "one": 1, "three": 3, "two": 2}')
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import unittest
|
2
|
+
|
3
|
+
import simplejson.decoder
|
4
|
+
import simplejson.encoder
|
5
|
+
|
6
|
+
|
7
|
+
class TestEncodeForHTML(unittest.TestCase):
|
8
|
+
|
9
|
+
def setUp(self):
|
10
|
+
self.decoder = simplejson.decoder.JSONDecoder()
|
11
|
+
self.encoder = simplejson.encoder.JSONEncoderForHTML()
|
12
|
+
|
13
|
+
def test_basic_encode(self):
|
14
|
+
self.assertEqual(r'"\u0026"', self.encoder.encode('&'))
|
15
|
+
self.assertEqual(r'"\u003c"', self.encoder.encode('<'))
|
16
|
+
self.assertEqual(r'"\u003e"', self.encoder.encode('>'))
|
17
|
+
|
18
|
+
def test_basic_roundtrip(self):
|
19
|
+
for char in '&<>':
|
20
|
+
self.assertEqual(
|
21
|
+
char, self.decoder.decode(
|
22
|
+
self.encoder.encode(char)))
|
23
|
+
|
24
|
+
def test_prevent_script_breakout(self):
|
25
|
+
bad_string = '</script><script>alert("gotcha")</script>'
|
26
|
+
self.assertEqual(
|
27
|
+
r'"\u003c/script\u003e\u003cscript\u003e'
|
28
|
+
r'alert(\"gotcha\")\u003c/script\u003e"',
|
29
|
+
self.encoder.encode(bad_string))
|
30
|
+
self.assertEqual(
|
31
|
+
bad_string, self.decoder.decode(
|
32
|
+
self.encoder.encode(bad_string)))
|
@@ -0,0 +1,34 @@
|
|
1
|
+
from unittest import TestCase
|
2
|
+
|
3
|
+
import simplejson as json
|
4
|
+
|
5
|
+
class TestErrors(TestCase):
|
6
|
+
def test_string_keys_error(self):
|
7
|
+
data = [{'a': 'A', 'b': (2, 4), 'c': 3.0, ('d',): 'D tuple'}]
|
8
|
+
self.assertRaises(TypeError, json.dumps, data)
|
9
|
+
|
10
|
+
def test_decode_error(self):
|
11
|
+
err = None
|
12
|
+
try:
|
13
|
+
json.loads('{}\na\nb')
|
14
|
+
except json.JSONDecodeError, e:
|
15
|
+
err = e
|
16
|
+
else:
|
17
|
+
self.fail('Expected JSONDecodeError')
|
18
|
+
self.assertEquals(err.lineno, 2)
|
19
|
+
self.assertEquals(err.colno, 1)
|
20
|
+
self.assertEquals(err.endlineno, 3)
|
21
|
+
self.assertEquals(err.endcolno, 2)
|
22
|
+
|
23
|
+
def test_scan_error(self):
|
24
|
+
err = None
|
25
|
+
for t in (str, unicode):
|
26
|
+
try:
|
27
|
+
json.loads(t('{"asdf": "'))
|
28
|
+
except json.JSONDecodeError, e:
|
29
|
+
err = e
|
30
|
+
else:
|
31
|
+
self.fail('Expected JSONDecodeError')
|
32
|
+
self.assertEquals(err.lineno, 1)
|
33
|
+
self.assertEquals(err.colno, 9)
|
34
|
+
|
@@ -0,0 +1,91 @@
|
|
1
|
+
from unittest import TestCase
|
2
|
+
|
3
|
+
import simplejson as json
|
4
|
+
|
5
|
+
# Fri Dec 30 18:57:26 2005
|
6
|
+
JSONDOCS = [
|
7
|
+
# http://json.org/JSON_checker/test/fail1.json
|
8
|
+
'"A JSON payload should be an object or array, not a string."',
|
9
|
+
# http://json.org/JSON_checker/test/fail2.json
|
10
|
+
'["Unclosed array"',
|
11
|
+
# http://json.org/JSON_checker/test/fail3.json
|
12
|
+
'{unquoted_key: "keys must be quoted}',
|
13
|
+
# http://json.org/JSON_checker/test/fail4.json
|
14
|
+
'["extra comma",]',
|
15
|
+
# http://json.org/JSON_checker/test/fail5.json
|
16
|
+
'["double extra comma",,]',
|
17
|
+
# http://json.org/JSON_checker/test/fail6.json
|
18
|
+
'[ , "<-- missing value"]',
|
19
|
+
# http://json.org/JSON_checker/test/fail7.json
|
20
|
+
'["Comma after the close"],',
|
21
|
+
# http://json.org/JSON_checker/test/fail8.json
|
22
|
+
'["Extra close"]]',
|
23
|
+
# http://json.org/JSON_checker/test/fail9.json
|
24
|
+
'{"Extra comma": true,}',
|
25
|
+
# http://json.org/JSON_checker/test/fail10.json
|
26
|
+
'{"Extra value after close": true} "misplaced quoted value"',
|
27
|
+
# http://json.org/JSON_checker/test/fail11.json
|
28
|
+
'{"Illegal expression": 1 + 2}',
|
29
|
+
# http://json.org/JSON_checker/test/fail12.json
|
30
|
+
'{"Illegal invocation": alert()}',
|
31
|
+
# http://json.org/JSON_checker/test/fail13.json
|
32
|
+
'{"Numbers cannot have leading zeroes": 013}',
|
33
|
+
# http://json.org/JSON_checker/test/fail14.json
|
34
|
+
'{"Numbers cannot be hex": 0x14}',
|
35
|
+
# http://json.org/JSON_checker/test/fail15.json
|
36
|
+
'["Illegal backslash escape: \\x15"]',
|
37
|
+
# http://json.org/JSON_checker/test/fail16.json
|
38
|
+
'["Illegal backslash escape: \\\'"]',
|
39
|
+
# http://json.org/JSON_checker/test/fail17.json
|
40
|
+
'["Illegal backslash escape: \\017"]',
|
41
|
+
# http://json.org/JSON_checker/test/fail18.json
|
42
|
+
'[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]',
|
43
|
+
# http://json.org/JSON_checker/test/fail19.json
|
44
|
+
'{"Missing colon" null}',
|
45
|
+
# http://json.org/JSON_checker/test/fail20.json
|
46
|
+
'{"Double colon":: null}',
|
47
|
+
# http://json.org/JSON_checker/test/fail21.json
|
48
|
+
'{"Comma instead of colon", null}',
|
49
|
+
# http://json.org/JSON_checker/test/fail22.json
|
50
|
+
'["Colon instead of comma": false]',
|
51
|
+
# http://json.org/JSON_checker/test/fail23.json
|
52
|
+
'["Bad value", truth]',
|
53
|
+
# http://json.org/JSON_checker/test/fail24.json
|
54
|
+
"['single quote']",
|
55
|
+
# http://code.google.com/p/simplejson/issues/detail?id=3
|
56
|
+
u'["A\u001FZ control characters in string"]',
|
57
|
+
]
|
58
|
+
|
59
|
+
SKIPS = {
|
60
|
+
1: "why not have a string payload?",
|
61
|
+
18: "spec doesn't specify any nesting limitations",
|
62
|
+
}
|
63
|
+
|
64
|
+
class TestFail(TestCase):
|
65
|
+
def test_failures(self):
|
66
|
+
for idx, doc in enumerate(JSONDOCS):
|
67
|
+
idx = idx + 1
|
68
|
+
if idx in SKIPS:
|
69
|
+
json.loads(doc)
|
70
|
+
continue
|
71
|
+
try:
|
72
|
+
json.loads(doc)
|
73
|
+
except json.JSONDecodeError:
|
74
|
+
pass
|
75
|
+
else:
|
76
|
+
#self.fail("Expected failure for fail{0}.json: {1!r}".format(idx, doc))
|
77
|
+
self.fail("Expected failure for fail%d.json: %r" % (idx, doc))
|
78
|
+
|
79
|
+
def test_array_decoder_issue46(self):
|
80
|
+
# http://code.google.com/p/simplejson/issues/detail?id=46
|
81
|
+
for doc in [u'[,]', '[,]']:
|
82
|
+
try:
|
83
|
+
json.loads(doc)
|
84
|
+
except json.JSONDecodeError, e:
|
85
|
+
self.assertEquals(e.pos, 1)
|
86
|
+
self.assertEquals(e.lineno, 1)
|
87
|
+
self.assertEquals(e.colno, 1)
|
88
|
+
except Exception, e:
|
89
|
+
self.fail("Unexpected exception raised %r %s" % (e, e))
|
90
|
+
else:
|
91
|
+
self.fail("Unexpected success parsing '[,]'")
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import math
|
2
|
+
from unittest import TestCase
|
3
|
+
|
4
|
+
import simplejson as json
|
5
|
+
|
6
|
+
class TestFloat(TestCase):
|
7
|
+
def test_floats(self):
|
8
|
+
for num in [1617161771.7650001, math.pi, math.pi**100,
|
9
|
+
math.pi**-100, 3.1]:
|
10
|
+
self.assertEquals(float(json.dumps(num)), num)
|
11
|
+
self.assertEquals(json.loads(json.dumps(num)), num)
|
12
|
+
self.assertEquals(json.loads(unicode(json.dumps(num))), num)
|
13
|
+
|
14
|
+
def test_ints(self):
|
15
|
+
for num in [1, 1L, 1<<32, 1<<64]:
|
16
|
+
self.assertEquals(json.dumps(num), str(num))
|
17
|
+
self.assertEquals(int(json.dumps(num)), num)
|
18
|
+
self.assertEquals(json.loads(json.dumps(num)), num)
|
19
|
+
self.assertEquals(json.loads(unicode(json.dumps(num))), num)
|
@@ -0,0 +1,86 @@
|
|
1
|
+
from unittest import TestCase
|
2
|
+
|
3
|
+
import simplejson as json
|
4
|
+
import textwrap
|
5
|
+
from StringIO import StringIO
|
6
|
+
|
7
|
+
class TestIndent(TestCase):
|
8
|
+
def test_indent(self):
|
9
|
+
h = [['blorpie'], ['whoops'], [], 'd-shtaeou', 'd-nthiouh',
|
10
|
+
'i-vhbjkhnth',
|
11
|
+
{'nifty': 87}, {'field': 'yes', 'morefield': False} ]
|
12
|
+
|
13
|
+
expect = textwrap.dedent("""\
|
14
|
+
[
|
15
|
+
\t[
|
16
|
+
\t\t"blorpie"
|
17
|
+
\t],
|
18
|
+
\t[
|
19
|
+
\t\t"whoops"
|
20
|
+
\t],
|
21
|
+
\t[],
|
22
|
+
\t"d-shtaeou",
|
23
|
+
\t"d-nthiouh",
|
24
|
+
\t"i-vhbjkhnth",
|
25
|
+
\t{
|
26
|
+
\t\t"nifty": 87
|
27
|
+
\t},
|
28
|
+
\t{
|
29
|
+
\t\t"field": "yes",
|
30
|
+
\t\t"morefield": false
|
31
|
+
\t}
|
32
|
+
]""")
|
33
|
+
|
34
|
+
|
35
|
+
d1 = json.dumps(h)
|
36
|
+
d2 = json.dumps(h, indent='\t', sort_keys=True, separators=(',', ': '))
|
37
|
+
d3 = json.dumps(h, indent=' ', sort_keys=True, separators=(',', ': '))
|
38
|
+
d4 = json.dumps(h, indent=2, sort_keys=True, separators=(',', ': '))
|
39
|
+
|
40
|
+
h1 = json.loads(d1)
|
41
|
+
h2 = json.loads(d2)
|
42
|
+
h3 = json.loads(d3)
|
43
|
+
h4 = json.loads(d4)
|
44
|
+
|
45
|
+
self.assertEquals(h1, h)
|
46
|
+
self.assertEquals(h2, h)
|
47
|
+
self.assertEquals(h3, h)
|
48
|
+
self.assertEquals(h4, h)
|
49
|
+
self.assertEquals(d3, expect.replace('\t', ' '))
|
50
|
+
self.assertEquals(d4, expect.replace('\t', ' '))
|
51
|
+
# NOTE: Python 2.4 textwrap.dedent converts tabs to spaces,
|
52
|
+
# so the following is expected to fail. Python 2.4 is not a
|
53
|
+
# supported platform in simplejson 2.1.0+.
|
54
|
+
self.assertEquals(d2, expect)
|
55
|
+
|
56
|
+
def test_indent0(self):
|
57
|
+
h = {3: 1}
|
58
|
+
def check(indent, expected):
|
59
|
+
d1 = json.dumps(h, indent=indent)
|
60
|
+
self.assertEquals(d1, expected)
|
61
|
+
|
62
|
+
sio = StringIO()
|
63
|
+
json.dump(h, sio, indent=indent)
|
64
|
+
self.assertEquals(sio.getvalue(), expected)
|
65
|
+
|
66
|
+
# indent=0 should emit newlines
|
67
|
+
check(0, '{\n"3": 1\n}')
|
68
|
+
# indent=None is more compact
|
69
|
+
check(None, '{"3": 1}')
|
70
|
+
|
71
|
+
def test_separators(self):
|
72
|
+
lst = [1,2,3,4]
|
73
|
+
expect = '[\n1,\n2,\n3,\n4\n]'
|
74
|
+
expect_spaces = '[\n1, \n2, \n3, \n4\n]'
|
75
|
+
# Ensure that separators still works
|
76
|
+
self.assertEquals(
|
77
|
+
expect_spaces,
|
78
|
+
json.dumps(lst, indent=0, separators=(', ', ': ')))
|
79
|
+
# Force the new defaults
|
80
|
+
self.assertEquals(
|
81
|
+
expect,
|
82
|
+
json.dumps(lst, indent=0, separators=(',', ': ')))
|
83
|
+
# Added in 2.1.4
|
84
|
+
self.assertEquals(
|
85
|
+
expect,
|
86
|
+
json.dumps(lst, indent=0))
|
@@ -0,0 +1,20 @@
|
|
1
|
+
from unittest import TestCase
|
2
|
+
|
3
|
+
import simplejson as json
|
4
|
+
from operator import itemgetter
|
5
|
+
|
6
|
+
class TestItemSortKey(TestCase):
|
7
|
+
def test_simple_first(self):
|
8
|
+
a = {'a': 1, 'c': 5, 'jack': 'jill', 'pick': 'axe', 'array': [1, 5, 6, 9], 'tuple': (83, 12, 3), 'crate': 'dog', 'zeak': 'oh'}
|
9
|
+
self.assertEquals(
|
10
|
+
'{"a": 1, "c": 5, "crate": "dog", "jack": "jill", "pick": "axe", "zeak": "oh", "array": [1, 5, 6, 9], "tuple": [83, 12, 3]}',
|
11
|
+
json.dumps(a, item_sort_key=json.simple_first))
|
12
|
+
|
13
|
+
def test_case(self):
|
14
|
+
a = {'a': 1, 'c': 5, 'Jack': 'jill', 'pick': 'axe', 'Array': [1, 5, 6, 9], 'tuple': (83, 12, 3), 'crate': 'dog', 'zeak': 'oh'}
|
15
|
+
self.assertEquals(
|
16
|
+
'{"Array": [1, 5, 6, 9], "Jack": "jill", "a": 1, "c": 5, "crate": "dog", "pick": "axe", "tuple": [83, 12, 3], "zeak": "oh"}',
|
17
|
+
json.dumps(a, item_sort_key=itemgetter(0)))
|
18
|
+
self.assertEquals(
|
19
|
+
'{"a": 1, "Array": [1, 5, 6, 9], "c": 5, "crate": "dog", "Jack": "jill", "pick": "axe", "tuple": [83, 12, 3], "zeak": "oh"}',
|
20
|
+
json.dumps(a, item_sort_key=lambda kv: kv[0].lower()))
|
@@ -0,0 +1,121 @@
|
|
1
|
+
import unittest
|
2
|
+
import simplejson as json
|
3
|
+
from StringIO import StringIO
|
4
|
+
|
5
|
+
try:
|
6
|
+
from collections import namedtuple
|
7
|
+
except ImportError:
|
8
|
+
class Value(tuple):
|
9
|
+
def __new__(cls, *args):
|
10
|
+
return tuple.__new__(cls, args)
|
11
|
+
|
12
|
+
def _asdict(self):
|
13
|
+
return {'value': self[0]}
|
14
|
+
class Point(tuple):
|
15
|
+
def __new__(cls, *args):
|
16
|
+
return tuple.__new__(cls, args)
|
17
|
+
|
18
|
+
def _asdict(self):
|
19
|
+
return {'x': self[0], 'y': self[1]}
|
20
|
+
else:
|
21
|
+
Value = namedtuple('Value', ['value'])
|
22
|
+
Point = namedtuple('Point', ['x', 'y'])
|
23
|
+
|
24
|
+
class DuckValue(object):
|
25
|
+
def __init__(self, *args):
|
26
|
+
self.value = Value(*args)
|
27
|
+
|
28
|
+
def _asdict(self):
|
29
|
+
return self.value._asdict()
|
30
|
+
|
31
|
+
class DuckPoint(object):
|
32
|
+
def __init__(self, *args):
|
33
|
+
self.point = Point(*args)
|
34
|
+
|
35
|
+
def _asdict(self):
|
36
|
+
return self.point._asdict()
|
37
|
+
|
38
|
+
class DeadDuck(object):
|
39
|
+
_asdict = None
|
40
|
+
|
41
|
+
class DeadDict(dict):
|
42
|
+
_asdict = None
|
43
|
+
|
44
|
+
CONSTRUCTORS = [
|
45
|
+
lambda v: v,
|
46
|
+
lambda v: [v],
|
47
|
+
lambda v: [{'key': v}],
|
48
|
+
]
|
49
|
+
|
50
|
+
class TestNamedTuple(unittest.TestCase):
|
51
|
+
def test_namedtuple_dumps(self):
|
52
|
+
for v in [Value(1), Point(1, 2), DuckValue(1), DuckPoint(1, 2)]:
|
53
|
+
d = v._asdict()
|
54
|
+
self.assertEqual(d, json.loads(json.dumps(v)))
|
55
|
+
self.assertEqual(
|
56
|
+
d,
|
57
|
+
json.loads(json.dumps(v, namedtuple_as_object=True)))
|
58
|
+
self.assertEqual(d, json.loads(json.dumps(v, tuple_as_array=False)))
|
59
|
+
self.assertEqual(
|
60
|
+
d,
|
61
|
+
json.loads(json.dumps(v, namedtuple_as_object=True,
|
62
|
+
tuple_as_array=False)))
|
63
|
+
|
64
|
+
def test_namedtuple_dumps_false(self):
|
65
|
+
for v in [Value(1), Point(1, 2)]:
|
66
|
+
l = list(v)
|
67
|
+
self.assertEqual(
|
68
|
+
l,
|
69
|
+
json.loads(json.dumps(v, namedtuple_as_object=False)))
|
70
|
+
self.assertRaises(TypeError, json.dumps, v,
|
71
|
+
tuple_as_array=False, namedtuple_as_object=False)
|
72
|
+
|
73
|
+
def test_namedtuple_dump(self):
|
74
|
+
for v in [Value(1), Point(1, 2), DuckValue(1), DuckPoint(1, 2)]:
|
75
|
+
d = v._asdict()
|
76
|
+
sio = StringIO()
|
77
|
+
json.dump(v, sio)
|
78
|
+
self.assertEqual(d, json.loads(sio.getvalue()))
|
79
|
+
sio = StringIO()
|
80
|
+
json.dump(v, sio, namedtuple_as_object=True)
|
81
|
+
self.assertEqual(
|
82
|
+
d,
|
83
|
+
json.loads(sio.getvalue()))
|
84
|
+
sio = StringIO()
|
85
|
+
json.dump(v, sio, tuple_as_array=False)
|
86
|
+
self.assertEqual(d, json.loads(sio.getvalue()))
|
87
|
+
sio = StringIO()
|
88
|
+
json.dump(v, sio, namedtuple_as_object=True,
|
89
|
+
tuple_as_array=False)
|
90
|
+
self.assertEqual(
|
91
|
+
d,
|
92
|
+
json.loads(sio.getvalue()))
|
93
|
+
|
94
|
+
def test_namedtuple_dump_false(self):
|
95
|
+
for v in [Value(1), Point(1, 2)]:
|
96
|
+
l = list(v)
|
97
|
+
sio = StringIO()
|
98
|
+
json.dump(v, sio, namedtuple_as_object=False)
|
99
|
+
self.assertEqual(
|
100
|
+
l,
|
101
|
+
json.loads(sio.getvalue()))
|
102
|
+
self.assertRaises(TypeError, json.dump, v, StringIO(),
|
103
|
+
tuple_as_array=False, namedtuple_as_object=False)
|
104
|
+
|
105
|
+
def test_asdict_not_callable_dump(self):
|
106
|
+
for f in CONSTRUCTORS:
|
107
|
+
self.assertRaises(TypeError,
|
108
|
+
json.dump, f(DeadDuck()), StringIO(), namedtuple_as_object=True)
|
109
|
+
sio = StringIO()
|
110
|
+
json.dump(f(DeadDict()), sio, namedtuple_as_object=True)
|
111
|
+
self.assertEqual(
|
112
|
+
json.dumps(f({})),
|
113
|
+
sio.getvalue())
|
114
|
+
|
115
|
+
def test_asdict_not_callable_dumps(self):
|
116
|
+
for f in CONSTRUCTORS:
|
117
|
+
self.assertRaises(TypeError,
|
118
|
+
json.dumps, f(DeadDuck()), namedtuple_as_object=True)
|
119
|
+
self.assertEqual(
|
120
|
+
json.dumps(f({})),
|
121
|
+
json.dumps(f(DeadDict()), namedtuple_as_object=True))
|