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,119 @@
|
|
1
|
+
"""Drop-in replacement for collections.OrderedDict by Raymond Hettinger
|
2
|
+
|
3
|
+
http://code.activestate.com/recipes/576693/
|
4
|
+
|
5
|
+
"""
|
6
|
+
from UserDict import DictMixin
|
7
|
+
|
8
|
+
# Modified from original to support Python 2.4, see
|
9
|
+
# http://code.google.com/p/simplejson/issues/detail?id=53
|
10
|
+
try:
|
11
|
+
all
|
12
|
+
except NameError:
|
13
|
+
def all(seq):
|
14
|
+
for elem in seq:
|
15
|
+
if not elem:
|
16
|
+
return False
|
17
|
+
return True
|
18
|
+
|
19
|
+
class OrderedDict(dict, DictMixin):
|
20
|
+
|
21
|
+
def __init__(self, *args, **kwds):
|
22
|
+
if len(args) > 1:
|
23
|
+
raise TypeError('expected at most 1 arguments, got %d' % len(args))
|
24
|
+
try:
|
25
|
+
self.__end
|
26
|
+
except AttributeError:
|
27
|
+
self.clear()
|
28
|
+
self.update(*args, **kwds)
|
29
|
+
|
30
|
+
def clear(self):
|
31
|
+
self.__end = end = []
|
32
|
+
end += [None, end, end] # sentinel node for doubly linked list
|
33
|
+
self.__map = {} # key --> [key, prev, next]
|
34
|
+
dict.clear(self)
|
35
|
+
|
36
|
+
def __setitem__(self, key, value):
|
37
|
+
if key not in self:
|
38
|
+
end = self.__end
|
39
|
+
curr = end[1]
|
40
|
+
curr[2] = end[1] = self.__map[key] = [key, curr, end]
|
41
|
+
dict.__setitem__(self, key, value)
|
42
|
+
|
43
|
+
def __delitem__(self, key):
|
44
|
+
dict.__delitem__(self, key)
|
45
|
+
key, prev, next = self.__map.pop(key)
|
46
|
+
prev[2] = next
|
47
|
+
next[1] = prev
|
48
|
+
|
49
|
+
def __iter__(self):
|
50
|
+
end = self.__end
|
51
|
+
curr = end[2]
|
52
|
+
while curr is not end:
|
53
|
+
yield curr[0]
|
54
|
+
curr = curr[2]
|
55
|
+
|
56
|
+
def __reversed__(self):
|
57
|
+
end = self.__end
|
58
|
+
curr = end[1]
|
59
|
+
while curr is not end:
|
60
|
+
yield curr[0]
|
61
|
+
curr = curr[1]
|
62
|
+
|
63
|
+
def popitem(self, last=True):
|
64
|
+
if not self:
|
65
|
+
raise KeyError('dictionary is empty')
|
66
|
+
# Modified from original to support Python 2.4, see
|
67
|
+
# http://code.google.com/p/simplejson/issues/detail?id=53
|
68
|
+
if last:
|
69
|
+
key = reversed(self).next()
|
70
|
+
else:
|
71
|
+
key = iter(self).next()
|
72
|
+
value = self.pop(key)
|
73
|
+
return key, value
|
74
|
+
|
75
|
+
def __reduce__(self):
|
76
|
+
items = [[k, self[k]] for k in self]
|
77
|
+
tmp = self.__map, self.__end
|
78
|
+
del self.__map, self.__end
|
79
|
+
inst_dict = vars(self).copy()
|
80
|
+
self.__map, self.__end = tmp
|
81
|
+
if inst_dict:
|
82
|
+
return (self.__class__, (items,), inst_dict)
|
83
|
+
return self.__class__, (items,)
|
84
|
+
|
85
|
+
def keys(self):
|
86
|
+
return list(self)
|
87
|
+
|
88
|
+
setdefault = DictMixin.setdefault
|
89
|
+
update = DictMixin.update
|
90
|
+
pop = DictMixin.pop
|
91
|
+
values = DictMixin.values
|
92
|
+
items = DictMixin.items
|
93
|
+
iterkeys = DictMixin.iterkeys
|
94
|
+
itervalues = DictMixin.itervalues
|
95
|
+
iteritems = DictMixin.iteritems
|
96
|
+
|
97
|
+
def __repr__(self):
|
98
|
+
if not self:
|
99
|
+
return '%s()' % (self.__class__.__name__,)
|
100
|
+
return '%s(%r)' % (self.__class__.__name__, self.items())
|
101
|
+
|
102
|
+
def copy(self):
|
103
|
+
return self.__class__(self)
|
104
|
+
|
105
|
+
@classmethod
|
106
|
+
def fromkeys(cls, iterable, value=None):
|
107
|
+
d = cls()
|
108
|
+
for key in iterable:
|
109
|
+
d[key] = value
|
110
|
+
return d
|
111
|
+
|
112
|
+
def __eq__(self, other):
|
113
|
+
if isinstance(other, OrderedDict):
|
114
|
+
return len(self)==len(other) and \
|
115
|
+
all(p==q for p, q in zip(self.items(), other.items()))
|
116
|
+
return dict.__eq__(self, other)
|
117
|
+
|
118
|
+
def __ne__(self, other):
|
119
|
+
return not self == other
|
@@ -0,0 +1,77 @@
|
|
1
|
+
"""JSON token scanner
|
2
|
+
"""
|
3
|
+
import re
|
4
|
+
def _import_c_make_scanner():
|
5
|
+
try:
|
6
|
+
from simplejson._speedups import make_scanner
|
7
|
+
return make_scanner
|
8
|
+
except ImportError:
|
9
|
+
return None
|
10
|
+
c_make_scanner = _import_c_make_scanner()
|
11
|
+
|
12
|
+
__all__ = ['make_scanner']
|
13
|
+
|
14
|
+
NUMBER_RE = re.compile(
|
15
|
+
r'(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?',
|
16
|
+
(re.VERBOSE | re.MULTILINE | re.DOTALL))
|
17
|
+
|
18
|
+
def py_make_scanner(context):
|
19
|
+
parse_object = context.parse_object
|
20
|
+
parse_array = context.parse_array
|
21
|
+
parse_string = context.parse_string
|
22
|
+
match_number = NUMBER_RE.match
|
23
|
+
encoding = context.encoding
|
24
|
+
strict = context.strict
|
25
|
+
parse_float = context.parse_float
|
26
|
+
parse_int = context.parse_int
|
27
|
+
parse_constant = context.parse_constant
|
28
|
+
object_hook = context.object_hook
|
29
|
+
object_pairs_hook = context.object_pairs_hook
|
30
|
+
memo = context.memo
|
31
|
+
|
32
|
+
def _scan_once(string, idx):
|
33
|
+
try:
|
34
|
+
nextchar = string[idx]
|
35
|
+
except IndexError:
|
36
|
+
raise StopIteration
|
37
|
+
|
38
|
+
if nextchar == '"':
|
39
|
+
return parse_string(string, idx + 1, encoding, strict)
|
40
|
+
elif nextchar == '{':
|
41
|
+
return parse_object((string, idx + 1), encoding, strict,
|
42
|
+
_scan_once, object_hook, object_pairs_hook, memo)
|
43
|
+
elif nextchar == '[':
|
44
|
+
return parse_array((string, idx + 1), _scan_once)
|
45
|
+
elif nextchar == 'n' and string[idx:idx + 4] == 'null':
|
46
|
+
return None, idx + 4
|
47
|
+
elif nextchar == 't' and string[idx:idx + 4] == 'true':
|
48
|
+
return True, idx + 4
|
49
|
+
elif nextchar == 'f' and string[idx:idx + 5] == 'false':
|
50
|
+
return False, idx + 5
|
51
|
+
|
52
|
+
m = match_number(string, idx)
|
53
|
+
if m is not None:
|
54
|
+
integer, frac, exp = m.groups()
|
55
|
+
if frac or exp:
|
56
|
+
res = parse_float(integer + (frac or '') + (exp or ''))
|
57
|
+
else:
|
58
|
+
res = parse_int(integer)
|
59
|
+
return res, m.end()
|
60
|
+
elif nextchar == 'N' and string[idx:idx + 3] == 'NaN':
|
61
|
+
return parse_constant('NaN'), idx + 3
|
62
|
+
elif nextchar == 'I' and string[idx:idx + 8] == 'Infinity':
|
63
|
+
return parse_constant('Infinity'), idx + 8
|
64
|
+
elif nextchar == '-' and string[idx:idx + 9] == '-Infinity':
|
65
|
+
return parse_constant('-Infinity'), idx + 9
|
66
|
+
else:
|
67
|
+
raise StopIteration
|
68
|
+
|
69
|
+
def scan_once(string, idx):
|
70
|
+
try:
|
71
|
+
return _scan_once(string, idx)
|
72
|
+
finally:
|
73
|
+
memo.clear()
|
74
|
+
|
75
|
+
return scan_once
|
76
|
+
|
77
|
+
make_scanner = c_make_scanner or py_make_scanner
|
@@ -0,0 +1,67 @@
|
|
1
|
+
import unittest
|
2
|
+
import doctest
|
3
|
+
|
4
|
+
|
5
|
+
class OptionalExtensionTestSuite(unittest.TestSuite):
|
6
|
+
def run(self, result):
|
7
|
+
import simplejson
|
8
|
+
run = unittest.TestSuite.run
|
9
|
+
run(self, result)
|
10
|
+
simplejson._toggle_speedups(False)
|
11
|
+
run(self, result)
|
12
|
+
simplejson._toggle_speedups(True)
|
13
|
+
return result
|
14
|
+
|
15
|
+
|
16
|
+
def additional_tests(suite=None):
|
17
|
+
import simplejson
|
18
|
+
import simplejson.encoder
|
19
|
+
import simplejson.decoder
|
20
|
+
if suite is None:
|
21
|
+
suite = unittest.TestSuite()
|
22
|
+
for mod in (simplejson, simplejson.encoder, simplejson.decoder):
|
23
|
+
suite.addTest(doctest.DocTestSuite(mod))
|
24
|
+
suite.addTest(doctest.DocFileSuite('../../index.rst'))
|
25
|
+
return suite
|
26
|
+
|
27
|
+
|
28
|
+
def all_tests_suite():
|
29
|
+
suite = unittest.TestLoader().loadTestsFromNames([
|
30
|
+
'simplejson.tests.test_bigint_as_string',
|
31
|
+
'simplejson.tests.test_check_circular',
|
32
|
+
'simplejson.tests.test_decode',
|
33
|
+
'simplejson.tests.test_default',
|
34
|
+
'simplejson.tests.test_dump',
|
35
|
+
'simplejson.tests.test_encode_basestring_ascii',
|
36
|
+
'simplejson.tests.test_encode_for_html',
|
37
|
+
'simplejson.tests.test_errors',
|
38
|
+
'simplejson.tests.test_fail',
|
39
|
+
'simplejson.tests.test_float',
|
40
|
+
'simplejson.tests.test_indent',
|
41
|
+
'simplejson.tests.test_pass1',
|
42
|
+
'simplejson.tests.test_pass2',
|
43
|
+
'simplejson.tests.test_pass3',
|
44
|
+
'simplejson.tests.test_recursion',
|
45
|
+
'simplejson.tests.test_scanstring',
|
46
|
+
'simplejson.tests.test_separators',
|
47
|
+
'simplejson.tests.test_speedups',
|
48
|
+
'simplejson.tests.test_unicode',
|
49
|
+
'simplejson.tests.test_decimal',
|
50
|
+
'simplejson.tests.test_tuple',
|
51
|
+
'simplejson.tests.test_namedtuple',
|
52
|
+
])
|
53
|
+
suite = additional_tests(suite)
|
54
|
+
return OptionalExtensionTestSuite([suite])
|
55
|
+
|
56
|
+
|
57
|
+
def main():
|
58
|
+
runner = unittest.TextTestRunner()
|
59
|
+
suite = all_tests_suite()
|
60
|
+
raise SystemExit(not runner.run(suite).wasSuccessful())
|
61
|
+
|
62
|
+
|
63
|
+
if __name__ == '__main__':
|
64
|
+
import os
|
65
|
+
import sys
|
66
|
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
67
|
+
main()
|
@@ -0,0 +1,55 @@
|
|
1
|
+
from unittest import TestCase
|
2
|
+
|
3
|
+
import simplejson as json
|
4
|
+
|
5
|
+
class TestBigintAsString(TestCase):
|
6
|
+
values = [(200, 200),
|
7
|
+
((2 ** 53) - 1, 9007199254740991),
|
8
|
+
((2 ** 53), '9007199254740992'),
|
9
|
+
((2 ** 53) + 1, '9007199254740993'),
|
10
|
+
(-100, -100),
|
11
|
+
((-2 ** 53), '-9007199254740992'),
|
12
|
+
((-2 ** 53) - 1, '-9007199254740993'),
|
13
|
+
((-2 ** 53) + 1, -9007199254740991)]
|
14
|
+
|
15
|
+
def test_ints(self):
|
16
|
+
for val, expect in self.values:
|
17
|
+
self.assertEquals(
|
18
|
+
val,
|
19
|
+
json.loads(json.dumps(val)))
|
20
|
+
self.assertEquals(
|
21
|
+
expect,
|
22
|
+
json.loads(json.dumps(val, bigint_as_string=True)))
|
23
|
+
|
24
|
+
def test_lists(self):
|
25
|
+
for val, expect in self.values:
|
26
|
+
val = [val, val]
|
27
|
+
expect = [expect, expect]
|
28
|
+
self.assertEquals(
|
29
|
+
val,
|
30
|
+
json.loads(json.dumps(val)))
|
31
|
+
self.assertEquals(
|
32
|
+
expect,
|
33
|
+
json.loads(json.dumps(val, bigint_as_string=True)))
|
34
|
+
|
35
|
+
def test_dicts(self):
|
36
|
+
for val, expect in self.values:
|
37
|
+
val = {'k': val}
|
38
|
+
expect = {'k': expect}
|
39
|
+
self.assertEquals(
|
40
|
+
val,
|
41
|
+
json.loads(json.dumps(val)))
|
42
|
+
self.assertEquals(
|
43
|
+
expect,
|
44
|
+
json.loads(json.dumps(val, bigint_as_string=True)))
|
45
|
+
|
46
|
+
def test_dict_keys(self):
|
47
|
+
for val, _ in self.values:
|
48
|
+
expect = {str(val): 'value'}
|
49
|
+
val = {val: 'value'}
|
50
|
+
self.assertEquals(
|
51
|
+
expect,
|
52
|
+
json.loads(json.dumps(val)))
|
53
|
+
self.assertEquals(
|
54
|
+
expect,
|
55
|
+
json.loads(json.dumps(val, bigint_as_string=True)))
|
@@ -0,0 +1,30 @@
|
|
1
|
+
from unittest import TestCase
|
2
|
+
import simplejson as json
|
3
|
+
|
4
|
+
def default_iterable(obj):
|
5
|
+
return list(obj)
|
6
|
+
|
7
|
+
class TestCheckCircular(TestCase):
|
8
|
+
def test_circular_dict(self):
|
9
|
+
dct = {}
|
10
|
+
dct['a'] = dct
|
11
|
+
self.assertRaises(ValueError, json.dumps, dct)
|
12
|
+
|
13
|
+
def test_circular_list(self):
|
14
|
+
lst = []
|
15
|
+
lst.append(lst)
|
16
|
+
self.assertRaises(ValueError, json.dumps, lst)
|
17
|
+
|
18
|
+
def test_circular_composite(self):
|
19
|
+
dct2 = {}
|
20
|
+
dct2['a'] = []
|
21
|
+
dct2['a'].append(dct2)
|
22
|
+
self.assertRaises(ValueError, json.dumps, dct2)
|
23
|
+
|
24
|
+
def test_circular_default(self):
|
25
|
+
json.dumps([set()], default=default_iterable)
|
26
|
+
self.assertRaises(TypeError, json.dumps, [set()])
|
27
|
+
|
28
|
+
def test_circular_off_default(self):
|
29
|
+
json.dumps([set()], default=default_iterable, check_circular=False)
|
30
|
+
self.assertRaises(TypeError, json.dumps, [set()], check_circular=False)
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import decimal
|
2
|
+
from decimal import Decimal
|
3
|
+
from unittest import TestCase
|
4
|
+
from StringIO import StringIO
|
5
|
+
|
6
|
+
import simplejson as json
|
7
|
+
|
8
|
+
class TestDecimal(TestCase):
|
9
|
+
NUMS = "1.0", "10.00", "1.1", "1234567890.1234567890", "500"
|
10
|
+
def dumps(self, obj, **kw):
|
11
|
+
sio = StringIO()
|
12
|
+
json.dump(obj, sio, **kw)
|
13
|
+
res = json.dumps(obj, **kw)
|
14
|
+
self.assertEquals(res, sio.getvalue())
|
15
|
+
return res
|
16
|
+
|
17
|
+
def loads(self, s, **kw):
|
18
|
+
sio = StringIO(s)
|
19
|
+
res = json.loads(s, **kw)
|
20
|
+
self.assertEquals(res, json.load(sio, **kw))
|
21
|
+
return res
|
22
|
+
|
23
|
+
def test_decimal_encode(self):
|
24
|
+
for d in map(Decimal, self.NUMS):
|
25
|
+
self.assertEquals(self.dumps(d, use_decimal=True), str(d))
|
26
|
+
|
27
|
+
def test_decimal_decode(self):
|
28
|
+
for s in self.NUMS:
|
29
|
+
self.assertEquals(self.loads(s, parse_float=Decimal), Decimal(s))
|
30
|
+
|
31
|
+
def test_decimal_roundtrip(self):
|
32
|
+
for d in map(Decimal, self.NUMS):
|
33
|
+
# The type might not be the same (int and Decimal) but they
|
34
|
+
# should still compare equal.
|
35
|
+
self.assertEquals(
|
36
|
+
self.loads(
|
37
|
+
self.dumps(d, use_decimal=True), parse_float=Decimal),
|
38
|
+
d)
|
39
|
+
self.assertEquals(
|
40
|
+
self.loads(
|
41
|
+
self.dumps([d], use_decimal=True), parse_float=Decimal),
|
42
|
+
[d])
|
43
|
+
|
44
|
+
def test_decimal_defaults(self):
|
45
|
+
d = Decimal('1.1')
|
46
|
+
# use_decimal=True is the default
|
47
|
+
self.assertRaises(TypeError, json.dumps, d, use_decimal=False)
|
48
|
+
self.assertEqual('1.1', json.dumps(d))
|
49
|
+
self.assertEqual('1.1', json.dumps(d, use_decimal=True))
|
50
|
+
self.assertRaises(TypeError, json.dump, d, StringIO(),
|
51
|
+
use_decimal=False)
|
52
|
+
sio = StringIO()
|
53
|
+
json.dump(d, sio)
|
54
|
+
self.assertEqual('1.1', sio.getvalue())
|
55
|
+
sio = StringIO()
|
56
|
+
json.dump(d, sio, use_decimal=True)
|
57
|
+
self.assertEqual('1.1', sio.getvalue())
|
58
|
+
|
59
|
+
def test_decimal_reload(self):
|
60
|
+
# Simulate a subinterpreter that reloads the Python modules but not
|
61
|
+
# the C code https://github.com/simplejson/simplejson/issues/34
|
62
|
+
global Decimal
|
63
|
+
Decimal = reload(decimal).Decimal
|
64
|
+
import simplejson.encoder
|
65
|
+
simplejson.encoder.Decimal = Decimal
|
66
|
+
self.test_decimal_roundtrip()
|
@@ -0,0 +1,83 @@
|
|
1
|
+
import decimal
|
2
|
+
from unittest import TestCase
|
3
|
+
from StringIO import StringIO
|
4
|
+
|
5
|
+
import simplejson as json
|
6
|
+
from simplejson import OrderedDict
|
7
|
+
|
8
|
+
class TestDecode(TestCase):
|
9
|
+
if not hasattr(TestCase, 'assertIs'):
|
10
|
+
def assertIs(self, a, b):
|
11
|
+
self.assertTrue(a is b, '%r is %r' % (a, b))
|
12
|
+
|
13
|
+
def test_decimal(self):
|
14
|
+
rval = json.loads('1.1', parse_float=decimal.Decimal)
|
15
|
+
self.assertTrue(isinstance(rval, decimal.Decimal))
|
16
|
+
self.assertEquals(rval, decimal.Decimal('1.1'))
|
17
|
+
|
18
|
+
def test_float(self):
|
19
|
+
rval = json.loads('1', parse_int=float)
|
20
|
+
self.assertTrue(isinstance(rval, float))
|
21
|
+
self.assertEquals(rval, 1.0)
|
22
|
+
|
23
|
+
def test_decoder_optimizations(self):
|
24
|
+
# Several optimizations were made that skip over calls to
|
25
|
+
# the whitespace regex, so this test is designed to try and
|
26
|
+
# exercise the uncommon cases. The array cases are already covered.
|
27
|
+
rval = json.loads('{ "key" : "value" , "k":"v" }')
|
28
|
+
self.assertEquals(rval, {"key":"value", "k":"v"})
|
29
|
+
|
30
|
+
def test_empty_objects(self):
|
31
|
+
s = '{}'
|
32
|
+
self.assertEqual(json.loads(s), eval(s))
|
33
|
+
s = '[]'
|
34
|
+
self.assertEqual(json.loads(s), eval(s))
|
35
|
+
s = '""'
|
36
|
+
self.assertEqual(json.loads(s), eval(s))
|
37
|
+
|
38
|
+
def test_object_pairs_hook(self):
|
39
|
+
s = '{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}'
|
40
|
+
p = [("xkd", 1), ("kcw", 2), ("art", 3), ("hxm", 4),
|
41
|
+
("qrt", 5), ("pad", 6), ("hoy", 7)]
|
42
|
+
self.assertEqual(json.loads(s), eval(s))
|
43
|
+
self.assertEqual(json.loads(s, object_pairs_hook=lambda x: x), p)
|
44
|
+
self.assertEqual(json.load(StringIO(s),
|
45
|
+
object_pairs_hook=lambda x: x), p)
|
46
|
+
od = json.loads(s, object_pairs_hook=OrderedDict)
|
47
|
+
self.assertEqual(od, OrderedDict(p))
|
48
|
+
self.assertEqual(type(od), OrderedDict)
|
49
|
+
# the object_pairs_hook takes priority over the object_hook
|
50
|
+
self.assertEqual(json.loads(s,
|
51
|
+
object_pairs_hook=OrderedDict,
|
52
|
+
object_hook=lambda x: None),
|
53
|
+
OrderedDict(p))
|
54
|
+
|
55
|
+
def check_keys_reuse(self, source, loads):
|
56
|
+
rval = loads(source)
|
57
|
+
(a, b), (c, d) = sorted(rval[0]), sorted(rval[1])
|
58
|
+
self.assertIs(a, c)
|
59
|
+
self.assertIs(b, d)
|
60
|
+
|
61
|
+
def test_keys_reuse_str(self):
|
62
|
+
s = u'[{"a_key": 1, "b_\xe9": 2}, {"a_key": 3, "b_\xe9": 4}]'.encode('utf8')
|
63
|
+
self.check_keys_reuse(s, json.loads)
|
64
|
+
|
65
|
+
def test_keys_reuse_unicode(self):
|
66
|
+
s = u'[{"a_key": 1, "b_\xe9": 2}, {"a_key": 3, "b_\xe9": 4}]'
|
67
|
+
self.check_keys_reuse(s, json.loads)
|
68
|
+
|
69
|
+
def test_empty_strings(self):
|
70
|
+
self.assertEqual(json.loads('""'), "")
|
71
|
+
self.assertEqual(json.loads(u'""'), u"")
|
72
|
+
self.assertEqual(json.loads('[""]'), [""])
|
73
|
+
self.assertEqual(json.loads(u'[""]'), [u""])
|
74
|
+
|
75
|
+
def test_raw_decode(self):
|
76
|
+
cls = json.decoder.JSONDecoder
|
77
|
+
self.assertEqual(
|
78
|
+
({'a': {}}, 9),
|
79
|
+
cls().raw_decode("{\"a\": {}}"))
|
80
|
+
# http://code.google.com/p/simplejson/issues/detail?id=85
|
81
|
+
self.assertEqual(
|
82
|
+
({'a': {}}, 9),
|
83
|
+
cls(object_pairs_hook=dict).raw_decode("{\"a\": {}}"))
|