pygments.rb-jruby 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/CHANGELOG.md +71 -0
- data/Gemfile +2 -0
- data/LICENSE +17 -0
- data/README.md +118 -0
- data/Rakefile +66 -0
- data/bench.rb +22 -0
- data/cache-lexers.rb +8 -0
- data/lexers +0 -0
- data/lib/pygments.rb +8 -0
- data/lib/pygments/lexer.rb +148 -0
- data/lib/pygments/mentos.py +351 -0
- data/lib/pygments/popen.rb +404 -0
- data/lib/pygments/version.rb +3 -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 +287 -0
- data/vendor/custom_lexers/github.py +565 -0
- data/vendor/pygments-main/AUTHORS +153 -0
- data/vendor/pygments-main/CHANGES +889 -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 +48 -0
- data/vendor/pygments-main/docs/src/java.txt +70 -0
- data/vendor/pygments-main/docs/src/lexerdevelopment.txt +603 -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/autopygmentize +64 -0
- data/vendor/pygments-main/external/lasso-builtins-generator-9.lasso +144 -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 +441 -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 +356 -0
- data/vendor/pygments-main/pygments/formatter.py +95 -0
- data/vendor/pygments-main/pygments/formatters/__init__.py +68 -0
- data/vendor/pygments-main/pygments/formatters/_mapping.py +92 -0
- data/vendor/pygments-main/pygments/formatters/bbcode.py +109 -0
- data/vendor/pygments-main/pygments/formatters/html.py +821 -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 +115 -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 +765 -0
- data/vendor/pygments-main/pygments/lexers/__init__.py +240 -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/_lassobuiltins.py +5172 -0
- data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +249 -0
- data/vendor/pygments-main/pygments/lexers/_mapping.py +354 -0
- data/vendor/pygments-main/pygments/lexers/_openedgebuiltins.py +562 -0
- data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +3787 -0
- data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +233 -0
- data/vendor/pygments-main/pygments/lexers/_robotframeworklexer.py +557 -0
- data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +40 -0
- data/vendor/pygments-main/pygments/lexers/_sourcemodbuiltins.py +1072 -0
- data/vendor/pygments-main/pygments/lexers/_stan_builtins.py +360 -0
- data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +13 -0
- data/vendor/pygments-main/pygments/lexers/agile.py +2290 -0
- data/vendor/pygments-main/pygments/lexers/asm.py +398 -0
- data/vendor/pygments-main/pygments/lexers/compiled.py +3723 -0
- data/vendor/pygments-main/pygments/lexers/dalvik.py +104 -0
- data/vendor/pygments-main/pygments/lexers/dotnet.py +671 -0
- data/vendor/pygments-main/pygments/lexers/foxpro.py +428 -0
- data/vendor/pygments-main/pygments/lexers/functional.py +2731 -0
- data/vendor/pygments-main/pygments/lexers/github.py +565 -0
- data/vendor/pygments-main/pygments/lexers/hdl.py +356 -0
- data/vendor/pygments-main/pygments/lexers/jvm.py +1112 -0
- data/vendor/pygments-main/pygments/lexers/math.py +1918 -0
- data/vendor/pygments-main/pygments/lexers/other.py +3778 -0
- data/vendor/pygments-main/pygments/lexers/parsers.py +778 -0
- data/vendor/pygments-main/pygments/lexers/shell.py +424 -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 +1742 -0
- data/vendor/pygments-main/pygments/lexers/text.py +1893 -0
- data/vendor/pygments-main/pygments/lexers/web.py +4045 -0
- data/vendor/pygments-main/pygments/modeline.py +40 -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 +140 -0
- data/vendor/pygments-main/pygments/util.py +277 -0
- data/vendor/pygments-main/scripts/check_sources.py +242 -0
- data/vendor/pygments-main/scripts/detect_missing_analyse_text.py +32 -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 +170 -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 +7 -0
- data/vendor/pygments-main/setup.py +90 -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/BOM.js +1 -0
- data/vendor/pygments-main/tests/examplefiles/CPDictionary.j +611 -0
- data/vendor/pygments-main/tests/examplefiles/Config.in.cache +1973 -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/Deflate.fs +578 -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/Get-CommandDefinitionHtml.ps1 +66 -0
- data/vendor/pygments-main/tests/examplefiles/IPDispatchC.nc +104 -0
- data/vendor/pygments-main/tests/examplefiles/IPDispatchP.nc +671 -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/RoleQ.pm6 +23 -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/autoit_submit.au3 +25 -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/bigtest.nsi +308 -0
- data/vendor/pygments-main/tests/examplefiles/boot-9.scm +1557 -0
- data/vendor/pygments-main/tests/examplefiles/ca65_example +284 -0
- data/vendor/pygments-main/tests/examplefiles/cbmbas_example +9 -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 +125 -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.Rd +78 -0
- data/vendor/pygments-main/tests/examplefiles/example.bug +54 -0
- data/vendor/pygments-main/tests/examplefiles/example.c +2080 -0
- data/vendor/pygments-main/tests/examplefiles/example.ceylon +52 -0
- data/vendor/pygments-main/tests/examplefiles/example.clay +33 -0
- data/vendor/pygments-main/tests/examplefiles/example.cls +15 -0
- data/vendor/pygments-main/tests/examplefiles/example.cob +3556 -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.hx +142 -0
- data/vendor/pygments-main/tests/examplefiles/example.jag +48 -0
- data/vendor/pygments-main/tests/examplefiles/example.kt +47 -0
- data/vendor/pygments-main/tests/examplefiles/example.lagda +19 -0
- data/vendor/pygments-main/tests/examplefiles/example.lua +250 -0
- data/vendor/pygments-main/tests/examplefiles/example.monkey +152 -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.msc +43 -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.prg +161 -0
- data/vendor/pygments-main/tests/examplefiles/example.rb +1852 -0
- data/vendor/pygments-main/tests/examplefiles/example.reg +19 -0
- data/vendor/pygments-main/tests/examplefiles/example.rexx +50 -0
- data/vendor/pygments-main/tests/examplefiles/example.rhtml +561 -0
- data/vendor/pygments-main/tests/examplefiles/example.rkt +95 -0
- data/vendor/pygments-main/tests/examplefiles/example.rpf +4 -0
- data/vendor/pygments-main/tests/examplefiles/example.sh-session +19 -0
- data/vendor/pygments-main/tests/examplefiles/example.shell-session +45 -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.stan +108 -0
- data/vendor/pygments-main/tests/examplefiles/example.tea +34 -0
- data/vendor/pygments-main/tests/examplefiles/example.ts +28 -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.xtend +34 -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/example2.msc +79 -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/garcia-wachs.kk +133 -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/grammar-test.p6 +22 -0
- data/vendor/pygments-main/tests/examplefiles/hello.smali +40 -0
- data/vendor/pygments-main/tests/examplefiles/hello.sp +9 -0
- data/vendor/pygments-main/tests/examplefiles/html+php_faulty.php +1 -0
- data/vendor/pygments-main/tests/examplefiles/http_request_example +15 -0
- data/vendor/pygments-main/tests/examplefiles/http_response_example +29 -0
- data/vendor/pygments-main/tests/examplefiles/import.hs +4 -0
- data/vendor/pygments-main/tests/examplefiles/inet_pton6.dg +71 -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/json.lasso +301 -0
- data/vendor/pygments-main/tests/examplefiles/json.lasso9 +213 -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/livescript-demo.ls +41 -0
- data/vendor/pygments-main/tests/examplefiles/logos_example.xm +28 -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 +30 -0
- data/vendor/pygments-main/tests/examplefiles/matlabsession_sample.txt +37 -0
- data/vendor/pygments-main/tests/examplefiles/metagrammar.treetop +455 -0
- data/vendor/pygments-main/tests/examplefiles/mg_sample.pro +73 -0
- data/vendor/pygments-main/tests/examplefiles/minehunt.qml +112 -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/nanomsg.intr +95 -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 +32 -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/phpMyAdmin.spec +163 -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/py3tb_test.py3tb +4 -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/pytb_test3.pytb +4 -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/robotframework.txt +39 -0
- data/vendor/pygments-main/tests/examplefiles/ruby_func_def.rb +11 -0
- data/vendor/pygments-main/tests/examplefiles/rust_example.rs +233 -0
- data/vendor/pygments-main/tests/examplefiles/scilab.sci +30 -0
- data/vendor/pygments-main/tests/examplefiles/session.dylan-console +9 -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/swig_java.swg +1329 -0
- data/vendor/pygments-main/tests/examplefiles/swig_std_vector.i +225 -0
- data/vendor/pygments-main/tests/examplefiles/test.R +153 -0
- data/vendor/pygments-main/tests/examplefiles/test.adb +211 -0
- data/vendor/pygments-main/tests/examplefiles/test.agda +102 -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.bb +95 -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.cu +36 -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.ebnf +31 -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.opa +10 -0
- data/vendor/pygments-main/tests/examplefiles/test.p6 +252 -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/test2.pypylog +120 -0
- data/vendor/pygments-main/tests/examplefiles/truncated.pytb +15 -0
- data/vendor/pygments-main/tests/examplefiles/type.lisp +1218 -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/unix-io.lid +37 -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 +49 -0
- data/vendor/pygments-main/tests/support.py +15 -0
- data/vendor/pygments-main/tests/support/tags +36 -0
- data/vendor/pygments-main/tests/test_basic_api.py +295 -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 +99 -0
- data/vendor/pygments-main/tests/test_html_formatter.py +178 -0
- data/vendor/pygments-main/tests/test_latex_formatter.py +55 -0
- data/vendor/pygments-main/tests/test_lexers_other.py +68 -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 +135 -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 +557 -0
@@ -0,0 +1,628 @@
|
|
1
|
+
:mod:`simplejson` --- JSON encoder and decoder
|
2
|
+
==============================================
|
3
|
+
|
4
|
+
.. module:: simplejson
|
5
|
+
:synopsis: Encode and decode the JSON format.
|
6
|
+
.. moduleauthor:: Bob Ippolito <bob@redivi.com>
|
7
|
+
.. sectionauthor:: Bob Ippolito <bob@redivi.com>
|
8
|
+
|
9
|
+
JSON (JavaScript Object Notation) <http://json.org> is a subset of JavaScript
|
10
|
+
syntax (ECMA-262 3rd edition) used as a lightweight data interchange format.
|
11
|
+
|
12
|
+
:mod:`simplejson` exposes an API familiar to users of the standard library
|
13
|
+
:mod:`marshal` and :mod:`pickle` modules. It is the externally maintained
|
14
|
+
version of the :mod:`json` library contained in Python 2.6, but maintains
|
15
|
+
compatibility with Python 2.5 and (currently) has
|
16
|
+
significant performance advantages, even without using the optional C
|
17
|
+
extension for speedups.
|
18
|
+
|
19
|
+
Development of simplejson happens on Github:
|
20
|
+
http://github.com/simplejson/simplejson
|
21
|
+
|
22
|
+
Encoding basic Python object hierarchies::
|
23
|
+
|
24
|
+
>>> import simplejson as json
|
25
|
+
>>> json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
|
26
|
+
'["foo", {"bar": ["baz", null, 1.0, 2]}]'
|
27
|
+
>>> print json.dumps("\"foo\bar")
|
28
|
+
"\"foo\bar"
|
29
|
+
>>> print json.dumps(u'\u1234')
|
30
|
+
"\u1234"
|
31
|
+
>>> print json.dumps('\\')
|
32
|
+
"\\"
|
33
|
+
>>> print json.dumps({"c": 0, "b": 0, "a": 0}, sort_keys=True)
|
34
|
+
{"a": 0, "b": 0, "c": 0}
|
35
|
+
>>> from StringIO import StringIO
|
36
|
+
>>> io = StringIO()
|
37
|
+
>>> json.dump(['streaming API'], io)
|
38
|
+
>>> io.getvalue()
|
39
|
+
'["streaming API"]'
|
40
|
+
|
41
|
+
Compact encoding::
|
42
|
+
|
43
|
+
>>> import simplejson as json
|
44
|
+
>>> json.dumps([1,2,3,{'4': 5, '6': 7}], separators=(',', ':'))
|
45
|
+
'[1,2,3,{"4":5,"6":7}]'
|
46
|
+
|
47
|
+
Pretty printing::
|
48
|
+
|
49
|
+
>>> import simplejson as json
|
50
|
+
>>> s = json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4 * ' ')
|
51
|
+
>>> print '\n'.join([l.rstrip() for l in s.splitlines()])
|
52
|
+
{
|
53
|
+
"4": 5,
|
54
|
+
"6": 7
|
55
|
+
}
|
56
|
+
|
57
|
+
Decoding JSON::
|
58
|
+
|
59
|
+
>>> import simplejson as json
|
60
|
+
>>> obj = [u'foo', {u'bar': [u'baz', None, 1.0, 2]}]
|
61
|
+
>>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]') == obj
|
62
|
+
True
|
63
|
+
>>> json.loads('"\\"foo\\bar"') == u'"foo\x08ar'
|
64
|
+
True
|
65
|
+
>>> from StringIO import StringIO
|
66
|
+
>>> io = StringIO('["streaming API"]')
|
67
|
+
>>> json.load(io)[0] == 'streaming API'
|
68
|
+
True
|
69
|
+
|
70
|
+
Using Decimal instead of float::
|
71
|
+
|
72
|
+
>>> import simplejson as json
|
73
|
+
>>> from decimal import Decimal
|
74
|
+
>>> json.loads('1.1', use_decimal=True) == Decimal('1.1')
|
75
|
+
True
|
76
|
+
>>> json.dumps(Decimal('1.1'), use_decimal=True) == '1.1'
|
77
|
+
True
|
78
|
+
|
79
|
+
Specializing JSON object decoding::
|
80
|
+
|
81
|
+
>>> import simplejson as json
|
82
|
+
>>> def as_complex(dct):
|
83
|
+
... if '__complex__' in dct:
|
84
|
+
... return complex(dct['real'], dct['imag'])
|
85
|
+
... return dct
|
86
|
+
...
|
87
|
+
>>> json.loads('{"__complex__": true, "real": 1, "imag": 2}',
|
88
|
+
... object_hook=as_complex)
|
89
|
+
(1+2j)
|
90
|
+
>>> import decimal
|
91
|
+
>>> json.loads('1.1', parse_float=decimal.Decimal) == decimal.Decimal('1.1')
|
92
|
+
True
|
93
|
+
|
94
|
+
Specializing JSON object encoding::
|
95
|
+
|
96
|
+
>>> import simplejson as json
|
97
|
+
>>> def encode_complex(obj):
|
98
|
+
... if isinstance(obj, complex):
|
99
|
+
... return [obj.real, obj.imag]
|
100
|
+
... raise TypeError(repr(o) + " is not JSON serializable")
|
101
|
+
...
|
102
|
+
>>> json.dumps(2 + 1j, default=encode_complex)
|
103
|
+
'[2.0, 1.0]'
|
104
|
+
>>> json.JSONEncoder(default=encode_complex).encode(2 + 1j)
|
105
|
+
'[2.0, 1.0]'
|
106
|
+
>>> ''.join(json.JSONEncoder(default=encode_complex).iterencode(2 + 1j))
|
107
|
+
'[2.0, 1.0]'
|
108
|
+
|
109
|
+
|
110
|
+
.. highlight:: none
|
111
|
+
|
112
|
+
Using :mod:`simplejson.tool` from the shell to validate and pretty-print::
|
113
|
+
|
114
|
+
$ echo '{"json":"obj"}' | python -m simplejson.tool
|
115
|
+
{
|
116
|
+
"json": "obj"
|
117
|
+
}
|
118
|
+
$ echo '{ 1.2:3.4}' | python -m simplejson.tool
|
119
|
+
Expecting property name enclosed in double quotes: line 1 column 2 (char 2)
|
120
|
+
|
121
|
+
.. highlight:: python
|
122
|
+
|
123
|
+
.. note::
|
124
|
+
|
125
|
+
The JSON produced by this module's default settings is a subset of
|
126
|
+
YAML, so it may be used as a serializer for that as well.
|
127
|
+
|
128
|
+
|
129
|
+
Basic Usage
|
130
|
+
-----------
|
131
|
+
|
132
|
+
.. function:: dump(obj, fp[, skipkeys[, ensure_ascii[, check_circular[, allow_nan[, cls[, indent[, separators[, encoding[, default[, use_decimal[, namedtuple_as_object[, tuple_as_array[, bigint_as_string[, sort_keys[, item_sort_key[, **kw]]]]]]]]]]]]]]]])
|
133
|
+
|
134
|
+
Serialize *obj* as a JSON formatted stream to *fp* (a ``.write()``-supporting
|
135
|
+
file-like object).
|
136
|
+
|
137
|
+
If *skipkeys* is true (default: ``False``), then dict keys that are not
|
138
|
+
of a basic type (:class:`str`, :class:`unicode`, :class:`int`, :class:`long`,
|
139
|
+
:class:`float`, :class:`bool`, ``None``) will be skipped instead of raising a
|
140
|
+
:exc:`TypeError`.
|
141
|
+
|
142
|
+
If *ensure_ascii* is false (default: ``True``), then some chunks written
|
143
|
+
to *fp* may be :class:`unicode` instances, subject to normal Python
|
144
|
+
:class:`str` to :class:`unicode` coercion rules. Unless ``fp.write()``
|
145
|
+
explicitly understands :class:`unicode` (as in :func:`codecs.getwriter`) this
|
146
|
+
is likely to cause an error. It's best to leave the default settings, because
|
147
|
+
they are safe and it is highly optimized.
|
148
|
+
|
149
|
+
If *check_circular* is false (default: ``True``), then the circular
|
150
|
+
reference check for container types will be skipped and a circular reference
|
151
|
+
will result in an :exc:`OverflowError` (or worse).
|
152
|
+
|
153
|
+
If *allow_nan* is false (default: ``True``), then it will be a
|
154
|
+
:exc:`ValueError` to serialize out of range :class:`float` values (``nan``,
|
155
|
+
``inf``, ``-inf``) in strict compliance of the JSON specification.
|
156
|
+
If *allow_nan* is true, their JavaScript equivalents will be used
|
157
|
+
(``NaN``, ``Infinity``, ``-Infinity``).
|
158
|
+
|
159
|
+
If *indent* is a string, then JSON array elements and object members
|
160
|
+
will be pretty-printed with a newline followed by that string repeated
|
161
|
+
for each level of nesting. ``None`` (the default) selects the most compact
|
162
|
+
representation without any newlines. For backwards compatibility with
|
163
|
+
versions of simplejson earlier than 2.1.0, an integer is also accepted
|
164
|
+
and is converted to a string with that many spaces.
|
165
|
+
|
166
|
+
.. versionchanged:: 2.1.0
|
167
|
+
Changed *indent* from an integer number of spaces to a string.
|
168
|
+
|
169
|
+
If specified, *separators* should be an ``(item_separator, dict_separator)``
|
170
|
+
tuple. By default, ``(', ', ': ')`` are used. To get the most compact JSON
|
171
|
+
representation, you should specify ``(',', ':')`` to eliminate whitespace.
|
172
|
+
|
173
|
+
*encoding* is the character encoding for str instances, default is
|
174
|
+
``'utf-8'``.
|
175
|
+
|
176
|
+
*default(obj)* is a function that should return a serializable version of
|
177
|
+
*obj* or raise :exc:`TypeError`. The default simply raises :exc:`TypeError`.
|
178
|
+
|
179
|
+
To use a custom :class:`JSONEncoder` subclass (e.g. one that overrides the
|
180
|
+
:meth:`default` method to serialize additional types), specify it with the
|
181
|
+
*cls* kwarg.
|
182
|
+
|
183
|
+
If *use_decimal* is true (default: ``True``) then :class:`decimal.Decimal`
|
184
|
+
will be natively serialized to JSON with full precision.
|
185
|
+
|
186
|
+
.. versionchanged:: 2.1.0
|
187
|
+
*use_decimal* is new in 2.1.0.
|
188
|
+
|
189
|
+
.. versionchanged:: 2.2.0
|
190
|
+
The default of *use_decimal* changed to ``True`` in 2.2.0.
|
191
|
+
|
192
|
+
If *namedtuple_as_object* is true (default: ``True``),
|
193
|
+
objects with ``_asdict()`` methods will be encoded
|
194
|
+
as JSON objects.
|
195
|
+
|
196
|
+
.. versionchanged:: 2.2.0
|
197
|
+
*namedtuple_as_object* is new in 2.2.0.
|
198
|
+
|
199
|
+
.. versionchanged:: 2.3.0
|
200
|
+
*namedtuple_as_object* no longer requires that these objects be
|
201
|
+
subclasses of :class:`tuple`.
|
202
|
+
|
203
|
+
If *tuple_as_array* is true (default: ``True``),
|
204
|
+
:class:`tuple` (and subclasses) will be encoded as JSON arrays.
|
205
|
+
|
206
|
+
.. versionchanged:: 2.2.0
|
207
|
+
*tuple_as_array* is new in 2.2.0.
|
208
|
+
|
209
|
+
If *bigint_as_string* is true (default: ``False``), :class:`int`` ``2**53``
|
210
|
+
and higher or lower than ``-2**53`` will be encoded as strings. This is to
|
211
|
+
avoid the rounding that happens in Javascript otherwise. Note that this
|
212
|
+
option loses type information, so use with extreme caution.
|
213
|
+
|
214
|
+
.. versionchanged:: 2.4.0
|
215
|
+
*bigint_as_string* is new in 2.4.0.
|
216
|
+
|
217
|
+
If *sort_keys* is true (not the default), then the output of dictionaries
|
218
|
+
will be sorted by key; this is useful for regression tests to ensure that
|
219
|
+
JSON serializations can be compared on a day-to-day basis.
|
220
|
+
|
221
|
+
If *item_sort_key* is a callable (not the default), then the output of
|
222
|
+
dictionaries will be sorted with it. The callable will be used like this:
|
223
|
+
``sorted(dct.items(), key=item_sort_key)``. This option takes precedence
|
224
|
+
over *sort_keys*.
|
225
|
+
|
226
|
+
.. versionchanged:: 2.5.0
|
227
|
+
*item_sort_key* is new in 2.5.0.
|
228
|
+
|
229
|
+
.. note::
|
230
|
+
|
231
|
+
JSON is not a framed protocol so unlike :mod:`pickle` or :mod:`marshal` it
|
232
|
+
does not make sense to serialize more than one JSON document without some
|
233
|
+
container protocol to delimit them.
|
234
|
+
|
235
|
+
|
236
|
+
.. function:: dumps(obj[, skipkeys[, ensure_ascii[, check_circular[, allow_nan[, cls[, indent[, separators[, encoding[, default[, use_decimal[, namedtuple_as_object[, tuple_as_array[, bigint_as_string[, sort_keys[, item_sort_key[, **kw]]]]]]]]]]]]]]]])
|
237
|
+
|
238
|
+
Serialize *obj* to a JSON formatted :class:`str`.
|
239
|
+
|
240
|
+
If *ensure_ascii* is false, then the return value will be a
|
241
|
+
:class:`unicode` instance. The other arguments have the same meaning as in
|
242
|
+
:func:`dump`. Note that the default *ensure_ascii* setting has much
|
243
|
+
better performance.
|
244
|
+
|
245
|
+
|
246
|
+
.. function:: load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, object_pairs_hook[, use_decimal[, **kw]]]]]]]]])
|
247
|
+
|
248
|
+
Deserialize *fp* (a ``.read()``-supporting file-like object containing a JSON
|
249
|
+
document) to a Python object. :exc:`JSONDecodeError` will be
|
250
|
+
raised if the given JSON document is not valid.
|
251
|
+
|
252
|
+
If the contents of *fp* are encoded with an ASCII based encoding other than
|
253
|
+
UTF-8 (e.g. latin-1), then an appropriate *encoding* name must be specified.
|
254
|
+
Encodings that are not ASCII based (such as UCS-2) are not allowed, and
|
255
|
+
should be wrapped with ``codecs.getreader(fp)(encoding)``, or simply decoded
|
256
|
+
to a :class:`unicode` object and passed to :func:`loads`. The default
|
257
|
+
setting of ``'utf-8'`` is fastest and should be using whenever possible.
|
258
|
+
|
259
|
+
If *fp.read()* returns :class:`str` then decoded JSON strings that contain
|
260
|
+
only ASCII characters may be parsed as :class:`str` for performance and
|
261
|
+
memory reasons. If your code expects only :class:`unicode` the appropriate
|
262
|
+
solution is to wrap fp with a reader as demonstrated above.
|
263
|
+
|
264
|
+
*object_hook* is an optional function that will be called with the result of
|
265
|
+
any object literal decode (a :class:`dict`). The return value of
|
266
|
+
*object_hook* will be used instead of the :class:`dict`. This feature can be used
|
267
|
+
to implement custom decoders (e.g. JSON-RPC class hinting).
|
268
|
+
|
269
|
+
*object_pairs_hook* is an optional function that will be called with the
|
270
|
+
result of any object literal decode with an ordered list of pairs. The
|
271
|
+
return value of *object_pairs_hook* will be used instead of the
|
272
|
+
:class:`dict`. This feature can be used to implement custom decoders that
|
273
|
+
rely on the order that the key and value pairs are decoded (for example,
|
274
|
+
:class:`collections.OrderedDict` will remember the order of insertion). If
|
275
|
+
*object_hook* is also defined, the *object_pairs_hook* takes priority.
|
276
|
+
|
277
|
+
.. versionchanged:: 2.1.0
|
278
|
+
Added support for *object_pairs_hook*.
|
279
|
+
|
280
|
+
*parse_float*, if specified, will be called with the string of every JSON
|
281
|
+
float to be decoded. By default, this is equivalent to ``float(num_str)``.
|
282
|
+
This can be used to use another datatype or parser for JSON floats
|
283
|
+
(e.g. :class:`decimal.Decimal`).
|
284
|
+
|
285
|
+
*parse_int*, if specified, will be called with the string of every JSON int
|
286
|
+
to be decoded. By default, this is equivalent to ``int(num_str)``. This can
|
287
|
+
be used to use another datatype or parser for JSON integers
|
288
|
+
(e.g. :class:`float`).
|
289
|
+
|
290
|
+
*parse_constant*, if specified, will be called with one of the following
|
291
|
+
strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``. This can be used to
|
292
|
+
raise an exception if invalid JSON numbers are encountered.
|
293
|
+
|
294
|
+
If *use_decimal* is true (default: ``False``) then *parse_float* is set to
|
295
|
+
:class:`decimal.Decimal`. This is a convenience for parity with the
|
296
|
+
:func:`dump` parameter.
|
297
|
+
|
298
|
+
.. versionchanged:: 2.1.0
|
299
|
+
*use_decimal* is new in 2.1.0.
|
300
|
+
|
301
|
+
To use a custom :class:`JSONDecoder` subclass, specify it with the ``cls``
|
302
|
+
kwarg. Additional keyword arguments will be passed to the constructor of the
|
303
|
+
class.
|
304
|
+
|
305
|
+
.. note::
|
306
|
+
|
307
|
+
:func:`load` will read the rest of the file-like object as a string and
|
308
|
+
then call :func:`loads`. It does not stop at the end of the first valid
|
309
|
+
JSON document it finds and it will raise an error if there is anything
|
310
|
+
other than whitespace after the document. Except for files containing
|
311
|
+
only one JSON document, it is recommended to use :func:`loads`.
|
312
|
+
|
313
|
+
|
314
|
+
.. function:: loads(s[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, object_pairs_hook[, use_decimal[, **kw]]]]]]]]])
|
315
|
+
|
316
|
+
Deserialize *s* (a :class:`str` or :class:`unicode` instance containing a JSON
|
317
|
+
document) to a Python object. :exc:`JSONDecodeError` will be
|
318
|
+
raised if the given JSON document is not valid.
|
319
|
+
|
320
|
+
If *s* is a :class:`str` instance and is encoded with an ASCII based encoding
|
321
|
+
other than UTF-8 (e.g. latin-1), then an appropriate *encoding* name must be
|
322
|
+
specified. Encodings that are not ASCII based (such as UCS-2) are not
|
323
|
+
allowed and should be decoded to :class:`unicode` first.
|
324
|
+
|
325
|
+
If *s* is a :class:`str` then decoded JSON strings that contain
|
326
|
+
only ASCII characters may be parsed as :class:`str` for performance and
|
327
|
+
memory reasons. If your code expects only :class:`unicode` the appropriate
|
328
|
+
solution is decode *s* to :class:`unicode` prior to calling loads.
|
329
|
+
|
330
|
+
The other arguments have the same meaning as in :func:`load`.
|
331
|
+
|
332
|
+
|
333
|
+
Encoders and decoders
|
334
|
+
---------------------
|
335
|
+
|
336
|
+
.. class:: JSONDecoder([encoding[, object_hook[, parse_float[, parse_int[, parse_constant[, object_pairs_hook[, strict]]]]]]])
|
337
|
+
|
338
|
+
Simple JSON decoder.
|
339
|
+
|
340
|
+
Performs the following translations in decoding by default:
|
341
|
+
|
342
|
+
+---------------+-------------------+
|
343
|
+
| JSON | Python |
|
344
|
+
+===============+===================+
|
345
|
+
| object | dict |
|
346
|
+
+---------------+-------------------+
|
347
|
+
| array | list |
|
348
|
+
+---------------+-------------------+
|
349
|
+
| string | unicode |
|
350
|
+
+---------------+-------------------+
|
351
|
+
| number (int) | int, long |
|
352
|
+
+---------------+-------------------+
|
353
|
+
| number (real) | float |
|
354
|
+
+---------------+-------------------+
|
355
|
+
| true | True |
|
356
|
+
+---------------+-------------------+
|
357
|
+
| false | False |
|
358
|
+
+---------------+-------------------+
|
359
|
+
| null | None |
|
360
|
+
+---------------+-------------------+
|
361
|
+
|
362
|
+
It also understands ``NaN``, ``Infinity``, and ``-Infinity`` as their
|
363
|
+
corresponding ``float`` values, which is outside the JSON spec.
|
364
|
+
|
365
|
+
*encoding* determines the encoding used to interpret any :class:`str` objects
|
366
|
+
decoded by this instance (``'utf-8'`` by default). It has no effect when decoding
|
367
|
+
:class:`unicode` objects.
|
368
|
+
|
369
|
+
Note that currently only encodings that are a superset of ASCII work, strings
|
370
|
+
of other encodings should be passed in as :class:`unicode`.
|
371
|
+
|
372
|
+
*object_hook* is an optional function that will be called with the result of
|
373
|
+
every JSON object decoded and its return value will be used in place of the
|
374
|
+
given :class:`dict`. This can be used to provide custom deserializations
|
375
|
+
(e.g. to support JSON-RPC class hinting).
|
376
|
+
|
377
|
+
*object_pairs_hook* is an optional function that will be called with the
|
378
|
+
result of any object literal decode with an ordered list of pairs. The
|
379
|
+
return value of *object_pairs_hook* will be used instead of the
|
380
|
+
:class:`dict`. This feature can be used to implement custom decoders that
|
381
|
+
rely on the order that the key and value pairs are decoded (for example,
|
382
|
+
:class:`collections.OrderedDict` will remember the order of insertion). If
|
383
|
+
*object_hook* is also defined, the *object_pairs_hook* takes priority.
|
384
|
+
|
385
|
+
.. versionchanged:: 2.1.0
|
386
|
+
Added support for *object_pairs_hook*.
|
387
|
+
|
388
|
+
*parse_float*, if specified, will be called with the string of every JSON
|
389
|
+
float to be decoded. By default, this is equivalent to ``float(num_str)``.
|
390
|
+
This can be used to use another datatype or parser for JSON floats
|
391
|
+
(e.g. :class:`decimal.Decimal`).
|
392
|
+
|
393
|
+
*parse_int*, if specified, will be called with the string of every JSON int
|
394
|
+
to be decoded. By default, this is equivalent to ``int(num_str)``. This can
|
395
|
+
be used to use another datatype or parser for JSON integers
|
396
|
+
(e.g. :class:`float`).
|
397
|
+
|
398
|
+
*parse_constant*, if specified, will be called with one of the following
|
399
|
+
strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``. This can be used to
|
400
|
+
raise an exception if invalid JSON numbers are encountered.
|
401
|
+
|
402
|
+
*strict* controls the parser's behavior when it encounters an invalid
|
403
|
+
control character in a string. The default setting of ``True`` means that
|
404
|
+
unescaped control characters are parse errors, if ``False`` then control
|
405
|
+
characters will be allowed in strings.
|
406
|
+
|
407
|
+
.. method:: decode(s)
|
408
|
+
|
409
|
+
Return the Python representation of *s* (a :class:`str` or
|
410
|
+
:class:`unicode` instance containing a JSON document)
|
411
|
+
|
412
|
+
If *s* is a :class:`str` then decoded JSON strings that contain
|
413
|
+
only ASCII characters may be parsed as :class:`str` for performance and
|
414
|
+
memory reasons. If your code expects only :class:`unicode` the
|
415
|
+
appropriate solution is decode *s* to :class:`unicode` prior to calling
|
416
|
+
decode.
|
417
|
+
|
418
|
+
:exc:`JSONDecodeError` will be raised if the given JSON
|
419
|
+
document is not valid.
|
420
|
+
|
421
|
+
.. method:: raw_decode(s)
|
422
|
+
|
423
|
+
Decode a JSON document from *s* (a :class:`str` or :class:`unicode`
|
424
|
+
beginning with a JSON document) and return a 2-tuple of the Python
|
425
|
+
representation and the index in *s* where the document ended.
|
426
|
+
|
427
|
+
This can be used to decode a JSON document from a string that may have
|
428
|
+
extraneous data at the end.
|
429
|
+
|
430
|
+
:exc:`JSONDecodeError` will be raised if the given JSON
|
431
|
+
document is not valid.
|
432
|
+
|
433
|
+
.. class:: JSONEncoder([skipkeys[, ensure_ascii[, check_circular[, allow_nan[, sort_keys[, indent[, separators[, encoding[, default[, use_decimal[, namedtuple_as_object[, tuple_as_array[, bigint_as_string[, item_sort_key]]]]]]]]]]]]])
|
434
|
+
|
435
|
+
Extensible JSON encoder for Python data structures.
|
436
|
+
|
437
|
+
Supports the following objects and types by default:
|
438
|
+
|
439
|
+
+-------------------+---------------+
|
440
|
+
| Python | JSON |
|
441
|
+
+===================+===============+
|
442
|
+
| dict, namedtuple | object |
|
443
|
+
+-------------------+---------------+
|
444
|
+
| list, tuple | array |
|
445
|
+
+-------------------+---------------+
|
446
|
+
| str, unicode | string |
|
447
|
+
+-------------------+---------------+
|
448
|
+
| int, long, float | number |
|
449
|
+
+-------------------+---------------+
|
450
|
+
| True | true |
|
451
|
+
+-------------------+---------------+
|
452
|
+
| False | false |
|
453
|
+
+-------------------+---------------+
|
454
|
+
| None | null |
|
455
|
+
+-------------------+---------------+
|
456
|
+
|
457
|
+
.. versionchanged:: 2.2.0
|
458
|
+
Changed *namedtuple* encoding from JSON array to object.
|
459
|
+
|
460
|
+
To extend this to recognize other objects, subclass and implement a
|
461
|
+
:meth:`default` method with another method that returns a serializable object
|
462
|
+
for ``o`` if possible, otherwise it should call the superclass implementation
|
463
|
+
(to raise :exc:`TypeError`).
|
464
|
+
|
465
|
+
If *skipkeys* is false (the default), then it is a :exc:`TypeError` to
|
466
|
+
attempt encoding of keys that are not str, int, long, float or None. If
|
467
|
+
*skipkeys* is true, such items are simply skipped.
|
468
|
+
|
469
|
+
If *ensure_ascii* is true (the default), the output is guaranteed to be
|
470
|
+
:class:`str` objects with all incoming unicode characters escaped. If
|
471
|
+
*ensure_ascii* is false, the output will be a unicode object.
|
472
|
+
|
473
|
+
If *check_circular* is false (the default), then lists, dicts, and custom
|
474
|
+
encoded objects will be checked for circular references during encoding to
|
475
|
+
prevent an infinite recursion (which would cause an :exc:`OverflowError`).
|
476
|
+
Otherwise, no such check takes place.
|
477
|
+
|
478
|
+
If *allow_nan* is true (the default), then ``NaN``, ``Infinity``, and
|
479
|
+
``-Infinity`` will be encoded as such. This behavior is not JSON
|
480
|
+
specification compliant, but is consistent with most JavaScript based
|
481
|
+
encoders and decoders. Otherwise, it will be a :exc:`ValueError` to encode
|
482
|
+
such floats.
|
483
|
+
|
484
|
+
If *sort_keys* is true (not the default), then the output of dictionaries
|
485
|
+
will be sorted by key; this is useful for regression tests to ensure that
|
486
|
+
JSON serializations can be compared on a day-to-day basis.
|
487
|
+
|
488
|
+
If *item_sort_key* is a callable (not the default), then the output of
|
489
|
+
dictionaries will be sorted with it. The callable will be used like this:
|
490
|
+
``sorted(dct.items(), key=item_sort_key)``. This option takes precedence
|
491
|
+
over *sort_keys*.
|
492
|
+
|
493
|
+
.. versionchanged:: 2.5.0
|
494
|
+
*item_sort_key* is new in 2.5.0.
|
495
|
+
|
496
|
+
If *indent* is a string, then JSON array elements and object members
|
497
|
+
will be pretty-printed with a newline followed by that string repeated
|
498
|
+
for each level of nesting. ``None`` (the default) selects the most compact
|
499
|
+
representation without any newlines. For backwards compatibility with
|
500
|
+
versions of simplejson earlier than 2.1.0, an integer is also accepted
|
501
|
+
and is converted to a string with that many spaces.
|
502
|
+
|
503
|
+
.. versionchanged:: 2.1.0
|
504
|
+
Changed *indent* from an integer number of spaces to a string.
|
505
|
+
|
506
|
+
If specified, *separators* should be an ``(item_separator, key_separator)``
|
507
|
+
tuple. By default, ``(', ', ': ')`` are used. To get the most compact JSON
|
508
|
+
representation, you should specify ``(',', ':')`` to eliminate whitespace.
|
509
|
+
|
510
|
+
If specified, *default* should be a function that gets called for objects
|
511
|
+
that can't otherwise be serialized. It should return a JSON encodable
|
512
|
+
version of the object or raise a :exc:`TypeError`.
|
513
|
+
|
514
|
+
If *encoding* is not ``None``, then all input strings will be transformed
|
515
|
+
into unicode using that encoding prior to JSON-encoding. The default is
|
516
|
+
``'utf-8'``.
|
517
|
+
|
518
|
+
If *namedtuple_as_object* is true (default: ``True``),
|
519
|
+
objects with ``_asdict()`` methods will be encoded
|
520
|
+
as JSON objects.
|
521
|
+
|
522
|
+
.. versionchanged:: 2.2.0
|
523
|
+
*namedtuple_as_object* is new in 2.2.0.
|
524
|
+
|
525
|
+
.. versionchanged:: 2.3.0
|
526
|
+
*namedtuple_as_object* no longer requires that these objects be
|
527
|
+
subclasses of :class:`tuple`.
|
528
|
+
|
529
|
+
If *tuple_as_array* is true (default: ``True``),
|
530
|
+
:class:`tuple` (and subclasses) will be encoded as JSON arrays.
|
531
|
+
|
532
|
+
.. versionchanged:: 2.2.0
|
533
|
+
*tuple_as_array* is new in 2.2.0.
|
534
|
+
|
535
|
+
If *bigint_as_string* is true (default: ``False``), :class:`int`` ``2**53``
|
536
|
+
and higher or lower than ``-2**53`` will be encoded as strings. This is to
|
537
|
+
avoid the rounding that happens in Javascript otherwise. Note that this
|
538
|
+
option loses type information, so use with extreme caution.
|
539
|
+
|
540
|
+
.. versionchanged:: 2.4.0
|
541
|
+
*bigint_as_string* is new in 2.4.0.
|
542
|
+
|
543
|
+
|
544
|
+
.. method:: default(o)
|
545
|
+
|
546
|
+
Implement this method in a subclass such that it returns a serializable
|
547
|
+
object for *o*, or calls the base implementation (to raise a
|
548
|
+
:exc:`TypeError`).
|
549
|
+
|
550
|
+
For example, to support arbitrary iterators, you could implement default
|
551
|
+
like this::
|
552
|
+
|
553
|
+
def default(self, o):
|
554
|
+
try:
|
555
|
+
iterable = iter(o)
|
556
|
+
except TypeError:
|
557
|
+
pass
|
558
|
+
else:
|
559
|
+
return list(iterable)
|
560
|
+
return JSONEncoder.default(self, o)
|
561
|
+
|
562
|
+
|
563
|
+
.. method:: encode(o)
|
564
|
+
|
565
|
+
Return a JSON string representation of a Python data structure, *o*. For
|
566
|
+
example::
|
567
|
+
|
568
|
+
>>> import simplejson as json
|
569
|
+
>>> json.JSONEncoder().encode({"foo": ["bar", "baz"]})
|
570
|
+
'{"foo": ["bar", "baz"]}'
|
571
|
+
|
572
|
+
|
573
|
+
.. method:: iterencode(o)
|
574
|
+
|
575
|
+
Encode the given object, *o*, and yield each string representation as
|
576
|
+
available. For example::
|
577
|
+
|
578
|
+
for chunk in JSONEncoder().iterencode(bigobject):
|
579
|
+
mysocket.write(chunk)
|
580
|
+
|
581
|
+
Note that :meth:`encode` has much better performance than
|
582
|
+
:meth:`iterencode`.
|
583
|
+
|
584
|
+
.. class:: JSONEncoderForHTML([skipkeys[, ensure_ascii[, check_circular[, allow_nan[, sort_keys[, indent[, separators[, encoding[, default[, use_decimal[, namedtuple_as_object[, tuple_as_array[, bigint_as_string[, item_sort_key]]]]]]]]]]]]])
|
585
|
+
|
586
|
+
Subclass of :class:`JSONEncoder` that escapes &, <, and > for embedding in HTML.
|
587
|
+
|
588
|
+
.. versionchanged:: 2.1.0
|
589
|
+
New in 2.1.0
|
590
|
+
|
591
|
+
Exceptions
|
592
|
+
----------
|
593
|
+
|
594
|
+
.. exception:: JSONDecodeError(msg, doc, pos[, end])
|
595
|
+
|
596
|
+
Subclass of :exc:`ValueError` with the following additional attributes:
|
597
|
+
|
598
|
+
.. attribute:: msg
|
599
|
+
|
600
|
+
The unformatted error message
|
601
|
+
|
602
|
+
.. attribute:: doc
|
603
|
+
|
604
|
+
The JSON document being parsed
|
605
|
+
|
606
|
+
.. attribute:: pos
|
607
|
+
|
608
|
+
The start index of doc where parsing failed
|
609
|
+
|
610
|
+
.. attribute:: end
|
611
|
+
|
612
|
+
The end index of doc where parsing failed (may be ``None``)
|
613
|
+
|
614
|
+
.. attribute:: lineno
|
615
|
+
|
616
|
+
The line corresponding to pos
|
617
|
+
|
618
|
+
.. attribute:: colno
|
619
|
+
|
620
|
+
The column corresponding to pos
|
621
|
+
|
622
|
+
.. attribute:: endlineno
|
623
|
+
|
624
|
+
The line corresponding to end (may be ``None``)
|
625
|
+
|
626
|
+
.. attribute:: endcolno
|
627
|
+
|
628
|
+
The column corresponding to end (may be ``None``)
|