summaryrefslogtreecommitdiff
path: root/ruby_2_2/lib
diff options
context:
space:
mode:
Diffstat (limited to 'ruby_2_2/lib')
-rw-r--r--ruby_2_2/lib/English.rb185
-rw-r--r--ruby_2_2/lib/abbrev.rb131
-rw-r--r--ruby_2_2/lib/base64.rb91
-rw-r--r--ruby_2_2/lib/benchmark.rb557
-rw-r--r--ruby_2_2/lib/cgi.rb295
-rw-r--r--ruby_2_2/lib/cgi/cookie.rb170
-rw-r--r--ruby_2_2/lib/cgi/core.rb880
-rw-r--r--ruby_2_2/lib/cgi/html.rb1034
-rw-r--r--ruby_2_2/lib/cgi/session.rb531
-rw-r--r--ruby_2_2/lib/cgi/session/pstore.rb100
-rw-r--r--ruby_2_2/lib/cgi/util.rb194
-rw-r--r--ruby_2_2/lib/cmath.rb442
-rw-r--r--ruby_2_2/lib/csv.rb2341
-rw-r--r--ruby_2_2/lib/debug.rb1087
-rw-r--r--ruby_2_2/lib/delegate.rb417
-rw-r--r--ruby_2_2/lib/drb.rb2
-rw-r--r--ruby_2_2/lib/drb/acl.rb232
-rw-r--r--ruby_2_2/lib/drb/drb.rb1864
-rw-r--r--ruby_2_2/lib/drb/eq.rb14
-rw-r--r--ruby_2_2/lib/drb/extserv.rb43
-rw-r--r--ruby_2_2/lib/drb/extservm.rb93
-rw-r--r--ruby_2_2/lib/drb/gw.rb160
-rw-r--r--ruby_2_2/lib/drb/invokemethod.rb34
-rw-r--r--ruby_2_2/lib/drb/observer.rb25
-rw-r--r--ruby_2_2/lib/drb/ssl.rb345
-rw-r--r--ruby_2_2/lib/drb/timeridconv.rb95
-rw-r--r--ruby_2_2/lib/drb/unix.rb117
-rw-r--r--ruby_2_2/lib/e2mmap.rb172
-rw-r--r--ruby_2_2/lib/erb.rb1022
-rw-r--r--ruby_2_2/lib/fileutils.rb1762
-rw-r--r--ruby_2_2/lib/find.rb88
-rw-r--r--ruby_2_2/lib/forwardable.rb297
-rw-r--r--ruby_2_2/lib/getoptlong.rb612
-rw-r--r--ruby_2_2/lib/ipaddr.rb658
-rw-r--r--ruby_2_2/lib/irb.rb703
-rw-r--r--ruby_2_2/lib/irb/cmd/chws.rb33
-rw-r--r--ruby_2_2/lib/irb/cmd/fork.rb38
-rw-r--r--ruby_2_2/lib/irb/cmd/help.rb41
-rw-r--r--ruby_2_2/lib/irb/cmd/load.rb66
-rw-r--r--ruby_2_2/lib/irb/cmd/nop.rb38
-rw-r--r--ruby_2_2/lib/irb/cmd/pushws.rb40
-rw-r--r--ruby_2_2/lib/irb/cmd/subirb.rb42
-rw-r--r--ruby_2_2/lib/irb/completion.rb227
-rw-r--r--ruby_2_2/lib/irb/context.rb419
-rw-r--r--ruby_2_2/lib/irb/ext/change-ws.rb45
-rw-r--r--ruby_2_2/lib/irb/ext/history.rb118
-rw-r--r--ruby_2_2/lib/irb/ext/loader.rb128
-rw-r--r--ruby_2_2/lib/irb/ext/math-mode.rb47
-rw-r--r--ruby_2_2/lib/irb/ext/multi-irb.rb265
-rw-r--r--ruby_2_2/lib/irb/ext/save-history.rb103
-rw-r--r--ruby_2_2/lib/irb/ext/tracer.rb71
-rw-r--r--ruby_2_2/lib/irb/ext/use-loader.rb73
-rw-r--r--ruby_2_2/lib/irb/ext/workspaces.rb66
-rw-r--r--ruby_2_2/lib/irb/extend-command.rb308
-rw-r--r--ruby_2_2/lib/irb/frame.rb80
-rw-r--r--ruby_2_2/lib/irb/help.rb36
-rw-r--r--ruby_2_2/lib/irb/init.rb304
-rw-r--r--ruby_2_2/lib/irb/input-method.rb191
-rw-r--r--ruby_2_2/lib/irb/inspector.rb131
-rw-r--r--ruby_2_2/lib/irb/lc/.document4
-rw-r--r--ruby_2_2/lib/irb/lc/error.rb31
-rw-r--r--ruby_2_2/lib/irb/lc/help-message50
-rw-r--r--ruby_2_2/lib/irb/lc/ja/encoding_aliases.rb10
-rw-r--r--ruby_2_2/lib/irb/lc/ja/error.rb30
-rw-r--r--ruby_2_2/lib/irb/lc/ja/help-message53
-rw-r--r--ruby_2_2/lib/irb/locale.rb181
-rw-r--r--ruby_2_2/lib/irb/magic-file.rb37
-rw-r--r--ruby_2_2/lib/irb/notifier.rb231
-rw-r--r--ruby_2_2/lib/irb/output-method.rb91
-rw-r--r--ruby_2_2/lib/irb/ruby-lex.rb1170
-rw-r--r--ruby_2_2/lib/irb/ruby-token.rb266
-rw-r--r--ruby_2_2/lib/irb/slex.rb281
-rw-r--r--ruby_2_2/lib/irb/src_encoding.rb4
-rw-r--r--ruby_2_2/lib/irb/version.rb15
-rw-r--r--ruby_2_2/lib/irb/workspace.rb114
-rw-r--r--ruby_2_2/lib/irb/ws-for-case-2.rb14
-rw-r--r--ruby_2_2/lib/irb/xmp.rb169
-rw-r--r--ruby_2_2/lib/logger.rb737
-rw-r--r--ruby_2_2/lib/mathn.rb191
-rw-r--r--ruby_2_2/lib/matrix.rb2161
-rw-r--r--ruby_2_2/lib/matrix/eigenvalue_decomposition.rb882
-rw-r--r--ruby_2_2/lib/matrix/lup_decomposition.rb218
-rw-r--r--ruby_2_2/lib/mkmf.rb2687
-rw-r--r--ruby_2_2/lib/monitor.rb300
-rw-r--r--ruby_2_2/lib/mutex_m.rb111
-rw-r--r--ruby_2_2/lib/net/ftp.rb1128
-rw-r--r--ruby_2_2/lib/net/http.rb1559
-rw-r--r--ruby_2_2/lib/net/http/backward.rb25
-rw-r--r--ruby_2_2/lib/net/http/exceptions.rb25
-rw-r--r--ruby_2_2/lib/net/http/generic_request.rb337
-rw-r--r--ruby_2_2/lib/net/http/header.rb452
-rw-r--r--ruby_2_2/lib/net/http/proxy_delta.rb16
-rw-r--r--ruby_2_2/lib/net/http/request.rb20
-rw-r--r--ruby_2_2/lib/net/http/requests.rb122
-rw-r--r--ruby_2_2/lib/net/http/response.rb416
-rw-r--r--ruby_2_2/lib/net/http/responses.rb273
-rw-r--r--ruby_2_2/lib/net/https.rb22
-rw-r--r--ruby_2_2/lib/net/imap.rb3622
-rw-r--r--ruby_2_2/lib/net/pop.rb1021
-rw-r--r--ruby_2_2/lib/net/protocol.rb420
-rw-r--r--ruby_2_2/lib/net/smtp.rb1073
-rw-r--r--ruby_2_2/lib/net/telnet.rb763
-rw-r--r--ruby_2_2/lib/observer.rb203
-rw-r--r--ruby_2_2/lib/open-uri.rb801
-rw-r--r--ruby_2_2/lib/open3.rb663
-rw-r--r--ruby_2_2/lib/optionparser.rb1
-rw-r--r--ruby_2_2/lib/optparse.rb2004
-rw-r--r--ruby_2_2/lib/optparse/ac.rb50
-rw-r--r--ruby_2_2/lib/optparse/date.rb17
-rw-r--r--ruby_2_2/lib/optparse/shellwords.rb6
-rw-r--r--ruby_2_2/lib/optparse/time.rb10
-rw-r--r--ruby_2_2/lib/optparse/uri.rb6
-rw-r--r--ruby_2_2/lib/optparse/version.rb70
-rw-r--r--ruby_2_2/lib/ostruct.rb316
-rw-r--r--ruby_2_2/lib/pp.rb546
-rw-r--r--ruby_2_2/lib/prettyprint.rb554
-rw-r--r--ruby_2_2/lib/prime.rb487
-rw-r--r--ruby_2_2/lib/profile.rb10
-rw-r--r--ruby_2_2/lib/profiler.rb148
-rw-r--r--ruby_2_2/lib/pstore.rb484
-rw-r--r--ruby_2_2/lib/racc/parser.rb622
-rw-r--r--ruby_2_2/lib/racc/rdoc/grammar.en.rdoc219
-rw-r--r--ruby_2_2/lib/rake.rb79
-rw-r--r--ruby_2_2/lib/rake/alt_system.rb110
-rw-r--r--ruby_2_2/lib/rake/application.rb790
-rw-r--r--ruby_2_2/lib/rake/backtrace.rb23
-rw-r--r--ruby_2_2/lib/rake/clean.rb76
-rw-r--r--ruby_2_2/lib/rake/cloneable.rb16
-rw-r--r--ruby_2_2/lib/rake/contrib/.document1
-rw-r--r--ruby_2_2/lib/rake/contrib/compositepublisher.rb21
-rw-r--r--ruby_2_2/lib/rake/contrib/ftptools.rb137
-rw-r--r--ruby_2_2/lib/rake/contrib/publisher.rb81
-rw-r--r--ruby_2_2/lib/rake/contrib/rubyforgepublisher.rb18
-rw-r--r--ruby_2_2/lib/rake/contrib/sshpublisher.rb61
-rw-r--r--ruby_2_2/lib/rake/contrib/sys.rb4
-rw-r--r--ruby_2_2/lib/rake/cpu_counter.rb125
-rw-r--r--ruby_2_2/lib/rake/default_loader.rb14
-rw-r--r--ruby_2_2/lib/rake/dsl_definition.rb201
-rw-r--r--ruby_2_2/lib/rake/early_time.rb21
-rw-r--r--ruby_2_2/lib/rake/ext/core.rb25
-rw-r--r--ruby_2_2/lib/rake/ext/module.rb2
-rw-r--r--ruby_2_2/lib/rake/ext/pathname.rb25
-rw-r--r--ruby_2_2/lib/rake/ext/string.rb173
-rw-r--r--ruby_2_2/lib/rake/ext/time.rb16
-rw-r--r--ruby_2_2/lib/rake/file_creation_task.rb24
-rw-r--r--ruby_2_2/lib/rake/file_list.rb428
-rw-r--r--ruby_2_2/lib/rake/file_task.rb46
-rw-r--r--ruby_2_2/lib/rake/file_utils.rb128
-rw-r--r--ruby_2_2/lib/rake/file_utils_ext.rb144
-rw-r--r--ruby_2_2/lib/rake/gempackagetask.rb4
-rw-r--r--ruby_2_2/lib/rake/invocation_chain.rb56
-rw-r--r--ruby_2_2/lib/rake/invocation_exception_mixin.rb16
-rw-r--r--ruby_2_2/lib/rake/late_time.rb17
-rw-r--r--ruby_2_2/lib/rake/linked_list.rb103
-rw-r--r--ruby_2_2/lib/rake/loaders/makefile.rb40
-rw-r--r--ruby_2_2/lib/rake/multi_task.rb13
-rw-r--r--ruby_2_2/lib/rake/name_space.rb38
-rw-r--r--ruby_2_2/lib/rake/packagetask.rb199
-rw-r--r--ruby_2_2/lib/rake/pathmap.rb3
-rw-r--r--ruby_2_2/lib/rake/phony.rb15
-rw-r--r--ruby_2_2/lib/rake/private_reader.rb20
-rw-r--r--ruby_2_2/lib/rake/promise.rb99
-rw-r--r--ruby_2_2/lib/rake/pseudo_status.rb29
-rw-r--r--ruby_2_2/lib/rake/rake_module.rb38
-rw-r--r--ruby_2_2/lib/rake/rake_test_loader.rb22
-rw-r--r--ruby_2_2/lib/rake/rdoctask.rb4
-rw-r--r--ruby_2_2/lib/rake/ruby182_test_unit_fix.rb29
-rw-r--r--ruby_2_2/lib/rake/rule_recursion_overflow_error.rb20
-rw-r--r--ruby_2_2/lib/rake/runtest.rb27
-rw-r--r--ruby_2_2/lib/rake/scope.rb42
-rw-r--r--ruby_2_2/lib/rake/task.rb383
-rw-r--r--ruby_2_2/lib/rake/task_argument_error.rb7
-rw-r--r--ruby_2_2/lib/rake/task_arguments.rb98
-rw-r--r--ruby_2_2/lib/rake/task_manager.rb310
-rw-r--r--ruby_2_2/lib/rake/tasklib.rb24
-rw-r--r--ruby_2_2/lib/rake/testtask.rb212
-rw-r--r--ruby_2_2/lib/rake/thread_history_display.rb48
-rw-r--r--ruby_2_2/lib/rake/thread_pool.rb164
-rw-r--r--ruby_2_2/lib/rake/trace_output.rb22
-rw-r--r--ruby_2_2/lib/rake/version.rb7
-rw-r--r--ruby_2_2/lib/rake/win32.rb56
-rw-r--r--ruby_2_2/lib/rbconfig/.document1
-rw-r--r--ruby_2_2/lib/rbconfig/datadir.rb13
-rw-r--r--ruby_2_2/lib/rdoc.rb185
-rw-r--r--ruby_2_2/lib/rdoc/alias.rb111
-rw-r--r--ruby_2_2/lib/rdoc/anon_class.rb10
-rw-r--r--ruby_2_2/lib/rdoc/any_method.rb316
-rw-r--r--ruby_2_2/lib/rdoc/attr.rb175
-rw-r--r--ruby_2_2/lib/rdoc/class_module.rb799
-rw-r--r--ruby_2_2/lib/rdoc/code_object.rb429
-rw-r--r--ruby_2_2/lib/rdoc/code_objects.rb5
-rw-r--r--ruby_2_2/lib/rdoc/comment.rb229
-rw-r--r--ruby_2_2/lib/rdoc/constant.rb186
-rw-r--r--ruby_2_2/lib/rdoc/context.rb1211
-rw-r--r--ruby_2_2/lib/rdoc/context/section.rb238
-rw-r--r--ruby_2_2/lib/rdoc/cross_reference.rb183
-rw-r--r--ruby_2_2/lib/rdoc/encoding.rb99
-rw-r--r--ruby_2_2/lib/rdoc/erb_partial.rb18
-rw-r--r--ruby_2_2/lib/rdoc/erbio.rb37
-rw-r--r--ruby_2_2/lib/rdoc/extend.rb9
-rw-r--r--ruby_2_2/lib/rdoc/generator.rb51
-rw-r--r--ruby_2_2/lib/rdoc/generator/darkfish.rb760
-rw-r--r--ruby_2_2/lib/rdoc/generator/json_index.rb292
-rw-r--r--ruby_2_2/lib/rdoc/generator/markup.rb169
-rw-r--r--ruby_2_2/lib/rdoc/generator/pot.rb97
-rw-r--r--ruby_2_2/lib/rdoc/generator/pot/message_extractor.rb67
-rw-r--r--ruby_2_2/lib/rdoc/generator/pot/po.rb83
-rw-r--r--ruby_2_2/lib/rdoc/generator/pot/po_entry.rb140
-rw-r--r--ruby_2_2/lib/rdoc/generator/ri.rb30
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/.document0
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/_footer.rhtml5
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/_head.rhtml19
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml19
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml9
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml15
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml9
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml15
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml15
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml12
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml11
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml12
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml11
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml14
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml11
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml18
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/class.rhtml174
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/css/fonts.css167
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/css/rdoc.css590
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttfbin94668 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttfbin94196 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttfbin96184 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttfbin95316 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttfbin71200 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttfbin71692 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/add.pngbin733 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/arrow_up.pngbin372 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/brick.pngbin452 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/brick_link.pngbin764 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/bug.pngbin774 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/bullet_black.pngbin211 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.pngbin207 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.pngbin209 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/date.pngbin626 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/delete.pngbin715 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/find.pngbin659 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gifbin5886 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/macFFBgHack.pngbin207 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/package.pngbin853 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/page_green.pngbin621 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/page_white_text.pngbin342 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/page_white_width.pngbin309 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/plugin.pngbin591 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/ruby.pngbin592 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/tag_blue.pngbin1880 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/tag_green.pngbin613 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/transparent.pngbin97 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/wrench.pngbin610 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/wrench_orange.pngbin584 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/images/zoom.pngbin692 -> 0 bytes
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/index.rhtml23
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/js/darkfish.js161
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/js/jquery.js4
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/js/search.js109
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/page.rhtml18
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml18
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/servlet_root.rhtml63
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml58
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/json_index/.document1
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/json_index/js/navigation.js142
-rw-r--r--ruby_2_2/lib/rdoc/generator/template/json_index/js/searcher.js228
-rw-r--r--ruby_2_2/lib/rdoc/ghost_method.rb6
-rw-r--r--ruby_2_2/lib/rdoc/i18n.rb9
-rw-r--r--ruby_2_2/lib/rdoc/i18n/locale.rb101
-rw-r--r--ruby_2_2/lib/rdoc/i18n/text.rb125
-rw-r--r--ruby_2_2/lib/rdoc/include.rb9
-rw-r--r--ruby_2_2/lib/rdoc/known_classes.rb72
-rw-r--r--ruby_2_2/lib/rdoc/markdown.rb16133
-rw-r--r--ruby_2_2/lib/rdoc/markdown/entities.rb2131
-rw-r--r--ruby_2_2/lib/rdoc/markdown/literals_1_9.rb420
-rw-r--r--ruby_2_2/lib/rdoc/markup.rb869
-rw-r--r--ruby_2_2/lib/rdoc/markup/attr_changer.rb22
-rw-r--r--ruby_2_2/lib/rdoc/markup/attr_span.rb29
-rw-r--r--ruby_2_2/lib/rdoc/markup/attribute_manager.rb343
-rw-r--r--ruby_2_2/lib/rdoc/markup/attributes.rb70
-rw-r--r--ruby_2_2/lib/rdoc/markup/blank_line.rb27
-rw-r--r--ruby_2_2/lib/rdoc/markup/block_quote.rb14
-rw-r--r--ruby_2_2/lib/rdoc/markup/document.rb164
-rw-r--r--ruby_2_2/lib/rdoc/markup/formatter.rb264
-rw-r--r--ruby_2_2/lib/rdoc/markup/formatter_test_case.rb767
-rw-r--r--ruby_2_2/lib/rdoc/markup/hard_break.rb31
-rw-r--r--ruby_2_2/lib/rdoc/markup/heading.rb78
-rw-r--r--ruby_2_2/lib/rdoc/markup/include.rb42
-rw-r--r--ruby_2_2/lib/rdoc/markup/indented_paragraph.rb47
-rw-r--r--ruby_2_2/lib/rdoc/markup/inline.rb1
-rw-r--r--ruby_2_2/lib/rdoc/markup/list.rb101
-rw-r--r--ruby_2_2/lib/rdoc/markup/list_item.rb99
-rw-r--r--ruby_2_2/lib/rdoc/markup/paragraph.rb28
-rw-r--r--ruby_2_2/lib/rdoc/markup/parser.rb558
-rw-r--r--ruby_2_2/lib/rdoc/markup/pre_process.rb293
-rw-r--r--ruby_2_2/lib/rdoc/markup/raw.rb69
-rw-r--r--ruby_2_2/lib/rdoc/markup/rule.rb20
-rw-r--r--ruby_2_2/lib/rdoc/markup/special.rb40
-rw-r--r--ruby_2_2/lib/rdoc/markup/text_formatter_test_case.rb114
-rw-r--r--ruby_2_2/lib/rdoc/markup/to_ansi.rb93
-rw-r--r--ruby_2_2/lib/rdoc/markup/to_bs.rb78
-rw-r--r--ruby_2_2/lib/rdoc/markup/to_html.rb398
-rw-r--r--ruby_2_2/lib/rdoc/markup/to_html_crossref.rb160
-rw-r--r--ruby_2_2/lib/rdoc/markup/to_html_snippet.rb284
-rw-r--r--ruby_2_2/lib/rdoc/markup/to_joined_paragraph.rb71
-rw-r--r--ruby_2_2/lib/rdoc/markup/to_label.rb74
-rw-r--r--ruby_2_2/lib/rdoc/markup/to_markdown.rb191
-rw-r--r--ruby_2_2/lib/rdoc/markup/to_rdoc.rb333
-rw-r--r--ruby_2_2/lib/rdoc/markup/to_table_of_contents.rb87
-rw-r--r--ruby_2_2/lib/rdoc/markup/to_test.rb69
-rw-r--r--ruby_2_2/lib/rdoc/markup/to_tt_only.rb120
-rw-r--r--ruby_2_2/lib/rdoc/markup/verbatim.rb83
-rw-r--r--ruby_2_2/lib/rdoc/meta_method.rb6
-rw-r--r--ruby_2_2/lib/rdoc/method_attr.rb418
-rw-r--r--ruby_2_2/lib/rdoc/mixin.rb120
-rw-r--r--ruby_2_2/lib/rdoc/normal_class.rb92
-rw-r--r--ruby_2_2/lib/rdoc/normal_module.rb73
-rw-r--r--ruby_2_2/lib/rdoc/options.rb1251
-rw-r--r--ruby_2_2/lib/rdoc/parser.rb310
-rw-r--r--ruby_2_2/lib/rdoc/parser/c.rb1229
-rw-r--r--ruby_2_2/lib/rdoc/parser/changelog.rb198
-rw-r--r--ruby_2_2/lib/rdoc/parser/markdown.rb23
-rw-r--r--ruby_2_2/lib/rdoc/parser/rd.rb22
-rw-r--r--ruby_2_2/lib/rdoc/parser/ruby.rb2160
-rw-r--r--ruby_2_2/lib/rdoc/parser/ruby_tools.rb167
-rw-r--r--ruby_2_2/lib/rdoc/parser/simple.rb61
-rw-r--r--ruby_2_2/lib/rdoc/parser/text.rb11
-rw-r--r--ruby_2_2/lib/rdoc/rd.rb99
-rw-r--r--ruby_2_2/lib/rdoc/rd/block_parser.rb1055
-rw-r--r--ruby_2_2/lib/rdoc/rd/inline.rb71
-rw-r--r--ruby_2_2/lib/rdoc/rd/inline_parser.rb1207
-rw-r--r--ruby_2_2/lib/rdoc/rdoc.rb570
-rw-r--r--ruby_2_2/lib/rdoc/require.rb51
-rw-r--r--ruby_2_2/lib/rdoc/ri.rb20
-rw-r--r--ruby_2_2/lib/rdoc/ri/driver.rb1497
-rw-r--r--ruby_2_2/lib/rdoc/ri/formatter.rb5
-rw-r--r--ruby_2_2/lib/rdoc/ri/paths.rb187
-rw-r--r--ruby_2_2/lib/rdoc/ri/store.rb6
-rw-r--r--ruby_2_2/lib/rdoc/ri/task.rb71
-rw-r--r--ruby_2_2/lib/rdoc/ruby_lex.rb1377
-rw-r--r--ruby_2_2/lib/rdoc/ruby_token.rb460
-rw-r--r--ruby_2_2/lib/rdoc/rubygems_hook.rb253
-rw-r--r--ruby_2_2/lib/rdoc/servlet.rb441
-rw-r--r--ruby_2_2/lib/rdoc/single_class.rb25
-rw-r--r--ruby_2_2/lib/rdoc/stats.rb461
-rw-r--r--ruby_2_2/lib/rdoc/stats/normal.rb59
-rw-r--r--ruby_2_2/lib/rdoc/stats/quiet.rb59
-rw-r--r--ruby_2_2/lib/rdoc/stats/verbose.rb45
-rw-r--r--ruby_2_2/lib/rdoc/store.rb979
-rw-r--r--ruby_2_2/lib/rdoc/task.rb330
-rw-r--r--ruby_2_2/lib/rdoc/test_case.rb217
-rw-r--r--ruby_2_2/lib/rdoc/text.rb324
-rw-r--r--ruby_2_2/lib/rdoc/token_stream.rb95
-rw-r--r--ruby_2_2/lib/rdoc/tom_doc.rb257
-rw-r--r--ruby_2_2/lib/rdoc/top_level.rb282
-rw-r--r--ruby_2_2/lib/resolv-replace.rb74
-rw-r--r--ruby_2_2/lib/resolv.rb2844
-rw-r--r--ruby_2_2/lib/rexml/attlistdecl.rb62
-rw-r--r--ruby_2_2/lib/rexml/attribute.rb191
-rw-r--r--ruby_2_2/lib/rexml/cdata.rb67
-rw-r--r--ruby_2_2/lib/rexml/child.rb96
-rw-r--r--ruby_2_2/lib/rexml/comment.rb79
-rw-r--r--ruby_2_2/lib/rexml/doctype.rb269
-rw-r--r--ruby_2_2/lib/rexml/document.rb290
-rw-r--r--ruby_2_2/lib/rexml/dtd/attlistdecl.rb10
-rw-r--r--ruby_2_2/lib/rexml/dtd/dtd.rb46
-rw-r--r--ruby_2_2/lib/rexml/dtd/elementdecl.rb17
-rw-r--r--ruby_2_2/lib/rexml/dtd/entitydecl.rb56
-rw-r--r--ruby_2_2/lib/rexml/dtd/notationdecl.rb39
-rw-r--r--ruby_2_2/lib/rexml/element.rb1240
-rw-r--r--ruby_2_2/lib/rexml/encoding.rb50
-rw-r--r--ruby_2_2/lib/rexml/entity.rb173
-rw-r--r--ruby_2_2/lib/rexml/formatters/default.rb111
-rw-r--r--ruby_2_2/lib/rexml/formatters/pretty.rb141
-rw-r--r--ruby_2_2/lib/rexml/formatters/transitive.rb57
-rw-r--r--ruby_2_2/lib/rexml/functions.rb394
-rw-r--r--ruby_2_2/lib/rexml/instruction.rb70
-rw-r--r--ruby_2_2/lib/rexml/light/node.rb195
-rw-r--r--ruby_2_2/lib/rexml/namespace.rb47
-rw-r--r--ruby_2_2/lib/rexml/node.rb75
-rw-r--r--ruby_2_2/lib/rexml/output.rb29
-rw-r--r--ruby_2_2/lib/rexml/parent.rb165
-rw-r--r--ruby_2_2/lib/rexml/parseexception.rb51
-rw-r--r--ruby_2_2/lib/rexml/parsers/baseparser.rb532
-rw-r--r--ruby_2_2/lib/rexml/parsers/lightparser.rb58
-rw-r--r--ruby_2_2/lib/rexml/parsers/pullparser.rb196
-rw-r--r--ruby_2_2/lib/rexml/parsers/sax2parser.rb272
-rw-r--r--ruby_2_2/lib/rexml/parsers/streamparser.rb52
-rw-r--r--ruby_2_2/lib/rexml/parsers/treeparser.rb100
-rw-r--r--ruby_2_2/lib/rexml/parsers/ultralightparser.rb56
-rw-r--r--ruby_2_2/lib/rexml/parsers/xpathparser.rb656
-rw-r--r--ruby_2_2/lib/rexml/quickpath.rb265
-rw-r--r--ruby_2_2/lib/rexml/rexml.rb31
-rw-r--r--ruby_2_2/lib/rexml/sax2listener.rb97
-rw-r--r--ruby_2_2/lib/rexml/security.rb27
-rw-r--r--ruby_2_2/lib/rexml/source.rb296
-rw-r--r--ruby_2_2/lib/rexml/streamlistener.rb92
-rw-r--r--ruby_2_2/lib/rexml/syncenumerator.rb32
-rw-r--r--ruby_2_2/lib/rexml/text.rb425
-rw-r--r--ruby_2_2/lib/rexml/undefinednamespaceexception.rb8
-rw-r--r--ruby_2_2/lib/rexml/validation/relaxng.rb538
-rw-r--r--ruby_2_2/lib/rexml/validation/validation.rb143
-rw-r--r--ruby_2_2/lib/rexml/validation/validationexception.rb9
-rw-r--r--ruby_2_2/lib/rexml/xmldecl.rb115
-rw-r--r--ruby_2_2/lib/rexml/xmltokens.rb84
-rw-r--r--ruby_2_2/lib/rexml/xpath.rb80
-rw-r--r--ruby_2_2/lib/rexml/xpath_parser.rb703
-rw-r--r--ruby_2_2/lib/rinda/rinda.rb327
-rw-r--r--ruby_2_2/lib/rinda/ring.rb480
-rw-r--r--ruby_2_2/lib/rinda/tuplespace.rb642
-rw-r--r--ruby_2_2/lib/rss.rb91
-rw-r--r--ruby_2_2/lib/rss/0.9.rb461
-rw-r--r--ruby_2_2/lib/rss/1.0.rb484
-rw-r--r--ruby_2_2/lib/rss/2.0.rb142
-rw-r--r--ruby_2_2/lib/rss/atom.rb839
-rw-r--r--ruby_2_2/lib/rss/content.rb33
-rw-r--r--ruby_2_2/lib/rss/content/1.0.rb9
-rw-r--r--ruby_2_2/lib/rss/content/2.0.rb11
-rw-r--r--ruby_2_2/lib/rss/converter.rb170
-rw-r--r--ruby_2_2/lib/rss/dublincore.rb163
-rw-r--r--ruby_2_2/lib/rss/dublincore/1.0.rb12
-rw-r--r--ruby_2_2/lib/rss/dublincore/2.0.rb12
-rw-r--r--ruby_2_2/lib/rss/dublincore/atom.rb16
-rw-r--r--ruby_2_2/lib/rss/image.rb197
-rw-r--r--ruby_2_2/lib/rss/itunes.rb412
-rw-r--r--ruby_2_2/lib/rss/maker.rb78
-rw-r--r--ruby_2_2/lib/rss/maker/0.9.rb508
-rw-r--r--ruby_2_2/lib/rss/maker/1.0.rb435
-rw-r--r--ruby_2_2/lib/rss/maker/2.0.rb223
-rw-r--r--ruby_2_2/lib/rss/maker/atom.rb172
-rw-r--r--ruby_2_2/lib/rss/maker/base.rb944
-rw-r--r--ruby_2_2/lib/rss/maker/content.rb21
-rw-r--r--ruby_2_2/lib/rss/maker/dublincore.rb121
-rw-r--r--ruby_2_2/lib/rss/maker/entry.rb163
-rw-r--r--ruby_2_2/lib/rss/maker/feed.rb426
-rw-r--r--ruby_2_2/lib/rss/maker/image.rb111
-rw-r--r--ruby_2_2/lib/rss/maker/itunes.rb242
-rw-r--r--ruby_2_2/lib/rss/maker/slash.rb33
-rw-r--r--ruby_2_2/lib/rss/maker/syndication.rb18
-rw-r--r--ruby_2_2/lib/rss/maker/taxonomy.rb118
-rw-r--r--ruby_2_2/lib/rss/maker/trackback.rb61
-rw-r--r--ruby_2_2/lib/rss/parser.rb570
-rw-r--r--ruby_2_2/lib/rss/rexmlparser.rb49
-rw-r--r--ruby_2_2/lib/rss/rss.rb1352
-rw-r--r--ruby_2_2/lib/rss/slash.rb51
-rw-r--r--ruby_2_2/lib/rss/syndication.rb68
-rw-r--r--ruby_2_2/lib/rss/taxonomy.rb147
-rw-r--r--ruby_2_2/lib/rss/trackback.rb290
-rw-r--r--ruby_2_2/lib/rss/utils.rb199
-rw-r--r--ruby_2_2/lib/rss/xml-stylesheet.rb105
-rw-r--r--ruby_2_2/lib/rss/xml.rb71
-rw-r--r--ruby_2_2/lib/rss/xmlparser.rb94
-rw-r--r--ruby_2_2/lib/rss/xmlscanner.rb121
-rw-r--r--ruby_2_2/lib/rubygems.rb1246
-rw-r--r--ruby_2_2/lib/rubygems/LICENSE.txt54
-rw-r--r--ruby_2_2/lib/rubygems/available_set.rb164
-rw-r--r--ruby_2_2/lib/rubygems/basic_specification.rb290
-rw-r--r--ruby_2_2/lib/rubygems/command.rb582
-rw-r--r--ruby_2_2/lib/rubygems/command_manager.rb218
-rw-r--r--ruby_2_2/lib/rubygems/commands/build_command.rb60
-rw-r--r--ruby_2_2/lib/rubygems/commands/cert_command.rb276
-rw-r--r--ruby_2_2/lib/rubygems/commands/check_command.rb93
-rw-r--r--ruby_2_2/lib/rubygems/commands/cleanup_command.rb165
-rw-r--r--ruby_2_2/lib/rubygems/commands/contents_command.rb190
-rw-r--r--ruby_2_2/lib/rubygems/commands/dependency_command.rb207
-rw-r--r--ruby_2_2/lib/rubygems/commands/environment_command.rb158
-rw-r--r--ruby_2_2/lib/rubygems/commands/fetch_command.rb77
-rw-r--r--ruby_2_2/lib/rubygems/commands/generate_index_command.rb84
-rw-r--r--ruby_2_2/lib/rubygems/commands/help_command.rb384
-rw-r--r--ruby_2_2/lib/rubygems/commands/install_command.rb347
-rw-r--r--ruby_2_2/lib/rubygems/commands/list_command.rb40
-rw-r--r--ruby_2_2/lib/rubygems/commands/lock_command.rb110
-rw-r--r--ruby_2_2/lib/rubygems/commands/mirror_command.rb25
-rw-r--r--ruby_2_2/lib/rubygems/commands/open_command.rb74
-rw-r--r--ruby_2_2/lib/rubygems/commands/outdated_command.rb32
-rw-r--r--ruby_2_2/lib/rubygems/commands/owner_command.rb99
-rw-r--r--ruby_2_2/lib/rubygems/commands/pristine_command.rb165
-rw-r--r--ruby_2_2/lib/rubygems/commands/push_command.rb98
-rw-r--r--ruby_2_2/lib/rubygems/commands/query_command.rb344
-rw-r--r--ruby_2_2/lib/rubygems/commands/rdoc_command.rb96
-rw-r--r--ruby_2_2/lib/rubygems/commands/search_command.rb40
-rw-r--r--ruby_2_2/lib/rubygems/commands/server_command.rb86
-rw-r--r--ruby_2_2/lib/rubygems/commands/setup_command.rb483
-rw-r--r--ruby_2_2/lib/rubygems/commands/sources_command.rb210
-rw-r--r--ruby_2_2/lib/rubygems/commands/specification_command.rb145
-rw-r--r--ruby_2_2/lib/rubygems/commands/stale_command.rb38
-rw-r--r--ruby_2_2/lib/rubygems/commands/uninstall_command.rb164
-rw-r--r--ruby_2_2/lib/rubygems/commands/unpack_command.rb182
-rw-r--r--ruby_2_2/lib/rubygems/commands/update_command.rb277
-rw-r--r--ruby_2_2/lib/rubygems/commands/which_command.rb90
-rw-r--r--ruby_2_2/lib/rubygems/commands/yank_command.rb107
-rw-r--r--ruby_2_2/lib/rubygems/compatibility.rb59
-rw-r--r--ruby_2_2/lib/rubygems/config_file.rb483
-rw-r--r--ruby_2_2/lib/rubygems/core_ext/kernel_gem.rb73
-rwxr-xr-xruby_2_2/lib/rubygems/core_ext/kernel_require.rb139
-rw-r--r--ruby_2_2/lib/rubygems/defaults.rb177
-rw-r--r--ruby_2_2/lib/rubygems/dependency.rb334
-rw-r--r--ruby_2_2/lib/rubygems/dependency_installer.rb480
-rw-r--r--ruby_2_2/lib/rubygems/dependency_list.rb240
-rw-r--r--ruby_2_2/lib/rubygems/deprecate.rb70
-rw-r--r--ruby_2_2/lib/rubygems/doctor.rb131
-rw-r--r--ruby_2_2/lib/rubygems/errors.rb137
-rw-r--r--ruby_2_2/lib/rubygems/exceptions.rb270
-rw-r--r--ruby_2_2/lib/rubygems/ext.rb18
-rw-r--r--ruby_2_2/lib/rubygems/ext/build_error.rb6
-rw-r--r--ruby_2_2/lib/rubygems/ext/builder.rb218
-rw-r--r--ruby_2_2/lib/rubygems/ext/cmake_builder.rb16
-rw-r--r--ruby_2_2/lib/rubygems/ext/configure_builder.rb23
-rw-r--r--ruby_2_2/lib/rubygems/ext/ext_conf_builder.rb78
-rw-r--r--ruby_2_2/lib/rubygems/ext/rake_builder.rb36
-rw-r--r--ruby_2_2/lib/rubygems/gem_runner.rb81
-rw-r--r--ruby_2_2/lib/rubygems/gemcutter_utilities.rb154
-rw-r--r--ruby_2_2/lib/rubygems/indexer.rb498
-rw-r--r--ruby_2_2/lib/rubygems/install_default_message.rb12
-rw-r--r--ruby_2_2/lib/rubygems/install_message.rb12
-rw-r--r--ruby_2_2/lib/rubygems/install_update_options.rb186
-rw-r--r--ruby_2_2/lib/rubygems/installer.rb826
-rw-r--r--ruby_2_2/lib/rubygems/installer_test_case.rb193
-rw-r--r--ruby_2_2/lib/rubygems/local_remote_options.rb148
-rw-r--r--ruby_2_2/lib/rubygems/mock_gem_ui.rb88
-rw-r--r--ruby_2_2/lib/rubygems/name_tuple.rb123
-rw-r--r--ruby_2_2/lib/rubygems/package.rb614
-rw-r--r--ruby_2_2/lib/rubygems/package/digest_io.rb64
-rw-r--r--ruby_2_2/lib/rubygems/package/file_source.rb33
-rw-r--r--ruby_2_2/lib/rubygems/package/io_source.rb45
-rw-r--r--ruby_2_2/lib/rubygems/package/old.rb178
-rw-r--r--ruby_2_2/lib/rubygems/package/source.rb3
-rw-r--r--ruby_2_2/lib/rubygems/package/tar_header.rb229
-rw-r--r--ruby_2_2/lib/rubygems/package/tar_reader.rb123
-rw-r--r--ruby_2_2/lib/rubygems/package/tar_reader/entry.rb147
-rw-r--r--ruby_2_2/lib/rubygems/package/tar_test_case.rb137
-rw-r--r--ruby_2_2/lib/rubygems/package/tar_writer.rb326
-rw-r--r--ruby_2_2/lib/rubygems/package_task.rb128
-rw-r--r--ruby_2_2/lib/rubygems/path_support.rb87
-rw-r--r--ruby_2_2/lib/rubygems/platform.rb204
-rw-r--r--ruby_2_2/lib/rubygems/psych_additions.rb9
-rw-r--r--ruby_2_2/lib/rubygems/psych_tree.rb31
-rw-r--r--ruby_2_2/lib/rubygems/rdoc.rb335
-rw-r--r--ruby_2_2/lib/rubygems/remote_fetcher.rb404
-rw-r--r--ruby_2_2/lib/rubygems/request.rb244
-rw-r--r--ruby_2_2/lib/rubygems/request/connection_pools.rb83
-rw-r--r--ruby_2_2/lib/rubygems/request/http_pool.rb47
-rw-r--r--ruby_2_2/lib/rubygems/request/https_pool.rb10
-rw-r--r--ruby_2_2/lib/rubygems/request_set.rb413
-rw-r--r--ruby_2_2/lib/rubygems/request_set/gem_dependency_api.rb801
-rw-r--r--ruby_2_2/lib/rubygems/request_set/lockfile.rb650
-rw-r--r--ruby_2_2/lib/rubygems/requirement.rb273
-rw-r--r--ruby_2_2/lib/rubygems/resolver.rb485
-rw-r--r--ruby_2_2/lib/rubygems/resolver/activation_request.rb172
-rw-r--r--ruby_2_2/lib/rubygems/resolver/api_set.rb125
-rw-r--r--ruby_2_2/lib/rubygems/resolver/api_specification.rb85
-rw-r--r--ruby_2_2/lib/rubygems/resolver/best_set.rb78
-rw-r--r--ruby_2_2/lib/rubygems/resolver/composed_set.rb66
-rw-r--r--ruby_2_2/lib/rubygems/resolver/conflict.rb160
-rw-r--r--ruby_2_2/lib/rubygems/resolver/current_set.rb13
-rw-r--r--ruby_2_2/lib/rubygems/resolver/dependency_request.rb116
-rw-r--r--ruby_2_2/lib/rubygems/resolver/git_set.rb122
-rw-r--r--ruby_2_2/lib/rubygems/resolver/git_specification.rb59
-rw-r--r--ruby_2_2/lib/rubygems/resolver/index_set.rb80
-rw-r--r--ruby_2_2/lib/rubygems/resolver/index_specification.rb69
-rw-r--r--ruby_2_2/lib/rubygems/resolver/installed_specification.rb58
-rw-r--r--ruby_2_2/lib/rubygems/resolver/installer_set.rb224
-rw-r--r--ruby_2_2/lib/rubygems/resolver/local_specification.rb41
-rw-r--r--ruby_2_2/lib/rubygems/resolver/lock_set.rb84
-rw-r--r--ruby_2_2/lib/rubygems/resolver/lock_specification.rb84
-rw-r--r--ruby_2_2/lib/rubygems/resolver/requirement_list.rb81
-rw-r--r--ruby_2_2/lib/rubygems/resolver/set.rb56
-rw-r--r--ruby_2_2/lib/rubygems/resolver/spec_specification.rb56
-rw-r--r--ruby_2_2/lib/rubygems/resolver/specification.rb110
-rw-r--r--ruby_2_2/lib/rubygems/resolver/stats.rb44
-rw-r--r--ruby_2_2/lib/rubygems/resolver/vendor_set.rb87
-rw-r--r--ruby_2_2/lib/rubygems/resolver/vendor_specification.rb24
-rw-r--r--ruby_2_2/lib/rubygems/safe_yaml.rb48
-rw-r--r--ruby_2_2/lib/rubygems/security.rb595
-rw-r--r--ruby_2_2/lib/rubygems/security/policies.rb115
-rw-r--r--ruby_2_2/lib/rubygems/security/policy.rb295
-rw-r--r--ruby_2_2/lib/rubygems/security/signer.rb154
-rw-r--r--ruby_2_2/lib/rubygems/security/trust_dir.rb118
-rw-r--r--ruby_2_2/lib/rubygems/server.rb868
-rw-r--r--ruby_2_2/lib/rubygems/source.rb234
-rw-r--r--ruby_2_2/lib/rubygems/source/git.rb240
-rw-r--r--ruby_2_2/lib/rubygems/source/installed.rb40
-rw-r--r--ruby_2_2/lib/rubygems/source/local.rb129
-rw-r--r--ruby_2_2/lib/rubygems/source/lock.rb48
-rw-r--r--ruby_2_2/lib/rubygems/source/specific_file.rb72
-rw-r--r--ruby_2_2/lib/rubygems/source/vendor.rb27
-rw-r--r--ruby_2_2/lib/rubygems/source_list.rb149
-rw-r--r--ruby_2_2/lib/rubygems/source_local.rb5
-rw-r--r--ruby_2_2/lib/rubygems/source_specific_file.rb4
-rw-r--r--ruby_2_2/lib/rubygems/spec_fetcher.rb269
-rw-r--r--ruby_2_2/lib/rubygems/specification.rb2808
-rw-r--r--ruby_2_2/lib/rubygems/ssl_certs/.document1
-rw-r--r--ruby_2_2/lib/rubygems/ssl_certs/AddTrustExternalCARoot-2048.pem25
-rw-r--r--ruby_2_2/lib/rubygems/ssl_certs/AddTrustExternalCARoot.pem32
-rw-r--r--ruby_2_2/lib/rubygems/ssl_certs/Class3PublicPrimaryCertificationAuthority.pem14
-rw-r--r--ruby_2_2/lib/rubygems/ssl_certs/DigiCertHighAssuranceEVRootCA.pem23
-rw-r--r--ruby_2_2/lib/rubygems/ssl_certs/EntrustnetSecureServerCertificationAuthority.pem28
-rw-r--r--ruby_2_2/lib/rubygems/ssl_certs/GeoTrustGlobalCA.pem20
-rw-r--r--ruby_2_2/lib/rubygems/ssl_certs/GlobalSignRootCA.pem21
-rw-r--r--ruby_2_2/lib/rubygems/stub_specification.rb196
-rw-r--r--ruby_2_2/lib/rubygems/syck_hack.rb76
-rw-r--r--ruby_2_2/lib/rubygems/test_case.rb1441
-rw-r--r--ruby_2_2/lib/rubygems/test_utilities.rb383
-rw-r--r--ruby_2_2/lib/rubygems/text.rb88
-rw-r--r--ruby_2_2/lib/rubygems/uninstaller.rb345
-rw-r--r--ruby_2_2/lib/rubygems/uri_formatter.rb49
-rw-r--r--ruby_2_2/lib/rubygems/user_interaction.rb711
-rw-r--r--ruby_2_2/lib/rubygems/util.rb134
-rw-r--r--ruby_2_2/lib/rubygems/util/list.rb48
-rw-r--r--ruby_2_2/lib/rubygems/util/stringio.rb34
-rw-r--r--ruby_2_2/lib/rubygems/validator.rb165
-rw-r--r--ruby_2_2/lib/rubygems/version.rb356
-rw-r--r--ruby_2_2/lib/rubygems/version_option.rb71
-rw-r--r--ruby_2_2/lib/scanf.rb776
-rw-r--r--ruby_2_2/lib/securerandom.rb293
-rw-r--r--ruby_2_2/lib/set.rb787
-rw-r--r--ruby_2_2/lib/shell.rb458
-rw-r--r--ruby_2_2/lib/shell/builtin-command.rb146
-rw-r--r--ruby_2_2/lib/shell/command-processor.rb667
-rw-r--r--ruby_2_2/lib/shell/error.rb25
-rw-r--r--ruby_2_2/lib/shell/filter.rb137
-rw-r--r--ruby_2_2/lib/shell/process-controller.rb310
-rw-r--r--ruby_2_2/lib/shell/system-command.rb158
-rw-r--r--ruby_2_2/lib/shell/version.rb15
-rw-r--r--ruby_2_2/lib/shellwords.rb215
-rw-r--r--ruby_2_2/lib/singleton.rb172
-rw-r--r--ruby_2_2/lib/sync.rb328
-rw-r--r--ruby_2_2/lib/tempfile.rb367
-rw-r--r--ruby_2_2/lib/thwait.rb140
-rw-r--r--ruby_2_2/lib/time.rb682
-rw-r--r--ruby_2_2/lib/timeout.rb129
-rw-r--r--ruby_2_2/lib/tmpdir.rb139
-rw-r--r--ruby_2_2/lib/tracer.rb286
-rw-r--r--ruby_2_2/lib/tsort.rb450
-rw-r--r--ruby_2_2/lib/ubygems.rb10
-rw-r--r--ruby_2_2/lib/un.rb375
-rw-r--r--ruby_2_2/lib/unicode_normalize.rb78
-rw-r--r--ruby_2_2/lib/unicode_normalize/normalize.rb168
-rw-r--r--ruby_2_2/lib/unicode_normalize/tables.rb1163
-rw-r--r--ruby_2_2/lib/uri.rb111
-rw-r--r--ruby_2_2/lib/uri/common.rb720
-rw-r--r--ruby_2_2/lib/uri/ftp.rb266
-rw-r--r--ruby_2_2/lib/uri/generic.rb1557
-rw-r--r--ruby_2_2/lib/uri/http.rb108
-rw-r--r--ruby_2_2/lib/uri/https.rb22
-rw-r--r--ruby_2_2/lib/uri/ldap.rb260
-rw-r--r--ruby_2_2/lib/uri/ldaps.rb20
-rw-r--r--ruby_2_2/lib/uri/mailto.rb293
-rw-r--r--ruby_2_2/lib/uri/rfc2396_parser.rb543
-rw-r--r--ruby_2_2/lib/uri/rfc3986_parser.rb124
-rw-r--r--ruby_2_2/lib/weakref.rb106
-rw-r--r--ruby_2_2/lib/webrick.rb226
-rw-r--r--ruby_2_2/lib/webrick/accesslog.rb158
-rw-r--r--ruby_2_2/lib/webrick/cgi.rb308
-rw-r--r--ruby_2_2/lib/webrick/compat.rb35
-rw-r--r--ruby_2_2/lib/webrick/config.rb151
-rw-r--r--ruby_2_2/lib/webrick/cookie.rb171
-rw-r--r--ruby_2_2/lib/webrick/htmlutils.rb29
-rw-r--r--ruby_2_2/lib/webrick/httpauth.rb95
-rw-r--r--ruby_2_2/lib/webrick/httpauth/authenticator.rb116
-rw-r--r--ruby_2_2/lib/webrick/httpauth/basicauth.rb108
-rw-r--r--ruby_2_2/lib/webrick/httpauth/digestauth.rb408
-rw-r--r--ruby_2_2/lib/webrick/httpauth/htdigest.rb131
-rw-r--r--ruby_2_2/lib/webrick/httpauth/htgroup.rb93
-rw-r--r--ruby_2_2/lib/webrick/httpauth/htpasswd.rb124
-rw-r--r--ruby_2_2/lib/webrick/httpauth/userdb.rb52
-rw-r--r--ruby_2_2/lib/webrick/httpproxy.rb337
-rw-r--r--ruby_2_2/lib/webrick/httprequest.rb584
-rw-r--r--ruby_2_2/lib/webrick/httpresponse.rb466
-rw-r--r--ruby_2_2/lib/webrick/https.rb86
-rw-r--r--ruby_2_2/lib/webrick/httpserver.rb278
-rw-r--r--ruby_2_2/lib/webrick/httpservlet.rb22
-rw-r--r--ruby_2_2/lib/webrick/httpservlet/abstract.rb153
-rw-r--r--ruby_2_2/lib/webrick/httpservlet/cgi_runner.rb46
-rw-r--r--ruby_2_2/lib/webrick/httpservlet/cgihandler.rb121
-rw-r--r--ruby_2_2/lib/webrick/httpservlet/erbhandler.rb87
-rw-r--r--ruby_2_2/lib/webrick/httpservlet/filehandler.rb521
-rw-r--r--ruby_2_2/lib/webrick/httpservlet/prochandler.rb46
-rw-r--r--ruby_2_2/lib/webrick/httpstatus.rb192
-rw-r--r--ruby_2_2/lib/webrick/httputils.rb509
-rw-r--r--ruby_2_2/lib/webrick/httpversion.rb75
-rw-r--r--ruby_2_2/lib/webrick/log.rb155
-rw-r--r--ruby_2_2/lib/webrick/server.rb365
-rw-r--r--ruby_2_2/lib/webrick/ssl.rb196
-rw-r--r--ruby_2_2/lib/webrick/utils.rb230
-rw-r--r--ruby_2_2/lib/webrick/version.rb17
-rw-r--r--ruby_2_2/lib/xmlrpc.rb301
-rw-r--r--ruby_2_2/lib/xmlrpc/base64.rb62
-rw-r--r--ruby_2_2/lib/xmlrpc/client.rb628
-rw-r--r--ruby_2_2/lib/xmlrpc/config.rb43
-rw-r--r--ruby_2_2/lib/xmlrpc/create.rb286
-rw-r--r--ruby_2_2/lib/xmlrpc/datetime.rb129
-rw-r--r--ruby_2_2/lib/xmlrpc/marshal.rb66
-rw-r--r--ruby_2_2/lib/xmlrpc/parser.rb870
-rw-r--r--ruby_2_2/lib/xmlrpc/server.rb707
-rw-r--r--ruby_2_2/lib/xmlrpc/utils.rb171
-rw-r--r--ruby_2_2/lib/yaml.rb59
-rw-r--r--ruby_2_2/lib/yaml/dbm.rb279
-rw-r--r--ruby_2_2/lib/yaml/store.rb81
703 files changed, 0 insertions, 180440 deletions
diff --git a/ruby_2_2/lib/English.rb b/ruby_2_2/lib/English.rb
deleted file mode 100644
index 838e5afc74..0000000000
--- a/ruby_2_2/lib/English.rb
+++ /dev/null
@@ -1,185 +0,0 @@
-# Include the English library file in a Ruby script, and you can
-# reference the global variables such as \VAR{\$\_} using less
-# cryptic names, listed in the following table.% \vref{tab:english}.
-#
-# Without 'English':
-#
-# $\ = ' -- '
-# "waterbuffalo" =~ /buff/
-# print $', $$, "\n"
-#
-# With English:
-#
-# require "English"
-#
-# $OUTPUT_FIELD_SEPARATOR = ' -- '
-# "waterbuffalo" =~ /buff/
-# print $POSTMATCH, $PID, "\n"
-#
-# Below is a full list of descriptive aliases and their associated global
-# variable:
-#
-# $ERROR_INFO:: $!
-# $ERROR_POSITION:: $@
-# $FS:: $;
-# $FIELD_SEPARATOR:: $;
-# $OFS:: $,
-# $OUTPUT_FIELD_SEPARATOR:: $,
-# $RS:: $/
-# $INPUT_RECORD_SEPARATOR:: $/
-# $ORS:: $\
-# $OUTPUT_RECORD_SEPARATOR:: $\
-# $INPUT_LINE_NUMBER:: $.
-# $NR:: $.
-# $LAST_READ_LINE:: $_
-# $DEFAULT_OUTPUT:: $>
-# $DEFAULT_INPUT:: $<
-# $PID:: $$
-# $PROCESS_ID:: $$
-# $CHILD_STATUS:: $?
-# $LAST_MATCH_INFO:: $~
-# $IGNORECASE:: $=
-# $ARGV:: $*
-# $MATCH:: $&
-# $PREMATCH:: $`
-# $POSTMATCH:: $'
-# $LAST_PAREN_MATCH:: $+
-#
-module English end if false
-
-# The exception object passed to +raise+.
-alias $ERROR_INFO $!
-
-# The stack backtrace generated by the last
-# exception. <tt>See Kernel.caller</tt> for details. Thread local.
-alias $ERROR_POSITION $@
-
-# The default separator pattern used by <tt>String.split</tt>. May be
-# set from the command line using the <tt>-F</tt> flag.
-alias $FS $;
-
-# The default separator pattern used by <tt>String.split</tt>. May be
-# set from the command line using the <tt>-F</tt> flag.
-alias $FIELD_SEPARATOR $;
-
-# The separator string output between the parameters to methods such
-# as <tt>Kernel.print</tt> and <tt>Array.join</tt>. Defaults to +nil+,
-# which adds no text.
-alias $OFS $,
-
-# The separator string output between the parameters to methods such
-# as <tt>Kernel.print</tt> and <tt>Array.join</tt>. Defaults to +nil+,
-# which adds no text.
-alias $OUTPUT_FIELD_SEPARATOR $,
-
-# The input record separator (newline by default). This is the value
-# that routines such as <tt>Kernel.gets</tt> use to determine record
-# boundaries. If set to +nil+, +gets+ will read the entire file.
-alias $RS $/
-
-# The input record separator (newline by default). This is the value
-# that routines such as <tt>Kernel.gets</tt> use to determine record
-# boundaries. If set to +nil+, +gets+ will read the entire file.
-alias $INPUT_RECORD_SEPARATOR $/
-
-# The string appended to the output of every call to methods such as
-# <tt>Kernel.print</tt> and <tt>IO.write</tt>. The default value is
-# +nil+.
-alias $ORS $\
-
-# The string appended to the output of every call to methods such as
-# <tt>Kernel.print</tt> and <tt>IO.write</tt>. The default value is
-# +nil+.
-alias $OUTPUT_RECORD_SEPARATOR $\
-
-# The number of the last line read from the current input file.
-alias $INPUT_LINE_NUMBER $.
-
-# The number of the last line read from the current input file.
-alias $NR $.
-
-# The last line read by <tt>Kernel.gets</tt> or
-# <tt>Kernel.readline</tt>. Many string-related functions in the
-# +Kernel+ module operate on <tt>$_</tt> by default. The variable is
-# local to the current scope. Thread local.
-alias $LAST_READ_LINE $_
-
-# The destination of output for <tt>Kernel.print</tt>
-# and <tt>Kernel.printf</tt>. The default value is
-# <tt>$stdout</tt>.
-alias $DEFAULT_OUTPUT $>
-
-# An object that provides access to the concatenation
-# of the contents of all the files
-# given as command-line arguments, or <tt>$stdin</tt>
-# (in the case where there are no
-# arguments). <tt>$<</tt> supports methods similar to a
-# +File+ object:
-# +inmode+, +close+,
-# <tt>closed?</tt>, +each+,
-# <tt>each_byte</tt>, <tt>each_line</tt>,
-# +eof+, <tt>eof?</tt>, +file+,
-# +filename+, +fileno+,
-# +getc+, +gets+, +lineno+,
-# <tt>lineno=</tt>, +path+,
-# +pos+, <tt>pos=</tt>,
-# +read+, +readchar+,
-# +readline+, +readlines+,
-# +rewind+, +seek+, +skip+,
-# +tell+, <tt>to_a</tt>, <tt>to_i</tt>,
-# <tt>to_io</tt>, <tt>to_s</tt>, along with the
-# methods in +Enumerable+. The method +file+
-# returns a +File+ object for the file currently
-# being read. This may change as <tt>$<</tt> reads
-# through the files on the command line. Read only.
-alias $DEFAULT_INPUT $<
-
-# The process number of the program being executed. Read only.
-alias $PID $$
-
-# The process number of the program being executed. Read only.
-alias $PROCESS_ID $$
-
-# The exit status of the last child process to terminate. Read
-# only. Thread local.
-alias $CHILD_STATUS $?
-
-# A +MatchData+ object that encapsulates the results of a successful
-# pattern match. The variables <tt>$&</tt>, <tt>$`</tt>, <tt>$'</tt>,
-# and <tt>$1</tt> to <tt>$9</tt> are all derived from
-# <tt>$~</tt>. Assigning to <tt>$~</tt> changes the values of these
-# derived variables. This variable is local to the current
-# scope.
-alias $LAST_MATCH_INFO $~
-
-# If set to any value apart from +nil+ or +false+, all pattern matches
-# will be case insensitive, string comparisons will ignore case, and
-# string hash values will be case insensitive. Deprecated
-alias $IGNORECASE $=
-
-# An array of strings containing the command-line
-# options from the invocation of the program. Options
-# used by the Ruby interpreter will have been
-# removed. Read only. Also known simply as +ARGV+.
-alias $ARGV $*
-
-# The string matched by the last successful pattern
-# match. This variable is local to the current
-# scope. Read only.
-alias $MATCH $&
-
-# The string preceding the match in the last
-# successful pattern match. This variable is local to
-# the current scope. Read only.
-alias $PREMATCH $`
-
-# The string following the match in the last
-# successful pattern match. This variable is local to
-# the current scope. Read only.
-alias $POSTMATCH $'
-
-# The contents of the highest-numbered group matched in the last
-# successful pattern match. Thus, in <tt>"cat" =~ /(c|a)(t|z)/</tt>,
-# <tt>$+</tt> will be set to "t". This variable is local to the
-# current scope. Read only.
-alias $LAST_PAREN_MATCH $+
diff --git a/ruby_2_2/lib/abbrev.rb b/ruby_2_2/lib/abbrev.rb
deleted file mode 100644
index 2c07fb5cf9..0000000000
--- a/ruby_2_2/lib/abbrev.rb
+++ /dev/null
@@ -1,131 +0,0 @@
-#--
-# Copyright (c) 2001,2003 Akinori MUSHA <knu@iDaemons.org>
-#
-# All rights reserved. You can redistribute and/or modify it under
-# the same terms as Ruby.
-#
-# $Idaemons: /home/cvs/rb/abbrev.rb,v 1.2 2001/05/30 09:37:45 knu Exp $
-# $RoughId: abbrev.rb,v 1.4 2003/10/14 19:45:42 knu Exp $
-# $Id$
-#++
-
-##
-# Calculates the set of unambiguous abbreviations for a given set of strings.
-#
-# require 'abbrev'
-# require 'pp'
-#
-# pp Abbrev.abbrev(['ruby'])
-# #=> {"ruby"=>"ruby", "rub"=>"ruby", "ru"=>"ruby", "r"=>"ruby"}
-#
-# pp Abbrev.abbrev(%w{ ruby rules })
-#
-# _Generates:_
-# { "ruby" => "ruby",
-# "rub" => "ruby",
-# "rules" => "rules",
-# "rule" => "rules",
-# "rul" => "rules" }
-#
-# It also provides an array core extension, Array#abbrev.
-#
-# pp %w{ summer winter }.abbrev
-#
-# _Generates:_
-# { "summer" => "summer",
-# "summe" => "summer",
-# "summ" => "summer",
-# "sum" => "summer",
-# "su" => "summer",
-# "s" => "summer",
-# "winter" => "winter",
-# "winte" => "winter",
-# "wint" => "winter",
-# "win" => "winter",
-# "wi" => "winter",
-# "w" => "winter" }
-
-module Abbrev
-
- # Given a set of strings, calculate the set of unambiguous abbreviations for
- # those strings, and return a hash where the keys are all the possible
- # abbreviations and the values are the full strings.
- #
- # Thus, given +words+ is "car" and "cone", the keys pointing to "car" would
- # be "ca" and "car", while those pointing to "cone" would be "co", "con", and
- # "cone".
- #
- # require 'abbrev'
- #
- # Abbrev.abbrev(%w{ car cone })
- # #=> {"ca"=>"car", "con"=>"cone", "co"=>"cone", "car"=>"car", "cone"=>"cone"}
- #
- # The optional +pattern+ parameter is a pattern or a string. Only input
- # strings that match the pattern or start with the string are included in the
- # output hash.
- #
- # Abbrev.abbrev(%w{car box cone crab}, /b/)
- # #=> {"box"=>"box", "bo"=>"box", "b"=>"box", "crab" => "crab"}
- #
- # Abbrev.abbrev(%w{car box cone}, 'ca')
- # #=> {"car"=>"car", "ca"=>"car"}
- def abbrev(words, pattern = nil)
- table = {}
- seen = Hash.new(0)
-
- if pattern.is_a?(String)
- pattern = /\A#{Regexp.quote(pattern)}/ # regard as a prefix
- end
-
- words.each do |word|
- next if word.empty?
- word.size.downto(1) { |len|
- abbrev = word[0...len]
-
- next if pattern && pattern !~ abbrev
-
- case seen[abbrev] += 1
- when 1
- table[abbrev] = word
- when 2
- table.delete(abbrev)
- else
- break
- end
- }
- end
-
- words.each do |word|
- next if pattern && pattern !~ word
-
- table[word] = word
- end
-
- table
- end
-
- module_function :abbrev
-end
-
-class Array
- # Calculates the set of unambiguous abbreviations for the strings in +self+.
- #
- # require 'abbrev'
- # %w{ car cone }.abbrev
- # #=> {"car"=>"car", "ca"=>"car", "cone"=>"cone", "con"=>"cone", "co"=>"cone"}
- #
- # The optional +pattern+ parameter is a pattern or a string. Only input
- # strings that match the pattern or start with the string are included in the
- # output hash.
- #
- # %w{ fast boat day }.abbrev(/^.a/)
- # #=> {"fast"=>"fast", "fas"=>"fast", "fa"=>"fast", "day"=>"day", "da"=>"day"}
- #
- # Abbrev.abbrev(%w{car box cone}, "ca")
- # #=> {"car"=>"car", "ca"=>"car"}
- #
- # See also Abbrev.abbrev
- def abbrev(pattern = nil)
- Abbrev::abbrev(self, pattern)
- end
-end
diff --git a/ruby_2_2/lib/base64.rb b/ruby_2_2/lib/base64.rb
deleted file mode 100644
index 98829f0d96..0000000000
--- a/ruby_2_2/lib/base64.rb
+++ /dev/null
@@ -1,91 +0,0 @@
-#
-# = base64.rb: methods for base64-encoding and -decoding strings
-#
-
-# The Base64 module provides for the encoding (#encode64, #strict_encode64,
-# #urlsafe_encode64) and decoding (#decode64, #strict_decode64,
-# #urlsafe_decode64) of binary data using a Base64 representation.
-#
-# == Example
-#
-# A simple encoding and decoding.
-#
-# require "base64"
-#
-# enc = Base64.encode64('Send reinforcements')
-# # -> "U2VuZCByZWluZm9yY2VtZW50cw==\n"
-# plain = Base64.decode64(enc)
-# # -> "Send reinforcements"
-#
-# The purpose of using base64 to encode data is that it translates any
-# binary data into purely printable characters.
-
-module Base64
- module_function
-
- # Returns the Base64-encoded version of +bin+.
- # This method complies with RFC 2045.
- # Line feeds are added to every 60 encoded characters.
- #
- # require 'base64'
- # Base64.encode64("Now is the time for all good coders\nto learn Ruby")
- #
- # <i>Generates:</i>
- #
- # Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g
- # UnVieQ==
- def encode64(bin)
- [bin].pack("m")
- end
-
- # Returns the Base64-decoded version of +str+.
- # This method complies with RFC 2045.
- # Characters outside the base alphabet are ignored.
- #
- # require 'base64'
- # str = 'VGhpcyBpcyBsaW5lIG9uZQpUaGlzIG' +
- # 'lzIGxpbmUgdHdvClRoaXMgaXMgbGlu' +
- # 'ZSB0aHJlZQpBbmQgc28gb24uLi4K'
- # puts Base64.decode64(str)
- #
- # <i>Generates:</i>
- #
- # This is line one
- # This is line two
- # This is line three
- # And so on...
- def decode64(str)
- str.unpack("m").first
- end
-
- # Returns the Base64-encoded version of +bin+.
- # This method complies with RFC 4648.
- # No line feeds are added.
- def strict_encode64(bin)
- [bin].pack("m0")
- end
-
- # Returns the Base64-decoded version of +str+.
- # This method complies with RFC 4648.
- # ArgumentError is raised if +str+ is incorrectly padded or contains
- # non-alphabet characters. Note that CR or LF are also rejected.
- def strict_decode64(str)
- str.unpack("m0").first
- end
-
- # Returns the Base64-encoded version of +bin+.
- # This method complies with ``Base 64 Encoding with URL and Filename Safe
- # Alphabet'' in RFC 4648.
- # The alphabet uses '-' instead of '+' and '_' instead of '/'.
- def urlsafe_encode64(bin)
- strict_encode64(bin).tr("+/", "-_")
- end
-
- # Returns the Base64-decoded version of +str+.
- # This method complies with ``Base 64 Encoding with URL and Filename Safe
- # Alphabet'' in RFC 4648.
- # The alphabet uses '-' instead of '+' and '_' instead of '/'.
- def urlsafe_decode64(str)
- strict_decode64(str.tr("-_", "+/"))
- end
-end
diff --git a/ruby_2_2/lib/benchmark.rb b/ruby_2_2/lib/benchmark.rb
deleted file mode 100644
index 690dff1c28..0000000000
--- a/ruby_2_2/lib/benchmark.rb
+++ /dev/null
@@ -1,557 +0,0 @@
-#--
-# benchmark.rb - a performance benchmarking library
-#
-# $Id$
-#
-# Created by Gotoken (gotoken@notwork.org).
-#
-# Documentation by Gotoken (original RD), Lyle Johnson (RDoc conversion), and
-# Gavin Sinclair (editing).
-#++
-#
-# == Overview
-#
-# The Benchmark module provides methods for benchmarking Ruby code, giving
-# detailed reports on the time taken for each task.
-#
-
-# The Benchmark module provides methods to measure and report the time
-# used to execute Ruby code.
-#
-# * Measure the time to construct the string given by the expression
-# <code>"a"*1_000_000_000</code>:
-#
-# require 'benchmark'
-#
-# puts Benchmark.measure { "a"*1_000_000_000 }
-#
-# On my machine (OSX 10.8.3 on i5 1.7 Ghz) this generates:
-#
-# 0.350000 0.400000 0.750000 ( 0.835234)
-#
-# This report shows the user CPU time, system CPU time, the sum of
-# the user and system CPU times, and the elapsed real time. The unit
-# of time is seconds.
-#
-# * Do some experiments sequentially using the #bm method:
-#
-# require 'benchmark'
-#
-# n = 5000000
-# Benchmark.bm do |x|
-# x.report { for i in 1..n; a = "1"; end }
-# x.report { n.times do ; a = "1"; end }
-# x.report { 1.upto(n) do ; a = "1"; end }
-# end
-#
-# The result:
-#
-# user system total real
-# 1.010000 0.000000 1.010000 ( 1.014479)
-# 1.000000 0.000000 1.000000 ( 0.998261)
-# 0.980000 0.000000 0.980000 ( 0.981335)
-#
-# * Continuing the previous example, put a label in each report:
-#
-# require 'benchmark'
-#
-# n = 5000000
-# Benchmark.bm(7) do |x|
-# x.report("for:") { for i in 1..n; a = "1"; end }
-# x.report("times:") { n.times do ; a = "1"; end }
-# x.report("upto:") { 1.upto(n) do ; a = "1"; end }
-# end
-#
-# The result:
-#
-# user system total real
-# for: 1.010000 0.000000 1.010000 ( 1.015688)
-# times: 1.000000 0.000000 1.000000 ( 1.003611)
-# upto: 1.030000 0.000000 1.030000 ( 1.028098)
-#
-# * The times for some benchmarks depend on the order in which items
-# are run. These differences are due to the cost of memory
-# allocation and garbage collection. To avoid these discrepancies,
-# the #bmbm method is provided. For example, to compare ways to
-# sort an array of floats:
-#
-# require 'benchmark'
-#
-# array = (1..1000000).map { rand }
-#
-# Benchmark.bmbm do |x|
-# x.report("sort!") { array.dup.sort! }
-# x.report("sort") { array.dup.sort }
-# end
-#
-# The result:
-#
-# Rehearsal -----------------------------------------
-# sort! 1.490000 0.010000 1.500000 ( 1.490520)
-# sort 1.460000 0.000000 1.460000 ( 1.463025)
-# -------------------------------- total: 2.960000sec
-#
-# user system total real
-# sort! 1.460000 0.000000 1.460000 ( 1.460465)
-# sort 1.450000 0.010000 1.460000 ( 1.448327)
-#
-# * Report statistics of sequential experiments with unique labels,
-# using the #benchmark method:
-#
-# require 'benchmark'
-# include Benchmark # we need the CAPTION and FORMAT constants
-#
-# n = 5000000
-# Benchmark.benchmark(CAPTION, 7, FORMAT, ">total:", ">avg:") do |x|
-# tf = x.report("for:") { for i in 1..n; a = "1"; end }
-# tt = x.report("times:") { n.times do ; a = "1"; end }
-# tu = x.report("upto:") { 1.upto(n) do ; a = "1"; end }
-# [tf+tt+tu, (tf+tt+tu)/3]
-# end
-#
-# The result:
-#
-# user system total real
-# for: 0.950000 0.000000 0.950000 ( 0.952039)
-# times: 0.980000 0.000000 0.980000 ( 0.984938)
-# upto: 0.950000 0.000000 0.950000 ( 0.946787)
-# >total: 2.880000 0.000000 2.880000 ( 2.883764)
-# >avg: 0.960000 0.000000 0.960000 ( 0.961255)
-
-module Benchmark
-
- BENCHMARK_VERSION = "2002-04-25" # :nodoc:
-
- # Invokes the block with a Benchmark::Report object, which
- # may be used to collect and report on the results of individual
- # benchmark tests. Reserves +label_width+ leading spaces for
- # labels on each line. Prints +caption+ at the top of the
- # report, and uses +format+ to format each line.
- # Returns an array of Benchmark::Tms objects.
- #
- # If the block returns an array of
- # Benchmark::Tms objects, these will be used to format
- # additional lines of output. If +label+ parameters are
- # given, these are used to label these extra lines.
- #
- # _Note_: Other methods provide a simpler interface to this one, and are
- # suitable for nearly all benchmarking requirements. See the examples in
- # Benchmark, and the #bm and #bmbm methods.
- #
- # Example:
- #
- # require 'benchmark'
- # include Benchmark # we need the CAPTION and FORMAT constants
- #
- # n = 5000000
- # Benchmark.benchmark(CAPTION, 7, FORMAT, ">total:", ">avg:") do |x|
- # tf = x.report("for:") { for i in 1..n; a = "1"; end }
- # tt = x.report("times:") { n.times do ; a = "1"; end }
- # tu = x.report("upto:") { 1.upto(n) do ; a = "1"; end }
- # [tf+tt+tu, (tf+tt+tu)/3]
- # end
- #
- # Generates:
- #
- # user system total real
- # for: 0.970000 0.000000 0.970000 ( 0.970493)
- # times: 0.990000 0.000000 0.990000 ( 0.989542)
- # upto: 0.970000 0.000000 0.970000 ( 0.972854)
- # >total: 2.930000 0.000000 2.930000 ( 2.932889)
- # >avg: 0.976667 0.000000 0.976667 ( 0.977630)
- #
-
- def benchmark(caption = "", label_width = nil, format = nil, *labels) # :yield: report
- sync = STDOUT.sync
- STDOUT.sync = true
- label_width ||= 0
- label_width += 1
- format ||= FORMAT
- print ' '*label_width + caption unless caption.empty?
- report = Report.new(label_width, format)
- results = yield(report)
- Array === results and results.grep(Tms).each {|t|
- print((labels.shift || t.label || "").ljust(label_width), t.format(format))
- }
- report.list
- ensure
- STDOUT.sync = sync unless sync.nil?
- end
-
-
- # A simple interface to the #benchmark method, #bm generates sequential
- # reports with labels. The parameters have the same meaning as for
- # #benchmark.
- #
- # require 'benchmark'
- #
- # n = 5000000
- # Benchmark.bm(7) do |x|
- # x.report("for:") { for i in 1..n; a = "1"; end }
- # x.report("times:") { n.times do ; a = "1"; end }
- # x.report("upto:") { 1.upto(n) do ; a = "1"; end }
- # end
- #
- # Generates:
- #
- # user system total real
- # for: 0.960000 0.000000 0.960000 ( 0.957966)
- # times: 0.960000 0.000000 0.960000 ( 0.960423)
- # upto: 0.950000 0.000000 0.950000 ( 0.954864)
- #
-
- def bm(label_width = 0, *labels, &blk) # :yield: report
- benchmark(CAPTION, label_width, FORMAT, *labels, &blk)
- end
-
-
- # Sometimes benchmark results are skewed because code executed
- # earlier encounters different garbage collection overheads than
- # that run later. #bmbm attempts to minimize this effect by running
- # the tests twice, the first time as a rehearsal in order to get the
- # runtime environment stable, the second time for
- # real. GC.start is executed before the start of each of
- # the real timings; the cost of this is not included in the
- # timings. In reality, though, there's only so much that #bmbm can
- # do, and the results are not guaranteed to be isolated from garbage
- # collection and other effects.
- #
- # Because #bmbm takes two passes through the tests, it can
- # calculate the required label width.
- #
- # require 'benchmark'
- #
- # array = (1..1000000).map { rand }
- #
- # Benchmark.bmbm do |x|
- # x.report("sort!") { array.dup.sort! }
- # x.report("sort") { array.dup.sort }
- # end
- #
- # Generates:
- #
- # Rehearsal -----------------------------------------
- # sort! 1.440000 0.010000 1.450000 ( 1.446833)
- # sort 1.440000 0.000000 1.440000 ( 1.448257)
- # -------------------------------- total: 2.890000sec
- #
- # user system total real
- # sort! 1.460000 0.000000 1.460000 ( 1.458065)
- # sort 1.450000 0.000000 1.450000 ( 1.455963)
- #
- # #bmbm yields a Benchmark::Job object and returns an array of
- # Benchmark::Tms objects.
- #
- def bmbm(width = 0) # :yield: job
- job = Job.new(width)
- yield(job)
- width = job.width + 1
- sync = STDOUT.sync
- STDOUT.sync = true
-
- # rehearsal
- puts 'Rehearsal '.ljust(width+CAPTION.length,'-')
- ets = job.list.inject(Tms.new) { |sum,(label,item)|
- print label.ljust(width)
- res = Benchmark.measure(&item)
- print res.format
- sum + res
- }.format("total: %tsec")
- print " #{ets}\n\n".rjust(width+CAPTION.length+2,'-')
-
- # take
- print ' '*width + CAPTION
- job.list.map { |label,item|
- GC.start
- print label.ljust(width)
- Benchmark.measure(label, &item).tap { |res| print res }
- }
- ensure
- STDOUT.sync = sync unless sync.nil?
- end
-
- # :stopdoc:
- case
- when defined?(Process::CLOCK_MONOTONIC)
- BENCHMARK_CLOCK = Process::CLOCK_MONOTONIC
- else
- BENCHMARK_CLOCK = Process::CLOCK_REALTIME
- end
- # :startdoc:
-
- #
- # Returns the time used to execute the given block as a
- # Benchmark::Tms object.
- #
- def measure(label = "") # :yield:
- t0, r0 = Process.times, Process.clock_gettime(BENCHMARK_CLOCK)
- yield
- t1, r1 = Process.times, Process.clock_gettime(BENCHMARK_CLOCK)
- Benchmark::Tms.new(t1.utime - t0.utime,
- t1.stime - t0.stime,
- t1.cutime - t0.cutime,
- t1.cstime - t0.cstime,
- r1 - r0,
- label)
- end
-
- #
- # Returns the elapsed real time used to execute the given block.
- #
- def realtime # :yield:
- r0 = Process.clock_gettime(BENCHMARK_CLOCK)
- yield
- Process.clock_gettime(BENCHMARK_CLOCK) - r0
- end
-
- module_function :benchmark, :measure, :realtime, :bm, :bmbm
-
- #
- # A Job is a sequence of labelled blocks to be processed by the
- # Benchmark.bmbm method. It is of little direct interest to the user.
- #
- class Job # :nodoc:
- #
- # Returns an initialized Job instance.
- # Usually, one doesn't call this method directly, as new
- # Job objects are created by the #bmbm method.
- # +width+ is a initial value for the label offset used in formatting;
- # the #bmbm method passes its +width+ argument to this constructor.
- #
- def initialize(width)
- @width = width
- @list = []
- end
-
- #
- # Registers the given label and block pair in the job list.
- #
- def item(label = "", &blk) # :yield:
- raise ArgumentError, "no block" unless block_given?
- label = label.to_s
- w = label.length
- @width = w if @width < w
- @list << [label, blk]
- self
- end
-
- alias report item
-
- # An array of 2-element arrays, consisting of label and block pairs.
- attr_reader :list
-
- # Length of the widest label in the #list.
- attr_reader :width
- end
-
- #
- # This class is used by the Benchmark.benchmark and Benchmark.bm methods.
- # It is of little direct interest to the user.
- #
- class Report # :nodoc:
- #
- # Returns an initialized Report instance.
- # Usually, one doesn't call this method directly, as new
- # Report objects are created by the #benchmark and #bm methods.
- # +width+ and +format+ are the label offset and
- # format string used by Tms#format.
- #
- def initialize(width = 0, format = nil)
- @width, @format, @list = width, format, []
- end
-
- #
- # Prints the +label+ and measured time for the block,
- # formatted by +format+. See Tms#format for the
- # formatting rules.
- #
- def item(label = "", *format, &blk) # :yield:
- print label.to_s.ljust(@width)
- @list << res = Benchmark.measure(label, &blk)
- print res.format(@format, *format)
- res
- end
-
- alias report item
-
- # An array of Benchmark::Tms objects representing each item.
- attr_reader :list
- end
-
-
-
- #
- # A data object, representing the times associated with a benchmark
- # measurement.
- #
- class Tms
-
- # Default caption, see also Benchmark::CAPTION
- CAPTION = " user system total real\n"
-
- # Default format string, see also Benchmark::FORMAT
- FORMAT = "%10.6u %10.6y %10.6t %10.6r\n"
-
- # User CPU time
- attr_reader :utime
-
- # System CPU time
- attr_reader :stime
-
- # User CPU time of children
- attr_reader :cutime
-
- # System CPU time of children
- attr_reader :cstime
-
- # Elapsed real time
- attr_reader :real
-
- # Total time, that is +utime+ + +stime+ + +cutime+ + +cstime+
- attr_reader :total
-
- # Label
- attr_reader :label
-
- #
- # Returns an initialized Tms object which has
- # +utime+ as the user CPU time, +stime+ as the system CPU time,
- # +cutime+ as the children's user CPU time, +cstime+ as the children's
- # system CPU time, +real+ as the elapsed real time and +label+ as the label.
- #
- def initialize(utime = 0.0, stime = 0.0, cutime = 0.0, cstime = 0.0, real = 0.0, label = nil)
- @utime, @stime, @cutime, @cstime, @real, @label = utime, stime, cutime, cstime, real, label.to_s
- @total = @utime + @stime + @cutime + @cstime
- end
-
- #
- # Returns a new Tms object whose times are the sum of the times for this
- # Tms object, plus the time required to execute the code block (+blk+).
- #
- def add(&blk) # :yield:
- self + Benchmark.measure(&blk)
- end
-
- #
- # An in-place version of #add.
- #
- def add!(&blk)
- t = Benchmark.measure(&blk)
- @utime = utime + t.utime
- @stime = stime + t.stime
- @cutime = cutime + t.cutime
- @cstime = cstime + t.cstime
- @real = real + t.real
- self
- end
-
- #
- # Returns a new Tms object obtained by memberwise summation
- # of the individual times for this Tms object with those of the other
- # Tms object.
- # This method and #/() are useful for taking statistics.
- #
- def +(other); memberwise(:+, other) end
-
- #
- # Returns a new Tms object obtained by memberwise subtraction
- # of the individual times for the other Tms object from those of this
- # Tms object.
- #
- def -(other); memberwise(:-, other) end
-
- #
- # Returns a new Tms object obtained by memberwise multiplication
- # of the individual times for this Tms object by _x_.
- #
- def *(x); memberwise(:*, x) end
-
- #
- # Returns a new Tms object obtained by memberwise division
- # of the individual times for this Tms object by _x_.
- # This method and #+() are useful for taking statistics.
- #
- def /(x); memberwise(:/, x) end
-
- #
- # Returns the contents of this Tms object as
- # a formatted string, according to a format string
- # like that passed to Kernel.format. In addition, #format
- # accepts the following extensions:
- #
- # <tt>%u</tt>:: Replaced by the user CPU time, as reported by Tms#utime.
- # <tt>%y</tt>:: Replaced by the system CPU time, as reported by #stime (Mnemonic: y of "s*y*stem")
- # <tt>%U</tt>:: Replaced by the children's user CPU time, as reported by Tms#cutime
- # <tt>%Y</tt>:: Replaced by the children's system CPU time, as reported by Tms#cstime
- # <tt>%t</tt>:: Replaced by the total CPU time, as reported by Tms#total
- # <tt>%r</tt>:: Replaced by the elapsed real time, as reported by Tms#real
- # <tt>%n</tt>:: Replaced by the label string, as reported by Tms#label (Mnemonic: n of "*n*ame")
- #
- # If _format_ is not given, FORMAT is used as default value, detailing the
- # user, system and real elapsed time.
- #
- def format(format = nil, *args)
- str = (format || FORMAT).dup
- str.gsub!(/(%[-+.\d]*)n/) { "#{$1}s" % label }
- str.gsub!(/(%[-+.\d]*)u/) { "#{$1}f" % utime }
- str.gsub!(/(%[-+.\d]*)y/) { "#{$1}f" % stime }
- str.gsub!(/(%[-+.\d]*)U/) { "#{$1}f" % cutime }
- str.gsub!(/(%[-+.\d]*)Y/) { "#{$1}f" % cstime }
- str.gsub!(/(%[-+.\d]*)t/) { "#{$1}f" % total }
- str.gsub!(/(%[-+.\d]*)r/) { "(#{$1}f)" % real }
- format ? str % args : str
- end
-
- #
- # Same as #format.
- #
- def to_s
- format
- end
-
- #
- # Returns a new 6-element array, consisting of the
- # label, user CPU time, system CPU time, children's
- # user CPU time, children's system CPU time and elapsed
- # real time.
- #
- def to_a
- [@label, @utime, @stime, @cutime, @cstime, @real]
- end
-
- protected
-
- #
- # Returns a new Tms object obtained by memberwise operation +op+
- # of the individual times for this Tms object with those of the other
- # Tms object.
- #
- # +op+ can be a mathematical operation such as <tt>+</tt>, <tt>-</tt>,
- # <tt>*</tt>, <tt>/</tt>
- #
- def memberwise(op, x)
- case x
- when Benchmark::Tms
- Benchmark::Tms.new(utime.__send__(op, x.utime),
- stime.__send__(op, x.stime),
- cutime.__send__(op, x.cutime),
- cstime.__send__(op, x.cstime),
- real.__send__(op, x.real)
- )
- else
- Benchmark::Tms.new(utime.__send__(op, x),
- stime.__send__(op, x),
- cutime.__send__(op, x),
- cstime.__send__(op, x),
- real.__send__(op, x)
- )
- end
- end
- end
-
- # The default caption string (heading above the output times).
- CAPTION = Benchmark::Tms::CAPTION
-
- # The default format string used to display times. See also Benchmark::Tms#format.
- FORMAT = Benchmark::Tms::FORMAT
-end
diff --git a/ruby_2_2/lib/cgi.rb b/ruby_2_2/lib/cgi.rb
deleted file mode 100644
index ae73fe37f6..0000000000
--- a/ruby_2_2/lib/cgi.rb
+++ /dev/null
@@ -1,295 +0,0 @@
-#
-# cgi.rb - cgi support library
-#
-# Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
-#
-# Copyright (C) 2000 Information-technology Promotion Agency, Japan
-#
-# Author: Wakou Aoyama <wakou@ruby-lang.org>
-#
-# Documentation: Wakou Aoyama (RDoc'd and embellished by William Webber)
-#
-
-# == Overview
-#
-# The Common Gateway Interface (CGI) is a simple protocol for passing an HTTP
-# request from a web server to a standalone program, and returning the output
-# to the web browser. Basically, a CGI program is called with the parameters
-# of the request passed in either in the environment (GET) or via $stdin
-# (POST), and everything it prints to $stdout is returned to the client.
-#
-# This file holds the CGI class. This class provides functionality for
-# retrieving HTTP request parameters, managing cookies, and generating HTML
-# output.
-#
-# The file CGI::Session provides session management functionality; see that
-# class for more details.
-#
-# See http://www.w3.org/CGI/ for more information on the CGI protocol.
-#
-# == Introduction
-#
-# CGI is a large class, providing several categories of methods, many of which
-# are mixed in from other modules. Some of the documentation is in this class,
-# some in the modules CGI::QueryExtension and CGI::HtmlExtension. See
-# CGI::Cookie for specific information on handling cookies, and cgi/session.rb
-# (CGI::Session) for information on sessions.
-#
-# For queries, CGI provides methods to get at environmental variables,
-# parameters, cookies, and multipart request data. For responses, CGI provides
-# methods for writing output and generating HTML.
-#
-# Read on for more details. Examples are provided at the bottom.
-#
-# == Queries
-#
-# The CGI class dynamically mixes in parameter and cookie-parsing
-# functionality, environmental variable access, and support for
-# parsing multipart requests (including uploaded files) from the
-# CGI::QueryExtension module.
-#
-# === Environmental Variables
-#
-# The standard CGI environmental variables are available as read-only
-# attributes of a CGI object. The following is a list of these variables:
-#
-#
-# AUTH_TYPE HTTP_HOST REMOTE_IDENT
-# CONTENT_LENGTH HTTP_NEGOTIATE REMOTE_USER
-# CONTENT_TYPE HTTP_PRAGMA REQUEST_METHOD
-# GATEWAY_INTERFACE HTTP_REFERER SCRIPT_NAME
-# HTTP_ACCEPT HTTP_USER_AGENT SERVER_NAME
-# HTTP_ACCEPT_CHARSET PATH_INFO SERVER_PORT
-# HTTP_ACCEPT_ENCODING PATH_TRANSLATED SERVER_PROTOCOL
-# HTTP_ACCEPT_LANGUAGE QUERY_STRING SERVER_SOFTWARE
-# HTTP_CACHE_CONTROL REMOTE_ADDR
-# HTTP_FROM REMOTE_HOST
-#
-#
-# For each of these variables, there is a corresponding attribute with the
-# same name, except all lower case and without a preceding HTTP_.
-# +content_length+ and +server_port+ are integers; the rest are strings.
-#
-# === Parameters
-#
-# The method #params() returns a hash of all parameters in the request as
-# name/value-list pairs, where the value-list is an Array of one or more
-# values. The CGI object itself also behaves as a hash of parameter names
-# to values, but only returns a single value (as a String) for each
-# parameter name.
-#
-# For instance, suppose the request contains the parameter
-# "favourite_colours" with the multiple values "blue" and "green". The
-# following behaviour would occur:
-#
-# cgi.params["favourite_colours"] # => ["blue", "green"]
-# cgi["favourite_colours"] # => "blue"
-#
-# If a parameter does not exist, the former method will return an empty
-# array, the latter an empty string. The simplest way to test for existence
-# of a parameter is by the #has_key? method.
-#
-# === Cookies
-#
-# HTTP Cookies are automatically parsed from the request. They are available
-# from the #cookies() accessor, which returns a hash from cookie name to
-# CGI::Cookie object.
-#
-# === Multipart requests
-#
-# If a request's method is POST and its content type is multipart/form-data,
-# then it may contain uploaded files. These are stored by the QueryExtension
-# module in the parameters of the request. The parameter name is the name
-# attribute of the file input field, as usual. However, the value is not
-# a string, but an IO object, either an IOString for small files, or a
-# Tempfile for larger ones. This object also has the additional singleton
-# methods:
-#
-# #local_path():: the path of the uploaded file on the local filesystem
-# #original_filename():: the name of the file on the client computer
-# #content_type():: the content type of the file
-#
-# == Responses
-#
-# The CGI class provides methods for sending header and content output to
-# the HTTP client, and mixes in methods for programmatic HTML generation
-# from CGI::HtmlExtension and CGI::TagMaker modules. The precise version of HTML
-# to use for HTML generation is specified at object creation time.
-#
-# === Writing output
-#
-# The simplest way to send output to the HTTP client is using the #out() method.
-# This takes the HTTP headers as a hash parameter, and the body content
-# via a block. The headers can be generated as a string using the #http_header()
-# method. The output stream can be written directly to using the #print()
-# method.
-#
-# === Generating HTML
-#
-# Each HTML element has a corresponding method for generating that
-# element as a String. The name of this method is the same as that
-# of the element, all lowercase. The attributes of the element are
-# passed in as a hash, and the body as a no-argument block that evaluates
-# to a String. The HTML generation module knows which elements are
-# always empty, and silently drops any passed-in body. It also knows
-# which elements require matching closing tags and which don't. However,
-# it does not know what attributes are legal for which elements.
-#
-# There are also some additional HTML generation methods mixed in from
-# the CGI::HtmlExtension module. These include individual methods for the
-# different types of form inputs, and methods for elements that commonly
-# take particular attributes where the attributes can be directly specified
-# as arguments, rather than via a hash.
-#
-# === Utility HTML escape and other methods like a function.
-#
-# There are some utility tool defined in cgi/util.rb .
-# And when include, you can use utility methods like a function.
-#
-# == Examples of use
-#
-# === Get form values
-#
-# require "cgi"
-# cgi = CGI.new
-# value = cgi['field_name'] # <== value string for 'field_name'
-# # if not 'field_name' included, then return "".
-# fields = cgi.keys # <== array of field names
-#
-# # returns true if form has 'field_name'
-# cgi.has_key?('field_name')
-# cgi.has_key?('field_name')
-# cgi.include?('field_name')
-#
-# CAUTION! cgi['field_name'] returned an Array with the old
-# cgi.rb(included in Ruby 1.6)
-#
-# === Get form values as hash
-#
-# require "cgi"
-# cgi = CGI.new
-# params = cgi.params
-#
-# cgi.params is a hash.
-#
-# cgi.params['new_field_name'] = ["value"] # add new param
-# cgi.params['field_name'] = ["new_value"] # change value
-# cgi.params.delete('field_name') # delete param
-# cgi.params.clear # delete all params
-#
-#
-# === Save form values to file
-#
-# require "pstore"
-# db = PStore.new("query.db")
-# db.transaction do
-# db["params"] = cgi.params
-# end
-#
-#
-# === Restore form values from file
-#
-# require "pstore"
-# db = PStore.new("query.db")
-# db.transaction do
-# cgi.params = db["params"]
-# end
-#
-#
-# === Get multipart form values
-#
-# require "cgi"
-# cgi = CGI.new
-# value = cgi['field_name'] # <== value string for 'field_name'
-# value.read # <== body of value
-# value.local_path # <== path to local file of value
-# value.original_filename # <== original filename of value
-# value.content_type # <== content_type of value
-#
-# and value has StringIO or Tempfile class methods.
-#
-# === Get cookie values
-#
-# require "cgi"
-# cgi = CGI.new
-# values = cgi.cookies['name'] # <== array of 'name'
-# # if not 'name' included, then return [].
-# names = cgi.cookies.keys # <== array of cookie names
-#
-# and cgi.cookies is a hash.
-#
-# === Get cookie objects
-#
-# require "cgi"
-# cgi = CGI.new
-# for name, cookie in cgi.cookies
-# cookie.expires = Time.now + 30
-# end
-# cgi.out("cookie" => cgi.cookies) {"string"}
-#
-# cgi.cookies # { "name1" => cookie1, "name2" => cookie2, ... }
-#
-# require "cgi"
-# cgi = CGI.new
-# cgi.cookies['name'].expires = Time.now + 30
-# cgi.out("cookie" => cgi.cookies['name']) {"string"}
-#
-# === Print http header and html string to $DEFAULT_OUTPUT ($>)
-#
-# require "cgi"
-# cgi = CGI.new("html4") # add HTML generation methods
-# cgi.out do
-# cgi.html do
-# cgi.head do
-# cgi.title { "TITLE" }
-# end +
-# cgi.body do
-# cgi.form("ACTION" => "uri") do
-# cgi.p do
-# cgi.textarea("get_text") +
-# cgi.br +
-# cgi.submit
-# end
-# end +
-# cgi.pre do
-# CGI::escapeHTML(
-# "params: #{cgi.params.inspect}\n" +
-# "cookies: #{cgi.cookies.inspect}\n" +
-# ENV.collect do |key, value|
-# "#{key} --> #{value}\n"
-# end.join("")
-# )
-# end
-# end
-# end
-# end
-#
-# # add HTML generation methods
-# CGI.new("html3") # html3.2
-# CGI.new("html4") # html4.01 (Strict)
-# CGI.new("html4Tr") # html4.01 Transitional
-# CGI.new("html4Fr") # html4.01 Frameset
-# CGI.new("html5") # html5
-#
-# === Some utility methods
-#
-# require 'cgi/util'
-# CGI.escapeHTML('Usage: foo "bar" <baz>')
-#
-#
-# === Some utility methods like a function
-#
-# require 'cgi/util'
-# include CGI::Util
-# escapeHTML('Usage: foo "bar" <baz>')
-# h('Usage: foo "bar" <baz>') # alias
-#
-#
-
-class CGI
-end
-
-require 'cgi/core'
-require 'cgi/cookie'
-require 'cgi/util'
-CGI.autoload(:HtmlExtension, 'cgi/html')
diff --git a/ruby_2_2/lib/cgi/cookie.rb b/ruby_2_2/lib/cgi/cookie.rb
deleted file mode 100644
index 3ec884dffb..0000000000
--- a/ruby_2_2/lib/cgi/cookie.rb
+++ /dev/null
@@ -1,170 +0,0 @@
-require 'cgi/util'
-class CGI
- # Class representing an HTTP cookie.
- #
- # In addition to its specific fields and methods, a Cookie instance
- # is a delegator to the array of its values.
- #
- # See RFC 2965.
- #
- # == Examples of use
- # cookie1 = CGI::Cookie.new("name", "value1", "value2", ...)
- # cookie1 = CGI::Cookie.new("name" => "name", "value" => "value")
- # cookie1 = CGI::Cookie.new('name' => 'name',
- # 'value' => ['value1', 'value2', ...],
- # 'path' => 'path', # optional
- # 'domain' => 'domain', # optional
- # 'expires' => Time.now, # optional
- # 'secure' => true # optional
- # )
- #
- # cgi.out("cookie" => [cookie1, cookie2]) { "string" }
- #
- # name = cookie1.name
- # values = cookie1.value
- # path = cookie1.path
- # domain = cookie1.domain
- # expires = cookie1.expires
- # secure = cookie1.secure
- #
- # cookie1.name = 'name'
- # cookie1.value = ['value1', 'value2', ...]
- # cookie1.path = 'path'
- # cookie1.domain = 'domain'
- # cookie1.expires = Time.now + 30
- # cookie1.secure = true
- class Cookie < Array
- @@accept_charset="UTF-8" unless defined?(@@accept_charset)
-
- # Create a new CGI::Cookie object.
- #
- # :call-seq:
- # Cookie.new(name_string,*value)
- # Cookie.new(options_hash)
- #
- # +name_string+::
- # The name of the cookie; in this form, there is no #domain or
- # #expiration. The #path is gleaned from the +SCRIPT_NAME+ environment
- # variable, and #secure is false.
- # <tt>*value</tt>::
- # value or list of values of the cookie
- # +options_hash+::
- # A Hash of options to initialize this Cookie. Possible options are:
- #
- # name:: the name of the cookie. Required.
- # value:: the cookie's value or list of values.
- # path:: the path for which this cookie applies. Defaults to the
- # the value of the +SCRIPT_NAME+ environment variable.
- # domain:: the domain for which this cookie applies.
- # expires:: the time at which this cookie expires, as a +Time+ object.
- # secure:: whether this cookie is a secure cookie or not (default to
- # false). Secure cookies are only transmitted to HTTPS
- # servers.
- #
- # These keywords correspond to attributes of the cookie object.
- def initialize(name = "", *value)
- @domain = nil
- @expires = nil
- if name.kind_of?(String)
- @name = name
- %r|^(.*/)|.match(ENV["SCRIPT_NAME"])
- @path = ($1 or "")
- @secure = false
- return super(value)
- end
-
- options = name
- unless options.has_key?("name")
- raise ArgumentError, "`name' required"
- end
-
- @name = options["name"]
- value = Array(options["value"])
- # simple support for IE
- if options["path"]
- @path = options["path"]
- else
- %r|^(.*/)|.match(ENV["SCRIPT_NAME"])
- @path = ($1 or "")
- end
- @domain = options["domain"]
- @expires = options["expires"]
- @secure = options["secure"] == true ? true : false
-
- super(value)
- end
-
- # Name of this cookie, as a +String+
- attr_accessor :name
- # Path for which this cookie applies, as a +String+
- attr_accessor :path
- # Domain for which this cookie applies, as a +String+
- attr_accessor :domain
- # Time at which this cookie expires, as a +Time+
- attr_accessor :expires
- # True if this cookie is secure; false otherwise
- attr_reader("secure")
-
- # Returns the value or list of values for this cookie.
- def value
- self
- end
-
- # Replaces the value of this cookie with a new value or list of values.
- def value=(val)
- replace(Array(val))
- end
-
- # Set whether the Cookie is a secure cookie or not.
- #
- # +val+ must be a boolean.
- def secure=(val)
- @secure = val if val == true or val == false
- @secure
- end
-
- # Convert the Cookie to its string representation.
- def to_s
- val = collect{|v| CGI.escape(v) }.join("&")
- buf = "#{@name}=#{val}"
- buf << "; domain=#{@domain}" if @domain
- buf << "; path=#{@path}" if @path
- buf << "; expires=#{CGI::rfc1123_date(@expires)}" if @expires
- buf << "; secure" if @secure == true
- buf
- end
-
- # Parse a raw cookie string into a hash of cookie-name=>Cookie
- # pairs.
- #
- # cookies = CGI::Cookie.parse("raw_cookie_string")
- # # { "name1" => cookie1, "name2" => cookie2, ... }
- #
- def self.parse(raw_cookie)
- cookies = Hash.new([])
- return cookies unless raw_cookie
-
- raw_cookie.split(/[;,]\s?/).each do |pairs|
- name, values = pairs.split('=',2)
- next unless name and values
- name = CGI.unescape(name)
- values ||= ""
- values = values.split('&').collect{|v| CGI.unescape(v,@@accept_charset) }
- if cookies.has_key?(name)
- values = cookies[name].value + values
- end
- cookies[name] = Cookie.new(name, *values)
- end
-
- cookies
- end
-
- # A summary of cookie string.
- def inspect
- "#<CGI::Cookie: #{self.to_s.inspect}>"
- end
-
- end # class Cookie
-end
-
-
diff --git a/ruby_2_2/lib/cgi/core.rb b/ruby_2_2/lib/cgi/core.rb
deleted file mode 100644
index b81f915379..0000000000
--- a/ruby_2_2/lib/cgi/core.rb
+++ /dev/null
@@ -1,880 +0,0 @@
-#--
-# Methods for generating HTML, parsing CGI-related parameters, and
-# generating HTTP responses.
-#++
-class CGI
-
- $CGI_ENV = ENV # for FCGI support
-
- # String for carriage return
- CR = "\015"
-
- # String for linefeed
- LF = "\012"
-
- # Standard internet newline sequence
- EOL = CR + LF
-
- REVISION = '$Id$' #:nodoc:
-
- # Whether processing will be required in binary vs text
- NEEDS_BINMODE = File::BINARY != 0
-
- # Path separators in different environments.
- PATH_SEPARATOR = {'UNIX'=>'/', 'WINDOWS'=>'\\', 'MACINTOSH'=>':'}
-
- # HTTP status codes.
- HTTP_STATUS = {
- "OK" => "200 OK",
- "PARTIAL_CONTENT" => "206 Partial Content",
- "MULTIPLE_CHOICES" => "300 Multiple Choices",
- "MOVED" => "301 Moved Permanently",
- "REDIRECT" => "302 Found",
- "NOT_MODIFIED" => "304 Not Modified",
- "BAD_REQUEST" => "400 Bad Request",
- "AUTH_REQUIRED" => "401 Authorization Required",
- "FORBIDDEN" => "403 Forbidden",
- "NOT_FOUND" => "404 Not Found",
- "METHOD_NOT_ALLOWED" => "405 Method Not Allowed",
- "NOT_ACCEPTABLE" => "406 Not Acceptable",
- "LENGTH_REQUIRED" => "411 Length Required",
- "PRECONDITION_FAILED" => "412 Precondition Failed",
- "SERVER_ERROR" => "500 Internal Server Error",
- "NOT_IMPLEMENTED" => "501 Method Not Implemented",
- "BAD_GATEWAY" => "502 Bad Gateway",
- "VARIANT_ALSO_VARIES" => "506 Variant Also Negotiates"
- }
-
- # :startdoc:
-
- # Synonym for ENV.
- def env_table
- ENV
- end
-
- # Synonym for $stdin.
- def stdinput
- $stdin
- end
-
- # Synonym for $stdout.
- def stdoutput
- $stdout
- end
-
- private :env_table, :stdinput, :stdoutput
-
- # Create an HTTP header block as a string.
- #
- # :call-seq:
- # http_header(content_type_string="text/html")
- # http_header(headers_hash)
- #
- # Includes the empty line that ends the header block.
- #
- # +content_type_string+::
- # If this form is used, this string is the <tt>Content-Type</tt>
- # +headers_hash+::
- # A Hash of header values. The following header keys are recognized:
- #
- # type:: The Content-Type header. Defaults to "text/html"
- # charset:: The charset of the body, appended to the Content-Type header.
- # nph:: A boolean value. If true, prepend protocol string and status
- # code, and date; and sets default values for "server" and
- # "connection" if not explicitly set.
- # status::
- # The HTTP status code as a String, returned as the Status header. The
- # values are:
- #
- # OK:: 200 OK
- # PARTIAL_CONTENT:: 206 Partial Content
- # MULTIPLE_CHOICES:: 300 Multiple Choices
- # MOVED:: 301 Moved Permanently
- # REDIRECT:: 302 Found
- # NOT_MODIFIED:: 304 Not Modified
- # BAD_REQUEST:: 400 Bad Request
- # AUTH_REQUIRED:: 401 Authorization Required
- # FORBIDDEN:: 403 Forbidden
- # NOT_FOUND:: 404 Not Found
- # METHOD_NOT_ALLOWED:: 405 Method Not Allowed
- # NOT_ACCEPTABLE:: 406 Not Acceptable
- # LENGTH_REQUIRED:: 411 Length Required
- # PRECONDITION_FAILED:: 412 Precondition Failed
- # SERVER_ERROR:: 500 Internal Server Error
- # NOT_IMPLEMENTED:: 501 Method Not Implemented
- # BAD_GATEWAY:: 502 Bad Gateway
- # VARIANT_ALSO_VARIES:: 506 Variant Also Negotiates
- #
- # server:: The server software, returned as the Server header.
- # connection:: The connection type, returned as the Connection header (for
- # instance, "close".
- # length:: The length of the content that will be sent, returned as the
- # Content-Length header.
- # language:: The language of the content, returned as the Content-Language
- # header.
- # expires:: The time on which the current content expires, as a +Time+
- # object, returned as the Expires header.
- # cookie::
- # A cookie or cookies, returned as one or more Set-Cookie headers. The
- # value can be the literal string of the cookie; a CGI::Cookie object;
- # an Array of literal cookie strings or Cookie objects; or a hash all of
- # whose values are literal cookie strings or Cookie objects.
- #
- # These cookies are in addition to the cookies held in the
- # @output_cookies field.
- #
- # Other headers can also be set; they are appended as key: value.
- #
- # Examples:
- #
- # http_header
- # # Content-Type: text/html
- #
- # http_header("text/plain")
- # # Content-Type: text/plain
- #
- # http_header("nph" => true,
- # "status" => "OK", # == "200 OK"
- # # "status" => "200 GOOD",
- # "server" => ENV['SERVER_SOFTWARE'],
- # "connection" => "close",
- # "type" => "text/html",
- # "charset" => "iso-2022-jp",
- # # Content-Type: text/html; charset=iso-2022-jp
- # "length" => 103,
- # "language" => "ja",
- # "expires" => Time.now + 30,
- # "cookie" => [cookie1, cookie2],
- # "my_header1" => "my_value"
- # "my_header2" => "my_value")
- #
- # This method does not perform charset conversion.
- def http_header(options='text/html')
- if options.is_a?(String)
- content_type = options
- buf = _header_for_string(content_type)
- elsif options.is_a?(Hash)
- if options.size == 1 && options.has_key?('type')
- content_type = options['type']
- buf = _header_for_string(content_type)
- else
- buf = _header_for_hash(options.dup)
- end
- else
- raise ArgumentError.new("expected String or Hash but got #{options.class}")
- end
- if defined?(MOD_RUBY)
- _header_for_modruby(buf)
- return ''
- else
- buf << EOL # empty line of separator
- return buf
- end
- end # http_header()
-
- # This method is an alias for #http_header, when HTML5 tag maker is inactive.
- #
- # NOTE: use #http_header to create HTTP header blocks, this alias is only
- # provided for backwards compatibility.
- #
- # Using #header with the HTML5 tag maker will create a <header> element.
- alias :header :http_header
-
- def _header_for_string(content_type) #:nodoc:
- buf = ''
- if nph?()
- buf << "#{$CGI_ENV['SERVER_PROTOCOL'] || 'HTTP/1.0'} 200 OK#{EOL}"
- buf << "Date: #{CGI.rfc1123_date(Time.now)}#{EOL}"
- buf << "Server: #{$CGI_ENV['SERVER_SOFTWARE']}#{EOL}"
- buf << "Connection: close#{EOL}"
- end
- buf << "Content-Type: #{content_type}#{EOL}"
- if @output_cookies
- @output_cookies.each {|cookie| buf << "Set-Cookie: #{cookie}#{EOL}" }
- end
- return buf
- end # _header_for_string
- private :_header_for_string
-
- def _header_for_hash(options) #:nodoc:
- buf = ''
- ## add charset to option['type']
- options['type'] ||= 'text/html'
- charset = options.delete('charset')
- options['type'] += "; charset=#{charset}" if charset
- ## NPH
- options.delete('nph') if defined?(MOD_RUBY)
- if options.delete('nph') || nph?()
- protocol = $CGI_ENV['SERVER_PROTOCOL'] || 'HTTP/1.0'
- status = options.delete('status')
- status = HTTP_STATUS[status] || status || '200 OK'
- buf << "#{protocol} #{status}#{EOL}"
- buf << "Date: #{CGI.rfc1123_date(Time.now)}#{EOL}"
- options['server'] ||= $CGI_ENV['SERVER_SOFTWARE'] || ''
- options['connection'] ||= 'close'
- end
- ## common headers
- status = options.delete('status')
- buf << "Status: #{HTTP_STATUS[status] || status}#{EOL}" if status
- server = options.delete('server')
- buf << "Server: #{server}#{EOL}" if server
- connection = options.delete('connection')
- buf << "Connection: #{connection}#{EOL}" if connection
- type = options.delete('type')
- buf << "Content-Type: #{type}#{EOL}" #if type
- length = options.delete('length')
- buf << "Content-Length: #{length}#{EOL}" if length
- language = options.delete('language')
- buf << "Content-Language: #{language}#{EOL}" if language
- expires = options.delete('expires')
- buf << "Expires: #{CGI.rfc1123_date(expires)}#{EOL}" if expires
- ## cookie
- if cookie = options.delete('cookie')
- case cookie
- when String, Cookie
- buf << "Set-Cookie: #{cookie}#{EOL}"
- when Array
- arr = cookie
- arr.each {|c| buf << "Set-Cookie: #{c}#{EOL}" }
- when Hash
- hash = cookie
- hash.each_value {|c| buf << "Set-Cookie: #{c}#{EOL}" }
- end
- end
- if @output_cookies
- @output_cookies.each {|c| buf << "Set-Cookie: #{c}#{EOL}" }
- end
- ## other headers
- options.each do |key, value|
- buf << "#{key}: #{value}#{EOL}"
- end
- return buf
- end # _header_for_hash
- private :_header_for_hash
-
- def nph? #:nodoc:
- return /IIS\/(\d+)/.match($CGI_ENV['SERVER_SOFTWARE']) && $1.to_i < 5
- end
-
- def _header_for_modruby(buf) #:nodoc:
- request = Apache::request
- buf.scan(/([^:]+): (.+)#{EOL}/o) do |name, value|
- warn sprintf("name:%s value:%s\n", name, value) if $DEBUG
- case name
- when 'Set-Cookie'
- request.headers_out.add(name, value)
- when /^status$/i
- request.status_line = value
- request.status = value.to_i
- when /^content-type$/i
- request.content_type = value
- when /^content-encoding$/i
- request.content_encoding = value
- when /^location$/i
- request.status = 302 if request.status == 200
- request.headers_out[name] = value
- else
- request.headers_out[name] = value
- end
- end
- request.send_http_header
- return ''
- end
- private :_header_for_modruby
-
- # Print an HTTP header and body to $DEFAULT_OUTPUT ($>)
- #
- # :call-seq:
- # cgi.out(content_type_string='text/html')
- # cgi.out(headers_hash)
- #
- # +content_type_string+::
- # If a string is passed, it is assumed to be the content type.
- # +headers_hash+::
- # This is a Hash of headers, similar to that used by #http_header.
- # +block+::
- # A block is required and should evaluate to the body of the response.
- #
- # <tt>Content-Length</tt> is automatically calculated from the size of
- # the String returned by the content block.
- #
- # If <tt>ENV['REQUEST_METHOD'] == "HEAD"</tt>, then only the header
- # is output (the content block is still required, but it is ignored).
- #
- # If the charset is "iso-2022-jp" or "euc-jp" or "shift_jis" then the
- # content is converted to this charset, and the language is set to "ja".
- #
- # Example:
- #
- # cgi = CGI.new
- # cgi.out{ "string" }
- # # Content-Type: text/html
- # # Content-Length: 6
- # #
- # # string
- #
- # cgi.out("text/plain") { "string" }
- # # Content-Type: text/plain
- # # Content-Length: 6
- # #
- # # string
- #
- # cgi.out("nph" => true,
- # "status" => "OK", # == "200 OK"
- # "server" => ENV['SERVER_SOFTWARE'],
- # "connection" => "close",
- # "type" => "text/html",
- # "charset" => "iso-2022-jp",
- # # Content-Type: text/html; charset=iso-2022-jp
- # "language" => "ja",
- # "expires" => Time.now + (3600 * 24 * 30),
- # "cookie" => [cookie1, cookie2],
- # "my_header1" => "my_value",
- # "my_header2" => "my_value") { "string" }
- # # HTTP/1.1 200 OK
- # # Date: Sun, 15 May 2011 17:35:54 GMT
- # # Server: Apache 2.2.0
- # # Connection: close
- # # Content-Type: text/html; charset=iso-2022-jp
- # # Content-Length: 6
- # # Content-Language: ja
- # # Expires: Tue, 14 Jun 2011 17:35:54 GMT
- # # Set-Cookie: foo
- # # Set-Cookie: bar
- # # my_header1: my_value
- # # my_header2: my_value
- # #
- # # string
- def out(options = "text/html") # :yield:
-
- options = { "type" => options } if options.kind_of?(String)
- content = yield
- options["length"] = content.bytesize.to_s
- output = stdoutput
- output.binmode if defined? output.binmode
- output.print http_header(options)
- output.print content unless "HEAD" == env_table['REQUEST_METHOD']
- end
-
-
- # Print an argument or list of arguments to the default output stream
- #
- # cgi = CGI.new
- # cgi.print # default: cgi.print == $DEFAULT_OUTPUT.print
- def print(*options)
- stdoutput.print(*options)
- end
-
- # Parse an HTTP query string into a hash of key=>value pairs.
- #
- # params = CGI::parse("query_string")
- # # {"name1" => ["value1", "value2", ...],
- # # "name2" => ["value1", "value2", ...], ... }
- #
- def CGI::parse(query)
- params = {}
- query.split(/[&;]/).each do |pairs|
- key, value = pairs.split('=',2).collect{|v| CGI::unescape(v) }
-
- next unless key
-
- params[key] ||= []
- params[key].push(value) if value
- end
-
- params.default=[].freeze
- params
- end
-
- # Maximum content length of post data
- ##MAX_CONTENT_LENGTH = 2 * 1024 * 1024
-
- # Maximum number of request parameters when multipart
- MAX_MULTIPART_COUNT = 128
-
- # Mixin module that provides the following:
- #
- # 1. Access to the CGI environment variables as methods. See
- # documentation to the CGI class for a list of these variables. The
- # methods are exposed by removing the leading +HTTP_+ (if it exists) and
- # downcasing the name. For example, +auth_type+ will return the
- # environment variable +AUTH_TYPE+, and +accept+ will return the value
- # for +HTTP_ACCEPT+.
- #
- # 2. Access to cookies, including the cookies attribute.
- #
- # 3. Access to parameters, including the params attribute, and overloading
- # #[] to perform parameter value lookup by key.
- #
- # 4. The initialize_query method, for initializing the above
- # mechanisms, handling multipart forms, and allowing the
- # class to be used in "offline" mode.
- #
- module QueryExtension
-
- %w[ CONTENT_LENGTH SERVER_PORT ].each do |env|
- define_method(env.sub(/^HTTP_/, '').downcase) do
- (val = env_table[env]) && Integer(val)
- end
- end
-
- %w[ AUTH_TYPE CONTENT_TYPE GATEWAY_INTERFACE PATH_INFO
- PATH_TRANSLATED QUERY_STRING REMOTE_ADDR REMOTE_HOST
- REMOTE_IDENT REMOTE_USER REQUEST_METHOD SCRIPT_NAME
- SERVER_NAME SERVER_PROTOCOL SERVER_SOFTWARE
-
- HTTP_ACCEPT HTTP_ACCEPT_CHARSET HTTP_ACCEPT_ENCODING
- HTTP_ACCEPT_LANGUAGE HTTP_CACHE_CONTROL HTTP_FROM HTTP_HOST
- HTTP_NEGOTIATE HTTP_PRAGMA HTTP_REFERER HTTP_USER_AGENT ].each do |env|
- define_method(env.sub(/^HTTP_/, '').downcase) do
- env_table[env]
- end
- end
-
- # Get the raw cookies as a string.
- def raw_cookie
- env_table["HTTP_COOKIE"]
- end
-
- # Get the raw RFC2965 cookies as a string.
- def raw_cookie2
- env_table["HTTP_COOKIE2"]
- end
-
- # Get the cookies as a hash of cookie-name=>Cookie pairs.
- attr_accessor :cookies
-
- # Get the parameters as a hash of name=>values pairs, where
- # values is an Array.
- attr_reader :params
-
- # Get the uploaded files as a hash of name=>values pairs
- attr_reader :files
-
- # Set all the parameters.
- def params=(hash)
- @params.clear
- @params.update(hash)
- end
-
- ##
- # Parses multipart form elements according to
- # http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2
- #
- # Returns a hash of multipart form parameters with bodies of type StringIO or
- # Tempfile depending on whether the multipart form element exceeds 10 KB
- #
- # params[name => body]
- #
- def read_multipart(boundary, content_length)
- ## read first boundary
- stdin = stdinput
- first_line = "--#{boundary}#{EOL}"
- content_length -= first_line.bytesize
- status = stdin.read(first_line.bytesize)
- raise EOFError.new("no content body") unless status
- raise EOFError.new("bad content body") unless first_line == status
- ## parse and set params
- params = {}
- @files = {}
- boundary_rexp = /--#{Regexp.quote(boundary)}(#{EOL}|--)/
- boundary_size = "#{EOL}--#{boundary}#{EOL}".bytesize
- buf = ''
- bufsize = 10 * 1024
- max_count = MAX_MULTIPART_COUNT
- n = 0
- tempfiles = []
- while true
- (n += 1) < max_count or raise StandardError.new("too many parameters.")
- ## create body (StringIO or Tempfile)
- body = create_body(bufsize < content_length)
- tempfiles << body if defined?(Tempfile) && body.kind_of?(Tempfile)
- class << body
- if method_defined?(:path)
- alias local_path path
- else
- def local_path
- nil
- end
- end
- attr_reader :original_filename, :content_type
- end
- ## find head and boundary
- head = nil
- separator = EOL * 2
- until head && matched = boundary_rexp.match(buf)
- if !head && pos = buf.index(separator)
- len = pos + EOL.bytesize
- head = buf[0, len]
- buf = buf[(pos+separator.bytesize)..-1]
- else
- if head && buf.size > boundary_size
- len = buf.size - boundary_size
- body.print(buf[0, len])
- buf[0, len] = ''
- end
- c = stdin.read(bufsize < content_length ? bufsize : content_length)
- raise EOFError.new("bad content body") if c.nil? || c.empty?
- buf << c
- content_length -= c.bytesize
- end
- end
- ## read to end of boundary
- m = matched
- len = m.begin(0)
- s = buf[0, len]
- if s =~ /(\r?\n)\z/
- s = buf[0, len - $1.bytesize]
- end
- body.print(s)
- buf = buf[m.end(0)..-1]
- boundary_end = m[1]
- content_length = -1 if boundary_end == '--'
- ## reset file cursor position
- body.rewind
- ## original filename
- /Content-Disposition:.* filename=(?:"(.*?)"|([^;\r\n]*))/i.match(head)
- filename = $1 || $2 || ''
- filename = CGI.unescape(filename) if unescape_filename?()
- body.instance_variable_set(:@original_filename, filename.taint)
- ## content type
- /Content-Type: (.*)/i.match(head)
- (content_type = $1 || '').chomp!
- body.instance_variable_set(:@content_type, content_type.taint)
- ## query parameter name
- /Content-Disposition:.* name=(?:"(.*?)"|([^;\r\n]*))/i.match(head)
- name = $1 || $2 || ''
- if body.original_filename.empty?
- value=body.read.dup.force_encoding(@accept_charset)
- body.close! if defined?(Tempfile) && body.kind_of?(Tempfile)
- (params[name] ||= []) << value
- unless value.valid_encoding?
- if @accept_charset_error_block
- @accept_charset_error_block.call(name,value)
- else
- raise InvalidEncoding,"Accept-Charset encoding error"
- end
- end
- class << params[name].last;self;end.class_eval do
- define_method(:read){self}
- define_method(:original_filename){""}
- define_method(:content_type){""}
- end
- else
- (params[name] ||= []) << body
- @files[name]=body
- end
- ## break loop
- break if content_length == -1
- end
- raise EOFError, "bad boundary end of body part" unless boundary_end =~ /--/
- params.default = []
- params
- rescue Exception
- if tempfiles
- tempfiles.each {|t|
- if t.path
- t.close!
- end
- }
- end
- raise
- end # read_multipart
- private :read_multipart
- def create_body(is_large) #:nodoc:
- if is_large
- require 'tempfile'
- body = Tempfile.new('CGI', encoding: Encoding::ASCII_8BIT)
- else
- begin
- require 'stringio'
- body = StringIO.new("".force_encoding(Encoding::ASCII_8BIT))
- rescue LoadError
- require 'tempfile'
- body = Tempfile.new('CGI', encoding: Encoding::ASCII_8BIT)
- end
- end
- body.binmode if defined? body.binmode
- return body
- end
- def unescape_filename? #:nodoc:
- user_agent = $CGI_ENV['HTTP_USER_AGENT']
- return /Mac/i.match(user_agent) && /Mozilla/i.match(user_agent) && !/MSIE/i.match(user_agent)
- end
-
- # offline mode. read name=value pairs on standard input.
- def read_from_cmdline
- require "shellwords"
-
- string = unless ARGV.empty?
- ARGV.join(' ')
- else
- if STDIN.tty?
- STDERR.print(
- %|(offline mode: enter name=value pairs on standard input)\n|
- )
- end
- array = readlines rescue nil
- if not array.nil?
- array.join(' ').gsub(/\n/n, '')
- else
- ""
- end
- end.gsub(/\\=/n, '%3D').gsub(/\\&/n, '%26')
-
- words = Shellwords.shellwords(string)
-
- if words.find{|x| /=/n.match(x) }
- words.join('&')
- else
- words.join('+')
- end
- end
- private :read_from_cmdline
-
- # A wrapper class to use a StringIO object as the body and switch
- # to a TempFile when the passed threshold is passed.
- # Initialize the data from the query.
- #
- # Handles multipart forms (in particular, forms that involve file uploads).
- # Reads query parameters in the @params field, and cookies into @cookies.
- def initialize_query()
- if ("POST" == env_table['REQUEST_METHOD']) and
- %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|.match(env_table['CONTENT_TYPE'])
- current_max_multipart_length = @max_multipart_length.respond_to?(:call) ? @max_multipart_length.call : @max_multipart_length
- raise StandardError.new("too large multipart data.") if env_table['CONTENT_LENGTH'].to_i > current_max_multipart_length
- boundary = $1.dup
- @multipart = true
- @params = read_multipart(boundary, Integer(env_table['CONTENT_LENGTH']))
- else
- @multipart = false
- @params = CGI::parse(
- case env_table['REQUEST_METHOD']
- when "GET", "HEAD"
- if defined?(MOD_RUBY)
- Apache::request.args or ""
- else
- env_table['QUERY_STRING'] or ""
- end
- when "POST"
- stdinput.binmode if defined? stdinput.binmode
- stdinput.read(Integer(env_table['CONTENT_LENGTH'])) or ''
- else
- read_from_cmdline
- end.dup.force_encoding(@accept_charset)
- )
- unless Encoding.find(@accept_charset) == Encoding::ASCII_8BIT
- @params.each do |key,values|
- values.each do |value|
- unless value.valid_encoding?
- if @accept_charset_error_block
- @accept_charset_error_block.call(key,value)
- else
- raise InvalidEncoding,"Accept-Charset encoding error"
- end
- end
- end
- end
- end
- end
-
- @cookies = CGI::Cookie::parse((env_table['HTTP_COOKIE'] or env_table['COOKIE']))
- end
- private :initialize_query
-
- # Returns whether the form contained multipart/form-data
- def multipart?
- @multipart
- end
-
- # Get the value for the parameter with a given key.
- #
- # If the parameter has multiple values, only the first will be
- # retrieved; use #params to get the array of values.
- def [](key)
- params = @params[key]
- return '' unless params
- value = params[0]
- if @multipart
- if value
- return value
- elsif defined? StringIO
- StringIO.new("".force_encoding(Encoding::ASCII_8BIT))
- else
- Tempfile.new("CGI",encoding: Encoding::ASCII_8BIT)
- end
- else
- str = if value then value.dup else "" end
- str
- end
- end
-
- # Return all query parameter names as an array of String.
- def keys(*args)
- @params.keys(*args)
- end
-
- # Returns true if a given query string parameter exists.
- def has_key?(*args)
- @params.has_key?(*args)
- end
- alias key? has_key?
- alias include? has_key?
-
- end # QueryExtension
-
- # Exception raised when there is an invalid encoding detected
- class InvalidEncoding < Exception; end
-
- # @@accept_charset is default accept character set.
- # This default value default is "UTF-8"
- # If you want to change the default accept character set
- # when create a new CGI instance, set this:
- #
- # CGI.accept_charset = "EUC-JP"
- #
- @@accept_charset="UTF-8"
-
- # Return the accept character set for all new CGI instances.
- def self.accept_charset
- @@accept_charset
- end
-
- # Set the accept character set for all new CGI instances.
- def self.accept_charset=(accept_charset)
- @@accept_charset=accept_charset
- end
-
- # Return the accept character set for this CGI instance.
- attr_reader :accept_charset
-
- # @@max_multipart_length is the maximum length of multipart data.
- # The default value is 128 * 1024 * 1024 bytes
- #
- # The default can be set to something else in the CGI constructor,
- # via the :max_multipart_length key in the option hash.
- #
- # See CGI.new documentation.
- #
- @@max_multipart_length= 128 * 1024 * 1024
-
- # Create a new CGI instance.
- #
- # :call-seq:
- # CGI.new(tag_maker) { block }
- # CGI.new(options_hash = {}) { block }
- #
- #
- # <tt>tag_maker</tt>::
- # This is the same as using the +options_hash+ form with the value <tt>{
- # :tag_maker => tag_maker }</tt> Note that it is recommended to use the
- # +options_hash+ form, since it also allows you specify the charset you
- # will accept.
- # <tt>options_hash</tt>::
- # A Hash that recognizes three options:
- #
- # <tt>:accept_charset</tt>::
- # specifies encoding of received query string. If omitted,
- # <tt>@@accept_charset</tt> is used. If the encoding is not valid, a
- # CGI::InvalidEncoding will be raised.
- #
- # Example. Suppose <tt>@@accept_charset</tt> is "UTF-8"
- #
- # when not specified:
- #
- # cgi=CGI.new # @accept_charset # => "UTF-8"
- #
- # when specified as "EUC-JP":
- #
- # cgi=CGI.new(:accept_charset => "EUC-JP") # => "EUC-JP"
- #
- # <tt>:tag_maker</tt>::
- # String that specifies which version of the HTML generation methods to
- # use. If not specified, no HTML generation methods will be loaded.
- #
- # The following values are supported:
- #
- # "html3":: HTML 3.x
- # "html4":: HTML 4.0
- # "html4Tr":: HTML 4.0 Transitional
- # "html4Fr":: HTML 4.0 with Framesets
- # "html5":: HTML 5
- #
- # <tt>:max_multipart_length</tt>::
- # Specifies maximum length of multipart data. Can be an Integer scalar or
- # a lambda, that will be evaluated when the request is parsed. This
- # allows more complex logic to be set when determining whether to accept
- # multipart data (e.g. consult a registered users upload allowance)
- #
- # Default is 128 * 1024 * 1024 bytes
- #
- # cgi=CGI.new(:max_multipart_length => 268435456) # simple scalar
- #
- # cgi=CGI.new(:max_multipart_length => -> {check_filesystem}) # lambda
- #
- # <tt>block</tt>::
- # If provided, the block is called when an invalid encoding is
- # encountered. For example:
- #
- # encoding_errors={}
- # cgi=CGI.new(:accept_charset=>"EUC-JP") do |name,value|
- # encoding_errors[name] = value
- # end
- #
- # Finally, if the CGI object is not created in a standard CGI call
- # environment (that is, it can't locate REQUEST_METHOD in its environment),
- # then it will run in "offline" mode. In this mode, it reads its parameters
- # from the command line or (failing that) from standard input. Otherwise,
- # cookies and other parameters are parsed automatically from the standard
- # CGI locations, which varies according to the REQUEST_METHOD.
- def initialize(options = {}, &block) # :yields: name, value
- @accept_charset_error_block = block_given? ? block : nil
- @options={
- :accept_charset=>@@accept_charset,
- :max_multipart_length=>@@max_multipart_length
- }
- case options
- when Hash
- @options.merge!(options)
- when String
- @options[:tag_maker]=options
- end
- @accept_charset=@options[:accept_charset]
- @max_multipart_length=@options[:max_multipart_length]
- if defined?(MOD_RUBY) && !ENV.key?("GATEWAY_INTERFACE")
- Apache.request.setup_cgi_env
- end
-
- extend QueryExtension
- @multipart = false
-
- initialize_query() # set @params, @cookies
- @output_cookies = nil
- @output_hidden = nil
-
- case @options[:tag_maker]
- when "html3"
- require 'cgi/html'
- extend Html3
- extend HtmlExtension
- when "html4"
- require 'cgi/html'
- extend Html4
- extend HtmlExtension
- when "html4Tr"
- require 'cgi/html'
- extend Html4Tr
- extend HtmlExtension
- when "html4Fr"
- require 'cgi/html'
- extend Html4Tr
- extend Html4Fr
- extend HtmlExtension
- when "html5"
- require 'cgi/html'
- extend Html5
- extend HtmlExtension
- end
- end
-
-end # class CGI
diff --git a/ruby_2_2/lib/cgi/html.rb b/ruby_2_2/lib/cgi/html.rb
deleted file mode 100644
index db47bb8266..0000000000
--- a/ruby_2_2/lib/cgi/html.rb
+++ /dev/null
@@ -1,1034 +0,0 @@
-class CGI
- # Base module for HTML-generation mixins.
- #
- # Provides methods for code generation for tags following
- # the various DTD element types.
- module TagMaker # :nodoc:
-
- # Generate code for an element with required start and end tags.
- #
- # - -
- def nn_element(element, attributes = {})
- s = nOE_element(element, attributes)
- if block_given?
- s << yield.to_s
- end
- s << "</#{element.upcase}>"
- end
-
- def nn_element_def(attributes = {}, &block)
- nn_element(__callee__, attributes, &block)
- end
-
- # Generate code for an empty element.
- #
- # - O EMPTY
- def nOE_element(element, attributes = {})
- attributes={attributes=>nil} if attributes.kind_of?(String)
- s = "<#{element.upcase}"
- attributes.each do|name, value|
- next unless value
- s << " "
- s << CGI::escapeHTML(name.to_s)
- if value != true
- s << '="'
- s << CGI::escapeHTML(value.to_s)
- s << '"'
- end
- end
- s << ">"
- end
-
- def nOE_element_def(attributes = {}, &block)
- nOE_element(__callee__, attributes, &block)
- end
-
-
- # Generate code for an element for which the end (and possibly the
- # start) tag is optional.
- #
- # O O or - O
- def nO_element(element, attributes = {})
- s = nOE_element(element, attributes)
- if block_given?
- s << yield.to_s
- s << "</#{element.upcase}>"
- end
- s
- end
-
- def nO_element_def(attributes = {}, &block)
- nO_element(__callee__, attributes, &block)
- end
-
- end # TagMaker
-
-
- # Mixin module providing HTML generation methods.
- #
- # For example,
- # cgi.a("http://www.example.com") { "Example" }
- # # => "<A HREF=\"http://www.example.com\">Example</A>"
- #
- # Modules Html3, Html4, etc., contain more basic HTML-generation methods
- # (+#title+, +#h1+, etc.).
- #
- # See class CGI for a detailed example.
- #
- module HtmlExtension
-
-
- # Generate an Anchor element as a string.
- #
- # +href+ can either be a string, giving the URL
- # for the HREF attribute, or it can be a hash of
- # the element's attributes.
- #
- # The body of the element is the string returned by the no-argument
- # block passed in.
- #
- # a("http://www.example.com") { "Example" }
- # # => "<A HREF=\"http://www.example.com\">Example</A>"
- #
- # a("HREF" => "http://www.example.com", "TARGET" => "_top") { "Example" }
- # # => "<A HREF=\"http://www.example.com\" TARGET=\"_top\">Example</A>"
- #
- def a(href = "") # :yield:
- attributes = if href.kind_of?(String)
- { "HREF" => href }
- else
- href
- end
- super(attributes)
- end
-
- # Generate a Document Base URI element as a String.
- #
- # +href+ can either by a string, giving the base URL for the HREF
- # attribute, or it can be a has of the element's attributes.
- #
- # The passed-in no-argument block is ignored.
- #
- # base("http://www.example.com/cgi")
- # # => "<BASE HREF=\"http://www.example.com/cgi\">"
- def base(href = "") # :yield:
- attributes = if href.kind_of?(String)
- { "HREF" => href }
- else
- href
- end
- super(attributes)
- end
-
- # Generate a BlockQuote element as a string.
- #
- # +cite+ can either be a string, give the URI for the source of
- # the quoted text, or a hash, giving all attributes of the element,
- # or it can be omitted, in which case the element has no attributes.
- #
- # The body is provided by the passed-in no-argument block
- #
- # blockquote("http://www.example.com/quotes/foo.html") { "Foo!" }
- # #=> "<BLOCKQUOTE CITE=\"http://www.example.com/quotes/foo.html\">Foo!</BLOCKQUOTE>
- def blockquote(cite = {}) # :yield:
- attributes = if cite.kind_of?(String)
- { "CITE" => cite }
- else
- cite
- end
- super(attributes)
- end
-
-
- # Generate a Table Caption element as a string.
- #
- # +align+ can be a string, giving the alignment of the caption
- # (one of top, bottom, left, or right). It can be a hash of
- # all the attributes of the element. Or it can be omitted.
- #
- # The body of the element is provided by the passed-in no-argument block.
- #
- # caption("left") { "Capital Cities" }
- # # => <CAPTION ALIGN=\"left\">Capital Cities</CAPTION>
- def caption(align = {}) # :yield:
- attributes = if align.kind_of?(String)
- { "ALIGN" => align }
- else
- align
- end
- super(attributes)
- end
-
-
- # Generate a Checkbox Input element as a string.
- #
- # The attributes of the element can be specified as three arguments,
- # +name+, +value+, and +checked+. +checked+ is a boolean value;
- # if true, the CHECKED attribute will be included in the element.
- #
- # Alternatively, the attributes can be specified as a hash.
- #
- # checkbox("name")
- # # = checkbox("NAME" => "name")
- #
- # checkbox("name", "value")
- # # = checkbox("NAME" => "name", "VALUE" => "value")
- #
- # checkbox("name", "value", true)
- # # = checkbox("NAME" => "name", "VALUE" => "value", "CHECKED" => true)
- def checkbox(name = "", value = nil, checked = nil)
- attributes = if name.kind_of?(String)
- { "TYPE" => "checkbox", "NAME" => name,
- "VALUE" => value, "CHECKED" => checked }
- else
- name["TYPE"] = "checkbox"
- name
- end
- input(attributes)
- end
-
- # Generate a sequence of checkbox elements, as a String.
- #
- # The checkboxes will all have the same +name+ attribute.
- # Each checkbox is followed by a label.
- # There will be one checkbox for each value. Each value
- # can be specified as a String, which will be used both
- # as the value of the VALUE attribute and as the label
- # for that checkbox. A single-element array has the
- # same effect.
- #
- # Each value can also be specified as a three-element array.
- # The first element is the VALUE attribute; the second is the
- # label; and the third is a boolean specifying whether this
- # checkbox is CHECKED.
- #
- # Each value can also be specified as a two-element
- # array, by omitting either the value element (defaults
- # to the same as the label), or the boolean checked element
- # (defaults to false).
- #
- # checkbox_group("name", "foo", "bar", "baz")
- # # <INPUT TYPE="checkbox" NAME="name" VALUE="foo">foo
- # # <INPUT TYPE="checkbox" NAME="name" VALUE="bar">bar
- # # <INPUT TYPE="checkbox" NAME="name" VALUE="baz">baz
- #
- # checkbox_group("name", ["foo"], ["bar", true], "baz")
- # # <INPUT TYPE="checkbox" NAME="name" VALUE="foo">foo
- # # <INPUT TYPE="checkbox" CHECKED NAME="name" VALUE="bar">bar
- # # <INPUT TYPE="checkbox" NAME="name" VALUE="baz">baz
- #
- # checkbox_group("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
- # # <INPUT TYPE="checkbox" NAME="name" VALUE="1">Foo
- # # <INPUT TYPE="checkbox" CHECKED NAME="name" VALUE="2">Bar
- # # <INPUT TYPE="checkbox" NAME="name" VALUE="Baz">Baz
- #
- # checkbox_group("NAME" => "name",
- # "VALUES" => ["foo", "bar", "baz"])
- #
- # checkbox_group("NAME" => "name",
- # "VALUES" => [["foo"], ["bar", true], "baz"])
- #
- # checkbox_group("NAME" => "name",
- # "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
- def checkbox_group(name = "", *values)
- if name.kind_of?(Hash)
- values = name["VALUES"]
- name = name["NAME"]
- end
- values.collect{|value|
- if value.kind_of?(String)
- checkbox(name, value) + value
- else
- if value[-1] == true || value[-1] == false
- checkbox(name, value[0], value[-1]) +
- value[-2]
- else
- checkbox(name, value[0]) +
- value[-1]
- end
- end
- }.join
- end
-
-
- # Generate an File Upload Input element as a string.
- #
- # The attributes of the element can be specified as three arguments,
- # +name+, +size+, and +maxlength+. +maxlength+ is the maximum length
- # of the file's _name_, not of the file's _contents_.
- #
- # Alternatively, the attributes can be specified as a hash.
- #
- # See #multipart_form() for forms that include file uploads.
- #
- # file_field("name")
- # # <INPUT TYPE="file" NAME="name" SIZE="20">
- #
- # file_field("name", 40)
- # # <INPUT TYPE="file" NAME="name" SIZE="40">
- #
- # file_field("name", 40, 100)
- # # <INPUT TYPE="file" NAME="name" SIZE="40" MAXLENGTH="100">
- #
- # file_field("NAME" => "name", "SIZE" => 40)
- # # <INPUT TYPE="file" NAME="name" SIZE="40">
- def file_field(name = "", size = 20, maxlength = nil)
- attributes = if name.kind_of?(String)
- { "TYPE" => "file", "NAME" => name,
- "SIZE" => size.to_s }
- else
- name["TYPE"] = "file"
- name
- end
- attributes["MAXLENGTH"] = maxlength.to_s if maxlength
- input(attributes)
- end
-
-
- # Generate a Form element as a string.
- #
- # +method+ should be either "get" or "post", and defaults to the latter.
- # +action+ defaults to the current CGI script name. +enctype+
- # defaults to "application/x-www-form-urlencoded".
- #
- # Alternatively, the attributes can be specified as a hash.
- #
- # See also #multipart_form() for forms that include file uploads.
- #
- # form{ "string" }
- # # <FORM METHOD="post" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
- #
- # form("get") { "string" }
- # # <FORM METHOD="get" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
- #
- # form("get", "url") { "string" }
- # # <FORM METHOD="get" ACTION="url" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
- #
- # form("METHOD" => "post", "ENCTYPE" => "enctype") { "string" }
- # # <FORM METHOD="post" ENCTYPE="enctype">string</FORM>
- def form(method = "post", action = script_name, enctype = "application/x-www-form-urlencoded")
- attributes = if method.kind_of?(String)
- { "METHOD" => method, "ACTION" => action,
- "ENCTYPE" => enctype }
- else
- unless method.has_key?("METHOD")
- method["METHOD"] = "post"
- end
- unless method.has_key?("ENCTYPE")
- method["ENCTYPE"] = enctype
- end
- method
- end
- if block_given?
- body = yield
- else
- body = ""
- end
- if @output_hidden
- body << @output_hidden.collect{|k,v|
- "<INPUT TYPE=\"HIDDEN\" NAME=\"#{k}\" VALUE=\"#{v}\">"
- }.join
- end
- super(attributes){body}
- end
-
- # Generate a Hidden Input element as a string.
- #
- # The attributes of the element can be specified as two arguments,
- # +name+ and +value+.
- #
- # Alternatively, the attributes can be specified as a hash.
- #
- # hidden("name")
- # # <INPUT TYPE="hidden" NAME="name">
- #
- # hidden("name", "value")
- # # <INPUT TYPE="hidden" NAME="name" VALUE="value">
- #
- # hidden("NAME" => "name", "VALUE" => "reset", "ID" => "foo")
- # # <INPUT TYPE="hidden" NAME="name" VALUE="value" ID="foo">
- def hidden(name = "", value = nil)
- attributes = if name.kind_of?(String)
- { "TYPE" => "hidden", "NAME" => name, "VALUE" => value }
- else
- name["TYPE"] = "hidden"
- name
- end
- input(attributes)
- end
-
- # Generate a top-level HTML element as a string.
- #
- # The attributes of the element are specified as a hash. The
- # pseudo-attribute "PRETTY" can be used to specify that the generated
- # HTML string should be indented. "PRETTY" can also be specified as
- # a string as the sole argument to this method. The pseudo-attribute
- # "DOCTYPE", if given, is used as the leading DOCTYPE SGML tag; it
- # should include the entire text of this tag, including angle brackets.
- #
- # The body of the html element is supplied as a block.
- #
- # html{ "string" }
- # # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML>string</HTML>
- #
- # html("LANG" => "ja") { "string" }
- # # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML LANG="ja">string</HTML>
- #
- # html("DOCTYPE" => false) { "string" }
- # # <HTML>string</HTML>
- #
- # html("DOCTYPE" => '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">') { "string" }
- # # <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML>string</HTML>
- #
- # html("PRETTY" => " ") { "<BODY></BODY>" }
- # # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
- # # <HTML>
- # # <BODY>
- # # </BODY>
- # # </HTML>
- #
- # html("PRETTY" => "\t") { "<BODY></BODY>" }
- # # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
- # # <HTML>
- # # <BODY>
- # # </BODY>
- # # </HTML>
- #
- # html("PRETTY") { "<BODY></BODY>" }
- # # = html("PRETTY" => " ") { "<BODY></BODY>" }
- #
- # html(if $VERBOSE then "PRETTY" end) { "HTML string" }
- #
- def html(attributes = {}) # :yield:
- if nil == attributes
- attributes = {}
- elsif "PRETTY" == attributes
- attributes = { "PRETTY" => true }
- end
- pretty = attributes.delete("PRETTY")
- pretty = " " if true == pretty
- buf = ""
-
- if attributes.has_key?("DOCTYPE")
- if attributes["DOCTYPE"]
- buf << attributes.delete("DOCTYPE")
- else
- attributes.delete("DOCTYPE")
- end
- else
- buf << doctype
- end
-
- buf << super(attributes)
-
- if pretty
- CGI::pretty(buf, pretty)
- else
- buf
- end
-
- end
-
- # Generate an Image Button Input element as a string.
- #
- # +src+ is the URL of the image to use for the button. +name+
- # is the input name. +alt+ is the alternative text for the image.
- #
- # Alternatively, the attributes can be specified as a hash.
- #
- # image_button("url")
- # # <INPUT TYPE="image" SRC="url">
- #
- # image_button("url", "name", "string")
- # # <INPUT TYPE="image" SRC="url" NAME="name" ALT="string">
- #
- # image_button("SRC" => "url", "ALT" => "string")
- # # <INPUT TYPE="image" SRC="url" ALT="string">
- def image_button(src = "", name = nil, alt = nil)
- attributes = if src.kind_of?(String)
- { "TYPE" => "image", "SRC" => src, "NAME" => name,
- "ALT" => alt }
- else
- src["TYPE"] = "image"
- src["SRC"] ||= ""
- src
- end
- input(attributes)
- end
-
-
- # Generate an Image element as a string.
- #
- # +src+ is the URL of the image. +alt+ is the alternative text for
- # the image. +width+ is the width of the image, and +height+ is
- # its height.
- #
- # Alternatively, the attributes can be specified as a hash.
- #
- # img("src", "alt", 100, 50)
- # # <IMG SRC="src" ALT="alt" WIDTH="100" HEIGHT="50">
- #
- # img("SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50)
- # # <IMG SRC="src" ALT="alt" WIDTH="100" HEIGHT="50">
- def img(src = "", alt = "", width = nil, height = nil)
- attributes = if src.kind_of?(String)
- { "SRC" => src, "ALT" => alt }
- else
- src
- end
- attributes["WIDTH"] = width.to_s if width
- attributes["HEIGHT"] = height.to_s if height
- super(attributes)
- end
-
-
- # Generate a Form element with multipart encoding as a String.
- #
- # Multipart encoding is used for forms that include file uploads.
- #
- # +action+ is the action to perform. +enctype+ is the encoding
- # type, which defaults to "multipart/form-data".
- #
- # Alternatively, the attributes can be specified as a hash.
- #
- # multipart_form{ "string" }
- # # <FORM METHOD="post" ENCTYPE="multipart/form-data">string</FORM>
- #
- # multipart_form("url") { "string" }
- # # <FORM METHOD="post" ACTION="url" ENCTYPE="multipart/form-data">string</FORM>
- def multipart_form(action = nil, enctype = "multipart/form-data")
- attributes = if action == nil
- { "METHOD" => "post", "ENCTYPE" => enctype }
- elsif action.kind_of?(String)
- { "METHOD" => "post", "ACTION" => action,
- "ENCTYPE" => enctype }
- else
- unless action.has_key?("METHOD")
- action["METHOD"] = "post"
- end
- unless action.has_key?("ENCTYPE")
- action["ENCTYPE"] = enctype
- end
- action
- end
- if block_given?
- form(attributes){ yield }
- else
- form(attributes)
- end
- end
-
-
- # Generate a Password Input element as a string.
- #
- # +name+ is the name of the input field. +value+ is its default
- # value. +size+ is the size of the input field display. +maxlength+
- # is the maximum length of the inputted password.
- #
- # Alternatively, attributes can be specified as a hash.
- #
- # password_field("name")
- # # <INPUT TYPE="password" NAME="name" SIZE="40">
- #
- # password_field("name", "value")
- # # <INPUT TYPE="password" NAME="name" VALUE="value" SIZE="40">
- #
- # password_field("password", "value", 80, 200)
- # # <INPUT TYPE="password" NAME="name" VALUE="value" SIZE="80" MAXLENGTH="200">
- #
- # password_field("NAME" => "name", "VALUE" => "value")
- # # <INPUT TYPE="password" NAME="name" VALUE="value">
- def password_field(name = "", value = nil, size = 40, maxlength = nil)
- attributes = if name.kind_of?(String)
- { "TYPE" => "password", "NAME" => name,
- "VALUE" => value, "SIZE" => size.to_s }
- else
- name["TYPE"] = "password"
- name
- end
- attributes["MAXLENGTH"] = maxlength.to_s if maxlength
- input(attributes)
- end
-
- # Generate a Select element as a string.
- #
- # +name+ is the name of the element. The +values+ are the options that
- # can be selected from the Select menu. Each value can be a String or
- # a one, two, or three-element Array. If a String or a one-element
- # Array, this is both the value of that option and the text displayed for
- # it. If a three-element Array, the elements are the option value, displayed
- # text, and a boolean value specifying whether this option starts as selected.
- # The two-element version omits either the option value (defaults to the same
- # as the display text) or the boolean selected specifier (defaults to false).
- #
- # The attributes and options can also be specified as a hash. In this
- # case, options are specified as an array of values as described above,
- # with the hash key of "VALUES".
- #
- # popup_menu("name", "foo", "bar", "baz")
- # # <SELECT NAME="name">
- # # <OPTION VALUE="foo">foo</OPTION>
- # # <OPTION VALUE="bar">bar</OPTION>
- # # <OPTION VALUE="baz">baz</OPTION>
- # # </SELECT>
- #
- # popup_menu("name", ["foo"], ["bar", true], "baz")
- # # <SELECT NAME="name">
- # # <OPTION VALUE="foo">foo</OPTION>
- # # <OPTION VALUE="bar" SELECTED>bar</OPTION>
- # # <OPTION VALUE="baz">baz</OPTION>
- # # </SELECT>
- #
- # popup_menu("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
- # # <SELECT NAME="name">
- # # <OPTION VALUE="1">Foo</OPTION>
- # # <OPTION SELECTED VALUE="2">Bar</OPTION>
- # # <OPTION VALUE="Baz">Baz</OPTION>
- # # </SELECT>
- #
- # popup_menu("NAME" => "name", "SIZE" => 2, "MULTIPLE" => true,
- # "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
- # # <SELECT NAME="name" MULTIPLE SIZE="2">
- # # <OPTION VALUE="1">Foo</OPTION>
- # # <OPTION SELECTED VALUE="2">Bar</OPTION>
- # # <OPTION VALUE="Baz">Baz</OPTION>
- # # </SELECT>
- def popup_menu(name = "", *values)
-
- if name.kind_of?(Hash)
- values = name["VALUES"]
- size = name["SIZE"].to_s if name["SIZE"]
- multiple = name["MULTIPLE"]
- name = name["NAME"]
- else
- size = nil
- multiple = nil
- end
-
- select({ "NAME" => name, "SIZE" => size,
- "MULTIPLE" => multiple }){
- values.collect{|value|
- if value.kind_of?(String)
- option({ "VALUE" => value }){ value }
- else
- if value[value.size - 1] == true
- option({ "VALUE" => value[0], "SELECTED" => true }){
- value[value.size - 2]
- }
- else
- option({ "VALUE" => value[0] }){
- value[value.size - 1]
- }
- end
- end
- }.join
- }
-
- end
-
- # Generates a radio-button Input element.
- #
- # +name+ is the name of the input field. +value+ is the value of
- # the field if checked. +checked+ specifies whether the field
- # starts off checked.
- #
- # Alternatively, the attributes can be specified as a hash.
- #
- # radio_button("name", "value")
- # # <INPUT TYPE="radio" NAME="name" VALUE="value">
- #
- # radio_button("name", "value", true)
- # # <INPUT TYPE="radio" NAME="name" VALUE="value" CHECKED>
- #
- # radio_button("NAME" => "name", "VALUE" => "value", "ID" => "foo")
- # # <INPUT TYPE="radio" NAME="name" VALUE="value" ID="foo">
- def radio_button(name = "", value = nil, checked = nil)
- attributes = if name.kind_of?(String)
- { "TYPE" => "radio", "NAME" => name,
- "VALUE" => value, "CHECKED" => checked }
- else
- name["TYPE"] = "radio"
- name
- end
- input(attributes)
- end
-
- # Generate a sequence of radio button Input elements, as a String.
- #
- # This works the same as #checkbox_group(). However, it is not valid
- # to have more than one radiobutton in a group checked.
- #
- # radio_group("name", "foo", "bar", "baz")
- # # <INPUT TYPE="radio" NAME="name" VALUE="foo">foo
- # # <INPUT TYPE="radio" NAME="name" VALUE="bar">bar
- # # <INPUT TYPE="radio" NAME="name" VALUE="baz">baz
- #
- # radio_group("name", ["foo"], ["bar", true], "baz")
- # # <INPUT TYPE="radio" NAME="name" VALUE="foo">foo
- # # <INPUT TYPE="radio" CHECKED NAME="name" VALUE="bar">bar
- # # <INPUT TYPE="radio" NAME="name" VALUE="baz">baz
- #
- # radio_group("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
- # # <INPUT TYPE="radio" NAME="name" VALUE="1">Foo
- # # <INPUT TYPE="radio" CHECKED NAME="name" VALUE="2">Bar
- # # <INPUT TYPE="radio" NAME="name" VALUE="Baz">Baz
- #
- # radio_group("NAME" => "name",
- # "VALUES" => ["foo", "bar", "baz"])
- #
- # radio_group("NAME" => "name",
- # "VALUES" => [["foo"], ["bar", true], "baz"])
- #
- # radio_group("NAME" => "name",
- # "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
- def radio_group(name = "", *values)
- if name.kind_of?(Hash)
- values = name["VALUES"]
- name = name["NAME"]
- end
- values.collect{|value|
- if value.kind_of?(String)
- radio_button(name, value) + value
- else
- if value[-1] == true || value[-1] == false
- radio_button(name, value[0], value[-1]) +
- value[-2]
- else
- radio_button(name, value[0]) +
- value[-1]
- end
- end
- }.join
- end
-
- # Generate a reset button Input element, as a String.
- #
- # This resets the values on a form to their initial values. +value+
- # is the text displayed on the button. +name+ is the name of this button.
- #
- # Alternatively, the attributes can be specified as a hash.
- #
- # reset
- # # <INPUT TYPE="reset">
- #
- # reset("reset")
- # # <INPUT TYPE="reset" VALUE="reset">
- #
- # reset("VALUE" => "reset", "ID" => "foo")
- # # <INPUT TYPE="reset" VALUE="reset" ID="foo">
- def reset(value = nil, name = nil)
- attributes = if (not value) or value.kind_of?(String)
- { "TYPE" => "reset", "VALUE" => value, "NAME" => name }
- else
- value["TYPE"] = "reset"
- value
- end
- input(attributes)
- end
-
- alias scrolling_list popup_menu
-
- # Generate a submit button Input element, as a String.
- #
- # +value+ is the text to display on the button. +name+ is the name
- # of the input.
- #
- # Alternatively, the attributes can be specified as a hash.
- #
- # submit
- # # <INPUT TYPE="submit">
- #
- # submit("ok")
- # # <INPUT TYPE="submit" VALUE="ok">
- #
- # submit("ok", "button1")
- # # <INPUT TYPE="submit" VALUE="ok" NAME="button1">
- #
- # submit("VALUE" => "ok", "NAME" => "button1", "ID" => "foo")
- # # <INPUT TYPE="submit" VALUE="ok" NAME="button1" ID="foo">
- def submit(value = nil, name = nil)
- attributes = if (not value) or value.kind_of?(String)
- { "TYPE" => "submit", "VALUE" => value, "NAME" => name }
- else
- value["TYPE"] = "submit"
- value
- end
- input(attributes)
- end
-
- # Generate a text field Input element, as a String.
- #
- # +name+ is the name of the input field. +value+ is its initial
- # value. +size+ is the size of the input area. +maxlength+
- # is the maximum length of input accepted.
- #
- # Alternatively, the attributes can be specified as a hash.
- #
- # text_field("name")
- # # <INPUT TYPE="text" NAME="name" SIZE="40">
- #
- # text_field("name", "value")
- # # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="40">
- #
- # text_field("name", "value", 80)
- # # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="80">
- #
- # text_field("name", "value", 80, 200)
- # # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="80" MAXLENGTH="200">
- #
- # text_field("NAME" => "name", "VALUE" => "value")
- # # <INPUT TYPE="text" NAME="name" VALUE="value">
- def text_field(name = "", value = nil, size = 40, maxlength = nil)
- attributes = if name.kind_of?(String)
- { "TYPE" => "text", "NAME" => name, "VALUE" => value,
- "SIZE" => size.to_s }
- else
- name["TYPE"] = "text"
- name
- end
- attributes["MAXLENGTH"] = maxlength.to_s if maxlength
- input(attributes)
- end
-
- # Generate a TextArea element, as a String.
- #
- # +name+ is the name of the textarea. +cols+ is the number of
- # columns and +rows+ is the number of rows in the display.
- #
- # Alternatively, the attributes can be specified as a hash.
- #
- # The body is provided by the passed-in no-argument block
- #
- # textarea("name")
- # # = textarea("NAME" => "name", "COLS" => 70, "ROWS" => 10)
- #
- # textarea("name", 40, 5)
- # # = textarea("NAME" => "name", "COLS" => 40, "ROWS" => 5)
- def textarea(name = "", cols = 70, rows = 10) # :yield:
- attributes = if name.kind_of?(String)
- { "NAME" => name, "COLS" => cols.to_s,
- "ROWS" => rows.to_s }
- else
- name
- end
- super(attributes)
- end
-
- end # HtmlExtension
-
-
- # Mixin module for HTML version 3 generation methods.
- module Html3 # :nodoc:
- include TagMaker
-
- # The DOCTYPE declaration for this version of HTML
- def doctype
- %|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">|
- end
-
- instance_method(:nn_element_def).tap do |m|
- # - -
- for element in %w[ A TT I B U STRIKE BIG SMALL SUB SUP EM STRONG
- DFN CODE SAMP KBD VAR CITE FONT ADDRESS DIV CENTER MAP
- APPLET PRE XMP LISTING DL OL UL DIR MENU SELECT TABLE TITLE
- STYLE SCRIPT H1 H2 H3 H4 H5 H6 TEXTAREA FORM BLOCKQUOTE
- CAPTION ]
- define_method(element.downcase, m)
- end
- end
-
- instance_method(:nOE_element_def).tap do |m|
- # - O EMPTY
- for element in %w[ IMG BASE BASEFONT BR AREA LINK PARAM HR INPUT
- ISINDEX META ]
- define_method(element.downcase, m)
- end
- end
-
- instance_method(:nO_element_def).tap do |m|
- # O O or - O
- for element in %w[ HTML HEAD BODY P PLAINTEXT DT DD LI OPTION TR
- TH TD ]
- define_method(element.downcase, m)
- end
- end
-
- end # Html3
-
-
- # Mixin module for HTML version 4 generation methods.
- module Html4 # :nodoc:
- include TagMaker
-
- # The DOCTYPE declaration for this version of HTML
- def doctype
- %|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">|
- end
-
- # Initialize the HTML generation methods for this version.
- # - -
- instance_method(:nn_element_def).tap do |m|
- for element in %w[ TT I B BIG SMALL EM STRONG DFN CODE SAMP KBD
- VAR CITE ABBR ACRONYM SUB SUP SPAN BDO ADDRESS DIV MAP OBJECT
- H1 H2 H3 H4 H5 H6 PRE Q INS DEL DL OL UL LABEL SELECT OPTGROUP
- FIELDSET LEGEND BUTTON TABLE TITLE STYLE SCRIPT NOSCRIPT
- TEXTAREA FORM A BLOCKQUOTE CAPTION ]
- define_method(element.downcase, m)
- end
- end
-
- # - O EMPTY
- instance_method(:nOE_element_def).tap do |m|
- for element in %w[ IMG BASE BR AREA LINK PARAM HR INPUT COL META ]
- define_method(element.downcase, m)
- end
- end
-
- # O O or - O
- instance_method(:nO_element_def).tap do |m|
- for element in %w[ HTML BODY P DT DD LI OPTION THEAD TFOOT TBODY
- COLGROUP TR TH TD HEAD ]
- define_method(element.downcase, m)
- end
- end
-
- end # Html4
-
-
- # Mixin module for HTML version 4 transitional generation methods.
- module Html4Tr # :nodoc:
- include TagMaker
-
- # The DOCTYPE declaration for this version of HTML
- def doctype
- %|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">|
- end
-
- # Initialise the HTML generation methods for this version.
- # - -
- instance_method(:nn_element_def).tap do |m|
- for element in %w[ TT I B U S STRIKE BIG SMALL EM STRONG DFN
- CODE SAMP KBD VAR CITE ABBR ACRONYM FONT SUB SUP SPAN BDO
- ADDRESS DIV CENTER MAP OBJECT APPLET H1 H2 H3 H4 H5 H6 PRE Q
- INS DEL DL OL UL DIR MENU LABEL SELECT OPTGROUP FIELDSET
- LEGEND BUTTON TABLE IFRAME NOFRAMES TITLE STYLE SCRIPT
- NOSCRIPT TEXTAREA FORM A BLOCKQUOTE CAPTION ]
- define_method(element.downcase, m)
- end
- end
-
- # - O EMPTY
- instance_method(:nOE_element_def).tap do |m|
- for element in %w[ IMG BASE BASEFONT BR AREA LINK PARAM HR INPUT
- COL ISINDEX META ]
- define_method(element.downcase, m)
- end
- end
-
- # O O or - O
- instance_method(:nO_element_def).tap do |m|
- for element in %w[ HTML BODY P DT DD LI OPTION THEAD TFOOT TBODY
- COLGROUP TR TH TD HEAD ]
- define_method(element.downcase, m)
- end
- end
-
- end # Html4Tr
-
-
- # Mixin module for generating HTML version 4 with framesets.
- module Html4Fr # :nodoc:
- include TagMaker
-
- # The DOCTYPE declaration for this version of HTML
- def doctype
- %|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">|
- end
-
- # Initialise the HTML generation methods for this version.
- # - -
- instance_method(:nn_element_def).tap do |m|
- for element in %w[ FRAMESET ]
- define_method(element.downcase, m)
- end
- end
-
- # - O EMPTY
- instance_method(:nOE_element_def).tap do |m|
- for element in %w[ FRAME ]
- define_method(element.downcase, m)
- end
- end
-
- end # Html4Fr
-
-
- # Mixin module for HTML version 5 generation methods.
- module Html5 # :nodoc:
- include TagMaker
-
- # The DOCTYPE declaration for this version of HTML
- def doctype
- %|<!DOCTYPE HTML>|
- end
-
- # Initialise the HTML generation methods for this version.
- # - -
- instance_method(:nn_element_def).tap do |m|
- for element in %w[ SECTION NAV ARTICLE ASIDE HGROUP HEADER
- FOOTER FIGURE FIGCAPTION S TIME U MARK RUBY BDI IFRAME
- VIDEO AUDIO CANVAS DATALIST OUTPUT PROGRESS METER DETAILS
- SUMMARY MENU DIALOG I B SMALL EM STRONG DFN CODE SAMP KBD
- VAR CITE ABBR SUB SUP SPAN BDO ADDRESS DIV MAP OBJECT
- H1 H2 H3 H4 H5 H6 PRE Q INS DEL DL OL UL LABEL SELECT
- FIELDSET LEGEND BUTTON TABLE TITLE STYLE SCRIPT NOSCRIPT
- TEXTAREA FORM A BLOCKQUOTE CAPTION ]
- define_method(element.downcase, m)
- end
- end
-
- # - O EMPTY
- instance_method(:nOE_element_def).tap do |m|
- for element in %w[ IMG BASE BR AREA LINK PARAM HR INPUT COL META
- COMMAND EMBED KEYGEN SOURCE TRACK WBR ]
- define_method(element.downcase, m)
- end
- end
-
- # O O or - O
- instance_method(:nO_element_def).tap do |m|
- for element in %w[ HTML HEAD BODY P DT DD LI OPTION THEAD TFOOT TBODY
- OPTGROUP COLGROUP RT RP TR TH TD ]
- define_method(element.downcase, m)
- end
- end
-
- end # Html5
-
- class HTML3
- include Html3
- include HtmlExtension
- end
-
- class HTML4
- include Html4
- include HtmlExtension
- end
-
- class HTML4Tr
- include Html4Tr
- include HtmlExtension
- end
-
- class HTML4Fr
- include Html4Tr
- include Html4Fr
- include HtmlExtension
- end
-
- class HTML5
- include Html5
- include HtmlExtension
- end
-
-end
diff --git a/ruby_2_2/lib/cgi/session.rb b/ruby_2_2/lib/cgi/session.rb
deleted file mode 100644
index 63c5003526..0000000000
--- a/ruby_2_2/lib/cgi/session.rb
+++ /dev/null
@@ -1,531 +0,0 @@
-#
-# cgi/session.rb - session support for cgi scripts
-#
-# Copyright (C) 2001 Yukihiro "Matz" Matsumoto
-# Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
-# Copyright (C) 2000 Information-technology Promotion Agency, Japan
-#
-# Author: Yukihiro "Matz" Matsumoto
-#
-# Documentation: William Webber (william@williamwebber.com)
-
-require 'cgi'
-require 'tmpdir'
-
-class CGI
-
- # == Overview
- #
- # This file provides the CGI::Session class, which provides session
- # support for CGI scripts. A session is a sequence of HTTP requests
- # and responses linked together and associated with a single client.
- # Information associated with the session is stored
- # on the server between requests. A session id is passed between client
- # and server with every request and response, transparently
- # to the user. This adds state information to the otherwise stateless
- # HTTP request/response protocol.
- #
- # == Lifecycle
- #
- # A CGI::Session instance is created from a CGI object. By default,
- # this CGI::Session instance will start a new session if none currently
- # exists, or continue the current session for this client if one does
- # exist. The +new_session+ option can be used to either always or
- # never create a new session. See #new() for more details.
- #
- # #delete() deletes a session from session storage. It
- # does not however remove the session id from the client. If the client
- # makes another request with the same id, the effect will be to start
- # a new session with the old session's id.
- #
- # == Setting and retrieving session data.
- #
- # The Session class associates data with a session as key-value pairs.
- # This data can be set and retrieved by indexing the Session instance
- # using '[]', much the same as hashes (although other hash methods
- # are not supported).
- #
- # When session processing has been completed for a request, the
- # session should be closed using the close() method. This will
- # store the session's state to persistent storage. If you want
- # to store the session's state to persistent storage without
- # finishing session processing for this request, call the update()
- # method.
- #
- # == Storing session state
- #
- # The caller can specify what form of storage to use for the session's
- # data with the +database_manager+ option to CGI::Session::new. The
- # following storage classes are provided as part of the standard library:
- #
- # CGI::Session::FileStore:: stores data as plain text in a flat file. Only
- # works with String data. This is the default
- # storage type.
- # CGI::Session::MemoryStore:: stores data in an in-memory hash. The data
- # only persists for as long as the current Ruby
- # interpreter instance does.
- # CGI::Session::PStore:: stores data in Marshalled format. Provided by
- # cgi/session/pstore.rb. Supports data of any type,
- # and provides file-locking and transaction support.
- #
- # Custom storage types can also be created by defining a class with
- # the following methods:
- #
- # new(session, options)
- # restore # returns hash of session data.
- # update
- # close
- # delete
- #
- # Changing storage type mid-session does not work. Note in particular
- # that by default the FileStore and PStore session data files have the
- # same name. If your application switches from one to the other without
- # making sure that filenames will be different
- # and clients still have old sessions lying around in cookies, then
- # things will break nastily!
- #
- # == Maintaining the session id.
- #
- # Most session state is maintained on the server. However, a session
- # id must be passed backwards and forwards between client and server
- # to maintain a reference to this session state.
- #
- # The simplest way to do this is via cookies. The CGI::Session class
- # provides transparent support for session id communication via cookies
- # if the client has cookies enabled.
- #
- # If the client has cookies disabled, the session id must be included
- # as a parameter of all requests sent by the client to the server. The
- # CGI::Session class in conjunction with the CGI class will transparently
- # add the session id as a hidden input field to all forms generated
- # using the CGI#form() HTML generation method. No built-in support is
- # provided for other mechanisms, such as URL re-writing. The caller is
- # responsible for extracting the session id from the session_id
- # attribute and manually encoding it in URLs and adding it as a hidden
- # input to HTML forms created by other mechanisms. Also, session expiry
- # is not automatically handled.
- #
- # == Examples of use
- #
- # === Setting the user's name
- #
- # require 'cgi'
- # require 'cgi/session'
- # require 'cgi/session/pstore' # provides CGI::Session::PStore
- #
- # cgi = CGI.new("html4")
- #
- # session = CGI::Session.new(cgi,
- # 'database_manager' => CGI::Session::PStore, # use PStore
- # 'session_key' => '_rb_sess_id', # custom session key
- # 'session_expires' => Time.now + 30 * 60, # 30 minute timeout
- # 'prefix' => 'pstore_sid_') # PStore option
- # if cgi.has_key?('user_name') and cgi['user_name'] != ''
- # # coerce to String: cgi[] returns the
- # # string-like CGI::QueryExtension::Value
- # session['user_name'] = cgi['user_name'].to_s
- # elsif !session['user_name']
- # session['user_name'] = "guest"
- # end
- # session.close
- #
- # === Creating a new session safely
- #
- # require 'cgi'
- # require 'cgi/session'
- #
- # cgi = CGI.new("html4")
- #
- # # We make sure to delete an old session if one exists,
- # # not just to free resources, but to prevent the session
- # # from being maliciously hijacked later on.
- # begin
- # session = CGI::Session.new(cgi, 'new_session' => false)
- # session.delete
- # rescue ArgumentError # if no old session
- # end
- # session = CGI::Session.new(cgi, 'new_session' => true)
- # session.close
- #
- class Session
-
- class NoSession < RuntimeError #:nodoc:
- end
-
- # The id of this session.
- attr_reader :session_id, :new_session
-
- def Session::callback(dbman) #:nodoc:
- Proc.new{
- dbman[0].close unless dbman.empty?
- }
- end
-
- # Create a new session id.
- #
- # The session id is an MD5 hash based upon the time,
- # a random number, and a constant string. This routine
- # is used internally for automatically generated
- # session ids.
- def create_new_id
- require 'securerandom'
- begin
- session_id = SecureRandom.hex(16)
- rescue NotImplementedError
- require 'digest/md5'
- md5 = Digest::MD5::new
- now = Time::now
- md5.update(now.to_s)
- md5.update(String(now.usec))
- md5.update(String(rand(0)))
- md5.update(String($$))
- md5.update('foobar')
- session_id = md5.hexdigest
- end
- session_id
- end
- private :create_new_id
-
- # Create a new CGI::Session object for +request+.
- #
- # +request+ is an instance of the +CGI+ class (see cgi.rb).
- # +option+ is a hash of options for initialising this
- # CGI::Session instance. The following options are
- # recognised:
- #
- # session_key:: the parameter name used for the session id.
- # Defaults to '_session_id'.
- # session_id:: the session id to use. If not provided, then
- # it is retrieved from the +session_key+ parameter
- # of the request, or automatically generated for
- # a new session.
- # new_session:: if true, force creation of a new session. If not set,
- # a new session is only created if none currently
- # exists. If false, a new session is never created,
- # and if none currently exists and the +session_id+
- # option is not set, an ArgumentError is raised.
- # database_manager:: the name of the class providing storage facilities
- # for session state persistence. Built-in support
- # is provided for +FileStore+ (the default),
- # +MemoryStore+, and +PStore+ (from
- # cgi/session/pstore.rb). See the documentation for
- # these classes for more details.
- #
- # The following options are also recognised, but only apply if the
- # session id is stored in a cookie.
- #
- # session_expires:: the time the current session expires, as a
- # +Time+ object. If not set, the session will terminate
- # when the user's browser is closed.
- # session_domain:: the hostname domain for which this session is valid.
- # If not set, defaults to the hostname of the server.
- # session_secure:: if +true+, this session will only work over HTTPS.
- # session_path:: the path for which this session applies. Defaults
- # to the directory of the CGI script.
- #
- # +option+ is also passed on to the session storage class initializer; see
- # the documentation for each session storage class for the options
- # they support.
- #
- # The retrieved or created session is automatically added to +request+
- # as a cookie, and also to its +output_hidden+ table, which is used
- # to add hidden input elements to forms.
- #
- # *WARNING* the +output_hidden+
- # fields are surrounded by a <fieldset> tag in HTML 4 generation, which
- # is _not_ invisible on many browsers; you may wish to disable the
- # use of fieldsets with code similar to the following
- # (see http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/37805)
- #
- # cgi = CGI.new("html4")
- # class << cgi
- # undef_method :fieldset
- # end
- #
- def initialize(request, option={})
- @new_session = false
- session_key = option['session_key'] || '_session_id'
- session_id = option['session_id']
- unless session_id
- if option['new_session']
- session_id = create_new_id
- @new_session = true
- end
- end
- unless session_id
- if request.key?(session_key)
- session_id = request[session_key]
- session_id = session_id.read if session_id.respond_to?(:read)
- end
- unless session_id
- session_id, = request.cookies[session_key]
- end
- unless session_id
- unless option.fetch('new_session', true)
- raise ArgumentError, "session_key `%s' should be supplied"%session_key
- end
- session_id = create_new_id
- @new_session = true
- end
- end
- @session_id = session_id
- dbman = option['database_manager'] || FileStore
- begin
- @dbman = dbman::new(self, option)
- rescue NoSession
- unless option.fetch('new_session', true)
- raise ArgumentError, "invalid session_id `%s'"%session_id
- end
- session_id = @session_id = create_new_id unless session_id
- @new_session=true
- retry
- end
- request.instance_eval do
- @output_hidden = {session_key => session_id} unless option['no_hidden']
- @output_cookies = [
- Cookie::new("name" => session_key,
- "value" => session_id,
- "expires" => option['session_expires'],
- "domain" => option['session_domain'],
- "secure" => option['session_secure'],
- "path" =>
- if option['session_path']
- option['session_path']
- elsif ENV["SCRIPT_NAME"]
- File::dirname(ENV["SCRIPT_NAME"])
- else
- ""
- end)
- ] unless option['no_cookies']
- end
- @dbprot = [@dbman]
- ObjectSpace::define_finalizer(self, Session::callback(@dbprot))
- end
-
- # Retrieve the session data for key +key+.
- def [](key)
- @data ||= @dbman.restore
- @data[key]
- end
-
- # Set the session data for key +key+.
- def []=(key, val)
- @write_lock ||= true
- @data ||= @dbman.restore
- @data[key] = val
- end
-
- # Store session data on the server. For some session storage types,
- # this is a no-op.
- def update
- @dbman.update
- end
-
- # Store session data on the server and close the session storage.
- # For some session storage types, this is a no-op.
- def close
- @dbman.close
- @dbprot.clear
- end
-
- # Delete the session from storage. Also closes the storage.
- #
- # Note that the session's data is _not_ automatically deleted
- # upon the session expiring.
- def delete
- @dbman.delete
- @dbprot.clear
- end
-
- # File-based session storage class.
- #
- # Implements session storage as a flat file of 'key=value' values.
- # This storage type only works directly with String values; the
- # user is responsible for converting other types to Strings when
- # storing and from Strings when retrieving.
- class FileStore
- # Create a new FileStore instance.
- #
- # This constructor is used internally by CGI::Session. The
- # user does not generally need to call it directly.
- #
- # +session+ is the session for which this instance is being
- # created. The session id must only contain alphanumeric
- # characters; automatically generated session ids observe
- # this requirement.
- #
- # +option+ is a hash of options for the initializer. The
- # following options are recognised:
- #
- # tmpdir:: the directory to use for storing the FileStore
- # file. Defaults to Dir::tmpdir (generally "/tmp"
- # on Unix systems).
- # prefix:: the prefix to add to the session id when generating
- # the filename for this session's FileStore file.
- # Defaults to "cgi_sid_".
- # suffix:: the prefix to add to the session id when generating
- # the filename for this session's FileStore file.
- # Defaults to the empty string.
- #
- # This session's FileStore file will be created if it does
- # not exist, or opened if it does.
- def initialize(session, option={})
- dir = option['tmpdir'] || Dir::tmpdir
- prefix = option['prefix'] || 'cgi_sid_'
- suffix = option['suffix'] || ''
- id = session.session_id
- require 'digest/md5'
- md5 = Digest::MD5.hexdigest(id)[0,16]
- @path = dir+"/"+prefix+md5+suffix
- if File::exist? @path
- @hash = nil
- else
- unless session.new_session
- raise CGI::Session::NoSession, "uninitialized session"
- end
- @hash = {}
- end
- end
-
- # Restore session state from the session's FileStore file.
- #
- # Returns the session state as a hash.
- def restore
- unless @hash
- @hash = {}
- begin
- lockf = File.open(@path+".lock", "r")
- lockf.flock File::LOCK_SH
- f = File.open(@path, 'r')
- for line in f
- line.chomp!
- k, v = line.split('=',2)
- @hash[CGI::unescape(k)] = Marshal.restore(CGI::unescape(v))
- end
- ensure
- f.close unless f.nil?
- lockf.close if lockf
- end
- end
- @hash
- end
-
- # Save session state to the session's FileStore file.
- def update
- return unless @hash
- begin
- lockf = File.open(@path+".lock", File::CREAT|File::RDWR, 0600)
- lockf.flock File::LOCK_EX
- f = File.open(@path+".new", File::CREAT|File::TRUNC|File::WRONLY, 0600)
- for k,v in @hash
- f.printf "%s=%s\n", CGI::escape(k), CGI::escape(String(Marshal.dump(v)))
- end
- f.close
- File.rename @path+".new", @path
- ensure
- f.close if f and !f.closed?
- lockf.close if lockf
- end
- end
-
- # Update and close the session's FileStore file.
- def close
- update
- end
-
- # Close and delete the session's FileStore file.
- def delete
- File::unlink @path+".lock" rescue nil
- File::unlink @path+".new" rescue nil
- File::unlink @path rescue nil
- end
- end
-
- # In-memory session storage class.
- #
- # Implements session storage as a global in-memory hash. Session
- # data will only persist for as long as the Ruby interpreter
- # instance does.
- class MemoryStore
- GLOBAL_HASH_TABLE = {} #:nodoc:
-
- # Create a new MemoryStore instance.
- #
- # +session+ is the session this instance is associated with.
- # +option+ is a list of initialisation options. None are
- # currently recognized.
- def initialize(session, option=nil)
- @session_id = session.session_id
- unless GLOBAL_HASH_TABLE.key?(@session_id)
- unless session.new_session
- raise CGI::Session::NoSession, "uninitialized session"
- end
- GLOBAL_HASH_TABLE[@session_id] = {}
- end
- end
-
- # Restore session state.
- #
- # Returns session data as a hash.
- def restore
- GLOBAL_HASH_TABLE[@session_id]
- end
-
- # Update session state.
- #
- # A no-op.
- def update
- # don't need to update; hash is shared
- end
-
- # Close session storage.
- #
- # A no-op.
- def close
- # don't need to close
- end
-
- # Delete the session state.
- def delete
- GLOBAL_HASH_TABLE.delete(@session_id)
- end
- end
-
- # Dummy session storage class.
- #
- # Implements session storage place holder. No actual storage
- # will be done.
- class NullStore
- # Create a new NullStore instance.
- #
- # +session+ is the session this instance is associated with.
- # +option+ is a list of initialisation options. None are
- # currently recognised.
- def initialize(session, option=nil)
- end
-
- # Restore (empty) session state.
- def restore
- {}
- end
-
- # Update session state.
- #
- # A no-op.
- def update
- end
-
- # Close session storage.
- #
- # A no-op.
- def close
- end
-
- # Delete the session state.
- #
- # A no-op.
- def delete
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/cgi/session/pstore.rb b/ruby_2_2/lib/cgi/session/pstore.rb
deleted file mode 100644
index 75343149e1..0000000000
--- a/ruby_2_2/lib/cgi/session/pstore.rb
+++ /dev/null
@@ -1,100 +0,0 @@
-#
-# cgi/session/pstore.rb - persistent storage of marshalled session data
-#
-# Documentation: William Webber (william@williamwebber.com)
-#
-# == Overview
-#
-# This file provides the CGI::Session::PStore class, which builds
-# persistent of session data on top of the pstore library. See
-# cgi/session.rb for more details on session storage managers.
-
-require 'cgi/session'
-require 'pstore'
-
-class CGI
- class Session
- # PStore-based session storage class.
- #
- # This builds upon the top-level PStore class provided by the
- # library file pstore.rb. Session data is marshalled and stored
- # in a file. File locking and transaction services are provided.
- class PStore
- # Create a new CGI::Session::PStore instance
- #
- # This constructor is used internally by CGI::Session. The
- # user does not generally need to call it directly.
- #
- # +session+ is the session for which this instance is being
- # created. The session id must only contain alphanumeric
- # characters; automatically generated session ids observe
- # this requirement.
- #
- # +option+ is a hash of options for the initializer. The
- # following options are recognised:
- #
- # tmpdir:: the directory to use for storing the PStore
- # file. Defaults to Dir::tmpdir (generally "/tmp"
- # on Unix systems).
- # prefix:: the prefix to add to the session id when generating
- # the filename for this session's PStore file.
- # Defaults to the empty string.
- #
- # This session's PStore file will be created if it does
- # not exist, or opened if it does.
- def initialize(session, option={})
- dir = option['tmpdir'] || Dir::tmpdir
- prefix = option['prefix'] || ''
- id = session.session_id
- require 'digest/md5'
- md5 = Digest::MD5.hexdigest(id)[0,16]
- path = dir+"/"+prefix+md5
- path.untaint
- if File::exist?(path)
- @hash = nil
- else
- unless session.new_session
- raise CGI::Session::NoSession, "uninitialized session"
- end
- @hash = {}
- end
- @p = ::PStore.new(path)
- @p.transaction do |p|
- File.chmod(0600, p.path)
- end
- end
-
- # Restore session state from the session's PStore file.
- #
- # Returns the session state as a hash.
- def restore
- unless @hash
- @p.transaction do
- @hash = @p['hash'] || {}
- end
- end
- @hash
- end
-
- # Save session state to the session's PStore file.
- def update
- @p.transaction do
- @p['hash'] = @hash
- end
- end
-
- # Update and close the session's PStore file.
- def close
- update
- end
-
- # Close and delete the session's PStore file.
- def delete
- path = @p.path
- File::unlink path
- end
-
- end
- end
-end
-# :enddoc:
diff --git a/ruby_2_2/lib/cgi/util.rb b/ruby_2_2/lib/cgi/util.rb
deleted file mode 100644
index 3d7db8f2c8..0000000000
--- a/ruby_2_2/lib/cgi/util.rb
+++ /dev/null
@@ -1,194 +0,0 @@
-class CGI; module Util; end; extend Util; end
-module CGI::Util
- @@accept_charset="UTF-8" unless defined?(@@accept_charset)
- # URL-encode a string.
- # url_encoded_string = CGI::escape("'Stop!' said Fred")
- # # => "%27Stop%21%27+said+Fred"
- def escape(string)
- encoding = string.encoding
- string.b.gsub(/([^ a-zA-Z0-9_.-]+)/) do |m|
- '%' + m.unpack('H2' * m.bytesize).join('%').upcase
- end.tr(' ', '+').force_encoding(encoding)
- end
-
- # URL-decode a string with encoding(optional).
- # string = CGI::unescape("%27Stop%21%27+said+Fred")
- # # => "'Stop!' said Fred"
- def unescape(string,encoding=@@accept_charset)
- str=string.tr('+', ' ').b.gsub(/((?:%[0-9a-fA-F]{2})+)/) do |m|
- [m.delete('%')].pack('H*')
- end.force_encoding(encoding)
- str.valid_encoding? ? str : str.force_encoding(string.encoding)
- end
-
- # The set of special characters and their escaped values
- TABLE_FOR_ESCAPE_HTML__ = {
- "'" => '&#39;',
- '&' => '&amp;',
- '"' => '&quot;',
- '<' => '&lt;',
- '>' => '&gt;',
- }
-
- # Escape special characters in HTML, namely &\"<>
- # CGI::escapeHTML('Usage: foo "bar" <baz>')
- # # => "Usage: foo &quot;bar&quot; &lt;baz&gt;"
- def escapeHTML(string)
- string.gsub(/['&\"<>]/, TABLE_FOR_ESCAPE_HTML__)
- end
-
- # Unescape a string that has been HTML-escaped
- # CGI::unescapeHTML("Usage: foo &quot;bar&quot; &lt;baz&gt;")
- # # => "Usage: foo \"bar\" <baz>"
- def unescapeHTML(string)
- return string unless string.include? '&'
- enc = string.encoding
- if enc != Encoding::UTF_8 && [Encoding::UTF_16BE, Encoding::UTF_16LE, Encoding::UTF_32BE, Encoding::UTF_32LE].include?(enc)
- return string.gsub(Regexp.new('&(apos|amp|quot|gt|lt|#[0-9]+|#x[0-9A-Fa-f]+);'.encode(enc))) do
- case $1.encode(Encoding::US_ASCII)
- when 'apos' then "'".encode(enc)
- when 'amp' then '&'.encode(enc)
- when 'quot' then '"'.encode(enc)
- when 'gt' then '>'.encode(enc)
- when 'lt' then '<'.encode(enc)
- when /\A#0*(\d+)\z/ then $1.to_i.chr(enc)
- when /\A#x([0-9a-f]+)\z/i then $1.hex.chr(enc)
- end
- end
- end
- asciicompat = Encoding.compatible?(string, "a")
- string.gsub(/&(apos|amp|quot|gt|lt|\#[0-9]+|\#[xX][0-9A-Fa-f]+);/) do
- match = $1.dup
- case match
- when 'apos' then "'"
- when 'amp' then '&'
- when 'quot' then '"'
- when 'gt' then '>'
- when 'lt' then '<'
- when /\A#0*(\d+)\z/
- n = $1.to_i
- if enc == Encoding::UTF_8 or
- enc == Encoding::ISO_8859_1 && n < 256 or
- asciicompat && n < 128
- n.chr(enc)
- else
- "&##{$1};"
- end
- when /\A#x([0-9a-f]+)\z/i
- n = $1.hex
- if enc == Encoding::UTF_8 or
- enc == Encoding::ISO_8859_1 && n < 256 or
- asciicompat && n < 128
- n.chr(enc)
- else
- "&#x#{$1};"
- end
- else
- "&#{match};"
- end
- end
- end
-
- # Synonym for CGI::escapeHTML(str)
- alias escape_html escapeHTML
-
- # Synonym for CGI::unescapeHTML(str)
- alias unescape_html unescapeHTML
-
- # Escape only the tags of certain HTML elements in +string+.
- #
- # Takes an element or elements or array of elements. Each element
- # is specified by the name of the element, without angle brackets.
- # This matches both the start and the end tag of that element.
- # The attribute list of the open tag will also be escaped (for
- # instance, the double-quotes surrounding attribute values).
- #
- # print CGI::escapeElement('<BR><A HREF="url"></A>', "A", "IMG")
- # # "<BR>&lt;A HREF=&quot;url&quot;&gt;&lt;/A&gt"
- #
- # print CGI::escapeElement('<BR><A HREF="url"></A>', ["A", "IMG"])
- # # "<BR>&lt;A HREF=&quot;url&quot;&gt;&lt;/A&gt"
- def escapeElement(string, *elements)
- elements = elements[0] if elements[0].kind_of?(Array)
- unless elements.empty?
- string.gsub(/<\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?>/i) do
- CGI::escapeHTML($&)
- end
- else
- string
- end
- end
-
- # Undo escaping such as that done by CGI::escapeElement()
- #
- # print CGI::unescapeElement(
- # CGI::escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG")
- # # "&lt;BR&gt;<A HREF="url"></A>"
- #
- # print CGI::unescapeElement(
- # CGI::escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"])
- # # "&lt;BR&gt;<A HREF="url"></A>"
- def unescapeElement(string, *elements)
- elements = elements[0] if elements[0].kind_of?(Array)
- unless elements.empty?
- string.gsub(/&lt;\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?&gt;/i) do
- unescapeHTML($&)
- end
- else
- string
- end
- end
-
- # Synonym for CGI::escapeElement(str)
- alias escape_element escapeElement
-
- # Synonym for CGI::unescapeElement(str)
- alias unescape_element unescapeElement
-
- # Abbreviated day-of-week names specified by RFC 822
- RFC822_DAYS = %w[ Sun Mon Tue Wed Thu Fri Sat ]
-
- # Abbreviated month names specified by RFC 822
- RFC822_MONTHS = %w[ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ]
-
- # Format a +Time+ object as a String using the format specified by RFC 1123.
- #
- # CGI::rfc1123_date(Time.now)
- # # Sat, 01 Jan 2000 00:00:00 GMT
- def rfc1123_date(time)
- t = time.clone.gmtime
- return format("%s, %.2d %s %.4d %.2d:%.2d:%.2d GMT",
- RFC822_DAYS[t.wday], t.day, RFC822_MONTHS[t.month-1], t.year,
- t.hour, t.min, t.sec)
- end
-
- # Prettify (indent) an HTML string.
- #
- # +string+ is the HTML string to indent. +shift+ is the indentation
- # unit to use; it defaults to two spaces.
- #
- # print CGI::pretty("<HTML><BODY></BODY></HTML>")
- # # <HTML>
- # # <BODY>
- # # </BODY>
- # # </HTML>
- #
- # print CGI::pretty("<HTML><BODY></BODY></HTML>", "\t")
- # # <HTML>
- # # <BODY>
- # # </BODY>
- # # </HTML>
- #
- def pretty(string, shift = " ")
- lines = string.gsub(/(?!\A)<.*?>/m, "\n\\0").gsub(/<.*?>(?!\n)/m, "\\0\n")
- end_pos = 0
- while end_pos = lines.index(/^<\/(\w+)/, end_pos)
- element = $1.dup
- start_pos = lines.rindex(/^\s*<#{element}/i, end_pos)
- lines[start_pos ... end_pos] = "__" + lines[start_pos ... end_pos].gsub(/\n(?!\z)/, "\n" + shift) + "__"
- end
- lines.gsub(/^((?:#{Regexp::quote(shift)})*)__(?=<\/?\w)/, '\1')
- end
-
- alias h escapeHTML
-end
diff --git a/ruby_2_2/lib/cmath.rb b/ruby_2_2/lib/cmath.rb
deleted file mode 100644
index 4753c47545..0000000000
--- a/ruby_2_2/lib/cmath.rb
+++ /dev/null
@@ -1,442 +0,0 @@
-##
-# = Trigonometric and transcendental functions for complex numbers.
-#
-# CMath is a library that provides trigonometric and transcendental
-# functions for complex numbers. The functions in this module accept
-# integers, floating-point numbers or complex numbers as arguments.
-#
-# Note that the selection of functions is similar, but not identical,
-# to that in module math. The reason for having two modules is that
-# some users aren't interested in complex numbers, and perhaps don't
-# even know what they are. They would rather have Math.sqrt(-1) raise
-# an exception than return a complex number.
-#
-# == Usage
-#
-# To start using this library, simply require cmath library:
-#
-# require "cmath"
-#
-# And after call any CMath function. For example:
-#
-# CMath.sqrt(-9) #=> 0+3.0i
-# CMath.exp(0 + 0i) #=> 1.0+0.0i
-# CMath.log10(-5.to_c) #=> (0.6989700043360187+1.3643763538418412i)
-#
-#
-# For more information you can see Complec class.
-
-module CMath
-
- include Math
-
- alias exp! exp
- alias log! log
- alias log2! log2
- alias log10! log10
- alias sqrt! sqrt
- alias cbrt! cbrt
-
- alias sin! sin
- alias cos! cos
- alias tan! tan
-
- alias sinh! sinh
- alias cosh! cosh
- alias tanh! tanh
-
- alias asin! asin
- alias acos! acos
- alias atan! atan
- alias atan2! atan2
-
- alias asinh! asinh
- alias acosh! acosh
- alias atanh! atanh
-
- ##
- # Math::E raised to the +z+ power
- #
- # CMath.exp(2i) #=> (-0.4161468365471424+0.9092974268256817i)
- def exp(z)
- begin
- if z.real?
- exp!(z)
- else
- ere = exp!(z.real)
- Complex(ere * cos!(z.imag),
- ere * sin!(z.imag))
- end
- rescue NoMethodError
- handle_no_method_error
- end
- end
-
- ##
- # Returns the natural logarithm of Complex. If a second argument is given,
- # it will be the base of logarithm.
- #
- # CMath.log(1 + 4i) #=> (1.416606672028108+1.3258176636680326i)
- # CMath.log(1 + 4i, 10) #=> (0.6152244606891369+0.5757952953408879i)
- def log(*args)
- begin
- z, b = args
- unless b.nil? || b.kind_of?(Numeric)
- raise TypeError, "Numeric Number required"
- end
- if z.real? and z >= 0 and (b.nil? or b >= 0)
- log!(*args)
- else
- a = Complex(log!(z.abs), z.arg)
- if b
- a /= log(b)
- end
- a
- end
- rescue NoMethodError
- handle_no_method_error
- end
- end
-
- ##
- # returns the base 2 logarithm of +z+
- #
- # CMath.log2(-1) => (0.0+4.532360141827194i)
- def log2(z)
- begin
- if z.real? and z >= 0
- log2!(z)
- else
- log(z) / log!(2)
- end
- rescue NoMethodError
- handle_no_method_error
- end
- end
-
- ##
- # returns the base 10 logarithm of +z+
- #
- # CMath.log10(-1) #=> (0.0+1.3643763538418412i)
- def log10(z)
- begin
- if z.real? and z >= 0
- log10!(z)
- else
- log(z) / log!(10)
- end
- rescue NoMethodError
- handle_no_method_error
- end
- end
-
- ##
- # Returns the non-negative square root of Complex.
- #
- # CMath.sqrt(-1 + 0i) #=> 0.0+1.0i
- def sqrt(z)
- begin
- if z.real?
- if z < 0
- Complex(0, sqrt!(-z))
- else
- sqrt!(z)
- end
- else
- if z.imag < 0 ||
- (z.imag == 0 && z.imag.to_s[0] == '-')
- sqrt(z.conjugate).conjugate
- else
- r = z.abs
- x = z.real
- Complex(sqrt!((r + x) / 2.0), sqrt!((r - x) / 2.0))
- end
- end
- rescue NoMethodError
- handle_no_method_error
- end
- end
-
- ##
- # returns the principal value of the cube root of +z+
- #
- # CMath.cbrt(1 + 4i) #=> (1.449461632813119+0.6858152562177092i)
- def cbrt(z)
- z ** (1.0/3)
- end
-
- ##
- # returns the sine of +z+, where +z+ is given in radians
- #
- # CMath.sin(1 + 1i) #=> (1.2984575814159773+0.6349639147847361i)
- def sin(z)
- begin
- if z.real?
- sin!(z)
- else
- Complex(sin!(z.real) * cosh!(z.imag),
- cos!(z.real) * sinh!(z.imag))
- end
- rescue NoMethodError
- handle_no_method_error
- end
- end
-
- ##
- # returns the cosine of +z+, where +z+ is given in radians
- #
- # CMath.cos(1 + 1i) #=> (0.8337300251311491-0.9888977057628651i)
- def cos(z)
- begin
- if z.real?
- cos!(z)
- else
- Complex(cos!(z.real) * cosh!(z.imag),
- -sin!(z.real) * sinh!(z.imag))
- end
- rescue NoMethodError
- handle_no_method_error
- end
- end
-
- ##
- # returns the tangent of +z+, where +z+ is given in radians
- #
- # CMath.tan(1 + 1i) #=> (0.27175258531951174+1.0839233273386943i)
- def tan(z)
- begin
- if z.real?
- tan!(z)
- else
- sin(z) / cos(z)
- end
- rescue NoMethodError
- handle_no_method_error
- end
- end
-
- ##
- # returns the hyperbolic sine of +z+, where +z+ is given in radians
- #
- # CMath.sinh(1 + 1i) #=> (0.6349639147847361+1.2984575814159773i)
- def sinh(z)
- begin
- if z.real?
- sinh!(z)
- else
- Complex(sinh!(z.real) * cos!(z.imag),
- cosh!(z.real) * sin!(z.imag))
- end
- rescue NoMethodError
- handle_no_method_error
- end
- end
-
- ##
- # returns the hyperbolic cosine of +z+, where +z+ is given in radians
- #
- # CMath.cosh(1 + 1i) #=> (0.8337300251311491+0.9888977057628651i)
- def cosh(z)
- begin
- if z.real?
- cosh!(z)
- else
- Complex(cosh!(z.real) * cos!(z.imag),
- sinh!(z.real) * sin!(z.imag))
- end
- rescue NoMethodError
- handle_no_method_error
- end
- end
-
- ##
- # returns the hyperbolic tangent of +z+, where +z+ is given in radians
- #
- # CMath.tanh(1 + 1i) #=> (1.0839233273386943+0.27175258531951174i)
- def tanh(z)
- begin
- if z.real?
- tanh!(z)
- else
- sinh(z) / cosh(z)
- end
- rescue NoMethodError
- handle_no_method_error
- end
- end
-
- ##
- # returns the arc sine of +z+
- #
- # CMath.asin(1 + 1i) #=> (0.6662394324925153+1.0612750619050355i)
- def asin(z)
- begin
- if z.real? and z >= -1 and z <= 1
- asin!(z)
- else
- (-1.0).i * log(1.0.i * z + sqrt(1.0 - z * z))
- end
- rescue NoMethodError
- handle_no_method_error
- end
- end
-
- ##
- # returns the arc cosine of +z+
- #
- # CMath.acos(1 + 1i) #=> (0.9045568943023813-1.0612750619050357i)
- def acos(z)
- begin
- if z.real? and z >= -1 and z <= 1
- acos!(z)
- else
- (-1.0).i * log(z + 1.0.i * sqrt(1.0 - z * z))
- end
- rescue NoMethodError
- handle_no_method_error
- end
- end
-
- ##
- # returns the arc tangent of +z+
- #
- # CMath.atan(1 + 1i) #=> (1.0172219678978514+0.4023594781085251i)
- def atan(z)
- begin
- if z.real?
- atan!(z)
- else
- 1.0.i * log((1.0.i + z) / (1.0.i - z)) / 2.0
- end
- rescue NoMethodError
- handle_no_method_error
- end
- end
-
- ##
- # returns the arc tangent of +y+ divided by +x+ using the signs of +y+ and
- # +x+ to determine the quadrant
- #
- # CMath.atan2(1 + 1i, 0) #=> (1.5707963267948966+0.0i)
- def atan2(y,x)
- begin
- if y.real? and x.real?
- atan2!(y,x)
- else
- (-1.0).i * log((x + 1.0.i * y) / sqrt(x * x + y * y))
- end
- rescue NoMethodError
- handle_no_method_error
- end
- end
-
- ##
- # returns the inverse hyperbolic sine of +z+
- #
- # CMath.asinh(1 + 1i) #=> (1.0612750619050357+0.6662394324925153i)
- def asinh(z)
- begin
- if z.real?
- asinh!(z)
- else
- log(z + sqrt(1.0 + z * z))
- end
- rescue NoMethodError
- handle_no_method_error
- end
- end
-
- ##
- # returns the inverse hyperbolic cosine of +z+
- #
- # CMath.acosh(1 + 1i) #=> (1.0612750619050357+0.9045568943023813i)
- def acosh(z)
- begin
- if z.real? and z >= 1
- acosh!(z)
- else
- log(z + sqrt(z * z - 1.0))
- end
- rescue NoMethodError
- handle_no_method_error
- end
- end
-
- ##
- # returns the inverse hyperbolic tangent of +z+
- #
- # CMath.atanh(1 + 1i) #=> (0.4023594781085251+1.0172219678978514i)
- def atanh(z)
- begin
- if z.real? and z >= -1 and z <= 1
- atanh!(z)
- else
- log((1.0 + z) / (1.0 - z)) / 2.0
- end
- rescue NoMethodError
- handle_no_method_error
- end
- end
-
- module_function :exp!
- module_function :exp
- module_function :log!
- module_function :log
- module_function :log2!
- module_function :log2
- module_function :log10!
- module_function :log10
- module_function :sqrt!
- module_function :sqrt
- module_function :cbrt!
- module_function :cbrt
-
- module_function :sin!
- module_function :sin
- module_function :cos!
- module_function :cos
- module_function :tan!
- module_function :tan
-
- module_function :sinh!
- module_function :sinh
- module_function :cosh!
- module_function :cosh
- module_function :tanh!
- module_function :tanh
-
- module_function :asin!
- module_function :asin
- module_function :acos!
- module_function :acos
- module_function :atan!
- module_function :atan
- module_function :atan2!
- module_function :atan2
-
- module_function :asinh!
- module_function :asinh
- module_function :acosh!
- module_function :acosh
- module_function :atanh!
- module_function :atanh
-
- module_function :frexp
- module_function :ldexp
- module_function :hypot
- module_function :erf
- module_function :erfc
- module_function :gamma
- module_function :lgamma
-
- private
- def handle_no_method_error # :nodoc:
- if $!.name == :real?
- raise TypeError, "Numeric Number required"
- else
- raise
- end
- end
- module_function :handle_no_method_error
-
-end
diff --git a/ruby_2_2/lib/csv.rb b/ruby_2_2/lib/csv.rb
deleted file mode 100644
index 54b820df31..0000000000
--- a/ruby_2_2/lib/csv.rb
+++ /dev/null
@@ -1,2341 +0,0 @@
-# encoding: US-ASCII
-# = csv.rb -- CSV Reading and Writing
-#
-# Created by James Edward Gray II on 2005-10-31.
-# Copyright 2005 James Edward Gray II. You can redistribute or modify this code
-# under the terms of Ruby's license.
-#
-# See CSV for documentation.
-#
-# == Description
-#
-# Welcome to the new and improved CSV.
-#
-# This version of the CSV library began its life as FasterCSV. FasterCSV was
-# intended as a replacement to Ruby's then standard CSV library. It was
-# designed to address concerns users of that library had and it had three
-# primary goals:
-#
-# 1. Be significantly faster than CSV while remaining a pure Ruby library.
-# 2. Use a smaller and easier to maintain code base. (FasterCSV eventually
-# grew larger, was also but considerably richer in features. The parsing
-# core remains quite small.)
-# 3. Improve on the CSV interface.
-#
-# Obviously, the last one is subjective. I did try to defer to the original
-# interface whenever I didn't have a compelling reason to change it though, so
-# hopefully this won't be too radically different.
-#
-# We must have met our goals because FasterCSV was renamed to CSV and replaced
-# the original library as of Ruby 1.9. If you are migrating code from 1.8 or
-# earlier, you may have to change your code to comply with the new interface.
-#
-# == What's Different From the Old CSV?
-#
-# I'm sure I'll miss something, but I'll try to mention most of the major
-# differences I am aware of, to help others quickly get up to speed:
-#
-# === CSV Parsing
-#
-# * This parser is m17n aware. See CSV for full details.
-# * This library has a stricter parser and will throw MalformedCSVErrors on
-# problematic data.
-# * This library has a less liberal idea of a line ending than CSV. What you
-# set as the <tt>:row_sep</tt> is law. It can auto-detect your line endings
-# though.
-# * The old library returned empty lines as <tt>[nil]</tt>. This library calls
-# them <tt>[]</tt>.
-# * This library has a much faster parser.
-#
-# === Interface
-#
-# * CSV now uses Hash-style parameters to set options.
-# * CSV no longer has generate_row() or parse_row().
-# * The old CSV's Reader and Writer classes have been dropped.
-# * CSV::open() is now more like Ruby's open().
-# * CSV objects now support most standard IO methods.
-# * CSV now has a new() method used to wrap objects like String and IO for
-# reading and writing.
-# * CSV::generate() is different from the old method.
-# * CSV no longer supports partial reads. It works line-by-line.
-# * CSV no longer allows the instance methods to override the separators for
-# performance reasons. They must be set in the constructor.
-#
-# If you use this library and find yourself missing any functionality I have
-# trimmed, please {let me know}[mailto:james@grayproductions.net].
-#
-# == Documentation
-#
-# See CSV for documentation.
-#
-# == What is CSV, really?
-#
-# CSV maintains a pretty strict definition of CSV taken directly from
-# {the RFC}[http://www.ietf.org/rfc/rfc4180.txt]. I relax the rules in only one
-# place and that is to make using this library easier. CSV will parse all valid
-# CSV.
-#
-# What you don't want to do is feed CSV invalid data. Because of the way the
-# CSV format works, it's common for a parser to need to read until the end of
-# the file to be sure a field is invalid. This eats a lot of time and memory.
-#
-# Luckily, when working with invalid CSV, Ruby's built-in methods will almost
-# always be superior in every way. For example, parsing non-quoted fields is as
-# easy as:
-#
-# data.split(",")
-#
-# == Questions and/or Comments
-#
-# Feel free to email {James Edward Gray II}[mailto:james@grayproductions.net]
-# with any questions.
-
-require "forwardable"
-require "English"
-require "date"
-require "stringio"
-
-#
-# This class provides a complete interface to CSV files and data. It offers
-# tools to enable you to read and write to and from Strings or IO objects, as
-# needed.
-#
-# == Reading
-#
-# === From a File
-#
-# ==== A Line at a Time
-#
-# CSV.foreach("path/to/file.csv") do |row|
-# # use row here...
-# end
-#
-# ==== All at Once
-#
-# arr_of_arrs = CSV.read("path/to/file.csv")
-#
-# === From a String
-#
-# ==== A Line at a Time
-#
-# CSV.parse("CSV,data,String") do |row|
-# # use row here...
-# end
-#
-# ==== All at Once
-#
-# arr_of_arrs = CSV.parse("CSV,data,String")
-#
-# == Writing
-#
-# === To a File
-#
-# CSV.open("path/to/file.csv", "wb") do |csv|
-# csv << ["row", "of", "CSV", "data"]
-# csv << ["another", "row"]
-# # ...
-# end
-#
-# === To a String
-#
-# csv_string = CSV.generate do |csv|
-# csv << ["row", "of", "CSV", "data"]
-# csv << ["another", "row"]
-# # ...
-# end
-#
-# == Convert a Single Line
-#
-# csv_string = ["CSV", "data"].to_csv # to CSV
-# csv_array = "CSV,String".parse_csv # from CSV
-#
-# == Shortcut Interface
-#
-# CSV { |csv_out| csv_out << %w{my data here} } # to $stdout
-# CSV(csv = "") { |csv_str| csv_str << %w{my data here} } # to a String
-# CSV($stderr) { |csv_err| csv_err << %w{my data here} } # to $stderr
-# CSV($stdin) { |csv_in| csv_in.each { |row| p row } } # from $stdin
-#
-# == Advanced Usage
-#
-# === Wrap an IO Object
-#
-# csv = CSV.new(io, options)
-# # ... read (with gets() or each()) from and write (with <<) to csv here ...
-#
-# == CSV and Character Encodings (M17n or Multilingualization)
-#
-# This new CSV parser is m17n savvy. The parser works in the Encoding of the IO
-# or String object being read from or written to. Your data is never transcoded
-# (unless you ask Ruby to transcode it for you) and will literally be parsed in
-# the Encoding it is in. Thus CSV will return Arrays or Rows of Strings in the
-# Encoding of your data. This is accomplished by transcoding the parser itself
-# into your Encoding.
-#
-# Some transcoding must take place, of course, to accomplish this multiencoding
-# support. For example, <tt>:col_sep</tt>, <tt>:row_sep</tt>, and
-# <tt>:quote_char</tt> must be transcoded to match your data. Hopefully this
-# makes the entire process feel transparent, since CSV's defaults should just
-# magically work for you data. However, you can set these values manually in
-# the target Encoding to avoid the translation.
-#
-# It's also important to note that while all of CSV's core parser is now
-# Encoding agnostic, some features are not. For example, the built-in
-# converters will try to transcode data to UTF-8 before making conversions.
-# Again, you can provide custom converters that are aware of your Encodings to
-# avoid this translation. It's just too hard for me to support native
-# conversions in all of Ruby's Encodings.
-#
-# Anyway, the practical side of this is simple: make sure IO and String objects
-# passed into CSV have the proper Encoding set and everything should just work.
-# CSV methods that allow you to open IO objects (CSV::foreach(), CSV::open(),
-# CSV::read(), and CSV::readlines()) do allow you to specify the Encoding.
-#
-# One minor exception comes when generating CSV into a String with an Encoding
-# that is not ASCII compatible. There's no existing data for CSV to use to
-# prepare itself and thus you will probably need to manually specify the desired
-# Encoding for most of those cases. It will try to guess using the fields in a
-# row of output though, when using CSV::generate_line() or Array#to_csv().
-#
-# I try to point out any other Encoding issues in the documentation of methods
-# as they come up.
-#
-# This has been tested to the best of my ability with all non-"dummy" Encodings
-# Ruby ships with. However, it is brave new code and may have some bugs.
-# Please feel free to {report}[mailto:james@grayproductions.net] any issues you
-# find with it.
-#
-class CSV
- # The version of the installed library.
- VERSION = "2.4.8".freeze
-
- #
- # A CSV::Row is part Array and part Hash. It retains an order for the fields
- # and allows duplicates just as an Array would, but also allows you to access
- # fields by name just as you could if they were in a Hash.
- #
- # All rows returned by CSV will be constructed from this class, if header row
- # processing is activated.
- #
- class Row
- #
- # Construct a new CSV::Row from +headers+ and +fields+, which are expected
- # to be Arrays. If one Array is shorter than the other, it will be padded
- # with +nil+ objects.
- #
- # The optional +header_row+ parameter can be set to +true+ to indicate, via
- # CSV::Row.header_row?() and CSV::Row.field_row?(), that this is a header
- # row. Otherwise, the row is assumes to be a field row.
- #
- # A CSV::Row object supports the following Array methods through delegation:
- #
- # * empty?()
- # * length()
- # * size()
- #
- def initialize(headers, fields, header_row = false)
- @header_row = header_row
- headers.each { |h| h.freeze if h.is_a? String }
-
- # handle extra headers or fields
- @row = if headers.size >= fields.size
- headers.zip(fields)
- else
- fields.zip(headers).map { |pair| pair.reverse! }
- end
- end
-
- # Internal data format used to compare equality.
- attr_reader :row
- protected :row
-
- ### Array Delegation ###
-
- extend Forwardable
- def_delegators :@row, :empty?, :length, :size
-
- # Returns +true+ if this is a header row.
- def header_row?
- @header_row
- end
-
- # Returns +true+ if this is a field row.
- def field_row?
- not header_row?
- end
-
- # Returns the headers of this row.
- def headers
- @row.map { |pair| pair.first }
- end
-
- #
- # :call-seq:
- # field( header )
- # field( header, offset )
- # field( index )
- #
- # This method will return the field value by +header+ or +index+. If a field
- # is not found, +nil+ is returned.
- #
- # When provided, +offset+ ensures that a header match occurs on or later
- # than the +offset+ index. You can use this to find duplicate headers,
- # without resorting to hard-coding exact indices.
- #
- def field(header_or_index, minimum_index = 0)
- # locate the pair
- finder = header_or_index.is_a?(Integer) ? :[] : :assoc
- pair = @row[minimum_index..-1].send(finder, header_or_index)
-
- # return the field if we have a pair
- pair.nil? ? nil : pair.last
- end
- alias_method :[], :field
-
- #
- # :call-seq:
- # fetch( header )
- # fetch( header ) { |row| ... }
- # fetch( header, default )
- #
- # This method will fetch the field value by +header+. It has the same
- # behavior as Hash#fetch: if there is a field with the given +header+, its
- # value is returned. Otherwise, if a block is given, it is yielded the
- # +header+ and its result is returned; if a +default+ is given as the
- # second argument, it is returned; otherwise a KeyError is raised.
- #
- def fetch(header, *varargs)
- raise ArgumentError, "Too many arguments" if varargs.length > 1
- pair = @row.assoc(header)
- if pair
- pair.last
- else
- if block_given?
- yield header
- elsif varargs.empty?
- raise KeyError, "key not found: #{header}"
- else
- varargs.first
- end
- end
- end
-
- # Returns +true+ if there is a field with the given +header+.
- def has_key?(header)
- !!@row.assoc(header)
- end
- alias_method :include?, :has_key?
- alias_method :key?, :has_key?
- alias_method :member?, :has_key?
-
- #
- # :call-seq:
- # []=( header, value )
- # []=( header, offset, value )
- # []=( index, value )
- #
- # Looks up the field by the semantics described in CSV::Row.field() and
- # assigns the +value+.
- #
- # Assigning past the end of the row with an index will set all pairs between
- # to <tt>[nil, nil]</tt>. Assigning to an unused header appends the new
- # pair.
- #
- def []=(*args)
- value = args.pop
-
- if args.first.is_a? Integer
- if @row[args.first].nil? # extending past the end with index
- @row[args.first] = [nil, value]
- @row.map! { |pair| pair.nil? ? [nil, nil] : pair }
- else # normal index assignment
- @row[args.first][1] = value
- end
- else
- index = index(*args)
- if index.nil? # appending a field
- self << [args.first, value]
- else # normal header assignment
- @row[index][1] = value
- end
- end
- end
-
- #
- # :call-seq:
- # <<( field )
- # <<( header_and_field_array )
- # <<( header_and_field_hash )
- #
- # If a two-element Array is provided, it is assumed to be a header and field
- # and the pair is appended. A Hash works the same way with the key being
- # the header and the value being the field. Anything else is assumed to be
- # a lone field which is appended with a +nil+ header.
- #
- # This method returns the row for chaining.
- #
- def <<(arg)
- if arg.is_a?(Array) and arg.size == 2 # appending a header and name
- @row << arg
- elsif arg.is_a?(Hash) # append header and name pairs
- arg.each { |pair| @row << pair }
- else # append field value
- @row << [nil, arg]
- end
-
- self # for chaining
- end
-
- #
- # A shortcut for appending multiple fields. Equivalent to:
- #
- # args.each { |arg| csv_row << arg }
- #
- # This method returns the row for chaining.
- #
- def push(*args)
- args.each { |arg| self << arg }
-
- self # for chaining
- end
-
- #
- # :call-seq:
- # delete( header )
- # delete( header, offset )
- # delete( index )
- #
- # Used to remove a pair from the row by +header+ or +index+. The pair is
- # located as described in CSV::Row.field(). The deleted pair is returned,
- # or +nil+ if a pair could not be found.
- #
- def delete(header_or_index, minimum_index = 0)
- if header_or_index.is_a? Integer # by index
- @row.delete_at(header_or_index)
- elsif i = index(header_or_index, minimum_index) # by header
- @row.delete_at(i)
- else
- [ ]
- end
- end
-
- #
- # The provided +block+ is passed a header and field for each pair in the row
- # and expected to return +true+ or +false+, depending on whether the pair
- # should be deleted.
- #
- # This method returns the row for chaining.
- #
- def delete_if(&block)
- @row.delete_if(&block)
-
- self # for chaining
- end
-
- #
- # This method accepts any number of arguments which can be headers, indices,
- # Ranges of either, or two-element Arrays containing a header and offset.
- # Each argument will be replaced with a field lookup as described in
- # CSV::Row.field().
- #
- # If called with no arguments, all fields are returned.
- #
- def fields(*headers_and_or_indices)
- if headers_and_or_indices.empty? # return all fields--no arguments
- @row.map { |pair| pair.last }
- else # or work like values_at()
- headers_and_or_indices.inject(Array.new) do |all, h_or_i|
- all + if h_or_i.is_a? Range
- index_begin = h_or_i.begin.is_a?(Integer) ? h_or_i.begin :
- index(h_or_i.begin)
- index_end = h_or_i.end.is_a?(Integer) ? h_or_i.end :
- index(h_or_i.end)
- new_range = h_or_i.exclude_end? ? (index_begin...index_end) :
- (index_begin..index_end)
- fields.values_at(new_range)
- else
- [field(*Array(h_or_i))]
- end
- end
- end
- end
- alias_method :values_at, :fields
-
- #
- # :call-seq:
- # index( header )
- # index( header, offset )
- #
- # This method will return the index of a field with the provided +header+.
- # The +offset+ can be used to locate duplicate header names, as described in
- # CSV::Row.field().
- #
- def index(header, minimum_index = 0)
- # find the pair
- index = headers[minimum_index..-1].index(header)
- # return the index at the right offset, if we found one
- index.nil? ? nil : index + minimum_index
- end
-
- # Returns +true+ if +name+ is a header for this row, and +false+ otherwise.
- def header?(name)
- headers.include? name
- end
- alias_method :include?, :header?
-
- #
- # Returns +true+ if +data+ matches a field in this row, and +false+
- # otherwise.
- #
- def field?(data)
- fields.include? data
- end
-
- include Enumerable
-
- #
- # Yields each pair of the row as header and field tuples (much like
- # iterating over a Hash).
- #
- # Support for Enumerable.
- #
- # This method returns the row for chaining.
- #
- def each(&block)
- @row.each(&block)
-
- self # for chaining
- end
-
- #
- # Returns +true+ if this row contains the same headers and fields in the
- # same order as +other+.
- #
- def ==(other)
- return @row == other.row if other.is_a? CSV::Row
- @row == other
- end
-
- #
- # Collapses the row into a simple Hash. Be warning that this discards field
- # order and clobbers duplicate fields.
- #
- def to_hash
- # flatten just one level of the internal Array
- Hash[*@row.inject(Array.new) { |ary, pair| ary.push(*pair) }]
- end
-
- #
- # Returns the row as a CSV String. Headers are not used. Equivalent to:
- #
- # csv_row.fields.to_csv( options )
- #
- def to_csv(options = Hash.new)
- fields.to_csv(options)
- end
- alias_method :to_s, :to_csv
-
- # A summary of fields, by header, in an ASCII compatible String.
- def inspect
- str = ["#<", self.class.to_s]
- each do |header, field|
- str << " " << (header.is_a?(Symbol) ? header.to_s : header.inspect) <<
- ":" << field.inspect
- end
- str << ">"
- begin
- str.join('')
- rescue # any encoding error
- str.map do |s|
- e = Encoding::Converter.asciicompat_encoding(s.encoding)
- e ? s.encode(e) : s.force_encoding("ASCII-8BIT")
- end.join('')
- end
- end
- end
-
- #
- # A CSV::Table is a two-dimensional data structure for representing CSV
- # documents. Tables allow you to work with the data by row or column,
- # manipulate the data, and even convert the results back to CSV, if needed.
- #
- # All tables returned by CSV will be constructed from this class, if header
- # row processing is activated.
- #
- class Table
- #
- # Construct a new CSV::Table from +array_of_rows+, which are expected
- # to be CSV::Row objects. All rows are assumed to have the same headers.
- #
- # A CSV::Table object supports the following Array methods through
- # delegation:
- #
- # * empty?()
- # * length()
- # * size()
- #
- def initialize(array_of_rows)
- @table = array_of_rows
- @mode = :col_or_row
- end
-
- # The current access mode for indexing and iteration.
- attr_reader :mode
-
- # Internal data format used to compare equality.
- attr_reader :table
- protected :table
-
- ### Array Delegation ###
-
- extend Forwardable
- def_delegators :@table, :empty?, :length, :size
-
- #
- # Returns a duplicate table object, in column mode. This is handy for
- # chaining in a single call without changing the table mode, but be aware
- # that this method can consume a fair amount of memory for bigger data sets.
- #
- # This method returns the duplicate table for chaining. Don't chain
- # destructive methods (like []=()) this way though, since you are working
- # with a duplicate.
- #
- def by_col
- self.class.new(@table.dup).by_col!
- end
-
- #
- # Switches the mode of this table to column mode. All calls to indexing and
- # iteration methods will work with columns until the mode is changed again.
- #
- # This method returns the table and is safe to chain.
- #
- def by_col!
- @mode = :col
-
- self
- end
-
- #
- # Returns a duplicate table object, in mixed mode. This is handy for
- # chaining in a single call without changing the table mode, but be aware
- # that this method can consume a fair amount of memory for bigger data sets.
- #
- # This method returns the duplicate table for chaining. Don't chain
- # destructive methods (like []=()) this way though, since you are working
- # with a duplicate.
- #
- def by_col_or_row
- self.class.new(@table.dup).by_col_or_row!
- end
-
- #
- # Switches the mode of this table to mixed mode. All calls to indexing and
- # iteration methods will use the default intelligent indexing system until
- # the mode is changed again. In mixed mode an index is assumed to be a row
- # reference while anything else is assumed to be column access by headers.
- #
- # This method returns the table and is safe to chain.
- #
- def by_col_or_row!
- @mode = :col_or_row
-
- self
- end
-
- #
- # Returns a duplicate table object, in row mode. This is handy for chaining
- # in a single call without changing the table mode, but be aware that this
- # method can consume a fair amount of memory for bigger data sets.
- #
- # This method returns the duplicate table for chaining. Don't chain
- # destructive methods (like []=()) this way though, since you are working
- # with a duplicate.
- #
- def by_row
- self.class.new(@table.dup).by_row!
- end
-
- #
- # Switches the mode of this table to row mode. All calls to indexing and
- # iteration methods will work with rows until the mode is changed again.
- #
- # This method returns the table and is safe to chain.
- #
- def by_row!
- @mode = :row
-
- self
- end
-
- #
- # Returns the headers for the first row of this table (assumed to match all
- # other rows). An empty Array is returned for empty tables.
- #
- def headers
- if @table.empty?
- Array.new
- else
- @table.first.headers
- end
- end
-
- #
- # In the default mixed mode, this method returns rows for index access and
- # columns for header access. You can force the index association by first
- # calling by_col!() or by_row!().
- #
- # Columns are returned as an Array of values. Altering that Array has no
- # effect on the table.
- #
- def [](index_or_header)
- if @mode == :row or # by index
- (@mode == :col_or_row and index_or_header.is_a? Integer)
- @table[index_or_header]
- else # by header
- @table.map { |row| row[index_or_header] }
- end
- end
-
- #
- # In the default mixed mode, this method assigns rows for index access and
- # columns for header access. You can force the index association by first
- # calling by_col!() or by_row!().
- #
- # Rows may be set to an Array of values (which will inherit the table's
- # headers()) or a CSV::Row.
- #
- # Columns may be set to a single value, which is copied to each row of the
- # column, or an Array of values. Arrays of values are assigned to rows top
- # to bottom in row major order. Excess values are ignored and if the Array
- # does not have a value for each row the extra rows will receive a +nil+.
- #
- # Assigning to an existing column or row clobbers the data. Assigning to
- # new columns creates them at the right end of the table.
- #
- def []=(index_or_header, value)
- if @mode == :row or # by index
- (@mode == :col_or_row and index_or_header.is_a? Integer)
- if value.is_a? Array
- @table[index_or_header] = Row.new(headers, value)
- else
- @table[index_or_header] = value
- end
- else # set column
- if value.is_a? Array # multiple values
- @table.each_with_index do |row, i|
- if row.header_row?
- row[index_or_header] = index_or_header
- else
- row[index_or_header] = value[i]
- end
- end
- else # repeated value
- @table.each do |row|
- if row.header_row?
- row[index_or_header] = index_or_header
- else
- row[index_or_header] = value
- end
- end
- end
- end
- end
-
- #
- # The mixed mode default is to treat a list of indices as row access,
- # returning the rows indicated. Anything else is considered columnar
- # access. For columnar access, the return set has an Array for each row
- # with the values indicated by the headers in each Array. You can force
- # column or row mode using by_col!() or by_row!().
- #
- # You cannot mix column and row access.
- #
- def values_at(*indices_or_headers)
- if @mode == :row or # by indices
- ( @mode == :col_or_row and indices_or_headers.all? do |index|
- index.is_a?(Integer) or
- ( index.is_a?(Range) and
- index.first.is_a?(Integer) and
- index.last.is_a?(Integer) )
- end )
- @table.values_at(*indices_or_headers)
- else # by headers
- @table.map { |row| row.values_at(*indices_or_headers) }
- end
- end
-
- #
- # Adds a new row to the bottom end of this table. You can provide an Array,
- # which will be converted to a CSV::Row (inheriting the table's headers()),
- # or a CSV::Row.
- #
- # This method returns the table for chaining.
- #
- def <<(row_or_array)
- if row_or_array.is_a? Array # append Array
- @table << Row.new(headers, row_or_array)
- else # append Row
- @table << row_or_array
- end
-
- self # for chaining
- end
-
- #
- # A shortcut for appending multiple rows. Equivalent to:
- #
- # rows.each { |row| self << row }
- #
- # This method returns the table for chaining.
- #
- def push(*rows)
- rows.each { |row| self << row }
-
- self # for chaining
- end
-
- #
- # Removes and returns the indicated column or row. In the default mixed
- # mode indices refer to rows and everything else is assumed to be a column
- # header. Use by_col!() or by_row!() to force the lookup.
- #
- def delete(index_or_header)
- if @mode == :row or # by index
- (@mode == :col_or_row and index_or_header.is_a? Integer)
- @table.delete_at(index_or_header)
- else # by header
- @table.map { |row| row.delete(index_or_header).last }
- end
- end
-
- #
- # Removes any column or row for which the block returns +true+. In the
- # default mixed mode or row mode, iteration is the standard row major
- # walking of rows. In column mode, iteration will +yield+ two element
- # tuples containing the column name and an Array of values for that column.
- #
- # This method returns the table for chaining.
- #
- def delete_if(&block)
- if @mode == :row or @mode == :col_or_row # by index
- @table.delete_if(&block)
- else # by header
- to_delete = Array.new
- headers.each_with_index do |header, i|
- to_delete << header if block[[header, self[header]]]
- end
- to_delete.map { |header| delete(header) }
- end
-
- self # for chaining
- end
-
- include Enumerable
-
- #
- # In the default mixed mode or row mode, iteration is the standard row major
- # walking of rows. In column mode, iteration will +yield+ two element
- # tuples containing the column name and an Array of values for that column.
- #
- # This method returns the table for chaining.
- #
- def each(&block)
- if @mode == :col
- headers.each { |header| block[[header, self[header]]] }
- else
- @table.each(&block)
- end
-
- self # for chaining
- end
-
- # Returns +true+ if all rows of this table ==() +other+'s rows.
- def ==(other)
- @table == other.table
- end
-
- #
- # Returns the table as an Array of Arrays. Headers will be the first row,
- # then all of the field rows will follow.
- #
- def to_a
- @table.inject([headers]) do |array, row|
- if row.header_row?
- array
- else
- array + [row.fields]
- end
- end
- end
-
- #
- # Returns the table as a complete CSV String. Headers will be listed first,
- # then all of the field rows.
- #
- # This method assumes you want the Table.headers(), unless you explicitly
- # pass <tt>:write_headers => false</tt>.
- #
- def to_csv(options = Hash.new)
- wh = options.fetch(:write_headers, true)
- @table.inject(wh ? [headers.to_csv(options)] : [ ]) do |rows, row|
- if row.header_row?
- rows
- else
- rows + [row.fields.to_csv(options)]
- end
- end.join('')
- end
- alias_method :to_s, :to_csv
-
- # Shows the mode and size of this table in a US-ASCII String.
- def inspect
- "#<#{self.class} mode:#{@mode} row_count:#{to_a.size}>".encode("US-ASCII")
- end
- end
-
- # The error thrown when the parser encounters illegal CSV formatting.
- class MalformedCSVError < RuntimeError; end
-
- #
- # A FieldInfo Struct contains details about a field's position in the data
- # source it was read from. CSV will pass this Struct to some blocks that make
- # decisions based on field structure. See CSV.convert_fields() for an
- # example.
- #
- # <b><tt>index</tt></b>:: The zero-based index of the field in its row.
- # <b><tt>line</tt></b>:: The line of the data source this row is from.
- # <b><tt>header</tt></b>:: The header for the column, when available.
- #
- FieldInfo = Struct.new(:index, :line, :header)
-
- # A Regexp used to find and convert some common Date formats.
- DateMatcher = / \A(?: (\w+,?\s+)?\w+\s+\d{1,2},?\s+\d{2,4} |
- \d{4}-\d{2}-\d{2} )\z /x
- # A Regexp used to find and convert some common DateTime formats.
- DateTimeMatcher =
- / \A(?: (\w+,?\s+)?\w+\s+\d{1,2}\s+\d{1,2}:\d{1,2}:\d{1,2},?\s+\d{2,4} |
- \d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2} )\z /x
-
- # The encoding used by all converters.
- ConverterEncoding = Encoding.find("UTF-8")
-
- #
- # This Hash holds the built-in converters of CSV that can be accessed by name.
- # You can select Converters with CSV.convert() or through the +options+ Hash
- # passed to CSV::new().
- #
- # <b><tt>:integer</tt></b>:: Converts any field Integer() accepts.
- # <b><tt>:float</tt></b>:: Converts any field Float() accepts.
- # <b><tt>:numeric</tt></b>:: A combination of <tt>:integer</tt>
- # and <tt>:float</tt>.
- # <b><tt>:date</tt></b>:: Converts any field Date::parse() accepts.
- # <b><tt>:date_time</tt></b>:: Converts any field DateTime::parse() accepts.
- # <b><tt>:all</tt></b>:: All built-in converters. A combination of
- # <tt>:date_time</tt> and <tt>:numeric</tt>.
- #
- # All built-in converters transcode field data to UTF-8 before attempting a
- # conversion. If your data cannot be transcoded to UTF-8 the conversion will
- # fail and the field will remain unchanged.
- #
- # This Hash is intentionally left unfrozen and users should feel free to add
- # values to it that can be accessed by all CSV objects.
- #
- # To add a combo field, the value should be an Array of names. Combo fields
- # can be nested with other combo fields.
- #
- Converters = { integer: lambda { |f|
- Integer(f.encode(ConverterEncoding)) rescue f
- },
- float: lambda { |f|
- Float(f.encode(ConverterEncoding)) rescue f
- },
- numeric: [:integer, :float],
- date: lambda { |f|
- begin
- e = f.encode(ConverterEncoding)
- e =~ DateMatcher ? Date.parse(e) : f
- rescue # encoding conversion or date parse errors
- f
- end
- },
- date_time: lambda { |f|
- begin
- e = f.encode(ConverterEncoding)
- e =~ DateTimeMatcher ? DateTime.parse(e) : f
- rescue # encoding conversion or date parse errors
- f
- end
- },
- all: [:date_time, :numeric] }
-
- #
- # This Hash holds the built-in header converters of CSV that can be accessed
- # by name. You can select HeaderConverters with CSV.header_convert() or
- # through the +options+ Hash passed to CSV::new().
- #
- # <b><tt>:downcase</tt></b>:: Calls downcase() on the header String.
- # <b><tt>:symbol</tt></b>:: The header String is downcased, spaces are
- # replaced with underscores, non-word characters
- # are dropped, and finally to_sym() is called.
- #
- # All built-in header converters transcode header data to UTF-8 before
- # attempting a conversion. If your data cannot be transcoded to UTF-8 the
- # conversion will fail and the header will remain unchanged.
- #
- # This Hash is intentionally left unfrozen and users should feel free to add
- # values to it that can be accessed by all CSV objects.
- #
- # To add a combo field, the value should be an Array of names. Combo fields
- # can be nested with other combo fields.
- #
- HeaderConverters = {
- downcase: lambda { |h| h.encode(ConverterEncoding).downcase },
- symbol: lambda { |h|
- h.encode(ConverterEncoding).downcase.strip.gsub(/\s+/, "_").
- gsub(/\W+/, "").to_sym
- }
- }
-
- #
- # The options used when no overrides are given by calling code. They are:
- #
- # <b><tt>:col_sep</tt></b>:: <tt>","</tt>
- # <b><tt>:row_sep</tt></b>:: <tt>:auto</tt>
- # <b><tt>:quote_char</tt></b>:: <tt>'"'</tt>
- # <b><tt>:field_size_limit</tt></b>:: +nil+
- # <b><tt>:converters</tt></b>:: +nil+
- # <b><tt>:unconverted_fields</tt></b>:: +nil+
- # <b><tt>:headers</tt></b>:: +false+
- # <b><tt>:return_headers</tt></b>:: +false+
- # <b><tt>:header_converters</tt></b>:: +nil+
- # <b><tt>:skip_blanks</tt></b>:: +false+
- # <b><tt>:force_quotes</tt></b>:: +false+
- # <b><tt>:skip_lines</tt></b>:: +nil+
- #
- DEFAULT_OPTIONS = { col_sep: ",",
- row_sep: :auto,
- quote_char: '"',
- field_size_limit: nil,
- converters: nil,
- unconverted_fields: nil,
- headers: false,
- return_headers: false,
- header_converters: nil,
- skip_blanks: false,
- force_quotes: false,
- skip_lines: nil }.freeze
-
- #
- # This method will return a CSV instance, just like CSV::new(), but the
- # instance will be cached and returned for all future calls to this method for
- # the same +data+ object (tested by Object#object_id()) with the same
- # +options+.
- #
- # If a block is given, the instance is passed to the block and the return
- # value becomes the return value of the block.
- #
- def self.instance(data = $stdout, options = Hash.new)
- # create a _signature_ for this method call, data object and options
- sig = [data.object_id] +
- options.values_at(*DEFAULT_OPTIONS.keys.sort_by { |sym| sym.to_s })
-
- # fetch or create the instance for this signature
- @@instances ||= Hash.new
- instance = (@@instances[sig] ||= new(data, options))
-
- if block_given?
- yield instance # run block, if given, returning result
- else
- instance # or return the instance
- end
- end
-
- #
- # :call-seq:
- # filter( options = Hash.new ) { |row| ... }
- # filter( input, options = Hash.new ) { |row| ... }
- # filter( input, output, options = Hash.new ) { |row| ... }
- #
- # This method is a convenience for building Unix-like filters for CSV data.
- # Each row is yielded to the provided block which can alter it as needed.
- # After the block returns, the row is appended to +output+ altered or not.
- #
- # The +input+ and +output+ arguments can be anything CSV::new() accepts
- # (generally String or IO objects). If not given, they default to
- # <tt>ARGF</tt> and <tt>$stdout</tt>.
- #
- # The +options+ parameter is also filtered down to CSV::new() after some
- # clever key parsing. Any key beginning with <tt>:in_</tt> or
- # <tt>:input_</tt> will have that leading identifier stripped and will only
- # be used in the +options+ Hash for the +input+ object. Keys starting with
- # <tt>:out_</tt> or <tt>:output_</tt> affect only +output+. All other keys
- # are assigned to both objects.
- #
- # The <tt>:output_row_sep</tt> +option+ defaults to
- # <tt>$INPUT_RECORD_SEPARATOR</tt> (<tt>$/</tt>).
- #
- def self.filter(*args)
- # parse options for input, output, or both
- in_options, out_options = Hash.new, {row_sep: $INPUT_RECORD_SEPARATOR}
- if args.last.is_a? Hash
- args.pop.each do |key, value|
- case key.to_s
- when /\Ain(?:put)?_(.+)\Z/
- in_options[$1.to_sym] = value
- when /\Aout(?:put)?_(.+)\Z/
- out_options[$1.to_sym] = value
- else
- in_options[key] = value
- out_options[key] = value
- end
- end
- end
- # build input and output wrappers
- input = new(args.shift || ARGF, in_options)
- output = new(args.shift || $stdout, out_options)
-
- # read, yield, write
- input.each do |row|
- yield row
- output << row
- end
- end
-
- #
- # This method is intended as the primary interface for reading CSV files. You
- # pass a +path+ and any +options+ you wish to set for the read. Each row of
- # file will be passed to the provided +block+ in turn.
- #
- # The +options+ parameter can be anything CSV::new() understands. This method
- # also understands an additional <tt>:encoding</tt> parameter that you can use
- # to specify the Encoding of the data in the file to be read. You must provide
- # this unless your data is in Encoding::default_external(). CSV will use this
- # to determine how to parse the data. You may provide a second Encoding to
- # have the data transcoded as it is read. For example,
- # <tt>encoding: "UTF-32BE:UTF-8"</tt> would read UTF-32BE data from the file
- # but transcode it to UTF-8 before CSV parses it.
- #
- def self.foreach(path, options = Hash.new, &block)
- return to_enum(__method__, path, options) unless block
- open(path, options) do |csv|
- csv.each(&block)
- end
- end
-
- #
- # :call-seq:
- # generate( str, options = Hash.new ) { |csv| ... }
- # generate( options = Hash.new ) { |csv| ... }
- #
- # This method wraps a String you provide, or an empty default String, in a
- # CSV object which is passed to the provided block. You can use the block to
- # append CSV rows to the String and when the block exits, the final String
- # will be returned.
- #
- # Note that a passed String *is* modified by this method. Call dup() before
- # passing if you need a new String.
- #
- # The +options+ parameter can be anything CSV::new() understands. This method
- # understands an additional <tt>:encoding</tt> parameter when not passed a
- # String to set the base Encoding for the output. CSV needs this hint if you
- # plan to output non-ASCII compatible data.
- #
- def self.generate(*args)
- # add a default empty String, if none was given
- if args.first.is_a? String
- io = StringIO.new(args.shift)
- io.seek(0, IO::SEEK_END)
- args.unshift(io)
- else
- encoding = args[-1][:encoding] if args.last.is_a?(Hash)
- str = ""
- str.force_encoding(encoding) if encoding
- args.unshift(str)
- end
- csv = new(*args) # wrap
- yield csv # yield for appending
- csv.string # return final String
- end
-
- #
- # This method is a shortcut for converting a single row (Array) into a CSV
- # String.
- #
- # The +options+ parameter can be anything CSV::new() understands. This method
- # understands an additional <tt>:encoding</tt> parameter to set the base
- # Encoding for the output. This method will try to guess your Encoding from
- # the first non-+nil+ field in +row+, if possible, but you may need to use
- # this parameter as a backup plan.
- #
- # The <tt>:row_sep</tt> +option+ defaults to <tt>$INPUT_RECORD_SEPARATOR</tt>
- # (<tt>$/</tt>) when calling this method.
- #
- def self.generate_line(row, options = Hash.new)
- options = {row_sep: $INPUT_RECORD_SEPARATOR}.merge(options)
- encoding = options.delete(:encoding)
- str = ""
- if encoding
- str.force_encoding(encoding)
- elsif field = row.find { |f| not f.nil? }
- str.force_encoding(String(field).encoding)
- end
- (new(str, options) << row).string
- end
-
- #
- # :call-seq:
- # open( filename, mode = "rb", options = Hash.new ) { |faster_csv| ... }
- # open( filename, options = Hash.new ) { |faster_csv| ... }
- # open( filename, mode = "rb", options = Hash.new )
- # open( filename, options = Hash.new )
- #
- # This method opens an IO object, and wraps that with CSV. This is intended
- # as the primary interface for writing a CSV file.
- #
- # You must pass a +filename+ and may optionally add a +mode+ for Ruby's
- # open(). You may also pass an optional Hash containing any +options+
- # CSV::new() understands as the final argument.
- #
- # This method works like Ruby's open() call, in that it will pass a CSV object
- # to a provided block and close it when the block terminates, or it will
- # return the CSV object when no block is provided. (*Note*: This is different
- # from the Ruby 1.8 CSV library which passed rows to the block. Use
- # CSV::foreach() for that behavior.)
- #
- # You must provide a +mode+ with an embedded Encoding designator unless your
- # data is in Encoding::default_external(). CSV will check the Encoding of the
- # underlying IO object (set by the +mode+ you pass) to determine how to parse
- # the data. You may provide a second Encoding to have the data transcoded as
- # it is read just as you can with a normal call to IO::open(). For example,
- # <tt>"rb:UTF-32BE:UTF-8"</tt> would read UTF-32BE data from the file but
- # transcode it to UTF-8 before CSV parses it.
- #
- # An opened CSV object will delegate to many IO methods for convenience. You
- # may call:
- #
- # * binmode()
- # * binmode?()
- # * close()
- # * close_read()
- # * close_write()
- # * closed?()
- # * eof()
- # * eof?()
- # * external_encoding()
- # * fcntl()
- # * fileno()
- # * flock()
- # * flush()
- # * fsync()
- # * internal_encoding()
- # * ioctl()
- # * isatty()
- # * path()
- # * pid()
- # * pos()
- # * pos=()
- # * reopen()
- # * seek()
- # * stat()
- # * sync()
- # * sync=()
- # * tell()
- # * to_i()
- # * to_io()
- # * truncate()
- # * tty?()
- #
- def self.open(*args)
- # find the +options+ Hash
- options = if args.last.is_a? Hash then args.pop else Hash.new end
- # wrap a File opened with the remaining +args+ with no newline
- # decorator
- file_opts = {universal_newline: false}.merge(options)
- begin
- f = File.open(*args, file_opts)
- rescue ArgumentError => e
- raise unless /needs binmode/ =~ e.message and args.size == 1
- args << "rb"
- file_opts = {encoding: Encoding.default_external}.merge(file_opts)
- retry
- end
- begin
- csv = new(f, options)
- rescue Exception
- f.close
- raise
- end
-
- # handle blocks like Ruby's open(), not like the CSV library
- if block_given?
- begin
- yield csv
- ensure
- csv.close
- end
- else
- csv
- end
- end
-
- #
- # :call-seq:
- # parse( str, options = Hash.new ) { |row| ... }
- # parse( str, options = Hash.new )
- #
- # This method can be used to easily parse CSV out of a String. You may either
- # provide a +block+ which will be called with each row of the String in turn,
- # or just use the returned Array of Arrays (when no +block+ is given).
- #
- # You pass your +str+ to read from, and an optional +options+ Hash containing
- # anything CSV::new() understands.
- #
- def self.parse(*args, &block)
- csv = new(*args)
- if block.nil? # slurp contents, if no block is given
- begin
- csv.read
- ensure
- csv.close
- end
- else # or pass each row to a provided block
- csv.each(&block)
- end
- end
-
- #
- # This method is a shortcut for converting a single line of a CSV String into
- # an Array. Note that if +line+ contains multiple rows, anything beyond the
- # first row is ignored.
- #
- # The +options+ parameter can be anything CSV::new() understands.
- #
- def self.parse_line(line, options = Hash.new)
- new(line, options).shift
- end
-
- #
- # Use to slurp a CSV file into an Array of Arrays. Pass the +path+ to the
- # file and any +options+ CSV::new() understands. This method also understands
- # an additional <tt>:encoding</tt> parameter that you can use to specify the
- # Encoding of the data in the file to be read. You must provide this unless
- # your data is in Encoding::default_external(). CSV will use this to determine
- # how to parse the data. You may provide a second Encoding to have the data
- # transcoded as it is read. For example,
- # <tt>encoding: "UTF-32BE:UTF-8"</tt> would read UTF-32BE data from the file
- # but transcode it to UTF-8 before CSV parses it.
- #
- def self.read(path, *options)
- open(path, *options) { |csv| csv.read }
- end
-
- # Alias for CSV::read().
- def self.readlines(*args)
- read(*args)
- end
-
- #
- # A shortcut for:
- #
- # CSV.read( path, { headers: true,
- # converters: :numeric,
- # header_converters: :symbol }.merge(options) )
- #
- def self.table(path, options = Hash.new)
- read( path, { headers: true,
- converters: :numeric,
- header_converters: :symbol }.merge(options) )
- end
-
- #
- # This constructor will wrap either a String or IO object passed in +data+ for
- # reading and/or writing. In addition to the CSV instance methods, several IO
- # methods are delegated. (See CSV::open() for a complete list.) If you pass
- # a String for +data+, you can later retrieve it (after writing to it, for
- # example) with CSV.string().
- #
- # Note that a wrapped String will be positioned at at the beginning (for
- # reading). If you want it at the end (for writing), use CSV::generate().
- # If you want any other positioning, pass a preset StringIO object instead.
- #
- # You may set any reading and/or writing preferences in the +options+ Hash.
- # Available options are:
- #
- # <b><tt>:col_sep</tt></b>:: The String placed between each field.
- # This String will be transcoded into
- # the data's Encoding before parsing.
- # <b><tt>:row_sep</tt></b>:: The String appended to the end of each
- # row. This can be set to the special
- # <tt>:auto</tt> setting, which requests
- # that CSV automatically discover this
- # from the data. Auto-discovery reads
- # ahead in the data looking for the next
- # <tt>"\r\n"</tt>, <tt>"\n"</tt>, or
- # <tt>"\r"</tt> sequence. A sequence
- # will be selected even if it occurs in
- # a quoted field, assuming that you
- # would have the same line endings
- # there. If none of those sequences is
- # found, +data+ is <tt>ARGF</tt>,
- # <tt>STDIN</tt>, <tt>STDOUT</tt>, or
- # <tt>STDERR</tt>, or the stream is only
- # available for output, the default
- # <tt>$INPUT_RECORD_SEPARATOR</tt>
- # (<tt>$/</tt>) is used. Obviously,
- # discovery takes a little time. Set
- # manually if speed is important. Also
- # note that IO objects should be opened
- # in binary mode on Windows if this
- # feature will be used as the
- # line-ending translation can cause
- # problems with resetting the document
- # position to where it was before the
- # read ahead. This String will be
- # transcoded into the data's Encoding
- # before parsing.
- # <b><tt>:quote_char</tt></b>:: The character used to quote fields.
- # This has to be a single character
- # String. This is useful for
- # application that incorrectly use
- # <tt>'</tt> as the quote character
- # instead of the correct <tt>"</tt>.
- # CSV will always consider a double
- # sequence of this character to be an
- # escaped quote. This String will be
- # transcoded into the data's Encoding
- # before parsing.
- # <b><tt>:field_size_limit</tt></b>:: This is a maximum size CSV will read
- # ahead looking for the closing quote
- # for a field. (In truth, it reads to
- # the first line ending beyond this
- # size.) If a quote cannot be found
- # within the limit CSV will raise a
- # MalformedCSVError, assuming the data
- # is faulty. You can use this limit to
- # prevent what are effectively DoS
- # attacks on the parser. However, this
- # limit can cause a legitimate parse to
- # fail and thus is set to +nil+, or off,
- # by default.
- # <b><tt>:converters</tt></b>:: An Array of names from the Converters
- # Hash and/or lambdas that handle custom
- # conversion. A single converter
- # doesn't have to be in an Array. All
- # built-in converters try to transcode
- # fields to UTF-8 before converting.
- # The conversion will fail if the data
- # cannot be transcoded, leaving the
- # field unchanged.
- # <b><tt>:unconverted_fields</tt></b>:: If set to +true+, an
- # unconverted_fields() method will be
- # added to all returned rows (Array or
- # CSV::Row) that will return the fields
- # as they were before conversion. Note
- # that <tt>:headers</tt> supplied by
- # Array or String were not fields of the
- # document and thus will have an empty
- # Array attached.
- # <b><tt>:headers</tt></b>:: If set to <tt>:first_row</tt> or
- # +true+, the initial row of the CSV
- # file will be treated as a row of
- # headers. If set to an Array, the
- # contents will be used as the headers.
- # If set to a String, the String is run
- # through a call of CSV::parse_line()
- # with the same <tt>:col_sep</tt>,
- # <tt>:row_sep</tt>, and
- # <tt>:quote_char</tt> as this instance
- # to produce an Array of headers. This
- # setting causes CSV#shift() to return
- # rows as CSV::Row objects instead of
- # Arrays and CSV#read() to return
- # CSV::Table objects instead of an Array
- # of Arrays.
- # <b><tt>:return_headers</tt></b>:: When +false+, header rows are silently
- # swallowed. If set to +true+, header
- # rows are returned in a CSV::Row object
- # with identical headers and
- # fields (save that the fields do not go
- # through the converters).
- # <b><tt>:write_headers</tt></b>:: When +true+ and <tt>:headers</tt> is
- # set, a header row will be added to the
- # output.
- # <b><tt>:header_converters</tt></b>:: Identical in functionality to
- # <tt>:converters</tt> save that the
- # conversions are only made to header
- # rows. All built-in converters try to
- # transcode headers to UTF-8 before
- # converting. The conversion will fail
- # if the data cannot be transcoded,
- # leaving the header unchanged.
- # <b><tt>:skip_blanks</tt></b>:: When set to a +true+ value, CSV will
- # skip over any empty rows. Note that
- # this setting will not skip rows that
- # contain column separators, even if
- # the rows contain no actual data. If
- # you want to skip rows that contain
- # separators but no content, consider
- # using <tt>:skip_lines</tt>, or
- # inspecting fields.compact.empty? on
- # each row.
- # <b><tt>:force_quotes</tt></b>:: When set to a +true+ value, CSV will
- # quote all CSV fields it creates.
- # <b><tt>:skip_lines</tt></b>:: When set to an object responding to
- # <tt>match</tt>, every line matching
- # it is considered a comment and ignored
- # during parsing. When set to a String,
- # it is first converted to a Regexp.
- # When set to +nil+ no line is considered
- # a comment. If the passed object does
- # not respond to <tt>match</tt>,
- # <tt>ArgumentError</tt> is thrown.
- #
- # See CSV::DEFAULT_OPTIONS for the default settings.
- #
- # Options cannot be overridden in the instance methods for performance reasons,
- # so be sure to set what you want here.
- #
- def initialize(data, options = Hash.new)
- if data.nil?
- raise ArgumentError.new("Cannot parse nil as CSV")
- end
-
- # build the options for this read/write
- options = DEFAULT_OPTIONS.merge(options)
-
- # create the IO object we will read from
- @io = data.is_a?(String) ? StringIO.new(data) : data
- # honor the IO encoding if we can, otherwise default to ASCII-8BIT
- @encoding = raw_encoding(nil) ||
- ( if encoding = options.delete(:internal_encoding)
- case encoding
- when Encoding; encoding
- else Encoding.find(encoding)
- end
- end ) ||
- ( case encoding = options.delete(:encoding)
- when Encoding; encoding
- when /\A[^:]+/; Encoding.find($&)
- end ) ||
- Encoding.default_internal || Encoding.default_external
- #
- # prepare for building safe regular expressions in the target encoding,
- # if we can transcode the needed characters
- #
- @re_esc = "\\".encode(@encoding) rescue ""
- @re_chars = /#{%"[-\\]\\[\\.^$?*+{}()|# \r\n\t\f\v]".encode(@encoding)}/
-
- init_separators(options)
- init_parsers(options)
- init_converters(options)
- init_headers(options)
- init_comments(options)
-
- @force_encoding = !!(encoding || options.delete(:encoding))
- options.delete(:internal_encoding)
- options.delete(:external_encoding)
- unless options.empty?
- raise ArgumentError, "Unknown options: #{options.keys.join(', ')}."
- end
-
- # track our own lineno since IO gets confused about line-ends is CSV fields
- @lineno = 0
- end
-
- #
- # The encoded <tt>:col_sep</tt> used in parsing and writing. See CSV::new
- # for details.
- #
- attr_reader :col_sep
- #
- # The encoded <tt>:row_sep</tt> used in parsing and writing. See CSV::new
- # for details.
- #
- attr_reader :row_sep
- #
- # The encoded <tt>:quote_char</tt> used in parsing and writing. See CSV::new
- # for details.
- #
- attr_reader :quote_char
- # The limit for field size, if any. See CSV::new for details.
- attr_reader :field_size_limit
-
- # The regex marking a line as a comment. See CSV::new for details
- attr_reader :skip_lines
-
- #
- # Returns the current list of converters in effect. See CSV::new for details.
- # Built-in converters will be returned by name, while others will be returned
- # as is.
- #
- def converters
- @converters.map do |converter|
- name = Converters.rassoc(converter)
- name ? name.first : converter
- end
- end
- #
- # Returns +true+ if unconverted_fields() to parsed results. See CSV::new
- # for details.
- #
- def unconverted_fields?() @unconverted_fields end
- #
- # Returns +nil+ if headers will not be used, +true+ if they will but have not
- # yet been read, or the actual headers after they have been read. See
- # CSV::new for details.
- #
- def headers
- @headers || true if @use_headers
- end
- #
- # Returns +true+ if headers will be returned as a row of results.
- # See CSV::new for details.
- #
- def return_headers?() @return_headers end
- # Returns +true+ if headers are written in output. See CSV::new for details.
- def write_headers?() @write_headers end
- #
- # Returns the current list of converters in effect for headers. See CSV::new
- # for details. Built-in converters will be returned by name, while others
- # will be returned as is.
- #
- def header_converters
- @header_converters.map do |converter|
- name = HeaderConverters.rassoc(converter)
- name ? name.first : converter
- end
- end
- #
- # Returns +true+ blank lines are skipped by the parser. See CSV::new
- # for details.
- #
- def skip_blanks?() @skip_blanks end
- # Returns +true+ if all output fields are quoted. See CSV::new for details.
- def force_quotes?() @force_quotes end
-
- #
- # The Encoding CSV is parsing or writing in. This will be the Encoding you
- # receive parsed data in and/or the Encoding data will be written in.
- #
- attr_reader :encoding
-
- #
- # The line number of the last row read from this file. Fields with nested
- # line-end characters will not affect this count.
- #
- attr_reader :lineno
-
- ### IO and StringIO Delegation ###
-
- extend Forwardable
- def_delegators :@io, :binmode, :binmode?, :close, :close_read, :close_write,
- :closed?, :eof, :eof?, :external_encoding, :fcntl,
- :fileno, :flock, :flush, :fsync, :internal_encoding,
- :ioctl, :isatty, :path, :pid, :pos, :pos=, :reopen,
- :seek, :stat, :string, :sync, :sync=, :tell, :to_i,
- :to_io, :truncate, :tty?
-
- # Rewinds the underlying IO object and resets CSV's lineno() counter.
- def rewind
- @headers = nil
- @lineno = 0
-
- @io.rewind
- end
-
- ### End Delegation ###
-
- #
- # The primary write method for wrapped Strings and IOs, +row+ (an Array or
- # CSV::Row) is converted to CSV and appended to the data source. When a
- # CSV::Row is passed, only the row's fields() are appended to the output.
- #
- # The data source must be open for writing.
- #
- def <<(row)
- # make sure headers have been assigned
- if header_row? and [Array, String].include? @use_headers.class
- parse_headers # won't read data for Array or String
- self << @headers if @write_headers
- end
-
- # handle CSV::Row objects and Hashes
- row = case row
- when self.class::Row then row.fields
- when Hash then @headers.map { |header| row[header] }
- else row
- end
-
- @headers = row if header_row?
- @lineno += 1
-
- output = row.map(&@quote).join(@col_sep) + @row_sep # quote and separate
- if @io.is_a?(StringIO) and
- output.encoding != (encoding = raw_encoding)
- if @force_encoding
- output = output.encode(encoding)
- elsif (compatible_encoding = Encoding.compatible?(@io.string, output))
- @io.set_encoding(compatible_encoding)
- @io.seek(0, IO::SEEK_END)
- end
- end
- @io << output
-
- self # for chaining
- end
- alias_method :add_row, :<<
- alias_method :puts, :<<
-
- #
- # :call-seq:
- # convert( name )
- # convert { |field| ... }
- # convert { |field, field_info| ... }
- #
- # You can use this method to install a CSV::Converters built-in, or provide a
- # block that handles a custom conversion.
- #
- # If you provide a block that takes one argument, it will be passed the field
- # and is expected to return the converted value or the field itself. If your
- # block takes two arguments, it will also be passed a CSV::FieldInfo Struct,
- # containing details about the field. Again, the block should return a
- # converted field or the field itself.
- #
- def convert(name = nil, &converter)
- add_converter(:converters, self.class::Converters, name, &converter)
- end
-
- #
- # :call-seq:
- # header_convert( name )
- # header_convert { |field| ... }
- # header_convert { |field, field_info| ... }
- #
- # Identical to CSV#convert(), but for header rows.
- #
- # Note that this method must be called before header rows are read to have any
- # effect.
- #
- def header_convert(name = nil, &converter)
- add_converter( :header_converters,
- self.class::HeaderConverters,
- name,
- &converter )
- end
-
- include Enumerable
-
- #
- # Yields each row of the data source in turn.
- #
- # Support for Enumerable.
- #
- # The data source must be open for reading.
- #
- def each
- if block_given?
- while row = shift
- yield row
- end
- else
- to_enum
- end
- end
-
- #
- # Slurps the remaining rows and returns an Array of Arrays.
- #
- # The data source must be open for reading.
- #
- def read
- rows = to_a
- if @use_headers
- Table.new(rows)
- else
- rows
- end
- end
- alias_method :readlines, :read
-
- # Returns +true+ if the next row read will be a header row.
- def header_row?
- @use_headers and @headers.nil?
- end
-
- #
- # The primary read method for wrapped Strings and IOs, a single row is pulled
- # from the data source, parsed and returned as an Array of fields (if header
- # rows are not used) or a CSV::Row (when header rows are used).
- #
- # The data source must be open for reading.
- #
- def shift
- #########################################################################
- ### This method is purposefully kept a bit long as simple conditional ###
- ### checks are faster than numerous (expensive) method calls. ###
- #########################################################################
-
- # handle headers not based on document content
- if header_row? and @return_headers and
- [Array, String].include? @use_headers.class
- if @unconverted_fields
- return add_unconverted_fields(parse_headers, Array.new)
- else
- return parse_headers
- end
- end
-
- #
- # it can take multiple calls to <tt>@io.gets()</tt> to get a full line,
- # because of \r and/or \n characters embedded in quoted fields
- #
- in_extended_col = false
- csv = Array.new
-
- loop do
- # add another read to the line
- unless parse = @io.gets(@row_sep)
- return nil
- end
-
- parse.sub!(@parsers[:line_end], "")
-
- if csv.empty?
- #
- # I believe a blank line should be an <tt>Array.new</tt>, not Ruby 1.8
- # CSV's <tt>[nil]</tt>
- #
- if parse.empty?
- @lineno += 1
- if @skip_blanks
- next
- elsif @unconverted_fields
- return add_unconverted_fields(Array.new, Array.new)
- elsif @use_headers
- return self.class::Row.new(Array.new, Array.new)
- else
- return Array.new
- end
- end
- end
-
- next if @skip_lines and @skip_lines.match parse
-
- parts = parse.split(@col_sep, -1)
- if parts.empty?
- if in_extended_col
- csv[-1] << @col_sep # will be replaced with a @row_sep after the parts.each loop
- else
- csv << nil
- end
- end
-
- # This loop is the hot path of csv parsing. Some things may be non-dry
- # for a reason. Make sure to benchmark when refactoring.
- parts.each do |part|
- if in_extended_col
- # If we are continuing a previous column
- if part[-1] == @quote_char && part.count(@quote_char) % 2 != 0
- # extended column ends
- csv.last << part[0..-2]
- if csv.last =~ @parsers[:stray_quote]
- raise MalformedCSVError,
- "Missing or stray quote in line #{lineno + 1}"
- end
- csv.last.gsub!(@quote_char * 2, @quote_char)
- in_extended_col = false
- else
- csv.last << part
- csv.last << @col_sep
- end
- elsif part[0] == @quote_char
- # If we are staring a new quoted column
- if part[-1] != @quote_char || part.count(@quote_char) % 2 != 0
- # start an extended column
- csv << part[1..-1]
- csv.last << @col_sep
- in_extended_col = true
- else
- # regular quoted column
- csv << part[1..-2]
- if csv.last =~ @parsers[:stray_quote]
- raise MalformedCSVError,
- "Missing or stray quote in line #{lineno + 1}"
- end
- csv.last.gsub!(@quote_char * 2, @quote_char)
- end
- elsif part =~ @parsers[:quote_or_nl]
- # Unquoted field with bad characters.
- if part =~ @parsers[:nl_or_lf]
- raise MalformedCSVError, "Unquoted fields do not allow " +
- "\\r or \\n (line #{lineno + 1})."
- else
- raise MalformedCSVError, "Illegal quoting in line #{lineno + 1}."
- end
- else
- # Regular ole unquoted field.
- csv << (part.empty? ? nil : part)
- end
- end
-
- # Replace tacked on @col_sep with @row_sep if we are still in an extended
- # column.
- csv[-1][-1] = @row_sep if in_extended_col
-
- if in_extended_col
- # if we're at eof?(), a quoted field wasn't closed...
- if @io.eof?
- raise MalformedCSVError,
- "Unclosed quoted field on line #{lineno + 1}."
- elsif @field_size_limit and csv.last.size >= @field_size_limit
- raise MalformedCSVError, "Field size exceeded on line #{lineno + 1}."
- end
- # otherwise, we need to loop and pull some more data to complete the row
- else
- @lineno += 1
-
- # save fields unconverted fields, if needed...
- unconverted = csv.dup if @unconverted_fields
-
- # convert fields, if needed...
- csv = convert_fields(csv) unless @use_headers or @converters.empty?
- # parse out header rows and handle CSV::Row conversions...
- csv = parse_headers(csv) if @use_headers
-
- # inject unconverted fields and accessor, if requested...
- if @unconverted_fields and not csv.respond_to? :unconverted_fields
- add_unconverted_fields(csv, unconverted)
- end
-
- # return the results
- break csv
- end
- end
- end
- alias_method :gets, :shift
- alias_method :readline, :shift
-
- #
- # Returns a simplified description of the key CSV attributes in an
- # ASCII compatible String.
- #
- def inspect
- str = ["<#", self.class.to_s, " io_type:"]
- # show type of wrapped IO
- if @io == $stdout then str << "$stdout"
- elsif @io == $stdin then str << "$stdin"
- elsif @io == $stderr then str << "$stderr"
- else str << @io.class.to_s
- end
- # show IO.path(), if available
- if @io.respond_to?(:path) and (p = @io.path)
- str << " io_path:" << p.inspect
- end
- # show encoding
- str << " encoding:" << @encoding.name
- # show other attributes
- %w[ lineno col_sep row_sep
- quote_char skip_blanks ].each do |attr_name|
- if a = instance_variable_get("@#{attr_name}")
- str << " " << attr_name << ":" << a.inspect
- end
- end
- if @use_headers
- str << " headers:" << headers.inspect
- end
- str << ">"
- begin
- str.join('')
- rescue # any encoding error
- str.map do |s|
- e = Encoding::Converter.asciicompat_encoding(s.encoding)
- e ? s.encode(e) : s.force_encoding("ASCII-8BIT")
- end.join('')
- end
- end
-
- private
-
- #
- # Stores the indicated separators for later use.
- #
- # If auto-discovery was requested for <tt>@row_sep</tt>, this method will read
- # ahead in the <tt>@io</tt> and try to find one. +ARGF+, +STDIN+, +STDOUT+,
- # +STDERR+ and any stream open for output only with a default
- # <tt>@row_sep</tt> of <tt>$INPUT_RECORD_SEPARATOR</tt> (<tt>$/</tt>).
- #
- # This method also establishes the quoting rules used for CSV output.
- #
- def init_separators(options)
- # store the selected separators
- @col_sep = options.delete(:col_sep).to_s.encode(@encoding)
- @row_sep = options.delete(:row_sep) # encode after resolving :auto
- @quote_char = options.delete(:quote_char).to_s.encode(@encoding)
-
- if @quote_char.length != 1
- raise ArgumentError, ":quote_char has to be a single character String"
- end
-
- #
- # automatically discover row separator when requested
- # (not fully encoding safe)
- #
- if @row_sep == :auto
- if [ARGF, STDIN, STDOUT, STDERR].include?(@io) or
- (defined?(Zlib) and @io.class == Zlib::GzipWriter)
- @row_sep = $INPUT_RECORD_SEPARATOR
- else
- begin
- #
- # remember where we were (pos() will raise an exception if @io is pipe
- # or not opened for reading)
- #
- saved_pos = @io.pos
- while @row_sep == :auto
- #
- # if we run out of data, it's probably a single line
- # (ensure will set default value)
- #
- break unless sample = @io.gets(nil, 1024)
- # extend sample if we're unsure of the line ending
- if sample.end_with? encode_str("\r")
- sample << (@io.gets(nil, 1) || "")
- end
-
- # try to find a standard separator
- if sample =~ encode_re("\r\n?|\n")
- @row_sep = $&
- break
- end
- end
-
- # tricky seek() clone to work around GzipReader's lack of seek()
- @io.rewind
- # reset back to the remembered position
- while saved_pos > 1024 # avoid loading a lot of data into memory
- @io.read(1024)
- saved_pos -= 1024
- end
- @io.read(saved_pos) if saved_pos.nonzero?
- rescue IOError # not opened for reading
- # do nothing: ensure will set default
- rescue NoMethodError # Zlib::GzipWriter doesn't have some IO methods
- # do nothing: ensure will set default
- rescue SystemCallError # pipe
- # do nothing: ensure will set default
- ensure
- #
- # set default if we failed to detect
- # (stream not opened for reading, a pipe, or a single line of data)
- #
- @row_sep = $INPUT_RECORD_SEPARATOR if @row_sep == :auto
- end
- end
- end
- @row_sep = @row_sep.to_s.encode(@encoding)
-
- # establish quoting rules
- @force_quotes = options.delete(:force_quotes)
- do_quote = lambda do |field|
- field = String(field)
- encoded_quote = @quote_char.encode(field.encoding)
- encoded_quote +
- field.gsub(encoded_quote, encoded_quote * 2) +
- encoded_quote
- end
- quotable_chars = encode_str("\r\n", @col_sep, @quote_char)
- @quote = if @force_quotes
- do_quote
- else
- lambda do |field|
- if field.nil? # represent +nil+ fields as empty unquoted fields
- ""
- else
- field = String(field) # Stringify fields
- # represent empty fields as empty quoted fields
- if field.empty? or
- field.count(quotable_chars).nonzero?
- do_quote.call(field)
- else
- field # unquoted field
- end
- end
- end
- end
- end
-
- # Pre-compiles parsers and stores them by name for access during reads.
- def init_parsers(options)
- # store the parser behaviors
- @skip_blanks = options.delete(:skip_blanks)
- @field_size_limit = options.delete(:field_size_limit)
-
- # prebuild Regexps for faster parsing
- esc_row_sep = escape_re(@row_sep)
- esc_quote = escape_re(@quote_char)
- @parsers = {
- # for detecting parse errors
- quote_or_nl: encode_re("[", esc_quote, "\r\n]"),
- nl_or_lf: encode_re("[\r\n]"),
- stray_quote: encode_re( "[^", esc_quote, "]", esc_quote,
- "[^", esc_quote, "]" ),
- # safer than chomp!()
- line_end: encode_re(esc_row_sep, "\\z"),
- # illegal unquoted characters
- return_newline: encode_str("\r\n")
- }
- end
-
- #
- # Loads any converters requested during construction.
- #
- # If +field_name+ is set <tt>:converters</tt> (the default) field converters
- # are set. When +field_name+ is <tt>:header_converters</tt> header converters
- # are added instead.
- #
- # The <tt>:unconverted_fields</tt> option is also actived for
- # <tt>:converters</tt> calls, if requested.
- #
- def init_converters(options, field_name = :converters)
- if field_name == :converters
- @unconverted_fields = options.delete(:unconverted_fields)
- end
-
- instance_variable_set("@#{field_name}", Array.new)
-
- # find the correct method to add the converters
- convert = method(field_name.to_s.sub(/ers\Z/, ""))
-
- # load converters
- unless options[field_name].nil?
- # allow a single converter not wrapped in an Array
- unless options[field_name].is_a? Array
- options[field_name] = [options[field_name]]
- end
- # load each converter...
- options[field_name].each do |converter|
- if converter.is_a? Proc # custom code block
- convert.call(&converter)
- else # by name
- convert.call(converter)
- end
- end
- end
-
- options.delete(field_name)
- end
-
- # Stores header row settings and loads header converters, if needed.
- def init_headers(options)
- @use_headers = options.delete(:headers)
- @return_headers = options.delete(:return_headers)
- @write_headers = options.delete(:write_headers)
-
- # headers must be delayed until shift(), in case they need a row of content
- @headers = nil
-
- init_converters(options, :header_converters)
- end
-
- # Stores the pattern of comments to skip from the provided options.
- #
- # The pattern must respond to +.match+, else ArgumentError is raised.
- # Strings are converted to a Regexp.
- #
- # See also CSV.new
- def init_comments(options)
- @skip_lines = options.delete(:skip_lines)
- @skip_lines = Regexp.new(@skip_lines) if @skip_lines.is_a? String
- if @skip_lines and not @skip_lines.respond_to?(:match)
- raise ArgumentError, ":skip_lines has to respond to matches"
- end
- end
- #
- # The actual work method for adding converters, used by both CSV.convert() and
- # CSV.header_convert().
- #
- # This method requires the +var_name+ of the instance variable to place the
- # converters in, the +const+ Hash to lookup named converters in, and the
- # normal parameters of the CSV.convert() and CSV.header_convert() methods.
- #
- def add_converter(var_name, const, name = nil, &converter)
- if name.nil? # custom converter
- instance_variable_get("@#{var_name}") << converter
- else # named converter
- combo = const[name]
- case combo
- when Array # combo converter
- combo.each do |converter_name|
- add_converter(var_name, const, converter_name)
- end
- else # individual named converter
- instance_variable_get("@#{var_name}") << combo
- end
- end
- end
-
- #
- # Processes +fields+ with <tt>@converters</tt>, or <tt>@header_converters</tt>
- # if +headers+ is passed as +true+, returning the converted field set. Any
- # converter that changes the field into something other than a String halts
- # the pipeline of conversion for that field. This is primarily an efficiency
- # shortcut.
- #
- def convert_fields(fields, headers = false)
- # see if we are converting headers or fields
- converters = headers ? @header_converters : @converters
-
- fields.map.with_index do |field, index|
- converters.each do |converter|
- break if field.nil?
- field = if converter.arity == 1 # straight field converter
- converter[field]
- else # FieldInfo converter
- header = @use_headers && !headers ? @headers[index] : nil
- converter[field, FieldInfo.new(index, lineno, header)]
- end
- break unless field.is_a? String # short-circuit pipeline for speed
- end
- field # final state of each field, converted or original
- end
- end
-
- #
- # This method is used to turn a finished +row+ into a CSV::Row. Header rows
- # are also dealt with here, either by returning a CSV::Row with identical
- # headers and fields (save that the fields do not go through the converters)
- # or by reading past them to return a field row. Headers are also saved in
- # <tt>@headers</tt> for use in future rows.
- #
- # When +nil+, +row+ is assumed to be a header row not based on an actual row
- # of the stream.
- #
- def parse_headers(row = nil)
- if @headers.nil? # header row
- @headers = case @use_headers # save headers
- # Array of headers
- when Array then @use_headers
- # CSV header String
- when String
- self.class.parse_line( @use_headers,
- col_sep: @col_sep,
- row_sep: @row_sep,
- quote_char: @quote_char )
- # first row is headers
- else row
- end
-
- # prepare converted and unconverted copies
- row = @headers if row.nil?
- @headers = convert_fields(@headers, true)
- @headers.each { |h| h.freeze if h.is_a? String }
-
- if @return_headers # return headers
- return self.class::Row.new(@headers, row, true)
- elsif not [Array, String].include? @use_headers.class # skip to field row
- return shift
- end
- end
-
- self.class::Row.new(@headers, convert_fields(row)) # field row
- end
-
- #
- # This method injects an instance variable <tt>unconverted_fields</tt> into
- # +row+ and an accessor method for +row+ called unconverted_fields(). The
- # variable is set to the contents of +fields+.
- #
- def add_unconverted_fields(row, fields)
- class << row
- attr_reader :unconverted_fields
- end
- row.instance_eval { @unconverted_fields = fields }
- row
- end
-
- #
- # This method is an encoding safe version of Regexp::escape(). It will escape
- # any characters that would change the meaning of a regular expression in the
- # encoding of +str+. Regular expression characters that cannot be transcoded
- # to the target encoding will be skipped and no escaping will be performed if
- # a backslash cannot be transcoded.
- #
- def escape_re(str)
- str.gsub(@re_chars) {|c| @re_esc + c}
- end
-
- #
- # Builds a regular expression in <tt>@encoding</tt>. All +chunks+ will be
- # transcoded to that encoding.
- #
- def encode_re(*chunks)
- Regexp.new(encode_str(*chunks))
- end
-
- #
- # Builds a String in <tt>@encoding</tt>. All +chunks+ will be transcoded to
- # that encoding.
- #
- def encode_str(*chunks)
- chunks.map { |chunk| chunk.encode(@encoding.name) }.join('')
- end
-
- private
-
- #
- # Returns the encoding of the internal IO object or the +default+ if the
- # encoding cannot be determined.
- #
- def raw_encoding(default = Encoding::ASCII_8BIT)
- if @io.respond_to? :internal_encoding
- @io.internal_encoding || @io.external_encoding
- elsif @io.is_a? StringIO
- @io.string.encoding
- elsif @io.respond_to? :encoding
- @io.encoding
- else
- default
- end
- end
-end
-
-# Passes +args+ to CSV::instance.
-#
-# CSV("CSV,data").read
-# #=> [["CSV", "data"]]
-#
-# If a block is given, the instance is passed the block and the return value
-# becomes the return value of the block.
-#
-# CSV("CSV,data") { |c|
-# c.read.any? { |a| a.include?("data") }
-# } #=> true
-#
-# CSV("CSV,data") { |c|
-# c.read.any? { |a| a.include?("zombies") }
-# } #=> false
-#
-def CSV(*args, &block)
- CSV.instance(*args, &block)
-end
-
-class Array # :nodoc:
- # Equivalent to CSV::generate_line(self, options)
- #
- # ["CSV", "data"].to_csv
- # #=> "CSV,data\n"
- def to_csv(options = Hash.new)
- CSV.generate_line(self, options)
- end
-end
-
-class String # :nodoc:
- # Equivalent to CSV::parse_line(self, options)
- #
- # "CSV,data".parse_csv
- # #=> ["CSV", "data"]
- def parse_csv(options = Hash.new)
- CSV.parse_line(self, options)
- end
-end
diff --git a/ruby_2_2/lib/debug.rb b/ruby_2_2/lib/debug.rb
deleted file mode 100644
index fcbf849f0d..0000000000
--- a/ruby_2_2/lib/debug.rb
+++ /dev/null
@@ -1,1087 +0,0 @@
-# Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
-# Copyright (C) 2000 Information-technology Promotion Agency, Japan
-# Copyright (C) 2000-2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
-
-require 'continuation'
-
-if $SAFE > 0
- STDERR.print "-r debug.rb is not available in safe mode\n"
- exit 1
-end
-
-require 'tracer'
-require 'pp'
-
-class Tracer # :nodoc:
- def Tracer.trace_func(*vars)
- Single.trace_func(*vars)
- end
-end
-
-SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__ # :nodoc:
-
-##
-# This library provides debugging functionality to Ruby.
-#
-# To add a debugger to your code, start by requiring +debug+ in your
-# program:
-#
-# def say(word)
-# require 'debug'
-# puts word
-# end
-#
-# This will cause Ruby to interrupt execution and show a prompt when the +say+
-# method is run.
-#
-# Once you're inside the prompt, you can start debugging your program.
-#
-# (rdb:1) p word
-# "hello"
-#
-# == Getting help
-#
-# You can get help at any time by pressing +h+.
-#
-# (rdb:1) h
-# Debugger help v.-0.002b
-# Commands
-# b[reak] [file:|class:]<line|method>
-# b[reak] [class.]<line|method>
-# set breakpoint to some position
-# wat[ch] <expression> set watchpoint to some expression
-# cat[ch] (<exception>|off) set catchpoint to an exception
-# b[reak] list breakpoints
-# cat[ch] show catchpoint
-# del[ete][ nnn] delete some or all breakpoints
-# disp[lay] <expression> add expression into display expression list
-# undisp[lay][ nnn] delete one particular or all display expressions
-# c[ont] run until program ends or hit breakpoint
-# s[tep][ nnn] step (into methods) one line or till line nnn
-# n[ext][ nnn] go over one line or till line nnn
-# w[here] display frames
-# f[rame] alias for where
-# l[ist][ (-|nn-mm)] list program, - lists backwards
-# nn-mm lists given lines
-# up[ nn] move to higher frame
-# down[ nn] move to lower frame
-# fin[ish] return to outer frame
-# tr[ace] (on|off) set trace mode of current thread
-# tr[ace] (on|off) all set trace mode of all threads
-# q[uit] exit from debugger
-# v[ar] g[lobal] show global variables
-# v[ar] l[ocal] show local variables
-# v[ar] i[nstance] <object> show instance variables of object
-# v[ar] c[onst] <object> show constants of object
-# m[ethod] i[nstance] <obj> show methods of object
-# m[ethod] <class|module> show instance methods of class or module
-# th[read] l[ist] list all threads
-# th[read] c[ur[rent]] show current thread
-# th[read] [sw[itch]] <nnn> switch thread context to nnn
-# th[read] stop <nnn> stop thread nnn
-# th[read] resume <nnn> resume thread nnn
-# p expression evaluate expression and print its value
-# h[elp] print this help
-# <everything else> evaluate
-#
-# == Usage
-#
-# The following is a list of common functionalities that the debugger
-# provides.
-#
-# === Navigating through your code
-#
-# In general, a debugger is used to find bugs in your program, which
-# often means pausing execution and inspecting variables at some point
-# in time.
-#
-# Let's look at an example:
-#
-# def my_method(foo)
-# require 'debug'
-# foo = get_foo if foo.nil?
-# raise if foo.nil?
-# end
-#
-# When you run this program, the debugger will kick in just before the
-# +foo+ assignment.
-#
-# (rdb:1) p foo
-# nil
-#
-# In this example, it'd be interesting to move to the next line and
-# inspect the value of +foo+ again. You can do that by pressing +n+:
-#
-# (rdb:1) n # goes to next line
-# (rdb:1) p foo
-# nil
-#
-# You now know that the original value of +foo+ was nil, and that it
-# still was nil after calling +get_foo+.
-#
-# Other useful commands for navigating through your code are:
-#
-# +c+::
-# Runs the program until it either exists or encounters another breakpoint.
-# You usually press +c+ when you are finished debugging your program and
-# want to resume its execution.
-# +s+::
-# Steps into method definition. In the previous example, +s+ would take you
-# inside the method definition of +get_foo+.
-# +r+::
-# Restart the program.
-# +q+::
-# Quit the program.
-#
-# === Inspecting variables
-#
-# You can use the debugger to easily inspect both local and global variables.
-# We've seen how to inspect local variables before:
-#
-# (rdb:1) p my_arg
-# 42
-#
-# You can also pretty print the result of variables or expressions:
-#
-# (rdb:1) pp %w{a very long long array containing many words}
-# ["a",
-# "very",
-# "long",
-# ...
-# ]
-#
-# You can list all local variables with +v l+:
-#
-# (rdb:1) v l
-# foo => "hello"
-#
-# Similarly, you can show all global variables with +v g+:
-#
-# (rdb:1) v g
-# all global variables
-#
-# Finally, you can omit +p+ if you simply want to evaluate a variable or
-# expression
-#
-# (rdb:1) 5**2
-# 25
-#
-# === Going beyond basics
-#
-# Ruby Debug provides more advanced functionalities like switching
-# between threads, setting breakpoints and watch expressions, and more.
-# The full list of commands is available at any time by pressing +h+.
-#
-# == Staying out of trouble
-#
-# Make sure you remove every instance of +require 'debug'+ before
-# shipping your code. Failing to do so may result in your program
-# hanging unpredictably.
-#
-# Debug is not available in safe mode.
-
-class DEBUGGER__
- MUTEX = Mutex.new # :nodoc:
-
- class Context # :nodoc:
- DEBUG_LAST_CMD = []
-
- begin
- require 'readline'
- def readline(prompt, hist)
- Readline::readline(prompt, hist)
- end
- rescue LoadError
- def readline(prompt, hist)
- STDOUT.print prompt
- STDOUT.flush
- line = STDIN.gets
- exit unless line
- line.chomp!
- line
- end
- USE_READLINE = false
- end
-
- def initialize
- if Thread.current == Thread.main
- @stop_next = 1
- else
- @stop_next = 0
- end
- @last_file = nil
- @file = nil
- @line = nil
- @no_step = nil
- @frames = []
- @finish_pos = 0
- @trace = false
- @catch = "StandardError"
- @suspend_next = false
- end
-
- def stop_next(n=1)
- @stop_next = n
- end
-
- def set_suspend
- @suspend_next = true
- end
-
- def clear_suspend
- @suspend_next = false
- end
-
- def suspend_all
- DEBUGGER__.suspend
- end
-
- def resume_all
- DEBUGGER__.resume
- end
-
- def check_suspend
- while MUTEX.synchronize {
- if @suspend_next
- DEBUGGER__.waiting.push Thread.current
- @suspend_next = false
- true
- end
- }
- end
- end
-
- def trace?
- @trace
- end
-
- def set_trace(arg)
- @trace = arg
- end
-
- def stdout
- DEBUGGER__.stdout
- end
-
- def break_points
- DEBUGGER__.break_points
- end
-
- def display
- DEBUGGER__.display
- end
-
- def context(th)
- DEBUGGER__.context(th)
- end
-
- def set_trace_all(arg)
- DEBUGGER__.set_trace(arg)
- end
-
- def set_last_thread(th)
- DEBUGGER__.set_last_thread(th)
- end
-
- def debug_eval(str, binding)
- begin
- eval(str, binding)
- rescue StandardError, ScriptError => e
- at = eval("caller(1)", binding)
- stdout.printf "%s:%s\n", at.shift, e.to_s.sub(/\(eval\):1:(in `.*?':)?/, '')
- for i in at
- stdout.printf "\tfrom %s\n", i
- end
- throw :debug_error
- end
- end
-
- def debug_silent_eval(str, binding)
- begin
- eval(str, binding)
- rescue StandardError, ScriptError
- nil
- end
- end
-
- def var_list(ary, binding)
- ary.sort!
- for v in ary
- stdout.printf " %s => %s\n", v, eval(v.to_s, binding).inspect
- end
- end
-
- def debug_variable_info(input, binding)
- case input
- when /^\s*g(?:lobal)?\s*$/
- var_list(global_variables, binding)
-
- when /^\s*l(?:ocal)?\s*$/
- var_list(eval("local_variables", binding), binding)
-
- when /^\s*i(?:nstance)?\s+/
- obj = debug_eval($', binding)
- var_list(obj.instance_variables, obj.instance_eval{binding()})
-
- when /^\s*c(?:onst(?:ant)?)?\s+/
- obj = debug_eval($', binding)
- unless obj.kind_of? Module
- stdout.print "Should be Class/Module: ", $', "\n"
- else
- var_list(obj.constants, obj.module_eval{binding()})
- end
- end
- end
-
- def debug_method_info(input, binding)
- case input
- when /^i(:?nstance)?\s+/
- obj = debug_eval($', binding)
-
- len = 0
- for v in obj.methods.sort
- len += v.size + 1
- if len > 70
- len = v.size + 1
- stdout.print "\n"
- end
- stdout.print v, " "
- end
- stdout.print "\n"
-
- else
- obj = debug_eval(input, binding)
- unless obj.kind_of? Module
- stdout.print "Should be Class/Module: ", input, "\n"
- else
- len = 0
- for v in obj.instance_methods(false).sort
- len += v.size + 1
- if len > 70
- len = v.size + 1
- stdout.print "\n"
- end
- stdout.print v, " "
- end
- stdout.print "\n"
- end
- end
- end
-
- def thnum
- num = DEBUGGER__.instance_eval{@thread_list[Thread.current]}
- unless num
- DEBUGGER__.make_thread_list
- num = DEBUGGER__.instance_eval{@thread_list[Thread.current]}
- end
- num
- end
-
- def debug_command(file, line, id, binding)
- MUTEX.lock
- unless defined?($debugger_restart) and $debugger_restart
- callcc{|c| $debugger_restart = c}
- end
- set_last_thread(Thread.current)
- frame_pos = 0
- binding_file = file
- binding_line = line
- previous_line = nil
- if ENV['EMACS']
- stdout.printf "\032\032%s:%d:\n", binding_file, binding_line
- else
- stdout.printf "%s:%d:%s", binding_file, binding_line,
- line_at(binding_file, binding_line)
- end
- @frames[0] = [binding, file, line, id]
- display_expressions(binding)
- prompt = true
- while prompt and input = readline("(rdb:%d) "%thnum(), true)
- catch(:debug_error) do
- if input == ""
- next unless DEBUG_LAST_CMD[0]
- input = DEBUG_LAST_CMD[0]
- stdout.print input, "\n"
- else
- DEBUG_LAST_CMD[0] = input
- end
-
- case input
- when /^\s*tr(?:ace)?(?:\s+(on|off))?(?:\s+(all))?$/
- if defined?( $2 )
- if $1 == 'on'
- set_trace_all true
- else
- set_trace_all false
- end
- elsif defined?( $1 )
- if $1 == 'on'
- set_trace true
- else
- set_trace false
- end
- end
- if trace?
- stdout.print "Trace on.\n"
- else
- stdout.print "Trace off.\n"
- end
-
- when /^\s*b(?:reak)?\s+(?:(.+):)?([^.:]+)$/
- pos = $2
- if $1
- klass = debug_silent_eval($1, binding)
- file = $1
- end
- if pos =~ /^\d+$/
- pname = pos
- pos = pos.to_i
- else
- pname = pos = pos.intern.id2name
- end
- break_points.push [true, 0, klass || file, pos]
- stdout.printf "Set breakpoint %d at %s:%s\n", break_points.size, klass || file, pname
-
- when /^\s*b(?:reak)?\s+(.+)[#.]([^.:]+)$/
- pos = $2.intern.id2name
- klass = debug_eval($1, binding)
- break_points.push [true, 0, klass, pos]
- stdout.printf "Set breakpoint %d at %s.%s\n", break_points.size, klass, pos
-
- when /^\s*wat(?:ch)?\s+(.+)$/
- exp = $1
- break_points.push [true, 1, exp]
- stdout.printf "Set watchpoint %d:%s\n", break_points.size, exp
-
- when /^\s*b(?:reak)?$/
- if break_points.find{|b| b[1] == 0}
- n = 1
- stdout.print "Breakpoints:\n"
- break_points.each do |b|
- if b[0] and b[1] == 0
- stdout.printf " %d %s:%s\n", n, b[2], b[3]
- end
- n += 1
- end
- end
- if break_points.find{|b| b[1] == 1}
- n = 1
- stdout.print "\n"
- stdout.print "Watchpoints:\n"
- for b in break_points
- if b[0] and b[1] == 1
- stdout.printf " %d %s\n", n, b[2]
- end
- n += 1
- end
- end
- if break_points.size == 0
- stdout.print "No breakpoints\n"
- else
- stdout.print "\n"
- end
-
- when /^\s*del(?:ete)?(?:\s+(\d+))?$/
- pos = $1
- unless pos
- input = readline("Clear all breakpoints? (y/n) ", false)
- if input == "y"
- for b in break_points
- b[0] = false
- end
- end
- else
- pos = pos.to_i
- if break_points[pos-1]
- break_points[pos-1][0] = false
- else
- stdout.printf "Breakpoint %d is not defined\n", pos
- end
- end
-
- when /^\s*disp(?:lay)?\s+(.+)$/
- exp = $1
- display.push [true, exp]
- stdout.printf "%d: ", display.size
- display_expression(exp, binding)
-
- when /^\s*disp(?:lay)?$/
- display_expressions(binding)
-
- when /^\s*undisp(?:lay)?(?:\s+(\d+))?$/
- pos = $1
- unless pos
- input = readline("Clear all expressions? (y/n) ", false)
- if input == "y"
- for d in display
- d[0] = false
- end
- end
- else
- pos = pos.to_i
- if display[pos-1]
- display[pos-1][0] = false
- else
- stdout.printf "Display expression %d is not defined\n", pos
- end
- end
-
- when /^\s*c(?:ont)?$/
- prompt = false
-
- when /^\s*s(?:tep)?(?:\s+(\d+))?$/
- if $1
- lev = $1.to_i
- else
- lev = 1
- end
- @stop_next = lev
- prompt = false
-
- when /^\s*n(?:ext)?(?:\s+(\d+))?$/
- if $1
- lev = $1.to_i
- else
- lev = 1
- end
- @stop_next = lev
- @no_step = @frames.size - frame_pos
- prompt = false
-
- when /^\s*w(?:here)?$/, /^\s*f(?:rame)?$/
- display_frames(frame_pos)
-
- when /^\s*l(?:ist)?(?:\s+(.+))?$/
- if not $1
- b = previous_line ? previous_line + 10 : binding_line - 5
- e = b + 9
- elsif $1 == '-'
- b = previous_line ? previous_line - 10 : binding_line - 5
- e = b + 9
- else
- b, e = $1.split(/[-,]/)
- if e
- b = b.to_i
- e = e.to_i
- else
- b = b.to_i - 5
- e = b + 9
- end
- end
- previous_line = b
- display_list(b, e, binding_file, binding_line)
-
- when /^\s*up(?:\s+(\d+))?$/
- previous_line = nil
- if $1
- lev = $1.to_i
- else
- lev = 1
- end
- frame_pos += lev
- if frame_pos >= @frames.size
- frame_pos = @frames.size - 1
- stdout.print "At toplevel\n"
- end
- binding, binding_file, binding_line = @frames[frame_pos]
- stdout.print format_frame(frame_pos)
-
- when /^\s*down(?:\s+(\d+))?$/
- previous_line = nil
- if $1
- lev = $1.to_i
- else
- lev = 1
- end
- frame_pos -= lev
- if frame_pos < 0
- frame_pos = 0
- stdout.print "At stack bottom\n"
- end
- binding, binding_file, binding_line = @frames[frame_pos]
- stdout.print format_frame(frame_pos)
-
- when /^\s*fin(?:ish)?$/
- if frame_pos == @frames.size
- stdout.print "\"finish\" not meaningful in the outermost frame.\n"
- else
- @finish_pos = @frames.size - frame_pos
- frame_pos = 0
- prompt = false
- end
-
- when /^\s*cat(?:ch)?(?:\s+(.+))?$/
- if $1
- excn = $1
- if excn == 'off'
- @catch = nil
- stdout.print "Clear catchpoint.\n"
- else
- @catch = excn
- stdout.printf "Set catchpoint %s.\n", @catch
- end
- else
- if @catch
- stdout.printf "Catchpoint %s.\n", @catch
- else
- stdout.print "No catchpoint.\n"
- end
- end
-
- when /^\s*q(?:uit)?$/
- input = readline("Really quit? (y/n) ", false)
- if input == "y"
- exit! # exit -> exit!: No graceful way to stop threads...
- end
-
- when /^\s*v(?:ar)?\s+/
- debug_variable_info($', binding)
-
- when /^\s*m(?:ethod)?\s+/
- debug_method_info($', binding)
-
- when /^\s*th(?:read)?\s+/
- if DEBUGGER__.debug_thread_info($', binding) == :cont
- prompt = false
- end
-
- when /^\s*pp\s+/
- PP.pp(debug_eval($', binding), stdout)
-
- when /^\s*p\s+/
- stdout.printf "%s\n", debug_eval($', binding).inspect
-
- when /^\s*r(?:estart)?$/
- $debugger_restart.call
-
- when /^\s*h(?:elp)?$/
- debug_print_help()
-
- else
- v = debug_eval(input, binding)
- stdout.printf "%s\n", v.inspect
- end
- end
- end
- MUTEX.unlock
- resume_all
- end
-
- def debug_print_help
- stdout.print <<EOHELP
-Debugger help v.-0.002b
-Commands
- b[reak] [file:|class:]<line|method>
- b[reak] [class.]<line|method>
- set breakpoint to some position
- wat[ch] <expression> set watchpoint to some expression
- cat[ch] (<exception>|off) set catchpoint to an exception
- b[reak] list breakpoints
- cat[ch] show catchpoint
- del[ete][ nnn] delete some or all breakpoints
- disp[lay] <expression> add expression into display expression list
- undisp[lay][ nnn] delete one particular or all display expressions
- c[ont] run until program ends or hit breakpoint
- s[tep][ nnn] step (into methods) one line or till line nnn
- n[ext][ nnn] go over one line or till line nnn
- w[here] display frames
- f[rame] alias for where
- l[ist][ (-|nn-mm)] list program, - lists backwards
- nn-mm lists given lines
- up[ nn] move to higher frame
- down[ nn] move to lower frame
- fin[ish] return to outer frame
- tr[ace] (on|off) set trace mode of current thread
- tr[ace] (on|off) all set trace mode of all threads
- q[uit] exit from debugger
- v[ar] g[lobal] show global variables
- v[ar] l[ocal] show local variables
- v[ar] i[nstance] <object> show instance variables of object
- v[ar] c[onst] <object> show constants of object
- m[ethod] i[nstance] <obj> show methods of object
- m[ethod] <class|module> show instance methods of class or module
- th[read] l[ist] list all threads
- th[read] c[ur[rent]] show current thread
- th[read] [sw[itch]] <nnn> switch thread context to nnn
- th[read] stop <nnn> stop thread nnn
- th[read] resume <nnn> resume thread nnn
- pp expression evaluate expression and pretty_print its value
- p expression evaluate expression and print its value
- r[estart] restart program
- h[elp] print this help
- <everything else> evaluate
-EOHELP
- end
-
- def display_expressions(binding)
- n = 1
- for d in display
- if d[0]
- stdout.printf "%d: ", n
- display_expression(d[1], binding)
- end
- n += 1
- end
- end
-
- def display_expression(exp, binding)
- stdout.printf "%s = %s\n", exp, debug_silent_eval(exp, binding).to_s
- end
-
- def frame_set_pos(file, line)
- if @frames[0]
- @frames[0][1] = file
- @frames[0][2] = line
- end
- end
-
- def display_frames(pos)
- 0.upto(@frames.size - 1) do |n|
- if n == pos
- stdout.print "--> "
- else
- stdout.print " "
- end
- stdout.print format_frame(n)
- end
- end
-
- def format_frame(pos)
- _, file, line, id = @frames[pos]
- sprintf "#%d %s:%s%s\n", pos + 1, file, line,
- (id ? ":in `#{id.id2name}'" : "")
- end
-
- def script_lines(file, line)
- unless (lines = SCRIPT_LINES__[file]) and lines != true
- Tracer::Single.get_line(file, line) if File.exist?(file)
- lines = SCRIPT_LINES__[file]
- lines = nil if lines == true
- end
- lines
- end
-
- def display_list(b, e, file, line)
- if lines = script_lines(file, line)
- stdout.printf "[%d, %d] in %s\n", b, e, file
- b.upto(e) do |n|
- if n > 0 && lines[n-1]
- if n == line
- stdout.printf "=> %d %s\n", n, lines[n-1].chomp
- else
- stdout.printf " %d %s\n", n, lines[n-1].chomp
- end
- end
- end
- else
- stdout.printf "No sourcefile available for %s\n", file
- end
- end
-
- def line_at(file, line)
- lines = script_lines(file, line)
- if lines and line = lines[line-1]
- return line
- end
- return "\n"
- end
-
- def debug_funcname(id)
- if id.nil?
- "toplevel"
- else
- id.id2name
- end
- end
-
- def check_break_points(file, klass, pos, binding, id)
- return false if break_points.empty?
- n = 1
- for b in break_points
- if b[0] # valid
- if b[1] == 0 # breakpoint
- if (b[2] == file and b[3] == pos) or
- (klass and b[2] == klass and b[3] == pos)
- stdout.printf "Breakpoint %d, %s at %s:%s\n", n, debug_funcname(id), file, pos
- return true
- end
- elsif b[1] == 1 # watchpoint
- if debug_silent_eval(b[2], binding)
- stdout.printf "Watchpoint %d, %s at %s:%s\n", n, debug_funcname(id), file, pos
- return true
- end
- end
- end
- n += 1
- end
- return false
- end
-
- def excn_handle(file, line, id, binding)
- if $!.class <= SystemExit
- set_trace_func nil
- exit
- end
-
- if @catch and ($!.class.ancestors.find { |e| e.to_s == @catch })
- stdout.printf "%s:%d: `%s' (%s)\n", file, line, $!, $!.class
- fs = @frames.size
- tb = caller(0)[-fs..-1]
- if tb
- for i in tb
- stdout.printf "\tfrom %s\n", i
- end
- end
- suspend_all
- debug_command(file, line, id, binding)
- end
- end
-
- def trace_func(event, file, line, id, binding, klass)
- Tracer.trace_func(event, file, line, id, binding, klass) if trace?
- context(Thread.current).check_suspend
- @file = file
- @line = line
- case event
- when 'line'
- frame_set_pos(file, line)
- if !@no_step or @frames.size == @no_step
- @stop_next -= 1
- @stop_next = -1 if @stop_next < 0
- elsif @frames.size < @no_step
- @stop_next = 0 # break here before leaving...
- else
- # nothing to do. skipped.
- end
- if @stop_next == 0 or check_break_points(file, nil, line, binding, id)
- @no_step = nil
- suspend_all
- debug_command(file, line, id, binding)
- end
-
- when 'call'
- @frames.unshift [binding, file, line, id]
- if check_break_points(file, klass, id.id2name, binding, id)
- suspend_all
- debug_command(file, line, id, binding)
- end
-
- when 'c-call'
- frame_set_pos(file, line)
-
- when 'class'
- @frames.unshift [binding, file, line, id]
-
- when 'return', 'end'
- if @frames.size == @finish_pos
- @stop_next = 1
- @finish_pos = 0
- end
- @frames.shift
-
- when 'raise'
- excn_handle(file, line, id, binding)
-
- end
- @last_file = file
- end
- end
-
- trap("INT") { DEBUGGER__.interrupt }
- @last_thread = Thread::main
- @max_thread = 1
- @thread_list = {Thread::main => 1}
- @break_points = []
- @display = []
- @waiting = []
- @stdout = STDOUT
-
- class << DEBUGGER__
- # Returns the IO used as stdout. Defaults to STDOUT
- def stdout
- @stdout
- end
-
- # Sets the IO used as stdout. Defaults to STDOUT
- def stdout=(s)
- @stdout = s
- end
-
- # Returns the display expression list
- #
- # See DEBUGGER__ for more usage
- def display
- @display
- end
-
- # Returns the list of break points where execution will be stopped.
- #
- # See DEBUGGER__ for more usage
- def break_points
- @break_points
- end
-
- # Returns the list of waiting threads.
- #
- # When stepping through the traces of a function, thread gets suspended, to
- # be resumed later.
- def waiting
- @waiting
- end
-
- def set_trace( arg )
- MUTEX.synchronize do
- make_thread_list
- for th, in @thread_list
- context(th).set_trace arg
- end
- end
- arg
- end
-
- def set_last_thread(th)
- @last_thread = th
- end
-
- def suspend
- MUTEX.synchronize do
- make_thread_list
- for th, in @thread_list
- next if th == Thread.current
- context(th).set_suspend
- end
- end
- # Schedule other threads to suspend as soon as possible.
- Thread.pass
- end
-
- def resume
- MUTEX.synchronize do
- make_thread_list
- @thread_list.each do |th,|
- next if th == Thread.current
- context(th).clear_suspend
- end
- waiting.each do |th|
- th.run
- end
- waiting.clear
- end
- # Schedule other threads to restart as soon as possible.
- Thread.pass
- end
-
- def context(thread=Thread.current)
- c = thread[:__debugger_data__]
- unless c
- thread[:__debugger_data__] = c = Context.new
- end
- c
- end
-
- def interrupt
- context(@last_thread).stop_next
- end
-
- def get_thread(num)
- th = @thread_list.key(num)
- unless th
- @stdout.print "No thread ##{num}\n"
- throw :debug_error
- end
- th
- end
-
- def thread_list(num)
- th = get_thread(num)
- if th == Thread.current
- @stdout.print "+"
- else
- @stdout.print " "
- end
- @stdout.printf "%d ", num
- @stdout.print th.inspect, "\t"
- file = context(th).instance_eval{@file}
- if file
- @stdout.print file,":",context(th).instance_eval{@line}
- end
- @stdout.print "\n"
- end
-
- def thread_list_all
- for th in @thread_list.values.sort
- thread_list(th)
- end
- end
-
- def make_thread_list
- hash = {}
- for th in Thread::list
- if @thread_list.key? th
- hash[th] = @thread_list[th]
- else
- @max_thread += 1
- hash[th] = @max_thread
- end
- end
- @thread_list = hash
- end
-
- def debug_thread_info(input, binding)
- case input
- when /^l(?:ist)?/
- make_thread_list
- thread_list_all
-
- when /^c(?:ur(?:rent)?)?$/
- make_thread_list
- thread_list(@thread_list[Thread.current])
-
- when /^(?:sw(?:itch)?\s+)?(\d+)/
- make_thread_list
- th = get_thread($1.to_i)
- if th == Thread.current
- @stdout.print "It's the current thread.\n"
- else
- thread_list(@thread_list[th])
- context(th).stop_next
- th.run
- return :cont
- end
-
- when /^stop\s+(\d+)/
- make_thread_list
- th = get_thread($1.to_i)
- if th == Thread.current
- @stdout.print "It's the current thread.\n"
- elsif th.stop?
- @stdout.print "Already stopped.\n"
- else
- thread_list(@thread_list[th])
- context(th).suspend
- end
-
- when /^resume\s+(\d+)/
- make_thread_list
- th = get_thread($1.to_i)
- if th == Thread.current
- @stdout.print "It's the current thread.\n"
- elsif !th.stop?
- @stdout.print "Already running."
- else
- thread_list(@thread_list[th])
- th.run
- end
- end
- end
- end
-
- stdout.printf "Debug.rb\n"
- stdout.printf "Emacs support available.\n\n"
- RubyVM::InstructionSequence.compile_option = {
- trace_instruction: true
- }
- set_trace_func proc { |event, file, line, id, binding, klass, *rest|
- DEBUGGER__.context.trace_func event, file, line, id, binding, klass
- }
-end
diff --git a/ruby_2_2/lib/delegate.rb b/ruby_2_2/lib/delegate.rb
deleted file mode 100644
index f2b1388107..0000000000
--- a/ruby_2_2/lib/delegate.rb
+++ /dev/null
@@ -1,417 +0,0 @@
-# = delegate -- Support for the Delegation Pattern
-#
-# Documentation by James Edward Gray II and Gavin Sinclair
-
-##
-# This library provides three different ways to delegate method calls to an
-# object. The easiest to use is SimpleDelegator. Pass an object to the
-# constructor and all methods supported by the object will be delegated. This
-# object can be changed later.
-#
-# Going a step further, the top level DelegateClass method allows you to easily
-# setup delegation through class inheritance. This is considerably more
-# flexible and thus probably the most common use for this library.
-#
-# Finally, if you need full control over the delegation scheme, you can inherit
-# from the abstract class Delegator and customize as needed. (If you find
-# yourself needing this control, have a look at Forwardable which is also in
-# the standard library. It may suit your needs better.)
-#
-# SimpleDelegator's implementation serves as a nice example if the use of
-# Delegator:
-#
-# class SimpleDelegator < Delegator
-# def initialize(obj)
-# super # pass obj to Delegator constructor, required
-# @delegate_sd_obj = obj # store obj for future use
-# end
-#
-# def __getobj__
-# @delegate_sd_obj # return object we are delegating to, required
-# end
-#
-# def __setobj__(obj)
-# @delegate_sd_obj = obj # change delegation object,
-# # a feature we're providing
-# end
-# end
-#
-# == Notes
-#
-# Be advised, RDoc will not detect delegated methods.
-#
-class Delegator < BasicObject
- kernel = ::Kernel.dup
- kernel.class_eval do
- alias __raise__ raise
- [:to_s,:inspect,:=~,:!~,:===,:<=>,:eql?,:hash].each do |m|
- undef_method m
- end
- private_instance_methods.each do |m|
- if /\Ablock_given\?\z|iterator\?\z|\A__.*__\z/ =~ m
- next
- end
- undef_method m
- end
- end
- include kernel
-
- # :stopdoc:
- def self.const_missing(n)
- ::Object.const_get(n)
- end
- # :startdoc:
-
- ##
- # :method: raise
- # Use __raise__ if your Delegator does not have a object to delegate the
- # raise method call.
- #
-
- #
- # Pass in the _obj_ to delegate method calls to. All methods supported by
- # _obj_ will be delegated to.
- #
- def initialize(obj)
- __setobj__(obj)
- end
-
- #
- # Handles the magic of delegation through \_\_getobj\_\_.
- #
- def method_missing(m, *args, &block)
- r = true
- target = self.__getobj__ {r = false}
- begin
- if r && target.respond_to?(m)
- target.__send__(m, *args, &block)
- elsif ::Kernel.respond_to?(m, true)
- ::Kernel.instance_method(m).bind(self).(*args, &block)
- else
- super(m, *args, &block)
- end
- ensure
- $@.delete_if {|t| %r"\A#{Regexp.quote(__FILE__)}:(?:#{[__LINE__-7, __LINE__-5, __LINE__-3].join('|')}):"o =~ t} if $@
- end
- end
-
- #
- # Checks for a method provided by this the delegate object by forwarding the
- # call through \_\_getobj\_\_.
- #
- def respond_to_missing?(m, include_private)
- r = true
- target = self.__getobj__ {r = false}
- r &&= target.respond_to?(m, include_private)
- if r && include_private && !target.respond_to?(m, false)
- warn "#{caller(3)[0]}: delegator does not forward private method \##{m}"
- return false
- end
- r
- end
-
- #
- # Returns the methods available to this delegate object as the union
- # of this object's and \_\_getobj\_\_ methods.
- #
- def methods(all=true)
- __getobj__.methods(all) | super
- end
-
- #
- # Returns the methods available to this delegate object as the union
- # of this object's and \_\_getobj\_\_ public methods.
- #
- def public_methods(all=true)
- __getobj__.public_methods(all) | super
- end
-
- #
- # Returns the methods available to this delegate object as the union
- # of this object's and \_\_getobj\_\_ protected methods.
- #
- def protected_methods(all=true)
- __getobj__.protected_methods(all) | super
- end
-
- # Note: no need to specialize private_methods, since they are not forwarded
-
- #
- # Returns true if two objects are considered of equal value.
- #
- def ==(obj)
- return true if obj.equal?(self)
- self.__getobj__ == obj
- end
-
- #
- # Returns true if two objects are not considered of equal value.
- #
- def !=(obj)
- return false if obj.equal?(self)
- __getobj__ != obj
- end
-
- #
- # Delegates ! to the \_\_getobj\_\_
- #
- def !
- !__getobj__
- end
-
- #
- # This method must be overridden by subclasses and should return the object
- # method calls are being delegated to.
- #
- def __getobj__
- __raise__ ::NotImplementedError, "need to define `__getobj__'"
- end
-
- #
- # This method must be overridden by subclasses and change the object delegate
- # to _obj_.
- #
- def __setobj__(obj)
- __raise__ ::NotImplementedError, "need to define `__setobj__'"
- end
-
- #
- # Serialization support for the object returned by \_\_getobj\_\_.
- #
- def marshal_dump
- ivars = instance_variables.reject {|var| /\A@delegate_/ =~ var}
- [
- :__v2__,
- ivars, ivars.map{|var| instance_variable_get(var)},
- __getobj__
- ]
- end
-
- #
- # Reinitializes delegation from a serialized object.
- #
- def marshal_load(data)
- version, vars, values, obj = data
- if version == :__v2__
- vars.each_with_index{|var, i| instance_variable_set(var, values[i])}
- __setobj__(obj)
- else
- __setobj__(data)
- end
- end
-
- def initialize_clone(obj) # :nodoc:
- self.__setobj__(obj.__getobj__.clone)
- end
- def initialize_dup(obj) # :nodoc:
- self.__setobj__(obj.__getobj__.dup)
- end
- private :initialize_clone, :initialize_dup
-
- ##
- # :method: trust
- # Trust both the object returned by \_\_getobj\_\_ and self.
- #
-
- ##
- # :method: untrust
- # Untrust both the object returned by \_\_getobj\_\_ and self.
- #
-
- ##
- # :method: taint
- # Taint both the object returned by \_\_getobj\_\_ and self.
- #
-
- ##
- # :method: untaint
- # Untaint both the object returned by \_\_getobj\_\_ and self.
- #
-
- ##
- # :method: freeze
- # Freeze both the object returned by \_\_getobj\_\_ and self.
- #
-
- [:trust, :untrust, :taint, :untaint, :freeze].each do |method|
- define_method method do
- __getobj__.send(method)
- super()
- end
- end
-
- @delegator_api = self.public_instance_methods
- def self.public_api # :nodoc:
- @delegator_api
- end
-end
-
-##
-# A concrete implementation of Delegator, this class provides the means to
-# delegate all supported method calls to the object passed into the constructor
-# and even to change the object being delegated to at a later time with
-# #__setobj__.
-#
-# class User
-# def born_on
-# Date.new(1989, 9, 10)
-# end
-# end
-#
-# class UserDecorator < SimpleDelegator
-# def birth_year
-# born_on.year
-# end
-# end
-#
-# decorated_user = UserDecorator.new(User.new)
-# decorated_user.birth_year #=> 1989
-# decorated_user.__getobj__ #=> #<User: ...>
-#
-# A SimpleDelegator instance can take advantage of the fact that SimpleDelegator
-# is a subclass of +Delegator+ to call <tt>super</tt> to have methods called on
-# the object being delegated to.
-#
-# class SuperArray < SimpleDelegator
-# def [](*args)
-# super + 1
-# end
-# end
-#
-# SuperArray.new([1])[0] #=> 2
-#
-# Here's a simple example that takes advantage of the fact that
-# SimpleDelegator's delegation object can be changed at any time.
-#
-# class Stats
-# def initialize
-# @source = SimpleDelegator.new([])
-# end
-#
-# def stats(records)
-# @source.__setobj__(records)
-#
-# "Elements: #{@source.size}\n" +
-# " Non-Nil: #{@source.compact.size}\n" +
-# " Unique: #{@source.uniq.size}\n"
-# end
-# end
-#
-# s = Stats.new
-# puts s.stats(%w{James Edward Gray II})
-# puts
-# puts s.stats([1, 2, 3, nil, 4, 5, 1, 2])
-#
-# Prints:
-#
-# Elements: 4
-# Non-Nil: 4
-# Unique: 4
-#
-# Elements: 8
-# Non-Nil: 7
-# Unique: 6
-#
-class SimpleDelegator<Delegator
- # Returns the current object method calls are being delegated to.
- def __getobj__
- unless defined?(@delegate_sd_obj)
- return yield if block_given?
- __raise__ ::ArgumentError, "not delegated"
- end
- @delegate_sd_obj
- end
-
- #
- # Changes the delegate object to _obj_.
- #
- # It's important to note that this does *not* cause SimpleDelegator's methods
- # to change. Because of this, you probably only want to change delegation
- # to objects of the same type as the original delegate.
- #
- # Here's an example of changing the delegation object.
- #
- # names = SimpleDelegator.new(%w{James Edward Gray II})
- # puts names[1] # => Edward
- # names.__setobj__(%w{Gavin Sinclair})
- # puts names[1] # => Sinclair
- #
- def __setobj__(obj)
- __raise__ ::ArgumentError, "cannot delegate to self" if self.equal?(obj)
- @delegate_sd_obj = obj
- end
-end
-
-def Delegator.delegating_block(mid) # :nodoc:
- lambda do |*args, &block|
- target = self.__getobj__
- begin
- target.__send__(mid, *args, &block)
- ensure
- $@.delete_if {|t| /\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}:/o =~ t} if $@
- end
- end
-end
-
-#
-# The primary interface to this library. Use to setup delegation when defining
-# your class.
-#
-# class MyClass < DelegateClass(ClassToDelegateTo) # Step 1
-# def initialize
-# super(obj_of_ClassToDelegateTo) # Step 2
-# end
-# end
-#
-# Here's a sample of use from Tempfile which is really a File object with a
-# few special rules about storage location and when the File should be
-# deleted. That makes for an almost textbook perfect example of how to use
-# delegation.
-#
-# class Tempfile < DelegateClass(File)
-# # constant and class member data initialization...
-#
-# def initialize(basename, tmpdir=Dir::tmpdir)
-# # build up file path/name in var tmpname...
-#
-# @tmpfile = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL, 0600)
-#
-# # ...
-#
-# super(@tmpfile)
-#
-# # below this point, all methods of File are supported...
-# end
-#
-# # ...
-# end
-#
-def DelegateClass(superclass)
- klass = Class.new(Delegator)
- methods = superclass.instance_methods
- methods -= ::Delegator.public_api
- methods -= [:to_s,:inspect,:=~,:!~,:===]
- klass.module_eval do
- def __getobj__ # :nodoc:
- unless defined?(@delegate_dc_obj)
- return yield if block_given?
- __raise__ ::ArgumentError, "not delegated"
- end
- @delegate_dc_obj
- end
- def __setobj__(obj) # :nodoc:
- __raise__ ::ArgumentError, "cannot delegate to self" if self.equal?(obj)
- @delegate_dc_obj = obj
- end
- methods.each do |method|
- define_method(method, Delegator.delegating_block(method))
- end
- end
- klass.define_singleton_method :public_instance_methods do |all=true|
- super(all) - superclass.protected_instance_methods
- end
- klass.define_singleton_method :protected_instance_methods do |all=true|
- super(all) | superclass.protected_instance_methods
- end
- return klass
-end
diff --git a/ruby_2_2/lib/drb.rb b/ruby_2_2/lib/drb.rb
deleted file mode 100644
index 93cc811e14..0000000000
--- a/ruby_2_2/lib/drb.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-require 'drb/drb'
-
diff --git a/ruby_2_2/lib/drb/acl.rb b/ruby_2_2/lib/drb/acl.rb
deleted file mode 100644
index 72e034e960..0000000000
--- a/ruby_2_2/lib/drb/acl.rb
+++ /dev/null
@@ -1,232 +0,0 @@
-# Copyright (c) 2000,2002,2003 Masatoshi SEKI
-#
-# acl.rb is copyrighted free software by Masatoshi SEKI.
-# You can redistribute it and/or modify it under the same terms as Ruby.
-
-require 'ipaddr'
-
-##
-# Simple Access Control Lists.
-#
-# Access control lists are composed of "allow" and "deny" halves to control
-# access. Use "all" or "*" to match any address. To match a specific address
-# use any address or address mask that IPAddr can understand.
-#
-# Example:
-#
-# list = %w[
-# deny all
-# allow 192.168.1.1
-# allow ::ffff:192.168.1.2
-# allow 192.168.1.3
-# ]
-#
-# # From Socket#peeraddr, see also ACL#allow_socket?
-# addr = ["AF_INET", 10, "lc630", "192.168.1.3"]
-#
-# acl = ACL.new
-# p acl.allow_addr?(addr) # => true
-#
-# acl = ACL.new(list, ACL::DENY_ALLOW)
-# p acl.allow_addr?(addr) # => true
-
-class ACL
-
- ##
- # The current version of ACL
-
- VERSION=["2.0.0"]
-
- ##
- # An entry in an ACL
-
- class ACLEntry
-
- ##
- # Creates a new entry using +str+.
- #
- # +str+ may be "*" or "all" to match any address, an IP address string
- # to match a specific address, an IP address mask per IPAddr, or one
- # containing "*" to match part of an IPv4 address.
-
- def initialize(str)
- if str == '*' or str == 'all'
- @pat = [:all]
- elsif str.include?('*')
- @pat = [:name, dot_pat(str)]
- else
- begin
- @pat = [:ip, IPAddr.new(str)]
- rescue ArgumentError
- @pat = [:name, dot_pat(str)]
- end
- end
- end
-
- private
-
- ##
- # Creates a regular expression to match IPv4 addresses
-
- def dot_pat_str(str)
- list = str.split('.').collect { |s|
- (s == '*') ? '.+' : s
- }
- list.join("\\.")
- end
-
- private
-
- ##
- # Creates a Regexp to match an address.
-
- def dot_pat(str)
- exp = "^" + dot_pat_str(str) + "$"
- Regexp.new(exp)
- end
-
- public
-
- ##
- # Matches +addr+ against this entry.
-
- def match(addr)
- case @pat[0]
- when :all
- true
- when :ip
- begin
- ipaddr = IPAddr.new(addr[3])
- ipaddr = ipaddr.ipv4_mapped if @pat[1].ipv6? && ipaddr.ipv4?
- rescue ArgumentError
- return false
- end
- (@pat[1].include?(ipaddr)) ? true : false
- when :name
- (@pat[1] =~ addr[2]) ? true : false
- else
- false
- end
- end
- end
-
- ##
- # A list of ACLEntry objects. Used to implement the allow and deny halves
- # of an ACL
-
- class ACLList
-
- ##
- # Creates an empty ACLList
-
- def initialize
- @list = []
- end
-
- public
-
- ##
- # Matches +addr+ against each ACLEntry in this list.
-
- def match(addr)
- @list.each do |e|
- return true if e.match(addr)
- end
- false
- end
-
- public
-
- ##
- # Adds +str+ as an ACLEntry in this list
-
- def add(str)
- @list.push(ACLEntry.new(str))
- end
-
- end
-
- ##
- # Default to deny
-
- DENY_ALLOW = 0
-
- ##
- # Default to allow
-
- ALLOW_DENY = 1
-
- ##
- # Creates a new ACL from +list+ with an evaluation +order+ of DENY_ALLOW or
- # ALLOW_DENY.
- #
- # An ACL +list+ is an Array of "allow" or "deny" and an address or address
- # mask or "all" or "*" to match any address:
- #
- # %w[
- # deny all
- # allow 192.0.2.2
- # allow 192.0.2.128/26
- # ]
-
- def initialize(list=nil, order = DENY_ALLOW)
- @order = order
- @deny = ACLList.new
- @allow = ACLList.new
- install_list(list) if list
- end
-
- public
-
- ##
- # Allow connections from Socket +soc+?
-
- def allow_socket?(soc)
- allow_addr?(soc.peeraddr)
- end
-
- public
-
- ##
- # Allow connections from addrinfo +addr+? It must be formatted like
- # Socket#peeraddr:
- #
- # ["AF_INET", 10, "lc630", "192.0.2.1"]
-
- def allow_addr?(addr)
- case @order
- when DENY_ALLOW
- return true if @allow.match(addr)
- return false if @deny.match(addr)
- return true
- when ALLOW_DENY
- return false if @deny.match(addr)
- return true if @allow.match(addr)
- return false
- else
- false
- end
- end
-
- public
-
- ##
- # Adds +list+ of ACL entries to this ACL.
-
- def install_list(list)
- i = 0
- while i < list.size
- permission, domain = list.slice(i,2)
- case permission.downcase
- when 'allow'
- @allow.add(domain)
- when 'deny'
- @deny.add(domain)
- else
- raise "Invalid ACL entry #{list}"
- end
- i += 2
- end
- end
-
-end
diff --git a/ruby_2_2/lib/drb/drb.rb b/ruby_2_2/lib/drb/drb.rb
deleted file mode 100644
index ab352afa1d..0000000000
--- a/ruby_2_2/lib/drb/drb.rb
+++ /dev/null
@@ -1,1864 +0,0 @@
-#
-# = drb/drb.rb
-#
-# Distributed Ruby: _dRuby_ version 2.0.4
-#
-# Copyright (c) 1999-2003 Masatoshi SEKI. You can redistribute it and/or
-# modify it under the same terms as Ruby.
-#
-# Author:: Masatoshi SEKI
-#
-# Documentation:: William Webber (william@williamwebber.com)
-#
-# == Overview
-#
-# dRuby is a distributed object system for Ruby. It allows an object in one
-# Ruby process to invoke methods on an object in another Ruby process on the
-# same or a different machine.
-#
-# The Ruby standard library contains the core classes of the dRuby package.
-# However, the full package also includes access control lists and the
-# Rinda tuple-space distributed task management system, as well as a
-# large number of samples. The full dRuby package can be downloaded from
-# the dRuby home page (see *References*).
-#
-# For an introduction and examples of usage see the documentation to the
-# DRb module.
-#
-# == References
-#
-# [http://www2a.biglobe.ne.jp/~seki/ruby/druby.html]
-# The dRuby home page, in Japanese. Contains the full dRuby package
-# and links to other Japanese-language sources.
-#
-# [http://www2a.biglobe.ne.jp/~seki/ruby/druby.en.html]
-# The English version of the dRuby home page.
-#
-# [http://pragprog.com/book/sidruby/the-druby-book]
-# The dRuby Book: Distributed and Parallel Computing with Ruby
-# by Masatoshi Seki and Makoto Inoue
-#
-# [http://www.ruby-doc.org/docs/ProgrammingRuby/html/ospace.html]
-# The chapter from *Programming* *Ruby* by Dave Thomas and Andy Hunt
-# which discusses dRuby.
-#
-# [http://www.clio.ne.jp/home/web-i31s/Flotuard/Ruby/PRC2K_seki/dRuby.en.html]
-# Translation of presentation on Ruby by Masatoshi Seki.
-
-require 'socket'
-require 'thread'
-require 'fcntl'
-require 'drb/eq'
-
-#
-# == Overview
-#
-# dRuby is a distributed object system for Ruby. It is written in
-# pure Ruby and uses its own protocol. No add-in services are needed
-# beyond those provided by the Ruby runtime, such as TCP sockets. It
-# does not rely on or interoperate with other distributed object
-# systems such as CORBA, RMI, or .NET.
-#
-# dRuby allows methods to be called in one Ruby process upon a Ruby
-# object located in another Ruby process, even on another machine.
-# References to objects can be passed between processes. Method
-# arguments and return values are dumped and loaded in marshalled
-# format. All of this is done transparently to both the caller of the
-# remote method and the object that it is called upon.
-#
-# An object in a remote process is locally represented by a
-# DRb::DRbObject instance. This acts as a sort of proxy for the
-# remote object. Methods called upon this DRbObject instance are
-# forwarded to its remote object. This is arranged dynamically at run
-# time. There are no statically declared interfaces for remote
-# objects, such as CORBA's IDL.
-#
-# dRuby calls made into a process are handled by a DRb::DRbServer
-# instance within that process. This reconstitutes the method call,
-# invokes it upon the specified local object, and returns the value to
-# the remote caller. Any object can receive calls over dRuby. There
-# is no need to implement a special interface, or mixin special
-# functionality. Nor, in the general case, does an object need to
-# explicitly register itself with a DRbServer in order to receive
-# dRuby calls.
-#
-# One process wishing to make dRuby calls upon another process must
-# somehow obtain an initial reference to an object in the remote
-# process by some means other than as the return value of a remote
-# method call, as there is initially no remote object reference it can
-# invoke a method upon. This is done by attaching to the server by
-# URI. Each DRbServer binds itself to a URI such as
-# 'druby://example.com:8787'. A DRbServer can have an object attached
-# to it that acts as the server's *front* *object*. A DRbObject can
-# be explicitly created from the server's URI. This DRbObject's
-# remote object will be the server's front object. This front object
-# can then return references to other Ruby objects in the DRbServer's
-# process.
-#
-# Method calls made over dRuby behave largely the same as normal Ruby
-# method calls made within a process. Method calls with blocks are
-# supported, as are raising exceptions. In addition to a method's
-# standard errors, a dRuby call may also raise one of the
-# dRuby-specific errors, all of which are subclasses of DRb::DRbError.
-#
-# Any type of object can be passed as an argument to a dRuby call or
-# returned as its return value. By default, such objects are dumped
-# or marshalled at the local end, then loaded or unmarshalled at the
-# remote end. The remote end therefore receives a copy of the local
-# object, not a distributed reference to it; methods invoked upon this
-# copy are executed entirely in the remote process, not passed on to
-# the local original. This has semantics similar to pass-by-value.
-#
-# However, if an object cannot be marshalled, a dRuby reference to it
-# is passed or returned instead. This will turn up at the remote end
-# as a DRbObject instance. All methods invoked upon this remote proxy
-# are forwarded to the local object, as described in the discussion of
-# DRbObjects. This has semantics similar to the normal Ruby
-# pass-by-reference.
-#
-# The easiest way to signal that we want an otherwise marshallable
-# object to be passed or returned as a DRbObject reference, rather
-# than marshalled and sent as a copy, is to include the
-# DRb::DRbUndumped mixin module.
-#
-# dRuby supports calling remote methods with blocks. As blocks (or
-# rather the Proc objects that represent them) are not marshallable,
-# the block executes in the local, not the remote, context. Each
-# value yielded to the block is passed from the remote object to the
-# local block, then the value returned by each block invocation is
-# passed back to the remote execution context to be collected, before
-# the collected values are finally returned to the local context as
-# the return value of the method invocation.
-#
-# == Examples of usage
-#
-# For more dRuby samples, see the +samples+ directory in the full
-# dRuby distribution.
-#
-# === dRuby in client/server mode
-#
-# This illustrates setting up a simple client-server drb
-# system. Run the server and client code in different terminals,
-# starting the server code first.
-#
-# ==== Server code
-#
-# require 'drb/drb'
-#
-# # The URI for the server to connect to
-# URI="druby://localhost:8787"
-#
-# class TimeServer
-#
-# def get_current_time
-# return Time.now
-# end
-#
-# end
-#
-# # The object that handles requests on the server
-# FRONT_OBJECT=TimeServer.new
-#
-# $SAFE = 1 # disable eval() and friends
-#
-# DRb.start_service(URI, FRONT_OBJECT)
-# # Wait for the drb server thread to finish before exiting.
-# DRb.thread.join
-#
-# ==== Client code
-#
-# require 'drb/drb'
-#
-# # The URI to connect to
-# SERVER_URI="druby://localhost:8787"
-#
-# # Start a local DRbServer to handle callbacks.
-# #
-# # Not necessary for this small example, but will be required
-# # as soon as we pass a non-marshallable object as an argument
-# # to a dRuby call.
-# #
-# # Note: this must be called at least once per process to take any effect.
-# # This is particularly important if your application forks.
-# DRb.start_service
-#
-# timeserver = DRbObject.new_with_uri(SERVER_URI)
-# puts timeserver.get_current_time
-#
-# === Remote objects under dRuby
-#
-# This example illustrates returning a reference to an object
-# from a dRuby call. The Logger instances live in the server
-# process. References to them are returned to the client process,
-# where methods can be invoked upon them. These methods are
-# executed in the server process.
-#
-# ==== Server code
-#
-# require 'drb/drb'
-#
-# URI="druby://localhost:8787"
-#
-# class Logger
-#
-# # Make dRuby send Logger instances as dRuby references,
-# # not copies.
-# include DRb::DRbUndumped
-#
-# def initialize(n, fname)
-# @name = n
-# @filename = fname
-# end
-#
-# def log(message)
-# File.open(@filename, "a") do |f|
-# f.puts("#{Time.now}: #{@name}: #{message}")
-# end
-# end
-#
-# end
-#
-# # We have a central object for creating and retrieving loggers.
-# # This retains a local reference to all loggers created. This
-# # is so an existing logger can be looked up by name, but also
-# # to prevent loggers from being garbage collected. A dRuby
-# # reference to an object is not sufficient to prevent it being
-# # garbage collected!
-# class LoggerFactory
-#
-# def initialize(bdir)
-# @basedir = bdir
-# @loggers = {}
-# end
-#
-# def get_logger(name)
-# if !@loggers.has_key? name
-# # make the filename safe, then declare it to be so
-# fname = name.gsub(/[.\/\\\:]/, "_").untaint
-# @loggers[name] = Logger.new(name, @basedir + "/" + fname)
-# end
-# return @loggers[name]
-# end
-#
-# end
-#
-# FRONT_OBJECT=LoggerFactory.new("/tmp/dlog")
-#
-# $SAFE = 1 # disable eval() and friends
-#
-# DRb.start_service(URI, FRONT_OBJECT)
-# DRb.thread.join
-#
-# ==== Client code
-#
-# require 'drb/drb'
-#
-# SERVER_URI="druby://localhost:8787"
-#
-# DRb.start_service
-#
-# log_service=DRbObject.new_with_uri(SERVER_URI)
-#
-# ["loga", "logb", "logc"].each do |logname|
-#
-# logger=log_service.get_logger(logname)
-#
-# logger.log("Hello, world!")
-# logger.log("Goodbye, world!")
-# logger.log("=== EOT ===")
-#
-# end
-#
-# == Security
-#
-# As with all network services, security needs to be considered when
-# using dRuby. By allowing external access to a Ruby object, you are
-# not only allowing outside clients to call the methods you have
-# defined for that object, but by default to execute arbitrary Ruby
-# code on your server. Consider the following:
-#
-# # !!! UNSAFE CODE !!!
-# ro = DRbObject::new_with_uri("druby://your.server.com:8989")
-# class << ro
-# undef :instance_eval # force call to be passed to remote object
-# end
-# ro.instance_eval("`rm -rf *`")
-#
-# The dangers posed by instance_eval and friends are such that a
-# DRbServer should generally be run with $SAFE set to at least
-# level 1. This will disable eval() and related calls on strings
-# passed across the wire. The sample usage code given above follows
-# this practice.
-#
-# A DRbServer can be configured with an access control list to
-# selectively allow or deny access from specified IP addresses. The
-# main druby distribution provides the ACL class for this purpose. In
-# general, this mechanism should only be used alongside, rather than
-# as a replacement for, a good firewall.
-#
-# == dRuby internals
-#
-# dRuby is implemented using three main components: a remote method
-# call marshaller/unmarshaller; a transport protocol; and an
-# ID-to-object mapper. The latter two can be directly, and the first
-# indirectly, replaced, in order to provide different behaviour and
-# capabilities.
-#
-# Marshalling and unmarshalling of remote method calls is performed by
-# a DRb::DRbMessage instance. This uses the Marshal module to dump
-# the method call before sending it over the transport layer, then
-# reconstitute it at the other end. There is normally no need to
-# replace this component, and no direct way is provided to do so.
-# However, it is possible to implement an alternative marshalling
-# scheme as part of an implementation of the transport layer.
-#
-# The transport layer is responsible for opening client and server
-# network connections and forwarding dRuby request across them.
-# Normally, it uses DRb::DRbMessage internally to manage marshalling
-# and unmarshalling. The transport layer is managed by
-# DRb::DRbProtocol. Multiple protocols can be installed in
-# DRbProtocol at the one time; selection between them is determined by
-# the scheme of a dRuby URI. The default transport protocol is
-# selected by the scheme 'druby:', and implemented by
-# DRb::DRbTCPSocket. This uses plain TCP/IP sockets for
-# communication. An alternative protocol, using UNIX domain sockets,
-# is implemented by DRb::DRbUNIXSocket in the file drb/unix.rb, and
-# selected by the scheme 'drbunix:'. A sample implementation over
-# HTTP can be found in the samples accompanying the main dRuby
-# distribution.
-#
-# The ID-to-object mapping component maps dRuby object ids to the
-# objects they refer to, and vice versa. The implementation to use
-# can be specified as part of a DRb::DRbServer's configuration. The
-# default implementation is provided by DRb::DRbIdConv. It uses an
-# object's ObjectSpace id as its dRuby id. This means that the dRuby
-# reference to that object only remains meaningful for the lifetime of
-# the object's process and the lifetime of the object within that
-# process. A modified implementation is provided by DRb::TimerIdConv
-# in the file drb/timeridconv.rb. This implementation retains a local
-# reference to all objects exported over dRuby for a configurable
-# period of time (defaulting to ten minutes), to prevent them being
-# garbage-collected within this time. Another sample implementation
-# is provided in sample/name.rb in the main dRuby distribution. This
-# allows objects to specify their own id or "name". A dRuby reference
-# can be made persistent across processes by having each process
-# register an object using the same dRuby name.
-#
-module DRb
-
- # Superclass of all errors raised in the DRb module.
- class DRbError < RuntimeError; end
-
- # Error raised when an error occurs on the underlying communication
- # protocol.
- class DRbConnError < DRbError; end
-
- # Class responsible for converting between an object and its id.
- #
- # This, the default implementation, uses an object's local ObjectSpace
- # __id__ as its id. This means that an object's identification over
- # drb remains valid only while that object instance remains alive
- # within the server runtime.
- #
- # For alternative mechanisms, see DRb::TimerIdConv in rdb/timeridconv.rb
- # and DRbNameIdConv in sample/name.rb in the full drb distribution.
- class DRbIdConv
-
- # Convert an object reference id to an object.
- #
- # This implementation looks up the reference id in the local object
- # space and returns the object it refers to.
- def to_obj(ref)
- ObjectSpace._id2ref(ref)
- end
-
- # Convert an object into a reference id.
- #
- # This implementation returns the object's __id__ in the local
- # object space.
- def to_id(obj)
- obj.nil? ? nil : obj.__id__
- end
- end
-
- # Mixin module making an object undumpable or unmarshallable.
- #
- # If an object which includes this module is returned by method
- # called over drb, then the object remains in the server space
- # and a reference to the object is returned, rather than the
- # object being marshalled and moved into the client space.
- module DRbUndumped
- def _dump(dummy) # :nodoc:
- raise TypeError, 'can\'t dump'
- end
- end
-
- # Error raised by the DRb module when an attempt is made to refer to
- # the context's current drb server but the context does not have one.
- # See #current_server.
- class DRbServerNotFound < DRbError; end
-
- # Error raised by the DRbProtocol module when it cannot find any
- # protocol implementation support the scheme specified in a URI.
- class DRbBadURI < DRbError; end
-
- # Error raised by a dRuby protocol when it doesn't support the
- # scheme specified in a URI. See DRb::DRbProtocol.
- class DRbBadScheme < DRbError; end
-
- # An exception wrapping a DRb::DRbUnknown object
- class DRbUnknownError < DRbError
-
- # Create a new DRbUnknownError for the DRb::DRbUnknown object +unknown+
- def initialize(unknown)
- @unknown = unknown
- super(unknown.name)
- end
-
- # Get the wrapped DRb::DRbUnknown object.
- attr_reader :unknown
-
- def self._load(s) # :nodoc:
- Marshal::load(s)
- end
-
- def _dump(lv) # :nodoc:
- Marshal::dump(@unknown)
- end
- end
-
- # An exception wrapping an error object
- class DRbRemoteError < DRbError
-
- # Creates a new remote error that wraps the Exception +error+
- def initialize(error)
- @reason = error.class.to_s
- super("#{error.message} (#{error.class})")
- set_backtrace(error.backtrace)
- end
-
- # the class of the error, as a string.
- attr_reader :reason
- end
-
- # Class wrapping a marshalled object whose type is unknown locally.
- #
- # If an object is returned by a method invoked over drb, but the
- # class of the object is unknown in the client namespace, or
- # the object is a constant unknown in the client namespace, then
- # the still-marshalled object is returned wrapped in a DRbUnknown instance.
- #
- # If this object is passed as an argument to a method invoked over
- # drb, then the wrapped object is passed instead.
- #
- # The class or constant name of the object can be read from the
- # +name+ attribute. The marshalled object is held in the +buf+
- # attribute.
- class DRbUnknown
-
- # Create a new DRbUnknown object.
- #
- # +buf+ is a string containing a marshalled object that could not
- # be unmarshalled. +err+ is the error message that was raised
- # when the unmarshalling failed. It is used to determine the
- # name of the unmarshalled object.
- def initialize(err, buf)
- case err.to_s
- when /uninitialized constant (\S+)/
- @name = $1
- when /undefined class\/module (\S+)/
- @name = $1
- else
- @name = nil
- end
- @buf = buf
- end
-
- # The name of the unknown thing.
- #
- # Class name for unknown objects; variable name for unknown
- # constants.
- attr_reader :name
-
- # Buffer contained the marshalled, unknown object.
- attr_reader :buf
-
- def self._load(s) # :nodoc:
- begin
- Marshal::load(s)
- rescue NameError, ArgumentError
- DRbUnknown.new($!, s)
- end
- end
-
- def _dump(lv) # :nodoc:
- @buf
- end
-
- # Attempt to load the wrapped marshalled object again.
- #
- # If the class of the object is now known locally, the object
- # will be unmarshalled and returned. Otherwise, a new
- # but identical DRbUnknown object will be returned.
- def reload
- self.class._load(@buf)
- end
-
- # Create a DRbUnknownError exception containing this object.
- def exception
- DRbUnknownError.new(self)
- end
- end
-
- # An Array wrapper that can be sent to another server via DRb.
- #
- # All entries in the array will be dumped or be references that point to
- # the local server.
-
- class DRbArray
-
- # Creates a new DRbArray that either dumps or wraps all the items in the
- # Array +ary+ so they can be loaded by a remote DRb server.
-
- def initialize(ary)
- @ary = ary.collect { |obj|
- if obj.kind_of? DRbUndumped
- DRbObject.new(obj)
- else
- begin
- Marshal.dump(obj)
- obj
- rescue
- DRbObject.new(obj)
- end
- end
- }
- end
-
- def self._load(s) # :nodoc:
- Marshal::load(s)
- end
-
- def _dump(lv) # :nodoc:
- Marshal.dump(@ary)
- end
- end
-
- # Handler for sending and receiving drb messages.
- #
- # This takes care of the low-level marshalling and unmarshalling
- # of drb requests and responses sent over the wire between server
- # and client. This relieves the implementor of a new drb
- # protocol layer with having to deal with these details.
- #
- # The user does not have to directly deal with this object in
- # normal use.
- class DRbMessage
- def initialize(config) # :nodoc:
- @load_limit = config[:load_limit]
- @argc_limit = config[:argc_limit]
- end
-
- def dump(obj, error=false) # :nodoc:
- obj = make_proxy(obj, error) if obj.kind_of? DRbUndumped
- begin
- str = Marshal::dump(obj)
- rescue
- str = Marshal::dump(make_proxy(obj, error))
- end
- [str.size].pack('N') + str
- end
-
- def load(soc) # :nodoc:
- begin
- sz = soc.read(4) # sizeof (N)
- rescue
- raise(DRbConnError, $!.message, $!.backtrace)
- end
- raise(DRbConnError, 'connection closed') if sz.nil?
- raise(DRbConnError, 'premature header') if sz.size < 4
- sz = sz.unpack('N')[0]
- raise(DRbConnError, "too large packet #{sz}") if @load_limit < sz
- begin
- str = soc.read(sz)
- rescue
- raise(DRbConnError, $!.message, $!.backtrace)
- end
- raise(DRbConnError, 'connection closed') if str.nil?
- raise(DRbConnError, 'premature marshal format(can\'t read)') if str.size < sz
- DRb.mutex.synchronize do
- begin
- save = Thread.current[:drb_untaint]
- Thread.current[:drb_untaint] = []
- Marshal::load(str)
- rescue NameError, ArgumentError
- DRbUnknown.new($!, str)
- ensure
- Thread.current[:drb_untaint].each do |x|
- x.untaint
- end
- Thread.current[:drb_untaint] = save
- end
- end
- end
-
- def send_request(stream, ref, msg_id, arg, b) # :nodoc:
- ary = []
- ary.push(dump(ref.__drbref))
- ary.push(dump(msg_id.id2name))
- ary.push(dump(arg.length))
- arg.each do |e|
- ary.push(dump(e))
- end
- ary.push(dump(b))
- stream.write(ary.join(''))
- rescue
- raise(DRbConnError, $!.message, $!.backtrace)
- end
-
- def recv_request(stream) # :nodoc:
- ref = load(stream)
- ro = DRb.to_obj(ref)
- msg = load(stream)
- argc = load(stream)
- raise(DRbConnError, "too many arguments") if @argc_limit < argc
- argv = Array.new(argc, nil)
- argc.times do |n|
- argv[n] = load(stream)
- end
- block = load(stream)
- return ro, msg, argv, block
- end
-
- def send_reply(stream, succ, result) # :nodoc:
- stream.write(dump(succ) + dump(result, !succ))
- rescue
- raise(DRbConnError, $!.message, $!.backtrace)
- end
-
- def recv_reply(stream) # :nodoc:
- succ = load(stream)
- result = load(stream)
- [succ, result]
- end
-
- private
- def make_proxy(obj, error=false) # :nodoc:
- if error
- DRbRemoteError.new(obj)
- else
- DRbObject.new(obj)
- end
- end
- end
-
- # Module managing the underlying network protocol(s) used by drb.
- #
- # By default, drb uses the DRbTCPSocket protocol. Other protocols
- # can be defined. A protocol must define the following class methods:
- #
- # [open(uri, config)] Open a client connection to the server at +uri+,
- # using configuration +config+. Return a protocol
- # instance for this connection.
- # [open_server(uri, config)] Open a server listening at +uri+,
- # using configuration +config+. Return a
- # protocol instance for this listener.
- # [uri_option(uri, config)] Take a URI, possibly containing an option
- # component (e.g. a trailing '?param=val'),
- # and return a [uri, option] tuple.
- #
- # All of these methods should raise a DRbBadScheme error if the URI
- # does not identify the protocol they support (e.g. "druby:" for
- # the standard Ruby protocol). This is how the DRbProtocol module,
- # given a URI, determines which protocol implementation serves that
- # protocol.
- #
- # The protocol instance returned by #open_server must have the
- # following methods:
- #
- # [accept] Accept a new connection to the server. Returns a protocol
- # instance capable of communicating with the client.
- # [close] Close the server connection.
- # [uri] Get the URI for this server.
- #
- # The protocol instance returned by #open must have the following methods:
- #
- # [send_request (ref, msg_id, arg, b)]
- # Send a request to +ref+ with the given message id and arguments.
- # This is most easily implemented by calling DRbMessage.send_request,
- # providing a stream that sits on top of the current protocol.
- # [recv_reply]
- # Receive a reply from the server and return it as a [success-boolean,
- # reply-value] pair. This is most easily implemented by calling
- # DRb.recv_reply, providing a stream that sits on top of the
- # current protocol.
- # [alive?]
- # Is this connection still alive?
- # [close]
- # Close this connection.
- #
- # The protocol instance returned by #open_server().accept() must have
- # the following methods:
- #
- # [recv_request]
- # Receive a request from the client and return a [object, message,
- # args, block] tuple. This is most easily implemented by calling
- # DRbMessage.recv_request, providing a stream that sits on top of
- # the current protocol.
- # [send_reply(succ, result)]
- # Send a reply to the client. This is most easily implemented
- # by calling DRbMessage.send_reply, providing a stream that sits
- # on top of the current protocol.
- # [close]
- # Close this connection.
- #
- # A new protocol is registered with the DRbProtocol module using
- # the add_protocol method.
- #
- # For examples of other protocols, see DRbUNIXSocket in drb/unix.rb,
- # and HTTP0 in sample/http0.rb and sample/http0serv.rb in the full
- # drb distribution.
- module DRbProtocol
-
- # Add a new protocol to the DRbProtocol module.
- def add_protocol(prot)
- @protocol.push(prot)
- end
- module_function :add_protocol
-
- # Open a client connection to +uri+ with the configuration +config+.
- #
- # The DRbProtocol module asks each registered protocol in turn to
- # try to open the URI. Each protocol signals that it does not handle that
- # URI by raising a DRbBadScheme error. If no protocol recognises the
- # URI, then a DRbBadURI error is raised. If a protocol accepts the
- # URI, but an error occurs in opening it, a DRbConnError is raised.
- def open(uri, config, first=true)
- @protocol.each do |prot|
- begin
- return prot.open(uri, config)
- rescue DRbBadScheme
- rescue DRbConnError
- raise($!)
- rescue
- raise(DRbConnError, "#{uri} - #{$!.inspect}")
- end
- end
- if first && (config[:auto_load] != false)
- auto_load(uri, config)
- return open(uri, config, false)
- end
- raise DRbBadURI, 'can\'t parse uri:' + uri
- end
- module_function :open
-
- # Open a server listening for connections at +uri+ with
- # configuration +config+.
- #
- # The DRbProtocol module asks each registered protocol in turn to
- # try to open a server at the URI. Each protocol signals that it does
- # not handle that URI by raising a DRbBadScheme error. If no protocol
- # recognises the URI, then a DRbBadURI error is raised. If a protocol
- # accepts the URI, but an error occurs in opening it, the underlying
- # error is passed on to the caller.
- def open_server(uri, config, first=true)
- @protocol.each do |prot|
- begin
- return prot.open_server(uri, config)
- rescue DRbBadScheme
- end
- end
- if first && (config[:auto_load] != false)
- auto_load(uri, config)
- return open_server(uri, config, false)
- end
- raise DRbBadURI, 'can\'t parse uri:' + uri
- end
- module_function :open_server
-
- # Parse +uri+ into a [uri, option] pair.
- #
- # The DRbProtocol module asks each registered protocol in turn to
- # try to parse the URI. Each protocol signals that it does not handle that
- # URI by raising a DRbBadScheme error. If no protocol recognises the
- # URI, then a DRbBadURI error is raised.
- def uri_option(uri, config, first=true)
- @protocol.each do |prot|
- begin
- uri, opt = prot.uri_option(uri, config)
- # opt = nil if opt == ''
- return uri, opt
- rescue DRbBadScheme
- end
- end
- if first && (config[:auto_load] != false)
- auto_load(uri, config)
- return uri_option(uri, config, false)
- end
- raise DRbBadURI, 'can\'t parse uri:' + uri
- end
- module_function :uri_option
-
- def auto_load(uri, config) # :nodoc:
- if uri =~ /^drb([a-z0-9]+):/
- require("drb/#{$1}") rescue nil
- end
- end
- module_function :auto_load
- end
-
- # The default drb protocol which communicates over a TCP socket.
- #
- # The DRb TCP protocol URI looks like:
- # <code>druby://<host>:<port>?<option></code>. The option is optional.
-
- class DRbTCPSocket
- # :stopdoc:
- private
- def self.parse_uri(uri)
- if uri =~ /^druby:\/\/(.*?):(\d+)(\?(.*))?$/
- host = $1
- port = $2.to_i
- option = $4
- [host, port, option]
- else
- raise(DRbBadScheme, uri) unless uri =~ /^druby:/
- raise(DRbBadURI, 'can\'t parse uri:' + uri)
- end
- end
-
- public
-
- # Open a client connection to +uri+ (DRb URI string) using configuration
- # +config+.
- #
- # This can raise DRb::DRbBadScheme or DRb::DRbBadURI if +uri+ is not for a
- # recognized protocol. See DRb::DRbServer.new for information on built-in
- # URI protocols.
- def self.open(uri, config)
- host, port, = parse_uri(uri)
- host.untaint
- port.untaint
- soc = TCPSocket.open(host, port)
- self.new(uri, soc, config)
- end
-
- # Returns the hostname of this server
- def self.getservername
- host = Socket::gethostname
- begin
- Socket::gethostbyname(host)[0]
- rescue
- 'localhost'
- end
- end
-
- # For the families available for +host+, returns a TCPServer on +port+.
- # If +port+ is 0 the first available port is used. IPv4 servers are
- # preferred over IPv6 servers.
- def self.open_server_inaddr_any(host, port)
- infos = Socket::getaddrinfo(host, nil,
- Socket::AF_UNSPEC,
- Socket::SOCK_STREAM,
- 0,
- Socket::AI_PASSIVE)
- families = Hash[*infos.collect { |af, *_| af }.uniq.zip([]).flatten]
- return TCPServer.open('0.0.0.0', port) if families.has_key?('AF_INET')
- return TCPServer.open('::', port) if families.has_key?('AF_INET6')
- return TCPServer.open(port)
- # :stopdoc:
- end
-
- # Open a server listening for connections at +uri+ using
- # configuration +config+.
- def self.open_server(uri, config)
- uri = 'druby://:0' unless uri
- host, port, _ = parse_uri(uri)
- config = {:tcp_original_host => host}.update(config)
- if host.size == 0
- host = getservername
- soc = open_server_inaddr_any(host, port)
- else
- soc = TCPServer.open(host, port)
- end
- port = soc.addr[1] if port == 0
- config[:tcp_port] = port
- uri = "druby://#{host}:#{port}"
- self.new(uri, soc, config)
- end
-
- # Parse +uri+ into a [uri, option] pair.
- def self.uri_option(uri, config)
- host, port, option = parse_uri(uri)
- return "druby://#{host}:#{port}", option
- end
-
- # Create a new DRbTCPSocket instance.
- #
- # +uri+ is the URI we are connected to.
- # +soc+ is the tcp socket we are bound to. +config+ is our
- # configuration.
- def initialize(uri, soc, config={})
- @uri = uri
- @socket = soc
- @config = config
- @acl = config[:tcp_acl]
- @msg = DRbMessage.new(config)
- set_sockopt(@socket)
- @shutdown_pipe_r, @shutdown_pipe_w = IO.pipe
- end
-
- # Get the URI that we are connected to.
- attr_reader :uri
-
- # Get the address of our TCP peer (the other end of the socket
- # we are bound to.
- def peeraddr
- @socket.peeraddr
- end
-
- # Get the socket.
- def stream; @socket; end
-
- # On the client side, send a request to the server.
- def send_request(ref, msg_id, arg, b)
- @msg.send_request(stream, ref, msg_id, arg, b)
- end
-
- # On the server side, receive a request from the client.
- def recv_request
- @msg.recv_request(stream)
- end
-
- # On the server side, send a reply to the client.
- def send_reply(succ, result)
- @msg.send_reply(stream, succ, result)
- end
-
- # On the client side, receive a reply from the server.
- def recv_reply
- @msg.recv_reply(stream)
- end
-
- public
-
- # Close the connection.
- #
- # If this is an instance returned by #open_server, then this stops
- # listening for new connections altogether. If this is an instance
- # returned by #open or by #accept, then it closes this particular
- # client-server session.
- def close
- if @socket
- @socket.close
- @socket = nil
- end
- close_shutdown_pipe
- end
-
- def close_shutdown_pipe
- if @shutdown_pipe_r && !@shutdown_pipe_r.closed?
- @shutdown_pipe_r.close
- @shutdown_pipe_r = nil
- end
- if @shutdown_pipe_w && !@shutdown_pipe_w.closed?
- @shutdown_pipe_w.close
- @shutdown_pipe_w = nil
- end
- end
- private :close_shutdown_pipe
-
- # On the server side, for an instance returned by #open_server,
- # accept a client connection and return a new instance to handle
- # the server's side of this client-server session.
- def accept
- while true
- s = accept_or_shutdown
- return nil unless s
- break if (@acl ? @acl.allow_socket?(s) : true)
- s.close
- end
- if @config[:tcp_original_host].to_s.size == 0
- uri = "druby://#{s.addr[3]}:#{@config[:tcp_port]}"
- else
- uri = @uri
- end
- self.class.new(uri, s, @config)
- end
-
- def accept_or_shutdown
- readables, = IO.select([@socket, @shutdown_pipe_r])
- if readables.include? @shutdown_pipe_r
- return nil
- end
- @socket.accept
- end
- private :accept_or_shutdown
-
- # Graceful shutdown
- def shutdown
- @shutdown_pipe_w.close if @shutdown_pipe_w && !@shutdown_pipe_w.closed?
- end
-
- # Check to see if this connection is alive.
- def alive?
- return false unless @socket
- if IO.select([@socket], nil, nil, 0)
- close
- return false
- end
- true
- end
-
- def set_sockopt(soc) # :nodoc:
- soc.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
- soc.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::FD_CLOEXEC
- end
- end
-
- module DRbProtocol
- @protocol = [DRbTCPSocket] # default
- end
-
- class DRbURIOption # :nodoc: I don't understand the purpose of this class...
- def initialize(option)
- @option = option.to_s
- end
- attr_reader :option
- def to_s; @option; end
-
- def ==(other)
- return false unless DRbURIOption === other
- @option == other.option
- end
-
- def hash
- @option.hash
- end
-
- alias eql? ==
- end
-
- # Object wrapping a reference to a remote drb object.
- #
- # Method calls on this object are relayed to the remote
- # object that this object is a stub for.
- class DRbObject
-
- # Unmarshall a marshalled DRbObject.
- #
- # If the referenced object is located within the local server, then
- # the object itself is returned. Otherwise, a new DRbObject is
- # created to act as a stub for the remote referenced object.
- def self._load(s)
- uri, ref = Marshal.load(s)
-
- if DRb.here?(uri)
- obj = DRb.to_obj(ref)
- if ((! obj.tainted?) && Thread.current[:drb_untaint])
- Thread.current[:drb_untaint].push(obj)
- end
- return obj
- end
-
- self.new_with(uri, ref)
- end
-
- # Creates a DRb::DRbObject given the reference information to the remote
- # host +uri+ and object +ref+.
-
- def self.new_with(uri, ref)
- it = self.allocate
- it.instance_variable_set(:@uri, uri)
- it.instance_variable_set(:@ref, ref)
- it
- end
-
- # Create a new DRbObject from a URI alone.
- def self.new_with_uri(uri)
- self.new(nil, uri)
- end
-
- # Marshall this object.
- #
- # The URI and ref of the object are marshalled.
- def _dump(lv)
- Marshal.dump([@uri, @ref])
- end
-
- # Create a new remote object stub.
- #
- # +obj+ is the (local) object we want to create a stub for. Normally
- # this is +nil+. +uri+ is the URI of the remote object that this
- # will be a stub for.
- def initialize(obj, uri=nil)
- @uri = nil
- @ref = nil
- if obj.nil?
- return if uri.nil?
- @uri, option = DRbProtocol.uri_option(uri, DRb.config)
- @ref = DRbURIOption.new(option) unless option.nil?
- else
- @uri = uri ? uri : (DRb.uri rescue nil)
- @ref = obj ? DRb.to_id(obj) : nil
- end
- end
-
- # Get the URI of the remote object.
- def __drburi
- @uri
- end
-
- # Get the reference of the object, if local.
- def __drbref
- @ref
- end
-
- undef :to_s
- undef :to_a if respond_to?(:to_a)
-
- # Routes respond_to? to the referenced remote object.
- def respond_to?(msg_id, priv=false)
- case msg_id
- when :_dump
- true
- when :marshal_dump
- false
- else
- method_missing(:respond_to?, msg_id, priv)
- end
- end
-
- # Routes method calls to the referenced remote object.
- def method_missing(msg_id, *a, &b)
- if DRb.here?(@uri)
- obj = DRb.to_obj(@ref)
- DRb.current_server.check_insecure_method(obj, msg_id)
- return obj.__send__(msg_id, *a, &b)
- end
-
- succ, result = self.class.with_friend(@uri) do
- DRbConn.open(@uri) do |conn|
- conn.send_message(self, msg_id, a, b)
- end
- end
-
- if succ
- return result
- elsif DRbUnknown === result
- raise result
- else
- bt = self.class.prepare_backtrace(@uri, result)
- result.set_backtrace(bt + caller)
- raise result
- end
- end
-
- # Given the +uri+ of another host executes the block provided.
- def self.with_friend(uri) # :nodoc:
- friend = DRb.fetch_server(uri)
- return yield() unless friend
-
- save = Thread.current['DRb']
- Thread.current['DRb'] = { 'server' => friend }
- return yield
- ensure
- Thread.current['DRb'] = save if friend
- end
-
- # Returns a modified backtrace from +result+ with the +uri+ where each call
- # in the backtrace came from.
- def self.prepare_backtrace(uri, result) # :nodoc:
- prefix = "(#{uri}) "
- bt = []
- result.backtrace.each do |x|
- break if /`__send__'$/ =~ x
- if /^\(druby:\/\// =~ x
- bt.push(x)
- else
- bt.push(prefix + x)
- end
- end
- bt
- end
-
- def pretty_print(q) # :nodoc:
- q.pp_object(self)
- end
-
- def pretty_print_cycle(q) # :nodoc:
- q.object_address_group(self) {
- q.breakable
- q.text '...'
- }
- end
- end
-
- # Class handling the connection between a DRbObject and the
- # server the real object lives on.
- #
- # This class maintains a pool of connections, to reduce the
- # overhead of starting and closing down connections for each
- # method call.
- #
- # This class is used internally by DRbObject. The user does
- # not normally need to deal with it directly.
- class DRbConn
- POOL_SIZE = 16 # :nodoc:
- @mutex = Mutex.new
- @pool = []
-
- def self.open(remote_uri) # :nodoc:
- begin
- conn = nil
-
- @mutex.synchronize do
- #FIXME
- new_pool = []
- @pool.each do |c|
- if conn.nil? and c.uri == remote_uri
- conn = c if c.alive?
- else
- new_pool.push c
- end
- end
- @pool = new_pool
- end
-
- conn = self.new(remote_uri) unless conn
- succ, result = yield(conn)
- return succ, result
-
- ensure
- if conn
- if succ
- @mutex.synchronize do
- @pool.unshift(conn)
- @pool.pop.close while @pool.size > POOL_SIZE
- end
- else
- conn.close
- end
- end
- end
- end
-
- def initialize(remote_uri) # :nodoc:
- @uri = remote_uri
- @protocol = DRbProtocol.open(remote_uri, DRb.config)
- end
- attr_reader :uri # :nodoc:
-
- def send_message(ref, msg_id, arg, block) # :nodoc:
- @protocol.send_request(ref, msg_id, arg, block)
- @protocol.recv_reply
- end
-
- def close # :nodoc:
- @protocol.close
- @protocol = nil
- end
-
- def alive? # :nodoc:
- return false unless @protocol
- @protocol.alive?
- end
- end
-
- # Class representing a drb server instance.
- #
- # A DRbServer must be running in the local process before any incoming
- # dRuby calls can be accepted, or any local objects can be passed as
- # dRuby references to remote processes, even if those local objects are
- # never actually called remotely. You do not need to start a DRbServer
- # in the local process if you are only making outgoing dRuby calls
- # passing marshalled parameters.
- #
- # Unless multiple servers are being used, the local DRbServer is normally
- # started by calling DRb.start_service.
- class DRbServer
- @@acl = nil
- @@idconv = DRbIdConv.new
- @@secondary_server = nil
- @@argc_limit = 256
- @@load_limit = 256 * 102400
- @@verbose = false
- @@safe_level = 0
-
- # Set the default value for the :argc_limit option.
- #
- # See #new(). The initial default value is 256.
- def self.default_argc_limit(argc)
- @@argc_limit = argc
- end
-
- # Set the default value for the :load_limit option.
- #
- # See #new(). The initial default value is 25 MB.
- def self.default_load_limit(sz)
- @@load_limit = sz
- end
-
- # Set the default access control list to +acl+. The default ACL is +nil+.
- #
- # See also DRb::ACL and #new()
- def self.default_acl(acl)
- @@acl = acl
- end
-
- # Set the default value for the :id_conv option.
- #
- # See #new(). The initial default value is a DRbIdConv instance.
- def self.default_id_conv(idconv)
- @@idconv = idconv
- end
-
- # Set the default safe level to +level+. The default safe level is 0
- #
- # See #new for more information.
- def self.default_safe_level(level)
- @@safe_level = level
- end
-
- # Set the default value of the :verbose option.
- #
- # See #new(). The initial default value is false.
- def self.verbose=(on)
- @@verbose = on
- end
-
- # Get the default value of the :verbose option.
- def self.verbose
- @@verbose
- end
-
- def self.make_config(hash={}) # :nodoc:
- default_config = {
- :idconv => @@idconv,
- :verbose => @@verbose,
- :tcp_acl => @@acl,
- :load_limit => @@load_limit,
- :argc_limit => @@argc_limit,
- :safe_level => @@safe_level
- }
- default_config.update(hash)
- end
-
- # Create a new DRbServer instance.
- #
- # +uri+ is the URI to bind to. This is normally of the form
- # 'druby://<hostname>:<port>' where <hostname> is a hostname of
- # the local machine. If nil, then the system's default hostname
- # will be bound to, on a port selected by the system; these value
- # can be retrieved from the +uri+ attribute. 'druby:' specifies
- # the default dRuby transport protocol: another protocol, such
- # as 'drbunix:', can be specified instead.
- #
- # +front+ is the front object for the server, that is, the object
- # to which remote method calls on the server will be passed. If
- # nil, then the server will not accept remote method calls.
- #
- # If +config_or_acl+ is a hash, it is the configuration to
- # use for this server. The following options are recognised:
- #
- # :idconv :: an id-to-object conversion object. This defaults
- # to an instance of the class DRb::DRbIdConv.
- # :verbose :: if true, all unsuccessful remote calls on objects
- # in the server will be logged to $stdout. false
- # by default.
- # :tcp_acl :: the access control list for this server. See
- # the ACL class from the main dRuby distribution.
- # :load_limit :: the maximum message size in bytes accepted by
- # the server. Defaults to 25 MB (26214400).
- # :argc_limit :: the maximum number of arguments to a remote
- # method accepted by the server. Defaults to
- # 256.
- # :safe_level :: The safe level of the DRbServer. The attribute
- # sets $SAFE for methods performed in the main_loop.
- # Defaults to 0.
- #
- # The default values of these options can be modified on
- # a class-wide basis by the class methods #default_argc_limit,
- # #default_load_limit, #default_acl, #default_id_conv,
- # and #verbose=
- #
- # If +config_or_acl+ is not a hash, but is not nil, it is
- # assumed to be the access control list for this server.
- # See the :tcp_acl option for more details.
- #
- # If no other server is currently set as the primary server,
- # this will become the primary server.
- #
- # The server will immediately start running in its own thread.
- def initialize(uri=nil, front=nil, config_or_acl=nil)
- if Hash === config_or_acl
- config = config_or_acl.dup
- else
- acl = config_or_acl || @@acl
- config = {
- :tcp_acl => acl
- }
- end
-
- @config = self.class.make_config(config)
-
- @protocol = DRbProtocol.open_server(uri, @config)
- @uri = @protocol.uri
- @exported_uri = [@uri]
-
- @front = front
- @idconv = @config[:idconv]
- @safe_level = @config[:safe_level]
-
- @grp = ThreadGroup.new
- @thread = run
-
- DRb.regist_server(self)
- end
-
- # The URI of this DRbServer.
- attr_reader :uri
-
- # The main thread of this DRbServer.
- #
- # This is the thread that listens for and accepts connections
- # from clients, not that handles each client's request-response
- # session.
- attr_reader :thread
-
- # The front object of the DRbServer.
- #
- # This object receives remote method calls made on the server's
- # URI alone, with an object id.
- attr_reader :front
-
- # The configuration of this DRbServer
- attr_reader :config
-
- # The safe level for this server. This is a number corresponding to
- # $SAFE.
- #
- # The default safe_level is 0
- attr_reader :safe_level
-
- # Set whether to operate in verbose mode.
- #
- # In verbose mode, failed calls are logged to stdout.
- def verbose=(v); @config[:verbose]=v; end
-
- # Get whether the server is in verbose mode.
- #
- # In verbose mode, failed calls are logged to stdout.
- def verbose; @config[:verbose]; end
-
- # Is this server alive?
- def alive?
- @thread.alive?
- end
-
- # Is +uri+ the URI for this server?
- def here?(uri)
- @exported_uri.include?(uri)
- end
-
- # Stop this server.
- def stop_service
- DRb.remove_server(self)
- if Thread.current['DRb'] && Thread.current['DRb']['server'] == self
- Thread.current['DRb']['stop_service'] = true
- else
- if @protocol.respond_to? :shutdown
- @protocol.shutdown
- else
- @thread.kill # xxx: Thread#kill
- end
- @thread.join
- end
- end
-
- # Convert a dRuby reference to the local object it refers to.
- def to_obj(ref)
- return front if ref.nil?
- return front[ref.to_s] if DRbURIOption === ref
- @idconv.to_obj(ref)
- end
-
- # Convert a local object to a dRuby reference.
- def to_id(obj)
- return nil if obj.__id__ == front.__id__
- @idconv.to_id(obj)
- end
-
- private
-
- ##
- # Starts the DRb main loop in a new thread.
-
- def run
- Thread.start do
- begin
- while main_loop
- end
- ensure
- @protocol.close if @protocol
- end
- end
- end
-
- # List of insecure methods.
- #
- # These methods are not callable via dRuby.
- INSECURE_METHOD = [
- :__send__
- ]
-
- # Has a method been included in the list of insecure methods?
- def insecure_method?(msg_id)
- INSECURE_METHOD.include?(msg_id)
- end
-
- # Coerce an object to a string, providing our own representation if
- # to_s is not defined for the object.
- def any_to_s(obj)
- obj.to_s + ":#{obj.class}"
- rescue
- sprintf("#<%s:0x%lx>", obj.class, obj.__id__)
- end
-
- # Check that a method is callable via dRuby.
- #
- # +obj+ is the object we want to invoke the method on. +msg_id+ is the
- # method name, as a Symbol.
- #
- # If the method is an insecure method (see #insecure_method?) a
- # SecurityError is thrown. If the method is private or undefined,
- # a NameError is thrown.
- def check_insecure_method(obj, msg_id)
- return true if Proc === obj && msg_id == :__drb_yield
- raise(ArgumentError, "#{any_to_s(msg_id)} is not a symbol") unless Symbol == msg_id.class
- raise(SecurityError, "insecure method `#{msg_id}'") if insecure_method?(msg_id)
-
- if obj.private_methods.include?(msg_id)
- desc = any_to_s(obj)
- raise NoMethodError, "private method `#{msg_id}' called for #{desc}"
- elsif obj.protected_methods.include?(msg_id)
- desc = any_to_s(obj)
- raise NoMethodError, "protected method `#{msg_id}' called for #{desc}"
- else
- true
- end
- end
- public :check_insecure_method
-
- class InvokeMethod # :nodoc:
- def initialize(drb_server, client)
- @drb_server = drb_server
- @safe_level = drb_server.safe_level
- @client = client
- end
-
- def perform
- @result = nil
- @succ = false
- setup_message
-
- if $SAFE < @safe_level
- info = Thread.current['DRb']
- if @block
- @result = Thread.new {
- Thread.current['DRb'] = info
- $SAFE = @safe_level
- perform_with_block
- }.value
- else
- @result = Thread.new {
- Thread.current['DRb'] = info
- $SAFE = @safe_level
- perform_without_block
- }.value
- end
- else
- if @block
- @result = perform_with_block
- else
- @result = perform_without_block
- end
- end
- @succ = true
- if @msg_id == :to_ary && @result.class == Array
- @result = DRbArray.new(@result)
- end
- return @succ, @result
- rescue StandardError, ScriptError, Interrupt
- @result = $!
- return @succ, @result
- end
-
- private
- def init_with_client
- obj, msg, argv, block = @client.recv_request
- @obj = obj
- @msg_id = msg.intern
- @argv = argv
- @block = block
- end
-
- def check_insecure_method
- @drb_server.check_insecure_method(@obj, @msg_id)
- end
-
- def setup_message
- init_with_client
- check_insecure_method
- end
-
- def perform_without_block
- if Proc === @obj && @msg_id == :__drb_yield
- if @argv.size == 1
- ary = @argv
- else
- ary = [@argv]
- end
- ary.collect(&@obj)[0]
- else
- @obj.__send__(@msg_id, *@argv)
- end
- end
-
- end
-
- require 'drb/invokemethod'
- class InvokeMethod
- include InvokeMethod18Mixin
- end
-
- # The main loop performed by a DRbServer's internal thread.
- #
- # Accepts a connection from a client, and starts up its own
- # thread to handle it. This thread loops, receiving requests
- # from the client, invoking them on a local object, and
- # returning responses, until the client closes the connection
- # or a local method call fails.
- def main_loop
- client0 = @protocol.accept
- return nil if !client0
- Thread.start(client0) do |client|
- @grp.add Thread.current
- Thread.current['DRb'] = { 'client' => client ,
- 'server' => self }
- DRb.mutex.synchronize do
- client_uri = client.uri
- @exported_uri << client_uri unless @exported_uri.include?(client_uri)
- end
- loop do
- begin
- succ = false
- invoke_method = InvokeMethod.new(self, client)
- succ, result = invoke_method.perform
- if !succ && verbose
- p result
- result.backtrace.each do |x|
- puts x
- end
- end
- client.send_reply(succ, result) rescue nil
- ensure
- client.close unless succ
- if Thread.current['DRb']['stop_service']
- Thread.new { stop_service }
- end
- break unless succ
- end
- end
- end
- end
- end
-
- @primary_server = nil
-
- # Start a dRuby server locally.
- #
- # The new dRuby server will become the primary server, even
- # if another server is currently the primary server.
- #
- # +uri+ is the URI for the server to bind to. If nil,
- # the server will bind to random port on the default local host
- # name and use the default dRuby protocol.
- #
- # +front+ is the server's front object. This may be nil.
- #
- # +config+ is the configuration for the new server. This may
- # be nil.
- #
- # See DRbServer::new.
- def start_service(uri=nil, front=nil, config=nil)
- @primary_server = DRbServer.new(uri, front, config)
- end
- module_function :start_service
-
- # The primary local dRuby server.
- #
- # This is the server created by the #start_service call.
- attr_accessor :primary_server
- module_function :primary_server=, :primary_server
-
- # Get the 'current' server.
- #
- # In the context of execution taking place within the main
- # thread of a dRuby server (typically, as a result of a remote
- # call on the server or one of its objects), the current
- # server is that server. Otherwise, the current server is
- # the primary server.
- #
- # If the above rule fails to find a server, a DRbServerNotFound
- # error is raised.
- def current_server
- drb = Thread.current['DRb']
- server = (drb && drb['server']) ? drb['server'] : @primary_server
- raise DRbServerNotFound unless server
- return server
- end
- module_function :current_server
-
- # Stop the local dRuby server.
- #
- # This operates on the primary server. If there is no primary
- # server currently running, it is a noop.
- def stop_service
- @primary_server.stop_service if @primary_server
- @primary_server = nil
- end
- module_function :stop_service
-
- # Get the URI defining the local dRuby space.
- #
- # This is the URI of the current server. See #current_server.
- def uri
- drb = Thread.current['DRb']
- client = (drb && drb['client'])
- if client
- uri = client.uri
- return uri if uri
- end
- current_server.uri
- end
- module_function :uri
-
- # Is +uri+ the URI for the current local server?
- def here?(uri)
- current_server.here?(uri) rescue false
- # (current_server.uri rescue nil) == uri
- end
- module_function :here?
-
- # Get the configuration of the current server.
- #
- # If there is no current server, this returns the default configuration.
- # See #current_server and DRbServer::make_config.
- def config
- current_server.config
- rescue
- DRbServer.make_config
- end
- module_function :config
-
- # Get the front object of the current server.
- #
- # This raises a DRbServerNotFound error if there is no current server.
- # See #current_server.
- def front
- current_server.front
- end
- module_function :front
-
- # Convert a reference into an object using the current server.
- #
- # This raises a DRbServerNotFound error if there is no current server.
- # See #current_server.
- def to_obj(ref)
- current_server.to_obj(ref)
- end
-
- # Get a reference id for an object using the current server.
- #
- # This raises a DRbServerNotFound error if there is no current server.
- # See #current_server.
- def to_id(obj)
- current_server.to_id(obj)
- end
- module_function :to_id
- module_function :to_obj
-
- # Get the thread of the primary server.
- #
- # This returns nil if there is no primary server. See #primary_server.
- def thread
- @primary_server ? @primary_server.thread : nil
- end
- module_function :thread
-
- # Set the default id conversion object.
- #
- # This is expected to be an instance such as DRb::DRbIdConv that responds to
- # #to_id and #to_obj that can convert objects to and from DRb references.
- #
- # See DRbServer#default_id_conv.
- def install_id_conv(idconv)
- DRbServer.default_id_conv(idconv)
- end
- module_function :install_id_conv
-
- # Set the default ACL to +acl+.
- #
- # See DRb::DRbServer.default_acl.
- def install_acl(acl)
- DRbServer.default_acl(acl)
- end
- module_function :install_acl
-
- @mutex = Mutex.new
- def mutex # :nodoc:
- @mutex
- end
- module_function :mutex
-
- @server = {}
- # Registers +server+ with DRb.
- #
- # This is called when a new DRb::DRbServer is created.
- #
- # If there is no primary server then +server+ becomes the primary server.
- #
- # Example:
- #
- # require 'drb'
- #
- # s = DRb::DRbServer.new # automatically calls regist_server
- # DRb.fetch_server s.uri #=> #<DRb::DRbServer:0x...>
- def regist_server(server)
- @server[server.uri] = server
- mutex.synchronize do
- @primary_server = server unless @primary_server
- end
- end
- module_function :regist_server
-
- # Removes +server+ from the list of registered servers.
- def remove_server(server)
- @server.delete(server.uri)
- end
- module_function :remove_server
-
- # Retrieves the server with the given +uri+.
- #
- # See also regist_server and remove_server.
- def fetch_server(uri)
- @server[uri]
- end
- module_function :fetch_server
-end
-
-# :stopdoc:
-DRbObject = DRb::DRbObject
-DRbUndumped = DRb::DRbUndumped
-DRbIdConv = DRb::DRbIdConv
diff --git a/ruby_2_2/lib/drb/eq.rb b/ruby_2_2/lib/drb/eq.rb
deleted file mode 100644
index 553f30c598..0000000000
--- a/ruby_2_2/lib/drb/eq.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-module DRb
- class DRbObject # :nodoc:
- def ==(other)
- return false unless DRbObject === other
- (@ref == other.__drbref) && (@uri == other.__drburi)
- end
-
- def hash
- [@uri, @ref].hash
- end
-
- alias eql? ==
- end
-end
diff --git a/ruby_2_2/lib/drb/extserv.rb b/ruby_2_2/lib/drb/extserv.rb
deleted file mode 100644
index 327b553a25..0000000000
--- a/ruby_2_2/lib/drb/extserv.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-=begin
- external service
- Copyright (c) 2000,2002 Masatoshi SEKI
-=end
-
-require 'drb/drb'
-require 'monitor'
-
-module DRb
- class ExtServ
- include MonitorMixin
- include DRbUndumped
-
- def initialize(there, name, server=nil)
- super()
- @server = server || DRb::primary_server
- @name = name
- ro = DRbObject.new(nil, there)
- synchronize do
- @invoker = ro.regist(name, DRbObject.new(self, @server.uri))
- end
- end
- attr_reader :server
-
- def front
- DRbObject.new(nil, @server.uri)
- end
-
- def stop_service
- synchronize do
- @invoker.unregist(@name)
- server = @server
- @server = nil
- server.stop_service
- true
- end
- end
-
- def alive?
- @server ? @server.alive? : false
- end
- end
-end
diff --git a/ruby_2_2/lib/drb/extservm.rb b/ruby_2_2/lib/drb/extservm.rb
deleted file mode 100644
index 8a7fc316af..0000000000
--- a/ruby_2_2/lib/drb/extservm.rb
+++ /dev/null
@@ -1,93 +0,0 @@
-=begin
- external service manager
- Copyright (c) 2000 Masatoshi SEKI
-=end
-
-require 'drb/drb'
-require 'thread'
-require 'monitor'
-
-module DRb
- class ExtServManager
- include DRbUndumped
- include MonitorMixin
-
- @@command = {}
-
- def self.command
- @@command
- end
-
- def self.command=(cmd)
- @@command = cmd
- end
-
- def initialize
- super()
- @cond = new_cond
- @servers = {}
- @waiting = []
- @queue = Queue.new
- @thread = invoke_thread
- @uri = nil
- end
- attr_accessor :uri
-
- def service(name)
- synchronize do
- while true
- server = @servers[name]
- return server if server && server.alive?
- invoke_service(name)
- @cond.wait
- end
- end
- end
-
- def regist(name, ro)
- synchronize do
- @servers[name] = ro
- @cond.signal
- end
- self
- end
-
- def unregist(name)
- synchronize do
- @servers.delete(name)
- end
- end
-
- private
- def invoke_thread
- Thread.new do
- while true
- name = @queue.pop
- invoke_service_command(name, @@command[name])
- end
- end
- end
-
- def invoke_service(name)
- @queue.push(name)
- end
-
- def invoke_service_command(name, command)
- raise "invalid command. name: #{name}" unless command
- synchronize do
- return if @servers.include?(name)
- @servers[name] = false
- end
- uri = @uri || DRb.uri
- if command.respond_to? :to_ary
- command = command.to_ary + [uri, name]
- pid = spawn(*command)
- else
- pid = spawn("#{command} #{uri} #{name}")
- end
- th = Process.detach(pid)
- th[:drb_service] = name
- th
- end
- end
-end
diff --git a/ruby_2_2/lib/drb/gw.rb b/ruby_2_2/lib/drb/gw.rb
deleted file mode 100644
index b3568ab08d..0000000000
--- a/ruby_2_2/lib/drb/gw.rb
+++ /dev/null
@@ -1,160 +0,0 @@
-require 'drb/drb'
-require 'monitor'
-
-module DRb
-
- # Gateway id conversion forms a gateway between different DRb protocols or
- # networks.
- #
- # The gateway needs to install this id conversion and create servers for
- # each of the protocols or networks it will be a gateway between. It then
- # needs to create a server that attaches to each of these networks. For
- # example:
- #
- # require 'drb/drb'
- # require 'drb/unix'
- # require 'drb/gw'
- #
- # DRb.install_id_conv DRb::GWIdConv.new
- # gw = DRb::GW.new
- # s1 = DRb::DRbServer.new 'drbunix:/path/to/gateway', gw
- # s2 = DRb::DRbServer.new 'druby://example:10000', gw
- #
- # s1.thread.join
- # s2.thread.join
- #
- # Each client must register services with the gateway, for example:
- #
- # DRb.start_service 'drbunix:', nil # an anonymous server
- # gw = DRbObject.new nil, 'drbunix:/path/to/gateway'
- # gw[:unix] = some_service
- # DRb.thread.join
-
- class GWIdConv < DRbIdConv
- def to_obj(ref) # :nodoc:
- if Array === ref && ref[0] == :DRbObject
- return DRbObject.new_with(ref[1], ref[2])
- end
- super(ref)
- end
- end
-
- # The GW provides a synchronized store for participants in the gateway to
- # communicate.
-
- class GW
- include MonitorMixin
-
- # Creates a new GW
-
- def initialize
- super()
- @hash = {}
- end
-
- # Retrieves +key+ from the GW
-
- def [](key)
- synchronize do
- @hash[key]
- end
- end
-
- # Stores value +v+ at +key+ in the GW
-
- def []=(key, v)
- synchronize do
- @hash[key] = v
- end
- end
- end
-
- class DRbObject # :nodoc:
- def self._load(s)
- uri, ref = Marshal.load(s)
- if DRb.uri == uri
- return ref ? DRb.to_obj(ref) : DRb.front
- end
-
- self.new_with(DRb.uri, [:DRbObject, uri, ref])
- end
-
- def _dump(lv)
- if DRb.uri == @uri
- if Array === @ref && @ref[0] == :DRbObject
- Marshal.dump([@ref[1], @ref[2]])
- else
- Marshal.dump([@uri, @ref]) # ??
- end
- else
- Marshal.dump([DRb.uri, [:DRbObject, @uri, @ref]])
- end
- end
- end
-end
-
-=begin
-DRb.install_id_conv(DRb::GWIdConv.new)
-
-front = DRb::GW.new
-
-s1 = DRb::DRbServer.new('drbunix:/tmp/gw_b_a', front)
-s2 = DRb::DRbServer.new('drbunix:/tmp/gw_b_c', front)
-
-s1.thread.join
-s2.thread.join
-=end
-
-=begin
-# foo.rb
-
-require 'drb/drb'
-
-class Foo
- include DRbUndumped
- def initialize(name, peer=nil)
- @name = name
- @peer = peer
- end
-
- def ping(obj)
- puts "#{@name}: ping: #{obj.inspect}"
- @peer.ping(self) if @peer
- end
-end
-=end
-
-=begin
-# gw_a.rb
-require 'drb/unix'
-require 'foo'
-
-obj = Foo.new('a')
-DRb.start_service("drbunix:/tmp/gw_a", obj)
-
-robj = DRbObject.new_with_uri('drbunix:/tmp/gw_b_a')
-robj[:a] = obj
-
-DRb.thread.join
-=end
-
-=begin
-# gw_c.rb
-require 'drb/unix'
-require 'foo'
-
-foo = Foo.new('c', nil)
-
-DRb.start_service("drbunix:/tmp/gw_c", nil)
-
-robj = DRbObject.new_with_uri("drbunix:/tmp/gw_b_c")
-
-puts "c->b"
-a = robj[:a]
-sleep 2
-
-a.ping(foo)
-
-DRb.thread.join
-=end
-
diff --git a/ruby_2_2/lib/drb/invokemethod.rb b/ruby_2_2/lib/drb/invokemethod.rb
deleted file mode 100644
index 71ebec11f6..0000000000
--- a/ruby_2_2/lib/drb/invokemethod.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-# for ruby-1.8.0
-
-module DRb # :nodoc: all
- class DRbServer
- module InvokeMethod18Mixin
- def block_yield(x)
- if x.size == 1 && x[0].class == Array
- x[0] = DRbArray.new(x[0])
- end
- @block.call(*x)
- end
-
- def perform_with_block
- @obj.__send__(@msg_id, *@argv) do |*x|
- jump_error = nil
- begin
- block_value = block_yield(x)
- rescue LocalJumpError
- jump_error = $!
- end
- if jump_error
- case jump_error.reason
- when :break
- break(jump_error.exit_value)
- else
- raise jump_error
- end
- end
- block_value
- end
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/drb/observer.rb b/ruby_2_2/lib/drb/observer.rb
deleted file mode 100644
index cab9ebc60b..0000000000
--- a/ruby_2_2/lib/drb/observer.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require 'observer'
-
-module DRb
- # The Observable module extended to DRb. See Observable for details.
- module DRbObservable
- include Observable
-
- # Notifies observers of a change in state. See also
- # Observable#notify_observers
- def notify_observers(*arg)
- if defined? @observer_state and @observer_state
- if defined? @observer_peers
- @observer_peers.each do |observer, method|
- begin
- observer.send(method, *arg)
- rescue
- delete_observer(observer)
- end
- end
- end
- @observer_state = false
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/drb/ssl.rb b/ruby_2_2/lib/drb/ssl.rb
deleted file mode 100644
index efd8271a78..0000000000
--- a/ruby_2_2/lib/drb/ssl.rb
+++ /dev/null
@@ -1,345 +0,0 @@
-require 'socket'
-require 'openssl'
-require 'drb/drb'
-require 'singleton'
-
-module DRb
-
- # The protocol for DRb over an SSL socket
- #
- # The URI for a DRb socket over SSL is:
- # <code>drbssl://<host>:<port>?<option></code>. The option is optional
- class DRbSSLSocket < DRbTCPSocket
-
- # SSLConfig handles the needed SSL information for establishing a
- # DRbSSLSocket connection, including generating the X509 / RSA pair.
- #
- # An instance of this config can be passed to DRbSSLSocket.new,
- # DRbSSLSocket.open and DRbSSLSocket.open_server
- #
- # See DRb::DRbSSLSocket::SSLConfig.new for more details
- class SSLConfig
-
- # Default values for a SSLConfig instance.
- #
- # See DRb::DRbSSLSocket::SSLConfig.new for more details
- DEFAULT = {
- :SSLCertificate => nil,
- :SSLPrivateKey => nil,
- :SSLClientCA => nil,
- :SSLCACertificatePath => nil,
- :SSLCACertificateFile => nil,
- :SSLTmpDhCallback => nil,
- :SSLVerifyMode => ::OpenSSL::SSL::VERIFY_NONE,
- :SSLVerifyDepth => nil,
- :SSLVerifyCallback => nil, # custom verification
- :SSLCertificateStore => nil,
- # Must specify if you use auto generated certificate.
- :SSLCertName => nil, # e.g. [["CN","fqdn.example.com"]]
- :SSLCertComment => "Generated by Ruby/OpenSSL"
- }
-
- # Create a new DRb::DRbSSLSocket::SSLConfig instance
- #
- # The DRb::DRbSSLSocket will take either a +config+ Hash or an instance
- # of SSLConfig, and will setup the certificate for its session for the
- # configuration. If want it to generate a generic certificate, the bare
- # minimum is to provide the :SSLCertName
- #
- # === Config options
- #
- # From +config+ Hash:
- #
- # :SSLCertificate ::
- # An instance of OpenSSL::X509::Certificate. If this is not provided,
- # then a generic X509 is generated, with a correspond :SSLPrivateKey
- #
- # :SSLPrivateKey ::
- # A private key instance, like OpenSSL::PKey::RSA. This key must be
- # the key that signed the :SSLCertificate
- #
- # :SSLClientCA ::
- # An OpenSSL::X509::Certificate, or Array of certificates that will
- # used as ClientCAs in the SSL Context
- #
- # :SSLCACertificatePath ::
- # A path to the directory of CA certificates. The certificates must
- # be in PEM format.
- #
- # :SSLCACertificateFile ::
- # A path to a CA certificate file, in PEM format.
- #
- # :SSLTmpDhCallback ::
- # A DH callback. See OpenSSL::SSL::SSLContext.tmp_dh_callback
- #
- # :SSLVerifyMode ::
- # This is the SSL verification mode. See OpenSSL::SSL::VERIFY_* for
- # available modes. The default is OpenSSL::SSL::VERIFY_NONE
- #
- # :SSLVerifyDepth ::
- # Number of CA certificates to walk, when verifying a certificate
- # chain.
- #
- # :SSLVerifyCallback ::
- # A callback to be used for additional verification. See
- # OpenSSL::SSL::SSLContext.verify_callback
- #
- # :SSLCertificateStore ::
- # A OpenSSL::X509::Store used for verification of certificates
- #
- # :SSLCertName ::
- # Issuer name for the certificate. This is required when generating
- # the certificate (if :SSLCertificate and :SSLPrivateKey were not
- # given). The value of this is to be an Array of pairs:
- #
- # [["C", "Raleigh"], ["ST","North Carolina"],
- # ["CN","fqdn.example.com"]]
- #
- # See also OpenSSL::X509::Name
- #
- # :SSLCertComment ::
- # A comment to be used for generating the certificate. The default is
- # "Generated by Ruby/OpenSSL"
- #
- #
- # === Example
- #
- # These values can be added after the fact, like a Hash.
- #
- # require 'drb/ssl'
- # c = DRb::DRbSSLSocket::SSLConfig.new {}
- # c[:SSLCertificate] =
- # OpenSSL::X509::Certificate.new(File.read('mycert.crt'))
- # c[:SSLPrivateKey] = OpenSSL::PKey::RSA.new(File.read('mycert.key'))
- # c[:SSLVerifyMode] = OpenSSL::SSL::VERIFY_PEER
- # c[:SSLCACertificatePath] = "/etc/ssl/certs/"
- # c.setup_certificate
- #
- # or
- #
- # require 'drb/ssl'
- # c = DRb::DRbSSLSocket::SSLConfig.new({
- # :SSLCertName => [["CN" => DRb::DRbSSLSocket.getservername]]
- # })
- # c.setup_certificate
- #
- def initialize(config)
- @config = config
- @cert = config[:SSLCertificate]
- @pkey = config[:SSLPrivateKey]
- @ssl_ctx = nil
- end
-
- # A convenience method to access the values like a Hash
- def [](key);
- @config[key] || DEFAULT[key]
- end
-
- # Connect to IO +tcp+, with context of the current certificate
- # configuration
- def connect(tcp)
- ssl = ::OpenSSL::SSL::SSLSocket.new(tcp, @ssl_ctx)
- ssl.sync = true
- ssl.connect
- ssl
- end
-
- # Accept connection to IO +tcp+, with context of the current certificate
- # configuration
- def accept(tcp)
- ssl = OpenSSL::SSL::SSLSocket.new(tcp, @ssl_ctx)
- ssl.sync = true
- ssl.accept
- ssl
- end
-
- # Ensures that :SSLCertificate and :SSLPrivateKey have been provided
- # or that a new certificate is generated with the other parameters
- # provided.
- def setup_certificate
- if @cert && @pkey
- return
- end
-
- rsa = OpenSSL::PKey::RSA.new(1024){|p, n|
- next unless self[:verbose]
- case p
- when 0; $stderr.putc "." # BN_generate_prime
- when 1; $stderr.putc "+" # BN_generate_prime
- when 2; $stderr.putc "*" # searching good prime,
- # n = #of try,
- # but also data from BN_generate_prime
- when 3; $stderr.putc "\n" # found good prime, n==0 - p, n==1 - q,
- # but also data from BN_generate_prime
- else; $stderr.putc "*" # BN_generate_prime
- end
- }
-
- cert = OpenSSL::X509::Certificate.new
- cert.version = 3
- cert.serial = 0
- name = OpenSSL::X509::Name.new(self[:SSLCertName])
- cert.subject = name
- cert.issuer = name
- cert.not_before = Time.now
- cert.not_after = Time.now + (365*24*60*60)
- cert.public_key = rsa.public_key
-
- ef = OpenSSL::X509::ExtensionFactory.new(nil,cert)
- cert.extensions = [
- ef.create_extension("basicConstraints","CA:FALSE"),
- ef.create_extension("subjectKeyIdentifier", "hash") ]
- ef.issuer_certificate = cert
- cert.add_extension(ef.create_extension("authorityKeyIdentifier",
- "keyid:always,issuer:always"))
- if comment = self[:SSLCertComment]
- cert.add_extension(ef.create_extension("nsComment", comment))
- end
- cert.sign(rsa, OpenSSL::Digest::SHA1.new)
-
- @cert = cert
- @pkey = rsa
- end
-
- # Establish the OpenSSL::SSL::SSLContext with the configuration
- # parameters provided.
- def setup_ssl_context
- ctx = ::OpenSSL::SSL::SSLContext.new
- ctx.cert = @cert
- ctx.key = @pkey
- ctx.client_ca = self[:SSLClientCA]
- ctx.ca_path = self[:SSLCACertificatePath]
- ctx.ca_file = self[:SSLCACertificateFile]
- ctx.tmp_dh_callback = self[:SSLTmpDhCallback]
- ctx.verify_mode = self[:SSLVerifyMode]
- ctx.verify_depth = self[:SSLVerifyDepth]
- ctx.verify_callback = self[:SSLVerifyCallback]
- ctx.cert_store = self[:SSLCertificateStore]
- @ssl_ctx = ctx
- end
- end
-
- # Parse the dRuby +uri+ for an SSL connection.
- #
- # Expects drbssl://...
- #
- # Raises DRbBadScheme or DRbBadURI if +uri+ is not matching or malformed
- def self.parse_uri(uri) # :nodoc:
- if uri =~ /^drbssl:\/\/(.*?):(\d+)(\?(.*))?$/
- host = $1
- port = $2.to_i
- option = $4
- [host, port, option]
- else
- raise(DRbBadScheme, uri) unless uri =~ /^drbssl:/
- raise(DRbBadURI, 'can\'t parse uri:' + uri)
- end
- end
-
- # Return an DRb::DRbSSLSocket instance as a client-side connection,
- # with the SSL connected. This is called from DRb::start_service or while
- # connecting to a remote object:
- #
- # DRb.start_service 'drbssl://localhost:0', front, config
- #
- # +uri+ is the URI we are connected to,
- # <code>'drbssl://localhost:0'</code> above, +config+ is our
- # configuration. Either a Hash or DRb::DRbSSLSocket::SSLConfig
- def self.open(uri, config)
- host, port, = parse_uri(uri)
- host.untaint
- port.untaint
- soc = TCPSocket.open(host, port)
- ssl_conf = SSLConfig::new(config)
- ssl_conf.setup_ssl_context
- ssl = ssl_conf.connect(soc)
- self.new(uri, ssl, ssl_conf, true)
- end
-
- # Returns a DRb::DRbSSLSocket instance as a server-side connection, with
- # the SSL connected. This is called from DRb::start_service or while
- # connecting to a remote object:
- #
- # DRb.start_service 'drbssl://localhost:0', front, config
- #
- # +uri+ is the URI we are connected to,
- # <code>'drbssl://localhost:0'</code> above, +config+ is our
- # configuration. Either a Hash or DRb::DRbSSLSocket::SSLConfig
- def self.open_server(uri, config)
- uri = 'drbssl://:0' unless uri
- host, port, = parse_uri(uri)
- if host.size == 0
- host = getservername
- soc = open_server_inaddr_any(host, port)
- else
- soc = TCPServer.open(host, port)
- end
- port = soc.addr[1] if port == 0
- @uri = "drbssl://#{host}:#{port}"
-
- ssl_conf = SSLConfig.new(config)
- ssl_conf.setup_certificate
- ssl_conf.setup_ssl_context
- self.new(@uri, soc, ssl_conf, false)
- end
-
- # This is a convenience method to parse +uri+ and separate out any
- # additional options appended in the +uri+.
- #
- # Returns an option-less uri and the option => [uri,option]
- #
- # The +config+ is completely unused, so passing nil is sufficient.
- def self.uri_option(uri, config) # :nodoc:
- host, port, option = parse_uri(uri)
- return "drbssl://#{host}:#{port}", option
- end
-
- # Create a DRb::DRbSSLSocket instance.
- #
- # +uri+ is the URI we are connected to.
- # +soc+ is the tcp socket we are bound to.
- # +config+ is our configuration. Either a Hash or SSLConfig
- # +is_established+ is a boolean of whether +soc+ is currently established
- #
- # This is called automatically based on the DRb protocol.
- def initialize(uri, soc, config, is_established)
- @ssl = is_established ? soc : nil
- super(uri, soc.to_io, config)
- end
-
- # Returns the SSL stream
- def stream; @ssl; end # :nodoc:
-
- # Closes the SSL stream before closing the dRuby connection.
- def close # :nodoc:
- if @ssl
- @ssl.close
- @ssl = nil
- end
- super
- end
-
- def accept # :nodoc:
- begin
- while true
- soc = accept_or_shutdown
- return nil unless soc
- break if (@acl ? @acl.allow_socket?(soc) : true)
- soc.close
- end
- begin
- ssl = @config.accept(soc)
- rescue Exception
- soc.close
- raise
- end
- self.class.new(uri, ssl, @config, true)
- rescue OpenSSL::SSL::SSLError
- warn("#{__FILE__}:#{__LINE__}: warning: #{$!.message} (#{$!.class})") if @config[:verbose]
- retry
- end
- end
- end
-
- DRbProtocol.add_protocol(DRbSSLSocket)
-end
diff --git a/ruby_2_2/lib/drb/timeridconv.rb b/ruby_2_2/lib/drb/timeridconv.rb
deleted file mode 100644
index 423b4563fa..0000000000
--- a/ruby_2_2/lib/drb/timeridconv.rb
+++ /dev/null
@@ -1,95 +0,0 @@
-require 'drb/drb'
-require 'monitor'
-
-module DRb
-
- # Timer id conversion keeps objects alive for a certain amount of time after
- # their last access. The default time period is 600 seconds and can be
- # changed upon initialization.
- #
- # To use TimerIdConv:
- #
- # DRb.install_id_conv TimerIdConv.new 60 # one minute
-
- class TimerIdConv < DRbIdConv
- class TimerHolder2 # :nodoc:
- include MonitorMixin
-
- class InvalidIndexError < RuntimeError; end
-
- def initialize(keeping=600)
- super()
- @sentinel = Object.new
- @gc = {}
- @renew = {}
- @keeping = keeping
- @expires = Time.now + @keeping
- end
-
- def add(obj)
- synchronize do
- rotate
- key = obj.__id__
- @renew[key] = obj
- return key
- end
- end
-
- def fetch(key, dv=@sentinel)
- synchronize do
- rotate
- obj = peek(key)
- if obj == @sentinel
- return dv unless dv == @sentinel
- raise InvalidIndexError
- end
- @renew[key] = obj # KeepIt
- return obj
- end
- end
-
- private
- def peek(key)
- synchronize do
- return @renew.fetch(key) { @gc.fetch(key, @sentinel) }
- end
- end
-
- def rotate
- synchronize do
- return if @expires > Time.now
- @gc = @renew # GCed
- @renew = {}
- @expires = Time.now + @keeping
- end
- end
-
- def keeper
- Thread.new do
- loop do
- rotate
- sleep(@keeping)
- end
- end
- end
- end
-
- # Creates a new TimerIdConv which will hold objects for +keeping+ seconds.
- def initialize(keeping=600)
- @holder = TimerHolder2.new(keeping)
- end
-
- def to_obj(ref) # :nodoc:
- return super if ref.nil?
- @holder.fetch(ref)
- rescue TimerHolder2::InvalidIndexError
- raise "invalid reference"
- end
-
- def to_id(obj) # :nodoc:
- return @holder.add(obj)
- end
- end
-end
-
-# DRb.install_id_conv(TimerIdConv.new)
diff --git a/ruby_2_2/lib/drb/unix.rb b/ruby_2_2/lib/drb/unix.rb
deleted file mode 100644
index 3fb8d0ecce..0000000000
--- a/ruby_2_2/lib/drb/unix.rb
+++ /dev/null
@@ -1,117 +0,0 @@
-require 'socket'
-require 'drb/drb'
-require 'tmpdir'
-
-raise(LoadError, "UNIXServer is required") unless defined?(UNIXServer)
-
-module DRb
-
- # Implements DRb over a UNIX socket
- #
- # DRb UNIX socket URIs look like <code>drbunix:<path>?<option></code>. The
- # option is optional.
-
- class DRbUNIXSocket < DRbTCPSocket
- # :stopdoc:
- def self.parse_uri(uri)
- if /^drbunix:(.*?)(\?(.*))?$/ =~ uri
- filename = $1
- option = $3
- [filename, option]
- else
- raise(DRbBadScheme, uri) unless uri =~ /^drbunix:/
- raise(DRbBadURI, 'can\'t parse uri:' + uri)
- end
- end
-
- def self.open(uri, config)
- filename, = parse_uri(uri)
- filename.untaint
- soc = UNIXSocket.open(filename)
- self.new(uri, soc, config)
- end
-
- def self.open_server(uri, config)
- filename, = parse_uri(uri)
- if filename.size == 0
- soc = temp_server
- filename = soc.path
- uri = 'drbunix:' + soc.path
- else
- soc = UNIXServer.open(filename)
- end
- owner = config[:UNIXFileOwner]
- group = config[:UNIXFileGroup]
- if owner || group
- require 'etc'
- owner = Etc.getpwnam( owner ).uid if owner
- group = Etc.getgrnam( group ).gid if group
- File.chown owner, group, filename
- end
- mode = config[:UNIXFileMode]
- File.chmod(mode, filename) if mode
-
- self.new(uri, soc, config, true)
- end
-
- def self.uri_option(uri, config)
- filename, option = parse_uri(uri)
- return "drbunix:#{filename}", option
- end
-
- def initialize(uri, soc, config={}, server_mode = false)
- super(uri, soc, config)
- set_sockopt(@socket)
- @server_mode = server_mode
- @acl = nil
- end
-
- # import from tempfile.rb
- Max_try = 10
- private
- def self.temp_server
- tmpdir = Dir::tmpdir
- n = 0
- while true
- begin
- tmpname = sprintf('%s/druby%d.%d', tmpdir, $$, n)
- lock = tmpname + '.lock'
- unless File.exist?(tmpname) or File.exist?(lock)
- Dir.mkdir(lock)
- break
- end
- rescue
- raise "cannot generate tempfile `%s'" % tmpname if n >= Max_try
- #sleep(1)
- end
- n += 1
- end
- soc = UNIXServer.new(tmpname)
- Dir.rmdir(lock)
- soc
- end
-
- public
- def close
- return unless @socket
- path = @socket.path if @server_mode
- @socket.close
- File.unlink(path) if @server_mode
- @socket = nil
- close_shutdown_pipe
- end
-
- def accept
- s = accept_or_shutdown
- return nil unless s
- self.class.new(nil, s, @config)
- end
-
- def set_sockopt(soc)
- soc.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::FD_CLOEXEC
- end
- end
-
- DRbProtocol.add_protocol(DRbUNIXSocket)
- # :startdoc:
-end
diff --git a/ruby_2_2/lib/e2mmap.rb b/ruby_2_2/lib/e2mmap.rb
deleted file mode 100644
index 1eb5b51678..0000000000
--- a/ruby_2_2/lib/e2mmap.rb
+++ /dev/null
@@ -1,172 +0,0 @@
-#
-#--
-# e2mmap.rb - for Ruby 1.1
-# $Release Version: 2.0$
-# $Revision: 1.10 $
-# by Keiju ISHITSUKA
-#
-#++
-#
-# Helper module for easily defining exceptions with predefined messages.
-#
-# == Usage
-#
-# 1.
-# class Foo
-# extend Exception2MessageMapper
-# def_e2message ExistingExceptionClass, "message..."
-# def_exception :NewExceptionClass, "message..."[, superclass]
-# ...
-# end
-#
-# 2.
-# module Error
-# extend Exception2MessageMapper
-# def_e2message ExistingExceptionClass, "message..."
-# def_exception :NewExceptionClass, "message..."[, superclass]
-# ...
-# end
-# class Foo
-# include Error
-# ...
-# end
-#
-# foo = Foo.new
-# foo.Fail ....
-#
-# 3.
-# module Error
-# extend Exception2MessageMapper
-# def_e2message ExistingExceptionClass, "message..."
-# def_exception :NewExceptionClass, "message..."[, superclass]
-# ...
-# end
-# class Foo
-# extend Exception2MessageMapper
-# include Error
-# ...
-# end
-#
-# Foo.Fail NewExceptionClass, arg...
-# Foo.Fail ExistingExceptionClass, arg...
-#
-#
-module Exception2MessageMapper
-
- E2MM = Exception2MessageMapper # :nodoc:
-
- def E2MM.extend_object(cl)
- super
- cl.bind(self) unless cl < E2MM
- end
-
- def bind(cl)
- self.module_eval %[
- def Raise(err = nil, *rest)
- Exception2MessageMapper.Raise(self.class, err, *rest)
- end
- alias Fail Raise
-
- def self.included(mod)
- mod.extend Exception2MessageMapper
- end
- ]
- end
-
- # Fail(err, *rest)
- # err: exception
- # rest: message arguments
- #
- def Raise(err = nil, *rest)
- E2MM.Raise(self, err, *rest)
- end
- alias Fail Raise
- alias fail Raise
-
- # def_e2message(c, m)
- # c: exception
- # m: message_form
- # define exception c with message m.
- #
- def def_e2message(c, m)
- E2MM.def_e2message(self, c, m)
- end
-
- # def_exception(n, m, s)
- # n: exception_name
- # m: message_form
- # s: superclass(default: StandardError)
- # define exception named ``c'' with message m.
- #
- def def_exception(n, m, s = StandardError)
- E2MM.def_exception(self, n, m, s)
- end
-
- #
- # Private definitions.
- #
- # {[class, exp] => message, ...}
- @MessageMap = {}
-
- # E2MM.def_e2message(k, e, m)
- # k: class to define exception under.
- # e: exception
- # m: message_form
- # define exception c with message m.
- #
- def E2MM.def_e2message(k, c, m)
- E2MM.instance_eval{@MessageMap[[k, c]] = m}
- c
- end
-
- # E2MM.def_exception(k, n, m, s)
- # k: class to define exception under.
- # n: exception_name
- # m: message_form
- # s: superclass(default: StandardError)
- # define exception named ``c'' with message m.
- #
- def E2MM.def_exception(k, n, m, s = StandardError)
- n = n.id2name if n.kind_of?(Fixnum)
- e = Class.new(s)
- E2MM.instance_eval{@MessageMap[[k, e]] = m}
- k.const_set(n, e)
- end
-
- # Fail(klass, err, *rest)
- # klass: class to define exception under.
- # err: exception
- # rest: message arguments
- #
- def E2MM.Raise(klass = E2MM, err = nil, *rest)
- if form = e2mm_message(klass, err)
- b = $@.nil? ? caller(1) : $@
- b.shift if b[0] =~ /^#{Regexp.quote(__FILE__)}:/
- raise err, sprintf(form, *rest), b
- else
- E2MM.Fail E2MM, ErrNotRegisteredException, err.inspect
- end
- end
- class << E2MM
- alias Fail Raise
- end
-
- def E2MM.e2mm_message(klass, exp)
- for c in klass.ancestors
- if mes = @MessageMap[[c,exp]]
- m = klass.instance_eval('"' + mes + '"')
- return m
- end
- end
- nil
- end
- class << self
- alias message e2mm_message
- end
-
- E2MM.def_exception(E2MM,
- :ErrNotRegisteredException,
- "not registered exception(%s)")
-end
-
-
diff --git a/ruby_2_2/lib/erb.rb b/ruby_2_2/lib/erb.rb
deleted file mode 100644
index 25654d62c5..0000000000
--- a/ruby_2_2/lib/erb.rb
+++ /dev/null
@@ -1,1022 +0,0 @@
-# -*- coding: us-ascii -*-
-# = ERB -- Ruby Templating
-#
-# Author:: Masatoshi SEKI
-# Documentation:: James Edward Gray II, Gavin Sinclair, and Simon Chiang
-#
-# See ERB for primary documentation and ERB::Util for a couple of utility
-# routines.
-#
-# Copyright (c) 1999-2000,2002,2003 Masatoshi SEKI
-#
-# You can redistribute it and/or modify it under the same terms as Ruby.
-
-require "cgi/util"
-
-#
-# = ERB -- Ruby Templating
-#
-# == Introduction
-#
-# ERB provides an easy to use but powerful templating system for Ruby. Using
-# ERB, actual Ruby code can be added to any plain text document for the
-# purposes of generating document information details and/or flow control.
-#
-# A very simple example is this:
-#
-# require 'erb'
-#
-# x = 42
-# template = ERB.new <<-EOF
-# The value of x is: <%= x %>
-# EOF
-# puts template.result(binding)
-#
-# <em>Prints:</em> The value of x is: 42
-#
-# More complex examples are given below.
-#
-#
-# == Recognized Tags
-#
-# ERB recognizes certain tags in the provided template and converts them based
-# on the rules below:
-#
-# <% Ruby code -- inline with output %>
-# <%= Ruby expression -- replace with result %>
-# <%# comment -- ignored -- useful in testing %>
-# % a line of Ruby code -- treated as <% line %> (optional -- see ERB.new)
-# %% replaced with % if first thing on a line and % processing is used
-# <%% or %%> -- replace with <% or %> respectively
-#
-# All other text is passed through ERB filtering unchanged.
-#
-#
-# == Options
-#
-# There are several settings you can change when you use ERB:
-# * the nature of the tags that are recognized;
-# * the value of <tt>$SAFE</tt> under which the template is run;
-# * the binding used to resolve local variables in the template.
-#
-# See the ERB.new and ERB#result methods for more detail.
-#
-# == Character encodings
-#
-# ERB (or Ruby code generated by ERB) returns a string in the same
-# character encoding as the input string. When the input string has
-# a magic comment, however, it returns a string in the encoding specified
-# by the magic comment.
-#
-# # -*- coding: utf-8 -*-
-# require 'erb'
-#
-# template = ERB.new <<EOF
-# <%#-*- coding: Big5 -*-%>
-# \_\_ENCODING\_\_ is <%= \_\_ENCODING\_\_ %>.
-# EOF
-# puts template.result
-#
-# <em>Prints:</em> \_\_ENCODING\_\_ is Big5.
-#
-#
-# == Examples
-#
-# === Plain Text
-#
-# ERB is useful for any generic templating situation. Note that in this example, we use the
-# convenient "% at start of line" tag, and we quote the template literally with
-# <tt>%q{...}</tt> to avoid trouble with the backslash.
-#
-# require "erb"
-#
-# # Create template.
-# template = %q{
-# From: James Edward Gray II <james@grayproductions.net>
-# To: <%= to %>
-# Subject: Addressing Needs
-#
-# <%= to[/\w+/] %>:
-#
-# Just wanted to send a quick note assuring that your needs are being
-# addressed.
-#
-# I want you to know that my team will keep working on the issues,
-# especially:
-#
-# <%# ignore numerous minor requests -- focus on priorities %>
-# % priorities.each do |priority|
-# * <%= priority %>
-# % end
-#
-# Thanks for your patience.
-#
-# James Edward Gray II
-# }.gsub(/^ /, '')
-#
-# message = ERB.new(template, 0, "%<>")
-#
-# # Set up template data.
-# to = "Community Spokesman <spokesman@ruby_community.org>"
-# priorities = [ "Run Ruby Quiz",
-# "Document Modules",
-# "Answer Questions on Ruby Talk" ]
-#
-# # Produce result.
-# email = message.result
-# puts email
-#
-# <i>Generates:</i>
-#
-# From: James Edward Gray II <james@grayproductions.net>
-# To: Community Spokesman <spokesman@ruby_community.org>
-# Subject: Addressing Needs
-#
-# Community:
-#
-# Just wanted to send a quick note assuring that your needs are being addressed.
-#
-# I want you to know that my team will keep working on the issues, especially:
-#
-# * Run Ruby Quiz
-# * Document Modules
-# * Answer Questions on Ruby Talk
-#
-# Thanks for your patience.
-#
-# James Edward Gray II
-#
-# === Ruby in HTML
-#
-# ERB is often used in <tt>.rhtml</tt> files (HTML with embedded Ruby). Notice the need in
-# this example to provide a special binding when the template is run, so that the instance
-# variables in the Product object can be resolved.
-#
-# require "erb"
-#
-# # Build template data class.
-# class Product
-# def initialize( code, name, desc, cost )
-# @code = code
-# @name = name
-# @desc = desc
-# @cost = cost
-#
-# @features = [ ]
-# end
-#
-# def add_feature( feature )
-# @features << feature
-# end
-#
-# # Support templating of member data.
-# def get_binding
-# binding
-# end
-#
-# # ...
-# end
-#
-# # Create template.
-# template = %{
-# <html>
-# <head><title>Ruby Toys -- <%= @name %></title></head>
-# <body>
-#
-# <h1><%= @name %> (<%= @code %>)</h1>
-# <p><%= @desc %></p>
-#
-# <ul>
-# <% @features.each do |f| %>
-# <li><b><%= f %></b></li>
-# <% end %>
-# </ul>
-#
-# <p>
-# <% if @cost < 10 %>
-# <b>Only <%= @cost %>!!!</b>
-# <% else %>
-# Call for a price, today!
-# <% end %>
-# </p>
-#
-# </body>
-# </html>
-# }.gsub(/^ /, '')
-#
-# rhtml = ERB.new(template)
-#
-# # Set up template data.
-# toy = Product.new( "TZ-1002",
-# "Rubysapien",
-# "Geek's Best Friend! Responds to Ruby commands...",
-# 999.95 )
-# toy.add_feature("Listens for verbal commands in the Ruby language!")
-# toy.add_feature("Ignores Perl, Java, and all C variants.")
-# toy.add_feature("Karate-Chop Action!!!")
-# toy.add_feature("Matz signature on left leg.")
-# toy.add_feature("Gem studded eyes... Rubies, of course!")
-#
-# # Produce result.
-# rhtml.run(toy.get_binding)
-#
-# <i>Generates (some blank lines removed):</i>
-#
-# <html>
-# <head><title>Ruby Toys -- Rubysapien</title></head>
-# <body>
-#
-# <h1>Rubysapien (TZ-1002)</h1>
-# <p>Geek's Best Friend! Responds to Ruby commands...</p>
-#
-# <ul>
-# <li><b>Listens for verbal commands in the Ruby language!</b></li>
-# <li><b>Ignores Perl, Java, and all C variants.</b></li>
-# <li><b>Karate-Chop Action!!!</b></li>
-# <li><b>Matz signature on left leg.</b></li>
-# <li><b>Gem studded eyes... Rubies, of course!</b></li>
-# </ul>
-#
-# <p>
-# Call for a price, today!
-# </p>
-#
-# </body>
-# </html>
-#
-#
-# == Notes
-#
-# There are a variety of templating solutions available in various Ruby projects:
-# * ERB's big brother, eRuby, works the same but is written in C for speed;
-# * Amrita (smart at producing HTML/XML);
-# * cs/Template (written in C for speed);
-# * RDoc, distributed with Ruby, uses its own template engine, which can be reused elsewhere;
-# * and others; search {RubyGems.org}[https://rubygems.org/] or
-# {The Ruby Toolbox}[https://www.ruby-toolbox.com/].
-#
-# Rails, the web application framework, uses ERB to create views.
-#
-class ERB
- Revision = '$Date:: $' # :nodoc: #'
-
- # Returns revision information for the erb.rb module.
- def self.version
- "erb.rb [2.1.0 #{ERB::Revision.split[1]}]"
- end
-end
-
-#--
-# ERB::Compiler
-class ERB
- # = ERB::Compiler
- #
- # Compiles ERB templates into Ruby code; the compiled code produces the
- # template result when evaluated. ERB::Compiler provides hooks to define how
- # generated output is handled.
- #
- # Internally ERB does something like this to generate the code returned by
- # ERB#src:
- #
- # compiler = ERB::Compiler.new('<>')
- # compiler.pre_cmd = ["_erbout=''"]
- # compiler.put_cmd = "_erbout.concat"
- # compiler.insert_cmd = "_erbout.concat"
- # compiler.post_cmd = ["_erbout"]
- #
- # code, enc = compiler.compile("Got <%= obj %>!\n")
- # puts code
- #
- # <i>Generates</i>:
- #
- # #coding:UTF-8
- # _erbout=''; _erbout.concat "Got "; _erbout.concat(( obj ).to_s); _erbout.concat "!\n"; _erbout
- #
- # By default the output is sent to the print method. For example:
- #
- # compiler = ERB::Compiler.new('<>')
- # code, enc = compiler.compile("Got <%= obj %>!\n")
- # puts code
- #
- # <i>Generates</i>:
- #
- # #coding:UTF-8
- # print "Got "; print(( obj ).to_s); print "!\n"
- #
- # == Evaluation
- #
- # The compiled code can be used in any context where the names in the code
- # correctly resolve. Using the last example, each of these print 'Got It!'
- #
- # Evaluate using a variable:
- #
- # obj = 'It'
- # eval code
- #
- # Evaluate using an input:
- #
- # mod = Module.new
- # mod.module_eval %{
- # def get(obj)
- # #{code}
- # end
- # }
- # extend mod
- # get('It')
- #
- # Evaluate using an accessor:
- #
- # klass = Class.new Object
- # klass.class_eval %{
- # attr_accessor :obj
- # def initialize(obj)
- # @obj = obj
- # end
- # def get_it
- # #{code}
- # end
- # }
- # klass.new('It').get_it
- #
- # Good! See also ERB#def_method, ERB#def_module, and ERB#def_class.
- class Compiler # :nodoc:
- class PercentLine # :nodoc:
- def initialize(str)
- @value = str
- end
- attr_reader :value
- alias :to_s :value
-
- def empty?
- @value.empty?
- end
- end
-
- class Scanner # :nodoc:
- @scanner_map = {}
- def self.regist_scanner(klass, trim_mode, percent)
- @scanner_map[[trim_mode, percent]] = klass
- end
-
- def self.default_scanner=(klass)
- @default_scanner = klass
- end
-
- def self.make_scanner(src, trim_mode, percent)
- klass = @scanner_map.fetch([trim_mode, percent], @default_scanner)
- klass.new(src, trim_mode, percent)
- end
-
- def initialize(src, trim_mode, percent)
- @src = src
- @stag = nil
- end
- attr_accessor :stag
-
- def scan; end
- end
-
- class TrimScanner < Scanner # :nodoc:
- def initialize(src, trim_mode, percent)
- super
- @trim_mode = trim_mode
- @percent = percent
- if @trim_mode == '>'
- @scan_line = self.method(:trim_line1)
- elsif @trim_mode == '<>'
- @scan_line = self.method(:trim_line2)
- elsif @trim_mode == '-'
- @scan_line = self.method(:explicit_trim_line)
- else
- @scan_line = self.method(:scan_line)
- end
- end
- attr_accessor :stag
-
- def scan(&block)
- @stag = nil
- if @percent
- @src.each_line do |line|
- percent_line(line, &block)
- end
- else
- @scan_line.call(@src, &block)
- end
- nil
- end
-
- def percent_line(line, &block)
- if @stag || line[0] != ?%
- return @scan_line.call(line, &block)
- end
-
- line[0] = ''
- if line[0] == ?%
- @scan_line.call(line, &block)
- else
- yield(PercentLine.new(line.chomp))
- end
- end
-
- def scan_line(line)
- line.scan(/(.*?)(<%%|%%>|<%=|<%#|<%|%>|\n|\z)/m) do |tokens|
- tokens.each do |token|
- next if token.empty?
- yield(token)
- end
- end
- end
-
- def trim_line1(line)
- line.scan(/(.*?)(<%%|%%>|<%=|<%#|<%|%>\n|%>|\n|\z)/m) do |tokens|
- tokens.each do |token|
- next if token.empty?
- if token == "%>\n"
- yield('%>')
- yield(:cr)
- else
- yield(token)
- end
- end
- end
- end
-
- def trim_line2(line)
- head = nil
- line.scan(/(.*?)(<%%|%%>|<%=|<%#|<%|%>\n|%>|\n|\z)/m) do |tokens|
- tokens.each do |token|
- next if token.empty?
- head = token unless head
- if token == "%>\n"
- yield('%>')
- if is_erb_stag?(head)
- yield(:cr)
- else
- yield("\n")
- end
- head = nil
- else
- yield(token)
- head = nil if token == "\n"
- end
- end
- end
- end
-
- def explicit_trim_line(line)
- line.scan(/(.*?)(^[ \t]*<%\-|<%\-|<%%|%%>|<%=|<%#|<%|-%>\n|-%>|%>|\z)/m) do |tokens|
- tokens.each do |token|
- next if token.empty?
- if @stag.nil? && /[ \t]*<%-/ =~ token
- yield('<%')
- elsif @stag && token == "-%>\n"
- yield('%>')
- yield(:cr)
- elsif @stag && token == '-%>'
- yield('%>')
- else
- yield(token)
- end
- end
- end
- end
-
- ERB_STAG = %w(<%= <%# <%)
- def is_erb_stag?(s)
- ERB_STAG.member?(s)
- end
- end
-
- Scanner.default_scanner = TrimScanner
-
- class SimpleScanner < Scanner # :nodoc:
- def scan
- @src.scan(/(.*?)(<%%|%%>|<%=|<%#|<%|%>|\n|\z)/m) do |tokens|
- tokens.each do |token|
- next if token.empty?
- yield(token)
- end
- end
- end
- end
-
- Scanner.regist_scanner(SimpleScanner, nil, false)
-
- begin
- require 'strscan'
- class SimpleScanner2 < Scanner # :nodoc:
- def scan
- stag_reg = /(.*?)(<%%|<%=|<%#|<%|\z)/m
- etag_reg = /(.*?)(%%>|%>|\z)/m
- scanner = StringScanner.new(@src)
- while ! scanner.eos?
- scanner.scan(@stag ? etag_reg : stag_reg)
- yield(scanner[1])
- yield(scanner[2])
- end
- end
- end
- Scanner.regist_scanner(SimpleScanner2, nil, false)
-
- class ExplicitScanner < Scanner # :nodoc:
- def scan
- stag_reg = /(.*?)(^[ \t]*<%-|<%%|<%=|<%#|<%-|<%|\z)/m
- etag_reg = /(.*?)(%%>|-%>|%>|\z)/m
- scanner = StringScanner.new(@src)
- while ! scanner.eos?
- scanner.scan(@stag ? etag_reg : stag_reg)
- yield(scanner[1])
-
- elem = scanner[2]
- if /[ \t]*<%-/ =~ elem
- yield('<%')
- elsif elem == '-%>'
- yield('%>')
- yield(:cr) if scanner.scan(/(\n|\z)/)
- else
- yield(elem)
- end
- end
- end
- end
- Scanner.regist_scanner(ExplicitScanner, '-', false)
-
- rescue LoadError
- end
-
- class Buffer # :nodoc:
- def initialize(compiler, enc=nil)
- @compiler = compiler
- @line = []
- @script = enc ? "#coding:#{enc}\n" : ""
- @compiler.pre_cmd.each do |x|
- push(x)
- end
- end
- attr_reader :script
-
- def push(cmd)
- @line << cmd
- end
-
- def cr
- @script << (@line.join('; '))
- @line = []
- @script << "\n"
- end
-
- def close
- return unless @line
- @compiler.post_cmd.each do |x|
- push(x)
- end
- @script << (@line.join('; '))
- @line = nil
- end
- end
-
- def content_dump(s) # :nodoc:
- n = s.count("\n")
- if n > 0
- s.dump + "\n" * n
- else
- s.dump
- end
- end
-
- def add_put_cmd(out, content)
- out.push("#{@put_cmd} #{content_dump(content)}")
- end
-
- def add_insert_cmd(out, content)
- out.push("#{@insert_cmd}((#{content}).to_s)")
- end
-
- # Compiles an ERB template into Ruby code. Returns an array of the code
- # and encoding like ["code", Encoding].
- def compile(s)
- enc = s.encoding
- raise ArgumentError, "#{enc} is not ASCII compatible" if enc.dummy?
- s = s.b # see String#b
- enc = detect_magic_comment(s) || enc
- out = Buffer.new(self, enc)
-
- content = ''
- scanner = make_scanner(s)
- scanner.scan do |token|
- next if token.nil?
- next if token == ''
- if scanner.stag.nil?
- case token
- when PercentLine
- add_put_cmd(out, content) if content.size > 0
- content = ''
- out.push(token.to_s)
- out.cr
- when :cr
- out.cr
- when '<%', '<%=', '<%#'
- scanner.stag = token
- add_put_cmd(out, content) if content.size > 0
- content = ''
- when "\n"
- content << "\n"
- add_put_cmd(out, content)
- content = ''
- when '<%%'
- content << '<%'
- else
- content << token
- end
- else
- case token
- when '%>'
- case scanner.stag
- when '<%'
- if content[-1] == ?\n
- content.chop!
- out.push(content)
- out.cr
- else
- out.push(content)
- end
- when '<%='
- add_insert_cmd(out, content)
- when '<%#'
- # out.push("# #{content_dump(content)}")
- end
- scanner.stag = nil
- content = ''
- when '%%>'
- content << '%>'
- else
- content << token
- end
- end
- end
- add_put_cmd(out, content) if content.size > 0
- out.close
- return out.script, enc
- end
-
- def prepare_trim_mode(mode) # :nodoc:
- case mode
- when 1
- return [false, '>']
- when 2
- return [false, '<>']
- when 0
- return [false, nil]
- when String
- perc = mode.include?('%')
- if mode.include?('-')
- return [perc, '-']
- elsif mode.include?('<>')
- return [perc, '<>']
- elsif mode.include?('>')
- return [perc, '>']
- else
- [perc, nil]
- end
- else
- return [false, nil]
- end
- end
-
- def make_scanner(src) # :nodoc:
- Scanner.make_scanner(src, @trim_mode, @percent)
- end
-
- # Construct a new compiler using the trim_mode. See ERB::new for available
- # trim modes.
- def initialize(trim_mode)
- @percent, @trim_mode = prepare_trim_mode(trim_mode)
- @put_cmd = 'print'
- @insert_cmd = @put_cmd
- @pre_cmd = []
- @post_cmd = []
- end
- attr_reader :percent, :trim_mode
-
- # The command to handle text that ends with a newline
- attr_accessor :put_cmd
-
- # The command to handle text that is inserted prior to a newline
- attr_accessor :insert_cmd
-
- # An array of commands prepended to compiled code
- attr_accessor :pre_cmd
-
- # An array of commands appended to compiled code
- attr_accessor :post_cmd
-
- private
- def detect_magic_comment(s)
- if /\A<%#(.*)%>/ =~ s or (@percent and /\A%#(.*)/ =~ s)
- comment = $1
- comment = $1 if comment[/-\*-\s*(.*?)\s*-*-$/]
- if %r"coding\s*[=:]\s*([[:alnum:]\-_]+)" =~ comment
- enc = $1.sub(/-(?:mac|dos|unix)/i, '')
- Encoding.find(enc)
- end
- end
- end
- end
-end
-
-#--
-# ERB
-class ERB
- #
- # Constructs a new ERB object with the template specified in _str_.
- #
- # An ERB object works by building a chunk of Ruby code that will output
- # the completed template when run. If _safe_level_ is set to a non-nil value,
- # ERB code will be run in a separate thread with <b>$SAFE</b> set to the
- # provided level.
- #
- # If _trim_mode_ is passed a String containing one or more of the following
- # modifiers, ERB will adjust its code generation as listed:
- #
- # % enables Ruby code processing for lines beginning with %
- # <> omit newline for lines starting with <% and ending in %>
- # > omit newline for lines ending in %>
- # - omit blank lines ending in -%>
- #
- # _eoutvar_ can be used to set the name of the variable ERB will build up
- # its output in. This is useful when you need to run multiple ERB
- # templates through the same binding and/or when you want to control where
- # output ends up. Pass the name of the variable to be used inside a String.
- #
- # === Example
- #
- # require "erb"
- #
- # # build data class
- # class Listings
- # PRODUCT = { :name => "Chicken Fried Steak",
- # :desc => "A well messages pattie, breaded and fried.",
- # :cost => 9.95 }
- #
- # attr_reader :product, :price
- #
- # def initialize( product = "", price = "" )
- # @product = product
- # @price = price
- # end
- #
- # def build
- # b = binding
- # # create and run templates, filling member data variables
- # ERB.new(<<-'END_PRODUCT'.gsub(/^\s+/, ""), 0, "", "@product").result b
- # <%= PRODUCT[:name] %>
- # <%= PRODUCT[:desc] %>
- # END_PRODUCT
- # ERB.new(<<-'END_PRICE'.gsub(/^\s+/, ""), 0, "", "@price").result b
- # <%= PRODUCT[:name] %> -- <%= PRODUCT[:cost] %>
- # <%= PRODUCT[:desc] %>
- # END_PRICE
- # end
- # end
- #
- # # setup template data
- # listings = Listings.new
- # listings.build
- #
- # puts listings.product + "\n" + listings.price
- #
- # _Generates_
- #
- # Chicken Fried Steak
- # A well messages pattie, breaded and fried.
- #
- # Chicken Fried Steak -- 9.95
- # A well messages pattie, breaded and fried.
- #
- def initialize(str, safe_level=nil, trim_mode=nil, eoutvar='_erbout')
- @safe_level = safe_level
- compiler = make_compiler(trim_mode)
- set_eoutvar(compiler, eoutvar)
- @src, @encoding = *compiler.compile(str)
- @filename = nil
- @lineno = 0
- end
-
- ##
- # Creates a new compiler for ERB. See ERB::Compiler.new for details
-
- def make_compiler(trim_mode)
- ERB::Compiler.new(trim_mode)
- end
-
- # The Ruby code generated by ERB
- attr_reader :src
-
- # The encoding to eval
- attr_reader :encoding
-
- # The optional _filename_ argument passed to Kernel#eval when the ERB code
- # is run
- attr_accessor :filename
-
- # The optional _lineno_ argument passed to Kernel#eval when the ERB code
- # is run
- attr_accessor :lineno
-
- def location=((filename, lineno))
- @filename = filename
- @lineno = lineno if lineno
- end
-
- #
- # Can be used to set _eoutvar_ as described in ERB::new. It's probably
- # easier to just use the constructor though, since calling this method
- # requires the setup of an ERB _compiler_ object.
- #
- def set_eoutvar(compiler, eoutvar = '_erbout')
- compiler.put_cmd = "#{eoutvar}.concat"
- compiler.insert_cmd = "#{eoutvar}.concat"
- compiler.pre_cmd = ["#{eoutvar} = ''"]
- compiler.post_cmd = ["#{eoutvar}.force_encoding(__ENCODING__)"]
- end
-
- # Generate results and print them. (see ERB#result)
- def run(b=new_toplevel)
- print self.result(b)
- end
-
- #
- # Executes the generated ERB code to produce a completed template, returning
- # the results of that code. (See ERB::new for details on how this process
- # can be affected by _safe_level_.)
- #
- # _b_ accepts a Binding object which is used to set the context of
- # code evaluation.
- #
- def result(b=new_toplevel)
- if @safe_level
- proc {
- $SAFE = @safe_level
- eval(@src, b, (@filename || '(erb)'), @lineno)
- }.call
- else
- eval(@src, b, (@filename || '(erb)'), @lineno)
- end
- end
-
- ##
- # Returns a new binding each time *near* TOPLEVEL_BINDING for runs that do
- # not specify a binding.
-
- def new_toplevel
- TOPLEVEL_BINDING.dup
- end
- private :new_toplevel
-
- # Define _methodname_ as instance method of _mod_ from compiled Ruby source.
- #
- # example:
- # filename = 'example.rhtml' # 'arg1' and 'arg2' are used in example.rhtml
- # erb = ERB.new(File.read(filename))
- # erb.def_method(MyClass, 'render(arg1, arg2)', filename)
- # print MyClass.new.render('foo', 123)
- def def_method(mod, methodname, fname='(ERB)')
- src = self.src
- magic_comment = "#coding:#{@encoding}\n"
- mod.module_eval do
- eval(magic_comment + "def #{methodname}\n" + src + "\nend\n", binding, fname, -2)
- end
- end
-
- # Create unnamed module, define _methodname_ as instance method of it, and return it.
- #
- # example:
- # filename = 'example.rhtml' # 'arg1' and 'arg2' are used in example.rhtml
- # erb = ERB.new(File.read(filename))
- # erb.filename = filename
- # MyModule = erb.def_module('render(arg1, arg2)')
- # class MyClass
- # include MyModule
- # end
- def def_module(methodname='erb')
- mod = Module.new
- def_method(mod, methodname, @filename || '(ERB)')
- mod
- end
-
- # Define unnamed class which has _methodname_ as instance method, and return it.
- #
- # example:
- # class MyClass_
- # def initialize(arg1, arg2)
- # @arg1 = arg1; @arg2 = arg2
- # end
- # end
- # filename = 'example.rhtml' # @arg1 and @arg2 are used in example.rhtml
- # erb = ERB.new(File.read(filename))
- # erb.filename = filename
- # MyClass = erb.def_class(MyClass_, 'render()')
- # print MyClass.new('foo', 123).render()
- def def_class(superklass=Object, methodname='result')
- cls = Class.new(superklass)
- def_method(cls, methodname, @filename || '(ERB)')
- cls
- end
-end
-
-#--
-# ERB::Util
-class ERB
- # A utility module for conversion routines, often handy in HTML generation.
- module Util
- public
- #
- # A utility method for escaping HTML tag characters in _s_.
- #
- # require "erb"
- # include ERB::Util
- #
- # puts html_escape("is a > 0 & a < 10?")
- #
- # _Generates_
- #
- # is a &gt; 0 &amp; a &lt; 10?
- #
- def html_escape(s)
- CGI.escapeHTML(s.to_s)
- end
- alias h html_escape
- module_function :h
- module_function :html_escape
-
- #
- # A utility method for encoding the String _s_ as a URL.
- #
- # require "erb"
- # include ERB::Util
- #
- # puts url_encode("Programming Ruby: The Pragmatic Programmer's Guide")
- #
- # _Generates_
- #
- # Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
- #
- def url_encode(s)
- s.to_s.b.gsub(/[^a-zA-Z0-9_\-.]/n) { |m|
- sprintf("%%%02X", m.unpack("C")[0])
- }
- end
- alias u url_encode
- module_function :u
- module_function :url_encode
- end
-end
-
-#--
-# ERB::DefMethod
-class ERB
- # Utility module to define eRuby script as instance method.
- #
- # === Example
- #
- # example.rhtml:
- # <% for item in @items %>
- # <b><%= item %></b>
- # <% end %>
- #
- # example.rb:
- # require 'erb'
- # class MyClass
- # extend ERB::DefMethod
- # def_erb_method('render()', 'example.rhtml')
- # def initialize(items)
- # @items = items
- # end
- # end
- # print MyClass.new([10,20,30]).render()
- #
- # result:
- #
- # <b>10</b>
- #
- # <b>20</b>
- #
- # <b>30</b>
- #
- module DefMethod
- public
- # define _methodname_ as instance method of current module, using ERB
- # object or eRuby file
- def def_erb_method(methodname, erb_or_fname)
- if erb_or_fname.kind_of? String
- fname = erb_or_fname
- erb = ERB.new(File.read(fname))
- erb.def_method(self, methodname, fname)
- else
- erb = erb_or_fname
- erb.def_method(self, methodname, erb.filename || '(ERB)')
- end
- end
- module_function :def_erb_method
- end
-end
diff --git a/ruby_2_2/lib/fileutils.rb b/ruby_2_2/lib/fileutils.rb
deleted file mode 100644
index 31b67afd0d..0000000000
--- a/ruby_2_2/lib/fileutils.rb
+++ /dev/null
@@ -1,1762 +0,0 @@
-#
-# = fileutils.rb
-#
-# Copyright (c) 2000-2007 Minero Aoki
-#
-# This program is free software.
-# You can distribute/modify this program under the same terms of ruby.
-#
-# == module FileUtils
-#
-# Namespace for several file utility methods for copying, moving, removing, etc.
-#
-# === Module Functions
-#
-# require 'fileutils'
-#
-# FileUtils.cd(dir, options)
-# FileUtils.cd(dir, options) {|dir| .... }
-# FileUtils.pwd()
-# FileUtils.mkdir(dir, options)
-# FileUtils.mkdir(list, options)
-# FileUtils.mkdir_p(dir, options)
-# FileUtils.mkdir_p(list, options)
-# FileUtils.rmdir(dir, options)
-# FileUtils.rmdir(list, options)
-# FileUtils.ln(old, new, options)
-# FileUtils.ln(list, destdir, options)
-# FileUtils.ln_s(old, new, options)
-# FileUtils.ln_s(list, destdir, options)
-# FileUtils.ln_sf(src, dest, options)
-# FileUtils.cp(src, dest, options)
-# FileUtils.cp(list, dir, options)
-# FileUtils.cp_r(src, dest, options)
-# FileUtils.cp_r(list, dir, options)
-# FileUtils.mv(src, dest, options)
-# FileUtils.mv(list, dir, options)
-# FileUtils.rm(list, options)
-# FileUtils.rm_r(list, options)
-# FileUtils.rm_rf(list, options)
-# FileUtils.install(src, dest, mode = <src's>, options)
-# FileUtils.chmod(mode, list, options)
-# FileUtils.chmod_R(mode, list, options)
-# FileUtils.chown(user, group, list, options)
-# FileUtils.chown_R(user, group, list, options)
-# FileUtils.touch(list, options)
-#
-# The <tt>options</tt> parameter is a hash of options, taken from the list
-# <tt>:force</tt>, <tt>:noop</tt>, <tt>:preserve</tt>, and <tt>:verbose</tt>.
-# <tt>:noop</tt> means that no changes are made. The other two are obvious.
-# Each method documents the options that it honours.
-#
-# All methods that have the concept of a "source" file or directory can take
-# either one file or a list of files in that argument. See the method
-# documentation for examples.
-#
-# There are some `low level' methods, which do not accept any option:
-#
-# FileUtils.copy_entry(src, dest, preserve = false, dereference = false)
-# FileUtils.copy_file(src, dest, preserve = false, dereference = true)
-# FileUtils.copy_stream(srcstream, deststream)
-# FileUtils.remove_entry(path, force = false)
-# FileUtils.remove_entry_secure(path, force = false)
-# FileUtils.remove_file(path, force = false)
-# FileUtils.compare_file(path_a, path_b)
-# FileUtils.compare_stream(stream_a, stream_b)
-# FileUtils.uptodate?(file, cmp_list)
-#
-# == module FileUtils::Verbose
-#
-# This module has all methods of FileUtils module, but it outputs messages
-# before acting. This equates to passing the <tt>:verbose</tt> flag to methods
-# in FileUtils.
-#
-# == module FileUtils::NoWrite
-#
-# This module has all methods of FileUtils module, but never changes
-# files/directories. This equates to passing the <tt>:noop</tt> flag to methods
-# in FileUtils.
-#
-# == module FileUtils::DryRun
-#
-# This module has all methods of FileUtils module, but never changes
-# files/directories. This equates to passing the <tt>:noop</tt> and
-# <tt>:verbose</tt> flags to methods in FileUtils.
-#
-
-module FileUtils
-
- def self.private_module_function(name) #:nodoc:
- module_function name
- private_class_method name
- end
-
- # This hash table holds command options.
- OPT_TABLE = {} #:nodoc: internal use only
-
- #
- # Options: (none)
- #
- # Returns the name of the current directory.
- #
- def pwd
- Dir.pwd
- end
- module_function :pwd
-
- alias getwd pwd
- module_function :getwd
-
- #
- # Options: verbose
- #
- # Changes the current directory to the directory +dir+.
- #
- # If this method is called with block, resumes to the old
- # working directory after the block execution finished.
- #
- # FileUtils.cd('/', :verbose => true) # chdir and report it
- #
- # FileUtils.cd('/') do # chdir
- # [...] # do something
- # end # return to original directory
- #
- def cd(dir, options = {}, &block) # :yield: dir
- fu_check_options options, OPT_TABLE['cd']
- fu_output_message "cd #{dir}" if options[:verbose]
- Dir.chdir(dir, &block)
- fu_output_message 'cd -' if options[:verbose] and block
- end
- module_function :cd
-
- alias chdir cd
- module_function :chdir
-
- OPT_TABLE['cd'] =
- OPT_TABLE['chdir'] = [:verbose]
-
- #
- # Options: (none)
- #
- # Returns true if +new+ is newer than all +old_list+.
- # Non-existent files are older than any file.
- #
- # FileUtils.uptodate?('hello.o', %w(hello.c hello.h)) or \
- # system 'make hello.o'
- #
- def uptodate?(new, old_list)
- return false unless File.exist?(new)
- new_time = File.mtime(new)
- old_list.each do |old|
- if File.exist?(old)
- return false unless new_time > File.mtime(old)
- end
- end
- true
- end
- module_function :uptodate?
-
- def remove_tailing_slash(dir)
- dir == '/' ? dir : dir.chomp(?/)
- end
- private_module_function :remove_tailing_slash
-
- #
- # Options: mode noop verbose
- #
- # Creates one or more directories.
- #
- # FileUtils.mkdir 'test'
- # FileUtils.mkdir %w( tmp data )
- # FileUtils.mkdir 'notexist', :noop => true # Does not really create.
- # FileUtils.mkdir 'tmp', :mode => 0700
- #
- def mkdir(list, options = {})
- fu_check_options options, OPT_TABLE['mkdir']
- list = fu_list(list)
- fu_output_message "mkdir #{options[:mode] ? ('-m %03o ' % options[:mode]) : ''}#{list.join ' '}" if options[:verbose]
- return if options[:noop]
-
- list.each do |dir|
- fu_mkdir dir, options[:mode]
- end
- end
- module_function :mkdir
-
- OPT_TABLE['mkdir'] = [:mode, :noop, :verbose]
-
- #
- # Options: mode noop verbose
- #
- # Creates a directory and all its parent directories.
- # For example,
- #
- # FileUtils.mkdir_p '/usr/local/lib/ruby'
- #
- # causes to make following directories, if it does not exist.
- # * /usr
- # * /usr/local
- # * /usr/local/lib
- # * /usr/local/lib/ruby
- #
- # You can pass several directories at a time in a list.
- #
- def mkdir_p(list, options = {})
- fu_check_options options, OPT_TABLE['mkdir_p']
- list = fu_list(list)
- fu_output_message "mkdir -p #{options[:mode] ? ('-m %03o ' % options[:mode]) : ''}#{list.join ' '}" if options[:verbose]
- return *list if options[:noop]
-
- list.map {|path| remove_tailing_slash(path)}.each do |path|
- # optimize for the most common case
- begin
- fu_mkdir path, options[:mode]
- next
- rescue SystemCallError
- next if File.directory?(path)
- end
-
- stack = []
- until path == stack.last # dirname("/")=="/", dirname("C:/")=="C:/"
- stack.push path
- path = File.dirname(path)
- end
- stack.pop # root directory should exist
- stack.reverse_each do |dir|
- begin
- fu_mkdir dir, options[:mode]
- rescue SystemCallError
- raise unless File.directory?(dir)
- end
- end
- end
-
- return *list
- end
- module_function :mkdir_p
-
- alias mkpath mkdir_p
- alias makedirs mkdir_p
- module_function :mkpath
- module_function :makedirs
-
- OPT_TABLE['mkdir_p'] =
- OPT_TABLE['mkpath'] =
- OPT_TABLE['makedirs'] = [:mode, :noop, :verbose]
-
- def fu_mkdir(path, mode) #:nodoc:
- path = remove_tailing_slash(path)
- if mode
- Dir.mkdir path, mode
- File.chmod mode, path
- else
- Dir.mkdir path
- end
- end
- private_module_function :fu_mkdir
-
- #
- # Options: parents, noop, verbose
- #
- # Removes one or more directories.
- #
- # FileUtils.rmdir 'somedir'
- # FileUtils.rmdir %w(somedir anydir otherdir)
- # # Does not really remove directory; outputs message.
- # FileUtils.rmdir 'somedir', :verbose => true, :noop => true
- #
- def rmdir(list, options = {})
- fu_check_options options, OPT_TABLE['rmdir']
- list = fu_list(list)
- parents = options[:parents]
- fu_output_message "rmdir #{parents ? '-p ' : ''}#{list.join ' '}" if options[:verbose]
- return if options[:noop]
- list.each do |dir|
- begin
- Dir.rmdir(dir = remove_tailing_slash(dir))
- if parents
- until (parent = File.dirname(dir)) == '.' or parent == dir
- dir = parent
- Dir.rmdir(dir)
- end
- end
- rescue Errno::ENOTEMPTY, Errno::EEXIST, Errno::ENOENT
- end
- end
- end
- module_function :rmdir
-
- OPT_TABLE['rmdir'] = [:parents, :noop, :verbose]
-
- #
- # Options: force noop verbose
- #
- # <b><tt>ln(old, new, options = {})</tt></b>
- #
- # Creates a hard link +new+ which points to +old+.
- # If +new+ already exists and it is a directory, creates a link +new/old+.
- # If +new+ already exists and it is not a directory, raises Errno::EEXIST.
- # But if :force option is set, overwrite +new+.
- #
- # FileUtils.ln 'gcc', 'cc', :verbose => true
- # FileUtils.ln '/usr/bin/emacs21', '/usr/bin/emacs'
- #
- # <b><tt>ln(list, destdir, options = {})</tt></b>
- #
- # Creates several hard links in a directory, with each one pointing to the
- # item in +list+. If +destdir+ is not a directory, raises Errno::ENOTDIR.
- #
- # include FileUtils
- # cd '/sbin'
- # FileUtils.ln %w(cp mv mkdir), '/bin' # Now /sbin/cp and /bin/cp are linked.
- #
- def ln(src, dest, options = {})
- fu_check_options options, OPT_TABLE['ln']
- fu_output_message "ln#{options[:force] ? ' -f' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
- return if options[:noop]
- fu_each_src_dest0(src, dest) do |s,d|
- remove_file d, true if options[:force]
- File.link s, d
- end
- end
- module_function :ln
-
- alias link ln
- module_function :link
-
- OPT_TABLE['ln'] =
- OPT_TABLE['link'] = [:force, :noop, :verbose]
-
- #
- # Options: force noop verbose
- #
- # <b><tt>ln_s(old, new, options = {})</tt></b>
- #
- # Creates a symbolic link +new+ which points to +old+. If +new+ already
- # exists and it is a directory, creates a symbolic link +new/old+. If +new+
- # already exists and it is not a directory, raises Errno::EEXIST. But if
- # :force option is set, overwrite +new+.
- #
- # FileUtils.ln_s '/usr/bin/ruby', '/usr/local/bin/ruby'
- # FileUtils.ln_s 'verylongsourcefilename.c', 'c', :force => true
- #
- # <b><tt>ln_s(list, destdir, options = {})</tt></b>
- #
- # Creates several symbolic links in a directory, with each one pointing to the
- # item in +list+. If +destdir+ is not a directory, raises Errno::ENOTDIR.
- #
- # If +destdir+ is not a directory, raises Errno::ENOTDIR.
- #
- # FileUtils.ln_s Dir.glob('bin/*.rb'), '/home/aamine/bin'
- #
- def ln_s(src, dest, options = {})
- fu_check_options options, OPT_TABLE['ln_s']
- fu_output_message "ln -s#{options[:force] ? 'f' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
- return if options[:noop]
- fu_each_src_dest0(src, dest) do |s,d|
- remove_file d, true if options[:force]
- File.symlink s, d
- end
- end
- module_function :ln_s
-
- alias symlink ln_s
- module_function :symlink
-
- OPT_TABLE['ln_s'] =
- OPT_TABLE['symlink'] = [:force, :noop, :verbose]
-
- #
- # Options: noop verbose
- #
- # Same as
- # #ln_s(src, dest, :force => true)
- #
- def ln_sf(src, dest, options = {})
- fu_check_options options, OPT_TABLE['ln_sf']
- options = options.dup
- options[:force] = true
- ln_s src, dest, options
- end
- module_function :ln_sf
-
- OPT_TABLE['ln_sf'] = [:noop, :verbose]
-
- #
- # Options: preserve noop verbose
- #
- # Copies a file content +src+ to +dest+. If +dest+ is a directory,
- # copies +src+ to +dest/src+.
- #
- # If +src+ is a list of files, then +dest+ must be a directory.
- #
- # FileUtils.cp 'eval.c', 'eval.c.org'
- # FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6'
- # FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6', :verbose => true
- # FileUtils.cp 'symlink', 'dest' # copy content, "dest" is not a symlink
- #
- def cp(src, dest, options = {})
- fu_check_options options, OPT_TABLE['cp']
- fu_output_message "cp#{options[:preserve] ? ' -p' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
- return if options[:noop]
- fu_each_src_dest(src, dest) do |s, d|
- copy_file s, d, options[:preserve]
- end
- end
- module_function :cp
-
- alias copy cp
- module_function :copy
-
- OPT_TABLE['cp'] =
- OPT_TABLE['copy'] = [:preserve, :noop, :verbose]
-
- #
- # Options: preserve noop verbose dereference_root remove_destination
- #
- # Copies +src+ to +dest+. If +src+ is a directory, this method copies
- # all its contents recursively. If +dest+ is a directory, copies
- # +src+ to +dest/src+.
- #
- # +src+ can be a list of files.
- #
- # # Installing Ruby library "mylib" under the site_ruby
- # FileUtils.rm_r site_ruby + '/mylib', :force
- # FileUtils.cp_r 'lib/', site_ruby + '/mylib'
- #
- # # Examples of copying several files to target directory.
- # FileUtils.cp_r %w(mail.rb field.rb debug/), site_ruby + '/tmail'
- # FileUtils.cp_r Dir.glob('*.rb'), '/home/aamine/lib/ruby', :noop => true, :verbose => true
- #
- # # If you want to copy all contents of a directory instead of the
- # # directory itself, c.f. src/x -> dest/x, src/y -> dest/y,
- # # use following code.
- # FileUtils.cp_r 'src/.', 'dest' # cp_r('src', 'dest') makes dest/src,
- # # but this doesn't.
- #
- def cp_r(src, dest, options = {})
- fu_check_options options, OPT_TABLE['cp_r']
- fu_output_message "cp -r#{options[:preserve] ? 'p' : ''}#{options[:remove_destination] ? ' --remove-destination' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
- return if options[:noop]
- options = options.dup
- options[:dereference_root] = true unless options.key?(:dereference_root)
- fu_each_src_dest(src, dest) do |s, d|
- copy_entry s, d, options[:preserve], options[:dereference_root], options[:remove_destination]
- end
- end
- module_function :cp_r
-
- OPT_TABLE['cp_r'] = [:preserve, :noop, :verbose,
- :dereference_root, :remove_destination]
-
- #
- # Copies a file system entry +src+ to +dest+.
- # If +src+ is a directory, this method copies its contents recursively.
- # This method preserves file types, c.f. symlink, directory...
- # (FIFO, device files and etc. are not supported yet)
- #
- # Both of +src+ and +dest+ must be a path name.
- # +src+ must exist, +dest+ must not exist.
- #
- # If +preserve+ is true, this method preserves owner, group, and
- # modified time. Permissions are copied regardless +preserve+.
- #
- # If +dereference_root+ is true, this method dereference tree root.
- #
- # If +remove_destination+ is true, this method removes each destination file before copy.
- #
- def copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
- Entry_.new(src, nil, dereference_root).wrap_traverse(proc do |ent|
- destent = Entry_.new(dest, ent.rel, false)
- File.unlink destent.path if remove_destination && File.file?(destent.path)
- ent.copy destent.path
- end, proc do |ent|
- destent = Entry_.new(dest, ent.rel, false)
- ent.copy_metadata destent.path if preserve
- end)
- end
- module_function :copy_entry
-
- #
- # Copies file contents of +src+ to +dest+.
- # Both of +src+ and +dest+ must be a path name.
- #
- def copy_file(src, dest, preserve = false, dereference = true)
- ent = Entry_.new(src, nil, dereference)
- ent.copy_file dest
- ent.copy_metadata dest if preserve
- end
- module_function :copy_file
-
- #
- # Copies stream +src+ to +dest+.
- # +src+ must respond to #read(n) and
- # +dest+ must respond to #write(str).
- #
- def copy_stream(src, dest)
- IO.copy_stream(src, dest)
- end
- module_function :copy_stream
-
- #
- # Options: force noop verbose
- #
- # Moves file(s) +src+ to +dest+. If +file+ and +dest+ exist on the different
- # disk partition, the file is copied then the original file is removed.
- #
- # FileUtils.mv 'badname.rb', 'goodname.rb'
- # FileUtils.mv 'stuff.rb', '/notexist/lib/ruby', :force => true # no error
- #
- # FileUtils.mv %w(junk.txt dust.txt), '/home/aamine/.trash/'
- # FileUtils.mv Dir.glob('test*.rb'), 'test', :noop => true, :verbose => true
- #
- def mv(src, dest, options = {})
- fu_check_options options, OPT_TABLE['mv']
- fu_output_message "mv#{options[:force] ? ' -f' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
- return if options[:noop]
- fu_each_src_dest(src, dest) do |s, d|
- destent = Entry_.new(d, nil, true)
- begin
- if destent.exist?
- if destent.directory?
- raise Errno::EEXIST, d
- else
- destent.remove_file if rename_cannot_overwrite_file?
- end
- end
- begin
- File.rename s, d
- rescue Errno::EXDEV
- copy_entry s, d, true
- if options[:secure]
- remove_entry_secure s, options[:force]
- else
- remove_entry s, options[:force]
- end
- end
- rescue SystemCallError
- raise unless options[:force]
- end
- end
- end
- module_function :mv
-
- alias move mv
- module_function :move
-
- OPT_TABLE['mv'] =
- OPT_TABLE['move'] = [:force, :noop, :verbose, :secure]
-
- def rename_cannot_overwrite_file? #:nodoc:
- /cygwin|mswin|mingw|bccwin|emx/ =~ RUBY_PLATFORM
- end
- private_module_function :rename_cannot_overwrite_file?
-
- #
- # Options: force noop verbose
- #
- # Remove file(s) specified in +list+. This method cannot remove directories.
- # All StandardErrors are ignored when the :force option is set.
- #
- # FileUtils.rm %w( junk.txt dust.txt )
- # FileUtils.rm Dir.glob('*.so')
- # FileUtils.rm 'NotExistFile', :force => true # never raises exception
- #
- def rm(list, options = {})
- fu_check_options options, OPT_TABLE['rm']
- list = fu_list(list)
- fu_output_message "rm#{options[:force] ? ' -f' : ''} #{list.join ' '}" if options[:verbose]
- return if options[:noop]
-
- list.each do |path|
- remove_file path, options[:force]
- end
- end
- module_function :rm
-
- alias remove rm
- module_function :remove
-
- OPT_TABLE['rm'] =
- OPT_TABLE['remove'] = [:force, :noop, :verbose]
-
- #
- # Options: noop verbose
- #
- # Equivalent to
- #
- # #rm(list, :force => true)
- #
- def rm_f(list, options = {})
- fu_check_options options, OPT_TABLE['rm_f']
- options = options.dup
- options[:force] = true
- rm list, options
- end
- module_function :rm_f
-
- alias safe_unlink rm_f
- module_function :safe_unlink
-
- OPT_TABLE['rm_f'] =
- OPT_TABLE['safe_unlink'] = [:noop, :verbose]
-
- #
- # Options: force noop verbose secure
- #
- # remove files +list+[0] +list+[1]... If +list+[n] is a directory,
- # removes its all contents recursively. This method ignores
- # StandardError when :force option is set.
- #
- # FileUtils.rm_r Dir.glob('/tmp/*')
- # FileUtils.rm_r '/', :force => true # :-)
- #
- # WARNING: This method causes local vulnerability
- # if one of parent directories or removing directory tree are world
- # writable (including /tmp, whose permission is 1777), and the current
- # process has strong privilege such as Unix super user (root), and the
- # system has symbolic link. For secure removing, read the documentation
- # of #remove_entry_secure carefully, and set :secure option to true.
- # Default is :secure=>false.
- #
- # NOTE: This method calls #remove_entry_secure if :secure option is set.
- # See also #remove_entry_secure.
- #
- def rm_r(list, options = {})
- fu_check_options options, OPT_TABLE['rm_r']
- # options[:secure] = true unless options.key?(:secure)
- list = fu_list(list)
- fu_output_message "rm -r#{options[:force] ? 'f' : ''} #{list.join ' '}" if options[:verbose]
- return if options[:noop]
- list.each do |path|
- if options[:secure]
- remove_entry_secure path, options[:force]
- else
- remove_entry path, options[:force]
- end
- end
- end
- module_function :rm_r
-
- OPT_TABLE['rm_r'] = [:force, :noop, :verbose, :secure]
-
- #
- # Options: noop verbose secure
- #
- # Equivalent to
- #
- # #rm_r(list, :force => true)
- #
- # WARNING: This method causes local vulnerability.
- # Read the documentation of #rm_r first.
- #
- def rm_rf(list, options = {})
- fu_check_options options, OPT_TABLE['rm_rf']
- options = options.dup
- options[:force] = true
- rm_r list, options
- end
- module_function :rm_rf
-
- alias rmtree rm_rf
- module_function :rmtree
-
- OPT_TABLE['rm_rf'] =
- OPT_TABLE['rmtree'] = [:noop, :verbose, :secure]
-
- #
- # This method removes a file system entry +path+. +path+ shall be a
- # regular file, a directory, or something. If +path+ is a directory,
- # remove it recursively. This method is required to avoid TOCTTOU
- # (time-of-check-to-time-of-use) local security vulnerability of #rm_r.
- # #rm_r causes security hole when:
- #
- # * Parent directory is world writable (including /tmp).
- # * Removing directory tree includes world writable directory.
- # * The system has symbolic link.
- #
- # To avoid this security hole, this method applies special preprocess.
- # If +path+ is a directory, this method chown(2) and chmod(2) all
- # removing directories. This requires the current process is the
- # owner of the removing whole directory tree, or is the super user (root).
- #
- # WARNING: You must ensure that *ALL* parent directories cannot be
- # moved by other untrusted users. For example, parent directories
- # should not be owned by untrusted users, and should not be world
- # writable except when the sticky bit set.
- #
- # WARNING: Only the owner of the removing directory tree, or Unix super
- # user (root) should invoke this method. Otherwise this method does not
- # work.
- #
- # For details of this security vulnerability, see Perl's case:
- #
- # http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2005-0448
- # http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2004-0452
- #
- # For fileutils.rb, this vulnerability is reported in [ruby-dev:26100].
- #
- def remove_entry_secure(path, force = false)
- unless fu_have_symlink?
- remove_entry path, force
- return
- end
- fullpath = File.expand_path(path)
- st = File.lstat(fullpath)
- unless st.directory?
- File.unlink fullpath
- return
- end
- # is a directory.
- parent_st = File.stat(File.dirname(fullpath))
- unless parent_st.world_writable?
- remove_entry path, force
- return
- end
- unless parent_st.sticky?
- raise ArgumentError, "parent directory is world writable, FileUtils#remove_entry_secure does not work; abort: #{path.inspect} (parent directory mode #{'%o' % parent_st.mode})"
- end
- # freeze tree root
- euid = Process.euid
- File.open(fullpath + '/.') {|f|
- unless fu_stat_identical_entry?(st, f.stat)
- # symlink (TOC-to-TOU attack?)
- File.unlink fullpath
- return
- end
- f.chown euid, -1
- f.chmod 0700
- unless fu_stat_identical_entry?(st, File.lstat(fullpath))
- # TOC-to-TOU attack?
- File.unlink fullpath
- return
- end
- }
- # ---- tree root is frozen ----
- root = Entry_.new(path)
- root.preorder_traverse do |ent|
- if ent.directory?
- ent.chown euid, -1
- ent.chmod 0700
- end
- end
- root.postorder_traverse do |ent|
- begin
- ent.remove
- rescue
- raise unless force
- end
- end
- rescue
- raise unless force
- end
- module_function :remove_entry_secure
-
- def fu_have_symlink? #:nodoc:
- File.symlink nil, nil
- rescue NotImplementedError
- return false
- rescue TypeError
- return true
- end
- private_module_function :fu_have_symlink?
-
- def fu_stat_identical_entry?(a, b) #:nodoc:
- a.dev == b.dev and a.ino == b.ino
- end
- private_module_function :fu_stat_identical_entry?
-
- #
- # This method removes a file system entry +path+.
- # +path+ might be a regular file, a directory, or something.
- # If +path+ is a directory, remove it recursively.
- #
- # See also #remove_entry_secure.
- #
- def remove_entry(path, force = false)
- Entry_.new(path).postorder_traverse do |ent|
- begin
- ent.remove
- rescue
- raise unless force
- end
- end
- rescue
- raise unless force
- end
- module_function :remove_entry
-
- #
- # Removes a file +path+.
- # This method ignores StandardError if +force+ is true.
- #
- def remove_file(path, force = false)
- Entry_.new(path).remove_file
- rescue
- raise unless force
- end
- module_function :remove_file
-
- #
- # Removes a directory +dir+ and its contents recursively.
- # This method ignores StandardError if +force+ is true.
- #
- def remove_dir(path, force = false)
- remove_entry path, force # FIXME?? check if it is a directory
- end
- module_function :remove_dir
-
- #
- # Returns true if the contents of a file A and a file B are identical.
- #
- # FileUtils.compare_file('somefile', 'somefile') #=> true
- # FileUtils.compare_file('/bin/cp', '/bin/mv') #=> maybe false
- #
- def compare_file(a, b)
- return false unless File.size(a) == File.size(b)
- File.open(a, 'rb') {|fa|
- File.open(b, 'rb') {|fb|
- return compare_stream(fa, fb)
- }
- }
- end
- module_function :compare_file
-
- alias identical? compare_file
- alias cmp compare_file
- module_function :identical?
- module_function :cmp
-
- #
- # Returns true if the contents of a stream +a+ and +b+ are identical.
- #
- def compare_stream(a, b)
- bsize = fu_stream_blksize(a, b)
- sa = ""
- sb = ""
- begin
- a.read(bsize, sa)
- b.read(bsize, sb)
- return true if sa.empty? && sb.empty?
- end while sa == sb
- false
- end
- module_function :compare_stream
-
- #
- # Options: mode preserve noop verbose
- #
- # If +src+ is not same as +dest+, copies it and changes the permission
- # mode to +mode+. If +dest+ is a directory, destination is +dest+/+src+.
- # This method removes destination before copy.
- #
- # FileUtils.install 'ruby', '/usr/local/bin/ruby', :mode => 0755, :verbose => true
- # FileUtils.install 'lib.rb', '/usr/local/lib/ruby/site_ruby', :verbose => true
- #
- def install(src, dest, options = {})
- fu_check_options options, OPT_TABLE['install']
- fu_output_message "install -c#{options[:preserve] && ' -p'}#{options[:mode] ? (' -m 0%o' % options[:mode]) : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
- return if options[:noop]
- fu_each_src_dest(src, dest) do |s, d|
- st = File.stat(s)
- unless File.exist?(d) and compare_file(s, d)
- remove_file d, true
- copy_file s, d
- File.utime st.atime, st.mtime, d if options[:preserve]
- File.chmod options[:mode], d if options[:mode]
- end
- end
- end
- module_function :install
-
- OPT_TABLE['install'] = [:mode, :preserve, :noop, :verbose]
-
- def user_mask(target) #:nodoc:
- target.each_char.inject(0) do |mask, chr|
- case chr
- when "u"
- mask | 04700
- when "g"
- mask | 02070
- when "o"
- mask | 01007
- when "a"
- mask | 07777
- else
- raise ArgumentError, "invalid `who' symbol in file mode: #{chr}"
- end
- end
- end
- private_module_function :user_mask
-
- def apply_mask(mode, user_mask, op, mode_mask)
- case op
- when '='
- (mode & ~user_mask) | (user_mask & mode_mask)
- when '+'
- mode | (user_mask & mode_mask)
- when '-'
- mode & ~(user_mask & mode_mask)
- end
- end
- private_module_function :apply_mask
-
- def symbolic_modes_to_i(mode_sym, path) #:nodoc:
- mode_sym.split(/,/).inject(File.stat(path).mode & 07777) do |current_mode, clause|
- target, *actions = clause.split(/([=+-])/)
- raise ArgumentError, "invalid file mode: #{mode_sym}" if actions.empty?
- target = 'a' if target.empty?
- user_mask = user_mask(target)
- actions.each_slice(2) do |op, perm|
- need_apply = op == '='
- mode_mask = (perm || '').each_char.inject(0) do |mask, chr|
- case chr
- when "r"
- mask | 0444
- when "w"
- mask | 0222
- when "x"
- mask | 0111
- when "X"
- if FileTest.directory? path
- mask | 0111
- else
- mask
- end
- when "s"
- mask | 06000
- when "t"
- mask | 01000
- when "u", "g", "o"
- if mask.nonzero?
- current_mode = apply_mask(current_mode, user_mask, op, mask)
- end
- need_apply = false
- copy_mask = user_mask(chr)
- (current_mode & copy_mask) / (copy_mask & 0111) * (user_mask & 0111)
- else
- raise ArgumentError, "invalid `perm' symbol in file mode: #{chr}"
- end
- end
-
- if mode_mask.nonzero? || need_apply
- current_mode = apply_mask(current_mode, user_mask, op, mode_mask)
- end
- end
- current_mode
- end
- end
- private_module_function :symbolic_modes_to_i
-
- def fu_mode(mode, path) #:nodoc:
- mode.is_a?(String) ? symbolic_modes_to_i(mode, path) : mode
- end
- private_module_function :fu_mode
-
- def mode_to_s(mode) #:nodoc:
- mode.is_a?(String) ? mode : "%o" % mode
- end
- private_module_function :mode_to_s
-
- #
- # Options: noop verbose
- #
- # Changes permission bits on the named files (in +list+) to the bit pattern
- # represented by +mode+.
- #
- # +mode+ is the symbolic and absolute mode can be used.
- #
- # Absolute mode is
- # FileUtils.chmod 0755, 'somecommand'
- # FileUtils.chmod 0644, %w(my.rb your.rb his.rb her.rb)
- # FileUtils.chmod 0755, '/usr/bin/ruby', :verbose => true
- #
- # Symbolic mode is
- # FileUtils.chmod "u=wrx,go=rx", 'somecommand'
- # FileUtils.chmod "u=wr,go=rr", %w(my.rb your.rb his.rb her.rb)
- # FileUtils.chmod "u=wrx,go=rx", '/usr/bin/ruby', :verbose => true
- #
- # "a" :: is user, group, other mask.
- # "u" :: is user's mask.
- # "g" :: is group's mask.
- # "o" :: is other's mask.
- # "w" :: is write permission.
- # "r" :: is read permission.
- # "x" :: is execute permission.
- # "X" ::
- # is execute permission for directories only, must be used in conjunction with "+"
- # "s" :: is uid, gid.
- # "t" :: is sticky bit.
- # "+" :: is added to a class given the specified mode.
- # "-" :: Is removed from a given class given mode.
- # "=" :: Is the exact nature of the class will be given a specified mode.
-
- def chmod(mode, list, options = {})
- fu_check_options options, OPT_TABLE['chmod']
- list = fu_list(list)
- fu_output_message sprintf('chmod %s %s', mode_to_s(mode), list.join(' ')) if options[:verbose]
- return if options[:noop]
- list.each do |path|
- Entry_.new(path).chmod(fu_mode(mode, path))
- end
- end
- module_function :chmod
-
- OPT_TABLE['chmod'] = [:noop, :verbose]
-
- #
- # Options: noop verbose force
- #
- # Changes permission bits on the named files (in +list+)
- # to the bit pattern represented by +mode+.
- #
- # FileUtils.chmod_R 0700, "/tmp/app.#{$$}"
- # FileUtils.chmod_R "u=wrx", "/tmp/app.#{$$}"
- #
- def chmod_R(mode, list, options = {})
- fu_check_options options, OPT_TABLE['chmod_R']
- list = fu_list(list)
- fu_output_message sprintf('chmod -R%s %s %s',
- (options[:force] ? 'f' : ''),
- mode_to_s(mode), list.join(' ')) if options[:verbose]
- return if options[:noop]
- list.each do |root|
- Entry_.new(root).traverse do |ent|
- begin
- ent.chmod(fu_mode(mode, ent.path))
- rescue
- raise unless options[:force]
- end
- end
- end
- end
- module_function :chmod_R
-
- OPT_TABLE['chmod_R'] = [:noop, :verbose, :force]
-
- #
- # Options: noop verbose
- #
- # Changes owner and group on the named files (in +list+)
- # to the user +user+ and the group +group+. +user+ and +group+
- # may be an ID (Integer/String) or a name (String).
- # If +user+ or +group+ is nil, this method does not change
- # the attribute.
- #
- # FileUtils.chown 'root', 'staff', '/usr/local/bin/ruby'
- # FileUtils.chown nil, 'bin', Dir.glob('/usr/bin/*'), :verbose => true
- #
- def chown(user, group, list, options = {})
- fu_check_options options, OPT_TABLE['chown']
- list = fu_list(list)
- fu_output_message sprintf('chown %s %s',
- (group ? "#{user}:#{group}" : user || ':'),
- list.join(' ')) if options[:verbose]
- return if options[:noop]
- uid = fu_get_uid(user)
- gid = fu_get_gid(group)
- list.each do |path|
- Entry_.new(path).chown uid, gid
- end
- end
- module_function :chown
-
- OPT_TABLE['chown'] = [:noop, :verbose]
-
- #
- # Options: noop verbose force
- #
- # Changes owner and group on the named files (in +list+)
- # to the user +user+ and the group +group+ recursively.
- # +user+ and +group+ may be an ID (Integer/String) or
- # a name (String). If +user+ or +group+ is nil, this
- # method does not change the attribute.
- #
- # FileUtils.chown_R 'www', 'www', '/var/www/htdocs'
- # FileUtils.chown_R 'cvs', 'cvs', '/var/cvs', :verbose => true
- #
- def chown_R(user, group, list, options = {})
- fu_check_options options, OPT_TABLE['chown_R']
- list = fu_list(list)
- fu_output_message sprintf('chown -R%s %s %s',
- (options[:force] ? 'f' : ''),
- (group ? "#{user}:#{group}" : user || ':'),
- list.join(' ')) if options[:verbose]
- return if options[:noop]
- uid = fu_get_uid(user)
- gid = fu_get_gid(group)
- list.each do |root|
- Entry_.new(root).traverse do |ent|
- begin
- ent.chown uid, gid
- rescue
- raise unless options[:force]
- end
- end
- end
- end
- module_function :chown_R
-
- OPT_TABLE['chown_R'] = [:noop, :verbose, :force]
-
- begin
- require 'etc'
- rescue LoadError # rescue LoadError for miniruby
- end
-
- def fu_get_uid(user) #:nodoc:
- return nil unless user
- case user
- when Integer
- user
- when /\A\d+\z/
- user.to_i
- else
- Etc.getpwnam(user) ? Etc.getpwnam(user).uid : nil
- end
- end
- private_module_function :fu_get_uid
-
- def fu_get_gid(group) #:nodoc:
- return nil unless group
- case group
- when Integer
- group
- when /\A\d+\z/
- group.to_i
- else
- Etc.getgrnam(group) ? Etc.getgrnam(group).gid : nil
- end
- end
- private_module_function :fu_get_gid
-
- #
- # Options: noop verbose mtime nocreate
- #
- # Updates modification time (mtime) and access time (atime) of file(s) in
- # +list+. Files are created if they don't exist.
- #
- # FileUtils.touch 'timestamp'
- # FileUtils.touch Dir.glob('*.c'); system 'make'
- #
- def touch(list, options = {})
- fu_check_options options, OPT_TABLE['touch']
- list = fu_list(list)
- nocreate = options[:nocreate]
- t = options[:mtime]
- if options[:verbose]
- fu_output_message "touch #{nocreate ? '-c ' : ''}#{t ? t.strftime('-t %Y%m%d%H%M.%S ') : ''}#{list.join ' '}"
- end
- return if options[:noop]
- list.each do |path|
- created = nocreate
- begin
- File.utime(t, t, path)
- rescue Errno::ENOENT
- raise if created
- File.open(path, 'a') {
- ;
- }
- created = true
- retry if t
- end
- end
- end
- module_function :touch
-
- OPT_TABLE['touch'] = [:noop, :verbose, :mtime, :nocreate]
-
- private
-
- module StreamUtils_
- private
-
- def fu_windows?
- /mswin|mingw|bccwin|emx/ =~ RUBY_PLATFORM
- end
-
- def fu_copy_stream0(src, dest, blksize = nil) #:nodoc:
- IO.copy_stream(src, dest)
- end
-
- def fu_stream_blksize(*streams)
- streams.each do |s|
- next unless s.respond_to?(:stat)
- size = fu_blksize(s.stat)
- return size if size
- end
- fu_default_blksize()
- end
-
- def fu_blksize(st)
- s = st.blksize
- return nil unless s
- return nil if s == 0
- s
- end
-
- def fu_default_blksize
- 1024
- end
- end
-
- include StreamUtils_
- extend StreamUtils_
-
- class Entry_ #:nodoc: internal use only
- include StreamUtils_
-
- def initialize(a, b = nil, deref = false)
- @prefix = @rel = @path = nil
- if b
- @prefix = a
- @rel = b
- else
- @path = a
- end
- @deref = deref
- @stat = nil
- @lstat = nil
- end
-
- def inspect
- "\#<#{self.class} #{path()}>"
- end
-
- def path
- if @path
- File.path(@path)
- else
- join(@prefix, @rel)
- end
- end
-
- def prefix
- @prefix || @path
- end
-
- def rel
- @rel
- end
-
- def dereference?
- @deref
- end
-
- def exist?
- begin
- lstat
- true
- rescue Errno::ENOENT
- false
- end
- end
-
- def file?
- s = lstat!
- s and s.file?
- end
-
- def directory?
- s = lstat!
- s and s.directory?
- end
-
- def symlink?
- s = lstat!
- s and s.symlink?
- end
-
- def chardev?
- s = lstat!
- s and s.chardev?
- end
-
- def blockdev?
- s = lstat!
- s and s.blockdev?
- end
-
- def socket?
- s = lstat!
- s and s.socket?
- end
-
- def pipe?
- s = lstat!
- s and s.pipe?
- end
-
- S_IF_DOOR = 0xD000
-
- def door?
- s = lstat!
- s and (s.mode & 0xF000 == S_IF_DOOR)
- end
-
- def entries
- opts = {}
- opts[:encoding] = ::Encoding::UTF_8 if fu_windows?
- Dir.entries(path(), opts)\
- .reject {|n| n == '.' or n == '..' }\
- .map {|n| Entry_.new(prefix(), join(rel(), n.untaint)) }
- end
-
- def stat
- return @stat if @stat
- if lstat() and lstat().symlink?
- @stat = File.stat(path())
- else
- @stat = lstat()
- end
- @stat
- end
-
- def stat!
- return @stat if @stat
- if lstat! and lstat!.symlink?
- @stat = File.stat(path())
- else
- @stat = lstat!
- end
- @stat
- rescue SystemCallError
- nil
- end
-
- def lstat
- if dereference?
- @lstat ||= File.stat(path())
- else
- @lstat ||= File.lstat(path())
- end
- end
-
- def lstat!
- lstat()
- rescue SystemCallError
- nil
- end
-
- def chmod(mode)
- if symlink?
- File.lchmod mode, path() if have_lchmod?
- else
- File.chmod mode, path()
- end
- end
-
- def chown(uid, gid)
- if symlink?
- File.lchown uid, gid, path() if have_lchown?
- else
- File.chown uid, gid, path()
- end
- end
-
- def copy(dest)
- case
- when file?
- copy_file dest
- when directory?
- if !File.exist?(dest) and descendant_directory?(dest, path)
- raise ArgumentError, "cannot copy directory %s to itself %s" % [path, dest]
- end
- begin
- Dir.mkdir dest
- rescue
- raise unless File.directory?(dest)
- end
- when symlink?
- File.symlink File.readlink(path()), dest
- when chardev?
- raise "cannot handle device file" unless File.respond_to?(:mknod)
- mknod dest, ?c, 0666, lstat().rdev
- when blockdev?
- raise "cannot handle device file" unless File.respond_to?(:mknod)
- mknod dest, ?b, 0666, lstat().rdev
- when socket?
- raise "cannot handle socket" unless File.respond_to?(:mknod)
- mknod dest, nil, lstat().mode, 0
- when pipe?
- raise "cannot handle FIFO" unless File.respond_to?(:mkfifo)
- mkfifo dest, 0666
- when door?
- raise "cannot handle door: #{path()}"
- else
- raise "unknown file type: #{path()}"
- end
- end
-
- def copy_file(dest)
- File.open(path()) do |s|
- File.open(dest, 'wb', s.stat.mode) do |f|
- IO.copy_stream(s, f)
- end
- end
- end
-
- def copy_metadata(path)
- st = lstat()
- if !st.symlink?
- File.utime st.atime, st.mtime, path
- end
- begin
- if st.symlink?
- begin
- File.lchown st.uid, st.gid, path
- rescue NotImplementedError
- end
- else
- File.chown st.uid, st.gid, path
- end
- rescue Errno::EPERM
- # clear setuid/setgid
- if st.symlink?
- begin
- File.lchmod st.mode & 01777, path
- rescue NotImplementedError
- end
- else
- File.chmod st.mode & 01777, path
- end
- else
- if st.symlink?
- begin
- File.lchmod st.mode, path
- rescue NotImplementedError
- end
- else
- File.chmod st.mode, path
- end
- end
- end
-
- def remove
- if directory?
- remove_dir1
- else
- remove_file
- end
- end
-
- def remove_dir1
- platform_support {
- Dir.rmdir path().chomp(?/)
- }
- end
-
- def remove_file
- platform_support {
- File.unlink path
- }
- end
-
- def platform_support
- return yield unless fu_windows?
- first_time_p = true
- begin
- yield
- rescue Errno::ENOENT
- raise
- rescue => err
- if first_time_p
- first_time_p = false
- begin
- File.chmod 0700, path() # Windows does not have symlink
- retry
- rescue SystemCallError
- end
- end
- raise err
- end
- end
-
- def preorder_traverse
- stack = [self]
- while ent = stack.pop
- yield ent
- stack.concat ent.entries.reverse if ent.directory?
- end
- end
-
- alias traverse preorder_traverse
-
- def postorder_traverse
- if directory?
- entries().each do |ent|
- ent.postorder_traverse do |e|
- yield e
- end
- end
- end
- ensure
- yield self
- end
-
- def wrap_traverse(pre, post)
- pre.call self
- if directory?
- entries.each do |ent|
- ent.wrap_traverse pre, post
- end
- end
- post.call self
- end
-
- private
-
- $fileutils_rb_have_lchmod = nil
-
- def have_lchmod?
- # This is not MT-safe, but it does not matter.
- if $fileutils_rb_have_lchmod == nil
- $fileutils_rb_have_lchmod = check_have_lchmod?
- end
- $fileutils_rb_have_lchmod
- end
-
- def check_have_lchmod?
- return false unless File.respond_to?(:lchmod)
- File.lchmod 0
- return true
- rescue NotImplementedError
- return false
- end
-
- $fileutils_rb_have_lchown = nil
-
- def have_lchown?
- # This is not MT-safe, but it does not matter.
- if $fileutils_rb_have_lchown == nil
- $fileutils_rb_have_lchown = check_have_lchown?
- end
- $fileutils_rb_have_lchown
- end
-
- def check_have_lchown?
- return false unless File.respond_to?(:lchown)
- File.lchown nil, nil
- return true
- rescue NotImplementedError
- return false
- end
-
- def join(dir, base)
- return File.path(dir) if not base or base == '.'
- return File.path(base) if not dir or dir == '.'
- File.join(dir, base)
- end
-
- if File::ALT_SEPARATOR
- DIRECTORY_TERM = "(?=[/#{Regexp.quote(File::ALT_SEPARATOR)}]|\\z)".freeze
- else
- DIRECTORY_TERM = "(?=/|\\z)".freeze
- end
- SYSCASE = File::FNM_SYSCASE.nonzero? ? "-i" : ""
-
- def descendant_directory?(descendant, ascendant)
- /\A(?#{SYSCASE}:#{Regexp.quote(ascendant)})#{DIRECTORY_TERM}/ =~ File.dirname(descendant)
- end
- end # class Entry_
-
- def fu_list(arg) #:nodoc:
- [arg].flatten.map {|path| File.path(path) }
- end
- private_module_function :fu_list
-
- def fu_each_src_dest(src, dest) #:nodoc:
- fu_each_src_dest0(src, dest) do |s, d|
- raise ArgumentError, "same file: #{s} and #{d}" if fu_same?(s, d)
- yield s, d
- end
- end
- private_module_function :fu_each_src_dest
-
- def fu_each_src_dest0(src, dest) #:nodoc:
- if tmp = Array.try_convert(src)
- tmp.each do |s|
- s = File.path(s)
- yield s, File.join(dest, File.basename(s))
- end
- else
- src = File.path(src)
- if File.directory?(dest)
- yield src, File.join(dest, File.basename(src))
- else
- yield src, File.path(dest)
- end
- end
- end
- private_module_function :fu_each_src_dest0
-
- def fu_same?(a, b) #:nodoc:
- File.identical?(a, b)
- end
- private_module_function :fu_same?
-
- def fu_check_options(options, optdecl) #:nodoc:
- h = options.dup
- optdecl.each do |opt|
- h.delete opt
- end
- raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless h.empty?
- end
- private_module_function :fu_check_options
-
- def fu_update_option(args, new) #:nodoc:
- if tmp = Hash.try_convert(args.last)
- args[-1] = tmp.dup.update(new)
- else
- args.push new
- end
- args
- end
- private_module_function :fu_update_option
-
- @fileutils_output = $stderr
- @fileutils_label = ''
-
- def fu_output_message(msg) #:nodoc:
- @fileutils_output ||= $stderr
- @fileutils_label ||= ''
- @fileutils_output.puts @fileutils_label + msg
- end
- private_module_function :fu_output_message
-
- #
- # Returns an Array of method names which have any options.
- #
- # p FileUtils.commands #=> ["chmod", "cp", "cp_r", "install", ...]
- #
- def FileUtils.commands
- OPT_TABLE.keys
- end
-
- #
- # Returns an Array of option names.
- #
- # p FileUtils.options #=> ["noop", "force", "verbose", "preserve", "mode"]
- #
- def FileUtils.options
- OPT_TABLE.values.flatten.uniq.map {|sym| sym.to_s }
- end
-
- #
- # Returns true if the method +mid+ have an option +opt+.
- #
- # p FileUtils.have_option?(:cp, :noop) #=> true
- # p FileUtils.have_option?(:rm, :force) #=> true
- # p FileUtils.have_option?(:rm, :preserve) #=> false
- #
- def FileUtils.have_option?(mid, opt)
- li = OPT_TABLE[mid.to_s] or raise ArgumentError, "no such method: #{mid}"
- li.include?(opt)
- end
-
- #
- # Returns an Array of option names of the method +mid+.
- #
- # p FileUtils.options_of(:rm) #=> ["noop", "verbose", "force"]
- #
- def FileUtils.options_of(mid)
- OPT_TABLE[mid.to_s].map {|sym| sym.to_s }
- end
-
- #
- # Returns an Array of method names which have the option +opt+.
- #
- # p FileUtils.collect_method(:preserve) #=> ["cp", "cp_r", "copy", "install"]
- #
- def FileUtils.collect_method(opt)
- OPT_TABLE.keys.select {|m| OPT_TABLE[m].include?(opt) }
- end
-
- LOW_METHODS = singleton_methods(false) - collect_method(:noop).map(&:intern)
- module LowMethods
- module_eval("private\n" + ::FileUtils::LOW_METHODS.map {|name| "def #{name}(*)end"}.join("\n"),
- __FILE__, __LINE__)
- end
-
- METHODS = singleton_methods() - [:private_module_function,
- :commands, :options, :have_option?, :options_of, :collect_method]
-
- #
- # This module has all methods of FileUtils module, but it outputs messages
- # before acting. This equates to passing the <tt>:verbose</tt> flag to
- # methods in FileUtils.
- #
- module Verbose
- include FileUtils
- @fileutils_output = $stderr
- @fileutils_label = ''
- ::FileUtils.collect_method(:verbose).each do |name|
- module_eval(<<-EOS, __FILE__, __LINE__ + 1)
- def #{name}(*args)
- super(*fu_update_option(args, :verbose => true))
- end
- private :#{name}
- EOS
- end
- extend self
- class << self
- ::FileUtils::METHODS.each do |m|
- public m
- end
- end
- end
-
- #
- # This module has all methods of FileUtils module, but never changes
- # files/directories. This equates to passing the <tt>:noop</tt> flag
- # to methods in FileUtils.
- #
- module NoWrite
- include FileUtils
- include LowMethods
- @fileutils_output = $stderr
- @fileutils_label = ''
- ::FileUtils.collect_method(:noop).each do |name|
- module_eval(<<-EOS, __FILE__, __LINE__ + 1)
- def #{name}(*args)
- super(*fu_update_option(args, :noop => true))
- end
- private :#{name}
- EOS
- end
- extend self
- class << self
- ::FileUtils::METHODS.each do |m|
- public m
- end
- end
- end
-
- #
- # This module has all methods of FileUtils module, but never changes
- # files/directories, with printing message before acting.
- # This equates to passing the <tt>:noop</tt> and <tt>:verbose</tt> flag
- # to methods in FileUtils.
- #
- module DryRun
- include FileUtils
- include LowMethods
- @fileutils_output = $stderr
- @fileutils_label = ''
- ::FileUtils.collect_method(:noop).each do |name|
- module_eval(<<-EOS, __FILE__, __LINE__ + 1)
- def #{name}(*args)
- super(*fu_update_option(args, :noop => true, :verbose => true))
- end
- private :#{name}
- EOS
- end
- extend self
- class << self
- ::FileUtils::METHODS.each do |m|
- public m
- end
- end
- end
-
-end
diff --git a/ruby_2_2/lib/find.rb b/ruby_2_2/lib/find.rb
deleted file mode 100644
index 55783a5695..0000000000
--- a/ruby_2_2/lib/find.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-#
-# find.rb: the Find module for processing all files under a given directory.
-#
-
-#
-# The +Find+ module supports the top-down traversal of a set of file paths.
-#
-# For example, to total the size of all files under your home directory,
-# ignoring anything in a "dot" directory (e.g. $HOME/.ssh):
-#
-# require 'find'
-#
-# total_size = 0
-#
-# Find.find(ENV["HOME"]) do |path|
-# if FileTest.directory?(path)
-# if File.basename(path)[0] == ?.
-# Find.prune # Don't look any further into this directory.
-# else
-# next
-# end
-# else
-# total_size += FileTest.size(path)
-# end
-# end
-#
-module Find
-
- #
- # Calls the associated block with the name of every file and directory listed
- # as arguments, then recursively on their subdirectories, and so on.
- #
- # Returns an enumerator if no block is given.
- #
- # See the +Find+ module documentation for an example.
- #
- def find(*paths, ignore_error: true) # :yield: path
- block_given? or return enum_for(__method__, *paths, ignore_error: ignore_error)
-
- fs_encoding = Encoding.find("filesystem")
-
- paths.collect!{|d| raise Errno::ENOENT unless File.exist?(d); d.dup}.each do |path|
- path = path.to_path if path.respond_to? :to_path
- enc = path.encoding == Encoding::US_ASCII ? fs_encoding : path.encoding
- ps = [path]
- while file = ps.shift
- catch(:prune) do
- yield file.dup.taint
- begin
- s = File.lstat(file)
- rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
- raise unless ignore_error
- next
- end
- if s.directory? then
- begin
- fs = Dir.entries(file, encoding: enc)
- rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
- raise unless ignore_error
- next
- end
- fs.sort!
- fs.reverse_each {|f|
- next if f == "." or f == ".."
- f = File.join(file, f)
- ps.unshift f.untaint
- }
- end
- end
- end
- end
- nil
- end
-
- #
- # Skips the current file or directory, restarting the loop with the next
- # entry. If the current file is a directory, that directory will not be
- # recursively entered. Meaningful only within the block associated with
- # Find::find.
- #
- # See the +Find+ module documentation for an example.
- #
- def prune
- throw :prune
- end
-
- module_function :find, :prune
-end
diff --git a/ruby_2_2/lib/forwardable.rb b/ruby_2_2/lib/forwardable.rb
deleted file mode 100644
index e78b9ed1e0..0000000000
--- a/ruby_2_2/lib/forwardable.rb
+++ /dev/null
@@ -1,297 +0,0 @@
-# frozen_string_literal: false
-#
-# forwardable.rb -
-# $Release Version: 1.1$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ishitsuka.com)
-# original definition by delegator.rb
-# Revised by Daniel J. Berger with suggestions from Florian Gross.
-#
-# Documentation by James Edward Gray II and Gavin Sinclair
-
-
-
-# The Forwardable module provides delegation of specified
-# methods to a designated object, using the methods #def_delegator
-# and #def_delegators.
-#
-# For example, say you have a class RecordCollection which
-# contains an array <tt>@records</tt>. You could provide the lookup method
-# #record_number(), which simply calls #[] on the <tt>@records</tt>
-# array, like this:
-#
-# require 'forwardable'
-#
-# class RecordCollection
-# attr_accessor :records
-# extend Forwardable
-# def_delegator :@records, :[], :record_number
-# end
-#
-# We can use the lookup method like so:
-#
-# r = RecordCollection.new
-# r.records = [4,5,6]
-# r.record_number(0) # => 4
-#
-# Further, if you wish to provide the methods #size, #<<, and #map,
-# all of which delegate to @records, this is how you can do it:
-#
-# class RecordCollection # re-open RecordCollection class
-# def_delegators :@records, :size, :<<, :map
-# end
-#
-# r = RecordCollection.new
-# r.records = [1,2,3]
-# r.record_number(0) # => 1
-# r.size # => 3
-# r << 4 # => [1, 2, 3, 4]
-# r.map { |x| x * 2 } # => [2, 4, 6, 8]
-#
-# You can even extend regular objects with Forwardable.
-#
-# my_hash = Hash.new
-# my_hash.extend Forwardable # prepare object for delegation
-# my_hash.def_delegator "STDOUT", "puts" # add delegation for STDOUT.puts()
-# my_hash.puts "Howdy!"
-#
-# == Another example
-#
-# We want to rely on what has come before obviously, but with delegation we can
-# take just the methods we need and even rename them as appropriate. In many
-# cases this is preferable to inheritance, which gives us the entire old
-# interface, even if much of it isn't needed.
-#
-# class Queue
-# extend Forwardable
-#
-# def initialize
-# @q = [ ] # prepare delegate object
-# end
-#
-# # setup preferred interface, enq() and deq()...
-# def_delegator :@q, :push, :enq
-# def_delegator :@q, :shift, :deq
-#
-# # support some general Array methods that fit Queues well
-# def_delegators :@q, :clear, :first, :push, :shift, :size
-# end
-#
-# q = Queue.new
-# q.enq 1, 2, 3, 4, 5
-# q.push 6
-#
-# q.shift # => 1
-# while q.size > 0
-# puts q.deq
-# end
-#
-# q.enq "Ruby", "Perl", "Python"
-# puts q.first
-# q.clear
-# puts q.first
-#
-# This should output:
-#
-# 2
-# 3
-# 4
-# 5
-# 6
-# Ruby
-# nil
-#
-# == Notes
-#
-# Be advised, RDoc will not detect delegated methods.
-#
-# +forwardable.rb+ provides single-method delegation via the def_delegator and
-# def_delegators methods. For full-class delegation via DelegateClass, see
-# +delegate.rb+.
-#
-module Forwardable
- # Version of +forwardable.rb+
- FORWARDABLE_VERSION = "1.1.0"
-
- FILE_REGEXP = %r"#{Regexp.quote(__FILE__)}"
-
- @debug = nil
- class << self
- # If true, <tt>__FILE__</tt> will remain in the backtrace in the event an
- # Exception is raised.
- attr_accessor :debug
- end
-
- # Takes a hash as its argument. The key is a symbol or an array of
- # symbols. These symbols correspond to method names. The value is
- # the accessor to which the methods will be delegated.
- #
- # :call-seq:
- # delegate method => accessor
- # delegate [method, method, ...] => accessor
- #
- def instance_delegate(hash)
- hash.each{ |methods, accessor|
- methods = [methods] unless methods.respond_to?(:each)
- methods.each{ |method|
- def_instance_delegator(accessor, method)
- }
- }
- end
-
- #
- # Shortcut for defining multiple delegator methods, but with no
- # provision for using a different name. The following two code
- # samples have the same effect:
- #
- # def_delegators :@records, :size, :<<, :map
- #
- # def_delegator :@records, :size
- # def_delegator :@records, :<<
- # def_delegator :@records, :map
- #
- def def_instance_delegators(accessor, *methods)
- methods.delete("__send__")
- methods.delete("__id__")
- for method in methods
- def_instance_delegator(accessor, method)
- end
- end
-
- # Define +method+ as delegator instance method with an optional
- # alias name +ali+. Method calls to +ali+ will be delegated to
- # +accessor.method+.
- #
- # class MyQueue
- # extend Forwardable
- # attr_reader :queue
- # def initialize
- # @queue = []
- # end
- #
- # def_delegator :@queue, :push, :mypush
- # end
- #
- # q = MyQueue.new
- # q.mypush 42
- # q.queue #=> [42]
- # q.push 23 #=> NoMethodError
- #
- def def_instance_delegator(accessor, method, ali = method)
- gen = Forwardable._delegator_method(self, accessor, method, ali)
-
- # If it's not a class or module, it's an instance
- (Module === self ? self : singleton_class).module_eval(&gen)
- end
-
- alias delegate instance_delegate
- alias def_delegators def_instance_delegators
- alias def_delegator def_instance_delegator
-
- def self._delegator_method(obj, accessor, method, ali)
- accessor = accessor.to_s unless Symbol === accessor
-
- if Module === obj ?
- obj.method_defined?(accessor) || obj.private_method_defined?(accessor) :
- obj.respond_to?(accessor, true)
- accessor = "#{accessor}()"
- end
-
- line_no = __LINE__+1; str = "#{<<-"begin;"}\n#{<<-"end;"}"
- begin;
- proc do
- def #{ali}(*args, &block)
- begin
- #{accessor}
- ensure
- $@.delete_if {|s| ::Forwardable::FILE_REGEXP =~ s} if $@ and !::Forwardable::debug
- end.__send__ :#{method}, *args, &block
- end
- end
- end;
-
- RubyVM::InstructionSequence
- .compile(str, __FILE__, __FILE__, line_no,
- trace_instruction: false,
- tailcall_optimization: true)
- .eval
- end
-end
-
-# SingleForwardable can be used to setup delegation at the object level as well.
-#
-# printer = String.new
-# printer.extend SingleForwardable # prepare object for delegation
-# printer.def_delegator "STDOUT", "puts" # add delegation for STDOUT.puts()
-# printer.puts "Howdy!"
-#
-# Also, SingleForwardable can be used to set up delegation for a Class or Module.
-#
-# class Implementation
-# def self.service
-# puts "serviced!"
-# end
-# end
-#
-# module Facade
-# extend SingleForwardable
-# def_delegator :Implementation, :service
-# end
-#
-# Facade.service #=> serviced!
-#
-# If you want to use both Forwardable and SingleForwardable, you can
-# use methods def_instance_delegator and def_single_delegator, etc.
-module SingleForwardable
- # Takes a hash as its argument. The key is a symbol or an array of
- # symbols. These symbols correspond to method names. The value is
- # the accessor to which the methods will be delegated.
- #
- # :call-seq:
- # delegate method => accessor
- # delegate [method, method, ...] => accessor
- #
- def single_delegate(hash)
- hash.each{ |methods, accessor|
- methods = [methods] unless methods.respond_to?(:each)
- methods.each{ |method|
- def_single_delegator(accessor, method)
- }
- }
- end
-
- #
- # Shortcut for defining multiple delegator methods, but with no
- # provision for using a different name. The following two code
- # samples have the same effect:
- #
- # def_delegators :@records, :size, :<<, :map
- #
- # def_delegator :@records, :size
- # def_delegator :@records, :<<
- # def_delegator :@records, :map
- #
- def def_single_delegators(accessor, *methods)
- methods.delete("__send__")
- methods.delete("__id__")
- for method in methods
- def_single_delegator(accessor, method)
- end
- end
-
- # :call-seq:
- # def_single_delegator(accessor, method, new_name=method)
- #
- # Defines a method _method_ which delegates to _accessor_ (i.e. it calls
- # the method of the same name in _accessor_). If _new_name_ is
- # provided, it is used as the name for the delegate method.
- def def_single_delegator(accessor, method, ali = method)
- gen = Forwardable._delegator_method(self, accessor, method, ali)
-
- instance_eval(&gen)
- end
-
- alias delegate single_delegate
- alias def_delegators def_single_delegators
- alias def_delegator def_single_delegator
-end
diff --git a/ruby_2_2/lib/getoptlong.rb b/ruby_2_2/lib/getoptlong.rb
deleted file mode 100644
index cf635f0438..0000000000
--- a/ruby_2_2/lib/getoptlong.rb
+++ /dev/null
@@ -1,612 +0,0 @@
-#
-# GetoptLong for Ruby
-#
-# Copyright (C) 1998, 1999, 2000 Motoyuki Kasahara.
-#
-# You may redistribute and/or modify this library under the same license
-# terms as Ruby.
-#
-# See GetoptLong for documentation.
-#
-# Additional documents and the latest version of `getoptlong.rb' can be
-# found at http://www.sra.co.jp/people/m-kasahr/ruby/getoptlong/
-
-# The GetoptLong class allows you to parse command line options similarly to
-# the GNU getopt_long() C library call. Note, however, that GetoptLong is a
-# pure Ruby implementation.
-#
-# GetoptLong allows for POSIX-style options like <tt>--file</tt> as well
-# as single letter options like <tt>-f</tt>
-#
-# The empty option <tt>--</tt> (two minus symbols) is used to end option
-# processing. This can be particularly important if options have optional
-# arguments.
-#
-# Here is a simple example of usage:
-#
-# require 'getoptlong'
-#
-# opts = GetoptLong.new(
-# [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
-# [ '--repeat', '-n', GetoptLong::REQUIRED_ARGUMENT ],
-# [ '--name', GetoptLong::OPTIONAL_ARGUMENT ]
-# )
-#
-# dir = nil
-# name = nil
-# repetitions = 1
-# opts.each do |opt, arg|
-# case opt
-# when '--help'
-# puts <<-EOF
-# hello [OPTION] ... DIR
-#
-# -h, --help:
-# show help
-#
-# --repeat x, -n x:
-# repeat x times
-#
-# --name [name]:
-# greet user by name, if name not supplied default is John
-#
-# DIR: The directory in which to issue the greeting.
-# EOF
-# when '--repeat'
-# repetitions = arg.to_i
-# when '--name'
-# if arg == ''
-# name = 'John'
-# else
-# name = arg
-# end
-# end
-# end
-#
-# if ARGV.length != 1
-# puts "Missing dir argument (try --help)"
-# exit 0
-# end
-#
-# dir = ARGV.shift
-#
-# Dir.chdir(dir)
-# for i in (1..repetitions)
-# print "Hello"
-# if name
-# print ", #{name}"
-# end
-# puts
-# end
-#
-# Example command line:
-#
-# hello -n 6 --name -- /tmp
-#
-class GetoptLong
- #
- # Orderings.
- #
- ORDERINGS = [REQUIRE_ORDER = 0, PERMUTE = 1, RETURN_IN_ORDER = 2]
-
- #
- # Argument flags.
- #
- ARGUMENT_FLAGS = [NO_ARGUMENT = 0, REQUIRED_ARGUMENT = 1,
- OPTIONAL_ARGUMENT = 2]
-
- #
- # Status codes.
- #
- STATUS_YET, STATUS_STARTED, STATUS_TERMINATED = 0, 1, 2
-
- #
- # Error types.
- #
- class Error < StandardError; end
- class AmbiguousOption < Error; end
- class NeedlessArgument < Error; end
- class MissingArgument < Error; end
- class InvalidOption < Error; end
-
- #
- # Set up option processing.
- #
- # The options to support are passed to new() as an array of arrays.
- # Each sub-array contains any number of String option names which carry
- # the same meaning, and one of the following flags:
- #
- # GetoptLong::NO_ARGUMENT :: Option does not take an argument.
- #
- # GetoptLong::REQUIRED_ARGUMENT :: Option always takes an argument.
- #
- # GetoptLong::OPTIONAL_ARGUMENT :: Option may or may not take an argument.
- #
- # The first option name is considered to be the preferred (canonical) name.
- # Other than that, the elements of each sub-array can be in any order.
- #
- def initialize(*arguments)
- #
- # Current ordering.
- #
- if ENV.include?('POSIXLY_CORRECT')
- @ordering = REQUIRE_ORDER
- else
- @ordering = PERMUTE
- end
-
- #
- # Hash table of option names.
- # Keys of the table are option names, and their values are canonical
- # names of the options.
- #
- @canonical_names = Hash.new
-
- #
- # Hash table of argument flags.
- # Keys of the table are option names, and their values are argument
- # flags of the options.
- #
- @argument_flags = Hash.new
-
- #
- # Whether error messages are output to $stderr.
- #
- @quiet = FALSE
-
- #
- # Status code.
- #
- @status = STATUS_YET
-
- #
- # Error code.
- #
- @error = nil
-
- #
- # Error message.
- #
- @error_message = nil
-
- #
- # Rest of catenated short options.
- #
- @rest_singles = ''
-
- #
- # List of non-option-arguments.
- # Append them to ARGV when option processing is terminated.
- #
- @non_option_arguments = Array.new
-
- if 0 < arguments.length
- set_options(*arguments)
- end
- end
-
- #
- # Set the handling of the ordering of options and arguments.
- # A RuntimeError is raised if option processing has already started.
- #
- # The supplied value must be a member of GetoptLong::ORDERINGS. It alters
- # the processing of options as follows:
- #
- # <b>REQUIRE_ORDER</b> :
- #
- # Options are required to occur before non-options.
- #
- # Processing of options ends as soon as a word is encountered that has not
- # been preceded by an appropriate option flag.
- #
- # For example, if -a and -b are options which do not take arguments,
- # parsing command line arguments of '-a one -b two' would result in
- # 'one', '-b', 'two' being left in ARGV, and only ('-a', '') being
- # processed as an option/arg pair.
- #
- # This is the default ordering, if the environment variable
- # POSIXLY_CORRECT is set. (This is for compatibility with GNU getopt_long.)
- #
- # <b>PERMUTE</b> :
- #
- # Options can occur anywhere in the command line parsed. This is the
- # default behavior.
- #
- # Every sequence of words which can be interpreted as an option (with or
- # without argument) is treated as an option; non-option words are skipped.
- #
- # For example, if -a does not require an argument and -b optionally takes
- # an argument, parsing '-a one -b two three' would result in ('-a','') and
- # ('-b', 'two') being processed as option/arg pairs, and 'one','three'
- # being left in ARGV.
- #
- # If the ordering is set to PERMUTE but the environment variable
- # POSIXLY_CORRECT is set, REQUIRE_ORDER is used instead. This is for
- # compatibility with GNU getopt_long.
- #
- # <b>RETURN_IN_ORDER</b> :
- #
- # All words on the command line are processed as options. Words not
- # preceded by a short or long option flag are passed as arguments
- # with an option of '' (empty string).
- #
- # For example, if -a requires an argument but -b does not, a command line
- # of '-a one -b two three' would result in option/arg pairs of ('-a', 'one')
- # ('-b', ''), ('', 'two'), ('', 'three') being processed.
- #
- def ordering=(ordering)
- #
- # The method is failed if option processing has already started.
- #
- if @status != STATUS_YET
- set_error(ArgumentError, "argument error")
- raise RuntimeError,
- "invoke ordering=, but option processing has already started"
- end
-
- #
- # Check ordering.
- #
- if !ORDERINGS.include?(ordering)
- raise ArgumentError, "invalid ordering `#{ordering}'"
- end
- if ordering == PERMUTE && ENV.include?('POSIXLY_CORRECT')
- @ordering = REQUIRE_ORDER
- else
- @ordering = ordering
- end
- end
-
- #
- # Return ordering.
- #
- attr_reader :ordering
-
- #
- # Set options. Takes the same argument as GetoptLong.new.
- #
- # Raises a RuntimeError if option processing has already started.
- #
- def set_options(*arguments)
- #
- # The method is failed if option processing has already started.
- #
- if @status != STATUS_YET
- raise RuntimeError,
- "invoke set_options, but option processing has already started"
- end
-
- #
- # Clear tables of option names and argument flags.
- #
- @canonical_names.clear
- @argument_flags.clear
-
- arguments.each do |arg|
- if !arg.is_a?(Array)
- raise ArgumentError, "the option list contains non-Array argument"
- end
-
- #
- # Find an argument flag and it set to `argument_flag'.
- #
- argument_flag = nil
- arg.each do |i|
- if ARGUMENT_FLAGS.include?(i)
- if argument_flag != nil
- raise ArgumentError, "too many argument-flags"
- end
- argument_flag = i
- end
- end
-
- raise ArgumentError, "no argument-flag" if argument_flag == nil
-
- canonical_name = nil
- arg.each do |i|
- #
- # Check an option name.
- #
- next if i == argument_flag
- begin
- if !i.is_a?(String) || i !~ /^-([^-]|-.+)$/
- raise ArgumentError, "an invalid option `#{i}'"
- end
- if (@canonical_names.include?(i))
- raise ArgumentError, "option redefined `#{i}'"
- end
- rescue
- @canonical_names.clear
- @argument_flags.clear
- raise
- end
-
- #
- # Register the option (`i') to the `@canonical_names' and
- # `@canonical_names' Hashes.
- #
- if canonical_name == nil
- canonical_name = i
- end
- @canonical_names[i] = canonical_name
- @argument_flags[i] = argument_flag
- end
- raise ArgumentError, "no option name" if canonical_name == nil
- end
- return self
- end
-
- #
- # Set/Unset `quiet' mode.
- #
- attr_writer :quiet
-
- #
- # Return the flag of `quiet' mode.
- #
- attr_reader :quiet
-
- #
- # `quiet?' is an alias of `quiet'.
- #
- alias quiet? quiet
-
- #
- # Explicitly terminate option processing.
- #
- def terminate
- return nil if @status == STATUS_TERMINATED
- raise RuntimeError, "an error has occurred" if @error != nil
-
- @status = STATUS_TERMINATED
- @non_option_arguments.reverse_each do |argument|
- ARGV.unshift(argument)
- end
-
- @canonical_names = nil
- @argument_flags = nil
- @rest_singles = nil
- @non_option_arguments = nil
-
- return self
- end
-
- #
- # Returns true if option processing has terminated, false otherwise.
- #
- def terminated?
- return @status == STATUS_TERMINATED
- end
-
- #
- # Set an error (a protected method).
- #
- def set_error(type, message)
- $stderr.print("#{$0}: #{message}\n") if !@quiet
-
- @error = type
- @error_message = message
- @canonical_names = nil
- @argument_flags = nil
- @rest_singles = nil
- @non_option_arguments = nil
-
- raise type, message
- end
- protected :set_error
-
- #
- # Examine whether an option processing is failed.
- #
- attr_reader :error
-
- #
- # `error?' is an alias of `error'.
- #
- alias error? error
-
- # Return the appropriate error message in POSIX-defined format.
- # If no error has occurred, returns nil.
- #
- def error_message
- return @error_message
- end
-
- #
- # Get next option name and its argument, as an Array of two elements.
- #
- # The option name is always converted to the first (preferred)
- # name given in the original options to GetoptLong.new.
- #
- # Example: ['--option', 'value']
- #
- # Returns nil if the processing is complete (as determined by
- # STATUS_TERMINATED).
- #
- def get
- option_name, option_argument = nil, ''
-
- #
- # Check status.
- #
- return nil if @error != nil
- case @status
- when STATUS_YET
- @status = STATUS_STARTED
- when STATUS_TERMINATED
- return nil
- end
-
- #
- # Get next option argument.
- #
- if 0 < @rest_singles.length
- argument = '-' + @rest_singles
- elsif (ARGV.length == 0)
- terminate
- return nil
- elsif @ordering == PERMUTE
- while 0 < ARGV.length && ARGV[0] !~ /^-./
- @non_option_arguments.push(ARGV.shift)
- end
- if ARGV.length == 0
- terminate
- return nil
- end
- argument = ARGV.shift
- elsif @ordering == REQUIRE_ORDER
- if (ARGV[0] !~ /^-./)
- terminate
- return nil
- end
- argument = ARGV.shift
- else
- argument = ARGV.shift
- end
-
- #
- # Check the special argument `--'.
- # `--' indicates the end of the option list.
- #
- if argument == '--' && @rest_singles.length == 0
- terminate
- return nil
- end
-
- #
- # Check for long and short options.
- #
- if argument =~ /^(--[^=]+)/ && @rest_singles.length == 0
- #
- # This is a long style option, which start with `--'.
- #
- pattern = $1
- if @canonical_names.include?(pattern)
- option_name = pattern
- else
- #
- # The option `option_name' is not registered in `@canonical_names'.
- # It may be an abbreviated.
- #
- matches = []
- @canonical_names.each_key do |key|
- if key.index(pattern) == 0
- option_name = key
- matches << key
- end
- end
- if 2 <= matches.length
- set_error(AmbiguousOption, "option `#{argument}' is ambiguous between #{matches.join(', ')}")
- elsif matches.length == 0
- set_error(InvalidOption, "unrecognized option `#{argument}'")
- end
- end
-
- #
- # Check an argument to the option.
- #
- if @argument_flags[option_name] == REQUIRED_ARGUMENT
- if argument =~ /=(.*)$/
- option_argument = $1
- elsif 0 < ARGV.length
- option_argument = ARGV.shift
- else
- set_error(MissingArgument,
- "option `#{argument}' requires an argument")
- end
- elsif @argument_flags[option_name] == OPTIONAL_ARGUMENT
- if argument =~ /=(.*)$/
- option_argument = $1
- elsif 0 < ARGV.length && ARGV[0] !~ /^-./
- option_argument = ARGV.shift
- else
- option_argument = ''
- end
- elsif argument =~ /=(.*)$/
- set_error(NeedlessArgument,
- "option `#{option_name}' doesn't allow an argument")
- end
-
- elsif argument =~ /^(-(.))(.*)/
- #
- # This is a short style option, which start with `-' (not `--').
- # Short options may be catenated (e.g. `-l -g' is equivalent to
- # `-lg').
- #
- option_name, ch, @rest_singles = $1, $2, $3
-
- if @canonical_names.include?(option_name)
- #
- # The option `option_name' is found in `@canonical_names'.
- # Check its argument.
- #
- if @argument_flags[option_name] == REQUIRED_ARGUMENT
- if 0 < @rest_singles.length
- option_argument = @rest_singles
- @rest_singles = ''
- elsif 0 < ARGV.length
- option_argument = ARGV.shift
- else
- # 1003.2 specifies the format of this message.
- set_error(MissingArgument, "option requires an argument -- #{ch}")
- end
- elsif @argument_flags[option_name] == OPTIONAL_ARGUMENT
- if 0 < @rest_singles.length
- option_argument = @rest_singles
- @rest_singles = ''
- elsif 0 < ARGV.length && ARGV[0] !~ /^-./
- option_argument = ARGV.shift
- else
- option_argument = ''
- end
- end
- else
- #
- # This is an invalid option.
- # 1003.2 specifies the format of this message.
- #
- if ENV.include?('POSIXLY_CORRECT')
- set_error(InvalidOption, "invalid option -- #{ch}")
- else
- set_error(InvalidOption, "invalid option -- #{ch}")
- end
- end
- else
- #
- # This is a non-option argument.
- # Only RETURN_IN_ORDER falled into here.
- #
- return '', argument
- end
-
- return @canonical_names[option_name], option_argument
- end
-
- #
- # `get_option' is an alias of `get'.
- #
- alias get_option get
-
- # Iterator version of `get'.
- #
- # The block is called repeatedly with two arguments:
- # The first is the option name.
- # The second is the argument which followed it (if any).
- # Example: ('--opt', 'value')
- #
- # The option name is always converted to the first (preferred)
- # name given in the original options to GetoptLong.new.
- #
- def each
- loop do
- option_name, option_argument = get_option
- break if option_name == nil
- yield option_name, option_argument
- end
- end
-
- #
- # `each_option' is an alias of `each'.
- #
- alias each_option each
-end
diff --git a/ruby_2_2/lib/ipaddr.rb b/ruby_2_2/lib/ipaddr.rb
deleted file mode 100644
index b0df4d3e6f..0000000000
--- a/ruby_2_2/lib/ipaddr.rb
+++ /dev/null
@@ -1,658 +0,0 @@
-#
-# ipaddr.rb - A class to manipulate an IP address
-#
-# Copyright (c) 2002 Hajimu UMEMOTO <ume@mahoroba.org>.
-# Copyright (c) 2007, 2009, 2012 Akinori MUSHA <knu@iDaemons.org>.
-# All rights reserved.
-#
-# You can redistribute and/or modify it under the same terms as Ruby.
-#
-# $Id$
-#
-# Contact:
-# - Akinori MUSHA <knu@iDaemons.org> (current maintainer)
-#
-# TODO:
-# - scope_id support
-#
-require 'socket'
-
-# IPAddr provides a set of methods to manipulate an IP address. Both IPv4 and
-# IPv6 are supported.
-#
-# == Example
-#
-# require 'ipaddr'
-#
-# ipaddr1 = IPAddr.new "3ffe:505:2::1"
-#
-# p ipaddr1 #=> #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0001/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>
-#
-# p ipaddr1.to_s #=> "3ffe:505:2::1"
-#
-# ipaddr2 = ipaddr1.mask(48) #=> #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0000/ffff:ffff:ffff:0000:0000:0000:0000:0000>
-#
-# p ipaddr2.to_s #=> "3ffe:505:2::"
-#
-# ipaddr3 = IPAddr.new "192.168.2.0/24"
-#
-# p ipaddr3 #=> #<IPAddr: IPv4:192.168.2.0/255.255.255.0>
-
-class IPAddr
-
- # 32 bit mask for IPv4
- IN4MASK = 0xffffffff
- # 128 bit mask for IPv4
- IN6MASK = 0xffffffffffffffffffffffffffffffff
- # Format string for IPv6
- IN6FORMAT = (["%.4x"] * 8).join(':')
-
- # Regexp _internally_ used for parsing IPv4 address.
- RE_IPV4ADDRLIKE = %r{
- \A
- (\d+) \. (\d+) \. (\d+) \. (\d+)
- \z
- }x
-
- # Regexp _internally_ used for parsing IPv6 address.
- RE_IPV6ADDRLIKE_FULL = %r{
- \A
- (?:
- (?: [\da-f]{1,4} : ){7} [\da-f]{1,4}
- |
- ( (?: [\da-f]{1,4} : ){6} )
- (\d+) \. (\d+) \. (\d+) \. (\d+)
- )
- \z
- }xi
-
- # Regexp _internally_ used for parsing IPv6 address.
- RE_IPV6ADDRLIKE_COMPRESSED = %r{
- \A
- ( (?: (?: [\da-f]{1,4} : )* [\da-f]{1,4} )? )
- ::
- ( (?:
- ( (?: [\da-f]{1,4} : )* )
- (?:
- [\da-f]{1,4}
- |
- (\d+) \. (\d+) \. (\d+) \. (\d+)
- )
- )? )
- \z
- }xi
-
- # Generic IPAddr related error. Exceptions raised in this class should
- # inherit from Error.
- class Error < ArgumentError; end
-
- # Raised when the provided IP address is an invalid address.
- class InvalidAddressError < Error; end
-
- # Raised when the address family is invalid such as an address with an
- # unsupported family, an address with an inconsistent family, or an address
- # who's family cannot be determined.
- class AddressFamilyError < Error; end
-
- # Raised when the address is an invalid length.
- class InvalidPrefixError < InvalidAddressError; end
-
- # Returns the address family of this IP address.
- attr_reader :family
-
- # Creates a new ipaddr containing the given network byte ordered
- # string form of an IP address.
- def IPAddr::new_ntoh(addr)
- return IPAddr.new(IPAddr::ntop(addr))
- end
-
- # Convert a network byte ordered string form of an IP address into
- # human readable form.
- def IPAddr::ntop(addr)
- case addr.size
- when 4
- s = addr.unpack('C4').join('.')
- when 16
- s = IN6FORMAT % addr.unpack('n8')
- else
- raise AddressFamilyError, "unsupported address family"
- end
- return s
- end
-
- # Returns a new ipaddr built by bitwise AND.
- def &(other)
- return self.clone.set(@addr & coerce_other(other).to_i)
- end
-
- # Returns a new ipaddr built by bitwise OR.
- def |(other)
- return self.clone.set(@addr | coerce_other(other).to_i)
- end
-
- # Returns a new ipaddr built by bitwise right-shift.
- def >>(num)
- return self.clone.set(@addr >> num)
- end
-
- # Returns a new ipaddr built by bitwise left shift.
- def <<(num)
- return self.clone.set(addr_mask(@addr << num))
- end
-
- # Returns a new ipaddr built by bitwise negation.
- def ~
- return self.clone.set(addr_mask(~@addr))
- end
-
- # Returns true if two ipaddrs are equal.
- def ==(other)
- other = coerce_other(other)
- return @family == other.family && @addr == other.to_i
- end
-
- # Returns a new ipaddr built by masking IP address with the given
- # prefixlen/netmask. (e.g. 8, 64, "255.255.255.0", etc.)
- def mask(prefixlen)
- return self.clone.mask!(prefixlen)
- end
-
- # Returns true if the given ipaddr is in the range.
- #
- # e.g.:
- # require 'ipaddr'
- # net1 = IPAddr.new("192.168.2.0/24")
- # net2 = IPAddr.new("192.168.2.100")
- # net3 = IPAddr.new("192.168.3.0")
- # p net1.include?(net2) #=> true
- # p net1.include?(net3) #=> false
- def include?(other)
- other = coerce_other(other)
- if ipv4_mapped?
- if (@mask_addr >> 32) != 0xffffffffffffffffffffffff
- return false
- end
- mask_addr = (@mask_addr & IN4MASK)
- addr = (@addr & IN4MASK)
- family = Socket::AF_INET
- else
- mask_addr = @mask_addr
- addr = @addr
- family = @family
- end
- if other.ipv4_mapped?
- other_addr = (other.to_i & IN4MASK)
- other_family = Socket::AF_INET
- else
- other_addr = other.to_i
- other_family = other.family
- end
-
- if family != other_family
- return false
- end
- return ((addr & mask_addr) == (other_addr & mask_addr))
- end
- alias === include?
-
- # Returns the integer representation of the ipaddr.
- def to_i
- return @addr
- end
-
- # Returns a string containing the IP address representation.
- def to_s
- str = to_string
- return str if ipv4?
-
- str.gsub!(/\b0{1,3}([\da-f]+)\b/i, '\1')
- loop do
- break if str.sub!(/\A0:0:0:0:0:0:0:0\z/, '::')
- break if str.sub!(/\b0:0:0:0:0:0:0\b/, ':')
- break if str.sub!(/\b0:0:0:0:0:0\b/, ':')
- break if str.sub!(/\b0:0:0:0:0\b/, ':')
- break if str.sub!(/\b0:0:0:0\b/, ':')
- break if str.sub!(/\b0:0:0\b/, ':')
- break if str.sub!(/\b0:0\b/, ':')
- break
- end
- str.sub!(/:{3,}/, '::')
-
- if /\A::(ffff:)?([\da-f]{1,4}):([\da-f]{1,4})\z/i =~ str
- str = sprintf('::%s%d.%d.%d.%d', $1, $2.hex / 256, $2.hex % 256, $3.hex / 256, $3.hex % 256)
- end
-
- str
- end
-
- # Returns a string containing the IP address representation in
- # canonical form.
- def to_string
- return _to_string(@addr)
- end
-
- # Returns a network byte ordered string form of the IP address.
- def hton
- case @family
- when Socket::AF_INET
- return [@addr].pack('N')
- when Socket::AF_INET6
- return (0..7).map { |i|
- (@addr >> (112 - 16 * i)) & 0xffff
- }.pack('n8')
- else
- raise AddressFamilyError, "unsupported address family"
- end
- end
-
- # Returns true if the ipaddr is an IPv4 address.
- def ipv4?
- return @family == Socket::AF_INET
- end
-
- # Returns true if the ipaddr is an IPv6 address.
- def ipv6?
- return @family == Socket::AF_INET6
- end
-
- # Returns true if the ipaddr is an IPv4-mapped IPv6 address.
- def ipv4_mapped?
- return ipv6? && (@addr >> 32) == 0xffff
- end
-
- # Returns true if the ipaddr is an IPv4-compatible IPv6 address.
- def ipv4_compat?
- if !ipv6? || (@addr >> 32) != 0
- return false
- end
- a = (@addr & IN4MASK)
- return a != 0 && a != 1
- end
-
- # Returns a new ipaddr built by converting the native IPv4 address
- # into an IPv4-mapped IPv6 address.
- def ipv4_mapped
- if !ipv4?
- raise InvalidAddressError, "not an IPv4 address"
- end
- return self.clone.set(@addr | 0xffff00000000, Socket::AF_INET6)
- end
-
- # Returns a new ipaddr built by converting the native IPv4 address
- # into an IPv4-compatible IPv6 address.
- def ipv4_compat
- if !ipv4?
- raise InvalidAddressError, "not an IPv4 address"
- end
- return self.clone.set(@addr, Socket::AF_INET6)
- end
-
- # Returns a new ipaddr built by converting the IPv6 address into a
- # native IPv4 address. If the IP address is not an IPv4-mapped or
- # IPv4-compatible IPv6 address, returns self.
- def native
- if !ipv4_mapped? && !ipv4_compat?
- return self
- end
- return self.clone.set(@addr & IN4MASK, Socket::AF_INET)
- end
-
- # Returns a string for DNS reverse lookup. It returns a string in
- # RFC3172 form for an IPv6 address.
- def reverse
- case @family
- when Socket::AF_INET
- return _reverse + ".in-addr.arpa"
- when Socket::AF_INET6
- return ip6_arpa
- else
- raise AddressFamilyError, "unsupported address family"
- end
- end
-
- # Returns a string for DNS reverse lookup compatible with RFC3172.
- def ip6_arpa
- if !ipv6?
- raise InvalidAddressError, "not an IPv6 address"
- end
- return _reverse + ".ip6.arpa"
- end
-
- # Returns a string for DNS reverse lookup compatible with RFC1886.
- def ip6_int
- if !ipv6?
- raise InvalidAddressError, "not an IPv6 address"
- end
- return _reverse + ".ip6.int"
- end
-
- # Returns the successor to the ipaddr.
- def succ
- return self.clone.set(@addr + 1, @family)
- end
-
- # Compares the ipaddr with another.
- def <=>(other)
- other = coerce_other(other)
-
- return nil if other.family != @family
-
- return @addr <=> other.to_i
- end
- include Comparable
-
- # Checks equality used by Hash.
- def eql?(other)
- return self.class == other.class && self.hash == other.hash && self == other
- end
-
- # Returns a hash value used by Hash, Set, and Array classes
- def hash
- return ([@addr, @mask_addr].hash << 1) | (ipv4? ? 0 : 1)
- end
-
- # Creates a Range object for the network address.
- def to_range
- begin_addr = (@addr & @mask_addr)
-
- case @family
- when Socket::AF_INET
- end_addr = (@addr | (IN4MASK ^ @mask_addr))
- when Socket::AF_INET6
- end_addr = (@addr | (IN6MASK ^ @mask_addr))
- else
- raise AddressFamilyError, "unsupported address family"
- end
-
- return clone.set(begin_addr, @family)..clone.set(end_addr, @family)
- end
-
- # Returns a string containing a human-readable representation of the
- # ipaddr. ("#<IPAddr: family:address/mask>")
- def inspect
- case @family
- when Socket::AF_INET
- af = "IPv4"
- when Socket::AF_INET6
- af = "IPv6"
- else
- raise AddressFamilyError, "unsupported address family"
- end
- return sprintf("#<%s: %s:%s/%s>", self.class.name,
- af, _to_string(@addr), _to_string(@mask_addr))
- end
-
- protected
-
- # Set +@addr+, the internal stored ip address, to given +addr+. The
- # parameter +addr+ is validated using the first +family+ member,
- # which is +Socket::AF_INET+ or +Socket::AF_INET6+.
- def set(addr, *family)
- case family[0] ? family[0] : @family
- when Socket::AF_INET
- if addr < 0 || addr > IN4MASK
- raise InvalidAddressError, "invalid address"
- end
- when Socket::AF_INET6
- if addr < 0 || addr > IN6MASK
- raise InvalidAddressError, "invalid address"
- end
- else
- raise AddressFamilyError, "unsupported address family"
- end
- @addr = addr
- if family[0]
- @family = family[0]
- end
- return self
- end
-
- # Set current netmask to given mask.
- def mask!(mask)
- if mask.kind_of?(String)
- if mask =~ /\A\d+\z/
- prefixlen = mask.to_i
- else
- m = IPAddr.new(mask)
- if m.family != @family
- raise InvalidPrefixError, "address family is not same"
- end
- @mask_addr = m.to_i
- @addr &= @mask_addr
- return self
- end
- else
- prefixlen = mask
- end
- case @family
- when Socket::AF_INET
- if prefixlen < 0 || prefixlen > 32
- raise InvalidPrefixError, "invalid length"
- end
- masklen = 32 - prefixlen
- @mask_addr = ((IN4MASK >> masklen) << masklen)
- when Socket::AF_INET6
- if prefixlen < 0 || prefixlen > 128
- raise InvalidPrefixError, "invalid length"
- end
- masklen = 128 - prefixlen
- @mask_addr = ((IN6MASK >> masklen) << masklen)
- else
- raise AddressFamilyError, "unsupported address family"
- end
- @addr = ((@addr >> masklen) << masklen)
- return self
- end
-
- private
-
- # Creates a new ipaddr object either from a human readable IP
- # address representation in string, or from a packed in_addr value
- # followed by an address family.
- #
- # In the former case, the following are the valid formats that will
- # be recognized: "address", "address/prefixlen" and "address/mask",
- # where IPv6 address may be enclosed in square brackets (`[' and
- # `]'). If a prefixlen or a mask is specified, it returns a masked
- # IP address. Although the address family is determined
- # automatically from a specified string, you can specify one
- # explicitly by the optional second argument.
- #
- # Otherwise an IP address is generated from a packed in_addr value
- # and an address family.
- #
- # The IPAddr class defines many methods and operators, and some of
- # those, such as &, |, include? and ==, accept a string, or a packed
- # in_addr value instead of an IPAddr object.
- def initialize(addr = '::', family = Socket::AF_UNSPEC)
- if !addr.kind_of?(String)
- case family
- when Socket::AF_INET, Socket::AF_INET6
- set(addr.to_i, family)
- @mask_addr = (family == Socket::AF_INET) ? IN4MASK : IN6MASK
- return
- when Socket::AF_UNSPEC
- raise AddressFamilyError, "address family must be specified"
- else
- raise AddressFamilyError, "unsupported address family: #{family}"
- end
- end
- prefix, prefixlen = addr.split('/')
- if prefix =~ /\A\[(.*)\]\z/i
- prefix = $1
- family = Socket::AF_INET6
- end
- # It seems AI_NUMERICHOST doesn't do the job.
- #Socket.getaddrinfo(left, nil, Socket::AF_INET6, Socket::SOCK_STREAM, nil,
- # Socket::AI_NUMERICHOST)
- @addr = @family = nil
- if family == Socket::AF_UNSPEC || family == Socket::AF_INET
- @addr = in_addr(prefix)
- if @addr
- @family = Socket::AF_INET
- end
- end
- if !@addr && (family == Socket::AF_UNSPEC || family == Socket::AF_INET6)
- @addr = in6_addr(prefix)
- @family = Socket::AF_INET6
- end
- if family != Socket::AF_UNSPEC && @family != family
- raise AddressFamilyError, "address family mismatch"
- end
- if prefixlen
- mask!(prefixlen)
- else
- @mask_addr = (@family == Socket::AF_INET) ? IN4MASK : IN6MASK
- end
- end
-
- def coerce_other(other)
- case other
- when IPAddr
- other
- when String
- self.class.new(other)
- else
- self.class.new(other, @family)
- end
- end
-
- def in_addr(addr)
- case addr
- when Array
- octets = addr
- else
- m = RE_IPV4ADDRLIKE.match(addr) or return nil
- octets = m.captures
- end
- octets.inject(0) { |i, s|
- (n = s.to_i) < 256 or raise InvalidAddressError, "invalid address"
- s.match(/\A0./) and raise InvalidAddressError, "zero-filled number in IPv4 address is ambiguous"
- i << 8 | n
- }
- end
-
- def in6_addr(left)
- case left
- when RE_IPV6ADDRLIKE_FULL
- if $2
- addr = in_addr($~[2,4])
- left = $1 + ':'
- else
- addr = 0
- end
- right = ''
- when RE_IPV6ADDRLIKE_COMPRESSED
- if $4
- left.count(':') <= 6 or raise InvalidAddressError, "invalid address"
- addr = in_addr($~[4,4])
- left = $1
- right = $3 + '0:0'
- else
- left.count(':') <= ($1.empty? || $2.empty? ? 8 : 7) or
- raise InvalidAddressError, "invalid address"
- left = $1
- right = $2
- addr = 0
- end
- else
- raise InvalidAddressError, "invalid address"
- end
- l = left.split(':')
- r = right.split(':')
- rest = 8 - l.size - r.size
- if rest < 0
- return nil
- end
- (l + Array.new(rest, '0') + r).inject(0) { |i, s|
- i << 16 | s.hex
- } | addr
- end
-
- def addr_mask(addr)
- case @family
- when Socket::AF_INET
- return addr & IN4MASK
- when Socket::AF_INET6
- return addr & IN6MASK
- else
- raise AddressFamilyError, "unsupported address family"
- end
- end
-
- def _reverse
- case @family
- when Socket::AF_INET
- return (0..3).map { |i|
- (@addr >> (8 * i)) & 0xff
- }.join('.')
- when Socket::AF_INET6
- return ("%.32x" % @addr).reverse!.gsub!(/.(?!$)/, '\&.')
- else
- raise AddressFamilyError, "unsupported address family"
- end
- end
-
- def _to_string(addr)
- case @family
- when Socket::AF_INET
- return (0..3).map { |i|
- (addr >> (24 - 8 * i)) & 0xff
- }.join('.')
- when Socket::AF_INET6
- return (("%.32x" % addr).gsub!(/.{4}(?!$)/, '\&:'))
- else
- raise AddressFamilyError, "unsupported address family"
- end
- end
-
-end
-
-unless Socket.const_defined? :AF_INET6
- class Socket < BasicSocket
- # IPv6 protocol family
- AF_INET6 = Object.new
- end
-
- class << IPSocket
- private
-
- def valid_v6?(addr)
- case addr
- when IPAddr::RE_IPV6ADDRLIKE_FULL
- if $2
- $~[2,4].all? {|i| i.to_i < 256 }
- else
- true
- end
- when IPAddr::RE_IPV6ADDRLIKE_COMPRESSED
- if $4
- addr.count(':') <= 6 && $~[4,4].all? {|i| i.to_i < 256}
- else
- addr.count(':') <= 7
- end
- else
- false
- end
- end
-
- alias getaddress_orig getaddress
-
- public
-
- # Returns a +String+ based representation of a valid DNS hostname,
- # IPv4 or IPv6 address.
- #
- # IPSocket.getaddress 'localhost' #=> "::1"
- # IPSocket.getaddress 'broadcasthost' #=> "255.255.255.255"
- # IPSocket.getaddress 'www.ruby-lang.org' #=> "221.186.184.68"
- # IPSocket.getaddress 'www.ccc.de' #=> "2a00:1328:e102:ccc0::122"
- def getaddress(s)
- if valid_v6?(s)
- s
- else
- getaddress_orig(s)
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/irb.rb b/ruby_2_2/lib/irb.rb
deleted file mode 100644
index a7da846bc6..0000000000
--- a/ruby_2_2/lib/irb.rb
+++ /dev/null
@@ -1,703 +0,0 @@
-#
-# irb.rb - irb main module
-# $Release Version: 0.9.6 $
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-require "e2mmap"
-
-require "irb/init"
-require "irb/context"
-require "irb/extend-command"
-
-require "irb/ruby-lex"
-require "irb/input-method"
-require "irb/locale"
-
-STDOUT.sync = true
-
-# IRB stands for "interactive Ruby" and is a tool to interactively execute Ruby
-# expressions read from the standard input.
-#
-# The +irb+ command from your shell will start the interpreter.
-#
-# == Usage
-#
-# Use of irb is easy if you know Ruby.
-#
-# When executing irb, prompts are displayed as follows. Then, enter the Ruby
-# expression. An input is executed when it is syntactically complete.
-#
-# $ irb
-# irb(main):001:0> 1+2
-# #=> 3
-# irb(main):002:0> class Foo
-# irb(main):003:1> def foo
-# irb(main):004:2> print 1
-# irb(main):005:2> end
-# irb(main):006:1> end
-# #=> nil
-#
-# The Readline extension module can be used with irb. Use of Readline is
-# default if it's installed.
-#
-# == Command line options
-#
-# Usage: irb.rb [options] [programfile] [arguments]
-# -f Suppress read of ~/.irbrc
-# -m Bc mode (load mathn, fraction or matrix are available)
-# -d Set $DEBUG to true (same as `ruby -d')
-# -r load-module Same as `ruby -r'
-# -I path Specify $LOAD_PATH directory
-# -U Same as `ruby -U`
-# -E enc Same as `ruby -E`
-# -w Same as `ruby -w`
-# -W[level=2] Same as `ruby -W`
-# --inspect Use `inspect' for output (default except for bc mode)
-# --noinspect Don't use inspect for output
-# --readline Use Readline extension module
-# --noreadline Don't use Readline extension module
-# --prompt prompt-mode
-# --prompt-mode prompt-mode
-# Switch prompt mode. Pre-defined prompt modes are
-# `default', `simple', `xmp' and `inf-ruby'
-# --inf-ruby-mode Use prompt appropriate for inf-ruby-mode on emacs.
-# Suppresses --readline.
-# --simple-prompt Simple prompt mode
-# --noprompt No prompt mode
-# --tracer Display trace for each execution of commands.
-# --back-trace-limit n
-# Display backtrace top n and tail n. The default
-# value is 16.
-# --irb_debug n Set internal debug level to n (not for popular use)
-# -v, --version Print the version of irb
-#
-# == Configuration
-#
-# IRB reads from <code>~/.irbrc</code> when it's invoked.
-#
-# If <code>~/.irbrc</code> doesn't exist, +irb+ will try to read in the following order:
-#
-# * +.irbrc+
-# * +irb.rc+
-# * +_irbrc+
-# * <code>$irbrc</code>
-#
-# The following are alternatives to the command line options. To use them type
-# as follows in an +irb+ session:
-#
-# IRB.conf[:IRB_NAME]="irb"
-# IRB.conf[:MATH_MODE]=false
-# IRB.conf[:INSPECT_MODE]=nil
-# IRB.conf[:IRB_RC] = nil
-# IRB.conf[:BACK_TRACE_LIMIT]=16
-# IRB.conf[:USE_LOADER] = false
-# IRB.conf[:USE_READLINE] = nil
-# IRB.conf[:USE_TRACER] = false
-# IRB.conf[:IGNORE_SIGINT] = true
-# IRB.conf[:IGNORE_EOF] = false
-# IRB.conf[:PROMPT_MODE] = :DEFAULT
-# IRB.conf[:PROMPT] = {...}
-# IRB.conf[:DEBUG_LEVEL]=0
-#
-# === Auto indentation
-#
-# To enable auto-indent mode in irb, add the following to your +.irbrc+:
-#
-# IRB.conf[:AUTO_INDENT] = true
-#
-# === Autocompletion
-#
-# To enable autocompletion for irb, add the following to your +.irbrc+:
-#
-# require 'irb/completion'
-#
-# === History
-#
-# By default, irb disables history and will not store any commands you used.
-#
-# If you want to enable history, add the following to your +.irbrc+:
-#
-# IRB.conf[:SAVE_HISTORY] = 1000
-#
-# This will now store the last 1000 commands in <code>~/.irb_history</code>.
-#
-# See IRB::Context#save_history= for more information.
-#
-# == Customizing the IRB Prompt
-#
-# In order to customize the prompt, you can change the following Hash:
-#
-# IRB.conf[:PROMPT]
-#
-# This example can be used in your +.irbrc+
-#
-# IRB.conf[:PROMPT][:MY_PROMPT] = { # name of prompt mode
-# :AUTO_INDENT => true, # enables auto-indent mode
-# :PROMPT_I => ">> ", # simple prompt
-# :PROMPT_S => nil, # prompt for continuated strings
-# :PROMPT_C => nil, # prompt for continuated statement
-# :RETURN => " ==>%s\n" # format to return value
-# }
-#
-# IRB.conf[:PROMPT_MODE] = :MY_PROMPT
-#
-# Or, invoke irb with the above prompt mode by:
-#
-# irb --prompt my-prompt
-#
-# Constants +PROMPT_I+, +PROMPT_S+ and +PROMPT_C+ specify the format. In the
-# prompt specification, some special strings are available:
-#
-# %N # command name which is running
-# %m # to_s of main object (self)
-# %M # inspect of main object (self)
-# %l # type of string(", ', /, ]), `]' is inner %w[...]
-# %NNi # indent level. NN is digits and means as same as printf("%NNd").
-# # It can be ommited
-# %NNn # line number.
-# %% # %
-#
-# For instance, the default prompt mode is defined as follows:
-#
-# IRB.conf[:PROMPT_MODE][:DEFAULT] = {
-# :PROMPT_I => "%N(%m):%03n:%i> ",
-# :PROMPT_S => "%N(%m):%03n:%i%l ",
-# :PROMPT_C => "%N(%m):%03n:%i* ",
-# :RETURN => "%s\n" # used to printf
-# }
-#
-# irb comes with a number of available modes:
-#
-# # :NULL:
-# # :PROMPT_I:
-# # :PROMPT_N:
-# # :PROMPT_S:
-# # :PROMPT_C:
-# # :RETURN: |
-# # %s
-# # :DEFAULT:
-# # :PROMPT_I: ! '%N(%m):%03n:%i> '
-# # :PROMPT_N: ! '%N(%m):%03n:%i> '
-# # :PROMPT_S: ! '%N(%m):%03n:%i%l '
-# # :PROMPT_C: ! '%N(%m):%03n:%i* '
-# # :RETURN: |
-# # => %s
-# # :CLASSIC:
-# # :PROMPT_I: ! '%N(%m):%03n:%i> '
-# # :PROMPT_N: ! '%N(%m):%03n:%i> '
-# # :PROMPT_S: ! '%N(%m):%03n:%i%l '
-# # :PROMPT_C: ! '%N(%m):%03n:%i* '
-# # :RETURN: |
-# # %s
-# # :SIMPLE:
-# # :PROMPT_I: ! '>> '
-# # :PROMPT_N: ! '>> '
-# # :PROMPT_S:
-# # :PROMPT_C: ! '?> '
-# # :RETURN: |
-# # => %s
-# # :INF_RUBY:
-# # :PROMPT_I: ! '%N(%m):%03n:%i> '
-# # :PROMPT_N:
-# # :PROMPT_S:
-# # :PROMPT_C:
-# # :RETURN: |
-# # %s
-# # :AUTO_INDENT: true
-# # :XMP:
-# # :PROMPT_I:
-# # :PROMPT_N:
-# # :PROMPT_S:
-# # :PROMPT_C:
-# # :RETURN: |2
-# # ==>%s
-#
-# == Restrictions
-#
-# Because irb evaluates input immediately after it is syntactically complete,
-# the results may be slightly different than directly using Ruby.
-#
-# == IRB Sessions
-#
-# IRB has a special feature, that allows you to manage many sessions at once.
-#
-# You can create new sessions with Irb.irb, and get a list of current sessions
-# with the +jobs+ command in the prompt.
-#
-# === Commands
-#
-# JobManager provides commands to handle the current sessions:
-#
-# jobs # List of current sessions
-# fg # Switches to the session of the given number
-# kill # Kills the session with the given number
-#
-# The +exit+ command, or ::irb_exit, will quit the current session and call any
-# exit hooks with IRB.irb_at_exit.
-#
-# A few commands for loading files within the session are also available:
-#
-# +source+::
-# Loads a given file in the current session and displays the source lines,
-# see IrbLoader#source_file
-# +irb_load+::
-# Loads the given file similarly to Kernel#load, see IrbLoader#irb_load
-# +irb_require+::
-# Loads the given file similarly to Kernel#require
-#
-# === Configuration
-#
-# The command line options, or IRB.conf, specify the default behavior of
-# Irb.irb.
-#
-# On the other hand, each conf in IRB@Command+line+options is used to
-# individually configure IRB.irb.
-#
-# If a proc is set for IRB.conf[:IRB_RC], its will be invoked after execution
-# of that proc with the context of the current session as its argument. Each
-# session can be configured using this mechanism.
-#
-# === Session variables
-#
-# There are a few variables in every Irb session that can come in handy:
-#
-# <code>_</code>::
-# The value command executed, as a local variable
-# <code>__</code>::
-# The history of evaluated commands
-# <code>__[line_no]</code>::
-# Returns the evaluation value at the given line number, +line_no+.
-# If +line_no+ is a negative, the return value +line_no+ many lines before
-# the most recent return value.
-#
-# === Example using IRB Sessions
-#
-# # invoke a new session
-# irb(main):001:0> irb
-# # list open sessions
-# irb.1(main):001:0> jobs
-# #0->irb on main (#<Thread:0x400fb7e4> : stop)
-# #1->irb#1 on main (#<Thread:0x40125d64> : running)
-#
-# # change the active session
-# irb.1(main):002:0> fg 0
-# # define class Foo in top-level session
-# irb(main):002:0> class Foo;end
-# # invoke a new session with the context of Foo
-# irb(main):003:0> irb Foo
-# # define Foo#foo
-# irb.2(Foo):001:0> def foo
-# irb.2(Foo):002:1> print 1
-# irb.2(Foo):003:1> end
-#
-# # change the active session
-# irb.2(Foo):004:0> fg 0
-# # list open sessions
-# irb(main):004:0> jobs
-# #0->irb on main (#<Thread:0x400fb7e4> : running)
-# #1->irb#1 on main (#<Thread:0x40125d64> : stop)
-# #2->irb#2 on Foo (#<Thread:0x4011d54c> : stop)
-# # check if Foo#foo is available
-# irb(main):005:0> Foo.instance_methods #=> [:foo, ...]
-#
-# # change the active sesssion
-# irb(main):006:0> fg 2
-# # define Foo#bar in the context of Foo
-# irb.2(Foo):005:0> def bar
-# irb.2(Foo):006:1> print "bar"
-# irb.2(Foo):007:1> end
-# irb.2(Foo):010:0> Foo.instance_methods #=> [:bar, :foo, ...]
-#
-# # change the active session
-# irb.2(Foo):011:0> fg 0
-# irb(main):007:0> f = Foo.new #=> #<Foo:0x4010af3c>
-# # invoke a new session with the context of f (instance of Foo)
-# irb(main):008:0> irb f
-# # list open sessions
-# irb.3(<Foo:0x4010af3c>):001:0> jobs
-# #0->irb on main (#<Thread:0x400fb7e4> : stop)
-# #1->irb#1 on main (#<Thread:0x40125d64> : stop)
-# #2->irb#2 on Foo (#<Thread:0x4011d54c> : stop)
-# #3->irb#3 on #<Foo:0x4010af3c> (#<Thread:0x4010a1e0> : running)
-# # evaluate f.foo
-# irb.3(<Foo:0x4010af3c>):002:0> foo #=> 1 => nil
-# # evaluate f.bar
-# irb.3(<Foo:0x4010af3c>):003:0> bar #=> bar => nil
-# # kill jobs 1, 2, and 3
-# irb.3(<Foo:0x4010af3c>):004:0> kill 1, 2, 3
-# # list open sesssions, should only include main session
-# irb(main):009:0> jobs
-# #0->irb on main (#<Thread:0x400fb7e4> : running)
-# # quit irb
-# irb(main):010:0> exit
-module IRB
-
- # An exception raised by IRB.irb_abort
- class Abort < Exception;end
-
- @CONF = {}
-
-
- # Displays current configuration.
- #
- # Modifing the configuration is achieved by sending a message to IRB.conf.
- #
- # See IRB@Configuration for more information.
- def IRB.conf
- @CONF
- end
-
- # Returns the current version of IRB, including release version and last
- # updated date.
- def IRB.version
- if v = @CONF[:VERSION] then return v end
-
- require "irb/version"
- rv = @RELEASE_VERSION.sub(/\.0/, "")
- @CONF[:VERSION] = format("irb %s(%s)", rv, @LAST_UPDATE_DATE)
- end
-
- # The current IRB::Context of the session, see IRB.conf
- #
- # irb
- # irb(main):001:0> IRB.CurrentContext.irb_name = "foo"
- # foo(main):002:0> IRB.conf[:MAIN_CONTEXT].irb_name #=> "foo"
- def IRB.CurrentContext
- IRB.conf[:MAIN_CONTEXT]
- end
-
- # Initializes IRB and creates a new Irb.irb object at the +TOPLEVEL_BINDING+
- def IRB.start(ap_path = nil)
- $0 = File::basename(ap_path, ".rb") if ap_path
-
- IRB.setup(ap_path)
-
- if @CONF[:SCRIPT]
- irb = Irb.new(nil, @CONF[:SCRIPT])
- else
- irb = Irb.new
- end
-
- @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
- @CONF[:MAIN_CONTEXT] = irb.context
-
- trap("SIGINT") do
- irb.signal_handle
- end
-
- begin
- catch(:IRB_EXIT) do
- irb.eval_input
- end
- ensure
- irb_at_exit
- end
- end
-
- # Calls each event hook of IRB.conf[:AT_EXIT] when the current session quits.
- def IRB.irb_at_exit
- @CONF[:AT_EXIT].each{|hook| hook.call}
- end
-
- # Quits irb
- def IRB.irb_exit(irb, ret)
- throw :IRB_EXIT, ret
- end
-
- # Aborts then interrupts irb.
- #
- # Will raise an Abort exception, or the given +exception+.
- def IRB.irb_abort(irb, exception = Abort)
- if defined? Thread
- irb.context.thread.raise exception, "abort then interrupt!"
- else
- raise exception, "abort then interrupt!"
- end
- end
-
- class Irb
- # Creates a new irb session
- def initialize(workspace = nil, input_method = nil, output_method = nil)
- @context = Context.new(self, workspace, input_method, output_method)
- @context.main.extend ExtendCommandBundle
- @signal_status = :IN_IRB
-
- @scanner = RubyLex.new
- @scanner.exception_on_syntax_error = false
- end
- # Returns the current context of this irb session
- attr_reader :context
- # The lexer used by this irb session
- attr_accessor :scanner
-
- # Evaluates input for this session.
- def eval_input
- @scanner.set_prompt do
- |ltype, indent, continue, line_no|
- if ltype
- f = @context.prompt_s
- elsif continue
- f = @context.prompt_c
- elsif indent > 0
- f = @context.prompt_n
- else
- f = @context.prompt_i
- end
- f = "" unless f
- if @context.prompting?
- @context.io.prompt = p = prompt(f, ltype, indent, line_no)
- else
- @context.io.prompt = p = ""
- end
- if @context.auto_indent_mode
- unless ltype
- ind = prompt(@context.prompt_i, ltype, indent, line_no)[/.*\z/].size +
- indent * 2 - p.size
- ind += 2 if continue
- @context.io.prompt = p + " " * ind if ind > 0
- end
- end
- end
-
- @scanner.set_input(@context.io) do
- signal_status(:IN_INPUT) do
- if l = @context.io.gets
- print l if @context.verbose?
- else
- if @context.ignore_eof? and @context.io.readable_after_eof?
- l = "\n"
- if @context.verbose?
- printf "Use \"exit\" to leave %s\n", @context.ap_name
- end
- else
- print "\n"
- end
- end
- l
- end
- end
-
- @scanner.each_top_level_statement do |line, line_no|
- signal_status(:IN_EVAL) do
- begin
- line.untaint
- @context.evaluate(line, line_no)
- output_value if @context.echo?
- exc = nil
- rescue Interrupt => exc
- rescue SystemExit, SignalException
- raise
- rescue Exception => exc
- end
- if exc
- print exc.class, ": ", exc, "\n"
- if exc.backtrace && exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ &&
- !(SyntaxError === exc)
- irb_bug = true
- else
- irb_bug = false
- end
-
- messages = []
- lasts = []
- levels = 0
- if exc.backtrace
- for m in exc.backtrace
- m = @context.workspace.filter_backtrace(m) unless irb_bug
- if m
- if messages.size < @context.back_trace_limit
- messages.push "\tfrom "+m
- else
- lasts.push "\tfrom "+m
- if lasts.size > @context.back_trace_limit
- lasts.shift
- levels += 1
- end
- end
- end
- end
- end
- print messages.join("\n"), "\n"
- unless lasts.empty?
- printf "... %d levels...\n", levels if levels > 0
- print lasts.join("\n"), "\n"
- end
- print "Maybe IRB bug!\n" if irb_bug
- end
- if $SAFE > 2
- abort "Error: irb does not work for $SAFE level higher than 2"
- end
- end
- end
- end
-
- # Evaluates the given block using the given +path+ as the Context#irb_path
- # and +name+ as the Context#irb_name.
- #
- # Used by the irb command +source+, see IRB@IRB+Sessions for more
- # information.
- def suspend_name(path = nil, name = nil)
- @context.irb_path, back_path = path, @context.irb_path if path
- @context.irb_name, back_name = name, @context.irb_name if name
- begin
- yield back_path, back_name
- ensure
- @context.irb_path = back_path if path
- @context.irb_name = back_name if name
- end
- end
-
- # Evaluates the given block using the given +workspace+ as the
- # Context#workspace.
- #
- # Used by the irb command +irb_load+, see IRB@IRB+Sessions for more
- # information.
- def suspend_workspace(workspace)
- @context.workspace, back_workspace = workspace, @context.workspace
- begin
- yield back_workspace
- ensure
- @context.workspace = back_workspace
- end
- end
-
- # Evaluates the given block using the given +input_method+ as the
- # Context#io.
- #
- # Used by the irb commands +source+ and +irb_load+, see IRB@IRB+Sessions
- # for more information.
- def suspend_input_method(input_method)
- back_io = @context.io
- @context.instance_eval{@io = input_method}
- begin
- yield back_io
- ensure
- @context.instance_eval{@io = back_io}
- end
- end
-
- # Evaluates the given block using the given +context+ as the Context.
- def suspend_context(context)
- @context, back_context = context, @context
- begin
- yield back_context
- ensure
- @context = back_context
- end
- end
-
- # Handler for the signal SIGINT, see Kernel#trap for more information.
- def signal_handle
- unless @context.ignore_sigint?
- print "\nabort!\n" if @context.verbose?
- exit
- end
-
- case @signal_status
- when :IN_INPUT
- print "^C\n"
- raise RubyLex::TerminateLineInput
- when :IN_EVAL
- IRB.irb_abort(self)
- when :IN_LOAD
- IRB.irb_abort(self, LoadAbort)
- when :IN_IRB
- # ignore
- else
- # ignore other cases as well
- end
- end
-
- # Evaluates the given block using the given +status+.
- def signal_status(status)
- return yield if @signal_status == :IN_LOAD
-
- signal_status_back = @signal_status
- @signal_status = status
- begin
- yield
- ensure
- @signal_status = signal_status_back
- end
- end
-
- def prompt(prompt, ltype, indent, line_no) # :nodoc:
- p = prompt.dup
- p.gsub!(/%([0-9]+)?([a-zA-Z])/) do
- case $2
- when "N"
- @context.irb_name
- when "m"
- @context.main.to_s
- when "M"
- @context.main.inspect
- when "l"
- ltype
- when "i"
- if $1
- format("%" + $1 + "d", indent)
- else
- indent.to_s
- end
- when "n"
- if $1
- format("%" + $1 + "d", line_no)
- else
- line_no.to_s
- end
- when "%"
- "%"
- end
- end
- p
- end
-
- def output_value # :nodoc:
- printf @context.return_format, @context.inspect_last_value
- end
-
- # Outputs the local variables to this current session, including
- # #signal_status and #context, using IRB::Locale.
- def inspect
- ary = []
- for iv in instance_variables
- case (iv = iv.to_s)
- when "@signal_status"
- ary.push format("%s=:%s", iv, @signal_status.id2name)
- when "@context"
- ary.push format("%s=%s", iv, eval(iv).__to_s__)
- else
- ary.push format("%s=%s", iv, eval(iv))
- end
- end
- format("#<%s: %s>", self.class, ary.join(", "))
- end
- end
-
- def @CONF.inspect
- IRB.version unless self[:VERSION]
-
- array = []
- for k, v in sort{|a1, a2| a1[0].id2name <=> a2[0].id2name}
- case k
- when :MAIN_CONTEXT, :__TMP__EHV__
- array.push format("CONF[:%s]=...myself...", k.id2name)
- when :PROMPT
- s = v.collect{
- |kk, vv|
- ss = vv.collect{|kkk, vvv| ":#{kkk.id2name}=>#{vvv.inspect}"}
- format(":%s=>{%s}", kk.id2name, ss.join(", "))
- }
- array.push format("CONF[:%s]={%s}", k.id2name, s.join(", "))
- else
- array.push format("CONF[:%s]=%s", k.id2name, v.inspect)
- end
- end
- array.join("\n")
- end
-end
diff --git a/ruby_2_2/lib/irb/cmd/chws.rb b/ruby_2_2/lib/irb/cmd/chws.rb
deleted file mode 100644
index 8c0260627e..0000000000
--- a/ruby_2_2/lib/irb/cmd/chws.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-#
-# change-ws.rb -
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-require "irb/cmd/nop.rb"
-require "irb/ext/change-ws.rb"
-
-# :stopdoc:
-module IRB
- module ExtendCommand
-
- class CurrentWorkingWorkspace<Nop
- def execute(*obj)
- irb_context.main
- end
- end
-
- class ChangeWorkspace<Nop
- def execute(*obj)
- irb_context.change_workspace(*obj)
- irb_context.main
- end
- end
- end
-end
-# :startdoc:
diff --git a/ruby_2_2/lib/irb/cmd/fork.rb b/ruby_2_2/lib/irb/cmd/fork.rb
deleted file mode 100644
index 1e02edac63..0000000000
--- a/ruby_2_2/lib/irb/cmd/fork.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-#
-# fork.rb -
-# $Release Version: 0.9.6 $
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-
-# :stopdoc:
-module IRB
- module ExtendCommand
- class Fork<Nop
- def execute
- pid = send ExtendCommand.irb_original_method_name("fork")
- unless pid
- class << self
- alias_method :exit, ExtendCommand.irb_original_method_name('exit')
- end
- if iterator?
- begin
- yield
- ensure
- exit
- end
- end
- end
- pid
- end
- end
- end
-end
-# :startdoc:
-
-
diff --git a/ruby_2_2/lib/irb/cmd/help.rb b/ruby_2_2/lib/irb/cmd/help.rb
deleted file mode 100644
index 76e299fc20..0000000000
--- a/ruby_2_2/lib/irb/cmd/help.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-#
-# help.rb - helper using ri
-# $Release Version: 0.9.6$
-# $Revision$
-#
-# --
-#
-#
-#
-
-require 'rdoc/ri/driver'
-
-require "irb/cmd/nop.rb"
-
-# :stopdoc:
-module IRB
- module ExtendCommand
- class Help<Nop
- begin
- Ri = RDoc::RI::Driver.new
- rescue SystemExit
- else
- def execute(*names)
- if names.empty?
- Ri.interactive
- return
- end
- names.each do |name|
- begin
- Ri.display_name(name.to_s)
- rescue RDoc::RI::Error
- puts $!.message
- end
- end
- nil
- end
- end
- end
- end
-end
-# :startdoc:
diff --git a/ruby_2_2/lib/irb/cmd/load.rb b/ruby_2_2/lib/irb/cmd/load.rb
deleted file mode 100644
index acda9d0c8c..0000000000
--- a/ruby_2_2/lib/irb/cmd/load.rb
+++ /dev/null
@@ -1,66 +0,0 @@
-#
-# load.rb -
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-require "irb/cmd/nop.rb"
-require "irb/ext/loader"
-
-# :stopdoc:
-module IRB
- module ExtendCommand
- class Load<Nop
- include IrbLoader
-
- def execute(file_name, priv = nil)
- return irb_load(file_name, priv)
- end
- end
-
- class Require<Nop
- include IrbLoader
-
- def execute(file_name)
-
- rex = Regexp.new("#{Regexp.quote(file_name)}(\.o|\.rb)?")
- return false if $".find{|f| f =~ rex}
-
- case file_name
- when /\.rb$/
- begin
- if irb_load(file_name)
- $".push file_name
- return true
- end
- rescue LoadError
- end
- when /\.(so|o|sl)$/
- return ruby_require(file_name)
- end
-
- begin
- irb_load(f = file_name + ".rb")
- $".push f
- return true
- rescue LoadError
- return ruby_require(file_name)
- end
- end
- end
-
- class Source<Nop
- include IrbLoader
- def execute(file_name)
- source_file(file_name)
- end
- end
- end
-
-end
-# :startdoc:
diff --git a/ruby_2_2/lib/irb/cmd/nop.rb b/ruby_2_2/lib/irb/cmd/nop.rb
deleted file mode 100644
index 60379f016a..0000000000
--- a/ruby_2_2/lib/irb/cmd/nop.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-#
-# nop.rb -
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-# :stopdoc:
-module IRB
- module ExtendCommand
- class Nop
-
-
- def self.execute(conf, *opts)
- command = new(conf)
- command.execute(*opts)
- end
-
- def initialize(conf)
- @irb_context = conf
- end
-
- attr_reader :irb_context
-
- def irb
- @irb_context.irb
- end
-
- def execute(*opts)
- #nop
- end
- end
- end
-end
-# :startdoc:
diff --git a/ruby_2_2/lib/irb/cmd/pushws.rb b/ruby_2_2/lib/irb/cmd/pushws.rb
deleted file mode 100644
index 0726a4377e..0000000000
--- a/ruby_2_2/lib/irb/cmd/pushws.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-#
-# change-ws.rb -
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-require "irb/cmd/nop.rb"
-require "irb/ext/workspaces.rb"
-
-# :stopdoc:
-module IRB
- module ExtendCommand
- class Workspaces<Nop
- def execute(*obj)
- irb_context.workspaces.collect{|ws| ws.main}
- end
- end
-
- class PushWorkspace<Workspaces
- def execute(*obj)
- irb_context.push_workspace(*obj)
- super
- end
- end
-
- class PopWorkspace<Workspaces
- def execute(*obj)
- irb_context.pop_workspace(*obj)
- super
- end
- end
- end
-end
-# :startdoc:
-
diff --git a/ruby_2_2/lib/irb/cmd/subirb.rb b/ruby_2_2/lib/irb/cmd/subirb.rb
deleted file mode 100644
index ccf4fc4bcd..0000000000
--- a/ruby_2_2/lib/irb/cmd/subirb.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-# multi.rb -
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-require "irb/cmd/nop.rb"
-require "irb/ext/multi-irb"
-
-# :stopdoc:
-module IRB
- module ExtendCommand
- class IrbCommand<Nop
- def execute(*obj)
- IRB.irb(nil, *obj)
- end
- end
-
- class Jobs<Nop
- def execute
- IRB.JobManager
- end
- end
-
- class Foreground<Nop
- def execute(key)
- IRB.JobManager.switch(key)
- end
- end
-
- class Kill<Nop
- def execute(*keys)
- IRB.JobManager.kill(*keys)
- end
- end
- end
-end
-# :startdoc:
diff --git a/ruby_2_2/lib/irb/completion.rb b/ruby_2_2/lib/irb/completion.rb
deleted file mode 100644
index 2d47f33d66..0000000000
--- a/ruby_2_2/lib/irb/completion.rb
+++ /dev/null
@@ -1,227 +0,0 @@
-#
-# irb/completor.rb -
-# $Release Version: 0.9$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ishitsuka.com)
-# From Original Idea of shugo@ruby-lang.org
-#
-
-require "readline"
-
-module IRB
- module InputCompletor # :nodoc:
-
-
- # Set of reserved words used by Ruby, you should not use these for
- # constants or variables
- ReservedWords = %w[
- BEGIN END
- alias and
- begin break
- case class
- def defined do
- else elsif end ensure
- false for
- if in
- module
- next nil not
- or
- redo rescue retry return
- self super
- then true
- undef unless until
- when while
- yield
- ]
-
- CompletionProc = proc { |input|
- bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
-
- case input
- when /^((["'`]).*\2)\.([^.]*)$/
- # String
- receiver = $1
- message = Regexp.quote($3)
-
- candidates = String.instance_methods.collect{|m| m.to_s}
- select_message(receiver, message, candidates)
-
- when /^(\/[^\/]*\/)\.([^.]*)$/
- # Regexp
- receiver = $1
- message = Regexp.quote($2)
-
- candidates = Regexp.instance_methods.collect{|m| m.to_s}
- select_message(receiver, message, candidates)
-
- when /^([^\]]*\])\.([^.]*)$/
- # Array
- receiver = $1
- message = Regexp.quote($2)
-
- candidates = Array.instance_methods.collect{|m| m.to_s}
- select_message(receiver, message, candidates)
-
- when /^([^\}]*\})\.([^.]*)$/
- # Proc or Hash
- receiver = $1
- message = Regexp.quote($2)
-
- candidates = Proc.instance_methods.collect{|m| m.to_s}
- candidates |= Hash.instance_methods.collect{|m| m.to_s}
- select_message(receiver, message, candidates)
-
- when /^(:[^:.]*)$/
- # Symbol
- if Symbol.respond_to?(:all_symbols)
- sym = $1
- candidates = Symbol.all_symbols.collect{|s| ":" + s.id2name}
- candidates.grep(/^#{Regexp.quote(sym)}/)
- else
- []
- end
-
- when /^::([A-Z][^:\.\(]*)$/
- # Absolute Constant or class methods
- receiver = $1
- candidates = Object.constants.collect{|m| m.to_s}
- candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
-
- when /^([A-Z].*)::([^:.]*)$/
- # Constant or class methods
- receiver = $1
- message = Regexp.quote($2)
- begin
- candidates = eval("#{receiver}.constants.collect{|m| m.to_s}", bind)
- candidates |= eval("#{receiver}.methods.collect{|m| m.to_s}", bind)
- rescue Exception
- candidates = []
- end
- select_message(receiver, message, candidates, "::")
-
- when /^(:[^:.]+)(\.|::)([^.]*)$/
- # Symbol
- receiver = $1
- sep = $2
- message = Regexp.quote($3)
-
- candidates = Symbol.instance_methods.collect{|m| m.to_s}
- select_message(receiver, message, candidates, sep)
-
- when /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)(\.|::)([^.]*)$/
- # Numeric
- receiver = $1
- sep = $5
- message = Regexp.quote($6)
-
- begin
- candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
- rescue Exception
- candidates = []
- end
- select_message(receiver, message, candidates, sep)
-
- when /^(-?0x[0-9a-fA-F_]+)(\.|::)([^.]*)$/
- # Numeric(0xFFFF)
- receiver = $1
- sep = $2
- message = Regexp.quote($3)
-
- begin
- candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
- rescue Exception
- candidates = []
- end
- select_message(receiver, message, candidates, sep)
-
- when /^(\$[^.]*)$/
- # global var
- regmessage = Regexp.new(Regexp.quote($1))
- candidates = global_variables.collect{|m| m.to_s}.grep(regmessage)
-
- when /^([^."].*)(\.|::)([^.]*)$/
- # variable.func or func.func
- receiver = $1
- sep = $2
- message = Regexp.quote($3)
-
- gv = eval("global_variables", bind).collect{|m| m.to_s}
- lv = eval("local_variables", bind).collect{|m| m.to_s}
- iv = eval("instance_variables", bind).collect{|m| m.to_s}
- cv = eval("self.class.constants", bind).collect{|m| m.to_s}
-
- if (gv | lv | iv | cv).include?(receiver) or /^[A-Z]/ =~ receiver && /\./ !~ receiver
- # foo.func and foo is var. OR
- # foo::func and foo is var. OR
- # foo::Const and foo is var. OR
- # Foo::Bar.func
- begin
- candidates = []
- rec = eval(receiver, bind)
- if sep == "::" and rec.kind_of?(Module)
- candidates = rec.constants.collect{|m| m.to_s}
- end
- candidates |= rec.methods.collect{|m| m.to_s}
- rescue Exception
- candidates = []
- end
- else
- # func1.func2
- candidates = []
- ObjectSpace.each_object(Module){|m|
- begin
- name = m.name
- rescue Exception
- name = ""
- end
- begin
- next if name != "IRB::Context" and
- /^(IRB|SLex|RubyLex|RubyToken)/ =~ name
- rescue Exception
- next
- end
- candidates.concat m.instance_methods(false).collect{|x| x.to_s}
- }
- candidates.sort!
- candidates.uniq!
- end
- select_message(receiver, message, candidates, sep)
-
- when /^\.([^.]*)$/
- # unknown(maybe String)
-
- receiver = ""
- message = Regexp.quote($1)
-
- candidates = String.instance_methods(true).collect{|m| m.to_s}
- select_message(receiver, message, candidates)
-
- else
- candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s}
-
- (candidates|ReservedWords).grep(/^#{Regexp.quote(input)}/)
- end
- }
-
- # Set of available operators in Ruby
- Operators = %w[% & * ** + - / < << <= <=> == === =~ > >= >> [] []= ^ ! != !~]
-
- def self.select_message(receiver, message, candidates, sep = ".")
- candidates.grep(/^#{message}/).collect do |e|
- case e
- when /^[a-zA-Z_]/
- receiver + sep + e
- when /^[0-9]/
- when *Operators
- #receiver + " " + e
- end
- end
- end
- end
-end
-
-if Readline.respond_to?("basic_word_break_characters=")
- Readline.basic_word_break_characters= " \t\n`><=;|&{("
-end
-Readline.completion_append_character = nil
-Readline.completion_proc = IRB::InputCompletor::CompletionProc
diff --git a/ruby_2_2/lib/irb/context.rb b/ruby_2_2/lib/irb/context.rb
deleted file mode 100644
index 9cf9600f02..0000000000
--- a/ruby_2_2/lib/irb/context.rb
+++ /dev/null
@@ -1,419 +0,0 @@
-#
-# irb/context.rb - irb context
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-require "irb/workspace"
-require "irb/inspector"
-
-module IRB
- # A class that wraps the current state of the irb session, including the
- # configuration of IRB.conf.
- class Context
- # Creates a new IRB context.
- #
- # The optional +input_method+ argument:
- #
- # +nil+:: uses stdin or Readline
- # +String+:: uses a File
- # +other+:: uses this as InputMethod
- def initialize(irb, workspace = nil, input_method = nil, output_method = nil)
- @irb = irb
- if workspace
- @workspace = workspace
- else
- @workspace = WorkSpace.new
- end
- @thread = Thread.current if defined? Thread
-
- # copy of default configuration
- @ap_name = IRB.conf[:AP_NAME]
- @rc = IRB.conf[:RC]
- @load_modules = IRB.conf[:LOAD_MODULES]
-
- @use_readline = IRB.conf[:USE_READLINE]
- @verbose = IRB.conf[:VERBOSE]
- @io = nil
-
- self.inspect_mode = IRB.conf[:INSPECT_MODE]
- self.math_mode = IRB.conf[:MATH_MODE] if IRB.conf[:MATH_MODE]
- self.use_tracer = IRB.conf[:USE_TRACER] if IRB.conf[:USE_TRACER]
- self.use_loader = IRB.conf[:USE_LOADER] if IRB.conf[:USE_LOADER]
- self.eval_history = IRB.conf[:EVAL_HISTORY] if IRB.conf[:EVAL_HISTORY]
-
- @ignore_sigint = IRB.conf[:IGNORE_SIGINT]
- @ignore_eof = IRB.conf[:IGNORE_EOF]
-
- @back_trace_limit = IRB.conf[:BACK_TRACE_LIMIT]
-
- self.prompt_mode = IRB.conf[:PROMPT_MODE]
-
- if IRB.conf[:SINGLE_IRB] or !defined?(IRB::JobManager)
- @irb_name = IRB.conf[:IRB_NAME]
- else
- @irb_name = IRB.conf[:IRB_NAME]+"#"+IRB.JobManager.n_jobs.to_s
- end
- @irb_path = "(" + @irb_name + ")"
-
- case input_method
- when nil
- case use_readline?
- when nil
- if (defined?(ReadlineInputMethod) && STDIN.tty? &&
- IRB.conf[:PROMPT_MODE] != :INF_RUBY)
- @io = ReadlineInputMethod.new
- else
- @io = StdioInputMethod.new
- end
- when false
- @io = StdioInputMethod.new
- when true
- if defined?(ReadlineInputMethod)
- @io = ReadlineInputMethod.new
- else
- @io = StdioInputMethod.new
- end
- end
-
- when String
- @io = FileInputMethod.new(input_method)
- @irb_name = File.basename(input_method)
- @irb_path = input_method
- else
- @io = input_method
- end
- self.save_history = IRB.conf[:SAVE_HISTORY] if IRB.conf[:SAVE_HISTORY]
-
- if output_method
- @output_method = output_method
- else
- @output_method = StdioOutputMethod.new
- end
-
- @echo = IRB.conf[:ECHO]
- if @echo.nil?
- @echo = true
- end
- self.debug_level = IRB.conf[:DEBUG_LEVEL]
- end
-
- # The top-level workspace, see WorkSpace#main
- def main
- @workspace.main
- end
-
- # The toplevel workspace, see #home_workspace
- attr_reader :workspace_home
- # WorkSpace in the current context
- attr_accessor :workspace
- # The current thread in this context
- attr_reader :thread
- # The current input method
- #
- # Can be either StdioInputMethod, ReadlineInputMethod, FileInputMethod or
- # other specified when the context is created. See ::new for more
- # information on +input_method+.
- attr_accessor :io
-
- # Current irb session
- attr_accessor :irb
- # A copy of the default <code>IRB.conf[:AP_NAME]</code>
- attr_accessor :ap_name
- # A copy of the default <code>IRB.conf[:RC]</code>
- attr_accessor :rc
- # A copy of the default <code>IRB.conf[:LOAD_MODULES]</code>
- attr_accessor :load_modules
- # Can be either name from <code>IRB.conf[:IRB_NAME]</code>, or the number of
- # the current job set by JobManager, such as <code>irb#2</code>
- attr_accessor :irb_name
- # Can be either the #irb_name surrounded by parenthesis, or the
- # +input_method+ passed to Context.new
- attr_accessor :irb_path
-
- # Whether +Readline+ is enabled or not.
- #
- # A copy of the default <code>IRB.conf[:USE_READLINE]</code>
- #
- # See #use_readline= for more information.
- attr_reader :use_readline
- # A copy of the default <code>IRB.conf[:INSPECT_MODE]</code>
- attr_reader :inspect_mode
-
- # A copy of the default <code>IRB.conf[:PROMPT_MODE]</code>
- attr_reader :prompt_mode
- # Standard IRB prompt
- #
- # See IRB@Customizing+the+IRB+Prompt for more information.
- attr_accessor :prompt_i
- # IRB prompt for continuated strings
- #
- # See IRB@Customizing+the+IRB+Prompt for more information.
- attr_accessor :prompt_s
- # IRB prompt for continuated statement (e.g. immediately after an +if+)
- #
- # See IRB@Customizing+the+IRB+Prompt for more information.
- attr_accessor :prompt_c
- # See IRB@Customizing+the+IRB+Prompt for more information.
- attr_accessor :prompt_n
- # Can be either the default <code>IRB.conf[:AUTO_INDENT]</code>, or the
- # mode set by #prompt_mode=
- #
- # To enable auto-indentation in irb:
- #
- # IRB.conf[:AUTO_INDENT] = true
- #
- # or
- #
- # irb_context.auto_indent_mode = true
- #
- # or
- #
- # IRB.CurrentContext.auto_indent_mode = true
- #
- # See IRB@Configuration for more information.
- attr_accessor :auto_indent_mode
- # The format of the return statement, set by #prompt_mode= using the
- # +:RETURN+ of the +mode+ passed to set the current #prompt_mode.
- attr_accessor :return_format
-
- # Whether <code>^C</code> (+control-c+) will be ignored or not.
- #
- # If set to +false+, <code>^C</code> will quit irb.
- #
- # If set to +true+,
- #
- # * during input: cancel input then return to top level.
- # * during execute: abandon current execution.
- attr_accessor :ignore_sigint
- # Whether <code>^D</code> (+control-d+) will be ignored or not.
- #
- # If set to +false+, <code>^D</code> will quit irb.
- attr_accessor :ignore_eof
- # Whether to echo the return value to output or not.
- #
- # Uses IRB.conf[:ECHO] if available, or defaults to +true+.
- #
- # puts "hello"
- # # hello
- # #=> nil
- # IRB.CurrentContext.echo = false
- # puts "omg"
- # # omg
- attr_accessor :echo
- # Whether verbose messages are displayed or not.
- #
- # A copy of the default <code>IRB.conf[:VERBOSE]</code>
- attr_accessor :verbose
- # The debug level of irb
- #
- # See #debug_level= for more information.
- attr_reader :debug_level
-
- # The limit of backtrace lines displayed as top +n+ and tail +n+.
- #
- # The default value is 16.
- #
- # Can also be set using the +--back-trace-limit+ command line option.
- #
- # See IRB@Command+line+options for more command line options.
- attr_accessor :back_trace_limit
-
- # Alias for #use_readline
- alias use_readline? use_readline
- # Alias for #rc
- alias rc? rc
- alias ignore_sigint? ignore_sigint
- alias ignore_eof? ignore_eof
- alias echo? echo
-
- # Returns whether messages are displayed or not.
- def verbose?
- if @verbose.nil?
- if defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)
- false
- elsif !STDIN.tty? or @io.kind_of?(FileInputMethod)
- true
- else
- false
- end
- else
- @verbose
- end
- end
-
- # Whether #verbose? is +true+, and +input_method+ is either
- # StdioInputMethod or ReadlineInputMethod, see #io for more information.
- def prompting?
- verbose? || (STDIN.tty? && @io.kind_of?(StdioInputMethod) ||
- (defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)))
- end
-
- # The return value of the last statement evaluated.
- attr_reader :last_value
-
- # Sets the return value from the last statement evaluated in this context
- # to #last_value.
- def set_last_value(value)
- @last_value = value
- @workspace.evaluate self, "_ = IRB.CurrentContext.last_value"
- end
-
- # Sets the +mode+ of the prompt in this context.
- #
- # See IRB@Customizing+the+IRB+Prompt for more information.
- def prompt_mode=(mode)
- @prompt_mode = mode
- pconf = IRB.conf[:PROMPT][mode]
- @prompt_i = pconf[:PROMPT_I]
- @prompt_s = pconf[:PROMPT_S]
- @prompt_c = pconf[:PROMPT_C]
- @prompt_n = pconf[:PROMPT_N]
- @return_format = pconf[:RETURN]
- if ai = pconf.include?(:AUTO_INDENT)
- @auto_indent_mode = ai
- else
- @auto_indent_mode = IRB.conf[:AUTO_INDENT]
- end
- end
-
- # Whether #inspect_mode is set or not, see #inspect_mode= for more detail.
- def inspect?
- @inspect_mode.nil? or @inspect_mode
- end
-
- # Whether #io uses a File for the +input_method+ passed when creating the
- # current context, see ::new
- def file_input?
- @io.class == FileInputMethod
- end
-
- # Specifies the inspect mode with +opt+:
- #
- # +true+:: display +inspect+
- # +false+:: display +to_s+
- # +nil+:: inspect mode in non-math mode,
- # non-inspect mode in math mode
- #
- # See IRB::Inspector for more information.
- #
- # Can also be set using the +--inspect+ and +--noinspect+ command line
- # options.
- #
- # See IRB@Command+line+options for more command line options.
- def inspect_mode=(opt)
-
- if i = Inspector::INSPECTORS[opt]
- @inspect_mode = opt
- @inspect_method = i
- i.init
- else
- case opt
- when nil
- if Inspector.keys_with_inspector(Inspector::INSPECTORS[true]).include?(@inspect_mode)
- self.inspect_mode = false
- elsif Inspector.keys_with_inspector(Inspector::INSPECTORS[false]).include?(@inspect_mode)
- self.inspect_mode = true
- else
- puts "Can't switch inspect mode."
- return
- end
- when /^\s*\{.*\}\s*$/
- begin
- inspector = eval "proc#{opt}"
- rescue Exception
- puts "Can't switch inspect mode(#{opt})."
- return
- end
- self.inspect_mode = inspector
- when Proc
- self.inspect_mode = IRB::Inspector(opt)
- when Inspector
- prefix = "usr%d"
- i = 1
- while Inspector::INSPECTORS[format(prefix, i)]; i += 1; end
- @inspect_mode = format(prefix, i)
- @inspect_method = opt
- Inspector.def_inspector(format(prefix, i), @inspect_method)
- else
- puts "Can't switch inspect mode(#{opt})."
- return
- end
- end
- print "Switch to#{unless @inspect_mode; ' non';end} inspect mode.\n" if verbose?
- @inspect_mode
- end
-
- # Obsolete method.
- #
- # Can be set using the +--noreadline+ and +--readline+ command line
- # options.
- #
- # See IRB@Command+line+options for more command line options.
- def use_readline=(opt)
- print "This method is obsolete."
- print "Do nothing."
- end
-
- # Sets the debug level of irb
- #
- # Can also be set using the +--irb_debug+ command line option.
- #
- # See IRB@Command+line+options for more command line options.
- def debug_level=(value)
- @debug_level = value
- RubyLex.debug_level = value
- end
-
- # Whether or not debug mode is enabled, see #debug_level=.
- def debug?
- @debug_level > 0
- end
-
- def evaluate(line, line_no) # :nodoc:
- @line_no = line_no
- set_last_value(@workspace.evaluate(self, line, irb_path, line_no))
- end
-
- def inspect_last_value # :nodoc:
- @inspect_method.inspect_value(@last_value)
- end
-
- alias __exit__ exit
- # Exits the current session, see IRB.irb_exit
- def exit(ret = 0)
- IRB.irb_exit(@irb, ret)
- end
-
- NOPRINTING_IVARS = ["@last_value"] # :nodoc:
- NO_INSPECTING_IVARS = ["@irb", "@io"] # :nodoc:
- IDNAME_IVARS = ["@prompt_mode"] # :nodoc:
-
- alias __inspect__ inspect
- def inspect # :nodoc:
- array = []
- for ivar in instance_variables.sort{|e1, e2| e1 <=> e2}
- ivar = ivar.to_s
- name = ivar.sub(/^@(.*)$/, '\1')
- val = instance_eval(ivar)
- case ivar
- when *NOPRINTING_IVARS
- array.push format("conf.%s=%s", name, "...")
- when *NO_INSPECTING_IVARS
- array.push format("conf.%s=%s", name, val.to_s)
- when *IDNAME_IVARS
- array.push format("conf.%s=:%s", name, val.id2name)
- else
- array.push format("conf.%s=%s", name, val.inspect)
- end
- end
- array.join("\n")
- end
- alias __to_s__ to_s
- alias to_s inspect
- end
-end
diff --git a/ruby_2_2/lib/irb/ext/change-ws.rb b/ruby_2_2/lib/irb/ext/change-ws.rb
deleted file mode 100644
index 0ae9097285..0000000000
--- a/ruby_2_2/lib/irb/ext/change-ws.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-#
-# irb/ext/cb.rb -
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-module IRB # :nodoc:
- class Context
-
- # Inherited from +TOPLEVEL_BINDING+.
- def home_workspace
- if defined? @home_workspace
- @home_workspace
- else
- @home_workspace = @workspace
- end
- end
-
- # Changes the current workspace to given object or binding.
- #
- # If the optional argument is omitted, the workspace will be
- # #home_workspace which is inherited from +TOPLEVEL_BINDING+ or the main
- # object, <code>IRB.conf[:MAIN_CONTEXT]</code> when irb was initialized.
- #
- # See IRB::WorkSpace.new for more information.
- def change_workspace(*_main)
- if _main.empty?
- @workspace = home_workspace
- return main
- end
-
- @workspace = WorkSpace.new(_main[0])
-
- if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
- main.extend ExtendCommandBundle
- end
- end
- end
-end
-
diff --git a/ruby_2_2/lib/irb/ext/history.rb b/ruby_2_2/lib/irb/ext/history.rb
deleted file mode 100644
index d8378753f2..0000000000
--- a/ruby_2_2/lib/irb/ext/history.rb
+++ /dev/null
@@ -1,118 +0,0 @@
-#
-# history.rb -
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-module IRB # :nodoc:
-
- class Context
-
- NOPRINTING_IVARS.push "@eval_history_values"
-
- # See #set_last_value
- alias _set_last_value set_last_value
-
- def set_last_value(value)
- _set_last_value(value)
-
- if @eval_history
- @eval_history_values.push @line_no, @last_value
- @workspace.evaluate self, "__ = IRB.CurrentContext.instance_eval{@eval_history_values}"
- end
-
- @last_value
- end
-
- # The command result history limit.
- attr_reader :eval_history
- # Sets command result history limit.
- #
- # +no+ is an Integer or +nil+.
- #
- # Returns +no+ of history items if greater than 0.
- #
- # If +no+ is 0, the number of history items is unlimited.
- #
- # If +no+ is +nil+, execution result history isn't used (default).
- def eval_history=(no)
- if no
- if defined?(@eval_history) && @eval_history
- @eval_history_values.size(no)
- else
- @eval_history_values = History.new(no)
- IRB.conf[:__TMP__EHV__] = @eval_history_values
- @workspace.evaluate(self, "__ = IRB.conf[:__TMP__EHV__]")
- IRB.conf.delete(:__TMP_EHV__)
- end
- else
- @eval_history_values = nil
- end
- @eval_history = no
- end
- end
-
- class History # :nodoc:
-
- def initialize(size = 16)
- @size = size
- @contents = []
- end
-
- def size(size)
- if size != 0 && size < @size
- @contents = @contents[@size - size .. @size]
- end
- @size = size
- end
-
- def [](idx)
- begin
- if idx >= 0
- @contents.find{|no, val| no == idx}[1]
- else
- @contents[idx][1]
- end
- rescue NameError
- nil
- end
- end
-
- def push(no, val)
- @contents.push [no, val]
- @contents.shift if @size != 0 && @contents.size > @size
- end
-
- alias real_inspect inspect
-
- def inspect
- if @contents.empty?
- return real_inspect
- end
-
- unless (last = @contents.pop)[1].equal?(self)
- @contents.push last
- last = nil
- end
- str = @contents.collect{|no, val|
- if val.equal?(self)
- "#{no} ...self-history..."
- else
- "#{no} #{val.inspect}"
- end
- }.join("\n")
- if str == ""
- str = "Empty."
- end
- @contents.push last if last
- str
- end
- end
-end
-
-
diff --git a/ruby_2_2/lib/irb/ext/loader.rb b/ruby_2_2/lib/irb/ext/loader.rb
deleted file mode 100644
index 821538cd44..0000000000
--- a/ruby_2_2/lib/irb/ext/loader.rb
+++ /dev/null
@@ -1,128 +0,0 @@
-#
-# loader.rb -
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-
-module IRB # :nodoc:
- # Raised in the event of an exception in a file loaded from an Irb session
- class LoadAbort < Exception;end
-
- # Provides a few commands for loading files within an irb session.
- #
- # See ExtendCommandBundle for more information.
- module IrbLoader
-
- alias ruby_load load
- alias ruby_require require
-
- # Loads the given file similarly to Kernel#load
- def irb_load(fn, priv = nil)
- path = search_file_from_ruby_path(fn)
- raise LoadError, "No such file to load -- #{fn}" unless path
-
- load_file(path, priv)
- end
-
- def search_file_from_ruby_path(fn) # :nodoc:
- if /^#{Regexp.quote(File::Separator)}/ =~ fn
- return fn if File.exist?(fn)
- return nil
- end
-
- for path in $:
- if File.exist?(f = File.join(path, fn))
- return f
- end
- end
- return nil
- end
-
- # Loads a given file in the current session and displays the source lines
- #
- # See Irb#suspend_input_method for more information.
- def source_file(path)
- irb.suspend_name(path, File.basename(path)) do
- irb.suspend_input_method(FileInputMethod.new(path)) do
- |back_io|
- irb.signal_status(:IN_LOAD) do
- if back_io.kind_of?(FileInputMethod)
- irb.eval_input
- else
- begin
- irb.eval_input
- rescue LoadAbort
- print "load abort!!\n"
- end
- end
- end
- end
- end
- end
-
- # Loads the given file in the current session's context and evaluates it.
- #
- # See Irb#suspend_input_method for more information.
- def load_file(path, priv = nil)
- irb.suspend_name(path, File.basename(path)) do
-
- if priv
- ws = WorkSpace.new(Module.new)
- else
- ws = WorkSpace.new
- end
- irb.suspend_workspace(ws) do
- irb.suspend_input_method(FileInputMethod.new(path)) do
- |back_io|
- irb.signal_status(:IN_LOAD) do
- if back_io.kind_of?(FileInputMethod)
- irb.eval_input
- else
- begin
- irb.eval_input
- rescue LoadAbort
- print "load abort!!\n"
- end
- end
- end
- end
- end
- end
- end
-
- def old # :nodoc:
- back_io = @io
- back_path = @irb_path
- back_name = @irb_name
- back_scanner = @irb.scanner
- begin
- @io = FileInputMethod.new(path)
- @irb_name = File.basename(path)
- @irb_path = path
- @irb.signal_status(:IN_LOAD) do
- if back_io.kind_of?(FileInputMethod)
- @irb.eval_input
- else
- begin
- @irb.eval_input
- rescue LoadAbort
- print "load abort!!\n"
- end
- end
- end
- ensure
- @io = back_io
- @irb_name = back_name
- @irb_path = back_path
- @irb.scanner = back_scanner
- end
- end
- end
-end
-
diff --git a/ruby_2_2/lib/irb/ext/math-mode.rb b/ruby_2_2/lib/irb/ext/math-mode.rb
deleted file mode 100644
index 01bd24a157..0000000000
--- a/ruby_2_2/lib/irb/ext/math-mode.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-#
-# math-mode.rb -
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-require "mathn"
-
-module IRB
- class Context
- # Returns whether bc mode is enabled.
- #
- # See #math_mode=
- attr_reader :math_mode
- # Alias for #math_mode
- alias math? math_mode
-
- # Sets bc mode, which loads +lib/mathn.rb+ so fractions or matrix are
- # available.
- #
- # Also available as the +-m+ command line option.
- #
- # See IRB@Command+line+options and the unix manpage <code>bc(1)</code> for
- # more information.
- def math_mode=(opt)
- if @math_mode == true && !opt
- IRB.fail CantReturnToNormalMode
- return
- end
-
- @math_mode = opt
- if math_mode
- main.extend Math
- print "start math mode\n" if verbose?
- end
- end
-
- def inspect?
- @inspect_mode.nil? && !@math_mode or @inspect_mode
- end
- end
-end
-
diff --git a/ruby_2_2/lib/irb/ext/multi-irb.rb b/ruby_2_2/lib/irb/ext/multi-irb.rb
deleted file mode 100644
index 52f6fda733..0000000000
--- a/ruby_2_2/lib/irb/ext/multi-irb.rb
+++ /dev/null
@@ -1,265 +0,0 @@
-#
-# irb/multi-irb.rb - multiple irb module
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-IRB.fail CantShiftToMultiIrbMode unless defined?(Thread)
-require "thread"
-
-module IRB
- class JobManager
-
- # Creates a new JobManager object
- def initialize
- @jobs = []
- @current_job = nil
- end
-
- # The active irb session
- attr_accessor :current_job
-
- # The total number of irb sessions, used to set +irb_name+ of the current
- # Context.
- def n_jobs
- @jobs.size
- end
-
- # Returns the thread for the given +key+ object, see #search for more
- # information.
- def thread(key)
- th, = search(key)
- th
- end
-
- # Returns the irb session for the given +key+ object, see #search for more
- # information.
- def irb(key)
- _, irb = search(key)
- irb
- end
-
- # Returns the top level thread.
- def main_thread
- @jobs[0][0]
- end
-
- # Returns the top level irb session.
- def main_irb
- @jobs[0][1]
- end
-
- # Add the given +irb+ session to the jobs Array.
- def insert(irb)
- @jobs.push [Thread.current, irb]
- end
-
- # Changes the current active irb session to the given +key+ in the jobs
- # Array.
- #
- # Raises an IrbAlreadyDead exception if the given +key+ is no longer alive.
- #
- # If the given irb session is already active, an IrbSwitchedToCurrentThread
- # exception is raised.
- def switch(key)
- th, irb = search(key)
- IRB.fail IrbAlreadyDead unless th.alive?
- IRB.fail IrbSwitchedToCurrentThread if th == Thread.current
- @current_job = irb
- th.run
- Thread.stop
- @current_job = irb(Thread.current)
- end
-
- # Terminates the irb sessions specified by the given +keys+.
- #
- # Raises an IrbAlreadyDead exception if one of the given +keys+ is already
- # terminated.
- #
- # See Thread#exit for more information.
- def kill(*keys)
- for key in keys
- th, _ = search(key)
- IRB.fail IrbAlreadyDead unless th.alive?
- th.exit
- end
- end
-
- # Returns the associated job for the given +key+.
- #
- # If given an Integer, it will return the +key+ index for the jobs Array.
- #
- # When an instance of Irb is given, it will return the irb session
- # associated with +key+.
- #
- # If given an instance of Thread, it will return the associated thread
- # +key+ using Object#=== on the jobs Array.
- #
- # Otherwise returns the irb session with the same top-level binding as the
- # given +key+.
- #
- # Raises a NoSuchJob exception if no job can be found with the given +key+.
- def search(key)
- job = case key
- when Integer
- @jobs[key]
- when Irb
- @jobs.find{|k, v| v.equal?(key)}
- when Thread
- @jobs.assoc(key)
- else
- @jobs.find{|k, v| v.context.main.equal?(key)}
- end
- IRB.fail NoSuchJob, key if job.nil?
- job
- end
-
- # Deletes the job at the given +key+.
- def delete(key)
- case key
- when Integer
- IRB.fail NoSuchJob, key unless @jobs[key]
- @jobs[key] = nil
- else
- catch(:EXISTS) do
- @jobs.each_index do
- |i|
- if @jobs[i] and (@jobs[i][0] == key ||
- @jobs[i][1] == key ||
- @jobs[i][1].context.main.equal?(key))
- @jobs[i] = nil
- throw :EXISTS
- end
- end
- IRB.fail NoSuchJob, key
- end
- end
- until assoc = @jobs.pop; end unless @jobs.empty?
- @jobs.push assoc
- end
-
- # Outputs a list of jobs, see the irb command +irb_jobs+, or +jobs+.
- def inspect
- ary = []
- @jobs.each_index do
- |i|
- th, irb = @jobs[i]
- next if th.nil?
-
- if th.alive?
- if th.stop?
- t_status = "stop"
- else
- t_status = "running"
- end
- else
- t_status = "exited"
- end
- ary.push format("#%d->%s on %s (%s: %s)",
- i,
- irb.context.irb_name,
- irb.context.main,
- th,
- t_status)
- end
- ary.join("\n")
- end
- end
-
- @JobManager = JobManager.new
-
- # The current JobManager in the session
- def IRB.JobManager
- @JobManager
- end
-
- # The current Context in this session
- def IRB.CurrentContext
- IRB.JobManager.irb(Thread.current).context
- end
-
- # Creates a new IRB session, see Irb.new.
- #
- # The optional +file+ argument is given to Context.new, along with the
- # workspace created with the remaining arguments, see WorkSpace.new
- def IRB.irb(file = nil, *main)
- workspace = WorkSpace.new(*main)
- parent_thread = Thread.current
- Thread.start do
- begin
- irb = Irb.new(workspace, file)
- rescue
- print "Subirb can't start with context(self): ", workspace.main.inspect, "\n"
- print "return to main irb\n"
- Thread.pass
- Thread.main.wakeup
- Thread.exit
- end
- @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
- @JobManager.insert(irb)
- @JobManager.current_job = irb
- begin
- system_exit = false
- catch(:IRB_EXIT) do
- irb.eval_input
- end
- rescue SystemExit
- system_exit = true
- raise
- #fail
- ensure
- unless system_exit
- @JobManager.delete(irb)
- if @JobManager.current_job == irb
- if parent_thread.alive?
- @JobManager.current_job = @JobManager.irb(parent_thread)
- parent_thread.run
- else
- @JobManager.current_job = @JobManager.main_irb
- @JobManager.main_thread.run
- end
- end
- end
- end
- end
- Thread.stop
- @JobManager.current_job = @JobManager.irb(Thread.current)
- end
-
- @CONF[:SINGLE_IRB_MODE] = false
- @JobManager.insert(@CONF[:MAIN_CONTEXT].irb)
- @JobManager.current_job = @CONF[:MAIN_CONTEXT].irb
-
- class Irb
- def signal_handle
- unless @context.ignore_sigint?
- print "\nabort!!\n" if @context.verbose?
- exit
- end
-
- case @signal_status
- when :IN_INPUT
- print "^C\n"
- IRB.JobManager.thread(self).raise RubyLex::TerminateLineInput
- when :IN_EVAL
- IRB.irb_abort(self)
- when :IN_LOAD
- IRB.irb_abort(self, LoadAbort)
- when :IN_IRB
- # ignore
- else
- # ignore other cases as well
- end
- end
- end
-
- trap("SIGINT") do
- @JobManager.current_job.signal_handle
- Thread.stop
- end
-
-end
diff --git a/ruby_2_2/lib/irb/ext/save-history.rb b/ruby_2_2/lib/irb/ext/save-history.rb
deleted file mode 100644
index 4477d18e1a..0000000000
--- a/ruby_2_2/lib/irb/ext/save-history.rb
+++ /dev/null
@@ -1,103 +0,0 @@
-# save-history.rb -
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-require "readline"
-
-module IRB
- module HistorySavingAbility # :nodoc:
- end
-
- class Context
- def init_save_history# :nodoc:
- unless (class<<@io;self;end).include?(HistorySavingAbility)
- @io.extend(HistorySavingAbility)
- end
- end
-
- # A copy of the default <code>IRB.conf[:SAVE_HISTORY]</code>
- def save_history
- IRB.conf[:SAVE_HISTORY]
- end
-
- # Sets <code>IRB.conf[:SAVE_HISTORY]</code> to the given +val+ and calls
- # #init_save_history with this context.
- #
- # Will store the number of +val+ entries of history in the #history_file
- #
- # Add the following to your +.irbrc+ to change the number of history
- # entries stored to 1000:
- #
- # IRB.conf[:SAVE_HISTORY] = 1000
- def save_history=(val)
- IRB.conf[:SAVE_HISTORY] = val
- if val
- main_context = IRB.conf[:MAIN_CONTEXT]
- main_context = self unless main_context
- main_context.init_save_history
- end
- end
-
- # A copy of the default <code>IRB.conf[:HISTORY_FILE]</code>
- def history_file
- IRB.conf[:HISTORY_FILE]
- end
-
- # Set <code>IRB.conf[:HISTORY_FILE]</code> to the given +hist+.
- def history_file=(hist)
- IRB.conf[:HISTORY_FILE] = hist
- end
- end
-
- module HistorySavingAbility # :nodoc:
- include Readline
-
- def HistorySavingAbility.extended(obj)
- IRB.conf[:AT_EXIT].push proc{obj.save_history}
- obj.load_history
- obj
- end
-
- def load_history
- if history_file = IRB.conf[:HISTORY_FILE]
- history_file = File.expand_path(history_file)
- end
- history_file = IRB.rc_file("_history") unless history_file
- if File.exist?(history_file)
- open(history_file) do |f|
- f.each {|l| HISTORY << l.chomp}
- end
- end
- end
-
- def save_history
- if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
- if history_file = IRB.conf[:HISTORY_FILE]
- history_file = File.expand_path(history_file)
- end
- history_file = IRB.rc_file("_history") unless history_file
-
- # Change the permission of a file that already exists[BUG #7694]
- begin
- if File.stat(history_file).mode & 066 != 0
- File.chmod(0600, history_file)
- end
- rescue Errno::ENOENT
- rescue
- raise
- end
-
- open(history_file, 'w', 0600 ) do |f|
- hist = HISTORY.to_a
- f.puts(hist[-num..-1] || hist)
- end
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/irb/ext/tracer.rb b/ruby_2_2/lib/irb/ext/tracer.rb
deleted file mode 100644
index c145cf5b4f..0000000000
--- a/ruby_2_2/lib/irb/ext/tracer.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-#
-# irb/lib/tracer.rb -
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-require "tracer"
-
-module IRB
-
- # initialize tracing function
- def IRB.initialize_tracer
- Tracer.verbose = false
- Tracer.add_filter {
- |event, file, line, id, binding, *rests|
- /^#{Regexp.quote(@CONF[:IRB_LIB_PATH])}/ !~ file and
- File::basename(file) != "irb.rb"
- }
- end
-
- class Context
- # Whether Tracer is used when evaluating statements in this context.
- #
- # See +lib/tracer.rb+ for more information.
- attr_reader :use_tracer
- alias use_tracer? use_tracer
-
- # Sets whether or not to use the Tracer library when evaluating statements
- # in this context.
- #
- # See +lib/tracer.rb+ for more information.
- def use_tracer=(opt)
- if opt
- Tracer.set_get_line_procs(@irb_path) {
- |line_no, *rests|
- @io.line(line_no)
- }
- elsif !opt && @use_tracer
- Tracer.off
- end
- @use_tracer=opt
- end
- end
-
- class WorkSpace
- alias __evaluate__ evaluate
- # Evaluate the context of this workspace and use the Tracer library to
- # output the exact lines of code are being executed in chronological order.
- #
- # See +lib/tracer.rb+ for more information.
- def evaluate(context, statements, file = nil, line = nil)
- if context.use_tracer? && file != nil && line != nil
- Tracer.on
- begin
- __evaluate__(context, statements, file, line)
- ensure
- Tracer.off
- end
- else
- __evaluate__(context, statements, file || __FILE__, line || __LINE__)
- end
- end
- end
-
- IRB.initialize_tracer
-end
-
diff --git a/ruby_2_2/lib/irb/ext/use-loader.rb b/ruby_2_2/lib/irb/ext/use-loader.rb
deleted file mode 100644
index 99e76b722f..0000000000
--- a/ruby_2_2/lib/irb/ext/use-loader.rb
+++ /dev/null
@@ -1,73 +0,0 @@
-#
-# use-loader.rb -
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-require "irb/cmd/load"
-require "irb/ext/loader"
-
-class Object
- alias __original__load__IRB_use_loader__ load
- alias __original__require__IRB_use_loader__ require
-end
-
-module IRB
- module ExtendCommandBundle
- # Loads the given file similarly to Kernel#load, see IrbLoader#irb_load
- def irb_load(*opts, &b)
- ExtendCommand::Load.execute(irb_context, *opts, &b)
- end
- # Loads the given file similarly to Kernel#require
- def irb_require(*opts, &b)
- ExtendCommand::Require.execute(irb_context, *opts, &b)
- end
- end
-
- class Context
-
- IRB.conf[:USE_LOADER] = false
-
- # Returns whether +irb+'s own file reader method is used by
- # +load+/+require+ or not.
- #
- # This mode is globally affected (irb-wide).
- def use_loader
- IRB.conf[:USE_LOADER]
- end
-
- alias use_loader? use_loader
-
- # Sets IRB.conf[:USE_LOADER]
- #
- # See #use_loader for more information.
- def use_loader=(opt)
-
- if IRB.conf[:USE_LOADER] != opt
- IRB.conf[:USE_LOADER] = opt
- if opt
- if !$".include?("irb/cmd/load")
- end
- (class<<@workspace.main;self;end).instance_eval {
- alias_method :load, :irb_load
- alias_method :require, :irb_require
- }
- else
- (class<<@workspace.main;self;end).instance_eval {
- alias_method :load, :__original__load__IRB_use_loader__
- alias_method :require, :__original__require__IRB_use_loader__
- }
- end
- end
- print "Switch to load/require#{unless use_loader; ' non';end} trace mode.\n" if verbose?
- opt
- end
- end
-end
-
-
diff --git a/ruby_2_2/lib/irb/ext/workspaces.rb b/ruby_2_2/lib/irb/ext/workspaces.rb
deleted file mode 100644
index 4237037271..0000000000
--- a/ruby_2_2/lib/irb/ext/workspaces.rb
+++ /dev/null
@@ -1,66 +0,0 @@
-#
-# push-ws.rb -
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-module IRB # :nodoc:
- class Context
-
- # Size of the current WorkSpace stack
- def irb_level
- workspace_stack.size
- end
-
- # WorkSpaces in the current stack
- def workspaces
- if defined? @workspaces
- @workspaces
- else
- @workspaces = []
- end
- end
-
- # Creates a new workspace with the given object or binding, and appends it
- # onto the current #workspaces stack.
- #
- # See IRB::Context#change_workspace and IRB::WorkSpace.new for more
- # information.
- def push_workspace(*_main)
- if _main.empty?
- if workspaces.empty?
- print "No other workspace\n"
- return nil
- end
- ws = workspaces.pop
- workspaces.push @workspace
- @workspace = ws
- return workspaces
- end
-
- workspaces.push @workspace
- @workspace = WorkSpace.new(@workspace.binding, _main[0])
- if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
- main.extend ExtendCommandBundle
- end
- end
-
- # Removes the last element from the current #workspaces stack and returns
- # it, or +nil+ if the current workspace stack is empty.
- #
- # Also, see #push_workspace.
- def pop_workspace
- if workspaces.empty?
- print "workspace stack empty\n"
- return
- end
- @workspace = workspaces.pop
- end
- end
-end
-
diff --git a/ruby_2_2/lib/irb/extend-command.rb b/ruby_2_2/lib/irb/extend-command.rb
deleted file mode 100644
index a9326272ff..0000000000
--- a/ruby_2_2/lib/irb/extend-command.rb
+++ /dev/null
@@ -1,308 +0,0 @@
-#
-# irb/extend-command.rb - irb extend command
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-module IRB # :nodoc:
- # Installs the default irb extensions command bundle.
- module ExtendCommandBundle
- EXCB = ExtendCommandBundle # :nodoc:
-
- # See #install_alias_method.
- NO_OVERRIDE = 0
- # See #install_alias_method.
- OVERRIDE_PRIVATE_ONLY = 0x01
- # See #install_alias_method.
- OVERRIDE_ALL = 0x02
-
- # Quits the current irb context
- #
- # +ret+ is the optional signal or message to send to Context#exit
- #
- # Same as <code>IRB.CurrentContext.exit</code>.
- def irb_exit(ret = 0)
- irb_context.exit(ret)
- end
-
- # Displays current configuration.
- #
- # Modifing the configuration is achieved by sending a message to IRB.conf.
- def irb_context
- IRB.CurrentContext
- end
-
- @ALIASES = [
- [:context, :irb_context, NO_OVERRIDE],
- [:conf, :irb_context, NO_OVERRIDE],
- [:irb_quit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
- [:exit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
- [:quit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
- ]
-
- @EXTEND_COMMANDS = [
- [:irb_current_working_workspace, :CurrentWorkingWorkspace, "irb/cmd/chws",
- [:irb_print_working_workspace, OVERRIDE_ALL],
- [:irb_cwws, OVERRIDE_ALL],
- [:irb_pwws, OVERRIDE_ALL],
- [:cwws, NO_OVERRIDE],
- [:pwws, NO_OVERRIDE],
- [:irb_current_working_binding, OVERRIDE_ALL],
- [:irb_print_working_binding, OVERRIDE_ALL],
- [:irb_cwb, OVERRIDE_ALL],
- [:irb_pwb, OVERRIDE_ALL],
- ],
- [:irb_change_workspace, :ChangeWorkspace, "irb/cmd/chws",
- [:irb_chws, OVERRIDE_ALL],
- [:irb_cws, OVERRIDE_ALL],
- [:chws, NO_OVERRIDE],
- [:cws, NO_OVERRIDE],
- [:irb_change_binding, OVERRIDE_ALL],
- [:irb_cb, OVERRIDE_ALL],
- [:cb, NO_OVERRIDE]],
-
- [:irb_workspaces, :Workspaces, "irb/cmd/pushws",
- [:workspaces, NO_OVERRIDE],
- [:irb_bindings, OVERRIDE_ALL],
- [:bindings, NO_OVERRIDE]],
- [:irb_push_workspace, :PushWorkspace, "irb/cmd/pushws",
- [:irb_pushws, OVERRIDE_ALL],
- [:pushws, NO_OVERRIDE],
- [:irb_push_binding, OVERRIDE_ALL],
- [:irb_pushb, OVERRIDE_ALL],
- [:pushb, NO_OVERRIDE]],
- [:irb_pop_workspace, :PopWorkspace, "irb/cmd/pushws",
- [:irb_popws, OVERRIDE_ALL],
- [:popws, NO_OVERRIDE],
- [:irb_pop_binding, OVERRIDE_ALL],
- [:irb_popb, OVERRIDE_ALL],
- [:popb, NO_OVERRIDE]],
-
- [:irb_load, :Load, "irb/cmd/load"],
- [:irb_require, :Require, "irb/cmd/load"],
- [:irb_source, :Source, "irb/cmd/load",
- [:source, NO_OVERRIDE]],
-
- [:irb, :IrbCommand, "irb/cmd/subirb"],
- [:irb_jobs, :Jobs, "irb/cmd/subirb",
- [:jobs, NO_OVERRIDE]],
- [:irb_fg, :Foreground, "irb/cmd/subirb",
- [:fg, NO_OVERRIDE]],
- [:irb_kill, :Kill, "irb/cmd/subirb",
- [:kill, OVERRIDE_PRIVATE_ONLY]],
-
- [:irb_help, :Help, "irb/cmd/help",
- [:help, NO_OVERRIDE]],
-
- ]
-
- # Installs the default irb commands:
- #
- # +irb_current_working_workspace+:: Context#main
- # +irb_change_workspace+:: Context#change_workspace
- # +irb_workspaces+:: Context#workspaces
- # +irb_push_workspace+:: Context#push_workspace
- # +irb_pop_workspace+:: Context#pop_workspace
- # +irb_load+:: #irb_load
- # +irb_require+:: #irb_require
- # +irb_source+:: IrbLoader#source_file
- # +irb+:: IRB.irb
- # +irb_jobs+:: JobManager
- # +irb_fg+:: JobManager#switch
- # +irb_kill+:: JobManager#kill
- # +irb_help+:: IRB@Command+line+options
- def self.install_extend_commands
- for args in @EXTEND_COMMANDS
- def_extend_command(*args)
- end
- end
-
- # Evaluate the given +cmd_name+ on the given +cmd_class+ Class.
- #
- # Will also define any given +aliases+ for the method.
- #
- # The optional +load_file+ parameter will be required within the method
- # definition.
- def self.def_extend_command(cmd_name, cmd_class, load_file = nil, *aliases)
- case cmd_class
- when Symbol
- cmd_class = cmd_class.id2name
- when String
- when Class
- cmd_class = cmd_class.name
- end
-
- if load_file
- line = __LINE__; eval %[
- def #{cmd_name}(*opts, &b)
- require "#{load_file}"
- arity = ExtendCommand::#{cmd_class}.instance_method(:execute).arity
- args = (1..(arity < 0 ? ~arity : arity)).map {|i| "arg" + i.to_s }
- args << "*opts" if arity < 0
- args << "&block"
- args = args.join(", ")
- line = __LINE__; eval %[
- def #{cmd_name}(\#{args})
- ExtendCommand::#{cmd_class}.execute(irb_context, \#{args})
- end
- ], nil, __FILE__, line
- send :#{cmd_name}, *opts, &b
- end
- ], nil, __FILE__, line
- else
- line = __LINE__; eval %[
- def #{cmd_name}(*opts, &b)
- ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b)
- end
- ], nil, __FILE__, line
- end
-
- for ali, flag in aliases
- @ALIASES.push [ali, cmd_name, flag]
- end
- end
-
- # Installs alias methods for the default irb commands, see
- # ::install_extend_commands.
- def install_alias_method(to, from, override = NO_OVERRIDE)
- to = to.id2name unless to.kind_of?(String)
- from = from.id2name unless from.kind_of?(String)
-
- if override == OVERRIDE_ALL or
- (override == OVERRIDE_PRIVATE_ONLY) && !respond_to?(to) or
- (override == NO_OVERRIDE) && !respond_to?(to, true)
- target = self
- (class << self; self; end).instance_eval{
- if target.respond_to?(to, true) &&
- !target.respond_to?(EXCB.irb_original_method_name(to), true)
- alias_method(EXCB.irb_original_method_name(to), to)
- end
- alias_method to, from
- }
- else
- print "irb: warn: can't alias #{to} from #{from}.\n"
- end
- end
-
- def self.irb_original_method_name(method_name) # :nodoc:
- "irb_" + method_name + "_org"
- end
-
- # Installs alias methods for the default irb commands on the given object
- # using #install_alias_method.
- def self.extend_object(obj)
- unless (class << obj; ancestors; end).include?(EXCB)
- super
- for ali, com, flg in @ALIASES
- obj.install_alias_method(ali, com, flg)
- end
- end
- end
-
- install_extend_commands
- end
-
- # Extends methods for the Context module
- module ContextExtender
- CE = ContextExtender # :nodoc:
-
- @EXTEND_COMMANDS = [
- [:eval_history=, "irb/ext/history.rb"],
- [:use_tracer=, "irb/ext/tracer.rb"],
- [:math_mode=, "irb/ext/math-mode.rb"],
- [:use_loader=, "irb/ext/use-loader.rb"],
- [:save_history=, "irb/ext/save-history.rb"],
- ]
-
- # Installs the default context extensions as irb commands:
- #
- # Context#eval_history=:: +irb/ext/history.rb+
- # Context#use_tracer=:: +irb/ext/tracer.rb+
- # Context#math_mode=:: +irb/ext/math-mode.rb+
- # Context#use_loader=:: +irb/ext/use-loader.rb+
- # Context#save_history=:: +irb/ext/save-history.rb+
- def self.install_extend_commands
- for args in @EXTEND_COMMANDS
- def_extend_command(*args)
- end
- end
-
- # Evaluate the given +command+ from the given +load_file+ on the Context
- # module.
- #
- # Will also define any given +aliases+ for the method.
- def self.def_extend_command(cmd_name, load_file, *aliases)
- line = __LINE__; Context.module_eval %[
- def #{cmd_name}(*opts, &b)
- Context.module_eval {remove_method(:#{cmd_name})}
- require "#{load_file}"
- send :#{cmd_name}, *opts, &b
- end
- for ali in aliases
- alias_method ali, cmd_name
- end
- ], __FILE__, line
- end
-
- CE.install_extend_commands
- end
-
- # A convenience module for extending Ruby methods.
- module MethodExtender
- # Extends the given +base_method+ with a prefix call to the given
- # +extend_method+.
- def def_pre_proc(base_method, extend_method)
- base_method = base_method.to_s
- extend_method = extend_method.to_s
-
- alias_name = new_alias_name(base_method)
- module_eval %[
- alias_method alias_name, base_method
- def #{base_method}(*opts)
- send :#{extend_method}, *opts
- send :#{alias_name}, *opts
- end
- ]
- end
-
- # Extends the given +base_method+ with a postfix call to the given
- # +extend_method+.
- def def_post_proc(base_method, extend_method)
- base_method = base_method.to_s
- extend_method = extend_method.to_s
-
- alias_name = new_alias_name(base_method)
- module_eval %[
- alias_method alias_name, base_method
- def #{base_method}(*opts)
- send :#{alias_name}, *opts
- send :#{extend_method}, *opts
- end
- ]
- end
-
- # Returns a unique method name to use as an alias for the given +name+.
- #
- # Usually returns <code>#{prefix}#{name}#{postfix}<num></code>, example:
- #
- # new_alias_name('foo') #=> __alias_of__foo__
- # def bar; end
- # new_alias_name('bar') #=> __alias_of__bar__2
- def new_alias_name(name, prefix = "__alias_of__", postfix = "__")
- base_name = "#{prefix}#{name}#{postfix}"
- all_methods = instance_methods(true) + private_instance_methods(true)
- same_methods = all_methods.grep(/^#{Regexp.quote(base_name)}[0-9]*$/)
- return base_name if same_methods.empty?
- no = same_methods.size
- while !same_methods.include?(alias_name = base_name + no)
- no += 1
- end
- alias_name
- end
- end
-end
-
diff --git a/ruby_2_2/lib/irb/frame.rb b/ruby_2_2/lib/irb/frame.rb
deleted file mode 100644
index 64dd63dddf..0000000000
--- a/ruby_2_2/lib/irb/frame.rb
+++ /dev/null
@@ -1,80 +0,0 @@
-#
-# frame.rb -
-# $Release Version: 0.9$
-# $Revision$
-# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
-#
-# --
-#
-#
-#
-
-require "e2mmap"
-
-module IRB
- class Frame
- extend Exception2MessageMapper
- def_exception :FrameOverflow, "frame overflow"
- def_exception :FrameUnderflow, "frame underflow"
-
- # Default number of stack frames
- INIT_STACK_TIMES = 3
- # Default number of frames offset
- CALL_STACK_OFFSET = 3
-
- # Creates a new stack frame
- def initialize
- @frames = [TOPLEVEL_BINDING] * INIT_STACK_TIMES
- end
-
- # Used by Kernel#set_trace_func to register each event in the call stack
- def trace_func(event, file, line, id, binding)
- case event
- when 'call', 'class'
- @frames.push binding
- when 'return', 'end'
- @frames.pop
- end
- end
-
- # Returns the +n+ number of frames on the call stack from the last frame
- # initialized.
- #
- # Raises FrameUnderflow if there are no frames in the given stack range.
- def top(n = 0)
- bind = @frames[-(n + CALL_STACK_OFFSET)]
- Fail FrameUnderflow unless bind
- bind
- end
-
- # Returns the +n+ number of frames on the call stack from the first frame
- # initialized.
- #
- # Raises FrameOverflow if there are no frames in the given stack range.
- def bottom(n = 0)
- bind = @frames[n]
- Fail FrameOverflow unless bind
- bind
- end
-
- # Convenience method for Frame#bottom
- def Frame.bottom(n = 0)
- @backtrace.bottom(n)
- end
-
- # Convenience method for Frame#top
- def Frame.top(n = 0)
- @backtrace.top(n)
- end
-
- # Returns the binding context of the caller from the last frame initialized
- def Frame.sender
- eval "self", @backtrace.top
- end
-
- @backtrace = Frame.new
- set_trace_func proc{|event, file, line, id, binding, klass|
- @backtrace.trace_func(event, file, line, id, binding)
- }
- end
-end
diff --git a/ruby_2_2/lib/irb/help.rb b/ruby_2_2/lib/irb/help.rb
deleted file mode 100644
index b9ebfb1ae5..0000000000
--- a/ruby_2_2/lib/irb/help.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-#
-# irb/help.rb - print usage module
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ishitsuka.com)
-#
-# --
-#
-#
-#
-
-require 'irb/magic-file'
-
-module IRB
- # Outputs the irb help message, see IRB@Command+line+options.
- def IRB.print_usage
- lc = IRB.conf[:LC_MESSAGES]
- path = lc.find("irb/help-message")
- space_line = false
- IRB::MagicFile.open(path){|f|
- f.each_line do |l|
- if /^\s*$/ =~ l
- lc.puts l unless space_line
- space_line = true
- next
- end
- space_line = false
-
- l.sub!(/#.*$/, "")
- next if /^\s*$/ =~ l
- lc.puts l
- end
- }
- end
-end
-
diff --git a/ruby_2_2/lib/irb/init.rb b/ruby_2_2/lib/irb/init.rb
deleted file mode 100644
index af9c363a97..0000000000
--- a/ruby_2_2/lib/irb/init.rb
+++ /dev/null
@@ -1,304 +0,0 @@
-#
-# irb/init.rb - irb initialize module
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-module IRB # :nodoc:
-
- # initialize config
- def IRB.setup(ap_path)
- IRB.init_config(ap_path)
- IRB.init_error
- IRB.parse_opts
- IRB.run_config
- IRB.load_modules
-
- unless @CONF[:PROMPT][@CONF[:PROMPT_MODE]]
- IRB.fail(UndefinedPromptMode, @CONF[:PROMPT_MODE])
- end
- end
-
- # @CONF default setting
- def IRB.init_config(ap_path)
- # class instance variables
- @TRACER_INITIALIZED = false
-
- # default configurations
- unless ap_path and @CONF[:AP_NAME]
- ap_path = File.join(File.dirname(File.dirname(__FILE__)), "irb.rb")
- end
- @CONF[:AP_NAME] = File::basename(ap_path, ".rb")
-
- @CONF[:IRB_NAME] = "irb"
- @CONF[:IRB_LIB_PATH] = File.dirname(__FILE__)
-
- @CONF[:RC] = true
- @CONF[:LOAD_MODULES] = []
- @CONF[:IRB_RC] = nil
-
- @CONF[:MATH_MODE] = false
- @CONF[:USE_READLINE] = false unless defined?(ReadlineInputMethod)
- @CONF[:INSPECT_MODE] = true
- @CONF[:USE_TRACER] = false
- @CONF[:USE_LOADER] = false
- @CONF[:IGNORE_SIGINT] = true
- @CONF[:IGNORE_EOF] = false
- @CONF[:ECHO] = nil
- @CONF[:VERBOSE] = nil
-
- @CONF[:EVAL_HISTORY] = nil
- @CONF[:SAVE_HISTORY] = nil
-
- @CONF[:BACK_TRACE_LIMIT] = 16
-
- @CONF[:PROMPT] = {
- :NULL => {
- :PROMPT_I => nil,
- :PROMPT_N => nil,
- :PROMPT_S => nil,
- :PROMPT_C => nil,
- :RETURN => "%s\n"
- },
- :DEFAULT => {
- :PROMPT_I => "%N(%m):%03n:%i> ",
- :PROMPT_N => "%N(%m):%03n:%i> ",
- :PROMPT_S => "%N(%m):%03n:%i%l ",
- :PROMPT_C => "%N(%m):%03n:%i* ",
- :RETURN => "=> %s\n"
- },
- :CLASSIC => {
- :PROMPT_I => "%N(%m):%03n:%i> ",
- :PROMPT_N => "%N(%m):%03n:%i> ",
- :PROMPT_S => "%N(%m):%03n:%i%l ",
- :PROMPT_C => "%N(%m):%03n:%i* ",
- :RETURN => "%s\n"
- },
- :SIMPLE => {
- :PROMPT_I => ">> ",
- :PROMPT_N => ">> ",
- :PROMPT_S => nil,
- :PROMPT_C => "?> ",
- :RETURN => "=> %s\n"
- },
- :INF_RUBY => {
- :PROMPT_I => "%N(%m):%03n:%i> ",
- :PROMPT_N => nil,
- :PROMPT_S => nil,
- :PROMPT_C => nil,
- :RETURN => "%s\n",
- :AUTO_INDENT => true
- },
- :XMP => {
- :PROMPT_I => nil,
- :PROMPT_N => nil,
- :PROMPT_S => nil,
- :PROMPT_C => nil,
- :RETURN => " ==>%s\n"
- }
- }
-
- @CONF[:PROMPT_MODE] = (STDIN.tty? ? :DEFAULT : :NULL)
- @CONF[:AUTO_INDENT] = false
-
- @CONF[:CONTEXT_MODE] = 3 # use binding in function on TOPLEVEL_BINDING
- @CONF[:SINGLE_IRB] = false
-
- @CONF[:LC_MESSAGES] = Locale.new
-
- @CONF[:AT_EXIT] = []
-
- @CONF[:DEBUG_LEVEL] = 0
- end
-
- def IRB.init_error
- @CONF[:LC_MESSAGES].load("irb/error.rb")
- end
-
- # option analyzing
- def IRB.parse_opts
- load_path = []
- while opt = ARGV.shift
- case opt
- when "-f"
- @CONF[:RC] = false
- when "-m"
- @CONF[:MATH_MODE] = true
- when "-d"
- $DEBUG = true
- $VERBOSE = true
- when "-w"
- $VERBOSE = true
- when /^-W(.+)?/
- opt = $1 || ARGV.shift
- case opt
- when "0"
- $VERBOSE = nil
- when "1"
- $VERBOSE = false
- else
- $VERBOSE = true
- end
- when /^-r(.+)?/
- opt = $1 || ARGV.shift
- @CONF[:LOAD_MODULES].push opt if opt
- when /^-I(.+)?/
- opt = $1 || ARGV.shift
- load_path.concat(opt.split(File::PATH_SEPARATOR)) if opt
- when '-U'
- set_encoding("UTF-8", "UTF-8")
- when /^-E(.+)?/, /^--encoding(?:=(.+))?/
- opt = $1 || ARGV.shift
- set_encoding(*opt.split(':', 2))
- when "--inspect"
- if /^-/ !~ ARGV.first
- @CONF[:INSPECT_MODE] = ARGV.shift
- else
- @CONF[:INSPECT_MODE] = true
- end
- when "--noinspect"
- @CONF[:INSPECT_MODE] = false
- when "--readline"
- @CONF[:USE_READLINE] = true
- when "--noreadline"
- @CONF[:USE_READLINE] = false
- when "--echo"
- @CONF[:ECHO] = true
- when "--noecho"
- @CONF[:ECHO] = false
- when "--verbose"
- @CONF[:VERBOSE] = true
- when "--noverbose"
- @CONF[:VERBOSE] = false
- when /^--prompt-mode(?:=(.+))?/, /^--prompt(?:=(.+))?/
- opt = $1 || ARGV.shift
- prompt_mode = opt.upcase.tr("-", "_").intern
- @CONF[:PROMPT_MODE] = prompt_mode
- when "--noprompt"
- @CONF[:PROMPT_MODE] = :NULL
- when "--inf-ruby-mode"
- @CONF[:PROMPT_MODE] = :INF_RUBY
- when "--sample-book-mode", "--simple-prompt"
- @CONF[:PROMPT_MODE] = :SIMPLE
- when "--tracer"
- @CONF[:USE_TRACER] = true
- when /^--back-trace-limit(?:=(.+))?/
- @CONF[:BACK_TRACE_LIMIT] = ($1 || ARGV.shift).to_i
- when /^--context-mode(?:=(.+))?/
- @CONF[:CONTEXT_MODE] = ($1 || ARGV.shift).to_i
- when "--single-irb"
- @CONF[:SINGLE_IRB] = true
- when /^--irb_debug(?:=(.+))?/
- @CONF[:DEBUG_LEVEL] = ($1 || ARGV.shift).to_i
- when "-v", "--version"
- print IRB.version, "\n"
- exit 0
- when "-h", "--help"
- require "irb/help"
- IRB.print_usage
- exit 0
- when "--"
- if opt = ARGV.shift
- @CONF[:SCRIPT] = opt
- $0 = opt
- end
- break
- when /^-/
- IRB.fail UnrecognizedSwitch, opt
- else
- @CONF[:SCRIPT] = opt
- $0 = opt
- break
- end
- end
- load_path.collect! do |path|
- /\A\.\// =~ path ? path : File.expand_path(path)
- end
- $LOAD_PATH.unshift(*load_path)
-
- end
-
- # running config
- def IRB.run_config
- if @CONF[:RC]
- begin
- load rc_file
- rescue LoadError, Errno::ENOENT
- rescue # StandardError, ScriptError
- print "load error: #{rc_file}\n"
- print $!.class, ": ", $!, "\n"
- for err in $@[0, $@.size - 2]
- print "\t", err, "\n"
- end
- end
- end
- end
-
- IRBRC_EXT = "rc"
- def IRB.rc_file(ext = IRBRC_EXT)
- if !@CONF[:RC_NAME_GENERATOR]
- rc_file_generators do |rcgen|
- @CONF[:RC_NAME_GENERATOR] ||= rcgen
- if File.exist?(rcgen.call(IRBRC_EXT))
- @CONF[:RC_NAME_GENERATOR] = rcgen
- break
- end
- end
- end
- case rc_file = @CONF[:RC_NAME_GENERATOR].call(ext)
- when String
- return rc_file
- else
- IRB.fail IllegalRCNameGenerator
- end
- end
-
- # enumerate possible rc-file base name generators
- def IRB.rc_file_generators
- if irbrc = ENV["IRBRC"]
- yield proc{|rc| rc == "rc" ? irbrc : irbrc+rc}
- end
- if home = ENV["HOME"]
- yield proc{|rc| home+"/.irb#{rc}"}
- end
- home = Dir.pwd
- yield proc{|rc| home+"/.irb#{rc}"}
- yield proc{|rc| home+"/irb#{rc.sub(/\A_?/, '.')}"}
- yield proc{|rc| home+"/_irb#{rc}"}
- yield proc{|rc| home+"/$irb#{rc}"}
- end
-
- # loading modules
- def IRB.load_modules
- for m in @CONF[:LOAD_MODULES]
- begin
- require m
- rescue LoadError => err
- warn err.backtrace[0] << ":#{err.class}: #{err}"
- end
- end
- end
-
-
- DefaultEncodings = Struct.new(:external, :internal)
- class << IRB
- private
- def set_encoding(extern, intern = nil)
- verbose, $VERBOSE = $VERBOSE, nil
- Encoding.default_external = extern unless extern.nil? || extern.empty?
- Encoding.default_internal = intern unless intern.nil? || intern.empty?
- @CONF[:ENCODINGS] = IRB::DefaultEncodings.new(extern, intern)
- [$stdin, $stdout, $stderr].each do |io|
- io.set_encoding(extern, intern)
- end
- @CONF[:LC_MESSAGES].instance_variable_set(:@encoding, extern)
- ensure
- $VERBOSE = verbose
- end
- end
-end
diff --git a/ruby_2_2/lib/irb/input-method.rb b/ruby_2_2/lib/irb/input-method.rb
deleted file mode 100644
index 4ea3f585f8..0000000000
--- a/ruby_2_2/lib/irb/input-method.rb
+++ /dev/null
@@ -1,191 +0,0 @@
-#
-# irb/input-method.rb - input methods used irb
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-require 'irb/src_encoding'
-require 'irb/magic-file'
-
-module IRB
- STDIN_FILE_NAME = "(line)" # :nodoc:
- class InputMethod
-
- # Creates a new input method object
- def initialize(file = STDIN_FILE_NAME)
- @file_name = file
- end
- # The file name of this input method, usually given during initialization.
- attr_reader :file_name
-
- # The irb prompt associated with this input method
- attr_accessor :prompt
-
- # Reads the next line from this input method.
- #
- # See IO#gets for more information.
- def gets
- IRB.fail NotImplementedError, "gets"
- end
- public :gets
-
- # Whether this input method is still readable when there is no more data to
- # read.
- #
- # See IO#eof for more information.
- def readable_after_eof?
- false
- end
- end
-
- class StdioInputMethod < InputMethod
- # Creates a new input method object
- def initialize
- super
- @line_no = 0
- @line = []
- @stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
- @stdout = IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
- end
-
- # Reads the next line from this input method.
- #
- # See IO#gets for more information.
- def gets
- print @prompt
- line = @stdin.gets
- @line[@line_no += 1] = line
- end
-
- # Whether the end of this input method has been reached, returns +true+ if
- # there is no more data to read.
- #
- # See IO#eof? for more information.
- def eof?
- @stdin.eof?
- end
-
- # Whether this input method is still readable when there is no more data to
- # read.
- #
- # See IO#eof for more information.
- def readable_after_eof?
- true
- end
-
- # Returns the current line number for #io.
- #
- # #line counts the number of times #gets is called.
- #
- # See IO#lineno for more information.
- def line(line_no)
- @line[line_no]
- end
-
- # The external encoding for standard input.
- def encoding
- @stdin.external_encoding
- end
- end
-
- # Use a File for IO with irb, see InputMethod
- class FileInputMethod < InputMethod
- # Creates a new input method object
- def initialize(file)
- super
- @io = IRB::MagicFile.open(file)
- end
- # The file name of this input method, usually given during initialization.
- attr_reader :file_name
-
- # Whether the end of this input method has been reached, returns +true+ if
- # there is no more data to read.
- #
- # See IO#eof? for more information.
- def eof?
- @io.eof?
- end
-
- # Reads the next line from this input method.
- #
- # See IO#gets for more information.
- def gets
- print @prompt
- l = @io.gets
- l
- end
-
- # The external encoding for standard input.
- def encoding
- @io.external_encoding
- end
- end
-
- begin
- require "readline"
- class ReadlineInputMethod < InputMethod
- include Readline
- # Creates a new input method object using Readline
- def initialize
- super
-
- @line_no = 0
- @line = []
- @eof = false
-
- @stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
- @stdout = IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
- end
-
- # Reads the next line from this input method.
- #
- # See IO#gets for more information.
- def gets
- Readline.input = @stdin
- Readline.output = @stdout
- if l = readline(@prompt, false)
- HISTORY.push(l) if !l.empty?
- @line[@line_no += 1] = l + "\n"
- else
- @eof = true
- l
- end
- end
-
- # Whether the end of this input method has been reached, returns +true+
- # if there is no more data to read.
- #
- # See IO#eof? for more information.
- def eof?
- @eof
- end
-
- # Whether this input method is still readable when there is no more data to
- # read.
- #
- # See IO#eof for more information.
- def readable_after_eof?
- true
- end
-
- # Returns the current line number for #io.
- #
- # #line counts the number of times #gets is called.
- #
- # See IO#lineno for more information.
- def line(line_no)
- @line[line_no]
- end
-
- # The external encoding for standard input.
- def encoding
- @stdin.external_encoding
- end
- end
- rescue LoadError
- end
-end
diff --git a/ruby_2_2/lib/irb/inspector.rb b/ruby_2_2/lib/irb/inspector.rb
deleted file mode 100644
index f09b12927a..0000000000
--- a/ruby_2_2/lib/irb/inspector.rb
+++ /dev/null
@@ -1,131 +0,0 @@
-#
-# irb/inspector.rb - inspect methods
-# $Release Version: 0.9.6$
-# $Revision: 1.19 $
-# $Date: 2002/06/11 07:51:31 $
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-module IRB # :nodoc:
-
-
- # Convenience method to create a new Inspector, using the given +inspect+
- # proc, and optional +init+ proc and passes them to Inspector.new
- #
- # irb(main):001:0> ins = IRB::Inspector(proc{ |v| "omg! #{v}" })
- # irb(main):001:0> IRB.CurrentContext.inspect_mode = ins # => omg! #<IRB::Inspector:0x007f46f7ba7d28>
- # irb(main):001:0> "what?" #=> omg! what?
- #
- def IRB::Inspector(inspect, init = nil)
- Inspector.new(inspect, init)
- end
-
- # An irb inspector
- #
- # In order to create your own custom inspector there are two things you
- # should be aware of:
- #
- # Inspector uses #inspect_value, or +inspect_proc+, for output of return values.
- #
- # This also allows for an optional #init+, or +init_proc+, which is called
- # when the inspector is activated.
- #
- # Knowing this, you can create a rudimentary inspector as follows:
- #
- # irb(main):001:0> ins = IRB::Inspector.new(proc{ |v| "omg! #{v}" })
- # irb(main):001:0> IRB.CurrentContext.inspect_mode = ins # => omg! #<IRB::Inspector:0x007f46f7ba7d28>
- # irb(main):001:0> "what?" #=> omg! what?
- #
- class Inspector
- # Default inspectors available to irb, this includes:
- #
- # +:pp+:: Using Kernel#pretty_inspect
- # +:yaml+:: Using YAML.dump
- # +:marshal+:: Using Marshal.dump
- INSPECTORS = {}
-
- # Determines the inspector to use where +inspector+ is one of the keys passed
- # during inspector definition.
- def self.keys_with_inspector(inspector)
- INSPECTORS.select{|k,v| v == inspector}.collect{|k, v| k}
- end
-
- # Example
- #
- # Inspector.def_inspector(key, init_p=nil){|v| v.inspect}
- # Inspector.def_inspector([key1,..], init_p=nil){|v| v.inspect}
- # Inspector.def_inspector(key, inspector)
- # Inspector.def_inspector([key1,...], inspector)
- def self.def_inspector(key, arg=nil, &block)
- if block_given?
- inspector = IRB::Inspector(block, arg)
- else
- inspector = arg
- end
-
- case key
- when Array
- for k in key
- def_inspector(k, inspector)
- end
- when Symbol
- INSPECTORS[key] = inspector
- INSPECTORS[key.to_s] = inspector
- when String
- INSPECTORS[key] = inspector
- INSPECTORS[key.intern] = inspector
- else
- INSPECTORS[key] = inspector
- end
- end
-
- # Creates a new inspector object, using the given +inspect_proc+ when
- # output return values in irb.
- def initialize(inspect_proc, init_proc = nil)
- @init = init_proc
- @inspect = inspect_proc
- end
-
- # Proc to call when the inspector is activated, good for requiring
- # dependent libraries.
- def init
- @init.call if @init
- end
-
- # Proc to call when the input is evaluated and output in irb.
- def inspect_value(v)
- @inspect.call(v)
- end
- end
-
- Inspector.def_inspector([false, :to_s, :raw]){|v| v.to_s}
- Inspector.def_inspector([true, :p, :inspect]){|v|
- begin
- v.inspect
- rescue NoMethodError
- puts "(Object doesn't support #inspect)"
- end
- }
- Inspector.def_inspector([:pp, :pretty_inspect], proc{require "pp"}){|v| v.pretty_inspect.chomp}
- Inspector.def_inspector([:yaml, :YAML], proc{require "yaml"}){|v|
- begin
- YAML.dump(v)
- rescue
- puts "(can't dump yaml. use inspect)"
- v.inspect
- end
- }
-
- Inspector.def_inspector([:marshal, :Marshal, :MARSHAL, Marshal]){|v|
- Marshal.dump(v)
- }
-end
-
-
-
-
-
diff --git a/ruby_2_2/lib/irb/lc/.document b/ruby_2_2/lib/irb/lc/.document
deleted file mode 100644
index 524bb9430b..0000000000
--- a/ruby_2_2/lib/irb/lc/.document
+++ /dev/null
@@ -1,4 +0,0 @@
-# hide help-message files which contain usage information
-error.rb
-ja/encoding_aliases.rb
-ja/error.rb
diff --git a/ruby_2_2/lib/irb/lc/error.rb b/ruby_2_2/lib/irb/lc/error.rb
deleted file mode 100644
index c0c6c30d79..0000000000
--- a/ruby_2_2/lib/irb/lc/error.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-# irb/lc/error.rb -
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-require "e2mmap"
-
-# :stopdoc:
-module IRB
-
- # exceptions
- extend Exception2MessageMapper
- def_exception :UnrecognizedSwitch, "Unrecognized switch: %s"
- def_exception :NotImplementedError, "Need to define `%s'"
- def_exception :CantReturnToNormalMode, "Can't return to normal mode."
- def_exception :IllegalParameter, "Invalid parameter(%s)."
- def_exception :IrbAlreadyDead, "Irb is already dead."
- def_exception :IrbSwitchedToCurrentThread, "Switched to current thread."
- def_exception :NoSuchJob, "No such job(%s)."
- def_exception :CantShiftToMultiIrbMode, "Can't shift to multi irb mode."
- def_exception :CantChangeBinding, "Can't change binding to (%s)."
- def_exception :UndefinedPromptMode, "Undefined prompt mode(%s)."
- def_exception :IllegalRCGenerator, 'Define illegal RC_NAME_GENERATOR.'
-
-end
-# :startdoc:
diff --git a/ruby_2_2/lib/irb/lc/help-message b/ruby_2_2/lib/irb/lc/help-message
deleted file mode 100644
index 5853693eb0..0000000000
--- a/ruby_2_2/lib/irb/lc/help-message
+++ /dev/null
@@ -1,50 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# irb/lc/help-message.rb -
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-Usage: irb.rb [options] [programfile] [arguments]
- -f Suppress read of ~/.irbrc
- -m Bc mode (load mathn, fraction or matrix are available)
- -d Set $DEBUG to true (same as `ruby -d')
- -r load-module Same as `ruby -r'
- -I path Specify $LOAD_PATH directory
- -U Same as `ruby -U`
- -E enc Same as `ruby -E`
- -w Same as `ruby -w`
- -W[level=2] Same as `ruby -W`
- --context-mode n Set n[0-3] to method to create Binding Object,
- when new workspace was created
- --echo Show result(default)
- --noecho Don't show result
- --inspect Use `inspect' for output (default except for bc mode)
- --noinspect Don't use inspect for output
- --readline Use Readline extension module
- --noreadline Don't use Readline extension module
- --prompt prompt-mode/--prompt-mode prompt-mode
- Switch prompt mode. Pre-defined prompt modes are
- `default', `simple', `xmp' and `inf-ruby'
- --inf-ruby-mode Use prompt appropriate for inf-ruby-mode on emacs.
- Suppresses --readline.
- --sample-book-mode/--simple-prompt
- Simple prompt mode
- --noprompt No prompt mode
- --single-irb Share self with sub-irb.
- --tracer Display trace for each execution of commands.
- --back-trace-limit n
- Display backtrace top n and tail n. The default
- value is 16.
- --irb_debug n Set internal debug level to n (not for popular use)
- --verbose Show details
- --noverbose Don't show details
- -v, --version Print the version of irb
- -h, --help Print help
- -- Separate options of irb from the list of command-line args
-
-# vim:fileencoding=utf-8
diff --git a/ruby_2_2/lib/irb/lc/ja/encoding_aliases.rb b/ruby_2_2/lib/irb/lc/ja/encoding_aliases.rb
deleted file mode 100644
index 5bef32e20e..0000000000
--- a/ruby_2_2/lib/irb/lc/ja/encoding_aliases.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-# :stopdoc:
-module IRB
- class Locale
- @@legacy_encoding_alias_map = {
- 'ujis' => Encoding::EUC_JP,
- 'euc' => Encoding::EUC_JP
- }.freeze
- end
-end
-# :startdoc:
diff --git a/ruby_2_2/lib/irb/lc/ja/error.rb b/ruby_2_2/lib/irb/lc/ja/error.rb
deleted file mode 100644
index 4f09d781cb..0000000000
--- a/ruby_2_2/lib/irb/lc/ja/error.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-# -*- coding: utf-8 -*-
-# irb/lc/ja/error.rb -
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-require "e2mmap"
-
-# :stopdoc:
-module IRB
- # exceptions
- extend Exception2MessageMapper
- def_exception :UnrecognizedSwitch, 'スイッチ(%s)が分りません'
- def_exception :NotImplementedError, '`%s\'の定義が必要です'
- def_exception :CantReturnToNormalMode, 'Normalモードに戻れません.'
- def_exception :IllegalParameter, 'パラメータ(%s)が間違っています.'
- def_exception :IrbAlreadyDead, 'Irbは既に死んでいます.'
- def_exception :IrbSwitchedToCurrentThread, 'カレントスレッドに切り替わりました.'
- def_exception :NoSuchJob, 'そのようなジョブ(%s)はありません.'
- def_exception :CantShiftToMultiIrbMode, 'multi-irb modeに移れません.'
- def_exception :CantChangeBinding, 'バインディング(%s)に変更できません.'
- def_exception :UndefinedPromptMode, 'プロンプトモード(%s)は定義されていません.'
- def_exception :IllegalRCNameGenerator, 'RC_NAME_GENERATORが正しく定義されていません.'
-end
-# :startdoc:
-# vim:fileencoding=utf-8
diff --git a/ruby_2_2/lib/irb/lc/ja/help-message b/ruby_2_2/lib/irb/lc/ja/help-message
deleted file mode 100644
index 288eb5245c..0000000000
--- a/ruby_2_2/lib/irb/lc/ja/help-message
+++ /dev/null
@@ -1,53 +0,0 @@
-# -*- coding: utf-8 -*-
-# irb/lc/ja/help-message.rb -
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-Usage: irb.rb [options] [programfile] [arguments]
- -f ~/.irbrc を読み込まない.
- -m bcモード(分数, 行列の計算ができる)
- -d $DEBUG をtrueにする(ruby -d と同じ)
- -r load-module ruby -r と同じ.
- -I path $LOAD_PATH に path を追加する.
- -U ruby -U と同じ.
- -E enc ruby -E と同じ.
- -w ruby -w と同じ.
- -W[level=2] ruby -W と同じ.
- --context-mode n 新しいワークスペースを作成した時に関連する Binding
- オブジェクトの作成方法を 0 から 3 のいずれかに設定する.
- --echo 実行結果を表示する(デフォルト).
- --noecho 実行結果を表示しない.
- --inspect 結果出力にinspectを用いる(bcモード以外はデフォルト).
- --noinspect 結果出力にinspectを用いない.
- --readline readlineライブラリを利用する.
- --noreadline readlineライブラリを利用しない.
- --prompt prompt-mode/--prompt-mode prompt-mode
- プロンプトモードを切替えます. 現在定義されているプ
- ロンプトモードは, default, simple, xmp, inf-rubyが
- 用意されています.
- --inf-ruby-mode emacsのinf-ruby-mode用のプロンプト表示を行なう. 特
- に指定がない限り, readlineライブラリは使わなくなる.
- --sample-book-mode/--simple-prompt
- 非常にシンプルなプロンプトを用いるモードです.
- --noprompt プロンプト表示を行なわない.
- --single-irb irb 中で self を実行して得られるオブジェクトをサ
- ブ irb と共有する.
- --tracer コマンド実行時にトレースを行なう.
- --back-trace-limit n
- バックトレース表示をバックトレースの頭から n, 後ろ
- からnだけ行なう. デフォルトは16
-
- --irb_debug n irbのデバッグレベルをnに設定する(非推奨).
-
- --verbose 詳細なメッセージを出力する.
- --noverbose 詳細なメッセージを出力しない(デフォルト).
- -v, --version irbのバージョンを表示する.
- -h, --help irb のヘルプを表示する.
- -- 以降のコマンドライン引数をオプションとして扱わない.
-
-# vim:fileencoding=utf-8
diff --git a/ruby_2_2/lib/irb/locale.rb b/ruby_2_2/lib/irb/locale.rb
deleted file mode 100644
index 9f40188171..0000000000
--- a/ruby_2_2/lib/irb/locale.rb
+++ /dev/null
@@ -1,181 +0,0 @@
-#
-# irb/locale.rb - internationalization module
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-module IRB # :nodoc:
- class Locale
-
- LOCALE_NAME_RE = %r[
- (?<language>[[:alpha:]]{2,3})
- (?:_ (?<territory>[[:alpha:]]{2,3}) )?
- (?:\. (?<codeset>[^@]+) )?
- (?:@ (?<modifier>.*) )?
- ]x
- LOCALE_DIR = "/lc/"
-
- @@legacy_encoding_alias_map = {}.freeze
-
- def initialize(locale = nil)
- @lang = @territory = @encoding_name = @modifier = nil
- @locale = locale || ENV["IRB_LANG"] || ENV["LC_MESSAGES"] || ENV["LC_ALL"] || ENV["LANG"] || "C"
- if m = LOCALE_NAME_RE.match(@locale)
- @lang, @territory, @encoding_name, @modifier = m[:language], m[:territory], m[:codeset], m[:modifier]
-
- if @encoding_name
- begin load 'irb/encoding_aliases.rb'; rescue LoadError; end
- if @encoding = @@legacy_encoding_alias_map[@encoding_name]
- warn "%s is obsolete. use %s" % ["#{@lang}_#{@territory}.#{@encoding_name}", "#{@lang}_#{@territory}.#{@encoding.name}"]
- end
- @encoding = Encoding.find(@encoding_name) rescue nil
- end
- end
- @encoding ||= (Encoding.find('locale') rescue Encoding::ASCII_8BIT)
- end
-
- attr_reader :lang, :territory, :encoding, :modifier
-
- def String(mes)
- mes = super(mes)
- if @encoding
- mes.encode(@encoding, undef: :replace)
- else
- mes
- end
- end
-
- def format(*opts)
- String(super(*opts))
- end
-
- def gets(*rs)
- String(super(*rs))
- end
-
- def readline(*rs)
- String(super(*rs))
- end
-
- def print(*opts)
- ary = opts.collect{|opt| String(opt)}
- super(*ary)
- end
-
- def printf(*opts)
- s = format(*opts)
- print s
- end
-
- def puts(*opts)
- ary = opts.collect{|opt| String(opt)}
- super(*ary)
- end
-
- def require(file, priv = nil)
- rex = Regexp.new("lc/#{Regexp.quote(file)}\.(so|o|sl|rb)?")
- return false if $".find{|f| f =~ rex}
-
- case file
- when /\.rb$/
- begin
- load(file, priv)
- $".push file
- return true
- rescue LoadError
- end
- when /\.(so|o|sl)$/
- return super
- end
-
- begin
- load(f = file + ".rb")
- $".push f #"
- return true
- rescue LoadError
- return ruby_require(file)
- end
- end
-
- alias toplevel_load load
-
- def load(file, priv=nil)
- found = find(file)
- if found
- return real_load(found, priv)
- else
- raise LoadError, "No such file to load -- #{file}"
- end
- end
-
- def find(file , paths = $:)
- dir = File.dirname(file)
- dir = "" if dir == "."
- base = File.basename(file)
-
- if dir.start_with?('/')
- return each_localized_path(dir, base).find{|full_path| File.readable? full_path}
- else
- return search_file(paths, dir, base)
- end
- end
-
- private
- def real_load(path, priv)
- src = MagicFile.open(path){|f| f.read}
- if priv
- eval("self", TOPLEVEL_BINDING).extend(Module.new {eval(src, nil, path)})
- else
- eval(src, TOPLEVEL_BINDING, path)
- end
- end
-
- # @param paths load paths in which IRB find a localized file.
- # @param dir directory
- # @param file basename to be localized
- #
- # typically, for the parameters and a <path> in paths, it searches
- # <path>/<dir>/<locale>/<file>
- def search_file(lib_paths, dir, file)
- each_localized_path(dir, file) do |lc_path|
- lib_paths.each do |libpath|
- full_path = File.join(libpath, lc_path)
- return full_path if File.readable?(full_path)
- end
- redo if defined?(Gem) and Gem.try_activate(lc_path)
- end
- nil
- end
-
- def each_localized_path(dir, file)
- return enum_for(:each_localized_path) unless block_given?
- each_sublocale do |lc|
- yield lc.nil? ? File.join(dir, LOCALE_DIR, file) : File.join(dir, LOCALE_DIR, lc, file)
- end
- end
-
- def each_sublocale
- if @lang
- if @territory
- if @encoding_name
- yield "#{@lang}_#{@territory}.#{@encoding_name}@#{@modifier}" if @modifier
- yield "#{@lang}_#{@territory}.#{@encoding_name}"
- end
- yield "#{@lang}_#{@territory}@#{@modifier}" if @modifier
- yield "#{@lang}_#{@territory}"
- end
- if @encoding_name
- yield "#{@lang}.#{@encoding_name}@#{@modifier}" if @modifier
- yield "#{@lang}.#{@encoding_name}"
- end
- yield "#{@lang}@#{@modifier}" if @modifier
- yield "#{@lang}"
- end
- yield nil
- end
- end
-end
diff --git a/ruby_2_2/lib/irb/magic-file.rb b/ruby_2_2/lib/irb/magic-file.rb
deleted file mode 100644
index 339ed60b6b..0000000000
--- a/ruby_2_2/lib/irb/magic-file.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-module IRB
- class << (MagicFile = Object.new)
- # see parser_magic_comment in parse.y
- ENCODING_SPEC_RE = %r"coding\s*[=:]\s*([[:alnum:]\-_]+)"
-
- def open(path)
- io = File.open(path, 'rb')
- line = io.gets
- line = io.gets if line[0,2] == "#!"
- encoding = detect_encoding(line)
- internal_encoding = encoding
- encoding ||= default_src_encoding
- io.rewind
- io.set_encoding(encoding, internal_encoding)
-
- if block_given?
- begin
- return (yield io)
- ensure
- io.close
- end
- else
- return io
- end
- end
-
- private
- def detect_encoding(line)
- return unless line[0] == ?#
- line = line[1..-1]
- line = $1 if line[/-\*-\s*(.*?)\s*-*-$/]
- return nil unless ENCODING_SPEC_RE =~ line
- encoding = $1
- return encoding.sub(/-(?:mac|dos|unix)/i, '')
- end
- end
-end
diff --git a/ruby_2_2/lib/irb/notifier.rb b/ruby_2_2/lib/irb/notifier.rb
deleted file mode 100644
index d5981df2bf..0000000000
--- a/ruby_2_2/lib/irb/notifier.rb
+++ /dev/null
@@ -1,231 +0,0 @@
-#
-# notifier.rb - output methods used by irb
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-require "e2mmap"
-require "irb/output-method"
-
-module IRB
- # An output formatter used internally by the lexer.
- module Notifier
- extend Exception2MessageMapper
- def_exception :ErrUndefinedNotifier,
- "undefined notifier level: %d is specified"
- def_exception :ErrUnrecognizedLevel,
- "unrecognized notifier level: %s is specified"
-
- # Define a new Notifier output source, returning a new CompositeNotifier
- # with the given +prefix+ and +output_method+.
- #
- # The optional +prefix+ will be appended to all objects being inspected
- # during output, using the given +output_method+ as the output source. If
- # no +output_method+ is given, StdioOutputMethod will be used, and all
- # expressions will be sent directly to STDOUT without any additional
- # formatting.
- def def_notifier(prefix = "", output_method = StdioOutputMethod.new)
- CompositeNotifier.new(prefix, output_method)
- end
- module_function :def_notifier
-
- # An abstract class, or superclass, for CompositeNotifier and
- # LeveledNotifier to inherit. It provides several wrapper methods for the
- # OutputMethod object used by the Notifier.
- class AbstractNotifier
- # Creates a new Notifier object
- def initialize(prefix, base_notifier)
- @prefix = prefix
- @base_notifier = base_notifier
- end
-
- # The +prefix+ for this Notifier, which is appended to all objects being
- # inspected during output.
- attr_reader :prefix
-
- # A wrapper method used to determine whether notifications are enabled.
- #
- # Defaults to +true+.
- def notify?
- true
- end
-
- # See OutputMethod#print for more detail.
- def print(*opts)
- @base_notifier.print prefix, *opts if notify?
- end
-
- # See OutputMethod#printn for more detail.
- def printn(*opts)
- @base_notifier.printn prefix, *opts if notify?
- end
-
- # See OutputMethod#printf for more detail.
- def printf(format, *opts)
- @base_notifier.printf(prefix + format, *opts) if notify?
- end
-
- # See OutputMethod#puts for more detail.
- def puts(*objs)
- if notify?
- @base_notifier.puts(*objs.collect{|obj| prefix + obj.to_s})
- end
- end
-
- # Same as #ppx, except it uses the #prefix given during object
- # initialization.
- # See OutputMethod#ppx for more detail.
- def pp(*objs)
- if notify?
- @base_notifier.ppx @prefix, *objs
- end
- end
-
- # Same as #pp, except it concatenates the given +prefix+ with the #prefix
- # given during object initialization.
- #
- # See OutputMethod#ppx for more detail.
- def ppx(prefix, *objs)
- if notify?
- @base_notifier.ppx @prefix+prefix, *objs
- end
- end
-
- # Execute the given block if notifications are enabled.
- def exec_if
- yield(@base_notifier) if notify?
- end
- end
-
- # A class that can be used to create a group of notifier objects with the
- # intent of representing a leveled notification system for irb.
- #
- # This class will allow you to generate other notifiers, and assign them
- # the appropriate level for output.
- #
- # The Notifier class provides a class-method Notifier.def_notifier to
- # create a new composite notifier. Using the first composite notifier
- # object you create, sibling notifiers can be initialized with
- # #def_notifier.
- class CompositeNotifier<AbstractNotifier
- # Create a new composite notifier object with the given +prefix+, and
- # +base_notifier+ to use for output.
- def initialize(prefix, base_notifier)
- super
-
- @notifiers = [D_NOMSG]
- @level_notifier = D_NOMSG
- end
-
- # List of notifiers in the group
- attr_reader :notifiers
-
- # Creates a new LeveledNotifier in the composite #notifiers group.
- #
- # The given +prefix+ will be assigned to the notifier, and +level+ will
- # be used as the index of the #notifiers Array.
- #
- # This method returns the newly created instance.
- def def_notifier(level, prefix = "")
- notifier = LeveledNotifier.new(self, level, prefix)
- @notifiers[level] = notifier
- notifier
- end
-
- # Returns the leveled notifier for this object
- attr_reader :level_notifier
- alias level level_notifier
-
- # Sets the leveled notifier for this object.
- #
- # When the given +value+ is an instance of AbstractNotifier,
- # #level_notifier is set to the given object.
- #
- # When an Integer is given, #level_notifier is set to the notifier at the
- # index +value+ in the #notifiers Array.
- #
- # If no notifier exists at the index +value+ in the #notifiers Array, an
- # ErrUndefinedNotifier exception is raised.
- #
- # An ErrUnrecognizedLevel exception is raised if the given +value+ is not
- # found in the existing #notifiers Array, or an instance of
- # AbstractNotifier
- def level_notifier=(value)
- case value
- when AbstractNotifier
- @level_notifier = value
- when Integer
- l = @notifiers[value]
- Notifier.Raise ErrUndefinedNotifier, value unless l
- @level_notifier = l
- else
- Notifier.Raise ErrUnrecognizedLevel, value unless l
- end
- end
-
- alias level= level_notifier=
- end
-
- # A leveled notifier is comparable to the composite group from
- # CompositeNotifier#notifiers.
- class LeveledNotifier<AbstractNotifier
- include Comparable
-
- # Create a new leveled notifier with the given +base+, and +prefix+ to
- # send to AbstractNotifier.new
- #
- # The given +level+ is used to compare other leveled notifiers in the
- # CompositeNotifier group to determine whether or not to output
- # notifications.
- def initialize(base, level, prefix)
- super(prefix, base)
-
- @level = level
- end
-
- # The current level of this notifier object
- attr_reader :level
-
- # Compares the level of this notifier object with the given +other+
- # notifier.
- #
- # See the Comparable module for more information.
- def <=>(other)
- @level <=> other.level
- end
-
- # Whether to output messages to the output method, depending on the level
- # of this notifier object.
- def notify?
- @base_notifier.level >= self
- end
- end
-
- # NoMsgNotifier is a LeveledNotifier that's used as the default notifier
- # when creating a new CompositeNotifier.
- #
- # This notifier is used as the +zero+ index, or level +0+, for
- # CompositeNotifier#notifiers, and will not output messages of any sort.
- class NoMsgNotifier<LeveledNotifier
- # Creates a new notifier that should not be used to output messages.
- def initialize
- @base_notifier = nil
- @level = 0
- @prefix = ""
- end
-
- # Ensures notifications are ignored, see AbstractNotifier#notify? for
- # more information.
- def notify?
- false
- end
- end
-
- D_NOMSG = NoMsgNotifier.new # :nodoc:
- end
-end
diff --git a/ruby_2_2/lib/irb/output-method.rb b/ruby_2_2/lib/irb/output-method.rb
deleted file mode 100644
index e0ba25f3e4..0000000000
--- a/ruby_2_2/lib/irb/output-method.rb
+++ /dev/null
@@ -1,91 +0,0 @@
-#
-# output-method.rb - output methods used by irb
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-require "e2mmap"
-
-module IRB
- # An abstract output class for IO in irb. This is mainly used internally by
- # IRB::Notifier. You can define your own output method to use with Irb.new,
- # or Context.new
- class OutputMethod
- extend Exception2MessageMapper
- def_exception :NotImplementedError, "Need to define `%s'"
-
-
- # Open this method to implement your own output method, raises a
- # NotImplementedError if you don't define #print in your own class.
- def print(*opts)
- OutputMethod.Raise NotImplementedError, "print"
- end
-
- # Prints the given +opts+, with a newline delimiter.
- def printn(*opts)
- print opts.join(" "), "\n"
- end
-
- # Extends IO#printf to format the given +opts+ for Kernel#sprintf using
- # #parse_printf_format
- def printf(format, *opts)
- if /(%*)%I/ =~ format
- format, opts = parse_printf_format(format, opts)
- end
- print sprintf(format, *opts)
- end
-
- # Returns an array of the given +format+ and +opts+ to be used by
- # Kernel#sprintf, if there was a successful Regexp match in the given
- # +format+ from #printf
- #
- # %
- # <flag> [#0- +]
- # <minimum field width> (\*|\*[1-9][0-9]*\$|[1-9][0-9]*)
- # <precision>.(\*|\*[1-9][0-9]*\$|[1-9][0-9]*|)?
- # #<length modifier>(hh|h|l|ll|L|q|j|z|t)
- # <conversion specifier>[diouxXeEfgGcsb%]
- def parse_printf_format(format, opts)
- return format, opts if $1.size % 2 == 1
- end
-
- # Calls #print on each element in the given +objs+, followed by a newline
- # character.
- def puts(*objs)
- for obj in objs
- print(*obj)
- print "\n"
- end
- end
-
- # Prints the given +objs+ calling Object#inspect on each.
- #
- # See #puts for more detail.
- def pp(*objs)
- puts(*objs.collect{|obj| obj.inspect})
- end
-
- # Prints the given +objs+ calling Object#inspect on each and appending the
- # given +prefix+.
- #
- # See #puts for more detail.
- def ppx(prefix, *objs)
- puts(*objs.collect{|obj| prefix+obj.inspect})
- end
-
- end
-
- # A standard output printer
- class StdioOutputMethod<OutputMethod
- # Prints the given +opts+ to standard output, see IO#print for more
- # information.
- def print(*opts)
- STDOUT.print(*opts)
- end
- end
-end
diff --git a/ruby_2_2/lib/irb/ruby-lex.rb b/ruby_2_2/lib/irb/ruby-lex.rb
deleted file mode 100644
index d98c5afa3e..0000000000
--- a/ruby_2_2/lib/irb/ruby-lex.rb
+++ /dev/null
@@ -1,1170 +0,0 @@
-#
-# irb/ruby-lex.rb - ruby lexcal analyzer
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-require "e2mmap"
-require "irb/slex"
-require "irb/ruby-token"
-
-# :stopdoc:
-class RubyLex
-
- extend Exception2MessageMapper
- def_exception(:AlreadyDefinedToken, "Already defined token(%s)")
- def_exception(:TkReading2TokenNoKey, "key nothing(key='%s')")
- def_exception(:TkSymbol2TokenNoKey, "key nothing(key='%s')")
- def_exception(:TkReading2TokenDuplicateError,
- "key duplicate(token_n='%s', key='%s')")
- def_exception(:SyntaxError, "%s")
-
- def_exception(:TerminateLineInput, "Terminate Line Input")
-
- include RubyToken
-
- class << self
- attr_accessor :debug_level
- def debug?
- @debug_level > 0
- end
- end
- @debug_level = 0
-
- def initialize
- lex_init
- set_input(STDIN)
-
- @seek = 0
- @exp_line_no = @line_no = 1
- @base_char_no = 0
- @char_no = 0
- @rests = []
- @readed = []
- @here_readed = []
-
- @indent = 0
- @indent_stack = []
- @lex_state = EXPR_BEG
- @space_seen = false
- @here_header = false
- @post_symbeg = false
-
- @continue = false
- @line = ""
-
- @skip_space = false
- @readed_auto_clean_up = false
- @exception_on_syntax_error = true
-
- @prompt = nil
- end
-
- attr_accessor :skip_space
- attr_accessor :readed_auto_clean_up
- attr_accessor :exception_on_syntax_error
-
- attr_reader :seek
- attr_reader :char_no
- attr_reader :line_no
- attr_reader :indent
-
- # io functions
- def set_input(io, p = nil, &block)
- @io = io
- if p.respond_to?(:call)
- @input = p
- elsif block_given?
- @input = block
- else
- @input = Proc.new{@io.gets}
- end
- end
-
- def get_readed
- if idx = @readed.rindex("\n")
- @base_char_no = @readed.size - (idx + 1)
- else
- @base_char_no += @readed.size
- end
-
- readed = @readed.join("")
- @readed = []
- readed
- end
-
- def getc
- while @rests.empty?
- @rests.push nil unless buf_input
- end
- c = @rests.shift
- if @here_header
- @here_readed.push c
- else
- @readed.push c
- end
- @seek += 1
- if c == "\n"
- @line_no += 1
- @char_no = 0
- else
- @char_no += 1
- end
- c
- end
-
- def gets
- l = ""
- while c = getc
- l.concat(c)
- break if c == "\n"
- end
- return nil if l == "" and c.nil?
- l
- end
-
- def eof?
- @io.eof?
- end
-
- def getc_of_rests
- if @rests.empty?
- nil
- else
- getc
- end
- end
-
- def ungetc(c = nil)
- if @here_readed.empty?
- c2 = @readed.pop
- else
- c2 = @here_readed.pop
- end
- c = c2 unless c
- @rests.unshift c #c =
- @seek -= 1
- if c == "\n"
- @line_no -= 1
- if idx = @readed.rindex("\n")
- @char_no = idx + 1
- else
- @char_no = @base_char_no + @readed.size
- end
- else
- @char_no -= 1
- end
- end
-
- def peek_equal?(str)
- chrs = str.split(//)
- until @rests.size >= chrs.size
- return false unless buf_input
- end
- @rests[0, chrs.size] == chrs
- end
-
- def peek_match?(regexp)
- while @rests.empty?
- return false unless buf_input
- end
- regexp =~ @rests.join("")
- end
-
- def peek(i = 0)
- while @rests.size <= i
- return nil unless buf_input
- end
- @rests[i]
- end
-
- def buf_input
- prompt
- line = @input.call
- return nil unless line
- @rests.concat line.chars.to_a
- true
- end
- private :buf_input
-
- def set_prompt(p = nil, &block)
- p = block if block_given?
- if p.respond_to?(:call)
- @prompt = p
- else
- @prompt = Proc.new{print p}
- end
- end
-
- def prompt
- if @prompt
- @prompt.call(@ltype, @indent, @continue, @line_no)
- end
- end
-
- def initialize_input
- @ltype = nil
- @quoted = nil
- @indent = 0
- @indent_stack = []
- @lex_state = EXPR_BEG
- @space_seen = false
- @here_header = false
-
- @continue = false
- @post_symbeg = false
-
- prompt
-
- @line = ""
- @exp_line_no = @line_no
- end
-
- def each_top_level_statement
- initialize_input
- catch(:TERM_INPUT) do
- loop do
- begin
- @continue = false
- prompt
- unless l = lex
- throw :TERM_INPUT if @line == ''
- else
- @line.concat l
- if @ltype or @continue or @indent > 0
- next
- end
- end
- if @line != "\n"
- @line.force_encoding(@io.encoding)
- yield @line, @exp_line_no
- end
- break unless l
- @line = ''
- @exp_line_no = @line_no
-
- @indent = 0
- @indent_stack = []
- prompt
- rescue TerminateLineInput
- initialize_input
- prompt
- get_readed
- end
- end
- end
- end
-
- def lex
- until (((tk = token).kind_of?(TkNL) || tk.kind_of?(TkEND_OF_SCRIPT)) &&
- !@continue or
- tk.nil?)
- end
- line = get_readed
- if line == "" and tk.kind_of?(TkEND_OF_SCRIPT) || tk.nil?
- nil
- else
- line
- end
- end
-
- def token
- @prev_seek = @seek
- @prev_line_no = @line_no
- @prev_char_no = @char_no
- begin
- begin
- tk = @OP.match(self)
- @space_seen = tk.kind_of?(TkSPACE)
- @lex_state = EXPR_END if @post_symbeg && tk.kind_of?(TkOp)
- @post_symbeg = tk.kind_of?(TkSYMBEG)
- rescue SyntaxError
- raise if @exception_on_syntax_error
- tk = TkError.new(@seek, @line_no, @char_no)
- end
- end while @skip_space and tk.kind_of?(TkSPACE)
- if @readed_auto_clean_up
- get_readed
- end
- tk
- end
-
- ENINDENT_CLAUSE = [
- "case", "class", "def", "do", "for", "if",
- "module", "unless", "until", "while", "begin"
- ]
- DEINDENT_CLAUSE = ["end"
- ]
-
- PERCENT_LTYPE = {
- "q" => "\'",
- "Q" => "\"",
- "x" => "\`",
- "r" => "/",
- "w" => "]",
- "W" => "]",
- "i" => "]",
- "I" => "]",
- "s" => ":"
- }
-
- PERCENT_PAREN = {
- "{" => "}",
- "[" => "]",
- "<" => ">",
- "(" => ")"
- }
-
- Ltype2Token = {
- "\'" => TkSTRING,
- "\"" => TkSTRING,
- "\`" => TkXSTRING,
- "/" => TkREGEXP,
- "]" => TkDSTRING,
- ":" => TkSYMBOL
- }
- DLtype2Token = {
- "\"" => TkDSTRING,
- "\`" => TkDXSTRING,
- "/" => TkDREGEXP,
- }
-
- def lex_init()
- @OP = IRB::SLex.new
- @OP.def_rules("\0", "\004", "\032") do |op, io|
- Token(TkEND_OF_SCRIPT)
- end
-
- @OP.def_rules(" ", "\t", "\f", "\r", "\13") do |op, io|
- @space_seen = true
- while getc =~ /[ \t\f\r\13]/; end
- ungetc
- Token(TkSPACE)
- end
-
- @OP.def_rule("#") do |op, io|
- identify_comment
- end
-
- @OP.def_rule("=begin",
- proc{|op, io| @prev_char_no == 0 && peek(0) =~ /\s/}) do
- |op, io|
- @ltype = "="
- until getc == "\n"; end
- until peek_equal?("=end") && peek(4) =~ /\s/
- until getc == "\n"; end
- end
- gets
- @ltype = nil
- Token(TkRD_COMMENT)
- end
-
- @OP.def_rule("\n") do |op, io|
- print "\\n\n" if RubyLex.debug?
- case @lex_state
- when EXPR_BEG, EXPR_FNAME, EXPR_DOT
- @continue = true
- else
- @continue = false
- @lex_state = EXPR_BEG
- until (@indent_stack.empty? ||
- [TkLPAREN, TkLBRACK, TkLBRACE,
- TkfLPAREN, TkfLBRACK, TkfLBRACE].include?(@indent_stack.last))
- @indent_stack.pop
- end
- end
- @here_header = false
- @here_readed = []
- Token(TkNL)
- end
-
- @OP.def_rules("*", "**",
- "=", "==", "===",
- "=~", "<=>",
- "<", "<=",
- ">", ">=", ">>",
- "!", "!=", "!~") do
- |op, io|
- case @lex_state
- when EXPR_FNAME, EXPR_DOT
- @lex_state = EXPR_ARG
- else
- @lex_state = EXPR_BEG
- end
- Token(op)
- end
-
- @OP.def_rules("<<") do
- |op, io|
- tk = nil
- if @lex_state != EXPR_END && @lex_state != EXPR_CLASS &&
- (@lex_state != EXPR_ARG || @space_seen)
- c = peek(0)
- if /\S/ =~ c && (/["'`]/ =~ c || /\w/ =~ c || c == "-")
- tk = identify_here_document
- end
- end
- unless tk
- tk = Token(op)
- case @lex_state
- when EXPR_FNAME, EXPR_DOT
- @lex_state = EXPR_ARG
- else
- @lex_state = EXPR_BEG
- end
- end
- tk
- end
-
- @OP.def_rules("'", '"') do
- |op, io|
- identify_string(op)
- end
-
- @OP.def_rules("`") do
- |op, io|
- if @lex_state == EXPR_FNAME
- @lex_state = EXPR_END
- Token(op)
- else
- identify_string(op)
- end
- end
-
- @OP.def_rules('?') do
- |op, io|
- if @lex_state == EXPR_END
- @lex_state = EXPR_BEG
- Token(TkQUESTION)
- else
- ch = getc
- if @lex_state == EXPR_ARG && ch =~ /\s/
- ungetc
- @lex_state = EXPR_BEG;
- Token(TkQUESTION)
- else
- if (ch == '\\')
- read_escape
- end
- @lex_state = EXPR_END
- Token(TkINTEGER)
- end
- end
- end
-
- @OP.def_rules("&", "&&", "|", "||") do
- |op, io|
- @lex_state = EXPR_BEG
- Token(op)
- end
-
- @OP.def_rules("+=", "-=", "*=", "**=",
- "&=", "|=", "^=", "<<=", ">>=", "||=", "&&=") do
- |op, io|
- @lex_state = EXPR_BEG
- op =~ /^(.*)=$/
- Token(TkOPASGN, $1)
- end
-
- @OP.def_rule("+@", proc{|op, io| @lex_state == EXPR_FNAME}) do
- |op, io|
- @lex_state = EXPR_ARG
- Token(op)
- end
-
- @OP.def_rule("-@", proc{|op, io| @lex_state == EXPR_FNAME}) do
- |op, io|
- @lex_state = EXPR_ARG
- Token(op)
- end
-
- @OP.def_rules("+", "-") do
- |op, io|
- catch(:RET) do
- if @lex_state == EXPR_ARG
- if @space_seen and peek(0) =~ /[0-9]/
- throw :RET, identify_number
- else
- @lex_state = EXPR_BEG
- end
- elsif @lex_state != EXPR_END and peek(0) =~ /[0-9]/
- throw :RET, identify_number
- else
- @lex_state = EXPR_BEG
- end
- Token(op)
- end
- end
-
- @OP.def_rule(".") do
- |op, io|
- @lex_state = EXPR_BEG
- if peek(0) =~ /[0-9]/
- ungetc
- identify_number
- else
- # for "obj.if" etc.
- @lex_state = EXPR_DOT
- Token(TkDOT)
- end
- end
-
- @OP.def_rules("..", "...") do
- |op, io|
- @lex_state = EXPR_BEG
- Token(op)
- end
-
- lex_int2
- end
-
- def lex_int2
- @OP.def_rules("]", "}", ")") do
- |op, io|
- @lex_state = EXPR_END
- @indent -= 1
- @indent_stack.pop
- Token(op)
- end
-
- @OP.def_rule(":") do
- |op, io|
- if @lex_state == EXPR_END || peek(0) =~ /\s/
- @lex_state = EXPR_BEG
- Token(TkCOLON)
- else
- @lex_state = EXPR_FNAME
- Token(TkSYMBEG)
- end
- end
-
- @OP.def_rule("::") do
- |op, io|
- if @lex_state == EXPR_BEG or @lex_state == EXPR_ARG && @space_seen
- @lex_state = EXPR_BEG
- Token(TkCOLON3)
- else
- @lex_state = EXPR_DOT
- Token(TkCOLON2)
- end
- end
-
- @OP.def_rule("/") do
- |op, io|
- if @lex_state == EXPR_BEG || @lex_state == EXPR_MID
- identify_string(op)
- elsif peek(0) == '='
- getc
- @lex_state = EXPR_BEG
- Token(TkOPASGN, "/") #/)
- elsif @lex_state == EXPR_ARG and @space_seen and peek(0) !~ /\s/
- identify_string(op)
- else
- @lex_state = EXPR_BEG
- Token("/") #/)
- end
- end
-
- @OP.def_rules("^") do
- |op, io|
- @lex_state = EXPR_BEG
- Token("^")
- end
-
- @OP.def_rules(",") do
- |op, io|
- @lex_state = EXPR_BEG
- Token(op)
- end
-
- @OP.def_rules(";") do
- |op, io|
- @lex_state = EXPR_BEG
- until (@indent_stack.empty? ||
- [TkLPAREN, TkLBRACK, TkLBRACE,
- TkfLPAREN, TkfLBRACK, TkfLBRACE].include?(@indent_stack.last))
- @indent_stack.pop
- end
- Token(op)
- end
-
- @OP.def_rule("~") do
- |op, io|
- @lex_state = EXPR_BEG
- Token("~")
- end
-
- @OP.def_rule("~@", proc{|op, io| @lex_state == EXPR_FNAME}) do
- |op, io|
- @lex_state = EXPR_BEG
- Token("~")
- end
-
- @OP.def_rule("(") do
- |op, io|
- @indent += 1
- if @lex_state == EXPR_BEG || @lex_state == EXPR_MID
- @lex_state = EXPR_BEG
- tk_c = TkfLPAREN
- else
- @lex_state = EXPR_BEG
- tk_c = TkLPAREN
- end
- @indent_stack.push tk_c
- Token(tk_c)
- end
-
- @OP.def_rule("[]", proc{|op, io| @lex_state == EXPR_FNAME}) do
- |op, io|
- @lex_state = EXPR_ARG
- Token("[]")
- end
-
- @OP.def_rule("[]=", proc{|op, io| @lex_state == EXPR_FNAME}) do
- |op, io|
- @lex_state = EXPR_ARG
- Token("[]=")
- end
-
- @OP.def_rule("[") do
- |op, io|
- @indent += 1
- if @lex_state == EXPR_FNAME
- tk_c = TkfLBRACK
- else
- if @lex_state == EXPR_BEG || @lex_state == EXPR_MID
- tk_c = TkLBRACK
- elsif @lex_state == EXPR_ARG && @space_seen
- tk_c = TkLBRACK
- else
- tk_c = TkfLBRACK
- end
- @lex_state = EXPR_BEG
- end
- @indent_stack.push tk_c
- Token(tk_c)
- end
-
- @OP.def_rule("{") do
- |op, io|
- @indent += 1
- if @lex_state != EXPR_END && @lex_state != EXPR_ARG
- tk_c = TkLBRACE
- else
- tk_c = TkfLBRACE
- end
- @lex_state = EXPR_BEG
- @indent_stack.push tk_c
- Token(tk_c)
- end
-
- @OP.def_rule('\\') do
- |op, io|
- if getc == "\n"
- @space_seen = true
- @continue = true
- Token(TkSPACE)
- else
- read_escape
- Token("\\")
- end
- end
-
- @OP.def_rule('%') do
- |op, io|
- if @lex_state == EXPR_BEG || @lex_state == EXPR_MID
- identify_quotation
- elsif peek(0) == '='
- getc
- Token(TkOPASGN, :%)
- elsif @lex_state == EXPR_ARG and @space_seen and peek(0) !~ /\s/
- identify_quotation
- else
- @lex_state = EXPR_BEG
- Token("%") #))
- end
- end
-
- @OP.def_rule('$') do
- |op, io|
- identify_gvar
- end
-
- @OP.def_rule('@') do
- |op, io|
- if peek(0) =~ /[\w@]/
- ungetc
- identify_identifier
- else
- Token("@")
- end
- end
-
- @OP.def_rule("") do
- |op, io|
- printf "MATCH: start %s: %s\n", op, io.inspect if RubyLex.debug?
- if peek(0) =~ /[0-9]/
- t = identify_number
- elsif peek(0) =~ /[^\x00-\/:-@\[-^`{-\x7F]/
- t = identify_identifier
- end
- printf "MATCH: end %s: %s\n", op, io.inspect if RubyLex.debug?
- t
- end
-
- p @OP if RubyLex.debug?
- end
-
- def identify_gvar
- @lex_state = EXPR_END
-
- case ch = getc
- when /[~_*$?!@\/\\;,=:<>".]/ #"
- Token(TkGVAR, "$" + ch)
- when "-"
- Token(TkGVAR, "$-" + getc)
- when "&", "`", "'", "+"
- Token(TkBACK_REF, "$"+ch)
- when /[1-9]/
- while getc =~ /[0-9]/; end
- ungetc
- Token(TkNTH_REF)
- when /\w/
- ungetc
- ungetc
- identify_identifier
- else
- ungetc
- Token("$")
- end
- end
-
- def identify_identifier
- token = ""
- if peek(0) =~ /[$@]/
- token.concat(c = getc)
- if c == "@" and peek(0) == "@"
- token.concat getc
- end
- end
-
- while (ch = getc) =~ /[^\x00-\/:-@\[-^`{-\x7F]/
- print ":", ch, ":" if RubyLex.debug?
- token.concat ch
- end
- ungetc
-
- if (ch == "!" || ch == "?") && token[0,1] =~ /\w/ && peek(0) != "="
- token.concat getc
- end
-
- # almost fix token
-
- case token
- when /^\$/
- return Token(TkGVAR, token)
- when /^\@\@/
- @lex_state = EXPR_END
- # p Token(TkCVAR, token)
- return Token(TkCVAR, token)
- when /^\@/
- @lex_state = EXPR_END
- return Token(TkIVAR, token)
- end
-
- if @lex_state != EXPR_DOT
- print token, "\n" if RubyLex.debug?
-
- token_c, *trans = TkReading2Token[token]
- if token_c
- # reserved word?
-
- if (@lex_state != EXPR_BEG &&
- @lex_state != EXPR_FNAME &&
- trans[1])
- # modifiers
- token_c = TkSymbol2Token[trans[1]]
- @lex_state = trans[0]
- else
- if @lex_state != EXPR_FNAME and peek(0) != ':'
- if ENINDENT_CLAUSE.include?(token)
- # check for ``class = val'' etc.
- valid = true
- case token
- when "class"
- valid = false unless peek_match?(/^\s*(<<|\w|::)/)
- when "def"
- valid = false if peek_match?(/^\s*(([+\-\/*&\|^]|<<|>>|\|\||\&\&)=|\&\&|\|\|)/)
- when "do"
- valid = false if peek_match?(/^\s*([+\-\/*]?=|\*|<|>|\&)/)
- when *ENINDENT_CLAUSE
- valid = false if peek_match?(/^\s*([+\-\/*]?=|\*|<|>|\&|\|)/)
- else
- # no nothing
- end
- if valid
- if token == "do"
- if ![TkFOR, TkWHILE, TkUNTIL].include?(@indent_stack.last)
- @indent += 1
- @indent_stack.push token_c
- end
- else
- @indent += 1
- @indent_stack.push token_c
- end
- end
-
- elsif DEINDENT_CLAUSE.include?(token)
- @indent -= 1
- @indent_stack.pop
- end
- @lex_state = trans[0]
- else
- @lex_state = EXPR_END
- end
- end
- return Token(token_c, token)
- end
- end
-
- if @lex_state == EXPR_FNAME
- @lex_state = EXPR_END
- if peek(0) == '='
- token.concat getc
- end
- elsif @lex_state == EXPR_BEG || @lex_state == EXPR_DOT
- @lex_state = EXPR_ARG
- else
- @lex_state = EXPR_END
- end
-
- if token[0, 1] =~ /[A-Z]/
- return Token(TkCONSTANT, token)
- elsif token[token.size - 1, 1] =~ /[!?]/
- return Token(TkFID, token)
- else
- return Token(TkIDENTIFIER, token)
- end
- end
-
- def identify_here_document
- ch = getc
- if ch == "-"
- ch = getc
- indent = true
- end
- if /['"`]/ =~ ch
- lt = ch
- quoted = ""
- while (c = getc) && c != lt
- quoted.concat c
- end
- else
- lt = '"'
- quoted = ch.dup
- while (c = getc) && c =~ /\w/
- quoted.concat c
- end
- ungetc
- end
-
- ltback, @ltype = @ltype, lt
- reserve = []
- while ch = getc
- reserve.push ch
- if ch == "\\"
- reserve.push ch = getc
- elsif ch == "\n"
- break
- end
- end
-
- @here_header = false
-
- line = ""
- while ch = getc
- if ch == "\n"
- if line == quoted
- break
- end
- line = ""
- else
- line.concat ch unless indent && line == "" && /\s/ =~ ch
- if @ltype != "'" && ch == "#" && peek(0) == "{"
- identify_string_dvar
- end
- end
- end
-
- @here_header = true
- @here_readed.concat reserve
- while ch = reserve.pop
- ungetc ch
- end
-
- @ltype = ltback
- @lex_state = EXPR_END
- Token(Ltype2Token[lt])
- end
-
- def identify_quotation
- ch = getc
- if lt = PERCENT_LTYPE[ch]
- ch = getc
- elsif ch =~ /\W/
- lt = "\""
- else
- RubyLex.fail SyntaxError, "unknown type of %string"
- end
- @quoted = ch unless @quoted = PERCENT_PAREN[ch]
- identify_string(lt, @quoted)
- end
-
- def identify_number
- @lex_state = EXPR_END
-
- if peek(0) == "0" && peek(1) !~ /[.eE]/
- getc
- case peek(0)
- when /[xX]/
- ch = getc
- match = /[0-9a-fA-F_]/
- when /[bB]/
- ch = getc
- match = /[01_]/
- when /[oO]/
- ch = getc
- match = /[0-7_]/
- when /[dD]/
- ch = getc
- match = /[0-9_]/
- when /[0-7]/
- match = /[0-7_]/
- when /[89]/
- RubyLex.fail SyntaxError, "Invalid octal digit"
- else
- return Token(TkINTEGER)
- end
-
- len0 = true
- non_digit = false
- while ch = getc
- if match =~ ch
- if ch == "_"
- if non_digit
- RubyLex.fail SyntaxError, "trailing `#{ch}' in number"
- else
- non_digit = ch
- end
- else
- non_digit = false
- len0 = false
- end
- else
- ungetc
- if len0
- RubyLex.fail SyntaxError, "numeric literal without digits"
- end
- if non_digit
- RubyLex.fail SyntaxError, "trailing `#{non_digit}' in number"
- end
- break
- end
- end
- return Token(TkINTEGER)
- end
-
- type = TkINTEGER
- allow_point = true
- allow_e = true
- non_digit = false
- while ch = getc
- case ch
- when /[0-9]/
- non_digit = false
- when "_"
- non_digit = ch
- when allow_point && "."
- if non_digit
- RubyLex.fail SyntaxError, "trailing `#{non_digit}' in number"
- end
- type = TkFLOAT
- if peek(0) !~ /[0-9]/
- type = TkINTEGER
- ungetc
- break
- end
- allow_point = false
- when allow_e && "e", allow_e && "E"
- if non_digit
- RubyLex.fail SyntaxError, "trailing `#{non_digit}' in number"
- end
- type = TkFLOAT
- if peek(0) =~ /[+-]/
- getc
- end
- allow_e = false
- allow_point = false
- non_digit = ch
- else
- if non_digit
- RubyLex.fail SyntaxError, "trailing `#{non_digit}' in number"
- end
- ungetc
- break
- end
- end
- Token(type)
- end
-
- def identify_string(ltype, quoted = ltype)
- @ltype = ltype
- @quoted = quoted
- subtype = nil
- begin
- nest = 0
- while ch = getc
- if @quoted == ch and nest == 0
- break
- elsif @ltype != "'" && ch == "#" && peek(0) == "{"
- identify_string_dvar
- elsif @ltype != "'" && @ltype != "]" && @ltype != ":" and ch == "#"
- subtype = true
- elsif ch == '\\' and @ltype == "'" #'
- case ch = getc
- when "\\", "\n", "'"
- else
- ungetc
- end
- elsif ch == '\\' #'
- read_escape
- end
- if PERCENT_PAREN.values.include?(@quoted)
- if PERCENT_PAREN[ch] == @quoted
- nest += 1
- elsif ch == @quoted
- nest -= 1
- end
- end
- end
- if @ltype == "/"
- while /[imxoesun]/ =~ peek(0)
- getc
- end
- end
- if subtype
- Token(DLtype2Token[ltype])
- else
- Token(Ltype2Token[ltype])
- end
- ensure
- @ltype = nil
- @quoted = nil
- @lex_state = EXPR_END
- end
- end
-
- def identify_string_dvar
- begin
- getc
-
- reserve_continue = @continue
- reserve_ltype = @ltype
- reserve_indent = @indent
- reserve_indent_stack = @indent_stack
- reserve_state = @lex_state
- reserve_quoted = @quoted
-
- @ltype = nil
- @quoted = nil
- @indent = 0
- @indent_stack = []
- @lex_state = EXPR_BEG
-
- loop do
- @continue = false
- prompt
- tk = token
- if @ltype or @continue or @indent >= 0
- next
- end
- break if tk.kind_of?(TkRBRACE)
- end
- ensure
- @continue = reserve_continue
- @ltype = reserve_ltype
- @indent = reserve_indent
- @indent_stack = reserve_indent_stack
- @lex_state = reserve_state
- @quoted = reserve_quoted
- end
- end
-
- def identify_comment
- @ltype = "#"
-
- while ch = getc
- if ch == "\n"
- @ltype = nil
- ungetc
- break
- end
- end
- return Token(TkCOMMENT)
- end
-
- def read_escape
- case ch = getc
- when "\n", "\r", "\f"
- when "\\", "n", "t", "r", "f", "v", "a", "e", "b", "s" #"
- when /[0-7]/
- ungetc ch
- 3.times do
- case ch = getc
- when /[0-7]/
- when nil
- break
- else
- ungetc
- break
- end
- end
-
- when "x"
- 2.times do
- case ch = getc
- when /[0-9a-fA-F]/
- when nil
- break
- else
- ungetc
- break
- end
- end
-
- when "M"
- if (ch = getc) != '-'
- ungetc
- else
- if (ch = getc) == "\\" #"
- read_escape
- end
- end
-
- when "C", "c" #, "^"
- if ch == "C" and (ch = getc) != "-"
- ungetc
- elsif (ch = getc) == "\\" #"
- read_escape
- end
- else
- # other characters
- end
- end
-end
-# :startdoc:
diff --git a/ruby_2_2/lib/irb/ruby-token.rb b/ruby_2_2/lib/irb/ruby-token.rb
deleted file mode 100644
index a80d81c9a5..0000000000
--- a/ruby_2_2/lib/irb/ruby-token.rb
+++ /dev/null
@@ -1,266 +0,0 @@
-#
-# irb/ruby-token.rb - ruby tokens
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-# :stopdoc:
-module RubyToken
- EXPR_BEG = :EXPR_BEG
- EXPR_MID = :EXPR_MID
- EXPR_END = :EXPR_END
- EXPR_ARG = :EXPR_ARG
- EXPR_FNAME = :EXPR_FNAME
- EXPR_DOT = :EXPR_DOT
- EXPR_CLASS = :EXPR_CLASS
-
- class Token
- def initialize(seek, line_no, char_no)
- @seek = seek
- @line_no = line_no
- @char_no = char_no
- end
- attr_reader :seek, :line_no, :char_no
- end
-
- class TkNode < Token
- def initialize(seek, line_no, char_no)
- super
- end
- attr_reader :node
- end
-
- class TkId < Token
- def initialize(seek, line_no, char_no, name)
- super(seek, line_no, char_no)
- @name = name
- end
- attr_reader :name
- end
-
- class TkVal < Token
- def initialize(seek, line_no, char_no, value = nil)
- super(seek, line_no, char_no)
- @value = value
- end
- attr_reader :value
- end
-
- class TkOp < Token
- attr_accessor :name
- end
-
- class TkOPASGN < TkOp
- def initialize(seek, line_no, char_no, op)
- super(seek, line_no, char_no)
- op = TkReading2Token[op][0] unless op.kind_of?(Symbol)
- @op = op
- end
- attr_reader :op
- end
-
- class TkUnknownChar < Token
- def initialize(seek, line_no, char_no, id)
- super(seek, line_no, char_no)
- @name = name
- end
- attr_reader :name
- end
-
- class TkError < Token
- end
-
- def Token(token, value = nil)
- case token
- when String
- if (tk = TkReading2Token[token]).nil?
- IRB.fail TkReading2TokenNoKey, token
- end
- tk = Token(tk[0], value)
- if tk.kind_of?(TkOp)
- tk.name = token
- end
- return tk
- when Symbol
- if (tk = TkSymbol2Token[token]).nil?
- IRB.fail TkSymbol2TokenNoKey, token
- end
- return Token(tk[0], value)
- else
- if (token.ancestors & [TkId, TkVal, TkOPASGN, TkUnknownChar]).empty?
- token.new(@prev_seek, @prev_line_no, @prev_char_no)
- else
- token.new(@prev_seek, @prev_line_no, @prev_char_no, value)
- end
- end
- end
-
- TokenDefinitions = [
- [:TkCLASS, TkId, "class", EXPR_CLASS],
- [:TkMODULE, TkId, "module", EXPR_BEG],
- [:TkDEF, TkId, "def", EXPR_FNAME],
- [:TkUNDEF, TkId, "undef", EXPR_FNAME],
- [:TkBEGIN, TkId, "begin", EXPR_BEG],
- [:TkRESCUE, TkId, "rescue", EXPR_MID],
- [:TkENSURE, TkId, "ensure", EXPR_BEG],
- [:TkEND, TkId, "end", EXPR_END],
- [:TkIF, TkId, "if", EXPR_BEG, :TkIF_MOD],
- [:TkUNLESS, TkId, "unless", EXPR_BEG, :TkUNLESS_MOD],
- [:TkTHEN, TkId, "then", EXPR_BEG],
- [:TkELSIF, TkId, "elsif", EXPR_BEG],
- [:TkELSE, TkId, "else", EXPR_BEG],
- [:TkCASE, TkId, "case", EXPR_BEG],
- [:TkWHEN, TkId, "when", EXPR_BEG],
- [:TkWHILE, TkId, "while", EXPR_BEG, :TkWHILE_MOD],
- [:TkUNTIL, TkId, "until", EXPR_BEG, :TkUNTIL_MOD],
- [:TkFOR, TkId, "for", EXPR_BEG],
- [:TkBREAK, TkId, "break", EXPR_END],
- [:TkNEXT, TkId, "next", EXPR_END],
- [:TkREDO, TkId, "redo", EXPR_END],
- [:TkRETRY, TkId, "retry", EXPR_END],
- [:TkIN, TkId, "in", EXPR_BEG],
- [:TkDO, TkId, "do", EXPR_BEG],
- [:TkRETURN, TkId, "return", EXPR_MID],
- [:TkYIELD, TkId, "yield", EXPR_END],
- [:TkSUPER, TkId, "super", EXPR_END],
- [:TkSELF, TkId, "self", EXPR_END],
- [:TkNIL, TkId, "nil", EXPR_END],
- [:TkTRUE, TkId, "true", EXPR_END],
- [:TkFALSE, TkId, "false", EXPR_END],
- [:TkAND, TkId, "and", EXPR_BEG],
- [:TkOR, TkId, "or", EXPR_BEG],
- [:TkNOT, TkId, "not", EXPR_BEG],
- [:TkIF_MOD, TkId],
- [:TkUNLESS_MOD, TkId],
- [:TkWHILE_MOD, TkId],
- [:TkUNTIL_MOD, TkId],
- [:TkALIAS, TkId, "alias", EXPR_FNAME],
- [:TkDEFINED, TkId, "defined?", EXPR_END],
- [:TklBEGIN, TkId, "BEGIN", EXPR_END],
- [:TklEND, TkId, "END", EXPR_END],
- [:Tk__LINE__, TkId, "__LINE__", EXPR_END],
- [:Tk__FILE__, TkId, "__FILE__", EXPR_END],
-
- [:TkIDENTIFIER, TkId],
- [:TkFID, TkId],
- [:TkGVAR, TkId],
- [:TkCVAR, TkId],
- [:TkIVAR, TkId],
- [:TkCONSTANT, TkId],
-
- [:TkINTEGER, TkVal],
- [:TkFLOAT, TkVal],
- [:TkSTRING, TkVal],
- [:TkXSTRING, TkVal],
- [:TkREGEXP, TkVal],
- [:TkSYMBOL, TkVal],
-
- [:TkDSTRING, TkNode],
- [:TkDXSTRING, TkNode],
- [:TkDREGEXP, TkNode],
- [:TkNTH_REF, TkNode],
- [:TkBACK_REF, TkNode],
-
- [:TkUPLUS, TkOp, "+@"],
- [:TkUMINUS, TkOp, "-@"],
- [:TkPOW, TkOp, "**"],
- [:TkCMP, TkOp, "<=>"],
- [:TkEQ, TkOp, "=="],
- [:TkEQQ, TkOp, "==="],
- [:TkNEQ, TkOp, "!="],
- [:TkGEQ, TkOp, ">="],
- [:TkLEQ, TkOp, "<="],
- [:TkANDOP, TkOp, "&&"],
- [:TkOROP, TkOp, "||"],
- [:TkMATCH, TkOp, "=~"],
- [:TkNMATCH, TkOp, "!~"],
- [:TkDOT2, TkOp, ".."],
- [:TkDOT3, TkOp, "..."],
- [:TkAREF, TkOp, "[]"],
- [:TkASET, TkOp, "[]="],
- [:TkLSHFT, TkOp, "<<"],
- [:TkRSHFT, TkOp, ">>"],
- [:TkCOLON2, TkOp],
- [:TkCOLON3, TkOp],
- [:TkASSOC, TkOp, "=>"],
- [:TkQUESTION, TkOp, "?"], #?
- [:TkCOLON, TkOp, ":"], #:
-
- [:TkfLPAREN], # func( #
- [:TkfLBRACK], # func[ #
- [:TkfLBRACE], # func{ #
- [:TkSTAR], # *arg
- [:TkAMPER], # &arg #
- [:TkSYMBEG], # :SYMBOL
-
- [:TkGT, TkOp, ">"],
- [:TkLT, TkOp, "<"],
- [:TkPLUS, TkOp, "+"],
- [:TkMINUS, TkOp, "-"],
- [:TkMULT, TkOp, "*"],
- [:TkDIV, TkOp, "/"],
- [:TkMOD, TkOp, "%"],
- [:TkBITOR, TkOp, "|"],
- [:TkBITXOR, TkOp, "^"],
- [:TkBITAND, TkOp, "&"],
- [:TkBITNOT, TkOp, "~"],
- [:TkNOTOP, TkOp, "!"],
-
- [:TkBACKQUOTE, TkOp, "`"],
-
- [:TkASSIGN, Token, "="],
- [:TkDOT, Token, "."],
- [:TkLPAREN, Token, "("], #(exp)
- [:TkLBRACK, Token, "["], #[arry]
- [:TkLBRACE, Token, "{"], #{hash}
- [:TkRPAREN, Token, ")"],
- [:TkRBRACK, Token, "]"],
- [:TkRBRACE, Token, "}"],
- [:TkCOMMA, Token, ","],
- [:TkSEMICOLON, Token, ";"],
-
- [:TkCOMMENT],
- [:TkRD_COMMENT],
- [:TkSPACE],
- [:TkNL],
- [:TkEND_OF_SCRIPT],
-
- [:TkBACKSLASH, TkUnknownChar, "\\"],
- [:TkAT, TkUnknownChar, "@"],
- [:TkDOLLAR, TkUnknownChar, "$"],
- ]
-
- # {reading => token_class}
- # {reading => [token_class, *opt]}
- TkReading2Token = {}
- TkSymbol2Token = {}
-
- def RubyToken.def_token(token_n, super_token = Token, reading = nil, *opts)
- token_n = token_n.id2name if token_n.kind_of?(Symbol)
- if RubyToken.const_defined?(token_n)
- IRB.fail AlreadyDefinedToken, token_n
- end
- token_c = eval("class #{token_n} < #{super_token}; end; #{token_n}")
-
- if reading
- if TkReading2Token[reading]
- IRB.fail TkReading2TokenDuplicateError, token_n, reading
- end
- if opts.empty?
- TkReading2Token[reading] = [token_c]
- else
- TkReading2Token[reading] = [token_c].concat(opts)
- end
- end
- TkSymbol2Token[token_n.intern] = token_c
- end
-
- for defs in TokenDefinitions
- def_token(*defs)
- end
-end
-# :startdoc:
diff --git a/ruby_2_2/lib/irb/slex.rb b/ruby_2_2/lib/irb/slex.rb
deleted file mode 100644
index f6c2bd92f5..0000000000
--- a/ruby_2_2/lib/irb/slex.rb
+++ /dev/null
@@ -1,281 +0,0 @@
-#
-# irb/slex.rb - simple lex analyzer
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-require "e2mmap"
-require "irb/notifier"
-
-# :stopdoc:
-module IRB
- class SLex
-
- extend Exception2MessageMapper
- def_exception :ErrNodeNothing, "node nothing"
- def_exception :ErrNodeAlreadyExists, "node already exists"
-
- DOUT = Notifier::def_notifier("SLex::")
- D_WARN = DOUT::def_notifier(1, "Warn: ")
- D_DEBUG = DOUT::def_notifier(2, "Debug: ")
- D_DETAIL = DOUT::def_notifier(4, "Detail: ")
-
- DOUT.level = Notifier::D_NOMSG
-
- def initialize
- @head = Node.new("")
- end
-
- def def_rule(token, preproc = nil, postproc = nil, &block)
- D_DETAIL.pp token
-
- postproc = block if block_given?
- create(token, preproc, postproc)
- end
-
- def def_rules(*tokens, &block)
- if block_given?
- p = block
- end
- for token in tokens
- def_rule(token, nil, p)
- end
- end
-
- def preproc(token, proc)
- node = search(token)
- node.preproc=proc
- end
-
- #$BMW%A%'%C%/(B?
- def postproc(token)
- node = search(token, proc)
- node.postproc=proc
- end
-
- def search(token)
- @head.search(token.split(//))
- end
-
- def create(token, preproc = nil, postproc = nil)
- @head.create_subnode(token.split(//), preproc, postproc)
- end
-
- def match(token)
- case token
- when Array
- when String
- return match(token.split(//))
- else
- return @head.match_io(token)
- end
- ret = @head.match(token)
- D_DETAIL.exec_if{D_DETAIL.printf "match end: %s:%s\n", ret, token.inspect}
- ret
- end
-
- def inspect
- format("<SLex: @head = %s>", @head.inspect)
- end
-
- #----------------------------------------------------------------------
- #
- # class Node -
- #
- #----------------------------------------------------------------------
- class Node
- # if postproc is nil, this node is an abstract node.
- # if postproc is non-nil, this node is a real node.
- def initialize(preproc = nil, postproc = nil)
- @Tree = {}
- @preproc = preproc
- @postproc = postproc
- end
-
- attr_accessor :preproc
- attr_accessor :postproc
-
- def search(chrs, opt = nil)
- return self if chrs.empty?
- ch = chrs.shift
- if node = @Tree[ch]
- node.search(chrs, opt)
- else
- if opt
- chrs.unshift ch
- self.create_subnode(chrs)
- else
- SLex.fail ErrNodeNothing
- end
- end
- end
-
- def create_subnode(chrs, preproc = nil, postproc = nil)
- if chrs.empty?
- if @postproc
- D_DETAIL.pp node
- SLex.fail ErrNodeAlreadyExists
- else
- D_DEBUG.puts "change abstract node to real node."
- @preproc = preproc
- @postproc = postproc
- end
- return self
- end
-
- ch = chrs.shift
- if node = @Tree[ch]
- if chrs.empty?
- if node.postproc
- DebugLogger.pp node
- DebugLogger.pp self
- DebugLogger.pp ch
- DebugLogger.pp chrs
- SLex.fail ErrNodeAlreadyExists
- else
- D_WARN.puts "change abstract node to real node"
- node.preproc = preproc
- node.postproc = postproc
- end
- else
- node.create_subnode(chrs, preproc, postproc)
- end
- else
- if chrs.empty?
- node = Node.new(preproc, postproc)
- else
- node = Node.new
- node.create_subnode(chrs, preproc, postproc)
- end
- @Tree[ch] = node
- end
- node
- end
-
- #
- # chrs: String
- # character array
- # io must have getc()/ungetc(); and ungetc() must be
- # able to be called arbitrary number of times.
- #
- def match(chrs, op = "")
- D_DETAIL.print "match>: ", chrs, "op:", op, "\n"
- if chrs.empty?
- if @preproc.nil? || @preproc.call(op, chrs)
- DOUT.printf(D_DETAIL, "op1: %s\n", op)
- @postproc.call(op, chrs)
- else
- nil
- end
- else
- ch = chrs.shift
- if node = @Tree[ch]
- if ret = node.match(chrs, op+ch)
- return ret
- else
- chrs.unshift ch
- if @postproc and @preproc.nil? || @preproc.call(op, chrs)
- DOUT.printf(D_DETAIL, "op2: %s\n", op.inspect)
- ret = @postproc.call(op, chrs)
- return ret
- else
- return nil
- end
- end
- else
- chrs.unshift ch
- if @postproc and @preproc.nil? || @preproc.call(op, chrs)
- DOUT.printf(D_DETAIL, "op3: %s\n", op)
- @postproc.call(op, chrs)
- return ""
- else
- return nil
- end
- end
- end
- end
-
- def match_io(io, op = "")
- if op == ""
- ch = io.getc
- if ch == nil
- return nil
- end
- else
- ch = io.getc_of_rests
- end
- if ch.nil?
- if @preproc.nil? || @preproc.call(op, io)
- D_DETAIL.printf("op1: %s\n", op)
- @postproc.call(op, io)
- else
- nil
- end
- else
- if node = @Tree[ch]
- if ret = node.match_io(io, op+ch)
- ret
- else
- io.ungetc ch
- if @postproc and @preproc.nil? || @preproc.call(op, io)
- DOUT.exec_if{D_DETAIL.printf "op2: %s\n", op.inspect}
- @postproc.call(op, io)
- else
- nil
- end
- end
- else
- io.ungetc ch
- if @postproc and @preproc.nil? || @preproc.call(op, io)
- D_DETAIL.printf("op3: %s\n", op)
- @postproc.call(op, io)
- else
- nil
- end
- end
- end
- end
- end
- end
-end
-# :startdoc:
-
-if $0 == __FILE__
- case $1
- when "1"
- tr = SLex.new
- print "0: ", tr.inspect, "\n"
- tr.def_rule("=") {print "=\n"}
- print "1: ", tr.inspect, "\n"
- tr.def_rule("==") {print "==\n"}
- print "2: ", tr.inspect, "\n"
-
- print "case 1:\n"
- print tr.match("="), "\n"
- print "case 2:\n"
- print tr.match("=="), "\n"
- print "case 3:\n"
- print tr.match("=>"), "\n"
-
- when "2"
- tr = SLex.new
- print "0: ", tr.inspect, "\n"
- tr.def_rule("=") {print "=\n"}
- print "1: ", tr.inspect, "\n"
- tr.def_rule("==", proc{false}) {print "==\n"}
- print "2: ", tr.inspect, "\n"
-
- print "case 1:\n"
- print tr.match("="), "\n"
- print "case 2:\n"
- print tr.match("=="), "\n"
- print "case 3:\n"
- print tr.match("=>"), "\n"
- end
- exit
-end
diff --git a/ruby_2_2/lib/irb/src_encoding.rb b/ruby_2_2/lib/irb/src_encoding.rb
deleted file mode 100644
index 958cef104c..0000000000
--- a/ruby_2_2/lib/irb/src_encoding.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-# DO NOT WRITE ANY MAGIC COMMENT HERE.
-def default_src_encoding
- return __ENCODING__
-end
diff --git a/ruby_2_2/lib/irb/version.rb b/ruby_2_2/lib/irb/version.rb
deleted file mode 100644
index bb998db3dd..0000000000
--- a/ruby_2_2/lib/irb/version.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-#
-# irb/version.rb - irb version definition file
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ishitsuka.com)
-#
-# --
-#
-#
-#
-
-module IRB # :nodoc:
- @RELEASE_VERSION = "0.9.6"
- @LAST_UPDATE_DATE = "09/06/30"
-end
diff --git a/ruby_2_2/lib/irb/workspace.rb b/ruby_2_2/lib/irb/workspace.rb
deleted file mode 100644
index e05c3bbc96..0000000000
--- a/ruby_2_2/lib/irb/workspace.rb
+++ /dev/null
@@ -1,114 +0,0 @@
-#
-# irb/workspace-binding.rb -
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-module IRB # :nodoc:
- class WorkSpace
- # Creates a new workspace.
- #
- # set self to main if specified, otherwise
- # inherit main from TOPLEVEL_BINDING.
- def initialize(*main)
- if main[0].kind_of?(Binding)
- @binding = main.shift
- elsif IRB.conf[:SINGLE_IRB]
- @binding = TOPLEVEL_BINDING
- else
- case IRB.conf[:CONTEXT_MODE]
- when 0 # binding in proc on TOPLEVEL_BINDING
- @binding = eval("proc{binding}.call",
- TOPLEVEL_BINDING,
- __FILE__,
- __LINE__)
- when 1 # binding in loaded file
- require "tempfile"
- f = Tempfile.open("irb-binding")
- f.print <<EOF
- $binding = binding
-EOF
- f.close
- load f.path
- @binding = $binding
-
- when 2 # binding in loaded file(thread use)
- unless defined? BINDING_QUEUE
- require "thread"
-
- IRB.const_set(:BINDING_QUEUE, SizedQueue.new(1))
- Thread.abort_on_exception = true
- Thread.start do
- eval "require \"irb/ws-for-case-2\"", TOPLEVEL_BINDING, __FILE__, __LINE__
- end
- Thread.pass
- end
- @binding = BINDING_QUEUE.pop
-
- when 3 # binding in function on TOPLEVEL_BINDING(default)
- @binding = eval("def irb_binding; private; binding; end; irb_binding",
- TOPLEVEL_BINDING,
- __FILE__,
- __LINE__ - 3)
- end
- end
- if main.empty?
- @main = eval("self", @binding)
- else
- @main = main[0]
- IRB.conf[:__MAIN__] = @main
- case @main
- when Module
- @binding = eval("IRB.conf[:__MAIN__].module_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
- else
- begin
- @binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
- rescue TypeError
- IRB.fail CantChangeBinding, @main.inspect
- end
- end
- end
- eval("_=nil", @binding)
- end
-
- # The Binding of this workspace
- attr_reader :binding
- # The top-level workspace of this context, also available as
- # <code>IRB.conf[:__MAIN__]</code>
- attr_reader :main
-
- # Evaluate the given +statements+ within the context of this workspace.
- def evaluate(context, statements, file = __FILE__, line = __LINE__)
- eval(statements, @binding, file, line)
- end
-
- # error message manipulator
- def filter_backtrace(bt)
- case IRB.conf[:CONTEXT_MODE]
- when 0
- return nil if bt =~ /\(irb_local_binding\)/
- when 1
- if(bt =~ %r!/tmp/irb-binding! or
- bt =~ %r!irb/.*\.rb! or
- bt =~ /irb\.rb/)
- return nil
- end
- when 2
- return nil if bt =~ /irb\/.*\.rb/
- return nil if bt =~ /irb\.rb/
- when 3
- return nil if bt =~ /irb\/.*\.rb/
- return nil if bt =~ /irb\.rb/
- bt = bt.sub(/:\s*in `irb_binding'/, '')
- end
- bt
- end
-
- def IRB.delete_caller
- end
- end
-end
diff --git a/ruby_2_2/lib/irb/ws-for-case-2.rb b/ruby_2_2/lib/irb/ws-for-case-2.rb
deleted file mode 100644
index 9f3af49f30..0000000000
--- a/ruby_2_2/lib/irb/ws-for-case-2.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-#
-# irb/ws-for-case-2.rb -
-# $Release Version: 0.9.6$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-while true
- IRB::BINDING_QUEUE.push _ = binding
-end
diff --git a/ruby_2_2/lib/irb/xmp.rb b/ruby_2_2/lib/irb/xmp.rb
deleted file mode 100644
index 449f04328b..0000000000
--- a/ruby_2_2/lib/irb/xmp.rb
+++ /dev/null
@@ -1,169 +0,0 @@
-#
-# xmp.rb - irb version of gotoken xmp
-# $Release Version: 0.9$
-# $Revision$
-# by Keiju ISHITSUKA(Nippon Rational Inc.)
-#
-# --
-#
-#
-#
-
-require "irb"
-require "irb/frame"
-
-# An example printer for irb.
-#
-# It's much like the standard library PrettyPrint, that shows the value of each
-# expression as it runs.
-#
-# In order to use this library, you must first require it:
-#
-# require 'irb/xmp'
-#
-# Now, you can take advantage of the Object#xmp convenience method.
-#
-# xmp <<END
-# foo = "bar"
-# baz = 42
-# END
-# #=> foo = "bar"
-# #==>"bar"
-# #=> baz = 42
-# #==>42
-#
-# You can also create an XMP object, with an optional binding to print
-# expressions in the given binding:
-#
-# ctx = binding
-# x = XMP.new ctx
-# x.puts
-# #=> today = "a good day"
-# #==>"a good day"
-# ctx.eval 'today # is what?'
-# #=> "a good day"
-class XMP
-
- # Creates a new XMP object.
- #
- # The top-level binding or, optional +bind+ parameter will be used when
- # creating the workspace. See WorkSpace.new for more information.
- #
- # This uses the +:XMP+ prompt mode, see IRB@Customizing+the+IRB+Prompt for
- # full detail.
- def initialize(bind = nil)
- IRB.init_config(nil)
-
- IRB.conf[:PROMPT_MODE] = :XMP
-
- bind = IRB::Frame.top(1) unless bind
- ws = IRB::WorkSpace.new(bind)
- @io = StringInputMethod.new
- @irb = IRB::Irb.new(ws, @io)
- @irb.context.ignore_sigint = false
-
- IRB.conf[:MAIN_CONTEXT] = @irb.context
- end
-
- # Evaluates the given +exps+, for example:
- #
- # require 'irb/xmp'
- # x = XMP.new
- #
- # x.puts '{:a => 1, :b => 2, :c => 3}'
- # #=> {:a => 1, :b => 2, :c => 3}
- # # ==>{:a=>1, :b=>2, :c=>3}
- # x.puts 'foo = "bar"'
- # # => foo = "bar"
- # # ==>"bar"
- def puts(exps)
- @io.puts exps
-
- if @irb.context.ignore_sigint
- begin
- trap_proc_b = trap("SIGINT"){@irb.signal_handle}
- catch(:IRB_EXIT) do
- @irb.eval_input
- end
- ensure
- trap("SIGINT", trap_proc_b)
- end
- else
- catch(:IRB_EXIT) do
- @irb.eval_input
- end
- end
- end
-
- # A custom InputMethod class used by XMP for evaluating string io.
- class StringInputMethod < IRB::InputMethod
- # Creates a new StringInputMethod object
- def initialize
- super
- @exps = []
- end
-
- # Whether there are any expressions left in this printer.
- def eof?
- @exps.empty?
- end
-
- # Reads the next expression from this printer.
- #
- # See IO#gets for more information.
- def gets
- while l = @exps.shift
- next if /^\s+$/ =~ l
- l.concat "\n"
- print @prompt, l
- break
- end
- l
- end
-
- # Concatenates all expressions in this printer, separated by newlines.
- #
- # An Encoding::CompatibilityError is raised of the given +exps+'s encoding
- # doesn't match the previous expression evaluated.
- def puts(exps)
- if @encoding and exps.encoding != @encoding
- enc = Encoding.compatible?(@exps.join("\n"), exps)
- if enc.nil?
- raise Encoding::CompatibilityError, "Encoding in which the passed expression is encoded is not compatible to the preceding's one"
- else
- @encoding = enc
- end
- else
- @encoding = exps.encoding
- end
- @exps.concat exps.split(/\n/)
- end
-
- # Returns the encoding of last expression printed by #puts.
- attr_reader :encoding
- end
-end
-
-# A convenience method that's only available when the you require the IRB::XMP standard library.
-#
-# Creates a new XMP object, using the given expressions as the +exps+
-# parameter, and optional binding as +bind+ or uses the top-level binding. Then
-# evaluates the given expressions using the +:XMP+ prompt mode.
-#
-# For example:
-#
-# require 'irb/xmp'
-# ctx = binding
-# xmp 'foo = "bar"', ctx
-# #=> foo = "bar"
-# #==>"bar"
-# ctx.eval 'foo'
-# #=> "bar"
-#
-# See XMP.new for more information.
-def xmp(exps, bind = nil)
- bind = IRB::Frame.top(1) unless bind
- xmp = XMP.new(bind)
- xmp.puts exps
- xmp
-end
diff --git a/ruby_2_2/lib/logger.rb b/ruby_2_2/lib/logger.rb
deleted file mode 100644
index 09c8943c94..0000000000
--- a/ruby_2_2/lib/logger.rb
+++ /dev/null
@@ -1,737 +0,0 @@
-# logger.rb - simple logging utility
-# Copyright (C) 2000-2003, 2005, 2008, 2011 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
-#
-# Documentation:: NAKAMURA, Hiroshi and Gavin Sinclair
-# License::
-# You can redistribute it and/or modify it under the same terms of Ruby's
-# license; either the dual license version in 2003, or any later version.
-# Revision:: $Id$
-#
-# A simple system for logging messages. See Logger for more documentation.
-
-require 'monitor'
-
-# == Description
-#
-# The Logger class provides a simple but sophisticated logging utility that
-# you can use to output messages.
-#
-# The messages have associated levels, such as +INFO+ or +ERROR+ that indicate
-# their importance. You can then give the Logger a level, and only messages
-# at that level or higher will be printed.
-#
-# The levels are:
-#
-# +UNKNOWN+:: An unknown message that should always be logged.
-# +FATAL+:: An unhandleable error that results in a program crash.
-# +ERROR+:: A handleable error condition.
-# +WARN+:: A warning.
-# +INFO+:: Generic (useful) information about system operation.
-# +DEBUG+:: Low-level information for developers.
-#
-# For instance, in a production system, you may have your Logger set to
-# +INFO+ or even +WARN+.
-# When you are developing the system, however, you probably
-# want to know about the program's internal state, and would set the Logger to
-# +DEBUG+.
-#
-# *Note*: Logger does not escape or sanitize any messages passed to it.
-# Developers should be aware of when potentially malicious data (user-input)
-# is passed to Logger, and manually escape the untrusted data:
-#
-# logger.info("User-input: #{input.dump}")
-# logger.info("User-input: %p" % input)
-#
-# You can use #formatter= for escaping all data.
-#
-# original_formatter = Logger::Formatter.new
-# logger.formatter = proc { |severity, datetime, progname, msg|
-# original_formatter.call(severity, datetime, progname, msg.dump)
-# }
-# logger.info(input)
-#
-# === Example
-#
-# This creates a Logger that outputs to the standard output stream, with a
-# level of +WARN+:
-#
-# require 'logger'
-#
-# logger = Logger.new(STDOUT)
-# logger.level = Logger::WARN
-#
-# logger.debug("Created logger")
-# logger.info("Program started")
-# logger.warn("Nothing to do!")
-#
-# path = "a_non_existent_file"
-#
-# begin
-# File.foreach(path) do |line|
-# unless line =~ /^(\w+) = (.*)$/
-# logger.error("Line in wrong format: #{line.chomp}")
-# end
-# end
-# rescue => err
-# logger.fatal("Caught exception; exiting")
-# logger.fatal(err)
-# end
-#
-# Because the Logger's level is set to +WARN+, only the warning, error, and
-# fatal messages are recorded. The debug and info messages are silently
-# discarded.
-#
-# === Features
-#
-# There are several interesting features that Logger provides, like
-# auto-rolling of log files, setting the format of log messages, and
-# specifying a program name in conjunction with the message. The next section
-# shows you how to achieve these things.
-#
-#
-# == HOWTOs
-#
-# === How to create a logger
-#
-# The options below give you various choices, in more or less increasing
-# complexity.
-#
-# 1. Create a logger which logs messages to STDERR/STDOUT.
-#
-# logger = Logger.new(STDERR)
-# logger = Logger.new(STDOUT)
-#
-# 2. Create a logger for the file which has the specified name.
-#
-# logger = Logger.new('logfile.log')
-#
-# 3. Create a logger for the specified file.
-#
-# file = File.open('foo.log', File::WRONLY | File::APPEND)
-# # To create new (and to remove old) logfile, add File::CREAT like:
-# # file = File.open('foo.log', File::WRONLY | File::APPEND | File::CREAT)
-# logger = Logger.new(file)
-#
-# 4. Create a logger which ages the logfile once it reaches a certain size.
-# Leave 10 "old" log files where each file is about 1,024,000 bytes.
-#
-# logger = Logger.new('foo.log', 10, 1024000)
-#
-# 5. Create a logger which ages the logfile daily/weekly/monthly.
-#
-# logger = Logger.new('foo.log', 'daily')
-# logger = Logger.new('foo.log', 'weekly')
-# logger = Logger.new('foo.log', 'monthly')
-#
-# === How to log a message
-#
-# Notice the different methods (+fatal+, +error+, +info+) being used to log
-# messages of various levels? Other methods in this family are +warn+ and
-# +debug+. +add+ is used below to log a message of an arbitrary (perhaps
-# dynamic) level.
-#
-# 1. Message in a block.
-#
-# logger.fatal { "Argument 'foo' not given." }
-#
-# 2. Message as a string.
-#
-# logger.error "Argument #{@foo} mismatch."
-#
-# 3. With progname.
-#
-# logger.info('initialize') { "Initializing..." }
-#
-# 4. With severity.
-#
-# logger.add(Logger::FATAL) { 'Fatal error!' }
-#
-# The block form allows you to create potentially complex log messages,
-# but to delay their evaluation until and unless the message is
-# logged. For example, if we have the following:
-#
-# logger.debug { "This is a " + potentially + " expensive operation" }
-#
-# If the logger's level is +INFO+ or higher, no debug messages will be logged,
-# and the entire block will not even be evaluated. Compare to this:
-#
-# logger.debug("This is a " + potentially + " expensive operation")
-#
-# Here, the string concatenation is done every time, even if the log
-# level is not set to show the debug message.
-#
-# === How to close a logger
-#
-# logger.close
-#
-# === Setting severity threshold
-#
-# 1. Original interface.
-#
-# logger.sev_threshold = Logger::WARN
-#
-# 2. Log4r (somewhat) compatible interface.
-#
-# logger.level = Logger::INFO
-#
-# # DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN
-#
-# == Format
-#
-# Log messages are rendered in the output stream in a certain format by
-# default. The default format and a sample are shown below:
-#
-# Log format:
-# SeverityID, [DateTime #pid] SeverityLabel -- ProgName: message
-#
-# Log sample:
-# I, [1999-03-03T02:34:24.895701 #19074] INFO -- Main: info.
-#
-# You may change the date and time format via #datetime_format=.
-#
-# logger.datetime_format = '%Y-%m-%d %H:%M:%S'
-# # e.g. "2004-01-03 00:54:26"
-#
-# Or, you may change the overall format via the #formatter= method.
-#
-# logger.formatter = proc do |severity, datetime, progname, msg|
-# "#{datetime}: #{msg}\n"
-# end
-# # e.g. "2005-09-22 08:51:08 +0900: hello world"
-#
-class Logger
- VERSION = "1.2.7"
- _, name, rev = %w$Id$
- if name
- name = name.chomp(",v")
- else
- name = File.basename(__FILE__)
- end
- rev ||= "v#{VERSION}"
- ProgName = "#{name}/#{rev}"
-
- class Error < RuntimeError # :nodoc:
- end
- # not used after 1.2.7. just for compat.
- class ShiftingError < Error # :nodoc:
- end
-
- # Logging severity.
- module Severity
- # Low-level information, mostly for developers.
- DEBUG = 0
- # Generic (useful) information about system operation.
- INFO = 1
- # A warning.
- WARN = 2
- # A handleable error condition.
- ERROR = 3
- # An unhandleable error that results in a program crash.
- FATAL = 4
- # An unknown message that should always be logged.
- UNKNOWN = 5
- end
- include Severity
-
- # Logging severity threshold (e.g. <tt>Logger::INFO</tt>).
- attr_accessor :level
-
- # Program name to include in log messages.
- attr_accessor :progname
-
- # Set date-time format.
- #
- # +datetime_format+:: A string suitable for passing to +strftime+.
- def datetime_format=(datetime_format)
- @default_formatter.datetime_format = datetime_format
- end
-
- # Returns the date format being used. See #datetime_format=
- def datetime_format
- @default_formatter.datetime_format
- end
-
- # Logging formatter, as a +Proc+ that will take four arguments and
- # return the formatted message. The arguments are:
- #
- # +severity+:: The Severity of the log message.
- # +time+:: A Time instance representing when the message was logged.
- # +progname+:: The #progname configured, or passed to the logger method.
- # +msg+:: The _Object_ the user passed to the log message; not necessarily a
- # String.
- #
- # The block should return an Object that can be written to the logging
- # device via +write+. The default formatter is used when no formatter is
- # set.
- attr_accessor :formatter
-
- alias sev_threshold level
- alias sev_threshold= level=
-
- # Returns +true+ iff the current severity level allows for the printing of
- # +DEBUG+ messages.
- def debug?; @level <= DEBUG; end
-
- # Returns +true+ iff the current severity level allows for the printing of
- # +INFO+ messages.
- def info?; @level <= INFO; end
-
- # Returns +true+ iff the current severity level allows for the printing of
- # +WARN+ messages.
- def warn?; @level <= WARN; end
-
- # Returns +true+ iff the current severity level allows for the printing of
- # +ERROR+ messages.
- def error?; @level <= ERROR; end
-
- # Returns +true+ iff the current severity level allows for the printing of
- # +FATAL+ messages.
- def fatal?; @level <= FATAL; end
-
- #
- # :call-seq:
- # Logger.new(logdev, shift_age = 7, shift_size = 1048576)
- # Logger.new(logdev, shift_age = 'weekly')
- #
- # === Args
- #
- # +logdev+::
- # The log device. This is a filename (String) or IO object (typically
- # +STDOUT+, +STDERR+, or an open file).
- # +shift_age+::
- # Number of old log files to keep, *or* frequency of rotation (+daily+,
- # +weekly+ or +monthly+).
- # +shift_size+::
- # Maximum logfile size (only applies when +shift_age+ is a number).
- #
- # === Description
- #
- # Create an instance.
- #
- def initialize(logdev, shift_age = 0, shift_size = 1048576)
- @progname = nil
- @level = DEBUG
- @default_formatter = Formatter.new
- @formatter = nil
- @logdev = nil
- if logdev
- @logdev = LogDevice.new(logdev, :shift_age => shift_age,
- :shift_size => shift_size)
- end
- end
-
- #
- # :call-seq:
- # Logger#add(severity, message = nil, progname = nil) { ... }
- #
- # === Args
- #
- # +severity+::
- # Severity. Constants are defined in Logger namespace: +DEBUG+, +INFO+,
- # +WARN+, +ERROR+, +FATAL+, or +UNKNOWN+.
- # +message+::
- # The log message. A String or Exception.
- # +progname+::
- # Program name string. Can be omitted. Treated as a message if no
- # +message+ and +block+ are given.
- # +block+::
- # Can be omitted. Called to get a message string if +message+ is nil.
- #
- # === Return
- #
- # When the given severity is not high enough (for this particular logger),
- # log no message, and return +true+.
- #
- # === Description
- #
- # Log a message if the given severity is high enough. This is the generic
- # logging method. Users will be more inclined to use #debug, #info, #warn,
- # #error, and #fatal.
- #
- # <b>Message format</b>: +message+ can be any object, but it has to be
- # converted to a String in order to log it. Generally, +inspect+ is used
- # if the given object is not a String.
- # A special case is an +Exception+ object, which will be printed in detail,
- # including message, class, and backtrace. See #msg2str for the
- # implementation if required.
- #
- # === Bugs
- #
- # * Logfile is not locked.
- # * Append open does not need to lock file.
- # * If the OS supports multi I/O, records possibly may be mixed.
- #
- def add(severity, message = nil, progname = nil)
- severity ||= UNKNOWN
- if @logdev.nil? or severity < @level
- return true
- end
- progname ||= @progname
- if message.nil?
- if block_given?
- message = yield
- else
- message = progname
- progname = @progname
- end
- end
- @logdev.write(
- format_message(format_severity(severity), Time.now, progname, message))
- true
- end
- alias log add
-
- #
- # Dump given message to the log device without any formatting. If no log
- # device exists, return +nil+.
- #
- def <<(msg)
- unless @logdev.nil?
- @logdev.write(msg)
- end
- end
-
- #
- # Log a +DEBUG+ message.
- #
- # See #info for more information.
- #
- def debug(progname = nil, &block)
- add(DEBUG, nil, progname, &block)
- end
-
- #
- # :call-seq:
- # info(message)
- # info(progname, &block)
- #
- # Log an +INFO+ message.
- #
- # +message+:: The message to log; does not need to be a String.
- # +progname+:: In the block form, this is the #progname to use in the
- # log message. The default can be set with #progname=.
- # +block+:: Evaluates to the message to log. This is not evaluated unless
- # the logger's level is sufficient to log the message. This
- # allows you to create potentially expensive logging messages that
- # are only called when the logger is configured to show them.
- #
- # === Examples
- #
- # logger.info("MainApp") { "Received connection from #{ip}" }
- # # ...
- # logger.info "Waiting for input from user"
- # # ...
- # logger.info { "User typed #{input}" }
- #
- # You'll probably stick to the second form above, unless you want to provide a
- # program name (which you can do with #progname= as well).
- #
- # === Return
- #
- # See #add.
- #
- def info(progname = nil, &block)
- add(INFO, nil, progname, &block)
- end
-
- #
- # Log a +WARN+ message.
- #
- # See #info for more information.
- #
- def warn(progname = nil, &block)
- add(WARN, nil, progname, &block)
- end
-
- #
- # Log an +ERROR+ message.
- #
- # See #info for more information.
- #
- def error(progname = nil, &block)
- add(ERROR, nil, progname, &block)
- end
-
- #
- # Log a +FATAL+ message.
- #
- # See #info for more information.
- #
- def fatal(progname = nil, &block)
- add(FATAL, nil, progname, &block)
- end
-
- #
- # Log an +UNKNOWN+ message. This will be printed no matter what the logger's
- # level is.
- #
- # See #info for more information.
- #
- def unknown(progname = nil, &block)
- add(UNKNOWN, nil, progname, &block)
- end
-
- #
- # Close the logging device.
- #
- def close
- @logdev.close if @logdev
- end
-
-private
-
- # Severity label for logging (max 5 chars).
- SEV_LABEL = %w(DEBUG INFO WARN ERROR FATAL ANY)
-
- def format_severity(severity)
- SEV_LABEL[severity] || 'ANY'
- end
-
- def format_message(severity, datetime, progname, msg)
- (@formatter || @default_formatter).call(severity, datetime, progname, msg)
- end
-
-
- # Default formatter for log messages.
- class Formatter
- Format = "%s, [%s#%d] %5s -- %s: %s\n"
-
- attr_accessor :datetime_format
-
- def initialize
- @datetime_format = nil
- end
-
- def call(severity, time, progname, msg)
- Format % [severity[0..0], format_datetime(time), $$, severity, progname,
- msg2str(msg)]
- end
-
- private
-
- def format_datetime(time)
- time.strftime(@datetime_format || "%Y-%m-%dT%H:%M:%S.%6N ".freeze)
- end
-
- def msg2str(msg)
- case msg
- when ::String
- msg
- when ::Exception
- "#{ msg.message } (#{ msg.class })\n" <<
- (msg.backtrace || []).join("\n")
- else
- msg.inspect
- end
- end
- end
-
- module Period
- module_function
-
- SiD = 24 * 60 * 60
-
- def next_rotate_time(now, shift_age)
- case shift_age
- when /^daily$/
- t = Time.mktime(now.year, now.month, now.mday) + SiD
- when /^weekly$/
- t = Time.mktime(now.year, now.month, now.mday) + SiD * (7 - now.wday)
- when /^monthly$/
- t = Time.mktime(now.year, now.month, 1) + SiD * 32
- mday = 1
- else
- return now
- end
- if mday or t.hour.nonzero? or t.min.nonzero? or t.sec.nonzero?
- t = Time.mktime(t.year, t.month, mday || (t.mday + (t.hour > 12 ? 1 : 0)))
- end
- t
- end
-
- def previous_period_end(now, shift_age)
- case shift_age
- when /^daily$/
- t = Time.mktime(now.year, now.month, now.mday) - SiD / 2
- when /^weekly$/
- t = Time.mktime(now.year, now.month, now.mday) - (SiD * (now.wday + 1) + SiD / 2)
- when /^monthly$/
- t = Time.mktime(now.year, now.month, 1) - SiD / 2
- else
- return now
- end
- Time.mktime(t.year, t.month, t.mday, 23, 59, 59)
- end
- end
-
- # Device used for logging messages.
- class LogDevice
- include Period
-
- attr_reader :dev
- attr_reader :filename
-
- class LogDeviceMutex
- include MonitorMixin
- end
-
- def initialize(log = nil, opt = {})
- @dev = @filename = @shift_age = @shift_size = nil
- @mutex = LogDeviceMutex.new
- if log.respond_to?(:write) and log.respond_to?(:close)
- @dev = log
- else
- @dev = open_logfile(log)
- @dev.sync = true
- @filename = log
- @shift_age = opt[:shift_age] || 7
- @shift_size = opt[:shift_size] || 1048576
- @next_rotate_time = next_rotate_time(Time.now, @shift_age) unless @shift_age.is_a?(Integer)
- end
- end
-
- def write(message)
- begin
- @mutex.synchronize do
- if @shift_age and @dev.respond_to?(:stat)
- begin
- check_shift_log
- rescue
- warn("log shifting failed. #{$!}")
- end
- end
- begin
- @dev.write(message)
- rescue
- warn("log writing failed. #{$!}")
- end
- end
- rescue Exception => ignored
- warn("log writing failed. #{ignored}")
- end
- end
-
- def close
- begin
- @mutex.synchronize do
- @dev.close rescue nil
- end
- rescue Exception
- @dev.close rescue nil
- end
- end
-
- private
-
- def open_logfile(filename)
- begin
- open(filename, (File::WRONLY | File::APPEND))
- rescue Errno::ENOENT
- create_logfile(filename)
- end
- end
-
- def create_logfile(filename)
- begin
- logdev = open(filename, (File::WRONLY | File::APPEND | File::CREAT | File::EXCL))
- logdev.flock(File::LOCK_EX)
- logdev.sync = true
- add_log_header(logdev)
- logdev.flock(File::LOCK_UN)
- rescue Errno::EEXIST
- # file is created by another process
- logdev = open_logfile(filename)
- logdev.sync = true
- end
- logdev
- end
-
- def add_log_header(file)
- file.write(
- "# Logfile created on %s by %s\n" % [Time.now.to_s, Logger::ProgName]
- ) if file.size == 0
- end
-
- def check_shift_log
- if @shift_age.is_a?(Integer)
- # Note: always returns false if '0'.
- if @filename && (@shift_age > 0) && (@dev.stat.size > @shift_size)
- lock_shift_log { shift_log_age }
- end
- else
- now = Time.now
- if now >= @next_rotate_time
- @next_rotate_time = next_rotate_time(now, @shift_age)
- lock_shift_log { shift_log_period(previous_period_end(now, @shift_age)) }
- end
- end
- end
-
- if /mswin|mingw/ =~ RUBY_PLATFORM
- def lock_shift_log
- yield
- end
- else
- def lock_shift_log
- retry_limit = 8
- retry_sleep = 0.1
- begin
- File.open(@filename, File::WRONLY | File::APPEND) do |lock|
- lock.flock(File::LOCK_EX) # inter-process locking. will be unlocked at closing file
- if File.identical?(@filename, lock) and File.identical?(lock, @dev)
- yield # log shifting
- else
- # log shifted by another process (i-node before locking and i-node after locking are different)
- @dev.close rescue nil
- @dev = open_logfile(@filename)
- @dev.sync = true
- end
- end
- rescue Errno::ENOENT
- # @filename file would not exist right after #rename and before #create_logfile
- if retry_limit <= 0
- warn("log rotation inter-process lock failed. #{$!}")
- else
- sleep retry_sleep
- retry_limit -= 1
- retry_sleep *= 2
- retry
- end
- end
- rescue
- warn("log rotation inter-process lock failed. #{$!}")
- end
- end
-
- def shift_log_age
- (@shift_age-3).downto(0) do |i|
- if FileTest.exist?("#{@filename}.#{i}")
- File.rename("#{@filename}.#{i}", "#{@filename}.#{i+1}")
- end
- end
- @dev.close rescue nil
- File.rename("#{@filename}", "#{@filename}.0")
- @dev = create_logfile(@filename)
- return true
- end
-
- def shift_log_period(period_end)
- postfix = period_end.strftime("%Y%m%d") # YYYYMMDD
- age_file = "#{@filename}.#{postfix}"
- if FileTest.exist?(age_file)
- # try to avoid filename crash caused by Timestamp change.
- idx = 0
- # .99 can be overridden; avoid too much file search with 'loop do'
- while idx < 100
- idx += 1
- age_file = "#{@filename}.#{postfix}.#{idx}"
- break unless FileTest.exist?(age_file)
- end
- end
- @dev.close rescue nil
- File.rename("#{@filename}", age_file)
- @dev = create_logfile(@filename)
- return true
- end
- end
-end
diff --git a/ruby_2_2/lib/mathn.rb b/ruby_2_2/lib/mathn.rb
deleted file mode 100644
index 315e5438d7..0000000000
--- a/ruby_2_2/lib/mathn.rb
+++ /dev/null
@@ -1,191 +0,0 @@
-#--
-# $Release Version: 0.5 $
-# $Revision: 1.1.1.1.4.1 $
-
-##
-# = mathn
-#
-# mathn serves to make mathematical operations more precise in Ruby
-# and to integrate other mathematical standard libraries.
-#
-# Without mathn:
-#
-# 3 / 2 => 1 # Integer
-#
-# With mathn:
-#
-# 3 / 2 => 3/2 # Rational
-#
-# mathn keeps value in exact terms.
-#
-# Without mathn:
-#
-# 20 / 9 * 3 * 14 / 7 * 3 / 2 # => 18
-#
-# With mathn:
-#
-# 20 / 9 * 3 * 14 / 7 * 3 / 2 # => 20
-#
-#
-# When you require 'mathn', the libraries for Prime, CMath, Matrix and Vector
-# are also loaded.
-#
-# == Copyright
-#
-# Author: Keiju ISHITSUKA (SHL Japan Inc.)
-#--
-# class Numeric follows to make this documentation findable in a reasonable
-# location
-
-warn('lib/mathn.rb is deprecated') if $VERBOSE
-
-class Numeric; end
-
-require "cmath.rb"
-require "matrix.rb"
-require "prime.rb"
-
-require "mathn/rational"
-require "mathn/complex"
-
-unless defined?(Math.exp!)
- Object.instance_eval{remove_const :Math}
- Math = CMath # :nodoc:
-end
-
-##
-# When mathn is required, Fixnum's division is enhanced to
-# return more precise values from mathematical expressions.
-#
-# 2/3*3 # => 0
-# require 'mathn'
-# 2/3*3 # => 2
-
-class Fixnum
- remove_method :/
-
- ##
- # +/+ defines the Rational division for Fixnum.
- #
- # 1/3 # => (1/3)
-
- alias / quo
-end
-
-##
-# When mathn is required Bignum's division is enhanced to
-# return more precise values from mathematical expressions.
-#
-# (2**72) / ((2**70) * 3) # => 4/3
-
-class Bignum
- remove_method :/
-
- ##
- # +/+ defines the Rational division for Bignum.
- #
- # (2**72) / ((2**70) * 3) # => 4/3
-
- alias / quo
-end
-
-##
-# When mathn is required, the Math module changes as follows:
-#
-# Standard Math module behaviour:
-# Math.sqrt(4/9) # => 0.0
-# Math.sqrt(4.0/9.0) # => 0.666666666666667
-# Math.sqrt(- 4/9) # => Errno::EDOM: Numerical argument out of domain - sqrt
-#
-# After require 'mathn', this is changed to:
-#
-# require 'mathn'
-# Math.sqrt(4/9) # => 2/3
-# Math.sqrt(4.0/9.0) # => 0.666666666666667
-# Math.sqrt(- 4/9) # => Complex(0, 2/3)
-
-module Math
- remove_method(:sqrt)
-
- ##
- # Computes the square root of +a+. It makes use of Complex and
- # Rational to have no rounding errors if possible.
- #
- # Math.sqrt(4/9) # => 2/3
- # Math.sqrt(- 4/9) # => Complex(0, 2/3)
- # Math.sqrt(4.0/9.0) # => 0.666666666666667
-
- def sqrt(a)
- if a.kind_of?(Complex)
- abs = sqrt(a.real*a.real + a.imag*a.imag)
- x = sqrt((a.real + abs)/Rational(2))
- y = sqrt((-a.real + abs)/Rational(2))
- if a.imag >= 0
- Complex(x, y)
- else
- Complex(x, -y)
- end
- elsif a.respond_to?(:nan?) and a.nan?
- a
- elsif a >= 0
- rsqrt(a)
- else
- Complex(0,rsqrt(-a))
- end
- end
-
- ##
- # Compute square root of a non negative number. This method is
- # internally used by +Math.sqrt+.
-
- def rsqrt(a)
- if a.kind_of?(Float)
- sqrt!(a)
- elsif a.kind_of?(Rational)
- rsqrt(a.numerator)/rsqrt(a.denominator)
- else
- src = a
- max = 2 ** 32
- byte_a = [src & 0xffffffff]
- # ruby's bug
- while (src >= max) and (src >>= 32)
- byte_a.unshift src & 0xffffffff
- end
-
- answer = 0
- main = 0
- side = 0
- for elm in byte_a
- main = (main << 32) + elm
- side <<= 16
- if answer != 0
- if main * 4 < side * side
- applo = main.div(side)
- else
- applo = ((sqrt!(side * side + 4 * main) - side)/2.0).to_i + 1
- end
- else
- applo = sqrt!(main).to_i + 1
- end
-
- while (x = (side + applo) * applo) > main
- applo -= 1
- end
- main -= x
- answer = (answer << 16) + applo
- side += applo * 2
- end
- if main == 0
- answer
- else
- sqrt!(a)
- end
- end
- end
-
- class << self
- remove_method(:sqrt)
- end
- module_function :sqrt
- module_function :rsqrt
-end
diff --git a/ruby_2_2/lib/matrix.rb b/ruby_2_2/lib/matrix.rb
deleted file mode 100644
index fb98d09323..0000000000
--- a/ruby_2_2/lib/matrix.rb
+++ /dev/null
@@ -1,2161 +0,0 @@
-# encoding: utf-8
-#
-# = matrix.rb
-#
-# An implementation of Matrix and Vector classes.
-#
-# See classes Matrix and Vector for documentation.
-#
-# Current Maintainer:: Marc-André Lafortune
-# Original Author:: Keiju ISHITSUKA
-# Original Documentation:: Gavin Sinclair (sourced from <i>Ruby in a Nutshell</i> (Matsumoto, O'Reilly))
-##
-
-require "e2mmap.rb"
-
-module ExceptionForMatrix # :nodoc:
- extend Exception2MessageMapper
- def_e2message(TypeError, "wrong argument type %s (expected %s)")
- def_e2message(ArgumentError, "Wrong # of arguments(%d for %d)")
-
- def_exception("ErrDimensionMismatch", "\#{self.name} dimension mismatch")
- def_exception("ErrNotRegular", "Not Regular Matrix")
- def_exception("ErrOperationNotDefined", "Operation(%s) can\\'t be defined: %s op %s")
- def_exception("ErrOperationNotImplemented", "Sorry, Operation(%s) not implemented: %s op %s")
-end
-
-#
-# The +Matrix+ class represents a mathematical matrix. It provides methods for creating
-# matrices, operating on them arithmetically and algebraically,
-# and determining their mathematical properties (trace, rank, inverse, determinant).
-#
-# == Method Catalogue
-#
-# To create a matrix:
-# * Matrix[*rows]
-# * Matrix.[](*rows)
-# * Matrix.rows(rows, copy = true)
-# * Matrix.columns(columns)
-# * Matrix.build(row_count, column_count, &block)
-# * Matrix.diagonal(*values)
-# * Matrix.scalar(n, value)
-# * Matrix.identity(n)
-# * Matrix.unit(n)
-# * Matrix.I(n)
-# * Matrix.zero(n)
-# * Matrix.row_vector(row)
-# * Matrix.column_vector(column)
-# * Matrix.hstack(*matrices)
-# * Matrix.vstack(*matrices)
-#
-# To access Matrix elements/columns/rows/submatrices/properties:
-# * #[](i, j)
-# * #row_count (row_size)
-# * #column_count (column_size)
-# * #row(i)
-# * #column(j)
-# * #collect
-# * #map
-# * #each
-# * #each_with_index
-# * #find_index
-# * #minor(*param)
-# * #first_minor(row, column)
-# * #cofactor(row, column)
-# * #adjugate
-# * #laplace_expansion(row_or_column: num)
-# * #cofactor_expansion(row_or_column: num)
-#
-# Properties of a matrix:
-# * #diagonal?
-# * #empty?
-# * #hermitian?
-# * #lower_triangular?
-# * #normal?
-# * #orthogonal?
-# * #permutation?
-# * #real?
-# * #regular?
-# * #singular?
-# * #square?
-# * #symmetric?
-# * #unitary?
-# * #upper_triangular?
-# * #zero?
-#
-# Matrix arithmetic:
-# * #*(m)
-# * #+(m)
-# * #-(m)
-# * #/(m)
-# * #inverse
-# * #inv
-# * #**
-# * #+@
-# * #-@
-#
-# Matrix functions:
-# * #determinant
-# * #det
-# * #hstack(*matrices)
-# * #rank
-# * #round
-# * #trace
-# * #tr
-# * #transpose
-# * #t
-# * #vstack(*matrices)
-#
-# Matrix decompositions:
-# * #eigen
-# * #eigensystem
-# * #lup
-# * #lup_decomposition
-#
-# Complex arithmetic:
-# * conj
-# * conjugate
-# * imag
-# * imaginary
-# * real
-# * rect
-# * rectangular
-#
-# Conversion to other data types:
-# * #coerce(other)
-# * #row_vectors
-# * #column_vectors
-# * #to_a
-#
-# String representations:
-# * #to_s
-# * #inspect
-#
-class Matrix
- include Enumerable
- include ExceptionForMatrix
- autoload :EigenvalueDecomposition, "matrix/eigenvalue_decomposition"
- autoload :LUPDecomposition, "matrix/lup_decomposition"
-
- # instance creations
- private_class_method :new
- attr_reader :rows
- protected :rows
-
- #
- # Creates a matrix where each argument is a row.
- # Matrix[ [25, 93], [-1, 66] ]
- # => 25 93
- # -1 66
- #
- def Matrix.[](*rows)
- rows(rows, false)
- end
-
- #
- # Creates a matrix where +rows+ is an array of arrays, each of which is a row
- # of the matrix. If the optional argument +copy+ is false, use the given
- # arrays as the internal structure of the matrix without copying.
- # Matrix.rows([[25, 93], [-1, 66]])
- # => 25 93
- # -1 66
- #
- def Matrix.rows(rows, copy = true)
- rows = convert_to_array(rows, copy)
- rows.map! do |row|
- convert_to_array(row, copy)
- end
- size = (rows[0] || []).size
- rows.each do |row|
- raise ErrDimensionMismatch, "row size differs (#{row.size} should be #{size})" unless row.size == size
- end
- new rows, size
- end
-
- #
- # Creates a matrix using +columns+ as an array of column vectors.
- # Matrix.columns([[25, 93], [-1, 66]])
- # => 25 -1
- # 93 66
- #
- def Matrix.columns(columns)
- rows(columns, false).transpose
- end
-
- #
- # Creates a matrix of size +row_count+ x +column_count+.
- # It fills the values by calling the given block,
- # passing the current row and column.
- # Returns an enumerator if no block is given.
- #
- # m = Matrix.build(2, 4) {|row, col| col - row }
- # => Matrix[[0, 1, 2, 3], [-1, 0, 1, 2]]
- # m = Matrix.build(3) { rand }
- # => a 3x3 matrix with random elements
- #
- def Matrix.build(row_count, column_count = row_count)
- row_count = CoercionHelper.coerce_to_int(row_count)
- column_count = CoercionHelper.coerce_to_int(column_count)
- raise ArgumentError if row_count < 0 || column_count < 0
- return to_enum :build, row_count, column_count unless block_given?
- rows = Array.new(row_count) do |i|
- Array.new(column_count) do |j|
- yield i, j
- end
- end
- new rows, column_count
- end
-
- #
- # Creates a matrix where the diagonal elements are composed of +values+.
- # Matrix.diagonal(9, 5, -3)
- # => 9 0 0
- # 0 5 0
- # 0 0 -3
- #
- def Matrix.diagonal(*values)
- size = values.size
- return Matrix.empty if size == 0
- rows = Array.new(size) {|j|
- row = Array.new(size, 0)
- row[j] = values[j]
- row
- }
- new rows
- end
-
- #
- # Creates an +n+ by +n+ diagonal matrix where each diagonal element is
- # +value+.
- # Matrix.scalar(2, 5)
- # => 5 0
- # 0 5
- #
- def Matrix.scalar(n, value)
- diagonal(*Array.new(n, value))
- end
-
- #
- # Creates an +n+ by +n+ identity matrix.
- # Matrix.identity(2)
- # => 1 0
- # 0 1
- #
- def Matrix.identity(n)
- scalar(n, 1)
- end
- class << Matrix
- alias unit identity
- alias I identity
- end
-
- #
- # Creates a zero matrix.
- # Matrix.zero(2)
- # => 0 0
- # 0 0
- #
- def Matrix.zero(row_count, column_count = row_count)
- rows = Array.new(row_count){Array.new(column_count, 0)}
- new rows, column_count
- end
-
- #
- # Creates a single-row matrix where the values of that row are as given in
- # +row+.
- # Matrix.row_vector([4,5,6])
- # => 4 5 6
- #
- def Matrix.row_vector(row)
- row = convert_to_array(row)
- new [row]
- end
-
- #
- # Creates a single-column matrix where the values of that column are as given
- # in +column+.
- # Matrix.column_vector([4,5,6])
- # => 4
- # 5
- # 6
- #
- def Matrix.column_vector(column)
- column = convert_to_array(column)
- new [column].transpose, 1
- end
-
- #
- # Creates a empty matrix of +row_count+ x +column_count+.
- # At least one of +row_count+ or +column_count+ must be 0.
- #
- # m = Matrix.empty(2, 0)
- # m == Matrix[ [], [] ]
- # => true
- # n = Matrix.empty(0, 3)
- # n == Matrix.columns([ [], [], [] ])
- # => true
- # m * n
- # => Matrix[[0, 0, 0], [0, 0, 0]]
- #
- def Matrix.empty(row_count = 0, column_count = 0)
- raise ArgumentError, "One size must be 0" if column_count != 0 && row_count != 0
- raise ArgumentError, "Negative size" if column_count < 0 || row_count < 0
-
- new([[]]*row_count, column_count)
- end
-
- #
- # Create a matrix by stacking matrices vertically
- #
- # x = Matrix[[1, 2], [3, 4]]
- # y = Matrix[[5, 6], [7, 8]]
- # Matrix.vstack(x, y) # => Matrix[[1, 2], [3, 4], [5, 6], [7, 8]]
- #
- def Matrix.vstack(x, *matrices)
- raise TypeError, "Expected a Matrix, got a #{x.class}" unless x.is_a?(Matrix)
- result = x.send(:rows).map(&:dup)
- matrices.each do |m|
- raise TypeError, "Expected a Matrix, got a #{m.class}" unless m.is_a?(Matrix)
- if m.column_count != x.column_count
- raise ErrDimensionMismatch, "The given matrices must have #{x.column_count} columns, but one has #{m.column_count}"
- end
- result.concat(m.send(:rows))
- end
- new result, x.column_count
- end
-
-
- #
- # Create a matrix by stacking matrices horizontally
- #
- # x = Matrix[[1, 2], [3, 4]]
- # y = Matrix[[5, 6], [7, 8]]
- # Matrix.hstack(x, y) # => Matrix[[1, 2, 5, 6], [3, 4, 7, 8]]
- #
- def Matrix.hstack(x, *matrices)
- raise TypeError, "Expected a Matrix, got a #{x.class}" unless x.is_a?(Matrix)
- result = x.send(:rows).map(&:dup)
- total_column_count = x.column_count
- matrices.each do |m|
- raise TypeError, "Expected a Matrix, got a #{m.class}" unless m.is_a?(Matrix)
- if m.row_count != x.row_count
- raise ErrDimensionMismatch, "The given matrices must have #{x.row_count} rows, but one has #{m.row_count}"
- end
- result.each_with_index do |row, i|
- row.concat m.send(:rows)[i]
- end
- total_column_count += m.column_count
- end
- new result, total_column_count
- end
-
- #
- # Matrix.new is private; use Matrix.rows, columns, [], etc... to create.
- #
- def initialize(rows, column_count = rows[0].size)
- # No checking is done at this point. rows must be an Array of Arrays.
- # column_count must be the size of the first row, if there is one,
- # otherwise it *must* be specified and can be any integer >= 0
- @rows = rows
- @column_count = column_count
- end
-
- def new_matrix(rows, column_count = rows[0].size) # :nodoc:
- self.class.send(:new, rows, column_count) # bypass privacy of Matrix.new
- end
- private :new_matrix
-
- #
- # Returns element (+i+,+j+) of the matrix. That is: row +i+, column +j+.
- #
- def [](i, j)
- @rows.fetch(i){return nil}[j]
- end
- alias element []
- alias component []
-
- def []=(i, j, v)
- @rows[i][j] = v
- end
- alias set_element []=
- alias set_component []=
- private :[]=, :set_element, :set_component
-
- #
- # Returns the number of rows.
- #
- def row_count
- @rows.size
- end
-
- alias_method :row_size, :row_count
- #
- # Returns the number of columns.
- #
- attr_reader :column_count
- alias_method :column_size, :column_count
-
- #
- # Returns row vector number +i+ of the matrix as a Vector (starting at 0 like
- # an array). When a block is given, the elements of that vector are iterated.
- #
- def row(i, &block) # :yield: e
- if block_given?
- @rows.fetch(i){return self}.each(&block)
- self
- else
- Vector.elements(@rows.fetch(i){return nil})
- end
- end
-
- #
- # Returns column vector number +j+ of the matrix as a Vector (starting at 0
- # like an array). When a block is given, the elements of that vector are
- # iterated.
- #
- def column(j) # :yield: e
- if block_given?
- return self if j >= column_count || j < -column_count
- row_count.times do |i|
- yield @rows[i][j]
- end
- self
- else
- return nil if j >= column_count || j < -column_count
- col = Array.new(row_count) {|i|
- @rows[i][j]
- }
- Vector.elements(col, false)
- end
- end
-
- #
- # Returns a matrix that is the result of iteration of the given block over all
- # elements of the matrix.
- # Matrix[ [1,2], [3,4] ].collect { |e| e**2 }
- # => 1 4
- # 9 16
- #
- def collect(&block) # :yield: e
- return to_enum(:collect) unless block_given?
- rows = @rows.collect{|row| row.collect(&block)}
- new_matrix rows, column_count
- end
- alias map collect
-
- #
- # Yields all elements of the matrix, starting with those of the first row,
- # or returns an Enumerator if no block given.
- # Elements can be restricted by passing an argument:
- # * :all (default): yields all elements
- # * :diagonal: yields only elements on the diagonal
- # * :off_diagonal: yields all elements except on the diagonal
- # * :lower: yields only elements on or below the diagonal
- # * :strict_lower: yields only elements below the diagonal
- # * :strict_upper: yields only elements above the diagonal
- # * :upper: yields only elements on or above the diagonal
- #
- # Matrix[ [1,2], [3,4] ].each { |e| puts e }
- # # => prints the numbers 1 to 4
- # Matrix[ [1,2], [3,4] ].each(:strict_lower).to_a # => [3]
- #
- def each(which = :all) # :yield: e
- return to_enum :each, which unless block_given?
- last = column_count - 1
- case which
- when :all
- block = Proc.new
- @rows.each do |row|
- row.each(&block)
- end
- when :diagonal
- @rows.each_with_index do |row, row_index|
- yield row.fetch(row_index){return self}
- end
- when :off_diagonal
- @rows.each_with_index do |row, row_index|
- column_count.times do |col_index|
- yield row[col_index] unless row_index == col_index
- end
- end
- when :lower
- @rows.each_with_index do |row, row_index|
- 0.upto([row_index, last].min) do |col_index|
- yield row[col_index]
- end
- end
- when :strict_lower
- @rows.each_with_index do |row, row_index|
- [row_index, column_count].min.times do |col_index|
- yield row[col_index]
- end
- end
- when :strict_upper
- @rows.each_with_index do |row, row_index|
- (row_index+1).upto(last) do |col_index|
- yield row[col_index]
- end
- end
- when :upper
- @rows.each_with_index do |row, row_index|
- row_index.upto(last) do |col_index|
- yield row[col_index]
- end
- end
- else
- raise ArgumentError, "expected #{which.inspect} to be one of :all, :diagonal, :off_diagonal, :lower, :strict_lower, :strict_upper or :upper"
- end
- self
- end
-
- #
- # Same as #each, but the row index and column index in addition to the element
- #
- # Matrix[ [1,2], [3,4] ].each_with_index do |e, row, col|
- # puts "#{e} at #{row}, #{col}"
- # end
- # # => Prints:
- # # 1 at 0, 0
- # # 2 at 0, 1
- # # 3 at 1, 0
- # # 4 at 1, 1
- #
- def each_with_index(which = :all) # :yield: e, row, column
- return to_enum :each_with_index, which unless block_given?
- last = column_count - 1
- case which
- when :all
- @rows.each_with_index do |row, row_index|
- row.each_with_index do |e, col_index|
- yield e, row_index, col_index
- end
- end
- when :diagonal
- @rows.each_with_index do |row, row_index|
- yield row.fetch(row_index){return self}, row_index, row_index
- end
- when :off_diagonal
- @rows.each_with_index do |row, row_index|
- column_count.times do |col_index|
- yield row[col_index], row_index, col_index unless row_index == col_index
- end
- end
- when :lower
- @rows.each_with_index do |row, row_index|
- 0.upto([row_index, last].min) do |col_index|
- yield row[col_index], row_index, col_index
- end
- end
- when :strict_lower
- @rows.each_with_index do |row, row_index|
- [row_index, column_count].min.times do |col_index|
- yield row[col_index], row_index, col_index
- end
- end
- when :strict_upper
- @rows.each_with_index do |row, row_index|
- (row_index+1).upto(last) do |col_index|
- yield row[col_index], row_index, col_index
- end
- end
- when :upper
- @rows.each_with_index do |row, row_index|
- row_index.upto(last) do |col_index|
- yield row[col_index], row_index, col_index
- end
- end
- else
- raise ArgumentError, "expected #{which.inspect} to be one of :all, :diagonal, :off_diagonal, :lower, :strict_lower, :strict_upper or :upper"
- end
- self
- end
-
- SELECTORS = {all: true, diagonal: true, off_diagonal: true, lower: true, strict_lower: true, strict_upper: true, upper: true}.freeze
- #
- # :call-seq:
- # index(value, selector = :all) -> [row, column]
- # index(selector = :all){ block } -> [row, column]
- # index(selector = :all) -> an_enumerator
- #
- # The index method is specialized to return the index as [row, column]
- # It also accepts an optional +selector+ argument, see #each for details.
- #
- # Matrix[ [1,2], [3,4] ].index(&:even?) # => [0, 1]
- # Matrix[ [1,1], [1,1] ].index(1, :strict_lower) # => [1, 0]
- #
- def index(*args)
- raise ArgumentError, "wrong number of arguments(#{args.size} for 0-2)" if args.size > 2
- which = (args.size == 2 || SELECTORS.include?(args.last)) ? args.pop : :all
- return to_enum :find_index, which, *args unless block_given? || args.size == 1
- if args.size == 1
- value = args.first
- each_with_index(which) do |e, row_index, col_index|
- return row_index, col_index if e == value
- end
- else
- each_with_index(which) do |e, row_index, col_index|
- return row_index, col_index if yield e
- end
- end
- nil
- end
- alias_method :find_index, :index
-
- #
- # Returns a section of the matrix. The parameters are either:
- # * start_row, nrows, start_col, ncols; OR
- # * row_range, col_range
- #
- # Matrix.diagonal(9, 5, -3).minor(0..1, 0..2)
- # => 9 0 0
- # 0 5 0
- #
- # Like Array#[], negative indices count backward from the end of the
- # row or column (-1 is the last element). Returns nil if the starting
- # row or column is greater than row_count or column_count respectively.
- #
- def minor(*param)
- case param.size
- when 2
- row_range, col_range = param
- from_row = row_range.first
- from_row += row_count if from_row < 0
- to_row = row_range.end
- to_row += row_count if to_row < 0
- to_row += 1 unless row_range.exclude_end?
- size_row = to_row - from_row
-
- from_col = col_range.first
- from_col += column_count if from_col < 0
- to_col = col_range.end
- to_col += column_count if to_col < 0
- to_col += 1 unless col_range.exclude_end?
- size_col = to_col - from_col
- when 4
- from_row, size_row, from_col, size_col = param
- return nil if size_row < 0 || size_col < 0
- from_row += row_count if from_row < 0
- from_col += column_count if from_col < 0
- else
- raise ArgumentError, param.inspect
- end
-
- return nil if from_row > row_count || from_col > column_count || from_row < 0 || from_col < 0
- rows = @rows[from_row, size_row].collect{|row|
- row[from_col, size_col]
- }
- new_matrix rows, [column_count - from_col, size_col].min
- end
-
- #
- # Returns the submatrix obtained by deleting the specified row and column.
- #
- # Matrix.diagonal(9, 5, -3, 4).first_minor(1, 2)
- # => 9 0 0
- # 0 0 0
- # 0 0 4
- #
- def first_minor(row, column)
- raise RuntimeError, "first_minor of empty matrix is not defined" if empty?
-
- unless 0 <= row && row < row_count
- raise ArgumentError, "invalid row (#{row.inspect} for 0..#{row_count - 1})"
- end
-
- unless 0 <= column && column < column_count
- raise ArgumentError, "invalid column (#{column.inspect} for 0..#{column_count - 1})"
- end
-
- arrays = to_a
- arrays.delete_at(row)
- arrays.each do |array|
- array.delete_at(column)
- end
-
- new_matrix arrays, column_count - 1
- end
-
- #
- # Returns the (row, column) cofactor which is obtained by multiplying
- # the first minor by (-1)**(row + column).
- #
- # Matrix.diagonal(9, 5, -3, 4).cofactor(1, 1)
- # => -108
- #
- def cofactor(row, column)
- raise RuntimeError, "cofactor of empty matrix is not defined" if empty?
- Matrix.Raise ErrDimensionMismatch unless square?
-
- det_of_minor = first_minor(row, column).determinant
- det_of_minor * (-1) ** (row + column)
- end
-
- #
- # Returns the adjugate of the matrix.
- #
- # Matrix[ [7,6],[3,9] ].adjugate
- # => 9 -6
- # -3 7
- #
- def adjugate
- Matrix.Raise ErrDimensionMismatch unless square?
- Matrix.build(row_count, column_count) do |row, column|
- cofactor(column, row)
- end
- end
-
- #
- # Returns the Laplace expansion along given row or column.
- #
- # Matrix[[7,6], [3,9]].laplace_expansion(column: 1)
- # => 45
- #
- # Matrix[[Vector[1, 0], Vector[0, 1]], [2, 3]].laplace_expansion(row: 0)
- # => Vector[3, -2]
- #
- #
- def laplace_expansion(row: nil, column: nil)
- num = row || column
-
- if !num || (row && column)
- raise ArgumentError, "exactly one the row or column arguments must be specified"
- end
-
- Matrix.Raise ErrDimensionMismatch unless square?
- raise RuntimeError, "laplace_expansion of empty matrix is not defined" if empty?
-
- unless 0 <= num && num < row_count
- raise ArgumentError, "invalid num (#{num.inspect} for 0..#{row_count - 1})"
- end
-
- send(row ? :row : :column, num).map.with_index { |e, k|
- e * cofactor(*(row ? [num, k] : [k,num]))
- }.inject(:+)
- end
- alias_method :cofactor_expansion, :laplace_expansion
-
-
- #--
- # TESTING -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- #++
-
- #
- # Returns +true+ if this is a diagonal matrix.
- # Raises an error if matrix is not square.
- #
- def diagonal?
- Matrix.Raise ErrDimensionMismatch unless square?
- each(:off_diagonal).all?(&:zero?)
- end
-
- #
- # Returns +true+ if this is an empty matrix, i.e. if the number of rows
- # or the number of columns is 0.
- #
- def empty?
- column_count == 0 || row_count == 0
- end
-
- #
- # Returns +true+ if this is an hermitian matrix.
- # Raises an error if matrix is not square.
- #
- def hermitian?
- Matrix.Raise ErrDimensionMismatch unless square?
- each_with_index(:upper).all? do |e, row, col|
- e == rows[col][row].conj
- end
- end
-
- #
- # Returns +true+ if this is a lower triangular matrix.
- #
- def lower_triangular?
- each(:strict_upper).all?(&:zero?)
- end
-
- #
- # Returns +true+ if this is a normal matrix.
- # Raises an error if matrix is not square.
- #
- def normal?
- Matrix.Raise ErrDimensionMismatch unless square?
- rows.each_with_index do |row_i, i|
- rows.each_with_index do |row_j, j|
- s = 0
- rows.each_with_index do |row_k, k|
- s += row_i[k] * row_j[k].conj - row_k[i].conj * row_k[j]
- end
- return false unless s == 0
- end
- end
- true
- end
-
- #
- # Returns +true+ if this is an orthogonal matrix
- # Raises an error if matrix is not square.
- #
- def orthogonal?
- Matrix.Raise ErrDimensionMismatch unless square?
- rows.each_with_index do |row, i|
- column_count.times do |j|
- s = 0
- row_count.times do |k|
- s += row[k] * rows[k][j]
- end
- return false unless s == (i == j ? 1 : 0)
- end
- end
- true
- end
-
- #
- # Returns +true+ if this is a permutation matrix
- # Raises an error if matrix is not square.
- #
- def permutation?
- Matrix.Raise ErrDimensionMismatch unless square?
- cols = Array.new(column_count)
- rows.each_with_index do |row, i|
- found = false
- row.each_with_index do |e, j|
- if e == 1
- return false if found || cols[j]
- found = cols[j] = true
- elsif e != 0
- return false
- end
- end
- return false unless found
- end
- true
- end
-
- #
- # Returns +true+ if all entries of the matrix are real.
- #
- def real?
- all?(&:real?)
- end
-
- #
- # Returns +true+ if this is a regular (i.e. non-singular) matrix.
- #
- def regular?
- not singular?
- end
-
- #
- # Returns +true+ if this is a singular matrix.
- #
- def singular?
- determinant == 0
- end
-
- #
- # Returns +true+ if this is a square matrix.
- #
- def square?
- column_count == row_count
- end
-
- #
- # Returns +true+ if this is a symmetric matrix.
- # Raises an error if matrix is not square.
- #
- def symmetric?
- Matrix.Raise ErrDimensionMismatch unless square?
- each_with_index(:strict_upper) do |e, row, col|
- return false if e != rows[col][row]
- end
- true
- end
-
- #
- # Returns +true+ if this is a unitary matrix
- # Raises an error if matrix is not square.
- #
- def unitary?
- Matrix.Raise ErrDimensionMismatch unless square?
- rows.each_with_index do |row, i|
- column_count.times do |j|
- s = 0
- row_count.times do |k|
- s += row[k].conj * rows[k][j]
- end
- return false unless s == (i == j ? 1 : 0)
- end
- end
- true
- end
-
- #
- # Returns +true+ if this is an upper triangular matrix.
- #
- def upper_triangular?
- each(:strict_lower).all?(&:zero?)
- end
-
- #
- # Returns +true+ if this is a matrix with only zero elements
- #
- def zero?
- all?(&:zero?)
- end
-
- #--
- # OBJECT METHODS -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- #++
-
- #
- # Returns +true+ if and only if the two matrices contain equal elements.
- #
- def ==(other)
- return false unless Matrix === other &&
- column_count == other.column_count # necessary for empty matrices
- rows == other.rows
- end
-
- def eql?(other)
- return false unless Matrix === other &&
- column_count == other.column_count # necessary for empty matrices
- rows.eql? other.rows
- end
-
- #
- # Returns a clone of the matrix, so that the contents of each do not reference
- # identical objects.
- # There should be no good reason to do this since Matrices are immutable.
- #
- def clone
- new_matrix @rows.map(&:dup), column_count
- end
-
- #
- # Returns a hash-code for the matrix.
- #
- def hash
- @rows.hash
- end
-
- #--
- # ARITHMETIC -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- #++
-
- #
- # Matrix multiplication.
- # Matrix[[2,4], [6,8]] * Matrix.identity(2)
- # => 2 4
- # 6 8
- #
- def *(m) # m is matrix or vector or number
- case(m)
- when Numeric
- rows = @rows.collect {|row|
- row.collect {|e| e * m }
- }
- return new_matrix rows, column_count
- when Vector
- m = self.class.column_vector(m)
- r = self * m
- return r.column(0)
- when Matrix
- Matrix.Raise ErrDimensionMismatch if column_count != m.row_count
-
- rows = Array.new(row_count) {|i|
- Array.new(m.column_count) {|j|
- (0 ... column_count).inject(0) do |vij, k|
- vij + self[i, k] * m[k, j]
- end
- }
- }
- return new_matrix rows, m.column_count
- else
- return apply_through_coercion(m, __method__)
- end
- end
-
- #
- # Matrix addition.
- # Matrix.scalar(2,5) + Matrix[[1,0], [-4,7]]
- # => 6 0
- # -4 12
- #
- def +(m)
- case m
- when Numeric
- Matrix.Raise ErrOperationNotDefined, "+", self.class, m.class
- when Vector
- m = self.class.column_vector(m)
- when Matrix
- else
- return apply_through_coercion(m, __method__)
- end
-
- Matrix.Raise ErrDimensionMismatch unless row_count == m.row_count && column_count == m.column_count
-
- rows = Array.new(row_count) {|i|
- Array.new(column_count) {|j|
- self[i, j] + m[i, j]
- }
- }
- new_matrix rows, column_count
- end
-
- #
- # Matrix subtraction.
- # Matrix[[1,5], [4,2]] - Matrix[[9,3], [-4,1]]
- # => -8 2
- # 8 1
- #
- def -(m)
- case m
- when Numeric
- Matrix.Raise ErrOperationNotDefined, "-", self.class, m.class
- when Vector
- m = self.class.column_vector(m)
- when Matrix
- else
- return apply_through_coercion(m, __method__)
- end
-
- Matrix.Raise ErrDimensionMismatch unless row_count == m.row_count && column_count == m.column_count
-
- rows = Array.new(row_count) {|i|
- Array.new(column_count) {|j|
- self[i, j] - m[i, j]
- }
- }
- new_matrix rows, column_count
- end
-
- #
- # Matrix division (multiplication by the inverse).
- # Matrix[[7,6], [3,9]] / Matrix[[2,9], [3,1]]
- # => -7 1
- # -3 -6
- #
- def /(other)
- case other
- when Numeric
- rows = @rows.collect {|row|
- row.collect {|e| e / other }
- }
- return new_matrix rows, column_count
- when Matrix
- return self * other.inverse
- else
- return apply_through_coercion(other, __method__)
- end
- end
-
- #
- # Returns the inverse of the matrix.
- # Matrix[[-1, -1], [0, -1]].inverse
- # => -1 1
- # 0 -1
- #
- def inverse
- Matrix.Raise ErrDimensionMismatch unless square?
- self.class.I(row_count).send(:inverse_from, self)
- end
- alias inv inverse
-
- def inverse_from(src) # :nodoc:
- last = row_count - 1
- a = src.to_a
-
- 0.upto(last) do |k|
- i = k
- akk = a[k][k].abs
- (k+1).upto(last) do |j|
- v = a[j][k].abs
- if v > akk
- i = j
- akk = v
- end
- end
- Matrix.Raise ErrNotRegular if akk == 0
- if i != k
- a[i], a[k] = a[k], a[i]
- @rows[i], @rows[k] = @rows[k], @rows[i]
- end
- akk = a[k][k]
-
- 0.upto(last) do |ii|
- next if ii == k
- q = a[ii][k].quo(akk)
- a[ii][k] = 0
-
- (k + 1).upto(last) do |j|
- a[ii][j] -= a[k][j] * q
- end
- 0.upto(last) do |j|
- @rows[ii][j] -= @rows[k][j] * q
- end
- end
-
- (k+1).upto(last) do |j|
- a[k][j] = a[k][j].quo(akk)
- end
- 0.upto(last) do |j|
- @rows[k][j] = @rows[k][j].quo(akk)
- end
- end
- self
- end
- private :inverse_from
-
- #
- # Matrix exponentiation.
- # Equivalent to multiplying the matrix by itself N times.
- # Non integer exponents will be handled by diagonalizing the matrix.
- #
- # Matrix[[7,6], [3,9]] ** 2
- # => 67 96
- # 48 99
- #
- def ** (other)
- case other
- when Integer
- x = self
- if other <= 0
- x = self.inverse
- return self.class.identity(self.column_count) if other == 0
- other = -other
- end
- z = nil
- loop do
- z = z ? z * x : x if other[0] == 1
- return z if (other >>= 1).zero?
- x *= x
- end
- when Numeric
- v, d, v_inv = eigensystem
- v * self.class.diagonal(*d.each(:diagonal).map{|e| e ** other}) * v_inv
- else
- Matrix.Raise ErrOperationNotDefined, "**", self.class, other.class
- end
- end
-
- def +@
- self
- end
-
- def -@
- collect {|e| -e }
- end
-
- #--
- # MATRIX FUNCTIONS -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- #++
-
- #
- # Returns the determinant of the matrix.
- #
- # Beware that using Float values can yield erroneous results
- # because of their lack of precision.
- # Consider using exact types like Rational or BigDecimal instead.
- #
- # Matrix[[7,6], [3,9]].determinant
- # => 45
- #
- def determinant
- Matrix.Raise ErrDimensionMismatch unless square?
- m = @rows
- case row_count
- # Up to 4x4, give result using Laplacian expansion by minors.
- # This will typically be faster, as well as giving good results
- # in case of Floats
- when 0
- +1
- when 1
- + m[0][0]
- when 2
- + m[0][0] * m[1][1] - m[0][1] * m[1][0]
- when 3
- m0, m1, m2 = m
- + m0[0] * m1[1] * m2[2] - m0[0] * m1[2] * m2[1] \
- - m0[1] * m1[0] * m2[2] + m0[1] * m1[2] * m2[0] \
- + m0[2] * m1[0] * m2[1] - m0[2] * m1[1] * m2[0]
- when 4
- m0, m1, m2, m3 = m
- + m0[0] * m1[1] * m2[2] * m3[3] - m0[0] * m1[1] * m2[3] * m3[2] \
- - m0[0] * m1[2] * m2[1] * m3[3] + m0[0] * m1[2] * m2[3] * m3[1] \
- + m0[0] * m1[3] * m2[1] * m3[2] - m0[0] * m1[3] * m2[2] * m3[1] \
- - m0[1] * m1[0] * m2[2] * m3[3] + m0[1] * m1[0] * m2[3] * m3[2] \
- + m0[1] * m1[2] * m2[0] * m3[3] - m0[1] * m1[2] * m2[3] * m3[0] \
- - m0[1] * m1[3] * m2[0] * m3[2] + m0[1] * m1[3] * m2[2] * m3[0] \
- + m0[2] * m1[0] * m2[1] * m3[3] - m0[2] * m1[0] * m2[3] * m3[1] \
- - m0[2] * m1[1] * m2[0] * m3[3] + m0[2] * m1[1] * m2[3] * m3[0] \
- + m0[2] * m1[3] * m2[0] * m3[1] - m0[2] * m1[3] * m2[1] * m3[0] \
- - m0[3] * m1[0] * m2[1] * m3[2] + m0[3] * m1[0] * m2[2] * m3[1] \
- + m0[3] * m1[1] * m2[0] * m3[2] - m0[3] * m1[1] * m2[2] * m3[0] \
- - m0[3] * m1[2] * m2[0] * m3[1] + m0[3] * m1[2] * m2[1] * m3[0]
- else
- # For bigger matrices, use an efficient and general algorithm.
- # Currently, we use the Gauss-Bareiss algorithm
- determinant_bareiss
- end
- end
- alias_method :det, :determinant
-
- #
- # Private. Use Matrix#determinant
- #
- # Returns the determinant of the matrix, using
- # Bareiss' multistep integer-preserving gaussian elimination.
- # It has the same computational cost order O(n^3) as standard Gaussian elimination.
- # Intermediate results are fraction free and of lower complexity.
- # A matrix of Integers will have thus intermediate results that are also Integers,
- # with smaller bignums (if any), while a matrix of Float will usually have
- # intermediate results with better precision.
- #
- def determinant_bareiss
- size = row_count
- last = size - 1
- a = to_a
- no_pivot = Proc.new{ return 0 }
- sign = +1
- pivot = 1
- size.times do |k|
- previous_pivot = pivot
- if (pivot = a[k][k]) == 0
- switch = (k+1 ... size).find(no_pivot) {|row|
- a[row][k] != 0
- }
- a[switch], a[k] = a[k], a[switch]
- pivot = a[k][k]
- sign = -sign
- end
- (k+1).upto(last) do |i|
- ai = a[i]
- (k+1).upto(last) do |j|
- ai[j] = (pivot * ai[j] - ai[k] * a[k][j]) / previous_pivot
- end
- end
- end
- sign * pivot
- end
- private :determinant_bareiss
-
- #
- # deprecated; use Matrix#determinant
- #
- def determinant_e
- warn "#{caller(1)[0]}: warning: Matrix#determinant_e is deprecated; use #determinant"
- determinant
- end
- alias det_e determinant_e
-
- #
- # Returns a new matrix resulting by stacking horizontally
- # the receiver with the given matrices
- #
- # x = Matrix[[1, 2], [3, 4]]
- # y = Matrix[[5, 6], [7, 8]]
- # x.hstack(y) # => Matrix[[1, 2, 5, 6], [3, 4, 7, 8]]
- #
- def hstack(*matrices)
- self.class.hstack(self, *matrices)
- end
-
- #
- # Returns the rank of the matrix.
- # Beware that using Float values can yield erroneous results
- # because of their lack of precision.
- # Consider using exact types like Rational or BigDecimal instead.
- #
- # Matrix[[7,6], [3,9]].rank
- # => 2
- #
- def rank
- # We currently use Bareiss' multistep integer-preserving gaussian elimination
- # (see comments on determinant)
- a = to_a
- last_column = column_count - 1
- last_row = row_count - 1
- pivot_row = 0
- previous_pivot = 1
- 0.upto(last_column) do |k|
- switch_row = (pivot_row .. last_row).find {|row|
- a[row][k] != 0
- }
- if switch_row
- a[switch_row], a[pivot_row] = a[pivot_row], a[switch_row] unless pivot_row == switch_row
- pivot = a[pivot_row][k]
- (pivot_row+1).upto(last_row) do |i|
- ai = a[i]
- (k+1).upto(last_column) do |j|
- ai[j] = (pivot * ai[j] - ai[k] * a[pivot_row][j]) / previous_pivot
- end
- end
- pivot_row += 1
- previous_pivot = pivot
- end
- end
- pivot_row
- end
-
- #
- # deprecated; use Matrix#rank
- #
- def rank_e
- warn "#{caller(1)[0]}: warning: Matrix#rank_e is deprecated; use #rank"
- rank
- end
-
- # Returns a matrix with entries rounded to the given precision
- # (see Float#round)
- #
- def round(ndigits=0)
- map{|e| e.round(ndigits)}
- end
-
- #
- # Returns the trace (sum of diagonal elements) of the matrix.
- # Matrix[[7,6], [3,9]].trace
- # => 16
- #
- def trace
- Matrix.Raise ErrDimensionMismatch unless square?
- (0...column_count).inject(0) do |tr, i|
- tr + @rows[i][i]
- end
- end
- alias tr trace
-
- #
- # Returns the transpose of the matrix.
- # Matrix[[1,2], [3,4], [5,6]]
- # => 1 2
- # 3 4
- # 5 6
- # Matrix[[1,2], [3,4], [5,6]].transpose
- # => 1 3 5
- # 2 4 6
- #
- def transpose
- return self.class.empty(column_count, 0) if row_count.zero?
- new_matrix @rows.transpose, row_count
- end
- alias t transpose
-
- #
- # Returns a new matrix resulting by stacking vertically
- # the receiver with the given matrices
- #
- # x = Matrix[[1, 2], [3, 4]]
- # y = Matrix[[5, 6], [7, 8]]
- # x.vstack(y) # => Matrix[[1, 2], [3, 4], [5, 6], [7, 8]]
- #
- def vstack(*matrices)
- self.class.vstack(self, *matrices)
- end
-
- #--
- # DECOMPOSITIONS -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- #++
-
- #
- # Returns the Eigensystem of the matrix; see +EigenvalueDecomposition+.
- # m = Matrix[[1, 2], [3, 4]]
- # v, d, v_inv = m.eigensystem
- # d.diagonal? # => true
- # v.inv == v_inv # => true
- # (v * d * v_inv).round(5) == m # => true
- #
- def eigensystem
- EigenvalueDecomposition.new(self)
- end
- alias eigen eigensystem
-
- #
- # Returns the LUP decomposition of the matrix; see +LUPDecomposition+.
- # a = Matrix[[1, 2], [3, 4]]
- # l, u, p = a.lup
- # l.lower_triangular? # => true
- # u.upper_triangular? # => true
- # p.permutation? # => true
- # l * u == p * a # => true
- # a.lup.solve([2, 5]) # => Vector[(1/1), (1/2)]
- #
- def lup
- LUPDecomposition.new(self)
- end
- alias lup_decomposition lup
-
- #--
- # COMPLEX ARITHMETIC -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- #++
-
- #
- # Returns the conjugate of the matrix.
- # Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]
- # => 1+2i i 0
- # 1 2 3
- # Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].conjugate
- # => 1-2i -i 0
- # 1 2 3
- #
- def conjugate
- collect(&:conjugate)
- end
- alias conj conjugate
-
- #
- # Returns the imaginary part of the matrix.
- # Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]
- # => 1+2i i 0
- # 1 2 3
- # Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].imaginary
- # => 2i i 0
- # 0 0 0
- #
- def imaginary
- collect(&:imaginary)
- end
- alias imag imaginary
-
- #
- # Returns the real part of the matrix.
- # Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]
- # => 1+2i i 0
- # 1 2 3
- # Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].real
- # => 1 0 0
- # 1 2 3
- #
- def real
- collect(&:real)
- end
-
- #
- # Returns an array containing matrices corresponding to the real and imaginary
- # parts of the matrix
- #
- # m.rect == [m.real, m.imag] # ==> true for all matrices m
- #
- def rect
- [real, imag]
- end
- alias rectangular rect
-
- #--
- # CONVERTING -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- #++
-
- #
- # The coerce method provides support for Ruby type coercion.
- # This coercion mechanism is used by Ruby to handle mixed-type
- # numeric operations: it is intended to find a compatible common
- # type between the two operands of the operator.
- # See also Numeric#coerce.
- #
- def coerce(other)
- case other
- when Numeric
- return Scalar.new(other), self
- else
- raise TypeError, "#{self.class} can't be coerced into #{other.class}"
- end
- end
-
- #
- # Returns an array of the row vectors of the matrix. See Vector.
- #
- def row_vectors
- Array.new(row_count) {|i|
- row(i)
- }
- end
-
- #
- # Returns an array of the column vectors of the matrix. See Vector.
- #
- def column_vectors
- Array.new(column_count) {|i|
- column(i)
- }
- end
-
- #
- # Returns an array of arrays that describe the rows of the matrix.
- #
- def to_a
- @rows.collect(&:dup)
- end
-
- def elements_to_f
- warn "#{caller(1)[0]}: warning: Matrix#elements_to_f is deprecated, use map(&:to_f)"
- map(&:to_f)
- end
-
- def elements_to_i
- warn "#{caller(1)[0]}: warning: Matrix#elements_to_i is deprecated, use map(&:to_i)"
- map(&:to_i)
- end
-
- def elements_to_r
- warn "#{caller(1)[0]}: warning: Matrix#elements_to_r is deprecated, use map(&:to_r)"
- map(&:to_r)
- end
-
- #--
- # PRINTING -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- #++
-
- #
- # Overrides Object#to_s
- #
- def to_s
- if empty?
- "#{self.class}.empty(#{row_count}, #{column_count})"
- else
- "#{self.class}[" + @rows.collect{|row|
- "[" + row.collect{|e| e.to_s}.join(", ") + "]"
- }.join(", ")+"]"
- end
- end
-
- #
- # Overrides Object#inspect
- #
- def inspect
- if empty?
- "#{self.class}.empty(#{row_count}, #{column_count})"
- else
- "#{self.class}#{@rows.inspect}"
- end
- end
-
- # Private helper modules
-
- module ConversionHelper # :nodoc:
- #
- # Converts the obj to an Array. If copy is set to true
- # a copy of obj will be made if necessary.
- #
- def convert_to_array(obj, copy = false) # :nodoc:
- case obj
- when Array
- copy ? obj.dup : obj
- when Vector
- obj.to_a
- else
- begin
- converted = obj.to_ary
- rescue Exception => e
- raise TypeError, "can't convert #{obj.class} into an Array (#{e.message})"
- end
- raise TypeError, "#{obj.class}#to_ary should return an Array" unless converted.is_a? Array
- converted
- end
- end
- private :convert_to_array
- end
-
- extend ConversionHelper
-
- module CoercionHelper # :nodoc:
- #
- # Applies the operator +oper+ with argument +obj+
- # through coercion of +obj+
- #
- def apply_through_coercion(obj, oper)
- coercion = obj.coerce(self)
- raise TypeError unless coercion.is_a?(Array) && coercion.length == 2
- coercion[0].public_send(oper, coercion[1])
- rescue
- raise TypeError, "#{obj.inspect} can't be coerced into #{self.class}"
- end
- private :apply_through_coercion
-
- #
- # Helper method to coerce a value into a specific class.
- # Raises a TypeError if the coercion fails or the returned value
- # is not of the right class.
- # (from Rubinius)
- #
- def self.coerce_to(obj, cls, meth) # :nodoc:
- return obj if obj.kind_of?(cls)
-
- begin
- ret = obj.__send__(meth)
- rescue Exception => e
- raise TypeError, "Coercion error: #{obj.inspect}.#{meth} => #{cls} failed:\n" \
- "(#{e.message})"
- end
- raise TypeError, "Coercion error: obj.#{meth} did NOT return a #{cls} (was #{ret.class})" unless ret.kind_of? cls
- ret
- end
-
- def self.coerce_to_int(obj)
- coerce_to(obj, Integer, :to_int)
- end
- end
-
- include CoercionHelper
-
- # Private CLASS
-
- class Scalar < Numeric # :nodoc:
- include ExceptionForMatrix
- include CoercionHelper
-
- def initialize(value)
- @value = value
- end
-
- # ARITHMETIC
- def +(other)
- case other
- when Numeric
- Scalar.new(@value + other)
- when Vector, Matrix
- Scalar.Raise ErrOperationNotDefined, "+", @value.class, other.class
- else
- apply_through_coercion(other, __method__)
- end
- end
-
- def -(other)
- case other
- when Numeric
- Scalar.new(@value - other)
- when Vector, Matrix
- Scalar.Raise ErrOperationNotDefined, "-", @value.class, other.class
- else
- apply_through_coercion(other, __method__)
- end
- end
-
- def *(other)
- case other
- when Numeric
- Scalar.new(@value * other)
- when Vector, Matrix
- other.collect{|e| @value * e}
- else
- apply_through_coercion(other, __method__)
- end
- end
-
- def / (other)
- case other
- when Numeric
- Scalar.new(@value / other)
- when Vector
- Scalar.Raise ErrOperationNotDefined, "/", @value.class, other.class
- when Matrix
- self * other.inverse
- else
- apply_through_coercion(other, __method__)
- end
- end
-
- def ** (other)
- case other
- when Numeric
- Scalar.new(@value ** other)
- when Vector
- Scalar.Raise ErrOperationNotDefined, "**", @value.class, other.class
- when Matrix
- #other.powered_by(self)
- Scalar.Raise ErrOperationNotImplemented, "**", @value.class, other.class
- else
- apply_through_coercion(other, __method__)
- end
- end
- end
-
-end
-
-
-#
-# The +Vector+ class represents a mathematical vector, which is useful in its own right, and
-# also constitutes a row or column of a Matrix.
-#
-# == Method Catalogue
-#
-# To create a Vector:
-# * Vector.[](*array)
-# * Vector.elements(array, copy = true)
-# * Vector.basis(size: n, index: k)
-#
-# To access elements:
-# * #[](i)
-#
-# To enumerate the elements:
-# * #each2(v)
-# * #collect2(v)
-#
-# Properties of vectors:
-# * #angle_with(v)
-# * Vector.independent?(*vs)
-# * #independent?(*vs)
-#
-# Vector arithmetic:
-# * #*(x) "is matrix or number"
-# * #+(v)
-# * #-(v)
-# * #+@
-# * #-@
-#
-# Vector functions:
-# * #inner_product(v), dot(v)
-# * #cross_product(v), cross(v)
-# * #collect
-# * #magnitude
-# * #map
-# * #map2(v)
-# * #norm
-# * #normalize
-# * #r
-# * #size
-#
-# Conversion to other data types:
-# * #covector
-# * #to_a
-# * #coerce(other)
-#
-# String representations:
-# * #to_s
-# * #inspect
-#
-class Vector
- include ExceptionForMatrix
- include Enumerable
- include Matrix::CoercionHelper
- extend Matrix::ConversionHelper
- #INSTANCE CREATION
-
- private_class_method :new
- attr_reader :elements
- protected :elements
-
- #
- # Creates a Vector from a list of elements.
- # Vector[7, 4, ...]
- #
- def Vector.[](*array)
- new convert_to_array(array, false)
- end
-
- #
- # Creates a vector from an Array. The optional second argument specifies
- # whether the array itself or a copy is used internally.
- #
- def Vector.elements(array, copy = true)
- new convert_to_array(array, copy)
- end
-
- #
- # Returns a standard basis +n+-vector, where k is the index.
- #
- # Vector.basis(size:, index:) # => Vector[0, 1, 0]
- #
- def Vector.basis(size:, index:)
- raise ArgumentError, "invalid size (#{size} for 1..)" if size < 1
- raise ArgumentError, "invalid index (#{index} for 0...#{size})" unless 0 <= index && index < size
- array = Array.new(size, 0)
- array[index] = 1
- new convert_to_array(array, false)
- end
-
- #
- # Vector.new is private; use Vector[] or Vector.elements to create.
- #
- def initialize(array)
- # No checking is done at this point.
- @elements = array
- end
-
- # ACCESSING
-
- #
- # Returns element number +i+ (starting at zero) of the vector.
- #
- def [](i)
- @elements[i]
- end
- alias element []
- alias component []
-
- def []=(i, v)
- @elements[i]= v
- end
- alias set_element []=
- alias set_component []=
- private :[]=, :set_element, :set_component
-
- #
- # Returns the number of elements in the vector.
- #
- def size
- @elements.size
- end
-
- #--
- # ENUMERATIONS -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- #++
-
- #
- # Iterate over the elements of this vector
- #
- def each(&block)
- return to_enum(:each) unless block_given?
- @elements.each(&block)
- self
- end
-
- #
- # Iterate over the elements of this vector and +v+ in conjunction.
- #
- def each2(v) # :yield: e1, e2
- raise TypeError, "Integer is not like Vector" if v.kind_of?(Integer)
- Vector.Raise ErrDimensionMismatch if size != v.size
- return to_enum(:each2, v) unless block_given?
- size.times do |i|
- yield @elements[i], v[i]
- end
- self
- end
-
- #
- # Collects (as in Enumerable#collect) over the elements of this vector and +v+
- # in conjunction.
- #
- def collect2(v) # :yield: e1, e2
- raise TypeError, "Integer is not like Vector" if v.kind_of?(Integer)
- Vector.Raise ErrDimensionMismatch if size != v.size
- return to_enum(:collect2, v) unless block_given?
- Array.new(size) do |i|
- yield @elements[i], v[i]
- end
- end
-
- #--
- # PROPERTIES -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- #++
-
- #
- # Returns +true+ iff all of vectors are linearly independent.
- #
- # Vector.independent?(Vector[1,0], Vector[0,1])
- # => true
- #
- # Vector.independent?(Vector[1,2], Vector[2,4])
- # => false
- #
- def Vector.independent?(*vs)
- vs.each do |v|
- raise TypeError, "expected Vector, got #{v.class}" unless v.is_a?(Vector)
- Vector.Raise ErrDimensionMismatch unless v.size == vs.first.size
- end
- return false if vs.count > vs.first.size
- Matrix[*vs].rank.eql?(vs.count)
- end
-
- #
- # Returns +true+ iff all of vectors are linearly independent.
- #
- # Vector[1,0].independent?(Vector[0,1])
- # => true
- #
- # Vector[1,2].independent?(Vector[2,4])
- # => false
- #
- def independent?(*vs)
- self.class.independent?(self, *vs)
- end
-
- #--
- # COMPARING -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- #++
-
- #
- # Returns +true+ iff the two vectors have the same elements in the same order.
- #
- def ==(other)
- return false unless Vector === other
- @elements == other.elements
- end
-
- def eql?(other)
- return false unless Vector === other
- @elements.eql? other.elements
- end
-
- #
- # Returns a copy of the vector.
- #
- def clone
- self.class.elements(@elements)
- end
-
- #
- # Returns a hash-code for the vector.
- #
- def hash
- @elements.hash
- end
-
- #--
- # ARITHMETIC -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- #++
-
- #
- # Multiplies the vector by +x+, where +x+ is a number or another vector.
- #
- def *(x)
- case x
- when Numeric
- els = @elements.collect{|e| e * x}
- self.class.elements(els, false)
- when Matrix
- Matrix.column_vector(self) * x
- when Vector
- Vector.Raise ErrOperationNotDefined, "*", self.class, x.class
- else
- apply_through_coercion(x, __method__)
- end
- end
-
- #
- # Vector addition.
- #
- def +(v)
- case v
- when Vector
- Vector.Raise ErrDimensionMismatch if size != v.size
- els = collect2(v) {|v1, v2|
- v1 + v2
- }
- self.class.elements(els, false)
- when Matrix
- Matrix.column_vector(self) + v
- else
- apply_through_coercion(v, __method__)
- end
- end
-
- #
- # Vector subtraction.
- #
- def -(v)
- case v
- when Vector
- Vector.Raise ErrDimensionMismatch if size != v.size
- els = collect2(v) {|v1, v2|
- v1 - v2
- }
- self.class.elements(els, false)
- when Matrix
- Matrix.column_vector(self) - v
- else
- apply_through_coercion(v, __method__)
- end
- end
-
- #
- # Vector division.
- #
- def /(x)
- case x
- when Numeric
- els = @elements.collect{|e| e / x}
- self.class.elements(els, false)
- when Matrix, Vector
- Vector.Raise ErrOperationNotDefined, "/", self.class, x.class
- else
- apply_through_coercion(x, __method__)
- end
- end
-
- def +@
- self
- end
-
- def -@
- collect {|e| -e }
- end
-
- #--
- # VECTOR FUNCTIONS -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- #++
-
- #
- # Returns the inner product of this vector with the other.
- # Vector[4,7].inner_product Vector[10,1] => 47
- #
- def inner_product(v)
- Vector.Raise ErrDimensionMismatch if size != v.size
-
- p = 0
- each2(v) {|v1, v2|
- p += v1 * v2.conj
- }
- p
- end
- alias_method :dot, :inner_product
-
- #
- # Returns the cross product of this vector with the others.
- # Vector[1, 0, 0].cross_product Vector[0, 1, 0] => Vector[0, 0, 1]
- #
- # It is generalized to other dimensions to return a vector perpendicular
- # to the arguments.
- # Vector[1, 2].cross_product # => Vector[-2, 1]
- # Vector[1, 0, 0, 0].cross_product(
- # Vector[0, 1, 0, 0],
- # Vector[0, 0, 1, 0]
- # ) #=> Vector[0, 0, 0, 1]
- #
- def cross_product(*vs)
- raise ErrOperationNotDefined, "cross product is not defined on vectors of dimension #{size}" unless size >= 2
- raise ArgumentError, "wrong number of arguments (#{vs.size} for #{size - 2})" unless vs.size == size - 2
- vs.each do |v|
- raise TypeError, "expected Vector, got #{v.class}" unless v.is_a? Vector
- Vector.Raise ErrDimensionMismatch unless v.size == size
- end
- case size
- when 2
- Vector[-@elements[1], @elements[0]]
- when 3
- v = vs[0]
- Vector[ v[2]*@elements[1] - v[1]*@elements[2],
- v[0]*@elements[2] - v[2]*@elements[0],
- v[1]*@elements[0] - v[0]*@elements[1] ]
- else
- rows = self, *vs, Array.new(size) {|i| Vector.basis(size: size, index: i) }
- Matrix.rows(rows).laplace_expansion(row: size - 1)
- end
- end
- alias_method :cross, :cross_product
-
- #
- # Like Array#collect.
- #
- def collect(&block) # :yield: e
- return to_enum(:collect) unless block_given?
- els = @elements.collect(&block)
- self.class.elements(els, false)
- end
- alias map collect
-
- #
- # Returns the modulus (Pythagorean distance) of the vector.
- # Vector[5,8,2].r => 9.643650761
- #
- def magnitude
- Math.sqrt(@elements.inject(0) {|v, e| v + e.abs2})
- end
- alias r magnitude
- alias norm magnitude
-
- #
- # Like Vector#collect2, but returns a Vector instead of an Array.
- #
- def map2(v, &block) # :yield: e1, e2
- return to_enum(:map2, v) unless block_given?
- els = collect2(v, &block)
- self.class.elements(els, false)
- end
-
- class ZeroVectorError < StandardError
- end
- #
- # Returns a new vector with the same direction but with norm 1.
- # v = Vector[5,8,2].normalize
- # # => Vector[0.5184758473652127, 0.8295613557843402, 0.20739033894608505]
- # v.norm => 1.0
- #
- def normalize
- n = magnitude
- raise ZeroVectorError, "Zero vectors can not be normalized" if n == 0
- self / n
- end
-
- #
- # Returns an angle with another vector. Result is within the [0...Math::PI].
- # Vector[1,0].angle_with(Vector[0,1])
- # # => Math::PI / 2
- #
- def angle_with(v)
- raise TypeError, "Expected a Vector, got a #{v.class}" unless v.is_a?(Vector)
- Vector.Raise ErrDimensionMismatch if size != v.size
- prod = magnitude * v.magnitude
- raise ZeroVectorError, "Can't get angle of zero vector" if prod == 0
-
- Math.acos( inner_product(v) / prod )
- end
-
- #--
- # CONVERTING
- #++
-
- #
- # Creates a single-row matrix from this vector.
- #
- def covector
- Matrix.row_vector(self)
- end
-
- #
- # Returns the elements of the vector in an array.
- #
- def to_a
- @elements.dup
- end
-
- def elements_to_f
- warn "#{caller(1)[0]}: warning: Vector#elements_to_f is deprecated"
- map(&:to_f)
- end
-
- def elements_to_i
- warn "#{caller(1)[0]}: warning: Vector#elements_to_i is deprecated"
- map(&:to_i)
- end
-
- def elements_to_r
- warn "#{caller(1)[0]}: warning: Vector#elements_to_r is deprecated"
- map(&:to_r)
- end
-
- #
- # The coerce method provides support for Ruby type coercion.
- # This coercion mechanism is used by Ruby to handle mixed-type
- # numeric operations: it is intended to find a compatible common
- # type between the two operands of the operator.
- # See also Numeric#coerce.
- #
- def coerce(other)
- case other
- when Numeric
- return Matrix::Scalar.new(other), self
- else
- raise TypeError, "#{self.class} can't be coerced into #{other.class}"
- end
- end
-
- #--
- # PRINTING -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- #++
-
- #
- # Overrides Object#to_s
- #
- def to_s
- "Vector[" + @elements.join(", ") + "]"
- end
-
- #
- # Overrides Object#inspect
- #
- def inspect
- "Vector" + @elements.inspect
- end
-end
diff --git a/ruby_2_2/lib/matrix/eigenvalue_decomposition.rb b/ruby_2_2/lib/matrix/eigenvalue_decomposition.rb
deleted file mode 100644
index ab353ecf61..0000000000
--- a/ruby_2_2/lib/matrix/eigenvalue_decomposition.rb
+++ /dev/null
@@ -1,882 +0,0 @@
-class Matrix
- # Adapted from JAMA: http://math.nist.gov/javanumerics/jama/
-
- # Eigenvalues and eigenvectors of a real matrix.
- #
- # Computes the eigenvalues and eigenvectors of a matrix A.
- #
- # If A is diagonalizable, this provides matrices V and D
- # such that A = V*D*V.inv, where D is the diagonal matrix with entries
- # equal to the eigenvalues and V is formed by the eigenvectors.
- #
- # If A is symmetric, then V is orthogonal and thus A = V*D*V.t
-
- class EigenvalueDecomposition
-
- # Constructs the eigenvalue decomposition for a square matrix +A+
- #
- def initialize(a)
- # @d, @e: Arrays for internal storage of eigenvalues.
- # @v: Array for internal storage of eigenvectors.
- # @h: Array for internal storage of nonsymmetric Hessenberg form.
- raise TypeError, "Expected Matrix but got #{a.class}" unless a.is_a?(Matrix)
- @size = a.row_count
- @d = Array.new(@size, 0)
- @e = Array.new(@size, 0)
-
- if (@symmetric = a.symmetric?)
- @v = a.to_a
- tridiagonalize
- diagonalize
- else
- @v = Array.new(@size) { Array.new(@size, 0) }
- @h = a.to_a
- @ort = Array.new(@size, 0)
- reduce_to_hessenberg
- hessenberg_to_real_schur
- end
- end
-
- # Returns the eigenvector matrix +V+
- #
- def eigenvector_matrix
- Matrix.send(:new, build_eigenvectors.transpose)
- end
- alias v eigenvector_matrix
-
- # Returns the inverse of the eigenvector matrix +V+
- #
- def eigenvector_matrix_inv
- r = Matrix.send(:new, build_eigenvectors)
- r = r.transpose.inverse unless @symmetric
- r
- end
- alias v_inv eigenvector_matrix_inv
-
- # Returns the eigenvalues in an array
- #
- def eigenvalues
- values = @d.dup
- @e.each_with_index{|imag, i| values[i] = Complex(values[i], imag) unless imag == 0}
- values
- end
-
- # Returns an array of the eigenvectors
- #
- def eigenvectors
- build_eigenvectors.map{|ev| Vector.send(:new, ev)}
- end
-
- # Returns the block diagonal eigenvalue matrix +D+
- #
- def eigenvalue_matrix
- Matrix.diagonal(*eigenvalues)
- end
- alias d eigenvalue_matrix
-
- # Returns [eigenvector_matrix, eigenvalue_matrix, eigenvector_matrix_inv]
- #
- def to_ary
- [v, d, v_inv]
- end
- alias_method :to_a, :to_ary
-
- private
- def build_eigenvectors
- # JAMA stores complex eigenvectors in a strange way
- # See http://web.archive.org/web/20111016032731/http://cio.nist.gov/esd/emaildir/lists/jama/msg01021.html
- @e.each_with_index.map do |imag, i|
- if imag == 0
- Array.new(@size){|j| @v[j][i]}
- elsif imag > 0
- Array.new(@size){|j| Complex(@v[j][i], @v[j][i+1])}
- else
- Array.new(@size){|j| Complex(@v[j][i-1], -@v[j][i])}
- end
- end
- end
- # Complex scalar division.
-
- def cdiv(xr, xi, yr, yi)
- if (yr.abs > yi.abs)
- r = yi/yr
- d = yr + r*yi
- [(xr + r*xi)/d, (xi - r*xr)/d]
- else
- r = yr/yi
- d = yi + r*yr
- [(r*xr + xi)/d, (r*xi - xr)/d]
- end
- end
-
-
- # Symmetric Householder reduction to tridiagonal form.
-
- def tridiagonalize
-
- # This is derived from the Algol procedures tred2 by
- # Bowdler, Martin, Reinsch, and Wilkinson, Handbook for
- # Auto. Comp., Vol.ii-Linear Algebra, and the corresponding
- # Fortran subroutine in EISPACK.
-
- @size.times do |j|
- @d[j] = @v[@size-1][j]
- end
-
- # Householder reduction to tridiagonal form.
-
- (@size-1).downto(0+1) do |i|
-
- # Scale to avoid under/overflow.
-
- scale = 0.0
- h = 0.0
- i.times do |k|
- scale = scale + @d[k].abs
- end
- if (scale == 0.0)
- @e[i] = @d[i-1]
- i.times do |j|
- @d[j] = @v[i-1][j]
- @v[i][j] = 0.0
- @v[j][i] = 0.0
- end
- else
-
- # Generate Householder vector.
-
- i.times do |k|
- @d[k] /= scale
- h += @d[k] * @d[k]
- end
- f = @d[i-1]
- g = Math.sqrt(h)
- if (f > 0)
- g = -g
- end
- @e[i] = scale * g
- h -= f * g
- @d[i-1] = f - g
- i.times do |j|
- @e[j] = 0.0
- end
-
- # Apply similarity transformation to remaining columns.
-
- i.times do |j|
- f = @d[j]
- @v[j][i] = f
- g = @e[j] + @v[j][j] * f
- (j+1).upto(i-1) do |k|
- g += @v[k][j] * @d[k]
- @e[k] += @v[k][j] * f
- end
- @e[j] = g
- end
- f = 0.0
- i.times do |j|
- @e[j] /= h
- f += @e[j] * @d[j]
- end
- hh = f / (h + h)
- i.times do |j|
- @e[j] -= hh * @d[j]
- end
- i.times do |j|
- f = @d[j]
- g = @e[j]
- j.upto(i-1) do |k|
- @v[k][j] -= (f * @e[k] + g * @d[k])
- end
- @d[j] = @v[i-1][j]
- @v[i][j] = 0.0
- end
- end
- @d[i] = h
- end
-
- # Accumulate transformations.
-
- 0.upto(@size-1-1) do |i|
- @v[@size-1][i] = @v[i][i]
- @v[i][i] = 1.0
- h = @d[i+1]
- if (h != 0.0)
- 0.upto(i) do |k|
- @d[k] = @v[k][i+1] / h
- end
- 0.upto(i) do |j|
- g = 0.0
- 0.upto(i) do |k|
- g += @v[k][i+1] * @v[k][j]
- end
- 0.upto(i) do |k|
- @v[k][j] -= g * @d[k]
- end
- end
- end
- 0.upto(i) do |k|
- @v[k][i+1] = 0.0
- end
- end
- @size.times do |j|
- @d[j] = @v[@size-1][j]
- @v[@size-1][j] = 0.0
- end
- @v[@size-1][@size-1] = 1.0
- @e[0] = 0.0
- end
-
-
- # Symmetric tridiagonal QL algorithm.
-
- def diagonalize
- # This is derived from the Algol procedures tql2, by
- # Bowdler, Martin, Reinsch, and Wilkinson, Handbook for
- # Auto. Comp., Vol.ii-Linear Algebra, and the corresponding
- # Fortran subroutine in EISPACK.
-
- 1.upto(@size-1) do |i|
- @e[i-1] = @e[i]
- end
- @e[@size-1] = 0.0
-
- f = 0.0
- tst1 = 0.0
- eps = Float::EPSILON
- @size.times do |l|
-
- # Find small subdiagonal element
-
- tst1 = [tst1, @d[l].abs + @e[l].abs].max
- m = l
- while (m < @size) do
- if (@e[m].abs <= eps*tst1)
- break
- end
- m+=1
- end
-
- # If m == l, @d[l] is an eigenvalue,
- # otherwise, iterate.
-
- if (m > l)
- iter = 0
- begin
- iter = iter + 1 # (Could check iteration count here.)
-
- # Compute implicit shift
-
- g = @d[l]
- p = (@d[l+1] - g) / (2.0 * @e[l])
- r = Math.hypot(p, 1.0)
- if (p < 0)
- r = -r
- end
- @d[l] = @e[l] / (p + r)
- @d[l+1] = @e[l] * (p + r)
- dl1 = @d[l+1]
- h = g - @d[l]
- (l+2).upto(@size-1) do |i|
- @d[i] -= h
- end
- f += h
-
- # Implicit QL transformation.
-
- p = @d[m]
- c = 1.0
- c2 = c
- c3 = c
- el1 = @e[l+1]
- s = 0.0
- s2 = 0.0
- (m-1).downto(l) do |i|
- c3 = c2
- c2 = c
- s2 = s
- g = c * @e[i]
- h = c * p
- r = Math.hypot(p, @e[i])
- @e[i+1] = s * r
- s = @e[i] / r
- c = p / r
- p = c * @d[i] - s * g
- @d[i+1] = h + s * (c * g + s * @d[i])
-
- # Accumulate transformation.
-
- @size.times do |k|
- h = @v[k][i+1]
- @v[k][i+1] = s * @v[k][i] + c * h
- @v[k][i] = c * @v[k][i] - s * h
- end
- end
- p = -s * s2 * c3 * el1 * @e[l] / dl1
- @e[l] = s * p
- @d[l] = c * p
-
- # Check for convergence.
-
- end while (@e[l].abs > eps*tst1)
- end
- @d[l] = @d[l] + f
- @e[l] = 0.0
- end
-
- # Sort eigenvalues and corresponding vectors.
-
- 0.upto(@size-2) do |i|
- k = i
- p = @d[i]
- (i+1).upto(@size-1) do |j|
- if (@d[j] < p)
- k = j
- p = @d[j]
- end
- end
- if (k != i)
- @d[k] = @d[i]
- @d[i] = p
- @size.times do |j|
- p = @v[j][i]
- @v[j][i] = @v[j][k]
- @v[j][k] = p
- end
- end
- end
- end
-
- # Nonsymmetric reduction to Hessenberg form.
-
- def reduce_to_hessenberg
- # This is derived from the Algol procedures orthes and ortran,
- # by Martin and Wilkinson, Handbook for Auto. Comp.,
- # Vol.ii-Linear Algebra, and the corresponding
- # Fortran subroutines in EISPACK.
-
- low = 0
- high = @size-1
-
- (low+1).upto(high-1) do |m|
-
- # Scale column.
-
- scale = 0.0
- m.upto(high) do |i|
- scale = scale + @h[i][m-1].abs
- end
- if (scale != 0.0)
-
- # Compute Householder transformation.
-
- h = 0.0
- high.downto(m) do |i|
- @ort[i] = @h[i][m-1]/scale
- h += @ort[i] * @ort[i]
- end
- g = Math.sqrt(h)
- if (@ort[m] > 0)
- g = -g
- end
- h -= @ort[m] * g
- @ort[m] = @ort[m] - g
-
- # Apply Householder similarity transformation
- # @h = (I-u*u'/h)*@h*(I-u*u')/h)
-
- m.upto(@size-1) do |j|
- f = 0.0
- high.downto(m) do |i|
- f += @ort[i]*@h[i][j]
- end
- f = f/h
- m.upto(high) do |i|
- @h[i][j] -= f*@ort[i]
- end
- end
-
- 0.upto(high) do |i|
- f = 0.0
- high.downto(m) do |j|
- f += @ort[j]*@h[i][j]
- end
- f = f/h
- m.upto(high) do |j|
- @h[i][j] -= f*@ort[j]
- end
- end
- @ort[m] = scale*@ort[m]
- @h[m][m-1] = scale*g
- end
- end
-
- # Accumulate transformations (Algol's ortran).
-
- @size.times do |i|
- @size.times do |j|
- @v[i][j] = (i == j ? 1.0 : 0.0)
- end
- end
-
- (high-1).downto(low+1) do |m|
- if (@h[m][m-1] != 0.0)
- (m+1).upto(high) do |i|
- @ort[i] = @h[i][m-1]
- end
- m.upto(high) do |j|
- g = 0.0
- m.upto(high) do |i|
- g += @ort[i] * @v[i][j]
- end
- # Double division avoids possible underflow
- g = (g / @ort[m]) / @h[m][m-1]
- m.upto(high) do |i|
- @v[i][j] += g * @ort[i]
- end
- end
- end
- end
- end
-
-
-
- # Nonsymmetric reduction from Hessenberg to real Schur form.
-
- def hessenberg_to_real_schur
-
- # This is derived from the Algol procedure hqr2,
- # by Martin and Wilkinson, Handbook for Auto. Comp.,
- # Vol.ii-Linear Algebra, and the corresponding
- # Fortran subroutine in EISPACK.
-
- # Initialize
-
- nn = @size
- n = nn-1
- low = 0
- high = nn-1
- eps = Float::EPSILON
- exshift = 0.0
- p=q=r=s=z=0
-
- # Store roots isolated by balanc and compute matrix norm
-
- norm = 0.0
- nn.times do |i|
- if (i < low || i > high)
- @d[i] = @h[i][i]
- @e[i] = 0.0
- end
- ([i-1, 0].max).upto(nn-1) do |j|
- norm = norm + @h[i][j].abs
- end
- end
-
- # Outer loop over eigenvalue index
-
- iter = 0
- while (n >= low) do
-
- # Look for single small sub-diagonal element
-
- l = n
- while (l > low) do
- s = @h[l-1][l-1].abs + @h[l][l].abs
- if (s == 0.0)
- s = norm
- end
- if (@h[l][l-1].abs < eps * s)
- break
- end
- l-=1
- end
-
- # Check for convergence
- # One root found
-
- if (l == n)
- @h[n][n] = @h[n][n] + exshift
- @d[n] = @h[n][n]
- @e[n] = 0.0
- n-=1
- iter = 0
-
- # Two roots found
-
- elsif (l == n-1)
- w = @h[n][n-1] * @h[n-1][n]
- p = (@h[n-1][n-1] - @h[n][n]) / 2.0
- q = p * p + w
- z = Math.sqrt(q.abs)
- @h[n][n] = @h[n][n] + exshift
- @h[n-1][n-1] = @h[n-1][n-1] + exshift
- x = @h[n][n]
-
- # Real pair
-
- if (q >= 0)
- if (p >= 0)
- z = p + z
- else
- z = p - z
- end
- @d[n-1] = x + z
- @d[n] = @d[n-1]
- if (z != 0.0)
- @d[n] = x - w / z
- end
- @e[n-1] = 0.0
- @e[n] = 0.0
- x = @h[n][n-1]
- s = x.abs + z.abs
- p = x / s
- q = z / s
- r = Math.sqrt(p * p+q * q)
- p /= r
- q /= r
-
- # Row modification
-
- (n-1).upto(nn-1) do |j|
- z = @h[n-1][j]
- @h[n-1][j] = q * z + p * @h[n][j]
- @h[n][j] = q * @h[n][j] - p * z
- end
-
- # Column modification
-
- 0.upto(n) do |i|
- z = @h[i][n-1]
- @h[i][n-1] = q * z + p * @h[i][n]
- @h[i][n] = q * @h[i][n] - p * z
- end
-
- # Accumulate transformations
-
- low.upto(high) do |i|
- z = @v[i][n-1]
- @v[i][n-1] = q * z + p * @v[i][n]
- @v[i][n] = q * @v[i][n] - p * z
- end
-
- # Complex pair
-
- else
- @d[n-1] = x + p
- @d[n] = x + p
- @e[n-1] = z
- @e[n] = -z
- end
- n -= 2
- iter = 0
-
- # No convergence yet
-
- else
-
- # Form shift
-
- x = @h[n][n]
- y = 0.0
- w = 0.0
- if (l < n)
- y = @h[n-1][n-1]
- w = @h[n][n-1] * @h[n-1][n]
- end
-
- # Wilkinson's original ad hoc shift
-
- if (iter == 10)
- exshift += x
- low.upto(n) do |i|
- @h[i][i] -= x
- end
- s = @h[n][n-1].abs + @h[n-1][n-2].abs
- x = y = 0.75 * s
- w = -0.4375 * s * s
- end
-
- # MATLAB's new ad hoc shift
-
- if (iter == 30)
- s = (y - x) / 2.0
- s *= s + w
- if (s > 0)
- s = Math.sqrt(s)
- if (y < x)
- s = -s
- end
- s = x - w / ((y - x) / 2.0 + s)
- low.upto(n) do |i|
- @h[i][i] -= s
- end
- exshift += s
- x = y = w = 0.964
- end
- end
-
- iter = iter + 1 # (Could check iteration count here.)
-
- # Look for two consecutive small sub-diagonal elements
-
- m = n-2
- while (m >= l) do
- z = @h[m][m]
- r = x - z
- s = y - z
- p = (r * s - w) / @h[m+1][m] + @h[m][m+1]
- q = @h[m+1][m+1] - z - r - s
- r = @h[m+2][m+1]
- s = p.abs + q.abs + r.abs
- p /= s
- q /= s
- r /= s
- if (m == l)
- break
- end
- if (@h[m][m-1].abs * (q.abs + r.abs) <
- eps * (p.abs * (@h[m-1][m-1].abs + z.abs +
- @h[m+1][m+1].abs)))
- break
- end
- m-=1
- end
-
- (m+2).upto(n) do |i|
- @h[i][i-2] = 0.0
- if (i > m+2)
- @h[i][i-3] = 0.0
- end
- end
-
- # Double QR step involving rows l:n and columns m:n
-
- m.upto(n-1) do |k|
- notlast = (k != n-1)
- if (k != m)
- p = @h[k][k-1]
- q = @h[k+1][k-1]
- r = (notlast ? @h[k+2][k-1] : 0.0)
- x = p.abs + q.abs + r.abs
- next if x == 0
- p /= x
- q /= x
- r /= x
- end
- s = Math.sqrt(p * p + q * q + r * r)
- if (p < 0)
- s = -s
- end
- if (s != 0)
- if (k != m)
- @h[k][k-1] = -s * x
- elsif (l != m)
- @h[k][k-1] = -@h[k][k-1]
- end
- p += s
- x = p / s
- y = q / s
- z = r / s
- q /= p
- r /= p
-
- # Row modification
-
- k.upto(nn-1) do |j|
- p = @h[k][j] + q * @h[k+1][j]
- if (notlast)
- p += r * @h[k+2][j]
- @h[k+2][j] = @h[k+2][j] - p * z
- end
- @h[k][j] = @h[k][j] - p * x
- @h[k+1][j] = @h[k+1][j] - p * y
- end
-
- # Column modification
-
- 0.upto([n, k+3].min) do |i|
- p = x * @h[i][k] + y * @h[i][k+1]
- if (notlast)
- p += z * @h[i][k+2]
- @h[i][k+2] = @h[i][k+2] - p * r
- end
- @h[i][k] = @h[i][k] - p
- @h[i][k+1] = @h[i][k+1] - p * q
- end
-
- # Accumulate transformations
-
- low.upto(high) do |i|
- p = x * @v[i][k] + y * @v[i][k+1]
- if (notlast)
- p += z * @v[i][k+2]
- @v[i][k+2] = @v[i][k+2] - p * r
- end
- @v[i][k] = @v[i][k] - p
- @v[i][k+1] = @v[i][k+1] - p * q
- end
- end # (s != 0)
- end # k loop
- end # check convergence
- end # while (n >= low)
-
- # Backsubstitute to find vectors of upper triangular form
-
- if (norm == 0.0)
- return
- end
-
- (nn-1).downto(0) do |n|
- p = @d[n]
- q = @e[n]
-
- # Real vector
-
- if (q == 0)
- l = n
- @h[n][n] = 1.0
- (n-1).downto(0) do |i|
- w = @h[i][i] - p
- r = 0.0
- l.upto(n) do |j|
- r += @h[i][j] * @h[j][n]
- end
- if (@e[i] < 0.0)
- z = w
- s = r
- else
- l = i
- if (@e[i] == 0.0)
- if (w != 0.0)
- @h[i][n] = -r / w
- else
- @h[i][n] = -r / (eps * norm)
- end
-
- # Solve real equations
-
- else
- x = @h[i][i+1]
- y = @h[i+1][i]
- q = (@d[i] - p) * (@d[i] - p) + @e[i] * @e[i]
- t = (x * s - z * r) / q
- @h[i][n] = t
- if (x.abs > z.abs)
- @h[i+1][n] = (-r - w * t) / x
- else
- @h[i+1][n] = (-s - y * t) / z
- end
- end
-
- # Overflow control
-
- t = @h[i][n].abs
- if ((eps * t) * t > 1)
- i.upto(n) do |j|
- @h[j][n] = @h[j][n] / t
- end
- end
- end
- end
-
- # Complex vector
-
- elsif (q < 0)
- l = n-1
-
- # Last vector component imaginary so matrix is triangular
-
- if (@h[n][n-1].abs > @h[n-1][n].abs)
- @h[n-1][n-1] = q / @h[n][n-1]
- @h[n-1][n] = -(@h[n][n] - p) / @h[n][n-1]
- else
- cdivr, cdivi = cdiv(0.0, -@h[n-1][n], @h[n-1][n-1]-p, q)
- @h[n-1][n-1] = cdivr
- @h[n-1][n] = cdivi
- end
- @h[n][n-1] = 0.0
- @h[n][n] = 1.0
- (n-2).downto(0) do |i|
- ra = 0.0
- sa = 0.0
- l.upto(n) do |j|
- ra = ra + @h[i][j] * @h[j][n-1]
- sa = sa + @h[i][j] * @h[j][n]
- end
- w = @h[i][i] - p
-
- if (@e[i] < 0.0)
- z = w
- r = ra
- s = sa
- else
- l = i
- if (@e[i] == 0)
- cdivr, cdivi = cdiv(-ra, -sa, w, q)
- @h[i][n-1] = cdivr
- @h[i][n] = cdivi
- else
-
- # Solve complex equations
-
- x = @h[i][i+1]
- y = @h[i+1][i]
- vr = (@d[i] - p) * (@d[i] - p) + @e[i] * @e[i] - q * q
- vi = (@d[i] - p) * 2.0 * q
- if (vr == 0.0 && vi == 0.0)
- vr = eps * norm * (w.abs + q.abs +
- x.abs + y.abs + z.abs)
- end
- cdivr, cdivi = cdiv(x*r-z*ra+q*sa, x*s-z*sa-q*ra, vr, vi)
- @h[i][n-1] = cdivr
- @h[i][n] = cdivi
- if (x.abs > (z.abs + q.abs))
- @h[i+1][n-1] = (-ra - w * @h[i][n-1] + q * @h[i][n]) / x
- @h[i+1][n] = (-sa - w * @h[i][n] - q * @h[i][n-1]) / x
- else
- cdivr, cdivi = cdiv(-r-y*@h[i][n-1], -s-y*@h[i][n], z, q)
- @h[i+1][n-1] = cdivr
- @h[i+1][n] = cdivi
- end
- end
-
- # Overflow control
-
- t = [@h[i][n-1].abs, @h[i][n].abs].max
- if ((eps * t) * t > 1)
- i.upto(n) do |j|
- @h[j][n-1] = @h[j][n-1] / t
- @h[j][n] = @h[j][n] / t
- end
- end
- end
- end
- end
- end
-
- # Vectors of isolated roots
-
- nn.times do |i|
- if (i < low || i > high)
- i.upto(nn-1) do |j|
- @v[i][j] = @h[i][j]
- end
- end
- end
-
- # Back transformation to get eigenvectors of original matrix
-
- (nn-1).downto(low) do |j|
- low.upto(high) do |i|
- z = 0.0
- low.upto([j, high].min) do |k|
- z += @v[i][k] * @h[k][j]
- end
- @v[i][j] = z
- end
- end
- end
-
- end
-end
diff --git a/ruby_2_2/lib/matrix/lup_decomposition.rb b/ruby_2_2/lib/matrix/lup_decomposition.rb
deleted file mode 100644
index 30f3276253..0000000000
--- a/ruby_2_2/lib/matrix/lup_decomposition.rb
+++ /dev/null
@@ -1,218 +0,0 @@
-class Matrix
- # Adapted from JAMA: http://math.nist.gov/javanumerics/jama/
-
- #
- # For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n
- # unit lower triangular matrix L, an n-by-n upper triangular matrix U,
- # and a m-by-m permutation matrix P so that L*U = P*A.
- # If m < n, then L is m-by-m and U is m-by-n.
- #
- # The LUP decomposition with pivoting always exists, even if the matrix is
- # singular, so the constructor will never fail. The primary use of the
- # LU decomposition is in the solution of square systems of simultaneous
- # linear equations. This will fail if singular? returns true.
- #
-
- class LUPDecomposition
- # Returns the lower triangular factor +L+
-
- include Matrix::ConversionHelper
-
- def l
- Matrix.build(@row_count, [@column_count, @row_count].min) do |i, j|
- if (i > j)
- @lu[i][j]
- elsif (i == j)
- 1
- else
- 0
- end
- end
- end
-
- # Returns the upper triangular factor +U+
-
- def u
- Matrix.build([@column_count, @row_count].min, @column_count) do |i, j|
- if (i <= j)
- @lu[i][j]
- else
- 0
- end
- end
- end
-
- # Returns the permutation matrix +P+
-
- def p
- rows = Array.new(@row_count){Array.new(@row_count, 0)}
- @pivots.each_with_index{|p, i| rows[i][p] = 1}
- Matrix.send :new, rows, @row_count
- end
-
- # Returns +L+, +U+, +P+ in an array
-
- def to_ary
- [l, u, p]
- end
- alias_method :to_a, :to_ary
-
- # Returns the pivoting indices
-
- attr_reader :pivots
-
- # Returns +true+ if +U+, and hence +A+, is singular.
-
- def singular? ()
- @column_count.times do |j|
- if (@lu[j][j] == 0)
- return true
- end
- end
- false
- end
-
- # Returns the determinant of +A+, calculated efficiently
- # from the factorization.
-
- def det
- if (@row_count != @column_count)
- Matrix.Raise Matrix::ErrDimensionMismatch
- end
- d = @pivot_sign
- @column_count.times do |j|
- d *= @lu[j][j]
- end
- d
- end
- alias_method :determinant, :det
-
- # Returns +m+ so that <tt>A*m = b</tt>,
- # or equivalently so that <tt>L*U*m = P*b</tt>
- # +b+ can be a Matrix or a Vector
-
- def solve b
- if (singular?)
- Matrix.Raise Matrix::ErrNotRegular, "Matrix is singular."
- end
- if b.is_a? Matrix
- if (b.row_count != @row_count)
- Matrix.Raise Matrix::ErrDimensionMismatch
- end
-
- # Copy right hand side with pivoting
- nx = b.column_count
- m = @pivots.map{|row| b.row(row).to_a}
-
- # Solve L*Y = P*b
- @column_count.times do |k|
- (k+1).upto(@column_count-1) do |i|
- nx.times do |j|
- m[i][j] -= m[k][j]*@lu[i][k]
- end
- end
- end
- # Solve U*m = Y
- (@column_count-1).downto(0) do |k|
- nx.times do |j|
- m[k][j] = m[k][j].quo(@lu[k][k])
- end
- k.times do |i|
- nx.times do |j|
- m[i][j] -= m[k][j]*@lu[i][k]
- end
- end
- end
- Matrix.send :new, m, nx
- else # same algorithm, specialized for simpler case of a vector
- b = convert_to_array(b)
- if (b.size != @row_count)
- Matrix.Raise Matrix::ErrDimensionMismatch
- end
-
- # Copy right hand side with pivoting
- m = b.values_at(*@pivots)
-
- # Solve L*Y = P*b
- @column_count.times do |k|
- (k+1).upto(@column_count-1) do |i|
- m[i] -= m[k]*@lu[i][k]
- end
- end
- # Solve U*m = Y
- (@column_count-1).downto(0) do |k|
- m[k] = m[k].quo(@lu[k][k])
- k.times do |i|
- m[i] -= m[k]*@lu[i][k]
- end
- end
- Vector.elements(m, false)
- end
- end
-
- def initialize a
- raise TypeError, "Expected Matrix but got #{a.class}" unless a.is_a?(Matrix)
- # Use a "left-looking", dot-product, Crout/Doolittle algorithm.
- @lu = a.to_a
- @row_count = a.row_count
- @column_count = a.column_count
- @pivots = Array.new(@row_count)
- @row_count.times do |i|
- @pivots[i] = i
- end
- @pivot_sign = 1
- lu_col_j = Array.new(@row_count)
-
- # Outer loop.
-
- @column_count.times do |j|
-
- # Make a copy of the j-th column to localize references.
-
- @row_count.times do |i|
- lu_col_j[i] = @lu[i][j]
- end
-
- # Apply previous transformations.
-
- @row_count.times do |i|
- lu_row_i = @lu[i]
-
- # Most of the time is spent in the following dot product.
-
- kmax = [i, j].min
- s = 0
- kmax.times do |k|
- s += lu_row_i[k]*lu_col_j[k]
- end
-
- lu_row_i[j] = lu_col_j[i] -= s
- end
-
- # Find pivot and exchange if necessary.
-
- p = j
- (j+1).upto(@row_count-1) do |i|
- if (lu_col_j[i].abs > lu_col_j[p].abs)
- p = i
- end
- end
- if (p != j)
- @column_count.times do |k|
- t = @lu[p][k]; @lu[p][k] = @lu[j][k]; @lu[j][k] = t
- end
- k = @pivots[p]; @pivots[p] = @pivots[j]; @pivots[j] = k
- @pivot_sign = -@pivot_sign
- end
-
- # Compute multipliers.
-
- if (j < @row_count && @lu[j][j] != 0)
- (j+1).upto(@row_count-1) do |i|
- @lu[i][j] = @lu[i][j].quo(@lu[j][j])
- end
- end
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/mkmf.rb b/ruby_2_2/lib/mkmf.rb
deleted file mode 100644
index d30471ee8e..0000000000
--- a/ruby_2_2/lib/mkmf.rb
+++ /dev/null
@@ -1,2687 +0,0 @@
-# -*- coding: us-ascii -*-
-# module to create Makefile for extension modules
-# invoke like: ruby -r mkmf extconf.rb
-
-require 'rbconfig'
-require 'fileutils'
-require 'shellwords'
-
-# :stopdoc:
-class String
- # Wraps a string in escaped quotes if it contains whitespace.
- def quote
- /\s/ =~ self ? "\"#{self}\"" : "#{self}"
- end
-
- # Escape whitespaces for Makefile.
- def unspace
- gsub(/\s/, '\\\\\\&')
- end
-
- # Generates a string used as cpp macro name.
- def tr_cpp
- strip.upcase.tr_s("^A-Z0-9_*", "_").tr_s("*", "P")
- end
-
- def funcall_style
- /\)\z/ =~ self ? dup : "#{self}()"
- end
-
- def sans_arguments
- self[/\A[^()]+/]
- end
-end
-
-class Array
- # Wraps all strings in escaped quotes if they contain whitespace.
- def quote
- map {|s| s.quote}
- end
-end
-# :startdoc:
-
-##
-# mkmf.rb is used by Ruby C extensions to generate a Makefile which will
-# correctly compile and link the C extension to Ruby and a third-party
-# library.
-module MakeMakefile
- #### defer until this module become global-state free.
- # def self.extended(obj)
- # obj.init_mkmf
- # super
- # end
- #
- # def initialize(*args, rbconfig: RbConfig, **rest)
- # init_mkmf(rbconfig::MAKEFILE_CONFIG, rbconfig::CONFIG)
- # super(*args, **rest)
- # end
-
- ##
- # The makefile configuration using the defaults from when Ruby was built.
-
- CONFIG = RbConfig::MAKEFILE_CONFIG
- ORIG_LIBPATH = ENV['LIB']
-
- ##
- # Extensions for files compiled with a C compiler
-
- C_EXT = %w[c m]
-
- ##
- # Extensions for files complied with a C++ compiler
-
- CXX_EXT = %w[cc mm cxx cpp]
- unless File.exist?(File.join(*File.split(__FILE__).tap {|d, b| b.swapcase}))
- CXX_EXT.concat(%w[C])
- end
-
- ##
- # Extensions for source files
-
- SRC_EXT = C_EXT + CXX_EXT
-
- ##
- # Extensions for header files
-
- HDR_EXT = %w[h hpp]
- $static = nil
- $config_h = '$(arch_hdrdir)/ruby/config.h'
- $default_static = $static
-
- unless defined? $configure_args
- $configure_args = {}
- args = CONFIG["configure_args"]
- if ENV["CONFIGURE_ARGS"]
- args << " " << ENV["CONFIGURE_ARGS"]
- end
- for arg in Shellwords::shellwords(args)
- arg, val = arg.split('=', 2)
- next unless arg
- arg.tr!('_', '-')
- if arg.sub!(/^(?!--)/, '--')
- val or next
- arg.downcase!
- end
- next if /^--(?:top|topsrc|src|cur)dir$/ =~ arg
- $configure_args[arg] = val || true
- end
- for arg in ARGV
- arg, val = arg.split('=', 2)
- next unless arg
- arg.tr!('_', '-')
- if arg.sub!(/^(?!--)/, '--')
- val or next
- arg.downcase!
- end
- $configure_args[arg] = val || true
- end
- end
-
- $libdir = CONFIG["libdir"]
- $rubylibdir = CONFIG["rubylibdir"]
- $archdir = CONFIG["archdir"]
- $sitedir = CONFIG["sitedir"]
- $sitelibdir = CONFIG["sitelibdir"]
- $sitearchdir = CONFIG["sitearchdir"]
- $vendordir = CONFIG["vendordir"]
- $vendorlibdir = CONFIG["vendorlibdir"]
- $vendorarchdir = CONFIG["vendorarchdir"]
-
- $mswin = /mswin/ =~ RUBY_PLATFORM
- $bccwin = /bccwin/ =~ RUBY_PLATFORM
- $mingw = /mingw/ =~ RUBY_PLATFORM
- $cygwin = /cygwin/ =~ RUBY_PLATFORM
- $netbsd = /netbsd/ =~ RUBY_PLATFORM
- $os2 = /os2/ =~ RUBY_PLATFORM
- $beos = /beos/ =~ RUBY_PLATFORM
- $haiku = /haiku/ =~ RUBY_PLATFORM
- $solaris = /solaris/ =~ RUBY_PLATFORM
- $universal = /universal/ =~ RUBY_PLATFORM
- $dest_prefix_pattern = (File::PATH_SEPARATOR == ';' ? /\A([[:alpha:]]:)?/ : /\A/)
-
- # :stopdoc:
-
- def config_string(key, config = CONFIG)
- s = config[key] and !s.empty? and block_given? ? yield(s) : s
- end
- module_function :config_string
-
- def dir_re(dir)
- Regexp.new('\$(?:\('+dir+'\)|\{'+dir+'\})(?:\$(?:\(target_prefix\)|\{target_prefix\}))?')
- end
- module_function :dir_re
-
- def relative_from(path, base)
- dir = File.join(path, "")
- if File.expand_path(dir) == File.expand_path(dir, base)
- path
- else
- File.join(base, path)
- end
- end
-
- INSTALL_DIRS = [
- [dir_re('commondir'), "$(RUBYCOMMONDIR)"],
- [dir_re('sitedir'), "$(RUBYCOMMONDIR)"],
- [dir_re('vendordir'), "$(RUBYCOMMONDIR)"],
- [dir_re('rubylibdir'), "$(RUBYLIBDIR)"],
- [dir_re('archdir'), "$(RUBYARCHDIR)"],
- [dir_re('sitelibdir'), "$(RUBYLIBDIR)"],
- [dir_re('vendorlibdir'), "$(RUBYLIBDIR)"],
- [dir_re('sitearchdir'), "$(RUBYARCHDIR)"],
- [dir_re('vendorarchdir'), "$(RUBYARCHDIR)"],
- [dir_re('rubyhdrdir'), "$(RUBYHDRDIR)"],
- [dir_re('sitehdrdir'), "$(SITEHDRDIR)"],
- [dir_re('vendorhdrdir'), "$(VENDORHDRDIR)"],
- [dir_re('bindir'), "$(BINDIR)"],
- ]
-
- def install_dirs(target_prefix = nil)
- if $extout
- dirs = [
- ['BINDIR', '$(extout)/bin'],
- ['RUBYCOMMONDIR', '$(extout)/common'],
- ['RUBYLIBDIR', '$(RUBYCOMMONDIR)$(target_prefix)'],
- ['RUBYARCHDIR', '$(extout)/$(arch)$(target_prefix)'],
- ['HDRDIR', '$(extout)/include/ruby$(target_prefix)'],
- ['ARCHHDRDIR', '$(extout)/include/$(arch)/ruby$(target_prefix)'],
- ['extout', "#$extout"],
- ['extout_prefix', "#$extout_prefix"],
- ]
- elsif $extmk
- dirs = [
- ['BINDIR', '$(bindir)'],
- ['RUBYCOMMONDIR', '$(rubylibdir)'],
- ['RUBYLIBDIR', '$(rubylibdir)$(target_prefix)'],
- ['RUBYARCHDIR', '$(archdir)$(target_prefix)'],
- ['HDRDIR', '$(rubyhdrdir)/ruby$(target_prefix)'],
- ['ARCHHDRDIR', '$(rubyhdrdir)/$(arch)/ruby$(target_prefix)'],
- ]
- elsif $configure_args.has_key?('--vendor')
- dirs = [
- ['BINDIR', '$(bindir)'],
- ['RUBYCOMMONDIR', '$(vendordir)$(target_prefix)'],
- ['RUBYLIBDIR', '$(vendorlibdir)$(target_prefix)'],
- ['RUBYARCHDIR', '$(vendorarchdir)$(target_prefix)'],
- ['HDRDIR', '$(rubyhdrdir)/ruby$(target_prefix)'],
- ['ARCHHDRDIR', '$(rubyhdrdir)/$(arch)/ruby$(target_prefix)'],
- ]
- else
- dirs = [
- ['BINDIR', '$(bindir)'],
- ['RUBYCOMMONDIR', '$(sitedir)$(target_prefix)'],
- ['RUBYLIBDIR', '$(sitelibdir)$(target_prefix)'],
- ['RUBYARCHDIR', '$(sitearchdir)$(target_prefix)'],
- ['HDRDIR', '$(rubyhdrdir)/ruby$(target_prefix)'],
- ['ARCHHDRDIR', '$(rubyhdrdir)/$(arch)/ruby$(target_prefix)'],
- ]
- end
- dirs << ['target_prefix', (target_prefix ? "/#{target_prefix}" : "")]
- dirs
- end
-
- def map_dir(dir, map = nil)
- map ||= INSTALL_DIRS
- map.inject(dir) {|d, (orig, new)| d.gsub(orig, new)}
- end
-
- topdir = File.dirname(File.dirname(__FILE__))
- path = File.expand_path($0)
- until (dir = File.dirname(path)) == path
- if File.identical?(dir, topdir)
- $extmk = true if %r"\A(?:ext|enc|tool|test)\z" =~ File.basename(path)
- break
- end
- path = dir
- end
- $extmk ||= false
- if not $extmk and File.exist?(($hdrdir = RbConfig::CONFIG["rubyhdrdir"]) + "/ruby/ruby.h")
- $topdir = $hdrdir
- $top_srcdir = $hdrdir
- $arch_hdrdir = RbConfig::CONFIG["rubyarchhdrdir"]
- elsif File.exist?(($hdrdir = ($top_srcdir ||= topdir) + "/include") + "/ruby.h")
- $topdir ||= RbConfig::CONFIG["topdir"]
- $arch_hdrdir = "$(extout)/include/$(arch)"
- else
- abort "mkmf.rb can't find header files for ruby at #{$hdrdir}/ruby.h"
- end
-
- CONFTEST = "conftest".freeze
- CONFTEST_C = "#{CONFTEST}.c"
-
- OUTFLAG = CONFIG['OUTFLAG']
- COUTFLAG = CONFIG['COUTFLAG']
- CPPOUTFILE = config_string('CPPOUTFILE') {|str| str.sub(/\bconftest\b/, CONFTEST)}
-
- def rm_f(*files)
- opt = (Hash === files.last ? [files.pop] : [])
- FileUtils.rm_f(Dir[*files.flatten], *opt)
- end
- module_function :rm_f
-
- def rm_rf(*files)
- opt = (Hash === files.last ? [files.pop] : [])
- FileUtils.rm_rf(Dir[*files.flatten], *opt)
- end
- module_function :rm_rf
-
- # Returns time stamp of the +target+ file if it exists and is newer than or
- # equal to all of +times+.
- def modified?(target, times)
- (t = File.mtime(target)) rescue return nil
- Array === times or times = [times]
- t if times.all? {|n| n <= t}
- end
-
- def split_libs(*strs)
- strs.map {|s| s.split(/\s+(?=-|\z)/)}.flatten
- end
-
- def merge_libs(*libs)
- libs.inject([]) do |x, y|
- y = y.inject([]) {|ary, e| ary.last == e ? ary : ary << e}
- y.each_with_index do |v, yi|
- if xi = x.rindex(v)
- x[(xi+1)..-1] = merge_libs(y[(yi+1)..-1], x[(xi+1)..-1])
- x[xi, 0] = y[0...yi]
- break
- end
- end and x.concat(y)
- x
- end
- end
-
- # This is a custom logging module. It generates an mkmf.log file when you
- # run your extconf.rb script. This can be useful for debugging unexpected
- # failures.
- #
- # This module and its associated methods are meant for internal use only.
- #
- module Logging
- @log = nil
- @logfile = 'mkmf.log'
- @orgerr = $stderr.dup
- @orgout = $stdout.dup
- @postpone = 0
- @quiet = $extmk
-
- def self::log_open
- @log ||= File::open(@logfile, 'wb')
- @log.sync = true
- end
-
- def self::log_opened?
- @log and not @log.closed?
- end
-
- def self::open
- log_open
- $stderr.reopen(@log)
- $stdout.reopen(@log)
- yield
- ensure
- $stderr.reopen(@orgerr)
- $stdout.reopen(@orgout)
- end
-
- def self::message(*s)
- log_open
- @log.printf(*s)
- end
-
- def self::logfile file
- @logfile = file
- log_close
- end
-
- def self::log_close
- if @log and not @log.closed?
- @log.flush
- @log.close
- @log = nil
- end
- end
-
- def self::postpone
- tmplog = "mkmftmp#{@postpone += 1}.log"
- open do
- log, *save = @log, @logfile, @orgout, @orgerr
- @log, @logfile, @orgout, @orgerr = nil, tmplog, log, log
- begin
- log.print(open {yield @log})
- ensure
- @log.close if @log and not @log.closed?
- File::open(tmplog) {|t| FileUtils.copy_stream(t, log)} if File.exist?(tmplog)
- @log, @logfile, @orgout, @orgerr = log, *save
- @postpone -= 1
- MakeMakefile.rm_f tmplog
- end
- end
- end
-
- class << self
- attr_accessor :quiet
- end
- end
-
- def libpath_env
- # used only if native compiling
- if libpathenv = config_string("LIBPATHENV")
- pathenv = ENV[libpathenv]
- libpath = RbConfig.expand($DEFLIBPATH.join(File::PATH_SEPARATOR))
- {libpathenv => [libpath, pathenv].compact.join(File::PATH_SEPARATOR)}
- else
- {}
- end
- end
-
- def xsystem command, opts = nil
- varpat = /\$\((\w+)\)|\$\{(\w+)\}/
- if varpat =~ command
- vars = Hash.new {|h, k| h[k] = ENV[k]}
- command = command.dup
- nil while command.gsub!(varpat) {vars[$1||$2]}
- end
- Logging::open do
- puts command.quote
- if opts and opts[:werror]
- result = nil
- Logging.postpone do |log|
- result = (system(libpath_env, command) and File.zero?(log.path))
- ""
- end
- result
- else
- system(libpath_env, command)
- end
- end
- end
-
- def xpopen command, *mode, &block
- Logging::open do
- case mode[0]
- when nil, /^r/
- puts "#{command} |"
- else
- puts "| #{command}"
- end
- IO.popen(libpath_env, command, *mode, &block)
- end
- end
-
- def log_src(src, heading="checked program was")
- src = src.split(/^/)
- fmt = "%#{src.size.to_s.size}d: %s"
- Logging::message <<"EOM"
-#{heading}:
-/* begin */
-EOM
- src.each_with_index {|line, no| Logging::message fmt, no+1, line}
- Logging::message <<"EOM"
-/* end */
-
-EOM
- end
-
- def create_tmpsrc(src)
- src = "#{COMMON_HEADERS}\n#{src}"
- src = yield(src) if block_given?
- src.gsub!(/[ \t]+$/, '')
- src.gsub!(/\A\n+|^\n+$/, '')
- src.sub!(/[^\n]\z/, "\\&\n")
- count = 0
- begin
- open(CONFTEST_C, "wb") do |cfile|
- cfile.print src
- end
- rescue Errno::EACCES
- if (count += 1) < 5
- sleep 0.2
- retry
- end
- end
- src
- end
-
- def have_devel?
- unless defined? $have_devel
- $have_devel = true
- $have_devel = try_link(MAIN_DOES_NOTHING)
- end
- $have_devel
- end
-
- def try_do(src, command, *opts, &b)
- unless have_devel?
- raise <<MSG
-The compiler failed to generate an executable file.
-You have to install development tools first.
-MSG
- end
- begin
- src = create_tmpsrc(src, &b)
- xsystem(command, *opts)
- ensure
- log_src(src)
- MakeMakefile.rm_rf "#{CONFTEST}.dSYM"
- end
- end
-
- def link_command(ldflags, opt="", libpath=$LIBPATH|$DEFLIBPATH)
- librubyarg = $extmk ? $LIBRUBYARG_STATIC : "$(LIBRUBYARG)"
- conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote,
- 'src' => "#{CONFTEST_C}",
- 'arch_hdrdir' => $arch_hdrdir.quote,
- 'top_srcdir' => $top_srcdir.quote,
- 'INCFLAGS' => "#$INCFLAGS",
- 'CPPFLAGS' => "#$CPPFLAGS",
- 'CFLAGS' => "#$CFLAGS",
- 'ARCH_FLAG' => "#$ARCH_FLAG",
- 'LDFLAGS' => "#$LDFLAGS #{ldflags}",
- 'LOCAL_LIBS' => "#$LOCAL_LIBS #$libs",
- 'LIBS' => "#{librubyarg} #{opt} #$LIBS")
- conf['LIBPATH'] = libpathflag(libpath.map {|s| RbConfig::expand(s.dup, conf)})
- RbConfig::expand(TRY_LINK.dup, conf)
- end
-
- def cc_command(opt="")
- conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote,
- 'arch_hdrdir' => $arch_hdrdir.quote,
- 'top_srcdir' => $top_srcdir.quote)
- RbConfig::expand("$(CC) #$INCFLAGS #$CPPFLAGS #$CFLAGS #$ARCH_FLAG #{opt} -c #{CONFTEST_C}",
- conf)
- end
-
- def cpp_command(outfile, opt="")
- conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote,
- 'arch_hdrdir' => $arch_hdrdir.quote,
- 'top_srcdir' => $top_srcdir.quote)
- if $universal and (arch_flag = conf['ARCH_FLAG']) and !arch_flag.empty?
- conf['ARCH_FLAG'] = arch_flag.gsub(/(?:\G|\s)-arch\s+\S+/, '')
- end
- RbConfig::expand("$(CPP) #$INCFLAGS #$CPPFLAGS #$CFLAGS #{opt} #{CONFTEST_C} #{outfile}",
- conf)
- end
-
- def libpathflag(libpath=$LIBPATH|$DEFLIBPATH)
- libpath.map{|x|
- case x
- when "$(topdir)", /\A\./
- LIBPATHFLAG
- else
- LIBPATHFLAG+RPATHFLAG
- end % x.quote
- }.join
- end
-
- def with_werror(opt, opts = nil)
- if opts
- if opts[:werror] and config_string("WERRORFLAG") {|flag| opt = opt ? "#{opt} #{flag}" : flag}
- (opts = opts.dup).delete(:werror)
- end
- yield(opt, opts)
- else
- yield(opt)
- end
- end
-
- def try_link0(src, opt="", *opts, &b) # :nodoc:
- cmd = link_command("", opt)
- if $universal
- require 'tmpdir'
- Dir.mktmpdir("mkmf_", oldtmpdir = ENV["TMPDIR"]) do |tmpdir|
- begin
- ENV["TMPDIR"] = tmpdir
- try_do(src, cmd, *opts, &b)
- ensure
- ENV["TMPDIR"] = oldtmpdir
- end
- end
- else
- try_do(src, cmd, *opts, &b)
- end and File.executable?(CONFTEST+$EXEEXT)
- end
-
- # Returns whether or not the +src+ can be compiled as a C source and linked
- # with its depending libraries successfully. +opt+ is passed to the linker
- # as options. Note that +$CFLAGS+ and +$LDFLAGS+ are also passed to the
- # linker.
- #
- # If a block given, it is called with the source before compilation. You can
- # modify the source in the block.
- #
- # [+src+] a String which contains a C source
- # [+opt+] a String which contains linker options
- def try_link(src, opt="", *opts, &b)
- try_link0(src, opt, *opts, &b)
- ensure
- MakeMakefile.rm_f "#{CONFTEST}*", "c0x32*"
- end
-
- # Returns whether or not the +src+ can be compiled as a C source. +opt+ is
- # passed to the C compiler as options. Note that +$CFLAGS+ is also passed to
- # the compiler.
- #
- # If a block given, it is called with the source before compilation. You can
- # modify the source in the block.
- #
- # [+src+] a String which contains a C source
- # [+opt+] a String which contains compiler options
- def try_compile(src, opt="", *opts, &b)
- with_werror(opt, *opts) {|_opt, *_opts| try_do(src, cc_command(_opt), *_opts, &b)} and
- File.file?("#{CONFTEST}.#{$OBJEXT}")
- ensure
- MakeMakefile.rm_f "#{CONFTEST}*"
- end
-
- # Returns whether or not the +src+ can be preprocessed with the C
- # preprocessor. +opt+ is passed to the preprocessor as options. Note that
- # +$CFLAGS+ is also passed to the preprocessor.
- #
- # If a block given, it is called with the source before preprocessing. You
- # can modify the source in the block.
- #
- # [+src+] a String which contains a C source
- # [+opt+] a String which contains preprocessor options
- def try_cpp(src, opt="", *opts, &b)
- try_do(src, cpp_command(CPPOUTFILE, opt), *opts, &b) and
- File.file?("#{CONFTEST}.i")
- ensure
- MakeMakefile.rm_f "#{CONFTEST}*"
- end
-
- alias_method :try_header, (config_string('try_header') || :try_cpp)
-
- def cpp_include(header)
- if header
- header = [header] unless header.kind_of? Array
- header.map {|h| String === h ? "#include <#{h}>\n" : h}.join
- else
- ""
- end
- end
-
- def with_cppflags(flags)
- cppflags = $CPPFLAGS
- $CPPFLAGS = flags
- ret = yield
- ensure
- $CPPFLAGS = cppflags unless ret
- end
-
- def try_cppflags(flags)
- try_header(MAIN_DOES_NOTHING, flags)
- end
-
- def with_cflags(flags)
- cflags = $CFLAGS
- $CFLAGS = flags
- ret = yield
- ensure
- $CFLAGS = cflags unless ret
- end
-
- def try_cflags(flags)
- try_compile(MAIN_DOES_NOTHING, flags)
- end
-
- def with_ldflags(flags)
- ldflags = $LDFLAGS
- $LDFLAGS = flags
- ret = yield
- ensure
- $LDFLAGS = ldflags unless ret
- end
-
- def try_ldflags(flags)
- try_link(MAIN_DOES_NOTHING, flags)
- end
-
- def try_static_assert(expr, headers = nil, opt = "", &b)
- headers = cpp_include(headers)
- try_compile(<<SRC, opt, &b)
-#{headers}
-/*top*/
-int conftest_const[(#{expr}) ? 1 : -1];
-SRC
- end
-
- def try_constant(const, headers = nil, opt = "", &b)
- includes = cpp_include(headers)
- neg = try_static_assert("#{const} < 0", headers, opt)
- if CROSS_COMPILING
- if neg
- const = "-(#{const})"
- elsif try_static_assert("#{const} > 0", headers, opt)
- # positive constant
- elsif try_static_assert("#{const} == 0", headers, opt)
- return 0
- else
- # not a constant
- return nil
- end
- upper = 1
- until try_static_assert("#{const} <= #{upper}", headers, opt)
- lower = upper
- upper <<= 1
- end
- return nil unless lower
- while upper > lower + 1
- mid = (upper + lower) / 2
- if try_static_assert("#{const} > #{mid}", headers, opt)
- lower = mid
- else
- upper = mid
- end
- end
- upper = -upper if neg
- return upper
- else
- src = %{#{includes}
-#include <stdio.h>
-/*top*/
-typedef#{neg ? '' : ' unsigned'}
-#ifdef PRI_LL_PREFIX
-#define PRI_CONFTEST_PREFIX PRI_LL_PREFIX
-LONG_LONG
-#else
-#define PRI_CONFTEST_PREFIX "l"
-long
-#endif
-conftest_type;
-conftest_type conftest_const = (conftest_type)(#{const});
-int main() {printf("%"PRI_CONFTEST_PREFIX"#{neg ? 'd' : 'u'}\\n", conftest_const); return 0;}
-}
- begin
- if try_link0(src, opt, &b)
- xpopen("./#{CONFTEST}") do |f|
- return Integer(f.gets)
- end
- end
- ensure
- MakeMakefile.rm_f "#{CONFTEST}*"
- end
- end
- nil
- end
-
- # You should use +have_func+ rather than +try_func+.
- #
- # [+func+] a String which contains a symbol name
- # [+libs+] a String which contains library names.
- # [+headers+] a String or an Array of strings which contains names of header
- # files.
- def try_func(func, libs, headers = nil, opt = "", &b)
- headers = cpp_include(headers)
- case func
- when /^&/
- decltype = proc {|x|"const volatile void *#{x}"}
- when /\)$/
- call = func
- else
- call = "#{func}()"
- decltype = proc {|x| "void ((*#{x})())"}
- end
- if opt and !opt.empty?
- [[:to_str], [:join, " "], [:to_s]].each do |meth, *args|
- if opt.respond_to?(meth)
- break opt = opt.send(meth, *args)
- end
- end
- opt = "#{opt} #{libs}"
- else
- opt = libs
- end
- decltype && try_link(<<"SRC", opt, &b) or
-#{headers}
-/*top*/
-extern int t(void);
-#{MAIN_DOES_NOTHING 't'}
-int t(void) { #{decltype["volatile p"]}; p = (#{decltype[]})#{func}; return 0; }
-SRC
- call && try_link(<<"SRC", opt, &b)
-#{headers}
-/*top*/
-extern int t(void);
-#{MAIN_DOES_NOTHING 't'}
-int t(void) { #{call}; return 0; }
-SRC
- end
-
- # You should use +have_var+ rather than +try_var+.
- def try_var(var, headers = nil, opt = "", &b)
- headers = cpp_include(headers)
- try_compile(<<"SRC", opt, &b)
-#{headers}
-/*top*/
-extern int t(void);
-#{MAIN_DOES_NOTHING 't'}
-int t(void) { const volatile void *volatile p; p = &(&#{var})[0]; return 0; }
-SRC
- end
-
- # Returns whether or not the +src+ can be preprocessed with the C
- # preprocessor and matches with +pat+.
- #
- # If a block given, it is called with the source before compilation. You can
- # modify the source in the block.
- #
- # [+pat+] a Regexp or a String
- # [+src+] a String which contains a C source
- # [+opt+] a String which contains preprocessor options
- #
- # NOTE: When pat is a Regexp the matching will be checked in process,
- # otherwise egrep(1) will be invoked to check it.
- def egrep_cpp(pat, src, opt = "", &b)
- src = create_tmpsrc(src, &b)
- xpopen(cpp_command('', opt)) do |f|
- if Regexp === pat
- puts(" ruby -ne 'print if #{pat.inspect}'")
- f.grep(pat) {|l|
- puts "#{f.lineno}: #{l}"
- return true
- }
- false
- else
- puts(" egrep '#{pat}'")
- begin
- stdin = $stdin.dup
- $stdin.reopen(f)
- system("egrep", pat)
- ensure
- $stdin.reopen(stdin)
- end
- end
- end
- ensure
- MakeMakefile.rm_f "#{CONFTEST}*"
- log_src(src)
- end
-
- # This is used internally by the have_macro? method.
- def macro_defined?(macro, src, opt = "", &b)
- src = src.sub(/[^\n]\z/, "\\&\n")
- try_compile(src + <<"SRC", opt, &b)
-/*top*/
-#ifndef #{macro}
-# error
-|:/ === #{macro} undefined === /:|
-#endif
-SRC
- end
-
- # Returns whether or not:
- # * the +src+ can be compiled as a C source,
- # * the result object can be linked with its depending libraries
- # successfully,
- # * the linked file can be invoked as an executable
- # * and the executable exits successfully
- #
- # +opt+ is passed to the linker as options. Note that +$CFLAGS+ and
- # +$LDFLAGS+ are also passed to the linker.
- #
- # If a block given, it is called with the source before compilation. You can
- # modify the source in the block.
- #
- # [+src+] a String which contains a C source
- # [+opt+] a String which contains linker options
- #
- # Returns true when the executable exits successfully, false when it fails,
- # or nil when preprocessing, compilation or link fails.
- def try_run(src, opt = "", &b)
- raise "cannot run test program while cross compiling" if CROSS_COMPILING
- if try_link0(src, opt, &b)
- xsystem("./#{CONFTEST}")
- else
- nil
- end
- ensure
- MakeMakefile.rm_f "#{CONFTEST}*"
- end
-
- def install_files(mfile, ifiles, map = nil, srcprefix = nil)
- ifiles or return
- ifiles.empty? and return
- srcprefix ||= "$(srcdir)/#{srcprefix}".chomp('/')
- RbConfig::expand(srcdir = srcprefix.dup)
- dirs = []
- path = Hash.new {|h, i| h[i] = dirs.push([i])[-1]}
- ifiles.each do |files, dir, prefix|
- dir = map_dir(dir, map)
- prefix &&= %r|\A#{Regexp.quote(prefix)}/?|
- if /\A\.\// =~ files
- # install files which are in current working directory.
- files = files[2..-1]
- len = nil
- else
- # install files which are under the $(srcdir).
- files = File.join(srcdir, files)
- len = srcdir.size
- end
- f = nil
- Dir.glob(files) do |fx|
- f = fx
- f[0..len] = "" if len
- case File.basename(f)
- when *$NONINSTALLFILES
- next
- end
- d = File.dirname(f)
- d.sub!(prefix, "") if prefix
- d = (d.empty? || d == ".") ? dir : File.join(dir, d)
- f = File.join(srcprefix, f) if len
- path[d] << f
- end
- unless len or f
- d = File.dirname(files)
- d.sub!(prefix, "") if prefix
- d = (d.empty? || d == ".") ? dir : File.join(dir, d)
- path[d] << files
- end
- end
- dirs
- end
-
- def install_rb(mfile, dest, srcdir = nil)
- install_files(mfile, [["lib/**/*.rb", dest, "lib"]], nil, srcdir)
- end
-
- def append_library(libs, lib) # :no-doc:
- format(LIBARG, lib) + " " + libs
- end
-
- def message(*s)
- unless Logging.quiet and not $VERBOSE
- printf(*s)
- $stdout.flush
- end
- end
-
- # This emits a string to stdout that allows users to see the results of the
- # various have* and find* methods as they are tested.
- #
- # Internal use only.
- #
- def checking_for(m, fmt = nil)
- f = caller[0][/in `([^<].*)'$/, 1] and f << ": " #` for vim #'
- m = "checking #{/\Acheck/ =~ f ? '' : 'for '}#{m}... "
- message "%s", m
- a = r = nil
- Logging::postpone do
- r = yield
- a = (fmt ? "#{fmt % r}" : r ? "yes" : "no") << "\n"
- "#{f}#{m}-------------------- #{a}\n"
- end
- message(a)
- Logging::message "--------------------\n\n"
- r
- end
-
- def checking_message(target, place = nil, opt = nil)
- [["in", place], ["with", opt]].inject("#{target}") do |msg, (pre, noun)|
- if noun
- [[:to_str], [:join, ","], [:to_s]].each do |meth, *args|
- if noun.respond_to?(meth)
- break noun = noun.send(meth, *args)
- end
- end
- msg << " #{pre} #{noun}" unless noun.empty?
- end
- msg
- end
- end
-
- # :startdoc:
-
- # Returns whether or not +macro+ is defined either in the common header
- # files or within any +headers+ you provide.
- #
- # Any options you pass to +opt+ are passed along to the compiler.
- #
- def have_macro(macro, headers = nil, opt = "", &b)
- checking_for checking_message(macro, headers, opt) do
- macro_defined?(macro, cpp_include(headers), opt, &b)
- end
- end
-
- # Returns whether or not the given entry point +func+ can be found within
- # +lib+. If +func+ is +nil+, the <code>main()</code> entry point is used by
- # default. If found, it adds the library to list of libraries to be used
- # when linking your extension.
- #
- # If +headers+ are provided, it will include those header files as the
- # header files it looks in when searching for +func+.
- #
- # The real name of the library to be linked can be altered by
- # <code>--with-FOOlib</code> configuration option.
- #
- def have_library(lib, func = nil, headers = nil, opt = "", &b)
- func = "main" if !func or func.empty?
- lib = with_config(lib+'lib', lib)
- checking_for checking_message(func.funcall_style, LIBARG%lib, opt) do
- if COMMON_LIBS.include?(lib)
- true
- else
- libs = append_library($libs, lib)
- if try_func(func, libs, headers, opt, &b)
- $libs = libs
- true
- else
- false
- end
- end
- end
- end
-
- # Returns whether or not the entry point +func+ can be found within the
- # library +lib+ in one of the +paths+ specified, where +paths+ is an array
- # of strings. If +func+ is +nil+ , then the <code>main()</code> function is
- # used as the entry point.
- #
- # If +lib+ is found, then the path it was found on is added to the list of
- # library paths searched and linked against.
- #
- def find_library(lib, func, *paths, &b)
- func = "main" if !func or func.empty?
- lib = with_config(lib+'lib', lib)
- paths = paths.collect {|path| path.split(File::PATH_SEPARATOR)}.flatten
- checking_for checking_message(func.funcall_style, LIBARG%lib) do
- libpath = $LIBPATH
- libs = append_library($libs, lib)
- begin
- until r = try_func(func, libs, &b) or paths.empty?
- $LIBPATH = libpath | [paths.shift]
- end
- if r
- $libs = libs
- libpath = nil
- end
- ensure
- $LIBPATH = libpath if libpath
- end
- r
- end
- end
-
- # Returns whether or not the function +func+ can be found in the common
- # header files, or within any +headers+ that you provide. If found, a macro
- # is passed as a preprocessor constant to the compiler using the function
- # name, in uppercase, prepended with +HAVE_+.
- #
- # To check functions in an additional library, you need to check that
- # library first using <code>have_library()</code>. The +func+ shall be
- # either mere function name or function name with arguments.
- #
- # For example, if <code>have_func('foo')</code> returned +true+, then the
- # +HAVE_FOO+ preprocessor macro would be passed to the compiler.
- #
- def have_func(func, headers = nil, opt = "", &b)
- checking_for checking_message(func.funcall_style, headers, opt) do
- if try_func(func, $libs, headers, opt, &b)
- $defs << "-DHAVE_#{func.sans_arguments.tr_cpp}"
- true
- else
- false
- end
- end
- end
-
- # Returns whether or not the variable +var+ can be found in the common
- # header files, or within any +headers+ that you provide. If found, a macro
- # is passed as a preprocessor constant to the compiler using the variable
- # name, in uppercase, prepended with +HAVE_+.
- #
- # To check variables in an additional library, you need to check that
- # library first using <code>have_library()</code>.
- #
- # For example, if <code>have_var('foo')</code> returned true, then the
- # +HAVE_FOO+ preprocessor macro would be passed to the compiler.
- #
- def have_var(var, headers = nil, opt = "", &b)
- checking_for checking_message(var, headers, opt) do
- if try_var(var, headers, opt, &b)
- $defs.push(format("-DHAVE_%s", var.tr_cpp))
- true
- else
- false
- end
- end
- end
-
- # Returns whether or not the given +header+ file can be found on your system.
- # If found, a macro is passed as a preprocessor constant to the compiler
- # using the header file name, in uppercase, prepended with +HAVE_+.
- #
- # For example, if <code>have_header('foo.h')</code> returned true, then the
- # +HAVE_FOO_H+ preprocessor macro would be passed to the compiler.
- #
- def have_header(header, preheaders = nil, opt = "", &b)
- checking_for header do
- if try_header(cpp_include(preheaders)+cpp_include(header), opt, &b)
- $defs.push(format("-DHAVE_%s", header.tr_cpp))
- true
- else
- false
- end
- end
- end
-
- # Returns whether or not the given +framework+ can be found on your system.
- # If found, a macro is passed as a preprocessor constant to the compiler
- # using the framework name, in uppercase, prepended with +HAVE_FRAMEWORK_+.
- #
- # For example, if <code>have_framework('Ruby')</code> returned true, then
- # the +HAVE_FRAMEWORK_RUBY+ preprocessor macro would be passed to the
- # compiler.
- #
- # If +fw+ is a pair of the framework name and its header file name
- # that header file is checked, instead of the normally used header
- # file which is named same as the framework.
- def have_framework(fw, &b)
- if Array === fw
- fw, header = *fw
- else
- header = "#{fw}.h"
- end
- checking_for fw do
- src = cpp_include("#{fw}/#{header}") << "\n" "int main(void){return 0;}"
- opt = " -framework #{fw}"
- if try_link(src, opt, &b) or (objc = try_link(src, "-ObjC#{opt}", &b))
- $defs.push(format("-DHAVE_FRAMEWORK_%s", fw.tr_cpp))
- # TODO: non-worse way than this hack, to get rid of separating
- # option and its argument.
- $LDFLAGS << " -ObjC" if objc and /(\A|\s)-ObjC(\s|\z)/ !~ $LDFLAGS
- $LIBS << opt
- true
- else
- false
- end
- end
- end
-
- # Instructs mkmf to search for the given +header+ in any of the +paths+
- # provided, and returns whether or not it was found in those paths.
- #
- # If the header is found then the path it was found on is added to the list
- # of included directories that are sent to the compiler (via the
- # <code>-I</code> switch).
- #
- def find_header(header, *paths)
- message = checking_message(header, paths)
- header = cpp_include(header)
- checking_for message do
- if try_header(header)
- true
- else
- found = false
- paths.each do |dir|
- opt = "-I#{dir}".quote
- if try_header(header, opt)
- $INCFLAGS << " " << opt
- found = true
- break
- end
- end
- found
- end
- end
- end
-
- # Returns whether or not the struct of type +type+ contains +member+. If
- # it does not, or the struct type can't be found, then false is returned.
- # You may optionally specify additional +headers+ in which to look for the
- # struct (in addition to the common header files).
- #
- # If found, a macro is passed as a preprocessor constant to the compiler
- # using the type name and the member name, in uppercase, prepended with
- # +HAVE_+.
- #
- # For example, if <code>have_struct_member('struct foo', 'bar')</code>
- # returned true, then the +HAVE_STRUCT_FOO_BAR+ preprocessor macro would be
- # passed to the compiler.
- #
- # +HAVE_ST_BAR+ is also defined for backward compatibility.
- #
- def have_struct_member(type, member, headers = nil, opt = "", &b)
- checking_for checking_message("#{type}.#{member}", headers) do
- if try_compile(<<"SRC", opt, &b)
-#{cpp_include(headers)}
-/*top*/
-int s = (char *)&((#{type}*)0)->#{member} - (char *)0;
-#{MAIN_DOES_NOTHING}
-SRC
- $defs.push(format("-DHAVE_%s_%s", type.tr_cpp, member.tr_cpp))
- $defs.push(format("-DHAVE_ST_%s", member.tr_cpp)) # backward compatibility
- true
- else
- false
- end
- end
- end
-
- # Returns whether or not the static type +type+ is defined.
- #
- # See also +have_type+
- #
- def try_type(type, headers = nil, opt = "", &b)
- if try_compile(<<"SRC", opt, &b)
-#{cpp_include(headers)}
-/*top*/
-typedef #{type} conftest_type;
-int conftestval[sizeof(conftest_type)?1:-1];
-SRC
- $defs.push(format("-DHAVE_TYPE_%s", type.tr_cpp))
- true
- else
- false
- end
- end
-
- # Returns whether or not the static type +type+ is defined. You may
- # optionally pass additional +headers+ to check against in addition to the
- # common header files.
- #
- # You may also pass additional flags to +opt+ which are then passed along to
- # the compiler.
- #
- # If found, a macro is passed as a preprocessor constant to the compiler
- # using the type name, in uppercase, prepended with +HAVE_TYPE_+.
- #
- # For example, if <code>have_type('foo')</code> returned true, then the
- # +HAVE_TYPE_FOO+ preprocessor macro would be passed to the compiler.
- #
- def have_type(type, headers = nil, opt = "", &b)
- checking_for checking_message(type, headers, opt) do
- try_type(type, headers, opt, &b)
- end
- end
-
- # Returns where the static type +type+ is defined.
- #
- # You may also pass additional flags to +opt+ which are then passed along to
- # the compiler.
- #
- # See also +have_type+.
- #
- def find_type(type, opt, *headers, &b)
- opt ||= ""
- fmt = "not found"
- def fmt.%(x)
- x ? x.respond_to?(:join) ? x.join(",") : x : self
- end
- checking_for checking_message(type, nil, opt), fmt do
- headers.find do |h|
- try_type(type, h, opt, &b)
- end
- end
- end
-
- # Returns whether or not the constant +const+ is defined.
- #
- # See also +have_const+
- #
- def try_const(const, headers = nil, opt = "", &b)
- const, type = *const
- if try_compile(<<"SRC", opt, &b)
-#{cpp_include(headers)}
-/*top*/
-typedef #{type || 'int'} conftest_type;
-conftest_type conftestval = #{type ? '' : '(int)'}#{const};
-SRC
- $defs.push(format("-DHAVE_CONST_%s", const.tr_cpp))
- true
- else
- false
- end
- end
-
- # Returns whether or not the constant +const+ is defined. You may
- # optionally pass the +type+ of +const+ as <code>[const, type]</code>,
- # such as:
- #
- # have_const(%w[PTHREAD_MUTEX_INITIALIZER pthread_mutex_t], "pthread.h")
- #
- # You may also pass additional +headers+ to check against in addition to the
- # common header files, and additional flags to +opt+ which are then passed
- # along to the compiler.
- #
- # If found, a macro is passed as a preprocessor constant to the compiler
- # using the type name, in uppercase, prepended with +HAVE_CONST_+.
- #
- # For example, if <code>have_const('foo')</code> returned true, then the
- # +HAVE_CONST_FOO+ preprocessor macro would be passed to the compiler.
- #
- def have_const(const, headers = nil, opt = "", &b)
- checking_for checking_message([*const].compact.join(' '), headers, opt) do
- try_const(const, headers, opt, &b)
- end
- end
-
- # :stopdoc:
- STRING_OR_FAILED_FORMAT = "%s"
- def STRING_OR_FAILED_FORMAT.%(x) # :nodoc:
- x ? super : "failed"
- end
-
- def typedef_expr(type, headers)
- typename, member = type.split('.', 2)
- prelude = cpp_include(headers).split(/$/)
- prelude << "typedef #{typename} rbcv_typedef_;\n"
- return "rbcv_typedef_", member, prelude
- end
-
- def try_signedness(type, member, headers = nil, opts = nil)
- raise ArgumentError, "don't know how to tell signedness of members" if member
- if try_static_assert("(#{type})-1 < 0", headers, opts)
- return -1
- elsif try_static_assert("(#{type})-1 > 0", headers, opts)
- return +1
- end
- end
-
- # :startdoc:
-
- # Returns the size of the given +type+. You may optionally specify
- # additional +headers+ to search in for the +type+.
- #
- # If found, a macro is passed as a preprocessor constant to the compiler
- # using the type name, in uppercase, prepended with +SIZEOF_+, followed by
- # the type name, followed by <code>=X</code> where "X" is the actual size.
- #
- # For example, if <code>check_sizeof('mystruct')</code> returned 12, then
- # the <code>SIZEOF_MYSTRUCT=12</code> preprocessor macro would be passed to
- # the compiler.
- #
- def check_sizeof(type, headers = nil, opts = "", &b)
- typedef, member, prelude = typedef_expr(type, headers)
- prelude << "static #{typedef} *rbcv_ptr_;\n"
- prelude = [prelude]
- expr = "sizeof((*rbcv_ptr_)#{"." << member if member})"
- fmt = STRING_OR_FAILED_FORMAT
- checking_for checking_message("size of #{type}", headers), fmt do
- if size = try_constant(expr, prelude, opts, &b)
- $defs.push(format("-DSIZEOF_%s=%s", type.tr_cpp, size))
- size
- end
- end
- end
-
- # Returns the signedness of the given +type+. You may optionally specify
- # additional +headers+ to search in for the +type+.
- #
- # If the +type+ is found and is a numeric type, a macro is passed as a
- # preprocessor constant to the compiler using the +type+ name, in uppercase,
- # prepended with +SIGNEDNESS_OF_+, followed by the +type+ name, followed by
- # <code>=X</code> where "X" is positive integer if the +type+ is unsigned
- # and a negative integer if the +type+ is signed.
- #
- # For example, if +size_t+ is defined as unsigned, then
- # <code>check_signedness('size_t')</code> would return +1 and the
- # <code>SIGNEDNESS_OF_SIZE_T=+1</code> preprocessor macro would be passed to
- # the compiler. The <code>SIGNEDNESS_OF_INT=-1</code> macro would be set
- # for <code>check_signedness('int')</code>
- #
- def check_signedness(type, headers = nil, opts = nil, &b)
- typedef, member, prelude = typedef_expr(type, headers)
- signed = nil
- checking_for("signedness of #{type}", STRING_OR_FAILED_FORMAT) do
- signed = try_signedness(typedef, member, [prelude], opts, &b) or next nil
- $defs.push("-DSIGNEDNESS_OF_%s=%+d" % [type.tr_cpp, signed])
- signed < 0 ? "signed" : "unsigned"
- end
- signed
- end
-
- # Returns the convertible integer type of the given +type+. You may
- # optionally specify additional +headers+ to search in for the +type+.
- # _convertible_ means actually the same type, or typedef'd from the same
- # type.
- #
- # If the +type+ is a integer type and the _convertible_ type is found,
- # the following macros are passed as preprocessor constants to the compiler
- # using the +type+ name, in uppercase.
- #
- # * +TYPEOF_+, followed by the +type+ name, followed by <code>=X</code>
- # where "X" is the found _convertible_ type name.
- # * +TYP2NUM+ and +NUM2TYP+,
- # where +TYP+ is the +type+ name in uppercase with replacing an +_t+
- # suffix with "T", followed by <code>=X</code> where "X" is the macro name
- # to convert +type+ to an Integer object, and vice versa.
- #
- # For example, if +foobar_t+ is defined as unsigned long, then
- # <code>convertible_int("foobar_t")</code> would return "unsigned long", and
- # define these macros:
- #
- # #define TYPEOF_FOOBAR_T unsigned long
- # #define FOOBART2NUM ULONG2NUM
- # #define NUM2FOOBART NUM2ULONG
- #
- def convertible_int(type, headers = nil, opts = nil, &b)
- type, macname = *type
- checking_for("convertible type of #{type}", STRING_OR_FAILED_FORMAT) do
- if UNIVERSAL_INTS.include?(type)
- type
- else
- typedef, member, prelude = typedef_expr(type, headers, &b)
- if member
- prelude << "static rbcv_typedef_ rbcv_var;"
- compat = UNIVERSAL_INTS.find {|t|
- try_static_assert("sizeof(rbcv_var.#{member}) == sizeof(#{t})", [prelude], opts, &b)
- }
- else
- next unless signed = try_signedness(typedef, member, [prelude])
- u = "unsigned " if signed > 0
- prelude << "extern rbcv_typedef_ foo();"
- compat = UNIVERSAL_INTS.find {|t|
- try_compile([prelude, "extern #{u}#{t} foo();"].join("\n"), opts, :werror=>true, &b)
- }
- end
- if compat
- macname ||= type.sub(/_(?=t\z)/, '').tr_cpp
- conv = (compat == "long long" ? "LL" : compat.upcase)
- compat = "#{u}#{compat}"
- typename = type.tr_cpp
- $defs.push(format("-DSIZEOF_%s=SIZEOF_%s", typename, compat.tr_cpp))
- $defs.push(format("-DTYPEOF_%s=%s", typename, compat.quote))
- $defs.push(format("-DPRI_%s_PREFIX=PRI_%s_PREFIX", macname, conv))
- conv = (u ? "U" : "") + conv
- $defs.push(format("-D%s2NUM=%s2NUM", macname, conv))
- $defs.push(format("-DNUM2%s=NUM2%s", macname, conv))
- compat
- end
- end
- end
- end
- # :stopdoc:
-
- # Used internally by the what_type? method to determine if +type+ is a scalar
- # pointer.
- def scalar_ptr_type?(type, member = nil, headers = nil, &b)
- try_compile(<<"SRC", &b) # pointer
-#{cpp_include(headers)}
-/*top*/
-volatile #{type} conftestval;
-extern int t(void);
-#{MAIN_DOES_NOTHING 't'}
-int t(void) {return (int)(1-*(conftestval#{member ? ".#{member}" : ""}));}
-SRC
- end
-
- # Used internally by the what_type? method to determine if +type+ is a scalar
- # pointer.
- def scalar_type?(type, member = nil, headers = nil, &b)
- try_compile(<<"SRC", &b) # pointer
-#{cpp_include(headers)}
-/*top*/
-volatile #{type} conftestval;
-extern int t(void);
-#{MAIN_DOES_NOTHING 't'}
-int t(void) {return (int)(1-(conftestval#{member ? ".#{member}" : ""}));}
-SRC
- end
-
- # Used internally by the what_type? method to check if the _typeof_ GCC
- # extension is available.
- def have_typeof?
- return $typeof if defined?($typeof)
- $typeof = %w[__typeof__ typeof].find do |t|
- try_compile(<<SRC)
-int rbcv_foo;
-#{t}(rbcv_foo) rbcv_bar;
-SRC
- end
- end
-
- def what_type?(type, member = nil, headers = nil, &b)
- m = "#{type}"
- var = val = "*rbcv_var_"
- func = "rbcv_func_(void)"
- if member
- m << "." << member
- else
- type, member = type.split('.', 2)
- end
- if member
- val = "(#{var}).#{member}"
- end
- prelude = [cpp_include(headers).split(/^/)]
- prelude << ["typedef #{type} rbcv_typedef_;\n",
- "extern rbcv_typedef_ *#{func};\n",
- "static rbcv_typedef_ #{var};\n",
- ]
- type = "rbcv_typedef_"
- fmt = member && !(typeof = have_typeof?) ? "seems %s" : "%s"
- if typeof
- var = "*rbcv_member_"
- func = "rbcv_mem_func_(void)"
- member = nil
- type = "rbcv_mem_typedef_"
- prelude[-1] << "typedef #{typeof}(#{val}) #{type};\n"
- prelude[-1] << "extern #{type} *#{func};\n"
- prelude[-1] << "static #{type} #{var};\n"
- val = var
- end
- def fmt.%(x)
- x ? super : "unknown"
- end
- checking_for checking_message(m, headers), fmt do
- if scalar_ptr_type?(type, member, prelude, &b)
- if try_static_assert("sizeof(*#{var}) == 1", prelude)
- return "string"
- end
- ptr = "*"
- elsif scalar_type?(type, member, prelude, &b)
- unless member and !typeof or try_static_assert("(#{type})-1 < 0", prelude)
- unsigned = "unsigned"
- end
- ptr = ""
- else
- next
- end
- type = UNIVERSAL_INTS.find do |t|
- pre = prelude
- unless member
- pre += [["static #{unsigned} #{t} #{ptr}#{var};\n",
- "extern #{unsigned} #{t} #{ptr}*#{func};\n"]]
- end
- try_static_assert("sizeof(#{ptr}#{val}) == sizeof(#{unsigned} #{t})", pre)
- end
- type or next
- [unsigned, type, ptr].join(" ").strip
- end
- end
-
- # This method is used internally by the find_executable method.
- #
- # Internal use only.
- #
- def find_executable0(bin, path = nil)
- executable_file = proc do |name|
- begin
- stat = File.stat(name)
- rescue SystemCallError
- else
- next name if stat.file? and stat.executable?
- end
- end
-
- exts = config_string('EXECUTABLE_EXTS') {|s| s.split} || config_string('EXEEXT') {|s| [s]}
- if File.expand_path(bin) == bin
- return bin if executable_file.call(bin)
- if exts
- exts.each {|ext| executable_file.call(file = bin + ext) and return file}
- end
- return nil
- end
- if path ||= ENV['PATH']
- path = path.split(File::PATH_SEPARATOR)
- else
- path = %w[/usr/local/bin /usr/ucb /usr/bin /bin]
- end
- file = nil
- path.each do |dir|
- return file if executable_file.call(file = File.join(dir, bin))
- if exts
- exts.each {|ext| executable_file.call(ext = file + ext) and return ext}
- end
- end
- nil
- end
-
- # :startdoc:
-
- # Searches for the executable +bin+ on +path+. The default path is your
- # +PATH+ environment variable. If that isn't defined, it will resort to
- # searching /usr/local/bin, /usr/ucb, /usr/bin and /bin.
- #
- # If found, it will return the full path, including the executable name, of
- # where it was found.
- #
- # Note that this method does not actually affect the generated Makefile.
- #
- def find_executable(bin, path = nil)
- checking_for checking_message(bin, path) do
- find_executable0(bin, path)
- end
- end
-
- # :stopdoc:
-
- def arg_config(config, default=nil, &block)
- $arg_config << [config, default]
- defaults = []
- if default
- defaults << default
- elsif !block
- defaults << nil
- end
- $configure_args.fetch(config.tr('_', '-'), *defaults, &block)
- end
-
- # :startdoc:
-
- # Tests for the presence of a <tt>--with-</tt>_config_ or
- # <tt>--without-</tt>_config_ option. Returns +true+ if the with option is
- # given, +false+ if the without option is given, and the default value
- # otherwise.
- #
- # This can be useful for adding custom definitions, such as debug
- # information.
- #
- # Example:
- #
- # if with_config("debug")
- # $defs.push("-DOSSL_DEBUG") unless $defs.include? "-DOSSL_DEBUG"
- # end
- #
- def with_config(config, default=nil)
- config = config.sub(/^--with[-_]/, '')
- val = arg_config("--with-"+config) do
- if arg_config("--without-"+config)
- false
- elsif block_given?
- yield(config, default)
- else
- break default
- end
- end
- case val
- when "yes"
- true
- when "no"
- false
- else
- val
- end
- end
-
- # Tests for the presence of an <tt>--enable-</tt>_config_ or
- # <tt>--disable-</tt>_config_ option. Returns +true+ if the enable option is
- # given, +false+ if the disable option is given, and the default value
- # otherwise.
- #
- # This can be useful for adding custom definitions, such as debug
- # information.
- #
- # Example:
- #
- # if enable_config("debug")
- # $defs.push("-DOSSL_DEBUG") unless $defs.include? "-DOSSL_DEBUG"
- # end
- #
- def enable_config(config, default=nil)
- if arg_config("--enable-"+config)
- true
- elsif arg_config("--disable-"+config)
- false
- elsif block_given?
- yield(config, default)
- else
- return default
- end
- end
-
- # Generates a header file consisting of the various macro definitions
- # generated by other methods such as have_func and have_header. These are
- # then wrapped in a custom <code>#ifndef</code> based on the +header+ file
- # name, which defaults to "extconf.h".
- #
- # For example:
- #
- # # extconf.rb
- # require 'mkmf'
- # have_func('realpath')
- # have_header('sys/utime.h')
- # create_header
- # create_makefile('foo')
- #
- # The above script would generate the following extconf.h file:
- #
- # #ifndef EXTCONF_H
- # #define EXTCONF_H
- # #define HAVE_REALPATH 1
- # #define HAVE_SYS_UTIME_H 1
- # #endif
- #
- # Given that the create_header method generates a file based on definitions
- # set earlier in your extconf.rb file, you will probably want to make this
- # one of the last methods you call in your script.
- #
- def create_header(header = "extconf.h")
- message "creating %s\n", header
- sym = header.tr_cpp
- hdr = ["#ifndef #{sym}\n#define #{sym}\n"]
- for line in $defs
- case line
- when /^-D([^=]+)(?:=(.*))?/
- hdr << "#define #$1 #{$2 ? Shellwords.shellwords($2)[0].gsub(/(?=\t+)/, "\\\n") : 1}\n"
- when /^-U(.*)/
- hdr << "#undef #$1\n"
- end
- end
- hdr << "#endif\n"
- hdr = hdr.join("")
- log_src(hdr, "#{header} is")
- unless (IO.read(header) == hdr rescue false)
- open(header, "wb") do |hfile|
- hfile.write(hdr)
- end
- end
- $extconf_h = header
- end
-
- # call-seq:
- # dir_config(target)
- # dir_config(target, prefix)
- # dir_config(target, idefault, ldefault)
- #
- # Sets a +target+ name that the user can then use to configure
- # various "with" options with on the command line by using that
- # name. For example, if the target is set to "foo", then the user
- # could use the <code>--with-foo-dir=prefix</code>,
- # <code>--with-foo-include=dir</code> and
- # <code>--with-foo-lib=dir</code> command line options to tell where
- # to search for header/library files.
- #
- # You may pass along additional parameters to specify default
- # values. If one is given it is taken as default +prefix+, and if
- # two are given they are taken as "include" and "lib" defaults in
- # that order.
- #
- # In any case, the return value will be an array of determined
- # "include" and "lib" directories, either of which can be nil if no
- # corresponding command line option is given when no default value
- # is specified.
- #
- # Note that dir_config only adds to the list of places to search for
- # libraries and include files. It does not link the libraries into your
- # application.
- #
- def dir_config(target, idefault=nil, ldefault=nil)
- if dir = with_config(target + "-dir", (idefault unless ldefault))
- defaults = Array === dir ? dir : dir.split(File::PATH_SEPARATOR)
- idefault = ldefault = nil
- end
-
- idir = with_config(target + "-include", idefault)
- $arg_config.last[1] ||= "${#{target}-dir}/include"
- ldir = with_config(target + "-lib", ldefault)
- $arg_config.last[1] ||= "${#{target}-dir}/#{_libdir_basename}"
-
- idirs = idir ? Array === idir ? idir.dup : idir.split(File::PATH_SEPARATOR) : []
- if defaults
- idirs.concat(defaults.collect {|d| d + "/include"})
- idir = ([idir] + idirs).compact.join(File::PATH_SEPARATOR)
- end
- unless idirs.empty?
- idirs.collect! {|d| "-I" + d}
- idirs -= Shellwords.shellwords($CPPFLAGS)
- unless idirs.empty?
- $CPPFLAGS = (idirs.quote << $CPPFLAGS).join(" ")
- end
- end
-
- ldirs = ldir ? Array === ldir ? ldir.dup : ldir.split(File::PATH_SEPARATOR) : []
- if defaults
- ldirs.concat(defaults.collect {|d| "#{d}/#{_libdir_basename}"})
- ldir = ([ldir] + ldirs).compact.join(File::PATH_SEPARATOR)
- end
- $LIBPATH = ldirs | $LIBPATH
-
- [idir, ldir]
- end
-
- # Returns compile/link information about an installed library in a
- # tuple of <code>[cflags, ldflags, libs]</code>, by using the
- # command found first in the following commands:
- #
- # 1. If <code>--with-{pkg}-config={command}</code> is given via
- # command line option: <code>{command} {option}</code>
- #
- # 2. <code>{pkg}-config {option}</code>
- #
- # 3. <code>pkg-config {option} {pkg}</code>
- #
- # Where {option} is, for instance, <code>--cflags</code>.
- #
- # The values obtained are appended to +$CFLAGS+, +$LDFLAGS+ and
- # +$libs+.
- #
- # If an <code>option</code> argument is given, the config command is
- # invoked with the option and a stripped output string is returned
- # without modifying any of the global values mentioned above.
- def pkg_config(pkg, option=nil)
- if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig)
- # iff package specific config command is given
- elsif ($PKGCONFIG ||=
- (pkgconfig = with_config("pkg-config", ("pkg-config" unless CROSS_COMPILING))) &&
- find_executable0(pkgconfig) && pkgconfig) and
- system("#{$PKGCONFIG} --exists #{pkg}")
- # default to pkg-config command
- pkgconfig = $PKGCONFIG
- get = proc {|opt|
- opt = IO.popen("#{$PKGCONFIG} --#{opt} #{pkg}", err:[:child, :out], &:read)
- opt.strip if $?.success?
- }
- elsif find_executable0(pkgconfig = "#{pkg}-config")
- # default to package specific config command, as a last resort.
- else
- pkgconfig = nil
- end
- if pkgconfig
- get ||= proc {|opt|
- opt = IO.popen("#{pkgconfig} --#{opt}", err:[:child, :out], &:read)
- opt.strip if $?.success?
- }
- end
- orig_ldflags = $LDFLAGS
- if get and option
- get[option]
- elsif get and try_ldflags(ldflags = get['libs'])
- if incflags = get['cflags-only-I']
- $INCFLAGS << " " << incflags
- cflags = get['cflags-only-other']
- else
- cflags = get['cflags']
- end
- libs = get['libs-only-l']
- if cflags
- $CFLAGS += " " << cflags
- $CXXFLAGS += " " << cflags
- end
- if libs
- ldflags = (Shellwords.shellwords(ldflags) - Shellwords.shellwords(libs)).quote.join(" ")
- else
- libs, ldflags = Shellwords.shellwords(ldflags).partition {|s| s =~ /-l([^ ]+)/ }.map {|l|l.quote.join(" ")}
- end
- $libs += " " << libs
-
- $LDFLAGS = [orig_ldflags, ldflags].join(' ')
- Logging::message "package configuration for %s\n", pkg
- Logging::message "cflags: %s\nldflags: %s\nlibs: %s\n\n",
- cflags, ldflags, libs
- [cflags, ldflags, libs]
- else
- Logging::message "package configuration for %s is not found\n", pkg
- nil
- end
- end
-
- # :stopdoc:
-
- def with_destdir(dir)
- dir = dir.sub($dest_prefix_pattern, '')
- /\A\$[\(\{]/ =~ dir ? dir : "$(DESTDIR)"+dir
- end
-
- # Converts forward slashes to backslashes. Aimed at MS Windows.
- #
- # Internal use only.
- #
- def winsep(s)
- s.tr('/', '\\')
- end
-
- # Converts native path to format acceptable in Makefile
- #
- # Internal use only.
- #
- if !CROSS_COMPILING
- case CONFIG['build_os']
- when 'mingw32'
- def mkintpath(path)
- # mingw uses make from msys and it needs special care
- # converts from C:\some\path to /C/some/path
- path = path.dup
- path.tr!('\\', '/')
- path.sub!(/\A([A-Za-z]):(?=\/)/, '/\1')
- path
- end
- when 'cygwin'
- if CONFIG['target_os'] != 'cygwin'
- def mkintpath(path)
- IO.popen(["cygpath", "-u", path], &:read).chomp
- end
- end
- end
- end
- unless method_defined?(:mkintpath)
- def mkintpath(path)
- path
- end
- end
-
- def configuration(srcdir)
- mk = []
- vpath = $VPATH.dup
- CONFIG["hdrdir"] ||= $hdrdir
- mk << %{
-SHELL = /bin/sh
-
-# V=0 quiet, V=1 verbose. other values don't work.
-V = 0
-Q1 = $(V:1=)
-Q = $(Q1:0=@)
-ECHO1 = $(V:1=@#{CONFIG['NULLCMD']})
-ECHO = $(ECHO1:0=@echo)
-NULLCMD = #{CONFIG['NULLCMD']}
-
-#### Start of system configuration section. ####
-#{"top_srcdir = " + $top_srcdir.sub(%r"\A#{Regexp.quote($topdir)}/", "$(topdir)/") if $extmk}
-srcdir = #{srcdir.gsub(/\$\((srcdir)\)|\$\{(srcdir)\}/) {mkintpath(CONFIG[$1||$2]).unspace}}
-topdir = #{mkintpath(topdir = $extmk ? CONFIG["topdir"] : $topdir).unspace}
-hdrdir = #{(hdrdir = CONFIG["hdrdir"]) == topdir ? "$(topdir)" : mkintpath(hdrdir).unspace}
-arch_hdrdir = #{$arch_hdrdir.quote}
-PATH_SEPARATOR = #{CONFIG['PATH_SEPARATOR']}
-VPATH = #{vpath.join(CONFIG['PATH_SEPARATOR'])}
-}
- if $extmk
- mk << "RUBYLIB =\n""RUBYOPT = -\n"
- end
- prefix = mkintpath(CONFIG["prefix"])
- if destdir = prefix[$dest_prefix_pattern, 1]
- mk << "\nDESTDIR = #{destdir}\n"
- prefix = prefix[destdir.size..-1]
- end
- mk << "prefix = #{with_destdir(prefix).unspace}\n"
- CONFIG.each do |key, var|
- mk << "#{key} = #{with_destdir(mkintpath(var)).unspace}\n" if /.prefix$/ =~ key
- end
- CONFIG.each do |key, var|
- next if /^abs_/ =~ key
- next if /^(?:src|top|hdr)dir$/ =~ key
- next unless /dir$/ =~ key
- mk << "#{key} = #{with_destdir(var)}\n"
- end
- if !$extmk and !$configure_args.has_key?('--ruby') and
- sep = config_string('BUILD_FILE_SEPARATOR')
- sep = ":/=#{sep}"
- else
- sep = ""
- end
- possible_command = (proc {|s| s if /top_srcdir/ !~ s} unless $extmk)
- extconf_h = $extconf_h ? "-DRUBY_EXTCONF_H=\\\"$(RUBY_EXTCONF_H)\\\" " : $defs.join(" ") << " "
- headers = %w[
- $(hdrdir)/ruby.h
- $(hdrdir)/ruby/ruby.h
- $(hdrdir)/ruby/defines.h
- $(hdrdir)/ruby/missing.h
- $(hdrdir)/ruby/intern.h
- $(hdrdir)/ruby/st.h
- $(hdrdir)/ruby/subst.h
- ]
- if RULE_SUBST
- headers.each {|h| h.sub!(/.*/, &RULE_SUBST.method(:%))}
- end
- headers << $config_h
- headers << '$(RUBY_EXTCONF_H)' if $extconf_h
- mk << %{
-
-CC = #{CONFIG['CC']}
-CXX = #{CONFIG['CXX']}
-LIBRUBY = #{CONFIG['LIBRUBY']}
-LIBRUBY_A = #{CONFIG['LIBRUBY_A']}
-LIBRUBYARG_SHARED = #$LIBRUBYARG_SHARED
-LIBRUBYARG_STATIC = #$LIBRUBYARG_STATIC
-empty =
-OUTFLAG = #{OUTFLAG}$(empty)
-COUTFLAG = #{COUTFLAG}$(empty)
-
-RUBY_EXTCONF_H = #{$extconf_h}
-cflags = #{CONFIG['cflags']}
-optflags = #{CONFIG['optflags']}
-debugflags = #{CONFIG['debugflags']}
-warnflags = #{$warnflags}
-CCDLFLAGS = #{$static ? '' : CONFIG['CCDLFLAGS']}
-CFLAGS = $(CCDLFLAGS) #$CFLAGS $(ARCH_FLAG)
-INCFLAGS = -I. #$INCFLAGS
-DEFS = #{CONFIG['DEFS']}
-CPPFLAGS = #{extconf_h}#{$CPPFLAGS}
-CXXFLAGS = $(CCDLFLAGS) #$CXXFLAGS $(ARCH_FLAG)
-ldflags = #{$LDFLAGS}
-dldflags = #{$DLDFLAGS} #{CONFIG['EXTDLDFLAGS']}
-ARCH_FLAG = #{$ARCH_FLAG}
-DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
-LDSHARED = #{CONFIG['LDSHARED']}
-LDSHAREDXX = #{config_string('LDSHAREDXX') || '$(LDSHARED)'}
-AR = #{CONFIG['AR']}
-EXEEXT = #{CONFIG['EXEEXT']}
-
-}
- CONFIG.each do |key, val|
- mk << "#{key} = #{val}\n" if /^RUBY.*NAME/ =~ key
- end
- mk << %{
-arch = #{CONFIG['arch']}
-sitearch = #{CONFIG['sitearch']}
-ruby_version = #{RbConfig::CONFIG['ruby_version']}
-ruby = #{$ruby.sub(%r[\A#{Regexp.quote(RbConfig::CONFIG['bindir'])}(?=/|\z)]) {'$(bindir)'}}
-RUBY = $(ruby#{sep})
-ruby_headers = #{headers.join(' ')}
-
-RM = #{config_string('RM', &possible_command) || '$(RUBY) -run -e rm -- -f'}
-RM_RF = #{'$(RUBY) -run -e rm -- -rf'}
-RMDIRS = #{config_string('RMDIRS', &possible_command) || '$(RUBY) -run -e rmdir -- -p'}
-MAKEDIRS = #{config_string('MAKEDIRS', &possible_command) || '@$(RUBY) -run -e mkdir -- -p'}
-INSTALL = #{config_string('INSTALL', &possible_command) || '@$(RUBY) -run -e install -- -vp'}
-INSTALL_PROG = #{config_string('INSTALL_PROG') || '$(INSTALL) -m 0755'}
-INSTALL_DATA = #{config_string('INSTALL_DATA') || '$(INSTALL) -m 0644'}
-COPY = #{config_string('CP', &possible_command) || '@$(RUBY) -run -e cp -- -v'}
-TOUCH = exit >
-
-#### End of system configuration section. ####
-
-preload = #{defined?($preload) && $preload ? $preload.join(' ') : ''}
-}
- if $nmake == ?b
- mk.each do |x|
- x.gsub!(/^(MAKEDIRS|INSTALL_(?:PROG|DATA))+\s*=.*\n/) do
- "!ifndef " + $1 + "\n" +
- $& +
- "!endif\n"
- end
- end
- end
- mk
- end
-
- def timestamp_file(name, target_prefix = nil)
- if target_prefix
- pat = []
- install_dirs.each do |n, d|
- pat << n if /\$\(target_prefix\)\z/ =~ d
- end
- name = name.gsub(/\$\((#{pat.join("|")})\)/) {$&+target_prefix}
- end
- name = name.gsub(/(\$[({]|[})])|(\/+)|[^-.\w]+/) {$1 ? "" : $2 ? ".-." : "_"}
- "$(TIMESTAMP_DIR)/.#{name}.time"
- end
- # :startdoc:
-
- # creates a stub Makefile.
- #
- def dummy_makefile(srcdir)
- configuration(srcdir) << <<RULES << CLEANINGS
-CLEANFILES = #{$cleanfiles.join(' ')}
-DISTCLEANFILES = #{$distcleanfiles.join(' ')}
-
-all install static install-so install-rb: Makefile
-.PHONY: all install static install-so install-rb
-.PHONY: clean clean-so clean-static clean-rb
-
-RULES
- end
-
- def each_compile_rules # :nodoc:
- vpath_splat = /\$\(\*VPATH\*\)/
- COMPILE_RULES.each do |rule|
- if vpath_splat =~ rule
- $VPATH.each do |path|
- yield rule.sub(vpath_splat) {path}
- end
- else
- yield rule
- end
- end
- end
-
- # Processes the data contents of the "depend" file. Each line of this file
- # is expected to be a file name.
- #
- # Returns the output of findings, in Makefile format.
- #
- def depend_rules(depend)
- suffixes = []
- depout = []
- cont = implicit = nil
- impconv = proc do
- each_compile_rules {|rule| depout << (rule % implicit[0]) << implicit[1]}
- implicit = nil
- end
- ruleconv = proc do |line|
- if implicit
- if /\A\t/ =~ line
- implicit[1] << line
- next
- else
- impconv[]
- end
- end
- if m = /\A\.(\w+)\.(\w+)(?:\s*:)/.match(line)
- suffixes << m[1] << m[2]
- implicit = [[m[1], m[2]], [m.post_match]]
- next
- elsif RULE_SUBST and /\A(?!\s*\w+\s*=)[$\w][^#]*:/ =~ line
- line.sub!(/\s*\#.*$/, '')
- comment = $&
- line.gsub!(%r"(\s)(?!\.)([^$(){}+=:\s\\,]+)(?=\s|\z)") {$1 + RULE_SUBST % $2}
- line = line.chomp + comment + "\n" if comment
- end
- depout << line
- end
- depend.each_line do |line|
- line.gsub!(/\.o\b/, ".#{$OBJEXT}")
- line.gsub!(/\{\$\(VPATH\)\}/, "") unless $nmake
- line.gsub!(/\$\((?:hdr|top)dir\)\/config.h/, $config_h)
- line.gsub!(%r"\$\(hdrdir\)/(?!ruby(?![^:;/\s]))(?=[-\w]+\.h)", '\&ruby/')
- if $nmake && /\A\s*\$\(RM|COPY\)/ =~ line
- line.gsub!(%r"[-\w\./]{2,}"){$&.tr("/", "\\")}
- line.gsub!(/(\$\((?!RM|COPY)[^:)]+)(?=\))/, '\1:/=\\')
- end
- if /(?:^|[^\\])(?:\\\\)*\\$/ =~ line
- (cont ||= []) << line
- next
- elsif cont
- line = (cont << line).join
- cont = nil
- end
- ruleconv.call(line)
- end
- if cont
- ruleconv.call(cont.join)
- elsif implicit
- impconv.call
- end
- unless suffixes.empty?
- depout.unshift(".SUFFIXES: ." + suffixes.uniq.join(" .") + "\n\n")
- end
- depout.unshift("$(OBJS): $(RUBY_EXTCONF_H)\n\n") if $extconf_h
- depout.flatten!
- depout
- end
-
- # Generates the Makefile for your extension, passing along any options and
- # preprocessor constants that you may have generated through other methods.
- #
- # The +target+ name should correspond the name of the global function name
- # defined within your C extension, minus the +Init_+. For example, if your
- # C extension is defined as +Init_foo+, then your target would simply be
- # "foo".
- #
- # If any "/" characters are present in the target name, only the last name
- # is interpreted as the target name, and the rest are considered toplevel
- # directory names, and the generated Makefile will be altered accordingly to
- # follow that directory structure.
- #
- # For example, if you pass "test/foo" as a target name, your extension will
- # be installed under the "test" directory. This means that in order to
- # load the file within a Ruby program later, that directory structure will
- # have to be followed, e.g. <code>require 'test/foo'</code>.
- #
- # The +srcprefix+ should be used when your source files are not in the same
- # directory as your build script. This will not only eliminate the need for
- # you to manually copy the source files into the same directory as your
- # build script, but it also sets the proper +target_prefix+ in the generated
- # Makefile.
- #
- # Setting the +target_prefix+ will, in turn, install the generated binary in
- # a directory under your <code>RbConfig::CONFIG['sitearchdir']</code> that
- # mimics your local filesystem when you run <code>make install</code>.
- #
- # For example, given the following file tree:
- #
- # ext/
- # extconf.rb
- # test/
- # foo.c
- #
- # And given the following code:
- #
- # create_makefile('test/foo', 'test')
- #
- # That will set the +target_prefix+ in the generated Makefile to "test".
- # That, in turn, will create the following file tree when installed via the
- # <code>make install</code> command:
- #
- # /path/to/ruby/sitearchdir/test/foo.so
- #
- # It is recommended that you use this approach to generate your makefiles,
- # instead of copying files around manually, because some third party
- # libraries may depend on the +target_prefix+ being set properly.
- #
- # The +srcprefix+ argument can be used to override the default source
- # directory, i.e. the current directory. It is included as part of the
- # +VPATH+ and added to the list of +INCFLAGS+.
- #
- def create_makefile(target, srcprefix = nil)
- $target = target
- libpath = $LIBPATH|$DEFLIBPATH
- message "creating Makefile\n"
- MakeMakefile.rm_f "#{CONFTEST}*"
- if CONFIG["DLEXT"] == $OBJEXT
- for lib in libs = $libs.split
- lib.sub!(/-l(.*)/, %%"lib\\1.#{$LIBEXT}"%)
- end
- $defs.push(format("-DEXTLIB='%s'", libs.join(",")))
- end
-
- if target.include?('/')
- target_prefix, target = File.split(target)
- target_prefix[0,0] = '/'
- else
- target_prefix = ""
- end
-
- srcprefix ||= "$(srcdir)/#{srcprefix}".chomp('/')
- RbConfig.expand(srcdir = srcprefix.dup)
-
- ext = ".#{$OBJEXT}"
- orig_srcs = Dir[File.join(srcdir, "*.{#{SRC_EXT.join(%q{,})}}")]
- if not $objs
- srcs = $srcs || orig_srcs
- objs = srcs.inject(Hash.new {[]}) {|h, f| h[File.basename(f, ".*") << ext] <<= f; h}
- $objs = objs.keys
- unless objs.delete_if {|b, f| f.size == 1}.empty?
- dups = objs.sort.map {|b, f|
- "#{b[/.*\./]}{#{f.collect {|n| n[/([^.]+)\z/]}.join(',')}}"
- }
- abort "source files duplication - #{dups.join(", ")}"
- end
- else
- $objs.collect! {|o| File.basename(o, ".*") << ext} unless $OBJEXT == "o"
- srcs = $srcs || $objs.collect {|o| o.chomp(ext) << ".c"}
- end
- $srcs = srcs
-
- hdrs = Dir[File.join(srcdir, "*.{#{HDR_EXT.join(%q{,})}}")]
-
- target = nil if $objs.empty?
-
- if target and EXPORT_PREFIX
- if File.exist?(File.join(srcdir, target + '.def'))
- deffile = "$(srcdir)/$(TARGET).def"
- unless EXPORT_PREFIX.empty?
- makedef = %{-pe "$_.sub!(/^(?=\\w)/,'#{EXPORT_PREFIX}') unless 1../^EXPORTS$/i"}
- end
- else
- makedef = %{-e "puts 'EXPORTS', '$(TARGET_ENTRY)'"}
- end
- if makedef
- $cleanfiles << '$(DEFFILE)'
- origdef = deffile
- deffile = "$(TARGET)-$(arch).def"
- end
- end
- origdef ||= ''
-
- if $extout and $INSTALLFILES
- $cleanfiles.concat($INSTALLFILES.collect {|files, dir|File.join(dir, files.sub(/\A\.\//, ''))})
- $distcleandirs.concat($INSTALLFILES.collect {|files, dir| dir})
- end
-
- if $extmk and $static
- $defs << "-DRUBY_EXPORT=1"
- end
-
- if $extmk and not $extconf_h
- create_header
- end
-
- libpath = libpathflag(libpath)
-
- dllib = target ? "$(TARGET).#{CONFIG['DLEXT']}" : ""
- staticlib = target ? "$(TARGET).#$LIBEXT" : ""
- mfile = open("Makefile", "wb")
- conf = configuration(srcprefix)
- conf = yield(conf) if block_given?
- mfile.puts(conf)
- mfile.print "
-libpath = #{($LIBPATH|$DEFLIBPATH).join(" ")}
-LIBPATH = #{libpath}
-DEFFILE = #{deffile}
-
-CLEANFILES = #{$cleanfiles.join(' ')}
-DISTCLEANFILES = #{$distcleanfiles.join(' ')}
-DISTCLEANDIRS = #{$distcleandirs.join(' ')}
-
-extout = #{$extout && $extout.quote}
-extout_prefix = #{$extout_prefix}
-target_prefix = #{target_prefix}
-LOCAL_LIBS = #{$LOCAL_LIBS}
-LIBS = #{$LIBRUBYARG} #{$libs} #{$LIBS}
-ORIG_SRCS = #{orig_srcs.collect(&File.method(:basename)).join(' ')}
-SRCS = $(ORIG_SRCS) #{(srcs - orig_srcs).collect(&File.method(:basename)).join(' ')}
-OBJS = #{$objs.join(" ")}
-HDRS = #{hdrs.map{|h| '$(srcdir)/' + File.basename(h)}.join(' ')}
-TARGET = #{target}
-TARGET_NAME = #{target && target[/\A\w+/]}
-TARGET_ENTRY = #{EXPORT_PREFIX || ''}Init_$(TARGET_NAME)
-DLLIB = #{dllib}
-EXTSTATIC = #{$static || ""}
-STATIC_LIB = #{staticlib unless $static.nil?}
-#{!$extout && defined?($installed_list) ? "INSTALLED_LIST = #{$installed_list}\n" : ""}
-TIMESTAMP_DIR = #{$extout ? '$(extout)/.timestamp' : '.'}
-" #"
- # TODO: fixme
- install_dirs.each {|d| mfile.print("%-14s= %s\n" % d) if /^[[:upper:]]/ =~ d[0]}
- n = ($extout ? '$(RUBYARCHDIR)/' : '') + '$(TARGET)'
- mfile.print "
-TARGET_SO = #{($extout ? '$(RUBYARCHDIR)/' : '')}$(DLLIB)
-CLEANLIBS = #{n}.#{CONFIG['DLEXT']} #{config_string('cleanlibs') {|t| t.gsub(/\$\*/) {n}}}
-CLEANOBJS = *.#{$OBJEXT} #{config_string('cleanobjs') {|t| t.gsub(/\$\*/, "$(TARGET)#{deffile ? '-$(arch)': ''}")} if target} *.bak
-
-all: #{$extout ? "install" : target ? "$(DLLIB)" : "Makefile"}
-static: $(STATIC_LIB)#{$extout ? " install-rb" : ""}
-.PHONY: all install static install-so install-rb
-.PHONY: clean clean-so clean-static clean-rb
-"
- mfile.print CLEANINGS
- fsep = config_string('BUILD_FILE_SEPARATOR') {|s| s unless s == "/"}
- if fsep
- sep = ":/=#{fsep}"
- fseprepl = proc {|s|
- s = s.gsub("/", fsep)
- s = s.gsub(/(\$\(\w+)(\))/) {$1+sep+$2}
- s.gsub(/(\$\{\w+)(\})/) {$1+sep+$2}
- }
- rsep = ":#{fsep}=/"
- else
- fseprepl = proc {|s| s}
- sep = ""
- rsep = ""
- end
- dirs = []
- mfile.print "install: install-so install-rb\n\n"
- sodir = (dir = "$(RUBYARCHDIR)").dup
- mfile.print("install-so: ")
- if target
- f = "$(DLLIB)"
- dest = "#{dir}/#{f}"
- if $extout
- mfile.puts dest
- mfile.print "clean-so::\n"
- mfile.print "\t-$(Q)$(RM) #{fseprepl[dest]}\n"
- mfile.print "\t-$(Q)$(RMDIRS) #{fseprepl[dir]}#{$ignore_error}\n"
- else
- mfile.print "#{f} #{timestamp_file(dir, target_prefix)}\n"
- mfile.print "\t$(INSTALL_PROG) #{fseprepl[f]} #{dir}\n"
- if defined?($installed_list)
- mfile.print "\t@echo #{dir}/#{File.basename(f)}>>$(INSTALLED_LIST)\n"
- end
- end
- mfile.print "clean-static::\n"
- mfile.print "\t-$(Q)$(RM) $(STATIC_LIB)\n"
- else
- mfile.puts "Makefile"
- end
- mfile.print("install-rb: pre-install-rb install-rb-default\n")
- mfile.print("install-rb-default: pre-install-rb-default\n")
- mfile.print("pre-install-rb: Makefile\n")
- mfile.print("pre-install-rb-default: Makefile\n")
- for sfx, i in [["-default", [["lib/**/*.rb", "$(RUBYLIBDIR)", "lib"]]], ["", $INSTALLFILES]]
- files = install_files(mfile, i, nil, srcprefix) or next
- for dir, *files in files
- unless dirs.include?(dir)
- dirs << dir
- mfile.print "pre-install-rb#{sfx}: #{timestamp_file(dir, target_prefix)}\n"
- end
- for f in files
- dest = "#{dir}/#{File.basename(f)}"
- mfile.print("install-rb#{sfx}: #{dest}\n")
- mfile.print("#{dest}: #{f} #{timestamp_file(dir, target_prefix)}\n")
- mfile.print("\t$(Q) $(#{$extout ? 'COPY' : 'INSTALL_DATA'}) #{f} $(@D)\n")
- if defined?($installed_list) and !$extout
- mfile.print("\t@echo #{dest}>>$(INSTALLED_LIST)\n")
- end
- if $extout
- mfile.print("clean-rb#{sfx}::\n")
- mfile.print("\t-$(Q)$(RM) #{fseprepl[dest]}\n")
- end
- end
- end
- mfile.print "pre-install-rb#{sfx}:\n"
- if files.empty?
- mfile.print("\t@$(NULLCMD)\n")
- else
- mfile.print("\t$(ECHO) installing#{sfx.sub(/^-/, " ")} #{target} libraries\n")
- end
- if $extout
- dirs.uniq!
- unless dirs.empty?
- mfile.print("clean-rb#{sfx}::\n")
- for dir in dirs.sort_by {|d| -d.count('/')}
- mfile.print("\t-$(Q)$(RMDIRS) #{fseprepl[dir]}#{$ignore_error}\n")
- end
- end
- end
- end
- dirs.unshift(sodir) if target and !dirs.include?(sodir)
- dirs.each do |d|
- t = timestamp_file(d, target_prefix)
- mfile.print "#{t}:\n\t$(Q) $(MAKEDIRS) $(@D) #{d}\n\t$(Q) $(TOUCH) $@\n"
- end
-
- mfile.print <<-SITEINSTALL
-
-site-install: site-install-so site-install-rb
-site-install-so: install-so
-site-install-rb: install-rb
-
- SITEINSTALL
-
- return unless target
-
- mfile.puts SRC_EXT.collect {|e| ".path.#{e} = $(VPATH)"} if $nmake == ?b
- mfile.print ".SUFFIXES: .#{(SRC_EXT + [$OBJEXT, $ASMEXT]).compact.join(' .')}\n"
- mfile.print "\n"
-
- compile_command = "\n\t$(ECHO) compiling $(<#{rsep})\n\t$(Q) %s\n\n"
- command = compile_command % COMPILE_CXX
- asm_command = compile_command.sub(/compiling/, 'translating') % ASSEMBLE_CXX
- CXX_EXT.each do |e|
- each_compile_rules do |rule|
- mfile.printf(rule, e, $OBJEXT)
- mfile.print(command)
- mfile.printf(rule, e, $ASMEXT)
- mfile.print(asm_command)
- end
- end
- command = compile_command % COMPILE_C
- asm_command = compile_command.sub(/compiling/, 'translating') % ASSEMBLE_C
- C_EXT.each do |e|
- each_compile_rules do |rule|
- mfile.printf(rule, e, $OBJEXT)
- mfile.print(command)
- mfile.printf(rule, e, $ASMEXT)
- mfile.print(asm_command)
- end
- end
-
- mfile.print "$(RUBYARCHDIR)/" if $extout
- mfile.print "$(DLLIB): "
- mfile.print "$(DEFFILE) " if makedef
- mfile.print "$(OBJS) Makefile"
- mfile.print " #{timestamp_file('$(RUBYARCHDIR)', target_prefix)}" if $extout
- mfile.print "\n"
- mfile.print "\t$(ECHO) linking shared-object #{target_prefix.sub(/\A\/(.*)/, '\1/')}$(DLLIB)\n"
- mfile.print "\t-$(Q)$(RM) $(@#{sep})\n"
- link_so = LINK_SO.gsub(/^/, "\t$(Q) ")
- if srcs.any?(&%r"\.(?:#{CXX_EXT.join('|')})\z".method(:===))
- link_so = link_so.sub(/\bLDSHARED\b/, '\&XX')
- end
- mfile.print link_so, "\n\n"
- unless $static.nil?
- mfile.print "$(STATIC_LIB): $(OBJS)\n\t-$(Q)$(RM) $(@#{sep})\n\t"
- mfile.print "$(ECHO) linking static-library $(@#{rsep})\n\t$(Q) "
- mfile.print "$(AR) #{config_string('ARFLAGS') || 'cru '}$@ $(OBJS)"
- config_string('RANLIB') do |ranlib|
- mfile.print "\n\t-$(Q)#{ranlib} $(@) 2> /dev/null || true"
- end
- end
- mfile.print "\n\n"
- if makedef
- mfile.print "$(DEFFILE): #{origdef}\n"
- mfile.print "\t$(ECHO) generating $(@#{rsep})\n"
- mfile.print "\t$(Q) $(RUBY) #{makedef} #{origdef} > $@\n\n"
- end
-
- depend = File.join(srcdir, "depend")
- if File.exist?(depend)
- mfile.print("###\n", *depend_rules(File.read(depend)))
- else
- mfile.print "$(OBJS): $(HDRS) $(ruby_headers)\n"
- end
-
- $makefile_created = true
- ensure
- mfile.close if mfile
- end
-
- # :stopdoc:
-
- def init_mkmf(config = CONFIG, rbconfig = RbConfig::CONFIG)
- $makefile_created = false
- $arg_config = []
- $enable_shared = config['ENABLE_SHARED'] == 'yes'
- $defs = []
- $extconf_h = nil
- if $warnflags = CONFIG['warnflags'] and CONFIG['GCC'] == 'yes'
- # turn warnings into errors only for bundled extensions.
- config['warnflags'] = $warnflags.gsub(/(\A|\s)-Werror[-=]/, '\1-W')
- if /icc\z/ =~ config['CC']
- config['warnflags'].gsub!(/(\A|\s)-W(?:division-by-zero|deprecated-declarations)/, '\1')
- end
- RbConfig.expand(rbconfig['warnflags'] = config['warnflags'].dup)
- config.each do |key, val|
- RbConfig.expand(rbconfig[key] = val.dup) if /warnflags/ =~ val
- end
- $warnflags = config['warnflags'] unless $extmk
- end
- $CFLAGS = with_config("cflags", arg_config("CFLAGS", config["CFLAGS"])).dup
- $CXXFLAGS = (with_config("cxxflags", arg_config("CXXFLAGS", config["CXXFLAGS"]))||'').dup
- $ARCH_FLAG = with_config("arch_flag", arg_config("ARCH_FLAG", config["ARCH_FLAG"])).dup
- $CPPFLAGS = with_config("cppflags", arg_config("CPPFLAGS", config["CPPFLAGS"])).dup
- $LDFLAGS = with_config("ldflags", arg_config("LDFLAGS", config["LDFLAGS"])).dup
- $INCFLAGS = "-I$(arch_hdrdir)"
- $INCFLAGS << " -I$(hdrdir)/ruby/backward" unless $extmk
- $INCFLAGS << " -I$(hdrdir) -I$(srcdir)"
- $DLDFLAGS = with_config("dldflags", arg_config("DLDFLAGS", config["DLDFLAGS"])).dup
- $LIBEXT = config['LIBEXT'].dup
- $OBJEXT = config["OBJEXT"].dup
- $EXEEXT = config["EXEEXT"].dup
- $ASMEXT = config_string('ASMEXT', &:dup) || 'S'
- $LIBS = "#{config['LIBS']} #{config['DLDLIBS']}"
- $LIBRUBYARG = ""
- $LIBRUBYARG_STATIC = config['LIBRUBYARG_STATIC']
- $LIBRUBYARG_SHARED = config['LIBRUBYARG_SHARED']
- $DEFLIBPATH = [$extmk ? "$(topdir)" : "$(#{config["libdirname"] || "libdir"})"]
- $DEFLIBPATH.unshift(".")
- $LIBPATH = []
- $INSTALLFILES = []
- $NONINSTALLFILES = [/~\z/, /\A#.*#\z/, /\A\.#/, /\.bak\z/i, /\.orig\z/, /\.rej\z/, /\.l[ao]\z/, /\.o\z/]
- $VPATH = %w[$(srcdir) $(arch_hdrdir)/ruby $(hdrdir)/ruby]
-
- $objs = nil
- $srcs = nil
- $libs = ""
- if $enable_shared or RbConfig.expand(config["LIBRUBY"].dup) != RbConfig.expand(config["LIBRUBY_A"].dup)
- $LIBRUBYARG = config['LIBRUBYARG']
- end
-
- $LOCAL_LIBS = ""
-
- $cleanfiles = config_string('CLEANFILES') {|s| Shellwords.shellwords(s)} || []
- $cleanfiles << "mkmf.log"
- $distcleanfiles = config_string('DISTCLEANFILES') {|s| Shellwords.shellwords(s)} || []
- $distcleandirs = config_string('DISTCLEANDIRS') {|s| Shellwords.shellwords(s)} || []
-
- $extout ||= nil
- $extout_prefix ||= nil
-
- $arg_config.clear
- dir_config("opt")
- end
-
- FailedMessage = <<MESSAGE
-Could not create Makefile due to some reason, probably lack of necessary
-libraries and/or headers. Check the mkmf.log file for more details. You may
-need configuration options.
-
-Provided configuration options:
-MESSAGE
-
- # Returns whether or not the Makefile was successfully generated. If not,
- # the script will abort with an error message.
- #
- # Internal use only.
- #
- def mkmf_failed(path)
- unless $makefile_created or File.exist?("Makefile")
- opts = $arg_config.collect {|t, n| "\t#{t}#{n ? "=#{n}" : ""}\n"}
- abort "*** #{path} failed ***\n" + FailedMessage + opts.join
- end
- end
-
- private
-
- def _libdir_basename
- @libdir_basename ||= config_string("libdir") {|name| name[/\A\$\(exec_prefix\)\/(.*)/, 1]} || "lib"
- end
-
- def MAIN_DOES_NOTHING(*refs)
- src = MAIN_DOES_NOTHING
- unless refs.empty?
- src = src.sub(/\{/) do
- $& +
- "\n if (argc > 1000000) {\n" +
- refs.map {|n|" printf(\"%p\", &#{n});\n"}.join("") +
- " }\n"
- end
- end
- src
- end
-
- extend self
- init_mkmf
-
- $make = with_config("make-prog", ENV["MAKE"] || "make")
- make, = Shellwords.shellwords($make)
- $nmake = nil
- case
- when $mswin
- $nmake = ?m if /nmake/i =~ make
- when $bccwin
- $nmake = ?b if /Borland/i =~ `#{make} -h`
- end
- $ignore_error = $nmake ? '' : ' 2> /dev/null || true'
-
- RbConfig::CONFIG["srcdir"] = CONFIG["srcdir"] =
- $srcdir = arg_config("--srcdir", File.dirname($0))
- $configure_args["--topsrcdir"] ||= $srcdir
- if $curdir = arg_config("--curdir")
- RbConfig.expand(curdir = $curdir.dup)
- else
- curdir = $curdir = "."
- end
- unless File.expand_path(RbConfig::CONFIG["topdir"]) == File.expand_path(curdir)
- CONFIG["topdir"] = $curdir
- RbConfig::CONFIG["topdir"] = curdir
- end
- $configure_args["--topdir"] ||= $curdir
- $ruby = arg_config("--ruby", File.join(RbConfig::CONFIG["bindir"], CONFIG["ruby_install_name"]))
-
- RbConfig.expand(CONFIG["RUBY_SO_NAME"])
-
- # :startdoc:
-
- split = Shellwords.method(:shellwords).to_proc
-
- EXPORT_PREFIX = config_string('EXPORT_PREFIX') {|s| s.strip}
-
- hdr = ['#include "ruby.h"' "\n"]
- config_string('COMMON_MACROS') do |s|
- Shellwords.shellwords(s).each do |w|
- w, v = w.split(/=/, 2)
- hdr << "#ifndef #{w}"
- hdr << "#define #{[w, v].compact.join(" ")}"
- hdr << "#endif /* #{w} */"
- end
- end
- config_string('COMMON_HEADERS') do |s|
- Shellwords.shellwords(s).each {|w| hdr << "#include <#{w}>"}
- end
-
- ##
- # Common headers for Ruby C extensions
-
- COMMON_HEADERS = hdr.join("\n")
-
- ##
- # Common libraries for Ruby C extensions
-
- COMMON_LIBS = config_string('COMMON_LIBS', &split) || []
-
- ##
- # make compile rules
-
- COMPILE_RULES = config_string('COMPILE_RULES', &split) || %w[.%s.%s:]
- RULE_SUBST = config_string('RULE_SUBST')
-
- ##
- # Command which will compile C files in the generated Makefile
-
- COMPILE_C = config_string('COMPILE_C') || '$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<'
-
- ##
- # Command which will compile C++ files in the generated Makefile
-
- COMPILE_CXX = config_string('COMPILE_CXX') || '$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<'
-
- ##
- # Command which will translate C files to assembler sources in the generated Makefile
-
- ASSEMBLE_C = config_string('ASSEMBLE_C') || COMPILE_C.sub(/(?<=\s)-c(?=\s)/, '-S')
-
- ##
- # Command which will translate C++ files to assembler sources in the generated Makefile
-
- ASSEMBLE_CXX = config_string('ASSEMBLE_CXX') || COMPILE_CXX.sub(/(?<=\s)-c(?=\s)/, '-S')
-
- ##
- # Command which will compile a program in order to test linking a library
-
- TRY_LINK = config_string('TRY_LINK') ||
- "$(CC) #{OUTFLAG}#{CONFTEST}#{$EXEEXT} $(INCFLAGS) $(CPPFLAGS) " \
- "$(CFLAGS) $(src) $(LIBPATH) $(LDFLAGS) $(ARCH_FLAG) $(LOCAL_LIBS) $(LIBS)"
-
- ##
- # Command which will link a shared library
-
- LINK_SO = (config_string('LINK_SO') || "").sub(/^$/) do
- if CONFIG["DLEXT"] == $OBJEXT
- "ld $(DLDFLAGS) -r -o $@ $(OBJS)\n"
- else
- "$(LDSHARED) #{OUTFLAG}$@ $(OBJS) " \
- "$(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)"
- end
- end
-
- ##
- # Argument which will add a library path to the linker
-
- LIBPATHFLAG = config_string('LIBPATHFLAG') || ' -L%s'
- RPATHFLAG = config_string('RPATHFLAG') || ''
-
- ##
- # Argument which will add a library to the linker
-
- LIBARG = config_string('LIBARG') || '-l%s'
-
- ##
- # A C main function which does no work
-
- MAIN_DOES_NOTHING = config_string('MAIN_DOES_NOTHING') || "int main(int argc, char **argv)\n{\n return 0;\n}"
- UNIVERSAL_INTS = config_string('UNIVERSAL_INTS') {|s| Shellwords.shellwords(s)} ||
- %w[int short long long\ long]
-
- sep = config_string('BUILD_FILE_SEPARATOR') {|s| ":/=#{s}" if s != "/"} || ""
-
- ##
- # Makefile rules that will clean the extension build directory
-
- CLEANINGS = "
-clean-static::
-clean-rb-default::
-clean-rb::
-clean-so::
-clean: clean-so clean-static clean-rb-default clean-rb
-\t\t-$(Q)$(RM) $(CLEANLIBS#{sep}) $(CLEANOBJS#{sep}) $(CLEANFILES#{sep}) .*.time
-
-distclean-rb-default::
-distclean-rb::
-distclean-so::
-distclean-static::
-distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
-\t\t-$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) #{CONFTEST}.* mkmf.log
-\t\t-$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES#{sep})
-\t\t-$(Q)$(RMDIRS) $(DISTCLEANDIRS#{sep})#{$ignore_error}
-
-realclean: distclean
-"
-end
-
-include MakeMakefile
-
-if not $extmk and /\A(extconf|makefile).rb\z/ =~ File.basename($0)
- END {mkmf_failed($0)}
-end
diff --git a/ruby_2_2/lib/monitor.rb b/ruby_2_2/lib/monitor.rb
deleted file mode 100644
index 07394b5900..0000000000
--- a/ruby_2_2/lib/monitor.rb
+++ /dev/null
@@ -1,300 +0,0 @@
-# = monitor.rb
-#
-# Copyright (C) 2001 Shugo Maeda <shugo@ruby-lang.org>
-#
-# This library is distributed under the terms of the Ruby license.
-# You can freely distribute/modify this library.
-#
-
-require 'thread'
-
-#
-# In concurrent programming, a monitor is an object or module intended to be
-# used safely by more than one thread. The defining characteristic of a
-# monitor is that its methods are executed with mutual exclusion. That is, at
-# each point in time, at most one thread may be executing any of its methods.
-# This mutual exclusion greatly simplifies reasoning about the implementation
-# of monitors compared to reasoning about parallel code that updates a data
-# structure.
-#
-# You can read more about the general principles on the Wikipedia page for
-# Monitors[http://en.wikipedia.org/wiki/Monitor_%28synchronization%29]
-#
-# == Examples
-#
-# === Simple object.extend
-#
-# require 'monitor.rb'
-#
-# buf = []
-# buf.extend(MonitorMixin)
-# empty_cond = buf.new_cond
-#
-# # consumer
-# Thread.start do
-# loop do
-# buf.synchronize do
-# empty_cond.wait_while { buf.empty? }
-# print buf.shift
-# end
-# end
-# end
-#
-# # producer
-# while line = ARGF.gets
-# buf.synchronize do
-# buf.push(line)
-# empty_cond.signal
-# end
-# end
-#
-# The consumer thread waits for the producer thread to push a line to buf
-# while <tt>buf.empty?</tt>. The producer thread (main thread) reads a
-# line from ARGF and pushes it into buf then calls <tt>empty_cond.signal</tt>
-# to notify the consumer thread of new data.
-#
-# === Simple Class include
-#
-# require 'monitor'
-#
-# class SynchronizedArray < Array
-#
-# include MonitorMixin
-#
-# def initialize(*args)
-# super(*args)
-# end
-#
-# alias :old_shift :shift
-# alias :old_unshift :unshift
-#
-# def shift(n=1)
-# self.synchronize do
-# self.old_shift(n)
-# end
-# end
-#
-# def unshift(item)
-# self.synchronize do
-# self.old_unshift(item)
-# end
-# end
-#
-# # other methods ...
-# end
-#
-# +SynchronizedArray+ implements an Array with synchronized access to items.
-# This Class is implemented as subclass of Array which includes the
-# MonitorMixin module.
-#
-module MonitorMixin
- #
- # FIXME: This isn't documented in Nutshell.
- #
- # Since MonitorMixin.new_cond returns a ConditionVariable, and the example
- # above calls while_wait and signal, this class should be documented.
- #
- class ConditionVariable
- class Timeout < Exception; end
-
- #
- # Releases the lock held in the associated monitor and waits; reacquires the lock on wakeup.
- #
- # If +timeout+ is given, this method returns after +timeout+ seconds passed,
- # even if no other thread doesn't signal.
- #
- def wait(timeout = nil)
- @monitor.__send__(:mon_check_owner)
- count = @monitor.__send__(:mon_exit_for_cond)
- begin
- @cond.wait(@monitor.instance_variable_get(:@mon_mutex), timeout)
- return true
- ensure
- @monitor.__send__(:mon_enter_for_cond, count)
- end
- end
-
- #
- # Calls wait repeatedly while the given block yields a truthy value.
- #
- def wait_while
- while yield
- wait
- end
- end
-
- #
- # Calls wait repeatedly until the given block yields a truthy value.
- #
- def wait_until
- until yield
- wait
- end
- end
-
- #
- # Wakes up the first thread in line waiting for this lock.
- #
- def signal
- @monitor.__send__(:mon_check_owner)
- @cond.signal
- end
-
- #
- # Wakes up all threads waiting for this lock.
- #
- def broadcast
- @monitor.__send__(:mon_check_owner)
- @cond.broadcast
- end
-
- private
-
- def initialize(monitor)
- @monitor = monitor
- @cond = ::ConditionVariable.new
- end
- end
-
- def self.extend_object(obj)
- super(obj)
- obj.__send__(:mon_initialize)
- end
-
- #
- # Attempts to enter exclusive section. Returns +false+ if lock fails.
- #
- def mon_try_enter
- if @mon_owner != Thread.current
- unless @mon_mutex.try_lock
- return false
- end
- @mon_owner = Thread.current
- end
- @mon_count += 1
- return true
- end
- # For backward compatibility
- alias try_mon_enter mon_try_enter
-
- #
- # Enters exclusive section.
- #
- def mon_enter
- if @mon_owner != Thread.current
- @mon_mutex.lock
- @mon_owner = Thread.current
- end
- @mon_count += 1
- end
-
- #
- # Leaves exclusive section.
- #
- def mon_exit
- mon_check_owner
- @mon_count -=1
- if @mon_count == 0
- @mon_owner = nil
- @mon_mutex.unlock
- end
- end
-
- #
- # Enters exclusive section and executes the block. Leaves the exclusive
- # section automatically when the block exits. See example under
- # +MonitorMixin+.
- #
- def mon_synchronize
- mon_enter
- begin
- yield
- ensure
- mon_exit
- end
- end
- alias synchronize mon_synchronize
-
- #
- # Creates a new MonitorMixin::ConditionVariable associated with the
- # receiver.
- #
- def new_cond
- return ConditionVariable.new(self)
- end
-
- private
-
- # Use <tt>extend MonitorMixin</tt> or <tt>include MonitorMixin</tt> instead
- # of this constructor. Have look at the examples above to understand how to
- # use this module.
- def initialize(*args)
- super
- mon_initialize
- end
-
- # Initializes the MonitorMixin after being included in a class or when an
- # object has been extended with the MonitorMixin
- def mon_initialize
- @mon_owner = nil
- @mon_count = 0
- @mon_mutex = Mutex.new
- end
-
- def mon_check_owner
- if @mon_owner != Thread.current
- raise ThreadError, "current thread not owner"
- end
- end
-
- def mon_enter_for_cond(count)
- @mon_owner = Thread.current
- @mon_count = count
- end
-
- def mon_exit_for_cond
- count = @mon_count
- @mon_owner = nil
- @mon_count = 0
- return count
- end
-end
-
-# Use the Monitor class when you want to have a lock object for blocks with
-# mutual exclusion.
-#
-# require 'monitor'
-#
-# lock = Monitor.new
-# lock.synchronize do
-# # exclusive access
-# end
-#
-class Monitor
- include MonitorMixin
- alias try_enter try_mon_enter
- alias enter mon_enter
- alias exit mon_exit
-end
-
-
-# Documentation comments:
-# - All documentation comes from Nutshell.
-# - MonitorMixin.new_cond appears in the example, but is not documented in
-# Nutshell.
-# - All the internals (internal modules Accessible and Initializable, class
-# ConditionVariable) appear in RDoc. It might be good to hide them, by
-# making them private, or marking them :nodoc:, etc.
-# - RDoc doesn't recognise aliases, so we have mon_synchronize documented, but
-# not synchronize.
-# - mon_owner is in Nutshell, but appears as an accessor in a separate module
-# here, so is hard/impossible to RDoc. Some other useful accessors
-# (mon_count and some queue stuff) are also in this module, and don't appear
-# directly in the RDoc output.
-# - in short, it may be worth changing the code layout in this file to make the
-# documentation easier
-
-# Local variables:
-# mode: Ruby
-# tab-width: 8
-# End:
diff --git a/ruby_2_2/lib/mutex_m.rb b/ruby_2_2/lib/mutex_m.rb
deleted file mode 100644
index 6698cb5ac6..0000000000
--- a/ruby_2_2/lib/mutex_m.rb
+++ /dev/null
@@ -1,111 +0,0 @@
-#
-# mutex_m.rb -
-# $Release Version: 3.0$
-# $Revision: 1.7 $
-# Original from mutex.rb
-# by Keiju ISHITSUKA(keiju@ishitsuka.com)
-# modified by matz
-# patched by akira yamada
-#
-# --
-
-
-require 'thread'
-
-# = mutex_m.rb
-#
-# When 'mutex_m' is required, any object that extends or includes Mutex_m will
-# be treated like a Mutex.
-#
-# Start by requiring the standard library Mutex_m:
-#
-# require "mutex_m.rb"
-#
-# From here you can extend an object with Mutex instance methods:
-#
-# obj = Object.new
-# obj.extend Mutex_m
-#
-# Or mixin Mutex_m into your module to your class inherit Mutex instance
-# methods.
-#
-# class Foo
-# include Mutex_m
-# # ...
-# end
-# obj = Foo.new
-# # this obj can be handled like Mutex
-#
-module Mutex_m
- def Mutex_m.define_aliases(cl) # :nodoc:
- cl.module_eval %q{
- alias locked? mu_locked?
- alias lock mu_lock
- alias unlock mu_unlock
- alias try_lock mu_try_lock
- alias synchronize mu_synchronize
- }
- end
-
- def Mutex_m.append_features(cl) # :nodoc:
- super
- define_aliases(cl) unless cl.instance_of?(Module)
- end
-
- def Mutex_m.extend_object(obj) # :nodoc:
- super
- obj.mu_extended
- end
-
- def mu_extended # :nodoc:
- unless (defined? locked? and
- defined? lock and
- defined? unlock and
- defined? try_lock and
- defined? synchronize)
- Mutex_m.define_aliases(singleton_class)
- end
- mu_initialize
- end
-
- # See Mutex#synchronize
- def mu_synchronize(&block)
- @_mutex.synchronize(&block)
- end
-
- # See Mutex#locked?
- def mu_locked?
- @_mutex.locked?
- end
-
- # See Mutex#try_lock
- def mu_try_lock
- @_mutex.try_lock
- end
-
- # See Mutex#lock
- def mu_lock
- @_mutex.lock
- end
-
- # See Mutex#unlock
- def mu_unlock
- @_mutex.unlock
- end
-
- # See Mutex#sleep
- def sleep(timeout = nil)
- @_mutex.sleep(timeout)
- end
-
- private
-
- def mu_initialize # :nodoc:
- @_mutex = Mutex.new
- end
-
- def initialize(*args) # :nodoc:
- mu_initialize
- super
- end
-end
diff --git a/ruby_2_2/lib/net/ftp.rb b/ruby_2_2/lib/net/ftp.rb
deleted file mode 100644
index 79edb80864..0000000000
--- a/ruby_2_2/lib/net/ftp.rb
+++ /dev/null
@@ -1,1128 +0,0 @@
-#
-# = net/ftp.rb - FTP Client Library
-#
-# Written by Shugo Maeda <shugo@ruby-lang.org>.
-#
-# Documentation by Gavin Sinclair, sourced from "Programming Ruby" (Hunt/Thomas)
-# and "Ruby In a Nutshell" (Matsumoto), used with permission.
-#
-# This library is distributed under the terms of the Ruby license.
-# You can freely distribute/modify this library.
-#
-# It is included in the Ruby standard library.
-#
-# See the Net::FTP class for an overview.
-#
-
-require "socket"
-require "monitor"
-require "net/protocol"
-
-module Net
-
- # :stopdoc:
- class FTPError < StandardError; end
- class FTPReplyError < FTPError; end
- class FTPTempError < FTPError; end
- class FTPPermError < FTPError; end
- class FTPProtoError < FTPError; end
- class FTPConnectionError < FTPError; end
- # :startdoc:
-
- #
- # This class implements the File Transfer Protocol. If you have used a
- # command-line FTP program, and are familiar with the commands, you will be
- # able to use this class easily. Some extra features are included to take
- # advantage of Ruby's style and strengths.
- #
- # == Example
- #
- # require 'net/ftp'
- #
- # === Example 1
- #
- # ftp = Net::FTP.new('example.com')
- # ftp.login
- # files = ftp.chdir('pub/lang/ruby/contrib')
- # files = ftp.list('n*')
- # ftp.getbinaryfile('nif.rb-0.91.gz', 'nif.gz', 1024)
- # ftp.close
- #
- # === Example 2
- #
- # Net::FTP.open('example.com') do |ftp|
- # ftp.login
- # files = ftp.chdir('pub/lang/ruby/contrib')
- # files = ftp.list('n*')
- # ftp.getbinaryfile('nif.rb-0.91.gz', 'nif.gz', 1024)
- # end
- #
- # == Major Methods
- #
- # The following are the methods most likely to be useful to users:
- # - FTP.open
- # - #getbinaryfile
- # - #gettextfile
- # - #putbinaryfile
- # - #puttextfile
- # - #chdir
- # - #nlst
- # - #size
- # - #rename
- # - #delete
- #
- class FTP
- include MonitorMixin
-
- # :stopdoc:
- FTP_PORT = 21
- CRLF = "\r\n"
- DEFAULT_BLOCKSIZE = BufferedIO::BUFSIZE
- # :startdoc:
-
- # When +true+, transfers are performed in binary mode. Default: +true+.
- attr_reader :binary
-
- # When +true+, the connection is in passive mode. Default: +false+.
- attr_accessor :passive
-
- # When +true+, all traffic to and from the server is written
- # to +$stdout+. Default: +false+.
- attr_accessor :debug_mode
-
- # Sets or retrieves the +resume+ status, which decides whether incomplete
- # transfers are resumed or restarted. Default: +false+.
- attr_accessor :resume
-
- # Number of seconds to wait for the connection to open. Any number
- # may be used, including Floats for fractional seconds. If the FTP
- # object cannot open a connection in this many seconds, it raises a
- # Net::OpenTimeout exception. The default value is +nil+.
- attr_accessor :open_timeout
-
- # Number of seconds to wait for one block to be read (via one read(2)
- # call). Any number may be used, including Floats for fractional
- # seconds. If the FTP object cannot read data in this many seconds,
- # it raises a Timeout::Error exception. The default value is 60 seconds.
- attr_reader :read_timeout
-
- # Setter for the read_timeout attribute.
- def read_timeout=(sec)
- @sock.read_timeout = sec
- @read_timeout = sec
- end
-
- # The server's welcome message.
- attr_reader :welcome
-
- # The server's last response code.
- attr_reader :last_response_code
- alias lastresp last_response_code
-
- # The server's last response.
- attr_reader :last_response
-
- #
- # A synonym for <tt>FTP.new</tt>, but with a mandatory host parameter.
- #
- # If a block is given, it is passed the +FTP+ object, which will be closed
- # when the block finishes, or when an exception is raised.
- #
- def FTP.open(host, user = nil, passwd = nil, acct = nil)
- if block_given?
- ftp = new(host, user, passwd, acct)
- begin
- yield ftp
- ensure
- ftp.close
- end
- else
- new(host, user, passwd, acct)
- end
- end
-
- #
- # Creates and returns a new +FTP+ object. If a +host+ is given, a connection
- # is made. Additionally, if the +user+ is given, the given user name,
- # password, and (optionally) account are used to log in. See #login.
- #
- def initialize(host = nil, user = nil, passwd = nil, acct = nil)
- super()
- @binary = true
- @passive = false
- @debug_mode = false
- @resume = false
- @sock = NullSocket.new
- @logged_in = false
- @open_timeout = nil
- @read_timeout = 60
- if host
- connect(host)
- if user
- login(user, passwd, acct)
- end
- end
- end
-
- # A setter to toggle transfers in binary mode.
- # +newmode+ is either +true+ or +false+
- def binary=(newmode)
- if newmode != @binary
- @binary = newmode
- send_type_command if @logged_in
- end
- end
-
- # Sends a command to destination host, with the current binary sendmode
- # type.
- #
- # If binary mode is +true+, then "TYPE I" (image) is sent, otherwise "TYPE
- # A" (ascii) is sent.
- def send_type_command # :nodoc:
- if @binary
- voidcmd("TYPE I")
- else
- voidcmd("TYPE A")
- end
- end
- private :send_type_command
-
- # Toggles transfers in binary mode and yields to a block.
- # This preserves your current binary send mode, but allows a temporary
- # transaction with binary sendmode of +newmode+.
- #
- # +newmode+ is either +true+ or +false+
- def with_binary(newmode) # :nodoc:
- oldmode = binary
- self.binary = newmode
- begin
- yield
- ensure
- self.binary = oldmode
- end
- end
- private :with_binary
-
- # Obsolete
- def return_code # :nodoc:
- $stderr.puts("warning: Net::FTP#return_code is obsolete and do nothing")
- return "\n"
- end
-
- # Obsolete
- def return_code=(s) # :nodoc:
- $stderr.puts("warning: Net::FTP#return_code= is obsolete and do nothing")
- end
-
- # Constructs a socket with +host+ and +port+.
- #
- # If SOCKSSocket is defined and the environment (ENV) defines
- # SOCKS_SERVER, then a SOCKSSocket is returned, else a TCPSocket is
- # returned.
- def open_socket(host, port) # :nodoc:
- return Timeout.timeout(@open_timeout, Net::OpenTimeout) {
- if defined? SOCKSSocket and ENV["SOCKS_SERVER"]
- @passive = true
- sock = SOCKSSocket.open(host, port)
- else
- sock = TCPSocket.open(host, port)
- end
- io = BufferedSocket.new(sock)
- io.read_timeout = @read_timeout
- io
- }
- end
- private :open_socket
-
- #
- # Establishes an FTP connection to host, optionally overriding the default
- # port. If the environment variable +SOCKS_SERVER+ is set, sets up the
- # connection through a SOCKS proxy. Raises an exception (typically
- # <tt>Errno::ECONNREFUSED</tt>) if the connection cannot be established.
- #
- def connect(host, port = FTP_PORT)
- if @debug_mode
- print "connect: ", host, ", ", port, "\n"
- end
- synchronize do
- @sock = open_socket(host, port)
- voidresp
- end
- end
-
- #
- # Set the socket used to connect to the FTP server.
- #
- # May raise FTPReplyError if +get_greeting+ is false.
- def set_socket(sock, get_greeting = true)
- synchronize do
- @sock = sock
- if get_greeting
- voidresp
- end
- end
- end
-
- # If string +s+ includes the PASS command (password), then the contents of
- # the password are cleaned from the string using "*"
- def sanitize(s) # :nodoc:
- if s =~ /^PASS /i
- return s[0, 5] + "*" * (s.length - 5)
- else
- return s
- end
- end
- private :sanitize
-
- # Ensures that +line+ has a control return / line feed (CRLF) and writes
- # it to the socket.
- def putline(line) # :nodoc:
- if @debug_mode
- print "put: ", sanitize(line), "\n"
- end
- if /[\r\n]/ =~ line
- raise ArgumentError, "A line must not contain CR or LF"
- end
- line = line + CRLF
- @sock.write(line)
- end
- private :putline
-
- # Reads a line from the sock. If EOF, then it will raise EOFError
- def getline # :nodoc:
- line = @sock.readline # if get EOF, raise EOFError
- line.sub!(/(\r\n|\n|\r)\z/n, "")
- if @debug_mode
- print "get: ", sanitize(line), "\n"
- end
- return line
- end
- private :getline
-
- # Receive a section of lines until the response code's match.
- def getmultiline # :nodoc:
- line = getline
- buff = line
- if line[3] == ?-
- code = line[0, 3]
- begin
- line = getline
- buff << "\n" << line
- end until line[0, 3] == code and line[3] != ?-
- end
- return buff << "\n"
- end
- private :getmultiline
-
- # Receives a response from the destination host.
- #
- # Returns the response code or raises FTPTempError, FTPPermError, or
- # FTPProtoError
- def getresp # :nodoc:
- @last_response = getmultiline
- @last_response_code = @last_response[0, 3]
- case @last_response_code
- when /\A[123]/
- return @last_response
- when /\A4/
- raise FTPTempError, @last_response
- when /\A5/
- raise FTPPermError, @last_response
- else
- raise FTPProtoError, @last_response
- end
- end
- private :getresp
-
- # Receives a response.
- #
- # Raises FTPReplyError if the first position of the response code is not
- # equal 2.
- def voidresp # :nodoc:
- resp = getresp
- if resp[0] != ?2
- raise FTPReplyError, resp
- end
- end
- private :voidresp
-
- #
- # Sends a command and returns the response.
- #
- def sendcmd(cmd)
- synchronize do
- putline(cmd)
- return getresp
- end
- end
-
- #
- # Sends a command and expect a response beginning with '2'.
- #
- def voidcmd(cmd)
- synchronize do
- putline(cmd)
- voidresp
- end
- end
-
- # Constructs and send the appropriate PORT (or EPRT) command
- def sendport(host, port) # :nodoc:
- af = (@sock.peeraddr)[0]
- if af == "AF_INET"
- cmd = "PORT " + (host.split(".") + port.divmod(256)).join(",")
- elsif af == "AF_INET6"
- cmd = sprintf("EPRT |2|%s|%d|", host, port)
- else
- raise FTPProtoError, host
- end
- voidcmd(cmd)
- end
- private :sendport
-
- # Constructs a TCPServer socket
- def makeport # :nodoc:
- TCPServer.open(@sock.addr[3], 0)
- end
- private :makeport
-
- # sends the appropriate command to enable a passive connection
- def makepasv # :nodoc:
- if @sock.peeraddr[0] == "AF_INET"
- host, port = parse227(sendcmd("PASV"))
- else
- host, port = parse229(sendcmd("EPSV"))
- # host, port = parse228(sendcmd("LPSV"))
- end
- return host, port
- end
- private :makepasv
-
- # Constructs a connection for transferring data
- def transfercmd(cmd, rest_offset = nil) # :nodoc:
- if @passive
- host, port = makepasv
- conn = open_socket(host, port)
- if @resume and rest_offset
- resp = sendcmd("REST " + rest_offset.to_s)
- if resp[0] != ?3
- raise FTPReplyError, resp
- end
- end
- resp = sendcmd(cmd)
- # skip 2XX for some ftp servers
- resp = getresp if resp[0] == ?2
- if resp[0] != ?1
- raise FTPReplyError, resp
- end
- else
- sock = makeport
- begin
- sendport(sock.addr[3], sock.addr[1])
- if @resume and rest_offset
- resp = sendcmd("REST " + rest_offset.to_s)
- if resp[0] != ?3
- raise FTPReplyError, resp
- end
- end
- resp = sendcmd(cmd)
- # skip 2XX for some ftp servers
- resp = getresp if resp[0] == ?2
- if resp[0] != ?1
- raise FTPReplyError, resp
- end
- conn = BufferedSocket.new(sock.accept)
- conn.read_timeout = @read_timeout
- sock.shutdown(Socket::SHUT_WR) rescue nil
- sock.read rescue nil
- ensure
- sock.close
- end
- end
- return conn
- end
- private :transfercmd
-
- #
- # Logs in to the remote host. The session must have been
- # previously connected. If +user+ is the string "anonymous" and
- # the +password+ is +nil+, "anonymous@" is used as a password. If
- # the +acct+ parameter is not +nil+, an FTP ACCT command is sent
- # following the successful login. Raises an exception on error
- # (typically <tt>Net::FTPPermError</tt>).
- #
- def login(user = "anonymous", passwd = nil, acct = nil)
- if user == "anonymous" and passwd == nil
- passwd = "anonymous@"
- end
-
- resp = ""
- synchronize do
- resp = sendcmd('USER ' + user)
- if resp[0] == ?3
- raise FTPReplyError, resp if passwd.nil?
- resp = sendcmd('PASS ' + passwd)
- end
- if resp[0] == ?3
- raise FTPReplyError, resp if acct.nil?
- resp = sendcmd('ACCT ' + acct)
- end
- end
- if resp[0] != ?2
- raise FTPReplyError, resp
- end
- @welcome = resp
- send_type_command
- @logged_in = true
- end
-
- #
- # Puts the connection into binary (image) mode, issues the given command,
- # and fetches the data returned, passing it to the associated block in
- # chunks of +blocksize+ characters. Note that +cmd+ is a server command
- # (such as "RETR myfile").
- #
- def retrbinary(cmd, blocksize, rest_offset = nil) # :yield: data
- synchronize do
- with_binary(true) do
- begin
- conn = transfercmd(cmd, rest_offset)
- loop do
- data = conn.read(blocksize)
- break if data == nil
- yield(data)
- end
- conn.shutdown(Socket::SHUT_WR)
- conn.read_timeout = 1
- conn.read
- ensure
- conn.close if conn
- end
- voidresp
- end
- end
- end
-
- #
- # Puts the connection into ASCII (text) mode, issues the given command, and
- # passes the resulting data, one line at a time, to the associated block. If
- # no block is given, prints the lines. Note that +cmd+ is a server command
- # (such as "RETR myfile").
- #
- def retrlines(cmd) # :yield: line
- synchronize do
- with_binary(false) do
- begin
- conn = transfercmd(cmd)
- loop do
- line = conn.gets
- break if line == nil
- yield(line.sub(/\r?\n\z/, ""), !line.match(/\n\z/).nil?)
- end
- conn.shutdown(Socket::SHUT_WR)
- conn.read_timeout = 1
- conn.read
- ensure
- conn.close if conn
- end
- voidresp
- end
- end
- end
-
- #
- # Puts the connection into binary (image) mode, issues the given server-side
- # command (such as "STOR myfile"), and sends the contents of the file named
- # +file+ to the server. If the optional block is given, it also passes it
- # the data, in chunks of +blocksize+ characters.
- #
- def storbinary(cmd, file, blocksize, rest_offset = nil) # :yield: data
- if rest_offset
- file.seek(rest_offset, IO::SEEK_SET)
- end
- synchronize do
- with_binary(true) do
- conn = transfercmd(cmd)
- loop do
- buf = file.read(blocksize)
- break if buf == nil
- conn.write(buf)
- yield(buf) if block_given?
- end
- conn.close
- voidresp
- end
- end
- rescue Errno::EPIPE
- # EPIPE, in this case, means that the data connection was unexpectedly
- # terminated. Rather than just raising EPIPE to the caller, check the
- # response on the control connection. If getresp doesn't raise a more
- # appropriate exception, re-raise the original exception.
- getresp
- raise
- end
-
- #
- # Puts the connection into ASCII (text) mode, issues the given server-side
- # command (such as "STOR myfile"), and sends the contents of the file
- # named +file+ to the server, one line at a time. If the optional block is
- # given, it also passes it the lines.
- #
- def storlines(cmd, file) # :yield: line
- synchronize do
- with_binary(false) do
- conn = transfercmd(cmd)
- loop do
- buf = file.gets
- break if buf == nil
- if buf[-2, 2] != CRLF
- buf = buf.chomp + CRLF
- end
- conn.write(buf)
- yield(buf) if block_given?
- end
- conn.close
- voidresp
- end
- end
- rescue Errno::EPIPE
- # EPIPE, in this case, means that the data connection was unexpectedly
- # terminated. Rather than just raising EPIPE to the caller, check the
- # response on the control connection. If getresp doesn't raise a more
- # appropriate exception, re-raise the original exception.
- getresp
- raise
- end
-
- #
- # Retrieves +remotefile+ in binary mode, storing the result in +localfile+.
- # If +localfile+ is nil, returns retrieved data.
- # If a block is supplied, it is passed the retrieved data in +blocksize+
- # chunks.
- #
- def getbinaryfile(remotefile, localfile = File.basename(remotefile),
- blocksize = DEFAULT_BLOCKSIZE) # :yield: data
- result = nil
- if localfile
- if @resume
- rest_offset = File.size?(localfile)
- f = File.open(localfile, "a")
- else
- rest_offset = nil
- f = File.open(localfile, "w")
- end
- elsif !block_given?
- result = ""
- end
- begin
- f.binmode if localfile
- retrbinary("RETR " + remotefile.to_s, blocksize, rest_offset) do |data|
- f.write(data) if localfile
- yield(data) if block_given?
- result.concat(data) if result
- end
- return result
- ensure
- f.close if localfile
- end
- end
-
- #
- # Retrieves +remotefile+ in ASCII (text) mode, storing the result in
- # +localfile+.
- # If +localfile+ is nil, returns retrieved data.
- # If a block is supplied, it is passed the retrieved data one
- # line at a time.
- #
- def gettextfile(remotefile, localfile = File.basename(remotefile)) # :yield: line
- result = nil
- if localfile
- f = File.open(localfile, "w")
- elsif !block_given?
- result = ""
- end
- begin
- retrlines("RETR " + remotefile) do |line, newline|
- l = newline ? line + "\n" : line
- f.print(l) if localfile
- yield(line, newline) if block_given?
- result.concat(l) if result
- end
- return result
- ensure
- f.close if localfile
- end
- end
-
- #
- # Retrieves +remotefile+ in whatever mode the session is set (text or
- # binary). See #gettextfile and #getbinaryfile.
- #
- def get(remotefile, localfile = File.basename(remotefile),
- blocksize = DEFAULT_BLOCKSIZE, &block) # :yield: data
- if @binary
- getbinaryfile(remotefile, localfile, blocksize, &block)
- else
- gettextfile(remotefile, localfile, &block)
- end
- end
-
- #
- # Transfers +localfile+ to the server in binary mode, storing the result in
- # +remotefile+. If a block is supplied, calls it, passing in the transmitted
- # data in +blocksize+ chunks.
- #
- def putbinaryfile(localfile, remotefile = File.basename(localfile),
- blocksize = DEFAULT_BLOCKSIZE, &block) # :yield: data
- if @resume
- begin
- rest_offset = size(remotefile)
- rescue Net::FTPPermError
- rest_offset = nil
- end
- else
- rest_offset = nil
- end
- f = File.open(localfile)
- begin
- f.binmode
- if rest_offset
- storbinary("APPE " + remotefile, f, blocksize, rest_offset, &block)
- else
- storbinary("STOR " + remotefile, f, blocksize, rest_offset, &block)
- end
- ensure
- f.close
- end
- end
-
- #
- # Transfers +localfile+ to the server in ASCII (text) mode, storing the result
- # in +remotefile+. If callback or an associated block is supplied, calls it,
- # passing in the transmitted data one line at a time.
- #
- def puttextfile(localfile, remotefile = File.basename(localfile), &block) # :yield: line
- f = File.open(localfile)
- begin
- storlines("STOR " + remotefile, f, &block)
- ensure
- f.close
- end
- end
-
- #
- # Transfers +localfile+ to the server in whatever mode the session is set
- # (text or binary). See #puttextfile and #putbinaryfile.
- #
- def put(localfile, remotefile = File.basename(localfile),
- blocksize = DEFAULT_BLOCKSIZE, &block)
- if @binary
- putbinaryfile(localfile, remotefile, blocksize, &block)
- else
- puttextfile(localfile, remotefile, &block)
- end
- end
-
- #
- # Sends the ACCT command.
- #
- # This is a less common FTP command, to send account
- # information if the destination host requires it.
- #
- def acct(account)
- cmd = "ACCT " + account
- voidcmd(cmd)
- end
-
- #
- # Returns an array of filenames in the remote directory.
- #
- def nlst(dir = nil)
- cmd = "NLST"
- if dir
- cmd = cmd + " " + dir
- end
- files = []
- retrlines(cmd) do |line|
- files.push(line)
- end
- return files
- end
-
- #
- # Returns an array of file information in the directory (the output is like
- # `ls -l`). If a block is given, it iterates through the listing.
- #
- def list(*args, &block) # :yield: line
- cmd = "LIST"
- args.each do |arg|
- cmd = cmd + " " + arg.to_s
- end
- if block
- retrlines(cmd, &block)
- else
- lines = []
- retrlines(cmd) do |line|
- lines << line
- end
- return lines
- end
- end
- alias ls list
- alias dir list
-
- #
- # Renames a file on the server.
- #
- def rename(fromname, toname)
- resp = sendcmd("RNFR " + fromname)
- if resp[0] != ?3
- raise FTPReplyError, resp
- end
- voidcmd("RNTO " + toname)
- end
-
- #
- # Deletes a file on the server.
- #
- def delete(filename)
- resp = sendcmd("DELE " + filename)
- if resp[0, 3] == "250"
- return
- elsif resp[0] == ?5
- raise FTPPermError, resp
- else
- raise FTPReplyError, resp
- end
- end
-
- #
- # Changes the (remote) directory.
- #
- def chdir(dirname)
- if dirname == ".."
- begin
- voidcmd("CDUP")
- return
- rescue FTPPermError => e
- if e.message[0, 3] != "500"
- raise e
- end
- end
- end
- cmd = "CWD " + dirname
- voidcmd(cmd)
- end
-
- #
- # Returns the size of the given (remote) filename.
- #
- def size(filename)
- with_binary(true) do
- resp = sendcmd("SIZE " + filename)
- if resp[0, 3] != "213"
- raise FTPReplyError, resp
- end
- return resp[3..-1].strip.to_i
- end
- end
-
- MDTM_REGEXP = /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/ # :nodoc:
-
- #
- # Returns the last modification time of the (remote) file. If +local+ is
- # +true+, it is returned as a local time, otherwise it's a UTC time.
- #
- def mtime(filename, local = false)
- str = mdtm(filename)
- ary = str.scan(MDTM_REGEXP)[0].collect {|i| i.to_i}
- return local ? Time.local(*ary) : Time.gm(*ary)
- end
-
- #
- # Creates a remote directory.
- #
- def mkdir(dirname)
- resp = sendcmd("MKD " + dirname)
- return parse257(resp)
- end
-
- #
- # Removes a remote directory.
- #
- def rmdir(dirname)
- voidcmd("RMD " + dirname)
- end
-
- #
- # Returns the current remote directory.
- #
- def pwd
- resp = sendcmd("PWD")
- return parse257(resp)
- end
- alias getdir pwd
-
- #
- # Returns system information.
- #
- def system
- resp = sendcmd("SYST")
- if resp[0, 3] != "215"
- raise FTPReplyError, resp
- end
- return resp[4 .. -1]
- end
-
- #
- # Aborts the previous command (ABOR command).
- #
- def abort
- line = "ABOR" + CRLF
- print "put: ABOR\n" if @debug_mode
- @sock.send(line, Socket::MSG_OOB)
- resp = getmultiline
- unless ["426", "226", "225"].include?(resp[0, 3])
- raise FTPProtoError, resp
- end
- return resp
- end
-
- #
- # Returns the status (STAT command).
- #
- def status
- line = "STAT" + CRLF
- print "put: STAT\n" if @debug_mode
- @sock.send(line, Socket::MSG_OOB)
- return getresp
- end
-
- #
- # Returns the raw last modification time of the (remote) file in the format
- # "YYYYMMDDhhmmss" (MDTM command).
- #
- # Use +mtime+ if you want a parsed Time instance.
- #
- def mdtm(filename)
- resp = sendcmd("MDTM " + filename)
- if resp[0, 3] == "213"
- return resp[3 .. -1].strip
- end
- end
-
- #
- # Issues the HELP command.
- #
- def help(arg = nil)
- cmd = "HELP"
- if arg
- cmd = cmd + " " + arg
- end
- sendcmd(cmd)
- end
-
- #
- # Exits the FTP session.
- #
- def quit
- voidcmd("QUIT")
- end
-
- #
- # Issues a NOOP command.
- #
- # Does nothing except return a response.
- #
- def noop
- voidcmd("NOOP")
- end
-
- #
- # Issues a SITE command.
- #
- def site(arg)
- cmd = "SITE " + arg
- voidcmd(cmd)
- end
-
- #
- # Closes the connection. Further operations are impossible until you open
- # a new connection with #connect.
- #
- def close
- if @sock and not @sock.closed?
- begin
- @sock.shutdown(Socket::SHUT_WR) rescue nil
- orig, self.read_timeout = self.read_timeout, 3
- @sock.read rescue nil
- ensure
- @sock.close
- self.read_timeout = orig
- end
- end
- end
-
- #
- # Returns +true+ iff the connection is closed.
- #
- def closed?
- @sock == nil or @sock.closed?
- end
-
- # handler for response code 227
- # (Entering Passive Mode (h1,h2,h3,h4,p1,p2))
- #
- # Returns host and port.
- def parse227(resp) # :nodoc:
- if resp[0, 3] != "227"
- raise FTPReplyError, resp
- end
- if m = /\((?<host>\d+(,\d+){3}),(?<port>\d+,\d+)\)/.match(resp)
- return parse_pasv_ipv4_host(m["host"]), parse_pasv_port(m["port"])
- else
- raise FTPProtoError, resp
- end
- end
- private :parse227
-
- # handler for response code 228
- # (Entering Long Passive Mode)
- #
- # Returns host and port.
- def parse228(resp) # :nodoc:
- if resp[0, 3] != "228"
- raise FTPReplyError, resp
- end
- if m = /\(4,4,(?<host>\d+(,\d+){3}),2,(?<port>\d+,\d+)\)/.match(resp)
- return parse_pasv_ipv4_host(m["host"]), parse_pasv_port(m["port"])
- elsif m = /\(6,16,(?<host>\d+(,(\d+)){15}),2,(?<port>\d+,\d+)\)/.match(resp)
- return parse_pasv_ipv6_host(m["host"]), parse_pasv_port(m["port"])
- else
- raise FTPProtoError, resp
- end
- end
- private :parse228
-
- def parse_pasv_ipv4_host(s)
- return s.tr(",", ".")
- end
- private :parse_pasv_ipv4_host
-
- def parse_pasv_ipv6_host(s)
- return s.split(/,/).map { |i|
- "%02x" % i.to_i
- }.each_slice(2).map(&:join).join(":")
- end
- private :parse_pasv_ipv6_host
-
- def parse_pasv_port(s)
- return s.split(/,/).map(&:to_i).inject { |x, y|
- (x << 8) + y
- }
- end
- private :parse_pasv_port
-
- # handler for response code 229
- # (Extended Passive Mode Entered)
- #
- # Returns host and port.
- def parse229(resp) # :nodoc:
- if resp[0, 3] != "229"
- raise FTPReplyError, resp
- end
- if m = /\((?<d>[!-~])\k<d>\k<d>(?<port>\d+)\k<d>\)/.match(resp)
- return @sock.peeraddr[3], m["port"].to_i
- else
- raise FTPProtoError, resp
- end
- end
- private :parse229
-
- # handler for response code 257
- # ("PATHNAME" created)
- #
- # Returns host and port.
- def parse257(resp) # :nodoc:
- if resp[0, 3] != "257"
- raise FTPReplyError, resp
- end
- if resp[3, 2] != ' "'
- return ""
- end
- dirname = ""
- i = 5
- n = resp.length
- while i < n
- c = resp[i, 1]
- i = i + 1
- if c == '"'
- if i > n or resp[i, 1] != '"'
- break
- end
- i = i + 1
- end
- dirname = dirname + c
- end
- return dirname
- end
- private :parse257
-
- # :stopdoc:
- class NullSocket
- def read_timeout=(sec)
- end
-
- def closed?
- true
- end
-
- def close
- end
-
- def method_missing(mid, *args)
- raise FTPConnectionError, "not connected"
- end
- end
-
- class BufferedSocket < BufferedIO
- [:addr, :peeraddr, :send, :shutdown].each do |method|
- define_method(method) { |*args|
- @io.__send__(method, *args)
- }
- end
-
- def read(len = nil)
- if len
- s = super(len, "", true)
- return s.empty? ? nil : s
- else
- result = ""
- while s = super(DEFAULT_BLOCKSIZE, "", true)
- break if s.empty?
- result << s
- end
- return result
- end
- end
-
- def gets
- line = readuntil("\n", true)
- return line.empty? ? nil : line
- end
-
- def readline
- line = gets
- if line.nil?
- raise EOFError, "end of file reached"
- end
- return line
- end
- end
- # :startdoc:
- end
-end
-
-
-# Documentation comments:
-# - sourced from pickaxe and nutshell, with improvements (hopefully)
diff --git a/ruby_2_2/lib/net/http.rb b/ruby_2_2/lib/net/http.rb
deleted file mode 100644
index bceee1c069..0000000000
--- a/ruby_2_2/lib/net/http.rb
+++ /dev/null
@@ -1,1559 +0,0 @@
-#
-# = net/http.rb
-#
-# Copyright (c) 1999-2007 Yukihiro Matsumoto
-# Copyright (c) 1999-2007 Minero Aoki
-# Copyright (c) 2001 GOTOU Yuuzou
-#
-# Written and maintained by Minero Aoki <aamine@loveruby.net>.
-# HTTPS support added by GOTOU Yuuzou <gotoyuzo@notwork.org>.
-#
-# This file is derived from "http-access.rb".
-#
-# Documented by Minero Aoki; converted to RDoc by William Webber.
-#
-# This program is free software. You can re-distribute and/or
-# modify this program under the same terms of ruby itself ---
-# Ruby Distribution License or GNU General Public License.
-#
-# See Net::HTTP for an overview and examples.
-#
-
-require 'net/protocol'
-require 'uri'
-
-module Net #:nodoc:
- autoload :OpenSSL, 'openssl'
-
- # :stopdoc:
- class HTTPBadResponse < StandardError; end
- class HTTPHeaderSyntaxError < StandardError; end
- # :startdoc:
-
- # == An HTTP client API for Ruby.
- #
- # Net::HTTP provides a rich library which can be used to build HTTP
- # user-agents. For more details about HTTP see
- # [RFC2616](http://www.ietf.org/rfc/rfc2616.txt)
- #
- # Net::HTTP is designed to work closely with URI. URI::HTTP#host,
- # URI::HTTP#port and URI::HTTP#request_uri are designed to work with
- # Net::HTTP.
- #
- # If you are only performing a few GET requests you should try OpenURI.
- #
- # == Simple Examples
- #
- # All examples assume you have loaded Net::HTTP with:
- #
- # require 'net/http'
- #
- # This will also require 'uri' so you don't need to require it separately.
- #
- # The Net::HTTP methods in the following section do not persist
- # connections. They are not recommended if you are performing many HTTP
- # requests.
- #
- # === GET
- #
- # Net::HTTP.get('example.com', '/index.html') # => String
- #
- # === GET by URI
- #
- # uri = URI('http://example.com/index.html?count=10')
- # Net::HTTP.get(uri) # => String
- #
- # === GET with Dynamic Parameters
- #
- # uri = URI('http://example.com/index.html')
- # params = { :limit => 10, :page => 3 }
- # uri.query = URI.encode_www_form(params)
- #
- # res = Net::HTTP.get_response(uri)
- # puts res.body if res.is_a?(Net::HTTPSuccess)
- #
- # === POST
- #
- # uri = URI('http://www.example.com/search.cgi')
- # res = Net::HTTP.post_form(uri, 'q' => 'ruby', 'max' => '50')
- # puts res.body
- #
- # === POST with Multiple Values
- #
- # uri = URI('http://www.example.com/search.cgi')
- # res = Net::HTTP.post_form(uri, 'q' => ['ruby', 'perl'], 'max' => '50')
- # puts res.body
- #
- # == How to use Net::HTTP
- #
- # The following example code can be used as the basis of a HTTP user-agent
- # which can perform a variety of request types using persistent
- # connections.
- #
- # uri = URI('http://example.com/some_path?query=string')
- #
- # Net::HTTP.start(uri.host, uri.port) do |http|
- # request = Net::HTTP::Get.new uri
- #
- # response = http.request request # Net::HTTPResponse object
- # end
- #
- # Net::HTTP::start immediately creates a connection to an HTTP server which
- # is kept open for the duration of the block. The connection will remain
- # open for multiple requests in the block if the server indicates it
- # supports persistent connections.
- #
- # The request types Net::HTTP supports are listed below in the section "HTTP
- # Request Classes".
- #
- # If you wish to re-use a connection across multiple HTTP requests without
- # automatically closing it you can use ::new instead of ::start. #request
- # will automatically open a connection to the server if one is not currently
- # open. You can manually close the connection with #finish.
- #
- # For all the Net::HTTP request objects and shortcut request methods you may
- # supply either a String for the request path or a URI from which Net::HTTP
- # will extract the request path.
- #
- # === Response Data
- #
- # uri = URI('http://example.com/index.html')
- # res = Net::HTTP.get_response(uri)
- #
- # # Headers
- # res['Set-Cookie'] # => String
- # res.get_fields('set-cookie') # => Array
- # res.to_hash['set-cookie'] # => Array
- # puts "Headers: #{res.to_hash.inspect}"
- #
- # # Status
- # puts res.code # => '200'
- # puts res.message # => 'OK'
- # puts res.class.name # => 'HTTPOK'
- #
- # # Body
- # puts res.body if res.response_body_permitted?
- #
- # === Following Redirection
- #
- # Each Net::HTTPResponse object belongs to a class for its response code.
- #
- # For example, all 2XX responses are instances of a Net::HTTPSuccess
- # subclass, a 3XX response is an instance of a Net::HTTPRedirection
- # subclass and a 200 response is an instance of the Net::HTTPOK class. For
- # details of response classes, see the section "HTTP Response Classes"
- # below.
- #
- # Using a case statement you can handle various types of responses properly:
- #
- # def fetch(uri_str, limit = 10)
- # # You should choose a better exception.
- # raise ArgumentError, 'too many HTTP redirects' if limit == 0
- #
- # response = Net::HTTP.get_response(URI(uri_str))
- #
- # case response
- # when Net::HTTPSuccess then
- # response
- # when Net::HTTPRedirection then
- # location = response['location']
- # warn "redirected to #{location}"
- # fetch(location, limit - 1)
- # else
- # response.value
- # end
- # end
- #
- # print fetch('http://www.ruby-lang.org')
- #
- # === POST
- #
- # A POST can be made using the Net::HTTP::Post request class. This example
- # creates a urlencoded POST body:
- #
- # uri = URI('http://www.example.com/todo.cgi')
- # req = Net::HTTP::Post.new(uri)
- # req.set_form_data('from' => '2005-01-01', 'to' => '2005-03-31')
- #
- # res = Net::HTTP.start(uri.hostname, uri.port) do |http|
- # http.request(req)
- # end
- #
- # case res
- # when Net::HTTPSuccess, Net::HTTPRedirection
- # # OK
- # else
- # res.value
- # end
- #
- # At this time Net::HTTP does not support multipart/form-data. To send
- # multipart/form-data use Net::HTTPRequest#body= and
- # Net::HTTPRequest#content_type=:
- #
- # req = Net::HTTP::Post.new(uri)
- # req.body = multipart_data
- # req.content_type = 'multipart/form-data'
- #
- # Other requests that can contain a body such as PUT can be created in the
- # same way using the corresponding request class (Net::HTTP::Put).
- #
- # === Setting Headers
- #
- # The following example performs a conditional GET using the
- # If-Modified-Since header. If the files has not been modified since the
- # time in the header a Not Modified response will be returned. See RFC 2616
- # section 9.3 for further details.
- #
- # uri = URI('http://example.com/cached_response')
- # file = File.stat 'cached_response'
- #
- # req = Net::HTTP::Get.new(uri)
- # req['If-Modified-Since'] = file.mtime.rfc2822
- #
- # res = Net::HTTP.start(uri.hostname, uri.port) {|http|
- # http.request(req)
- # }
- #
- # open 'cached_response', 'w' do |io|
- # io.write res.body
- # end if res.is_a?(Net::HTTPSuccess)
- #
- # === Basic Authentication
- #
- # Basic authentication is performed according to
- # [RFC2617](http://www.ietf.org/rfc/rfc2617.txt)
- #
- # uri = URI('http://example.com/index.html?key=value')
- #
- # req = Net::HTTP::Get.new(uri)
- # req.basic_auth 'user', 'pass'
- #
- # res = Net::HTTP.start(uri.hostname, uri.port) {|http|
- # http.request(req)
- # }
- # puts res.body
- #
- # === Streaming Response Bodies
- #
- # By default Net::HTTP reads an entire response into memory. If you are
- # handling large files or wish to implement a progress bar you can instead
- # stream the body directly to an IO.
- #
- # uri = URI('http://example.com/large_file')
- #
- # Net::HTTP.start(uri.host, uri.port) do |http|
- # request = Net::HTTP::Get.new uri
- #
- # http.request request do |response|
- # open 'large_file', 'w' do |io|
- # response.read_body do |chunk|
- # io.write chunk
- # end
- # end
- # end
- # end
- #
- # === HTTPS
- #
- # HTTPS is enabled for an HTTP connection by Net::HTTP#use_ssl=.
- #
- # uri = URI('https://secure.example.com/some_path?query=string')
- #
- # Net::HTTP.start(uri.host, uri.port,
- # :use_ssl => uri.scheme == 'https') do |http|
- # request = Net::HTTP::Get.new uri
- #
- # response = http.request request # Net::HTTPResponse object
- # end
- #
- # In previous versions of Ruby you would need to require 'net/https' to use
- # HTTPS. This is no longer true.
- #
- # === Proxies
- #
- # Net::HTTP will automatically create a proxy from the +http_proxy+
- # environment variable if it is present. To disable use of +http_proxy+,
- # pass +nil+ for the proxy address.
- #
- # You may also create a custom proxy:
- #
- # proxy_addr = 'your.proxy.host'
- # proxy_port = 8080
- #
- # Net::HTTP.new('example.com', nil, proxy_addr, proxy_port).start { |http|
- # # always proxy via your.proxy.addr:8080
- # }
- #
- # See Net::HTTP.new for further details and examples such as proxies that
- # require a username and password.
- #
- # === Compression
- #
- # Net::HTTP automatically adds Accept-Encoding for compression of response
- # bodies and automatically decompresses gzip and deflate responses unless a
- # Range header was sent.
- #
- # Compression can be disabled through the Accept-Encoding: identity header.
- #
- # == HTTP Request Classes
- #
- # Here is the HTTP request class hierarchy.
- #
- # * Net::HTTPRequest
- # * Net::HTTP::Get
- # * Net::HTTP::Head
- # * Net::HTTP::Post
- # * Net::HTTP::Patch
- # * Net::HTTP::Put
- # * Net::HTTP::Proppatch
- # * Net::HTTP::Lock
- # * Net::HTTP::Unlock
- # * Net::HTTP::Options
- # * Net::HTTP::Propfind
- # * Net::HTTP::Delete
- # * Net::HTTP::Move
- # * Net::HTTP::Copy
- # * Net::HTTP::Mkcol
- # * Net::HTTP::Trace
- #
- # == HTTP Response Classes
- #
- # Here is HTTP response class hierarchy. All classes are defined in Net
- # module and are subclasses of Net::HTTPResponse.
- #
- # HTTPUnknownResponse:: For unhandled HTTP extensions
- # HTTPInformation:: 1xx
- # HTTPContinue:: 100
- # HTTPSwitchProtocol:: 101
- # HTTPSuccess:: 2xx
- # HTTPOK:: 200
- # HTTPCreated:: 201
- # HTTPAccepted:: 202
- # HTTPNonAuthoritativeInformation:: 203
- # HTTPNoContent:: 204
- # HTTPResetContent:: 205
- # HTTPPartialContent:: 206
- # HTTPMultiStatus:: 207
- # HTTPIMUsed:: 226
- # HTTPRedirection:: 3xx
- # HTTPMultipleChoices:: 300
- # HTTPMovedPermanently:: 301
- # HTTPFound:: 302
- # HTTPSeeOther:: 303
- # HTTPNotModified:: 304
- # HTTPUseProxy:: 305
- # HTTPTemporaryRedirect:: 307
- # HTTPClientError:: 4xx
- # HTTPBadRequest:: 400
- # HTTPUnauthorized:: 401
- # HTTPPaymentRequired:: 402
- # HTTPForbidden:: 403
- # HTTPNotFound:: 404
- # HTTPMethodNotAllowed:: 405
- # HTTPNotAcceptable:: 406
- # HTTPProxyAuthenticationRequired:: 407
- # HTTPRequestTimeOut:: 408
- # HTTPConflict:: 409
- # HTTPGone:: 410
- # HTTPLengthRequired:: 411
- # HTTPPreconditionFailed:: 412
- # HTTPRequestEntityTooLarge:: 413
- # HTTPRequestURITooLong:: 414
- # HTTPUnsupportedMediaType:: 415
- # HTTPRequestedRangeNotSatisfiable:: 416
- # HTTPExpectationFailed:: 417
- # HTTPUnprocessableEntity:: 422
- # HTTPLocked:: 423
- # HTTPFailedDependency:: 424
- # HTTPUpgradeRequired:: 426
- # HTTPPreconditionRequired:: 428
- # HTTPTooManyRequests:: 429
- # HTTPRequestHeaderFieldsTooLarge:: 431
- # HTTPServerError:: 5xx
- # HTTPInternalServerError:: 500
- # HTTPNotImplemented:: 501
- # HTTPBadGateway:: 502
- # HTTPServiceUnavailable:: 503
- # HTTPGatewayTimeOut:: 504
- # HTTPVersionNotSupported:: 505
- # HTTPInsufficientStorage:: 507
- # HTTPNetworkAuthenticationRequired:: 511
- #
- # There is also the Net::HTTPBadResponse exception which is raised when
- # there is a protocol error.
- #
- class HTTP < Protocol
-
- # :stopdoc:
- Revision = %q$Revision$.split[1]
- HTTPVersion = '1.1'
- begin
- require 'zlib'
- require 'stringio' #for our purposes (unpacking gzip) lump these together
- HAVE_ZLIB=true
- rescue LoadError
- HAVE_ZLIB=false
- end
- # :startdoc:
-
- # Turns on net/http 1.2 (Ruby 1.8) features.
- # Defaults to ON in Ruby 1.8 or later.
- def HTTP.version_1_2
- true
- end
-
- # Returns true if net/http is in version 1.2 mode.
- # Defaults to true.
- def HTTP.version_1_2?
- true
- end
-
- def HTTP.version_1_1? #:nodoc:
- false
- end
-
- class << HTTP
- alias is_version_1_1? version_1_1? #:nodoc:
- alias is_version_1_2? version_1_2? #:nodoc:
- end
-
- #
- # short cut methods
- #
-
- #
- # Gets the body text from the target and outputs it to $stdout. The
- # target can either be specified as
- # (+uri+), or as (+host+, +path+, +port+ = 80); so:
- #
- # Net::HTTP.get_print URI('http://www.example.com/index.html')
- #
- # or:
- #
- # Net::HTTP.get_print 'www.example.com', '/index.html'
- #
- def HTTP.get_print(uri_or_host, path = nil, port = nil)
- get_response(uri_or_host, path, port) {|res|
- res.read_body do |chunk|
- $stdout.print chunk
- end
- }
- nil
- end
-
- # Sends a GET request to the target and returns the HTTP response
- # as a string. The target can either be specified as
- # (+uri+), or as (+host+, +path+, +port+ = 80); so:
- #
- # print Net::HTTP.get(URI('http://www.example.com/index.html'))
- #
- # or:
- #
- # print Net::HTTP.get('www.example.com', '/index.html')
- #
- def HTTP.get(uri_or_host, path = nil, port = nil)
- get_response(uri_or_host, path, port).body
- end
-
- # Sends a GET request to the target and returns the HTTP response
- # as a Net::HTTPResponse object. The target can either be specified as
- # (+uri+), or as (+host+, +path+, +port+ = 80); so:
- #
- # res = Net::HTTP.get_response(URI('http://www.example.com/index.html'))
- # print res.body
- #
- # or:
- #
- # res = Net::HTTP.get_response('www.example.com', '/index.html')
- # print res.body
- #
- def HTTP.get_response(uri_or_host, path = nil, port = nil, &block)
- if path
- host = uri_or_host
- new(host, port || HTTP.default_port).start {|http|
- return http.request_get(path, &block)
- }
- else
- uri = uri_or_host
- start(uri.hostname, uri.port,
- :use_ssl => uri.scheme == 'https') {|http|
- return http.request_get(uri, &block)
- }
- end
- end
-
- # Posts HTML form data to the specified URI object.
- # The form data must be provided as a Hash mapping from String to String.
- # Example:
- #
- # { "cmd" => "search", "q" => "ruby", "max" => "50" }
- #
- # This method also does Basic Authentication iff +url+.user exists.
- # But userinfo for authentication is deprecated (RFC3986).
- # So this feature will be removed.
- #
- # Example:
- #
- # require 'net/http'
- # require 'uri'
- #
- # Net::HTTP.post_form URI('http://www.example.com/search.cgi'),
- # { "q" => "ruby", "max" => "50" }
- #
- def HTTP.post_form(url, params)
- req = Post.new(url)
- req.form_data = params
- req.basic_auth url.user, url.password if url.user
- start(url.hostname, url.port,
- :use_ssl => url.scheme == 'https' ) {|http|
- http.request(req)
- }
- end
-
- #
- # HTTP session management
- #
-
- # The default port to use for HTTP requests; defaults to 80.
- def HTTP.default_port
- http_default_port()
- end
-
- # The default port to use for HTTP requests; defaults to 80.
- def HTTP.http_default_port
- 80
- end
-
- # The default port to use for HTTPS requests; defaults to 443.
- def HTTP.https_default_port
- 443
- end
-
- def HTTP.socket_type #:nodoc: obsolete
- BufferedIO
- end
-
- # :call-seq:
- # HTTP.start(address, port, p_addr, p_port, p_user, p_pass, &block)
- # HTTP.start(address, port=nil, p_addr=nil, p_port=nil, p_user=nil, p_pass=nil, opt, &block)
- #
- # Creates a new Net::HTTP object, then additionally opens the TCP
- # connection and HTTP session.
- #
- # Arguments are the following:
- # _address_ :: hostname or IP address of the server
- # _port_ :: port of the server
- # _p_addr_ :: address of proxy
- # _p_port_ :: port of proxy
- # _p_user_ :: user of proxy
- # _p_pass_ :: pass of proxy
- # _opt_ :: optional hash
- #
- # _opt_ sets following values by its accessor.
- # The keys are ca_file, ca_path, cert, cert_store, ciphers,
- # close_on_empty_response, key, open_timeout, read_timeout, ssl_timeout,
- # ssl_version, use_ssl, verify_callback, verify_depth and verify_mode.
- # If you set :use_ssl as true, you can use https and default value of
- # verify_mode is set as OpenSSL::SSL::VERIFY_PEER.
- #
- # If the optional block is given, the newly
- # created Net::HTTP object is passed to it and closed when the
- # block finishes. In this case, the return value of this method
- # is the return value of the block. If no block is given, the
- # return value of this method is the newly created Net::HTTP object
- # itself, and the caller is responsible for closing it upon completion
- # using the finish() method.
- def HTTP.start(address, *arg, &block) # :yield: +http+
- arg.pop if opt = Hash.try_convert(arg[-1])
- port, p_addr, p_port, p_user, p_pass = *arg
- port = https_default_port if !port && opt && opt[:use_ssl]
- http = new(address, port, p_addr, p_port, p_user, p_pass)
-
- if opt
- if opt[:use_ssl]
- opt = {verify_mode: OpenSSL::SSL::VERIFY_PEER}.update(opt)
- end
- http.methods.grep(/\A(\w+)=\z/) do |meth|
- key = $1.to_sym
- opt.key?(key) or next
- http.__send__(meth, opt[key])
- end
- end
-
- http.start(&block)
- end
-
- class << HTTP
- alias newobj new # :nodoc:
- end
-
- # Creates a new Net::HTTP object without opening a TCP connection or
- # HTTP session.
- #
- # The +address+ should be a DNS hostname or IP address, the +port+ is the
- # port the server operates on. If no +port+ is given the default port for
- # HTTP or HTTPS is used.
- #
- # If none of the +p_+ arguments are given, the proxy host and port are
- # taken from the +http_proxy+ environment variable (or its uppercase
- # equivalent) if present. If the proxy requires authentication you must
- # supply it by hand. See URI::Generic#find_proxy for details of proxy
- # detection from the environment. To disable proxy detection set +p_addr+
- # to nil.
- #
- # If you are connecting to a custom proxy, +p_addr+ the DNS name or IP
- # address of the proxy host, +p_port+ the port to use to access the proxy,
- # and +p_user+ and +p_pass+ the username and password if authorization is
- # required to use the proxy.
- #
- def HTTP.new(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil)
- http = super address, port
-
- if proxy_class? then # from Net::HTTP::Proxy()
- http.proxy_from_env = @proxy_from_env
- http.proxy_address = @proxy_address
- http.proxy_port = @proxy_port
- http.proxy_user = @proxy_user
- http.proxy_pass = @proxy_pass
- elsif p_addr == :ENV then
- http.proxy_from_env = true
- else
- http.proxy_address = p_addr
- http.proxy_port = p_port || default_port
- http.proxy_user = p_user
- http.proxy_pass = p_pass
- end
-
- http
- end
-
- # Creates a new Net::HTTP object for the specified server address,
- # without opening the TCP connection or initializing the HTTP session.
- # The +address+ should be a DNS hostname or IP address.
- def initialize(address, port = nil)
- @address = address
- @port = (port || HTTP.default_port)
- @local_host = nil
- @local_port = nil
- @curr_http_version = HTTPVersion
- @keep_alive_timeout = 2
- @last_communicated = nil
- @close_on_empty_response = false
- @socket = nil
- @started = false
- @open_timeout = nil
- @read_timeout = 60
- @continue_timeout = nil
- @debug_output = nil
-
- @proxy_from_env = false
- @proxy_uri = nil
- @proxy_address = nil
- @proxy_port = nil
- @proxy_user = nil
- @proxy_pass = nil
-
- @use_ssl = false
- @ssl_context = nil
- @ssl_session = nil
- @enable_post_connection_check = true
- @sspi_enabled = false
- SSL_IVNAMES.each do |ivname|
- instance_variable_set ivname, nil
- end
- end
-
- def inspect
- "#<#{self.class} #{@address}:#{@port} open=#{started?}>"
- end
-
- # *WARNING* This method opens a serious security hole.
- # Never use this method in production code.
- #
- # Sets an output stream for debugging.
- #
- # http = Net::HTTP.new(hostname)
- # http.set_debug_output $stderr
- # http.start { .... }
- #
- def set_debug_output(output)
- warn 'Net::HTTP#set_debug_output called after HTTP started' if started?
- @debug_output = output
- end
-
- # The DNS host name or IP address to connect to.
- attr_reader :address
-
- # The port number to connect to.
- attr_reader :port
-
- # The local host used to establish the connection.
- attr_accessor :local_host
-
- # The local port used to establish the connection.
- attr_accessor :local_port
-
- attr_writer :proxy_from_env
- attr_writer :proxy_address
- attr_writer :proxy_port
- attr_writer :proxy_user
- attr_writer :proxy_pass
-
- # Number of seconds to wait for the connection to open. Any number
- # may be used, including Floats for fractional seconds. If the HTTP
- # object cannot open a connection in this many seconds, it raises a
- # Net::OpenTimeout exception. The default value is +nil+.
- attr_accessor :open_timeout
-
- # Number of seconds to wait for one block to be read (via one read(2)
- # call). Any number may be used, including Floats for fractional
- # seconds. If the HTTP object cannot read data in this many seconds,
- # it raises a Net::ReadTimeout exception. The default value is 60 seconds.
- attr_reader :read_timeout
-
- # Setter for the read_timeout attribute.
- def read_timeout=(sec)
- @socket.read_timeout = sec if @socket
- @read_timeout = sec
- end
-
- # Seconds to wait for 100 Continue response. If the HTTP object does not
- # receive a response in this many seconds it sends the request body. The
- # default value is +nil+.
- attr_reader :continue_timeout
-
- # Setter for the continue_timeout attribute.
- def continue_timeout=(sec)
- @socket.continue_timeout = sec if @socket
- @continue_timeout = sec
- end
-
- # Seconds to reuse the connection of the previous request.
- # If the idle time is less than this Keep-Alive Timeout,
- # Net::HTTP reuses the TCP/IP socket used by the previous communication.
- # The default value is 2 seconds.
- attr_accessor :keep_alive_timeout
-
- # Returns true if the HTTP session has been started.
- def started?
- @started
- end
-
- alias active? started? #:nodoc: obsolete
-
- attr_accessor :close_on_empty_response
-
- # Returns true if SSL/TLS is being used with HTTP.
- def use_ssl?
- @use_ssl
- end
-
- # Turn on/off SSL.
- # This flag must be set before starting session.
- # If you change use_ssl value after session started,
- # a Net::HTTP object raises IOError.
- def use_ssl=(flag)
- flag = flag ? true : false
- if started? and @use_ssl != flag
- raise IOError, "use_ssl value changed, but session already started"
- end
- @use_ssl = flag
- end
-
- SSL_IVNAMES = [
- :@ca_file,
- :@ca_path,
- :@cert,
- :@cert_store,
- :@ciphers,
- :@key,
- :@ssl_timeout,
- :@ssl_version,
- :@verify_callback,
- :@verify_depth,
- :@verify_mode,
- ]
- SSL_ATTRIBUTES = [
- :ca_file,
- :ca_path,
- :cert,
- :cert_store,
- :ciphers,
- :key,
- :ssl_timeout,
- :ssl_version,
- :verify_callback,
- :verify_depth,
- :verify_mode,
- ]
-
- # Sets path of a CA certification file in PEM format.
- #
- # The file can contain several CA certificates.
- attr_accessor :ca_file
-
- # Sets path of a CA certification directory containing certifications in
- # PEM format.
- attr_accessor :ca_path
-
- # Sets an OpenSSL::X509::Certificate object as client certificate.
- # (This method is appeared in Michal Rokos's OpenSSL extension).
- attr_accessor :cert
-
- # Sets the X509::Store to verify peer certificate.
- attr_accessor :cert_store
-
- # Sets the available ciphers. See OpenSSL::SSL::SSLContext#ciphers=
- attr_accessor :ciphers
-
- # Sets an OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object.
- # (This method is appeared in Michal Rokos's OpenSSL extension.)
- attr_accessor :key
-
- # Sets the SSL timeout seconds.
- attr_accessor :ssl_timeout
-
- # Sets the SSL version. See OpenSSL::SSL::SSLContext#ssl_version=
- attr_accessor :ssl_version
-
- # Sets the verify callback for the server certification verification.
- attr_accessor :verify_callback
-
- # Sets the maximum depth for the certificate chain verification.
- attr_accessor :verify_depth
-
- # Sets the flags for server the certification verification at beginning of
- # SSL/TLS session.
- #
- # OpenSSL::SSL::VERIFY_NONE or OpenSSL::SSL::VERIFY_PEER are acceptable.
- attr_accessor :verify_mode
-
- # Returns the X.509 certificates the server presented.
- def peer_cert
- if not use_ssl? or not @socket
- return nil
- end
- @socket.io.peer_cert
- end
-
- # Opens a TCP connection and HTTP session.
- #
- # When this method is called with a block, it passes the Net::HTTP
- # object to the block, and closes the TCP connection and HTTP session
- # after the block has been executed.
- #
- # When called with a block, it returns the return value of the
- # block; otherwise, it returns self.
- #
- def start # :yield: http
- raise IOError, 'HTTP session already opened' if @started
- if block_given?
- begin
- do_start
- return yield(self)
- ensure
- do_finish
- end
- end
- do_start
- self
- end
-
- def do_start
- connect
- @started = true
- end
- private :do_start
-
- def connect
- if proxy? then
- conn_address = proxy_address
- conn_port = proxy_port
- else
- conn_address = address
- conn_port = port
- end
-
- D "opening connection to #{conn_address}:#{conn_port}..."
- s = Timeout.timeout(@open_timeout, Net::OpenTimeout) {
- TCPSocket.open(conn_address, conn_port, @local_host, @local_port)
- }
- s.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
- D "opened"
- if use_ssl?
- ssl_parameters = Hash.new
- iv_list = instance_variables
- SSL_IVNAMES.each_with_index do |ivname, i|
- if iv_list.include?(ivname) and
- value = instance_variable_get(ivname)
- ssl_parameters[SSL_ATTRIBUTES[i]] = value if value
- end
- end
- @ssl_context = OpenSSL::SSL::SSLContext.new
- @ssl_context.set_params(ssl_parameters)
- D "starting SSL for #{conn_address}:#{conn_port}..."
- s = OpenSSL::SSL::SSLSocket.new(s, @ssl_context)
- s.sync_close = true
- D "SSL established"
- end
- @socket = BufferedIO.new(s)
- @socket.read_timeout = @read_timeout
- @socket.continue_timeout = @continue_timeout
- @socket.debug_output = @debug_output
- if use_ssl?
- begin
- if proxy?
- buf = "CONNECT #{@address}:#{@port} HTTP/#{HTTPVersion}\r\n"
- buf << "Host: #{@address}:#{@port}\r\n"
- if proxy_user
- credential = ["#{proxy_user}:#{proxy_pass}"].pack('m')
- credential.delete!("\r\n")
- buf << "Proxy-Authorization: Basic #{credential}\r\n"
- end
- buf << "\r\n"
- @socket.write(buf)
- HTTPResponse.read_new(@socket).value
- end
- # Server Name Indication (SNI) RFC 3546
- s.hostname = @address if s.respond_to? :hostname=
- if @ssl_session and
- Process.clock_gettime(Process::CLOCK_REALTIME) < @ssl_session.time.to_f + @ssl_session.timeout
- s.session = @ssl_session if @ssl_session
- end
- Timeout.timeout(@open_timeout, Net::OpenTimeout) { s.connect }
- if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
- s.post_connection_check(@address)
- end
- @ssl_session = s.session
- rescue => exception
- D "Conn close because of connect error #{exception}"
- @socket.close if @socket and not @socket.closed?
- raise exception
- end
- end
- on_connect
- end
- private :connect
-
- def on_connect
- end
- private :on_connect
-
- # Finishes the HTTP session and closes the TCP connection.
- # Raises IOError if the session has not been started.
- def finish
- raise IOError, 'HTTP session not yet started' unless started?
- do_finish
- end
-
- def do_finish
- @started = false
- @socket.close if @socket and not @socket.closed?
- @socket = nil
- end
- private :do_finish
-
- #
- # proxy
- #
-
- public
-
- # no proxy
- @is_proxy_class = false
- @proxy_from_env = false
- @proxy_addr = nil
- @proxy_port = nil
- @proxy_user = nil
- @proxy_pass = nil
-
- # Creates an HTTP proxy class which behaves like Net::HTTP, but
- # performs all access via the specified proxy.
- #
- # This class is obsolete. You may pass these same parameters directly to
- # Net::HTTP.new. See Net::HTTP.new for details of the arguments.
- def HTTP.Proxy(p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil)
- return self unless p_addr
-
- Class.new(self) {
- @is_proxy_class = true
-
- if p_addr == :ENV then
- @proxy_from_env = true
- @proxy_address = nil
- @proxy_port = nil
- else
- @proxy_from_env = false
- @proxy_address = p_addr
- @proxy_port = p_port || default_port
- end
-
- @proxy_user = p_user
- @proxy_pass = p_pass
- }
- end
-
- class << HTTP
- # returns true if self is a class which was created by HTTP::Proxy.
- def proxy_class?
- defined?(@is_proxy_class) ? @is_proxy_class : false
- end
-
- # Address of proxy host. If Net::HTTP does not use a proxy, nil.
- attr_reader :proxy_address
-
- # Port number of proxy host. If Net::HTTP does not use a proxy, nil.
- attr_reader :proxy_port
-
- # User name for accessing proxy. If Net::HTTP does not use a proxy, nil.
- attr_reader :proxy_user
-
- # User password for accessing proxy. If Net::HTTP does not use a proxy,
- # nil.
- attr_reader :proxy_pass
- end
-
- # True if requests for this connection will be proxied
- def proxy?
- !!if @proxy_from_env then
- proxy_uri
- else
- @proxy_address
- end
- end
-
- # True if the proxy for this connection is determined from the environment
- def proxy_from_env?
- @proxy_from_env
- end
-
- # The proxy URI determined from the environment for this connection.
- def proxy_uri # :nodoc:
- @proxy_uri ||= URI::HTTP.new(
- "http".freeze, nil, address, port, nil, nil, nil, nil, nil
- ).find_proxy
- end
-
- # The address of the proxy server, if one is configured.
- def proxy_address
- if @proxy_from_env then
- proxy_uri && proxy_uri.hostname
- else
- @proxy_address
- end
- end
-
- # The port of the proxy server, if one is configured.
- def proxy_port
- if @proxy_from_env then
- proxy_uri && proxy_uri.port
- else
- @proxy_port
- end
- end
-
- # The proxy username, if one is configured
- def proxy_user
- @proxy_user
- end
-
- # The proxy password, if one is configured
- def proxy_pass
- @proxy_pass
- end
-
- alias proxyaddr proxy_address #:nodoc: obsolete
- alias proxyport proxy_port #:nodoc: obsolete
-
- private
-
- # without proxy, obsolete
-
- def conn_address # :nodoc:
- address()
- end
-
- def conn_port # :nodoc:
- port()
- end
-
- def edit_path(path)
- if proxy? and not use_ssl? then
- "http://#{addr_port}#{path}"
- else
- path
- end
- end
-
- #
- # HTTP operations
- #
-
- public
-
- # Retrieves data from +path+ on the connected-to host which may be an
- # absolute path String or a URI to extract the path from.
- #
- # +initheader+ must be a Hash like { 'Accept' => '*/*', ... },
- # and it defaults to an empty hash.
- # If +initheader+ doesn't have the key 'accept-encoding', then
- # a value of "gzip;q=1.0,deflate;q=0.6,identity;q=0.3" is used,
- # so that gzip compression is used in preference to deflate
- # compression, which is used in preference to no compression.
- # Ruby doesn't have libraries to support the compress (Lempel-Ziv)
- # compression, so that is not supported. The intent of this is
- # to reduce bandwidth by default. If this routine sets up
- # compression, then it does the decompression also, removing
- # the header as well to prevent confusion. Otherwise
- # it leaves the body as it found it.
- #
- # This method returns a Net::HTTPResponse object.
- #
- # If called with a block, yields each fragment of the
- # entity body in turn as a string as it is read from
- # the socket. Note that in this case, the returned response
- # object will *not* contain a (meaningful) body.
- #
- # +dest+ argument is obsolete.
- # It still works but you must not use it.
- #
- # This method never raises an exception.
- #
- # response = http.get('/index.html')
- #
- # # using block
- # File.open('result.txt', 'w') {|f|
- # http.get('/~foo/') do |str|
- # f.write str
- # end
- # }
- #
- def get(path, initheader = nil, dest = nil, &block) # :yield: +body_segment+
- res = nil
- request(Get.new(path, initheader)) {|r|
- r.read_body dest, &block
- res = r
- }
- res
- end
-
- # Gets only the header from +path+ on the connected-to host.
- # +header+ is a Hash like { 'Accept' => '*/*', ... }.
- #
- # This method returns a Net::HTTPResponse object.
- #
- # This method never raises an exception.
- #
- # response = nil
- # Net::HTTP.start('some.www.server', 80) {|http|
- # response = http.head('/index.html')
- # }
- # p response['content-type']
- #
- def head(path, initheader = nil)
- request(Head.new(path, initheader))
- end
-
- # Posts +data+ (must be a String) to +path+. +header+ must be a Hash
- # like { 'Accept' => '*/*', ... }.
- #
- # This method returns a Net::HTTPResponse object.
- #
- # If called with a block, yields each fragment of the
- # entity body in turn as a string as it is read from
- # the socket. Note that in this case, the returned response
- # object will *not* contain a (meaningful) body.
- #
- # +dest+ argument is obsolete.
- # It still works but you must not use it.
- #
- # This method never raises exception.
- #
- # response = http.post('/cgi-bin/search.rb', 'query=foo')
- #
- # # using block
- # File.open('result.txt', 'w') {|f|
- # http.post('/cgi-bin/search.rb', 'query=foo') do |str|
- # f.write str
- # end
- # }
- #
- # You should set Content-Type: header field for POST.
- # If no Content-Type: field given, this method uses
- # "application/x-www-form-urlencoded" by default.
- #
- def post(path, data, initheader = nil, dest = nil, &block) # :yield: +body_segment+
- send_entity(path, data, initheader, dest, Post, &block)
- end
-
- # Sends a PATCH request to the +path+ and gets a response,
- # as an HTTPResponse object.
- def patch(path, data, initheader = nil, dest = nil, &block) # :yield: +body_segment+
- send_entity(path, data, initheader, dest, Patch, &block)
- end
-
- def put(path, data, initheader = nil) #:nodoc:
- request(Put.new(path, initheader), data)
- end
-
- # Sends a PROPPATCH request to the +path+ and gets a response,
- # as an HTTPResponse object.
- def proppatch(path, body, initheader = nil)
- request(Proppatch.new(path, initheader), body)
- end
-
- # Sends a LOCK request to the +path+ and gets a response,
- # as an HTTPResponse object.
- def lock(path, body, initheader = nil)
- request(Lock.new(path, initheader), body)
- end
-
- # Sends a UNLOCK request to the +path+ and gets a response,
- # as an HTTPResponse object.
- def unlock(path, body, initheader = nil)
- request(Unlock.new(path, initheader), body)
- end
-
- # Sends a OPTIONS request to the +path+ and gets a response,
- # as an HTTPResponse object.
- def options(path, initheader = nil)
- request(Options.new(path, initheader))
- end
-
- # Sends a PROPFIND request to the +path+ and gets a response,
- # as an HTTPResponse object.
- def propfind(path, body = nil, initheader = {'Depth' => '0'})
- request(Propfind.new(path, initheader), body)
- end
-
- # Sends a DELETE request to the +path+ and gets a response,
- # as an HTTPResponse object.
- def delete(path, initheader = {'Depth' => 'Infinity'})
- request(Delete.new(path, initheader))
- end
-
- # Sends a MOVE request to the +path+ and gets a response,
- # as an HTTPResponse object.
- def move(path, initheader = nil)
- request(Move.new(path, initheader))
- end
-
- # Sends a COPY request to the +path+ and gets a response,
- # as an HTTPResponse object.
- def copy(path, initheader = nil)
- request(Copy.new(path, initheader))
- end
-
- # Sends a MKCOL request to the +path+ and gets a response,
- # as an HTTPResponse object.
- def mkcol(path, body = nil, initheader = nil)
- request(Mkcol.new(path, initheader), body)
- end
-
- # Sends a TRACE request to the +path+ and gets a response,
- # as an HTTPResponse object.
- def trace(path, initheader = nil)
- request(Trace.new(path, initheader))
- end
-
- # Sends a GET request to the +path+.
- # Returns the response as a Net::HTTPResponse object.
- #
- # When called with a block, passes an HTTPResponse object to the block.
- # The body of the response will not have been read yet;
- # the block can process it using HTTPResponse#read_body,
- # if desired.
- #
- # Returns the response.
- #
- # This method never raises Net::* exceptions.
- #
- # response = http.request_get('/index.html')
- # # The entity body is already read in this case.
- # p response['content-type']
- # puts response.body
- #
- # # Using a block
- # http.request_get('/index.html') {|response|
- # p response['content-type']
- # response.read_body do |str| # read body now
- # print str
- # end
- # }
- #
- def request_get(path, initheader = nil, &block) # :yield: +response+
- request(Get.new(path, initheader), &block)
- end
-
- # Sends a HEAD request to the +path+ and returns the response
- # as a Net::HTTPResponse object.
- #
- # Returns the response.
- #
- # This method never raises Net::* exceptions.
- #
- # response = http.request_head('/index.html')
- # p response['content-type']
- #
- def request_head(path, initheader = nil, &block)
- request(Head.new(path, initheader), &block)
- end
-
- # Sends a POST request to the +path+.
- #
- # Returns the response as a Net::HTTPResponse object.
- #
- # When called with a block, the block is passed an HTTPResponse
- # object. The body of that response will not have been read yet;
- # the block can process it using HTTPResponse#read_body, if desired.
- #
- # Returns the response.
- #
- # This method never raises Net::* exceptions.
- #
- # # example
- # response = http.request_post('/cgi-bin/nice.rb', 'datadatadata...')
- # p response.status
- # puts response.body # body is already read in this case
- #
- # # using block
- # http.request_post('/cgi-bin/nice.rb', 'datadatadata...') {|response|
- # p response.status
- # p response['content-type']
- # response.read_body do |str| # read body now
- # print str
- # end
- # }
- #
- def request_post(path, data, initheader = nil, &block) # :yield: +response+
- request Post.new(path, initheader), data, &block
- end
-
- def request_put(path, data, initheader = nil, &block) #:nodoc:
- request Put.new(path, initheader), data, &block
- end
-
- alias get2 request_get #:nodoc: obsolete
- alias head2 request_head #:nodoc: obsolete
- alias post2 request_post #:nodoc: obsolete
- alias put2 request_put #:nodoc: obsolete
-
-
- # Sends an HTTP request to the HTTP server.
- # Also sends a DATA string if +data+ is given.
- #
- # Returns a Net::HTTPResponse object.
- #
- # This method never raises Net::* exceptions.
- #
- # response = http.send_request('GET', '/index.html')
- # puts response.body
- #
- def send_request(name, path, data = nil, header = nil)
- has_response_body = name != 'HEAD'
- r = HTTPGenericRequest.new(name,(data ? true : false),has_response_body,path,header)
- request r, data
- end
-
- # Sends an HTTPRequest object +req+ to the HTTP server.
- #
- # If +req+ is a Net::HTTP::Post or Net::HTTP::Put request containing
- # data, the data is also sent. Providing data for a Net::HTTP::Head or
- # Net::HTTP::Get request results in an ArgumentError.
- #
- # Returns an HTTPResponse object.
- #
- # When called with a block, passes an HTTPResponse object to the block.
- # The body of the response will not have been read yet;
- # the block can process it using HTTPResponse#read_body,
- # if desired.
- #
- # This method never raises Net::* exceptions.
- #
- def request(req, body = nil, &block) # :yield: +response+
- unless started?
- start {
- req['connection'] ||= 'close'
- return request(req, body, &block)
- }
- end
- if proxy_user()
- req.proxy_basic_auth proxy_user(), proxy_pass() unless use_ssl?
- end
- req.set_body_internal body
- res = transport_request(req, &block)
- if sspi_auth?(res)
- sspi_auth(req)
- res = transport_request(req, &block)
- end
- res
- end
-
- private
-
- # Executes a request which uses a representation
- # and returns its body.
- def send_entity(path, data, initheader, dest, type, &block)
- res = nil
- request(type.new(path, initheader), data) {|r|
- r.read_body dest, &block
- res = r
- }
- res
- end
-
- IDEMPOTENT_METHODS_ = %w/GET HEAD PUT DELETE OPTIONS TRACE/ # :nodoc:
-
- def transport_request(req)
- count = 0
- begin
- begin_transport req
- res = catch(:response) {
- req.exec @socket, @curr_http_version, edit_path(req.path)
- begin
- res = HTTPResponse.read_new(@socket)
- res.decode_content = req.decode_content
- end while res.kind_of?(HTTPInformation)
-
- res.uri = req.uri
-
- res
- }
- res.reading_body(@socket, req.response_body_permitted?) {
- yield res if block_given?
- }
- rescue Net::OpenTimeout
- raise
- rescue Net::ReadTimeout, IOError, EOFError,
- Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE,
- # avoid a dependency on OpenSSL
- defined?(OpenSSL::SSL) ? OpenSSL::SSL::SSLError : IOError,
- Timeout::Error => exception
- if count == 0 && IDEMPOTENT_METHODS_.include?(req.method)
- count += 1
- @socket.close if @socket and not @socket.closed?
- D "Conn close because of error #{exception}, and retry"
- retry
- end
- D "Conn close because of error #{exception}"
- @socket.close if @socket and not @socket.closed?
- raise
- end
-
- end_transport req, res
- res
- rescue => exception
- D "Conn close because of error #{exception}"
- @socket.close if @socket and not @socket.closed?
- raise exception
- end
-
- def begin_transport(req)
- if @socket.closed?
- connect
- elsif @last_communicated && @last_communicated + @keep_alive_timeout < Time.now
- D 'Conn close because of keep_alive_timeout'
- @socket.close
- connect
- end
-
- if not req.response_body_permitted? and @close_on_empty_response
- req['connection'] ||= 'close'
- end
-
- req.update_uri address, port, use_ssl?
- req['host'] ||= addr_port()
- end
-
- def end_transport(req, res)
- @curr_http_version = res.http_version
- @last_communicated = nil
- if @socket.closed?
- D 'Conn socket closed'
- elsif not res.body and @close_on_empty_response
- D 'Conn close'
- @socket.close
- elsif keep_alive?(req, res)
- D 'Conn keep-alive'
- @last_communicated = Time.now
- else
- D 'Conn close'
- @socket.close
- end
- end
-
- def keep_alive?(req, res)
- return false if req.connection_close?
- if @curr_http_version <= '1.0'
- res.connection_keep_alive?
- else # HTTP/1.1 or later
- not res.connection_close?
- end
- end
-
- def sspi_auth?(res)
- return false unless @sspi_enabled
- if res.kind_of?(HTTPProxyAuthenticationRequired) and
- proxy? and res["Proxy-Authenticate"].include?("Negotiate")
- begin
- require 'win32/sspi'
- true
- rescue LoadError
- false
- end
- else
- false
- end
- end
-
- def sspi_auth(req)
- n = Win32::SSPI::NegotiateAuth.new
- req["Proxy-Authorization"] = "Negotiate #{n.get_initial_token}"
- # Some versions of ISA will close the connection if this isn't present.
- req["Connection"] = "Keep-Alive"
- req["Proxy-Connection"] = "Keep-Alive"
- res = transport_request(req)
- authphrase = res["Proxy-Authenticate"] or return res
- req["Proxy-Authorization"] = "Negotiate #{n.complete_authentication(authphrase)}"
- rescue => err
- raise HTTPAuthenticationError.new('HTTP authentication failed', err)
- end
-
- #
- # utils
- #
-
- private
-
- def addr_port
- if use_ssl?
- address() + (port == HTTP.https_default_port ? '' : ":#{port()}")
- else
- address() + (port == HTTP.http_default_port ? '' : ":#{port()}")
- end
- end
-
- def D(msg)
- return unless @debug_output
- @debug_output << msg
- @debug_output << "\n"
- end
- end
-
-end
-
-require 'net/http/exceptions'
-
-require 'net/http/header'
-
-require 'net/http/generic_request'
-require 'net/http/request'
-require 'net/http/requests'
-
-require 'net/http/response'
-require 'net/http/responses'
-
-require 'net/http/proxy_delta'
-
-require 'net/http/backward'
-
diff --git a/ruby_2_2/lib/net/http/backward.rb b/ruby_2_2/lib/net/http/backward.rb
deleted file mode 100644
index faf47b8489..0000000000
--- a/ruby_2_2/lib/net/http/backward.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-# for backward compatibility
-
-# :enddoc:
-
-class Net::HTTP
- ProxyMod = ProxyDelta
-end
-
-module Net
- HTTPSession = Net::HTTP
-end
-
-module Net::NetPrivate
- HTTPRequest = ::Net::HTTPRequest
-end
-
-Net::HTTPInformationCode = Net::HTTPInformation
-Net::HTTPSuccessCode = Net::HTTPSuccess
-Net::HTTPRedirectionCode = Net::HTTPRedirection
-Net::HTTPRetriableCode = Net::HTTPRedirection
-Net::HTTPClientErrorCode = Net::HTTPClientError
-Net::HTTPFatalErrorCode = Net::HTTPClientError
-Net::HTTPServerErrorCode = Net::HTTPServerError
-Net::HTTPResponceReceiver = Net::HTTPResponse
-
diff --git a/ruby_2_2/lib/net/http/exceptions.rb b/ruby_2_2/lib/net/http/exceptions.rb
deleted file mode 100644
index 6c5d81cb04..0000000000
--- a/ruby_2_2/lib/net/http/exceptions.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-# Net::HTTP exception class.
-# You cannot use Net::HTTPExceptions directly; instead, you must use
-# its subclasses.
-module Net::HTTPExceptions
- def initialize(msg, res) #:nodoc:
- super msg
- @response = res
- end
- attr_reader :response
- alias data response #:nodoc: obsolete
-end
-class Net::HTTPError < Net::ProtocolError
- include Net::HTTPExceptions
-end
-class Net::HTTPRetriableError < Net::ProtoRetriableError
- include Net::HTTPExceptions
-end
-class Net::HTTPServerException < Net::ProtoServerError
- # We cannot use the name "HTTPServerError", it is the name of the response.
- include Net::HTTPExceptions
-end
-class Net::HTTPFatalError < Net::ProtoFatalError
- include Net::HTTPExceptions
-end
-
diff --git a/ruby_2_2/lib/net/http/generic_request.rb b/ruby_2_2/lib/net/http/generic_request.rb
deleted file mode 100644
index 959a3c6510..0000000000
--- a/ruby_2_2/lib/net/http/generic_request.rb
+++ /dev/null
@@ -1,337 +0,0 @@
-# HTTPGenericRequest is the parent of the HTTPRequest class.
-# Do not use this directly; use a subclass of HTTPRequest.
-#
-# Mixes in the HTTPHeader module to provide easier access to HTTP headers.
-#
-class Net::HTTPGenericRequest
-
- include Net::HTTPHeader
-
- def initialize(m, reqbody, resbody, uri_or_path, initheader = nil)
- @method = m
- @request_has_body = reqbody
- @response_has_body = resbody
-
- if URI === uri_or_path then
- @uri = uri_or_path.dup
- host = @uri.hostname.dup
- host << ":".freeze << @uri.port.to_s if @uri.port != @uri.default_port
- @path = uri_or_path.request_uri
- raise ArgumentError, "no HTTP request path given" unless @path
- else
- @uri = nil
- host = nil
- raise ArgumentError, "no HTTP request path given" unless uri_or_path
- raise ArgumentError, "HTTP request path is empty" if uri_or_path.empty?
- @path = uri_or_path.dup
- end
-
- @decode_content = false
-
- if @response_has_body and Net::HTTP::HAVE_ZLIB then
- if !initheader ||
- !initheader.keys.any? { |k|
- %w[accept-encoding range].include? k.downcase
- } then
- @decode_content = true
- initheader = initheader ? initheader.dup : {}
- initheader["accept-encoding"] =
- "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
- end
- end
-
- initialize_http_header initheader
- self['Accept'] ||= '*/*'
- self['User-Agent'] ||= 'Ruby'
- self['Host'] ||= host if host
- @body = nil
- @body_stream = nil
- @body_data = nil
- end
-
- attr_reader :method
- attr_reader :path
- attr_reader :uri
-
- # Automatically set to false if the user sets the Accept-Encoding header.
- # This indicates they wish to handle Content-encoding in responses
- # themselves.
- attr_reader :decode_content
-
- def inspect
- "\#<#{self.class} #{@method}>"
- end
-
- ##
- # Don't automatically decode response content-encoding if the user indicates
- # they want to handle it.
-
- def []=(key, val) # :nodoc:
- @decode_content = false if key.downcase == 'accept-encoding'
-
- super key, val
- end
-
- def request_body_permitted?
- @request_has_body
- end
-
- def response_body_permitted?
- @response_has_body
- end
-
- def body_exist?
- warn "Net::HTTPRequest#body_exist? is obsolete; use response_body_permitted?" if $VERBOSE
- response_body_permitted?
- end
-
- attr_reader :body
-
- def body=(str)
- @body = str
- @body_stream = nil
- @body_data = nil
- str
- end
-
- attr_reader :body_stream
-
- def body_stream=(input)
- @body = nil
- @body_stream = input
- @body_data = nil
- input
- end
-
- def set_body_internal(str) #:nodoc: internal use only
- raise ArgumentError, "both of body argument and HTTPRequest#body set" if str and (@body or @body_stream)
- self.body = str if str
- if @body.nil? && @body_stream.nil? && @body_data.nil? && request_body_permitted?
- self.body = ''
- end
- end
-
- #
- # write
- #
-
- def exec(sock, ver, path) #:nodoc: internal use only
- if @body
- send_request_with_body sock, ver, path, @body
- elsif @body_stream
- send_request_with_body_stream sock, ver, path, @body_stream
- elsif @body_data
- send_request_with_body_data sock, ver, path, @body_data
- else
- write_header sock, ver, path
- end
- end
-
- def update_uri(addr, port, ssl) # :nodoc: internal use only
- # reflect the connection and @path to @uri
- return unless @uri
-
- if ssl
- scheme = 'https'.freeze
- klass = URI::HTTPS
- else
- scheme = 'http'.freeze
- klass = URI::HTTP
- end
-
- if host = self['host']
- host.sub!(/:.*/s, ''.freeze)
- elsif host = @uri.host
- else
- host = addr
- end
- # convert the class of the URI
- if @uri.is_a?(klass)
- @uri.host = host
- @uri.port = port
- else
- @uri = klass.new(
- scheme, @uri.userinfo,
- host, port, nil,
- @uri.path, nil, @uri.query, nil)
- end
- end
-
- private
-
- class Chunker #:nodoc:
- def initialize(sock)
- @sock = sock
- @prev = nil
- end
-
- def write(buf)
- # avoid memcpy() of buf, buf can huge and eat memory bandwidth
- @sock.write("#{buf.bytesize.to_s(16)}\r\n")
- rv = @sock.write(buf)
- @sock.write("\r\n")
- rv
- end
-
- def finish
- @sock.write("0\r\n\r\n")
- end
- end
-
- def send_request_with_body(sock, ver, path, body)
- self.content_length = body.bytesize
- delete 'Transfer-Encoding'
- supply_default_content_type
- write_header sock, ver, path
- wait_for_continue sock, ver if sock.continue_timeout
- sock.write body
- end
-
- def send_request_with_body_stream(sock, ver, path, f)
- unless content_length() or chunked?
- raise ArgumentError,
- "Content-Length not given and Transfer-Encoding is not `chunked'"
- end
- supply_default_content_type
- write_header sock, ver, path
- wait_for_continue sock, ver if sock.continue_timeout
- if chunked?
- chunker = Chunker.new(sock)
- IO.copy_stream(f, chunker)
- chunker.finish
- else
- # copy_stream can sendfile() to sock.io unless we use SSL.
- # If sock.io is an SSLSocket, copy_stream will hit SSL_write()
- IO.copy_stream(f, sock.io)
- end
- end
-
- def send_request_with_body_data(sock, ver, path, params)
- if /\Amultipart\/form-data\z/i !~ self.content_type
- self.content_type = 'application/x-www-form-urlencoded'
- return send_request_with_body(sock, ver, path, URI.encode_www_form(params))
- end
-
- opt = @form_option.dup
- require 'securerandom' unless defined?(SecureRandom)
- opt[:boundary] ||= SecureRandom.urlsafe_base64(40)
- self.set_content_type(self.content_type, boundary: opt[:boundary])
- if chunked?
- write_header sock, ver, path
- encode_multipart_form_data(sock, params, opt)
- else
- require 'tempfile'
- file = Tempfile.new('multipart')
- file.binmode
- encode_multipart_form_data(file, params, opt)
- file.rewind
- self.content_length = file.size
- write_header sock, ver, path
- IO.copy_stream(file, sock)
- file.close(true)
- end
- end
-
- def encode_multipart_form_data(out, params, opt)
- charset = opt[:charset]
- boundary = opt[:boundary]
- require 'securerandom' unless defined?(SecureRandom)
- boundary ||= SecureRandom.urlsafe_base64(40)
- chunked_p = chunked?
-
- buf = ''
- params.each do |key, value, h={}|
- key = quote_string(key, charset)
- filename =
- h.key?(:filename) ? h[:filename] :
- value.respond_to?(:to_path) ? File.basename(value.to_path) :
- nil
-
- buf << "--#{boundary}\r\n"
- if filename
- filename = quote_string(filename, charset)
- type = h[:content_type] || 'application/octet-stream'
- buf << "Content-Disposition: form-data; " \
- "name=\"#{key}\"; filename=\"#{filename}\"\r\n" \
- "Content-Type: #{type}\r\n\r\n"
- if !out.respond_to?(:write) || !value.respond_to?(:read)
- # if +out+ is not an IO or +value+ is not an IO
- buf << (value.respond_to?(:read) ? value.read : value)
- elsif value.respond_to?(:size) && chunked_p
- # if +out+ is an IO and +value+ is a File, use IO.copy_stream
- flush_buffer(out, buf, chunked_p)
- out << "%x\r\n" % value.size if chunked_p
- IO.copy_stream(value, out)
- out << "\r\n" if chunked_p
- else
- # +out+ is an IO, and +value+ is not a File but an IO
- flush_buffer(out, buf, chunked_p)
- 1 while flush_buffer(out, value.read(4096), chunked_p)
- end
- else
- # non-file field:
- # HTML5 says, "The parts of the generated multipart/form-data
- # resource that correspond to non-file fields must not have a
- # Content-Type header specified."
- buf << "Content-Disposition: form-data; name=\"#{key}\"\r\n\r\n"
- buf << (value.respond_to?(:read) ? value.read : value)
- end
- buf << "\r\n"
- end
- buf << "--#{boundary}--\r\n"
- flush_buffer(out, buf, chunked_p)
- out << "0\r\n\r\n" if chunked_p
- end
-
- def quote_string(str, charset)
- str = str.encode(charset, fallback:->(c){'&#%d;'%c.encode("UTF-8").ord}) if charset
- str.gsub(/[\\"]/, '\\\\\&')
- end
-
- def flush_buffer(out, buf, chunked_p)
- return unless buf
- out << "%x\r\n"%buf.bytesize if chunked_p
- out << buf
- out << "\r\n" if chunked_p
- buf.clear
- end
-
- def supply_default_content_type
- return if content_type()
- warn 'net/http: warning: Content-Type did not set; using application/x-www-form-urlencoded' if $VERBOSE
- set_content_type 'application/x-www-form-urlencoded'
- end
-
- ##
- # Waits up to the continue timeout for a response from the server provided
- # we're speaking HTTP 1.1 and are expecting a 100-continue response.
-
- def wait_for_continue(sock, ver)
- if ver >= '1.1' and @header['expect'] and
- @header['expect'].include?('100-continue')
- if IO.select([sock.io], nil, nil, sock.continue_timeout)
- res = Net::HTTPResponse.read_new(sock)
- unless res.kind_of?(Net::HTTPContinue)
- res.decode_content = @decode_content
- throw :response, res
- end
- end
- end
- end
-
- def write_header(sock, ver, path)
- reqline = "#{@method} #{path} HTTP/#{ver}"
- if /[\r\n]/ =~ reqline
- raise ArgumentError, "A Request-Line must not contain CR or LF"
- end
- buf = ""
- buf << reqline << "\r\n"
- each_capitalized do |k,v|
- buf << "#{k}: #{v}\r\n"
- end
- buf << "\r\n"
- sock.write buf
- end
-
-end
-
diff --git a/ruby_2_2/lib/net/http/header.rb b/ruby_2_2/lib/net/http/header.rb
deleted file mode 100644
index 912419df55..0000000000
--- a/ruby_2_2/lib/net/http/header.rb
+++ /dev/null
@@ -1,452 +0,0 @@
-# The HTTPHeader module defines methods for reading and writing
-# HTTP headers.
-#
-# It is used as a mixin by other classes, to provide hash-like
-# access to HTTP header values. Unlike raw hash access, HTTPHeader
-# provides access via case-insensitive keys. It also provides
-# methods for accessing commonly-used HTTP header values in more
-# convenient formats.
-#
-module Net::HTTPHeader
-
- def initialize_http_header(initheader)
- @header = {}
- return unless initheader
- initheader.each do |key, value|
- warn "net/http: warning: duplicated HTTP header: #{key}" if key?(key) and $VERBOSE
- @header[key.downcase] = [value.strip]
- end
- end
-
- def size #:nodoc: obsolete
- @header.size
- end
-
- alias length size #:nodoc: obsolete
-
- # Returns the header field corresponding to the case-insensitive key.
- # For example, a key of "Content-Type" might return "text/html"
- def [](key)
- a = @header[key.downcase] or return nil
- a.join(', ')
- end
-
- # Sets the header field corresponding to the case-insensitive key.
- def []=(key, val)
- unless val
- @header.delete key.downcase
- return val
- end
- @header[key.downcase] = [val]
- end
-
- # [Ruby 1.8.3]
- # Adds a value to a named header field, instead of replacing its value.
- # Second argument +val+ must be a String.
- # See also #[]=, #[] and #get_fields.
- #
- # request.add_field 'X-My-Header', 'a'
- # p request['X-My-Header'] #=> "a"
- # p request.get_fields('X-My-Header') #=> ["a"]
- # request.add_field 'X-My-Header', 'b'
- # p request['X-My-Header'] #=> "a, b"
- # p request.get_fields('X-My-Header') #=> ["a", "b"]
- # request.add_field 'X-My-Header', 'c'
- # p request['X-My-Header'] #=> "a, b, c"
- # p request.get_fields('X-My-Header') #=> ["a", "b", "c"]
- #
- def add_field(key, val)
- if @header.key?(key.downcase)
- @header[key.downcase].push val
- else
- @header[key.downcase] = [val]
- end
- end
-
- # [Ruby 1.8.3]
- # Returns an array of header field strings corresponding to the
- # case-insensitive +key+. This method allows you to get duplicated
- # header fields without any processing. See also #[].
- #
- # p response.get_fields('Set-Cookie')
- # #=> ["session=al98axx; expires=Fri, 31-Dec-1999 23:58:23",
- # "query=rubyscript; expires=Fri, 31-Dec-1999 23:58:23"]
- # p response['Set-Cookie']
- # #=> "session=al98axx; expires=Fri, 31-Dec-1999 23:58:23, query=rubyscript; expires=Fri, 31-Dec-1999 23:58:23"
- #
- def get_fields(key)
- return nil unless @header[key.downcase]
- @header[key.downcase].dup
- end
-
- # Returns the header field corresponding to the case-insensitive key.
- # Returns the default value +args+, or the result of the block, or
- # raises an IndexError if there's no header field named +key+
- # See Hash#fetch
- def fetch(key, *args, &block) #:yield: +key+
- a = @header.fetch(key.downcase, *args, &block)
- a.kind_of?(Array) ? a.join(', ') : a
- end
-
- # Iterates through the header names and values, passing in the name
- # and value to the code block supplied.
- #
- # Example:
- #
- # response.header.each_header {|key,value| puts "#{key} = #{value}" }
- #
- def each_header #:yield: +key+, +value+
- block_given? or return enum_for(__method__)
- @header.each do |k,va|
- yield k, va.join(', ')
- end
- end
-
- alias each each_header
-
- # Iterates through the header names in the header, passing
- # each header name to the code block.
- def each_name(&block) #:yield: +key+
- block_given? or return enum_for(__method__)
- @header.each_key(&block)
- end
-
- alias each_key each_name
-
- # Iterates through the header names in the header, passing
- # capitalized header names to the code block.
- #
- # Note that header names are capitalized systematically;
- # capitalization may not match that used by the remote HTTP
- # server in its response.
- def each_capitalized_name #:yield: +key+
- block_given? or return enum_for(__method__)
- @header.each_key do |k|
- yield capitalize(k)
- end
- end
-
- # Iterates through header values, passing each value to the
- # code block.
- def each_value #:yield: +value+
- block_given? or return enum_for(__method__)
- @header.each_value do |va|
- yield va.join(', ')
- end
- end
-
- # Removes a header field, specified by case-insensitive key.
- def delete(key)
- @header.delete(key.downcase)
- end
-
- # true if +key+ header exists.
- def key?(key)
- @header.key?(key.downcase)
- end
-
- # Returns a Hash consisting of header names and array of values.
- # e.g.
- # {"cache-control" => ["private"],
- # "content-type" => ["text/html"],
- # "date" => ["Wed, 22 Jun 2005 22:11:50 GMT"]}
- def to_hash
- @header.dup
- end
-
- # As for #each_header, except the keys are provided in capitalized form.
- #
- # Note that header names are capitalized systematically;
- # capitalization may not match that used by the remote HTTP
- # server in its response.
- def each_capitalized
- block_given? or return enum_for(__method__)
- @header.each do |k,v|
- yield capitalize(k), v.join(', ')
- end
- end
-
- alias canonical_each each_capitalized
-
- def capitalize(name)
- name.split(/-/).map {|s| s.capitalize }.join('-')
- end
- private :capitalize
-
- # Returns an Array of Range objects which represent the Range:
- # HTTP header field, or +nil+ if there is no such header.
- def range
- return nil unless @header['range']
-
- value = self['Range']
- # byte-range-set = *( "," OWS ) ( byte-range-spec / suffix-byte-range-spec )
- # *( OWS "," [ OWS ( byte-range-spec / suffix-byte-range-spec ) ] )
- # corrected collected ABNF
- # http://tools.ietf.org/html/draft-ietf-httpbis-p5-range-19#section-5.4.1
- # http://tools.ietf.org/html/draft-ietf-httpbis-p5-range-19#appendix-C
- # http://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-19#section-3.2.5
- unless /\Abytes=((?:,[ \t]*)*(?:\d+-\d*|-\d+)(?:[ \t]*,(?:[ \t]*\d+-\d*|-\d+)?)*)\z/ =~ value
- raise Net::HTTPHeaderSyntaxError, "invalid syntax for byte-ranges-specifier: '#{value}'"
- end
-
- byte_range_set = $1
- result = byte_range_set.split(/,/).map {|spec|
- m = /(\d+)?\s*-\s*(\d+)?/i.match(spec) or
- raise Net::HTTPHeaderSyntaxError, "invalid byte-range-spec: '#{spec}'"
- d1 = m[1].to_i
- d2 = m[2].to_i
- if m[1] and m[2]
- if d1 > d2
- raise Net::HTTPHeaderSyntaxError, "last-byte-pos MUST greater than or equal to first-byte-pos but '#{spec}'"
- end
- d1..d2
- elsif m[1]
- d1..-1
- elsif m[2]
- -d2..-1
- else
- raise Net::HTTPHeaderSyntaxError, 'range is not specified'
- end
- }
- # if result.empty?
- # byte-range-set must include at least one byte-range-spec or suffix-byte-range-spec
- # but above regexp already denies it.
- if result.size == 1 && result[0].begin == 0 && result[0].end == -1
- raise Net::HTTPHeaderSyntaxError, 'only one suffix-byte-range-spec with zero suffix-length'
- end
- result
- end
-
- # Sets the HTTP Range: header.
- # Accepts either a Range object as a single argument,
- # or a beginning index and a length from that index.
- # Example:
- #
- # req.range = (0..1023)
- # req.set_range 0, 1023
- #
- def set_range(r, e = nil)
- unless r
- @header.delete 'range'
- return r
- end
- r = (r...r+e) if e
- case r
- when Numeric
- n = r.to_i
- rangestr = (n > 0 ? "0-#{n-1}" : "-#{-n}")
- when Range
- first = r.first
- last = r.end
- last -= 1 if r.exclude_end?
- if last == -1
- rangestr = (first > 0 ? "#{first}-" : "-#{-first}")
- else
- raise Net::HTTPHeaderSyntaxError, 'range.first is negative' if first < 0
- raise Net::HTTPHeaderSyntaxError, 'range.last is negative' if last < 0
- raise Net::HTTPHeaderSyntaxError, 'must be .first < .last' if first > last
- rangestr = "#{first}-#{last}"
- end
- else
- raise TypeError, 'Range/Integer is required'
- end
- @header['range'] = ["bytes=#{rangestr}"]
- r
- end
-
- alias range= set_range
-
- # Returns an Integer object which represents the HTTP Content-Length:
- # header field, or +nil+ if that field was not provided.
- def content_length
- return nil unless key?('Content-Length')
- len = self['Content-Length'].slice(/\d+/) or
- raise Net::HTTPHeaderSyntaxError, 'wrong Content-Length format'
- len.to_i
- end
-
- def content_length=(len)
- unless len
- @header.delete 'content-length'
- return nil
- end
- @header['content-length'] = [len.to_i.to_s]
- end
-
- # Returns "true" if the "transfer-encoding" header is present and
- # set to "chunked". This is an HTTP/1.1 feature, allowing the
- # the content to be sent in "chunks" without at the outset
- # stating the entire content length.
- def chunked?
- return false unless @header['transfer-encoding']
- field = self['Transfer-Encoding']
- (/(?:\A|[^\-\w])chunked(?![\-\w])/i =~ field) ? true : false
- end
-
- # Returns a Range object which represents the value of the Content-Range:
- # header field.
- # For a partial entity body, this indicates where this fragment
- # fits inside the full entity body, as range of byte offsets.
- def content_range
- return nil unless @header['content-range']
- m = %r<bytes\s+(\d+)-(\d+)/(\d+|\*)>i.match(self['Content-Range']) or
- raise Net::HTTPHeaderSyntaxError, 'wrong Content-Range format'
- m[1].to_i .. m[2].to_i
- end
-
- # The length of the range represented in Content-Range: header.
- def range_length
- r = content_range() or return nil
- r.end - r.begin + 1
- end
-
- # Returns a content type string such as "text/html".
- # This method returns nil if Content-Type: header field does not exist.
- def content_type
- return nil unless main_type()
- if sub_type()
- then "#{main_type()}/#{sub_type()}"
- else main_type()
- end
- end
-
- # Returns a content type string such as "text".
- # This method returns nil if Content-Type: header field does not exist.
- def main_type
- return nil unless @header['content-type']
- self['Content-Type'].split(';').first.to_s.split('/')[0].to_s.strip
- end
-
- # Returns a content type string such as "html".
- # This method returns nil if Content-Type: header field does not exist
- # or sub-type is not given (e.g. "Content-Type: text").
- def sub_type
- return nil unless @header['content-type']
- _, sub = *self['Content-Type'].split(';').first.to_s.split('/')
- return nil unless sub
- sub.strip
- end
-
- # Any parameters specified for the content type, returned as a Hash.
- # For example, a header of Content-Type: text/html; charset=EUC-JP
- # would result in type_params returning {'charset' => 'EUC-JP'}
- def type_params
- result = {}
- list = self['Content-Type'].to_s.split(';')
- list.shift
- list.each do |param|
- k, v = *param.split('=', 2)
- result[k.strip] = v.strip
- end
- result
- end
-
- # Sets the content type in an HTTP header.
- # The +type+ should be a full HTTP content type, e.g. "text/html".
- # The +params+ are an optional Hash of parameters to add after the
- # content type, e.g. {'charset' => 'iso-8859-1'}
- def set_content_type(type, params = {})
- @header['content-type'] = [type + params.map{|k,v|"; #{k}=#{v}"}.join('')]
- end
-
- alias content_type= set_content_type
-
- # Set header fields and a body from HTML form data.
- # +params+ should be an Array of Arrays or
- # a Hash containing HTML form data.
- # Optional argument +sep+ means data record separator.
- #
- # Values are URL encoded as necessary and the content-type is set to
- # application/x-www-form-urlencoded
- #
- # Example:
- # http.form_data = {"q" => "ruby", "lang" => "en"}
- # http.form_data = {"q" => ["ruby", "perl"], "lang" => "en"}
- # http.set_form_data({"q" => "ruby", "lang" => "en"}, ';')
- #
- def set_form_data(params, sep = '&')
- query = URI.encode_www_form(params)
- query.gsub!(/&/, sep) if sep != '&'
- self.body = query
- self.content_type = 'application/x-www-form-urlencoded'
- end
-
- alias form_data= set_form_data
-
- # Set a HTML form data set.
- # +params+ is the form data set; it is an Array of Arrays or a Hash
- # +enctype is the type to encode the form data set.
- # It is application/x-www-form-urlencoded or multipart/form-data.
- # +formpot+ is an optional hash to specify the detail.
- #
- # boundary:: the boundary of the multipart message
- # charset:: the charset of the message. All names and the values of
- # non-file fields are encoded as the charset.
- #
- # Each item of params is an array and contains following items:
- # +name+:: the name of the field
- # +value+:: the value of the field, it should be a String or a File
- # +opt+:: an optional hash to specify additional information
- #
- # Each item is a file field or a normal field.
- # If +value+ is a File object or the +opt+ have a filename key,
- # the item is treated as a file field.
- #
- # If Transfer-Encoding is set as chunked, this send the request in
- # chunked encoding. Because chunked encoding is HTTP/1.1 feature,
- # you must confirm the server to support HTTP/1.1 before sending it.
- #
- # Example:
- # http.set_form([["q", "ruby"], ["lang", "en"]])
- #
- # See also RFC 2388, RFC 2616, HTML 4.01, and HTML5
- #
- def set_form(params, enctype='application/x-www-form-urlencoded', formopt={})
- @body_data = params
- @body = nil
- @body_stream = nil
- @form_option = formopt
- case enctype
- when /\Aapplication\/x-www-form-urlencoded\z/i,
- /\Amultipart\/form-data\z/i
- self.content_type = enctype
- else
- raise ArgumentError, "invalid enctype: #{enctype}"
- end
- end
-
- # Set the Authorization: header for "Basic" authorization.
- def basic_auth(account, password)
- @header['authorization'] = [basic_encode(account, password)]
- end
-
- # Set Proxy-Authorization: header for "Basic" authorization.
- def proxy_basic_auth(account, password)
- @header['proxy-authorization'] = [basic_encode(account, password)]
- end
-
- def basic_encode(account, password)
- 'Basic ' + ["#{account}:#{password}"].pack('m').delete("\r\n")
- end
- private :basic_encode
-
- def connection_close?
- tokens(@header['connection']).include?('close') or
- tokens(@header['proxy-connection']).include?('close')
- end
-
- def connection_keep_alive?
- tokens(@header['connection']).include?('keep-alive') or
- tokens(@header['proxy-connection']).include?('keep-alive')
- end
-
- def tokens(vals)
- return [] unless vals
- vals.map {|v| v.split(',') }.flatten\
- .reject {|str| str.strip.empty? }\
- .map {|tok| tok.strip.downcase }
- end
- private :tokens
-
-end
-
diff --git a/ruby_2_2/lib/net/http/proxy_delta.rb b/ruby_2_2/lib/net/http/proxy_delta.rb
deleted file mode 100644
index b16c9f1ed8..0000000000
--- a/ruby_2_2/lib/net/http/proxy_delta.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-module Net::HTTP::ProxyDelta #:nodoc: internal use only
- private
-
- def conn_address
- proxy_address()
- end
-
- def conn_port
- proxy_port()
- end
-
- def edit_path(path)
- use_ssl? ? path : "http://#{addr_port()}#{path}"
- end
-end
-
diff --git a/ruby_2_2/lib/net/http/request.rb b/ruby_2_2/lib/net/http/request.rb
deleted file mode 100644
index e8b0f48fcc..0000000000
--- a/ruby_2_2/lib/net/http/request.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# HTTP request class.
-# This class wraps together the request header and the request path.
-# You cannot use this class directly. Instead, you should use one of its
-# subclasses: Net::HTTP::Get, Net::HTTP::Post, Net::HTTP::Head.
-#
-class Net::HTTPRequest < Net::HTTPGenericRequest
- # Creates an HTTP request object for +path+.
- #
- # +initheader+ are the default headers to use. Net::HTTP adds
- # Accept-Encoding to enable compression of the response body unless
- # Accept-Encoding or Range are supplied in +initheader+.
-
- def initialize(path, initheader = nil)
- super self.class::METHOD,
- self.class::REQUEST_HAS_BODY,
- self.class::RESPONSE_HAS_BODY,
- path, initheader
- end
-end
-
diff --git a/ruby_2_2/lib/net/http/requests.rb b/ruby_2_2/lib/net/http/requests.rb
deleted file mode 100644
index c1f8360479..0000000000
--- a/ruby_2_2/lib/net/http/requests.rb
+++ /dev/null
@@ -1,122 +0,0 @@
-#
-# HTTP/1.1 methods --- RFC2616
-#
-
-# See Net::HTTPGenericRequest for attributes and methods.
-# See Net::HTTP for usage examples.
-class Net::HTTP::Get < Net::HTTPRequest
- METHOD = 'GET'
- REQUEST_HAS_BODY = false
- RESPONSE_HAS_BODY = true
-end
-
-# See Net::HTTPGenericRequest for attributes and methods.
-# See Net::HTTP for usage examples.
-class Net::HTTP::Head < Net::HTTPRequest
- METHOD = 'HEAD'
- REQUEST_HAS_BODY = false
- RESPONSE_HAS_BODY = false
-end
-
-# See Net::HTTPGenericRequest for attributes and methods.
-# See Net::HTTP for usage examples.
-class Net::HTTP::Post < Net::HTTPRequest
- METHOD = 'POST'
- REQUEST_HAS_BODY = true
- RESPONSE_HAS_BODY = true
-end
-
-# See Net::HTTPGenericRequest for attributes and methods.
-# See Net::HTTP for usage examples.
-class Net::HTTP::Put < Net::HTTPRequest
- METHOD = 'PUT'
- REQUEST_HAS_BODY = true
- RESPONSE_HAS_BODY = true
-end
-
-# See Net::HTTPGenericRequest for attributes and methods.
-# See Net::HTTP for usage examples.
-class Net::HTTP::Delete < Net::HTTPRequest
- METHOD = 'DELETE'
- REQUEST_HAS_BODY = false
- RESPONSE_HAS_BODY = true
-end
-
-# See Net::HTTPGenericRequest for attributes and methods.
-class Net::HTTP::Options < Net::HTTPRequest
- METHOD = 'OPTIONS'
- REQUEST_HAS_BODY = false
- RESPONSE_HAS_BODY = true
-end
-
-# See Net::HTTPGenericRequest for attributes and methods.
-class Net::HTTP::Trace < Net::HTTPRequest
- METHOD = 'TRACE'
- REQUEST_HAS_BODY = false
- RESPONSE_HAS_BODY = true
-end
-
-#
-# PATCH method --- RFC5789
-#
-
-# See Net::HTTPGenericRequest for attributes and methods.
-class Net::HTTP::Patch < Net::HTTPRequest
- METHOD = 'PATCH'
- REQUEST_HAS_BODY = true
- RESPONSE_HAS_BODY = true
-end
-
-#
-# WebDAV methods --- RFC2518
-#
-
-# See Net::HTTPGenericRequest for attributes and methods.
-class Net::HTTP::Propfind < Net::HTTPRequest
- METHOD = 'PROPFIND'
- REQUEST_HAS_BODY = true
- RESPONSE_HAS_BODY = true
-end
-
-# See Net::HTTPGenericRequest for attributes and methods.
-class Net::HTTP::Proppatch < Net::HTTPRequest
- METHOD = 'PROPPATCH'
- REQUEST_HAS_BODY = true
- RESPONSE_HAS_BODY = true
-end
-
-# See Net::HTTPGenericRequest for attributes and methods.
-class Net::HTTP::Mkcol < Net::HTTPRequest
- METHOD = 'MKCOL'
- REQUEST_HAS_BODY = true
- RESPONSE_HAS_BODY = true
-end
-
-# See Net::HTTPGenericRequest for attributes and methods.
-class Net::HTTP::Copy < Net::HTTPRequest
- METHOD = 'COPY'
- REQUEST_HAS_BODY = false
- RESPONSE_HAS_BODY = true
-end
-
-# See Net::HTTPGenericRequest for attributes and methods.
-class Net::HTTP::Move < Net::HTTPRequest
- METHOD = 'MOVE'
- REQUEST_HAS_BODY = false
- RESPONSE_HAS_BODY = true
-end
-
-# See Net::HTTPGenericRequest for attributes and methods.
-class Net::HTTP::Lock < Net::HTTPRequest
- METHOD = 'LOCK'
- REQUEST_HAS_BODY = true
- RESPONSE_HAS_BODY = true
-end
-
-# See Net::HTTPGenericRequest for attributes and methods.
-class Net::HTTP::Unlock < Net::HTTPRequest
- METHOD = 'UNLOCK'
- REQUEST_HAS_BODY = true
- RESPONSE_HAS_BODY = true
-end
-
diff --git a/ruby_2_2/lib/net/http/response.rb b/ruby_2_2/lib/net/http/response.rb
deleted file mode 100644
index 126c22160d..0000000000
--- a/ruby_2_2/lib/net/http/response.rb
+++ /dev/null
@@ -1,416 +0,0 @@
-# HTTP response class.
-#
-# This class wraps together the response header and the response body (the
-# entity requested).
-#
-# It mixes in the HTTPHeader module, which provides access to response
-# header values both via hash-like methods and via individual readers.
-#
-# Note that each possible HTTP response code defines its own
-# HTTPResponse subclass. These are listed below.
-#
-# All classes are defined under the Net module. Indentation indicates
-# inheritance. For a list of the classes see Net::HTTP.
-#
-#
-class Net::HTTPResponse
- class << self
- # true if the response has a body.
- def body_permitted?
- self::HAS_BODY
- end
-
- def exception_type # :nodoc: internal use only
- self::EXCEPTION_TYPE
- end
-
- def read_new(sock) #:nodoc: internal use only
- httpv, code, msg = read_status_line(sock)
- res = response_class(code).new(httpv, code, msg)
- each_response_header(sock) do |k,v|
- res.add_field k, v
- end
- res
- end
-
- private
-
- def read_status_line(sock)
- str = sock.readline
- m = /\AHTTP(?:\/(\d+\.\d+))?\s+(\d\d\d)(?:\s+(.*))?\z/in.match(str) or
- raise Net::HTTPBadResponse, "wrong status line: #{str.dump}"
- m.captures
- end
-
- def response_class(code)
- CODE_TO_OBJ[code] or
- CODE_CLASS_TO_OBJ[code[0,1]] or
- Net::HTTPUnknownResponse
- end
-
- def each_response_header(sock)
- key = value = nil
- while true
- line = sock.readuntil("\n", true).sub(/\s+\z/, '')
- break if line.empty?
- if line[0] == ?\s or line[0] == ?\t and value
- value << ' ' unless value.empty?
- value << line.strip
- else
- yield key, value if key
- key, value = line.strip.split(/\s*:\s*/, 2)
- raise Net::HTTPBadResponse, 'wrong header line format' if value.nil?
- end
- end
- yield key, value if key
- end
- end
-
- # next is to fix bug in RDoc, where the private inside class << self
- # spills out.
- public
-
- include Net::HTTPHeader
-
- def initialize(httpv, code, msg) #:nodoc: internal use only
- @http_version = httpv
- @code = code
- @message = msg
- initialize_http_header nil
- @body = nil
- @read = false
- @uri = nil
- @decode_content = false
- end
-
- # The HTTP version supported by the server.
- attr_reader :http_version
-
- # The HTTP result code string. For example, '302'. You can also
- # determine the response type by examining which response subclass
- # the response object is an instance of.
- attr_reader :code
-
- # The HTTP result message sent by the server. For example, 'Not Found'.
- attr_reader :message
- alias msg message # :nodoc: obsolete
-
- # The URI used to fetch this response. The response URI is only available
- # if a URI was used to create the request.
- attr_reader :uri
-
- # Set to true automatically when the request did not contain an
- # Accept-Encoding header from the user.
- attr_accessor :decode_content
-
- def inspect
- "#<#{self.class} #{@code} #{@message} readbody=#{@read}>"
- end
-
- #
- # response <-> exception relationship
- #
-
- def code_type #:nodoc:
- self.class
- end
-
- def error! #:nodoc:
- raise error_type().new(@code + ' ' + @message.dump, self)
- end
-
- def error_type #:nodoc:
- self.class::EXCEPTION_TYPE
- end
-
- # Raises an HTTP error if the response is not 2xx (success).
- def value
- error! unless self.kind_of?(Net::HTTPSuccess)
- end
-
- def uri= uri # :nodoc:
- @uri = uri.dup if uri
- end
-
- #
- # header (for backward compatibility only; DO NOT USE)
- #
-
- def response #:nodoc:
- warn "#{caller(1)[0]}: warning: Net::HTTPResponse#response is obsolete" if $VERBOSE
- self
- end
-
- def header #:nodoc:
- warn "#{caller(1)[0]}: warning: Net::HTTPResponse#header is obsolete" if $VERBOSE
- self
- end
-
- def read_header #:nodoc:
- warn "#{caller(1)[0]}: warning: Net::HTTPResponse#read_header is obsolete" if $VERBOSE
- self
- end
-
- #
- # body
- #
-
- def reading_body(sock, reqmethodallowbody) #:nodoc: internal use only
- @socket = sock
- @body_exist = reqmethodallowbody && self.class.body_permitted?
- begin
- yield
- self.body # ensure to read body
- ensure
- @socket = nil
- end
- end
-
- # Gets the entity body returned by the remote HTTP server.
- #
- # If a block is given, the body is passed to the block, and
- # the body is provided in fragments, as it is read in from the socket.
- #
- # Calling this method a second or subsequent time for the same
- # HTTPResponse object will return the value already read.
- #
- # http.request_get('/index.html') {|res|
- # puts res.read_body
- # }
- #
- # http.request_get('/index.html') {|res|
- # p res.read_body.object_id # 538149362
- # p res.read_body.object_id # 538149362
- # }
- #
- # # using iterator
- # http.request_get('/index.html') {|res|
- # res.read_body do |segment|
- # print segment
- # end
- # }
- #
- def read_body(dest = nil, &block)
- if @read
- raise IOError, "#{self.class}\#read_body called twice" if dest or block
- return @body
- end
- to = procdest(dest, block)
- stream_check
- if @body_exist
- read_body_0 to
- @body = to
- else
- @body = nil
- end
- @read = true
-
- @body
- end
-
- # Returns the full entity body.
- #
- # Calling this method a second or subsequent time will return the
- # string already read.
- #
- # http.request_get('/index.html') {|res|
- # puts res.body
- # }
- #
- # http.request_get('/index.html') {|res|
- # p res.body.object_id # 538149362
- # p res.body.object_id # 538149362
- # }
- #
- def body
- read_body()
- end
-
- # Because it may be necessary to modify the body, Eg, decompression
- # this method facilitates that.
- def body=(value)
- @body = value
- end
-
- alias entity body #:nodoc: obsolete
-
- private
-
- ##
- # Checks for a supported Content-Encoding header and yields an Inflate
- # wrapper for this response's socket when zlib is present. If the
- # Content-Encoding is unsupported or zlib is missing the plain socket is
- # yielded.
- #
- # If a Content-Range header is present a plain socket is yielded as the
- # bytes in the range may not be a complete deflate block.
-
- def inflater # :nodoc:
- return yield @socket unless Net::HTTP::HAVE_ZLIB
- return yield @socket unless @decode_content
- return yield @socket if self['content-range']
-
- v = self['content-encoding']
- case v && v.downcase
- when 'deflate', 'gzip', 'x-gzip' then
- self.delete 'content-encoding'
-
- inflate_body_io = Inflater.new(@socket)
-
- begin
- yield inflate_body_io
- ensure
- orig_err = $!
- begin
- inflate_body_io.finish
- rescue => err
- raise orig_err || err
- end
- end
- when 'none', 'identity' then
- self.delete 'content-encoding'
-
- yield @socket
- else
- yield @socket
- end
- end
-
- def read_body_0(dest)
- inflater do |inflate_body_io|
- if chunked?
- read_chunked dest, inflate_body_io
- return
- end
-
- @socket = inflate_body_io
-
- clen = content_length()
- if clen
- @socket.read clen, dest, true # ignore EOF
- return
- end
- clen = range_length()
- if clen
- @socket.read clen, dest
- return
- end
- @socket.read_all dest
- end
- end
-
- ##
- # read_chunked reads from +@socket+ for chunk-size, chunk-extension, CRLF,
- # etc. and +chunk_data_io+ for chunk-data which may be deflate or gzip
- # encoded.
- #
- # See RFC 2616 section 3.6.1 for definitions
-
- def read_chunked(dest, chunk_data_io) # :nodoc:
- total = 0
- while true
- line = @socket.readline
- hexlen = line.slice(/[0-9a-fA-F]+/) or
- raise Net::HTTPBadResponse, "wrong chunk size line: #{line}"
- len = hexlen.hex
- break if len == 0
- begin
- chunk_data_io.read len, dest
- ensure
- total += len
- @socket.read 2 # \r\n
- end
- end
- until @socket.readline.empty?
- # none
- end
- end
-
- def stream_check
- raise IOError, 'attempt to read body out of block' if @socket.closed?
- end
-
- def procdest(dest, block)
- raise ArgumentError, 'both arg and block given for HTTP method' if
- dest and block
- if block
- Net::ReadAdapter.new(block)
- else
- dest || ''
- end
- end
-
- ##
- # Inflater is a wrapper around Net::BufferedIO that transparently inflates
- # zlib and gzip streams.
-
- class Inflater # :nodoc:
-
- ##
- # Creates a new Inflater wrapping +socket+
-
- def initialize socket
- @socket = socket
- # zlib with automatic gzip detection
- @inflate = Zlib::Inflate.new(32 + Zlib::MAX_WBITS)
- end
-
- ##
- # Finishes the inflate stream.
-
- def finish
- return if @inflate.total_in == 0
- @inflate.finish
- end
-
- ##
- # Returns a Net::ReadAdapter that inflates each read chunk into +dest+.
- #
- # This allows a large response body to be inflated without storing the
- # entire body in memory.
-
- def inflate_adapter(dest)
- if dest.respond_to?(:set_encoding)
- dest.set_encoding(Encoding::ASCII_8BIT)
- elsif dest.respond_to?(:force_encoding)
- dest.force_encoding(Encoding::ASCII_8BIT)
- end
- block = proc do |compressed_chunk|
- @inflate.inflate(compressed_chunk) do |chunk|
- dest << chunk
- end
- end
-
- Net::ReadAdapter.new(block)
- end
-
- ##
- # Reads +clen+ bytes from the socket, inflates them, then writes them to
- # +dest+. +ignore_eof+ is passed down to Net::BufferedIO#read
- #
- # Unlike Net::BufferedIO#read, this method returns more than +clen+ bytes.
- # At this time there is no way for a user of Net::HTTPResponse to read a
- # specific number of bytes from the HTTP response body, so this internal
- # API does not return the same number of bytes as were requested.
- #
- # See https://bugs.ruby-lang.org/issues/6492 for further discussion.
-
- def read clen, dest, ignore_eof = false
- temp_dest = inflate_adapter(dest)
-
- @socket.read clen, temp_dest, ignore_eof
- end
-
- ##
- # Reads the rest of the socket, inflates it, then writes it to +dest+.
-
- def read_all dest
- temp_dest = inflate_adapter(dest)
-
- @socket.read_all temp_dest
- end
-
- end
-
-end
-
diff --git a/ruby_2_2/lib/net/http/responses.rb b/ruby_2_2/lib/net/http/responses.rb
deleted file mode 100644
index 1454a27a3e..0000000000
--- a/ruby_2_2/lib/net/http/responses.rb
+++ /dev/null
@@ -1,273 +0,0 @@
-# :stopdoc:
-class Net::HTTPUnknownResponse < Net::HTTPResponse
- HAS_BODY = true
- EXCEPTION_TYPE = Net::HTTPError
-end
-class Net::HTTPInformation < Net::HTTPResponse # 1xx
- HAS_BODY = false
- EXCEPTION_TYPE = Net::HTTPError
-end
-class Net::HTTPSuccess < Net::HTTPResponse # 2xx
- HAS_BODY = true
- EXCEPTION_TYPE = Net::HTTPError
-end
-class Net::HTTPRedirection < Net::HTTPResponse # 3xx
- HAS_BODY = true
- EXCEPTION_TYPE = Net::HTTPRetriableError
-end
-class Net::HTTPClientError < Net::HTTPResponse # 4xx
- HAS_BODY = true
- EXCEPTION_TYPE = Net::HTTPServerException # for backward compatibility
-end
-class Net::HTTPServerError < Net::HTTPResponse # 5xx
- HAS_BODY = true
- EXCEPTION_TYPE = Net::HTTPFatalError # for backward compatibility
-end
-
-class Net::HTTPContinue < Net::HTTPInformation # 100
- HAS_BODY = false
-end
-class Net::HTTPSwitchProtocol < Net::HTTPInformation # 101
- HAS_BODY = false
-end
-# 102 - RFC 2518; removed in RFC 4918
-
-class Net::HTTPOK < Net::HTTPSuccess # 200
- HAS_BODY = true
-end
-class Net::HTTPCreated < Net::HTTPSuccess # 201
- HAS_BODY = true
-end
-class Net::HTTPAccepted < Net::HTTPSuccess # 202
- HAS_BODY = true
-end
-class Net::HTTPNonAuthoritativeInformation < Net::HTTPSuccess # 203
- HAS_BODY = true
-end
-class Net::HTTPNoContent < Net::HTTPSuccess # 204
- HAS_BODY = false
-end
-class Net::HTTPResetContent < Net::HTTPSuccess # 205
- HAS_BODY = false
-end
-class Net::HTTPPartialContent < Net::HTTPSuccess # 206
- HAS_BODY = true
-end
-class Net::HTTPMultiStatus < Net::HTTPSuccess # 207 - RFC 4918
- HAS_BODY = true
-end
-# 208 Already Reported - RFC 5842; experimental
-class Net::HTTPIMUsed < Net::HTTPSuccess # 226 - RFC 3229
- HAS_BODY = true
-end
-
-class Net::HTTPMultipleChoices < Net::HTTPRedirection # 300
- HAS_BODY = true
-end
-Net::HTTPMultipleChoice = Net::HTTPMultipleChoices
-class Net::HTTPMovedPermanently < Net::HTTPRedirection # 301
- HAS_BODY = true
-end
-class Net::HTTPFound < Net::HTTPRedirection # 302
- HAS_BODY = true
-end
-Net::HTTPMovedTemporarily = Net::HTTPFound
-class Net::HTTPSeeOther < Net::HTTPRedirection # 303
- HAS_BODY = true
-end
-class Net::HTTPNotModified < Net::HTTPRedirection # 304
- HAS_BODY = false
-end
-class Net::HTTPUseProxy < Net::HTTPRedirection # 305
- HAS_BODY = false
-end
-# 306 Switch Proxy - no longer unused
-class Net::HTTPTemporaryRedirect < Net::HTTPRedirection # 307
- HAS_BODY = true
-end
-class Net::HTTPPermanentRedirect < Net::HTTPRedirection # 308
- HAS_BODY = true
-end
-
-class Net::HTTPBadRequest < Net::HTTPClientError # 400
- HAS_BODY = true
-end
-class Net::HTTPUnauthorized < Net::HTTPClientError # 401
- HAS_BODY = true
-end
-class Net::HTTPPaymentRequired < Net::HTTPClientError # 402
- HAS_BODY = true
-end
-class Net::HTTPForbidden < Net::HTTPClientError # 403
- HAS_BODY = true
-end
-class Net::HTTPNotFound < Net::HTTPClientError # 404
- HAS_BODY = true
-end
-class Net::HTTPMethodNotAllowed < Net::HTTPClientError # 405
- HAS_BODY = true
-end
-class Net::HTTPNotAcceptable < Net::HTTPClientError # 406
- HAS_BODY = true
-end
-class Net::HTTPProxyAuthenticationRequired < Net::HTTPClientError # 407
- HAS_BODY = true
-end
-class Net::HTTPRequestTimeOut < Net::HTTPClientError # 408
- HAS_BODY = true
-end
-class Net::HTTPConflict < Net::HTTPClientError # 409
- HAS_BODY = true
-end
-class Net::HTTPGone < Net::HTTPClientError # 410
- HAS_BODY = true
-end
-class Net::HTTPLengthRequired < Net::HTTPClientError # 411
- HAS_BODY = true
-end
-class Net::HTTPPreconditionFailed < Net::HTTPClientError # 412
- HAS_BODY = true
-end
-class Net::HTTPRequestEntityTooLarge < Net::HTTPClientError # 413
- HAS_BODY = true
-end
-class Net::HTTPRequestURITooLong < Net::HTTPClientError # 414
- HAS_BODY = true
-end
-Net::HTTPRequestURITooLarge = Net::HTTPRequestURITooLong
-class Net::HTTPUnsupportedMediaType < Net::HTTPClientError # 415
- HAS_BODY = true
-end
-class Net::HTTPRequestedRangeNotSatisfiable < Net::HTTPClientError # 416
- HAS_BODY = true
-end
-class Net::HTTPExpectationFailed < Net::HTTPClientError # 417
- HAS_BODY = true
-end
-# 418 I'm a teapot - RFC 2324; a joke RFC
-# 420 Enhance Your Calm - Twitter
-class Net::HTTPUnprocessableEntity < Net::HTTPClientError # 422 - RFC 4918
- HAS_BODY = true
-end
-class Net::HTTPLocked < Net::HTTPClientError # 423 - RFC 4918
- HAS_BODY = true
-end
-class Net::HTTPFailedDependency < Net::HTTPClientError # 424 - RFC 4918
- HAS_BODY = true
-end
-# 425 Unordered Collection - existed only in draft
-class Net::HTTPUpgradeRequired < Net::HTTPClientError # 426 - RFC 2817
- HAS_BODY = true
-end
-class Net::HTTPPreconditionRequired < Net::HTTPClientError # 428 - RFC 6585
- HAS_BODY = true
-end
-class Net::HTTPTooManyRequests < Net::HTTPClientError # 429 - RFC 6585
- HAS_BODY = true
-end
-class Net::HTTPRequestHeaderFieldsTooLarge < Net::HTTPClientError # 431 - RFC 6585
- HAS_BODY = true
-end
-# 444 No Response - Nginx
-# 449 Retry With - Microsoft
-# 450 Blocked by Windows Parental Controls - Microsoft
-# 499 Client Closed Request - Nginx
-
-class Net::HTTPInternalServerError < Net::HTTPServerError # 500
- HAS_BODY = true
-end
-class Net::HTTPNotImplemented < Net::HTTPServerError # 501
- HAS_BODY = true
-end
-class Net::HTTPBadGateway < Net::HTTPServerError # 502
- HAS_BODY = true
-end
-class Net::HTTPServiceUnavailable < Net::HTTPServerError # 503
- HAS_BODY = true
-end
-class Net::HTTPGatewayTimeOut < Net::HTTPServerError # 504
- HAS_BODY = true
-end
-class Net::HTTPVersionNotSupported < Net::HTTPServerError # 505
- HAS_BODY = true
-end
-# 506 Variant Also Negotiates - RFC 2295; experimental
-class Net::HTTPInsufficientStorage < Net::HTTPServerError # 507 - RFC 4918
- HAS_BODY = true
-end
-# 508 Loop Detected - RFC 5842; experimental
-# 509 Bandwidth Limit Exceeded - Apache bw/limited extension
-# 510 Not Extended - RFC 2774; experimental
-class Net::HTTPNetworkAuthenticationRequired < Net::HTTPServerError # 511 - RFC 6585
- HAS_BODY = true
-end
-
-class Net::HTTPResponse
- CODE_CLASS_TO_OBJ = {
- '1' => Net::HTTPInformation,
- '2' => Net::HTTPSuccess,
- '3' => Net::HTTPRedirection,
- '4' => Net::HTTPClientError,
- '5' => Net::HTTPServerError
- }
- CODE_TO_OBJ = {
- '100' => Net::HTTPContinue,
- '101' => Net::HTTPSwitchProtocol,
-
- '200' => Net::HTTPOK,
- '201' => Net::HTTPCreated,
- '202' => Net::HTTPAccepted,
- '203' => Net::HTTPNonAuthoritativeInformation,
- '204' => Net::HTTPNoContent,
- '205' => Net::HTTPResetContent,
- '206' => Net::HTTPPartialContent,
- '207' => Net::HTTPMultiStatus,
- '226' => Net::HTTPIMUsed,
-
- '300' => Net::HTTPMultipleChoices,
- '301' => Net::HTTPMovedPermanently,
- '302' => Net::HTTPFound,
- '303' => Net::HTTPSeeOther,
- '304' => Net::HTTPNotModified,
- '305' => Net::HTTPUseProxy,
- '307' => Net::HTTPTemporaryRedirect,
-
- '400' => Net::HTTPBadRequest,
- '401' => Net::HTTPUnauthorized,
- '402' => Net::HTTPPaymentRequired,
- '403' => Net::HTTPForbidden,
- '404' => Net::HTTPNotFound,
- '405' => Net::HTTPMethodNotAllowed,
- '406' => Net::HTTPNotAcceptable,
- '407' => Net::HTTPProxyAuthenticationRequired,
- '408' => Net::HTTPRequestTimeOut,
- '409' => Net::HTTPConflict,
- '410' => Net::HTTPGone,
- '411' => Net::HTTPLengthRequired,
- '412' => Net::HTTPPreconditionFailed,
- '413' => Net::HTTPRequestEntityTooLarge,
- '414' => Net::HTTPRequestURITooLong,
- '415' => Net::HTTPUnsupportedMediaType,
- '416' => Net::HTTPRequestedRangeNotSatisfiable,
- '417' => Net::HTTPExpectationFailed,
- '422' => Net::HTTPUnprocessableEntity,
- '423' => Net::HTTPLocked,
- '424' => Net::HTTPFailedDependency,
- '426' => Net::HTTPUpgradeRequired,
- '428' => Net::HTTPPreconditionRequired,
- '429' => Net::HTTPTooManyRequests,
- '431' => Net::HTTPRequestHeaderFieldsTooLarge,
-
- '500' => Net::HTTPInternalServerError,
- '501' => Net::HTTPNotImplemented,
- '502' => Net::HTTPBadGateway,
- '503' => Net::HTTPServiceUnavailable,
- '504' => Net::HTTPGatewayTimeOut,
- '505' => Net::HTTPVersionNotSupported,
- '507' => Net::HTTPInsufficientStorage,
- '511' => Net::HTTPNetworkAuthenticationRequired,
- }
-end
-
-# :startdoc:
-
diff --git a/ruby_2_2/lib/net/https.rb b/ruby_2_2/lib/net/https.rb
deleted file mode 100644
index d36f82002d..0000000000
--- a/ruby_2_2/lib/net/https.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-=begin
-
-= net/https -- SSL/TLS enhancement for Net::HTTP.
-
- This file has been merged with net/http. There is no longer any need to
- require 'net/https' to use HTTPS.
-
- See Net::HTTP for details on how to make HTTPS connections.
-
-== Info
- 'OpenSSL for Ruby 2' project
- Copyright (C) 2001 GOTOU Yuuzou <gotoyuzo@notwork.org>
- All rights reserved.
-
-== Licence
- This program is licenced under the same licence as Ruby.
- (See the file 'LICENCE'.)
-
-=end
-
-require 'net/http'
-require 'openssl'
diff --git a/ruby_2_2/lib/net/imap.rb b/ruby_2_2/lib/net/imap.rb
deleted file mode 100644
index 0517ca1385..0000000000
--- a/ruby_2_2/lib/net/imap.rb
+++ /dev/null
@@ -1,3622 +0,0 @@
-#
-# = net/imap.rb
-#
-# Copyright (C) 2000 Shugo Maeda <shugo@ruby-lang.org>
-#
-# This library is distributed under the terms of the Ruby license.
-# You can freely distribute/modify this library.
-#
-# Documentation: Shugo Maeda, with RDoc conversion and overview by William
-# Webber.
-#
-# See Net::IMAP for documentation.
-#
-
-
-require "socket"
-require "monitor"
-require "digest/md5"
-require "strscan"
-begin
- require "openssl"
-rescue LoadError
-end
-
-module Net
-
- #
- # Net::IMAP implements Internet Message Access Protocol (IMAP) client
- # functionality. The protocol is described in [IMAP].
- #
- # == IMAP Overview
- #
- # An IMAP client connects to a server, and then authenticates
- # itself using either #authenticate() or #login(). Having
- # authenticated itself, there is a range of commands
- # available to it. Most work with mailboxes, which may be
- # arranged in an hierarchical namespace, and each of which
- # contains zero or more messages. How this is implemented on
- # the server is implementation-dependent; on a UNIX server, it
- # will frequently be implemented as files in mailbox format
- # within a hierarchy of directories.
- #
- # To work on the messages within a mailbox, the client must
- # first select that mailbox, using either #select() or (for
- # read-only access) #examine(). Once the client has successfully
- # selected a mailbox, they enter _selected_ state, and that
- # mailbox becomes the _current_ mailbox, on which mail-item
- # related commands implicitly operate.
- #
- # Messages have two sorts of identifiers: message sequence
- # numbers and UIDs.
- #
- # Message sequence numbers number messages within a mailbox
- # from 1 up to the number of items in the mailbox. If a new
- # message arrives during a session, it receives a sequence
- # number equal to the new size of the mailbox. If messages
- # are expunged from the mailbox, remaining messages have their
- # sequence numbers "shuffled down" to fill the gaps.
- #
- # UIDs, on the other hand, are permanently guaranteed not to
- # identify another message within the same mailbox, even if
- # the existing message is deleted. UIDs are required to
- # be assigned in ascending (but not necessarily sequential)
- # order within a mailbox; this means that if a non-IMAP client
- # rearranges the order of mailitems within a mailbox, the
- # UIDs have to be reassigned. An IMAP client thus cannot
- # rearrange message orders.
- #
- # == Examples of Usage
- #
- # === List sender and subject of all recent messages in the default mailbox
- #
- # imap = Net::IMAP.new('mail.example.com')
- # imap.authenticate('LOGIN', 'joe_user', 'joes_password')
- # imap.examine('INBOX')
- # imap.search(["RECENT"]).each do |message_id|
- # envelope = imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"]
- # puts "#{envelope.from[0].name}: \t#{envelope.subject}"
- # end
- #
- # === Move all messages from April 2003 from "Mail/sent-mail" to "Mail/sent-apr03"
- #
- # imap = Net::IMAP.new('mail.example.com')
- # imap.authenticate('LOGIN', 'joe_user', 'joes_password')
- # imap.select('Mail/sent-mail')
- # if not imap.list('Mail/', 'sent-apr03')
- # imap.create('Mail/sent-apr03')
- # end
- # imap.search(["BEFORE", "30-Apr-2003", "SINCE", "1-Apr-2003"]).each do |message_id|
- # imap.copy(message_id, "Mail/sent-apr03")
- # imap.store(message_id, "+FLAGS", [:Deleted])
- # end
- # imap.expunge
- #
- # == Thread Safety
- #
- # Net::IMAP supports concurrent threads. For example,
- #
- # imap = Net::IMAP.new("imap.foo.net", "imap2")
- # imap.authenticate("cram-md5", "bar", "password")
- # imap.select("inbox")
- # fetch_thread = Thread.start { imap.fetch(1..-1, "UID") }
- # search_result = imap.search(["BODY", "hello"])
- # fetch_result = fetch_thread.value
- # imap.disconnect
- #
- # This script invokes the FETCH command and the SEARCH command concurrently.
- #
- # == Errors
- #
- # An IMAP server can send three different types of responses to indicate
- # failure:
- #
- # NO:: the attempted command could not be successfully completed. For
- # instance, the username/password used for logging in are incorrect;
- # the selected mailbox does not exist; etc.
- #
- # BAD:: the request from the client does not follow the server's
- # understanding of the IMAP protocol. This includes attempting
- # commands from the wrong client state; for instance, attempting
- # to perform a SEARCH command without having SELECTed a current
- # mailbox. It can also signal an internal server
- # failure (such as a disk crash) has occurred.
- #
- # BYE:: the server is saying goodbye. This can be part of a normal
- # logout sequence, and can be used as part of a login sequence
- # to indicate that the server is (for some reason) unwilling
- # to accept your connection. As a response to any other command,
- # it indicates either that the server is shutting down, or that
- # the server is timing out the client connection due to inactivity.
- #
- # These three error response are represented by the errors
- # Net::IMAP::NoResponseError, Net::IMAP::BadResponseError, and
- # Net::IMAP::ByeResponseError, all of which are subclasses of
- # Net::IMAP::ResponseError. Essentially, all methods that involve
- # sending a request to the server can generate one of these errors.
- # Only the most pertinent instances have been documented below.
- #
- # Because the IMAP class uses Sockets for communication, its methods
- # are also susceptible to the various errors that can occur when
- # working with sockets. These are generally represented as
- # Errno errors. For instance, any method that involves sending a
- # request to the server and/or receiving a response from it could
- # raise an Errno::EPIPE error if the network connection unexpectedly
- # goes down. See the socket(7), ip(7), tcp(7), socket(2), connect(2),
- # and associated man pages.
- #
- # Finally, a Net::IMAP::DataFormatError is thrown if low-level data
- # is found to be in an incorrect format (for instance, when converting
- # between UTF-8 and UTF-16), and Net::IMAP::ResponseParseError is
- # thrown if a server response is non-parseable.
- #
- #
- # == References
- #
- # [[IMAP]]
- # M. Crispin, "INTERNET MESSAGE ACCESS PROTOCOL - VERSION 4rev1",
- # RFC 2060, December 1996. (Note: since obsoleted by RFC 3501)
- #
- # [[LANGUAGE-TAGS]]
- # Alvestrand, H., "Tags for the Identification of
- # Languages", RFC 1766, March 1995.
- #
- # [[MD5]]
- # Myers, J., and M. Rose, "The Content-MD5 Header Field", RFC
- # 1864, October 1995.
- #
- # [[MIME-IMB]]
- # Freed, N., and N. Borenstein, "MIME (Multipurpose Internet
- # Mail Extensions) Part One: Format of Internet Message Bodies", RFC
- # 2045, November 1996.
- #
- # [[RFC-822]]
- # Crocker, D., "Standard for the Format of ARPA Internet Text
- # Messages", STD 11, RFC 822, University of Delaware, August 1982.
- #
- # [[RFC-2087]]
- # Myers, J., "IMAP4 QUOTA extension", RFC 2087, January 1997.
- #
- # [[RFC-2086]]
- # Myers, J., "IMAP4 ACL extension", RFC 2086, January 1997.
- #
- # [[RFC-2195]]
- # Klensin, J., Catoe, R., and Krumviede, P., "IMAP/POP AUTHorize Extension
- # for Simple Challenge/Response", RFC 2195, September 1997.
- #
- # [[SORT-THREAD-EXT]]
- # Crispin, M., "INTERNET MESSAGE ACCESS PROTOCOL - SORT and THREAD
- # Extensions", draft-ietf-imapext-sort, May 2003.
- #
- # [[OSSL]]
- # http://www.openssl.org
- #
- # [[RSSL]]
- # http://savannah.gnu.org/projects/rubypki
- #
- # [[UTF7]]
- # Goldsmith, D. and Davis, M., "UTF-7: A Mail-Safe Transformation Format of
- # Unicode", RFC 2152, May 1997.
- #
- class IMAP
- include MonitorMixin
- if defined?(OpenSSL::SSL)
- include OpenSSL
- include SSL
- end
-
- # Returns an initial greeting response from the server.
- attr_reader :greeting
-
- # Returns recorded untagged responses. For example:
- #
- # imap.select("inbox")
- # p imap.responses["EXISTS"][-1]
- # #=> 2
- # p imap.responses["UIDVALIDITY"][-1]
- # #=> 968263756
- attr_reader :responses
-
- # Returns all response handlers.
- attr_reader :response_handlers
-
- # The thread to receive exceptions.
- attr_accessor :client_thread
-
- # Flag indicating a message has been seen.
- SEEN = :Seen
-
- # Flag indicating a message has been answered.
- ANSWERED = :Answered
-
- # Flag indicating a message has been flagged for special or urgent
- # attention.
- FLAGGED = :Flagged
-
- # Flag indicating a message has been marked for deletion. This
- # will occur when the mailbox is closed or expunged.
- DELETED = :Deleted
-
- # Flag indicating a message is only a draft or work-in-progress version.
- DRAFT = :Draft
-
- # Flag indicating that the message is "recent," meaning that this
- # session is the first session in which the client has been notified
- # of this message.
- RECENT = :Recent
-
- # Flag indicating that a mailbox context name cannot contain
- # children.
- NOINFERIORS = :Noinferiors
-
- # Flag indicating that a mailbox is not selected.
- NOSELECT = :Noselect
-
- # Flag indicating that a mailbox has been marked "interesting" by
- # the server; this commonly indicates that the mailbox contains
- # new messages.
- MARKED = :Marked
-
- # Flag indicating that the mailbox does not contains new messages.
- UNMARKED = :Unmarked
-
- # Returns the debug mode.
- def self.debug
- return @@debug
- end
-
- # Sets the debug mode.
- def self.debug=(val)
- return @@debug = val
- end
-
- # Returns the max number of flags interned to symbols.
- def self.max_flag_count
- return @@max_flag_count
- end
-
- # Sets the max number of flags interned to symbols.
- def self.max_flag_count=(count)
- @@max_flag_count = count
- end
-
- # Adds an authenticator for Net::IMAP#authenticate. +auth_type+
- # is the type of authentication this authenticator supports
- # (for instance, "LOGIN"). The +authenticator+ is an object
- # which defines a process() method to handle authentication with
- # the server. See Net::IMAP::LoginAuthenticator,
- # Net::IMAP::CramMD5Authenticator, and Net::IMAP::DigestMD5Authenticator
- # for examples.
- #
- #
- # If +auth_type+ refers to an existing authenticator, it will be
- # replaced by the new one.
- def self.add_authenticator(auth_type, authenticator)
- @@authenticators[auth_type] = authenticator
- end
-
- # The default port for IMAP connections, port 143
- def self.default_port
- return PORT
- end
-
- # The default port for IMAPS connections, port 993
- def self.default_tls_port
- return SSL_PORT
- end
-
- class << self
- alias default_imap_port default_port
- alias default_imaps_port default_tls_port
- alias default_ssl_port default_tls_port
- end
-
- # Disconnects from the server.
- def disconnect
- begin
- begin
- # try to call SSL::SSLSocket#io.
- @sock.io.shutdown
- rescue NoMethodError
- # @sock is not an SSL::SSLSocket.
- @sock.shutdown
- end
- rescue Errno::ENOTCONN
- # ignore `Errno::ENOTCONN: Socket is not connected' on some platforms.
- rescue Exception => e
- @receiver_thread.raise(e)
- end
- @receiver_thread.join
- synchronize do
- unless @sock.closed?
- @sock.close
- end
- end
- raise e if e
- end
-
- # Returns true if disconnected from the server.
- def disconnected?
- return @sock.closed?
- end
-
- # Sends a CAPABILITY command, and returns an array of
- # capabilities that the server supports. Each capability
- # is a string. See [IMAP] for a list of possible
- # capabilities.
- #
- # Note that the Net::IMAP class does not modify its
- # behaviour according to the capabilities of the server;
- # it is up to the user of the class to ensure that
- # a certain capability is supported by a server before
- # using it.
- def capability
- synchronize do
- send_command("CAPABILITY")
- return @responses.delete("CAPABILITY")[-1]
- end
- end
-
- # Sends a NOOP command to the server. It does nothing.
- def noop
- send_command("NOOP")
- end
-
- # Sends a LOGOUT command to inform the server that the client is
- # done with the connection.
- def logout
- send_command("LOGOUT")
- end
-
- # Sends a STARTTLS command to start TLS session.
- def starttls(options = {}, verify = true)
- send_command("STARTTLS") do |resp|
- if resp.kind_of?(TaggedResponse) && resp.name == "OK"
- begin
- # for backward compatibility
- certs = options.to_str
- options = create_ssl_params(certs, verify)
- rescue NoMethodError
- end
- start_tls_session(options)
- end
- end
- end
-
- # Sends an AUTHENTICATE command to authenticate the client.
- # The +auth_type+ parameter is a string that represents
- # the authentication mechanism to be used. Currently Net::IMAP
- # supports the authentication mechanisms:
- #
- # LOGIN:: login using cleartext user and password.
- # CRAM-MD5:: login with cleartext user and encrypted password
- # (see [RFC-2195] for a full description). This
- # mechanism requires that the server have the user's
- # password stored in clear-text password.
- #
- # For both of these mechanisms, there should be two +args+: username
- # and (cleartext) password. A server may not support one or the other
- # of these mechanisms; check #capability() for a capability of
- # the form "AUTH=LOGIN" or "AUTH=CRAM-MD5".
- #
- # Authentication is done using the appropriate authenticator object:
- # see @@authenticators for more information on plugging in your own
- # authenticator.
- #
- # For example:
- #
- # imap.authenticate('LOGIN', user, password)
- #
- # A Net::IMAP::NoResponseError is raised if authentication fails.
- def authenticate(auth_type, *args)
- auth_type = auth_type.upcase
- unless @@authenticators.has_key?(auth_type)
- raise ArgumentError,
- format('unknown auth type - "%s"', auth_type)
- end
- authenticator = @@authenticators[auth_type].new(*args)
- send_command("AUTHENTICATE", auth_type) do |resp|
- if resp.instance_of?(ContinuationRequest)
- data = authenticator.process(resp.data.text.unpack("m")[0])
- s = [data].pack("m").gsub(/\n/, "")
- send_string_data(s)
- put_string(CRLF)
- end
- end
- end
-
- # Sends a LOGIN command to identify the client and carries
- # the plaintext +password+ authenticating this +user+. Note
- # that, unlike calling #authenticate() with an +auth_type+
- # of "LOGIN", #login() does *not* use the login authenticator.
- #
- # A Net::IMAP::NoResponseError is raised if authentication fails.
- def login(user, password)
- send_command("LOGIN", user, password)
- end
-
- # Sends a SELECT command to select a +mailbox+ so that messages
- # in the +mailbox+ can be accessed.
- #
- # After you have selected a mailbox, you may retrieve the
- # number of items in that mailbox from @responses["EXISTS"][-1],
- # and the number of recent messages from @responses["RECENT"][-1].
- # Note that these values can change if new messages arrive
- # during a session; see #add_response_handler() for a way of
- # detecting this event.
- #
- # A Net::IMAP::NoResponseError is raised if the mailbox does not
- # exist or is for some reason non-selectable.
- def select(mailbox)
- synchronize do
- @responses.clear
- send_command("SELECT", mailbox)
- end
- end
-
- # Sends a EXAMINE command to select a +mailbox+ so that messages
- # in the +mailbox+ can be accessed. Behaves the same as #select(),
- # except that the selected +mailbox+ is identified as read-only.
- #
- # A Net::IMAP::NoResponseError is raised if the mailbox does not
- # exist or is for some reason non-examinable.
- def examine(mailbox)
- synchronize do
- @responses.clear
- send_command("EXAMINE", mailbox)
- end
- end
-
- # Sends a CREATE command to create a new +mailbox+.
- #
- # A Net::IMAP::NoResponseError is raised if a mailbox with that name
- # cannot be created.
- def create(mailbox)
- send_command("CREATE", mailbox)
- end
-
- # Sends a DELETE command to remove the +mailbox+.
- #
- # A Net::IMAP::NoResponseError is raised if a mailbox with that name
- # cannot be deleted, either because it does not exist or because the
- # client does not have permission to delete it.
- def delete(mailbox)
- send_command("DELETE", mailbox)
- end
-
- # Sends a RENAME command to change the name of the +mailbox+ to
- # +newname+.
- #
- # A Net::IMAP::NoResponseError is raised if a mailbox with the
- # name +mailbox+ cannot be renamed to +newname+ for whatever
- # reason; for instance, because +mailbox+ does not exist, or
- # because there is already a mailbox with the name +newname+.
- def rename(mailbox, newname)
- send_command("RENAME", mailbox, newname)
- end
-
- # Sends a SUBSCRIBE command to add the specified +mailbox+ name to
- # the server's set of "active" or "subscribed" mailboxes as returned
- # by #lsub().
- #
- # A Net::IMAP::NoResponseError is raised if +mailbox+ cannot be
- # subscribed to; for instance, because it does not exist.
- def subscribe(mailbox)
- send_command("SUBSCRIBE", mailbox)
- end
-
- # Sends a UNSUBSCRIBE command to remove the specified +mailbox+ name
- # from the server's set of "active" or "subscribed" mailboxes.
- #
- # A Net::IMAP::NoResponseError is raised if +mailbox+ cannot be
- # unsubscribed from; for instance, because the client is not currently
- # subscribed to it.
- def unsubscribe(mailbox)
- send_command("UNSUBSCRIBE", mailbox)
- end
-
- # Sends a LIST command, and returns a subset of names from
- # the complete set of all names available to the client.
- # +refname+ provides a context (for instance, a base directory
- # in a directory-based mailbox hierarchy). +mailbox+ specifies
- # a mailbox or (via wildcards) mailboxes under that context.
- # Two wildcards may be used in +mailbox+: '*', which matches
- # all characters *including* the hierarchy delimiter (for instance,
- # '/' on a UNIX-hosted directory-based mailbox hierarchy); and '%',
- # which matches all characters *except* the hierarchy delimiter.
- #
- # If +refname+ is empty, +mailbox+ is used directly to determine
- # which mailboxes to match. If +mailbox+ is empty, the root
- # name of +refname+ and the hierarchy delimiter are returned.
- #
- # The return value is an array of +Net::IMAP::MailboxList+. For example:
- #
- # imap.create("foo/bar")
- # imap.create("foo/baz")
- # p imap.list("", "foo/%")
- # #=> [#<Net::IMAP::MailboxList attr=[:Noselect], delim="/", name="foo/">, \\
- # #<Net::IMAP::MailboxList attr=[:Noinferiors, :Marked], delim="/", name="foo/bar">, \\
- # #<Net::IMAP::MailboxList attr=[:Noinferiors], delim="/", name="foo/baz">]
- def list(refname, mailbox)
- synchronize do
- send_command("LIST", refname, mailbox)
- return @responses.delete("LIST")
- end
- end
-
- # Sends a XLIST command, and returns a subset of names from
- # the complete set of all names available to the client.
- # +refname+ provides a context (for instance, a base directory
- # in a directory-based mailbox hierarchy). +mailbox+ specifies
- # a mailbox or (via wildcards) mailboxes under that context.
- # Two wildcards may be used in +mailbox+: '*', which matches
- # all characters *including* the hierarchy delimiter (for instance,
- # '/' on a UNIX-hosted directory-based mailbox hierarchy); and '%',
- # which matches all characters *except* the hierarchy delimiter.
- #
- # If +refname+ is empty, +mailbox+ is used directly to determine
- # which mailboxes to match. If +mailbox+ is empty, the root
- # name of +refname+ and the hierarchy delimiter are returned.
- #
- # The XLIST command is like the LIST command except that the flags
- # returned refer to the function of the folder/mailbox, e.g. :Sent
- #
- # The return value is an array of +Net::IMAP::MailboxList+. For example:
- #
- # imap.create("foo/bar")
- # imap.create("foo/baz")
- # p imap.xlist("", "foo/%")
- # #=> [#<Net::IMAP::MailboxList attr=[:Noselect], delim="/", name="foo/">, \\
- # #<Net::IMAP::MailboxList attr=[:Noinferiors, :Marked], delim="/", name="foo/bar">, \\
- # #<Net::IMAP::MailboxList attr=[:Noinferiors], delim="/", name="foo/baz">]
- def xlist(refname, mailbox)
- synchronize do
- send_command("XLIST", refname, mailbox)
- return @responses.delete("XLIST")
- end
- end
-
- # Sends the GETQUOTAROOT command along with the specified +mailbox+.
- # This command is generally available to both admin and user.
- # If this mailbox exists, it returns an array containing objects of type
- # Net::IMAP::MailboxQuotaRoot and Net::IMAP::MailboxQuota.
- def getquotaroot(mailbox)
- synchronize do
- send_command("GETQUOTAROOT", mailbox)
- result = []
- result.concat(@responses.delete("QUOTAROOT"))
- result.concat(@responses.delete("QUOTA"))
- return result
- end
- end
-
- # Sends the GETQUOTA command along with specified +mailbox+.
- # If this mailbox exists, then an array containing a
- # Net::IMAP::MailboxQuota object is returned. This
- # command is generally only available to server admin.
- def getquota(mailbox)
- synchronize do
- send_command("GETQUOTA", mailbox)
- return @responses.delete("QUOTA")
- end
- end
-
- # Sends a SETQUOTA command along with the specified +mailbox+ and
- # +quota+. If +quota+ is nil, then +quota+ will be unset for that
- # mailbox. Typically one needs to be logged in as a server admin
- # for this to work. The IMAP quota commands are described in
- # [RFC-2087].
- def setquota(mailbox, quota)
- if quota.nil?
- data = '()'
- else
- data = '(STORAGE ' + quota.to_s + ')'
- end
- send_command("SETQUOTA", mailbox, RawData.new(data))
- end
-
- # Sends the SETACL command along with +mailbox+, +user+ and the
- # +rights+ that user is to have on that mailbox. If +rights+ is nil,
- # then that user will be stripped of any rights to that mailbox.
- # The IMAP ACL commands are described in [RFC-2086].
- def setacl(mailbox, user, rights)
- if rights.nil?
- send_command("SETACL", mailbox, user, "")
- else
- send_command("SETACL", mailbox, user, rights)
- end
- end
-
- # Send the GETACL command along with a specified +mailbox+.
- # If this mailbox exists, an array containing objects of
- # Net::IMAP::MailboxACLItem will be returned.
- def getacl(mailbox)
- synchronize do
- send_command("GETACL", mailbox)
- return @responses.delete("ACL")[-1]
- end
- end
-
- # Sends a LSUB command, and returns a subset of names from the set
- # of names that the user has declared as being "active" or
- # "subscribed." +refname+ and +mailbox+ are interpreted as
- # for #list().
- # The return value is an array of +Net::IMAP::MailboxList+.
- def lsub(refname, mailbox)
- synchronize do
- send_command("LSUB", refname, mailbox)
- return @responses.delete("LSUB")
- end
- end
-
- # Sends a STATUS command, and returns the status of the indicated
- # +mailbox+. +attr+ is a list of one or more attributes whose
- # statuses are to be requested. Supported attributes include:
- #
- # MESSAGES:: the number of messages in the mailbox.
- # RECENT:: the number of recent messages in the mailbox.
- # UNSEEN:: the number of unseen messages in the mailbox.
- #
- # The return value is a hash of attributes. For example:
- #
- # p imap.status("inbox", ["MESSAGES", "RECENT"])
- # #=> {"RECENT"=>0, "MESSAGES"=>44}
- #
- # A Net::IMAP::NoResponseError is raised if status values
- # for +mailbox+ cannot be returned; for instance, because it
- # does not exist.
- def status(mailbox, attr)
- synchronize do
- send_command("STATUS", mailbox, attr)
- return @responses.delete("STATUS")[-1].attr
- end
- end
-
- # Sends a APPEND command to append the +message+ to the end of
- # the +mailbox+. The optional +flags+ argument is an array of
- # flags initially passed to the new message. The optional
- # +date_time+ argument specifies the creation time to assign to the
- # new message; it defaults to the current time.
- # For example:
- #
- # imap.append("inbox", <<EOF.gsub(/\n/, "\r\n"), [:Seen], Time.now)
- # Subject: hello
- # From: shugo@ruby-lang.org
- # To: shugo@ruby-lang.org
- #
- # hello world
- # EOF
- #
- # A Net::IMAP::NoResponseError is raised if the mailbox does
- # not exist (it is not created automatically), or if the flags,
- # date_time, or message arguments contain errors.
- def append(mailbox, message, flags = nil, date_time = nil)
- args = []
- if flags
- args.push(flags)
- end
- args.push(date_time) if date_time
- args.push(Literal.new(message))
- send_command("APPEND", mailbox, *args)
- end
-
- # Sends a CHECK command to request a checkpoint of the currently
- # selected mailbox. This performs implementation-specific
- # housekeeping; for instance, reconciling the mailbox's
- # in-memory and on-disk state.
- def check
- send_command("CHECK")
- end
-
- # Sends a CLOSE command to close the currently selected mailbox.
- # The CLOSE command permanently removes from the mailbox all
- # messages that have the \Deleted flag set.
- def close
- send_command("CLOSE")
- end
-
- # Sends a EXPUNGE command to permanently remove from the currently
- # selected mailbox all messages that have the \Deleted flag set.
- def expunge
- synchronize do
- send_command("EXPUNGE")
- return @responses.delete("EXPUNGE")
- end
- end
-
- # Sends a SEARCH command to search the mailbox for messages that
- # match the given searching criteria, and returns message sequence
- # numbers. +keys+ can either be a string holding the entire
- # search string, or a single-dimension array of search keywords and
- # arguments. The following are some common search criteria;
- # see [IMAP] section 6.4.4 for a full list.
- #
- # <message set>:: a set of message sequence numbers. ',' indicates
- # an interval, ':' indicates a range. For instance,
- # '2,10:12,15' means "2,10,11,12,15".
- #
- # BEFORE <date>:: messages with an internal date strictly before
- # <date>. The date argument has a format similar
- # to 8-Aug-2002.
- #
- # BODY <string>:: messages that contain <string> within their body.
- #
- # CC <string>:: messages containing <string> in their CC field.
- #
- # FROM <string>:: messages that contain <string> in their FROM field.
- #
- # NEW:: messages with the \Recent, but not the \Seen, flag set.
- #
- # NOT <search-key>:: negate the following search key.
- #
- # OR <search-key> <search-key>:: "or" two search keys together.
- #
- # ON <date>:: messages with an internal date exactly equal to <date>,
- # which has a format similar to 8-Aug-2002.
- #
- # SINCE <date>:: messages with an internal date on or after <date>.
- #
- # SUBJECT <string>:: messages with <string> in their subject.
- #
- # TO <string>:: messages with <string> in their TO field.
- #
- # For example:
- #
- # p imap.search(["SUBJECT", "hello", "NOT", "NEW"])
- # #=> [1, 6, 7, 8]
- def search(keys, charset = nil)
- return search_internal("SEARCH", keys, charset)
- end
-
- # Similar to #search(), but returns unique identifiers.
- def uid_search(keys, charset = nil)
- return search_internal("UID SEARCH", keys, charset)
- end
-
- # Sends a FETCH command to retrieve data associated with a message
- # in the mailbox.
- #
- # The +set+ parameter is a number or a range between two numbers,
- # or an array of those. The number is a message sequence number,
- # where -1 repesents a '*' for use in range notation like 100..-1
- # being interpreted as '100:*'. Beware that the +exclude_end?+
- # property of a Range object is ignored, and the contents of a
- # range are independent of the order of the range endpoints as per
- # the protocol specification, so 1...5, 5..1 and 5...1 are all
- # equivalent to 1..5.
- #
- # +attr+ is a list of attributes to fetch; see the documentation
- # for Net::IMAP::FetchData for a list of valid attributes.
- #
- # The return value is an array of Net::IMAP::FetchData or nil
- # (instead of an empty array) if there is no matching message.
- #
- # For example:
- #
- # p imap.fetch(6..8, "UID")
- # #=> [#<Net::IMAP::FetchData seqno=6, attr={"UID"=>98}>, \\
- # #<Net::IMAP::FetchData seqno=7, attr={"UID"=>99}>, \\
- # #<Net::IMAP::FetchData seqno=8, attr={"UID"=>100}>]
- # p imap.fetch(6, "BODY[HEADER.FIELDS (SUBJECT)]")
- # #=> [#<Net::IMAP::FetchData seqno=6, attr={"BODY[HEADER.FIELDS (SUBJECT)]"=>"Subject: test\r\n\r\n"}>]
- # data = imap.uid_fetch(98, ["RFC822.SIZE", "INTERNALDATE"])[0]
- # p data.seqno
- # #=> 6
- # p data.attr["RFC822.SIZE"]
- # #=> 611
- # p data.attr["INTERNALDATE"]
- # #=> "12-Oct-2000 22:40:59 +0900"
- # p data.attr["UID"]
- # #=> 98
- def fetch(set, attr)
- return fetch_internal("FETCH", set, attr)
- end
-
- # Similar to #fetch(), but +set+ contains unique identifiers.
- def uid_fetch(set, attr)
- return fetch_internal("UID FETCH", set, attr)
- end
-
- # Sends a STORE command to alter data associated with messages
- # in the mailbox, in particular their flags. The +set+ parameter
- # is a number, an array of numbers, or a Range object. Each number
- # is a message sequence number. +attr+ is the name of a data item
- # to store: 'FLAGS' will replace the message's flag list
- # with the provided one, '+FLAGS' will add the provided flags,
- # and '-FLAGS' will remove them. +flags+ is a list of flags.
- #
- # The return value is an array of Net::IMAP::FetchData. For example:
- #
- # p imap.store(6..8, "+FLAGS", [:Deleted])
- # #=> [#<Net::IMAP::FetchData seqno=6, attr={"FLAGS"=>[:Seen, :Deleted]}>, \\
- # #<Net::IMAP::FetchData seqno=7, attr={"FLAGS"=>[:Seen, :Deleted]}>, \\
- # #<Net::IMAP::FetchData seqno=8, attr={"FLAGS"=>[:Seen, :Deleted]}>]
- def store(set, attr, flags)
- return store_internal("STORE", set, attr, flags)
- end
-
- # Similar to #store(), but +set+ contains unique identifiers.
- def uid_store(set, attr, flags)
- return store_internal("UID STORE", set, attr, flags)
- end
-
- # Sends a COPY command to copy the specified message(s) to the end
- # of the specified destination +mailbox+. The +set+ parameter is
- # a number, an array of numbers, or a Range object. The number is
- # a message sequence number.
- def copy(set, mailbox)
- copy_internal("COPY", set, mailbox)
- end
-
- # Similar to #copy(), but +set+ contains unique identifiers.
- def uid_copy(set, mailbox)
- copy_internal("UID COPY", set, mailbox)
- end
-
- # Sends a SORT command to sort messages in the mailbox.
- # Returns an array of message sequence numbers. For example:
- #
- # p imap.sort(["FROM"], ["ALL"], "US-ASCII")
- # #=> [1, 2, 3, 5, 6, 7, 8, 4, 9]
- # p imap.sort(["DATE"], ["SUBJECT", "hello"], "US-ASCII")
- # #=> [6, 7, 8, 1]
- #
- # See [SORT-THREAD-EXT] for more details.
- def sort(sort_keys, search_keys, charset)
- return sort_internal("SORT", sort_keys, search_keys, charset)
- end
-
- # Similar to #sort(), but returns an array of unique identifiers.
- def uid_sort(sort_keys, search_keys, charset)
- return sort_internal("UID SORT", sort_keys, search_keys, charset)
- end
-
- # Adds a response handler. For example, to detect when
- # the server sends a new EXISTS response (which normally
- # indicates new messages being added to the mailbox),
- # add the following handler after selecting the
- # mailbox:
- #
- # imap.add_response_handler { |resp|
- # if resp.kind_of?(Net::IMAP::UntaggedResponse) and resp.name == "EXISTS"
- # puts "Mailbox now has #{resp.data} messages"
- # end
- # }
- #
- def add_response_handler(handler = Proc.new)
- @response_handlers.push(handler)
- end
-
- # Removes the response handler.
- def remove_response_handler(handler)
- @response_handlers.delete(handler)
- end
-
- # Similar to #search(), but returns message sequence numbers in threaded
- # format, as a Net::IMAP::ThreadMember tree. The supported algorithms
- # are:
- #
- # ORDEREDSUBJECT:: split into single-level threads according to subject,
- # ordered by date.
- # REFERENCES:: split into threads by parent/child relationships determined
- # by which message is a reply to which.
- #
- # Unlike #search(), +charset+ is a required argument. US-ASCII
- # and UTF-8 are sample values.
- #
- # See [SORT-THREAD-EXT] for more details.
- def thread(algorithm, search_keys, charset)
- return thread_internal("THREAD", algorithm, search_keys, charset)
- end
-
- # Similar to #thread(), but returns unique identifiers instead of
- # message sequence numbers.
- def uid_thread(algorithm, search_keys, charset)
- return thread_internal("UID THREAD", algorithm, search_keys, charset)
- end
-
- # Sends an IDLE command that waits for notifications of new or expunged
- # messages. Yields responses from the server during the IDLE.
- #
- # Use #idle_done() to leave IDLE.
- def idle(&response_handler)
- raise LocalJumpError, "no block given" unless response_handler
-
- response = nil
-
- synchronize do
- tag = Thread.current[:net_imap_tag] = generate_tag
- put_string("#{tag} IDLE#{CRLF}")
-
- begin
- add_response_handler(response_handler)
- @idle_done_cond = new_cond
- @idle_done_cond.wait
- @idle_done_cond = nil
- if @receiver_thread_terminating
- raise Net::IMAP::Error, "connection closed"
- end
- ensure
- unless @receiver_thread_terminating
- remove_response_handler(response_handler)
- put_string("DONE#{CRLF}")
- response = get_tagged_response(tag, "IDLE")
- end
- end
- end
-
- return response
- end
-
- # Leaves IDLE.
- def idle_done
- synchronize do
- if @idle_done_cond.nil?
- raise Net::IMAP::Error, "not during IDLE"
- end
- @idle_done_cond.signal
- end
- end
-
- # Decode a string from modified UTF-7 format to UTF-8.
- #
- # UTF-7 is a 7-bit encoding of Unicode [UTF7]. IMAP uses a
- # slightly modified version of this to encode mailbox names
- # containing non-ASCII characters; see [IMAP] section 5.1.3.
- #
- # Net::IMAP does _not_ automatically encode and decode
- # mailbox names to and from UTF-7.
- def self.decode_utf7(s)
- return s.gsub(/&([^-]+)?-/n) {
- if $1
- ($1.tr(",", "/") + "===").unpack("m")[0].encode(Encoding::UTF_8, Encoding::UTF_16BE)
- else
- "&"
- end
- }
- end
-
- # Encode a string from UTF-8 format to modified UTF-7.
- def self.encode_utf7(s)
- return s.gsub(/(&)|[^\x20-\x7e]+/) {
- if $1
- "&-"
- else
- base64 = [$&.encode(Encoding::UTF_16BE)].pack("m")
- "&" + base64.delete("=\n").tr("/", ",") + "-"
- end
- }.force_encoding("ASCII-8BIT")
- end
-
- # Formats +time+ as an IMAP-style date.
- def self.format_date(time)
- return time.strftime('%d-%b-%Y')
- end
-
- # Formats +time+ as an IMAP-style date-time.
- def self.format_datetime(time)
- return time.strftime('%d-%b-%Y %H:%M %z')
- end
-
- private
-
- CRLF = "\r\n" # :nodoc:
- PORT = 143 # :nodoc:
- SSL_PORT = 993 # :nodoc:
-
- @@debug = false
- @@authenticators = {}
- @@max_flag_count = 10000
-
- # :call-seq:
- # Net::IMAP.new(host, options = {})
- #
- # Creates a new Net::IMAP object and connects it to the specified
- # +host+.
- #
- # +options+ is an option hash, each key of which is a symbol.
- #
- # The available options are:
- #
- # port:: Port number (default value is 143 for imap, or 993 for imaps)
- # ssl:: If options[:ssl] is true, then an attempt will be made
- # to use SSL (now TLS) to connect to the server. For this to work
- # OpenSSL [OSSL] and the Ruby OpenSSL [RSSL] extensions need to
- # be installed.
- # If options[:ssl] is a hash, it's passed to
- # OpenSSL::SSL::SSLContext#set_params as parameters.
- #
- # The most common errors are:
- #
- # Errno::ECONNREFUSED:: Connection refused by +host+ or an intervening
- # firewall.
- # Errno::ETIMEDOUT:: Connection timed out (possibly due to packets
- # being dropped by an intervening firewall).
- # Errno::ENETUNREACH:: There is no route to that network.
- # SocketError:: Hostname not known or other socket error.
- # Net::IMAP::ByeResponseError:: The connected to the host was successful, but
- # it immediately said goodbye.
- def initialize(host, port_or_options = {},
- usessl = false, certs = nil, verify = true)
- super()
- @host = host
- begin
- options = port_or_options.to_hash
- rescue NoMethodError
- # for backward compatibility
- options = {}
- options[:port] = port_or_options
- if usessl
- options[:ssl] = create_ssl_params(certs, verify)
- end
- end
- @port = options[:port] || (options[:ssl] ? SSL_PORT : PORT)
- @tag_prefix = "RUBY"
- @tagno = 0
- @parser = ResponseParser.new
- @sock = TCPSocket.open(@host, @port)
- begin
- if options[:ssl]
- start_tls_session(options[:ssl])
- @usessl = true
- else
- @usessl = false
- end
- @responses = Hash.new([].freeze)
- @tagged_responses = {}
- @response_handlers = []
- @tagged_response_arrival = new_cond
- @continuation_request_arrival = new_cond
- @idle_done_cond = nil
- @logout_command_tag = nil
- @debug_output_bol = true
- @exception = nil
-
- @greeting = get_response
- if @greeting.nil?
- raise Error, "connection closed"
- end
- if @greeting.name == "BYE"
- raise ByeResponseError, @greeting
- end
-
- @client_thread = Thread.current
- @receiver_thread = Thread.start {
- begin
- receive_responses
- rescue Exception
- end
- }
- @receiver_thread_terminating = false
- rescue Exception
- @sock.close
- raise
- end
- end
-
- def receive_responses
- connection_closed = false
- until connection_closed
- synchronize do
- @exception = nil
- end
- begin
- resp = get_response
- rescue Exception => e
- synchronize do
- @sock.close
- @exception = e
- end
- break
- end
- unless resp
- synchronize do
- @exception = EOFError.new("end of file reached")
- end
- break
- end
- begin
- synchronize do
- case resp
- when TaggedResponse
- @tagged_responses[resp.tag] = resp
- @tagged_response_arrival.broadcast
- if resp.tag == @logout_command_tag
- return
- end
- when UntaggedResponse
- record_response(resp.name, resp.data)
- if resp.data.instance_of?(ResponseText) &&
- (code = resp.data.code)
- record_response(code.name, code.data)
- end
- if resp.name == "BYE" && @logout_command_tag.nil?
- @sock.close
- @exception = ByeResponseError.new(resp)
- connection_closed = true
- end
- when ContinuationRequest
- @continuation_request_arrival.signal
- end
- @response_handlers.each do |handler|
- handler.call(resp)
- end
- end
- rescue Exception => e
- @exception = e
- synchronize do
- @tagged_response_arrival.broadcast
- @continuation_request_arrival.broadcast
- end
- end
- end
- synchronize do
- @receiver_thread_terminating = true
- @tagged_response_arrival.broadcast
- @continuation_request_arrival.broadcast
- if @idle_done_cond
- @idle_done_cond.signal
- end
- end
- end
-
- def get_tagged_response(tag, cmd)
- until @tagged_responses.key?(tag)
- raise @exception if @exception
- @tagged_response_arrival.wait
- end
- resp = @tagged_responses.delete(tag)
- case resp.name
- when /\A(?:NO)\z/ni
- raise NoResponseError, resp
- when /\A(?:BAD)\z/ni
- raise BadResponseError, resp
- else
- return resp
- end
- end
-
- def get_response
- buff = ""
- while true
- s = @sock.gets(CRLF)
- break unless s
- buff.concat(s)
- if /\{(\d+)\}\r\n/n =~ s
- s = @sock.read($1.to_i)
- buff.concat(s)
- else
- break
- end
- end
- return nil if buff.length == 0
- if @@debug
- $stderr.print(buff.gsub(/^/n, "S: "))
- end
- return @parser.parse(buff)
- end
-
- def record_response(name, data)
- unless @responses.has_key?(name)
- @responses[name] = []
- end
- @responses[name].push(data)
- end
-
- def send_command(cmd, *args, &block)
- synchronize do
- args.each do |i|
- validate_data(i)
- end
- tag = generate_tag
- put_string(tag + " " + cmd)
- args.each do |i|
- put_string(" ")
- send_data(i)
- end
- put_string(CRLF)
- if cmd == "LOGOUT"
- @logout_command_tag = tag
- end
- if block
- add_response_handler(block)
- end
- begin
- return get_tagged_response(tag, cmd)
- ensure
- if block
- remove_response_handler(block)
- end
- end
- end
- end
-
- def generate_tag
- @tagno += 1
- return format("%s%04d", @tag_prefix, @tagno)
- end
-
- def put_string(str)
- @sock.print(str)
- if @@debug
- if @debug_output_bol
- $stderr.print("C: ")
- end
- $stderr.print(str.gsub(/\n(?!\z)/n, "\nC: "))
- if /\r\n\z/n.match(str)
- @debug_output_bol = true
- else
- @debug_output_bol = false
- end
- end
- end
-
- def validate_data(data)
- case data
- when nil
- when String
- when Integer
- NumValidator.ensure_number(data)
- when Array
- data.each do |i|
- validate_data(i)
- end
- when Time
- when Symbol
- else
- data.validate
- end
- end
-
- def send_data(data)
- case data
- when nil
- put_string("NIL")
- when String
- send_string_data(data)
- when Integer
- send_number_data(data)
- when Array
- send_list_data(data)
- when Time
- send_time_data(data)
- when Symbol
- send_symbol_data(data)
- else
- data.send_data(self)
- end
- end
-
- def send_string_data(str)
- case str
- when ""
- put_string('""')
- when /[\x80-\xff\r\n]/n
- # literal
- send_literal(str)
- when /[(){ \x00-\x1f\x7f%*"\\]/n
- # quoted string
- send_quoted_string(str)
- else
- put_string(str)
- end
- end
-
- def send_quoted_string(str)
- put_string('"' + str.gsub(/["\\]/n, "\\\\\\&") + '"')
- end
-
- def send_literal(str)
- put_string("{" + str.bytesize.to_s + "}" + CRLF)
- @continuation_request_arrival.wait
- raise @exception if @exception
- put_string(str)
- end
-
- def send_number_data(num)
- put_string(num.to_s)
- end
-
- def send_list_data(list)
- put_string("(")
- first = true
- list.each do |i|
- if first
- first = false
- else
- put_string(" ")
- end
- send_data(i)
- end
- put_string(")")
- end
-
- DATE_MONTH = %w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
-
- def send_time_data(time)
- t = time.dup.gmtime
- s = format('"%2d-%3s-%4d %02d:%02d:%02d +0000"',
- t.day, DATE_MONTH[t.month - 1], t.year,
- t.hour, t.min, t.sec)
- put_string(s)
- end
-
- def send_symbol_data(symbol)
- put_string("\\" + symbol.to_s)
- end
-
- def search_internal(cmd, keys, charset)
- if keys.instance_of?(String)
- keys = [RawData.new(keys)]
- else
- normalize_searching_criteria(keys)
- end
- synchronize do
- if charset
- send_command(cmd, "CHARSET", charset, *keys)
- else
- send_command(cmd, *keys)
- end
- return @responses.delete("SEARCH")[-1]
- end
- end
-
- def fetch_internal(cmd, set, attr)
- case attr
- when String then
- attr = RawData.new(attr)
- when Array then
- attr = attr.map { |arg|
- arg.is_a?(String) ? RawData.new(arg) : arg
- }
- end
-
- synchronize do
- @responses.delete("FETCH")
- send_command(cmd, MessageSet.new(set), attr)
- return @responses.delete("FETCH")
- end
- end
-
- def store_internal(cmd, set, attr, flags)
- if attr.instance_of?(String)
- attr = RawData.new(attr)
- end
- synchronize do
- @responses.delete("FETCH")
- send_command(cmd, MessageSet.new(set), attr, flags)
- return @responses.delete("FETCH")
- end
- end
-
- def copy_internal(cmd, set, mailbox)
- send_command(cmd, MessageSet.new(set), mailbox)
- end
-
- def sort_internal(cmd, sort_keys, search_keys, charset)
- if search_keys.instance_of?(String)
- search_keys = [RawData.new(search_keys)]
- else
- normalize_searching_criteria(search_keys)
- end
- normalize_searching_criteria(search_keys)
- synchronize do
- send_command(cmd, sort_keys, charset, *search_keys)
- return @responses.delete("SORT")[-1]
- end
- end
-
- def thread_internal(cmd, algorithm, search_keys, charset)
- if search_keys.instance_of?(String)
- search_keys = [RawData.new(search_keys)]
- else
- normalize_searching_criteria(search_keys)
- end
- normalize_searching_criteria(search_keys)
- send_command(cmd, algorithm, charset, *search_keys)
- return @responses.delete("THREAD")[-1]
- end
-
- def normalize_searching_criteria(keys)
- keys.collect! do |i|
- case i
- when -1, Range, Array
- MessageSet.new(i)
- else
- i
- end
- end
- end
-
- def create_ssl_params(certs = nil, verify = true)
- params = {}
- if certs
- if File.file?(certs)
- params[:ca_file] = certs
- elsif File.directory?(certs)
- params[:ca_path] = certs
- end
- end
- if verify
- params[:verify_mode] = VERIFY_PEER
- else
- params[:verify_mode] = VERIFY_NONE
- end
- return params
- end
-
- def start_tls_session(params = {})
- unless defined?(OpenSSL::SSL)
- raise "SSL extension not installed"
- end
- if @sock.kind_of?(OpenSSL::SSL::SSLSocket)
- raise RuntimeError, "already using SSL"
- end
- begin
- params = params.to_hash
- rescue NoMethodError
- params = {}
- end
- context = SSLContext.new
- context.set_params(params)
- if defined?(VerifyCallbackProc)
- context.verify_callback = VerifyCallbackProc
- end
- @sock = SSLSocket.new(@sock, context)
- @sock.sync_close = true
- @sock.connect
- if context.verify_mode != VERIFY_NONE
- @sock.post_connection_check(@host)
- end
- end
-
- class RawData # :nodoc:
- def send_data(imap)
- imap.send(:put_string, @data)
- end
-
- def validate
- end
-
- private
-
- def initialize(data)
- @data = data
- end
- end
-
- class Atom # :nodoc:
- def send_data(imap)
- imap.send(:put_string, @data)
- end
-
- def validate
- end
-
- private
-
- def initialize(data)
- @data = data
- end
- end
-
- class QuotedString # :nodoc:
- def send_data(imap)
- imap.send(:send_quoted_string, @data)
- end
-
- def validate
- end
-
- private
-
- def initialize(data)
- @data = data
- end
- end
-
- class Literal # :nodoc:
- def send_data(imap)
- imap.send(:send_literal, @data)
- end
-
- def validate
- end
-
- private
-
- def initialize(data)
- @data = data
- end
- end
-
- class MessageSet # :nodoc:
- def send_data(imap)
- imap.send(:put_string, format_internal(@data))
- end
-
- def validate
- validate_internal(@data)
- end
-
- private
-
- def initialize(data)
- @data = data
- end
-
- def format_internal(data)
- case data
- when "*"
- return data
- when Integer
- if data == -1
- return "*"
- else
- return data.to_s
- end
- when Range
- return format_internal(data.first) +
- ":" + format_internal(data.last)
- when Array
- return data.collect {|i| format_internal(i)}.join(",")
- when ThreadMember
- return data.seqno.to_s +
- ":" + data.children.collect {|i| format_internal(i).join(",")}
- end
- end
-
- def validate_internal(data)
- case data
- when "*"
- when Integer
- NumValidator.ensure_nz_number(data)
- when Range
- when Array
- data.each do |i|
- validate_internal(i)
- end
- when ThreadMember
- data.children.each do |i|
- validate_internal(i)
- end
- else
- raise DataFormatError, data.inspect
- end
- end
- end
-
- # Common validators of number and nz_number types
- module NumValidator # :nodoc
- class << self
- # Check is passed argument valid 'number' in RFC 3501 terminology
- def valid_number?(num)
- # [RFC 3501]
- # number = 1*DIGIT
- # ; Unsigned 32-bit integer
- # ; (0 <= n < 4,294,967,296)
- num >= 0 && num < 4294967296
- end
-
- # Check is passed argument valid 'nz_number' in RFC 3501 terminology
- def valid_nz_number?(num)
- # [RFC 3501]
- # nz-number = digit-nz *DIGIT
- # ; Non-zero unsigned 32-bit integer
- # ; (0 < n < 4,294,967,296)
- num != 0 && valid_number?(num)
- end
-
- # Ensure argument is 'number' or raise DataFormatError
- def ensure_number(num)
- return if valid_number?(num)
-
- msg = "number must be unsigned 32-bit integer: #{num}"
- raise DataFormatError, msg
- end
-
- # Ensure argument is 'nz_number' or raise DataFormatError
- def ensure_nz_number(num)
- return if valid_nz_number?(num)
-
- msg = "nz_number must be non-zero unsigned 32-bit integer: #{num}"
- raise DataFormatError, msg
- end
- end
- end
-
- # Net::IMAP::ContinuationRequest represents command continuation requests.
- #
- # The command continuation request response is indicated by a "+" token
- # instead of a tag. This form of response indicates that the server is
- # ready to accept the continuation of a command from the client. The
- # remainder of this response is a line of text.
- #
- # continue_req ::= "+" SPACE (resp_text / base64)
- #
- # ==== Fields:
- #
- # data:: Returns the data (Net::IMAP::ResponseText).
- #
- # raw_data:: Returns the raw data string.
- ContinuationRequest = Struct.new(:data, :raw_data)
-
- # Net::IMAP::UntaggedResponse represents untagged responses.
- #
- # Data transmitted by the server to the client and status responses
- # that do not indicate command completion are prefixed with the token
- # "*", and are called untagged responses.
- #
- # response_data ::= "*" SPACE (resp_cond_state / resp_cond_bye /
- # mailbox_data / message_data / capability_data)
- #
- # ==== Fields:
- #
- # name:: Returns the name, such as "FLAGS", "LIST", or "FETCH".
- #
- # data:: Returns the data such as an array of flag symbols,
- # a ((<Net::IMAP::MailboxList>)) object.
- #
- # raw_data:: Returns the raw data string.
- UntaggedResponse = Struct.new(:name, :data, :raw_data)
-
- # Net::IMAP::TaggedResponse represents tagged responses.
- #
- # The server completion result response indicates the success or
- # failure of the operation. It is tagged with the same tag as the
- # client command which began the operation.
- #
- # response_tagged ::= tag SPACE resp_cond_state CRLF
- #
- # tag ::= 1*<any ATOM_CHAR except "+">
- #
- # resp_cond_state ::= ("OK" / "NO" / "BAD") SPACE resp_text
- #
- # ==== Fields:
- #
- # tag:: Returns the tag.
- #
- # name:: Returns the name, one of "OK", "NO", or "BAD".
- #
- # data:: Returns the data. See ((<Net::IMAP::ResponseText>)).
- #
- # raw_data:: Returns the raw data string.
- #
- TaggedResponse = Struct.new(:tag, :name, :data, :raw_data)
-
- # Net::IMAP::ResponseText represents texts of responses.
- # The text may be prefixed by the response code.
- #
- # resp_text ::= ["[" resp_text_code "]" SPACE] (text_mime2 / text)
- # ;; text SHOULD NOT begin with "[" or "="
- #
- # ==== Fields:
- #
- # code:: Returns the response code. See ((<Net::IMAP::ResponseCode>)).
- #
- # text:: Returns the text.
- #
- ResponseText = Struct.new(:code, :text)
-
- # Net::IMAP::ResponseCode represents response codes.
- #
- # resp_text_code ::= "ALERT" / "PARSE" /
- # "PERMANENTFLAGS" SPACE "(" #(flag / "\*") ")" /
- # "READ-ONLY" / "READ-WRITE" / "TRYCREATE" /
- # "UIDVALIDITY" SPACE nz_number /
- # "UNSEEN" SPACE nz_number /
- # atom [SPACE 1*<any TEXT_CHAR except "]">]
- #
- # ==== Fields:
- #
- # name:: Returns the name, such as "ALERT", "PERMANENTFLAGS", or "UIDVALIDITY".
- #
- # data:: Returns the data, if it exists.
- #
- ResponseCode = Struct.new(:name, :data)
-
- # Net::IMAP::MailboxList represents contents of the LIST response.
- #
- # mailbox_list ::= "(" #("\Marked" / "\Noinferiors" /
- # "\Noselect" / "\Unmarked" / flag_extension) ")"
- # SPACE (<"> QUOTED_CHAR <"> / nil) SPACE mailbox
- #
- # ==== Fields:
- #
- # attr:: Returns the name attributes. Each name attribute is a symbol
- # capitalized by String#capitalize, such as :Noselect (not :NoSelect).
- #
- # delim:: Returns the hierarchy delimiter.
- #
- # name:: Returns the mailbox name.
- #
- MailboxList = Struct.new(:attr, :delim, :name)
-
- # Net::IMAP::MailboxQuota represents contents of GETQUOTA response.
- # This object can also be a response to GETQUOTAROOT. In the syntax
- # specification below, the delimiter used with the "#" construct is a
- # single space (SPACE).
- #
- # quota_list ::= "(" #quota_resource ")"
- #
- # quota_resource ::= atom SPACE number SPACE number
- #
- # quota_response ::= "QUOTA" SPACE astring SPACE quota_list
- #
- # ==== Fields:
- #
- # mailbox:: The mailbox with the associated quota.
- #
- # usage:: Current storage usage of the mailbox.
- #
- # quota:: Quota limit imposed on the mailbox.
- #
- MailboxQuota = Struct.new(:mailbox, :usage, :quota)
-
- # Net::IMAP::MailboxQuotaRoot represents part of the GETQUOTAROOT
- # response. (GETQUOTAROOT can also return Net::IMAP::MailboxQuota.)
- #
- # quotaroot_response ::= "QUOTAROOT" SPACE astring *(SPACE astring)
- #
- # ==== Fields:
- #
- # mailbox:: The mailbox with the associated quota.
- #
- # quotaroots:: Zero or more quotaroots that affect the quota on the
- # specified mailbox.
- #
- MailboxQuotaRoot = Struct.new(:mailbox, :quotaroots)
-
- # Net::IMAP::MailboxACLItem represents the response from GETACL.
- #
- # acl_data ::= "ACL" SPACE mailbox *(SPACE identifier SPACE rights)
- #
- # identifier ::= astring
- #
- # rights ::= astring
- #
- # ==== Fields:
- #
- # user:: Login name that has certain rights to the mailbox
- # that was specified with the getacl command.
- #
- # rights:: The access rights the indicated user has to the
- # mailbox.
- #
- MailboxACLItem = Struct.new(:user, :rights, :mailbox)
-
- # Net::IMAP::StatusData represents the contents of the STATUS response.
- #
- # ==== Fields:
- #
- # mailbox:: Returns the mailbox name.
- #
- # attr:: Returns a hash. Each key is one of "MESSAGES", "RECENT", "UIDNEXT",
- # "UIDVALIDITY", "UNSEEN". Each value is a number.
- #
- StatusData = Struct.new(:mailbox, :attr)
-
- # Net::IMAP::FetchData represents the contents of the FETCH response.
- #
- # ==== Fields:
- #
- # seqno:: Returns the message sequence number.
- # (Note: not the unique identifier, even for the UID command response.)
- #
- # attr:: Returns a hash. Each key is a data item name, and each value is
- # its value.
- #
- # The current data items are:
- #
- # [BODY]
- # A form of BODYSTRUCTURE without extension data.
- # [BODY[<section>]<<origin_octet>>]
- # A string expressing the body contents of the specified section.
- # [BODYSTRUCTURE]
- # An object that describes the [MIME-IMB] body structure of a message.
- # See Net::IMAP::BodyTypeBasic, Net::IMAP::BodyTypeText,
- # Net::IMAP::BodyTypeMessage, Net::IMAP::BodyTypeMultipart.
- # [ENVELOPE]
- # A Net::IMAP::Envelope object that describes the envelope
- # structure of a message.
- # [FLAGS]
- # A array of flag symbols that are set for this message. Flag symbols
- # are capitalized by String#capitalize.
- # [INTERNALDATE]
- # A string representing the internal date of the message.
- # [RFC822]
- # Equivalent to BODY[].
- # [RFC822.HEADER]
- # Equivalent to BODY.PEEK[HEADER].
- # [RFC822.SIZE]
- # A number expressing the [RFC-822] size of the message.
- # [RFC822.TEXT]
- # Equivalent to BODY[TEXT].
- # [UID]
- # A number expressing the unique identifier of the message.
- #
- FetchData = Struct.new(:seqno, :attr)
-
- # Net::IMAP::Envelope represents envelope structures of messages.
- #
- # ==== Fields:
- #
- # date:: Returns a string that represents the date.
- #
- # subject:: Returns a string that represents the subject.
- #
- # from:: Returns an array of Net::IMAP::Address that represents the from.
- #
- # sender:: Returns an array of Net::IMAP::Address that represents the sender.
- #
- # reply_to:: Returns an array of Net::IMAP::Address that represents the reply-to.
- #
- # to:: Returns an array of Net::IMAP::Address that represents the to.
- #
- # cc:: Returns an array of Net::IMAP::Address that represents the cc.
- #
- # bcc:: Returns an array of Net::IMAP::Address that represents the bcc.
- #
- # in_reply_to:: Returns a string that represents the in-reply-to.
- #
- # message_id:: Returns a string that represents the message-id.
- #
- Envelope = Struct.new(:date, :subject, :from, :sender, :reply_to,
- :to, :cc, :bcc, :in_reply_to, :message_id)
-
- #
- # Net::IMAP::Address represents electronic mail addresses.
- #
- # ==== Fields:
- #
- # name:: Returns the phrase from [RFC-822] mailbox.
- #
- # route:: Returns the route from [RFC-822] route-addr.
- #
- # mailbox:: nil indicates end of [RFC-822] group.
- # If non-nil and host is nil, returns [RFC-822] group name.
- # Otherwise, returns [RFC-822] local-part.
- #
- # host:: nil indicates [RFC-822] group syntax.
- # Otherwise, returns [RFC-822] domain name.
- #
- Address = Struct.new(:name, :route, :mailbox, :host)
-
- #
- # Net::IMAP::ContentDisposition represents Content-Disposition fields.
- #
- # ==== Fields:
- #
- # dsp_type:: Returns the disposition type.
- #
- # param:: Returns a hash that represents parameters of the Content-Disposition
- # field.
- #
- ContentDisposition = Struct.new(:dsp_type, :param)
-
- # Net::IMAP::ThreadMember represents a thread-node returned
- # by Net::IMAP#thread.
- #
- # ==== Fields:
- #
- # seqno:: The sequence number of this message.
- #
- # children:: An array of Net::IMAP::ThreadMember objects for mail
- # items that are children of this in the thread.
- #
- ThreadMember = Struct.new(:seqno, :children)
-
- # Net::IMAP::BodyTypeBasic represents basic body structures of messages.
- #
- # ==== Fields:
- #
- # media_type:: Returns the content media type name as defined in [MIME-IMB].
- #
- # subtype:: Returns the content subtype name as defined in [MIME-IMB].
- #
- # param:: Returns a hash that represents parameters as defined in [MIME-IMB].
- #
- # content_id:: Returns a string giving the content id as defined in [MIME-IMB].
- #
- # description:: Returns a string giving the content description as defined in
- # [MIME-IMB].
- #
- # encoding:: Returns a string giving the content transfer encoding as defined in
- # [MIME-IMB].
- #
- # size:: Returns a number giving the size of the body in octets.
- #
- # md5:: Returns a string giving the body MD5 value as defined in [MD5].
- #
- # disposition:: Returns a Net::IMAP::ContentDisposition object giving
- # the content disposition.
- #
- # language:: Returns a string or an array of strings giving the body
- # language value as defined in [LANGUAGE-TAGS].
- #
- # extension:: Returns extension data.
- #
- # multipart?:: Returns false.
- #
- class BodyTypeBasic < Struct.new(:media_type, :subtype,
- :param, :content_id,
- :description, :encoding, :size,
- :md5, :disposition, :language,
- :extension)
- def multipart?
- return false
- end
-
- # Obsolete: use +subtype+ instead. Calling this will
- # generate a warning message to +stderr+, then return
- # the value of +subtype+.
- def media_subtype
- $stderr.printf("warning: media_subtype is obsolete.\n")
- $stderr.printf(" use subtype instead.\n")
- return subtype
- end
- end
-
- # Net::IMAP::BodyTypeText represents TEXT body structures of messages.
- #
- # ==== Fields:
- #
- # lines:: Returns the size of the body in text lines.
- #
- # And Net::IMAP::BodyTypeText has all fields of Net::IMAP::BodyTypeBasic.
- #
- class BodyTypeText < Struct.new(:media_type, :subtype,
- :param, :content_id,
- :description, :encoding, :size,
- :lines,
- :md5, :disposition, :language,
- :extension)
- def multipart?
- return false
- end
-
- # Obsolete: use +subtype+ instead. Calling this will
- # generate a warning message to +stderr+, then return
- # the value of +subtype+.
- def media_subtype
- $stderr.printf("warning: media_subtype is obsolete.\n")
- $stderr.printf(" use subtype instead.\n")
- return subtype
- end
- end
-
- # Net::IMAP::BodyTypeMessage represents MESSAGE/RFC822 body structures of messages.
- #
- # ==== Fields:
- #
- # envelope:: Returns a Net::IMAP::Envelope giving the envelope structure.
- #
- # body:: Returns an object giving the body structure.
- #
- # And Net::IMAP::BodyTypeMessage has all methods of Net::IMAP::BodyTypeText.
- #
- class BodyTypeMessage < Struct.new(:media_type, :subtype,
- :param, :content_id,
- :description, :encoding, :size,
- :envelope, :body, :lines,
- :md5, :disposition, :language,
- :extension)
- def multipart?
- return false
- end
-
- # Obsolete: use +subtype+ instead. Calling this will
- # generate a warning message to +stderr+, then return
- # the value of +subtype+.
- def media_subtype
- $stderr.printf("warning: media_subtype is obsolete.\n")
- $stderr.printf(" use subtype instead.\n")
- return subtype
- end
- end
-
- # Net::IMAP::BodyTypeAttachment represents attachment body structures
- # of messages.
- #
- # ==== Fields:
- #
- # media_type:: Returns the content media type name.
- #
- # subtype:: Returns +nil+.
- #
- # param:: Returns a hash that represents parameters.
- #
- # multipart?:: Returns false.
- #
- class BodyTypeAttachment < Struct.new(:media_type, :subtype,
- :param)
- def multipart?
- return false
- end
- end
-
- # Net::IMAP::BodyTypeMultipart represents multipart body structures
- # of messages.
- #
- # ==== Fields:
- #
- # media_type:: Returns the content media type name as defined in [MIME-IMB].
- #
- # subtype:: Returns the content subtype name as defined in [MIME-IMB].
- #
- # parts:: Returns multiple parts.
- #
- # param:: Returns a hash that represents parameters as defined in [MIME-IMB].
- #
- # disposition:: Returns a Net::IMAP::ContentDisposition object giving
- # the content disposition.
- #
- # language:: Returns a string or an array of strings giving the body
- # language value as defined in [LANGUAGE-TAGS].
- #
- # extension:: Returns extension data.
- #
- # multipart?:: Returns true.
- #
- class BodyTypeMultipart < Struct.new(:media_type, :subtype,
- :parts,
- :param, :disposition, :language,
- :extension)
- def multipart?
- return true
- end
-
- # Obsolete: use +subtype+ instead. Calling this will
- # generate a warning message to +stderr+, then return
- # the value of +subtype+.
- def media_subtype
- $stderr.printf("warning: media_subtype is obsolete.\n")
- $stderr.printf(" use subtype instead.\n")
- return subtype
- end
- end
-
- class BodyTypeExtension < Struct.new(:media_type, :subtype,
- :params, :content_id,
- :description, :encoding, :size)
- def multipart?
- return false
- end
- end
-
- class ResponseParser # :nodoc:
- def initialize
- @str = nil
- @pos = nil
- @lex_state = nil
- @token = nil
- @flag_symbols = {}
- end
-
- def parse(str)
- @str = str
- @pos = 0
- @lex_state = EXPR_BEG
- @token = nil
- return response
- end
-
- private
-
- EXPR_BEG = :EXPR_BEG
- EXPR_DATA = :EXPR_DATA
- EXPR_TEXT = :EXPR_TEXT
- EXPR_RTEXT = :EXPR_RTEXT
- EXPR_CTEXT = :EXPR_CTEXT
-
- T_SPACE = :SPACE
- T_NIL = :NIL
- T_NUMBER = :NUMBER
- T_ATOM = :ATOM
- T_QUOTED = :QUOTED
- T_LPAR = :LPAR
- T_RPAR = :RPAR
- T_BSLASH = :BSLASH
- T_STAR = :STAR
- T_LBRA = :LBRA
- T_RBRA = :RBRA
- T_LITERAL = :LITERAL
- T_PLUS = :PLUS
- T_PERCENT = :PERCENT
- T_CRLF = :CRLF
- T_EOF = :EOF
- T_TEXT = :TEXT
-
- BEG_REGEXP = /\G(?:\
-(?# 1: SPACE )( +)|\
-(?# 2: NIL )(NIL)(?=[\x80-\xff(){ \x00-\x1f\x7f%*"\\\[\]+])|\
-(?# 3: NUMBER )(\d+)(?=[\x80-\xff(){ \x00-\x1f\x7f%*"\\\[\]+])|\
-(?# 4: ATOM )([^\x80-\xff(){ \x00-\x1f\x7f%*"\\\[\]+]+)|\
-(?# 5: QUOTED )"((?:[^\x00\r\n"\\]|\\["\\])*)"|\
-(?# 6: LPAR )(\()|\
-(?# 7: RPAR )(\))|\
-(?# 8: BSLASH )(\\)|\
-(?# 9: STAR )(\*)|\
-(?# 10: LBRA )(\[)|\
-(?# 11: RBRA )(\])|\
-(?# 12: LITERAL )\{(\d+)\}\r\n|\
-(?# 13: PLUS )(\+)|\
-(?# 14: PERCENT )(%)|\
-(?# 15: CRLF )(\r\n)|\
-(?# 16: EOF )(\z))/ni
-
- DATA_REGEXP = /\G(?:\
-(?# 1: SPACE )( )|\
-(?# 2: NIL )(NIL)|\
-(?# 3: NUMBER )(\d+)|\
-(?# 4: QUOTED )"((?:[^\x00\r\n"\\]|\\["\\])*)"|\
-(?# 5: LITERAL )\{(\d+)\}\r\n|\
-(?# 6: LPAR )(\()|\
-(?# 7: RPAR )(\)))/ni
-
- TEXT_REGEXP = /\G(?:\
-(?# 1: TEXT )([^\x00\r\n]*))/ni
-
- RTEXT_REGEXP = /\G(?:\
-(?# 1: LBRA )(\[)|\
-(?# 2: TEXT )([^\x00\r\n]*))/ni
-
- CTEXT_REGEXP = /\G(?:\
-(?# 1: TEXT )([^\x00\r\n\]]*))/ni
-
- Token = Struct.new(:symbol, :value)
-
- def response
- token = lookahead
- case token.symbol
- when T_PLUS
- result = continue_req
- when T_STAR
- result = response_untagged
- else
- result = response_tagged
- end
- match(T_CRLF)
- match(T_EOF)
- return result
- end
-
- def continue_req
- match(T_PLUS)
- match(T_SPACE)
- return ContinuationRequest.new(resp_text, @str)
- end
-
- def response_untagged
- match(T_STAR)
- match(T_SPACE)
- token = lookahead
- if token.symbol == T_NUMBER
- return numeric_response
- elsif token.symbol == T_ATOM
- case token.value
- when /\A(?:OK|NO|BAD|BYE|PREAUTH)\z/ni
- return response_cond
- when /\A(?:FLAGS)\z/ni
- return flags_response
- when /\A(?:LIST|LSUB|XLIST)\z/ni
- return list_response
- when /\A(?:QUOTA)\z/ni
- return getquota_response
- when /\A(?:QUOTAROOT)\z/ni
- return getquotaroot_response
- when /\A(?:ACL)\z/ni
- return getacl_response
- when /\A(?:SEARCH|SORT)\z/ni
- return search_response
- when /\A(?:THREAD)\z/ni
- return thread_response
- when /\A(?:STATUS)\z/ni
- return status_response
- when /\A(?:CAPABILITY)\z/ni
- return capability_response
- else
- return text_response
- end
- else
- parse_error("unexpected token %s", token.symbol)
- end
- end
-
- def response_tagged
- tag = atom
- match(T_SPACE)
- token = match(T_ATOM)
- name = token.value.upcase
- match(T_SPACE)
- return TaggedResponse.new(tag, name, resp_text, @str)
- end
-
- def response_cond
- token = match(T_ATOM)
- name = token.value.upcase
- match(T_SPACE)
- return UntaggedResponse.new(name, resp_text, @str)
- end
-
- def numeric_response
- n = number
- match(T_SPACE)
- token = match(T_ATOM)
- name = token.value.upcase
- case name
- when "EXISTS", "RECENT", "EXPUNGE"
- return UntaggedResponse.new(name, n, @str)
- when "FETCH"
- shift_token
- match(T_SPACE)
- data = FetchData.new(n, msg_att(n))
- return UntaggedResponse.new(name, data, @str)
- end
- end
-
- def msg_att(n)
- match(T_LPAR)
- attr = {}
- while true
- token = lookahead
- case token.symbol
- when T_RPAR
- shift_token
- break
- when T_SPACE
- shift_token
- next
- end
- case token.value
- when /\A(?:ENVELOPE)\z/ni
- name, val = envelope_data
- when /\A(?:FLAGS)\z/ni
- name, val = flags_data
- when /\A(?:INTERNALDATE)\z/ni
- name, val = internaldate_data
- when /\A(?:RFC822(?:\.HEADER|\.TEXT)?)\z/ni
- name, val = rfc822_text
- when /\A(?:RFC822\.SIZE)\z/ni
- name, val = rfc822_size
- when /\A(?:BODY(?:STRUCTURE)?)\z/ni
- name, val = body_data
- when /\A(?:UID)\z/ni
- name, val = uid_data
- else
- parse_error("unknown attribute `%s' for {%d}", token.value, n)
- end
- attr[name] = val
- end
- return attr
- end
-
- def envelope_data
- token = match(T_ATOM)
- name = token.value.upcase
- match(T_SPACE)
- return name, envelope
- end
-
- def envelope
- @lex_state = EXPR_DATA
- token = lookahead
- if token.symbol == T_NIL
- shift_token
- result = nil
- else
- match(T_LPAR)
- date = nstring
- match(T_SPACE)
- subject = nstring
- match(T_SPACE)
- from = address_list
- match(T_SPACE)
- sender = address_list
- match(T_SPACE)
- reply_to = address_list
- match(T_SPACE)
- to = address_list
- match(T_SPACE)
- cc = address_list
- match(T_SPACE)
- bcc = address_list
- match(T_SPACE)
- in_reply_to = nstring
- match(T_SPACE)
- message_id = nstring
- match(T_RPAR)
- result = Envelope.new(date, subject, from, sender, reply_to,
- to, cc, bcc, in_reply_to, message_id)
- end
- @lex_state = EXPR_BEG
- return result
- end
-
- def flags_data
- token = match(T_ATOM)
- name = token.value.upcase
- match(T_SPACE)
- return name, flag_list
- end
-
- def internaldate_data
- token = match(T_ATOM)
- name = token.value.upcase
- match(T_SPACE)
- token = match(T_QUOTED)
- return name, token.value
- end
-
- def rfc822_text
- token = match(T_ATOM)
- name = token.value.upcase
- token = lookahead
- if token.symbol == T_LBRA
- shift_token
- match(T_RBRA)
- end
- match(T_SPACE)
- return name, nstring
- end
-
- def rfc822_size
- token = match(T_ATOM)
- name = token.value.upcase
- match(T_SPACE)
- return name, number
- end
-
- def body_data
- token = match(T_ATOM)
- name = token.value.upcase
- token = lookahead
- if token.symbol == T_SPACE
- shift_token
- return name, body
- end
- name.concat(section)
- token = lookahead
- if token.symbol == T_ATOM
- name.concat(token.value)
- shift_token
- end
- match(T_SPACE)
- data = nstring
- return name, data
- end
-
- def body
- @lex_state = EXPR_DATA
- token = lookahead
- if token.symbol == T_NIL
- shift_token
- result = nil
- else
- match(T_LPAR)
- token = lookahead
- if token.symbol == T_LPAR
- result = body_type_mpart
- else
- result = body_type_1part
- end
- match(T_RPAR)
- end
- @lex_state = EXPR_BEG
- return result
- end
-
- def body_type_1part
- token = lookahead
- case token.value
- when /\A(?:TEXT)\z/ni
- return body_type_text
- when /\A(?:MESSAGE)\z/ni
- return body_type_msg
- when /\A(?:ATTACHMENT)\z/ni
- return body_type_attachment
- when /\A(?:MIXED)\z/ni
- return body_type_mixed
- else
- return body_type_basic
- end
- end
-
- def body_type_basic
- mtype, msubtype = media_type
- token = lookahead
- if token.symbol == T_RPAR
- return BodyTypeBasic.new(mtype, msubtype)
- end
- match(T_SPACE)
- param, content_id, desc, enc, size = body_fields
- md5, disposition, language, extension = body_ext_1part
- return BodyTypeBasic.new(mtype, msubtype,
- param, content_id,
- desc, enc, size,
- md5, disposition, language, extension)
- end
-
- def body_type_text
- mtype, msubtype = media_type
- match(T_SPACE)
- param, content_id, desc, enc, size = body_fields
- match(T_SPACE)
- lines = number
- md5, disposition, language, extension = body_ext_1part
- return BodyTypeText.new(mtype, msubtype,
- param, content_id,
- desc, enc, size,
- lines,
- md5, disposition, language, extension)
- end
-
- def body_type_msg
- mtype, msubtype = media_type
- match(T_SPACE)
- param, content_id, desc, enc, size = body_fields
-
- token = lookahead
- if token.symbol == T_RPAR
- # If this is not message/rfc822, we shouldn't apply the RFC822
- # spec to it. We should handle anything other than
- # message/rfc822 using multipart extension data [rfc3501] (i.e.
- # the data itself won't be returned, we would have to retrieve it
- # with BODYSTRUCTURE instead of with BODY
-
- # Also, sometimes a message/rfc822 is included as a large
- # attachment instead of having all of the other details
- # (e.g. attaching a .eml file to an email)
- if msubtype == "RFC822"
- return BodyTypeMessage.new(mtype, msubtype, param, content_id,
- desc, enc, size, nil, nil, nil, nil,
- nil, nil, nil)
- else
- return BodyTypeExtension.new(mtype, msubtype,
- param, content_id,
- desc, enc, size)
- end
- end
-
- match(T_SPACE)
- env = envelope
- match(T_SPACE)
- b = body
- match(T_SPACE)
- lines = number
- md5, disposition, language, extension = body_ext_1part
- return BodyTypeMessage.new(mtype, msubtype,
- param, content_id,
- desc, enc, size,
- env, b, lines,
- md5, disposition, language, extension)
- end
-
- def body_type_attachment
- mtype = case_insensitive_string
- match(T_SPACE)
- param = body_fld_param
- return BodyTypeAttachment.new(mtype, nil, param)
- end
-
- def body_type_mixed
- mtype = "MULTIPART"
- msubtype = case_insensitive_string
- param, disposition, language, extension = body_ext_mpart
- return BodyTypeBasic.new(mtype, msubtype, param, nil, nil, nil, nil, nil, disposition, language, extension)
- end
-
- def body_type_mpart
- parts = []
- while true
- token = lookahead
- if token.symbol == T_SPACE
- shift_token
- break
- end
- parts.push(body)
- end
- mtype = "MULTIPART"
- msubtype = case_insensitive_string
- param, disposition, language, extension = body_ext_mpart
- return BodyTypeMultipart.new(mtype, msubtype, parts,
- param, disposition, language,
- extension)
- end
-
- def media_type
- mtype = case_insensitive_string
- token = lookahead
- if token.symbol != T_SPACE
- return mtype, nil
- end
- match(T_SPACE)
- msubtype = case_insensitive_string
- return mtype, msubtype
- end
-
- def body_fields
- param = body_fld_param
- match(T_SPACE)
- content_id = nstring
- match(T_SPACE)
- desc = nstring
- match(T_SPACE)
- enc = case_insensitive_string
- match(T_SPACE)
- size = number
- return param, content_id, desc, enc, size
- end
-
- def body_fld_param
- token = lookahead
- if token.symbol == T_NIL
- shift_token
- return nil
- end
- match(T_LPAR)
- param = {}
- while true
- token = lookahead
- case token.symbol
- when T_RPAR
- shift_token
- break
- when T_SPACE
- shift_token
- end
- name = case_insensitive_string
- match(T_SPACE)
- val = string
- param[name] = val
- end
- return param
- end
-
- def body_ext_1part
- token = lookahead
- if token.symbol == T_SPACE
- shift_token
- else
- return nil
- end
- md5 = nstring
-
- token = lookahead
- if token.symbol == T_SPACE
- shift_token
- else
- return md5
- end
- disposition = body_fld_dsp
-
- token = lookahead
- if token.symbol == T_SPACE
- shift_token
- else
- return md5, disposition
- end
- language = body_fld_lang
-
- token = lookahead
- if token.symbol == T_SPACE
- shift_token
- else
- return md5, disposition, language
- end
-
- extension = body_extensions
- return md5, disposition, language, extension
- end
-
- def body_ext_mpart
- token = lookahead
- if token.symbol == T_SPACE
- shift_token
- else
- return nil
- end
- param = body_fld_param
-
- token = lookahead
- if token.symbol == T_SPACE
- shift_token
- else
- return param
- end
- disposition = body_fld_dsp
-
- token = lookahead
- if token.symbol == T_SPACE
- shift_token
- else
- return param, disposition
- end
- language = body_fld_lang
-
- token = lookahead
- if token.symbol == T_SPACE
- shift_token
- else
- return param, disposition, language
- end
-
- extension = body_extensions
- return param, disposition, language, extension
- end
-
- def body_fld_dsp
- token = lookahead
- if token.symbol == T_NIL
- shift_token
- return nil
- end
- match(T_LPAR)
- dsp_type = case_insensitive_string
- match(T_SPACE)
- param = body_fld_param
- match(T_RPAR)
- return ContentDisposition.new(dsp_type, param)
- end
-
- def body_fld_lang
- token = lookahead
- if token.symbol == T_LPAR
- shift_token
- result = []
- while true
- token = lookahead
- case token.symbol
- when T_RPAR
- shift_token
- return result
- when T_SPACE
- shift_token
- end
- result.push(case_insensitive_string)
- end
- else
- lang = nstring
- if lang
- return lang.upcase
- else
- return lang
- end
- end
- end
-
- def body_extensions
- result = []
- while true
- token = lookahead
- case token.symbol
- when T_RPAR
- return result
- when T_SPACE
- shift_token
- end
- result.push(body_extension)
- end
- end
-
- def body_extension
- token = lookahead
- case token.symbol
- when T_LPAR
- shift_token
- result = body_extensions
- match(T_RPAR)
- return result
- when T_NUMBER
- return number
- else
- return nstring
- end
- end
-
- def section
- str = ""
- token = match(T_LBRA)
- str.concat(token.value)
- token = match(T_ATOM, T_NUMBER, T_RBRA)
- if token.symbol == T_RBRA
- str.concat(token.value)
- return str
- end
- str.concat(token.value)
- token = lookahead
- if token.symbol == T_SPACE
- shift_token
- str.concat(token.value)
- token = match(T_LPAR)
- str.concat(token.value)
- while true
- token = lookahead
- case token.symbol
- when T_RPAR
- str.concat(token.value)
- shift_token
- break
- when T_SPACE
- shift_token
- str.concat(token.value)
- end
- str.concat(format_string(astring))
- end
- end
- token = match(T_RBRA)
- str.concat(token.value)
- return str
- end
-
- def format_string(str)
- case str
- when ""
- return '""'
- when /[\x80-\xff\r\n]/n
- # literal
- return "{" + str.bytesize.to_s + "}" + CRLF + str
- when /[(){ \x00-\x1f\x7f%*"\\]/n
- # quoted string
- return '"' + str.gsub(/["\\]/n, "\\\\\\&") + '"'
- else
- # atom
- return str
- end
- end
-
- def uid_data
- token = match(T_ATOM)
- name = token.value.upcase
- match(T_SPACE)
- return name, number
- end
-
- def text_response
- token = match(T_ATOM)
- name = token.value.upcase
- match(T_SPACE)
- @lex_state = EXPR_TEXT
- token = match(T_TEXT)
- @lex_state = EXPR_BEG
- return UntaggedResponse.new(name, token.value)
- end
-
- def flags_response
- token = match(T_ATOM)
- name = token.value.upcase
- match(T_SPACE)
- return UntaggedResponse.new(name, flag_list, @str)
- end
-
- def list_response
- token = match(T_ATOM)
- name = token.value.upcase
- match(T_SPACE)
- return UntaggedResponse.new(name, mailbox_list, @str)
- end
-
- def mailbox_list
- attr = flag_list
- match(T_SPACE)
- token = match(T_QUOTED, T_NIL)
- if token.symbol == T_NIL
- delim = nil
- else
- delim = token.value
- end
- match(T_SPACE)
- name = astring
- return MailboxList.new(attr, delim, name)
- end
-
- def getquota_response
- # If quota never established, get back
- # `NO Quota root does not exist'.
- # If quota removed, get `()' after the
- # folder spec with no mention of `STORAGE'.
- token = match(T_ATOM)
- name = token.value.upcase
- match(T_SPACE)
- mailbox = astring
- match(T_SPACE)
- match(T_LPAR)
- token = lookahead
- case token.symbol
- when T_RPAR
- shift_token
- data = MailboxQuota.new(mailbox, nil, nil)
- return UntaggedResponse.new(name, data, @str)
- when T_ATOM
- shift_token
- match(T_SPACE)
- token = match(T_NUMBER)
- usage = token.value
- match(T_SPACE)
- token = match(T_NUMBER)
- quota = token.value
- match(T_RPAR)
- data = MailboxQuota.new(mailbox, usage, quota)
- return UntaggedResponse.new(name, data, @str)
- else
- parse_error("unexpected token %s", token.symbol)
- end
- end
-
- def getquotaroot_response
- # Similar to getquota, but only admin can use getquota.
- token = match(T_ATOM)
- name = token.value.upcase
- match(T_SPACE)
- mailbox = astring
- quotaroots = []
- while true
- token = lookahead
- break unless token.symbol == T_SPACE
- shift_token
- quotaroots.push(astring)
- end
- data = MailboxQuotaRoot.new(mailbox, quotaroots)
- return UntaggedResponse.new(name, data, @str)
- end
-
- def getacl_response
- token = match(T_ATOM)
- name = token.value.upcase
- match(T_SPACE)
- mailbox = astring
- data = []
- token = lookahead
- if token.symbol == T_SPACE
- shift_token
- while true
- token = lookahead
- case token.symbol
- when T_CRLF
- break
- when T_SPACE
- shift_token
- end
- user = astring
- match(T_SPACE)
- rights = astring
- data.push(MailboxACLItem.new(user, rights, mailbox))
- end
- end
- return UntaggedResponse.new(name, data, @str)
- end
-
- def search_response
- token = match(T_ATOM)
- name = token.value.upcase
- token = lookahead
- if token.symbol == T_SPACE
- shift_token
- data = []
- while true
- token = lookahead
- case token.symbol
- when T_CRLF
- break
- when T_SPACE
- shift_token
- when T_NUMBER
- data.push(number)
- when T_LPAR
- # TODO: include the MODSEQ value in a response
- shift_token
- match(T_ATOM)
- match(T_SPACE)
- match(T_NUMBER)
- match(T_RPAR)
- end
- end
- else
- data = []
- end
- return UntaggedResponse.new(name, data, @str)
- end
-
- def thread_response
- token = match(T_ATOM)
- name = token.value.upcase
- token = lookahead
-
- if token.symbol == T_SPACE
- threads = []
-
- while true
- shift_token
- token = lookahead
-
- case token.symbol
- when T_LPAR
- threads << thread_branch(token)
- when T_CRLF
- break
- end
- end
- else
- # no member
- threads = []
- end
-
- return UntaggedResponse.new(name, threads, @str)
- end
-
- def thread_branch(token)
- rootmember = nil
- lastmember = nil
-
- while true
- shift_token # ignore first T_LPAR
- token = lookahead
-
- case token.symbol
- when T_NUMBER
- # new member
- newmember = ThreadMember.new(number, [])
- if rootmember.nil?
- rootmember = newmember
- else
- lastmember.children << newmember
- end
- lastmember = newmember
- when T_SPACE
- # do nothing
- when T_LPAR
- if rootmember.nil?
- # dummy member
- lastmember = rootmember = ThreadMember.new(nil, [])
- end
-
- lastmember.children << thread_branch(token)
- when T_RPAR
- break
- end
- end
-
- return rootmember
- end
-
- def status_response
- token = match(T_ATOM)
- name = token.value.upcase
- match(T_SPACE)
- mailbox = astring
- match(T_SPACE)
- match(T_LPAR)
- attr = {}
- while true
- token = lookahead
- case token.symbol
- when T_RPAR
- shift_token
- break
- when T_SPACE
- shift_token
- end
- token = match(T_ATOM)
- key = token.value.upcase
- match(T_SPACE)
- val = number
- attr[key] = val
- end
- data = StatusData.new(mailbox, attr)
- return UntaggedResponse.new(name, data, @str)
- end
-
- def capability_response
- token = match(T_ATOM)
- name = token.value.upcase
- match(T_SPACE)
- data = []
- while true
- token = lookahead
- case token.symbol
- when T_CRLF
- break
- when T_SPACE
- shift_token
- next
- end
- data.push(atom.upcase)
- end
- return UntaggedResponse.new(name, data, @str)
- end
-
- def resp_text
- @lex_state = EXPR_RTEXT
- token = lookahead
- if token.symbol == T_LBRA
- code = resp_text_code
- else
- code = nil
- end
- token = match(T_TEXT)
- @lex_state = EXPR_BEG
- return ResponseText.new(code, token.value)
- end
-
- def resp_text_code
- @lex_state = EXPR_BEG
- match(T_LBRA)
- token = match(T_ATOM)
- name = token.value.upcase
- case name
- when /\A(?:ALERT|PARSE|READ-ONLY|READ-WRITE|TRYCREATE|NOMODSEQ)\z/n
- result = ResponseCode.new(name, nil)
- when /\A(?:PERMANENTFLAGS)\z/n
- match(T_SPACE)
- result = ResponseCode.new(name, flag_list)
- when /\A(?:UIDVALIDITY|UIDNEXT|UNSEEN)\z/n
- match(T_SPACE)
- result = ResponseCode.new(name, number)
- else
- token = lookahead
- if token.symbol == T_SPACE
- shift_token
- @lex_state = EXPR_CTEXT
- token = match(T_TEXT)
- @lex_state = EXPR_BEG
- result = ResponseCode.new(name, token.value)
- else
- result = ResponseCode.new(name, nil)
- end
- end
- match(T_RBRA)
- @lex_state = EXPR_RTEXT
- return result
- end
-
- def address_list
- token = lookahead
- if token.symbol == T_NIL
- shift_token
- return nil
- else
- result = []
- match(T_LPAR)
- while true
- token = lookahead
- case token.symbol
- when T_RPAR
- shift_token
- break
- when T_SPACE
- shift_token
- end
- result.push(address)
- end
- return result
- end
- end
-
- ADDRESS_REGEXP = /\G\
-(?# 1: NAME )(?:NIL|"((?:[^\x80-\xff\x00\r\n"\\]|\\["\\])*)") \
-(?# 2: ROUTE )(?:NIL|"((?:[^\x80-\xff\x00\r\n"\\]|\\["\\])*)") \
-(?# 3: MAILBOX )(?:NIL|"((?:[^\x80-\xff\x00\r\n"\\]|\\["\\])*)") \
-(?# 4: HOST )(?:NIL|"((?:[^\x80-\xff\x00\r\n"\\]|\\["\\])*)")\
-\)/ni
-
- def address
- match(T_LPAR)
- if @str.index(ADDRESS_REGEXP, @pos)
- # address does not include literal.
- @pos = $~.end(0)
- name = $1
- route = $2
- mailbox = $3
- host = $4
- for s in [name, route, mailbox, host]
- if s
- s.gsub!(/\\(["\\])/n, "\\1")
- end
- end
- else
- name = nstring
- match(T_SPACE)
- route = nstring
- match(T_SPACE)
- mailbox = nstring
- match(T_SPACE)
- host = nstring
- match(T_RPAR)
- end
- return Address.new(name, route, mailbox, host)
- end
-
- FLAG_REGEXP = /\
-(?# FLAG )\\([^\x80-\xff(){ \x00-\x1f\x7f%"\\]+)|\
-(?# ATOM )([^\x80-\xff(){ \x00-\x1f\x7f%*"\\]+)/n
-
- def flag_list
- if @str.index(/\(([^)]*)\)/ni, @pos)
- @pos = $~.end(0)
- return $1.scan(FLAG_REGEXP).collect { |flag, atom|
- if atom
- atom
- else
- symbol = flag.capitalize.untaint.intern
- @flag_symbols[symbol] = true
- if @flag_symbols.length > IMAP.max_flag_count
- raise FlagCountError, "number of flag symbols exceeded"
- end
- symbol
- end
- }
- else
- parse_error("invalid flag list")
- end
- end
-
- def nstring
- token = lookahead
- if token.symbol == T_NIL
- shift_token
- return nil
- else
- return string
- end
- end
-
- def astring
- token = lookahead
- if string_token?(token)
- return string
- else
- return atom
- end
- end
-
- def string
- token = lookahead
- if token.symbol == T_NIL
- shift_token
- return nil
- end
- token = match(T_QUOTED, T_LITERAL)
- return token.value
- end
-
- STRING_TOKENS = [T_QUOTED, T_LITERAL, T_NIL]
-
- def string_token?(token)
- return STRING_TOKENS.include?(token.symbol)
- end
-
- def case_insensitive_string
- token = lookahead
- if token.symbol == T_NIL
- shift_token
- return nil
- end
- token = match(T_QUOTED, T_LITERAL)
- return token.value.upcase
- end
-
- def atom
- result = ""
- while true
- token = lookahead
- if atom_token?(token)
- result.concat(token.value)
- shift_token
- else
- if result.empty?
- parse_error("unexpected token %s", token.symbol)
- else
- return result
- end
- end
- end
- end
-
- ATOM_TOKENS = [
- T_ATOM,
- T_NUMBER,
- T_NIL,
- T_LBRA,
- T_RBRA,
- T_PLUS
- ]
-
- def atom_token?(token)
- return ATOM_TOKENS.include?(token.symbol)
- end
-
- def number
- token = lookahead
- if token.symbol == T_NIL
- shift_token
- return nil
- end
- token = match(T_NUMBER)
- return token.value.to_i
- end
-
- def nil_atom
- match(T_NIL)
- return nil
- end
-
- def match(*args)
- token = lookahead
- unless args.include?(token.symbol)
- parse_error('unexpected token %s (expected %s)',
- token.symbol.id2name,
- args.collect {|i| i.id2name}.join(" or "))
- end
- shift_token
- return token
- end
-
- def lookahead
- unless @token
- @token = next_token
- end
- return @token
- end
-
- def shift_token
- @token = nil
- end
-
- def next_token
- case @lex_state
- when EXPR_BEG
- if @str.index(BEG_REGEXP, @pos)
- @pos = $~.end(0)
- if $1
- return Token.new(T_SPACE, $+)
- elsif $2
- return Token.new(T_NIL, $+)
- elsif $3
- return Token.new(T_NUMBER, $+)
- elsif $4
- return Token.new(T_ATOM, $+)
- elsif $5
- return Token.new(T_QUOTED,
- $+.gsub(/\\(["\\])/n, "\\1"))
- elsif $6
- return Token.new(T_LPAR, $+)
- elsif $7
- return Token.new(T_RPAR, $+)
- elsif $8
- return Token.new(T_BSLASH, $+)
- elsif $9
- return Token.new(T_STAR, $+)
- elsif $10
- return Token.new(T_LBRA, $+)
- elsif $11
- return Token.new(T_RBRA, $+)
- elsif $12
- len = $+.to_i
- val = @str[@pos, len]
- @pos += len
- return Token.new(T_LITERAL, val)
- elsif $13
- return Token.new(T_PLUS, $+)
- elsif $14
- return Token.new(T_PERCENT, $+)
- elsif $15
- return Token.new(T_CRLF, $+)
- elsif $16
- return Token.new(T_EOF, $+)
- else
- parse_error("[Net::IMAP BUG] BEG_REGEXP is invalid")
- end
- else
- @str.index(/\S*/n, @pos)
- parse_error("unknown token - %s", $&.dump)
- end
- when EXPR_DATA
- if @str.index(DATA_REGEXP, @pos)
- @pos = $~.end(0)
- if $1
- return Token.new(T_SPACE, $+)
- elsif $2
- return Token.new(T_NIL, $+)
- elsif $3
- return Token.new(T_NUMBER, $+)
- elsif $4
- return Token.new(T_QUOTED,
- $+.gsub(/\\(["\\])/n, "\\1"))
- elsif $5
- len = $+.to_i
- val = @str[@pos, len]
- @pos += len
- return Token.new(T_LITERAL, val)
- elsif $6
- return Token.new(T_LPAR, $+)
- elsif $7
- return Token.new(T_RPAR, $+)
- else
- parse_error("[Net::IMAP BUG] DATA_REGEXP is invalid")
- end
- else
- @str.index(/\S*/n, @pos)
- parse_error("unknown token - %s", $&.dump)
- end
- when EXPR_TEXT
- if @str.index(TEXT_REGEXP, @pos)
- @pos = $~.end(0)
- if $1
- return Token.new(T_TEXT, $+)
- else
- parse_error("[Net::IMAP BUG] TEXT_REGEXP is invalid")
- end
- else
- @str.index(/\S*/n, @pos)
- parse_error("unknown token - %s", $&.dump)
- end
- when EXPR_RTEXT
- if @str.index(RTEXT_REGEXP, @pos)
- @pos = $~.end(0)
- if $1
- return Token.new(T_LBRA, $+)
- elsif $2
- return Token.new(T_TEXT, $+)
- else
- parse_error("[Net::IMAP BUG] RTEXT_REGEXP is invalid")
- end
- else
- @str.index(/\S*/n, @pos)
- parse_error("unknown token - %s", $&.dump)
- end
- when EXPR_CTEXT
- if @str.index(CTEXT_REGEXP, @pos)
- @pos = $~.end(0)
- if $1
- return Token.new(T_TEXT, $+)
- else
- parse_error("[Net::IMAP BUG] CTEXT_REGEXP is invalid")
- end
- else
- @str.index(/\S*/n, @pos) #/
- parse_error("unknown token - %s", $&.dump)
- end
- else
- parse_error("invalid @lex_state - %s", @lex_state.inspect)
- end
- end
-
- def parse_error(fmt, *args)
- if IMAP.debug
- $stderr.printf("@str: %s\n", @str.dump)
- $stderr.printf("@pos: %d\n", @pos)
- $stderr.printf("@lex_state: %s\n", @lex_state)
- if @token
- $stderr.printf("@token.symbol: %s\n", @token.symbol)
- $stderr.printf("@token.value: %s\n", @token.value.inspect)
- end
- end
- raise ResponseParseError, format(fmt, *args)
- end
- end
-
- # Authenticator for the "LOGIN" authentication type. See
- # #authenticate().
- class LoginAuthenticator
- def process(data)
- case @state
- when STATE_USER
- @state = STATE_PASSWORD
- return @user
- when STATE_PASSWORD
- return @password
- end
- end
-
- private
-
- STATE_USER = :USER
- STATE_PASSWORD = :PASSWORD
-
- def initialize(user, password)
- @user = user
- @password = password
- @state = STATE_USER
- end
- end
- add_authenticator "LOGIN", LoginAuthenticator
-
- # Authenticator for the "PLAIN" authentication type. See
- # #authenticate().
- class PlainAuthenticator
- def process(data)
- return "\0#{@user}\0#{@password}"
- end
-
- private
-
- def initialize(user, password)
- @user = user
- @password = password
- end
- end
- add_authenticator "PLAIN", PlainAuthenticator
-
- # Authenticator for the "CRAM-MD5" authentication type. See
- # #authenticate().
- class CramMD5Authenticator
- def process(challenge)
- digest = hmac_md5(challenge, @password)
- return @user + " " + digest
- end
-
- private
-
- def initialize(user, password)
- @user = user
- @password = password
- end
-
- def hmac_md5(text, key)
- if key.length > 64
- key = Digest::MD5.digest(key)
- end
-
- k_ipad = key + "\0" * (64 - key.length)
- k_opad = key + "\0" * (64 - key.length)
- for i in 0..63
- k_ipad[i] = (k_ipad[i].ord ^ 0x36).chr
- k_opad[i] = (k_opad[i].ord ^ 0x5c).chr
- end
-
- digest = Digest::MD5.digest(k_ipad + text)
-
- return Digest::MD5.hexdigest(k_opad + digest)
- end
- end
- add_authenticator "CRAM-MD5", CramMD5Authenticator
-
- # Authenticator for the "DIGEST-MD5" authentication type. See
- # #authenticate().
- class DigestMD5Authenticator
- def process(challenge)
- case @stage
- when STAGE_ONE
- @stage = STAGE_TWO
- sparams = {}
- c = StringScanner.new(challenge)
- while c.scan(/(?:\s*,)?\s*(\w+)=("(?:[^\\"]+|\\.)*"|[^,]+)\s*/)
- k, v = c[1], c[2]
- if v =~ /^"(.*)"$/
- v = $1
- if v =~ /,/
- v = v.split(',')
- end
- end
- sparams[k] = v
- end
-
- raise DataFormatError, "Bad Challenge: '#{challenge}'" unless c.rest.size == 0
- raise Error, "Server does not support auth (qop = #{sparams['qop'].join(',')})" unless sparams['qop'].include?("auth")
-
- response = {
- :nonce => sparams['nonce'],
- :username => @user,
- :realm => sparams['realm'],
- :cnonce => Digest::MD5.hexdigest("%.15f:%.15f:%d" % [Time.now.to_f, rand, Process.pid.to_s]),
- :'digest-uri' => 'imap/' + sparams['realm'],
- :qop => 'auth',
- :maxbuf => 65535,
- :nc => "%08d" % nc(sparams['nonce']),
- :charset => sparams['charset'],
- }
-
- response[:authzid] = @authname unless @authname.nil?
-
- # now, the real thing
- a0 = Digest::MD5.digest( [ response.values_at(:username, :realm), @password ].join(':') )
-
- a1 = [ a0, response.values_at(:nonce,:cnonce) ].join(':')
- a1 << ':' + response[:authzid] unless response[:authzid].nil?
-
- a2 = "AUTHENTICATE:" + response[:'digest-uri']
- a2 << ":00000000000000000000000000000000" if response[:qop] and response[:qop] =~ /^auth-(?:conf|int)$/
-
- response[:response] = Digest::MD5.hexdigest(
- [
- Digest::MD5.hexdigest(a1),
- response.values_at(:nonce, :nc, :cnonce, :qop),
- Digest::MD5.hexdigest(a2)
- ].join(':')
- )
-
- return response.keys.map {|key| qdval(key.to_s, response[key]) }.join(',')
- when STAGE_TWO
- @stage = nil
- # if at the second stage, return an empty string
- if challenge =~ /rspauth=/
- return ''
- else
- raise ResponseParseError, challenge
- end
- else
- raise ResponseParseError, challenge
- end
- end
-
- def initialize(user, password, authname = nil)
- @user, @password, @authname = user, password, authname
- @nc, @stage = {}, STAGE_ONE
- end
-
- private
-
- STAGE_ONE = :stage_one
- STAGE_TWO = :stage_two
-
- def nc(nonce)
- if @nc.has_key? nonce
- @nc[nonce] = @nc[nonce] + 1
- else
- @nc[nonce] = 1
- end
- return @nc[nonce]
- end
-
- # some responses need quoting
- def qdval(k, v)
- return if k.nil? or v.nil?
- if %w"username authzid realm nonce cnonce digest-uri qop".include? k
- v.gsub!(/([\\"])/, "\\\1")
- return '%s="%s"' % [k, v]
- else
- return '%s=%s' % [k, v]
- end
- end
- end
- add_authenticator "DIGEST-MD5", DigestMD5Authenticator
-
- # Superclass of IMAP errors.
- class Error < StandardError
- end
-
- # Error raised when data is in the incorrect format.
- class DataFormatError < Error
- end
-
- # Error raised when a response from the server is non-parseable.
- class ResponseParseError < Error
- end
-
- # Superclass of all errors used to encapsulate "fail" responses
- # from the server.
- class ResponseError < Error
-
- # The response that caused this error
- attr_accessor :response
-
- def initialize(response)
- @response = response
-
- super @response.data.text
- end
-
- end
-
- # Error raised upon a "NO" response from the server, indicating
- # that the client command could not be completed successfully.
- class NoResponseError < ResponseError
- end
-
- # Error raised upon a "BAD" response from the server, indicating
- # that the client command violated the IMAP protocol, or an internal
- # server failure has occurred.
- class BadResponseError < ResponseError
- end
-
- # Error raised upon a "BYE" response from the server, indicating
- # that the client is not being allowed to login, or has been timed
- # out due to inactivity.
- class ByeResponseError < ResponseError
- end
-
- # Error raised when too many flags are interned to symbols.
- class FlagCountError < Error
- end
- end
-end
diff --git a/ruby_2_2/lib/net/pop.rb b/ruby_2_2/lib/net/pop.rb
deleted file mode 100644
index db7192c95a..0000000000
--- a/ruby_2_2/lib/net/pop.rb
+++ /dev/null
@@ -1,1021 +0,0 @@
-# = net/pop.rb
-#
-# Copyright (c) 1999-2007 Yukihiro Matsumoto.
-#
-# Copyright (c) 1999-2007 Minero Aoki.
-#
-# Written & maintained by Minero Aoki <aamine@loveruby.net>.
-#
-# Documented by William Webber and Minero Aoki.
-#
-# This program is free software. You can re-distribute and/or
-# modify this program under the same terms as Ruby itself,
-# Ruby Distribute License.
-#
-# NOTE: You can find Japanese version of this document at:
-# http://www.ruby-lang.org/ja/man/html/net_pop.html
-#
-# $Id$
-#
-# See Net::POP3 for documentation.
-#
-
-require 'net/protocol'
-require 'digest/md5'
-require 'timeout'
-
-begin
- require "openssl"
-rescue LoadError
-end
-
-module Net
-
- # Non-authentication POP3 protocol error
- # (reply code "-ERR", except authentication).
- class POPError < ProtocolError; end
-
- # POP3 authentication error.
- class POPAuthenticationError < ProtoAuthError; end
-
- # Unexpected response from the server.
- class POPBadResponse < POPError; end
-
- #
- # == What is This Library?
- #
- # This library provides functionality for retrieving
- # email via POP3, the Post Office Protocol version 3. For details
- # of POP3, see [RFC1939] (http://www.ietf.org/rfc/rfc1939.txt).
- #
- # == Examples
- #
- # === Retrieving Messages
- #
- # This example retrieves messages from the server and deletes them
- # on the server.
- #
- # Messages are written to files named 'inbox/1', 'inbox/2', ....
- # Replace 'pop.example.com' with your POP3 server address, and
- # 'YourAccount' and 'YourPassword' with the appropriate account
- # details.
- #
- # require 'net/pop'
- #
- # pop = Net::POP3.new('pop.example.com')
- # pop.start('YourAccount', 'YourPassword') # (1)
- # if pop.mails.empty?
- # puts 'No mail.'
- # else
- # i = 0
- # pop.each_mail do |m| # or "pop.mails.each ..." # (2)
- # File.open("inbox/#{i}", 'w') do |f|
- # f.write m.pop
- # end
- # m.delete
- # i += 1
- # end
- # puts "#{pop.mails.size} mails popped."
- # end
- # pop.finish # (3)
- #
- # 1. Call Net::POP3#start and start POP session.
- # 2. Access messages by using POP3#each_mail and/or POP3#mails.
- # 3. Close POP session by calling POP3#finish or use the block form of #start.
- #
- # === Shortened Code
- #
- # The example above is very verbose. You can shorten the code by using
- # some utility methods. First, the block form of Net::POP3.start can
- # be used instead of POP3.new, POP3#start and POP3#finish.
- #
- # require 'net/pop'
- #
- # Net::POP3.start('pop.example.com', 110,
- # 'YourAccount', 'YourPassword') do |pop|
- # if pop.mails.empty?
- # puts 'No mail.'
- # else
- # i = 0
- # pop.each_mail do |m| # or "pop.mails.each ..."
- # File.open("inbox/#{i}", 'w') do |f|
- # f.write m.pop
- # end
- # m.delete
- # i += 1
- # end
- # puts "#{pop.mails.size} mails popped."
- # end
- # end
- #
- # POP3#delete_all is an alternative for #each_mail and #delete.
- #
- # require 'net/pop'
- #
- # Net::POP3.start('pop.example.com', 110,
- # 'YourAccount', 'YourPassword') do |pop|
- # if pop.mails.empty?
- # puts 'No mail.'
- # else
- # i = 1
- # pop.delete_all do |m|
- # File.open("inbox/#{i}", 'w') do |f|
- # f.write m.pop
- # end
- # i += 1
- # end
- # end
- # end
- #
- # And here is an even shorter example.
- #
- # require 'net/pop'
- #
- # i = 0
- # Net::POP3.delete_all('pop.example.com', 110,
- # 'YourAccount', 'YourPassword') do |m|
- # File.open("inbox/#{i}", 'w') do |f|
- # f.write m.pop
- # end
- # i += 1
- # end
- #
- # === Memory Space Issues
- #
- # All the examples above get each message as one big string.
- # This example avoids this.
- #
- # require 'net/pop'
- #
- # i = 1
- # Net::POP3.delete_all('pop.example.com', 110,
- # 'YourAccount', 'YourPassword') do |m|
- # File.open("inbox/#{i}", 'w') do |f|
- # m.pop do |chunk| # get a message little by little.
- # f.write chunk
- # end
- # i += 1
- # end
- # end
- #
- # === Using APOP
- #
- # The net/pop library supports APOP authentication.
- # To use APOP, use the Net::APOP class instead of the Net::POP3 class.
- # You can use the utility method, Net::POP3.APOP(). For example:
- #
- # require 'net/pop'
- #
- # # Use APOP authentication if $isapop == true
- # pop = Net::POP3.APOP($is_apop).new('apop.example.com', 110)
- # pop.start(YourAccount', 'YourPassword') do |pop|
- # # Rest of the code is the same.
- # end
- #
- # === Fetch Only Selected Mail Using 'UIDL' POP Command
- #
- # If your POP server provides UIDL functionality,
- # you can grab only selected mails from the POP server.
- # e.g.
- #
- # def need_pop?( id )
- # # determine if we need pop this mail...
- # end
- #
- # Net::POP3.start('pop.example.com', 110,
- # 'Your account', 'Your password') do |pop|
- # pop.mails.select { |m| need_pop?(m.unique_id) }.each do |m|
- # do_something(m.pop)
- # end
- # end
- #
- # The POPMail#unique_id() method returns the unique-id of the message as a
- # String. Normally the unique-id is a hash of the message.
- #
- class POP3 < Protocol
-
- # svn revision of this library
- Revision = %q$Revision$.split[1]
-
- #
- # Class Parameters
- #
-
- # returns the port for POP3
- def POP3.default_port
- default_pop3_port()
- end
-
- # The default port for POP3 connections, port 110
- def POP3.default_pop3_port
- 110
- end
-
- # The default port for POP3S connections, port 995
- def POP3.default_pop3s_port
- 995
- end
-
- def POP3.socket_type #:nodoc: obsolete
- Net::InternetMessageIO
- end
-
- #
- # Utilities
- #
-
- # Returns the APOP class if +isapop+ is true; otherwise, returns
- # the POP class. For example:
- #
- # # Example 1
- # pop = Net::POP3::APOP($is_apop).new(addr, port)
- #
- # # Example 2
- # Net::POP3::APOP($is_apop).start(addr, port) do |pop|
- # ....
- # end
- #
- def POP3.APOP(isapop)
- isapop ? APOP : POP3
- end
-
- # Starts a POP3 session and iterates over each POPMail object,
- # yielding it to the +block+.
- # This method is equivalent to:
- #
- # Net::POP3.start(address, port, account, password) do |pop|
- # pop.each_mail do |m|
- # yield m
- # end
- # end
- #
- # This method raises a POPAuthenticationError if authentication fails.
- #
- # === Example
- #
- # Net::POP3.foreach('pop.example.com', 110,
- # 'YourAccount', 'YourPassword') do |m|
- # file.write m.pop
- # m.delete if $DELETE
- # end
- #
- def POP3.foreach(address, port = nil,
- account = nil, password = nil,
- isapop = false, &block) # :yields: message
- start(address, port, account, password, isapop) {|pop|
- pop.each_mail(&block)
- }
- end
-
- # Starts a POP3 session and deletes all messages on the server.
- # If a block is given, each POPMail object is yielded to it before
- # being deleted.
- #
- # This method raises a POPAuthenticationError if authentication fails.
- #
- # === Example
- #
- # Net::POP3.delete_all('pop.example.com', 110,
- # 'YourAccount', 'YourPassword') do |m|
- # file.write m.pop
- # end
- #
- def POP3.delete_all(address, port = nil,
- account = nil, password = nil,
- isapop = false, &block)
- start(address, port, account, password, isapop) {|pop|
- pop.delete_all(&block)
- }
- end
-
- # Opens a POP3 session, attempts authentication, and quits.
- #
- # This method raises POPAuthenticationError if authentication fails.
- #
- # === Example: normal POP3
- #
- # Net::POP3.auth_only('pop.example.com', 110,
- # 'YourAccount', 'YourPassword')
- #
- # === Example: APOP
- #
- # Net::POP3.auth_only('pop.example.com', 110,
- # 'YourAccount', 'YourPassword', true)
- #
- def POP3.auth_only(address, port = nil,
- account = nil, password = nil,
- isapop = false)
- new(address, port, isapop).auth_only account, password
- end
-
- # Starts a pop3 session, attempts authentication, and quits.
- # This method must not be called while POP3 session is opened.
- # This method raises POPAuthenticationError if authentication fails.
- def auth_only(account, password)
- raise IOError, 'opening previously opened POP session' if started?
- start(account, password) {
- ;
- }
- end
-
- #
- # SSL
- #
-
- @ssl_params = nil
-
- # :call-seq:
- # Net::POP.enable_ssl(params = {})
- #
- # Enable SSL for all new instances.
- # +params+ is passed to OpenSSL::SSLContext#set_params.
- def POP3.enable_ssl(*args)
- @ssl_params = create_ssl_params(*args)
- end
-
- # Constructs proper parameters from arguments
- def POP3.create_ssl_params(verify_or_params = {}, certs = nil)
- begin
- params = verify_or_params.to_hash
- rescue NoMethodError
- params = {}
- params[:verify_mode] = verify_or_params
- if certs
- if File.file?(certs)
- params[:ca_file] = certs
- elsif File.directory?(certs)
- params[:ca_path] = certs
- end
- end
- end
- return params
- end
-
- # Disable SSL for all new instances.
- def POP3.disable_ssl
- @ssl_params = nil
- end
-
- # returns the SSL Parameters
- #
- # see also POP3.enable_ssl
- def POP3.ssl_params
- return @ssl_params
- end
-
- # returns +true+ if POP3.ssl_params is set
- def POP3.use_ssl?
- return !@ssl_params.nil?
- end
-
- # returns whether verify_mode is enable from POP3.ssl_params
- def POP3.verify
- return @ssl_params[:verify_mode]
- end
-
- # returns the :ca_file or :ca_path from POP3.ssl_params
- def POP3.certs
- return @ssl_params[:ca_file] || @ssl_params[:ca_path]
- end
-
- #
- # Session management
- #
-
- # Creates a new POP3 object and open the connection. Equivalent to
- #
- # Net::POP3.new(address, port, isapop).start(account, password)
- #
- # If +block+ is provided, yields the newly-opened POP3 object to it,
- # and automatically closes it at the end of the session.
- #
- # === Example
- #
- # Net::POP3.start(addr, port, account, password) do |pop|
- # pop.each_mail do |m|
- # file.write m.pop
- # m.delete
- # end
- # end
- #
- def POP3.start(address, port = nil,
- account = nil, password = nil,
- isapop = false, &block) # :yield: pop
- new(address, port, isapop).start(account, password, &block)
- end
-
- # Creates a new POP3 object.
- #
- # +address+ is the hostname or ip address of your POP3 server.
- #
- # The optional +port+ is the port to connect to.
- #
- # The optional +isapop+ specifies whether this connection is going
- # to use APOP authentication; it defaults to +false+.
- #
- # This method does *not* open the TCP connection.
- def initialize(addr, port = nil, isapop = false)
- @address = addr
- @ssl_params = POP3.ssl_params
- @port = port
- @apop = isapop
-
- @command = nil
- @socket = nil
- @started = false
- @open_timeout = 30
- @read_timeout = 60
- @debug_output = nil
-
- @mails = nil
- @n_mails = nil
- @n_bytes = nil
- end
-
- # Does this instance use APOP authentication?
- def apop?
- @apop
- end
-
- # does this instance use SSL?
- def use_ssl?
- return !@ssl_params.nil?
- end
-
- # :call-seq:
- # Net::POP#enable_ssl(params = {})
- #
- # Enables SSL for this instance. Must be called before the connection is
- # established to have any effect.
- # +params[:port]+ is port to establish the SSL connection on; Defaults to 995.
- # +params+ (except :port) is passed to OpenSSL::SSLContext#set_params.
- def enable_ssl(verify_or_params = {}, certs = nil, port = nil)
- begin
- @ssl_params = verify_or_params.to_hash.dup
- @port = @ssl_params.delete(:port) || @port
- rescue NoMethodError
- @ssl_params = POP3.create_ssl_params(verify_or_params, certs)
- @port = port || @port
- end
- end
-
- # Disable SSL for all new instances.
- def disable_ssl
- @ssl_params = nil
- end
-
- # Provide human-readable stringification of class state.
- def inspect
- "#<#{self.class} #{@address}:#{@port} open=#{@started}>"
- end
-
- # *WARNING*: This method causes a serious security hole.
- # Use this method only for debugging.
- #
- # Set an output stream for debugging.
- #
- # === Example
- #
- # pop = Net::POP.new(addr, port)
- # pop.set_debug_output $stderr
- # pop.start(account, passwd) do |pop|
- # ....
- # end
- #
- def set_debug_output(arg)
- @debug_output = arg
- end
-
- # The address to connect to.
- attr_reader :address
-
- # The port number to connect to.
- def port
- return @port || (use_ssl? ? POP3.default_pop3s_port : POP3.default_pop3_port)
- end
-
- # Seconds to wait until a connection is opened.
- # If the POP3 object cannot open a connection within this time,
- # it raises a Net::OpenTimeout exception. The default value is 30 seconds.
- attr_accessor :open_timeout
-
- # Seconds to wait until reading one block (by one read(1) call).
- # If the POP3 object cannot complete a read() within this time,
- # it raises a Net::ReadTimeout exception. The default value is 60 seconds.
- attr_reader :read_timeout
-
- # Set the read timeout.
- def read_timeout=(sec)
- @command.socket.read_timeout = sec if @command
- @read_timeout = sec
- end
-
- # +true+ if the POP3 session has started.
- def started?
- @started
- end
-
- alias active? started? #:nodoc: obsolete
-
- # Starts a POP3 session.
- #
- # When called with block, gives a POP3 object to the block and
- # closes the session after block call finishes.
- #
- # This method raises a POPAuthenticationError if authentication fails.
- def start(account, password) # :yield: pop
- raise IOError, 'POP session already started' if @started
- if block_given?
- begin
- do_start account, password
- return yield(self)
- ensure
- do_finish
- end
- else
- do_start account, password
- return self
- end
- end
-
- # internal method for Net::POP3.start
- def do_start(account, password) # :nodoc:
- s = Timeout.timeout(@open_timeout, Net::OpenTimeout) do
- TCPSocket.open(@address, port)
- end
- if use_ssl?
- raise 'openssl library not installed' unless defined?(OpenSSL)
- context = OpenSSL::SSL::SSLContext.new
- context.set_params(@ssl_params)
- s = OpenSSL::SSL::SSLSocket.new(s, context)
- s.sync_close = true
- s.connect
- if context.verify_mode != OpenSSL::SSL::VERIFY_NONE
- s.post_connection_check(@address)
- end
- end
- @socket = InternetMessageIO.new(s)
- logging "POP session started: #{@address}:#{@port} (#{@apop ? 'APOP' : 'POP'})"
- @socket.read_timeout = @read_timeout
- @socket.debug_output = @debug_output
- on_connect
- @command = POP3Command.new(@socket)
- if apop?
- @command.apop account, password
- else
- @command.auth account, password
- end
- @started = true
- ensure
- # Authentication failed, clean up connection.
- unless @started
- s.close if s and not s.closed?
- @socket = nil
- @command = nil
- end
- end
- private :do_start
-
- # Does nothing
- def on_connect # :nodoc:
- end
- private :on_connect
-
- # Finishes a POP3 session and closes TCP connection.
- def finish
- raise IOError, 'POP session not yet started' unless started?
- do_finish
- end
-
- # nil's out the:
- # - mails
- # - number counter for mails
- # - number counter for bytes
- # - quits the current command, if any
- def do_finish # :nodoc:
- @mails = nil
- @n_mails = nil
- @n_bytes = nil
- @command.quit if @command
- ensure
- @started = false
- @command = nil
- @socket.close if @socket and not @socket.closed?
- @socket = nil
- end
- private :do_finish
-
- # Returns the current command.
- #
- # Raises IOError if there is no active socket
- def command # :nodoc:
- raise IOError, 'POP session not opened yet' \
- if not @socket or @socket.closed?
- @command
- end
- private :command
-
- #
- # POP protocol wrapper
- #
-
- # Returns the number of messages on the POP server.
- def n_mails
- return @n_mails if @n_mails
- @n_mails, @n_bytes = command().stat
- @n_mails
- end
-
- # Returns the total size in bytes of all the messages on the POP server.
- def n_bytes
- return @n_bytes if @n_bytes
- @n_mails, @n_bytes = command().stat
- @n_bytes
- end
-
- # Returns an array of Net::POPMail objects, representing all the
- # messages on the server. This array is renewed when the session
- # restarts; otherwise, it is fetched from the server the first time
- # this method is called (directly or indirectly) and cached.
- #
- # This method raises a POPError if an error occurs.
- def mails
- return @mails.dup if @mails
- if n_mails() == 0
- # some popd raises error for LIST on the empty mailbox.
- @mails = []
- return []
- end
-
- @mails = command().list.map {|num, size|
- POPMail.new(num, size, self, command())
- }
- @mails.dup
- end
-
- # Yields each message to the passed-in block in turn.
- # Equivalent to:
- #
- # pop3.mails.each do |popmail|
- # ....
- # end
- #
- # This method raises a POPError if an error occurs.
- def each_mail(&block) # :yield: message
- mails().each(&block)
- end
-
- alias each each_mail
-
- # Deletes all messages on the server.
- #
- # If called with a block, yields each message in turn before deleting it.
- #
- # === Example
- #
- # n = 1
- # pop.delete_all do |m|
- # File.open("inbox/#{n}") do |f|
- # f.write m.pop
- # end
- # n += 1
- # end
- #
- # This method raises a POPError if an error occurs.
- #
- def delete_all # :yield: message
- mails().each do |m|
- yield m if block_given?
- m.delete unless m.deleted?
- end
- end
-
- # Resets the session. This clears all "deleted" marks from messages.
- #
- # This method raises a POPError if an error occurs.
- def reset
- command().rset
- mails().each do |m|
- m.instance_eval {
- @deleted = false
- }
- end
- end
-
- def set_all_uids #:nodoc: internal use only (called from POPMail#uidl)
- uidl = command().uidl
- @mails.each {|m| m.uid = uidl[m.number] }
- end
-
- # debugging output for +msg+
- def logging(msg)
- @debug_output << msg + "\n" if @debug_output
- end
-
- end # class POP3
-
- # class aliases
- POP = POP3 # :nodoc:
- POPSession = POP3 # :nodoc:
- POP3Session = POP3 # :nodoc:
-
- #
- # This class is equivalent to POP3, except that it uses APOP authentication.
- #
- class APOP < POP3
- # Always returns true.
- def apop?
- true
- end
- end
-
- # class aliases
- APOPSession = APOP
-
- #
- # This class represents a message which exists on the POP server.
- # Instances of this class are created by the POP3 class; they should
- # not be directly created by the user.
- #
- class POPMail
-
- def initialize(num, len, pop, cmd) #:nodoc:
- @number = num
- @length = len
- @pop = pop
- @command = cmd
- @deleted = false
- @uid = nil
- end
-
- # The sequence number of the message on the server.
- attr_reader :number
-
- # The length of the message in octets.
- attr_reader :length
- alias size length
-
- # Provide human-readable stringification of class state.
- def inspect
- "#<#{self.class} #{@number}#{@deleted ? ' deleted' : ''}>"
- end
-
- #
- # This method fetches the message. If called with a block, the
- # message is yielded to the block one chunk at a time. If called
- # without a block, the message is returned as a String. The optional
- # +dest+ argument will be prepended to the returned String; this
- # argument is essentially obsolete.
- #
- # === Example without block
- #
- # POP3.start('pop.example.com', 110,
- # 'YourAccount, 'YourPassword') do |pop|
- # n = 1
- # pop.mails.each do |popmail|
- # File.open("inbox/#{n}", 'w') do |f|
- # f.write popmail.pop
- # end
- # popmail.delete
- # n += 1
- # end
- # end
- #
- # === Example with block
- #
- # POP3.start('pop.example.com', 110,
- # 'YourAccount, 'YourPassword') do |pop|
- # n = 1
- # pop.mails.each do |popmail|
- # File.open("inbox/#{n}", 'w') do |f|
- # popmail.pop do |chunk| ####
- # f.write chunk
- # end
- # end
- # n += 1
- # end
- # end
- #
- # This method raises a POPError if an error occurs.
- #
- def pop( dest = '', &block ) # :yield: message_chunk
- if block_given?
- @command.retr(@number, &block)
- nil
- else
- @command.retr(@number) do |chunk|
- dest << chunk
- end
- dest
- end
- end
-
- alias all pop #:nodoc: obsolete
- alias mail pop #:nodoc: obsolete
-
- # Fetches the message header and +lines+ lines of body.
- #
- # The optional +dest+ argument is obsolete.
- #
- # This method raises a POPError if an error occurs.
- def top(lines, dest = '')
- @command.top(@number, lines) do |chunk|
- dest << chunk
- end
- dest
- end
-
- # Fetches the message header.
- #
- # The optional +dest+ argument is obsolete.
- #
- # This method raises a POPError if an error occurs.
- def header(dest = '')
- top(0, dest)
- end
-
- # Marks a message for deletion on the server. Deletion does not
- # actually occur until the end of the session; deletion may be
- # cancelled for _all_ marked messages by calling POP3#reset().
- #
- # This method raises a POPError if an error occurs.
- #
- # === Example
- #
- # POP3.start('pop.example.com', 110,
- # 'YourAccount, 'YourPassword') do |pop|
- # n = 1
- # pop.mails.each do |popmail|
- # File.open("inbox/#{n}", 'w') do |f|
- # f.write popmail.pop
- # end
- # popmail.delete ####
- # n += 1
- # end
- # end
- #
- def delete
- @command.dele @number
- @deleted = true
- end
-
- alias delete! delete #:nodoc: obsolete
-
- # True if the mail has been deleted.
- def deleted?
- @deleted
- end
-
- # Returns the unique-id of the message.
- # Normally the unique-id is a hash string of the message.
- #
- # This method raises a POPError if an error occurs.
- def unique_id
- return @uid if @uid
- @pop.set_all_uids
- @uid
- end
-
- alias uidl unique_id
-
- def uid=(uid) #:nodoc: internal use only
- @uid = uid
- end
-
- end # class POPMail
-
-
- class POP3Command #:nodoc: internal use only
-
- def initialize(sock)
- @socket = sock
- @error_occurred = false
- res = check_response(critical { recv_response() })
- @apop_stamp = res.slice(/<[!-~]+@[!-~]+>/)
- end
-
- attr_reader :socket
-
- def inspect
- "#<#{self.class} socket=#{@socket}>"
- end
-
- def auth(account, password)
- check_response_auth(critical {
- check_response_auth(get_response('USER %s', account))
- get_response('PASS %s', password)
- })
- end
-
- def apop(account, password)
- raise POPAuthenticationError, 'not APOP server; cannot login' \
- unless @apop_stamp
- check_response_auth(critical {
- get_response('APOP %s %s',
- account,
- Digest::MD5.hexdigest(@apop_stamp + password))
- })
- end
-
- def list
- critical {
- getok 'LIST'
- list = []
- @socket.each_list_item do |line|
- m = /\A(\d+)[ \t]+(\d+)/.match(line) or
- raise POPBadResponse, "bad response: #{line}"
- list.push [m[1].to_i, m[2].to_i]
- end
- return list
- }
- end
-
- def stat
- res = check_response(critical { get_response('STAT') })
- m = /\A\+OK\s+(\d+)\s+(\d+)/.match(res) or
- raise POPBadResponse, "wrong response format: #{res}"
- [m[1].to_i, m[2].to_i]
- end
-
- def rset
- check_response(critical { get_response('RSET') })
- end
-
- def top(num, lines = 0, &block)
- critical {
- getok('TOP %d %d', num, lines)
- @socket.each_message_chunk(&block)
- }
- end
-
- def retr(num, &block)
- critical {
- getok('RETR %d', num)
- @socket.each_message_chunk(&block)
- }
- end
-
- def dele(num)
- check_response(critical { get_response('DELE %d', num) })
- end
-
- def uidl(num = nil)
- if num
- res = check_response(critical { get_response('UIDL %d', num) })
- return res.split(/ /)[1]
- else
- critical {
- getok('UIDL')
- table = {}
- @socket.each_list_item do |line|
- num, uid = line.split
- table[num.to_i] = uid
- end
- return table
- }
- end
- end
-
- def quit
- check_response(critical { get_response('QUIT') })
- end
-
- private
-
- def getok(fmt, *fargs)
- @socket.writeline sprintf(fmt, *fargs)
- check_response(recv_response())
- end
-
- def get_response(fmt, *fargs)
- @socket.writeline sprintf(fmt, *fargs)
- recv_response()
- end
-
- def recv_response
- @socket.readline
- end
-
- def check_response(res)
- raise POPError, res unless /\A\+OK/i =~ res
- res
- end
-
- def check_response_auth(res)
- raise POPAuthenticationError, res unless /\A\+OK/i =~ res
- res
- end
-
- def critical
- return '+OK dummy ok response' if @error_occurred
- begin
- return yield()
- rescue Exception
- @error_occurred = true
- raise
- end
- end
-
- end # class POP3Command
-
-end # module Net
diff --git a/ruby_2_2/lib/net/protocol.rb b/ruby_2_2/lib/net/protocol.rb
deleted file mode 100644
index 25477014fb..0000000000
--- a/ruby_2_2/lib/net/protocol.rb
+++ /dev/null
@@ -1,420 +0,0 @@
-#
-# = net/protocol.rb
-#
-#--
-# Copyright (c) 1999-2004 Yukihiro Matsumoto
-# Copyright (c) 1999-2004 Minero Aoki
-#
-# written and maintained by Minero Aoki <aamine@loveruby.net>
-#
-# This program is free software. You can re-distribute and/or
-# modify this program under the same terms as Ruby itself,
-# Ruby Distribute License or GNU General Public License.
-#
-# $Id$
-#++
-#
-# WARNING: This file is going to remove.
-# Do not rely on the implementation written in this file.
-#
-
-require 'socket'
-require 'timeout'
-
-module Net # :nodoc:
-
- class Protocol #:nodoc: internal use only
- private
- def Protocol.protocol_param(name, val)
- module_eval(<<-End, __FILE__, __LINE__ + 1)
- def #{name}
- #{val}
- end
- End
- end
- end
-
-
- class ProtocolError < StandardError; end
- class ProtoSyntaxError < ProtocolError; end
- class ProtoFatalError < ProtocolError; end
- class ProtoUnknownError < ProtocolError; end
- class ProtoServerError < ProtocolError; end
- class ProtoAuthError < ProtocolError; end
- class ProtoCommandError < ProtocolError; end
- class ProtoRetriableError < ProtocolError; end
- ProtocRetryError = ProtoRetriableError
-
- ##
- # OpenTimeout, a subclass of Timeout::Error, is raised if a connection cannot
- # be created within the open_timeout.
-
- class OpenTimeout < Timeout::Error; end
-
- ##
- # ReadTimeout, a subclass of Timeout::Error, is raised if a chunk of the
- # response cannot be read within the read_timeout.
-
- class ReadTimeout < Timeout::Error; end
-
-
- class BufferedIO #:nodoc: internal use only
- def initialize(io)
- @io = io
- @read_timeout = 60
- @continue_timeout = nil
- @debug_output = nil
- @rbuf = ''
- end
-
- attr_reader :io
- attr_accessor :read_timeout
- attr_accessor :continue_timeout
- attr_accessor :debug_output
-
- def inspect
- "#<#{self.class} io=#{@io}>"
- end
-
- def eof?
- @io.eof?
- end
-
- def closed?
- @io.closed?
- end
-
- def close
- @io.close
- end
-
- #
- # Read
- #
-
- public
-
- def read(len, dest = '', ignore_eof = false)
- LOG "reading #{len} bytes..."
- read_bytes = 0
- begin
- while read_bytes + @rbuf.size < len
- dest << (s = rbuf_consume(@rbuf.size))
- read_bytes += s.size
- rbuf_fill
- end
- dest << (s = rbuf_consume(len - read_bytes))
- read_bytes += s.size
- rescue EOFError
- raise unless ignore_eof
- end
- LOG "read #{read_bytes} bytes"
- dest
- end
-
- def read_all(dest = '')
- LOG 'reading all...'
- read_bytes = 0
- begin
- while true
- dest << (s = rbuf_consume(@rbuf.size))
- read_bytes += s.size
- rbuf_fill
- end
- rescue EOFError
- ;
- end
- LOG "read #{read_bytes} bytes"
- dest
- end
-
- def readuntil(terminator, ignore_eof = false)
- begin
- until idx = @rbuf.index(terminator)
- rbuf_fill
- end
- return rbuf_consume(idx + terminator.size)
- rescue EOFError
- raise unless ignore_eof
- return rbuf_consume(@rbuf.size)
- end
- end
-
- def readline
- readuntil("\n").chop
- end
-
- private
-
- BUFSIZE = 1024 * 16
-
- def rbuf_fill
- begin
- @rbuf << @io.read_nonblock(BUFSIZE)
- rescue IO::WaitReadable
- if IO.select([@io], nil, nil, @read_timeout)
- retry
- else
- raise Net::ReadTimeout
- end
- rescue IO::WaitWritable
- # OpenSSL::Buffering#read_nonblock may fail with IO::WaitWritable.
- # http://www.openssl.org/support/faq.html#PROG10
- if IO.select(nil, [@io], nil, @read_timeout)
- retry
- else
- raise Net::ReadTimeout
- end
- end
- end
-
- def rbuf_consume(len)
- s = @rbuf.slice!(0, len)
- @debug_output << %Q[-> #{s.dump}\n] if @debug_output
- s
- end
-
- #
- # Write
- #
-
- public
-
- def write(str)
- writing {
- write0 str
- }
- end
-
- alias << write
-
- def writeline(str)
- writing {
- write0 str + "\r\n"
- }
- end
-
- private
-
- def writing
- @written_bytes = 0
- @debug_output << '<- ' if @debug_output
- yield
- @debug_output << "\n" if @debug_output
- bytes = @written_bytes
- @written_bytes = nil
- bytes
- end
-
- def write0(str)
- @debug_output << str.dump if @debug_output
- len = @io.write(str)
- @written_bytes += len
- len
- end
-
- #
- # Logging
- #
-
- private
-
- def LOG_off
- @save_debug_out = @debug_output
- @debug_output = nil
- end
-
- def LOG_on
- @debug_output = @save_debug_out
- end
-
- def LOG(msg)
- return unless @debug_output
- @debug_output << msg + "\n"
- end
- end
-
-
- class InternetMessageIO < BufferedIO #:nodoc: internal use only
- def initialize(io)
- super
- @wbuf = nil
- end
-
- #
- # Read
- #
-
- def each_message_chunk
- LOG 'reading message...'
- LOG_off()
- read_bytes = 0
- while (line = readuntil("\r\n")) != ".\r\n"
- read_bytes += line.size
- yield line.sub(/\A\./, '')
- end
- LOG_on()
- LOG "read message (#{read_bytes} bytes)"
- end
-
- # *library private* (cannot handle 'break')
- def each_list_item
- while (str = readuntil("\r\n")) != ".\r\n"
- yield str.chop
- end
- end
-
- def write_message_0(src)
- prev = @written_bytes
- each_crlf_line(src) do |line|
- write0 dot_stuff(line)
- end
- @written_bytes - prev
- end
-
- #
- # Write
- #
-
- def write_message(src)
- LOG "writing message from #{src.class}"
- LOG_off()
- len = writing {
- using_each_crlf_line {
- write_message_0 src
- }
- }
- LOG_on()
- LOG "wrote #{len} bytes"
- len
- end
-
- def write_message_by_block(&block)
- LOG 'writing message from block'
- LOG_off()
- len = writing {
- using_each_crlf_line {
- begin
- block.call(WriteAdapter.new(self, :write_message_0))
- rescue LocalJumpError
- # allow `break' from writer block
- end
- }
- }
- LOG_on()
- LOG "wrote #{len} bytes"
- len
- end
-
- private
-
- def dot_stuff(s)
- s.sub(/\A\./, '..')
- end
-
- def using_each_crlf_line
- @wbuf = ''
- yield
- if not @wbuf.empty? # unterminated last line
- write0 dot_stuff(@wbuf.chomp) + "\r\n"
- elsif @written_bytes == 0 # empty src
- write0 "\r\n"
- end
- write0 ".\r\n"
- @wbuf = nil
- end
-
- def each_crlf_line(src)
- buffer_filling(@wbuf, src) do
- while line = @wbuf.slice!(/\A[^\r\n]*(?:\n|\r(?:\n|(?!\z)))/)
- yield line.chomp("\n") + "\r\n"
- end
- end
- end
-
- def buffer_filling(buf, src)
- case src
- when String # for speeding up.
- 0.step(src.size - 1, 1024) do |i|
- buf << src[i, 1024]
- yield
- end
- when File # for speeding up.
- while s = src.read(1024)
- buf << s
- yield
- end
- else # generic reader
- src.each do |str|
- buf << str
- yield if buf.size > 1024
- end
- yield unless buf.empty?
- end
- end
- end
-
-
- #
- # The writer adapter class
- #
- class WriteAdapter
- def initialize(socket, method)
- @socket = socket
- @method_id = method
- end
-
- def inspect
- "#<#{self.class} socket=#{@socket.inspect}>"
- end
-
- def write(str)
- @socket.__send__(@method_id, str)
- end
-
- alias print write
-
- def <<(str)
- write str
- self
- end
-
- def puts(str = '')
- write str.chomp("\n") + "\n"
- end
-
- def printf(*args)
- write sprintf(*args)
- end
- end
-
-
- class ReadAdapter #:nodoc: internal use only
- def initialize(block)
- @block = block
- end
-
- def inspect
- "#<#{self.class}>"
- end
-
- def <<(str)
- call_block(str, &@block) if @block
- end
-
- private
-
- # This method is needed because @block must be called by yield,
- # not Proc#call. You can see difference when using `break' in
- # the block.
- def call_block(str)
- yield str
- end
- end
-
-
- module NetPrivate #:nodoc: obsolete
- Socket = ::Net::InternetMessageIO
- end
-
-end # module Net
diff --git a/ruby_2_2/lib/net/smtp.rb b/ruby_2_2/lib/net/smtp.rb
deleted file mode 100644
index 64e536a12a..0000000000
--- a/ruby_2_2/lib/net/smtp.rb
+++ /dev/null
@@ -1,1073 +0,0 @@
-# = net/smtp.rb
-#
-# Copyright (c) 1999-2007 Yukihiro Matsumoto.
-#
-# Copyright (c) 1999-2007 Minero Aoki.
-#
-# Written & maintained by Minero Aoki <aamine@loveruby.net>.
-#
-# Documented by William Webber and Minero Aoki.
-#
-# This program is free software. You can re-distribute and/or
-# modify this program under the same terms as Ruby itself.
-#
-# NOTE: You can find Japanese version of this document at:
-# http://www.ruby-lang.org/ja/man/html/net_smtp.html
-#
-# $Id$
-#
-# See Net::SMTP for documentation.
-#
-
-require 'net/protocol'
-require 'digest/md5'
-require 'timeout'
-begin
- require 'openssl'
-rescue LoadError
-end
-
-module Net
-
- # Module mixed in to all SMTP error classes
- module SMTPError
- # This *class* is a module for backward compatibility.
- # In later release, this module becomes a class.
- end
-
- # Represents an SMTP authentication error.
- class SMTPAuthenticationError < ProtoAuthError
- include SMTPError
- end
-
- # Represents SMTP error code 420 or 450, a temporary error.
- class SMTPServerBusy < ProtoServerError
- include SMTPError
- end
-
- # Represents an SMTP command syntax error (error code 500)
- class SMTPSyntaxError < ProtoSyntaxError
- include SMTPError
- end
-
- # Represents a fatal SMTP error (error code 5xx, except for 500)
- class SMTPFatalError < ProtoFatalError
- include SMTPError
- end
-
- # Unexpected reply code returned from server.
- class SMTPUnknownError < ProtoUnknownError
- include SMTPError
- end
-
- # Command is not supported on server.
- class SMTPUnsupportedCommand < ProtocolError
- include SMTPError
- end
-
- #
- # == What is This Library?
- #
- # This library provides functionality to send internet
- # mail via SMTP, the Simple Mail Transfer Protocol. For details of
- # SMTP itself, see [RFC2821] (http://www.ietf.org/rfc/rfc2821.txt).
- #
- # == What is This Library NOT?
- #
- # This library does NOT provide functions to compose internet mails.
- # You must create them by yourself. If you want better mail support,
- # try RubyMail or TMail or search for alternatives in
- # {RubyGems.org}[https://rubygems.org/] or {The Ruby
- # Toolbox}[https://www.ruby-toolbox.com/].
- #
- # FYI: the official documentation on internet mail is: [RFC2822] (http://www.ietf.org/rfc/rfc2822.txt).
- #
- # == Examples
- #
- # === Sending Messages
- #
- # You must open a connection to an SMTP server before sending messages.
- # The first argument is the address of your SMTP server, and the second
- # argument is the port number. Using SMTP.start with a block is the simplest
- # way to do this. This way, the SMTP connection is closed automatically
- # after the block is executed.
- #
- # require 'net/smtp'
- # Net::SMTP.start('your.smtp.server', 25) do |smtp|
- # # Use the SMTP object smtp only in this block.
- # end
- #
- # Replace 'your.smtp.server' with your SMTP server. Normally
- # your system manager or internet provider supplies a server
- # for you.
- #
- # Then you can send messages.
- #
- # msgstr = <<END_OF_MESSAGE
- # From: Your Name <your@mail.address>
- # To: Destination Address <someone@example.com>
- # Subject: test message
- # Date: Sat, 23 Jun 2001 16:26:43 +0900
- # Message-Id: <unique.message.id.string@example.com>
- #
- # This is a test message.
- # END_OF_MESSAGE
- #
- # require 'net/smtp'
- # Net::SMTP.start('your.smtp.server', 25) do |smtp|
- # smtp.send_message msgstr,
- # 'your@mail.address',
- # 'his_address@example.com'
- # end
- #
- # === Closing the Session
- #
- # You MUST close the SMTP session after sending messages, by calling
- # the #finish method:
- #
- # # using SMTP#finish
- # smtp = Net::SMTP.start('your.smtp.server', 25)
- # smtp.send_message msgstr, 'from@address', 'to@address'
- # smtp.finish
- #
- # You can also use the block form of SMTP.start/SMTP#start. This closes
- # the SMTP session automatically:
- #
- # # using block form of SMTP.start
- # Net::SMTP.start('your.smtp.server', 25) do |smtp|
- # smtp.send_message msgstr, 'from@address', 'to@address'
- # end
- #
- # I strongly recommend this scheme. This form is simpler and more robust.
- #
- # === HELO domain
- #
- # In almost all situations, you must provide a third argument
- # to SMTP.start/SMTP#start. This is the domain name which you are on
- # (the host to send mail from). It is called the "HELO domain".
- # The SMTP server will judge whether it should send or reject
- # the SMTP session by inspecting the HELO domain.
- #
- # Net::SMTP.start('your.smtp.server', 25,
- # 'mail.from.domain') { |smtp| ... }
- #
- # === SMTP Authentication
- #
- # The Net::SMTP class supports three authentication schemes;
- # PLAIN, LOGIN and CRAM MD5. (SMTP Authentication: [RFC2554])
- # To use SMTP authentication, pass extra arguments to
- # SMTP.start/SMTP#start.
- #
- # # PLAIN
- # Net::SMTP.start('your.smtp.server', 25, 'mail.from.domain',
- # 'Your Account', 'Your Password', :plain)
- # # LOGIN
- # Net::SMTP.start('your.smtp.server', 25, 'mail.from.domain',
- # 'Your Account', 'Your Password', :login)
- #
- # # CRAM MD5
- # Net::SMTP.start('your.smtp.server', 25, 'mail.from.domain',
- # 'Your Account', 'Your Password', :cram_md5)
- #
- class SMTP
-
- Revision = %q$Revision$.split[1]
-
- # The default SMTP port number, 25.
- def SMTP.default_port
- 25
- end
-
- # The default mail submission port number, 587.
- def SMTP.default_submission_port
- 587
- end
-
- # The default SMTPS port number, 465.
- def SMTP.default_tls_port
- 465
- end
-
- class << self
- alias default_ssl_port default_tls_port
- end
-
- def SMTP.default_ssl_context
- OpenSSL::SSL::SSLContext.new
- end
-
- #
- # Creates a new Net::SMTP object.
- #
- # +address+ is the hostname or ip address of your SMTP
- # server. +port+ is the port to connect to; it defaults to
- # port 25.
- #
- # This method does not open the TCP connection. You can use
- # SMTP.start instead of SMTP.new if you want to do everything
- # at once. Otherwise, follow SMTP.new with SMTP#start.
- #
- def initialize(address, port = nil)
- @address = address
- @port = (port || SMTP.default_port)
- @esmtp = true
- @capabilities = nil
- @socket = nil
- @started = false
- @open_timeout = 30
- @read_timeout = 60
- @error_occurred = false
- @debug_output = nil
- @tls = false
- @starttls = false
- @ssl_context = nil
- end
-
- # Provide human-readable stringification of class state.
- def inspect
- "#<#{self.class} #{@address}:#{@port} started=#{@started}>"
- end
-
- #
- # Set whether to use ESMTP or not. This should be done before
- # calling #start. Note that if #start is called in ESMTP mode,
- # and the connection fails due to a ProtocolError, the SMTP
- # object will automatically switch to plain SMTP mode and
- # retry (but not vice versa).
- #
- attr_accessor :esmtp
-
- # +true+ if the SMTP object uses ESMTP (which it does by default).
- alias :esmtp? :esmtp
-
- # true if server advertises STARTTLS.
- # You cannot get valid value before opening SMTP session.
- def capable_starttls?
- capable?('STARTTLS')
- end
-
- def capable?(key)
- return nil unless @capabilities
- @capabilities[key] ? true : false
- end
- private :capable?
-
- # true if server advertises AUTH PLAIN.
- # You cannot get valid value before opening SMTP session.
- def capable_plain_auth?
- auth_capable?('PLAIN')
- end
-
- # true if server advertises AUTH LOGIN.
- # You cannot get valid value before opening SMTP session.
- def capable_login_auth?
- auth_capable?('LOGIN')
- end
-
- # true if server advertises AUTH CRAM-MD5.
- # You cannot get valid value before opening SMTP session.
- def capable_cram_md5_auth?
- auth_capable?('CRAM-MD5')
- end
-
- def auth_capable?(type)
- return nil unless @capabilities
- return false unless @capabilities['AUTH']
- @capabilities['AUTH'].include?(type)
- end
- private :auth_capable?
-
- # Returns supported authentication methods on this server.
- # You cannot get valid value before opening SMTP session.
- def capable_auth_types
- return [] unless @capabilities
- return [] unless @capabilities['AUTH']
- @capabilities['AUTH']
- end
-
- # true if this object uses SMTP/TLS (SMTPS).
- def tls?
- @tls
- end
-
- alias ssl? tls?
-
- # Enables SMTP/TLS (SMTPS: SMTP over direct TLS connection) for
- # this object. Must be called before the connection is established
- # to have any effect. +context+ is a OpenSSL::SSL::SSLContext object.
- def enable_tls(context = SMTP.default_ssl_context)
- raise 'openssl library not installed' unless defined?(OpenSSL)
- raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @starttls
- @tls = true
- @ssl_context = context
- end
-
- alias enable_ssl enable_tls
-
- # Disables SMTP/TLS for this object. Must be called before the
- # connection is established to have any effect.
- def disable_tls
- @tls = false
- @ssl_context = nil
- end
-
- alias disable_ssl disable_tls
-
- # Returns truth value if this object uses STARTTLS.
- # If this object always uses STARTTLS, returns :always.
- # If this object uses STARTTLS when the server support TLS, returns :auto.
- def starttls?
- @starttls
- end
-
- # true if this object uses STARTTLS.
- def starttls_always?
- @starttls == :always
- end
-
- # true if this object uses STARTTLS when server advertises STARTTLS.
- def starttls_auto?
- @starttls == :auto
- end
-
- # Enables SMTP/TLS (STARTTLS) for this object.
- # +context+ is a OpenSSL::SSL::SSLContext object.
- def enable_starttls(context = SMTP.default_ssl_context)
- raise 'openssl library not installed' unless defined?(OpenSSL)
- raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @tls
- @starttls = :always
- @ssl_context = context
- end
-
- # Enables SMTP/TLS (STARTTLS) for this object if server accepts.
- # +context+ is a OpenSSL::SSL::SSLContext object.
- def enable_starttls_auto(context = SMTP.default_ssl_context)
- raise 'openssl library not installed' unless defined?(OpenSSL)
- raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @tls
- @starttls = :auto
- @ssl_context = context
- end
-
- # Disables SMTP/TLS (STARTTLS) for this object. Must be called
- # before the connection is established to have any effect.
- def disable_starttls
- @starttls = false
- @ssl_context = nil
- end
-
- # The address of the SMTP server to connect to.
- attr_reader :address
-
- # The port number of the SMTP server to connect to.
- attr_reader :port
-
- # Seconds to wait while attempting to open a connection.
- # If the connection cannot be opened within this time, a
- # Net::OpenTimeout is raised. The default value is 30 seconds.
- attr_accessor :open_timeout
-
- # Seconds to wait while reading one block (by one read(2) call).
- # If the read(2) call does not complete within this time, a
- # Net::ReadTimeout is raised. The default value is 60 seconds.
- attr_reader :read_timeout
-
- # Set the number of seconds to wait until timing-out a read(2)
- # call.
- def read_timeout=(sec)
- @socket.read_timeout = sec if @socket
- @read_timeout = sec
- end
-
- #
- # WARNING: This method causes serious security holes.
- # Use this method for only debugging.
- #
- # Set an output stream for debug logging.
- # You must call this before #start.
- #
- # # example
- # smtp = Net::SMTP.new(addr, port)
- # smtp.set_debug_output $stderr
- # smtp.start do |smtp|
- # ....
- # end
- #
- def debug_output=(arg)
- @debug_output = arg
- end
-
- alias set_debug_output debug_output=
-
- #
- # SMTP session control
- #
-
- #
- # Creates a new Net::SMTP object and connects to the server.
- #
- # This method is equivalent to:
- #
- # Net::SMTP.new(address, port).start(helo_domain, account, password, authtype)
- #
- # === Example
- #
- # Net::SMTP.start('your.smtp.server') do |smtp|
- # smtp.send_message msgstr, 'from@example.com', ['dest@example.com']
- # end
- #
- # === Block Usage
- #
- # If called with a block, the newly-opened Net::SMTP object is yielded
- # to the block, and automatically closed when the block finishes. If called
- # without a block, the newly-opened Net::SMTP object is returned to
- # the caller, and it is the caller's responsibility to close it when
- # finished.
- #
- # === Parameters
- #
- # +address+ is the hostname or ip address of your smtp server.
- #
- # +port+ is the port to connect to; it defaults to port 25.
- #
- # +helo+ is the _HELO_ _domain_ provided by the client to the
- # server (see overview comments); it defaults to 'localhost'.
- #
- # The remaining arguments are used for SMTP authentication, if required
- # or desired. +user+ is the account name; +secret+ is your password
- # or other authentication token; and +authtype+ is the authentication
- # type, one of :plain, :login, or :cram_md5. See the discussion of
- # SMTP Authentication in the overview notes.
- #
- # === Errors
- #
- # This method may raise:
- #
- # * Net::SMTPAuthenticationError
- # * Net::SMTPServerBusy
- # * Net::SMTPSyntaxError
- # * Net::SMTPFatalError
- # * Net::SMTPUnknownError
- # * Net::OpenTimeout
- # * Net::ReadTimeout
- # * IOError
- #
- def SMTP.start(address, port = nil, helo = 'localhost',
- user = nil, secret = nil, authtype = nil,
- &block) # :yield: smtp
- new(address, port).start(helo, user, secret, authtype, &block)
- end
-
- # +true+ if the SMTP session has been started.
- def started?
- @started
- end
-
- #
- # Opens a TCP connection and starts the SMTP session.
- #
- # === Parameters
- #
- # +helo+ is the _HELO_ _domain_ that you'll dispatch mails from; see
- # the discussion in the overview notes.
- #
- # If both of +user+ and +secret+ are given, SMTP authentication
- # will be attempted using the AUTH command. +authtype+ specifies
- # the type of authentication to attempt; it must be one of
- # :login, :plain, and :cram_md5. See the notes on SMTP Authentication
- # in the overview.
- #
- # === Block Usage
- #
- # When this methods is called with a block, the newly-started SMTP
- # object is yielded to the block, and automatically closed after
- # the block call finishes. Otherwise, it is the caller's
- # responsibility to close the session when finished.
- #
- # === Example
- #
- # This is very similar to the class method SMTP.start.
- #
- # require 'net/smtp'
- # smtp = Net::SMTP.new('smtp.mail.server', 25)
- # smtp.start(helo_domain, account, password, authtype) do |smtp|
- # smtp.send_message msgstr, 'from@example.com', ['dest@example.com']
- # end
- #
- # The primary use of this method (as opposed to SMTP.start)
- # is probably to set debugging (#set_debug_output) or ESMTP
- # (#esmtp=), which must be done before the session is
- # started.
- #
- # === Errors
- #
- # If session has already been started, an IOError will be raised.
- #
- # This method may raise:
- #
- # * Net::SMTPAuthenticationError
- # * Net::SMTPServerBusy
- # * Net::SMTPSyntaxError
- # * Net::SMTPFatalError
- # * Net::SMTPUnknownError
- # * Net::OpenTimeout
- # * Net::ReadTimeout
- # * IOError
- #
- def start(helo = 'localhost',
- user = nil, secret = nil, authtype = nil) # :yield: smtp
- if block_given?
- begin
- do_start helo, user, secret, authtype
- return yield(self)
- ensure
- do_finish
- end
- else
- do_start helo, user, secret, authtype
- return self
- end
- end
-
- # Finishes the SMTP session and closes TCP connection.
- # Raises IOError if not started.
- def finish
- raise IOError, 'not yet started' unless started?
- do_finish
- end
-
- private
-
- def tcp_socket(address, port)
- TCPSocket.open address, port
- end
-
- def do_start(helo_domain, user, secret, authtype)
- raise IOError, 'SMTP session already started' if @started
- if user or secret
- check_auth_method(authtype || DEFAULT_AUTH_TYPE)
- check_auth_args user, secret
- end
- s = Timeout.timeout(@open_timeout, Net::OpenTimeout) do
- tcp_socket(@address, @port)
- end
- logging "Connection opened: #{@address}:#{@port}"
- @socket = new_internet_message_io(tls? ? tlsconnect(s) : s)
- check_response critical { recv_response() }
- do_helo helo_domain
- if starttls_always? or (capable_starttls? and starttls_auto?)
- unless capable_starttls?
- raise SMTPUnsupportedCommand,
- "STARTTLS is not supported on this server"
- end
- starttls
- @socket = new_internet_message_io(tlsconnect(s))
- # helo response may be different after STARTTLS
- do_helo helo_domain
- end
- authenticate user, secret, (authtype || DEFAULT_AUTH_TYPE) if user
- @started = true
- ensure
- unless @started
- # authentication failed, cancel connection.
- s.close if s and not s.closed?
- @socket = nil
- end
- end
-
- def ssl_socket(socket, context)
- OpenSSL::SSL::SSLSocket.new socket, context
- end
-
- def tlsconnect(s)
- verified = false
- s = ssl_socket(s, @ssl_context)
- logging "TLS connection started"
- s.sync_close = true
- s.connect
- if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
- s.post_connection_check(@address)
- end
- verified = true
- s
- ensure
- s.close unless verified
- end
-
- def new_internet_message_io(s)
- io = InternetMessageIO.new(s)
- io.read_timeout = @read_timeout
- io.debug_output = @debug_output
- io
- end
-
- def do_helo(helo_domain)
- res = @esmtp ? ehlo(helo_domain) : helo(helo_domain)
- @capabilities = res.capabilities
- rescue SMTPError
- if @esmtp
- @esmtp = false
- @error_occurred = false
- retry
- end
- raise
- end
-
- def do_finish
- quit if @socket and not @socket.closed? and not @error_occurred
- ensure
- @started = false
- @error_occurred = false
- @socket.close if @socket and not @socket.closed?
- @socket = nil
- end
-
- #
- # Message Sending
- #
-
- public
-
- #
- # Sends +msgstr+ as a message. Single CR ("\r") and LF ("\n") found
- # in the +msgstr+, are converted into the CR LF pair. You cannot send a
- # binary message with this method. +msgstr+ should include both
- # the message headers and body.
- #
- # +from_addr+ is a String representing the source mail address.
- #
- # +to_addr+ is a String or Strings or Array of Strings, representing
- # the destination mail address or addresses.
- #
- # === Example
- #
- # Net::SMTP.start('smtp.example.com') do |smtp|
- # smtp.send_message msgstr,
- # 'from@example.com',
- # ['dest@example.com', 'dest2@example.com']
- # end
- #
- # === Errors
- #
- # This method may raise:
- #
- # * Net::SMTPServerBusy
- # * Net::SMTPSyntaxError
- # * Net::SMTPFatalError
- # * Net::SMTPUnknownError
- # * Net::ReadTimeout
- # * IOError
- #
- def send_message(msgstr, from_addr, *to_addrs)
- raise IOError, 'closed session' unless @socket
- mailfrom from_addr
- rcptto_list(to_addrs) {data msgstr}
- end
-
- alias send_mail send_message
- alias sendmail send_message # obsolete
-
- #
- # Opens a message writer stream and gives it to the block.
- # The stream is valid only in the block, and has these methods:
- #
- # puts(str = ''):: outputs STR and CR LF.
- # print(str):: outputs STR.
- # printf(fmt, *args):: outputs sprintf(fmt,*args).
- # write(str):: outputs STR and returns the length of written bytes.
- # <<(str):: outputs STR and returns self.
- #
- # If a single CR ("\r") or LF ("\n") is found in the message,
- # it is converted to the CR LF pair. You cannot send a binary
- # message with this method.
- #
- # === Parameters
- #
- # +from_addr+ is a String representing the source mail address.
- #
- # +to_addr+ is a String or Strings or Array of Strings, representing
- # the destination mail address or addresses.
- #
- # === Example
- #
- # Net::SMTP.start('smtp.example.com', 25) do |smtp|
- # smtp.open_message_stream('from@example.com', ['dest@example.com']) do |f|
- # f.puts 'From: from@example.com'
- # f.puts 'To: dest@example.com'
- # f.puts 'Subject: test message'
- # f.puts
- # f.puts 'This is a test message.'
- # end
- # end
- #
- # === Errors
- #
- # This method may raise:
- #
- # * Net::SMTPServerBusy
- # * Net::SMTPSyntaxError
- # * Net::SMTPFatalError
- # * Net::SMTPUnknownError
- # * Net::ReadTimeout
- # * IOError
- #
- def open_message_stream(from_addr, *to_addrs, &block) # :yield: stream
- raise IOError, 'closed session' unless @socket
- mailfrom from_addr
- rcptto_list(to_addrs) {data(&block)}
- end
-
- alias ready open_message_stream # obsolete
-
- #
- # Authentication
- #
-
- public
-
- DEFAULT_AUTH_TYPE = :plain
-
- def authenticate(user, secret, authtype = DEFAULT_AUTH_TYPE)
- check_auth_method authtype
- check_auth_args user, secret
- send auth_method(authtype), user, secret
- end
-
- def auth_plain(user, secret)
- check_auth_args user, secret
- res = critical {
- get_response('AUTH PLAIN ' + base64_encode("\0#{user}\0#{secret}"))
- }
- check_auth_response res
- res
- end
-
- def auth_login(user, secret)
- check_auth_args user, secret
- res = critical {
- check_auth_continue get_response('AUTH LOGIN')
- check_auth_continue get_response(base64_encode(user))
- get_response(base64_encode(secret))
- }
- check_auth_response res
- res
- end
-
- def auth_cram_md5(user, secret)
- check_auth_args user, secret
- res = critical {
- res0 = get_response('AUTH CRAM-MD5')
- check_auth_continue res0
- crammed = cram_md5_response(secret, res0.cram_md5_challenge)
- get_response(base64_encode("#{user} #{crammed}"))
- }
- check_auth_response res
- res
- end
-
- private
-
- def check_auth_method(type)
- unless respond_to?(auth_method(type), true)
- raise ArgumentError, "wrong authentication type #{type}"
- end
- end
-
- def auth_method(type)
- "auth_#{type.to_s.downcase}".intern
- end
-
- def check_auth_args(user, secret, authtype = DEFAULT_AUTH_TYPE)
- unless user
- raise ArgumentError, 'SMTP-AUTH requested but missing user name'
- end
- unless secret
- raise ArgumentError, 'SMTP-AUTH requested but missing secret phrase'
- end
- end
-
- def base64_encode(str)
- # expects "str" may not become too long
- [str].pack('m').gsub(/\s+/, '')
- end
-
- IMASK = 0x36
- OMASK = 0x5c
-
- # CRAM-MD5: [RFC2195]
- def cram_md5_response(secret, challenge)
- tmp = Digest::MD5.digest(cram_secret(secret, IMASK) + challenge)
- Digest::MD5.hexdigest(cram_secret(secret, OMASK) + tmp)
- end
-
- CRAM_BUFSIZE = 64
-
- def cram_secret(secret, mask)
- secret = Digest::MD5.digest(secret) if secret.size > CRAM_BUFSIZE
- buf = secret.ljust(CRAM_BUFSIZE, "\0")
- 0.upto(buf.size - 1) do |i|
- buf[i] = (buf[i].ord ^ mask).chr
- end
- buf
- end
-
- #
- # SMTP command dispatcher
- #
-
- public
-
- # Aborts the current mail transaction
-
- def rset
- getok('RSET')
- end
-
- def starttls
- getok('STARTTLS')
- end
-
- def helo(domain)
- getok("HELO #{domain}")
- end
-
- def ehlo(domain)
- getok("EHLO #{domain}")
- end
-
- def mailfrom(from_addr)
- if $SAFE > 0
- raise SecurityError, 'tainted from_addr' if from_addr.tainted?
- end
- getok("MAIL FROM:<#{from_addr}>")
- end
-
- def rcptto_list(to_addrs)
- raise ArgumentError, 'mail destination not given' if to_addrs.empty?
- ok_users = []
- unknown_users = []
- to_addrs.flatten.each do |addr|
- begin
- rcptto addr
- rescue SMTPAuthenticationError
- unknown_users << addr.dump
- else
- ok_users << addr
- end
- end
- raise ArgumentError, 'mail destination not given' if ok_users.empty?
- ret = yield
- unless unknown_users.empty?
- raise SMTPAuthenticationError, "failed to deliver for #{unknown_users.join(', ')}"
- end
- ret
- end
-
- def rcptto(to_addr)
- if $SAFE > 0
- raise SecurityError, 'tainted to_addr' if to_addr.tainted?
- end
- getok("RCPT TO:<#{to_addr}>")
- end
-
- # This method sends a message.
- # If +msgstr+ is given, sends it as a message.
- # If block is given, yield a message writer stream.
- # You must write message before the block is closed.
- #
- # # Example 1 (by string)
- # smtp.data(<<EndMessage)
- # From: john@example.com
- # To: betty@example.com
- # Subject: I found a bug
- #
- # Check vm.c:58879.
- # EndMessage
- #
- # # Example 2 (by block)
- # smtp.data {|f|
- # f.puts "From: john@example.com"
- # f.puts "To: betty@example.com"
- # f.puts "Subject: I found a bug"
- # f.puts ""
- # f.puts "Check vm.c:58879."
- # }
- #
- def data(msgstr = nil, &block) #:yield: stream
- if msgstr and block
- raise ArgumentError, "message and block are exclusive"
- end
- unless msgstr or block
- raise ArgumentError, "message or block is required"
- end
- res = critical {
- check_continue get_response('DATA')
- socket_sync_bak = @socket.io.sync
- begin
- @socket.io.sync = false
- if msgstr
- @socket.write_message msgstr
- else
- @socket.write_message_by_block(&block)
- end
- ensure
- @socket.io.flush
- @socket.io.sync = socket_sync_bak
- end
- recv_response()
- }
- check_response res
- res
- end
-
- def quit
- getok('QUIT')
- end
-
- private
-
- def getok(reqline)
- res = critical {
- @socket.writeline reqline
- recv_response()
- }
- check_response res
- res
- end
-
- def get_response(reqline)
- @socket.writeline reqline
- recv_response()
- end
-
- def recv_response
- buf = ''
- while true
- line = @socket.readline
- buf << line << "\n"
- break unless line[3,1] == '-' # "210-PIPELINING"
- end
- Response.parse(buf)
- end
-
- def critical
- return Response.parse('200 dummy reply code') if @error_occurred
- begin
- return yield()
- rescue Exception
- @error_occurred = true
- raise
- end
- end
-
- def check_response(res)
- unless res.success?
- raise res.exception_class, res.message
- end
- end
-
- def check_continue(res)
- unless res.continue?
- raise SMTPUnknownError, "could not get 3xx (#{res.status}: #{res.string})"
- end
- end
-
- def check_auth_response(res)
- unless res.success?
- raise SMTPAuthenticationError, res.message
- end
- end
-
- def check_auth_continue(res)
- unless res.continue?
- raise res.exception_class, res.message
- end
- end
-
- # This class represents a response received by the SMTP server. Instances
- # of this class are created by the SMTP class; they should not be directly
- # created by the user. For more information on SMTP responses, view
- # {Section 4.2 of RFC 5321}[http://tools.ietf.org/html/rfc5321#section-4.2]
- class Response
- # Parses the received response and separates the reply code and the human
- # readable reply text
- def self.parse(str)
- new(str[0,3], str)
- end
-
- # Creates a new instance of the Response class and sets the status and
- # string attributes
- def initialize(status, string)
- @status = status
- @string = string
- end
-
- # The three digit reply code of the SMTP response
- attr_reader :status
-
- # The human readable reply text of the SMTP response
- attr_reader :string
-
- # Takes the first digit of the reply code to determine the status type
- def status_type_char
- @status[0, 1]
- end
-
- # Determines whether the response received was a Positive Completion
- # reply (2xx reply code)
- def success?
- status_type_char() == '2'
- end
-
- # Determines whether the response received was a Positive Intermediate
- # reply (3xx reply code)
- def continue?
- status_type_char() == '3'
- end
-
- # The first line of the human readable reply text
- def message
- @string.lines.first
- end
-
- # Creates a CRAM-MD5 challenge. You can view more information on CRAM-MD5
- # on Wikipedia: http://en.wikipedia.org/wiki/CRAM-MD5
- def cram_md5_challenge
- @string.split(/ /)[1].unpack('m')[0]
- end
-
- # Returns a hash of the human readable reply text in the response if it
- # is multiple lines. It does not return the first line. The key of the
- # hash is the first word the value of the hash is an array with each word
- # thereafter being a value in the array
- def capabilities
- return {} unless @string[3, 1] == '-'
- h = {}
- @string.lines.drop(1).each do |line|
- k, *v = line[4..-1].chomp.split
- h[k] = v
- end
- h
- end
-
- # Determines whether there was an error and raises the appropriate error
- # based on the reply code of the response
- def exception_class
- case @status
- when /\A4/ then SMTPServerBusy
- when /\A50/ then SMTPSyntaxError
- when /\A53/ then SMTPAuthenticationError
- when /\A5/ then SMTPFatalError
- else SMTPUnknownError
- end
- end
- end
-
- def logging(msg)
- @debug_output << msg + "\n" if @debug_output
- end
-
- end # class SMTP
-
- SMTPSession = SMTP # :nodoc:
-
-end
diff --git a/ruby_2_2/lib/net/telnet.rb b/ruby_2_2/lib/net/telnet.rb
deleted file mode 100644
index 2260e7fb10..0000000000
--- a/ruby_2_2/lib/net/telnet.rb
+++ /dev/null
@@ -1,763 +0,0 @@
-# = net/telnet.rb - Simple Telnet Client Library
-#
-# Author:: Wakou Aoyama <wakou@ruby-lang.org>
-# Documentation:: William Webber and Wakou Aoyama
-#
-# This file holds the class Net::Telnet, which provides client-side
-# telnet functionality.
-#
-# For documentation, see Net::Telnet.
-#
-
-require "net/protocol"
-require "English"
-
-module Net
-
- #
- # == Net::Telnet
- #
- # Provides telnet client functionality.
- #
- # This class also has, through delegation, all the methods of a
- # socket object (by default, a +TCPSocket+, but can be set by the
- # +Proxy+ option to <tt>new()</tt>). This provides methods such as
- # <tt>close()</tt> to end the session and <tt>sysread()</tt> to read
- # data directly from the host, instead of via the <tt>waitfor()</tt>
- # mechanism. Note that if you do use <tt>sysread()</tt> directly
- # when in telnet mode, you should probably pass the output through
- # <tt>preprocess()</tt> to extract telnet command sequences.
- #
- # == Overview
- #
- # The telnet protocol allows a client to login remotely to a user
- # account on a server and execute commands via a shell. The equivalent
- # is done by creating a Net::Telnet class with the +Host+ option
- # set to your host, calling #login() with your user and password,
- # issuing one or more #cmd() calls, and then calling #close()
- # to end the session. The #waitfor(), #print(), #puts(), and
- # #write() methods, which #cmd() is implemented on top of, are
- # only needed if you are doing something more complicated.
- #
- # A Net::Telnet object can also be used to connect to non-telnet
- # services, such as SMTP or HTTP. In this case, you normally
- # want to provide the +Port+ option to specify the port to
- # connect to, and set the +Telnetmode+ option to false to prevent
- # the client from attempting to interpret telnet command sequences.
- # Generally, #login() will not work with other protocols, and you
- # have to handle authentication yourself.
- #
- # For some protocols, it will be possible to specify the +Prompt+
- # option once when you create the Telnet object and use #cmd() calls;
- # for others, you will have to specify the response sequence to
- # look for as the Match option to every #cmd() call, or call
- # #puts() and #waitfor() directly; for yet others, you will have
- # to use #sysread() instead of #waitfor() and parse server
- # responses yourself.
- #
- # It is worth noting that when you create a new Net::Telnet object,
- # you can supply a proxy IO channel via the Proxy option. This
- # can be used to attach the Telnet object to other Telnet objects,
- # to already open sockets, or to any read-write IO object. This
- # can be useful, for instance, for setting up a test fixture for
- # unit testing.
- #
- # == Examples
- #
- # === Log in and send a command, echoing all output to stdout
- #
- # localhost = Net::Telnet::new("Host" => "localhost",
- # "Timeout" => 10,
- # "Prompt" => /[$%#>] \z/n)
- # localhost.login("username", "password") { |c| print c }
- # localhost.cmd("command") { |c| print c }
- # localhost.close
- #
- #
- # === Check a POP server to see if you have mail
- #
- # pop = Net::Telnet::new("Host" => "your_destination_host_here",
- # "Port" => 110,
- # "Telnetmode" => false,
- # "Prompt" => /^\+OK/n)
- # pop.cmd("user " + "your_username_here") { |c| print c }
- # pop.cmd("pass " + "your_password_here") { |c| print c }
- # pop.cmd("list") { |c| print c }
- #
- # == References
- #
- # There are a large number of RFCs relevant to the Telnet protocol.
- # RFCs 854-861 define the base protocol. For a complete listing
- # of relevant RFCs, see
- # http://www.omnifarious.org/~hopper/technical/telnet-rfc.html
- #
- class Telnet
-
- # :stopdoc:
- IAC = 255.chr # "\377" # "\xff" # interpret as command
- DONT = 254.chr # "\376" # "\xfe" # you are not to use option
- DO = 253.chr # "\375" # "\xfd" # please, you use option
- WONT = 252.chr # "\374" # "\xfc" # I won't use option
- WILL = 251.chr # "\373" # "\xfb" # I will use option
- SB = 250.chr # "\372" # "\xfa" # interpret as subnegotiation
- GA = 249.chr # "\371" # "\xf9" # you may reverse the line
- EL = 248.chr # "\370" # "\xf8" # erase the current line
- EC = 247.chr # "\367" # "\xf7" # erase the current character
- AYT = 246.chr # "\366" # "\xf6" # are you there
- AO = 245.chr # "\365" # "\xf5" # abort output--but let prog finish
- IP = 244.chr # "\364" # "\xf4" # interrupt process--permanently
- BREAK = 243.chr # "\363" # "\xf3" # break
- DM = 242.chr # "\362" # "\xf2" # data mark--for connect. cleaning
- NOP = 241.chr # "\361" # "\xf1" # nop
- SE = 240.chr # "\360" # "\xf0" # end sub negotiation
- EOR = 239.chr # "\357" # "\xef" # end of record (transparent mode)
- ABORT = 238.chr # "\356" # "\xee" # Abort process
- SUSP = 237.chr # "\355" # "\xed" # Suspend process
- EOF = 236.chr # "\354" # "\xec" # End of file
- SYNCH = 242.chr # "\362" # "\xf2" # for telfunc calls
-
- OPT_BINARY = 0.chr # "\000" # "\x00" # Binary Transmission
- OPT_ECHO = 1.chr # "\001" # "\x01" # Echo
- OPT_RCP = 2.chr # "\002" # "\x02" # Reconnection
- OPT_SGA = 3.chr # "\003" # "\x03" # Suppress Go Ahead
- OPT_NAMS = 4.chr # "\004" # "\x04" # Approx Message Size Negotiation
- OPT_STATUS = 5.chr # "\005" # "\x05" # Status
- OPT_TM = 6.chr # "\006" # "\x06" # Timing Mark
- OPT_RCTE = 7.chr # "\a" # "\x07" # Remote Controlled Trans and Echo
- OPT_NAOL = 8.chr # "\010" # "\x08" # Output Line Width
- OPT_NAOP = 9.chr # "\t" # "\x09" # Output Page Size
- OPT_NAOCRD = 10.chr # "\n" # "\x0a" # Output Carriage-Return Disposition
- OPT_NAOHTS = 11.chr # "\v" # "\x0b" # Output Horizontal Tab Stops
- OPT_NAOHTD = 12.chr # "\f" # "\x0c" # Output Horizontal Tab Disposition
- OPT_NAOFFD = 13.chr # "\r" # "\x0d" # Output Formfeed Disposition
- OPT_NAOVTS = 14.chr # "\016" # "\x0e" # Output Vertical Tabstops
- OPT_NAOVTD = 15.chr # "\017" # "\x0f" # Output Vertical Tab Disposition
- OPT_NAOLFD = 16.chr # "\020" # "\x10" # Output Linefeed Disposition
- OPT_XASCII = 17.chr # "\021" # "\x11" # Extended ASCII
- OPT_LOGOUT = 18.chr # "\022" # "\x12" # Logout
- OPT_BM = 19.chr # "\023" # "\x13" # Byte Macro
- OPT_DET = 20.chr # "\024" # "\x14" # Data Entry Terminal
- OPT_SUPDUP = 21.chr # "\025" # "\x15" # SUPDUP
- OPT_SUPDUPOUTPUT = 22.chr # "\026" # "\x16" # SUPDUP Output
- OPT_SNDLOC = 23.chr # "\027" # "\x17" # Send Location
- OPT_TTYPE = 24.chr # "\030" # "\x18" # Terminal Type
- OPT_EOR = 25.chr # "\031" # "\x19" # End of Record
- OPT_TUID = 26.chr # "\032" # "\x1a" # TACACS User Identification
- OPT_OUTMRK = 27.chr # "\e" # "\x1b" # Output Marking
- OPT_TTYLOC = 28.chr # "\034" # "\x1c" # Terminal Location Number
- OPT_3270REGIME = 29.chr # "\035" # "\x1d" # Telnet 3270 Regime
- OPT_X3PAD = 30.chr # "\036" # "\x1e" # X.3 PAD
- OPT_NAWS = 31.chr # "\037" # "\x1f" # Negotiate About Window Size
- OPT_TSPEED = 32.chr # " " # "\x20" # Terminal Speed
- OPT_LFLOW = 33.chr # "!" # "\x21" # Remote Flow Control
- OPT_LINEMODE = 34.chr # "\"" # "\x22" # Linemode
- OPT_XDISPLOC = 35.chr # "#" # "\x23" # X Display Location
- OPT_OLD_ENVIRON = 36.chr # "$" # "\x24" # Environment Option
- OPT_AUTHENTICATION = 37.chr # "%" # "\x25" # Authentication Option
- OPT_ENCRYPT = 38.chr # "&" # "\x26" # Encryption Option
- OPT_NEW_ENVIRON = 39.chr # "'" # "\x27" # New Environment Option
- OPT_EXOPL = 255.chr # "\377" # "\xff" # Extended-Options-List
-
- NULL = "\000"
- CR = "\015"
- LF = "\012"
- EOL = CR + LF
- REVISION = '$Id$'
- # :startdoc:
-
- #
- # Creates a new Net::Telnet object.
- #
- # Attempts to connect to the host (unless the Proxy option is
- # provided: see below). If a block is provided, it is yielded
- # status messages on the attempt to connect to the server, of
- # the form:
- #
- # Trying localhost...
- # Connected to localhost.
- #
- # +options+ is a hash of options. The following example lists
- # all options and their default values.
- #
- # host = Net::Telnet::new(
- # "Host" => "localhost", # default: "localhost"
- # "Port" => 23, # default: 23
- # "Binmode" => false, # default: false
- # "Output_log" => "output_log", # default: nil (no output)
- # "Dump_log" => "dump_log", # default: nil (no output)
- # "Prompt" => /[$%#>] \z/n, # default: /[$%#>] \z/n
- # "Telnetmode" => true, # default: true
- # "Timeout" => 10, # default: 10
- # # if ignore timeout then set "Timeout" to false.
- # "Waittime" => 0, # default: 0
- # "Proxy" => proxy # default: nil
- # # proxy is Net::Telnet or IO object
- # )
- #
- # The options have the following meanings:
- #
- # Host:: the hostname or IP address of the host to connect to, as a String.
- # Defaults to "localhost".
- #
- # Port:: the port to connect to. Defaults to 23.
- #
- # Binmode:: if false (the default), newline substitution is performed.
- # Outgoing LF is
- # converted to CRLF, and incoming CRLF is converted to LF. If
- # true, this substitution is not performed. This value can
- # also be set with the #binmode() method. The
- # outgoing conversion only applies to the #puts() and #print()
- # methods, not the #write() method. The precise nature of
- # the newline conversion is also affected by the telnet options
- # SGA and BIN.
- #
- # Output_log:: the name of the file to write connection status messages
- # and all received traffic to. In the case of a proper
- # Telnet session, this will include the client input as
- # echoed by the host; otherwise, it only includes server
- # responses. Output is appended verbatim to this file.
- # By default, no output log is kept.
- #
- # Dump_log:: as for Output_log, except that output is written in hexdump
- # format (16 bytes per line as hex pairs, followed by their
- # printable equivalent), with connection status messages
- # preceded by '#', sent traffic preceded by '>', and
- # received traffic preceded by '<'. By default, not dump log
- # is kept.
- #
- # Prompt:: a regular expression matching the host's command-line prompt
- # sequence. This is needed by the Telnet class to determine
- # when the output from a command has finished and the host is
- # ready to receive a new command. By default, this regular
- # expression is /[$%#>] \z/n.
- #
- # Telnetmode:: a boolean value, true by default. In telnet mode,
- # traffic received from the host is parsed for special
- # command sequences, and these sequences are escaped
- # in outgoing traffic sent using #puts() or #print()
- # (but not #write()). If you are using the Net::Telnet
- # object to connect to a non-telnet service (such as
- # SMTP or POP), this should be set to "false" to prevent
- # undesired data corruption. This value can also be set
- # by the #telnetmode() method.
- #
- # Timeout:: the number of seconds to wait before timing out both the
- # initial attempt to connect to host (in this constructor),
- # which raises a Net::OpenTimeout, and all attempts to read data
- # from the host, which raises a Net::ReadTimeout (in #waitfor(),
- # #cmd(), and #login()). The default value is 10 seconds.
- # You can disable the timeout by setting this value to false.
- # In this case, the connect attempt will eventually timeout
- # on the underlying connect(2) socket call with an
- # Errno::ETIMEDOUT error (but generally only after a few
- # minutes), but other attempts to read data from the host
- # will hang indefinitely if no data is forthcoming.
- #
- # Waittime:: the amount of time to wait after seeing what looks like a
- # prompt (that is, received data that matches the Prompt
- # option regular expression) to see if more data arrives.
- # If more data does arrive in this time, Net::Telnet assumes
- # that what it saw was not really a prompt. This is to try to
- # avoid false matches, but it can also lead to missing real
- # prompts (if, for instance, a background process writes to
- # the terminal soon after the prompt is displayed). By
- # default, set to 0, meaning not to wait for more data.
- #
- # Proxy:: a proxy object to used instead of opening a direct connection
- # to the host. Must be either another Net::Telnet object or
- # an IO object. If it is another Net::Telnet object, this
- # instance will use that one's socket for communication. If an
- # IO object, it is used directly for communication. Any other
- # kind of object will cause an error to be raised.
- #
- def initialize(options) # :yield: mesg
- @options = options
- @options["Host"] = "localhost" unless @options.has_key?("Host")
- @options["Port"] = 23 unless @options.has_key?("Port")
- @options["Prompt"] = /[$%#>] \z/n unless @options.has_key?("Prompt")
- @options["Timeout"] = 10 unless @options.has_key?("Timeout")
- @options["Waittime"] = 0 unless @options.has_key?("Waittime")
- unless @options.has_key?("Binmode")
- @options["Binmode"] = false
- else
- unless (true == @options["Binmode"] or false == @options["Binmode"])
- raise ArgumentError, "Binmode option must be true or false"
- end
- end
-
- unless @options.has_key?("Telnetmode")
- @options["Telnetmode"] = true
- else
- unless (true == @options["Telnetmode"] or false == @options["Telnetmode"])
- raise ArgumentError, "Telnetmode option must be true or false"
- end
- end
-
- @telnet_option = { "SGA" => false, "BINARY" => false }
-
- if @options.has_key?("Output_log")
- @log = File.open(@options["Output_log"], 'a+')
- @log.sync = true
- @log.binmode
- end
-
- if @options.has_key?("Dump_log")
- @dumplog = File.open(@options["Dump_log"], 'a+')
- @dumplog.sync = true
- @dumplog.binmode
- def @dumplog.log_dump(dir, x) # :nodoc:
- len = x.length
- addr = 0
- offset = 0
- while 0 < len
- if len < 16
- line = x[offset, len]
- else
- line = x[offset, 16]
- end
- hexvals = line.unpack('H*')[0]
- hexvals += ' ' * (32 - hexvals.length)
- hexvals = format("%s %s %s %s " * 4, *hexvals.unpack('a2' * 16))
- line = line.gsub(/[\000-\037\177-\377]/n, '.')
- printf "%s 0x%5.5x: %s%s\n", dir, addr, hexvals, line
- addr += 16
- offset += 16
- len -= 16
- end
- print "\n"
- end
- end
-
- if @options.has_key?("Proxy")
- if @options["Proxy"].kind_of?(Net::Telnet)
- @sock = @options["Proxy"].sock
- elsif @options["Proxy"].kind_of?(IO)
- @sock = @options["Proxy"]
- else
- raise "Error: Proxy must be an instance of Net::Telnet or IO."
- end
- else
- message = "Trying " + @options["Host"] + "...\n"
- yield(message) if block_given?
- @log.write(message) if @options.has_key?("Output_log")
- @dumplog.log_dump('#', message) if @options.has_key?("Dump_log")
-
- begin
- if @options["Timeout"] == false
- @sock = TCPSocket.open(@options["Host"], @options["Port"])
- else
- Timeout.timeout(@options["Timeout"], Net::OpenTimeout) do
- @sock = TCPSocket.open(@options["Host"], @options["Port"])
- end
- end
- rescue Net::OpenTimeout
- raise Net::OpenTimeout, "timed out while opening a connection to the host"
- rescue
- @log.write($ERROR_INFO.to_s + "\n") if @options.has_key?("Output_log")
- @dumplog.log_dump('#', $ERROR_INFO.to_s + "\n") if @options.has_key?("Dump_log")
- raise
- end
- @sock.sync = true
- @sock.binmode
-
- message = "Connected to " + @options["Host"] + ".\n"
- yield(message) if block_given?
- @log.write(message) if @options.has_key?("Output_log")
- @dumplog.log_dump('#', message) if @options.has_key?("Dump_log")
- end
-
- end # initialize
-
- # The socket the Telnet object is using. Note that this object becomes
- # a delegate of the Telnet object, so normally you invoke its methods
- # directly on the Telnet object.
- attr_reader :sock
-
- # Set telnet command interpretation on (+mode+ == true) or off
- # (+mode+ == false), or return the current value (+mode+ not
- # provided). It should be on for true telnet sessions, off if
- # using Net::Telnet to connect to a non-telnet service such
- # as SMTP.
- def telnetmode(mode = nil)
- case mode
- when nil
- @options["Telnetmode"]
- when true, false
- @options["Telnetmode"] = mode
- else
- raise ArgumentError, "argument must be true or false, or missing"
- end
- end
-
- # Turn telnet command interpretation on (true) or off (false). It
- # should be on for true telnet sessions, off if using Net::Telnet
- # to connect to a non-telnet service such as SMTP.
- def telnetmode=(mode)
- if (true == mode or false == mode)
- @options["Telnetmode"] = mode
- else
- raise ArgumentError, "argument must be true or false"
- end
- end
-
- # Turn newline conversion on (+mode+ == false) or off (+mode+ == true),
- # or return the current value (+mode+ is not specified).
- def binmode(mode = nil)
- case mode
- when nil
- @options["Binmode"]
- when true, false
- @options["Binmode"] = mode
- else
- raise ArgumentError, "argument must be true or false"
- end
- end
-
- # Turn newline conversion on (false) or off (true).
- def binmode=(mode)
- if (true == mode or false == mode)
- @options["Binmode"] = mode
- else
- raise ArgumentError, "argument must be true or false"
- end
- end
-
- # Preprocess received data from the host.
- #
- # Performs newline conversion and detects telnet command sequences.
- # Called automatically by #waitfor(). You should only use this
- # method yourself if you have read input directly using sysread()
- # or similar, and even then only if in telnet mode.
- def preprocess(string)
- # combine CR+NULL into CR
- string = string.gsub(/#{CR}#{NULL}/no, CR) if @options["Telnetmode"]
-
- # combine EOL into "\n"
- string = string.gsub(/#{EOL}/no, "\n") unless @options["Binmode"]
-
- # remove NULL
- string = string.gsub(/#{NULL}/no, '') unless @options["Binmode"]
-
- string.gsub(/#{IAC}(
- [#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]|
- [#{DO}#{DONT}#{WILL}#{WONT}]
- [#{OPT_BINARY}-#{OPT_NEW_ENVIRON}#{OPT_EXOPL}]|
- #{SB}[^#{IAC}]*#{IAC}#{SE}
- )/xno) do
- if IAC == $1 # handle escaped IAC characters
- IAC
- elsif AYT == $1 # respond to "IAC AYT" (are you there)
- self.write("nobody here but us pigeons" + EOL)
- ''
- elsif DO[0] == $1[0] # respond to "IAC DO x"
- if OPT_BINARY[0] == $1[1]
- @telnet_option["BINARY"] = true
- self.write(IAC + WILL + OPT_BINARY)
- else
- self.write(IAC + WONT + $1[1..1])
- end
- ''
- elsif DONT[0] == $1[0] # respond to "IAC DON'T x" with "IAC WON'T x"
- self.write(IAC + WONT + $1[1..1])
- ''
- elsif WILL[0] == $1[0] # respond to "IAC WILL x"
- if OPT_BINARY[0] == $1[1]
- self.write(IAC + DO + OPT_BINARY)
- elsif OPT_ECHO[0] == $1[1]
- self.write(IAC + DO + OPT_ECHO)
- elsif OPT_SGA[0] == $1[1]
- @telnet_option["SGA"] = true
- self.write(IAC + DO + OPT_SGA)
- else
- self.write(IAC + DONT + $1[1..1])
- end
- ''
- elsif WONT[0] == $1[0] # respond to "IAC WON'T x"
- if OPT_ECHO[0] == $1[1]
- self.write(IAC + DONT + OPT_ECHO)
- elsif OPT_SGA[0] == $1[1]
- @telnet_option["SGA"] = false
- self.write(IAC + DONT + OPT_SGA)
- else
- self.write(IAC + DONT + $1[1..1])
- end
- ''
- else
- ''
- end
- end
- end # preprocess
-
- # Read data from the host until a certain sequence is matched.
- #
- # If a block is given, the received data will be yielded as it
- # is read in (not necessarily all in one go), or nil if EOF
- # occurs before any data is received. Whether a block is given
- # or not, all data read will be returned in a single string, or again
- # nil if EOF occurs before any data is received. Note that
- # received data includes the matched sequence we were looking for.
- #
- # +options+ can be either a regular expression or a hash of options.
- # If a regular expression, this specifies the data to wait for.
- # If a hash, this can specify the following options:
- #
- # Match:: a regular expression, specifying the data to wait for.
- # Prompt:: as for Match; used only if Match is not specified.
- # String:: as for Match, except a string that will be converted
- # into a regular expression. Used only if Match and
- # Prompt are not specified.
- # Timeout:: the number of seconds to wait for data from the host
- # before raising a Timeout::Error. If set to false,
- # no timeout will occur. If not specified, the
- # Timeout option value specified when this instance
- # was created will be used, or, failing that, the
- # default value of 10 seconds.
- # Waittime:: the number of seconds to wait after matching against
- # the input data to see if more data arrives. If more
- # data arrives within this time, we will judge ourselves
- # not to have matched successfully, and will continue
- # trying to match. If not specified, the Waittime option
- # value specified when this instance was created will be
- # used, or, failing that, the default value of 0 seconds,
- # which means not to wait for more input.
- # FailEOF:: if true, when the remote end closes the connection then an
- # EOFError will be raised. Otherwise, defaults to the old
- # behaviour that the function will return whatever data
- # has been received already, or nil if nothing was received.
- #
- def waitfor(options) # :yield: recvdata
- time_out = @options["Timeout"]
- waittime = @options["Waittime"]
- fail_eof = @options["FailEOF"]
-
- if options.kind_of?(Hash)
- prompt = if options.has_key?("Match")
- options["Match"]
- elsif options.has_key?("Prompt")
- options["Prompt"]
- elsif options.has_key?("String")
- Regexp.new( Regexp.quote(options["String"]) )
- end
- time_out = options["Timeout"] if options.has_key?("Timeout")
- waittime = options["Waittime"] if options.has_key?("Waittime")
- fail_eof = options["FailEOF"] if options.has_key?("FailEOF")
- else
- prompt = options
- end
-
- if time_out == false
- time_out = nil
- end
-
- line = ''
- buf = ''
- rest = ''
- until(prompt === line and not IO::select([@sock], nil, nil, waittime))
- unless IO::select([@sock], nil, nil, time_out)
- raise Net::ReadTimeout, "timed out while waiting for more data"
- end
- begin
- c = @sock.readpartial(1024 * 1024)
- @dumplog.log_dump('<', c) if @options.has_key?("Dump_log")
- if @options["Telnetmode"]
- c = rest + c
- if Integer(c.rindex(/#{IAC}#{SE}/no) || 0) <
- Integer(c.rindex(/#{IAC}#{SB}/no) || 0)
- buf = preprocess(c[0 ... c.rindex(/#{IAC}#{SB}/no)])
- rest = c[c.rindex(/#{IAC}#{SB}/no) .. -1]
- elsif pt = c.rindex(/#{IAC}[^#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]?\z/no) ||
- c.rindex(/\r\z/no)
- buf = preprocess(c[0 ... pt])
- rest = c[pt .. -1]
- else
- buf = preprocess(c)
- rest = ''
- end
- else
- # Not Telnetmode.
- #
- # We cannot use preprocess() on this data, because that
- # method makes some Telnetmode-specific assumptions.
- buf = rest + c
- rest = ''
- unless @options["Binmode"]
- if pt = buf.rindex(/\r\z/no)
- buf = buf[0 ... pt]
- rest = buf[pt .. -1]
- end
- buf.gsub!(/#{EOL}/no, "\n")
- end
- end
- @log.print(buf) if @options.has_key?("Output_log")
- line += buf
- yield buf if block_given?
- rescue EOFError # End of file reached
- raise if fail_eof
- if line == ''
- line = nil
- yield nil if block_given?
- end
- break
- end
- end
- line
- end
-
- # Write +string+ to the host.
- #
- # Does not perform any conversions on +string+. Will log +string+ to the
- # dumplog, if the Dump_log option is set.
- def write(string)
- length = string.length
- while 0 < length
- IO::select(nil, [@sock])
- @dumplog.log_dump('>', string[-length..-1]) if @options.has_key?("Dump_log")
- length -= @sock.syswrite(string[-length..-1])
- end
- end
-
- # Sends a string to the host.
- #
- # This does _not_ automatically append a newline to the string. Embedded
- # newlines may be converted and telnet command sequences escaped
- # depending upon the values of telnetmode, binmode, and telnet options
- # set by the host.
- def print(string)
- string = string.gsub(/#{IAC}/no, IAC + IAC) if @options["Telnetmode"]
-
- if @options["Binmode"]
- self.write(string)
- else
- if @telnet_option["BINARY"] and @telnet_option["SGA"]
- # IAC WILL SGA IAC DO BIN send EOL --> CR
- self.write(string.gsub(/\n/n, CR))
- elsif @telnet_option["SGA"]
- # IAC WILL SGA send EOL --> CR+NULL
- self.write(string.gsub(/\n/n, CR + NULL))
- else
- # NONE send EOL --> CR+LF
- self.write(string.gsub(/\n/n, EOL))
- end
- end
- end
-
- # Sends a string to the host.
- #
- # Same as #print(), but appends a newline to the string.
- def puts(string)
- self.print(string + "\n")
- end
-
- # Send a command to the host.
- #
- # More exactly, sends a string to the host, and reads in all received
- # data until is sees the prompt or other matched sequence.
- #
- # If a block is given, the received data will be yielded to it as
- # it is read in. Whether a block is given or not, the received data
- # will be return as a string. Note that the received data includes
- # the prompt and in most cases the host's echo of our command.
- #
- # +options+ is either a String, specified the string or command to
- # send to the host; or it is a hash of options. If a hash, the
- # following options can be specified:
- #
- # String:: the command or other string to send to the host.
- # Match:: a regular expression, the sequence to look for in
- # the received data before returning. If not specified,
- # the Prompt option value specified when this instance
- # was created will be used, or, failing that, the default
- # prompt of /[$%#>] \z/n.
- # Timeout:: the seconds to wait for data from the host before raising
- # a Timeout error. If not specified, the Timeout option
- # value specified when this instance was created will be
- # used, or, failing that, the default value of 10 seconds.
- #
- # The command or other string will have the newline sequence appended
- # to it.
- def cmd(options) # :yield: recvdata
- match = @options["Prompt"]
- time_out = @options["Timeout"]
- fail_eof = @options["FailEOF"]
-
- if options.kind_of?(Hash)
- string = options["String"]
- match = options["Match"] if options.has_key?("Match")
- time_out = options["Timeout"] if options.has_key?("Timeout")
- fail_eof = options["FailEOF"] if options.has_key?("FailEOF")
- else
- string = options
- end
-
- self.puts(string)
- if block_given?
- waitfor({"Prompt" => match, "Timeout" => time_out, "FailEOF" => fail_eof}){|c| yield c }
- else
- waitfor({"Prompt" => match, "Timeout" => time_out, "FailEOF" => fail_eof})
- end
- end
-
- # Login to the host with a given username and password.
- #
- # The username and password can either be provided as two string
- # arguments in that order, or as a hash with keys "Name" and
- # "Password".
- #
- # This method looks for the strings "login" and "Password" from the
- # host to determine when to send the username and password. If the
- # login sequence does not follow this pattern (for instance, you
- # are connecting to a service other than telnet), you will need
- # to handle login yourself.
- #
- # The password can be omitted, either by only
- # provided one String argument, which will be used as the username,
- # or by providing a has that has no "Password" key. In this case,
- # the method will not look for the "Password:" prompt; if it is
- # sent, it will have to be dealt with by later calls.
- #
- # The method returns all data received during the login process from
- # the host, including the echoed username but not the password (which
- # the host should not echo). If a block is passed in, this received
- # data is also yielded to the block as it is received.
- def login(options, password = nil) # :yield: recvdata
- login_prompt = /[Ll]ogin[: ]*\z/n
- password_prompt = /[Pp]ass(?:word|phrase)[: ]*\z/n
- if options.kind_of?(Hash)
- username = options["Name"]
- password = options["Password"]
- login_prompt = options["LoginPrompt"] if options["LoginPrompt"]
- password_prompt = options["PasswordPrompt"] if options["PasswordPrompt"]
- else
- username = options
- end
-
- if block_given?
- line = waitfor(login_prompt){|c| yield c }
- if password
- line += cmd({"String" => username,
- "Match" => password_prompt}){|c| yield c }
- line += cmd(password){|c| yield c }
- else
- line += cmd(username){|c| yield c }
- end
- else
- line = waitfor(login_prompt)
- if password
- line += cmd({"String" => username,
- "Match" => password_prompt})
- line += cmd(password)
- else
- line += cmd(username)
- end
- end
- line
- end
-
- # Closes the connection
- def close
- @sock.close
- end
-
- end # class Telnet
-end # module Net
-
diff --git a/ruby_2_2/lib/observer.rb b/ruby_2_2/lib/observer.rb
deleted file mode 100644
index 10f2eb0db5..0000000000
--- a/ruby_2_2/lib/observer.rb
+++ /dev/null
@@ -1,203 +0,0 @@
-#
-# Implementation of the _Observer_ object-oriented design pattern. The
-# following documentation is copied, with modifications, from "Programming
-# Ruby", by Hunt and Thomas; http://www.ruby-doc.org/docs/ProgrammingRuby/html/lib_patterns.html.
-#
-# See Observable for more info.
-
-# The Observer pattern (also known as publish/subscribe) provides a simple
-# mechanism for one object to inform a set of interested third-party objects
-# when its state changes.
-#
-# == Mechanism
-#
-# The notifying class mixes in the +Observable+
-# module, which provides the methods for managing the associated observer
-# objects.
-#
-# The observable object must:
-# * assert that it has +#changed+
-# * call +#notify_observers+
-#
-# An observer subscribes to updates using Observable#add_observer, which also
-# specifies the method called via #notify_observers. The default method for
-# #notify_observers is #update.
-#
-# === Example
-#
-# The following example demonstrates this nicely. A +Ticker+, when run,
-# continually receives the stock +Price+ for its <tt>@symbol</tt>. A +Warner+
-# is a general observer of the price, and two warners are demonstrated, a
-# +WarnLow+ and a +WarnHigh+, which print a warning if the price is below or
-# above their set limits, respectively.
-#
-# The +update+ callback allows the warners to run without being explicitly
-# called. The system is set up with the +Ticker+ and several observers, and the
-# observers do their duty without the top-level code having to interfere.
-#
-# Note that the contract between publisher and subscriber (observable and
-# observer) is not declared or enforced. The +Ticker+ publishes a time and a
-# price, and the warners receive that. But if you don't ensure that your
-# contracts are correct, nothing else can warn you.
-#
-# require "observer"
-#
-# class Ticker ### Periodically fetch a stock price.
-# include Observable
-#
-# def initialize(symbol)
-# @symbol = symbol
-# end
-#
-# def run
-# last_price = nil
-# loop do
-# price = Price.fetch(@symbol)
-# print "Current price: #{price}\n"
-# if price != last_price
-# changed # notify observers
-# last_price = price
-# notify_observers(Time.now, price)
-# end
-# sleep 1
-# end
-# end
-# end
-#
-# class Price ### A mock class to fetch a stock price (60 - 140).
-# def self.fetch(symbol)
-# 60 + rand(80)
-# end
-# end
-#
-# class Warner ### An abstract observer of Ticker objects.
-# def initialize(ticker, limit)
-# @limit = limit
-# ticker.add_observer(self)
-# end
-# end
-#
-# class WarnLow < Warner
-# def update(time, price) # callback for observer
-# if price < @limit
-# print "--- #{time.to_s}: Price below #@limit: #{price}\n"
-# end
-# end
-# end
-#
-# class WarnHigh < Warner
-# def update(time, price) # callback for observer
-# if price > @limit
-# print "+++ #{time.to_s}: Price above #@limit: #{price}\n"
-# end
-# end
-# end
-#
-# ticker = Ticker.new("MSFT")
-# WarnLow.new(ticker, 80)
-# WarnHigh.new(ticker, 120)
-# ticker.run
-#
-# Produces:
-#
-# Current price: 83
-# Current price: 75
-# --- Sun Jun 09 00:10:25 CDT 2002: Price below 80: 75
-# Current price: 90
-# Current price: 134
-# +++ Sun Jun 09 00:10:25 CDT 2002: Price above 120: 134
-# Current price: 134
-# Current price: 112
-# Current price: 79
-# --- Sun Jun 09 00:10:25 CDT 2002: Price below 80: 79
-module Observable
-
- #
- # Add +observer+ as an observer on this object. so that it will receive
- # notifications.
- #
- # +observer+:: the object that will be notified of changes.
- # +func+:: Symbol naming the method that will be called when this Observable
- # has changes.
- #
- # This method must return true for +observer.respond_to?+ and will
- # receive <tt>*arg</tt> when #notify_observers is called, where
- # <tt>*arg</tt> is the value passed to #notify_observers by this
- # Observable
- def add_observer(observer, func=:update)
- @observer_peers = {} unless defined? @observer_peers
- unless observer.respond_to? func
- raise NoMethodError, "observer does not respond to `#{func}'"
- end
- @observer_peers[observer] = func
- end
-
- #
- # Remove +observer+ as an observer on this object so that it will no longer
- # receive notifications.
- #
- # +observer+:: An observer of this Observable
- def delete_observer(observer)
- @observer_peers.delete observer if defined? @observer_peers
- end
-
- #
- # Remove all observers associated with this object.
- #
- def delete_observers
- @observer_peers.clear if defined? @observer_peers
- end
-
- #
- # Return the number of observers associated with this object.
- #
- def count_observers
- if defined? @observer_peers
- @observer_peers.size
- else
- 0
- end
- end
-
- #
- # Set the changed state of this object. Notifications will be sent only if
- # the changed +state+ is +true+.
- #
- # +state+:: Boolean indicating the changed state of this Observable.
- #
- def changed(state=true)
- @observer_state = state
- end
-
- #
- # Returns true if this object's state has been changed since the last
- # #notify_observers call.
- #
- def changed?
- if defined? @observer_state and @observer_state
- true
- else
- false
- end
- end
-
- #
- # Notify observers of a change in state *if* this object's changed state is
- # +true+.
- #
- # This will invoke the method named in #add_observer, passing <tt>*arg</tt>.
- # The changed state is then set to +false+.
- #
- # <tt>*arg</tt>:: Any arguments to pass to the observers.
- def notify_observers(*arg)
- if defined? @observer_state and @observer_state
- if defined? @observer_peers
- @observer_peers.each do |k, v|
- k.send v, *arg
- end
- end
- @observer_state = false
- end
- end
-
-end
diff --git a/ruby_2_2/lib/open-uri.rb b/ruby_2_2/lib/open-uri.rb
deleted file mode 100644
index e49a09b192..0000000000
--- a/ruby_2_2/lib/open-uri.rb
+++ /dev/null
@@ -1,801 +0,0 @@
-require 'uri'
-require 'stringio'
-require 'time'
-
-module Kernel
- private
- alias open_uri_original_open open # :nodoc:
- class << self
- alias open_uri_original_open open # :nodoc:
- end
-
- # Allows the opening of various resources including URIs.
- #
- # If the first argument responds to the 'open' method, 'open' is called on
- # it with the rest of the arguments.
- #
- # If the first argument is a string that begins with xxx://, it is parsed by
- # URI.parse. If the parsed object responds to the 'open' method,
- # 'open' is called on it with the rest of the arguments.
- #
- # Otherwise, the original Kernel#open is called.
- #
- # OpenURI::OpenRead#open provides URI::HTTP#open, URI::HTTPS#open and
- # URI::FTP#open, Kernel#open.
- #
- # We can accept URIs and strings that begin with http://, https:// and
- # ftp://. In these cases, the opened file object is extended by OpenURI::Meta.
- def open(name, *rest, &block) # :doc:
- if name.respond_to?(:open)
- name.open(*rest, &block)
- elsif name.respond_to?(:to_str) &&
- %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ name &&
- (uri = URI.parse(name)).respond_to?(:open)
- uri.open(*rest, &block)
- else
- open_uri_original_open(name, *rest, &block)
- end
- end
- module_function :open
-end
-
-# OpenURI is an easy-to-use wrapper for Net::HTTP, Net::HTTPS and Net::FTP.
-#
-# == Example
-#
-# It is possible to open an http, https or ftp URL as though it were a file:
-#
-# open("http://www.ruby-lang.org/") {|f|
-# f.each_line {|line| p line}
-# }
-#
-# The opened file has several getter methods for its meta-information, as
-# follows, since it is extended by OpenURI::Meta.
-#
-# open("http://www.ruby-lang.org/en") {|f|
-# f.each_line {|line| p line}
-# p f.base_uri # <URI::HTTP:0x40e6ef2 URL:http://www.ruby-lang.org/en/>
-# p f.content_type # "text/html"
-# p f.charset # "iso-8859-1"
-# p f.content_encoding # []
-# p f.last_modified # Thu Dec 05 02:45:02 UTC 2002
-# }
-#
-# Additional header fields can be specified by an optional hash argument.
-#
-# open("http://www.ruby-lang.org/en/",
-# "User-Agent" => "Ruby/#{RUBY_VERSION}",
-# "From" => "foo@bar.invalid",
-# "Referer" => "http://www.ruby-lang.org/") {|f|
-# # ...
-# }
-#
-# The environment variables such as http_proxy, https_proxy and ftp_proxy
-# are in effect by default. Here we disable proxy:
-#
-# open("http://www.ruby-lang.org/en/", :proxy => nil) {|f|
-# # ...
-# }
-#
-# See OpenURI::OpenRead.open and Kernel#open for more on available options.
-#
-# URI objects can be opened in a similar way.
-#
-# uri = URI.parse("http://www.ruby-lang.org/en/")
-# uri.open {|f|
-# # ...
-# }
-#
-# URI objects can be read directly. The returned string is also extended by
-# OpenURI::Meta.
-#
-# str = uri.read
-# p str.base_uri
-#
-# Author:: Tanaka Akira <akr@m17n.org>
-
-module OpenURI
- Options = {
- :proxy => true,
- :proxy_http_basic_authentication => true,
- :progress_proc => true,
- :content_length_proc => true,
- :http_basic_authentication => true,
- :read_timeout => true,
- :open_timeout => true,
- :ssl_ca_cert => nil,
- :ssl_verify_mode => nil,
- :ftp_active_mode => false,
- :redirect => true,
- }
-
- def OpenURI.check_options(options) # :nodoc:
- options.each {|k, v|
- next unless Symbol === k
- unless Options.include? k
- raise ArgumentError, "unrecognized option: #{k}"
- end
- }
- end
-
- def OpenURI.scan_open_optional_arguments(*rest) # :nodoc:
- if !rest.empty? && (String === rest.first || Integer === rest.first)
- mode = rest.shift
- if !rest.empty? && Integer === rest.first
- perm = rest.shift
- end
- end
- return mode, perm, rest
- end
-
- def OpenURI.open_uri(name, *rest) # :nodoc:
- uri = URI::Generic === name ? name : URI.parse(name)
- mode, _, rest = OpenURI.scan_open_optional_arguments(*rest)
- options = rest.shift if !rest.empty? && Hash === rest.first
- raise ArgumentError.new("extra arguments") if !rest.empty?
- options ||= {}
- OpenURI.check_options(options)
-
- if /\Arb?(?:\Z|:([^:]+))/ =~ mode
- encoding, = $1,Encoding.find($1) if $1
- mode = nil
- end
-
- unless mode == nil ||
- mode == 'r' || mode == 'rb' ||
- mode == File::RDONLY
- raise ArgumentError.new("invalid access mode #{mode} (#{uri.class} resource is read only.)")
- end
-
- io = open_loop(uri, options)
- io.set_encoding(encoding) if encoding
- if block_given?
- begin
- yield io
- ensure
- if io.respond_to? :close!
- io.close! # Tempfile
- else
- io.close if !io.closed?
- end
- end
- else
- io
- end
- end
-
- def OpenURI.open_loop(uri, options) # :nodoc:
- proxy_opts = []
- proxy_opts << :proxy_http_basic_authentication if options.include? :proxy_http_basic_authentication
- proxy_opts << :proxy if options.include? :proxy
- proxy_opts.compact!
- if 1 < proxy_opts.length
- raise ArgumentError, "multiple proxy options specified"
- end
- case proxy_opts.first
- when :proxy_http_basic_authentication
- opt_proxy, proxy_user, proxy_pass = options.fetch(:proxy_http_basic_authentication)
- proxy_user = proxy_user.to_str
- proxy_pass = proxy_pass.to_str
- if opt_proxy == true
- raise ArgumentError.new("Invalid authenticated proxy option: #{options[:proxy_http_basic_authentication].inspect}")
- end
- when :proxy
- opt_proxy = options.fetch(:proxy)
- proxy_user = nil
- proxy_pass = nil
- when nil
- opt_proxy = true
- proxy_user = nil
- proxy_pass = nil
- end
- case opt_proxy
- when true
- find_proxy = lambda {|u| pxy = u.find_proxy; pxy ? [pxy, nil, nil] : nil}
- when nil, false
- find_proxy = lambda {|u| nil}
- when String
- opt_proxy = URI.parse(opt_proxy)
- find_proxy = lambda {|u| [opt_proxy, proxy_user, proxy_pass]}
- when URI::Generic
- find_proxy = lambda {|u| [opt_proxy, proxy_user, proxy_pass]}
- else
- raise ArgumentError.new("Invalid proxy option: #{opt_proxy}")
- end
-
- uri_set = {}
- buf = nil
- while true
- redirect = catch(:open_uri_redirect) {
- buf = Buffer.new
- uri.buffer_open(buf, find_proxy.call(uri), options)
- nil
- }
- if redirect
- if redirect.relative?
- # Although it violates RFC2616, Location: field may have relative
- # URI. It is converted to absolute URI using uri as a base URI.
- redirect = uri + redirect
- end
- if !options.fetch(:redirect, true)
- raise HTTPRedirect.new(buf.io.status.join(' '), buf.io, redirect)
- end
- unless OpenURI.redirectable?(uri, redirect)
- raise "redirection forbidden: #{uri} -> #{redirect}"
- end
- if options.include? :http_basic_authentication
- # send authentication only for the URI directly specified.
- options = options.dup
- options.delete :http_basic_authentication
- end
- uri = redirect
- raise "HTTP redirection loop: #{uri}" if uri_set.include? uri.to_s
- uri_set[uri.to_s] = true
- else
- break
- end
- end
- io = buf.io
- io.base_uri = uri
- io
- end
-
- def OpenURI.redirectable?(uri1, uri2) # :nodoc:
- # This test is intended to forbid a redirection from http://... to
- # file:///etc/passwd, file:///dev/zero, etc. CVE-2011-1521
- # https to http redirect is also forbidden intentionally.
- # It avoids sending secure cookie or referer by non-secure HTTP protocol.
- # (RFC 2109 4.3.1, RFC 2965 3.3, RFC 2616 15.1.3)
- # However this is ad hoc. It should be extensible/configurable.
- uri1.scheme.downcase == uri2.scheme.downcase ||
- (/\A(?:http|ftp)\z/i =~ uri1.scheme && /\A(?:http|ftp)\z/i =~ uri2.scheme)
- end
-
- def OpenURI.open_http(buf, target, proxy, options) # :nodoc:
- if proxy
- proxy_uri, proxy_user, proxy_pass = proxy
- raise "Non-HTTP proxy URI: #{proxy_uri}" if proxy_uri.class != URI::HTTP
- end
-
- if target.userinfo
- raise ArgumentError, "userinfo not supported. [RFC3986]"
- end
-
- header = {}
- options.each {|k, v| header[k] = v if String === k }
-
- require 'net/http'
- klass = Net::HTTP
- if URI::HTTP === target
- # HTTP or HTTPS
- if proxy
- if proxy_user && proxy_pass
- klass = Net::HTTP::Proxy(proxy_uri.hostname, proxy_uri.port, proxy_user, proxy_pass)
- else
- klass = Net::HTTP::Proxy(proxy_uri.hostname, proxy_uri.port)
- end
- end
- target_host = target.hostname
- target_port = target.port
- request_uri = target.request_uri
- else
- # FTP over HTTP proxy
- target_host = proxy_uri.hostname
- target_port = proxy_uri.port
- request_uri = target.to_s
- if proxy_user && proxy_pass
- header["Proxy-Authorization"] = 'Basic ' + ["#{proxy_user}:#{proxy_pass}"].pack('m').delete("\r\n")
- end
- end
-
- http = proxy ? klass.new(target_host, target_port) : klass.new(target_host, target_port, nil)
- if target.class == URI::HTTPS
- require 'net/https'
- http.use_ssl = true
- http.verify_mode = options[:ssl_verify_mode] || OpenSSL::SSL::VERIFY_PEER
- store = OpenSSL::X509::Store.new
- if options[:ssl_ca_cert]
- Array(options[:ssl_ca_cert]).each do |cert|
- if File.directory? cert
- store.add_path cert
- else
- store.add_file cert
- end
- end
- else
- store.set_default_paths
- end
- http.cert_store = store
- end
- if options.include? :read_timeout
- http.read_timeout = options[:read_timeout]
- end
- if options.include? :open_timeout
- http.open_timeout = options[:open_timeout]
- end
-
- resp = nil
- http.start {
- req = Net::HTTP::Get.new(request_uri, header)
- if options.include? :http_basic_authentication
- user, pass = options[:http_basic_authentication]
- req.basic_auth user, pass
- end
- http.request(req) {|response|
- resp = response
- if options[:content_length_proc] && Net::HTTPSuccess === resp
- if resp.key?('Content-Length')
- options[:content_length_proc].call(resp['Content-Length'].to_i)
- else
- options[:content_length_proc].call(nil)
- end
- end
- resp.read_body {|str|
- buf << str
- if options[:progress_proc] && Net::HTTPSuccess === resp
- options[:progress_proc].call(buf.size)
- end
- }
- }
- }
- io = buf.io
- io.rewind
- io.status = [resp.code, resp.message]
- resp.each_name {|name| buf.io.meta_add_field2 name, resp.get_fields(name) }
- case resp
- when Net::HTTPSuccess
- when Net::HTTPMovedPermanently, # 301
- Net::HTTPFound, # 302
- Net::HTTPSeeOther, # 303
- Net::HTTPTemporaryRedirect # 307
- begin
- loc_uri = URI.parse(resp['location'])
- rescue URI::InvalidURIError
- raise OpenURI::HTTPError.new(io.status.join(' ') + ' (Invalid Location URI)', io)
- end
- throw :open_uri_redirect, loc_uri
- else
- raise OpenURI::HTTPError.new(io.status.join(' '), io)
- end
- end
-
- class HTTPError < StandardError
- def initialize(message, io)
- super(message)
- @io = io
- end
- attr_reader :io
- end
-
- # Raised on redirection,
- # only occurs when +redirect+ option for HTTP is +false+.
- class HTTPRedirect < HTTPError
- def initialize(message, io, uri)
- super(message, io)
- @uri = uri
- end
- attr_reader :uri
- end
-
- class Buffer # :nodoc: all
- def initialize
- @io = StringIO.new
- @size = 0
- end
- attr_reader :size
-
- StringMax = 10240
- def <<(str)
- @io << str
- @size += str.length
- if StringIO === @io && StringMax < @size
- require 'tempfile'
- io = Tempfile.new('open-uri')
- io.binmode
- Meta.init io, @io if Meta === @io
- io << @io.string
- @io = io
- end
- end
-
- def io
- Meta.init @io unless Meta === @io
- @io
- end
- end
-
- # Mixin for holding meta-information.
- module Meta
- def Meta.init(obj, src=nil) # :nodoc:
- obj.extend Meta
- obj.instance_eval {
- @base_uri = nil
- @meta = {} # name to string. legacy.
- @metas = {} # name to array of strings.
- }
- if src
- obj.status = src.status
- obj.base_uri = src.base_uri
- src.metas.each {|name, values|
- obj.meta_add_field2(name, values)
- }
- end
- end
-
- # returns an Array that consists of status code and message.
- attr_accessor :status
-
- # returns a URI that is the base of relative URIs in the data.
- # It may differ from the URI supplied by a user due to redirection.
- attr_accessor :base_uri
-
- # returns a Hash that represents header fields.
- # The Hash keys are downcased for canonicalization.
- # The Hash values are a field body.
- # If there are multiple field with same field name,
- # the field values are concatenated with a comma.
- attr_reader :meta
-
- # returns a Hash that represents header fields.
- # The Hash keys are downcased for canonicalization.
- # The Hash value are an array of field values.
- attr_reader :metas
-
- def meta_setup_encoding # :nodoc:
- charset = self.charset
- enc = nil
- if charset
- begin
- enc = Encoding.find(charset)
- rescue ArgumentError
- end
- end
- enc = Encoding::ASCII_8BIT unless enc
- if self.respond_to? :force_encoding
- self.force_encoding(enc)
- elsif self.respond_to? :string
- self.string.force_encoding(enc)
- else # Tempfile
- self.set_encoding enc
- end
- end
-
- def meta_add_field2(name, values) # :nodoc:
- name = name.downcase
- @metas[name] = values
- @meta[name] = values.join(', ')
- meta_setup_encoding if name == 'content-type'
- end
-
- def meta_add_field(name, value) # :nodoc:
- meta_add_field2(name, [value])
- end
-
- # returns a Time that represents the Last-Modified field.
- def last_modified
- if vs = @metas['last-modified']
- v = vs.join(', ')
- Time.httpdate(v)
- else
- nil
- end
- end
-
- # :stopdoc:
- RE_LWS = /[\r\n\t ]+/n
- RE_TOKEN = %r{[^\x00- ()<>@,;:\\"/\[\]?={}\x7f]+}n
- RE_QUOTED_STRING = %r{"(?:[\r\n\t !#-\[\]-~\x80-\xff]|\\[\x00-\x7f])*"}n
- RE_PARAMETERS = %r{(?:;#{RE_LWS}?#{RE_TOKEN}#{RE_LWS}?=#{RE_LWS}?(?:#{RE_TOKEN}|#{RE_QUOTED_STRING})#{RE_LWS}?)*}n
- # :startdoc:
-
- def content_type_parse # :nodoc:
- vs = @metas['content-type']
- # The last (?:;#{RE_LWS}?)? matches extra ";" which violates RFC2045.
- if vs && %r{\A#{RE_LWS}?(#{RE_TOKEN})#{RE_LWS}?/(#{RE_TOKEN})#{RE_LWS}?(#{RE_PARAMETERS})(?:;#{RE_LWS}?)?\z}no =~ vs.join(', ')
- type = $1.downcase
- subtype = $2.downcase
- parameters = []
- $3.scan(/;#{RE_LWS}?(#{RE_TOKEN})#{RE_LWS}?=#{RE_LWS}?(?:(#{RE_TOKEN})|(#{RE_QUOTED_STRING}))/no) {|att, val, qval|
- if qval
- val = qval[1...-1].gsub(/[\r\n\t !#-\[\]-~\x80-\xff]+|(\\[\x00-\x7f])/n) { $1 ? $1[1,1] : $& }
- end
- parameters << [att.downcase, val]
- }
- ["#{type}/#{subtype}", *parameters]
- else
- nil
- end
- end
-
- # returns "type/subtype" which is MIME Content-Type.
- # It is downcased for canonicalization.
- # Content-Type parameters are stripped.
- def content_type
- type, *_ = content_type_parse
- type || 'application/octet-stream'
- end
-
- # returns a charset parameter in Content-Type field.
- # It is downcased for canonicalization.
- #
- # If charset parameter is not given but a block is given,
- # the block is called and its result is returned.
- # It can be used to guess charset.
- #
- # If charset parameter and block is not given,
- # nil is returned except text type in HTTP.
- # In that case, "iso-8859-1" is returned as defined by RFC2616 3.7.1.
- def charset
- type, *parameters = content_type_parse
- if pair = parameters.assoc('charset')
- pair.last.downcase
- elsif block_given?
- yield
- elsif type && %r{\Atext/} =~ type &&
- @base_uri && /\Ahttp\z/i =~ @base_uri.scheme
- "iso-8859-1" # RFC2616 3.7.1
- else
- nil
- end
- end
-
- # Returns a list of encodings in Content-Encoding field as an array of
- # strings.
- #
- # The encodings are downcased for canonicalization.
- def content_encoding
- vs = @metas['content-encoding']
- if vs && %r{\A#{RE_LWS}?#{RE_TOKEN}#{RE_LWS}?(?:,#{RE_LWS}?#{RE_TOKEN}#{RE_LWS}?)*}o =~ (v = vs.join(', '))
- v.scan(RE_TOKEN).map {|content_coding| content_coding.downcase}
- else
- []
- end
- end
- end
-
- # Mixin for HTTP and FTP URIs.
- module OpenRead
- # OpenURI::OpenRead#open provides `open' for URI::HTTP and URI::FTP.
- #
- # OpenURI::OpenRead#open takes optional 3 arguments as:
- #
- # OpenURI::OpenRead#open([mode [, perm]] [, options]) [{|io| ... }]
- #
- # OpenURI::OpenRead#open returns an IO-like object if block is not given.
- # Otherwise it yields the IO object and return the value of the block.
- # The IO object is extended with OpenURI::Meta.
- #
- # +mode+ and +perm+ are the same as Kernel#open.
- #
- # However, +mode+ must be read mode because OpenURI::OpenRead#open doesn't
- # support write mode (yet).
- # Also +perm+ is ignored because it is meaningful only for file creation.
- #
- # +options+ must be a hash.
- #
- # Each option with a string key specifies an extra header field for HTTP.
- # I.e., it is ignored for FTP without HTTP proxy.
- #
- # The hash may include other options, where keys are symbols:
- #
- # [:proxy]
- # Synopsis:
- # :proxy => "http://proxy.foo.com:8000/"
- # :proxy => URI.parse("http://proxy.foo.com:8000/")
- # :proxy => true
- # :proxy => false
- # :proxy => nil
- #
- # If :proxy option is specified, the value should be String, URI,
- # boolean or nil.
- #
- # When String or URI is given, it is treated as proxy URI.
- #
- # When true is given or the option itself is not specified,
- # environment variable `scheme_proxy' is examined.
- # `scheme' is replaced by `http', `https' or `ftp'.
- #
- # When false or nil is given, the environment variables are ignored and
- # connection will be made to a server directly.
- #
- # [:proxy_http_basic_authentication]
- # Synopsis:
- # :proxy_http_basic_authentication =>
- # ["http://proxy.foo.com:8000/", "proxy-user", "proxy-password"]
- # :proxy_http_basic_authentication =>
- # [URI.parse("http://proxy.foo.com:8000/"),
- # "proxy-user", "proxy-password"]
- #
- # If :proxy option is specified, the value should be an Array with 3
- # elements. It should contain a proxy URI, a proxy user name and a proxy
- # password. The proxy URI should be a String, an URI or nil. The proxy
- # user name and password should be a String.
- #
- # If nil is given for the proxy URI, this option is just ignored.
- #
- # If :proxy and :proxy_http_basic_authentication is specified,
- # ArgumentError is raised.
- #
- # [:http_basic_authentication]
- # Synopsis:
- # :http_basic_authentication=>[user, password]
- #
- # If :http_basic_authentication is specified,
- # the value should be an array which contains 2 strings:
- # username and password.
- # It is used for HTTP Basic authentication defined by RFC 2617.
- #
- # [:content_length_proc]
- # Synopsis:
- # :content_length_proc => lambda {|content_length| ... }
- #
- # If :content_length_proc option is specified, the option value procedure
- # is called before actual transfer is started.
- # It takes one argument, which is expected content length in bytes.
- #
- # If two or more transfer is done by HTTP redirection, the procedure
- # is called only one for a last transfer.
- #
- # When expected content length is unknown, the procedure is called with
- # nil. This happens when the HTTP response has no Content-Length header.
- #
- # [:progress_proc]
- # Synopsis:
- # :progress_proc => lambda {|size| ...}
- #
- # If :progress_proc option is specified, the proc is called with one
- # argument each time when `open' gets content fragment from network.
- # The argument +size+ is the accumulated transferred size in bytes.
- #
- # If two or more transfer is done by HTTP redirection, the procedure
- # is called only one for a last transfer.
- #
- # :progress_proc and :content_length_proc are intended to be used for
- # progress bar.
- # For example, it can be implemented as follows using Ruby/ProgressBar.
- #
- # pbar = nil
- # open("http://...",
- # :content_length_proc => lambda {|t|
- # if t && 0 < t
- # pbar = ProgressBar.new("...", t)
- # pbar.file_transfer_mode
- # end
- # },
- # :progress_proc => lambda {|s|
- # pbar.set s if pbar
- # }) {|f| ... }
- #
- # [:read_timeout]
- # Synopsis:
- # :read_timeout=>nil (no timeout)
- # :read_timeout=>10 (10 second)
- #
- # :read_timeout option specifies a timeout of read for http connections.
- #
- # [:open_timeout]
- # Synopsis:
- # :open_timeout=>nil (no timeout)
- # :open_timeout=>10 (10 second)
- #
- # :open_timeout option specifies a timeout of open for http connections.
- #
- # [:ssl_ca_cert]
- # Synopsis:
- # :ssl_ca_cert=>filename or an Array of filenames
- #
- # :ssl_ca_cert is used to specify CA certificate for SSL.
- # If it is given, default certificates are not used.
- #
- # [:ssl_verify_mode]
- # Synopsis:
- # :ssl_verify_mode=>mode
- #
- # :ssl_verify_mode is used to specify openssl verify mode.
- #
- # [:ftp_active_mode]
- # Synopsis:
- # :ftp_active_mode=>bool
- #
- # <tt>:ftp_active_mode => true</tt> is used to make ftp active mode.
- # Ruby 1.9 uses passive mode by default.
- # Note that the active mode is default in Ruby 1.8 or prior.
- #
- # [:redirect]
- # Synopsis:
- # :redirect=>bool
- #
- # +:redirect+ is true by default. <tt>:redirect => false</tt> is used to
- # disable all HTTP redirects.
- #
- # OpenURI::HTTPRedirect exception raised on redirection.
- # Using +true+ also means that redirections between http and ftp are
- # permitted.
- #
- def open(*rest, &block)
- OpenURI.open_uri(self, *rest, &block)
- end
-
- # OpenURI::OpenRead#read([options]) reads a content referenced by self and
- # returns the content as string.
- # The string is extended with OpenURI::Meta.
- # The argument +options+ is same as OpenURI::OpenRead#open.
- def read(options={})
- self.open(options) {|f|
- str = f.read
- Meta.init str, f
- str
- }
- end
- end
-end
-
-module URI
- class HTTP
- def buffer_open(buf, proxy, options) # :nodoc:
- OpenURI.open_http(buf, self, proxy, options)
- end
-
- include OpenURI::OpenRead
- end
-
- class FTP
- def buffer_open(buf, proxy, options) # :nodoc:
- if proxy
- OpenURI.open_http(buf, self, proxy, options)
- return
- end
- require 'net/ftp'
-
- path = self.path
- path = path.sub(%r{\A/}, '%2F') # re-encode the beginning slash because uri library decodes it.
- directories = path.split(%r{/}, -1)
- directories.each {|d|
- d.gsub!(/%([0-9A-Fa-f][0-9A-Fa-f])/) { [$1].pack("H2") }
- }
- unless filename = directories.pop
- raise ArgumentError, "no filename: #{self.inspect}"
- end
- directories.each {|d|
- if /[\r\n]/ =~ d
- raise ArgumentError, "invalid directory: #{d.inspect}"
- end
- }
- if /[\r\n]/ =~ filename
- raise ArgumentError, "invalid filename: #{filename.inspect}"
- end
- typecode = self.typecode
- if typecode && /\A[aid]\z/ !~ typecode
- raise ArgumentError, "invalid typecode: #{typecode.inspect}"
- end
-
- # The access sequence is defined by RFC 1738
- ftp = Net::FTP.new
- ftp.connect(self.hostname, self.port)
- ftp.passive = true if !options[:ftp_active_mode]
- # todo: extract user/passwd from .netrc.
- user = 'anonymous'
- passwd = nil
- user, passwd = self.userinfo.split(/:/) if self.userinfo
- ftp.login(user, passwd)
- directories.each {|cwd|
- ftp.voidcmd("CWD #{cwd}")
- }
- if typecode
- # xxx: typecode D is not handled.
- ftp.voidcmd("TYPE #{typecode.upcase}")
- end
- if options[:content_length_proc]
- options[:content_length_proc].call(ftp.size(filename))
- end
- ftp.retrbinary("RETR #{filename}", 4096) { |str|
- buf << str
- options[:progress_proc].call(buf.size) if options[:progress_proc]
- }
- ftp.close
- buf.io.rewind
- end
-
- include OpenURI::OpenRead
- end
-end
diff --git a/ruby_2_2/lib/open3.rb b/ruby_2_2/lib/open3.rb
deleted file mode 100644
index 6ec4a941d2..0000000000
--- a/ruby_2_2/lib/open3.rb
+++ /dev/null
@@ -1,663 +0,0 @@
-#
-# = open3.rb: Popen, but with stderr, too
-#
-# Author:: Yukihiro Matsumoto
-# Documentation:: Konrad Meyer
-#
-# Open3 gives you access to stdin, stdout, and stderr when running other
-# programs.
-#
-
-#
-# Open3 grants you access to stdin, stdout, stderr and a thread to wait for the
-# child process when running another program.
-# You can specify various attributes, redirections, current directory, etc., of
-# the program in the same way as for Process.spawn.
-#
-# - Open3.popen3 : pipes for stdin, stdout, stderr
-# - Open3.popen2 : pipes for stdin, stdout
-# - Open3.popen2e : pipes for stdin, merged stdout and stderr
-# - Open3.capture3 : give a string for stdin; get strings for stdout, stderr
-# - Open3.capture2 : give a string for stdin; get a string for stdout
-# - Open3.capture2e : give a string for stdin; get a string for merged stdout and stderr
-# - Open3.pipeline_rw : pipes for first stdin and last stdout of a pipeline
-# - Open3.pipeline_r : pipe for last stdout of a pipeline
-# - Open3.pipeline_w : pipe for first stdin of a pipeline
-# - Open3.pipeline_start : run a pipeline without waiting
-# - Open3.pipeline : run a pipeline and wait for its completion
-#
-
-module Open3
-
- # Open stdin, stdout, and stderr streams and start external executable.
- # In addition, a thread to wait for the started process is created.
- # The thread has a pid method and a thread variable :pid which is the pid of
- # the started process.
- #
- # Block form:
- #
- # Open3.popen3([env,] cmd... [, opts]) {|stdin, stdout, stderr, wait_thr|
- # pid = wait_thr.pid # pid of the started process.
- # ...
- # exit_status = wait_thr.value # Process::Status object returned.
- # }
- #
- # Non-block form:
- #
- # stdin, stdout, stderr, wait_thr = Open3.popen3([env,] cmd... [, opts])
- # pid = wait_thr[:pid] # pid of the started process
- # ...
- # stdin.close # stdin, stdout and stderr should be closed explicitly in this form.
- # stdout.close
- # stderr.close
- # exit_status = wait_thr.value # Process::Status object returned.
- #
- # The parameters env, cmd, and opts are passed to Process.spawn.
- # A commandline string and a list of argument strings can be accepted as follows:
- #
- # Open3.popen3("echo abc") {|i, o, e, t| ... }
- # Open3.popen3("echo", "abc") {|i, o, e, t| ... }
- # Open3.popen3(["echo", "argv0"], "abc") {|i, o, e, t| ... }
- #
- # If the last parameter, opts, is a Hash, it is recognized as an option for Process.spawn.
- #
- # Open3.popen3("pwd", :chdir=>"/") {|i,o,e,t|
- # p o.read.chomp #=> "/"
- # }
- #
- # wait_thr.value waits for the termination of the process.
- # The block form also waits for the process when it returns.
- #
- # Closing stdin, stdout and stderr does not wait for the process to complete.
- #
- # You should be careful to avoid deadlocks.
- # Since pipes are fixed length buffers,
- # Open3.popen3("prog") {|i, o, e, t| o.read } deadlocks if
- # the program generates too much output on stderr.
- # You should read stdout and stderr simultaneously (using threads or IO.select).
- # However, if you don't need stderr output, you can use Open3.popen2.
- # If merged stdout and stderr output is not a problem, you can use Open3.popen2e.
- # If you really need stdout and stderr output as separate strings, you can consider Open3.capture3.
- #
- def popen3(*cmd, **opts, &block)
- in_r, in_w = IO.pipe
- opts[:in] = in_r
- in_w.sync = true
-
- out_r, out_w = IO.pipe
- opts[:out] = out_w
-
- err_r, err_w = IO.pipe
- opts[:err] = err_w
-
- popen_run(cmd, opts, [in_r, out_w, err_w], [in_w, out_r, err_r], &block)
- end
- module_function :popen3
-
- # Open3.popen2 is similar to Open3.popen3 except that it doesn't create a pipe for
- # the standard error stream.
- #
- # Block form:
- #
- # Open3.popen2([env,] cmd... [, opts]) {|stdin, stdout, wait_thr|
- # pid = wait_thr.pid # pid of the started process.
- # ...
- # exit_status = wait_thr.value # Process::Status object returned.
- # }
- #
- # Non-block form:
- #
- # stdin, stdout, wait_thr = Open3.popen2([env,] cmd... [, opts])
- # ...
- # stdin.close # stdin and stdout should be closed explicitly in this form.
- # stdout.close
- #
- # See Process.spawn for the optional hash arguments _env_ and _opts_.
- #
- # Example:
- #
- # Open3.popen2("wc -c") {|i,o,t|
- # i.print "answer to life the universe and everything"
- # i.close
- # p o.gets #=> "42\n"
- # }
- #
- # Open3.popen2("bc -q") {|i,o,t|
- # i.puts "obase=13"
- # i.puts "6 * 9"
- # p o.gets #=> "42\n"
- # }
- #
- # Open3.popen2("dc") {|i,o,t|
- # i.print "42P"
- # i.close
- # p o.read #=> "*"
- # }
- #
- def popen2(*cmd, **opts, &block)
- in_r, in_w = IO.pipe
- opts[:in] = in_r
- in_w.sync = true
-
- out_r, out_w = IO.pipe
- opts[:out] = out_w
-
- popen_run(cmd, opts, [in_r, out_w], [in_w, out_r], &block)
- end
- module_function :popen2
-
- # Open3.popen2e is similar to Open3.popen3 except that it merges
- # the standard output stream and the standard error stream.
- #
- # Block form:
- #
- # Open3.popen2e([env,] cmd... [, opts]) {|stdin, stdout_and_stderr, wait_thr|
- # pid = wait_thr.pid # pid of the started process.
- # ...
- # exit_status = wait_thr.value # Process::Status object returned.
- # }
- #
- # Non-block form:
- #
- # stdin, stdout_and_stderr, wait_thr = Open3.popen2e([env,] cmd... [, opts])
- # ...
- # stdin.close # stdin and stdout_and_stderr should be closed explicitly in this form.
- # stdout_and_stderr.close
- #
- # See Process.spawn for the optional hash arguments _env_ and _opts_.
- #
- # Example:
- # # check gcc warnings
- # source = "foo.c"
- # Open3.popen2e("gcc", "-Wall", source) {|i,oe,t|
- # oe.each {|line|
- # if /warning/ =~ line
- # ...
- # end
- # }
- # }
- #
- def popen2e(*cmd, **opts, &block)
- in_r, in_w = IO.pipe
- opts[:in] = in_r
- in_w.sync = true
-
- out_r, out_w = IO.pipe
- opts[[:out, :err]] = out_w
-
- popen_run(cmd, opts, [in_r, out_w], [in_w, out_r], &block)
- end
- module_function :popen2e
-
- def popen_run(cmd, opts, child_io, parent_io) # :nodoc:
- pid = spawn(*cmd, opts)
- wait_thr = Process.detach(pid)
- child_io.each {|io| io.close }
- result = [*parent_io, wait_thr]
- if defined? yield
- begin
- return yield(*result)
- ensure
- parent_io.each{|io| io.close unless io.closed?}
- wait_thr.join
- end
- end
- result
- end
- module_function :popen_run
- class << self
- private :popen_run
- end
-
- # Open3.capture3 captures the standard output and the standard error of a command.
- #
- # stdout_str, stderr_str, status = Open3.capture3([env,] cmd... [, opts])
- #
- # The arguments env, cmd and opts are passed to Open3.popen3 except
- # <code>opts[:stdin_data]</code> and <code>opts[:binmode]</code>. See Process.spawn.
- #
- # If <code>opts[:stdin_data]</code> is specified, it is sent to the command's standard input.
- #
- # If <code>opts[:binmode]</code> is true, internal pipes are set to binary mode.
- #
- # Examples:
- #
- # # dot is a command of graphviz.
- # graph = <<'End'
- # digraph g {
- # a -> b
- # }
- # End
- # drawn_graph, dot_log = Open3.capture3("dot -v", :stdin_data=>graph)
- #
- # o, e, s = Open3.capture3("echo abc; sort >&2", :stdin_data=>"foo\nbar\nbaz\n")
- # p o #=> "abc\n"
- # p e #=> "bar\nbaz\nfoo\n"
- # p s #=> #<Process::Status: pid 32682 exit 0>
- #
- # # generate a thumbnail image using the convert command of ImageMagick.
- # # However, if the image is really stored in a file,
- # # system("convert", "-thumbnail", "80", "png:#{filename}", "png:-") is better
- # # because of reduced memory consumption.
- # # But if the image is stored in a DB or generated by the gnuplot Open3.capture2 example,
- # # Open3.capture3 should be considered.
- # #
- # image = File.read("/usr/share/openclipart/png/animals/mammals/sheep-md-v0.1.png", :binmode=>true)
- # thumbnail, err, s = Open3.capture3("convert -thumbnail 80 png:- png:-", :stdin_data=>image, :binmode=>true)
- # if s.success?
- # STDOUT.binmode; print thumbnail
- # end
- #
- def capture3(*cmd, stdin_data: '', binmode: false, **opts)
- popen3(*cmd, opts) {|i, o, e, t|
- if binmode
- i.binmode
- o.binmode
- e.binmode
- end
- out_reader = Thread.new { o.read }
- err_reader = Thread.new { e.read }
- begin
- i.write stdin_data
- rescue Errno::EPIPE
- end
- i.close
- [out_reader.value, err_reader.value, t.value]
- }
- end
- module_function :capture3
-
- # Open3.capture2 captures the standard output of a command.
- #
- # stdout_str, status = Open3.capture2([env,] cmd... [, opts])
- #
- # The arguments env, cmd and opts are passed to Open3.popen3 except
- # <code>opts[:stdin_data]</code> and <code>opts[:binmode]</code>. See Process.spawn.
- #
- # If <code>opts[:stdin_data]</code> is specified, it is sent to the command's standard input.
- #
- # If <code>opts[:binmode]</code> is true, internal pipes are set to binary mode.
- #
- # Example:
- #
- # # factor is a command for integer factorization.
- # o, s = Open3.capture2("factor", :stdin_data=>"42")
- # p o #=> "42: 2 3 7\n"
- #
- # # generate x**2 graph in png using gnuplot.
- # gnuplot_commands = <<"End"
- # set terminal png
- # plot x**2, "-" with lines
- # 1 14
- # 2 1
- # 3 8
- # 4 5
- # e
- # End
- # image, s = Open3.capture2("gnuplot", :stdin_data=>gnuplot_commands, :binmode=>true)
- #
- def capture2(*cmd, stdin_data: nil, binmode: false, **opts)
- popen2(*cmd, opts) {|i, o, t|
- if binmode
- i.binmode
- o.binmode
- end
- out_reader = Thread.new { o.read }
- if stdin_data
- begin
- i.write stdin_data
- rescue Errno::EPIPE
- end
- end
- i.close
- [out_reader.value, t.value]
- }
- end
- module_function :capture2
-
- # Open3.capture2e captures the standard output and the standard error of a command.
- #
- # stdout_and_stderr_str, status = Open3.capture2e([env,] cmd... [, opts])
- #
- # The arguments env, cmd and opts are passed to Open3.popen3 except
- # <code>opts[:stdin_data]</code> and <code>opts[:binmode]</code>. See Process.spawn.
- #
- # If <code>opts[:stdin_data]</code> is specified, it is sent to the command's standard input.
- #
- # If <code>opts[:binmode]</code> is true, internal pipes are set to binary mode.
- #
- # Example:
- #
- # # capture make log
- # make_log, s = Open3.capture2e("make")
- #
- def capture2e(*cmd, stdin_data: nil, binmode: false, **opts)
- popen2e(*cmd, opts) {|i, oe, t|
- if binmode
- i.binmode
- oe.binmode
- end
- outerr_reader = Thread.new { oe.read }
- if stdin_data
- begin
- i.write stdin_data
- rescue Errno::EPIPE
- end
- end
- i.close
- [outerr_reader.value, t.value]
- }
- end
- module_function :capture2e
-
- # Open3.pipeline_rw starts a list of commands as a pipeline with pipes
- # which connect to stdin of the first command and stdout of the last command.
- #
- # Open3.pipeline_rw(cmd1, cmd2, ... [, opts]) {|first_stdin, last_stdout, wait_threads|
- # ...
- # }
- #
- # first_stdin, last_stdout, wait_threads = Open3.pipeline_rw(cmd1, cmd2, ... [, opts])
- # ...
- # first_stdin.close
- # last_stdout.close
- #
- # Each cmd is a string or an array.
- # If it is an array, the elements are passed to Process.spawn.
- #
- # cmd:
- # commandline command line string which is passed to a shell
- # [env, commandline, opts] command line string which is passed to a shell
- # [env, cmdname, arg1, ..., opts] command name and one or more arguments (no shell)
- # [env, [cmdname, argv0], arg1, ..., opts] command name and arguments including argv[0] (no shell)
- #
- # Note that env and opts are optional, as for Process.spawn.
- #
- # The options to pass to Process.spawn are constructed by merging
- # +opts+, the last hash element of the array, and
- # specifications for the pipes between each of the commands.
- #
- # Example:
- #
- # Open3.pipeline_rw("tr -dc A-Za-z", "wc -c") {|i, o, ts|
- # i.puts "All persons more than a mile high to leave the court."
- # i.close
- # p o.gets #=> "42\n"
- # }
- #
- # Open3.pipeline_rw("sort", "cat -n") {|stdin, stdout, wait_thrs|
- # stdin.puts "foo"
- # stdin.puts "bar"
- # stdin.puts "baz"
- # stdin.close # send EOF to sort.
- # p stdout.read #=> " 1\tbar\n 2\tbaz\n 3\tfoo\n"
- # }
- def pipeline_rw(*cmds, **opts, &block)
- in_r, in_w = IO.pipe
- opts[:in] = in_r
- in_w.sync = true
-
- out_r, out_w = IO.pipe
- opts[:out] = out_w
-
- pipeline_run(cmds, opts, [in_r, out_w], [in_w, out_r], &block)
- end
- module_function :pipeline_rw
-
- # Open3.pipeline_r starts a list of commands as a pipeline with a pipe
- # which connects to stdout of the last command.
- #
- # Open3.pipeline_r(cmd1, cmd2, ... [, opts]) {|last_stdout, wait_threads|
- # ...
- # }
- #
- # last_stdout, wait_threads = Open3.pipeline_r(cmd1, cmd2, ... [, opts])
- # ...
- # last_stdout.close
- #
- # Each cmd is a string or an array.
- # If it is an array, the elements are passed to Process.spawn.
- #
- # cmd:
- # commandline command line string which is passed to a shell
- # [env, commandline, opts] command line string which is passed to a shell
- # [env, cmdname, arg1, ..., opts] command name and one or more arguments (no shell)
- # [env, [cmdname, argv0], arg1, ..., opts] command name and arguments including argv[0] (no shell)
- #
- # Note that env and opts are optional, as for Process.spawn.
- #
- # Example:
- #
- # Open3.pipeline_r("zcat /var/log/apache2/access.log.*.gz",
- # [{"LANG"=>"C"}, "grep", "GET /favicon.ico"],
- # "logresolve") {|o, ts|
- # o.each_line {|line|
- # ...
- # }
- # }
- #
- # Open3.pipeline_r("yes", "head -10") {|o, ts|
- # p o.read #=> "y\ny\ny\ny\ny\ny\ny\ny\ny\ny\n"
- # p ts[0].value #=> #<Process::Status: pid 24910 SIGPIPE (signal 13)>
- # p ts[1].value #=> #<Process::Status: pid 24913 exit 0>
- # }
- #
- def pipeline_r(*cmds, **opts, &block)
- out_r, out_w = IO.pipe
- opts[:out] = out_w
-
- pipeline_run(cmds, opts, [out_w], [out_r], &block)
- end
- module_function :pipeline_r
-
- # Open3.pipeline_w starts a list of commands as a pipeline with a pipe
- # which connects to stdin of the first command.
- #
- # Open3.pipeline_w(cmd1, cmd2, ... [, opts]) {|first_stdin, wait_threads|
- # ...
- # }
- #
- # first_stdin, wait_threads = Open3.pipeline_w(cmd1, cmd2, ... [, opts])
- # ...
- # first_stdin.close
- #
- # Each cmd is a string or an array.
- # If it is an array, the elements are passed to Process.spawn.
- #
- # cmd:
- # commandline command line string which is passed to a shell
- # [env, commandline, opts] command line string which is passed to a shell
- # [env, cmdname, arg1, ..., opts] command name and one or more arguments (no shell)
- # [env, [cmdname, argv0], arg1, ..., opts] command name and arguments including argv[0] (no shell)
- #
- # Note that env and opts are optional, as for Process.spawn.
- #
- # Example:
- #
- # Open3.pipeline_w("bzip2 -c", :out=>"/tmp/hello.bz2") {|i, ts|
- # i.puts "hello"
- # }
- #
- def pipeline_w(*cmds, **opts, &block)
- in_r, in_w = IO.pipe
- opts[:in] = in_r
- in_w.sync = true
-
- pipeline_run(cmds, opts, [in_r], [in_w], &block)
- end
- module_function :pipeline_w
-
- # Open3.pipeline_start starts a list of commands as a pipeline.
- # No pipes are created for stdin of the first command and
- # stdout of the last command.
- #
- # Open3.pipeline_start(cmd1, cmd2, ... [, opts]) {|wait_threads|
- # ...
- # }
- #
- # wait_threads = Open3.pipeline_start(cmd1, cmd2, ... [, opts])
- # ...
- #
- # Each cmd is a string or an array.
- # If it is an array, the elements are passed to Process.spawn.
- #
- # cmd:
- # commandline command line string which is passed to a shell
- # [env, commandline, opts] command line string which is passed to a shell
- # [env, cmdname, arg1, ..., opts] command name and one or more arguments (no shell)
- # [env, [cmdname, argv0], arg1, ..., opts] command name and arguments including argv[0] (no shell)
- #
- # Note that env and opts are optional, as for Process.spawn.
- #
- # Example:
- #
- # # Run xeyes in 10 seconds.
- # Open3.pipeline_start("xeyes") {|ts|
- # sleep 10
- # t = ts[0]
- # Process.kill("TERM", t.pid)
- # p t.value #=> #<Process::Status: pid 911 SIGTERM (signal 15)>
- # }
- #
- # # Convert pdf to ps and send it to a printer.
- # # Collect error message of pdftops and lpr.
- # pdf_file = "paper.pdf"
- # printer = "printer-name"
- # err_r, err_w = IO.pipe
- # Open3.pipeline_start(["pdftops", pdf_file, "-"],
- # ["lpr", "-P#{printer}"],
- # :err=>err_w) {|ts|
- # err_w.close
- # p err_r.read # error messages of pdftops and lpr.
- # }
- #
- def pipeline_start(*cmds, **opts, &block)
- if block
- pipeline_run(cmds, opts, [], [], &block)
- else
- ts, = pipeline_run(cmds, opts, [], [])
- ts
- end
- end
- module_function :pipeline_start
-
- # Open3.pipeline starts a list of commands as a pipeline.
- # It waits for the completion of the commands.
- # No pipes are created for stdin of the first command and
- # stdout of the last command.
- #
- # status_list = Open3.pipeline(cmd1, cmd2, ... [, opts])
- #
- # Each cmd is a string or an array.
- # If it is an array, the elements are passed to Process.spawn.
- #
- # cmd:
- # commandline command line string which is passed to a shell
- # [env, commandline, opts] command line string which is passed to a shell
- # [env, cmdname, arg1, ..., opts] command name and one or more arguments (no shell)
- # [env, [cmdname, argv0], arg1, ..., opts] command name and arguments including argv[0] (no shell)
- #
- # Note that env and opts are optional, as Process.spawn.
- #
- # Example:
- #
- # fname = "/usr/share/man/man1/ruby.1.gz"
- # p Open3.pipeline(["zcat", fname], "nroff -man", "less")
- # #=> [#<Process::Status: pid 11817 exit 0>,
- # # #<Process::Status: pid 11820 exit 0>,
- # # #<Process::Status: pid 11828 exit 0>]
- #
- # fname = "/usr/share/man/man1/ls.1.gz"
- # Open3.pipeline(["zcat", fname], "nroff -man", "colcrt")
- #
- # # convert PDF to PS and send to a printer by lpr
- # pdf_file = "paper.pdf"
- # printer = "printer-name"
- # Open3.pipeline(["pdftops", pdf_file, "-"],
- # ["lpr", "-P#{printer}"])
- #
- # # count lines
- # Open3.pipeline("sort", "uniq -c", :in=>"names.txt", :out=>"count")
- #
- # # cyclic pipeline
- # r,w = IO.pipe
- # w.print "ibase=14\n10\n"
- # Open3.pipeline("bc", "tee /dev/tty", :in=>r, :out=>w)
- # #=> 14
- # # 18
- # # 22
- # # 30
- # # 42
- # # 58
- # # 78
- # # 106
- # # 202
- #
- def pipeline(*cmds, **opts)
- pipeline_run(cmds, opts, [], []) {|ts|
- ts.map {|t| t.value }
- }
- end
- module_function :pipeline
-
- def pipeline_run(cmds, pipeline_opts, child_io, parent_io) # :nodoc:
- if cmds.empty?
- raise ArgumentError, "no commands"
- end
-
- opts_base = pipeline_opts.dup
- opts_base.delete :in
- opts_base.delete :out
-
- wait_thrs = []
- r = nil
- cmds.each_with_index {|cmd, i|
- cmd_opts = opts_base.dup
- if String === cmd
- cmd = [cmd]
- else
- cmd_opts.update cmd.pop if Hash === cmd.last
- end
- if i == 0
- if !cmd_opts.include?(:in)
- if pipeline_opts.include?(:in)
- cmd_opts[:in] = pipeline_opts[:in]
- end
- end
- else
- cmd_opts[:in] = r
- end
- if i != cmds.length - 1
- r2, w2 = IO.pipe
- cmd_opts[:out] = w2
- else
- if !cmd_opts.include?(:out)
- if pipeline_opts.include?(:out)
- cmd_opts[:out] = pipeline_opts[:out]
- end
- end
- end
- pid = spawn(*cmd, cmd_opts)
- wait_thrs << Process.detach(pid)
- r.close if r
- w2.close if w2
- r = r2
- }
- result = parent_io + [wait_thrs]
- child_io.each {|io| io.close }
- if defined? yield
- begin
- return yield(*result)
- ensure
- parent_io.each{|io| io.close unless io.closed?}
- wait_thrs.each {|t| t.join }
- end
- end
- result
- end
- module_function :pipeline_run
- class << self
- private :pipeline_run
- end
-
-end
diff --git a/ruby_2_2/lib/optionparser.rb b/ruby_2_2/lib/optionparser.rb
deleted file mode 100644
index d89a4d22fb..0000000000
--- a/ruby_2_2/lib/optionparser.rb
+++ /dev/null
@@ -1 +0,0 @@
-require_relative 'optparse'
diff --git a/ruby_2_2/lib/optparse.rb b/ruby_2_2/lib/optparse.rb
deleted file mode 100644
index fad204b72a..0000000000
--- a/ruby_2_2/lib/optparse.rb
+++ /dev/null
@@ -1,2004 +0,0 @@
-#
-# optparse.rb - command-line option analysis with the OptionParser class.
-#
-# Author:: Nobu Nakada
-# Documentation:: Nobu Nakada and Gavin Sinclair.
-#
-# See OptionParser for documentation.
-#
-
-
-#--
-# == Developer Documentation (not for RDoc output)
-#
-# === Class tree
-#
-# - OptionParser:: front end
-# - OptionParser::Switch:: each switches
-# - OptionParser::List:: options list
-# - OptionParser::ParseError:: errors on parsing
-# - OptionParser::AmbiguousOption
-# - OptionParser::NeedlessArgument
-# - OptionParser::MissingArgument
-# - OptionParser::InvalidOption
-# - OptionParser::InvalidArgument
-# - OptionParser::AmbiguousArgument
-#
-# === Object relationship diagram
-#
-# +--------------+
-# | OptionParser |<>-----+
-# +--------------+ | +--------+
-# | ,-| Switch |
-# on_head -------->+---------------+ / +--------+
-# accept/reject -->| List |<|>-
-# | |<|>- +----------+
-# on ------------->+---------------+ `-| argument |
-# : : | class |
-# +---------------+ |==========|
-# on_tail -------->| | |pattern |
-# +---------------+ |----------|
-# OptionParser.accept ->| DefaultList | |converter |
-# reject |(shared between| +----------+
-# | all instances)|
-# +---------------+
-#
-#++
-#
-# == OptionParser
-#
-# === Introduction
-#
-# OptionParser is a class for command-line option analysis. It is much more
-# advanced, yet also easier to use, than GetoptLong, and is a more Ruby-oriented
-# solution.
-#
-# === Features
-#
-# 1. The argument specification and the code to handle it are written in the
-# same place.
-# 2. It can output an option summary; you don't need to maintain this string
-# separately.
-# 3. Optional and mandatory arguments are specified very gracefully.
-# 4. Arguments can be automatically converted to a specified class.
-# 5. Arguments can be restricted to a certain set.
-#
-# All of these features are demonstrated in the examples below. See
-# #make_switch for full documentation.
-#
-# === Minimal example
-#
-# require 'optparse'
-#
-# options = {}
-# OptionParser.new do |opts|
-# opts.banner = "Usage: example.rb [options]"
-#
-# opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
-# options[:verbose] = v
-# end
-# end.parse!
-#
-# p options
-# p ARGV
-#
-# === Generating Help
-#
-# OptionParser can be used to automatically generate help for the commands you
-# write:
-#
-# require 'optparse'
-#
-# Options = Struct.new(:name)
-#
-# class Parser
-# def self.parse(options)
-# args = Options.new("world")
-#
-# opt_parser = OptionParser.new do |opts|
-# opts.banner = "Usage: example.rb [options]"
-#
-# opts.on("-nNAME", "--name=NAME", "Name to say hello to") do |n|
-# args.name = n
-# end
-#
-# opts.on("-h", "--help", "Prints this help") do
-# puts opts
-# exit
-# end
-# end
-#
-# opt_parser.parse!(options)
-# return args
-# end
-# end
-# options = Parser.parse %w[--help]
-#
-# #=>
-# # Usage: example.rb [options]
-# # -n, --name=NAME Name to say hello to
-# # -h, --help Prints this help#
-#
-# === Complete example
-#
-# The following example is a complete Ruby program. You can run it and see the
-# effect of specifying various options. This is probably the best way to learn
-# the features of +optparse+.
-#
-# require 'optparse'
-# require 'optparse/time'
-# require 'ostruct'
-# require 'pp'
-#
-# class OptparseExample
-#
-# CODES = %w[iso-2022-jp shift_jis euc-jp utf8 binary]
-# CODE_ALIASES = { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
-#
-# #
-# # Return a structure describing the options.
-# #
-# def self.parse(args)
-# # The options specified on the command line will be collected in *options*.
-# # We set default values here.
-# options = OpenStruct.new
-# options.library = []
-# options.inplace = false
-# options.encoding = "utf8"
-# options.transfer_type = :auto
-# options.verbose = false
-#
-# opt_parser = OptionParser.new do |opts|
-# opts.banner = "Usage: example.rb [options]"
-#
-# opts.separator ""
-# opts.separator "Specific options:"
-#
-# # Mandatory argument.
-# opts.on("-r", "--require LIBRARY",
-# "Require the LIBRARY before executing your script") do |lib|
-# options.library << lib
-# end
-#
-# # Optional argument; multi-line description.
-# opts.on("-i", "--inplace [EXTENSION]",
-# "Edit ARGV files in place",
-# " (make backup if EXTENSION supplied)") do |ext|
-# options.inplace = true
-# options.extension = ext || ''
-# options.extension.sub!(/\A\.?(?=.)/, ".") # Ensure extension begins with dot.
-# end
-#
-# # Cast 'delay' argument to a Float.
-# opts.on("--delay N", Float, "Delay N seconds before executing") do |n|
-# options.delay = n
-# end
-#
-# # Cast 'time' argument to a Time object.
-# opts.on("-t", "--time [TIME]", Time, "Begin execution at given time") do |time|
-# options.time = time
-# end
-#
-# # Cast to octal integer.
-# opts.on("-F", "--irs [OCTAL]", OptionParser::OctalInteger,
-# "Specify record separator (default \\0)") do |rs|
-# options.record_separator = rs
-# end
-#
-# # List of arguments.
-# opts.on("--list x,y,z", Array, "Example 'list' of arguments") do |list|
-# options.list = list
-# end
-#
-# # Keyword completion. We are specifying a specific set of arguments (CODES
-# # and CODE_ALIASES - notice the latter is a Hash), and the user may provide
-# # the shortest unambiguous text.
-# code_list = (CODE_ALIASES.keys + CODES).join(',')
-# opts.on("--code CODE", CODES, CODE_ALIASES, "Select encoding",
-# " (#{code_list})") do |encoding|
-# options.encoding = encoding
-# end
-#
-# # Optional argument with keyword completion.
-# opts.on("--type [TYPE]", [:text, :binary, :auto],
-# "Select transfer type (text, binary, auto)") do |t|
-# options.transfer_type = t
-# end
-#
-# # Boolean switch.
-# opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
-# options.verbose = v
-# end
-#
-# opts.separator ""
-# opts.separator "Common options:"
-#
-# # No argument, shows at tail. This will print an options summary.
-# # Try it and see!
-# opts.on_tail("-h", "--help", "Show this message") do
-# puts opts
-# exit
-# end
-#
-# # Another typical switch to print the version.
-# opts.on_tail("--version", "Show version") do
-# puts ::Version.join('.')
-# exit
-# end
-# end
-#
-# opt_parser.parse!(args)
-# options
-# end # parse()
-#
-# end # class OptparseExample
-#
-# options = OptparseExample.parse(ARGV)
-# pp options
-# pp ARGV
-#
-# === Shell Completion
-#
-# For modern shells (e.g. bash, zsh, etc.), you can use shell
-# completion for command line options.
-#
-# === Further documentation
-#
-# The above examples should be enough to learn how to use this class. If you
-# have any questions, file a ticket at http://bugs.ruby-lang.org.
-#
-class OptionParser
- # :stopdoc:
- NoArgument = [NO_ARGUMENT = :NONE, nil].freeze
- RequiredArgument = [REQUIRED_ARGUMENT = :REQUIRED, true].freeze
- OptionalArgument = [OPTIONAL_ARGUMENT = :OPTIONAL, false].freeze
- # :startdoc:
-
- #
- # Keyword completion module. This allows partial arguments to be specified
- # and resolved against a list of acceptable values.
- #
- module Completion
- def self.regexp(key, icase)
- Regexp.new('\A' + Regexp.quote(key).gsub(/\w+\b/, '\&\w*'), icase)
- end
-
- def self.candidate(key, icase = false, pat = nil, &block)
- pat ||= Completion.regexp(key, icase)
- candidates = []
- block.call do |k, *v|
- (if Regexp === k
- kn = "".freeze
- k === key
- else
- kn = defined?(k.id2name) ? k.id2name : k
- pat === kn
- end) or next
- v << k if v.empty?
- candidates << [k, v, kn]
- end
- candidates
- end
-
- def candidate(key, icase = false, pat = nil)
- Completion.candidate(key, icase, pat, &method(:each))
- end
-
- public
- def complete(key, icase = false, pat = nil)
- candidates = candidate(key, icase, pat, &method(:each)).sort_by {|k, v, kn| kn.size}
- if candidates.size == 1
- canon, sw, * = candidates[0]
- elsif candidates.size > 1
- canon, sw, cn = candidates.shift
- candidates.each do |k, v, kn|
- next if sw == v
- if String === cn and String === kn
- if cn.rindex(kn, 0)
- canon, sw, cn = k, v, kn
- next
- elsif kn.rindex(cn, 0)
- next
- end
- end
- throw :ambiguous, key
- end
- end
- if canon
- block_given? or return key, *sw
- yield(key, *sw)
- end
- end
-
- def convert(opt = nil, val = nil, *)
- val
- end
- end
-
-
- #
- # Map from option/keyword string to object with completion.
- #
- class OptionMap < Hash
- include Completion
- end
-
-
- #
- # Individual switch class. Not important to the user.
- #
- # Defined within Switch are several Switch-derived classes: NoArgument,
- # RequiredArgument, etc.
- #
- class Switch
- attr_reader :pattern, :conv, :short, :long, :arg, :desc, :block
-
- #
- # Guesses argument style from +arg+. Returns corresponding
- # OptionParser::Switch class (OptionalArgument, etc.).
- #
- def self.guess(arg)
- case arg
- when ""
- t = self
- when /\A=?\[/
- t = Switch::OptionalArgument
- when /\A\s+\[/
- t = Switch::PlacedArgument
- else
- t = Switch::RequiredArgument
- end
- self >= t or incompatible_argument_styles(arg, t)
- t
- end
-
- def self.incompatible_argument_styles(arg, t)
- raise(ArgumentError, "#{arg}: incompatible argument styles\n #{self}, #{t}",
- ParseError.filter_backtrace(caller(2)))
- end
-
- def self.pattern
- NilClass
- end
-
- def initialize(pattern = nil, conv = nil,
- short = nil, long = nil, arg = nil,
- desc = ([] if short or long), block = Proc.new)
- raise if Array === pattern
- @pattern, @conv, @short, @long, @arg, @desc, @block =
- pattern, conv, short, long, arg, desc, block
- end
-
- #
- # Parses +arg+ and returns rest of +arg+ and matched portion to the
- # argument pattern. Yields when the pattern doesn't match substring.
- #
- def parse_arg(arg)
- pattern or return nil, [arg]
- unless m = pattern.match(arg)
- yield(InvalidArgument, arg)
- return arg, []
- end
- if String === m
- m = [s = m]
- else
- m = m.to_a
- s = m[0]
- return nil, m unless String === s
- end
- raise InvalidArgument, arg unless arg.rindex(s, 0)
- return nil, m if s.length == arg.length
- yield(InvalidArgument, arg) # didn't match whole arg
- return arg[s.length..-1], m
- end
- private :parse_arg
-
- #
- # Parses argument, converts and returns +arg+, +block+ and result of
- # conversion. Yields at semi-error condition instead of raising an
- # exception.
- #
- def conv_arg(arg, val = [])
- if conv
- val = conv.call(*val)
- else
- val = proc {|v| v}.call(*val)
- end
- return arg, block, val
- end
- private :conv_arg
-
- #
- # Produces the summary text. Each line of the summary is yielded to the
- # block (without newline).
- #
- # +sdone+:: Already summarized short style options keyed hash.
- # +ldone+:: Already summarized long style options keyed hash.
- # +width+:: Width of left side (option part). In other words, the right
- # side (description part) starts after +width+ columns.
- # +max+:: Maximum width of left side -> the options are filled within
- # +max+ columns.
- # +indent+:: Prefix string indents all summarized lines.
- #
- def summarize(sdone = [], ldone = [], width = 1, max = width - 1, indent = "")
- sopts, lopts = [], [], nil
- @short.each {|s| sdone.fetch(s) {sopts << s}; sdone[s] = true} if @short
- @long.each {|s| ldone.fetch(s) {lopts << s}; ldone[s] = true} if @long
- return if sopts.empty? and lopts.empty? # completely hidden
-
- left = [sopts.join(', ')]
- right = desc.dup
-
- while s = lopts.shift
- l = left[-1].length + s.length
- l += arg.length if left.size == 1 && arg
- l < max or sopts.empty? or left << ''
- left[-1] << if left[-1].empty? then ' ' * 4 else ', ' end << s
- end
-
- if arg
- left[0] << (left[1] ? arg.sub(/\A(\[?)=/, '\1') + ',' : arg)
- end
- mlen = left.collect {|ss| ss.length}.max.to_i
- while mlen > width and l = left.shift
- mlen = left.collect {|ss| ss.length}.max.to_i if l.length == mlen
- if l.length < width and (r = right[0]) and !r.empty?
- l = l.to_s.ljust(width) + ' ' + r
- right.shift
- end
- yield(indent + l)
- end
-
- while begin l = left.shift; r = right.shift; l or r end
- l = l.to_s.ljust(width) + ' ' + r if r and !r.empty?
- yield(indent + l)
- end
-
- self
- end
-
- def add_banner(to) # :nodoc:
- unless @short or @long
- s = desc.join
- to << " [" + s + "]..." unless s.empty?
- end
- to
- end
-
- def match_nonswitch?(str) # :nodoc:
- @pattern =~ str unless @short or @long
- end
-
- #
- # Main name of the switch.
- #
- def switch_name
- (long.first || short.first).sub(/\A-+(?:\[no-\])?/, '')
- end
-
- def compsys(sdone, ldone) # :nodoc:
- sopts, lopts = [], []
- @short.each {|s| sdone.fetch(s) {sopts << s}; sdone[s] = true} if @short
- @long.each {|s| ldone.fetch(s) {lopts << s}; ldone[s] = true} if @long
- return if sopts.empty? and lopts.empty? # completely hidden
-
- (sopts+lopts).each do |opt|
- # "(-x -c -r)-l[left justify]" \
- if /^--\[no-\](.+)$/ =~ opt
- o = $1
- yield("--#{o}", desc.join(""))
- yield("--no-#{o}", desc.join(""))
- else
- yield("#{opt}", desc.join(""))
- end
- end
- end
-
- #
- # Switch that takes no arguments.
- #
- class NoArgument < self
-
- #
- # Raises an exception if any arguments given.
- #
- def parse(arg, argv)
- yield(NeedlessArgument, arg) if arg
- conv_arg(arg)
- end
-
- def self.incompatible_argument_styles(*)
- end
-
- def self.pattern
- Object
- end
- end
-
- #
- # Switch that takes an argument.
- #
- class RequiredArgument < self
-
- #
- # Raises an exception if argument is not present.
- #
- def parse(arg, argv)
- unless arg
- raise MissingArgument if argv.empty?
- arg = argv.shift
- end
- conv_arg(*parse_arg(arg, &method(:raise)))
- end
- end
-
- #
- # Switch that can omit argument.
- #
- class OptionalArgument < self
-
- #
- # Parses argument if given, or uses default value.
- #
- def parse(arg, argv, &error)
- if arg
- conv_arg(*parse_arg(arg, &error))
- else
- conv_arg(arg)
- end
- end
- end
-
- #
- # Switch that takes an argument, which does not begin with '-'.
- #
- class PlacedArgument < self
-
- #
- # Returns nil if argument is not present or begins with '-'.
- #
- def parse(arg, argv, &error)
- if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
- return nil, block, nil
- end
- opt = (val = parse_arg(val, &error))[1]
- val = conv_arg(*val)
- if opt and !arg
- argv.shift
- else
- val[0] = nil
- end
- val
- end
- end
- end
-
- #
- # Simple option list providing mapping from short and/or long option
- # string to OptionParser::Switch and mapping from acceptable argument to
- # matching pattern and converter pair. Also provides summary feature.
- #
- class List
- # Map from acceptable argument types to pattern and converter pairs.
- attr_reader :atype
-
- # Map from short style option switches to actual switch objects.
- attr_reader :short
-
- # Map from long style option switches to actual switch objects.
- attr_reader :long
-
- # List of all switches and summary string.
- attr_reader :list
-
- #
- # Just initializes all instance variables.
- #
- def initialize
- @atype = {}
- @short = OptionMap.new
- @long = OptionMap.new
- @list = []
- end
-
- #
- # See OptionParser.accept.
- #
- def accept(t, pat = /.*/m, &block)
- if pat
- pat.respond_to?(:match) or
- raise TypeError, "has no `match'", ParseError.filter_backtrace(caller(2))
- else
- pat = t if t.respond_to?(:match)
- end
- unless block
- block = pat.method(:convert).to_proc if pat.respond_to?(:convert)
- end
- @atype[t] = [pat, block]
- end
-
- #
- # See OptionParser.reject.
- #
- def reject(t)
- @atype.delete(t)
- end
-
- #
- # Adds +sw+ according to +sopts+, +lopts+ and +nlopts+.
- #
- # +sw+:: OptionParser::Switch instance to be added.
- # +sopts+:: Short style option list.
- # +lopts+:: Long style option list.
- # +nlopts+:: Negated long style options list.
- #
- def update(sw, sopts, lopts, nsw = nil, nlopts = nil)
- sopts.each {|o| @short[o] = sw} if sopts
- lopts.each {|o| @long[o] = sw} if lopts
- nlopts.each {|o| @long[o] = nsw} if nsw and nlopts
- used = @short.invert.update(@long.invert)
- @list.delete_if {|o| Switch === o and !used[o]}
- end
- private :update
-
- #
- # Inserts +switch+ at the head of the list, and associates short, long
- # and negated long options. Arguments are:
- #
- # +switch+:: OptionParser::Switch instance to be inserted.
- # +short_opts+:: List of short style options.
- # +long_opts+:: List of long style options.
- # +nolong_opts+:: List of long style options with "no-" prefix.
- #
- # prepend(switch, short_opts, long_opts, nolong_opts)
- #
- def prepend(*args)
- update(*args)
- @list.unshift(args[0])
- end
-
- #
- # Appends +switch+ at the tail of the list, and associates short, long
- # and negated long options. Arguments are:
- #
- # +switch+:: OptionParser::Switch instance to be inserted.
- # +short_opts+:: List of short style options.
- # +long_opts+:: List of long style options.
- # +nolong_opts+:: List of long style options with "no-" prefix.
- #
- # append(switch, short_opts, long_opts, nolong_opts)
- #
- def append(*args)
- update(*args)
- @list.push(args[0])
- end
-
- #
- # Searches +key+ in +id+ list. The result is returned or yielded if a
- # block is given. If it isn't found, nil is returned.
- #
- def search(id, key)
- if list = __send__(id)
- val = list.fetch(key) {return nil}
- block_given? ? yield(val) : val
- end
- end
-
- #
- # Searches list +id+ for +opt+ and the optional patterns for completion
- # +pat+. If +icase+ is true, the search is case insensitive. The result
- # is returned or yielded if a block is given. If it isn't found, nil is
- # returned.
- #
- def complete(id, opt, icase = false, *pat, &block)
- __send__(id).complete(opt, icase, *pat, &block)
- end
-
- #
- # Iterates over each option, passing the option to the +block+.
- #
- def each_option(&block)
- list.each(&block)
- end
-
- #
- # Creates the summary table, passing each line to the +block+ (without
- # newline). The arguments +args+ are passed along to the summarize
- # method which is called on every option.
- #
- def summarize(*args, &block)
- sum = []
- list.reverse_each do |opt|
- if opt.respond_to?(:summarize) # perhaps OptionParser::Switch
- s = []
- opt.summarize(*args) {|l| s << l}
- sum.concat(s.reverse)
- elsif !opt or opt.empty?
- sum << ""
- elsif opt.respond_to?(:each_line)
- sum.concat([*opt.each_line].reverse)
- else
- sum.concat([*opt.each].reverse)
- end
- end
- sum.reverse_each(&block)
- end
-
- def add_banner(to) # :nodoc:
- list.each do |opt|
- if opt.respond_to?(:add_banner)
- opt.add_banner(to)
- end
- end
- to
- end
-
- def compsys(*args, &block) # :nodoc:
- list.each do |opt|
- if opt.respond_to?(:compsys)
- opt.compsys(*args, &block)
- end
- end
- end
- end
-
- #
- # Hash with completion search feature. See OptionParser::Completion.
- #
- class CompletingHash < Hash
- include Completion
-
- #
- # Completion for hash key.
- #
- def match(key)
- *values = fetch(key) {
- raise AmbiguousArgument, catch(:ambiguous) {return complete(key)}
- }
- return key, *values
- end
- end
-
- # :stopdoc:
-
- #
- # Enumeration of acceptable argument styles. Possible values are:
- #
- # NO_ARGUMENT:: The switch takes no arguments. (:NONE)
- # REQUIRED_ARGUMENT:: The switch requires an argument. (:REQUIRED)
- # OPTIONAL_ARGUMENT:: The switch requires an optional argument. (:OPTIONAL)
- #
- # Use like --switch=argument (long style) or -Xargument (short style). For
- # short style, only portion matched to argument pattern is treated as
- # argument.
- #
- ArgumentStyle = {}
- NoArgument.each {|el| ArgumentStyle[el] = Switch::NoArgument}
- RequiredArgument.each {|el| ArgumentStyle[el] = Switch::RequiredArgument}
- OptionalArgument.each {|el| ArgumentStyle[el] = Switch::OptionalArgument}
- ArgumentStyle.freeze
-
- #
- # Switches common used such as '--', and also provides default
- # argument classes
- #
- DefaultList = List.new
- DefaultList.short['-'] = Switch::NoArgument.new {}
- DefaultList.long[''] = Switch::NoArgument.new {throw :terminate}
-
-
- COMPSYS_HEADER = <<'XXX' # :nodoc:
-
-typeset -A opt_args
-local context state line
-
-_arguments -s -S \
-XXX
-
- def compsys(to, name = File.basename($0)) # :nodoc:
- to << "#compdef #{name}\n"
- to << COMPSYS_HEADER
- visit(:compsys, {}, {}) {|o, d|
- to << %Q[ "#{o}[#{d.gsub(/[\"\[\]]/, '\\\\\&')}]" \\\n]
- }
- to << " '*:file:_files' && return 0\n"
- end
-
- #
- # Default options for ARGV, which never appear in option summary.
- #
- Officious = {}
-
- #
- # --help
- # Shows option summary.
- #
- Officious['help'] = proc do |parser|
- Switch::NoArgument.new do |arg|
- puts parser.help
- exit
- end
- end
-
- #
- # --*-completion-bash=WORD
- # Shows candidates for command line completion.
- #
- Officious['*-completion-bash'] = proc do |parser|
- Switch::RequiredArgument.new do |arg|
- puts parser.candidate(arg)
- exit
- end
- end
-
- #
- # --*-completion-zsh[=NAME:FILE]
- # Creates zsh completion file.
- #
- Officious['*-completion-zsh'] = proc do |parser|
- Switch::OptionalArgument.new do |arg|
- parser.compsys(STDOUT, arg)
- exit
- end
- end
-
- #
- # --version
- # Shows version string if Version is defined.
- #
- Officious['version'] = proc do |parser|
- Switch::OptionalArgument.new do |pkg|
- if pkg
- begin
- require 'optparse/version'
- rescue LoadError
- else
- show_version(*pkg.split(/,/)) or
- abort("#{parser.program_name}: no version found in package #{pkg}")
- exit
- end
- end
- v = parser.ver or abort("#{parser.program_name}: version unknown")
- puts v
- exit
- end
- end
-
- # :startdoc:
-
- #
- # Class methods
- #
-
- #
- # Initializes a new instance and evaluates the optional block in context
- # of the instance. Arguments +args+ are passed to #new, see there for
- # description of parameters.
- #
- # This method is *deprecated*, its behavior corresponds to the older #new
- # method.
- #
- def self.with(*args, &block)
- opts = new(*args)
- opts.instance_eval(&block)
- opts
- end
-
- #
- # Returns an incremented value of +default+ according to +arg+.
- #
- def self.inc(arg, default = nil)
- case arg
- when Integer
- arg.nonzero?
- when nil
- default.to_i + 1
- end
- end
- def inc(*args)
- self.class.inc(*args)
- end
-
- #
- # Initializes the instance and yields itself if called with a block.
- #
- # +banner+:: Banner message.
- # +width+:: Summary width.
- # +indent+:: Summary indent.
- #
- def initialize(banner = nil, width = 32, indent = ' ' * 4)
- @stack = [DefaultList, List.new, List.new]
- @program_name = nil
- @banner = banner
- @summary_width = width
- @summary_indent = indent
- @default_argv = ARGV
- add_officious
- yield self if block_given?
- end
-
- def add_officious # :nodoc:
- list = base()
- Officious.each do |opt, block|
- list.long[opt] ||= block.call(self)
- end
- end
-
- #
- # Terminates option parsing. Optional parameter +arg+ is a string pushed
- # back to be the first non-option argument.
- #
- def terminate(arg = nil)
- self.class.terminate(arg)
- end
- def self.terminate(arg = nil)
- throw :terminate, arg
- end
-
- @stack = [DefaultList]
- def self.top() DefaultList end
-
- #
- # Directs to accept specified class +t+. The argument string is passed to
- # the block in which it should be converted to the desired class.
- #
- # +t+:: Argument class specifier, any object including Class.
- # +pat+:: Pattern for argument, defaults to +t+ if it responds to match.
- #
- # accept(t, pat, &block)
- #
- def accept(*args, &blk) top.accept(*args, &blk) end
- #
- # See #accept.
- #
- def self.accept(*args, &blk) top.accept(*args, &blk) end
-
- #
- # Directs to reject specified class argument.
- #
- # +t+:: Argument class specifier, any object including Class.
- #
- # reject(t)
- #
- def reject(*args, &blk) top.reject(*args, &blk) end
- #
- # See #reject.
- #
- def self.reject(*args, &blk) top.reject(*args, &blk) end
-
- #
- # Instance methods
- #
-
- # Heading banner preceding summary.
- attr_writer :banner
-
- # Program name to be emitted in error message and default banner,
- # defaults to $0.
- attr_writer :program_name
-
- # Width for option list portion of summary. Must be Numeric.
- attr_accessor :summary_width
-
- # Indentation for summary. Must be String (or have + String method).
- attr_accessor :summary_indent
-
- # Strings to be parsed in default.
- attr_accessor :default_argv
-
- #
- # Heading banner preceding summary.
- #
- def banner
- unless @banner
- @banner = "Usage: #{program_name} [options]"
- visit(:add_banner, @banner)
- end
- @banner
- end
-
- #
- # Program name to be emitted in error message and default banner, defaults
- # to $0.
- #
- def program_name
- @program_name || File.basename($0, '.*')
- end
-
- # for experimental cascading :-)
- alias set_banner banner=
- alias set_program_name program_name=
- alias set_summary_width summary_width=
- alias set_summary_indent summary_indent=
-
- # Version
- attr_writer :version
- # Release code
- attr_writer :release
-
- #
- # Version
- #
- def version
- @version || (defined?(::Version) && ::Version)
- end
-
- #
- # Release code
- #
- def release
- @release || (defined?(::Release) && ::Release) || (defined?(::RELEASE) && ::RELEASE)
- end
-
- #
- # Returns version string from program_name, version and release.
- #
- def ver
- if v = version
- str = "#{program_name} #{[v].join('.')}"
- str << " (#{v})" if v = release
- str
- end
- end
-
- def warn(mesg = $!)
- super("#{program_name}: #{mesg}")
- end
-
- def abort(mesg = $!)
- super("#{program_name}: #{mesg}")
- end
-
- #
- # Subject of #on / #on_head, #accept / #reject
- #
- def top
- @stack[-1]
- end
-
- #
- # Subject of #on_tail.
- #
- def base
- @stack[1]
- end
-
- #
- # Pushes a new List.
- #
- def new
- @stack.push(List.new)
- if block_given?
- yield self
- else
- self
- end
- end
-
- #
- # Removes the last List.
- #
- def remove
- @stack.pop
- end
-
- #
- # Puts option summary into +to+ and returns +to+. Yields each line if
- # a block is given.
- #
- # +to+:: Output destination, which must have method <<. Defaults to [].
- # +width+:: Width of left side, defaults to @summary_width.
- # +max+:: Maximum length allowed for left side, defaults to +width+ - 1.
- # +indent+:: Indentation, defaults to @summary_indent.
- #
- def summarize(to = [], width = @summary_width, max = width - 1, indent = @summary_indent, &blk)
- blk ||= proc {|l| to << (l.index($/, -1) ? l : l + $/)}
- visit(:summarize, {}, {}, width, max, indent, &blk)
- to
- end
-
- #
- # Returns option summary string.
- #
- def help; summarize("#{banner}".sub(/\n?\z/, "\n")) end
- alias to_s help
-
- #
- # Returns option summary list.
- #
- def to_a; summarize("#{banner}".split(/^/)) end
-
- #
- # Checks if an argument is given twice, in which case an ArgumentError is
- # raised. Called from OptionParser#switch only.
- #
- # +obj+:: New argument.
- # +prv+:: Previously specified argument.
- # +msg+:: Exception message.
- #
- def notwice(obj, prv, msg)
- unless !prv or prv == obj
- raise(ArgumentError, "argument #{msg} given twice: #{obj}",
- ParseError.filter_backtrace(caller(2)))
- end
- obj
- end
- private :notwice
-
- SPLAT_PROC = proc {|*a| a.length <= 1 ? a.first : a} # :nodoc:
- #
- # Creates an OptionParser::Switch from the parameters. The parsed argument
- # value is passed to the given block, where it can be processed.
- #
- # See at the beginning of OptionParser for some full examples.
- #
- # +opts+ can include the following elements:
- #
- # [Argument style:]
- # One of the following:
- # :NONE, :REQUIRED, :OPTIONAL
- #
- # [Argument pattern:]
- # Acceptable option argument format, must be pre-defined with
- # OptionParser.accept or OptionParser#accept, or Regexp. This can appear
- # once or assigned as String if not present, otherwise causes an
- # ArgumentError. Examples:
- # Float, Time, Array
- #
- # [Possible argument values:]
- # Hash or Array.
- # [:text, :binary, :auto]
- # %w[iso-2022-jp shift_jis euc-jp utf8 binary]
- # { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
- #
- # [Long style switch:]
- # Specifies a long style switch which takes a mandatory, optional or no
- # argument. It's a string of the following form:
- # "--switch=MANDATORY" or "--switch MANDATORY"
- # "--switch[=OPTIONAL]"
- # "--switch"
- #
- # [Short style switch:]
- # Specifies short style switch which takes a mandatory, optional or no
- # argument. It's a string of the following form:
- # "-xMANDATORY"
- # "-x[OPTIONAL]"
- # "-x"
- # There is also a special form which matches character range (not full
- # set of regular expression):
- # "-[a-z]MANDATORY"
- # "-[a-z][OPTIONAL]"
- # "-[a-z]"
- #
- # [Argument style and description:]
- # Instead of specifying mandatory or optional arguments directly in the
- # switch parameter, this separate parameter can be used.
- # "=MANDATORY"
- # "=[OPTIONAL]"
- #
- # [Description:]
- # Description string for the option.
- # "Run verbosely"
- #
- # [Handler:]
- # Handler for the parsed argument value. Either give a block or pass a
- # Proc or Method as an argument.
- #
- def make_switch(opts, block = nil)
- short, long, nolong, style, pattern, conv, not_pattern, not_conv, not_style = [], [], []
- ldesc, sdesc, desc, arg = [], [], []
- default_style = Switch::NoArgument
- default_pattern = nil
- klass = nil
- q, a = nil
- has_arg = false
-
- opts.each do |o|
- # argument class
- next if search(:atype, o) do |pat, c|
- klass = notwice(o, klass, 'type')
- if not_style and not_style != Switch::NoArgument
- not_pattern, not_conv = pat, c
- else
- default_pattern, conv = pat, c
- end
- end
-
- # directly specified pattern(any object possible to match)
- if (!(String === o || Symbol === o)) and o.respond_to?(:match)
- pattern = notwice(o, pattern, 'pattern')
- if pattern.respond_to?(:convert)
- conv = pattern.method(:convert).to_proc
- else
- conv = SPLAT_PROC
- end
- next
- end
-
- # anything others
- case o
- when Proc, Method
- block = notwice(o, block, 'block')
- when Array, Hash
- case pattern
- when CompletingHash
- when nil
- pattern = CompletingHash.new
- conv = pattern.method(:convert).to_proc if pattern.respond_to?(:convert)
- else
- raise ArgumentError, "argument pattern given twice"
- end
- o.each {|pat, *v| pattern[pat] = v.fetch(0) {pat}}
- when Module
- raise ArgumentError, "unsupported argument type: #{o}", ParseError.filter_backtrace(caller(4))
- when *ArgumentStyle.keys
- style = notwice(ArgumentStyle[o], style, 'style')
- when /^--no-([^\[\]=\s]*)(.+)?/
- q, a = $1, $2
- o = notwice(a ? Object : TrueClass, klass, 'type')
- not_pattern, not_conv = search(:atype, o) unless not_style
- not_style = (not_style || default_style).guess(arg = a) if a
- default_style = Switch::NoArgument
- default_pattern, conv = search(:atype, FalseClass) unless default_pattern
- ldesc << "--no-#{q}"
- long << 'no-' + (q = q.downcase)
- nolong << q
- when /^--\[no-\]([^\[\]=\s]*)(.+)?/
- q, a = $1, $2
- o = notwice(a ? Object : TrueClass, klass, 'type')
- if a
- default_style = default_style.guess(arg = a)
- default_pattern, conv = search(:atype, o) unless default_pattern
- end
- ldesc << "--[no-]#{q}"
- long << (o = q.downcase)
- not_pattern, not_conv = search(:atype, FalseClass) unless not_style
- not_style = Switch::NoArgument
- nolong << 'no-' + o
- when /^--([^\[\]=\s]*)(.+)?/
- q, a = $1, $2
- if a
- o = notwice(NilClass, klass, 'type')
- default_style = default_style.guess(arg = a)
- default_pattern, conv = search(:atype, o) unless default_pattern
- end
- ldesc << "--#{q}"
- long << (o = q.downcase)
- when /^-(\[\^?\]?(?:[^\\\]]|\\.)*\])(.+)?/
- q, a = $1, $2
- o = notwice(Object, klass, 'type')
- if a
- default_style = default_style.guess(arg = a)
- default_pattern, conv = search(:atype, o) unless default_pattern
- else
- has_arg = true
- end
- sdesc << "-#{q}"
- short << Regexp.new(q)
- when /^-(.)(.+)?/
- q, a = $1, $2
- if a
- o = notwice(NilClass, klass, 'type')
- default_style = default_style.guess(arg = a)
- default_pattern, conv = search(:atype, o) unless default_pattern
- end
- sdesc << "-#{q}"
- short << q
- when /^=/
- style = notwice(default_style.guess(arg = o), style, 'style')
- default_pattern, conv = search(:atype, Object) unless default_pattern
- else
- desc.push(o)
- end
- end
-
- default_pattern, conv = search(:atype, default_style.pattern) unless default_pattern
- if !(short.empty? and long.empty?)
- if has_arg and default_style == Switch::NoArgument
- default_style = Switch::RequiredArgument
- end
- s = (style || default_style).new(pattern || default_pattern,
- conv, sdesc, ldesc, arg, desc, block)
- elsif !block
- if style or pattern
- raise ArgumentError, "no switch given", ParseError.filter_backtrace(caller)
- end
- s = desc
- else
- short << pattern
- s = (style || default_style).new(pattern,
- conv, nil, nil, arg, desc, block)
- end
- return s, short, long,
- (not_style.new(not_pattern, not_conv, sdesc, ldesc, nil, desc, block) if not_style),
- nolong
- end
-
- def define(*opts, &block)
- top.append(*(sw = make_switch(opts, block)))
- sw[0]
- end
-
- #
- # Add option switch and handler. See #make_switch for an explanation of
- # parameters.
- #
- def on(*opts, &block)
- define(*opts, &block)
- self
- end
- alias def_option define
-
- def define_head(*opts, &block)
- top.prepend(*(sw = make_switch(opts, block)))
- sw[0]
- end
-
- #
- # Add option switch like with #on, but at head of summary.
- #
- def on_head(*opts, &block)
- define_head(*opts, &block)
- self
- end
- alias def_head_option define_head
-
- def define_tail(*opts, &block)
- base.append(*(sw = make_switch(opts, block)))
- sw[0]
- end
-
- #
- # Add option switch like with #on, but at tail of summary.
- #
- def on_tail(*opts, &block)
- define_tail(*opts, &block)
- self
- end
- alias def_tail_option define_tail
-
- #
- # Add separator in summary.
- #
- def separator(string)
- top.append(string, nil, nil)
- end
-
- #
- # Parses command line arguments +argv+ in order. When a block is given,
- # each non-option argument is yielded.
- #
- # Returns the rest of +argv+ left unparsed.
- #
- def order(*argv, &block)
- argv = argv[0].dup if argv.size == 1 and Array === argv[0]
- order!(argv, &block)
- end
-
- #
- # Same as #order, but removes switches destructively.
- # Non-option arguments remain in +argv+.
- #
- def order!(argv = default_argv, &nonopt)
- parse_in_order(argv, &nonopt)
- end
-
- def parse_in_order(argv = default_argv, setter = nil, &nonopt) # :nodoc:
- opt, arg, val, rest = nil
- nonopt ||= proc {|a| throw :terminate, a}
- argv.unshift(arg) if arg = catch(:terminate) {
- while arg = argv.shift
- case arg
- # long option
- when /\A--([^=]*)(?:=(.*))?/m
- opt, rest = $1, $2
- begin
- sw, = complete(:long, opt, true)
- rescue ParseError
- raise $!.set_option(arg, true)
- end
- begin
- opt, cb, val = sw.parse(rest, argv) {|*exc| raise(*exc)}
- val = cb.call(val) if cb
- setter.call(sw.switch_name, val) if setter
- rescue ParseError
- raise $!.set_option(arg, rest)
- end
-
- # short option
- when /\A-(.)((=).*|.+)?/m
- opt, has_arg, eq, val, rest = $1, $3, $3, $2, $2
- begin
- sw, = search(:short, opt)
- unless sw
- begin
- sw, = complete(:short, opt)
- # short option matched.
- val = arg.sub(/\A-/, '')
- has_arg = true
- rescue InvalidOption
- # if no short options match, try completion with long
- # options.
- sw, = complete(:long, opt)
- eq ||= !rest
- end
- end
- rescue ParseError
- raise $!.set_option(arg, true)
- end
- begin
- opt, cb, val = sw.parse(val, argv) {|*exc| raise(*exc) if eq}
- raise InvalidOption, arg if has_arg and !eq and arg == "-#{opt}"
- argv.unshift(opt) if opt and (!rest or (opt = opt.sub(/\A-*/, '-')) != '-')
- val = cb.call(val) if cb
- setter.call(sw.switch_name, val) if setter
- rescue ParseError
- raise $!.set_option(arg, arg.length > 2)
- end
-
- # non-option argument
- else
- catch(:prune) do
- visit(:each_option) do |sw0|
- sw = sw0
- sw.block.call(arg) if Switch === sw and sw.match_nonswitch?(arg)
- end
- nonopt.call(arg)
- end
- end
- end
-
- nil
- }
-
- visit(:search, :short, nil) {|sw| sw.block.call(*argv) if !sw.pattern}
-
- argv
- end
- private :parse_in_order
-
- #
- # Parses command line arguments +argv+ in permutation mode and returns
- # list of non-option arguments.
- #
- def permute(*argv)
- argv = argv[0].dup if argv.size == 1 and Array === argv[0]
- permute!(argv)
- end
-
- #
- # Same as #permute, but removes switches destructively.
- # Non-option arguments remain in +argv+.
- #
- def permute!(argv = default_argv)
- nonopts = []
- order!(argv, &nonopts.method(:<<))
- argv[0, 0] = nonopts
- argv
- end
-
- #
- # Parses command line arguments +argv+ in order when environment variable
- # POSIXLY_CORRECT is set, and in permutation mode otherwise.
- #
- def parse(*argv)
- argv = argv[0].dup if argv.size == 1 and Array === argv[0]
- parse!(argv)
- end
-
- #
- # Same as #parse, but removes switches destructively.
- # Non-option arguments remain in +argv+.
- #
- def parse!(argv = default_argv)
- if ENV.include?('POSIXLY_CORRECT')
- order!(argv)
- else
- permute!(argv)
- end
- end
-
- #
- # Wrapper method for getopts.rb.
- #
- # params = ARGV.getopts("ab:", "foo", "bar:", "zot:Z;zot option)
- # # params[:a] = true # -a
- # # params[:b] = "1" # -b1
- # # params[:foo] = "1" # --foo
- # # params[:bar] = "x" # --bar x
- # # params[:zot] = "z" # --zot Z
- #
- def getopts(*args)
- argv = Array === args.first ? args.shift : default_argv
- single_options, *long_options = *args
-
- result = {}
-
- single_options.scan(/(.)(:)?/) do |opt, val|
- if val
- result[opt] = nil
- define("-#{opt} VAL")
- else
- result[opt] = false
- define("-#{opt}")
- end
- end if single_options
-
- long_options.each do |arg|
- arg, desc = arg.split(';', 2)
- opt, val = arg.split(':', 2)
- if val
- result[opt] = val.empty? ? nil : val
- define("--#{opt}=#{result[opt] || "VAL"}", *[desc].compact)
- else
- result[opt] = false
- define("--#{opt}", *[desc].compact)
- end
- end
-
- parse_in_order(argv, result.method(:[]=))
- result
- end
-
- #
- # See #getopts.
- #
- def self.getopts(*args)
- new.getopts(*args)
- end
-
- #
- # Traverses @stack, sending each element method +id+ with +args+ and
- # +block+.
- #
- def visit(id, *args, &block)
- @stack.reverse_each do |el|
- el.send(id, *args, &block)
- end
- nil
- end
- private :visit
-
- #
- # Searches +key+ in @stack for +id+ hash and returns or yields the result.
- #
- def search(id, key)
- block_given = block_given?
- visit(:search, id, key) do |k|
- return block_given ? yield(k) : k
- end
- end
- private :search
-
- #
- # Completes shortened long style option switch and returns pair of
- # canonical switch and switch descriptor OptionParser::Switch.
- #
- # +id+:: Searching table.
- # +opt+:: Searching key.
- # +icase+:: Search case insensitive if true.
- # +pat+:: Optional pattern for completion.
- #
- def complete(typ, opt, icase = false, *pat)
- if pat.empty?
- search(typ, opt) {|sw| return [sw, opt]} # exact match or...
- end
- raise AmbiguousOption, catch(:ambiguous) {
- visit(:complete, typ, opt, icase, *pat) {|o, *sw| return sw}
- raise InvalidOption, opt
- }
- end
- private :complete
-
- def candidate(word)
- list = []
- case word
- when /\A--/
- word, arg = word.split(/=/, 2)
- argpat = Completion.regexp(arg, false) if arg and !arg.empty?
- long = true
- when /\A-(!-)/
- short = true
- when /\A-/
- long = short = true
- end
- pat = Completion.regexp(word, true)
- visit(:each_option) do |opt|
- next unless Switch === opt
- opts = (long ? opt.long : []) + (short ? opt.short : [])
- opts = Completion.candidate(word, true, pat, &opts.method(:each)).map(&:first) if pat
- if /\A=/ =~ opt.arg
- opts.map! {|sw| sw + "="}
- if arg and CompletingHash === opt.pattern
- if opts = opt.pattern.candidate(arg, false, argpat)
- opts.map!(&:last)
- end
- end
- end
- list.concat(opts)
- end
- list
- end
-
- #
- # Loads options from file names as +filename+. Does nothing when the file
- # is not present. Returns whether successfully loaded.
- #
- # +filename+ defaults to basename of the program without suffix in a
- # directory ~/.options.
- #
- def load(filename = nil)
- begin
- filename ||= File.expand_path(File.basename($0, '.*'), '~/.options')
- rescue
- return false
- end
- begin
- parse(*IO.readlines(filename).each {|s| s.chomp!})
- true
- rescue Errno::ENOENT, Errno::ENOTDIR
- false
- end
- end
-
- #
- # Parses environment variable +env+ or its uppercase with splitting like a
- # shell.
- #
- # +env+ defaults to the basename of the program.
- #
- def environment(env = File.basename($0, '.*'))
- env = ENV[env] || ENV[env.upcase] or return
- require 'shellwords'
- parse(*Shellwords.shellwords(env))
- end
-
- #
- # Acceptable argument classes
- #
-
- #
- # Any string and no conversion. This is fall-back.
- #
- accept(Object) {|s,|s or s.nil?}
-
- accept(NilClass) {|s,|s}
-
- #
- # Any non-empty string, and no conversion.
- #
- accept(String, /.+/m) {|s,*|s}
-
- #
- # Ruby/C-like integer, octal for 0-7 sequence, binary for 0b, hexadecimal
- # for 0x, and decimal for others; with optional sign prefix. Converts to
- # Integer.
- #
- decimal = '\d+(?:_\d+)*'
- binary = 'b[01]+(?:_[01]+)*'
- hex = 'x[\da-f]+(?:_[\da-f]+)*'
- octal = "0(?:[0-7]+(?:_[0-7]+)*|#{binary}|#{hex})?"
- integer = "#{octal}|#{decimal}"
-
- accept(Integer, %r"\A[-+]?(?:#{integer})\z"io) {|s,|
- begin
- Integer(s)
- rescue ArgumentError
- raise OptionParser::InvalidArgument, s
- end if s
- }
-
- #
- # Float number format, and converts to Float.
- #
- float = "(?:#{decimal}(?:\\.(?:#{decimal})?)?|\\.#{decimal})(?:E[-+]?#{decimal})?"
- floatpat = %r"\A[-+]?#{float}\z"io
- accept(Float, floatpat) {|s,| s.to_f if s}
-
- #
- # Generic numeric format, converts to Integer for integer format, Float
- # for float format, and Rational for rational format.
- #
- real = "[-+]?(?:#{octal}|#{float})"
- accept(Numeric, /\A(#{real})(?:\/(#{real}))?\z/io) {|s, d, n|
- if n
- Rational(d, n)
- elsif s
- eval(s)
- end
- }
-
- #
- # Decimal integer format, to be converted to Integer.
- #
- DecimalInteger = /\A[-+]?#{decimal}\z/io
- accept(DecimalInteger, DecimalInteger) {|s,|
- begin
- Integer(s)
- rescue ArgumentError
- raise OptionParser::InvalidArgument, s
- end if s
- }
-
- #
- # Ruby/C like octal/hexadecimal/binary integer format, to be converted to
- # Integer.
- #
- OctalInteger = /\A[-+]?(?:[0-7]+(?:_[0-7]+)*|0(?:#{binary}|#{hex}))\z/io
- accept(OctalInteger, OctalInteger) {|s,|
- begin
- Integer(s, 8)
- rescue ArgumentError
- raise OptionParser::InvalidArgument, s
- end if s
- }
-
- #
- # Decimal integer/float number format, to be converted to Integer for
- # integer format, Float for float format.
- #
- DecimalNumeric = floatpat # decimal integer is allowed as float also.
- accept(DecimalNumeric, floatpat) {|s,|
- begin
- eval(s)
- rescue SyntaxError
- raise OptionParser::InvalidArgument, s
- end if s
- }
-
- #
- # Boolean switch, which means whether it is present or not, whether it is
- # absent or not with prefix no-, or it takes an argument
- # yes/no/true/false/+/-.
- #
- yesno = CompletingHash.new
- %w[- no false].each {|el| yesno[el] = false}
- %w[+ yes true].each {|el| yesno[el] = true}
- yesno['nil'] = false # should be nil?
- accept(TrueClass, yesno) {|arg, val| val == nil or val}
- #
- # Similar to TrueClass, but defaults to false.
- #
- accept(FalseClass, yesno) {|arg, val| val != nil and val}
-
- #
- # List of strings separated by ",".
- #
- accept(Array) do |s,|
- if s
- s = s.split(',').collect {|ss| ss unless ss.empty?}
- end
- s
- end
-
- #
- # Regular expression with options.
- #
- accept(Regexp, %r"\A/((?:\\.|[^\\])*)/([[:alpha:]]+)?\z|.*") do |all, s, o|
- f = 0
- if o
- f |= Regexp::IGNORECASE if /i/ =~ o
- f |= Regexp::MULTILINE if /m/ =~ o
- f |= Regexp::EXTENDED if /x/ =~ o
- k = o.delete("imx")
- k = nil if k.empty?
- end
- Regexp.new(s || all, f, k)
- end
-
- #
- # Exceptions
- #
-
- #
- # Base class of exceptions from OptionParser.
- #
- class ParseError < RuntimeError
- # Reason which caused the error.
- Reason = 'parse error'.freeze
-
- def initialize(*args)
- @args = args
- @reason = nil
- end
-
- attr_reader :args
- attr_writer :reason
-
- #
- # Pushes back erred argument(s) to +argv+.
- #
- def recover(argv)
- argv[0, 0] = @args
- argv
- end
-
- def self.filter_backtrace(array)
- unless $DEBUG
- array.delete_if(&%r"\A#{Regexp.quote(__FILE__)}:"o.method(:=~))
- end
- array
- end
-
- def set_backtrace(array)
- super(self.class.filter_backtrace(array))
- end
-
- def set_option(opt, eq)
- if eq
- @args[0] = opt
- else
- @args.unshift(opt)
- end
- self
- end
-
- #
- # Returns error reason. Override this for I18N.
- #
- def reason
- @reason || self.class::Reason
- end
-
- def inspect
- "#<#{self.class}: #{args.join(' ')}>"
- end
-
- #
- # Default stringizing method to emit standard error message.
- #
- def message
- reason + ': ' + args.join(' ')
- end
-
- alias to_s message
- end
-
- #
- # Raises when ambiguously completable string is encountered.
- #
- class AmbiguousOption < ParseError
- const_set(:Reason, 'ambiguous option'.freeze)
- end
-
- #
- # Raises when there is an argument for a switch which takes no argument.
- #
- class NeedlessArgument < ParseError
- const_set(:Reason, 'needless argument'.freeze)
- end
-
- #
- # Raises when a switch with mandatory argument has no argument.
- #
- class MissingArgument < ParseError
- const_set(:Reason, 'missing argument'.freeze)
- end
-
- #
- # Raises when switch is undefined.
- #
- class InvalidOption < ParseError
- const_set(:Reason, 'invalid option'.freeze)
- end
-
- #
- # Raises when the given argument does not match required format.
- #
- class InvalidArgument < ParseError
- const_set(:Reason, 'invalid argument'.freeze)
- end
-
- #
- # Raises when the given argument word can't be completed uniquely.
- #
- class AmbiguousArgument < InvalidArgument
- const_set(:Reason, 'ambiguous argument'.freeze)
- end
-
- #
- # Miscellaneous
- #
-
- #
- # Extends command line arguments array (ARGV) to parse itself.
- #
- module Arguable
-
- #
- # Sets OptionParser object, when +opt+ is +false+ or +nil+, methods
- # OptionParser::Arguable#options and OptionParser::Arguable#options= are
- # undefined. Thus, there is no ways to access the OptionParser object
- # via the receiver object.
- #
- def options=(opt)
- unless @optparse = opt
- class << self
- undef_method(:options)
- undef_method(:options=)
- end
- end
- end
-
- #
- # Actual OptionParser object, automatically created if nonexistent.
- #
- # If called with a block, yields the OptionParser object and returns the
- # result of the block. If an OptionParser::ParseError exception occurs
- # in the block, it is rescued, a error message printed to STDERR and
- # +nil+ returned.
- #
- def options
- @optparse ||= OptionParser.new
- @optparse.default_argv = self
- block_given? or return @optparse
- begin
- yield @optparse
- rescue ParseError
- @optparse.warn $!
- nil
- end
- end
-
- #
- # Parses +self+ destructively in order and returns +self+ containing the
- # rest arguments left unparsed.
- #
- def order!(&blk) options.order!(self, &blk) end
-
- #
- # Parses +self+ destructively in permutation mode and returns +self+
- # containing the rest arguments left unparsed.
- #
- def permute!() options.permute!(self) end
-
- #
- # Parses +self+ destructively and returns +self+ containing the
- # rest arguments left unparsed.
- #
- def parse!() options.parse!(self) end
-
- #
- # Substitution of getopts is possible as follows. Also see
- # OptionParser#getopts.
- #
- # def getopts(*args)
- # ($OPT = ARGV.getopts(*args)).each do |opt, val|
- # eval "$OPT_#{opt.gsub(/[^A-Za-z0-9_]/, '_')} = val"
- # end
- # rescue OptionParser::ParseError
- # end
- #
- def getopts(*args)
- options.getopts(self, *args)
- end
-
- #
- # Initializes instance variable.
- #
- def self.extend_object(obj)
- super
- obj.instance_eval {@optparse = nil}
- end
- def initialize(*args)
- super
- @optparse = nil
- end
- end
-
- #
- # Acceptable argument classes. Now contains DecimalInteger, OctalInteger
- # and DecimalNumeric. See Acceptable argument classes (in source code).
- #
- module Acceptables
- const_set(:DecimalInteger, OptionParser::DecimalInteger)
- const_set(:OctalInteger, OptionParser::OctalInteger)
- const_set(:DecimalNumeric, OptionParser::DecimalNumeric)
- end
-end
-
-# ARGV is arguable by OptionParser
-ARGV.extend(OptionParser::Arguable)
-
-# An alias for OptionParser.
-OptParse = OptionParser # :nodoc:
diff --git a/ruby_2_2/lib/optparse/ac.rb b/ruby_2_2/lib/optparse/ac.rb
deleted file mode 100644
index 6a8626094d..0000000000
--- a/ruby_2_2/lib/optparse/ac.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-require 'optparse'
-
-class OptionParser::AC < OptionParser
- private
-
- def _check_ac_args(name, block)
- unless /\A\w[-\w]*\z/ =~ name
- raise ArgumentError, name
- end
- unless block
- raise ArgumentError, "no block given", ParseError.filter_backtrace(caller)
- end
- end
-
- def _ac_arg_enable(prefix, name, help_string, block)
- _check_ac_args(name, block)
-
- sdesc = []
- ldesc = ["--#{prefix}-#{name}"]
- desc = [help_string]
- q = name.downcase
- enable = Switch::NoArgument.new(nil, proc {true}, sdesc, ldesc, nil, desc, block)
- disable = Switch::NoArgument.new(nil, proc {false}, sdesc, ldesc, nil, desc, block)
- top.append(enable, [], ["enable-" + q], disable, ['disable-' + q])
- enable
- end
-
- public
-
- def ac_arg_enable(name, help_string, &block)
- _ac_arg_enable("enable", name, help_string, block)
- end
-
- def ac_arg_disable(name, help_string, &block)
- _ac_arg_enable("disable", name, help_string, block)
- end
-
- def ac_arg_with(name, help_string, &block)
- _check_ac_args(name, block)
-
- sdesc = []
- ldesc = ["--with-#{name}"]
- desc = [help_string]
- q = name.downcase
- with = Switch::PlacedArgument.new(*search(:atype, String), sdesc, ldesc, nil, desc, block)
- without = Switch::NoArgument.new(nil, proc {}, sdesc, ldesc, nil, desc, block)
- top.append(with, [], ["with-" + q], without, ['without-' + q])
- with
- end
-end
diff --git a/ruby_2_2/lib/optparse/date.rb b/ruby_2_2/lib/optparse/date.rb
deleted file mode 100644
index d680559f37..0000000000
--- a/ruby_2_2/lib/optparse/date.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-require 'optparse'
-require 'date'
-
-OptionParser.accept(DateTime) do |s,|
- begin
- DateTime.parse(s) if s
- rescue ArgumentError
- raise OptionParser::InvalidArgument, s
- end
-end
-OptionParser.accept(Date) do |s,|
- begin
- Date.parse(s) if s
- rescue ArgumentError
- raise OptionParser::InvalidArgument, s
- end
-end
diff --git a/ruby_2_2/lib/optparse/shellwords.rb b/ruby_2_2/lib/optparse/shellwords.rb
deleted file mode 100644
index 0422d7c887..0000000000
--- a/ruby_2_2/lib/optparse/shellwords.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-# -*- ruby -*-
-
-require 'shellwords'
-require 'optparse'
-
-OptionParser.accept(Shellwords) {|s,| Shellwords.shellwords(s)}
diff --git a/ruby_2_2/lib/optparse/time.rb b/ruby_2_2/lib/optparse/time.rb
deleted file mode 100644
index 402cadcf16..0000000000
--- a/ruby_2_2/lib/optparse/time.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require 'optparse'
-require 'time'
-
-OptionParser.accept(Time) do |s,|
- begin
- (Time.httpdate(s) rescue Time.parse(s)) if s
- rescue
- raise OptionParser::InvalidArgument, s
- end
-end
diff --git a/ruby_2_2/lib/optparse/uri.rb b/ruby_2_2/lib/optparse/uri.rb
deleted file mode 100644
index 024dc69eac..0000000000
--- a/ruby_2_2/lib/optparse/uri.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-# -*- ruby -*-
-
-require 'optparse'
-require 'uri'
-
-OptionParser.accept(URI) {|s,| URI.parse(s) if s}
diff --git a/ruby_2_2/lib/optparse/version.rb b/ruby_2_2/lib/optparse/version.rb
deleted file mode 100644
index 8525677418..0000000000
--- a/ruby_2_2/lib/optparse/version.rb
+++ /dev/null
@@ -1,70 +0,0 @@
-# OptionParser internal utility
-
-class << OptionParser
- def show_version(*pkgs)
- progname = ARGV.options.program_name
- result = false
- show = proc do |klass, cname, version|
- str = "#{progname}"
- unless klass == ::Object and cname == :VERSION
- version = version.join(".") if Array === version
- str << ": #{klass}" unless klass == Object
- str << " version #{version}"
- end
- [:Release, :RELEASE].find do |rel|
- if klass.const_defined?(rel)
- str << " (#{klass.const_get(rel)})"
- end
- end
- puts str
- result = true
- end
- if pkgs.size == 1 and pkgs[0] == "all"
- self.search_const(::Object, /\AV(?:ERSION|ersion)\z/) do |klass, cname, version|
- unless cname[1] == ?e and klass.const_defined?(:Version)
- show.call(klass, cname.intern, version)
- end
- end
- else
- pkgs.each do |pkg|
- begin
- pkg = pkg.split(/::|\//).inject(::Object) {|m, c| m.const_get(c)}
- v = case
- when pkg.const_defined?(:Version)
- pkg.const_get(n = :Version)
- when pkg.const_defined?(:VERSION)
- pkg.const_get(n = :VERSION)
- else
- n = nil
- "unknown"
- end
- show.call(pkg, n, v)
- rescue NameError
- end
- end
- end
- result
- end
-
- def each_const(path, base = ::Object)
- path.split(/::|\//).inject(base) do |klass, name|
- raise NameError, path unless Module === klass
- klass.constants.grep(/#{name}/i) do |c|
- klass.const_defined?(c) or next
- klass.const_get(c)
- end
- end
- end
-
- def search_const(klass, name)
- klasses = [klass]
- while klass = klasses.shift
- klass.constants.each do |cname|
- klass.const_defined?(cname) or next
- const = klass.const_get(cname)
- yield klass, cname, const if name === cname
- klasses << const if Module === const and const != ::Object
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/ostruct.rb b/ruby_2_2/lib/ostruct.rb
deleted file mode 100644
index c44f102547..0000000000
--- a/ruby_2_2/lib/ostruct.rb
+++ /dev/null
@@ -1,316 +0,0 @@
-#
-# = ostruct.rb: OpenStruct implementation
-#
-# Author:: Yukihiro Matsumoto
-# Documentation:: Gavin Sinclair
-#
-# OpenStruct allows the creation of data objects with arbitrary attributes.
-# See OpenStruct for an example.
-#
-
-#
-# An OpenStruct is a data structure, similar to a Hash, that allows the
-# definition of arbitrary attributes with their accompanying values. This is
-# accomplished by using Ruby's metaprogramming to define methods on the class
-# itself.
-#
-# == Examples
-#
-# require "ostruct"
-#
-# person = OpenStruct.new
-# person.name = "John Smith"
-# person.age = 70
-#
-# person.name # => "John Smith"
-# person.age # => 70
-# person.address # => nil
-#
-# An OpenStruct employs a Hash internally to store the attributes and values
-# and can even be initialized with one:
-#
-# australia = OpenStruct.new(:country => "Australia", :capital => "Canberra")
-# # => #<OpenStruct country="Australia", capital="Canberra">
-#
-# Hash keys with spaces or characters that could normally not be used for
-# method calls (e.g. <code>()[]*</code>) will not be immediately available
-# on the OpenStruct object as a method for retrieval or assignment, but can
-# still be reached through the Object#send method.
-#
-# measurements = OpenStruct.new("length (in inches)" => 24)
-# measurements.send("length (in inches)") # => 24
-#
-# message = OpenStruct.new(:queued? => true)
-# message.queued? # => true
-# message.send("queued?=", false)
-# message.queued? # => false
-#
-# Removing the presence of an attribute requires the execution of the
-# delete_field method as setting the property value to +nil+ will not
-# remove the attribute.
-#
-# first_pet = OpenStruct.new(:name => "Rowdy", :owner => "John Smith")
-# second_pet = OpenStruct.new(:name => "Rowdy")
-#
-# first_pet.owner = nil
-# first_pet # => #<OpenStruct name="Rowdy", owner=nil>
-# first_pet == second_pet # => false
-#
-# first_pet.delete_field(:owner)
-# first_pet # => #<OpenStruct name="Rowdy">
-# first_pet == second_pet # => true
-#
-#
-# == Implementation
-#
-# An OpenStruct utilizes Ruby's method lookup structure to find and define the
-# necessary methods for properties. This is accomplished through the methods
-# method_missing and define_singleton_method.
-#
-# This should be a consideration if there is a concern about the performance of
-# the objects that are created, as there is much more overhead in the setting
-# of these properties compared to using a Hash or a Struct.
-#
-class OpenStruct
- #
- # Creates a new OpenStruct object. By default, the resulting OpenStruct
- # object will have no attributes.
- #
- # The optional +hash+, if given, will generate attributes and values
- # (can be a Hash, an OpenStruct or a Struct).
- # For example:
- #
- # require "ostruct"
- # hash = { "country" => "Australia", :capital => "Canberra" }
- # data = OpenStruct.new(hash)
- #
- # data # => #<OpenStruct country="Australia", capital="Canberra">
- #
- def initialize(hash=nil)
- @table = {}
- if hash
- hash.each_pair do |k, v|
- k = k.to_sym
- @table[k] = v
- new_ostruct_member(k)
- end
- end
- end
-
- # Duplicates an OpenStruct object's Hash table.
- def initialize_copy(orig) # :nodoc:
- super
- @table = @table.dup
- @table.each_key{|key| new_ostruct_member(key)}
- end
-
- #
- # Converts the OpenStruct to a hash with keys representing
- # each attribute (as symbols) and their corresponding values.
- #
- # require "ostruct"
- # data = OpenStruct.new("country" => "Australia", :capital => "Canberra")
- # data.to_h # => {:country => "Australia", :capital => "Canberra" }
- #
- def to_h
- @table.dup
- end
-
- #
- # :call-seq:
- # ostruct.each_pair {|name, value| block } -> ostruct
- # ostruct.each_pair -> Enumerator
- #
- # Yields all attributes (as symbols) along with the corresponding values
- # or returns an enumerator if no block is given.
- #
- # require "ostruct"
- # data = OpenStruct.new("country" => "Australia", :capital => "Canberra")
- # data.each_pair.to_a # => [[:country, "Australia"], [:capital, "Canberra"]]
- #
- def each_pair
- return to_enum(__method__) { @table.size } unless block_given?
- @table.each_pair{|p| yield p}
- self
- end
-
- #
- # Provides marshalling support for use by the Marshal library.
- #
- def marshal_dump
- @table
- end
-
- #
- # Provides marshalling support for use by the Marshal library.
- #
- def marshal_load(x)
- @table = x
- @table.each_key{|key| new_ostruct_member(key)}
- end
-
- #
- # Used internally to check if the OpenStruct is able to be
- # modified before granting access to the internal Hash table to be modified.
- #
- def modifiable
- begin
- @modifiable = true
- rescue
- raise RuntimeError, "can't modify frozen #{self.class}", caller(3)
- end
- @table
- end
- protected :modifiable
-
- #
- # Used internally to defined properties on the
- # OpenStruct. It does this by using the metaprogramming function
- # define_singleton_method for both the getter method and the setter method.
- #
- def new_ostruct_member(name)
- name = name.to_sym
- unless respond_to?(name)
- define_singleton_method(name) { @table[name] }
- define_singleton_method("#{name}=") { |x| modifiable[name] = x }
- end
- name
- end
- protected :new_ostruct_member
-
- def method_missing(mid, *args) # :nodoc:
- mname = mid.id2name
- len = args.length
- if mname.chomp!('=')
- if len != 1
- raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1)
- end
- modifiable[new_ostruct_member(mname)] = args[0]
- elsif len == 0
- @table[mid]
- else
- err = NoMethodError.new "undefined method `#{mid}' for #{self}", mid, args
- err.set_backtrace caller(1)
- raise err
- end
- end
-
- #
- # :call-seq:
- # ostruct[name] -> object
- #
- # Returns the value of an attribute.
- #
- # require "ostruct"
- # person = OpenStruct.new("name" => "John Smith", "age" => 70)
- # person[:age] # => 70, same as person.age
- #
- def [](name)
- @table[name.to_sym]
- end
-
- #
- # :call-seq:
- # ostruct[name] = obj -> obj
- #
- # Sets the value of an attribute.
- #
- # require "ostruct"
- # person = OpenStruct.new("name" => "John Smith", "age" => 70)
- # person[:age] = 42 # equivalent to person.age = 42
- # person.age # => 42
- #
- def []=(name, value)
- modifiable[new_ostruct_member(name)] = value
- end
-
- #
- # Removes the named field from the object. Returns the value that the field
- # contained if it was defined.
- #
- # require "ostruct"
- #
- # person = OpenStruct.new(name: "John", age: 70, pension: 300)
- #
- # person.delete_field("age") # => 70
- # person # => #<OpenStruct name="John", pension=300>
- #
- # Setting the value to +nil+ will not remove the attribute:
- #
- # person.pension = nil
- # person # => #<OpenStruct name="John", pension=nil>
- #
- def delete_field(name)
- sym = name.to_sym
- singleton_class.__send__(:remove_method, sym, "#{sym}=")
- @table.delete sym
- end
-
- InspectKey = :__inspect_key__ # :nodoc:
-
- #
- # Returns a string containing a detailed summary of the keys and values.
- #
- def inspect
- str = "#<#{self.class}"
-
- ids = (Thread.current[InspectKey] ||= [])
- if ids.include?(object_id)
- return str << ' ...>'
- end
-
- ids << object_id
- begin
- first = true
- for k,v in @table
- str << "," unless first
- first = false
- str << " #{k}=#{v.inspect}"
- end
- return str << '>'
- ensure
- ids.pop
- end
- end
- alias :to_s :inspect
-
- attr_reader :table # :nodoc:
- protected :table
-
- #
- # Compares this object and +other+ for equality. An OpenStruct is equal to
- # +other+ when +other+ is an OpenStruct and the two objects' Hash tables are
- # equal.
- #
- # require "ostruct"
- # first_pet = OpenStruct.new("name" => "Rowdy")
- # second_pet = OpenStruct.new(:name => "Rowdy")
- # third_pet = OpenStruct.new("name" => "Rowdy", :age => nil)
- #
- # first_pet == second_pet # => true
- # first_pet == third_pet # => false
- #
- def ==(other)
- return false unless other.kind_of?(OpenStruct)
- @table == other.table
- end
-
- #
- # Compares this object and +other+ for equality. An OpenStruct is eql? to
- # +other+ when +other+ is an OpenStruct and the two objects' Hash tables are
- # eql?.
- #
- def eql?(other)
- return false unless other.kind_of?(OpenStruct)
- @table.eql?(other.table)
- end
-
- # Computes a hash code for this OpenStruct.
- # Two OpenStruct objects with the same content will have the same hash code
- # (and will compare using #eql?).
- #
- # See also Object#hash.
- def hash
- @table.hash
- end
-end
diff --git a/ruby_2_2/lib/pp.rb b/ruby_2_2/lib/pp.rb
deleted file mode 100644
index 3c73463c9c..0000000000
--- a/ruby_2_2/lib/pp.rb
+++ /dev/null
@@ -1,546 +0,0 @@
-require 'prettyprint'
-
-module Kernel
- # Returns a pretty printed object as a string.
- #
- # In order to use this method you must first require the PP module:
- #
- # require 'pp'
- #
- # See the PP module for more information.
- def pretty_inspect
- PP.pp(self, '')
- end
-
- private
- # prints arguments in pretty form.
- #
- # pp returns argument(s).
- def pp(*objs) # :nodoc:
- objs.each {|obj|
- PP.pp(obj)
- }
- objs.size <= 1 ? objs.first : objs
- end
- module_function :pp # :nodoc:
-end
-
-##
-# A pretty-printer for Ruby objects.
-#
-# All examples assume you have loaded the PP class with:
-# require 'pp'
-#
-##
-# == What PP Does
-#
-# Standard output by #p returns this:
-# #<PP:0x81fedf0 @genspace=#<Proc:0x81feda0>, @group_queue=#<PrettyPrint::GroupQueue:0x81fed3c @queue=[[#<PrettyPrint::Group:0x81fed78 @breakables=[], @depth=0, @break=false>], []]>, @buffer=[], @newline="\n", @group_stack=[#<PrettyPrint::Group:0x81fed78 @breakables=[], @depth=0, @break=false>], @buffer_width=0, @indent=0, @maxwidth=79, @output_width=2, @output=#<IO:0x8114ee4>>
-#
-# Pretty-printed output returns this:
-# #<PP:0x81fedf0
-# @buffer=[],
-# @buffer_width=0,
-# @genspace=#<Proc:0x81feda0>,
-# @group_queue=
-# #<PrettyPrint::GroupQueue:0x81fed3c
-# @queue=
-# [[#<PrettyPrint::Group:0x81fed78 @break=false, @breakables=[], @depth=0>],
-# []]>,
-# @group_stack=
-# [#<PrettyPrint::Group:0x81fed78 @break=false, @breakables=[], @depth=0>],
-# @indent=0,
-# @maxwidth=79,
-# @newline="\n",
-# @output=#<IO:0x8114ee4>,
-# @output_width=2>
-#
-##
-# == Usage
-#
-# pp(obj) #=> obj
-# pp obj #=> obj
-# pp(obj1, obj2, ...) #=> [obj1, obj2, ...]
-# pp() #=> nil
-#
-# Output <tt>obj(s)</tt> to <tt>$></tt> in pretty printed format.
-#
-# It returns <tt>obj(s)</tt>.
-#
-##
-# == Output Customization
-#
-# To define a customized pretty printing function for your classes,
-# redefine method <code>#pretty_print(pp)</code> in the class.
-#
-# <code>#pretty_print</code> takes the +pp+ argument, which is an instance of the PP class.
-# The method uses #text, #breakable, #nest, #group and #pp to print the
-# object.
-#
-##
-# == Pretty-Print JSON
-#
-# To pretty-print JSON refer to JSON#pretty_generate.
-#
-##
-# == Author
-# Tanaka Akira <akr@fsij.org>
-
-class PP < PrettyPrint
- # Outputs +obj+ to +out+ in pretty printed format of
- # +width+ columns in width.
- #
- # If +out+ is omitted, <code>$></code> is assumed.
- # If +width+ is omitted, 79 is assumed.
- #
- # PP.pp returns +out+.
- def PP.pp(obj, out=$>, width=79)
- q = PP.new(out, width)
- q.guard_inspect_key {q.pp obj}
- q.flush
- #$pp = q
- out << "\n"
- end
-
- # Outputs +obj+ to +out+ like PP.pp but with no indent and
- # newline.
- #
- # PP.singleline_pp returns +out+.
- def PP.singleline_pp(obj, out=$>)
- q = SingleLine.new(out)
- q.guard_inspect_key {q.pp obj}
- q.flush
- out
- end
-
- # :stopdoc:
- def PP.mcall(obj, mod, meth, *args, &block)
- mod.instance_method(meth).bind(obj).call(*args, &block)
- end
- # :startdoc:
-
- @sharing_detection = false
- class << self
- # Returns the sharing detection flag as a boolean value.
- # It is false by default.
- attr_accessor :sharing_detection
- end
-
- module PPMethods
-
- # Yields to a block
- # and preserves the previous set of objects being printed.
- def guard_inspect_key
- if Thread.current[:__recursive_key__] == nil
- Thread.current[:__recursive_key__] = {}.taint
- end
-
- if Thread.current[:__recursive_key__][:inspect] == nil
- Thread.current[:__recursive_key__][:inspect] = {}.taint
- end
-
- save = Thread.current[:__recursive_key__][:inspect]
-
- begin
- Thread.current[:__recursive_key__][:inspect] = {}.taint
- yield
- ensure
- Thread.current[:__recursive_key__][:inspect] = save
- end
- end
-
- # Check whether the object_id +id+ is in the current buffer of objects
- # to be pretty printed. Used to break cycles in chains of objects to be
- # pretty printed.
- def check_inspect_key(id)
- Thread.current[:__recursive_key__] &&
- Thread.current[:__recursive_key__][:inspect] &&
- Thread.current[:__recursive_key__][:inspect].include?(id)
- end
-
- # Adds the object_id +id+ to the set of objects being pretty printed, so
- # as to not repeat objects.
- def push_inspect_key(id)
- Thread.current[:__recursive_key__][:inspect][id] = true
- end
-
- # Removes an object from the set of objects being pretty printed.
- def pop_inspect_key(id)
- Thread.current[:__recursive_key__][:inspect].delete id
- end
-
- # Adds +obj+ to the pretty printing buffer
- # using Object#pretty_print or Object#pretty_print_cycle.
- #
- # Object#pretty_print_cycle is used when +obj+ is already
- # printed, a.k.a the object reference chain has a cycle.
- def pp(obj)
- id = obj.object_id
-
- if check_inspect_key(id)
- group {obj.pretty_print_cycle self}
- return
- end
-
- begin
- push_inspect_key(id)
- group {obj.pretty_print self}
- ensure
- pop_inspect_key(id) unless PP.sharing_detection
- end
- end
-
- # A convenience method which is same as follows:
- #
- # group(1, '#<' + obj.class.name, '>') { ... }
- def object_group(obj, &block) # :yield:
- group(1, '#<' + obj.class.name, '>', &block)
- end
-
- # A convenience method, like object_group, but also reformats the Object's
- # object_id.
- def object_address_group(obj, &block)
- str = Kernel.instance_method(:to_s).bind(obj).call
- str.chomp!('>')
- group(1, str, '>', &block)
- end
-
- # A convenience method which is same as follows:
- #
- # text ','
- # breakable
- def comma_breakable
- text ','
- breakable
- end
-
- # Adds a separated list.
- # The list is separated by comma with breakable space, by default.
- #
- # #seplist iterates the +list+ using +iter_method+.
- # It yields each object to the block given for #seplist.
- # The procedure +separator_proc+ is called between each yields.
- #
- # If the iteration is zero times, +separator_proc+ is not called at all.
- #
- # If +separator_proc+ is nil or not given,
- # +lambda { comma_breakable }+ is used.
- # If +iter_method+ is not given, :each is used.
- #
- # For example, following 3 code fragments has similar effect.
- #
- # q.seplist([1,2,3]) {|v| xxx v }
- #
- # q.seplist([1,2,3], lambda { q.comma_breakable }, :each) {|v| xxx v }
- #
- # xxx 1
- # q.comma_breakable
- # xxx 2
- # q.comma_breakable
- # xxx 3
- def seplist(list, sep=nil, iter_method=:each) # :yield: element
- sep ||= lambda { comma_breakable }
- first = true
- list.__send__(iter_method) {|*v|
- if first
- first = false
- else
- sep.call
- end
- yield(*v)
- }
- end
-
- # A present standard failsafe for pretty printing any given Object
- def pp_object(obj)
- object_address_group(obj) {
- seplist(obj.pretty_print_instance_variables, lambda { text ',' }) {|v|
- breakable
- v = v.to_s if Symbol === v
- text v
- text '='
- group(1) {
- breakable ''
- pp(obj.instance_eval(v))
- }
- }
- }
- end
-
- # A pretty print for a Hash
- def pp_hash(obj)
- group(1, '{', '}') {
- seplist(obj, nil, :each_pair) {|k, v|
- group {
- pp k
- text '=>'
- group(1) {
- breakable ''
- pp v
- }
- }
- }
- }
- end
- end
-
- include PPMethods
-
- class SingleLine < PrettyPrint::SingleLine # :nodoc:
- include PPMethods
- end
-
- module ObjectMixin # :nodoc:
- # 1. specific pretty_print
- # 2. specific inspect
- # 3. generic pretty_print
-
- # A default pretty printing method for general objects.
- # It calls #pretty_print_instance_variables to list instance variables.
- #
- # If +self+ has a customized (redefined) #inspect method,
- # the result of self.inspect is used but it obviously has no
- # line break hints.
- #
- # This module provides predefined #pretty_print methods for some of
- # the most commonly used built-in classes for convenience.
- def pretty_print(q)
- method_method = Object.instance_method(:method).bind(self)
- begin
- inspect_method = method_method.call(:inspect)
- rescue NameError
- end
- if inspect_method && /\(Kernel\)#/ !~ inspect_method.inspect
- q.text self.inspect
- elsif !inspect_method && self.respond_to?(:inspect)
- q.text self.inspect
- else
- q.pp_object(self)
- end
- end
-
- # A default pretty printing method for general objects that are
- # detected as part of a cycle.
- def pretty_print_cycle(q)
- q.object_address_group(self) {
- q.breakable
- q.text '...'
- }
- end
-
- # Returns a sorted array of instance variable names.
- #
- # This method should return an array of names of instance variables as symbols or strings as:
- # +[:@a, :@b]+.
- def pretty_print_instance_variables
- instance_variables.sort
- end
-
- # Is #inspect implementation using #pretty_print.
- # If you implement #pretty_print, it can be used as follows.
- #
- # alias inspect pretty_print_inspect
- #
- # However, doing this requires that every class that #inspect is called on
- # implement #pretty_print, or a RuntimeError will be raised.
- def pretty_print_inspect
- if /\(PP::ObjectMixin\)#/ =~ Object.instance_method(:method).bind(self).call(:pretty_print).inspect
- raise "pretty_print is not overridden for #{self.class}"
- end
- PP.singleline_pp(self, '')
- end
- end
-end
-
-class Array # :nodoc:
- def pretty_print(q) # :nodoc:
- q.group(1, '[', ']') {
- q.seplist(self) {|v|
- q.pp v
- }
- }
- end
-
- def pretty_print_cycle(q) # :nodoc:
- q.text(empty? ? '[]' : '[...]')
- end
-end
-
-class Hash # :nodoc:
- def pretty_print(q) # :nodoc:
- q.pp_hash self
- end
-
- def pretty_print_cycle(q) # :nodoc:
- q.text(empty? ? '{}' : '{...}')
- end
-end
-
-class << ENV # :nodoc:
- def pretty_print(q) # :nodoc:
- h = {}
- ENV.keys.sort.each {|k|
- h[k] = ENV[k]
- }
- q.pp_hash h
- end
-end
-
-class Struct # :nodoc:
- def pretty_print(q) # :nodoc:
- q.group(1, sprintf("#<struct %s", PP.mcall(self, Kernel, :class).name), '>') {
- q.seplist(PP.mcall(self, Struct, :members), lambda { q.text "," }) {|member|
- q.breakable
- q.text member.to_s
- q.text '='
- q.group(1) {
- q.breakable ''
- q.pp self[member]
- }
- }
- }
- end
-
- def pretty_print_cycle(q) # :nodoc:
- q.text sprintf("#<struct %s:...>", PP.mcall(self, Kernel, :class).name)
- end
-end
-
-class Range # :nodoc:
- def pretty_print(q) # :nodoc:
- q.pp self.begin
- q.breakable ''
- q.text(self.exclude_end? ? '...' : '..')
- q.breakable ''
- q.pp self.end
- end
-end
-
-class File < IO # :nodoc:
- class Stat # :nodoc:
- def pretty_print(q) # :nodoc:
- require 'etc.so'
- q.object_group(self) {
- q.breakable
- q.text sprintf("dev=0x%x", self.dev); q.comma_breakable
- q.text "ino="; q.pp self.ino; q.comma_breakable
- q.group {
- m = self.mode
- q.text sprintf("mode=0%o", m)
- q.breakable
- q.text sprintf("(%s %c%c%c%c%c%c%c%c%c)",
- self.ftype,
- (m & 0400 == 0 ? ?- : ?r),
- (m & 0200 == 0 ? ?- : ?w),
- (m & 0100 == 0 ? (m & 04000 == 0 ? ?- : ?S) :
- (m & 04000 == 0 ? ?x : ?s)),
- (m & 0040 == 0 ? ?- : ?r),
- (m & 0020 == 0 ? ?- : ?w),
- (m & 0010 == 0 ? (m & 02000 == 0 ? ?- : ?S) :
- (m & 02000 == 0 ? ?x : ?s)),
- (m & 0004 == 0 ? ?- : ?r),
- (m & 0002 == 0 ? ?- : ?w),
- (m & 0001 == 0 ? (m & 01000 == 0 ? ?- : ?T) :
- (m & 01000 == 0 ? ?x : ?t)))
- }
- q.comma_breakable
- q.text "nlink="; q.pp self.nlink; q.comma_breakable
- q.group {
- q.text "uid="; q.pp self.uid
- begin
- pw = Etc.getpwuid(self.uid)
- rescue ArgumentError
- end
- if pw
- q.breakable; q.text "(#{pw.name})"
- end
- }
- q.comma_breakable
- q.group {
- q.text "gid="; q.pp self.gid
- begin
- gr = Etc.getgrgid(self.gid)
- rescue ArgumentError
- end
- if gr
- q.breakable; q.text "(#{gr.name})"
- end
- }
- q.comma_breakable
- q.group {
- q.text sprintf("rdev=0x%x", self.rdev)
- if self.rdev_major && self.rdev_minor
- q.breakable
- q.text sprintf('(%d, %d)', self.rdev_major, self.rdev_minor)
- end
- }
- q.comma_breakable
- q.text "size="; q.pp self.size; q.comma_breakable
- q.text "blksize="; q.pp self.blksize; q.comma_breakable
- q.text "blocks="; q.pp self.blocks; q.comma_breakable
- q.group {
- t = self.atime
- q.text "atime="; q.pp t
- q.breakable; q.text "(#{t.tv_sec})"
- }
- q.comma_breakable
- q.group {
- t = self.mtime
- q.text "mtime="; q.pp t
- q.breakable; q.text "(#{t.tv_sec})"
- }
- q.comma_breakable
- q.group {
- t = self.ctime
- q.text "ctime="; q.pp t
- q.breakable; q.text "(#{t.tv_sec})"
- }
- }
- end
- end
-end
-
-class MatchData # :nodoc:
- def pretty_print(q) # :nodoc:
- nc = []
- self.regexp.named_captures.each {|name, indexes|
- indexes.each {|i| nc[i] = name }
- }
- q.object_group(self) {
- q.breakable
- q.seplist(0...self.size, lambda { q.breakable }) {|i|
- if i == 0
- q.pp self[i]
- else
- if nc[i]
- q.text nc[i]
- else
- q.pp i
- end
- q.text ':'
- q.pp self[i]
- end
- }
- }
- end
-end
-
-class Object < BasicObject # :nodoc:
- include PP::ObjectMixin
-end
-
-[Numeric, Symbol, FalseClass, TrueClass, NilClass, Module].each {|c|
- c.class_eval {
- def pretty_print_cycle(q)
- q.text inspect
- end
- }
-}
-
-[Numeric, FalseClass, TrueClass, Module].each {|c|
- c.class_eval {
- def pretty_print(q)
- q.text inspect
- end
- }
-}
diff --git a/ruby_2_2/lib/prettyprint.rb b/ruby_2_2/lib/prettyprint.rb
deleted file mode 100644
index 7e989374b7..0000000000
--- a/ruby_2_2/lib/prettyprint.rb
+++ /dev/null
@@ -1,554 +0,0 @@
-# This class implements a pretty printing algorithm. It finds line breaks and
-# nice indentations for grouped structure.
-#
-# By default, the class assumes that primitive elements are strings and each
-# byte in the strings have single column in width. But it can be used for
-# other situations by giving suitable arguments for some methods:
-# * newline object and space generation block for PrettyPrint.new
-# * optional width argument for PrettyPrint#text
-# * PrettyPrint#breakable
-#
-# There are several candidate uses:
-# * text formatting using proportional fonts
-# * multibyte characters which has columns different to number of bytes
-# * non-string formatting
-#
-# == Bugs
-# * Box based formatting?
-# * Other (better) model/algorithm?
-#
-# Report any bugs at http://bugs.ruby-lang.org
-#
-# == References
-# Christian Lindig, Strictly Pretty, March 2000,
-# http://www.st.cs.uni-sb.de/~lindig/papers/#pretty
-#
-# Philip Wadler, A prettier printer, March 1998,
-# http://homepages.inf.ed.ac.uk/wadler/topics/language-design.html#prettier
-#
-# == Author
-# Tanaka Akira <akr@fsij.org>
-#
-class PrettyPrint
-
- # This is a convenience method which is same as follows:
- #
- # begin
- # q = PrettyPrint.new(output, maxwidth, newline, &genspace)
- # ...
- # q.flush
- # output
- # end
- #
- def PrettyPrint.format(output='', maxwidth=79, newline="\n", genspace=lambda {|n| ' ' * n})
- q = PrettyPrint.new(output, maxwidth, newline, &genspace)
- yield q
- q.flush
- output
- end
-
- # This is similar to PrettyPrint::format but the result has no breaks.
- #
- # +maxwidth+, +newline+ and +genspace+ are ignored.
- #
- # The invocation of +breakable+ in the block doesn't break a line and is
- # treated as just an invocation of +text+.
- #
- def PrettyPrint.singleline_format(output='', maxwidth=nil, newline=nil, genspace=nil)
- q = SingleLine.new(output)
- yield q
- output
- end
-
- # Creates a buffer for pretty printing.
- #
- # +output+ is an output target. If it is not specified, '' is assumed. It
- # should have a << method which accepts the first argument +obj+ of
- # PrettyPrint#text, the first argument +sep+ of PrettyPrint#breakable, the
- # first argument +newline+ of PrettyPrint.new, and the result of a given
- # block for PrettyPrint.new.
- #
- # +maxwidth+ specifies maximum line length. If it is not specified, 79 is
- # assumed. However actual outputs may overflow +maxwidth+ if long
- # non-breakable texts are provided.
- #
- # +newline+ is used for line breaks. "\n" is used if it is not specified.
- #
- # The block is used to generate spaces. {|width| ' ' * width} is used if it
- # is not given.
- #
- def initialize(output='', maxwidth=79, newline="\n", &genspace)
- @output = output
- @maxwidth = maxwidth
- @newline = newline
- @genspace = genspace || lambda {|n| ' ' * n}
-
- @output_width = 0
- @buffer_width = 0
- @buffer = []
-
- root_group = Group.new(0)
- @group_stack = [root_group]
- @group_queue = GroupQueue.new(root_group)
- @indent = 0
- end
-
- # The output object.
- #
- # This defaults to '', and should accept the << method
- attr_reader :output
-
- # The maximum width of a line, before it is separated in to a newline
- #
- # This defaults to 79, and should be a Fixnum
- attr_reader :maxwidth
-
- # The value that is appended to +output+ to add a new line.
- #
- # This defaults to "\n", and should be String
- attr_reader :newline
-
- # A lambda or Proc, that takes one argument, of a Fixnum, and returns
- # the corresponding number of spaces.
- #
- # By default this is:
- # lambda {|n| ' ' * n}
- attr_reader :genspace
-
- # The number of spaces to be indented
- attr_reader :indent
-
- # The PrettyPrint::GroupQueue of groups in stack to be pretty printed
- attr_reader :group_queue
-
- # Returns the group most recently added to the stack.
- #
- # Contrived example:
- # out = ""
- # => ""
- # q = PrettyPrint.new(out)
- # => #<PrettyPrint:0x82f85c0 @output="", @maxwidth=79, @newline="\n", @genspace=#<Proc:0x82f8368@/home/vbatts/.rvm/rubies/ruby-head/lib/ruby/2.0.0/prettyprint.rb:82 (lambda)>, @output_width=0, @buffer_width=0, @buffer=[], @group_stack=[#<PrettyPrint::Group:0x82f8138 @depth=0, @breakables=[], @break=false>], @group_queue=#<PrettyPrint::GroupQueue:0x82fb7c0 @queue=[[#<PrettyPrint::Group:0x82f8138 @depth=0, @breakables=[], @break=false>]]>, @indent=0>
- # q.group {
- # q.text q.current_group.inspect
- # q.text q.newline
- # q.group(q.current_group.depth + 1) {
- # q.text q.current_group.inspect
- # q.text q.newline
- # q.group(q.current_group.depth + 1) {
- # q.text q.current_group.inspect
- # q.text q.newline
- # q.group(q.current_group.depth + 1) {
- # q.text q.current_group.inspect
- # q.text q.newline
- # }
- # }
- # }
- # }
- # => 284
- # puts out
- # #<PrettyPrint::Group:0x8354758 @depth=1, @breakables=[], @break=false>
- # #<PrettyPrint::Group:0x8354550 @depth=2, @breakables=[], @break=false>
- # #<PrettyPrint::Group:0x83541cc @depth=3, @breakables=[], @break=false>
- # #<PrettyPrint::Group:0x8347e54 @depth=4, @breakables=[], @break=false>
- def current_group
- @group_stack.last
- end
-
- # Breaks the buffer into lines that are shorter than #maxwidth
- def break_outmost_groups
- while @maxwidth < @output_width + @buffer_width
- return unless group = @group_queue.deq
- until group.breakables.empty?
- data = @buffer.shift
- @output_width = data.output(@output, @output_width)
- @buffer_width -= data.width
- end
- while !@buffer.empty? && Text === @buffer.first
- text = @buffer.shift
- @output_width = text.output(@output, @output_width)
- @buffer_width -= text.width
- end
- end
- end
-
- # This adds +obj+ as a text of +width+ columns in width.
- #
- # If +width+ is not specified, obj.length is used.
- #
- def text(obj, width=obj.length)
- if @buffer.empty?
- @output << obj
- @output_width += width
- else
- text = @buffer.last
- unless Text === text
- text = Text.new
- @buffer << text
- end
- text.add(obj, width)
- @buffer_width += width
- break_outmost_groups
- end
- end
-
- # This is similar to #breakable except
- # the decision to break or not is determined individually.
- #
- # Two #fill_breakable under a group may cause 4 results:
- # (break,break), (break,non-break), (non-break,break), (non-break,non-break).
- # This is different to #breakable because two #breakable under a group
- # may cause 2 results:
- # (break,break), (non-break,non-break).
- #
- # The text +sep+ is inserted if a line is not broken at this point.
- #
- # If +sep+ is not specified, " " is used.
- #
- # If +width+ is not specified, +sep.length+ is used. You will have to
- # specify this when +sep+ is a multibyte character, for example.
- #
- def fill_breakable(sep=' ', width=sep.length)
- group { breakable sep, width }
- end
-
- # This says "you can break a line here if necessary", and a +width+\-column
- # text +sep+ is inserted if a line is not broken at the point.
- #
- # If +sep+ is not specified, " " is used.
- #
- # If +width+ is not specified, +sep.length+ is used. You will have to
- # specify this when +sep+ is a multibyte character, for example.
- #
- def breakable(sep=' ', width=sep.length)
- group = @group_stack.last
- if group.break?
- flush
- @output << @newline
- @output << @genspace.call(@indent)
- @output_width = @indent
- @buffer_width = 0
- else
- @buffer << Breakable.new(sep, width, self)
- @buffer_width += width
- break_outmost_groups
- end
- end
-
- # Groups line break hints added in the block. The line break hints are all
- # to be used or not.
- #
- # If +indent+ is specified, the method call is regarded as nested by
- # nest(indent) { ... }.
- #
- # If +open_obj+ is specified, <tt>text open_obj, open_width</tt> is called
- # before grouping. If +close_obj+ is specified, <tt>text close_obj,
- # close_width</tt> is called after grouping.
- #
- def group(indent=0, open_obj='', close_obj='', open_width=open_obj.length, close_width=close_obj.length)
- text open_obj, open_width
- group_sub {
- nest(indent) {
- yield
- }
- }
- text close_obj, close_width
- end
-
- # Takes a block and queues a new group that is indented 1 level further.
- def group_sub
- group = Group.new(@group_stack.last.depth + 1)
- @group_stack.push group
- @group_queue.enq group
- begin
- yield
- ensure
- @group_stack.pop
- if group.breakables.empty?
- @group_queue.delete group
- end
- end
- end
-
- # Increases left margin after newline with +indent+ for line breaks added in
- # the block.
- #
- def nest(indent)
- @indent += indent
- begin
- yield
- ensure
- @indent -= indent
- end
- end
-
- # outputs buffered data.
- #
- def flush
- @buffer.each {|data|
- @output_width = data.output(@output, @output_width)
- }
- @buffer.clear
- @buffer_width = 0
- end
-
- # The Text class is the means by which to collect strings from objects.
- #
- # This class is intended for internal use of the PrettyPrint buffers.
- class Text # :nodoc:
-
- # Creates a new text object.
- #
- # This constructor takes no arguments.
- #
- # The workflow is to append a PrettyPrint::Text object to the buffer, and
- # being able to call the buffer.last() to reference it.
- #
- # As there are objects, use PrettyPrint::Text#add to include the objects
- # and the width to utilized by the String version of this object.
- def initialize
- @objs = []
- @width = 0
- end
-
- # The total width of the objects included in this Text object.
- attr_reader :width
-
- # Render the String text of the objects that have been added to this Text object.
- #
- # Output the text to +out+, and increment the width to +output_width+
- def output(out, output_width)
- @objs.each {|obj| out << obj}
- output_width + @width
- end
-
- # Include +obj+ in the objects to be pretty printed, and increment
- # this Text object's total width by +width+
- def add(obj, width)
- @objs << obj
- @width += width
- end
- end
-
- # The Breakable class is used for breaking up object information
- #
- # This class is intended for internal use of the PrettyPrint buffers.
- class Breakable # :nodoc:
-
- # Create a new Breakable object.
- #
- # Arguments:
- # * +sep+ String of the separator
- # * +width+ Fixnum width of the +sep+
- # * +q+ parent PrettyPrint object, to base from
- def initialize(sep, width, q)
- @obj = sep
- @width = width
- @pp = q
- @indent = q.indent
- @group = q.current_group
- @group.breakables.push self
- end
-
- # Holds the separator String
- #
- # The +sep+ argument from ::new
- attr_reader :obj
-
- # The width of +obj+ / +sep+
- attr_reader :width
-
- # The number of spaces to indent.
- #
- # This is inferred from +q+ within PrettyPrint, passed in ::new
- attr_reader :indent
-
- # Render the String text of the objects that have been added to this
- # Breakable object.
- #
- # Output the text to +out+, and increment the width to +output_width+
- def output(out, output_width)
- @group.breakables.shift
- if @group.break?
- out << @pp.newline
- out << @pp.genspace.call(@indent)
- @indent
- else
- @pp.group_queue.delete @group if @group.breakables.empty?
- out << @obj
- output_width + @width
- end
- end
- end
-
- # The Group class is used for making indentation easier.
- #
- # While this class does neither the breaking into newlines nor indentation,
- # it is used in a stack (as well as a queue) within PrettyPrint, to group
- # objects.
- #
- # For information on using groups, see PrettyPrint#group
- #
- # This class is intended for internal use of the PrettyPrint buffers.
- class Group # :nodoc:
- # Create a Group object
- #
- # Arguments:
- # * +depth+ - this group's relation to previous groups
- def initialize(depth)
- @depth = depth
- @breakables = []
- @break = false
- end
-
- # This group's relation to previous groups
- attr_reader :depth
-
- # Array to hold the Breakable objects for this Group
- attr_reader :breakables
-
- # Makes a break for this Group, and returns true
- def break
- @break = true
- end
-
- # Boolean of whether this Group has made a break
- def break?
- @break
- end
-
- # Boolean of whether this Group has been queried for being first
- #
- # This is used as a predicate, and ought to be called first.
- def first?
- if defined? @first
- false
- else
- @first = false
- true
- end
- end
- end
-
- # The GroupQueue class is used for managing the queue of Group to be pretty
- # printed.
- #
- # This queue groups the Group objects, based on their depth.
- #
- # This class is intended for internal use of the PrettyPrint buffers.
- class GroupQueue # :nodoc:
- # Create a GroupQueue object
- #
- # Arguments:
- # * +groups+ - one or more PrettyPrint::Group objects
- def initialize(*groups)
- @queue = []
- groups.each {|g| enq g}
- end
-
- # Enqueue +group+
- #
- # This does not strictly append the group to the end of the queue,
- # but instead adds it in line, base on the +group.depth+
- def enq(group)
- depth = group.depth
- @queue << [] until depth < @queue.length
- @queue[depth] << group
- end
-
- # Returns the outer group of the queue
- def deq
- @queue.each {|gs|
- (gs.length-1).downto(0) {|i|
- unless gs[i].breakables.empty?
- group = gs.slice!(i, 1).first
- group.break
- return group
- end
- }
- gs.each {|group| group.break}
- gs.clear
- }
- return nil
- end
-
- # Remote +group+ from this queue
- def delete(group)
- @queue[group.depth].delete(group)
- end
- end
-
- # PrettyPrint::SingleLine is used by PrettyPrint.singleline_format
- #
- # It is passed to be similar to a PrettyPrint object itself, by responding to:
- # * #text
- # * #breakable
- # * #nest
- # * #group
- # * #flush
- # * #first?
- #
- # but instead, the output has no line breaks
- #
- class SingleLine
- # Create a PrettyPrint::SingleLine object
- #
- # Arguments:
- # * +output+ - String (or similar) to store rendered text. Needs to respond to '<<'
- # * +maxwidth+ - Argument position expected to be here for compatibility.
- # This argument is a noop.
- # * +newline+ - Argument position expected to be here for compatibility.
- # This argument is a noop.
- def initialize(output, maxwidth=nil, newline=nil)
- @output = output
- @first = [true]
- end
-
- # Add +obj+ to the text to be output.
- #
- # +width+ argument is here for compatibility. It is a noop argument.
- def text(obj, width=nil)
- @output << obj
- end
-
- # Appends +sep+ to the text to be output. By default +sep+ is ' '
- #
- # +width+ argument is here for compatibility. It is a noop argument.
- def breakable(sep=' ', width=nil)
- @output << sep
- end
-
- # Takes +indent+ arg, but does nothing with it.
- #
- # Yields to a block.
- def nest(indent) # :nodoc:
- yield
- end
-
- # Opens a block for grouping objects to be pretty printed.
- #
- # Arguments:
- # * +indent+ - noop argument. Present for compatibility.
- # * +open_obj+ - text appended before the &blok. Default is ''
- # * +close_obj+ - text appended after the &blok. Default is ''
- # * +open_width+ - noop argument. Present for compatibility.
- # * +close_width+ - noop argument. Present for compatibility.
- def group(indent=nil, open_obj='', close_obj='', open_width=nil, close_width=nil)
- @first.push true
- @output << open_obj
- yield
- @output << close_obj
- @first.pop
- end
-
- # Method present for compatibility, but is a noop
- def flush # :nodoc:
- end
-
- # This is used as a predicate, and ought to be called first.
- def first?
- result = @first[-1]
- @first[-1] = false
- result
- end
- end
-end
diff --git a/ruby_2_2/lib/prime.rb b/ruby_2_2/lib/prime.rb
deleted file mode 100644
index b2b55f1f2e..0000000000
--- a/ruby_2_2/lib/prime.rb
+++ /dev/null
@@ -1,487 +0,0 @@
-#
-# = prime.rb
-#
-# Prime numbers and factorization library.
-#
-# Copyright::
-# Copyright (c) 1998-2008 Keiju ISHITSUKA(SHL Japan Inc.)
-# Copyright (c) 2008 Yuki Sonoda (Yugui) <yugui@yugui.jp>
-#
-# Documentation::
-# Yuki Sonoda
-#
-
-require "singleton"
-require "forwardable"
-
-class Integer
- # Re-composes a prime factorization and returns the product.
- #
- # See Prime#int_from_prime_division for more details.
- def Integer.from_prime_division(pd)
- Prime.int_from_prime_division(pd)
- end
-
- # Returns the factorization of +self+.
- #
- # See Prime#prime_division for more details.
- def prime_division(generator = Prime::Generator23.new)
- Prime.prime_division(self, generator)
- end
-
- # Returns true if +self+ is a prime number, else returns false.
- def prime?
- Prime.prime?(self)
- end
-
- # Iterates the given block over all prime numbers.
- #
- # See +Prime+#each for more details.
- def Integer.each_prime(ubound, &block) # :yields: prime
- Prime.each(ubound, &block)
- end
-end
-
-#
-# The set of all prime numbers.
-#
-# == Example
-#
-# Prime.each(100) do |prime|
-# p prime #=> 2, 3, 5, 7, 11, ...., 97
-# end
-#
-# Prime is Enumerable:
-#
-# Prime.first 5 # => [2, 3, 5, 7, 11]
-#
-# == Retrieving the instance
-#
-# +Prime+.new is obsolete. Now +Prime+ has the default instance and you can
-# access it as +Prime+.instance.
-#
-# For convenience, each instance method of +Prime+.instance can be accessed
-# as a class method of +Prime+.
-#
-# e.g.
-# Prime.instance.prime?(2) #=> true
-# Prime.prime?(2) #=> true
-#
-# == Generators
-#
-# A "generator" provides an implementation of enumerating pseudo-prime
-# numbers and it remembers the position of enumeration and upper bound.
-# Furthermore, it is an external iterator of prime enumeration which is
-# compatible with an Enumerator.
-#
-# +Prime+::+PseudoPrimeGenerator+ is the base class for generators.
-# There are few implementations of generator.
-#
-# [+Prime+::+EratosthenesGenerator+]
-# Uses eratosthenes' sieve.
-# [+Prime+::+TrialDivisionGenerator+]
-# Uses the trial division method.
-# [+Prime+::+Generator23+]
-# Generates all positive integers which are not divisible by either 2 or 3.
-# This sequence is very bad as a pseudo-prime sequence. But this
-# is faster and uses much less memory than the other generators. So,
-# it is suitable for factorizing an integer which is not large but
-# has many prime factors. e.g. for Prime#prime? .
-
-class Prime
- include Enumerable
- @the_instance = Prime.new
-
- # obsolete. Use +Prime+::+instance+ or class methods of +Prime+.
- def initialize
- @generator = EratosthenesGenerator.new
- extend OldCompatibility
- warn "Prime::new is obsolete. use Prime::instance or class methods of Prime."
- end
-
- class << self
- extend Forwardable
- include Enumerable
- # Returns the default instance of Prime.
- def instance; @the_instance end
-
- def method_added(method) # :nodoc:
- (class<< self;self;end).def_delegator :instance, method
- end
- end
-
- # Iterates the given block over all prime numbers.
- #
- # == Parameters
- #
- # +ubound+::
- # Optional. An arbitrary positive number.
- # The upper bound of enumeration. The method enumerates
- # prime numbers infinitely if +ubound+ is nil.
- # +generator+::
- # Optional. An implementation of pseudo-prime generator.
- #
- # == Return value
- #
- # An evaluated value of the given block at the last time.
- # Or an enumerator which is compatible to an +Enumerator+
- # if no block given.
- #
- # == Description
- #
- # Calls +block+ once for each prime number, passing the prime as
- # a parameter.
- #
- # +ubound+::
- # Upper bound of prime numbers. The iterator stops after it
- # yields all prime numbers p <= +ubound+.
- #
- # == Note
- #
- # +Prime+.+new+ returns an object extended by +Prime+::+OldCompatibility+
- # in order to be compatible with Ruby 1.8, and +Prime+#each is overwritten
- # by +Prime+::+OldCompatibility+#+each+.
- #
- # +Prime+.+new+ is now obsolete. Use +Prime+.+instance+.+each+ or simply
- # +Prime+.+each+.
- def each(ubound = nil, generator = EratosthenesGenerator.new, &block)
- generator.upper_bound = ubound
- generator.each(&block)
- end
-
-
- # Returns true if +value+ is a prime number, else returns false.
- #
- # == Parameters
- #
- # +value+:: an arbitrary integer to be checked.
- # +generator+:: optional. A pseudo-prime generator.
- def prime?(value, generator = Prime::Generator23.new)
- return false if value < 2
- for num in generator
- q,r = value.divmod num
- return true if q < num
- return false if r == 0
- end
- end
-
- # Re-composes a prime factorization and returns the product.
- #
- # == Parameters
- # +pd+:: Array of pairs of integers. The each internal
- # pair consists of a prime number -- a prime factor --
- # and a natural number -- an exponent.
- #
- # == Example
- # For <tt>[[p_1, e_1], [p_2, e_2], ...., [p_n, e_n]]</tt>, it returns:
- #
- # p_1**e_1 * p_2**e_2 * .... * p_n**e_n.
- #
- # Prime.int_from_prime_division([[2,2], [3,1]]) #=> 12
- def int_from_prime_division(pd)
- pd.inject(1){|value, (prime, index)|
- value * prime**index
- }
- end
-
- # Returns the factorization of +value+.
- #
- # == Parameters
- # +value+:: An arbitrary integer.
- # +generator+:: Optional. A pseudo-prime generator.
- # +generator+.succ must return the next
- # pseudo-prime number in the ascending
- # order. It must generate all prime numbers,
- # but may also generate non prime numbers too.
- #
- # === Exceptions
- # +ZeroDivisionError+:: when +value+ is zero.
- #
- # == Example
- # For an arbitrary integer:
- #
- # n = p_1**e_1 * p_2**e_2 * .... * p_n**e_n,
- #
- # prime_division(n) returns:
- #
- # [[p_1, e_1], [p_2, e_2], ...., [p_n, e_n]].
- #
- # Prime.prime_division(12) #=> [[2,2], [3,1]]
- #
- def prime_division(value, generator = Prime::Generator23.new)
- raise ZeroDivisionError if value == 0
- if value < 0
- value = -value
- pv = [[-1, 1]]
- else
- pv = []
- end
- for prime in generator
- count = 0
- while (value1, mod = value.divmod(prime)
- mod) == 0
- value = value1
- count += 1
- end
- if count != 0
- pv.push [prime, count]
- end
- break if value1 <= prime
- end
- if value > 1
- pv.push [value, 1]
- end
- return pv
- end
-
- # An abstract class for enumerating pseudo-prime numbers.
- #
- # Concrete subclasses should override succ, next, rewind.
- class PseudoPrimeGenerator
- include Enumerable
-
- def initialize(ubound = nil)
- @ubound = ubound
- end
-
- def upper_bound=(ubound)
- @ubound = ubound
- end
- def upper_bound
- @ubound
- end
-
- # returns the next pseudo-prime number, and move the internal
- # position forward.
- #
- # +PseudoPrimeGenerator+#succ raises +NotImplementedError+.
- def succ
- raise NotImplementedError, "need to define `succ'"
- end
-
- # alias of +succ+.
- def next
- raise NotImplementedError, "need to define `next'"
- end
-
- # Rewinds the internal position for enumeration.
- #
- # See +Enumerator+#rewind.
- def rewind
- raise NotImplementedError, "need to define `rewind'"
- end
-
- # Iterates the given block for each prime number.
- def each
- return self.dup unless block_given?
- if @ubound
- last_value = nil
- loop do
- prime = succ
- break last_value if prime > @ubound
- last_value = yield prime
- end
- else
- loop do
- yield succ
- end
- end
- end
-
- # see +Enumerator+#with_index.
- alias with_index each_with_index
-
- # see +Enumerator+#with_object.
- def with_object(obj)
- return enum_for(:with_object) unless block_given?
- each do |prime|
- yield prime, obj
- end
- end
- end
-
- # An implementation of +PseudoPrimeGenerator+.
- #
- # Uses +EratosthenesSieve+.
- class EratosthenesGenerator < PseudoPrimeGenerator
- def initialize
- @last_prime_index = -1
- super
- end
-
- def succ
- @last_prime_index += 1
- EratosthenesSieve.instance.get_nth_prime(@last_prime_index)
- end
- def rewind
- initialize
- end
- alias next succ
- end
-
- # An implementation of +PseudoPrimeGenerator+ which uses
- # a prime table generated by trial division.
- class TrialDivisionGenerator<PseudoPrimeGenerator
- def initialize
- @index = -1
- super
- end
-
- def succ
- TrialDivision.instance[@index += 1]
- end
- def rewind
- initialize
- end
- alias next succ
- end
-
- # Generates all integers which are greater than 2 and
- # are not divisible by either 2 or 3.
- #
- # This is a pseudo-prime generator, suitable on
- # checking primality of an integer by brute force
- # method.
- class Generator23<PseudoPrimeGenerator
- def initialize
- @prime = 1
- @step = nil
- super
- end
-
- def succ
- if (@step)
- @prime += @step
- @step = 6 - @step
- else
- case @prime
- when 1; @prime = 2
- when 2; @prime = 3
- when 3; @prime = 5; @step = 2
- end
- end
- return @prime
- end
- alias next succ
- def rewind
- initialize
- end
- end
-
- # Internal use. An implementation of prime table by trial division method.
- class TrialDivision
- include Singleton
-
- def initialize # :nodoc:
- # These are included as class variables to cache them for later uses. If memory
- # usage is a problem, they can be put in Prime#initialize as instance variables.
-
- # There must be no primes between @primes[-1] and @next_to_check.
- @primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]
- # @next_to_check % 6 must be 1.
- @next_to_check = 103 # @primes[-1] - @primes[-1] % 6 + 7
- @ulticheck_index = 3 # @primes.index(@primes.reverse.find {|n|
- # n < Math.sqrt(@@next_to_check) })
- @ulticheck_next_squared = 121 # @primes[@ulticheck_index + 1] ** 2
- end
-
- # Returns the cached prime numbers.
- def cache
- return @primes
- end
- alias primes cache
- alias primes_so_far cache
-
- # Returns the +index+th prime number.
- #
- # +index+ is a 0-based index.
- def [](index)
- while index >= @primes.length
- # Only check for prime factors up to the square root of the potential primes,
- # but without the performance hit of an actual square root calculation.
- if @next_to_check + 4 > @ulticheck_next_squared
- @ulticheck_index += 1
- @ulticheck_next_squared = @primes.at(@ulticheck_index + 1) ** 2
- end
- # Only check numbers congruent to one and five, modulo six. All others
-
- # are divisible by two or three. This also allows us to skip checking against
- # two and three.
- @primes.push @next_to_check if @primes[2..@ulticheck_index].find {|prime| @next_to_check % prime == 0 }.nil?
- @next_to_check += 4
- @primes.push @next_to_check if @primes[2..@ulticheck_index].find {|prime| @next_to_check % prime == 0 }.nil?
- @next_to_check += 2
- end
- return @primes[index]
- end
- end
-
- # Internal use. An implementation of eratosthenes' sieve
- class EratosthenesSieve
- include Singleton
-
- def initialize
- @primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]
- # @max_checked must be an even number
- @max_checked = @primes.last + 1
- end
-
- def get_nth_prime(n)
- compute_primes while @primes.size <= n
- @primes[n]
- end
-
- private
- def compute_primes
- # max_segment_size must be an even number
- max_segment_size = 1e6.to_i
- max_cached_prime = @primes.last
- # do not double count primes if #compute_primes is interrupted
- # by Timeout.timeout
- @max_checked = max_cached_prime + 1 if max_cached_prime > @max_checked
-
- segment_min = @max_checked
- segment_max = [segment_min + max_segment_size, max_cached_prime * 2].min
- root = Integer(Math.sqrt(segment_max).floor)
-
- sieving_primes = @primes[1 .. -1].take_while { |prime| prime <= root }
- offsets = Array.new(sieving_primes.size) do |i|
- (-(segment_min + 1 + sieving_primes[i]) / 2) % sieving_primes[i]
- end
-
- segment = ((segment_min + 1) .. segment_max).step(2).to_a
- sieving_primes.each_with_index do |prime, index|
- composite_index = offsets[index]
- while composite_index < segment.size do
- segment[composite_index] = nil
- composite_index += prime
- end
- end
-
- segment.each do |prime|
- @primes.push prime unless prime.nil?
- end
- @max_checked = segment_max
- end
- end
-
- # Provides a +Prime+ object with compatibility to Ruby 1.8 when instantiated via +Prime+.+new+.
- module OldCompatibility
- # Returns the next prime number and forwards internal pointer.
- def succ
- @generator.succ
- end
- alias next succ
-
- # Overwrites Prime#each.
- #
- # Iterates the given block over all prime numbers. Note that enumeration
- # starts from the current position of internal pointer, not rewound.
- def each
- return @generator.dup unless block_given?
- loop do
- yield succ
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/profile.rb b/ruby_2_2/lib/profile.rb
deleted file mode 100644
index 2aeecce908..0000000000
--- a/ruby_2_2/lib/profile.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require 'profiler'
-
-RubyVM::InstructionSequence.compile_option = {
- :trace_instruction => true,
- :specialized_instruction => false
-}
-END {
- Profiler__::print_profile(STDERR)
-}
-Profiler__::start_profile
diff --git a/ruby_2_2/lib/profiler.rb b/ruby_2_2/lib/profiler.rb
deleted file mode 100644
index e53951cbe6..0000000000
--- a/ruby_2_2/lib/profiler.rb
+++ /dev/null
@@ -1,148 +0,0 @@
-# Profile provides a way to Profile your Ruby application.
-#
-# Profiling your program is a way of determining which methods are called and
-# how long each method takes to complete. This way you can detect which
-# methods are possible bottlenecks.
-#
-# Profiling your program will slow down your execution time considerably,
-# so activate it only when you need it. Don't confuse benchmarking with
-# profiling.
-#
-# There are two ways to activate Profiling:
-#
-# == Command line
-#
-# Run your Ruby script with <code>-rprofile</code>:
-#
-# ruby -rprofile example.rb
-#
-# If you're profiling an executable in your <code>$PATH</code> you can use
-# <code>ruby -S</code>:
-#
-# ruby -rprofile -S some_executable
-#
-# == From code
-#
-# Just require 'profile':
-#
-# require 'profile'
-#
-# def slow_method
-# 5000.times do
-# 9999999999999999*999999999
-# end
-# end
-#
-# def fast_method
-# 5000.times do
-# 9999999999999999+999999999
-# end
-# end
-#
-# slow_method
-# fast_method
-#
-# The output in both cases is a report when the execution is over:
-#
-# ruby -rprofile example.rb
-#
-# % cumulative self self total
-# time seconds seconds calls ms/call ms/call name
-# 68.42 0.13 0.13 2 65.00 95.00 Integer#times
-# 15.79 0.16 0.03 5000 0.01 0.01 Fixnum#*
-# 15.79 0.19 0.03 5000 0.01 0.01 Fixnum#+
-# 0.00 0.19 0.00 2 0.00 0.00 IO#set_encoding
-# 0.00 0.19 0.00 1 0.00 100.00 Object#slow_method
-# 0.00 0.19 0.00 2 0.00 0.00 Module#method_added
-# 0.00 0.19 0.00 1 0.00 90.00 Object#fast_method
-# 0.00 0.19 0.00 1 0.00 190.00 #toplevel
-
-module Profiler__
- class Wrapper < Struct.new(:defined_class, :method_id, :hash) # :nodoc:
- private :defined_class=, :method_id=, :hash=
-
- def initialize(klass, mid)
- super(klass, mid, nil)
- self.hash = Struct.instance_method(:hash).bind(self).call
- end
-
- def to_s
- "#{defined_class.inspect}#".sub(/\A\#<Class:(.*)>#\z/, '\1.') << method_id.to_s
- end
- alias inspect to_s
- end
-
- # internal values
- @@start = nil # the start time that profiling began
- @@stacks = nil # the map of stacks keyed by thread
- @@maps = nil # the map of call data keyed by thread, class and id. Call data contains the call count, total time,
- PROFILE_CALL_PROC = TracePoint.new(*%i[call c_call b_call]) {|tp| # :nodoc:
- now = Process.times[0]
- stack = (@@stacks[Thread.current] ||= [])
- stack.push [now, 0.0]
- }
- PROFILE_RETURN_PROC = TracePoint.new(*%i[return c_return b_return]) {|tp| # :nodoc:
- now = Process.times[0]
- key = Wrapper.new(tp.defined_class, tp.method_id)
- stack = (@@stacks[Thread.current] ||= [])
- if tick = stack.pop
- threadmap = (@@maps[Thread.current] ||= {})
- data = (threadmap[key] ||= [0, 0.0, 0.0, key])
- data[0] += 1
- cost = now - tick[0]
- data[1] += cost
- data[2] += cost - tick[1]
- stack[-1][1] += cost if stack[-1]
- end
- }
-module_function
- # Starts the profiler.
- #
- # See Profiler__ for more information.
- def start_profile
- @@start = Process.times[0]
- @@stacks = {}
- @@maps = {}
- PROFILE_CALL_PROC.enable
- PROFILE_RETURN_PROC.enable
- end
- # Stops the profiler.
- #
- # See Profiler__ for more information.
- def stop_profile
- PROFILE_CALL_PROC.disable
- PROFILE_RETURN_PROC.disable
- end
- # Outputs the results from the profiler.
- #
- # See Profiler__ for more information.
- def print_profile(f)
- stop_profile
- total = Process.times[0] - @@start
- if total == 0 then total = 0.01 end
- totals = {}
- @@maps.values.each do |threadmap|
- threadmap.each do |key, data|
- total_data = (totals[key] ||= [0, 0.0, 0.0, key])
- total_data[0] += data[0]
- total_data[1] += data[1]
- total_data[2] += data[2]
- end
- end
-
- # Maybe we should show a per thread output and a totals view?
-
- data = totals.values
- data = data.sort_by{|x| -x[2]}
- sum = 0
- f.printf " %% cumulative self self total\n"
- f.printf " time seconds seconds calls ms/call ms/call name\n"
- for d in data
- sum += d[2]
- f.printf "%6.2f %8.2f %8.2f %8d ", d[2]/total*100, sum, d[2], d[0]
- f.printf "%8.2f %8.2f %s\n", d[2]*1000/d[0], d[1]*1000/d[0], d[3]
- end
- f.printf "%6.2f %8.2f %8.2f %8d ", 0.0, total, 0.0, 1 # ???
- f.printf "%8.2f %8.2f %s\n", 0.0, total*1000, "#toplevel" # ???
- end
-end
diff --git a/ruby_2_2/lib/pstore.rb b/ruby_2_2/lib/pstore.rb
deleted file mode 100644
index 02c20c91c7..0000000000
--- a/ruby_2_2/lib/pstore.rb
+++ /dev/null
@@ -1,484 +0,0 @@
-# = PStore -- Transactional File Storage for Ruby Objects
-#
-# pstore.rb -
-# originally by matz
-# documentation by Kev Jackson and James Edward Gray II
-# improved by Hongli Lai
-#
-# See PStore for documentation.
-
-require "digest/md5"
-
-#
-# PStore implements a file based persistence mechanism based on a Hash. User
-# code can store hierarchies of Ruby objects (values) into the data store file
-# by name (keys). An object hierarchy may be just a single object. User code
-# may later read values back from the data store or even update data, as needed.
-#
-# The transactional behavior ensures that any changes succeed or fail together.
-# This can be used to ensure that the data store is not left in a transitory
-# state, where some values were updated but others were not.
-#
-# Behind the scenes, Ruby objects are stored to the data store file with
-# Marshal. That carries the usual limitations. Proc objects cannot be
-# marshalled, for example.
-#
-# == Usage example:
-#
-# require "pstore"
-#
-# # a mock wiki object...
-# class WikiPage
-# def initialize( page_name, author, contents )
-# @page_name = page_name
-# @revisions = Array.new
-#
-# add_revision(author, contents)
-# end
-#
-# attr_reader :page_name
-#
-# def add_revision( author, contents )
-# @revisions << { :created => Time.now,
-# :author => author,
-# :contents => contents }
-# end
-#
-# def wiki_page_references
-# [@page_name] + @revisions.last[:contents].scan(/\b(?:[A-Z]+[a-z]+){2,}/)
-# end
-#
-# # ...
-# end
-#
-# # create a new page...
-# home_page = WikiPage.new( "HomePage", "James Edward Gray II",
-# "A page about the JoysOfDocumentation..." )
-#
-# # then we want to update page data and the index together, or not at all...
-# wiki = PStore.new("wiki_pages.pstore")
-# wiki.transaction do # begin transaction; do all of this or none of it
-# # store page...
-# wiki[home_page.page_name] = home_page
-# # ensure that an index has been created...
-# wiki[:wiki_index] ||= Array.new
-# # update wiki index...
-# wiki[:wiki_index].push(*home_page.wiki_page_references)
-# end # commit changes to wiki data store file
-#
-# ### Some time later... ###
-#
-# # read wiki data...
-# wiki.transaction(true) do # begin read-only transaction, no changes allowed
-# wiki.roots.each do |data_root_name|
-# p data_root_name
-# p wiki[data_root_name]
-# end
-# end
-#
-# == Transaction modes
-#
-# By default, file integrity is only ensured as long as the operating system
-# (and the underlying hardware) doesn't raise any unexpected I/O errors. If an
-# I/O error occurs while PStore is writing to its file, then the file will
-# become corrupted.
-#
-# You can prevent this by setting <em>pstore.ultra_safe = true</em>.
-# However, this results in a minor performance loss, and only works on platforms
-# that support atomic file renames. Please consult the documentation for
-# +ultra_safe+ for details.
-#
-# Needless to say, if you're storing valuable data with PStore, then you should
-# backup the PStore files from time to time.
-class PStore
- RDWR_ACCESS = {mode: IO::RDWR | IO::CREAT | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze
- RD_ACCESS = {mode: IO::RDONLY | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze
- WR_ACCESS = {mode: IO::WRONLY | IO::CREAT | IO::TRUNC | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze
-
- # The error type thrown by all PStore methods.
- class Error < StandardError
- end
-
- # Whether PStore should do its best to prevent file corruptions, even when under
- # unlikely-to-occur error conditions such as out-of-space conditions and other
- # unusual OS filesystem errors. Setting this flag comes at the price in the form
- # of a performance loss.
- #
- # This flag only has effect on platforms on which file renames are atomic (e.g.
- # all POSIX platforms: Linux, MacOS X, FreeBSD, etc). The default value is false.
- attr_accessor :ultra_safe
-
- #
- # To construct a PStore object, pass in the _file_ path where you would like
- # the data to be stored.
- #
- # PStore objects are always reentrant. But if _thread_safe_ is set to true,
- # then it will become thread-safe at the cost of a minor performance hit.
- #
- def initialize(file, thread_safe = false)
- dir = File::dirname(file)
- unless File::directory? dir
- raise PStore::Error, format("directory %s does not exist", dir)
- end
- if File::exist? file and not File::readable? file
- raise PStore::Error, format("file %s not readable", file)
- end
- @filename = file
- @abort = false
- @ultra_safe = false
- @thread_safe = thread_safe
- @lock = Mutex.new
- end
-
- # Raises PStore::Error if the calling code is not in a PStore#transaction.
- def in_transaction
- raise PStore::Error, "not in transaction" unless @lock.locked?
- end
- #
- # Raises PStore::Error if the calling code is not in a PStore#transaction or
- # if the code is in a read-only PStore#transaction.
- #
- def in_transaction_wr
- in_transaction
- raise PStore::Error, "in read-only transaction" if @rdonly
- end
- private :in_transaction, :in_transaction_wr
-
- #
- # Retrieves a value from the PStore file data, by _name_. The hierarchy of
- # Ruby objects stored under that root _name_ will be returned.
- #
- # *WARNING*: This method is only valid in a PStore#transaction. It will
- # raise PStore::Error if called at any other time.
- #
- def [](name)
- in_transaction
- @table[name]
- end
- #
- # This method is just like PStore#[], save that you may also provide a
- # _default_ value for the object. In the event the specified _name_ is not
- # found in the data store, your _default_ will be returned instead. If you do
- # not specify a default, PStore::Error will be raised if the object is not
- # found.
- #
- # *WARNING*: This method is only valid in a PStore#transaction. It will
- # raise PStore::Error if called at any other time.
- #
- def fetch(name, default=PStore::Error)
- in_transaction
- unless @table.key? name
- if default == PStore::Error
- raise PStore::Error, format("undefined root name `%s'", name)
- else
- return default
- end
- end
- @table[name]
- end
- #
- # Stores an individual Ruby object or a hierarchy of Ruby objects in the data
- # store file under the root _name_. Assigning to a _name_ already in the data
- # store clobbers the old data.
- #
- # == Example:
- #
- # require "pstore"
- #
- # store = PStore.new("data_file.pstore")
- # store.transaction do # begin transaction
- # # load some data into the store...
- # store[:single_object] = "My data..."
- # store[:obj_heirarchy] = { "Kev Jackson" => ["rational.rb", "pstore.rb"],
- # "James Gray" => ["erb.rb", "pstore.rb"] }
- # end # commit changes to data store file
- #
- # *WARNING*: This method is only valid in a PStore#transaction and it cannot
- # be read-only. It will raise PStore::Error if called at any other time.
- #
- def []=(name, value)
- in_transaction_wr
- @table[name] = value
- end
- #
- # Removes an object hierarchy from the data store, by _name_.
- #
- # *WARNING*: This method is only valid in a PStore#transaction and it cannot
- # be read-only. It will raise PStore::Error if called at any other time.
- #
- def delete(name)
- in_transaction_wr
- @table.delete name
- end
-
- #
- # Returns the names of all object hierarchies currently in the store.
- #
- # *WARNING*: This method is only valid in a PStore#transaction. It will
- # raise PStore::Error if called at any other time.
- #
- def roots
- in_transaction
- @table.keys
- end
- #
- # Returns true if the supplied _name_ is currently in the data store.
- #
- # *WARNING*: This method is only valid in a PStore#transaction. It will
- # raise PStore::Error if called at any other time.
- #
- def root?(name)
- in_transaction
- @table.key? name
- end
- # Returns the path to the data store file.
- def path
- @filename
- end
-
- #
- # Ends the current PStore#transaction, committing any changes to the data
- # store immediately.
- #
- # == Example:
- #
- # require "pstore"
- #
- # store = PStore.new("data_file.pstore")
- # store.transaction do # begin transaction
- # # load some data into the store...
- # store[:one] = 1
- # store[:two] = 2
- #
- # store.commit # end transaction here, committing changes
- #
- # store[:three] = 3 # this change is never reached
- # end
- #
- # *WARNING*: This method is only valid in a PStore#transaction. It will
- # raise PStore::Error if called at any other time.
- #
- def commit
- in_transaction
- @abort = false
- throw :pstore_abort_transaction
- end
- #
- # Ends the current PStore#transaction, discarding any changes to the data
- # store.
- #
- # == Example:
- #
- # require "pstore"
- #
- # store = PStore.new("data_file.pstore")
- # store.transaction do # begin transaction
- # store[:one] = 1 # this change is not applied, see below...
- # store[:two] = 2 # this change is not applied, see below...
- #
- # store.abort # end transaction here, discard all changes
- #
- # store[:three] = 3 # this change is never reached
- # end
- #
- # *WARNING*: This method is only valid in a PStore#transaction. It will
- # raise PStore::Error if called at any other time.
- #
- def abort
- in_transaction
- @abort = true
- throw :pstore_abort_transaction
- end
-
- #
- # Opens a new transaction for the data store. Code executed inside a block
- # passed to this method may read and write data to and from the data store
- # file.
- #
- # At the end of the block, changes are committed to the data store
- # automatically. You may exit the transaction early with a call to either
- # PStore#commit or PStore#abort. See those methods for details about how
- # changes are handled. Raising an uncaught Exception in the block is
- # equivalent to calling PStore#abort.
- #
- # If _read_only_ is set to +true+, you will only be allowed to read from the
- # data store during the transaction and any attempts to change the data will
- # raise a PStore::Error.
- #
- # Note that PStore does not support nested transactions.
- #
- def transaction(read_only = false) # :yields: pstore
- value = nil
- if !@thread_safe
- raise PStore::Error, "nested transaction" unless @lock.try_lock
- else
- begin
- @lock.lock
- rescue ThreadError
- raise PStore::Error, "nested transaction"
- end
- end
- begin
- @rdonly = read_only
- @abort = false
- file = open_and_lock_file(@filename, read_only)
- if file
- begin
- @table, checksum, original_data_size = load_data(file, read_only)
-
- catch(:pstore_abort_transaction) do
- value = yield(self)
- end
-
- if !@abort && !read_only
- save_data(checksum, original_data_size, file)
- end
- ensure
- file.close if !file.closed?
- end
- else
- # This can only occur if read_only == true.
- @table = {}
- catch(:pstore_abort_transaction) do
- value = yield(self)
- end
- end
- ensure
- @lock.unlock
- end
- value
- end
-
- private
- # Constant for relieving Ruby's garbage collector.
- EMPTY_STRING = ""
- EMPTY_MARSHAL_DATA = Marshal.dump({})
- EMPTY_MARSHAL_CHECKSUM = Digest::MD5.digest(EMPTY_MARSHAL_DATA)
-
- #
- # Open the specified filename (either in read-only mode or in
- # read-write mode) and lock it for reading or writing.
- #
- # The opened File object will be returned. If _read_only_ is true,
- # and the file does not exist, then nil will be returned.
- #
- # All exceptions are propagated.
- #
- def open_and_lock_file(filename, read_only)
- if read_only
- begin
- file = File.new(filename, RD_ACCESS)
- begin
- file.flock(File::LOCK_SH)
- return file
- rescue
- file.close
- raise
- end
- rescue Errno::ENOENT
- return nil
- end
- else
- file = File.new(filename, RDWR_ACCESS)
- file.flock(File::LOCK_EX)
- return file
- end
- end
-
- # Load the given PStore file.
- # If +read_only+ is true, the unmarshalled Hash will be returned.
- # If +read_only+ is false, a 3-tuple will be returned: the unmarshalled
- # Hash, an MD5 checksum of the data, and the size of the data.
- def load_data(file, read_only)
- if read_only
- begin
- table = load(file)
- raise Error, "PStore file seems to be corrupted." unless table.is_a?(Hash)
- rescue EOFError
- # This seems to be a newly-created file.
- table = {}
- end
- table
- else
- data = file.read
- if data.empty?
- # This seems to be a newly-created file.
- table = {}
- checksum = empty_marshal_checksum
- size = empty_marshal_data.bytesize
- else
- table = load(data)
- checksum = Digest::MD5.digest(data)
- size = data.bytesize
- raise Error, "PStore file seems to be corrupted." unless table.is_a?(Hash)
- end
- data.replace(EMPTY_STRING)
- [table, checksum, size]
- end
- end
-
- def on_windows?
- is_windows = RUBY_PLATFORM =~ /mswin|mingw|bccwin|wince/
- self.class.__send__(:define_method, :on_windows?) do
- is_windows
- end
- is_windows
- end
-
- def save_data(original_checksum, original_file_size, file)
- new_data = dump(@table)
-
- if new_data.bytesize != original_file_size || Digest::MD5.digest(new_data) != original_checksum
- if @ultra_safe && !on_windows?
- # Windows doesn't support atomic file renames.
- save_data_with_atomic_file_rename_strategy(new_data, file)
- else
- save_data_with_fast_strategy(new_data, file)
- end
- end
-
- new_data.replace(EMPTY_STRING)
- end
-
- def save_data_with_atomic_file_rename_strategy(data, file)
- temp_filename = "#{@filename}.tmp.#{Process.pid}.#{rand 1000000}"
- temp_file = File.new(temp_filename, WR_ACCESS)
- begin
- temp_file.flock(File::LOCK_EX)
- temp_file.write(data)
- temp_file.flush
- File.rename(temp_filename, @filename)
- rescue
- File.unlink(temp_file) rescue nil
- raise
- ensure
- temp_file.close
- end
- end
-
- def save_data_with_fast_strategy(data, file)
- file.rewind
- file.write(data)
- file.truncate(data.bytesize)
- end
-
-
- # This method is just a wrapped around Marshal.dump
- # to allow subclass overriding used in YAML::Store.
- def dump(table) # :nodoc:
- Marshal::dump(table)
- end
-
- # This method is just a wrapped around Marshal.load.
- # to allow subclass overriding used in YAML::Store.
- def load(content) # :nodoc:
- Marshal::load(content)
- end
-
- def empty_marshal_data
- EMPTY_MARSHAL_DATA
- end
- def empty_marshal_checksum
- EMPTY_MARSHAL_CHECKSUM
- end
-end
diff --git a/ruby_2_2/lib/racc/parser.rb b/ruby_2_2/lib/racc/parser.rb
deleted file mode 100644
index f811ab6e78..0000000000
--- a/ruby_2_2/lib/racc/parser.rb
+++ /dev/null
@@ -1,622 +0,0 @@
-#--
-# $originalId: parser.rb,v 1.8 2006/07/06 11:42:07 aamine Exp $
-#
-# Copyright (c) 1999-2006 Minero Aoki
-#
-# This program is free software.
-# You can distribute/modify this program under the same terms of ruby.
-#
-# As a special exception, when this code is copied by Racc
-# into a Racc output file, you may use that output file
-# without restriction.
-#++
-
-module Racc
- class ParseError < StandardError; end
-end
-unless defined?(::ParseError)
- ParseError = Racc::ParseError
-end
-
-# Racc is a LALR(1) parser generator.
-# It is written in Ruby itself, and generates Ruby programs.
-#
-# == Command-line Reference
-#
-# racc [-o<var>filename</var>] [--output-file=<var>filename</var>]
-# [-e<var>rubypath</var>] [--embedded=<var>rubypath</var>]
-# [-v] [--verbose]
-# [-O<var>filename</var>] [--log-file=<var>filename</var>]
-# [-g] [--debug]
-# [-E] [--embedded]
-# [-l] [--no-line-convert]
-# [-c] [--line-convert-all]
-# [-a] [--no-omit-actions]
-# [-C] [--check-only]
-# [-S] [--output-status]
-# [--version] [--copyright] [--help] <var>grammarfile</var>
-#
-# [+filename+]
-# Racc grammar file. Any extension is permitted.
-# [-o+outfile+, --output-file=+outfile+]
-# A filename for output. default is <+filename+>.tab.rb
-# [-O+filename+, --log-file=+filename+]
-# Place logging output in file +filename+.
-# Default log file name is <+filename+>.output.
-# [-e+rubypath+, --executable=+rubypath+]
-# output executable file(mode 755). where +path+ is the Ruby interpreter.
-# [-v, --verbose]
-# verbose mode. create +filename+.output file, like yacc's y.output file.
-# [-g, --debug]
-# add debug code to parser class. To display debugging information,
-# use this '-g' option and set @yydebug true in parser class.
-# [-E, --embedded]
-# Output parser which doesn't need runtime files (racc/parser.rb).
-# [-C, --check-only]
-# Check syntax of racc grammar file and quit.
-# [-S, --output-status]
-# Print messages time to time while compiling.
-# [-l, --no-line-convert]
-# turns off line number converting.
-# [-c, --line-convert-all]
-# Convert line number of actions, inner, header and footer.
-# [-a, --no-omit-actions]
-# Call all actions, even if an action is empty.
-# [--version]
-# print Racc version and quit.
-# [--copyright]
-# Print copyright and quit.
-# [--help]
-# Print usage and quit.
-#
-# == Generating Parser Using Racc
-#
-# To compile Racc grammar file, simply type:
-#
-# $ racc parse.y
-#
-# This creates Ruby script file "parse.tab.y". The -o option can change the output filename.
-#
-# == Writing A Racc Grammar File
-#
-# If you want your own parser, you have to write a grammar file.
-# A grammar file contains the name of your parser class, grammar for the parser,
-# user code, and anything else.
-# When writing a grammar file, yacc's knowledge is helpful.
-# If you have not used yacc before, Racc is not too difficult.
-#
-# Here's an example Racc grammar file.
-#
-# class Calcparser
-# rule
-# target: exp { print val[0] }
-#
-# exp: exp '+' exp
-# | exp '*' exp
-# | '(' exp ')'
-# | NUMBER
-# end
-#
-# Racc grammar files resemble yacc files.
-# But (of course), this is Ruby code.
-# yacc's $$ is the 'result', $0, $1... is
-# an array called 'val', and $-1, $-2... is an array called '_values'.
-#
-# See the {Grammar File Reference}[rdoc-ref:lib/racc/rdoc/grammar.en.rdoc] for
-# more information on grammar files.
-#
-# == Parser
-#
-# Then you must prepare the parse entry method. There are two types of
-# parse methods in Racc, Racc::Parser#do_parse and Racc::Parser#yyparse
-#
-# Racc::Parser#do_parse is simple.
-#
-# It's yyparse() of yacc, and Racc::Parser#next_token is yylex().
-# This method must returns an array like [TOKENSYMBOL, ITS_VALUE].
-# EOF is [false, false].
-# (TOKENSYMBOL is a Ruby symbol (taken from String#intern) by default.
-# If you want to change this, see the grammar reference.
-#
-# Racc::Parser#yyparse is little complicated, but useful.
-# It does not use Racc::Parser#next_token, instead it gets tokens from any iterator.
-#
-# For example, <code>yyparse(obj, :scan)</code> causes
-# calling +obj#scan+, and you can return tokens by yielding them from +obj#scan+.
-#
-# == Debugging
-#
-# When debugging, "-v" or/and the "-g" option is helpful.
-#
-# "-v" creates verbose log file (.output).
-# "-g" creates a "Verbose Parser".
-# Verbose Parser prints the internal status when parsing.
-# But it's _not_ automatic.
-# You must use -g option and set +@yydebug+ to +true+ in order to get output.
-# -g option only creates the verbose parser.
-#
-# === Racc reported syntax error.
-#
-# Isn't there too many "end"?
-# grammar of racc file is changed in v0.10.
-#
-# Racc does not use '%' mark, while yacc uses huge number of '%' marks..
-#
-# === Racc reported "XXXX conflicts".
-#
-# Try "racc -v xxxx.y".
-# It causes producing racc's internal log file, xxxx.output.
-#
-# === Generated parsers does not work correctly
-#
-# Try "racc -g xxxx.y".
-# This command let racc generate "debugging parser".
-# Then set @yydebug=true in your parser.
-# It produces a working log of your parser.
-#
-# == Re-distributing Racc runtime
-#
-# A parser, which is created by Racc, requires the Racc runtime module;
-# racc/parser.rb.
-#
-# Ruby 1.8.x comes with Racc runtime module,
-# you need NOT distribute Racc runtime files.
-#
-# If you want to include the Racc runtime module with your parser.
-# This can be done by using '-E' option:
-#
-# $ racc -E -omyparser.rb myparser.y
-#
-# This command creates myparser.rb which `includes' Racc runtime.
-# Only you must do is to distribute your parser file (myparser.rb).
-#
-# Note: parser.rb is LGPL, but your parser is not.
-# Your own parser is completely yours.
-module Racc
-
- unless defined?(Racc_No_Extensions)
- Racc_No_Extensions = false # :nodoc:
- end
-
- class Parser
-
- Racc_Runtime_Version = '1.4.6'
- Racc_Runtime_Revision = %w$originalRevision: 1.8 $[1]
-
- Racc_Runtime_Core_Version_R = '1.4.6'
- Racc_Runtime_Core_Revision_R = %w$originalRevision: 1.8 $[1]
- begin
- require 'racc/cparse'
- # Racc_Runtime_Core_Version_C = (defined in extension)
- Racc_Runtime_Core_Revision_C = Racc_Runtime_Core_Id_C.split[2]
- unless new.respond_to?(:_racc_do_parse_c, true)
- raise LoadError, 'old cparse.so'
- end
- if Racc_No_Extensions
- raise LoadError, 'selecting ruby version of racc runtime core'
- end
-
- Racc_Main_Parsing_Routine = :_racc_do_parse_c # :nodoc:
- Racc_YY_Parse_Method = :_racc_yyparse_c # :nodoc:
- Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_C # :nodoc:
- Racc_Runtime_Core_Revision = Racc_Runtime_Core_Revision_C # :nodoc:
- Racc_Runtime_Type = 'c' # :nodoc:
- rescue LoadError
- Racc_Main_Parsing_Routine = :_racc_do_parse_rb
- Racc_YY_Parse_Method = :_racc_yyparse_rb
- Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_R
- Racc_Runtime_Core_Revision = Racc_Runtime_Core_Revision_R
- Racc_Runtime_Type = 'ruby'
- end
-
- def Parser.racc_runtime_type # :nodoc:
- Racc_Runtime_Type
- end
-
- def _racc_setup
- @yydebug = false unless self.class::Racc_debug_parser
- @yydebug = false unless defined?(@yydebug)
- if @yydebug
- @racc_debug_out = $stderr unless defined?(@racc_debug_out)
- @racc_debug_out ||= $stderr
- end
- arg = self.class::Racc_arg
- arg[13] = true if arg.size < 14
- arg
- end
-
- def _racc_init_sysvars
- @racc_state = [0]
- @racc_tstack = []
- @racc_vstack = []
-
- @racc_t = nil
- @racc_val = nil
-
- @racc_read_next = true
-
- @racc_user_yyerror = false
- @racc_error_status = 0
- end
-
- # The entry point of the parser. This method is used with #next_token.
- # If Racc wants to get token (and its value), calls next_token.
- #
- # Example:
- # def parse
- # @q = [[1,1],
- # [2,2],
- # [3,3],
- # [false, '$']]
- # do_parse
- # end
- #
- # def next_token
- # @q.shift
- # end
- def do_parse
- __send__(Racc_Main_Parsing_Routine, _racc_setup(), false)
- end
-
- # The method to fetch next token.
- # If you use #do_parse method, you must implement #next_token.
- #
- # The format of return value is [TOKEN_SYMBOL, VALUE].
- # +token-symbol+ is represented by Ruby's symbol by default, e.g. :IDENT
- # for 'IDENT'. ";" (String) for ';'.
- #
- # The final symbol (End of file) must be false.
- def next_token
- raise NotImplementedError, "#{self.class}\#next_token is not defined"
- end
-
- def _racc_do_parse_rb(arg, in_debug)
- action_table, action_check, action_default, action_pointer,
- _, _, _, _,
- _, _, token_table, _,
- _, _, * = arg
-
- _racc_init_sysvars
- tok = act = i = nil
-
- catch(:racc_end_parse) {
- while true
- if i = action_pointer[@racc_state[-1]]
- if @racc_read_next
- if @racc_t != 0 # not EOF
- tok, @racc_val = next_token()
- unless tok # EOF
- @racc_t = 0
- else
- @racc_t = (token_table[tok] or 1) # error token
- end
- racc_read_token(@racc_t, tok, @racc_val) if @yydebug
- @racc_read_next = false
- end
- end
- i += @racc_t
- unless i >= 0 and
- act = action_table[i] and
- action_check[i] == @racc_state[-1]
- act = action_default[@racc_state[-1]]
- end
- else
- act = action_default[@racc_state[-1]]
- end
- while act = _racc_evalact(act, arg)
- ;
- end
- end
- }
- end
-
- # Another entry point for the parser.
- # If you use this method, you must implement RECEIVER#METHOD_ID method.
- #
- # RECEIVER#METHOD_ID is a method to get next token.
- # It must 'yield' the token, which format is [TOKEN-SYMBOL, VALUE].
- def yyparse(recv, mid)
- __send__(Racc_YY_Parse_Method, recv, mid, _racc_setup(), true)
- end
-
- def _racc_yyparse_rb(recv, mid, arg, c_debug)
- action_table, action_check, action_default, action_pointer,
- _, _, _, _,
- _, _, token_table, _,
- _, _, * = arg
-
- _racc_init_sysvars
- act = nil
- i = nil
-
- catch(:racc_end_parse) {
- until i = action_pointer[@racc_state[-1]]
- while act = _racc_evalact(action_default[@racc_state[-1]], arg)
- ;
- end
- end
- recv.__send__(mid) do |tok, val|
- unless tok
- @racc_t = 0
- else
- @racc_t = (token_table[tok] or 1) # error token
- end
- @racc_val = val
- @racc_read_next = false
-
- i += @racc_t
- unless i >= 0 and
- act = action_table[i] and
- action_check[i] == @racc_state[-1]
- act = action_default[@racc_state[-1]]
- end
- while act = _racc_evalact(act, arg)
- ;
- end
-
- while not(i = action_pointer[@racc_state[-1]]) or
- not @racc_read_next or
- @racc_t == 0 # $
- unless i and i += @racc_t and
- i >= 0 and
- act = action_table[i] and
- action_check[i] == @racc_state[-1]
- act = action_default[@racc_state[-1]]
- end
- while act = _racc_evalact(act, arg)
- ;
- end
- end
- end
- }
- end
-
- ###
- ### common
- ###
-
- def _racc_evalact(act, arg)
- action_table, action_check, _, action_pointer,
- _, _, _, _,
- _, _, _, shift_n, reduce_n,
- _, _, * = arg
-
- if act > 0 and act < shift_n
- #
- # shift
- #
- if @racc_error_status > 0
- @racc_error_status -= 1 unless @racc_t == 1 # error token
- end
- @racc_vstack.push @racc_val
- @racc_state.push act
- @racc_read_next = true
- if @yydebug
- @racc_tstack.push @racc_t
- racc_shift @racc_t, @racc_tstack, @racc_vstack
- end
-
- elsif act < 0 and act > -reduce_n
- #
- # reduce
- #
- code = catch(:racc_jump) {
- @racc_state.push _racc_do_reduce(arg, act)
- false
- }
- if code
- case code
- when 1 # yyerror
- @racc_user_yyerror = true # user_yyerror
- return -reduce_n
- when 2 # yyaccept
- return shift_n
- else
- raise '[Racc Bug] unknown jump code'
- end
- end
-
- elsif act == shift_n
- #
- # accept
- #
- racc_accept if @yydebug
- throw :racc_end_parse, @racc_vstack[0]
-
- elsif act == -reduce_n
- #
- # error
- #
- case @racc_error_status
- when 0
- unless arg[21] # user_yyerror
- on_error @racc_t, @racc_val, @racc_vstack
- end
- when 3
- if @racc_t == 0 # is $
- throw :racc_end_parse, nil
- end
- @racc_read_next = true
- end
- @racc_user_yyerror = false
- @racc_error_status = 3
- while true
- if i = action_pointer[@racc_state[-1]]
- i += 1 # error token
- if i >= 0 and
- (act = action_table[i]) and
- action_check[i] == @racc_state[-1]
- break
- end
- end
- throw :racc_end_parse, nil if @racc_state.size <= 1
- @racc_state.pop
- @racc_vstack.pop
- if @yydebug
- @racc_tstack.pop
- racc_e_pop @racc_state, @racc_tstack, @racc_vstack
- end
- end
- return act
-
- else
- raise "[Racc Bug] unknown action #{act.inspect}"
- end
-
- racc_next_state(@racc_state[-1], @racc_state) if @yydebug
-
- nil
- end
-
- def _racc_do_reduce(arg, act)
- _, _, _, _,
- goto_table, goto_check, goto_default, goto_pointer,
- nt_base, reduce_table, _, _,
- _, use_result, * = arg
- state = @racc_state
- vstack = @racc_vstack
- tstack = @racc_tstack
-
- i = act * -3
- len = reduce_table[i]
- reduce_to = reduce_table[i+1]
- method_id = reduce_table[i+2]
- void_array = []
-
- tmp_t = tstack[-len, len] if @yydebug
- tmp_v = vstack[-len, len]
- tstack[-len, len] = void_array if @yydebug
- vstack[-len, len] = void_array
- state[-len, len] = void_array
-
- # tstack must be updated AFTER method call
- if use_result
- vstack.push __send__(method_id, tmp_v, vstack, tmp_v[0])
- else
- vstack.push __send__(method_id, tmp_v, vstack)
- end
- tstack.push reduce_to
-
- racc_reduce(tmp_t, reduce_to, tstack, vstack) if @yydebug
-
- k1 = reduce_to - nt_base
- if i = goto_pointer[k1]
- i += state[-1]
- if i >= 0 and (curstate = goto_table[i]) and goto_check[i] == k1
- return curstate
- end
- end
- goto_default[k1]
- end
-
- # This method is called when a parse error is found.
- #
- # ERROR_TOKEN_ID is an internal ID of token which caused error.
- # You can get string representation of this ID by calling
- # #token_to_str.
- #
- # ERROR_VALUE is a value of error token.
- #
- # value_stack is a stack of symbol values.
- # DO NOT MODIFY this object.
- #
- # This method raises ParseError by default.
- #
- # If this method returns, parsers enter "error recovering mode".
- def on_error(t, val, vstack)
- raise ParseError, sprintf("\nparse error on value %s (%s)",
- val.inspect, token_to_str(t) || '?')
- end
-
- # Enter error recovering mode.
- # This method does not call #on_error.
- def yyerror
- throw :racc_jump, 1
- end
-
- # Exit parser.
- # Return value is Symbol_Value_Stack[0].
- def yyaccept
- throw :racc_jump, 2
- end
-
- # Leave error recovering mode.
- def yyerrok
- @racc_error_status = 0
- end
-
- # For debugging output
- def racc_read_token(t, tok, val)
- @racc_debug_out.print 'read '
- @racc_debug_out.print tok.inspect, '(', racc_token2str(t), ') '
- @racc_debug_out.puts val.inspect
- @racc_debug_out.puts
- end
-
- def racc_shift(tok, tstack, vstack)
- @racc_debug_out.puts "shift #{racc_token2str tok}"
- racc_print_stacks tstack, vstack
- @racc_debug_out.puts
- end
-
- def racc_reduce(toks, sim, tstack, vstack)
- out = @racc_debug_out
- out.print 'reduce '
- if toks.empty?
- out.print ' <none>'
- else
- toks.each {|t| out.print ' ', racc_token2str(t) }
- end
- out.puts " --> #{racc_token2str(sim)}"
-
- racc_print_stacks tstack, vstack
- @racc_debug_out.puts
- end
-
- def racc_accept
- @racc_debug_out.puts 'accept'
- @racc_debug_out.puts
- end
-
- def racc_e_pop(state, tstack, vstack)
- @racc_debug_out.puts 'error recovering mode: pop token'
- racc_print_states state
- racc_print_stacks tstack, vstack
- @racc_debug_out.puts
- end
-
- def racc_next_state(curstate, state)
- @racc_debug_out.puts "goto #{curstate}"
- racc_print_states state
- @racc_debug_out.puts
- end
-
- def racc_print_stacks(t, v)
- out = @racc_debug_out
- out.print ' ['
- t.each_index do |i|
- out.print ' (', racc_token2str(t[i]), ' ', v[i].inspect, ')'
- end
- out.puts ' ]'
- end
-
- def racc_print_states(s)
- out = @racc_debug_out
- out.print ' ['
- s.each {|st| out.print ' ', st }
- out.puts ' ]'
- end
-
- def racc_token2str(tok)
- self.class::Racc_token_to_s_table[tok] or
- raise "[Racc Bug] can't convert token #{tok} to string"
- end
-
- # Convert internal ID of token symbol to the string.
- def token_to_str(t)
- self.class::Racc_token_to_s_table[t]
- end
-
- end
-
-end
diff --git a/ruby_2_2/lib/racc/rdoc/grammar.en.rdoc b/ruby_2_2/lib/racc/rdoc/grammar.en.rdoc
deleted file mode 100644
index a154246ee5..0000000000
--- a/ruby_2_2/lib/racc/rdoc/grammar.en.rdoc
+++ /dev/null
@@ -1,219 +0,0 @@
-= Racc Grammar File Reference
-
-== Global Structure
-
-== Class Block and User Code Block
-
-There are two blocks on toplevel. One is 'class' block, another is 'user code'
-block. 'user code' block MUST be placed after 'class' block.
-
-== Comments
-
-You can insert comments about all places. Two style comments can be used, Ruby style '#.....' and C style '/\*......*\/'.
-
-== Class Block
-
-The class block is formed like this:
-
- class CLASS_NAME
- [precedance table]
- [token declarations]
- [expected number of S/R conflicts]
- [options]
- [semantic value convertion]
- [start rule]
- rule
- GRAMMARS
-
-CLASS_NAME is a name of parser class. This is the name of generating parser
-class.
-
-If CLASS_NAME includes '::', Racc outputs module clause. For example, writing
-"class M::C" causes creating the code bellow:
-
- module M
- class C
- :
- :
- end
- end
-
-== Grammar Block
-
-The grammar block describes grammar which is able to be understood by parser.
-Syntax is:
-
- (token): (token) (token) (token).... (action)
-
- (token): (token) (token) (token).... (action)
- | (token) (token) (token).... (action)
- | (token) (token) (token).... (action)
-
-(action) is an action which is executed when its (token)s are found.
-(action) is a ruby code block, which is surrounded by braces:
-
- { print val[0]
- puts val[1] }
-
-Note that you cannot use '%' string, here document, '%r' regexp in action.
-
-Actions can be omitted. When it is omitted, '' (empty string) is used.
-
-A return value of action is a value of left side value ($$). It is value of
-result, or returned value by `return` statement.
-
-Here is an example of whole grammar block.
-
- rule
- goal: definition rules source { result = val }
-
- definition: /* none */ { result = [] }
- | definition startdesig { result[0] = val[1] }
- | definition
- precrule # this line continues from upper line
- {
- result[1] = val[1]
- }
-
- startdesig: START TOKEN
-
-You can use the following special local variables in action:
-
-* result ($$)
-
-The value of left-hand side (lhs). A default value is val[0].
-
-* val ($1,$2,$3...)
-
-An array of value of right-hand side (rhs).
-
-* _values (...$-2,$-1,$0)
-
-A stack of values. DO NOT MODIFY this stack unless you know what you are doing.
-
-== Operator Precedence
-
-This function is equal to '%prec' in yacc.
-To designate this block:
-
- prechigh
- nonassoc '++'
- left '*' '/'
- left '+' '-'
- right '='
- preclow
-
-`right` is yacc's %right, `left` is yacc's %left.
-
-`=` + (symbol) means yacc's %prec:
-
- prechigh
- nonassoc UMINUS
- left '*' '/'
- left '+' '-'
- preclow
-
- rule
- exp: exp '*' exp
- | exp '-' exp
- | '-' exp =UMINUS # equals to "%prec UMINUS"
- :
- :
-
-== expect
-
-Racc has bison's "expect" directive.
-
- # Example
-
- class MyParser
- rule
- expect 3
- :
- :
-
-This directive declares "expected" number of shift/reduce conflicts. If
-"expected" number is equal to real number of conflicts, Racc does not print
-conflict warning message.
-
-== Declaring Tokens
-
-By declaring tokens, you can avoid many meaningless bugs. If declared token
-does not exist or existing token does not decleared, Racc output warnings.
-Declaration syntax is:
-
- token TOKEN_NAME AND_IS_THIS
- ALSO_THIS_IS AGAIN_AND_AGAIN THIS_IS_LAST
-
-== Options
-
-You can write options for Racc command in your Racc file.
-
- options OPTION OPTION ...
-
-Options are:
-
-* omit_action_call
-
-omits empty action call or not.
-
-* result_var
-
-uses local variable "result" or not.
-
-You can use 'no_' prefix to invert their meanings.
-
-== Converting Token Symbol
-
-Token symbols are, as default,
-
- * naked token string in Racc file (TOK, XFILE, this_is_token, ...)
- --> symbol (:TOK, :XFILE, :this_is_token, ...)
- * quoted string (':', '.', '(', ...)
- --> same string (':', '.', '(', ...)
-
-You can change this default by "convert" block.
-Here is an example:
-
- convert
- PLUS 'PlusClass' # We use PlusClass for symbol of `PLUS'
- MIN 'MinusClass' # We use MinusClass for symbol of `MIN'
- end
-
-We can use almost all ruby value can be used by token symbol,
-except 'false' and 'nil'. These cause unexpected parse error.
-
-If you want to use String as token symbol, special care is required.
-For example:
-
- convert
- class '"cls"' # in code, "cls"
- PLUS '"plus\n"' # in code, "plus\n"
- MIN "\"minus#{val}\"" # in code, \"minus#{val}\"
- end
-
-== Start Rule
-
-'%start' in yacc. This changes start rule.
-
- start real_target
-
-== User Code Block
-
-"User Code Block" is a Ruby source code which is copied to output. There are
-three user code blocks, "header" "inner" and "footer".
-
-Format of user code is like this:
-
- ---- header
- ruby statement
- ruby statement
- ruby statement
-
- ---- inner
- ruby statement
- :
- :
-
-If four '-' exist on line head, Racc treat it as beginning of user code block.
-The name of user code block must be one word.
diff --git a/ruby_2_2/lib/rake.rb b/ruby_2_2/lib/rake.rb
deleted file mode 100644
index 7366862ad0..0000000000
--- a/ruby_2_2/lib/rake.rb
+++ /dev/null
@@ -1,79 +0,0 @@
-#--
-# Copyright 2003-2010 by Jim Weirich (jim.weirich@gmail.com)
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to
-# deal in the Software without restriction, including without limitation the
-# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-# sell copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-# IN THE SOFTWARE.
-#++
-
-module Rake
- VERSION = '10.4.2'
-end
-
-require 'rake/version'
-
-# :stopdoc:
-# TODO: Remove in Rake 11
-RAKEVERSION = Rake::VERSION
-# :startdoc:
-
-require 'rbconfig'
-require 'fileutils'
-require 'singleton'
-require 'monitor'
-require 'optparse'
-require 'ostruct'
-
-require 'rake/ext/module'
-require 'rake/ext/string'
-require 'rake/ext/time'
-
-require 'rake/win32'
-
-require 'rake/linked_list'
-require 'rake/cpu_counter'
-require 'rake/scope'
-require 'rake/task_argument_error'
-require 'rake/rule_recursion_overflow_error'
-require 'rake/rake_module'
-require 'rake/trace_output'
-require 'rake/pseudo_status'
-require 'rake/task_arguments'
-require 'rake/invocation_chain'
-require 'rake/task'
-require 'rake/file_task'
-require 'rake/file_creation_task'
-require 'rake/multi_task'
-require 'rake/dsl_definition'
-require 'rake/file_utils_ext'
-require 'rake/file_list'
-require 'rake/default_loader'
-require 'rake/early_time'
-require 'rake/late_time'
-require 'rake/name_space'
-require 'rake/task_manager'
-require 'rake/application'
-require 'rake/backtrace'
-
-$trace = false
-
-# :stopdoc:
-#
-# Some top level Constants.
-
-FileList = Rake::FileList
-RakeFileUtils = Rake::FileUtilsExt
diff --git a/ruby_2_2/lib/rake/alt_system.rb b/ruby_2_2/lib/rake/alt_system.rb
deleted file mode 100644
index aa7b7791b6..0000000000
--- a/ruby_2_2/lib/rake/alt_system.rb
+++ /dev/null
@@ -1,110 +0,0 @@
-#
-# Copyright (c) 2008 James M. Lawrence
-#
-# Permission is hereby granted, free of charge, to any person
-# obtaining a copy of this software and associated documentation files
-# (the "Software"), to deal in the Software without restriction,
-# including without limitation the rights to use, copy, modify, merge,
-# publish, distribute, sublicense, and/or sell copies of the Software,
-# and to permit persons to whom the Software is furnished to do so,
-# subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be
-# included in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
-# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
-# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
-#
-
-require 'rbconfig'
-
-##
-# Alternate implementations of system() and backticks `` on Windows
-# for ruby-1.8 and earlier.
-#--
-# TODO: Remove in Rake 11
-
-module Rake::AltSystem # :nodoc: all
- WINDOWS = RbConfig::CONFIG["host_os"] =~
- %r!(msdos|mswin|djgpp|mingw|[Ww]indows)!
-
- class << self
- def define_module_function(name, &block)
- define_method(name, &block)
- module_function(name)
- end
- end
-
- if WINDOWS && RUBY_VERSION < "1.9.0"
- RUNNABLE_EXTS = %w[com exe bat cmd]
- RUNNABLE_PATTERN = %r!\.(#{RUNNABLE_EXTS.join('|')})\Z!i
-
- define_module_function :kernel_system, &Kernel.method(:system)
- define_module_function :kernel_backticks, &Kernel.method(:'`')
-
- module_function
-
- def repair_command(cmd)
- "call " + (
- if cmd =~ %r!\A\s*\".*?\"!
- # already quoted
- cmd
- elsif match = cmd.match(%r!\A\s*(\S+)!)
- if match[1] =~ %r!/!
- # avoid x/y.bat interpretation as x with option /y
- %Q!"#{match[1]}"! + match.post_match
- else
- # a shell command will fail if quoted
- cmd
- end
- else
- # empty or whitespace
- cmd
- end
- )
- end
-
- def find_runnable(file)
- if file =~ RUNNABLE_PATTERN
- file
- else
- RUNNABLE_EXTS.each { |ext|
- test = "#{file}.#{ext}"
- return test if File.exist?(test)
- }
- nil
- end
- end
-
- def system(cmd, *args)
- repaired = (
- if args.empty?
- [repair_command(cmd)]
- elsif runnable = find_runnable(cmd)
- [File.expand_path(runnable), *args]
- else
- # non-existent file
- [cmd, *args]
- end
- )
- kernel_system(*repaired)
- end
-
- def backticks(cmd)
- kernel_backticks(repair_command(cmd))
- end
-
- define_module_function :'`', &method(:backticks)
- else
- # Non-Windows or ruby-1.9+: same as Kernel versions
- define_module_function :system, &Kernel.method(:system)
- define_module_function :backticks, &Kernel.method(:'`')
- define_module_function :'`', &Kernel.method(:'`')
- end
-end
diff --git a/ruby_2_2/lib/rake/application.rb b/ruby_2_2/lib/rake/application.rb
deleted file mode 100644
index bd72a2efae..0000000000
--- a/ruby_2_2/lib/rake/application.rb
+++ /dev/null
@@ -1,790 +0,0 @@
-require 'shellwords'
-require 'optparse'
-
-require 'rake/task_manager'
-require 'rake/file_list'
-require 'rake/thread_pool'
-require 'rake/thread_history_display'
-require 'rake/trace_output'
-require 'rake/win32'
-
-module Rake
-
- CommandLineOptionError = Class.new(StandardError)
-
- ##
- # Rake main application object. When invoking +rake+ from the
- # command line, a Rake::Application object is created and run.
-
- class Application
- include TaskManager
- include TraceOutput
-
- # The name of the application (typically 'rake')
- attr_reader :name
-
- # The original directory where rake was invoked.
- attr_reader :original_dir
-
- # Name of the actual rakefile used.
- attr_reader :rakefile
-
- # Number of columns on the terminal
- attr_accessor :terminal_columns
-
- # List of the top level task names (task names from the command line).
- attr_reader :top_level_tasks
-
- DEFAULT_RAKEFILES = [
- 'rakefile',
- 'Rakefile',
- 'rakefile.rb',
- 'Rakefile.rb'
- ].freeze
-
- # Initialize a Rake::Application object.
- def initialize
- super
- @name = 'rake'
- @rakefiles = DEFAULT_RAKEFILES.dup
- @rakefile = nil
- @pending_imports = []
- @imported = []
- @loaders = {}
- @default_loader = Rake::DefaultLoader.new
- @original_dir = Dir.pwd
- @top_level_tasks = []
- add_loader('rb', DefaultLoader.new)
- add_loader('rf', DefaultLoader.new)
- add_loader('rake', DefaultLoader.new)
- @tty_output = STDOUT.tty?
- @terminal_columns = ENV['RAKE_COLUMNS'].to_i
- end
-
- # Run the Rake application. The run method performs the following
- # three steps:
- #
- # * Initialize the command line options (+init+).
- # * Define the tasks (+load_rakefile+).
- # * Run the top level tasks (+top_level+).
- #
- # If you wish to build a custom rake command, you should call
- # +init+ on your application. Then define any tasks. Finally,
- # call +top_level+ to run your top level tasks.
- def run
- standard_exception_handling do
- init
- load_rakefile
- top_level
- end
- end
-
- # Initialize the command line parameters and app name.
- def init(app_name='rake')
- standard_exception_handling do
- @name = app_name
- args = handle_options
- collect_command_line_tasks(args)
- end
- end
-
- # Find the rakefile and then load it and any pending imports.
- def load_rakefile
- standard_exception_handling do
- raw_load_rakefile
- end
- end
-
- # Run the top level tasks of a Rake application.
- def top_level
- run_with_threads do
- if options.show_tasks
- display_tasks_and_comments
- elsif options.show_prereqs
- display_prerequisites
- else
- top_level_tasks.each { |task_name| invoke_task(task_name) }
- end
- end
- end
-
- # Run the given block with the thread startup and shutdown.
- def run_with_threads
- thread_pool.gather_history if options.job_stats == :history
-
- yield
-
- thread_pool.join
- if options.job_stats
- stats = thread_pool.statistics
- puts "Maximum active threads: #{stats[:max_active_threads]} + main"
- puts "Total threads in play: #{stats[:total_threads_in_play]} + main"
- end
- ThreadHistoryDisplay.new(thread_pool.history).show if
- options.job_stats == :history
- end
-
- # Add a loader to handle imported files ending in the extension
- # +ext+.
- def add_loader(ext, loader)
- ext = ".#{ext}" unless ext =~ /^\./
- @loaders[ext] = loader
- end
-
- # Application options from the command line
- def options
- @options ||= OpenStruct.new
- end
-
- # Return the thread pool used for multithreaded processing.
- def thread_pool # :nodoc:
- @thread_pool ||= ThreadPool.new(options.thread_pool_size || Rake.suggested_thread_count-1)
- end
-
- # internal ----------------------------------------------------------------
-
- # Invokes a task with arguments that are extracted from +task_string+
- def invoke_task(task_string) # :nodoc:
- name, args = parse_task_string(task_string)
- t = self[name]
- t.invoke(*args)
- end
-
- def parse_task_string(string) # :nodoc:
- /^([^\[]+)(?:\[(.*)\])$/ =~ string.to_s
-
- name = $1
- remaining_args = $2
-
- return string, [] unless name
- return name, [] if remaining_args.empty?
-
- args = []
-
- begin
- /((?:[^\\,]|\\.)*?)\s*(?:,\s*(.*))?$/ =~ remaining_args
-
- remaining_args = $2
- args << $1.gsub(/\\(.)/, '\1')
- end while remaining_args
-
- return name, args
- end
-
- # Provide standard exception handling for the given block.
- def standard_exception_handling # :nodoc:
- yield
- rescue SystemExit
- # Exit silently with current status
- raise
- rescue OptionParser::InvalidOption => ex
- $stderr.puts ex.message
- exit(false)
- rescue Exception => ex
- # Exit with error message
- display_error_message(ex)
- exit_because_of_exception(ex)
- end
-
- # Exit the program because of an unhandle exception.
- # (may be overridden by subclasses)
- def exit_because_of_exception(ex) # :nodoc:
- exit(false)
- end
-
- # Display the error message that caused the exception.
- def display_error_message(ex) # :nodoc:
- trace "#{name} aborted!"
- display_exception_details(ex)
- trace "Tasks: #{ex.chain}" if has_chain?(ex)
- trace "(See full trace by running task with --trace)" unless
- options.backtrace
- end
-
- def display_exception_details(ex) # :nodoc:
- seen = Thread.current[:rake_display_exception_details_seen] ||= []
- return if seen.include? ex
- seen << ex
-
- display_exception_message_details(ex)
- display_exception_backtrace(ex)
- display_exception_details(ex.cause) if has_cause?(ex)
- end
-
- def has_cause?(ex) # :nodoc:
- ex.respond_to?(:cause) && ex.cause
- end
-
- def display_exception_message_details(ex) # :nodoc:
- if ex.instance_of?(RuntimeError)
- trace ex.message
- else
- trace "#{ex.class.name}: #{ex.message}"
- end
- end
-
- def display_exception_backtrace(ex) # :nodoc:
- if options.backtrace
- trace ex.backtrace.join("\n")
- else
- trace Backtrace.collapse(ex.backtrace).join("\n")
- end
- end
-
- # Warn about deprecated usage.
- #
- # Example:
- # Rake.application.deprecate("import", "Rake.import", caller.first)
- #
- def deprecate(old_usage, new_usage, call_site) # :nodoc:
- unless options.ignore_deprecate
- $stderr.puts "WARNING: '#{old_usage}' is deprecated. " +
- "Please use '#{new_usage}' instead.\n" +
- " at #{call_site}"
- end
- end
-
- # Does the exception have a task invocation chain?
- def has_chain?(exception) # :nodoc:
- exception.respond_to?(:chain) && exception.chain
- end
- private :has_chain?
-
- # True if one of the files in RAKEFILES is in the current directory.
- # If a match is found, it is copied into @rakefile.
- def have_rakefile # :nodoc:
- @rakefiles.each do |fn|
- if File.exist?(fn)
- others = FileList.glob(fn, File::FNM_CASEFOLD)
- return others.size == 1 ? others.first : fn
- elsif fn == ''
- return fn
- end
- end
- return nil
- end
-
- # True if we are outputting to TTY, false otherwise
- def tty_output? # :nodoc:
- @tty_output
- end
-
- # Override the detected TTY output state (mostly for testing)
- def tty_output=(tty_output_state) # :nodoc:
- @tty_output = tty_output_state
- end
-
- # We will truncate output if we are outputting to a TTY or if we've been
- # given an explicit column width to honor
- def truncate_output? # :nodoc:
- tty_output? || @terminal_columns.nonzero?
- end
-
- # Display the tasks and comments.
- def display_tasks_and_comments # :nodoc:
- displayable_tasks = tasks.select { |t|
- (options.show_all_tasks || t.comment) &&
- t.name =~ options.show_task_pattern
- }
- case options.show_tasks
- when :tasks
- width = displayable_tasks.map { |t| t.name_with_args.length }.max || 10
- if truncate_output?
- max_column = terminal_width - name.size - width - 7
- else
- max_column = nil
- end
-
- displayable_tasks.each do |t|
- printf("#{name} %-#{width}s # %s\n",
- t.name_with_args,
- max_column ? truncate(t.comment, max_column) : t.comment)
- end
- when :describe
- displayable_tasks.each do |t|
- puts "#{name} #{t.name_with_args}"
- comment = t.full_comment || ""
- comment.split("\n").each do |line|
- puts " #{line}"
- end
- puts
- end
- when :lines
- displayable_tasks.each do |t|
- t.locations.each do |loc|
- printf "#{name} %-30s %s\n", t.name_with_args, loc
- end
- end
- else
- fail "Unknown show task mode: '#{options.show_tasks}'"
- end
- end
-
- def terminal_width # :nodoc:
- if @terminal_columns.nonzero?
- result = @terminal_columns
- else
- result = unix? ? dynamic_width : 80
- end
- (result < 10) ? 80 : result
- rescue
- 80
- end
-
- # Calculate the dynamic width of the
- def dynamic_width # :nodoc:
- @dynamic_width ||= (dynamic_width_stty.nonzero? || dynamic_width_tput)
- end
-
- def dynamic_width_stty # :nodoc:
- %x{stty size 2>/dev/null}.split[1].to_i
- end
-
- def dynamic_width_tput # :nodoc:
- %x{tput cols 2>/dev/null}.to_i
- end
-
- def unix? # :nodoc:
- RbConfig::CONFIG['host_os'] =~
- /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
- end
-
- def windows? # :nodoc:
- Win32.windows?
- end
-
- def truncate(string, width) # :nodoc:
- if string.nil?
- ""
- elsif string.length <= width
- string
- else
- (string[0, width - 3] || "") + "..."
- end
- end
-
- # Display the tasks and prerequisites
- def display_prerequisites # :nodoc:
- tasks.each do |t|
- puts "#{name} #{t.name}"
- t.prerequisites.each { |pre| puts " #{pre}" }
- end
- end
-
- def trace(*strings) # :nodoc:
- options.trace_output ||= $stderr
- trace_on(options.trace_output, *strings)
- end
-
- def sort_options(options) # :nodoc:
- options.sort_by { |opt|
- opt.select { |o| o =~ /^-/ }.map { |o| o.downcase }.sort.reverse
- }
- end
- private :sort_options
-
- # A list of all the standard options used in rake, suitable for
- # passing to OptionParser.
- def standard_rake_options # :nodoc:
- sort_options(
- [
- ['--all', '-A',
- "Show all tasks, even uncommented ones (in combination with -T or -D)",
- lambda { |value|
- options.show_all_tasks = value
- }
- ],
- ['--backtrace=[OUT]',
- "Enable full backtrace. OUT can be stderr (default) or stdout.",
- lambda { |value|
- options.backtrace = true
- select_trace_output(options, 'backtrace', value)
- }
- ],
- ['--build-all', '-B',
- "Build all prerequisites, including those which are up-to-date.",
- lambda { |value|
- options.build_all = true
- }
- ],
- ['--comments',
- "Show commented tasks only",
- lambda { |value|
- options.show_all_tasks = !value
- }
- ],
- ['--describe', '-D [PATTERN]',
- "Describe the tasks (matching optional PATTERN), then exit.",
- lambda { |value|
- select_tasks_to_show(options, :describe, value)
- }
- ],
- ['--dry-run', '-n',
- "Do a dry run without executing actions.",
- lambda { |value|
- Rake.verbose(true)
- Rake.nowrite(true)
- options.dryrun = true
- options.trace = true
- }
- ],
- ['--execute', '-e CODE',
- "Execute some Ruby code and exit.",
- lambda { |value|
- eval(value)
- exit
- }
- ],
- ['--execute-print', '-p CODE',
- "Execute some Ruby code, print the result, then exit.",
- lambda { |value|
- puts eval(value)
- exit
- }
- ],
- ['--execute-continue', '-E CODE',
- "Execute some Ruby code, " +
- "then continue with normal task processing.",
- lambda { |value| eval(value) }
- ],
- ['--jobs', '-j [NUMBER]',
- "Specifies the maximum number of tasks to execute in parallel. " +
- "(default is number of CPU cores + 4)",
- lambda { |value|
- if value.nil? || value == ''
- value = FIXNUM_MAX
- elsif value =~ /^\d+$/
- value = value.to_i
- else
- value = Rake.suggested_thread_count
- end
- value = 1 if value < 1
- options.thread_pool_size = value - 1
- }
- ],
- ['--job-stats [LEVEL]',
- "Display job statistics. " +
- "LEVEL=history displays a complete job list",
- lambda { |value|
- if value =~ /^history/i
- options.job_stats = :history
- else
- options.job_stats = true
- end
- }
- ],
- ['--libdir', '-I LIBDIR',
- "Include LIBDIR in the search path for required modules.",
- lambda { |value| $:.push(value) }
- ],
- ['--multitask', '-m',
- "Treat all tasks as multitasks.",
- lambda { |value| options.always_multitask = true }
- ],
- ['--no-search', '--nosearch',
- '-N', "Do not search parent directories for the Rakefile.",
- lambda { |value| options.nosearch = true }
- ],
- ['--prereqs', '-P',
- "Display the tasks and dependencies, then exit.",
- lambda { |value| options.show_prereqs = true }
- ],
- ['--quiet', '-q',
- "Do not log messages to standard output.",
- lambda { |value| Rake.verbose(false) }
- ],
- ['--rakefile', '-f [FILENAME]',
- "Use FILENAME as the rakefile to search for.",
- lambda { |value|
- value ||= ''
- @rakefiles.clear
- @rakefiles << value
- }
- ],
- ['--rakelibdir', '--rakelib', '-R RAKELIBDIR',
- "Auto-import any .rake files in RAKELIBDIR. " +
- "(default is 'rakelib')",
- lambda { |value|
- options.rakelib = value.split(File::PATH_SEPARATOR)
- }
- ],
- ['--require', '-r MODULE',
- "Require MODULE before executing rakefile.",
- lambda { |value|
- begin
- require value
- rescue LoadError => ex
- begin
- rake_require value
- rescue LoadError
- raise ex
- end
- end
- }
- ],
- ['--rules',
- "Trace the rules resolution.",
- lambda { |value| options.trace_rules = true }
- ],
- ['--silent', '-s',
- "Like --quiet, but also suppresses the " +
- "'in directory' announcement.",
- lambda { |value|
- Rake.verbose(false)
- options.silent = true
- }
- ],
- ['--suppress-backtrace PATTERN',
- "Suppress backtrace lines matching regexp PATTERN. " +
- "Ignored if --trace is on.",
- lambda { |value|
- options.suppress_backtrace_pattern = Regexp.new(value)
- }
- ],
- ['--system', '-g',
- "Using system wide (global) rakefiles " +
- "(usually '~/.rake/*.rake').",
- lambda { |value| options.load_system = true }
- ],
- ['--no-system', '--nosystem', '-G',
- "Use standard project Rakefile search paths, " +
- "ignore system wide rakefiles.",
- lambda { |value| options.ignore_system = true }
- ],
- ['--tasks', '-T [PATTERN]',
- "Display the tasks (matching optional PATTERN) " +
- "with descriptions, then exit.",
- lambda { |value|
- select_tasks_to_show(options, :tasks, value)
- }
- ],
- ['--trace=[OUT]', '-t',
- "Turn on invoke/execute tracing, enable full backtrace. " +
- "OUT can be stderr (default) or stdout.",
- lambda { |value|
- options.trace = true
- options.backtrace = true
- select_trace_output(options, 'trace', value)
- Rake.verbose(true)
- }
- ],
- ['--verbose', '-v',
- "Log message to standard output.",
- lambda { |value| Rake.verbose(true) }
- ],
- ['--version', '-V',
- "Display the program version.",
- lambda { |value|
- puts "rake, version #{RAKEVERSION}"
- exit
- }
- ],
- ['--where', '-W [PATTERN]',
- "Describe the tasks (matching optional PATTERN), then exit.",
- lambda { |value|
- select_tasks_to_show(options, :lines, value)
- options.show_all_tasks = true
- }
- ],
- ['--no-deprecation-warnings', '-X',
- "Disable the deprecation warnings.",
- lambda { |value|
- options.ignore_deprecate = true
- }
- ],
- ])
- end
-
- def select_tasks_to_show(options, show_tasks, value) # :nodoc:
- options.show_tasks = show_tasks
- options.show_task_pattern = Regexp.new(value || '')
- Rake::TaskManager.record_task_metadata = true
- end
- private :select_tasks_to_show
-
- def select_trace_output(options, trace_option, value) # :nodoc:
- value = value.strip unless value.nil?
- case value
- when 'stdout'
- options.trace_output = $stdout
- when 'stderr', nil
- options.trace_output = $stderr
- else
- fail CommandLineOptionError,
- "Unrecognized --#{trace_option} option '#{value}'"
- end
- end
- private :select_trace_output
-
- # Read and handle the command line options. Returns the command line
- # arguments that we didn't understand, which should (in theory) be just
- # task names and env vars.
- def handle_options # :nodoc:
- options.rakelib = ['rakelib']
- options.trace_output = $stderr
-
- OptionParser.new do |opts|
- opts.banner = "#{Rake.application.name} [-f rakefile] {options} targets..."
- opts.separator ""
- opts.separator "Options are ..."
-
- opts.on_tail("-h", "--help", "-H", "Display this help message.") do
- puts opts
- exit
- end
-
- standard_rake_options.each { |args| opts.on(*args) }
- opts.environment('RAKEOPT')
- end.parse(ARGV)
- end
-
- # Similar to the regular Ruby +require+ command, but will check
- # for *.rake files in addition to *.rb files.
- def rake_require(file_name, paths=$LOAD_PATH, loaded=$") # :nodoc:
- fn = file_name + ".rake"
- return false if loaded.include?(fn)
- paths.each do |path|
- full_path = File.join(path, fn)
- if File.exist?(full_path)
- Rake.load_rakefile(full_path)
- loaded << fn
- return true
- end
- end
- fail LoadError, "Can't find #{file_name}"
- end
-
- def find_rakefile_location # :nodoc:
- here = Dir.pwd
- until (fn = have_rakefile)
- Dir.chdir("..")
- return nil if Dir.pwd == here || options.nosearch
- here = Dir.pwd
- end
- [fn, here]
- ensure
- Dir.chdir(Rake.original_dir)
- end
-
- def print_rakefile_directory(location) # :nodoc:
- $stderr.puts "(in #{Dir.pwd})" unless
- options.silent or original_dir == location
- end
-
- def raw_load_rakefile # :nodoc:
- rakefile, location = find_rakefile_location
- if (! options.ignore_system) &&
- (options.load_system || rakefile.nil?) &&
- system_dir && File.directory?(system_dir)
- print_rakefile_directory(location)
- glob("#{system_dir}/*.rake") do |name|
- add_import name
- end
- else
- fail "No Rakefile found (looking for: #{@rakefiles.join(', ')})" if
- rakefile.nil?
- @rakefile = rakefile
- Dir.chdir(location)
- print_rakefile_directory(location)
- Rake.load_rakefile(File.expand_path(@rakefile)) if
- @rakefile && @rakefile != ''
- options.rakelib.each do |rlib|
- glob("#{rlib}/*.rake") do |name|
- add_import name
- end
- end
- end
- load_imports
- end
-
- def glob(path, &block) # :nodoc:
- FileList.glob(path.gsub("\\", '/')).each(&block)
- end
- private :glob
-
- # The directory path containing the system wide rakefiles.
- def system_dir # :nodoc:
- @system_dir ||=
- begin
- if ENV['RAKE_SYSTEM']
- ENV['RAKE_SYSTEM']
- else
- standard_system_dir
- end
- end
- end
-
- # The standard directory containing system wide rake files.
- if Win32.windows?
- def standard_system_dir #:nodoc:
- Win32.win32_system_dir
- end
- else
- def standard_system_dir #:nodoc:
- File.join(File.expand_path('~'), '.rake')
- end
- end
- private :standard_system_dir
-
- # Collect the list of tasks on the command line. If no tasks are
- # given, return a list containing only the default task.
- # Environmental assignments are processed at this time as well.
- #
- # `args` is the list of arguments to peruse to get the list of tasks.
- # It should be the command line that was given to rake, less any
- # recognised command-line options, which OptionParser.parse will
- # have taken care of already.
- def collect_command_line_tasks(args) # :nodoc:
- @top_level_tasks = []
- args.each do |arg|
- if arg =~ /^(\w+)=(.*)$/m
- ENV[$1] = $2
- else
- @top_level_tasks << arg unless arg =~ /^-/
- end
- end
- @top_level_tasks.push(default_task_name) if @top_level_tasks.empty?
- end
-
- # Default task name ("default").
- # (May be overridden by subclasses)
- def default_task_name # :nodoc:
- "default"
- end
-
- # Add a file to the list of files to be imported.
- def add_import(fn) # :nodoc:
- @pending_imports << fn
- end
-
- # Load the pending list of imported files.
- def load_imports # :nodoc:
- while fn = @pending_imports.shift
- next if @imported.member?(fn)
- fn_task = lookup(fn) and fn_task.invoke
- ext = File.extname(fn)
- loader = @loaders[ext] || @default_loader
- loader.load(fn)
- if fn_task = lookup(fn) and fn_task.needed?
- fn_task.reenable
- fn_task.invoke
- loader.load(fn)
- end
- @imported << fn
- end
- end
-
- def rakefile_location(backtrace=caller) # :nodoc:
- backtrace.map { |t| t[/([^:]+):/, 1] }
-
- re = /^#{@rakefile}$/
- re = /#{re.source}/i if windows?
-
- backtrace.find { |str| str =~ re } || ''
- end
-
- private
- FIXNUM_MAX = (2**(0.size * 8 - 2) - 1) # :nodoc:
-
- end
-end
diff --git a/ruby_2_2/lib/rake/backtrace.rb b/ruby_2_2/lib/rake/backtrace.rb
deleted file mode 100644
index dc18773436..0000000000
--- a/ruby_2_2/lib/rake/backtrace.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-module Rake
- module Backtrace # :nodoc: all
- SYS_KEYS = RbConfig::CONFIG.keys.grep(/(?:[a-z]prefix|libdir)\z/)
- SYS_PATHS = RbConfig::CONFIG.values_at(*SYS_KEYS).uniq +
- [ File.join(File.dirname(__FILE__), "..") ]
-
- SUPPRESSED_PATHS = SYS_PATHS.
- map { |s| s.gsub("\\", "/") }.
- map { |f| File.expand_path(f) }.
- reject { |s| s.nil? || s =~ /^ *$/ }
- SUPPRESSED_PATHS_RE = SUPPRESSED_PATHS.map { |f| Regexp.quote(f) }.join("|")
- SUPPRESSED_PATHS_RE << "|^org\\/jruby\\/\\w+\\.java" if
- Object.const_defined?(:RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
-
- SUPPRESS_PATTERN = %r!(\A(#{SUPPRESSED_PATHS_RE})|bin/rake:\d+)!i
-
- def self.collapse(backtrace)
- pattern = Rake.application.options.suppress_backtrace_pattern ||
- SUPPRESS_PATTERN
- backtrace.reject { |elem| elem =~ pattern }
- end
- end
-end
diff --git a/ruby_2_2/lib/rake/clean.rb b/ruby_2_2/lib/rake/clean.rb
deleted file mode 100644
index a49cd44167..0000000000
--- a/ruby_2_2/lib/rake/clean.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-# The 'rake/clean' file defines two file lists (CLEAN and CLOBBER) and
-# two rake tasks (:clean and :clobber).
-#
-# [:clean] Clean up the project by deleting scratch files and backup
-# files. Add files to the CLEAN file list to have the :clean
-# target handle them.
-#
-# [:clobber] Clobber all generated and non-source files in a project.
-# The task depends on :clean, so all the clean files will
-# be deleted as well as files in the CLOBBER file list.
-# The intent of this task is to return a project to its
-# pristine, just unpacked state.
-
-require 'rake'
-
-# :stopdoc:
-
-module Rake
- module Cleaner
- extend FileUtils
-
- module_function
-
- def cleanup_files(file_names)
- file_names.each do |file_name|
- cleanup(file_name)
- end
- end
-
- def cleanup(file_name, opts={})
- begin
- rm_r file_name, opts
- rescue StandardError => ex
- puts "Failed to remove #{file_name}: #{ex}" unless file_already_gone?(file_name)
- end
- end
-
- def file_already_gone?(file_name)
- return false if File.exist?(file_name)
-
- path = file_name
- prev = nil
-
- while path = File.dirname(path)
- return false if cant_be_deleted?(path)
- break if [prev, "."].include?(path)
- prev = path
- end
- true
- end
- private_class_method :file_already_gone?
-
- def cant_be_deleted?(path_name)
- File.exist?(path_name) &&
- (!File.readable?(path_name) || !File.executable?(path_name))
- end
- private_class_method :cant_be_deleted?
- end
-end
-
-CLEAN = ::Rake::FileList["**/*~", "**/*.bak", "**/core"]
-CLEAN.clear_exclude.exclude { |fn|
- fn.pathmap("%f").downcase == 'core' && File.directory?(fn)
-}
-
-desc "Remove any temporary products."
-task :clean do
- Rake::Cleaner.cleanup_files(CLEAN)
-end
-
-CLOBBER = ::Rake::FileList.new
-
-desc "Remove any generated file."
-task :clobber => [:clean] do
- Rake::Cleaner.cleanup_files(CLOBBER)
-end
diff --git a/ruby_2_2/lib/rake/cloneable.rb b/ruby_2_2/lib/rake/cloneable.rb
deleted file mode 100644
index d53645f2f3..0000000000
--- a/ruby_2_2/lib/rake/cloneable.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-module Rake
- ##
- # Mixin for creating easily cloned objects.
-
- module Cloneable # :nodoc:
- # The hook that is invoked by 'clone' and 'dup' methods.
- def initialize_copy(source)
- super
- source.instance_variables.each do |var|
- src_value = source.instance_variable_get(var)
- value = src_value.clone rescue src_value
- instance_variable_set(var, value)
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rake/contrib/.document b/ruby_2_2/lib/rake/contrib/.document
deleted file mode 100644
index 8b13789179..0000000000
--- a/ruby_2_2/lib/rake/contrib/.document
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/ruby_2_2/lib/rake/contrib/compositepublisher.rb b/ruby_2_2/lib/rake/contrib/compositepublisher.rb
deleted file mode 100644
index 69952a0808..0000000000
--- a/ruby_2_2/lib/rake/contrib/compositepublisher.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-module Rake
-
- # Manage several publishers as a single entity.
- class CompositePublisher
- def initialize
- @publishers = []
- end
-
- # Add a publisher to the composite.
- def add(pub)
- @publishers << pub
- end
-
- # Upload all the individual publishers.
- def upload
- @publishers.each { |p| p.upload }
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rake/contrib/ftptools.rb b/ruby_2_2/lib/rake/contrib/ftptools.rb
deleted file mode 100644
index b178523bc6..0000000000
--- a/ruby_2_2/lib/rake/contrib/ftptools.rb
+++ /dev/null
@@ -1,137 +0,0 @@
-# = Tools for FTP uploading.
-#
-# This file is still under development and is not released for general
-# use.
-
-require 'date'
-require 'net/ftp'
-require 'rake/file_list'
-
-module Rake # :nodoc:
-
- class FtpFile # :nodoc: all
- attr_reader :name, :size, :owner, :group, :time
-
- def self.date
- @date_class ||= Date
- end
-
- def self.time
- @time_class ||= Time
- end
-
- def initialize(path, entry)
- @path = path
- @mode, _, @owner, @group, size, d1, d2, d3, @name = entry.split(' ')
- @size = size.to_i
- @time = determine_time(d1, d2, d3)
- end
-
- def path
- File.join(@path, @name)
- end
-
- def directory?
- @mode[0] == ?d
- end
-
- def mode
- parse_mode(@mode)
- end
-
- def symlink?
- @mode[0] == ?l
- end
-
- private # --------------------------------------------------------
-
- def parse_mode(m)
- result = 0
- (1..9).each do |i|
- result = 2 * result + ((m[i] == ?-) ? 0 : 1)
- end
- result
- end
-
- def determine_time(d1, d2, d3)
- now = self.class.time.now
- if /:/ !~ d3
- result = Time.parse("#{d1} #{d2} #{d3}")
- else
- result = Time.parse("#{d1} #{d2} #{now.year} #{d3}")
- result = Time.parse("#{d1} #{d2} #{now.year - 1} #{d3}") if
- result > now
- end
- result
- end
- end
-
- ##
- # Manage the uploading of files to an FTP account.
- class FtpUploader # :nodoc:
-
- # Log uploads to standard output when true.
- attr_accessor :verbose
-
- class << FtpUploader
- # Create an uploader and pass it to the given block as +up+.
- # When the block is complete, close the uploader.
- def connect(path, host, account, password)
- up = self.new(path, host, account, password)
- begin
- yield(up)
- ensure
- up.close
- end
- end
- end
-
- # Create an FTP uploader targeting the directory +path+ on +host+
- # using the given account and password. +path+ will be the root
- # path of the uploader.
- def initialize(path, host, account, password)
- @created = Hash.new
- @path = path
- @ftp = Net::FTP.new(host, account, password)
- makedirs(@path)
- @ftp.chdir(@path)
- end
-
- # Create the directory +path+ in the uploader root path.
- def makedirs(path)
- route = []
- File.split(path).each do |dir|
- route << dir
- current_dir = File.join(route)
- if @created[current_dir].nil?
- @created[current_dir] = true
- $stderr.puts "Creating Directory #{current_dir}" if @verbose
- @ftp.mkdir(current_dir) rescue nil
- end
- end
- end
-
- # Upload all files matching +wildcard+ to the uploader's root
- # path.
- def upload_files(wildcard)
- FileList.glob(wildcard).each do |fn|
- upload(fn)
- end
- end
-
- # Close the uploader.
- def close
- @ftp.close
- end
-
- private # --------------------------------------------------------
-
- # Upload a single file to the uploader's root path.
- def upload(file)
- $stderr.puts "Uploading #{file}" if @verbose
- dir = File.dirname(file)
- makedirs(dir)
- @ftp.putbinaryfile(file, file) unless File.directory?(file)
- end
- end
-end
diff --git a/ruby_2_2/lib/rake/contrib/publisher.rb b/ruby_2_2/lib/rake/contrib/publisher.rb
deleted file mode 100644
index f4ee1abf86..0000000000
--- a/ruby_2_2/lib/rake/contrib/publisher.rb
+++ /dev/null
@@ -1,81 +0,0 @@
-# Copyright 2003-2010 by Jim Weirich (jim.weirich@gmail.com)
-# All rights reserved.
-
-# :stopdoc:
-
-# Configuration information about an upload host system.
-# name :: Name of host system.
-# webdir :: Base directory for the web information for the
-# application. The application name (APP) is appended to
-# this directory before using.
-# pkgdir :: Directory on the host system where packages can be
-# placed.
-HostInfo = Struct.new(:name, :webdir, :pkgdir)
-
-# :startdoc:
-
-# TODO: Move to contrib/sshpublisher
-#--
-# Manage several publishers as a single entity.
-class CompositePublisher # :nodoc:
- def initialize
- @publishers = []
- end
-
- # Add a publisher to the composite.
- def add(pub)
- @publishers << pub
- end
-
- # Upload all the individual publishers.
- def upload
- @publishers.each { |p| p.upload }
- end
-end
-
-# TODO: Remove in Rake 11, duplicated
-#--
-# Publish an entire directory to an existing remote directory using
-# SSH.
-class SshDirPublisher # :nodoc: all
- def initialize(host, remote_dir, local_dir)
- @host = host
- @remote_dir = remote_dir
- @local_dir = local_dir
- end
-
- def upload
- run %{scp -rq #{@local_dir}/* #{@host}:#{@remote_dir}}
- end
-end
-
-# TODO: Remove in Rake 11, duplicated
-#--
-# Publish an entire directory to a fresh remote directory using SSH.
-class SshFreshDirPublisher < SshDirPublisher # :nodoc: all
- def upload
- run %{ssh #{@host} rm -rf #{@remote_dir}} rescue nil
- run %{ssh #{@host} mkdir #{@remote_dir}}
- super
- end
-end
-
-# TODO: Remove in Rake 11, duplicated
-#--
-# Publish a list of files to an existing remote directory.
-class SshFilePublisher # :nodoc: all
- # Create a publisher using the give host information.
- def initialize(host, remote_dir, local_dir, *files)
- @host = host
- @remote_dir = remote_dir
- @local_dir = local_dir
- @files = files
- end
-
- # Upload the local directory to the remote directory.
- def upload
- @files.each do |fn|
- run %{scp -q #{@local_dir}/#{fn} #{@host}:#{@remote_dir}}
- end
- end
-end
diff --git a/ruby_2_2/lib/rake/contrib/rubyforgepublisher.rb b/ruby_2_2/lib/rake/contrib/rubyforgepublisher.rb
deleted file mode 100644
index 00889ad7b9..0000000000
--- a/ruby_2_2/lib/rake/contrib/rubyforgepublisher.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# TODO: Remove in Rake 11
-
-require 'rake/contrib/sshpublisher'
-
-module Rake
-
- class RubyForgePublisher < SshDirPublisher # :nodoc: all
- attr_reader :project, :proj_id, :user
-
- def initialize(projname, user)
- super(
- "#{user}@rubyforge.org",
- "/var/www/gforge-projects/#{projname}",
- "html")
- end
- end
-
-end
diff --git a/ruby_2_2/lib/rake/contrib/sshpublisher.rb b/ruby_2_2/lib/rake/contrib/sshpublisher.rb
deleted file mode 100644
index 64f577017c..0000000000
--- a/ruby_2_2/lib/rake/contrib/sshpublisher.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-require 'rake/dsl_definition'
-require 'rake/contrib/compositepublisher'
-
-module Rake
-
- # Publish an entire directory to an existing remote directory using
- # SSH.
- class SshDirPublisher
- include Rake::DSL
-
- # Creates an SSH publisher which will scp all files in +local_dir+ to
- # +remote_dir+ on +host+
-
- def initialize(host, remote_dir, local_dir)
- @host = host
- @remote_dir = remote_dir
- @local_dir = local_dir
- end
-
- # Uploads the files
-
- def upload
- sh "scp", "-rq", "#{@local_dir}/*", "#{@host}:#{@remote_dir}"
- end
- end
-
- # Publish an entire directory to a fresh remote directory using SSH.
- class SshFreshDirPublisher < SshDirPublisher
-
- # Uploads the files after removing the existing remote directory.
-
- def upload
- sh "ssh", @host, "rm", "-rf", @remote_dir rescue nil
- sh "ssh", @host, "mkdir", @remote_dir
- super
- end
- end
-
- # Publish a list of files to an existing remote directory.
- class SshFilePublisher
- include Rake::DSL
-
- # Creates an SSH publisher which will scp all +files+ in +local_dir+ to
- # +remote_dir+ on +host+.
-
- def initialize(host, remote_dir, local_dir, *files)
- @host = host
- @remote_dir = remote_dir
- @local_dir = local_dir
- @files = files
- end
-
- # Uploads the files
-
- def upload
- @files.each do |fn|
- sh "scp", "-q", "#{@local_dir}/#{fn}", "#{@host}:#{@remote_dir}"
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rake/contrib/sys.rb b/ruby_2_2/lib/rake/contrib/sys.rb
deleted file mode 100644
index 8d4c735434..0000000000
--- a/ruby_2_2/lib/rake/contrib/sys.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-# TODO: Remove in Rake 11
-
-fail "ERROR: 'rake/contrib/sys' is obsolete and no longer supported. " +
- "Use 'FileUtils' instead."
diff --git a/ruby_2_2/lib/rake/cpu_counter.rb b/ruby_2_2/lib/rake/cpu_counter.rb
deleted file mode 100644
index f29778ed5d..0000000000
--- a/ruby_2_2/lib/rake/cpu_counter.rb
+++ /dev/null
@@ -1,125 +0,0 @@
-module Rake
-
- # Based on a script at:
- # http://stackoverflow.com/questions/891537/ruby-detect-number-of-cpus-installed
- class CpuCounter # :nodoc: all
- def self.count
- new.count_with_default
- end
-
- def count_with_default(default=4)
- count || default
- rescue StandardError
- default
- end
-
- begin
- require 'etc'
- rescue LoadError
- else
- if Etc.respond_to?(:nprocessors)
- def count
- return Etc.nprocessors
- end
- end
- end
- end
-end
-
-unless Rake::CpuCounter.method_defined?(:count)
- Rake::CpuCounter.class_eval <<-'end;', __FILE__, __LINE__+1
- require 'rbconfig'
-
- # TODO: replace with IO.popen using array-style arguments in Rake 11
- require 'open3'
-
- def count
- if defined?(Java::Java)
- count_via_java_runtime
- else
- case RbConfig::CONFIG['host_os']
- when /darwin9/
- count_via_hwprefs_cpu_count
- when /darwin/
- count_via_hwprefs_thread_count || count_via_sysctl
- when /linux/
- count_via_cpuinfo
- when /bsd/
- count_via_sysctl
- when /mswin|mingw/
- count_via_win32
- else
- # Try everything
- count_via_win32 ||
- count_via_sysctl ||
- count_via_hwprefs_thread_count ||
- count_via_hwprefs_cpu_count ||
- count_via_cpuinfo
- end
- end
- end
-
- def count_via_java_runtime
- Java::Java.lang.Runtime.getRuntime.availableProcessors
- rescue StandardError
- nil
- end
-
- def count_via_win32
- require 'win32ole'
- wmi = WIN32OLE.connect("winmgmts://")
- cpu = wmi.ExecQuery("select NumberOfCores from Win32_Processor") # TODO count hyper-threaded in this
- cpu.to_enum.first.NumberOfCores
- rescue StandardError, LoadError
- nil
- end
-
- def count_via_cpuinfo
- open('/proc/cpuinfo') { |f| f.readlines }.grep(/processor/).size
- rescue StandardError
- nil
- end
-
- def count_via_hwprefs_thread_count
- run 'hwprefs', 'thread_count'
- end
-
- def count_via_hwprefs_cpu_count
- run 'hwprefs', 'cpu_count'
- end
-
- def count_via_sysctl
- run 'sysctl', '-n', 'hw.ncpu'
- end
-
- def run(command, *args)
- cmd = resolve_command(command)
- if cmd
- Open3.popen3 cmd, *args do |inn, out, err,|
- inn.close
- err.read
- out.read.to_i
- end
- else
- nil
- end
- end
-
- def resolve_command(command)
- look_for_command("/usr/sbin", command) ||
- look_for_command("/sbin", command) ||
- in_path_command(command)
- end
-
- def look_for_command(dir, command)
- path = File.join(dir, command)
- File.exist?(path) ? path : nil
- end
-
- def in_path_command(command)
- Open3.popen3 'which', command do |_, out,|
- out.eof? ? nil : command
- end
- end
- end;
-end
diff --git a/ruby_2_2/lib/rake/default_loader.rb b/ruby_2_2/lib/rake/default_loader.rb
deleted file mode 100644
index 6154408f44..0000000000
--- a/ruby_2_2/lib/rake/default_loader.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-module Rake
-
- # Default Rakefile loader used by +import+.
- class DefaultLoader
-
- ##
- # Loads a rakefile into the current application from +fn+
-
- def load(fn)
- Rake.load_rakefile(File.expand_path(fn))
- end
- end
-
-end
diff --git a/ruby_2_2/lib/rake/dsl_definition.rb b/ruby_2_2/lib/rake/dsl_definition.rb
deleted file mode 100644
index 26f4ca828c..0000000000
--- a/ruby_2_2/lib/rake/dsl_definition.rb
+++ /dev/null
@@ -1,201 +0,0 @@
-# Rake DSL functions.
-require 'rake/file_utils_ext'
-
-module Rake
-
- ##
- # DSL is a module that provides #task, #desc, #namespace, etc. Use this
- # when you'd like to use rake outside the top level scope.
- #
- # For a Rakefile you run from the comamnd line this module is automatically
- # included.
-
- module DSL
-
- #--
- # Include the FileUtils file manipulation functions in the top
- # level module, but mark them private so that they don't
- # unintentionally define methods on other objects.
- #++
-
- include FileUtilsExt
- private(*FileUtils.instance_methods(false))
- private(*FileUtilsExt.instance_methods(false))
-
- private
-
- # :call-seq:
- # task task_name
- # task task_name: dependencies
- # task task_name, arguments => dependencies
- # task task_name, argument[, argument ...], :needs: dependencies
- #
- # Declare a basic task. The +task_name+ is always the first argument. If
- # the task name contains a ":" it is defined in that namespace.
- #
- # The +dependencies+ may be a single task name or an Array of task names.
- # The +argument+ (a single name) or +arguments+ (an Array of names) define
- # the arguments provided to the task.
- #
- # The task, argument and dependency names may be either symbols or
- # strings.
- #
- # A task with a single dependency:
- #
- # task clobber: %w[clean] do
- # rm_rf "html"
- # end
- #
- # A task with an argument and a dependency:
- #
- # task :package, [:version] => :test do |t, args|
- # # ...
- # end
- #
- # To invoke this task from the command line:
- #
- # $ rake package[1.2.3]
- #
- # Alternate definition:
- #
- # task :package, :version, needs: :test do |t, args|
- # # ...
- # end
- #
- def task(*args, &block) # :doc:
- Rake::Task.define_task(*args, &block)
- end
-
- # Declare a file task.
- #
- # Example:
- # file "config.cfg" => ["config.template"] do
- # open("config.cfg", "w") do |outfile|
- # open("config.template") do |infile|
- # while line = infile.gets
- # outfile.puts line
- # end
- # end
- # end
- # end
- #
- def file(*args, &block) # :doc:
- Rake::FileTask.define_task(*args, &block)
- end
-
- # Declare a file creation task.
- # (Mainly used for the directory command).
- def file_create(*args, &block)
- Rake::FileCreationTask.define_task(*args, &block)
- end
-
- # Declare a set of files tasks to create the given directories on
- # demand.
- #
- # Example:
- # directory "testdata/doc"
- #
- def directory(*args, &block) # :doc:
- result = file_create(*args, &block)
- dir, _ = *Rake.application.resolve_args(args)
- dir = Rake.from_pathname(dir)
- Rake.each_dir_parent(dir) do |d|
- file_create d do |t|
- mkdir_p t.name unless File.exist?(t.name)
- end
- end
- result
- end
-
- # Declare a task that performs its prerequisites in
- # parallel. Multitasks does *not* guarantee that its prerequisites
- # will execute in any given order (which is obvious when you think
- # about it)
- #
- # Example:
- # multitask deploy: %w[deploy_gem deploy_rdoc]
- #
- def multitask(*args, &block) # :doc:
- Rake::MultiTask.define_task(*args, &block)
- end
-
- # Create a new rake namespace and use it for evaluating the given
- # block. Returns a NameSpace object that can be used to lookup
- # tasks defined in the namespace.
- #
- # Example:
- #
- # ns = namespace "nested" do
- # # the "nested:run" task
- # task :run
- # end
- # task_run = ns[:run] # find :run in the given namespace.
- #
- # Tasks can also be defined in a namespace by using a ":" in the task
- # name:
- #
- # task "nested:test" do
- # # ...
- # end
- #
- def namespace(name=nil, &block) # :doc:
- name = name.to_s if name.kind_of?(Symbol)
- name = name.to_str if name.respond_to?(:to_str)
- unless name.kind_of?(String) || name.nil?
- raise ArgumentError, "Expected a String or Symbol for a namespace name"
- end
- Rake.application.in_namespace(name, &block)
- end
-
- # Declare a rule for auto-tasks.
- #
- # Example:
- # rule '.o' => '.c' do |t|
- # sh 'cc', '-o', t.name, t.source
- # end
- #
- def rule(*args, &block) # :doc:
- Rake::Task.create_rule(*args, &block)
- end
-
- # Describes the next rake task. Duplicate descriptions are discarded.
- # Descriptions are shown with <code>rake -T</code> (up to the first
- # sentence) and <code>rake -D</code> (the entire description).
- #
- # Example:
- # desc "Run the Unit Tests"
- # task test: [:build]
- # # ... run tests
- # end
- #
- def desc(description) # :doc:
- Rake.application.last_description = description
- end
-
- # Import the partial Rakefiles +fn+. Imported files are loaded
- # _after_ the current file is completely loaded. This allows the
- # import statement to appear anywhere in the importing file, and yet
- # allowing the imported files to depend on objects defined in the
- # importing file.
- #
- # A common use of the import statement is to include files
- # containing dependency declarations.
- #
- # See also the --rakelibdir command line option.
- #
- # Example:
- # import ".depend", "my_rules"
- #
- def import(*fns) # :doc:
- fns.each do |fn|
- Rake.application.add_import(fn)
- end
- end
- end
- extend FileUtilsExt
-end
-
-# Extend the main object with the DSL commands. This allows top-level
-# calls to task, etc. to work from a Rakefile without polluting the
-# object inheritance tree.
-self.extend Rake::DSL
diff --git a/ruby_2_2/lib/rake/early_time.rb b/ruby_2_2/lib/rake/early_time.rb
deleted file mode 100644
index abcb1872b5..0000000000
--- a/ruby_2_2/lib/rake/early_time.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-module Rake
-
- # EarlyTime is a fake timestamp that occurs _before_ any other time value.
- class EarlyTime
- include Comparable
- include Singleton
-
- ##
- # The EarlyTime always comes before +other+!
-
- def <=>(other)
- -1
- end
-
- def to_s # :nodoc:
- "<EARLY TIME>"
- end
- end
-
- EARLY = EarlyTime.instance
-end
diff --git a/ruby_2_2/lib/rake/ext/core.rb b/ruby_2_2/lib/rake/ext/core.rb
deleted file mode 100644
index 7575df15a9..0000000000
--- a/ruby_2_2/lib/rake/ext/core.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-class Module
- # Check for an existing method in the current class before extending. If
- # the method already exists, then a warning is printed and the extension is
- # not added. Otherwise the block is yielded and any definitions in the
- # block will take effect.
- #
- # Usage:
- #
- # class String
- # rake_extension("xyz") do
- # def xyz
- # ...
- # end
- # end
- # end
- #
- def rake_extension(method) # :nodoc:
- if method_defined?(method)
- $stderr.puts "WARNING: Possible conflict with Rake extension: " +
- "#{self}##{method} already exists"
- else
- yield
- end
- end
-end
diff --git a/ruby_2_2/lib/rake/ext/module.rb b/ruby_2_2/lib/rake/ext/module.rb
deleted file mode 100644
index 3ee155ff6c..0000000000
--- a/ruby_2_2/lib/rake/ext/module.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-
-# TODO: remove in Rake 11
diff --git a/ruby_2_2/lib/rake/ext/pathname.rb b/ruby_2_2/lib/rake/ext/pathname.rb
deleted file mode 100644
index 49e2cd47ac..0000000000
--- a/ruby_2_2/lib/rake/ext/pathname.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require 'rake/ext/core'
-require 'pathname'
-
-class Pathname
-
- rake_extension("ext") do
- # Return a new Pathname with <tt>String#ext</tt> applied to it.
- #
- # This Pathname extension comes from Rake
- def ext(newext='')
- Pathname.new(Rake.from_pathname(self).ext(newext))
- end
- end
-
- rake_extension("pathmap") do
- # Apply the pathmap spec to the Pathname, returning a
- # new Pathname with the modified paths. (See String#pathmap for
- # details.)
- #
- # This Pathname extension comes from Rake
- def pathmap(spec=nil, &block)
- Pathname.new(Rake.from_pathname(self).pathmap(spec, &block))
- end
- end
-end
diff --git a/ruby_2_2/lib/rake/ext/string.rb b/ruby_2_2/lib/rake/ext/string.rb
deleted file mode 100644
index b47b055a74..0000000000
--- a/ruby_2_2/lib/rake/ext/string.rb
+++ /dev/null
@@ -1,173 +0,0 @@
-require 'rake/ext/core'
-
-class String
-
- rake_extension("ext") do
- # Replace the file extension with +newext+. If there is no extension on
- # the string, append the new extension to the end. If the new extension
- # is not given, or is the empty string, remove any existing extension.
- #
- # +ext+ is a user added method for the String class.
- #
- # This String extension comes from Rake
- def ext(newext='')
- return self.dup if ['.', '..'].include? self
- newext = (newext =~ /^\./) ? newext : ("." + newext) if newext != ''
- self.chomp(File.extname(self)) << newext
- end
- end
-
- rake_extension("pathmap") do
- # Explode a path into individual components. Used by +pathmap+.
- #
- # This String extension comes from Rake
- def pathmap_explode
- head, tail = File.split(self)
- return [self] if head == self
- return [tail] if head == '.' || tail == '/'
- return [head, tail] if head == '/'
- return head.pathmap_explode + [tail]
- end
- protected :pathmap_explode
-
- # Extract a partial path from the path. Include +n+ directories from the
- # front end (left hand side) if +n+ is positive. Include |+n+|
- # directories from the back end (right hand side) if +n+ is negative.
- #
- # This String extension comes from Rake
- def pathmap_partial(n)
- dirs = File.dirname(self).pathmap_explode
- partial_dirs =
- if n > 0
- dirs[0...n]
- elsif n < 0
- dirs.reverse[0...-n].reverse
- else
- "."
- end
- File.join(partial_dirs)
- end
- protected :pathmap_partial
-
- # Perform the pathmap replacement operations on the given path. The
- # patterns take the form 'pat1,rep1;pat2,rep2...'.
- #
- # This String extension comes from Rake
- def pathmap_replace(patterns, &block)
- result = self
- patterns.split(';').each do |pair|
- pattern, replacement = pair.split(',')
- pattern = Regexp.new(pattern)
- if replacement == '*' && block_given?
- result = result.sub(pattern, &block)
- elsif replacement
- result = result.sub(pattern, replacement)
- else
- result = result.sub(pattern, '')
- end
- end
- result
- end
- protected :pathmap_replace
-
- # Map the path according to the given specification. The specification
- # controls the details of the mapping. The following special patterns are
- # recognized:
- #
- # <tt>%p</tt> :: The complete path.
- # <tt>%f</tt> :: The base file name of the path, with its file extension,
- # but without any directories.
- # <tt>%n</tt> :: The file name of the path without its file extension.
- # <tt>%d</tt> :: The directory list of the path.
- # <tt>%x</tt> :: The file extension of the path. An empty string if there
- # is no extension.
- # <tt>%X</tt> :: Everything *but* the file extension.
- # <tt>%s</tt> :: The alternate file separator if defined, otherwise use #
- # the standard file separator.
- # <tt>%%</tt> :: A percent sign.
- #
- # The <tt>%d</tt> specifier can also have a numeric prefix (e.g. '%2d').
- # If the number is positive, only return (up to) +n+ directories in the
- # path, starting from the left hand side. If +n+ is negative, return (up
- # to) +n+ directories from the right hand side of the path.
- #
- # Examples:
- #
- # 'a/b/c/d/file.txt'.pathmap("%2d") => 'a/b'
- # 'a/b/c/d/file.txt'.pathmap("%-2d") => 'c/d'
- #
- # Also the <tt>%d</tt>, <tt>%p</tt>, <tt>%f</tt>, <tt>%n</tt>,
- # <tt>%x</tt>, and <tt>%X</tt> operators can take a pattern/replacement
- # argument to perform simple string substitutions on a particular part of
- # the path. The pattern and replacement are separated by a comma and are
- # enclosed by curly braces. The replacement spec comes after the %
- # character but before the operator letter. (e.g. "%{old,new}d").
- # Multiple replacement specs should be separated by semi-colons (e.g.
- # "%{old,new;src,bin}d").
- #
- # Regular expressions may be used for the pattern, and back refs may be
- # used in the replacement text. Curly braces, commas and semi-colons are
- # excluded from both the pattern and replacement text (let's keep parsing
- # reasonable).
- #
- # For example:
- #
- # "src/org/onestepback/proj/A.java".pathmap("%{^src,class}X.class")
- #
- # returns:
- #
- # "class/org/onestepback/proj/A.class"
- #
- # If the replacement text is '*', then a block may be provided to perform
- # some arbitrary calculation for the replacement.
- #
- # For example:
- #
- # "/path/to/file.TXT".pathmap("%X%{.*,*}x") { |ext|
- # ext.downcase
- # }
- #
- # Returns:
- #
- # "/path/to/file.txt"
- #
- # This String extension comes from Rake
- def pathmap(spec=nil, &block)
- return self if spec.nil?
- result = ''
- spec.scan(/%\{[^}]*\}-?\d*[sdpfnxX%]|%-?\d+d|%.|[^%]+/) do |frag|
- case frag
- when '%f'
- result << File.basename(self)
- when '%n'
- result << File.basename(self).ext
- when '%d'
- result << File.dirname(self)
- when '%x'
- result << File.extname(self)
- when '%X'
- result << self.ext
- when '%p'
- result << self
- when '%s'
- result << (File::ALT_SEPARATOR || File::SEPARATOR)
- when '%-'
- # do nothing
- when '%%'
- result << "%"
- when /%(-?\d+)d/
- result << pathmap_partial($1.to_i)
- when /^%\{([^}]*)\}(\d*[dpfnxX])/
- patterns, operator = $1, $2
- result << pathmap('%' + operator).pathmap_replace(patterns, &block)
- when /^%/
- fail ArgumentError, "Unknown pathmap specifier #{frag} in '#{spec}'"
- else
- result << frag
- end
- end
- result
- end
- end
-
-end
diff --git a/ruby_2_2/lib/rake/ext/time.rb b/ruby_2_2/lib/rake/ext/time.rb
deleted file mode 100644
index d3b8cf9dc1..0000000000
--- a/ruby_2_2/lib/rake/ext/time.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-#--
-# Extensions to time to allow comparisons with early and late time classes.
-
-require 'rake/early_time'
-require 'rake/late_time'
-
-class Time # :nodoc: all
- alias rake_original_time_compare :<=>
- def <=>(other)
- if Rake::EarlyTime === other || Rake::LateTime === other
- - other.<=>(self)
- else
- rake_original_time_compare(other)
- end
- end
-end
diff --git a/ruby_2_2/lib/rake/file_creation_task.rb b/ruby_2_2/lib/rake/file_creation_task.rb
deleted file mode 100644
index c87e2192bb..0000000000
--- a/ruby_2_2/lib/rake/file_creation_task.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require 'rake/file_task'
-require 'rake/early_time'
-
-module Rake
-
- # A FileCreationTask is a file task that when used as a dependency will be
- # needed if and only if the file has not been created. Once created, it is
- # not re-triggered if any of its dependencies are newer, nor does trigger
- # any rebuilds of tasks that depend on it whenever it is updated.
- #
- class FileCreationTask < FileTask
- # Is this file task needed? Yes if it doesn't exist.
- def needed?
- ! File.exist?(name)
- end
-
- # Time stamp for file creation task. This time stamp is earlier
- # than any other time stamp.
- def timestamp
- Rake::EARLY
- end
- end
-
-end
diff --git a/ruby_2_2/lib/rake/file_list.rb b/ruby_2_2/lib/rake/file_list.rb
deleted file mode 100644
index 006ec7703e..0000000000
--- a/ruby_2_2/lib/rake/file_list.rb
+++ /dev/null
@@ -1,428 +0,0 @@
-require 'rake/cloneable'
-require 'rake/file_utils_ext'
-require 'rake/pathmap'
-
-
-module Rake
-
- ##
- # A FileList is essentially an array with a few helper methods defined to
- # make file manipulation a bit easier.
- #
- # FileLists are lazy. When given a list of glob patterns for possible files
- # to be included in the file list, instead of searching the file structures
- # to find the files, a FileList holds the pattern for latter use.
- #
- # This allows us to define a number of FileList to match any number of
- # files, but only search out the actual files when then FileList itself is
- # actually used. The key is that the first time an element of the
- # FileList/Array is requested, the pending patterns are resolved into a real
- # list of file names.
- #
- class FileList
-
- include Cloneable
-
- # == Method Delegation
- #
- # The lazy evaluation magic of FileLists happens by implementing all the
- # array specific methods to call +resolve+ before delegating the heavy
- # lifting to an embedded array object (@items).
- #
- # In addition, there are two kinds of delegation calls. The regular kind
- # delegates to the @items array and returns the result directly. Well,
- # almost directly. It checks if the returned value is the @items object
- # itself, and if so will return the FileList object instead.
- #
- # The second kind of delegation call is used in methods that normally
- # return a new Array object. We want to capture the return value of these
- # methods and wrap them in a new FileList object. We enumerate these
- # methods in the +SPECIAL_RETURN+ list below.
-
- # List of array methods (that are not in +Object+) that need to be
- # delegated.
- ARRAY_METHODS = (Array.instance_methods - Object.instance_methods).
- map { |n| n.to_s }
-
- # List of additional methods that must be delegated.
- MUST_DEFINE = %w[inspect <=>]
-
- # List of methods that should not be delegated here (we define special
- # versions of them explicitly below).
- MUST_NOT_DEFINE = %w[to_a to_ary partition * <<]
-
- # List of delegated methods that return new array values which need
- # wrapping.
- SPECIAL_RETURN = %w[
- map collect sort sort_by select find_all reject grep
- compact flatten uniq values_at
- + - & |
- ]
-
- DELEGATING_METHODS = (ARRAY_METHODS + MUST_DEFINE - MUST_NOT_DEFINE).
- map { |s| s.to_s }.sort.uniq
-
- # Now do the delegation.
- DELEGATING_METHODS.each do |sym|
- if SPECIAL_RETURN.include?(sym)
- ln = __LINE__ + 1
- class_eval %{
- def #{sym}(*args, &block)
- resolve
- result = @items.send(:#{sym}, *args, &block)
- FileList.new.import(result)
- end
- }, __FILE__, ln
- else
- ln = __LINE__ + 1
- class_eval %{
- def #{sym}(*args, &block)
- resolve
- result = @items.send(:#{sym}, *args, &block)
- result.object_id == @items.object_id ? self : result
- end
- }, __FILE__, ln
- end
- end
-
- # Create a file list from the globbable patterns given. If you wish to
- # perform multiple includes or excludes at object build time, use the
- # "yield self" pattern.
- #
- # Example:
- # file_list = FileList.new('lib/**/*.rb', 'test/test*.rb')
- #
- # pkg_files = FileList.new('lib/**/*') do |fl|
- # fl.exclude(/\bCVS\b/)
- # end
- #
- def initialize(*patterns)
- @pending_add = []
- @pending = false
- @exclude_patterns = DEFAULT_IGNORE_PATTERNS.dup
- @exclude_procs = DEFAULT_IGNORE_PROCS.dup
- @items = []
- patterns.each { |pattern| include(pattern) }
- yield self if block_given?
- end
-
- # Add file names defined by glob patterns to the file list. If an array
- # is given, add each element of the array.
- #
- # Example:
- # file_list.include("*.java", "*.cfg")
- # file_list.include %w( math.c lib.h *.o )
- #
- def include(*filenames)
- # TODO: check for pending
- filenames.each do |fn|
- if fn.respond_to? :to_ary
- include(*fn.to_ary)
- else
- @pending_add << Rake.from_pathname(fn)
- end
- end
- @pending = true
- self
- end
- alias :add :include
-
- # Register a list of file name patterns that should be excluded from the
- # list. Patterns may be regular expressions, glob patterns or regular
- # strings. In addition, a block given to exclude will remove entries that
- # return true when given to the block.
- #
- # Note that glob patterns are expanded against the file system. If a file
- # is explicitly added to a file list, but does not exist in the file
- # system, then an glob pattern in the exclude list will not exclude the
- # file.
- #
- # Examples:
- # FileList['a.c', 'b.c'].exclude("a.c") => ['b.c']
- # FileList['a.c', 'b.c'].exclude(/^a/) => ['b.c']
- #
- # If "a.c" is a file, then ...
- # FileList['a.c', 'b.c'].exclude("a.*") => ['b.c']
- #
- # If "a.c" is not a file, then ...
- # FileList['a.c', 'b.c'].exclude("a.*") => ['a.c', 'b.c']
- #
- def exclude(*patterns, &block)
- patterns.each do |pat|
- @exclude_patterns << Rake.from_pathname(pat)
- end
- @exclude_procs << block if block_given?
- resolve_exclude unless @pending
- self
- end
-
- # Clear all the exclude patterns so that we exclude nothing.
- def clear_exclude
- @exclude_patterns = []
- @exclude_procs = []
- self
- end
-
- # A FileList is equal through array equality.
- def ==(array)
- to_ary == array
- end
-
- # Return the internal array object.
- def to_a
- resolve
- @items
- end
-
- # Return the internal array object.
- def to_ary
- to_a
- end
-
- # Lie about our class.
- def is_a?(klass)
- klass == Array || super(klass)
- end
- alias kind_of? is_a?
-
- # Redefine * to return either a string or a new file list.
- def *(other)
- result = @items * other
- case result
- when Array
- FileList.new.import(result)
- else
- result
- end
- end
-
- def <<(obj)
- resolve
- @items << Rake.from_pathname(obj)
- self
- end
-
- # Resolve all the pending adds now.
- def resolve
- if @pending
- @pending = false
- @pending_add.each do |fn| resolve_add(fn) end
- @pending_add = []
- resolve_exclude
- end
- self
- end
-
- def resolve_add(fn) # :nodoc:
- case fn
- when %r{[*?\[\{]}
- add_matching(fn)
- else
- self << fn
- end
- end
- private :resolve_add
-
- def resolve_exclude # :nodoc:
- reject! { |fn| excluded_from_list?(fn) }
- self
- end
- private :resolve_exclude
-
- # Return a new FileList with the results of running +sub+ against each
- # element of the original list.
- #
- # Example:
- # FileList['a.c', 'b.c'].sub(/\.c$/, '.o') => ['a.o', 'b.o']
- #
- def sub(pat, rep)
- inject(FileList.new) { |res, fn| res << fn.sub(pat, rep) }
- end
-
- # Return a new FileList with the results of running +gsub+ against each
- # element of the original list.
- #
- # Example:
- # FileList['lib/test/file', 'x/y'].gsub(/\//, "\\")
- # => ['lib\\test\\file', 'x\\y']
- #
- def gsub(pat, rep)
- inject(FileList.new) { |res, fn| res << fn.gsub(pat, rep) }
- end
-
- # Same as +sub+ except that the original file list is modified.
- def sub!(pat, rep)
- each_with_index { |fn, i| self[i] = fn.sub(pat, rep) }
- self
- end
-
- # Same as +gsub+ except that the original file list is modified.
- def gsub!(pat, rep)
- each_with_index { |fn, i| self[i] = fn.gsub(pat, rep) }
- self
- end
-
- # Apply the pathmap spec to each of the included file names, returning a
- # new file list with the modified paths. (See String#pathmap for
- # details.)
- def pathmap(spec=nil)
- collect { |fn| fn.pathmap(spec) }
- end
-
- # Return a new FileList with <tt>String#ext</tt> method applied to
- # each member of the array.
- #
- # This method is a shortcut for:
- #
- # array.collect { |item| item.ext(newext) }
- #
- # +ext+ is a user added method for the Array class.
- def ext(newext='')
- collect { |fn| fn.ext(newext) }
- end
-
- # Grep each of the files in the filelist using the given pattern. If a
- # block is given, call the block on each matching line, passing the file
- # name, line number, and the matching line of text. If no block is given,
- # a standard emacs style file:linenumber:line message will be printed to
- # standard out. Returns the number of matched items.
- def egrep(pattern, *options)
- matched = 0
- each do |fn|
- begin
- open(fn, "r", *options) do |inf|
- count = 0
- inf.each do |line|
- count += 1
- if pattern.match(line)
- matched += 1
- if block_given?
- yield fn, count, line
- else
- puts "#{fn}:#{count}:#{line}"
- end
- end
- end
- end
- rescue StandardError => ex
- $stderr.puts "Error while processing '#{fn}': #{ex}"
- end
- end
- matched
- end
-
- # Return a new file list that only contains file names from the current
- # file list that exist on the file system.
- def existing
- select { |fn| File.exist?(fn) }
- end
-
- # Modify the current file list so that it contains only file name that
- # exist on the file system.
- def existing!
- resolve
- @items = @items.select { |fn| File.exist?(fn) }
- self
- end
-
- # FileList version of partition. Needed because the nested arrays should
- # be FileLists in this version.
- def partition(&block) # :nodoc:
- resolve
- result = @items.partition(&block)
- [
- FileList.new.import(result[0]),
- FileList.new.import(result[1]),
- ]
- end
-
- # Convert a FileList to a string by joining all elements with a space.
- def to_s
- resolve
- self.join(' ')
- end
-
- # Add matching glob patterns.
- def add_matching(pattern)
- FileList.glob(pattern).each do |fn|
- self << fn unless excluded_from_list?(fn)
- end
- end
- private :add_matching
-
- # Should the given file name be excluded from the list?
- #
- # NOTE: This method was formerly named "exclude?", but Rails
- # introduced an exclude? method as an array method and setup a
- # conflict with file list. We renamed the method to avoid
- # confusion. If you were using "FileList#exclude?" in your user
- # code, you will need to update.
- def excluded_from_list?(fn)
- return true if @exclude_patterns.any? do |pat|
- case pat
- when Regexp
- fn =~ pat
- when /[*?]/
- File.fnmatch?(pat, fn, File::FNM_PATHNAME)
- else
- fn == pat
- end
- end
- @exclude_procs.any? { |p| p.call(fn) }
- end
-
- DEFAULT_IGNORE_PATTERNS = [
- /(^|[\/\\])CVS([\/\\]|$)/,
- /(^|[\/\\])\.svn([\/\\]|$)/,
- /\.bak$/,
- /~$/
- ]
- DEFAULT_IGNORE_PROCS = [
- proc { |fn| fn =~ /(^|[\/\\])core$/ && ! File.directory?(fn) }
- ]
-
- def import(array) # :nodoc:
- @items = array
- self
- end
-
- class << self
- # Create a new file list including the files listed. Similar to:
- #
- # FileList.new(*args)
- def [](*args)
- new(*args)
- end
-
- # Get a sorted list of files matching the pattern. This method
- # should be preferred to Dir[pattern] and Dir.glob(pattern) because
- # the files returned are guaranteed to be sorted.
- def glob(pattern, *args)
- Dir.glob(pattern, *args).sort
- end
- end
- end
-end
-
-module Rake
- class << self
-
- # Yield each file or directory component.
- def each_dir_parent(dir) # :nodoc:
- old_length = nil
- while dir != '.' && dir.length != old_length
- yield(dir)
- old_length = dir.length
- dir = File.dirname(dir)
- end
- end
-
- # Convert Pathname and Pathname-like objects to strings;
- # leave everything else alone
- def from_pathname(path) # :nodoc:
- path = path.to_path if path.respond_to?(:to_path)
- path = path.to_str if path.respond_to?(:to_str)
- path
- end
- end
-end # module Rake
diff --git a/ruby_2_2/lib/rake/file_task.rb b/ruby_2_2/lib/rake/file_task.rb
deleted file mode 100644
index 4c9b04074f..0000000000
--- a/ruby_2_2/lib/rake/file_task.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-require 'rake/task.rb'
-require 'rake/early_time'
-
-module Rake
-
- # A FileTask is a task that includes time based dependencies. If any of a
- # FileTask's prerequisites have a timestamp that is later than the file
- # represented by this task, then the file must be rebuilt (using the
- # supplied actions).
- #
- class FileTask < Task
-
- # Is this file task needed? Yes if it doesn't exist, or if its time stamp
- # is out of date.
- def needed?
- ! File.exist?(name) || out_of_date?(timestamp) || @application.options.build_all
- end
-
- # Time stamp for file task.
- def timestamp
- if File.exist?(name)
- File.mtime(name.to_s)
- else
- Rake::LATE
- end
- end
-
- private
-
- # Are there any prerequisites with a later time than the given time stamp?
- def out_of_date?(stamp)
- @prerequisites.any? { |n| application[n, @scope].timestamp > stamp }
- end
-
- # ----------------------------------------------------------------
- # Task class methods.
- #
- class << self
- # Apply the scope to the task name according to the rules for this kind
- # of task. File based tasks ignore the scope when creating the name.
- def scope_name(scope, task_name)
- Rake.from_pathname(task_name)
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rake/file_utils.rb b/ruby_2_2/lib/rake/file_utils.rb
deleted file mode 100644
index 27f4e2e1d1..0000000000
--- a/ruby_2_2/lib/rake/file_utils.rb
+++ /dev/null
@@ -1,128 +0,0 @@
-require 'rbconfig'
-require 'fileutils'
-
-#--
-# This a FileUtils extension that defines several additional commands to be
-# added to the FileUtils utility functions.
-module FileUtils
- # Path to the currently running Ruby program
- RUBY = ENV['RUBY'] || File.join(
- RbConfig::CONFIG['bindir'],
- RbConfig::CONFIG['ruby_install_name'] + RbConfig::CONFIG['EXEEXT']).
- sub(/.*\s.*/m, '"\&"')
-
- OPT_TABLE['sh'] = %w(noop verbose)
- OPT_TABLE['ruby'] = %w(noop verbose)
-
- # Run the system command +cmd+. If multiple arguments are given the command
- # is run directly (without the shell, same semantics as Kernel::exec and
- # Kernel::system).
- #
- # It is recommended you use the multiple argument form over interpolating
- # user input for both usability and security reasons. With the multiple
- # argument form you can easily process files with spaces or other shell
- # reserved characters in them. With the multiple argument form your rake
- # tasks are not vulnerable to users providing an argument like
- # <code>; rm # -rf /</code>.
- #
- # If a block is given, upon command completion the block is called with an
- # OK flag (true on a zero exit status) and a Process::Status object.
- # Without a block a RuntimeError is raised when the command exits non-zero.
- #
- # Examples:
- #
- # sh 'ls -ltr'
- #
- # sh 'ls', 'file with spaces'
- #
- # # check exit status after command runs
- # sh %{grep pattern file} do |ok, res|
- # if ! ok
- # puts "pattern not found (status = #{res.exitstatus})"
- # end
- # end
- #
- def sh(*cmd, &block)
- options = (Hash === cmd.last) ? cmd.pop : {}
- shell_runner = block_given? ? block : create_shell_runner(cmd)
- set_verbose_option(options)
- options[:noop] ||= Rake::FileUtilsExt.nowrite_flag
- Rake.rake_check_options options, :noop, :verbose
- Rake.rake_output_message cmd.join(" ") if options[:verbose]
-
- unless options[:noop]
- res = rake_system(*cmd)
- status = $?
- status = Rake::PseudoStatus.new(1) if !res && status.nil?
- shell_runner.call(res, status)
- end
- end
-
- def create_shell_runner(cmd) # :nodoc:
- show_command = cmd.join(" ")
- show_command = show_command[0, 42] + "..." unless $trace
- lambda do |ok, status|
- ok or
- fail "Command failed with status (#{status.exitstatus}): " +
- "[#{show_command}]"
- end
- end
- private :create_shell_runner
-
- def set_verbose_option(options) # :nodoc:
- unless options.key? :verbose
- options[:verbose] =
- (Rake::FileUtilsExt.verbose_flag == Rake::FileUtilsExt::DEFAULT) ||
- Rake::FileUtilsExt.verbose_flag
- end
- end
- private :set_verbose_option
-
- def rake_system(*cmd) # :nodoc:
- Rake::AltSystem.system(*cmd)
- end
- private :rake_system
-
- # Run a Ruby interpreter with the given arguments.
- #
- # Example:
- # ruby %{-pe '$_.upcase!' <README}
- #
- def ruby(*args, &block)
- options = (Hash === args.last) ? args.pop : {}
- if args.length > 1
- sh(*([RUBY] + args + [options]), &block)
- else
- sh("#{RUBY} #{args.first}", options, &block)
- end
- end
-
- LN_SUPPORTED = [true]
-
- # Attempt to do a normal file link, but fall back to a copy if the link
- # fails.
- def safe_ln(*args)
- if ! LN_SUPPORTED[0]
- cp(*args)
- else
- begin
- ln(*args)
- rescue StandardError, NotImplementedError
- LN_SUPPORTED[0] = false
- cp(*args)
- end
- end
- end
-
- # Split a file path into individual directory names.
- #
- # Example:
- # split_all("a/b/c") => ['a', 'b', 'c']
- #
- def split_all(path)
- head, tail = File.split(path)
- return [tail] if head == '.' || tail == '/'
- return [head, tail] if head == '/'
- return split_all(head) + [tail]
- end
-end
diff --git a/ruby_2_2/lib/rake/file_utils_ext.rb b/ruby_2_2/lib/rake/file_utils_ext.rb
deleted file mode 100644
index 309159aec1..0000000000
--- a/ruby_2_2/lib/rake/file_utils_ext.rb
+++ /dev/null
@@ -1,144 +0,0 @@
-require 'rake/file_utils'
-
-module Rake
- #
- # FileUtilsExt provides a custom version of the FileUtils methods
- # that respond to the <tt>verbose</tt> and <tt>nowrite</tt>
- # commands.
- #
- module FileUtilsExt
- include FileUtils
-
- class << self
- attr_accessor :verbose_flag, :nowrite_flag
- end
-
- DEFAULT = Object.new
-
- FileUtilsExt.verbose_flag = DEFAULT
- FileUtilsExt.nowrite_flag = false
-
- FileUtils.commands.each do |name|
- opts = FileUtils.options_of name
- default_options = []
- if opts.include?("verbose")
- default_options << ':verbose => FileUtilsExt.verbose_flag'
- end
- if opts.include?("noop")
- default_options << ':noop => FileUtilsExt.nowrite_flag'
- end
-
- next if default_options.empty?
- module_eval(<<-EOS, __FILE__, __LINE__ + 1)
- def #{name}( *args, &block )
- super(
- *rake_merge_option(args,
- #{default_options.join(', ')}
- ), &block)
- end
- EOS
- end
-
- # Get/set the verbose flag controlling output from the FileUtils
- # utilities. If verbose is true, then the utility method is
- # echoed to standard output.
- #
- # Examples:
- # verbose # return the current value of the
- # # verbose flag
- # verbose(v) # set the verbose flag to _v_.
- # verbose(v) { code } # Execute code with the verbose flag set
- # # temporarily to _v_. Return to the
- # # original value when code is done.
- def verbose(value=nil)
- oldvalue = FileUtilsExt.verbose_flag
- FileUtilsExt.verbose_flag = value unless value.nil?
- if block_given?
- begin
- yield
- ensure
- FileUtilsExt.verbose_flag = oldvalue
- end
- end
- FileUtilsExt.verbose_flag
- end
-
- # Get/set the nowrite flag controlling output from the FileUtils
- # utilities. If verbose is true, then the utility method is
- # echoed to standard output.
- #
- # Examples:
- # nowrite # return the current value of the
- # # nowrite flag
- # nowrite(v) # set the nowrite flag to _v_.
- # nowrite(v) { code } # Execute code with the nowrite flag set
- # # temporarily to _v_. Return to the
- # # original value when code is done.
- def nowrite(value=nil)
- oldvalue = FileUtilsExt.nowrite_flag
- FileUtilsExt.nowrite_flag = value unless value.nil?
- if block_given?
- begin
- yield
- ensure
- FileUtilsExt.nowrite_flag = oldvalue
- end
- end
- oldvalue
- end
-
- # Use this function to prevent potentially destructive ruby code
- # from running when the :nowrite flag is set.
- #
- # Example:
- #
- # when_writing("Building Project") do
- # project.build
- # end
- #
- # The following code will build the project under normal
- # conditions. If the nowrite(true) flag is set, then the example
- # will print:
- #
- # DRYRUN: Building Project
- #
- # instead of actually building the project.
- #
- def when_writing(msg=nil)
- if FileUtilsExt.nowrite_flag
- $stderr.puts "DRYRUN: #{msg}" if msg
- else
- yield
- end
- end
-
- # Merge the given options with the default values.
- def rake_merge_option(args, defaults)
- if Hash === args.last
- defaults.update(args.last)
- args.pop
- end
- args.push defaults
- args
- end
-
- # Send the message to the default rake output (which is $stderr).
- def rake_output_message(message)
- $stderr.puts(message)
- end
-
- # Check that the options do not contain options not listed in
- # +optdecl+. An ArgumentError exception is thrown if non-declared
- # options are found.
- def rake_check_options(options, *optdecl)
- h = options.dup
- optdecl.each do |name|
- h.delete name
- end
- raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless
- h.empty?
- end
-
- extend self
- end
-end
diff --git a/ruby_2_2/lib/rake/gempackagetask.rb b/ruby_2_2/lib/rake/gempackagetask.rb
deleted file mode 100644
index 16e7ce042b..0000000000
--- a/ruby_2_2/lib/rake/gempackagetask.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-# TODO: Remove in Rake 11
-
-fail "ERROR: 'rake/gempackagetask' is obsolete and no longer supported. " +
- "Use 'rubygems/package_task' instead."
diff --git a/ruby_2_2/lib/rake/invocation_chain.rb b/ruby_2_2/lib/rake/invocation_chain.rb
deleted file mode 100644
index 540628957c..0000000000
--- a/ruby_2_2/lib/rake/invocation_chain.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-module Rake
-
- # InvocationChain tracks the chain of task invocations to detect
- # circular dependencies.
- class InvocationChain < LinkedList
-
- # Is the invocation already in the chain?
- def member?(invocation)
- head == invocation || tail.member?(invocation)
- end
-
- # Append an invocation to the chain of invocations. It is an error
- # if the invocation already listed.
- def append(invocation)
- if member?(invocation)
- fail RuntimeError, "Circular dependency detected: #{to_s} => #{invocation}"
- end
- conj(invocation)
- end
-
- # Convert to string, ie: TOP => invocation => invocation
- def to_s
- "#{prefix}#{head}"
- end
-
- # Class level append.
- def self.append(invocation, chain)
- chain.append(invocation)
- end
-
- private
-
- def prefix
- "#{tail} => "
- end
-
- # Null object for an empty chain.
- class EmptyInvocationChain < LinkedList::EmptyLinkedList
- @parent = InvocationChain
-
- def member?(obj)
- false
- end
-
- def append(invocation)
- conj(invocation)
- end
-
- def to_s
- "TOP"
- end
- end
-
- EMPTY = EmptyInvocationChain.new
- end
-end
diff --git a/ruby_2_2/lib/rake/invocation_exception_mixin.rb b/ruby_2_2/lib/rake/invocation_exception_mixin.rb
deleted file mode 100644
index 84ff3353ba..0000000000
--- a/ruby_2_2/lib/rake/invocation_exception_mixin.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-module Rake
- module InvocationExceptionMixin
- # Return the invocation chain (list of Rake tasks) that were in
- # effect when this exception was detected by rake. May be null if
- # no tasks were active.
- def chain
- @rake_invocation_chain ||= nil
- end
-
- # Set the invocation chain in effect when this exception was
- # detected.
- def chain=(value)
- @rake_invocation_chain = value
- end
- end
-end
diff --git a/ruby_2_2/lib/rake/late_time.rb b/ruby_2_2/lib/rake/late_time.rb
deleted file mode 100644
index d959a7821f..0000000000
--- a/ruby_2_2/lib/rake/late_time.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-module Rake
- # LateTime is a fake timestamp that occurs _after_ any other time value.
- class LateTime
- include Comparable
- include Singleton
-
- def <=>(other)
- 1
- end
-
- def to_s
- '<LATE TIME>'
- end
- end
-
- LATE = LateTime.instance
-end
diff --git a/ruby_2_2/lib/rake/linked_list.rb b/ruby_2_2/lib/rake/linked_list.rb
deleted file mode 100644
index b5ab797808..0000000000
--- a/ruby_2_2/lib/rake/linked_list.rb
+++ /dev/null
@@ -1,103 +0,0 @@
-module Rake
-
- # Polylithic linked list structure used to implement several data
- # structures in Rake.
- class LinkedList
- include Enumerable
-
- attr_reader :head, :tail
-
- def initialize(head, tail=EMPTY)
- @head = head
- @tail = tail
- end
-
- # Polymorphically add a new element to the head of a list. The
- # type of head node will be the same list type as the tail.
- def conj(item)
- self.class.cons(item, self)
- end
-
- # Is the list empty?
- def empty?
- false
- end
-
- # Lists are structurally equivalent.
- def ==(other)
- current = self
- while ! current.empty? && ! other.empty?
- return false if current.head != other.head
- current = current.tail
- other = other.tail
- end
- current.empty? && other.empty?
- end
-
- # Convert to string: LL(item, item...)
- def to_s
- items = map { |item| item.to_s }.join(", ")
- "LL(#{items})"
- end
-
- # Same as +to_s+, but with inspected items.
- def inspect
- items = map { |item| item.inspect }.join(", ")
- "LL(#{items})"
- end
-
- # For each item in the list.
- def each
- current = self
- while ! current.empty?
- yield(current.head)
- current = current.tail
- end
- self
- end
-
- # Make a list out of the given arguments. This method is
- # polymorphic
- def self.make(*args)
- result = empty
- args.reverse_each do |item|
- result = cons(item, result)
- end
- result
- end
-
- # Cons a new head onto the tail list.
- def self.cons(head, tail)
- new(head, tail)
- end
-
- # The standard empty list class for the given LinkedList class.
- def self.empty
- self::EMPTY
- end
-
- # Represent an empty list, using the Null Object Pattern.
- #
- # When inheriting from the LinkedList class, you should implement
- # a type specific Empty class as well. Make sure you set the class
- # instance variable @parent to the associated list class (this
- # allows conj, cons and make to work polymorphically).
- class EmptyLinkedList < LinkedList
- @parent = LinkedList
-
- def initialize
- end
-
- def empty?
- true
- end
-
- def self.cons(head, tail)
- @parent.cons(head, tail)
- end
- end
-
- EMPTY = EmptyLinkedList.new
- end
-
-end
diff --git a/ruby_2_2/lib/rake/loaders/makefile.rb b/ruby_2_2/lib/rake/loaders/makefile.rb
deleted file mode 100644
index 4ece4323af..0000000000
--- a/ruby_2_2/lib/rake/loaders/makefile.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-module Rake
-
- # Makefile loader to be used with the import file loader.
- class MakefileLoader
- include Rake::DSL
-
- SPACE_MARK = "\0"
-
- # Load the makefile dependencies in +fn+.
- def load(fn)
- lines = File.read fn
- lines.gsub!(/\\ /, SPACE_MARK)
- lines.gsub!(/#[^\n]*\n/m, "")
- lines.gsub!(/\\\n/, ' ')
- lines.each_line do |line|
- process_line(line)
- end
- end
-
- private
-
- # Process one logical line of makefile data.
- def process_line(line)
- file_tasks, args = line.split(':', 2)
- return if args.nil?
- dependents = args.split.map { |d| respace(d) }
- file_tasks.scan(/\S+/) do |file_task|
- file_task = respace(file_task)
- file file_task => dependents
- end
- end
-
- def respace(str)
- str.tr SPACE_MARK, ' '
- end
- end
-
- # Install the handler
- Rake.application.add_loader('mf', MakefileLoader.new)
-end
diff --git a/ruby_2_2/lib/rake/multi_task.rb b/ruby_2_2/lib/rake/multi_task.rb
deleted file mode 100644
index 5418a7a7b0..0000000000
--- a/ruby_2_2/lib/rake/multi_task.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-module Rake
-
- # Same as a regular task, but the immediate prerequisites are done in
- # parallel using Ruby threads.
- #
- class MultiTask < Task
- private
- def invoke_prerequisites(task_args, invocation_chain) # :nodoc:
- invoke_prerequisites_concurrently(task_args, invocation_chain)
- end
- end
-
-end
diff --git a/ruby_2_2/lib/rake/name_space.rb b/ruby_2_2/lib/rake/name_space.rb
deleted file mode 100644
index 58f911e434..0000000000
--- a/ruby_2_2/lib/rake/name_space.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-##
-# The NameSpace class will lookup task names in the scope defined by a
-# +namespace+ command.
-
-class Rake::NameSpace
-
- ##
- # Create a namespace lookup object using the given task manager
- # and the list of scopes.
-
- def initialize(task_manager, scope_list)
- @task_manager = task_manager
- @scope = scope_list.dup
- end
-
- ##
- # Lookup a task named +name+ in the namespace.
-
- def [](name)
- @task_manager.lookup(name, @scope)
- end
-
- ##
- # The scope of the namespace (a LinkedList)
-
- def scope
- @scope.dup
- end
-
- ##
- # Return the list of tasks defined in this and nested namespaces.
-
- def tasks
- @task_manager.tasks_in_scope(@scope)
- end
-
-end
-
diff --git a/ruby_2_2/lib/rake/packagetask.rb b/ruby_2_2/lib/rake/packagetask.rb
deleted file mode 100644
index 249ee72b11..0000000000
--- a/ruby_2_2/lib/rake/packagetask.rb
+++ /dev/null
@@ -1,199 +0,0 @@
-# Define a package task library to aid in the definition of
-# redistributable package files.
-
-require 'rake'
-require 'rake/tasklib'
-
-module Rake
-
- # Create a packaging task that will package the project into
- # distributable files (e.g zip archive or tar files).
- #
- # The PackageTask will create the following targets:
- #
- # +:package+ ::
- # Create all the requested package files.
- #
- # +:clobber_package+ ::
- # Delete all the package files. This target is automatically
- # added to the main clobber target.
- #
- # +:repackage+ ::
- # Rebuild the package files from scratch, even if they are not out
- # of date.
- #
- # <tt>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tgz"</tt> ::
- # Create a gzipped tar package (if <em>need_tar</em> is true).
- #
- # <tt>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tar.gz"</tt> ::
- # Create a gzipped tar package (if <em>need_tar_gz</em> is true).
- #
- # <tt>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tar.bz2"</tt> ::
- # Create a bzip2'd tar package (if <em>need_tar_bz2</em> is true).
- #
- # <tt>"<em>package_dir</em>/<em>name</em>-<em>version</em>.zip"</tt> ::
- # Create a zip package archive (if <em>need_zip</em> is true).
- #
- # Example:
- #
- # Rake::PackageTask.new("rake", "1.2.3") do |p|
- # p.need_tar = true
- # p.package_files.include("lib/**/*.rb")
- # end
- #
- class PackageTask < TaskLib
- # Name of the package (from the GEM Spec).
- attr_accessor :name
-
- # Version of the package (e.g. '1.3.2').
- attr_accessor :version
-
- # Directory used to store the package files (default is 'pkg').
- attr_accessor :package_dir
-
- # True if a gzipped tar file (tgz) should be produced (default is
- # false).
- attr_accessor :need_tar
-
- # True if a gzipped tar file (tar.gz) should be produced (default
- # is false).
- attr_accessor :need_tar_gz
-
- # True if a bzip2'd tar file (tar.bz2) should be produced (default
- # is false).
- attr_accessor :need_tar_bz2
-
- # True if a zip file should be produced (default is false)
- attr_accessor :need_zip
-
- # List of files to be included in the package.
- attr_accessor :package_files
-
- # Tar command for gzipped or bzip2ed archives. The default is 'tar'.
- attr_accessor :tar_command
-
- # Zip command for zipped archives. The default is 'zip'.
- attr_accessor :zip_command
-
- # Create a Package Task with the given name and version. Use +:noversion+
- # as the version to build a package without a version or to provide a
- # fully-versioned package name.
-
- def initialize(name=nil, version=nil)
- init(name, version)
- yield self if block_given?
- define unless name.nil?
- end
-
- # Initialization that bypasses the "yield self" and "define" step.
- def init(name, version)
- @name = name
- @version = version
- @package_files = Rake::FileList.new
- @package_dir = 'pkg'
- @need_tar = false
- @need_tar_gz = false
- @need_tar_bz2 = false
- @need_zip = false
- @tar_command = 'tar'
- @zip_command = 'zip'
- end
-
- # Create the tasks defined by this task library.
- def define
- fail "Version required (or :noversion)" if @version.nil?
- @version = nil if :noversion == @version
-
- desc "Build all the packages"
- task :package
-
- desc "Force a rebuild of the package files"
- task :repackage => [:clobber_package, :package]
-
- desc "Remove package products"
- task :clobber_package do
- rm_r package_dir rescue nil
- end
-
- task :clobber => [:clobber_package]
-
- [
- [need_tar, tgz_file, "z"],
- [need_tar_gz, tar_gz_file, "z"],
- [need_tar_bz2, tar_bz2_file, "j"]
- ].each do |(need, file, flag)|
- if need
- task :package => ["#{package_dir}/#{file}"]
- file "#{package_dir}/#{file}" =>
- [package_dir_path] + package_files do
- chdir(package_dir) do
- sh @tar_command, "#{flag}cvf", file, package_name
- end
- end
- end
- end
-
- if need_zip
- task :package => ["#{package_dir}/#{zip_file}"]
- file "#{package_dir}/#{zip_file}" =>
- [package_dir_path] + package_files do
- chdir(package_dir) do
- sh @zip_command, "-r", zip_file, package_name
- end
- end
- end
-
- directory package_dir_path => @package_files do
- @package_files.each do |fn|
- f = File.join(package_dir_path, fn)
- fdir = File.dirname(f)
- mkdir_p(fdir) unless File.exist?(fdir)
- if File.directory?(fn)
- mkdir_p(f)
- else
- rm_f f
- safe_ln(fn, f)
- end
- end
- end
- self
- end
-
- # The name of this package
-
- def package_name
- @version ? "#{@name}-#{@version}" : @name
- end
-
- # The directory this package will be built in
-
- def package_dir_path
- "#{package_dir}/#{package_name}"
- end
-
- # The package name with .tgz added
-
- def tgz_file
- "#{package_name}.tgz"
- end
-
- # The package name with .tar.gz added
-
- def tar_gz_file
- "#{package_name}.tar.gz"
- end
-
- # The package name with .tar.bz2 added
-
- def tar_bz2_file
- "#{package_name}.tar.bz2"
- end
-
- # The package name with .zip added
-
- def zip_file
- "#{package_name}.zip"
- end
- end
-
-end
diff --git a/ruby_2_2/lib/rake/pathmap.rb b/ruby_2_2/lib/rake/pathmap.rb
deleted file mode 100644
index 9a840cda29..0000000000
--- a/ruby_2_2/lib/rake/pathmap.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-# TODO: Remove in Rake 11
-
-require 'rake/ext/string'
diff --git a/ruby_2_2/lib/rake/phony.rb b/ruby_2_2/lib/rake/phony.rb
deleted file mode 100644
index 29633ae066..0000000000
--- a/ruby_2_2/lib/rake/phony.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# Defines a :phony task that you can use as a dependency. This allows
-# file-based tasks to use non-file-based tasks as prerequisites
-# without forcing them to rebuild.
-#
-# See FileTask#out_of_date? and Task#timestamp for more info.
-
-require 'rake'
-
-task :phony
-
-Rake::Task[:phony].tap do |task|
- def task.timestamp # :nodoc:
- Time.at 0
- end
-end
diff --git a/ruby_2_2/lib/rake/private_reader.rb b/ruby_2_2/lib/rake/private_reader.rb
deleted file mode 100644
index 1620978576..0000000000
--- a/ruby_2_2/lib/rake/private_reader.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-module Rake
-
- # Include PrivateReader to use +private_reader+.
- module PrivateReader # :nodoc: all
-
- def self.included(base)
- base.extend(ClassMethods)
- end
-
- module ClassMethods
-
- # Declare a list of private accessors
- def private_reader(*names)
- attr_reader(*names)
- private(*names)
- end
- end
-
- end
-end
diff --git a/ruby_2_2/lib/rake/promise.rb b/ruby_2_2/lib/rake/promise.rb
deleted file mode 100644
index 31c4563476..0000000000
--- a/ruby_2_2/lib/rake/promise.rb
+++ /dev/null
@@ -1,99 +0,0 @@
-module Rake
-
- # A Promise object represents a promise to do work (a chore) in the
- # future. The promise is created with a block and a list of
- # arguments for the block. Calling value will return the value of
- # the promised chore.
- #
- # Used by ThreadPool.
- #
- class Promise # :nodoc: all
- NOT_SET = Object.new.freeze # :nodoc:
-
- attr_accessor :recorder
-
- # Create a promise to do the chore specified by the block.
- def initialize(args, &block)
- @mutex = Mutex.new
- @result = NOT_SET
- @error = NOT_SET
- @args = args
- @block = block
- end
-
- # Return the value of this promise.
- #
- # If the promised chore is not yet complete, then do the work
- # synchronously. We will wait.
- def value
- unless complete?
- stat :sleeping_on, :item_id => object_id
- @mutex.synchronize do
- stat :has_lock_on, :item_id => object_id
- chore
- stat :releasing_lock_on, :item_id => object_id
- end
- end
- error? ? raise(@error) : @result
- end
-
- # If no one else is working this promise, go ahead and do the chore.
- def work
- stat :attempting_lock_on, :item_id => object_id
- if @mutex.try_lock
- stat :has_lock_on, :item_id => object_id
- chore
- stat :releasing_lock_on, :item_id => object_id
- @mutex.unlock
- else
- stat :bailed_on, :item_id => object_id
- end
- end
-
- private
-
- # Perform the chore promised
- def chore
- if complete?
- stat :found_completed, :item_id => object_id
- return
- end
- stat :will_execute, :item_id => object_id
- begin
- @result = @block.call(*@args)
- rescue Exception => e
- @error = e
- end
- stat :did_execute, :item_id => object_id
- discard
- end
-
- # Do we have a result for the promise
- def result?
- ! @result.equal?(NOT_SET)
- end
-
- # Did the promise throw an error
- def error?
- ! @error.equal?(NOT_SET)
- end
-
- # Are we done with the promise
- def complete?
- result? || error?
- end
-
- # free up these items for the GC
- def discard
- @args = nil
- @block = nil
- end
-
- # Record execution statistics if there is a recorder
- def stat(*args)
- @recorder.call(*args) if @recorder
- end
-
- end
-
-end
diff --git a/ruby_2_2/lib/rake/pseudo_status.rb b/ruby_2_2/lib/rake/pseudo_status.rb
deleted file mode 100644
index 16e1903bd6..0000000000
--- a/ruby_2_2/lib/rake/pseudo_status.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-module Rake
-
- ##
- # Exit status class for times the system just gives us a nil.
- class PseudoStatus # :nodoc: all
- attr_reader :exitstatus
-
- def initialize(code=0)
- @exitstatus = code
- end
-
- def to_i
- @exitstatus << 8
- end
-
- def >>(n)
- to_i >> n
- end
-
- def stopped?
- false
- end
-
- def exited?
- true
- end
- end
-
-end
diff --git a/ruby_2_2/lib/rake/rake_module.rb b/ruby_2_2/lib/rake/rake_module.rb
deleted file mode 100644
index 3692753434..0000000000
--- a/ruby_2_2/lib/rake/rake_module.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-require 'rake/application'
-
-module Rake
-
- class << self
- # Current Rake Application
- def application
- @application ||= Rake::Application.new
- end
-
- # Set the current Rake application object.
- def application=(app)
- @application = app
- end
-
- def suggested_thread_count # :nodoc:
- @cpu_count ||= Rake::CpuCounter.count
- @cpu_count + 4
- end
-
- # Return the original directory where the Rake application was started.
- def original_dir
- application.original_dir
- end
-
- # Load a rakefile.
- def load_rakefile(path)
- load(path)
- end
-
- # Add files to the rakelib list
- def add_rakelib(*files)
- application.options.rakelib ||= []
- application.options.rakelib.concat(files)
- end
- end
-
-end
diff --git a/ruby_2_2/lib/rake/rake_test_loader.rb b/ruby_2_2/lib/rake/rake_test_loader.rb
deleted file mode 100644
index 7e3a6b3f35..0000000000
--- a/ruby_2_2/lib/rake/rake_test_loader.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-require 'rake'
-
-# Load the test files from the command line.
-argv = ARGV.select do |argument|
- case argument
- when /^-/ then
- argument
- when /\*/ then
- FileList[argument].to_a.each do |file|
- require File.expand_path file
- end
-
- false
- else
- require File.expand_path argument
-
- false
- end
-end
-
-ARGV.replace argv
-
diff --git a/ruby_2_2/lib/rake/rdoctask.rb b/ruby_2_2/lib/rake/rdoctask.rb
deleted file mode 100644
index 8d7df4f12b..0000000000
--- a/ruby_2_2/lib/rake/rdoctask.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-# TODO: Remove in Rake 11
-
-fail "ERROR: 'rake/rdoctask' is obsolete and no longer supported. " +
- "Use 'rdoc/task' (available in RDoc 2.4.2+) instead."
diff --git a/ruby_2_2/lib/rake/ruby182_test_unit_fix.rb b/ruby_2_2/lib/rake/ruby182_test_unit_fix.rb
deleted file mode 100644
index 40b30a6fde..0000000000
--- a/ruby_2_2/lib/rake/ruby182_test_unit_fix.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# TODO: Remove in rake 11
-
-# Local Rake override to fix bug in Ruby 0.8.2
-module Test # :nodoc:
- # Local Rake override to fix bug in Ruby 0.8.2
- module Unit # :nodoc:
- # Local Rake override to fix bug in Ruby 0.8.2
- module Collector # :nodoc:
- # Local Rake override to fix bug in Ruby 0.8.2
- class Dir # :nodoc:
- undef collect_file
- def collect_file(name, suites, already_gathered) # :nodoc:
- dir = File.dirname(File.expand_path(name))
- $:.unshift(dir) unless $:.first == dir
- if @req
- @req.require(name)
- else
- require(name)
- end
- find_test_cases(already_gathered).each do |t|
- add_suite(suites, t.suite)
- end
- ensure
- $:.delete_at $:.rindex(dir)
- end
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rake/rule_recursion_overflow_error.rb b/ruby_2_2/lib/rake/rule_recursion_overflow_error.rb
deleted file mode 100644
index da4318da9d..0000000000
--- a/ruby_2_2/lib/rake/rule_recursion_overflow_error.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-
-module Rake
-
- # Error indicating a recursion overflow error in task selection.
- class RuleRecursionOverflowError < StandardError
- def initialize(*args)
- super
- @targets = []
- end
-
- def add_target(target)
- @targets << target
- end
-
- def message
- super + ": [" + @targets.reverse.join(' => ') + "]"
- end
- end
-
-end
diff --git a/ruby_2_2/lib/rake/runtest.rb b/ruby_2_2/lib/rake/runtest.rb
deleted file mode 100644
index 4774b0e262..0000000000
--- a/ruby_2_2/lib/rake/runtest.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-require 'test/unit'
-require 'test/unit/assertions'
-require 'rake/file_list'
-
-module Rake
- include Test::Unit::Assertions
-
- ##
- # Deprecated way of running tests in process, but only for Test::Unit.
- #--
- # TODO: Remove in rake 11
-
- def run_tests(pattern='test/test*.rb', log_enabled=false) # :nodoc:
- FileList.glob(pattern).each do |fn|
- $stderr.puts fn if log_enabled
- begin
- require fn
- rescue Exception => ex
- $stderr.puts "Error in #{fn}: #{ex.message}"
- $stderr.puts ex.backtrace
- assert false
- end
- end
- end
-
- extend self
-end
diff --git a/ruby_2_2/lib/rake/scope.rb b/ruby_2_2/lib/rake/scope.rb
deleted file mode 100644
index dbefcea465..0000000000
--- a/ruby_2_2/lib/rake/scope.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-module Rake
- class Scope < LinkedList # :nodoc: all
-
- # Path for the scope.
- def path
- map { |item| item.to_s }.reverse.join(":")
- end
-
- # Path for the scope + the named path.
- def path_with_task_name(task_name)
- "#{path}:#{task_name}"
- end
-
- # Trim +n+ innermost scope levels from the scope. In no case will
- # this trim beyond the toplevel scope.
- def trim(n)
- result = self
- while n > 0 && ! result.empty?
- result = result.tail
- n -= 1
- end
- result
- end
-
- # Scope lists always end with an EmptyScope object. See Null
- # Object Pattern)
- class EmptyScope < EmptyLinkedList
- @parent = Scope
-
- def path
- ""
- end
-
- def path_with_task_name(task_name)
- task_name
- end
- end
-
- # Singleton null object for an empty scope.
- EMPTY = EmptyScope.new
- end
-end
diff --git a/ruby_2_2/lib/rake/task.rb b/ruby_2_2/lib/rake/task.rb
deleted file mode 100644
index 9bcf725523..0000000000
--- a/ruby_2_2/lib/rake/task.rb
+++ /dev/null
@@ -1,383 +0,0 @@
-require 'rake/invocation_exception_mixin'
-
-module Rake
-
- ##
- # A Task is the basic unit of work in a Rakefile. Tasks have associated
- # actions (possibly more than one) and a list of prerequisites. When
- # invoked, a task will first ensure that all of its prerequisites have an
- # opportunity to run and then it will execute its own actions.
- #
- # Tasks are not usually created directly using the new method, but rather
- # use the +file+ and +task+ convenience methods.
- #
- class Task
- # List of prerequisites for a task.
- attr_reader :prerequisites
-
- # List of actions attached to a task.
- attr_reader :actions
-
- # Application owning this task.
- attr_accessor :application
-
- # Array of nested namespaces names used for task lookup by this task.
- attr_reader :scope
-
- # File/Line locations of each of the task definitions for this
- # task (only valid if the task was defined with the detect
- # location option set).
- attr_reader :locations
-
- # Return task name
- def to_s
- name
- end
-
- def inspect # :nodoc:
- "<#{self.class} #{name} => [#{prerequisites.join(', ')}]>"
- end
-
- # List of sources for task.
- attr_writer :sources
- def sources
- if defined?(@sources)
- @sources
- else
- prerequisites
- end
- end
-
- # List of prerequisite tasks
- def prerequisite_tasks
- prerequisites.map { |pre| lookup_prerequisite(pre) }
- end
-
- def lookup_prerequisite(prerequisite_name) # :nodoc:
- application[prerequisite_name, @scope]
- end
- private :lookup_prerequisite
-
- # List of all unique prerequisite tasks including prerequisite tasks'
- # prerequisites.
- # Includes self when cyclic dependencies are found.
- def all_prerequisite_tasks
- seen = {}
- collect_prerequisites(seen)
- seen.values
- end
-
- def collect_prerequisites(seen) # :nodoc:
- prerequisite_tasks.each do |pre|
- next if seen[pre.name]
- seen[pre.name] = pre
- pre.collect_prerequisites(seen)
- end
- end
- protected :collect_prerequisites
-
- # First source from a rule (nil if no sources)
- def source
- sources.first
- end
-
- # Create a task named +task_name+ with no actions or prerequisites. Use
- # +enhance+ to add actions and prerequisites.
- def initialize(task_name, app)
- @name = task_name.to_s
- @prerequisites = []
- @actions = []
- @already_invoked = false
- @comments = []
- @lock = Monitor.new
- @application = app
- @scope = app.current_scope
- @arg_names = nil
- @locations = []
- end
-
- # Enhance a task with prerequisites or actions. Returns self.
- def enhance(deps=nil, &block)
- @prerequisites |= deps if deps
- @actions << block if block_given?
- self
- end
-
- # Name of the task, including any namespace qualifiers.
- def name
- @name.to_s
- end
-
- # Name of task with argument list description.
- def name_with_args # :nodoc:
- if arg_description
- "#{name}#{arg_description}"
- else
- name
- end
- end
-
- # Argument description (nil if none).
- def arg_description # :nodoc:
- @arg_names ? "[#{arg_names.join(',')}]" : nil
- end
-
- # Name of arguments for this task.
- def arg_names
- @arg_names || []
- end
-
- # Reenable the task, allowing its tasks to be executed if the task
- # is invoked again.
- def reenable
- @already_invoked = false
- end
-
- # Clear the existing prerequisites and actions of a rake task.
- def clear
- clear_prerequisites
- clear_actions
- clear_comments
- self
- end
-
- # Clear the existing prerequisites of a rake task.
- def clear_prerequisites
- prerequisites.clear
- self
- end
-
- # Clear the existing actions on a rake task.
- def clear_actions
- actions.clear
- self
- end
-
- # Clear the existing comments on a rake task.
- def clear_comments
- @comments = []
- self
- end
-
- # Invoke the task if it is needed. Prerequisites are invoked first.
- def invoke(*args)
- task_args = TaskArguments.new(arg_names, args)
- invoke_with_call_chain(task_args, InvocationChain::EMPTY)
- end
-
- # Same as invoke, but explicitly pass a call chain to detect
- # circular dependencies.
- def invoke_with_call_chain(task_args, invocation_chain) # :nodoc:
- new_chain = InvocationChain.append(self, invocation_chain)
- @lock.synchronize do
- if application.options.trace
- application.trace "** Invoke #{name} #{format_trace_flags}"
- end
- return if @already_invoked
- @already_invoked = true
- invoke_prerequisites(task_args, new_chain)
- execute(task_args) if needed?
- end
- rescue Exception => ex
- add_chain_to(ex, new_chain)
- raise ex
- end
- protected :invoke_with_call_chain
-
- def add_chain_to(exception, new_chain) # :nodoc:
- exception.extend(InvocationExceptionMixin) unless
- exception.respond_to?(:chain)
- exception.chain = new_chain if exception.chain.nil?
- end
- private :add_chain_to
-
- # Invoke all the prerequisites of a task.
- def invoke_prerequisites(task_args, invocation_chain) # :nodoc:
- if application.options.always_multitask
- invoke_prerequisites_concurrently(task_args, invocation_chain)
- else
- prerequisite_tasks.each { |p|
- prereq_args = task_args.new_scope(p.arg_names)
- p.invoke_with_call_chain(prereq_args, invocation_chain)
- }
- end
- end
-
- # Invoke all the prerequisites of a task in parallel.
- def invoke_prerequisites_concurrently(task_args, invocation_chain)# :nodoc:
- futures = prerequisite_tasks.map do |p|
- prereq_args = task_args.new_scope(p.arg_names)
- application.thread_pool.future(p) do |r|
- r.invoke_with_call_chain(prereq_args, invocation_chain)
- end
- end
- futures.each { |f| f.value }
- end
-
- # Format the trace flags for display.
- def format_trace_flags
- flags = []
- flags << "first_time" unless @already_invoked
- flags << "not_needed" unless needed?
- flags.empty? ? "" : "(" + flags.join(", ") + ")"
- end
- private :format_trace_flags
-
- # Execute the actions associated with this task.
- def execute(args=nil)
- args ||= EMPTY_TASK_ARGS
- if application.options.dryrun
- application.trace "** Execute (dry run) #{name}"
- return
- end
- application.trace "** Execute #{name}" if application.options.trace
- application.enhance_with_matching_rule(name) if @actions.empty?
- @actions.each do |act|
- case act.arity
- when 1
- act.call(self)
- else
- act.call(self, args)
- end
- end
- end
-
- # Is this task needed?
- def needed?
- true
- end
-
- # Timestamp for this task. Basic tasks return the current time for their
- # time stamp. Other tasks can be more sophisticated.
- def timestamp
- Time.now
- end
-
- # Add a description to the task. The description can consist of an option
- # argument list (enclosed brackets) and an optional comment.
- def add_description(description)
- return unless description
- comment = description.strip
- add_comment(comment) if comment && ! comment.empty?
- end
-
- def comment=(comment) # :nodoc:
- add_comment(comment)
- end
-
- def add_comment(comment) # :nodoc:
- return if comment.nil?
- @comments << comment unless @comments.include?(comment)
- end
- private :add_comment
-
- # Full collection of comments. Multiple comments are separated by
- # newlines.
- def full_comment
- transform_comments("\n")
- end
-
- # First line (or sentence) of all comments. Multiple comments are
- # separated by a "/".
- def comment
- transform_comments(" / ") { |c| first_sentence(c) }
- end
-
- # Transform the list of comments as specified by the block and
- # join with the separator.
- def transform_comments(separator, &block)
- if @comments.empty?
- nil
- else
- block ||= lambda { |c| c }
- @comments.map(&block).join(separator)
- end
- end
- private :transform_comments
-
- # Get the first sentence in a string. The sentence is terminated
- # by the first period or the end of the line. Decimal points do
- # not count as periods.
- def first_sentence(string)
- string.split(/\.[ \t]|\.$|\n/).first
- end
- private :first_sentence
-
- # Set the names of the arguments for this task. +args+ should be
- # an array of symbols, one for each argument name.
- def set_arg_names(args)
- @arg_names = args.map { |a| a.to_sym }
- end
-
- # Return a string describing the internal state of a task. Useful for
- # debugging.
- def investigation
- result = "------------------------------\n"
- result << "Investigating #{name}\n"
- result << "class: #{self.class}\n"
- result << "task needed: #{needed?}\n"
- result << "timestamp: #{timestamp}\n"
- result << "pre-requisites: \n"
- prereqs = prerequisite_tasks
- prereqs.sort! { |a, b| a.timestamp <=> b.timestamp }
- prereqs.each do |p|
- result << "--#{p.name} (#{p.timestamp})\n"
- end
- latest_prereq = prerequisite_tasks.map { |pre| pre.timestamp }.max
- result << "latest-prerequisite time: #{latest_prereq}\n"
- result << "................................\n\n"
- return result
- end
-
- # ----------------------------------------------------------------
- # Rake Module Methods
- #
- class << self
-
- # Clear the task list. This cause rake to immediately forget all the
- # tasks that have been assigned. (Normally used in the unit tests.)
- def clear
- Rake.application.clear
- end
-
- # List of all defined tasks.
- def tasks
- Rake.application.tasks
- end
-
- # Return a task with the given name. If the task is not currently
- # known, try to synthesize one from the defined rules. If no rules are
- # found, but an existing file matches the task name, assume it is a file
- # task with no dependencies or actions.
- def [](task_name)
- Rake.application[task_name]
- end
-
- # TRUE if the task name is already defined.
- def task_defined?(task_name)
- Rake.application.lookup(task_name) != nil
- end
-
- # Define a task given +args+ and an option block. If a rule with the
- # given name already exists, the prerequisites and actions are added to
- # the existing task. Returns the defined task.
- def define_task(*args, &block)
- Rake.application.define_task(self, *args, &block)
- end
-
- # Define a rule for synthesizing tasks.
- def create_rule(*args, &block)
- Rake.application.create_rule(*args, &block)
- end
-
- # Apply the scope to the task name according to the rules for
- # this kind of task. Generic tasks will accept the scope as
- # part of the name.
- def scope_name(scope, task_name)
-# (scope + [task_name]).join(':')
- scope.path_with_task_name(task_name)
- end
-
- end # class << Rake::Task
- end # class Rake::Task
-end
diff --git a/ruby_2_2/lib/rake/task_argument_error.rb b/ruby_2_2/lib/rake/task_argument_error.rb
deleted file mode 100644
index 3e1dda64db..0000000000
--- a/ruby_2_2/lib/rake/task_argument_error.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-module Rake
-
- # Error indicating an ill-formed task declaration.
- class TaskArgumentError < ArgumentError
- end
-
-end
diff --git a/ruby_2_2/lib/rake/task_arguments.rb b/ruby_2_2/lib/rake/task_arguments.rb
deleted file mode 100644
index fc0d657274..0000000000
--- a/ruby_2_2/lib/rake/task_arguments.rb
+++ /dev/null
@@ -1,98 +0,0 @@
-module Rake
-
- ##
- # TaskArguments manage the arguments passed to a task.
- #
- class TaskArguments
- include Enumerable
-
- # Argument names
- attr_reader :names
-
- # Create a TaskArgument object with a list of argument +names+ and a set
- # of associated +values+. +parent+ is the parent argument object.
- def initialize(names, values, parent=nil)
- @names = names
- @parent = parent
- @hash = {}
- @values = values
- names.each_with_index { |name, i|
- @hash[name.to_sym] = values[i] unless values[i].nil?
- }
- end
-
- # Retrieve the complete array of sequential values
- def to_a
- @values.dup
- end
-
- # Retrieve the list of values not associated with named arguments
- def extras
- @values[@names.length..-1] || []
- end
-
- # Create a new argument scope using the prerequisite argument
- # names.
- def new_scope(names)
- values = names.map { |n| self[n] }
- self.class.new(names, values + extras, self)
- end
-
- # Find an argument value by name or index.
- def [](index)
- lookup(index.to_sym)
- end
-
- # Specify a hash of default values for task arguments. Use the
- # defaults only if there is no specific value for the given
- # argument.
- def with_defaults(defaults)
- @hash = defaults.merge(@hash)
- end
-
- # Enumerates the arguments and their values
- def each(&block)
- @hash.each(&block)
- end
-
- # Extracts the argument values at +keys+
- def values_at(*keys)
- keys.map { |k| lookup(k) }
- end
-
- # Returns the value of the given argument via method_missing
- def method_missing(sym, *args)
- lookup(sym.to_sym)
- end
-
- # Returns a Hash of arguments and their values
- def to_hash
- @hash
- end
-
- def to_s # :nodoc:
- @hash.inspect
- end
-
- def inspect # :nodoc:
- to_s
- end
-
- # Returns true if +key+ is one of the arguments
- def has_key?(key)
- @hash.has_key?(key)
- end
-
- protected
-
- def lookup(name) # :nodoc:
- if @hash.has_key?(name)
- @hash[name]
- elsif @parent
- @parent.lookup(name)
- end
- end
- end
-
- EMPTY_TASK_ARGS = TaskArguments.new([], []) # :nodoc:
-end
diff --git a/ruby_2_2/lib/rake/task_manager.rb b/ruby_2_2/lib/rake/task_manager.rb
deleted file mode 100644
index cbb9f5ee2f..0000000000
--- a/ruby_2_2/lib/rake/task_manager.rb
+++ /dev/null
@@ -1,310 +0,0 @@
-module Rake
-
- # The TaskManager module is a mixin for managing tasks.
- module TaskManager
- # Track the last comment made in the Rakefile.
- attr_accessor :last_description
-
- # TODO: Remove in Rake 11
-
- alias :last_comment :last_description # :nodoc: Backwards compatibility
-
- def initialize # :nodoc:
- super
- @tasks = Hash.new
- @rules = Array.new
- @scope = Scope.make
- @last_description = nil
- end
-
- def create_rule(*args, &block) # :nodoc:
- pattern, args, deps = resolve_args(args)
- pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern
- @rules << [pattern, args, deps, block]
- end
-
- def define_task(task_class, *args, &block) # :nodoc:
- task_name, arg_names, deps = resolve_args(args)
-
- original_scope = @scope
- if String === task_name and
- not task_class.ancestors.include? Rake::FileTask then
- task_name, *definition_scope = *(task_name.split(":").reverse)
- @scope = Scope.make(*(definition_scope + @scope.to_a))
- end
-
- task_name = task_class.scope_name(@scope, task_name)
- deps = [deps] unless deps.respond_to?(:to_ary)
- deps = deps.map { |d| Rake.from_pathname(d).to_s }
- task = intern(task_class, task_name)
- task.set_arg_names(arg_names) unless arg_names.empty?
- if Rake::TaskManager.record_task_metadata
- add_location(task)
- task.add_description(get_description(task))
- end
- task.enhance(deps, &block)
- ensure
- @scope = original_scope
- end
-
- # Lookup a task. Return an existing task if found, otherwise
- # create a task of the current type.
- def intern(task_class, task_name)
- @tasks[task_name.to_s] ||= task_class.new(task_name, self)
- end
-
- # Find a matching task for +task_name+.
- def [](task_name, scopes=nil)
- task_name = task_name.to_s
- self.lookup(task_name, scopes) or
- enhance_with_matching_rule(task_name) or
- synthesize_file_task(task_name) or
- fail "Don't know how to build task '#{task_name}'"
- end
-
- def synthesize_file_task(task_name) # :nodoc:
- return nil unless File.exist?(task_name)
- define_task(Rake::FileTask, task_name)
- end
-
- # Resolve the arguments for a task/rule. Returns a triplet of
- # [task_name, arg_name_list, prerequisites].
- def resolve_args(args)
- if args.last.is_a?(Hash)
- deps = args.pop
- resolve_args_with_dependencies(args, deps)
- else
- resolve_args_without_dependencies(args)
- end
- end
-
- # Resolve task arguments for a task or rule when there are no
- # dependencies declared.
- #
- # The patterns recognized by this argument resolving function are:
- #
- # task :t
- # task :t, [:a]
- #
- def resolve_args_without_dependencies(args)
- task_name = args.shift
- if args.size == 1 && args.first.respond_to?(:to_ary)
- arg_names = args.first.to_ary
- else
- arg_names = args
- end
- [task_name, arg_names, []]
- end
- private :resolve_args_without_dependencies
-
- # Resolve task arguments for a task or rule when there are
- # dependencies declared.
- #
- # The patterns recognized by this argument resolving function are:
- #
- # task :t => [:d]
- # task :t, [a] => [:d]
- #
- def resolve_args_with_dependencies(args, hash) # :nodoc:
- fail "Task Argument Error" if hash.size != 1
- key, value = hash.map { |k, v| [k, v] }.first
- if args.empty?
- task_name = key
- arg_names = []
- deps = value || []
- else
- task_name = args.shift
- arg_names = key
- deps = value
- end
- deps = [deps] unless deps.respond_to?(:to_ary)
- [task_name, arg_names, deps]
- end
- private :resolve_args_with_dependencies
-
- # If a rule can be found that matches the task name, enhance the
- # task with the prerequisites and actions from the rule. Set the
- # source attribute of the task appropriately for the rule. Return
- # the enhanced task or nil of no rule was found.
- def enhance_with_matching_rule(task_name, level=0)
- fail Rake::RuleRecursionOverflowError,
- "Rule Recursion Too Deep" if level >= 16
- @rules.each do |pattern, args, extensions, block|
- if pattern.match(task_name)
- task = attempt_rule(task_name, args, extensions, block, level)
- return task if task
- end
- end
- nil
- rescue Rake::RuleRecursionOverflowError => ex
- ex.add_target(task_name)
- fail ex
- end
-
- # List of all defined tasks in this application.
- def tasks
- @tasks.values.sort_by { |t| t.name }
- end
-
- # List of all the tasks defined in the given scope (and its
- # sub-scopes).
- def tasks_in_scope(scope)
- prefix = scope.path
- tasks.select { |t|
- /^#{prefix}:/ =~ t.name
- }
- end
-
- # Clear all tasks in this application.
- def clear
- @tasks.clear
- @rules.clear
- end
-
- # Lookup a task, using scope and the scope hints in the task name.
- # This method performs straight lookups without trying to
- # synthesize file tasks or rules. Special scope names (e.g. '^')
- # are recognized. If no scope argument is supplied, use the
- # current scope. Return nil if the task cannot be found.
- def lookup(task_name, initial_scope=nil)
- initial_scope ||= @scope
- task_name = task_name.to_s
- if task_name =~ /^rake:/
- scopes = Scope.make
- task_name = task_name.sub(/^rake:/, '')
- elsif task_name =~ /^(\^+)/
- scopes = initial_scope.trim($1.size)
- task_name = task_name.sub(/^(\^+)/, '')
- else
- scopes = initial_scope
- end
- lookup_in_scope(task_name, scopes)
- end
-
- # Lookup the task name
- def lookup_in_scope(name, scope)
- loop do
- tn = scope.path_with_task_name(name)
- task = @tasks[tn]
- return task if task
- break if scope.empty?
- scope = scope.tail
- end
- nil
- end
- private :lookup_in_scope
-
- # Return the list of scope names currently active in the task
- # manager.
- def current_scope
- @scope
- end
-
- # Evaluate the block in a nested namespace named +name+. Create
- # an anonymous namespace if +name+ is nil.
- def in_namespace(name)
- name ||= generate_name
- @scope = Scope.new(name, @scope)
- ns = NameSpace.new(self, @scope)
- yield(ns)
- ns
- ensure
- @scope = @scope.tail
- end
-
- private
-
- # Add a location to the locations field of the given task.
- def add_location(task)
- loc = find_location
- task.locations << loc if loc
- task
- end
-
- # Find the location that called into the dsl layer.
- def find_location
- locations = caller
- i = 0
- while locations[i]
- return locations[i + 1] if locations[i] =~ /rake\/dsl_definition.rb/
- i += 1
- end
- nil
- end
-
- # Generate an anonymous namespace name.
- def generate_name
- @seed ||= 0
- @seed += 1
- "_anon_#{@seed}"
- end
-
- def trace_rule(level, message) # :nodoc:
- options.trace_output.puts "#{" " * level}#{message}" if
- Rake.application.options.trace_rules
- end
-
- # Attempt to create a rule given the list of prerequisites.
- def attempt_rule(task_name, args, extensions, block, level)
- sources = make_sources(task_name, extensions)
- prereqs = sources.map { |source|
- trace_rule level, "Attempting Rule #{task_name} => #{source}"
- if File.exist?(source) || Rake::Task.task_defined?(source)
- trace_rule level, "(#{task_name} => #{source} ... EXIST)"
- source
- elsif parent = enhance_with_matching_rule(source, level + 1)
- trace_rule level, "(#{task_name} => #{source} ... ENHANCE)"
- parent.name
- else
- trace_rule level, "(#{task_name} => #{source} ... FAIL)"
- return nil
- end
- }
- task = FileTask.define_task(task_name, {args => prereqs}, &block)
- task.sources = prereqs
- task
- end
-
- # Make a list of sources from the list of file name extensions /
- # translation procs.
- def make_sources(task_name, extensions)
- result = extensions.map { |ext|
- case ext
- when /%/
- task_name.pathmap(ext)
- when %r{/}
- ext
- when /^\./
- task_name.ext(ext)
- when String
- ext
- when Proc, Method
- if ext.arity == 1
- ext.call(task_name)
- else
- ext.call
- end
- else
- fail "Don't know how to handle rule dependent: #{ext.inspect}"
- end
- }
- result.flatten
- end
-
-
- private
-
- # Return the current description, clearing it in the process.
- def get_description(task)
- desc = @last_description
- @last_description = nil
- desc
- end
-
- class << self
- attr_accessor :record_task_metadata # :nodoc:
- TaskManager.record_task_metadata = false
- end
- end
-
-end
diff --git a/ruby_2_2/lib/rake/tasklib.rb b/ruby_2_2/lib/rake/tasklib.rb
deleted file mode 100644
index 6203d9402b..0000000000
--- a/ruby_2_2/lib/rake/tasklib.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require 'rake'
-
-module Rake
-
- # Base class for Task Libraries.
- class TaskLib
- include Cloneable
- include Rake::DSL
-
- # Make a symbol by pasting two strings together.
- #
- # NOTE: DEPRECATED! This method is kinda stupid. I don't know why
- # I didn't just use string interpolation. But now other task
- # libraries depend on this so I can't remove it without breaking
- # other people's code. So for now it stays for backwards
- # compatibility. BUT DON'T USE IT.
- #--
- # TODO: Remove in Rake 11
- def paste(a, b) # :nodoc:
- (a.to_s + b.to_s).intern
- end
- end
-
-end
diff --git a/ruby_2_2/lib/rake/testtask.rb b/ruby_2_2/lib/rake/testtask.rb
deleted file mode 100644
index 2daa589634..0000000000
--- a/ruby_2_2/lib/rake/testtask.rb
+++ /dev/null
@@ -1,212 +0,0 @@
-require 'rake'
-require 'rake/tasklib'
-
-module Rake
-
- # Create a task that runs a set of tests.
- #
- # Example:
- #
- # Rake::TestTask.new do |t|
- # t.libs << "test"
- # t.test_files = FileList['test/test*.rb']
- # t.verbose = true
- # end
- #
- # If rake is invoked with a "TEST=filename" command line option,
- # then the list of test files will be overridden to include only the
- # filename specified on the command line. This provides an easy way
- # to run just one test.
- #
- # If rake is invoked with a "TESTOPTS=options" command line option,
- # then the given options are passed to the test process after a
- # '--'. This allows Test::Unit options to be passed to the test
- # suite.
- #
- # Examples:
- #
- # rake test # run tests normally
- # rake test TEST=just_one_file.rb # run just one test file.
- # rake test TESTOPTS="-v" # run in verbose mode
- # rake test TESTOPTS="--runner=fox" # use the fox test runner
- #
- class TestTask < TaskLib
-
- # Name of test task. (default is :test)
- attr_accessor :name
-
- # List of directories to added to $LOAD_PATH before running the
- # tests. (default is 'lib')
- attr_accessor :libs
-
- # True if verbose test output desired. (default is false)
- attr_accessor :verbose
-
- # Test options passed to the test suite. An explicit
- # TESTOPTS=opts on the command line will override this. (default
- # is NONE)
- attr_accessor :options
-
- # Request that the tests be run with the warning flag set.
- # E.g. warning=true implies "ruby -w" used to run the tests.
- attr_accessor :warning
-
- # Glob pattern to match test files. (default is 'test/test*.rb')
- attr_accessor :pattern
-
- # Style of test loader to use. Options are:
- #
- # * :rake -- Rake provided test loading script (default).
- # * :testrb -- Ruby provided test loading script.
- # * :direct -- Load tests using command line loader.
- #
- attr_accessor :loader
-
- # Array of commandline options to pass to ruby when running test loader.
- attr_accessor :ruby_opts
-
- # Description of the test task. (default is 'Run tests')
- attr_accessor :description
-
- # Explicitly define the list of test files to be included in a
- # test. +list+ is expected to be an array of file names (a
- # FileList is acceptable). If both +pattern+ and +test_files+ are
- # used, then the list of test files is the union of the two.
- def test_files=(list)
- @test_files = list
- end
-
- # Create a testing task.
- def initialize(name=:test)
- @name = name
- @libs = ["lib"]
- @pattern = nil
- @options = nil
- @test_files = nil
- @verbose = false
- @warning = false
- @loader = :rake
- @ruby_opts = []
- @description = "Run tests" + (@name == :test ? "" : " for #{@name}")
- yield self if block_given?
- @pattern = 'test/test*.rb' if @pattern.nil? && @test_files.nil?
- define
- end
-
- # Create the tasks defined by this task lib.
- def define
- desc @description
- task @name do
- FileUtilsExt.verbose(@verbose) do
- args =
- "#{ruby_opts_string} #{run_code} " +
- "#{file_list_string} #{option_list}"
- ruby args do |ok, status|
- if !ok && status.respond_to?(:signaled?) && status.signaled?
- raise SignalException.new(status.termsig)
- elsif !ok
- fail "Command failed with status (#{status.exitstatus}): " +
- "[ruby #{args}]"
- end
- end
- end
- end
- self
- end
-
- def option_list # :nodoc:
- (ENV['TESTOPTS'] ||
- ENV['TESTOPT'] ||
- ENV['TEST_OPTS'] ||
- ENV['TEST_OPT'] ||
- @options ||
- "")
- end
-
- def ruby_opts_string # :nodoc:
- opts = @ruby_opts.dup
- opts.unshift("-I\"#{lib_path}\"") unless @libs.empty?
- opts.unshift("-w") if @warning
- opts.join(" ")
- end
-
- def lib_path # :nodoc:
- @libs.join(File::PATH_SEPARATOR)
- end
-
- def file_list_string # :nodoc:
- file_list.map { |fn| "\"#{fn}\"" }.join(' ')
- end
-
- def file_list # :nodoc:
- if ENV['TEST']
- FileList[ENV['TEST']]
- else
- result = []
- result += @test_files.to_a if @test_files
- result << @pattern if @pattern
- result
- end
- end
-
- def fix # :nodoc:
- case ruby_version
- when '1.8.2'
- "\"#{find_file 'rake/ruby182_test_unit_fix'}\""
- else
- nil
- end || ''
- end
-
- def ruby_version # :nodoc:
- RUBY_VERSION
- end
-
- def run_code # :nodoc:
- case @loader
- when :direct
- "-e \"ARGV.each{|f| require f}\""
- when :testrb
- "-S testrb #{fix}"
- when :rake
- "#{rake_include_arg} \"#{rake_loader}\""
- end
- end
-
- def rake_loader # :nodoc:
- find_file('rake/rake_test_loader') or
- fail "unable to find rake test loader"
- end
-
- def find_file(fn) # :nodoc:
- $LOAD_PATH.each do |path|
- file_path = File.join(path, "#{fn}.rb")
- return file_path if File.exist? file_path
- end
- nil
- end
-
- def rake_include_arg # :nodoc:
- spec = Gem.loaded_specs['rake']
- if spec.respond_to?(:default_gem?) && spec.default_gem?
- ""
- else
- "-I\"#{rake_lib_dir}\""
- end
- end
-
- def rake_lib_dir # :nodoc:
- find_dir('rake') or
- fail "unable to find rake lib"
- end
-
- def find_dir(fn) # :nodoc:
- $LOAD_PATH.each do |path|
- file_path = File.join(path, "#{fn}.rb")
- return path if File.exist? file_path
- end
- nil
- end
-
- end
-end
diff --git a/ruby_2_2/lib/rake/thread_history_display.rb b/ruby_2_2/lib/rake/thread_history_display.rb
deleted file mode 100644
index c2af9ecef5..0000000000
--- a/ruby_2_2/lib/rake/thread_history_display.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-require 'rake/private_reader'
-
-module Rake
-
- class ThreadHistoryDisplay # :nodoc: all
- include Rake::PrivateReader
-
- private_reader :stats, :items, :threads
-
- def initialize(stats)
- @stats = stats
- @items = { :_seq_ => 1 }
- @threads = { :_seq_ => "A" }
- end
-
- def show
- puts "Job History:"
- stats.each do |stat|
- stat[:data] ||= {}
- rename(stat, :thread, threads)
- rename(stat[:data], :item_id, items)
- rename(stat[:data], :new_thread, threads)
- rename(stat[:data], :deleted_thread, threads)
- printf("%8d %2s %-20s %s\n",
- (stat[:time] * 1_000_000).round,
- stat[:thread],
- stat[:event],
- stat[:data].map do |k, v| "#{k}:#{v}" end.join(" "))
- end
- end
-
- private
-
- def rename(hash, key, renames)
- if hash && hash[key]
- original = hash[key]
- value = renames[original]
- unless value
- value = renames[:_seq_]
- renames[:_seq_] = renames[:_seq_].succ
- renames[original] = value
- end
- hash[key] = value
- end
- end
- end
-
-end
diff --git a/ruby_2_2/lib/rake/thread_pool.rb b/ruby_2_2/lib/rake/thread_pool.rb
deleted file mode 100644
index d2ac6e7ac2..0000000000
--- a/ruby_2_2/lib/rake/thread_pool.rb
+++ /dev/null
@@ -1,164 +0,0 @@
-require 'thread'
-require 'set'
-
-require 'rake/promise'
-
-module Rake
-
- class ThreadPool # :nodoc: all
-
- # Creates a ThreadPool object. The +thread_count+ parameter is the size
- # of the pool.
- def initialize(thread_count)
- @max_active_threads = [thread_count, 0].max
- @threads = Set.new
- @threads_mon = Monitor.new
- @queue = Queue.new
- @join_cond = @threads_mon.new_cond
-
- @history_start_time = nil
- @history = []
- @history_mon = Monitor.new
- @total_threads_in_play = 0
- end
-
- # Creates a future executed by the +ThreadPool+.
- #
- # The args are passed to the block when executing (similarly to
- # Thread#new) The return value is an object representing
- # a future which has been created and added to the queue in the
- # pool. Sending #value to the object will sleep the
- # current thread until the future is finished and will return the
- # result (or raise an exception thrown from the future)
- def future(*args, &block)
- promise = Promise.new(args, &block)
- promise.recorder = lambda { |*stats| stat(*stats) }
-
- @queue.enq promise
- stat :queued, :item_id => promise.object_id
- start_thread
- promise
- end
-
- # Waits until the queue of futures is empty and all threads have exited.
- def join
- @threads_mon.synchronize do
- begin
- stat :joining
- @join_cond.wait unless @threads.empty?
- stat :joined
- rescue Exception => e
- stat :joined
- $stderr.puts e
- $stderr.print "Queue contains #{@queue.size} items. " +
- "Thread pool contains #{@threads.count} threads\n"
- $stderr.print "Current Thread #{Thread.current} status = " +
- "#{Thread.current.status}\n"
- $stderr.puts e.backtrace.join("\n")
- @threads.each do |t|
- $stderr.print "Thread #{t} status = #{t.status}\n"
- # 1.8 doesn't support Thread#backtrace
- $stderr.puts t.backtrace.join("\n") if t.respond_to? :backtrace
- end
- raise e
- end
- end
- end
-
- # Enable the gathering of history events.
- def gather_history #:nodoc:
- @history_start_time = Time.now if @history_start_time.nil?
- end
-
- # Return a array of history events for the thread pool.
- #
- # History gathering must be enabled to be able to see the events
- # (see #gather_history). Best to call this when the job is
- # complete (i.e. after ThreadPool#join is called).
- def history # :nodoc:
- @history_mon.synchronize { @history.dup }.
- sort_by { |i| i[:time] }.
- each { |i| i[:time] -= @history_start_time }
- end
-
- # Return a hash of always collected statistics for the thread pool.
- def statistics # :nodoc:
- {
- :total_threads_in_play => @total_threads_in_play,
- :max_active_threads => @max_active_threads,
- }
- end
-
- private
-
- # processes one item on the queue. Returns true if there was an
- # item to process, false if there was no item
- def process_queue_item #:nodoc:
- return false if @queue.empty?
-
- # Even though we just asked if the queue was empty, it
- # still could have had an item which by this statement
- # is now gone. For this reason we pass true to Queue#deq
- # because we will sleep indefinitely if it is empty.
- promise = @queue.deq(true)
- stat :dequeued, :item_id => promise.object_id
- promise.work
- return true
-
- rescue ThreadError # this means the queue is empty
- false
- end
-
- def safe_thread_count
- @threads_mon.synchronize do
- @threads.count
- end
- end
-
- def start_thread # :nodoc:
- @threads_mon.synchronize do
- next unless @threads.count < @max_active_threads
-
- t = Thread.new do
- begin
- while safe_thread_count <= @max_active_threads
- break unless process_queue_item
- end
- ensure
- @threads_mon.synchronize do
- @threads.delete Thread.current
- stat :ended, :thread_count => @threads.count
- @join_cond.broadcast if @threads.empty?
- end
- end
- end
-
- @threads << t
- stat(
- :spawned,
- :new_thread => t.object_id,
- :thread_count => @threads.count)
- @total_threads_in_play = @threads.count if
- @threads.count > @total_threads_in_play
- end
- end
-
- def stat(event, data=nil) # :nodoc:
- return if @history_start_time.nil?
- info = {
- :event => event,
- :data => data,
- :time => Time.now,
- :thread => Thread.current.object_id,
- }
- @history_mon.synchronize { @history << info }
- end
-
- # for testing only
-
- def __queue__ # :nodoc:
- @queue
- end
- end
-
-end
diff --git a/ruby_2_2/lib/rake/trace_output.rb b/ruby_2_2/lib/rake/trace_output.rb
deleted file mode 100644
index 396096d4df..0000000000
--- a/ruby_2_2/lib/rake/trace_output.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-module Rake
- module TraceOutput # :nodoc: all
-
- # Write trace output to output stream +out+.
- #
- # The write is done as a single IO call (to print) to lessen the
- # chance that the trace output is interrupted by other tasks also
- # producing output.
- def trace_on(out, *strings)
- sep = $\ || "\n"
- if strings.empty?
- output = sep
- else
- output = strings.map { |s|
- next if s.nil?
- s =~ /#{sep}$/ ? s : s + sep
- }.join
- end
- out.print(output)
- end
- end
-end
diff --git a/ruby_2_2/lib/rake/version.rb b/ruby_2_2/lib/rake/version.rb
deleted file mode 100644
index b9b1b2d485..0000000000
--- a/ruby_2_2/lib/rake/version.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-module Rake
- module Version # :nodoc: all
- MAJOR, MINOR, BUILD, *OTHER = Rake::VERSION.split '.'
-
- NUMBERS = [MAJOR, MINOR, BUILD, *OTHER]
- end
-end
diff --git a/ruby_2_2/lib/rake/win32.rb b/ruby_2_2/lib/rake/win32.rb
deleted file mode 100644
index 6b4873da2c..0000000000
--- a/ruby_2_2/lib/rake/win32.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-
-module Rake
- require 'rake/alt_system'
-
- # Win 32 interface methods for Rake. Windows specific functionality
- # will be placed here to collect that knowledge in one spot.
- module Win32 # :nodoc: all
-
- # Error indicating a problem in locating the home directory on a
- # Win32 system.
- class Win32HomeError < RuntimeError
- end
-
- class << self
- # True if running on a windows system.
- def windows?
- AltSystem::WINDOWS
- end
-
- # Run a command line on windows.
- def rake_system(*cmd)
- AltSystem.system(*cmd)
- end
-
- # The standard directory containing system wide rake files on
- # Win 32 systems. Try the following environment variables (in
- # order):
- #
- # * HOME
- # * HOMEDRIVE + HOMEPATH
- # * APPDATA
- # * USERPROFILE
- #
- # If the above are not defined, the return nil.
- def win32_system_dir #:nodoc:
- win32_shared_path = ENV['HOME']
- if win32_shared_path.nil? && ENV['HOMEDRIVE'] && ENV['HOMEPATH']
- win32_shared_path = ENV['HOMEDRIVE'] + ENV['HOMEPATH']
- end
-
- win32_shared_path ||= ENV['APPDATA']
- win32_shared_path ||= ENV['USERPROFILE']
- raise Win32HomeError,
- "Unable to determine home path environment variable." if
- win32_shared_path.nil? or win32_shared_path.empty?
- normalize(File.join(win32_shared_path, 'Rake'))
- end
-
- # Normalize a win32 path so that the slashes are all forward slashes.
- def normalize(path)
- path.gsub(/\\/, '/')
- end
-
- end
- end
-end
diff --git a/ruby_2_2/lib/rbconfig/.document b/ruby_2_2/lib/rbconfig/.document
deleted file mode 100644
index 4cea83cd0e..0000000000
--- a/ruby_2_2/lib/rbconfig/.document
+++ /dev/null
@@ -1 +0,0 @@
-# these files are obsolete
diff --git a/ruby_2_2/lib/rbconfig/datadir.rb b/ruby_2_2/lib/rbconfig/datadir.rb
deleted file mode 100644
index 9b7eabb473..0000000000
--- a/ruby_2_2/lib/rbconfig/datadir.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-# N.B. This file is used by Config.datadir in rubygems.rb, and must not be
-# removed before that require is removed. I require to avoid warning more than
-# once.
-
-warn 'rbconfig/datadir.rb and {Rb}Config.datadir is being deprecated from '\
- 'RubyGems. It will be removed completely on or after June 2011. If you '\
- 'wish to rely on a datadir, please use Gem.datadir.'
diff --git a/ruby_2_2/lib/rdoc.rb b/ruby_2_2/lib/rdoc.rb
deleted file mode 100644
index a99e5dc309..0000000000
--- a/ruby_2_2/lib/rdoc.rb
+++ /dev/null
@@ -1,185 +0,0 @@
-$DEBUG_RDOC = nil
-
-# :main: README.rdoc
-
-##
-# RDoc produces documentation for Ruby source files by parsing the source and
-# extracting the definition for classes, modules, methods, includes and
-# requires. It associates these with optional documentation contained in an
-# immediately preceding comment block then renders the result using an output
-# formatter.
-#
-# For a simple introduction to writing or generating documentation using RDoc
-# see the README.
-#
-# == Roadmap
-#
-# If you think you found a bug in RDoc see CONTRIBUTING@Bugs
-#
-# If you want to use RDoc to create documentation for your Ruby source files,
-# see RDoc::Markup and refer to <tt>rdoc --help</tt> for command line usage.
-#
-# If you want to set the default markup format see
-# RDoc::Markup@Supported+Formats
-#
-# If you want to store rdoc configuration in your gem (such as the default
-# markup format) see RDoc::Options@Saved+Options
-#
-# If you want to write documentation for Ruby files see RDoc::Parser::Ruby
-#
-# If you want to write documentation for extensions written in C see
-# RDoc::Parser::C
-#
-# If you want to generate documentation using <tt>rake</tt> see RDoc::Task.
-#
-# If you want to drive RDoc programmatically, see RDoc::RDoc.
-#
-# If you want to use the library to format text blocks into HTML or other
-# formats, look at RDoc::Markup.
-#
-# If you want to make an RDoc plugin such as a generator or directive handler
-# see RDoc::RDoc.
-#
-# If you want to write your own output generator see RDoc::Generator.
-#
-# If you want an overview of how RDoc works see CONTRIBUTING
-#
-# == Credits
-#
-# RDoc is currently being maintained by Eric Hodel <drbrain@segment7.net>.
-#
-# Dave Thomas <dave@pragmaticprogrammer.com> is the original author of RDoc.
-#
-# * The Ruby parser in rdoc/parse.rb is based heavily on the outstanding
-# work of Keiju ISHITSUKA of Nippon Rational Inc, who produced the Ruby
-# parser for irb and the rtags package.
-
-module RDoc
-
- ##
- # Exception thrown by any rdoc error.
-
- class Error < RuntimeError; end
-
- ##
- # RDoc version you are using
-
- VERSION = '4.2.0'
-
- ##
- # Method visibilities
-
- VISIBILITIES = [:public, :protected, :private]
-
- ##
- # Name of the dotfile that contains the description of files to be processed
- # in the current directory
-
- DOT_DOC_FILENAME = ".document"
-
- ##
- # General RDoc modifiers
-
- GENERAL_MODIFIERS = %w[nodoc].freeze
-
- ##
- # RDoc modifiers for classes
-
- CLASS_MODIFIERS = GENERAL_MODIFIERS
-
- ##
- # RDoc modifiers for attributes
-
- ATTR_MODIFIERS = GENERAL_MODIFIERS
-
- ##
- # RDoc modifiers for constants
-
- CONSTANT_MODIFIERS = GENERAL_MODIFIERS
-
- ##
- # RDoc modifiers for methods
-
- METHOD_MODIFIERS = GENERAL_MODIFIERS +
- %w[arg args yield yields notnew not-new not_new doc]
-
- ##
- # Loads the best available YAML library.
-
- def self.load_yaml
- begin
- gem 'psych'
- rescue Gem::LoadError
- end
-
- begin
- require 'psych'
- rescue ::LoadError
- ensure
- require 'yaml'
- end
- end
-
- autoload :RDoc, 'rdoc/rdoc'
-
- autoload :TestCase, 'rdoc/test_case'
-
- autoload :CrossReference, 'rdoc/cross_reference'
- autoload :ERBIO, 'rdoc/erbio'
- autoload :ERBPartial, 'rdoc/erb_partial'
- autoload :Encoding, 'rdoc/encoding'
- autoload :Generator, 'rdoc/generator'
- autoload :Options, 'rdoc/options'
- autoload :Parser, 'rdoc/parser'
- autoload :Servlet, 'rdoc/servlet'
- autoload :RI, 'rdoc/ri'
- autoload :Stats, 'rdoc/stats'
- autoload :Store, 'rdoc/store'
- autoload :Task, 'rdoc/task'
- autoload :Text, 'rdoc/text'
-
- autoload :Markdown, 'rdoc/markdown'
- autoload :Markup, 'rdoc/markup'
- autoload :RD, 'rdoc/rd'
- autoload :TomDoc, 'rdoc/tom_doc'
-
- autoload :KNOWN_CLASSES, 'rdoc/known_classes'
-
- autoload :RubyLex, 'rdoc/ruby_lex'
- autoload :RubyToken, 'rdoc/ruby_token'
- autoload :TokenStream, 'rdoc/token_stream'
-
- autoload :Comment, 'rdoc/comment'
-
- autoload :I18n, 'rdoc/i18n'
-
- # code objects
- #
- # We represent the various high-level code constructs that appear in Ruby
- # programs: classes, modules, methods, and so on.
- autoload :CodeObject, 'rdoc/code_object'
-
- autoload :Context, 'rdoc/context'
- autoload :TopLevel, 'rdoc/top_level'
-
- autoload :AnonClass, 'rdoc/anon_class'
- autoload :ClassModule, 'rdoc/class_module'
- autoload :NormalClass, 'rdoc/normal_class'
- autoload :NormalModule, 'rdoc/normal_module'
- autoload :SingleClass, 'rdoc/single_class'
-
- autoload :Alias, 'rdoc/alias'
- autoload :AnyMethod, 'rdoc/any_method'
- autoload :MethodAttr, 'rdoc/method_attr'
- autoload :GhostMethod, 'rdoc/ghost_method'
- autoload :MetaMethod, 'rdoc/meta_method'
- autoload :Attr, 'rdoc/attr'
-
- autoload :Constant, 'rdoc/constant'
- autoload :Mixin, 'rdoc/mixin'
- autoload :Include, 'rdoc/include'
- autoload :Extend, 'rdoc/extend'
- autoload :Require, 'rdoc/require'
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/alias.rb b/ruby_2_2/lib/rdoc/alias.rb
deleted file mode 100644
index 39d2694817..0000000000
--- a/ruby_2_2/lib/rdoc/alias.rb
+++ /dev/null
@@ -1,111 +0,0 @@
-##
-# Represent an alias, which is an old_name/new_name pair associated with a
-# particular context
-#--
-# TODO implement Alias as a proxy to a method/attribute, inheriting from
-# MethodAttr
-
-class RDoc::Alias < RDoc::CodeObject
-
- ##
- # Aliased method's name
-
- attr_reader :new_name
-
- alias name new_name
-
- ##
- # Aliasee method's name
-
- attr_reader :old_name
-
- ##
- # Is this an alias declared in a singleton context?
-
- attr_accessor :singleton
-
- ##
- # Source file token stream
-
- attr_reader :text
-
- ##
- # Creates a new Alias with a token stream of +text+ that aliases +old_name+
- # to +new_name+, has +comment+ and is a +singleton+ context.
-
- def initialize(text, old_name, new_name, comment, singleton = false)
- super()
-
- @text = text
- @singleton = singleton
- @old_name = old_name
- @new_name = new_name
- self.comment = comment
- end
-
- ##
- # Order by #singleton then #new_name
-
- def <=>(other)
- [@singleton ? 0 : 1, new_name] <=> [other.singleton ? 0 : 1, other.new_name]
- end
-
- ##
- # HTML fragment reference for this alias
-
- def aref
- type = singleton ? 'c' : 'i'
- "#alias-#{type}-#{html_name}"
- end
-
- ##
- # Full old name including namespace
-
- def full_old_name
- @full_name || "#{parent.name}#{pretty_old_name}"
- end
-
- ##
- # HTML id-friendly version of +#new_name+.
-
- def html_name
- CGI.escape(@new_name.gsub('-', '-2D')).gsub('%','-').sub(/^-/, '')
- end
-
- def inspect # :nodoc:
- parent_name = parent ? parent.name : '(unknown)'
- "#<%s:0x%x %s.alias_method %s, %s>" % [
- self.class, object_id,
- parent_name, @old_name, @new_name,
- ]
- end
-
- ##
- # '::' for the alias of a singleton method/attribute, '#' for instance-level.
-
- def name_prefix
- singleton ? '::' : '#'
- end
-
- ##
- # Old name with prefix '::' or '#'.
-
- def pretty_old_name
- "#{singleton ? '::' : '#'}#{@old_name}"
- end
-
- ##
- # New name with prefix '::' or '#'.
-
- def pretty_new_name
- "#{singleton ? '::' : '#'}#{@new_name}"
- end
-
- alias pretty_name pretty_new_name
-
- def to_s # :nodoc:
- "alias: #{self.new_name} -> #{self.pretty_old_name} in: #{parent}"
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/anon_class.rb b/ruby_2_2/lib/rdoc/anon_class.rb
deleted file mode 100644
index c23d8e5d96..0000000000
--- a/ruby_2_2/lib/rdoc/anon_class.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-##
-# An anonymous class like:
-#
-# c = Class.new do end
-#
-# AnonClass is currently not used.
-
-class RDoc::AnonClass < RDoc::ClassModule
-end
-
diff --git a/ruby_2_2/lib/rdoc/any_method.rb b/ruby_2_2/lib/rdoc/any_method.rb
deleted file mode 100644
index ae022d72f8..0000000000
--- a/ruby_2_2/lib/rdoc/any_method.rb
+++ /dev/null
@@ -1,316 +0,0 @@
-##
-# AnyMethod is the base class for objects representing methods
-
-class RDoc::AnyMethod < RDoc::MethodAttr
-
- ##
- # 2::
- # RDoc 4
- # Added calls_super
- # Added parent name and class
- # Added section title
- # 3::
- # RDoc 4.1
- # Added is_alias_for
-
- MARSHAL_VERSION = 3 # :nodoc:
-
- ##
- # Don't rename \#initialize to \::new
-
- attr_accessor :dont_rename_initialize
-
- ##
- # The C function that implements this method (if it was defined in a C file)
-
- attr_accessor :c_function
-
- ##
- # Different ways to call this method
-
- attr_reader :call_seq
-
- ##
- # Parameters for this method
-
- attr_accessor :params
-
- ##
- # If true this method uses +super+ to call a superclass version
-
- attr_accessor :calls_super
-
- include RDoc::TokenStream
-
- ##
- # Creates a new AnyMethod with a token stream +text+ and +name+
-
- def initialize text, name
- super
-
- @c_function = nil
- @dont_rename_initialize = false
- @token_stream = nil
- @calls_super = false
- @superclass_method = nil
- end
-
- ##
- # Adds +an_alias+ as an alias for this method in +context+.
-
- def add_alias an_alias, context = nil
- method = self.class.new an_alias.text, an_alias.new_name
-
- method.record_location an_alias.file
- method.singleton = self.singleton
- method.params = self.params
- method.visibility = self.visibility
- method.comment = an_alias.comment
- method.is_alias_for = self
- @aliases << method
- context.add_method method if context
- method
- end
-
- ##
- # Prefix for +aref+ is 'method'.
-
- def aref_prefix
- 'method'
- end
-
- ##
- # The call_seq or the param_seq with method name, if there is no call_seq.
- #
- # Use this for displaying a method's argument lists.
-
- def arglists
- if @call_seq then
- @call_seq
- elsif @params then
- "#{name}#{param_seq}"
- end
- end
-
- ##
- # Sets the different ways you can call this method. If an empty +call_seq+
- # is given nil is assumed.
- #
- # See also #param_seq
-
- def call_seq= call_seq
- return if call_seq.empty?
-
- @call_seq = call_seq
- end
-
- ##
- # Loads is_alias_for from the internal name. Returns nil if the alias
- # cannot be found.
-
- def is_alias_for # :nodoc:
- case @is_alias_for
- when RDoc::MethodAttr then
- @is_alias_for
- when Array then
- return nil unless @store
-
- klass_name, singleton, method_name = @is_alias_for
-
- return nil unless klass = @store.find_class_or_module(klass_name)
-
- @is_alias_for = klass.find_method method_name, singleton
- end
- end
-
- ##
- # Dumps this AnyMethod for use by ri. See also #marshal_load
-
- def marshal_dump
- aliases = @aliases.map do |a|
- [a.name, parse(a.comment)]
- end
-
- is_alias_for = [
- @is_alias_for.parent.full_name,
- @is_alias_for.singleton,
- @is_alias_for.name
- ] if @is_alias_for
-
- [ MARSHAL_VERSION,
- @name,
- full_name,
- @singleton,
- @visibility,
- parse(@comment),
- @call_seq,
- @block_params,
- aliases,
- @params,
- @file.relative_name,
- @calls_super,
- @parent.name,
- @parent.class,
- @section.title,
- is_alias_for,
- ]
- end
-
- ##
- # Loads this AnyMethod from +array+. For a loaded AnyMethod the following
- # methods will return cached values:
- #
- # * #full_name
- # * #parent_name
-
- def marshal_load array
- initialize_visibility
-
- @dont_rename_initialize = nil
- @token_stream = nil
- @aliases = []
- @parent = nil
- @parent_name = nil
- @parent_class = nil
- @section = nil
- @file = nil
-
- version = array[0]
- @name = array[1]
- @full_name = array[2]
- @singleton = array[3]
- @visibility = array[4]
- @comment = array[5]
- @call_seq = array[6]
- @block_params = array[7]
- # 8 handled below
- @params = array[9]
- # 10 handled below
- @calls_super = array[11]
- @parent_name = array[12]
- @parent_title = array[13]
- @section_title = array[14]
- @is_alias_for = array[15]
-
- array[8].each do |new_name, comment|
- add_alias RDoc::Alias.new(nil, @name, new_name, comment, @singleton)
- end
-
- @parent_name ||= if @full_name =~ /#/ then
- $`
- else
- name = @full_name.split('::')
- name.pop
- name.join '::'
- end
-
- @file = RDoc::TopLevel.new array[10] if version > 0
- end
-
- ##
- # Method name
- #
- # If the method has no assigned name, it extracts it from #call_seq.
-
- def name
- return @name if @name
-
- @name =
- @call_seq[/^.*?\.(\w+)/, 1] ||
- @call_seq[/^.*?(\w+)/, 1] ||
- @call_seq if @call_seq
- end
-
- ##
- # A list of this method's method and yield parameters. +call-seq+ params
- # are preferred over parsed method and block params.
-
- def param_list
- if @call_seq then
- params = @call_seq.split("\n").last
- params = params.sub(/.*?\((.*)\)/, '\1')
- params = params.sub(/(\{|do)\s*\|([^|]*)\|.*/, ',\2')
- elsif @params then
- params = @params.sub(/\((.*)\)/, '\1')
-
- params << ",#{@block_params}" if @block_params
- elsif @block_params then
- params = @block_params
- else
- return []
- end
-
- if @block_params then
- # If this method has explicit block parameters, remove any explicit
- # &block
- params.sub!(/,?\s*&\w+/, '')
- else
- params.sub!(/\&(\w+)/, '\1')
- end
-
- params = params.gsub(/\s+/, '').split(',').reject(&:empty?)
-
- params.map { |param| param.sub(/=.*/, '') }
- end
-
- ##
- # Pretty parameter list for this method. If the method's parameters were
- # given by +call-seq+ it is preferred over the parsed values.
-
- def param_seq
- if @call_seq then
- params = @call_seq.split("\n").last
- params = params.sub(/[^( ]+/, '')
- params = params.sub(/(\|[^|]+\|)\s*\.\.\.\s*(end|\})/, '\1 \2')
- elsif @params then
- params = @params.gsub(/\s*\#.*/, '')
- params = params.tr("\n", " ").squeeze(" ")
- params = "(#{params})" unless params[0] == ?(
- else
- params = ''
- end
-
- if @block_params then
- # If this method has explicit block parameters, remove any explicit
- # &block
- params.sub!(/,?\s*&\w+/, '')
-
- block = @block_params.gsub(/\s*\#.*/, '')
- block = block.tr("\n", " ").squeeze(" ")
- if block[0] == ?(
- block.sub!(/^\(/, '').sub!(/\)/, '')
- end
- params << " { |#{block}| ... }"
- end
-
- params
- end
-
- ##
- # Sets the store for this method and its referenced code objects.
-
- def store= store
- super
-
- @file = @store.add_file @file.full_name if @file
- end
-
- ##
- # For methods that +super+, find the superclass method that would be called.
-
- def superclass_method
- return unless @calls_super
- return @superclass_method if @superclass_method
-
- parent.each_ancestor do |ancestor|
- if method = ancestor.method_list.find { |m| m.name == @name } then
- @superclass_method = method
- break
- end
- end
-
- @superclass_method
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/attr.rb b/ruby_2_2/lib/rdoc/attr.rb
deleted file mode 100644
index 960e1d1107..0000000000
--- a/ruby_2_2/lib/rdoc/attr.rb
+++ /dev/null
@@ -1,175 +0,0 @@
-##
-# An attribute created by \#attr, \#attr_reader, \#attr_writer or
-# \#attr_accessor
-
-class RDoc::Attr < RDoc::MethodAttr
-
- ##
- # 3::
- # RDoc 4
- # Added parent name and class
- # Added section title
-
- MARSHAL_VERSION = 3 # :nodoc:
-
- ##
- # Is the attribute readable ('R'), writable ('W') or both ('RW')?
-
- attr_accessor :rw
-
- ##
- # Creates a new Attr with body +text+, +name+, read/write status +rw+ and
- # +comment+. +singleton+ marks this as a class attribute.
-
- def initialize(text, name, rw, comment, singleton = false)
- super text, name
-
- @rw = rw
- @singleton = singleton
- self.comment = comment
- end
-
- ##
- # Attributes are equal when their names, singleton and rw are identical
-
- def == other
- self.class == other.class and
- self.name == other.name and
- self.rw == other.rw and
- self.singleton == other.singleton
- end
-
- ##
- # Add +an_alias+ as an attribute in +context+.
-
- def add_alias(an_alias, context)
- new_attr = self.class.new(self.text, an_alias.new_name, self.rw,
- self.comment, self.singleton)
-
- new_attr.record_location an_alias.file
- new_attr.visibility = self.visibility
- new_attr.is_alias_for = self
- @aliases << new_attr
- context.add_attribute new_attr
- new_attr
- end
-
- ##
- # The #aref prefix for attributes
-
- def aref_prefix
- 'attribute'
- end
-
- ##
- # Attributes never call super. See RDoc::AnyMethod#calls_super
- #
- # An RDoc::Attr can show up in the method list in some situations (see
- # Gem::ConfigFile)
-
- def calls_super # :nodoc:
- false
- end
-
- ##
- # Returns attr_reader, attr_writer or attr_accessor as appropriate.
-
- def definition
- case @rw
- when 'RW' then 'attr_accessor'
- when 'R' then 'attr_reader'
- when 'W' then 'attr_writer'
- end
- end
-
- def inspect # :nodoc:
- alias_for = @is_alias_for ? " (alias for #{@is_alias_for.name})" : nil
- visibility = self.visibility
- visibility = "forced #{visibility}" if force_documentation
- "#<%s:0x%x %s %s (%s)%s>" % [
- self.class, object_id,
- full_name,
- rw,
- visibility,
- alias_for,
- ]
- end
-
- ##
- # Dumps this Attr for use by ri. See also #marshal_load
-
- def marshal_dump
- [ MARSHAL_VERSION,
- @name,
- full_name,
- @rw,
- @visibility,
- parse(@comment),
- singleton,
- @file.relative_name,
- @parent.full_name,
- @parent.class,
- @section.title
- ]
- end
-
- ##
- # Loads this Attr from +array+. For a loaded Attr the following
- # methods will return cached values:
- #
- # * #full_name
- # * #parent_name
-
- def marshal_load array
- initialize_visibility
-
- @aliases = []
- @parent = nil
- @parent_name = nil
- @parent_class = nil
- @section = nil
- @file = nil
-
- version = array[0]
- @name = array[1]
- @full_name = array[2]
- @rw = array[3]
- @visibility = array[4]
- @comment = array[5]
- @singleton = array[6] || false # MARSHAL_VERSION == 0
- # 7 handled below
- @parent_name = array[8]
- @parent_class = array[9]
- @section_title = array[10]
-
- @file = RDoc::TopLevel.new array[7] if version > 1
-
- @parent_name ||= @full_name.split('#', 2).first
- end
-
- def pretty_print q # :nodoc:
- q.group 2, "[#{self.class.name} #{full_name} #{rw} #{visibility}", "]" do
- unless comment.empty? then
- q.breakable
- q.text "comment:"
- q.breakable
- q.pp @comment
- end
- end
- end
-
- def to_s # :nodoc:
- "#{definition} #{name} in: #{parent}"
- end
-
- ##
- # Attributes do not have token streams.
- #
- # An RDoc::Attr can show up in the method list in some situations (see
- # Gem::ConfigFile)
-
- def token_stream # :nodoc:
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/class_module.rb b/ruby_2_2/lib/rdoc/class_module.rb
deleted file mode 100644
index 71566f050a..0000000000
--- a/ruby_2_2/lib/rdoc/class_module.rb
+++ /dev/null
@@ -1,799 +0,0 @@
-##
-# ClassModule is the base class for objects representing either a class or a
-# module.
-
-class RDoc::ClassModule < RDoc::Context
-
- ##
- # 1::
- # RDoc 3.7
- # * Added visibility, singleton and file to attributes
- # * Added file to constants
- # * Added file to includes
- # * Added file to methods
- # 2::
- # RDoc 3.13
- # * Added extends
- # 3::
- # RDoc 4.0
- # * Added sections
- # * Added in_files
- # * Added parent name
- # * Complete Constant dump
-
- MARSHAL_VERSION = 3 # :nodoc:
-
- ##
- # Constants that are aliases for this class or module
-
- attr_accessor :constant_aliases
-
- ##
- # Comment and the location it came from. Use #add_comment to add comments
-
- attr_accessor :comment_location
-
- attr_accessor :diagram # :nodoc:
-
- ##
- # Class or module this constant is an alias for
-
- attr_accessor :is_alias_for
-
- ##
- # Return a RDoc::ClassModule of class +class_type+ that is a copy
- # of module +module+. Used to promote modules to classes.
- #--
- # TODO move to RDoc::NormalClass (I think)
-
- def self.from_module class_type, mod
- klass = class_type.new mod.name
-
- mod.comment_location.each do |comment, location|
- klass.add_comment comment, location
- end
-
- klass.parent = mod.parent
- klass.section = mod.section
- klass.viewer = mod.viewer
-
- klass.attributes.concat mod.attributes
- klass.method_list.concat mod.method_list
- klass.aliases.concat mod.aliases
- klass.external_aliases.concat mod.external_aliases
- klass.constants.concat mod.constants
- klass.includes.concat mod.includes
- klass.extends.concat mod.extends
-
- klass.methods_hash.update mod.methods_hash
- klass.constants_hash.update mod.constants_hash
-
- klass.current_section = mod.current_section
- klass.in_files.concat mod.in_files
- klass.sections.concat mod.sections
- klass.unmatched_alias_lists = mod.unmatched_alias_lists
- klass.current_section = mod.current_section
- klass.visibility = mod.visibility
-
- klass.classes_hash.update mod.classes_hash
- klass.modules_hash.update mod.modules_hash
- klass.metadata.update mod.metadata
-
- klass.document_self = mod.received_nodoc ? nil : mod.document_self
- klass.document_children = mod.document_children
- klass.force_documentation = mod.force_documentation
- klass.done_documenting = mod.done_documenting
-
- # update the parent of all children
-
- (klass.attributes +
- klass.method_list +
- klass.aliases +
- klass.external_aliases +
- klass.constants +
- klass.includes +
- klass.extends +
- klass.classes +
- klass.modules).each do |obj|
- obj.parent = klass
- obj.full_name = nil
- end
-
- klass
- end
-
- ##
- # Creates a new ClassModule with +name+ with optional +superclass+
- #
- # This is a constructor for subclasses, and must never be called directly.
-
- def initialize(name, superclass = nil)
- @constant_aliases = []
- @diagram = nil
- @is_alias_for = nil
- @name = name
- @superclass = superclass
- @comment_location = [] # [[comment, location]]
-
- super()
- end
-
- ##
- # Adds +comment+ to this ClassModule's list of comments at +location+. This
- # method is preferred over #comment= since it allows ri data to be updated
- # across multiple runs.
-
- def add_comment comment, location
- return unless document_self
-
- original = comment
-
- comment = case comment
- when RDoc::Comment then
- comment.normalize
- else
- normalize_comment comment
- end
-
- @comment_location.delete_if { |(_, l)| l == location }
-
- @comment_location << [comment, location]
-
- self.comment = original
- end
-
- def add_things my_things, other_things # :nodoc:
- other_things.each do |group, things|
- my_things[group].each { |thing| yield false, thing } if
- my_things.include? group
-
- things.each do |thing|
- yield true, thing
- end
- end
- end
-
- ##
- # Ancestors list for this ClassModule: the list of included modules
- # (classes will add their superclass if any).
- #
- # Returns the included classes or modules, not the includes
- # themselves. The returned values are either String or
- # RDoc::NormalModule instances (see RDoc::Include#module).
- #
- # The values are returned in reverse order of their inclusion,
- # which is the order suitable for searching methods/attributes
- # in the ancestors. The superclass, if any, comes last.
-
- def ancestors
- includes.map { |i| i.module }.reverse
- end
-
- def aref_prefix # :nodoc:
- raise NotImplementedError, "missing aref_prefix for #{self.class}"
- end
-
- ##
- # HTML fragment reference for this module or class. See
- # RDoc::NormalClass#aref and RDoc::NormalModule#aref
-
- def aref
- "#{aref_prefix}-#{full_name}"
- end
-
- ##
- # Ancestors of this class or module only
-
- alias direct_ancestors ancestors
-
- ##
- # Clears the comment. Used by the Ruby parser.
-
- def clear_comment
- @comment = ''
- end
-
- ##
- # This method is deprecated, use #add_comment instead.
- #
- # Appends +comment+ to the current comment, but separated by a rule. Works
- # more like <tt>+=</tt>.
-
- def comment= comment # :nodoc:
- comment = case comment
- when RDoc::Comment then
- comment.normalize
- else
- normalize_comment comment
- end
-
- comment = "#{@comment}\n---\n#{comment}" unless @comment.empty?
-
- super comment
- end
-
- ##
- # Prepares this ClassModule for use by a generator.
- #
- # See RDoc::Store#complete
-
- def complete min_visibility
- update_aliases
- remove_nodoc_children
- update_includes
- remove_invisible min_visibility
- end
-
- ##
- # Does this ClassModule or any of its methods have document_self set?
-
- def document_self_or_methods
- document_self || method_list.any?{ |m| m.document_self }
- end
-
- ##
- # Does this class or module have a comment with content or is
- # #received_nodoc true?
-
- def documented?
- return true if @received_nodoc
- return false if @comment_location.empty?
- @comment_location.any? { |comment, _| not comment.empty? }
- end
-
- ##
- # Iterates the ancestors of this class or module for which an
- # RDoc::ClassModule exists.
-
- def each_ancestor # :yields: module
- return enum_for __method__ unless block_given?
-
- ancestors.each do |mod|
- next if String === mod
- next if self == mod
- yield mod
- end
- end
-
- ##
- # Looks for a symbol in the #ancestors. See Context#find_local_symbol.
-
- def find_ancestor_local_symbol symbol
- each_ancestor do |m|
- res = m.find_local_symbol(symbol)
- return res if res
- end
-
- nil
- end
-
- ##
- # Finds a class or module with +name+ in this namespace or its descendants
-
- def find_class_named name
- return self if full_name == name
- return self if @name == name
-
- @classes.values.find do |klass|
- next if klass == self
- klass.find_class_named name
- end
- end
-
- ##
- # Return the fully qualified name of this class or module
-
- def full_name
- @full_name ||= if RDoc::ClassModule === parent then
- "#{parent.full_name}::#{@name}"
- else
- @name
- end
- end
-
- ##
- # TODO: filter included items by #display?
-
- def marshal_dump # :nodoc:
- attrs = attributes.sort.map do |attr|
- next unless attr.display?
- [ attr.name, attr.rw,
- attr.visibility, attr.singleton, attr.file_name,
- ]
- end.compact
-
- method_types = methods_by_type.map do |type, visibilities|
- visibilities = visibilities.map do |visibility, methods|
- method_names = methods.map do |method|
- next unless method.display?
- [method.name, method.file_name]
- end.compact
-
- [visibility, method_names.uniq]
- end
-
- [type, visibilities]
- end
-
- [ MARSHAL_VERSION,
- @name,
- full_name,
- @superclass,
- parse(@comment_location),
- attrs,
- constants.select { |constant| constant.display? },
- includes.map do |incl|
- next unless incl.display?
- [incl.name, parse(incl.comment), incl.file_name]
- end.compact,
- method_types,
- extends.map do |ext|
- next unless ext.display?
- [ext.name, parse(ext.comment), ext.file_name]
- end.compact,
- @sections.values,
- @in_files.map do |tl|
- tl.relative_name
- end,
- parent.full_name,
- parent.class,
- ]
- end
-
- def marshal_load array # :nodoc:
- initialize_visibility
- initialize_methods_etc
- @current_section = nil
- @document_self = true
- @done_documenting = false
- @parent = nil
- @temporary_section = nil
- @visibility = nil
- @classes = {}
- @modules = {}
-
- @name = array[1]
- @full_name = array[2]
- @superclass = array[3]
- @comment = array[4]
-
- @comment_location = if RDoc::Markup::Document === @comment.parts.first then
- @comment
- else
- RDoc::Markup::Document.new @comment
- end
-
- array[5].each do |name, rw, visibility, singleton, file|
- singleton ||= false
- visibility ||= :public
-
- attr = RDoc::Attr.new nil, name, rw, nil, singleton
-
- add_attribute attr
- attr.visibility = visibility
- attr.record_location RDoc::TopLevel.new file
- end
-
- array[6].each do |constant, comment, file|
- case constant
- when RDoc::Constant then
- add_constant constant
- else
- constant = add_constant RDoc::Constant.new(constant, nil, comment)
- constant.record_location RDoc::TopLevel.new file
- end
- end
-
- array[7].each do |name, comment, file|
- incl = add_include RDoc::Include.new(name, comment)
- incl.record_location RDoc::TopLevel.new file
- end
-
- array[8].each do |type, visibilities|
- visibilities.each do |visibility, methods|
- @visibility = visibility
-
- methods.each do |name, file|
- method = RDoc::AnyMethod.new nil, name
- method.singleton = true if type == 'class'
- method.record_location RDoc::TopLevel.new file
- add_method method
- end
- end
- end
-
- array[9].each do |name, comment, file|
- ext = add_extend RDoc::Extend.new(name, comment)
- ext.record_location RDoc::TopLevel.new file
- end if array[9] # Support Marshal version 1
-
- sections = (array[10] || []).map do |section|
- [section.title, section]
- end
-
- @sections = Hash[*sections.flatten]
- @current_section = add_section nil
-
- @in_files = []
-
- (array[11] || []).each do |filename|
- record_location RDoc::TopLevel.new filename
- end
-
- @parent_name = array[12]
- @parent_class = array[13]
- end
-
- ##
- # Merges +class_module+ into this ClassModule.
- #
- # The data in +class_module+ is preferred over the receiver.
-
- def merge class_module
- @parent = class_module.parent
- @parent_name = class_module.parent_name
-
- other_document = parse class_module.comment_location
-
- if other_document then
- document = parse @comment_location
-
- document = document.merge other_document
-
- @comment = @comment_location = document
- end
-
- cm = class_module
- other_files = cm.in_files
-
- merge_collections attributes, cm.attributes, other_files do |add, attr|
- if add then
- add_attribute attr
- else
- @attributes.delete attr
- @methods_hash.delete attr.pretty_name
- end
- end
-
- merge_collections constants, cm.constants, other_files do |add, const|
- if add then
- add_constant const
- else
- @constants.delete const
- @constants_hash.delete const.name
- end
- end
-
- merge_collections includes, cm.includes, other_files do |add, incl|
- if add then
- add_include incl
- else
- @includes.delete incl
- end
- end
-
- @includes.uniq! # clean up
-
- merge_collections extends, cm.extends, other_files do |add, ext|
- if add then
- add_extend ext
- else
- @extends.delete ext
- end
- end
-
- @extends.uniq! # clean up
-
- merge_collections method_list, cm.method_list, other_files do |add, meth|
- if add then
- add_method meth
- else
- @method_list.delete meth
- @methods_hash.delete meth.pretty_name
- end
- end
-
- merge_sections cm
-
- self
- end
-
- ##
- # Merges collection +mine+ with +other+ preferring other. +other_files+ is
- # used to help determine which items should be deleted.
- #
- # Yields whether the item should be added or removed (true or false) and the
- # item to be added or removed.
- #
- # merge_collections things, other.things, other.in_files do |add, thing|
- # if add then
- # # add the thing
- # else
- # # remove the thing
- # end
- # end
-
- def merge_collections mine, other, other_files, &block # :nodoc:
- my_things = mine. group_by { |thing| thing.file }
- other_things = other.group_by { |thing| thing.file }
-
- remove_things my_things, other_files, &block
- add_things my_things, other_things, &block
- end
-
- ##
- # Merges the comments in this ClassModule with the comments in the other
- # ClassModule +cm+.
-
- def merge_sections cm # :nodoc:
- my_sections = sections.group_by { |section| section.title }
- other_sections = cm.sections.group_by { |section| section.title }
-
- other_files = cm.in_files
-
- remove_things my_sections, other_files do |_, section|
- @sections.delete section.title
- end
-
- other_sections.each do |group, sections|
- if my_sections.include? group
- my_sections[group].each do |my_section|
- other_section = cm.sections_hash[group]
-
- my_comments = my_section.comments
- other_comments = other_section.comments
-
- other_files = other_section.in_files
-
- merge_collections my_comments, other_comments, other_files do |add, comment|
- if add then
- my_section.add_comment comment
- else
- my_section.remove_comment comment
- end
- end
- end
- else
- sections.each do |section|
- add_section group, section.comments
- end
- end
- end
- end
-
- ##
- # Does this object represent a module?
-
- def module?
- false
- end
-
- ##
- # Allows overriding the initial name.
- #
- # Used for modules and classes that are constant aliases.
-
- def name= new_name
- @name = new_name
- end
-
- ##
- # Parses +comment_location+ into an RDoc::Markup::Document composed of
- # multiple RDoc::Markup::Documents with their file set.
-
- def parse comment_location
- case comment_location
- when String then
- super
- when Array then
- docs = comment_location.map do |comment, location|
- doc = super comment
- doc.file = location
- doc
- end
-
- RDoc::Markup::Document.new(*docs)
- when RDoc::Comment then
- doc = super comment_location.text, comment_location.format
- doc.file = comment_location.location
- doc
- when RDoc::Markup::Document then
- return comment_location
- else
- raise ArgumentError, "unknown comment class #{comment_location.class}"
- end
- end
-
- ##
- # Path to this class or module for use with HTML generator output.
-
- def path
- http_url @store.rdoc.generator.class_dir
- end
-
- ##
- # Name to use to generate the url:
- # modules and classes that are aliases for another
- # module or class return the name of the latter.
-
- def name_for_path
- is_alias_for ? is_alias_for.full_name : full_name
- end
-
- ##
- # Returns the classes and modules that are not constants
- # aliasing another class or module. For use by formatters
- # only (caches its result).
-
- def non_aliases
- @non_aliases ||= classes_and_modules.reject { |cm| cm.is_alias_for }
- end
-
- ##
- # Updates the child modules or classes of class/module +parent+ by
- # deleting the ones that have been removed from the documentation.
- #
- # +parent_hash+ is either <tt>parent.modules_hash</tt> or
- # <tt>parent.classes_hash</tt> and +all_hash+ is ::all_modules_hash or
- # ::all_classes_hash.
-
- def remove_nodoc_children
- prefix = self.full_name + '::'
-
- modules_hash.each_key do |name|
- full_name = prefix + name
- modules_hash.delete name unless @store.modules_hash[full_name]
- end
-
- classes_hash.each_key do |name|
- full_name = prefix + name
- classes_hash.delete name unless @store.classes_hash[full_name]
- end
- end
-
- def remove_things my_things, other_files # :nodoc:
- my_things.delete_if do |file, things|
- next false unless other_files.include? file
-
- things.each do |thing|
- yield false, thing
- end
-
- true
- end
- end
-
- ##
- # Search record used by RDoc::Generator::JsonIndex
-
- def search_record
- [
- name,
- full_name,
- full_name,
- '',
- path,
- '',
- snippet(@comment_location),
- ]
- end
-
- ##
- # Sets the store for this class or module and its contained code objects.
-
- def store= store
- super
-
- @attributes .each do |attr| attr.store = store end
- @constants .each do |const| const.store = store end
- @includes .each do |incl| incl.store = store end
- @extends .each do |ext| ext.store = store end
- @method_list.each do |meth| meth.store = store end
- end
-
- ##
- # Get the superclass of this class. Attempts to retrieve the superclass
- # object, returns the name if it is not known.
-
- def superclass
- @store.find_class_named(@superclass) || @superclass
- end
-
- ##
- # Set the superclass of this class to +superclass+
-
- def superclass=(superclass)
- raise NoMethodError, "#{full_name} is a module" if module?
- @superclass = superclass
- end
-
- def to_s # :nodoc:
- if is_alias_for then
- "#{self.class.name} #{self.full_name} -> #{is_alias_for}"
- else
- super
- end
- end
-
- ##
- # 'module' or 'class'
-
- def type
- module? ? 'module' : 'class'
- end
-
- ##
- # Updates the child modules & classes by replacing the ones that are
- # aliases through a constant.
- #
- # The aliased module/class is replaced in the children and in
- # RDoc::Store#modules_hash or RDoc::Store#classes_hash
- # by a copy that has <tt>RDoc::ClassModule#is_alias_for</tt> set to
- # the aliased module/class, and this copy is added to <tt>#aliases</tt>
- # of the aliased module/class.
- #
- # Formatters can use the #non_aliases method to retrieve children that
- # are not aliases, for instance to list the namespace content, since
- # the aliased modules are included in the constants of the class/module,
- # that are listed separately.
-
- def update_aliases
- constants.each do |const|
- next unless cm = const.is_alias_for
- cm_alias = cm.dup
- cm_alias.name = const.name
-
- # Don't move top-level aliases under Object, they look ugly there
- unless RDoc::TopLevel === cm_alias.parent then
- cm_alias.parent = self
- cm_alias.full_name = nil # force update for new parent
- end
-
- cm_alias.aliases.clear
- cm_alias.is_alias_for = cm
-
- if cm.module? then
- @store.modules_hash[cm_alias.full_name] = cm_alias
- modules_hash[const.name] = cm_alias
- else
- @store.classes_hash[cm_alias.full_name] = cm_alias
- classes_hash[const.name] = cm_alias
- end
-
- cm.aliases << cm_alias
- end
- end
-
- ##
- # Deletes from #includes those whose module has been removed from the
- # documentation.
- #--
- # FIXME: includes are not reliably removed, see _possible_bug test case
-
- def update_includes
- includes.reject! do |include|
- mod = include.module
- !(String === mod) && @store.modules_hash[mod.full_name].nil?
- end
-
- includes.uniq!
- end
-
- ##
- # Deletes from #extends those whose module has been removed from the
- # documentation.
- #--
- # FIXME: like update_includes, extends are not reliably removed
-
- def update_extends
- extends.reject! do |ext|
- mod = ext.module
-
- !(String === mod) && @store.modules_hash[mod.full_name].nil?
- end
-
- extends.uniq!
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/code_object.rb b/ruby_2_2/lib/rdoc/code_object.rb
deleted file mode 100644
index 4620fa586d..0000000000
--- a/ruby_2_2/lib/rdoc/code_object.rb
+++ /dev/null
@@ -1,429 +0,0 @@
-##
-# Base class for the RDoc code tree.
-#
-# We contain the common stuff for contexts (which are containers) and other
-# elements (methods, attributes and so on)
-#
-# Here's the tree of the CodeObject subclasses:
-#
-# * RDoc::Context
-# * RDoc::TopLevel
-# * RDoc::ClassModule
-# * RDoc::AnonClass (never used so far)
-# * RDoc::NormalClass
-# * RDoc::NormalModule
-# * RDoc::SingleClass
-# * RDoc::MethodAttr
-# * RDoc::Attr
-# * RDoc::AnyMethod
-# * RDoc::GhostMethod
-# * RDoc::MetaMethod
-# * RDoc::Alias
-# * RDoc::Constant
-# * RDoc::Mixin
-# * RDoc::Require
-# * RDoc::Include
-
-class RDoc::CodeObject
-
- include RDoc::Text
-
- ##
- # Our comment
-
- attr_reader :comment
-
- ##
- # Do we document our children?
-
- attr_reader :document_children
-
- ##
- # Do we document ourselves?
-
- attr_reader :document_self
-
- ##
- # Are we done documenting (ie, did we come across a :enddoc:)?
-
- attr_reader :done_documenting
-
- ##
- # Which file this code object was defined in
-
- attr_reader :file
-
- ##
- # Force documentation of this CodeObject
-
- attr_reader :force_documentation
-
- ##
- # Line in #file where this CodeObject was defined
-
- attr_accessor :line
-
- ##
- # Hash of arbitrary metadata for this CodeObject
-
- attr_reader :metadata
-
- ##
- # Offset in #file where this CodeObject was defined
- #--
- # TODO character or byte?
-
- attr_accessor :offset
-
- ##
- # Sets the parent CodeObject
-
- attr_writer :parent
-
- ##
- # Did we ever receive a +:nodoc:+ directive?
-
- attr_reader :received_nodoc
-
- ##
- # Set the section this CodeObject is in
-
- attr_writer :section
-
- ##
- # The RDoc::Store for this object.
-
- attr_reader :store
-
- ##
- # We are the model of the code, but we know that at some point we will be
- # worked on by viewers. By implementing the Viewable protocol, viewers can
- # associated themselves with these objects.
-
- attr_accessor :viewer
-
- ##
- # Creates a new CodeObject that will document itself and its children
-
- def initialize
- @metadata = {}
- @comment = ''
- @parent = nil
- @parent_name = nil # for loading
- @parent_class = nil # for loading
- @section = nil
- @section_title = nil # for loading
- @file = nil
- @full_name = nil
- @store = nil
- @track_visibility = true
-
- initialize_visibility
- end
-
- ##
- # Initializes state for visibility of this CodeObject and its children.
-
- def initialize_visibility # :nodoc:
- @document_children = true
- @document_self = true
- @done_documenting = false
- @force_documentation = false
- @received_nodoc = false
- @ignored = false
- @suppressed = false
- @track_visibility = true
- end
-
- ##
- # Replaces our comment with +comment+, unless it is empty.
-
- def comment=(comment)
- @comment = case comment
- when NilClass then ''
- when RDoc::Markup::Document then comment
- when RDoc::Comment then comment.normalize
- else
- if comment and not comment.empty? then
- normalize_comment comment
- else
- # HACK correct fix is to have #initialize create @comment
- # with the correct encoding
- if String === @comment and
- Object.const_defined? :Encoding and @comment.empty? then
- @comment.force_encoding comment.encoding
- end
- @comment
- end
- end
- end
-
- ##
- # Should this CodeObject be displayed in output?
- #
- # A code object should be displayed if:
- #
- # * The item didn't have a nodoc or wasn't in a container that had nodoc
- # * The item wasn't ignored
- # * The item has documentation and was not suppressed
-
- def display?
- @document_self and not @ignored and
- (documented? or not @suppressed)
- end
-
- ##
- # Enables or disables documentation of this CodeObject's children unless it
- # has been turned off by :enddoc:
-
- def document_children=(document_children)
- return unless @track_visibility
-
- @document_children = document_children unless @done_documenting
- end
-
- ##
- # Enables or disables documentation of this CodeObject unless it has been
- # turned off by :enddoc:. If the argument is +nil+ it means the
- # documentation is turned off by +:nodoc:+.
-
- def document_self=(document_self)
- return unless @track_visibility
- return if @done_documenting
-
- @document_self = document_self
- @received_nodoc = true if document_self.nil?
- end
-
- ##
- # Does this object have a comment with content or is #received_nodoc true?
-
- def documented?
- @received_nodoc or !@comment.empty?
- end
-
- ##
- # Turns documentation on/off, and turns on/off #document_self
- # and #document_children.
- #
- # Once documentation has been turned off (by +:enddoc:+),
- # the object will refuse to turn #document_self or
- # #document_children on, so +:doc:+ and +:start_doc:+ directives
- # will have no effect in the current file.
-
- def done_documenting=(value)
- return unless @track_visibility
- @done_documenting = value
- @document_self = !value
- @document_children = @document_self
- end
-
- ##
- # Yields each parent of this CodeObject. See also
- # RDoc::ClassModule#each_ancestor
-
- def each_parent
- code_object = self
-
- while code_object = code_object.parent do
- yield code_object
- end
-
- self
- end
-
- ##
- # File name where this CodeObject was found.
- #
- # See also RDoc::Context#in_files
-
- def file_name
- return unless @file
-
- @file.absolute_name
- end
-
- ##
- # Force the documentation of this object unless documentation
- # has been turned off by :enddoc:
- #--
- # HACK untested, was assigning to an ivar
-
- def force_documentation=(value)
- @force_documentation = value unless @done_documenting
- end
-
- ##
- # Sets the full_name overriding any computed full name.
- #
- # Set to +nil+ to clear RDoc's cached value
-
- def full_name= full_name
- @full_name = full_name
- end
-
- ##
- # Use this to ignore a CodeObject and all its children until found again
- # (#record_location is called). An ignored item will not be displayed in
- # documentation.
- #
- # See github issue #55
- #
- # The ignored status is temporary in order to allow implementation details
- # to be hidden. At the end of processing a file RDoc allows all classes
- # and modules to add new documentation to previously created classes.
- #
- # If a class was ignored (via stopdoc) then reopened later with additional
- # documentation it should be displayed. If a class was ignored and never
- # reopened it should not be displayed. The ignore flag allows this to
- # occur.
-
- def ignore
- return unless @track_visibility
-
- @ignored = true
-
- stop_doc
- end
-
- ##
- # Has this class been ignored?
- #
- # See also #ignore
-
- def ignored?
- @ignored
- end
-
- ##
- # The options instance from the store this CodeObject is attached to, or a
- # default options instance if the CodeObject is not attached.
- #
- # This is used by Text#snippet
-
- def options
- if @store and @store.rdoc then
- @store.rdoc.options
- else
- RDoc::Options.new
- end
- end
-
- ##
- # Our parent CodeObject. The parent may be missing for classes loaded from
- # legacy RI data stores.
-
- def parent
- return @parent if @parent
- return nil unless @parent_name
-
- if @parent_class == RDoc::TopLevel then
- @parent = @store.add_file @parent_name
- else
- @parent = @store.find_class_or_module @parent_name
-
- return @parent if @parent
-
- begin
- @parent = @store.load_class @parent_name
- rescue RDoc::Store::MissingFileError
- nil
- end
- end
- end
-
- ##
- # File name of our parent
-
- def parent_file_name
- @parent ? @parent.base_name : '(unknown)'
- end
-
- ##
- # Name of our parent
-
- def parent_name
- @parent ? @parent.full_name : '(unknown)'
- end
-
- ##
- # Records the RDoc::TopLevel (file) where this code object was defined
-
- def record_location top_level
- @ignored = false
- @suppressed = false
- @file = top_level
- end
-
- ##
- # The section this CodeObject is in. Sections allow grouping of constants,
- # attributes and methods inside a class or module.
-
- def section
- return @section if @section
-
- @section = parent.add_section @section_title if parent
- end
-
- ##
- # Enable capture of documentation unless documentation has been
- # turned off by :enddoc:
-
- def start_doc
- return if @done_documenting
-
- @document_self = true
- @document_children = true
- @ignored = false
- @suppressed = false
- end
-
- ##
- # Disable capture of documentation
-
- def stop_doc
- return unless @track_visibility
-
- @document_self = false
- @document_children = false
- end
-
- ##
- # Sets the +store+ that contains this CodeObject
-
- def store= store
- @store = store
-
- return unless @track_visibility
-
- if :nodoc == options.visibility then
- initialize_visibility
- @track_visibility = false
- end
- end
-
- ##
- # Use this to suppress a CodeObject and all its children until the next file
- # it is seen in or documentation is discovered. A suppressed item with
- # documentation will be displayed while an ignored item with documentation
- # may not be displayed.
-
- def suppress
- return unless @track_visibility
-
- @suppressed = true
-
- stop_doc
- end
-
- ##
- # Has this class been suppressed?
- #
- # See also #suppress
-
- def suppressed?
- @suppressed
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/code_objects.rb b/ruby_2_2/lib/rdoc/code_objects.rb
deleted file mode 100644
index f1a626cd2e..0000000000
--- a/ruby_2_2/lib/rdoc/code_objects.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-# This file was used to load all the RDoc::CodeObject subclasses at once. Now
-# autoload handles this.
-
-require 'rdoc'
-
diff --git a/ruby_2_2/lib/rdoc/comment.rb b/ruby_2_2/lib/rdoc/comment.rb
deleted file mode 100644
index 33ced18b5a..0000000000
--- a/ruby_2_2/lib/rdoc/comment.rb
+++ /dev/null
@@ -1,229 +0,0 @@
-##
-# A comment holds the text comment for a RDoc::CodeObject and provides a
-# unified way of cleaning it up and parsing it into an RDoc::Markup::Document.
-#
-# Each comment may have a different markup format set by #format=. By default
-# 'rdoc' is used. The :markup: directive tells RDoc which format to use.
-#
-# See RDoc::Markup@Other+directives for instructions on adding an alternate
-# format.
-
-class RDoc::Comment
-
- include RDoc::Text
-
- ##
- # The format of this comment. Defaults to RDoc::Markup
-
- attr_reader :format
-
- ##
- # The RDoc::TopLevel this comment was found in
-
- attr_accessor :location
-
- ##
- # For duck-typing when merging classes at load time
-
- alias file location # :nodoc:
-
- ##
- # The text for this comment
-
- attr_reader :text
-
- ##
- # Overrides the content returned by #parse. Use when there is no #text
- # source for this comment
-
- attr_writer :document
-
- ##
- # Creates a new comment with +text+ that is found in the RDoc::TopLevel
- # +location+.
-
- def initialize text = nil, location = nil
- @location = location
- @text = text
-
- @document = nil
- @format = 'rdoc'
- @normalized = false
- end
-
- ##
- #--
- # TODO deep copy @document
-
- def initialize_copy copy # :nodoc:
- @text = copy.text.dup
- end
-
- def == other # :nodoc:
- self.class === other and
- other.text == @text and other.location == @location
- end
-
- ##
- # Look for a 'call-seq' in the comment to override the normal parameter
- # handling. The :call-seq: is indented from the baseline. All lines of the
- # same indentation level and prefix are consumed.
- #
- # For example, all of the following will be used as the :call-seq:
- #
- # # :call-seq:
- # # ARGF.readlines(sep=$/) -> array
- # # ARGF.readlines(limit) -> array
- # # ARGF.readlines(sep, limit) -> array
- # #
- # # ARGF.to_a(sep=$/) -> array
- # # ARGF.to_a(limit) -> array
- # # ARGF.to_a(sep, limit) -> array
-
- def extract_call_seq method
- # we must handle situations like the above followed by an unindented first
- # comment. The difficulty is to make sure not to match lines starting
- # with ARGF at the same indent, but that are after the first description
- # paragraph.
- if @text =~ /^\s*:?call-seq:(.*?(?:\S).*?)^\s*$/m then
- all_start, all_stop = $~.offset(0)
- seq_start, seq_stop = $~.offset(1)
-
- # we get the following lines that start with the leading word at the
- # same indent, even if they have blank lines before
- if $1 =~ /(^\s*\n)+^(\s*\w+)/m then
- leading = $2 # ' * ARGF' in the example above
- re = %r%
- \A(
- (^\s*\n)+
- (^#{Regexp.escape leading}.*?\n)+
- )+
- ^\s*$
- %xm
-
- if @text[seq_stop..-1] =~ re then
- all_stop = seq_stop + $~.offset(0).last
- seq_stop = seq_stop + $~.offset(1).last
- end
- end
-
- seq = @text[seq_start..seq_stop]
- seq.gsub!(/^\s*(\S|\n)/m, '\1')
- @text.slice! all_start...all_stop
-
- method.call_seq = seq.chomp
-
- elsif @text.sub!(/^\s*:?call-seq:(.*?)(^\s*$|\z)/m, '') then
- seq = $1
- seq.gsub!(/^\s*/, '')
- method.call_seq = seq
- end
-
- method
- end
-
- ##
- # A comment is empty if its text String is empty.
-
- def empty?
- @text.empty?
- end
-
- ##
- # HACK dubious
-
- def force_encoding encoding
- @text.force_encoding encoding
- end
-
- ##
- # Sets the format of this comment and resets any parsed document
-
- def format= format
- @format = format
- @document = nil
- end
-
- def inspect # :nodoc:
- location = @location ? @location.relative_name : '(unknown)'
-
- "#<%s:%x %s %p>" % [self.class, object_id, location, @text]
- end
-
- ##
- # Normalizes the text. See RDoc::Text#normalize_comment for details
-
- def normalize
- return self unless @text
- return self if @normalized # TODO eliminate duplicate normalization
-
- @text = normalize_comment @text
-
- @normalized = true
-
- self
- end
-
- ##
- # Was this text normalized?
-
- def normalized? # :nodoc:
- @normalized
- end
-
- ##
- # Parses the comment into an RDoc::Markup::Document. The parsed document is
- # cached until the text is changed.
-
- def parse
- return @document if @document
-
- @document = super @text, @format
- @document.file = @location
- @document
- end
-
- ##
- # Removes private sections from this comment. Private sections are flush to
- # the comment marker and start with <tt>--</tt> and end with <tt>++</tt>.
- # For C-style comments, a private marker may not start at the opening of the
- # comment.
- #
- # /*
- # *--
- # * private
- # *++
- # * public
- # */
-
- def remove_private
- # Workaround for gsub encoding for Ruby 1.9.2 and earlier
- empty = ''
- empty.force_encoding @text.encoding if Object.const_defined? :Encoding
-
- @text = @text.gsub(%r%^\s*([#*]?)--.*?^\s*(\1)\+\+\n?%m, empty)
- @text = @text.sub(%r%^\s*[#*]?--.*%m, '')
- end
-
- ##
- # Replaces this comment's text with +text+ and resets the parsed document.
- #
- # An error is raised if the comment contains a document but no text.
-
- def text= text
- raise RDoc::Error, 'replacing document-only comment is not allowed' if
- @text.nil? and @document
-
- @document = nil
- @text = text
- end
-
- ##
- # Returns true if this comment is in TomDoc format.
-
- def tomdoc?
- @format == 'tomdoc'
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/constant.rb b/ruby_2_2/lib/rdoc/constant.rb
deleted file mode 100644
index 97985cbf99..0000000000
--- a/ruby_2_2/lib/rdoc/constant.rb
+++ /dev/null
@@ -1,186 +0,0 @@
-##
-# A constant
-
-class RDoc::Constant < RDoc::CodeObject
-
- MARSHAL_VERSION = 0 # :nodoc:
-
- ##
- # Sets the module or class this is constant is an alias for.
-
- attr_writer :is_alias_for
-
- ##
- # The constant's name
-
- attr_accessor :name
-
- ##
- # The constant's value
-
- attr_accessor :value
-
- ##
- # The constant's visibility
-
- attr_accessor :visibility
-
- ##
- # Creates a new constant with +name+, +value+ and +comment+
-
- def initialize(name, value, comment)
- super()
-
- @name = name
- @value = value
-
- @is_alias_for = nil
- @visibility = nil
-
- self.comment = comment
- end
-
- ##
- # Constants are ordered by name
-
- def <=> other
- return unless self.class === other
-
- [parent_name, name] <=> [other.parent_name, other.name]
- end
-
- ##
- # Constants are equal when their #parent and #name is the same
-
- def == other
- self.class == other.class and
- @parent == other.parent and
- @name == other.name
- end
-
- ##
- # A constant is documented if it has a comment, or is an alias
- # for a documented class or module.
-
- def documented?
- return true if super
- return false unless @is_alias_for
- case @is_alias_for
- when String then
- found = @store.find_class_or_module @is_alias_for
- return false unless found
- @is_alias_for = found
- end
- @is_alias_for.documented?
- end
-
- ##
- # Full constant name including namespace
-
- def full_name
- @full_name ||= "#{parent_name}::#{@name}"
- end
-
- ##
- # The module or class this constant is an alias for
-
- def is_alias_for
- case @is_alias_for
- when String then
- found = @store.find_class_or_module @is_alias_for
- @is_alias_for = found if found
- @is_alias_for
- else
- @is_alias_for
- end
- end
-
- def inspect # :nodoc:
- "#<%s:0x%x %s::%s>" % [
- self.class, object_id,
- parent_name, @name,
- ]
- end
-
- ##
- # Dumps this Constant for use by ri. See also #marshal_load
-
- def marshal_dump
- alias_name = case found = is_alias_for
- when RDoc::CodeObject then found.full_name
- else found
- end
-
- [ MARSHAL_VERSION,
- @name,
- full_name,
- @visibility,
- alias_name,
- parse(@comment),
- @file.relative_name,
- parent.name,
- parent.class,
- section.title,
- ]
- end
-
- ##
- # Loads this Constant from +array+. For a loaded Constant the following
- # methods will return cached values:
- #
- # * #full_name
- # * #parent_name
-
- def marshal_load array
- initialize array[1], nil, array[5]
-
- @full_name = array[2]
- @visibility = array[3]
- @is_alias_for = array[4]
- # 5 handled above
- # 6 handled below
- @parent_name = array[7]
- @parent_class = array[8]
- @section_title = array[9]
-
- @file = RDoc::TopLevel.new array[6]
- end
-
- ##
- # Path to this constant for use with HTML generator output.
-
- def path
- "#{@parent.path}##{@name}"
- end
-
- def pretty_print q # :nodoc:
- q.group 2, "[#{self.class.name} #{full_name}", "]" do
- unless comment.empty? then
- q.breakable
- q.text "comment:"
- q.breakable
- q.pp @comment
- end
- end
- end
-
- ##
- # Sets the store for this class or module and its contained code objects.
-
- def store= store
- super
-
- @file = @store.add_file @file.full_name if @file
- end
-
- def to_s # :nodoc:
- parent_name = parent ? parent.full_name : '(unknown)'
- if is_alias_for
- "constant #{parent_name}::#@name -> #{is_alias_for}"
- else
- "constant #{parent_name}::#@name"
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/context.rb b/ruby_2_2/lib/rdoc/context.rb
deleted file mode 100644
index 5eb86ddc92..0000000000
--- a/ruby_2_2/lib/rdoc/context.rb
+++ /dev/null
@@ -1,1211 +0,0 @@
-require 'cgi'
-
-##
-# A Context is something that can hold modules, classes, methods, attributes,
-# aliases, requires, and includes. Classes, modules, and files are all
-# Contexts.
-
-class RDoc::Context < RDoc::CodeObject
-
- include Comparable
-
- ##
- # Types of methods
-
- TYPES = %w[class instance]
-
- ##
- # If a context has these titles it will be sorted in this order.
-
- TOMDOC_TITLES = [nil, 'Public', 'Internal', 'Deprecated'] # :nodoc:
- TOMDOC_TITLES_SORT = TOMDOC_TITLES.sort_by { |title| title.to_s } # :nodoc:
-
- ##
- # Class/module aliases
-
- attr_reader :aliases
-
- ##
- # All attr* methods
-
- attr_reader :attributes
-
- ##
- # Block params to be used in the next MethodAttr parsed under this context
-
- attr_accessor :block_params
-
- ##
- # Constants defined
-
- attr_reader :constants
-
- ##
- # Sets the current documentation section of documentation
-
- attr_writer :current_section
-
- ##
- # Files this context is found in
-
- attr_reader :in_files
-
- ##
- # Modules this context includes
-
- attr_reader :includes
-
- ##
- # Modules this context is extended with
-
- attr_reader :extends
-
- ##
- # Methods defined in this context
-
- attr_reader :method_list
-
- ##
- # Name of this class excluding namespace. See also full_name
-
- attr_reader :name
-
- ##
- # Files this context requires
-
- attr_reader :requires
-
- ##
- # Use this section for the next method, attribute or constant added.
-
- attr_accessor :temporary_section
-
- ##
- # Hash <tt>old_name => [aliases]</tt>, for aliases
- # that haven't (yet) been resolved to a method/attribute.
- # (Not to be confused with the aliases of the context.)
-
- attr_accessor :unmatched_alias_lists
-
- ##
- # Aliases that could not be resolved.
-
- attr_reader :external_aliases
-
- ##
- # Current visibility of this context
-
- attr_accessor :visibility
-
- ##
- # Hash of registered methods. Attributes are also registered here,
- # twice if they are RW.
-
- attr_reader :methods_hash
-
- ##
- # Params to be used in the next MethodAttr parsed under this context
-
- attr_accessor :params
-
- ##
- # Hash of registered constants.
-
- attr_reader :constants_hash
-
- ##
- # Creates an unnamed empty context with public current visibility
-
- def initialize
- super
-
- @in_files = []
-
- @name ||= "unknown"
- @parent = nil
- @visibility = :public
-
- @current_section = Section.new self, nil, nil
- @sections = { nil => @current_section }
- @temporary_section = nil
-
- @classes = {}
- @modules = {}
-
- initialize_methods_etc
- end
-
- ##
- # Sets the defaults for methods and so-forth
-
- def initialize_methods_etc
- @method_list = []
- @attributes = []
- @aliases = []
- @requires = []
- @includes = []
- @extends = []
- @constants = []
- @external_aliases = []
-
- # This Hash maps a method name to a list of unmatched aliases (aliases of
- # a method not yet encountered).
- @unmatched_alias_lists = {}
-
- @methods_hash = {}
- @constants_hash = {}
-
- @params = nil
-
- @store ||= nil
- end
-
- ##
- # Contexts are sorted by full_name
-
- def <=>(other)
- return nil unless RDoc::CodeObject === other
-
- full_name <=> other.full_name
- end
-
- ##
- # Adds an item of type +klass+ with the given +name+ and +comment+ to the
- # context.
- #
- # Currently only RDoc::Extend and RDoc::Include are supported.
-
- def add klass, name, comment
- if RDoc::Extend == klass then
- ext = RDoc::Extend.new name, comment
- add_extend ext
- elsif RDoc::Include == klass then
- incl = RDoc::Include.new name, comment
- add_include incl
- else
- raise NotImplementedError, "adding a #{klass} is not implemented"
- end
- end
-
- ##
- # Adds +an_alias+ that is automatically resolved
-
- def add_alias an_alias
- return an_alias unless @document_self
-
- method_attr = find_method(an_alias.old_name, an_alias.singleton) ||
- find_attribute(an_alias.old_name, an_alias.singleton)
-
- if method_attr then
- method_attr.add_alias an_alias, self
- else
- add_to @external_aliases, an_alias
- unmatched_alias_list =
- @unmatched_alias_lists[an_alias.pretty_old_name] ||= []
- unmatched_alias_list.push an_alias
- end
-
- an_alias
- end
-
- ##
- # Adds +attribute+ if not already there. If it is (as method(s) or attribute),
- # updates the comment if it was empty.
- #
- # The attribute is registered only if it defines a new method.
- # For instance, <tt>attr_reader :foo</tt> will not be registered
- # if method +foo+ exists, but <tt>attr_accessor :foo</tt> will be registered
- # if method +foo+ exists, but <tt>foo=</tt> does not.
-
- def add_attribute attribute
- return attribute unless @document_self
-
- # mainly to check for redefinition of an attribute as a method
- # TODO find a policy for 'attr_reader :foo' + 'def foo=()'
- register = false
-
- key = nil
-
- if attribute.rw.index 'R' then
- key = attribute.pretty_name
- known = @methods_hash[key]
-
- if known then
- known.comment = attribute.comment if known.comment.empty?
- elsif registered = @methods_hash[attribute.pretty_name << '='] and
- RDoc::Attr === registered then
- registered.rw = 'RW'
- else
- @methods_hash[key] = attribute
- register = true
- end
- end
-
- if attribute.rw.index 'W' then
- key = attribute.pretty_name << '='
- known = @methods_hash[key]
-
- if known then
- known.comment = attribute.comment if known.comment.empty?
- elsif registered = @methods_hash[attribute.pretty_name] and
- RDoc::Attr === registered then
- registered.rw = 'RW'
- else
- @methods_hash[key] = attribute
- register = true
- end
- end
-
- if register then
- attribute.visibility = @visibility
- add_to @attributes, attribute
- resolve_aliases attribute
- end
-
- attribute
- end
-
- ##
- # Adds a class named +given_name+ with +superclass+.
- #
- # Both +given_name+ and +superclass+ may contain '::', and are
- # interpreted relative to the +self+ context. This allows handling correctly
- # examples like these:
- # class RDoc::Gauntlet < Gauntlet
- # module Mod
- # class Object # implies < ::Object
- # class SubObject < Object # this is _not_ ::Object
- #
- # Given <tt>class Container::Item</tt> RDoc assumes +Container+ is a module
- # unless it later sees <tt>class Container</tt>. +add_class+ automatically
- # upgrades +given_name+ to a class in this case.
-
- def add_class class_type, given_name, superclass = '::Object'
- # superclass +nil+ is passed by the C parser in the following cases:
- # - registering Object in 1.8 (correct)
- # - registering BasicObject in 1.9 (correct)
- # - registering RubyVM in 1.9 in iseq.c (incorrect: < Object in vm.c)
- #
- # If we later find a superclass for a registered class with a nil
- # superclass, we must honor it.
-
- # find the name & enclosing context
- if given_name =~ /^:+(\w+)$/ then
- full_name = $1
- enclosing = top_level
- name = full_name.split(/:+/).last
- else
- full_name = child_name given_name
-
- if full_name =~ /^(.+)::(\w+)$/ then
- name = $2
- ename = $1
- enclosing = @store.classes_hash[ename] || @store.modules_hash[ename]
- # HACK: crashes in actionpack/lib/action_view/helpers/form_helper.rb (metaprogramming)
- unless enclosing then
- # try the given name at top level (will work for the above example)
- enclosing = @store.classes_hash[given_name] ||
- @store.modules_hash[given_name]
- return enclosing if enclosing
- # not found: create the parent(s)
- names = ename.split('::')
- enclosing = self
- names.each do |n|
- enclosing = enclosing.classes_hash[n] ||
- enclosing.modules_hash[n] ||
- enclosing.add_module(RDoc::NormalModule, n)
- end
- end
- else
- name = full_name
- enclosing = self
- end
- end
-
- # fix up superclass
- if full_name == 'BasicObject' then
- superclass = nil
- elsif full_name == 'Object' then
- superclass = defined?(::BasicObject) ? '::BasicObject' : nil
- end
-
- # find the superclass full name
- if superclass then
- if superclass =~ /^:+/ then
- superclass = $' #'
- else
- if superclass =~ /^(\w+):+(.+)$/ then
- suffix = $2
- mod = find_module_named($1)
- superclass = mod.full_name + '::' + suffix if mod
- else
- mod = find_module_named(superclass)
- superclass = mod.full_name if mod
- end
- end
-
- # did we believe it was a module?
- mod = @store.modules_hash.delete superclass
-
- upgrade_to_class mod, RDoc::NormalClass, mod.parent if mod
-
- # e.g., Object < Object
- superclass = nil if superclass == full_name
- end
-
- klass = @store.classes_hash[full_name]
-
- if klass then
- # if TopLevel, it may not be registered in the classes:
- enclosing.classes_hash[name] = klass
-
- # update the superclass if needed
- if superclass then
- existing = klass.superclass
- existing = existing.full_name unless existing.is_a?(String) if existing
- if existing.nil? ||
- (existing == 'Object' && superclass != 'Object') then
- klass.superclass = superclass
- end
- end
- else
- # this is a new class
- mod = @store.modules_hash.delete full_name
-
- if mod then
- klass = upgrade_to_class mod, RDoc::NormalClass, enclosing
-
- klass.superclass = superclass unless superclass.nil?
- else
- klass = class_type.new name, superclass
-
- enclosing.add_class_or_module(klass, enclosing.classes_hash,
- @store.classes_hash)
- end
- end
-
- klass.parent = self
-
- klass
- end
-
- ##
- # Adds the class or module +mod+ to the modules or
- # classes Hash +self_hash+, and to +all_hash+ (either
- # <tt>TopLevel::modules_hash</tt> or <tt>TopLevel::classes_hash</tt>),
- # unless #done_documenting is +true+. Sets the #parent of +mod+
- # to +self+, and its #section to #current_section. Returns +mod+.
-
- def add_class_or_module mod, self_hash, all_hash
- mod.section = current_section # TODO declaring context? something is
- # wrong here...
- mod.parent = self
- mod.store = @store
-
- unless @done_documenting then
- self_hash[mod.name] = mod
- # this must be done AFTER adding mod to its parent, so that the full
- # name is correct:
- all_hash[mod.full_name] = mod
- end
-
- mod
- end
-
- ##
- # Adds +constant+ if not already there. If it is, updates the comment,
- # value and/or is_alias_for of the known constant if they were empty/nil.
-
- def add_constant constant
- return constant unless @document_self
-
- # HACK: avoid duplicate 'PI' & 'E' in math.c (1.8.7 source code)
- # (this is a #ifdef: should be handled by the C parser)
- known = @constants_hash[constant.name]
-
- if known then
- known.comment = constant.comment if known.comment.empty?
-
- known.value = constant.value if
- known.value.nil? or known.value.strip.empty?
-
- known.is_alias_for ||= constant.is_alias_for
- else
- @constants_hash[constant.name] = constant
- add_to @constants, constant
- end
-
- constant
- end
-
- ##
- # Adds included module +include+ which should be an RDoc::Include
-
- def add_include include
- add_to @includes, include
-
- include
- end
-
- ##
- # Adds extension module +ext+ which should be an RDoc::Extend
-
- def add_extend ext
- add_to @extends, ext
-
- ext
- end
-
- ##
- # Adds +method+ if not already there. If it is (as method or attribute),
- # updates the comment if it was empty.
-
- def add_method method
- return method unless @document_self
-
- # HACK: avoid duplicate 'new' in io.c & struct.c (1.8.7 source code)
- key = method.pretty_name
- known = @methods_hash[key]
-
- if known then
- if @store then # otherwise we are loading
- known.comment = method.comment if known.comment.empty?
- previously = ", previously in #{known.file}" unless
- method.file == known.file
- @store.rdoc.options.warn \
- "Duplicate method #{known.full_name} in #{method.file}#{previously}"
- end
- else
- @methods_hash[key] = method
- method.visibility = @visibility
- add_to @method_list, method
- resolve_aliases method
- end
-
- method
- end
-
- ##
- # Adds a module named +name+. If RDoc already knows +name+ is a class then
- # that class is returned instead. See also #add_class.
-
- def add_module(class_type, name)
- mod = @classes[name] || @modules[name]
- return mod if mod
-
- full_name = child_name name
- mod = @store.modules_hash[full_name] || class_type.new(name)
-
- add_class_or_module mod, @modules, @store.modules_hash
- end
-
- ##
- # Adds an alias from +from+ (a class or module) to +name+ which was defined
- # in +file+.
-
- def add_module_alias from, name, file
- return from if @done_documenting
-
- to_name = child_name name
-
- # if we already know this name, don't register an alias:
- # see the metaprogramming in lib/active_support/basic_object.rb,
- # where we already know BasicObject is a class when we find
- # BasicObject = BlankSlate
- return from if @store.find_class_or_module to_name
-
- to = from.dup
- to.name = name
- to.full_name = nil
-
- if to.module? then
- @store.modules_hash[to_name] = to
- @modules[name] = to
- else
- @store.classes_hash[to_name] = to
- @classes[name] = to
- end
-
- # Registers a constant for this alias. The constant value and comment
- # will be updated later, when the Ruby parser adds the constant
- const = RDoc::Constant.new name, nil, to.comment
- const.record_location file
- const.is_alias_for = from
- add_constant const
-
- to
- end
-
- ##
- # Adds +require+ to this context's top level
-
- def add_require(require)
- return require unless @document_self
-
- if RDoc::TopLevel === self then
- add_to @requires, require
- else
- parent.add_require require
- end
- end
-
- ##
- # Returns a section with +title+, creating it if it doesn't already exist.
- # +comment+ will be appended to the section's comment.
- #
- # A section with a +title+ of +nil+ will return the default section.
- #
- # See also RDoc::Context::Section
-
- def add_section title, comment = nil
- if section = @sections[title] then
- section.add_comment comment if comment
- else
- section = Section.new self, title, comment
- @sections[title] = section
- end
-
- section
- end
-
- ##
- # Adds +thing+ to the collection +array+
-
- def add_to array, thing
- array << thing if @document_self
-
- thing.parent = self
- thing.store = @store if @store
- thing.section = current_section
- end
-
- ##
- # Is there any content?
- #
- # This means any of: comment, aliases, methods, attributes, external
- # aliases, require, constant.
- #
- # Includes and extends are also checked unless <tt>includes == false</tt>.
-
- def any_content(includes = true)
- @any_content ||= !(
- @comment.empty? &&
- @method_list.empty? &&
- @attributes.empty? &&
- @aliases.empty? &&
- @external_aliases.empty? &&
- @requires.empty? &&
- @constants.empty?
- )
- @any_content || (includes && !(@includes + @extends).empty? )
- end
-
- ##
- # Creates the full name for a child with +name+
-
- def child_name name
- if name =~ /^:+/
- $' #'
- elsif RDoc::TopLevel === self then
- name
- else
- "#{self.full_name}::#{name}"
- end
- end
-
- ##
- # Class attributes
-
- def class_attributes
- @class_attributes ||= attributes.select { |a| a.singleton }
- end
-
- ##
- # Class methods
-
- def class_method_list
- @class_method_list ||= method_list.select { |a| a.singleton }
- end
-
- ##
- # Array of classes in this context
-
- def classes
- @classes.values
- end
-
- ##
- # All classes and modules in this namespace
-
- def classes_and_modules
- classes + modules
- end
-
- ##
- # Hash of classes keyed by class name
-
- def classes_hash
- @classes
- end
-
- ##
- # The current documentation section that new items will be added to. If
- # temporary_section is available it will be used.
-
- def current_section
- if section = @temporary_section then
- @temporary_section = nil
- else
- section = @current_section
- end
-
- section
- end
-
- ##
- # Is part of this thing was defined in +file+?
-
- def defined_in?(file)
- @in_files.include?(file)
- end
-
- def display(method_attr) # :nodoc:
- if method_attr.is_a? RDoc::Attr
- "#{method_attr.definition} #{method_attr.pretty_name}"
- else
- "method #{method_attr.pretty_name}"
- end
- end
-
- ##
- # Iterator for ancestors for duck-typing. Does nothing. See
- # RDoc::ClassModule#each_ancestor.
- #
- # This method exists to make it easy to work with Context subclasses that
- # aren't part of RDoc.
-
- def each_ancestor # :nodoc:
- end
-
- ##
- # Iterator for attributes
-
- def each_attribute # :yields: attribute
- @attributes.each { |a| yield a }
- end
-
- ##
- # Iterator for classes and modules
-
- def each_classmodule(&block) # :yields: module
- classes_and_modules.sort.each(&block)
- end
-
- ##
- # Iterator for constants
-
- def each_constant # :yields: constant
- @constants.each {|c| yield c}
- end
-
- ##
- # Iterator for included modules
-
- def each_include # :yields: include
- @includes.each do |i| yield i end
- end
-
- ##
- # Iterator for extension modules
-
- def each_extend # :yields: extend
- @extends.each do |e| yield e end
- end
-
- ##
- # Iterator for methods
-
- def each_method # :yields: method
- return enum_for __method__ unless block_given?
-
- @method_list.sort.each { |m| yield m }
- end
-
- ##
- # Iterator for each section's contents sorted by title. The +section+, the
- # section's +constants+ and the sections +attributes+ are yielded. The
- # +constants+ and +attributes+ collections are sorted.
- #
- # To retrieve methods in a section use #methods_by_type with the optional
- # +section+ parameter.
- #
- # NOTE: Do not edit collections yielded by this method
-
- def each_section # :yields: section, constants, attributes
- return enum_for __method__ unless block_given?
-
- constants = @constants.group_by do |constant| constant.section end
- attributes = @attributes.group_by do |attribute| attribute.section end
-
- constants.default = []
- attributes.default = []
-
- sort_sections.each do |section|
- yield section, constants[section].sort, attributes[section].sort
- end
- end
-
- ##
- # Finds an attribute +name+ with singleton value +singleton+.
-
- def find_attribute(name, singleton)
- name = $1 if name =~ /^(.*)=$/
- @attributes.find { |a| a.name == name && a.singleton == singleton }
- end
-
- ##
- # Finds an attribute with +name+ in this context
-
- def find_attribute_named(name)
- case name
- when /\A#/ then
- find_attribute name[1..-1], false
- when /\A::/ then
- find_attribute name[2..-1], true
- else
- @attributes.find { |a| a.name == name }
- end
- end
-
- ##
- # Finds a class method with +name+ in this context
-
- def find_class_method_named(name)
- @method_list.find { |meth| meth.singleton && meth.name == name }
- end
-
- ##
- # Finds a constant with +name+ in this context
-
- def find_constant_named(name)
- @constants.find {|m| m.name == name}
- end
-
- ##
- # Find a module at a higher scope
-
- def find_enclosing_module_named(name)
- parent && parent.find_module_named(name)
- end
-
- ##
- # Finds an external alias +name+ with singleton value +singleton+.
-
- def find_external_alias(name, singleton)
- @external_aliases.find { |m| m.name == name && m.singleton == singleton }
- end
-
- ##
- # Finds an external alias with +name+ in this context
-
- def find_external_alias_named(name)
- case name
- when /\A#/ then
- find_external_alias name[1..-1], false
- when /\A::/ then
- find_external_alias name[2..-1], true
- else
- @external_aliases.find { |a| a.name == name }
- end
- end
-
- ##
- # Finds a file with +name+ in this context
-
- def find_file_named name
- @store.find_file_named name
- end
-
- ##
- # Finds an instance method with +name+ in this context
-
- def find_instance_method_named(name)
- @method_list.find { |meth| !meth.singleton && meth.name == name }
- end
-
- ##
- # Finds a method, constant, attribute, external alias, module or file
- # named +symbol+ in this context.
-
- def find_local_symbol(symbol)
- find_method_named(symbol) or
- find_constant_named(symbol) or
- find_attribute_named(symbol) or
- find_external_alias_named(symbol) or
- find_module_named(symbol) or
- find_file_named(symbol)
- end
-
- ##
- # Finds a method named +name+ with singleton value +singleton+.
-
- def find_method(name, singleton)
- @method_list.find { |m| m.name == name && m.singleton == singleton }
- end
-
- ##
- # Finds a instance or module method with +name+ in this context
-
- def find_method_named(name)
- case name
- when /\A#/ then
- find_method name[1..-1], false
- when /\A::/ then
- find_method name[2..-1], true
- else
- @method_list.find { |meth| meth.name == name }
- end
- end
-
- ##
- # Find a module with +name+ using ruby's scoping rules
-
- def find_module_named(name)
- res = @modules[name] || @classes[name]
- return res if res
- return self if self.name == name
- find_enclosing_module_named name
- end
-
- ##
- # Look up +symbol+, first as a module, then as a local symbol.
-
- def find_symbol(symbol)
- find_symbol_module(symbol) || find_local_symbol(symbol)
- end
-
- ##
- # Look up a module named +symbol+.
-
- def find_symbol_module(symbol)
- result = nil
-
- # look for a class or module 'symbol'
- case symbol
- when /^::/ then
- result = @store.find_class_or_module symbol
- when /^(\w+):+(.+)$/
- suffix = $2
- top = $1
- searched = self
- while searched do
- mod = searched.find_module_named(top)
- break unless mod
- result = @store.find_class_or_module "#{mod.full_name}::#{suffix}"
- break if result || searched.is_a?(RDoc::TopLevel)
- searched = searched.parent
- end
- else
- searched = self
- while searched do
- result = searched.find_module_named(symbol)
- break if result || searched.is_a?(RDoc::TopLevel)
- searched = searched.parent
- end
- end
-
- result
- end
-
- ##
- # The full name for this context. This method is overridden by subclasses.
-
- def full_name
- '(unknown)'
- end
-
- ##
- # Does this context and its methods and constants all have documentation?
- #
- # (Yes, fully documented doesn't mean everything.)
-
- def fully_documented?
- documented? and
- attributes.all? { |a| a.documented? } and
- method_list.all? { |m| m.documented? } and
- constants.all? { |c| c.documented? }
- end
-
- ##
- # URL for this with a +prefix+
-
- def http_url(prefix)
- path = name_for_path
- path = path.gsub(/<<\s*(\w*)/, 'from-\1') if path =~ /<</
- path = [prefix] + path.split('::')
-
- File.join(*path.compact) + '.html'
- end
-
- ##
- # Instance attributes
-
- def instance_attributes
- @instance_attributes ||= attributes.reject { |a| a.singleton }
- end
-
- ##
- # Instance methods
- #--
- # TODO rename to instance_methods
-
- def instance_method_list
- @instance_method_list ||= method_list.reject { |a| a.singleton }
- end
-
- ##
- # Breaks method_list into a nested hash by type (<tt>'class'</tt> or
- # <tt>'instance'</tt>) and visibility (+:public+, +:protected+, +:private+).
- #
- # If +section+ is provided only methods in that RDoc::Context::Section will
- # be returned.
-
- def methods_by_type section = nil
- methods = {}
-
- TYPES.each do |type|
- visibilities = {}
- RDoc::VISIBILITIES.each do |vis|
- visibilities[vis] = []
- end
-
- methods[type] = visibilities
- end
-
- each_method do |method|
- next if section and not method.section == section
- methods[method.type][method.visibility] << method
- end
-
- methods
- end
-
- ##
- # Yields AnyMethod and Attr entries matching the list of names in +methods+.
-
- def methods_matching(methods, singleton = false, &block)
- (@method_list + @attributes).each do |m|
- yield m if methods.include?(m.name) and m.singleton == singleton
- end
-
- each_ancestor do |parent|
- parent.methods_matching(methods, singleton, &block)
- end
- end
-
- ##
- # Array of modules in this context
-
- def modules
- @modules.values
- end
-
- ##
- # Hash of modules keyed by module name
-
- def modules_hash
- @modules
- end
-
- ##
- # Name to use to generate the url.
- # <tt>#full_name</tt> by default.
-
- def name_for_path
- full_name
- end
-
- ##
- # Changes the visibility for new methods to +visibility+
-
- def ongoing_visibility=(visibility)
- @visibility = visibility
- end
-
- ##
- # Record +top_level+ as a file +self+ is in.
-
- def record_location(top_level)
- @in_files << top_level unless @in_files.include?(top_level)
- end
-
- ##
- # Should we remove this context from the documentation?
- #
- # The answer is yes if:
- # * #received_nodoc is +true+
- # * #any_content is +false+ (not counting includes)
- # * All #includes are modules (not a string), and their module has
- # <tt>#remove_from_documentation? == true</tt>
- # * All classes and modules have <tt>#remove_from_documentation? == true</tt>
-
- def remove_from_documentation?
- @remove_from_documentation ||=
- @received_nodoc &&
- !any_content(false) &&
- @includes.all? { |i| !i.module.is_a?(String) && i.module.remove_from_documentation? } &&
- classes_and_modules.all? { |cm| cm.remove_from_documentation? }
- end
-
- ##
- # Removes methods and attributes with a visibility less than +min_visibility+.
- #--
- # TODO mark the visibility of attributes in the template (if not public?)
-
- def remove_invisible min_visibility
- return if [:private, :nodoc].include? min_visibility
- remove_invisible_in @method_list, min_visibility
- remove_invisible_in @attributes, min_visibility
- end
-
- ##
- # Only called when min_visibility == :public or :private
-
- def remove_invisible_in array, min_visibility # :nodoc:
- if min_visibility == :public then
- array.reject! { |e|
- e.visibility != :public and not e.force_documentation
- }
- else
- array.reject! { |e|
- e.visibility == :private and not e.force_documentation
- }
- end
- end
-
- ##
- # Tries to resolve unmatched aliases when a method or attribute has just
- # been added.
-
- def resolve_aliases added
- # resolve any pending unmatched aliases
- key = added.pretty_name
- unmatched_alias_list = @unmatched_alias_lists[key]
- return unless unmatched_alias_list
- unmatched_alias_list.each do |unmatched_alias|
- added.add_alias unmatched_alias, self
- @external_aliases.delete unmatched_alias
- end
- @unmatched_alias_lists.delete key
- end
-
- ##
- # Returns RDoc::Context::Section objects referenced in this context for use
- # in a table of contents.
-
- def section_contents
- used_sections = {}
-
- each_method do |method|
- next unless method.display?
-
- used_sections[method.section] = true
- end
-
- # order found sections
- sections = sort_sections.select do |section|
- used_sections[section]
- end
-
- # only the default section is used
- return [] if
- sections.length == 1 and not sections.first.title
-
- sections
- end
-
- ##
- # Sections in this context
-
- def sections
- @sections.values
- end
-
- def sections_hash # :nodoc:
- @sections
- end
-
- ##
- # Sets the current section to a section with +title+. See also #add_section
-
- def set_current_section title, comment
- @current_section = add_section title, comment
- end
-
- ##
- # Given an array +methods+ of method names, set the visibility of each to
- # +visibility+
-
- def set_visibility_for(methods, visibility, singleton = false)
- methods_matching methods, singleton do |m|
- m.visibility = visibility
- end
- end
-
- ##
- # Sorts sections alphabetically (default) or in TomDoc fashion (none,
- # Public, Internal, Deprecated)
-
- def sort_sections
- titles = @sections.map { |title, _| title }
-
- if titles.length > 1 and
- TOMDOC_TITLES_SORT ==
- (titles | TOMDOC_TITLES).sort_by { |title| title.to_s } then
- @sections.values_at(*TOMDOC_TITLES).compact
- else
- @sections.sort_by { |title, _|
- title.to_s
- }.map { |_, section|
- section
- }
- end
- end
-
- def to_s # :nodoc:
- "#{self.class.name} #{self.full_name}"
- end
-
- ##
- # Return the TopLevel that owns us
- #--
- # FIXME we can be 'owned' by several TopLevel (see #record_location &
- # #in_files)
-
- def top_level
- return @top_level if defined? @top_level
- @top_level = self
- @top_level = @top_level.parent until RDoc::TopLevel === @top_level
- @top_level
- end
-
- ##
- # Upgrades NormalModule +mod+ in +enclosing+ to a +class_type+
-
- def upgrade_to_class mod, class_type, enclosing
- enclosing.modules_hash.delete mod.name
-
- klass = RDoc::ClassModule.from_module class_type, mod
- klass.store = @store
-
- # if it was there, then we keep it even if done_documenting
- @store.classes_hash[mod.full_name] = klass
- enclosing.classes_hash[mod.name] = klass
-
- klass
- end
-
- autoload :Section, 'rdoc/context/section'
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/context/section.rb b/ruby_2_2/lib/rdoc/context/section.rb
deleted file mode 100644
index 580f07deff..0000000000
--- a/ruby_2_2/lib/rdoc/context/section.rb
+++ /dev/null
@@ -1,238 +0,0 @@
-##
-# A section of documentation like:
-#
-# # :section: The title
-# # The body
-#
-# Sections can be referenced multiple times and will be collapsed into a
-# single section.
-
-class RDoc::Context::Section
-
- include RDoc::Text
-
- MARSHAL_VERSION = 0 # :nodoc:
-
- ##
- # Section comment
-
- attr_reader :comment
-
- ##
- # Section comments
-
- attr_reader :comments
-
- ##
- # Context this Section lives in
-
- attr_reader :parent
-
- ##
- # Section title
-
- attr_reader :title
-
- @@sequence = "SEC00000"
-
- ##
- # Creates a new section with +title+ and +comment+
-
- def initialize parent, title, comment
- @parent = parent
- @title = title ? title.strip : title
-
- @@sequence.succ!
- @sequence = @@sequence.dup
-
- @comments = []
-
- add_comment comment
- end
-
- ##
- # Sections are equal when they have the same #title
-
- def == other
- self.class === other and @title == other.title
- end
-
- ##
- # Adds +comment+ to this section
-
- def add_comment comment
- comment = extract_comment comment
-
- return if comment.empty?
-
- case comment
- when RDoc::Comment then
- @comments << comment
- when RDoc::Markup::Document then
- @comments.concat comment.parts
- when Array then
- @comments.concat comment
- else
- raise TypeError, "unknown comment type: #{comment.inspect}"
- end
- end
-
- ##
- # Anchor reference for linking to this section
-
- def aref
- title = @title || '[untitled]'
-
- CGI.escape(title).gsub('%', '-').sub(/^-/, '')
- end
-
- ##
- # Extracts the comment for this section from the original comment block.
- # If the first line contains :section:, strip it and use the rest.
- # Otherwise remove lines up to the line containing :section:, and look
- # for those lines again at the end and remove them. This lets us write
- #
- # # :section: The title
- # # The body
-
- def extract_comment comment
- case comment
- when Array then
- comment.map do |c|
- extract_comment c
- end
- when nil
- RDoc::Comment.new ''
- when RDoc::Comment then
- if comment.text =~ /^#[ \t]*:section:.*\n/ then
- start = $`
- rest = $'
-
- comment.text = if start.empty? then
- rest
- else
- rest.sub(/#{start.chomp}\Z/, '')
- end
- end
-
- comment
- when RDoc::Markup::Document then
- comment
- else
- raise TypeError, "unknown comment #{comment.inspect}"
- end
- end
-
- def inspect # :nodoc:
- "#<%s:0x%x %p>" % [self.class, object_id, title]
- end
-
- ##
- # The files comments in this section come from
-
- def in_files
- return [] if @comments.empty?
-
- case @comments
- when Array then
- @comments.map do |comment|
- comment.file
- end
- when RDoc::Markup::Document then
- @comment.parts.map do |document|
- document.file
- end
- else
- raise RDoc::Error, "BUG: unknown comment class #{@comments.class}"
- end
- end
-
- ##
- # Serializes this Section. The title and parsed comment are saved, but not
- # the section parent which must be restored manually.
-
- def marshal_dump
- [
- MARSHAL_VERSION,
- @title,
- parse,
- ]
- end
-
- ##
- # De-serializes this Section. The section parent must be restored manually.
-
- def marshal_load array
- @parent = nil
-
- @title = array[1]
- @comments = array[2]
- end
-
- ##
- # Parses +comment_location+ into an RDoc::Markup::Document composed of
- # multiple RDoc::Markup::Documents with their file set.
-
- def parse
- case @comments
- when String then
- super
- when Array then
- docs = @comments.map do |comment, location|
- doc = super comment
- doc.file = location if location
- doc
- end
-
- RDoc::Markup::Document.new(*docs)
- when RDoc::Comment then
- doc = super @comments.text, comments.format
- doc.file = @comments.location
- doc
- when RDoc::Markup::Document then
- return @comments
- else
- raise ArgumentError, "unknown comment class #{comments.class}"
- end
- end
-
- ##
- # The section's title, or 'Top Section' if the title is nil.
- #
- # This is used by the table of contents template so the name is silly.
-
- def plain_html
- @title || 'Top Section'
- end
-
- ##
- # Removes a comment from this section if it is from the same file as
- # +comment+
-
- def remove_comment comment
- return if @comments.empty?
-
- case @comments
- when Array then
- @comments.delete_if do |my_comment|
- my_comment.file == comment.file
- end
- when RDoc::Markup::Document then
- @comments.parts.delete_if do |document|
- document.file == comment.file.name
- end
- else
- raise RDoc::Error, "BUG: unknown comment class #{@comments.class}"
- end
- end
-
- ##
- # Section sequence number (deprecated)
-
- def sequence
- warn "RDoc::Context::Section#sequence is deprecated, use #aref"
- @sequence
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/cross_reference.rb b/ruby_2_2/lib/rdoc/cross_reference.rb
deleted file mode 100644
index 5b08d5202d..0000000000
--- a/ruby_2_2/lib/rdoc/cross_reference.rb
+++ /dev/null
@@ -1,183 +0,0 @@
-##
-# RDoc::CrossReference is a reusable way to create cross references for names.
-
-class RDoc::CrossReference
-
- ##
- # Regular expression to match class references
- #
- # 1. There can be a '\\' in front of text to suppress the cross-reference
- # 2. There can be a '::' in front of class names to reference from the
- # top-level namespace.
- # 3. The method can be followed by parenthesis (not recommended)
-
- CLASS_REGEXP_STR = '\\\\?((?:\:{2})?[A-Z]\w*(?:\:\:\w+)*)'
-
- ##
- # Regular expression to match method references.
- #
- # See CLASS_REGEXP_STR
-
- METHOD_REGEXP_STR = '([a-z]\w*[!?=]?|%|===|\[\]=?|<<|>>)(?:\([\w.+*/=<>-]*\))?'
-
- ##
- # Regular expressions matching text that should potentially have
- # cross-reference links generated are passed to add_special. Note that
- # these expressions are meant to pick up text for which cross-references
- # have been suppressed, since the suppression characters are removed by the
- # code that is triggered.
-
- CROSSREF_REGEXP = /(?:^|\s)
- (
- (?:
- # A::B::C.meth
- #{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}
-
- # Stand-alone method (preceded by a #)
- | \\?\##{METHOD_REGEXP_STR}
-
- # Stand-alone method (preceded by ::)
- | ::#{METHOD_REGEXP_STR}
-
- # A::B::C
- # The stuff after CLASS_REGEXP_STR is a
- # nasty hack. CLASS_REGEXP_STR unfortunately matches
- # words like dog and cat (these are legal "class"
- # names in Fortran 95). When a word is flagged as a
- # potential cross-reference, limitations in the markup
- # engine suppress other processing, such as typesetting.
- # This is particularly noticeable for contractions.
- # In order that words like "can't" not
- # be flagged as potential cross-references, only
- # flag potential class cross-references if the character
- # after the cross-reference is a space, sentence
- # punctuation, tag start character, or attribute
- # marker.
- | #{CLASS_REGEXP_STR}(?=[@\s).?!,;<\000]|\z)
-
- # Things that look like filenames
- # The key thing is that there must be at least
- # one special character (period, slash, or
- # underscore).
- | (?:\.\.\/)*[-\/\w]+[_\/.][-\w\/.]+
-
- # Things that have markup suppressed
- # Don't process things like '\<' in \<tt>, though.
- # TODO: including < is a hack, not very satisfying.
- | \\[^\s<]
- )
-
- # labels for headings
- (?:@[\w+%-]+(?:\.[\w|%-]+)?)?
- )/x
-
- ##
- # Version of CROSSREF_REGEXP used when <tt>--hyperlink-all</tt> is specified.
-
- ALL_CROSSREF_REGEXP = /
- (?:^|\s)
- (
- (?:
- # A::B::C.meth
- #{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}
-
- # Stand-alone method
- | \\?#{METHOD_REGEXP_STR}
-
- # A::B::C
- | #{CLASS_REGEXP_STR}(?=[@\s).?!,;<\000]|\z)
-
- # Things that look like filenames
- | (?:\.\.\/)*[-\/\w]+[_\/.][-\w\/.]+
-
- # Things that have markup suppressed
- | \\[^\s<]
- )
-
- # labels for headings
- (?:@[\w+%-]+)?
- )/x
-
- ##
- # Hash of references that have been looked-up to their replacements
-
- attr_accessor :seen
-
- ##
- # Allows cross-references to be created based on the given +context+
- # (RDoc::Context).
-
- def initialize context
- @context = context
- @store = context.store
-
- @seen = {}
- end
-
- ##
- # Returns a reference to +name+.
- #
- # If the reference is found and +name+ is not documented +text+ will be
- # returned. If +name+ is escaped +name+ is returned. If +name+ is not
- # found +text+ is returned.
-
- def resolve name, text
- return @seen[name] if @seen.include? name
-
- if /#{CLASS_REGEXP_STR}([.#]|::)#{METHOD_REGEXP_STR}/o =~ name then
- type = $2
- type = '' if type == '.' # will find either #method or ::method
- method = "#{type}#{$3}"
- container = @context.find_symbol_module($1)
- elsif /^([.#]|::)#{METHOD_REGEXP_STR}/o =~ name then
- type = $1
- type = '' if type == '.'
- method = "#{type}#{$2}"
- container = @context
- else
- container = nil
- end
-
- if container then
- ref = container.find_local_symbol method
-
- unless ref || RDoc::TopLevel === container then
- ref = container.find_ancestor_local_symbol method
- end
- end
-
- ref = case name
- when /^\\(#{CLASS_REGEXP_STR})$/o then
- @context.find_symbol $1
- else
- @context.find_symbol name
- end unless ref
-
- # Try a page name
- ref = @store.page name if not ref and name =~ /^\w+$/
-
- ref = nil if RDoc::Alias === ref # external alias, can't link to it
-
- out = if name == '\\' then
- name
- elsif name =~ /^\\/ then
- # we remove the \ only in front of what we know:
- # other backslashes are treated later, only outside of <tt>
- ref ? $' : name
- elsif ref then
- if ref.display? then
- ref
- else
- text
- end
- else
- text
- end
-
- @seen[name] = out
-
- out
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/encoding.rb b/ruby_2_2/lib/rdoc/encoding.rb
deleted file mode 100644
index b3515a435f..0000000000
--- a/ruby_2_2/lib/rdoc/encoding.rb
+++ /dev/null
@@ -1,99 +0,0 @@
-# coding: US-ASCII
-
-##
-# This class is a wrapper around File IO and Encoding that helps RDoc load
-# files and convert them to the correct encoding.
-
-module RDoc::Encoding
-
- ##
- # Reads the contents of +filename+ and handles any encoding directives in
- # the file.
- #
- # The content will be converted to the +encoding+. If the file cannot be
- # converted a warning will be printed and nil will be returned.
- #
- # If +force_transcode+ is true the document will be transcoded and any
- # unknown character in the target encoding will be replaced with '?'
-
- def self.read_file filename, encoding, force_transcode = false
- content = open filename, "rb" do |f| f.read end
- content.gsub!("\r\n", "\n") if RUBY_PLATFORM =~ /mswin|mingw/
-
- utf8 = content.sub!(/\A\xef\xbb\xbf/, '')
-
- RDoc::Encoding.set_encoding content
-
- if Object.const_defined? :Encoding then
- begin
- encoding ||= Encoding.default_external
- orig_encoding = content.encoding
-
- if not orig_encoding.ascii_compatible? then
- content.encode! encoding
- elsif utf8 then
- content.force_encoding Encoding::UTF_8
- content.encode! encoding
- else
- # assume the content is in our output encoding
- content.force_encoding encoding
- end
-
- unless content.valid_encoding? then
- # revert and try to transcode
- content.force_encoding orig_encoding
- content.encode! encoding
- end
-
- unless content.valid_encoding? then
- warn "unable to convert #{filename} to #{encoding}, skipping"
- content = nil
- end
- rescue Encoding::InvalidByteSequenceError,
- Encoding::UndefinedConversionError => e
- if force_transcode then
- content.force_encoding orig_encoding
- content.encode!(encoding,
- :invalid => :replace, :undef => :replace,
- :replace => '?')
- return content
- else
- warn "unable to convert #{e.message} for #{filename}, skipping"
- return nil
- end
- end
- end
-
- content
- rescue ArgumentError => e
- raise unless e.message =~ /unknown encoding name - (.*)/
- warn "unknown encoding name \"#{$1}\" for #{filename}, skipping"
- nil
- rescue Errno::EISDIR, Errno::ENOENT
- nil
- end
-
- ##
- # Sets the encoding of +string+ based on the magic comment
-
- def self.set_encoding string
- string =~ /\A(?:#!.*\n)?(.*\n)/
-
- first_line = $1
-
- name = case first_line
- when /^<\?xml[^?]*encoding=(["'])(.*?)\1/ then $2
- when /\b(?:en)?coding[=:]\s*([^\s;]+)/i then $1
- else return
- end
-
- string.sub! first_line, ''
-
- return unless Object.const_defined? :Encoding
-
- enc = Encoding.find name
- string.force_encoding enc if enc
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/erb_partial.rb b/ruby_2_2/lib/rdoc/erb_partial.rb
deleted file mode 100644
index 910d1e0351..0000000000
--- a/ruby_2_2/lib/rdoc/erb_partial.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-##
-# Allows an ERB template to be rendered in the context (binding) of an
-# existing ERB template evaluation.
-
-class RDoc::ERBPartial < ERB
-
- ##
- # Overrides +compiler+ startup to set the +eoutvar+ to an empty string only
- # if it isn't already set.
-
- def set_eoutvar compiler, eoutvar = '_erbout'
- super
-
- compiler.pre_cmd = ["#{eoutvar} ||= ''"]
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/erbio.rb b/ruby_2_2/lib/rdoc/erbio.rb
deleted file mode 100644
index 04a89fbd34..0000000000
--- a/ruby_2_2/lib/rdoc/erbio.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-require 'erb'
-
-##
-# A subclass of ERB that writes directly to an IO. Credit to Aaron Patterson
-# and Masatoshi SEKI.
-#
-# To use:
-#
-# erbio = RDoc::ERBIO.new '<%= "hello world" %>', nil, nil
-#
-# open 'hello.txt', 'w' do |io|
-# erbio.result binding
-# end
-#
-# Note that binding must enclose the io you wish to output on.
-
-class RDoc::ERBIO < ERB
-
- ##
- # Defaults +eoutvar+ to 'io', otherwise is identical to ERB's initialize
-
- def initialize str, safe_level = nil, trim_mode = nil, eoutvar = 'io'
- super
- end
-
- ##
- # Instructs +compiler+ how to write to +io_variable+
-
- def set_eoutvar compiler, io_variable
- compiler.put_cmd = "#{io_variable}.write"
- compiler.insert_cmd = "#{io_variable}.write"
- compiler.pre_cmd = []
- compiler.post_cmd = []
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/extend.rb b/ruby_2_2/lib/rdoc/extend.rb
deleted file mode 100644
index efa2c69bee..0000000000
--- a/ruby_2_2/lib/rdoc/extend.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-##
-# A Module extension to a class with \#extend
-#
-# RDoc::Extend.new 'Enumerable', 'comment ...'
-
-class RDoc::Extend < RDoc::Mixin
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/generator.rb b/ruby_2_2/lib/rdoc/generator.rb
deleted file mode 100644
index 7d3989d42f..0000000000
--- a/ruby_2_2/lib/rdoc/generator.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-##
-# RDoc uses generators to turn parsed source code in the form of an
-# RDoc::CodeObject tree into some form of output. RDoc comes with the HTML
-# generator RDoc::Generator::Darkfish and an ri data generator
-# RDoc::Generator::RI.
-#
-# == Registering a Generator
-#
-# Generators are registered by calling RDoc::RDoc.add_generator with the class
-# of the generator:
-#
-# class My::Awesome::Generator
-# RDoc::RDoc.add_generator self
-# end
-#
-# == Adding Options to +rdoc+
-#
-# Before option processing in +rdoc+, RDoc::Options will call ::setup_options
-# on the generator class with an RDoc::Options instance. The generator can
-# use RDoc::Options#option_parser to add command-line options to the +rdoc+
-# tool. See RDoc::Options@Custom+Options for an example and see OptionParser
-# for details on how to add options.
-#
-# You can extend the RDoc::Options instance with additional accessors for your
-# generator.
-#
-# == Generator Instantiation
-#
-# After parsing, RDoc::RDoc will instantiate a generator by calling
-# #initialize with an RDoc::Store instance and an RDoc::Options instance.
-#
-# The RDoc::Store instance holds documentation for parsed source code. In
-# RDoc 3 and earlier the RDoc::TopLevel class held this data. When upgrading
-# a generator from RDoc 3 and earlier you should only need to replace
-# RDoc::TopLevel with the store instance.
-#
-# RDoc will then call #generate on the generator instance. You can use the
-# various methods on RDoc::Store and in the RDoc::CodeObject tree to create
-# your desired output format.
-
-module RDoc::Generator
-
- autoload :Markup, 'rdoc/generator/markup'
-
- autoload :Darkfish, 'rdoc/generator/darkfish'
- autoload :JsonIndex, 'rdoc/generator/json_index'
- autoload :RI, 'rdoc/generator/ri'
- autoload :POT, 'rdoc/generator/pot'
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/generator/darkfish.rb b/ruby_2_2/lib/rdoc/generator/darkfish.rb
deleted file mode 100644
index 024040466d..0000000000
--- a/ruby_2_2/lib/rdoc/generator/darkfish.rb
+++ /dev/null
@@ -1,760 +0,0 @@
-# -*- mode: ruby; ruby-indent-level: 2; tab-width: 2 -*-
-
-require 'erb'
-require 'fileutils'
-require 'pathname'
-require 'rdoc/generator/markup'
-
-##
-# Darkfish RDoc HTML Generator
-#
-# $Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $
-#
-# == Author/s
-# * Michael Granger (ged@FaerieMUD.org)
-#
-# == Contributors
-# * Mahlon E. Smith (mahlon@martini.nu)
-# * Eric Hodel (drbrain@segment7.net)
-#
-# == License
-#
-# Copyright (c) 2007, 2008, Michael Granger. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# * Redistributions of source code must retain the above copyright notice,
-# this list of conditions and the following disclaimer.
-#
-# * Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-#
-# * Neither the name of the author/s, nor the names of the project's
-# contributors may be used to endorse or promote products derived from this
-# software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-# == Attributions
-#
-# Darkfish uses the {Silk Icons}[http://www.famfamfam.com/lab/icons/silk/] set
-# by Mark James.
-
-class RDoc::Generator::Darkfish
-
- RDoc::RDoc.add_generator self
-
- include ERB::Util
-
- ##
- # Stylesheets, fonts, etc. that are included in RDoc.
-
- BUILTIN_STYLE_ITEMS = # :nodoc:
- %w[
- css/fonts.css
- fonts/Lato-Light.ttf
- fonts/Lato-LightItalic.ttf
- fonts/Lato-Regular.ttf
- fonts/Lato-RegularItalic.ttf
- fonts/SourceCodePro-Bold.ttf
- fonts/SourceCodePro-Regular.ttf
- css/rdoc.css
- ]
-
- ##
- # Path to this file's parent directory. Used to find templates and other
- # resources.
-
- GENERATOR_DIR = File.join 'rdoc', 'generator'
-
- ##
- # Release Version
-
- VERSION = '3'
-
- ##
- # Description of this generator
-
- DESCRIPTION = 'HTML generator, written by Michael Granger'
-
- ##
- # The relative path to style sheets and javascript. By default this is set
- # the same as the rel_prefix.
-
- attr_accessor :asset_rel_path
-
- ##
- # The path to generate files into, combined with <tt>--op</tt> from the
- # options for a full path.
-
- attr_reader :base_dir
-
- ##
- # Classes and modules to be used by this generator, not necessarily
- # displayed. See also #modsort
-
- attr_reader :classes
-
- ##
- # No files will be written when dry_run is true.
-
- attr_accessor :dry_run
-
- ##
- # When false the generate methods return a String instead of writing to a
- # file. The default is true.
-
- attr_accessor :file_output
-
- ##
- # Files to be displayed by this generator
-
- attr_reader :files
-
- ##
- # The JSON index generator for this Darkfish generator
-
- attr_reader :json_index
-
- ##
- # Methods to be displayed by this generator
-
- attr_reader :methods
-
- ##
- # Sorted list of classes and modules to be displayed by this generator
-
- attr_reader :modsort
-
- ##
- # The RDoc::Store that is the source of the generated content
-
- attr_reader :store
-
- ##
- # The directory where the template files live
-
- attr_reader :template_dir # :nodoc:
-
- ##
- # The output directory
-
- attr_reader :outputdir
-
- ##
- # Initialize a few instance variables before we start
-
- def initialize store, options
- @store = store
- @options = options
-
- @asset_rel_path = ''
- @base_dir = Pathname.pwd.expand_path
- @dry_run = @options.dry_run
- @file_output = true
- @template_dir = Pathname.new options.template_dir
- @template_cache = {}
-
- @classes = nil
- @context = nil
- @files = nil
- @methods = nil
- @modsort = nil
-
- @json_index = RDoc::Generator::JsonIndex.new self, options
- end
-
- ##
- # Output progress information if debugging is enabled
-
- def debug_msg *msg
- return unless $DEBUG_RDOC
- $stderr.puts(*msg)
- end
-
- ##
- # Directory where generated class HTML files live relative to the output
- # dir.
-
- def class_dir
- nil
- end
-
- ##
- # Directory where generated class HTML files live relative to the output
- # dir.
-
- def file_dir
- nil
- end
-
- ##
- # Create the directories the generated docs will live in if they don't
- # already exist.
-
- def gen_sub_directories
- @outputdir.mkpath
- end
-
- ##
- # Copy over the stylesheet into the appropriate place in the output
- # directory.
-
- def write_style_sheet
- debug_msg "Copying static files"
- options = { :verbose => $DEBUG_RDOC, :noop => @dry_run }
-
- BUILTIN_STYLE_ITEMS.each do |item|
- install_rdoc_static_file @template_dir + item, "./#{item}", options
- end
-
- @options.template_stylesheets.each do |stylesheet|
- FileUtils.cp stylesheet, '.', options
- end
-
- Dir[(@template_dir + "{js,images}/**/*").to_s].each do |path|
- next if File.directory? path
- next if File.basename(path) =~ /^\./
-
- dst = Pathname.new(path).relative_path_from @template_dir
-
- install_rdoc_static_file @template_dir + path, dst, options
- end
- end
-
- ##
- # Build the initial indices and output objects based on an array of TopLevel
- # objects containing the extracted information.
-
- def generate
- setup
-
- write_style_sheet
- generate_index
- generate_class_files
- generate_file_files
- generate_table_of_contents
- @json_index.generate
- @json_index.generate_gzipped
-
- copy_static
-
- rescue => e
- debug_msg "%s: %s\n %s" % [
- e.class.name, e.message, e.backtrace.join("\n ")
- ]
-
- raise
- end
-
- ##
- # Copies static files from the static_path into the output directory
-
- def copy_static
- return if @options.static_path.empty?
-
- fu_options = { :verbose => $DEBUG_RDOC, :noop => @dry_run }
-
- @options.static_path.each do |path|
- unless File.directory? path then
- FileUtils.install path, @outputdir, fu_options.merge(:mode => 0644)
- next
- end
-
- Dir.chdir path do
- Dir[File.join('**', '*')].each do |entry|
- dest_file = @outputdir + entry
-
- if File.directory? entry then
- FileUtils.mkdir_p entry, fu_options
- else
- FileUtils.install entry, dest_file, fu_options.merge(:mode => 0644)
- end
- end
- end
- end
- end
-
- ##
- # Return a list of the documented modules sorted by salience first, then
- # by name.
-
- def get_sorted_module_list classes
- classes.select do |klass|
- klass.display?
- end.sort
- end
-
- ##
- # Generate an index page which lists all the classes which are documented.
-
- def generate_index
- setup
-
- template_file = @template_dir + 'index.rhtml'
- return unless template_file.exist?
-
- debug_msg "Rendering the index page..."
-
- out_file = @base_dir + @options.op_dir + 'index.html'
- rel_prefix = @outputdir.relative_path_from out_file.dirname
- search_index_rel_prefix = rel_prefix
- search_index_rel_prefix += @asset_rel_path if @file_output
-
- # suppress 1.9.3 warning
- asset_rel_prefix = asset_rel_prefix = rel_prefix + @asset_rel_path
-
- @title = @options.title
-
- render_template template_file, out_file do |io| binding end
- rescue => e
- error = RDoc::Error.new \
- "error generating index.html: #{e.message} (#{e.class})"
- error.set_backtrace e.backtrace
-
- raise error
- end
-
- ##
- # Generates a class file for +klass+
-
- def generate_class klass, template_file = nil
- setup
-
- current = klass
-
- template_file ||= @template_dir + 'class.rhtml'
-
- debug_msg " working on %s (%s)" % [klass.full_name, klass.path]
- out_file = @outputdir + klass.path
- rel_prefix = @outputdir.relative_path_from out_file.dirname
- search_index_rel_prefix = rel_prefix
- search_index_rel_prefix += @asset_rel_path if @file_output
-
- # suppress 1.9.3 warning
- asset_rel_prefix = asset_rel_prefix = rel_prefix + @asset_rel_path
- svninfo = svninfo = get_svninfo(current)
-
- @title = "#{klass.type} #{klass.full_name} - #{@options.title}"
-
- debug_msg " rendering #{out_file}"
- render_template template_file, out_file do |io| binding end
- end
-
- ##
- # Generate a documentation file for each class and module
-
- def generate_class_files
- setup
-
- template_file = @template_dir + 'class.rhtml'
- template_file = @template_dir + 'classpage.rhtml' unless
- template_file.exist?
- return unless template_file.exist?
- debug_msg "Generating class documentation in #{@outputdir}"
-
- current = nil
-
- @classes.each do |klass|
- current = klass
-
- generate_class klass, template_file
- end
- rescue => e
- error = RDoc::Error.new \
- "error generating #{current.path}: #{e.message} (#{e.class})"
- error.set_backtrace e.backtrace
-
- raise error
- end
-
- ##
- # Generate a documentation file for each file
-
- def generate_file_files
- setup
-
- page_file = @template_dir + 'page.rhtml'
- fileinfo_file = @template_dir + 'fileinfo.rhtml'
-
- # for legacy templates
- filepage_file = @template_dir + 'filepage.rhtml' unless
- page_file.exist? or fileinfo_file.exist?
-
- return unless
- page_file.exist? or fileinfo_file.exist? or filepage_file.exist?
-
- debug_msg "Generating file documentation in #{@outputdir}"
-
- out_file = nil
- current = nil
-
- @files.each do |file|
- current = file
-
- if file.text? and page_file.exist? then
- generate_page file
- next
- end
-
- template_file = nil
- out_file = @outputdir + file.path
- debug_msg " working on %s (%s)" % [file.full_name, out_file]
- rel_prefix = @outputdir.relative_path_from out_file.dirname
- search_index_rel_prefix = rel_prefix
- search_index_rel_prefix += @asset_rel_path if @file_output
-
- # suppress 1.9.3 warning
- asset_rel_prefix = asset_rel_prefix = rel_prefix + @asset_rel_path
-
- unless filepage_file then
- if file.text? then
- next unless page_file.exist?
- template_file = page_file
- @title = file.page_name
- else
- next unless fileinfo_file.exist?
- template_file = fileinfo_file
- @title = "File: #{file.base_name}"
- end
- end
-
- @title += " - #{@options.title}"
- template_file ||= filepage_file
-
- render_template template_file, out_file do |io| binding end
- end
- rescue => e
- error =
- RDoc::Error.new "error generating #{out_file}: #{e.message} (#{e.class})"
- error.set_backtrace e.backtrace
-
- raise error
- end
-
- ##
- # Generate a page file for +file+
-
- def generate_page file
- setup
-
- template_file = @template_dir + 'page.rhtml'
-
- out_file = @outputdir + file.path
- debug_msg " working on %s (%s)" % [file.full_name, out_file]
- rel_prefix = @outputdir.relative_path_from out_file.dirname
- search_index_rel_prefix = rel_prefix
- search_index_rel_prefix += @asset_rel_path if @file_output
-
- # suppress 1.9.3 warning
- current = current = file
- asset_rel_prefix = asset_rel_prefix = rel_prefix + @asset_rel_path
-
- @title = "#{file.page_name} - #{@options.title}"
-
- debug_msg " rendering #{out_file}"
- render_template template_file, out_file do |io| binding end
- end
-
- ##
- # Generates the 404 page for the RDoc servlet
-
- def generate_servlet_not_found message
- setup
-
- template_file = @template_dir + 'servlet_not_found.rhtml'
- return unless template_file.exist?
-
- debug_msg "Rendering the servlet 404 Not Found page..."
-
- rel_prefix = rel_prefix = ''
- search_index_rel_prefix = rel_prefix
- search_index_rel_prefix += @asset_rel_path if @file_output
-
- # suppress 1.9.3 warning
- asset_rel_prefix = asset_rel_prefix = ''
-
- @title = 'Not Found'
-
- render_template template_file do |io| binding end
- rescue => e
- error = RDoc::Error.new \
- "error generating servlet_not_found: #{e.message} (#{e.class})"
- error.set_backtrace e.backtrace
-
- raise error
- end
-
- ##
- # Generates the servlet root page for the RDoc servlet
-
- def generate_servlet_root installed
- setup
-
- template_file = @template_dir + 'servlet_root.rhtml'
- return unless template_file.exist?
-
- debug_msg 'Rendering the servlet root page...'
-
- rel_prefix = '.'
- asset_rel_prefix = rel_prefix
- search_index_rel_prefix = asset_rel_prefix
- search_index_rel_prefix += @asset_rel_path if @file_output
-
- @title = 'Local RDoc Documentation'
-
- render_template template_file do |io| binding end
- rescue => e
- error = RDoc::Error.new \
- "error generating servlet_root: #{e.message} (#{e.class})"
- error.set_backtrace e.backtrace
-
- raise error
- end
-
- ##
- # Generate an index page which lists all the classes which are documented.
-
- def generate_table_of_contents
- setup
-
- template_file = @template_dir + 'table_of_contents.rhtml'
- return unless template_file.exist?
-
- debug_msg "Rendering the Table of Contents..."
-
- out_file = @outputdir + 'table_of_contents.html'
- rel_prefix = @outputdir.relative_path_from out_file.dirname
- search_index_rel_prefix = rel_prefix
- search_index_rel_prefix += @asset_rel_path if @file_output
-
- # suppress 1.9.3 warning
- asset_rel_prefix = asset_rel_prefix = rel_prefix + @asset_rel_path
-
- @title = "Table of Contents - #{@options.title}"
-
- render_template template_file, out_file do |io| binding end
- rescue => e
- error = RDoc::Error.new \
- "error generating table_of_contents.html: #{e.message} (#{e.class})"
- error.set_backtrace e.backtrace
-
- raise error
- end
-
- def install_rdoc_static_file source, destination, options # :nodoc:
- return unless source.exist?
-
- begin
- FileUtils.mkdir_p File.dirname(destination), options
-
- begin
- FileUtils.ln source, destination, options
- rescue Errno::EEXIST
- FileUtils.rm destination
- retry
- end
- rescue
- FileUtils.cp source, destination, options
- end
- end
-
- ##
- # Prepares for generation of output from the current directory
-
- def setup
- return if instance_variable_defined? :@outputdir
-
- @outputdir = Pathname.new(@options.op_dir).expand_path @base_dir
-
- return unless @store
-
- @classes = @store.all_classes_and_modules.sort
- @files = @store.all_files.sort
- @methods = @classes.map { |m| m.method_list }.flatten.sort
- @modsort = get_sorted_module_list @classes
- end
-
- ##
- # Return a string describing the amount of time in the given number of
- # seconds in terms a human can understand easily.
-
- def time_delta_string seconds
- return 'less than a minute' if seconds < 60
- return "#{seconds / 60} minute#{seconds / 60 == 1 ? '' : 's'}" if
- seconds < 3000 # 50 minutes
- return 'about one hour' if seconds < 5400 # 90 minutes
- return "#{seconds / 3600} hours" if seconds < 64800 # 18 hours
- return 'one day' if seconds < 86400 # 1 day
- return 'about one day' if seconds < 172800 # 2 days
- return "#{seconds / 86400} days" if seconds < 604800 # 1 week
- return 'about one week' if seconds < 1209600 # 2 week
- return "#{seconds / 604800} weeks" if seconds < 7257600 # 3 months
- return "#{seconds / 2419200} months" if seconds < 31536000 # 1 year
- return "#{seconds / 31536000} years"
- end
-
- # %q$Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $"
- SVNID_PATTERN = /
- \$Id:\s
- (\S+)\s # filename
- (\d+)\s # rev
- (\d{4}-\d{2}-\d{2})\s # Date (YYYY-MM-DD)
- (\d{2}:\d{2}:\d{2}Z)\s # Time (HH:MM:SSZ)
- (\w+)\s # committer
- \$$
- /x
-
- ##
- # Try to extract Subversion information out of the first constant whose
- # value looks like a subversion Id tag. If no matching constant is found,
- # and empty hash is returned.
-
- def get_svninfo klass
- constants = klass.constants or return {}
-
- constants.find { |c| c.value =~ SVNID_PATTERN } or return {}
-
- filename, rev, date, time, committer = $~.captures
- commitdate = Time.parse "#{date} #{time}"
-
- return {
- :filename => filename,
- :rev => Integer(rev),
- :commitdate => commitdate,
- :commitdelta => time_delta_string(Time.now - commitdate),
- :committer => committer,
- }
- end
-
- ##
- # Creates a template from its components and the +body_file+.
- #
- # For backwards compatibility, if +body_file+ contains "<html" the body is
- # used directly.
-
- def assemble_template body_file
- body = body_file.read
- return body if body =~ /<html/
-
- head_file = @template_dir + '_head.rhtml'
- footer_file = @template_dir + '_footer.rhtml'
-
- <<-TEMPLATE
-<!DOCTYPE html>
-
-<html>
-<head>
-#{head_file.read}
-
-#{body}
-
-#{footer_file.read}
- TEMPLATE
- end
-
- ##
- # Renders the ERb contained in +file_name+ relative to the template
- # directory and returns the result based on the current context.
-
- def render file_name
- template_file = @template_dir + file_name
-
- template = template_for template_file, false, RDoc::ERBPartial
-
- template.filename = template_file.to_s
-
- template.result @context
- end
-
- ##
- # Load and render the erb template in the given +template_file+ and write
- # it out to +out_file+.
- #
- # Both +template_file+ and +out_file+ should be Pathname-like objects.
- #
- # An io will be yielded which must be captured by binding in the caller.
-
- def render_template template_file, out_file = nil # :yield: io
- io_output = out_file && !@dry_run && @file_output
- erb_klass = io_output ? RDoc::ERBIO : ERB
-
- template = template_for template_file, true, erb_klass
-
- if io_output then
- debug_msg "Outputting to %s" % [out_file.expand_path]
-
- out_file.dirname.mkpath
- out_file.open 'w', 0644 do |io|
- io.set_encoding @options.encoding if Object.const_defined? :Encoding
-
- @context = yield io
-
- template_result template, @context, template_file
- end
- else
- @context = yield nil
-
- output = template_result template, @context, template_file
-
- debug_msg " would have written %d characters to %s" % [
- output.length, out_file.expand_path
- ] if @dry_run
-
- output
- end
- end
-
- ##
- # Creates the result for +template+ with +context+. If an error is raised a
- # Pathname +template_file+ will indicate the file where the error occurred.
-
- def template_result template, context, template_file
- template.filename = template_file.to_s
- template.result context
- rescue NoMethodError => e
- raise RDoc::Error, "Error while evaluating %s: %s" % [
- template_file.expand_path,
- e.message,
- ], e.backtrace
- end
-
- ##
- # Retrieves a cache template for +file+, if present, or fills the cache.
-
- def template_for file, page = true, klass = ERB
- template = @template_cache[file]
-
- return template if template
-
- if page then
- template = assemble_template file
- erbout = 'io'
- else
- template = file.read
- template = template.encode @options.encoding if
- Object.const_defined? :Encoding
-
- file_var = File.basename(file).sub(/\..*/, '')
-
- erbout = "_erbout_#{file_var}"
- end
-
- template = klass.new template, nil, '<>', erbout
- @template_cache[file] = template
- template
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/generator/json_index.rb b/ruby_2_2/lib/rdoc/generator/json_index.rb
deleted file mode 100644
index 9d6f0d4356..0000000000
--- a/ruby_2_2/lib/rdoc/generator/json_index.rb
+++ /dev/null
@@ -1,292 +0,0 @@
-require 'json'
-require 'zlib'
-
-##
-# The JsonIndex generator is designed to complement an HTML generator and
-# produces a JSON search index. This generator is derived from sdoc by
-# Vladimir Kolesnikov and contains verbatim code written by him.
-#
-# This generator is designed to be used with a regular HTML generator:
-#
-# class RDoc::Generator::Darkfish
-# def initialize options
-# # ...
-# @base_dir = Pathname.pwd.expand_path
-#
-# @json_index = RDoc::Generator::JsonIndex.new self, options
-# end
-#
-# def generate
-# # ...
-# @json_index.generate
-# end
-# end
-#
-# == Index Format
-#
-# The index is output as a JSON file assigned to the global variable
-# +search_data+. The structure is:
-#
-# var search_data = {
-# "index": {
-# "searchIndex":
-# ["a", "b", ...],
-# "longSearchIndex":
-# ["a", "a::b", ...],
-# "info": [
-# ["A", "A", "A.html", "", ""],
-# ["B", "A::B", "A::B.html", "", ""],
-# ...
-# ]
-# }
-# }
-#
-# The same item is described across the +searchIndex+, +longSearchIndex+ and
-# +info+ fields. The +searchIndex+ field contains the item's short name, the
-# +longSearchIndex+ field contains the full_name (when appropriate) and the
-# +info+ field contains the item's name, full_name, path, parameters and a
-# snippet of the item's comment.
-#
-# == LICENSE
-#
-# Copyright (c) 2009 Vladimir Kolesnikov
-#
-# Permission is hereby granted, free of charge, to any person obtaining
-# a copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice shall be
-# included in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-class RDoc::Generator::JsonIndex
-
- include RDoc::Text
-
- ##
- # Where the search index lives in the generated output
-
- SEARCH_INDEX_FILE = File.join 'js', 'search_index.js'
-
- attr_reader :index # :nodoc:
-
- ##
- # Creates a new generator. +parent_generator+ is used to determine the
- # class_dir and file_dir of links in the output index.
- #
- # +options+ are the same options passed to the parent generator.
-
- def initialize parent_generator, options
- @parent_generator = parent_generator
- @store = parent_generator.store
- @options = options
-
- @template_dir = File.expand_path '../template/json_index', __FILE__
- @base_dir = @parent_generator.base_dir
-
- @classes = nil
- @files = nil
- @index = nil
- end
-
- ##
- # Builds the JSON index as a Hash.
-
- def build_index
- reset @store.all_files.sort, @store.all_classes_and_modules.sort
-
- index_classes
- index_methods
- index_pages
-
- { :index => @index }
- end
-
- ##
- # Output progress information if debugging is enabled
-
- def debug_msg *msg
- return unless $DEBUG_RDOC
- $stderr.puts(*msg)
- end
-
- ##
- # Writes the JSON index to disk
-
- def generate
- debug_msg "Generating JSON index"
-
- debug_msg " writing search index to %s" % SEARCH_INDEX_FILE
- data = build_index
-
- return if @options.dry_run
-
- out_dir = @base_dir + @options.op_dir
- index_file = out_dir + SEARCH_INDEX_FILE
-
- FileUtils.mkdir_p index_file.dirname, :verbose => $DEBUG_RDOC
-
- index_file.open 'w', 0644 do |io|
- io.set_encoding Encoding::UTF_8 if Object.const_defined? :Encoding
- io.write 'var search_data = '
-
- JSON.dump data, io, 0
- end
-
- Dir.chdir @template_dir do
- Dir['**/*.js'].each do |source|
- dest = File.join out_dir, source
-
- FileUtils.install source, dest, :mode => 0644, :verbose => $DEBUG_RDOC
- end
- end
- end
-
- ##
- # Compress the search_index.js file using gzip
-
- def generate_gzipped
- debug_msg "Compressing generated JSON index"
- out_dir = @base_dir + @options.op_dir
-
- search_index_file = out_dir + SEARCH_INDEX_FILE
- outfile = out_dir + "#{search_index_file}.gz"
-
- debug_msg "Reading the JSON index file from %s" % search_index_file
- search_index = search_index_file.read
-
- debug_msg "Writing gzipped search index to %s" % outfile
-
- Zlib::GzipWriter.open(outfile) do |gz|
- gz.mtime = File.mtime(search_index_file)
- gz.orig_name = search_index_file.to_s
- gz.write search_index
- gz.close
- end
-
- # GZip the rest of the js files
- Dir.chdir @template_dir do
- Dir['**/*.js'].each do |source|
- dest = out_dir + source
- outfile = out_dir + "#{dest}.gz"
-
- debug_msg "Reading the original js file from %s" % dest
- data = dest.read
-
- debug_msg "Writing gzipped file to %s" % outfile
-
- Zlib::GzipWriter.open(outfile) do |gz|
- gz.mtime = File.mtime(dest)
- gz.orig_name = dest.to_s
- gz.write data
- gz.close
- end
- end
- end
- end
-
- ##
- # Adds classes and modules to the index
-
- def index_classes
- debug_msg " generating class search index"
-
- documented = @classes.uniq.select do |klass|
- klass.document_self_or_methods
- end
-
- documented.each do |klass|
- debug_msg " #{klass.full_name}"
- record = klass.search_record
- @index[:searchIndex] << search_string(record.shift)
- @index[:longSearchIndex] << search_string(record.shift)
- @index[:info] << record
- end
- end
-
- ##
- # Adds methods to the index
-
- def index_methods
- debug_msg " generating method search index"
-
- list = @classes.uniq.map do |klass|
- klass.method_list
- end.flatten.sort_by do |method|
- [method.name, method.parent.full_name]
- end
-
- list.each do |method|
- debug_msg " #{method.full_name}"
- record = method.search_record
- @index[:searchIndex] << "#{search_string record.shift}()"
- @index[:longSearchIndex] << "#{search_string record.shift}()"
- @index[:info] << record
- end
- end
-
- ##
- # Adds pages to the index
-
- def index_pages
- debug_msg " generating pages search index"
-
- pages = @files.select do |file|
- file.text?
- end
-
- pages.each do |page|
- debug_msg " #{page.page_name}"
- record = page.search_record
- @index[:searchIndex] << search_string(record.shift)
- @index[:longSearchIndex] << ''
- record.shift
- @index[:info] << record
- end
- end
-
- ##
- # The directory classes are written to
-
- def class_dir
- @parent_generator.class_dir
- end
-
- ##
- # The directory files are written to
-
- def file_dir
- @parent_generator.file_dir
- end
-
- def reset files, classes # :nodoc:
- @files = files
- @classes = classes
-
- @index = {
- :searchIndex => [],
- :longSearchIndex => [],
- :info => []
- }
- end
-
- ##
- # Removes whitespace and downcases +string+
-
- def search_string string
- string.downcase.gsub(/\s/, '')
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/generator/markup.rb b/ruby_2_2/lib/rdoc/generator/markup.rb
deleted file mode 100644
index 788e5a485d..0000000000
--- a/ruby_2_2/lib/rdoc/generator/markup.rb
+++ /dev/null
@@ -1,169 +0,0 @@
-##
-# Handle common RDoc::Markup tasks for various CodeObjects
-#
-# This module is loaded by generators. It allows RDoc's CodeObject tree to
-# avoid loading generator code to improve startup time for +ri+.
-
-module RDoc::Generator::Markup
-
- ##
- # Generates a relative URL from this object's path to +target_path+
-
- def aref_to(target_path)
- RDoc::Markup::ToHtml.gen_relative_url path, target_path
- end
-
- ##
- # Generates a relative URL from +from_path+ to this object's path
-
- def as_href(from_path)
- RDoc::Markup::ToHtml.gen_relative_url from_path, path
- end
-
- ##
- # Handy wrapper for marking up this object's comment
-
- def description
- markup @comment
- end
-
- ##
- # Creates an RDoc::Markup::ToHtmlCrossref formatter
-
- def formatter
- return @formatter if defined? @formatter
-
- options = @store.rdoc.options
- this = RDoc::Context === self ? self : @parent
-
- @formatter = RDoc::Markup::ToHtmlCrossref.new options, this.path, this
- @formatter.code_object = self
- @formatter
- end
-
- ##
- # Build a webcvs URL starting for the given +url+ with +full_path+ appended
- # as the destination path. If +url+ contains '%s' +full_path+ will be
- # will replace the %s using sprintf on the +url+.
-
- def cvs_url(url, full_path)
- if /%s/ =~ url then
- sprintf url, full_path
- else
- url + full_path
- end
- end
-
-end
-
-class RDoc::CodeObject
-
- include RDoc::Generator::Markup
-
-end
-
-class RDoc::MethodAttr
-
- @add_line_numbers = false
-
- class << self
- ##
- # Allows controlling whether <tt>#markup_code</tt> adds line numbers to
- # the source code.
-
- attr_accessor :add_line_numbers
- end
-
- ##
- # Prepend +src+ with line numbers. Relies on the first line of a source
- # code listing having:
- #
- # # File xxxxx, line dddd
- #
- # If it has this comment then line numbers are added to +src+ and the <tt>,
- # line dddd</tt> portion of the comment is removed.
-
- def add_line_numbers(src)
- return unless src.sub!(/\A(.*)(, line (\d+))/, '\1')
- first = $3.to_i - 1
- last = first + src.count("\n")
- size = last.to_s.length
-
- line = first
- src.gsub!(/^/) do
- res = if line == first then
- " " * (size + 1)
- else
- "<span class=\"line-num\">%2$*1$d</span> " % [size, line]
- end
-
- line += 1
- res
- end
- end
-
- ##
- # Turns the method's token stream into HTML.
- #
- # Prepends line numbers if +add_line_numbers+ is true.
-
- def markup_code
- return '' unless @token_stream
-
- src = RDoc::TokenStream.to_html @token_stream
-
- # dedent the source
- indent = src.length
- lines = src.lines.to_a
- lines.shift if src =~ /\A.*#\ *File/i # remove '# File' comment
- lines.each do |line|
- if line =~ /^ *(?=\S)/
- n = $&.length
- indent = n if n < indent
- break if n == 0
- end
- end
- src.gsub!(/^#{' ' * indent}/, '') if indent > 0
-
- add_line_numbers(src) if RDoc::MethodAttr.add_line_numbers
-
- src
- end
-
-end
-
-class RDoc::ClassModule
-
- ##
- # Handy wrapper for marking up this class or module's comment
-
- def description
- markup @comment_location
- end
-
-end
-
-class RDoc::Context::Section
-
- include RDoc::Generator::Markup
-
-end
-
-class RDoc::TopLevel
-
- ##
- # Returns a URL for this source file on some web repository. Use the -W
- # command line option to set.
-
- def cvs_url
- url = @store.rdoc.options.webcvs
-
- if /%s/ =~ url then
- url % @relative_name
- else
- url + @relative_name
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/generator/pot.rb b/ruby_2_2/lib/rdoc/generator/pot.rb
deleted file mode 100644
index db6f3a0354..0000000000
--- a/ruby_2_2/lib/rdoc/generator/pot.rb
+++ /dev/null
@@ -1,97 +0,0 @@
-##
-# Generates a POT file.
-#
-# Here is a translator work flow with the generator.
-#
-# == Create .pot
-#
-# You create .pot file by pot formatter:
-#
-# % rdoc --format pot
-#
-# It generates doc/rdoc.pot.
-#
-# == Create .po
-#
-# You create .po file from doc/rdoc.pot. This operation is needed only
-# the first time. This work flow assumes that you are a translator
-# for Japanese.
-#
-# You create locale/ja/rdoc.po from doc/rdoc.pot. You can use msginit
-# provided by GNU gettext or rmsginit provided by gettext gem. This
-# work flow uses gettext gem because it is more portable than GNU
-# gettext for Rubyists. Gettext gem is implemented by pure Ruby.
-#
-# % gem install gettext
-# % mkdir -p locale/ja
-# % rmsginit --input doc/rdoc.pot --output locale/ja/rdoc.po --locale ja
-#
-# Translate messages in .po
-#
-# You translate messages in .po by a PO file editor. po-mode.el exists
-# for Emacs users. There are some GUI tools such as GTranslator.
-# There are some Web services such as POEditor and Tansifex. You can
-# edit by your favorite text editor because .po is a text file.
-# Generate localized documentation
-#
-# You can generate localized documentation with locale/ja/rdoc.po:
-#
-# % rdoc --locale ja
-#
-# You can find documentation in Japanese in doc/. Yay!
-#
-# == Update translation
-#
-# You need to update translation when your application is added or
-# modified messages.
-#
-# You can update .po by the following command lines:
-#
-# % rdoc --format pot
-# % rmsgmerge --update locale/ja/rdoc.po doc/rdoc.pot
-#
-# You edit locale/ja/rdoc.po to translate new messages.
-
-class RDoc::Generator::POT
-
- RDoc::RDoc.add_generator self
-
- ##
- # Description of this generator
-
- DESCRIPTION = 'creates .pot file'
-
- ##
- # Set up a new .pot generator
-
- def initialize store, options #:not-new:
- @options = options
- @store = store
- end
-
- ##
- # Writes .pot to disk.
-
- def generate
- po = extract_messages
- pot_path = 'rdoc.pot'
- File.open(pot_path, "w") do |pot|
- pot.print(po.to_s)
- end
- end
-
- def class_dir
- nil
- end
-
- private
- def extract_messages
- extractor = MessageExtractor.new(@store)
- extractor.extract
- end
-
- autoload :MessageExtractor, 'rdoc/generator/pot/message_extractor'
- autoload :PO, 'rdoc/generator/pot/po'
- autoload :POEntry, 'rdoc/generator/pot/po_entry'
-
-end
diff --git a/ruby_2_2/lib/rdoc/generator/pot/message_extractor.rb b/ruby_2_2/lib/rdoc/generator/pot/message_extractor.rb
deleted file mode 100644
index ceabc5262a..0000000000
--- a/ruby_2_2/lib/rdoc/generator/pot/message_extractor.rb
+++ /dev/null
@@ -1,67 +0,0 @@
-##
-# Extracts message from RDoc::Store
-
-class RDoc::Generator::POT::MessageExtractor
-
- ##
- # Creates a message extractor for +store+.
-
- def initialize store
- @store = store
- @po = RDoc::Generator::POT::PO.new
- end
-
- ##
- # Extracts messages from +store+, stores them into
- # RDoc::Generator::POT::PO and returns it.
-
- def extract
- @store.all_classes_and_modules.each do |klass|
- extract_from_klass(klass)
- end
- @po
- end
-
- private
-
- def extract_from_klass klass
- extract_text(klass.comment_location, klass.full_name)
-
- klass.each_section do |section, constants, attributes|
- extract_text(section.title ,"#{klass.full_name}: section title")
- section.comments.each do |comment|
- extract_text(comment, "#{klass.full_name}: #{section.title}")
- end
- end
-
- klass.each_constant do |constant|
- extract_text(constant.comment, constant.full_name)
- end
-
- klass.each_attribute do |attribute|
- extract_text(attribute.comment, attribute.full_name)
- end
-
- klass.each_method do |method|
- extract_text(method.comment, method.full_name)
- end
- end
-
- def extract_text text, comment, location = nil
- return if text.nil?
-
- options = {
- :extracted_comment => comment,
- :references => [location].compact,
- }
- i18n_text = RDoc::I18n::Text.new(text)
- i18n_text.extract_messages do |part|
- @po.add(entry(part[:paragraph], options))
- end
- end
-
- def entry msgid, options
- RDoc::Generator::POT::POEntry.new(msgid, options)
- end
-
-end
diff --git a/ruby_2_2/lib/rdoc/generator/pot/po.rb b/ruby_2_2/lib/rdoc/generator/pot/po.rb
deleted file mode 100644
index 6a6b5821f3..0000000000
--- a/ruby_2_2/lib/rdoc/generator/pot/po.rb
+++ /dev/null
@@ -1,83 +0,0 @@
-##
-# Generates a PO format text
-
-class RDoc::Generator::POT::PO
-
- ##
- # Creates an object that represents PO format.
-
- def initialize
- @entries = {}
- add_header
- end
-
- ##
- # Adds a PO entry to the PO.
-
- def add entry
- existing_entry = @entries[entry.msgid]
- if existing_entry
- entry = existing_entry.merge(entry)
- end
- @entries[entry.msgid] = entry
- end
-
- ##
- # Returns PO format text for the PO.
-
- def to_s
- po = ''
- sort_entries.each do |entry|
- po << "\n" unless po.empty?
- po << entry.to_s
- end
- po
- end
-
- private
-
- def add_header
- add(header_entry)
- end
-
- def header_entry
- comment = <<-COMMENT
-SOME DESCRIPTIVE TITLE.
-Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
-This file is distributed under the same license as the PACKAGE package.
-FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
- COMMENT
-
- content = <<-CONTENT
-Project-Id-Version: PACKAGE VERSEION
-Report-Msgid-Bugs-To:
-PO-Revision-Date: YEAR-MO_DA HO:MI+ZONE
-Last-Translator: FULL NAME <EMAIL@ADDRESS>
-Language-Team: LANGUAGE <LL@li.org>
-Language:
-MIME-Version: 1.0
-Content-Type: text/plain; charset=CHARSET
-Content-Transfer-Encoding: 8bit
-Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;
- CONTENT
-
- options = {
- :msgstr => content,
- :translator_comment => comment,
- :flags => ['fuzzy'],
- }
- RDoc::Generator::POT::POEntry.new('', options)
- end
-
- def sort_entries
- headers, messages = @entries.values.partition do |entry|
- entry.msgid.empty?
- end
- # TODO: sort by location
- sorted_messages = messages.sort_by do |entry|
- entry.msgid
- end
- headers + sorted_messages
- end
-
-end
diff --git a/ruby_2_2/lib/rdoc/generator/pot/po_entry.rb b/ruby_2_2/lib/rdoc/generator/pot/po_entry.rb
deleted file mode 100644
index d4cef59ee9..0000000000
--- a/ruby_2_2/lib/rdoc/generator/pot/po_entry.rb
+++ /dev/null
@@ -1,140 +0,0 @@
-##
-# A PO entry in PO
-
-class RDoc::Generator::POT::POEntry
-
- # The msgid content
- attr_reader :msgid
-
- # The msgstr content
- attr_reader :msgstr
-
- # The comment content created by translator (PO editor)
- attr_reader :translator_comment
-
- # The comment content extracted from source file
- attr_reader :extracted_comment
-
- # The locations where the PO entry is extracted
- attr_reader :references
-
- # The flags of the PO entry
- attr_reader :flags
-
- ##
- # Creates a PO entry for +msgid+. Other valus can be specified by
- # +options+.
-
- def initialize msgid, options = {}
- @msgid = msgid
- @msgstr = options[:msgstr] || ""
- @translator_comment = options[:translator_comment]
- @extracted_comment = options[:extracted_comment]
- @references = options[:references] || []
- @flags = options[:flags] || []
- end
-
- ##
- # Returns the PO entry in PO format.
-
- def to_s
- entry = ''
- entry << format_translator_comment
- entry << format_extracted_comment
- entry << format_references
- entry << format_flags
- entry << <<-ENTRY
-msgid #{format_message(@msgid)}
-msgstr #{format_message(@msgstr)}
- ENTRY
- end
-
- ##
- # Merges the PO entry with +other_entry+.
-
- def merge other_entry
- options = {
- :extracted_comment => merge_string(@extracted_comment,
- other_entry.extracted_comment),
- :translator_comment => merge_string(@translator_comment,
- other_entry.translator_comment),
- :references => merge_array(@references,
- other_entry.references),
- :flags => merge_array(@flags,
- other_entry.flags),
- }
- self.class.new(@msgid, options)
- end
-
- private
-
- def format_comment mark, comment
- return '' unless comment
- return '' if comment.empty?
-
- formatted_comment = ''
- comment.each_line do |line|
- formatted_comment << "#{mark} #{line}"
- end
- formatted_comment << "\n" unless formatted_comment.end_with?("\n")
- formatted_comment
- end
-
- def format_translator_comment
- format_comment('#', @translator_comment)
- end
-
- def format_extracted_comment
- format_comment('#.', @extracted_comment)
- end
-
- def format_references
- return '' if @references.empty?
-
- formatted_references = ''
- @references.sort.each do |file, line|
- formatted_references << "\#: #{file}:#{line}\n"
- end
- formatted_references
- end
-
- def format_flags
- return '' if @flags.empty?
-
- formatted_flags = flags.join(",")
- "\#, #{formatted_flags}\n"
- end
-
- def format_message message
- return "\"#{escape(message)}\"" unless message.include?("\n")
-
- formatted_message = '""'
- message.each_line do |line|
- formatted_message << "\n"
- formatted_message << "\"#{escape(line)}\""
- end
- formatted_message
- end
-
- def escape string
- string.gsub(/["\\\t\n]/) do |special_character|
- case special_character
- when "\t"
- "\\t"
- when "\n"
- "\\n"
- else
- "\\#{special_character}"
- end
- end
- end
-
- def merge_string string1, string2
- [string1, string2].compact.join("\n")
- end
-
- def merge_array array1, array2
- (array1 + array2).uniq
- end
-
-end
diff --git a/ruby_2_2/lib/rdoc/generator/ri.rb b/ruby_2_2/lib/rdoc/generator/ri.rb
deleted file mode 100644
index b9c4141a5e..0000000000
--- a/ruby_2_2/lib/rdoc/generator/ri.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-##
-# Generates ri data files
-
-class RDoc::Generator::RI
-
- RDoc::RDoc.add_generator self
-
- ##
- # Description of this generator
-
- DESCRIPTION = 'creates ri data files'
-
- ##
- # Set up a new ri generator
-
- def initialize store, options #:not-new:
- @options = options
- @store = store
- @store.path = '.'
- end
-
- ##
- # Writes the parsed data store to disk for use by ri.
-
- def generate
- @store.save
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/.document b/ruby_2_2/lib/rdoc/generator/template/darkfish/.document
deleted file mode 100644
index e69de29bb2..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/.document
+++ /dev/null
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/_footer.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/_footer.rhtml
deleted file mode 100644
index fe5822cc6b..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/_footer.rhtml
+++ /dev/null
@@ -1,5 +0,0 @@
-<footer id="validator-badges" role="contentinfo">
- <p><a href="http://validator.w3.org/check/referer">Validate</a>
- <p>Generated by <a href="http://docs.seattlerb.org/rdoc/">RDoc</a> <%= RDoc::VERSION %>.
- <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
-</footer>
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/_head.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/_head.rhtml
deleted file mode 100644
index 70f1c188d6..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/_head.rhtml
+++ /dev/null
@@ -1,19 +0,0 @@
-<meta charset="<%= @options.charset %>">
-
-<title><%= h @title %></title>
-
-<script type="text/javascript">
- var rdoc_rel_prefix = "<%= rel_prefix %>/";
-</script>
-
-<script src="<%= asset_rel_prefix %>/js/jquery.js"></script>
-<script src="<%= asset_rel_prefix %>/js/darkfish.js"></script>
-
-<link href="<%= asset_rel_prefix %>/css/fonts.css" rel="stylesheet">
-<link href="<%= asset_rel_prefix %>/css/rdoc.css" rel="stylesheet">
-<% if @options.template_stylesheets.flatten.any? then %>
-<% @options.template_stylesheets.flatten.each do |stylesheet| %>
-<link href="<%= asset_rel_prefix %>/<%= File.basename stylesheet %>" rel="stylesheet">
-<% end %>
-<% end %>
-
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml
deleted file mode 100644
index e889f8063d..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml
+++ /dev/null
@@ -1,19 +0,0 @@
-<% if !svninfo.empty? then %>
-<div id="file-svninfo-section" class="nav-section">
- <h3>VCS Info</h3>
-
- <div class="section-body">
- <dl class="svninfo">
- <dt>Rev
- <dd><%= svninfo[:rev] %>
-
- <dt>Last Checked In
- <dd><%= svninfo[:commitdate].strftime('%Y-%m-%d %H:%M:%S') %>
- (<%= svninfo[:commitdelta] %> ago)
-
- <dt>Checked in by
- <dd><%= svninfo[:committer] %>
- </dl>
- </div>
-</div>
-<% end %>
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml
deleted file mode 100644
index fe54d8339f..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml
+++ /dev/null
@@ -1,9 +0,0 @@
-<div id="classindex-section" class="nav-section">
- <h3>Class and Module Index</h3>
-
- <ul class="link-list">
- <% @modsort.each do |index_klass| %>
- <li><a href="<%= rel_prefix %>/<%= index_klass.path %>"><%= index_klass.full_name %></a>
- <% end %>
- </ul>
-</div>
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml
deleted file mode 100644
index 2bd8efee99..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml
+++ /dev/null
@@ -1,15 +0,0 @@
-<% unless klass.extends.empty? then %>
-<div id="extends-section" class="nav-section">
- <h3>Extended With Modules</h3>
-
- <ul class="link-list">
- <% klass.each_extend do |ext| %>
- <% unless String === ext.module then %>
- <li><a class="extend" href="<%= klass.aref_to ext.module.path %>"><%= ext.module.full_name %></a>
- <% else %>
- <li><span class="extend"><%= ext.name %></span>
- <% end %>
- <% end %>
- </ul>
-</div>
-<% end %>
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml
deleted file mode 100644
index 0ba1d2be80..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml
+++ /dev/null
@@ -1,9 +0,0 @@
-<div id="file-list-section" class="nav-section">
- <h3>Defined In</h3>
-
- <ul>
-<% klass.in_files.each do |tl| %>
- <li><%= h tl.relative_name %>
-<% end %>
- </ul>
-</div>
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml
deleted file mode 100644
index d141098ecd..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml
+++ /dev/null
@@ -1,15 +0,0 @@
-<% unless klass.includes.empty? then %>
-<div id="includes-section" class="nav-section">
- <h3>Included Modules</h3>
-
- <ul class="link-list">
- <% klass.each_include do |inc| %>
- <% unless String === inc.module then %>
- <li><a class="include" href="<%= klass.aref_to inc.module.path %>"><%= inc.module.full_name %></a>
- <% else %>
- <li><span class="include"><%= inc.name %></span>
- <% end %>
- <% end %>
- </ul>
-</div>
-<% end %>
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml
deleted file mode 100644
index 1285bfd732..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml
+++ /dev/null
@@ -1,15 +0,0 @@
-<div id="home-section" class="nav-section">
- <h3>Documentation</h3>
-
- <ul>
- <% installed.each do |name, href, exists, type, _| %>
- <% next if type == :extra %>
- <li class="folder">
- <% if exists then %>
- <a href="<%= href %>"><%= h name %></a>
- <% else %>
- <%= h name %>
- <% end %>
- <% end %>
- </ul>
-</div>
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml
deleted file mode 100644
index 45df08d8fe..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml
+++ /dev/null
@@ -1,12 +0,0 @@
-<% unless klass.method_list.empty? then %>
-<!-- Method Quickref -->
-<div id="method-list-section" class="nav-section">
- <h3>Methods</h3>
-
- <ul class="link-list" role="directory">
- <% klass.each_method do |meth| %>
- <li <% if meth.calls_super %>class="calls-super" <% end %>><a href="#<%= meth.aref %>"><%= meth.singleton ? '::' : '#' %><%= h meth.name %></a>
- <% end %>
- </ul>
-</div>
-<% end %>
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml
deleted file mode 100644
index d7f330840a..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml
+++ /dev/null
@@ -1,11 +0,0 @@
-<div id="home-section" role="region" title="Quick navigation" class="nav-section">
- <h2>
- <a href="<%= rel_prefix %>/index.html" rel="home">Home</a>
- </h2>
-
- <div id="table-of-contents-navigation">
- <a href="<%= rel_prefix %>/table_of_contents.html#pages">Pages</a>
- <a href="<%= rel_prefix %>/table_of_contents.html#classes">Classes</a>
- <a href="<%= rel_prefix %>/table_of_contents.html#methods">Methods</a>
- </div>
-</div>
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml
deleted file mode 100644
index 5f39825f08..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml
+++ /dev/null
@@ -1,12 +0,0 @@
-<% simple_files = @files.select { |f| f.text? } %>
-<% unless simple_files.empty? then %>
-<div id="fileindex-section" class="nav-section">
- <h3>Pages</h3>
-
- <ul class="link-list">
- <% simple_files.each do |f| %>
- <li><a href="<%= rel_prefix %>/<%= f.path %>"><%= h f.page_name %></a>
- <% end %>
- </ul>
-</div>
-<% end %>
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml
deleted file mode 100644
index cc04852652..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml
+++ /dev/null
@@ -1,11 +0,0 @@
-<% if klass.type == 'class' then %>
-<div id="parent-class-section" class="nav-section">
- <h3>Parent</h3>
-
- <% if klass.superclass and not String === klass.superclass then %>
- <p class="link"><a href="<%= klass.aref_to klass.superclass.path %>"><%= klass.superclass.full_name %></a>
- <% else %>
- <p class="link"><%= klass.superclass %>
- <% end %>
-</div>
-<% end %>
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml
deleted file mode 100644
index 9c49b31376..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml
+++ /dev/null
@@ -1,14 +0,0 @@
-<div id="search-section" role="search" class="project-section initially-hidden">
- <form action="#" method="get" accept-charset="utf-8">
- <div id="search-field-wrapper">
- <input id="search-field" role="combobox" aria-label="Search"
- aria-autocomplete="list" aria-controls="search-results"
- type="text" name="search" placeholder="Search" spellcheck="false"
- title="Type to search, Up and Down to navigate, Enter to load">
- </div>
-
- <ul id="search-results" aria-label="Search Results"
- aria-busy="false" aria-expanded="false"
- aria-atomic="false" class="initially-hidden"></ul>
- </form>
-</div>
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml
deleted file mode 100644
index 15ff78ba91..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml
+++ /dev/null
@@ -1,11 +0,0 @@
-<% unless klass.sections.length == 1 then %>
-<div id="sections-section" class="nav-section">
- <h3>Sections</h3>
-
- <ul class="link-list" role="directory">
- <% klass.sort_sections.each do |section| %>
- <li><a href="#<%= section.aref %>"><%= h section.title %></a></li>
- <% end %>
- </ul>
-</div>
-<% end %>
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml
deleted file mode 100644
index b58e6b3c61..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml
+++ /dev/null
@@ -1,18 +0,0 @@
-<% comment = if current.respond_to? :comment_location then
- current.comment_location
- else
- current.comment
- end
- table = current.parse(comment).table_of_contents
-
- if table.length > 1 then %>
-<div class="nav-section">
- <h3>Table of Contents</h3>
-
- <ul class="link-list" role="directory">
-<% table.each do |heading| %>
- <li><a href="#<%= heading.label current %>"><%= heading.plain_html %></a>
-<% end %>
- </ul>
-</div>
-<% end %>
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/class.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/class.rhtml
deleted file mode 100644
index b497000112..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/class.rhtml
+++ /dev/null
@@ -1,174 +0,0 @@
-<body id="top" role="document" class="<%= klass.type %>">
-<nav role="navigation">
- <div id="project-navigation">
- <%= render '_sidebar_navigation.rhtml' %>
- <%= render '_sidebar_search.rhtml' %>
- </div>
-
- <%= render '_sidebar_table_of_contents.rhtml' %>
-
- <div id="class-metadata">
- <%= render '_sidebar_sections.rhtml' %>
- <%= render '_sidebar_parent.rhtml' %>
- <%= render '_sidebar_includes.rhtml' %>
- <%= render '_sidebar_extends.rhtml' %>
- <%= render '_sidebar_methods.rhtml' %>
- </div>
-</nav>
-
-<main role="main" aria-labelledby="<%=h klass.aref %>">
- <h1 id="<%=h klass.aref %>" class="<%= klass.type %>">
- <%= klass.type %> <%= klass.full_name %>
- </h1>
-
- <section class="description">
- <%= klass.description %>
- </section>
-
- <% klass.each_section do |section, constants, attributes| %>
- <% constants = constants.select { |const| const.display? } %>
- <% attributes = attributes.select { |attr| attr.display? } %>
- <section id="<%= section.aref %>" class="documentation-section">
- <% if section.title then %>
- <header class="documentation-section-title">
- <h2>
- <%= section.title %>
- </h2>
- <span class="section-click-top">
- <a href="#top">&uarr; top</a>
- </span>
- </header>
- <% end %>
-
- <% if section.comment then %>
- <div>
- <%= section.description %>
- </div>
- <% end %>
-
- <% unless constants.empty? then %>
- <section class="constants-list">
- <header>
- <h3>Constants</h3>
- </header>
- <dl>
- <% constants.each do |const| %>
- <dt id="<%= const.name %>"><%= const.name %>
- <% if const.comment then %>
- <dd><%= const.description.strip %>
- <% else %>
- <dd class="missing-docs">(Not documented)
- <% end %>
- <% end %>
- </dl>
- </section>
- <% end %>
-
- <% unless attributes.empty? then %>
- <section class="attribute-method-details" class="method-section">
- <header>
- <h3>Attributes</h3>
- </header>
-
- <% attributes.each do |attrib| %>
- <div id="<%= attrib.aref %>" class="method-detail">
- <div class="method-heading attribute-method-heading">
- <span class="method-name"><%= h attrib.name %></span><span
- class="attribute-access-type">[<%= attrib.rw %>]</span>
- </div>
-
- <div class="method-description">
- <% if attrib.comment then %>
- <%= attrib.description.strip %>
- <% else %>
- <p class="missing-docs">(Not documented)
- <% end %>
- </div>
- </div>
- <% end %>
- </section>
- <% end %>
-
- <% klass.methods_by_type(section).each do |type, visibilities|
- next if visibilities.empty?
- visibilities.each do |visibility, methods|
- next if methods.empty? %>
- <section id="<%= visibility %>-<%= type %>-<%= section.aref %>-method-details" class="method-section">
- <header>
- <h3><%= visibility.to_s.capitalize %> <%= type.capitalize %> Methods</h3>
- </header>
-
- <% methods.each do |method| %>
- <div id="<%= method.aref %>" class="method-detail <%= method.is_alias_for ? "method-alias" : '' %>">
- <% if method.call_seq then %>
- <% method.call_seq.strip.split("\n").each_with_index do |call_seq, i| %>
- <div class="method-heading">
- <span class="method-callseq">
- <%= h(call_seq.strip.
- gsub( /^\w+\./m, '')).
- gsub(/(.*)[-=]&gt;/, '\1&rarr;') %>
- </span>
- <% if i == 0 and method.token_stream then %>
- <span class="method-click-advice">click to toggle source</span>
- <% end %>
- </div>
- <% end %>
- <% else %>
- <div class="method-heading">
- <span class="method-name"><%= h method.name %></span><span
- class="method-args"><%= method.param_seq %></span>
- <% if method.token_stream then %>
- <span class="method-click-advice">click to toggle source</span>
- <% end %>
- </div>
- <% end %>
-
- <div class="method-description">
- <% if method.comment then %>
- <%= method.description.strip %>
- <% else %>
- <p class="missing-docs">(Not documented)
- <% end %>
- <% if method.calls_super then %>
- <div class="method-calls-super">
- Calls superclass method
- <%=
- method.superclass_method ?
- method.formatter.link(method.superclass_method.full_name, method.superclass_method.full_name) : nil
- %>
- </div>
- <% end %>
-
- <% if method.token_stream then %>
- <div class="method-source-code" id="<%= method.html_name %>-source">
- <pre><%= method.markup_code %></pre>
- </div>
- <% end %>
- </div>
-
- <% unless method.aliases.empty? then %>
- <div class="aliases">
- Also aliased as: <%= method.aliases.map do |aka|
- if aka.parent then # HACK lib/rexml/encodings
- %{<a href="#{klass.aref_to aka.path}">#{h aka.name}</a>}
- else
- h aka.name
- end
- end.join ", " %>
- </div>
- <% end %>
-
- <% if method.is_alias_for then %>
- <div class="aliases">
- Alias for: <a href="<%= klass.aref_to method.is_alias_for.path %>"><%= h method.is_alias_for.name %></a>
- </div>
- <% end %>
- </div>
-
- <% end %>
- </section>
- <% end
- end %>
- </section>
-<% end %>
-</main>
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/css/fonts.css b/ruby_2_2/lib/rdoc/generator/template/darkfish/css/fonts.css
deleted file mode 100644
index e9e721183b..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/css/fonts.css
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/),
- * with Reserved Font Name "Source". All Rights Reserved. Source is a
- * trademark of Adobe Systems Incorporated in the United States and/or other
- * countries.
- *
- * This Font Software is licensed under the SIL Open Font License, Version
- * 1.1.
- *
- * This license is copied below, and is also available with a FAQ at:
- * http://scripts.sil.org/OFL
- */
-
-@font-face {
- font-family: "Source Code Pro";
- font-style: normal;
- font-weight: 400;
- src: local("Source Code Pro"),
- local("SourceCodePro-Regular"),
- url("fonts/SourceCodePro-Regular.ttf") format("truetype");
-}
-
-@font-face {
- font-family: "Source Code Pro";
- font-style: normal;
- font-weight: 700;
- src: local("Source Code Pro Bold"),
- local("SourceCodePro-Bold"),
- url("fonts/SourceCodePro-Bold.ttf") format("truetype");
-}
-
-/*
- * Copyright (c) 2010, Łukasz Dziedzic (dziedzic@typoland.com),
- * with Reserved Font Name Lato.
- *
- * This Font Software is licensed under the SIL Open Font License, Version
- * 1.1.
- *
- * This license is copied below, and is also available with a FAQ at:
- * http://scripts.sil.org/OFL
- */
-
-@font-face {
- font-family: "Lato";
- font-style: normal;
- font-weight: 300;
- src: local("Lato Light"),
- local("Lato-Light"),
- url("fonts/Lato-Light.ttf") format("truetype");
-}
-
-@font-face {
- font-family: "Lato";
- font-style: italic;
- font-weight: 300;
- src: local("Lato Light Italic"),
- local("Lato-LightItalic"),
- url("fonts/Lato-LightItalic.ttf") format("truetype");
-}
-
-@font-face {
- font-family: "Lato";
- font-style: normal;
- font-weight: 700;
- src: local("Lato Regular"),
- local("Lato-Regular"),
- url("fonts/Lato-Regular.ttf") format("truetype");
-}
-
-@font-face {
- font-family: "Lato";
- font-style: italic;
- font-weight: 700;
- src: local("Lato Italic"),
- local("Lato-Italic"),
- url("fonts/Lato-RegularItalic.ttf") format("truetype");
-}
-
-/*
- * -----------------------------------------------------------
- * SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
- * -----------------------------------------------------------
- *
- * PREAMBLE
- * The goals of the Open Font License (OFL) are to stimulate worldwide
- * development of collaborative font projects, to support the font creation
- * efforts of academic and linguistic communities, and to provide a free and
- * open framework in which fonts may be shared and improved in partnership
- * with others.
- *
- * The OFL allows the licensed fonts to be used, studied, modified and
- * redistributed freely as long as they are not sold by themselves. The
- * fonts, including any derivative works, can be bundled, embedded,
- * redistributed and/or sold with any software provided that any reserved
- * names are not used by derivative works. The fonts and derivatives,
- * however, cannot be released under any other type of license. The
- * requirement for fonts to remain under this license does not apply
- * to any document created using the fonts or their derivatives.
- *
- * DEFINITIONS
- * "Font Software" refers to the set of files released by the Copyright
- * Holder(s) under this license and clearly marked as such. This may
- * include source files, build scripts and documentation.
- *
- * "Reserved Font Name" refers to any names specified as such after the
- * copyright statement(s).
- *
- * "Original Version" refers to the collection of Font Software components as
- * distributed by the Copyright Holder(s).
- *
- * "Modified Version" refers to any derivative made by adding to, deleting,
- * or substituting -- in part or in whole -- any of the components of the
- * Original Version, by changing formats or by porting the Font Software to a
- * new environment.
- *
- * "Author" refers to any designer, engineer, programmer, technical
- * writer or other person who contributed to the Font Software.
- *
- * PERMISSION & CONDITIONS
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of the Font Software, to use, study, copy, merge, embed, modify,
- * redistribute, and sell modified and unmodified copies of the Font
- * Software, subject to the following conditions:
- *
- * 1) Neither the Font Software nor any of its individual components,
- * in Original or Modified Versions, may be sold by itself.
- *
- * 2) Original or Modified Versions of the Font Software may be bundled,
- * redistributed and/or sold with any software, provided that each copy
- * contains the above copyright notice and this license. These can be
- * included either as stand-alone text files, human-readable headers or
- * in the appropriate machine-readable metadata fields within text or
- * binary files as long as those fields can be easily viewed by the user.
- *
- * 3) No Modified Version of the Font Software may use the Reserved Font
- * Name(s) unless explicit written permission is granted by the corresponding
- * Copyright Holder. This restriction only applies to the primary font name as
- * presented to the users.
- *
- * 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
- * Software shall not be used to promote, endorse or advertise any
- * Modified Version, except to acknowledge the contribution(s) of the
- * Copyright Holder(s) and the Author(s) or with their explicit written
- * permission.
- *
- * 5) The Font Software, modified or unmodified, in part or in whole,
- * must be distributed entirely under this license, and must not be
- * distributed under any other license. The requirement for fonts to
- * remain under this license does not apply to any document created
- * using the Font Software.
- *
- * TERMINATION
- * This license becomes null and void if any of the above conditions are
- * not met.
- *
- * DISCLAIMER
- * THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
- * OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
- * DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
- * OTHER DEALINGS IN THE FONT SOFTWARE.
- */
-
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/css/rdoc.css b/ruby_2_2/lib/rdoc/generator/template/darkfish/css/rdoc.css
deleted file mode 100644
index 2f4dca7e08..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/css/rdoc.css
+++ /dev/null
@@ -1,590 +0,0 @@
-/*
- * "Darkfish" Rdoc CSS
- * $Id: rdoc.css 54 2009-01-27 01:09:48Z deveiant $
- *
- * Author: Michael Granger <ged@FaerieMUD.org>
- *
- */
-
-/* vim: ft=css et sw=2 ts=2 sts=2 */
-/* Base Green is: #6C8C22 */
-
-* { padding: 0; margin: 0; }
-
-body {
- background: #fafafa;
- font-family: Lato, sans-serif;
- font-weight: 300;
-}
-
-h1 span,
-h2 span,
-h3 span,
-h4 span,
-h5 span,
-h6 span {
- position: relative;
-
- display: none;
- padding-left: 1em;
- line-height: 0;
- vertical-align: baseline;
- font-size: 10px;
-}
-
-h1 span { top: -1.3em; }
-h2 span { top: -1.2em; }
-h3 span { top: -1.0em; }
-h4 span { top: -0.8em; }
-h5 span { top: -0.5em; }
-h6 span { top: -0.5em; }
-
-h1:hover span,
-h2:hover span,
-h3:hover span,
-h4:hover span,
-h5:hover span,
-h6:hover span {
- display: inline;
-}
-
-:link,
-:visited {
- color: #6C8C22;
- text-decoration: none;
-}
-
-:link:hover,
-:visited:hover {
- border-bottom: 1px dotted #6C8C22;
-}
-
-code,
-pre {
- font-family: "Source Code Pro", Monaco, monospace;
-}
-
-/* @group Generic Classes */
-
-.initially-hidden {
- display: none;
-}
-
-#search-field {
- width: 98%;
- background: white;
- border: none;
- height: 1.5em;
- -webkit-border-radius: 4px;
- -moz-border-radius: 4px;
- border-radius: 4px;
- text-align: left;
-}
-#search-field:focus {
- background: #f1edba;
-}
-#search-field:-moz-placeholder,
-#search-field::-webkit-input-placeholder {
- font-weight: bold;
- color: #666;
-}
-
-.missing-docs {
- font-size: 120%;
- background: white url(images/wrench_orange.png) no-repeat 4px center;
- color: #ccc;
- line-height: 2em;
- border: 1px solid #d00;
- opacity: 1;
- padding-left: 20px;
- text-indent: 24px;
- letter-spacing: 3px;
- font-weight: bold;
- -webkit-border-radius: 5px;
- -moz-border-radius: 5px;
-}
-
-.target-section {
- border: 2px solid #dcce90;
- border-left-width: 8px;
- padding: 0 1em;
- background: #fff3c2;
-}
-
-/* @end */
-
-/* @group Index Page, Standalone file pages */
-.table-of-contents ul {
- margin: 1em;
- list-style: none;
-}
-
-.table-of-contents ul ul {
- margin-top: 0.25em;
-}
-
-.table-of-contents ul :link,
-.table-of-contents ul :visited {
- font-size: 16px;
-}
-
-.table-of-contents li {
- margin-bottom: 0.25em;
-}
-
-.table-of-contents li .toc-toggle {
- width: 16px;
- height: 16px;
- background: url(images/add.png) no-repeat;
-}
-
-.table-of-contents li .toc-toggle.open {
- background: url(images/delete.png) no-repeat;
-}
-
-/* @end */
-
-/* @group Top-Level Structure */
-
-nav {
- float: left;
- width: 260px;
- font-family: Helvetica, sans-serif;
- font-size: 14px;
-}
-
-main {
- display: block;
- margin: 0 2em 5em 260px;
- padding-left: 20px;
- min-width: 340px;
- font-size: 16px;
-}
-
-main h1,
-main h2,
-main h3,
-main h4,
-main h5,
-main h6 {
- font-family: Helvetica, sans-serif;
-}
-
-.table-of-contents main {
- margin-left: 2em;
-}
-
-#validator-badges {
- clear: both;
- margin: 1em 1em 2em;
- font-size: smaller;
-}
-
-/* @end */
-
-/* @group navigation */
-nav {
- margin-bottom: 1em;
-}
-
-nav .nav-section {
- margin-top: 2em;
- border-top: 2px solid #aaa;
- font-size: 90%;
- overflow: hidden;
-}
-
-nav h2 {
- margin: 0;
- padding: 2px 8px 2px 8px;
- background-color: #e8e8e8;
- color: #555;
- font-size: 125%;
- text-align: center;
-}
-
-nav h3,
-#table-of-contents-navigation {
- margin: 0;
- padding: 2px 8px 2px 8px;
- text-align: right;
- background-color: #e8e8e8;
- color: #555;
-}
-
-nav ul,
-nav dl,
-nav p {
- padding: 4px 8px 0;
- list-style: none;
-}
-
-#project-navigation .nav-section {
- margin: 0;
- border-top: 0;
-}
-
-#home-section h2 {
- text-align: center;
-}
-
-#table-of-contents-navigation {
- font-size: 1.2em;
- font-weight: bold;
- text-align: center;
-}
-
-#search-section {
- margin-top: 0;
- border-top: 0;
-}
-
-#search-field-wrapper {
- border-top: 1px solid #aaa;
- border-bottom: 1px solid #aaa;
- padding: 3px 8px;
- background-color: #e8e8e8;
- color: #555;
-}
-
-ul.link-list li {
- white-space: nowrap;
- line-height: 1.4em;
-}
-
-ul.link-list .type {
- font-size: 8px;
- text-transform: uppercase;
- color: white;
- background: #969696;
- padding: 2px 4px;
- -webkit-border-radius: 5px;
-}
-
-.calls-super {
- background: url(images/arrow_up.png) no-repeat right center;
-}
-
-/* @end */
-
-/* @group Documentation Section */
-main {
- color: #333;
-}
-
-main > h1:first-child,
-main > h2:first-child,
-main > h3:first-child,
-main > h4:first-child,
-main > h5:first-child,
-main > h6:first-child {
- margin-top: 0px;
-}
-
-main sup {
- vertical-align: super;
- font-size: 0.8em;
-}
-
-/* The heading with the class name */
-main h1[class] {
- margin-top: 0;
- margin-bottom: 1em;
- font-size: 2em;
- color: #6C8C22;
-}
-
-main h1 {
- margin: 2em 0 0.5em;
- font-size: 1.7em;
-}
-
-main h2 {
- margin: 2em 0 0.5em;
- font-size: 1.5em;
-}
-
-main h3 {
- margin: 2em 0 0.5em;
- font-size: 1.2em;
-}
-
-main h4 {
- margin: 2em 0 0.5em;
- font-size: 1.1em;
-}
-
-main h5 {
- margin: 2em 0 0.5em;
- font-size: 1em;
-}
-
-main h6 {
- margin: 2em 0 0.5em;
- font-size: 1em;
-}
-
-main p {
- margin: 0 0 0.5em;
- line-height: 1.4em;
-}
-
-main pre {
- margin: 1.2em 0.5em;
- padding: 1em;
- font-size: 0.8em;
-}
-
-main hr {
- margin: 1.5em 1em;
- border: 2px solid #ddd;
-}
-
-main blockquote {
- margin: 0 2em 1.2em 1.2em;
- padding-left: 0.5em;
- border-left: 2px solid #ddd;
-}
-
-main ol,
-main ul {
- margin: 1em 2em;
-}
-
-main li > p {
- margin-bottom: 0.5em;
-}
-
-main dl {
- margin: 1em 0.5em;
-}
-
-main dt {
- margin-bottom: 0.5em;
- font-weight: bold;
-}
-
-main dd {
- margin: 0 1em 1em 0.5em;
-}
-
-main header h2 {
- margin-top: 2em;
- border-width: 0;
- border-top: 4px solid #bbb;
- font-size: 130%;
-}
-
-main header h3 {
- margin: 2em 0 1.5em;
- border-width: 0;
- border-top: 3px solid #bbb;
- font-size: 120%;
-}
-
-.documentation-section-title {
- position: relative;
-}
-.documentation-section-title .section-click-top {
- position: absolute;
- top: 6px;
- left: 12px;
- font-size: 10px;
- color: #9b9877;
- visibility: hidden;
- padding-left: 0.5px;
-}
-
-.documentation-section-title:hover .section-click-top {
- visibility: visible;
-}
-
-.constants-list > dl {
- margin: 1em 0 2em;
- border: 0;
-}
-
-.constants-list > dl dt {
- margin-bottom: 0.75em;
- padding-left: 0;
- font-family: "Source Code Pro", Monaco, monospace;
- font-size: 110%;
-}
-
-.constants-list > dl dt a {
- color: inherit;
-}
-
-.constants-list > dl dd {
- margin: 0 0 2em 0;
- padding: 0;
- color: #666;
-}
-
-.documentation-section h2 {
- position: relative;
-}
-
-.documentation-section h2 a {
- position: absolute;
- top: 8px;
- right: 10px;
- font-size: 12px;
- color: #9b9877;
- visibility: hidden;
-}
-
-.documentation-section h2:hover a {
- visibility: visible;
-}
-
-/* @group Method Details */
-
-main .method-source-code {
- display: none;
-}
-
-main .method-description .method-calls-super {
- color: #333;
- font-weight: bold;
-}
-
-main .method-detail {
- margin-bottom: 2.5em;
- cursor: pointer;
-}
-
-main .method-detail:target {
- margin-left: -10px;
- border-left: 10px solid #f1edba;
-}
-
-main .method-heading {
- position: relative;
- font-family: "Source Code Pro", Monaco, monospace;
- font-size: 110%;
- font-weight: bold;
- color: #333;
-}
-main .method-heading :link,
-main .method-heading :visited {
- color: inherit;
-}
-main .method-click-advice {
- position: absolute;
- top: 2px;
- right: 5px;
- font-size: 12px;
- color: #9b9877;
- visibility: hidden;
- padding-right: 20px;
- line-height: 20px;
- background: url(images/zoom.png) no-repeat right top;
-}
-main .method-heading:hover .method-click-advice {
- visibility: visible;
-}
-
-main .method-alias .method-heading {
- color: #666;
-}
-
-main .method-description,
-main .aliases {
- margin-top: 0.75em;
- color: #333;
-}
-
-main .aliases {
- padding-top: 4px;
- font-style: italic;
- cursor: default;
-}
-main .method-description ul {
- margin-left: 1.5em;
-}
-
-main #attribute-method-details .method-detail:hover {
- background-color: transparent;
- cursor: default;
-}
-main .attribute-access-type {
- text-transform: uppercase;
- padding: 0 1em;
-}
-/* @end */
-
-/* @end */
-
-/* @group Source Code */
-
-pre {
- margin: 0.5em 0;
- border: 1px dashed #999;
- padding: 0.5em;
- background: #262626;
- color: white;
- overflow: auto;
-}
-
-.ruby-constant { color: #7fffd4; background: transparent; }
-.ruby-keyword { color: #00ffff; background: transparent; }
-.ruby-ivar { color: #eedd82; background: transparent; }
-.ruby-operator { color: #00ffee; background: transparent; }
-.ruby-identifier { color: #ffdead; background: transparent; }
-.ruby-node { color: #ffa07a; background: transparent; }
-.ruby-comment { color: #dc0000; background: transparent; }
-.ruby-regexp { color: #ffa07a; background: transparent; }
-.ruby-value { color: #7fffd4; background: transparent; }
-
-/* @end */
-
-
-/* @group search results */
-#search-results {
- font-family: Lato, sans-serif;
- font-weight: 300;
-}
-
-#search-results .search-match {
- font-family: Helvetica, sans-serif;
- font-weight: normal;
-}
-
-#search-results .search-selected {
- background: #e8e8e8;
- border-bottom: 1px solid transparent;
-}
-
-#search-results li {
- list-style: none;
- border-bottom: 1px solid #aaa;
- margin-bottom: 0.5em;
-}
-
-#search-results li:last-child {
- border-bottom: none;
- margin-bottom: 0;
-}
-
-#search-results li p {
- padding: 0;
- margin: 0.5em;
-}
-
-#search-results .search-namespace {
- font-weight: bold;
-}
-
-#search-results li em {
- background: yellow;
- font-style: normal;
-}
-
-#search-results pre {
- margin: 0.5em;
- font-family: "Source Code Pro", Monaco, monospace;
-}
-
-/* @end */
-
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf b/ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf
deleted file mode 100644
index b49dd43729..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf b/ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf
deleted file mode 100644
index 7959fef075..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf b/ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf
deleted file mode 100644
index 839cd589dc..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf b/ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf
deleted file mode 100644
index bababa09e3..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf b/ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf
deleted file mode 100644
index 61e3090c1c..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf b/ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf
deleted file mode 100644
index 85686d967d..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/add.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/add.png
deleted file mode 100644
index 6332fefea4..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/add.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/arrow_up.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/arrow_up.png
deleted file mode 100644
index 1ebb193243..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/arrow_up.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/brick.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/brick.png
deleted file mode 100644
index 7851cf34c9..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/brick.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/brick_link.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/brick_link.png
deleted file mode 100644
index 9ebf013a23..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/brick_link.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/bug.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/bug.png
deleted file mode 100644
index 2d5fb90ec6..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/bug.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/bullet_black.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/bullet_black.png
deleted file mode 100644
index 57619706d1..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/bullet_black.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png
deleted file mode 100644
index b47ce55f68..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png
deleted file mode 100644
index 9ab4a89664..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/date.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/date.png
deleted file mode 100644
index 783c83357f..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/date.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/delete.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/delete.png
deleted file mode 100644
index 08f249365a..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/delete.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/find.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/find.png
deleted file mode 100644
index 1547479646..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/find.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif
deleted file mode 100644
index 82290f4833..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png
deleted file mode 100644
index c6473b324e..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/package.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/package.png
deleted file mode 100644
index da3c2a2d74..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/package.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/page_green.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/page_green.png
deleted file mode 100644
index de8e003f9f..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/page_green.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/page_white_text.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/page_white_text.png
deleted file mode 100644
index 813f712f72..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/page_white_text.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/page_white_width.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/page_white_width.png
deleted file mode 100644
index 1eb880947d..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/page_white_width.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/plugin.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/plugin.png
deleted file mode 100644
index 6187b15aec..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/plugin.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/ruby.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/ruby.png
deleted file mode 100644
index f763a16880..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/ruby.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/tag_blue.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/tag_blue.png
deleted file mode 100644
index 3f02b5f8f8..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/tag_blue.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/tag_green.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/tag_green.png
deleted file mode 100644
index 83ec984bd7..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/tag_green.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/transparent.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/transparent.png
deleted file mode 100644
index d665e179ef..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/transparent.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/wrench.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/wrench.png
deleted file mode 100644
index 5c8213fef5..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/wrench.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/wrench_orange.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/wrench_orange.png
deleted file mode 100644
index 565a9330e0..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/wrench_orange.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/zoom.png b/ruby_2_2/lib/rdoc/generator/template/darkfish/images/zoom.png
deleted file mode 100644
index 908612e394..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/images/zoom.png
+++ /dev/null
Binary files differ
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/index.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/index.rhtml
deleted file mode 100644
index 7d1c74807b..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/index.rhtml
+++ /dev/null
@@ -1,23 +0,0 @@
-<body id="top" role="document" class="file">
-<nav role="navigation">
- <div id="project-navigation">
- <%= render '_sidebar_navigation.rhtml' %>
-
- <%= render '_sidebar_search.rhtml' %>
- </div>
-
- <div id="project-metadata">
- <%= render '_sidebar_pages.rhtml' %>
- <%= render '_sidebar_classes.rhtml' %>
- </div>
-</nav>
-
-<main role="main">
-<% if @options.main_page and
- main_page = @files.find { |f| f.full_name == @options.main_page } then %>
-<%= main_page.description %>
-<% else %>
-<p>This is the API documentation for <%= @title %>.
-<% end %>
-</main>
-
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/js/darkfish.js b/ruby_2_2/lib/rdoc/generator/template/darkfish/js/darkfish.js
deleted file mode 100644
index b789a65631..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/js/darkfish.js
+++ /dev/null
@@ -1,161 +0,0 @@
-/**
- *
- * Darkfish Page Functions
- * $Id: darkfish.js 53 2009-01-07 02:52:03Z deveiant $
- *
- * Author: Michael Granger <mgranger@laika.com>
- *
- */
-
-/* Provide console simulation for firebug-less environments */
-if (!("console" in window) || !("firebug" in console)) {
- var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
- "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
-
- window.console = {};
- for (var i = 0; i < names.length; ++i)
- window.console[names[i]] = function() {};
-};
-
-
-/**
- * Unwrap the first element that matches the given @expr@ from the targets and return them.
- */
-$.fn.unwrap = function( expr ) {
- return this.each( function() {
- $(this).parents( expr ).eq( 0 ).after( this ).remove();
- });
-};
-
-
-function showSource( e ) {
- var target = e.target;
- var codeSections = $(target).
- parents('.method-detail').
- find('.method-source-code');
-
- $(target).
- parents('.method-detail').
- find('.method-source-code').
- slideToggle();
-};
-
-function hookSourceViews() {
- $('.method-heading').click( showSource );
-};
-
-function hookSearch() {
- var input = $('#search-field').eq(0);
- var result = $('#search-results').eq(0);
- $(result).show();
-
- var search_section = $('#search-section').get(0);
- $(search_section).show();
-
- var search = new Search(search_data, input, result);
-
- search.renderItem = function(result) {
- var li = document.createElement('li');
- var html = '';
-
- // TODO add relative path to <script> per-page
- html += '<p class="search-match"><a href="' + rdoc_rel_prefix + result.path + '">' + this.hlt(result.title);
- if (result.params)
- html += '<span class="params">' + result.params + '</span>';
- html += '</a>';
-
-
- if (result.namespace)
- html += '<p class="search-namespace">' + this.hlt(result.namespace);
-
- if (result.snippet)
- html += '<div class="search-snippet">' + result.snippet + '</div>';
-
- li.innerHTML = html;
-
- return li;
- }
-
- search.select = function(result) {
- var result_element = result.get(0);
- window.location.href = result_element.firstChild.firstChild.href;
- }
-
- search.scrollIntoView = search.scrollInWindow;
-};
-
-function highlightTarget( anchor ) {
- console.debug( "Highlighting target '%s'.", anchor );
-
- $("a[name]").each( function() {
- if ( $(this).attr("name") == anchor ) {
- if ( !$(this).parent().parent().hasClass('target-section') ) {
- console.debug( "Wrapping the target-section" );
- $('div.method-detail').unwrap( 'div.target-section' );
- $(this).parent().wrap( '<div class="target-section"></div>' );
- } else {
- console.debug( "Already wrapped." );
- }
- }
- });
-};
-
-function highlightLocationTarget() {
- console.debug( "Location hash: %s", window.location.hash );
- if ( ! window.location.hash || window.location.hash.length == 0 ) return;
-
- var anchor = window.location.hash.substring(1);
- console.debug( "Found anchor: %s; matching %s", anchor, "a[name=" + anchor + "]" );
-
- highlightTarget( anchor );
-};
-
-function highlightClickTarget( event ) {
- console.debug( "Highlighting click target for event %o", event.target );
- try {
- var anchor = $(event.target).attr( 'href' ).substring(1);
- console.debug( "Found target anchor: %s", anchor );
- highlightTarget( anchor );
- } catch ( err ) {
- console.error( "Exception while highlighting: %o", err );
- };
-};
-
-function loadAsync(path, success) {
- $.ajax({
- url: rdoc_rel_prefix + path,
- dataType: 'script',
- success: success,
- cache: true
- });
-};
-
-$(document).ready( function() {
- hookSourceViews();
- highlightLocationTarget();
- $('ul.link-list a').bind( "click", highlightClickTarget );
-
- var search_scripts_loaded = {
- navigation_loaded: false,
- search_loaded: false,
- search_index_loaded: false,
- searcher_loaded: false,
- }
-
- var search_success_function = function(variable) {
- return (function (data, status, xhr) {
- search_scripts_loaded[variable] = true;
-
- if (search_scripts_loaded['navigation_loaded'] == true &&
- search_scripts_loaded['search_loaded'] == true &&
- search_scripts_loaded['search_index_loaded'] == true &&
- search_scripts_loaded['searcher_loaded'] == true)
- hookSearch();
- });
- }
-
- loadAsync('js/navigation.js', search_success_function('navigation_loaded'));
- loadAsync('js/search.js', search_success_function('search_loaded'));
- loadAsync('js/search_index.js', search_success_function('search_index_loaded'));
- loadAsync('js/searcher.js', search_success_function('searcher_loaded'));
-});
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/js/jquery.js b/ruby_2_2/lib/rdoc/generator/template/darkfish/js/jquery.js
deleted file mode 100644
index 628ed9b316..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/js/jquery.js
+++ /dev/null
@@ -1,4 +0,0 @@
-/*! jQuery v1.6.4 http://jquery.com/ | http://jquery.org/license */
-(function(a,b){function cu(a){return f.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}function cr(a){if(!cg[a]){var b=c.body,d=f("<"+a+">").appendTo(b),e=d.css("display");d.remove();if(e==="none"||e===""){ch||(ch=c.createElement("iframe"),ch.frameBorder=ch.width=ch.height=0),b.appendChild(ch);if(!ci||!ch.createElement)ci=(ch.contentWindow||ch.contentDocument).document,ci.write((c.compatMode==="CSS1Compat"?"<!doctype html>":"")+"<html><body>"),ci.close();d=ci.createElement(a),ci.body.appendChild(d),e=f.css(d,"display"),b.removeChild(ch)}cg[a]=e}return cg[a]}function cq(a,b){var c={};f.each(cm.concat.apply([],cm.slice(0,b)),function(){c[this]=a});return c}function cp(){cn=b}function co(){setTimeout(cp,0);return cn=f.now()}function cf(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}function ce(){try{return new a.XMLHttpRequest}catch(b){}}function b$(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var d=a.dataTypes,e={},g,h,i=d.length,j,k=d[0],l,m,n,o,p;for(g=1;g<i;g++){if(g===1)for(h in a.converters)typeof h=="string"&&(e[h.toLowerCase()]=a.converters[h]);l=k,k=d[g];if(k==="*")k=l;else if(l!=="*"&&l!==k){m=l+" "+k,n=e[m]||e["* "+k];if(!n){p=b;for(o in e){j=o.split(" ");if(j[0]===l||j[0]==="*"){p=e[j[1]+" "+k];if(p){o=e[o],o===!0?n=p:p===!0&&(n=o);break}}}}!n&&!p&&f.error("No conversion from "+m.replace(" "," to ")),n!==!0&&(c=n?n(c):p(o(c)))}}return c}function bZ(a,c,d){var e=a.contents,f=a.dataTypes,g=a.responseFields,h,i,j,k;for(i in g)i in d&&(c[g[i]]=d[i]);while(f[0]==="*")f.shift(),h===b&&(h=a.mimeType||c.getResponseHeader("content-type"));if(h)for(i in e)if(e[i]&&e[i].test(h)){f.unshift(i);break}if(f[0]in d)j=f[0];else{for(i in d){if(!f[0]||a.converters[i+" "+f[0]]){j=i;break}k||(k=i)}j=j||k}if(j){j!==f[0]&&f.unshift(j);return d[j]}}function bY(a,b,c,d){if(f.isArray(b))f.each(b,function(b,e){c||bA.test(a)?d(a,e):bY(a+"["+(typeof e=="object"||f.isArray(e)?b:"")+"]",e,c,d)});else if(!c&&b!=null&&typeof b=="object")for(var e in b)bY(a+"["+e+"]",b[e],c,d);else d(a,b)}function bX(a,c){var d,e,g=f.ajaxSettings.flatOptions||{};for(d in c)c[d]!==b&&((g[d]?a:e||(e={}))[d]=c[d]);e&&f.extend(!0,a,e)}function bW(a,c,d,e,f,g){f=f||c.dataTypes[0],g=g||{},g[f]=!0;var h=a[f],i=0,j=h?h.length:0,k=a===bP,l;for(;i<j&&(k||!l);i++)l=h[i](c,d,e),typeof l=="string"&&(!k||g[l]?l=b:(c.dataTypes.unshift(l),l=bW(a,c,d,e,l,g)));(k||!l)&&!g["*"]&&(l=bW(a,c,d,e,"*",g));return l}function bV(a){return function(b,c){typeof b!="string"&&(c=b,b="*");if(f.isFunction(c)){var d=b.toLowerCase().split(bL),e=0,g=d.length,h,i,j;for(;e<g;e++)h=d[e],j=/^\+/.test(h),j&&(h=h.substr(1)||"*"),i=a[h]=a[h]||[],i[j?"unshift":"push"](c)}}}function by(a,b,c){var d=b==="width"?a.offsetWidth:a.offsetHeight,e=b==="width"?bt:bu;if(d>0){c!=="border"&&f.each(e,function(){c||(d-=parseFloat(f.css(a,"padding"+this))||0),c==="margin"?d+=parseFloat(f.css(a,c+this))||0:d-=parseFloat(f.css(a,"border"+this+"Width"))||0});return d+"px"}d=bv(a,b,b);if(d<0||d==null)d=a.style[b]||0;d=parseFloat(d)||0,c&&f.each(e,function(){d+=parseFloat(f.css(a,"padding"+this))||0,c!=="padding"&&(d+=parseFloat(f.css(a,"border"+this+"Width"))||0),c==="margin"&&(d+=parseFloat(f.css(a,c+this))||0)});return d+"px"}function bl(a,b){b.src?f.ajax({url:b.src,async:!1,dataType:"script"}):f.globalEval((b.text||b.textContent||b.innerHTML||"").replace(bd,"/*$0*/")),b.parentNode&&b.parentNode.removeChild(b)}function bk(a){f.nodeName(a,"input")?bj(a):"getElementsByTagName"in a&&f.grep(a.getElementsByTagName("input"),bj)}function bj(a){if(a.type==="checkbox"||a.type==="radio")a.defaultChecked=a.checked}function bi(a){return"getElementsByTagName"in a?a.getElementsByTagName("*"):"querySelectorAll"in a?a.querySelectorAll("*"):[]}function bh(a,b){var c;if(b.nodeType===1){b.clearAttributes&&b.clearAttributes(),b.mergeAttributes&&b.mergeAttributes(a),c=b.nodeName.toLowerCase();if(c==="object")b.outerHTML=a.outerHTML;else if(c!=="input"||a.type!=="checkbox"&&a.type!=="radio"){if(c==="option")b.selected=a.defaultSelected;else if(c==="input"||c==="textarea")b.defaultValue=a.defaultValue}else a.checked&&(b.defaultChecked=b.checked=a.checked),b.value!==a.value&&(b.value=a.value);b.removeAttribute(f.expando)}}function bg(a,b){if(b.nodeType===1&&!!f.hasData(a)){var c=f.expando,d=f.data(a),e=f.data(b,d);if(d=d[c]){var g=d.events;e=e[c]=f.extend({},d);if(g){delete e.handle,e.events={};for(var h in g)for(var i=0,j=g[h].length;i<j;i++)f.event.add(b,h+(g[h][i].namespace?".":"")+g[h][i].namespace,g[h][i],g[h][i].data)}}}}function bf(a,b){return f.nodeName(a,"table")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function V(a,b,c){b=b||0;if(f.isFunction(b))return f.grep(a,function(a,d){var e=!!b.call(a,d,a);return e===c});if(b.nodeType)return f.grep(a,function(a,d){return a===b===c});if(typeof b=="string"){var d=f.grep(a,function(a){return a.nodeType===1});if(Q.test(b))return f.filter(b,d,!c);b=f.filter(b,d)}return f.grep(a,function(a,d){return f.inArray(a,b)>=0===c})}function U(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function M(a,b){return(a&&a!=="*"?a+".":"")+b.replace(y,"`").replace(z,"&")}function L(a){var b,c,d,e,g,h,i,j,k,l,m,n,o,p=[],q=[],r=f._data(this,"events");if(!(a.liveFired===this||!r||!r.live||a.target.disabled||a.button&&a.type==="click")){a.namespace&&(n=new RegExp("(^|\\.)"+a.namespace.split(".").join("\\.(?:.*\\.)?")+"(\\.|$)")),a.liveFired=this;var s=r.live.slice(0);for(i=0;i<s.length;i++)g=s[i],g.origType.replace(w,"")===a.type?q.push(g.selector):s.splice(i--,1);e=f(a.target).closest(q,a.currentTarget);for(j=0,k=e.length;j<k;j++){m=e[j];for(i=0;i<s.length;i++){g=s[i];if(m.selector===g.selector&&(!n||n.test(g.namespace))&&!m.elem.disabled){h=m.elem,d=null;if(g.preType==="mouseenter"||g.preType==="mouseleave")a.type=g.preType,d=f(a.relatedTarget).closest(g.selector)[0],d&&f.contains(h,d)&&(d=h);(!d||d!==h)&&p.push({elem:h,handleObj:g,level:m.level})}}}for(j=0,k=p.length;j<k;j++){e=p[j];if(c&&e.level>c)break;a.currentTarget=e.elem,a.data=e.handleObj.data,a.handleObj=e.handleObj,o=e.handleObj.origHandler.apply(e.elem,arguments);if(o===!1||a.isPropagationStopped()){c=e.level,o===!1&&(b=!1);if(a.isImmediatePropagationStopped())break}}return b}}function J(a,c,d){var e=f.extend({},d[0]);e.type=a,e.originalEvent={},e.liveFired=b,f.event.handle.call(c,e),e.isDefaultPrevented()&&d[0].preventDefault()}function D(){return!0}function C(){return!1}function m(a,c,d){var e=c+"defer",g=c+"queue",h=c+"mark",i=f.data(a,e,b,!0);i&&(d==="queue"||!f.data(a,g,b,!0))&&(d==="mark"||!f.data(a,h,b,!0))&&setTimeout(function(){!f.data(a,g,b,!0)&&!f.data(a,h,b,!0)&&(f.removeData(a,e,!0),i.resolve())},0)}function l(a){for(var b in a)if(b!=="toJSON")return!1;return!0}function k(a,c,d){if(d===b&&a.nodeType===1){var e="data-"+c.replace(j,"-$1").toLowerCase();d=a.getAttribute(e);if(typeof d=="string"){try{d=d==="true"?!0:d==="false"?!1:d==="null"?null:f.isNaN(d)?i.test(d)?f.parseJSON(d):d:parseFloat(d)}catch(g){}f.data(a,c,d)}else d=b}return d}var c=a.document,d=a.navigator,e=a.location,f=function(){function K(){if(!e.isReady){try{c.documentElement.doScroll("left")}catch(a){setTimeout(K,1);return}e.ready()}}var e=function(a,b){return new e.fn.init(a,b,h)},f=a.jQuery,g=a.$,h,i=/^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,j=/\S/,k=/^\s+/,l=/\s+$/,m=/\d/,n=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,o=/^[\],:{}\s]*$/,p=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,q=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,r=/(?:^|:|,)(?:\s*\[)+/g,s=/(webkit)[ \/]([\w.]+)/,t=/(opera)(?:.*version)?[ \/]([\w.]+)/,u=/(msie) ([\w.]+)/,v=/(mozilla)(?:.*? rv:([\w.]+))?/,w=/-([a-z]|[0-9])/ig,x=/^-ms-/,y=function(a,b){return(b+"").toUpperCase()},z=d.userAgent,A,B,C,D=Object.prototype.toString,E=Object.prototype.hasOwnProperty,F=Array.prototype.push,G=Array.prototype.slice,H=String.prototype.trim,I=Array.prototype.indexOf,J={};e.fn=e.prototype={constructor:e,init:function(a,d,f){var g,h,j,k;if(!a)return this;if(a.nodeType){this.context=this[0]=a,this.length=1;return this}if(a==="body"&&!d&&c.body){this.context=c,this[0]=c.body,this.selector=a,this.length=1;return this}if(typeof a=="string"){a.charAt(0)!=="<"||a.charAt(a.length-1)!==">"||a.length<3?g=i.exec(a):g=[null,a,null];if(g&&(g[1]||!d)){if(g[1]){d=d instanceof e?d[0]:d,k=d?d.ownerDocument||d:c,j=n.exec(a),j?e.isPlainObject(d)?(a=[c.createElement(j[1])],e.fn.attr.call(a,d,!0)):a=[k.createElement(j[1])]:(j=e.buildFragment([g[1]],[k]),a=(j.cacheable?e.clone(j.fragment):j.fragment).childNodes);return e.merge(this,a)}h=c.getElementById(g[2]);if(h&&h.parentNode){if(h.id!==g[2])return f.find(a);this.length=1,this[0]=h}this.context=c,this.selector=a;return this}return!d||d.jquery?(d||f).find(a):this.constructor(d).find(a)}if(e.isFunction(a))return f.ready(a);a.selector!==b&&(this.selector=a.selector,this.context=a.context);return e.makeArray(a,this)},selector:"",jquery:"1.6.4",length:0,size:function(){return this.length},toArray:function(){return G.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var d=this.constructor();e.isArray(a)?F.apply(d,a):e.merge(d,a),d.prevObject=this,d.context=this.context,b==="find"?d.selector=this.selector+(this.selector?" ":"")+c:b&&(d.selector=this.selector+"."+b+"("+c+")");return d},each:function(a,b){return e.each(this,a,b)},ready:function(a){e.bindReady(),B.done(a);return this},eq:function(a){return a===-1?this.slice(a):this.slice(a,+a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(G.apply(this,arguments),"slice",G.call(arguments).join(","))},map:function(a){return this.pushStack(e.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:F,sort:[].sort,splice:[].splice},e.fn.init.prototype=e.fn,e.extend=e.fn.extend=function(){var a,c,d,f,g,h,i=arguments[0]||{},j=1,k=arguments.length,l=!1;typeof i=="boolean"&&(l=i,i=arguments[1]||{},j=2),typeof i!="object"&&!e.isFunction(i)&&(i={}),k===j&&(i=this,--j);for(;j<k;j++)if((a=arguments[j])!=null)for(c in a){d=i[c],f=a[c];if(i===f)continue;l&&f&&(e.isPlainObject(f)||(g=e.isArray(f)))?(g?(g=!1,h=d&&e.isArray(d)?d:[]):h=d&&e.isPlainObject(d)?d:{},i[c]=e.extend(l,h,f)):f!==b&&(i[c]=f)}return i},e.extend({noConflict:function(b){a.$===e&&(a.$=g),b&&a.jQuery===e&&(a.jQuery=f);return e},isReady:!1,readyWait:1,holdReady:function(a){a?e.readyWait++:e.ready(!0)},ready:function(a){if(a===!0&&!--e.readyWait||a!==!0&&!e.isReady){if(!c.body)return setTimeout(e.ready,1);e.isReady=!0;if(a!==!0&&--e.readyWait>0)return;B.resolveWith(c,[e]),e.fn.trigger&&e(c).trigger("ready").unbind("ready")}},bindReady:function(){if(!B){B=e._Deferred();if(c.readyState==="complete")return setTimeout(e.ready,1);if(c.addEventListener)c.addEventListener("DOMContentLoaded",C,!1),a.addEventListener("load",e.ready,!1);else if(c.attachEvent){c.attachEvent("onreadystatechange",C),a.attachEvent("onload",e.ready);var b=!1;try{b=a.frameElement==null}catch(d){}c.documentElement.doScroll&&b&&K()}}},isFunction:function(a){return e.type(a)==="function"},isArray:Array.isArray||function(a){return e.type(a)==="array"},isWindow:function(a){return a&&typeof a=="object"&&"setInterval"in a},isNaN:function(a){return a==null||!m.test(a)||isNaN(a)},type:function(a){return a==null?String(a):J[D.call(a)]||"object"},isPlainObject:function(a){if(!a||e.type(a)!=="object"||a.nodeType||e.isWindow(a))return!1;try{if(a.constructor&&!E.call(a,"constructor")&&!E.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}var d;for(d in a);return d===b||E.call(a,d)},isEmptyObject:function(a){for(var b in a)return!1;return!0},error:function(a){throw a},parseJSON:function(b){if(typeof b!="string"||!b)return null;b=e.trim(b);if(a.JSON&&a.JSON.parse)return a.JSON.parse(b);if(o.test(b.replace(p,"@").replace(q,"]").replace(r,"")))return(new Function("return "+b))();e.error("Invalid JSON: "+b)},parseXML:function(c){var d,f;try{a.DOMParser?(f=new DOMParser,d=f.parseFromString(c,"text/xml")):(d=new ActiveXObject("Microsoft.XMLDOM"),d.async="false",d.loadXML(c))}catch(g){d=b}(!d||!d.documentElement||d.getElementsByTagName("parsererror").length)&&e.error("Invalid XML: "+c);return d},noop:function(){},globalEval:function(b){b&&j.test(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(x,"ms-").replace(w,y)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,d){var f,g=0,h=a.length,i=h===b||e.isFunction(a);if(d){if(i){for(f in a)if(c.apply(a[f],d)===!1)break}else for(;g<h;)if(c.apply(a[g++],d)===!1)break}else if(i){for(f in a)if(c.call(a[f],f,a[f])===!1)break}else for(;g<h;)if(c.call(a[g],g,a[g++])===!1)break;return a},trim:H?function(a){return a==null?"":H.call(a)}:function(a){return a==null?"":(a+"").replace(k,"").replace(l,"")},makeArray:function(a,b){var c=b||[];if(a!=null){var d=e.type(a);a.length==null||d==="string"||d==="function"||d==="regexp"||e.isWindow(a)?F.call(c,a):e.merge(c,a)}return c},inArray:function(a,b){if(!b)return-1;if(I)return I.call(b,a);for(var c=0,d=b.length;c<d;c++)if(b[c]===a)return c;return-1},merge:function(a,c){var d=a.length,e=0;if(typeof c.length=="number")for(var f=c.length;e<f;e++)a[d++]=c[e];else while(c[e]!==b)a[d++]=c[e++];a.length=d;return a},grep:function(a,b,c){var d=[],e;c=!!c;for(var f=0,g=a.length;f<g;f++)e=!!b(a[f],f),c!==e&&d.push(a[f]);return d},map:function(a,c,d){var f,g,h=[],i=0,j=a.length,k=a instanceof e||j!==b&&typeof j=="number"&&(j>0&&a[0]&&a[j-1]||j===0||e.isArray(a));if(k)for(;i<j;i++)f=c(a[i],i,d),f!=null&&(h[h.length]=f);else for(g in a)f=c(a[g],g,d),f!=null&&(h[h.length]=f);return h.concat.apply([],h)},guid:1,proxy:function(a,c){if(typeof c=="string"){var d=a[c];c=a,a=d}if(!e.isFunction(a))return b;var f=G.call(arguments,2),g=function(){return a.apply(c,f.concat(G.call(arguments)))};g.guid=a.guid=a.guid||g.guid||e.guid++;return g},access:function(a,c,d,f,g,h){var i=a.length;if(typeof c=="object"){for(var j in c)e.access(a,j,c[j],f,g,d);return a}if(d!==b){f=!h&&f&&e.isFunction(d);for(var k=0;k<i;k++)g(a[k],c,f?d.call(a[k],k,g(a[k],c)):d,h);return a}return i?g(a[0],c):b},now:function(){return(new Date).getTime()},uaMatch:function(a){a=a.toLowerCase();var b=s.exec(a)||t.exec(a)||u.exec(a)||a.indexOf("compatible")<0&&v.exec(a)||[];return{browser:b[1]||"",version:b[2]||"0"}},sub:function(){function a(b,c){return new a.fn.init(b,c)}e.extend(!0,a,this),a.superclass=this,a.fn=a.prototype=this(),a.fn.constructor=a,a.sub=this.sub,a.fn.init=function(d,f){f&&f instanceof e&&!(f instanceof a)&&(f=a(f));return e.fn.init.call(this,d,f,b)},a.fn.init.prototype=a.fn;var b=a(c);return a},browser:{}}),e.each("Boolean Number String Function Array Date RegExp Object".split(" "),function(a,b){J["[object "+b+"]"]=b.toLowerCase()}),A=e.uaMatch(z),A.browser&&(e.browser[A.browser]=!0,e.browser.version=A.version),e.browser.webkit&&(e.browser.safari=!0),j.test(" ")&&(k=/^[\s\xA0]+/,l=/[\s\xA0]+$/),h=e(c),c.addEventListener?C=function(){c.removeEventListener("DOMContentLoaded",C,!1),e.ready()}:c.attachEvent&&(C=function(){c.readyState==="complete"&&(c.detachEvent("onreadystatechange",C),e.ready())});return e}(),g="done fail isResolved isRejected promise then always pipe".split(" "),h=[].slice;f.extend({_Deferred:function(){var a=[],b,c,d,e={done:function(){if(!d){var c=arguments,g,h,i,j,k;b&&(k=b,b=0);for(g=0,h=c.length;g<h;g++)i=c[g],j=f.type(i),j==="array"?e.done.apply(e,i):j==="function"&&a.push(i);k&&e.resolveWith(k[0],k[1])}return this},resolveWith:function(e,f){if(!d&&!b&&!c){f=f||[],c=1;try{while(a[0])a.shift().apply(e,f)}finally{b=[e,f],c=0}}return this},resolve:function(){e.resolveWith(this,arguments);return this},isResolved:function(){return!!c||!!b},cancel:function(){d=1,a=[];return this}};return e},Deferred:function(a){var b=f._Deferred(),c=f._Deferred(),d;f.extend(b,{then:function(a,c){b.done(a).fail(c);return this},always:function(){return b.done.apply(b,arguments).fail.apply(this,arguments)},fail:c.done,rejectWith:c.resolveWith,reject:c.resolve,isRejected:c.isResolved,pipe:function(a,c){return f.Deferred(function(d){f.each({done:[a,"resolve"],fail:[c,"reject"]},function(a,c){var e=c[0],g=c[1],h;f.isFunction(e)?b[a](function(){h=e.apply(this,arguments),h&&f.isFunction(h.promise)?h.promise().then(d.resolve,d.reject):d[g+"With"](this===b?d:this,[h])}):b[a](d[g])})}).promise()},promise:function(a){if(a==null){if(d)return d;d=a={}}var c=g.length;while(c--)a[g[c]]=b[g[c]];return a}}),b.done(c.cancel).fail(b.cancel),delete b.cancel,a&&a.call(b,b);return b},when:function(a){function i(a){return function(c){b[a]=arguments.length>1?h.call(arguments,0):c,--e||g.resolveWith(g,h.call(b,0))}}var b=arguments,c=0,d=b.length,e=d,g=d<=1&&a&&f.isFunction(a.promise)?a:f.Deferred();if(d>1){for(;c<d;c++)b[c]&&f.isFunction(b[c].promise)?b[c].promise().then(i(c),g.reject):--e;e||g.resolveWith(g,b)}else g!==a&&g.resolveWith(g,d?[a]:[]);return g.promise()}}),f.support=function(){var a=c.createElement("div"),b=c.documentElement,d,e,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u;a.setAttribute("className","t"),a.innerHTML=" <link/><table></table><a href='/a' style='top:1px;float:left;opacity:.55;'>a</a><input type='checkbox'/>",d=a.getElementsByTagName("*"),e=a.getElementsByTagName("a")[0];if(!d||!d.length||!e)return{};g=c.createElement("select"),h=g.appendChild(c.createElement("option")),i=a.getElementsByTagName("input")[0],k={leadingWhitespace:a.firstChild.nodeType===3,tbody:!a.getElementsByTagName("tbody").length,htmlSerialize:!!a.getElementsByTagName("link").length,style:/top/.test(e.getAttribute("style")),hrefNormalized:e.getAttribute("href")==="/a",opacity:/^0.55$/.test(e.style.opacity),cssFloat:!!e.style.cssFloat,checkOn:i.value==="on",optSelected:h.selected,getSetAttribute:a.className!=="t",submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0},i.checked=!0,k.noCloneChecked=i.cloneNode(!0).checked,g.disabled=!0,k.optDisabled=!h.disabled;try{delete a.test}catch(v){k.deleteExpando=!1}!a.addEventListener&&a.attachEvent&&a.fireEvent&&(a.attachEvent("onclick",function(){k.noCloneEvent=!1}),a.cloneNode(!0).fireEvent("onclick")),i=c.createElement("input"),i.value="t",i.setAttribute("type","radio"),k.radioValue=i.value==="t",i.setAttribute("checked","checked"),a.appendChild(i),l=c.createDocumentFragment(),l.appendChild(a.firstChild),k.checkClone=l.cloneNode(!0).cloneNode(!0).lastChild.checked,a.innerHTML="",a.style.width=a.style.paddingLeft="1px",m=c.getElementsByTagName("body")[0],o=c.createElement(m?"div":"body"),p={visibility:"hidden",width:0,height:0,border:0,margin:0,background:"none"},m&&f.extend(p,{position:"absolute",left:"-1000px",top:"-1000px"});for(t in p)o.style[t]=p[t];o.appendChild(a),n=m||b,n.insertBefore(o,n.firstChild),k.appendChecked=i.checked,k.boxModel=a.offsetWidth===2,"zoom"in a.style&&(a.style.display="inline",a.style.zoom=1,k.inlineBlockNeedsLayout=a.offsetWidth===2,a.style.display="",a.innerHTML="<div style='width:4px;'></div>",k.shrinkWrapBlocks=a.offsetWidth!==2),a.innerHTML="<table><tr><td style='padding:0;border:0;display:none'></td><td>t</td></tr></table>",q=a.getElementsByTagName("td"),u=q[0].offsetHeight===0,q[0].style.display="",q[1].style.display="none",k.reliableHiddenOffsets=u&&q[0].offsetHeight===0,a.innerHTML="",c.defaultView&&c.defaultView.getComputedStyle&&(j=c.createElement("div"),j.style.width="0",j.style.marginRight="0",a.appendChild(j),k.reliableMarginRight=(parseInt((c.defaultView.getComputedStyle(j,null)||{marginRight:0}).marginRight,10)||0)===0),o.innerHTML="",n.removeChild(o);if(a.attachEvent)for(t in{submit:1,change:1,focusin:1})s="on"+t,u=s in a,u||(a.setAttribute(s,"return;"),u=typeof a[s]=="function"),k[t+"Bubbles"]=u;o=l=g=h=m=j=a=i=null;return k}(),f.boxModel=f.support.boxModel;var i=/^(?:\{.*\}|\[.*\])$/,j=/([A-Z])/g;f.extend({cache:{},uuid:0,expando:"jQuery"+(f.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(a){a=a.nodeType?f.cache[a[f.expando]]:a[f.expando];return!!a&&!l(a)},data:function(a,c,d,e){if(!!f.acceptData(a)){var g,h,i=f.expando,j=typeof c=="string",k=a.nodeType,l=k?f.cache:a,m=k?a[f.expando]:a[f.expando]&&f.expando;if((!m||e&&m&&l[m]&&!l[m][i])&&j&&d===b)return;m||(k?a[f.expando]=m=++f.uuid:m=f.expando),l[m]||(l[m]={},k||(l[m].toJSON=f.noop));if(typeof c=="object"||typeof c=="function")e?l[m][i]=f.extend(l[m][i],c):l[m]=f.extend(l[m],c);g=l[m],e&&(g[i]||(g[i]={}),g=g[i]),d!==b&&(g[f.camelCase(c)]=d);if(c==="events"&&!g[c])return g[i]&&g[i].events;j?(h=g[c],h==null&&(h=g[f.camelCase(c)])):h=g;return h}},removeData:function(a,b,c){if(!!f.acceptData(a)){var d,e=f.expando,g=a.nodeType,h=g?f.cache:a,i=g?a[f.expando]:f.expando;if(!h[i])return;if(b){d=c?h[i][e]:h[i];if(d){d[b]||(b=f.camelCase(b)),delete d[b];if(!l(d))return}}if(c){delete h[i][e];if(!l(h[i]))return}var j=h[i][e];f.support.deleteExpando||!h.setInterval?delete h[i]:h[i]=null,j?(h[i]={},g||(h[i].toJSON=f.noop),h[i][e]=j):g&&(f.support.deleteExpando?delete a[f.expando]:a.removeAttribute?a.removeAttribute(f.expando):a[f.expando]=null)}},_data:function(a,b,c){return f.data(a,b,c,!0)},acceptData:function(a){if(a.nodeName){var b=f.noData[a.nodeName.toLowerCase()];if(b)return b!==!0&&a.getAttribute("classid")===b}return!0}}),f.fn.extend({data:function(a,c){var d=null;if(typeof a=="undefined"){if(this.length){d=f.data(this[0]);if(this[0].nodeType===1){var e=this[0].attributes,g;for(var h=0,i=e.length;h<i;h++)g=e[h].name,g.indexOf("data-")===0&&(g=f.camelCase(g.substring(5)),k(this[0],g,d[g]))}}return d}if(typeof a=="object")return this.each(function(){f.data(this,a)});var j=a.split(".");j[1]=j[1]?"."+j[1]:"";if(c===b){d=this.triggerHandler("getData"+j[1]+"!",[j[0]]),d===b&&this.length&&(d=f.data(this[0],a),d=k(this[0],a,d));return d===b&&j[1]?this.data(j[0]):d}return this.each(function(){var b=f(this),d=[j[0],c];b.triggerHandler("setData"+j[1]+"!",d),f.data(this,a,c),b.triggerHandler("changeData"+j[1]+"!",d)})},removeData:function(a){return this.each(function(){f.removeData(this,a)})}}),f.extend({_mark:function(a,c){a&&(c=(c||"fx")+"mark",f.data(a,c,(f.data(a,c,b,!0)||0)+1,!0))},_unmark:function(a,c,d){a!==!0&&(d=c,c=a,a=!1);if(c){d=d||"fx";var e=d+"mark",g=a?0:(f.data(c,e,b,!0)||1)-1;g?f.data(c,e,g,!0):(f.removeData(c,e,!0),m(c,d,"mark"))}},queue:function(a,c,d){if(a){c=(c||"fx")+"queue";var e=f.data(a,c,b,!0);d&&(!e||f.isArray(d)?e=f.data(a,c,f.makeArray(d),!0):e.push(d));return e||[]}},dequeue:function(a,b){b=b||"fx";var c=f.queue(a,b),d=c.shift(),e;d==="inprogress"&&(d=c.shift()),d&&(b==="fx"&&c.unshift("inprogress"),d.call(a,function(){f.dequeue(a,b)})),c.length||(f.removeData(a,b+"queue",!0),m(a,b,"queue"))}}),f.fn.extend({queue:function(a,c){typeof a!="string"&&(c=a,a="fx");if(c===b)return f.queue(this[0],a);return this.each(function(){var b=f.queue(this,a,c);a==="fx"&&b[0]!=="inprogress"&&f.dequeue(this,a)})},dequeue:function(a){return this.each(function(){f.dequeue(this,a)})},delay:function(a,b){a=f.fx?f.fx.speeds[a]||a:a,b=b||"fx";return this.queue(b,function(){var c=this;setTimeout(function(){f.dequeue(c,b)},a)})},clearQueue:function(a){return this.queue(a||"fx",[])},promise:function(a,c){function m(){--h||d.resolveWith(e,[e])}typeof a!="string"&&(c=a,a=b),a=a||"fx";var d=f.Deferred(),e=this,g=e.length,h=1,i=a+"defer",j=a+"queue",k=a+"mark",l;while(g--)if(l=f.data(e[g],i,b,!0)||(f.data(e[g],j,b,!0)||f.data(e[g],k,b,!0))&&f.data(e[g],i,f._Deferred(),!0))h++,l.done(m);m();return d.promise()}});var n=/[\n\t\r]/g,o=/\s+/,p=/\r/g,q=/^(?:button|input)$/i,r=/^(?:button|input|object|select|textarea)$/i,s=/^a(?:rea)?$/i,t=/^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,u,v;f.fn.extend({attr:function(a,b){return f.access(this,a,b,!0,f.attr)},removeAttr:function(a){return this.each(function(){f.removeAttr(this,a)})},prop:function(a,b){return f.access(this,a,b,!0,f.prop)},removeProp:function(a){a=f.propFix[a]||a;return this.each(function(){try{this[a]=b,delete this[a]}catch(c){}})},addClass:function(a){var b,c,d,e,g,h,i;if(f.isFunction(a))return this.each(function(b){f(this).addClass(a.call(this,b,this.className))});if(a&&typeof a=="string"){b=a.split(o);for(c=0,d=this.length;c<d;c++){e=this[c];if(e.nodeType===1)if(!e.className&&b.length===1)e.className=a;else{g=" "+e.className+" ";for(h=0,i=b.length;h<i;h++)~g.indexOf(" "+b[h]+" ")||(g+=b[h]+" ");e.className=f.trim(g)}}}return this},removeClass:function(a){var c,d,e,g,h,i,j;if(f.isFunction(a))return this.each(function(b){f(this).removeClass(a.call(this,b,this.className))});if(a&&typeof a=="string"||a===b){c=(a||"").split(o);for(d=0,e=this.length;d<e;d++){g=this[d];if(g.nodeType===1&&g.className)if(a){h=(" "+g.className+" ").replace(n," ");for(i=0,j=c.length;i<j;i++)h=h.replace(" "+c[i]+" "," ");g.className=f.trim(h)}else g.className=""}}return this},toggleClass:function(a,b){var c=typeof a,d=typeof b=="boolean";if(f.isFunction(a))return this.each(function(c){f(this).toggleClass(a.call(this,c,this.className,b),b)});return this.each(function(){if(c==="string"){var e,g=0,h=f(this),i=b,j=a.split(o);while(e=j[g++])i=d?i:!h.hasClass(e),h[i?"addClass":"removeClass"](e)}else if(c==="undefined"||c==="boolean")this.className&&f._data(this,"__className__",this.className),this.className=this.className||a===!1?"":f._data(this,"__className__")||""})},hasClass:function(a){var b=" "+a+" ";for(var c=0,d=this.length;c<d;c++)if(this[c].nodeType===1&&(" "+this[c].className+" ").replace(n," ").indexOf(b)>-1)return!0;return!1},val:function(a){var c,d,e=this[0];if(!arguments.length){if(e){c=f.valHooks[e.nodeName.toLowerCase()]||f.valHooks[e.type];if(c&&"get"in c&&(d=c.get(e,"value"))!==b)return d;d=e.value;return typeof d=="string"?d.replace(p,""):d==null?"":d}return b}var g=f.isFunction(a);return this.each(function(d){var e=f(this),h;if(this.nodeType===1){g?h=a.call(this,d,e.val()):h=a,h==null?h="":typeof h=="number"?h+="":f.isArray(h)&&(h=f.map(h,function(a){return a==null?"":a+""})),c=f.valHooks[this.nodeName.toLowerCase()]||f.valHooks[this.type];if(!c||!("set"in c)||c.set(this,h,"value")===b)this.value=h}})}}),f.extend({valHooks:{option:{get:function(a){var b=a.attributes.value;return!b||b.specified?a.value:a.text}},select:{get:function(a){var b,c=a.selectedIndex,d=[],e=a.options,g=a.type==="select-one";if(c<0)return null;for(var h=g?c:0,i=g?c+1:e.length;h<i;h++){var j=e[h];if(j.selected&&(f.support.optDisabled?!j.disabled:j.getAttribute("disabled")===null)&&(!j.parentNode.disabled||!f.nodeName(j.parentNode,"optgroup"))){b=f(j).val();if(g)return b;d.push(b)}}if(g&&!d.length&&e.length)return f(e[c]).val();return d},set:function(a,b){var c=f.makeArray(b);f(a).find("option").each(function(){this.selected=f.inArray(f(this).val(),c)>=0}),c.length||(a.selectedIndex=-1);return c}}},attrFn:{val:!0,css:!0,html:!0,text:!0,data:!0,width:!0,height:!0,offset:!0},attrFix:{tabindex:"tabIndex"},attr:function(a,c,d,e){var g=a.nodeType;if(!a||g===3||g===8||g===2)return b;if(e&&c in f.attrFn)return f(a)[c](d);if(!("getAttribute"in a))return f.prop(a,c,d);var h,i,j=g!==1||!f.isXMLDoc(a);j&&(c=f.attrFix[c]||c,i=f.attrHooks[c],i||(t.test(c)?i=v:u&&(i=u)));if(d!==b){if(d===null){f.removeAttr(a,c);return b}if(i&&"set"in i&&j&&(h=i.set(a,d,c))!==b)return h;a.setAttribute(c,""+d);return d}if(i&&"get"in i&&j&&(h=i.get(a,c))!==null)return h;h=a.getAttribute(c);return h===null?b:h},removeAttr:function(a,b){var c;a.nodeType===1&&(b=f.attrFix[b]||b,f.attr(a,b,""),a.removeAttribute(b),t.test(b)&&(c=f.propFix[b]||b)in a&&(a[c]=!1))},attrHooks:{type:{set:function(a,b){if(q.test(a.nodeName)&&a.parentNode)f.error("type property can't be changed");else if(!f.support.radioValue&&b==="radio"&&f.nodeName(a,"input")){var c=a.value;a.setAttribute("type",b),c&&(a.value=c);return b}}},value:{get:function(a,b){if(u&&f.nodeName(a,"button"))return u.get(a,b);return b in a?a.value:null},set:function(a,b,c){if(u&&f.nodeName(a,"button"))return u.set(a,b,c);a.value=b}}},propFix:{tabindex:"tabIndex",readonly:"readOnly","for":"htmlFor","class":"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},prop:function(a,c,d){var e=a.nodeType;if(!a||e===3||e===8||e===2)return b;var g,h,i=e!==1||!f.isXMLDoc(a);i&&(c=f.propFix[c]||c,h=f.propHooks[c]);return d!==b?h&&"set"in h&&(g=h.set(a,d,c))!==b?g:a[c]=d:h&&"get"in h&&(g=h.get(a,c))!==null?g:a[c]},propHooks:{tabIndex:{get:function(a){var c=a.getAttributeNode("tabindex");return c&&c.specified?parseInt(c.value,10):r.test(a.nodeName)||s.test(a.nodeName)&&a.href?0:b}}}}),f.attrHooks.tabIndex=f.propHooks.tabIndex,v={get:function(a,c){var d;return f.prop(a,c)===!0||(d=a.getAttributeNode(c))&&d.nodeValue!==!1?c.toLowerCase():b},set:function(a,b,c){var d;b===!1?f.removeAttr(a,c):(d=f.propFix[c]||c,d in a&&(a[d]=!0),a.setAttribute(c,c.toLowerCase()));return c}},f.support.getSetAttribute||(u=f.valHooks.button={get:function(a,c){var d;d=a.getAttributeNode(c);return d&&d.nodeValue!==""?d.nodeValue:b},set:function(a,b,d){var e=a.getAttributeNode(d);e||(e=c.createAttribute(d),a.setAttributeNode(e));return e.nodeValue=b+""}},f.each(["width","height"],function(a,b){f.attrHooks[b]=f.extend(f.attrHooks[b],{set:function(a,c){if(c===""){a.setAttribute(b,"auto");return c}}})})),f.support.hrefNormalized||f.each(["href","src","width","height"],function(a,c){f.attrHooks[c]=f.extend(f.attrHooks[c],{get:function(a){var d=a.getAttribute(c,2);return d===null?b:d}})}),f.support.style||(f.attrHooks.style={get:function(a){return a.style.cssText.toLowerCase()||b},set:function(a,b){return a.style.cssText=""+b}}),f.support.optSelected||(f.propHooks.selected=f.extend(f.propHooks.selected,{get:function(a){var b=a.parentNode;b&&(b.selectedIndex,b.parentNode&&b.parentNode.selectedIndex);return null}})),f.support.checkOn||f.each(["radio","checkbox"],function(){f.valHooks[this]={get:function(a){return a.getAttribute("value")===null?"on":a.value}}}),f.each(["radio","checkbox"],function(){f.valHooks[this]=f.extend(f.valHooks[this],{set:function(a,b){if(f.isArray(b))return a.checked=f.inArray(f(a).val(),b)>=0}})});var w=/\.(.*)$/,x=/^(?:textarea|input|select)$/i,y=/\./g,z=/ /g,A=/[^\w\s.|`]/g,B=function(a){return a.replace(A,"\\$&")};f.event={add:function(a,c,d,e){if(a.nodeType!==3&&a.nodeType!==8){if(d===!1)d=C;else if(!d)return;var g,h;d.handler&&(g=d,d=g.handler),d.guid||(d.guid=f.guid++);var i=f._data(a);if(!i)return;var j=i.events,k=i.handle;j||(i.events=j={}),k||(i.handle=k=function(a){return typeof f!="undefined"&&(!a||f.event.triggered!==a.type)?f.event.handle.apply(k.elem,arguments):b}),k.elem=a,c=c.split(" ");var l,m=0,n;while(l=c[m++]){h=g?f.extend({},g):{handler:d,data:e},l.indexOf(".")>-1?(n=l.split("."),l=n.shift(),h.namespace=n.slice(0).sort().join(".")):(n=[],h.namespace=""),h.type=l,h.guid||(h.guid=d.guid);var o=j[l],p=f.event.special[l]||{};if(!o){o=j[l]=[];if(!p.setup||p.setup.call(a,e,n,k)===!1)a.addEventListener?a.addEventListener(l,k,!1):a.attachEvent&&a.attachEvent("on"+l,k)}p.add&&(p.add.call(a,h),h.handler.guid||(h.handler.guid=d.guid)),o.push(h),f.event.global[l]=!0}a=null}},global:{},remove:function(a,c,d,e){if(a.nodeType!==3&&a.nodeType!==8){d===!1&&(d=C);var g,h,i,j,k=0,l,m,n,o,p,q,r,s=f.hasData(a)&&f._data(a),t=s&&s.events;if(!s||!t)return;c&&c.type&&(d=c.handler,c=c.type);if(!c||typeof c=="string"&&c.charAt(0)==="."){c=c||"";for(h in t)f.event.remove(a,h+c);return}c=c.split(" ");while(h=c[k++]){r=h,q=null,l=h.indexOf(".")<0,m=[],l||(m=h.split("."),h=m.shift(),n=new RegExp("(^|\\.)"+f.map(m.slice(0).sort(),B).join("\\.(?:.*\\.)?")+"(\\.|$)")),p=t[h];if(!p)continue;if(!d){for(j=0;j<p.length;j++){q=p[j];if(l||n.test(q.namespace))f.event.remove(a,r,q.handler,j),p.splice(j--,1)}continue}o=f.event.special[h]||{};for(j=e||0;j<p.length;j++){q=p[j];if(d.guid===q.guid){if(l||n.test(q.namespace))e==null&&p.splice(j--,1),o.remove&&o.remove.call(a,q);if(e!=null)break}}if(p.length===0||e!=null&&p.length===1)(!o.teardown||o.teardown.call(a,m)===!1)&&f.removeEvent(a,h,s.handle),g=null,delete
-t[h]}if(f.isEmptyObject(t)){var u=s.handle;u&&(u.elem=null),delete s.events,delete s.handle,f.isEmptyObject(s)&&f.removeData(a,b,!0)}}},customEvent:{getData:!0,setData:!0,changeData:!0},trigger:function(c,d,e,g){var h=c.type||c,i=[],j;h.indexOf("!")>=0&&(h=h.slice(0,-1),j=!0),h.indexOf(".")>=0&&(i=h.split("."),h=i.shift(),i.sort());if(!!e&&!f.event.customEvent[h]||!!f.event.global[h]){c=typeof c=="object"?c[f.expando]?c:new f.Event(h,c):new f.Event(h),c.type=h,c.exclusive=j,c.namespace=i.join("."),c.namespace_re=new RegExp("(^|\\.)"+i.join("\\.(?:.*\\.)?")+"(\\.|$)");if(g||!e)c.preventDefault(),c.stopPropagation();if(!e){f.each(f.cache,function(){var a=f.expando,b=this[a];b&&b.events&&b.events[h]&&f.event.trigger(c,d,b.handle.elem)});return}if(e.nodeType===3||e.nodeType===8)return;c.result=b,c.target=e,d=d!=null?f.makeArray(d):[],d.unshift(c);var k=e,l=h.indexOf(":")<0?"on"+h:"";do{var m=f._data(k,"handle");c.currentTarget=k,m&&m.apply(k,d),l&&f.acceptData(k)&&k[l]&&k[l].apply(k,d)===!1&&(c.result=!1,c.preventDefault()),k=k.parentNode||k.ownerDocument||k===c.target.ownerDocument&&a}while(k&&!c.isPropagationStopped());if(!c.isDefaultPrevented()){var n,o=f.event.special[h]||{};if((!o._default||o._default.call(e.ownerDocument,c)===!1)&&(h!=="click"||!f.nodeName(e,"a"))&&f.acceptData(e)){try{l&&e[h]&&(n=e[l],n&&(e[l]=null),f.event.triggered=h,e[h]())}catch(p){}n&&(e[l]=n),f.event.triggered=b}}return c.result}},handle:function(c){c=f.event.fix(c||a.event);var d=((f._data(this,"events")||{})[c.type]||[]).slice(0),e=!c.exclusive&&!c.namespace,g=Array.prototype.slice.call(arguments,0);g[0]=c,c.currentTarget=this;for(var h=0,i=d.length;h<i;h++){var j=d[h];if(e||c.namespace_re.test(j.namespace)){c.handler=j.handler,c.data=j.data,c.handleObj=j;var k=j.handler.apply(this,g);k!==b&&(c.result=k,k===!1&&(c.preventDefault(),c.stopPropagation()));if(c.isImmediatePropagationStopped())break}}return c.result},props:"altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode layerX layerY metaKey newValue offsetX offsetY pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),fix:function(a){if(a[f.expando])return a;var d=a;a=f.Event(d);for(var e=this.props.length,g;e;)g=this.props[--e],a[g]=d[g];a.target||(a.target=a.srcElement||c),a.target.nodeType===3&&(a.target=a.target.parentNode),!a.relatedTarget&&a.fromElement&&(a.relatedTarget=a.fromElement===a.target?a.toElement:a.fromElement);if(a.pageX==null&&a.clientX!=null){var h=a.target.ownerDocument||c,i=h.documentElement,j=h.body;a.pageX=a.clientX+(i&&i.scrollLeft||j&&j.scrollLeft||0)-(i&&i.clientLeft||j&&j.clientLeft||0),a.pageY=a.clientY+(i&&i.scrollTop||j&&j.scrollTop||0)-(i&&i.clientTop||j&&j.clientTop||0)}a.which==null&&(a.charCode!=null||a.keyCode!=null)&&(a.which=a.charCode!=null?a.charCode:a.keyCode),!a.metaKey&&a.ctrlKey&&(a.metaKey=a.ctrlKey),!a.which&&a.button!==b&&(a.which=a.button&1?1:a.button&2?3:a.button&4?2:0);return a},guid:1e8,proxy:f.proxy,special:{ready:{setup:f.bindReady,teardown:f.noop},live:{add:function(a){f.event.add(this,M(a.origType,a.selector),f.extend({},a,{handler:L,guid:a.handler.guid}))},remove:function(a){f.event.remove(this,M(a.origType,a.selector),a)}},beforeunload:{setup:function(a,b,c){f.isWindow(this)&&(this.onbeforeunload=c)},teardown:function(a,b){this.onbeforeunload===b&&(this.onbeforeunload=null)}}}},f.removeEvent=c.removeEventListener?function(a,b,c){a.removeEventListener&&a.removeEventListener(b,c,!1)}:function(a,b,c){a.detachEvent&&a.detachEvent("on"+b,c)},f.Event=function(a,b){if(!this.preventDefault)return new f.Event(a,b);a&&a.type?(this.originalEvent=a,this.type=a.type,this.isDefaultPrevented=a.defaultPrevented||a.returnValue===!1||a.getPreventDefault&&a.getPreventDefault()?D:C):this.type=a,b&&f.extend(this,b),this.timeStamp=f.now(),this[f.expando]=!0},f.Event.prototype={preventDefault:function(){this.isDefaultPrevented=D;var a=this.originalEvent;!a||(a.preventDefault?a.preventDefault():a.returnValue=!1)},stopPropagation:function(){this.isPropagationStopped=D;var a=this.originalEvent;!a||(a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0)},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=D,this.stopPropagation()},isDefaultPrevented:C,isPropagationStopped:C,isImmediatePropagationStopped:C};var E=function(a){var b=a.relatedTarget,c=!1,d=a.type;a.type=a.data,b!==this&&(b&&(c=f.contains(this,b)),c||(f.event.handle.apply(this,arguments),a.type=d))},F=function(a){a.type=a.data,f.event.handle.apply(this,arguments)};f.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(a,b){f.event.special[a]={setup:function(c){f.event.add(this,b,c&&c.selector?F:E,a)},teardown:function(a){f.event.remove(this,b,a&&a.selector?F:E)}}}),f.support.submitBubbles||(f.event.special.submit={setup:function(a,b){if(!f.nodeName(this,"form"))f.event.add(this,"click.specialSubmit",function(a){var b=a.target,c=f.nodeName(b,"input")||f.nodeName(b,"button")?b.type:"";(c==="submit"||c==="image")&&f(b).closest("form").length&&J("submit",this,arguments)}),f.event.add(this,"keypress.specialSubmit",function(a){var b=a.target,c=f.nodeName(b,"input")||f.nodeName(b,"button")?b.type:"";(c==="text"||c==="password")&&f(b).closest("form").length&&a.keyCode===13&&J("submit",this,arguments)});else return!1},teardown:function(a){f.event.remove(this,".specialSubmit")}});if(!f.support.changeBubbles){var G,H=function(a){var b=f.nodeName(a,"input")?a.type:"",c=a.value;b==="radio"||b==="checkbox"?c=a.checked:b==="select-multiple"?c=a.selectedIndex>-1?f.map(a.options,function(a){return a.selected}).join("-"):"":f.nodeName(a,"select")&&(c=a.selectedIndex);return c},I=function(c){var d=c.target,e,g;if(!!x.test(d.nodeName)&&!d.readOnly){e=f._data(d,"_change_data"),g=H(d),(c.type!=="focusout"||d.type!=="radio")&&f._data(d,"_change_data",g);if(e===b||g===e)return;if(e!=null||g)c.type="change",c.liveFired=b,f.event.trigger(c,arguments[1],d)}};f.event.special.change={filters:{focusout:I,beforedeactivate:I,click:function(a){var b=a.target,c=f.nodeName(b,"input")?b.type:"";(c==="radio"||c==="checkbox"||f.nodeName(b,"select"))&&I.call(this,a)},keydown:function(a){var b=a.target,c=f.nodeName(b,"input")?b.type:"";(a.keyCode===13&&!f.nodeName(b,"textarea")||a.keyCode===32&&(c==="checkbox"||c==="radio")||c==="select-multiple")&&I.call(this,a)},beforeactivate:function(a){var b=a.target;f._data(b,"_change_data",H(b))}},setup:function(a,b){if(this.type==="file")return!1;for(var c in G)f.event.add(this,c+".specialChange",G[c]);return x.test(this.nodeName)},teardown:function(a){f.event.remove(this,".specialChange");return x.test(this.nodeName)}},G=f.event.special.change.filters,G.focus=G.beforeactivate}f.support.focusinBubbles||f.each({focus:"focusin",blur:"focusout"},function(a,b){function e(a){var c=f.event.fix(a);c.type=b,c.originalEvent={},f.event.trigger(c,null,c.target),c.isDefaultPrevented()&&a.preventDefault()}var d=0;f.event.special[b]={setup:function(){d++===0&&c.addEventListener(a,e,!0)},teardown:function(){--d===0&&c.removeEventListener(a,e,!0)}}}),f.each(["bind","one"],function(a,c){f.fn[c]=function(a,d,e){var g;if(typeof a=="object"){for(var h in a)this[c](h,d,a[h],e);return this}if(arguments.length===2||d===!1)e=d,d=b;c==="one"?(g=function(a){f(this).unbind(a,g);return e.apply(this,arguments)},g.guid=e.guid||f.guid++):g=e;if(a==="unload"&&c!=="one")this.one(a,d,e);else for(var i=0,j=this.length;i<j;i++)f.event.add(this[i],a,g,d);return this}}),f.fn.extend({unbind:function(a,b){if(typeof a=="object"&&!a.preventDefault)for(var c in a)this.unbind(c,a[c]);else for(var d=0,e=this.length;d<e;d++)f.event.remove(this[d],a,b);return this},delegate:function(a,b,c,d){return this.live(b,c,d,a)},undelegate:function(a,b,c){return arguments.length===0?this.unbind("live"):this.die(b,null,c,a)},trigger:function(a,b){return this.each(function(){f.event.trigger(a,b,this)})},triggerHandler:function(a,b){if(this[0])return f.event.trigger(a,b,this[0],!0)},toggle:function(a){var b=arguments,c=a.guid||f.guid++,d=0,e=function(c){var e=(f.data(this,"lastToggle"+a.guid)||0)%d;f.data(this,"lastToggle"+a.guid,e+1),c.preventDefault();return b[e].apply(this,arguments)||!1};e.guid=c;while(d<b.length)b[d++].guid=c;return this.click(e)},hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)}});var K={focus:"focusin",blur:"focusout",mouseenter:"mouseover",mouseleave:"mouseout"};f.each(["live","die"],function(a,c){f.fn[c]=function(a,d,e,g){var h,i=0,j,k,l,m=g||this.selector,n=g?this:f(this.context);if(typeof a=="object"&&!a.preventDefault){for(var o in a)n[c](o,d,a[o],m);return this}if(c==="die"&&!a&&g&&g.charAt(0)==="."){n.unbind(g);return this}if(d===!1||f.isFunction(d))e=d||C,d=b;a=(a||"").split(" ");while((h=a[i++])!=null){j=w.exec(h),k="",j&&(k=j[0],h=h.replace(w,""));if(h==="hover"){a.push("mouseenter"+k,"mouseleave"+k);continue}l=h,K[h]?(a.push(K[h]+k),h=h+k):h=(K[h]||h)+k;if(c==="live")for(var p=0,q=n.length;p<q;p++)f.event.add(n[p],"live."+M(h,m),{data:d,selector:m,handler:e,origType:h,origHandler:e,preType:l});else n.unbind("live."+M(h,m),e)}return this}}),f.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error".split(" "),function(a,b){f.fn[b]=function(a,c){c==null&&(c=a,a=null);return arguments.length>0?this.bind(b,a,c):this.trigger(b)},f.attrFn&&(f.attrFn[b]=!0)}),function(){function u(a,b,c,d,e,f){for(var g=0,h=d.length;g<h;g++){var i=d[g];if(i){var j=!1;i=i[a];while(i){if(i.sizcache===c){j=d[i.sizset];break}if(i.nodeType===1){f||(i.sizcache=c,i.sizset=g);if(typeof b!="string"){if(i===b){j=!0;break}}else if(k.filter(b,[i]).length>0){j=i;break}}i=i[a]}d[g]=j}}}function t(a,b,c,d,e,f){for(var g=0,h=d.length;g<h;g++){var i=d[g];if(i){var j=!1;i=i[a];while(i){if(i.sizcache===c){j=d[i.sizset];break}i.nodeType===1&&!f&&(i.sizcache=c,i.sizset=g);if(i.nodeName.toLowerCase()===b){j=i;break}i=i[a]}d[g]=j}}}var a=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,d=0,e=Object.prototype.toString,g=!1,h=!0,i=/\\/g,j=/\W/;[0,0].sort(function(){h=!1;return 0});var k=function(b,d,f,g){f=f||[],d=d||c;var h=d;if(d.nodeType!==1&&d.nodeType!==9)return[];if(!b||typeof b!="string")return f;var i,j,n,o,q,r,s,t,u=!0,w=k.isXML(d),x=[],y=b;do{a.exec(""),i=a.exec(y);if(i){y=i[3],x.push(i[1]);if(i[2]){o=i[3];break}}}while(i);if(x.length>1&&m.exec(b))if(x.length===2&&l.relative[x[0]])j=v(x[0]+x[1],d);else{j=l.relative[x[0]]?[d]:k(x.shift(),d);while(x.length)b=x.shift(),l.relative[b]&&(b+=x.shift()),j=v(b,j)}else{!g&&x.length>1&&d.nodeType===9&&!w&&l.match.ID.test(x[0])&&!l.match.ID.test(x[x.length-1])&&(q=k.find(x.shift(),d,w),d=q.expr?k.filter(q.expr,q.set)[0]:q.set[0]);if(d){q=g?{expr:x.pop(),set:p(g)}:k.find(x.pop(),x.length===1&&(x[0]==="~"||x[0]==="+")&&d.parentNode?d.parentNode:d,w),j=q.expr?k.filter(q.expr,q.set):q.set,x.length>0?n=p(j):u=!1;while(x.length)r=x.pop(),s=r,l.relative[r]?s=x.pop():r="",s==null&&(s=d),l.relative[r](n,s,w)}else n=x=[]}n||(n=j),n||k.error(r||b);if(e.call(n)==="[object Array]")if(!u)f.push.apply(f,n);else if(d&&d.nodeType===1)for(t=0;n[t]!=null;t++)n[t]&&(n[t]===!0||n[t].nodeType===1&&k.contains(d,n[t]))&&f.push(j[t]);else for(t=0;n[t]!=null;t++)n[t]&&n[t].nodeType===1&&f.push(j[t]);else p(n,f);o&&(k(o,h,f,g),k.uniqueSort(f));return f};k.uniqueSort=function(a){if(r){g=h,a.sort(r);if(g)for(var b=1;b<a.length;b++)a[b]===a[b-1]&&a.splice(b--,1)}return a},k.matches=function(a,b){return k(a,null,null,b)},k.matchesSelector=function(a,b){return k(b,null,null,[a]).length>0},k.find=function(a,b,c){var d;if(!a)return[];for(var e=0,f=l.order.length;e<f;e++){var g,h=l.order[e];if(g=l.leftMatch[h].exec(a)){var j=g[1];g.splice(1,1);if(j.substr(j.length-1)!=="\\"){g[1]=(g[1]||"").replace(i,""),d=l.find[h](g,b,c);if(d!=null){a=a.replace(l.match[h],"");break}}}}d||(d=typeof b.getElementsByTagName!="undefined"?b.getElementsByTagName("*"):[]);return{set:d,expr:a}},k.filter=function(a,c,d,e){var f,g,h=a,i=[],j=c,m=c&&c[0]&&k.isXML(c[0]);while(a&&c.length){for(var n in l.filter)if((f=l.leftMatch[n].exec(a))!=null&&f[2]){var o,p,q=l.filter[n],r=f[1];g=!1,f.splice(1,1);if(r.substr(r.length-1)==="\\")continue;j===i&&(i=[]);if(l.preFilter[n]){f=l.preFilter[n](f,j,d,i,e,m);if(!f)g=o=!0;else if(f===!0)continue}if(f)for(var s=0;(p=j[s])!=null;s++)if(p){o=q(p,f,s,j);var t=e^!!o;d&&o!=null?t?g=!0:j[s]=!1:t&&(i.push(p),g=!0)}if(o!==b){d||(j=i),a=a.replace(l.match[n],"");if(!g)return[];break}}if(a===h)if(g==null)k.error(a);else break;h=a}return j},k.error=function(a){throw"Syntax error, unrecognized expression: "+a};var l=k.selectors={order:["ID","NAME","TAG"],match:{ID:/#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,CLASS:/\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,NAME:/\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,ATTR:/\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(?:(['"])(.*?)\3|(#?(?:[\w\u00c0-\uFFFF\-]|\\.)*)|)|)\s*\]/,TAG:/^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,CHILD:/:(only|nth|last|first)-child(?:\(\s*(even|odd|(?:[+\-]?\d+|(?:[+\-]?\d*)?n\s*(?:[+\-]\s*\d+)?))\s*\))?/,POS:/:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,PSEUDO:/:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/},leftMatch:{},attrMap:{"class":"className","for":"htmlFor"},attrHandle:{href:function(a){return a.getAttribute("href")},type:function(a){return a.getAttribute("type")}},relative:{"+":function(a,b){var c=typeof b=="string",d=c&&!j.test(b),e=c&&!d;d&&(b=b.toLowerCase());for(var f=0,g=a.length,h;f<g;f++)if(h=a[f]){while((h=h.previousSibling)&&h.nodeType!==1);a[f]=e||h&&h.nodeName.toLowerCase()===b?h||!1:h===b}e&&k.filter(b,a,!0)},">":function(a,b){var c,d=typeof b=="string",e=0,f=a.length;if(d&&!j.test(b)){b=b.toLowerCase();for(;e<f;e++){c=a[e];if(c){var g=c.parentNode;a[e]=g.nodeName.toLowerCase()===b?g:!1}}}else{for(;e<f;e++)c=a[e],c&&(a[e]=d?c.parentNode:c.parentNode===b);d&&k.filter(b,a,!0)}},"":function(a,b,c){var e,f=d++,g=u;typeof b=="string"&&!j.test(b)&&(b=b.toLowerCase(),e=b,g=t),g("parentNode",b,f,a,e,c)},"~":function(a,b,c){var e,f=d++,g=u;typeof b=="string"&&!j.test(b)&&(b=b.toLowerCase(),e=b,g=t),g("previousSibling",b,f,a,e,c)}},find:{ID:function(a,b,c){if(typeof b.getElementById!="undefined"&&!c){var d=b.getElementById(a[1]);return d&&d.parentNode?[d]:[]}},NAME:function(a,b){if(typeof b.getElementsByName!="undefined"){var c=[],d=b.getElementsByName(a[1]);for(var e=0,f=d.length;e<f;e++)d[e].getAttribute("name")===a[1]&&c.push(d[e]);return c.length===0?null:c}},TAG:function(a,b){if(typeof b.getElementsByTagName!="undefined")return b.getElementsByTagName(a[1])}},preFilter:{CLASS:function(a,b,c,d,e,f){a=" "+a[1].replace(i,"")+" ";if(f)return a;for(var g=0,h;(h=b[g])!=null;g++)h&&(e^(h.className&&(" "+h.className+" ").replace(/[\t\n\r]/g," ").indexOf(a)>=0)?c||d.push(h):c&&(b[g]=!1));return!1},ID:function(a){return a[1].replace(i,"")},TAG:function(a,b){return a[1].replace(i,"").toLowerCase()},CHILD:function(a){if(a[1]==="nth"){a[2]||k.error(a[0]),a[2]=a[2].replace(/^\+|\s*/g,"");var b=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(a[2]==="even"&&"2n"||a[2]==="odd"&&"2n+1"||!/\D/.test(a[2])&&"0n+"+a[2]||a[2]);a[2]=b[1]+(b[2]||1)-0,a[3]=b[3]-0}else a[2]&&k.error(a[0]);a[0]=d++;return a},ATTR:function(a,b,c,d,e,f){var g=a[1]=a[1].replace(i,"");!f&&l.attrMap[g]&&(a[1]=l.attrMap[g]),a[4]=(a[4]||a[5]||"").replace(i,""),a[2]==="~="&&(a[4]=" "+a[4]+" ");return a},PSEUDO:function(b,c,d,e,f){if(b[1]==="not")if((a.exec(b[3])||"").length>1||/^\w/.test(b[3]))b[3]=k(b[3],null,null,c);else{var g=k.filter(b[3],c,d,!0^f);d||e.push.apply(e,g);return!1}else if(l.match.POS.test(b[0])||l.match.CHILD.test(b[0]))return!0;return b},POS:function(a){a.unshift(!0);return a}},filters:{enabled:function(a){return a.disabled===!1&&a.type!=="hidden"},disabled:function(a){return a.disabled===!0},checked:function(a){return a.checked===!0},selected:function(a){a.parentNode&&a.parentNode.selectedIndex;return a.selected===!0},parent:function(a){return!!a.firstChild},empty:function(a){return!a.firstChild},has:function(a,b,c){return!!k(c[3],a).length},header:function(a){return/h\d/i.test(a.nodeName)},text:function(a){var b=a.getAttribute("type"),c=a.type;return a.nodeName.toLowerCase()==="input"&&"text"===c&&(b===c||b===null)},radio:function(a){return a.nodeName.toLowerCase()==="input"&&"radio"===a.type},checkbox:function(a){return a.nodeName.toLowerCase()==="input"&&"checkbox"===a.type},file:function(a){return a.nodeName.toLowerCase()==="input"&&"file"===a.type},password:function(a){return a.nodeName.toLowerCase()==="input"&&"password"===a.type},submit:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"submit"===a.type},image:function(a){return a.nodeName.toLowerCase()==="input"&&"image"===a.type},reset:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"reset"===a.type},button:function(a){var b=a.nodeName.toLowerCase();return b==="input"&&"button"===a.type||b==="button"},input:function(a){return/input|select|textarea|button/i.test(a.nodeName)},focus:function(a){return a===a.ownerDocument.activeElement}},setFilters:{first:function(a,b){return b===0},last:function(a,b,c,d){return b===d.length-1},even:function(a,b){return b%2===0},odd:function(a,b){return b%2===1},lt:function(a,b,c){return b<c[3]-0},gt:function(a,b,c){return b>c[3]-0},nth:function(a,b,c){return c[3]-0===b},eq:function(a,b,c){return c[3]-0===b}},filter:{PSEUDO:function(a,b,c,d){var e=b[1],f=l.filters[e];if(f)return f(a,c,b,d);if(e==="contains")return(a.textContent||a.innerText||k.getText([a])||"").indexOf(b[3])>=0;if(e==="not"){var g=b[3];for(var h=0,i=g.length;h<i;h++)if(g[h]===a)return!1;return!0}k.error(e)},CHILD:function(a,b){var c=b[1],d=a;switch(c){case"only":case"first":while(d=d.previousSibling)if(d.nodeType===1)return!1;if(c==="first")return!0;d=a;case"last":while(d=d.nextSibling)if(d.nodeType===1)return!1;return!0;case"nth":var e=b[2],f=b[3];if(e===1&&f===0)return!0;var g=b[0],h=a.parentNode;if(h&&(h.sizcache!==g||!a.nodeIndex)){var i=0;for(d=h.firstChild;d;d=d.nextSibling)d.nodeType===1&&(d.nodeIndex=++i);h.sizcache=g}var j=a.nodeIndex-f;return e===0?j===0:j%e===0&&j/e>=0}},ID:function(a,b){return a.nodeType===1&&a.getAttribute("id")===b},TAG:function(a,b){return b==="*"&&a.nodeType===1||a.nodeName.toLowerCase()===b},CLASS:function(a,b){return(" "+(a.className||a.getAttribute("class"))+" ").indexOf(b)>-1},ATTR:function(a,b){var c=b[1],d=l.attrHandle[c]?l.attrHandle[c](a):a[c]!=null?a[c]:a.getAttribute(c),e=d+"",f=b[2],g=b[4];return d==null?f==="!=":f==="="?e===g:f==="*="?e.indexOf(g)>=0:f==="~="?(" "+e+" ").indexOf(g)>=0:g?f==="!="?e!==g:f==="^="?e.indexOf(g)===0:f==="$="?e.substr(e.length-g.length)===g:f==="|="?e===g||e.substr(0,g.length+1)===g+"-":!1:e&&d!==!1},POS:function(a,b,c,d){var e=b[2],f=l.setFilters[e];if(f)return f(a,c,b,d)}}},m=l.match.POS,n=function(a,b){return"\\"+(b-0+1)};for(var o in l.match)l.match[o]=new RegExp(l.match[o].source+/(?![^\[]*\])(?![^\(]*\))/.source),l.leftMatch[o]=new RegExp(/(^(?:.|\r|\n)*?)/.source+l.match[o].source.replace(/\\(\d+)/g,n));var p=function(a,b){a=Array.prototype.slice.call(a,0);if(b){b.push.apply(b,a);return b}return a};try{Array.prototype.slice.call(c.documentElement.childNodes,0)[0].nodeType}catch(q){p=function(a,b){var c=0,d=b||[];if(e.call(a)==="[object Array]")Array.prototype.push.apply(d,a);else if(typeof a.length=="number")for(var f=a.length;c<f;c++)d.push(a[c]);else for(;a[c];c++)d.push(a[c]);return d}}var r,s;c.documentElement.compareDocumentPosition?r=function(a,b){if(a===b){g=!0;return 0}if(!a.compareDocumentPosition||!b.compareDocumentPosition)return a.compareDocumentPosition?-1:1;return a.compareDocumentPosition(b)&4?-1:1}:(r=function(a,b){if(a===b){g=!0;return 0}if(a.sourceIndex&&b.sourceIndex)return a.sourceIndex-b.sourceIndex;var c,d,e=[],f=[],h=a.parentNode,i=b.parentNode,j=h;if(h===i)return s(a,b);if(!h)return-1;if(!i)return 1;while(j)e.unshift(j),j=j.parentNode;j=i;while(j)f.unshift(j),j=j.parentNode;c=e.length,d=f.length;for(var k=0;k<c&&k<d;k++)if(e[k]!==f[k])return s(e[k],f[k]);return k===c?s(a,f[k],-1):s(e[k],b,1)},s=function(a,b,c){if(a===b)return c;var d=a.nextSibling;while(d){if(d===b)return-1;d=d.nextSibling}return 1}),k.getText=function(a){var b="",c;for(var d=0;a[d];d++)c=a[d],c.nodeType===3||c.nodeType===4?b+=c.nodeValue:c.nodeType!==8&&(b+=k.getText(c.childNodes));return b},function(){var a=c.createElement("div"),d="script"+(new Date).getTime(),e=c.documentElement;a.innerHTML="<a name='"+d+"'/>",e.insertBefore(a,e.firstChild),c.getElementById(d)&&(l.find.ID=function(a,c,d){if(typeof c.getElementById!="undefined"&&!d){var e=c.getElementById(a[1]);return e?e.id===a[1]||typeof e.getAttributeNode!="undefined"&&e.getAttributeNode("id").nodeValue===a[1]?[e]:b:[]}},l.filter.ID=function(a,b){var c=typeof a.getAttributeNode!="undefined"&&a.getAttributeNode("id");return a.nodeType===1&&c&&c.nodeValue===b}),e.removeChild(a),e=a=null}(),function(){var a=c.createElement("div");a.appendChild(c.createComment("")),a.getElementsByTagName("*").length>0&&(l.find.TAG=function(a,b){var c=b.getElementsByTagName(a[1]);if(a[1]==="*"){var d=[];for(var e=0;c[e];e++)c[e].nodeType===1&&d.push(c[e]);c=d}return c}),a.innerHTML="<a href='#'></a>",a.firstChild&&typeof a.firstChild.getAttribute!="undefined"&&a.firstChild.getAttribute("href")!=="#"&&(l.attrHandle.href=function(a){return a.getAttribute("href",2)}),a=null}(),c.querySelectorAll&&function(){var a=k,b=c.createElement("div"),d="__sizzle__";b.innerHTML="<p class='TEST'></p>";if(!b.querySelectorAll||b.querySelectorAll(".TEST").length!==0){k=function(b,e,f,g){e=e||c;if(!g&&!k.isXML(e)){var h=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b);if(h&&(e.nodeType===1||e.nodeType===9)){if(h[1])return p(e.getElementsByTagName(b),f);if(h[2]&&l.find.CLASS&&e.getElementsByClassName)return p(e.getElementsByClassName(h[2]),f)}if(e.nodeType===9){if(b==="body"&&e.body)return p([e.body],f);if(h&&h[3]){var i=e.getElementById(h[3]);if(!i||!i.parentNode)return p([],f);if(i.id===h[3])return p([i],f)}try{return p(e.querySelectorAll(b),f)}catch(j){}}else if(e.nodeType===1&&e.nodeName.toLowerCase()!=="object"){var m=e,n=e.getAttribute("id"),o=n||d,q=e.parentNode,r=/^\s*[+~]/.test(b);n?o=o.replace(/'/g,"\\$&"):e.setAttribute("id",o),r&&q&&(e=e.parentNode);try{if(!r||q)return p(e.querySelectorAll("[id='"+o+"'] "+b),f)}catch(s){}finally{n||m.removeAttribute("id")}}}return a(b,e,f,g)};for(var e in a)k[e]=a[e];b=null}}(),function(){var a=c.documentElement,b=a.matchesSelector||a.mozMatchesSelector||a.webkitMatchesSelector||a.msMatchesSelector;if(b){var d=!b.call(c.createElement("div"),"div"),e=!1;try{b.call(c.documentElement,"[test!='']:sizzle")}catch(f){e=!0}k.matchesSelector=function(a,c){c=c.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!k.isXML(a))try{if(e||!l.match.PSEUDO.test(c)&&!/!=/.test(c)){var f=b.call(a,c);if(f||!d||a.document&&a.document.nodeType!==11)return f}}catch(g){}return k(c,null,null,[a]).length>0}}}(),function(){var a=c.createElement("div");a.innerHTML="<div class='test e'></div><div class='test'></div>";if(!!a.getElementsByClassName&&a.getElementsByClassName("e").length!==0){a.lastChild.className="e";if(a.getElementsByClassName("e").length===1)return;l.order.splice(1,0,"CLASS"),l.find.CLASS=function(a,b,c){if(typeof b.getElementsByClassName!="undefined"&&!c)return b.getElementsByClassName(a[1])},a=null}}(),c.documentElement.contains?k.contains=function(a,b){return a!==b&&(a.contains?a.contains(b):!0)}:c.documentElement.compareDocumentPosition?k.contains=function(a,b){return!!(a.compareDocumentPosition(b)&16)}:k.contains=function(){return!1},k.isXML=function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!=="HTML":!1};var v=function(a,b){var c,d=[],e="",f=b.nodeType?[b]:b;while(c=l.match.PSEUDO.exec(a))e+=c[0],a=a.replace(l.match.PSEUDO,"");a=l.relative[a]?a+"*":a;for(var g=0,h=f.length;g<h;g++)k(a,f[g],d);return k.filter(e,d)};f.find=k,f.expr=k.selectors,f.expr[":"]=f.expr.filters,f.unique=k.uniqueSort,f.text=k.getText,f.isXMLDoc=k.isXML,f.contains=k.contains}();var N=/Until$/,O=/^(?:parents|prevUntil|prevAll)/,P=/,/,Q=/^.[^:#\[\.,]*$/,R=Array.prototype.slice,S=f.expr.match.POS,T={children:!0,contents:!0,next:!0,prev:!0};f.fn.extend({find:function(a){var b=this,c,d;if(typeof a!="string")return f(a).filter(function(){for(c=0,d=b.length;c<d;c++)if(f.contains(b[c],this))return!0});var e=this.pushStack("","find",a),g,h,i;for(c=0,d=this.length;c<d;c++){g=e.length,f.find(a,this[c],e);if(c>0)for(h=g;h<e.length;h++)for(i=0;i<g;i++)if(e[i]===e[h]){e.splice(h--,1);break}}return e},has:function(a){var b=f(a);return this.filter(function(){for(var a=0,c=b.length;a<c;a++)if(f.contains(this,b[a]))return!0})},not:function(a){return this.pushStack(V(this,a,!1),"not",a)},filter:function(a){return this.pushStack(V(this,a,!0),"filter",a)},is:function(a){return!!a&&(typeof a=="string"?f.filter(a,this).length>0:this.filter(a).length>0)},closest:function(a,b){var c=[],d,e,g=this[0];if(f.isArray(a)){var h,i,j={},k=1;if(g&&a.length){for(d=0,e=a.length;d<e;d++)i=a[d],j[i]||(j[i]=S.test(i)?f(i,b||this.context):i);while(g&&g.ownerDocument&&g!==b){for(i in j)h=j[i],(h.jquery?h.index(g)>-1:f(g).is(h))&&c.push({selector:i,elem:g,level:k});g=g.parentNode,k++}}return c}var l=S.test(a)||typeof a!="string"?f(a,b||this.context):0;for(d=0,e=this.length;d<e;d++){g=this[d];while(g){if(l?l.index(g)>-1:f.find.matchesSelector(g,a)){c.push(g);break}g=g.parentNode;if(!g||!g.ownerDocument||g===b||g.nodeType===11)break}}c=c.length>1?f.unique(c):c;return this.pushStack(c,"closest",a)},index:function(a){if(!a)return this[0]&&this[0].parentNode?this.prevAll().length:-1;if(typeof a=="string")return f.inArray(this[0],f(a));return f.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var c=typeof a=="string"?f(a,b):f.makeArray(a&&a.nodeType?[a]:a),d=f.merge(this.get(),c);return this.pushStack(U(c[0])||U(d[0])?d:f.unique(d))},andSelf:function(){return this.add(this.prevObject)}}),f.each({parent:function(a){var b=a.parentNode;return b&&b.nodeType!==11?b:null},parents:function(a){return f.dir(a,"parentNode")},parentsUntil:function(a,b,c){return f.dir(a,"parentNode",c)},next:function(a){return f.nth(a,2,"nextSibling")},prev:function(a){return f.nth(a,2,"previousSibling")},nextAll:function(a){return f.dir(a,"nextSibling")},prevAll:function(a){return f.dir(a,"previousSibling")},nextUntil:function(a,b,c){return f.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return f.dir(a,"previousSibling",c)},siblings:function(a){return f.sibling(a.parentNode.firstChild,a)},children:function(a){return f.sibling(a.firstChild)},contents:function(a){return f.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:f.makeArray(a.childNodes)}},function(a,b){f.fn[a]=function(c,d){var e=f.map(this,b,c),g=R.call(arguments);N.test(a)||(d=c),d&&typeof d=="string"&&(e=f.filter(d,e)),e=this.length>1&&!T[a]?f.unique(e):e,(this.length>1||P.test(d))&&O.test(a)&&(e=e.reverse());return this.pushStack(e,a,g.join(","))}}),f.extend({filter:function(a,b,c){c&&(a=":not("+a+")");return b.length===1?f.find.matchesSelector(b[0],a)?[b[0]]:[]:f.find.matches(a,b)},dir:function(a,c,d){var e=[],g=a[c];while(g&&g.nodeType!==9&&(d===b||g.nodeType!==1||!f(g).is(d)))g.nodeType===1&&e.push(g),g=g[c];return e},nth:function(a,b,c,d){b=b||1;var e=0;for(;a;a=a[c])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){var c=[];for(;a;a=a.nextSibling)a.nodeType===1&&a!==b&&c.push(a);return c}});var W=/ jQuery\d+="(?:\d+|null)"/g,X=/^\s+/,Y=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,Z=/<([\w:]+)/,$=/<tbody/i,_=/<|&#?\w+;/,ba=/<(?:script|object|embed|option|style)/i,bb=/checked\s*(?:[^=]|=\s*.checked.)/i,bc=/\/(java|ecma)script/i,bd=/^\s*<!(?:\[CDATA\[|\-\-)/,be={option:[1,"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],area:[1,"<map>","</map>"],_default:[0,"",""]};be.optgroup=be.option,be.tbody=be.tfoot=be.colgroup=be.caption=be.thead,be.th=be.td,f.support.htmlSerialize||(be._default=[1,"div<div>","</div>"]),f.fn.extend({text:function(a){if(f.isFunction(a))return this.each(function(b){var c=f(this);c.text(a.call(this,b,c.text()))});if(typeof a!="object"&&a!==b)return this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a));return f.text(this)},wrapAll:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapAll(a.call(this,b))});if(this[0]){var b=f(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&a.firstChild.nodeType===1)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapInner(a.call(this,b))});return this.each(function(){var b=f(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){return this.each(function(){f(this).wrapAll(a)})},unwrap:function(){return this.parent().each(function(){f.nodeName(this,"body")||f(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=f(arguments[0]);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,f(arguments[0]).toArray());return a}},remove:function(a,b){for(var c=0,d;(d=this[c])!=null;c++)if(!a||f.filter(a,[d]).length)!b&&d.nodeType===1&&(f.cleanData(d.getElementsByTagName("*")),f.cleanData([d])),d.parentNode&&d.parentNode.removeChild(d);return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++){b.nodeType===1&&f.cleanData(b.getElementsByTagName("*"));while(b.firstChild)b.removeChild(b.firstChild)}return this},clone:function(a,b){a=a==null?!1:a,b=b==null?a:b;return this.map(function(){return f.clone(this,a,b)})},html:function(a){if(a===b)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(W,""):null;if(typeof a=="string"&&!ba.test(a)&&(f.support.leadingWhitespace||!X.test(a))&&!be[(Z.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(Y,"<$1></$2>");try{for(var c=0,d=this.length;c<d;c++)this[c].nodeType===1&&(f.cleanData(this[c].getElementsByTagName("*")),this[c].innerHTML=a)}catch(e){this.empty().append(a)}}else f.isFunction(a)?this.each(function(b){var c=f(this);c.html(a.call(this,b,c.html()))}):this.empty().append(a);return this},replaceWith:function(a){if(this[0]&&this[0].parentNode){if(f.isFunction(a))return this.each(function(b){var c=f(this),d=c.html();c.replaceWith(a.call(this,b,d))});typeof a!="string"&&(a=f(a).detach());return this.each(function(){var b=this.nextSibling,c=this.parentNode;f(this).remove(),b?f(b).before(a):f(c).append(a)})}return this.length?this.pushStack(f(f.isFunction(a)?a():a),"replaceWith",a):this},detach:function(a){return this.remove(a,!0)},domManip:function(a,c,d){var e,g,h,i,j=a[0],k=[];if(!f.support.checkClone&&arguments.length===3&&typeof j=="string"&&bb.test(j))return this.each(function(){f(this).domManip(a,c,d,!0)});if(f.isFunction(j))return this.each(function(e){var g=f(this);a[0]=j.call(this,e,c?g.html():b),g.domManip(a,c,d)});if(this[0]){i=j&&j.parentNode,f.support.parentNode&&i&&i.nodeType===11&&i.childNodes.length===this.length?e={fragment:i}:e=f.buildFragment(a,this,k),h=e.fragment,h.childNodes.length===1?g=h=h.firstChild:g=h.firstChild;if(g){c=c&&f.nodeName(g,"tr");for(var l=0,m=this.length,n=m-1;l<m;l++)d.call(c?bf(this[l],g):this[l],e.cacheable||m>1&&l<n?f.clone(h,!0,!0):h)}k.length&&f.each(k,bl)}return this}}),f.buildFragment=function(a,b,d){var e,g,h,i;b&&b[0]&&(i=b[0].ownerDocument||b[0]),i.createDocumentFragment||(i=c),a.length===1&&typeof a[0]=="string"&&a[0].length<512&&i===c&&a[0].charAt(0)==="<"&&!ba.test(a[0])&&(f.support.checkClone||!bb.test(a[0]))&&(g=!0,h=f.fragments[a[0]],h&&h!==1&&(e=h)),e||(e=i.createDocumentFragment(),f.clean
-(a,i,e,d)),g&&(f.fragments[a[0]]=h?e:1);return{fragment:e,cacheable:g}},f.fragments={},f.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){f.fn[a]=function(c){var d=[],e=f(c),g=this.length===1&&this[0].parentNode;if(g&&g.nodeType===11&&g.childNodes.length===1&&e.length===1){e[b](this[0]);return this}for(var h=0,i=e.length;h<i;h++){var j=(h>0?this.clone(!0):this).get();f(e[h])[b](j),d=d.concat(j)}return this.pushStack(d,a,e.selector)}}),f.extend({clone:function(a,b,c){var d=a.cloneNode(!0),e,g,h;if((!f.support.noCloneEvent||!f.support.noCloneChecked)&&(a.nodeType===1||a.nodeType===11)&&!f.isXMLDoc(a)){bh(a,d),e=bi(a),g=bi(d);for(h=0;e[h];++h)g[h]&&bh(e[h],g[h])}if(b){bg(a,d);if(c){e=bi(a),g=bi(d);for(h=0;e[h];++h)bg(e[h],g[h])}}e=g=null;return d},clean:function(a,b,d,e){var g;b=b||c,typeof b.createElement=="undefined"&&(b=b.ownerDocument||b[0]&&b[0].ownerDocument||c);var h=[],i;for(var j=0,k;(k=a[j])!=null;j++){typeof k=="number"&&(k+="");if(!k)continue;if(typeof k=="string")if(!_.test(k))k=b.createTextNode(k);else{k=k.replace(Y,"<$1></$2>");var l=(Z.exec(k)||["",""])[1].toLowerCase(),m=be[l]||be._default,n=m[0],o=b.createElement("div");o.innerHTML=m[1]+k+m[2];while(n--)o=o.lastChild;if(!f.support.tbody){var p=$.test(k),q=l==="table"&&!p?o.firstChild&&o.firstChild.childNodes:m[1]==="<table>"&&!p?o.childNodes:[];for(i=q.length-1;i>=0;--i)f.nodeName(q[i],"tbody")&&!q[i].childNodes.length&&q[i].parentNode.removeChild(q[i])}!f.support.leadingWhitespace&&X.test(k)&&o.insertBefore(b.createTextNode(X.exec(k)[0]),o.firstChild),k=o.childNodes}var r;if(!f.support.appendChecked)if(k[0]&&typeof (r=k.length)=="number")for(i=0;i<r;i++)bk(k[i]);else bk(k);k.nodeType?h.push(k):h=f.merge(h,k)}if(d){g=function(a){return!a.type||bc.test(a.type)};for(j=0;h[j];j++)if(e&&f.nodeName(h[j],"script")&&(!h[j].type||h[j].type.toLowerCase()==="text/javascript"))e.push(h[j].parentNode?h[j].parentNode.removeChild(h[j]):h[j]);else{if(h[j].nodeType===1){var s=f.grep(h[j].getElementsByTagName("script"),g);h.splice.apply(h,[j+1,0].concat(s))}d.appendChild(h[j])}}return h},cleanData:function(a){var b,c,d=f.cache,e=f.expando,g=f.event.special,h=f.support.deleteExpando;for(var i=0,j;(j=a[i])!=null;i++){if(j.nodeName&&f.noData[j.nodeName.toLowerCase()])continue;c=j[f.expando];if(c){b=d[c]&&d[c][e];if(b&&b.events){for(var k in b.events)g[k]?f.event.remove(j,k):f.removeEvent(j,k,b.handle);b.handle&&(b.handle.elem=null)}h?delete j[f.expando]:j.removeAttribute&&j.removeAttribute(f.expando),delete d[c]}}}});var bm=/alpha\([^)]*\)/i,bn=/opacity=([^)]*)/,bo=/([A-Z]|^ms)/g,bp=/^-?\d+(?:px)?$/i,bq=/^-?\d/,br=/^([\-+])=([\-+.\de]+)/,bs={position:"absolute",visibility:"hidden",display:"block"},bt=["Left","Right"],bu=["Top","Bottom"],bv,bw,bx;f.fn.css=function(a,c){if(arguments.length===2&&c===b)return this;return f.access(this,a,c,!0,function(a,c,d){return d!==b?f.style(a,c,d):f.css(a,c)})},f.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=bv(a,"opacity","opacity");return c===""?"1":c}return a.style.opacity}}},cssNumber:{fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":f.support.cssFloat?"cssFloat":"styleFloat"},style:function(a,c,d,e){if(!!a&&a.nodeType!==3&&a.nodeType!==8&&!!a.style){var g,h,i=f.camelCase(c),j=a.style,k=f.cssHooks[i];c=f.cssProps[i]||i;if(d===b){if(k&&"get"in k&&(g=k.get(a,!1,e))!==b)return g;return j[c]}h=typeof d,h==="string"&&(g=br.exec(d))&&(d=+(g[1]+1)*+g[2]+parseFloat(f.css(a,c)),h="number");if(d==null||h==="number"&&isNaN(d))return;h==="number"&&!f.cssNumber[i]&&(d+="px");if(!k||!("set"in k)||(d=k.set(a,d))!==b)try{j[c]=d}catch(l){}}},css:function(a,c,d){var e,g;c=f.camelCase(c),g=f.cssHooks[c],c=f.cssProps[c]||c,c==="cssFloat"&&(c="float");if(g&&"get"in g&&(e=g.get(a,!0,d))!==b)return e;if(bv)return bv(a,c)},swap:function(a,b,c){var d={};for(var e in b)d[e]=a.style[e],a.style[e]=b[e];c.call(a);for(e in b)a.style[e]=d[e]}}),f.curCSS=f.css,f.each(["height","width"],function(a,b){f.cssHooks[b]={get:function(a,c,d){var e;if(c){if(a.offsetWidth!==0)return by(a,b,d);f.swap(a,bs,function(){e=by(a,b,d)});return e}},set:function(a,b){if(!bp.test(b))return b;b=parseFloat(b);if(b>=0)return b+"px"}}}),f.support.opacity||(f.cssHooks.opacity={get:function(a,b){return bn.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?parseFloat(RegExp.$1)/100+"":b?"1":""},set:function(a,b){var c=a.style,d=a.currentStyle,e=f.isNaN(b)?"":"alpha(opacity="+b*100+")",g=d&&d.filter||c.filter||"";c.zoom=1;if(b>=1&&f.trim(g.replace(bm,""))===""){c.removeAttribute("filter");if(d&&!d.filter)return}c.filter=bm.test(g)?g.replace(bm,e):g+" "+e}}),f(function(){f.support.reliableMarginRight||(f.cssHooks.marginRight={get:function(a,b){var c;f.swap(a,{display:"inline-block"},function(){b?c=bv(a,"margin-right","marginRight"):c=a.style.marginRight});return c}})}),c.defaultView&&c.defaultView.getComputedStyle&&(bw=function(a,c){var d,e,g;c=c.replace(bo,"-$1").toLowerCase();if(!(e=a.ownerDocument.defaultView))return b;if(g=e.getComputedStyle(a,null))d=g.getPropertyValue(c),d===""&&!f.contains(a.ownerDocument.documentElement,a)&&(d=f.style(a,c));return d}),c.documentElement.currentStyle&&(bx=function(a,b){var c,d=a.currentStyle&&a.currentStyle[b],e=a.runtimeStyle&&a.runtimeStyle[b],f=a.style;!bp.test(d)&&bq.test(d)&&(c=f.left,e&&(a.runtimeStyle.left=a.currentStyle.left),f.left=b==="fontSize"?"1em":d||0,d=f.pixelLeft+"px",f.left=c,e&&(a.runtimeStyle.left=e));return d===""?"auto":d}),bv=bw||bx,f.expr&&f.expr.filters&&(f.expr.filters.hidden=function(a){var b=a.offsetWidth,c=a.offsetHeight;return b===0&&c===0||!f.support.reliableHiddenOffsets&&(a.style.display||f.css(a,"display"))==="none"},f.expr.filters.visible=function(a){return!f.expr.filters.hidden(a)});var bz=/%20/g,bA=/\[\]$/,bB=/\r?\n/g,bC=/#.*$/,bD=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,bE=/^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,bF=/^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,bG=/^(?:GET|HEAD)$/,bH=/^\/\//,bI=/\?/,bJ=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,bK=/^(?:select|textarea)/i,bL=/\s+/,bM=/([?&])_=[^&]*/,bN=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,bO=f.fn.load,bP={},bQ={},bR,bS,bT=["*/"]+["*"];try{bR=e.href}catch(bU){bR=c.createElement("a"),bR.href="",bR=bR.href}bS=bN.exec(bR.toLowerCase())||[],f.fn.extend({load:function(a,c,d){if(typeof a!="string"&&bO)return bO.apply(this,arguments);if(!this.length)return this;var e=a.indexOf(" ");if(e>=0){var g=a.slice(e,a.length);a=a.slice(0,e)}var h="GET";c&&(f.isFunction(c)?(d=c,c=b):typeof c=="object"&&(c=f.param(c,f.ajaxSettings.traditional),h="POST"));var i=this;f.ajax({url:a,type:h,dataType:"html",data:c,complete:function(a,b,c){c=a.responseText,a.isResolved()&&(a.done(function(a){c=a}),i.html(g?f("<div>").append(c.replace(bJ,"")).find(g):c)),d&&i.each(d,[c,b,a])}});return this},serialize:function(){return f.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?f.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||bK.test(this.nodeName)||bE.test(this.type))}).map(function(a,b){var c=f(this).val();return c==null?null:f.isArray(c)?f.map(c,function(a,c){return{name:b.name,value:a.replace(bB,"\r\n")}}):{name:b.name,value:c.replace(bB,"\r\n")}}).get()}}),f.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){f.fn[b]=function(a){return this.bind(b,a)}}),f.each(["get","post"],function(a,c){f[c]=function(a,d,e,g){f.isFunction(d)&&(g=g||e,e=d,d=b);return f.ajax({type:c,url:a,data:d,success:e,dataType:g})}}),f.extend({getScript:function(a,c){return f.get(a,b,c,"script")},getJSON:function(a,b,c){return f.get(a,b,c,"json")},ajaxSetup:function(a,b){b?bX(a,f.ajaxSettings):(b=a,a=f.ajaxSettings),bX(a,b);return a},ajaxSettings:{url:bR,isLocal:bF.test(bS[1]),global:!0,type:"GET",contentType:"application/x-www-form-urlencoded",processData:!0,async:!0,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":bT},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":a.String,"text html":!0,"text json":f.parseJSON,"text xml":f.parseXML},flatOptions:{context:!0,url:!0}},ajaxPrefilter:bV(bP),ajaxTransport:bV(bQ),ajax:function(a,c){function w(a,c,l,m){if(s!==2){s=2,q&&clearTimeout(q),p=b,n=m||"",v.readyState=a>0?4:0;var o,r,u,w=c,x=l?bZ(d,v,l):b,y,z;if(a>=200&&a<300||a===304){if(d.ifModified){if(y=v.getResponseHeader("Last-Modified"))f.lastModified[k]=y;if(z=v.getResponseHeader("Etag"))f.etag[k]=z}if(a===304)w="notmodified",o=!0;else try{r=b$(d,x),w="success",o=!0}catch(A){w="parsererror",u=A}}else{u=w;if(!w||a)w="error",a<0&&(a=0)}v.status=a,v.statusText=""+(c||w),o?h.resolveWith(e,[r,w,v]):h.rejectWith(e,[v,w,u]),v.statusCode(j),j=b,t&&g.trigger("ajax"+(o?"Success":"Error"),[v,d,o?r:u]),i.resolveWith(e,[v,w]),t&&(g.trigger("ajaxComplete",[v,d]),--f.active||f.event.trigger("ajaxStop"))}}typeof a=="object"&&(c=a,a=b),c=c||{};var d=f.ajaxSetup({},c),e=d.context||d,g=e!==d&&(e.nodeType||e instanceof f)?f(e):f.event,h=f.Deferred(),i=f._Deferred(),j=d.statusCode||{},k,l={},m={},n,o,p,q,r,s=0,t,u,v={readyState:0,setRequestHeader:function(a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this},getAllResponseHeaders:function(){return s===2?n:null},getResponseHeader:function(a){var c;if(s===2){if(!o){o={};while(c=bD.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c},overrideMimeType:function(a){s||(d.mimeType=a);return this},abort:function(a){a=a||"abort",p&&p.abort(a),w(0,a);return this}};h.promise(v),v.success=v.done,v.error=v.fail,v.complete=i.done,v.statusCode=function(a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b)}return this},d.url=((a||d.url)+"").replace(bC,"").replace(bH,bS[1]+"//"),d.dataTypes=f.trim(d.dataType||"*").toLowerCase().split(bL),d.crossDomain==null&&(r=bN.exec(d.url.toLowerCase()),d.crossDomain=!(!r||r[1]==bS[1]&&r[2]==bS[2]&&(r[3]||(r[1]==="http:"?80:443))==(bS[3]||(bS[1]==="http:"?80:443)))),d.data&&d.processData&&typeof d.data!="string"&&(d.data=f.param(d.data,d.traditional)),bW(bP,d,c,v);if(s===2)return!1;t=d.global,d.type=d.type.toUpperCase(),d.hasContent=!bG.test(d.type),t&&f.active++===0&&f.event.trigger("ajaxStart");if(!d.hasContent){d.data&&(d.url+=(bI.test(d.url)?"&":"?")+d.data,delete d.data),k=d.url;if(d.cache===!1){var x=f.now(),y=d.url.replace(bM,"$1_="+x);d.url=y+(y===d.url?(bI.test(d.url)?"&":"?")+"_="+x:"")}}(d.data&&d.hasContent&&d.contentType!==!1||c.contentType)&&v.setRequestHeader("Content-Type",d.contentType),d.ifModified&&(k=k||d.url,f.lastModified[k]&&v.setRequestHeader("If-Modified-Since",f.lastModified[k]),f.etag[k]&&v.setRequestHeader("If-None-Match",f.etag[k])),v.setRequestHeader("Accept",d.dataTypes[0]&&d.accepts[d.dataTypes[0]]?d.accepts[d.dataTypes[0]]+(d.dataTypes[0]!=="*"?", "+bT+"; q=0.01":""):d.accepts["*"]);for(u in d.headers)v.setRequestHeader(u,d.headers[u]);if(d.beforeSend&&(d.beforeSend.call(e,v,d)===!1||s===2)){v.abort();return!1}for(u in{success:1,error:1,complete:1})v[u](d[u]);p=bW(bQ,d,c,v);if(!p)w(-1,"No Transport");else{v.readyState=1,t&&g.trigger("ajaxSend",[v,d]),d.async&&d.timeout>0&&(q=setTimeout(function(){v.abort("timeout")},d.timeout));try{s=1,p.send(l,w)}catch(z){s<2?w(-1,z):f.error(z)}}return v},param:function(a,c){var d=[],e=function(a,b){b=f.isFunction(b)?b():b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};c===b&&(c=f.ajaxSettings.traditional);if(f.isArray(a)||a.jquery&&!f.isPlainObject(a))f.each(a,function(){e(this.name,this.value)});else for(var g in a)bY(g,a[g],c,e);return d.join("&").replace(bz,"+")}}),f.extend({active:0,lastModified:{},etag:{}});var b_=f.now(),ca=/(\=)\?(&|$)|\?\?/i;f.ajaxSetup({jsonp:"callback",jsonpCallback:function(){return f.expando+"_"+b_++}}),f.ajaxPrefilter("json jsonp",function(b,c,d){var e=b.contentType==="application/x-www-form-urlencoded"&&typeof b.data=="string";if(b.dataTypes[0]==="jsonp"||b.jsonp!==!1&&(ca.test(b.url)||e&&ca.test(b.data))){var g,h=b.jsonpCallback=f.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,i=a[h],j=b.url,k=b.data,l="$1"+h+"$2";b.jsonp!==!1&&(j=j.replace(ca,l),b.url===j&&(e&&(k=k.replace(ca,l)),b.data===k&&(j+=(/\?/.test(j)?"&":"?")+b.jsonp+"="+h))),b.url=j,b.data=k,a[h]=function(a){g=[a]},d.always(function(){a[h]=i,g&&f.isFunction(i)&&a[h](g[0])}),b.converters["script json"]=function(){g||f.error(h+" was not called");return g[0]},b.dataTypes[0]="json";return"script"}}),f.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/javascript|ecmascript/},converters:{"text script":function(a){f.globalEval(a);return a}}}),f.ajaxPrefilter("script",function(a){a.cache===b&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),f.ajaxTransport("script",function(a){if(a.crossDomain){var d,e=c.head||c.getElementsByTagName("head")[0]||c.documentElement;return{send:function(f,g){d=c.createElement("script"),d.async="async",a.scriptCharset&&(d.charset=a.scriptCharset),d.src=a.url,d.onload=d.onreadystatechange=function(a,c){if(c||!d.readyState||/loaded|complete/.test(d.readyState))d.onload=d.onreadystatechange=null,e&&d.parentNode&&e.removeChild(d),d=b,c||g(200,"success")},e.insertBefore(d,e.firstChild)},abort:function(){d&&d.onload(0,1)}}}});var cb=a.ActiveXObject?function(){for(var a in cd)cd[a](0,1)}:!1,cc=0,cd;f.ajaxSettings.xhr=a.ActiveXObject?function(){return!this.isLocal&&ce()||cf()}:ce,function(a){f.extend(f.support,{ajax:!!a,cors:!!a&&"withCredentials"in a})}(f.ajaxSettings.xhr()),f.support.ajax&&f.ajaxTransport(function(c){if(!c.crossDomain||f.support.cors){var d;return{send:function(e,g){var h=c.xhr(),i,j;c.username?h.open(c.type,c.url,c.async,c.username,c.password):h.open(c.type,c.url,c.async);if(c.xhrFields)for(j in c.xhrFields)h[j]=c.xhrFields[j];c.mimeType&&h.overrideMimeType&&h.overrideMimeType(c.mimeType),!c.crossDomain&&!e["X-Requested-With"]&&(e["X-Requested-With"]="XMLHttpRequest");try{for(j in e)h.setRequestHeader(j,e[j])}catch(k){}h.send(c.hasContent&&c.data||null),d=function(a,e){var j,k,l,m,n;try{if(d&&(e||h.readyState===4)){d=b,i&&(h.onreadystatechange=f.noop,cb&&delete cd[i]);if(e)h.readyState!==4&&h.abort();else{j=h.status,l=h.getAllResponseHeaders(),m={},n=h.responseXML,n&&n.documentElement&&(m.xml=n),m.text=h.responseText;try{k=h.statusText}catch(o){k=""}!j&&c.isLocal&&!c.crossDomain?j=m.text?200:404:j===1223&&(j=204)}}}catch(p){e||g(-1,p)}m&&g(j,k,m,l)},!c.async||h.readyState===4?d():(i=++cc,cb&&(cd||(cd={},f(a).unload(cb)),cd[i]=d),h.onreadystatechange=d)},abort:function(){d&&d(0,1)}}}});var cg={},ch,ci,cj=/^(?:toggle|show|hide)$/,ck=/^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,cl,cm=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]],cn;f.fn.extend({show:function(a,b,c){var d,e;if(a||a===0)return this.animate(cq("show",3),a,b,c);for(var g=0,h=this.length;g<h;g++)d=this[g],d.style&&(e=d.style.display,!f._data(d,"olddisplay")&&e==="none"&&(e=d.style.display=""),e===""&&f.css(d,"display")==="none"&&f._data(d,"olddisplay",cr(d.nodeName)));for(g=0;g<h;g++){d=this[g];if(d.style){e=d.style.display;if(e===""||e==="none")d.style.display=f._data(d,"olddisplay")||""}}return this},hide:function(a,b,c){if(a||a===0)return this.animate(cq("hide",3),a,b,c);for(var d=0,e=this.length;d<e;d++)if(this[d].style){var g=f.css(this[d],"display");g!=="none"&&!f._data(this[d],"olddisplay")&&f._data(this[d],"olddisplay",g)}for(d=0;d<e;d++)this[d].style&&(this[d].style.display="none");return this},_toggle:f.fn.toggle,toggle:function(a,b,c){var d=typeof a=="boolean";f.isFunction(a)&&f.isFunction(b)?this._toggle.apply(this,arguments):a==null||d?this.each(function(){var b=d?a:f(this).is(":hidden");f(this)[b?"show":"hide"]()}):this.animate(cq("toggle",3),a,b,c);return this},fadeTo:function(a,b,c,d){return this.filter(":hidden").css("opacity",0).show().end().animate({opacity:b},a,c,d)},animate:function(a,b,c,d){var e=f.speed(b,c,d);if(f.isEmptyObject(a))return this.each(e.complete,[!1]);a=f.extend({},a);return this[e.queue===!1?"each":"queue"](function(){e.queue===!1&&f._mark(this);var b=f.extend({},e),c=this.nodeType===1,d=c&&f(this).is(":hidden"),g,h,i,j,k,l,m,n,o;b.animatedProperties={};for(i in a){g=f.camelCase(i),i!==g&&(a[g]=a[i],delete a[i]),h=a[g],f.isArray(h)?(b.animatedProperties[g]=h[1],h=a[g]=h[0]):b.animatedProperties[g]=b.specialEasing&&b.specialEasing[g]||b.easing||"swing";if(h==="hide"&&d||h==="show"&&!d)return b.complete.call(this);c&&(g==="height"||g==="width")&&(b.overflow=[this.style.overflow,this.style.overflowX,this.style.overflowY],f.css(this,"display")==="inline"&&f.css(this,"float")==="none"&&(f.support.inlineBlockNeedsLayout?(j=cr(this.nodeName),j==="inline"?this.style.display="inline-block":(this.style.display="inline",this.style.zoom=1)):this.style.display="inline-block"))}b.overflow!=null&&(this.style.overflow="hidden");for(i in a)k=new f.fx(this,b,i),h=a[i],cj.test(h)?k[h==="toggle"?d?"show":"hide":h]():(l=ck.exec(h),m=k.cur(),l?(n=parseFloat(l[2]),o=l[3]||(f.cssNumber[i]?"":"px"),o!=="px"&&(f.style(this,i,(n||1)+o),m=(n||1)/k.cur()*m,f.style(this,i,m+o)),l[1]&&(n=(l[1]==="-="?-1:1)*n+m),k.custom(m,n,o)):k.custom(m,h,""));return!0})},stop:function(a,b){a&&this.queue([]),this.each(function(){var a=f.timers,c=a.length;b||f._unmark(!0,this);while(c--)a[c].elem===this&&(b&&a[c](!0),a.splice(c,1))}),b||this.dequeue();return this}}),f.each({slideDown:cq("show",1),slideUp:cq("hide",1),slideToggle:cq("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){f.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),f.extend({speed:function(a,b,c){var d=a&&typeof a=="object"?f.extend({},a):{complete:c||!c&&b||f.isFunction(a)&&a,duration:a,easing:c&&b||b&&!f.isFunction(b)&&b};d.duration=f.fx.off?0:typeof d.duration=="number"?d.duration:d.duration in f.fx.speeds?f.fx.speeds[d.duration]:f.fx.speeds._default,d.old=d.complete,d.complete=function(a){f.isFunction(d.old)&&d.old.call(this),d.queue!==!1?f.dequeue(this):a!==!1&&f._unmark(this)};return d},easing:{linear:function(a,b,c,d){return c+d*a},swing:function(a,b,c,d){return(-Math.cos(a*Math.PI)/2+.5)*d+c}},timers:[],fx:function(a,b,c){this.options=b,this.elem=a,this.prop=c,b.orig=b.orig||{}}}),f.fx.prototype={update:function(){this.options.step&&this.options.step.call(this.elem,this.now,this),(f.fx.step[this.prop]||f.fx.step._default)(this)},cur:function(){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null))return this.elem[this.prop];var a,b=f.css(this.elem,this.prop);return isNaN(a=parseFloat(b))?!b||b==="auto"?0:b:a},custom:function(a,b,c){function g(a){return d.step(a)}var d=this,e=f.fx;this.startTime=cn||co(),this.start=a,this.end=b,this.unit=c||this.unit||(f.cssNumber[this.prop]?"":"px"),this.now=this.start,this.pos=this.state=0,g.elem=this.elem,g()&&f.timers.push(g)&&!cl&&(cl=setInterval(e.tick,e.interval))},show:function(){this.options.orig[this.prop]=f.style(this.elem,this.prop),this.options.show=!0,this.custom(this.prop==="width"||this.prop==="height"?1:0,this.cur()),f(this.elem).show()},hide:function(){this.options.orig[this.prop]=f.style(this.elem,this.prop),this.options.hide=!0,this.custom(this.cur(),0)},step:function(a){var b=cn||co(),c=!0,d=this.elem,e=this.options,g,h;if(a||b>=e.duration+this.startTime){this.now=this.end,this.pos=this.state=1,this.update(),e.animatedProperties[this.prop]=!0;for(g in e.animatedProperties)e.animatedProperties[g]!==!0&&(c=!1);if(c){e.overflow!=null&&!f.support.shrinkWrapBlocks&&f.each(["","X","Y"],function(a,b){d.style["overflow"+b]=e.overflow[a]}),e.hide&&f(d).hide();if(e.hide||e.show)for(var i in e.animatedProperties)f.style(d,i,e.orig[i]);e.complete.call(d)}return!1}e.duration==Infinity?this.now=b:(h=b-this.startTime,this.state=h/e.duration,this.pos=f.easing[e.animatedProperties[this.prop]](this.state,h,0,1,e.duration),this.now=this.start+(this.end-this.start)*this.pos),this.update();return!0}},f.extend(f.fx,{tick:function(){for(var a=f.timers,b=0;b<a.length;++b)a[b]()||a.splice(b--,1);a.length||f.fx.stop()},interval:13,stop:function(){clearInterval(cl),cl=null},speeds:{slow:600,fast:200,_default:400},step:{opacity:function(a){f.style(a.elem,"opacity",a.now)},_default:function(a){a.elem.style&&a.elem.style[a.prop]!=null?a.elem.style[a.prop]=(a.prop==="width"||a.prop==="height"?Math.max(0,a.now):a.now)+a.unit:a.elem[a.prop]=a.now}}}),f.expr&&f.expr.filters&&(f.expr.filters.animated=function(a){return f.grep(f.timers,function(b){return a===b.elem}).length});var cs=/^t(?:able|d|h)$/i,ct=/^(?:body|html)$/i;"getBoundingClientRect"in c.documentElement?f.fn.offset=function(a){var b=this[0],c;if(a)return this.each(function(b){f.offset.setOffset(this,a,b)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return f.offset.bodyOffset(b);try{c=b.getBoundingClientRect()}catch(d){}var e=b.ownerDocument,g=e.documentElement;if(!c||!f.contains(g,b))return c?{top:c.top,left:c.left}:{top:0,left:0};var h=e.body,i=cu(e),j=g.clientTop||h.clientTop||0,k=g.clientLeft||h.clientLeft||0,l=i.pageYOffset||f.support.boxModel&&g.scrollTop||h.scrollTop,m=i.pageXOffset||f.support.boxModel&&g.scrollLeft||h.scrollLeft,n=c.top+l-j,o=c.left+m-k;return{top:n,left:o}}:f.fn.offset=function(a){var b=this[0];if(a)return this.each(function(b){f.offset.setOffset(this,a,b)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return f.offset.bodyOffset(b);f.offset.initialize();var c,d=b.offsetParent,e=b,g=b.ownerDocument,h=g.documentElement,i=g.body,j=g.defaultView,k=j?j.getComputedStyle(b,null):b.currentStyle,l=b.offsetTop,m=b.offsetLeft;while((b=b.parentNode)&&b!==i&&b!==h){if(f.offset.supportsFixedPosition&&k.position==="fixed")break;c=j?j.getComputedStyle(b,null):b.currentStyle,l-=b.scrollTop,m-=b.scrollLeft,b===d&&(l+=b.offsetTop,m+=b.offsetLeft,f.offset.doesNotAddBorder&&(!f.offset.doesAddBorderForTableAndCells||!cs.test(b.nodeName))&&(l+=parseFloat(c.borderTopWidth)||0,m+=parseFloat(c.borderLeftWidth)||0),e=d,d=b.offsetParent),f.offset.subtractsBorderForOverflowNotVisible&&c.overflow!=="visible"&&(l+=parseFloat(c.borderTopWidth)||0,m+=parseFloat(c.borderLeftWidth)||0),k=c}if(k.position==="relative"||k.position==="static")l+=i.offsetTop,m+=i.offsetLeft;f.offset.supportsFixedPosition&&k.position==="fixed"&&(l+=Math.max(h.scrollTop,i.scrollTop),m+=Math.max(h.scrollLeft,i.scrollLeft));return{top:l,left:m}},f.offset={initialize:function(){var a=c.body,b=c.createElement("div"),d,e,g,h,i=parseFloat(f.css(a,"marginTop"))||0,j="<div style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;'><div></div></div><table style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;' cellpadding='0' cellspacing='0'><tr><td></td></tr></table>";f.extend(b.style,{position:"absolute",top:0,left:0,margin:0,border:0,width:"1px",height:"1px",visibility:"hidden"}),b.innerHTML=j,a.insertBefore(b,a.firstChild),d=b.firstChild,e=d.firstChild,h=d.nextSibling.firstChild.firstChild,this.doesNotAddBorder=e.offsetTop!==5,this.doesAddBorderForTableAndCells=h.offsetTop===5,e.style.position="fixed",e.style.top="20px",this.supportsFixedPosition=e.offsetTop===20||e.offsetTop===15,e.style.position=e.style.top="",d.style.overflow="hidden",d.style.position="relative",this.subtractsBorderForOverflowNotVisible=e.offsetTop===-5,this.doesNotIncludeMarginInBodyOffset=a.offsetTop!==i,a.removeChild(b),f.offset.initialize=f.noop},bodyOffset:function(a){var b=a.offsetTop,c=a.offsetLeft;f.offset.initialize(),f.offset.doesNotIncludeMarginInBodyOffset&&(b+=parseFloat(f.css(a,"marginTop"))||0,c+=parseFloat(f.css(a,"marginLeft"))||0);return{top:b,left:c}},setOffset:function(a,b,c){var d=f.css(a,"position");d==="static"&&(a.style.position="relative");var e=f(a),g=e.offset(),h=f.css(a,"top"),i=f.css(a,"left"),j=(d==="absolute"||d==="fixed")&&f.inArray("auto",[h,i])>-1,k={},l={},m,n;j?(l=e.position(),m=l.top,n=l.left):(m=parseFloat(h)||0,n=parseFloat(i)||0),f.isFunction(b)&&(b=b.call(a,c,g)),b.top!=null&&(k.top=b.top-g.top+m),b.left!=null&&(k.left=b.left-g.left+n),"using"in b?b.using.call(a,k):e.css(k)}},f.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),c=this.offset(),d=ct.test(b[0].nodeName)?{top:0,left:0}:b.offset();c.top-=parseFloat(f.css(a,"marginTop"))||0,c.left-=parseFloat(f.css(a,"marginLeft"))||0,d.top+=parseFloat(f.css(b[0],"borderTopWidth"))||0,d.left+=parseFloat(f.css(b[0],"borderLeftWidth"))||0;return{top:c.top-d.top,left:c.left-d.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||c.body;while(a&&!ct.test(a.nodeName)&&f.css(a,"position")==="static")a=a.offsetParent;return a})}}),f.each(["Left","Top"],function(a,c){var d="scroll"+c;f.fn[d]=function(c){var e,g;if(c===b){e=this[0];if(!e)return null;g=cu(e);return g?"pageXOffset"in g?g[a?"pageYOffset":"pageXOffset"]:f.support.boxModel&&g.document.documentElement[d]||g.document.body[d]:e[d]}return this.each(function(){g=cu(this),g?g.scrollTo(a?f(g).scrollLeft():c,a?c:f(g).scrollTop()):this[d]=c})}}),f.each(["Height","Width"],function(a,c){var d=c.toLowerCase();f.fn["inner"+c]=function(){var a=this[0];return a&&a.style?parseFloat(f.css(a,d,"padding")):null},f.fn["outer"+c]=function(a){var b=this[0];return b&&b.style?parseFloat(f.css(b,d,a?"margin":"border")):null},f.fn[d]=function(a){var e=this[0];if(!e)return a==null?null:this;if(f.isFunction(a))return this.each(function(b){var c=f(this);c[d](a.call(this,b,c[d]()))});if(f.isWindow(e)){var g=e.document.documentElement["client"+c],h=e.document.body;return e.document.compatMode==="CSS1Compat"&&g||h&&h["client"+c]||g}if(e.nodeType===9)return Math.max(e.documentElement["client"+c],e.body["scroll"+c],e.documentElement["scroll"+c],e.body["offset"+c],e.documentElement["offset"+c]);if(a===b){var i=f.css(e,d),j=parseFloat(i);return f.isNaN(j)?i:j}return this.css(d,typeof a=="string"?a:a+"px")}}),a.jQuery=a.$=f})(window); \ No newline at end of file
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/js/search.js b/ruby_2_2/lib/rdoc/generator/template/darkfish/js/search.js
deleted file mode 100644
index 60ac295e6c..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/js/search.js
+++ /dev/null
@@ -1,109 +0,0 @@
-Search = function(data, input, result) {
- this.data = data;
- this.$input = $(input);
- this.$result = $(result);
-
- this.$current = null;
- this.$view = this.$result.parent();
- this.searcher = new Searcher(data.index);
- this.init();
-}
-
-Search.prototype = $.extend({}, Navigation, new function() {
- var suid = 1;
-
- this.init = function() {
- var _this = this;
- var observer = function(e) {
- switch(e.originalEvent.keyCode) {
- case 38: // Event.KEY_UP
- case 40: // Event.KEY_DOWN
- return;
- }
- _this.search(_this.$input[0].value);
- };
- this.$input.keyup(observer);
- this.$input.click(observer); // mac's clear field
-
- this.searcher.ready(function(results, isLast) {
- _this.addResults(results, isLast);
- })
-
- this.initNavigation();
- this.setNavigationActive(false);
- }
-
- this.search = function(value, selectFirstMatch) {
- value = jQuery.trim(value).toLowerCase();
- if (value) {
- this.setNavigationActive(true);
- } else {
- this.setNavigationActive(false);
- }
-
- if (value == '') {
- this.lastQuery = value;
- this.$result.empty();
- this.$result.attr('aria-expanded', 'false');
- this.setNavigationActive(false);
- } else if (value != this.lastQuery) {
- this.lastQuery = value;
- this.$result.attr('aria-busy', 'true');
- this.$result.attr('aria-expanded', 'true');
- this.firstRun = true;
- this.searcher.find(value);
- }
- }
-
- this.addResults = function(results, isLast) {
- var target = this.$result.get(0);
- if (this.firstRun && (results.length > 0 || isLast)) {
- this.$current = null;
- this.$result.empty();
- }
-
- for (var i=0, l = results.length; i < l; i++) {
- var item = this.renderItem.call(this, results[i]);
- item.setAttribute('id', 'search-result-' + target.childElementCount);
- target.appendChild(item);
- };
-
- if (this.firstRun && results.length > 0) {
- this.firstRun = false;
- this.$current = $(target.firstChild);
- this.$current.addClass('search-selected');
- }
- if (jQuery.browser.msie) this.$element[0].className += '';
-
- if (isLast) this.$result.attr('aria-busy', 'false');
- }
-
- this.move = function(isDown) {
- if (!this.$current) return;
- var $next = this.$current[isDown ? 'next' : 'prev']();
- if ($next.length) {
- this.$current.removeClass('search-selected');
- $next.addClass('search-selected');
- this.$input.attr('aria-activedescendant', $next.attr('id'));
- this.scrollIntoView($next[0], this.$view[0]);
- this.$current = $next;
- this.$input.val($next[0].firstChild.firstChild.text);
- this.$input.select();
- }
- return true;
- }
-
- this.hlt = function(html) {
- return this.escapeHTML(html).
- replace(/\u0001/g, '<em>').
- replace(/\u0002/g, '</em>');
- }
-
- this.escapeHTML = function(html) {
- return html.replace(/[&<>]/g, function(c) {
- return '&#' + c.charCodeAt(0) + ';';
- });
- }
-
-});
-
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/page.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/page.rhtml
deleted file mode 100644
index 4a6b006bb3..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/page.rhtml
+++ /dev/null
@@ -1,18 +0,0 @@
-<body id="top" role="document" class="file">
-<nav role="navigation">
- <div id="project-navigation">
- <%= render '_sidebar_navigation.rhtml' %>
- <%= render '_sidebar_search.rhtml' %>
- </div>
-
- <%= render '_sidebar_table_of_contents.rhtml' %>
-
- <div id="project-metadata">
- <%= render '_sidebar_pages.rhtml' %>
- </div>
-</nav>
-
-<main role="main" aria-label="Page <%=h file.full_name%>">
-<%= file.description %>
-</main>
-
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml
deleted file mode 100644
index f0841572c3..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml
+++ /dev/null
@@ -1,18 +0,0 @@
-<body role="document">
-<nav role="navigation">
- <%= render '_sidebar_navigation.rhtml' %>
-
- <%= render '_sidebar_search.rhtml' %>
-
- <div id="project-metadata">
- <%= render '_sidebar_pages.rhtml' %>
- <%= render '_sidebar_classes.rhtml' %>
- </div>
-</nav>
-
-<main role="main">
- <h1>Not Found</h1>
-
- <p><%= message %>
-</main>
-
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/servlet_root.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/servlet_root.rhtml
deleted file mode 100644
index 3a33659aea..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/servlet_root.rhtml
+++ /dev/null
@@ -1,63 +0,0 @@
-<body role="document">
-<nav role="navigation">
- <div id="project-navigation">
- <div id="home-section" class="nav-section">
- <h2>
- <a href="<%= rel_prefix %>/" rel="home">Home</a>
- </h2>
- </div>
-
- <%= render '_sidebar_search.rhtml' %>
- </div>
-
-<%= render '_sidebar_installed.rhtml' %>
-</nav>
-
-<main role="main">
- <h1>Local RDoc Documentation</h1>
-
- <p>Here you can browse local documentation from the ruby standard library and
- your installed gems.
-
-<% extra_dirs = installed.select { |_, _, _, type,| type == :extra } %>
-<% unless extra_dirs.empty? %>
- <h2>Extra Documentation Directories</h2>
-
- <p>The following additional documentation directories are available:</p>
-
- <ol>
- <% extra_dirs.each do |name, href, exists, _, path| %>
- <li>
- <% if exists %>
- <a href="<%= href %>"><%= h name %></a> (<%= h path %>)
- <% else %>
- <%= h name %> (<%= h path %>; <i>not available</i>)
- <% end %>
- </li>
- <% end %>
- </ol>
-<% end %>
-
-<% gems = installed.select { |_, _, _, type,| type == :gem } %>
-<% missing = gems.reject { |_, _, exists,| exists } %>
-<% unless missing.empty? then %>
- <h2>Missing Gem Documentation</h2>
-
- <p>You are missing documentation for some of your installed gems.
- You can install missing documentation for gems by running
- <kbd>gem rdoc --all</kbd>. After installing the missing documentation you
- only need to reload this page. The newly created documentation will
- automatically appear.
-
- <p>You can also install documentation for a specific gem by running one of
- the following commands.
-
- <ul>
- <% names = missing.map { |name,| name.sub(/-([^-]*)$/, '') }.uniq %>
- <% names.each do |name| %>
- <li><kbd>gem rdoc <%=h name %></kbd>
- <% end %>
- </ul>
-<% end %>
-</main>
-
diff --git a/ruby_2_2/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml b/ruby_2_2/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml
deleted file mode 100644
index 7ff1a9e93e..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml
+++ /dev/null
@@ -1,58 +0,0 @@
-<body id="top" class="table-of-contents">
-<main role="main">
-<h1 class="class"><%= h @title %></h1>
-
-<% simple_files = @files.select { |f| f.text? } %>
-<% unless simple_files.empty? then %>
-<h2 id="pages">Pages</h2>
-<ul>
-<% simple_files.sort.each do |file| %>
- <li class="file">
- <a href="<%= file.path %>"><%= h file.page_name %></a>
-<%
- # HACK table_of_contents should not exist on Document
- table = file.parse(file.comment).table_of_contents
- unless table.empty? then %>
- <ul>
-<% table.each do |heading| %>
- <li><a href="<%= file.path %>#<%= heading.aref %>"><%= heading.plain_html %></a>
-<% end %>
- </ul>
-<% end %>
- </li>
- <% end %>
-</ul>
-<% end %>
-
-<h2 id="classes">Classes and Modules</h2>
-<ul>
-<% @modsort.each do |klass| %>
- <li class="<%= klass.type %>">
- <a href="<%= klass.path %>"><%= klass.full_name %></a>
-<% table = []
- table.concat klass.parse(klass.comment_location).table_of_contents
- table.concat klass.section_contents
-
- unless table.empty? then %>
- <ul>
-<% table.each do |item| %>
- <li><a href="<%= klass.path %>#<%= item.aref %>"><%= item.plain_html %></a>
-<% end %>
- </ul>
-<% end %>
- </li>
-<% end %>
-</ul>
-
-<h2 id="methods">Methods</h2>
-<ul>
-<% @store.all_classes_and_modules.map do |mod|
- mod.method_list
- end.flatten.sort.each do |method| %>
- <li class="method">
- <a href="<%= method.path %>"><%= h method.pretty_name %></a>
- &mdash;
- <span class="container"><%= method.parent.full_name %></span>
-<% end %>
-</ul>
-</main>
diff --git a/ruby_2_2/lib/rdoc/generator/template/json_index/.document b/ruby_2_2/lib/rdoc/generator/template/json_index/.document
deleted file mode 100644
index 1713b67654..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/json_index/.document
+++ /dev/null
@@ -1 +0,0 @@
-# ignore all files in this directory
diff --git a/ruby_2_2/lib/rdoc/generator/template/json_index/js/navigation.js b/ruby_2_2/lib/rdoc/generator/template/json_index/js/navigation.js
deleted file mode 100644
index e41268123e..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/json_index/js/navigation.js
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Navigation allows movement using the arrow keys through the search results.
- *
- * When using this library you will need to set scrollIntoView to the
- * appropriate function for your layout. Use scrollInWindow if the container
- * is not scrollable and scrollInElement if the container is a separate
- * scrolling region.
- */
-Navigation = new function() {
- this.initNavigation = function() {
- var _this = this;
-
- $(document).keydown(function(e) {
- _this.onkeydown(e);
- }).keyup(function(e) {
- _this.onkeyup(e);
- });
-
- this.navigationActive = true;
- }
-
- this.setNavigationActive = function(state) {
- this.navigationActive = state;
- this.clearMoveTimeout();
- }
-
- this.onkeyup = function(e) {
- if (!this.navigationActive) return;
-
- switch(e.keyCode) {
- case 37: //Event.KEY_LEFT:
- case 38: //Event.KEY_UP:
- case 39: //Event.KEY_RIGHT:
- case 40: //Event.KEY_DOWN:
- this.clearMoveTimeout();
- break;
- }
- }
-
- this.onkeydown = function(e) {
- if (!this.navigationActive) return;
- switch(e.keyCode) {
- case 37: //Event.KEY_LEFT:
- if (this.moveLeft()) e.preventDefault();
- break;
- case 38: //Event.KEY_UP:
- if (e.keyCode == 38 || e.ctrlKey) {
- if (this.moveUp()) e.preventDefault();
- this.startMoveTimeout(false);
- }
- break;
- case 39: //Event.KEY_RIGHT:
- if (this.moveRight()) e.preventDefault();
- break;
- case 40: //Event.KEY_DOWN:
- if (e.keyCode == 40 || e.ctrlKey) {
- if (this.moveDown()) e.preventDefault();
- this.startMoveTimeout(true);
- }
- break;
- case 13: //Event.KEY_RETURN:
- if (this.$current)
- e.preventDefault();
- this.select(this.$current);
- break;
- }
- if (e.ctrlKey && e.shiftKey) this.select(this.$current);
- }
-
- this.clearMoveTimeout = function() {
- clearTimeout(this.moveTimeout);
- this.moveTimeout = null;
- }
-
- this.startMoveTimeout = function(isDown) {
- if (!$.browser.mozilla && !$.browser.opera) return;
- if (this.moveTimeout) this.clearMoveTimeout();
- var _this = this;
-
- var go = function() {
- if (!_this.moveTimeout) return;
- _this[isDown ? 'moveDown' : 'moveUp']();
- _this.moveTimout = setTimeout(go, 100);
- }
- this.moveTimeout = setTimeout(go, 200);
- }
-
- this.moveRight = function() {
- }
-
- this.moveLeft = function() {
- }
-
- this.move = function(isDown) {
- }
-
- this.moveUp = function() {
- return this.move(false);
- }
-
- this.moveDown = function() {
- return this.move(true);
- }
-
- /*
- * Scrolls to the given element in the scrollable element view.
- */
- this.scrollInElement = function(element, view) {
- var offset, viewHeight, viewScroll, height;
- offset = element.offsetTop;
- height = element.offsetHeight;
- viewHeight = view.offsetHeight;
- viewScroll = view.scrollTop;
-
- if (offset - viewScroll + height > viewHeight) {
- view.scrollTop = offset - viewHeight + height;
- }
- if (offset < viewScroll) {
- view.scrollTop = offset;
- }
- }
-
- /*
- * Scrolls to the given element in the window. The second argument is
- * ignored
- */
- this.scrollInWindow = function(element, ignored) {
- var offset, viewHeight, viewScroll, height;
- offset = element.offsetTop;
- height = element.offsetHeight;
- viewHeight = window.innerHeight;
- viewScroll = window.scrollY;
-
- if (offset - viewScroll + height > viewHeight) {
- window.scrollTo(window.scrollX, offset - viewHeight + height);
- }
- if (offset < viewScroll) {
- window.scrollTo(window.scrollX, offset);
- }
- }
-}
-
diff --git a/ruby_2_2/lib/rdoc/generator/template/json_index/js/searcher.js b/ruby_2_2/lib/rdoc/generator/template/json_index/js/searcher.js
deleted file mode 100644
index f854b541d0..0000000000
--- a/ruby_2_2/lib/rdoc/generator/template/json_index/js/searcher.js
+++ /dev/null
@@ -1,228 +0,0 @@
-Searcher = function(data) {
- this.data = data;
- this.handlers = [];
-}
-
-Searcher.prototype = new function() {
- // search is performed in chunks of 1000 for non-blocking user input
- var CHUNK_SIZE = 1000;
- // do not try to find more than 100 results
- var MAX_RESULTS = 100;
- var huid = 1;
- var suid = 1;
- var runs = 0;
-
- this.find = function(query) {
- var queries = splitQuery(query);
- var regexps = buildRegexps(queries);
- var highlighters = buildHilighters(queries);
- var state = { from: 0, pass: 0, limit: MAX_RESULTS, n: suid++};
- var _this = this;
-
- this.currentSuid = state.n;
-
- if (!query) return;
-
- var run = function() {
- // stop current search thread if new search started
- if (state.n != _this.currentSuid) return;
-
- var results =
- performSearch(_this.data, regexps, queries, highlighters, state);
- var hasMore = (state.limit > 0 && state.pass < 4);
-
- triggerResults.call(_this, results, !hasMore);
- if (hasMore) {
- setTimeout(run, 2);
- }
- runs++;
- };
- runs = 0;
-
- // start search thread
- run();
- }
-
- /* ----- Events ------ */
- this.ready = function(fn) {
- fn.huid = huid;
- this.handlers.push(fn);
- }
-
- /* ----- Utilities ------ */
- function splitQuery(query) {
- return jQuery.grep(query.split(/(\s+|::?|\(\)?)/), function(string) {
- return string.match(/\S/)
- });
- }
-
- function buildRegexps(queries) {
- return jQuery.map(queries, function(query) {
- return new RegExp(query.replace(/(.)/g, '([$1])([^$1]*?)'), 'i')
- });
- }
-
- function buildHilighters(queries) {
- return jQuery.map(queries, function(query) {
- return jQuery.map(query.split(''), function(l, i) {
- return '\u0001$' + (i*2+1) + '\u0002$' + (i*2+2);
- }).join('');
- });
- }
-
- // function longMatchRegexp(index, longIndex, regexps) {
- // for (var i = regexps.length - 1; i >= 0; i--){
- // if (!index.match(regexps[i]) && !longIndex.match(regexps[i])) return false;
- // };
- // return true;
- // }
-
-
- /* ----- Mathchers ------ */
-
- /*
- * This record matches if the index starts with queries[0] and the record
- * matches all of the regexps
- */
- function matchPassBeginning(index, longIndex, queries, regexps) {
- if (index.indexOf(queries[0]) != 0) return false;
- for (var i=1, l = regexps.length; i < l; i++) {
- if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
- return false;
- };
- return true;
- }
-
- /*
- * This record matches if the longIndex starts with queries[0] and the
- * longIndex matches all of the regexps
- */
- function matchPassLongIndex(index, longIndex, queries, regexps) {
- if (longIndex.indexOf(queries[0]) != 0) return false;
- for (var i=1, l = regexps.length; i < l; i++) {
- if (!longIndex.match(regexps[i]))
- return false;
- };
- return true;
- }
-
- /*
- * This record matches if the index contains queries[0] and the record
- * matches all of the regexps
- */
- function matchPassContains(index, longIndex, queries, regexps) {
- if (index.indexOf(queries[0]) == -1) return false;
- for (var i=1, l = regexps.length; i < l; i++) {
- if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
- return false;
- };
- return true;
- }
-
- /*
- * This record matches if regexps[0] matches the index and the record
- * matches all of the regexps
- */
- function matchPassRegexp(index, longIndex, queries, regexps) {
- if (!index.match(regexps[0])) return false;
- for (var i=1, l = regexps.length; i < l; i++) {
- if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
- return false;
- };
- return true;
- }
-
-
- /* ----- Highlighters ------ */
- function highlightRegexp(info, queries, regexps, highlighters) {
- var result = createResult(info);
- for (var i=0, l = regexps.length; i < l; i++) {
- result.title = result.title.replace(regexps[i], highlighters[i]);
- result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
- };
- return result;
- }
-
- function hltSubstring(string, pos, length) {
- return string.substring(0, pos) + '\u0001' + string.substring(pos, pos + length) + '\u0002' + string.substring(pos + length);
- }
-
- function highlightQuery(info, queries, regexps, highlighters) {
- var result = createResult(info);
- var pos = 0;
- var lcTitle = result.title.toLowerCase();
-
- pos = lcTitle.indexOf(queries[0]);
- if (pos != -1) {
- result.title = hltSubstring(result.title, pos, queries[0].length);
- }
-
- result.namespace = result.namespace.replace(regexps[0], highlighters[0]);
- for (var i=1, l = regexps.length; i < l; i++) {
- result.title = result.title.replace(regexps[i], highlighters[i]);
- result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
- };
- return result;
- }
-
- function createResult(info) {
- var result = {};
- result.title = info[0];
- result.namespace = info[1];
- result.path = info[2];
- result.params = info[3];
- result.snippet = info[4];
- return result;
- }
-
- /* ----- Searching ------ */
- function performSearch(data, regexps, queries, highlighters, state) {
- var searchIndex = data.searchIndex;
- var longSearchIndex = data.longSearchIndex;
- var info = data.info;
- var result = [];
- var i = state.from;
- var l = searchIndex.length;
- var togo = CHUNK_SIZE;
- var matchFunc, hltFunc;
-
- while (state.pass < 4 && state.limit > 0 && togo > 0) {
- if (state.pass == 0) {
- matchFunc = matchPassBeginning;
- hltFunc = highlightQuery;
- } else if (state.pass == 1) {
- matchFunc = matchPassLongIndex;
- hltFunc = highlightQuery;
- } else if (state.pass == 2) {
- matchFunc = matchPassContains;
- hltFunc = highlightQuery;
- } else if (state.pass == 3) {
- matchFunc = matchPassRegexp;
- hltFunc = highlightRegexp;
- }
-
- for (; togo > 0 && i < l && state.limit > 0; i++, togo--) {
- if (info[i].n == state.n) continue;
- if (matchFunc(searchIndex[i], longSearchIndex[i], queries, regexps)) {
- info[i].n = state.n;
- result.push(hltFunc(info[i], queries, regexps, highlighters));
- state.limit--;
- }
- };
- if (searchIndex.length <= i) {
- state.pass++;
- i = state.from = 0;
- } else {
- state.from = i;
- }
- }
- return result;
- }
-
- function triggerResults(results, isLast) {
- jQuery.each(this.handlers, function(i, fn) {
- fn.call(this, results, isLast)
- })
- }
-}
-
diff --git a/ruby_2_2/lib/rdoc/ghost_method.rb b/ruby_2_2/lib/rdoc/ghost_method.rb
deleted file mode 100644
index 7eb2d93167..0000000000
--- a/ruby_2_2/lib/rdoc/ghost_method.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-##
-# GhostMethod represents a method referenced only by a comment
-
-class RDoc::GhostMethod < RDoc::AnyMethod
-end
-
diff --git a/ruby_2_2/lib/rdoc/i18n.rb b/ruby_2_2/lib/rdoc/i18n.rb
deleted file mode 100644
index 4cccbc66d3..0000000000
--- a/ruby_2_2/lib/rdoc/i18n.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-##
-# This module provides i18n realated features.
-
-module RDoc::I18n
-
- autoload :Locale, 'rdoc/i18n/locale'
- autoload :Text, 'rdoc/i18n/text'
-
-end
diff --git a/ruby_2_2/lib/rdoc/i18n/locale.rb b/ruby_2_2/lib/rdoc/i18n/locale.rb
deleted file mode 100644
index e98732e086..0000000000
--- a/ruby_2_2/lib/rdoc/i18n/locale.rb
+++ /dev/null
@@ -1,101 +0,0 @@
-##
-# A message container for a locale.
-#
-# This object provides the following two features:
-#
-# * Loads translated messages from .po file.
-# * Translates a message into the locale.
-
-class RDoc::I18n::Locale
-
- @@locales = {} # :nodoc:
-
- class << self
-
- ##
- # Returns the locale object for +locale_name+.
-
- def [](locale_name)
- @@locales[locale_name] ||= new(locale_name)
- end
-
- ##
- # Sets the locale object for +locale_name+.
- #
- # Normally, this method is not used. This method is useful for
- # testing.
-
- def []=(locale_name, locale)
- @@locales[locale_name] = locale
- end
-
- end
-
- ##
- # The name of the locale. It uses IETF language tag format
- # +[language[_territory][.codeset][@modifier]]+.
- #
- # See also {BCP 47 - Tags for Identifying
- # Languages}[http://tools.ietf.org/rfc/bcp/bcp47.txt].
-
- attr_reader :name
-
- ##
- # Creates a new locale object for +name+ locale. +name+ must
- # follow IETF language tag format.
-
- def initialize(name)
- @name = name
- @messages = {}
- end
-
- ##
- # Loads translation messages from +locale_directory+/+@name+/rdoc.po
- # or +locale_directory+/+@name+.po. The former has high priority.
- #
- # This method requires gettext gem for parsing .po file. If you
- # don't have gettext gem, this method doesn't load .po file. This
- # method warns and returns +false+.
- #
- # Returns +true+ if succeeded, +false+ otherwise.
-
- def load(locale_directory)
- return false if @name.nil?
-
- po_file_candidates = [
- File.join(locale_directory, @name, 'rdoc.po'),
- File.join(locale_directory, "#{@name}.po"),
- ]
- po_file = po_file_candidates.find do |po_file_candidate|
- File.exist?(po_file_candidate)
- end
- return false unless po_file
-
- begin
- require 'gettext/po_parser'
- require 'gettext/mo'
- rescue LoadError
- warn('Need gettext gem for i18n feature:')
- warn(' gem install gettext')
- return false
- end
-
- po_parser = GetText::POParser.new
- messages = GetText::MO.new
- po_parser.report_warning = false
- po_parser.parse_file(po_file, messages)
-
- @messages.merge!(messages)
-
- true
- end
-
- ##
- # Translates the +message+ into locale. If there is no tranlsation
- # messages for +message+ in locale, +message+ itself is returned.
-
- def translate(message)
- @messages[message] || message
- end
-
-end
diff --git a/ruby_2_2/lib/rdoc/i18n/text.rb b/ruby_2_2/lib/rdoc/i18n/text.rb
deleted file mode 100644
index ee5c66a1ff..0000000000
--- a/ruby_2_2/lib/rdoc/i18n/text.rb
+++ /dev/null
@@ -1,125 +0,0 @@
-##
-# An i18n supported text.
-#
-# This object provides the following two features:
-#
-# * Extracts translation messages from wrapped raw text.
-# * Translates wrapped raw text in specified locale.
-#
-# Wrapped raw text is one of String, RDoc::Comment or Array of them.
-
-class RDoc::I18n::Text
-
- ##
- # Creates a new i18n supported text for +raw+ text.
-
- def initialize(raw)
- @raw = raw
- end
-
- ##
- # Extracts translation target messages and yields each message.
- #
- # Each yielded message is a Hash. It consists of the followings:
- #
- # :type :: :paragraph
- # :paragraph :: String (The translation target message itself.)
- # :line_no :: Integer (The line number of the :paragraph is started.)
- #
- # The above content may be added in the future.
-
- def extract_messages
- parse do |part|
- case part[:type]
- when :empty_line
- # ignore
- when :paragraph
- yield(part)
- end
- end
- end
-
- # Translates raw text into +locale+.
- def translate(locale)
- translated_text = ''
- parse do |part|
- case part[:type]
- when :paragraph
- translated_text << locale.translate(part[:paragraph])
- when :empty_line
- translated_text << part[:line]
- else
- raise "should not reach here: unexpected type: #{type}"
- end
- end
- translated_text
- end
-
- private
- def parse(&block)
- paragraph = ''
- paragraph_start_line = 0
- line_no = 0
-
- each_line(@raw) do |line|
- line_no += 1
- case line
- when /\A\s*\z/
- if paragraph.empty?
- emit_empty_line_event(line, line_no, &block)
- else
- paragraph << line
- emit_paragraph_event(paragraph, paragraph_start_line, line_no,
- &block)
- paragraph = ''
- end
- else
- paragraph_start_line = line_no if paragraph.empty?
- paragraph << line
- end
- end
-
- unless paragraph.empty?
- emit_paragraph_event(paragraph, paragraph_start_line, line_no, &block)
- end
- end
-
- def each_line(raw, &block)
- case raw
- when RDoc::Comment
- raw.text.each_line(&block)
- when Array
- raw.each do |comment, location|
- each_line(comment, &block)
- end
- else
- raw.each_line(&block)
- end
- end
-
- def emit_empty_line_event(line, line_no)
- part = {
- :type => :empty_line,
- :line => line,
- :line_no => line_no,
- }
- yield(part)
- end
-
- def emit_paragraph_event(paragraph, paragraph_start_line, line_no, &block)
- paragraph_part = {
- :type => :paragraph,
- :line_no => paragraph_start_line,
- }
- match_data = /(\s*)\z/.match(paragraph)
- if match_data
- paragraph_part[:paragraph] = match_data.pre_match
- yield(paragraph_part)
- emit_empty_line_event(match_data[1], line_no, &block)
- else
- paragraph_part[:paragraph] = paragraph
- yield(paragraph_part)
- end
- end
-
-end
diff --git a/ruby_2_2/lib/rdoc/include.rb b/ruby_2_2/lib/rdoc/include.rb
deleted file mode 100644
index 75ed9c7bff..0000000000
--- a/ruby_2_2/lib/rdoc/include.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-##
-# A Module included in a class with \#include
-#
-# RDoc::Include.new 'Enumerable', 'comment ...'
-
-class RDoc::Include < RDoc::Mixin
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/known_classes.rb b/ruby_2_2/lib/rdoc/known_classes.rb
deleted file mode 100644
index a04068a435..0000000000
--- a/ruby_2_2/lib/rdoc/known_classes.rb
+++ /dev/null
@@ -1,72 +0,0 @@
-module RDoc
-
- ##
- # Ruby's built-in classes, modules and exceptions
-
- KNOWN_CLASSES = {
- "rb_cArray" => "Array",
- "rb_cBasicObject" => "BasicObject",
- "rb_cBignum" => "Bignum",
- "rb_cClass" => "Class",
- "rb_cData" => "Data",
- "rb_cDir" => "Dir",
- "rb_cEncoding" => "Encoding",
- "rb_cFalseClass" => "FalseClass",
- "rb_cFile" => "File",
- "rb_cFixnum" => "Fixnum",
- "rb_cFloat" => "Float",
- "rb_cHash" => "Hash",
- "rb_cIO" => "IO",
- "rb_cInteger" => "Integer",
- "rb_cModule" => "Module",
- "rb_cNilClass" => "NilClass",
- "rb_cNumeric" => "Numeric",
- "rb_cObject" => "Object",
- "rb_cProc" => "Proc",
- "rb_cRange" => "Range",
- "rb_cRegexp" => "Regexp",
- "rb_cRubyVM" => "RubyVM",
- "rb_cSocket" => "Socket",
- "rb_cString" => "String",
- "rb_cStruct" => "Struct",
- "rb_cSymbol" => "Symbol",
- "rb_cThread" => "Thread",
- "rb_cTime" => "Time",
- "rb_cTrueClass" => "TrueClass",
-
- "rb_eArgError" => "ArgError",
- "rb_eEOFError" => "EOFError",
- "rb_eException" => "Exception",
- "rb_eFatal" => "fatal",
- "rb_eFloatDomainError" => "FloatDomainError",
- "rb_eIOError" => "IOError",
- "rb_eIndexError" => "IndexError",
- "rb_eInterrupt" => "Interrupt",
- "rb_eLoadError" => "LoadError",
- "rb_eNameError" => "NameError",
- "rb_eNoMemError" => "NoMemError",
- "rb_eNotImpError" => "NotImpError",
- "rb_eRangeError" => "RangeError",
- "rb_eRuntimeError" => "RuntimeError",
- "rb_eScriptError" => "ScriptError",
- "rb_eSecurityError" => "SecurityError",
- "rb_eSignal" => "SignalException",
- "rb_eStandardError" => "StandardError",
- "rb_eSyntaxError" => "SyntaxError",
- "rb_eSystemCallError" => "SystemCallError",
- "rb_eSystemExit" => "SystemExit",
- "rb_eTypeError" => "TypeError",
- "rb_eZeroDivError" => "ZeroDivError",
-
- "rb_mComparable" => "Comparable",
- "rb_mEnumerable" => "Enumerable",
- "rb_mErrno" => "Errno",
- "rb_mFConst" => "File::Constants",
- "rb_mFileTest" => "FileTest",
- "rb_mGC" => "GC",
- "rb_mKernel" => "Kernel",
- "rb_mMath" => "Math",
- "rb_mProcess" => "Process"
- }
-
-end
diff --git a/ruby_2_2/lib/rdoc/markdown.rb b/ruby_2_2/lib/rdoc/markdown.rb
deleted file mode 100644
index 033fc2be6d..0000000000
--- a/ruby_2_2/lib/rdoc/markdown.rb
+++ /dev/null
@@ -1,16133 +0,0 @@
-# coding: UTF-8
-# :markup: markdown
-
-##
-# RDoc::Markdown as described by the [markdown syntax][syntax].
-#
-# To choose Markdown as your only default format see
-# RDoc::Options@Saved+Options for instructions on setting up a `.doc_options`
-# file to store your project default.
-#
-# ## Usage
-#
-# Here is a brief example of using this parse to read a markdown file by hand.
-#
-# data = File.read("README.md")
-# formatter = RDoc::Markup::ToHtml.new(RDoc::Options.new, nil)
-# html = RDoc::Markdown.parse(data).accept(@formatter)
-#
-# # do something with html
-#
-# ## Extensions
-#
-# The following markdown extensions are supported by the parser, but not all
-# are used in RDoc output by default.
-#
-# ### RDoc
-#
-# The RDoc Markdown parser has the following built-in behaviors that cannot be
-# disabled.
-#
-# Underscores embedded in words are never interpreted as emphasis. (While the
-# [markdown dingus][dingus] emphasizes in-word underscores, neither the
-# Markdown syntax nor MarkdownTest mention this behavior.)
-#
-# For HTML output, RDoc always auto-links bare URLs.
-#
-# ### Break on Newline
-#
-# The break_on_newline extension converts all newlines into hard line breaks
-# as in [Github Flavored Markdown][GFM]. This extension is disabled by
-# default.
-#
-# ### CSS
-#
-# The #css extension enables CSS blocks to be included in the output, but they
-# are not used for any built-in RDoc output format. This extension is disabled
-# by default.
-#
-# Example:
-#
-# <style type="text/css">
-# h1 { font-size: 3em }
-# </style>
-#
-# ### Definition Lists
-#
-# The definition_lists extension allows definition lists using the [PHP
-# Markdown Extra syntax][PHPE], but only one label and definition are supported
-# at this time. This extension is enabled by default.
-#
-# Example:
-#
-# ```
-# cat
-# : A small furry mammal
-# that seems to sleep a lot
-#
-# ant
-# : A little insect that is known
-# to enjoy picnics
-#
-# ```
-#
-# Produces:
-#
-# cat
-# : A small furry mammal
-# that seems to sleep a lot
-#
-# ant
-# : A little insect that is known
-# to enjoy picnics
-#
-# ### Github
-#
-# The #github extension enables a partial set of [Github Flavored Markdown]
-# [GFM]. This extension is enabled by default.
-#
-# Supported github extensions include:
-#
-# #### Fenced code blocks
-#
-# Use ` ``` ` around a block of code instead of indenting it four spaces.
-#
-# #### Syntax highlighting
-#
-# Use ` ``` ruby ` as the start of a code fence to add syntax highlighting.
-# (Currently only `ruby` syntax is supported).
-#
-# ### HTML
-#
-# Enables raw HTML to be included in the output. This extension is enabled by
-# default.
-#
-# Example:
-#
-# <table>
-# ...
-# </table>
-#
-# ### Notes
-#
-# The #notes extension enables footnote support. This extension is enabled by
-# default.
-#
-# Example:
-#
-# Here is some text[^1] including an inline footnote ^[for short footnotes]
-#
-# ...
-#
-# [^1]: With the footnote text down at the bottom
-#
-# Produces:
-#
-# Here is some text[^1] including an inline footnote ^[for short footnotes]
-#
-# [^1]: With the footnote text down at the bottom
-#
-# ## Limitations
-#
-# * Link titles are not used
-# * Footnotes are collapsed into a single paragraph
-#
-# ## Author
-#
-# This markdown parser is a port to kpeg from [peg-markdown][pegmarkdown] by
-# John MacFarlane.
-#
-# It is used under the MIT license:
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-#
-# The port to kpeg was performed by Eric Hodel and Evan Phoenix
-#
-# [dingus]: http://daringfireball.net/projects/markdown/dingus
-# [GFM]: http://github.github.com/github-flavored-markdown/
-# [pegmarkdown]: https://github.com/jgm/peg-markdown
-# [PHPE]: http://michelf.com/projects/php-markdown/extra/#def-list
-# [syntax]: http://daringfireball.net/projects/markdown/syntax
-#--
-# Last updated to jgm/peg-markdown commit 8f8fc22ef0
-class RDoc::Markdown
- # :stopdoc:
-
- # This is distinct from setup_parser so that a standalone parser
- # can redefine #initialize and still have access to the proper
- # parser setup code.
- def initialize(str, debug=false)
- setup_parser(str, debug)
- end
-
-
-
- # Prepares for parsing +str+. If you define a custom initialize you must
- # call this method before #parse
- def setup_parser(str, debug=false)
- set_string str, 0
- @memoizations = Hash.new { |h,k| h[k] = {} }
- @result = nil
- @failed_rule = nil
- @failing_rule_offset = -1
-
- setup_foreign_grammar
- end
-
- attr_reader :string
- attr_reader :failing_rule_offset
- attr_accessor :result, :pos
-
- def current_column(target=pos)
- if c = string.rindex("\n", target-1)
- return target - c - 1
- end
-
- target + 1
- end
-
- def current_line(target=pos)
- cur_offset = 0
- cur_line = 0
-
- string.each_line do |line|
- cur_line += 1
- cur_offset += line.size
- return cur_line if cur_offset >= target
- end
-
- -1
- end
-
- def lines
- lines = []
- string.each_line { |l| lines << l }
- lines
- end
-
-
-
- def get_text(start)
- @string[start..@pos-1]
- end
-
- # Sets the string and current parsing position for the parser.
- def set_string string, pos
- @string = string
- @string_size = string ? string.size : 0
- @pos = pos
- end
-
- def show_pos
- width = 10
- if @pos < width
- "#{@pos} (\"#{@string[0,@pos]}\" @ \"#{@string[@pos,width]}\")"
- else
- "#{@pos} (\"... #{@string[@pos - width, width]}\" @ \"#{@string[@pos,width]}\")"
- end
- end
-
- def failure_info
- l = current_line @failing_rule_offset
- c = current_column @failing_rule_offset
-
- if @failed_rule.kind_of? Symbol
- info = self.class::Rules[@failed_rule]
- "line #{l}, column #{c}: failed rule '#{info.name}' = '#{info.rendered}'"
- else
- "line #{l}, column #{c}: failed rule '#{@failed_rule}'"
- end
- end
-
- def failure_caret
- l = current_line @failing_rule_offset
- c = current_column @failing_rule_offset
-
- line = lines[l-1]
- "#{line}\n#{' ' * (c - 1)}^"
- end
-
- def failure_character
- l = current_line @failing_rule_offset
- c = current_column @failing_rule_offset
- lines[l-1][c-1, 1]
- end
-
- def failure_oneline
- l = current_line @failing_rule_offset
- c = current_column @failing_rule_offset
-
- char = lines[l-1][c-1, 1]
-
- if @failed_rule.kind_of? Symbol
- info = self.class::Rules[@failed_rule]
- "@#{l}:#{c} failed rule '#{info.name}', got '#{char}'"
- else
- "@#{l}:#{c} failed rule '#{@failed_rule}', got '#{char}'"
- end
- end
-
- class ParseError < RuntimeError
- end
-
- def raise_error
- raise ParseError, failure_oneline
- end
-
- def show_error(io=STDOUT)
- error_pos = @failing_rule_offset
- line_no = current_line(error_pos)
- col_no = current_column(error_pos)
-
- io.puts "On line #{line_no}, column #{col_no}:"
-
- if @failed_rule.kind_of? Symbol
- info = self.class::Rules[@failed_rule]
- io.puts "Failed to match '#{info.rendered}' (rule '#{info.name}')"
- else
- io.puts "Failed to match rule '#{@failed_rule}'"
- end
-
- io.puts "Got: #{string[error_pos,1].inspect}"
- line = lines[line_no-1]
- io.puts "=> #{line}"
- io.print(" " * (col_no + 3))
- io.puts "^"
- end
-
- def set_failed_rule(name)
- if @pos > @failing_rule_offset
- @failed_rule = name
- @failing_rule_offset = @pos
- end
- end
-
- attr_reader :failed_rule
-
- def match_string(str)
- len = str.size
- if @string[pos,len] == str
- @pos += len
- return str
- end
-
- return nil
- end
-
- def scan(reg)
- if m = reg.match(@string[@pos..-1])
- width = m.end(0)
- @pos += width
- return true
- end
-
- return nil
- end
-
- if "".respond_to? :ord
- def get_byte
- if @pos >= @string_size
- return nil
- end
-
- s = @string[@pos].ord
- @pos += 1
- s
- end
- else
- def get_byte
- if @pos >= @string_size
- return nil
- end
-
- s = @string[@pos]
- @pos += 1
- s
- end
- end
-
- def parse(rule=nil)
- # We invoke the rules indirectly via apply
- # instead of by just calling them as methods because
- # if the rules use left recursion, apply needs to
- # manage that.
-
- if !rule
- apply(:_root)
- else
- method = rule.gsub("-","_hyphen_")
- apply :"_#{method}"
- end
- end
-
- class MemoEntry
- def initialize(ans, pos)
- @ans = ans
- @pos = pos
- @result = nil
- @set = false
- @left_rec = false
- end
-
- attr_reader :ans, :pos, :result, :set
- attr_accessor :left_rec
-
- def move!(ans, pos, result)
- @ans = ans
- @pos = pos
- @result = result
- @set = true
- @left_rec = false
- end
- end
-
- def external_invoke(other, rule, *args)
- old_pos = @pos
- old_string = @string
-
- set_string other.string, other.pos
-
- begin
- if val = __send__(rule, *args)
- other.pos = @pos
- other.result = @result
- else
- other.set_failed_rule "#{self.class}##{rule}"
- end
- val
- ensure
- set_string old_string, old_pos
- end
- end
-
- def apply_with_args(rule, *args)
- memo_key = [rule, args]
- if m = @memoizations[memo_key][@pos]
- @pos = m.pos
- if !m.set
- m.left_rec = true
- return nil
- end
-
- @result = m.result
-
- return m.ans
- else
- m = MemoEntry.new(nil, @pos)
- @memoizations[memo_key][@pos] = m
- start_pos = @pos
-
- ans = __send__ rule, *args
-
- lr = m.left_rec
-
- m.move! ans, @pos, @result
-
- # Don't bother trying to grow the left recursion
- # if it's failing straight away (thus there is no seed)
- if ans and lr
- return grow_lr(rule, args, start_pos, m)
- else
- return ans
- end
-
- return ans
- end
- end
-
- def apply(rule)
- if m = @memoizations[rule][@pos]
- @pos = m.pos
- if !m.set
- m.left_rec = true
- return nil
- end
-
- @result = m.result
-
- return m.ans
- else
- m = MemoEntry.new(nil, @pos)
- @memoizations[rule][@pos] = m
- start_pos = @pos
-
- ans = __send__ rule
-
- lr = m.left_rec
-
- m.move! ans, @pos, @result
-
- # Don't bother trying to grow the left recursion
- # if it's failing straight away (thus there is no seed)
- if ans and lr
- return grow_lr(rule, nil, start_pos, m)
- else
- return ans
- end
-
- return ans
- end
- end
-
- def grow_lr(rule, args, start_pos, m)
- while true
- @pos = start_pos
- @result = m.result
-
- if args
- ans = __send__ rule, *args
- else
- ans = __send__ rule
- end
- return nil unless ans
-
- break if @pos <= m.pos
-
- m.move! ans, @pos, @result
- end
-
- @result = m.result
- @pos = m.pos
- return m.ans
- end
-
- class RuleInfo
- def initialize(name, rendered)
- @name = name
- @rendered = rendered
- end
-
- attr_reader :name, :rendered
- end
-
- def self.rule_info(name, rendered)
- RuleInfo.new(name, rendered)
- end
-
-
- # :startdoc:
-
-
-
- require 'rubygems'
- require 'rdoc'
- require 'rdoc/markup/to_joined_paragraph'
- require 'rdoc/markdown/entities'
-
- if RUBY_VERSION > '1.9' then
- require 'rdoc/markdown/literals_1_9'
- else
- require 'rdoc/markdown/literals_1_8'
- end
-
- ##
- # Supported extensions
-
- EXTENSIONS = []
-
- ##
- # Extensions enabled by default
-
- DEFAULT_EXTENSIONS = [
- :definition_lists,
- :github,
- :html,
- :notes,
- ]
-
- # :section: Extensions
-
- ##
- # Creates extension methods for the `name` extension to enable and disable
- # the extension and to query if they are active.
-
- def self.extension name
- EXTENSIONS << name
-
- define_method "#{name}?" do
- extension? name
- end
-
- define_method "#{name}=" do |enable|
- extension name, enable
- end
- end
-
- ##
- # Converts all newlines into hard breaks
-
- extension :break_on_newline
-
- ##
- # Allow style blocks
-
- extension :css
-
- ##
- # Allow PHP Markdown Extras style definition lists
-
- extension :definition_lists
-
- ##
- # Allow Github Flavored Markdown
-
- extension :github
-
- ##
- # Allow HTML
-
- extension :html
-
- ##
- # Enables the notes extension
-
- extension :notes
-
- # :section:
-
- ##
- # Parses the `markdown` document into an RDoc::Document using the default
- # extensions.
-
- def self.parse markdown
- parser = new
-
- parser.parse markdown
- end
-
- # TODO remove when kpeg 0.10 is released
- alias orig_initialize initialize # :nodoc:
-
- ##
- # Creates a new markdown parser that enables the given +extensions+.
-
- def initialize extensions = DEFAULT_EXTENSIONS, debug = false
- @debug = debug
- @formatter = RDoc::Markup::ToJoinedParagraph.new
- @extensions = extensions
-
- @references = nil
- @unlinked_references = nil
-
- @footnotes = nil
- @note_order = nil
- end
-
- ##
- # Wraps `text` in emphasis for rdoc inline formatting
-
- def emphasis text
- if text =~ /\A[a-z\d.\/]+\z/i then
- "_#{text}_"
- else
- "<em>#{text}</em>"
- end
- end
-
- ##
- # :category: Extensions
- #
- # Is the extension `name` enabled?
-
- def extension? name
- @extensions.include? name
- end
-
- ##
- # :category: Extensions
- #
- # Enables or disables the extension with `name`
-
- def extension name, enable
- if enable then
- @extensions |= [name]
- else
- @extensions -= [name]
- end
- end
-
- ##
- # Parses `text` in a clone of this parser. This is used for handling nested
- # lists the same way as markdown_parser.
-
- def inner_parse text # :nodoc:
- parser = clone
-
- parser.setup_parser text, @debug
-
- parser.peg_parse
-
- doc = parser.result
-
- doc.accept @formatter
-
- doc.parts
- end
-
- ##
- # Finds a link reference for `label` and creates a new link to it with
- # `content` as the link text. If `label` was not encountered in the
- # reference-gathering parser pass the label and content are reconstructed
- # with the linking `text` (usually whitespace).
-
- def link_to content, label = content, text = nil
- raise 'enable notes extension' if
- content.start_with? '^' and label.equal? content
-
- if ref = @references[label] then
- "{#{content}}[#{ref}]"
- elsif label.equal? content then
- "[#{content}]#{text}"
- else
- "[#{content}]#{text}[#{label}]"
- end
- end
-
- ##
- # Creates an RDoc::Markup::ListItem by parsing the `unparsed` content from
- # the first parsing pass.
-
- def list_item_from unparsed
- parsed = inner_parse unparsed.join
- RDoc::Markup::ListItem.new nil, *parsed
- end
-
- ##
- # Stores `label` as a note and fills in previously unknown note references.
-
- def note label
- #foottext = "rdoc-label:foottext-#{label}:footmark-#{label}"
-
- #ref.replace foottext if ref = @unlinked_notes.delete(label)
-
- @notes[label] = foottext
-
- #"{^1}[rdoc-label:footmark-#{label}:foottext-#{label}] "
- end
-
- ##
- # Creates a new link for the footnote `reference` and adds the reference to
- # the note order list for proper display at the end of the document.
-
- def note_for ref
- @note_order << ref
-
- label = @note_order.length
-
- "{*#{label}}[rdoc-label:foottext-#{label}:footmark-#{label}]"
- end
-
- ##
- # The internal kpeg parse method
-
- alias peg_parse parse # :nodoc:
-
- ##
- # Creates an RDoc::Markup::Paragraph from `parts` and including
- # extension-specific behavior
-
- def paragraph parts
- parts = parts.map do |part|
- if "\n" == part then
- RDoc::Markup::HardBreak.new
- else
- part
- end
- end if break_on_newline?
-
- RDoc::Markup::Paragraph.new(*parts)
- end
-
- ##
- # Parses `markdown` into an RDoc::Document
-
- def parse markdown
- @references = {}
- @unlinked_references = {}
-
- markdown += "\n\n"
-
- setup_parser markdown, @debug
- peg_parse 'References'
-
- if notes? then
- @footnotes = {}
-
- setup_parser markdown, @debug
- peg_parse 'Notes'
-
- # using note_order on the first pass would be a bug
- @note_order = []
- end
-
- setup_parser markdown, @debug
- peg_parse
-
- doc = result
-
- if notes? and not @footnotes.empty? then
- doc << RDoc::Markup::Rule.new(1)
-
- @note_order.each_with_index do |ref, index|
- label = index + 1
- note = @footnotes[ref]
-
- link = "{^#{label}}[rdoc-label:footmark-#{label}:foottext-#{label}] "
- note.parts.unshift link
-
- doc << note
- end
- end
-
- doc.accept @formatter
-
- doc
- end
-
- ##
- # Stores `label` as a reference to `link` and fills in previously unknown
- # link references.
-
- def reference label, link
- if ref = @unlinked_references.delete(label) then
- ref.replace link
- end
-
- @references[label] = link
- end
-
- ##
- # Wraps `text` in strong markup for rdoc inline formatting
-
- def strong text
- if text =~ /\A[a-z\d.\/-]+\z/i then
- "*#{text}*"
- else
- "<b>#{text}</b>"
- end
- end
-
-
- # :stopdoc:
- def setup_foreign_grammar
- @_grammar_literals = RDoc::Markdown::Literals.new(nil)
- end
-
- # root = Doc
- def _root
- _tmp = apply(:_Doc)
- set_failed_rule :_root unless _tmp
- return _tmp
- end
-
- # Doc = BOM? Block*:a { RDoc::Markup::Document.new(*a.compact) }
- def _Doc
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = apply(:_BOM)
- unless _tmp
- _tmp = true
- self.pos = _save1
- end
- unless _tmp
- self.pos = _save
- break
- end
- _ary = []
- while true
- _tmp = apply(:_Block)
- _ary << @result if _tmp
- break unless _tmp
- end
- _tmp = true
- @result = _ary
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; RDoc::Markup::Document.new(*a.compact) ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Doc unless _tmp
- return _tmp
- end
-
- # Block = @BlankLine* (BlockQuote | Verbatim | CodeFence | Note | Reference | HorizontalRule | Heading | OrderedList | BulletList | DefinitionList | HtmlBlock | StyleBlock | Para | Plain)
- def _Block
-
- _save = self.pos
- while true # sequence
- while true
- _tmp = _BlankLine()
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_BlockQuote)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_Verbatim)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_CodeFence)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_Note)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_Reference)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_HorizontalRule)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_Heading)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_OrderedList)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_BulletList)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_DefinitionList)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_HtmlBlock)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_StyleBlock)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_Para)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_Plain)
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Block unless _tmp
- return _tmp
- end
-
- # Para = @NonindentSpace Inlines:a @BlankLine+ { paragraph a }
- def _Para
-
- _save = self.pos
- while true # sequence
- _tmp = _NonindentSpace()
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Inlines)
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
- _tmp = _BlankLine()
- if _tmp
- while true
- _tmp = _BlankLine()
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save1
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; paragraph a ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Para unless _tmp
- return _tmp
- end
-
- # Plain = Inlines:a { paragraph a }
- def _Plain
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_Inlines)
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; paragraph a ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Plain unless _tmp
- return _tmp
- end
-
- # AtxInline = !@Newline !(@Sp? /#*/ @Sp @Newline) Inline
- def _AtxInline
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = _Newline()
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = _Sp()
- unless _tmp
- _tmp = true
- self.pos = _save4
- end
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = scan(/\A(?-mix:#*)/)
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = _Newline()
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- _tmp = _tmp ? nil : true
- self.pos = _save2
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Inline)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_AtxInline unless _tmp
- return _tmp
- end
-
- # AtxStart = < /\#{1,6}/ > { text.length }
- def _AtxStart
-
- _save = self.pos
- while true # sequence
- _text_start = self.pos
- _tmp = scan(/\A(?-mix:\#{1,6})/)
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; text.length ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_AtxStart unless _tmp
- return _tmp
- end
-
- # AtxHeading = AtxStart:s @Sp? AtxInline+:a (@Sp? /#*/ @Sp)? @Newline { RDoc::Markup::Heading.new(s, a.join) }
- def _AtxHeading
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_AtxStart)
- s = @result
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
- _tmp = _Sp()
- unless _tmp
- _tmp = true
- self.pos = _save1
- end
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _ary = []
- _tmp = apply(:_AtxInline)
- if _tmp
- _ary << @result
- while true
- _tmp = apply(:_AtxInline)
- _ary << @result if _tmp
- break unless _tmp
- end
- _tmp = true
- @result = _ary
- else
- self.pos = _save2
- end
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _save3 = self.pos
-
- _save4 = self.pos
- while true # sequence
- _save5 = self.pos
- _tmp = _Sp()
- unless _tmp
- _tmp = true
- self.pos = _save5
- end
- unless _tmp
- self.pos = _save4
- break
- end
- _tmp = scan(/\A(?-mix:#*)/)
- unless _tmp
- self.pos = _save4
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save4
- end
- break
- end # end sequence
-
- unless _tmp
- _tmp = true
- self.pos = _save3
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _Newline()
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; RDoc::Markup::Heading.new(s, a.join) ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_AtxHeading unless _tmp
- return _tmp
- end
-
- # SetextHeading = (SetextHeading1 | SetextHeading2)
- def _SetextHeading
-
- _save = self.pos
- while true # choice
- _tmp = apply(:_SetextHeading1)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_SetextHeading2)
- break if _tmp
- self.pos = _save
- break
- end # end choice
-
- set_failed_rule :_SetextHeading unless _tmp
- return _tmp
- end
-
- # SetextBottom1 = /={3,}/ @Newline
- def _SetextBottom1
-
- _save = self.pos
- while true # sequence
- _tmp = scan(/\A(?-mix:={3,})/)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _Newline()
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_SetextBottom1 unless _tmp
- return _tmp
- end
-
- # SetextBottom2 = /-{3,}/ @Newline
- def _SetextBottom2
-
- _save = self.pos
- while true # sequence
- _tmp = scan(/\A(?-mix:-{3,})/)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _Newline()
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_SetextBottom2 unless _tmp
- return _tmp
- end
-
- # SetextHeading1 = &(@RawLine SetextBottom1) @StartList:a (!@Endline Inline:b { a << b })+ @Sp? @Newline SetextBottom1 { RDoc::Markup::Heading.new(1, a.join) }
- def _SetextHeading1
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
-
- _save2 = self.pos
- while true # sequence
- _tmp = _RawLine()
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = apply(:_SetextBottom1)
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _StartList()
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _save3 = self.pos
-
- _save4 = self.pos
- while true # sequence
- _save5 = self.pos
- _tmp = _Endline()
- _tmp = _tmp ? nil : true
- self.pos = _save5
- unless _tmp
- self.pos = _save4
- break
- end
- _tmp = apply(:_Inline)
- b = @result
- unless _tmp
- self.pos = _save4
- break
- end
- @result = begin; a << b ; end
- _tmp = true
- unless _tmp
- self.pos = _save4
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save6 = self.pos
- while true # sequence
- _save7 = self.pos
- _tmp = _Endline()
- _tmp = _tmp ? nil : true
- self.pos = _save7
- unless _tmp
- self.pos = _save6
- break
- end
- _tmp = apply(:_Inline)
- b = @result
- unless _tmp
- self.pos = _save6
- break
- end
- @result = begin; a << b ; end
- _tmp = true
- unless _tmp
- self.pos = _save6
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save3
- end
- unless _tmp
- self.pos = _save
- break
- end
- _save8 = self.pos
- _tmp = _Sp()
- unless _tmp
- _tmp = true
- self.pos = _save8
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _Newline()
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_SetextBottom1)
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; RDoc::Markup::Heading.new(1, a.join) ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_SetextHeading1 unless _tmp
- return _tmp
- end
-
- # SetextHeading2 = &(@RawLine SetextBottom2) @StartList:a (!@Endline Inline:b { a << b })+ @Sp? @Newline SetextBottom2 { RDoc::Markup::Heading.new(2, a.join) }
- def _SetextHeading2
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
-
- _save2 = self.pos
- while true # sequence
- _tmp = _RawLine()
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = apply(:_SetextBottom2)
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _StartList()
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _save3 = self.pos
-
- _save4 = self.pos
- while true # sequence
- _save5 = self.pos
- _tmp = _Endline()
- _tmp = _tmp ? nil : true
- self.pos = _save5
- unless _tmp
- self.pos = _save4
- break
- end
- _tmp = apply(:_Inline)
- b = @result
- unless _tmp
- self.pos = _save4
- break
- end
- @result = begin; a << b ; end
- _tmp = true
- unless _tmp
- self.pos = _save4
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save6 = self.pos
- while true # sequence
- _save7 = self.pos
- _tmp = _Endline()
- _tmp = _tmp ? nil : true
- self.pos = _save7
- unless _tmp
- self.pos = _save6
- break
- end
- _tmp = apply(:_Inline)
- b = @result
- unless _tmp
- self.pos = _save6
- break
- end
- @result = begin; a << b ; end
- _tmp = true
- unless _tmp
- self.pos = _save6
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save3
- end
- unless _tmp
- self.pos = _save
- break
- end
- _save8 = self.pos
- _tmp = _Sp()
- unless _tmp
- _tmp = true
- self.pos = _save8
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _Newline()
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_SetextBottom2)
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; RDoc::Markup::Heading.new(2, a.join) ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_SetextHeading2 unless _tmp
- return _tmp
- end
-
- # Heading = (SetextHeading | AtxHeading)
- def _Heading
-
- _save = self.pos
- while true # choice
- _tmp = apply(:_SetextHeading)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_AtxHeading)
- break if _tmp
- self.pos = _save
- break
- end # end choice
-
- set_failed_rule :_Heading unless _tmp
- return _tmp
- end
-
- # BlockQuote = BlockQuoteRaw:a { RDoc::Markup::BlockQuote.new(*a) }
- def _BlockQuote
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_BlockQuoteRaw)
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; RDoc::Markup::BlockQuote.new(*a) ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_BlockQuote unless _tmp
- return _tmp
- end
-
- # BlockQuoteRaw = @StartList:a (">" " "? Line:l { a << l } (!">" !@BlankLine Line:c { a << c })* (@BlankLine:n { a << n })*)+ { inner_parse a.join }
- def _BlockQuoteRaw
-
- _save = self.pos
- while true # sequence
- _tmp = _StartList()
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
-
- _save2 = self.pos
- while true # sequence
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save2
- break
- end
- _save3 = self.pos
- _tmp = match_string(" ")
- unless _tmp
- _tmp = true
- self.pos = _save3
- end
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = apply(:_Line)
- l = @result
- unless _tmp
- self.pos = _save2
- break
- end
- @result = begin; a << l ; end
- _tmp = true
- unless _tmp
- self.pos = _save2
- break
- end
- while true
-
- _save5 = self.pos
- while true # sequence
- _save6 = self.pos
- _tmp = match_string(">")
- _tmp = _tmp ? nil : true
- self.pos = _save6
- unless _tmp
- self.pos = _save5
- break
- end
- _save7 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save7
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = apply(:_Line)
- c = @result
- unless _tmp
- self.pos = _save5
- break
- end
- @result = begin; a << c ; end
- _tmp = true
- unless _tmp
- self.pos = _save5
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save2
- break
- end
- while true
-
- _save9 = self.pos
- while true # sequence
- _tmp = _BlankLine()
- n = @result
- unless _tmp
- self.pos = _save9
- break
- end
- @result = begin; a << n ; end
- _tmp = true
- unless _tmp
- self.pos = _save9
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save10 = self.pos
- while true # sequence
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save10
- break
- end
- _save11 = self.pos
- _tmp = match_string(" ")
- unless _tmp
- _tmp = true
- self.pos = _save11
- end
- unless _tmp
- self.pos = _save10
- break
- end
- _tmp = apply(:_Line)
- l = @result
- unless _tmp
- self.pos = _save10
- break
- end
- @result = begin; a << l ; end
- _tmp = true
- unless _tmp
- self.pos = _save10
- break
- end
- while true
-
- _save13 = self.pos
- while true # sequence
- _save14 = self.pos
- _tmp = match_string(">")
- _tmp = _tmp ? nil : true
- self.pos = _save14
- unless _tmp
- self.pos = _save13
- break
- end
- _save15 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save15
- unless _tmp
- self.pos = _save13
- break
- end
- _tmp = apply(:_Line)
- c = @result
- unless _tmp
- self.pos = _save13
- break
- end
- @result = begin; a << c ; end
- _tmp = true
- unless _tmp
- self.pos = _save13
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save10
- break
- end
- while true
-
- _save17 = self.pos
- while true # sequence
- _tmp = _BlankLine()
- n = @result
- unless _tmp
- self.pos = _save17
- break
- end
- @result = begin; a << n ; end
- _tmp = true
- unless _tmp
- self.pos = _save17
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save10
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save1
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; inner_parse a.join ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_BlockQuoteRaw unless _tmp
- return _tmp
- end
-
- # NonblankIndentedLine = !@BlankLine IndentedLine
- def _NonblankIndentedLine
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_IndentedLine)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_NonblankIndentedLine unless _tmp
- return _tmp
- end
-
- # VerbatimChunk = @BlankLine*:a NonblankIndentedLine+:b { a.concat b }
- def _VerbatimChunk
-
- _save = self.pos
- while true # sequence
- _ary = []
- while true
- _tmp = _BlankLine()
- _ary << @result if _tmp
- break unless _tmp
- end
- _tmp = true
- @result = _ary
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _ary = []
- _tmp = apply(:_NonblankIndentedLine)
- if _tmp
- _ary << @result
- while true
- _tmp = apply(:_NonblankIndentedLine)
- _ary << @result if _tmp
- break unless _tmp
- end
- _tmp = true
- @result = _ary
- else
- self.pos = _save2
- end
- b = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a.concat b ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_VerbatimChunk unless _tmp
- return _tmp
- end
-
- # Verbatim = VerbatimChunk+:a { RDoc::Markup::Verbatim.new(*a.flatten) }
- def _Verbatim
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _ary = []
- _tmp = apply(:_VerbatimChunk)
- if _tmp
- _ary << @result
- while true
- _tmp = apply(:_VerbatimChunk)
- _ary << @result if _tmp
- break unless _tmp
- end
- _tmp = true
- @result = _ary
- else
- self.pos = _save1
- end
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; RDoc::Markup::Verbatim.new(*a.flatten) ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Verbatim unless _tmp
- return _tmp
- end
-
- # HorizontalRule = @NonindentSpace ("*" @Sp "*" @Sp "*" (@Sp "*")* | "-" @Sp "-" @Sp "-" (@Sp "-")* | "_" @Sp "_" @Sp "_" (@Sp "_")*) @Sp @Newline @BlankLine+ { RDoc::Markup::Rule.new 1 }
- def _HorizontalRule
-
- _save = self.pos
- while true # sequence
- _tmp = _NonindentSpace()
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
-
- _save2 = self.pos
- while true # sequence
- _tmp = match_string("*")
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = match_string("*")
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = match_string("*")
- unless _tmp
- self.pos = _save2
- break
- end
- while true
-
- _save4 = self.pos
- while true # sequence
- _tmp = _Sp()
- unless _tmp
- self.pos = _save4
- break
- end
- _tmp = match_string("*")
- unless _tmp
- self.pos = _save4
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save1
-
- _save5 = self.pos
- while true # sequence
- _tmp = match_string("-")
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = match_string("-")
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = match_string("-")
- unless _tmp
- self.pos = _save5
- break
- end
- while true
-
- _save7 = self.pos
- while true # sequence
- _tmp = _Sp()
- unless _tmp
- self.pos = _save7
- break
- end
- _tmp = match_string("-")
- unless _tmp
- self.pos = _save7
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save5
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save1
-
- _save8 = self.pos
- while true # sequence
- _tmp = match_string("_")
- unless _tmp
- self.pos = _save8
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save8
- break
- end
- _tmp = match_string("_")
- unless _tmp
- self.pos = _save8
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save8
- break
- end
- _tmp = match_string("_")
- unless _tmp
- self.pos = _save8
- break
- end
- while true
-
- _save10 = self.pos
- while true # sequence
- _tmp = _Sp()
- unless _tmp
- self.pos = _save10
- break
- end
- _tmp = match_string("_")
- unless _tmp
- self.pos = _save10
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save8
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _Newline()
- unless _tmp
- self.pos = _save
- break
- end
- _save11 = self.pos
- _tmp = _BlankLine()
- if _tmp
- while true
- _tmp = _BlankLine()
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save11
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; RDoc::Markup::Rule.new 1 ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HorizontalRule unless _tmp
- return _tmp
- end
-
- # Bullet = !HorizontalRule @NonindentSpace /[+*-]/ @Spacechar+
- def _Bullet
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = apply(:_HorizontalRule)
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _NonindentSpace()
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = scan(/\A(?-mix:[+*-])/)
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _tmp = _Spacechar()
- if _tmp
- while true
- _tmp = _Spacechar()
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save2
- end
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Bullet unless _tmp
- return _tmp
- end
-
- # BulletList = &Bullet (ListTight | ListLoose):a { RDoc::Markup::List.new(:BULLET, *a) }
- def _BulletList
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = apply(:_Bullet)
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_ListTight)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_ListLoose)
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; RDoc::Markup::List.new(:BULLET, *a) ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_BulletList unless _tmp
- return _tmp
- end
-
- # ListTight = ListItemTight+:a @BlankLine* !(Bullet | Enumerator) { a }
- def _ListTight
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _ary = []
- _tmp = apply(:_ListItemTight)
- if _tmp
- _ary << @result
- while true
- _tmp = apply(:_ListItemTight)
- _ary << @result if _tmp
- break unless _tmp
- end
- _tmp = true
- @result = _ary
- else
- self.pos = _save1
- end
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = _BlankLine()
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _save3 = self.pos
-
- _save4 = self.pos
- while true # choice
- _tmp = apply(:_Bullet)
- break if _tmp
- self.pos = _save4
- _tmp = apply(:_Enumerator)
- break if _tmp
- self.pos = _save4
- break
- end # end choice
-
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_ListTight unless _tmp
- return _tmp
- end
-
- # ListLoose = @StartList:a (ListItem:b @BlankLine* { a << b })+ { a }
- def _ListLoose
-
- _save = self.pos
- while true # sequence
- _tmp = _StartList()
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
-
- _save2 = self.pos
- while true # sequence
- _tmp = apply(:_ListItem)
- b = @result
- unless _tmp
- self.pos = _save2
- break
- end
- while true
- _tmp = _BlankLine()
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save2
- break
- end
- @result = begin; a << b ; end
- _tmp = true
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save4 = self.pos
- while true # sequence
- _tmp = apply(:_ListItem)
- b = @result
- unless _tmp
- self.pos = _save4
- break
- end
- while true
- _tmp = _BlankLine()
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save4
- break
- end
- @result = begin; a << b ; end
- _tmp = true
- unless _tmp
- self.pos = _save4
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save1
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_ListLoose unless _tmp
- return _tmp
- end
-
- # ListItem = (Bullet | Enumerator) @StartList:a ListBlock:b { a << b } (ListContinuationBlock:c { a.push(*c) })* { list_item_from a }
- def _ListItem
-
- _save = self.pos
- while true # sequence
-
- _save1 = self.pos
- while true # choice
- _tmp = apply(:_Bullet)
- break if _tmp
- self.pos = _save1
- _tmp = apply(:_Enumerator)
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _StartList()
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_ListBlock)
- b = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a << b ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save3 = self.pos
- while true # sequence
- _tmp = apply(:_ListContinuationBlock)
- c = @result
- unless _tmp
- self.pos = _save3
- break
- end
- @result = begin; a.push(*c) ; end
- _tmp = true
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; list_item_from a ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_ListItem unless _tmp
- return _tmp
- end
-
- # ListItemTight = (Bullet | Enumerator) ListBlock:a (!@BlankLine ListContinuationBlock:b { a.push(*b) })* !ListContinuationBlock { list_item_from a }
- def _ListItemTight
-
- _save = self.pos
- while true # sequence
-
- _save1 = self.pos
- while true # choice
- _tmp = apply(:_Bullet)
- break if _tmp
- self.pos = _save1
- _tmp = apply(:_Enumerator)
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_ListBlock)
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = apply(:_ListContinuationBlock)
- b = @result
- unless _tmp
- self.pos = _save3
- break
- end
- @result = begin; a.push(*b) ; end
- _tmp = true
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _save5 = self.pos
- _tmp = apply(:_ListContinuationBlock)
- _tmp = _tmp ? nil : true
- self.pos = _save5
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; list_item_from a ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_ListItemTight unless _tmp
- return _tmp
- end
-
- # ListBlock = !@BlankLine Line:a ListBlockLine*:c { [a, *c] }
- def _ListBlock
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Line)
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _ary = []
- while true
- _tmp = apply(:_ListBlockLine)
- _ary << @result if _tmp
- break unless _tmp
- end
- _tmp = true
- @result = _ary
- c = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; [a, *c] ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_ListBlock unless _tmp
- return _tmp
- end
-
- # ListContinuationBlock = @StartList:a @BlankLine* { a << "\n" } (Indent ListBlock:b { a.concat b })+ { a }
- def _ListContinuationBlock
-
- _save = self.pos
- while true # sequence
- _tmp = _StartList()
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = _BlankLine()
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a << "\n" ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
-
- _save3 = self.pos
- while true # sequence
- _tmp = apply(:_Indent)
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = apply(:_ListBlock)
- b = @result
- unless _tmp
- self.pos = _save3
- break
- end
- @result = begin; a.concat b ; end
- _tmp = true
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save4 = self.pos
- while true # sequence
- _tmp = apply(:_Indent)
- unless _tmp
- self.pos = _save4
- break
- end
- _tmp = apply(:_ListBlock)
- b = @result
- unless _tmp
- self.pos = _save4
- break
- end
- @result = begin; a.concat b ; end
- _tmp = true
- unless _tmp
- self.pos = _save4
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save2
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_ListContinuationBlock unless _tmp
- return _tmp
- end
-
- # Enumerator = @NonindentSpace [0-9]+ "." @Spacechar+
- def _Enumerator
-
- _save = self.pos
- while true # sequence
- _tmp = _NonindentSpace()
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
- _save2 = self.pos
- _tmp = get_byte
- if _tmp
- unless _tmp >= 48 and _tmp <= 57
- self.pos = _save2
- _tmp = nil
- end
- end
- if _tmp
- while true
- _save3 = self.pos
- _tmp = get_byte
- if _tmp
- unless _tmp >= 48 and _tmp <= 57
- self.pos = _save3
- _tmp = nil
- end
- end
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save1
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(".")
- unless _tmp
- self.pos = _save
- break
- end
- _save4 = self.pos
- _tmp = _Spacechar()
- if _tmp
- while true
- _tmp = _Spacechar()
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save4
- end
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Enumerator unless _tmp
- return _tmp
- end
-
- # OrderedList = &Enumerator (ListTight | ListLoose):a { RDoc::Markup::List.new(:NUMBER, *a) }
- def _OrderedList
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = apply(:_Enumerator)
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_ListTight)
- break if _tmp
- self.pos = _save2
- _tmp = apply(:_ListLoose)
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; RDoc::Markup::List.new(:NUMBER, *a) ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_OrderedList unless _tmp
- return _tmp
- end
-
- # ListBlockLine = !@BlankLine !(Indent? (Bullet | Enumerator)) !HorizontalRule OptionallyIndentedLine
- def _ListBlockLine
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_Indent)
- unless _tmp
- _tmp = true
- self.pos = _save4
- end
- unless _tmp
- self.pos = _save3
- break
- end
-
- _save5 = self.pos
- while true # choice
- _tmp = apply(:_Bullet)
- break if _tmp
- self.pos = _save5
- _tmp = apply(:_Enumerator)
- break if _tmp
- self.pos = _save5
- break
- end # end choice
-
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- _tmp = _tmp ? nil : true
- self.pos = _save2
- unless _tmp
- self.pos = _save
- break
- end
- _save6 = self.pos
- _tmp = apply(:_HorizontalRule)
- _tmp = _tmp ? nil : true
- self.pos = _save6
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_OptionallyIndentedLine)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_ListBlockLine unless _tmp
- return _tmp
- end
-
- # HtmlOpenAnchor = "<" Spnl ("a" | "A") Spnl HtmlAttribute* ">"
- def _HtmlOpenAnchor
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("a")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("A")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlOpenAnchor unless _tmp
- return _tmp
- end
-
- # HtmlCloseAnchor = "<" Spnl "/" ("a" | "A") Spnl ">"
- def _HtmlCloseAnchor
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("a")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("A")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlCloseAnchor unless _tmp
- return _tmp
- end
-
- # HtmlAnchor = HtmlOpenAnchor (HtmlAnchor | !HtmlCloseAnchor .)* HtmlCloseAnchor
- def _HtmlAnchor
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlOpenAnchor)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlAnchor)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlCloseAnchor)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlCloseAnchor)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlAnchor unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenAddress = "<" Spnl ("address" | "ADDRESS") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenAddress
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("address")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("ADDRESS")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenAddress unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseAddress = "<" Spnl "/" ("address" | "ADDRESS") Spnl ">"
- def _HtmlBlockCloseAddress
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("address")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("ADDRESS")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseAddress unless _tmp
- return _tmp
- end
-
- # HtmlBlockAddress = HtmlBlockOpenAddress (HtmlBlockAddress | !HtmlBlockCloseAddress .)* HtmlBlockCloseAddress
- def _HtmlBlockAddress
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenAddress)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockAddress)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseAddress)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseAddress)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockAddress unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenBlockquote = "<" Spnl ("blockquote" | "BLOCKQUOTE") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenBlockquote
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("blockquote")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("BLOCKQUOTE")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenBlockquote unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseBlockquote = "<" Spnl "/" ("blockquote" | "BLOCKQUOTE") Spnl ">"
- def _HtmlBlockCloseBlockquote
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("blockquote")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("BLOCKQUOTE")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseBlockquote unless _tmp
- return _tmp
- end
-
- # HtmlBlockBlockquote = HtmlBlockOpenBlockquote (HtmlBlockBlockquote | !HtmlBlockCloseBlockquote .)* HtmlBlockCloseBlockquote
- def _HtmlBlockBlockquote
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenBlockquote)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockBlockquote)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseBlockquote)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseBlockquote)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockBlockquote unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenCenter = "<" Spnl ("center" | "CENTER") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenCenter
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("center")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("CENTER")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenCenter unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseCenter = "<" Spnl "/" ("center" | "CENTER") Spnl ">"
- def _HtmlBlockCloseCenter
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("center")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("CENTER")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseCenter unless _tmp
- return _tmp
- end
-
- # HtmlBlockCenter = HtmlBlockOpenCenter (HtmlBlockCenter | !HtmlBlockCloseCenter .)* HtmlBlockCloseCenter
- def _HtmlBlockCenter
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenCenter)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockCenter)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseCenter)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseCenter)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCenter unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenDir = "<" Spnl ("dir" | "DIR") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenDir
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("dir")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("DIR")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenDir unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseDir = "<" Spnl "/" ("dir" | "DIR") Spnl ">"
- def _HtmlBlockCloseDir
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("dir")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("DIR")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseDir unless _tmp
- return _tmp
- end
-
- # HtmlBlockDir = HtmlBlockOpenDir (HtmlBlockDir | !HtmlBlockCloseDir .)* HtmlBlockCloseDir
- def _HtmlBlockDir
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenDir)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockDir)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseDir)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseDir)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockDir unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenDiv = "<" Spnl ("div" | "DIV") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenDiv
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("div")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("DIV")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenDiv unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseDiv = "<" Spnl "/" ("div" | "DIV") Spnl ">"
- def _HtmlBlockCloseDiv
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("div")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("DIV")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseDiv unless _tmp
- return _tmp
- end
-
- # HtmlBlockDiv = HtmlBlockOpenDiv (HtmlBlockDiv | !HtmlBlockCloseDiv .)* HtmlBlockCloseDiv
- def _HtmlBlockDiv
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenDiv)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockDiv)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseDiv)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseDiv)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockDiv unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenDl = "<" Spnl ("dl" | "DL") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenDl
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("dl")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("DL")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenDl unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseDl = "<" Spnl "/" ("dl" | "DL") Spnl ">"
- def _HtmlBlockCloseDl
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("dl")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("DL")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseDl unless _tmp
- return _tmp
- end
-
- # HtmlBlockDl = HtmlBlockOpenDl (HtmlBlockDl | !HtmlBlockCloseDl .)* HtmlBlockCloseDl
- def _HtmlBlockDl
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenDl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockDl)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseDl)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseDl)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockDl unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenFieldset = "<" Spnl ("fieldset" | "FIELDSET") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenFieldset
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("fieldset")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("FIELDSET")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenFieldset unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseFieldset = "<" Spnl "/" ("fieldset" | "FIELDSET") Spnl ">"
- def _HtmlBlockCloseFieldset
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("fieldset")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("FIELDSET")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseFieldset unless _tmp
- return _tmp
- end
-
- # HtmlBlockFieldset = HtmlBlockOpenFieldset (HtmlBlockFieldset | !HtmlBlockCloseFieldset .)* HtmlBlockCloseFieldset
- def _HtmlBlockFieldset
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenFieldset)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockFieldset)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseFieldset)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseFieldset)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockFieldset unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenForm = "<" Spnl ("form" | "FORM") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenForm
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("form")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("FORM")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenForm unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseForm = "<" Spnl "/" ("form" | "FORM") Spnl ">"
- def _HtmlBlockCloseForm
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("form")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("FORM")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseForm unless _tmp
- return _tmp
- end
-
- # HtmlBlockForm = HtmlBlockOpenForm (HtmlBlockForm | !HtmlBlockCloseForm .)* HtmlBlockCloseForm
- def _HtmlBlockForm
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenForm)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockForm)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseForm)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseForm)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockForm unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenH1 = "<" Spnl ("h1" | "H1") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenH1
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("h1")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("H1")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenH1 unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseH1 = "<" Spnl "/" ("h1" | "H1") Spnl ">"
- def _HtmlBlockCloseH1
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("h1")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("H1")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseH1 unless _tmp
- return _tmp
- end
-
- # HtmlBlockH1 = HtmlBlockOpenH1 (HtmlBlockH1 | !HtmlBlockCloseH1 .)* HtmlBlockCloseH1
- def _HtmlBlockH1
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenH1)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockH1)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseH1)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseH1)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockH1 unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenH2 = "<" Spnl ("h2" | "H2") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenH2
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("h2")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("H2")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenH2 unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseH2 = "<" Spnl "/" ("h2" | "H2") Spnl ">"
- def _HtmlBlockCloseH2
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("h2")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("H2")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseH2 unless _tmp
- return _tmp
- end
-
- # HtmlBlockH2 = HtmlBlockOpenH2 (HtmlBlockH2 | !HtmlBlockCloseH2 .)* HtmlBlockCloseH2
- def _HtmlBlockH2
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenH2)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockH2)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseH2)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseH2)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockH2 unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenH3 = "<" Spnl ("h3" | "H3") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenH3
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("h3")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("H3")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenH3 unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseH3 = "<" Spnl "/" ("h3" | "H3") Spnl ">"
- def _HtmlBlockCloseH3
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("h3")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("H3")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseH3 unless _tmp
- return _tmp
- end
-
- # HtmlBlockH3 = HtmlBlockOpenH3 (HtmlBlockH3 | !HtmlBlockCloseH3 .)* HtmlBlockCloseH3
- def _HtmlBlockH3
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenH3)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockH3)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseH3)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseH3)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockH3 unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenH4 = "<" Spnl ("h4" | "H4") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenH4
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("h4")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("H4")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenH4 unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseH4 = "<" Spnl "/" ("h4" | "H4") Spnl ">"
- def _HtmlBlockCloseH4
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("h4")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("H4")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseH4 unless _tmp
- return _tmp
- end
-
- # HtmlBlockH4 = HtmlBlockOpenH4 (HtmlBlockH4 | !HtmlBlockCloseH4 .)* HtmlBlockCloseH4
- def _HtmlBlockH4
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenH4)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockH4)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseH4)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseH4)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockH4 unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenH5 = "<" Spnl ("h5" | "H5") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenH5
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("h5")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("H5")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenH5 unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseH5 = "<" Spnl "/" ("h5" | "H5") Spnl ">"
- def _HtmlBlockCloseH5
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("h5")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("H5")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseH5 unless _tmp
- return _tmp
- end
-
- # HtmlBlockH5 = HtmlBlockOpenH5 (HtmlBlockH5 | !HtmlBlockCloseH5 .)* HtmlBlockCloseH5
- def _HtmlBlockH5
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenH5)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockH5)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseH5)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseH5)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockH5 unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenH6 = "<" Spnl ("h6" | "H6") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenH6
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("h6")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("H6")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenH6 unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseH6 = "<" Spnl "/" ("h6" | "H6") Spnl ">"
- def _HtmlBlockCloseH6
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("h6")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("H6")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseH6 unless _tmp
- return _tmp
- end
-
- # HtmlBlockH6 = HtmlBlockOpenH6 (HtmlBlockH6 | !HtmlBlockCloseH6 .)* HtmlBlockCloseH6
- def _HtmlBlockH6
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenH6)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockH6)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseH6)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseH6)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockH6 unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenMenu = "<" Spnl ("menu" | "MENU") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenMenu
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("menu")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("MENU")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenMenu unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseMenu = "<" Spnl "/" ("menu" | "MENU") Spnl ">"
- def _HtmlBlockCloseMenu
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("menu")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("MENU")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseMenu unless _tmp
- return _tmp
- end
-
- # HtmlBlockMenu = HtmlBlockOpenMenu (HtmlBlockMenu | !HtmlBlockCloseMenu .)* HtmlBlockCloseMenu
- def _HtmlBlockMenu
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenMenu)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockMenu)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseMenu)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseMenu)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockMenu unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenNoframes = "<" Spnl ("noframes" | "NOFRAMES") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenNoframes
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("noframes")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("NOFRAMES")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenNoframes unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseNoframes = "<" Spnl "/" ("noframes" | "NOFRAMES") Spnl ">"
- def _HtmlBlockCloseNoframes
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("noframes")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("NOFRAMES")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseNoframes unless _tmp
- return _tmp
- end
-
- # HtmlBlockNoframes = HtmlBlockOpenNoframes (HtmlBlockNoframes | !HtmlBlockCloseNoframes .)* HtmlBlockCloseNoframes
- def _HtmlBlockNoframes
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenNoframes)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockNoframes)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseNoframes)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseNoframes)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockNoframes unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenNoscript = "<" Spnl ("noscript" | "NOSCRIPT") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenNoscript
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("noscript")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("NOSCRIPT")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenNoscript unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseNoscript = "<" Spnl "/" ("noscript" | "NOSCRIPT") Spnl ">"
- def _HtmlBlockCloseNoscript
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("noscript")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("NOSCRIPT")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseNoscript unless _tmp
- return _tmp
- end
-
- # HtmlBlockNoscript = HtmlBlockOpenNoscript (HtmlBlockNoscript | !HtmlBlockCloseNoscript .)* HtmlBlockCloseNoscript
- def _HtmlBlockNoscript
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenNoscript)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockNoscript)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseNoscript)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseNoscript)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockNoscript unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenOl = "<" Spnl ("ol" | "OL") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenOl
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("ol")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("OL")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenOl unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseOl = "<" Spnl "/" ("ol" | "OL") Spnl ">"
- def _HtmlBlockCloseOl
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("ol")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("OL")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseOl unless _tmp
- return _tmp
- end
-
- # HtmlBlockOl = HtmlBlockOpenOl (HtmlBlockOl | !HtmlBlockCloseOl .)* HtmlBlockCloseOl
- def _HtmlBlockOl
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenOl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockOl)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseOl)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseOl)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOl unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenP = "<" Spnl ("p" | "P") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenP
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("p")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("P")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenP unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseP = "<" Spnl "/" ("p" | "P") Spnl ">"
- def _HtmlBlockCloseP
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("p")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("P")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseP unless _tmp
- return _tmp
- end
-
- # HtmlBlockP = HtmlBlockOpenP (HtmlBlockP | !HtmlBlockCloseP .)* HtmlBlockCloseP
- def _HtmlBlockP
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenP)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockP)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseP)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseP)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockP unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenPre = "<" Spnl ("pre" | "PRE") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenPre
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("pre")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("PRE")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenPre unless _tmp
- return _tmp
- end
-
- # HtmlBlockClosePre = "<" Spnl "/" ("pre" | "PRE") Spnl ">"
- def _HtmlBlockClosePre
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("pre")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("PRE")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockClosePre unless _tmp
- return _tmp
- end
-
- # HtmlBlockPre = HtmlBlockOpenPre (HtmlBlockPre | !HtmlBlockClosePre .)* HtmlBlockClosePre
- def _HtmlBlockPre
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenPre)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockPre)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockClosePre)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockClosePre)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockPre unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenTable = "<" Spnl ("table" | "TABLE") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenTable
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("table")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("TABLE")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenTable unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseTable = "<" Spnl "/" ("table" | "TABLE") Spnl ">"
- def _HtmlBlockCloseTable
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("table")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("TABLE")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseTable unless _tmp
- return _tmp
- end
-
- # HtmlBlockTable = HtmlBlockOpenTable (HtmlBlockTable | !HtmlBlockCloseTable .)* HtmlBlockCloseTable
- def _HtmlBlockTable
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenTable)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockTable)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseTable)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseTable)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockTable unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenUl = "<" Spnl ("ul" | "UL") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenUl
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("ul")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("UL")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenUl unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseUl = "<" Spnl "/" ("ul" | "UL") Spnl ">"
- def _HtmlBlockCloseUl
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("ul")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("UL")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseUl unless _tmp
- return _tmp
- end
-
- # HtmlBlockUl = HtmlBlockOpenUl (HtmlBlockUl | !HtmlBlockCloseUl .)* HtmlBlockCloseUl
- def _HtmlBlockUl
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenUl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockUl)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseUl)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseUl)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockUl unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenDd = "<" Spnl ("dd" | "DD") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenDd
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("dd")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("DD")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenDd unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseDd = "<" Spnl "/" ("dd" | "DD") Spnl ">"
- def _HtmlBlockCloseDd
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("dd")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("DD")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseDd unless _tmp
- return _tmp
- end
-
- # HtmlBlockDd = HtmlBlockOpenDd (HtmlBlockDd | !HtmlBlockCloseDd .)* HtmlBlockCloseDd
- def _HtmlBlockDd
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenDd)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockDd)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseDd)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseDd)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockDd unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenDt = "<" Spnl ("dt" | "DT") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenDt
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("dt")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("DT")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenDt unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseDt = "<" Spnl "/" ("dt" | "DT") Spnl ">"
- def _HtmlBlockCloseDt
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("dt")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("DT")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseDt unless _tmp
- return _tmp
- end
-
- # HtmlBlockDt = HtmlBlockOpenDt (HtmlBlockDt | !HtmlBlockCloseDt .)* HtmlBlockCloseDt
- def _HtmlBlockDt
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenDt)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockDt)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseDt)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseDt)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockDt unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenFrameset = "<" Spnl ("frameset" | "FRAMESET") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenFrameset
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("frameset")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("FRAMESET")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenFrameset unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseFrameset = "<" Spnl "/" ("frameset" | "FRAMESET") Spnl ">"
- def _HtmlBlockCloseFrameset
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("frameset")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("FRAMESET")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseFrameset unless _tmp
- return _tmp
- end
-
- # HtmlBlockFrameset = HtmlBlockOpenFrameset (HtmlBlockFrameset | !HtmlBlockCloseFrameset .)* HtmlBlockCloseFrameset
- def _HtmlBlockFrameset
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenFrameset)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockFrameset)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseFrameset)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseFrameset)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockFrameset unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenLi = "<" Spnl ("li" | "LI") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenLi
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("li")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("LI")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenLi unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseLi = "<" Spnl "/" ("li" | "LI") Spnl ">"
- def _HtmlBlockCloseLi
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("li")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("LI")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseLi unless _tmp
- return _tmp
- end
-
- # HtmlBlockLi = HtmlBlockOpenLi (HtmlBlockLi | !HtmlBlockCloseLi .)* HtmlBlockCloseLi
- def _HtmlBlockLi
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenLi)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockLi)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseLi)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseLi)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockLi unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenTbody = "<" Spnl ("tbody" | "TBODY") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenTbody
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("tbody")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("TBODY")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenTbody unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseTbody = "<" Spnl "/" ("tbody" | "TBODY") Spnl ">"
- def _HtmlBlockCloseTbody
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("tbody")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("TBODY")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseTbody unless _tmp
- return _tmp
- end
-
- # HtmlBlockTbody = HtmlBlockOpenTbody (HtmlBlockTbody | !HtmlBlockCloseTbody .)* HtmlBlockCloseTbody
- def _HtmlBlockTbody
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenTbody)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockTbody)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseTbody)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseTbody)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockTbody unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenTd = "<" Spnl ("td" | "TD") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenTd
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("td")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("TD")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenTd unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseTd = "<" Spnl "/" ("td" | "TD") Spnl ">"
- def _HtmlBlockCloseTd
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("td")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("TD")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseTd unless _tmp
- return _tmp
- end
-
- # HtmlBlockTd = HtmlBlockOpenTd (HtmlBlockTd | !HtmlBlockCloseTd .)* HtmlBlockCloseTd
- def _HtmlBlockTd
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenTd)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockTd)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseTd)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseTd)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockTd unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenTfoot = "<" Spnl ("tfoot" | "TFOOT") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenTfoot
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("tfoot")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("TFOOT")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenTfoot unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseTfoot = "<" Spnl "/" ("tfoot" | "TFOOT") Spnl ">"
- def _HtmlBlockCloseTfoot
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("tfoot")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("TFOOT")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseTfoot unless _tmp
- return _tmp
- end
-
- # HtmlBlockTfoot = HtmlBlockOpenTfoot (HtmlBlockTfoot | !HtmlBlockCloseTfoot .)* HtmlBlockCloseTfoot
- def _HtmlBlockTfoot
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenTfoot)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockTfoot)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseTfoot)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseTfoot)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockTfoot unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenTh = "<" Spnl ("th" | "TH") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenTh
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("th")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("TH")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenTh unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseTh = "<" Spnl "/" ("th" | "TH") Spnl ">"
- def _HtmlBlockCloseTh
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("th")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("TH")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseTh unless _tmp
- return _tmp
- end
-
- # HtmlBlockTh = HtmlBlockOpenTh (HtmlBlockTh | !HtmlBlockCloseTh .)* HtmlBlockCloseTh
- def _HtmlBlockTh
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenTh)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockTh)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseTh)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseTh)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockTh unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenThead = "<" Spnl ("thead" | "THEAD") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenThead
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("thead")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("THEAD")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenThead unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseThead = "<" Spnl "/" ("thead" | "THEAD") Spnl ">"
- def _HtmlBlockCloseThead
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("thead")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("THEAD")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseThead unless _tmp
- return _tmp
- end
-
- # HtmlBlockThead = HtmlBlockOpenThead (HtmlBlockThead | !HtmlBlockCloseThead .)* HtmlBlockCloseThead
- def _HtmlBlockThead
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenThead)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockThead)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseThead)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseThead)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockThead unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenTr = "<" Spnl ("tr" | "TR") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenTr
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("tr")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("TR")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenTr unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseTr = "<" Spnl "/" ("tr" | "TR") Spnl ">"
- def _HtmlBlockCloseTr
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("tr")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("TR")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseTr unless _tmp
- return _tmp
- end
-
- # HtmlBlockTr = HtmlBlockOpenTr (HtmlBlockTr | !HtmlBlockCloseTr .)* HtmlBlockCloseTr
- def _HtmlBlockTr
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenTr)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockTr)
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_HtmlBlockCloseTr)
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseTr)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockTr unless _tmp
- return _tmp
- end
-
- # HtmlBlockOpenScript = "<" Spnl ("script" | "SCRIPT") Spnl HtmlAttribute* ">"
- def _HtmlBlockOpenScript
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("script")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("SCRIPT")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockOpenScript unless _tmp
- return _tmp
- end
-
- # HtmlBlockCloseScript = "<" Spnl "/" ("script" | "SCRIPT") Spnl ">"
- def _HtmlBlockCloseScript
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("script")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("SCRIPT")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockCloseScript unless _tmp
- return _tmp
- end
-
- # HtmlBlockScript = HtmlBlockOpenScript (!HtmlBlockCloseScript .)* HtmlBlockCloseScript
- def _HtmlBlockScript
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_HtmlBlockOpenScript)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # sequence
- _save3 = self.pos
- _tmp = apply(:_HtmlBlockCloseScript)
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockCloseScript)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockScript unless _tmp
- return _tmp
- end
-
- # HtmlBlockInTags = (HtmlAnchor | HtmlBlockAddress | HtmlBlockBlockquote | HtmlBlockCenter | HtmlBlockDir | HtmlBlockDiv | HtmlBlockDl | HtmlBlockFieldset | HtmlBlockForm | HtmlBlockH1 | HtmlBlockH2 | HtmlBlockH3 | HtmlBlockH4 | HtmlBlockH5 | HtmlBlockH6 | HtmlBlockMenu | HtmlBlockNoframes | HtmlBlockNoscript | HtmlBlockOl | HtmlBlockP | HtmlBlockPre | HtmlBlockTable | HtmlBlockUl | HtmlBlockDd | HtmlBlockDt | HtmlBlockFrameset | HtmlBlockLi | HtmlBlockTbody | HtmlBlockTd | HtmlBlockTfoot | HtmlBlockTh | HtmlBlockThead | HtmlBlockTr | HtmlBlockScript)
- def _HtmlBlockInTags
-
- _save = self.pos
- while true # choice
- _tmp = apply(:_HtmlAnchor)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockAddress)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockBlockquote)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockCenter)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockDir)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockDiv)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockDl)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockFieldset)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockForm)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockH1)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockH2)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockH3)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockH4)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockH5)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockH6)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockMenu)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockNoframes)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockNoscript)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockOl)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockP)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockPre)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockTable)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockUl)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockDd)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockDt)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockFrameset)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockLi)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockTbody)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockTd)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockTfoot)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockTh)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockThead)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockTr)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_HtmlBlockScript)
- break if _tmp
- self.pos = _save
- break
- end # end choice
-
- set_failed_rule :_HtmlBlockInTags unless _tmp
- return _tmp
- end
-
- # HtmlBlock = < (HtmlBlockInTags | HtmlComment | HtmlBlockSelfClosing | HtmlUnclosed) > @BlankLine+ { if html? then RDoc::Markup::Raw.new text end }
- def _HtmlBlock
-
- _save = self.pos
- while true # sequence
- _text_start = self.pos
-
- _save1 = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlockInTags)
- break if _tmp
- self.pos = _save1
- _tmp = apply(:_HtmlComment)
- break if _tmp
- self.pos = _save1
- _tmp = apply(:_HtmlBlockSelfClosing)
- break if _tmp
- self.pos = _save1
- _tmp = apply(:_HtmlUnclosed)
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _tmp = _BlankLine()
- if _tmp
- while true
- _tmp = _BlankLine()
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save2
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; if html? then
- RDoc::Markup::Raw.new text
- end ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlock unless _tmp
- return _tmp
- end
-
- # HtmlUnclosed = "<" Spnl HtmlUnclosedType Spnl HtmlAttribute* Spnl ">"
- def _HtmlUnclosed
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlUnclosedType)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlUnclosed unless _tmp
- return _tmp
- end
-
- # HtmlUnclosedType = ("HR" | "hr")
- def _HtmlUnclosedType
-
- _save = self.pos
- while true # choice
- _tmp = match_string("HR")
- break if _tmp
- self.pos = _save
- _tmp = match_string("hr")
- break if _tmp
- self.pos = _save
- break
- end # end choice
-
- set_failed_rule :_HtmlUnclosedType unless _tmp
- return _tmp
- end
-
- # HtmlBlockSelfClosing = "<" Spnl HtmlBlockType Spnl HtmlAttribute* "/" Spnl ">"
- def _HtmlBlockSelfClosing
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_HtmlBlockType)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlBlockSelfClosing unless _tmp
- return _tmp
- end
-
- # HtmlBlockType = ("ADDRESS" | "BLOCKQUOTE" | "CENTER" | "DD" | "DIR" | "DIV" | "DL" | "DT" | "FIELDSET" | "FORM" | "FRAMESET" | "H1" | "H2" | "H3" | "H4" | "H5" | "H6" | "HR" | "ISINDEX" | "LI" | "MENU" | "NOFRAMES" | "NOSCRIPT" | "OL" | "P" | "PRE" | "SCRIPT" | "TABLE" | "TBODY" | "TD" | "TFOOT" | "TH" | "THEAD" | "TR" | "UL" | "address" | "blockquote" | "center" | "dd" | "dir" | "div" | "dl" | "dt" | "fieldset" | "form" | "frameset" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "hr" | "isindex" | "li" | "menu" | "noframes" | "noscript" | "ol" | "p" | "pre" | "script" | "table" | "tbody" | "td" | "tfoot" | "th" | "thead" | "tr" | "ul")
- def _HtmlBlockType
-
- _save = self.pos
- while true # choice
- _tmp = match_string("ADDRESS")
- break if _tmp
- self.pos = _save
- _tmp = match_string("BLOCKQUOTE")
- break if _tmp
- self.pos = _save
- _tmp = match_string("CENTER")
- break if _tmp
- self.pos = _save
- _tmp = match_string("DD")
- break if _tmp
- self.pos = _save
- _tmp = match_string("DIR")
- break if _tmp
- self.pos = _save
- _tmp = match_string("DIV")
- break if _tmp
- self.pos = _save
- _tmp = match_string("DL")
- break if _tmp
- self.pos = _save
- _tmp = match_string("DT")
- break if _tmp
- self.pos = _save
- _tmp = match_string("FIELDSET")
- break if _tmp
- self.pos = _save
- _tmp = match_string("FORM")
- break if _tmp
- self.pos = _save
- _tmp = match_string("FRAMESET")
- break if _tmp
- self.pos = _save
- _tmp = match_string("H1")
- break if _tmp
- self.pos = _save
- _tmp = match_string("H2")
- break if _tmp
- self.pos = _save
- _tmp = match_string("H3")
- break if _tmp
- self.pos = _save
- _tmp = match_string("H4")
- break if _tmp
- self.pos = _save
- _tmp = match_string("H5")
- break if _tmp
- self.pos = _save
- _tmp = match_string("H6")
- break if _tmp
- self.pos = _save
- _tmp = match_string("HR")
- break if _tmp
- self.pos = _save
- _tmp = match_string("ISINDEX")
- break if _tmp
- self.pos = _save
- _tmp = match_string("LI")
- break if _tmp
- self.pos = _save
- _tmp = match_string("MENU")
- break if _tmp
- self.pos = _save
- _tmp = match_string("NOFRAMES")
- break if _tmp
- self.pos = _save
- _tmp = match_string("NOSCRIPT")
- break if _tmp
- self.pos = _save
- _tmp = match_string("OL")
- break if _tmp
- self.pos = _save
- _tmp = match_string("P")
- break if _tmp
- self.pos = _save
- _tmp = match_string("PRE")
- break if _tmp
- self.pos = _save
- _tmp = match_string("SCRIPT")
- break if _tmp
- self.pos = _save
- _tmp = match_string("TABLE")
- break if _tmp
- self.pos = _save
- _tmp = match_string("TBODY")
- break if _tmp
- self.pos = _save
- _tmp = match_string("TD")
- break if _tmp
- self.pos = _save
- _tmp = match_string("TFOOT")
- break if _tmp
- self.pos = _save
- _tmp = match_string("TH")
- break if _tmp
- self.pos = _save
- _tmp = match_string("THEAD")
- break if _tmp
- self.pos = _save
- _tmp = match_string("TR")
- break if _tmp
- self.pos = _save
- _tmp = match_string("UL")
- break if _tmp
- self.pos = _save
- _tmp = match_string("address")
- break if _tmp
- self.pos = _save
- _tmp = match_string("blockquote")
- break if _tmp
- self.pos = _save
- _tmp = match_string("center")
- break if _tmp
- self.pos = _save
- _tmp = match_string("dd")
- break if _tmp
- self.pos = _save
- _tmp = match_string("dir")
- break if _tmp
- self.pos = _save
- _tmp = match_string("div")
- break if _tmp
- self.pos = _save
- _tmp = match_string("dl")
- break if _tmp
- self.pos = _save
- _tmp = match_string("dt")
- break if _tmp
- self.pos = _save
- _tmp = match_string("fieldset")
- break if _tmp
- self.pos = _save
- _tmp = match_string("form")
- break if _tmp
- self.pos = _save
- _tmp = match_string("frameset")
- break if _tmp
- self.pos = _save
- _tmp = match_string("h1")
- break if _tmp
- self.pos = _save
- _tmp = match_string("h2")
- break if _tmp
- self.pos = _save
- _tmp = match_string("h3")
- break if _tmp
- self.pos = _save
- _tmp = match_string("h4")
- break if _tmp
- self.pos = _save
- _tmp = match_string("h5")
- break if _tmp
- self.pos = _save
- _tmp = match_string("h6")
- break if _tmp
- self.pos = _save
- _tmp = match_string("hr")
- break if _tmp
- self.pos = _save
- _tmp = match_string("isindex")
- break if _tmp
- self.pos = _save
- _tmp = match_string("li")
- break if _tmp
- self.pos = _save
- _tmp = match_string("menu")
- break if _tmp
- self.pos = _save
- _tmp = match_string("noframes")
- break if _tmp
- self.pos = _save
- _tmp = match_string("noscript")
- break if _tmp
- self.pos = _save
- _tmp = match_string("ol")
- break if _tmp
- self.pos = _save
- _tmp = match_string("p")
- break if _tmp
- self.pos = _save
- _tmp = match_string("pre")
- break if _tmp
- self.pos = _save
- _tmp = match_string("script")
- break if _tmp
- self.pos = _save
- _tmp = match_string("table")
- break if _tmp
- self.pos = _save
- _tmp = match_string("tbody")
- break if _tmp
- self.pos = _save
- _tmp = match_string("td")
- break if _tmp
- self.pos = _save
- _tmp = match_string("tfoot")
- break if _tmp
- self.pos = _save
- _tmp = match_string("th")
- break if _tmp
- self.pos = _save
- _tmp = match_string("thead")
- break if _tmp
- self.pos = _save
- _tmp = match_string("tr")
- break if _tmp
- self.pos = _save
- _tmp = match_string("ul")
- break if _tmp
- self.pos = _save
- break
- end # end choice
-
- set_failed_rule :_HtmlBlockType unless _tmp
- return _tmp
- end
-
- # StyleOpen = "<" Spnl ("style" | "STYLE") Spnl HtmlAttribute* ">"
- def _StyleOpen
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("style")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("STYLE")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_StyleOpen unless _tmp
- return _tmp
- end
-
- # StyleClose = "<" Spnl "/" ("style" | "STYLE") Spnl ">"
- def _StyleClose
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("/")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = match_string("style")
- break if _tmp
- self.pos = _save1
- _tmp = match_string("STYLE")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_StyleClose unless _tmp
- return _tmp
- end
-
- # InStyleTags = StyleOpen (!StyleClose .)* StyleClose
- def _InStyleTags
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_StyleOpen)
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # sequence
- _save3 = self.pos
- _tmp = apply(:_StyleClose)
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_StyleClose)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_InStyleTags unless _tmp
- return _tmp
- end
-
- # StyleBlock = < InStyleTags > @BlankLine* { if css? then RDoc::Markup::Raw.new text end }
- def _StyleBlock
-
- _save = self.pos
- while true # sequence
- _text_start = self.pos
- _tmp = apply(:_InStyleTags)
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = _BlankLine()
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; if css? then
- RDoc::Markup::Raw.new text
- end ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_StyleBlock unless _tmp
- return _tmp
- end
-
- # Inlines = (!@Endline Inline:i { i } | @Endline:c &Inline { c })+:chunks @Endline? { chunks }
- def _Inlines
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _ary = []
-
- _save2 = self.pos
- while true # choice
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = _Endline()
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = apply(:_Inline)
- i = @result
- unless _tmp
- self.pos = _save3
- break
- end
- @result = begin; i ; end
- _tmp = true
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
-
- _save5 = self.pos
- while true # sequence
- _tmp = _Endline()
- c = @result
- unless _tmp
- self.pos = _save5
- break
- end
- _save6 = self.pos
- _tmp = apply(:_Inline)
- self.pos = _save6
- unless _tmp
- self.pos = _save5
- break
- end
- @result = begin; c ; end
- _tmp = true
- unless _tmp
- self.pos = _save5
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- if _tmp
- _ary << @result
- while true
-
- _save7 = self.pos
- while true # choice
-
- _save8 = self.pos
- while true # sequence
- _save9 = self.pos
- _tmp = _Endline()
- _tmp = _tmp ? nil : true
- self.pos = _save9
- unless _tmp
- self.pos = _save8
- break
- end
- _tmp = apply(:_Inline)
- i = @result
- unless _tmp
- self.pos = _save8
- break
- end
- @result = begin; i ; end
- _tmp = true
- unless _tmp
- self.pos = _save8
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save7
-
- _save10 = self.pos
- while true # sequence
- _tmp = _Endline()
- c = @result
- unless _tmp
- self.pos = _save10
- break
- end
- _save11 = self.pos
- _tmp = apply(:_Inline)
- self.pos = _save11
- unless _tmp
- self.pos = _save10
- break
- end
- @result = begin; c ; end
- _tmp = true
- unless _tmp
- self.pos = _save10
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save7
- break
- end # end choice
-
- _ary << @result if _tmp
- break unless _tmp
- end
- _tmp = true
- @result = _ary
- else
- self.pos = _save1
- end
- chunks = @result
- unless _tmp
- self.pos = _save
- break
- end
- _save12 = self.pos
- _tmp = _Endline()
- unless _tmp
- _tmp = true
- self.pos = _save12
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; chunks ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Inlines unless _tmp
- return _tmp
- end
-
- # Inline = (Str | @Endline | UlOrStarLine | @Space | Strong | Emph | Image | Link | NoteReference | InlineNote | Code | RawHtml | Entity | EscapedChar | Symbol)
- def _Inline
-
- _save = self.pos
- while true # choice
- _tmp = apply(:_Str)
- break if _tmp
- self.pos = _save
- _tmp = _Endline()
- break if _tmp
- self.pos = _save
- _tmp = apply(:_UlOrStarLine)
- break if _tmp
- self.pos = _save
- _tmp = _Space()
- break if _tmp
- self.pos = _save
- _tmp = apply(:_Strong)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_Emph)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_Image)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_Link)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_NoteReference)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_InlineNote)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_Code)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_RawHtml)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_Entity)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_EscapedChar)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_Symbol)
- break if _tmp
- self.pos = _save
- break
- end # end choice
-
- set_failed_rule :_Inline unless _tmp
- return _tmp
- end
-
- # Space = @Spacechar+ { " " }
- def _Space
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = _Spacechar()
- if _tmp
- while true
- _tmp = _Spacechar()
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save1
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; " " ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Space unless _tmp
- return _tmp
- end
-
- # Str = @StartList:a < @NormalChar+ > { a = text } (StrChunk:c { a << c })* { a }
- def _Str
-
- _save = self.pos
- while true # sequence
- _tmp = _StartList()
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _text_start = self.pos
- _save1 = self.pos
- _tmp = _NormalChar()
- if _tmp
- while true
- _tmp = _NormalChar()
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save1
- end
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a = text ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save3 = self.pos
- while true # sequence
- _tmp = apply(:_StrChunk)
- c = @result
- unless _tmp
- self.pos = _save3
- break
- end
- @result = begin; a << c ; end
- _tmp = true
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Str unless _tmp
- return _tmp
- end
-
- # StrChunk = < (@NormalChar | /_+/ &Alphanumeric)+ > { text }
- def _StrChunk
-
- _save = self.pos
- while true # sequence
- _text_start = self.pos
- _save1 = self.pos
-
- _save2 = self.pos
- while true # choice
- _tmp = _NormalChar()
- break if _tmp
- self.pos = _save2
-
- _save3 = self.pos
- while true # sequence
- _tmp = scan(/\A(?-mix:_+)/)
- unless _tmp
- self.pos = _save3
- break
- end
- _save4 = self.pos
- _tmp = apply(:_Alphanumeric)
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- if _tmp
- while true
-
- _save5 = self.pos
- while true # choice
- _tmp = _NormalChar()
- break if _tmp
- self.pos = _save5
-
- _save6 = self.pos
- while true # sequence
- _tmp = scan(/\A(?-mix:_+)/)
- unless _tmp
- self.pos = _save6
- break
- end
- _save7 = self.pos
- _tmp = apply(:_Alphanumeric)
- self.pos = _save7
- unless _tmp
- self.pos = _save6
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save5
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save1
- end
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; text ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_StrChunk unless _tmp
- return _tmp
- end
-
- # EscapedChar = "\\" !@Newline < /[:\\`|*_{}\[\]()#+.!><-]/ > { text }
- def _EscapedChar
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("\\")
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
- _tmp = _Newline()
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _text_start = self.pos
- _tmp = scan(/\A(?-mix:[:\\`|*_{}\[\]()#+.!><-])/)
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; text ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_EscapedChar unless _tmp
- return _tmp
- end
-
- # Entity = (HexEntity | DecEntity | CharEntity):a { a }
- def _Entity
-
- _save = self.pos
- while true # sequence
-
- _save1 = self.pos
- while true # choice
- _tmp = apply(:_HexEntity)
- break if _tmp
- self.pos = _save1
- _tmp = apply(:_DecEntity)
- break if _tmp
- self.pos = _save1
- _tmp = apply(:_CharEntity)
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Entity unless _tmp
- return _tmp
- end
-
- # Endline = (@LineBreak | @TerminalEndline | @NormalEndline)
- def _Endline
-
- _save = self.pos
- while true # choice
- _tmp = _LineBreak()
- break if _tmp
- self.pos = _save
- _tmp = _TerminalEndline()
- break if _tmp
- self.pos = _save
- _tmp = _NormalEndline()
- break if _tmp
- self.pos = _save
- break
- end # end choice
-
- set_failed_rule :_Endline unless _tmp
- return _tmp
- end
-
- # NormalEndline = @Sp @Newline !@BlankLine !">" !AtxStart !(Line /={3,}|-{3,}=/ @Newline) { "\n" }
- def _NormalEndline
-
- _save = self.pos
- while true # sequence
- _tmp = _Sp()
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _Newline()
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _tmp = match_string(">")
- _tmp = _tmp ? nil : true
- self.pos = _save2
- unless _tmp
- self.pos = _save
- break
- end
- _save3 = self.pos
- _tmp = apply(:_AtxStart)
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save
- break
- end
- _save4 = self.pos
-
- _save5 = self.pos
- while true # sequence
- _tmp = apply(:_Line)
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = scan(/\A(?-mix:={3,}|-{3,}=)/)
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = _Newline()
- unless _tmp
- self.pos = _save5
- end
- break
- end # end sequence
-
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; "\n" ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_NormalEndline unless _tmp
- return _tmp
- end
-
- # TerminalEndline = @Sp @Newline @Eof
- def _TerminalEndline
-
- _save = self.pos
- while true # sequence
- _tmp = _Sp()
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _Newline()
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _Eof()
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_TerminalEndline unless _tmp
- return _tmp
- end
-
- # LineBreak = " " @NormalEndline { RDoc::Markup::HardBreak.new }
- def _LineBreak
-
- _save = self.pos
- while true # sequence
- _tmp = match_string(" ")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _NormalEndline()
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; RDoc::Markup::HardBreak.new ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_LineBreak unless _tmp
- return _tmp
- end
-
- # Symbol = < @SpecialChar > { text }
- def _Symbol
-
- _save = self.pos
- while true # sequence
- _text_start = self.pos
- _tmp = _SpecialChar()
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; text ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Symbol unless _tmp
- return _tmp
- end
-
- # UlOrStarLine = (UlLine | StarLine):a { a }
- def _UlOrStarLine
-
- _save = self.pos
- while true # sequence
-
- _save1 = self.pos
- while true # choice
- _tmp = apply(:_UlLine)
- break if _tmp
- self.pos = _save1
- _tmp = apply(:_StarLine)
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_UlOrStarLine unless _tmp
- return _tmp
- end
-
- # StarLine = (< /\*{4,}/ > { text } | < @Spacechar /\*+/ &@Spacechar > { text })
- def _StarLine
-
- _save = self.pos
- while true # choice
-
- _save1 = self.pos
- while true # sequence
- _text_start = self.pos
- _tmp = scan(/\A(?-mix:\*{4,})/)
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save1
- break
- end
- @result = begin; text ; end
- _tmp = true
- unless _tmp
- self.pos = _save1
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save
-
- _save2 = self.pos
- while true # sequence
- _text_start = self.pos
-
- _save3 = self.pos
- while true # sequence
- _tmp = _Spacechar()
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = scan(/\A(?-mix:\*+)/)
- unless _tmp
- self.pos = _save3
- break
- end
- _save4 = self.pos
- _tmp = _Spacechar()
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save2
- break
- end
- @result = begin; text ; end
- _tmp = true
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save
- break
- end # end choice
-
- set_failed_rule :_StarLine unless _tmp
- return _tmp
- end
-
- # UlLine = (< /_{4,}/ > { text } | < @Spacechar /_+/ &@Spacechar > { text })
- def _UlLine
-
- _save = self.pos
- while true # choice
-
- _save1 = self.pos
- while true # sequence
- _text_start = self.pos
- _tmp = scan(/\A(?-mix:_{4,})/)
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save1
- break
- end
- @result = begin; text ; end
- _tmp = true
- unless _tmp
- self.pos = _save1
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save
-
- _save2 = self.pos
- while true # sequence
- _text_start = self.pos
-
- _save3 = self.pos
- while true # sequence
- _tmp = _Spacechar()
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = scan(/\A(?-mix:_+)/)
- unless _tmp
- self.pos = _save3
- break
- end
- _save4 = self.pos
- _tmp = _Spacechar()
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save2
- break
- end
- @result = begin; text ; end
- _tmp = true
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save
- break
- end # end choice
-
- set_failed_rule :_UlLine unless _tmp
- return _tmp
- end
-
- # Emph = (EmphStar | EmphUl)
- def _Emph
-
- _save = self.pos
- while true # choice
- _tmp = apply(:_EmphStar)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_EmphUl)
- break if _tmp
- self.pos = _save
- break
- end # end choice
-
- set_failed_rule :_Emph unless _tmp
- return _tmp
- end
-
- # OneStarOpen = !StarLine "*" !@Spacechar !@Newline
- def _OneStarOpen
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = apply(:_StarLine)
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("*")
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _tmp = _Spacechar()
- _tmp = _tmp ? nil : true
- self.pos = _save2
- unless _tmp
- self.pos = _save
- break
- end
- _save3 = self.pos
- _tmp = _Newline()
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_OneStarOpen unless _tmp
- return _tmp
- end
-
- # OneStarClose = !@Spacechar !@Newline Inline:a "*" { a }
- def _OneStarClose
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = _Spacechar()
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _tmp = _Newline()
- _tmp = _tmp ? nil : true
- self.pos = _save2
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Inline)
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("*")
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_OneStarClose unless _tmp
- return _tmp
- end
-
- # EmphStar = OneStarOpen @StartList:a (!OneStarClose Inline:l { a << l })* OneStarClose:l { a << l } { emphasis a.join }
- def _EmphStar
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_OneStarOpen)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _StartList()
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # sequence
- _save3 = self.pos
- _tmp = apply(:_OneStarClose)
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = apply(:_Inline)
- l = @result
- unless _tmp
- self.pos = _save2
- break
- end
- @result = begin; a << l ; end
- _tmp = true
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_OneStarClose)
- l = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a << l ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; emphasis a.join ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_EmphStar unless _tmp
- return _tmp
- end
-
- # OneUlOpen = !UlLine "_" !@Spacechar !@Newline
- def _OneUlOpen
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = apply(:_UlLine)
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("_")
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _tmp = _Spacechar()
- _tmp = _tmp ? nil : true
- self.pos = _save2
- unless _tmp
- self.pos = _save
- break
- end
- _save3 = self.pos
- _tmp = _Newline()
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_OneUlOpen unless _tmp
- return _tmp
- end
-
- # OneUlClose = !@Spacechar !@Newline Inline:a "_" { a }
- def _OneUlClose
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = _Spacechar()
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _tmp = _Newline()
- _tmp = _tmp ? nil : true
- self.pos = _save2
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Inline)
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("_")
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_OneUlClose unless _tmp
- return _tmp
- end
-
- # EmphUl = OneUlOpen @StartList:a (!OneUlClose Inline:l { a << l })* OneUlClose:l { a << l } { emphasis a.join }
- def _EmphUl
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_OneUlOpen)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _StartList()
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # sequence
- _save3 = self.pos
- _tmp = apply(:_OneUlClose)
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = apply(:_Inline)
- l = @result
- unless _tmp
- self.pos = _save2
- break
- end
- @result = begin; a << l ; end
- _tmp = true
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_OneUlClose)
- l = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a << l ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; emphasis a.join ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_EmphUl unless _tmp
- return _tmp
- end
-
- # Strong = (StrongStar | StrongUl)
- def _Strong
-
- _save = self.pos
- while true # choice
- _tmp = apply(:_StrongStar)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_StrongUl)
- break if _tmp
- self.pos = _save
- break
- end # end choice
-
- set_failed_rule :_Strong unless _tmp
- return _tmp
- end
-
- # TwoStarOpen = !StarLine "**" !@Spacechar !@Newline
- def _TwoStarOpen
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = apply(:_StarLine)
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("**")
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _tmp = _Spacechar()
- _tmp = _tmp ? nil : true
- self.pos = _save2
- unless _tmp
- self.pos = _save
- break
- end
- _save3 = self.pos
- _tmp = _Newline()
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_TwoStarOpen unless _tmp
- return _tmp
- end
-
- # TwoStarClose = !@Spacechar !@Newline Inline:a "**" { a }
- def _TwoStarClose
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = _Spacechar()
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _tmp = _Newline()
- _tmp = _tmp ? nil : true
- self.pos = _save2
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Inline)
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("**")
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_TwoStarClose unless _tmp
- return _tmp
- end
-
- # StrongStar = TwoStarOpen @StartList:a (!TwoStarClose Inline:l { a << l })* TwoStarClose:l { a << l } { strong a.join }
- def _StrongStar
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_TwoStarOpen)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _StartList()
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # sequence
- _save3 = self.pos
- _tmp = apply(:_TwoStarClose)
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = apply(:_Inline)
- l = @result
- unless _tmp
- self.pos = _save2
- break
- end
- @result = begin; a << l ; end
- _tmp = true
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_TwoStarClose)
- l = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a << l ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; strong a.join ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_StrongStar unless _tmp
- return _tmp
- end
-
- # TwoUlOpen = !UlLine "__" !@Spacechar !@Newline
- def _TwoUlOpen
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = apply(:_UlLine)
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("__")
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _tmp = _Spacechar()
- _tmp = _tmp ? nil : true
- self.pos = _save2
- unless _tmp
- self.pos = _save
- break
- end
- _save3 = self.pos
- _tmp = _Newline()
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_TwoUlOpen unless _tmp
- return _tmp
- end
-
- # TwoUlClose = !@Spacechar !@Newline Inline:a "__" { a }
- def _TwoUlClose
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = _Spacechar()
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _tmp = _Newline()
- _tmp = _tmp ? nil : true
- self.pos = _save2
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Inline)
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("__")
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_TwoUlClose unless _tmp
- return _tmp
- end
-
- # StrongUl = TwoUlOpen @StartList:a (!TwoUlClose Inline:i { a << i })* TwoUlClose:l { a << l } { strong a.join }
- def _StrongUl
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_TwoUlOpen)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _StartList()
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # sequence
- _save3 = self.pos
- _tmp = apply(:_TwoUlClose)
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = apply(:_Inline)
- i = @result
- unless _tmp
- self.pos = _save2
- break
- end
- @result = begin; a << i ; end
- _tmp = true
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_TwoUlClose)
- l = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a << l ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; strong a.join ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_StrongUl unless _tmp
- return _tmp
- end
-
- # Image = "!" (ExplicitLink | ReferenceLink):a { "rdoc-image:#{a[/\[(.*)\]/, 1]}" }
- def _Image
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("!")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
- _tmp = apply(:_ExplicitLink)
- break if _tmp
- self.pos = _save1
- _tmp = apply(:_ReferenceLink)
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; "rdoc-image:#{a[/\[(.*)\]/, 1]}" ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Image unless _tmp
- return _tmp
- end
-
- # Link = (ExplicitLink | ReferenceLink | AutoLink)
- def _Link
-
- _save = self.pos
- while true # choice
- _tmp = apply(:_ExplicitLink)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_ReferenceLink)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_AutoLink)
- break if _tmp
- self.pos = _save
- break
- end # end choice
-
- set_failed_rule :_Link unless _tmp
- return _tmp
- end
-
- # ReferenceLink = (ReferenceLinkDouble | ReferenceLinkSingle)
- def _ReferenceLink
-
- _save = self.pos
- while true # choice
- _tmp = apply(:_ReferenceLinkDouble)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_ReferenceLinkSingle)
- break if _tmp
- self.pos = _save
- break
- end # end choice
-
- set_failed_rule :_ReferenceLink unless _tmp
- return _tmp
- end
-
- # ReferenceLinkDouble = Label:content < Spnl > !"[]" Label:label { link_to content, label, text }
- def _ReferenceLinkDouble
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_Label)
- content = @result
- unless _tmp
- self.pos = _save
- break
- end
- _text_start = self.pos
- _tmp = apply(:_Spnl)
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
- _tmp = match_string("[]")
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Label)
- label = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; link_to content, label, text ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_ReferenceLinkDouble unless _tmp
- return _tmp
- end
-
- # ReferenceLinkSingle = Label:content < (Spnl "[]")? > { link_to content, content, text }
- def _ReferenceLinkSingle
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_Label)
- content = @result
- unless _tmp
- self.pos = _save
- break
- end
- _text_start = self.pos
- _save1 = self.pos
-
- _save2 = self.pos
- while true # sequence
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = match_string("[]")
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- unless _tmp
- _tmp = true
- self.pos = _save1
- end
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; link_to content, content, text ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_ReferenceLinkSingle unless _tmp
- return _tmp
- end
-
- # ExplicitLink = Label:l Spnl "(" @Sp Source:s Spnl Title @Sp ")" { "{#{l}}[#{s}]" }
- def _ExplicitLink
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_Label)
- l = @result
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("(")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Source)
- s = @result
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Title)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(")")
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; "{#{l}}[#{s}]" ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_ExplicitLink unless _tmp
- return _tmp
- end
-
- # Source = ("<" < SourceContents > ">" | < SourceContents >) { text }
- def _Source
-
- _save = self.pos
- while true # sequence
-
- _save1 = self.pos
- while true # choice
-
- _save2 = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save2
- break
- end
- _text_start = self.pos
- _tmp = apply(:_SourceContents)
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save1
- _text_start = self.pos
- _tmp = apply(:_SourceContents)
- if _tmp
- text = get_text(_text_start)
- end
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; text ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Source unless _tmp
- return _tmp
- end
-
- # SourceContents = (((!"(" !")" !">" Nonspacechar)+ | "(" SourceContents ")")* | "")
- def _SourceContents
-
- _save = self.pos
- while true # choice
- while true
-
- _save2 = self.pos
- while true # choice
- _save3 = self.pos
-
- _save4 = self.pos
- while true # sequence
- _save5 = self.pos
- _tmp = match_string("(")
- _tmp = _tmp ? nil : true
- self.pos = _save5
- unless _tmp
- self.pos = _save4
- break
- end
- _save6 = self.pos
- _tmp = match_string(")")
- _tmp = _tmp ? nil : true
- self.pos = _save6
- unless _tmp
- self.pos = _save4
- break
- end
- _save7 = self.pos
- _tmp = match_string(">")
- _tmp = _tmp ? nil : true
- self.pos = _save7
- unless _tmp
- self.pos = _save4
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save4
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save8 = self.pos
- while true # sequence
- _save9 = self.pos
- _tmp = match_string("(")
- _tmp = _tmp ? nil : true
- self.pos = _save9
- unless _tmp
- self.pos = _save8
- break
- end
- _save10 = self.pos
- _tmp = match_string(")")
- _tmp = _tmp ? nil : true
- self.pos = _save10
- unless _tmp
- self.pos = _save8
- break
- end
- _save11 = self.pos
- _tmp = match_string(">")
- _tmp = _tmp ? nil : true
- self.pos = _save11
- unless _tmp
- self.pos = _save8
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save8
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save3
- end
- break if _tmp
- self.pos = _save2
-
- _save12 = self.pos
- while true # sequence
- _tmp = match_string("(")
- unless _tmp
- self.pos = _save12
- break
- end
- _tmp = apply(:_SourceContents)
- unless _tmp
- self.pos = _save12
- break
- end
- _tmp = match_string(")")
- unless _tmp
- self.pos = _save12
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- break if _tmp
- self.pos = _save
- _tmp = match_string("")
- break if _tmp
- self.pos = _save
- break
- end # end choice
-
- set_failed_rule :_SourceContents unless _tmp
- return _tmp
- end
-
- # Title = (TitleSingle | TitleDouble | ""):a { a }
- def _Title
-
- _save = self.pos
- while true # sequence
-
- _save1 = self.pos
- while true # choice
- _tmp = apply(:_TitleSingle)
- break if _tmp
- self.pos = _save1
- _tmp = apply(:_TitleDouble)
- break if _tmp
- self.pos = _save1
- _tmp = match_string("")
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Title unless _tmp
- return _tmp
- end
-
- # TitleSingle = "'" (!("'" @Sp (")" | @Newline)) .)* "'"
- def _TitleSingle
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("'")
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # sequence
- _save3 = self.pos
-
- _save4 = self.pos
- while true # sequence
- _tmp = match_string("'")
- unless _tmp
- self.pos = _save4
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save4
- break
- end
-
- _save5 = self.pos
- while true # choice
- _tmp = match_string(")")
- break if _tmp
- self.pos = _save5
- _tmp = _Newline()
- break if _tmp
- self.pos = _save5
- break
- end # end choice
-
- unless _tmp
- self.pos = _save4
- end
- break
- end # end sequence
-
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("'")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_TitleSingle unless _tmp
- return _tmp
- end
-
- # TitleDouble = "\"" (!("\"" @Sp (")" | @Newline)) .)* "\""
- def _TitleDouble
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("\"")
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # sequence
- _save3 = self.pos
-
- _save4 = self.pos
- while true # sequence
- _tmp = match_string("\"")
- unless _tmp
- self.pos = _save4
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save4
- break
- end
-
- _save5 = self.pos
- while true # choice
- _tmp = match_string(")")
- break if _tmp
- self.pos = _save5
- _tmp = _Newline()
- break if _tmp
- self.pos = _save5
- break
- end # end choice
-
- unless _tmp
- self.pos = _save4
- end
- break
- end # end sequence
-
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("\"")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_TitleDouble unless _tmp
- return _tmp
- end
-
- # AutoLink = (AutoLinkUrl | AutoLinkEmail)
- def _AutoLink
-
- _save = self.pos
- while true # choice
- _tmp = apply(:_AutoLinkUrl)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_AutoLinkEmail)
- break if _tmp
- self.pos = _save
- break
- end # end choice
-
- set_failed_rule :_AutoLink unless _tmp
- return _tmp
- end
-
- # AutoLinkUrl = "<" < /[A-Za-z]+/ "://" (!@Newline !">" .)+ > ">" { text }
- def _AutoLinkUrl
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _text_start = self.pos
-
- _save1 = self.pos
- while true # sequence
- _tmp = scan(/\A(?-mix:[A-Za-z]+)/)
- unless _tmp
- self.pos = _save1
- break
- end
- _tmp = match_string("://")
- unless _tmp
- self.pos = _save1
- break
- end
- _save2 = self.pos
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = _Newline()
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _save5 = self.pos
- _tmp = match_string(">")
- _tmp = _tmp ? nil : true
- self.pos = _save5
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save6 = self.pos
- while true # sequence
- _save7 = self.pos
- _tmp = _Newline()
- _tmp = _tmp ? nil : true
- self.pos = _save7
- unless _tmp
- self.pos = _save6
- break
- end
- _save8 = self.pos
- _tmp = match_string(">")
- _tmp = _tmp ? nil : true
- self.pos = _save8
- unless _tmp
- self.pos = _save6
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save6
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save2
- end
- unless _tmp
- self.pos = _save1
- end
- break
- end # end sequence
-
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; text ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_AutoLinkUrl unless _tmp
- return _tmp
- end
-
- # AutoLinkEmail = "<" "mailto:"? < /[\w+.\/!%~$-]+/i "@" (!@Newline !">" .)+ > ">" { "mailto:#{text}" }
- def _AutoLinkEmail
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
- _tmp = match_string("mailto:")
- unless _tmp
- _tmp = true
- self.pos = _save1
- end
- unless _tmp
- self.pos = _save
- break
- end
- _text_start = self.pos
-
- _save2 = self.pos
- while true # sequence
- _tmp = scan(/\A(?i-mx:[\w+.\/!%~$-]+)/)
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = match_string("@")
- unless _tmp
- self.pos = _save2
- break
- end
- _save3 = self.pos
-
- _save4 = self.pos
- while true # sequence
- _save5 = self.pos
- _tmp = _Newline()
- _tmp = _tmp ? nil : true
- self.pos = _save5
- unless _tmp
- self.pos = _save4
- break
- end
- _save6 = self.pos
- _tmp = match_string(">")
- _tmp = _tmp ? nil : true
- self.pos = _save6
- unless _tmp
- self.pos = _save4
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save4
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save7 = self.pos
- while true # sequence
- _save8 = self.pos
- _tmp = _Newline()
- _tmp = _tmp ? nil : true
- self.pos = _save8
- unless _tmp
- self.pos = _save7
- break
- end
- _save9 = self.pos
- _tmp = match_string(">")
- _tmp = _tmp ? nil : true
- self.pos = _save9
- unless _tmp
- self.pos = _save7
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save7
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save3
- end
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; "mailto:#{text}" ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_AutoLinkEmail unless _tmp
- return _tmp
- end
-
- # Reference = @NonindentSpace !"[]" Label:label ":" Spnl RefSrc:link RefTitle @BlankLine+ { # TODO use title reference label, link nil }
- def _Reference
-
- _save = self.pos
- while true # sequence
- _tmp = _NonindentSpace()
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
- _tmp = match_string("[]")
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Label)
- label = @result
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(":")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_RefSrc)
- link = @result
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_RefTitle)
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _tmp = _BlankLine()
- if _tmp
- while true
- _tmp = _BlankLine()
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save2
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; # TODO use title
- reference label, link
- nil
- ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Reference unless _tmp
- return _tmp
- end
-
- # Label = "[" (!"^" &{ notes? } | &. &{ !notes? }) @StartList:a (!"]" Inline:l { a << l })* "]" { a.join.gsub(/\s+/, ' ') }
- def _Label
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("[")
- unless _tmp
- self.pos = _save
- break
- end
-
- _save1 = self.pos
- while true # choice
-
- _save2 = self.pos
- while true # sequence
- _save3 = self.pos
- _tmp = match_string("^")
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save2
- break
- end
- _save4 = self.pos
- _tmp = begin; notes? ; end
- self.pos = _save4
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save1
-
- _save5 = self.pos
- while true # sequence
- _save6 = self.pos
- _tmp = get_byte
- self.pos = _save6
- unless _tmp
- self.pos = _save5
- break
- end
- _save7 = self.pos
- _tmp = begin; !notes? ; end
- self.pos = _save7
- unless _tmp
- self.pos = _save5
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _StartList()
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save9 = self.pos
- while true # sequence
- _save10 = self.pos
- _tmp = match_string("]")
- _tmp = _tmp ? nil : true
- self.pos = _save10
- unless _tmp
- self.pos = _save9
- break
- end
- _tmp = apply(:_Inline)
- l = @result
- unless _tmp
- self.pos = _save9
- break
- end
- @result = begin; a << l ; end
- _tmp = true
- unless _tmp
- self.pos = _save9
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("]")
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a.join.gsub(/\s+/, ' ') ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Label unless _tmp
- return _tmp
- end
-
- # RefSrc = < Nonspacechar+ > { text }
- def _RefSrc
-
- _save = self.pos
- while true # sequence
- _text_start = self.pos
- _save1 = self.pos
- _tmp = apply(:_Nonspacechar)
- if _tmp
- while true
- _tmp = apply(:_Nonspacechar)
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save1
- end
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; text ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_RefSrc unless _tmp
- return _tmp
- end
-
- # RefTitle = (RefTitleSingle | RefTitleDouble | RefTitleParens | EmptyTitle)
- def _RefTitle
-
- _save = self.pos
- while true # choice
- _tmp = apply(:_RefTitleSingle)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_RefTitleDouble)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_RefTitleParens)
- break if _tmp
- self.pos = _save
- _tmp = apply(:_EmptyTitle)
- break if _tmp
- self.pos = _save
- break
- end # end choice
-
- set_failed_rule :_RefTitle unless _tmp
- return _tmp
- end
-
- # EmptyTitle = ""
- def _EmptyTitle
- _tmp = match_string("")
- set_failed_rule :_EmptyTitle unless _tmp
- return _tmp
- end
-
- # RefTitleSingle = Spnl "'" < (!("'" @Sp @Newline | @Newline) .)* > "'" { text }
- def _RefTitleSingle
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("'")
- unless _tmp
- self.pos = _save
- break
- end
- _text_start = self.pos
- while true
-
- _save2 = self.pos
- while true # sequence
- _save3 = self.pos
-
- _save4 = self.pos
- while true # choice
-
- _save5 = self.pos
- while true # sequence
- _tmp = match_string("'")
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = _Newline()
- unless _tmp
- self.pos = _save5
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save4
- _tmp = _Newline()
- break if _tmp
- self.pos = _save4
- break
- end # end choice
-
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("'")
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; text ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_RefTitleSingle unless _tmp
- return _tmp
- end
-
- # RefTitleDouble = Spnl "\"" < (!("\"" @Sp @Newline | @Newline) .)* > "\"" { text }
- def _RefTitleDouble
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("\"")
- unless _tmp
- self.pos = _save
- break
- end
- _text_start = self.pos
- while true
-
- _save2 = self.pos
- while true # sequence
- _save3 = self.pos
-
- _save4 = self.pos
- while true # choice
-
- _save5 = self.pos
- while true # sequence
- _tmp = match_string("\"")
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = _Newline()
- unless _tmp
- self.pos = _save5
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save4
- _tmp = _Newline()
- break if _tmp
- self.pos = _save4
- break
- end # end choice
-
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("\"")
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; text ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_RefTitleDouble unless _tmp
- return _tmp
- end
-
- # RefTitleParens = Spnl "(" < (!(")" @Sp @Newline | @Newline) .)* > ")" { text }
- def _RefTitleParens
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("(")
- unless _tmp
- self.pos = _save
- break
- end
- _text_start = self.pos
- while true
-
- _save2 = self.pos
- while true # sequence
- _save3 = self.pos
-
- _save4 = self.pos
- while true # choice
-
- _save5 = self.pos
- while true # sequence
- _tmp = match_string(")")
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = _Newline()
- unless _tmp
- self.pos = _save5
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save4
- _tmp = _Newline()
- break if _tmp
- self.pos = _save4
- break
- end # end choice
-
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(")")
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; text ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_RefTitleParens unless _tmp
- return _tmp
- end
-
- # References = (Reference | SkipBlock)*
- def _References
- while true
-
- _save1 = self.pos
- while true # choice
- _tmp = apply(:_Reference)
- break if _tmp
- self.pos = _save1
- _tmp = apply(:_SkipBlock)
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- set_failed_rule :_References unless _tmp
- return _tmp
- end
-
- # Ticks1 = "`" !"`"
- def _Ticks1
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("`")
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Ticks1 unless _tmp
- return _tmp
- end
-
- # Ticks2 = "``" !"`"
- def _Ticks2
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("``")
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Ticks2 unless _tmp
- return _tmp
- end
-
- # Ticks3 = "```" !"`"
- def _Ticks3
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("```")
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Ticks3 unless _tmp
- return _tmp
- end
-
- # Ticks4 = "````" !"`"
- def _Ticks4
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("````")
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Ticks4 unless _tmp
- return _tmp
- end
-
- # Ticks5 = "`````" !"`"
- def _Ticks5
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("`````")
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Ticks5 unless _tmp
- return _tmp
- end
-
- # Code = (Ticks1 @Sp < ((!"`" Nonspacechar)+ | !Ticks1 /`+/ | !(@Sp Ticks1) (@Spacechar | @Newline !@BlankLine))+ > @Sp Ticks1 | Ticks2 @Sp < ((!"`" Nonspacechar)+ | !Ticks2 /`+/ | !(@Sp Ticks2) (@Spacechar | @Newline !@BlankLine))+ > @Sp Ticks2 | Ticks3 @Sp < ((!"`" Nonspacechar)+ | !Ticks3 /`+/ | !(@Sp Ticks3) (@Spacechar | @Newline !@BlankLine))+ > @Sp Ticks3 | Ticks4 @Sp < ((!"`" Nonspacechar)+ | !Ticks4 /`+/ | !(@Sp Ticks4) (@Spacechar | @Newline !@BlankLine))+ > @Sp Ticks4 | Ticks5 @Sp < ((!"`" Nonspacechar)+ | !Ticks5 /`+/ | !(@Sp Ticks5) (@Spacechar | @Newline !@BlankLine))+ > @Sp Ticks5) { "<code>#{text}</code>" }
- def _Code
-
- _save = self.pos
- while true # sequence
-
- _save1 = self.pos
- while true # choice
-
- _save2 = self.pos
- while true # sequence
- _tmp = apply(:_Ticks1)
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save2
- break
- end
- _text_start = self.pos
- _save3 = self.pos
-
- _save4 = self.pos
- while true # choice
- _save5 = self.pos
-
- _save6 = self.pos
- while true # sequence
- _save7 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save7
- unless _tmp
- self.pos = _save6
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save6
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save8 = self.pos
- while true # sequence
- _save9 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save9
- unless _tmp
- self.pos = _save8
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save8
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save5
- end
- break if _tmp
- self.pos = _save4
-
- _save10 = self.pos
- while true # sequence
- _save11 = self.pos
- _tmp = apply(:_Ticks1)
- _tmp = _tmp ? nil : true
- self.pos = _save11
- unless _tmp
- self.pos = _save10
- break
- end
- _tmp = scan(/\A(?-mix:`+)/)
- unless _tmp
- self.pos = _save10
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save4
-
- _save12 = self.pos
- while true # sequence
- _save13 = self.pos
-
- _save14 = self.pos
- while true # sequence
- _tmp = _Sp()
- unless _tmp
- self.pos = _save14
- break
- end
- _tmp = apply(:_Ticks1)
- unless _tmp
- self.pos = _save14
- end
- break
- end # end sequence
-
- _tmp = _tmp ? nil : true
- self.pos = _save13
- unless _tmp
- self.pos = _save12
- break
- end
-
- _save15 = self.pos
- while true # choice
- _tmp = _Spacechar()
- break if _tmp
- self.pos = _save15
-
- _save16 = self.pos
- while true # sequence
- _tmp = _Newline()
- unless _tmp
- self.pos = _save16
- break
- end
- _save17 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save17
- unless _tmp
- self.pos = _save16
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save15
- break
- end # end choice
-
- unless _tmp
- self.pos = _save12
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save4
- break
- end # end choice
-
- if _tmp
- while true
-
- _save18 = self.pos
- while true # choice
- _save19 = self.pos
-
- _save20 = self.pos
- while true # sequence
- _save21 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save21
- unless _tmp
- self.pos = _save20
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save20
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save22 = self.pos
- while true # sequence
- _save23 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save23
- unless _tmp
- self.pos = _save22
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save22
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save19
- end
- break if _tmp
- self.pos = _save18
-
- _save24 = self.pos
- while true # sequence
- _save25 = self.pos
- _tmp = apply(:_Ticks1)
- _tmp = _tmp ? nil : true
- self.pos = _save25
- unless _tmp
- self.pos = _save24
- break
- end
- _tmp = scan(/\A(?-mix:`+)/)
- unless _tmp
- self.pos = _save24
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save18
-
- _save26 = self.pos
- while true # sequence
- _save27 = self.pos
-
- _save28 = self.pos
- while true # sequence
- _tmp = _Sp()
- unless _tmp
- self.pos = _save28
- break
- end
- _tmp = apply(:_Ticks1)
- unless _tmp
- self.pos = _save28
- end
- break
- end # end sequence
-
- _tmp = _tmp ? nil : true
- self.pos = _save27
- unless _tmp
- self.pos = _save26
- break
- end
-
- _save29 = self.pos
- while true # choice
- _tmp = _Spacechar()
- break if _tmp
- self.pos = _save29
-
- _save30 = self.pos
- while true # sequence
- _tmp = _Newline()
- unless _tmp
- self.pos = _save30
- break
- end
- _save31 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save31
- unless _tmp
- self.pos = _save30
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save29
- break
- end # end choice
-
- unless _tmp
- self.pos = _save26
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save18
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save3
- end
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = apply(:_Ticks1)
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save1
-
- _save32 = self.pos
- while true # sequence
- _tmp = apply(:_Ticks2)
- unless _tmp
- self.pos = _save32
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save32
- break
- end
- _text_start = self.pos
- _save33 = self.pos
-
- _save34 = self.pos
- while true # choice
- _save35 = self.pos
-
- _save36 = self.pos
- while true # sequence
- _save37 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save37
- unless _tmp
- self.pos = _save36
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save36
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save38 = self.pos
- while true # sequence
- _save39 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save39
- unless _tmp
- self.pos = _save38
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save38
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save35
- end
- break if _tmp
- self.pos = _save34
-
- _save40 = self.pos
- while true # sequence
- _save41 = self.pos
- _tmp = apply(:_Ticks2)
- _tmp = _tmp ? nil : true
- self.pos = _save41
- unless _tmp
- self.pos = _save40
- break
- end
- _tmp = scan(/\A(?-mix:`+)/)
- unless _tmp
- self.pos = _save40
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save34
-
- _save42 = self.pos
- while true # sequence
- _save43 = self.pos
-
- _save44 = self.pos
- while true # sequence
- _tmp = _Sp()
- unless _tmp
- self.pos = _save44
- break
- end
- _tmp = apply(:_Ticks2)
- unless _tmp
- self.pos = _save44
- end
- break
- end # end sequence
-
- _tmp = _tmp ? nil : true
- self.pos = _save43
- unless _tmp
- self.pos = _save42
- break
- end
-
- _save45 = self.pos
- while true # choice
- _tmp = _Spacechar()
- break if _tmp
- self.pos = _save45
-
- _save46 = self.pos
- while true # sequence
- _tmp = _Newline()
- unless _tmp
- self.pos = _save46
- break
- end
- _save47 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save47
- unless _tmp
- self.pos = _save46
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save45
- break
- end # end choice
-
- unless _tmp
- self.pos = _save42
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save34
- break
- end # end choice
-
- if _tmp
- while true
-
- _save48 = self.pos
- while true # choice
- _save49 = self.pos
-
- _save50 = self.pos
- while true # sequence
- _save51 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save51
- unless _tmp
- self.pos = _save50
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save50
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save52 = self.pos
- while true # sequence
- _save53 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save53
- unless _tmp
- self.pos = _save52
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save52
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save49
- end
- break if _tmp
- self.pos = _save48
-
- _save54 = self.pos
- while true # sequence
- _save55 = self.pos
- _tmp = apply(:_Ticks2)
- _tmp = _tmp ? nil : true
- self.pos = _save55
- unless _tmp
- self.pos = _save54
- break
- end
- _tmp = scan(/\A(?-mix:`+)/)
- unless _tmp
- self.pos = _save54
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save48
-
- _save56 = self.pos
- while true # sequence
- _save57 = self.pos
-
- _save58 = self.pos
- while true # sequence
- _tmp = _Sp()
- unless _tmp
- self.pos = _save58
- break
- end
- _tmp = apply(:_Ticks2)
- unless _tmp
- self.pos = _save58
- end
- break
- end # end sequence
-
- _tmp = _tmp ? nil : true
- self.pos = _save57
- unless _tmp
- self.pos = _save56
- break
- end
-
- _save59 = self.pos
- while true # choice
- _tmp = _Spacechar()
- break if _tmp
- self.pos = _save59
-
- _save60 = self.pos
- while true # sequence
- _tmp = _Newline()
- unless _tmp
- self.pos = _save60
- break
- end
- _save61 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save61
- unless _tmp
- self.pos = _save60
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save59
- break
- end # end choice
-
- unless _tmp
- self.pos = _save56
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save48
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save33
- end
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save32
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save32
- break
- end
- _tmp = apply(:_Ticks2)
- unless _tmp
- self.pos = _save32
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save1
-
- _save62 = self.pos
- while true # sequence
- _tmp = apply(:_Ticks3)
- unless _tmp
- self.pos = _save62
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save62
- break
- end
- _text_start = self.pos
- _save63 = self.pos
-
- _save64 = self.pos
- while true # choice
- _save65 = self.pos
-
- _save66 = self.pos
- while true # sequence
- _save67 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save67
- unless _tmp
- self.pos = _save66
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save66
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save68 = self.pos
- while true # sequence
- _save69 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save69
- unless _tmp
- self.pos = _save68
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save68
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save65
- end
- break if _tmp
- self.pos = _save64
-
- _save70 = self.pos
- while true # sequence
- _save71 = self.pos
- _tmp = apply(:_Ticks3)
- _tmp = _tmp ? nil : true
- self.pos = _save71
- unless _tmp
- self.pos = _save70
- break
- end
- _tmp = scan(/\A(?-mix:`+)/)
- unless _tmp
- self.pos = _save70
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save64
-
- _save72 = self.pos
- while true # sequence
- _save73 = self.pos
-
- _save74 = self.pos
- while true # sequence
- _tmp = _Sp()
- unless _tmp
- self.pos = _save74
- break
- end
- _tmp = apply(:_Ticks3)
- unless _tmp
- self.pos = _save74
- end
- break
- end # end sequence
-
- _tmp = _tmp ? nil : true
- self.pos = _save73
- unless _tmp
- self.pos = _save72
- break
- end
-
- _save75 = self.pos
- while true # choice
- _tmp = _Spacechar()
- break if _tmp
- self.pos = _save75
-
- _save76 = self.pos
- while true # sequence
- _tmp = _Newline()
- unless _tmp
- self.pos = _save76
- break
- end
- _save77 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save77
- unless _tmp
- self.pos = _save76
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save75
- break
- end # end choice
-
- unless _tmp
- self.pos = _save72
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save64
- break
- end # end choice
-
- if _tmp
- while true
-
- _save78 = self.pos
- while true # choice
- _save79 = self.pos
-
- _save80 = self.pos
- while true # sequence
- _save81 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save81
- unless _tmp
- self.pos = _save80
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save80
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save82 = self.pos
- while true # sequence
- _save83 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save83
- unless _tmp
- self.pos = _save82
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save82
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save79
- end
- break if _tmp
- self.pos = _save78
-
- _save84 = self.pos
- while true # sequence
- _save85 = self.pos
- _tmp = apply(:_Ticks3)
- _tmp = _tmp ? nil : true
- self.pos = _save85
- unless _tmp
- self.pos = _save84
- break
- end
- _tmp = scan(/\A(?-mix:`+)/)
- unless _tmp
- self.pos = _save84
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save78
-
- _save86 = self.pos
- while true # sequence
- _save87 = self.pos
-
- _save88 = self.pos
- while true # sequence
- _tmp = _Sp()
- unless _tmp
- self.pos = _save88
- break
- end
- _tmp = apply(:_Ticks3)
- unless _tmp
- self.pos = _save88
- end
- break
- end # end sequence
-
- _tmp = _tmp ? nil : true
- self.pos = _save87
- unless _tmp
- self.pos = _save86
- break
- end
-
- _save89 = self.pos
- while true # choice
- _tmp = _Spacechar()
- break if _tmp
- self.pos = _save89
-
- _save90 = self.pos
- while true # sequence
- _tmp = _Newline()
- unless _tmp
- self.pos = _save90
- break
- end
- _save91 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save91
- unless _tmp
- self.pos = _save90
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save89
- break
- end # end choice
-
- unless _tmp
- self.pos = _save86
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save78
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save63
- end
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save62
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save62
- break
- end
- _tmp = apply(:_Ticks3)
- unless _tmp
- self.pos = _save62
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save1
-
- _save92 = self.pos
- while true # sequence
- _tmp = apply(:_Ticks4)
- unless _tmp
- self.pos = _save92
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save92
- break
- end
- _text_start = self.pos
- _save93 = self.pos
-
- _save94 = self.pos
- while true # choice
- _save95 = self.pos
-
- _save96 = self.pos
- while true # sequence
- _save97 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save97
- unless _tmp
- self.pos = _save96
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save96
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save98 = self.pos
- while true # sequence
- _save99 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save99
- unless _tmp
- self.pos = _save98
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save98
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save95
- end
- break if _tmp
- self.pos = _save94
-
- _save100 = self.pos
- while true # sequence
- _save101 = self.pos
- _tmp = apply(:_Ticks4)
- _tmp = _tmp ? nil : true
- self.pos = _save101
- unless _tmp
- self.pos = _save100
- break
- end
- _tmp = scan(/\A(?-mix:`+)/)
- unless _tmp
- self.pos = _save100
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save94
-
- _save102 = self.pos
- while true # sequence
- _save103 = self.pos
-
- _save104 = self.pos
- while true # sequence
- _tmp = _Sp()
- unless _tmp
- self.pos = _save104
- break
- end
- _tmp = apply(:_Ticks4)
- unless _tmp
- self.pos = _save104
- end
- break
- end # end sequence
-
- _tmp = _tmp ? nil : true
- self.pos = _save103
- unless _tmp
- self.pos = _save102
- break
- end
-
- _save105 = self.pos
- while true # choice
- _tmp = _Spacechar()
- break if _tmp
- self.pos = _save105
-
- _save106 = self.pos
- while true # sequence
- _tmp = _Newline()
- unless _tmp
- self.pos = _save106
- break
- end
- _save107 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save107
- unless _tmp
- self.pos = _save106
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save105
- break
- end # end choice
-
- unless _tmp
- self.pos = _save102
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save94
- break
- end # end choice
-
- if _tmp
- while true
-
- _save108 = self.pos
- while true # choice
- _save109 = self.pos
-
- _save110 = self.pos
- while true # sequence
- _save111 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save111
- unless _tmp
- self.pos = _save110
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save110
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save112 = self.pos
- while true # sequence
- _save113 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save113
- unless _tmp
- self.pos = _save112
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save112
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save109
- end
- break if _tmp
- self.pos = _save108
-
- _save114 = self.pos
- while true # sequence
- _save115 = self.pos
- _tmp = apply(:_Ticks4)
- _tmp = _tmp ? nil : true
- self.pos = _save115
- unless _tmp
- self.pos = _save114
- break
- end
- _tmp = scan(/\A(?-mix:`+)/)
- unless _tmp
- self.pos = _save114
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save108
-
- _save116 = self.pos
- while true # sequence
- _save117 = self.pos
-
- _save118 = self.pos
- while true # sequence
- _tmp = _Sp()
- unless _tmp
- self.pos = _save118
- break
- end
- _tmp = apply(:_Ticks4)
- unless _tmp
- self.pos = _save118
- end
- break
- end # end sequence
-
- _tmp = _tmp ? nil : true
- self.pos = _save117
- unless _tmp
- self.pos = _save116
- break
- end
-
- _save119 = self.pos
- while true # choice
- _tmp = _Spacechar()
- break if _tmp
- self.pos = _save119
-
- _save120 = self.pos
- while true # sequence
- _tmp = _Newline()
- unless _tmp
- self.pos = _save120
- break
- end
- _save121 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save121
- unless _tmp
- self.pos = _save120
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save119
- break
- end # end choice
-
- unless _tmp
- self.pos = _save116
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save108
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save93
- end
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save92
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save92
- break
- end
- _tmp = apply(:_Ticks4)
- unless _tmp
- self.pos = _save92
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save1
-
- _save122 = self.pos
- while true # sequence
- _tmp = apply(:_Ticks5)
- unless _tmp
- self.pos = _save122
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save122
- break
- end
- _text_start = self.pos
- _save123 = self.pos
-
- _save124 = self.pos
- while true # choice
- _save125 = self.pos
-
- _save126 = self.pos
- while true # sequence
- _save127 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save127
- unless _tmp
- self.pos = _save126
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save126
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save128 = self.pos
- while true # sequence
- _save129 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save129
- unless _tmp
- self.pos = _save128
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save128
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save125
- end
- break if _tmp
- self.pos = _save124
-
- _save130 = self.pos
- while true # sequence
- _save131 = self.pos
- _tmp = apply(:_Ticks5)
- _tmp = _tmp ? nil : true
- self.pos = _save131
- unless _tmp
- self.pos = _save130
- break
- end
- _tmp = scan(/\A(?-mix:`+)/)
- unless _tmp
- self.pos = _save130
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save124
-
- _save132 = self.pos
- while true # sequence
- _save133 = self.pos
-
- _save134 = self.pos
- while true # sequence
- _tmp = _Sp()
- unless _tmp
- self.pos = _save134
- break
- end
- _tmp = apply(:_Ticks5)
- unless _tmp
- self.pos = _save134
- end
- break
- end # end sequence
-
- _tmp = _tmp ? nil : true
- self.pos = _save133
- unless _tmp
- self.pos = _save132
- break
- end
-
- _save135 = self.pos
- while true # choice
- _tmp = _Spacechar()
- break if _tmp
- self.pos = _save135
-
- _save136 = self.pos
- while true # sequence
- _tmp = _Newline()
- unless _tmp
- self.pos = _save136
- break
- end
- _save137 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save137
- unless _tmp
- self.pos = _save136
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save135
- break
- end # end choice
-
- unless _tmp
- self.pos = _save132
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save124
- break
- end # end choice
-
- if _tmp
- while true
-
- _save138 = self.pos
- while true # choice
- _save139 = self.pos
-
- _save140 = self.pos
- while true # sequence
- _save141 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save141
- unless _tmp
- self.pos = _save140
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save140
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save142 = self.pos
- while true # sequence
- _save143 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save143
- unless _tmp
- self.pos = _save142
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save142
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save139
- end
- break if _tmp
- self.pos = _save138
-
- _save144 = self.pos
- while true # sequence
- _save145 = self.pos
- _tmp = apply(:_Ticks5)
- _tmp = _tmp ? nil : true
- self.pos = _save145
- unless _tmp
- self.pos = _save144
- break
- end
- _tmp = scan(/\A(?-mix:`+)/)
- unless _tmp
- self.pos = _save144
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save138
-
- _save146 = self.pos
- while true # sequence
- _save147 = self.pos
-
- _save148 = self.pos
- while true # sequence
- _tmp = _Sp()
- unless _tmp
- self.pos = _save148
- break
- end
- _tmp = apply(:_Ticks5)
- unless _tmp
- self.pos = _save148
- end
- break
- end # end sequence
-
- _tmp = _tmp ? nil : true
- self.pos = _save147
- unless _tmp
- self.pos = _save146
- break
- end
-
- _save149 = self.pos
- while true # choice
- _tmp = _Spacechar()
- break if _tmp
- self.pos = _save149
-
- _save150 = self.pos
- while true # sequence
- _tmp = _Newline()
- unless _tmp
- self.pos = _save150
- break
- end
- _save151 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save151
- unless _tmp
- self.pos = _save150
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save149
- break
- end # end choice
-
- unless _tmp
- self.pos = _save146
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save138
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save123
- end
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save122
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save122
- break
- end
- _tmp = apply(:_Ticks5)
- unless _tmp
- self.pos = _save122
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; "<code>#{text}</code>" ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Code unless _tmp
- return _tmp
- end
-
- # RawHtml = < (HtmlComment | HtmlBlockScript | HtmlTag) > { if html? then text else '' end }
- def _RawHtml
-
- _save = self.pos
- while true # sequence
- _text_start = self.pos
-
- _save1 = self.pos
- while true # choice
- _tmp = apply(:_HtmlComment)
- break if _tmp
- self.pos = _save1
- _tmp = apply(:_HtmlBlockScript)
- break if _tmp
- self.pos = _save1
- _tmp = apply(:_HtmlTag)
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; if html? then text else '' end ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_RawHtml unless _tmp
- return _tmp
- end
-
- # BlankLine = @Sp @Newline { "\n" }
- def _BlankLine
-
- _save = self.pos
- while true # sequence
- _tmp = _Sp()
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _Newline()
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; "\n" ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_BlankLine unless _tmp
- return _tmp
- end
-
- # Quoted = ("\"" (!"\"" .)* "\"" | "'" (!"'" .)* "'")
- def _Quoted
-
- _save = self.pos
- while true # choice
-
- _save1 = self.pos
- while true # sequence
- _tmp = match_string("\"")
- unless _tmp
- self.pos = _save1
- break
- end
- while true
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = match_string("\"")
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save1
- break
- end
- _tmp = match_string("\"")
- unless _tmp
- self.pos = _save1
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save
-
- _save5 = self.pos
- while true # sequence
- _tmp = match_string("'")
- unless _tmp
- self.pos = _save5
- break
- end
- while true
-
- _save7 = self.pos
- while true # sequence
- _save8 = self.pos
- _tmp = match_string("'")
- _tmp = _tmp ? nil : true
- self.pos = _save8
- unless _tmp
- self.pos = _save7
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save7
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = match_string("'")
- unless _tmp
- self.pos = _save5
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save
- break
- end # end choice
-
- set_failed_rule :_Quoted unless _tmp
- return _tmp
- end
-
- # HtmlAttribute = (AlphanumericAscii | "-")+ Spnl ("=" Spnl (Quoted | (!">" Nonspacechar)+))? Spnl
- def _HtmlAttribute
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
-
- _save2 = self.pos
- while true # choice
- _tmp = apply(:_AlphanumericAscii)
- break if _tmp
- self.pos = _save2
- _tmp = match_string("-")
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- if _tmp
- while true
-
- _save3 = self.pos
- while true # choice
- _tmp = apply(:_AlphanumericAscii)
- break if _tmp
- self.pos = _save3
- _tmp = match_string("-")
- break if _tmp
- self.pos = _save3
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save1
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _save4 = self.pos
-
- _save5 = self.pos
- while true # sequence
- _tmp = match_string("=")
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save5
- break
- end
-
- _save6 = self.pos
- while true # choice
- _tmp = apply(:_Quoted)
- break if _tmp
- self.pos = _save6
- _save7 = self.pos
-
- _save8 = self.pos
- while true # sequence
- _save9 = self.pos
- _tmp = match_string(">")
- _tmp = _tmp ? nil : true
- self.pos = _save9
- unless _tmp
- self.pos = _save8
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save8
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save10 = self.pos
- while true # sequence
- _save11 = self.pos
- _tmp = match_string(">")
- _tmp = _tmp ? nil : true
- self.pos = _save11
- unless _tmp
- self.pos = _save10
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save10
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save7
- end
- break if _tmp
- self.pos = _save6
- break
- end # end choice
-
- unless _tmp
- self.pos = _save5
- end
- break
- end # end sequence
-
- unless _tmp
- _tmp = true
- self.pos = _save4
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlAttribute unless _tmp
- return _tmp
- end
-
- # HtmlComment = "<!--" (!"-->" .)* "-->"
- def _HtmlComment
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<!--")
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save2 = self.pos
- while true # sequence
- _save3 = self.pos
- _tmp = match_string("-->")
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("-->")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlComment unless _tmp
- return _tmp
- end
-
- # HtmlTag = "<" Spnl "/"? AlphanumericAscii+ Spnl HtmlAttribute* "/"? Spnl ">"
- def _HtmlTag
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("<")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
- _tmp = match_string("/")
- unless _tmp
- _tmp = true
- self.pos = _save1
- end
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _tmp = apply(:_AlphanumericAscii)
- if _tmp
- while true
- _tmp = apply(:_AlphanumericAscii)
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save2
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = apply(:_HtmlAttribute)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- _save4 = self.pos
- _tmp = match_string("/")
- unless _tmp
- _tmp = true
- self.pos = _save4
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(">")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HtmlTag unless _tmp
- return _tmp
- end
-
- # Eof = !.
- def _Eof
- _save = self.pos
- _tmp = get_byte
- _tmp = _tmp ? nil : true
- self.pos = _save
- set_failed_rule :_Eof unless _tmp
- return _tmp
- end
-
- # Nonspacechar = !@Spacechar !@Newline .
- def _Nonspacechar
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = _Spacechar()
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _tmp = _Newline()
- _tmp = _tmp ? nil : true
- self.pos = _save2
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Nonspacechar unless _tmp
- return _tmp
- end
-
- # Sp = @Spacechar*
- def _Sp
- while true
- _tmp = _Spacechar()
- break unless _tmp
- end
- _tmp = true
- set_failed_rule :_Sp unless _tmp
- return _tmp
- end
-
- # Spnl = @Sp (@Newline @Sp)?
- def _Spnl
-
- _save = self.pos
- while true # sequence
- _tmp = _Sp()
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
-
- _save2 = self.pos
- while true # sequence
- _tmp = _Newline()
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- unless _tmp
- _tmp = true
- self.pos = _save1
- end
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Spnl unless _tmp
- return _tmp
- end
-
- # SpecialChar = (/[*_`&\[\]()<!#\\'"]/ | @ExtendedSpecialChar)
- def _SpecialChar
-
- _save = self.pos
- while true # choice
- _tmp = scan(/\A(?-mix:[*_`&\[\]()<!#\\'"])/)
- break if _tmp
- self.pos = _save
- _tmp = _ExtendedSpecialChar()
- break if _tmp
- self.pos = _save
- break
- end # end choice
-
- set_failed_rule :_SpecialChar unless _tmp
- return _tmp
- end
-
- # NormalChar = !(@SpecialChar | @Spacechar | @Newline) .
- def _NormalChar
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
-
- _save2 = self.pos
- while true # choice
- _tmp = _SpecialChar()
- break if _tmp
- self.pos = _save2
- _tmp = _Spacechar()
- break if _tmp
- self.pos = _save2
- _tmp = _Newline()
- break if _tmp
- self.pos = _save2
- break
- end # end choice
-
- _tmp = _tmp ? nil : true
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_NormalChar unless _tmp
- return _tmp
- end
-
- # Digit = [0-9]
- def _Digit
- _save = self.pos
- _tmp = get_byte
- if _tmp
- unless _tmp >= 48 and _tmp <= 57
- self.pos = _save
- _tmp = nil
- end
- end
- set_failed_rule :_Digit unless _tmp
- return _tmp
- end
-
- # Alphanumeric = %literals.Alphanumeric
- def _Alphanumeric
- _tmp = @_grammar_literals.external_invoke(self, :_Alphanumeric)
- set_failed_rule :_Alphanumeric unless _tmp
- return _tmp
- end
-
- # AlphanumericAscii = %literals.AlphanumericAscii
- def _AlphanumericAscii
- _tmp = @_grammar_literals.external_invoke(self, :_AlphanumericAscii)
- set_failed_rule :_AlphanumericAscii unless _tmp
- return _tmp
- end
-
- # BOM = %literals.BOM
- def _BOM
- _tmp = @_grammar_literals.external_invoke(self, :_BOM)
- set_failed_rule :_BOM unless _tmp
- return _tmp
- end
-
- # Newline = %literals.Newline
- def _Newline
- _tmp = @_grammar_literals.external_invoke(self, :_Newline)
- set_failed_rule :_Newline unless _tmp
- return _tmp
- end
-
- # NonAlphanumeric = %literals.NonAlphanumeric
- def _NonAlphanumeric
- _tmp = @_grammar_literals.external_invoke(self, :_NonAlphanumeric)
- set_failed_rule :_NonAlphanumeric unless _tmp
- return _tmp
- end
-
- # Spacechar = %literals.Spacechar
- def _Spacechar
- _tmp = @_grammar_literals.external_invoke(self, :_Spacechar)
- set_failed_rule :_Spacechar unless _tmp
- return _tmp
- end
-
- # HexEntity = /&#x/i < /[0-9a-fA-F]+/ > ";" { [text.to_i(16)].pack 'U' }
- def _HexEntity
-
- _save = self.pos
- while true # sequence
- _tmp = scan(/\A(?i-mx:&#x)/)
- unless _tmp
- self.pos = _save
- break
- end
- _text_start = self.pos
- _tmp = scan(/\A(?-mix:[0-9a-fA-F]+)/)
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(";")
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; [text.to_i(16)].pack 'U' ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_HexEntity unless _tmp
- return _tmp
- end
-
- # DecEntity = "&#" < /[0-9]+/ > ";" { [text.to_i].pack 'U' }
- def _DecEntity
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("&#")
- unless _tmp
- self.pos = _save
- break
- end
- _text_start = self.pos
- _tmp = scan(/\A(?-mix:[0-9]+)/)
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(";")
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; [text.to_i].pack 'U' ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_DecEntity unless _tmp
- return _tmp
- end
-
- # CharEntity = "&" < /[A-Za-z0-9]+/ > ";" { if entity = HTML_ENTITIES[text] then entity.pack 'U*' else "&#{text};" end }
- def _CharEntity
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("&")
- unless _tmp
- self.pos = _save
- break
- end
- _text_start = self.pos
- _tmp = scan(/\A(?-mix:[A-Za-z0-9]+)/)
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(";")
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; if entity = HTML_ENTITIES[text] then
- entity.pack 'U*'
- else
- "&#{text};"
- end
- ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_CharEntity unless _tmp
- return _tmp
- end
-
- # NonindentSpace = / {0,3}/
- def _NonindentSpace
- _tmp = scan(/\A(?-mix: {0,3})/)
- set_failed_rule :_NonindentSpace unless _tmp
- return _tmp
- end
-
- # Indent = /\t| /
- def _Indent
- _tmp = scan(/\A(?-mix:\t| )/)
- set_failed_rule :_Indent unless _tmp
- return _tmp
- end
-
- # IndentedLine = Indent Line
- def _IndentedLine
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_Indent)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Line)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_IndentedLine unless _tmp
- return _tmp
- end
-
- # OptionallyIndentedLine = Indent? Line
- def _OptionallyIndentedLine
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = apply(:_Indent)
- unless _tmp
- _tmp = true
- self.pos = _save1
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Line)
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_OptionallyIndentedLine unless _tmp
- return _tmp
- end
-
- # StartList = &. { [] }
- def _StartList
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = get_byte
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; [] ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_StartList unless _tmp
- return _tmp
- end
-
- # Line = @RawLine:a { a }
- def _Line
-
- _save = self.pos
- while true # sequence
- _tmp = _RawLine()
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Line unless _tmp
- return _tmp
- end
-
- # RawLine = (< (!"\r" !"\n" .)* @Newline > | < .+ > @Eof) { text }
- def _RawLine
-
- _save = self.pos
- while true # sequence
-
- _save1 = self.pos
- while true # choice
- _text_start = self.pos
-
- _save2 = self.pos
- while true # sequence
- while true
-
- _save4 = self.pos
- while true # sequence
- _save5 = self.pos
- _tmp = match_string("\r")
- _tmp = _tmp ? nil : true
- self.pos = _save5
- unless _tmp
- self.pos = _save4
- break
- end
- _save6 = self.pos
- _tmp = match_string("\n")
- _tmp = _tmp ? nil : true
- self.pos = _save6
- unless _tmp
- self.pos = _save4
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save4
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = _Newline()
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- if _tmp
- text = get_text(_text_start)
- end
- break if _tmp
- self.pos = _save1
-
- _save7 = self.pos
- while true # sequence
- _text_start = self.pos
- _save8 = self.pos
- _tmp = get_byte
- if _tmp
- while true
- _tmp = get_byte
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save8
- end
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save7
- break
- end
- _tmp = _Eof()
- unless _tmp
- self.pos = _save7
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; text ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_RawLine unless _tmp
- return _tmp
- end
-
- # SkipBlock = (HtmlBlock | (!"#" !SetextBottom1 !SetextBottom2 !@BlankLine @RawLine)+ @BlankLine* | @BlankLine+ | @RawLine)
- def _SkipBlock
-
- _save = self.pos
- while true # choice
- _tmp = apply(:_HtmlBlock)
- break if _tmp
- self.pos = _save
-
- _save1 = self.pos
- while true # sequence
- _save2 = self.pos
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = match_string("#")
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _save5 = self.pos
- _tmp = apply(:_SetextBottom1)
- _tmp = _tmp ? nil : true
- self.pos = _save5
- unless _tmp
- self.pos = _save3
- break
- end
- _save6 = self.pos
- _tmp = apply(:_SetextBottom2)
- _tmp = _tmp ? nil : true
- self.pos = _save6
- unless _tmp
- self.pos = _save3
- break
- end
- _save7 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save7
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = _RawLine()
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save8 = self.pos
- while true # sequence
- _save9 = self.pos
- _tmp = match_string("#")
- _tmp = _tmp ? nil : true
- self.pos = _save9
- unless _tmp
- self.pos = _save8
- break
- end
- _save10 = self.pos
- _tmp = apply(:_SetextBottom1)
- _tmp = _tmp ? nil : true
- self.pos = _save10
- unless _tmp
- self.pos = _save8
- break
- end
- _save11 = self.pos
- _tmp = apply(:_SetextBottom2)
- _tmp = _tmp ? nil : true
- self.pos = _save11
- unless _tmp
- self.pos = _save8
- break
- end
- _save12 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save12
- unless _tmp
- self.pos = _save8
- break
- end
- _tmp = _RawLine()
- unless _tmp
- self.pos = _save8
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save2
- end
- unless _tmp
- self.pos = _save1
- break
- end
- while true
- _tmp = _BlankLine()
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save1
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save
- _save14 = self.pos
- _tmp = _BlankLine()
- if _tmp
- while true
- _tmp = _BlankLine()
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save14
- end
- break if _tmp
- self.pos = _save
- _tmp = _RawLine()
- break if _tmp
- self.pos = _save
- break
- end # end choice
-
- set_failed_rule :_SkipBlock unless _tmp
- return _tmp
- end
-
- # ExtendedSpecialChar = &{ notes? } "^"
- def _ExtendedSpecialChar
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = begin; notes? ; end
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("^")
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_ExtendedSpecialChar unless _tmp
- return _tmp
- end
-
- # NoteReference = &{ notes? } RawNoteReference:ref { note_for ref }
- def _NoteReference
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = begin; notes? ; end
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_RawNoteReference)
- ref = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; note_for ref ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_NoteReference unless _tmp
- return _tmp
- end
-
- # RawNoteReference = "[^" < (!@Newline !"]" .)+ > "]" { text }
- def _RawNoteReference
-
- _save = self.pos
- while true # sequence
- _tmp = match_string("[^")
- unless _tmp
- self.pos = _save
- break
- end
- _text_start = self.pos
- _save1 = self.pos
-
- _save2 = self.pos
- while true # sequence
- _save3 = self.pos
- _tmp = _Newline()
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save2
- break
- end
- _save4 = self.pos
- _tmp = match_string("]")
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save5 = self.pos
- while true # sequence
- _save6 = self.pos
- _tmp = _Newline()
- _tmp = _tmp ? nil : true
- self.pos = _save6
- unless _tmp
- self.pos = _save5
- break
- end
- _save7 = self.pos
- _tmp = match_string("]")
- _tmp = _tmp ? nil : true
- self.pos = _save7
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = get_byte
- unless _tmp
- self.pos = _save5
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save1
- end
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("]")
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; text ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_RawNoteReference unless _tmp
- return _tmp
- end
-
- # Note = &{ notes? } @NonindentSpace RawNoteReference:ref ":" @Sp @StartList:a RawNoteBlock:i { a.concat i } (&Indent RawNoteBlock:i { a.concat i })* { @footnotes[ref] = paragraph a nil }
- def _Note
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = begin; notes? ; end
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _NonindentSpace()
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_RawNoteReference)
- ref = @result
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(":")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _StartList()
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_RawNoteBlock)
- i = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a.concat i ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- while true
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = apply(:_Indent)
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = apply(:_RawNoteBlock)
- i = @result
- unless _tmp
- self.pos = _save3
- break
- end
- @result = begin; a.concat i ; end
- _tmp = true
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; @footnotes[ref] = paragraph a
-
- nil
- ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_Note unless _tmp
- return _tmp
- end
-
- # InlineNote = &{ notes? } "^[" @StartList:a (!"]" Inline:l { a << l })+ "]" { ref = [:inline, @note_order.length] @footnotes[ref] = paragraph a note_for ref }
- def _InlineNote
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = begin; notes? ; end
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("^[")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _StartList()
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
-
- _save3 = self.pos
- while true # sequence
- _save4 = self.pos
- _tmp = match_string("]")
- _tmp = _tmp ? nil : true
- self.pos = _save4
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = apply(:_Inline)
- l = @result
- unless _tmp
- self.pos = _save3
- break
- end
- @result = begin; a << l ; end
- _tmp = true
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save5 = self.pos
- while true # sequence
- _save6 = self.pos
- _tmp = match_string("]")
- _tmp = _tmp ? nil : true
- self.pos = _save6
- unless _tmp
- self.pos = _save5
- break
- end
- _tmp = apply(:_Inline)
- l = @result
- unless _tmp
- self.pos = _save5
- break
- end
- @result = begin; a << l ; end
- _tmp = true
- unless _tmp
- self.pos = _save5
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save2
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string("]")
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin;
- ref = [:inline, @note_order.length]
- @footnotes[ref] = paragraph a
-
- note_for ref
- ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_InlineNote unless _tmp
- return _tmp
- end
-
- # Notes = (Note | SkipBlock)*
- def _Notes
- while true
-
- _save1 = self.pos
- while true # choice
- _tmp = apply(:_Note)
- break if _tmp
- self.pos = _save1
- _tmp = apply(:_SkipBlock)
- break if _tmp
- self.pos = _save1
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- set_failed_rule :_Notes unless _tmp
- return _tmp
- end
-
- # RawNoteBlock = @StartList:a (!@BlankLine OptionallyIndentedLine:l { a << l })+ < @BlankLine* > { a << text } { a }
- def _RawNoteBlock
-
- _save = self.pos
- while true # sequence
- _tmp = _StartList()
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
-
- _save2 = self.pos
- while true # sequence
- _save3 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save3
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = apply(:_OptionallyIndentedLine)
- l = @result
- unless _tmp
- self.pos = _save2
- break
- end
- @result = begin; a << l ; end
- _tmp = true
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save4 = self.pos
- while true # sequence
- _save5 = self.pos
- _tmp = _BlankLine()
- _tmp = _tmp ? nil : true
- self.pos = _save5
- unless _tmp
- self.pos = _save4
- break
- end
- _tmp = apply(:_OptionallyIndentedLine)
- l = @result
- unless _tmp
- self.pos = _save4
- break
- end
- @result = begin; a << l ; end
- _tmp = true
- unless _tmp
- self.pos = _save4
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save1
- end
- unless _tmp
- self.pos = _save
- break
- end
- _text_start = self.pos
- while true
- _tmp = _BlankLine()
- break unless _tmp
- end
- _tmp = true
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a << text ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; a ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_RawNoteBlock unless _tmp
- return _tmp
- end
-
- # CodeFence = &{ github? } Ticks3 (@Sp StrChunk:format)? Spnl < ((!"`" Nonspacechar)+ | !Ticks3 /`+/ | Spacechar | @Newline)+ > Ticks3 @Sp @Newline* { verbatim = RDoc::Markup::Verbatim.new text verbatim.format = format.intern if format verbatim }
- def _CodeFence
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = begin; github? ; end
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Ticks3)
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
-
- _save3 = self.pos
- while true # sequence
- _tmp = _Sp()
- unless _tmp
- self.pos = _save3
- break
- end
- _tmp = apply(:_StrChunk)
- format = @result
- unless _tmp
- self.pos = _save3
- end
- break
- end # end sequence
-
- unless _tmp
- _tmp = true
- self.pos = _save2
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Spnl)
- unless _tmp
- self.pos = _save
- break
- end
- _text_start = self.pos
- _save4 = self.pos
-
- _save5 = self.pos
- while true # choice
- _save6 = self.pos
-
- _save7 = self.pos
- while true # sequence
- _save8 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save8
- unless _tmp
- self.pos = _save7
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save7
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save9 = self.pos
- while true # sequence
- _save10 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save10
- unless _tmp
- self.pos = _save9
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save9
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save6
- end
- break if _tmp
- self.pos = _save5
-
- _save11 = self.pos
- while true # sequence
- _save12 = self.pos
- _tmp = apply(:_Ticks3)
- _tmp = _tmp ? nil : true
- self.pos = _save12
- unless _tmp
- self.pos = _save11
- break
- end
- _tmp = scan(/\A(?-mix:`+)/)
- unless _tmp
- self.pos = _save11
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save5
- _tmp = apply(:_Spacechar)
- break if _tmp
- self.pos = _save5
- _tmp = _Newline()
- break if _tmp
- self.pos = _save5
- break
- end # end choice
-
- if _tmp
- while true
-
- _save13 = self.pos
- while true # choice
- _save14 = self.pos
-
- _save15 = self.pos
- while true # sequence
- _save16 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save16
- unless _tmp
- self.pos = _save15
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save15
- end
- break
- end # end sequence
-
- if _tmp
- while true
-
- _save17 = self.pos
- while true # sequence
- _save18 = self.pos
- _tmp = match_string("`")
- _tmp = _tmp ? nil : true
- self.pos = _save18
- unless _tmp
- self.pos = _save17
- break
- end
- _tmp = apply(:_Nonspacechar)
- unless _tmp
- self.pos = _save17
- end
- break
- end # end sequence
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save14
- end
- break if _tmp
- self.pos = _save13
-
- _save19 = self.pos
- while true # sequence
- _save20 = self.pos
- _tmp = apply(:_Ticks3)
- _tmp = _tmp ? nil : true
- self.pos = _save20
- unless _tmp
- self.pos = _save19
- break
- end
- _tmp = scan(/\A(?-mix:`+)/)
- unless _tmp
- self.pos = _save19
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save13
- _tmp = apply(:_Spacechar)
- break if _tmp
- self.pos = _save13
- _tmp = _Newline()
- break if _tmp
- self.pos = _save13
- break
- end # end choice
-
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save4
- end
- if _tmp
- text = get_text(_text_start)
- end
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Ticks3)
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save
- break
- end
- while true
- _tmp = _Newline()
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; verbatim = RDoc::Markup::Verbatim.new text
- verbatim.format = format.intern if format
- verbatim
- ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_CodeFence unless _tmp
- return _tmp
- end
-
- # DefinitionList = &{ definition_lists? } DefinitionListItem+:list { RDoc::Markup::List.new :NOTE, *list.flatten }
- def _DefinitionList
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _tmp = begin; definition_lists? ; end
- self.pos = _save1
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _ary = []
- _tmp = apply(:_DefinitionListItem)
- if _tmp
- _ary << @result
- while true
- _tmp = apply(:_DefinitionListItem)
- _ary << @result if _tmp
- break unless _tmp
- end
- _tmp = true
- @result = _ary
- else
- self.pos = _save2
- end
- list = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; RDoc::Markup::List.new :NOTE, *list.flatten ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_DefinitionList unless _tmp
- return _tmp
- end
-
- # DefinitionListItem = DefinitionListLabel+:label DefinitionListDefinition+:defns { list_items = [] list_items << RDoc::Markup::ListItem.new(label, defns.shift) list_items.concat defns.map { |defn| RDoc::Markup::ListItem.new nil, defn } unless list_items.empty? list_items }
- def _DefinitionListItem
-
- _save = self.pos
- while true # sequence
- _save1 = self.pos
- _ary = []
- _tmp = apply(:_DefinitionListLabel)
- if _tmp
- _ary << @result
- while true
- _tmp = apply(:_DefinitionListLabel)
- _ary << @result if _tmp
- break unless _tmp
- end
- _tmp = true
- @result = _ary
- else
- self.pos = _save1
- end
- label = @result
- unless _tmp
- self.pos = _save
- break
- end
- _save2 = self.pos
- _ary = []
- _tmp = apply(:_DefinitionListDefinition)
- if _tmp
- _ary << @result
- while true
- _tmp = apply(:_DefinitionListDefinition)
- _ary << @result if _tmp
- break unless _tmp
- end
- _tmp = true
- @result = _ary
- else
- self.pos = _save2
- end
- defns = @result
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; list_items = []
- list_items <<
- RDoc::Markup::ListItem.new(label, defns.shift)
-
- list_items.concat defns.map { |defn|
- RDoc::Markup::ListItem.new nil, defn
- } unless list_items.empty?
-
- list_items
- ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_DefinitionListItem unless _tmp
- return _tmp
- end
-
- # DefinitionListLabel = StrChunk:label @Sp @Newline { label }
- def _DefinitionListLabel
-
- _save = self.pos
- while true # sequence
- _tmp = apply(:_StrChunk)
- label = @result
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _Sp()
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _Newline()
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; label ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_DefinitionListLabel unless _tmp
- return _tmp
- end
-
- # DefinitionListDefinition = @NonindentSpace ":" @Space Inlines:a @BlankLine+ { paragraph a }
- def _DefinitionListDefinition
-
- _save = self.pos
- while true # sequence
- _tmp = _NonindentSpace()
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = match_string(":")
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = _Space()
- unless _tmp
- self.pos = _save
- break
- end
- _tmp = apply(:_Inlines)
- a = @result
- unless _tmp
- self.pos = _save
- break
- end
- _save1 = self.pos
- _tmp = _BlankLine()
- if _tmp
- while true
- _tmp = _BlankLine()
- break unless _tmp
- end
- _tmp = true
- else
- self.pos = _save1
- end
- unless _tmp
- self.pos = _save
- break
- end
- @result = begin; paragraph a ; end
- _tmp = true
- unless _tmp
- self.pos = _save
- end
- break
- end # end sequence
-
- set_failed_rule :_DefinitionListDefinition unless _tmp
- return _tmp
- end
-
- Rules = {}
- Rules[:_root] = rule_info("root", "Doc")
- Rules[:_Doc] = rule_info("Doc", "BOM? Block*:a { RDoc::Markup::Document.new(*a.compact) }")
- Rules[:_Block] = rule_info("Block", "@BlankLine* (BlockQuote | Verbatim | CodeFence | Note | Reference | HorizontalRule | Heading | OrderedList | BulletList | DefinitionList | HtmlBlock | StyleBlock | Para | Plain)")
- Rules[:_Para] = rule_info("Para", "@NonindentSpace Inlines:a @BlankLine+ { paragraph a }")
- Rules[:_Plain] = rule_info("Plain", "Inlines:a { paragraph a }")
- Rules[:_AtxInline] = rule_info("AtxInline", "!@Newline !(@Sp? /\#*/ @Sp @Newline) Inline")
- Rules[:_AtxStart] = rule_info("AtxStart", "< /\\\#{1,6}/ > { text.length }")
- Rules[:_AtxHeading] = rule_info("AtxHeading", "AtxStart:s @Sp? AtxInline+:a (@Sp? /\#*/ @Sp)? @Newline { RDoc::Markup::Heading.new(s, a.join) }")
- Rules[:_SetextHeading] = rule_info("SetextHeading", "(SetextHeading1 | SetextHeading2)")
- Rules[:_SetextBottom1] = rule_info("SetextBottom1", "/={3,}/ @Newline")
- Rules[:_SetextBottom2] = rule_info("SetextBottom2", "/-{3,}/ @Newline")
- Rules[:_SetextHeading1] = rule_info("SetextHeading1", "&(@RawLine SetextBottom1) @StartList:a (!@Endline Inline:b { a << b })+ @Sp? @Newline SetextBottom1 { RDoc::Markup::Heading.new(1, a.join) }")
- Rules[:_SetextHeading2] = rule_info("SetextHeading2", "&(@RawLine SetextBottom2) @StartList:a (!@Endline Inline:b { a << b })+ @Sp? @Newline SetextBottom2 { RDoc::Markup::Heading.new(2, a.join) }")
- Rules[:_Heading] = rule_info("Heading", "(SetextHeading | AtxHeading)")
- Rules[:_BlockQuote] = rule_info("BlockQuote", "BlockQuoteRaw:a { RDoc::Markup::BlockQuote.new(*a) }")
- Rules[:_BlockQuoteRaw] = rule_info("BlockQuoteRaw", "@StartList:a (\">\" \" \"? Line:l { a << l } (!\">\" !@BlankLine Line:c { a << c })* (@BlankLine:n { a << n })*)+ { inner_parse a.join }")
- Rules[:_NonblankIndentedLine] = rule_info("NonblankIndentedLine", "!@BlankLine IndentedLine")
- Rules[:_VerbatimChunk] = rule_info("VerbatimChunk", "@BlankLine*:a NonblankIndentedLine+:b { a.concat b }")
- Rules[:_Verbatim] = rule_info("Verbatim", "VerbatimChunk+:a { RDoc::Markup::Verbatim.new(*a.flatten) }")
- Rules[:_HorizontalRule] = rule_info("HorizontalRule", "@NonindentSpace (\"*\" @Sp \"*\" @Sp \"*\" (@Sp \"*\")* | \"-\" @Sp \"-\" @Sp \"-\" (@Sp \"-\")* | \"_\" @Sp \"_\" @Sp \"_\" (@Sp \"_\")*) @Sp @Newline @BlankLine+ { RDoc::Markup::Rule.new 1 }")
- Rules[:_Bullet] = rule_info("Bullet", "!HorizontalRule @NonindentSpace /[+*-]/ @Spacechar+")
- Rules[:_BulletList] = rule_info("BulletList", "&Bullet (ListTight | ListLoose):a { RDoc::Markup::List.new(:BULLET, *a) }")
- Rules[:_ListTight] = rule_info("ListTight", "ListItemTight+:a @BlankLine* !(Bullet | Enumerator) { a }")
- Rules[:_ListLoose] = rule_info("ListLoose", "@StartList:a (ListItem:b @BlankLine* { a << b })+ { a }")
- Rules[:_ListItem] = rule_info("ListItem", "(Bullet | Enumerator) @StartList:a ListBlock:b { a << b } (ListContinuationBlock:c { a.push(*c) })* { list_item_from a }")
- Rules[:_ListItemTight] = rule_info("ListItemTight", "(Bullet | Enumerator) ListBlock:a (!@BlankLine ListContinuationBlock:b { a.push(*b) })* !ListContinuationBlock { list_item_from a }")
- Rules[:_ListBlock] = rule_info("ListBlock", "!@BlankLine Line:a ListBlockLine*:c { [a, *c] }")
- Rules[:_ListContinuationBlock] = rule_info("ListContinuationBlock", "@StartList:a @BlankLine* { a << \"\\n\" } (Indent ListBlock:b { a.concat b })+ { a }")
- Rules[:_Enumerator] = rule_info("Enumerator", "@NonindentSpace [0-9]+ \".\" @Spacechar+")
- Rules[:_OrderedList] = rule_info("OrderedList", "&Enumerator (ListTight | ListLoose):a { RDoc::Markup::List.new(:NUMBER, *a) }")
- Rules[:_ListBlockLine] = rule_info("ListBlockLine", "!@BlankLine !(Indent? (Bullet | Enumerator)) !HorizontalRule OptionallyIndentedLine")
- Rules[:_HtmlOpenAnchor] = rule_info("HtmlOpenAnchor", "\"<\" Spnl (\"a\" | \"A\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlCloseAnchor] = rule_info("HtmlCloseAnchor", "\"<\" Spnl \"/\" (\"a\" | \"A\") Spnl \">\"")
- Rules[:_HtmlAnchor] = rule_info("HtmlAnchor", "HtmlOpenAnchor (HtmlAnchor | !HtmlCloseAnchor .)* HtmlCloseAnchor")
- Rules[:_HtmlBlockOpenAddress] = rule_info("HtmlBlockOpenAddress", "\"<\" Spnl (\"address\" | \"ADDRESS\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseAddress] = rule_info("HtmlBlockCloseAddress", "\"<\" Spnl \"/\" (\"address\" | \"ADDRESS\") Spnl \">\"")
- Rules[:_HtmlBlockAddress] = rule_info("HtmlBlockAddress", "HtmlBlockOpenAddress (HtmlBlockAddress | !HtmlBlockCloseAddress .)* HtmlBlockCloseAddress")
- Rules[:_HtmlBlockOpenBlockquote] = rule_info("HtmlBlockOpenBlockquote", "\"<\" Spnl (\"blockquote\" | \"BLOCKQUOTE\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseBlockquote] = rule_info("HtmlBlockCloseBlockquote", "\"<\" Spnl \"/\" (\"blockquote\" | \"BLOCKQUOTE\") Spnl \">\"")
- Rules[:_HtmlBlockBlockquote] = rule_info("HtmlBlockBlockquote", "HtmlBlockOpenBlockquote (HtmlBlockBlockquote | !HtmlBlockCloseBlockquote .)* HtmlBlockCloseBlockquote")
- Rules[:_HtmlBlockOpenCenter] = rule_info("HtmlBlockOpenCenter", "\"<\" Spnl (\"center\" | \"CENTER\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseCenter] = rule_info("HtmlBlockCloseCenter", "\"<\" Spnl \"/\" (\"center\" | \"CENTER\") Spnl \">\"")
- Rules[:_HtmlBlockCenter] = rule_info("HtmlBlockCenter", "HtmlBlockOpenCenter (HtmlBlockCenter | !HtmlBlockCloseCenter .)* HtmlBlockCloseCenter")
- Rules[:_HtmlBlockOpenDir] = rule_info("HtmlBlockOpenDir", "\"<\" Spnl (\"dir\" | \"DIR\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseDir] = rule_info("HtmlBlockCloseDir", "\"<\" Spnl \"/\" (\"dir\" | \"DIR\") Spnl \">\"")
- Rules[:_HtmlBlockDir] = rule_info("HtmlBlockDir", "HtmlBlockOpenDir (HtmlBlockDir | !HtmlBlockCloseDir .)* HtmlBlockCloseDir")
- Rules[:_HtmlBlockOpenDiv] = rule_info("HtmlBlockOpenDiv", "\"<\" Spnl (\"div\" | \"DIV\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseDiv] = rule_info("HtmlBlockCloseDiv", "\"<\" Spnl \"/\" (\"div\" | \"DIV\") Spnl \">\"")
- Rules[:_HtmlBlockDiv] = rule_info("HtmlBlockDiv", "HtmlBlockOpenDiv (HtmlBlockDiv | !HtmlBlockCloseDiv .)* HtmlBlockCloseDiv")
- Rules[:_HtmlBlockOpenDl] = rule_info("HtmlBlockOpenDl", "\"<\" Spnl (\"dl\" | \"DL\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseDl] = rule_info("HtmlBlockCloseDl", "\"<\" Spnl \"/\" (\"dl\" | \"DL\") Spnl \">\"")
- Rules[:_HtmlBlockDl] = rule_info("HtmlBlockDl", "HtmlBlockOpenDl (HtmlBlockDl | !HtmlBlockCloseDl .)* HtmlBlockCloseDl")
- Rules[:_HtmlBlockOpenFieldset] = rule_info("HtmlBlockOpenFieldset", "\"<\" Spnl (\"fieldset\" | \"FIELDSET\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseFieldset] = rule_info("HtmlBlockCloseFieldset", "\"<\" Spnl \"/\" (\"fieldset\" | \"FIELDSET\") Spnl \">\"")
- Rules[:_HtmlBlockFieldset] = rule_info("HtmlBlockFieldset", "HtmlBlockOpenFieldset (HtmlBlockFieldset | !HtmlBlockCloseFieldset .)* HtmlBlockCloseFieldset")
- Rules[:_HtmlBlockOpenForm] = rule_info("HtmlBlockOpenForm", "\"<\" Spnl (\"form\" | \"FORM\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseForm] = rule_info("HtmlBlockCloseForm", "\"<\" Spnl \"/\" (\"form\" | \"FORM\") Spnl \">\"")
- Rules[:_HtmlBlockForm] = rule_info("HtmlBlockForm", "HtmlBlockOpenForm (HtmlBlockForm | !HtmlBlockCloseForm .)* HtmlBlockCloseForm")
- Rules[:_HtmlBlockOpenH1] = rule_info("HtmlBlockOpenH1", "\"<\" Spnl (\"h1\" | \"H1\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseH1] = rule_info("HtmlBlockCloseH1", "\"<\" Spnl \"/\" (\"h1\" | \"H1\") Spnl \">\"")
- Rules[:_HtmlBlockH1] = rule_info("HtmlBlockH1", "HtmlBlockOpenH1 (HtmlBlockH1 | !HtmlBlockCloseH1 .)* HtmlBlockCloseH1")
- Rules[:_HtmlBlockOpenH2] = rule_info("HtmlBlockOpenH2", "\"<\" Spnl (\"h2\" | \"H2\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseH2] = rule_info("HtmlBlockCloseH2", "\"<\" Spnl \"/\" (\"h2\" | \"H2\") Spnl \">\"")
- Rules[:_HtmlBlockH2] = rule_info("HtmlBlockH2", "HtmlBlockOpenH2 (HtmlBlockH2 | !HtmlBlockCloseH2 .)* HtmlBlockCloseH2")
- Rules[:_HtmlBlockOpenH3] = rule_info("HtmlBlockOpenH3", "\"<\" Spnl (\"h3\" | \"H3\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseH3] = rule_info("HtmlBlockCloseH3", "\"<\" Spnl \"/\" (\"h3\" | \"H3\") Spnl \">\"")
- Rules[:_HtmlBlockH3] = rule_info("HtmlBlockH3", "HtmlBlockOpenH3 (HtmlBlockH3 | !HtmlBlockCloseH3 .)* HtmlBlockCloseH3")
- Rules[:_HtmlBlockOpenH4] = rule_info("HtmlBlockOpenH4", "\"<\" Spnl (\"h4\" | \"H4\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseH4] = rule_info("HtmlBlockCloseH4", "\"<\" Spnl \"/\" (\"h4\" | \"H4\") Spnl \">\"")
- Rules[:_HtmlBlockH4] = rule_info("HtmlBlockH4", "HtmlBlockOpenH4 (HtmlBlockH4 | !HtmlBlockCloseH4 .)* HtmlBlockCloseH4")
- Rules[:_HtmlBlockOpenH5] = rule_info("HtmlBlockOpenH5", "\"<\" Spnl (\"h5\" | \"H5\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseH5] = rule_info("HtmlBlockCloseH5", "\"<\" Spnl \"/\" (\"h5\" | \"H5\") Spnl \">\"")
- Rules[:_HtmlBlockH5] = rule_info("HtmlBlockH5", "HtmlBlockOpenH5 (HtmlBlockH5 | !HtmlBlockCloseH5 .)* HtmlBlockCloseH5")
- Rules[:_HtmlBlockOpenH6] = rule_info("HtmlBlockOpenH6", "\"<\" Spnl (\"h6\" | \"H6\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseH6] = rule_info("HtmlBlockCloseH6", "\"<\" Spnl \"/\" (\"h6\" | \"H6\") Spnl \">\"")
- Rules[:_HtmlBlockH6] = rule_info("HtmlBlockH6", "HtmlBlockOpenH6 (HtmlBlockH6 | !HtmlBlockCloseH6 .)* HtmlBlockCloseH6")
- Rules[:_HtmlBlockOpenMenu] = rule_info("HtmlBlockOpenMenu", "\"<\" Spnl (\"menu\" | \"MENU\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseMenu] = rule_info("HtmlBlockCloseMenu", "\"<\" Spnl \"/\" (\"menu\" | \"MENU\") Spnl \">\"")
- Rules[:_HtmlBlockMenu] = rule_info("HtmlBlockMenu", "HtmlBlockOpenMenu (HtmlBlockMenu | !HtmlBlockCloseMenu .)* HtmlBlockCloseMenu")
- Rules[:_HtmlBlockOpenNoframes] = rule_info("HtmlBlockOpenNoframes", "\"<\" Spnl (\"noframes\" | \"NOFRAMES\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseNoframes] = rule_info("HtmlBlockCloseNoframes", "\"<\" Spnl \"/\" (\"noframes\" | \"NOFRAMES\") Spnl \">\"")
- Rules[:_HtmlBlockNoframes] = rule_info("HtmlBlockNoframes", "HtmlBlockOpenNoframes (HtmlBlockNoframes | !HtmlBlockCloseNoframes .)* HtmlBlockCloseNoframes")
- Rules[:_HtmlBlockOpenNoscript] = rule_info("HtmlBlockOpenNoscript", "\"<\" Spnl (\"noscript\" | \"NOSCRIPT\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseNoscript] = rule_info("HtmlBlockCloseNoscript", "\"<\" Spnl \"/\" (\"noscript\" | \"NOSCRIPT\") Spnl \">\"")
- Rules[:_HtmlBlockNoscript] = rule_info("HtmlBlockNoscript", "HtmlBlockOpenNoscript (HtmlBlockNoscript | !HtmlBlockCloseNoscript .)* HtmlBlockCloseNoscript")
- Rules[:_HtmlBlockOpenOl] = rule_info("HtmlBlockOpenOl", "\"<\" Spnl (\"ol\" | \"OL\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseOl] = rule_info("HtmlBlockCloseOl", "\"<\" Spnl \"/\" (\"ol\" | \"OL\") Spnl \">\"")
- Rules[:_HtmlBlockOl] = rule_info("HtmlBlockOl", "HtmlBlockOpenOl (HtmlBlockOl | !HtmlBlockCloseOl .)* HtmlBlockCloseOl")
- Rules[:_HtmlBlockOpenP] = rule_info("HtmlBlockOpenP", "\"<\" Spnl (\"p\" | \"P\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseP] = rule_info("HtmlBlockCloseP", "\"<\" Spnl \"/\" (\"p\" | \"P\") Spnl \">\"")
- Rules[:_HtmlBlockP] = rule_info("HtmlBlockP", "HtmlBlockOpenP (HtmlBlockP | !HtmlBlockCloseP .)* HtmlBlockCloseP")
- Rules[:_HtmlBlockOpenPre] = rule_info("HtmlBlockOpenPre", "\"<\" Spnl (\"pre\" | \"PRE\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockClosePre] = rule_info("HtmlBlockClosePre", "\"<\" Spnl \"/\" (\"pre\" | \"PRE\") Spnl \">\"")
- Rules[:_HtmlBlockPre] = rule_info("HtmlBlockPre", "HtmlBlockOpenPre (HtmlBlockPre | !HtmlBlockClosePre .)* HtmlBlockClosePre")
- Rules[:_HtmlBlockOpenTable] = rule_info("HtmlBlockOpenTable", "\"<\" Spnl (\"table\" | \"TABLE\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseTable] = rule_info("HtmlBlockCloseTable", "\"<\" Spnl \"/\" (\"table\" | \"TABLE\") Spnl \">\"")
- Rules[:_HtmlBlockTable] = rule_info("HtmlBlockTable", "HtmlBlockOpenTable (HtmlBlockTable | !HtmlBlockCloseTable .)* HtmlBlockCloseTable")
- Rules[:_HtmlBlockOpenUl] = rule_info("HtmlBlockOpenUl", "\"<\" Spnl (\"ul\" | \"UL\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseUl] = rule_info("HtmlBlockCloseUl", "\"<\" Spnl \"/\" (\"ul\" | \"UL\") Spnl \">\"")
- Rules[:_HtmlBlockUl] = rule_info("HtmlBlockUl", "HtmlBlockOpenUl (HtmlBlockUl | !HtmlBlockCloseUl .)* HtmlBlockCloseUl")
- Rules[:_HtmlBlockOpenDd] = rule_info("HtmlBlockOpenDd", "\"<\" Spnl (\"dd\" | \"DD\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseDd] = rule_info("HtmlBlockCloseDd", "\"<\" Spnl \"/\" (\"dd\" | \"DD\") Spnl \">\"")
- Rules[:_HtmlBlockDd] = rule_info("HtmlBlockDd", "HtmlBlockOpenDd (HtmlBlockDd | !HtmlBlockCloseDd .)* HtmlBlockCloseDd")
- Rules[:_HtmlBlockOpenDt] = rule_info("HtmlBlockOpenDt", "\"<\" Spnl (\"dt\" | \"DT\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseDt] = rule_info("HtmlBlockCloseDt", "\"<\" Spnl \"/\" (\"dt\" | \"DT\") Spnl \">\"")
- Rules[:_HtmlBlockDt] = rule_info("HtmlBlockDt", "HtmlBlockOpenDt (HtmlBlockDt | !HtmlBlockCloseDt .)* HtmlBlockCloseDt")
- Rules[:_HtmlBlockOpenFrameset] = rule_info("HtmlBlockOpenFrameset", "\"<\" Spnl (\"frameset\" | \"FRAMESET\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseFrameset] = rule_info("HtmlBlockCloseFrameset", "\"<\" Spnl \"/\" (\"frameset\" | \"FRAMESET\") Spnl \">\"")
- Rules[:_HtmlBlockFrameset] = rule_info("HtmlBlockFrameset", "HtmlBlockOpenFrameset (HtmlBlockFrameset | !HtmlBlockCloseFrameset .)* HtmlBlockCloseFrameset")
- Rules[:_HtmlBlockOpenLi] = rule_info("HtmlBlockOpenLi", "\"<\" Spnl (\"li\" | \"LI\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseLi] = rule_info("HtmlBlockCloseLi", "\"<\" Spnl \"/\" (\"li\" | \"LI\") Spnl \">\"")
- Rules[:_HtmlBlockLi] = rule_info("HtmlBlockLi", "HtmlBlockOpenLi (HtmlBlockLi | !HtmlBlockCloseLi .)* HtmlBlockCloseLi")
- Rules[:_HtmlBlockOpenTbody] = rule_info("HtmlBlockOpenTbody", "\"<\" Spnl (\"tbody\" | \"TBODY\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseTbody] = rule_info("HtmlBlockCloseTbody", "\"<\" Spnl \"/\" (\"tbody\" | \"TBODY\") Spnl \">\"")
- Rules[:_HtmlBlockTbody] = rule_info("HtmlBlockTbody", "HtmlBlockOpenTbody (HtmlBlockTbody | !HtmlBlockCloseTbody .)* HtmlBlockCloseTbody")
- Rules[:_HtmlBlockOpenTd] = rule_info("HtmlBlockOpenTd", "\"<\" Spnl (\"td\" | \"TD\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseTd] = rule_info("HtmlBlockCloseTd", "\"<\" Spnl \"/\" (\"td\" | \"TD\") Spnl \">\"")
- Rules[:_HtmlBlockTd] = rule_info("HtmlBlockTd", "HtmlBlockOpenTd (HtmlBlockTd | !HtmlBlockCloseTd .)* HtmlBlockCloseTd")
- Rules[:_HtmlBlockOpenTfoot] = rule_info("HtmlBlockOpenTfoot", "\"<\" Spnl (\"tfoot\" | \"TFOOT\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseTfoot] = rule_info("HtmlBlockCloseTfoot", "\"<\" Spnl \"/\" (\"tfoot\" | \"TFOOT\") Spnl \">\"")
- Rules[:_HtmlBlockTfoot] = rule_info("HtmlBlockTfoot", "HtmlBlockOpenTfoot (HtmlBlockTfoot | !HtmlBlockCloseTfoot .)* HtmlBlockCloseTfoot")
- Rules[:_HtmlBlockOpenTh] = rule_info("HtmlBlockOpenTh", "\"<\" Spnl (\"th\" | \"TH\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseTh] = rule_info("HtmlBlockCloseTh", "\"<\" Spnl \"/\" (\"th\" | \"TH\") Spnl \">\"")
- Rules[:_HtmlBlockTh] = rule_info("HtmlBlockTh", "HtmlBlockOpenTh (HtmlBlockTh | !HtmlBlockCloseTh .)* HtmlBlockCloseTh")
- Rules[:_HtmlBlockOpenThead] = rule_info("HtmlBlockOpenThead", "\"<\" Spnl (\"thead\" | \"THEAD\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseThead] = rule_info("HtmlBlockCloseThead", "\"<\" Spnl \"/\" (\"thead\" | \"THEAD\") Spnl \">\"")
- Rules[:_HtmlBlockThead] = rule_info("HtmlBlockThead", "HtmlBlockOpenThead (HtmlBlockThead | !HtmlBlockCloseThead .)* HtmlBlockCloseThead")
- Rules[:_HtmlBlockOpenTr] = rule_info("HtmlBlockOpenTr", "\"<\" Spnl (\"tr\" | \"TR\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseTr] = rule_info("HtmlBlockCloseTr", "\"<\" Spnl \"/\" (\"tr\" | \"TR\") Spnl \">\"")
- Rules[:_HtmlBlockTr] = rule_info("HtmlBlockTr", "HtmlBlockOpenTr (HtmlBlockTr | !HtmlBlockCloseTr .)* HtmlBlockCloseTr")
- Rules[:_HtmlBlockOpenScript] = rule_info("HtmlBlockOpenScript", "\"<\" Spnl (\"script\" | \"SCRIPT\") Spnl HtmlAttribute* \">\"")
- Rules[:_HtmlBlockCloseScript] = rule_info("HtmlBlockCloseScript", "\"<\" Spnl \"/\" (\"script\" | \"SCRIPT\") Spnl \">\"")
- Rules[:_HtmlBlockScript] = rule_info("HtmlBlockScript", "HtmlBlockOpenScript (!HtmlBlockCloseScript .)* HtmlBlockCloseScript")
- Rules[:_HtmlBlockInTags] = rule_info("HtmlBlockInTags", "(HtmlAnchor | HtmlBlockAddress | HtmlBlockBlockquote | HtmlBlockCenter | HtmlBlockDir | HtmlBlockDiv | HtmlBlockDl | HtmlBlockFieldset | HtmlBlockForm | HtmlBlockH1 | HtmlBlockH2 | HtmlBlockH3 | HtmlBlockH4 | HtmlBlockH5 | HtmlBlockH6 | HtmlBlockMenu | HtmlBlockNoframes | HtmlBlockNoscript | HtmlBlockOl | HtmlBlockP | HtmlBlockPre | HtmlBlockTable | HtmlBlockUl | HtmlBlockDd | HtmlBlockDt | HtmlBlockFrameset | HtmlBlockLi | HtmlBlockTbody | HtmlBlockTd | HtmlBlockTfoot | HtmlBlockTh | HtmlBlockThead | HtmlBlockTr | HtmlBlockScript)")
- Rules[:_HtmlBlock] = rule_info("HtmlBlock", "< (HtmlBlockInTags | HtmlComment | HtmlBlockSelfClosing | HtmlUnclosed) > @BlankLine+ { if html? then RDoc::Markup::Raw.new text end }")
- Rules[:_HtmlUnclosed] = rule_info("HtmlUnclosed", "\"<\" Spnl HtmlUnclosedType Spnl HtmlAttribute* Spnl \">\"")
- Rules[:_HtmlUnclosedType] = rule_info("HtmlUnclosedType", "(\"HR\" | \"hr\")")
- Rules[:_HtmlBlockSelfClosing] = rule_info("HtmlBlockSelfClosing", "\"<\" Spnl HtmlBlockType Spnl HtmlAttribute* \"/\" Spnl \">\"")
- Rules[:_HtmlBlockType] = rule_info("HtmlBlockType", "(\"ADDRESS\" | \"BLOCKQUOTE\" | \"CENTER\" | \"DD\" | \"DIR\" | \"DIV\" | \"DL\" | \"DT\" | \"FIELDSET\" | \"FORM\" | \"FRAMESET\" | \"H1\" | \"H2\" | \"H3\" | \"H4\" | \"H5\" | \"H6\" | \"HR\" | \"ISINDEX\" | \"LI\" | \"MENU\" | \"NOFRAMES\" | \"NOSCRIPT\" | \"OL\" | \"P\" | \"PRE\" | \"SCRIPT\" | \"TABLE\" | \"TBODY\" | \"TD\" | \"TFOOT\" | \"TH\" | \"THEAD\" | \"TR\" | \"UL\" | \"address\" | \"blockquote\" | \"center\" | \"dd\" | \"dir\" | \"div\" | \"dl\" | \"dt\" | \"fieldset\" | \"form\" | \"frameset\" | \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\" | \"hr\" | \"isindex\" | \"li\" | \"menu\" | \"noframes\" | \"noscript\" | \"ol\" | \"p\" | \"pre\" | \"script\" | \"table\" | \"tbody\" | \"td\" | \"tfoot\" | \"th\" | \"thead\" | \"tr\" | \"ul\")")
- Rules[:_StyleOpen] = rule_info("StyleOpen", "\"<\" Spnl (\"style\" | \"STYLE\") Spnl HtmlAttribute* \">\"")
- Rules[:_StyleClose] = rule_info("StyleClose", "\"<\" Spnl \"/\" (\"style\" | \"STYLE\") Spnl \">\"")
- Rules[:_InStyleTags] = rule_info("InStyleTags", "StyleOpen (!StyleClose .)* StyleClose")
- Rules[:_StyleBlock] = rule_info("StyleBlock", "< InStyleTags > @BlankLine* { if css? then RDoc::Markup::Raw.new text end }")
- Rules[:_Inlines] = rule_info("Inlines", "(!@Endline Inline:i { i } | @Endline:c &Inline { c })+:chunks @Endline? { chunks }")
- Rules[:_Inline] = rule_info("Inline", "(Str | @Endline | UlOrStarLine | @Space | Strong | Emph | Image | Link | NoteReference | InlineNote | Code | RawHtml | Entity | EscapedChar | Symbol)")
- Rules[:_Space] = rule_info("Space", "@Spacechar+ { \" \" }")
- Rules[:_Str] = rule_info("Str", "@StartList:a < @NormalChar+ > { a = text } (StrChunk:c { a << c })* { a }")
- Rules[:_StrChunk] = rule_info("StrChunk", "< (@NormalChar | /_+/ &Alphanumeric)+ > { text }")
- Rules[:_EscapedChar] = rule_info("EscapedChar", "\"\\\\\" !@Newline < /[:\\\\`|*_{}\\[\\]()\#+.!><-]/ > { text }")
- Rules[:_Entity] = rule_info("Entity", "(HexEntity | DecEntity | CharEntity):a { a }")
- Rules[:_Endline] = rule_info("Endline", "(@LineBreak | @TerminalEndline | @NormalEndline)")
- Rules[:_NormalEndline] = rule_info("NormalEndline", "@Sp @Newline !@BlankLine !\">\" !AtxStart !(Line /={3,}|-{3,}=/ @Newline) { \"\\n\" }")
- Rules[:_TerminalEndline] = rule_info("TerminalEndline", "@Sp @Newline @Eof")
- Rules[:_LineBreak] = rule_info("LineBreak", "\" \" @NormalEndline { RDoc::Markup::HardBreak.new }")
- Rules[:_Symbol] = rule_info("Symbol", "< @SpecialChar > { text }")
- Rules[:_UlOrStarLine] = rule_info("UlOrStarLine", "(UlLine | StarLine):a { a }")
- Rules[:_StarLine] = rule_info("StarLine", "(< /\\*{4,}/ > { text } | < @Spacechar /\\*+/ &@Spacechar > { text })")
- Rules[:_UlLine] = rule_info("UlLine", "(< /_{4,}/ > { text } | < @Spacechar /_+/ &@Spacechar > { text })")
- Rules[:_Emph] = rule_info("Emph", "(EmphStar | EmphUl)")
- Rules[:_OneStarOpen] = rule_info("OneStarOpen", "!StarLine \"*\" !@Spacechar !@Newline")
- Rules[:_OneStarClose] = rule_info("OneStarClose", "!@Spacechar !@Newline Inline:a \"*\" { a }")
- Rules[:_EmphStar] = rule_info("EmphStar", "OneStarOpen @StartList:a (!OneStarClose Inline:l { a << l })* OneStarClose:l { a << l } { emphasis a.join }")
- Rules[:_OneUlOpen] = rule_info("OneUlOpen", "!UlLine \"_\" !@Spacechar !@Newline")
- Rules[:_OneUlClose] = rule_info("OneUlClose", "!@Spacechar !@Newline Inline:a \"_\" { a }")
- Rules[:_EmphUl] = rule_info("EmphUl", "OneUlOpen @StartList:a (!OneUlClose Inline:l { a << l })* OneUlClose:l { a << l } { emphasis a.join }")
- Rules[:_Strong] = rule_info("Strong", "(StrongStar | StrongUl)")
- Rules[:_TwoStarOpen] = rule_info("TwoStarOpen", "!StarLine \"**\" !@Spacechar !@Newline")
- Rules[:_TwoStarClose] = rule_info("TwoStarClose", "!@Spacechar !@Newline Inline:a \"**\" { a }")
- Rules[:_StrongStar] = rule_info("StrongStar", "TwoStarOpen @StartList:a (!TwoStarClose Inline:l { a << l })* TwoStarClose:l { a << l } { strong a.join }")
- Rules[:_TwoUlOpen] = rule_info("TwoUlOpen", "!UlLine \"__\" !@Spacechar !@Newline")
- Rules[:_TwoUlClose] = rule_info("TwoUlClose", "!@Spacechar !@Newline Inline:a \"__\" { a }")
- Rules[:_StrongUl] = rule_info("StrongUl", "TwoUlOpen @StartList:a (!TwoUlClose Inline:i { a << i })* TwoUlClose:l { a << l } { strong a.join }")
- Rules[:_Image] = rule_info("Image", "\"!\" (ExplicitLink | ReferenceLink):a { \"rdoc-image:\#{a[/\\[(.*)\\]/, 1]}\" }")
- Rules[:_Link] = rule_info("Link", "(ExplicitLink | ReferenceLink | AutoLink)")
- Rules[:_ReferenceLink] = rule_info("ReferenceLink", "(ReferenceLinkDouble | ReferenceLinkSingle)")
- Rules[:_ReferenceLinkDouble] = rule_info("ReferenceLinkDouble", "Label:content < Spnl > !\"[]\" Label:label { link_to content, label, text }")
- Rules[:_ReferenceLinkSingle] = rule_info("ReferenceLinkSingle", "Label:content < (Spnl \"[]\")? > { link_to content, content, text }")
- Rules[:_ExplicitLink] = rule_info("ExplicitLink", "Label:l Spnl \"(\" @Sp Source:s Spnl Title @Sp \")\" { \"{\#{l}}[\#{s}]\" }")
- Rules[:_Source] = rule_info("Source", "(\"<\" < SourceContents > \">\" | < SourceContents >) { text }")
- Rules[:_SourceContents] = rule_info("SourceContents", "(((!\"(\" !\")\" !\">\" Nonspacechar)+ | \"(\" SourceContents \")\")* | \"\")")
- Rules[:_Title] = rule_info("Title", "(TitleSingle | TitleDouble | \"\"):a { a }")
- Rules[:_TitleSingle] = rule_info("TitleSingle", "\"'\" (!(\"'\" @Sp (\")\" | @Newline)) .)* \"'\"")
- Rules[:_TitleDouble] = rule_info("TitleDouble", "\"\\\"\" (!(\"\\\"\" @Sp (\")\" | @Newline)) .)* \"\\\"\"")
- Rules[:_AutoLink] = rule_info("AutoLink", "(AutoLinkUrl | AutoLinkEmail)")
- Rules[:_AutoLinkUrl] = rule_info("AutoLinkUrl", "\"<\" < /[A-Za-z]+/ \"://\" (!@Newline !\">\" .)+ > \">\" { text }")
- Rules[:_AutoLinkEmail] = rule_info("AutoLinkEmail", "\"<\" \"mailto:\"? < /[\\w+.\\/!%~$-]+/i \"@\" (!@Newline !\">\" .)+ > \">\" { \"mailto:\#{text}\" }")
- Rules[:_Reference] = rule_info("Reference", "@NonindentSpace !\"[]\" Label:label \":\" Spnl RefSrc:link RefTitle @BlankLine+ { \# TODO use title reference label, link nil }")
- Rules[:_Label] = rule_info("Label", "\"[\" (!\"^\" &{ notes? } | &. &{ !notes? }) @StartList:a (!\"]\" Inline:l { a << l })* \"]\" { a.join.gsub(/\\s+/, ' ') }")
- Rules[:_RefSrc] = rule_info("RefSrc", "< Nonspacechar+ > { text }")
- Rules[:_RefTitle] = rule_info("RefTitle", "(RefTitleSingle | RefTitleDouble | RefTitleParens | EmptyTitle)")
- Rules[:_EmptyTitle] = rule_info("EmptyTitle", "\"\"")
- Rules[:_RefTitleSingle] = rule_info("RefTitleSingle", "Spnl \"'\" < (!(\"'\" @Sp @Newline | @Newline) .)* > \"'\" { text }")
- Rules[:_RefTitleDouble] = rule_info("RefTitleDouble", "Spnl \"\\\"\" < (!(\"\\\"\" @Sp @Newline | @Newline) .)* > \"\\\"\" { text }")
- Rules[:_RefTitleParens] = rule_info("RefTitleParens", "Spnl \"(\" < (!(\")\" @Sp @Newline | @Newline) .)* > \")\" { text }")
- Rules[:_References] = rule_info("References", "(Reference | SkipBlock)*")
- Rules[:_Ticks1] = rule_info("Ticks1", "\"`\" !\"`\"")
- Rules[:_Ticks2] = rule_info("Ticks2", "\"``\" !\"`\"")
- Rules[:_Ticks3] = rule_info("Ticks3", "\"```\" !\"`\"")
- Rules[:_Ticks4] = rule_info("Ticks4", "\"````\" !\"`\"")
- Rules[:_Ticks5] = rule_info("Ticks5", "\"`````\" !\"`\"")
- Rules[:_Code] = rule_info("Code", "(Ticks1 @Sp < ((!\"`\" Nonspacechar)+ | !Ticks1 /`+/ | !(@Sp Ticks1) (@Spacechar | @Newline !@BlankLine))+ > @Sp Ticks1 | Ticks2 @Sp < ((!\"`\" Nonspacechar)+ | !Ticks2 /`+/ | !(@Sp Ticks2) (@Spacechar | @Newline !@BlankLine))+ > @Sp Ticks2 | Ticks3 @Sp < ((!\"`\" Nonspacechar)+ | !Ticks3 /`+/ | !(@Sp Ticks3) (@Spacechar | @Newline !@BlankLine))+ > @Sp Ticks3 | Ticks4 @Sp < ((!\"`\" Nonspacechar)+ | !Ticks4 /`+/ | !(@Sp Ticks4) (@Spacechar | @Newline !@BlankLine))+ > @Sp Ticks4 | Ticks5 @Sp < ((!\"`\" Nonspacechar)+ | !Ticks5 /`+/ | !(@Sp Ticks5) (@Spacechar | @Newline !@BlankLine))+ > @Sp Ticks5) { \"<code>\#{text}</code>\" }")
- Rules[:_RawHtml] = rule_info("RawHtml", "< (HtmlComment | HtmlBlockScript | HtmlTag) > { if html? then text else '' end }")
- Rules[:_BlankLine] = rule_info("BlankLine", "@Sp @Newline { \"\\n\" }")
- Rules[:_Quoted] = rule_info("Quoted", "(\"\\\"\" (!\"\\\"\" .)* \"\\\"\" | \"'\" (!\"'\" .)* \"'\")")
- Rules[:_HtmlAttribute] = rule_info("HtmlAttribute", "(AlphanumericAscii | \"-\")+ Spnl (\"=\" Spnl (Quoted | (!\">\" Nonspacechar)+))? Spnl")
- Rules[:_HtmlComment] = rule_info("HtmlComment", "\"<!--\" (!\"-->\" .)* \"-->\"")
- Rules[:_HtmlTag] = rule_info("HtmlTag", "\"<\" Spnl \"/\"? AlphanumericAscii+ Spnl HtmlAttribute* \"/\"? Spnl \">\"")
- Rules[:_Eof] = rule_info("Eof", "!.")
- Rules[:_Nonspacechar] = rule_info("Nonspacechar", "!@Spacechar !@Newline .")
- Rules[:_Sp] = rule_info("Sp", "@Spacechar*")
- Rules[:_Spnl] = rule_info("Spnl", "@Sp (@Newline @Sp)?")
- Rules[:_SpecialChar] = rule_info("SpecialChar", "(/[*_`&\\[\\]()<!\#\\\\'\"]/ | @ExtendedSpecialChar)")
- Rules[:_NormalChar] = rule_info("NormalChar", "!(@SpecialChar | @Spacechar | @Newline) .")
- Rules[:_Digit] = rule_info("Digit", "[0-9]")
- Rules[:_Alphanumeric] = rule_info("Alphanumeric", "%literals.Alphanumeric")
- Rules[:_AlphanumericAscii] = rule_info("AlphanumericAscii", "%literals.AlphanumericAscii")
- Rules[:_BOM] = rule_info("BOM", "%literals.BOM")
- Rules[:_Newline] = rule_info("Newline", "%literals.Newline")
- Rules[:_NonAlphanumeric] = rule_info("NonAlphanumeric", "%literals.NonAlphanumeric")
- Rules[:_Spacechar] = rule_info("Spacechar", "%literals.Spacechar")
- Rules[:_HexEntity] = rule_info("HexEntity", "/&\#x/i < /[0-9a-fA-F]+/ > \";\" { [text.to_i(16)].pack 'U' }")
- Rules[:_DecEntity] = rule_info("DecEntity", "\"&\#\" < /[0-9]+/ > \";\" { [text.to_i].pack 'U' }")
- Rules[:_CharEntity] = rule_info("CharEntity", "\"&\" < /[A-Za-z0-9]+/ > \";\" { if entity = HTML_ENTITIES[text] then entity.pack 'U*' else \"&\#{text};\" end }")
- Rules[:_NonindentSpace] = rule_info("NonindentSpace", "/ {0,3}/")
- Rules[:_Indent] = rule_info("Indent", "/\\t| /")
- Rules[:_IndentedLine] = rule_info("IndentedLine", "Indent Line")
- Rules[:_OptionallyIndentedLine] = rule_info("OptionallyIndentedLine", "Indent? Line")
- Rules[:_StartList] = rule_info("StartList", "&. { [] }")
- Rules[:_Line] = rule_info("Line", "@RawLine:a { a }")
- Rules[:_RawLine] = rule_info("RawLine", "(< (!\"\\r\" !\"\\n\" .)* @Newline > | < .+ > @Eof) { text }")
- Rules[:_SkipBlock] = rule_info("SkipBlock", "(HtmlBlock | (!\"\#\" !SetextBottom1 !SetextBottom2 !@BlankLine @RawLine)+ @BlankLine* | @BlankLine+ | @RawLine)")
- Rules[:_ExtendedSpecialChar] = rule_info("ExtendedSpecialChar", "&{ notes? } \"^\"")
- Rules[:_NoteReference] = rule_info("NoteReference", "&{ notes? } RawNoteReference:ref { note_for ref }")
- Rules[:_RawNoteReference] = rule_info("RawNoteReference", "\"[^\" < (!@Newline !\"]\" .)+ > \"]\" { text }")
- Rules[:_Note] = rule_info("Note", "&{ notes? } @NonindentSpace RawNoteReference:ref \":\" @Sp @StartList:a RawNoteBlock:i { a.concat i } (&Indent RawNoteBlock:i { a.concat i })* { @footnotes[ref] = paragraph a nil }")
- Rules[:_InlineNote] = rule_info("InlineNote", "&{ notes? } \"^[\" @StartList:a (!\"]\" Inline:l { a << l })+ \"]\" { ref = [:inline, @note_order.length] @footnotes[ref] = paragraph a note_for ref }")
- Rules[:_Notes] = rule_info("Notes", "(Note | SkipBlock)*")
- Rules[:_RawNoteBlock] = rule_info("RawNoteBlock", "@StartList:a (!@BlankLine OptionallyIndentedLine:l { a << l })+ < @BlankLine* > { a << text } { a }")
- Rules[:_CodeFence] = rule_info("CodeFence", "&{ github? } Ticks3 (@Sp StrChunk:format)? Spnl < ((!\"`\" Nonspacechar)+ | !Ticks3 /`+/ | Spacechar | @Newline)+ > Ticks3 @Sp @Newline* { verbatim = RDoc::Markup::Verbatim.new text verbatim.format = format.intern if format verbatim }")
- Rules[:_DefinitionList] = rule_info("DefinitionList", "&{ definition_lists? } DefinitionListItem+:list { RDoc::Markup::List.new :NOTE, *list.flatten }")
- Rules[:_DefinitionListItem] = rule_info("DefinitionListItem", "DefinitionListLabel+:label DefinitionListDefinition+:defns { list_items = [] list_items << RDoc::Markup::ListItem.new(label, defns.shift) list_items.concat defns.map { |defn| RDoc::Markup::ListItem.new nil, defn } unless list_items.empty? list_items }")
- Rules[:_DefinitionListLabel] = rule_info("DefinitionListLabel", "StrChunk:label @Sp @Newline { label }")
- Rules[:_DefinitionListDefinition] = rule_info("DefinitionListDefinition", "@NonindentSpace \":\" @Space Inlines:a @BlankLine+ { paragraph a }")
- # :startdoc:
-end
diff --git a/ruby_2_2/lib/rdoc/markdown/entities.rb b/ruby_2_2/lib/rdoc/markdown/entities.rb
deleted file mode 100644
index 0661abab78..0000000000
--- a/ruby_2_2/lib/rdoc/markdown/entities.rb
+++ /dev/null
@@ -1,2131 +0,0 @@
-##
-# HTML entity name map for RDoc::Markdown
-
-RDoc::Markdown::HTML_ENTITIES = {
- "AElig" => [0x000C6],
- "AMP" => [0x00026],
- "Aacute" => [0x000C1],
- "Abreve" => [0x00102],
- "Acirc" => [0x000C2],
- "Acy" => [0x00410],
- "Afr" => [0x1D504],
- "Agrave" => [0x000C0],
- "Alpha" => [0x00391],
- "Amacr" => [0x00100],
- "And" => [0x02A53],
- "Aogon" => [0x00104],
- "Aopf" => [0x1D538],
- "ApplyFunction" => [0x02061],
- "Aring" => [0x000C5],
- "Ascr" => [0x1D49C],
- "Assign" => [0x02254],
- "Atilde" => [0x000C3],
- "Auml" => [0x000C4],
- "Backslash" => [0x02216],
- "Barv" => [0x02AE7],
- "Barwed" => [0x02306],
- "Bcy" => [0x00411],
- "Because" => [0x02235],
- "Bernoullis" => [0x0212C],
- "Beta" => [0x00392],
- "Bfr" => [0x1D505],
- "Bopf" => [0x1D539],
- "Breve" => [0x002D8],
- "Bscr" => [0x0212C],
- "Bumpeq" => [0x0224E],
- "CHcy" => [0x00427],
- "COPY" => [0x000A9],
- "Cacute" => [0x00106],
- "Cap" => [0x022D2],
- "CapitalDifferentialD" => [0x02145],
- "Cayleys" => [0x0212D],
- "Ccaron" => [0x0010C],
- "Ccedil" => [0x000C7],
- "Ccirc" => [0x00108],
- "Cconint" => [0x02230],
- "Cdot" => [0x0010A],
- "Cedilla" => [0x000B8],
- "CenterDot" => [0x000B7],
- "Cfr" => [0x0212D],
- "Chi" => [0x003A7],
- "CircleDot" => [0x02299],
- "CircleMinus" => [0x02296],
- "CirclePlus" => [0x02295],
- "CircleTimes" => [0x02297],
- "ClockwiseContourIntegral" => [0x02232],
- "CloseCurlyDoubleQuote" => [0x0201D],
- "CloseCurlyQuote" => [0x02019],
- "Colon" => [0x02237],
- "Colone" => [0x02A74],
- "Congruent" => [0x02261],
- "Conint" => [0x0222F],
- "ContourIntegral" => [0x0222E],
- "Copf" => [0x02102],
- "Coproduct" => [0x02210],
- "CounterClockwiseContourIntegral" => [0x02233],
- "Cross" => [0x02A2F],
- "Cscr" => [0x1D49E],
- "Cup" => [0x022D3],
- "CupCap" => [0x0224D],
- "DD" => [0x02145],
- "DDotrahd" => [0x02911],
- "DJcy" => [0x00402],
- "DScy" => [0x00405],
- "DZcy" => [0x0040F],
- "Dagger" => [0x02021],
- "Darr" => [0x021A1],
- "Dashv" => [0x02AE4],
- "Dcaron" => [0x0010E],
- "Dcy" => [0x00414],
- "Del" => [0x02207],
- "Delta" => [0x00394],
- "Dfr" => [0x1D507],
- "DiacriticalAcute" => [0x000B4],
- "DiacriticalDot" => [0x002D9],
- "DiacriticalDoubleAcute" => [0x002DD],
- "DiacriticalGrave" => [0x00060],
- "DiacriticalTilde" => [0x002DC],
- "Diamond" => [0x022C4],
- "DifferentialD" => [0x02146],
- "Dopf" => [0x1D53B],
- "Dot" => [0x000A8],
- "DotDot" => [0x020DC],
- "DotEqual" => [0x02250],
- "DoubleContourIntegral" => [0x0222F],
- "DoubleDot" => [0x000A8],
- "DoubleDownArrow" => [0x021D3],
- "DoubleLeftArrow" => [0x021D0],
- "DoubleLeftRightArrow" => [0x021D4],
- "DoubleLeftTee" => [0x02AE4],
- "DoubleLongLeftArrow" => [0x027F8],
- "DoubleLongLeftRightArrow" => [0x027FA],
- "DoubleLongRightArrow" => [0x027F9],
- "DoubleRightArrow" => [0x021D2],
- "DoubleRightTee" => [0x022A8],
- "DoubleUpArrow" => [0x021D1],
- "DoubleUpDownArrow" => [0x021D5],
- "DoubleVerticalBar" => [0x02225],
- "DownArrow" => [0x02193],
- "DownArrowBar" => [0x02913],
- "DownArrowUpArrow" => [0x021F5],
- "DownBreve" => [0x00311],
- "DownLeftRightVector" => [0x02950],
- "DownLeftTeeVector" => [0x0295E],
- "DownLeftVector" => [0x021BD],
- "DownLeftVectorBar" => [0x02956],
- "DownRightTeeVector" => [0x0295F],
- "DownRightVector" => [0x021C1],
- "DownRightVectorBar" => [0x02957],
- "DownTee" => [0x022A4],
- "DownTeeArrow" => [0x021A7],
- "Downarrow" => [0x021D3],
- "Dscr" => [0x1D49F],
- "Dstrok" => [0x00110],
- "ENG" => [0x0014A],
- "ETH" => [0x000D0],
- "Eacute" => [0x000C9],
- "Ecaron" => [0x0011A],
- "Ecirc" => [0x000CA],
- "Ecy" => [0x0042D],
- "Edot" => [0x00116],
- "Efr" => [0x1D508],
- "Egrave" => [0x000C8],
- "Element" => [0x02208],
- "Emacr" => [0x00112],
- "EmptySmallSquare" => [0x025FB],
- "EmptyVerySmallSquare" => [0x025AB],
- "Eogon" => [0x00118],
- "Eopf" => [0x1D53C],
- "Epsilon" => [0x00395],
- "Equal" => [0x02A75],
- "EqualTilde" => [0x02242],
- "Equilibrium" => [0x021CC],
- "Escr" => [0x02130],
- "Esim" => [0x02A73],
- "Eta" => [0x00397],
- "Euml" => [0x000CB],
- "Exists" => [0x02203],
- "ExponentialE" => [0x02147],
- "Fcy" => [0x00424],
- "Ffr" => [0x1D509],
- "FilledSmallSquare" => [0x025FC],
- "FilledVerySmallSquare" => [0x025AA],
- "Fopf" => [0x1D53D],
- "ForAll" => [0x02200],
- "Fouriertrf" => [0x02131],
- "Fscr" => [0x02131],
- "GJcy" => [0x00403],
- "GT" => [0x0003E],
- "Gamma" => [0x00393],
- "Gammad" => [0x003DC],
- "Gbreve" => [0x0011E],
- "Gcedil" => [0x00122],
- "Gcirc" => [0x0011C],
- "Gcy" => [0x00413],
- "Gdot" => [0x00120],
- "Gfr" => [0x1D50A],
- "Gg" => [0x022D9],
- "Gopf" => [0x1D53E],
- "GreaterEqual" => [0x02265],
- "GreaterEqualLess" => [0x022DB],
- "GreaterFullEqual" => [0x02267],
- "GreaterGreater" => [0x02AA2],
- "GreaterLess" => [0x02277],
- "GreaterSlantEqual" => [0x02A7E],
- "GreaterTilde" => [0x02273],
- "Gscr" => [0x1D4A2],
- "Gt" => [0x0226B],
- "HARDcy" => [0x0042A],
- "Hacek" => [0x002C7],
- "Hat" => [0x0005E],
- "Hcirc" => [0x00124],
- "Hfr" => [0x0210C],
- "HilbertSpace" => [0x0210B],
- "Hopf" => [0x0210D],
- "HorizontalLine" => [0x02500],
- "Hscr" => [0x0210B],
- "Hstrok" => [0x00126],
- "HumpDownHump" => [0x0224E],
- "HumpEqual" => [0x0224F],
- "IEcy" => [0x00415],
- "IJlig" => [0x00132],
- "IOcy" => [0x00401],
- "Iacute" => [0x000CD],
- "Icirc" => [0x000CE],
- "Icy" => [0x00418],
- "Idot" => [0x00130],
- "Ifr" => [0x02111],
- "Igrave" => [0x000CC],
- "Im" => [0x02111],
- "Imacr" => [0x0012A],
- "ImaginaryI" => [0x02148],
- "Implies" => [0x021D2],
- "Int" => [0x0222C],
- "Integral" => [0x0222B],
- "Intersection" => [0x022C2],
- "InvisibleComma" => [0x02063],
- "InvisibleTimes" => [0x02062],
- "Iogon" => [0x0012E],
- "Iopf" => [0x1D540],
- "Iota" => [0x00399],
- "Iscr" => [0x02110],
- "Itilde" => [0x00128],
- "Iukcy" => [0x00406],
- "Iuml" => [0x000CF],
- "Jcirc" => [0x00134],
- "Jcy" => [0x00419],
- "Jfr" => [0x1D50D],
- "Jopf" => [0x1D541],
- "Jscr" => [0x1D4A5],
- "Jsercy" => [0x00408],
- "Jukcy" => [0x00404],
- "KHcy" => [0x00425],
- "KJcy" => [0x0040C],
- "Kappa" => [0x0039A],
- "Kcedil" => [0x00136],
- "Kcy" => [0x0041A],
- "Kfr" => [0x1D50E],
- "Kopf" => [0x1D542],
- "Kscr" => [0x1D4A6],
- "LJcy" => [0x00409],
- "LT" => [0x0003C],
- "Lacute" => [0x00139],
- "Lambda" => [0x0039B],
- "Lang" => [0x027EA],
- "Laplacetrf" => [0x02112],
- "Larr" => [0x0219E],
- "Lcaron" => [0x0013D],
- "Lcedil" => [0x0013B],
- "Lcy" => [0x0041B],
- "LeftAngleBracket" => [0x027E8],
- "LeftArrow" => [0x02190],
- "LeftArrowBar" => [0x021E4],
- "LeftArrowRightArrow" => [0x021C6],
- "LeftCeiling" => [0x02308],
- "LeftDoubleBracket" => [0x027E6],
- "LeftDownTeeVector" => [0x02961],
- "LeftDownVector" => [0x021C3],
- "LeftDownVectorBar" => [0x02959],
- "LeftFloor" => [0x0230A],
- "LeftRightArrow" => [0x02194],
- "LeftRightVector" => [0x0294E],
- "LeftTee" => [0x022A3],
- "LeftTeeArrow" => [0x021A4],
- "LeftTeeVector" => [0x0295A],
- "LeftTriangle" => [0x022B2],
- "LeftTriangleBar" => [0x029CF],
- "LeftTriangleEqual" => [0x022B4],
- "LeftUpDownVector" => [0x02951],
- "LeftUpTeeVector" => [0x02960],
- "LeftUpVector" => [0x021BF],
- "LeftUpVectorBar" => [0x02958],
- "LeftVector" => [0x021BC],
- "LeftVectorBar" => [0x02952],
- "Leftarrow" => [0x021D0],
- "Leftrightarrow" => [0x021D4],
- "LessEqualGreater" => [0x022DA],
- "LessFullEqual" => [0x02266],
- "LessGreater" => [0x02276],
- "LessLess" => [0x02AA1],
- "LessSlantEqual" => [0x02A7D],
- "LessTilde" => [0x02272],
- "Lfr" => [0x1D50F],
- "Ll" => [0x022D8],
- "Lleftarrow" => [0x021DA],
- "Lmidot" => [0x0013F],
- "LongLeftArrow" => [0x027F5],
- "LongLeftRightArrow" => [0x027F7],
- "LongRightArrow" => [0x027F6],
- "Longleftarrow" => [0x027F8],
- "Longleftrightarrow" => [0x027FA],
- "Longrightarrow" => [0x027F9],
- "Lopf" => [0x1D543],
- "LowerLeftArrow" => [0x02199],
- "LowerRightArrow" => [0x02198],
- "Lscr" => [0x02112],
- "Lsh" => [0x021B0],
- "Lstrok" => [0x00141],
- "Lt" => [0x0226A],
- "Map" => [0x02905],
- "Mcy" => [0x0041C],
- "MediumSpace" => [0x0205F],
- "Mellintrf" => [0x02133],
- "Mfr" => [0x1D510],
- "MinusPlus" => [0x02213],
- "Mopf" => [0x1D544],
- "Mscr" => [0x02133],
- "Mu" => [0x0039C],
- "NJcy" => [0x0040A],
- "Nacute" => [0x00143],
- "Ncaron" => [0x00147],
- "Ncedil" => [0x00145],
- "Ncy" => [0x0041D],
- "NegativeMediumSpace" => [0x0200B],
- "NegativeThickSpace" => [0x0200B],
- "NegativeThinSpace" => [0x0200B],
- "NegativeVeryThinSpace" => [0x0200B],
- "NestedGreaterGreater" => [0x0226B],
- "NestedLessLess" => [0x0226A],
- "NewLine" => [0x0000A],
- "Nfr" => [0x1D511],
- "NoBreak" => [0x02060],
- "NonBreakingSpace" => [0x000A0],
- "Nopf" => [0x02115],
- "Not" => [0x02AEC],
- "NotCongruent" => [0x02262],
- "NotCupCap" => [0x0226D],
- "NotDoubleVerticalBar" => [0x02226],
- "NotElement" => [0x02209],
- "NotEqual" => [0x02260],
- "NotEqualTilde" => [0x02242, 0x00338],
- "NotExists" => [0x02204],
- "NotGreater" => [0x0226F],
- "NotGreaterEqual" => [0x02271],
- "NotGreaterFullEqual" => [0x02267, 0x00338],
- "NotGreaterGreater" => [0x0226B, 0x00338],
- "NotGreaterLess" => [0x02279],
- "NotGreaterSlantEqual" => [0x02A7E, 0x00338],
- "NotGreaterTilde" => [0x02275],
- "NotHumpDownHump" => [0x0224E, 0x00338],
- "NotHumpEqual" => [0x0224F, 0x00338],
- "NotLeftTriangle" => [0x022EA],
- "NotLeftTriangleBar" => [0x029CF, 0x00338],
- "NotLeftTriangleEqual" => [0x022EC],
- "NotLess" => [0x0226E],
- "NotLessEqual" => [0x02270],
- "NotLessGreater" => [0x02278],
- "NotLessLess" => [0x0226A, 0x00338],
- "NotLessSlantEqual" => [0x02A7D, 0x00338],
- "NotLessTilde" => [0x02274],
- "NotNestedGreaterGreater" => [0x02AA2, 0x00338],
- "NotNestedLessLess" => [0x02AA1, 0x00338],
- "NotPrecedes" => [0x02280],
- "NotPrecedesEqual" => [0x02AAF, 0x00338],
- "NotPrecedesSlantEqual" => [0x022E0],
- "NotReverseElement" => [0x0220C],
- "NotRightTriangle" => [0x022EB],
- "NotRightTriangleBar" => [0x029D0, 0x00338],
- "NotRightTriangleEqual" => [0x022ED],
- "NotSquareSubset" => [0x0228F, 0x00338],
- "NotSquareSubsetEqual" => [0x022E2],
- "NotSquareSuperset" => [0x02290, 0x00338],
- "NotSquareSupersetEqual" => [0x022E3],
- "NotSubset" => [0x02282, 0x020D2],
- "NotSubsetEqual" => [0x02288],
- "NotSucceeds" => [0x02281],
- "NotSucceedsEqual" => [0x02AB0, 0x00338],
- "NotSucceedsSlantEqual" => [0x022E1],
- "NotSucceedsTilde" => [0x0227F, 0x00338],
- "NotSuperset" => [0x02283, 0x020D2],
- "NotSupersetEqual" => [0x02289],
- "NotTilde" => [0x02241],
- "NotTildeEqual" => [0x02244],
- "NotTildeFullEqual" => [0x02247],
- "NotTildeTilde" => [0x02249],
- "NotVerticalBar" => [0x02224],
- "Nscr" => [0x1D4A9],
- "Ntilde" => [0x000D1],
- "Nu" => [0x0039D],
- "OElig" => [0x00152],
- "Oacute" => [0x000D3],
- "Ocirc" => [0x000D4],
- "Ocy" => [0x0041E],
- "Odblac" => [0x00150],
- "Ofr" => [0x1D512],
- "Ograve" => [0x000D2],
- "Omacr" => [0x0014C],
- "Omega" => [0x003A9],
- "Omicron" => [0x0039F],
- "Oopf" => [0x1D546],
- "OpenCurlyDoubleQuote" => [0x0201C],
- "OpenCurlyQuote" => [0x02018],
- "Or" => [0x02A54],
- "Oscr" => [0x1D4AA],
- "Oslash" => [0x000D8],
- "Otilde" => [0x000D5],
- "Otimes" => [0x02A37],
- "Ouml" => [0x000D6],
- "OverBar" => [0x0203E],
- "OverBrace" => [0x023DE],
- "OverBracket" => [0x023B4],
- "OverParenthesis" => [0x023DC],
- "PartialD" => [0x02202],
- "Pcy" => [0x0041F],
- "Pfr" => [0x1D513],
- "Phi" => [0x003A6],
- "Pi" => [0x003A0],
- "PlusMinus" => [0x000B1],
- "Poincareplane" => [0x0210C],
- "Popf" => [0x02119],
- "Pr" => [0x02ABB],
- "Precedes" => [0x0227A],
- "PrecedesEqual" => [0x02AAF],
- "PrecedesSlantEqual" => [0x0227C],
- "PrecedesTilde" => [0x0227E],
- "Prime" => [0x02033],
- "Product" => [0x0220F],
- "Proportion" => [0x02237],
- "Proportional" => [0x0221D],
- "Pscr" => [0x1D4AB],
- "Psi" => [0x003A8],
- "QUOT" => [0x00022],
- "Qfr" => [0x1D514],
- "Qopf" => [0x0211A],
- "Qscr" => [0x1D4AC],
- "RBarr" => [0x02910],
- "REG" => [0x000AE],
- "Racute" => [0x00154],
- "Rang" => [0x027EB],
- "Rarr" => [0x021A0],
- "Rarrtl" => [0x02916],
- "Rcaron" => [0x00158],
- "Rcedil" => [0x00156],
- "Rcy" => [0x00420],
- "Re" => [0x0211C],
- "ReverseElement" => [0x0220B],
- "ReverseEquilibrium" => [0x021CB],
- "ReverseUpEquilibrium" => [0x0296F],
- "Rfr" => [0x0211C],
- "Rho" => [0x003A1],
- "RightAngleBracket" => [0x027E9],
- "RightArrow" => [0x02192],
- "RightArrowBar" => [0x021E5],
- "RightArrowLeftArrow" => [0x021C4],
- "RightCeiling" => [0x02309],
- "RightDoubleBracket" => [0x027E7],
- "RightDownTeeVector" => [0x0295D],
- "RightDownVector" => [0x021C2],
- "RightDownVectorBar" => [0x02955],
- "RightFloor" => [0x0230B],
- "RightTee" => [0x022A2],
- "RightTeeArrow" => [0x021A6],
- "RightTeeVector" => [0x0295B],
- "RightTriangle" => [0x022B3],
- "RightTriangleBar" => [0x029D0],
- "RightTriangleEqual" => [0x022B5],
- "RightUpDownVector" => [0x0294F],
- "RightUpTeeVector" => [0x0295C],
- "RightUpVector" => [0x021BE],
- "RightUpVectorBar" => [0x02954],
- "RightVector" => [0x021C0],
- "RightVectorBar" => [0x02953],
- "Rightarrow" => [0x021D2],
- "Ropf" => [0x0211D],
- "RoundImplies" => [0x02970],
- "Rrightarrow" => [0x021DB],
- "Rscr" => [0x0211B],
- "Rsh" => [0x021B1],
- "RuleDelayed" => [0x029F4],
- "SHCHcy" => [0x00429],
- "SHcy" => [0x00428],
- "SOFTcy" => [0x0042C],
- "Sacute" => [0x0015A],
- "Sc" => [0x02ABC],
- "Scaron" => [0x00160],
- "Scedil" => [0x0015E],
- "Scirc" => [0x0015C],
- "Scy" => [0x00421],
- "Sfr" => [0x1D516],
- "ShortDownArrow" => [0x02193],
- "ShortLeftArrow" => [0x02190],
- "ShortRightArrow" => [0x02192],
- "ShortUpArrow" => [0x02191],
- "Sigma" => [0x003A3],
- "SmallCircle" => [0x02218],
- "Sopf" => [0x1D54A],
- "Sqrt" => [0x0221A],
- "Square" => [0x025A1],
- "SquareIntersection" => [0x02293],
- "SquareSubset" => [0x0228F],
- "SquareSubsetEqual" => [0x02291],
- "SquareSuperset" => [0x02290],
- "SquareSupersetEqual" => [0x02292],
- "SquareUnion" => [0x02294],
- "Sscr" => [0x1D4AE],
- "Star" => [0x022C6],
- "Sub" => [0x022D0],
- "Subset" => [0x022D0],
- "SubsetEqual" => [0x02286],
- "Succeeds" => [0x0227B],
- "SucceedsEqual" => [0x02AB0],
- "SucceedsSlantEqual" => [0x0227D],
- "SucceedsTilde" => [0x0227F],
- "SuchThat" => [0x0220B],
- "Sum" => [0x02211],
- "Sup" => [0x022D1],
- "Superset" => [0x02283],
- "SupersetEqual" => [0x02287],
- "Supset" => [0x022D1],
- "THORN" => [0x000DE],
- "TRADE" => [0x02122],
- "TSHcy" => [0x0040B],
- "TScy" => [0x00426],
- "Tab" => [0x00009],
- "Tau" => [0x003A4],
- "Tcaron" => [0x00164],
- "Tcedil" => [0x00162],
- "Tcy" => [0x00422],
- "Tfr" => [0x1D517],
- "Therefore" => [0x02234],
- "Theta" => [0x00398],
- "ThickSpace" => [0x0205F, 0x0200A],
- "ThinSpace" => [0x02009],
- "Tilde" => [0x0223C],
- "TildeEqual" => [0x02243],
- "TildeFullEqual" => [0x02245],
- "TildeTilde" => [0x02248],
- "Topf" => [0x1D54B],
- "TripleDot" => [0x020DB],
- "Tscr" => [0x1D4AF],
- "Tstrok" => [0x00166],
- "Uacute" => [0x000DA],
- "Uarr" => [0x0219F],
- "Uarrocir" => [0x02949],
- "Ubrcy" => [0x0040E],
- "Ubreve" => [0x0016C],
- "Ucirc" => [0x000DB],
- "Ucy" => [0x00423],
- "Udblac" => [0x00170],
- "Ufr" => [0x1D518],
- "Ugrave" => [0x000D9],
- "Umacr" => [0x0016A],
- "UnderBar" => [0x0005F],
- "UnderBrace" => [0x023DF],
- "UnderBracket" => [0x023B5],
- "UnderParenthesis" => [0x023DD],
- "Union" => [0x022C3],
- "UnionPlus" => [0x0228E],
- "Uogon" => [0x00172],
- "Uopf" => [0x1D54C],
- "UpArrow" => [0x02191],
- "UpArrowBar" => [0x02912],
- "UpArrowDownArrow" => [0x021C5],
- "UpDownArrow" => [0x02195],
- "UpEquilibrium" => [0x0296E],
- "UpTee" => [0x022A5],
- "UpTeeArrow" => [0x021A5],
- "Uparrow" => [0x021D1],
- "Updownarrow" => [0x021D5],
- "UpperLeftArrow" => [0x02196],
- "UpperRightArrow" => [0x02197],
- "Upsi" => [0x003D2],
- "Upsilon" => [0x003A5],
- "Uring" => [0x0016E],
- "Uscr" => [0x1D4B0],
- "Utilde" => [0x00168],
- "Uuml" => [0x000DC],
- "VDash" => [0x022AB],
- "Vbar" => [0x02AEB],
- "Vcy" => [0x00412],
- "Vdash" => [0x022A9],
- "Vdashl" => [0x02AE6],
- "Vee" => [0x022C1],
- "Verbar" => [0x02016],
- "Vert" => [0x02016],
- "VerticalBar" => [0x02223],
- "VerticalLine" => [0x0007C],
- "VerticalSeparator" => [0x02758],
- "VerticalTilde" => [0x02240],
- "VeryThinSpace" => [0x0200A],
- "Vfr" => [0x1D519],
- "Vopf" => [0x1D54D],
- "Vscr" => [0x1D4B1],
- "Vvdash" => [0x022AA],
- "Wcirc" => [0x00174],
- "Wedge" => [0x022C0],
- "Wfr" => [0x1D51A],
- "Wopf" => [0x1D54E],
- "Wscr" => [0x1D4B2],
- "Xfr" => [0x1D51B],
- "Xi" => [0x0039E],
- "Xopf" => [0x1D54F],
- "Xscr" => [0x1D4B3],
- "YAcy" => [0x0042F],
- "YIcy" => [0x00407],
- "YUcy" => [0x0042E],
- "Yacute" => [0x000DD],
- "Ycirc" => [0x00176],
- "Ycy" => [0x0042B],
- "Yfr" => [0x1D51C],
- "Yopf" => [0x1D550],
- "Yscr" => [0x1D4B4],
- "Yuml" => [0x00178],
- "ZHcy" => [0x00416],
- "Zacute" => [0x00179],
- "Zcaron" => [0x0017D],
- "Zcy" => [0x00417],
- "Zdot" => [0x0017B],
- "ZeroWidthSpace" => [0x0200B],
- "Zeta" => [0x00396],
- "Zfr" => [0x02128],
- "Zopf" => [0x02124],
- "Zscr" => [0x1D4B5],
- "aacute" => [0x000E1],
- "abreve" => [0x00103],
- "ac" => [0x0223E],
- "acE" => [0x0223E, 0x00333],
- "acd" => [0x0223F],
- "acirc" => [0x000E2],
- "acute" => [0x000B4],
- "acy" => [0x00430],
- "aelig" => [0x000E6],
- "af" => [0x02061],
- "afr" => [0x1D51E],
- "agrave" => [0x000E0],
- "alefsym" => [0x02135],
- "aleph" => [0x02135],
- "alpha" => [0x003B1],
- "amacr" => [0x00101],
- "amalg" => [0x02A3F],
- "amp" => [0x00026],
- "and" => [0x02227],
- "andand" => [0x02A55],
- "andd" => [0x02A5C],
- "andslope" => [0x02A58],
- "andv" => [0x02A5A],
- "ang" => [0x02220],
- "ange" => [0x029A4],
- "angle" => [0x02220],
- "angmsd" => [0x02221],
- "angmsdaa" => [0x029A8],
- "angmsdab" => [0x029A9],
- "angmsdac" => [0x029AA],
- "angmsdad" => [0x029AB],
- "angmsdae" => [0x029AC],
- "angmsdaf" => [0x029AD],
- "angmsdag" => [0x029AE],
- "angmsdah" => [0x029AF],
- "angrt" => [0x0221F],
- "angrtvb" => [0x022BE],
- "angrtvbd" => [0x0299D],
- "angsph" => [0x02222],
- "angst" => [0x000C5],
- "angzarr" => [0x0237C],
- "aogon" => [0x00105],
- "aopf" => [0x1D552],
- "ap" => [0x02248],
- "apE" => [0x02A70],
- "apacir" => [0x02A6F],
- "ape" => [0x0224A],
- "apid" => [0x0224B],
- "apos" => [0x00027],
- "approx" => [0x02248],
- "approxeq" => [0x0224A],
- "aring" => [0x000E5],
- "ascr" => [0x1D4B6],
- "ast" => [0x0002A],
- "asymp" => [0x02248],
- "asympeq" => [0x0224D],
- "atilde" => [0x000E3],
- "auml" => [0x000E4],
- "awconint" => [0x02233],
- "awint" => [0x02A11],
- "bNot" => [0x02AED],
- "backcong" => [0x0224C],
- "backepsilon" => [0x003F6],
- "backprime" => [0x02035],
- "backsim" => [0x0223D],
- "backsimeq" => [0x022CD],
- "barvee" => [0x022BD],
- "barwed" => [0x02305],
- "barwedge" => [0x02305],
- "bbrk" => [0x023B5],
- "bbrktbrk" => [0x023B6],
- "bcong" => [0x0224C],
- "bcy" => [0x00431],
- "bdquo" => [0x0201E],
- "becaus" => [0x02235],
- "because" => [0x02235],
- "bemptyv" => [0x029B0],
- "bepsi" => [0x003F6],
- "bernou" => [0x0212C],
- "beta" => [0x003B2],
- "beth" => [0x02136],
- "between" => [0x0226C],
- "bfr" => [0x1D51F],
- "bigcap" => [0x022C2],
- "bigcirc" => [0x025EF],
- "bigcup" => [0x022C3],
- "bigodot" => [0x02A00],
- "bigoplus" => [0x02A01],
- "bigotimes" => [0x02A02],
- "bigsqcup" => [0x02A06],
- "bigstar" => [0x02605],
- "bigtriangledown" => [0x025BD],
- "bigtriangleup" => [0x025B3],
- "biguplus" => [0x02A04],
- "bigvee" => [0x022C1],
- "bigwedge" => [0x022C0],
- "bkarow" => [0x0290D],
- "blacklozenge" => [0x029EB],
- "blacksquare" => [0x025AA],
- "blacktriangle" => [0x025B4],
- "blacktriangledown" => [0x025BE],
- "blacktriangleleft" => [0x025C2],
- "blacktriangleright" => [0x025B8],
- "blank" => [0x02423],
- "blk12" => [0x02592],
- "blk14" => [0x02591],
- "blk34" => [0x02593],
- "block" => [0x02588],
- "bne" => [0x0003D, 0x020E5],
- "bnequiv" => [0x02261, 0x020E5],
- "bnot" => [0x02310],
- "bopf" => [0x1D553],
- "bot" => [0x022A5],
- "bottom" => [0x022A5],
- "bowtie" => [0x022C8],
- "boxDL" => [0x02557],
- "boxDR" => [0x02554],
- "boxDl" => [0x02556],
- "boxDr" => [0x02553],
- "boxH" => [0x02550],
- "boxHD" => [0x02566],
- "boxHU" => [0x02569],
- "boxHd" => [0x02564],
- "boxHu" => [0x02567],
- "boxUL" => [0x0255D],
- "boxUR" => [0x0255A],
- "boxUl" => [0x0255C],
- "boxUr" => [0x02559],
- "boxV" => [0x02551],
- "boxVH" => [0x0256C],
- "boxVL" => [0x02563],
- "boxVR" => [0x02560],
- "boxVh" => [0x0256B],
- "boxVl" => [0x02562],
- "boxVr" => [0x0255F],
- "boxbox" => [0x029C9],
- "boxdL" => [0x02555],
- "boxdR" => [0x02552],
- "boxdl" => [0x02510],
- "boxdr" => [0x0250C],
- "boxh" => [0x02500],
- "boxhD" => [0x02565],
- "boxhU" => [0x02568],
- "boxhd" => [0x0252C],
- "boxhu" => [0x02534],
- "boxminus" => [0x0229F],
- "boxplus" => [0x0229E],
- "boxtimes" => [0x022A0],
- "boxuL" => [0x0255B],
- "boxuR" => [0x02558],
- "boxul" => [0x02518],
- "boxur" => [0x02514],
- "boxv" => [0x02502],
- "boxvH" => [0x0256A],
- "boxvL" => [0x02561],
- "boxvR" => [0x0255E],
- "boxvh" => [0x0253C],
- "boxvl" => [0x02524],
- "boxvr" => [0x0251C],
- "bprime" => [0x02035],
- "breve" => [0x002D8],
- "brvbar" => [0x000A6],
- "bscr" => [0x1D4B7],
- "bsemi" => [0x0204F],
- "bsim" => [0x0223D],
- "bsime" => [0x022CD],
- "bsol" => [0x0005C],
- "bsolb" => [0x029C5],
- "bsolhsub" => [0x027C8],
- "bull" => [0x02022],
- "bullet" => [0x02022],
- "bump" => [0x0224E],
- "bumpE" => [0x02AAE],
- "bumpe" => [0x0224F],
- "bumpeq" => [0x0224F],
- "cacute" => [0x00107],
- "cap" => [0x02229],
- "capand" => [0x02A44],
- "capbrcup" => [0x02A49],
- "capcap" => [0x02A4B],
- "capcup" => [0x02A47],
- "capdot" => [0x02A40],
- "caps" => [0x02229, 0x0FE00],
- "caret" => [0x02041],
- "caron" => [0x002C7],
- "ccaps" => [0x02A4D],
- "ccaron" => [0x0010D],
- "ccedil" => [0x000E7],
- "ccirc" => [0x00109],
- "ccups" => [0x02A4C],
- "ccupssm" => [0x02A50],
- "cdot" => [0x0010B],
- "cedil" => [0x000B8],
- "cemptyv" => [0x029B2],
- "cent" => [0x000A2],
- "centerdot" => [0x000B7],
- "cfr" => [0x1D520],
- "chcy" => [0x00447],
- "check" => [0x02713],
- "checkmark" => [0x02713],
- "chi" => [0x003C7],
- "cir" => [0x025CB],
- "cirE" => [0x029C3],
- "circ" => [0x002C6],
- "circeq" => [0x02257],
- "circlearrowleft" => [0x021BA],
- "circlearrowright" => [0x021BB],
- "circledR" => [0x000AE],
- "circledS" => [0x024C8],
- "circledast" => [0x0229B],
- "circledcirc" => [0x0229A],
- "circleddash" => [0x0229D],
- "cire" => [0x02257],
- "cirfnint" => [0x02A10],
- "cirmid" => [0x02AEF],
- "cirscir" => [0x029C2],
- "clubs" => [0x02663],
- "clubsuit" => [0x02663],
- "colon" => [0x0003A],
- "colone" => [0x02254],
- "coloneq" => [0x02254],
- "comma" => [0x0002C],
- "commat" => [0x00040],
- "comp" => [0x02201],
- "compfn" => [0x02218],
- "complement" => [0x02201],
- "complexes" => [0x02102],
- "cong" => [0x02245],
- "congdot" => [0x02A6D],
- "conint" => [0x0222E],
- "copf" => [0x1D554],
- "coprod" => [0x02210],
- "copy" => [0x000A9],
- "copysr" => [0x02117],
- "crarr" => [0x021B5],
- "cross" => [0x02717],
- "cscr" => [0x1D4B8],
- "csub" => [0x02ACF],
- "csube" => [0x02AD1],
- "csup" => [0x02AD0],
- "csupe" => [0x02AD2],
- "ctdot" => [0x022EF],
- "cudarrl" => [0x02938],
- "cudarrr" => [0x02935],
- "cuepr" => [0x022DE],
- "cuesc" => [0x022DF],
- "cularr" => [0x021B6],
- "cularrp" => [0x0293D],
- "cup" => [0x0222A],
- "cupbrcap" => [0x02A48],
- "cupcap" => [0x02A46],
- "cupcup" => [0x02A4A],
- "cupdot" => [0x0228D],
- "cupor" => [0x02A45],
- "cups" => [0x0222A, 0x0FE00],
- "curarr" => [0x021B7],
- "curarrm" => [0x0293C],
- "curlyeqprec" => [0x022DE],
- "curlyeqsucc" => [0x022DF],
- "curlyvee" => [0x022CE],
- "curlywedge" => [0x022CF],
- "curren" => [0x000A4],
- "curvearrowleft" => [0x021B6],
- "curvearrowright" => [0x021B7],
- "cuvee" => [0x022CE],
- "cuwed" => [0x022CF],
- "cwconint" => [0x02232],
- "cwint" => [0x02231],
- "cylcty" => [0x0232D],
- "dArr" => [0x021D3],
- "dHar" => [0x02965],
- "dagger" => [0x02020],
- "daleth" => [0x02138],
- "darr" => [0x02193],
- "dash" => [0x02010],
- "dashv" => [0x022A3],
- "dbkarow" => [0x0290F],
- "dblac" => [0x002DD],
- "dcaron" => [0x0010F],
- "dcy" => [0x00434],
- "dd" => [0x02146],
- "ddagger" => [0x02021],
- "ddarr" => [0x021CA],
- "ddotseq" => [0x02A77],
- "deg" => [0x000B0],
- "delta" => [0x003B4],
- "demptyv" => [0x029B1],
- "dfisht" => [0x0297F],
- "dfr" => [0x1D521],
- "dharl" => [0x021C3],
- "dharr" => [0x021C2],
- "diam" => [0x022C4],
- "diamond" => [0x022C4],
- "diamondsuit" => [0x02666],
- "diams" => [0x02666],
- "die" => [0x000A8],
- "digamma" => [0x003DD],
- "disin" => [0x022F2],
- "div" => [0x000F7],
- "divide" => [0x000F7],
- "divideontimes" => [0x022C7],
- "divonx" => [0x022C7],
- "djcy" => [0x00452],
- "dlcorn" => [0x0231E],
- "dlcrop" => [0x0230D],
- "dollar" => [0x00024],
- "dopf" => [0x1D555],
- "dot" => [0x002D9],
- "doteq" => [0x02250],
- "doteqdot" => [0x02251],
- "dotminus" => [0x02238],
- "dotplus" => [0x02214],
- "dotsquare" => [0x022A1],
- "doublebarwedge" => [0x02306],
- "downarrow" => [0x02193],
- "downdownarrows" => [0x021CA],
- "downharpoonleft" => [0x021C3],
- "downharpoonright" => [0x021C2],
- "drbkarow" => [0x02910],
- "drcorn" => [0x0231F],
- "drcrop" => [0x0230C],
- "dscr" => [0x1D4B9],
- "dscy" => [0x00455],
- "dsol" => [0x029F6],
- "dstrok" => [0x00111],
- "dtdot" => [0x022F1],
- "dtri" => [0x025BF],
- "dtrif" => [0x025BE],
- "duarr" => [0x021F5],
- "duhar" => [0x0296F],
- "dwangle" => [0x029A6],
- "dzcy" => [0x0045F],
- "dzigrarr" => [0x027FF],
- "eDDot" => [0x02A77],
- "eDot" => [0x02251],
- "eacute" => [0x000E9],
- "easter" => [0x02A6E],
- "ecaron" => [0x0011B],
- "ecir" => [0x02256],
- "ecirc" => [0x000EA],
- "ecolon" => [0x02255],
- "ecy" => [0x0044D],
- "edot" => [0x00117],
- "ee" => [0x02147],
- "efDot" => [0x02252],
- "efr" => [0x1D522],
- "eg" => [0x02A9A],
- "egrave" => [0x000E8],
- "egs" => [0x02A96],
- "egsdot" => [0x02A98],
- "el" => [0x02A99],
- "elinters" => [0x023E7],
- "ell" => [0x02113],
- "els" => [0x02A95],
- "elsdot" => [0x02A97],
- "emacr" => [0x00113],
- "empty" => [0x02205],
- "emptyset" => [0x02205],
- "emptyv" => [0x02205],
- "emsp" => [0x02003],
- "emsp13" => [0x02004],
- "emsp14" => [0x02005],
- "eng" => [0x0014B],
- "ensp" => [0x02002],
- "eogon" => [0x00119],
- "eopf" => [0x1D556],
- "epar" => [0x022D5],
- "eparsl" => [0x029E3],
- "eplus" => [0x02A71],
- "epsi" => [0x003B5],
- "epsilon" => [0x003B5],
- "epsiv" => [0x003F5],
- "eqcirc" => [0x02256],
- "eqcolon" => [0x02255],
- "eqsim" => [0x02242],
- "eqslantgtr" => [0x02A96],
- "eqslantless" => [0x02A95],
- "equals" => [0x0003D],
- "equest" => [0x0225F],
- "equiv" => [0x02261],
- "equivDD" => [0x02A78],
- "eqvparsl" => [0x029E5],
- "erDot" => [0x02253],
- "erarr" => [0x02971],
- "escr" => [0x0212F],
- "esdot" => [0x02250],
- "esim" => [0x02242],
- "eta" => [0x003B7],
- "eth" => [0x000F0],
- "euml" => [0x000EB],
- "euro" => [0x020AC],
- "excl" => [0x00021],
- "exist" => [0x02203],
- "expectation" => [0x02130],
- "exponentiale" => [0x02147],
- "fallingdotseq" => [0x02252],
- "fcy" => [0x00444],
- "female" => [0x02640],
- "ffilig" => [0x0FB03],
- "fflig" => [0x0FB00],
- "ffllig" => [0x0FB04],
- "ffr" => [0x1D523],
- "filig" => [0x0FB01],
- "fjlig" => [0x00066, 0x0006A],
- "flat" => [0x0266D],
- "fllig" => [0x0FB02],
- "fltns" => [0x025B1],
- "fnof" => [0x00192],
- "fopf" => [0x1D557],
- "forall" => [0x02200],
- "fork" => [0x022D4],
- "forkv" => [0x02AD9],
- "fpartint" => [0x02A0D],
- "frac12" => [0x000BD],
- "frac13" => [0x02153],
- "frac14" => [0x000BC],
- "frac15" => [0x02155],
- "frac16" => [0x02159],
- "frac18" => [0x0215B],
- "frac23" => [0x02154],
- "frac25" => [0x02156],
- "frac34" => [0x000BE],
- "frac35" => [0x02157],
- "frac38" => [0x0215C],
- "frac45" => [0x02158],
- "frac56" => [0x0215A],
- "frac58" => [0x0215D],
- "frac78" => [0x0215E],
- "frasl" => [0x02044],
- "frown" => [0x02322],
- "fscr" => [0x1D4BB],
- "gE" => [0x02267],
- "gEl" => [0x02A8C],
- "gacute" => [0x001F5],
- "gamma" => [0x003B3],
- "gammad" => [0x003DD],
- "gap" => [0x02A86],
- "gbreve" => [0x0011F],
- "gcirc" => [0x0011D],
- "gcy" => [0x00433],
- "gdot" => [0x00121],
- "ge" => [0x02265],
- "gel" => [0x022DB],
- "geq" => [0x02265],
- "geqq" => [0x02267],
- "geqslant" => [0x02A7E],
- "ges" => [0x02A7E],
- "gescc" => [0x02AA9],
- "gesdot" => [0x02A80],
- "gesdoto" => [0x02A82],
- "gesdotol" => [0x02A84],
- "gesl" => [0x022DB, 0x0FE00],
- "gesles" => [0x02A94],
- "gfr" => [0x1D524],
- "gg" => [0x0226B],
- "ggg" => [0x022D9],
- "gimel" => [0x02137],
- "gjcy" => [0x00453],
- "gl" => [0x02277],
- "glE" => [0x02A92],
- "gla" => [0x02AA5],
- "glj" => [0x02AA4],
- "gnE" => [0x02269],
- "gnap" => [0x02A8A],
- "gnapprox" => [0x02A8A],
- "gne" => [0x02A88],
- "gneq" => [0x02A88],
- "gneqq" => [0x02269],
- "gnsim" => [0x022E7],
- "gopf" => [0x1D558],
- "grave" => [0x00060],
- "gscr" => [0x0210A],
- "gsim" => [0x02273],
- "gsime" => [0x02A8E],
- "gsiml" => [0x02A90],
- "gt" => [0x0003E],
- "gtcc" => [0x02AA7],
- "gtcir" => [0x02A7A],
- "gtdot" => [0x022D7],
- "gtlPar" => [0x02995],
- "gtquest" => [0x02A7C],
- "gtrapprox" => [0x02A86],
- "gtrarr" => [0x02978],
- "gtrdot" => [0x022D7],
- "gtreqless" => [0x022DB],
- "gtreqqless" => [0x02A8C],
- "gtrless" => [0x02277],
- "gtrsim" => [0x02273],
- "gvertneqq" => [0x02269, 0x0FE00],
- "gvnE" => [0x02269, 0x0FE00],
- "hArr" => [0x021D4],
- "hairsp" => [0x0200A],
- "half" => [0x000BD],
- "hamilt" => [0x0210B],
- "hardcy" => [0x0044A],
- "harr" => [0x02194],
- "harrcir" => [0x02948],
- "harrw" => [0x021AD],
- "hbar" => [0x0210F],
- "hcirc" => [0x00125],
- "hearts" => [0x02665],
- "heartsuit" => [0x02665],
- "hellip" => [0x02026],
- "hercon" => [0x022B9],
- "hfr" => [0x1D525],
- "hksearow" => [0x02925],
- "hkswarow" => [0x02926],
- "hoarr" => [0x021FF],
- "homtht" => [0x0223B],
- "hookleftarrow" => [0x021A9],
- "hookrightarrow" => [0x021AA],
- "hopf" => [0x1D559],
- "horbar" => [0x02015],
- "hscr" => [0x1D4BD],
- "hslash" => [0x0210F],
- "hstrok" => [0x00127],
- "hybull" => [0x02043],
- "hyphen" => [0x02010],
- "iacute" => [0x000ED],
- "ic" => [0x02063],
- "icirc" => [0x000EE],
- "icy" => [0x00438],
- "iecy" => [0x00435],
- "iexcl" => [0x000A1],
- "iff" => [0x021D4],
- "ifr" => [0x1D526],
- "igrave" => [0x000EC],
- "ii" => [0x02148],
- "iiiint" => [0x02A0C],
- "iiint" => [0x0222D],
- "iinfin" => [0x029DC],
- "iiota" => [0x02129],
- "ijlig" => [0x00133],
- "imacr" => [0x0012B],
- "image" => [0x02111],
- "imagline" => [0x02110],
- "imagpart" => [0x02111],
- "imath" => [0x00131],
- "imof" => [0x022B7],
- "imped" => [0x001B5],
- "in" => [0x02208],
- "incare" => [0x02105],
- "infin" => [0x0221E],
- "infintie" => [0x029DD],
- "inodot" => [0x00131],
- "int" => [0x0222B],
- "intcal" => [0x022BA],
- "integers" => [0x02124],
- "intercal" => [0x022BA],
- "intlarhk" => [0x02A17],
- "intprod" => [0x02A3C],
- "iocy" => [0x00451],
- "iogon" => [0x0012F],
- "iopf" => [0x1D55A],
- "iota" => [0x003B9],
- "iprod" => [0x02A3C],
- "iquest" => [0x000BF],
- "iscr" => [0x1D4BE],
- "isin" => [0x02208],
- "isinE" => [0x022F9],
- "isindot" => [0x022F5],
- "isins" => [0x022F4],
- "isinsv" => [0x022F3],
- "isinv" => [0x02208],
- "it" => [0x02062],
- "itilde" => [0x00129],
- "iukcy" => [0x00456],
- "iuml" => [0x000EF],
- "jcirc" => [0x00135],
- "jcy" => [0x00439],
- "jfr" => [0x1D527],
- "jmath" => [0x00237],
- "jopf" => [0x1D55B],
- "jscr" => [0x1D4BF],
- "jsercy" => [0x00458],
- "jukcy" => [0x00454],
- "kappa" => [0x003BA],
- "kappav" => [0x003F0],
- "kcedil" => [0x00137],
- "kcy" => [0x0043A],
- "kfr" => [0x1D528],
- "kgreen" => [0x00138],
- "khcy" => [0x00445],
- "kjcy" => [0x0045C],
- "kopf" => [0x1D55C],
- "kscr" => [0x1D4C0],
- "lAarr" => [0x021DA],
- "lArr" => [0x021D0],
- "lAtail" => [0x0291B],
- "lBarr" => [0x0290E],
- "lE" => [0x02266],
- "lEg" => [0x02A8B],
- "lHar" => [0x02962],
- "lacute" => [0x0013A],
- "laemptyv" => [0x029B4],
- "lagran" => [0x02112],
- "lambda" => [0x003BB],
- "lang" => [0x027E8],
- "langd" => [0x02991],
- "langle" => [0x027E8],
- "lap" => [0x02A85],
- "laquo" => [0x000AB],
- "larr" => [0x02190],
- "larrb" => [0x021E4],
- "larrbfs" => [0x0291F],
- "larrfs" => [0x0291D],
- "larrhk" => [0x021A9],
- "larrlp" => [0x021AB],
- "larrpl" => [0x02939],
- "larrsim" => [0x02973],
- "larrtl" => [0x021A2],
- "lat" => [0x02AAB],
- "latail" => [0x02919],
- "late" => [0x02AAD],
- "lates" => [0x02AAD, 0x0FE00],
- "lbarr" => [0x0290C],
- "lbbrk" => [0x02772],
- "lbrace" => [0x0007B],
- "lbrack" => [0x0005B],
- "lbrke" => [0x0298B],
- "lbrksld" => [0x0298F],
- "lbrkslu" => [0x0298D],
- "lcaron" => [0x0013E],
- "lcedil" => [0x0013C],
- "lceil" => [0x02308],
- "lcub" => [0x0007B],
- "lcy" => [0x0043B],
- "ldca" => [0x02936],
- "ldquo" => [0x0201C],
- "ldquor" => [0x0201E],
- "ldrdhar" => [0x02967],
- "ldrushar" => [0x0294B],
- "ldsh" => [0x021B2],
- "le" => [0x02264],
- "leftarrow" => [0x02190],
- "leftarrowtail" => [0x021A2],
- "leftharpoondown" => [0x021BD],
- "leftharpoonup" => [0x021BC],
- "leftleftarrows" => [0x021C7],
- "leftrightarrow" => [0x02194],
- "leftrightarrows" => [0x021C6],
- "leftrightharpoons" => [0x021CB],
- "leftrightsquigarrow" => [0x021AD],
- "leftthreetimes" => [0x022CB],
- "leg" => [0x022DA],
- "leq" => [0x02264],
- "leqq" => [0x02266],
- "leqslant" => [0x02A7D],
- "les" => [0x02A7D],
- "lescc" => [0x02AA8],
- "lesdot" => [0x02A7F],
- "lesdoto" => [0x02A81],
- "lesdotor" => [0x02A83],
- "lesg" => [0x022DA, 0x0FE00],
- "lesges" => [0x02A93],
- "lessapprox" => [0x02A85],
- "lessdot" => [0x022D6],
- "lesseqgtr" => [0x022DA],
- "lesseqqgtr" => [0x02A8B],
- "lessgtr" => [0x02276],
- "lesssim" => [0x02272],
- "lfisht" => [0x0297C],
- "lfloor" => [0x0230A],
- "lfr" => [0x1D529],
- "lg" => [0x02276],
- "lgE" => [0x02A91],
- "lhard" => [0x021BD],
- "lharu" => [0x021BC],
- "lharul" => [0x0296A],
- "lhblk" => [0x02584],
- "ljcy" => [0x00459],
- "ll" => [0x0226A],
- "llarr" => [0x021C7],
- "llcorner" => [0x0231E],
- "llhard" => [0x0296B],
- "lltri" => [0x025FA],
- "lmidot" => [0x00140],
- "lmoust" => [0x023B0],
- "lmoustache" => [0x023B0],
- "lnE" => [0x02268],
- "lnap" => [0x02A89],
- "lnapprox" => [0x02A89],
- "lne" => [0x02A87],
- "lneq" => [0x02A87],
- "lneqq" => [0x02268],
- "lnsim" => [0x022E6],
- "loang" => [0x027EC],
- "loarr" => [0x021FD],
- "lobrk" => [0x027E6],
- "longleftarrow" => [0x027F5],
- "longleftrightarrow" => [0x027F7],
- "longmapsto" => [0x027FC],
- "longrightarrow" => [0x027F6],
- "looparrowleft" => [0x021AB],
- "looparrowright" => [0x021AC],
- "lopar" => [0x02985],
- "lopf" => [0x1D55D],
- "loplus" => [0x02A2D],
- "lotimes" => [0x02A34],
- "lowast" => [0x02217],
- "lowbar" => [0x0005F],
- "loz" => [0x025CA],
- "lozenge" => [0x025CA],
- "lozf" => [0x029EB],
- "lpar" => [0x00028],
- "lparlt" => [0x02993],
- "lrarr" => [0x021C6],
- "lrcorner" => [0x0231F],
- "lrhar" => [0x021CB],
- "lrhard" => [0x0296D],
- "lrm" => [0x0200E],
- "lrtri" => [0x022BF],
- "lsaquo" => [0x02039],
- "lscr" => [0x1D4C1],
- "lsh" => [0x021B0],
- "lsim" => [0x02272],
- "lsime" => [0x02A8D],
- "lsimg" => [0x02A8F],
- "lsqb" => [0x0005B],
- "lsquo" => [0x02018],
- "lsquor" => [0x0201A],
- "lstrok" => [0x00142],
- "lt" => [0x0003C],
- "ltcc" => [0x02AA6],
- "ltcir" => [0x02A79],
- "ltdot" => [0x022D6],
- "lthree" => [0x022CB],
- "ltimes" => [0x022C9],
- "ltlarr" => [0x02976],
- "ltquest" => [0x02A7B],
- "ltrPar" => [0x02996],
- "ltri" => [0x025C3],
- "ltrie" => [0x022B4],
- "ltrif" => [0x025C2],
- "lurdshar" => [0x0294A],
- "luruhar" => [0x02966],
- "lvertneqq" => [0x02268, 0x0FE00],
- "lvnE" => [0x02268, 0x0FE00],
- "mDDot" => [0x0223A],
- "macr" => [0x000AF],
- "male" => [0x02642],
- "malt" => [0x02720],
- "maltese" => [0x02720],
- "map" => [0x021A6],
- "mapsto" => [0x021A6],
- "mapstodown" => [0x021A7],
- "mapstoleft" => [0x021A4],
- "mapstoup" => [0x021A5],
- "marker" => [0x025AE],
- "mcomma" => [0x02A29],
- "mcy" => [0x0043C],
- "mdash" => [0x02014],
- "measuredangle" => [0x02221],
- "mfr" => [0x1D52A],
- "mho" => [0x02127],
- "micro" => [0x000B5],
- "mid" => [0x02223],
- "midast" => [0x0002A],
- "midcir" => [0x02AF0],
- "middot" => [0x000B7],
- "minus" => [0x02212],
- "minusb" => [0x0229F],
- "minusd" => [0x02238],
- "minusdu" => [0x02A2A],
- "mlcp" => [0x02ADB],
- "mldr" => [0x02026],
- "mnplus" => [0x02213],
- "models" => [0x022A7],
- "mopf" => [0x1D55E],
- "mp" => [0x02213],
- "mscr" => [0x1D4C2],
- "mstpos" => [0x0223E],
- "mu" => [0x003BC],
- "multimap" => [0x022B8],
- "mumap" => [0x022B8],
- "nGg" => [0x022D9, 0x00338],
- "nGt" => [0x0226B, 0x020D2],
- "nGtv" => [0x0226B, 0x00338],
- "nLeftarrow" => [0x021CD],
- "nLeftrightarrow" => [0x021CE],
- "nLl" => [0x022D8, 0x00338],
- "nLt" => [0x0226A, 0x020D2],
- "nLtv" => [0x0226A, 0x00338],
- "nRightarrow" => [0x021CF],
- "nVDash" => [0x022AF],
- "nVdash" => [0x022AE],
- "nabla" => [0x02207],
- "nacute" => [0x00144],
- "nang" => [0x02220, 0x020D2],
- "nap" => [0x02249],
- "napE" => [0x02A70, 0x00338],
- "napid" => [0x0224B, 0x00338],
- "napos" => [0x00149],
- "napprox" => [0x02249],
- "natur" => [0x0266E],
- "natural" => [0x0266E],
- "naturals" => [0x02115],
- "nbsp" => [0x000A0],
- "nbump" => [0x0224E, 0x00338],
- "nbumpe" => [0x0224F, 0x00338],
- "ncap" => [0x02A43],
- "ncaron" => [0x00148],
- "ncedil" => [0x00146],
- "ncong" => [0x02247],
- "ncongdot" => [0x02A6D, 0x00338],
- "ncup" => [0x02A42],
- "ncy" => [0x0043D],
- "ndash" => [0x02013],
- "ne" => [0x02260],
- "neArr" => [0x021D7],
- "nearhk" => [0x02924],
- "nearr" => [0x02197],
- "nearrow" => [0x02197],
- "nedot" => [0x02250, 0x00338],
- "nequiv" => [0x02262],
- "nesear" => [0x02928],
- "nesim" => [0x02242, 0x00338],
- "nexist" => [0x02204],
- "nexists" => [0x02204],
- "nfr" => [0x1D52B],
- "ngE" => [0x02267, 0x00338],
- "nge" => [0x02271],
- "ngeq" => [0x02271],
- "ngeqq" => [0x02267, 0x00338],
- "ngeqslant" => [0x02A7E, 0x00338],
- "nges" => [0x02A7E, 0x00338],
- "ngsim" => [0x02275],
- "ngt" => [0x0226F],
- "ngtr" => [0x0226F],
- "nhArr" => [0x021CE],
- "nharr" => [0x021AE],
- "nhpar" => [0x02AF2],
- "ni" => [0x0220B],
- "nis" => [0x022FC],
- "nisd" => [0x022FA],
- "niv" => [0x0220B],
- "njcy" => [0x0045A],
- "nlArr" => [0x021CD],
- "nlE" => [0x02266, 0x00338],
- "nlarr" => [0x0219A],
- "nldr" => [0x02025],
- "nle" => [0x02270],
- "nleftarrow" => [0x0219A],
- "nleftrightarrow" => [0x021AE],
- "nleq" => [0x02270],
- "nleqq" => [0x02266, 0x00338],
- "nleqslant" => [0x02A7D, 0x00338],
- "nles" => [0x02A7D, 0x00338],
- "nless" => [0x0226E],
- "nlsim" => [0x02274],
- "nlt" => [0x0226E],
- "nltri" => [0x022EA],
- "nltrie" => [0x022EC],
- "nmid" => [0x02224],
- "nopf" => [0x1D55F],
- "not" => [0x000AC],
- "notin" => [0x02209],
- "notinE" => [0x022F9, 0x00338],
- "notindot" => [0x022F5, 0x00338],
- "notinva" => [0x02209],
- "notinvb" => [0x022F7],
- "notinvc" => [0x022F6],
- "notni" => [0x0220C],
- "notniva" => [0x0220C],
- "notnivb" => [0x022FE],
- "notnivc" => [0x022FD],
- "npar" => [0x02226],
- "nparallel" => [0x02226],
- "nparsl" => [0x02AFD, 0x020E5],
- "npart" => [0x02202, 0x00338],
- "npolint" => [0x02A14],
- "npr" => [0x02280],
- "nprcue" => [0x022E0],
- "npre" => [0x02AAF, 0x00338],
- "nprec" => [0x02280],
- "npreceq" => [0x02AAF, 0x00338],
- "nrArr" => [0x021CF],
- "nrarr" => [0x0219B],
- "nrarrc" => [0x02933, 0x00338],
- "nrarrw" => [0x0219D, 0x00338],
- "nrightarrow" => [0x0219B],
- "nrtri" => [0x022EB],
- "nrtrie" => [0x022ED],
- "nsc" => [0x02281],
- "nsccue" => [0x022E1],
- "nsce" => [0x02AB0, 0x00338],
- "nscr" => [0x1D4C3],
- "nshortmid" => [0x02224],
- "nshortparallel" => [0x02226],
- "nsim" => [0x02241],
- "nsime" => [0x02244],
- "nsimeq" => [0x02244],
- "nsmid" => [0x02224],
- "nspar" => [0x02226],
- "nsqsube" => [0x022E2],
- "nsqsupe" => [0x022E3],
- "nsub" => [0x02284],
- "nsubE" => [0x02AC5, 0x00338],
- "nsube" => [0x02288],
- "nsubset" => [0x02282, 0x020D2],
- "nsubseteq" => [0x02288],
- "nsubseteqq" => [0x02AC5, 0x00338],
- "nsucc" => [0x02281],
- "nsucceq" => [0x02AB0, 0x00338],
- "nsup" => [0x02285],
- "nsupE" => [0x02AC6, 0x00338],
- "nsupe" => [0x02289],
- "nsupset" => [0x02283, 0x020D2],
- "nsupseteq" => [0x02289],
- "nsupseteqq" => [0x02AC6, 0x00338],
- "ntgl" => [0x02279],
- "ntilde" => [0x000F1],
- "ntlg" => [0x02278],
- "ntriangleleft" => [0x022EA],
- "ntrianglelefteq" => [0x022EC],
- "ntriangleright" => [0x022EB],
- "ntrianglerighteq" => [0x022ED],
- "nu" => [0x003BD],
- "num" => [0x00023],
- "numero" => [0x02116],
- "numsp" => [0x02007],
- "nvDash" => [0x022AD],
- "nvHarr" => [0x02904],
- "nvap" => [0x0224D, 0x020D2],
- "nvdash" => [0x022AC],
- "nvge" => [0x02265, 0x020D2],
- "nvgt" => [0x0003E, 0x020D2],
- "nvinfin" => [0x029DE],
- "nvlArr" => [0x02902],
- "nvle" => [0x02264, 0x020D2],
- "nvlt" => [0x0003C, 0x020D2],
- "nvltrie" => [0x022B4, 0x020D2],
- "nvrArr" => [0x02903],
- "nvrtrie" => [0x022B5, 0x020D2],
- "nvsim" => [0x0223C, 0x020D2],
- "nwArr" => [0x021D6],
- "nwarhk" => [0x02923],
- "nwarr" => [0x02196],
- "nwarrow" => [0x02196],
- "nwnear" => [0x02927],
- "oS" => [0x024C8],
- "oacute" => [0x000F3],
- "oast" => [0x0229B],
- "ocir" => [0x0229A],
- "ocirc" => [0x000F4],
- "ocy" => [0x0043E],
- "odash" => [0x0229D],
- "odblac" => [0x00151],
- "odiv" => [0x02A38],
- "odot" => [0x02299],
- "odsold" => [0x029BC],
- "oelig" => [0x00153],
- "ofcir" => [0x029BF],
- "ofr" => [0x1D52C],
- "ogon" => [0x002DB],
- "ograve" => [0x000F2],
- "ogt" => [0x029C1],
- "ohbar" => [0x029B5],
- "ohm" => [0x003A9],
- "oint" => [0x0222E],
- "olarr" => [0x021BA],
- "olcir" => [0x029BE],
- "olcross" => [0x029BB],
- "oline" => [0x0203E],
- "olt" => [0x029C0],
- "omacr" => [0x0014D],
- "omega" => [0x003C9],
- "omicron" => [0x003BF],
- "omid" => [0x029B6],
- "ominus" => [0x02296],
- "oopf" => [0x1D560],
- "opar" => [0x029B7],
- "operp" => [0x029B9],
- "oplus" => [0x02295],
- "or" => [0x02228],
- "orarr" => [0x021BB],
- "ord" => [0x02A5D],
- "order" => [0x02134],
- "orderof" => [0x02134],
- "ordf" => [0x000AA],
- "ordm" => [0x000BA],
- "origof" => [0x022B6],
- "oror" => [0x02A56],
- "orslope" => [0x02A57],
- "orv" => [0x02A5B],
- "oscr" => [0x02134],
- "oslash" => [0x000F8],
- "osol" => [0x02298],
- "otilde" => [0x000F5],
- "otimes" => [0x02297],
- "otimesas" => [0x02A36],
- "ouml" => [0x000F6],
- "ovbar" => [0x0233D],
- "par" => [0x02225],
- "para" => [0x000B6],
- "parallel" => [0x02225],
- "parsim" => [0x02AF3],
- "parsl" => [0x02AFD],
- "part" => [0x02202],
- "pcy" => [0x0043F],
- "percnt" => [0x00025],
- "period" => [0x0002E],
- "permil" => [0x02030],
- "perp" => [0x022A5],
- "pertenk" => [0x02031],
- "pfr" => [0x1D52D],
- "phi" => [0x003C6],
- "phiv" => [0x003D5],
- "phmmat" => [0x02133],
- "phone" => [0x0260E],
- "pi" => [0x003C0],
- "pitchfork" => [0x022D4],
- "piv" => [0x003D6],
- "planck" => [0x0210F],
- "planckh" => [0x0210E],
- "plankv" => [0x0210F],
- "plus" => [0x0002B],
- "plusacir" => [0x02A23],
- "plusb" => [0x0229E],
- "pluscir" => [0x02A22],
- "plusdo" => [0x02214],
- "plusdu" => [0x02A25],
- "pluse" => [0x02A72],
- "plusmn" => [0x000B1],
- "plussim" => [0x02A26],
- "plustwo" => [0x02A27],
- "pm" => [0x000B1],
- "pointint" => [0x02A15],
- "popf" => [0x1D561],
- "pound" => [0x000A3],
- "pr" => [0x0227A],
- "prE" => [0x02AB3],
- "prap" => [0x02AB7],
- "prcue" => [0x0227C],
- "pre" => [0x02AAF],
- "prec" => [0x0227A],
- "precapprox" => [0x02AB7],
- "preccurlyeq" => [0x0227C],
- "preceq" => [0x02AAF],
- "precnapprox" => [0x02AB9],
- "precneqq" => [0x02AB5],
- "precnsim" => [0x022E8],
- "precsim" => [0x0227E],
- "prime" => [0x02032],
- "primes" => [0x02119],
- "prnE" => [0x02AB5],
- "prnap" => [0x02AB9],
- "prnsim" => [0x022E8],
- "prod" => [0x0220F],
- "profalar" => [0x0232E],
- "profline" => [0x02312],
- "profsurf" => [0x02313],
- "prop" => [0x0221D],
- "propto" => [0x0221D],
- "prsim" => [0x0227E],
- "prurel" => [0x022B0],
- "pscr" => [0x1D4C5],
- "psi" => [0x003C8],
- "puncsp" => [0x02008],
- "qfr" => [0x1D52E],
- "qint" => [0x02A0C],
- "qopf" => [0x1D562],
- "qprime" => [0x02057],
- "qscr" => [0x1D4C6],
- "quaternions" => [0x0210D],
- "quatint" => [0x02A16],
- "quest" => [0x0003F],
- "questeq" => [0x0225F],
- "quot" => [0x00022],
- "rAarr" => [0x021DB],
- "rArr" => [0x021D2],
- "rAtail" => [0x0291C],
- "rBarr" => [0x0290F],
- "rHar" => [0x02964],
- "race" => [0x0223D, 0x00331],
- "racute" => [0x00155],
- "radic" => [0x0221A],
- "raemptyv" => [0x029B3],
- "rang" => [0x027E9],
- "rangd" => [0x02992],
- "range" => [0x029A5],
- "rangle" => [0x027E9],
- "raquo" => [0x000BB],
- "rarr" => [0x02192],
- "rarrap" => [0x02975],
- "rarrb" => [0x021E5],
- "rarrbfs" => [0x02920],
- "rarrc" => [0x02933],
- "rarrfs" => [0x0291E],
- "rarrhk" => [0x021AA],
- "rarrlp" => [0x021AC],
- "rarrpl" => [0x02945],
- "rarrsim" => [0x02974],
- "rarrtl" => [0x021A3],
- "rarrw" => [0x0219D],
- "ratail" => [0x0291A],
- "ratio" => [0x02236],
- "rationals" => [0x0211A],
- "rbarr" => [0x0290D],
- "rbbrk" => [0x02773],
- "rbrace" => [0x0007D],
- "rbrack" => [0x0005D],
- "rbrke" => [0x0298C],
- "rbrksld" => [0x0298E],
- "rbrkslu" => [0x02990],
- "rcaron" => [0x00159],
- "rcedil" => [0x00157],
- "rceil" => [0x02309],
- "rcub" => [0x0007D],
- "rcy" => [0x00440],
- "rdca" => [0x02937],
- "rdldhar" => [0x02969],
- "rdquo" => [0x0201D],
- "rdquor" => [0x0201D],
- "rdsh" => [0x021B3],
- "real" => [0x0211C],
- "realine" => [0x0211B],
- "realpart" => [0x0211C],
- "reals" => [0x0211D],
- "rect" => [0x025AD],
- "reg" => [0x000AE],
- "rfisht" => [0x0297D],
- "rfloor" => [0x0230B],
- "rfr" => [0x1D52F],
- "rhard" => [0x021C1],
- "rharu" => [0x021C0],
- "rharul" => [0x0296C],
- "rho" => [0x003C1],
- "rhov" => [0x003F1],
- "rightarrow" => [0x02192],
- "rightarrowtail" => [0x021A3],
- "rightharpoondown" => [0x021C1],
- "rightharpoonup" => [0x021C0],
- "rightleftarrows" => [0x021C4],
- "rightleftharpoons" => [0x021CC],
- "rightrightarrows" => [0x021C9],
- "rightsquigarrow" => [0x0219D],
- "rightthreetimes" => [0x022CC],
- "ring" => [0x002DA],
- "risingdotseq" => [0x02253],
- "rlarr" => [0x021C4],
- "rlhar" => [0x021CC],
- "rlm" => [0x0200F],
- "rmoust" => [0x023B1],
- "rmoustache" => [0x023B1],
- "rnmid" => [0x02AEE],
- "roang" => [0x027ED],
- "roarr" => [0x021FE],
- "robrk" => [0x027E7],
- "ropar" => [0x02986],
- "ropf" => [0x1D563],
- "roplus" => [0x02A2E],
- "rotimes" => [0x02A35],
- "rpar" => [0x00029],
- "rpargt" => [0x02994],
- "rppolint" => [0x02A12],
- "rrarr" => [0x021C9],
- "rsaquo" => [0x0203A],
- "rscr" => [0x1D4C7],
- "rsh" => [0x021B1],
- "rsqb" => [0x0005D],
- "rsquo" => [0x02019],
- "rsquor" => [0x02019],
- "rthree" => [0x022CC],
- "rtimes" => [0x022CA],
- "rtri" => [0x025B9],
- "rtrie" => [0x022B5],
- "rtrif" => [0x025B8],
- "rtriltri" => [0x029CE],
- "ruluhar" => [0x02968],
- "rx" => [0x0211E],
- "sacute" => [0x0015B],
- "sbquo" => [0x0201A],
- "sc" => [0x0227B],
- "scE" => [0x02AB4],
- "scap" => [0x02AB8],
- "scaron" => [0x00161],
- "sccue" => [0x0227D],
- "sce" => [0x02AB0],
- "scedil" => [0x0015F],
- "scirc" => [0x0015D],
- "scnE" => [0x02AB6],
- "scnap" => [0x02ABA],
- "scnsim" => [0x022E9],
- "scpolint" => [0x02A13],
- "scsim" => [0x0227F],
- "scy" => [0x00441],
- "sdot" => [0x022C5],
- "sdotb" => [0x022A1],
- "sdote" => [0x02A66],
- "seArr" => [0x021D8],
- "searhk" => [0x02925],
- "searr" => [0x02198],
- "searrow" => [0x02198],
- "sect" => [0x000A7],
- "semi" => [0x0003B],
- "seswar" => [0x02929],
- "setminus" => [0x02216],
- "setmn" => [0x02216],
- "sext" => [0x02736],
- "sfr" => [0x1D530],
- "sfrown" => [0x02322],
- "sharp" => [0x0266F],
- "shchcy" => [0x00449],
- "shcy" => [0x00448],
- "shortmid" => [0x02223],
- "shortparallel" => [0x02225],
- "shy" => [0x000AD],
- "sigma" => [0x003C3],
- "sigmaf" => [0x003C2],
- "sigmav" => [0x003C2],
- "sim" => [0x0223C],
- "simdot" => [0x02A6A],
- "sime" => [0x02243],
- "simeq" => [0x02243],
- "simg" => [0x02A9E],
- "simgE" => [0x02AA0],
- "siml" => [0x02A9D],
- "simlE" => [0x02A9F],
- "simne" => [0x02246],
- "simplus" => [0x02A24],
- "simrarr" => [0x02972],
- "slarr" => [0x02190],
- "smallsetminus" => [0x02216],
- "smashp" => [0x02A33],
- "smeparsl" => [0x029E4],
- "smid" => [0x02223],
- "smile" => [0x02323],
- "smt" => [0x02AAA],
- "smte" => [0x02AAC],
- "smtes" => [0x02AAC, 0x0FE00],
- "softcy" => [0x0044C],
- "sol" => [0x0002F],
- "solb" => [0x029C4],
- "solbar" => [0x0233F],
- "sopf" => [0x1D564],
- "spades" => [0x02660],
- "spadesuit" => [0x02660],
- "spar" => [0x02225],
- "sqcap" => [0x02293],
- "sqcaps" => [0x02293, 0x0FE00],
- "sqcup" => [0x02294],
- "sqcups" => [0x02294, 0x0FE00],
- "sqsub" => [0x0228F],
- "sqsube" => [0x02291],
- "sqsubset" => [0x0228F],
- "sqsubseteq" => [0x02291],
- "sqsup" => [0x02290],
- "sqsupe" => [0x02292],
- "sqsupset" => [0x02290],
- "sqsupseteq" => [0x02292],
- "squ" => [0x025A1],
- "square" => [0x025A1],
- "squarf" => [0x025AA],
- "squf" => [0x025AA],
- "srarr" => [0x02192],
- "sscr" => [0x1D4C8],
- "ssetmn" => [0x02216],
- "ssmile" => [0x02323],
- "sstarf" => [0x022C6],
- "star" => [0x02606],
- "starf" => [0x02605],
- "straightepsilon" => [0x003F5],
- "straightphi" => [0x003D5],
- "strns" => [0x000AF],
- "sub" => [0x02282],
- "subE" => [0x02AC5],
- "subdot" => [0x02ABD],
- "sube" => [0x02286],
- "subedot" => [0x02AC3],
- "submult" => [0x02AC1],
- "subnE" => [0x02ACB],
- "subne" => [0x0228A],
- "subplus" => [0x02ABF],
- "subrarr" => [0x02979],
- "subset" => [0x02282],
- "subseteq" => [0x02286],
- "subseteqq" => [0x02AC5],
- "subsetneq" => [0x0228A],
- "subsetneqq" => [0x02ACB],
- "subsim" => [0x02AC7],
- "subsub" => [0x02AD5],
- "subsup" => [0x02AD3],
- "succ" => [0x0227B],
- "succapprox" => [0x02AB8],
- "succcurlyeq" => [0x0227D],
- "succeq" => [0x02AB0],
- "succnapprox" => [0x02ABA],
- "succneqq" => [0x02AB6],
- "succnsim" => [0x022E9],
- "succsim" => [0x0227F],
- "sum" => [0x02211],
- "sung" => [0x0266A],
- "sup" => [0x02283],
- "sup1" => [0x000B9],
- "sup2" => [0x000B2],
- "sup3" => [0x000B3],
- "supE" => [0x02AC6],
- "supdot" => [0x02ABE],
- "supdsub" => [0x02AD8],
- "supe" => [0x02287],
- "supedot" => [0x02AC4],
- "suphsol" => [0x027C9],
- "suphsub" => [0x02AD7],
- "suplarr" => [0x0297B],
- "supmult" => [0x02AC2],
- "supnE" => [0x02ACC],
- "supne" => [0x0228B],
- "supplus" => [0x02AC0],
- "supset" => [0x02283],
- "supseteq" => [0x02287],
- "supseteqq" => [0x02AC6],
- "supsetneq" => [0x0228B],
- "supsetneqq" => [0x02ACC],
- "supsim" => [0x02AC8],
- "supsub" => [0x02AD4],
- "supsup" => [0x02AD6],
- "swArr" => [0x021D9],
- "swarhk" => [0x02926],
- "swarr" => [0x02199],
- "swarrow" => [0x02199],
- "swnwar" => [0x0292A],
- "szlig" => [0x000DF],
- "target" => [0x02316],
- "tau" => [0x003C4],
- "tbrk" => [0x023B4],
- "tcaron" => [0x00165],
- "tcedil" => [0x00163],
- "tcy" => [0x00442],
- "tdot" => [0x020DB],
- "telrec" => [0x02315],
- "tfr" => [0x1D531],
- "there4" => [0x02234],
- "therefore" => [0x02234],
- "theta" => [0x003B8],
- "thetasym" => [0x003D1],
- "thetav" => [0x003D1],
- "thickapprox" => [0x02248],
- "thicksim" => [0x0223C],
- "thinsp" => [0x02009],
- "thkap" => [0x02248],
- "thksim" => [0x0223C],
- "thorn" => [0x000FE],
- "tilde" => [0x002DC],
- "times" => [0x000D7],
- "timesb" => [0x022A0],
- "timesbar" => [0x02A31],
- "timesd" => [0x02A30],
- "tint" => [0x0222D],
- "toea" => [0x02928],
- "top" => [0x022A4],
- "topbot" => [0x02336],
- "topcir" => [0x02AF1],
- "topf" => [0x1D565],
- "topfork" => [0x02ADA],
- "tosa" => [0x02929],
- "tprime" => [0x02034],
- "trade" => [0x02122],
- "triangle" => [0x025B5],
- "triangledown" => [0x025BF],
- "triangleleft" => [0x025C3],
- "trianglelefteq" => [0x022B4],
- "triangleq" => [0x0225C],
- "triangleright" => [0x025B9],
- "trianglerighteq" => [0x022B5],
- "tridot" => [0x025EC],
- "trie" => [0x0225C],
- "triminus" => [0x02A3A],
- "triplus" => [0x02A39],
- "trisb" => [0x029CD],
- "tritime" => [0x02A3B],
- "trpezium" => [0x023E2],
- "tscr" => [0x1D4C9],
- "tscy" => [0x00446],
- "tshcy" => [0x0045B],
- "tstrok" => [0x00167],
- "twixt" => [0x0226C],
- "twoheadleftarrow" => [0x0219E],
- "twoheadrightarrow" => [0x021A0],
- "uArr" => [0x021D1],
- "uHar" => [0x02963],
- "uacute" => [0x000FA],
- "uarr" => [0x02191],
- "ubrcy" => [0x0045E],
- "ubreve" => [0x0016D],
- "ucirc" => [0x000FB],
- "ucy" => [0x00443],
- "udarr" => [0x021C5],
- "udblac" => [0x00171],
- "udhar" => [0x0296E],
- "ufisht" => [0x0297E],
- "ufr" => [0x1D532],
- "ugrave" => [0x000F9],
- "uharl" => [0x021BF],
- "uharr" => [0x021BE],
- "uhblk" => [0x02580],
- "ulcorn" => [0x0231C],
- "ulcorner" => [0x0231C],
- "ulcrop" => [0x0230F],
- "ultri" => [0x025F8],
- "umacr" => [0x0016B],
- "uml" => [0x000A8],
- "uogon" => [0x00173],
- "uopf" => [0x1D566],
- "uparrow" => [0x02191],
- "updownarrow" => [0x02195],
- "upharpoonleft" => [0x021BF],
- "upharpoonright" => [0x021BE],
- "uplus" => [0x0228E],
- "upsi" => [0x003C5],
- "upsih" => [0x003D2],
- "upsilon" => [0x003C5],
- "upuparrows" => [0x021C8],
- "urcorn" => [0x0231D],
- "urcorner" => [0x0231D],
- "urcrop" => [0x0230E],
- "uring" => [0x0016F],
- "urtri" => [0x025F9],
- "uscr" => [0x1D4CA],
- "utdot" => [0x022F0],
- "utilde" => [0x00169],
- "utri" => [0x025B5],
- "utrif" => [0x025B4],
- "uuarr" => [0x021C8],
- "uuml" => [0x000FC],
- "uwangle" => [0x029A7],
- "vArr" => [0x021D5],
- "vBar" => [0x02AE8],
- "vBarv" => [0x02AE9],
- "vDash" => [0x022A8],
- "vangrt" => [0x0299C],
- "varepsilon" => [0x003F5],
- "varkappa" => [0x003F0],
- "varnothing" => [0x02205],
- "varphi" => [0x003D5],
- "varpi" => [0x003D6],
- "varpropto" => [0x0221D],
- "varr" => [0x02195],
- "varrho" => [0x003F1],
- "varsigma" => [0x003C2],
- "varsubsetneq" => [0x0228A, 0x0FE00],
- "varsubsetneqq" => [0x02ACB, 0x0FE00],
- "varsupsetneq" => [0x0228B, 0x0FE00],
- "varsupsetneqq" => [0x02ACC, 0x0FE00],
- "vartheta" => [0x003D1],
- "vartriangleleft" => [0x022B2],
- "vartriangleright" => [0x022B3],
- "vcy" => [0x00432],
- "vdash" => [0x022A2],
- "vee" => [0x02228],
- "veebar" => [0x022BB],
- "veeeq" => [0x0225A],
- "vellip" => [0x022EE],
- "verbar" => [0x0007C],
- "vert" => [0x0007C],
- "vfr" => [0x1D533],
- "vltri" => [0x022B2],
- "vnsub" => [0x02282, 0x020D2],
- "vnsup" => [0x02283, 0x020D2],
- "vopf" => [0x1D567],
- "vprop" => [0x0221D],
- "vrtri" => [0x022B3],
- "vscr" => [0x1D4CB],
- "vsubnE" => [0x02ACB, 0x0FE00],
- "vsubne" => [0x0228A, 0x0FE00],
- "vsupnE" => [0x02ACC, 0x0FE00],
- "vsupne" => [0x0228B, 0x0FE00],
- "vzigzag" => [0x0299A],
- "wcirc" => [0x00175],
- "wedbar" => [0x02A5F],
- "wedge" => [0x02227],
- "wedgeq" => [0x02259],
- "weierp" => [0x02118],
- "wfr" => [0x1D534],
- "wopf" => [0x1D568],
- "wp" => [0x02118],
- "wr" => [0x02240],
- "wreath" => [0x02240],
- "wscr" => [0x1D4CC],
- "xcap" => [0x022C2],
- "xcirc" => [0x025EF],
- "xcup" => [0x022C3],
- "xdtri" => [0x025BD],
- "xfr" => [0x1D535],
- "xhArr" => [0x027FA],
- "xharr" => [0x027F7],
- "xi" => [0x003BE],
- "xlArr" => [0x027F8],
- "xlarr" => [0x027F5],
- "xmap" => [0x027FC],
- "xnis" => [0x022FB],
- "xodot" => [0x02A00],
- "xopf" => [0x1D569],
- "xoplus" => [0x02A01],
- "xotime" => [0x02A02],
- "xrArr" => [0x027F9],
- "xrarr" => [0x027F6],
- "xscr" => [0x1D4CD],
- "xsqcup" => [0x02A06],
- "xuplus" => [0x02A04],
- "xutri" => [0x025B3],
- "xvee" => [0x022C1],
- "xwedge" => [0x022C0],
- "yacute" => [0x000FD],
- "yacy" => [0x0044F],
- "ycirc" => [0x00177],
- "ycy" => [0x0044B],
- "yen" => [0x000A5],
- "yfr" => [0x1D536],
- "yicy" => [0x00457],
- "yopf" => [0x1D56A],
- "yscr" => [0x1D4CE],
- "yucy" => [0x0044E],
- "yuml" => [0x000FF],
- "zacute" => [0x0017A],
- "zcaron" => [0x0017E],
- "zcy" => [0x00437],
- "zdot" => [0x0017C],
- "zeetrf" => [0x02128],
- "zeta" => [0x003B6],
- "zfr" => [0x1D537],
- "zhcy" => [0x00436],
- "zigrarr" => [0x021DD],
- "zopf" => [0x1D56B],
- "zscr" => [0x1D4CF],
- "zwj" => [0x0200D],
- "zwnj" => [0x0200C],
-}
-
diff --git a/ruby_2_2/lib/rdoc/markdown/literals_1_9.rb b/ruby_2_2/lib/rdoc/markdown/literals_1_9.rb
deleted file mode 100644
index f7bfbe27a1..0000000000
--- a/ruby_2_2/lib/rdoc/markdown/literals_1_9.rb
+++ /dev/null
@@ -1,420 +0,0 @@
-# coding: UTF-8
-# :markup: markdown
-
-##
-#--
-# This set of literals is for Ruby 1.9 regular expressions and gives full
-# unicode support.
-#
-# Unlike peg-markdown, this set of literals recognizes Unicode alphanumeric
-# characters, newlines and spaces.
-class RDoc::Markdown::Literals
- # :stopdoc:
-
- # This is distinct from setup_parser so that a standalone parser
- # can redefine #initialize and still have access to the proper
- # parser setup code.
- def initialize(str, debug=false)
- setup_parser(str, debug)
- end
-
-
-
- # Prepares for parsing +str+. If you define a custom initialize you must
- # call this method before #parse
- def setup_parser(str, debug=false)
- set_string str, 0
- @memoizations = Hash.new { |h,k| h[k] = {} }
- @result = nil
- @failed_rule = nil
- @failing_rule_offset = -1
-
- setup_foreign_grammar
- end
-
- attr_reader :string
- attr_reader :failing_rule_offset
- attr_accessor :result, :pos
-
- def current_column(target=pos)
- if c = string.rindex("\n", target-1)
- return target - c - 1
- end
-
- target + 1
- end
-
- def current_line(target=pos)
- cur_offset = 0
- cur_line = 0
-
- string.each_line do |line|
- cur_line += 1
- cur_offset += line.size
- return cur_line if cur_offset >= target
- end
-
- -1
- end
-
- def lines
- lines = []
- string.each_line { |l| lines << l }
- lines
- end
-
-
-
- def get_text(start)
- @string[start..@pos-1]
- end
-
- # Sets the string and current parsing position for the parser.
- def set_string string, pos
- @string = string
- @string_size = string ? string.size : 0
- @pos = pos
- end
-
- def show_pos
- width = 10
- if @pos < width
- "#{@pos} (\"#{@string[0,@pos]}\" @ \"#{@string[@pos,width]}\")"
- else
- "#{@pos} (\"... #{@string[@pos - width, width]}\" @ \"#{@string[@pos,width]}\")"
- end
- end
-
- def failure_info
- l = current_line @failing_rule_offset
- c = current_column @failing_rule_offset
-
- if @failed_rule.kind_of? Symbol
- info = self.class::Rules[@failed_rule]
- "line #{l}, column #{c}: failed rule '#{info.name}' = '#{info.rendered}'"
- else
- "line #{l}, column #{c}: failed rule '#{@failed_rule}'"
- end
- end
-
- def failure_caret
- l = current_line @failing_rule_offset
- c = current_column @failing_rule_offset
-
- line = lines[l-1]
- "#{line}\n#{' ' * (c - 1)}^"
- end
-
- def failure_character
- l = current_line @failing_rule_offset
- c = current_column @failing_rule_offset
- lines[l-1][c-1, 1]
- end
-
- def failure_oneline
- l = current_line @failing_rule_offset
- c = current_column @failing_rule_offset
-
- char = lines[l-1][c-1, 1]
-
- if @failed_rule.kind_of? Symbol
- info = self.class::Rules[@failed_rule]
- "@#{l}:#{c} failed rule '#{info.name}', got '#{char}'"
- else
- "@#{l}:#{c} failed rule '#{@failed_rule}', got '#{char}'"
- end
- end
-
- class ParseError < RuntimeError
- end
-
- def raise_error
- raise ParseError, failure_oneline
- end
-
- def show_error(io=STDOUT)
- error_pos = @failing_rule_offset
- line_no = current_line(error_pos)
- col_no = current_column(error_pos)
-
- io.puts "On line #{line_no}, column #{col_no}:"
-
- if @failed_rule.kind_of? Symbol
- info = self.class::Rules[@failed_rule]
- io.puts "Failed to match '#{info.rendered}' (rule '#{info.name}')"
- else
- io.puts "Failed to match rule '#{@failed_rule}'"
- end
-
- io.puts "Got: #{string[error_pos,1].inspect}"
- line = lines[line_no-1]
- io.puts "=> #{line}"
- io.print(" " * (col_no + 3))
- io.puts "^"
- end
-
- def set_failed_rule(name)
- if @pos > @failing_rule_offset
- @failed_rule = name
- @failing_rule_offset = @pos
- end
- end
-
- attr_reader :failed_rule
-
- def match_string(str)
- len = str.size
- if @string[pos,len] == str
- @pos += len
- return str
- end
-
- return nil
- end
-
- def scan(reg)
- if m = reg.match(@string[@pos..-1])
- width = m.end(0)
- @pos += width
- return true
- end
-
- return nil
- end
-
- if "".respond_to? :ord
- def get_byte
- if @pos >= @string_size
- return nil
- end
-
- s = @string[@pos].ord
- @pos += 1
- s
- end
- else
- def get_byte
- if @pos >= @string_size
- return nil
- end
-
- s = @string[@pos]
- @pos += 1
- s
- end
- end
-
- def parse(rule=nil)
- # We invoke the rules indirectly via apply
- # instead of by just calling them as methods because
- # if the rules use left recursion, apply needs to
- # manage that.
-
- if !rule
- apply(:_root)
- else
- method = rule.gsub("-","_hyphen_")
- apply :"_#{method}"
- end
- end
-
- class MemoEntry
- def initialize(ans, pos)
- @ans = ans
- @pos = pos
- @result = nil
- @set = false
- @left_rec = false
- end
-
- attr_reader :ans, :pos, :result, :set
- attr_accessor :left_rec
-
- def move!(ans, pos, result)
- @ans = ans
- @pos = pos
- @result = result
- @set = true
- @left_rec = false
- end
- end
-
- def external_invoke(other, rule, *args)
- old_pos = @pos
- old_string = @string
-
- set_string other.string, other.pos
-
- begin
- if val = __send__(rule, *args)
- other.pos = @pos
- other.result = @result
- else
- other.set_failed_rule "#{self.class}##{rule}"
- end
- val
- ensure
- set_string old_string, old_pos
- end
- end
-
- def apply_with_args(rule, *args)
- memo_key = [rule, args]
- if m = @memoizations[memo_key][@pos]
- @pos = m.pos
- if !m.set
- m.left_rec = true
- return nil
- end
-
- @result = m.result
-
- return m.ans
- else
- m = MemoEntry.new(nil, @pos)
- @memoizations[memo_key][@pos] = m
- start_pos = @pos
-
- ans = __send__ rule, *args
-
- lr = m.left_rec
-
- m.move! ans, @pos, @result
-
- # Don't bother trying to grow the left recursion
- # if it's failing straight away (thus there is no seed)
- if ans and lr
- return grow_lr(rule, args, start_pos, m)
- else
- return ans
- end
-
- return ans
- end
- end
-
- def apply(rule)
- if m = @memoizations[rule][@pos]
- @pos = m.pos
- if !m.set
- m.left_rec = true
- return nil
- end
-
- @result = m.result
-
- return m.ans
- else
- m = MemoEntry.new(nil, @pos)
- @memoizations[rule][@pos] = m
- start_pos = @pos
-
- ans = __send__ rule
-
- lr = m.left_rec
-
- m.move! ans, @pos, @result
-
- # Don't bother trying to grow the left recursion
- # if it's failing straight away (thus there is no seed)
- if ans and lr
- return grow_lr(rule, nil, start_pos, m)
- else
- return ans
- end
-
- return ans
- end
- end
-
- def grow_lr(rule, args, start_pos, m)
- while true
- @pos = start_pos
- @result = m.result
-
- if args
- ans = __send__ rule, *args
- else
- ans = __send__ rule
- end
- return nil unless ans
-
- break if @pos <= m.pos
-
- m.move! ans, @pos, @result
- end
-
- @result = m.result
- @pos = m.pos
- return m.ans
- end
-
- class RuleInfo
- def initialize(name, rendered)
- @name = name
- @rendered = rendered
- end
-
- attr_reader :name, :rendered
- end
-
- def self.rule_info(name, rendered)
- RuleInfo.new(name, rendered)
- end
-
-
- # :startdoc:
- # :stopdoc:
- def setup_foreign_grammar; end
-
- # Alphanumeric = /\p{Word}/
- def _Alphanumeric
- _tmp = scan(/\A(?-mix:\p{Word})/)
- set_failed_rule :_Alphanumeric unless _tmp
- return _tmp
- end
-
- # AlphanumericAscii = /[A-Za-z0-9]/
- def _AlphanumericAscii
- _tmp = scan(/\A(?-mix:[A-Za-z0-9])/)
- set_failed_rule :_AlphanumericAscii unless _tmp
- return _tmp
- end
-
- # BOM = "uFEFF"
- def _BOM
- _tmp = match_string("uFEFF")
- set_failed_rule :_BOM unless _tmp
- return _tmp
- end
-
- # Newline = /\n|\r\n?|\p{Zl}|\p{Zp}/
- def _Newline
- _tmp = scan(/\A(?-mix:\n|\r\n?|\p{Zl}|\p{Zp})/)
- set_failed_rule :_Newline unless _tmp
- return _tmp
- end
-
- # NonAlphanumeric = /\p{^Word}/
- def _NonAlphanumeric
- _tmp = scan(/\A(?-mix:\p{^Word})/)
- set_failed_rule :_NonAlphanumeric unless _tmp
- return _tmp
- end
-
- # Spacechar = /\t|\p{Zs}/
- def _Spacechar
- _tmp = scan(/\A(?-mix:\t|\p{Zs})/)
- set_failed_rule :_Spacechar unless _tmp
- return _tmp
- end
-
- Rules = {}
- Rules[:_Alphanumeric] = rule_info("Alphanumeric", "/\\p{Word}/")
- Rules[:_AlphanumericAscii] = rule_info("AlphanumericAscii", "/[A-Za-z0-9]/")
- Rules[:_BOM] = rule_info("BOM", "\"uFEFF\"")
- Rules[:_Newline] = rule_info("Newline", "/\\n|\\r\\n?|\\p{Zl}|\\p{Zp}/")
- Rules[:_NonAlphanumeric] = rule_info("NonAlphanumeric", "/\\p{^Word}/")
- Rules[:_Spacechar] = rule_info("Spacechar", "/\\t|\\p{Zs}/")
- # :startdoc:
-end
diff --git a/ruby_2_2/lib/rdoc/markup.rb b/ruby_2_2/lib/rdoc/markup.rb
deleted file mode 100644
index 0e754ff33d..0000000000
--- a/ruby_2_2/lib/rdoc/markup.rb
+++ /dev/null
@@ -1,869 +0,0 @@
-##
-# RDoc::Markup parses plain text documents and attempts to decompose them into
-# their constituent parts. Some of these parts are high-level: paragraphs,
-# chunks of verbatim text, list entries and the like. Other parts happen at
-# the character level: a piece of bold text, a word in code font. This markup
-# is similar in spirit to that used on WikiWiki webs, where folks create web
-# pages using a simple set of formatting rules.
-#
-# RDoc::Markup and other markup formats do no output formatting, this is
-# handled by the RDoc::Markup::Formatter subclasses.
-#
-# = Supported Formats
-#
-# Besides the RDoc::Markup format, the following formats are built in to RDoc:
-#
-# markdown::
-# The markdown format as described by
-# http://daringfireball.net/projects/markdown/. See RDoc::Markdown for
-# details on the parser and supported extensions.
-# rd::
-# The rdtool format. See RDoc::RD for details on the parser and format.
-# tomdoc::
-# The TomDoc format as described by http://tomdoc.org/. See RDoc::TomDoc
-# for details on the parser and supported extensions.
-#
-# You can choose a markup format using the following methods:
-#
-# per project::
-# If you build your documentation with rake use RDoc::Task#markup.
-#
-# If you build your documentation by hand run:
-#
-# rdoc --markup your_favorite_format --write-options
-#
-# and commit <tt>.rdoc_options</tt> and ship it with your packaged gem.
-# per file::
-# At the top of the file use the <tt>:markup:</tt> directive to set the
-# default format for the rest of the file.
-# per comment::
-# Use the <tt>:markup:</tt> directive at the top of a comment you want
-# to write in a different format.
-#
-# = RDoc::Markup
-#
-# RDoc::Markup is extensible at runtime: you can add \new markup elements to
-# be recognized in the documents that RDoc::Markup parses.
-#
-# RDoc::Markup is intended to be the basis for a family of tools which share
-# the common requirement that simple, plain-text should be rendered in a
-# variety of different output formats and media. It is envisaged that
-# RDoc::Markup could be the basis for formatting RDoc style comment blocks,
-# Wiki entries, and online FAQs.
-#
-# == Synopsis
-#
-# This code converts +input_string+ to HTML. The conversion takes place in
-# the +convert+ method, so you can use the same RDoc::Markup converter to
-# convert multiple input strings.
-#
-# require 'rdoc'
-#
-# h = RDoc::Markup::ToHtml.new(RDoc::Options.new)
-#
-# puts h.convert(input_string)
-#
-# You can extend the RDoc::Markup parser to recognize new markup
-# sequences, and to add special processing for text that matches a
-# regular expression. Here we make WikiWords significant to the parser,
-# and also make the sequences {word} and \<no>text...</no> signify
-# strike-through text. We then subclass the HTML output class to deal
-# with these:
-#
-# require 'rdoc'
-#
-# class WikiHtml < RDoc::Markup::ToHtml
-# def handle_special_WIKIWORD(special)
-# "<font color=red>" + special.text + "</font>"
-# end
-# end
-#
-# markup = RDoc::Markup.new
-# markup.add_word_pair("{", "}", :STRIKE)
-# markup.add_html("no", :STRIKE)
-#
-# markup.add_special(/\b([A-Z][a-z]+[A-Z]\w+)/, :WIKIWORD)
-#
-# wh = WikiHtml.new RDoc::Options.new, markup
-# wh.add_tag(:STRIKE, "<strike>", "</strike>")
-#
-# puts "<body>#{wh.convert ARGF.read}</body>"
-#
-# == Encoding
-#
-# Where Encoding support is available, RDoc will automatically convert all
-# documents to the same output encoding. The output encoding can be set via
-# RDoc::Options#encoding and defaults to Encoding.default_external.
-#
-# = \RDoc Markup Reference
-#
-# == Block Markup
-#
-# === Paragraphs and Verbatim
-#
-# The markup engine looks for a document's natural left margin. This is
-# used as the initial margin for the document.
-#
-# Consecutive lines starting at this margin are considered to be a
-# paragraph. Empty lines separate paragraphs.
-#
-# Any line that starts to the right of the current margin is treated
-# as verbatim text. This is useful for code listings:
-#
-# 3.times { puts "Ruby" }
-#
-# In verbatim text, two or more blank lines are collapsed into one,
-# and trailing blank lines are removed:
-#
-# This is the first line
-#
-#
-# This is the second non-blank line,
-# after 2 blank lines in the source markup.
-#
-#
-# There were two trailing blank lines right above this paragraph, that
-# have been removed. In addition, the verbatim text has been shifted
-# left, so the amount of indentation of verbatim text is unimportant.
-#
-# For HTML output RDoc makes a small effort to determine if a verbatim section
-# contains Ruby source code. If so, the verbatim block will be marked up as
-# HTML. Triggers include "def", "class", "module", "require", the "hash
-# rocket"# (=>) or a block call with a parameter.
-#
-# === Headers
-#
-# A line starting with an equal sign (=) is treated as a
-# heading. Level one headings have one equals sign, level two headings
-# have two, and so on until level six, which is the maximum
-# (seven hyphens or more result in a level six heading).
-#
-# For example, the above header was obtained with:
-#
-# === Headers
-#
-# In HTML output headers have an id matching their name. The above example's
-# HTML is:
-#
-# <h3 id="label-Headers">Headers</h3>
-#
-# If a heading is inside a method body the id will be prefixed with the
-# method's id. If the above header where in the documentation for a method
-# such as:
-#
-# ##
-# # This method does fun things
-# #
-# # = Example
-# #
-# # Example of fun things goes here ...
-#
-# def do_fun_things
-# end
-#
-# The header's id would be:
-#
-# <h1 id="method-i-do_fun_things-label-Example">Example</h1>
-#
-# The label can be linked-to using <tt>SomeClass@Headers</tt>. See
-# {Links}[RDoc::Markup@Links] for further details.
-#
-# === Rules
-#
-# A line starting with three or more hyphens (at the current indent)
-# generates a horizontal rule.
-#
-# ---
-#
-# produces:
-#
-# ---
-#
-# === Simple Lists
-#
-# If a paragraph starts with a "*", "-", "<digit>." or "<letter>.",
-# then it is taken to be the start of a list. The margin is increased to be
-# the first non-space following the list start flag. Subsequent lines
-# should be indented to this new margin until the list ends. For example:
-#
-# * this is a list with three paragraphs in
-# the first item. This is the first paragraph.
-#
-# And this is the second paragraph.
-#
-# 1. This is an indented, numbered list.
-# 2. This is the second item in that list
-#
-# This is the third conventional paragraph in the
-# first list item.
-#
-# * This is the second item in the original list
-#
-# produces:
-#
-# * this is a list with three paragraphs in
-# the first item. This is the first paragraph.
-#
-# And this is the second paragraph.
-#
-# 1. This is an indented, numbered list.
-# 2. This is the second item in that list
-#
-# This is the third conventional paragraph in the
-# first list item.
-#
-# * This is the second item in the original list
-#
-# === Labeled Lists
-#
-# You can also construct labeled lists, sometimes called description
-# or definition lists. Do this by putting the label in square brackets
-# and indenting the list body:
-#
-# [cat] a small furry mammal
-# that seems to sleep a lot
-#
-# [ant] a little insect that is known
-# to enjoy picnics
-#
-# produces:
-#
-# [cat] a small furry mammal
-# that seems to sleep a lot
-#
-# [ant] a little insect that is known
-# to enjoy picnics
-#
-# If you want the list bodies to line up to the left of the labels,
-# use two colons:
-#
-# cat:: a small furry mammal
-# that seems to sleep a lot
-#
-# ant:: a little insect that is known
-# to enjoy picnics
-#
-# produces:
-#
-# cat:: a small furry mammal
-# that seems to sleep a lot
-#
-# ant:: a little insect that is known
-# to enjoy picnics
-#
-# Notice that blank lines right after the label are ignored in labeled lists:
-#
-# [one]
-#
-# definition 1
-#
-# [two]
-#
-# definition 2
-#
-# produces the same output as
-#
-# [one] definition 1
-# [two] definition 2
-#
-#
-# === Lists and Verbatim
-#
-# If you want to introduce a verbatim section right after a list, it has to be
-# less indented than the list item bodies, but more indented than the list
-# label, letter, digit or bullet. For instance:
-#
-# * point 1
-#
-# * point 2, first paragraph
-#
-# point 2, second paragraph
-# verbatim text inside point 2
-# point 2, third paragraph
-# verbatim text outside of the list (the list is therefore closed)
-# regular paragraph after the list
-#
-# produces:
-#
-# * point 1
-#
-# * point 2, first paragraph
-#
-# point 2, second paragraph
-# verbatim text inside point 2
-# point 2, third paragraph
-# verbatim text outside of the list (the list is therefore closed)
-# regular paragraph after the list
-#
-# == Text Markup
-#
-# === Bold, Italic, Typewriter Text
-#
-# You can use markup within text (except verbatim) to change the
-# appearance of parts of that text. Out of the box, RDoc::Markup
-# supports word-based and general markup.
-#
-# Word-based markup uses flag characters around individual words:
-#
-# <tt>\*_word_\*</tt>:: displays _word_ in a *bold* font
-# <tt>\__word_\_</tt>:: displays _word_ in an _emphasized_ font
-# <tt>\+_word_\+</tt>:: displays _word_ in a +code+ font
-#
-# General markup affects text between a start delimiter and an end
-# delimiter. Not surprisingly, these delimiters look like HTML markup.
-#
-# <tt>\<b>_text_</b></tt>:: displays _text_ in a *bold* font
-# <tt>\<em>_text_</em></tt>:: displays _text_ in an _emphasized_ font
-# (alternate tag: <tt>\<i></tt>)
-# <tt>\<tt>_text_\</tt></tt>:: displays _text_ in a +code+ font
-# (alternate tag: <tt>\<code></tt>)
-#
-# Unlike conventional Wiki markup, general markup can cross line
-# boundaries. You can turn off the interpretation of markup by
-# preceding the first character with a backslash (see <i>Escaping
-# Text Markup</i>, below).
-#
-# === Links
-#
-# Links to starting with +http:+, +https:+, +mailto:+, +ftp:+ or +www.+
-# are recognized. An HTTP url that references an external image is converted
-# into an inline image element.
-#
-# Classes and methods will be automatically linked to their definition. For
-# example, <tt>RDoc::Markup</tt> will link to this documentation. By default
-# methods will only be automatically linked if they contain an <tt>_</tt> (all
-# methods can be automatically linked through the <tt>--hyperlink-all</tt>
-# command line option).
-#
-# Single-word methods can be linked by using the <tt>#</tt> character for
-# instance methods or <tt>::</tt> for class methods. For example,
-# <tt>#convert</tt> links to #convert. A class or method may be combined like
-# <tt>RDoc::Markup#convert</tt>.
-#
-# A heading inside the documentation can be linked by following the class
-# or method by an <tt>@</tt> then the heading name.
-# <tt>RDoc::Markup@Links</tt> will link to this section like this:
-# RDoc::Markup@Links. Spaces in headings with multiple words must be escaped
-# with <tt>+</tt> like <tt>RDoc::Markup@Escaping+Text+Markup</tt>.
-# Punctuation and other special characters must be escaped like CGI.escape.
-#
-# The <tt>@</tt> can also be used to link to sections. If a section and a
-# heading share the same name the section is preferred for the link.
-#
-# Links can also be of the form <tt>label[url]</tt>, in which case +label+ is
-# used in the displayed text, and +url+ is used as the target. If +label+
-# contains multiple words, put it in braces: <tt>{multi word label}[url]</tt>.
-# The +url+ may be an +http:+-type link or a cross-reference to a class,
-# module or method with a label.
-#
-# Links with the <code>rdoc-image:</code> scheme will create an image tag for
-# HTML output. Only fully-qualified URLs are supported.
-#
-# Links with the <tt>rdoc-ref:</tt> scheme will link to the referenced class,
-# module, method, file, etc. If the referenced item is does not exist
-# no link will be generated and <tt>rdoc-ref:</tt> will be removed from the
-# resulting text.
-#
-# Links starting with <tt>rdoc-label:label_name</tt> will link to the
-# +label_name+. You can create a label for the current link (for
-# bidirectional links) by supplying a name for the current link like
-# <tt>rdoc-label:label-other:label-mine</tt>.
-#
-# Links starting with +link:+ refer to local files whose path is relative to
-# the <tt>--op</tt> directory. Use <tt>rdoc-ref:</tt> instead of
-# <tt>link:</tt> to link to files generated by RDoc as the link target may
-# be different across RDoc generators.
-#
-# Example links:
-#
-# https://github.com/rdoc/rdoc
-# mailto:user@example.com
-# {RDoc Documentation}[http://rdoc.rubyforge.org]
-# {RDoc Markup}[rdoc-ref:RDoc::Markup]
-#
-# === Escaping Text Markup
-#
-# Text markup can be escaped with a backslash, as in \<tt>, which was obtained
-# with <tt>\\<tt></tt>. Except in verbatim sections and between \<tt> tags,
-# to produce a backslash you have to double it unless it is followed by a
-# space, tab or newline. Otherwise, the HTML formatter will discard it, as it
-# is used to escape potential links:
-#
-# * The \ must be doubled if not followed by white space: \\.
-# * But not in \<tt> tags: in a Regexp, <tt>\S</tt> matches non-space.
-# * This is a link to {ruby-lang}[www.ruby-lang.org].
-# * This is not a link, however: \{ruby-lang.org}[www.ruby-lang.org].
-# * This will not be linked to \RDoc::RDoc#document
-#
-# generates:
-#
-# * The \ must be doubled if not followed by white space: \\.
-# * But not in \<tt> tags: in a Regexp, <tt>\S</tt> matches non-space.
-# * This is a link to {ruby-lang}[www.ruby-lang.org]
-# * This is not a link, however: \{ruby-lang.org}[www.ruby-lang.org]
-# * This will not be linked to \RDoc::RDoc#document
-#
-# Inside \<tt> tags, more precisely, leading backslashes are removed only if
-# followed by a markup character (<tt><*_+</tt>), a backslash, or a known link
-# reference (a known class or method). So in the example above, the backslash
-# of <tt>\S</tt> would be removed if there was a class or module named +S+ in
-# the current context.
-#
-# This behavior is inherited from RDoc version 1, and has been kept for
-# compatibility with existing RDoc documentation.
-#
-# === Conversion of characters
-#
-# HTML will convert two/three dashes to an em-dash. Other common characters are
-# converted as well:
-#
-# em-dash:: -- or ---
-# ellipsis:: ...
-#
-# single quotes:: 'text' or `text'
-# double quotes:: "text" or ``text''
-#
-# copyright:: (c)
-# registered trademark:: (r)
-#
-# produces:
-#
-# em-dash:: -- or ---
-# ellipsis:: ...
-#
-# single quotes:: 'text' or `text'
-# double quotes:: "text" or ``text''
-#
-# copyright:: (c)
-# registered trademark:: (r)
-#
-#
-# == Documenting Source Code
-#
-# Comment blocks can be written fairly naturally, either using <tt>#</tt> on
-# successive lines of the comment, or by including the comment in
-# a <tt>=begin</tt>/<tt>=end</tt> block. If you use the latter form,
-# the <tt>=begin</tt> line _must_ be flagged with an +rdoc+ tag:
-#
-# =begin rdoc
-# Documentation to be processed by RDoc.
-#
-# ...
-# =end
-#
-# RDoc stops processing comments if it finds a comment line starting
-# with <tt>--</tt> right after the <tt>#</tt> character (otherwise,
-# it will be treated as a rule if it has three dashes or more).
-# This can be used to separate external from internal comments,
-# or to stop a comment being associated with a method, class, or module.
-# Commenting can be turned back on with a line that starts with <tt>++</tt>.
-#
-# ##
-# # Extract the age and calculate the date-of-birth.
-# #--
-# # FIXME: fails if the birthday falls on February 29th
-# #++
-# # The DOB is returned as a Time object.
-#
-# def get_dob(person)
-# # ...
-# end
-#
-# Names of classes, files, and any method names containing an underscore or
-# preceded by a hash character are automatically linked from comment text to
-# their description. This linking works inside the current class or module,
-# and with ancestor methods (in included modules or in the superclass).
-#
-# Method parameter lists are extracted and displayed with the method
-# description. If a method calls +yield+, then the parameters passed to yield
-# will also be displayed:
-#
-# def fred
-# ...
-# yield line, address
-#
-# This will get documented as:
-#
-# fred() { |line, address| ... }
-#
-# You can override this using a comment containing ':yields: ...' immediately
-# after the method definition
-#
-# def fred # :yields: index, position
-# # ...
-#
-# yield line, address
-#
-# which will get documented as
-#
-# fred() { |index, position| ... }
-#
-# +:yields:+ is an example of a documentation directive. These appear
-# immediately after the start of the document element they are modifying.
-#
-# RDoc automatically cross-references words with underscores or camel-case.
-# To suppress cross-references, prefix the word with a \ character. To
-# include special characters like "<tt>\n</tt>", you'll need to use
-# two \ characters in normal text, but only one in \<tt> text:
-#
-# "\\n" or "<tt>\n</tt>"
-#
-# produces:
-#
-# "\\n" or "<tt>\n</tt>"
-#
-# == Directives
-#
-# Directives are keywords surrounded by ":" characters.
-#
-# === Controlling what is documented
-#
-# [+:nodoc:+ / <tt>:nodoc: all</tt>]
-# This directive prevents documentation for the element from
-# being generated. For classes and modules, methods, aliases,
-# constants, and attributes directly within the affected class or
-# module also will be omitted. By default, though, modules and
-# classes within that class or module _will_ be documented. This is
-# turned off by adding the +all+ modifier.
-#
-# module MyModule # :nodoc:
-# class Input
-# end
-# end
-#
-# module OtherModule # :nodoc: all
-# class Output
-# end
-# end
-#
-# In the above code, only class <tt>MyModule::Input</tt> will be documented.
-#
-# The +:nodoc:+ directive, like +:enddoc:+, +:stopdoc:+ and +:startdoc:+
-# presented below, is local to the current file: if you do not want to
-# document a module that appears in several files, specify +:nodoc:+ on each
-# appearance, at least once per file.
-#
-# [+:stopdoc:+ / +:startdoc:+]
-# Stop and start adding new documentation elements to the current container.
-# For example, if a class has a number of constants that you don't want to
-# document, put a +:stopdoc:+ before the first, and a +:startdoc:+ after the
-# last. If you don't specify a +:startdoc:+ by the end of the container,
-# disables documentation for the rest of the current file.
-#
-# [+:doc:+]
-# Forces a method or attribute to be documented even if it wouldn't be
-# otherwise. Useful if, for example, you want to include documentation of a
-# particular private method.
-#
-# [+:enddoc:+]
-# Document nothing further at the current level: directives +:startdoc:+ and
-# +:doc:+ that appear after this will not be honored for the current container
-# (file, class or module), in the current file.
-#
-# [+:notnew:+ / +:not_new:+ / +:not-new:+ ]
-# Only applicable to the +initialize+ instance method. Normally RDoc
-# assumes that the documentation and parameters for +initialize+ are
-# actually for the +new+ method, and so fakes out a +new+ for the class.
-# The +:notnew:+ directive stops this. Remember that +initialize+ is private,
-# so you won't see the documentation unless you use the +-a+ command line
-# option.
-#
-# === Method arguments
-#
-# [+:arg:+ or +:args:+ _parameters_]
-# Overrides the default argument handling with exactly these parameters.
-#
-# ##
-# # :args: a, b
-#
-# def some_method(*a)
-# end
-#
-# [+:yield:+ or +:yields:+ _parameters_]
-# Overrides the default yield discovery with these parameters.
-#
-# ##
-# # :yields: key, value
-#
-# def each_thing &block
-# @things.each(&block)
-# end
-#
-# [+:call-seq:+]
-# Lines up to the next blank line or lines with a common prefix in the
-# comment are treated as the method's calling sequence, overriding the
-# default parsing of method parameters and yield arguments.
-#
-# Multiple lines may be used.
-#
-# # :call-seq:
-# # ARGF.readlines(sep=$/) -> array
-# # ARGF.readlines(limit) -> array
-# # ARGF.readlines(sep, limit) -> array
-# #
-# # ARGF.to_a(sep=$/) -> array
-# # ARGF.to_a(limit) -> array
-# # ARGF.to_a(sep, limit) -> array
-# #
-# # The remaining lines are documentation ...
-#
-# === Sections
-#
-# Sections allow you to group methods in a class into sensible containers. If
-# you use the sections 'Public', 'Internal' and 'Deprecated' (the three
-# allowed method statuses from TomDoc) the sections will be displayed in that
-# order placing the most useful methods at the top. Otherwise, sections will
-# be displayed in alphabetical order.
-#
-# [+:category:+ _section_]
-# Adds this item to the named +section+ overriding the current section. Use
-# this to group methods by section in RDoc output while maintaining a
-# sensible ordering (like alphabetical).
-#
-# # :category: Utility Methods
-# #
-# # CGI escapes +text+
-#
-# def convert_string text
-# CGI.escapeHTML text
-# end
-#
-# An empty category will place the item in the default category:
-#
-# # :category:
-# #
-# # This method is in the default category
-#
-# def some_method
-# # ...
-# end
-#
-# Unlike the :section: directive, :category: is not sticky. The category
-# only applies to the item immediately following the comment.
-#
-# Use the :section: directive to provide introductory text for a section of
-# documentation.
-#
-# [+:section:+ _title_]
-# Provides section introductory text in RDoc output. The title following
-# +:section:+ is used as the section name and the remainder of the comment
-# containing the section is used as introductory text. A section's comment
-# block must be separated from following comment blocks. Use an empty title
-# to switch to the default section.
-#
-# The :section: directive is sticky, so subsequent methods, aliases,
-# attributes, and classes will be contained in this section until the
-# section is changed. The :category: directive will override the :section:
-# directive.
-#
-# A :section: comment block may have one or more lines before the :section:
-# directive. These will be removed, and any identical lines at the end of
-# the block are also removed. This allows you to add visual cues to the
-# section.
-#
-# Example:
-#
-# # ----------------------------------------
-# # :section: My Section
-# # This is the section that I wrote.
-# # See it glisten in the noon-day sun.
-# # ----------------------------------------
-#
-# ##
-# # Comment for some_method
-#
-# def some_method
-# # ...
-# end
-#
-# === Other directives
-#
-# [+:markup:+ _type_]
-# Overrides the default markup type for this comment with the specified
-# markup type. For Ruby files, if the first comment contains this directive
-# it is applied automatically to all comments in the file.
-#
-# Unless you are converting between markup formats you should use a
-# <code>.rdoc_options</code> file to specify the default documentation
-# format for your entire project. See RDoc::Options@Saved+Options for
-# instructions.
-#
-# At the top of a file the +:markup:+ directive applies to the entire file:
-#
-# # coding: UTF-8
-# # :markup: TomDoc
-#
-# # TomDoc comment here ...
-#
-# class MyClass
-# # ...
-#
-# For just one comment:
-#
-# # ...
-# end
-#
-# # :markup: RDoc
-# #
-# # This is a comment in RDoc markup format ...
-#
-# def some_method
-# # ...
-#
-# See Markup@CONTRIBUTING for instructions on adding a new markup format.
-#
-# [+:include:+ _filename_]
-# Include the contents of the named file at this point. This directive
-# must appear alone on one line, possibly preceded by spaces. In this
-# position, it can be escaped with a \ in front of the first colon.
-#
-# The file will be searched for in the directories listed by the +--include+
-# option, or in the current directory by default. The contents of the file
-# will be shifted to have the same indentation as the ':' at the start of
-# the +:include:+ directive.
-#
-# [+:title:+ _text_]
-# Sets the title for the document. Equivalent to the <tt>--title</tt>
-# command line parameter. (The command line parameter overrides any :title:
-# directive in the source).
-#
-# [+:main:+ _name_]
-# Equivalent to the <tt>--main</tt> command line parameter.
-#
-#--
-# Original Author:: Dave Thomas, dave@pragmaticprogrammer.com
-# License:: Ruby license
-
-class RDoc::Markup
-
- ##
- # An AttributeManager which handles inline markup.
-
- attr_reader :attribute_manager
-
- ##
- # Parses +str+ into an RDoc::Markup::Document.
-
- def self.parse str
- RDoc::Markup::Parser.parse str
- rescue RDoc::Markup::Parser::Error => e
- $stderr.puts <<-EOF
-While parsing markup, RDoc encountered a #{e.class}:
-
-#{e}
-\tfrom #{e.backtrace.join "\n\tfrom "}
-
----8<---
-#{text}
----8<---
-
-RDoc #{RDoc::VERSION}
-
-Ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} #{RUBY_RELEASE_DATE}
-
-Please file a bug report with the above information at:
-
-https://github.com/rdoc/rdoc/issues
-
- EOF
- raise
- end
-
- ##
- # Take a block of text and use various heuristics to determine its
- # structure (paragraphs, lists, and so on). Invoke an event handler as we
- # identify significant chunks.
-
- def initialize attribute_manager = nil
- @attribute_manager = attribute_manager || RDoc::Markup::AttributeManager.new
- @output = nil
- end
-
- ##
- # Add to the sequences used to add formatting to an individual word (such
- # as *bold*). Matching entries will generate attributes that the output
- # formatters can recognize by their +name+.
-
- def add_word_pair(start, stop, name)
- @attribute_manager.add_word_pair(start, stop, name)
- end
-
- ##
- # Add to the sequences recognized as general markup.
-
- def add_html(tag, name)
- @attribute_manager.add_html(tag, name)
- end
-
- ##
- # Add to other inline sequences. For example, we could add WikiWords using
- # something like:
- #
- # parser.add_special(/\b([A-Z][a-z]+[A-Z]\w+)/, :WIKIWORD)
- #
- # Each wiki word will be presented to the output formatter via the
- # accept_special method.
-
- def add_special(pattern, name)
- @attribute_manager.add_special(pattern, name)
- end
-
- ##
- # We take +input+, parse it if necessary, then invoke the output +formatter+
- # using a Visitor to render the result.
-
- def convert input, formatter
- document = case input
- when RDoc::Markup::Document then
- input
- else
- RDoc::Markup::Parser.parse input
- end
-
- document.accept formatter
- end
-
- autoload :Parser, 'rdoc/markup/parser'
- autoload :PreProcess, 'rdoc/markup/pre_process'
-
- # Inline markup classes
- autoload :AttrChanger, 'rdoc/markup/attr_changer'
- autoload :AttrSpan, 'rdoc/markup/attr_span'
- autoload :Attributes, 'rdoc/markup/attributes'
- autoload :AttributeManager, 'rdoc/markup/attribute_manager'
- autoload :Special, 'rdoc/markup/special'
-
- # RDoc::Markup AST
- autoload :BlankLine, 'rdoc/markup/blank_line'
- autoload :BlockQuote, 'rdoc/markup/block_quote'
- autoload :Document, 'rdoc/markup/document'
- autoload :HardBreak, 'rdoc/markup/hard_break'
- autoload :Heading, 'rdoc/markup/heading'
- autoload :Include, 'rdoc/markup/include'
- autoload :IndentedParagraph, 'rdoc/markup/indented_paragraph'
- autoload :List, 'rdoc/markup/list'
- autoload :ListItem, 'rdoc/markup/list_item'
- autoload :Paragraph, 'rdoc/markup/paragraph'
- autoload :Raw, 'rdoc/markup/raw'
- autoload :Rule, 'rdoc/markup/rule'
- autoload :Verbatim, 'rdoc/markup/verbatim'
-
- # Formatters
- autoload :Formatter, 'rdoc/markup/formatter'
- autoload :FormatterTestCase, 'rdoc/markup/formatter_test_case'
- autoload :TextFormatterTestCase, 'rdoc/markup/text_formatter_test_case'
-
- autoload :ToAnsi, 'rdoc/markup/to_ansi'
- autoload :ToBs, 'rdoc/markup/to_bs'
- autoload :ToHtml, 'rdoc/markup/to_html'
- autoload :ToHtmlCrossref, 'rdoc/markup/to_html_crossref'
- autoload :ToHtmlSnippet, 'rdoc/markup/to_html_snippet'
- autoload :ToLabel, 'rdoc/markup/to_label'
- autoload :ToMarkdown, 'rdoc/markup/to_markdown'
- autoload :ToRdoc, 'rdoc/markup/to_rdoc'
- autoload :ToTableOfContents, 'rdoc/markup/to_table_of_contents'
- autoload :ToTest, 'rdoc/markup/to_test'
- autoload :ToTtOnly, 'rdoc/markup/to_tt_only'
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/attr_changer.rb b/ruby_2_2/lib/rdoc/markup/attr_changer.rb
deleted file mode 100644
index 1772f18b2b..0000000000
--- a/ruby_2_2/lib/rdoc/markup/attr_changer.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-class RDoc::Markup
-
- AttrChanger = Struct.new :turn_on, :turn_off # :nodoc:
-
-end
-
-##
-# An AttrChanger records a change in attributes. It contains a bitmap of the
-# attributes to turn on, and a bitmap of those to turn off.
-
-class RDoc::Markup::AttrChanger
-
- def to_s # :nodoc:
- "Attr: +#{turn_on}/-#{turn_off}"
- end
-
- def inspect # :nodoc:
- '+%d/-%d' % [turn_on, turn_off]
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/attr_span.rb b/ruby_2_2/lib/rdoc/markup/attr_span.rb
deleted file mode 100644
index b5c1b3b7b7..0000000000
--- a/ruby_2_2/lib/rdoc/markup/attr_span.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-##
-# An array of attributes which parallels the characters in a string.
-
-class RDoc::Markup::AttrSpan
-
- ##
- # Creates a new AttrSpan for +length+ characters
-
- def initialize(length)
- @attrs = Array.new(length, 0)
- end
-
- ##
- # Toggles +bits+ from +start+ to +length+
- def set_attrs(start, length, bits)
- for i in start ... (start+length)
- @attrs[i] |= bits
- end
- end
-
- ##
- # Accesses flags for character +n+
-
- def [](n)
- @attrs[n]
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/attribute_manager.rb b/ruby_2_2/lib/rdoc/markup/attribute_manager.rb
deleted file mode 100644
index ce4ac76d5b..0000000000
--- a/ruby_2_2/lib/rdoc/markup/attribute_manager.rb
+++ /dev/null
@@ -1,343 +0,0 @@
-##
-# Manages changes of attributes in a block of text
-
-class RDoc::Markup::AttributeManager
-
- ##
- # The NUL character
-
- NULL = "\000".freeze
-
- #--
- # We work by substituting non-printing characters in to the text. For now
- # I'm assuming that I can substitute a character in the range 0..8 for a 7
- # bit character without damaging the encoded string, but this might be
- # optimistic
- #++
-
- A_PROTECT = 004 # :nodoc:
-
- ##
- # Special mask character to prevent inline markup handling
-
- PROTECT_ATTR = A_PROTECT.chr # :nodoc:
-
- ##
- # The attributes enabled for this markup object.
-
- attr_reader :attributes
-
- ##
- # This maps delimiters that occur around words (such as *bold* or +tt+)
- # where the start and end delimiters and the same. This lets us optimize
- # the regexp
-
- attr_reader :matching_word_pairs
-
- ##
- # And this is used when the delimiters aren't the same. In this case the
- # hash maps a pattern to the attribute character
-
- attr_reader :word_pair_map
-
- ##
- # This maps HTML tags to the corresponding attribute char
-
- attr_reader :html_tags
-
- ##
- # A \ in front of a character that would normally be processed turns off
- # processing. We do this by turning \< into <#{PROTECT}
-
- attr_reader :protectable
-
- ##
- # And this maps _special_ sequences to a name. A special sequence is
- # something like a WikiWord
-
- attr_reader :special
-
- ##
- # Creates a new attribute manager that understands bold, emphasized and
- # teletype text.
-
- def initialize
- @html_tags = {}
- @matching_word_pairs = {}
- @protectable = %w[<]
- @special = []
- @word_pair_map = {}
- @attributes = RDoc::Markup::Attributes.new
-
- add_word_pair "*", "*", :BOLD
- add_word_pair "_", "_", :EM
- add_word_pair "+", "+", :TT
-
- add_html "em", :EM
- add_html "i", :EM
- add_html "b", :BOLD
- add_html "tt", :TT
- add_html "code", :TT
- end
-
- ##
- # Return an attribute object with the given turn_on and turn_off bits set
-
- def attribute(turn_on, turn_off)
- RDoc::Markup::AttrChanger.new turn_on, turn_off
- end
-
- ##
- # Changes the current attribute from +current+ to +new+
-
- def change_attribute current, new
- diff = current ^ new
- attribute(new & diff, current & diff)
- end
-
- ##
- # Used by the tests to change attributes by name from +current_set+ to
- # +new_set+
-
- def changed_attribute_by_name current_set, new_set
- current = new = 0
- current_set.each do |name|
- current |= @attributes.bitmap_for(name)
- end
-
- new_set.each do |name|
- new |= @attributes.bitmap_for(name)
- end
-
- change_attribute(current, new)
- end
-
- ##
- # Copies +start_pos+ to +end_pos+ from the current string
-
- def copy_string(start_pos, end_pos)
- res = @str[start_pos...end_pos]
- res.gsub!(/\000/, '')
- res
- end
-
- ##
- # Map attributes like <b>text</b>to the sequence
- # \001\002<char>\001\003<char>, where <char> is a per-attribute specific
- # character
-
- def convert_attrs(str, attrs)
- # first do matching ones
- tags = @matching_word_pairs.keys.join("")
-
- re = /(^|\W)([#{tags}])([#\\]?[\w:.\/-]+?\S?)\2(\W|$)/
-
- 1 while str.gsub!(re) do
- attr = @matching_word_pairs[$2]
- attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr)
- $1 + NULL * $2.length + $3 + NULL * $2.length + $4
- end
-
- # then non-matching
- unless @word_pair_map.empty? then
- @word_pair_map.each do |regexp, attr|
- str.gsub!(regexp) {
- attrs.set_attrs($`.length + $1.length, $2.length, attr)
- NULL * $1.length + $2 + NULL * $3.length
- }
- end
- end
- end
-
- ##
- # Converts HTML tags to RDoc attributes
-
- def convert_html(str, attrs)
- tags = @html_tags.keys.join '|'
-
- 1 while str.gsub!(/<(#{tags})>(.*?)<\/\1>/i) {
- attr = @html_tags[$1.downcase]
- html_length = $1.length + 2
- seq = NULL * html_length
- attrs.set_attrs($`.length + html_length, $2.length, attr)
- seq + $2 + seq + NULL
- }
- end
-
- ##
- # Converts special sequences to RDoc attributes
-
- def convert_specials str, attrs
- @special.each do |regexp, attribute|
- str.scan(regexp) do
- capture = $~.size == 1 ? 0 : 1
-
- s, e = $~.offset capture
-
- attrs.set_attrs s, e - s, attribute | @attributes.special
- end
- end
- end
-
- ##
- # Escapes special sequences of text to prevent conversion to RDoc
-
- def mask_protected_sequences
- # protect __send__, __FILE__, etc.
- @str.gsub!(/__([a-z]+)__/i,
- "_#{PROTECT_ATTR}_#{PROTECT_ATTR}\\1_#{PROTECT_ATTR}_#{PROTECT_ATTR}")
- @str.gsub!(/(\A|[^\\])\\([#{Regexp.escape @protectable.join}])/m,
- "\\1\\2#{PROTECT_ATTR}")
- @str.gsub!(/\\(\\[#{Regexp.escape @protectable.join}])/m, "\\1")
- end
-
- ##
- # Unescapes special sequences of text
-
- def unmask_protected_sequences
- @str.gsub!(/(.)#{PROTECT_ATTR}/, "\\1\000")
- end
-
- ##
- # Adds a markup class with +name+ for words wrapped in the +start+ and
- # +stop+ character. To make words wrapped with "*" bold:
- #
- # am.add_word_pair '*', '*', :BOLD
-
- def add_word_pair(start, stop, name)
- raise ArgumentError, "Word flags may not start with '<'" if
- start[0,1] == '<'
-
- bitmap = @attributes.bitmap_for name
-
- if start == stop then
- @matching_word_pairs[start] = bitmap
- else
- pattern = /(#{Regexp.escape start})(\S+)(#{Regexp.escape stop})/
- @word_pair_map[pattern] = bitmap
- end
-
- @protectable << start[0,1]
- @protectable.uniq!
- end
-
- ##
- # Adds a markup class with +name+ for words surrounded by HTML tag +tag+.
- # To process emphasis tags:
- #
- # am.add_html 'em', :EM
-
- def add_html(tag, name)
- @html_tags[tag.downcase] = @attributes.bitmap_for name
- end
-
- ##
- # Adds a special handler for +pattern+ with +name+. A simple URL handler
- # would be:
- #
- # @am.add_special(/((https?:)\S+\w)/, :HYPERLINK)
-
- def add_special pattern, name
- @special << [pattern, @attributes.bitmap_for(name)]
- end
-
- ##
- # Processes +str+ converting attributes, HTML and specials
-
- def flow str
- @str = str
-
- mask_protected_sequences
-
- @attrs = RDoc::Markup::AttrSpan.new @str.length
-
- convert_attrs @str, @attrs
- convert_html @str, @attrs
- convert_specials @str, @attrs
-
- unmask_protected_sequences
-
- split_into_flow
- end
-
- ##
- # Debug method that prints a string along with its attributes
-
- def display_attributes
- puts
- puts @str.tr(NULL, "!")
- bit = 1
- 16.times do |bno|
- line = ""
- @str.length.times do |i|
- if (@attrs[i] & bit) == 0
- line << " "
- else
- if bno.zero?
- line << "S"
- else
- line << ("%d" % (bno+1))
- end
- end
- end
- puts(line) unless line =~ /^ *$/
- bit <<= 1
- end
- end
-
- ##
- # Splits the string into chunks by attribute change
-
- def split_into_flow
- res = []
- current_attr = 0
-
- str_len = @str.length
-
- # skip leading invisible text
- i = 0
- i += 1 while i < str_len and @str[i].chr == "\0"
- start_pos = i
-
- # then scan the string, chunking it on attribute changes
- while i < str_len
- new_attr = @attrs[i]
- if new_attr != current_attr
- if i > start_pos
- res << copy_string(start_pos, i)
- start_pos = i
- end
-
- res << change_attribute(current_attr, new_attr)
- current_attr = new_attr
-
- if (current_attr & @attributes.special) != 0 then
- i += 1 while
- i < str_len and (@attrs[i] & @attributes.special) != 0
-
- res << RDoc::Markup::Special.new(current_attr,
- copy_string(start_pos, i))
- start_pos = i
- next
- end
- end
-
- # move on, skipping any invisible characters
- begin
- i += 1
- end while i < str_len and @str[i].chr == "\0"
- end
-
- # tidy up trailing text
- if start_pos < str_len
- res << copy_string(start_pos, str_len)
- end
-
- # and reset to all attributes off
- res << change_attribute(current_attr, 0) if current_attr != 0
-
- res
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/attributes.rb b/ruby_2_2/lib/rdoc/markup/attributes.rb
deleted file mode 100644
index 3423f10ca7..0000000000
--- a/ruby_2_2/lib/rdoc/markup/attributes.rb
+++ /dev/null
@@ -1,70 +0,0 @@
-##
-# We manage a set of attributes. Each attribute has a symbol name and a bit
-# value.
-
-class RDoc::Markup::Attributes
-
- ##
- # The special attribute type. See RDoc::Markup#add_special
-
- attr_reader :special
-
- ##
- # Creates a new attributes set.
-
- def initialize
- @special = 1
-
- @name_to_bitmap = [
- [:_SPECIAL_, @special],
- ]
-
- @next_bitmap = @special << 1
- end
-
- ##
- # Returns a unique bit for +name+
-
- def bitmap_for name
- bitmap = @name_to_bitmap.assoc name
-
- unless bitmap then
- bitmap = @next_bitmap
- @next_bitmap <<= 1
- @name_to_bitmap << [name, bitmap]
- else
- bitmap = bitmap.last
- end
-
- bitmap
- end
-
- ##
- # Returns a string representation of +bitmap+
-
- def as_string bitmap
- return 'none' if bitmap.zero?
- res = []
-
- @name_to_bitmap.each do |name, bit|
- res << name if (bitmap & bit) != 0
- end
-
- res.join ','
- end
-
- ##
- # yields each attribute name in +bitmap+
-
- def each_name_of bitmap
- return enum_for __method__, bitmap unless block_given?
-
- @name_to_bitmap.each do |name, bit|
- next if bit == @special
-
- yield name.to_s if (bitmap & bit) != 0
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/blank_line.rb b/ruby_2_2/lib/rdoc/markup/blank_line.rb
deleted file mode 100644
index 5da0ac8d81..0000000000
--- a/ruby_2_2/lib/rdoc/markup/blank_line.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-##
-# An empty line. This class is a singleton.
-
-class RDoc::Markup::BlankLine
-
- @instance = new
-
- ##
- # RDoc::Markup::BlankLine is a singleton
-
- def self.new
- @instance
- end
-
- ##
- # Calls #accept_blank_line on +visitor+
-
- def accept visitor
- visitor.accept_blank_line self
- end
-
- def pretty_print q # :nodoc:
- q.text 'blankline'
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/block_quote.rb b/ruby_2_2/lib/rdoc/markup/block_quote.rb
deleted file mode 100644
index 552f0c4baa..0000000000
--- a/ruby_2_2/lib/rdoc/markup/block_quote.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-##
-# A quoted section which contains markup items.
-
-class RDoc::Markup::BlockQuote < RDoc::Markup::Raw
-
- ##
- # Calls #accept_block_quote on +visitor+
-
- def accept visitor
- visitor.accept_block_quote self
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/document.rb b/ruby_2_2/lib/rdoc/markup/document.rb
deleted file mode 100644
index be93d80eec..0000000000
--- a/ruby_2_2/lib/rdoc/markup/document.rb
+++ /dev/null
@@ -1,164 +0,0 @@
-##
-# A Document containing lists, headings, paragraphs, etc.
-
-class RDoc::Markup::Document
-
- include Enumerable
-
- ##
- # The file this document was created from. See also
- # RDoc::ClassModule#add_comment
-
- attr_reader :file
-
- ##
- # If a heading is below the given level it will be omitted from the
- # table_of_contents
-
- attr_accessor :omit_headings_below
-
- ##
- # The parts of the Document
-
- attr_reader :parts
-
- ##
- # Creates a new Document with +parts+
-
- def initialize *parts
- @parts = []
- @parts.concat parts
-
- @file = nil
- @omit_headings_from_table_of_contents_below = nil
- end
-
- ##
- # Appends +part+ to the document
-
- def << part
- case part
- when RDoc::Markup::Document then
- unless part.empty? then
- parts.concat part.parts
- parts << RDoc::Markup::BlankLine.new
- end
- when String then
- raise ArgumentError,
- "expected RDoc::Markup::Document and friends, got String" unless
- part.empty?
- else
- parts << part
- end
- end
-
- def == other # :nodoc:
- self.class == other.class and
- @file == other.file and
- @parts == other.parts
- end
-
- ##
- # Runs this document and all its #items through +visitor+
-
- def accept visitor
- visitor.start_accepting
-
- visitor.accept_document self
-
- visitor.end_accepting
- end
-
- ##
- # Concatenates the given +parts+ onto the document
-
- def concat parts
- self.parts.concat parts
- end
-
- ##
- # Enumerator for the parts of this document
-
- def each &block
- @parts.each(&block)
- end
-
- ##
- # Does this document have no parts?
-
- def empty?
- @parts.empty? or (@parts.length == 1 and merged? and @parts.first.empty?)
- end
-
- ##
- # The file this Document was created from.
-
- def file= location
- @file = case location
- when RDoc::TopLevel then
- location.relative_name
- else
- location
- end
- end
-
- ##
- # When this is a collection of documents (#file is not set and this document
- # contains only other documents as its direct children) #merge replaces
- # documents in this class with documents from +other+ when the file matches
- # and adds documents from +other+ when the files do not.
- #
- # The information in +other+ is preferred over the receiver
-
- def merge other
- if empty? then
- @parts = other.parts
- return self
- end
-
- other.parts.each do |other_part|
- self.parts.delete_if do |self_part|
- self_part.file and self_part.file == other_part.file
- end
-
- self.parts << other_part
- end
-
- self
- end
-
- ##
- # Does this Document contain other Documents?
-
- def merged?
- RDoc::Markup::Document === @parts.first
- end
-
- def pretty_print q # :nodoc:
- start = @file ? "[doc (#{@file}): " : '[doc: '
-
- q.group 2, start, ']' do
- q.seplist @parts do |part|
- q.pp part
- end
- end
- end
-
- ##
- # Appends +parts+ to the document
-
- def push *parts
- self.parts.concat parts
- end
-
- ##
- # Returns an Array of headings in the document.
- #
- # Require 'rdoc/markup/formatter' before calling this method.
-
- def table_of_contents
- accept RDoc::Markup::ToTableOfContents.to_toc
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/formatter.rb b/ruby_2_2/lib/rdoc/markup/formatter.rb
deleted file mode 100644
index 7661c95239..0000000000
--- a/ruby_2_2/lib/rdoc/markup/formatter.rb
+++ /dev/null
@@ -1,264 +0,0 @@
-##
-# Base class for RDoc markup formatters
-#
-# Formatters are a visitor that converts an RDoc::Markup tree (from a comment)
-# into some kind of output. RDoc ships with formatters for converting back to
-# rdoc, ANSI text, HTML, a Table of Contents and other formats.
-#
-# If you'd like to write your own Formatter use
-# RDoc::Markup::FormatterTestCase. If you're writing a text-output formatter
-# use RDoc::Markup::TextFormatterTestCase which provides extra test cases.
-
-class RDoc::Markup::Formatter
-
- ##
- # Tag for inline markup containing a +bit+ for the bitmask and the +on+ and
- # +off+ triggers.
-
- InlineTag = Struct.new(:bit, :on, :off)
-
- ##
- # Converts a target url to one that is relative to a given path
-
- def self.gen_relative_url path, target
- from = File.dirname path
- to, to_file = File.split target
-
- from = from.split "/"
- to = to.split "/"
-
- from.delete '.'
- to.delete '.'
-
- while from.size > 0 and to.size > 0 and from[0] == to[0] do
- from.shift
- to.shift
- end
-
- from.fill ".."
- from.concat to
- from << to_file
- File.join(*from)
- end
-
- ##
- # Creates a new Formatter
-
- def initialize options, markup = nil
- @options = options
-
- @markup = markup || RDoc::Markup.new
- @am = @markup.attribute_manager
- @am.add_special(/<br>/, :HARD_BREAK)
-
- @attributes = @am.attributes
-
- @attr_tags = []
-
- @in_tt = 0
- @tt_bit = @attributes.bitmap_for :TT
-
- @hard_break = ''
- @from_path = '.'
- end
-
- ##
- # Adds +document+ to the output
-
- def accept_document document
- document.parts.each do |item|
- case item
- when RDoc::Markup::Document then # HACK
- accept_document item
- else
- item.accept self
- end
- end
- end
-
- ##
- # Adds a special for links of the form rdoc-...:
-
- def add_special_RDOCLINK
- @markup.add_special(/rdoc-[a-z]+:[^\s\]]+/, :RDOCLINK)
- end
-
- ##
- # Adds a special for links of the form {<text>}[<url>] and <word>[<url>]
-
- def add_special_TIDYLINK
- @markup.add_special(/(?:
- \{.*?\} | # multi-word label
- \b[^\s{}]+? # single-word label
- )
-
- \[\S+?\] # link target
- /x, :TIDYLINK)
- end
-
- ##
- # Add a new set of tags for an attribute. We allow separate start and end
- # tags for flexibility
-
- def add_tag(name, start, stop)
- attr = @attributes.bitmap_for name
- @attr_tags << InlineTag.new(attr, start, stop)
- end
-
- ##
- # Allows +tag+ to be decorated with additional information.
-
- def annotate(tag)
- tag
- end
-
- ##
- # Marks up +content+
-
- def convert content
- @markup.convert content, self
- end
-
- ##
- # Converts flow items +flow+
-
- def convert_flow(flow)
- res = []
-
- flow.each do |item|
- case item
- when String then
- res << convert_string(item)
- when RDoc::Markup::AttrChanger then
- off_tags res, item
- on_tags res, item
- when RDoc::Markup::Special then
- res << convert_special(item)
- else
- raise "Unknown flow element: #{item.inspect}"
- end
- end
-
- res.join
- end
-
- ##
- # Converts added specials. See RDoc::Markup#add_special
-
- def convert_special special
- return special.text if in_tt?
-
- handled = false
-
- @attributes.each_name_of special.type do |name|
- method_name = "handle_special_#{name}"
-
- if respond_to? method_name then
- special.text = send method_name, special
- handled = true
- end
- end
-
- unless handled then
- special_name = @attributes.as_string special.type
-
- raise RDoc::Error, "Unhandled special #{special_name}: #{special}"
- end
-
- special.text
- end
-
- ##
- # Converts a string to be fancier if desired
-
- def convert_string string
- string
- end
-
- ##
- # Use ignore in your subclass to ignore the content of a node.
- #
- # ##
- # # We don't support raw nodes in ToNoRaw
- #
- # alias accept_raw ignore
-
- def ignore *node
- end
-
- ##
- # Are we currently inside tt tags?
-
- def in_tt?
- @in_tt > 0
- end
-
- ##
- # Turns on tags for +item+ on +res+
-
- def on_tags res, item
- attr_mask = item.turn_on
- return if attr_mask.zero?
-
- @attr_tags.each do |tag|
- if attr_mask & tag.bit != 0 then
- res << annotate(tag.on)
- @in_tt += 1 if tt? tag
- end
- end
- end
-
- ##
- # Turns off tags for +item+ on +res+
-
- def off_tags res, item
- attr_mask = item.turn_off
- return if attr_mask.zero?
-
- @attr_tags.reverse_each do |tag|
- if attr_mask & tag.bit != 0 then
- @in_tt -= 1 if tt? tag
- res << annotate(tag.off)
- end
- end
- end
-
- ##
- # Extracts and a scheme, url and an anchor id from +url+ and returns them.
-
- def parse_url url
- case url
- when /^rdoc-label:([^:]*)(?::(.*))?/ then
- scheme = 'link'
- path = "##{$1}"
- id = " id=\"#{$2}\"" if $2
- when /([A-Za-z]+):(.*)/ then
- scheme = $1.downcase
- path = $2
- when /^#/ then
- else
- scheme = 'http'
- path = url
- url = url
- end
-
- if scheme == 'link' then
- url = if path[0, 1] == '#' then # is this meaningful?
- path
- else
- self.class.gen_relative_url @from_path, path
- end
- end
-
- [scheme, url, id]
- end
-
- ##
- # Is +tag+ a tt tag?
-
- def tt? tag
- tag.bit == @tt_bit
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/formatter_test_case.rb b/ruby_2_2/lib/rdoc/markup/formatter_test_case.rb
deleted file mode 100644
index 6616a75898..0000000000
--- a/ruby_2_2/lib/rdoc/markup/formatter_test_case.rb
+++ /dev/null
@@ -1,767 +0,0 @@
-require 'minitest/unit'
-
-##
-# Test case for creating new RDoc::Markup formatters. See
-# test/test_rdoc_markup_to_*.rb for examples.
-#
-# This test case adds a variety of tests to your subclass when
-# #add_visitor_tests is called. Most tests set up a scenario then call a
-# method you will provide to perform the assertion on the output.
-#
-# Your subclass must instantiate a visitor and assign it to <tt>@to</tt>.
-#
-# For example, test_accept_blank_line sets up a RDoc::Markup::BlockLine then
-# calls accept_blank_line on your visitor. You are responsible for asserting
-# that the output is correct.
-#
-# Example:
-#
-# class TestRDocMarkupToNewFormat < RDoc::Markup::FormatterTestCase
-#
-# add_visitor_tests
-#
-# def setup
-# super
-#
-# @to = RDoc::Markup::ToNewFormat.new
-# end
-#
-# def accept_blank_line
-# assert_equal :junk, @to.res.join
-# end
-#
-# # ...
-#
-# end
-
-class RDoc::Markup::FormatterTestCase < RDoc::TestCase
-
- ##
- # Call #setup when inheriting from this test case.
- #
- # Provides the following instance variables:
- #
- # +@m+:: RDoc::Markup.new
- # +@RM+:: RDoc::Markup # to reduce typing
- # +@bullet_list+:: @RM::List.new :BULLET, # ...
- # +@label_list+:: @RM::List.new :LABEL, # ...
- # +@lalpha_list+:: @RM::List.new :LALPHA, # ...
- # +@note_list+:: @RM::List.new :NOTE, # ...
- # +@number_list+:: @RM::List.new :NUMBER, # ...
- # +@ualpha_list+:: @RM::List.new :UALPHA, # ...
-
- def setup
- super
-
- @options = RDoc::Options.new
-
- @m = @RM.new
-
- @bullet_list = @RM::List.new(:BULLET,
- @RM::ListItem.new(nil, @RM::Paragraph.new('l1')),
- @RM::ListItem.new(nil, @RM::Paragraph.new('l2')))
-
- @label_list = @RM::List.new(:LABEL,
- @RM::ListItem.new('cat', @RM::Paragraph.new('cats are cool')),
- @RM::ListItem.new('dog', @RM::Paragraph.new('dogs are cool too')))
-
- @lalpha_list = @RM::List.new(:LALPHA,
- @RM::ListItem.new(nil, @RM::Paragraph.new('l1')),
- @RM::ListItem.new(nil, @RM::Paragraph.new('l2')))
-
- @note_list = @RM::List.new(:NOTE,
- @RM::ListItem.new('cat', @RM::Paragraph.new('cats are cool')),
- @RM::ListItem.new('dog', @RM::Paragraph.new('dogs are cool too')))
-
- @number_list = @RM::List.new(:NUMBER,
- @RM::ListItem.new(nil, @RM::Paragraph.new('l1')),
- @RM::ListItem.new(nil, @RM::Paragraph.new('l2')))
-
- @ualpha_list = @RM::List.new(:UALPHA,
- @RM::ListItem.new(nil, @RM::Paragraph.new('l1')),
- @RM::ListItem.new(nil, @RM::Paragraph.new('l2')))
- end
-
- ##
- # Call to add the visitor tests to your test case
-
- def self.add_visitor_tests
- class_eval do
-
- ##
- # Calls start_accepting which needs to verify startup state
-
- def test_start_accepting
- @to.start_accepting
-
- start_accepting
- end
-
- ##
- # Calls end_accepting on your test case which needs to call
- # <tt>@to.end_accepting</tt> and verify document generation
-
- def test_end_accepting
- @to.start_accepting
- @to.res << 'hi'
-
- end_accepting
- end
-
- ##
- # Calls accept_blank_line
-
- def test_accept_blank_line
- @to.start_accepting
-
- @to.accept_blank_line @RM::BlankLine.new
-
- accept_blank_line
- end
-
- ##
- # Calls accept_block_quote
-
- def test_accept_block_quote
- @to.start_accepting
-
- @to.accept_block_quote block para 'quote'
-
- accept_block_quote
- end
- ##
- # Test case that calls <tt>@to.accept_document</tt>
-
- def test_accept_document
- @to.start_accepting
- @to.accept_document @RM::Document.new @RM::Paragraph.new 'hello'
-
- accept_document
- end
-
- ##
- # Calls accept_heading with a level 5 RDoc::Markup::Heading
-
- def test_accept_heading
- @to.start_accepting
-
- @to.accept_heading @RM::Heading.new(5, 'Hello')
-
- accept_heading
- end
-
- ##
- # Calls accept_heading_1 with a level 1 RDoc::Markup::Heading
-
- def test_accept_heading_1
- @to.start_accepting
-
- @to.accept_heading @RM::Heading.new(1, 'Hello')
-
- accept_heading_1
- end
-
- ##
- # Calls accept_heading_2 with a level 2 RDoc::Markup::Heading
-
- def test_accept_heading_2
- @to.start_accepting
-
- @to.accept_heading @RM::Heading.new(2, 'Hello')
-
- accept_heading_2
- end
-
- ##
- # Calls accept_heading_3 with a level 3 RDoc::Markup::Heading
-
- def test_accept_heading_3
- # HACK this doesn't belong here
- skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars
-
- @to.start_accepting
-
- @to.accept_heading @RM::Heading.new(3, 'Hello')
-
- accept_heading_3
- end
-
- ##
- # Calls accept_heading_4 with a level 4 RDoc::Markup::Heading
-
- def test_accept_heading_4
- @to.start_accepting
-
- @to.accept_heading @RM::Heading.new(4, 'Hello')
-
- accept_heading_4
- end
-
- ##
- # Calls accept_heading_b with a bold level 1 RDoc::Markup::Heading
-
- def test_accept_heading_b
- @to.start_accepting
-
- @to.accept_heading @RM::Heading.new(1, '*Hello*')
-
- accept_heading_b
- end
-
- ##
- # Calls accept_heading_suppressed_crossref with a level 1
- # RDoc::Markup::Heading containing a suppressed crossref
-
- def test_accept_heading_suppressed_crossref # HACK to_html_crossref test
- @to.start_accepting
-
- @to.accept_heading @RM::Heading.new(1, '\\Hello')
-
- accept_heading_suppressed_crossref
- end
-
- ##
- # Calls accept_paragraph
-
- def test_accept_paragraph
- @to.start_accepting
-
- @to.accept_paragraph @RM::Paragraph.new('hi')
-
- accept_paragraph
- end
-
- ##
- # Calls accept_paragraph_b with a RDoc::Markup::Paragraph containing
- # bold words
-
- def test_accept_paragraph_b
- @to.start_accepting
-
- @to.accept_paragraph @RM::Paragraph.new('reg <b>bold words</b> reg')
-
- accept_paragraph_b
- end
-
- ##
- # Calls accept_paragraph_br with a RDoc::Markup::Paragraph containing
- # a \<br>
-
- def test_accept_paragraph_br
- @to.start_accepting
-
- @to.accept_paragraph para 'one<br>two'
-
- accept_paragraph_br
- end
-
- ##
- # Calls accept_paragraph with a Paragraph containing a hard break
-
- def test_accept_paragraph_break
- @to.start_accepting
-
- @to.accept_paragraph para('hello', hard_break, 'world')
-
- accept_paragraph_break
- end
-
- ##
- # Calls accept_paragraph_i with a RDoc::Markup::Paragraph containing
- # emphasized words
-
- def test_accept_paragraph_i
- @to.start_accepting
-
- @to.accept_paragraph @RM::Paragraph.new('reg <em>italic words</em> reg')
-
- accept_paragraph_i
- end
-
- ##
- # Calls accept_paragraph_plus with a RDoc::Markup::Paragraph containing
- # teletype words
-
- def test_accept_paragraph_plus
- @to.start_accepting
-
- @to.accept_paragraph @RM::Paragraph.new('reg +teletype+ reg')
-
- accept_paragraph_plus
- end
-
- ##
- # Calls accept_paragraph_star with a RDoc::Markup::Paragraph containing
- # bold words
-
- def test_accept_paragraph_star
- @to.start_accepting
-
- @to.accept_paragraph @RM::Paragraph.new('reg *bold* reg')
-
- accept_paragraph_star
- end
-
- ##
- # Calls accept_paragraph_underscore with a RDoc::Markup::Paragraph
- # containing emphasized words
-
- def test_accept_paragraph_underscore
- @to.start_accepting
-
- @to.accept_paragraph @RM::Paragraph.new('reg _italic_ reg')
-
- accept_paragraph_underscore
- end
-
- ##
- # Calls accept_verbatim with a RDoc::Markup::Verbatim
-
- def test_accept_verbatim
- @to.start_accepting
-
- @to.accept_verbatim @RM::Verbatim.new("hi\n", " world\n")
-
- accept_verbatim
- end
-
- ##
- # Calls accept_raw with a RDoc::Markup::Raw
-
- def test_accept_raw
- @to.start_accepting
-
- @to.accept_raw @RM::Raw.new("<table>",
- "<tr><th>Name<th>Count",
- "<tr><td>a<td>1",
- "<tr><td>b<td>2",
- "</table>")
-
- accept_raw
- end
-
- ##
- # Calls accept_rule with a RDoc::Markup::Rule
-
- def test_accept_rule
- @to.start_accepting
-
- @to.accept_rule @RM::Rule.new(4)
-
- accept_rule
- end
-
- ##
- # Calls accept_list_item_start_bullet
-
- def test_accept_list_item_start_bullet
- @to.start_accepting
-
- @to.accept_list_start @bullet_list
-
- @to.accept_list_item_start @bullet_list.items.first
-
- accept_list_item_start_bullet
- end
-
- ##
- # Calls accept_list_item_start_label
-
- def test_accept_list_item_start_label
- @to.start_accepting
-
- @to.accept_list_start @label_list
-
- @to.accept_list_item_start @label_list.items.first
-
- accept_list_item_start_label
- end
-
- ##
- # Calls accept_list_item_start_lalpha
-
- def test_accept_list_item_start_lalpha
- @to.start_accepting
-
- @to.accept_list_start @lalpha_list
-
- @to.accept_list_item_start @lalpha_list.items.first
-
- accept_list_item_start_lalpha
- end
-
- ##
- # Calls accept_list_item_start_note
-
- def test_accept_list_item_start_note
- @to.start_accepting
-
- @to.accept_list_start @note_list
-
- @to.accept_list_item_start @note_list.items.first
-
- accept_list_item_start_note
- end
-
- ##
- # Calls accept_list_item_start_note_2
-
- def test_accept_list_item_start_note_2
- list = list(:NOTE,
- item('<tt>teletype</tt>',
- para('teletype description')))
-
- @to.start_accepting
-
- list.accept @to
-
- @to.end_accepting
-
- accept_list_item_start_note_2
- end
-
- ##
- # Calls accept_list_item_start_note_multi_description
-
- def test_accept_list_item_start_note_multi_description
- list = list(:NOTE,
- item(%w[label],
- para('description one')),
- item(nil, para('description two')))
-
- @to.start_accepting
-
- list.accept @to
-
- @to.end_accepting
-
- accept_list_item_start_note_multi_description
- end
-
- ##
- # Calls accept_list_item_start_note_multi_label
-
- def test_accept_list_item_start_note_multi_label
- list = list(:NOTE,
- item(%w[one two],
- para('two headers')))
-
- @to.start_accepting
-
- list.accept @to
-
- @to.end_accepting
-
- accept_list_item_start_note_multi_label
- end
-
- ##
- # Calls accept_list_item_start_number
-
- def test_accept_list_item_start_number
- @to.start_accepting
-
- @to.accept_list_start @number_list
-
- @to.accept_list_item_start @number_list.items.first
-
- accept_list_item_start_number
- end
-
- ##
- # Calls accept_list_item_start_ualpha
-
- def test_accept_list_item_start_ualpha
- @to.start_accepting
-
- @to.accept_list_start @ualpha_list
-
- @to.accept_list_item_start @ualpha_list.items.first
-
- accept_list_item_start_ualpha
- end
-
- ##
- # Calls accept_list_item_end_bullet
-
- def test_accept_list_item_end_bullet
- @to.start_accepting
-
- @to.accept_list_start @bullet_list
-
- @to.accept_list_item_start @bullet_list.items.first
-
- @to.accept_list_item_end @bullet_list.items.first
-
- accept_list_item_end_bullet
- end
-
- ##
- # Calls accept_list_item_end_label
-
- def test_accept_list_item_end_label
- @to.start_accepting
-
- @to.accept_list_start @label_list
-
- @to.accept_list_item_start @label_list.items.first
-
- @to.accept_list_item_end @label_list.items.first
-
- accept_list_item_end_label
- end
-
- ##
- # Calls accept_list_item_end_lalpha
-
- def test_accept_list_item_end_lalpha
- @to.start_accepting
-
- @to.accept_list_start @lalpha_list
-
- @to.accept_list_item_start @lalpha_list.items.first
-
- @to.accept_list_item_end @lalpha_list.items.first
-
- accept_list_item_end_lalpha
- end
-
- ##
- # Calls accept_list_item_end_note
-
- def test_accept_list_item_end_note
- @to.start_accepting
-
- @to.accept_list_start @note_list
-
- @to.accept_list_item_start @note_list.items.first
-
- @to.accept_list_item_end @note_list.items.first
-
- accept_list_item_end_note
- end
-
- ##
- # Calls accept_list_item_end_number
-
- def test_accept_list_item_end_number
- @to.start_accepting
-
- @to.accept_list_start @number_list
-
- @to.accept_list_item_start @number_list.items.first
-
- @to.accept_list_item_end @number_list.items.first
-
- accept_list_item_end_number
- end
-
- ##
- # Calls accept_list_item_end_ualpha
-
- def test_accept_list_item_end_ualpha
- @to.start_accepting
-
- @to.accept_list_start @ualpha_list
-
- @to.accept_list_item_start @ualpha_list.items.first
-
- @to.accept_list_item_end @ualpha_list.items.first
-
- accept_list_item_end_ualpha
- end
-
- ##
- # Calls accept_list_start_bullet
-
- def test_accept_list_start_bullet
- @to.start_accepting
-
- @to.accept_list_start @bullet_list
-
- accept_list_start_bullet
- end
-
- ##
- # Calls accept_list_start_label
-
- def test_accept_list_start_label
- @to.start_accepting
-
- @to.accept_list_start @label_list
-
- accept_list_start_label
- end
-
- ##
- # Calls accept_list_start_lalpha
-
- def test_accept_list_start_lalpha
- @to.start_accepting
-
- @to.accept_list_start @lalpha_list
-
- accept_list_start_lalpha
- end
-
- ##
- # Calls accept_list_start_note
-
- def test_accept_list_start_note
- @to.start_accepting
-
- @to.accept_list_start @note_list
-
- accept_list_start_note
- end
-
- ##
- # Calls accept_list_start_number
-
- def test_accept_list_start_number
- @to.start_accepting
-
- @to.accept_list_start @number_list
-
- accept_list_start_number
- end
-
- ##
- # Calls accept_list_start_ualpha
-
- def test_accept_list_start_ualpha
- @to.start_accepting
-
- @to.accept_list_start @ualpha_list
-
- accept_list_start_ualpha
- end
-
- ##
- # Calls accept_list_end_bullet
-
- def test_accept_list_end_bullet
- @to.start_accepting
-
- @to.accept_list_start @bullet_list
-
- @to.accept_list_end @bullet_list
-
- accept_list_end_bullet
- end
-
- ##
- # Calls accept_list_end_label
-
- def test_accept_list_end_label
- @to.start_accepting
-
- @to.accept_list_start @label_list
-
- @to.accept_list_end @label_list
-
- accept_list_end_label
- end
-
- ##
- # Calls accept_list_end_lalpha
-
- def test_accept_list_end_lalpha
- @to.start_accepting
-
- @to.accept_list_start @lalpha_list
-
- @to.accept_list_end @lalpha_list
-
- accept_list_end_lalpha
- end
-
- ##
- # Calls accept_list_end_number
-
- def test_accept_list_end_number
- @to.start_accepting
-
- @to.accept_list_start @number_list
-
- @to.accept_list_end @number_list
-
- accept_list_end_number
- end
-
- ##
- # Calls accept_list_end_note
-
- def test_accept_list_end_note
- @to.start_accepting
-
- @to.accept_list_start @note_list
-
- @to.accept_list_end @note_list
-
- accept_list_end_note
- end
-
- ##
- # Calls accept_list_end_ualpha
-
- def test_accept_list_end_ualpha
- @to.start_accepting
-
- @to.accept_list_start @ualpha_list
-
- @to.accept_list_end @ualpha_list
-
- accept_list_end_ualpha
- end
-
- ##
- # Calls list_nested with a two-level list
-
- def test_list_nested
- doc = @RM::Document.new(
- @RM::List.new(:BULLET,
- @RM::ListItem.new(nil,
- @RM::Paragraph.new('l1'),
- @RM::List.new(:BULLET,
- @RM::ListItem.new(nil,
- @RM::Paragraph.new('l1.1')))),
- @RM::ListItem.new(nil,
- @RM::Paragraph.new('l2'))))
-
- doc.accept @to
-
- list_nested
- end
-
- ##
- # Calls list_verbatim with a list containing a verbatim block
-
- def test_list_verbatim # HACK overblown
- doc =
- doc(
- list(:BULLET,
- item(nil,
- para('list stuff'),
- blank_line,
- verb("* list\n",
- " with\n",
- "\n",
- " second\n",
- "\n",
- " 1. indented\n",
- " 2. numbered\n",
- "\n",
- " third\n",
- "\n",
- "* second\n"))))
-
- doc.accept @to
-
- list_verbatim
- end
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/hard_break.rb b/ruby_2_2/lib/rdoc/markup/hard_break.rb
deleted file mode 100644
index 8445ad26e7..0000000000
--- a/ruby_2_2/lib/rdoc/markup/hard_break.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-##
-# A hard-break in the middle of a paragraph.
-
-class RDoc::Markup::HardBreak
-
- @instance = new
-
- ##
- # RDoc::Markup::HardBreak is a singleton
-
- def self.new
- @instance
- end
-
- ##
- # Calls #accept_hard_break on +visitor+
-
- def accept visitor
- visitor.accept_hard_break self
- end
-
- def == other # :nodoc:
- self.class === other
- end
-
- def pretty_print q # :nodoc:
- q.text "[break]"
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/heading.rb b/ruby_2_2/lib/rdoc/markup/heading.rb
deleted file mode 100644
index 535e310e54..0000000000
--- a/ruby_2_2/lib/rdoc/markup/heading.rb
+++ /dev/null
@@ -1,78 +0,0 @@
-##
-# A heading with a level (1-6) and text
-
-RDoc::Markup::Heading =
- Struct.new :level, :text do
-
- @to_html = nil
- @to_label = nil
-
- ##
- # A singleton RDoc::Markup::ToLabel formatter for headings.
-
- def self.to_label
- @to_label ||= RDoc::Markup::ToLabel.new
- end
-
- ##
- # A singleton plain HTML formatter for headings. Used for creating labels
- # for the Table of Contents
-
- def self.to_html
- return @to_html if @to_html
-
- markup = RDoc::Markup.new
- markup.add_special RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
-
- @to_html = RDoc::Markup::ToHtml.new nil
-
- def @to_html.handle_special_CROSSREF special
- special.text.sub(/^\\/, '')
- end
-
- @to_html
- end
-
- ##
- # Calls #accept_heading on +visitor+
-
- def accept visitor
- visitor.accept_heading self
- end
-
- ##
- # An HTML-safe anchor reference for this header.
-
- def aref
- "label-#{self.class.to_label.convert text.dup}"
- end
-
- ##
- # Creates a fully-qualified label which will include the label from
- # +context+. This helps keep ids unique in HTML.
-
- def label context = nil
- label = aref
-
- label = [context.aref, label].compact.join '-' if
- context and context.respond_to? :aref
-
- label
- end
-
- ##
- # HTML markup of the text of this label without the surrounding header
- # element.
-
- def plain_html
- self.class.to_html.to_html(text.dup)
- end
-
- def pretty_print q # :nodoc:
- q.group 2, "[head: #{level} ", ']' do
- q.pp text
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/include.rb b/ruby_2_2/lib/rdoc/markup/include.rb
deleted file mode 100644
index a2e8903279..0000000000
--- a/ruby_2_2/lib/rdoc/markup/include.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-##
-# A file included at generation time. Objects of this class are created by
-# RDoc::RD for an extension-less include.
-#
-# This implementation in incomplete.
-
-class RDoc::Markup::Include
-
- ##
- # The filename to be included, without extension
-
- attr_reader :file
-
- ##
- # Directories to search for #file
-
- attr_reader :include_path
-
- ##
- # Creates a new include that will import +file+ from +include_path+
-
- def initialize file, include_path
- @file = file
- @include_path = include_path
- end
-
- def == other # :nodoc:
- self.class === other and
- @file == other.file and @include_path == other.include_path
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[incl ', ']' do
- q.text file
- q.breakable
- q.text 'from '
- q.pp include_path
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/indented_paragraph.rb b/ruby_2_2/lib/rdoc/markup/indented_paragraph.rb
deleted file mode 100644
index 1b8a8c725d..0000000000
--- a/ruby_2_2/lib/rdoc/markup/indented_paragraph.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-##
-# An Indented Paragraph of text
-
-class RDoc::Markup::IndentedParagraph < RDoc::Markup::Raw
-
- ##
- # The indent in number of spaces
-
- attr_reader :indent
-
- ##
- # Creates a new IndentedParagraph containing +parts+ indented with +indent+
- # spaces
-
- def initialize indent, *parts
- @indent = indent
-
- super(*parts)
- end
-
- def == other # :nodoc:
- super and indent == other.indent
- end
-
- ##
- # Calls #accept_indented_paragraph on +visitor+
-
- def accept visitor
- visitor.accept_indented_paragraph self
- end
-
- ##
- # Joins the raw paragraph text and converts inline HardBreaks to the
- # +hard_break+ text followed by the indent.
-
- def text hard_break = nil
- @parts.map do |part|
- if RDoc::Markup::HardBreak === part then
- '%1$s%3$*2$s' % [hard_break, @indent, ' '] if hard_break
- else
- part
- end
- end.join
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/inline.rb b/ruby_2_2/lib/rdoc/markup/inline.rb
deleted file mode 100644
index fb3ab5c74d..0000000000
--- a/ruby_2_2/lib/rdoc/markup/inline.rb
+++ /dev/null
@@ -1 +0,0 @@
-warn "requiring rdoc/markup/inline is deprecated and will be removed in RDoc 4." if $-w
diff --git a/ruby_2_2/lib/rdoc/markup/list.rb b/ruby_2_2/lib/rdoc/markup/list.rb
deleted file mode 100644
index 89b7fc20fa..0000000000
--- a/ruby_2_2/lib/rdoc/markup/list.rb
+++ /dev/null
@@ -1,101 +0,0 @@
-##
-# A List is a homogeneous set of ListItems.
-#
-# The supported list types include:
-#
-# :BULLET::
-# An unordered list
-# :LABEL::
-# An unordered definition list, but using an alternate RDoc::Markup syntax
-# :LALPHA::
-# An ordered list using increasing lowercase English letters
-# :NOTE::
-# An unordered definition list
-# :NUMBER::
-# An ordered list using increasing Arabic numerals
-# :UALPHA::
-# An ordered list using increasing uppercase English letters
-#
-# Definition lists behave like HTML definition lists. Each list item can
-# describe multiple terms. See RDoc::Markup::ListItem for how labels and
-# definition are stored as list items.
-
-class RDoc::Markup::List
-
- ##
- # The list's type
-
- attr_accessor :type
-
- ##
- # Items in the list
-
- attr_reader :items
-
- ##
- # Creates a new list of +type+ with +items+. Valid list types are:
- # +:BULLET+, +:LABEL+, +:LALPHA+, +:NOTE+, +:NUMBER+, +:UALPHA+
-
- def initialize type = nil, *items
- @type = type
- @items = []
- @items.concat items
- end
-
- ##
- # Appends +item+ to the list
-
- def << item
- @items << item
- end
-
- def == other # :nodoc:
- self.class == other.class and
- @type == other.type and
- @items == other.items
- end
-
- ##
- # Runs this list and all its #items through +visitor+
-
- def accept visitor
- visitor.accept_list_start self
-
- @items.each do |item|
- item.accept visitor
- end
-
- visitor.accept_list_end self
- end
-
- ##
- # Is the list empty?
-
- def empty?
- @items.empty?
- end
-
- ##
- # Returns the last item in the list
-
- def last
- @items.last
- end
-
- def pretty_print q # :nodoc:
- q.group 2, "[list: #{@type} ", ']' do
- q.seplist @items do |item|
- q.pp item
- end
- end
- end
-
- ##
- # Appends +items+ to the list
-
- def push *items
- @items.concat items
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/list_item.rb b/ruby_2_2/lib/rdoc/markup/list_item.rb
deleted file mode 100644
index c5e59fe167..0000000000
--- a/ruby_2_2/lib/rdoc/markup/list_item.rb
+++ /dev/null
@@ -1,99 +0,0 @@
-##
-# An item within a List that contains paragraphs, headings, etc.
-#
-# For BULLET, NUMBER, LALPHA and UALPHA lists, the label will always be nil.
-# For NOTE and LABEL lists, the list label may contain:
-#
-# * a single String for a single label
-# * an Array of Strings for a list item with multiple terms
-# * nil for an extra description attached to a previously labeled list item
-
-class RDoc::Markup::ListItem
-
- ##
- # The label for the ListItem
-
- attr_accessor :label
-
- ##
- # Parts of the ListItem
-
- attr_reader :parts
-
- ##
- # Creates a new ListItem with an optional +label+ containing +parts+
-
- def initialize label = nil, *parts
- @label = label
- @parts = []
- @parts.concat parts
- end
-
- ##
- # Appends +part+ to the ListItem
-
- def << part
- @parts << part
- end
-
- def == other # :nodoc:
- self.class == other.class and
- @label == other.label and
- @parts == other.parts
- end
-
- ##
- # Runs this list item and all its #parts through +visitor+
-
- def accept visitor
- visitor.accept_list_item_start self
-
- @parts.each do |part|
- part.accept visitor
- end
-
- visitor.accept_list_item_end self
- end
-
- ##
- # Is the ListItem empty?
-
- def empty?
- @parts.empty?
- end
-
- ##
- # Length of parts in the ListItem
-
- def length
- @parts.length
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[item: ', ']' do
- case @label
- when Array then
- q.pp @label
- q.text ';'
- q.breakable
- when String then
- q.pp @label
- q.text ';'
- q.breakable
- end
-
- q.seplist @parts do |part|
- q.pp part
- end
- end
- end
-
- ##
- # Adds +parts+ to the ListItem
-
- def push *parts
- @parts.concat parts
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/paragraph.rb b/ruby_2_2/lib/rdoc/markup/paragraph.rb
deleted file mode 100644
index 7180729f75..0000000000
--- a/ruby_2_2/lib/rdoc/markup/paragraph.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-##
-# A Paragraph of text
-
-class RDoc::Markup::Paragraph < RDoc::Markup::Raw
-
- ##
- # Calls #accept_paragraph on +visitor+
-
- def accept visitor
- visitor.accept_paragraph self
- end
-
- ##
- # Joins the raw paragraph text and converts inline HardBreaks to the
- # +hard_break+ text.
-
- def text hard_break = ''
- @parts.map do |part|
- if RDoc::Markup::HardBreak === part then
- hard_break
- else
- part
- end
- end.join
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/parser.rb b/ruby_2_2/lib/rdoc/markup/parser.rb
deleted file mode 100644
index cc828a4513..0000000000
--- a/ruby_2_2/lib/rdoc/markup/parser.rb
+++ /dev/null
@@ -1,558 +0,0 @@
-require 'strscan'
-
-##
-# A recursive-descent parser for RDoc markup.
-#
-# The parser tokenizes an input string then parses the tokens into a Document.
-# Documents can be converted into output formats by writing a visitor like
-# RDoc::Markup::ToHTML.
-#
-# The parser only handles the block-level constructs Paragraph, List,
-# ListItem, Heading, Verbatim, BlankLine and Rule. Inline markup such as
-# <tt>\+blah\+</tt> is handled separately by RDoc::Markup::AttributeManager.
-#
-# To see what markup the Parser implements read RDoc. To see how to use
-# RDoc markup to format text in your program read RDoc::Markup.
-
-class RDoc::Markup::Parser
-
- include RDoc::Text
-
- ##
- # List token types
-
- LIST_TOKENS = [
- :BULLET,
- :LABEL,
- :LALPHA,
- :NOTE,
- :NUMBER,
- :UALPHA,
- ]
-
- ##
- # Parser error subclass
-
- class Error < RuntimeError; end
-
- ##
- # Raised when the parser is unable to handle the given markup
-
- class ParseError < Error; end
-
- ##
- # Enables display of debugging information
-
- attr_accessor :debug
-
- ##
- # Token accessor
-
- attr_reader :tokens
-
- ##
- # Parses +str+ into a Document.
- #
- # Use RDoc::Markup#parse instead of this method.
-
- def self.parse str
- parser = new
- parser.tokenize str
- doc = RDoc::Markup::Document.new
- parser.parse doc
- end
-
- ##
- # Returns a token stream for +str+, for testing
-
- def self.tokenize str
- parser = new
- parser.tokenize str
- parser.tokens
- end
-
- ##
- # Creates a new Parser. See also ::parse
-
- def initialize
- @binary_input = nil
- @current_token = nil
- @debug = false
- @have_encoding = Object.const_defined? :Encoding
- @have_byteslice = ''.respond_to? :byteslice
- @input = nil
- @input_encoding = nil
- @line = 0
- @line_pos = 0
- @s = nil
- @tokens = []
- end
-
- ##
- # Builds a Heading of +level+
-
- def build_heading level
- type, text, = get
-
- text = case type
- when :TEXT then
- skip :NEWLINE
- text
- else
- unget
- ''
- end
-
- RDoc::Markup::Heading.new level, text
- end
-
- ##
- # Builds a List flush to +margin+
-
- def build_list margin
- p :list_start => margin if @debug
-
- list = RDoc::Markup::List.new
- label = nil
-
- until @tokens.empty? do
- type, data, column, = get
-
- case type
- when *LIST_TOKENS then
- if column < margin || (list.type && list.type != type) then
- unget
- break
- end
-
- list.type = type
- peek_type, _, column, = peek_token
-
- case type
- when :NOTE, :LABEL then
- label = [] unless label
-
- if peek_type == :NEWLINE then
- # description not on the same line as LABEL/NOTE
- # skip the trailing newline & any blank lines below
- while peek_type == :NEWLINE
- get
- peek_type, _, column, = peek_token
- end
-
- # we may be:
- # - at end of stream
- # - at a column < margin:
- # [text]
- # blah blah blah
- # - at the same column, but with a different type of list item
- # [text]
- # * blah blah
- # - at the same column, with the same type of list item
- # [one]
- # [two]
- # In all cases, we have an empty description.
- # In the last case only, we continue.
- if peek_type.nil? || column < margin then
- empty = true
- elsif column == margin then
- case peek_type
- when type
- empty = :continue
- when *LIST_TOKENS
- empty = true
- else
- empty = false
- end
- else
- empty = false
- end
-
- if empty then
- label << data
- next if empty == :continue
- break
- end
- end
- else
- data = nil
- end
-
- if label then
- data = label << data
- label = nil
- end
-
- list_item = RDoc::Markup::ListItem.new data
- parse list_item, column
- list << list_item
-
- else
- unget
- break
- end
- end
-
- p :list_end => margin if @debug
-
- if list.empty? then
- return nil unless label
- return nil unless [:LABEL, :NOTE].include? list.type
-
- list_item = RDoc::Markup::ListItem.new label, RDoc::Markup::BlankLine.new
- list << list_item
- end
-
- list
- end
-
- ##
- # Builds a Paragraph that is flush to +margin+
-
- def build_paragraph margin
- p :paragraph_start => margin if @debug
-
- paragraph = RDoc::Markup::Paragraph.new
-
- until @tokens.empty? do
- type, data, column, = get
-
- if type == :TEXT and column == margin then
- paragraph << data
-
- break if peek_token.first == :BREAK
-
- data << ' ' if skip :NEWLINE
- else
- unget
- break
- end
- end
-
- paragraph.parts.last.sub!(/ \z/, '') # cleanup
-
- p :paragraph_end => margin if @debug
-
- paragraph
- end
-
- ##
- # Builds a Verbatim that is indented from +margin+.
- #
- # The verbatim block is shifted left (the least indented lines start in
- # column 0). Each part of the verbatim is one line of text, always
- # terminated by a newline. Blank lines always consist of a single newline
- # character, and there is never a single newline at the end of the verbatim.
-
- def build_verbatim margin
- p :verbatim_begin => margin if @debug
- verbatim = RDoc::Markup::Verbatim.new
-
- min_indent = nil
- generate_leading_spaces = true
- line = ''
-
- until @tokens.empty? do
- type, data, column, = get
-
- if type == :NEWLINE then
- line << data
- verbatim << line
- line = ''
- generate_leading_spaces = true
- next
- end
-
- if column <= margin
- unget
- break
- end
-
- if generate_leading_spaces then
- indent = column - margin
- line << ' ' * indent
- min_indent = indent if min_indent.nil? || indent < min_indent
- generate_leading_spaces = false
- end
-
- case type
- when :HEADER then
- line << '=' * data
- _, _, peek_column, = peek_token
- peek_column ||= column + data
- indent = peek_column - column - data
- line << ' ' * indent
- when :RULE then
- width = 2 + data
- line << '-' * width
- _, _, peek_column, = peek_token
- peek_column ||= column + width
- indent = peek_column - column - width
- line << ' ' * indent
- when :BREAK, :TEXT then
- line << data
- else # *LIST_TOKENS
- list_marker = case type
- when :BULLET then data
- when :LABEL then "[#{data}]"
- when :NOTE then "#{data}::"
- else # :LALPHA, :NUMBER, :UALPHA
- "#{data}."
- end
- line << list_marker
- peek_type, _, peek_column = peek_token
- unless peek_type == :NEWLINE then
- peek_column ||= column + list_marker.length
- indent = peek_column - column - list_marker.length
- line << ' ' * indent
- end
- end
-
- end
-
- verbatim << line << "\n" unless line.empty?
- verbatim.parts.each { |p| p.slice!(0, min_indent) unless p == "\n" } if min_indent > 0
- verbatim.normalize
-
- p :verbatim_end => margin if @debug
-
- verbatim
- end
-
- ##
- # The character offset for the input string at the given +byte_offset+
-
- def char_pos byte_offset
- if @have_byteslice then
- @input.byteslice(0, byte_offset).length
- elsif @have_encoding then
- matched = @binary_input[0, byte_offset]
- matched.force_encoding @input_encoding
- matched.length
- else
- byte_offset
- end
- end
-
- ##
- # Pulls the next token from the stream.
-
- def get
- @current_token = @tokens.shift
- p :get => @current_token if @debug
- @current_token
- end
-
- ##
- # Parses the tokens into an array of RDoc::Markup::XXX objects,
- # and appends them to the passed +parent+ RDoc::Markup::YYY object.
- #
- # Exits at the end of the token stream, or when it encounters a token
- # in a column less than +indent+ (unless it is a NEWLINE).
- #
- # Returns +parent+.
-
- def parse parent, indent = 0
- p :parse_start => indent if @debug
-
- until @tokens.empty? do
- type, data, column, = get
-
- case type
- when :BREAK then
- parent << RDoc::Markup::BlankLine.new
- skip :NEWLINE, false
- next
- when :NEWLINE then
- # trailing newlines are skipped below, so this is a blank line
- parent << RDoc::Markup::BlankLine.new
- skip :NEWLINE, false
- next
- end
-
- # indentation change: break or verbatim
- if column < indent then
- unget
- break
- elsif column > indent then
- unget
- parent << build_verbatim(indent)
- next
- end
-
- # indentation is the same
- case type
- when :HEADER then
- parent << build_heading(data)
- when :RULE then
- parent << RDoc::Markup::Rule.new(data)
- skip :NEWLINE
- when :TEXT then
- unget
- parse_text parent, indent
- when *LIST_TOKENS then
- unget
- parent << build_list(indent)
- else
- type, data, column, line = @current_token
- raise ParseError, "Unhandled token #{type} (#{data.inspect}) at #{line}:#{column}"
- end
- end
-
- p :parse_end => indent if @debug
-
- parent
-
- end
-
- ##
- # Small hook that is overridden by RDoc::TomDoc
-
- def parse_text parent, indent # :nodoc:
- parent << build_paragraph(indent)
- end
-
- ##
- # Returns the next token on the stream without modifying the stream
-
- def peek_token
- token = @tokens.first || []
- p :peek => token if @debug
- token
- end
-
- ##
- # Creates the StringScanner
-
- def setup_scanner input
- @line = 0
- @line_pos = 0
- @input = input.dup
-
- if @have_encoding and not @have_byteslice then
- @input_encoding = @input.encoding
- @binary_input = @input.force_encoding Encoding::BINARY
- end
-
- @s = StringScanner.new input
- end
-
- ##
- # Skips the next token if its type is +token_type+.
- #
- # Optionally raises an error if the next token is not of the expected type.
-
- def skip token_type, error = true
- type, = get
- return unless type # end of stream
- return @current_token if token_type == type
- unget
- raise ParseError, "expected #{token_type} got #{@current_token.inspect}" if error
- end
-
- ##
- # Turns text +input+ into a stream of tokens
-
- def tokenize input
- setup_scanner input
-
- until @s.eos? do
- pos = @s.pos
-
- # leading spaces will be reflected by the column of the next token
- # the only thing we loose are trailing spaces at the end of the file
- next if @s.scan(/ +/)
-
- # note: after BULLET, LABEL, etc.,
- # indent will be the column of the next non-newline token
-
- @tokens << case
- # [CR]LF => :NEWLINE
- when @s.scan(/\r?\n/) then
- token = [:NEWLINE, @s.matched, *token_pos(pos)]
- @line_pos = char_pos @s.pos
- @line += 1
- token
- # === text => :HEADER then :TEXT
- when @s.scan(/(=+)(\s*)/) then
- level = @s[1].length
- header = [:HEADER, level, *token_pos(pos)]
-
- if @s[2] =~ /^\r?\n/ then
- @s.pos -= @s[2].length
- header
- else
- pos = @s.pos
- @s.scan(/.*/)
- @tokens << header
- [:TEXT, @s.matched.sub(/\r$/, ''), *token_pos(pos)]
- end
- # --- (at least 3) and nothing else on the line => :RULE
- when @s.scan(/(-{3,}) *\r?$/) then
- [:RULE, @s[1].length - 2, *token_pos(pos)]
- # * or - followed by white space and text => :BULLET
- when @s.scan(/([*-]) +(\S)/) then
- @s.pos -= @s[2].bytesize # unget \S
- [:BULLET, @s[1], *token_pos(pos)]
- # A. text, a. text, 12. text => :UALPHA, :LALPHA, :NUMBER
- when @s.scan(/([a-z]|\d+)\. +(\S)/i) then
- # FIXME if tab(s), the column will be wrong
- # either support tabs everywhere by first expanding them to
- # spaces, or assume that they will have been replaced
- # before (and provide a check for that at least in debug
- # mode)
- list_label = @s[1]
- @s.pos -= @s[2].bytesize # unget \S
- list_type =
- case list_label
- when /[a-z]/ then :LALPHA
- when /[A-Z]/ then :UALPHA
- when /\d/ then :NUMBER
- else
- raise ParseError, "BUG token #{list_label}"
- end
- [list_type, list_label, *token_pos(pos)]
- # [text] followed by spaces or end of line => :LABEL
- when @s.scan(/\[(.*?)\]( +|\r?$)/) then
- [:LABEL, @s[1], *token_pos(pos)]
- # text:: followed by spaces or end of line => :NOTE
- when @s.scan(/(.*?)::( +|\r?$)/) then
- [:NOTE, @s[1], *token_pos(pos)]
- # anything else: :TEXT
- else @s.scan(/(.*?)( )?\r?$/)
- token = [:TEXT, @s[1], *token_pos(pos)]
-
- if @s[2] then
- @tokens << token
- [:BREAK, @s[2], *token_pos(pos + @s[1].length)]
- else
- token
- end
- end
- end
-
- self
- end
-
- ##
- # Calculates the column (by character) and line of the current token based
- # on +byte_offset+.
-
- def token_pos byte_offset
- offset = char_pos byte_offset
-
- [offset - @line_pos, @line]
- end
-
- ##
- # Returns the current token to the token stream
-
- def unget
- token = @current_token
- p :unget => token if @debug
- raise Error, 'too many #ungets' if token == @tokens.first
- @tokens.unshift token if token
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/pre_process.rb b/ruby_2_2/lib/rdoc/markup/pre_process.rb
deleted file mode 100644
index 01fb293462..0000000000
--- a/ruby_2_2/lib/rdoc/markup/pre_process.rb
+++ /dev/null
@@ -1,293 +0,0 @@
-##
-# Handle common directives that can occur in a block of text:
-#
-# \:include: filename
-#
-# Directives can be escaped by preceding them with a backslash.
-#
-# RDoc plugin authors can register additional directives to be handled by
-# using RDoc::Markup::PreProcess::register.
-#
-# Any directive that is not built-in to RDoc (including those registered via
-# plugins) will be stored in the metadata hash on the CodeObject the comment
-# is attached to. See RDoc::Markup@Directives for the list of built-in
-# directives.
-
-class RDoc::Markup::PreProcess
-
- ##
- # An RDoc::Options instance that will be filled in with overrides from
- # directives
-
- attr_accessor :options
-
- ##
- # Adds a post-process handler for directives. The handler will be called
- # with the result RDoc::Comment (or text String) and the code object for the
- # comment (if any).
-
- def self.post_process &block
- @post_processors << block
- end
-
- ##
- # Registered post-processors
-
- def self.post_processors
- @post_processors
- end
-
- ##
- # Registers +directive+ as one handled by RDoc. If a block is given the
- # directive will be replaced by the result of the block, otherwise the
- # directive will be removed from the processed text.
- #
- # The block will be called with the directive name and the directive
- # parameter:
- #
- # RDoc::Markup::PreProcess.register 'my-directive' do |directive, param|
- # # replace text, etc.
- # end
-
- def self.register directive, &block
- @registered[directive] = block
- end
-
- ##
- # Registered directives
-
- def self.registered
- @registered
- end
-
- ##
- # Clears all registered directives and post-processors
-
- def self.reset
- @post_processors = []
- @registered = {}
- end
-
- reset
-
- ##
- # Creates a new pre-processor for +input_file_name+ that will look for
- # included files in +include_path+
-
- def initialize(input_file_name, include_path)
- @input_file_name = input_file_name
- @include_path = include_path
- @options = nil
- end
-
- ##
- # Look for directives in the given +text+.
- #
- # Options that we don't handle are yielded. If the block returns false the
- # directive is restored to the text. If the block returns nil or no block
- # was given the directive is handled according to the registered directives.
- # If a String was returned the directive is replaced with the string.
- #
- # If no matching directive was registered the directive is restored to the
- # text.
- #
- # If +code_object+ is given and the directive is unknown then the
- # directive's parameter is set as metadata on the +code_object+. See
- # RDoc::CodeObject#metadata for details.
-
- def handle text, code_object = nil, &block
- if RDoc::Comment === text then
- comment = text
- text = text.text
- end
-
- encoding = text.encoding if defined?(Encoding)
-
- # regexp helper (square brackets for optional)
- # $1 $2 $3 $4 $5
- # [prefix][\]:directive:[spaces][param]newline
- text.gsub!(/^([ \t]*(?:#|\/?\*)?[ \t]*)(\\?):(\w+):([ \t]*)(.+)?(\r?\n|$)/) do
- # skip something like ':toto::'
- next $& if $4.empty? and $5 and $5[0, 1] == ':'
-
- # skip if escaped
- next "#$1:#$3:#$4#$5\n" unless $2.empty?
-
- # This is not in handle_directive because I didn't want to pass another
- # argument into it
- if comment and $3 == 'markup' then
- next "#{$1.strip}\n" unless $5
- comment.format = $5.downcase
- next "#{$1.strip}\n"
- end
-
- handle_directive $1, $3, $5, code_object, encoding, &block
- end
-
- comment = text unless comment
-
- self.class.post_processors.each do |handler|
- handler.call comment, code_object
- end
-
- text
- end
-
- ##
- # Performs the actions described by +directive+ and its parameter +param+.
- #
- # +code_object+ is used for directives that operate on a class or module.
- # +prefix+ is used to ensure the replacement for handled directives is
- # correct. +encoding+ is used for the <tt>include</tt> directive.
- #
- # For a list of directives in RDoc see RDoc::Markup.
- #--
- # When 1.8.7 support is ditched prefix can be defaulted to ''
-
- def handle_directive prefix, directive, param, code_object = nil,
- encoding = nil
- blankline = "#{prefix.strip}\n"
- directive = directive.downcase
-
- case directive
- when 'arg', 'args' then
- return "#{prefix}:#{directive}: #{param}\n" unless code_object
-
- code_object.params = param
-
- blankline
- when 'category' then
- if RDoc::Context === code_object then
- section = code_object.add_section param
- code_object.temporary_section = section
- end
-
- blankline # ignore category if we're not on an RDoc::Context
- when 'doc' then
- return blankline unless code_object
- code_object.document_self = true
- code_object.force_documentation = true
-
- blankline
- when 'enddoc' then
- return blankline unless code_object
- code_object.done_documenting = true
-
- blankline
- when 'include' then
- filename = param.split.first
- include_file filename, prefix, encoding
- when 'main' then
- @options.main_page = param if @options.respond_to? :main_page
-
- blankline
- when 'nodoc' then
- return blankline unless code_object
- code_object.document_self = nil # notify nodoc
- code_object.document_children = param !~ /all/i
-
- blankline
- when 'notnew', 'not_new', 'not-new' then
- return blankline unless RDoc::AnyMethod === code_object
-
- code_object.dont_rename_initialize = true
-
- blankline
- when 'startdoc' then
- return blankline unless code_object
-
- code_object.start_doc
- code_object.force_documentation = true
-
- blankline
- when 'stopdoc' then
- return blankline unless code_object
-
- code_object.stop_doc
-
- blankline
- when 'title' then
- @options.default_title = param if @options.respond_to? :default_title=
-
- blankline
- when 'yield', 'yields' then
- return blankline unless code_object
- # remove parameter &block
- code_object.params.sub!(/,?\s*&\w+/, '') if code_object.params
-
- code_object.block_params = param
-
- blankline
- else
- result = yield directive, param if block_given?
-
- case result
- when nil then
- code_object.metadata[directive] = param if code_object
-
- if RDoc::Markup::PreProcess.registered.include? directive then
- handler = RDoc::Markup::PreProcess.registered[directive]
- result = handler.call directive, param if handler
- else
- result = "#{prefix}:#{directive}: #{param}\n"
- end
- when false then
- result = "#{prefix}:#{directive}: #{param}\n"
- end
-
- result
- end
- end
-
- ##
- # Handles the <tt>:include: _filename_</tt> directive.
- #
- # If the first line of the included file starts with '#', and contains
- # an encoding information in the form 'coding:' or 'coding=', it is
- # removed.
- #
- # If all lines in the included file start with a '#', this leading '#'
- # is removed before inclusion. The included content is indented like
- # the <tt>:include:</tt> directive.
- #--
- # so all content will be verbatim because of the likely space after '#'?
- # TODO shift left the whole file content in that case
- # TODO comment stop/start #-- and #++ in included file must be processed here
-
- def include_file name, indent, encoding
- full_name = find_include_file name
-
- unless full_name then
- warn "Couldn't find file to include '#{name}' from #{@input_file_name}"
- return ''
- end
-
- content = RDoc::Encoding.read_file full_name, encoding, true
-
- # strip magic comment
- content = content.sub(/\A# .*coding[=:].*$/, '').lstrip
-
- # strip leading '#'s, but only if all lines start with them
- if content =~ /^[^#]/ then
- content.gsub(/^/, indent)
- else
- content.gsub(/^#?/, indent)
- end
- end
-
- ##
- # Look for the given file in the directory containing the current file,
- # and then in each of the directories specified in the RDOC_INCLUDE path
-
- def find_include_file(name)
- to_search = [File.dirname(@input_file_name)].concat @include_path
- to_search.each do |dir|
- full_name = File.join(dir, name)
- stat = File.stat(full_name) rescue next
- return full_name if stat.readable?
- end
- nil
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/raw.rb b/ruby_2_2/lib/rdoc/markup/raw.rb
deleted file mode 100644
index e11e8efff4..0000000000
--- a/ruby_2_2/lib/rdoc/markup/raw.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-##
-# A section of text that is added to the output document as-is
-
-class RDoc::Markup::Raw
-
- ##
- # The component parts of the list
-
- attr_reader :parts
-
- ##
- # Creates a new Raw containing +parts+
-
- def initialize *parts
- @parts = []
- @parts.concat parts
- end
-
- ##
- # Appends +text+
-
- def << text
- @parts << text
- end
-
- def == other # :nodoc:
- self.class == other.class and @parts == other.parts
- end
-
- ##
- # Calls #accept_raw+ on +visitor+
-
- def accept visitor
- visitor.accept_raw self
- end
-
- ##
- # Appends +other+'s parts
-
- def merge other
- @parts.concat other.parts
- end
-
- def pretty_print q # :nodoc:
- self.class.name =~ /.*::(\w{1,4})/i
-
- q.group 2, "[#{$1.downcase}: ", ']' do
- q.seplist @parts do |part|
- q.pp part
- end
- end
- end
-
- ##
- # Appends +texts+ onto this Paragraph
-
- def push *texts
- self.parts.concat texts
- end
-
- ##
- # The raw text
-
- def text
- @parts.join ' '
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/rule.rb b/ruby_2_2/lib/rdoc/markup/rule.rb
deleted file mode 100644
index b778f2bc09..0000000000
--- a/ruby_2_2/lib/rdoc/markup/rule.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-##
-# A horizontal rule with a weight
-
-class RDoc::Markup::Rule < Struct.new :weight
-
- ##
- # Calls #accept_rule on +visitor+
-
- def accept visitor
- visitor.accept_rule self
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[rule:', ']' do
- q.pp weight
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/special.rb b/ruby_2_2/lib/rdoc/markup/special.rb
deleted file mode 100644
index 1c0fc03eea..0000000000
--- a/ruby_2_2/lib/rdoc/markup/special.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-##
-# Hold details of a special sequence
-
-class RDoc::Markup::Special
-
- ##
- # Special type
-
- attr_reader :type
-
- ##
- # Special text
-
- attr_accessor :text
-
- ##
- # Creates a new special sequence of +type+ with +text+
-
- def initialize(type, text)
- @type, @text = type, text
- end
-
- ##
- # Specials are equal when the have the same text and type
-
- def ==(o)
- self.text == o.text && self.type == o.type
- end
-
- def inspect # :nodoc:
- "#<RDoc::Markup::Special:0x%x @type=%p, @text=%p>" % [
- object_id, @type, text.dump]
- end
-
- def to_s # :nodoc:
- "Special: type=#{type} text=#{text.dump}"
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/text_formatter_test_case.rb b/ruby_2_2/lib/rdoc/markup/text_formatter_test_case.rb
deleted file mode 100644
index 4abf42563b..0000000000
--- a/ruby_2_2/lib/rdoc/markup/text_formatter_test_case.rb
+++ /dev/null
@@ -1,114 +0,0 @@
-##
-# Test case for creating new plain-text RDoc::Markup formatters. See also
-# RDoc::Markup::FormatterTestCase
-#
-# See test_rdoc_markup_to_rdoc.rb for a complete example.
-#
-# Example:
-#
-# class TestRDocMarkupToNewTextFormat < RDoc::Markup::TextFormatterTestCase
-#
-# add_visitor_tests
-# add_text_tests
-#
-# def setup
-# super
-#
-# @to = RDoc::Markup::ToNewTextFormat.new
-# end
-#
-# def accept_blank_line
-# assert_equal :junk, @to.res.join
-# end
-#
-# # ...
-#
-# end
-
-class RDoc::Markup::TextFormatterTestCase < RDoc::Markup::FormatterTestCase
-
- ##
- # Adds test cases to the calling TestCase.
-
- def self.add_text_tests
- self.class_eval do
-
- ##
- # Test case that calls <tt>@to.accept_heading</tt>
-
- def test_accept_heading_indent
- @to.start_accepting
- @to.indent = 3
- @to.accept_heading @RM::Heading.new(1, 'Hello')
-
- accept_heading_indent
- end
-
- ##
- # Test case that calls <tt>@to.accept_rule</tt>
-
- def test_accept_rule_indent
- @to.start_accepting
- @to.indent = 3
- @to.accept_rule @RM::Rule.new(1)
-
- accept_rule_indent
- end
-
- ##
- # Test case that calls <tt>@to.accept_verbatim</tt>
-
- def test_accept_verbatim_indent
- @to.start_accepting
- @to.indent = 2
- @to.accept_verbatim @RM::Verbatim.new("hi\n", " world\n")
-
- accept_verbatim_indent
- end
-
- ##
- # Test case that calls <tt>@to.accept_verbatim</tt> with a big indent
-
- def test_accept_verbatim_big_indent
- @to.start_accepting
- @to.indent = 2
- @to.accept_verbatim @RM::Verbatim.new("hi\n", "world\n")
-
- accept_verbatim_big_indent
- end
-
- ##
- # Test case that calls <tt>@to.accept_paragraph</tt> with an indent
-
- def test_accept_paragraph_indent
- @to.start_accepting
- @to.indent = 3
- @to.accept_paragraph @RM::Paragraph.new(('words ' * 30).strip)
-
- accept_paragraph_indent
- end
-
- ##
- # Test case that calls <tt>@to.accept_paragraph</tt> with a long line
-
- def test_accept_paragraph_wrap
- @to.start_accepting
- @to.accept_paragraph @RM::Paragraph.new(('words ' * 30).strip)
-
- accept_paragraph_wrap
- end
-
- ##
- # Test case that calls <tt>@to.attributes</tt> with an escaped
- # cross-reference. If this test doesn't pass something may be very
- # wrong.
-
- def test_attributes
- assert_equal 'Dog', @to.attributes("\\Dog")
- end
-
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/to_ansi.rb b/ruby_2_2/lib/rdoc/markup/to_ansi.rb
deleted file mode 100644
index 4d439ce88d..0000000000
--- a/ruby_2_2/lib/rdoc/markup/to_ansi.rb
+++ /dev/null
@@ -1,93 +0,0 @@
-##
-# Outputs RDoc markup with vibrant ANSI color!
-
-class RDoc::Markup::ToAnsi < RDoc::Markup::ToRdoc
-
- ##
- # Creates a new ToAnsi visitor that is ready to output vibrant ANSI color!
-
- def initialize markup = nil
- super
-
- @headings.clear
- @headings[1] = ["\e[1;32m", "\e[m"] # bold
- @headings[2] = ["\e[4;32m", "\e[m"] # underline
- @headings[3] = ["\e[32m", "\e[m"] # just green
- end
-
- ##
- # Maps attributes to ANSI sequences
-
- def init_tags
- add_tag :BOLD, "\e[1m", "\e[m"
- add_tag :TT, "\e[7m", "\e[m"
- add_tag :EM, "\e[4m", "\e[m"
- end
-
- ##
- # Overrides indent width to ensure output lines up correctly.
-
- def accept_list_item_end list_item
- width = case @list_type.last
- when :BULLET then
- 2
- when :NOTE, :LABEL then
- if @prefix then
- @res << @prefix.strip
- @prefix = nil
- end
-
- @res << "\n" unless res.length == 1
- 2
- else
- bullet = @list_index.last.to_s
- @list_index[-1] = @list_index.last.succ
- bullet.length + 2
- end
-
- @indent -= width
- end
-
- ##
- # Adds coloring to note and label list items
-
- def accept_list_item_start list_item
- bullet = case @list_type.last
- when :BULLET then
- '*'
- when :NOTE, :LABEL then
- labels = Array(list_item.label).map do |label|
- attributes(label).strip
- end.join "\n"
-
- labels << ":\n" unless labels.empty?
-
- labels
- else
- @list_index.last.to_s + '.'
- end
-
- case @list_type.last
- when :NOTE, :LABEL then
- @indent += 2
- @prefix = bullet + (' ' * @indent)
- else
- @prefix = (' ' * @indent) + bullet.ljust(bullet.length + 1)
-
- width = bullet.gsub(/\e\[[\d;]*m/, '').length + 1
-
- @indent += width
- end
- end
-
- ##
- # Starts accepting with a reset screen
-
- def start_accepting
- super
-
- @res = ["\e[0m"]
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/to_bs.rb b/ruby_2_2/lib/rdoc/markup/to_bs.rb
deleted file mode 100644
index 10c31854d2..0000000000
--- a/ruby_2_2/lib/rdoc/markup/to_bs.rb
+++ /dev/null
@@ -1,78 +0,0 @@
-##
-# Outputs RDoc markup with hot backspace action! You will probably need a
-# pager to use this output format.
-#
-# This formatter won't work on 1.8.6 because it lacks String#chars.
-
-class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc
-
- ##
- # Returns a new ToBs that is ready for hot backspace action!
-
- def initialize markup = nil
- super
-
- @in_b = false
- @in_em = false
- end
-
- ##
- # Sets a flag that is picked up by #annotate to do the right thing in
- # #convert_string
-
- def init_tags
- add_tag :BOLD, '+b', '-b'
- add_tag :EM, '+_', '-_'
- add_tag :TT, '' , '' # we need in_tt information maintained
- end
-
- ##
- # Makes heading text bold.
-
- def accept_heading heading
- use_prefix or @res << ' ' * @indent
- @res << @headings[heading.level][0]
- @in_b = true
- @res << attributes(heading.text)
- @in_b = false
- @res << @headings[heading.level][1]
- @res << "\n"
- end
-
- ##
- # Turns on or off special handling for +convert_string+
-
- def annotate tag
- case tag
- when '+b' then @in_b = true
- when '-b' then @in_b = false
- when '+_' then @in_em = true
- when '-_' then @in_em = false
- end
- ''
- end
-
- ##
- # Calls convert_string on the result of convert_special
-
- def convert_special special
- convert_string super
- end
-
- ##
- # Adds bold or underline mixed with backspaces
-
- def convert_string string
- return string unless string.respond_to? :chars # your ruby is lame
- return string unless @in_b or @in_em
- chars = if @in_b then
- string.chars.map do |char| "#{char}\b#{char}" end
- elsif @in_em then
- string.chars.map do |char| "_\b#{char}" end
- end
-
- chars.join
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/to_html.rb b/ruby_2_2/lib/rdoc/markup/to_html.rb
deleted file mode 100644
index 2b1216ef2a..0000000000
--- a/ruby_2_2/lib/rdoc/markup/to_html.rb
+++ /dev/null
@@ -1,398 +0,0 @@
-require 'cgi'
-
-##
-# Outputs RDoc markup as HTML.
-
-class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
-
- include RDoc::Text
-
- # :section: Utilities
-
- ##
- # Maps RDoc::Markup::Parser::LIST_TOKENS types to HTML tags
-
- LIST_TYPE_TO_HTML = {
- :BULLET => ['<ul>', '</ul>'],
- :LABEL => ['<dl class="rdoc-list label-list">', '</dl>'],
- :LALPHA => ['<ol style="list-style-type: lower-alpha">', '</ol>'],
- :NOTE => ['<dl class="rdoc-list note-list">', '</dl>'],
- :NUMBER => ['<ol>', '</ol>'],
- :UALPHA => ['<ol style="list-style-type: upper-alpha">', '</ol>'],
- }
-
- attr_reader :res # :nodoc:
- attr_reader :in_list_entry # :nodoc:
- attr_reader :list # :nodoc:
-
- ##
- # The RDoc::CodeObject HTML is being generated for. This is used to
- # generate namespaced URI fragments
-
- attr_accessor :code_object
-
- ##
- # Path to this document for relative links
-
- attr_accessor :from_path
-
- # :section:
-
- ##
- # Creates a new formatter that will output HTML
-
- def initialize options, markup = nil
- super
-
- @code_object = nil
- @from_path = ''
- @in_list_entry = nil
- @list = nil
- @th = nil
- @hard_break = "<br>\n"
-
- # external links
- @markup.add_special(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)\S+\w/,
- :HYPERLINK)
-
- add_special_RDOCLINK
- add_special_TIDYLINK
-
- init_tags
- end
-
- # :section: Special Handling
- #
- # These methods handle special markup added by RDoc::Markup#add_special.
-
- def handle_RDOCLINK url # :nodoc:
- case url
- when /^rdoc-ref:/
- $'
- when /^rdoc-label:/
- text = $'
-
- text = case text
- when /\Alabel-/ then $'
- when /\Afootmark-/ then $'
- when /\Afoottext-/ then $'
- else text
- end
-
- gen_url url, text
- when /^rdoc-image:/
- "<img src=\"#{$'}\">"
- else
- url =~ /\Ardoc-[a-z]+:/
-
- $'
- end
- end
-
- ##
- # +special+ is a <code><br></code>
-
- def handle_special_HARD_BREAK special
- '<br>'
- end
-
- ##
- # +special+ is a potential link. The following schemes are handled:
- #
- # <tt>mailto:</tt>::
- # Inserted as-is.
- # <tt>http:</tt>::
- # Links are checked to see if they reference an image. If so, that image
- # gets inserted using an <tt><img></tt> tag. Otherwise a conventional
- # <tt><a href></tt> is used.
- # <tt>link:</tt>::
- # Reference to a local file relative to the output directory.
-
- def handle_special_HYPERLINK(special)
- url = special.text
-
- gen_url url, url
- end
-
- ##
- # +special+ is an rdoc-schemed link that will be converted into a hyperlink.
- #
- # For the +rdoc-ref+ scheme the named reference will be returned without
- # creating a link.
- #
- # For the +rdoc-label+ scheme the footnote and label prefixes are stripped
- # when creating a link. All other contents will be linked verbatim.
-
- def handle_special_RDOCLINK special
- handle_RDOCLINK special.text
- end
-
- ##
- # This +special+ is a link where the label is different from the URL
- # <tt>label[url]</tt> or <tt>{long label}[url]</tt>
-
- def handle_special_TIDYLINK(special)
- text = special.text
-
- return text unless
- text =~ /^\{(.*)\}\[(.*?)\]$/ or text =~ /^(\S+)\[(.*?)\]$/
-
- label = $1
- url = $2
-
- label = handle_RDOCLINK label if /^rdoc-image:/ =~ label
-
- gen_url url, label
- end
-
- # :section: Visitor
- #
- # These methods implement the HTML visitor.
-
- ##
- # Prepares the visitor for HTML generation
-
- def start_accepting
- @res = []
- @in_list_entry = []
- @list = []
- end
-
- ##
- # Returns the generated output
-
- def end_accepting
- @res.join
- end
-
- ##
- # Adds +block_quote+ to the output
-
- def accept_block_quote block_quote
- @res << "\n<blockquote>"
-
- block_quote.parts.each do |part|
- part.accept self
- end
-
- @res << "</blockquote>\n"
- end
-
- ##
- # Adds +paragraph+ to the output
-
- def accept_paragraph paragraph
- @res << "\n<p>"
- text = paragraph.text @hard_break
- text = text.gsub(/\r?\n/, ' ')
- @res << wrap(to_html(text))
- @res << "</p>\n"
- end
-
- ##
- # Adds +verbatim+ to the output
-
- def accept_verbatim verbatim
- text = verbatim.text.rstrip
-
- klass = nil
-
- content = if verbatim.ruby? or parseable? text then
- begin
- tokens = RDoc::RubyLex.tokenize text, @options
- klass = ' class="ruby"'
-
- RDoc::TokenStream.to_html tokens
- rescue RDoc::RubyLex::Error
- CGI.escapeHTML text
- end
- else
- CGI.escapeHTML text
- end
-
- if @options.pipe then
- @res << "\n<pre><code>#{CGI.escapeHTML text}</code></pre>\n"
- else
- @res << "\n<pre#{klass}>#{content}</pre>\n"
- end
- end
-
- ##
- # Adds +rule+ to the output
-
- def accept_rule rule
- @res << "<hr>\n"
- end
-
- ##
- # Prepares the visitor for consuming +list+
-
- def accept_list_start(list)
- @list << list.type
- @res << html_list_name(list.type, true)
- @in_list_entry.push false
- end
-
- ##
- # Finishes consumption of +list+
-
- def accept_list_end(list)
- @list.pop
- if tag = @in_list_entry.pop
- @res << tag
- end
- @res << html_list_name(list.type, false) << "\n"
- end
-
- ##
- # Prepares the visitor for consuming +list_item+
-
- def accept_list_item_start(list_item)
- if tag = @in_list_entry.last
- @res << tag
- end
-
- @res << list_item_start(list_item, @list.last)
- end
-
- ##
- # Finishes consumption of +list_item+
-
- def accept_list_item_end(list_item)
- @in_list_entry[-1] = list_end_for(@list.last)
- end
-
- ##
- # Adds +blank_line+ to the output
-
- def accept_blank_line(blank_line)
- # @res << annotate("<p />") << "\n"
- end
-
- ##
- # Adds +heading+ to the output. The headings greater than 6 are trimmed to
- # level 6.
-
- def accept_heading heading
- level = [6, heading.level].min
-
- label = heading.label @code_object
-
- @res << if @options.output_decoration
- "\n<h#{level} id=\"#{label}\">"
- else
- "\n<h#{level}>"
- end
- @res << to_html(heading.text)
- unless @options.pipe then
- @res << "<span><a href=\"##{label}\">&para;</a>"
- @res << " <a href=\"#top\">&uarr;</a></span>"
- end
- @res << "</h#{level}>\n"
- end
-
- ##
- # Adds +raw+ to the output
-
- def accept_raw raw
- @res << raw.parts.join("\n")
- end
-
- # :section: Utilities
-
- ##
- # CGI-escapes +text+
-
- def convert_string(text)
- CGI.escapeHTML text
- end
-
- ##
- # Generate a link to +url+ with content +text+. Handles the special cases
- # for img: and link: described under handle_special_HYPERLINK
-
- def gen_url url, text
- scheme, url, id = parse_url url
-
- if %w[http https link].include?(scheme) and
- url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
- "<img src=\"#{url}\" />"
- else
- text = text.sub %r%^#{scheme}:/*%i, ''
- text = text.sub %r%^[*\^](\d+)$%, '\1'
-
- link = "<a#{id} href=\"#{url}\">#{text}</a>"
-
- link = "<sup>#{link}</sup>" if /"foot/ =~ id
-
- link
- end
- end
-
- ##
- # Determines the HTML list element for +list_type+ and +open_tag+
-
- def html_list_name(list_type, open_tag)
- tags = LIST_TYPE_TO_HTML[list_type]
- raise RDoc::Error, "Invalid list type: #{list_type.inspect}" unless tags
- tags[open_tag ? 0 : 1]
- end
-
- ##
- # Maps attributes to HTML tags
-
- def init_tags
- add_tag :BOLD, "<strong>", "</strong>"
- add_tag :TT, "<code>", "</code>"
- add_tag :EM, "<em>", "</em>"
- end
-
- ##
- # Returns the HTML tag for +list_type+, possible using a label from
- # +list_item+
-
- def list_item_start(list_item, list_type)
- case list_type
- when :BULLET, :LALPHA, :NUMBER, :UALPHA then
- "<li>"
- when :LABEL, :NOTE then
- Array(list_item.label).map do |label|
- "<dt>#{to_html label}\n"
- end.join << "<dd>"
- else
- raise RDoc::Error, "Invalid list type: #{list_type.inspect}"
- end
- end
-
- ##
- # Returns the HTML end-tag for +list_type+
-
- def list_end_for(list_type)
- case list_type
- when :BULLET, :LALPHA, :NUMBER, :UALPHA then
- "</li>"
- when :LABEL, :NOTE then
- "</dd>"
- else
- raise RDoc::Error, "Invalid list type: #{list_type.inspect}"
- end
- end
-
- ##
- # Returns true if text is valid ruby syntax
-
- def parseable? text
- eval("BEGIN {return true}\n#{text}")
- rescue SyntaxError
- false
- end
-
- ##
- # Converts +item+ to HTML using RDoc::Text#to_html
-
- def to_html item
- super convert_flow @am.flow item
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/to_html_crossref.rb b/ruby_2_2/lib/rdoc/markup/to_html_crossref.rb
deleted file mode 100644
index d27e0ab627..0000000000
--- a/ruby_2_2/lib/rdoc/markup/to_html_crossref.rb
+++ /dev/null
@@ -1,160 +0,0 @@
-##
-# Subclass of the RDoc::Markup::ToHtml class that supports looking up method
-# names, classes, etc to create links. RDoc::CrossReference is used to
-# generate those links based on the current context.
-
-class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
-
- # :stopdoc:
- ALL_CROSSREF_REGEXP = RDoc::CrossReference::ALL_CROSSREF_REGEXP
- CLASS_REGEXP_STR = RDoc::CrossReference::CLASS_REGEXP_STR
- CROSSREF_REGEXP = RDoc::CrossReference::CROSSREF_REGEXP
- METHOD_REGEXP_STR = RDoc::CrossReference::METHOD_REGEXP_STR
- # :startdoc:
-
- ##
- # RDoc::CodeObject for generating references
-
- attr_accessor :context
-
- ##
- # Should we show '#' characters on method references?
-
- attr_accessor :show_hash
-
- ##
- # Creates a new crossref resolver that generates links relative to +context+
- # which lives at +from_path+ in the generated files. '#' characters on
- # references are removed unless +show_hash+ is true. Only method names
- # preceded by '#' or '::' are linked, unless +hyperlink_all+ is true.
-
- def initialize(options, from_path, context, markup = nil)
- raise ArgumentError, 'from_path cannot be nil' if from_path.nil?
-
- super options, markup
-
- @context = context
- @from_path = from_path
- @hyperlink_all = @options.hyperlink_all
- @show_hash = @options.show_hash
-
- crossref_re = @hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
- @markup.add_special crossref_re, :CROSSREF
-
- @cross_reference = RDoc::CrossReference.new @context
- end
-
- ##
- # Creates a link to the reference +name+ if the name exists. If +text+ is
- # given it is used as the link text, otherwise +name+ is used.
-
- def cross_reference name, text = nil
- lookup = name
-
- name = name[1..-1] unless @show_hash if name[0, 1] == '#'
-
- name = "#{CGI.unescape $'} at #{$1}" if name =~ /(.*[^#:])@/
-
- text = name unless text
-
- link lookup, text
- end
-
- ##
- # We're invoked when any text matches the CROSSREF pattern. If we find the
- # corresponding reference, generate a link. If the name we're looking for
- # contains no punctuation, we look for it up the module/class chain. For
- # example, ToHtml is found, even without the <tt>RDoc::Markup::</tt> prefix,
- # because we look for it in module Markup first.
-
- def handle_special_CROSSREF(special)
- name = special.text
-
- return name if name =~ /@[\w-]+\.[\w-]/ # labels that look like emails
-
- unless @hyperlink_all then
- # This ensures that words entirely consisting of lowercase letters will
- # not have cross-references generated (to suppress lots of erroneous
- # cross-references to "new" in text, for instance)
- return name if name =~ /\A[a-z]*\z/
- end
-
- cross_reference name
- end
-
- ##
- # Handles <tt>rdoc-ref:</tt> scheme links and allows RDoc::Markup::ToHtml to
- # handle other schemes.
-
- def handle_special_HYPERLINK special
- return cross_reference $' if special.text =~ /\Ardoc-ref:/
-
- super
- end
-
- ##
- # +special+ is an rdoc-schemed link that will be converted into a hyperlink.
- # For the rdoc-ref scheme the cross-reference will be looked up and the
- # given name will be used.
- #
- # All other contents are handled by
- # {the superclass}[rdoc-ref:RDoc::Markup::ToHtml#handle_special_RDOCLINK]
-
- def handle_special_RDOCLINK special
- url = special.text
-
- case url
- when /\Ardoc-ref:/ then
- cross_reference $'
- else
- super
- end
- end
-
- ##
- # Generates links for <tt>rdoc-ref:</tt> scheme URLs and allows
- # RDoc::Markup::ToHtml to handle other schemes.
-
- def gen_url url, text
- return super unless url =~ /\Ardoc-ref:/
-
- cross_reference $', text
- end
-
- ##
- # Creates an HTML link to +name+ with the given +text+.
-
- def link name, text
- original_name = name
-
- if name =~ /(.*[^#:])@/ then
- name = $1
- label = $'
- end
-
- ref = @cross_reference.resolve name, text
-
- text = ref.output_name @context if
- RDoc::MethodAttr === ref and text == original_name
-
- case ref
- when String then
- ref
- else
- path = ref.as_href @from_path
-
- if path =~ /#/ then
- path << "-label-#{label}"
- elsif ref.sections and
- ref.sections.any? { |section| label == section.title } then
- path << "##{label}"
- else
- path << "#label-#{label}"
- end if label
-
- "<a href=\"#{path}\">#{text}</a>"
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/to_html_snippet.rb b/ruby_2_2/lib/rdoc/markup/to_html_snippet.rb
deleted file mode 100644
index 4ad0a9a4b9..0000000000
--- a/ruby_2_2/lib/rdoc/markup/to_html_snippet.rb
+++ /dev/null
@@ -1,284 +0,0 @@
-##
-# Outputs RDoc markup as paragraphs with inline markup only.
-
-class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
-
- ##
- # After this many characters the input will be cut off.
-
- attr_reader :character_limit
-
- ##
- # The number of characters seen so far.
-
- attr_reader :characters # :nodoc:
-
- ##
- # The attribute bitmask
-
- attr_reader :mask
-
- ##
- # After this many paragraphs the input will be cut off.
-
- attr_reader :paragraph_limit
-
- ##
- # Count of paragraphs found
-
- attr_reader :paragraphs
-
- ##
- # Creates a new ToHtmlSnippet formatter that will cut off the input on the
- # next word boundary after the given number of +characters+ or +paragraphs+
- # of text have been encountered.
-
- def initialize options, characters = 100, paragraphs = 3, markup = nil
- super options, markup
-
- @character_limit = characters
- @paragraph_limit = paragraphs
-
- @characters = 0
- @mask = 0
- @paragraphs = 0
-
- @markup.add_special RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
- end
-
- ##
- # Adds +heading+ to the output as a paragraph
-
- def accept_heading heading
- @res << "<p>#{to_html heading.text}\n"
-
- add_paragraph
- end
-
- ##
- # Raw sections are untrusted and ignored
-
- alias accept_raw ignore
-
- ##
- # Rules are ignored
-
- alias accept_rule ignore
-
- def accept_paragraph paragraph
- para = @in_list_entry.last || "<p>"
-
- text = paragraph.text @hard_break
-
- @res << "#{para}#{wrap to_html text}\n"
-
- add_paragraph
- end
-
- ##
- # Finishes consumption of +list_item+
-
- def accept_list_item_end list_item
- end
-
- ##
- # Prepares the visitor for consuming +list_item+
-
- def accept_list_item_start list_item
- @res << list_item_start(list_item, @list.last)
- end
-
- ##
- # Prepares the visitor for consuming +list+
-
- def accept_list_start list
- @list << list.type
- @res << html_list_name(list.type, true)
- @in_list_entry.push ''
- end
-
- ##
- # Adds +verbatim+ to the output
-
- def accept_verbatim verbatim
- throw :done if @characters >= @character_limit
- input = verbatim.text.rstrip
-
- text = truncate input
- text << ' ...' unless text == input
-
- super RDoc::Markup::Verbatim.new text
-
- add_paragraph
- end
-
- ##
- # Prepares the visitor for HTML snippet generation
-
- def start_accepting
- super
-
- @characters = 0
- end
-
- ##
- # Removes escaping from the cross-references in +special+
-
- def handle_special_CROSSREF special
- special.text.sub(/\A\\/, '')
- end
-
- ##
- # +special+ is a <code><br></code>
-
- def handle_special_HARD_BREAK special
- @characters -= 4
- '<br>'
- end
-
- ##
- # Lists are paragraphs, but notes and labels have a separator
-
- def list_item_start list_item, list_type
- throw :done if @characters >= @character_limit
-
- case list_type
- when :BULLET, :LALPHA, :NUMBER, :UALPHA then
- "<p>"
- when :LABEL, :NOTE then
- labels = Array(list_item.label).map do |label|
- to_html label
- end.join ', '
-
- labels << " &mdash; " unless labels.empty?
-
- start = "<p>#{labels}"
- @characters += 1 # try to include the label
- start
- else
- raise RDoc::Error, "Invalid list type: #{list_type.inspect}"
- end
- end
-
- ##
- # Returns just the text of +link+, +url+ is only used to determine the link
- # type.
-
- def gen_url url, text
- if url =~ /^rdoc-label:([^:]*)(?::(.*))?/ then
- type = "link"
- elsif url =~ /([A-Za-z]+):(.*)/ then
- type = $1
- else
- type = "http"
- end
-
- if (type == "http" or type == "https" or type == "link") and
- url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
- ''
- else
- text.sub(%r%^#{type}:/*%, '')
- end
- end
-
- ##
- # In snippets, there are no lists
-
- def html_list_name list_type, open_tag
- ''
- end
-
- ##
- # Throws +:done+ when paragraph_limit paragraphs have been encountered
-
- def add_paragraph
- @paragraphs += 1
-
- throw :done if @paragraphs >= @paragraph_limit
- end
-
- ##
- # Marks up +content+
-
- def convert content
- catch :done do
- return super
- end
-
- end_accepting
- end
-
- ##
- # Converts flow items +flow+
-
- def convert_flow flow
- throw :done if @characters >= @character_limit
-
- res = []
- @mask = 0
-
- flow.each do |item|
- case item
- when RDoc::Markup::AttrChanger then
- off_tags res, item
- on_tags res, item
- when String then
- text = convert_string item
- res << truncate(text)
- when RDoc::Markup::Special then
- text = convert_special item
- res << truncate(text)
- else
- raise "Unknown flow element: #{item.inspect}"
- end
-
- if @characters >= @character_limit then
- off_tags res, RDoc::Markup::AttrChanger.new(0, @mask)
- break
- end
- end
-
- res << ' ...' if @characters >= @character_limit
-
- res.join
- end
-
- ##
- # Maintains a bitmask to allow HTML elements to be closed properly. See
- # RDoc::Markup::Formatter.
-
- def on_tags res, item
- @mask ^= item.turn_on
-
- super
- end
-
- ##
- # Maintains a bitmask to allow HTML elements to be closed properly. See
- # RDoc::Markup::Formatter.
-
- def off_tags res, item
- @mask ^= item.turn_off
-
- super
- end
-
- ##
- # Truncates +text+ at the end of the first word after the character_limit.
-
- def truncate text
- length = text.length
- characters = @characters
- @characters += length
-
- return text if @characters < @character_limit
-
- remaining = @character_limit - characters
-
- text =~ /\A(.{#{remaining},}?)(\s|$)/m # TODO word-break instead of \s?
-
- $1
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/to_joined_paragraph.rb b/ruby_2_2/lib/rdoc/markup/to_joined_paragraph.rb
deleted file mode 100644
index 835841071d..0000000000
--- a/ruby_2_2/lib/rdoc/markup/to_joined_paragraph.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-##
-# Joins the parts of an RDoc::Markup::Paragraph into a single String.
-#
-# This allows for easier maintenance and testing of Markdown support.
-#
-# This formatter only works on Paragraph instances. Attempting to process
-# other markup syntax items will not work.
-
-class RDoc::Markup::ToJoinedParagraph < RDoc::Markup::Formatter
-
- def initialize # :nodoc:
- super nil
- end
-
- def start_accepting # :nodoc:
- end
-
- def end_accepting # :nodoc:
- end
-
- ##
- # Converts the parts of +paragraph+ to a single entry.
-
- def accept_paragraph paragraph
- parts = []
- string = false
-
- paragraph.parts.each do |part|
- if String === part then
- if string then
- string << part
- else
- parts << part
- string = part
- end
- else
- parts << part
- string = false
- end
- end
-
- parts = parts.map do |part|
- if String === part then
- part.rstrip
- else
- part
- end
- end
-
- # TODO use Enumerable#chunk when Ruby 1.8 support is dropped
- #parts = paragraph.parts.chunk do |part|
- # String === part
- #end.map do |string, chunk|
- # string ? chunk.join.rstrip : chunk
- #end.flatten
-
- paragraph.parts.replace parts
- end
-
- alias accept_block_quote ignore
- alias accept_heading ignore
- alias accept_list_end ignore
- alias accept_list_item_end ignore
- alias accept_list_item_start ignore
- alias accept_list_start ignore
- alias accept_raw ignore
- alias accept_rule ignore
- alias accept_verbatim ignore
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/to_label.rb b/ruby_2_2/lib/rdoc/markup/to_label.rb
deleted file mode 100644
index 6fbe4a3dbd..0000000000
--- a/ruby_2_2/lib/rdoc/markup/to_label.rb
+++ /dev/null
@@ -1,74 +0,0 @@
-require 'cgi'
-
-##
-# Creates HTML-safe labels suitable for use in id attributes. Tidylinks are
-# converted to their link part and cross-reference links have the suppression
-# marks removed (\\SomeClass is converted to SomeClass).
-
-class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
-
- attr_reader :res # :nodoc:
-
- ##
- # Creates a new formatter that will output HTML-safe labels
-
- def initialize markup = nil
- super nil, markup
-
- @markup.add_special RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
- @markup.add_special(/(((\{.*?\})|\b\S+?)\[\S+?\])/, :TIDYLINK)
-
- add_tag :BOLD, '', ''
- add_tag :TT, '', ''
- add_tag :EM, '', ''
-
- @res = []
- end
-
- ##
- # Converts +text+ to an HTML-safe label
-
- def convert text
- label = convert_flow @am.flow text
-
- CGI.escape(label).gsub('%', '-').sub(/^-/, '')
- end
-
- ##
- # Converts the CROSSREF +special+ to plain text, removing the suppression
- # marker, if any
-
- def handle_special_CROSSREF special
- text = special.text
-
- text.sub(/^\\/, '')
- end
-
- ##
- # Converts the TIDYLINK +special+ to just the text part
-
- def handle_special_TIDYLINK special
- text = special.text
-
- return text unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/
-
- $1
- end
-
- alias accept_blank_line ignore
- alias accept_block_quote ignore
- alias accept_heading ignore
- alias accept_list_end ignore
- alias accept_list_item_end ignore
- alias accept_list_item_start ignore
- alias accept_list_start ignore
- alias accept_paragraph ignore
- alias accept_raw ignore
- alias accept_rule ignore
- alias accept_verbatim ignore
- alias end_accepting ignore
- alias handle_special_HARD_BREAK ignore
- alias start_accepting ignore
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/to_markdown.rb b/ruby_2_2/lib/rdoc/markup/to_markdown.rb
deleted file mode 100644
index d4b15bf41b..0000000000
--- a/ruby_2_2/lib/rdoc/markup/to_markdown.rb
+++ /dev/null
@@ -1,191 +0,0 @@
-# :markup: markdown
-
-##
-# Outputs parsed markup as Markdown
-
-class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
-
- ##
- # Creates a new formatter that will output Markdown format text
-
- def initialize markup = nil
- super
-
- @headings[1] = ['# ', '']
- @headings[2] = ['## ', '']
- @headings[3] = ['### ', '']
- @headings[4] = ['#### ', '']
- @headings[5] = ['##### ', '']
- @headings[6] = ['###### ', '']
-
- add_special_RDOCLINK
- add_special_TIDYLINK
-
- @hard_break = " \n"
- end
-
- ##
- # Maps attributes to HTML sequences
-
- def init_tags
- add_tag :BOLD, '**', '**'
- add_tag :EM, '*', '*'
- add_tag :TT, '`', '`'
- end
-
- ##
- # Adds a newline to the output
-
- def handle_special_HARD_BREAK special
- " \n"
- end
-
- ##
- # Finishes consumption of `list`
-
- def accept_list_end list
- @res << "\n"
-
- super
- end
-
- ##
- # Finishes consumption of `list_item`
-
- def accept_list_item_end list_item
- width = case @list_type.last
- when :BULLET then
- 4
- when :NOTE, :LABEL then
- use_prefix
-
- 4
- else
- @list_index[-1] = @list_index.last.succ
- 4
- end
-
- @indent -= width
- end
-
- ##
- # Prepares the visitor for consuming `list_item`
-
- def accept_list_item_start list_item
- type = @list_type.last
-
- case type
- when :NOTE, :LABEL then
- bullets = Array(list_item.label).map do |label|
- attributes(label).strip
- end.join "\n"
-
- bullets << "\n:"
-
- @prefix = ' ' * @indent
- @indent += 4
- @prefix << bullets + (' ' * (@indent - 1))
- else
- bullet = type == :BULLET ? '*' : @list_index.last.to_s + '.'
- @prefix = (' ' * @indent) + bullet.ljust(4)
-
- @indent += 4
- end
- end
-
- ##
- # Prepares the visitor for consuming `list`
-
- def accept_list_start list
- case list.type
- when :BULLET, :LABEL, :NOTE then
- @list_index << nil
- when :LALPHA, :NUMBER, :UALPHA then
- @list_index << 1
- else
- raise RDoc::Error, "invalid list type #{list.type}"
- end
-
- @list_width << 4
- @list_type << list.type
- end
-
- ##
- # Adds `rule` to the output
-
- def accept_rule rule
- use_prefix or @res << ' ' * @indent
- @res << '-' * 3
- @res << "\n"
- end
-
- ##
- # Outputs `verbatim` indented 4 columns
-
- def accept_verbatim verbatim
- indent = ' ' * (@indent + 4)
-
- verbatim.parts.each do |part|
- @res << indent unless part == "\n"
- @res << part
- end
-
- @res << "\n" unless @res =~ /\n\z/
- end
-
- ##
- # Creates a Markdown-style URL from +url+ with +text+.
-
- def gen_url url, text
- scheme, url, = parse_url url
-
- "[#{text.sub(%r{^#{scheme}:/*}i, '')}](#{url})"
- end
-
- ##
- # Handles <tt>rdoc-</tt> type links for footnotes.
-
- def handle_rdoc_link url
- case url
- when /^rdoc-ref:/ then
- $'
- when /^rdoc-label:footmark-(\d+)/ then
- "[^#{$1}]:"
- when /^rdoc-label:foottext-(\d+)/ then
- "[^#{$1}]"
- when /^rdoc-label:label-/ then
- gen_url url, $'
- when /^rdoc-image:/ then
- "![](#{$'})"
- when /^rdoc-[a-z]+:/ then
- $'
- end
- end
-
- ##
- # Converts the RDoc markup tidylink into a Markdown.style link.
-
- def handle_special_TIDYLINK special
- text = special.text
-
- return text unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/
-
- label = $1
- url = $2
-
- if url =~ /^rdoc-label:foot/ then
- handle_rdoc_link url
- else
- gen_url url, label
- end
- end
-
- ##
- # Converts the rdoc-...: links into a Markdown.style links.
-
- def handle_special_RDOCLINK special
- handle_rdoc_link special.text
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/to_rdoc.rb b/ruby_2_2/lib/rdoc/markup/to_rdoc.rb
deleted file mode 100644
index f16b4ed5a3..0000000000
--- a/ruby_2_2/lib/rdoc/markup/to_rdoc.rb
+++ /dev/null
@@ -1,333 +0,0 @@
-##
-# Outputs RDoc markup as RDoc markup! (mostly)
-
-class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
-
- ##
- # Current indent amount for output in characters
-
- attr_accessor :indent
-
- ##
- # Output width in characters
-
- attr_accessor :width
-
- ##
- # Stack of current list indexes for alphabetic and numeric lists
-
- attr_reader :list_index
-
- ##
- # Stack of list types
-
- attr_reader :list_type
-
- ##
- # Stack of list widths for indentation
-
- attr_reader :list_width
-
- ##
- # Prefix for the next list item. See #use_prefix
-
- attr_reader :prefix
-
- ##
- # Output accumulator
-
- attr_reader :res
-
- ##
- # Creates a new formatter that will output (mostly) \RDoc markup
-
- def initialize markup = nil
- super nil, markup
-
- @markup.add_special(/\\\S/, :SUPPRESSED_CROSSREF)
- @width = 78
- init_tags
-
- @headings = {}
- @headings.default = []
-
- @headings[1] = ['= ', '']
- @headings[2] = ['== ', '']
- @headings[3] = ['=== ', '']
- @headings[4] = ['==== ', '']
- @headings[5] = ['===== ', '']
- @headings[6] = ['====== ', '']
-
- @hard_break = "\n"
- end
-
- ##
- # Maps attributes to HTML sequences
-
- def init_tags
- add_tag :BOLD, "<b>", "</b>"
- add_tag :TT, "<tt>", "</tt>"
- add_tag :EM, "<em>", "</em>"
- end
-
- ##
- # Adds +blank_line+ to the output
-
- def accept_blank_line blank_line
- @res << "\n"
- end
-
- ##
- # Adds +paragraph+ to the output
-
- def accept_block_quote block_quote
- @indent += 2
-
- block_quote.parts.each do |part|
- @prefix = '> '
-
- part.accept self
- end
-
- @indent -= 2
- end
-
- ##
- # Adds +heading+ to the output
-
- def accept_heading heading
- use_prefix or @res << ' ' * @indent
- @res << @headings[heading.level][0]
- @res << attributes(heading.text)
- @res << @headings[heading.level][1]
- @res << "\n"
- end
-
- ##
- # Finishes consumption of +list+
-
- def accept_list_end list
- @list_index.pop
- @list_type.pop
- @list_width.pop
- end
-
- ##
- # Finishes consumption of +list_item+
-
- def accept_list_item_end list_item
- width = case @list_type.last
- when :BULLET then
- 2
- when :NOTE, :LABEL then
- if @prefix then
- @res << @prefix.strip
- @prefix = nil
- end
-
- @res << "\n"
- 2
- else
- bullet = @list_index.last.to_s
- @list_index[-1] = @list_index.last.succ
- bullet.length + 2
- end
-
- @indent -= width
- end
-
- ##
- # Prepares the visitor for consuming +list_item+
-
- def accept_list_item_start list_item
- type = @list_type.last
-
- case type
- when :NOTE, :LABEL then
- bullets = Array(list_item.label).map do |label|
- attributes(label).strip
- end.join "\n"
-
- bullets << ":\n" unless bullets.empty?
-
- @prefix = ' ' * @indent
- @indent += 2
- @prefix << bullets + (' ' * @indent)
- else
- bullet = type == :BULLET ? '*' : @list_index.last.to_s + '.'
- @prefix = (' ' * @indent) + bullet.ljust(bullet.length + 1)
- width = bullet.length + 1
- @indent += width
- end
- end
-
- ##
- # Prepares the visitor for consuming +list+
-
- def accept_list_start list
- case list.type
- when :BULLET then
- @list_index << nil
- @list_width << 1
- when :LABEL, :NOTE then
- @list_index << nil
- @list_width << 2
- when :LALPHA then
- @list_index << 'a'
- @list_width << list.items.length.to_s.length
- when :NUMBER then
- @list_index << 1
- @list_width << list.items.length.to_s.length
- when :UALPHA then
- @list_index << 'A'
- @list_width << list.items.length.to_s.length
- else
- raise RDoc::Error, "invalid list type #{list.type}"
- end
-
- @list_type << list.type
- end
-
- ##
- # Adds +paragraph+ to the output
-
- def accept_paragraph paragraph
- text = paragraph.text @hard_break
- wrap attributes text
- end
-
- ##
- # Adds +paragraph+ to the output
-
- def accept_indented_paragraph paragraph
- @indent += paragraph.indent
- text = paragraph.text @hard_break
- wrap attributes text
- @indent -= paragraph.indent
- end
-
- ##
- # Adds +raw+ to the output
-
- def accept_raw raw
- @res << raw.parts.join("\n")
- end
-
- ##
- # Adds +rule+ to the output
-
- def accept_rule rule
- use_prefix or @res << ' ' * @indent
- @res << '-' * (@width - @indent)
- @res << "\n"
- end
-
- ##
- # Outputs +verbatim+ indented 2 columns
-
- def accept_verbatim verbatim
- indent = ' ' * (@indent + 2)
-
- verbatim.parts.each do |part|
- @res << indent unless part == "\n"
- @res << part
- end
-
- @res << "\n" unless @res =~ /\n\z/
- end
-
- ##
- # Applies attribute-specific markup to +text+ using RDoc::AttributeManager
-
- def attributes text
- flow = @am.flow text.dup
- convert_flow flow
- end
-
- ##
- # Returns the generated output
-
- def end_accepting
- @res.join
- end
-
- ##
- # Removes preceding \\ from the suppressed crossref +special+
-
- def handle_special_SUPPRESSED_CROSSREF special
- text = special.text
- text = text.sub('\\', '') unless in_tt?
- text
- end
-
- ##
- # Adds a newline to the output
-
- def handle_special_HARD_BREAK special
- "\n"
- end
-
- ##
- # Prepares the visitor for text generation
-
- def start_accepting
- @res = [""]
- @indent = 0
- @prefix = nil
-
- @list_index = []
- @list_type = []
- @list_width = []
- end
-
- ##
- # Adds the stored #prefix to the output and clears it. Lists generate a
- # prefix for later consumption.
-
- def use_prefix
- prefix, @prefix = @prefix, nil
- @res << prefix if prefix
-
- prefix
- end
-
- ##
- # Wraps +text+ to #width
-
- def wrap text
- return unless text && !text.empty?
-
- text_len = @width - @indent
-
- text_len = 20 if text_len < 20
-
- re = /^(.{0,#{text_len}})[ \n]/
- next_prefix = ' ' * @indent
-
- prefix = @prefix || next_prefix
- @prefix = nil
-
- @res << prefix
-
- while text.length > text_len
- if text =~ re then
- @res << $1
- text.slice!(0, $&.length)
- else
- @res << text.slice!(0, text_len)
- end
-
- @res << "\n" << next_prefix
- end
-
- if text.empty? then
- @res.pop
- @res.pop
- else
- @res << text
- @res << "\n"
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/to_table_of_contents.rb b/ruby_2_2/lib/rdoc/markup/to_table_of_contents.rb
deleted file mode 100644
index 2e0f98cfeb..0000000000
--- a/ruby_2_2/lib/rdoc/markup/to_table_of_contents.rb
+++ /dev/null
@@ -1,87 +0,0 @@
-##
-# Extracts just the RDoc::Markup::Heading elements from a
-# RDoc::Markup::Document to help build a table of contents
-
-class RDoc::Markup::ToTableOfContents < RDoc::Markup::Formatter
-
- @to_toc = nil
-
- ##
- # Singleton for table-of-contents generation
-
- def self.to_toc
- @to_toc ||= new
- end
-
- ##
- # Output accumulator
-
- attr_reader :res
-
- ##
- # Omits headings with a level less than the given level.
-
- attr_accessor :omit_headings_below
-
- def initialize # :nodoc:
- super nil
-
- @omit_headings_below = nil
- end
-
- ##
- # Adds +document+ to the output, using its heading cutoff if present
-
- def accept_document document
- @omit_headings_below = document.omit_headings_below
-
- super
- end
-
- ##
- # Adds +heading+ to the table of contents
-
- def accept_heading heading
- @res << heading unless suppressed? heading
- end
-
- ##
- # Returns the table of contents
-
- def end_accepting
- @res
- end
-
- ##
- # Prepares the visitor for text generation
-
- def start_accepting
- @omit_headings_below = nil
- @res = []
- end
-
- ##
- # Returns true if +heading+ is below the display threshold
-
- def suppressed? heading
- return false unless @omit_headings_below
-
- heading.level > @omit_headings_below
- end
-
- # :stopdoc:
- alias accept_block_quote ignore
- alias accept_raw ignore
- alias accept_rule ignore
- alias accept_blank_line ignore
- alias accept_paragraph ignore
- alias accept_verbatim ignore
- alias accept_list_end ignore
- alias accept_list_item_start ignore
- alias accept_list_item_end ignore
- alias accept_list_end_bullet ignore
- alias accept_list_start ignore
- # :startdoc:
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/to_test.rb b/ruby_2_2/lib/rdoc/markup/to_test.rb
deleted file mode 100644
index c51f64b917..0000000000
--- a/ruby_2_2/lib/rdoc/markup/to_test.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-##
-# This Markup outputter is used for testing purposes.
-
-class RDoc::Markup::ToTest < RDoc::Markup::Formatter
-
- # :stopdoc:
-
- ##
- # :section: Visitor
-
- def start_accepting
- @res = []
- @list = []
- end
-
- def end_accepting
- @res
- end
-
- def accept_paragraph(paragraph)
- @res << convert_flow(@am.flow(paragraph.text))
- end
-
- def accept_raw raw
- @res << raw.parts.join
- end
-
- def accept_verbatim(verbatim)
- @res << verbatim.text.gsub(/^(\S)/, ' \1')
- end
-
- def accept_list_start(list)
- @list << case list.type
- when :BULLET then
- '*'
- when :NUMBER then
- '1'
- else
- list.type
- end
- end
-
- def accept_list_end(list)
- @list.pop
- end
-
- def accept_list_item_start(list_item)
- @res << "#{' ' * (@list.size - 1)}#{@list.last}: "
- end
-
- def accept_list_item_end(list_item)
- end
-
- def accept_blank_line(blank_line)
- @res << "\n"
- end
-
- def accept_heading(heading)
- @res << "#{'=' * heading.level} #{heading.text}"
- end
-
- def accept_rule(rule)
- @res << '-' * rule.weight
- end
-
- # :startdoc:
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/to_tt_only.rb b/ruby_2_2/lib/rdoc/markup/to_tt_only.rb
deleted file mode 100644
index e2da20c6f3..0000000000
--- a/ruby_2_2/lib/rdoc/markup/to_tt_only.rb
+++ /dev/null
@@ -1,120 +0,0 @@
-##
-# Extracts sections of text enclosed in plus, tt or code. Used to discover
-# undocumented parameters.
-
-class RDoc::Markup::ToTtOnly < RDoc::Markup::Formatter
-
- ##
- # Stack of list types
-
- attr_reader :list_type
-
- ##
- # Output accumulator
-
- attr_reader :res
-
- ##
- # Creates a new tt-only formatter.
-
- def initialize markup = nil
- super nil, markup
-
- add_tag :TT, nil, nil
- end
-
- ##
- # Adds tts from +block_quote+ to the output
-
- def accept_block_quote block_quote
- tt_sections block_quote.text
- end
-
- ##
- # Pops the list type for +list+ from #list_type
-
- def accept_list_end list
- @list_type.pop
- end
-
- ##
- # Pushes the list type for +list+ onto #list_type
-
- def accept_list_start list
- @list_type << list.type
- end
-
- ##
- # Prepares the visitor for consuming +list_item+
-
- def accept_list_item_start list_item
- case @list_type.last
- when :NOTE, :LABEL then
- Array(list_item.label).map do |label|
- tt_sections label
- end.flatten
- end
- end
-
- ##
- # Adds +paragraph+ to the output
-
- def accept_paragraph paragraph
- tt_sections(paragraph.text)
- end
-
- ##
- # Does nothing to +markup_item+ because it doesn't have any user-built
- # content
-
- def do_nothing markup_item
- end
-
- alias accept_blank_line do_nothing # :nodoc:
- alias accept_heading do_nothing # :nodoc:
- alias accept_list_item_end do_nothing # :nodoc:
- alias accept_raw do_nothing # :nodoc:
- alias accept_rule do_nothing # :nodoc:
- alias accept_verbatim do_nothing # :nodoc:
-
- ##
- # Extracts tt sections from +text+
-
- def tt_sections text
- flow = @am.flow text.dup
-
- flow.each do |item|
- case item
- when String then
- @res << item if in_tt?
- when RDoc::Markup::AttrChanger then
- off_tags res, item
- on_tags res, item
- when RDoc::Markup::Special then
- @res << convert_special(item) if in_tt? # TODO can this happen?
- else
- raise "Unknown flow element: #{item.inspect}"
- end
- end
-
- res
- end
-
- ##
- # Returns an Array of items that were wrapped in plus, tt or code.
-
- def end_accepting
- @res.compact
- end
-
- ##
- # Prepares the visitor for gathering tt sections
-
- def start_accepting
- @res = []
-
- @list_type = []
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/markup/verbatim.rb b/ruby_2_2/lib/rdoc/markup/verbatim.rb
deleted file mode 100644
index 0ddde675e3..0000000000
--- a/ruby_2_2/lib/rdoc/markup/verbatim.rb
+++ /dev/null
@@ -1,83 +0,0 @@
-##
-# A section of verbatim text
-
-class RDoc::Markup::Verbatim < RDoc::Markup::Raw
-
- ##
- # Format of this verbatim section
-
- attr_accessor :format
-
- def initialize *parts # :nodoc:
- super
-
- @format = nil
- end
-
- def == other # :nodoc:
- super and @format == other.format
- end
-
- ##
- # Calls #accept_verbatim on +visitor+
-
- def accept visitor
- visitor.accept_verbatim self
- end
-
- ##
- # Collapses 3+ newlines into two newlines
-
- def normalize
- parts = []
-
- newlines = 0
-
- @parts.each do |part|
- case part
- when /^\s*\n/ then
- newlines += 1
- parts << part if newlines == 1
- else
- newlines = 0
- parts << part
- end
- end
-
- parts.pop if parts.last =~ /\A\r?\n\z/
-
- @parts = parts
- end
-
- def pretty_print q # :nodoc:
- self.class.name =~ /.*::(\w{1,4})/i
-
- q.group 2, "[#{$1.downcase}: ", ']' do
- if @format then
- q.text "format: #{@format}"
- q.breakable
- end
-
- q.seplist @parts do |part|
- q.pp part
- end
- end
- end
-
- ##
- # Is this verbatim section Ruby code?
-
- def ruby?
- @format ||= nil # TODO for older ri data, switch the tree to marshal_dump
- @format == :ruby
- end
-
- ##
- # The text of the section
-
- def text
- @parts.join
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/meta_method.rb b/ruby_2_2/lib/rdoc/meta_method.rb
deleted file mode 100644
index 68ba8109e0..0000000000
--- a/ruby_2_2/lib/rdoc/meta_method.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-##
-# MetaMethod represents a meta-programmed method
-
-class RDoc::MetaMethod < RDoc::AnyMethod
-end
-
diff --git a/ruby_2_2/lib/rdoc/method_attr.rb b/ruby_2_2/lib/rdoc/method_attr.rb
deleted file mode 100644
index a0ea851dc5..0000000000
--- a/ruby_2_2/lib/rdoc/method_attr.rb
+++ /dev/null
@@ -1,418 +0,0 @@
-##
-# Abstract class representing either a method or an attribute.
-
-class RDoc::MethodAttr < RDoc::CodeObject
-
- include Comparable
-
- ##
- # Name of this method/attribute.
-
- attr_accessor :name
-
- ##
- # public, protected, private
-
- attr_accessor :visibility
-
- ##
- # Is this a singleton method/attribute?
-
- attr_accessor :singleton
-
- ##
- # Source file token stream
-
- attr_reader :text
-
- ##
- # Array of other names for this method/attribute
-
- attr_reader :aliases
-
- ##
- # The method/attribute we're aliasing
-
- attr_accessor :is_alias_for
-
- #--
- # The attributes below are for AnyMethod only.
- # They are left here for the time being to
- # allow ri to operate.
- # TODO modify ri to avoid calling these on attributes.
- #++
-
- ##
- # Parameters yielded by the called block
-
- attr_reader :block_params
-
- ##
- # Parameters for this method
-
- attr_accessor :params
-
- ##
- # Different ways to call this method
-
- attr_accessor :call_seq
-
- ##
- # The call_seq or the param_seq with method name, if there is no call_seq.
-
- attr_reader :arglists
-
- ##
- # Pretty parameter list for this method
-
- attr_reader :param_seq
-
-
- ##
- # Creates a new MethodAttr from token stream +text+ and method or attribute
- # name +name+.
- #
- # Usually this is called by super from a subclass.
-
- def initialize text, name
- super()
-
- @text = text
- @name = name
-
- @aliases = []
- @is_alias_for = nil
- @parent_name = nil
- @singleton = nil
- @visibility = :public
- @see = false
-
- @arglists = nil
- @block_params = nil
- @call_seq = nil
- @param_seq = nil
- @params = nil
- end
-
- ##
- # Resets cached data for the object so it can be rebuilt by accessor methods
-
- def initialize_copy other # :nodoc:
- @full_name = nil
- end
-
- def initialize_visibility # :nodoc:
- super
- @see = nil
- end
-
- ##
- # Order by #singleton then #name
-
- def <=>(other)
- return unless other.respond_to?(:singleton) &&
- other.respond_to?(:name)
-
- [ @singleton ? 0 : 1, name] <=>
- [other.singleton ? 0 : 1, other.name]
- end
-
- def == other # :nodoc:
- equal?(other) or self.class == other.class and full_name == other.full_name
- end
-
- ##
- # A method/attribute is documented if any of the following is true:
- # - it was marked with :nodoc:;
- # - it has a comment;
- # - it is an alias for a documented method;
- # - it has a +#see+ method that is documented.
-
- def documented?
- super or
- (is_alias_for and is_alias_for.documented?) or
- (see and see.documented?)
- end
-
- ##
- # A method/attribute to look at,
- # in particular if this method/attribute has no documentation.
- #
- # It can be a method/attribute of the superclass or of an included module,
- # including the Kernel module, which is always appended to the included
- # modules.
- #
- # Returns +nil+ if there is no such method/attribute.
- # The +#is_alias_for+ method/attribute, if any, is not included.
- #
- # Templates may generate a "see also ..." if this method/attribute
- # has documentation, and "see ..." if it does not.
-
- def see
- @see = find_see if @see == false
- @see
- end
-
- ##
- # Sets the store for this class or module and its contained code objects.
-
- def store= store
- super
-
- @file = @store.add_file @file.full_name if @file
- end
-
- def find_see # :nodoc:
- return nil if singleton || is_alias_for
-
- # look for the method
- other = find_method_or_attribute name
- return other if other
-
- # if it is a setter, look for a getter
- return nil unless name =~ /[a-z_]=$/i # avoid == or ===
- return find_method_or_attribute name[0..-2]
- end
-
- def find_method_or_attribute name # :nodoc:
- return nil unless parent.respond_to? :ancestors
-
- searched = parent.ancestors
- kernel = @store.modules_hash['Kernel']
-
- searched << kernel if kernel &&
- parent != kernel && !searched.include?(kernel)
-
- searched.each do |ancestor|
- next if String === ancestor
- next if parent == ancestor
-
- other = ancestor.find_method_named('#' << name) ||
- ancestor.find_attribute_named(name)
-
- return other if other
- end
-
- nil
- end
-
- ##
- # Abstract method. Contexts in their building phase call this
- # to register a new alias for this known method/attribute.
- #
- # - creates a new AnyMethod/Attribute named <tt>an_alias.new_name</tt>;
- # - adds +self+ as an alias for the new method or attribute
- # - adds the method or attribute to #aliases
- # - adds the method or attribute to +context+.
-
- def add_alias(an_alias, context)
- raise NotImplementedError
- end
-
- ##
- # HTML fragment reference for this method
-
- def aref
- type = singleton ? 'c' : 'i'
- # % characters are not allowed in html names => dash instead
- "#{aref_prefix}-#{type}-#{html_name}"
- end
-
- ##
- # Prefix for +aref+, defined by subclasses.
-
- def aref_prefix
- raise NotImplementedError
- end
-
- ##
- # Attempts to sanitize the content passed by the Ruby parser:
- # remove outer parentheses, etc.
-
- def block_params=(value)
- # 'yield.to_s' or 'assert yield, msg'
- return @block_params = '' if value =~ /^[\.,]/
-
- # remove trailing 'if/unless ...'
- return @block_params = '' if value =~ /^(if|unless)\s/
-
- value = $1.strip if value =~ /^(.+)\s(if|unless)\s/
-
- # outer parentheses
- value = $1 if value =~ /^\s*\((.*)\)\s*$/
- value = value.strip
-
- # proc/lambda
- return @block_params = $1 if value =~ /^(proc|lambda)(\s*\{|\sdo)/
-
- # surrounding +...+ or [...]
- value = $1.strip if value =~ /^\+(.*)\+$/
- value = $1.strip if value =~ /^\[(.*)\]$/
-
- return @block_params = '' if value.empty?
-
- # global variable
- return @block_params = 'str' if value =~ /^\$[&0-9]$/
-
- # wipe out array/hash indices
- value.gsub!(/(\w)\[[^\[]+\]/, '\1')
-
- # remove @ from class/instance variables
- value.gsub!(/@@?([a-z0-9_]+)/, '\1')
-
- # method calls => method name
- value.gsub!(/([A-Z:a-z0-9_]+)\.([a-z0-9_]+)(\s*\(\s*[a-z0-9_.,\s]*\s*\)\s*)?/) do
- case $2
- when 'to_s' then $1
- when 'const_get' then 'const'
- when 'new' then
- $1.split('::').last. # ClassName => class_name
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
- downcase
- else
- $2
- end
- end
-
- # class prefixes
- value.gsub!(/[A-Za-z0-9_:]+::/, '')
-
- # simple expressions
- value = $1 if value =~ /^([a-z0-9_]+)\s*[-*+\/]/
-
- @block_params = value.strip
- end
-
- ##
- # HTML id-friendly method/attribute name
-
- def html_name
- require 'cgi'
-
- CGI.escape(@name.gsub('-', '-2D')).gsub('%','-').sub(/^-/, '')
- end
-
- ##
- # Full method/attribute name including namespace
-
- def full_name
- @full_name ||= "#{parent_name}#{pretty_name}"
- end
-
- def inspect # :nodoc:
- alias_for = @is_alias_for ? " (alias for #{@is_alias_for.name})" : nil
- visibility = self.visibility
- visibility = "forced #{visibility}" if force_documentation
- "#<%s:0x%x %s (%s)%s>" % [
- self.class, object_id,
- full_name,
- visibility,
- alias_for,
- ]
- end
-
- ##
- # '::' for a class method/attribute, '#' for an instance method.
-
- def name_prefix
- @singleton ? '::' : '#'
- end
-
- ##
- # Name for output to HTML. For class methods the full name with a "." is
- # used like +SomeClass.method_name+. For instance methods the class name is
- # used if +context+ does not match the parent.
- #
- # This is to help prevent people from using :: to call class methods.
-
- def output_name context
- return "#{name_prefix}#{@name}" if context == parent
-
- "#{parent_name}#{@singleton ? '.' : '#'}#{@name}"
- end
-
- ##
- # Method/attribute name with class/instance indicator
-
- def pretty_name
- "#{name_prefix}#{@name}"
- end
-
- ##
- # Type of method/attribute (class or instance)
-
- def type
- singleton ? 'class' : 'instance'
- end
-
- ##
- # Path to this method for use with HTML generator output.
-
- def path
- "#{@parent.path}##{aref}"
- end
-
- ##
- # Name of our parent with special handling for un-marshaled methods
-
- def parent_name
- @parent_name || super
- end
-
- def pretty_print q # :nodoc:
- alias_for =
- if @is_alias_for.respond_to? :name then
- "alias for #{@is_alias_for.name}"
- elsif Array === @is_alias_for then
- "alias for #{@is_alias_for.last}"
- end
-
- q.group 2, "[#{self.class.name} #{full_name} #{visibility}", "]" do
- if alias_for then
- q.breakable
- q.text alias_for
- end
-
- if text then
- q.breakable
- q.text "text:"
- q.breakable
- q.pp @text
- end
-
- unless comment.empty? then
- q.breakable
- q.text "comment:"
- q.breakable
- q.pp @comment
- end
- end
- end
-
- ##
- # Used by RDoc::Generator::JsonIndex to create a record for the search
- # engine.
-
- def search_record
- [
- @name,
- full_name,
- @name,
- @parent.full_name,
- path,
- params,
- snippet(@comment),
- ]
- end
-
- def to_s # :nodoc:
- if @is_alias_for
- "#{self.class.name}: #{full_name} -> #{is_alias_for}"
- else
- "#{self.class.name}: #{full_name}"
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/mixin.rb b/ruby_2_2/lib/rdoc/mixin.rb
deleted file mode 100644
index 547744f870..0000000000
--- a/ruby_2_2/lib/rdoc/mixin.rb
+++ /dev/null
@@ -1,120 +0,0 @@
-##
-# A Mixin adds features from a module into another context. RDoc::Include and
-# RDoc::Extend are both mixins.
-
-class RDoc::Mixin < RDoc::CodeObject
-
- ##
- # Name of included module
-
- attr_accessor :name
-
- ##
- # Creates a new Mixin for +name+ with +comment+
-
- def initialize(name, comment)
- super()
- @name = name
- self.comment = comment
- @module = nil # cache for module if found
- end
-
- ##
- # Mixins are sorted by name
-
- def <=> other
- return unless self.class === other
-
- name <=> other.name
- end
-
- def == other # :nodoc:
- self.class === other and @name == other.name
- end
-
- alias eql? == # :nodoc:
-
- ##
- # Full name based on #module
-
- def full_name
- m = self.module
- RDoc::ClassModule === m ? m.full_name : @name
- end
-
- def hash # :nodoc:
- [@name, self.module].hash
- end
-
- def inspect # :nodoc:
- "#<%s:0x%x %s.%s %s>" % [
- self.class,
- object_id,
- parent_name, self.class.name.downcase, @name,
- ]
- end
-
- ##
- # Attempts to locate the included module object. Returns the name if not
- # known.
- #
- # The scoping rules of Ruby to resolve the name of an included module are:
- # - first look into the children of the current context;
- # - if not found, look into the children of included modules,
- # in reverse inclusion order;
- # - if still not found, go up the hierarchy of names.
- #
- # This method has <code>O(n!)</code> behavior when the module calling
- # include is referencing nonexistent modules. Avoid calling #module until
- # after all the files are parsed. This behavior is due to ruby's constant
- # lookup behavior.
- #
- # As of the beginning of October, 2011, no gem includes nonexistent modules.
-
- def module
- return @module if @module
-
- # search the current context
- return @name unless parent
- full_name = parent.child_name(@name)
- @module = @store.modules_hash[full_name]
- return @module if @module
- return @name if @name =~ /^::/
-
- # search the includes before this one, in reverse order
- searched = parent.includes.take_while { |i| i != self }.reverse
- searched.each do |i|
- inc = i.module
- next if String === inc
- full_name = inc.child_name(@name)
- @module = @store.modules_hash[full_name]
- return @module if @module
- end
-
- # go up the hierarchy of names
- up = parent.parent
- while up
- full_name = up.child_name(@name)
- @module = @store.modules_hash[full_name]
- return @module if @module
- up = up.parent
- end
-
- @name
- end
-
- ##
- # Sets the store for this class or module and its contained code objects.
-
- def store= store
- super
-
- @file = @store.add_file @file.full_name if @file
- end
-
- def to_s # :nodoc:
- "#{self.class.name.downcase} #@name in: #{parent}"
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/normal_class.rb b/ruby_2_2/lib/rdoc/normal_class.rb
deleted file mode 100644
index 7589e2686c..0000000000
--- a/ruby_2_2/lib/rdoc/normal_class.rb
+++ /dev/null
@@ -1,92 +0,0 @@
-##
-# A normal class, neither singleton nor anonymous
-
-class RDoc::NormalClass < RDoc::ClassModule
-
- ##
- # The ancestors of this class including modules. Unlike Module#ancestors,
- # this class is not included in the result. The result will contain both
- # RDoc::ClassModules and Strings.
-
- def ancestors
- if String === superclass then
- super << superclass
- elsif superclass then
- ancestors = super
- ancestors << superclass
- ancestors.concat superclass.ancestors
- else
- super
- end
- end
-
- def aref_prefix # :nodoc:
- 'class'
- end
-
- ##
- # The definition of this class, <tt>class MyClassName</tt>
-
- def definition
- "class #{full_name}"
- end
-
- def direct_ancestors
- superclass ? super + [superclass] : super
- end
-
- def inspect # :nodoc:
- superclass = @superclass ? " < #{@superclass}" : nil
- "<%s:0x%x class %s%s includes: %p extends: %p attributes: %p methods: %p aliases: %p>" % [
- self.class, object_id,
- full_name, superclass, @includes, @extends, @attributes, @method_list, @aliases
- ]
- end
-
- def to_s # :nodoc:
- display = "#{self.class.name} #{self.full_name}"
- if superclass
- display << ' < ' << (superclass.is_a?(String) ? superclass : superclass.full_name)
- end
- display << ' -> ' << is_alias_for.to_s if is_alias_for
- display
- end
-
- def pretty_print q # :nodoc:
- superclass = @superclass ? " < #{@superclass}" : nil
-
- q.group 2, "[class #{full_name}#{superclass} ", "]" do
- q.breakable
- q.text "includes:"
- q.breakable
- q.seplist @includes do |inc| q.pp inc end
-
- q.breakable
- q.text "constants:"
- q.breakable
- q.seplist @constants do |const| q.pp const end
-
- q.breakable
- q.text "attributes:"
- q.breakable
- q.seplist @attributes do |attr| q.pp attr end
-
- q.breakable
- q.text "methods:"
- q.breakable
- q.seplist @method_list do |meth| q.pp meth end
-
- q.breakable
- q.text "aliases:"
- q.breakable
- q.seplist @aliases do |aliaz| q.pp aliaz end
-
- q.breakable
- q.text "comment:"
- q.breakable
- q.pp comment
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/normal_module.rb b/ruby_2_2/lib/rdoc/normal_module.rb
deleted file mode 100644
index 961c431ed6..0000000000
--- a/ruby_2_2/lib/rdoc/normal_module.rb
+++ /dev/null
@@ -1,73 +0,0 @@
-##
-# A normal module, like NormalClass
-
-class RDoc::NormalModule < RDoc::ClassModule
-
- def aref_prefix # :nodoc:
- 'module'
- end
-
- def inspect # :nodoc:
- "#<%s:0x%x module %s includes: %p extends: %p attributes: %p methods: %p aliases: %p>" % [
- self.class, object_id,
- full_name, @includes, @extends, @attributes, @method_list, @aliases
- ]
- end
-
- ##
- # The definition of this module, <tt>module MyModuleName</tt>
-
- def definition
- "module #{full_name}"
- end
-
- ##
- # This is a module, returns true
-
- def module?
- true
- end
-
- def pretty_print q # :nodoc:
- q.group 2, "[module #{full_name}: ", "]" do
- q.breakable
- q.text "includes:"
- q.breakable
- q.seplist @includes do |inc| q.pp inc end
- q.breakable
-
- q.breakable
- q.text "constants:"
- q.breakable
- q.seplist @constants do |const| q.pp const end
-
- q.text "attributes:"
- q.breakable
- q.seplist @attributes do |attr| q.pp attr end
- q.breakable
-
- q.text "methods:"
- q.breakable
- q.seplist @method_list do |meth| q.pp meth end
- q.breakable
-
- q.text "aliases:"
- q.breakable
- q.seplist @aliases do |aliaz| q.pp aliaz end
- q.breakable
-
- q.text "comment:"
- q.breakable
- q.pp comment
- end
- end
-
- ##
- # Modules don't have one, raises NoMethodError
-
- def superclass
- raise NoMethodError, "#{full_name} is a module"
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/options.rb b/ruby_2_2/lib/rdoc/options.rb
deleted file mode 100644
index 5779d35c44..0000000000
--- a/ruby_2_2/lib/rdoc/options.rb
+++ /dev/null
@@ -1,1251 +0,0 @@
-require 'optparse'
-require 'pathname'
-
-##
-# RDoc::Options handles the parsing and storage of options
-#
-# == Saved Options
-#
-# You can save some options like the markup format in the
-# <tt>.rdoc_options</tt> file in your gem. The easiest way to do this is:
-#
-# rdoc --markup tomdoc --write-options
-#
-# Which will automatically create the file and fill it with the options you
-# specified.
-#
-# The following options will not be saved since they interfere with the user's
-# preferences or with the normal operation of RDoc:
-#
-# * +--coverage-report+
-# * +--dry-run+
-# * +--encoding+
-# * +--force-update+
-# * +--format+
-# * +--pipe+
-# * +--quiet+
-# * +--template+
-# * +--verbose+
-#
-# == Custom Options
-#
-# Generators can hook into RDoc::Options to add generator-specific command
-# line options.
-#
-# When <tt>--format</tt> is encountered in ARGV, RDoc calls ::setup_options on
-# the generator class to add extra options to the option parser. Options for
-# custom generators must occur after <tt>--format</tt>. <tt>rdoc --help</tt>
-# will list options for all installed generators.
-#
-# Example:
-#
-# class RDoc::Generator::Spellcheck
-# RDoc::RDoc.add_generator self
-#
-# def self.setup_options rdoc_options
-# op = rdoc_options.option_parser
-#
-# op.on('--spell-dictionary DICTIONARY',
-# RDoc::Options::Path) do |dictionary|
-# rdoc_options.spell_dictionary = dictionary
-# end
-# end
-# end
-#
-# Of course, RDoc::Options does not respond to +spell_dictionary+ by default
-# so you will need to add it:
-#
-# class RDoc::Options
-#
-# ##
-# # The spell dictionary used by the spell-checking plugin.
-#
-# attr_accessor :spell_dictionary
-#
-# end
-#
-# == Option Validators
-#
-# OptionParser validators will validate and cast user input values. In
-# addition to the validators that ship with OptionParser (String, Integer,
-# Float, TrueClass, FalseClass, Array, Regexp, Date, Time, URI, etc.),
-# RDoc::Options adds Path, PathArray and Template.
-
-class RDoc::Options
-
- ##
- # The deprecated options.
-
- DEPRECATED = {
- '--accessor' => 'support discontinued',
- '--diagram' => 'support discontinued',
- '--help-output' => 'support discontinued',
- '--image-format' => 'was an option for --diagram',
- '--inline-source' => 'source code is now always inlined',
- '--merge' => 'ri now always merges class information',
- '--one-file' => 'support discontinued',
- '--op-name' => 'support discontinued',
- '--opname' => 'support discontinued',
- '--promiscuous' => 'files always only document their content',
- '--ri-system' => 'Ruby installers use other techniques',
- }
-
- ##
- # RDoc options ignored (or handled specially) by --write-options
-
- SPECIAL = %w[
- coverage_report
- dry_run
- encoding
- files
- force_output
- force_update
- generator
- generator_name
- generator_options
- generators
- op_dir
- option_parser
- pipe
- rdoc_include
- root
- static_path
- stylesheet_url
- template
- template_dir
- update_output_dir
- verbosity
- write_options
- ]
-
- ##
- # Option validator for OptionParser that matches a directory that exists on
- # the filesystem.
-
- Directory = Object.new
-
- ##
- # Option validator for OptionParser that matches a file or directory that
- # exists on the filesystem.
-
- Path = Object.new
-
- ##
- # Option validator for OptionParser that matches a comma-separated list of
- # files or directories that exist on the filesystem.
-
- PathArray = Object.new
-
- ##
- # Option validator for OptionParser that matches a template directory for an
- # installed generator that lives in
- # <tt>"rdoc/generator/template/#{template_name}"</tt>
-
- Template = Object.new
-
- ##
- # Character-set for HTML output. #encoding is preferred over #charset
-
- attr_accessor :charset
-
- ##
- # If true, RDoc will not write any files.
-
- attr_accessor :dry_run
-
- ##
- # The output encoding. All input files will be transcoded to this encoding.
- #
- # The default encoding is UTF-8. This is set via --encoding.
-
- attr_accessor :encoding
-
- ##
- # Files matching this pattern will be excluded
-
- attr_accessor :exclude
-
- ##
- # The list of files to be processed
-
- attr_accessor :files
-
- ##
- # Create the output even if the output directory does not look
- # like an rdoc output directory
-
- attr_accessor :force_output
-
- ##
- # Scan newer sources than the flag file if true.
-
- attr_accessor :force_update
-
- ##
- # Formatter to mark up text with
-
- attr_accessor :formatter
-
- ##
- # Description of the output generator (set with the <tt>--format</tt> option)
-
- attr_accessor :generator
-
- ##
- # For #==
-
- attr_reader :generator_name # :nodoc:
-
- ##
- # Loaded generator options. Used to prevent --help from loading the same
- # options multiple times.
-
- attr_accessor :generator_options
-
- ##
- # Old rdoc behavior: hyperlink all words that match a method name,
- # even if not preceded by '#' or '::'
-
- attr_accessor :hyperlink_all
-
- ##
- # Include line numbers in the source code
-
- attr_accessor :line_numbers
-
- ##
- # The output locale.
-
- attr_accessor :locale
-
- ##
- # The directory where locale data live.
-
- attr_accessor :locale_dir
-
- ##
- # Name of the file, class or module to display in the initial index page (if
- # not specified the first file we encounter is used)
-
- attr_accessor :main_page
-
- ##
- # The default markup format. The default is 'rdoc'. 'markdown', 'tomdoc'
- # and 'rd' are also built-in.
-
- attr_accessor :markup
-
- ##
- # If true, only report on undocumented files
-
- attr_accessor :coverage_report
-
- ##
- # The name of the output directory
-
- attr_accessor :op_dir
-
- ##
- # The OptionParser for this instance
-
- attr_accessor :option_parser
-
- ##
- # Output heading decorations?
- attr_accessor :output_decoration
-
- ##
- # Directory where guides, FAQ, and other pages not associated with a class
- # live. You may leave this unset if these are at the root of your project.
-
- attr_accessor :page_dir
-
- ##
- # Is RDoc in pipe mode?
-
- attr_accessor :pipe
-
- ##
- # Array of directories to search for files to satisfy an :include:
-
- attr_accessor :rdoc_include
-
- ##
- # Root of the source documentation will be generated for. Set this when
- # building documentation outside the source directory. Defaults to the
- # current directory.
-
- attr_accessor :root
-
- ##
- # Include the '#' at the front of hyperlinked instance method names
-
- attr_accessor :show_hash
-
- ##
- # Directory to copy static files from
-
- attr_accessor :static_path
-
- ##
- # The number of columns in a tab
-
- attr_accessor :tab_width
-
- ##
- # Template to be used when generating output
-
- attr_accessor :template
-
- ##
- # Directory the template lives in
-
- attr_accessor :template_dir
-
- ##
- # Additional template stylesheets
-
- attr_accessor :template_stylesheets
-
- ##
- # Documentation title
-
- attr_accessor :title
-
- ##
- # Should RDoc update the timestamps in the output dir?
-
- attr_accessor :update_output_dir
-
- ##
- # Verbosity, zero means quiet
-
- attr_accessor :verbosity
-
- ##
- # URL of web cvs frontend
-
- attr_accessor :webcvs
-
- ##
- # Minimum visibility of a documented method. One of +:public+, +:protected+,
- # +:private+ or +:nodoc+.
- #
- # The +:nodoc+ visibility ignores all directives related to visibility. The
- # other visibilities may be overridden on a per-method basis with the :doc:
- # directive.
-
- attr_reader :visibility
-
- def initialize # :nodoc:
- init_ivars
- end
-
- def init_ivars # :nodoc:
- @dry_run = false
- @exclude = []
- @files = nil
- @force_output = false
- @force_update = true
- @generator = nil
- @generator_name = nil
- @generator_options = []
- @generators = RDoc::RDoc::GENERATORS
- @hyperlink_all = false
- @line_numbers = false
- @locale = nil
- @locale_name = nil
- @locale_dir = 'locale'
- @main_page = nil
- @markup = 'rdoc'
- @coverage_report = false
- @op_dir = nil
- @page_dir = nil
- @pipe = false
- @output_decoration = true
- @rdoc_include = []
- @root = Pathname(Dir.pwd)
- @show_hash = false
- @static_path = []
- @stylesheet_url = nil # TODO remove in RDoc 4
- @tab_width = 8
- @template = nil
- @template_dir = nil
- @template_stylesheets = []
- @title = nil
- @update_output_dir = true
- @verbosity = 1
- @visibility = :protected
- @webcvs = nil
- @write_options = false
-
- if Object.const_defined? :Encoding then
- @encoding = Encoding::UTF_8
- @charset = @encoding.name
- else
- @encoding = nil
- @charset = 'UTF-8'
- end
- end
-
- def init_with map # :nodoc:
- init_ivars
-
- encoding = map['encoding']
- @encoding = if Object.const_defined? :Encoding then
- encoding ? Encoding.find(encoding) : encoding
- end
-
- @charset = map['charset']
- @exclude = map['exclude']
- @generator_name = map['generator_name']
- @hyperlink_all = map['hyperlink_all']
- @line_numbers = map['line_numbers']
- @locale_name = map['locale_name']
- @locale_dir = map['locale_dir']
- @main_page = map['main_page']
- @markup = map['markup']
- @op_dir = map['op_dir']
- @show_hash = map['show_hash']
- @tab_width = map['tab_width']
- @template_dir = map['template_dir']
- @title = map['title']
- @visibility = map['visibility']
- @webcvs = map['webcvs']
-
- @rdoc_include = sanitize_path map['rdoc_include']
- @static_path = sanitize_path map['static_path']
- end
-
- def yaml_initialize tag, map # :nodoc:
- init_with map
- end
-
- def == other # :nodoc:
- self.class === other and
- @encoding == other.encoding and
- @generator_name == other.generator_name and
- @hyperlink_all == other.hyperlink_all and
- @line_numbers == other.line_numbers and
- @locale == other.locale and
- @locale_dir == other.locale_dir and
- @main_page == other.main_page and
- @markup == other.markup and
- @op_dir == other.op_dir and
- @rdoc_include == other.rdoc_include and
- @show_hash == other.show_hash and
- @static_path == other.static_path and
- @tab_width == other.tab_width and
- @template == other.template and
- @title == other.title and
- @visibility == other.visibility and
- @webcvs == other.webcvs
- end
-
- ##
- # Check that the files on the command line exist
-
- def check_files
- @files.delete_if do |file|
- if File.exist? file then
- if File.readable? file then
- false
- else
- warn "file '#{file}' not readable"
-
- true
- end
- else
- warn "file '#{file}' not found"
-
- true
- end
- end
- end
-
- ##
- # Ensure only one generator is loaded
-
- def check_generator
- if @generator then
- raise OptionParser::InvalidOption,
- "generator already set to #{@generator_name}"
- end
- end
-
- ##
- # Set the title, but only if not already set. Used to set the title
- # from a source file, so that a title set from the command line
- # will have the priority.
-
- def default_title=(string)
- @title ||= string
- end
-
- ##
- # For dumping YAML
-
- def encode_with coder # :nodoc:
- encoding = @encoding ? @encoding.name : nil
-
- coder.add 'encoding', encoding
- coder.add 'static_path', sanitize_path(@static_path)
- coder.add 'rdoc_include', sanitize_path(@rdoc_include)
-
- ivars = instance_variables.map { |ivar| ivar.to_s[1..-1] }
- ivars -= SPECIAL
-
- ivars.sort.each do |ivar|
- coder.add ivar, instance_variable_get("@#{ivar}")
- end
- end
-
- ##
- # Completes any unfinished option setup business such as filtering for
- # existent files, creating a regexp for #exclude and setting a default
- # #template.
-
- def finish
- @op_dir ||= 'doc'
-
- @rdoc_include << "." if @rdoc_include.empty?
- root = @root.to_s
- @rdoc_include << root unless @rdoc_include.include?(root)
-
- if @exclude.nil? or Regexp === @exclude then
- # done, #finish is being re-run
- elsif @exclude.empty? then
- @exclude = nil
- else
- @exclude = Regexp.new(@exclude.join("|"))
- end
-
- finish_page_dir
-
- check_files
-
- # If no template was specified, use the default template for the output
- # formatter
-
- unless @template then
- @template = @generator_name
- @template_dir = template_dir_for @template
- end
-
- if @locale_name
- @locale = RDoc::I18n::Locale[@locale_name]
- @locale.load(@locale_dir)
- else
- @locale = nil
- end
-
- self
- end
-
- ##
- # Fixes the page_dir to be relative to the root_dir and adds the page_dir to
- # the files list.
-
- def finish_page_dir
- return unless @page_dir
-
- @files << @page_dir.to_s
-
- page_dir = @page_dir.expand_path.relative_path_from @root
-
- @page_dir = page_dir
- end
-
- ##
- # Returns a properly-space list of generators and their descriptions.
-
- def generator_descriptions
- lengths = []
-
- generators = RDoc::RDoc::GENERATORS.map do |name, generator|
- lengths << name.length
-
- description = generator::DESCRIPTION if
- generator.const_defined? :DESCRIPTION
-
- [name, description]
- end
-
- longest = lengths.max
-
- generators.sort.map do |name, description|
- if description then
- " %-*s - %s" % [longest, name, description]
- else
- " #{name}"
- end
- end.join "\n"
- end
-
- ##
- # Parses command line options.
-
- def parse argv
- ignore_invalid = true
-
- argv.insert(0, *ENV['RDOCOPT'].split) if ENV['RDOCOPT']
-
- opts = OptionParser.new do |opt|
- @option_parser = opt
- opt.program_name = File.basename $0
- opt.version = RDoc::VERSION
- opt.release = nil
- opt.summary_indent = ' ' * 4
- opt.banner = <<-EOF
-Usage: #{opt.program_name} [options] [names...]
-
- Files are parsed, and the information they contain collected, before any
- output is produced. This allows cross references between all files to be
- resolved. If a name is a directory, it is traversed. If no names are
- specified, all Ruby files in the current directory (and subdirectories) are
- processed.
-
- How RDoc generates output depends on the output formatter being used, and on
- the options you give.
-
- Options can be specified via the RDOCOPT environment variable, which
- functions similar to the RUBYOPT environment variable for ruby.
-
- $ export RDOCOPT="--show-hash"
-
- will make rdoc show hashes in method links by default. Command-line options
- always will override those in RDOCOPT.
-
- Available formatters:
-
-#{generator_descriptions}
-
- RDoc understands the following file formats:
-
- EOF
-
- parsers = Hash.new { |h,parser| h[parser] = [] }
-
- RDoc::Parser.parsers.each do |regexp, parser|
- parsers[parser.name.sub('RDoc::Parser::', '')] << regexp.source
- end
-
- parsers.sort.each do |parser, regexp|
- opt.banner << " - #{parser}: #{regexp.join ', '}\n"
- end
- opt.banner << " - TomDoc: Only in ruby files\n"
-
- opt.banner << "\n The following options are deprecated:\n\n"
-
- name_length = DEPRECATED.keys.sort_by { |k| k.length }.last.length
-
- DEPRECATED.sort_by { |k,| k }.each do |name, reason|
- opt.banner << " %*1$2$s %3$s\n" % [-name_length, name, reason]
- end
-
- opt.accept Template do |template|
- template_dir = template_dir_for template
-
- unless template_dir then
- $stderr.puts "could not find template #{template}"
- nil
- else
- [template, template_dir]
- end
- end
-
- opt.accept Directory do |directory|
- directory = File.expand_path directory
-
- raise OptionParser::InvalidArgument unless File.directory? directory
-
- directory
- end
-
- opt.accept Path do |path|
- path = File.expand_path path
-
- raise OptionParser::InvalidArgument unless File.exist? path
-
- path
- end
-
- opt.accept PathArray do |paths,|
- paths = if paths then
- paths.split(',').map { |d| d unless d.empty? }
- end
-
- paths.map do |path|
- path = File.expand_path path
-
- raise OptionParser::InvalidArgument unless File.exist? path
-
- path
- end
- end
-
- opt.separator nil
- opt.separator "Parsing options:"
- opt.separator nil
-
- if Object.const_defined? :Encoding then
- opt.on("--encoding=ENCODING", "-e", Encoding.list.map { |e| e.name },
- "Specifies the output encoding. All files",
- "read will be converted to this encoding.",
- "The default encoding is UTF-8.",
- "--encoding is preferred over --charset") do |value|
- @encoding = Encoding.find value
- @charset = @encoding.name # may not be valid value
- end
-
- opt.separator nil
- end
-
-
- opt.on("--locale=NAME",
- "Specifies the output locale.") do |value|
- @locale_name = value
- end
-
- opt.on("--locale-data-dir=DIR",
- "Specifies the directory where locale data live.") do |value|
- @locale_dir = value
- end
-
- opt.separator nil
-
- opt.on("--all", "-a",
- "Synonym for --visibility=private.") do |value|
- @visibility = :private
- end
-
- opt.separator nil
-
- opt.on("--exclude=PATTERN", "-x", Regexp,
- "Do not process files or directories",
- "matching PATTERN.") do |value|
- @exclude << value
- end
-
- opt.separator nil
-
- opt.on("--extension=NEW=OLD", "-E",
- "Treat files ending with .new as if they",
- "ended with .old. Using '-E cgi=rb' will",
- "cause xxx.cgi to be parsed as a Ruby file.") do |value|
- new, old = value.split(/=/, 2)
-
- unless new and old then
- raise OptionParser::InvalidArgument, "Invalid parameter to '-E'"
- end
-
- unless RDoc::Parser.alias_extension old, new then
- raise OptionParser::InvalidArgument, "Unknown extension .#{old} to -E"
- end
- end
-
- opt.separator nil
-
- opt.on("--[no-]force-update", "-U",
- "Forces rdoc to scan all sources even if",
- "newer than the flag file.") do |value|
- @force_update = value
- end
-
- opt.separator nil
-
- opt.on("--pipe", "-p",
- "Convert RDoc on stdin to HTML") do
- @pipe = true
- end
-
- opt.separator nil
-
- opt.on("--tab-width=WIDTH", "-w", Integer,
- "Set the width of tab characters.") do |value|
- raise OptionParser::InvalidArgument,
- "#{value} is an invalid tab width" if value <= 0
- @tab_width = value
- end
-
- opt.separator nil
-
- opt.on("--visibility=VISIBILITY", "-V", RDoc::VISIBILITIES + [:nodoc],
- "Minimum visibility to document a method.",
- "One of 'public', 'protected' (the default),",
- "'private' or 'nodoc' (show everything)") do |value|
- @visibility = value
- end
-
- opt.separator nil
-
- markup_formats = RDoc::Text::MARKUP_FORMAT.keys.sort
-
- opt.on("--markup=MARKUP", markup_formats,
- "The markup format for the named files.",
- "The default is rdoc. Valid values are:",
- markup_formats.join(', ')) do |value|
- @markup = value
- end
-
- opt.separator nil
-
- opt.on("--root=ROOT", Directory,
- "Root of the source tree documentation",
- "will be generated for. Set this when",
- "building documentation outside the",
- "source directory. Default is the",
- "current directory.") do |root|
- @root = Pathname(root)
- end
-
- opt.separator nil
-
- opt.on("--page-dir=DIR", Directory,
- "Directory where guides, your FAQ or",
- "other pages not associated with a class",
- "live. Set this when you don't store",
- "such files at your project root.",
- "NOTE: Do not use the same file name in",
- "the page dir and the root of your project") do |page_dir|
- @page_dir = Pathname(page_dir)
- end
-
- opt.separator nil
- opt.separator "Common generator options:"
- opt.separator nil
-
- opt.on("--force-output", "-O",
- "Forces rdoc to write the output files,",
- "even if the output directory exists",
- "and does not seem to have been created",
- "by rdoc.") do |value|
- @force_output = value
- end
-
- opt.separator nil
-
- generator_text = @generators.keys.map { |name| " #{name}" }.sort
-
- opt.on("-f", "--fmt=FORMAT", "--format=FORMAT", @generators.keys,
- "Set the output formatter. One of:", *generator_text) do |value|
- check_generator
-
- @generator_name = value.downcase
- setup_generator
- end
-
- opt.separator nil
-
- opt.on("--include=DIRECTORIES", "-i", PathArray,
- "Set (or add to) the list of directories to",
- "be searched when satisfying :include:",
- "requests. Can be used more than once.") do |value|
- @rdoc_include.concat value.map { |dir| dir.strip }
- end
-
- opt.separator nil
-
- opt.on("--[no-]coverage-report=[LEVEL]", "--[no-]dcov", "-C", Integer,
- "Prints a report on undocumented items.",
- "Does not generate files.") do |value|
- value = 0 if value.nil? # Integer converts -C to nil
-
- @coverage_report = value
- @force_update = true if value
- end
-
- opt.separator nil
-
- opt.on("--output=DIR", "--op", "-o",
- "Set the output directory.") do |value|
- @op_dir = value
- end
-
- opt.separator nil
-
- opt.on("-d",
- "Deprecated --diagram option.",
- "Prevents firing debug mode",
- "with legacy invocation.") do |value|
- end
-
- opt.separator nil
- opt.separator 'HTML generator options:'
- opt.separator nil
-
- opt.on("--charset=CHARSET", "-c",
- "Specifies the output HTML character-set.",
- "Use --encoding instead of --charset if",
- "available.") do |value|
- @charset = value
- end
-
- opt.separator nil
-
- opt.on("--hyperlink-all", "-A",
- "Generate hyperlinks for all words that",
- "correspond to known methods, even if they",
- "do not start with '#' or '::' (legacy",
- "behavior).") do |value|
- @hyperlink_all = value
- end
-
- opt.separator nil
-
- opt.on("--main=NAME", "-m",
- "NAME will be the initial page displayed.") do |value|
- @main_page = value
- end
-
- opt.separator nil
-
- opt.on("--[no-]line-numbers", "-N",
- "Include line numbers in the source code.",
- "By default, only the number of the first",
- "line is displayed, in a leading comment.") do |value|
- @line_numbers = value
- end
-
- opt.separator nil
-
- opt.on("--show-hash", "-H",
- "A name of the form #name in a comment is a",
- "possible hyperlink to an instance method",
- "name. When displayed, the '#' is removed",
- "unless this option is specified.") do |value|
- @show_hash = value
- end
-
- opt.separator nil
-
- opt.on("--template=NAME", "-T", Template,
- "Set the template used when generating",
- "output. The default depends on the",
- "formatter used.") do |(template, template_dir)|
- @template = template
- @template_dir = template_dir
- end
-
- opt.separator nil
-
- opt.on("--template-stylesheets=FILES", PathArray,
- "Set (or add to) the list of files to",
- "include with the html template.") do |value|
- @template_stylesheets << value
- end
-
- opt.separator nil
-
- opt.on("--title=TITLE", "-t",
- "Set TITLE as the title for HTML output.") do |value|
- @title = value
- end
-
- opt.separator nil
-
- opt.on("--copy-files=PATH", Path,
- "Specify a file or directory to copy static",
- "files from.",
- "If a file is given it will be copied into",
- "the output dir. If a directory is given the",
- "entire directory will be copied.",
- "You can use this multiple times") do |value|
- @static_path << value
- end
-
- opt.separator nil
-
- opt.on("--webcvs=URL", "-W",
- "Specify a URL for linking to a web frontend",
- "to CVS. If the URL contains a '\%s', the",
- "name of the current file will be",
- "substituted; if the URL doesn't contain a",
- "'\%s', the filename will be appended to it.") do |value|
- @webcvs = value
- end
-
- opt.separator nil
- opt.separator "ri generator options:"
- opt.separator nil
-
- opt.on("--ri", "-r",
- "Generate output for use by `ri`. The files",
- "are stored in the '.rdoc' directory under",
- "your home directory unless overridden by a",
- "subsequent --op parameter, so no special",
- "privileges are needed.") do |value|
- check_generator
-
- @generator_name = "ri"
- @op_dir ||= RDoc::RI::Paths::HOMEDIR
- setup_generator
- end
-
- opt.separator nil
-
- opt.on("--ri-site", "-R",
- "Generate output for use by `ri`. The files",
- "are stored in a site-wide directory,",
- "making them accessible to others, so",
- "special privileges are needed.") do |value|
- check_generator
-
- @generator_name = "ri"
- @op_dir = RDoc::RI::Paths.site_dir
- setup_generator
- end
-
- opt.separator nil
- opt.separator "Generic options:"
- opt.separator nil
-
- opt.on("--write-options",
- "Write .rdoc_options to the current",
- "directory with the given options. Not all",
- "options will be used. See RDoc::Options",
- "for details.") do |value|
- @write_options = true
- end
-
- opt.separator nil
-
- opt.on("--[no-]dry-run",
- "Don't write any files") do |value|
- @dry_run = value
- end
-
- opt.separator nil
-
- opt.on("-D", "--[no-]debug",
- "Displays lots on internal stuff.") do |value|
- $DEBUG_RDOC = value
- end
-
- opt.separator nil
-
- opt.on("--[no-]ignore-invalid",
- "Ignore invalid options and continue",
- "(default true).") do |value|
- ignore_invalid = value
- end
-
- opt.separator nil
-
- opt.on("--quiet", "-q",
- "Don't show progress as we parse.") do |value|
- @verbosity = 0
- end
-
- opt.separator nil
-
- opt.on("--verbose", "-V",
- "Display extra progress as RDoc parses") do |value|
- @verbosity = 2
- end
-
- opt.separator nil
-
- opt.on("--version", "-v", "print the version") do
- puts opt.version
- exit
- end
-
- opt.separator nil
-
- opt.on("--help", "-h", "Display this help") do
- RDoc::RDoc::GENERATORS.each_key do |generator|
- setup_generator generator
- end
-
- puts opt.help
- exit
- end
-
- opt.separator nil
- end
-
- setup_generator 'darkfish' if
- argv.grep(/\A(-f|--fmt|--format|-r|-R|--ri|--ri-site)\b/).empty?
-
- deprecated = []
- invalid = []
-
- begin
- opts.parse! argv
- rescue OptionParser::ParseError => e
- if DEPRECATED[e.args.first] then
- deprecated << e.args.first
- elsif %w[--format --ri -r --ri-site -R].include? e.args.first then
- raise
- else
- invalid << e.args.join(' ')
- end
-
- retry
- end
-
- unless @generator then
- @generator = RDoc::Generator::Darkfish
- @generator_name = 'darkfish'
- end
-
- if @pipe and not argv.empty? then
- @pipe = false
- invalid << '-p (with files)'
- end
-
- unless quiet then
- deprecated.each do |opt|
- $stderr.puts 'option ' << opt << ' is deprecated: ' << DEPRECATED[opt]
- end
- end
-
- unless invalid.empty? then
- invalid = "invalid options: #{invalid.join ', '}"
-
- if ignore_invalid then
- unless quiet then
- $stderr.puts invalid
- $stderr.puts '(invalid options are ignored)'
- end
- else
- unless quiet then
- $stderr.puts opts
- end
- $stderr.puts invalid
- exit 1
- end
- end
-
- @files = argv.dup
-
- finish
-
- if @write_options then
- write_options
- exit
- end
-
- self
- end
-
- ##
- # Don't display progress as we process the files
-
- def quiet
- @verbosity.zero?
- end
-
- ##
- # Set quietness to +bool+
-
- def quiet= bool
- @verbosity = bool ? 0 : 1
- end
-
- ##
- # Removes directories from +path+ that are outside the current directory
-
- def sanitize_path path
- require 'pathname'
- dot = Pathname.new('.').expand_path
-
- path.reject do |item|
- path = Pathname.new(item).expand_path
- relative = path.relative_path_from(dot).to_s
- relative.start_with? '..'
- end
- end
-
- ##
- # Set up an output generator for the named +generator_name+.
- #
- # If the found generator responds to :setup_options it will be called with
- # the options instance. This allows generators to add custom options or set
- # default options.
-
- def setup_generator generator_name = @generator_name
- @generator = @generators[generator_name]
-
- unless @generator then
- raise OptionParser::InvalidArgument,
- "Invalid output formatter #{generator_name}"
- end
-
- return if @generator_options.include? @generator
-
- @generator_name = generator_name
- @generator_options << @generator
-
- if @generator.respond_to? :setup_options then
- @option_parser ||= OptionParser.new
- @generator.setup_options self
- end
- end
-
- ##
- # Finds the template dir for +template+
-
- def template_dir_for template
- template_path = File.join 'rdoc', 'generator', 'template', template
-
- $LOAD_PATH.map do |path|
- File.join File.expand_path(path), template_path
- end.find do |dir|
- File.directory? dir
- end
- end
-
- ##
- # This is compatibility code for syck
-
- def to_yaml opts = {} # :nodoc:
- return super if YAML.const_defined?(:ENGINE) and not YAML::ENGINE.syck?
-
- YAML.quick_emit self, opts do |out|
- out.map taguri, to_yaml_style do |map|
- encode_with map
- end
- end
- end
-
- # Sets the minimum visibility of a documented method.
- #
- # Accepts +:public+, +:protected+, +:private+, +:nodoc+, or +:all+.
- #
- # When +:all+ is passed, visibility is set to +:private+, similarly to
- # RDOCOPT="--all", see #visibility for more information.
-
- def visibility= visibility
- case visibility
- when :all
- @visibility = :private
- else
- @visibility = visibility
- end
- end
-
- ##
- # Displays a warning using Kernel#warn if we're being verbose
-
- def warn message
- super message if @verbosity > 1
- end
-
- ##
- # Writes the YAML file .rdoc_options to the current directory containing the
- # parsed options.
-
- def write_options
- RDoc.load_yaml
-
- open '.rdoc_options', 'w' do |io|
- io.set_encoding Encoding::UTF_8 if Object.const_defined? :Encoding
-
- YAML.dump self, io
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/parser.rb b/ruby_2_2/lib/rdoc/parser.rb
deleted file mode 100644
index 4da7f00d3c..0000000000
--- a/ruby_2_2/lib/rdoc/parser.rb
+++ /dev/null
@@ -1,310 +0,0 @@
-# -*- coding: us-ascii -*-
-
-##
-# A parser is simple a class that subclasses RDoc::Parser and implements #scan
-# to fill in an RDoc::TopLevel with parsed data.
-#
-# The initialize method takes an RDoc::TopLevel to fill with parsed content,
-# the name of the file to be parsed, the content of the file, an RDoc::Options
-# object and an RDoc::Stats object to inform the user of parsed items. The
-# scan method is then called to parse the file and must return the
-# RDoc::TopLevel object. By calling super these items will be set for you.
-#
-# In order to be used by RDoc the parser needs to register the file extensions
-# it can parse. Use ::parse_files_matching to register extensions.
-#
-# require 'rdoc'
-#
-# class RDoc::Parser::Xyz < RDoc::Parser
-# parse_files_matching /\.xyz$/
-#
-# def initialize top_level, file_name, content, options, stats
-# super
-#
-# # extra initialization if needed
-# end
-#
-# def scan
-# # parse file and fill in @top_level
-# end
-# end
-
-class RDoc::Parser
-
- @parsers = []
-
- class << self
-
- ##
- # An Array of arrays that maps file extension (or name) regular
- # expressions to parser classes that will parse matching filenames.
- #
- # Use parse_files_matching to register a parser's file extensions.
-
- attr_reader :parsers
-
- end
-
- ##
- # The name of the file being parsed
-
- attr_reader :file_name
-
- ##
- # Alias an extension to another extension. After this call, files ending
- # "new_ext" will be parsed using the same parser as "old_ext"
-
- def self.alias_extension(old_ext, new_ext)
- old_ext = old_ext.sub(/^\.(.*)/, '\1')
- new_ext = new_ext.sub(/^\.(.*)/, '\1')
-
- parser = can_parse_by_name "xxx.#{old_ext}"
- return false unless parser
-
- RDoc::Parser.parsers.unshift [/\.#{new_ext}$/, parser]
-
- true
- end
-
- ##
- # Determines if the file is a "binary" file which basically means it has
- # content that an RDoc parser shouldn't try to consume.
-
- def self.binary?(file)
- return false if file =~ /\.(rdoc|txt)$/
-
- s = File.read(file, 1024) or return false
-
- have_encoding = s.respond_to? :encoding
-
- return true if s[0, 2] == Marshal.dump('')[0, 2] or s.index("\x00")
-
- if have_encoding then
- mode = "r"
- s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024.
- encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1]
- mode = "rb:#{encoding}" if encoding
- s = File.open(file, mode) {|f| f.gets(nil, 1024)}
-
- not s.valid_encoding?
- else
- if 0.respond_to? :fdiv then
- s.count("\x00-\x7F", "^ -~\t\r\n").fdiv(s.size) > 0.3
- else # HACK 1.8.6
- (s.count("\x00-\x7F", "^ -~\t\r\n").to_f / s.size) > 0.3
- end
- end
- end
-
- ##
- # Processes common directives for CodeObjects for the C and Ruby parsers.
- #
- # Applies +directive+'s +value+ to +code_object+, if appropriate
-
- def self.process_directive code_object, directive, value
- warn "RDoc::Parser::process_directive is deprecated and wil be removed in RDoc 4. Use RDoc::Markup::PreProcess#handle_directive instead" if $-w
-
- case directive
- when 'nodoc' then
- code_object.document_self = nil # notify nodoc
- code_object.document_children = value.downcase != 'all'
- when 'doc' then
- code_object.document_self = true
- code_object.force_documentation = true
- when 'yield', 'yields' then
- # remove parameter &block
- code_object.params.sub!(/,?\s*&\w+/, '') if code_object.params
-
- code_object.block_params = value
- when 'arg', 'args' then
- code_object.params = value
- end
- end
-
- ##
- # Checks if +file+ is a zip file in disguise. Signatures from
- # http://www.garykessler.net/library/file_sigs.html
-
- def self.zip? file
- zip_signature = File.read file, 4
-
- zip_signature == "PK\x03\x04" or
- zip_signature == "PK\x05\x06" or
- zip_signature == "PK\x07\x08"
- rescue
- false
- end
-
- ##
- # Return a parser that can handle a particular extension
-
- def self.can_parse file_name
- parser = can_parse_by_name file_name
-
- # HACK Selenium hides a jar file using a .txt extension
- return if parser == RDoc::Parser::Simple and zip? file_name
-
- parser
- end
-
- ##
- # Returns a parser that can handle the extension for +file_name+. This does
- # not depend upon the file being readable.
-
- def self.can_parse_by_name file_name
- _, parser = RDoc::Parser.parsers.find { |regexp,| regexp =~ file_name }
-
- # The default parser must not parse binary files
- ext_name = File.extname file_name
- return parser if ext_name.empty?
-
- if parser == RDoc::Parser::Simple and ext_name !~ /txt|rdoc/ then
- case check_modeline file_name
- when nil, 'rdoc' then # continue
- else return nil
- end
- end
-
- parser
- rescue Errno::EACCES
- end
-
- ##
- # Returns the file type from the modeline in +file_name+
-
- def self.check_modeline file_name
- line = open file_name do |io|
- io.gets
- end
-
- /-\*-\s*(.*?\S)\s*-\*-/ =~ line
-
- return nil unless type = $1
-
- if /;/ =~ type then
- return nil unless /(?:\s|\A)mode:\s*([^\s;]+)/i =~ type
- type = $1
- end
-
- return nil if /coding:/i =~ type
-
- type.downcase
- rescue ArgumentError # invalid byte sequence, etc.
- end
-
- ##
- # Finds and instantiates the correct parser for the given +file_name+ and
- # +content+.
-
- def self.for top_level, file_name, content, options, stats
- return if binary? file_name
-
- parser = use_markup content
-
- unless parser then
- parse_name = file_name
-
- # If no extension, look for shebang
- if file_name !~ /\.\w+$/ && content =~ %r{\A#!(.+)} then
- shebang = $1
- case shebang
- when %r{env\s+ruby}, %r{/ruby}
- parse_name = 'dummy.rb'
- end
- end
-
- parser = can_parse parse_name
- end
-
- return unless parser
-
- content = remove_modeline content
-
- parser.new top_level, file_name, content, options, stats
- rescue SystemCallError
- nil
- end
-
- ##
- # Record which file types this parser can understand.
- #
- # It is ok to call this multiple times.
-
- def self.parse_files_matching(regexp)
- RDoc::Parser.parsers.unshift [regexp, self]
- end
-
- ##
- # Removes an emacs-style modeline from the first line of the document
-
- def self.remove_modeline content
- content.sub(/\A.*-\*-\s*(.*?\S)\s*-\*-.*\r?\n/, '')
- end
-
- ##
- # If there is a <tt>markup: parser_name</tt> comment at the front of the
- # file, use it to determine the parser. For example:
- #
- # # markup: rdoc
- # # Class comment can go here
- #
- # class C
- # end
- #
- # The comment should appear as the first line of the +content+.
- #
- # If the content contains a shebang or editor modeline the comment may
- # appear on the second or third line.
- #
- # Any comment style may be used to hide the markup comment.
-
- def self.use_markup content
- markup = content.lines.first(3).grep(/markup:\s+(\w+)/) { $1 }.first
-
- return unless markup
-
- # TODO Ruby should be returned only when the filename is correct
- return RDoc::Parser::Ruby if %w[tomdoc markdown].include? markup
-
- markup = Regexp.escape markup
-
- _, selected = RDoc::Parser.parsers.find do |_, parser|
- /^#{markup}$/i =~ parser.name.sub(/.*:/, '')
- end
-
- selected
- end
-
- ##
- # Creates a new Parser storing +top_level+, +file_name+, +content+,
- # +options+ and +stats+ in instance variables. In +@preprocess+ an
- # RDoc::Markup::PreProcess object is created which allows processing of
- # directives.
-
- def initialize top_level, file_name, content, options, stats
- @top_level = top_level
- @top_level.parser = self.class
- @store = @top_level.store
-
- @file_name = file_name
- @content = content
- @options = options
- @stats = stats
-
- @preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
- @preprocess.options = @options
- end
-
- autoload :RubyTools, 'rdoc/parser/ruby_tools'
- autoload :Text, 'rdoc/parser/text'
-
-end
-
-# simple must come first in order to show up last in the parsers list
-require 'rdoc/parser/simple'
-require 'rdoc/parser/c'
-require 'rdoc/parser/changelog'
-require 'rdoc/parser/markdown'
-require 'rdoc/parser/rd'
-require 'rdoc/parser/ruby'
-
diff --git a/ruby_2_2/lib/rdoc/parser/c.rb b/ruby_2_2/lib/rdoc/parser/c.rb
deleted file mode 100644
index fd336f5f5b..0000000000
--- a/ruby_2_2/lib/rdoc/parser/c.rb
+++ /dev/null
@@ -1,1229 +0,0 @@
-require 'tsort'
-
-##
-# RDoc::Parser::C attempts to parse C extension files. It looks for
-# the standard patterns that you find in extensions: <tt>rb_define_class,
-# rb_define_method</tt> and so on. It tries to find the corresponding
-# C source for the methods and extract comments, but if we fail
-# we don't worry too much.
-#
-# The comments associated with a Ruby method are extracted from the C
-# comment block associated with the routine that _implements_ that
-# method, that is to say the method whose name is given in the
-# <tt>rb_define_method</tt> call. For example, you might write:
-#
-# /*
-# * Returns a new array that is a one-dimensional flattening of this
-# * array (recursively). That is, for every element that is an array,
-# * extract its elements into the new array.
-# *
-# * s = [ 1, 2, 3 ] #=> [1, 2, 3]
-# * t = [ 4, 5, 6, [7, 8] ] #=> [4, 5, 6, [7, 8]]
-# * a = [ s, t, 9, 10 ] #=> [[1, 2, 3], [4, 5, 6, [7, 8]], 9, 10]
-# * a.flatten #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
-# */
-# static VALUE
-# rb_ary_flatten(ary)
-# VALUE ary;
-# {
-# ary = rb_obj_dup(ary);
-# rb_ary_flatten_bang(ary);
-# return ary;
-# }
-#
-# ...
-#
-# void
-# Init_Array()
-# {
-# ...
-# rb_define_method(rb_cArray, "flatten", rb_ary_flatten, 0);
-#
-# Here RDoc will determine from the rb_define_method line that there's a
-# method called "flatten" in class Array, and will look for the implementation
-# in the method rb_ary_flatten. It will then use the comment from that
-# method in the HTML output. This method must be in the same source file
-# as the rb_define_method.
-#
-# The comment blocks may include special directives:
-#
-# [Document-class: +name+]
-# Documentation for the named class.
-#
-# [Document-module: +name+]
-# Documentation for the named module.
-#
-# [Document-const: +name+]
-# Documentation for the named +rb_define_const+.
-#
-# Constant values can be supplied on the first line of the comment like so:
-#
-# /* 300: The highest possible score in bowling */
-# rb_define_const(cFoo, "PERFECT", INT2FIX(300));
-#
-# The value can contain internal colons so long as they are escaped with a \
-#
-# [Document-global: +name+]
-# Documentation for the named +rb_define_global_const+
-#
-# [Document-variable: +name+]
-# Documentation for the named +rb_define_variable+
-#
-# [Document-method: +method_name+]
-# Documentation for the named method. Use this when the method name is
-# unambiguous.
-#
-# [Document-method: <tt>ClassName::method_name<tt>]
-# Documentation for a singleton method in the given class. Use this when
-# the method name alone is ambiguous.
-#
-# [Document-method: <tt>ClassName#method_name<tt>]
-# Documentation for a instance method in the given class. Use this when the
-# method name alone is ambiguous.
-#
-# [Document-attr: +name+]
-# Documentation for the named attribute.
-#
-# [call-seq: <i>text up to an empty line</i>]
-# Because C source doesn't give descriptive names to Ruby-level parameters,
-# you need to document the calling sequence explicitly
-#
-# In addition, RDoc assumes by default that the C method implementing a
-# Ruby function is in the same source file as the rb_define_method call.
-# If this isn't the case, add the comment:
-#
-# rb_define_method(....); // in filename
-#
-# As an example, we might have an extension that defines multiple classes
-# in its Init_xxx method. We could document them using
-#
-# /*
-# * Document-class: MyClass
-# *
-# * Encapsulate the writing and reading of the configuration
-# * file. ...
-# */
-#
-# /*
-# * Document-method: read_value
-# *
-# * call-seq:
-# * cfg.read_value(key) -> value
-# * cfg.read_value(key} { |key| } -> value
-# *
-# * Return the value corresponding to +key+ from the configuration.
-# * In the second form, if the key isn't found, invoke the
-# * block and return its value.
-# */
-
-class RDoc::Parser::C < RDoc::Parser
-
- parse_files_matching(/\.(?:([CcHh])\1?|c([+xp])\2|y)\z/)
-
- include RDoc::Text
-
- ##
- # Maps C variable names to names of Ruby classes or modules
-
- attr_reader :classes
-
- ##
- # C file the parser is parsing
-
- attr_accessor :content
-
- ##
- # Dependencies from a missing enclosing class to the classes in
- # missing_dependencies that depend upon it.
-
- attr_reader :enclosure_dependencies
-
- ##
- # Maps C variable names to names of Ruby classes (and singleton classes)
-
- attr_reader :known_classes
-
- ##
- # Classes found while parsing the C file that were not yet registered due to
- # a missing enclosing class. These are processed by do_missing
-
- attr_reader :missing_dependencies
-
- ##
- # Maps C variable names to names of Ruby singleton classes
-
- attr_reader :singleton_classes
-
- ##
- # The TopLevel items in the parsed file belong to
-
- attr_reader :top_level
-
- ##
- # Prepares for parsing a C file. See RDoc::Parser#initialize for details on
- # the arguments.
-
- def initialize top_level, file_name, content, options, stats
- super
-
- @known_classes = RDoc::KNOWN_CLASSES.dup
- @content = handle_tab_width handle_ifdefs_in @content
- @file_dir = File.dirname @file_name
-
- @classes = load_variable_map :c_class_variables
- @singleton_classes = load_variable_map :c_singleton_class_variables
-
- # class_variable => { function => [method, ...] }
- @methods = Hash.new { |h, f| h[f] = Hash.new { |i, m| i[m] = [] } }
-
- # missing variable => [handle_class_module arguments]
- @missing_dependencies = {}
-
- # missing enclosure variable => [dependent handle_class_module arguments]
- @enclosure_dependencies = Hash.new { |h, k| h[k] = [] }
- @enclosure_dependencies.instance_variable_set :@missing_dependencies,
- @missing_dependencies
-
- @enclosure_dependencies.extend TSort
-
- def @enclosure_dependencies.tsort_each_node &block
- each_key(&block)
- rescue TSort::Cyclic => e
- cycle_vars = e.message.scan(/"(.*?)"/).flatten
-
- cycle = cycle_vars.sort.map do |var_name|
- delete var_name
-
- var_name, type, mod_name, = @missing_dependencies[var_name]
-
- "#{type} #{mod_name} (#{var_name})"
- end.join ', '
-
- warn "Unable to create #{cycle} due to a cyclic class or module creation"
-
- retry
- end
-
- def @enclosure_dependencies.tsort_each_child node, &block
- fetch(node, []).each(&block)
- end
- end
-
- ##
- # Removes duplicate call-seq entries for methods using the same
- # implementation.
-
- def deduplicate_call_seq
- @methods.each do |var_name, functions|
- class_name = @known_classes[var_name]
- class_obj = find_class var_name, class_name
-
- functions.each_value do |method_names|
- next if method_names.length == 1
-
- method_names.each do |method_name|
- deduplicate_method_name class_obj, method_name
- end
- end
- end
- end
-
- ##
- # If two ruby methods share a C implementation (and comment) this
- # deduplicates the examples in the call_seq for the method to reduce
- # confusion in the output.
-
- def deduplicate_method_name class_obj, method_name # :nodoc:
- return unless
- method = class_obj.method_list.find { |m| m.name == method_name }
- return unless call_seq = method.call_seq
-
- method_name = method_name[0, 1] if method_name =~ /\A\[/
-
- entries = call_seq.split "\n"
-
- matching = entries.select do |entry|
- entry =~ /^\w*\.?#{Regexp.escape method_name}/ or
- entry =~ /\s#{Regexp.escape method_name}\s/
- end
-
- method.call_seq = matching.join "\n"
- end
-
- ##
- # Scans #content for rb_define_alias
-
- def do_aliases
- @content.scan(/rb_define_alias\s*\(
- \s*(\w+),
- \s*"(.+?)",
- \s*"(.+?)"
- \s*\)/xm) do |var_name, new_name, old_name|
- class_name = @known_classes[var_name]
-
- unless class_name then
- @options.warn "Enclosing class or module %p for alias %s %s is not known" % [
- var_name, new_name, old_name]
- next
- end
-
- class_obj = find_class var_name, class_name
-
- al = RDoc::Alias.new '', old_name, new_name, ''
- al.singleton = @singleton_classes.key? var_name
-
- comment = find_alias_comment var_name, new_name, old_name
-
- comment.normalize
-
- al.comment = comment
-
- al.record_location @top_level
-
- class_obj.add_alias al
- @stats.add_alias al
- end
- end
-
- ##
- # Scans #content for rb_attr and rb_define_attr
-
- def do_attrs
- @content.scan(/rb_attr\s*\(
- \s*(\w+),
- \s*([\w"()]+),
- \s*([01]),
- \s*([01]),
- \s*\w+\);/xm) do |var_name, attr_name, read, write|
- handle_attr var_name, attr_name, read, write
- end
-
- @content.scan(%r%rb_define_attr\(
- \s*([\w\.]+),
- \s*"([^"]+)",
- \s*(\d+),
- \s*(\d+)\s*\);
- %xm) do |var_name, attr_name, read, write|
- handle_attr var_name, attr_name, read, write
- end
- end
-
- ##
- # Scans #content for boot_defclass
-
- def do_boot_defclass
- @content.scan(/(\w+)\s*=\s*boot_defclass\s*\(\s*"(\w+?)",\s*(\w+?)\s*\)/) do
- |var_name, class_name, parent|
- parent = nil if parent == "0"
- handle_class_module(var_name, :class, class_name, parent, nil)
- end
- end
-
- ##
- # Scans #content for rb_define_class, boot_defclass, rb_define_class_under
- # and rb_singleton_class
-
- def do_classes
- do_boot_defclass
- do_define_class
- do_define_class_under
- do_singleton_class
- do_struct_define_without_accessor
- end
-
- ##
- # Scans #content for rb_define_variable, rb_define_readonly_variable,
- # rb_define_const and rb_define_global_const
-
- def do_constants
- @content.scan(%r%\Wrb_define_
- ( variable |
- readonly_variable |
- const |
- global_const )
- \s*\(
- (?:\s*(\w+),)?
- \s*"(\w+)",
- \s*(.*?)\s*\)\s*;
- %xm) do |type, var_name, const_name, definition|
- var_name = "rb_cObject" if !var_name or var_name == "rb_mKernel"
- handle_constants type, var_name, const_name, definition
- end
-
- @content.scan(%r%
- \Wrb_curses_define_const
- \s*\(
- \s*
- (\w+)
- \s*
- \)
- \s*;%xm) do |consts|
- const = consts.first
-
- handle_constants 'const', 'mCurses', const, "UINT2NUM(#{const})"
- end
-
- @content.scan(%r%
- \Wrb_file_const
- \s*\(
- \s*
- "([^"]+)",
- \s*
- (.*?)
- \s*
- \)
- \s*;%xm) do |name, value|
- handle_constants 'const', 'rb_mFConst', name, value
- end
- end
-
- ##
- # Scans #content for rb_define_class
-
- def do_define_class
- # The '.' lets us handle SWIG-generated files
- @content.scan(/([\w\.]+)\s* = \s*rb_define_class\s*
- \(
- \s*"(\w+)",
- \s*(\w+)\s*
- \)/mx) do |var_name, class_name, parent|
- handle_class_module(var_name, :class, class_name, parent, nil)
- end
- end
-
- ##
- # Scans #content for rb_define_class_under
-
- def do_define_class_under
- @content.scan(/([\w\.]+)\s* = # var_name
- \s*rb_define_class_under\s*
- \(
- \s* (\w+), # under
- \s* "(\w+)", # class_name
- \s*
- (?:
- ([\w\*\s\(\)\.\->]+) | # parent_name
- rb_path2class\("([\w:]+)"\) # path
- )
- \s*
- \)
- /mx) do |var_name, under, class_name, parent_name, path|
- parent = path || parent_name
-
- handle_class_module var_name, :class, class_name, parent, under
- end
- end
-
- ##
- # Scans #content for rb_define_module
-
- def do_define_module
- @content.scan(/(\w+)\s* = \s*rb_define_module\s*\(\s*"(\w+)"\s*\)/mx) do
- |var_name, class_name|
- handle_class_module(var_name, :module, class_name, nil, nil)
- end
- end
-
- ##
- # Scans #content for rb_define_module_under
-
- def do_define_module_under
- @content.scan(/(\w+)\s* = \s*rb_define_module_under\s*
- \(
- \s*(\w+),
- \s*"(\w+)"
- \s*\)/mx) do |var_name, in_module, class_name|
- handle_class_module(var_name, :module, class_name, nil, in_module)
- end
- end
-
- ##
- # Scans #content for rb_include_module
-
- def do_includes
- @content.scan(/rb_include_module\s*\(\s*(\w+?),\s*(\w+?)\s*\)/) do |c,m|
- next unless cls = @classes[c]
- m = @known_classes[m] || m
-
- comment = RDoc::Comment.new '', @top_level
- incl = cls.add_include RDoc::Include.new(m, comment)
- incl.record_location @top_level
- end
- end
-
- ##
- # Scans #content for rb_define_method, rb_define_singleton_method,
- # rb_define_module_function, rb_define_private_method,
- # rb_define_global_function and define_filetest_function
-
- def do_methods
- @content.scan(%r%rb_define_
- (
- singleton_method |
- method |
- module_function |
- private_method
- )
- \s*\(\s*([\w\.]+),
- \s*"([^"]+)",
- \s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\(|\(METHOD\))?(\w+)\)?,
- \s*(-?\w+)\s*\)
- (?:;\s*/[*/]\s+in\s+(\w+?\.(?:cpp|c|y)))?
- %xm) do |type, var_name, meth_name, function, param_count, source_file|
-
- # Ignore top-object and weird struct.c dynamic stuff
- next if var_name == "ruby_top_self"
- next if var_name == "nstr"
-
- var_name = "rb_cObject" if var_name == "rb_mKernel"
- handle_method(type, var_name, meth_name, function, param_count,
- source_file)
- end
-
- @content.scan(%r%rb_define_global_function\s*\(
- \s*"([^"]+)",
- \s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
- \s*(-?\w+)\s*\)
- (?:;\s*/[*/]\s+in\s+(\w+?\.[cy]))?
- %xm) do |meth_name, function, param_count, source_file|
- handle_method("method", "rb_mKernel", meth_name, function, param_count,
- source_file)
- end
-
- @content.scan(/define_filetest_function\s*\(
- \s*"([^"]+)",
- \s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
- \s*(-?\w+)\s*\)/xm) do |meth_name, function, param_count|
-
- handle_method("method", "rb_mFileTest", meth_name, function, param_count)
- handle_method("singleton_method", "rb_cFile", meth_name, function,
- param_count)
- end
- end
-
- ##
- # Creates classes and module that were missing were defined due to the file
- # order being different than the declaration order.
-
- def do_missing
- return if @missing_dependencies.empty?
-
- @enclosure_dependencies.tsort.each do |in_module|
- arguments = @missing_dependencies.delete in_module
-
- next unless arguments # dependency on existing class
-
- handle_class_module(*arguments)
- end
- end
-
- ##
- # Scans #content for rb_define_module and rb_define_module_under
-
- def do_modules
- do_define_module
- do_define_module_under
- end
-
- ##
- # Scans #content for rb_singleton_class
-
- def do_singleton_class
- @content.scan(/([\w\.]+)\s* = \s*rb_singleton_class\s*
- \(
- \s*(\w+)
- \s*\)/mx) do |sclass_var, class_var|
- handle_singleton sclass_var, class_var
- end
- end
-
- ##
- # Scans #content for struct_define_without_accessor
-
- def do_struct_define_without_accessor
- @content.scan(/([\w\.]+)\s* = \s*rb_struct_define_without_accessor\s*
- \(
- \s*"(\w+)", # Class name
- \s*(\w+), # Parent class
- \s*\w+, # Allocation function
- (\s*"\w+",)* # Attributes
- \s*NULL
- \)/mx) do |var_name, class_name, parent|
- handle_class_module(var_name, :class, class_name, parent, nil)
- end
- end
-
- ##
- # Finds the comment for an alias on +class_name+ from +new_name+ to
- # +old_name+
-
- def find_alias_comment class_name, new_name, old_name
- content =~ %r%((?>/\*.*?\*/\s+))
- rb_define_alias\(\s*#{Regexp.escape class_name}\s*,
- \s*"#{Regexp.escape new_name}"\s*,
- \s*"#{Regexp.escape old_name}"\s*\);%xm
-
- RDoc::Comment.new($1 || '', @top_level)
- end
-
- ##
- # Finds a comment for rb_define_attr, rb_attr or Document-attr.
- #
- # +var_name+ is the C class variable the attribute is defined on.
- # +attr_name+ is the attribute's name.
- #
- # +read+ and +write+ are the read/write flags ('1' or '0'). Either both or
- # neither must be provided.
-
- def find_attr_comment var_name, attr_name, read = nil, write = nil
- attr_name = Regexp.escape attr_name
-
- rw = if read and write then
- /\s*#{read}\s*,\s*#{write}\s*/xm
- else
- /.*?/m
- end
-
- comment = if @content =~ %r%((?>/\*.*?\*/\s+))
- rb_define_attr\((?:\s*#{var_name},)?\s*
- "#{attr_name}"\s*,
- #{rw}\)\s*;%xm then
- $1
- elsif @content =~ %r%((?>/\*.*?\*/\s+))
- rb_attr\(\s*#{var_name}\s*,
- \s*#{attr_name}\s*,
- #{rw},.*?\)\s*;%xm then
- $1
- elsif @content =~ %r%(/\*.*?(?:\s*\*\s*)?)
- Document-attr:\s#{attr_name}\s*?\n
- ((?>(.|\n)*?\*/))%x then
- "#{$1}\n#{$2}"
- else
- ''
- end
-
- RDoc::Comment.new comment, @top_level
- end
-
- ##
- # Find the C code corresponding to a Ruby method
-
- def find_body class_name, meth_name, meth_obj, file_content, quiet = false
- case file_content
- when %r%((?>/\*.*?\*/\s*)?)
- ((?:(?:\w+)\s+)?
- (?:intern\s+)?VALUE\s+#{meth_name}
- \s*(\([^)]*\))([^;]|$))%xm then
- comment = RDoc::Comment.new $1, @top_level
- body = $2
- offset, = $~.offset(2)
-
- comment.remove_private if comment
-
- # try to find the whole body
- body = $& if /#{Regexp.escape body}[^(]*?\{.*?^\}/m =~ file_content
-
- # The comment block may have been overridden with a 'Document-method'
- # block. This happens in the interpreter when multiple methods are
- # vectored through to the same C method but those methods are logically
- # distinct (for example Kernel.hash and Kernel.object_id share the same
- # implementation
-
- override_comment = find_override_comment class_name, meth_obj
- comment = override_comment if override_comment
-
- comment.normalize
- find_modifiers comment, meth_obj if comment
-
- #meth_obj.params = params
- meth_obj.start_collecting_tokens
- tk = RDoc::RubyToken::Token.new nil, 1, 1
- tk.set_text body
- meth_obj.add_token tk
- meth_obj.comment = comment
- meth_obj.offset = offset
- meth_obj.line = file_content[0, offset].count("\n") + 1
-
- body
- when %r%((?>/\*.*?\*/\s*))^\s*(\#\s*define\s+#{meth_name}\s+(\w+))%m then
- comment = RDoc::Comment.new $1, @top_level
- body = $2
- offset = $~.offset(2).first
-
- find_body class_name, $3, meth_obj, file_content, true
-
- comment.normalize
- find_modifiers comment, meth_obj
-
- meth_obj.start_collecting_tokens
- tk = RDoc::RubyToken::Token.new nil, 1, 1
- tk.set_text body
- meth_obj.add_token tk
- meth_obj.comment = comment
- meth_obj.offset = offset
- meth_obj.line = file_content[0, offset].count("\n") + 1
-
- body
- when %r%^\s*\#\s*define\s+#{meth_name}\s+(\w+)%m then
- # with no comment we hope the aliased definition has it and use it's
- # definition
-
- body = find_body(class_name, $1, meth_obj, file_content, true)
-
- return body if body
-
- @options.warn "No definition for #{meth_name}"
- false
- else # No body, but might still have an override comment
- comment = find_override_comment class_name, meth_obj
-
- if comment then
- comment.normalize
- find_modifiers comment, meth_obj
- meth_obj.comment = comment
-
- ''
- else
- @options.warn "No definition for #{meth_name}"
- false
- end
- end
- end
-
- ##
- # Finds a RDoc::NormalClass or RDoc::NormalModule for +raw_name+
-
- def find_class(raw_name, name)
- unless @classes[raw_name]
- if raw_name =~ /^rb_m/
- container = @top_level.add_module RDoc::NormalModule, name
- else
- container = @top_level.add_class RDoc::NormalClass, name
- end
-
- container.record_location @top_level
- @classes[raw_name] = container
- end
- @classes[raw_name]
- end
-
- ##
- # Look for class or module documentation above Init_+class_name+(void),
- # in a Document-class +class_name+ (or module) comment or above an
- # rb_define_class (or module). If a comment is supplied above a matching
- # Init_ and a rb_define_class the Init_ comment is used.
- #
- # /*
- # * This is a comment for Foo
- # */
- # Init_Foo(void) {
- # VALUE cFoo = rb_define_class("Foo", rb_cObject);
- # }
- #
- # /*
- # * Document-class: Foo
- # * This is a comment for Foo
- # */
- # Init_foo(void) {
- # VALUE cFoo = rb_define_class("Foo", rb_cObject);
- # }
- #
- # /*
- # * This is a comment for Foo
- # */
- # VALUE cFoo = rb_define_class("Foo", rb_cObject);
-
- def find_class_comment class_name, class_mod
- comment = nil
-
- if @content =~ %r%
- ((?>/\*.*?\*/\s+))
- (static\s+)?
- void\s+
- Init_#{class_name}\s*(?:_\(\s*)?\(\s*(?:void\s*)?\)%xmi then
- comment = $1.sub(%r%Document-(?:class|module):\s+#{class_name}%, '')
- elsif @content =~ %r%Document-(?:class|module):\s+#{class_name}\s*?
- (?:<\s+[:,\w]+)?\n((?>.*?\*/))%xm then
- comment = "/*\n#{$1}"
- elsif @content =~ %r%((?>/\*.*?\*/\s+))
- ([\w\.\s]+\s* = \s+)?rb_define_(class|module)[\t (]*?"(#{class_name})"%xm then
- comment = $1
- elsif @content =~ %r%((?>/\*.*?\*/\s+))
- ([\w\. \t]+ = \s+)?rb_define_(class|module)_under[\t\w, (]*?"(#{class_name.split('::').last})"%xm then
- comment = $1
- else
- comment = ''
- end
-
- comment = RDoc::Comment.new comment, @top_level
- comment.normalize
-
- look_for_directives_in class_mod, comment
-
- class_mod.add_comment comment, @top_level
- end
-
- ##
- # Finds a comment matching +type+ and +const_name+ either above the
- # comment or in the matching Document- section.
-
- def find_const_comment(type, const_name, class_name = nil)
- comment = if @content =~ %r%((?>^\s*/\*.*?\*/\s+))
- rb_define_#{type}\((?:\s*(\w+),)?\s*
- "#{const_name}"\s*,
- .*?\)\s*;%xmi then
- $1
- elsif class_name and
- @content =~ %r%Document-(?:const|global|variable):\s
- #{class_name}::#{const_name}
- \s*?\n((?>.*?\*/))%xm then
- "/*\n#{$1}"
- elsif @content =~ %r%Document-(?:const|global|variable):
- \s#{const_name}
- \s*?\n((?>.*?\*/))%xm then
- "/*\n#{$1}"
- else
- ''
- end
-
- RDoc::Comment.new comment, @top_level
- end
-
- ##
- # Handles modifiers in +comment+ and updates +meth_obj+ as appropriate.
-
- def find_modifiers comment, meth_obj
- comment.normalize
- comment.extract_call_seq meth_obj
-
- look_for_directives_in meth_obj, comment
- end
-
- ##
- # Finds a <tt>Document-method</tt> override for +meth_obj+ on +class_name+
-
- def find_override_comment class_name, meth_obj
- name = Regexp.escape meth_obj.name
- prefix = Regexp.escape meth_obj.name_prefix
-
- comment = if @content =~ %r%Document-method:
- \s+#{class_name}#{prefix}#{name}
- \s*?\n((?>.*?\*/))%xm then
- "/*#{$1}"
- elsif @content =~ %r%Document-method:
- \s#{name}\s*?\n((?>.*?\*/))%xm then
- "/*#{$1}"
- end
-
- return unless comment
-
- RDoc::Comment.new comment, @top_level
- end
-
- ##
- # Creates a new RDoc::Attr +attr_name+ on class +var_name+ that is either
- # +read+, +write+ or both
-
- def handle_attr(var_name, attr_name, read, write)
- rw = ''
- rw << 'R' if '1' == read
- rw << 'W' if '1' == write
-
- class_name = @known_classes[var_name]
-
- return unless class_name
-
- class_obj = find_class var_name, class_name
-
- return unless class_obj
-
- comment = find_attr_comment var_name, attr_name
- comment.normalize
-
- name = attr_name.gsub(/rb_intern\("([^"]+)"\)/, '\1')
-
- attr = RDoc::Attr.new '', name, rw, comment
-
- attr.record_location @top_level
- class_obj.add_attribute attr
- @stats.add_attribute attr
- end
-
- ##
- # Creates a new RDoc::NormalClass or RDoc::NormalModule based on +type+
- # named +class_name+ in +parent+ which was assigned to the C +var_name+.
-
- def handle_class_module(var_name, type, class_name, parent, in_module)
- parent_name = @known_classes[parent] || parent
-
- if in_module then
- enclosure = @classes[in_module] || @store.find_c_enclosure(in_module)
-
- if enclosure.nil? and enclosure = @known_classes[in_module] then
- enc_type = /^rb_m/ =~ in_module ? :module : :class
- handle_class_module in_module, enc_type, enclosure, nil, nil
- enclosure = @classes[in_module]
- end
-
- unless enclosure then
- @enclosure_dependencies[in_module] << var_name
- @missing_dependencies[var_name] =
- [var_name, type, class_name, parent, in_module]
-
- return
- end
- else
- enclosure = @top_level
- end
-
- if type == :class then
- full_name = if RDoc::ClassModule === enclosure then
- enclosure.full_name + "::#{class_name}"
- else
- class_name
- end
-
- if @content =~ %r%Document-class:\s+#{full_name}\s*<\s+([:,\w]+)% then
- parent_name = $1
- end
-
- cm = enclosure.add_class RDoc::NormalClass, class_name, parent_name
- else
- cm = enclosure.add_module RDoc::NormalModule, class_name
- end
-
- cm.record_location enclosure.top_level
-
- find_class_comment cm.full_name, cm
-
- case cm
- when RDoc::NormalClass
- @stats.add_class cm
- when RDoc::NormalModule
- @stats.add_module cm
- end
-
- @classes[var_name] = cm
- @known_classes[var_name] = cm.full_name
- @store.add_c_enclosure var_name, cm
- end
-
- ##
- # Adds constants. By providing some_value: at the start of the comment you
- # can override the C value of the comment to give a friendly definition.
- #
- # /* 300: The perfect score in bowling */
- # rb_define_const(cFoo, "PERFECT", INT2FIX(300);
- #
- # Will override <tt>INT2FIX(300)</tt> with the value +300+ in the output
- # RDoc. Values may include quotes and escaped colons (\:).
-
- def handle_constants(type, var_name, const_name, definition)
- class_name = @known_classes[var_name]
-
- return unless class_name
-
- class_obj = find_class var_name, class_name
-
- unless class_obj then
- @options.warn 'Enclosing class or module %p is not known' % [const_name]
- return
- end
-
- comment = find_const_comment type, const_name, class_name
- comment.normalize
-
- # In the case of rb_define_const, the definition and comment are in
- # "/* definition: comment */" form. The literal ':' and '\' characters
- # can be escaped with a backslash.
- if type.downcase == 'const' then
- no_match, new_definition, new_comment = comment.text.split(/(\A.*):/)
-
- if no_match and no_match.empty? then
- if new_definition.empty? then # Default to literal C definition
- new_definition = definition
- else
- new_definition.gsub!("\:", ":")
- new_definition.gsub!("\\", '\\')
- end
-
- new_definition.sub!(/\A(\s+)/, '')
-
- new_comment = "#{$1}#{new_comment.lstrip}"
-
- new_comment = RDoc::Comment.new new_comment, @top_level
-
- con = RDoc::Constant.new const_name, new_definition, new_comment
- else
- con = RDoc::Constant.new const_name, definition, comment
- end
- else
- con = RDoc::Constant.new const_name, definition, comment
- end
-
- con.record_location @top_level
- @stats.add_constant con
- class_obj.add_constant con
- end
-
- ##
- # Removes #ifdefs that would otherwise confuse us
-
- def handle_ifdefs_in(body)
- body.gsub(/^#ifdef HAVE_PROTOTYPES.*?#else.*?\n(.*?)#endif.*?\n/m, '\1')
- end
-
- ##
- # Adds an RDoc::AnyMethod +meth_name+ defined on a class or module assigned
- # to +var_name+. +type+ is the type of method definition function used.
- # +singleton_method+ and +module_function+ create a singleton method.
-
- def handle_method(type, var_name, meth_name, function, param_count,
- source_file = nil)
- class_name = @known_classes[var_name]
- singleton = @singleton_classes.key? var_name
-
- @methods[var_name][function] << meth_name
-
- return unless class_name
-
- class_obj = find_class var_name, class_name
-
- if class_obj then
- if meth_name == 'initialize' then
- meth_name = 'new'
- singleton = true
- type = 'method' # force public
- end
-
- meth_obj = RDoc::AnyMethod.new '', meth_name
- meth_obj.c_function = function
- meth_obj.singleton =
- singleton || %w[singleton_method module_function].include?(type)
-
- p_count = Integer(param_count) rescue -1
-
- if source_file then
- file_name = File.join @file_dir, source_file
-
- if File.exist? file_name then
- file_content = File.read file_name
- else
- @options.warn "unknown source #{source_file} for #{meth_name} in #{@file_name}"
- end
- else
- file_content = @content
- end
-
- body = find_body class_name, function, meth_obj, file_content
-
- if body and meth_obj.document_self then
- meth_obj.params = if p_count < -1 then # -2 is Array
- '(*args)'
- elsif p_count == -1 then # argc, argv
- rb_scan_args body
- else
- "(#{(1..p_count).map { |i| "p#{i}" }.join ', '})"
- end
-
-
- meth_obj.record_location @top_level
- class_obj.add_method meth_obj
- @stats.add_method meth_obj
- meth_obj.visibility = :private if 'private_method' == type
- end
- end
- end
-
- ##
- # Registers a singleton class +sclass_var+ as a singleton of +class_var+
-
- def handle_singleton sclass_var, class_var
- class_name = @known_classes[class_var]
-
- @known_classes[sclass_var] = class_name
- @singleton_classes[sclass_var] = class_name
- end
-
- ##
- # Normalizes tabs in +body+
-
- def handle_tab_width(body)
- if /\t/ =~ body
- tab_width = @options.tab_width
- body.split(/\n/).map do |line|
- 1 while line.gsub!(/\t+/) do
- ' ' * (tab_width * $&.length - $`.length % tab_width)
- end && $~
- line
- end.join "\n"
- else
- body
- end
- end
-
- ##
- # Loads the variable map with the given +name+ from the RDoc::Store, if
- # present.
-
- def load_variable_map map_name
- return {} unless files = @store.cache[map_name]
- return {} unless name_map = files[@file_name]
-
- class_map = {}
-
- name_map.each do |variable, name|
- next unless mod = @store.find_class_or_module(name)
-
- class_map[variable] = if map_name == :c_class_variables then
- mod
- else
- name
- end
- @known_classes[variable] = name
- end
-
- class_map
- end
-
- ##
- # Look for directives in a normal comment block:
- #
- # /*
- # * :title: My Awesome Project
- # */
- #
- # This method modifies the +comment+
-
- def look_for_directives_in context, comment
- @preprocess.handle comment, context do |directive, param|
- case directive
- when 'main' then
- @options.main_page = param
- ''
- when 'title' then
- @options.default_title = param if @options.respond_to? :default_title=
- ''
- end
- end
-
- comment
- end
-
- ##
- # Extracts parameters from the +method_body+ and returns a method
- # parameter string. Follows 1.9.3dev's scan-arg-spec, see README.EXT
-
- def rb_scan_args method_body
- method_body =~ /rb_scan_args\((.*?)\)/m
- return '(*args)' unless $1
-
- $1.split(/,/)[2] =~ /"(.*?)"/ # format argument
- format = $1.split(//)
-
- lead = opt = trail = 0
-
- if format.first =~ /\d/ then
- lead = $&.to_i
- format.shift
- if format.first =~ /\d/ then
- opt = $&.to_i
- format.shift
- if format.first =~ /\d/ then
- trail = $&.to_i
- format.shift
- block_arg = true
- end
- end
- end
-
- if format.first == '*' and not block_arg then
- var = true
- format.shift
- if format.first =~ /\d/ then
- trail = $&.to_i
- format.shift
- end
- end
-
- if format.first == ':' then
- hash = true
- format.shift
- end
-
- if format.first == '&' then
- block = true
- format.shift
- end
-
- # if the format string is not empty there's a bug in the C code, ignore it
-
- args = []
- position = 1
-
- (1...(position + lead)).each do |index|
- args << "p#{index}"
- end
-
- position += lead
-
- (position...(position + opt)).each do |index|
- args << "p#{index} = v#{index}"
- end
-
- position += opt
-
- if var then
- args << '*args'
- position += 1
- end
-
- (position...(position + trail)).each do |index|
- args << "p#{index}"
- end
-
- position += trail
-
- if hash then
- args << "p#{position} = {}"
- end
-
- args << '&block' if block
-
- "(#{args.join ', '})"
- end
-
- ##
- # Removes lines that are commented out that might otherwise get picked up
- # when scanning for classes and methods
-
- def remove_commented_out_lines
- @content.gsub!(%r%//.*rb_define_%, '//')
- end
-
- ##
- # Extracts the classes, modules, methods, attributes, constants and aliases
- # from a C file and returns an RDoc::TopLevel for this file
-
- def scan
- remove_commented_out_lines
-
- do_modules
- do_classes
- do_missing
-
- do_constants
- do_methods
- do_includes
- do_aliases
- do_attrs
-
- deduplicate_call_seq
-
- @store.add_c_variables self
-
- @top_level
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/parser/changelog.rb b/ruby_2_2/lib/rdoc/parser/changelog.rb
deleted file mode 100644
index a3567c1f81..0000000000
--- a/ruby_2_2/lib/rdoc/parser/changelog.rb
+++ /dev/null
@@ -1,198 +0,0 @@
-require 'time'
-
-##
-# A ChangeLog file parser.
-#
-# This parser converts a ChangeLog into an RDoc::Markup::Document. When
-# viewed as HTML a ChangeLog page will have an entry for each day's entries in
-# the sidebar table of contents.
-#
-# This parser is meant to parse the MRI ChangeLog, but can be used to parse any
-# {GNU style Change
-# Log}[http://www.gnu.org/prep/standards/html_node/Style-of-Change-Logs.html].
-
-class RDoc::Parser::ChangeLog < RDoc::Parser
-
- include RDoc::Parser::Text
-
- parse_files_matching(/(\/|\\|\A)ChangeLog[^\/\\]*\z/)
-
- ##
- # Attaches the +continuation+ of the previous line to the +entry_body+.
- #
- # Continued function listings are joined together as a single entry.
- # Continued descriptions are joined to make a single paragraph.
-
- def continue_entry_body entry_body, continuation
- return unless last = entry_body.last
-
- if last =~ /\)\s*\z/ and continuation =~ /\A\(/ then
- last.sub!(/\)\s*\z/, ',')
- continuation.sub!(/\A\(/, '')
- end
-
- if last =~ /\s\z/ then
- last << continuation
- else
- last << ' ' << continuation
- end
- end
-
- ##
- # Creates an RDoc::Markup::Document given the +groups+ of ChangeLog entries.
-
- def create_document groups
- doc = RDoc::Markup::Document.new
- doc.omit_headings_below = 2
- doc.file = @top_level
-
- doc << RDoc::Markup::Heading.new(1, File.basename(@file_name))
- doc << RDoc::Markup::BlankLine.new
-
- groups.sort_by do |day,| day end.reverse_each do |day, entries|
- doc << RDoc::Markup::Heading.new(2, day.dup)
- doc << RDoc::Markup::BlankLine.new
-
- doc.concat create_entries entries
- end
-
- doc
- end
-
- ##
- # Returns a list of ChangeLog entries an RDoc::Markup nodes for the given
- # +entries+.
-
- def create_entries entries
- out = []
-
- entries.each do |entry, items|
- out << RDoc::Markup::Heading.new(3, entry)
- out << RDoc::Markup::BlankLine.new
-
- out << create_items(items)
- end
-
- out
- end
-
- ##
- # Returns an RDoc::Markup::List containing the given +items+ in the
- # ChangeLog
-
- def create_items items
- list = RDoc::Markup::List.new :NOTE
-
- items.each do |item|
- item =~ /\A(.*?(?:\([^)]+\))?):\s*/
-
- title = $1
- body = $'
-
- paragraph = RDoc::Markup::Paragraph.new body
- list_item = RDoc::Markup::ListItem.new title, paragraph
- list << list_item
- end
-
- list
- end
-
- ##
- # Groups +entries+ by date.
-
- def group_entries entries
- entries.group_by do |title, _|
- begin
- Time.parse(title).strftime '%Y-%m-%d'
- rescue NoMethodError, ArgumentError
- time, = title.split ' ', 2
- Time.parse(time).strftime '%Y-%m-%d'
- end
- end
- end
-
- ##
- # Parses the entries in the ChangeLog.
- #
- # Returns an Array of each ChangeLog entry in order of parsing.
- #
- # A ChangeLog entry is an Array containing the ChangeLog title (date and
- # committer) and an Array of ChangeLog items (file and function changed with
- # description).
- #
- # An example result would be:
- #
- # [ 'Tue Dec 4 08:33:46 2012 Eric Hodel <drbrain@segment7.net>',
- # [ 'README.EXT: Converted to RDoc format',
- # 'README.EXT.ja: ditto']]
-
- def parse_entries
- entries = []
- entry_name = nil
- entry_body = []
-
- @content.each_line do |line|
- case line
- when /^\s*$/ then
- next
- when /^\w.*/ then
- entries << [entry_name, entry_body] if entry_name
-
- entry_name = $&
-
- begin
- time = Time.parse entry_name
- # HACK Ruby 1.8 does not raise ArgumentError for Time.parse "Other"
- entry_name = nil unless entry_name =~ /#{time.year}/
- rescue NoMethodError
- # HACK Ruby 2.1.2 and earlier raises NoMethodError if time part is absent
- entry_name.split ' ', 2
- rescue ArgumentError
- if /out of range/ =~ $!.message
- Time.parse(entry_name.split(' ', 2)[0]) rescue entry_name = nil
- else
- entry_name = nil
- end
- end
-
- entry_body = []
- when /^(\t| {8})?\*\s*(.*)/ then # "\t* file.c (func): ..."
- entry_body << $2
- when /^(\t| {8})?\s*(\(.*)/ then # "\t(func): ..."
- entry = $2
-
- if entry_body.last =~ /:/ then
- entry_body << entry
- else
- continue_entry_body entry_body, entry
- end
- when /^(\t| {8})?\s*(.*)/ then
- continue_entry_body entry_body, $2
- end
- end
-
- entries << [entry_name, entry_body] if entry_name
-
- entries.reject! do |(entry,_)|
- entry == nil
- end
-
- entries
- end
-
- ##
- # Converts the ChangeLog into an RDoc::Markup::Document
-
- def scan
- entries = parse_entries
- grouped_entries = group_entries entries
-
- doc = create_document grouped_entries
-
- @top_level.comment = doc
-
- @top_level
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/parser/markdown.rb b/ruby_2_2/lib/rdoc/parser/markdown.rb
deleted file mode 100644
index 6fd88cf614..0000000000
--- a/ruby_2_2/lib/rdoc/parser/markdown.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-##
-# Parse a Markdown format file. The parsed RDoc::Markup::Document is attached
-# as a file comment.
-
-class RDoc::Parser::Markdown < RDoc::Parser
-
- include RDoc::Parser::Text
-
- parse_files_matching(/\.(md|markdown)(?:\.[^.]+)?$/)
-
- ##
- # Creates an Markdown-format TopLevel for the given file.
-
- def scan
- comment = RDoc::Comment.new @content, @top_level
- comment.format = 'markdown'
-
- @top_level.comment = comment
- end
-
-end
-
-
diff --git a/ruby_2_2/lib/rdoc/parser/rd.rb b/ruby_2_2/lib/rdoc/parser/rd.rb
deleted file mode 100644
index 09069ae297..0000000000
--- a/ruby_2_2/lib/rdoc/parser/rd.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-##
-# Parse a RD format file. The parsed RDoc::Markup::Document is attached as a
-# file comment.
-
-class RDoc::Parser::RD < RDoc::Parser
-
- include RDoc::Parser::Text
-
- parse_files_matching(/\.rd(?:\.[^.]+)?$/)
-
- ##
- # Creates an rd-format TopLevel for the given file.
-
- def scan
- comment = RDoc::Comment.new @content, @top_level
- comment.format = 'rd'
-
- @top_level.comment = comment
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/parser/ruby.rb b/ruby_2_2/lib/rdoc/parser/ruby.rb
deleted file mode 100644
index ce1083edc7..0000000000
--- a/ruby_2_2/lib/rdoc/parser/ruby.rb
+++ /dev/null
@@ -1,2160 +0,0 @@
-##
-# This file contains stuff stolen outright from:
-#
-# rtags.rb -
-# ruby-lex.rb - ruby lexcal analyzer
-# ruby-token.rb - ruby tokens
-# by Keiju ISHITSUKA (Nippon Rational Inc.)
-#
-
-$TOKEN_DEBUG ||= nil
-
-##
-# Extracts code elements from a source file returning a TopLevel object
-# containing the constituent file elements.
-#
-# This file is based on rtags
-#
-# RubyParser understands how to document:
-# * classes
-# * modules
-# * methods
-# * constants
-# * aliases
-# * private, public, protected
-# * private_class_function, public_class_function
-# * module_function
-# * attr, attr_reader, attr_writer, attr_accessor
-# * extra accessors given on the command line
-# * metaprogrammed methods
-# * require
-# * include
-#
-# == Method Arguments
-#
-#--
-# NOTE: I don't think this works, needs tests, remove the paragraph following
-# this block when known to work
-#
-# The parser extracts the arguments from the method definition. You can
-# override this with a custom argument definition using the :args: directive:
-#
-# ##
-# # This method tries over and over until it is tired
-#
-# def go_go_go(thing_to_try, tries = 10) # :args: thing_to_try
-# puts thing_to_try
-# go_go_go thing_to_try, tries - 1
-# end
-#
-# If you have a more-complex set of overrides you can use the :call-seq:
-# directive:
-#++
-#
-# The parser extracts the arguments from the method definition. You can
-# override this with a custom argument definition using the :call-seq:
-# directive:
-#
-# ##
-# # This method can be called with a range or an offset and length
-# #
-# # :call-seq:
-# # my_method(Range)
-# # my_method(offset, length)
-#
-# def my_method(*args)
-# end
-#
-# The parser extracts +yield+ expressions from method bodies to gather the
-# yielded argument names. If your method manually calls a block instead of
-# yielding or you want to override the discovered argument names use
-# the :yields: directive:
-#
-# ##
-# # My method is awesome
-#
-# def my_method(&block) # :yields: happy, times
-# block.call 1, 2
-# end
-#
-# == Metaprogrammed Methods
-#
-# To pick up a metaprogrammed method, the parser looks for a comment starting
-# with '##' before an identifier:
-#
-# ##
-# # This is a meta-programmed method!
-#
-# add_my_method :meta_method, :arg1, :arg2
-#
-# The parser looks at the token after the identifier to determine the name, in
-# this example, :meta_method. If a name cannot be found, a warning is printed
-# and 'unknown is used.
-#
-# You can force the name of a method using the :method: directive:
-#
-# ##
-# # :method: some_method!
-#
-# By default, meta-methods are instance methods. To indicate that a method is
-# a singleton method instead use the :singleton-method: directive:
-#
-# ##
-# # :singleton-method:
-#
-# You can also use the :singleton-method: directive with a name:
-#
-# ##
-# # :singleton-method: some_method!
-#
-# You can define arguments for metaprogrammed methods via either the
-# :call-seq:, :arg: or :args: directives.
-#
-# Additionally you can mark a method as an attribute by
-# using :attr:, :attr_reader:, :attr_writer: or :attr_accessor:. Just like
-# for :method:, the name is optional.
-#
-# ##
-# # :attr_reader: my_attr_name
-#
-# == Hidden methods and attributes
-#
-# You can provide documentation for methods that don't appear using
-# the :method:, :singleton-method: and :attr: directives:
-#
-# ##
-# # :attr_writer: ghost_writer
-# # There is an attribute here, but you can't see it!
-#
-# ##
-# # :method: ghost_method
-# # There is a method here, but you can't see it!
-#
-# ##
-# # this is a comment for a regular method
-#
-# def regular_method() end
-#
-# Note that by default, the :method: directive will be ignored if there is a
-# standard rdocable item following it.
-
-class RDoc::Parser::Ruby < RDoc::Parser
-
- parse_files_matching(/\.rbw?$/)
-
- include RDoc::RubyToken
- include RDoc::TokenStream
- include RDoc::Parser::RubyTools
-
- ##
- # RDoc::NormalClass type
-
- NORMAL = "::"
-
- ##
- # RDoc::SingleClass type
-
- SINGLE = "<<"
-
- ##
- # Creates a new Ruby parser.
-
- def initialize(top_level, file_name, content, options, stats)
- super
-
- @size = 0
- @token_listeners = nil
- @scanner = RDoc::RubyLex.new content, @options
- @scanner.exception_on_syntax_error = false
- @prev_seek = nil
- @markup = @options.markup
- @track_visibility = :nodoc != @options.visibility
-
- @encoding = nil
- @encoding = @options.encoding if Object.const_defined? :Encoding
-
- reset
- end
-
- ##
- # Retrieves the read token stream and replaces +pattern+ with +replacement+
- # using gsub. If the result is only a ";" returns an empty string.
-
- def get_tkread_clean pattern, replacement # :nodoc:
- read = get_tkread.gsub(pattern, replacement).strip
- return '' if read == ';'
- read
- end
-
- ##
- # Extracts the visibility information for the visibility token +tk+
- # and +single+ class type identifier.
- #
- # Returns the visibility type (a string), the visibility (a symbol) and
- # +singleton+ if the methods following should be converted to singleton
- # methods.
-
- def get_visibility_information tk, single # :nodoc:
- vis_type = tk.name
- singleton = single == SINGLE
-
- vis =
- case vis_type
- when 'private' then :private
- when 'protected' then :protected
- when 'public' then :public
- when 'private_class_method' then
- singleton = true
- :private
- when 'public_class_method' then
- singleton = true
- :public
- when 'module_function' then
- singleton = true
- :public
- else
- raise RDoc::Error, "Invalid visibility: #{tk.name}"
- end
-
- return vis_type, vis, singleton
- end
-
- ##
- # Look for the first comment in a file that isn't a shebang line.
-
- def collect_first_comment
- skip_tkspace
- comment = ''
- comment.force_encoding @encoding if @encoding
- first_line = true
- first_comment_tk_class = nil
-
- tk = get_tk
-
- while TkCOMMENT === tk
- if first_line and tk.text =~ /\A#!/ then
- skip_tkspace
- tk = get_tk
- elsif first_line and tk.text =~ /\A#\s*-\*-/ then
- first_line = false
- skip_tkspace
- tk = get_tk
- else
- break if first_comment_tk_class and not first_comment_tk_class === tk
- first_comment_tk_class = tk.class
-
- first_line = false
- comment << tk.text << "\n"
- tk = get_tk
-
- if TkNL === tk then
- skip_tkspace false
- tk = get_tk
- end
- end
- end
-
- unget_tk tk
-
- new_comment comment
- end
-
- ##
- # Consumes trailing whitespace from the token stream
-
- def consume_trailing_spaces # :nodoc:
- get_tkread
- skip_tkspace false
- end
-
- ##
- # Creates a new attribute in +container+ with +name+.
-
- def create_attr container, single, name, rw, comment # :nodoc:
- att = RDoc::Attr.new get_tkread, name, rw, comment, single == SINGLE
- record_location att
-
- container.add_attribute att
- @stats.add_attribute att
-
- att
- end
-
- ##
- # Creates a module alias in +container+ at +rhs_name+ (or at the top-level
- # for "::") with the name from +constant+.
-
- def create_module_alias container, constant, rhs_name # :nodoc:
- mod = if rhs_name =~ /^::/ then
- @store.find_class_or_module rhs_name
- else
- container.find_module_named rhs_name
- end
-
- container.add_module_alias mod, constant.name, @top_level if mod
- end
-
- ##
- # Aborts with +msg+
-
- def error(msg)
- msg = make_message msg
-
- abort msg
- end
-
- ##
- # Looks for a true or false token. Returns false if TkFALSE or TkNIL are
- # found.
-
- def get_bool
- skip_tkspace
- tk = get_tk
- case tk
- when TkTRUE
- true
- when TkFALSE, TkNIL
- false
- else
- unget_tk tk
- true
- end
- end
-
- ##
- # Look for the name of a class of module (optionally with a leading :: or
- # with :: separated named) and return the ultimate name, the associated
- # container, and the given name (with the ::).
-
- def get_class_or_module container, ignore_constants = false
- skip_tkspace
- name_t = get_tk
- given_name = ''
-
- # class ::A -> A is in the top level
- case name_t
- when TkCOLON2, TkCOLON3 then # bug
- name_t = get_tk
- container = @top_level
- given_name << '::'
- end
-
- skip_tkspace false
- given_name << name_t.name
-
- while TkCOLON2 === peek_tk do
- prev_container = container
- container = container.find_module_named name_t.name
- container ||=
- if ignore_constants then
- RDoc::Context.new
- else
- c = prev_container.add_module RDoc::NormalModule, name_t.name
- c.ignore unless prev_container.document_children
- @top_level.add_to_classes_or_modules c
- c
- end
-
- record_location container
-
- get_tk
- skip_tkspace false
- name_t = get_tk
- given_name << '::' << name_t.name
- end
-
- skip_tkspace false
-
- return [container, name_t, given_name]
- end
-
- ##
- # Return a superclass, which can be either a constant of an expression
-
- def get_class_specification
- case peek_tk
- when TkSELF then return 'self'
- when TkGVAR then return ''
- end
-
- res = get_constant
-
- skip_tkspace false
-
- get_tkread # empty out read buffer
-
- tk = get_tk
-
- case tk
- when TkNL, TkCOMMENT, TkSEMICOLON then
- unget_tk(tk)
- return res
- end
-
- res += parse_call_parameters(tk)
- res
- end
-
- ##
- # Parse a constant, which might be qualified by one or more class or module
- # names
-
- def get_constant
- res = ""
- skip_tkspace false
- tk = get_tk
-
- while TkCOLON2 === tk or TkCOLON3 === tk or TkCONSTANT === tk do
- res += tk.name
- tk = get_tk
- end
-
- unget_tk(tk)
- res
- end
-
- ##
- # Get a constant that may be surrounded by parens
-
- def get_constant_with_optional_parens
- skip_tkspace false
-
- nest = 0
-
- while TkLPAREN === (tk = peek_tk) or TkfLPAREN === tk do
- get_tk
- skip_tkspace
- nest += 1
- end
-
- name = get_constant
-
- while nest > 0
- skip_tkspace
- tk = get_tk
- nest -= 1 if TkRPAREN === tk
- end
-
- name
- end
-
- ##
- # Little hack going on here. In the statement:
- #
- # f = 2*(1+yield)
- #
- # We see the RPAREN as the next token, so we need to exit early. This still
- # won't catch all cases (such as "a = yield + 1"
-
- def get_end_token tk # :nodoc:
- case tk
- when TkLPAREN, TkfLPAREN
- TkRPAREN
- when TkRPAREN
- nil
- else
- TkNL
- end
- end
-
- ##
- # Retrieves the method container for a singleton method.
-
- def get_method_container container, name_t # :nodoc:
- prev_container = container
- container = container.find_module_named(name_t.name)
-
- unless container then
- constant = prev_container.constants.find do |const|
- const.name == name_t.name
- end
-
- if constant then
- parse_method_dummy prev_container
- return
- end
- end
-
- unless container then
- # TODO seems broken, should starting at Object in @store
- obj = name_t.name.split("::").inject(Object) do |state, item|
- state.const_get(item)
- end rescue nil
-
- type = obj.class == Class ? RDoc::NormalClass : RDoc::NormalModule
-
- unless [Class, Module].include?(obj.class) then
- warn("Couldn't find #{name_t.name}. Assuming it's a module")
- end
-
- if type == RDoc::NormalClass then
- sclass = obj.superclass ? obj.superclass.name : nil
- container = prev_container.add_class type, name_t.name, sclass
- else
- container = prev_container.add_module type, name_t.name
- end
-
- record_location container
- end
-
- container
- end
-
- ##
- # Extracts a name or symbol from the token stream.
-
- def get_symbol_or_name
- tk = get_tk
- case tk
- when TkSYMBOL then
- text = tk.text.sub(/^:/, '')
-
- if TkASSIGN === peek_tk then
- get_tk
- text << '='
- end
-
- text
- when TkId, TkOp then
- tk.name
- when TkAMPER,
- TkDSTRING,
- TkSTAR,
- TkSTRING then
- tk.text
- else
- raise RDoc::Error, "Name or symbol expected (got #{tk})"
- end
- end
-
- def stop_at_EXPR_END # :nodoc:
- @scanner.lex_state == :EXPR_END || !@scanner.continue
- end
-
- ##
- # Marks containers between +container+ and +ancestor+ as ignored
-
- def suppress_parents container, ancestor # :nodoc:
- while container and container != ancestor do
- container.suppress unless container.documented?
- container = container.parent
- end
- end
-
- ##
- # Look for directives in a normal comment block:
- #
- # # :stopdoc:
- # # Don't display comment from this point forward
- #
- # This routine modifies its +comment+ parameter.
-
- def look_for_directives_in context, comment
- @preprocess.handle comment, context do |directive, param|
- case directive
- when 'method', 'singleton-method',
- 'attr', 'attr_accessor', 'attr_reader', 'attr_writer' then
- false # handled elsewhere
- when 'section' then
- context.set_current_section param, comment.dup
- comment.text = ''
- break
- end
- end
-
- remove_private_comments comment
- end
-
- ##
- # Adds useful info about the parser to +message+
-
- def make_message message
- prefix = "#{@file_name}:"
-
- prefix << "#{@scanner.line_no}:#{@scanner.char_no}:" if @scanner
-
- "#{prefix} #{message}"
- end
-
- ##
- # Creates a comment with the correct format
-
- def new_comment comment
- c = RDoc::Comment.new comment, @top_level
- c.format = @markup
- c
- end
-
- ##
- # Creates an RDoc::Attr for the name following +tk+, setting the comment to
- # +comment+.
-
- def parse_attr(context, single, tk, comment)
- offset = tk.seek
- line_no = tk.line_no
-
- args = parse_symbol_arg 1
- if args.size > 0 then
- name = args[0]
- rw = "R"
- skip_tkspace false
- tk = get_tk
-
- if TkCOMMA === tk then
- rw = "RW" if get_bool
- else
- unget_tk tk
- end
-
- att = create_attr context, single, name, rw, comment
- att.offset = offset
- att.line = line_no
-
- read_documentation_modifiers att, RDoc::ATTR_MODIFIERS
- else
- warn "'attr' ignored - looks like a variable"
- end
- end
-
- ##
- # Creates an RDoc::Attr for each attribute listed after +tk+, setting the
- # comment for each to +comment+.
-
- def parse_attr_accessor(context, single, tk, comment)
- offset = tk.seek
- line_no = tk.line_no
-
- args = parse_symbol_arg
- rw = "?"
-
- tmp = RDoc::CodeObject.new
- read_documentation_modifiers tmp, RDoc::ATTR_MODIFIERS
- # TODO In most other places we let the context keep track of document_self
- # and add found items appropriately but here we do not. I'm not sure why.
- return if @track_visibility and not tmp.document_self
-
- case tk.name
- when "attr_reader" then rw = "R"
- when "attr_writer" then rw = "W"
- when "attr_accessor" then rw = "RW"
- else
- rw = '?'
- end
-
- for name in args
- att = create_attr context, single, name, rw, comment
- att.offset = offset
- att.line = line_no
- end
- end
-
- ##
- # Parses an +alias+ in +context+ with +comment+
-
- def parse_alias(context, single, tk, comment)
- offset = tk.seek
- line_no = tk.line_no
-
- skip_tkspace
-
- if TkLPAREN === peek_tk then
- get_tk
- skip_tkspace
- end
-
- new_name = get_symbol_or_name
-
- @scanner.lex_state = :EXPR_FNAME
-
- skip_tkspace
- if TkCOMMA === peek_tk then
- get_tk
- skip_tkspace
- end
-
- begin
- old_name = get_symbol_or_name
- rescue RDoc::Error
- return
- end
-
- al = RDoc::Alias.new(get_tkread, old_name, new_name, comment,
- single == SINGLE)
- record_location al
- al.offset = offset
- al.line = line_no
-
- read_documentation_modifiers al, RDoc::ATTR_MODIFIERS
- context.add_alias al
- @stats.add_alias al
-
- al
- end
-
- ##
- # Extracts call parameters from the token stream.
-
- def parse_call_parameters(tk)
- end_token = case tk
- when TkLPAREN, TkfLPAREN
- TkRPAREN
- when TkRPAREN
- return ""
- else
- TkNL
- end
- nest = 0
-
- loop do
- case tk
- when TkSEMICOLON
- break
- when TkLPAREN, TkfLPAREN
- nest += 1
- when end_token
- if end_token == TkRPAREN
- nest -= 1
- break if @scanner.lex_state == :EXPR_END and nest <= 0
- else
- break unless @scanner.continue
- end
- when TkCOMMENT, TkASSIGN, TkOPASGN
- unget_tk(tk)
- break
- when nil then
- break
- end
- tk = get_tk
- end
-
- get_tkread_clean "\n", " "
- end
-
- ##
- # Parses a class in +context+ with +comment+
-
- def parse_class container, single, tk, comment
- offset = tk.seek
- line_no = tk.line_no
-
- declaration_context = container
- container, name_t, given_name = get_class_or_module container
-
- cls =
- case name_t
- when TkCONSTANT
- parse_class_regular container, declaration_context, single,
- name_t, given_name, comment
- when TkLSHFT
- case name = get_class_specification
- when 'self', container.name
- parse_statements container, SINGLE
- return # don't update offset or line
- else
- parse_class_singleton container, name, comment
- end
- else
- warn "Expected class name or '<<'. Got #{name_t.class}: #{name_t.text.inspect}"
- return
- end
-
- cls.offset = offset
- cls.line = line_no
-
- cls
- end
-
- ##
- # Parses and creates a regular class
-
- def parse_class_regular container, declaration_context, single, # :nodoc:
- name_t, given_name, comment
- superclass = '::Object'
-
- if given_name =~ /^::/ then
- declaration_context = @top_level
- given_name = $'
- end
-
- if TkLT === peek_tk then
- get_tk
- skip_tkspace
- superclass = get_class_specification
- superclass = '(unknown)' if superclass.empty?
- end
-
- cls_type = single == SINGLE ? RDoc::SingleClass : RDoc::NormalClass
- cls = declaration_context.add_class cls_type, given_name, superclass
- cls.ignore unless container.document_children
-
- read_documentation_modifiers cls, RDoc::CLASS_MODIFIERS
- record_location cls
-
- cls.add_comment comment, @top_level
-
- @top_level.add_to_classes_or_modules cls
- @stats.add_class cls
-
- suppress_parents container, declaration_context unless cls.document_self
-
- parse_statements cls
-
- cls
- end
-
- ##
- # Parses a singleton class in +container+ with the given +name+ and
- # +comment+.
-
- def parse_class_singleton container, name, comment # :nodoc:
- other = @store.find_class_named name
-
- unless other then
- if name =~ /^::/ then
- name = $'
- container = @top_level
- end
-
- other = container.add_module RDoc::NormalModule, name
- record_location other
-
- # class << $gvar
- other.ignore if name.empty?
-
- other.add_comment comment, @top_level
- end
-
- # notify :nodoc: all if not a constant-named class/module
- # (and remove any comment)
- unless name =~ /\A(::)?[A-Z]/ then
- other.document_self = nil
- other.document_children = false
- other.clear_comment
- end
-
- @top_level.add_to_classes_or_modules other
- @stats.add_class other
-
- read_documentation_modifiers other, RDoc::CLASS_MODIFIERS
- parse_statements(other, SINGLE)
-
- other
- end
-
- ##
- # Parses a constant in +context+ with +comment+. If +ignore_constants+ is
- # true, no found constants will be added to RDoc.
-
- def parse_constant container, tk, comment, ignore_constants = false
- offset = tk.seek
- line_no = tk.line_no
-
- name = tk.name
- skip_tkspace false
-
- return unless name =~ /^\w+$/
-
- eq_tk = get_tk
-
- if TkCOLON2 === eq_tk then
- unget_tk eq_tk
- unget_tk tk
-
- container, name_t, = get_class_or_module container, ignore_constants
-
- name = name_t.name
-
- eq_tk = get_tk
- end
-
- unless TkASSIGN === eq_tk then
- unget_tk eq_tk
- return false
- end
-
- if TkGT === peek_tk then
- unget_tk eq_tk
- return
- end
-
- value = ''
- con = RDoc::Constant.new name, value, comment
-
- body = parse_constant_body container, con
-
- return unless body
-
- value.replace body
- record_location con
- con.offset = offset
- con.line = line_no
- read_documentation_modifiers con, RDoc::CONSTANT_MODIFIERS
-
- @stats.add_constant con
- container.add_constant con
-
- true
- end
-
- def parse_constant_body container, constant # :nodoc:
- nest = 0
- rhs_name = ''
-
- get_tkread
-
- tk = get_tk
-
- loop do
- case tk
- when TkSEMICOLON then
- break if nest <= 0
- when TkLPAREN, TkfLPAREN, TkLBRACE, TkfLBRACE, TkLBRACK, TkfLBRACK,
- TkDO, TkIF, TkUNLESS, TkCASE, TkDEF, TkBEGIN then
- nest += 1
- when TkRPAREN, TkRBRACE, TkRBRACK, TkEND then
- nest -= 1
- when TkCOMMENT then
- if nest <= 0 and stop_at_EXPR_END then
- unget_tk tk
- break
- else
- unget_tk tk
- read_documentation_modifiers constant, RDoc::CONSTANT_MODIFIERS
- end
- when TkCONSTANT then
- rhs_name << tk.name
-
- if nest <= 0 and TkNL === peek_tk then
- create_module_alias container, constant, rhs_name
- break
- end
- when TkNL then
- if nest <= 0 and stop_at_EXPR_END then
- unget_tk tk
- break
- end
- when TkCOLON2, TkCOLON3 then
- rhs_name << '::'
- when nil then
- break
- end
- tk = get_tk
- end
-
- get_tkread_clean(/^[ \t]+/, '')
- end
-
- ##
- # Generates an RDoc::Method or RDoc::Attr from +comment+ by looking for
- # :method: or :attr: directives in +comment+.
-
- def parse_comment container, tk, comment
- return parse_comment_tomdoc container, tk, comment if @markup == 'tomdoc'
- column = tk.char_no
- offset = tk.seek
- line_no = tk.line_no
-
- text = comment.text
-
- singleton = !!text.sub!(/(^# +:?)(singleton-)(method:)/, '\1\3')
-
- co =
- if text.sub!(/^# +:?method: *(\S*).*?\n/i, '') then
- parse_comment_ghost container, text, $1, column, line_no, comment
- elsif text.sub!(/# +:?(attr(_reader|_writer|_accessor)?): *(\S*).*?\n/i, '') then
- parse_comment_attr container, $1, $3, comment
- end
-
- if co then
- co.singleton = singleton
- co.offset = offset
- co.line = line_no
- end
-
- true
- end
-
- ##
- # Parse a comment that is describing an attribute in +container+ with the
- # given +name+ and +comment+.
-
- def parse_comment_attr container, type, name, comment # :nodoc:
- return if name.empty?
-
- rw = case type
- when 'attr_reader' then 'R'
- when 'attr_writer' then 'W'
- else 'RW'
- end
-
- create_attr container, NORMAL, name, rw, comment
- end
-
- def parse_comment_ghost container, text, name, column, line_no, # :nodoc:
- comment
- name = nil if name.empty?
-
- meth = RDoc::GhostMethod.new get_tkread, name
- record_location meth
-
- meth.start_collecting_tokens
- indent = TkSPACE.new 0, 1, 1
- indent.set_text " " * column
-
- position_comment = TkCOMMENT.new 0, line_no, 1
- position_comment.set_text "# File #{@top_level.relative_name}, line #{line_no}"
- meth.add_tokens [position_comment, NEWLINE_TOKEN, indent]
-
- meth.params =
- if text.sub!(/^#\s+:?args?:\s*(.*?)\s*$/i, '') then
- $1
- else
- ''
- end
-
- comment.normalize
- comment.extract_call_seq meth
-
- return unless meth.name
-
- container.add_method meth
-
- meth.comment = comment
-
- @stats.add_method meth
-
- meth
- end
-
- ##
- # Creates an RDoc::Method on +container+ from +comment+ if there is a
- # Signature section in the comment
-
- def parse_comment_tomdoc container, tk, comment
- return unless signature = RDoc::TomDoc.signature(comment)
- offset = tk.seek
- line_no = tk.line_no
-
- name, = signature.split %r%[ \(]%, 2
-
- meth = RDoc::GhostMethod.new get_tkread, name
- record_location meth
- meth.offset = offset
- meth.line = line_no
-
- meth.start_collecting_tokens
- indent = TkSPACE.new 0, 1, 1
- indent.set_text " " * offset
-
- position_comment = TkCOMMENT.new 0, line_no, 1
- position_comment.set_text "# File #{@top_level.relative_name}, line #{line_no}"
- meth.add_tokens [position_comment, NEWLINE_TOKEN, indent]
-
- meth.call_seq = signature
-
- comment.normalize
-
- return unless meth.name
-
- container.add_method meth
-
- meth.comment = comment
-
- @stats.add_method meth
- end
-
- ##
- # Parses an +include+ or +extend+, indicated by the +klass+ and adds it to
- # +container+ # with +comment+
-
- def parse_extend_or_include klass, container, comment # :nodoc:
- loop do
- skip_tkspace_comment
-
- name = get_constant_with_optional_parens
-
- unless name.empty? then
- obj = container.add klass, name, comment
- record_location obj
- end
-
- return unless TkCOMMA === peek_tk
-
- get_tk
- end
- end
-
- ##
- # Parses identifiers that can create new methods or change visibility.
- #
- # Returns true if the comment was not consumed.
-
- def parse_identifier container, single, tk, comment # :nodoc:
- case tk.name
- when 'private', 'protected', 'public', 'private_class_method',
- 'public_class_method', 'module_function' then
- parse_visibility container, single, tk
- return true
- when 'attr' then
- parse_attr container, single, tk, comment
- when /^attr_(reader|writer|accessor)$/ then
- parse_attr_accessor container, single, tk, comment
- when 'alias_method' then
- parse_alias container, single, tk, comment
- when 'require', 'include' then
- # ignore
- else
- if comment.text =~ /\A#\#$/ then
- case comment.text
- when /^# +:?attr(_reader|_writer|_accessor)?:/ then
- parse_meta_attr container, single, tk, comment
- else
- method = parse_meta_method container, single, tk, comment
- method.params = container.params if
- container.params
- method.block_params = container.block_params if
- container.block_params
- end
- end
- end
-
- false
- end
-
- ##
- # Parses a meta-programmed attribute and creates an RDoc::Attr.
- #
- # To create foo and bar attributes on class C with comment "My attributes":
- #
- # class C
- #
- # ##
- # # :attr:
- # #
- # # My attributes
- #
- # my_attr :foo, :bar
- #
- # end
- #
- # To create a foo attribute on class C with comment "My attribute":
- #
- # class C
- #
- # ##
- # # :attr: foo
- # #
- # # My attribute
- #
- # my_attr :foo, :bar
- #
- # end
-
- def parse_meta_attr(context, single, tk, comment)
- args = parse_symbol_arg
- rw = "?"
-
- # If nodoc is given, don't document any of them
-
- tmp = RDoc::CodeObject.new
- read_documentation_modifiers tmp, RDoc::ATTR_MODIFIERS
-
- if comment.text.sub!(/^# +:?(attr(_reader|_writer|_accessor)?): *(\S*).*?\n/i, '') then
- rw = case $1
- when 'attr_reader' then 'R'
- when 'attr_writer' then 'W'
- else 'RW'
- end
- name = $3 unless $3.empty?
- end
-
- if name then
- att = create_attr context, single, name, rw, comment
- else
- args.each do |attr_name|
- att = create_attr context, single, attr_name, rw, comment
- end
- end
-
- att
- end
-
- ##
- # Parses a meta-programmed method
-
- def parse_meta_method(container, single, tk, comment)
- column = tk.char_no
- offset = tk.seek
- line_no = tk.line_no
-
- start_collecting_tokens
- add_token tk
- add_token_listener self
-
- skip_tkspace false
-
- singleton = !!comment.text.sub!(/(^# +:?)(singleton-)(method:)/, '\1\3')
-
- name = parse_meta_method_name comment, tk
-
- return unless name
-
- meth = RDoc::MetaMethod.new get_tkread, name
- record_location meth
- meth.offset = offset
- meth.line = line_no
- meth.singleton = singleton
-
- remove_token_listener self
-
- meth.start_collecting_tokens
- indent = TkSPACE.new 0, 1, 1
- indent.set_text " " * column
-
- position_comment = TkCOMMENT.new 0, line_no, 1
- position_comment.value = "# File #{@top_level.relative_name}, line #{line_no}"
- meth.add_tokens [position_comment, NEWLINE_TOKEN, indent]
- meth.add_tokens @token_stream
-
- parse_meta_method_params container, single, meth, tk, comment
-
- meth.comment = comment
-
- @stats.add_method meth
-
- meth
- end
-
- ##
- # Parses the name of a metaprogrammed method. +comment+ is used to
- # determine the name while +tk+ is used in an error message if the name
- # cannot be determined.
-
- def parse_meta_method_name comment, tk # :nodoc:
- if comment.text.sub!(/^# +:?method: *(\S*).*?\n/i, '') then
- return $1 unless $1.empty?
- end
-
- name_t = get_tk
-
- case name_t
- when TkSYMBOL then
- name_t.text[1..-1]
- when TkSTRING then
- name_t.value[1..-2]
- when TkASSIGN then # ignore
- remove_token_listener self
-
- nil
- else
- warn "unknown name token #{name_t.inspect} for meta-method '#{tk.name}'"
- 'unknown'
- end
- end
-
- ##
- # Parses the parameters and block for a meta-programmed method.
-
- def parse_meta_method_params container, single, meth, tk, comment # :nodoc:
- token_listener meth do
- meth.params = ''
-
- comment.normalize
- comment.extract_call_seq meth
-
- container.add_method meth
-
- last_tk = tk
-
- while tk = get_tk do
- case tk
- when TkSEMICOLON then
- break
- when TkNL then
- break unless last_tk and TkCOMMA === last_tk
- when TkSPACE then
- # expression continues
- when TkDO then
- parse_statements container, single, meth
- break
- else
- last_tk = tk
- end
- end
- end
- end
-
- ##
- # Parses a normal method defined by +def+
-
- def parse_method(container, single, tk, comment)
- singleton = nil
- added_container = false
- name = nil
- column = tk.char_no
- offset = tk.seek
- line_no = tk.line_no
-
- start_collecting_tokens
- add_token tk
-
- token_listener self do
- prev_container = container
- name, container, singleton = parse_method_name container
- added_container = container != prev_container
- end
-
- return unless name
-
- meth = RDoc::AnyMethod.new get_tkread, name
- meth.singleton = single == SINGLE ? true : singleton
-
- record_location meth
- meth.offset = offset
- meth.line = line_no
-
- meth.start_collecting_tokens
- indent = TkSPACE.new 0, 1, 1
- indent.set_text " " * column
-
- token = TkCOMMENT.new 0, line_no, 1
- token.set_text "# File #{@top_level.relative_name}, line #{line_no}"
- meth.add_tokens [token, NEWLINE_TOKEN, indent]
- meth.add_tokens @token_stream
-
- parse_method_params_and_body container, single, meth, added_container
-
- comment.normalize
- comment.extract_call_seq meth
-
- meth.comment = comment
-
- @stats.add_method meth
- end
-
- ##
- # Parses the parameters and body of +meth+
-
- def parse_method_params_and_body container, single, meth, added_container
- token_listener meth do
- @scanner.continue = false
- parse_method_parameters meth
-
- if meth.document_self or not @track_visibility then
- container.add_method meth
- elsif added_container then
- container.document_self = false
- end
-
- # Having now read the method parameters and documentation modifiers, we
- # now know whether we have to rename #initialize to ::new
-
- if meth.name == "initialize" && !meth.singleton then
- if meth.dont_rename_initialize then
- meth.visibility = :protected
- else
- meth.singleton = true
- meth.name = "new"
- meth.visibility = :public
- end
- end
-
- parse_statements container, single, meth
- end
- end
-
- ##
- # Parses a method that needs to be ignored.
-
- def parse_method_dummy container
- dummy = RDoc::Context.new
- dummy.parent = container
- dummy.store = container.store
- skip_method dummy
- end
-
- ##
- # Parses the name of a method in +container+.
- #
- # Returns the method name, the container it is in (for def Foo.name) and if
- # it is a singleton or regular method.
-
- def parse_method_name container # :nodoc:
- @scanner.lex_state = :EXPR_FNAME
-
- skip_tkspace
- name_t = get_tk
- back_tk = skip_tkspace
- singleton = false
-
- case dot = get_tk
- when TkDOT, TkCOLON2 then
- singleton = true
-
- name, container = parse_method_name_singleton container, name_t
- else
- unget_tk dot
- back_tk.reverse_each do |token|
- unget_tk token
- end
-
- name = parse_method_name_regular container, name_t
- end
-
- return name, container, singleton
- end
-
- ##
- # For the given +container+ and initial name token +name_t+ the method name
- # is parsed from the token stream for a regular method.
-
- def parse_method_name_regular container, name_t # :nodoc:
- case name_t
- when TkSTAR, TkAMPER then
- name_t.text
- else
- unless name_t.respond_to? :name then
- warn "expected method name token, . or ::, got #{name_t.inspect}"
- skip_method container
- return
- end
- name_t.name
- end
- end
-
- ##
- # For the given +container+ and initial name token +name_t+ the method name
- # and the new +container+ (if necessary) are parsed from the token stream
- # for a singleton method.
-
- def parse_method_name_singleton container, name_t # :nodoc:
- @scanner.lex_state = :EXPR_FNAME
- skip_tkspace
- name_t2 = get_tk
-
- name =
- case name_t
- when TkSELF, TkMOD then
- case name_t2
- # NOTE: work around '[' being consumed early and not being re-tokenized
- # as a TkAREF
- when TkfLBRACK then
- get_tk
- '[]'
- else
- name_t2.name
- end
- when TkCONSTANT then
- name = name_t2.name
-
- container = get_method_container container, name_t
-
- return unless container
-
- name
- when TkIDENTIFIER, TkIVAR, TkGVAR then
- parse_method_dummy container
-
- nil
- when TkTRUE, TkFALSE, TkNIL then
- klass_name = "#{name_t.name.capitalize}Class"
- container = @store.find_class_named klass_name
- container ||= @top_level.add_class RDoc::NormalClass, klass_name
-
- name_t2.name
- else
- warn "unexpected method name token #{name_t.inspect}"
- # break
- skip_method container
-
- nil
- end
-
- return name, container
- end
-
- ##
- # Extracts +yield+ parameters from +method+
-
- def parse_method_or_yield_parameters(method = nil,
- modifiers = RDoc::METHOD_MODIFIERS)
- skip_tkspace false
- tk = get_tk
- end_token = get_end_token tk
- return '' unless end_token
-
- nest = 0
-
- loop do
- case tk
- when TkSEMICOLON then
- break if nest == 0
- when TkLBRACE, TkfLBRACE then
- nest += 1
- when TkRBRACE then
- nest -= 1
- if nest <= 0
- # we might have a.each { |i| yield i }
- unget_tk(tk) if nest < 0
- break
- end
- when TkLPAREN, TkfLPAREN then
- nest += 1
- when end_token then
- if end_token == TkRPAREN
- nest -= 1
- break if nest <= 0
- else
- break unless @scanner.continue
- end
- when TkRPAREN then
- nest -= 1
- when method && method.block_params.nil? && TkCOMMENT then
- unget_tk tk
- read_documentation_modifiers method, modifiers
- @read.pop
- when TkCOMMENT then
- @read.pop
- when nil then
- break
- end
- tk = get_tk
- end
-
- get_tkread_clean(/\s+/, ' ')
- end
-
- ##
- # Capture the method's parameters. Along the way, look for a comment
- # containing:
- #
- # # yields: ....
- #
- # and add this as the block_params for the method
-
- def parse_method_parameters method
- res = parse_method_or_yield_parameters method
-
- res = "(#{res})" unless res =~ /\A\(/
- method.params = res unless method.params
-
- return if method.block_params
-
- skip_tkspace false
- read_documentation_modifiers method, RDoc::METHOD_MODIFIERS
- end
-
- ##
- # Parses an RDoc::NormalModule in +container+ with +comment+
-
- def parse_module container, single, tk, comment
- container, name_t, = get_class_or_module container
-
- name = name_t.name
-
- mod = container.add_module RDoc::NormalModule, name
- mod.ignore unless container.document_children
- record_location mod
-
- read_documentation_modifiers mod, RDoc::CLASS_MODIFIERS
- mod.add_comment comment, @top_level
- parse_statements mod
-
- @stats.add_module mod
- end
-
- ##
- # Parses an RDoc::Require in +context+ containing +comment+
-
- def parse_require(context, comment)
- skip_tkspace_comment
- tk = get_tk
-
- if TkLPAREN === tk then
- skip_tkspace_comment
- tk = get_tk
- end
-
- name = tk.text if TkSTRING === tk
-
- if name then
- @top_level.add_require RDoc::Require.new(name, comment)
- else
- unget_tk tk
- end
- end
-
- ##
- # Parses a rescue
-
- def parse_rescue
- skip_tkspace false
-
- while tk = get_tk
- case tk
- when TkNL, TkSEMICOLON then
- break
- when TkCOMMA then
- skip_tkspace false
-
- get_tk if TkNL === peek_tk
- end
-
- skip_tkspace false
- end
- end
-
- ##
- # The core of the Ruby parser.
-
- def parse_statements(container, single = NORMAL, current_method = nil,
- comment = new_comment(''))
- raise 'no' unless RDoc::Comment === comment
- comment.force_encoding @encoding if @encoding
-
- nest = 1
- save_visibility = container.visibility
-
- non_comment_seen = true
-
- while tk = get_tk do
- keep_comment = false
- try_parse_comment = false
-
- non_comment_seen = true unless TkCOMMENT === tk
-
- case tk
- when TkNL then
- skip_tkspace
- tk = get_tk
-
- if TkCOMMENT === tk then
- if non_comment_seen then
- # Look for RDoc in a comment about to be thrown away
- non_comment_seen = parse_comment container, tk, comment unless
- comment.empty?
-
- comment = ''
- comment.force_encoding @encoding if @encoding
- end
-
- while TkCOMMENT === tk do
- comment << tk.text << "\n"
-
- tk = get_tk
-
- if TkNL === tk then
- skip_tkspace false # leading spaces
- tk = get_tk
- end
- end
-
- comment = new_comment comment
-
- unless comment.empty? then
- look_for_directives_in container, comment
-
- if container.done_documenting then
- throw :eof if RDoc::TopLevel === container
- container.ongoing_visibility = save_visibility
- end
- end
-
- keep_comment = true
- else
- non_comment_seen = true
- end
-
- unget_tk tk
- keep_comment = true
-
- when TkCLASS then
- parse_class container, single, tk, comment
-
- when TkMODULE then
- parse_module container, single, tk, comment
-
- when TkDEF then
- parse_method container, single, tk, comment
-
- when TkCONSTANT then
- unless parse_constant container, tk, comment, current_method then
- try_parse_comment = true
- end
-
- when TkALIAS then
- parse_alias container, single, tk, comment unless current_method
-
- when TkYIELD then
- if current_method.nil? then
- warn "Warning: yield outside of method" if container.document_self
- else
- parse_yield container, single, tk, current_method
- end
-
- # Until and While can have a 'do', which shouldn't increase the nesting.
- # We can't solve the general case, but we can handle most occurrences by
- # ignoring a do at the end of a line.
-
- when TkUNTIL, TkWHILE then
- nest += 1
- skip_optional_do_after_expression
-
- # 'for' is trickier
- when TkFOR then
- nest += 1
- skip_for_variable
- skip_optional_do_after_expression
-
- when TkCASE, TkDO, TkIF, TkUNLESS, TkBEGIN then
- nest += 1
-
- when TkSUPER then
- current_method.calls_super = true if current_method
-
- when TkRESCUE then
- parse_rescue
-
- when TkIDENTIFIER then
- if nest == 1 and current_method.nil? then
- keep_comment = parse_identifier container, single, tk, comment
- end
-
- case tk.name
- when "require" then
- parse_require container, comment
- when "include" then
- parse_extend_or_include RDoc::Include, container, comment
- when "extend" then
- parse_extend_or_include RDoc::Extend, container, comment
- end
-
- when TkEND then
- nest -= 1
- if nest == 0 then
- read_documentation_modifiers container, RDoc::CLASS_MODIFIERS
- container.ongoing_visibility = save_visibility
-
- parse_comment container, tk, comment unless comment.empty?
-
- return
- end
- else
- try_parse_comment = nest == 1
- end
-
- if try_parse_comment then
- non_comment_seen = parse_comment container, tk, comment unless
- comment.empty?
-
- keep_comment = false
- end
-
- unless keep_comment then
- comment = new_comment ''
- comment.force_encoding @encoding if @encoding
- container.params = nil
- container.block_params = nil
- end
-
- consume_trailing_spaces
- end
-
- container.params = nil
- container.block_params = nil
- end
-
- ##
- # Parse up to +no+ symbol arguments
-
- def parse_symbol_arg(no = nil)
- skip_tkspace_comment
-
- case tk = get_tk
- when TkLPAREN
- parse_symbol_arg_paren no
- else
- parse_symbol_arg_space no, tk
- end
- end
-
- ##
- # Parses up to +no+ symbol arguments surrounded by () and places them in
- # +args+.
-
- def parse_symbol_arg_paren no # :nodoc:
- args = []
-
- loop do
- skip_tkspace_comment
- if tk1 = parse_symbol_in_arg
- args.push tk1
- break if no and args.size >= no
- end
-
- skip_tkspace_comment
- case tk2 = get_tk
- when TkRPAREN
- break
- when TkCOMMA
- else
- warn("unexpected token: '#{tk2.inspect}'") if $DEBUG_RDOC
- break
- end
- end
-
- args
- end
-
- ##
- # Parses up to +no+ symbol arguments separated by spaces and places them in
- # +args+.
-
- def parse_symbol_arg_space no, tk # :nodoc:
- args = []
-
- unget_tk tk
- if tk = parse_symbol_in_arg
- args.push tk
- return args if no and args.size >= no
- end
-
- loop do
- skip_tkspace false
-
- tk1 = get_tk
- unless TkCOMMA === tk1 then
- unget_tk tk1
- break
- end
-
- skip_tkspace_comment
- if tk = parse_symbol_in_arg
- args.push tk
- break if no and args.size >= no
- end
- end
-
- args
- end
-
- ##
- # Returns symbol text from the next token
-
- def parse_symbol_in_arg
- case tk = get_tk
- when TkSYMBOL
- tk.text.sub(/^:/, '')
- when TkSTRING
- eval @read[-1]
- when TkDSTRING, TkIDENTIFIER then
- nil # ignore
- else
- warn("Expected symbol or string, got #{tk.inspect}") if $DEBUG_RDOC
- nil
- end
- end
-
- ##
- # Parses statements in the top-level +container+
-
- def parse_top_level_statements container
- comment = collect_first_comment
-
- look_for_directives_in container, comment
-
- throw :eof if container.done_documenting
-
- @markup = comment.format
-
- # HACK move if to RDoc::Context#comment=
- container.comment = comment if container.document_self unless comment.empty?
-
- parse_statements container, NORMAL, nil, comment
- end
-
- ##
- # Determines the visibility in +container+ from +tk+
-
- def parse_visibility(container, single, tk)
- vis_type, vis, singleton = get_visibility_information tk, single
-
- skip_tkspace_comment false
-
- case peek_tk
- # Ryan Davis suggested the extension to ignore modifiers, because he
- # often writes
- #
- # protected unless $TESTING
- #
- when TkNL, TkUNLESS_MOD, TkIF_MOD, TkSEMICOLON then
- container.ongoing_visibility = vis
- else
- update_visibility container, vis_type, vis, singleton
- end
- end
-
- ##
- # Determines the block parameter for +context+
-
- def parse_yield(context, single, tk, method)
- return if method.block_params
-
- get_tkread
- @scanner.continue = false
- method.block_params = parse_method_or_yield_parameters
- end
-
- ##
- # Directives are modifier comments that can appear after class, module, or
- # method names. For example:
- #
- # def fred # :yields: a, b
- #
- # or:
- #
- # class MyClass # :nodoc:
- #
- # We return the directive name and any parameters as a two element array if
- # the name is in +allowed+. A directive can be found anywhere up to the end
- # of the current line.
-
- def read_directive allowed
- tokens = []
-
- while tk = get_tk do
- tokens << tk
-
- case tk
- when TkNL, TkDEF then
- return
- when TkCOMMENT then
- return unless tk.text =~ /\s*:?([\w-]+):\s*(.*)/
-
- directive = $1.downcase
-
- return [directive, $2] if allowed.include? directive
-
- return
- end
- end
- ensure
- unless tokens.length == 1 and TkCOMMENT === tokens.first then
- tokens.reverse_each do |token|
- unget_tk token
- end
- end
- end
-
- ##
- # Handles directives following the definition for +context+ (any
- # RDoc::CodeObject) if the directives are +allowed+ at this point.
- #
- # See also RDoc::Markup::PreProcess#handle_directive
-
- def read_documentation_modifiers context, allowed
- directive, value = read_directive allowed
-
- return unless directive
-
- @preprocess.handle_directive '', directive, value, context do |dir, param|
- if %w[notnew not_new not-new].include? dir then
- context.dont_rename_initialize = true
-
- true
- end
- end
- end
-
- ##
- # Records the location of this +container+ in the file for this parser and
- # adds it to the list of classes and modules in the file.
-
- def record_location container # :nodoc:
- case container
- when RDoc::ClassModule then
- @top_level.add_to_classes_or_modules container
- end
-
- container.record_location @top_level
- end
-
- ##
- # Removes private comments from +comment+
- #--
- # TODO remove
-
- def remove_private_comments comment
- comment.remove_private
- end
-
- ##
- # Scans this Ruby file for Ruby constructs
-
- def scan
- reset
-
- catch :eof do
- begin
- parse_top_level_statements @top_level
-
- rescue StandardError => e
- bytes = ''
-
- 20.times do @scanner.ungetc end
- count = 0
- 60.times do |i|
- count = i
- byte = @scanner.getc
- break unless byte
- bytes << byte
- end
- count -= 20
- count.times do @scanner.ungetc end
-
- $stderr.puts <<-EOF
-
-#{self.class} failure around line #{@scanner.line_no} of
-#{@file_name}
-
- EOF
-
- unless bytes.empty? then
- $stderr.puts
- $stderr.puts bytes.inspect
- end
-
- raise e
- end
- end
-
- @top_level
- end
-
- ##
- # while, until, and for have an optional do
-
- def skip_optional_do_after_expression
- skip_tkspace false
- tk = get_tk
- end_token = get_end_token tk
-
- b_nest = 0
- nest = 0
- @scanner.continue = false
-
- loop do
- case tk
- when TkSEMICOLON then
- break if b_nest.zero?
- when TkLPAREN, TkfLPAREN then
- nest += 1
- when TkBEGIN then
- b_nest += 1
- when TkEND then
- b_nest -= 1
- when TkDO
- break if nest.zero?
- when end_token then
- if end_token == TkRPAREN
- nest -= 1
- break if @scanner.lex_state == :EXPR_END and nest.zero?
- else
- break unless @scanner.continue
- end
- when nil then
- break
- end
- tk = get_tk
- end
-
- skip_tkspace false
-
- get_tk if TkDO === peek_tk
- end
-
- ##
- # skip the var [in] part of a 'for' statement
-
- def skip_for_variable
- skip_tkspace false
- get_tk
- skip_tkspace false
- tk = get_tk
- unget_tk(tk) unless TkIN === tk
- end
-
- ##
- # Skips the next method in +container+
-
- def skip_method container
- meth = RDoc::AnyMethod.new "", "anon"
- parse_method_parameters meth
- parse_statements container, false, meth
- end
-
- ##
- # Skip spaces until a comment is found
-
- def skip_tkspace_comment(skip_nl = true)
- loop do
- skip_tkspace skip_nl
- return unless TkCOMMENT === peek_tk
- get_tk
- end
- end
-
- ##
- # Updates visibility in +container+ from +vis_type+ and +vis+.
-
- def update_visibility container, vis_type, vis, singleton # :nodoc:
- new_methods = []
-
- case vis_type
- when 'module_function' then
- args = parse_symbol_arg
- container.set_visibility_for args, :private, false
-
- container.methods_matching args do |m|
- s_m = m.dup
- record_location s_m
- s_m.singleton = true
- new_methods << s_m
- end
- when 'public_class_method', 'private_class_method' then
- args = parse_symbol_arg
-
- container.methods_matching args, true do |m|
- if m.parent != container then
- m = m.dup
- record_location m
- new_methods << m
- end
-
- m.visibility = vis
- end
- else
- args = parse_symbol_arg
- container.set_visibility_for args, vis, singleton
- end
-
- new_methods.each do |method|
- case method
- when RDoc::AnyMethod then
- container.add_method method
- when RDoc::Attr then
- container.add_attribute method
- end
- method.visibility = vis
- end
- end
-
- ##
- # Prints +message+ to +$stderr+ unless we're being quiet
-
- def warn message
- @options.warn make_message message
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/parser/ruby_tools.rb b/ruby_2_2/lib/rdoc/parser/ruby_tools.rb
deleted file mode 100644
index 654431ea30..0000000000
--- a/ruby_2_2/lib/rdoc/parser/ruby_tools.rb
+++ /dev/null
@@ -1,167 +0,0 @@
-##
-# Collection of methods for writing parsers against RDoc::RubyLex and
-# RDoc::RubyToken
-
-module RDoc::Parser::RubyTools
-
- include RDoc::RubyToken
-
- ##
- # Adds a token listener +obj+, but you should probably use token_listener
-
- def add_token_listener(obj)
- @token_listeners ||= []
- @token_listeners << obj
- end
-
- ##
- # Fetches the next token from the scanner
-
- def get_tk
- tk = nil
-
- if @tokens.empty? then
- tk = @scanner.token
- @read.push @scanner.get_readed
- puts "get_tk1 => #{tk.inspect}" if $TOKEN_DEBUG
- else
- @read.push @unget_read.shift
- tk = @tokens.shift
- puts "get_tk2 => #{tk.inspect}" if $TOKEN_DEBUG
- end
-
- tk = nil if TkEND_OF_SCRIPT === tk
-
- if TkSYMBEG === tk then
- set_token_position tk.line_no, tk.char_no
-
- case tk1 = get_tk
- when TkId, TkOp, TkSTRING, TkDSTRING, TkSTAR, TkAMPER then
- if tk1.respond_to?(:name) then
- tk = Token(TkSYMBOL).set_text(":" + tk1.name)
- else
- tk = Token(TkSYMBOL).set_text(":" + tk1.text)
- end
-
- # remove the identifier we just read to replace it with a symbol
- @token_listeners.each do |obj|
- obj.pop_token
- end if @token_listeners
- else
- tk = tk1
- end
- end
-
- # inform any listeners of our shiny new token
- @token_listeners.each do |obj|
- obj.add_token(tk)
- end if @token_listeners
-
- tk
- end
-
- ##
- # Reads and returns all tokens up to one of +tokens+. Leaves the matched
- # token in the token list.
-
- def get_tk_until(*tokens)
- read = []
-
- loop do
- tk = get_tk
-
- case tk
- when *tokens then
- unget_tk tk
- break
- end
-
- read << tk
- end
-
- read
- end
-
- ##
- # Retrieves a String representation of the read tokens
-
- def get_tkread
- read = @read.join("")
- @read = []
- read
- end
-
- ##
- # Peek equivalent for get_tkread
-
- def peek_read
- @read.join('')
- end
-
- ##
- # Peek at the next token, but don't remove it from the stream
-
- def peek_tk
- unget_tk(tk = get_tk)
- tk
- end
-
- ##
- # Removes the token listener +obj+
-
- def remove_token_listener(obj)
- @token_listeners.delete(obj)
- end
-
- ##
- # Resets the tools
-
- def reset
- @read = []
- @tokens = []
- @unget_read = []
- @nest = 0
- end
-
- ##
- # Skips whitespace tokens including newlines if +skip_nl+ is true
-
- def skip_tkspace(skip_nl = true) # HACK dup
- tokens = []
-
- while TkSPACE === (tk = get_tk) or (skip_nl and TkNL === tk) do
- tokens.push tk
- end
-
- unget_tk tk
- tokens
- end
-
- ##
- # Has +obj+ listen to tokens
-
- def token_listener(obj)
- add_token_listener obj
- yield
- ensure
- remove_token_listener obj
- end
-
- ##
- # Returns +tk+ to the scanner
-
- def unget_tk(tk)
- @tokens.unshift tk
- @unget_read.unshift @read.pop
-
- # Remove this token from any listeners
- @token_listeners.each do |obj|
- obj.pop_token
- end if @token_listeners
-
- nil
- end
-
-end
-
-
diff --git a/ruby_2_2/lib/rdoc/parser/simple.rb b/ruby_2_2/lib/rdoc/parser/simple.rb
deleted file mode 100644
index 65cfc1b2e7..0000000000
--- a/ruby_2_2/lib/rdoc/parser/simple.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-##
-# Parse a non-source file. We basically take the whole thing as one big
-# comment.
-
-class RDoc::Parser::Simple < RDoc::Parser
-
- include RDoc::Parser::Text
-
- parse_files_matching(//)
-
- attr_reader :content # :nodoc:
-
- ##
- # Prepare to parse a plain file
-
- def initialize(top_level, file_name, content, options, stats)
- super
-
- preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
-
- preprocess.handle @content, @top_level
- end
-
- ##
- # Extract the file contents and attach them to the TopLevel as a comment
-
- def scan
- comment = remove_coding_comment @content
- comment = remove_private_comment comment
-
- comment = RDoc::Comment.new comment, @top_level
-
- @top_level.comment = comment
- @top_level
- end
-
- ##
- # Removes the encoding magic comment from +text+
-
- def remove_coding_comment text
- text.sub(/\A# .*coding[=:].*$/, '')
- end
-
- ##
- # Removes private comments.
- #
- # Unlike RDoc::Comment#remove_private this implementation only looks for two
- # dashes at the beginning of the line. Three or more dashes are considered
- # to be a rule and ignored.
-
- def remove_private_comment comment
- # Workaround for gsub encoding for Ruby 1.9.2 and earlier
- empty = ''
- empty.force_encoding comment.encoding if Object.const_defined? :Encoding
-
- comment = comment.gsub(%r%^--\n.*?^\+\+\n?%m, empty)
- comment.sub(%r%^--\n.*%m, empty)
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/parser/text.rb b/ruby_2_2/lib/rdoc/parser/text.rb
deleted file mode 100644
index f973313551..0000000000
--- a/ruby_2_2/lib/rdoc/parser/text.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-##
-# Indicates this parser is text and doesn't contain code constructs.
-#
-# Include this module in a RDoc::Parser subclass to make it show up as a file,
-# not as part of a class or module.
-#--
-# This is not named File to avoid overriding ::File
-
-module RDoc::Parser::Text
-end
-
diff --git a/ruby_2_2/lib/rdoc/rd.rb b/ruby_2_2/lib/rdoc/rd.rb
deleted file mode 100644
index 28c5d286e0..0000000000
--- a/ruby_2_2/lib/rdoc/rd.rb
+++ /dev/null
@@ -1,99 +0,0 @@
-##
-# RDoc::RD implements the RD format from the rdtool gem.
-#
-# To choose RD as your only default format see
-# RDoc::Options@Saved+Options for instructions on setting up a
-# <code>.doc_options</code> file to store your project default.
-#
-# == LICENSE
-#
-# The grammar that produces RDoc::RD::BlockParser and RDoc::RD::InlineParser
-# is included in RDoc under the Ruby License.
-#
-# You can find the original source for rdtool at
-# https://github.com/uwabami/rdtool/
-#
-# You can use, re-distribute or change these files under Ruby's License or GPL.
-#
-# 1. You may make and give away verbatim copies of the source form of the
-# software without restriction, provided that you duplicate all of the
-# original copyright notices and associated disclaimers.
-#
-# 2. You may modify your copy of the software in any way, provided that
-# you do at least ONE of the following:
-#
-# a. place your modifications in the Public Domain or otherwise
-# make them Freely Available, such as by posting said
-# modifications to Usenet or an equivalent medium, or by allowing
-# the author to include your modifications in the software.
-#
-# b. use the modified software only within your corporation or
-# organization.
-#
-# c. give non-standard binaries non-standard names, with
-# instructions on where to get the original software distribution.
-#
-# d. make other distribution arrangements with the author.
-#
-# 3. You may distribute the software in object code or binary form,
-# provided that you do at least ONE of the following:
-#
-# a. distribute the binaries and library files of the software,
-# together with instructions (in the manual page or equivalent)
-# on where to get the original distribution.
-#
-# b. accompany the distribution with the machine-readable source of
-# the software.
-#
-# c. give non-standard binaries non-standard names, with
-# instructions on where to get the original software distribution.
-#
-# d. make other distribution arrangements with the author.
-#
-# 4. You may modify and include the part of the software into any other
-# software (possibly commercial). But some files in the distribution
-# are not written by the author, so that they are not under these terms.
-#
-# For the list of those files and their copying conditions, see the
-# file LEGAL.
-#
-# 5. The scripts and library files supplied as input to or produced as
-# output from the software do not automatically fall under the
-# copyright of the software, but belong to whomever generated them,
-# and may be sold commercially, and may be aggregated with this
-# software.
-#
-# 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE.
-
-class RDoc::RD
-
- ##
- # Parses +rd+ source and returns an RDoc::Markup::Document. If the
- # <tt>=begin</tt> or <tt>=end</tt> lines are missing they will be added.
-
- def self.parse rd
- rd = rd.lines.to_a
-
- if rd.find { |i| /\S/ === i } and !rd.find{|i| /^=begin\b/ === i } then
- rd.unshift("=begin\n").push("=end\n")
- end
-
- parser = RDoc::RD::BlockParser.new
- document = parser.parse rd
-
- # isn't this always true?
- document.parts.shift if RDoc::Markup::BlankLine === document.parts.first
- document.parts.pop if RDoc::Markup::BlankLine === document.parts.last
-
- document
- end
-
- autoload :BlockParser, 'rdoc/rd/block_parser'
- autoload :InlineParser, 'rdoc/rd/inline_parser'
- autoload :Inline, 'rdoc/rd/inline'
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/rd/block_parser.rb b/ruby_2_2/lib/rdoc/rd/block_parser.rb
deleted file mode 100644
index ac754f4200..0000000000
--- a/ruby_2_2/lib/rdoc/rd/block_parser.rb
+++ /dev/null
@@ -1,1055 +0,0 @@
-#
-# DO NOT MODIFY!!!!
-# This file is automatically generated by Racc 1.4.12
-# from Racc grammer file "".
-#
-
-require 'racc/parser.rb'
-
-class RDoc::RD
-
-##
-# RD format parser for headings, paragraphs, lists, verbatim sections that
-# exist as blocks.
-
-class BlockParser < Racc::Parser
-
-
-# :stopdoc:
-
-TMPFILE = ["rdtmp", $$, 0]
-
-MARK_TO_LEVEL = {
- '=' => 1,
- '==' => 2,
- '===' => 3,
- '====' => 4,
- '+' => 5,
- '++' => 6,
-}
-
-# :startdoc:
-
-##
-# Footnotes for this document
-
-attr_reader :footnotes
-
-##
-# Labels for items in this document
-
-attr_reader :labels
-
-##
-# Path to find included files in
-
-attr_accessor :include_path
-
-##
-# Creates a new RDoc::RD::BlockParser. Use #parse to parse an rd-format
-# document.
-
-def initialize
- @inline_parser = RDoc::RD::InlineParser.new self
- @include_path = []
-
- # for testing
- @footnotes = []
- @labels = {}
-end
-
-##
-# Parses +src+ and returns an RDoc::Markup::Document.
-
-def parse src
- @src = src
- @src.push false
-
- @footnotes = []
- @labels = {}
-
- # @i: index(line no.) of src
- @i = 0
-
- # stack for current indentation
- @indent_stack = []
-
- # how indented.
- @current_indent = @indent_stack.join("")
-
- # RDoc::RD::BlockParser for tmp src
- @subparser = nil
-
- # which part is in now
- @in_part = nil
- @part_content = []
-
- @in_verbatim = false
-
- @yydebug = true
-
- document = do_parse
-
- unless @footnotes.empty? then
- blankline = document.parts.pop
-
- document.parts << RDoc::Markup::Rule.new(1)
- document.parts.concat @footnotes
-
- document.parts.push blankline
- end
-
- document
-end
-
-##
-# Returns the next token from the document
-
-def next_token # :nodoc:
- # preprocessing
- # if it is not in RD part
- # => method
- while @in_part != "rd"
- line = @src[@i]
- @i += 1 # next line
-
- case line
- # src end
- when false
- return [false, false]
- # RD part begin
- when /^=begin\s*(?:\bRD\b.*)?\s*$/
- if @in_part # if in non-RD part
- @part_content.push(line)
- else
- @in_part = "rd"
- return [:WHITELINE, "=begin\n"] # <= for textblockand
- end
- # non-RD part begin
- when /^=begin\s+(\w+)/
- part = $1
- if @in_part # if in non-RD part
- @part_content.push(line)
- else
- @in_part = part if @tree.filter[part] # if filter exists
-# p "BEGIN_PART: #{@in_part}" # DEBUG
- end
- # non-RD part end
- when /^=end/
- if @in_part # if in non-RD part
-# p "END_PART: #{@in_part}" # DEBUG
- # make Part-in object
- part = RDoc::RD::Part.new(@part_content.join(""), @tree, "r")
- @part_content.clear
- # call filter, part_out is output(Part object)
- part_out = @tree.filter[@in_part].call(part)
-
- if @tree.filter[@in_part].mode == :rd # if output is RD formatted
- subtree = parse_subtree(part_out.to_a)
- else # if output is target formatted
- basename = TMPFILE.join('.')
- TMPFILE[-1] += 1
- tmpfile = open(@tree.tmp_dir + "/" + basename + ".#{@in_part}", "w")
- tmpfile.print(part_out)
- tmpfile.close
- subtree = parse_subtree(["=begin\n", "<<< #{basename}\n", "=end\n"])
- end
- @in_part = nil
- return [:SUBTREE, subtree]
- end
- else
- if @in_part # if in non-RD part
- @part_content.push(line)
- end
- end
- end
-
- @current_indent = @indent_stack.join("")
- line = @src[@i]
- case line
- when false
- if_current_indent_equal("") do
- [false, false]
- end
- when /^=end/
- if_current_indent_equal("") do
- @in_part = nil
- [:WHITELINE, "=end"] # MUST CHANGE??
- end
- when /^\s*$/
- @i += 1 # next line
- return [:WHITELINE, ':WHITELINE']
- when /^\#/ # comment line
- @i += 1 # next line
- self.next_token()
- when /^(={1,4})(?!=)\s*(?=\S)/, /^(\+{1,2})(?!\+)\s*(?=\S)/
- rest = $' # '
- rest.strip!
- mark = $1
- if_current_indent_equal("") do
- return [:HEADLINE, [MARK_TO_LEVEL[mark], rest]]
- end
- when /^<<<\s*(\S+)/
- file = $1
- if_current_indent_equal("") do
- suffix = file[-3 .. -1]
- if suffix == ".rd" or suffix == ".rb"
- subtree = parse_subtree(get_included(file))
- [:SUBTREE, subtree]
- else
- [:INCLUDE, file]
- end
- end
- when /^(\s*)\*(\s*)/
- rest = $' # '
- newIndent = $2
- if_current_indent_equal($1) do
- if @in_verbatim
- [:STRINGLINE, line]
- else
- @indent_stack.push("\s" << newIndent)
- [:ITEMLISTLINE, rest]
- end
- end
- when /^(\s*)(\(\d+\))(\s*)/
- rest = $' # '
- mark = $2
- newIndent = $3
- if_current_indent_equal($1) do
- if @in_verbatim
- [:STRINGLINE, line]
- else
- @indent_stack.push("\s" * mark.size << newIndent)
- [:ENUMLISTLINE, rest]
- end
- end
- when /^(\s*):(\s*)/
- rest = $' # '
- newIndent = $2
- if_current_indent_equal($1) do
- if @in_verbatim
- [:STRINGLINE, line]
- else
- @indent_stack.push("\s#{$2}")
- [:DESCLISTLINE, rest]
- end
- end
- when /^(\s*)---(?!-|\s*$)/
- indent = $1
- rest = $'
- /\s*/ === rest
- term = $'
- new_indent = $&
- if_current_indent_equal(indent) do
- if @in_verbatim
- [:STRINGLINE, line]
- else
- @indent_stack.push("\s\s\s" + new_indent)
- [:METHODLISTLINE, term]
- end
- end
- when /^(\s*)/
- if_current_indent_equal($1) do
- [:STRINGLINE, line]
- end
- else
- raise "[BUG] parsing error may occured."
- end
-end
-
-##
-# Yields to the given block if +indent+ matches the current indent, otherwise
-# an indentation token is processed.
-
-def if_current_indent_equal(indent)
- indent = indent.sub(/\t/, "\s" * 8)
- if @current_indent == indent
- @i += 1 # next line
- yield
- elsif indent.index(@current_indent) == 0
- @indent_stack.push(indent[@current_indent.size .. -1])
- [:INDENT, ":INDENT"]
- else
- @indent_stack.pop
- [:DEDENT, ":DEDENT"]
- end
-end
-private :if_current_indent_equal
-
-##
-# Cuts off excess whitespace in +src+
-
-def cut_off(src)
- ret = []
- whiteline_buf = []
-
- line = src.shift
- /^\s*/ =~ line
-
- indent = Regexp.quote($&)
- ret.push($')
-
- while line = src.shift
- if /^(\s*)$/ =~ line
- whiteline_buf.push(line)
- elsif /^#{indent}/ =~ line
- unless whiteline_buf.empty?
- ret.concat(whiteline_buf)
- whiteline_buf.clear
- end
- ret.push($')
- else
- raise "[BUG]: probably Parser Error while cutting off.\n"
- end
- end
- ret
-end
-private :cut_off
-
-def set_term_to_element(parent, term)
-# parent.set_term_under_document_struct(term, @tree.document_struct)
- parent.set_term_without_document_struct(term)
-end
-private :set_term_to_element
-
-##
-# Raises a ParseError when invalid formatting is found
-
-def on_error(et, ev, _values)
- prv, cur, nxt = format_line_num(@i, @i+1, @i+2)
-
- raise ParseError, <<Msg
-
-RD syntax error: line #{@i+1}:
- #{prv} |#{@src[@i-1].chomp}
- #{cur}=>|#{@src[@i].chomp}
- #{nxt} |#{@src[@i+1].chomp}
-
-Msg
-end
-
-##
-# Current line number
-
-def line_index
- @i
-end
-
-##
-# Parses subtree +src+
-
-def parse_subtree src
- @subparser ||= RDoc::RD::BlockParser.new
-
- @subparser.parse src
-end
-private :parse_subtree
-
-##
-# Retrieves the content for +file+ from the include_path
-
-def get_included(file)
- included = []
-
- @include_path.each do |dir|
- file_name = File.join dir, file
-
- if File.exist? file_name then
- included = IO.readlines file_name
- break
- end
- end
-
- included
-end
-private :get_included
-
-##
-# Formats line numbers +line_numbers+ prettily
-
-def format_line_num(*line_numbers)
- width = line_numbers.collect{|i| i.to_s.length }.max
- line_numbers.collect{|i| sprintf("%#{width}d", i) }
-end
-private :format_line_num
-
-##
-# Retrieves the content of +values+ as a single String
-
-def content values
- values.map { |value| value.content }.join
-end
-
-##
-# Creates a paragraph for +value+
-
-def paragraph value
- content = cut_off(value).join(' ').rstrip
- contents = @inline_parser.parse content
-
- RDoc::Markup::Paragraph.new(*contents)
-end
-
-##
-# Adds footnote +content+ to the document
-
-def add_footnote content
- index = @footnotes.length / 2 + 1
-
- footmark_link = "{^#{index}}[rdoc-label:footmark-#{index}:foottext-#{index}]"
-
- @footnotes << RDoc::Markup::Paragraph.new(footmark_link, ' ', *content)
- @footnotes << RDoc::Markup::BlankLine.new
-
- index
-end
-
-##
-# Adds label +label+ to the document
-
-def add_label label
- @labels[label] = true
-
- label
-end
-
-# :stopdoc:
-
-##### State transition tables begin ###
-
-racc_action_table = [
- 34, 35, 30, 33, 14, 73, 38, 33, 76, 15,
- 88, 34, 35, 30, 33, 40, 34, 35, 30, 33,
- 40, 65, 34, 35, 30, 33, 14, 73, 77, 14,
- 54, 15, 34, 35, 30, 33, 14, 9, 10, 11,
- 12, 15, 34, 35, 30, 33, 14, 73, 81, 54,
- 38, 15, 34, 35, 30, 33, 14, 73, 40, 67,
- 83, 15, 34, 35, 30, 33, 14, 73, 54, 30,
- 35, 15, 34, 35, 30, 33, 34, 47, 36, 14,
- 59, 15, 34, 35, 30, 33, 14, 73, 38, nil,
- nil, 15, 34, 35, 30, 33, nil, 47, nil, nil,
- nil, 15, 34, 35, 30, 33, 14, 73, nil, nil,
- nil, 15, 34, 35, 30, 33, 14, 73, nil, nil,
- nil, 15, 34, 35, 30, 33, 14, 9, 10, 11,
- 12, 15, 34, 35, 30, 33, 14, 73, nil, nil,
- nil, 15, 34, 35, 30, 33, 14, 73, 61, 63,
- nil, 15, nil, 62, 60, 61, 63, 61, 63, 14,
- 62, 87, 62, nil, 79, 34, 35, 30, 33 ]
-
-racc_action_check = [
- 86, 86, 86, 86, 86, 86, 57, 31, 49, 86,
- 86, 41, 41, 41, 41, 41, 15, 15, 15, 15,
- 15, 41, 45, 45, 45, 45, 45, 45, 51, 34,
- 54, 45, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 85, 85, 85, 85, 85, 85, 56, 33,
- 58, 85, 79, 79, 79, 79, 79, 79, 62, 44,
- 66, 79, 78, 78, 78, 78, 78, 78, 30, 28,
- 25, 78, 24, 24, 24, 24, 22, 24, 1, 35,
- 36, 24, 75, 75, 75, 75, 75, 75, 13, nil,
- nil, 75, 27, 27, 27, 27, nil, 27, nil, nil,
- nil, 27, 74, 74, 74, 74, 74, 74, nil, nil,
- nil, 74, 68, 68, 68, 68, 68, 68, nil, nil,
- nil, 68, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 46, 46, 46, 46, 46, 46, nil, nil,
- nil, 46, 47, 47, 47, 47, 47, 47, 39, 39,
- nil, 47, nil, 39, 39, 82, 82, 64, 64, 52,
- 82, 82, 64, nil, 52, 20, 20, 20, 20 ]
-
-racc_action_pointer = [
- 29, 78, 119, nil, nil, nil, nil, nil, nil, nil,
- nil, nil, nil, 81, nil, 13, nil, nil, nil, nil,
- 162, nil, 73, nil, 69, 66, nil, 89, 64, nil,
- 60, 1, nil, 41, 22, 72, 80, nil, nil, 141,
- nil, 8, nil, nil, 46, 19, 129, 139, nil, -5,
- nil, 15, 152, nil, 22, nil, 35, -1, 43, nil,
- nil, nil, 51, nil, 150, nil, 47, nil, 109, nil,
- nil, nil, nil, nil, 99, 79, nil, nil, 59, 49,
- nil, nil, 148, nil, nil, 39, -3, nil, nil ]
-
-racc_action_default = [
- -2, -73, -1, -4, -5, -6, -7, -8, -9, -10,
- -11, -12, -13, -14, -16, -73, -23, -24, -25, -26,
- -27, -31, -32, -34, -72, -36, -38, -72, -40, -42,
- -59, -44, -46, -59, -63, -65, -73, -3, -15, -73,
- -22, -73, -30, -33, -73, -69, -70, -71, -37, -73,
- -41, -73, -51, -58, -61, -45, -73, -62, -64, 89,
- -17, -19, -73, -21, -18, -28, -73, -35, -66, -53,
- -54, -55, -56, -57, -67, -68, -39, -43, -49, -73,
- -60, -47, -73, -29, -52, -48, -73, -20, -50 ]
-
-racc_goto_table = [
- 4, 39, 4, 68, 74, 75, 5, 6, 5, 6,
- 51, 42, 44, 56, 3, 49, 37, 57, 58, 41,
- 43, 48, 84, 50, 66, 55, 1, 64, 84, 84,
- 45, 46, 42, 45, 46, 2, 85, 86, 80, 84,
- 84, nil, nil, nil, nil, nil, nil, nil, 82, nil,
- nil, nil, 78 ]
-
-racc_goto_check = [
- 4, 10, 4, 31, 31, 31, 5, 6, 5, 6,
- 27, 12, 21, 27, 3, 21, 3, 9, 9, 17,
- 19, 23, 32, 26, 11, 29, 1, 10, 32, 32,
- 5, 6, 12, 5, 6, 2, 31, 31, 33, 32,
- 32, nil, nil, nil, nil, nil, nil, nil, 10, nil,
- nil, nil, 4 ]
-
-racc_goto_pointer = [
- nil, 26, 35, 14, 0, 6, 7, nil, nil, -17,
- -14, -17, -9, nil, nil, nil, nil, 4, nil, -2,
- nil, -12, nil, -4, nil, nil, -5, -20, nil, -6,
- nil, -42, -46, -16 ]
-
-racc_goto_default = [
- nil, nil, nil, nil, 70, 71, 72, 7, 8, 13,
- nil, nil, 21, 16, 17, 18, 19, 20, 22, 23,
- 24, nil, 25, 26, 27, 28, 29, nil, 31, 32,
- 52, nil, 69, 53 ]
-
-racc_reduce_table = [
- 0, 0, :racc_error,
- 1, 15, :_reduce_1,
- 0, 15, :_reduce_2,
- 2, 16, :_reduce_3,
- 1, 16, :_reduce_4,
- 1, 17, :_reduce_5,
- 1, 17, :_reduce_6,
- 1, 17, :_reduce_none,
- 1, 17, :_reduce_8,
- 1, 17, :_reduce_9,
- 1, 17, :_reduce_10,
- 1, 17, :_reduce_11,
- 1, 21, :_reduce_12,
- 1, 22, :_reduce_13,
- 1, 18, :_reduce_14,
- 2, 23, :_reduce_15,
- 1, 23, :_reduce_16,
- 3, 19, :_reduce_17,
- 1, 25, :_reduce_18,
- 2, 24, :_reduce_19,
- 4, 24, :_reduce_20,
- 2, 24, :_reduce_21,
- 1, 24, :_reduce_22,
- 1, 26, :_reduce_none,
- 1, 26, :_reduce_none,
- 1, 26, :_reduce_none,
- 1, 26, :_reduce_none,
- 1, 20, :_reduce_27,
- 3, 20, :_reduce_28,
- 4, 20, :_reduce_29,
- 2, 31, :_reduce_30,
- 1, 31, :_reduce_31,
- 1, 27, :_reduce_32,
- 2, 32, :_reduce_33,
- 1, 32, :_reduce_34,
- 3, 33, :_reduce_35,
- 1, 28, :_reduce_36,
- 2, 36, :_reduce_37,
- 1, 36, :_reduce_38,
- 3, 37, :_reduce_39,
- 1, 29, :_reduce_40,
- 2, 39, :_reduce_41,
- 1, 39, :_reduce_42,
- 3, 40, :_reduce_43,
- 1, 30, :_reduce_44,
- 2, 42, :_reduce_45,
- 1, 42, :_reduce_46,
- 3, 43, :_reduce_47,
- 3, 41, :_reduce_48,
- 2, 41, :_reduce_49,
- 4, 41, :_reduce_50,
- 1, 41, :_reduce_51,
- 2, 45, :_reduce_52,
- 1, 45, :_reduce_none,
- 1, 46, :_reduce_54,
- 1, 46, :_reduce_55,
- 1, 46, :_reduce_none,
- 1, 46, :_reduce_57,
- 1, 44, :_reduce_none,
- 0, 44, :_reduce_none,
- 2, 47, :_reduce_none,
- 1, 47, :_reduce_none,
- 2, 34, :_reduce_62,
- 1, 34, :_reduce_63,
- 2, 38, :_reduce_64,
- 1, 38, :_reduce_65,
- 2, 35, :_reduce_66,
- 2, 35, :_reduce_67,
- 2, 35, :_reduce_68,
- 1, 35, :_reduce_69,
- 1, 35, :_reduce_none,
- 1, 35, :_reduce_71,
- 0, 35, :_reduce_72 ]
-
-racc_reduce_n = 73
-
-racc_shift_n = 89
-
-racc_token_table = {
- false => 0,
- :error => 1,
- :DUMMY => 2,
- :ITEMLISTLINE => 3,
- :ENUMLISTLINE => 4,
- :DESCLISTLINE => 5,
- :METHODLISTLINE => 6,
- :STRINGLINE => 7,
- :WHITELINE => 8,
- :SUBTREE => 9,
- :HEADLINE => 10,
- :INCLUDE => 11,
- :INDENT => 12,
- :DEDENT => 13 }
-
-racc_nt_base = 14
-
-racc_use_result_var = true
-
-Racc_arg = [
- racc_action_table,
- racc_action_check,
- racc_action_default,
- racc_action_pointer,
- racc_goto_table,
- racc_goto_check,
- racc_goto_default,
- racc_goto_pointer,
- racc_nt_base,
- racc_reduce_table,
- racc_token_table,
- racc_shift_n,
- racc_reduce_n,
- racc_use_result_var ]
-
-Racc_token_to_s_table = [
- "$end",
- "error",
- "DUMMY",
- "ITEMLISTLINE",
- "ENUMLISTLINE",
- "DESCLISTLINE",
- "METHODLISTLINE",
- "STRINGLINE",
- "WHITELINE",
- "SUBTREE",
- "HEADLINE",
- "INCLUDE",
- "INDENT",
- "DEDENT",
- "$start",
- "document",
- "blocks",
- "block",
- "textblock",
- "verbatim",
- "lists",
- "headline",
- "include",
- "textblockcontent",
- "verbatimcontent",
- "verbatim_after_lists",
- "list",
- "itemlist",
- "enumlist",
- "desclist",
- "methodlist",
- "lists2",
- "itemlistitems",
- "itemlistitem",
- "first_textblock_in_itemlist",
- "other_blocks_in_list",
- "enumlistitems",
- "enumlistitem",
- "first_textblock_in_enumlist",
- "desclistitems",
- "desclistitem",
- "description_part",
- "methodlistitems",
- "methodlistitem",
- "whitelines",
- "blocks_in_list",
- "block_in_list",
- "whitelines2" ]
-
-Racc_debug_parser = false
-
-##### State transition tables end #####
-
-# reduce 0 omitted
-
-def _reduce_1(val, _values, result)
- result = RDoc::Markup::Document.new(*val[0])
- result
-end
-
-def _reduce_2(val, _values, result)
- raise ParseError, "file empty"
- result
-end
-
-def _reduce_3(val, _values, result)
- result = val[0].concat val[1]
- result
-end
-
-def _reduce_4(val, _values, result)
- result = val[0]
- result
-end
-
-def _reduce_5(val, _values, result)
- result = val
- result
-end
-
-def _reduce_6(val, _values, result)
- result = val
- result
-end
-
-# reduce 7 omitted
-
-def _reduce_8(val, _values, result)
- result = val
- result
-end
-
-def _reduce_9(val, _values, result)
- result = val
- result
-end
-
-def _reduce_10(val, _values, result)
- result = [RDoc::Markup::BlankLine.new]
- result
-end
-
-def _reduce_11(val, _values, result)
- result = val[0].parts
- result
-end
-
-def _reduce_12(val, _values, result)
- # val[0] is like [level, title]
- title = @inline_parser.parse(val[0][1])
- result = RDoc::Markup::Heading.new(val[0][0], title)
-
- result
-end
-
-def _reduce_13(val, _values, result)
- result = RDoc::Markup::Include.new val[0], @include_path
-
- result
-end
-
-def _reduce_14(val, _values, result)
- # val[0] is Array of String
- result = paragraph val[0]
-
- result
-end
-
-def _reduce_15(val, _values, result)
- result << val[1].rstrip
- result
-end
-
-def _reduce_16(val, _values, result)
- result = [val[0].rstrip]
- result
-end
-
-def _reduce_17(val, _values, result)
- # val[1] is Array of String
- content = cut_off val[1]
- result = RDoc::Markup::Verbatim.new(*content)
-
- # imform to lexer.
- @in_verbatim = false
-
- result
-end
-
-def _reduce_18(val, _values, result)
- # val[0] is Array of String
- content = cut_off val[0]
- result = RDoc::Markup::Verbatim.new(*content)
-
- # imform to lexer.
- @in_verbatim = false
-
- result
-end
-
-def _reduce_19(val, _values, result)
- result << val[1]
-
- result
-end
-
-def _reduce_20(val, _values, result)
- result.concat val[2]
-
- result
-end
-
-def _reduce_21(val, _values, result)
- result << "\n"
-
- result
-end
-
-def _reduce_22(val, _values, result)
- result = val
- # inform to lexer.
- @in_verbatim = true
-
- result
-end
-
-# reduce 23 omitted
-
-# reduce 24 omitted
-
-# reduce 25 omitted
-
-# reduce 26 omitted
-
-def _reduce_27(val, _values, result)
- result = val[0]
-
- result
-end
-
-def _reduce_28(val, _values, result)
- result = val[1]
-
- result
-end
-
-def _reduce_29(val, _values, result)
- result = val[1].push(val[2])
-
- result
-end
-
-def _reduce_30(val, _values, result)
- result = val[0] << val[1]
- result
-end
-
-def _reduce_31(val, _values, result)
- result = [val[0]]
- result
-end
-
-def _reduce_32(val, _values, result)
- result = RDoc::Markup::List.new :BULLET, *val[0]
-
- result
-end
-
-def _reduce_33(val, _values, result)
- result.push(val[1])
- result
-end
-
-def _reduce_34(val, _values, result)
- result = val
- result
-end
-
-def _reduce_35(val, _values, result)
- result = RDoc::Markup::ListItem.new nil, val[0], *val[1]
-
- result
-end
-
-def _reduce_36(val, _values, result)
- result = RDoc::Markup::List.new :NUMBER, *val[0]
-
- result
-end
-
-def _reduce_37(val, _values, result)
- result.push(val[1])
- result
-end
-
-def _reduce_38(val, _values, result)
- result = val
- result
-end
-
-def _reduce_39(val, _values, result)
- result = RDoc::Markup::ListItem.new nil, val[0], *val[1]
-
- result
-end
-
-def _reduce_40(val, _values, result)
- result = RDoc::Markup::List.new :NOTE, *val[0]
-
- result
-end
-
-def _reduce_41(val, _values, result)
- result.push(val[1])
- result
-end
-
-def _reduce_42(val, _values, result)
- result = val
- result
-end
-
-def _reduce_43(val, _values, result)
- term = @inline_parser.parse val[0].strip
-
- result = RDoc::Markup::ListItem.new term, *val[1]
-
- result
-end
-
-def _reduce_44(val, _values, result)
- result = RDoc::Markup::List.new :LABEL, *val[0]
-
- result
-end
-
-def _reduce_45(val, _values, result)
- result.push(val[1])
- result
-end
-
-def _reduce_46(val, _values, result)
- result = val
- result
-end
-
-def _reduce_47(val, _values, result)
- result = RDoc::Markup::ListItem.new "<tt>#{val[0].strip}</tt>", *val[1]
-
- result
-end
-
-def _reduce_48(val, _values, result)
- result = [val[1]].concat(val[2])
-
- result
-end
-
-def _reduce_49(val, _values, result)
- result = [val[1]]
-
- result
-end
-
-def _reduce_50(val, _values, result)
- result = val[2]
-
- result
-end
-
-def _reduce_51(val, _values, result)
- result = []
-
- result
-end
-
-def _reduce_52(val, _values, result)
- result.concat val[1]
- result
-end
-
-# reduce 53 omitted
-
-def _reduce_54(val, _values, result)
- result = val
- result
-end
-
-def _reduce_55(val, _values, result)
- result = val
- result
-end
-
-# reduce 56 omitted
-
-def _reduce_57(val, _values, result)
- result = []
- result
-end
-
-# reduce 58 omitted
-
-# reduce 59 omitted
-
-# reduce 60 omitted
-
-# reduce 61 omitted
-
-def _reduce_62(val, _values, result)
- result = paragraph [val[0]].concat(val[1])
-
- result
-end
-
-def _reduce_63(val, _values, result)
- result = paragraph [val[0]]
-
- result
-end
-
-def _reduce_64(val, _values, result)
- result = paragraph [val[0]].concat(val[1])
-
- result
-end
-
-def _reduce_65(val, _values, result)
- result = paragraph [val[0]]
-
- result
-end
-
-def _reduce_66(val, _values, result)
- result = [val[0]].concat(val[1])
-
- result
-end
-
-def _reduce_67(val, _values, result)
- result.concat val[1]
- result
-end
-
-def _reduce_68(val, _values, result)
- result = val[1]
- result
-end
-
-def _reduce_69(val, _values, result)
- result = val
- result
-end
-
-# reduce 70 omitted
-
-def _reduce_71(val, _values, result)
- result = []
- result
-end
-
-def _reduce_72(val, _values, result)
- result = []
- result
-end
-
-def _reduce_none(val, _values, result)
- val[0]
-end
-
-end # class BlockParser
-
-end
diff --git a/ruby_2_2/lib/rdoc/rd/inline.rb b/ruby_2_2/lib/rdoc/rd/inline.rb
deleted file mode 100644
index ee724fb80f..0000000000
--- a/ruby_2_2/lib/rdoc/rd/inline.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-##
-# Inline keeps track of markup and labels to create proper links.
-
-class RDoc::RD::Inline
-
- ##
- # The text of the reference
-
- attr_reader :reference
-
- ##
- # The markup of this reference in RDoc format
-
- attr_reader :rdoc
-
- ##
- # Creates a new Inline for +rdoc+ and +reference+.
- #
- # +rdoc+ may be another Inline or a String. If +reference+ is not given it
- # will use the text from +rdoc+.
-
- def self.new rdoc, reference = rdoc
- if self === rdoc and reference.equal? rdoc then
- rdoc
- else
- super
- end
- end
-
- ##
- # Initializes the Inline with +rdoc+ and +inline+
-
- def initialize rdoc, reference # :not-new:
- @reference = reference.equal?(rdoc) ? reference.dup : reference
-
- # unpack
- @reference = @reference.reference if self.class === @reference
- @rdoc = rdoc
- end
-
- def == other # :nodoc:
- self.class === other and
- @reference == other.reference and @rdoc == other.rdoc
- end
-
- ##
- # Appends +more+ to this inline. +more+ may be a String or another Inline.
-
- def append more
- case more
- when String then
- @reference << more
- @rdoc << more
- when RDoc::RD::Inline then
- @reference << more.reference
- @rdoc << more.rdoc
- else
- raise "unknown thingy #{more}"
- end
-
- self
- end
-
- def inspect # :nodoc:
- "(inline: #{self})"
- end
-
- alias to_s rdoc # :nodoc:
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/rd/inline_parser.rb b/ruby_2_2/lib/rdoc/rd/inline_parser.rb
deleted file mode 100644
index 98b503564d..0000000000
--- a/ruby_2_2/lib/rdoc/rd/inline_parser.rb
+++ /dev/null
@@ -1,1207 +0,0 @@
-#
-# DO NOT MODIFY!!!!
-# This file is automatically generated by Racc 1.4.12
-# from Racc grammer file "".
-#
-
-require 'racc/parser.rb'
-
-require 'strscan'
-
-class RDoc::RD
-
-##
-# RD format parser for inline markup such as emphasis, links, footnotes, etc.
-
-class InlineParser < Racc::Parser
-
-
-# :stopdoc:
-
-EM_OPEN = '((*'
-EM_OPEN_RE = /\A#{Regexp.quote(EM_OPEN)}/
-EM_CLOSE = '*))'
-EM_CLOSE_RE = /\A#{Regexp.quote(EM_CLOSE)}/
-CODE_OPEN = '(({'
-CODE_OPEN_RE = /\A#{Regexp.quote(CODE_OPEN)}/
-CODE_CLOSE = '}))'
-CODE_CLOSE_RE = /\A#{Regexp.quote(CODE_CLOSE)}/
-VAR_OPEN = '((|'
-VAR_OPEN_RE = /\A#{Regexp.quote(VAR_OPEN)}/
-VAR_CLOSE = '|))'
-VAR_CLOSE_RE = /\A#{Regexp.quote(VAR_CLOSE)}/
-KBD_OPEN = '((%'
-KBD_OPEN_RE = /\A#{Regexp.quote(KBD_OPEN)}/
-KBD_CLOSE = '%))'
-KBD_CLOSE_RE = /\A#{Regexp.quote(KBD_CLOSE)}/
-INDEX_OPEN = '((:'
-INDEX_OPEN_RE = /\A#{Regexp.quote(INDEX_OPEN)}/
-INDEX_CLOSE = ':))'
-INDEX_CLOSE_RE = /\A#{Regexp.quote(INDEX_CLOSE)}/
-REF_OPEN = '((<'
-REF_OPEN_RE = /\A#{Regexp.quote(REF_OPEN)}/
-REF_CLOSE = '>))'
-REF_CLOSE_RE = /\A#{Regexp.quote(REF_CLOSE)}/
-FOOTNOTE_OPEN = '((-'
-FOOTNOTE_OPEN_RE = /\A#{Regexp.quote(FOOTNOTE_OPEN)}/
-FOOTNOTE_CLOSE = '-))'
-FOOTNOTE_CLOSE_RE = /\A#{Regexp.quote(FOOTNOTE_CLOSE)}/
-VERB_OPEN = "(('"
-VERB_OPEN_RE = /\A#{Regexp.quote(VERB_OPEN)}/
-VERB_CLOSE = "'))"
-VERB_CLOSE_RE = /\A#{Regexp.quote(VERB_CLOSE)}/
-
-BAR = "|"
-BAR_RE = /\A#{Regexp.quote(BAR)}/
-QUOTE = '"'
-QUOTE_RE = /\A#{Regexp.quote(QUOTE)}/
-SLASH = "/"
-SLASH_RE = /\A#{Regexp.quote(SLASH)}/
-BACK_SLASH = "\\"
-BACK_SLASH_RE = /\A#{Regexp.quote(BACK_SLASH)}/
-URL = "URL:"
-URL_RE = /\A#{Regexp.quote(URL)}/
-
-other_re_mode = Regexp::EXTENDED
-other_re_mode |= Regexp::MULTILINE
-
-OTHER_RE = Regexp.new(
- "\\A.+?(?=#{Regexp.quote(EM_OPEN)}|#{Regexp.quote(EM_CLOSE)}|
- #{Regexp.quote(CODE_OPEN)}|#{Regexp.quote(CODE_CLOSE)}|
- #{Regexp.quote(VAR_OPEN)}|#{Regexp.quote(VAR_CLOSE)}|
- #{Regexp.quote(KBD_OPEN)}|#{Regexp.quote(KBD_CLOSE)}|
- #{Regexp.quote(INDEX_OPEN)}|#{Regexp.quote(INDEX_CLOSE)}|
- #{Regexp.quote(REF_OPEN)}|#{Regexp.quote(REF_CLOSE)}|
- #{Regexp.quote(FOOTNOTE_OPEN)}|#{Regexp.quote(FOOTNOTE_CLOSE)}|
- #{Regexp.quote(VERB_OPEN)}|#{Regexp.quote(VERB_CLOSE)}|
- #{Regexp.quote(BAR)}|
- #{Regexp.quote(QUOTE)}|
- #{Regexp.quote(SLASH)}|
- #{Regexp.quote(BACK_SLASH)}|
- #{Regexp.quote(URL)})", other_re_mode)
-
-# :startdoc:
-
-##
-# Creates a new parser for inline markup in the rd format. The +block_parser+
-# is used to for footnotes and labels in the inline text.
-
-def initialize block_parser
- @block_parser = block_parser
-end
-
-##
-# Parses the +inline+ text from RD format into RDoc format.
-
-def parse inline
- @inline = inline
- @src = StringScanner.new inline
- @pre = ""
- @yydebug = true
- do_parse.to_s
-end
-
-##
-# Returns the next token from the inline text
-
-def next_token
- return [false, false] if @src.eos?
-# p @src.rest if @yydebug
- if ret = @src.scan(EM_OPEN_RE)
- @pre << ret
- [:EM_OPEN, ret]
- elsif ret = @src.scan(EM_CLOSE_RE)
- @pre << ret
- [:EM_CLOSE, ret]
- elsif ret = @src.scan(CODE_OPEN_RE)
- @pre << ret
- [:CODE_OPEN, ret]
- elsif ret = @src.scan(CODE_CLOSE_RE)
- @pre << ret
- [:CODE_CLOSE, ret]
- elsif ret = @src.scan(VAR_OPEN_RE)
- @pre << ret
- [:VAR_OPEN, ret]
- elsif ret = @src.scan(VAR_CLOSE_RE)
- @pre << ret
- [:VAR_CLOSE, ret]
- elsif ret = @src.scan(KBD_OPEN_RE)
- @pre << ret
- [:KBD_OPEN, ret]
- elsif ret = @src.scan(KBD_CLOSE_RE)
- @pre << ret
- [:KBD_CLOSE, ret]
- elsif ret = @src.scan(INDEX_OPEN_RE)
- @pre << ret
- [:INDEX_OPEN, ret]
- elsif ret = @src.scan(INDEX_CLOSE_RE)
- @pre << ret
- [:INDEX_CLOSE, ret]
- elsif ret = @src.scan(REF_OPEN_RE)
- @pre << ret
- [:REF_OPEN, ret]
- elsif ret = @src.scan(REF_CLOSE_RE)
- @pre << ret
- [:REF_CLOSE, ret]
- elsif ret = @src.scan(FOOTNOTE_OPEN_RE)
- @pre << ret
- [:FOOTNOTE_OPEN, ret]
- elsif ret = @src.scan(FOOTNOTE_CLOSE_RE)
- @pre << ret
- [:FOOTNOTE_CLOSE, ret]
- elsif ret = @src.scan(VERB_OPEN_RE)
- @pre << ret
- [:VERB_OPEN, ret]
- elsif ret = @src.scan(VERB_CLOSE_RE)
- @pre << ret
- [:VERB_CLOSE, ret]
- elsif ret = @src.scan(BAR_RE)
- @pre << ret
- [:BAR, ret]
- elsif ret = @src.scan(QUOTE_RE)
- @pre << ret
- [:QUOTE, ret]
- elsif ret = @src.scan(SLASH_RE)
- @pre << ret
- [:SLASH, ret]
- elsif ret = @src.scan(BACK_SLASH_RE)
- @pre << ret
- [:BACK_SLASH, ret]
- elsif ret = @src.scan(URL_RE)
- @pre << ret
- [:URL, ret]
- elsif ret = @src.scan(OTHER_RE)
- @pre << ret
- [:OTHER, ret]
- else
- ret = @src.rest
- @pre << ret
- @src.terminate
- [:OTHER, ret]
- end
-end
-
-##
-# Raises a ParseError when invalid formatting is found
-
-def on_error(et, ev, values)
- lines_of_rest = @src.rest.lines.to_a.length
- prev_words = prev_words_on_error(ev)
- at = 4 + prev_words.length
-
- message = <<-MSG
-RD syntax error: line #{@block_parser.line_index - lines_of_rest}:
-...#{prev_words} #{(ev||'')} #{next_words_on_error()} ...
- MSG
-
- message << " " * at + "^" * (ev ? ev.length : 0) + "\n"
- raise ParseError, message
-end
-
-##
-# Returns words before the error
-
-def prev_words_on_error(ev)
- pre = @pre
- if ev and /#{Regexp.quote(ev)}$/ =~ pre
- pre = $`
- end
- last_line(pre)
-end
-
-##
-# Returns the last line of +src+
-
-def last_line(src)
- if n = src.rindex("\n")
- src[(n+1) .. -1]
- else
- src
- end
-end
-private :last_line
-
-##
-# Returns words following an error
-
-def next_words_on_error
- if n = @src.rest.index("\n")
- @src.rest[0 .. (n-1)]
- else
- @src.rest
- end
-end
-
-##
-# Creates a new RDoc::RD::Inline for the +rdoc+ markup and the raw +reference+
-
-def inline rdoc, reference = rdoc
- RDoc::RD::Inline.new rdoc, reference
-end
-
-# :stopdoc:
-##### State transition tables begin ###
-
-racc_action_table = [
- 63, 64, 65, 153, 81, 62, 76, 78, 79, 87,
- 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
- 77, 80, 152, 63, 64, 65, 61, 81, 62, 76,
- 78, 79, 124, 66, 67, 68, 69, 70, 71, 72,
- 73, 74, 75, 77, 80, 149, 104, 103, 102, 100,
- 101, 99, 115, 116, 117, 164, 105, 106, 107, 108,
- 109, 110, 111, 112, 113, 114, 96, 118, 119, 104,
- 103, 102, 100, 101, 99, 115, 116, 117, 89, 105,
- 106, 107, 108, 109, 110, 111, 112, 113, 114, 88,
- 118, 119, 104, 103, 102, 100, 101, 99, 115, 116,
- 117, 161, 105, 106, 107, 108, 109, 110, 111, 112,
- 113, 114, 86, 118, 119, 104, 103, 102, 100, 101,
- 99, 115, 116, 117, 85, 105, 106, 107, 108, 109,
- 110, 111, 112, 113, 114, 137, 118, 119, 63, 64,
- 65, 61, 81, 62, 76, 78, 79, 84, 66, 67,
- 68, 69, 70, 71, 72, 73, 74, 75, 77, 80,
- 22, 23, 24, 25, 26, 21, 18, 19, 176, 177,
- 13, 173, 14, 154, 15, 175, 16, 137, 17, 42,
- 148, 20, 54, 38, 53, 55, 56, 57, 29, 13,
- 177, 14, nil, 15, nil, 16, nil, 17, nil, nil,
- 20, 22, 23, 24, 25, 26, 21, 18, 19, nil,
- nil, 13, nil, 14, nil, 15, nil, 16, nil, 17,
- nil, nil, 20, 22, 23, 24, 25, 26, 21, 18,
- 19, nil, nil, 13, nil, 14, nil, 15, nil, 16,
- nil, 17, nil, nil, 20, 22, 23, 24, 25, 26,
- 21, 18, 19, nil, nil, 13, nil, 14, nil, 15,
- nil, 16, nil, 17, 145, nil, 20, 54, 133, 53,
- 55, 56, 57, nil, 13, nil, 14, nil, 15, nil,
- 16, nil, 17, nil, nil, 20, 22, 23, 24, 25,
- 26, 21, 18, 19, nil, nil, 13, nil, 14, nil,
- 15, nil, 16, nil, 17, 145, nil, 20, 54, 133,
- 53, 55, 56, 57, nil, 13, nil, 14, nil, 15,
- nil, 16, nil, 17, nil, nil, 20, 22, 23, 24,
- 25, 26, 21, 18, 19, nil, nil, 13, nil, 14,
- nil, 15, nil, 16, nil, 17, 145, nil, 20, 54,
- 133, 53, 55, 56, 57, nil, 13, nil, 14, nil,
- 15, nil, 16, nil, 17, 145, nil, 20, 54, 133,
- 53, 55, 56, 57, nil, 13, nil, 14, nil, 15,
- nil, 16, nil, 17, nil, nil, 20, 22, 23, 24,
- 25, 26, 21, 18, 19, nil, nil, 13, nil, 14,
- nil, 15, nil, 16, 122, 17, nil, 54, 20, 53,
- 55, 56, 57, nil, 13, nil, 14, nil, 15, nil,
- 16, nil, 17, nil, nil, 20, 22, 23, 24, 25,
- 26, 21, 18, 19, nil, nil, 13, nil, 14, nil,
- 15, nil, 16, nil, 17, nil, nil, 20, 135, 136,
- 54, 133, 53, 55, 56, 57, nil, 13, nil, 14,
- nil, 15, nil, 16, nil, 17, nil, nil, 20, 135,
- 136, 54, 133, 53, 55, 56, 57, nil, 13, nil,
- 14, nil, 15, nil, 16, nil, 17, nil, nil, 20,
- 135, 136, 54, 133, 53, 55, 56, 57, nil, 13,
- nil, 14, nil, 15, nil, 16, nil, 17, nil, nil,
- 20, 172, 135, 136, 54, 133, 53, 55, 56, 57,
- 165, 135, 136, 54, 133, 53, 55, 56, 57, 95,
- nil, nil, 54, 91, 53, 55, 56, 57, 174, 135,
- 136, 54, 133, 53, 55, 56, 57, 158, nil, nil,
- 54, nil, 53, 55, 56, 57, 178, 135, 136, 54,
- 133, 53, 55, 56, 57, 145, nil, nil, 54, 133,
- 53, 55, 56, 57, 145, nil, nil, 54, 133, 53,
- 55, 56, 57, 135, 136, 54, 133, 53, 55, 56,
- 57, 135, 136, 54, 133, 53, 55, 56, 57, 135,
- 136, 54, 133, 53, 55, 56, 57, 22, 23, 24,
- 25, 26, 21 ]
-
-racc_action_check = [
- 61, 61, 61, 61, 61, 61, 61, 61, 61, 33,
- 61, 61, 61, 61, 61, 61, 61, 61, 61, 61,
- 61, 61, 61, 59, 59, 59, 59, 59, 59, 59,
- 59, 59, 41, 59, 59, 59, 59, 59, 59, 59,
- 59, 59, 59, 59, 59, 59, 97, 97, 97, 97,
- 97, 97, 97, 97, 97, 125, 97, 97, 97, 97,
- 97, 97, 97, 97, 97, 97, 37, 97, 97, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 35, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 34,
- 38, 38, 155, 155, 155, 155, 155, 155, 155, 155,
- 155, 100, 155, 155, 155, 155, 155, 155, 155, 155,
- 155, 155, 32, 155, 155, 91, 91, 91, 91, 91,
- 91, 91, 91, 91, 31, 91, 91, 91, 91, 91,
- 91, 91, 91, 91, 91, 43, 91, 91, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 29, 20, 20,
- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
- 17, 17, 17, 17, 17, 17, 17, 17, 165, 165,
- 17, 162, 17, 90, 17, 164, 17, 94, 17, 18,
- 58, 17, 18, 18, 18, 18, 18, 18, 1, 18,
- 172, 18, nil, 18, nil, 18, nil, 18, nil, nil,
- 18, 19, 19, 19, 19, 19, 19, 19, 19, nil,
- nil, 19, nil, 19, nil, 19, nil, 19, nil, 19,
- nil, nil, 19, 16, 16, 16, 16, 16, 16, 16,
- 16, nil, nil, 16, nil, 16, nil, 16, nil, 16,
- nil, 16, nil, nil, 16, 15, 15, 15, 15, 15,
- 15, 15, 15, nil, nil, 15, nil, 15, nil, 15,
- nil, 15, nil, 15, 45, nil, 15, 45, 45, 45,
- 45, 45, 45, nil, 45, nil, 45, nil, 45, nil,
- 45, nil, 45, nil, nil, 45, 14, 14, 14, 14,
- 14, 14, 14, 14, nil, nil, 14, nil, 14, nil,
- 14, nil, 14, nil, 14, 146, nil, 14, 146, 146,
- 146, 146, 146, 146, nil, 146, nil, 146, nil, 146,
- nil, 146, nil, 146, nil, nil, 146, 13, 13, 13,
- 13, 13, 13, 13, 13, nil, nil, 13, nil, 13,
- nil, 13, nil, 13, nil, 13, 138, nil, 13, 138,
- 138, 138, 138, 138, 138, nil, 138, nil, 138, nil,
- 138, nil, 138, nil, 138, 44, nil, 138, 44, 44,
- 44, 44, 44, 44, nil, 44, nil, 44, nil, 44,
- nil, 44, nil, 44, nil, nil, 44, 2, 2, 2,
- 2, 2, 2, 2, 2, nil, nil, 2, nil, 2,
- nil, 2, nil, 2, 39, 2, nil, 39, 2, 39,
- 39, 39, 39, nil, 39, nil, 39, nil, 39, nil,
- 39, nil, 39, nil, nil, 39, 0, 0, 0, 0,
- 0, 0, 0, 0, nil, nil, 0, nil, 0, nil,
- 0, nil, 0, nil, 0, nil, nil, 0, 122, 122,
- 122, 122, 122, 122, 122, 122, nil, 122, nil, 122,
- nil, 122, nil, 122, nil, 122, nil, nil, 122, 127,
- 127, 127, 127, 127, 127, 127, 127, nil, 127, nil,
- 127, nil, 127, nil, 127, nil, 127, nil, nil, 127,
- 42, 42, 42, 42, 42, 42, 42, 42, nil, 42,
- nil, 42, nil, 42, nil, 42, nil, 42, nil, nil,
- 42, 159, 159, 159, 159, 159, 159, 159, 159, 159,
- 126, 126, 126, 126, 126, 126, 126, 126, 126, 36,
- nil, nil, 36, 36, 36, 36, 36, 36, 163, 163,
- 163, 163, 163, 163, 163, 163, 163, 92, nil, nil,
- 92, nil, 92, 92, 92, 92, 171, 171, 171, 171,
- 171, 171, 171, 171, 171, 142, nil, nil, 142, 142,
- 142, 142, 142, 142, 52, nil, nil, 52, 52, 52,
- 52, 52, 52, 95, 95, 95, 95, 95, 95, 95,
- 95, 168, 168, 168, 168, 168, 168, 168, 168, 158,
- 158, 158, 158, 158, 158, 158, 158, 27, 27, 27,
- 27, 27, 27 ]
-
-racc_action_pointer = [
- 423, 188, 384, nil, nil, nil, nil, nil, nil, nil,
- nil, nil, nil, 324, 283, 242, 220, 157, 176, 198,
- 135, nil, nil, nil, nil, nil, nil, 604, nil, 147,
- nil, 110, 96, -9, 69, 56, 526, 43, 66, 401,
- nil, 28, 486, 130, 362, 261, nil, nil, nil, nil,
- nil, nil, 571, nil, nil, nil, nil, nil, 169, 20,
- nil, -3, nil, nil, nil, nil, nil, nil, nil, nil,
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
- 150, 112, 544, nil, 172, 579, nil, 43, nil, nil,
- 95, nil, nil, nil, nil, nil, nil, nil, nil, nil,
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
- nil, nil, 444, nil, nil, 52, 517, 465, nil, nil,
- nil, nil, nil, nil, nil, nil, nil, nil, 343, nil,
- nil, nil, 562, nil, nil, nil, 302, nil, nil, nil,
- nil, nil, nil, nil, nil, 89, nil, nil, 595, 508,
- nil, nil, 168, 535, 171, 164, nil, nil, 587, nil,
- nil, 553, 185, nil, nil, nil, nil, nil, nil ]
-
-racc_action_default = [
- -138, -138, -1, -3, -4, -5, -6, -7, -8, -9,
- -10, -11, -12, -138, -138, -138, -138, -138, -138, -138,
- -138, -103, -104, -105, -106, -107, -108, -111, -110, -138,
- -2, -138, -138, -138, -138, -138, -138, -138, -138, -27,
- -26, -35, -138, -58, -41, -40, -47, -48, -49, -50,
- -51, -52, -63, -66, -67, -68, -69, -70, -138, -138,
- -112, -138, -116, -117, -118, -119, -120, -121, -122, -123,
- -124, -125, -126, -127, -128, -129, -130, -131, -132, -133,
- -134, -135, -137, -109, 179, -13, -14, -15, -16, -17,
- -138, -138, -23, -22, -33, -138, -19, -24, -79, -80,
- -138, -82, -83, -84, -85, -86, -87, -88, -89, -90,
- -91, -92, -93, -94, -95, -96, -97, -98, -99, -100,
- -25, -35, -138, -58, -28, -138, -59, -42, -46, -55,
- -56, -65, -71, -72, -75, -76, -77, -31, -38, -44,
- -53, -54, -57, -61, -73, -74, -39, -62, -101, -102,
- -136, -113, -114, -115, -18, -20, -21, -33, -138, -138,
- -78, -81, -138, -59, -36, -37, -64, -45, -59, -43,
- -60, -138, -34, -36, -37, -29, -30, -32, -34 ]
-
-racc_goto_table = [
- 126, 44, 125, 43, 144, 144, 160, 93, 97, 52,
- 166, 82, 144, 41, 40, 39, 138, 146, 169, 147,
- 167, 94, 44, 1, 123, 129, 169, 52, 36, 37,
- 52, 90, 59, 92, 121, 120, 31, 32, 33, 34,
- 35, 170, 58, 166, 83, 30, 170, 166, 151, nil,
- 150, nil, 166, 159, 8, 166, 8, nil, nil, nil,
- nil, 155, nil, 156, 160, nil, nil, 8, 8, 8,
- 8, 8, nil, 8, 4, nil, 4, 157, nil, nil,
- 163, nil, 162, 52, nil, 168, nil, 4, 4, 4,
- 4, 4, nil, 4, nil, nil, nil, nil, 144, nil,
- nil, nil, 144, nil, nil, 129, 144, 144, nil, 5,
- 129, 5, nil, nil, nil, nil, 171, 6, nil, 6,
- nil, nil, 5, 5, 5, 5, 5, 11, 5, 11,
- 6, 6, 6, 6, 6, 7, 6, 7, nil, nil,
- 11, 11, 11, 11, 11, nil, 11, nil, 7, 7,
- 7, 7, 7, nil, 7 ]
-
-racc_goto_check = [
- 22, 24, 21, 23, 36, 36, 37, 18, 16, 34,
- 35, 41, 36, 20, 19, 17, 25, 25, 28, 32,
- 29, 23, 24, 1, 23, 24, 28, 34, 13, 15,
- 34, 14, 38, 17, 20, 19, 1, 1, 1, 1,
- 1, 33, 1, 35, 39, 3, 33, 35, 42, nil,
- 41, nil, 35, 22, 8, 35, 8, nil, nil, nil,
- nil, 16, nil, 18, 37, nil, nil, 8, 8, 8,
- 8, 8, nil, 8, 4, nil, 4, 23, nil, nil,
- 22, nil, 21, 34, nil, 22, nil, 4, 4, 4,
- 4, 4, nil, 4, nil, nil, nil, nil, 36, nil,
- nil, nil, 36, nil, nil, 24, 36, 36, nil, 5,
- 24, 5, nil, nil, nil, nil, 22, 6, nil, 6,
- nil, nil, 5, 5, 5, 5, 5, 11, 5, 11,
- 6, 6, 6, 6, 6, 7, 6, 7, nil, nil,
- 11, 11, 11, 11, 11, nil, 11, nil, 7, 7,
- 7, 7, 7, nil, 7 ]
-
-racc_goto_pointer = [
- nil, 23, nil, 43, 74, 109, 117, 135, 54, nil,
- nil, 127, nil, 10, -5, 11, -30, -3, -29, -4,
- -5, -40, -42, -15, -17, -28, nil, nil, -120, -107,
- nil, nil, -33, -101, -9, -116, -40, -91, 12, 17,
- nil, -9, -13 ]
-
-racc_goto_default = [
- nil, nil, 2, 3, 46, 47, 48, 49, 50, 9,
- 10, 51, 12, nil, nil, nil, nil, nil, nil, nil,
- nil, nil, nil, nil, 140, nil, 45, 127, 139, 128,
- 141, 130, 142, 143, 132, 131, 134, 98, nil, 28,
- 27, nil, 60 ]
-
-racc_reduce_table = [
- 0, 0, :racc_error,
- 1, 27, :_reduce_none,
- 2, 28, :_reduce_2,
- 1, 28, :_reduce_3,
- 1, 29, :_reduce_none,
- 1, 29, :_reduce_none,
- 1, 29, :_reduce_none,
- 1, 29, :_reduce_none,
- 1, 29, :_reduce_none,
- 1, 29, :_reduce_none,
- 1, 29, :_reduce_none,
- 1, 29, :_reduce_none,
- 1, 29, :_reduce_none,
- 3, 30, :_reduce_13,
- 3, 31, :_reduce_14,
- 3, 32, :_reduce_15,
- 3, 33, :_reduce_16,
- 3, 34, :_reduce_17,
- 4, 35, :_reduce_18,
- 3, 35, :_reduce_19,
- 2, 40, :_reduce_20,
- 2, 40, :_reduce_21,
- 1, 40, :_reduce_22,
- 1, 40, :_reduce_23,
- 2, 41, :_reduce_24,
- 2, 41, :_reduce_25,
- 1, 41, :_reduce_26,
- 1, 41, :_reduce_27,
- 2, 39, :_reduce_none,
- 4, 39, :_reduce_29,
- 4, 39, :_reduce_30,
- 2, 43, :_reduce_31,
- 4, 43, :_reduce_32,
- 1, 44, :_reduce_33,
- 3, 44, :_reduce_34,
- 1, 45, :_reduce_none,
- 3, 45, :_reduce_36,
- 3, 45, :_reduce_37,
- 2, 46, :_reduce_38,
- 2, 46, :_reduce_39,
- 1, 46, :_reduce_40,
- 1, 46, :_reduce_41,
- 1, 47, :_reduce_none,
- 2, 51, :_reduce_43,
- 1, 51, :_reduce_44,
- 2, 53, :_reduce_45,
- 1, 53, :_reduce_46,
- 1, 50, :_reduce_none,
- 1, 50, :_reduce_none,
- 1, 50, :_reduce_none,
- 1, 50, :_reduce_none,
- 1, 50, :_reduce_none,
- 1, 50, :_reduce_none,
- 1, 54, :_reduce_none,
- 1, 54, :_reduce_none,
- 1, 55, :_reduce_none,
- 1, 55, :_reduce_none,
- 1, 56, :_reduce_57,
- 1, 52, :_reduce_58,
- 1, 57, :_reduce_59,
- 2, 58, :_reduce_60,
- 1, 58, :_reduce_none,
- 2, 49, :_reduce_62,
- 1, 49, :_reduce_none,
- 2, 48, :_reduce_64,
- 1, 48, :_reduce_none,
- 1, 60, :_reduce_none,
- 1, 60, :_reduce_none,
- 1, 60, :_reduce_none,
- 1, 60, :_reduce_none,
- 1, 60, :_reduce_none,
- 1, 62, :_reduce_none,
- 1, 62, :_reduce_none,
- 1, 59, :_reduce_none,
- 1, 59, :_reduce_none,
- 1, 61, :_reduce_none,
- 1, 61, :_reduce_none,
- 1, 61, :_reduce_none,
- 2, 42, :_reduce_78,
- 1, 42, :_reduce_none,
- 1, 63, :_reduce_none,
- 2, 63, :_reduce_none,
- 1, 63, :_reduce_none,
- 1, 63, :_reduce_none,
- 1, 63, :_reduce_none,
- 1, 63, :_reduce_none,
- 1, 63, :_reduce_none,
- 1, 63, :_reduce_none,
- 1, 63, :_reduce_none,
- 1, 63, :_reduce_none,
- 1, 63, :_reduce_none,
- 1, 63, :_reduce_none,
- 1, 63, :_reduce_none,
- 1, 63, :_reduce_none,
- 1, 63, :_reduce_none,
- 1, 63, :_reduce_none,
- 1, 63, :_reduce_none,
- 1, 63, :_reduce_none,
- 1, 63, :_reduce_none,
- 1, 63, :_reduce_none,
- 1, 63, :_reduce_none,
- 3, 36, :_reduce_101,
- 3, 37, :_reduce_102,
- 1, 65, :_reduce_none,
- 1, 65, :_reduce_none,
- 1, 65, :_reduce_none,
- 1, 65, :_reduce_none,
- 1, 65, :_reduce_none,
- 1, 65, :_reduce_none,
- 2, 66, :_reduce_109,
- 1, 66, :_reduce_none,
- 1, 38, :_reduce_111,
- 1, 67, :_reduce_none,
- 2, 67, :_reduce_113,
- 2, 67, :_reduce_114,
- 2, 67, :_reduce_115,
- 1, 68, :_reduce_none,
- 1, 68, :_reduce_none,
- 1, 68, :_reduce_none,
- 1, 68, :_reduce_none,
- 1, 68, :_reduce_none,
- 1, 68, :_reduce_none,
- 1, 68, :_reduce_none,
- 1, 68, :_reduce_none,
- 1, 68, :_reduce_none,
- 1, 68, :_reduce_none,
- 1, 68, :_reduce_none,
- 1, 68, :_reduce_none,
- 1, 68, :_reduce_none,
- 1, 68, :_reduce_none,
- 1, 68, :_reduce_none,
- 1, 68, :_reduce_none,
- 1, 68, :_reduce_none,
- 1, 68, :_reduce_none,
- 1, 68, :_reduce_none,
- 1, 68, :_reduce_none,
- 2, 64, :_reduce_136,
- 1, 64, :_reduce_none ]
-
-racc_reduce_n = 138
-
-racc_shift_n = 179
-
-racc_token_table = {
- false => 0,
- :error => 1,
- :EX_LOW => 2,
- :QUOTE => 3,
- :BAR => 4,
- :SLASH => 5,
- :BACK_SLASH => 6,
- :URL => 7,
- :OTHER => 8,
- :REF_OPEN => 9,
- :FOOTNOTE_OPEN => 10,
- :FOOTNOTE_CLOSE => 11,
- :EX_HIGH => 12,
- :EM_OPEN => 13,
- :EM_CLOSE => 14,
- :CODE_OPEN => 15,
- :CODE_CLOSE => 16,
- :VAR_OPEN => 17,
- :VAR_CLOSE => 18,
- :KBD_OPEN => 19,
- :KBD_CLOSE => 20,
- :INDEX_OPEN => 21,
- :INDEX_CLOSE => 22,
- :REF_CLOSE => 23,
- :VERB_OPEN => 24,
- :VERB_CLOSE => 25 }
-
-racc_nt_base = 26
-
-racc_use_result_var = true
-
-Racc_arg = [
- racc_action_table,
- racc_action_check,
- racc_action_default,
- racc_action_pointer,
- racc_goto_table,
- racc_goto_check,
- racc_goto_default,
- racc_goto_pointer,
- racc_nt_base,
- racc_reduce_table,
- racc_token_table,
- racc_shift_n,
- racc_reduce_n,
- racc_use_result_var ]
-
-Racc_token_to_s_table = [
- "$end",
- "error",
- "EX_LOW",
- "QUOTE",
- "BAR",
- "SLASH",
- "BACK_SLASH",
- "URL",
- "OTHER",
- "REF_OPEN",
- "FOOTNOTE_OPEN",
- "FOOTNOTE_CLOSE",
- "EX_HIGH",
- "EM_OPEN",
- "EM_CLOSE",
- "CODE_OPEN",
- "CODE_CLOSE",
- "VAR_OPEN",
- "VAR_CLOSE",
- "KBD_OPEN",
- "KBD_CLOSE",
- "INDEX_OPEN",
- "INDEX_CLOSE",
- "REF_CLOSE",
- "VERB_OPEN",
- "VERB_CLOSE",
- "$start",
- "content",
- "elements",
- "element",
- "emphasis",
- "code",
- "var",
- "keyboard",
- "index",
- "reference",
- "footnote",
- "verb",
- "normal_str_ele",
- "substitute",
- "ref_label",
- "ref_label2",
- "ref_url_strings",
- "filename",
- "element_label",
- "element_label2",
- "ref_subst_content",
- "ref_subst_content_q",
- "ref_subst_strings_q",
- "ref_subst_strings_first",
- "ref_subst_ele2",
- "ref_subst_eles",
- "ref_subst_str_ele_first",
- "ref_subst_eles_q",
- "ref_subst_ele",
- "ref_subst_ele_q",
- "ref_subst_str_ele",
- "ref_subst_str_ele_q",
- "ref_subst_strings",
- "ref_subst_string3",
- "ref_subst_string",
- "ref_subst_string_q",
- "ref_subst_string2",
- "ref_url_string",
- "verb_strings",
- "normal_string",
- "normal_strings",
- "verb_string",
- "verb_normal_string" ]
-
-Racc_debug_parser = false
-
-##### State transition tables end #####
-
-# reduce 0 omitted
-
-# reduce 1 omitted
-
-def _reduce_2(val, _values, result)
- result.append val[1]
- result
-end
-
-def _reduce_3(val, _values, result)
- result = val[0]
- result
-end
-
-# reduce 4 omitted
-
-# reduce 5 omitted
-
-# reduce 6 omitted
-
-# reduce 7 omitted
-
-# reduce 8 omitted
-
-# reduce 9 omitted
-
-# reduce 10 omitted
-
-# reduce 11 omitted
-
-# reduce 12 omitted
-
-def _reduce_13(val, _values, result)
- content = val[1]
- result = inline "<em>#{content}</em>", content
-
- result
-end
-
-def _reduce_14(val, _values, result)
- content = val[1]
- result = inline "<code>#{content}</code>", content
-
- result
-end
-
-def _reduce_15(val, _values, result)
- content = val[1]
- result = inline "+#{content}+", content
-
- result
-end
-
-def _reduce_16(val, _values, result)
- content = val[1]
- result = inline "<tt>#{content}</tt>", content
-
- result
-end
-
-def _reduce_17(val, _values, result)
- label = val[1]
- @block_parser.add_label label.reference
- result = "<span id=\"label-#{label}\">#{label}</span>"
-
- result
-end
-
-def _reduce_18(val, _values, result)
- result = "{#{val[1]}}[#{val[2].join}]"
-
- result
-end
-
-def _reduce_19(val, _values, result)
- scheme, inline = val[1]
-
- result = "{#{inline}}[#{scheme}#{inline.reference}]"
-
- result
-end
-
-def _reduce_20(val, _values, result)
- result = [nil, inline(val[1])]
-
- result
-end
-
-def _reduce_21(val, _values, result)
- result = [
- 'rdoc-label:',
- inline("#{val[0].reference}/#{val[1].reference}")
- ]
-
- result
-end
-
-def _reduce_22(val, _values, result)
- result = ['rdoc-label:', val[0].reference]
-
- result
-end
-
-def _reduce_23(val, _values, result)
- result = ['rdoc-label:', "#{val[0].reference}/"]
-
- result
-end
-
-def _reduce_24(val, _values, result)
- result = [nil, inline(val[1])]
-
- result
-end
-
-def _reduce_25(val, _values, result)
- result = [
- 'rdoc-label:',
- inline("#{val[0].reference}/#{val[1].reference}")
- ]
-
- result
-end
-
-def _reduce_26(val, _values, result)
- result = ['rdoc-label:', val[0]]
-
- result
-end
-
-def _reduce_27(val, _values, result)
- ref = val[0].reference
- result = ['rdoc-label:', inline(ref, "#{ref}/")]
-
- result
-end
-
-# reduce 28 omitted
-
-def _reduce_29(val, _values, result)
- result = val[1]
- result
-end
-
-def _reduce_30(val, _values, result)
- result = val[1]
- result
-end
-
-def _reduce_31(val, _values, result)
- result = inline val[0]
-
- result
-end
-
-def _reduce_32(val, _values, result)
- result = inline "\"#{val[1]}\""
-
- result
-end
-
-def _reduce_33(val, _values, result)
- result = inline val[0]
-
- result
-end
-
-def _reduce_34(val, _values, result)
- result = inline "\"#{val[1]}\""
-
- result
-end
-
-# reduce 35 omitted
-
-def _reduce_36(val, _values, result)
- result = val[1]
- result
-end
-
-def _reduce_37(val, _values, result)
- result = inline val[1]
- result
-end
-
-def _reduce_38(val, _values, result)
- result = val[0].append val[1]
-
- result
-end
-
-def _reduce_39(val, _values, result)
- result = val[0].append val[1]
-
- result
-end
-
-def _reduce_40(val, _values, result)
- result = val[0]
-
- result
-end
-
-def _reduce_41(val, _values, result)
- result = inline val[0]
-
- result
-end
-
-# reduce 42 omitted
-
-def _reduce_43(val, _values, result)
- result = val[0].append val[1]
-
- result
-end
-
-def _reduce_44(val, _values, result)
- result = inline val[0]
-
- result
-end
-
-def _reduce_45(val, _values, result)
- result = val[0].append val[1]
-
- result
-end
-
-def _reduce_46(val, _values, result)
- result = val[0]
-
- result
-end
-
-# reduce 47 omitted
-
-# reduce 48 omitted
-
-# reduce 49 omitted
-
-# reduce 50 omitted
-
-# reduce 51 omitted
-
-# reduce 52 omitted
-
-# reduce 53 omitted
-
-# reduce 54 omitted
-
-# reduce 55 omitted
-
-# reduce 56 omitted
-
-def _reduce_57(val, _values, result)
- result = val[0]
-
- result
-end
-
-def _reduce_58(val, _values, result)
- result = inline val[0]
-
- result
-end
-
-def _reduce_59(val, _values, result)
- result = inline val[0]
-
- result
-end
-
-def _reduce_60(val, _values, result)
- result << val[1]
- result
-end
-
-# reduce 61 omitted
-
-def _reduce_62(val, _values, result)
- result << val[1]
-
- result
-end
-
-# reduce 63 omitted
-
-def _reduce_64(val, _values, result)
- result << val[1]
-
- result
-end
-
-# reduce 65 omitted
-
-# reduce 66 omitted
-
-# reduce 67 omitted
-
-# reduce 68 omitted
-
-# reduce 69 omitted
-
-# reduce 70 omitted
-
-# reduce 71 omitted
-
-# reduce 72 omitted
-
-# reduce 73 omitted
-
-# reduce 74 omitted
-
-# reduce 75 omitted
-
-# reduce 76 omitted
-
-# reduce 77 omitted
-
-def _reduce_78(val, _values, result)
- result << val[1]
- result
-end
-
-# reduce 79 omitted
-
-# reduce 80 omitted
-
-# reduce 81 omitted
-
-# reduce 82 omitted
-
-# reduce 83 omitted
-
-# reduce 84 omitted
-
-# reduce 85 omitted
-
-# reduce 86 omitted
-
-# reduce 87 omitted
-
-# reduce 88 omitted
-
-# reduce 89 omitted
-
-# reduce 90 omitted
-
-# reduce 91 omitted
-
-# reduce 92 omitted
-
-# reduce 93 omitted
-
-# reduce 94 omitted
-
-# reduce 95 omitted
-
-# reduce 96 omitted
-
-# reduce 97 omitted
-
-# reduce 98 omitted
-
-# reduce 99 omitted
-
-# reduce 100 omitted
-
-def _reduce_101(val, _values, result)
- index = @block_parser.add_footnote val[1].rdoc
- result = "{*#{index}}[rdoc-label:foottext-#{index}:footmark-#{index}]"
-
- result
-end
-
-def _reduce_102(val, _values, result)
- result = inline "<tt>#{val[1]}</tt>", val[1]
-
- result
-end
-
-# reduce 103 omitted
-
-# reduce 104 omitted
-
-# reduce 105 omitted
-
-# reduce 106 omitted
-
-# reduce 107 omitted
-
-# reduce 108 omitted
-
-def _reduce_109(val, _values, result)
- result << val[1]
- result
-end
-
-# reduce 110 omitted
-
-def _reduce_111(val, _values, result)
- result = inline val[0]
-
- result
-end
-
-# reduce 112 omitted
-
-def _reduce_113(val, _values, result)
- result = val[1]
- result
-end
-
-def _reduce_114(val, _values, result)
- result = val[1]
- result
-end
-
-def _reduce_115(val, _values, result)
- result = val[1]
- result
-end
-
-# reduce 116 omitted
-
-# reduce 117 omitted
-
-# reduce 118 omitted
-
-# reduce 119 omitted
-
-# reduce 120 omitted
-
-# reduce 121 omitted
-
-# reduce 122 omitted
-
-# reduce 123 omitted
-
-# reduce 124 omitted
-
-# reduce 125 omitted
-
-# reduce 126 omitted
-
-# reduce 127 omitted
-
-# reduce 128 omitted
-
-# reduce 129 omitted
-
-# reduce 130 omitted
-
-# reduce 131 omitted
-
-# reduce 132 omitted
-
-# reduce 133 omitted
-
-# reduce 134 omitted
-
-# reduce 135 omitted
-
-def _reduce_136(val, _values, result)
- result << val[1]
- result
-end
-
-# reduce 137 omitted
-
-def _reduce_none(val, _values, result)
- val[0]
-end
-
-end # class InlineParser
-
-end
diff --git a/ruby_2_2/lib/rdoc/rdoc.rb b/ruby_2_2/lib/rdoc/rdoc.rb
deleted file mode 100644
index 4d45d47978..0000000000
--- a/ruby_2_2/lib/rdoc/rdoc.rb
+++ /dev/null
@@ -1,570 +0,0 @@
-require 'rdoc'
-
-require 'find'
-require 'fileutils'
-require 'pathname'
-require 'time'
-
-##
-# This is the driver for generating RDoc output. It handles file parsing and
-# generation of output.
-#
-# To use this class to generate RDoc output via the API, the recommended way
-# is:
-#
-# rdoc = RDoc::RDoc.new
-# options = rdoc.load_options # returns an RDoc::Options instance
-# # set extra options
-# rdoc.document options
-#
-# You can also generate output like the +rdoc+ executable:
-#
-# rdoc = RDoc::RDoc.new
-# rdoc.document argv
-#
-# Where +argv+ is an array of strings, each corresponding to an argument you'd
-# give rdoc on the command line. See <tt>rdoc --help<tt> for details.
-
-class RDoc::RDoc
-
- @current = nil
-
- ##
- # This is the list of supported output generators
-
- GENERATORS = {}
-
- ##
- # File pattern to exclude
-
- attr_accessor :exclude
-
- ##
- # Generator instance used for creating output
-
- attr_accessor :generator
-
- ##
- # Hash of files and their last modified times.
-
- attr_reader :last_modified
-
- ##
- # RDoc options
-
- attr_accessor :options
-
- ##
- # Accessor for statistics. Available after each call to parse_files
-
- attr_reader :stats
-
- ##
- # The current documentation store
-
- attr_reader :store
-
- ##
- # Add +klass+ that can generate output after parsing
-
- def self.add_generator(klass)
- name = klass.name.sub(/^RDoc::Generator::/, '').downcase
- GENERATORS[name] = klass
- end
-
- ##
- # Active RDoc::RDoc instance
-
- def self.current
- @current
- end
-
- ##
- # Sets the active RDoc::RDoc instance
-
- def self.current= rdoc
- @current = rdoc
- end
-
- ##
- # Creates a new RDoc::RDoc instance. Call #document to parse files and
- # generate documentation.
-
- def initialize
- @current = nil
- @exclude = nil
- @generator = nil
- @last_modified = {}
- @old_siginfo = nil
- @options = nil
- @stats = nil
- @store = nil
- end
-
- ##
- # Report an error message and exit
-
- def error(msg)
- raise RDoc::Error, msg
- end
-
- ##
- # Gathers a set of parseable files from the files and directories listed in
- # +files+.
-
- def gather_files files
- files = ["."] if files.empty?
-
- file_list = normalized_file_list files, true, @exclude
-
- file_list = file_list.uniq
-
- file_list = remove_unparseable file_list
-
- file_list.sort
- end
-
- ##
- # Turns RDoc from stdin into HTML
-
- def handle_pipe
- @html = RDoc::Markup::ToHtml.new @options
-
- parser = RDoc::Text::MARKUP_FORMAT[@options.markup]
-
- document = parser.parse $stdin.read
-
- out = @html.convert document
-
- $stdout.write out
- end
-
- ##
- # Installs a siginfo handler that prints the current filename.
-
- def install_siginfo_handler
- return unless Signal.list.include? 'INFO'
-
- @old_siginfo = trap 'INFO' do
- puts @current if @current
- end
- end
-
- ##
- # Loads options from .rdoc_options if the file exists, otherwise creates a
- # new RDoc::Options instance.
-
- def load_options
- options_file = File.expand_path '.rdoc_options'
- return RDoc::Options.new unless File.exist? options_file
-
- RDoc.load_yaml
-
- parse_error = if Object.const_defined? :Psych then
- Psych::SyntaxError
- else
- ArgumentError
- end
-
- begin
- options = YAML.load_file '.rdoc_options'
- rescue *parse_error
- end
-
- raise RDoc::Error, "#{options_file} is not a valid rdoc options file" unless
- RDoc::Options === options
-
- options
- end
-
- ##
- # Create an output dir if it doesn't exist. If it does exist, but doesn't
- # contain the flag file <tt>created.rid</tt> then we refuse to use it, as
- # we may clobber some manually generated documentation
-
- def setup_output_dir(dir, force)
- flag_file = output_flag_file dir
-
- last = {}
-
- if @options.dry_run then
- # do nothing
- elsif File.exist? dir then
- error "#{dir} exists and is not a directory" unless File.directory? dir
-
- begin
- open flag_file do |io|
- unless force then
- Time.parse io.gets
-
- io.each do |line|
- file, time = line.split "\t", 2
- time = Time.parse(time) rescue next
- last[file] = time
- end
- end
- end
- rescue SystemCallError, TypeError
- error <<-ERROR
-
-Directory #{dir} already exists, but it looks like it isn't an RDoc directory.
-
-Because RDoc doesn't want to risk destroying any of your existing files,
-you'll need to specify a different output directory name (using the --op <dir>
-option)
-
- ERROR
- end unless @options.force_output
- else
- FileUtils.mkdir_p dir
- FileUtils.touch flag_file
- end
-
- last
- end
-
- ##
- # Sets the current documentation tree to +store+ and sets the store's rdoc
- # driver to this instance.
-
- def store= store
- @store = store
- @store.rdoc = self
- end
-
- ##
- # Update the flag file in an output directory.
-
- def update_output_dir(op_dir, time, last = {})
- return if @options.dry_run or not @options.update_output_dir
-
- open output_flag_file(op_dir), "w" do |f|
- f.puts time.rfc2822
- last.each do |n, t|
- f.puts "#{n}\t#{t.rfc2822}"
- end
- end
- end
-
- ##
- # Return the path name of the flag file in an output directory.
-
- def output_flag_file(op_dir)
- File.join op_dir, "created.rid"
- end
-
- ##
- # The .document file contains a list of file and directory name patterns,
- # representing candidates for documentation. It may also contain comments
- # (starting with '#')
-
- def parse_dot_doc_file in_dir, filename
- # read and strip comments
- patterns = File.read(filename).gsub(/#.*/, '')
-
- result = []
-
- patterns.split.each do |patt|
- candidates = Dir.glob(File.join(in_dir, patt))
- result.concat normalized_file_list(candidates)
- end
-
- result
- end
-
- ##
- # Given a list of files and directories, create a list of all the Ruby
- # files they contain.
- #
- # If +force_doc+ is true we always add the given files, if false, only
- # add files that we guarantee we can parse. It is true when looking at
- # files given on the command line, false when recursing through
- # subdirectories.
- #
- # The effect of this is that if you want a file with a non-standard
- # extension parsed, you must name it explicitly.
-
- def normalized_file_list(relative_files, force_doc = false,
- exclude_pattern = nil)
- file_list = []
-
- relative_files.each do |rel_file_name|
- next if rel_file_name.end_with? 'created.rid'
- next if exclude_pattern && exclude_pattern =~ rel_file_name
- stat = File.stat rel_file_name rescue next
-
- case type = stat.ftype
- when "file" then
- next if last_modified = @last_modified[rel_file_name] and
- stat.mtime.to_i <= last_modified.to_i
-
- if force_doc or RDoc::Parser.can_parse(rel_file_name) then
- file_list << rel_file_name.sub(/^\.\//, '')
- @last_modified[rel_file_name] = stat.mtime
- end
- when "directory" then
- next if rel_file_name == "CVS" || rel_file_name == ".svn"
-
- created_rid = File.join rel_file_name, "created.rid"
- next if File.file? created_rid
-
- dot_doc = File.join rel_file_name, RDoc::DOT_DOC_FILENAME
-
- if File.file? dot_doc then
- file_list << parse_dot_doc_file(rel_file_name, dot_doc)
- else
- file_list << list_files_in_directory(rel_file_name)
- end
- else
- warn "rdoc can't parse the #{type} #{rel_file_name}"
- end
- end
-
- file_list.flatten
- end
-
- ##
- # Return a list of the files to be processed in a directory. We know that
- # this directory doesn't have a .document file, so we're looking for real
- # files. However we may well contain subdirectories which must be tested
- # for .document files.
-
- def list_files_in_directory dir
- files = Dir.glob File.join(dir, "*")
-
- normalized_file_list files, false, @options.exclude
- end
-
- ##
- # Parses +filename+ and returns an RDoc::TopLevel
-
- def parse_file filename
- if Object.const_defined? :Encoding then
- encoding = @options.encoding
- filename = filename.encode encoding
- end
-
- @stats.add_file filename
-
- return if RDoc::Parser.binary? filename
-
- content = RDoc::Encoding.read_file filename, encoding
-
- return unless content
-
- filename_path = Pathname(filename).expand_path
- relative_path = filename_path.relative_path_from @options.root
-
- if @options.page_dir and
- relative_path.to_s.start_with? @options.page_dir.to_s then
- relative_path =
- relative_path.relative_path_from @options.page_dir
- end
-
- top_level = @store.add_file filename, relative_path.to_s
-
- parser = RDoc::Parser.for top_level, filename, content, @options, @stats
-
- return unless parser
-
- parser.scan
-
- # restart documentation for the classes & modules found
- top_level.classes_or_modules.each do |cm|
- cm.done_documenting = false
- end
-
- top_level
-
- rescue Errno::EACCES => e
- $stderr.puts <<-EOF
-Unable to read #{filename}, #{e.message}
-
-Please check the permissions for this file. Perhaps you do not have access to
-it or perhaps the original author's permissions are to restrictive. If the
-this is not your library please report a bug to the author.
- EOF
- rescue => e
- $stderr.puts <<-EOF
-Before reporting this, could you check that the file you're documenting
-has proper syntax:
-
- #{Gem.ruby} -c #{filename}
-
-RDoc is not a full Ruby parser and will fail when fed invalid ruby programs.
-
-The internal error was:
-
-\t(#{e.class}) #{e.message}
-
- EOF
-
- $stderr.puts e.backtrace.join("\n\t") if $DEBUG_RDOC
-
- raise e
- nil
- end
-
- ##
- # Parse each file on the command line, recursively entering directories.
-
- def parse_files files
- file_list = gather_files files
- @stats = RDoc::Stats.new @store, file_list.length, @options.verbosity
-
- return [] if file_list.empty?
-
- @stats.begin_adding
-
- file_info = file_list.map do |filename|
- @current = filename
- parse_file filename
- end.compact
-
- @stats.done_adding
-
- file_info
- end
-
- ##
- # Removes file extensions known to be unparseable from +files+ and TAGS
- # files for emacs and vim.
-
- def remove_unparseable files
- files.reject do |file|
- file =~ /\.(?:class|eps|erb|scpt\.txt|ttf|yml)$/i or
- (file =~ /tags$/i and
- open(file, 'rb') { |io|
- io.read(100) =~ /\A(\f\n[^,]+,\d+$|!_TAG_)/
- })
- end
- end
-
- ##
- # Generates documentation or a coverage report depending upon the settings
- # in +options+.
- #
- # +options+ can be either an RDoc::Options instance or an array of strings
- # equivalent to the strings that would be passed on the command line like
- # <tt>%w[-q -o doc -t My\ Doc\ Title]</tt>. #document will automatically
- # call RDoc::Options#finish if an options instance was given.
- #
- # For a list of options, see either RDoc::Options or <tt>rdoc --help</tt>.
- #
- # By default, output will be stored in a directory called "doc" below the
- # current directory, so make sure you're somewhere writable before invoking.
-
- def document options
- self.store = RDoc::Store.new
-
- if RDoc::Options === options then
- @options = options
- @options.finish
- else
- @options = load_options
- @options.parse options
- end
-
- if @options.pipe then
- handle_pipe
- exit
- end
-
- @exclude = @options.exclude
-
- unless @options.coverage_report then
- @last_modified = setup_output_dir @options.op_dir, @options.force_update
- end
-
- @store.encoding = @options.encoding if @options.respond_to? :encoding
- @store.dry_run = @options.dry_run
- @store.main = @options.main_page
- @store.title = @options.title
- @store.path = @options.op_dir
-
- @start_time = Time.now
-
- @store.load_cache
-
- file_info = parse_files @options.files
-
- @options.default_title = "RDoc Documentation"
-
- @store.complete @options.visibility
-
- @stats.coverage_level = @options.coverage_report
-
- if @options.coverage_report then
- puts
-
- puts @stats.report.accept RDoc::Markup::ToRdoc.new
- elsif file_info.empty? then
- $stderr.puts "\nNo newer files." unless @options.quiet
- else
- gen_klass = @options.generator
-
- @generator = gen_klass.new @store, @options
-
- generate
- end
-
- if @stats and (@options.coverage_report or not @options.quiet) then
- puts
- puts @stats.summary.accept RDoc::Markup::ToRdoc.new
- end
-
- exit @stats.fully_documented? if @options.coverage_report
- end
-
- ##
- # Generates documentation for +file_info+ (from #parse_files) into the
- # output dir using the generator selected
- # by the RDoc options
-
- def generate
- Dir.chdir @options.op_dir do
- unless @options.quiet then
- $stderr.puts "\nGenerating #{@generator.class.name.sub(/^.*::/, '')} format into #{Dir.pwd}..."
- end
-
- @generator.generate
- update_output_dir '.', @start_time, @last_modified
- end
- end
-
- ##
- # Removes a siginfo handler and replaces the previous
-
- def remove_siginfo_handler
- return unless Signal.list.key? 'INFO'
-
- handler = @old_siginfo || 'DEFAULT'
-
- trap 'INFO', handler
- end
-
-end
-
-begin
- require 'rubygems'
-
- if Gem.respond_to? :find_files then
- rdoc_extensions = Gem.find_files 'rdoc/discover'
-
- rdoc_extensions.each do |extension|
- begin
- load extension
- rescue => e
- warn "error loading #{extension.inspect}: #{e.message} (#{e.class})"
- warn "\t#{e.backtrace.join "\n\t"}" if $DEBUG
- end
- end
- end
-rescue LoadError
-end
-
-# require built-in generators after discovery in case they've been replaced
-require 'rdoc/generator/darkfish'
-require 'rdoc/generator/ri'
-require 'rdoc/generator/pot'
-
diff --git a/ruby_2_2/lib/rdoc/require.rb b/ruby_2_2/lib/rdoc/require.rb
deleted file mode 100644
index a3d4bd18c0..0000000000
--- a/ruby_2_2/lib/rdoc/require.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-##
-# A file loaded by \#require
-
-class RDoc::Require < RDoc::CodeObject
-
- ##
- # Name of the required file
-
- attr_accessor :name
-
- ##
- # Creates a new Require that loads +name+ with +comment+
-
- def initialize(name, comment)
- super()
- @name = name.gsub(/'|"/, "") #'
- @top_level = nil
- self.comment = comment
- end
-
- def inspect # :nodoc:
- "#<%s:0x%x require '%s' in %s>" % [
- self.class,
- object_id,
- @name,
- parent_file_name,
- ]
- end
-
- def to_s # :nodoc:
- "require #{name} in: #{parent}"
- end
-
- ##
- # The RDoc::TopLevel corresponding to this require, or +nil+ if not found.
-
- def top_level
- @top_level ||= begin
- tl = RDoc::TopLevel.all_files_hash[name + '.rb']
-
- if tl.nil? and RDoc::TopLevel.all_files.first.full_name =~ %r(^lib/) then
- # second chance
- tl = RDoc::TopLevel.all_files_hash['lib/' + name + '.rb']
- end
-
- tl
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/ri.rb b/ruby_2_2/lib/rdoc/ri.rb
deleted file mode 100644
index 8b35e0fa2f..0000000000
--- a/ruby_2_2/lib/rdoc/ri.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require 'rdoc'
-
-##
-# Namespace for the ri command line tool's implementation.
-#
-# See <tt>ri --help</tt> for details.
-
-module RDoc::RI
-
- ##
- # Base RI error class
-
- class Error < RDoc::Error; end
-
- autoload :Driver, 'rdoc/ri/driver'
- autoload :Paths, 'rdoc/ri/paths'
- autoload :Store, 'rdoc/ri/store'
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/ri/driver.rb b/ruby_2_2/lib/rdoc/ri/driver.rb
deleted file mode 100644
index 39064c1384..0000000000
--- a/ruby_2_2/lib/rdoc/ri/driver.rb
+++ /dev/null
@@ -1,1497 +0,0 @@
-require 'abbrev'
-require 'optparse'
-
-begin
- require 'readline'
-rescue LoadError
-end
-
-begin
- require 'win32console'
-rescue LoadError
-end
-
-require 'rdoc'
-
-##
-# For RubyGems backwards compatibility
-
-require 'rdoc/ri/formatter'
-
-##
-# The RI driver implements the command-line ri tool.
-#
-# The driver supports:
-# * loading RI data from:
-# * Ruby's standard library
-# * RubyGems
-# * ~/.rdoc
-# * A user-supplied directory
-# * Paging output (uses RI_PAGER environment variable, PAGER environment
-# variable or the less, more and pager programs)
-# * Interactive mode with tab-completion
-# * Abbreviated names (ri Zl shows Zlib documentation)
-# * Colorized output
-# * Merging output from multiple RI data sources
-
-class RDoc::RI::Driver
-
- ##
- # Base Driver error class
-
- class Error < RDoc::RI::Error; end
-
- ##
- # Raised when a name isn't found in the ri data stores
-
- class NotFoundError < Error
-
- ##
- # Name that wasn't found
-
- alias name message
-
- def message # :nodoc:
- "Nothing known about #{super}"
- end
- end
-
- ##
- # Show all method documentation following a class or module
-
- attr_accessor :show_all
-
- ##
- # An RDoc::RI::Store for each entry in the RI path
-
- attr_accessor :stores
-
- ##
- # Controls the user of the pager vs $stdout
-
- attr_accessor :use_stdout
-
- ##
- # Default options for ri
-
- def self.default_options
- options = {}
- options[:interactive] = false
- options[:profile] = false
- options[:show_all] = false
- options[:use_cache] = true
- options[:use_stdout] = !$stdout.tty?
- options[:width] = 72
-
- # By default all standard paths are used.
- options[:use_system] = true
- options[:use_site] = true
- options[:use_home] = true
- options[:use_gems] = true
- options[:extra_doc_dirs] = []
-
- return options
- end
-
- ##
- # Dump +data_path+ using pp
-
- def self.dump data_path
- require 'pp'
-
- open data_path, 'rb' do |io|
- pp Marshal.load(io.read)
- end
- end
-
- ##
- # Parses +argv+ and returns a Hash of options
-
- def self.process_args argv
- options = default_options
-
- opts = OptionParser.new do |opt|
- opt.accept File do |file,|
- File.readable?(file) and not File.directory?(file) and file
- end
-
- opt.program_name = File.basename $0
- opt.version = RDoc::VERSION
- opt.release = nil
- opt.summary_indent = ' ' * 4
-
- opt.banner = <<-EOT
-Usage: #{opt.program_name} [options] [names...]
-
-Where name can be:
-
- Class | Module | Module::Class
-
- Class::method | Class#method | Class.method | method
-
- gem_name: | gem_name:README | gem_name:History
-
-All class names may be abbreviated to their minimum unambiguous form. If a name
-is ambiguous, all valid options will be listed.
-
-A '.' matches either class or instance methods, while #method
-matches only instance and ::method matches only class methods.
-
-README and other files may be displayed by prefixing them with the gem name
-they're contained in. If the gem name is followed by a ':' all files in the
-gem will be shown. The file name extension may be omitted where it is
-unambiguous.
-
-For example:
-
- #{opt.program_name} Fil
- #{opt.program_name} File
- #{opt.program_name} File.new
- #{opt.program_name} zip
- #{opt.program_name} rdoc:README
-
-Note that shell quoting or escaping may be required for method names containing
-punctuation:
-
- #{opt.program_name} 'Array.[]'
- #{opt.program_name} compact\\!
-
-To see the default directories ri will search, run:
-
- #{opt.program_name} --list-doc-dirs
-
-Specifying the --system, --site, --home, --gems or --doc-dir options will
-limit ri to searching only the specified directories.
-
-ri options may be set in the 'RI' environment variable.
-
-The ri pager can be set with the 'RI_PAGER' environment variable or the
-'PAGER' environment variable.
- EOT
-
- opt.separator nil
- opt.separator "Options:"
-
- opt.separator nil
-
- opt.on("--[no-]interactive", "-i",
- "In interactive mode you can repeatedly",
- "look up methods with autocomplete.") do |interactive|
- options[:interactive] = interactive
- end
-
- opt.separator nil
-
- opt.on("--[no-]all", "-a",
- "Show all documentation for a class or",
- "module.") do |show_all|
- options[:show_all] = show_all
- end
-
- opt.separator nil
-
- opt.on("--[no-]list", "-l",
- "List classes ri knows about.") do |list|
- options[:list] = list
- end
-
- opt.separator nil
-
- opt.on("--[no-]pager",
- "Send output directly to stdout,",
- "rather than to a pager.") do |use_pager|
- options[:use_stdout] = !use_pager
- end
-
- opt.separator nil
-
- opt.on("-T",
- "Synonym for --no-pager") do
- options[:use_stdout] = true
- end
-
- opt.separator nil
-
- opt.on("--width=WIDTH", "-w", OptionParser::DecimalInteger,
- "Set the width of the output.") do |width|
- options[:width] = width
- end
-
- opt.separator nil
-
- opt.on("--server [PORT]", Integer,
- "Run RDoc server on the given port.",
- "The default port is 8214.") do |port|
- options[:server] = port || 8214
- end
-
- opt.separator nil
-
- formatters = RDoc::Markup.constants.grep(/^To[A-Z][a-z]+$/).sort
- formatters = formatters.sort.map do |formatter|
- formatter.to_s.sub('To', '').downcase
- end
- formatters -= %w[html label test] # remove useless output formats
-
- opt.on("--format=NAME", "-f",
- "Uses the selected formatter. The default",
- "formatter is bs for paged output and ansi",
- "otherwise. Valid formatters are:",
- formatters.join(' '), formatters) do |value|
- options[:formatter] = RDoc::Markup.const_get "To#{value.capitalize}"
- end
-
- opt.separator nil
- opt.separator "Data source options:"
- opt.separator nil
-
- opt.on("--[no-]list-doc-dirs",
- "List the directories from which ri will",
- "source documentation on stdout and exit.") do |list_doc_dirs|
- options[:list_doc_dirs] = list_doc_dirs
- end
-
- opt.separator nil
-
- opt.on("--doc-dir=DIRNAME", "-d", Array,
- "List of directories from which to source",
- "documentation in addition to the standard",
- "directories. May be repeated.") do |value|
- value.each do |dir|
- unless File.directory? dir then
- raise OptionParser::InvalidArgument, "#{dir} is not a directory"
- end
-
- options[:extra_doc_dirs] << File.expand_path(dir)
- end
- end
-
- opt.separator nil
-
- opt.on("--no-standard-docs",
- "Do not include documentation from",
- "the Ruby standard library, site_lib,",
- "installed gems, or ~/.rdoc.",
- "Use with --doc-dir") do
- options[:use_system] = false
- options[:use_site] = false
- options[:use_gems] = false
- options[:use_home] = false
- end
-
- opt.separator nil
-
- opt.on("--[no-]system",
- "Include documentation from Ruby's standard",
- "library. Defaults to true.") do |value|
- options[:use_system] = value
- end
-
- opt.separator nil
-
- opt.on("--[no-]site",
- "Include documentation from libraries",
- "installed in site_lib.",
- "Defaults to true.") do |value|
- options[:use_site] = value
- end
-
- opt.separator nil
-
- opt.on("--[no-]gems",
- "Include documentation from RubyGems.",
- "Defaults to true.") do |value|
- options[:use_gems] = value
- end
-
- opt.separator nil
-
- opt.on("--[no-]home",
- "Include documentation stored in ~/.rdoc.",
- "Defaults to true.") do |value|
- options[:use_home] = value
- end
-
- opt.separator nil
- opt.separator "Debug options:"
- opt.separator nil
-
- opt.on("--[no-]profile",
- "Run with the ruby profiler") do |value|
- options[:profile] = value
- end
-
- opt.separator nil
-
- opt.on("--dump=CACHE", File,
- "Dumps data from an ri cache or data file") do |value|
- options[:dump_path] = value
- end
- end
-
- argv = ENV['RI'].to_s.split.concat argv
-
- opts.parse! argv
-
- options[:names] = argv
-
- options[:use_stdout] ||= !$stdout.tty?
- options[:use_stdout] ||= options[:interactive]
- options[:width] ||= 72
-
- options
-
- rescue OptionParser::InvalidArgument, OptionParser::InvalidOption => e
- puts opts
- puts
- puts e
- exit 1
- end
-
- ##
- # Runs the ri command line executable using +argv+
-
- def self.run argv = ARGV
- options = process_args argv
-
- if options[:dump_path] then
- dump options[:dump_path]
- return
- end
-
- ri = new options
- ri.run
- end
-
- ##
- # Creates a new driver using +initial_options+ from ::process_args
-
- def initialize initial_options = {}
- @paging = false
- @classes = nil
-
- options = self.class.default_options.update(initial_options)
-
- @formatter_klass = options[:formatter]
-
- require 'profile' if options[:profile]
-
- @names = options[:names]
- @list = options[:list]
-
- @doc_dirs = []
- @stores = []
-
- RDoc::RI::Paths.each(options[:use_system], options[:use_site],
- options[:use_home], options[:use_gems],
- *options[:extra_doc_dirs]) do |path, type|
- @doc_dirs << path
-
- store = RDoc::RI::Store.new path, type
- store.load_cache
- @stores << store
- end
-
- @list_doc_dirs = options[:list_doc_dirs]
-
- @interactive = options[:interactive]
- @server = options[:server]
- @use_stdout = options[:use_stdout]
- @show_all = options[:show_all]
-
- # pager process for jruby
- @jruby_pager_process = nil
- end
-
- ##
- # Adds paths for undocumented classes +also_in+ to +out+
-
- def add_also_in out, also_in
- return if also_in.empty?
-
- out << RDoc::Markup::Rule.new(1)
- out << RDoc::Markup::Paragraph.new("Also found in:")
-
- paths = RDoc::Markup::Verbatim.new
- also_in.each do |store|
- paths.parts.push store.friendly_path, "\n"
- end
- out << paths
- end
-
- ##
- # Adds a class header to +out+ for class +name+ which is described in
- # +classes+.
-
- def add_class out, name, classes
- heading = if classes.all? { |klass| klass.module? } then
- name
- else
- superclass = classes.map do |klass|
- klass.superclass unless klass.module?
- end.compact.shift || 'Object'
-
- superclass = superclass.full_name unless String === superclass
-
- "#{name} < #{superclass}"
- end
-
- out << RDoc::Markup::Heading.new(1, heading)
- out << RDoc::Markup::BlankLine.new
- end
-
- ##
- # Adds "(from ...)" to +out+ for +store+
-
- def add_from out, store
- out << RDoc::Markup::Paragraph.new("(from #{store.friendly_path})")
- end
-
- ##
- # Adds +extends+ to +out+
-
- def add_extends out, extends
- add_extension_modules out, 'Extended by', extends
- end
-
- ##
- # Adds a list of +extensions+ to this module of the given +type+ to +out+.
- # add_includes and add_extends call this, so you should use those directly.
-
- def add_extension_modules out, type, extensions
- return if extensions.empty?
-
- out << RDoc::Markup::Rule.new(1)
- out << RDoc::Markup::Heading.new(1, "#{type}:")
-
- extensions.each do |modules, store|
- if modules.length == 1 then
- add_extension_modules_single out, store, modules.first
- else
- add_extension_modules_multiple out, store, modules
- end
- end
- end
-
- ##
- # Renders multiple included +modules+ from +store+ to +out+.
-
- def add_extension_modules_multiple out, store, modules # :nodoc:
- out << RDoc::Markup::Paragraph.new("(from #{store.friendly_path})")
-
- wout, with = modules.partition { |incl| incl.comment.empty? }
-
- out << RDoc::Markup::BlankLine.new unless with.empty?
-
- with.each do |incl|
- out << RDoc::Markup::Paragraph.new(incl.name)
- out << RDoc::Markup::BlankLine.new
- out << incl.comment
- end
-
- unless wout.empty? then
- verb = RDoc::Markup::Verbatim.new
-
- wout.each do |incl|
- verb.push incl.name, "\n"
- end
-
- out << verb
- end
- end
-
- ##
- # Adds a single extension module +include+ from +store+ to +out+
-
- def add_extension_modules_single out, store, include # :nodoc:
- name = include.name
- path = store.friendly_path
- out << RDoc::Markup::Paragraph.new("#{name} (from #{path})")
-
- if include.comment then
- out << RDoc::Markup::BlankLine.new
- out << include.comment
- end
- end
-
- ##
- # Adds +includes+ to +out+
-
- def add_includes out, includes
- add_extension_modules out, 'Includes', includes
- end
-
- ##
- # Looks up the method +name+ and adds it to +out+
-
- def add_method out, name
- filtered = lookup_method name
-
- method_out = method_document name, filtered
-
- out.concat method_out.parts
- end
-
- ##
- # Adds documentation for all methods in +klass+ to +out+
-
- def add_method_documentation out, klass
- klass.method_list.each do |method|
- begin
- add_method out, method.full_name
- rescue NotFoundError
- next
- end
- end
- end
-
- ##
- # Adds a list of +methods+ to +out+ with a heading of +name+
-
- def add_method_list out, methods, name
- return if methods.empty?
-
- out << RDoc::Markup::Heading.new(1, "#{name}:")
- out << RDoc::Markup::BlankLine.new
-
- if @use_stdout and !@interactive then
- out.concat methods.map { |method|
- RDoc::Markup::Verbatim.new method
- }
- else
- out << RDoc::Markup::IndentedParagraph.new(2, methods.join(', '))
- end
-
- out << RDoc::Markup::BlankLine.new
- end
-
- ##
- # Returns ancestor classes of +klass+
-
- def ancestors_of klass
- ancestors = []
-
- unexamined = [klass]
- seen = []
-
- loop do
- break if unexamined.empty?
- current = unexamined.shift
- seen << current
-
- stores = classes[current]
-
- break unless stores and not stores.empty?
-
- klasses = stores.map do |store|
- store.ancestors[current]
- end.flatten.uniq
-
- klasses = klasses - seen
-
- ancestors.concat klasses
- unexamined.concat klasses
- end
-
- ancestors.reverse
- end
-
- ##
- # For RubyGems backwards compatibility
-
- def class_cache # :nodoc:
- end
-
- ##
- # Builds a RDoc::Markup::Document from +found+, +klasess+ and +includes+
-
- def class_document name, found, klasses, includes, extends
- also_in = []
-
- out = RDoc::Markup::Document.new
-
- add_class out, name, klasses
-
- add_includes out, includes
- add_extends out, extends
-
- found.each do |store, klass|
- render_class out, store, klass, also_in
- end
-
- add_also_in out, also_in
-
- out
- end
-
- ##
- # Adds the class +comment+ to +out+.
-
- def class_document_comment out, comment # :nodoc:
- unless comment.empty? then
- out << RDoc::Markup::Rule.new(1)
-
- if comment.merged? then
- parts = comment.parts
- parts = parts.zip [RDoc::Markup::BlankLine.new] * parts.length
- parts.flatten!
- parts.pop
-
- out.concat parts
- else
- out << comment
- end
- end
- end
-
- ##
- # Adds the constants from +klass+ to the Document +out+.
-
- def class_document_constants out, klass # :nodoc:
- return if klass.constants.empty?
-
- out << RDoc::Markup::Heading.new(1, "Constants:")
- out << RDoc::Markup::BlankLine.new
- list = RDoc::Markup::List.new :NOTE
-
- constants = klass.constants.sort_by { |constant| constant.name }
-
- list.items.concat constants.map { |constant|
- parts = constant.comment.parts if constant.comment
- parts << RDoc::Markup::Paragraph.new('[not documented]') if
- parts.empty?
-
- RDoc::Markup::ListItem.new(constant.name, *parts)
- }
-
- out << list
- out << RDoc::Markup::BlankLine.new
- end
-
- ##
- # Hash mapping a known class or module to the stores it can be loaded from
-
- def classes
- return @classes if @classes
-
- @classes = {}
-
- @stores.each do |store|
- store.cache[:modules].each do |mod|
- # using default block causes searched-for modules to be added
- @classes[mod] ||= []
- @classes[mod] << store
- end
- end
-
- @classes
- end
-
- ##
- # Returns the stores wherein +name+ is found along with the classes,
- # extends and includes that match it
-
- def classes_and_includes_and_extends_for name
- klasses = []
- extends = []
- includes = []
-
- found = @stores.map do |store|
- begin
- klass = store.load_class name
- klasses << klass
- extends << [klass.extends, store] if klass.extends
- includes << [klass.includes, store] if klass.includes
- [store, klass]
- rescue RDoc::Store::MissingFileError
- end
- end.compact
-
- extends.reject! do |modules,| modules.empty? end
- includes.reject! do |modules,| modules.empty? end
-
- [found, klasses, includes, extends]
- end
-
- ##
- # Completes +name+ based on the caches. For Readline
-
- def complete name
- completions = []
-
- klass, selector, method = parse_name name
-
- complete_klass name, klass, selector, method, completions
- complete_method name, klass, selector, completions
-
- completions.sort.uniq
- end
-
- def complete_klass name, klass, selector, method, completions # :nodoc:
- klasses = classes.keys
-
- # may need to include Foo when given Foo::
- klass_name = method ? name : klass
-
- if name !~ /#|\./ then
- completions.replace klasses.grep(/^#{Regexp.escape klass_name}[^:]*$/)
- completions.concat klasses.grep(/^#{Regexp.escape name}[^:]*$/) if
- name =~ /::$/
-
- completions << klass if classes.key? klass # to complete a method name
- elsif selector then
- completions << klass if classes.key? klass
- elsif classes.key? klass_name then
- completions << klass_name
- end
- end
-
- def complete_method name, klass, selector, completions # :nodoc:
- if completions.include? klass and name =~ /#|\.|::/ then
- methods = list_methods_matching name
-
- if not methods.empty? then
- # remove Foo if given Foo:: and a method was found
- completions.delete klass
- elsif selector then
- # replace Foo with Foo:: as given
- completions.delete klass
- completions << "#{klass}#{selector}"
- end
-
- completions.concat methods
- end
- end
-
- ##
- # Converts +document+ to text and writes it to the pager
-
- def display document
- page do |io|
- text = document.accept formatter(io)
-
- io.write text
- end
- end
-
- ##
- # Outputs formatted RI data for class +name+. Groups undocumented classes
-
- def display_class name
- return if name =~ /#|\./
-
- found, klasses, includes, extends =
- classes_and_includes_and_extends_for name
-
- return if found.empty?
-
- out = class_document name, found, klasses, includes, extends
-
- display out
- end
-
- ##
- # Outputs formatted RI data for method +name+
-
- def display_method name
- out = RDoc::Markup::Document.new
-
- add_method out, name
-
- display out
- end
-
- ##
- # Outputs formatted RI data for the class or method +name+.
- #
- # Returns true if +name+ was found, false if it was not an alternative could
- # be guessed, raises an error if +name+ couldn't be guessed.
-
- def display_name name
- if name =~ /\w:(\w|$)/ then
- display_page name
- return true
- end
-
- return true if display_class name
-
- display_method name if name =~ /::|#|\./
-
- true
- rescue NotFoundError
- matches = list_methods_matching name if name =~ /::|#|\./
- matches = classes.keys.grep(/^#{Regexp.escape name}/) if matches.empty?
-
- raise if matches.empty?
-
- page do |io|
- io.puts "#{name} not found, maybe you meant:"
- io.puts
- io.puts matches.sort.join("\n")
- end
-
- false
- end
-
- ##
- # Displays each name in +name+
-
- def display_names names
- names.each do |name|
- name = expand_name name
-
- display_name name
- end
- end
-
- ##
- # Outputs formatted RI data for page +name+.
-
- def display_page name
- store_name, page_name = name.split ':', 2
-
- store = @stores.find { |s| s.source == store_name }
-
- return display_page_list store if page_name.empty?
-
- pages = store.cache[:pages]
-
- unless pages.include? page_name then
- found_names = pages.select do |n|
- n =~ /#{Regexp.escape page_name}\.[^.]+$/
- end
-
- if found_names.length.zero? then
- return display_page_list store, pages
- elsif found_names.length > 1 then
- return display_page_list store, found_names, page_name
- end
-
- page_name = found_names.first
- end
-
- page = store.load_page page_name
-
- display page.comment
- end
-
- ##
- # Outputs a formatted RI page list for the pages in +store+.
-
- def display_page_list store, pages = store.cache[:pages], search = nil
- out = RDoc::Markup::Document.new
-
- title = if search then
- "#{search} pages"
- else
- 'Pages'
- end
-
- out << RDoc::Markup::Heading.new(1, "#{title} in #{store.friendly_path}")
- out << RDoc::Markup::BlankLine.new
-
- list = RDoc::Markup::List.new(:BULLET)
-
- pages.each do |page|
- list << RDoc::Markup::Paragraph.new(page)
- end
-
- out << list
-
- display out
- end
-
- ##
- # Expands abbreviated klass +klass+ into a fully-qualified class. "Zl::Da"
- # will be expanded to Zlib::DataError.
-
- def expand_class klass
- klass.split('::').inject '' do |expanded, klass_part|
- expanded << '::' unless expanded.empty?
- short = expanded << klass_part
-
- subset = classes.keys.select do |klass_name|
- klass_name =~ /^#{expanded}[^:]*$/
- end
-
- abbrevs = Abbrev.abbrev subset
-
- expanded = abbrevs[short]
-
- raise NotFoundError, short unless expanded
-
- expanded.dup
- end
- end
-
- ##
- # Expands the class portion of +name+ into a fully-qualified class. See
- # #expand_class.
-
- def expand_name name
- klass, selector, method = parse_name name
-
- return [selector, method].join if klass.empty?
-
- case selector
- when ':' then
- [find_store(klass), selector, method]
- else
- [expand_class(klass), selector, method]
- end.join
- end
-
- ##
- # Filters the methods in +found+ trying to find a match for +name+.
-
- def filter_methods found, name
- regexp = name_regexp name
-
- filtered = found.find_all do |store, methods|
- methods.any? { |method| method.full_name =~ regexp }
- end
-
- return filtered unless filtered.empty?
-
- found
- end
-
- ##
- # Yields items matching +name+ including the store they were found in, the
- # class being searched for, the class they were found in (an ancestor) the
- # types of methods to look up (from #method_type), and the method name being
- # searched for
-
- def find_methods name
- klass, selector, method = parse_name name
-
- types = method_type selector
-
- klasses = nil
- ambiguous = klass.empty?
-
- if ambiguous then
- klasses = classes.keys
- else
- klasses = ancestors_of klass
- klasses.unshift klass
- end
-
- methods = []
-
- klasses.each do |ancestor|
- ancestors = classes[ancestor]
-
- next unless ancestors
-
- klass = ancestor if ambiguous
-
- ancestors.each do |store|
- methods << [store, klass, ancestor, types, method]
- end
- end
-
- methods = methods.sort_by do |_, k, a, _, m|
- [k, a, m].compact
- end
-
- methods.each do |item|
- yield(*item) # :yields: store, klass, ancestor, types, method
- end
-
- self
- end
-
- ##
- # Finds the given +pager+ for jruby. Returns an IO if +pager+ was found.
- #
- # Returns false if +pager+ does not exist.
- #
- # Returns nil if the jruby JVM doesn't support ProcessBuilder redirection
- # (1.6 and older).
-
- def find_pager_jruby pager
- require 'java'
- require 'shellwords'
-
- return nil unless java.lang.ProcessBuilder.constants.include? :Redirect
-
- pager = Shellwords.split pager
-
- pb = java.lang.ProcessBuilder.new(*pager)
- pb = pb.redirect_output java.lang.ProcessBuilder::Redirect::INHERIT
-
- @jruby_pager_process = pb.start
-
- input = @jruby_pager_process.output_stream
-
- io = input.to_io
- io.sync = true
- io
- rescue java.io.IOException
- false
- end
-
- ##
- # Finds a store that matches +name+ which can be the name of a gem, "ruby",
- # "home" or "site".
- #
- # See also RDoc::Store#source
-
- def find_store name
- @stores.each do |store|
- source = store.source
-
- return source if source == name
-
- return source if
- store.type == :gem and source =~ /^#{Regexp.escape name}-\d/
- end
-
- raise RDoc::RI::Driver::NotFoundError, name
- end
-
- ##
- # Creates a new RDoc::Markup::Formatter. If a formatter is given with -f,
- # use it. If we're outputting to a pager, use bs, otherwise ansi.
-
- def formatter(io)
- if @formatter_klass then
- @formatter_klass.new
- elsif paging? or !io.tty? then
- RDoc::Markup::ToBs.new
- else
- RDoc::Markup::ToAnsi.new
- end
- end
-
- ##
- # Runs ri interactively using Readline if it is available.
-
- def interactive
- puts "\nEnter the method name you want to look up."
-
- if defined? Readline then
- Readline.completion_proc = method :complete
- puts "You can use tab to autocomplete."
- end
-
- puts "Enter a blank line to exit.\n\n"
-
- loop do
- name = if defined? Readline then
- Readline.readline ">> "
- else
- print ">> "
- $stdin.gets
- end
-
- return if name.nil? or name.empty?
-
- name = expand_name name.strip
-
- begin
- display_name name
- rescue NotFoundError => e
- puts e.message
- end
- end
-
- rescue Interrupt
- exit
- end
-
- ##
- # Is +file+ in ENV['PATH']?
-
- def in_path? file
- return true if file =~ %r%\A/% and File.exist? file
-
- ENV['PATH'].split(File::PATH_SEPARATOR).any? do |path|
- File.exist? File.join(path, file)
- end
- end
-
- ##
- # Lists classes known to ri starting with +names+. If +names+ is empty all
- # known classes are shown.
-
- def list_known_classes names = []
- classes = []
-
- stores.each do |store|
- classes << store.module_names
- end
-
- classes = classes.flatten.uniq.sort
-
- unless names.empty? then
- filter = Regexp.union names.map { |name| /^#{name}/ }
-
- classes = classes.grep filter
- end
-
- page do |io|
- if paging? or io.tty? then
- if names.empty? then
- io.puts "Classes and Modules known to ri:"
- else
- io.puts "Classes and Modules starting with #{names.join ', '}:"
- end
- io.puts
- end
-
- io.puts classes.join("\n")
- end
- end
-
- ##
- # Returns an Array of methods matching +name+
-
- def list_methods_matching name
- found = []
-
- find_methods name do |store, klass, ancestor, types, method|
- if types == :instance or types == :both then
- methods = store.instance_methods[ancestor]
-
- if methods then
- matches = methods.grep(/^#{Regexp.escape method.to_s}/)
-
- matches = matches.map do |match|
- "#{klass}##{match}"
- end
-
- found.concat matches
- end
- end
-
- if types == :class or types == :both then
- methods = store.class_methods[ancestor]
-
- next unless methods
- matches = methods.grep(/^#{Regexp.escape method.to_s}/)
-
- matches = matches.map do |match|
- "#{klass}::#{match}"
- end
-
- found.concat matches
- end
- end
-
- found.uniq
- end
-
- ##
- # Loads RI data for method +name+ on +klass+ from +store+. +type+ and
- # +cache+ indicate if it is a class or instance method.
-
- def load_method store, cache, klass, type, name
- methods = store.send(cache)[klass]
-
- return unless methods
-
- method = methods.find do |method_name|
- method_name == name
- end
-
- return unless method
-
- store.load_method klass, "#{type}#{method}"
- rescue RDoc::Store::MissingFileError => e
- comment = RDoc::Comment.new("missing documentation at #{e.file}").parse
-
- method = RDoc::AnyMethod.new nil, name
- method.comment = comment
- method
- end
-
- ##
- # Returns an Array of RI data for methods matching +name+
-
- def load_methods_matching name
- found = []
-
- find_methods name do |store, klass, ancestor, types, method|
- methods = []
-
- methods << load_method(store, :class_methods, ancestor, '::', method) if
- [:class, :both].include? types
-
- methods << load_method(store, :instance_methods, ancestor, '#', method) if
- [:instance, :both].include? types
-
- found << [store, methods.compact]
- end
-
- found.reject do |path, methods| methods.empty? end
- end
-
- ##
- # Returns a filtered list of methods matching +name+
-
- def lookup_method name
- found = load_methods_matching name
-
- raise NotFoundError, name if found.empty?
-
- filter_methods found, name
- end
-
- ##
- # Builds a RDoc::Markup::Document from +found+, +klasses+ and +includes+
-
- def method_document name, filtered
- out = RDoc::Markup::Document.new
-
- out << RDoc::Markup::Heading.new(1, name)
- out << RDoc::Markup::BlankLine.new
-
- filtered.each do |store, methods|
- methods.each do |method|
- render_method out, store, method, name
- end
- end
-
- out
- end
-
- ##
- # Returns the type of method (:both, :instance, :class) for +selector+
-
- def method_type selector
- case selector
- when '.', nil then :both
- when '#' then :instance
- else :class
- end
- end
-
- ##
- # Returns a regular expression for +name+ that will match an
- # RDoc::AnyMethod's name.
-
- def name_regexp name
- klass, type, name = parse_name name
-
- case type
- when '#', '::' then
- /^#{klass}#{type}#{Regexp.escape name}$/
- else
- /^#{klass}(#|::)#{Regexp.escape name}$/
- end
- end
-
- ##
- # Paginates output through a pager program.
-
- def page
- if pager = setup_pager then
- begin
- yield pager
- ensure
- pager.close
- @jruby_pager_process.wait_for if @jruby_pager_process
- end
- else
- yield $stdout
- end
- rescue Errno::EPIPE
- ensure
- @paging = false
- end
-
- ##
- # Are we using a pager?
-
- def paging?
- @paging
- end
-
- ##
- # Extracts the class, selector and method name parts from +name+ like
- # Foo::Bar#baz.
- #
- # NOTE: Given Foo::Bar, Bar is considered a class even though it may be a
- # method
-
- def parse_name name
- parts = name.split(/(::?|#|\.)/)
-
- if parts.length == 1 then
- if parts.first =~ /^[a-z]|^([%&*+\/<>^`|~-]|\+@|-@|<<|<=>?|===?|=>|=~|>>|\[\]=?|~@)$/ then
- type = '.'
- meth = parts.pop
- else
- type = nil
- meth = nil
- end
- elsif parts.length == 2 or parts.last =~ /::|#|\./ then
- type = parts.pop
- meth = nil
- elsif parts[1] == ':' then
- klass = parts.shift
- type = parts.shift
- meth = parts.join
- elsif parts[-2] != '::' or parts.last !~ /^[A-Z]/ then
- meth = parts.pop
- type = parts.pop
- end
-
- klass ||= parts.join
-
- [klass, type, meth]
- end
-
- ##
- # Renders the +klass+ from +store+ to +out+. If the klass has no
- # documentable items the class is added to +also_in+ instead.
-
- def render_class out, store, klass, also_in # :nodoc:
- comment = klass.comment
- # TODO the store's cache should always return an empty Array
- class_methods = store.class_methods[klass.full_name] || []
- instance_methods = store.instance_methods[klass.full_name] || []
- attributes = store.attributes[klass.full_name] || []
-
- if comment.empty? and
- instance_methods.empty? and class_methods.empty? then
- also_in << store
- return
- end
-
- add_from out, store
-
- class_document_comment out, comment
-
- if class_methods or instance_methods or not klass.constants.empty? then
- out << RDoc::Markup::Rule.new(1)
- end
-
- class_document_constants out, klass
-
- add_method_list out, class_methods, 'Class methods'
- add_method_list out, instance_methods, 'Instance methods'
- add_method_list out, attributes, 'Attributes'
-
- add_method_documentation out, klass if @show_all
- end
-
- def render_method out, store, method, name # :nodoc:
- out << RDoc::Markup::Paragraph.new("(from #{store.friendly_path})")
-
- unless name =~ /^#{Regexp.escape method.parent_name}/ then
- out << RDoc::Markup::Heading.new(3, "Implementation from #{method.parent_name}")
- end
-
- out << RDoc::Markup::Rule.new(1)
-
- render_method_arguments out, method.arglists
- render_method_superclass out, method
- render_method_comment out, method
- end
-
- def render_method_arguments out, arglists # :nodoc:
- return unless arglists
-
- arglists = arglists.chomp.split "\n"
- arglists = arglists.map { |line| line + "\n" }
- out << RDoc::Markup::Verbatim.new(*arglists)
- out << RDoc::Markup::Rule.new(1)
- end
-
- def render_method_comment out, method # :nodoc:
- out << RDoc::Markup::BlankLine.new
- out << method.comment
- out << RDoc::Markup::BlankLine.new
- end
-
- def render_method_superclass out, method # :nodoc:
- return unless
- method.respond_to?(:superclass_method) and method.superclass_method
-
- out << RDoc::Markup::BlankLine.new
- out << RDoc::Markup::Heading.new(4, "(Uses superclass method #{method.superclass_method})")
- out << RDoc::Markup::Rule.new(1)
- end
-
- ##
- # Looks up and displays ri data according to the options given.
-
- def run
- if @list_doc_dirs then
- puts @doc_dirs
- elsif @list then
- list_known_classes @names
- elsif @server then
- start_server
- elsif @interactive or @names.empty? then
- interactive
- else
- display_names @names
- end
- rescue NotFoundError => e
- abort e.message
- end
-
- ##
- # Sets up a pager program to pass output through. Tries the RI_PAGER and
- # PAGER environment variables followed by pager, less then more.
-
- def setup_pager
- return if @use_stdout
-
- jruby = Object.const_defined?(:RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
-
- pagers = [ENV['RI_PAGER'], ENV['PAGER'], 'pager', 'less', 'more']
-
- pagers.compact.uniq.each do |pager|
- next unless pager
-
- pager_cmd = pager.split.first
-
- next unless in_path? pager_cmd
-
- if jruby then
- case io = find_pager_jruby(pager)
- when nil then break
- when false then next
- else io
- end
- else
- io = IO.popen(pager, 'w') rescue next
- end
-
- next if $? and $?.pid == io.pid and $?.exited? # pager didn't work
-
- @paging = true
-
- return io
- end
-
- @use_stdout = true
-
- nil
- end
-
- ##
- # Starts a WEBrick server for ri.
-
- def start_server
- require 'webrick'
-
- server = WEBrick::HTTPServer.new :Port => @server
-
- extra_doc_dirs = @stores.map {|s| s.type == :extra ? s.path : nil}.compact
-
- server.mount '/', RDoc::Servlet, nil, extra_doc_dirs
-
- trap 'INT' do server.shutdown end
- trap 'TERM' do server.shutdown end
-
- server.start
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/ri/formatter.rb b/ruby_2_2/lib/rdoc/ri/formatter.rb
deleted file mode 100644
index 84d37a9d31..0000000000
--- a/ruby_2_2/lib/rdoc/ri/formatter.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-##
-# For RubyGems backwards compatibility
-
-module RDoc::RI::Formatter # :nodoc:
-end
diff --git a/ruby_2_2/lib/rdoc/ri/paths.rb b/ruby_2_2/lib/rdoc/ri/paths.rb
deleted file mode 100644
index 970cb91461..0000000000
--- a/ruby_2_2/lib/rdoc/ri/paths.rb
+++ /dev/null
@@ -1,187 +0,0 @@
-require 'rdoc/ri'
-
-##
-# The directories where ri data lives. Paths can be enumerated via ::each, or
-# queried individually via ::system_dir, ::site_dir, ::home_dir and ::gem_dir.
-
-module RDoc::RI::Paths
-
- #:stopdoc:
- require 'rbconfig'
-
- version = RbConfig::CONFIG['ruby_version']
-
- BASE = if RbConfig::CONFIG.key? 'ridir' then
- File.join RbConfig::CONFIG['ridir'], version
- else
- File.join RbConfig::CONFIG['datadir'], 'ri', version
- end
-
- homedir = begin
- File.expand_path('~')
- rescue ArgumentError
- end
-
- homedir ||= ENV['HOME'] ||
- ENV['USERPROFILE'] || ENV['HOMEPATH'] # for 1.8 compatibility
-
- HOMEDIR = if homedir then
- File.join homedir, ".rdoc"
- end
- #:startdoc:
-
- ##
- # Iterates over each selected path yielding the directory and type.
- #
- # Yielded types:
- # :system:: Where Ruby's ri data is stored. Yielded when +system+ is
- # true
- # :site:: Where ri for installed libraries are stored. Yielded when
- # +site+ is true. Normally no ri data is stored here.
- # :home:: ~/.rdoc. Yielded when +home+ is true.
- # :gem:: ri data for an installed gem. Yielded when +gems+ is true.
- # :extra:: ri data directory from the command line. Yielded for each
- # entry in +extra_dirs+
-
- def self.each system = true, site = true, home = true, gems = :latest, *extra_dirs # :yields: directory, type
- return enum_for __method__, system, site, home, gems, *extra_dirs unless
- block_given?
-
- extra_dirs.each do |dir|
- yield dir, :extra
- end
-
- yield system_dir, :system if system
- yield site_dir, :site if site
- yield home_dir, :home if home and HOMEDIR
-
- gemdirs(gems).each do |dir|
- yield dir, :gem
- end if gems
-
- nil
- end
-
- ##
- # The ri directory for the gem with +gem_name+.
-
- def self.gem_dir name, version
- req = Gem::Requirement.new "= #{version}"
-
- spec = Gem::Specification.find_by_name name, req
-
- File.join spec.doc_dir, 'ri'
- end
-
- ##
- # The latest installed gems' ri directories. +filter+ can be :all or
- # :latest.
- #
- # A +filter+ :all includes all versions of gems and includes gems without
- # ri documentation.
-
- def self.gemdirs filter = :latest
- require 'rubygems' unless defined?(Gem)
-
- ri_paths = {}
-
- all = Gem::Specification.map do |spec|
- [File.join(spec.doc_dir, 'ri'), spec.name, spec.version]
- end
-
- if filter == :all then
- gemdirs = []
-
- all.group_by do |_, name, _|
- name
- end.sort_by do |group, _|
- group
- end.map do |group, items|
- items.sort_by do |_, _, version|
- version
- end.reverse_each do |dir,|
- gemdirs << dir
- end
- end
-
- return gemdirs
- end
-
- all.each do |dir, name, ver|
- next unless File.exist? dir
-
- if ri_paths[name].nil? or ver > ri_paths[name].first then
- ri_paths[name] = [ver, name, dir]
- end
- end
-
- ri_paths.sort_by { |_, (_, name, _)| name }.map { |k, v| v.last }
- rescue LoadError
- []
- end
-
- ##
- # The location of the rdoc data in the user's home directory.
- #
- # Like ::system, ri data in the user's home directory is rare and predates
- # libraries distributed via RubyGems. ri data is rarely generated into this
- # directory.
-
- def self.home_dir
- HOMEDIR
- end
-
- ##
- # Returns existing directories from the selected documentation directories
- # as an Array.
- #
- # See also ::each
-
- def self.path(system = true, site = true, home = true, gems = :latest, *extra_dirs)
- path = raw_path system, site, home, gems, *extra_dirs
-
- path.select { |directory| File.directory? directory }
- end
-
- ##
- # Returns selected documentation directories including nonexistent
- # directories.
- #
- # See also ::each
-
- def self.raw_path(system, site, home, gems, *extra_dirs)
- path = []
-
- each(system, site, home, gems, *extra_dirs) do |dir, type|
- path << dir
- end
-
- path.compact
- end
-
- ##
- # The location of ri data installed into the site dir.
- #
- # Historically this was available for documentation installed by Ruby
- # libraries predating RubyGems. It is unlikely to contain any content for
- # modern Ruby installations.
-
- def self.site_dir
- File.join BASE, 'site'
- end
-
- ##
- # The location of the built-in ri data.
- #
- # This data is built automatically when `make` is run when Ruby is
- # installed. If you did not install Ruby by hand you may need to install
- # the documentation yourself. Please consult the documentation for your
- # package manager or Ruby installer for details. You can also use the
- # rdoc-data gem to install system ri data for common versions of Ruby.
-
- def self.system_dir
- File.join BASE, 'system'
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/ri/store.rb b/ruby_2_2/lib/rdoc/ri/store.rb
deleted file mode 100644
index 9fa9bbb03c..0000000000
--- a/ruby_2_2/lib/rdoc/ri/store.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module RDoc::RI
-
- Store = RDoc::Store # :nodoc:
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/ri/task.rb b/ruby_2_2/lib/rdoc/ri/task.rb
deleted file mode 100644
index e545d4ac1e..0000000000
--- a/ruby_2_2/lib/rdoc/ri/task.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-require 'rubygems'
-begin
- gem 'rdoc'
-rescue Gem::LoadError
-end unless defined?(RDoc)
-
-require 'rdoc/task'
-
-##
-# RDoc::RI::Task creates ri data in <code>./.rdoc</code> for your project.
-#
-# It contains the following tasks:
-#
-# [ri]
-# Build ri data
-#
-# [clobber_ri]
-# Delete ri data files. This target is automatically added to the main
-# clobber target.
-#
-# [reri]
-# Rebuild the ri data from scratch even if they are not out of date.
-#
-# Simple example:
-#
-# require 'rdoc/ri/task'
-#
-# RDoc::RI::Task.new do |ri|
-# ri.main = 'README.rdoc'
-# ri.rdoc_files.include 'README.rdoc', 'lib/**/*.rb'
-# end
-#
-# For further configuration details see RDoc::Task.
-
-class RDoc::RI::Task < RDoc::Task
-
- DEFAULT_NAMES = { # :nodoc:
- :clobber_rdoc => :clobber_ri,
- :rdoc => :ri,
- :rerdoc => :reri,
- }
-
- ##
- # Create an ri task with the given name. See RDoc::Task for documentation on
- # setting names.
-
- def initialize name = DEFAULT_NAMES # :yield: self
- super
- end
-
- def clobber_task_description # :nodoc:
- "Remove RI data files"
- end
-
- ##
- # Sets default task values
-
- def defaults
- super
-
- @rdoc_dir = '.rdoc'
- end
-
- def rdoc_task_description # :nodoc:
- 'Build RI data files'
- end
-
- def rerdoc_task_description # :nodoc:
- 'Rebuild RI data files'
- end
-end
diff --git a/ruby_2_2/lib/rdoc/ruby_lex.rb b/ruby_2_2/lib/rdoc/ruby_lex.rb
deleted file mode 100644
index 91b90ab2cf..0000000000
--- a/ruby_2_2/lib/rdoc/ruby_lex.rb
+++ /dev/null
@@ -1,1377 +0,0 @@
-# coding: US-ASCII
-
-#--
-# irb/ruby-lex.rb - ruby lexcal analyzer
-# $Release Version: 0.9.5$
-# $Revision: 17979 $
-# $Date: 2008-07-09 10:17:05 -0700 (Wed, 09 Jul 2008) $
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-#++
-
-require "e2mmap"
-require "irb/slex"
-require "stringio"
-
-##
-# Ruby lexer adapted from irb.
-#
-# The internals are not documented because they are scary.
-
-class RDoc::RubyLex
-
- ##
- # Raised upon invalid input
-
- class Error < RDoc::Error
- end
-
- # :stopdoc:
-
- extend Exception2MessageMapper
-
- def_exception(:AlreadyDefinedToken, "Already defined token(%s)")
- def_exception(:TkReading2TokenNoKey, "key nothing(key='%s')")
- def_exception(:TkSymbol2TokenNoKey, "key nothing(key='%s')")
- def_exception(:TkReading2TokenDuplicateError,
- "key duplicate(token_n='%s', key='%s')")
- def_exception(:SyntaxError, "%s")
-
- def_exception(:TerminateLineInput, "Terminate Line Input")
-
- include RDoc::RubyToken
- include IRB
-
- attr_accessor :continue
- attr_accessor :lex_state
- attr_reader :reader
-
- class << self
- attr_accessor :debug_level
- end
-
- def self.debug?
- @debug_level > 0
- end
-
- self.debug_level = 0
-
- # :startdoc:
-
- ##
- # Returns an Array of +ruby+ tokens. See ::new for a description of
- # +options+.
-
- def self.tokenize ruby, options
- tokens = []
-
- scanner = RDoc::RubyLex.new ruby, options
- scanner.exception_on_syntax_error = true
-
- while token = scanner.token do
- tokens << token
- end
-
- tokens
- end
-
- ##
- # Creates a new lexer for +content+. +options+ is an RDoc::Options, only
- # +tab_width is used.
-
- def initialize(content, options)
- lex_init
-
- if /\t/ =~ content then
- tab_width = options.tab_width
- content = content.split(/\n/).map do |line|
- 1 while line.gsub!(/\t+/) {
- ' ' * (tab_width*$&.length - $`.length % tab_width)
- } && $~
- line
- end.join("\n")
- end
-
- content << "\n" unless content[-1, 1] == "\n"
-
- set_input StringIO.new content
-
- @base_char_no = 0
- @char_no = 0
- @exp_line_no = @line_no = 1
- @here_readed = []
- @readed = []
- @rests = []
- @seek = 0
-
- @here_header = false
- @indent = 0
- @indent_stack = []
- @lex_state = :EXPR_BEG
- @space_seen = false
-
- @continue = false
- @line = ""
-
- @skip_space = false
- @readed_auto_clean_up = false
- @exception_on_syntax_error = true
-
- @prompt = nil
- @prev_seek = nil
- @ltype = nil
- end
-
- # :stopdoc:
-
- def inspect # :nodoc:
- "#<%s:0x%x pos %d lex_state %p space_seen %p>" % [
- self.class, object_id,
- @io.pos, @lex_state, @space_seen,
- ]
- end
-
- attr_accessor :skip_space
- attr_accessor :readed_auto_clean_up
- attr_accessor :exception_on_syntax_error
-
- attr_reader :seek
- attr_reader :char_no
- attr_reader :line_no
- attr_reader :indent
-
- # io functions
- def set_input(io, p = nil, &block)
- @io = io
- if p.respond_to?(:call)
- @input = p
- elsif block_given?
- @input = block
- else
- @input = Proc.new{@io.gets}
- end
- end
-
- def get_readed
- if idx = @readed.rindex("\n")
- @base_char_no = @readed.size - (idx + 1)
- else
- @base_char_no += @readed.size
- end
-
- readed = @readed.join("")
- @readed = []
- readed
- end
-
- def getc
- while @rests.empty?
- # return nil unless buf_input
- @rests.push nil unless buf_input
- end
- c = @rests.shift
- if @here_header
- @here_readed.push c
- else
- @readed.push c
- end
- @seek += 1
- if c == "\n"
- @line_no += 1
- @char_no = 0
- else
- @char_no += 1
- end
-
- c
- end
-
- def gets
- l = ""
- while c = getc
- l.concat(c)
- break if c == "\n"
- end
- return nil if l == "" and c.nil?
- l
- end
-
- def eof?
- @io.eof?
- end
-
- def getc_of_rests
- if @rests.empty?
- nil
- else
- getc
- end
- end
-
- def ungetc(c = nil)
- if @here_readed.empty?
- c2 = @readed.pop
- else
- c2 = @here_readed.pop
- end
- c = c2 unless c
- @rests.unshift c #c =
- @seek -= 1
- if c == "\n"
- @line_no -= 1
- if idx = @readed.rindex("\n")
- @char_no = idx + 1
- else
- @char_no = @base_char_no + @readed.size
- end
- else
- @char_no -= 1
- end
- end
-
- def peek_equal?(str)
- chrs = str.split(//)
- until @rests.size >= chrs.size
- return false unless buf_input
- end
- @rests[0, chrs.size] == chrs
- end
-
- def peek_match?(regexp)
- while @rests.empty?
- return false unless buf_input
- end
- regexp =~ @rests.join("")
- end
-
- def peek(i = 0)
- while @rests.size <= i
- return nil unless buf_input
- end
- @rests[i]
- end
-
- def buf_input
- prompt
- line = @input.call
- return nil unless line
- @rests.concat line.split(//)
- true
- end
- private :buf_input
-
- def set_prompt(p = nil, &block)
- p = block if block_given?
- if p.respond_to?(:call)
- @prompt = p
- else
- @prompt = Proc.new{print p}
- end
- end
-
- def prompt
- if @prompt
- @prompt.call(@ltype, @indent, @continue, @line_no)
- end
- end
-
- def initialize_input
- @ltype = nil
- @quoted = nil
- @indent = 0
- @indent_stack = []
- @lex_state = :EXPR_BEG
- @space_seen = false
- @here_header = false
-
- @continue = false
- prompt
-
- @line = ""
- @exp_line_no = @line_no
- end
-
- def each_top_level_statement
- initialize_input
- catch(:TERM_INPUT) do
- loop do
- begin
- @continue = false
- prompt
- unless l = lex
- throw :TERM_INPUT if @line == ''
- else
- #p l
- @line.concat l
- if @ltype or @continue or @indent > 0
- next
- end
- end
- if @line != "\n"
- yield @line, @exp_line_no
- end
- break unless l
- @line = ''
- @exp_line_no = @line_no
-
- @indent = 0
- @indent_stack = []
- prompt
- rescue TerminateLineInput
- initialize_input
- prompt
- get_readed
- end
- end
- end
- end
-
- def lex
- until (((tk = token).kind_of?(TkNL) || tk.kind_of?(TkEND_OF_SCRIPT)) &&
- !@continue or
- tk.nil?)
- #p tk
- #p @lex_state
- #p self
- end
- line = get_readed
- # print self.inspect
- if line == "" and tk.kind_of?(TkEND_OF_SCRIPT) || tk.nil?
- nil
- else
- line
- end
- end
-
- def token
- # require "tracer"
- # Tracer.on
- @prev_seek = @seek
- @prev_line_no = @line_no
- @prev_char_no = @char_no
- begin
- begin
- tk = @OP.match(self)
- @space_seen = tk.kind_of?(TkSPACE)
- rescue SyntaxError => e
- raise Error, "syntax error: #{e.message}" if
- @exception_on_syntax_error
-
- tk = TkError.new(@seek, @line_no, @char_no)
- end
- end while @skip_space and tk.kind_of?(TkSPACE)
-
- if @readed_auto_clean_up
- get_readed
- end
- # Tracer.off
- tk
- end
-
- ENINDENT_CLAUSE = [
- "case", "class", "def", "do", "for", "if",
- "module", "unless", "until", "while", "begin" #, "when"
- ]
-
- DEINDENT_CLAUSE = ["end" #, "when"
- ]
-
- PERCENT_LTYPE = {
- "q" => "\'",
- "Q" => "\"",
- "x" => "\`",
- "r" => "/",
- "w" => "]",
- "W" => "]",
- "s" => ":"
- }
-
- PERCENT_PAREN = {
- "{" => "}",
- "[" => "]",
- "<" => ">",
- "(" => ")"
- }
-
- PERCENT_PAREN_REV = PERCENT_PAREN.invert
-
- Ltype2Token = {
- "\'" => TkSTRING,
- "\"" => TkSTRING,
- "\`" => TkXSTRING,
- "/" => TkREGEXP,
- "]" => TkDSTRING,
- ":" => TkSYMBOL
- }
- DLtype2Token = {
- "\"" => TkDSTRING,
- "\`" => TkDXSTRING,
- "/" => TkDREGEXP,
- }
-
- def lex_init()
- @OP = IRB::SLex.new
- @OP.def_rules("\0", "\004", "\032") do |op, io|
- Token(TkEND_OF_SCRIPT, '')
- end
-
- @OP.def_rules(" ", "\t", "\f", "\r", "\13") do |op, io|
- @space_seen = true
- str = op
- while (ch = getc) =~ /[ \t\f\r\13]/ do
- str << ch
- end
- ungetc
- Token TkSPACE, str
- end
-
- @OP.def_rule("#") do |op, io|
- identify_comment
- end
-
- @OP.def_rule("=begin",
- proc{|op, io| @prev_char_no == 0 && peek(0) =~ /\s/}) do
- |op, io|
- @ltype = "="
- res = ''
- nil until getc == "\n"
-
- until ( peek_equal?("=end") && peek(4) =~ /\s/ ) do
- (ch = getc)
- res << ch
- end
-
- gets # consume =end
-
- @ltype = nil
- Token(TkRD_COMMENT, res)
- end
-
- @OP.def_rule("\n") do |op, io|
- print "\\n\n" if RDoc::RubyLex.debug?
- case @lex_state
- when :EXPR_BEG, :EXPR_FNAME, :EXPR_DOT
- @continue = true
- else
- @continue = false
- @lex_state = :EXPR_BEG
- until (@indent_stack.empty? ||
- [TkLPAREN, TkLBRACK, TkLBRACE,
- TkfLPAREN, TkfLBRACK, TkfLBRACE].include?(@indent_stack.last))
- @indent_stack.pop
- end
- end
- @here_header = false
- @here_readed = []
- Token(TkNL)
- end
-
- @OP.def_rules("*", "**",
- "=", "==", "===",
- "=~", "<=>",
- "<", "<=",
- ">", ">=", ">>") do
- |op, io|
- case @lex_state
- when :EXPR_FNAME, :EXPR_DOT
- @lex_state = :EXPR_ARG
- else
- @lex_state = :EXPR_BEG
- end
- Token(op)
- end
-
- @OP.def_rules("!", "!=", "!~") do
- |op, io|
- @lex_state = :EXPR_BEG
- Token(op)
- end
-
- @OP.def_rules("<<") do
- |op, io|
- tk = nil
- if @lex_state != :EXPR_END && @lex_state != :EXPR_CLASS &&
- (@lex_state != :EXPR_ARG || @space_seen)
- c = peek(0)
- if /\S/ =~ c && (/["'`]/ =~ c || /\w/ =~ c || c == "-")
- tk = identify_here_document
- end
- end
- unless tk
- tk = Token(op)
- case @lex_state
- when :EXPR_FNAME, :EXPR_DOT
- @lex_state = :EXPR_ARG
- else
- @lex_state = :EXPR_BEG
- end
- end
- tk
- end
-
- @OP.def_rules("'", '"') do
- |op, io|
- identify_string(op)
- end
-
- @OP.def_rules("`") do
- |op, io|
- if @lex_state == :EXPR_FNAME
- @lex_state = :EXPR_END
- Token(op)
- else
- identify_string(op)
- end
- end
-
- @OP.def_rules('?') do
- |op, io|
- if @lex_state == :EXPR_END
- @lex_state = :EXPR_BEG
- Token(TkQUESTION)
- else
- ch = getc
- if @lex_state == :EXPR_ARG && ch =~ /\s/
- ungetc
- @lex_state = :EXPR_BEG;
- Token(TkQUESTION)
- else
- @lex_state = :EXPR_END
- Token(TkCHAR, "?#{ch}")
- end
- end
- end
-
- @OP.def_rules("&", "&&", "|", "||") do
- |op, io|
- @lex_state = :EXPR_BEG
- Token(op)
- end
-
- @OP.def_rules("+=", "-=", "*=", "**=",
- "&=", "|=", "^=", "<<=", ">>=", "||=", "&&=") do
- |op, io|
- @lex_state = :EXPR_BEG
- op =~ /^(.*)=$/
- Token(TkOPASGN, $1)
- end
-
- @OP.def_rule("+@", proc{|op, io| @lex_state == :EXPR_FNAME}) do
- |op, io|
- @lex_state = :EXPR_ARG
- Token(op)
- end
-
- @OP.def_rule("-@", proc{|op, io| @lex_state == :EXPR_FNAME}) do
- |op, io|
- @lex_state = :EXPR_ARG
- Token(op)
- end
-
- @OP.def_rules("+", "-") do
- |op, io|
- catch(:RET) do
- if @lex_state == :EXPR_ARG
- if @space_seen and peek(0) =~ /[0-9]/
- throw :RET, identify_number(op)
- else
- @lex_state = :EXPR_BEG
- end
- elsif @lex_state != :EXPR_END and peek(0) =~ /[0-9]/
- throw :RET, identify_number(op)
- else
- @lex_state = :EXPR_BEG
- end
- Token(op)
- end
- end
-
- @OP.def_rule(".") do
- |op, io|
- @lex_state = :EXPR_BEG
- if peek(0) =~ /[0-9]/
- ungetc
- identify_number
- else
- # for "obj.if" etc.
- @lex_state = :EXPR_DOT
- Token(TkDOT)
- end
- end
-
- @OP.def_rules("..", "...") do
- |op, io|
- @lex_state = :EXPR_BEG
- Token(op)
- end
-
- lex_int2
- end
-
- def lex_int2
- @OP.def_rules("]", "}", ")") do
- |op, io|
- @lex_state = :EXPR_END
- @indent -= 1
- @indent_stack.pop
- Token(op)
- end
-
- @OP.def_rule(":") do
- |op, io|
- if @lex_state == :EXPR_END || peek(0) =~ /\s/
- @lex_state = :EXPR_BEG
- Token(TkCOLON)
- else
- @lex_state = :EXPR_FNAME;
- Token(TkSYMBEG)
- end
- end
-
- @OP.def_rule("::") do
- |op, io|
- # p @lex_state.id2name, @space_seen
- if @lex_state == :EXPR_BEG or @lex_state == :EXPR_ARG && @space_seen
- @lex_state = :EXPR_BEG
- Token(TkCOLON3)
- else
- @lex_state = :EXPR_DOT
- Token(TkCOLON2)
- end
- end
-
- @OP.def_rule("/") do
- |op, io|
- if @lex_state == :EXPR_BEG || @lex_state == :EXPR_MID
- identify_string(op)
- elsif peek(0) == '='
- getc
- @lex_state = :EXPR_BEG
- Token(TkOPASGN, "/") #/)
- elsif @lex_state == :EXPR_ARG and @space_seen and peek(0) !~ /\s/
- identify_string(op)
- else
- @lex_state = :EXPR_BEG
- Token("/") #/)
- end
- end
-
- @OP.def_rules("^") do
- |op, io|
- @lex_state = :EXPR_BEG
- Token("^")
- end
-
- # @OP.def_rules("^=") do
- # @lex_state = :EXPR_BEG
- # Token(OP_ASGN, :^)
- # end
-
- @OP.def_rules(",") do
- |op, io|
- @lex_state = :EXPR_BEG
- Token(op)
- end
-
- @OP.def_rules(";") do
- |op, io|
- @lex_state = :EXPR_BEG
- until (@indent_stack.empty? ||
- [TkLPAREN, TkLBRACK, TkLBRACE,
- TkfLPAREN, TkfLBRACK, TkfLBRACE].include?(@indent_stack.last))
- @indent_stack.pop
- end
- Token(op)
- end
-
- @OP.def_rule("~") do
- |op, io|
- @lex_state = :EXPR_BEG
- Token("~")
- end
-
- @OP.def_rule("~@", proc{|op, io| @lex_state == :EXPR_FNAME}) do
- |op, io|
- @lex_state = :EXPR_BEG
- Token("~")
- end
-
- @OP.def_rule("(") do
- |op, io|
- @indent += 1
- if @lex_state == :EXPR_BEG || @lex_state == :EXPR_MID
- @lex_state = :EXPR_BEG
- tk_c = TkfLPAREN
- else
- @lex_state = :EXPR_BEG
- tk_c = TkLPAREN
- end
- @indent_stack.push tk_c
- Token tk_c
- end
-
- @OP.def_rule("[]", proc{|op, io| @lex_state == :EXPR_FNAME}) do
- |op, io|
- @lex_state = :EXPR_ARG
- Token("[]")
- end
-
- @OP.def_rule("[]=", proc{|op, io| @lex_state == :EXPR_FNAME}) do
- |op, io|
- @lex_state = :EXPR_ARG
- Token("[]=")
- end
-
- @OP.def_rule("[") do
- |op, io|
- @indent += 1
- if @lex_state == :EXPR_FNAME
- tk_c = TkfLBRACK
- else
- if @lex_state == :EXPR_BEG || @lex_state == :EXPR_MID
- tk_c = TkLBRACK
- elsif @lex_state == :EXPR_ARG && @space_seen
- tk_c = TkLBRACK
- else
- tk_c = TkfLBRACK
- end
- @lex_state = :EXPR_BEG
- end
- @indent_stack.push tk_c
- Token(tk_c)
- end
-
- @OP.def_rule("{") do
- |op, io|
- @indent += 1
- if @lex_state != :EXPR_END && @lex_state != :EXPR_ARG
- tk_c = TkLBRACE
- else
- tk_c = TkfLBRACE
- end
- @lex_state = :EXPR_BEG
- @indent_stack.push tk_c
- Token(tk_c)
- end
-
- @OP.def_rule('\\') do
- |op, io|
- if getc == "\n"
- @space_seen = true
- @continue = true
- Token(TkSPACE)
- else
- ungetc
- Token("\\")
- end
- end
-
- @OP.def_rule('%') do
- |op, io|
- if @lex_state == :EXPR_BEG || @lex_state == :EXPR_MID
- identify_quotation
- elsif peek(0) == '='
- getc
- Token(TkOPASGN, :%)
- elsif @lex_state == :EXPR_ARG and @space_seen and peek(0) !~ /\s/
- identify_quotation
- else
- @lex_state = :EXPR_BEG
- Token("%") #))
- end
- end
-
- @OP.def_rule('$') do
- |op, io|
- identify_gvar
- end
-
- @OP.def_rule('@') do
- |op, io|
- if peek(0) =~ /[\w@]/
- ungetc
- identify_identifier
- else
- Token("@")
- end
- end
-
- # @OP.def_rule("def", proc{|op, io| /\s/ =~ io.peek(0)}) do
- # |op, io|
- # @indent += 1
- # @lex_state = :EXPR_FNAME
- # # @lex_state = :EXPR_END
- # # until @rests[0] == "\n" or @rests[0] == ";"
- # # rests.shift
- # # end
- # end
-
- @OP.def_rule("_") do
- if peek_match?(/_END__/) and @lex_state == :EXPR_BEG then
- 6.times { getc }
- Token(TkEND_OF_SCRIPT, '__END__')
- else
- ungetc
- identify_identifier
- end
- end
-
- @OP.def_rule("") do
- |op, io|
- printf "MATCH: start %s: %s\n", op, io.inspect if RDoc::RubyLex.debug?
- if peek(0) =~ /[0-9]/
- t = identify_number
- else
- t = identify_identifier
- end
- printf "MATCH: end %s: %s\n", op, io.inspect if RDoc::RubyLex.debug?
- t
- end
-
- p @OP if RDoc::RubyLex.debug?
- end
-
- def identify_gvar
- @lex_state = :EXPR_END
-
- case ch = getc
- when /[~_*$?!@\/\\;,=:<>".]/ #"
- Token(TkGVAR, "$" + ch)
- when "-"
- Token(TkGVAR, "$-" + getc)
- when "&", "`", "'", "+"
- Token(TkBACK_REF, "$"+ch)
- when /[1-9]/
- ref = ch
- while (ch = getc) =~ /[0-9]/ do ref << ch end
- ungetc
- Token(TkNTH_REF, "$#{ref}")
- when /\w/
- ungetc
- ungetc
- identify_identifier
- else
- ungetc
- Token("$")
- end
- end
-
- IDENT_RE = if defined? Encoding then
- eval '/[\w\u{0080}-\u{FFFFF}]/u' # 1.8 can't parse \u{}
- else
- /[\w\x80-\xFF]/
- end
-
- def identify_identifier
- token = ""
- if peek(0) =~ /[$@]/
- token.concat(c = getc)
- if c == "@" and peek(0) == "@"
- token.concat getc
- end
- end
-
- while (ch = getc) =~ IDENT_RE do
- print " :#{ch}: " if RDoc::RubyLex.debug?
- token.concat ch
- end
-
- ungetc
-
- if (ch == "!" || ch == "?") && token[0,1] =~ /\w/ && peek(0) != "="
- token.concat getc
- end
-
- # almost fix token
-
- case token
- when /^\$/
- return Token(TkGVAR, token)
- when /^\@\@/
- @lex_state = :EXPR_END
- # p Token(TkCVAR, token)
- return Token(TkCVAR, token)
- when /^\@/
- @lex_state = :EXPR_END
- return Token(TkIVAR, token)
- end
-
- if @lex_state != :EXPR_DOT
- print token, "\n" if RDoc::RubyLex.debug?
-
- token_c, *trans = TkReading2Token[token]
- if token_c
- # reserved word?
-
- if (@lex_state != :EXPR_BEG &&
- @lex_state != :EXPR_FNAME &&
- trans[1])
- # modifiers
- token_c = TkSymbol2Token[trans[1]]
- @lex_state = trans[0]
- else
- if @lex_state != :EXPR_FNAME
- if ENINDENT_CLAUSE.include?(token)
- valid = peek(0) != ':'
-
- # check for ``class = val'' etc.
- case token
- when "class"
- valid = false unless peek_match?(/^\s*(<<|\w|::)/)
- when "def"
- valid = false if peek_match?(/^\s*(([+-\/*&\|^]|<<|>>|\|\||\&\&)=|\&\&|\|\|)/)
- when "do"
- valid = false if peek_match?(/^\s*([+-\/*]?=|\*|<|>|\&)/)
- when *ENINDENT_CLAUSE
- valid = false if peek_match?(/^\s*([+-\/*]?=|\*|<|>|\&|\|)/)
- else
- # no nothing
- end if valid
-
- if valid
- if token == "do"
- if ![TkFOR, TkWHILE, TkUNTIL].include?(@indent_stack.last)
- @indent += 1
- @indent_stack.push token_c
- end
- else
- @indent += 1
- @indent_stack.push token_c
- end
- else
- token_c = TkIDENTIFIER
- end
-
- elsif DEINDENT_CLAUSE.include?(token)
- @indent -= 1
- @indent_stack.pop
- end
- @lex_state = trans[0]
- else
- @lex_state = :EXPR_END
- end
- end
- return Token(token_c, token)
- end
- end
-
- if @lex_state == :EXPR_FNAME
- @lex_state = :EXPR_END
- if peek(0) == '='
- token.concat getc
- end
- elsif @lex_state == :EXPR_BEG || @lex_state == :EXPR_DOT ||
- @lex_state == :EXPR_ARG
- @lex_state = :EXPR_ARG
- else
- @lex_state = :EXPR_END
- end
-
- if token[0, 1] =~ /[A-Z]/
- return Token(TkCONSTANT, token)
- elsif token[token.size - 1, 1] =~ /[!?]/
- return Token(TkFID, token)
- else
- return Token(TkIDENTIFIER, token)
- end
- end
-
- def identify_here_document
- ch = getc
- # if lt = PERCENT_LTYPE[ch]
- if ch == "-"
- ch = getc
- indent = true
- end
- if /['"`]/ =~ ch
- user_quote = lt = ch
- quoted = ""
- while (c = getc) && c != lt
- quoted.concat c
- end
- else
- user_quote = nil
- lt = '"'
- quoted = ch.dup
- while (c = getc) && c =~ /\w/
- quoted.concat c
- end
- ungetc
- end
-
- ltback, @ltype = @ltype, lt
- reserve = []
- while ch = getc
- reserve.push ch
- if ch == "\\"
- reserve.push ch = getc
- elsif ch == "\n"
- break
- end
- end
-
- output_heredoc = reserve.join =~ /\A\r?\n\z/
-
- if output_heredoc then
- doc = '<<'
- doc << '-' if indent
- doc << "#{user_quote}#{quoted}#{user_quote}\n"
- else
- doc = '"'
- end
-
- @here_header = false
- while l = gets
- l = l.sub(/(:?\r)?\n\z/, "\n")
- if (indent ? l.strip : l.chomp) == quoted
- break
- end
- doc << l
- end
-
- if output_heredoc then
- raise Error, "Missing terminating #{quoted} for string" unless l
-
- doc << l.chomp
- else
- doc << '"'
- end
-
- @here_header = true
- @here_readed.concat reserve
- while ch = reserve.pop
- ungetc ch
- end
-
- token_class = output_heredoc ? RDoc::RubyLex::TkHEREDOC : Ltype2Token[lt]
- @ltype = ltback
- @lex_state = :EXPR_END
- Token(token_class, doc)
- end
-
- def identify_quotation
- type = ch = getc
- if lt = PERCENT_LTYPE[type]
- ch = getc
- elsif type =~ /\W/
- type = nil
- lt = "\""
- else
- return Token(TkMOD, '%')
- end
- # if ch !~ /\W/
- # ungetc
- # next
- # end
- #@ltype = lt
- @quoted = ch unless @quoted = PERCENT_PAREN[ch]
- identify_string(lt, @quoted, type)
- end
-
- def identify_number(op = "")
- @lex_state = :EXPR_END
-
- num = op
-
- if peek(0) == "0" && peek(1) !~ /[.eE]/
- num << getc
-
- case peek(0)
- when /[xX]/
- ch = getc
- match = /[0-9a-fA-F_]/
- when /[bB]/
- ch = getc
- match = /[01_]/
- when /[oO]/
- ch = getc
- match = /[0-7_]/
- when /[dD]/
- ch = getc
- match = /[0-9_]/
- when /[0-7]/
- match = /[0-7_]/
- when /[89]/
- raise Error, "Illegal octal digit"
- else
- return Token(TkINTEGER, num)
- end
-
- num << ch if ch
-
- len0 = true
- non_digit = false
- while ch = getc
- num << ch
- if match =~ ch
- if ch == "_"
- if non_digit
- raise Error, "trailing `#{ch}' in number"
- else
- non_digit = ch
- end
- else
- non_digit = false
- len0 = false
- end
- else
- ungetc
- num[-1, 1] = ''
- if len0
- raise Error, "numeric literal without digits"
- end
- if non_digit
- raise Error, "trailing `#{non_digit}' in number"
- end
- break
- end
- end
- return Token(TkINTEGER, num)
- end
-
- type = TkINTEGER
- allow_point = true
- allow_e = true
- non_digit = false
- while ch = getc
- num << ch
- case ch
- when /[0-9]/
- non_digit = false
- when "_"
- non_digit = ch
- when allow_point && "."
- if non_digit
- raise Error, "trailing `#{non_digit}' in number"
- end
- type = TkFLOAT
- if peek(0) !~ /[0-9]/
- type = TkINTEGER
- ungetc
- num[-1, 1] = ''
- break
- end
- allow_point = false
- when allow_e && "e", allow_e && "E"
- if non_digit
- raise Error, "trailing `#{non_digit}' in number"
- end
- type = TkFLOAT
- if peek(0) =~ /[+-]/
- num << getc
- end
- allow_e = false
- allow_point = false
- non_digit = ch
- else
- if non_digit
- raise Error, "trailing `#{non_digit}' in number"
- end
- ungetc
- num[-1, 1] = ''
- break
- end
- end
-
- Token(type, num)
- end
-
- def identify_string(ltype, quoted = ltype, type = nil)
- close = PERCENT_PAREN.values.include?(quoted)
- @ltype = ltype
- @quoted = quoted
-
- str = if ltype == quoted and %w[" ' /].include? ltype then
- ltype.dup
- elsif RUBY_VERSION > '1.9' then
- "%#{type or PERCENT_LTYPE.key ltype}#{PERCENT_PAREN_REV[quoted]||quoted}"
- else
- "%#{type or PERCENT_LTYPE.index ltype}#{PERCENT_PAREN_REV[quoted]||quoted}"
- end
-
- subtype = nil
- begin
- nest = 0
-
- while ch = getc
- str << ch
-
- if @quoted == ch and nest <= 0
- break
- elsif @ltype != "'" && @ltype != "]" && @ltype != ":" and ch == "#"
- ch = getc
- subtype = true
- if ch == "{" then
- str << ch << skip_inner_expression
- next
- else
- ungetc
- end
- elsif ch == '\\'
- if %w[' /].include? @ltype then
- case ch = getc
- when "\\", "\n", "'"
- when @ltype
- str << ch
- else
- ungetc
- end
- else
- str << read_escape
- end
- end
-
- if close then
- if PERCENT_PAREN[ch] == @quoted
- nest += 1
- elsif ch == @quoted
- nest -= 1
- end
- end
- end
-
- if @ltype == "/"
- while peek(0) =~ /i|m|x|o|e|s|u|n/
- str << getc
- end
- end
-
- if subtype
- Token(DLtype2Token[ltype], str)
- else
- Token(Ltype2Token[ltype], str)
- end
- ensure
- @ltype = nil
- @quoted = nil
- @lex_state = :EXPR_END
- end
- end
-
- def skip_inner_expression
- res = ""
- nest = 0
- while ch = getc
- res << ch
- if ch == '}'
- break if nest.zero?
- nest -= 1
- elsif ch == '{'
- nest += 1
- end
- end
- res
- end
-
- def identify_comment
- @ltype = "#"
-
- comment = '#'
-
- while ch = getc
- # if ch == "\\" #"
- # read_escape
- # end
- if ch == "\n"
- @ltype = nil
- ungetc
- break
- end
-
- comment << ch
- end
-
- return Token(TkCOMMENT, comment)
- end
-
- def read_escape
- escape = ''
- ch = getc
-
- case ch
- when "\n", "\r", "\f"
- escape << ch
- when "\\", "n", "t", "r", "f", "v", "a", "e", "b", "s" #"
- escape << ch
- when /[0-7]/
- ungetc ch
- 3.times do
- ch = getc
- case ch
- when /[0-7]/
- escape << ch
- when nil
- break
- else
- ungetc
- break
- end
- end
-
- when "x"
- escape << ch
-
- 2.times do
- ch = getc
- case ch
- when /[0-9a-fA-F]/
- escape << ch
- when nil
- break
- else
- ungetc
- break
- end
- end
-
- when "M"
- escape << ch
-
- ch = getc
- if ch != '-'
- ungetc
- else
- escape << ch
-
- ch = getc
- if ch == "\\" #"
- ungetc
- escape << read_escape
- else
- escape << ch
- end
- end
-
- when "C", "c" #, "^"
- escape << ch
-
- if ch == "C"
- ch = getc
-
- if ch == "-"
- escape << ch
- ch = getc
- escape << ch
-
- escape << read_escape if ch == "\\"
- else
- ungetc
- end
- elsif (ch = getc) == "\\" #"
- escape << ch << read_escape
- end
- else
- escape << ch
-
- # other characters
- end
-
- escape
- end
-
- # :startdoc:
-
-end
-
-#RDoc::RubyLex.debug_level = 1
-
diff --git a/ruby_2_2/lib/rdoc/ruby_token.rb b/ruby_2_2/lib/rdoc/ruby_token.rb
deleted file mode 100644
index f091e1a676..0000000000
--- a/ruby_2_2/lib/rdoc/ruby_token.rb
+++ /dev/null
@@ -1,460 +0,0 @@
-#--
-# irb/ruby-token.rb - ruby tokens
-# $Release Version: 0.9.5$
-# $Revision: 11708 $
-# $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#++
-# Definitions of all tokens involved in the lexical analysis.
-#
-# This class is not documented because it is so deep in the internals.
-
-module RDoc::RubyToken
- # :stopdoc:
-
- EXPR_BEG = :EXPR_BEG
- EXPR_MID = :EXPR_MID
- EXPR_END = :EXPR_END
- EXPR_ARG = :EXPR_ARG
- EXPR_FNAME = :EXPR_FNAME
- EXPR_DOT = :EXPR_DOT
- EXPR_CLASS = :EXPR_CLASS
-
- # for ruby 1.4X
- if !defined?(Symbol)
- Symbol = Integer
- end
-
- def set_token_position(line, char)
- @prev_line_no = line
- @prev_char_no = char
- end
-
- class Token
- def initialize(seek, line_no, char_no, text = nil)
- @seek = seek
- @line_no = line_no
- @char_no = char_no
- @text = text
- end
-
- attr_reader :seek
- attr_reader :line_no
- attr_reader :char_no
-
- attr_accessor :text
-
- def ==(other)
- self.class == other.class and
- other.line_no == @line_no and
- other.char_no == @char_no and
- other.text == @text
- end
-
- ##
- # Because we're used in contexts that expect to return a token, we set the
- # text string and then return ourselves
-
- def set_text(text)
- @text = text
- self
- end
-
- def inspect # :nodoc:
- klass = self.class.name.split('::').last
- "{%s %d, %d:%d %p}" % [klass, @seek, @line_no, @char_no, @text]
- end
-
- end
-
- class TkNode < Token
- def initialize(seek, line_no, char_no, node = nil)
- super seek, line_no, char_no
- @node = node
- end
-
- attr_reader:node
-
- def ==(other)
- self.class == other.class and
- other.line_no == @line_no and
- other.char_no == @char_no and
- other.node == @node
- end
-
- def set_text text
- @node = text
- self
- end
-
- alias text node
-
- def inspect # :nodoc:
- klass = self.class.name.split('::').last
- "{%s %d, %d:%d %p}" % [klass, @seek, @line_no, @char_no, @node]
- end
-
- end
-
- class TkId < Token
- def initialize(seek, line_no, char_no, name)
- super(seek, line_no, char_no)
- @name = name
- end
- attr_reader:name
-
- def ==(other)
- self.class == other.class and
- other.line_no == @line_no and
- other.char_no == @char_no and
- other.name == @name
- end
-
- def set_text text
- @name = text
- self
- end
-
- alias text name
-
- def inspect # :nodoc:
- klass = self.class.name.split('::').last
- "{%s %d, %d:%d %p}" % [klass, @seek, @line_no, @char_no, @name]
- end
-
- end
-
- class TkKW < TkId
- end
-
- class TkVal < Token
- def initialize(seek, line_no, char_no, value = nil)
- super(seek, line_no, char_no)
- @value = value
- end
- attr_accessor :value
-
- def ==(other)
- self.class == other.class and
- other.line_no == @line_no and
- other.char_no == @char_no and
- other.value == @value
- end
-
- def set_text text
- @value = text
- self
- end
-
- alias text value
-
- def inspect # :nodoc:
- klass = self.class.name.split('::').last
- "{%s %s, %d:%d %p}" % [klass, @seek, @line_no, @char_no, @value]
- end
-
- end
-
- class TkOp < Token
- def initialize(seek, line_no, char_no, name = nil)
- super seek, line_no, char_no
- @name = name
- end
-
- attr_accessor :name
-
- def ==(other)
- self.class == other.class and
- other.line_no == @line_no and
- other.char_no == @char_no and
- other.name == @name
- end
-
- def set_text text
- @name = text
- self
- end
-
- alias text name
-
- def inspect # :nodoc:
- klass = self.class.name.split('::').last
- "{%s %d, %d:%d %p}" % [klass, @seek, @line_no, @char_no, @name]
- end
-
- end
-
- class TkOPASGN < TkOp
- def initialize(seek, line_no, char_no, op)
- super(seek, line_no, char_no)
- op = TkReading2Token[op][0] unless op.kind_of?(Symbol)
- @op = op
- @text = nil
- end
-
- attr_reader:op
-
- def ==(other)
- self.class == other.class and
- other.line_no == @line_no and
- other.char_no == @char_no and
- other.op == @op
- end
-
- def text
- @text ||= "#{TkToken2Reading[op]}="
- end
-
- def inspect # :nodoc:
- klass = self.class.name.split('::').last
- "{%s %d, %d:%d %p}" % [klass, @seek, @line_no, @char_no, @op]
- end
-
- end
-
- class TkUnknownChar < Token
- def initialize(seek, line_no, char_no, name)
- super(seek, line_no, char_no)
- @name = name
- end
- attr_reader:name
-
- def ==(other)
- self.class == other.class and
- other.line_no == @line_no and
- other.char_no == @char_no and
- other.name == @name
- end
-
- def set_text text
- @name = text
- self
- end
-
- alias text name
-
- def inspect # :nodoc:
- klass = self.class.name.split('::').last
- "{%s %d, %d:%d %p}" % [klass, @seek, @line_no, @char_no, @name]
- end
-
- end
-
- class TkError < Token
- end
-
- def Token(token, value = nil)
- value ||= TkToken2Reading[token]
-
- case token
- when String
- if (tk = TkReading2Token[token]).nil?
- IRB.fail TkReading2TokenNoKey, token
- end
-
- tk = Token(tk[0], value)
-
- if tk.kind_of?(TkOp) then
- tk.name = token
- end
- when Symbol
- if (tk = TkSymbol2Token[token]).nil?
- IRB.fail TkSymbol2TokenNoKey, token
- end
-
- tk = Token(tk[0], value)
- else
- if token.instance_method(:initialize).arity == 3 then
- tk = token.new(@prev_seek, @prev_line_no, @prev_char_no)
- tk.set_text value
- else
- tk = token.new(@prev_seek, @prev_line_no, @prev_char_no, value)
- end
- end
-
- tk
- end
-
- TokenDefinitions = [
- [:TkCLASS, TkKW, "class", :EXPR_CLASS],
- [:TkMODULE, TkKW, "module", :EXPR_BEG],
- [:TkDEF, TkKW, "def", :EXPR_FNAME],
- [:TkUNDEF, TkKW, "undef", :EXPR_FNAME],
- [:TkBEGIN, TkKW, "begin", :EXPR_BEG],
- [:TkRESCUE, TkKW, "rescue", :EXPR_MID],
- [:TkENSURE, TkKW, "ensure", :EXPR_BEG],
- [:TkEND, TkKW, "end", :EXPR_END],
- [:TkIF, TkKW, "if", :EXPR_BEG, :TkIF_MOD],
- [:TkUNLESS, TkKW, "unless", :EXPR_BEG, :TkUNLESS_MOD],
- [:TkTHEN, TkKW, "then", :EXPR_BEG],
- [:TkELSIF, TkKW, "elsif", :EXPR_BEG],
- [:TkELSE, TkKW, "else", :EXPR_BEG],
- [:TkCASE, TkKW, "case", :EXPR_BEG],
- [:TkWHEN, TkKW, "when", :EXPR_BEG],
- [:TkWHILE, TkKW, "while", :EXPR_BEG, :TkWHILE_MOD],
- [:TkUNTIL, TkKW, "until", :EXPR_BEG, :TkUNTIL_MOD],
- [:TkFOR, TkKW, "for", :EXPR_BEG],
- [:TkBREAK, TkKW, "break", :EXPR_MID],
- [:TkNEXT, TkKW, "next", :EXPR_END],
- [:TkREDO, TkKW, "redo", :EXPR_END],
- [:TkRETRY, TkKW, "retry", :EXPR_END],
- [:TkIN, TkKW, "in", :EXPR_BEG],
- [:TkDO, TkKW, "do", :EXPR_BEG],
- [:TkRETURN, TkKW, "return", :EXPR_MID],
- [:TkYIELD, TkKW, "yield", :EXPR_END],
- [:TkSUPER, TkKW, "super", :EXPR_END],
- [:TkSELF, TkKW, "self", :EXPR_END],
- [:TkNIL, TkKW, "nil", :EXPR_END],
- [:TkTRUE, TkKW, "true", :EXPR_END],
- [:TkFALSE, TkKW, "false", :EXPR_END],
- [:TkAND, TkKW, "and", :EXPR_BEG],
- [:TkOR, TkKW, "or", :EXPR_BEG],
- [:TkNOT, TkKW, "not", :EXPR_BEG],
- [:TkIF_MOD, TkKW],
- [:TkUNLESS_MOD, TkKW],
- [:TkWHILE_MOD, TkKW],
- [:TkUNTIL_MOD, TkKW],
- [:TkALIAS, TkKW, "alias", :EXPR_FNAME],
- [:TkDEFINED, TkKW, "defined?", :EXPR_END],
- [:TklBEGIN, TkKW, "BEGIN", :EXPR_END],
- [:TklEND, TkKW, "END", :EXPR_END],
- [:Tk__LINE__, TkKW, "__LINE__", :EXPR_END],
- [:Tk__FILE__, TkKW, "__FILE__", :EXPR_END],
-
- [:TkIDENTIFIER, TkId],
- [:TkFID, TkId],
- [:TkGVAR, TkId],
- [:TkCVAR, TkId],
- [:TkIVAR, TkId],
- [:TkCONSTANT, TkId],
-
- [:TkINTEGER, TkVal],
- [:TkFLOAT, TkVal],
- [:TkSTRING, TkVal],
- [:TkHEREDOC, TkVal],
- [:TkXSTRING, TkVal],
- [:TkREGEXP, TkVal],
- [:TkSYMBOL, TkVal],
- [:TkCHAR, TkVal],
-
- [:TkDSTRING, TkNode],
- [:TkDXSTRING, TkNode],
- [:TkDREGEXP, TkNode],
- [:TkNTH_REF, TkNode],
- [:TkBACK_REF, TkNode],
-
- [:TkUPLUS, TkOp, "+@"],
- [:TkUMINUS, TkOp, "-@"],
- [:TkPOW, TkOp, "**"],
- [:TkCMP, TkOp, "<=>"],
- [:TkEQ, TkOp, "=="],
- [:TkEQQ, TkOp, "==="],
- [:TkNEQ, TkOp, "!="],
- [:TkGEQ, TkOp, ">="],
- [:TkLEQ, TkOp, "<="],
- [:TkANDOP, TkOp, "&&"],
- [:TkOROP, TkOp, "||"],
- [:TkMATCH, TkOp, "=~"],
- [:TkNMATCH, TkOp, "!~"],
- [:TkDOT2, TkOp, ".."],
- [:TkDOT3, TkOp, "..."],
- [:TkAREF, TkOp, "[]"],
- [:TkASET, TkOp, "[]="],
- [:TkLSHFT, TkOp, "<<"],
- [:TkRSHFT, TkOp, ">>"],
- [:TkCOLON2, TkOp, '::'],
- [:TkCOLON3, TkOp, '::'],
- #[:OPASGN, TkOp], # +=, -= etc. #
- [:TkASSOC, TkOp, "=>"],
- [:TkQUESTION, TkOp, "?"], #?
- [:TkCOLON, TkOp, ":"], #:
-
- [:TkfLPAREN, Token, "("], # func( #
- [:TkfLBRACK, Token, "["], # func[ #
- [:TkfLBRACE, Token, "{"], # func{ #
- [:TkSYMBEG, Token, ":"], # :SYMBOL
-
- [:TkAMPER, TkOp, "&"],
- [:TkGT, TkOp, ">"],
- [:TkLT, TkOp, "<"],
- [:TkPLUS, TkOp, "+"],
- [:TkSTAR, TkOp, "*"],
- [:TkMINUS, TkOp, "-"],
- [:TkMULT, TkOp, "*"],
- [:TkDIV, TkOp, "/"],
- [:TkMOD, TkOp, "%"],
- [:TkBITOR, TkOp, "|"],
- [:TkBITXOR, TkOp, "^"],
- [:TkBITAND, TkOp, "&"],
- [:TkBITNOT, TkOp, "~"],
- [:TkNOTOP, TkOp, "!"],
-
- [:TkBACKQUOTE, TkOp, "`"],
-
- [:TkASSIGN, Token, "="],
- [:TkDOT, Token, "."],
- [:TkLPAREN, Token, "("], #(exp)
- [:TkLBRACK, Token, "["], #[arry]
- [:TkLBRACE, Token, "{"], #{hash}
- [:TkRPAREN, Token, ")"],
- [:TkRBRACK, Token, "]"],
- [:TkRBRACE, Token, "}"],
- [:TkCOMMA, Token, ","],
- [:TkSEMICOLON, Token, ";"],
-
- [:TkCOMMENT, TkVal],
- [:TkSPACE, Token, " "],
- [:TkNL, Token, "\n"],
- [:TkEND_OF_SCRIPT],
-
- [:TkBACKSLASH, TkUnknownChar, "\\"],
- [:TkAT, TkUnknownChar, "@"],
- [:TkDOLLAR, TkUnknownChar, "$"],
- ]
-
- # {reading => token_class}
- # {reading => [token_class, *opt]}
- TkReading2Token = {}
- TkToken2Reading = {}
- TkSymbol2Token = {}
-
- def self.def_token(token_n, super_token = Token, reading = nil, *opts)
- token_n = token_n.id2name if token_n.kind_of?(Symbol)
- if const_defined?(token_n)
- IRB.fail AlreadyDefinedToken, token_n
- end
- token_c = eval("class #{token_n} < #{super_token}; end; #{token_n}")
-
- if reading
- TkToken2Reading[token_c] = reading
-
- return if TkReading2Token[reading]
-
- if opts.empty?
- TkReading2Token[reading] = [token_c]
- else
- TkReading2Token[reading] = [token_c].concat(opts)
- end
- end
- TkSymbol2Token[token_n.intern] = token_c
- end
-
- for defs in TokenDefinitions
- def_token(*defs)
- end
-
- def_token :TkRD_COMMENT, TkCOMMENT
-
- NEWLINE_TOKEN = TkNL.new 0, 0, 0, "\n"
-
- class TkSYMBOL
-
- def to_sym
- @sym ||= text[1..-1].intern
- end
-
- end
-
- # :startdoc:
-end
-
diff --git a/ruby_2_2/lib/rdoc/rubygems_hook.rb b/ruby_2_2/lib/rdoc/rubygems_hook.rb
deleted file mode 100644
index c4eaddbd97..0000000000
--- a/ruby_2_2/lib/rdoc/rubygems_hook.rb
+++ /dev/null
@@ -1,253 +0,0 @@
-require 'rubygems'
-require 'rubygems/user_interaction'
-require 'fileutils'
-require 'rdoc'
-
-##
-# Gem::RDoc provides methods to generate RDoc and ri data for installed gems
-# upon gem installation.
-#
-# This file is automatically required by RubyGems 1.9 and newer.
-
-class RDoc::RubygemsHook
-
- include Gem::UserInteraction
- extend Gem::UserInteraction
-
- @rdoc_version = nil
- @specs = []
-
- ##
- # Force installation of documentation?
-
- attr_accessor :force
-
- ##
- # Generate rdoc?
-
- attr_accessor :generate_rdoc
-
- ##
- # Generate ri data?
-
- attr_accessor :generate_ri
-
- class << self
-
- ##
- # Loaded version of RDoc. Set by ::load_rdoc
-
- attr_reader :rdoc_version
-
- end
-
- ##
- # Post installs hook that generates documentation for each specification in
- # +specs+
-
- def self.generation_hook installer, specs
- start = Time.now
- types = installer.document
-
- generate_rdoc = types.include? 'rdoc'
- generate_ri = types.include? 'ri'
-
- specs.each do |spec|
- new(spec, generate_rdoc, generate_ri).generate
- end
-
- return unless generate_rdoc or generate_ri
-
- duration = (Time.now - start).to_i
- names = specs.map(&:name).join ', '
-
- say "Done installing documentation for #{names} after #{duration} seconds"
- end
-
- ##
- # Loads the RDoc generator
-
- def self.load_rdoc
- return if @rdoc_version
-
- require 'rdoc/rdoc'
-
- @rdoc_version = Gem::Version.new ::RDoc::VERSION
- end
-
- ##
- # Creates a new documentation generator for +spec+. RDoc and ri data
- # generation can be enabled or disabled through +generate_rdoc+ and
- # +generate_ri+ respectively.
- #
- # Only +generate_ri+ is enabled by default.
-
- def initialize spec, generate_rdoc = false, generate_ri = true
- @doc_dir = spec.doc_dir
- @force = false
- @rdoc = nil
- @spec = spec
-
- @generate_rdoc = generate_rdoc
- @generate_ri = generate_ri
-
- @rdoc_dir = spec.doc_dir 'rdoc'
- @ri_dir = spec.doc_dir 'ri'
- end
-
- ##
- # Removes legacy rdoc arguments from +args+
- #--
- # TODO move to RDoc::Options
-
- def delete_legacy_args args
- args.delete '--inline-source'
- args.delete '--promiscuous'
- args.delete '-p'
- args.delete '--one-file'
- end
-
- ##
- # Generates documentation using the named +generator+ ("darkfish" or "ri")
- # and following the given +options+.
- #
- # Documentation will be generated into +destination+
-
- def document generator, options, destination
- generator_name = generator
-
- options = options.dup
- options.exclude ||= [] # TODO maybe move to RDoc::Options#finish
- options.setup_generator generator
- options.op_dir = destination
- options.finish
-
- generator = options.generator.new @rdoc.store, options
-
- @rdoc.options = options
- @rdoc.generator = generator
-
- say "Installing #{generator_name} documentation for #{@spec.full_name}"
-
- FileUtils.mkdir_p options.op_dir
-
- Dir.chdir options.op_dir do
- begin
- @rdoc.class.current = @rdoc
- @rdoc.generator.generate
- ensure
- @rdoc.class.current = nil
- end
- end
- end
-
- ##
- # Generates RDoc and ri data
-
- def generate
- return if @spec.default_gem?
- return unless @generate_ri or @generate_rdoc
-
- setup
-
- options = nil
-
- args = @spec.rdoc_options
-
- if @spec.respond_to? :source_paths then
- args.concat @spec.source_paths
- else
- args.concat @spec.require_paths
- end
-
- args.concat @spec.extra_rdoc_files
-
- case config_args = Gem.configuration[:rdoc]
- when String then
- args = args.concat config_args.split
- when Array then
- args = args.concat config_args
- end
-
- delete_legacy_args args
-
- Dir.chdir @spec.full_gem_path do
- options = ::RDoc::Options.new
- options.default_title = "#{@spec.full_name} Documentation"
- options.parse args
- end
-
- options.quiet = !Gem.configuration.really_verbose
-
- @rdoc = new_rdoc
- @rdoc.options = options
-
- store = RDoc::Store.new
- store.encoding = options.encoding if options.respond_to? :encoding
- store.dry_run = options.dry_run
- store.main = options.main_page
- store.title = options.title
-
- @rdoc.store = store
-
- say "Parsing documentation for #{@spec.full_name}"
-
- Dir.chdir @spec.full_gem_path do
- @rdoc.parse_files options.files
- end
-
- document 'ri', options, @ri_dir if
- @generate_ri and (@force or not File.exist? @ri_dir)
-
- document 'darkfish', options, @rdoc_dir if
- @generate_rdoc and (@force or not File.exist? @rdoc_dir)
- end
-
- ##
- # #new_rdoc creates a new RDoc instance. This method is provided only to
- # make testing easier.
-
- def new_rdoc # :nodoc:
- ::RDoc::RDoc.new
- end
-
- ##
- # Is rdoc documentation installed?
-
- def rdoc_installed?
- File.exist? @rdoc_dir
- end
-
- ##
- # Removes generated RDoc and ri data
-
- def remove
- base_dir = @spec.base_dir
-
- raise Gem::FilePermissionError, base_dir unless File.writable? base_dir
-
- FileUtils.rm_rf @rdoc_dir
- FileUtils.rm_rf @ri_dir
- end
-
- ##
- # Is ri data installed?
-
- def ri_installed?
- File.exist? @ri_dir
- end
-
- ##
- # Prepares the spec for documentation generation
-
- def setup
- self.class.load_rdoc
-
- raise Gem::FilePermissionError, @doc_dir if
- File.exist?(@doc_dir) and not File.writable?(@doc_dir)
-
- FileUtils.mkdir_p @doc_dir unless File.exist? @doc_dir
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/servlet.rb b/ruby_2_2/lib/rdoc/servlet.rb
deleted file mode 100644
index ec8fd739f1..0000000000
--- a/ruby_2_2/lib/rdoc/servlet.rb
+++ /dev/null
@@ -1,441 +0,0 @@
-require 'rdoc'
-require 'time'
-require 'webrick'
-
-##
-# This is a WEBrick servlet that allows you to browse ri documentation.
-#
-# You can show documentation through either `ri --server` or, with RubyGems
-# 2.0 or newer, `gem server`. For ri, the server runs on port 8214 by
-# default. For RubyGems the server runs on port 8808 by default.
-#
-# You can use this servlet in your own project by mounting it on a WEBrick
-# server:
-#
-# require 'webrick'
-#
-# server = WEBrick::HTTPServer.new Port: 8000
-#
-# server.mount '/', RDoc::Servlet
-#
-# If you want to mount the servlet some other place than the root, provide the
-# base path when mounting:
-#
-# server.mount '/rdoc', RDoc::Servlet, '/rdoc'
-
-class RDoc::Servlet < WEBrick::HTTPServlet::AbstractServlet
-
- @server_stores = Hash.new { |hash, server| hash[server] = {} }
- @cache = Hash.new { |hash, store| hash[store] = {} }
-
- ##
- # Maps an asset type to its path on the filesystem
-
- attr_reader :asset_dirs
-
- ##
- # An RDoc::Options instance used for rendering options
-
- attr_reader :options
-
- ##
- # Creates an instance of this servlet that shares cached data between
- # requests.
-
- def self.get_instance server, *options # :nodoc:
- stores = @server_stores[server]
-
- new server, stores, @cache, *options
- end
-
- ##
- # Creates a new WEBrick servlet.
- #
- # Use +mount_path+ when mounting the servlet somewhere other than /.
- #
- # Use +extra_doc_dirs+ for additional documentation directories.
- #
- # +server+ is provided automatically by WEBrick when mounting. +stores+ and
- # +cache+ are provided automatically by the servlet.
-
- def initialize server, stores, cache, mount_path = nil, extra_doc_dirs = []
- super server
-
- @cache = cache
- @mount_path = mount_path
- @extra_doc_dirs = extra_doc_dirs
- @stores = stores
-
- @options = RDoc::Options.new
- @options.op_dir = '.'
-
- darkfish_dir = nil
-
- # HACK dup
- $LOAD_PATH.each do |path|
- darkfish_dir = File.join path, 'rdoc/generator/template/darkfish/'
- next unless File.directory? darkfish_dir
- @options.template_dir = darkfish_dir
- break
- end
-
- @asset_dirs = {
- :darkfish => darkfish_dir,
- :json_index =>
- File.expand_path('../generator/template/json_index/', __FILE__),
- }
- end
-
- ##
- # Serves the asset at the path in +req+ for +generator_name+ via +res+.
-
- def asset generator_name, req, res
- asset_dir = @asset_dirs[generator_name]
-
- asset_path = File.join asset_dir, req.path
-
- if_modified_since req, res, asset_path
-
- res.body = File.read asset_path
-
- res.content_type = case req.path
- when /css$/ then 'text/css'
- when /js$/ then 'application/javascript'
- else 'application/octet-stream'
- end
- end
-
- ##
- # GET request entry point. Fills in +res+ for the path, etc. in +req+.
-
- def do_GET req, res
- req.path.sub!(/^#{Regexp.escape @mount_path}/o, '') if @mount_path
-
- case req.path
- when '/' then
- root req, res
- when '/rdoc.css', '/js/darkfish.js', '/js/jquery.js', '/js/search.js',
- %r%^/images/% then
- asset :darkfish, req, res
- when '/js/navigation.js', '/js/searcher.js' then
- asset :json_index, req, res
- when '/js/search_index.js' then
- root_search req, res
- else
- show_documentation req, res
- end
- rescue WEBrick::HTTPStatus::NotFound => e
- generator = generator_for RDoc::Store.new
-
- not_found generator, req, res, e.message
- rescue WEBrick::HTTPStatus::Status
- raise
- rescue => e
- error e, req, res
- end
-
- ##
- # Fills in +res+ with the class, module or page for +req+ from +store+.
- #
- # +path+ is relative to the mount_path and is used to determine the class,
- # module or page name (/RDoc/Servlet.html becomes RDoc::Servlet).
- # +generator+ is used to create the page.
-
- def documentation_page store, generator, path, req, res
- name = path.sub(/.html$/, '').gsub '/', '::'
-
- if klass = store.find_class_or_module(name) then
- res.body = generator.generate_class klass
- elsif page = store.find_text_page(name.sub(/_([^_]*)$/, '.\1')) then
- res.body = generator.generate_page page
- else
- not_found generator, req, res
- end
- end
-
- ##
- # Creates the JSON search index on +res+ for the given +store+. +generator+
- # must respond to \#json_index to build. +req+ is ignored.
-
- def documentation_search store, generator, req, res
- json_index = @cache[store].fetch :json_index do
- @cache[store][:json_index] =
- JSON.dump generator.json_index.build_index
- end
-
- res.content_type = 'application/javascript'
- res.body = "var search_data = #{json_index}"
- end
-
- ##
- # Returns the RDoc::Store and path relative to +mount_path+ for
- # documentation at +path+.
-
- def documentation_source path
- _, source_name, path = path.split '/', 3
-
- store = @stores[source_name]
- return store, path if store
-
- store = store_for source_name
-
- store.load_all
-
- @stores[source_name] = store
-
- return store, path
- end
-
- ##
- # Generates an error page for the +exception+ while handling +req+ on +res+.
-
- def error exception, req, res
- backtrace = exception.backtrace.join "\n"
-
- res.content_type = 'text/html'
- res.status = 500
- res.body = <<-BODY
-<!DOCTYPE html>
-<html>
-<head>
-<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
-
-<title>Error - #{ERB::Util.html_escape exception.class}</title>
-
-<link type="text/css" media="screen" href="#{@mount_path}/rdoc.css" rel="stylesheet">
-</head>
-<body>
-<h1>Error</h1>
-
-<p>While processing <code>#{ERB::Util.html_escape req.request_uri}</code> the
-RDoc (#{ERB::Util.html_escape RDoc::VERSION}) server has encountered a
-<code>#{ERB::Util.html_escape exception.class}</code>
-exception:
-
-<pre>#{ERB::Util.html_escape exception.message}</pre>
-
-<p>Please report this to the
-<a href="https://github.com/rdoc/rdoc/issues">RDoc issues tracker</a>. Please
-include the RDoc version, the URI above and exception class, message and
-backtrace. If you're viewing a gem's documentation, include the gem name and
-version. If you're viewing Ruby's documentation, include the version of ruby.
-
-<p>Backtrace:
-
-<pre>#{ERB::Util.html_escape backtrace}</pre>
-
-</body>
-</html>
- BODY
- end
-
- ##
- # Instantiates a Darkfish generator for +store+
-
- def generator_for store
- generator = RDoc::Generator::Darkfish.new store, @options
- generator.file_output = false
- generator.asset_rel_path = '..'
-
- rdoc = RDoc::RDoc.new
- rdoc.store = store
- rdoc.generator = generator
- rdoc.options = @options
-
- @options.main_page = store.main
- @options.title = store.title
-
- generator
- end
-
- ##
- # Handles the If-Modified-Since HTTP header on +req+ for +path+. If the
- # file has not been modified a Not Modified response is returned. If the
- # file has been modified a Last-Modified header is added to +res+.
-
- def if_modified_since req, res, path = nil
- last_modified = File.stat(path).mtime if path
-
- res['last-modified'] = last_modified.httpdate
-
- return unless ims = req['if-modified-since']
-
- ims = Time.parse ims
-
- unless ims < last_modified then
- res.body = ''
- raise WEBrick::HTTPStatus::NotModified
- end
- end
-
- ##
- # Returns an Array of installed documentation.
- #
- # Each entry contains the documentation name (gem name, 'Ruby
- # Documentation', etc.), the path relative to the mount point, whether the
- # documentation exists, the type of documentation (See RDoc::RI::Paths#each)
- # and the filesystem to the RDoc::Store for the documentation.
-
- def installed_docs
- extra_counter = 0
- ri_paths.map do |path, type|
- store = RDoc::Store.new path, type
- exists = File.exist? store.cache_path
-
- case type
- when :gem then
- gem_path = path[%r%/([^/]*)/ri$%, 1]
- [gem_path, "#{gem_path}/", exists, type, path]
- when :system then
- ['Ruby Documentation', 'ruby/', exists, type, path]
- when :site then
- ['Site Documentation', 'site/', exists, type, path]
- when :home then
- ['Home Documentation', 'home/', exists, type, path]
- when :extra then
- extra_counter += 1
- store.load_cache if exists
- title = store.title || "Extra Documentation"
- [title, "extra-#{extra_counter}/", exists, type, path]
- end
- end
- end
-
- ##
- # Returns a 404 page built by +generator+ for +req+ on +res+.
-
- def not_found generator, req, res, message = nil
- message ||= "The page <kbd>#{ERB::Util.h req.path}</kbd> was not found"
- res.body = generator.generate_servlet_not_found message
- res.status = 404
- end
-
- ##
- # Enumerates the ri paths. See RDoc::RI::Paths#each
-
- def ri_paths &block
- RDoc::RI::Paths.each true, true, true, :all, *@extra_doc_dirs, &block #TODO: pass extra_dirs
- end
-
- ##
- # Generates the root page on +res+. +req+ is ignored.
-
- def root req, res
- generator = RDoc::Generator::Darkfish.new nil, @options
-
- res.body = generator.generate_servlet_root installed_docs
-
- res.content_type = 'text/html'
- end
-
- ##
- # Generates a search index for the root page on +res+. +req+ is ignored.
-
- def root_search req, res
- search_index = []
- info = []
-
- installed_docs.map do |name, href, exists, type, path|
- next unless exists
-
- search_index << name
-
- case type
- when :gem
- gemspec = path.gsub(%r%/doc/([^/]*?)/ri$%,
- '/specifications/\1.gemspec')
-
- spec = Gem::Specification.load gemspec
-
- path = spec.full_name
- comment = spec.summary
- when :system then
- path = 'ruby'
- comment = 'Documentation for the Ruby standard library'
- when :site then
- path = 'site'
- comment = 'Documentation for non-gem libraries'
- when :home then
- path = 'home'
- comment = 'Documentation from your home directory'
- when :extra
- comment = name
- end
-
- info << [name, '', path, '', comment]
- end
-
- index = {
- :index => {
- :searchIndex => search_index,
- :longSearchIndex => search_index,
- :info => info,
- }
- }
-
- res.body = "var search_data = #{JSON.dump index};"
- res.content_type = 'application/javascript'
- end
-
- ##
- # Displays documentation for +req+ on +res+, whether that be HTML or some
- # asset.
-
- def show_documentation req, res
- store, path = documentation_source req.path
-
- if_modified_since req, res, store.cache_path
-
- generator = generator_for store
-
- case path
- when nil, '', 'index.html' then
- res.body = generator.generate_index
- when 'table_of_contents.html' then
- res.body = generator.generate_table_of_contents
- when 'js/search_index.js' then
- documentation_search store, generator, req, res
- else
- documentation_page store, generator, path, req, res
- end
- ensure
- res.content_type ||= 'text/html'
- end
-
- ##
- # Returns an RDoc::Store for the given +source_name+ ('ruby' or a gem name).
-
- def store_for source_name
- case source_name
- when 'home' then
- RDoc::Store.new RDoc::RI::Paths.home_dir, :home
- when 'ruby' then
- RDoc::Store.new RDoc::RI::Paths.system_dir, :system
- when 'site' then
- RDoc::Store.new RDoc::RI::Paths.site_dir, :site
- when /^extra-(\d+)$/ then
- index = $1.to_i - 1
- ri_dir = installed_docs[index][4]
- RDoc::Store.new ri_dir, :extra
- else
- ri_dir, type = ri_paths.find do |dir, dir_type|
- next unless dir_type == :gem
-
- source_name == dir[%r%/([^/]*)/ri$%, 1]
- end
-
- raise WEBrick::HTTPStatus::NotFound,
- "Could not find gem \"#{source_name}\". Are you sure you installed it?" unless ri_dir
-
- store = RDoc::Store.new ri_dir, type
-
- return store if File.exist? store.cache_path
-
- raise WEBrick::HTTPStatus::NotFound,
- "Could not find documentation for \"#{source_name}\". Please run `gem rdoc --ri gem_name`"
-
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/single_class.rb b/ruby_2_2/lib/rdoc/single_class.rb
deleted file mode 100644
index 358e1f38eb..0000000000
--- a/ruby_2_2/lib/rdoc/single_class.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-##
-# A singleton class
-
-class RDoc::SingleClass < RDoc::ClassModule
-
- ##
- # Adds the superclass to the included modules.
-
- def ancestors
- superclass ? super + [superclass] : super
- end
-
- def aref_prefix # :nodoc:
- 'sclass'
- end
-
- ##
- # The definition of this singleton class, <tt>class << MyClassName</tt>
-
- def definition
- "class << #{full_name}"
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/stats.rb b/ruby_2_2/lib/rdoc/stats.rb
deleted file mode 100644
index 94fdd279c7..0000000000
--- a/ruby_2_2/lib/rdoc/stats.rb
+++ /dev/null
@@ -1,461 +0,0 @@
-##
-# RDoc statistics collector which prints a summary and report of a project's
-# documentation totals.
-
-class RDoc::Stats
-
- include RDoc::Text
-
- ##
- # Output level for the coverage report
-
- attr_reader :coverage_level
-
- ##
- # Count of files parsed during parsing
-
- attr_reader :files_so_far
-
- ##
- # Total number of files found
-
- attr_reader :num_files
-
- ##
- # Creates a new Stats that will have +num_files+. +verbosity+ defaults to 1
- # which will create an RDoc::Stats::Normal outputter.
-
- def initialize store, num_files, verbosity = 1
- @num_files = num_files
- @store = store
-
- @coverage_level = 0
- @doc_items = nil
- @files_so_far = 0
- @fully_documented = false
- @num_params = 0
- @percent_doc = nil
- @start = Time.now
- @undoc_params = 0
-
- @display = case verbosity
- when 0 then Quiet.new num_files
- when 1 then Normal.new num_files
- else Verbose.new num_files
- end
- end
-
- ##
- # Records the parsing of an alias +as+.
-
- def add_alias as
- @display.print_alias as
- end
-
- ##
- # Records the parsing of an attribute +attribute+
-
- def add_attribute attribute
- @display.print_attribute attribute
- end
-
- ##
- # Records the parsing of a class +klass+
-
- def add_class klass
- @display.print_class klass
- end
-
- ##
- # Records the parsing of +constant+
-
- def add_constant constant
- @display.print_constant constant
- end
-
- ##
- # Records the parsing of +file+
-
- def add_file(file)
- @files_so_far += 1
- @display.print_file @files_so_far, file
- end
-
- ##
- # Records the parsing of +method+
-
- def add_method(method)
- @display.print_method method
- end
-
- ##
- # Records the parsing of a module +mod+
-
- def add_module(mod)
- @display.print_module mod
- end
-
- ##
- # Call this to mark the beginning of parsing for display purposes
-
- def begin_adding
- @display.begin_adding
- end
-
- ##
- # Calculates documentation totals and percentages for classes, modules,
- # constants, attributes and methods.
-
- def calculate
- return if @doc_items
-
- ucm = @store.unique_classes_and_modules
-
- classes = @store.unique_classes.reject { |cm| cm.full_name == 'Object' }
-
- constants = []
- ucm.each { |cm| constants.concat cm.constants }
-
- methods = []
- ucm.each { |cm| methods.concat cm.method_list }
-
- attributes = []
- ucm.each { |cm| attributes.concat cm.attributes }
-
- @num_attributes, @undoc_attributes = doc_stats attributes
- @num_classes, @undoc_classes = doc_stats classes
- @num_constants, @undoc_constants = doc_stats constants
- @num_methods, @undoc_methods = doc_stats methods
- @num_modules, @undoc_modules = doc_stats @store.unique_modules
-
- @num_items =
- @num_attributes +
- @num_classes +
- @num_constants +
- @num_methods +
- @num_modules +
- @num_params
-
- @undoc_items =
- @undoc_attributes +
- @undoc_classes +
- @undoc_constants +
- @undoc_methods +
- @undoc_modules +
- @undoc_params
-
- @doc_items = @num_items - @undoc_items
- end
-
- ##
- # Sets coverage report level. Accepted values are:
- #
- # false or nil:: No report
- # 0:: Classes, modules, constants, attributes, methods
- # 1:: Level 0 + method parameters
-
- def coverage_level= level
- level = -1 unless level
-
- @coverage_level = level
- end
-
- ##
- # Returns the length and number of undocumented items in +collection+.
-
- def doc_stats collection
- visible = collection.select { |item| item.display? }
- [visible.length, visible.count { |item| not item.documented? }]
- end
-
- ##
- # Call this to mark the end of parsing for display purposes
-
- def done_adding
- @display.done_adding
- end
-
- ##
- # The documentation status of this project. +true+ when 100%, +false+ when
- # less than 100% and +nil+ when unknown.
- #
- # Set by calling #calculate
-
- def fully_documented?
- @fully_documented
- end
-
- ##
- # A report that says you did a great job!
-
- def great_job
- report = RDoc::Markup::Document.new
-
- report << RDoc::Markup::Paragraph.new('100% documentation!')
- report << RDoc::Markup::Paragraph.new('Great Job!')
-
- report
- end
-
- ##
- # Calculates the percentage of items documented.
-
- def percent_doc
- return @percent_doc if @percent_doc
-
- @fully_documented = (@num_items - @doc_items) == 0
-
- @percent_doc = @doc_items.to_f / @num_items * 100 if @num_items.nonzero?
- @percent_doc ||= 0
-
- @percent_doc
- end
-
- ##
- # Returns a report on which items are not documented
-
- def report
- if @coverage_level > 0 then
- extend RDoc::Text
- end
-
- if @coverage_level.zero? then
- calculate
-
- return great_job if @num_items == @doc_items
- end
-
- ucm = @store.unique_classes_and_modules
-
- report = RDoc::Markup::Document.new
- report << RDoc::Markup::Paragraph.new('The following items are not documented:')
- report << RDoc::Markup::BlankLine.new
-
- ucm.sort.each do |cm|
- body = report_class_module(cm) {
- [
- report_constants(cm),
- report_attributes(cm),
- report_methods(cm),
- ].compact
- }
-
- report << body if body
- end
-
- if @coverage_level > 0 then
- calculate
-
- return great_job if @num_items == @doc_items
- end
-
- report
- end
-
- ##
- # Returns a report on undocumented attributes in ClassModule +cm+
-
- def report_attributes cm
- return if cm.attributes.empty?
-
- report = []
-
- cm.each_attribute do |attr|
- next if attr.documented?
- line = attr.line ? ":#{attr.line}" : nil
- report << " #{attr.definition} :#{attr.name} # in file #{attr.file.full_name}#{line}\n"
- report << "\n"
- end
-
- report
- end
-
- ##
- # Returns a report on undocumented items in ClassModule +cm+
-
- def report_class_module cm
- return if cm.fully_documented? and @coverage_level.zero?
- return unless cm.display?
-
- report = RDoc::Markup::Document.new
-
- if cm.in_files.empty? then
- report << RDoc::Markup::Paragraph.new("#{cm.definition} is referenced but empty.")
- report << RDoc::Markup::Paragraph.new("It probably came from another project. I'm sorry I'm holding it against you.")
-
- return report
- elsif cm.documented? then
- documented = true
- klass = RDoc::Markup::Verbatim.new("#{cm.definition} # is documented\n")
- else
- report << RDoc::Markup::Paragraph.new('In files:')
-
- list = RDoc::Markup::List.new :BULLET
-
- cm.in_files.each do |file|
- para = RDoc::Markup::Paragraph.new file.full_name
- list << RDoc::Markup::ListItem.new(nil, para)
- end
-
- report << list
- report << RDoc::Markup::BlankLine.new
-
- klass = RDoc::Markup::Verbatim.new("#{cm.definition}\n")
- end
-
- klass << "\n"
-
- body = yield.flatten # HACK remove #flatten
-
- if body.empty? then
- return if documented
-
- klass.parts.pop
- else
- klass.parts.concat body
- end
-
- klass << "end\n"
-
- report << klass
-
- report
- end
-
- ##
- # Returns a report on undocumented constants in ClassModule +cm+
-
- def report_constants cm
- return if cm.constants.empty?
-
- report = []
-
- cm.each_constant do |constant|
- # TODO constant aliases are listed in the summary but not reported
- # figure out what to do here
- next if constant.documented? || constant.is_alias_for
-
- line = constant.line ? ":#{constant.line}" : line
- report << " # in file #{constant.file.full_name}#{line}\n"
- report << " #{constant.name} = nil\n"
- report << "\n"
- end
-
- report
- end
-
- ##
- # Returns a report on undocumented methods in ClassModule +cm+
-
- def report_methods cm
- return if cm.method_list.empty?
-
- report = []
-
- cm.each_method do |method|
- next if method.documented? and @coverage_level.zero?
-
- if @coverage_level > 0 then
- params, undoc = undoc_params method
-
- @num_params += params
-
- unless undoc.empty? then
- @undoc_params += undoc.length
-
- undoc = undoc.map do |param| "+#{param}+" end
- param_report = " # #{undoc.join ', '} is not documented\n"
- end
- end
-
- next if method.documented? and not param_report
-
- line = method.line ? ":#{method.line}" : nil
- scope = method.singleton ? 'self.' : nil
-
- report << " # in file #{method.file.full_name}#{line}\n"
- report << param_report if param_report
- report << " def #{scope}#{method.name}#{method.params}; end\n"
- report << "\n"
- end
-
- report
- end
-
- ##
- # Returns a summary of the collected statistics.
-
- def summary
- calculate
-
- num_width = [@num_files, @num_items].max.to_s.length
- undoc_width = [
- @undoc_attributes,
- @undoc_classes,
- @undoc_constants,
- @undoc_items,
- @undoc_methods,
- @undoc_modules,
- @undoc_params,
- ].max.to_s.length
-
- report = RDoc::Markup::Verbatim.new
-
- report << "Files: %*d\n" % [num_width, @num_files]
-
- report << "\n"
-
- report << "Classes: %*d (%*d undocumented)\n" % [
- num_width, @num_classes, undoc_width, @undoc_classes]
- report << "Modules: %*d (%*d undocumented)\n" % [
- num_width, @num_modules, undoc_width, @undoc_modules]
- report << "Constants: %*d (%*d undocumented)\n" % [
- num_width, @num_constants, undoc_width, @undoc_constants]
- report << "Attributes: %*d (%*d undocumented)\n" % [
- num_width, @num_attributes, undoc_width, @undoc_attributes]
- report << "Methods: %*d (%*d undocumented)\n" % [
- num_width, @num_methods, undoc_width, @undoc_methods]
- report << "Parameters: %*d (%*d undocumented)\n" % [
- num_width, @num_params, undoc_width, @undoc_params] if
- @coverage_level > 0
-
- report << "\n"
-
- report << "Total: %*d (%*d undocumented)\n" % [
- num_width, @num_items, undoc_width, @undoc_items]
-
- report << "%6.2f%% documented\n" % percent_doc
- report << "\n"
- report << "Elapsed: %0.1fs\n" % (Time.now - @start)
-
- RDoc::Markup::Document.new report
- end
-
- ##
- # Determines which parameters in +method+ were not documented. Returns a
- # total parameter count and an Array of undocumented methods.
-
- def undoc_params method
- @formatter ||= RDoc::Markup::ToTtOnly.new
-
- params = method.param_list
-
- params = params.map { |param| param.gsub(/^\*\*?/, '') }
-
- return 0, [] if params.empty?
-
- document = parse method.comment
-
- tts = document.accept @formatter
-
- undoc = params - tts
-
- [params.length, undoc]
- end
-
- autoload :Quiet, 'rdoc/stats/quiet'
- autoload :Normal, 'rdoc/stats/normal'
- autoload :Verbose, 'rdoc/stats/verbose'
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/stats/normal.rb b/ruby_2_2/lib/rdoc/stats/normal.rb
deleted file mode 100644
index ef366a500e..0000000000
--- a/ruby_2_2/lib/rdoc/stats/normal.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-begin
- require 'io/console/size'
-rescue LoadError
-end
-
-##
-# Stats printer that prints just the files being documented with a progress
-# bar
-
-class RDoc::Stats::Normal < RDoc::Stats::Quiet
-
- def begin_adding # :nodoc:
- puts "Parsing sources..."
- @last_width = 0
- end
-
- ##
- # Prints a file with a progress bar
-
- def print_file files_so_far, filename
- progress_bar = sprintf("%3d%% [%2d/%2d] ",
- 100 * files_so_far / @num_files,
- files_so_far,
- @num_files)
-
- # Print a progress bar, but make sure it fits on a single line. Filename
- # will be truncated if necessary.
- terminal_width = if defined?(IO) && IO.respond_to?(:console_size)
- IO.console_size[1].to_i.nonzero? || 80
- else
- 80
- end
- max_filename_size = terminal_width - progress_bar.size
-
- if filename.size > max_filename_size then
- # Turn "some_long_filename.rb" to "...ong_filename.rb"
- filename = filename[(filename.size - max_filename_size) .. -1]
- filename[0..2] = "..."
- end
-
- line = "#{progress_bar}#{filename}"
- if $stdout.tty?
- # Clean the line with whitespaces so that leftover output from the
- # previous line doesn't show up.
- $stdout.print("\r" << (" " * @last_width) << ("\b" * @last_width) << "\r") if @last_width && @last_width > 0
- @last_width = line.size
- $stdout.print("#{line}\r")
- else
- $stdout.puts(line)
- end
- $stdout.flush
- end
-
- def done_adding # :nodoc:
- puts
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/stats/quiet.rb b/ruby_2_2/lib/rdoc/stats/quiet.rb
deleted file mode 100644
index eed27b2a88..0000000000
--- a/ruby_2_2/lib/rdoc/stats/quiet.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-##
-# Stats printer that prints nothing
-
-class RDoc::Stats::Quiet
-
- ##
- # Creates a new Quiet that will print nothing
-
- def initialize num_files
- @num_files = num_files
- end
-
- ##
- # Prints a message at the beginning of parsing
-
- def begin_adding(*) end
-
- ##
- # Prints when an alias is added
-
- def print_alias(*) end
-
- ##
- # Prints when an attribute is added
-
- def print_attribute(*) end
-
- ##
- # Prints when a class is added
-
- def print_class(*) end
-
- ##
- # Prints when a constant is added
-
- def print_constant(*) end
-
- ##
- # Prints when a file is added
-
- def print_file(*) end
-
- ##
- # Prints when a method is added
-
- def print_method(*) end
-
- ##
- # Prints when a module is added
-
- def print_module(*) end
-
- ##
- # Prints when RDoc is done
-
- def done_adding(*) end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/stats/verbose.rb b/ruby_2_2/lib/rdoc/stats/verbose.rb
deleted file mode 100644
index 430809ae07..0000000000
--- a/ruby_2_2/lib/rdoc/stats/verbose.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-##
-# Stats printer that prints everything documented, including the documented
-# status
-
-class RDoc::Stats::Verbose < RDoc::Stats::Normal
-
- ##
- # Returns a marker for RDoc::CodeObject +co+ being undocumented
-
- def nodoc co
- " (undocumented)" unless co.documented?
- end
-
- def print_alias as # :nodoc:
- puts " alias #{as.new_name} #{as.old_name}#{nodoc as}"
- end
-
- def print_attribute attribute # :nodoc:
- puts " #{attribute.definition} #{attribute.name}#{nodoc attribute}"
- end
-
- def print_class(klass) # :nodoc:
- puts " class #{klass.full_name}#{nodoc klass}"
- end
-
- def print_constant(constant) # :nodoc:
- puts " #{constant.name}#{nodoc constant}"
- end
-
- def print_file(files_so_far, file) # :nodoc:
- super
- puts
- end
-
- def print_method(method) # :nodoc:
- puts " #{method.singleton ? '::' : '#'}#{method.name}#{nodoc method}"
- end
-
- def print_module(mod) # :nodoc:
- puts " module #{mod.full_name}#{nodoc mod}"
- end
-
-end
-
-
diff --git a/ruby_2_2/lib/rdoc/store.rb b/ruby_2_2/lib/rdoc/store.rb
deleted file mode 100644
index fde6f0695b..0000000000
--- a/ruby_2_2/lib/rdoc/store.rb
+++ /dev/null
@@ -1,979 +0,0 @@
-require 'fileutils'
-
-##
-# A set of rdoc data for a single project (gem, path, etc.).
-#
-# The store manages reading and writing ri data for a project and maintains a
-# cache of methods, classes and ancestors in the store.
-#
-# The store maintains a #cache of its contents for faster lookup. After
-# adding items to the store it must be flushed using #save_cache. The cache
-# contains the following structures:
-#
-# @cache = {
-# :ancestors => {}, # class name => ancestor names
-# :attributes => {}, # class name => attributes
-# :class_methods => {}, # class name => class methods
-# :instance_methods => {}, # class name => instance methods
-# :modules => [], # classes and modules in this store
-# :pages => [], # page names
-# }
-#--
-# TODO need to prune classes
-
-class RDoc::Store
-
- ##
- # Errors raised from loading or saving the store
-
- class Error < RDoc::Error
- end
-
- ##
- # Raised when a stored file for a class, module, page or method is missing.
-
- class MissingFileError < Error
-
- ##
- # The store the file should exist in
-
- attr_reader :store
-
- ##
- # The file the #name should be saved as
-
- attr_reader :file
-
- ##
- # The name of the object the #file would be loaded from
-
- attr_reader :name
-
- ##
- # Creates a new MissingFileError for the missing +file+ for the given
- # +name+ that should have been in the +store+.
-
- def initialize store, file, name
- @store = store
- @file = file
- @name = name
- end
-
- def message # :nodoc:
- "store at #{@store.path} missing file #{@file} for #{@name}"
- end
-
- end
-
- ##
- # Stores the name of the C variable a class belongs to. This helps wire up
- # classes defined from C across files.
-
- attr_reader :c_enclosure_classes # :nodoc:
-
- attr_reader :c_enclosure_names # :nodoc:
-
- ##
- # Maps C variables to class or module names for each parsed C file.
-
- attr_reader :c_class_variables
-
- ##
- # Maps C variables to singleton class names for each parsed C file.
-
- attr_reader :c_singleton_class_variables
-
- ##
- # If true this Store will not write any files
-
- attr_accessor :dry_run
-
- ##
- # Path this store reads or writes
-
- attr_accessor :path
-
- ##
- # The RDoc::RDoc driver for this parse tree. This allows classes consulting
- # the documentation tree to access user-set options, for example.
-
- attr_accessor :rdoc
-
- ##
- # Type of ri datastore this was loaded from. See RDoc::RI::Driver,
- # RDoc::RI::Paths.
-
- attr_accessor :type
-
- ##
- # The contents of the Store
-
- attr_reader :cache
-
- ##
- # The encoding of the contents in the Store
-
- attr_accessor :encoding
-
- ##
- # Creates a new Store of +type+ that will load or save to +path+
-
- def initialize path = nil, type = nil
- @dry_run = false
- @encoding = nil
- @path = path
- @rdoc = nil
- @type = type
-
- @cache = {
- :ancestors => {},
- :attributes => {},
- :class_methods => {},
- :c_class_variables => {},
- :c_singleton_class_variables => {},
- :encoding => @encoding,
- :instance_methods => {},
- :main => nil,
- :modules => [],
- :pages => [],
- :title => nil,
- }
-
- @classes_hash = {}
- @modules_hash = {}
- @files_hash = {}
-
- @c_enclosure_classes = {}
- @c_enclosure_names = {}
-
- @c_class_variables = {}
- @c_singleton_class_variables = {}
-
- @unique_classes = nil
- @unique_modules = nil
- end
-
- ##
- # Adds +module+ as an enclosure (namespace) for the given +variable+ for C
- # files.
-
- def add_c_enclosure variable, namespace
- @c_enclosure_classes[variable] = namespace
- end
-
- ##
- # Adds C variables from an RDoc::Parser::C
-
- def add_c_variables c_parser
- filename = c_parser.top_level.relative_name
-
- @c_class_variables[filename] = make_variable_map c_parser.classes
-
- @c_singleton_class_variables[filename] = c_parser.singleton_classes
- end
-
- ##
- # Adds the file with +name+ as an RDoc::TopLevel to the store. Returns the
- # created RDoc::TopLevel.
-
- def add_file absolute_name, relative_name = absolute_name
- unless top_level = @files_hash[relative_name] then
- top_level = RDoc::TopLevel.new absolute_name, relative_name
- top_level.store = self
- @files_hash[relative_name] = top_level
- end
-
- top_level
- end
-
- ##
- # Returns all classes discovered by RDoc
-
- def all_classes
- @classes_hash.values
- end
-
- ##
- # Returns all classes and modules discovered by RDoc
-
- def all_classes_and_modules
- @classes_hash.values + @modules_hash.values
- end
-
- ##
- # All TopLevels known to RDoc
-
- def all_files
- @files_hash.values
- end
-
- ##
- # Returns all modules discovered by RDoc
-
- def all_modules
- modules_hash.values
- end
-
- ##
- # Ancestors cache accessor. Maps a klass name to an Array of its ancestors
- # in this store. If Foo in this store inherits from Object, Kernel won't be
- # listed (it will be included from ruby's ri store).
-
- def ancestors
- @cache[:ancestors]
- end
-
- ##
- # Attributes cache accessor. Maps a class to an Array of its attributes.
-
- def attributes
- @cache[:attributes]
- end
-
- ##
- # Path to the cache file
-
- def cache_path
- File.join @path, 'cache.ri'
- end
-
- ##
- # Path to the ri data for +klass_name+
-
- def class_file klass_name
- name = klass_name.split('::').last
- File.join class_path(klass_name), "cdesc-#{name}.ri"
- end
-
- ##
- # Class methods cache accessor. Maps a class to an Array of its class
- # methods (not full name).
-
- def class_methods
- @cache[:class_methods]
- end
-
- ##
- # Path where data for +klass_name+ will be stored (methods or class data)
-
- def class_path klass_name
- File.join @path, *klass_name.split('::')
- end
-
- ##
- # Hash of all classes known to RDoc
-
- def classes_hash
- @classes_hash
- end
-
- ##
- # Removes empty items and ensures item in each collection are unique and
- # sorted
-
- def clean_cache_collection collection # :nodoc:
- collection.each do |name, item|
- if item.empty? then
- collection.delete name
- else
- # HACK mongrel-1.1.5 documents its files twice
- item.uniq!
- item.sort!
- end
- end
- end
-
- ##
- # Prepares the RDoc code object tree for use by a generator.
- #
- # It finds unique classes/modules defined, and replaces classes/modules that
- # are aliases for another one by a copy with RDoc::ClassModule#is_alias_for
- # set.
- #
- # It updates the RDoc::ClassModule#constant_aliases attribute of "real"
- # classes or modules.
- #
- # It also completely removes the classes and modules that should be removed
- # from the documentation and the methods that have a visibility below
- # +min_visibility+, which is the <tt>--visibility</tt> option.
- #
- # See also RDoc::Context#remove_from_documentation?
-
- def complete min_visibility
- fix_basic_object_inheritance
-
- # cache included modules before they are removed from the documentation
- all_classes_and_modules.each { |cm| cm.ancestors }
-
- unless min_visibility == :nodoc then
- remove_nodoc @classes_hash
- remove_nodoc @modules_hash
- end
-
- @unique_classes = find_unique @classes_hash
- @unique_modules = find_unique @modules_hash
-
- unique_classes_and_modules.each do |cm|
- cm.complete min_visibility
- end
-
- @files_hash.each_key do |file_name|
- tl = @files_hash[file_name]
-
- unless tl.text? then
- tl.modules_hash.clear
- tl.classes_hash.clear
-
- tl.classes_or_modules.each do |cm|
- name = cm.full_name
- if cm.type == 'class' then
- tl.classes_hash[name] = cm if @classes_hash[name]
- else
- tl.modules_hash[name] = cm if @modules_hash[name]
- end
- end
- end
- end
- end
-
- ##
- # Hash of all files known to RDoc
-
- def files_hash
- @files_hash
- end
-
- ##
- # Finds the enclosure (namespace) for the given C +variable+.
-
- def find_c_enclosure variable
- @c_enclosure_classes.fetch variable do
- break unless name = @c_enclosure_names[variable]
-
- mod = find_class_or_module name
-
- unless mod then
- loaded_mod = load_class_data name
-
- file = loaded_mod.in_files.first
-
- return unless file # legacy data source
-
- file.store = self
-
- mod = file.add_module RDoc::NormalModule, name
- end
-
- @c_enclosure_classes[variable] = mod
- end
- end
-
- ##
- # Finds the class with +name+ in all discovered classes
-
- def find_class_named name
- @classes_hash[name]
- end
-
- ##
- # Finds the class with +name+ starting in namespace +from+
-
- def find_class_named_from name, from
- from = find_class_named from unless RDoc::Context === from
-
- until RDoc::TopLevel === from do
- return nil unless from
-
- klass = from.find_class_named name
- return klass if klass
-
- from = from.parent
- end
-
- find_class_named name
- end
-
- ##
- # Finds the class or module with +name+
-
- def find_class_or_module name
- name = $' if name =~ /^::/
- @classes_hash[name] || @modules_hash[name]
- end
-
- ##
- # Finds the file with +name+ in all discovered files
-
- def find_file_named name
- @files_hash[name]
- end
-
- ##
- # Finds the module with +name+ in all discovered modules
-
- def find_module_named name
- @modules_hash[name]
- end
-
- ##
- # Returns the RDoc::TopLevel that is a text file and has the given
- # +file_name+
-
- def find_text_page file_name
- @files_hash.each_value.find do |file|
- file.text? and file.full_name == file_name
- end
- end
-
- ##
- # Finds unique classes/modules defined in +all_hash+,
- # and returns them as an array. Performs the alias
- # updates in +all_hash+: see ::complete.
- #--
- # TODO aliases should be registered by Context#add_module_alias
-
- def find_unique all_hash
- unique = []
-
- all_hash.each_pair do |full_name, cm|
- unique << cm if full_name == cm.full_name
- end
-
- unique
- end
-
- ##
- # Fixes the erroneous <tt>BasicObject < Object</tt> in 1.9.
- #
- # Because we assumed all classes without a stated superclass
- # inherit from Object, we have the above wrong inheritance.
- #
- # We fix BasicObject right away if we are running in a Ruby
- # version >= 1.9. If not, we may be documenting 1.9 source
- # while running under 1.8: we search the files of BasicObject
- # for "object.c", and fix the inheritance if we find it.
-
- def fix_basic_object_inheritance
- basic = classes_hash['BasicObject']
- return unless basic
- if RUBY_VERSION >= '1.9'
- basic.superclass = nil
- elsif basic.in_files.any? { |f| File.basename(f.full_name) == 'object.c' }
- basic.superclass = nil
- end
- end
-
- ##
- # Friendly rendition of #path
-
- def friendly_path
- case type
- when :gem then
- parent = File.expand_path '..', @path
- "gem #{File.basename parent}"
- when :home then '~/.rdoc'
- when :site then 'ruby site'
- when :system then 'ruby core'
- else @path
- end
- end
-
- def inspect # :nodoc:
- "#<%s:0x%x %s %p>" % [self.class, object_id, @path, module_names.sort]
- end
-
- ##
- # Instance methods cache accessor. Maps a class to an Array of its
- # instance methods (not full name).
-
- def instance_methods
- @cache[:instance_methods]
- end
-
- ##
- # Loads all items from this store into memory. This recreates a
- # documentation tree for use by a generator
-
- def load_all
- load_cache
-
- module_names.each do |module_name|
- mod = find_class_or_module(module_name) || load_class(module_name)
-
- # load method documentation since the loaded class/module does not have
- # it
- loaded_methods = mod.method_list.map do |method|
- load_method module_name, method.full_name
- end
-
- mod.method_list.replace loaded_methods
-
- loaded_attributes = mod.attributes.map do |attribute|
- load_method module_name, attribute.full_name
- end
-
- mod.attributes.replace loaded_attributes
- end
-
- all_classes_and_modules.each do |mod|
- descendent_re = /^#{mod.full_name}::[^:]+$/
-
- module_names.each do |name|
- next unless name =~ descendent_re
-
- descendent = find_class_or_module name
-
- case descendent
- when RDoc::NormalClass then
- mod.classes_hash[name] = descendent
- when RDoc::NormalModule then
- mod.modules_hash[name] = descendent
- end
- end
- end
-
- @cache[:pages].each do |page_name|
- page = load_page page_name
- @files_hash[page_name] = page
- end
- end
-
- ##
- # Loads cache file for this store
-
- def load_cache
- #orig_enc = @encoding
-
- open cache_path, 'rb' do |io|
- @cache = Marshal.load io.read
- end
-
- load_enc = @cache[:encoding]
-
- # TODO this feature will be time-consuming to add:
- # a) Encodings may be incompatible but transcodeable
- # b) Need to warn in the appropriate spots, wherever they may be
- # c) Need to handle cross-cache differences in encodings
- # d) Need to warn when generating into a cache with different encodings
- #
- #if orig_enc and load_enc != orig_enc then
- # warn "Cached encoding #{load_enc} is incompatible with #{orig_enc}\n" \
- # "from #{path}/cache.ri" unless
- # Encoding.compatible? orig_enc, load_enc
- #end
-
- @encoding = load_enc unless @encoding
-
- @cache[:pages] ||= []
- @cache[:main] ||= nil
- @cache[:c_class_variables] ||= {}
- @cache[:c_singleton_class_variables] ||= {}
-
- @cache[:c_class_variables].each do |_, map|
- map.each do |variable, name|
- @c_enclosure_names[variable] = name
- end
- end
-
- @cache
- rescue Errno::ENOENT
- end
-
- ##
- # Loads ri data for +klass_name+ and hooks it up to this store.
-
- def load_class klass_name
- obj = load_class_data klass_name
-
- obj.store = self
-
- case obj
- when RDoc::NormalClass then
- @classes_hash[klass_name] = obj
- when RDoc::NormalModule then
- @modules_hash[klass_name] = obj
- end
- end
-
- ##
- # Loads ri data for +klass_name+
-
- def load_class_data klass_name
- file = class_file klass_name
-
- open file, 'rb' do |io|
- Marshal.load io.read
- end
- rescue Errno::ENOENT => e
- error = MissingFileError.new(self, file, klass_name)
- error.set_backtrace e.backtrace
- raise error
- end
-
- ##
- # Loads ri data for +method_name+ in +klass_name+
-
- def load_method klass_name, method_name
- file = method_file klass_name, method_name
-
- open file, 'rb' do |io|
- obj = Marshal.load io.read
- obj.store = self
- obj.parent =
- find_class_or_module(klass_name) || load_class(klass_name) unless
- obj.parent
- obj
- end
- rescue Errno::ENOENT => e
- error = MissingFileError.new(self, file, klass_name + method_name)
- error.set_backtrace e.backtrace
- raise error
- end
-
- ##
- # Loads ri data for +page_name+
-
- def load_page page_name
- file = page_file page_name
-
- open file, 'rb' do |io|
- obj = Marshal.load io.read
- obj.store = self
- obj
- end
- rescue Errno::ENOENT => e
- error = MissingFileError.new(self, file, page_name)
- error.set_backtrace e.backtrace
- raise error
- end
-
- ##
- # Gets the main page for this RDoc store. This page is used as the root of
- # the RDoc server.
-
- def main
- @cache[:main]
- end
-
- ##
- # Sets the main page for this RDoc store.
-
- def main= page
- @cache[:main] = page
- end
-
- ##
- # Converts the variable => ClassModule map +variables+ from a C parser into
- # a variable => class name map.
-
- def make_variable_map variables
- map = {}
-
- variables.each { |variable, class_module|
- map[variable] = class_module.full_name
- }
-
- map
- end
-
- ##
- # Path to the ri data for +method_name+ in +klass_name+
-
- def method_file klass_name, method_name
- method_name = method_name.split('::').last
- method_name =~ /#(.*)/
- method_type = $1 ? 'i' : 'c'
- method_name = $1 if $1
-
- method_name = if ''.respond_to? :ord then
- method_name.gsub(/\W/) { "%%%02x" % $&[0].ord }
- else
- method_name.gsub(/\W/) { "%%%02x" % $&[0] }
- end
-
- File.join class_path(klass_name), "#{method_name}-#{method_type}.ri"
- end
-
- ##
- # Modules cache accessor. An Array of all the module (and class) names in
- # the store.
-
- def module_names
- @cache[:modules]
- end
-
- ##
- # Hash of all modules known to RDoc
-
- def modules_hash
- @modules_hash
- end
-
- ##
- # Returns the RDoc::TopLevel that is a text file and has the given +name+
-
- def page name
- @files_hash.each_value.find do |file|
- file.text? and file.page_name == name
- end
- end
-
- ##
- # Path to the ri data for +page_name+
-
- def page_file page_name
- file_name = File.basename(page_name).gsub('.', '_')
-
- File.join @path, File.dirname(page_name), "page-#{file_name}.ri"
- end
-
- ##
- # Removes from +all_hash+ the contexts that are nodoc or have no content.
- #
- # See RDoc::Context#remove_from_documentation?
-
- def remove_nodoc all_hash
- all_hash.keys.each do |name|
- context = all_hash[name]
- all_hash.delete(name) if context.remove_from_documentation?
- end
- end
-
- ##
- # Saves all entries in the store
-
- def save
- load_cache
-
- all_classes_and_modules.each do |klass|
- save_class klass
-
- klass.each_method do |method|
- save_method klass, method
- end
-
- klass.each_attribute do |attribute|
- save_method klass, attribute
- end
- end
-
- all_files.each do |file|
- save_page file
- end
-
- save_cache
- end
-
- ##
- # Writes the cache file for this store
-
- def save_cache
- clean_cache_collection @cache[:ancestors]
- clean_cache_collection @cache[:attributes]
- clean_cache_collection @cache[:class_methods]
- clean_cache_collection @cache[:instance_methods]
-
- @cache[:modules].uniq!
- @cache[:modules].sort!
-
- @cache[:pages].uniq!
- @cache[:pages].sort!
-
- @cache[:encoding] = @encoding # this gets set twice due to assert_cache
-
- @cache[:c_class_variables].merge! @c_class_variables
- @cache[:c_singleton_class_variables].merge! @c_singleton_class_variables
-
- return if @dry_run
-
- marshal = Marshal.dump @cache
-
- open cache_path, 'wb' do |io|
- io.write marshal
- end
- end
-
- ##
- # Writes the ri data for +klass+ (or module)
-
- def save_class klass
- full_name = klass.full_name
-
- FileUtils.mkdir_p class_path(full_name) unless @dry_run
-
- @cache[:modules] << full_name
-
- path = class_file full_name
-
- begin
- disk_klass = load_class full_name
-
- klass = disk_klass.merge klass
- rescue MissingFileError
- end
-
- # BasicObject has no ancestors
- ancestors = klass.direct_ancestors.compact.map do |ancestor|
- # HACK for classes we don't know about (class X < RuntimeError)
- String === ancestor ? ancestor : ancestor.full_name
- end
-
- @cache[:ancestors][full_name] ||= []
- @cache[:ancestors][full_name].concat ancestors
-
- attribute_definitions = klass.attributes.map do |attribute|
- "#{attribute.definition} #{attribute.name}"
- end
-
- unless attribute_definitions.empty? then
- @cache[:attributes][full_name] ||= []
- @cache[:attributes][full_name].concat attribute_definitions
- end
-
- to_delete = []
-
- unless klass.method_list.empty? then
- @cache[:class_methods][full_name] ||= []
- @cache[:instance_methods][full_name] ||= []
-
- class_methods, instance_methods =
- klass.method_list.partition { |meth| meth.singleton }
-
- class_methods = class_methods. map { |method| method.name }
- instance_methods = instance_methods.map { |method| method.name }
- attribute_names = klass.attributes.map { |attr| attr.name }
-
- old = @cache[:class_methods][full_name] - class_methods
- to_delete.concat old.map { |method|
- method_file full_name, "#{full_name}::#{method}"
- }
-
- old = @cache[:instance_methods][full_name] -
- instance_methods - attribute_names
- to_delete.concat old.map { |method|
- method_file full_name, "#{full_name}##{method}"
- }
-
- @cache[:class_methods][full_name] = class_methods
- @cache[:instance_methods][full_name] = instance_methods
- end
-
- return if @dry_run
-
- FileUtils.rm_f to_delete
-
- marshal = Marshal.dump klass
-
- open path, 'wb' do |io|
- io.write marshal
- end
- end
-
- ##
- # Writes the ri data for +method+ on +klass+
-
- def save_method klass, method
- full_name = klass.full_name
-
- FileUtils.mkdir_p class_path(full_name) unless @dry_run
-
- cache = if method.singleton then
- @cache[:class_methods]
- else
- @cache[:instance_methods]
- end
- cache[full_name] ||= []
- cache[full_name] << method.name
-
- return if @dry_run
-
- marshal = Marshal.dump method
-
- open method_file(full_name, method.full_name), 'wb' do |io|
- io.write marshal
- end
- end
-
- ##
- # Writes the ri data for +page+
-
- def save_page page
- return unless page.text?
-
- path = page_file page.full_name
-
- FileUtils.mkdir_p File.dirname(path) unless @dry_run
-
- cache[:pages] ||= []
- cache[:pages] << page.full_name
-
- return if @dry_run
-
- marshal = Marshal.dump page
-
- open path, 'wb' do |io|
- io.write marshal
- end
- end
-
- ##
- # Source of the contents of this store.
- #
- # For a store from a gem the source is the gem name. For a store from the
- # home directory the source is "home". For system ri store (the standard
- # library documentation) the source is"ruby". For a store from the site
- # ri directory the store is "site". For other stores the source is the
- # #path.
-
- def source
- case type
- when :gem then File.basename File.expand_path '..', @path
- when :home then 'home'
- when :site then 'site'
- when :system then 'ruby'
- else @path
- end
- end
-
- ##
- # Gets the title for this RDoc store. This is used as the title in each
- # page on the RDoc server
-
- def title
- @cache[:title]
- end
-
- ##
- # Sets the title page for this RDoc store.
-
- def title= title
- @cache[:title] = title
- end
-
- ##
- # Returns the unique classes discovered by RDoc.
- #
- # ::complete must have been called prior to using this method.
-
- def unique_classes
- @unique_classes
- end
-
- ##
- # Returns the unique classes and modules discovered by RDoc.
- # ::complete must have been called prior to using this method.
-
- def unique_classes_and_modules
- @unique_classes + @unique_modules
- end
-
- ##
- # Returns the unique modules discovered by RDoc.
- # ::complete must have been called prior to using this method.
-
- def unique_modules
- @unique_modules
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/task.rb b/ruby_2_2/lib/rdoc/task.rb
deleted file mode 100644
index a83939090d..0000000000
--- a/ruby_2_2/lib/rdoc/task.rb
+++ /dev/null
@@ -1,330 +0,0 @@
-#--
-# Copyright (c) 2003, 2004 Jim Weirich, 2009 Eric Hodel
-#
-# Permission is hereby granted, free of charge, to any person obtaining
-# a copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice shall be
-# included in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#++
-
-require 'rubygems'
-begin
- gem 'rdoc'
-rescue Gem::LoadError
-end unless defined?(RDoc)
-
-begin
- gem 'rake'
-rescue Gem::LoadError
-end unless defined?(Rake)
-
-require 'rdoc'
-require 'rake'
-require 'rake/tasklib'
-
-##
-# RDoc::Task creates the following rake tasks to generate and clean up RDoc
-# output:
-#
-# [rdoc]
-# Main task for this RDoc task.
-#
-# [clobber_rdoc]
-# Delete all the rdoc files. This target is automatically added to the main
-# clobber target.
-#
-# [rerdoc]
-# Rebuild the rdoc files from scratch, even if they are not out of date.
-#
-# Simple Example:
-#
-# require 'rdoc/task'
-#
-# RDoc::Task.new do |rdoc|
-# rdoc.main = "README.rdoc"
-# rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb")
-# end
-#
-# The +rdoc+ object passed to the block is an RDoc::Task object. See the
-# attributes list for the RDoc::Task class for available customization options.
-#
-# == Specifying different task names
-#
-# You may wish to give the task a different name, such as if you are
-# generating two sets of documentation. For instance, if you want to have a
-# development set of documentation including private methods:
-#
-# require 'rdoc/task'
-#
-# RDoc::Task.new :rdoc_dev do |rdoc|
-# rdoc.main = "README.doc"
-# rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb")
-# rdoc.options << "--all"
-# end
-#
-# The tasks would then be named :<em>rdoc_dev</em>,
-# :clobber_<em>rdoc_dev</em>, and :re<em>rdoc_dev</em>.
-#
-# If you wish to have completely different task names, then pass a Hash as
-# first argument. With the <tt>:rdoc</tt>, <tt>:clobber_rdoc</tt> and
-# <tt>:rerdoc</tt> options, you can customize the task names to your liking.
-#
-# For example:
-#
-# require 'rdoc/task'
-#
-# RDoc::Task.new(:rdoc => "rdoc", :clobber_rdoc => "rdoc:clean",
-# :rerdoc => "rdoc:force")
-#
-# This will create the tasks <tt>:rdoc</tt>, <tt>:rdoc:clean</tt> and
-# <tt>:rdoc:force</tt>.
-
-class RDoc::Task < Rake::TaskLib
-
- ##
- # Name of the main, top level task. (default is :rdoc)
-
- attr_accessor :name
-
- ##
- # Comment markup format. rdoc, rd and tomdoc are supported. (default is
- # 'rdoc')
-
- attr_accessor :markup
-
- ##
- # Name of directory to receive the html output files. (default is "html")
-
- attr_accessor :rdoc_dir
-
- ##
- # Title of RDoc documentation. (defaults to rdoc's default)
-
- attr_accessor :title
-
- ##
- # Name of file to be used as the main, top level file of the RDoc. (default
- # is none)
-
- attr_accessor :main
-
- ##
- # Name of template to be used by rdoc. (defaults to rdoc's default)
-
- attr_accessor :template
-
- ##
- # Name of format generator (<tt>--format<tt>) used by rdoc. (defaults to
- # rdoc's default)
-
- attr_accessor :generator
-
- ##
- # List of files to be included in the rdoc generation. (default is [])
-
- attr_accessor :rdoc_files
-
- ##
- # Additional list of options to be passed rdoc. (default is [])
-
- attr_accessor :options
-
- ##
- # Whether to run the rdoc process as an external shell (default is false)
-
- attr_accessor :external
-
- ##
- # Create an RDoc task with the given name. See the RDoc::Task class overview
- # for documentation.
-
- def initialize name = :rdoc # :yield: self
- defaults
-
- check_names name
-
- @name = name
-
- yield self if block_given?
-
- define
- end
-
- ##
- # Ensures that +names+ only includes names for the :rdoc, :clobber_rdoc and
- # :rerdoc. If other names are given an ArgumentError is raised.
-
- def check_names names
- return unless Hash === names
-
- invalid_options =
- names.keys.map { |k| k.to_sym } - [:rdoc, :clobber_rdoc, :rerdoc]
-
- unless invalid_options.empty? then
- raise ArgumentError, "invalid options: #{invalid_options.join ', '}"
- end
- end
-
- ##
- # Task description for the clobber rdoc task or its renamed equivalent
-
- def clobber_task_description
- "Remove RDoc HTML files"
- end
-
- ##
- # Sets default task values
-
- def defaults
- @name = :rdoc
- @rdoc_files = Rake::FileList.new
- @rdoc_dir = 'html'
- @main = nil
- @title = nil
- @template = nil
- @generator = nil
- @options = []
- end
-
- ##
- # All source is inline now. This method is deprecated
-
- def inline_source # :nodoc:
- warn "RDoc::Task#inline_source is deprecated"
- true
- end
-
- ##
- # All source is inline now. This method is deprecated
-
- def inline_source=(value) # :nodoc:
- warn "RDoc::Task#inline_source is deprecated"
- end
-
- ##
- # Create the tasks defined by this task lib.
-
- def define
- desc rdoc_task_description
- task rdoc_task_name
-
- desc rerdoc_task_description
- task rerdoc_task_name => [clobber_task_name, rdoc_task_name]
-
- desc clobber_task_description
- task clobber_task_name do
- rm_r @rdoc_dir rescue nil
- end
-
- task :clobber => [clobber_task_name]
-
- directory @rdoc_dir
-
- rdoc_target_deps = [
- @rdoc_files,
- Rake.application.rakefile
- ].flatten.compact
-
- task rdoc_task_name => [rdoc_target]
- file rdoc_target => rdoc_target_deps do
- @before_running_rdoc.call if @before_running_rdoc
- args = option_list + @rdoc_files
-
- $stderr.puts "rdoc #{args.join ' '}" if Rake.application.options.trace
- RDoc::RDoc.new.document args
- end
-
- self
- end
-
- ##
- # List of options that will be supplied to RDoc
-
- def option_list
- result = @options.dup
- result << "-o" << @rdoc_dir
- result << "--main" << main if main
- result << "--markup" << markup if markup
- result << "--title" << title if title
- result << "-T" << template if template
- result << '-f' << generator if generator
- result
- end
-
- ##
- # The block passed to this method will be called just before running the
- # RDoc generator. It is allowed to modify RDoc::Task attributes inside the
- # block.
-
- def before_running_rdoc(&block)
- @before_running_rdoc = block
- end
-
- ##
- # Task description for the rdoc task or its renamed equivalent
-
- def rdoc_task_description
- 'Build RDoc HTML files'
- end
-
- ##
- # Task description for the rerdoc task or its renamed description
-
- def rerdoc_task_description
- "Rebuild RDoc HTML files"
- end
-
- private
-
- def rdoc_target
- "#{rdoc_dir}/created.rid"
- end
-
- def rdoc_task_name
- case name
- when Hash then (name[:rdoc] || "rdoc").to_s
- else name.to_s
- end
- end
-
- def clobber_task_name
- case name
- when Hash then (name[:clobber_rdoc] || "clobber_rdoc").to_s
- else "clobber_#{name}"
- end
- end
-
- def rerdoc_task_name
- case name
- when Hash then (name[:rerdoc] || "rerdoc").to_s
- else "re#{name}"
- end
- end
-
-end
-
-# :stopdoc:
-module Rake
-
- ##
- # For backwards compatibility
-
- RDocTask = RDoc::Task
-
-end
-# :startdoc:
-
diff --git a/ruby_2_2/lib/rdoc/test_case.rb b/ruby_2_2/lib/rdoc/test_case.rb
deleted file mode 100644
index 4989516b7a..0000000000
--- a/ruby_2_2/lib/rdoc/test_case.rb
+++ /dev/null
@@ -1,217 +0,0 @@
-require 'rubygems'
-
-begin
- gem 'minitest', '~> 4.0' unless defined?(Test::Unit)
-rescue NoMethodError, Gem::LoadError
- # for ruby tests
-end
-
-require 'minitest/autorun'
-require 'minitest/benchmark' if ENV['BENCHMARK']
-
-require 'fileutils'
-require 'pp'
-require 'tempfile'
-require 'tmpdir'
-require 'stringio'
-
-require 'rdoc'
-
-##
-# RDoc::TestCase is an abstract TestCase to provide common setup and teardown
-# across all RDoc tests. The test case uses minitest, so all the assertions
-# of minitest may be used.
-#
-# The testcase provides the following:
-#
-# * A reset code-object tree
-# * A reset markup preprocessor (RDoc::Markup::PreProcess)
-# * The <code>@RM</code> alias of RDoc::Markup (for less typing)
-# * <code>@pwd</code> containing the current working directory
-# * FileUtils, pp, Tempfile, Dir.tmpdir and StringIO
-
-class RDoc::TestCase < MiniTest::Unit::TestCase
-
- ##
- # Abstract test-case setup
-
- def setup
- super
-
- @top_level = nil
-
- @have_encoding = Object.const_defined? :Encoding
-
- @RM = RDoc::Markup
-
- RDoc::Markup::PreProcess.reset
-
- @pwd = Dir.pwd
-
- @store = RDoc::Store.new
-
- @rdoc = RDoc::RDoc.new
- @rdoc.store = @store
- @rdoc.options = RDoc::Options.new
-
- g = Object.new
- def g.class_dir() end
- def g.file_dir() end
- @rdoc.generator = g
- end
-
- ##
- # Asserts +path+ is a file
-
- def assert_file path
- assert File.file?(path), "#{path} is not a file"
- end
-
- ##
- # Asserts +path+ is a directory
-
- def assert_directory path
- assert File.directory?(path), "#{path} is not a directory"
- end
-
- ##
- # Refutes +path+ exists
-
- def refute_file path
- refute File.exist?(path), "#{path} exists"
- end
-
- ##
- # Shortcut for RDoc::Markup::BlankLine.new
-
- def blank_line
- @RM::BlankLine.new
- end
-
- ##
- # Shortcut for RDoc::Markup::BlockQuote.new with +contents+
-
- def block *contents
- @RM::BlockQuote.new(*contents)
- end
-
- ##
- # Creates an RDoc::Comment with +text+ which was defined on +top_level+.
- # By default the comment has the 'rdoc' format.
-
- def comment text, top_level = @top_level
- RDoc::Comment.new text, top_level
- end
-
- ##
- # Shortcut for RDoc::Markup::Document.new with +contents+
-
- def doc *contents
- @RM::Document.new(*contents)
- end
-
- ##
- # Shortcut for RDoc::Markup::HardBreak.new
-
- def hard_break
- @RM::HardBreak.new
- end
-
- ##
- # Shortcut for RDoc::Markup::Heading.new with +level+ and +text+
-
- def head level, text
- @RM::Heading.new level, text
- end
-
- ##
- # Shortcut for RDoc::Markup::ListItem.new with +label+ and +parts+
-
- def item label = nil, *parts
- @RM::ListItem.new label, *parts
- end
-
- ##
- # Shortcut for RDoc::Markup::List.new with +type+ and +items+
-
- def list type = nil, *items
- @RM::List.new type, *items
- end
-
- ##
- # Enables pretty-print output
-
- def mu_pp obj # :nodoc:
- s = ''
- s = PP.pp obj, s
- s = s.force_encoding Encoding.default_external if defined? Encoding
- s.chomp
- end
-
- ##
- # Shortcut for RDoc::Markup::Paragraph.new with +contents+
-
- def para *a
- @RM::Paragraph.new(*a)
- end
-
- ##
- # Shortcut for RDoc::Markup::Rule.new with +weight+
-
- def rule weight
- @RM::Rule.new weight
- end
-
- ##
- # Shortcut for RDoc::Markup::Raw.new with +contents+
-
- def raw *contents
- @RM::Raw.new(*contents)
- end
-
- ##
- # Creates a temporary directory changes the current directory to it for the
- # duration of the block.
- #
- # Depends upon Dir.mktmpdir
-
- def temp_dir
- skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir
-
- Dir.mktmpdir do |temp_dir|
- Dir.chdir temp_dir do
- yield temp_dir
- end
- end
- end
-
- ##
- # Shortcut for RDoc::Markup::Verbatim.new with +parts+
-
- def verb *parts
- @RM::Verbatim.new(*parts)
- end
-
- ##
- # run capture_io with setting $VERBOSE = true
-
- def verbose_capture_io
- capture_io do
- begin
- orig_verbose = $VERBOSE
- $VERBOSE = true
- yield
- ensure
- $VERBOSE = orig_verbose
- end
- end
- end
-end
-
-# This hack allows autoload to work when Dir.pwd is changed for Ruby 1.8 since
-# -I paths are not expanded.
-$LOAD_PATH.each do |load_path|
- break if load_path[0] == ?/
- load_path.replace File.expand_path load_path
-end if RUBY_VERSION < '1.9'
-
diff --git a/ruby_2_2/lib/rdoc/text.rb b/ruby_2_2/lib/rdoc/text.rb
deleted file mode 100644
index 606f15eb0e..0000000000
--- a/ruby_2_2/lib/rdoc/text.rb
+++ /dev/null
@@ -1,324 +0,0 @@
-# coding: utf-8
-
-##
-# For RDoc::Text#to_html
-
-require 'strscan'
-
-##
-# For RDoc::Text#snippet
-
-begin
- gem 'json'
-rescue Gem::LoadError
-end
-
-require 'json'
-
-##
-# Methods for manipulating comment text
-
-module RDoc::Text
-
- ##
- # Maps markup formats to classes that can parse them. If the format is
- # unknown, "rdoc" format is used.
-
- MARKUP_FORMAT = {
- 'markdown' => RDoc::Markdown,
- 'rdoc' => RDoc::Markup,
- 'rd' => RDoc::RD,
- 'tomdoc' => RDoc::TomDoc,
- }
-
- MARKUP_FORMAT.default = RDoc::Markup
-
- ##
- # Maps an encoding to a Hash of characters properly transcoded for that
- # encoding.
- #
- # See also encode_fallback.
-
- TO_HTML_CHARACTERS = Hash.new do |h, encoding|
- h[encoding] = {
- :close_dquote => encode_fallback('”', encoding, '"'),
- :close_squote => encode_fallback('’', encoding, '\''),
- :copyright => encode_fallback('©', encoding, '(c)'),
- :ellipsis => encode_fallback('…', encoding, '...'),
- :em_dash => encode_fallback('—', encoding, '---'),
- :en_dash => encode_fallback('–', encoding, '--'),
- :open_dquote => encode_fallback('“', encoding, '"'),
- :open_squote => encode_fallback('‘', encoding, '\''),
- :trademark => encode_fallback('®', encoding, '(r)'),
- }
- end if Object.const_defined? :Encoding
-
- ##
- # Transcodes +character+ to +encoding+ with a +fallback+ character.
-
- def self.encode_fallback character, encoding, fallback
- character.encode(encoding, :fallback => { character => fallback },
- :undef => :replace, :replace => fallback)
- end
-
- ##
- # Expands tab characters in +text+ to eight spaces
-
- def expand_tabs text
- expanded = []
-
- text.each_line do |line|
- nil while line.gsub!(/(?:\G|\r)((?:.{8})*?)([^\t\r\n]{0,7})\t/) do
- r = "#{$1}#{$2}#{' ' * (8 - $2.size)}"
- r.force_encoding text.encoding if Object.const_defined? :Encoding
- r
- end
-
- expanded << line
- end
-
- expanded.join
- end
-
- ##
- # Flush +text+ left based on the shortest line
-
- def flush_left text
- indent = 9999
-
- text.each_line do |line|
- line_indent = line =~ /\S/ || 9999
- indent = line_indent if indent > line_indent
- end
-
- empty = ''
- empty.force_encoding text.encoding if Object.const_defined? :Encoding
-
- text.gsub(/^ {0,#{indent}}/, empty)
- end
-
- ##
- # Convert a string in markup format into HTML.
- #
- # Requires the including class to implement #formatter
-
- def markup text
- if @store.rdoc.options
- locale = @store.rdoc.options.locale
- else
- locale = nil
- end
- if locale
- i18n_text = RDoc::I18n::Text.new(text)
- text = i18n_text.translate(locale)
- end
- parse(text).accept formatter
- end
-
- ##
- # Strips hashes, expands tabs then flushes +text+ to the left
-
- def normalize_comment text
- return text if text.empty?
-
- text = strip_stars text
- text = strip_hashes text
- text = expand_tabs text
- text = flush_left text
- text = strip_newlines text
- text
- end
-
- ##
- # Normalizes +text+ then builds a RDoc::Markup::Document from it
-
- def parse text, format = 'rdoc'
- return text if RDoc::Markup::Document === text
- return text.parse if RDoc::Comment === text
-
- text = normalize_comment text # TODO remove, should not be necessary
-
- return RDoc::Markup::Document.new if text =~ /\A\n*\z/
-
- MARKUP_FORMAT[format].parse text
- end
-
- ##
- # The first +limit+ characters of +text+ as HTML
-
- def snippet text, limit = 100
- document = parse text
-
- RDoc::Markup::ToHtmlSnippet.new(options, limit).convert document
- end
-
- ##
- # Strips leading # characters from +text+
-
- def strip_hashes text
- return text if text =~ /^(?>\s*)[^\#]/
-
- empty = ''
- empty.force_encoding text.encoding if Object.const_defined? :Encoding
-
- text.gsub(/^\s*(#+)/) { $1.tr '#', ' ' }.gsub(/^\s+$/, empty)
- end
-
- ##
- # Strips leading and trailing \n characters from +text+
-
- def strip_newlines text
- text.gsub(/\A\n*(.*?)\n*\z/m) do $1 end # block preserves String encoding
- end
-
- ##
- # Strips /* */ style comments
-
- def strip_stars text
- return text unless text =~ %r%/\*.*\*/%m
-
- encoding = text.encoding if Object.const_defined? :Encoding
-
- text = text.gsub %r%Document-method:\s+[\w:.#=!?]+%, ''
-
- space = ' '
- space.force_encoding encoding if encoding
-
- text.sub! %r%/\*+% do space * $&.length end
- text.sub! %r%\*+/% do space * $&.length end
- text.gsub! %r%^[ \t]*\*%m do space * $&.length end
-
- empty = ''
- empty.force_encoding encoding if encoding
- text.gsub(/^\s+$/, empty)
- end
-
- ##
- # Converts ampersand, dashes, ellipsis, quotes, copyright and registered
- # trademark symbols in +text+ to properly encoded characters.
-
- def to_html text
- if Object.const_defined? :Encoding then
- html = ''.encode text.encoding
-
- encoded = RDoc::Text::TO_HTML_CHARACTERS[text.encoding]
- else
- html = ''
- encoded = {
- :close_dquote => '”',
- :close_squote => '’',
- :copyright => '©',
- :ellipsis => '…',
- :em_dash => '—',
- :en_dash => '–',
- :open_dquote => '“',
- :open_squote => '‘',
- :trademark => '®',
- }
- end
-
- s = StringScanner.new text
- insquotes = false
- indquotes = false
- after_word = nil
-
- until s.eos? do
- case
- when s.scan(/<(tt|code)>.*?<\/\1>/) then # skip contents of tt
- html << s.matched.gsub('\\\\', '\\')
- when s.scan(/<(tt|code)>.*?/) then
- warn "mismatched <#{s[1]}> tag" # TODO signal file/line
- html << s.matched
- when s.scan(/<[^>]+\/?s*>/) then # skip HTML tags
- html << s.matched
- when s.scan(/\\(\S)/) then # unhandled suppressed crossref
- html << s[1]
- after_word = nil
- when s.scan(/\.\.\.(\.?)/) then
- html << s[1] << encoded[:ellipsis]
- after_word = nil
- when s.scan(/\(c\)/) then
- html << encoded[:copyright]
- after_word = nil
- when s.scan(/\(r\)/) then
- html << encoded[:trademark]
- after_word = nil
- when s.scan(/---/) then
- html << encoded[:em_dash]
- after_word = nil
- when s.scan(/--/) then
- html << encoded[:en_dash]
- after_word = nil
- when s.scan(/&quot;|"/) then
- html << encoded[indquotes ? :close_dquote : :open_dquote]
- indquotes = !indquotes
- after_word = nil
- when s.scan(/``/) then # backtick double quote
- html << encoded[:open_dquote]
- after_word = nil
- when s.scan(/''/) then # tick double quote
- html << encoded[:close_dquote]
- after_word = nil
- when s.scan(/'/) then # single quote
- if insquotes
- html << encoded[:close_squote]
- insquotes = false
- elsif after_word
- # Mary's dog, my parents' house: do not start paired quotes
- html << encoded[:close_squote]
- else
- html << encoded[:open_squote]
- insquotes = true
- end
-
- after_word = nil
- else # advance to the next potentially significant character
- match = s.scan(/.+?(?=[<\\.("'`&-])/) #"
-
- if match then
- html << match
- after_word = match =~ /\w$/
- else
- html << s.rest
- break
- end
- end
- end
-
- html
- end
-
- ##
- # Wraps +txt+ to +line_len+
-
- def wrap(txt, line_len = 76)
- res = []
- sp = 0
- ep = txt.length
-
- while sp < ep
- # scan back for a space
- p = sp + line_len - 1
- if p >= ep
- p = ep
- else
- while p > sp and txt[p] != ?\s
- p -= 1
- end
- if p <= sp
- p = sp + line_len
- while p < ep and txt[p] != ?\s
- p += 1
- end
- end
- end
- res << txt[sp...p] << "\n"
- sp = p
- sp += 1 while sp < ep and txt[sp] == ?\s
- end
-
- res.join.strip
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/token_stream.rb b/ruby_2_2/lib/rdoc/token_stream.rb
deleted file mode 100644
index b46b7da2f7..0000000000
--- a/ruby_2_2/lib/rdoc/token_stream.rb
+++ /dev/null
@@ -1,95 +0,0 @@
-##
-# A TokenStream is a list of tokens, gathered during the parse of some entity
-# (say a method). Entities populate these streams by being registered with the
-# lexer. Any class can collect tokens by including TokenStream. From the
-# outside, you use such an object by calling the start_collecting_tokens
-# method, followed by calls to add_token and pop_token.
-
-module RDoc::TokenStream
-
- ##
- # Converts +token_stream+ to HTML wrapping various tokens with
- # <tt><span></tt> elements. The following tokens types are wrapped in spans
- # with the given class names:
- #
- # TkCONSTANT :: 'ruby-constant'
- # TkKW :: 'ruby-keyword'
- # TkIVAR :: 'ruby-ivar'
- # TkOp :: 'ruby-operator'
- # TkId :: 'ruby-identifier'
- # TkNode :: 'ruby-node'
- # TkCOMMENT :: 'ruby-comment'
- # TkREGEXP :: 'ruby-regexp'
- # TkSTRING :: 'ruby-string'
- # TkVal :: 'ruby-value'
- #
- # Other token types are not wrapped in spans.
-
- def self.to_html token_stream
- token_stream.map do |t|
- next unless t
-
- style = case t
- when RDoc::RubyToken::TkCONSTANT then 'ruby-constant'
- when RDoc::RubyToken::TkKW then 'ruby-keyword'
- when RDoc::RubyToken::TkIVAR then 'ruby-ivar'
- when RDoc::RubyToken::TkOp then 'ruby-operator'
- when RDoc::RubyToken::TkId then 'ruby-identifier'
- when RDoc::RubyToken::TkNode then 'ruby-node'
- when RDoc::RubyToken::TkCOMMENT then 'ruby-comment'
- when RDoc::RubyToken::TkREGEXP then 'ruby-regexp'
- when RDoc::RubyToken::TkSTRING then 'ruby-string'
- when RDoc::RubyToken::TkVal then 'ruby-value'
- end
-
- text = CGI.escapeHTML t.text
-
- if style then
- "<span class=\"#{style}\">#{text}</span>"
- else
- text
- end
- end.join
- end
-
- ##
- # Adds +tokens+ to the collected tokens
-
- def add_tokens(*tokens)
- tokens.flatten.each { |token| @token_stream << token }
- end
-
- alias add_token add_tokens
-
- ##
- # Starts collecting tokens
-
- def collect_tokens
- @token_stream = []
- end
-
- alias start_collecting_tokens collect_tokens
-
- ##
- # Remove the last token from the collected tokens
-
- def pop_token
- @token_stream.pop
- end
-
- ##
- # Current token stream
-
- def token_stream
- @token_stream
- end
-
- ##
- # Returns a string representation of the token stream
-
- def tokens_to_s
- token_stream.compact.map { |token| token.text }.join ''
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/tom_doc.rb b/ruby_2_2/lib/rdoc/tom_doc.rb
deleted file mode 100644
index 2b62243525..0000000000
--- a/ruby_2_2/lib/rdoc/tom_doc.rb
+++ /dev/null
@@ -1,257 +0,0 @@
-# :markup: tomdoc
-
-# A parser for TomDoc based on TomDoc 1.0.0-rc1 (02adef9b5a)
-#
-# The TomDoc specification can be found at:
-#
-# http://tomdoc.org
-#
-# The latest version of the TomDoc specification can be found at:
-#
-# https://github.com/mojombo/tomdoc/blob/master/tomdoc.md
-#
-# To choose TomDoc as your only default format see RDoc::Options@Saved+Options
-# for instructions on setting up a <code>.rdoc_options</code> file to store
-# your project default.
-#
-# There are a few differences between this parser and the specification. A
-# best-effort was made to follow the specification as closely as possible but
-# some choices to deviate were made.
-#
-# A future version of RDoc will warn when a MUST or MUST NOT is violated and
-# may warn when a SHOULD or SHOULD NOT is violated. RDoc will always try
-# to emit documentation even if given invalid TomDoc.
-#
-# Here are some implementation choices this parser currently makes:
-#
-# This parser allows rdoc-style inline markup but you should not depended on
-# it.
-#
-# This parser allows a space between the comment and the method body.
-#
-# This parser does not require the default value to be described for an
-# optional argument.
-#
-# This parser does not examine the order of sections. An Examples section may
-# precede the Arguments section.
-#
-# This class is documented in TomDoc format. Since this is a subclass of the
-# RDoc markup parser there isn't much to see here, unfortunately.
-
-class RDoc::TomDoc < RDoc::Markup::Parser
-
- # Internal: Token accessor
-
- attr_reader :tokens
-
- # Internal: Adds a post-processor which sets the RDoc section based on the
- # comment's status.
- #
- # Returns nothing.
-
- def self.add_post_processor # :nodoc:
- RDoc::Markup::PreProcess.post_process do |comment, code_object|
- next unless code_object and
- RDoc::Comment === comment and comment.format == 'tomdoc'
-
- comment.text.gsub!(/(\A\s*# )(Public|Internal|Deprecated):\s+/) do
- section = code_object.add_section $2
- code_object.temporary_section = section
-
- $1
- end
- end
- end
-
- add_post_processor
-
- # Public: Parses TomDoc from text
- #
- # text - A String containing TomDoc-format text.
- #
- # Examples
- #
- # RDoc::TomDoc.parse <<-TOMDOC
- # This method does some things
- #
- # Returns nothing.
- # TOMDOC
- # # => #<RDoc::Markup::Document:0xXXX @parts=[...], @file=nil>
- #
- # Returns an RDoc::Markup::Document representing the TomDoc format.
-
- def self.parse text
- parser = new
-
- parser.tokenize text
- doc = RDoc::Markup::Document.new
- parser.parse doc
- doc
- end
-
- # Internal: Extracts the Signature section's method signature
- #
- # comment - An RDoc::Comment that will be parsed and have the signature
- # extracted
- #
- # Returns a String containing the signature and nil if not
-
- def self.signature comment
- return unless comment.tomdoc?
-
- document = comment.parse
-
- signature = nil
- found_heading = false
- found_signature = false
-
- document.parts.delete_if do |part|
- next false if found_signature
-
- found_heading ||=
- RDoc::Markup::Heading === part && part.text == 'Signature'
-
- next false unless found_heading
-
- next true if RDoc::Markup::BlankLine === part
-
- if RDoc::Markup::Verbatim === part then
- signature = part
- found_signature = true
- end
- end
-
- signature and signature.text
- end
-
- # Public: Creates a new TomDoc parser. See also RDoc::Markup::parse
-
- def initialize
- super
-
- @section = nil
- @seen_returns = false
- end
-
- # Internal: Builds a heading from the token stream
- #
- # level - The level of heading to create
- #
- # Returns an RDoc::Markup::Heading
-
- def build_heading level
- heading = super
-
- @section = heading.text
-
- heading
- end
-
- # Internal: Builds a verbatim from the token stream. A verbatim in the
- # Examples section will be marked as in Ruby format.
- #
- # margin - The indentation from the margin for lines that belong to this
- # verbatim section.
- #
- # Returns an RDoc::Markup::Verbatim
-
- def build_verbatim margin
- verbatim = super
-
- verbatim.format = :ruby if @section == 'Examples'
-
- verbatim
- end
-
- # Internal: Builds a paragraph from the token stream
- #
- # margin - Unused
- #
- # Returns an RDoc::Markup::Paragraph.
-
- def build_paragraph margin
- p :paragraph_start => margin if @debug
-
- paragraph = RDoc::Markup::Paragraph.new
-
- until @tokens.empty? do
- type, data, = get
-
- case type
- when :TEXT then
- @section = 'Returns' if data =~ /\AReturns/
-
- paragraph << data
- when :NEWLINE then
- if :TEXT == peek_token[0] then
- paragraph << ' '
- else
- break
- end
- else
- unget
- break
- end
- end
-
- p :paragraph_end => margin if @debug
-
- paragraph
- end
-
- ##
- # Detects a section change to "Returns" and adds a heading
-
- def parse_text parent, indent # :nodoc:
- paragraph = build_paragraph indent
-
- if false == @seen_returns and 'Returns' == @section then
- @seen_returns = true
- parent << RDoc::Markup::Heading.new(3, 'Returns')
- parent << RDoc::Markup::BlankLine.new
- end
-
- parent << paragraph
- end
-
- # Internal: Turns text into an Array of tokens
- #
- # text - A String containing TomDoc-format text.
- #
- # Returns self.
-
- def tokenize text
- text.sub!(/\A(Public|Internal|Deprecated):\s+/, '')
-
- setup_scanner text
-
- until @s.eos? do
- pos = @s.pos
-
- # leading spaces will be reflected by the column of the next token
- # the only thing we loose are trailing spaces at the end of the file
- next if @s.scan(/ +/)
-
- @tokens << case
- when @s.scan(/\r?\n/) then
- token = [:NEWLINE, @s.matched, *token_pos(pos)]
- @line_pos = char_pos @s.pos
- @line += 1
- token
- when @s.scan(/(Examples|Signature)$/) then
- @tokens << [:HEADER, 3, *token_pos(pos)]
-
- [:TEXT, @s[1], *token_pos(pos)]
- when @s.scan(/([:\w][\w\[\]]*)[ ]+- /) then
- [:NOTE, @s[1], *token_pos(pos)]
- else
- @s.scan(/.*/)
- [:TEXT, @s.matched.sub(/\r$/, ''), *token_pos(pos)]
- end
- end
-
- self
- end
-
-end
-
diff --git a/ruby_2_2/lib/rdoc/top_level.rb b/ruby_2_2/lib/rdoc/top_level.rb
deleted file mode 100644
index 64d81d20c1..0000000000
--- a/ruby_2_2/lib/rdoc/top_level.rb
+++ /dev/null
@@ -1,282 +0,0 @@
-##
-# A TopLevel context is a representation of the contents of a single file
-
-class RDoc::TopLevel < RDoc::Context
-
- MARSHAL_VERSION = 0 # :nodoc:
-
- ##
- # This TopLevel's File::Stat struct
-
- attr_accessor :file_stat
-
- ##
- # Relative name of this file
-
- attr_accessor :relative_name
-
- ##
- # Absolute name of this file
-
- attr_accessor :absolute_name
-
- ##
- # All the classes or modules that were declared in
- # this file. These are assigned to either +#classes_hash+
- # or +#modules_hash+ once we know what they really are.
-
- attr_reader :classes_or_modules
-
- attr_accessor :diagram # :nodoc:
-
- ##
- # The parser class that processed this file
-
- attr_accessor :parser
-
- ##
- # Creates a new TopLevel for the file at +absolute_name+. If documentation
- # is being generated outside the source dir +relative_name+ is relative to
- # the source directory.
-
- def initialize absolute_name, relative_name = absolute_name
- super()
- @name = nil
- @absolute_name = absolute_name
- @relative_name = relative_name
- @file_stat = File.stat(absolute_name) rescue nil # HACK for testing
- @diagram = nil
- @parser = nil
-
- @classes_or_modules = []
- end
-
- ##
- # An RDoc::TopLevel is equal to another with the same relative_name
-
- def == other
- self.class === other and @relative_name == other.relative_name
- end
-
- alias eql? ==
-
- ##
- # Adds +an_alias+ to +Object+ instead of +self+.
-
- def add_alias(an_alias)
- object_class.record_location self
- return an_alias unless @document_self
- object_class.add_alias an_alias
- end
-
- ##
- # Adds +constant+ to +Object+ instead of +self+.
-
- def add_constant constant
- object_class.record_location self
- return constant unless @document_self
- object_class.add_constant constant
- end
-
- ##
- # Adds +include+ to +Object+ instead of +self+.
-
- def add_include(include)
- object_class.record_location self
- return include unless @document_self
- object_class.add_include include
- end
-
- ##
- # Adds +method+ to +Object+ instead of +self+.
-
- def add_method(method)
- object_class.record_location self
- return method unless @document_self
- object_class.add_method method
- end
-
- ##
- # Adds class or module +mod+. Used in the building phase
- # by the Ruby parser.
-
- def add_to_classes_or_modules mod
- @classes_or_modules << mod
- end
-
- ##
- # Base name of this file
-
- def base_name
- File.basename @relative_name
- end
-
- alias name base_name
-
- ##
- # Only a TopLevel that contains text file) will be displayed. See also
- # RDoc::CodeObject#display?
-
- def display?
- text? and super
- end
-
- ##
- # See RDoc::TopLevel::find_class_or_module
- #--
- # TODO Why do we search through all classes/modules found, not just the
- # ones of this instance?
-
- def find_class_or_module name
- @store.find_class_or_module name
- end
-
- ##
- # Finds a class or module named +symbol+
-
- def find_local_symbol(symbol)
- find_class_or_module(symbol) || super
- end
-
- ##
- # Finds a module or class with +name+
-
- def find_module_named(name)
- find_class_or_module(name)
- end
-
- ##
- # Returns the relative name of this file
-
- def full_name
- @relative_name
- end
-
- ##
- # An RDoc::TopLevel has the same hash as another with the same
- # relative_name
-
- def hash
- @relative_name.hash
- end
-
- ##
- # URL for this with a +prefix+
-
- def http_url(prefix)
- path = [prefix, @relative_name.tr('.', '_')]
-
- File.join(*path.compact) + '.html'
- end
-
- def inspect # :nodoc:
- "#<%s:0x%x %p modules: %p classes: %p>" % [
- self.class, object_id,
- base_name,
- @modules.map { |n,m| m },
- @classes.map { |n,c| c }
- ]
- end
-
- ##
- # Time this file was last modified, if known
-
- def last_modified
- @file_stat ? file_stat.mtime : nil
- end
-
- ##
- # Dumps this TopLevel for use by ri. See also #marshal_load
-
- def marshal_dump
- [
- MARSHAL_VERSION,
- @relative_name,
- @parser,
- parse(@comment),
- ]
- end
-
- ##
- # Loads this TopLevel from +array+.
-
- def marshal_load array # :nodoc:
- initialize array[1]
-
- @parser = array[2]
- @comment = array[3]
-
- @file_stat = nil
- end
-
- ##
- # Returns the NormalClass "Object", creating it if not found.
- #
- # Records +self+ as a location in "Object".
-
- def object_class
- @object_class ||= begin
- oc = @store.find_class_named('Object') || add_class(RDoc::NormalClass, 'Object')
- oc.record_location self
- oc
- end
- end
-
- ##
- # Base name of this file without the extension
-
- def page_name
- basename = File.basename @relative_name
- basename =~ /\.(rb|rdoc|txt|md)$/i
-
- $` || basename
- end
-
- ##
- # Path to this file for use with HTML generator output.
-
- def path
- http_url @store.rdoc.generator.file_dir
- end
-
- def pretty_print q # :nodoc:
- q.group 2, "[#{self.class}: ", "]" do
- q.text "base name: #{base_name.inspect}"
- q.breakable
-
- items = @modules.map { |n,m| m }
- items.concat @modules.map { |n,c| c }
- q.seplist items do |mod| q.pp mod end
- end
- end
-
- ##
- # Search record used by RDoc::Generator::JsonIndex
-
- def search_record
- return unless @parser < RDoc::Parser::Text
-
- [
- page_name,
- '',
- page_name,
- '',
- path,
- '',
- snippet(@comment),
- ]
- end
-
- ##
- # Is this TopLevel from a text file instead of a source code file?
-
- def text?
- @parser and @parser.ancestors.include? RDoc::Parser::Text
- end
-
- def to_s # :nodoc:
- "file #{full_name}"
- end
-
-end
-
diff --git a/ruby_2_2/lib/resolv-replace.rb b/ruby_2_2/lib/resolv-replace.rb
deleted file mode 100644
index 3e28a843fd..0000000000
--- a/ruby_2_2/lib/resolv-replace.rb
+++ /dev/null
@@ -1,74 +0,0 @@
-require 'socket'
-require 'resolv'
-
-class << IPSocket
- # :stopdoc:
- alias original_resolv_getaddress getaddress
- # :startdoc:
- def getaddress(host)
- begin
- return Resolv.getaddress(host).to_s
- rescue Resolv::ResolvError
- raise SocketError, "Hostname not known: #{host}"
- end
- end
-end
-
-class TCPSocket < IPSocket
- # :stopdoc:
- alias original_resolv_initialize initialize
- # :startdoc:
- def initialize(host, serv, *rest)
- rest[0] = IPSocket.getaddress(rest[0]) if rest[0]
- original_resolv_initialize(IPSocket.getaddress(host), serv, *rest)
- end
-end
-
-class UDPSocket < IPSocket
- # :stopdoc:
- alias original_resolv_bind bind
- # :startdoc:
- def bind(host, port)
- host = IPSocket.getaddress(host) if host != ""
- original_resolv_bind(host, port)
- end
-
- # :stopdoc:
- alias original_resolv_connect connect
- # :startdoc:
- def connect(host, port)
- original_resolv_connect(IPSocket.getaddress(host), port)
- end
-
- # :stopdoc:
- alias original_resolv_send send
- # :startdoc:
- def send(mesg, flags, *rest)
- if rest.length == 2
- host, port = rest
- begin
- addrs = Resolv.getaddresses(host)
- rescue Resolv::ResolvError
- raise SocketError, "Hostname not known: #{host}"
- end
- addrs[0...-1].each {|addr|
- begin
- return original_resolv_send(mesg, flags, addr, port)
- rescue SystemCallError
- end
- }
- original_resolv_send(mesg, flags, addrs[-1], port)
- else
- original_resolv_send(mesg, flags, *rest)
- end
- end
-end
-
-class SOCKSSocket < TCPSocket
- # :stopdoc:
- alias original_resolv_initialize initialize
- # :startdoc:
- def initialize(host, serv)
- original_resolv_initialize(IPSocket.getaddress(host), port)
- end
-end if defined? SOCKSSocket
diff --git a/ruby_2_2/lib/resolv.rb b/ruby_2_2/lib/resolv.rb
deleted file mode 100644
index dee6afd1f5..0000000000
--- a/ruby_2_2/lib/resolv.rb
+++ /dev/null
@@ -1,2844 +0,0 @@
-require 'socket'
-require 'timeout'
-require 'thread'
-
-begin
- require 'securerandom'
-rescue LoadError
-end
-
-# Resolv is a thread-aware DNS resolver library written in Ruby. Resolv can
-# handle multiple DNS requests concurrently without blocking the entire Ruby
-# interpreter.
-#
-# See also resolv-replace.rb to replace the libc resolver with Resolv.
-#
-# Resolv can look up various DNS resources using the DNS module directly.
-#
-# Examples:
-#
-# p Resolv.getaddress "www.ruby-lang.org"
-# p Resolv.getname "210.251.121.214"
-#
-# Resolv::DNS.open do |dns|
-# ress = dns.getresources "www.ruby-lang.org", Resolv::DNS::Resource::IN::A
-# p ress.map { |r| r.address }
-# ress = dns.getresources "ruby-lang.org", Resolv::DNS::Resource::IN::MX
-# p ress.map { |r| [r.exchange.to_s, r.preference] }
-# end
-#
-#
-# == Bugs
-#
-# * NIS is not supported.
-# * /etc/nsswitch.conf is not supported.
-
-class Resolv
-
- ##
- # Looks up the first IP address for +name+.
-
- def self.getaddress(name)
- DefaultResolver.getaddress(name)
- end
-
- ##
- # Looks up all IP address for +name+.
-
- def self.getaddresses(name)
- DefaultResolver.getaddresses(name)
- end
-
- ##
- # Iterates over all IP addresses for +name+.
-
- def self.each_address(name, &block)
- DefaultResolver.each_address(name, &block)
- end
-
- ##
- # Looks up the hostname of +address+.
-
- def self.getname(address)
- DefaultResolver.getname(address)
- end
-
- ##
- # Looks up all hostnames for +address+.
-
- def self.getnames(address)
- DefaultResolver.getnames(address)
- end
-
- ##
- # Iterates over all hostnames for +address+.
-
- def self.each_name(address, &proc)
- DefaultResolver.each_name(address, &proc)
- end
-
- ##
- # Creates a new Resolv using +resolvers+.
-
- def initialize(resolvers=[Hosts.new, DNS.new])
- @resolvers = resolvers
- end
-
- ##
- # Looks up the first IP address for +name+.
-
- def getaddress(name)
- each_address(name) {|address| return address}
- raise ResolvError.new("no address for #{name}")
- end
-
- ##
- # Looks up all IP address for +name+.
-
- def getaddresses(name)
- ret = []
- each_address(name) {|address| ret << address}
- return ret
- end
-
- ##
- # Iterates over all IP addresses for +name+.
-
- def each_address(name)
- if AddressRegex =~ name
- yield name
- return
- end
- yielded = false
- @resolvers.each {|r|
- r.each_address(name) {|address|
- yield address.to_s
- yielded = true
- }
- return if yielded
- }
- end
-
- ##
- # Looks up the hostname of +address+.
-
- def getname(address)
- each_name(address) {|name| return name}
- raise ResolvError.new("no name for #{address}")
- end
-
- ##
- # Looks up all hostnames for +address+.
-
- def getnames(address)
- ret = []
- each_name(address) {|name| ret << name}
- return ret
- end
-
- ##
- # Iterates over all hostnames for +address+.
-
- def each_name(address)
- yielded = false
- @resolvers.each {|r|
- r.each_name(address) {|name|
- yield name.to_s
- yielded = true
- }
- return if yielded
- }
- end
-
- ##
- # Indicates a failure to resolve a name or address.
-
- class ResolvError < StandardError; end
-
- ##
- # Indicates a timeout resolving a name or address.
-
- class ResolvTimeout < Timeout::Error; end
-
- ##
- # Resolv::Hosts is a hostname resolver that uses the system hosts file.
-
- class Hosts
- begin
- raise LoadError unless /mswin|mingw|cygwin/ =~ RUBY_PLATFORM
- require 'win32/resolv'
- DefaultFileName = Win32::Resolv.get_hosts_path
- rescue LoadError
- DefaultFileName = '/etc/hosts'
- end
-
- ##
- # Creates a new Resolv::Hosts, using +filename+ for its data source.
-
- def initialize(filename = DefaultFileName)
- @filename = filename
- @mutex = Mutex.new
- @initialized = nil
- end
-
- def lazy_initialize # :nodoc:
- @mutex.synchronize {
- unless @initialized
- @name2addr = {}
- @addr2name = {}
- open(@filename, 'rb') {|f|
- f.each {|line|
- line.sub!(/#.*/, '')
- addr, hostname, *aliases = line.split(/\s+/)
- next unless addr
- addr.untaint
- hostname.untaint
- @addr2name[addr] = [] unless @addr2name.include? addr
- @addr2name[addr] << hostname
- @addr2name[addr] += aliases
- @name2addr[hostname] = [] unless @name2addr.include? hostname
- @name2addr[hostname] << addr
- aliases.each {|n|
- n.untaint
- @name2addr[n] = [] unless @name2addr.include? n
- @name2addr[n] << addr
- }
- }
- }
- @name2addr.each {|name, arr| arr.reverse!}
- @initialized = true
- end
- }
- self
- end
-
- ##
- # Gets the IP address of +name+ from the hosts file.
-
- def getaddress(name)
- each_address(name) {|address| return address}
- raise ResolvError.new("#{@filename} has no name: #{name}")
- end
-
- ##
- # Gets all IP addresses for +name+ from the hosts file.
-
- def getaddresses(name)
- ret = []
- each_address(name) {|address| ret << address}
- return ret
- end
-
- ##
- # Iterates over all IP addresses for +name+ retrieved from the hosts file.
-
- def each_address(name, &proc)
- lazy_initialize
- if @name2addr.include?(name)
- @name2addr[name].each(&proc)
- end
- end
-
- ##
- # Gets the hostname of +address+ from the hosts file.
-
- def getname(address)
- each_name(address) {|name| return name}
- raise ResolvError.new("#{@filename} has no address: #{address}")
- end
-
- ##
- # Gets all hostnames for +address+ from the hosts file.
-
- def getnames(address)
- ret = []
- each_name(address) {|name| ret << name}
- return ret
- end
-
- ##
- # Iterates over all hostnames for +address+ retrieved from the hosts file.
-
- def each_name(address, &proc)
- lazy_initialize
- if @addr2name.include?(address)
- @addr2name[address].each(&proc)
- end
- end
- end
-
- ##
- # Resolv::DNS is a DNS stub resolver.
- #
- # Information taken from the following places:
- #
- # * STD0013
- # * RFC 1035
- # * ftp://ftp.isi.edu/in-notes/iana/assignments/dns-parameters
- # * etc.
-
- class DNS
-
- ##
- # Default DNS Port
-
- Port = 53
-
- ##
- # Default DNS UDP packet size
-
- UDPSize = 512
-
- ##
- # Creates a new DNS resolver. See Resolv::DNS.new for argument details.
- #
- # Yields the created DNS resolver to the block, if given, otherwise
- # returns it.
-
- def self.open(*args)
- dns = new(*args)
- return dns unless block_given?
- begin
- yield dns
- ensure
- dns.close
- end
- end
-
- ##
- # Creates a new DNS resolver.
- #
- # +config_info+ can be:
- #
- # nil:: Uses /etc/resolv.conf.
- # String:: Path to a file using /etc/resolv.conf's format.
- # Hash:: Must contain :nameserver, :search and :ndots keys.
- # :nameserver_port can be used to specify port number of nameserver address.
- #
- # The value of :nameserver should be an address string or
- # an array of address strings.
- # - :nameserver => '8.8.8.8'
- # - :nameserver => ['8.8.8.8', '8.8.4.4']
- #
- # The value of :nameserver_port should be an array of
- # pair of nameserver address and port number.
- # - :nameserver_port => [['8.8.8.8', 53], ['8.8.4.4', 53]]
- #
- # Example:
- #
- # Resolv::DNS.new(:nameserver => ['210.251.121.21'],
- # :search => ['ruby-lang.org'],
- # :ndots => 1)
-
- def initialize(config_info=nil)
- @mutex = Mutex.new
- @config = Config.new(config_info)
- @initialized = nil
- end
-
- # Sets the resolver timeouts. This may be a single positive number
- # or an array of positive numbers representing timeouts in seconds.
- # If an array is specified, a DNS request will retry and wait for
- # each successive interval in the array until a successful response
- # is received. Specifying +nil+ reverts to the default timeouts:
- # [ 5, second = 5 * 2 / nameserver_count, 2 * second, 4 * second ]
- #
- # Example:
- #
- # dns.timeouts = 3
- #
- def timeouts=(values)
- @config.timeouts = values
- end
-
- def lazy_initialize # :nodoc:
- @mutex.synchronize {
- unless @initialized
- @config.lazy_initialize
- @initialized = true
- end
- }
- self
- end
-
- ##
- # Closes the DNS resolver.
-
- def close
- @mutex.synchronize {
- if @initialized
- @initialized = false
- end
- }
- end
-
- ##
- # Gets the IP address of +name+ from the DNS resolver.
- #
- # +name+ can be a Resolv::DNS::Name or a String. Retrieved address will
- # be a Resolv::IPv4 or Resolv::IPv6
-
- def getaddress(name)
- each_address(name) {|address| return address}
- raise ResolvError.new("DNS result has no information for #{name}")
- end
-
- ##
- # Gets all IP addresses for +name+ from the DNS resolver.
- #
- # +name+ can be a Resolv::DNS::Name or a String. Retrieved addresses will
- # be a Resolv::IPv4 or Resolv::IPv6
-
- def getaddresses(name)
- ret = []
- each_address(name) {|address| ret << address}
- return ret
- end
-
- ##
- # Iterates over all IP addresses for +name+ retrieved from the DNS
- # resolver.
- #
- # +name+ can be a Resolv::DNS::Name or a String. Retrieved addresses will
- # be a Resolv::IPv4 or Resolv::IPv6
-
- def each_address(name)
- each_resource(name, Resource::IN::A) {|resource| yield resource.address}
- if use_ipv6?
- each_resource(name, Resource::IN::AAAA) {|resource| yield resource.address}
- end
- end
-
- def use_ipv6? # :nodoc:
- begin
- list = Socket.ip_address_list
- rescue NotImplementedError
- return true
- end
- list.any? {|a| a.ipv6? && !a.ipv6_loopback? && !a.ipv6_linklocal? }
- end
- private :use_ipv6?
-
- ##
- # Gets the hostname for +address+ from the DNS resolver.
- #
- # +address+ must be a Resolv::IPv4, Resolv::IPv6 or a String. Retrieved
- # name will be a Resolv::DNS::Name.
-
- def getname(address)
- each_name(address) {|name| return name}
- raise ResolvError.new("DNS result has no information for #{address}")
- end
-
- ##
- # Gets all hostnames for +address+ from the DNS resolver.
- #
- # +address+ must be a Resolv::IPv4, Resolv::IPv6 or a String. Retrieved
- # names will be Resolv::DNS::Name instances.
-
- def getnames(address)
- ret = []
- each_name(address) {|name| ret << name}
- return ret
- end
-
- ##
- # Iterates over all hostnames for +address+ retrieved from the DNS
- # resolver.
- #
- # +address+ must be a Resolv::IPv4, Resolv::IPv6 or a String. Retrieved
- # names will be Resolv::DNS::Name instances.
-
- def each_name(address)
- case address
- when Name
- ptr = address
- when IPv4::Regex
- ptr = IPv4.create(address).to_name
- when IPv6::Regex
- ptr = IPv6.create(address).to_name
- else
- raise ResolvError.new("cannot interpret as address: #{address}")
- end
- each_resource(ptr, Resource::IN::PTR) {|resource| yield resource.name}
- end
-
- ##
- # Look up the +typeclass+ DNS resource of +name+.
- #
- # +name+ must be a Resolv::DNS::Name or a String.
- #
- # +typeclass+ should be one of the following:
- #
- # * Resolv::DNS::Resource::IN::A
- # * Resolv::DNS::Resource::IN::AAAA
- # * Resolv::DNS::Resource::IN::ANY
- # * Resolv::DNS::Resource::IN::CNAME
- # * Resolv::DNS::Resource::IN::HINFO
- # * Resolv::DNS::Resource::IN::MINFO
- # * Resolv::DNS::Resource::IN::MX
- # * Resolv::DNS::Resource::IN::NS
- # * Resolv::DNS::Resource::IN::PTR
- # * Resolv::DNS::Resource::IN::SOA
- # * Resolv::DNS::Resource::IN::TXT
- # * Resolv::DNS::Resource::IN::WKS
- #
- # Returned resource is represented as a Resolv::DNS::Resource instance,
- # i.e. Resolv::DNS::Resource::IN::A.
-
- def getresource(name, typeclass)
- each_resource(name, typeclass) {|resource| return resource}
- raise ResolvError.new("DNS result has no information for #{name}")
- end
-
- ##
- # Looks up all +typeclass+ DNS resources for +name+. See #getresource for
- # argument details.
-
- def getresources(name, typeclass)
- ret = []
- each_resource(name, typeclass) {|resource| ret << resource}
- return ret
- end
-
- ##
- # Iterates over all +typeclass+ DNS resources for +name+. See
- # #getresource for argument details.
-
- def each_resource(name, typeclass, &proc)
- fetch_resource(name, typeclass) {|reply, reply_name|
- extract_resources(reply, reply_name, typeclass, &proc)
- }
- end
-
- def fetch_resource(name, typeclass)
- lazy_initialize
- requester = make_udp_requester
- senders = {}
- begin
- @config.resolv(name) {|candidate, tout, nameserver, port|
- msg = Message.new
- msg.rd = 1
- msg.add_question(candidate, typeclass)
- unless sender = senders[[candidate, nameserver, port]]
- sender = requester.sender(msg, candidate, nameserver, port)
- next if !sender
- senders[[candidate, nameserver, port]] = sender
- end
- reply, reply_name = requester.request(sender, tout)
- case reply.rcode
- when RCode::NoError
- if reply.tc == 1 and not Requester::TCP === requester
- requester.close
- # Retry via TCP:
- requester = make_tcp_requester(nameserver, port)
- senders = {}
- # This will use TCP for all remaining candidates (assuming the
- # current candidate does not already respond successfully via
- # TCP). This makes sense because we already know the full
- # response will not fit in an untruncated UDP packet.
- redo
- else
- yield(reply, reply_name)
- end
- return
- when RCode::NXDomain
- raise Config::NXDomain.new(reply_name.to_s)
- else
- raise Config::OtherResolvError.new(reply_name.to_s)
- end
- }
- ensure
- requester.close
- end
- end
-
- def make_udp_requester # :nodoc:
- nameserver_port = @config.nameserver_port
- if nameserver_port.length == 1
- Requester::ConnectedUDP.new(*nameserver_port[0])
- else
- Requester::UnconnectedUDP.new(*nameserver_port)
- end
- end
-
- def make_tcp_requester(host, port) # :nodoc:
- return Requester::TCP.new(host, port)
- end
-
- def extract_resources(msg, name, typeclass) # :nodoc:
- if typeclass < Resource::ANY
- n0 = Name.create(name)
- msg.each_answer {|n, ttl, data|
- yield data if n0 == n
- }
- end
- yielded = false
- n0 = Name.create(name)
- msg.each_answer {|n, ttl, data|
- if n0 == n
- case data
- when typeclass
- yield data
- yielded = true
- when Resource::CNAME
- n0 = data.name
- end
- end
- }
- return if yielded
- msg.each_answer {|n, ttl, data|
- if n0 == n
- case data
- when typeclass
- yield data
- end
- end
- }
- end
-
- if defined? SecureRandom
- def self.random(arg) # :nodoc:
- begin
- SecureRandom.random_number(arg)
- rescue NotImplementedError
- rand(arg)
- end
- end
- else
- def self.random(arg) # :nodoc:
- rand(arg)
- end
- end
-
-
- def self.rangerand(range) # :nodoc:
- base = range.begin
- len = range.end - range.begin
- if !range.exclude_end?
- len += 1
- end
- base + random(len)
- end
-
- RequestID = {} # :nodoc:
- RequestIDMutex = Mutex.new # :nodoc:
-
- def self.allocate_request_id(host, port) # :nodoc:
- id = nil
- RequestIDMutex.synchronize {
- h = (RequestID[[host, port]] ||= {})
- begin
- id = rangerand(0x0000..0xffff)
- end while h[id]
- h[id] = true
- }
- id
- end
-
- def self.free_request_id(host, port, id) # :nodoc:
- RequestIDMutex.synchronize {
- key = [host, port]
- if h = RequestID[key]
- h.delete id
- if h.empty?
- RequestID.delete key
- end
- end
- }
- end
-
- def self.bind_random_port(udpsock, bind_host="0.0.0.0") # :nodoc:
- begin
- port = rangerand(1024..65535)
- udpsock.bind(bind_host, port)
- rescue Errno::EADDRINUSE, # POSIX
- Errno::EACCES, # SunOS: See PRIV_SYS_NFS in privileges(5)
- Errno::EPERM # FreeBSD: security.mac.portacl.port_high is configurable. See mac_portacl(4).
- retry
- end
- end
-
- class Requester # :nodoc:
- def initialize
- @senders = {}
- @socks = nil
- end
-
- def request(sender, tout)
- start = Time.now
- timelimit = start + tout
- begin
- sender.send
- rescue Errno::EHOSTUNREACH, # multi-homed IPv6 may generate this
- Errno::ENETUNREACH
- raise ResolvTimeout
- end
- while true
- before_select = Time.now
- timeout = timelimit - before_select
- if timeout <= 0
- raise ResolvTimeout
- end
- select_result = IO.select(@socks, nil, nil, timeout)
- if !select_result
- after_select = Time.now
- next if after_select < timelimit
- raise ResolvTimeout
- end
- begin
- reply, from = recv_reply(select_result[0])
- rescue Errno::ECONNREFUSED, # GNU/Linux, FreeBSD
- Errno::ECONNRESET # Windows
- # No name server running on the server?
- # Don't wait anymore.
- raise ResolvTimeout
- end
- begin
- msg = Message.decode(reply)
- rescue DecodeError
- next # broken DNS message ignored
- end
- if s = sender_for(from, msg)
- break
- else
- # unexpected DNS message ignored
- end
- end
- return msg, s.data
- end
-
- def sender_for(addr, msg)
- @senders[[addr,msg.id]]
- end
-
- def close
- socks = @socks
- @socks = nil
- if socks
- socks.each {|sock| sock.close }
- end
- end
-
- class Sender # :nodoc:
- def initialize(msg, data, sock)
- @msg = msg
- @data = data
- @sock = sock
- end
- end
-
- class UnconnectedUDP < Requester # :nodoc:
- def initialize(*nameserver_port)
- super()
- @nameserver_port = nameserver_port
- @socks_hash = {}
- @socks = []
- nameserver_port.each {|host, port|
- if host.index(':')
- bind_host = "::"
- af = Socket::AF_INET6
- else
- bind_host = "0.0.0.0"
- af = Socket::AF_INET
- end
- next if @socks_hash[bind_host]
- begin
- sock = UDPSocket.new(af)
- rescue Errno::EAFNOSUPPORT
- next # The kernel doesn't support the address family.
- end
- sock.do_not_reverse_lookup = true
- DNS.bind_random_port(sock, bind_host)
- @socks << sock
- @socks_hash[bind_host] = sock
- }
- end
-
- def recv_reply(readable_socks)
- reply, from = readable_socks[0].recvfrom(UDPSize)
- return reply, [from[3],from[1]]
- end
-
- def sender(msg, data, host, port=Port)
- sock = @socks_hash[host.index(':') ? "::" : "0.0.0.0"]
- return nil if !sock
- service = [host, port]
- id = DNS.allocate_request_id(host, port)
- request = msg.encode
- request[0,2] = [id].pack('n')
- return @senders[[service, id]] =
- Sender.new(request, data, sock, host, port)
- end
-
- def close
- super
- @senders.each_key {|service, id|
- DNS.free_request_id(service[0], service[1], id)
- }
- end
-
- class Sender < Requester::Sender # :nodoc:
- def initialize(msg, data, sock, host, port)
- super(msg, data, sock)
- @host = host
- @port = port
- end
- attr_reader :data
-
- def send
- raise "@sock is nil." if @sock.nil?
- @sock.send(@msg, 0, @host, @port)
- end
- end
- end
-
- class ConnectedUDP < Requester # :nodoc:
- def initialize(host, port=Port)
- super()
- @host = host
- @port = port
- is_ipv6 = host.index(':')
- sock = UDPSocket.new(is_ipv6 ? Socket::AF_INET6 : Socket::AF_INET)
- @socks = [sock]
- sock.do_not_reverse_lookup = true
- DNS.bind_random_port(sock, is_ipv6 ? "::" : "0.0.0.0")
- sock.connect(host, port)
- end
-
- def recv_reply(readable_socks)
- reply = readable_socks[0].recv(UDPSize)
- return reply, nil
- end
-
- def sender(msg, data, host=@host, port=@port)
- unless host == @host && port == @port
- raise RequestError.new("host/port don't match: #{host}:#{port}")
- end
- id = DNS.allocate_request_id(@host, @port)
- request = msg.encode
- request[0,2] = [id].pack('n')
- return @senders[[nil,id]] = Sender.new(request, data, @socks[0])
- end
-
- def close
- super
- @senders.each_key {|from, id|
- DNS.free_request_id(@host, @port, id)
- }
- end
-
- class Sender < Requester::Sender # :nodoc:
- def send
- raise "@sock is nil." if @sock.nil?
- @sock.send(@msg, 0)
- end
- attr_reader :data
- end
- end
-
- class MDNSOneShot < UnconnectedUDP # :nodoc:
- def sender(msg, data, host, port=Port)
- id = DNS.allocate_request_id(host, port)
- request = msg.encode
- request[0,2] = [id].pack('n')
- sock = @socks_hash[host.index(':') ? "::" : "0.0.0.0"]
- return @senders[id] =
- UnconnectedUDP::Sender.new(request, data, sock, host, port)
- end
-
- def sender_for(addr, msg)
- @senders[msg.id]
- end
- end
-
- class TCP < Requester # :nodoc:
- def initialize(host, port=Port)
- super()
- @host = host
- @port = port
- sock = TCPSocket.new(@host, @port)
- @socks = [sock]
- @senders = {}
- end
-
- def recv_reply(readable_socks)
- len = readable_socks[0].read(2).unpack('n')[0]
- reply = @socks[0].read(len)
- return reply, nil
- end
-
- def sender(msg, data, host=@host, port=@port)
- unless host == @host && port == @port
- raise RequestError.new("host/port don't match: #{host}:#{port}")
- end
- id = DNS.allocate_request_id(@host, @port)
- request = msg.encode
- request[0,2] = [request.length, id].pack('nn')
- return @senders[[nil,id]] = Sender.new(request, data, @socks[0])
- end
-
- class Sender < Requester::Sender # :nodoc:
- def send
- @sock.print(@msg)
- @sock.flush
- end
- attr_reader :data
- end
-
- def close
- super
- @senders.each_key {|from,id|
- DNS.free_request_id(@host, @port, id)
- }
- end
- end
-
- ##
- # Indicates a problem with the DNS request.
-
- class RequestError < StandardError
- end
- end
-
- class Config # :nodoc:
- def initialize(config_info=nil)
- @mutex = Mutex.new
- @config_info = config_info
- @initialized = nil
- @timeouts = nil
- end
-
- def timeouts=(values)
- if values
- values = Array(values)
- values.each do |t|
- Numeric === t or raise ArgumentError, "#{t.inspect} is not numeric"
- t > 0.0 or raise ArgumentError, "timeout=#{t} must be positive"
- end
- @timeouts = values
- else
- @timeouts = nil
- end
- end
-
- def Config.parse_resolv_conf(filename)
- nameserver = []
- search = nil
- ndots = 1
- open(filename, 'rb') {|f|
- f.each {|line|
- line.sub!(/[#;].*/, '')
- keyword, *args = line.split(/\s+/)
- args.each { |arg|
- arg.untaint
- }
- next unless keyword
- case keyword
- when 'nameserver'
- nameserver += args
- when 'domain'
- next if args.empty?
- search = [args[0]]
- when 'search'
- next if args.empty?
- search = args
- when 'options'
- args.each {|arg|
- case arg
- when /\Andots:(\d+)\z/
- ndots = $1.to_i
- end
- }
- end
- }
- }
- return { :nameserver => nameserver, :search => search, :ndots => ndots }
- end
-
- def Config.default_config_hash(filename="/etc/resolv.conf")
- if File.exist? filename
- config_hash = Config.parse_resolv_conf(filename)
- else
- if /mswin|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM
- require 'win32/resolv'
- search, nameserver = Win32::Resolv.get_resolv_info
- config_hash = {}
- config_hash[:nameserver] = nameserver if nameserver
- config_hash[:search] = [search].flatten if search
- end
- end
- config_hash || {}
- end
-
- def lazy_initialize
- @mutex.synchronize {
- unless @initialized
- @nameserver_port = []
- @search = nil
- @ndots = 1
- case @config_info
- when nil
- config_hash = Config.default_config_hash
- when String
- config_hash = Config.parse_resolv_conf(@config_info)
- when Hash
- config_hash = @config_info.dup
- if String === config_hash[:nameserver]
- config_hash[:nameserver] = [config_hash[:nameserver]]
- end
- if String === config_hash[:search]
- config_hash[:search] = [config_hash[:search]]
- end
- else
- raise ArgumentError.new("invalid resolv configuration: #{@config_info.inspect}")
- end
- if config_hash.include? :nameserver
- @nameserver_port = config_hash[:nameserver].map {|ns| [ns, Port] }
- end
- if config_hash.include? :nameserver_port
- @nameserver_port = config_hash[:nameserver_port].map {|ns, port| [ns, (port || Port)] }
- end
- @search = config_hash[:search] if config_hash.include? :search
- @ndots = config_hash[:ndots] if config_hash.include? :ndots
-
- if @nameserver_port.empty?
- @nameserver_port << ['0.0.0.0', Port]
- end
- if @search
- @search = @search.map {|arg| Label.split(arg) }
- else
- hostname = Socket.gethostname
- if /\./ =~ hostname
- @search = [Label.split($')]
- else
- @search = [[]]
- end
- end
-
- if !@nameserver_port.kind_of?(Array) ||
- @nameserver_port.any? {|ns_port|
- !(Array === ns_port) ||
- ns_port.length != 2
- !(String === ns_port[0]) ||
- !(Integer === ns_port[1])
- }
- raise ArgumentError.new("invalid nameserver config: #{@nameserver_port.inspect}")
- end
-
- if !@search.kind_of?(Array) ||
- !@search.all? {|ls| ls.all? {|l| Label::Str === l } }
- raise ArgumentError.new("invalid search config: #{@search.inspect}")
- end
-
- if !@ndots.kind_of?(Integer)
- raise ArgumentError.new("invalid ndots config: #{@ndots.inspect}")
- end
-
- @initialized = true
- end
- }
- self
- end
-
- def single?
- lazy_initialize
- if @nameserver_port.length == 1
- return @nameserver_port[0]
- else
- return nil
- end
- end
-
- def nameserver_port
- @nameserver_port
- end
-
- def generate_candidates(name)
- candidates = nil
- name = Name.create(name)
- if name.absolute?
- candidates = [name]
- else
- if @ndots <= name.length - 1
- candidates = [Name.new(name.to_a)]
- else
- candidates = []
- end
- candidates.concat(@search.map {|domain| Name.new(name.to_a + domain)})
- fname = Name.create("#{name}.")
- if !candidates.include?(fname)
- candidates << fname
- end
- end
- return candidates
- end
-
- InitialTimeout = 5
-
- def generate_timeouts
- ts = [InitialTimeout]
- ts << ts[-1] * 2 / @nameserver_port.length
- ts << ts[-1] * 2
- ts << ts[-1] * 2
- return ts
- end
-
- def resolv(name)
- candidates = generate_candidates(name)
- timeouts = @timeouts || generate_timeouts
- begin
- candidates.each {|candidate|
- begin
- timeouts.each {|tout|
- @nameserver_port.each {|nameserver, port|
- begin
- yield candidate, tout, nameserver, port
- rescue ResolvTimeout
- end
- }
- }
- raise ResolvError.new("DNS resolv timeout: #{name}")
- rescue NXDomain
- end
- }
- rescue ResolvError
- end
- end
-
- ##
- # Indicates no such domain was found.
-
- class NXDomain < ResolvError
- end
-
- ##
- # Indicates some other unhandled resolver error was encountered.
-
- class OtherResolvError < ResolvError
- end
- end
-
- module OpCode # :nodoc:
- Query = 0
- IQuery = 1
- Status = 2
- Notify = 4
- Update = 5
- end
-
- module RCode # :nodoc:
- NoError = 0
- FormErr = 1
- ServFail = 2
- NXDomain = 3
- NotImp = 4
- Refused = 5
- YXDomain = 6
- YXRRSet = 7
- NXRRSet = 8
- NotAuth = 9
- NotZone = 10
- BADVERS = 16
- BADSIG = 16
- BADKEY = 17
- BADTIME = 18
- BADMODE = 19
- BADNAME = 20
- BADALG = 21
- end
-
- ##
- # Indicates that the DNS response was unable to be decoded.
-
- class DecodeError < StandardError
- end
-
- ##
- # Indicates that the DNS request was unable to be encoded.
-
- class EncodeError < StandardError
- end
-
- module Label # :nodoc:
- def self.split(arg)
- labels = []
- arg.scan(/[^\.]+/) {labels << Str.new($&)}
- return labels
- end
-
- class Str # :nodoc:
- def initialize(string)
- @string = string
- @downcase = string.downcase
- end
- attr_reader :string, :downcase
-
- def to_s
- return @string
- end
-
- def inspect
- return "#<#{self.class} #{self}>"
- end
-
- def ==(other)
- return self.class == other.class && @downcase == other.downcase
- end
-
- def eql?(other)
- return self == other
- end
-
- def hash
- return @downcase.hash
- end
- end
- end
-
- ##
- # A representation of a DNS name.
-
- class Name
-
- ##
- # Creates a new DNS name from +arg+. +arg+ can be:
- #
- # Name:: returns +arg+.
- # String:: Creates a new Name.
-
- def self.create(arg)
- case arg
- when Name
- return arg
- when String
- return Name.new(Label.split(arg), /\.\z/ =~ arg ? true : false)
- else
- raise ArgumentError.new("cannot interpret as DNS name: #{arg.inspect}")
- end
- end
-
- def initialize(labels, absolute=true) # :nodoc:
- labels = labels.map {|label|
- case label
- when String then Label::Str.new(label)
- when Label::Str then label
- else
- raise ArgumentError, "unexpected label: #{label.inspect}"
- end
- }
- @labels = labels
- @absolute = absolute
- end
-
- def inspect # :nodoc:
- "#<#{self.class}: #{self}#{@absolute ? '.' : ''}>"
- end
-
- ##
- # True if this name is absolute.
-
- def absolute?
- return @absolute
- end
-
- def ==(other) # :nodoc:
- return false unless Name === other
- return false unless @absolute == other.absolute?
- return @labels == other.to_a
- end
-
- alias eql? == # :nodoc:
-
- ##
- # Returns true if +other+ is a subdomain.
- #
- # Example:
- #
- # domain = Resolv::DNS::Name.create("y.z")
- # p Resolv::DNS::Name.create("w.x.y.z").subdomain_of?(domain) #=> true
- # p Resolv::DNS::Name.create("x.y.z").subdomain_of?(domain) #=> true
- # p Resolv::DNS::Name.create("y.z").subdomain_of?(domain) #=> false
- # p Resolv::DNS::Name.create("z").subdomain_of?(domain) #=> false
- # p Resolv::DNS::Name.create("x.y.z.").subdomain_of?(domain) #=> false
- # p Resolv::DNS::Name.create("w.z").subdomain_of?(domain) #=> false
- #
-
- def subdomain_of?(other)
- raise ArgumentError, "not a domain name: #{other.inspect}" unless Name === other
- return false if @absolute != other.absolute?
- other_len = other.length
- return false if @labels.length <= other_len
- return @labels[-other_len, other_len] == other.to_a
- end
-
- def hash # :nodoc:
- return @labels.hash ^ @absolute.hash
- end
-
- def to_a # :nodoc:
- return @labels
- end
-
- def length # :nodoc:
- return @labels.length
- end
-
- def [](i) # :nodoc:
- return @labels[i]
- end
-
- ##
- # returns the domain name as a string.
- #
- # The domain name doesn't have a trailing dot even if the name object is
- # absolute.
- #
- # Example:
- #
- # p Resolv::DNS::Name.create("x.y.z.").to_s #=> "x.y.z"
- # p Resolv::DNS::Name.create("x.y.z").to_s #=> "x.y.z"
-
- def to_s
- return @labels.join('.')
- end
- end
-
- class Message # :nodoc:
- @@identifier = -1
-
- def initialize(id = (@@identifier += 1) & 0xffff)
- @id = id
- @qr = 0
- @opcode = 0
- @aa = 0
- @tc = 0
- @rd = 0 # recursion desired
- @ra = 0 # recursion available
- @rcode = 0
- @question = []
- @answer = []
- @authority = []
- @additional = []
- end
-
- attr_accessor :id, :qr, :opcode, :aa, :tc, :rd, :ra, :rcode
- attr_reader :question, :answer, :authority, :additional
-
- def ==(other)
- return @id == other.id &&
- @qr == other.qr &&
- @opcode == other.opcode &&
- @aa == other.aa &&
- @tc == other.tc &&
- @rd == other.rd &&
- @ra == other.ra &&
- @rcode == other.rcode &&
- @question == other.question &&
- @answer == other.answer &&
- @authority == other.authority &&
- @additional == other.additional
- end
-
- def add_question(name, typeclass)
- @question << [Name.create(name), typeclass]
- end
-
- def each_question
- @question.each {|name, typeclass|
- yield name, typeclass
- }
- end
-
- def add_answer(name, ttl, data)
- @answer << [Name.create(name), ttl, data]
- end
-
- def each_answer
- @answer.each {|name, ttl, data|
- yield name, ttl, data
- }
- end
-
- def add_authority(name, ttl, data)
- @authority << [Name.create(name), ttl, data]
- end
-
- def each_authority
- @authority.each {|name, ttl, data|
- yield name, ttl, data
- }
- end
-
- def add_additional(name, ttl, data)
- @additional << [Name.create(name), ttl, data]
- end
-
- def each_additional
- @additional.each {|name, ttl, data|
- yield name, ttl, data
- }
- end
-
- def each_resource
- each_answer {|name, ttl, data| yield name, ttl, data}
- each_authority {|name, ttl, data| yield name, ttl, data}
- each_additional {|name, ttl, data| yield name, ttl, data}
- end
-
- def encode
- return MessageEncoder.new {|msg|
- msg.put_pack('nnnnnn',
- @id,
- (@qr & 1) << 15 |
- (@opcode & 15) << 11 |
- (@aa & 1) << 10 |
- (@tc & 1) << 9 |
- (@rd & 1) << 8 |
- (@ra & 1) << 7 |
- (@rcode & 15),
- @question.length,
- @answer.length,
- @authority.length,
- @additional.length)
- @question.each {|q|
- name, typeclass = q
- msg.put_name(name)
- msg.put_pack('nn', typeclass::TypeValue, typeclass::ClassValue)
- }
- [@answer, @authority, @additional].each {|rr|
- rr.each {|r|
- name, ttl, data = r
- msg.put_name(name)
- msg.put_pack('nnN', data.class::TypeValue, data.class::ClassValue, ttl)
- msg.put_length16 {data.encode_rdata(msg)}
- }
- }
- }.to_s
- end
-
- class MessageEncoder # :nodoc:
- def initialize
- @data = ''
- @names = {}
- yield self
- end
-
- def to_s
- return @data
- end
-
- def put_bytes(d)
- @data << d
- end
-
- def put_pack(template, *d)
- @data << d.pack(template)
- end
-
- def put_length16
- length_index = @data.length
- @data << "\0\0"
- data_start = @data.length
- yield
- data_end = @data.length
- @data[length_index, 2] = [data_end - data_start].pack("n")
- end
-
- def put_string(d)
- self.put_pack("C", d.length)
- @data << d
- end
-
- def put_string_list(ds)
- ds.each {|d|
- self.put_string(d)
- }
- end
-
- def put_name(d)
- put_labels(d.to_a)
- end
-
- def put_labels(d)
- d.each_index {|i|
- domain = d[i..-1]
- if idx = @names[domain]
- self.put_pack("n", 0xc000 | idx)
- return
- else
- @names[domain] = @data.length
- self.put_label(d[i])
- end
- }
- @data << "\0"
- end
-
- def put_label(d)
- self.put_string(d.to_s)
- end
- end
-
- def Message.decode(m)
- o = Message.new(0)
- MessageDecoder.new(m) {|msg|
- id, flag, qdcount, ancount, nscount, arcount =
- msg.get_unpack('nnnnnn')
- o.id = id
- o.qr = (flag >> 15) & 1
- o.opcode = (flag >> 11) & 15
- o.aa = (flag >> 10) & 1
- o.tc = (flag >> 9) & 1
- o.rd = (flag >> 8) & 1
- o.ra = (flag >> 7) & 1
- o.rcode = flag & 15
- (1..qdcount).each {
- name, typeclass = msg.get_question
- o.add_question(name, typeclass)
- }
- (1..ancount).each {
- name, ttl, data = msg.get_rr
- o.add_answer(name, ttl, data)
- }
- (1..nscount).each {
- name, ttl, data = msg.get_rr
- o.add_authority(name, ttl, data)
- }
- (1..arcount).each {
- name, ttl, data = msg.get_rr
- o.add_additional(name, ttl, data)
- }
- }
- return o
- end
-
- class MessageDecoder # :nodoc:
- def initialize(data)
- @data = data
- @index = 0
- @limit = data.length
- yield self
- end
-
- def inspect
- "\#<#{self.class}: #{@data[0, @index].inspect} #{@data[@index..-1].inspect}>"
- end
-
- def get_length16
- len, = self.get_unpack('n')
- save_limit = @limit
- @limit = @index + len
- d = yield(len)
- if @index < @limit
- raise DecodeError.new("junk exists")
- elsif @limit < @index
- raise DecodeError.new("limit exceeded")
- end
- @limit = save_limit
- return d
- end
-
- def get_bytes(len = @limit - @index)
- raise DecodeError.new("limit exceeded") if @limit < @index + len
- d = @data[@index, len]
- @index += len
- return d
- end
-
- def get_unpack(template)
- len = 0
- template.each_byte {|byte|
- byte = "%c" % byte
- case byte
- when ?c, ?C
- len += 1
- when ?n
- len += 2
- when ?N
- len += 4
- else
- raise StandardError.new("unsupported template: '#{byte.chr}' in '#{template}'")
- end
- }
- raise DecodeError.new("limit exceeded") if @limit < @index + len
- arr = @data.unpack("@#{@index}#{template}")
- @index += len
- return arr
- end
-
- def get_string
- raise DecodeError.new("limit exceeded") if @limit <= @index
- len = @data[@index].ord
- raise DecodeError.new("limit exceeded") if @limit < @index + 1 + len
- d = @data[@index + 1, len]
- @index += 1 + len
- return d
- end
-
- def get_string_list
- strings = []
- while @index < @limit
- strings << self.get_string
- end
- strings
- end
-
- def get_name
- return Name.new(self.get_labels)
- end
-
- def get_labels
- prev_index = @index
- save_index = nil
- d = []
- while true
- raise DecodeError.new("limit exceeded") if @limit <= @index
- case @data[@index].ord
- when 0
- @index += 1
- if save_index
- @index = save_index
- end
- return d
- when 192..255
- idx = self.get_unpack('n')[0] & 0x3fff
- if prev_index <= idx
- raise DecodeError.new("non-backward name pointer")
- end
- prev_index = idx
- if !save_index
- save_index = @index
- end
- @index = idx
- else
- d << self.get_label
- end
- end
- end
-
- def get_label
- return Label::Str.new(self.get_string)
- end
-
- def get_question
- name = self.get_name
- type, klass = self.get_unpack("nn")
- return name, Resource.get_class(type, klass)
- end
-
- def get_rr
- name = self.get_name
- type, klass, ttl = self.get_unpack('nnN')
- typeclass = Resource.get_class(type, klass)
- res = self.get_length16 { typeclass.decode_rdata self }
- res.instance_variable_set :@ttl, ttl
- return name, ttl, res
- end
- end
- end
-
- ##
- # A DNS query abstract class.
-
- class Query
- def encode_rdata(msg) # :nodoc:
- raise EncodeError.new("#{self.class} is query.")
- end
-
- def self.decode_rdata(msg) # :nodoc:
- raise DecodeError.new("#{self.class} is query.")
- end
- end
-
- ##
- # A DNS resource abstract class.
-
- class Resource < Query
-
- ##
- # Remaining Time To Live for this Resource.
-
- attr_reader :ttl
-
- ClassHash = {} # :nodoc:
-
- def encode_rdata(msg) # :nodoc:
- raise NotImplementedError.new
- end
-
- def self.decode_rdata(msg) # :nodoc:
- raise NotImplementedError.new
- end
-
- def ==(other) # :nodoc:
- return false unless self.class == other.class
- s_ivars = self.instance_variables
- s_ivars.sort!
- s_ivars.delete :@ttl
- o_ivars = other.instance_variables
- o_ivars.sort!
- o_ivars.delete :@ttl
- return s_ivars == o_ivars &&
- s_ivars.collect {|name| self.instance_variable_get name} ==
- o_ivars.collect {|name| other.instance_variable_get name}
- end
-
- def eql?(other) # :nodoc:
- return self == other
- end
-
- def hash # :nodoc:
- h = 0
- vars = self.instance_variables
- vars.delete :@ttl
- vars.each {|name|
- h ^= self.instance_variable_get(name).hash
- }
- return h
- end
-
- def self.get_class(type_value, class_value) # :nodoc:
- return ClassHash[[type_value, class_value]] ||
- Generic.create(type_value, class_value)
- end
-
- ##
- # A generic resource abstract class.
-
- class Generic < Resource
-
- ##
- # Creates a new generic resource.
-
- def initialize(data)
- @data = data
- end
-
- ##
- # Data for this generic resource.
-
- attr_reader :data
-
- def encode_rdata(msg) # :nodoc:
- msg.put_bytes(data)
- end
-
- def self.decode_rdata(msg) # :nodoc:
- return self.new(msg.get_bytes)
- end
-
- def self.create(type_value, class_value) # :nodoc:
- c = Class.new(Generic)
- c.const_set(:TypeValue, type_value)
- c.const_set(:ClassValue, class_value)
- Generic.const_set("Type#{type_value}_Class#{class_value}", c)
- ClassHash[[type_value, class_value]] = c
- return c
- end
- end
-
- ##
- # Domain Name resource abstract class.
-
- class DomainName < Resource
-
- ##
- # Creates a new DomainName from +name+.
-
- def initialize(name)
- @name = name
- end
-
- ##
- # The name of this DomainName.
-
- attr_reader :name
-
- def encode_rdata(msg) # :nodoc:
- msg.put_name(@name)
- end
-
- def self.decode_rdata(msg) # :nodoc:
- return self.new(msg.get_name)
- end
- end
-
- # Standard (class generic) RRs
-
- ClassValue = nil # :nodoc:
-
- ##
- # An authoritative name server.
-
- class NS < DomainName
- TypeValue = 2 # :nodoc:
- end
-
- ##
- # The canonical name for an alias.
-
- class CNAME < DomainName
- TypeValue = 5 # :nodoc:
- end
-
- ##
- # Start Of Authority resource.
-
- class SOA < Resource
-
- TypeValue = 6 # :nodoc:
-
- ##
- # Creates a new SOA record. See the attr documentation for the
- # details of each argument.
-
- def initialize(mname, rname, serial, refresh, retry_, expire, minimum)
- @mname = mname
- @rname = rname
- @serial = serial
- @refresh = refresh
- @retry = retry_
- @expire = expire
- @minimum = minimum
- end
-
- ##
- # Name of the host where the master zone file for this zone resides.
-
- attr_reader :mname
-
- ##
- # The person responsible for this domain name.
-
- attr_reader :rname
-
- ##
- # The version number of the zone file.
-
- attr_reader :serial
-
- ##
- # How often, in seconds, a secondary name server is to check for
- # updates from the primary name server.
-
- attr_reader :refresh
-
- ##
- # How often, in seconds, a secondary name server is to retry after a
- # failure to check for a refresh.
-
- attr_reader :retry
-
- ##
- # Time in seconds that a secondary name server is to use the data
- # before refreshing from the primary name server.
-
- attr_reader :expire
-
- ##
- # The minimum number of seconds to be used for TTL values in RRs.
-
- attr_reader :minimum
-
- def encode_rdata(msg) # :nodoc:
- msg.put_name(@mname)
- msg.put_name(@rname)
- msg.put_pack('NNNNN', @serial, @refresh, @retry, @expire, @minimum)
- end
-
- def self.decode_rdata(msg) # :nodoc:
- mname = msg.get_name
- rname = msg.get_name
- serial, refresh, retry_, expire, minimum = msg.get_unpack('NNNNN')
- return self.new(
- mname, rname, serial, refresh, retry_, expire, minimum)
- end
- end
-
- ##
- # A Pointer to another DNS name.
-
- class PTR < DomainName
- TypeValue = 12 # :nodoc:
- end
-
- ##
- # Host Information resource.
-
- class HINFO < Resource
-
- TypeValue = 13 # :nodoc:
-
- ##
- # Creates a new HINFO running +os+ on +cpu+.
-
- def initialize(cpu, os)
- @cpu = cpu
- @os = os
- end
-
- ##
- # CPU architecture for this resource.
-
- attr_reader :cpu
-
- ##
- # Operating system for this resource.
-
- attr_reader :os
-
- def encode_rdata(msg) # :nodoc:
- msg.put_string(@cpu)
- msg.put_string(@os)
- end
-
- def self.decode_rdata(msg) # :nodoc:
- cpu = msg.get_string
- os = msg.get_string
- return self.new(cpu, os)
- end
- end
-
- ##
- # Mailing list or mailbox information.
-
- class MINFO < Resource
-
- TypeValue = 14 # :nodoc:
-
- def initialize(rmailbx, emailbx)
- @rmailbx = rmailbx
- @emailbx = emailbx
- end
-
- ##
- # Domain name responsible for this mail list or mailbox.
-
- attr_reader :rmailbx
-
- ##
- # Mailbox to use for error messages related to the mail list or mailbox.
-
- attr_reader :emailbx
-
- def encode_rdata(msg) # :nodoc:
- msg.put_name(@rmailbx)
- msg.put_name(@emailbx)
- end
-
- def self.decode_rdata(msg) # :nodoc:
- rmailbx = msg.get_string
- emailbx = msg.get_string
- return self.new(rmailbx, emailbx)
- end
- end
-
- ##
- # Mail Exchanger resource.
-
- class MX < Resource
-
- TypeValue= 15 # :nodoc:
-
- ##
- # Creates a new MX record with +preference+, accepting mail at
- # +exchange+.
-
- def initialize(preference, exchange)
- @preference = preference
- @exchange = exchange
- end
-
- ##
- # The preference for this MX.
-
- attr_reader :preference
-
- ##
- # The host of this MX.
-
- attr_reader :exchange
-
- def encode_rdata(msg) # :nodoc:
- msg.put_pack('n', @preference)
- msg.put_name(@exchange)
- end
-
- def self.decode_rdata(msg) # :nodoc:
- preference, = msg.get_unpack('n')
- exchange = msg.get_name
- return self.new(preference, exchange)
- end
- end
-
- ##
- # Unstructured text resource.
-
- class TXT < Resource
-
- TypeValue = 16 # :nodoc:
-
- def initialize(first_string, *rest_strings)
- @strings = [first_string, *rest_strings]
- end
-
- ##
- # Returns an Array of Strings for this TXT record.
-
- attr_reader :strings
-
- ##
- # Returns the concatenated string from +strings+.
-
- def data
- @strings.join("")
- end
-
- def encode_rdata(msg) # :nodoc:
- msg.put_string_list(@strings)
- end
-
- def self.decode_rdata(msg) # :nodoc:
- strings = msg.get_string_list
- return self.new(*strings)
- end
- end
-
- ##
- # Location resource
-
- class LOC < Resource
-
- TypeValue = 29 # :nodoc:
-
- def initialize(version, ssize, hprecision, vprecision, latitude, longitude, altitude)
- @version = version
- @ssize = Resolv::LOC::Size.create(ssize)
- @hprecision = Resolv::LOC::Size.create(hprecision)
- @vprecision = Resolv::LOC::Size.create(vprecision)
- @latitude = Resolv::LOC::Coord.create(latitude)
- @longitude = Resolv::LOC::Coord.create(longitude)
- @altitude = Resolv::LOC::Alt.create(altitude)
- end
-
- ##
- # Returns the version value for this LOC record which should always be 00
-
- attr_reader :version
-
- ##
- # The spherical size of this LOC
- # in meters using scientific notation as 2 integers of XeY
-
- attr_reader :ssize
-
- ##
- # The horizontal precision using ssize type values
- # in meters using scientific notation as 2 integers of XeY
- # for precision use value/2 e.g. 2m = +/-1m
-
- attr_reader :hprecision
-
- ##
- # The vertical precision using ssize type values
- # in meters using scientific notation as 2 integers of XeY
- # for precision use value/2 e.g. 2m = +/-1m
-
- attr_reader :vprecision
-
- ##
- # The latitude for this LOC where 2**31 is the equator
- # in thousandths of an arc second as an unsigned 32bit integer
-
- attr_reader :latitude
-
- ##
- # The longitude for this LOC where 2**31 is the prime meridian
- # in thousandths of an arc second as an unsigned 32bit integer
-
- attr_reader :longitude
-
- ##
- # The altitude of the LOC above a reference sphere whose surface sits 100km below the WGS84 spheroid
- # in centimeters as an unsigned 32bit integer
-
- attr_reader :altitude
-
-
- def encode_rdata(msg) # :nodoc:
- msg.put_bytes(@version)
- msg.put_bytes(@ssize.scalar)
- msg.put_bytes(@hprecision.scalar)
- msg.put_bytes(@vprecision.scalar)
- msg.put_bytes(@latitude.coordinates)
- msg.put_bytes(@longitude.coordinates)
- msg.put_bytes(@altitude.altitude)
- end
-
- def self.decode_rdata(msg) # :nodoc:
- version = msg.get_bytes(1)
- ssize = msg.get_bytes(1)
- hprecision = msg.get_bytes(1)
- vprecision = msg.get_bytes(1)
- latitude = msg.get_bytes(4)
- longitude = msg.get_bytes(4)
- altitude = msg.get_bytes(4)
- return self.new(
- version,
- Resolv::LOC::Size.new(ssize),
- Resolv::LOC::Size.new(hprecision),
- Resolv::LOC::Size.new(vprecision),
- Resolv::LOC::Coord.new(latitude,"lat"),
- Resolv::LOC::Coord.new(longitude,"lon"),
- Resolv::LOC::Alt.new(altitude)
- )
- end
- end
-
- ##
- # A Query type requesting any RR.
-
- class ANY < Query
- TypeValue = 255 # :nodoc:
- end
-
- ClassInsensitiveTypes = [ # :nodoc:
- NS, CNAME, SOA, PTR, HINFO, MINFO, MX, TXT, LOC, ANY
- ]
-
- ##
- # module IN contains ARPA Internet specific RRs.
-
- module IN
-
- ClassValue = 1 # :nodoc:
-
- ClassInsensitiveTypes.each {|s|
- c = Class.new(s)
- c.const_set(:TypeValue, s::TypeValue)
- c.const_set(:ClassValue, ClassValue)
- ClassHash[[s::TypeValue, ClassValue]] = c
- self.const_set(s.name.sub(/.*::/, ''), c)
- }
-
- ##
- # IPv4 Address resource
-
- class A < Resource
- TypeValue = 1
- ClassValue = IN::ClassValue
- ClassHash[[TypeValue, ClassValue]] = self # :nodoc:
-
- ##
- # Creates a new A for +address+.
-
- def initialize(address)
- @address = IPv4.create(address)
- end
-
- ##
- # The Resolv::IPv4 address for this A.
-
- attr_reader :address
-
- def encode_rdata(msg) # :nodoc:
- msg.put_bytes(@address.address)
- end
-
- def self.decode_rdata(msg) # :nodoc:
- return self.new(IPv4.new(msg.get_bytes(4)))
- end
- end
-
- ##
- # Well Known Service resource.
-
- class WKS < Resource
- TypeValue = 11
- ClassValue = IN::ClassValue
- ClassHash[[TypeValue, ClassValue]] = self # :nodoc:
-
- def initialize(address, protocol, bitmap)
- @address = IPv4.create(address)
- @protocol = protocol
- @bitmap = bitmap
- end
-
- ##
- # The host these services run on.
-
- attr_reader :address
-
- ##
- # IP protocol number for these services.
-
- attr_reader :protocol
-
- ##
- # A bit map of enabled services on this host.
- #
- # If protocol is 6 (TCP) then the 26th bit corresponds to the SMTP
- # service (port 25). If this bit is set, then an SMTP server should
- # be listening on TCP port 25; if zero, SMTP service is not
- # supported.
-
- attr_reader :bitmap
-
- def encode_rdata(msg) # :nodoc:
- msg.put_bytes(@address.address)
- msg.put_pack("n", @protocol)
- msg.put_bytes(@bitmap)
- end
-
- def self.decode_rdata(msg) # :nodoc:
- address = IPv4.new(msg.get_bytes(4))
- protocol, = msg.get_unpack("n")
- bitmap = msg.get_bytes
- return self.new(address, protocol, bitmap)
- end
- end
-
- ##
- # An IPv6 address record.
-
- class AAAA < Resource
- TypeValue = 28
- ClassValue = IN::ClassValue
- ClassHash[[TypeValue, ClassValue]] = self # :nodoc:
-
- ##
- # Creates a new AAAA for +address+.
-
- def initialize(address)
- @address = IPv6.create(address)
- end
-
- ##
- # The Resolv::IPv6 address for this AAAA.
-
- attr_reader :address
-
- def encode_rdata(msg) # :nodoc:
- msg.put_bytes(@address.address)
- end
-
- def self.decode_rdata(msg) # :nodoc:
- return self.new(IPv6.new(msg.get_bytes(16)))
- end
- end
-
- ##
- # SRV resource record defined in RFC 2782
- #
- # These records identify the hostname and port that a service is
- # available at.
-
- class SRV < Resource
- TypeValue = 33
- ClassValue = IN::ClassValue
- ClassHash[[TypeValue, ClassValue]] = self # :nodoc:
-
- # Create a SRV resource record.
- #
- # See the documentation for #priority, #weight, #port and #target
- # for +priority+, +weight+, +port and +target+ respectively.
-
- def initialize(priority, weight, port, target)
- @priority = priority.to_int
- @weight = weight.to_int
- @port = port.to_int
- @target = Name.create(target)
- end
-
- # The priority of this target host.
- #
- # A client MUST attempt to contact the target host with the
- # lowest-numbered priority it can reach; target hosts with the same
- # priority SHOULD be tried in an order defined by the weight field.
- # The range is 0-65535. Note that it is not widely implemented and
- # should be set to zero.
-
- attr_reader :priority
-
- # A server selection mechanism.
- #
- # The weight field specifies a relative weight for entries with the
- # same priority. Larger weights SHOULD be given a proportionately
- # higher probability of being selected. The range of this number is
- # 0-65535. Domain administrators SHOULD use Weight 0 when there
- # isn't any server selection to do, to make the RR easier to read
- # for humans (less noisy). Note that it is not widely implemented
- # and should be set to zero.
-
- attr_reader :weight
-
- # The port on this target host of this service.
- #
- # The range is 0-65535.
-
- attr_reader :port
-
- # The domain name of the target host.
- #
- # A target of "." means that the service is decidedly not available
- # at this domain.
-
- attr_reader :target
-
- def encode_rdata(msg) # :nodoc:
- msg.put_pack("n", @priority)
- msg.put_pack("n", @weight)
- msg.put_pack("n", @port)
- msg.put_name(@target)
- end
-
- def self.decode_rdata(msg) # :nodoc:
- priority, = msg.get_unpack("n")
- weight, = msg.get_unpack("n")
- port, = msg.get_unpack("n")
- target = msg.get_name
- return self.new(priority, weight, port, target)
- end
- end
- end
- end
- end
-
- ##
- # A Resolv::DNS IPv4 address.
-
- class IPv4
-
- ##
- # Regular expression IPv4 addresses must match.
-
- Regex256 = /0
- |1(?:[0-9][0-9]?)?
- |2(?:[0-4][0-9]?|5[0-5]?|[6-9])?
- |[3-9][0-9]?/x
- Regex = /\A(#{Regex256})\.(#{Regex256})\.(#{Regex256})\.(#{Regex256})\z/
-
- def self.create(arg)
- case arg
- when IPv4
- return arg
- when Regex
- if (0..255) === (a = $1.to_i) &&
- (0..255) === (b = $2.to_i) &&
- (0..255) === (c = $3.to_i) &&
- (0..255) === (d = $4.to_i)
- return self.new([a, b, c, d].pack("CCCC"))
- else
- raise ArgumentError.new("IPv4 address with invalid value: " + arg)
- end
- else
- raise ArgumentError.new("cannot interpret as IPv4 address: #{arg.inspect}")
- end
- end
-
- def initialize(address) # :nodoc:
- unless address.kind_of?(String)
- raise ArgumentError, 'IPv4 address must be a string'
- end
- unless address.length == 4
- raise ArgumentError, "IPv4 address expects 4 bytes but #{address.length} bytes"
- end
- @address = address
- end
-
- ##
- # A String representation of this IPv4 address.
-
- ##
- # The raw IPv4 address as a String.
-
- attr_reader :address
-
- def to_s # :nodoc:
- return sprintf("%d.%d.%d.%d", *@address.unpack("CCCC"))
- end
-
- def inspect # :nodoc:
- return "#<#{self.class} #{self}>"
- end
-
- ##
- # Turns this IPv4 address into a Resolv::DNS::Name.
-
- def to_name
- return DNS::Name.create(
- '%d.%d.%d.%d.in-addr.arpa.' % @address.unpack('CCCC').reverse)
- end
-
- def ==(other) # :nodoc:
- return @address == other.address
- end
-
- def eql?(other) # :nodoc:
- return self == other
- end
-
- def hash # :nodoc:
- return @address.hash
- end
- end
-
- ##
- # A Resolv::DNS IPv6 address.
-
- class IPv6
-
- ##
- # IPv6 address format a:b:c:d:e:f:g:h
- Regex_8Hex = /\A
- (?:[0-9A-Fa-f]{1,4}:){7}
- [0-9A-Fa-f]{1,4}
- \z/x
-
- ##
- # Compressed IPv6 address format a::b
-
- Regex_CompressedHex = /\A
- ((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?) ::
- ((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)
- \z/x
-
- ##
- # IPv4 mapped IPv6 address format a:b:c:d:e:f:w.x.y.z
-
- Regex_6Hex4Dec = /\A
- ((?:[0-9A-Fa-f]{1,4}:){6,6})
- (\d+)\.(\d+)\.(\d+)\.(\d+)
- \z/x
-
- ##
- # Compressed IPv4 mapped IPv6 address format a::b:w.x.y.z
-
- Regex_CompressedHex4Dec = /\A
- ((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?) ::
- ((?:[0-9A-Fa-f]{1,4}:)*)
- (\d+)\.(\d+)\.(\d+)\.(\d+)
- \z/x
-
- ##
- # A composite IPv6 address Regexp.
-
- Regex = /
- (?:#{Regex_8Hex}) |
- (?:#{Regex_CompressedHex}) |
- (?:#{Regex_6Hex4Dec}) |
- (?:#{Regex_CompressedHex4Dec})/x
-
- ##
- # Creates a new IPv6 address from +arg+ which may be:
- #
- # IPv6:: returns +arg+.
- # String:: +arg+ must match one of the IPv6::Regex* constants
-
- def self.create(arg)
- case arg
- when IPv6
- return arg
- when String
- address = ''
- if Regex_8Hex =~ arg
- arg.scan(/[0-9A-Fa-f]+/) {|hex| address << [hex.hex].pack('n')}
- elsif Regex_CompressedHex =~ arg
- prefix = $1
- suffix = $2
- a1 = ''
- a2 = ''
- prefix.scan(/[0-9A-Fa-f]+/) {|hex| a1 << [hex.hex].pack('n')}
- suffix.scan(/[0-9A-Fa-f]+/) {|hex| a2 << [hex.hex].pack('n')}
- omitlen = 16 - a1.length - a2.length
- address << a1 << "\0" * omitlen << a2
- elsif Regex_6Hex4Dec =~ arg
- prefix, a, b, c, d = $1, $2.to_i, $3.to_i, $4.to_i, $5.to_i
- if (0..255) === a && (0..255) === b && (0..255) === c && (0..255) === d
- prefix.scan(/[0-9A-Fa-f]+/) {|hex| address << [hex.hex].pack('n')}
- address << [a, b, c, d].pack('CCCC')
- else
- raise ArgumentError.new("not numeric IPv6 address: " + arg)
- end
- elsif Regex_CompressedHex4Dec =~ arg
- prefix, suffix, a, b, c, d = $1, $2, $3.to_i, $4.to_i, $5.to_i, $6.to_i
- if (0..255) === a && (0..255) === b && (0..255) === c && (0..255) === d
- a1 = ''
- a2 = ''
- prefix.scan(/[0-9A-Fa-f]+/) {|hex| a1 << [hex.hex].pack('n')}
- suffix.scan(/[0-9A-Fa-f]+/) {|hex| a2 << [hex.hex].pack('n')}
- omitlen = 12 - a1.length - a2.length
- address << a1 << "\0" * omitlen << a2 << [a, b, c, d].pack('CCCC')
- else
- raise ArgumentError.new("not numeric IPv6 address: " + arg)
- end
- else
- raise ArgumentError.new("not numeric IPv6 address: " + arg)
- end
- return IPv6.new(address)
- else
- raise ArgumentError.new("cannot interpret as IPv6 address: #{arg.inspect}")
- end
- end
-
- def initialize(address) # :nodoc:
- unless address.kind_of?(String) && address.length == 16
- raise ArgumentError.new('IPv6 address must be 16 bytes')
- end
- @address = address
- end
-
- ##
- # The raw IPv6 address as a String.
-
- attr_reader :address
-
- def to_s # :nodoc:
- address = sprintf("%X:%X:%X:%X:%X:%X:%X:%X", *@address.unpack("nnnnnnnn"))
- unless address.sub!(/(^|:)0(:0)+(:|$)/, '::')
- address.sub!(/(^|:)0(:|$)/, '::')
- end
- return address
- end
-
- def inspect # :nodoc:
- return "#<#{self.class} #{self}>"
- end
-
- ##
- # Turns this IPv6 address into a Resolv::DNS::Name.
- #--
- # ip6.arpa should be searched too. [RFC3152]
-
- def to_name
- return DNS::Name.new(
- @address.unpack("H32")[0].split(//).reverse + ['ip6', 'arpa'])
- end
-
- def ==(other) # :nodoc:
- return @address == other.address
- end
-
- def eql?(other) # :nodoc:
- return self == other
- end
-
- def hash # :nodoc:
- return @address.hash
- end
- end
-
- ##
- # Resolv::MDNS is a one-shot Multicast DNS (mDNS) resolver. It blindly
- # makes queries to the mDNS addresses without understanding anything about
- # multicast ports.
- #
- # Information taken form the following places:
- #
- # * RFC 6762
-
- class MDNS < DNS
-
- ##
- # Default mDNS Port
-
- Port = 5353
-
- ##
- # Default IPv4 mDNS address
-
- AddressV4 = '224.0.0.251'
-
- ##
- # Default IPv6 mDNS address
-
- AddressV6 = 'ff02::fb'
-
- ##
- # Default mDNS addresses
-
- Addresses = [
- [AddressV4, Port],
- [AddressV6, Port],
- ]
-
- ##
- # Creates a new one-shot Multicast DNS (mDNS) resolver.
- #
- # +config_info+ can be:
- #
- # nil::
- # Uses the default mDNS addresses
- #
- # Hash::
- # Must contain :nameserver or :nameserver_port like
- # Resolv::DNS#initialize.
-
- def initialize(config_info=nil)
- if config_info then
- super({ nameserver_port: Addresses }.merge(config_info))
- else
- super(nameserver_port: Addresses)
- end
- end
-
- ##
- # Iterates over all IP addresses for +name+ retrieved from the mDNS
- # resolver, provided name ends with "local". If the name does not end in
- # "local" no records will be returned.
- #
- # +name+ can be a Resolv::DNS::Name or a String. Retrieved addresses will
- # be a Resolv::IPv4 or Resolv::IPv6
-
- def each_address(name)
- name = Resolv::DNS::Name.create(name)
-
- return unless name.to_a.last == 'local'
-
- super(name)
- end
-
- def make_udp_requester # :nodoc:
- nameserver_port = @config.nameserver_port
- Requester::MDNSOneShot.new(*nameserver_port)
- end
-
- end
-
- module LOC
-
- ##
- # A Resolv::LOC::Size
-
- class Size
-
- Regex = /^(\d+\.*\d*)[m]$/
-
- ##
- # Creates a new LOC::Size from +arg+ which may be:
- #
- # LOC::Size:: returns +arg+.
- # String:: +arg+ must match the LOC::Size::Regex constant
-
- def self.create(arg)
- case arg
- when Size
- return arg
- when String
- scalar = ''
- if Regex =~ arg
- scalar = [(($1.to_f*(1e2)).to_i.to_s[0].to_i*(2**4)+(($1.to_f*(1e2)).to_i.to_s.length-1))].pack("C")
- else
- raise ArgumentError.new("not a properly formed Size string: " + arg)
- end
- return Size.new(scalar)
- else
- raise ArgumentError.new("cannot interpret as Size: #{arg.inspect}")
- end
- end
-
- def initialize(scalar)
- @scalar = scalar
- end
-
- ##
- # The raw size
-
- attr_reader :scalar
-
- def to_s # :nodoc:
- s = @scalar.unpack("H2").join.to_s
- return ((s[0].to_i)*(10**(s[1].to_i-2))).to_s << "m"
- end
-
- def inspect # :nodoc:
- return "#<#{self.class} #{self}>"
- end
-
- def ==(other) # :nodoc:
- return @scalar == other.scalar
- end
-
- def eql?(other) # :nodoc:
- return self == other
- end
-
- def hash # :nodoc:
- return @scalar.hash
- end
-
- end
-
- ##
- # A Resolv::LOC::Coord
-
- class Coord
-
- Regex = /^(\d+)\s(\d+)\s(\d+\.\d+)\s([NESW])$/
-
- ##
- # Creates a new LOC::Coord from +arg+ which may be:
- #
- # LOC::Coord:: returns +arg+.
- # String:: +arg+ must match the LOC::Coord::Regex constant
-
- def self.create(arg)
- case arg
- when Coord
- return arg
- when String
- coordinates = ''
- if Regex =~ arg && $1<180
- hemi = ($4[/([NE])/,1]) || ($4[/([SW])/,1]) ? 1 : -1
- coordinates = [(($1.to_i*(36e5))+($2.to_i*(6e4))+($3.to_f*(1e3)))*hemi+(2**31)].pack("N")
- (orientation ||= '') << $4[[/NS/],1] ? 'lat' : 'lon'
- else
- raise ArgumentError.new("not a properly formed Coord string: " + arg)
- end
- return Coord.new(coordinates,orientation)
- else
- raise ArgumentError.new("cannot interpret as Coord: #{arg.inspect}")
- end
- end
-
- def initialize(coordinates,orientation)
- unless coordinates.kind_of?(String)
- raise ArgumentError.new("Coord must be a 32bit unsigned integer in hex format: #{coordinates.inspect}")
- end
- unless orientation.kind_of?(String) && orientation[/^lon$|^lat$/]
- raise ArgumentError.new('Coord expects orientation to be a String argument of "lat" or "lon"')
- end
- @coordinates = coordinates
- @orientation = orientation
- end
-
- ##
- # The raw coordinates
-
- attr_reader :coordinates
-
- ## The orientation of the hemisphere as 'lat' or 'lon'
-
- attr_reader :orientation
-
- def to_s # :nodoc:
- c = @coordinates.unpack("N").join.to_i
- val = (c - (2**31)).abs
- fracsecs = (val % 1e3).to_i.to_s
- val = val / 1e3
- secs = (val % 60).to_i.to_s
- val = val / 60
- mins = (val % 60).to_i.to_s
- degs = (val / 60).to_i.to_s
- posi = (c >= 2**31)
- case posi
- when true
- hemi = @orientation[/^lat$/] ? "N" : "E"
- else
- hemi = @orientation[/^lon$/] ? "W" : "S"
- end
- return degs << " " << mins << " " << secs << "." << fracsecs << " " << hemi
- end
-
- def inspect # :nodoc:
- return "#<#{self.class} #{self}>"
- end
-
- def ==(other) # :nodoc:
- return @coordinates == other.coordinates
- end
-
- def eql?(other) # :nodoc:
- return self == other
- end
-
- def hash # :nodoc:
- return @coordinates.hash
- end
-
- end
-
- ##
- # A Resolv::LOC::Alt
-
- class Alt
-
- Regex = /^([+-]*\d+\.*\d*)[m]$/
-
- ##
- # Creates a new LOC::Alt from +arg+ which may be:
- #
- # LOC::Alt:: returns +arg+.
- # String:: +arg+ must match the LOC::Alt::Regex constant
-
- def self.create(arg)
- case arg
- when Alt
- return arg
- when String
- altitude = ''
- if Regex =~ arg
- altitude = [($1.to_f*(1e2))+(1e7)].pack("N")
- else
- raise ArgumentError.new("not a properly formed Alt string: " + arg)
- end
- return Alt.new(altitude)
- else
- raise ArgumentError.new("cannot interpret as Alt: #{arg.inspect}")
- end
- end
-
- def initialize(altitude)
- @altitude = altitude
- end
-
- ##
- # The raw altitude
-
- attr_reader :altitude
-
- def to_s # :nodoc:
- a = @altitude.unpack("N").join.to_i
- return ((a.to_f/1e2)-1e5).to_s + "m"
- end
-
- def inspect # :nodoc:
- return "#<#{self.class} #{self}>"
- end
-
- def ==(other) # :nodoc:
- return @altitude == other.altitude
- end
-
- def eql?(other) # :nodoc:
- return self == other
- end
-
- def hash # :nodoc:
- return @altitude.hash
- end
-
- end
-
- end
-
- ##
- # Default resolver to use for Resolv class methods.
-
- DefaultResolver = self.new
-
- ##
- # Replaces the resolvers in the default resolver with +new_resolvers+. This
- # allows resolvers to be changed for resolv-replace.
-
- def DefaultResolver.replace_resolvers new_resolvers
- @resolvers = new_resolvers
- end
-
- ##
- # Address Regexp to use for matching IP addresses.
-
- AddressRegex = /(?:#{IPv4::Regex})|(?:#{IPv6::Regex})/
-
-end
-
diff --git a/ruby_2_2/lib/rexml/attlistdecl.rb b/ruby_2_2/lib/rexml/attlistdecl.rb
deleted file mode 100644
index ec4e6c3b8d..0000000000
--- a/ruby_2_2/lib/rexml/attlistdecl.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-#vim:ts=2 sw=2 noexpandtab:
-require 'rexml/child'
-require 'rexml/source'
-
-module REXML
- # This class needs:
- # * Documentation
- # * Work! Not all types of attlists are intelligently parsed, so we just
- # spew back out what we get in. This works, but it would be better if
- # we formatted the output ourselves.
- #
- # AttlistDecls provide *just* enough support to allow namespace
- # declarations. If you need some sort of generalized support, or have an
- # interesting idea about how to map the hideous, terrible design of DTD
- # AttlistDecls onto an intuitive Ruby interface, let me know. I'm desperate
- # for anything to make DTDs more palateable.
- class AttlistDecl < Child
- include Enumerable
-
- # What is this? Got me.
- attr_reader :element_name
-
- # Create an AttlistDecl, pulling the information from a Source. Notice
- # that this isn't very convenient; to create an AttlistDecl, you basically
- # have to format it yourself, and then have the initializer parse it.
- # Sorry, but for the forseeable future, DTD support in REXML is pretty
- # weak on convenience. Have I mentioned how much I hate DTDs?
- def initialize(source)
- super()
- if (source.kind_of? Array)
- @element_name, @pairs, @contents = *source
- end
- end
-
- # Access the attlist attribute/value pairs.
- # value = attlist_decl[ attribute_name ]
- def [](key)
- @pairs[key]
- end
-
- # Whether an attlist declaration includes the given attribute definition
- # if attlist_decl.include? "xmlns:foobar"
- def include?(key)
- @pairs.keys.include? key
- end
-
- # Iterate over the key/value pairs:
- # attlist_decl.each { |attribute_name, attribute_value| ... }
- def each(&block)
- @pairs.each(&block)
- end
-
- # Write out exactly what we got in.
- def write out, indent=-1
- out << @contents
- end
-
- def node_type
- :attlistdecl
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/attribute.rb b/ruby_2_2/lib/rexml/attribute.rb
deleted file mode 100644
index c3e8aa07d7..0000000000
--- a/ruby_2_2/lib/rexml/attribute.rb
+++ /dev/null
@@ -1,191 +0,0 @@
-require "rexml/namespace"
-require 'rexml/text'
-
-module REXML
- # Defines an Element Attribute; IE, a attribute=value pair, as in:
- # <element attribute="value"/>. Attributes can be in their own
- # namespaces. General users of REXML will not interact with the
- # Attribute class much.
- class Attribute
- include Node
- include Namespace
-
- # The element to which this attribute belongs
- attr_reader :element
- # The normalized value of this attribute. That is, the attribute with
- # entities intact.
- attr_writer :normalized
- PATTERN = /\s*(#{NAME_STR})\s*=\s*(["'])(.*?)\2/um
-
- NEEDS_A_SECOND_CHECK = /(<|&((#{Entity::NAME});|(#0*((?:\d+)|(?:x[a-fA-F0-9]+)));)?)/um
-
- # Constructor.
- # FIXME: The parser doesn't catch illegal characters in attributes
- #
- # first::
- # Either: an Attribute, which this new attribute will become a
- # clone of; or a String, which is the name of this attribute
- # second::
- # If +first+ is an Attribute, then this may be an Element, or nil.
- # If nil, then the Element parent of this attribute is the parent
- # of the +first+ Attribute. If the first argument is a String,
- # then this must also be a String, and is the content of the attribute.
- # If this is the content, it must be fully normalized (contain no
- # illegal characters).
- # parent::
- # Ignored unless +first+ is a String; otherwise, may be the Element
- # parent of this attribute, or nil.
- #
- #
- # Attribute.new( attribute_to_clone )
- # Attribute.new( attribute_to_clone, parent_element )
- # Attribute.new( "attr", "attr_value" )
- # Attribute.new( "attr", "attr_value", parent_element )
- def initialize( first, second=nil, parent=nil )
- @normalized = @unnormalized = @element = nil
- if first.kind_of? Attribute
- self.name = first.expanded_name
- @unnormalized = first.value
- if second.kind_of? Element
- @element = second
- else
- @element = first.element
- end
- elsif first.kind_of? String
- @element = parent
- self.name = first
- @normalized = second.to_s
- else
- raise "illegal argument #{first.class.name} to Attribute constructor"
- end
- end
-
- # Returns the namespace of the attribute.
- #
- # e = Element.new( "elns:myelement" )
- # e.add_attribute( "nsa:a", "aval" )
- # e.add_attribute( "b", "bval" )
- # e.attributes.get_attribute( "a" ).prefix # -> "nsa"
- # e.attributes.get_attribute( "b" ).prefix # -> "elns"
- # a = Attribute.new( "x", "y" )
- # a.prefix # -> ""
- def prefix
- pf = super
- if pf == ""
- pf = @element.prefix if @element
- end
- pf
- end
-
- # Returns the namespace URL, if defined, or nil otherwise
- #
- # e = Element.new("el")
- # e.add_namespace("ns", "http://url")
- # e.add_attribute("ns:a", "b")
- # e.add_attribute("nsx:a", "c")
- # e.attribute("ns:a").namespace # => "http://url"
- # e.attribute("nsx:a").namespace # => nil
- def namespace arg=nil
- arg = prefix if arg.nil?
- @element.namespace arg
- end
-
- # Returns true if other is an Attribute and has the same name and value,
- # false otherwise.
- def ==( other )
- other.kind_of?(Attribute) and other.name==name and other.value==value
- end
-
- # Creates (and returns) a hash from both the name and value
- def hash
- name.hash + value.hash
- end
-
- # Returns this attribute out as XML source, expanding the name
- #
- # a = Attribute.new( "x", "y" )
- # a.to_string # -> "x='y'"
- # b = Attribute.new( "ns:x", "y" )
- # b.to_string # -> "ns:x='y'"
- def to_string
- if @element and @element.context and @element.context[:attribute_quote] == :quote
- %Q^#@expanded_name="#{to_s().gsub(/"/, '&quot;')}"^
- else
- "#@expanded_name='#{to_s().gsub(/'/, '&apos;')}'"
- end
- end
-
- def doctype
- if @element
- doc = @element.document
- doc.doctype if doc
- end
- end
-
- # Returns the attribute value, with entities replaced
- def to_s
- return @normalized if @normalized
-
- @normalized = Text::normalize( @unnormalized, doctype )
- @unnormalized = nil
- @normalized
- end
-
- # Returns the UNNORMALIZED value of this attribute. That is, entities
- # have been expanded to their values
- def value
- return @unnormalized if @unnormalized
- @unnormalized = Text::unnormalize( @normalized, doctype )
- @normalized = nil
- @unnormalized
- end
-
- # Returns a copy of this attribute
- def clone
- Attribute.new self
- end
-
- # Sets the element of which this object is an attribute. Normally, this
- # is not directly called.
- #
- # Returns this attribute
- def element=( element )
- @element = element
-
- if @normalized
- Text.check( @normalized, NEEDS_A_SECOND_CHECK, doctype )
- end
-
- self
- end
-
- # Removes this Attribute from the tree, and returns true if successful
- #
- # This method is usually not called directly.
- def remove
- @element.attributes.delete self.name unless @element.nil?
- end
-
- # Writes this attribute (EG, puts 'key="value"' to the output)
- def write( output, indent=-1 )
- output << to_string
- end
-
- def node_type
- :attribute
- end
-
- def inspect
- rv = ""
- write( rv )
- rv
- end
-
- def xpath
- path = @element.xpath
- path += "/@#{self.expanded_name}"
- return path
- end
- end
-end
-#vim:ts=2 sw=2 noexpandtab:
diff --git a/ruby_2_2/lib/rexml/cdata.rb b/ruby_2_2/lib/rexml/cdata.rb
deleted file mode 100644
index 73358edc28..0000000000
--- a/ruby_2_2/lib/rexml/cdata.rb
+++ /dev/null
@@ -1,67 +0,0 @@
-require "rexml/text"
-
-module REXML
- class CData < Text
- START = '<![CDATA['
- STOP = ']]>'
- ILLEGAL = /(\]\]>)/
-
- # Constructor. CData is data between <![CDATA[ ... ]]>
- #
- # _Examples_
- # CData.new( source )
- # CData.new( "Here is some CDATA" )
- # CData.new( "Some unprocessed data", respect_whitespace_TF, parent_element )
- def initialize( first, whitespace=true, parent=nil )
- super( first, whitespace, parent, false, true, ILLEGAL )
- end
-
- # Make a copy of this object
- #
- # _Examples_
- # c = CData.new( "Some text" )
- # d = c.clone
- # d.to_s # -> "Some text"
- def clone
- CData.new self
- end
-
- # Returns the content of this CData object
- #
- # _Examples_
- # c = CData.new( "Some text" )
- # c.to_s # -> "Some text"
- def to_s
- @string
- end
-
- def value
- @string
- end
-
- # == DEPRECATED
- # See the rexml/formatters package
- #
- # Generates XML output of this object
- #
- # output::
- # Where to write the string. Defaults to $stdout
- # indent::
- # The amount to indent this node by
- # transitive::
- # Ignored
- # ie_hack::
- # Ignored
- #
- # _Examples_
- # c = CData.new( " Some text " )
- # c.write( $stdout ) #-> <![CDATA[ Some text ]]>
- def write( output=$stdout, indent=-1, transitive=false, ie_hack=false )
- Kernel.warn( "#{self.class.name}.write is deprecated" )
- indent( output, indent )
- output << START
- output << @string
- output << STOP
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/child.rb b/ruby_2_2/lib/rexml/child.rb
deleted file mode 100644
index bf97d5f903..0000000000
--- a/ruby_2_2/lib/rexml/child.rb
+++ /dev/null
@@ -1,96 +0,0 @@
-require "rexml/node"
-
-module REXML
- ##
- # A Child object is something contained by a parent, and this class
- # contains methods to support that. Most user code will not use this
- # class directly.
- class Child
- include Node
- attr_reader :parent # The Parent of this object
-
- # Constructor. Any inheritors of this class should call super to make
- # sure this method is called.
- # parent::
- # if supplied, the parent of this child will be set to the
- # supplied value, and self will be added to the parent
- def initialize( parent = nil )
- @parent = nil
- # Declare @parent, but don't define it. The next line sets the
- # parent.
- parent.add( self ) if parent
- end
-
- # Replaces this object with another object. Basically, calls
- # Parent.replace_child
- #
- # Returns:: self
- def replace_with( child )
- @parent.replace_child( self, child )
- self
- end
-
- # Removes this child from the parent.
- #
- # Returns:: self
- def remove
- unless @parent.nil?
- @parent.delete self
- end
- self
- end
-
- # Sets the parent of this child to the supplied argument.
- #
- # other::
- # Must be a Parent object. If this object is the same object as the
- # existing parent of this child, no action is taken. Otherwise, this
- # child is removed from the current parent (if one exists), and is added
- # to the new parent.
- # Returns:: The parent added
- def parent=( other )
- return @parent if @parent == other
- @parent.delete self if defined? @parent and @parent
- @parent = other
- end
-
- alias :next_sibling :next_sibling_node
- alias :previous_sibling :previous_sibling_node
-
- # Sets the next sibling of this child. This can be used to insert a child
- # after some other child.
- # a = Element.new("a")
- # b = a.add_element("b")
- # c = Element.new("c")
- # b.next_sibling = c
- # # => <a><b/><c/></a>
- def next_sibling=( other )
- parent.insert_after self, other
- end
-
- # Sets the previous sibling of this child. This can be used to insert a
- # child before some other child.
- # a = Element.new("a")
- # b = a.add_element("b")
- # c = Element.new("c")
- # b.previous_sibling = c
- # # => <a><b/><c/></a>
- def previous_sibling=(other)
- parent.insert_before self, other
- end
-
- # Returns:: the document this child belongs to, or nil if this child
- # belongs to no document
- def document
- return parent.document unless parent.nil?
- nil
- end
-
- # This doesn't yet handle encodings
- def bytes
- document.encoding
-
- to_s
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/comment.rb b/ruby_2_2/lib/rexml/comment.rb
deleted file mode 100644
index 000b03dddd..0000000000
--- a/ruby_2_2/lib/rexml/comment.rb
+++ /dev/null
@@ -1,79 +0,0 @@
-require "rexml/child"
-
-module REXML
- ##
- # Represents an XML comment; that is, text between \<!-- ... -->
- class Comment < Child
- include Comparable
- START = "<!--"
- STOP = "-->"
-
- # The content text
-
- attr_accessor :string
-
- ##
- # Constructor. The first argument can be one of three types:
- # @param first If String, the contents of this comment are set to the
- # argument. If Comment, the argument is duplicated. If
- # Source, the argument is scanned for a comment.
- # @param second If the first argument is a Source, this argument
- # should be nil, not supplied, or a Parent to be set as the parent
- # of this object
- def initialize( first, second = nil )
- super(second)
- if first.kind_of? String
- @string = first
- elsif first.kind_of? Comment
- @string = first.string
- end
- end
-
- def clone
- Comment.new self
- end
-
- # == DEPRECATED
- # See REXML::Formatters
- #
- # output::
- # Where to write the string
- # indent::
- # An integer. If -1, no indenting will be used; otherwise, the
- # indentation will be this number of spaces, and children will be
- # indented an additional amount.
- # transitive::
- # Ignored by this class. The contents of comments are never modified.
- # ie_hack::
- # Needed for conformity to the child API, but not used by this class.
- def write( output, indent=-1, transitive=false, ie_hack=false )
- Kernel.warn("Comment.write is deprecated. See REXML::Formatters")
- indent( output, indent )
- output << START
- output << @string
- output << STOP
- end
-
- alias :to_s :string
-
- ##
- # Compares this Comment to another; the contents of the comment are used
- # in the comparison.
- def <=>(other)
- other.to_s <=> @string
- end
-
- ##
- # Compares this Comment to another; the contents of the comment are used
- # in the comparison.
- def ==( other )
- other.kind_of? Comment and
- (other <=> self) == 0
- end
-
- def node_type
- :comment
- end
- end
-end
-#vim:ts=2 sw=2 noexpandtab:
diff --git a/ruby_2_2/lib/rexml/doctype.rb b/ruby_2_2/lib/rexml/doctype.rb
deleted file mode 100644
index 0b3c533bb4..0000000000
--- a/ruby_2_2/lib/rexml/doctype.rb
+++ /dev/null
@@ -1,269 +0,0 @@
-require "rexml/parent"
-require "rexml/parseexception"
-require "rexml/namespace"
-require 'rexml/entity'
-require 'rexml/attlistdecl'
-require 'rexml/xmltokens'
-
-module REXML
- # Represents an XML DOCTYPE declaration; that is, the contents of <!DOCTYPE
- # ... >. DOCTYPES can be used to declare the DTD of a document, as well as
- # being used to declare entities used in the document.
- class DocType < Parent
- include XMLTokens
- START = "<!DOCTYPE"
- STOP = ">"
- SYSTEM = "SYSTEM"
- PUBLIC = "PUBLIC"
- DEFAULT_ENTITIES = {
- 'gt'=>EntityConst::GT,
- 'lt'=>EntityConst::LT,
- 'quot'=>EntityConst::QUOT,
- "apos"=>EntityConst::APOS
- }
-
- # name is the name of the doctype
- # external_id is the referenced DTD, if given
- attr_reader :name, :external_id, :entities, :namespaces
-
- # Constructor
- #
- # dt = DocType.new( 'foo', '-//I/Hate/External/IDs' )
- # # <!DOCTYPE foo '-//I/Hate/External/IDs'>
- # dt = DocType.new( doctype_to_clone )
- # # Incomplete. Shallow clone of doctype
- #
- # +Note+ that the constructor:
- #
- # Doctype.new( Source.new( "<!DOCTYPE foo 'bar'>" ) )
- #
- # is _deprecated_. Do not use it. It will probably disappear.
- def initialize( first, parent=nil )
- @entities = DEFAULT_ENTITIES
- @long_name = @uri = nil
- if first.kind_of? String
- super()
- @name = first
- @external_id = parent
- elsif first.kind_of? DocType
- super( parent )
- @name = first.name
- @external_id = first.external_id
- elsif first.kind_of? Array
- super( parent )
- @name = first[0]
- @external_id = first[1]
- @long_name = first[2]
- @uri = first[3]
- elsif first.kind_of? Source
- super( parent )
- parser = Parsers::BaseParser.new( first )
- event = parser.pull
- if event[0] == :start_doctype
- @name, @external_id, @long_name, @uri, = event[1..-1]
- end
- else
- super()
- end
- end
-
- def node_type
- :doctype
- end
-
- def attributes_of element
- rv = []
- each do |child|
- child.each do |key,val|
- rv << Attribute.new(key,val)
- end if child.kind_of? AttlistDecl and child.element_name == element
- end
- rv
- end
-
- def attribute_of element, attribute
- att_decl = find do |child|
- child.kind_of? AttlistDecl and
- child.element_name == element and
- child.include? attribute
- end
- return nil unless att_decl
- att_decl[attribute]
- end
-
- def clone
- DocType.new self
- end
-
- # output::
- # Where to write the string
- # indent::
- # An integer. If -1, no indentation will be used; otherwise, the
- # indentation will be this number of spaces, and children will be
- # indented an additional amount.
- # transitive::
- # Ignored
- # ie_hack::
- # Ignored
- def write( output, indent=0, transitive=false, ie_hack=false )
- f = REXML::Formatters::Default.new
- indent( output, indent )
- output << START
- output << ' '
- output << @name
- output << " #@external_id" if @external_id
- output << " #{@long_name.inspect}" if @long_name
- output << " #{@uri.inspect}" if @uri
- unless @children.empty?
- output << ' ['
- @children.each { |child|
- output << "\n"
- f.write( child, output )
- }
- output << "\n]"
- end
- output << STOP
- end
-
- def context
- @parent.context
- end
-
- def entity( name )
- @entities[name].unnormalized if @entities[name]
- end
-
- def add child
- super(child)
- @entities = DEFAULT_ENTITIES.clone if @entities == DEFAULT_ENTITIES
- @entities[ child.name ] = child if child.kind_of? Entity
- end
-
- # This method retrieves the public identifier identifying the document's
- # DTD.
- #
- # Method contributed by Henrik Martensson
- def public
- case @external_id
- when "SYSTEM"
- nil
- when "PUBLIC"
- strip_quotes(@long_name)
- end
- end
-
- # This method retrieves the system identifier identifying the document's DTD
- #
- # Method contributed by Henrik Martensson
- def system
- case @external_id
- when "SYSTEM"
- strip_quotes(@long_name)
- when "PUBLIC"
- @uri.kind_of?(String) ? strip_quotes(@uri) : nil
- end
- end
-
- # This method returns a list of notations that have been declared in the
- # _internal_ DTD subset. Notations in the external DTD subset are not
- # listed.
- #
- # Method contributed by Henrik Martensson
- def notations
- children().select {|node| node.kind_of?(REXML::NotationDecl)}
- end
-
- # Retrieves a named notation. Only notations declared in the internal
- # DTD subset can be retrieved.
- #
- # Method contributed by Henrik Martensson
- def notation(name)
- notations.find { |notation_decl|
- notation_decl.name == name
- }
- end
-
- private
-
- # Method contributed by Henrik Martensson
- def strip_quotes(quoted_string)
- quoted_string =~ /^[\'\"].*[\'\"]$/ ?
- quoted_string[1, quoted_string.length-2] :
- quoted_string
- end
- end
-
- # We don't really handle any of these since we're not a validating
- # parser, so we can be pretty dumb about them. All we need to be able
- # to do is spew them back out on a write()
-
- # This is an abstract class. You never use this directly; it serves as a
- # parent class for the specific declarations.
- class Declaration < Child
- def initialize src
- super()
- @string = src
- end
-
- def to_s
- @string+'>'
- end
-
- # == DEPRECATED
- # See REXML::Formatters
- #
- def write( output, indent )
- output << to_s
- end
- end
-
- public
- class ElementDecl < Declaration
- def initialize( src )
- super
- end
- end
-
- class ExternalEntity < Child
- def initialize( src )
- super()
- @entity = src
- end
- def to_s
- @entity
- end
- def write( output, indent )
- output << @entity
- end
- end
-
- class NotationDecl < Child
- attr_accessor :public, :system
- def initialize name, middle, pub, sys
- super(nil)
- @name = name
- @middle = middle
- @public = pub
- @system = sys
- end
-
- def to_s
- notation = "<!NOTATION #{@name} #{@middle}"
- notation << " #{@public.inspect}" if @public
- notation << " #{@system.inspect}" if @system
- notation << ">"
- notation
- end
-
- def write( output, indent=-1 )
- output << to_s
- end
-
- # This method retrieves the name of the notation.
- #
- # Method contributed by Henrik Martensson
- def name
- @name
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/document.rb b/ruby_2_2/lib/rexml/document.rb
deleted file mode 100644
index d7d24f4732..0000000000
--- a/ruby_2_2/lib/rexml/document.rb
+++ /dev/null
@@ -1,290 +0,0 @@
-require "rexml/security"
-require "rexml/element"
-require "rexml/xmldecl"
-require "rexml/source"
-require "rexml/comment"
-require "rexml/doctype"
-require "rexml/instruction"
-require "rexml/rexml"
-require "rexml/parseexception"
-require "rexml/output"
-require "rexml/parsers/baseparser"
-require "rexml/parsers/streamparser"
-require "rexml/parsers/treeparser"
-
-module REXML
- # Represents a full XML document, including PIs, a doctype, etc. A
- # Document has a single child that can be accessed by root().
- # Note that if you want to have an XML declaration written for a document
- # you create, you must add one; REXML documents do not write a default
- # declaration for you. See |DECLARATION| and |write|.
- class Document < Element
- # A convenient default XML declaration. If you want an XML declaration,
- # the easiest way to add one is mydoc << Document::DECLARATION
- # +DEPRECATED+
- # Use: mydoc << XMLDecl.default
- DECLARATION = XMLDecl.default
-
- # Constructor
- # @param source if supplied, must be a Document, String, or IO.
- # Documents have their context and Element attributes cloned.
- # Strings are expected to be valid XML documents. IOs are expected
- # to be sources of valid XML documents.
- # @param context if supplied, contains the context of the document;
- # this should be a Hash.
- def initialize( source = nil, context = {} )
- @entity_expansion_count = 0
- super()
- @context = context
- return if source.nil?
- if source.kind_of? Document
- @context = source.context
- super source
- else
- build( source )
- end
- end
-
- def node_type
- :document
- end
-
- # Should be obvious
- def clone
- Document.new self
- end
-
- # According to the XML spec, a root node has no expanded name
- def expanded_name
- ''
- #d = doc_type
- #d ? d.name : "UNDEFINED"
- end
-
- alias :name :expanded_name
-
- # We override this, because XMLDecls and DocTypes must go at the start
- # of the document
- def add( child )
- if child.kind_of? XMLDecl
- if @children[0].kind_of? XMLDecl
- @children[0] = child
- else
- @children.unshift child
- end
- child.parent = self
- elsif child.kind_of? DocType
- # Find first Element or DocType node and insert the decl right
- # before it. If there is no such node, just insert the child at the
- # end. If there is a child and it is an DocType, then replace it.
- insert_before_index = @children.find_index { |x|
- x.kind_of?(Element) || x.kind_of?(DocType)
- }
- if insert_before_index # Not null = not end of list
- if @children[ insert_before_index ].kind_of? DocType
- @children[ insert_before_index ] = child
- else
- @children[ insert_before_index-1, 0 ] = child
- end
- else # Insert at end of list
- @children << child
- end
- child.parent = self
- else
- rv = super
- raise "attempted adding second root element to document" if @elements.size > 1
- rv
- end
- end
- alias :<< :add
-
- def add_element(arg=nil, arg2=nil)
- rv = super
- raise "attempted adding second root element to document" if @elements.size > 1
- rv
- end
-
- # @return the root Element of the document, or nil if this document
- # has no children.
- def root
- elements[1]
- #self
- #@children.find { |item| item.kind_of? Element }
- end
-
- # @return the DocType child of the document, if one exists,
- # and nil otherwise.
- def doctype
- @children.find { |item| item.kind_of? DocType }
- end
-
- # @return the XMLDecl of this document; if no XMLDecl has been
- # set, the default declaration is returned.
- def xml_decl
- rv = @children[0]
- return rv if rv.kind_of? XMLDecl
- @children.unshift(XMLDecl.default)[0]
- end
-
- # @return the XMLDecl version of this document as a String.
- # If no XMLDecl has been set, returns the default version.
- def version
- xml_decl().version
- end
-
- # @return the XMLDecl encoding of this document as an
- # Encoding object.
- # If no XMLDecl has been set, returns the default encoding.
- def encoding
- xml_decl().encoding
- end
-
- # @return the XMLDecl standalone value of this document as a String.
- # If no XMLDecl has been set, returns the default setting.
- def stand_alone?
- xml_decl().stand_alone?
- end
-
- # :call-seq:
- # doc.write(output=$stdout, indent=-1, transtive=false, ie_hack=false, encoding=nil)
- # doc.write(options={:output => $stdout, :indent => -1, :transtive => false, :ie_hack => false, :encoding => nil})
- #
- # Write the XML tree out, optionally with indent. This writes out the
- # entire XML document, including XML declarations, doctype declarations,
- # and processing instructions (if any are given).
- #
- # A controversial point is whether Document should always write the XML
- # declaration (<?xml version='1.0'?>) whether or not one is given by the
- # user (or source document). REXML does not write one if one was not
- # specified, because it adds unnecessary bandwidth to applications such
- # as XML-RPC.
- #
- # Accept Nth argument style and options Hash style as argument.
- # The recommended style is options Hash style for one or more
- # arguments case.
- #
- # _Examples_
- # Document.new("<a><b/></a>").write
- #
- # output = ""
- # Document.new("<a><b/></a>").write(output)
- #
- # output = ""
- # Document.new("<a><b/></a>").write(:output => output, :indent => 2)
- #
- # See also the classes in the rexml/formatters package for the proper way
- # to change the default formatting of XML output.
- #
- # _Examples_
- #
- # output = ""
- # tr = Transitive.new
- # tr.write(Document.new("<a><b/></a>"), output)
- #
- # output::
- # output an object which supports '<< string'; this is where the
- # document will be written.
- # indent::
- # An integer. If -1, no indenting will be used; otherwise, the
- # indentation will be twice this number of spaces, and children will be
- # indented an additional amount. For a value of 3, every item will be
- # indented 3 more levels, or 6 more spaces (2 * 3). Defaults to -1
- # transitive::
- # If transitive is true and indent is >= 0, then the output will be
- # pretty-printed in such a way that the added whitespace does not affect
- # the absolute *value* of the document -- that is, it leaves the value
- # and number of Text nodes in the document unchanged.
- # ie_hack::
- # This hack inserts a space before the /> on empty tags to address
- # a limitation of Internet Explorer. Defaults to false
- # encoding::
- # Encoding name as String. Change output encoding to specified encoding
- # instead of encoding in XML declaration.
- # Defaults to nil. It means encoding in XML declaration is used.
- def write(*arguments)
- if arguments.size == 1 and arguments[0].class == Hash
- options = arguments[0]
-
- output = options[:output]
- indent = options[:indent]
- transitive = options[:transitive]
- ie_hack = options[:ie_hack]
- encoding = options[:encoding]
- else
- output, indent, transitive, ie_hack, encoding, = *arguments
- end
-
- output ||= $stdout
- indent ||= -1
- transitive = false if transitive.nil?
- ie_hack = false if ie_hack.nil?
- encoding ||= xml_decl.encoding
-
- if encoding != 'UTF-8' && !output.kind_of?(Output)
- output = Output.new( output, encoding )
- end
- formatter = if indent > -1
- if transitive
- require "rexml/formatters/transitive"
- REXML::Formatters::Transitive.new( indent, ie_hack )
- else
- REXML::Formatters::Pretty.new( indent, ie_hack )
- end
- else
- REXML::Formatters::Default.new( ie_hack )
- end
- formatter.write( self, output )
- end
-
-
- def Document::parse_stream( source, listener )
- Parsers::StreamParser.new( source, listener ).parse
- end
-
- # Set the entity expansion limit. By default the limit is set to 10000.
- #
- # Deprecated. Use REXML::Security.entity_expansion_limit= instead.
- def Document::entity_expansion_limit=( val )
- Security.entity_expansion_limit = val
- end
-
- # Get the entity expansion limit. By default the limit is set to 10000.
- #
- # Deprecated. Use REXML::Security.entity_expansion_limit= instead.
- def Document::entity_expansion_limit
- return Security.entity_expansion_limit
- end
-
- # Set the entity expansion limit. By default the limit is set to 10240.
- #
- # Deprecated. Use REXML::Security.entity_expansion_text_limit= instead.
- def Document::entity_expansion_text_limit=( val )
- Security.entity_expansion_text_limit = val
- end
-
- # Get the entity expansion limit. By default the limit is set to 10240.
- #
- # Deprecated. Use REXML::Security.entity_expansion_text_limit instead.
- def Document::entity_expansion_text_limit
- return Security.entity_expansion_text_limit
- end
-
- attr_reader :entity_expansion_count
-
- def record_entity_expansion
- @entity_expansion_count += 1
- if @entity_expansion_count > Security.entity_expansion_limit
- raise "number of entity expansions exceeded, processing aborted."
- end
- end
-
- def document
- self
- end
-
- private
- def build( source )
- Parsers::TreeParser.new( source, self ).parse
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/dtd/attlistdecl.rb b/ruby_2_2/lib/rexml/dtd/attlistdecl.rb
deleted file mode 100644
index 25955ee274..0000000000
--- a/ruby_2_2/lib/rexml/dtd/attlistdecl.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require "rexml/child"
-module REXML
- module DTD
- class AttlistDecl < Child
- START = "<!ATTLIST"
- START_RE = /^\s*#{START}/um
- PATTERN_RE = /\s*(#{START}.*?>)/um
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/dtd/dtd.rb b/ruby_2_2/lib/rexml/dtd/dtd.rb
deleted file mode 100644
index 62317bac9e..0000000000
--- a/ruby_2_2/lib/rexml/dtd/dtd.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-require "rexml/dtd/elementdecl"
-require "rexml/dtd/entitydecl"
-require "rexml/comment"
-require "rexml/dtd/notationdecl"
-require "rexml/dtd/attlistdecl"
-require "rexml/parent"
-
-module REXML
- module DTD
- class Parser
- def Parser.parse( input )
- case input
- when String
- parse_helper input
- when File
- parse_helper input.read
- end
- end
-
- # Takes a String and parses it out
- def Parser.parse_helper( input )
- contents = Parent.new
- while input.size > 0
- case input
- when ElementDecl.PATTERN_RE
- match = $&
- contents << ElementDecl.new( match )
- when AttlistDecl.PATTERN_RE
- matchdata = $~
- contents << AttlistDecl.new( matchdata )
- when EntityDecl.PATTERN_RE
- matchdata = $~
- contents << EntityDecl.new( matchdata )
- when Comment.PATTERN_RE
- matchdata = $~
- contents << Comment.new( matchdata )
- when NotationDecl.PATTERN_RE
- matchdata = $~
- contents << NotationDecl.new( matchdata )
- end
- end
- contents
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/dtd/elementdecl.rb b/ruby_2_2/lib/rexml/dtd/elementdecl.rb
deleted file mode 100644
index f90b27d761..0000000000
--- a/ruby_2_2/lib/rexml/dtd/elementdecl.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-require "rexml/child"
-module REXML
- module DTD
- class ElementDecl < Child
- START = "<!ELEMENT"
- START_RE = /^\s*#{START}/um
- # PATTERN_RE = /^\s*(#{START}.*?)>/um
- PATTERN_RE = /^\s*#{START}\s+((?:[:\w][-\.\w]*:)?[-!\*\.\w]*)(.*?)>/
- #\s*((((["']).*?\5)|[^\/'">]*)*?)(\/)?>/um, true)
-
- def initialize match
- @name = match[1]
- @rest = match[2]
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/dtd/entitydecl.rb b/ruby_2_2/lib/rexml/dtd/entitydecl.rb
deleted file mode 100644
index a9286b2b90..0000000000
--- a/ruby_2_2/lib/rexml/dtd/entitydecl.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-require "rexml/child"
-module REXML
- module DTD
- class EntityDecl < Child
- START = "<!ENTITY"
- START_RE = /^\s*#{START}/um
- PUBLIC = /^\s*#{START}\s+(?:%\s+)?(\w+)\s+PUBLIC\s+((["']).*?\3)\s+((["']).*?\5)\s*>/um
- SYSTEM = /^\s*#{START}\s+(?:%\s+)?(\w+)\s+SYSTEM\s+((["']).*?\3)(?:\s+NDATA\s+\w+)?\s*>/um
- PLAIN = /^\s*#{START}\s+(\w+)\s+((["']).*?\3)\s*>/um
- PERCENT = /^\s*#{START}\s+%\s+(\w+)\s+((["']).*?\3)\s*>/um
- # <!ENTITY name SYSTEM "...">
- # <!ENTITY name "...">
- def initialize src
- super()
- md = nil
- if src.match( PUBLIC )
- md = src.match( PUBLIC, true )
- @middle = "PUBLIC"
- @content = "#{md[2]} #{md[4]}"
- elsif src.match( SYSTEM )
- md = src.match( SYSTEM, true )
- @middle = "SYSTEM"
- @content = md[2]
- elsif src.match( PLAIN )
- md = src.match( PLAIN, true )
- @middle = ""
- @content = md[2]
- elsif src.match( PERCENT )
- md = src.match( PERCENT, true )
- @middle = ""
- @content = md[2]
- end
- raise ParseException.new("failed Entity match", src) if md.nil?
- @name = md[1]
- end
-
- def to_s
- rv = "<!ENTITY #@name "
- rv << "#@middle " if @middle.size > 0
- rv << @content
- rv
- end
-
- def write( output, indent )
- indent( output, indent )
- output << to_s
- end
-
- def EntityDecl.parse_source source, listener
- md = source.match( PATTERN_RE, true )
- thing = md[0].squeeze(" \t\n\r")
- listener.send inspect.downcase, thing
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/dtd/notationdecl.rb b/ruby_2_2/lib/rexml/dtd/notationdecl.rb
deleted file mode 100644
index 17d1b9ef29..0000000000
--- a/ruby_2_2/lib/rexml/dtd/notationdecl.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-require "rexml/child"
-module REXML
- module DTD
- class NotationDecl < Child
- START = "<!NOTATION"
- START_RE = /^\s*#{START}/um
- PUBLIC = /^\s*#{START}\s+(\w[\w-]*)\s+(PUBLIC)\s+((["']).*?\4)\s*>/um
- SYSTEM = /^\s*#{START}\s+(\w[\w-]*)\s+(SYSTEM)\s+((["']).*?\4)\s*>/um
- def initialize src
- super()
- if src.match( PUBLIC )
- md = src.match( PUBLIC, true )
- elsif src.match( SYSTEM )
- md = src.match( SYSTEM, true )
- else
- raise ParseException.new( "error parsing notation: no matching pattern", src )
- end
- @name = md[1]
- @middle = md[2]
- @rest = md[3]
- end
-
- def to_s
- "<!NOTATION #@name #@middle #@rest>"
- end
-
- def write( output, indent )
- indent( output, indent )
- output << to_s
- end
-
- def NotationDecl.parse_source source, listener
- md = source.match( PATTERN_RE, true )
- thing = md[0].squeeze(" \t\n\r")
- listener.send inspect.downcase, thing
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/element.rb b/ruby_2_2/lib/rexml/element.rb
deleted file mode 100644
index e459704d3c..0000000000
--- a/ruby_2_2/lib/rexml/element.rb
+++ /dev/null
@@ -1,1240 +0,0 @@
-require "rexml/parent"
-require "rexml/namespace"
-require "rexml/attribute"
-require "rexml/cdata"
-require "rexml/xpath"
-require "rexml/parseexception"
-
-module REXML
- # An implementation note about namespaces:
- # As we parse, when we find namespaces we put them in a hash and assign
- # them a unique ID. We then convert the namespace prefix for the node
- # to the unique ID. This makes namespace lookup much faster for the
- # cost of extra memory use. We save the namespace prefix for the
- # context node and convert it back when we write it.
- @@namespaces = {}
-
- # Represents a tagged XML element. Elements are characterized by
- # having children, attributes, and names, and can themselves be
- # children.
- class Element < Parent
- include Namespace
-
- UNDEFINED = "UNDEFINED"; # The default name
-
- # Mechanisms for accessing attributes and child elements of this
- # element.
- attr_reader :attributes, :elements
- # The context holds information about the processing environment, such as
- # whitespace handling.
- attr_accessor :context
-
- # Constructor
- # arg::
- # if not supplied, will be set to the default value.
- # If a String, the name of this object will be set to the argument.
- # If an Element, the object will be shallowly cloned; name,
- # attributes, and namespaces will be copied. Children will +not+ be
- # copied.
- # parent::
- # if supplied, must be a Parent, and will be used as
- # the parent of this object.
- # context::
- # If supplied, must be a hash containing context items. Context items
- # include:
- # * <tt>:respect_whitespace</tt> the value of this is :+all+ or an array of
- # strings being the names of the elements to respect
- # whitespace for. Defaults to :+all+.
- # * <tt>:compress_whitespace</tt> the value can be :+all+ or an array of
- # strings being the names of the elements to ignore whitespace on.
- # Overrides :+respect_whitespace+.
- # * <tt>:ignore_whitespace_nodes</tt> the value can be :+all+ or an array
- # of strings being the names of the elements in which to ignore
- # whitespace-only nodes. If this is set, Text nodes which contain only
- # whitespace will not be added to the document tree.
- # * <tt>:raw</tt> can be :+all+, or an array of strings being the names of
- # the elements to process in raw mode. In raw mode, special
- # characters in text is not converted to or from entities.
- def initialize( arg = UNDEFINED, parent=nil, context=nil )
- super(parent)
-
- @elements = Elements.new(self)
- @attributes = Attributes.new(self)
- @context = context
-
- if arg.kind_of? String
- self.name = arg
- elsif arg.kind_of? Element
- self.name = arg.expanded_name
- arg.attributes.each_attribute{ |attribute|
- @attributes << Attribute.new( attribute )
- }
- @context = arg.context
- end
- end
-
- def inspect
- rv = "<#@expanded_name"
-
- @attributes.each_attribute do |attr|
- rv << " "
- attr.write( rv, 0 )
- end
-
- if children.size > 0
- rv << "> ... </>"
- else
- rv << "/>"
- end
- end
-
-
- # Creates a shallow copy of self.
- # d = Document.new "<a><b/><b/><c><d/></c></a>"
- # new_a = d.root.clone
- # puts new_a # => "<a/>"
- def clone
- self.class.new self
- end
-
- # Evaluates to the root node of the document that this element
- # belongs to. If this element doesn't belong to a document, but does
- # belong to another Element, the parent's root will be returned, until the
- # earliest ancestor is found.
- #
- # Note that this is not the same as the document element.
- # In the following example, <a> is the document element, and the root
- # node is the parent node of the document element. You may ask yourself
- # why the root node is useful: consider the doctype and XML declaration,
- # and any processing instructions before the document element... they
- # are children of the root node, or siblings of the document element.
- # The only time this isn't true is when an Element is created that is
- # not part of any Document. In this case, the ancestor that has no
- # parent acts as the root node.
- # d = Document.new '<a><b><c/></b></a>'
- # a = d[1] ; c = a[1][1]
- # d.root_node == d # TRUE
- # a.root_node # namely, d
- # c.root_node # again, d
- def root_node
- parent.nil? ? self : parent.root_node
- end
-
- def root
- return elements[1] if self.kind_of? Document
- return self if parent.kind_of? Document or parent.nil?
- return parent.root
- end
-
- # Evaluates to the document to which this element belongs, or nil if this
- # element doesn't belong to a document.
- def document
- rt = root
- rt.parent if rt
- end
-
- # Evaluates to +true+ if whitespace is respected for this element. This
- # is the case if:
- # 1. Neither :+respect_whitespace+ nor :+compress_whitespace+ has any value
- # 2. The context has :+respect_whitespace+ set to :+all+ or
- # an array containing the name of this element, and
- # :+compress_whitespace+ isn't set to :+all+ or an array containing the
- # name of this element.
- # The evaluation is tested against +expanded_name+, and so is namespace
- # sensitive.
- def whitespace
- @whitespace = nil
- if @context
- if @context[:respect_whitespace]
- @whitespace = (@context[:respect_whitespace] == :all or
- @context[:respect_whitespace].include? expanded_name)
- end
- @whitespace = false if (@context[:compress_whitespace] and
- (@context[:compress_whitespace] == :all or
- @context[:compress_whitespace].include? expanded_name)
- )
- end
- @whitespace = true unless @whitespace == false
- @whitespace
- end
-
- def ignore_whitespace_nodes
- @ignore_whitespace_nodes = false
- if @context
- if @context[:ignore_whitespace_nodes]
- @ignore_whitespace_nodes =
- (@context[:ignore_whitespace_nodes] == :all or
- @context[:ignore_whitespace_nodes].include? expanded_name)
- end
- end
- end
-
- # Evaluates to +true+ if raw mode is set for this element. This
- # is the case if the context has :+raw+ set to :+all+ or
- # an array containing the name of this element.
- #
- # The evaluation is tested against +expanded_name+, and so is namespace
- # sensitive.
- def raw
- @raw = (@context and @context[:raw] and
- (@context[:raw] == :all or
- @context[:raw].include? expanded_name))
- @raw
- end
-
- #once :whitespace, :raw, :ignore_whitespace_nodes
-
- #################################################
- # Namespaces #
- #################################################
-
- # Evaluates to an +Array+ containing the prefixes (names) of all defined
- # namespaces at this context node.
- # doc = Document.new("<a xmlns:x='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>")
- # doc.elements['//b'].prefixes # -> ['x', 'y']
- def prefixes
- prefixes = []
- prefixes = parent.prefixes if parent
- prefixes |= attributes.prefixes
- return prefixes
- end
-
- def namespaces
- namespaces = {}
- namespaces = parent.namespaces if parent
- namespaces = namespaces.merge( attributes.namespaces )
- return namespaces
- end
-
- # Evaluates to the URI for a prefix, or the empty string if no such
- # namespace is declared for this element. Evaluates recursively for
- # ancestors. Returns the default namespace, if there is one.
- # prefix::
- # the prefix to search for. If not supplied, returns the default
- # namespace if one exists
- # Returns::
- # the namespace URI as a String, or nil if no such namespace
- # exists. If the namespace is undefined, returns an empty string
- # doc = Document.new("<a xmlns='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>")
- # b = doc.elements['//b']
- # b.namespace # -> '1'
- # b.namespace("y") # -> '2'
- def namespace(prefix=nil)
- if prefix.nil?
- prefix = prefix()
- end
- if prefix == ''
- prefix = "xmlns"
- else
- prefix = "xmlns:#{prefix}" unless prefix[0,5] == 'xmlns'
- end
- ns = attributes[ prefix ]
- ns = parent.namespace(prefix) if ns.nil? and parent
- ns = '' if ns.nil? and prefix == 'xmlns'
- return ns
- end
-
- # Adds a namespace to this element.
- # prefix::
- # the prefix string, or the namespace URI if +uri+ is not
- # supplied
- # uri::
- # the namespace URI. May be nil, in which +prefix+ is used as
- # the URI
- # Evaluates to: this Element
- # a = Element.new("a")
- # a.add_namespace("xmlns:foo", "bar" )
- # a.add_namespace("foo", "bar") # shorthand for previous line
- # a.add_namespace("twiddle")
- # puts a #-> <a xmlns:foo='bar' xmlns='twiddle'/>
- def add_namespace( prefix, uri=nil )
- unless uri
- @attributes["xmlns"] = prefix
- else
- prefix = "xmlns:#{prefix}" unless prefix =~ /^xmlns:/
- @attributes[ prefix ] = uri
- end
- self
- end
-
- # Removes a namespace from this node. This only works if the namespace is
- # actually declared in this node. If no argument is passed, deletes the
- # default namespace.
- #
- # Evaluates to: this element
- # doc = Document.new "<a xmlns:foo='bar' xmlns='twiddle'/>"
- # doc.root.delete_namespace
- # puts doc # -> <a xmlns:foo='bar'/>
- # doc.root.delete_namespace 'foo'
- # puts doc # -> <a/>
- def delete_namespace namespace="xmlns"
- namespace = "xmlns:#{namespace}" unless namespace == 'xmlns'
- attribute = attributes.get_attribute(namespace)
- attribute.remove unless attribute.nil?
- self
- end
-
- #################################################
- # Elements #
- #################################################
-
- # Adds a child to this element, optionally setting attributes in
- # the element.
- # element::
- # optional. If Element, the element is added.
- # Otherwise, a new Element is constructed with the argument (see
- # Element.initialize).
- # attrs::
- # If supplied, must be a Hash containing String name,value
- # pairs, which will be used to set the attributes of the new Element.
- # Returns:: the Element that was added
- # el = doc.add_element 'my-tag'
- # el = doc.add_element 'my-tag', {'attr1'=>'val1', 'attr2'=>'val2'}
- # el = Element.new 'my-tag'
- # doc.add_element el
- def add_element element, attrs=nil
- raise "First argument must be either an element name, or an Element object" if element.nil?
- el = @elements.add(element)
- attrs.each do |key, value|
- el.attributes[key]=value
- end if attrs.kind_of? Hash
- el
- end
-
- # Deletes a child element.
- # element::
- # Must be an +Element+, +String+, or +Integer+. If Element,
- # the element is removed. If String, the element is found (via XPath)
- # and removed. <em>This means that any parent can remove any
- # descendant.<em> If Integer, the Element indexed by that number will be
- # removed.
- # Returns:: the element that was removed.
- # doc.delete_element "/a/b/c[@id='4']"
- # doc.delete_element doc.elements["//k"]
- # doc.delete_element 1
- def delete_element element
- @elements.delete element
- end
-
- # Evaluates to +true+ if this element has at least one child Element
- # doc = Document.new "<a><b/><c>Text</c></a>"
- # doc.root.has_elements # -> true
- # doc.elements["/a/b"].has_elements # -> false
- # doc.elements["/a/c"].has_elements # -> false
- def has_elements?
- !@elements.empty?
- end
-
- # Iterates through the child elements, yielding for each Element that
- # has a particular attribute set.
- # key::
- # the name of the attribute to search for
- # value::
- # the value of the attribute
- # max::
- # (optional) causes this method to return after yielding
- # for this number of matching children
- # name::
- # (optional) if supplied, this is an XPath that filters
- # the children to check.
- #
- # doc = Document.new "<a><b @id='1'/><c @id='2'/><d @id='1'/><e/></a>"
- # # Yields b, c, d
- # doc.root.each_element_with_attribute( 'id' ) {|e| p e}
- # # Yields b, d
- # doc.root.each_element_with_attribute( 'id', '1' ) {|e| p e}
- # # Yields b
- # doc.root.each_element_with_attribute( 'id', '1', 1 ) {|e| p e}
- # # Yields d
- # doc.root.each_element_with_attribute( 'id', '1', 0, 'd' ) {|e| p e}
- def each_element_with_attribute( key, value=nil, max=0, name=nil, &block ) # :yields: Element
- each_with_something( proc {|child|
- if value.nil?
- child.attributes[key] != nil
- else
- child.attributes[key]==value
- end
- }, max, name, &block )
- end
-
- # Iterates through the children, yielding for each Element that
- # has a particular text set.
- # text::
- # the text to search for. If nil, or not supplied, will iterate
- # over all +Element+ children that contain at least one +Text+ node.
- # max::
- # (optional) causes this method to return after yielding
- # for this number of matching children
- # name::
- # (optional) if supplied, this is an XPath that filters
- # the children to check.
- #
- # doc = Document.new '<a><b>b</b><c>b</c><d>d</d><e/></a>'
- # # Yields b, c, d
- # doc.each_element_with_text {|e|p e}
- # # Yields b, c
- # doc.each_element_with_text('b'){|e|p e}
- # # Yields b
- # doc.each_element_with_text('b', 1){|e|p e}
- # # Yields d
- # doc.each_element_with_text(nil, 0, 'd'){|e|p e}
- def each_element_with_text( text=nil, max=0, name=nil, &block ) # :yields: Element
- each_with_something( proc {|child|
- if text.nil?
- child.has_text?
- else
- child.text == text
- end
- }, max, name, &block )
- end
-
- # Synonym for Element.elements.each
- def each_element( xpath=nil, &block ) # :yields: Element
- @elements.each( xpath, &block )
- end
-
- # Synonym for Element.to_a
- # This is a little slower than calling elements.each directly.
- # xpath:: any XPath by which to search for elements in the tree
- # Returns:: an array of Elements that match the supplied path
- def get_elements( xpath )
- @elements.to_a( xpath )
- end
-
- # Returns the next sibling that is an element, or nil if there is
- # no Element sibling after this one
- # doc = Document.new '<a><b/>text<c/></a>'
- # doc.root.elements['b'].next_element #-> <c/>
- # doc.root.elements['c'].next_element #-> nil
- def next_element
- element = next_sibling
- element = element.next_sibling until element.nil? or element.kind_of? Element
- return element
- end
-
- # Returns the previous sibling that is an element, or nil if there is
- # no Element sibling prior to this one
- # doc = Document.new '<a><b/>text<c/></a>'
- # doc.root.elements['c'].previous_element #-> <b/>
- # doc.root.elements['b'].previous_element #-> nil
- def previous_element
- element = previous_sibling
- element = element.previous_sibling until element.nil? or element.kind_of? Element
- return element
- end
-
-
- #################################################
- # Text #
- #################################################
-
- # Evaluates to +true+ if this element has at least one Text child
- def has_text?
- not text().nil?
- end
-
- # A convenience method which returns the String value of the _first_
- # child text element, if one exists, and +nil+ otherwise.
- #
- # <em>Note that an element may have multiple Text elements, perhaps
- # separated by other children</em>. Be aware that this method only returns
- # the first Text node.
- #
- # This method returns the +value+ of the first text child node, which
- # ignores the +raw+ setting, so always returns normalized text. See
- # the Text::value documentation.
- #
- # doc = Document.new "<p>some text <b>this is bold!</b> more text</p>"
- # # The element 'p' has two text elements, "some text " and " more text".
- # doc.root.text #-> "some text "
- def text( path = nil )
- rv = get_text(path)
- return rv.value unless rv.nil?
- nil
- end
-
- # Returns the first child Text node, if any, or +nil+ otherwise.
- # This method returns the actual +Text+ node, rather than the String content.
- # doc = Document.new "<p>some text <b>this is bold!</b> more text</p>"
- # # The element 'p' has two text elements, "some text " and " more text".
- # doc.root.get_text.value #-> "some text "
- def get_text path = nil
- rv = nil
- if path
- element = @elements[ path ]
- rv = element.get_text unless element.nil?
- else
- rv = @children.find { |node| node.kind_of? Text }
- end
- return rv
- end
-
- # Sets the first Text child of this object. See text() for a
- # discussion about Text children.
- #
- # If a Text child already exists, the child is replaced by this
- # content. This means that Text content can be deleted by calling
- # this method with a nil argument. In this case, the next Text
- # child becomes the first Text child. In no case is the order of
- # any siblings disturbed.
- # text::
- # If a String, a new Text child is created and added to
- # this Element as the first Text child. If Text, the text is set
- # as the first Child element. If nil, then any existing first Text
- # child is removed.
- # Returns:: this Element.
- # doc = Document.new '<a><b/></a>'
- # doc.root.text = 'Sean' #-> '<a><b/>Sean</a>'
- # doc.root.text = 'Elliott' #-> '<a><b/>Elliott</a>'
- # doc.root.add_element 'c' #-> '<a><b/>Elliott<c/></a>'
- # doc.root.text = 'Russell' #-> '<a><b/>Russell<c/></a>'
- # doc.root.text = nil #-> '<a><b/><c/></a>'
- def text=( text )
- if text.kind_of? String
- text = Text.new( text, whitespace(), nil, raw() )
- elsif !text.nil? and !text.kind_of? Text
- text = Text.new( text.to_s, whitespace(), nil, raw() )
- end
- old_text = get_text
- if text.nil?
- old_text.remove unless old_text.nil?
- else
- if old_text.nil?
- self << text
- else
- old_text.replace_with( text )
- end
- end
- return self
- end
-
- # A helper method to add a Text child. Actual Text instances can
- # be added with regular Parent methods, such as add() and <<()
- # text::
- # if a String, a new Text instance is created and added
- # to the parent. If Text, the object is added directly.
- # Returns:: this Element
- # e = Element.new('a') #-> <e/>
- # e.add_text 'foo' #-> <e>foo</e>
- # e.add_text Text.new(' bar') #-> <e>foo bar</e>
- # Note that at the end of this example, the branch has <b>3</b> nodes; the 'e'
- # element and <b>2</b> Text node children.
- def add_text( text )
- if text.kind_of? String
- if @children[-1].kind_of? Text
- @children[-1] << text
- return
- end
- text = Text.new( text, whitespace(), nil, raw() )
- end
- self << text unless text.nil?
- return self
- end
-
- def node_type
- :element
- end
-
- def xpath
- path_elements = []
- cur = self
- path_elements << __to_xpath_helper( self )
- while cur.parent
- cur = cur.parent
- path_elements << __to_xpath_helper( cur )
- end
- return path_elements.reverse.join( "/" )
- end
-
- #################################################
- # Attributes #
- #################################################
-
- def attribute( name, namespace=nil )
- prefix = nil
- if namespaces.respond_to? :key
- prefix = namespaces.key(namespace) if namespace
- else
- prefix = namespaces.index(namespace) if namespace
- end
- prefix = nil if prefix == 'xmlns'
-
- ret_val =
- attributes.get_attribute( "#{prefix ? prefix + ':' : ''}#{name}" )
-
- return ret_val unless ret_val.nil?
- return nil if prefix.nil?
-
- # now check that prefix'es namespace is not the same as the
- # default namespace
- return nil unless ( namespaces[ prefix ] == namespaces[ 'xmlns' ] )
-
- attributes.get_attribute( name )
-
- end
-
- # Evaluates to +true+ if this element has any attributes set, false
- # otherwise.
- def has_attributes?
- return !@attributes.empty?
- end
-
- # Adds an attribute to this element, overwriting any existing attribute
- # by the same name.
- # key::
- # can be either an Attribute or a String. If an Attribute,
- # the attribute is added to the list of Element attributes. If String,
- # the argument is used as the name of the new attribute, and the value
- # parameter must be supplied.
- # value::
- # Required if +key+ is a String, and ignored if the first argument is
- # an Attribute. This is a String, and is used as the value
- # of the new Attribute. This should be the unnormalized value of the
- # attribute (without entities).
- # Returns:: the Attribute added
- # e = Element.new 'e'
- # e.add_attribute( 'a', 'b' ) #-> <e a='b'/>
- # e.add_attribute( 'x:a', 'c' ) #-> <e a='b' x:a='c'/>
- # e.add_attribute Attribute.new('b', 'd') #-> <e a='b' x:a='c' b='d'/>
- def add_attribute( key, value=nil )
- if key.kind_of? Attribute
- @attributes << key
- else
- @attributes[key] = value
- end
- end
-
- # Add multiple attributes to this element.
- # hash:: is either a hash, or array of arrays
- # el.add_attributes( {"name1"=>"value1", "name2"=>"value2"} )
- # el.add_attributes( [ ["name1","value1"], ["name2"=>"value2"] ] )
- def add_attributes hash
- if hash.kind_of? Hash
- hash.each_pair {|key, value| @attributes[key] = value }
- elsif hash.kind_of? Array
- hash.each { |value| @attributes[ value[0] ] = value[1] }
- end
- end
-
- # Removes an attribute
- # key::
- # either an Attribute or a String. In either case, the
- # attribute is found by matching the attribute name to the argument,
- # and then removed. If no attribute is found, no action is taken.
- # Returns::
- # the attribute removed, or nil if this Element did not contain
- # a matching attribute
- # e = Element.new('E')
- # e.add_attribute( 'name', 'Sean' ) #-> <E name='Sean'/>
- # r = e.add_attribute( 'sur:name', 'Russell' ) #-> <E name='Sean' sur:name='Russell'/>
- # e.delete_attribute( 'name' ) #-> <E sur:name='Russell'/>
- # e.delete_attribute( r ) #-> <E/>
- def delete_attribute(key)
- attr = @attributes.get_attribute(key)
- attr.remove unless attr.nil?
- end
-
- #################################################
- # Other Utilities #
- #################################################
-
- # Get an array of all CData children.
- # IMMUTABLE
- def cdatas
- find_all { |child| child.kind_of? CData }.freeze
- end
-
- # Get an array of all Comment children.
- # IMMUTABLE
- def comments
- find_all { |child| child.kind_of? Comment }.freeze
- end
-
- # Get an array of all Instruction children.
- # IMMUTABLE
- def instructions
- find_all { |child| child.kind_of? Instruction }.freeze
- end
-
- # Get an array of all Text children.
- # IMMUTABLE
- def texts
- find_all { |child| child.kind_of? Text }.freeze
- end
-
- # == DEPRECATED
- # See REXML::Formatters
- #
- # Writes out this element, and recursively, all children.
- # output::
- # output an object which supports '<< string'; this is where the
- # document will be written.
- # indent::
- # An integer. If -1, no indenting will be used; otherwise, the
- # indentation will be this number of spaces, and children will be
- # indented an additional amount. Defaults to -1
- # transitive::
- # If transitive is true and indent is >= 0, then the output will be
- # pretty-printed in such a way that the added whitespace does not affect
- # the parse tree of the document
- # ie_hack::
- # This hack inserts a space before the /> on empty tags to address
- # a limitation of Internet Explorer. Defaults to false
- #
- # out = ''
- # doc.write( out ) #-> doc is written to the string 'out'
- # doc.write( $stdout ) #-> doc written to the console
- def write(output=$stdout, indent=-1, transitive=false, ie_hack=false)
- Kernel.warn("#{self.class.name}.write is deprecated. See REXML::Formatters")
- formatter = if indent > -1
- if transitive
- require "rexml/formatters/transitive"
- REXML::Formatters::Transitive.new( indent, ie_hack )
- else
- REXML::Formatters::Pretty.new( indent, ie_hack )
- end
- else
- REXML::Formatters::Default.new( ie_hack )
- end
- formatter.write( self, output )
- end
-
-
- private
- def __to_xpath_helper node
- rv = node.expanded_name.clone
- if node.parent
- results = node.parent.find_all {|n|
- n.kind_of?(REXML::Element) and n.expanded_name == node.expanded_name
- }
- if results.length > 1
- idx = results.index( node )
- rv << "[#{idx+1}]"
- end
- end
- rv
- end
-
- # A private helper method
- def each_with_something( test, max=0, name=nil )
- num = 0
- @elements.each( name ){ |child|
- yield child if test.call(child) and num += 1
- return if max>0 and num == max
- }
- end
- end
-
- ########################################################################
- # ELEMENTS #
- ########################################################################
-
- # A class which provides filtering of children for Elements, and
- # XPath search support. You are expected to only encounter this class as
- # the <tt>element.elements</tt> object. Therefore, you are
- # _not_ expected to instantiate this yourself.
- class Elements
- include Enumerable
- # Constructor
- # parent:: the parent Element
- def initialize parent
- @element = parent
- end
-
- # Fetches a child element. Filters only Element children, regardless of
- # the XPath match.
- # index::
- # the search parameter. This is either an Integer, which
- # will be used to find the index'th child Element, or an XPath,
- # which will be used to search for the Element. <em>Because
- # of the nature of XPath searches, any element in the connected XML
- # document can be fetched through any other element.</em> <b>The
- # Integer index is 1-based, not 0-based.</b> This means that the first
- # child element is at index 1, not 0, and the +n+th element is at index
- # +n+, not <tt>n-1</tt>. This is because XPath indexes element children
- # starting from 1, not 0, and the indexes should be the same.
- # name::
- # optional, and only used in the first argument is an
- # Integer. In that case, the index'th child Element that has the
- # supplied name will be returned. Note again that the indexes start at 1.
- # Returns:: the first matching Element, or nil if no child matched
- # doc = Document.new '<a><b/><c id="1"/><c id="2"/><d/></a>'
- # doc.root.elements[1] #-> <b/>
- # doc.root.elements['c'] #-> <c id="1"/>
- # doc.root.elements[2,'c'] #-> <c id="2"/>
- def []( index, name=nil)
- if index.kind_of? Integer
- raise "index (#{index}) must be >= 1" if index < 1
- name = literalize(name) if name
- num = 0
- @element.find { |child|
- child.kind_of? Element and
- (name.nil? ? true : child.has_name?( name )) and
- (num += 1) == index
- }
- else
- return XPath::first( @element, index )
- #{ |element|
- # return element if element.kind_of? Element
- #}
- #return nil
- end
- end
-
- # Sets an element, replacing any previous matching element. If no
- # existing element is found ,the element is added.
- # index:: Used to find a matching element to replace. See []().
- # element::
- # The element to replace the existing element with
- # the previous element
- # Returns:: nil if no previous element was found.
- #
- # doc = Document.new '<a/>'
- # doc.root.elements[10] = Element.new('b') #-> <a><b/></a>
- # doc.root.elements[1] #-> <b/>
- # doc.root.elements[1] = Element.new('c') #-> <a><c/></a>
- # doc.root.elements['c'] = Element.new('d') #-> <a><d/></a>
- def []=( index, element )
- previous = self[index]
- if previous.nil?
- @element.add element
- else
- previous.replace_with element
- end
- return previous
- end
-
- # Returns +true+ if there are no +Element+ children, +false+ otherwise
- def empty?
- @element.find{ |child| child.kind_of? Element}.nil?
- end
-
- # Returns the index of the supplied child (starting at 1), or -1 if
- # the element is not a child
- # element:: an +Element+ child
- def index element
- rv = 0
- found = @element.find do |child|
- child.kind_of? Element and
- (rv += 1) and
- child == element
- end
- return rv if found == element
- return -1
- end
-
- # Deletes a child Element
- # element::
- # Either an Element, which is removed directly; an
- # xpath, where the first matching child is removed; or an Integer,
- # where the n'th Element is removed.
- # Returns:: the removed child
- # doc = Document.new '<a><b/><c/><c id="1"/></a>'
- # b = doc.root.elements[1]
- # doc.root.elements.delete b #-> <a><c/><c id="1"/></a>
- # doc.elements.delete("a/c[@id='1']") #-> <a><c/></a>
- # doc.root.elements.delete 1 #-> <a/>
- def delete element
- if element.kind_of? Element
- @element.delete element
- else
- el = self[element]
- el.remove if el
- end
- end
-
- # Removes multiple elements. Filters for Element children, regardless of
- # XPath matching.
- # xpath:: all elements matching this String path are removed.
- # Returns:: an Array of Elements that have been removed
- # doc = Document.new '<a><c/><c/><c/><c/></a>'
- # deleted = doc.elements.delete_all 'a/c' #-> [<c/>, <c/>, <c/>, <c/>]
- def delete_all( xpath )
- rv = []
- XPath::each( @element, xpath) {|element|
- rv << element if element.kind_of? Element
- }
- rv.each do |element|
- @element.delete element
- element.remove
- end
- return rv
- end
-
- # Adds an element
- # element::
- # if supplied, is either an Element, String, or
- # Source (see Element.initialize). If not supplied or nil, a
- # new, default Element will be constructed
- # Returns:: the added Element
- # a = Element.new('a')
- # a.elements.add(Element.new('b')) #-> <a><b/></a>
- # a.elements.add('c') #-> <a><b/><c/></a>
- def add element=nil
- if element.nil?
- Element.new("", self, @element.context)
- elsif not element.kind_of?(Element)
- Element.new(element, self, @element.context)
- else
- @element << element
- element.context = @element.context
- element
- end
- end
-
- alias :<< :add
-
- # Iterates through all of the child Elements, optionally filtering
- # them by a given XPath
- # xpath::
- # optional. If supplied, this is a String XPath, and is used to
- # filter the children, so that only matching children are yielded. Note
- # that XPaths are automatically filtered for Elements, so that
- # non-Element children will not be yielded
- # doc = Document.new '<a><b/><c/><d/>sean<b/><c/><d/></a>'
- # doc.root.elements.each {|e|p e} #-> Yields b, c, d, b, c, d elements
- # doc.root.elements.each('b') {|e|p e} #-> Yields b, b elements
- # doc.root.elements.each('child::node()') {|e|p e}
- # #-> Yields <b/>, <c/>, <d/>, <b/>, <c/>, <d/>
- # XPath.each(doc.root, 'child::node()', &block)
- # #-> Yields <b/>, <c/>, <d/>, sean, <b/>, <c/>, <d/>
- def each( xpath=nil )
- XPath::each( @element, xpath ) {|e| yield e if e.kind_of? Element }
- end
-
- def collect( xpath=nil )
- collection = []
- XPath::each( @element, xpath ) {|e|
- collection << yield(e) if e.kind_of?(Element)
- }
- collection
- end
-
- def inject( xpath=nil, initial=nil )
- first = true
- XPath::each( @element, xpath ) {|e|
- if (e.kind_of? Element)
- if (first and initial == nil)
- initial = e
- first = false
- else
- initial = yield( initial, e ) if e.kind_of? Element
- end
- end
- }
- initial
- end
-
- # Returns the number of +Element+ children of the parent object.
- # doc = Document.new '<a>sean<b/>elliott<b/>russell<b/></a>'
- # doc.root.size #-> 6, 3 element and 3 text nodes
- # doc.root.elements.size #-> 3
- def size
- count = 0
- @element.each {|child| count+=1 if child.kind_of? Element }
- count
- end
-
- # Returns an Array of Element children. An XPath may be supplied to
- # filter the children. Only Element children are returned, even if the
- # supplied XPath matches non-Element children.
- # doc = Document.new '<a>sean<b/>elliott<c/></a>'
- # doc.root.elements.to_a #-> [ <b/>, <c/> ]
- # doc.root.elements.to_a("child::node()") #-> [ <b/>, <c/> ]
- # XPath.match(doc.root, "child::node()") #-> [ sean, <b/>, elliott, <c/> ]
- def to_a( xpath=nil )
- rv = XPath.match( @element, xpath )
- return rv.find_all{|e| e.kind_of? Element} if xpath
- rv
- end
-
- private
- # Private helper class. Removes quotes from quoted strings
- def literalize name
- name = name[1..-2] if name[0] == ?' or name[0] == ?" #'
- name
- end
- end
-
- ########################################################################
- # ATTRIBUTES #
- ########################################################################
-
- # A class that defines the set of Attributes of an Element and provides
- # operations for accessing elements in that set.
- class Attributes < Hash
- # Constructor
- # element:: the Element of which this is an Attribute
- def initialize element
- @element = element
- end
-
- # Fetches an attribute value. If you want to get the Attribute itself,
- # use get_attribute()
- # name:: an XPath attribute name. Namespaces are relevant here.
- # Returns::
- # the String value of the matching attribute, or +nil+ if no
- # matching attribute was found. This is the unnormalized value
- # (with entities expanded).
- #
- # doc = Document.new "<a foo:att='1' bar:att='2' att='&lt;'/>"
- # doc.root.attributes['att'] #-> '<'
- # doc.root.attributes['bar:att'] #-> '2'
- def [](name)
- attr = get_attribute(name)
- return attr.value unless attr.nil?
- return nil
- end
-
- def to_a
- enum_for(:each_attribute).to_a
- end
-
- # Returns the number of attributes the owning Element contains.
- # doc = Document "<a x='1' y='2' foo:x='3'/>"
- # doc.root.attributes.length #-> 3
- def length
- c = 0
- each_attribute { c+=1 }
- c
- end
- alias :size :length
-
- # Iterates over the attributes of an Element. Yields actual Attribute
- # nodes, not String values.
- #
- # doc = Document.new '<a x="1" y="2"/>'
- # doc.root.attributes.each_attribute {|attr|
- # p attr.expanded_name+" => "+attr.value
- # }
- def each_attribute # :yields: attribute
- each_value do |val|
- if val.kind_of? Attribute
- yield val
- else
- val.each_value { |atr| yield atr }
- end
- end
- end
-
- # Iterates over each attribute of an Element, yielding the expanded name
- # and value as a pair of Strings.
- #
- # doc = Document.new '<a x="1" y="2"/>'
- # doc.root.attributes.each {|name, value| p name+" => "+value }
- def each
- each_attribute do |attr|
- yield [attr.expanded_name, attr.value]
- end
- end
-
- # Fetches an attribute
- # name::
- # the name by which to search for the attribute. Can be a
- # <tt>prefix:name</tt> namespace name.
- # Returns:: The first matching attribute, or nil if there was none. This
- # value is an Attribute node, not the String value of the attribute.
- # doc = Document.new '<a x:foo="1" foo="2" bar="3"/>'
- # doc.root.attributes.get_attribute("foo").value #-> "2"
- # doc.root.attributes.get_attribute("x:foo").value #-> "1"
- def get_attribute( name )
- attr = fetch( name, nil )
- if attr.nil?
- return nil if name.nil?
- # Look for prefix
- name =~ Namespace::NAMESPLIT
- prefix, n = $1, $2
- if prefix
- attr = fetch( n, nil )
- # check prefix
- if attr == nil
- elsif attr.kind_of? Attribute
- return attr if prefix == attr.prefix
- else
- attr = attr[ prefix ]
- return attr
- end
- end
- element_document = @element.document
- if element_document and element_document.doctype
- expn = @element.expanded_name
- expn = element_document.doctype.name if expn.size == 0
- attr_val = element_document.doctype.attribute_of(expn, name)
- return Attribute.new( name, attr_val ) if attr_val
- end
- return nil
- end
- if attr.kind_of? Hash
- attr = attr[ @element.prefix ]
- end
- return attr
- end
-
- # Sets an attribute, overwriting any existing attribute value by the
- # same name. Namespace is significant.
- # name:: the name of the attribute
- # value::
- # (optional) If supplied, the value of the attribute. If
- # nil, any existing matching attribute is deleted.
- # Returns::
- # Owning element
- # doc = Document.new "<a x:foo='1' foo='3'/>"
- # doc.root.attributes['y:foo'] = '2'
- # doc.root.attributes['foo'] = '4'
- # doc.root.attributes['x:foo'] = nil
- def []=( name, value )
- if value.nil? # Delete the named attribute
- attr = get_attribute(name)
- delete attr
- return
- end
-
- unless value.kind_of? Attribute
- if @element.document and @element.document.doctype
- value = Text::normalize( value, @element.document.doctype )
- else
- value = Text::normalize( value, nil )
- end
- value = Attribute.new(name, value)
- end
- value.element = @element
- old_attr = fetch(value.name, nil)
- if old_attr.nil?
- store(value.name, value)
- elsif old_attr.kind_of? Hash
- old_attr[value.prefix] = value
- elsif old_attr.prefix != value.prefix
- # Check for conflicting namespaces
- raise ParseException.new(
- "Namespace conflict in adding attribute \"#{value.name}\": "+
- "Prefix \"#{old_attr.prefix}\" = "+
- "\"#{@element.namespace(old_attr.prefix)}\" and prefix "+
- "\"#{value.prefix}\" = \"#{@element.namespace(value.prefix)}\"") if
- value.prefix != "xmlns" and old_attr.prefix != "xmlns" and
- @element.namespace( old_attr.prefix ) ==
- @element.namespace( value.prefix )
- store value.name, { old_attr.prefix => old_attr,
- value.prefix => value }
- else
- store value.name, value
- end
- return @element
- end
-
- # Returns an array of Strings containing all of the prefixes declared
- # by this set of # attributes. The array does not include the default
- # namespace declaration, if one exists.
- # doc = Document.new("<a xmlns='foo' xmlns:x='bar' xmlns:y='twee' "+
- # "z='glorp' p:k='gru'/>")
- # prefixes = doc.root.attributes.prefixes #-> ['x', 'y']
- def prefixes
- ns = []
- each_attribute do |attribute|
- ns << attribute.name if attribute.prefix == 'xmlns'
- end
- if @element.document and @element.document.doctype
- expn = @element.expanded_name
- expn = @element.document.doctype.name if expn.size == 0
- @element.document.doctype.attributes_of(expn).each {
- |attribute|
- ns << attribute.name if attribute.prefix == 'xmlns'
- }
- end
- ns
- end
-
- def namespaces
- namespaces = {}
- each_attribute do |attribute|
- namespaces[attribute.name] = attribute.value if attribute.prefix == 'xmlns' or attribute.name == 'xmlns'
- end
- if @element.document and @element.document.doctype
- expn = @element.expanded_name
- expn = @element.document.doctype.name if expn.size == 0
- @element.document.doctype.attributes_of(expn).each {
- |attribute|
- namespaces[attribute.name] = attribute.value if attribute.prefix == 'xmlns' or attribute.name == 'xmlns'
- }
- end
- namespaces
- end
-
- # Removes an attribute
- # attribute::
- # either a String, which is the name of the attribute to remove --
- # namespaces are significant here -- or the attribute to remove.
- # Returns:: the owning element
- # doc = Document.new "<a y:foo='0' x:foo='1' foo='3' z:foo='4'/>"
- # doc.root.attributes.delete 'foo' #-> <a y:foo='0' x:foo='1' z:foo='4'/>"
- # doc.root.attributes.delete 'x:foo' #-> <a y:foo='0' z:foo='4'/>"
- # attr = doc.root.attributes.get_attribute('y:foo')
- # doc.root.attributes.delete attr #-> <a z:foo='4'/>"
- def delete( attribute )
- name = nil
- prefix = nil
- if attribute.kind_of? Attribute
- name = attribute.name
- prefix = attribute.prefix
- else
- attribute =~ Namespace::NAMESPLIT
- prefix, name = $1, $2
- prefix = '' unless prefix
- end
- old = fetch(name, nil)
- if old.kind_of? Hash # the supplied attribute is one of many
- old.delete(prefix)
- if old.size == 1
- repl = nil
- old.each_value{|v| repl = v}
- store name, repl
- end
- elsif old.nil?
- return @element
- else # the supplied attribute is a top-level one
- super(name)
- end
- @element
- end
-
- # Adds an attribute, overriding any existing attribute by the
- # same name. Namespaces are significant.
- # attribute:: An Attribute
- def add( attribute )
- self[attribute.name] = attribute
- end
-
- alias :<< :add
-
- # Deletes all attributes matching a name. Namespaces are significant.
- # name::
- # A String; all attributes that match this path will be removed
- # Returns:: an Array of the Attributes that were removed
- def delete_all( name )
- rv = []
- each_attribute { |attribute|
- rv << attribute if attribute.expanded_name == name
- }
- rv.each{ |attr| attr.remove }
- return rv
- end
-
- # The +get_attribute_ns+ method retrieves a method by its namespace
- # and name. Thus it is possible to reliably identify an attribute
- # even if an XML processor has changed the prefix.
- #
- # Method contributed by Henrik Martensson
- def get_attribute_ns(namespace, name)
- result = nil
- each_attribute() { |attribute|
- if name == attribute.name &&
- namespace == attribute.namespace() &&
- ( !namespace.empty? || !attribute.fully_expanded_name.index(':') )
- # foo will match xmlns:foo, but only if foo isn't also an attribute
- result = attribute if !result or !namespace.empty? or
- !attribute.fully_expanded_name.index(':')
- end
- }
- result
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/encoding.rb b/ruby_2_2/lib/rexml/encoding.rb
deleted file mode 100644
index 1c7e79a124..0000000000
--- a/ruby_2_2/lib/rexml/encoding.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-# coding: US-ASCII
-module REXML
- module Encoding
- # ID ---> Encoding name
- attr_reader :encoding
- def encoding=(encoding)
- encoding = encoding.name if encoding.is_a?(Encoding)
- if encoding.is_a?(String)
- original_encoding = encoding
- encoding = find_encoding(encoding)
- unless encoding
- raise ArgumentError, "Bad encoding name #{original_encoding}"
- end
- end
- return false if defined?(@encoding) and encoding == @encoding
- if encoding
- @encoding = encoding.upcase
- else
- @encoding = 'UTF-8'
- end
- true
- end
-
- def encode(string)
- string.encode(@encoding)
- end
-
- def decode(string)
- string.encode(::Encoding::UTF_8, @encoding)
- end
-
- private
- def find_encoding(name)
- case name
- when /\Ashift-jis\z/i
- return "SHIFT_JIS"
- when /\ACP-(\d+)\z/
- name = "CP#{$1}"
- when /\AUTF-8\z/i
- return name
- end
- begin
- ::Encoding::Converter.search_convpath(name, 'UTF-8')
- rescue ::Encoding::ConverterNotFoundError
- return nil
- end
- name
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/entity.rb b/ruby_2_2/lib/rexml/entity.rb
deleted file mode 100644
index 3a35ec6b94..0000000000
--- a/ruby_2_2/lib/rexml/entity.rb
+++ /dev/null
@@ -1,173 +0,0 @@
-require 'rexml/child'
-require 'rexml/source'
-require 'rexml/xmltokens'
-
-module REXML
- # God, I hate DTDs. I really do. Why this idiot standard still
- # plagues us is beyond me.
- class Entity < Child
- include XMLTokens
- PUBIDCHAR = "\x20\x0D\x0Aa-zA-Z0-9\\-()+,./:=?;!*@$_%#"
- SYSTEMLITERAL = %Q{((?:"[^"]*")|(?:'[^']*'))}
- PUBIDLITERAL = %Q{("[#{PUBIDCHAR}']*"|'[#{PUBIDCHAR}]*')}
- EXTERNALID = "(?:(?:(SYSTEM)\\s+#{SYSTEMLITERAL})|(?:(PUBLIC)\\s+#{PUBIDLITERAL}\\s+#{SYSTEMLITERAL}))"
- NDATADECL = "\\s+NDATA\\s+#{NAME}"
- PEREFERENCE = "%#{NAME};"
- ENTITYVALUE = %Q{((?:"(?:[^%&"]|#{PEREFERENCE}|#{REFERENCE})*")|(?:'([^%&']|#{PEREFERENCE}|#{REFERENCE})*'))}
- PEDEF = "(?:#{ENTITYVALUE}|#{EXTERNALID})"
- ENTITYDEF = "(?:#{ENTITYVALUE}|(?:#{EXTERNALID}(#{NDATADECL})?))"
- PEDECL = "<!ENTITY\\s+(%)\\s+#{NAME}\\s+#{PEDEF}\\s*>"
- GEDECL = "<!ENTITY\\s+#{NAME}\\s+#{ENTITYDEF}\\s*>"
- ENTITYDECL = /\s*(?:#{GEDECL})|(?:#{PEDECL})/um
-
- attr_reader :name, :external, :ref, :ndata, :pubid
-
- # Create a new entity. Simple entities can be constructed by passing a
- # name, value to the constructor; this creates a generic, plain entity
- # reference. For anything more complicated, you have to pass a Source to
- # the constructor with the entity definition, or use the accessor methods.
- # +WARNING+: There is no validation of entity state except when the entity
- # is read from a stream. If you start poking around with the accessors,
- # you can easily create a non-conformant Entity. The best thing to do is
- # dump the stupid DTDs and use XMLSchema instead.
- #
- # e = Entity.new( 'amp', '&' )
- def initialize stream, value=nil, parent=nil, reference=false
- super(parent)
- @ndata = @pubid = @value = @external = nil
- if stream.kind_of? Array
- @name = stream[1]
- if stream[-1] == '%'
- @reference = true
- stream.pop
- else
- @reference = false
- end
- if stream[2] =~ /SYSTEM|PUBLIC/
- @external = stream[2]
- if @external == 'SYSTEM'
- @ref = stream[3]
- @ndata = stream[4] if stream.size == 5
- else
- @pubid = stream[3]
- @ref = stream[4]
- end
- else
- @value = stream[2]
- end
- else
- @reference = reference
- @external = nil
- @name = stream
- @value = value
- end
- end
-
- # Evaluates whether the given string matches an entity definition,
- # returning true if so, and false otherwise.
- def Entity::matches? string
- (ENTITYDECL =~ string) == 0
- end
-
- # Evaluates to the unnormalized value of this entity; that is, replacing
- # all entities -- both %ent; and &ent; entities. This differs from
- # +value()+ in that +value+ only replaces %ent; entities.
- def unnormalized
- document.record_entity_expansion unless document.nil?
- v = value()
- return nil if v.nil?
- @unnormalized = Text::unnormalize(v, parent)
- @unnormalized
- end
-
- #once :unnormalized
-
- # Returns the value of this entity unprocessed -- raw. This is the
- # normalized value; that is, with all %ent; and &ent; entities intact
- def normalized
- @value
- end
-
- # Write out a fully formed, correct entity definition (assuming the Entity
- # object itself is valid.)
- #
- # out::
- # An object implementing <TT>&lt;&lt;<TT> to which the entity will be
- # output
- # indent::
- # *DEPRECATED* and ignored
- def write out, indent=-1
- out << '<!ENTITY '
- out << '% ' if @reference
- out << @name
- out << ' '
- if @external
- out << @external << ' '
- if @pubid
- q = @pubid.include?('"')?"'":'"'
- out << q << @pubid << q << ' '
- end
- q = @ref.include?('"')?"'":'"'
- out << q << @ref << q
- out << ' NDATA ' << @ndata if @ndata
- else
- q = @value.include?('"')?"'":'"'
- out << q << @value << q
- end
- out << '>'
- end
-
- # Returns this entity as a string. See write().
- def to_s
- rv = ''
- write rv
- rv
- end
-
- PEREFERENCE_RE = /#{PEREFERENCE}/um
- # Returns the value of this entity. At the moment, only internal entities
- # are processed. If the value contains internal references (IE,
- # %blah;), those are replaced with their values. IE, if the doctype
- # contains:
- # <!ENTITY % foo "bar">
- # <!ENTITY yada "nanoo %foo; nanoo>
- # then:
- # doctype.entity('yada').value #-> "nanoo bar nanoo"
- def value
- if @value
- matches = @value.scan(PEREFERENCE_RE)
- rv = @value.clone
- if @parent
- sum = 0
- matches.each do |entity_reference|
- entity_value = @parent.entity( entity_reference[0] )
- if sum + entity_value.bytesize > Security.entity_expansion_text_limit
- raise "entity expansion has grown too large"
- else
- sum += entity_value.bytesize
- end
- rv.gsub!( /%#{entity_reference.join};/um, entity_value )
- end
- end
- return rv
- end
- nil
- end
- end
-
- # This is a set of entity constants -- the ones defined in the XML
- # specification. These are +gt+, +lt+, +amp+, +quot+ and +apos+.
- # CAUTION: these entities does not have parent and document
- module EntityConst
- # +>+
- GT = Entity.new( 'gt', '>' )
- # +<+
- LT = Entity.new( 'lt', '<' )
- # +&+
- AMP = Entity.new( 'amp', '&' )
- # +"+
- QUOT = Entity.new( 'quot', '"' )
- # +'+
- APOS = Entity.new( 'apos', "'" )
- end
-end
diff --git a/ruby_2_2/lib/rexml/formatters/default.rb b/ruby_2_2/lib/rexml/formatters/default.rb
deleted file mode 100644
index 574c821f96..0000000000
--- a/ruby_2_2/lib/rexml/formatters/default.rb
+++ /dev/null
@@ -1,111 +0,0 @@
-module REXML
- module Formatters
- class Default
- # Prints out the XML document with no formatting -- except if id_hack is
- # set.
- #
- # ie_hack::
- # If set to true, then inserts whitespace before the close of an empty
- # tag, so that IE's bad XML parser doesn't choke.
- def initialize( ie_hack=false )
- @ie_hack = ie_hack
- end
-
- # Writes the node to some output.
- #
- # node::
- # The node to write
- # output::
- # A class implementing <TT>&lt;&lt;</TT>. Pass in an Output object to
- # change the output encoding.
- def write( node, output )
- case node
-
- when Document
- if node.xml_decl.encoding != 'UTF-8' && !output.kind_of?(Output)
- output = Output.new( output, node.xml_decl.encoding )
- end
- write_document( node, output )
-
- when Element
- write_element( node, output )
-
- when Declaration, ElementDecl, NotationDecl, ExternalEntity, Entity,
- Attribute, AttlistDecl
- node.write( output,-1 )
-
- when Instruction
- write_instruction( node, output )
-
- when DocType, XMLDecl
- node.write( output )
-
- when Comment
- write_comment( node, output )
-
- when CData
- write_cdata( node, output )
-
- when Text
- write_text( node, output )
-
- else
- raise Exception.new("XML FORMATTING ERROR")
-
- end
- end
-
- protected
- def write_document( node, output )
- node.children.each { |child| write( child, output ) }
- end
-
- def write_element( node, output )
- output << "<#{node.expanded_name}"
-
- node.attributes.to_a.map { |a|
- Hash === a ? a.values : a
- }.flatten.sort_by {|attr| attr.name}.each do |attr|
- output << " "
- attr.write( output )
- end unless node.attributes.empty?
-
- if node.children.empty?
- output << " " if @ie_hack
- output << "/"
- else
- output << ">"
- node.children.each { |child|
- write( child, output )
- }
- output << "</#{node.expanded_name}"
- end
- output << ">"
- end
-
- def write_text( node, output )
- output << node.to_s()
- end
-
- def write_comment( node, output )
- output << Comment::START
- output << node.to_s
- output << Comment::STOP
- end
-
- def write_cdata( node, output )
- output << CData::START
- output << node.to_s
- output << CData::STOP
- end
-
- def write_instruction( node, output )
- output << Instruction::START.sub(/\\/u, '')
- output << node.target
- output << ' '
- output << node.content
- output << Instruction::STOP.sub(/\\/u, '')
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/formatters/pretty.rb b/ruby_2_2/lib/rexml/formatters/pretty.rb
deleted file mode 100644
index e5ba561a58..0000000000
--- a/ruby_2_2/lib/rexml/formatters/pretty.rb
+++ /dev/null
@@ -1,141 +0,0 @@
-require 'rexml/formatters/default'
-
-module REXML
- module Formatters
- # Pretty-prints an XML document. This destroys whitespace in text nodes
- # and will insert carriage returns and indentations.
- #
- # TODO: Add an option to print attributes on new lines
- class Pretty < Default
-
- # If compact is set to true, then the formatter will attempt to use as
- # little space as possible
- attr_accessor :compact
- # The width of a page. Used for formatting text
- attr_accessor :width
-
- # Create a new pretty printer.
- #
- # output::
- # An object implementing '<<(String)', to which the output will be written.
- # indentation::
- # An integer greater than 0. The indentation of each level will be
- # this number of spaces. If this is < 1, the behavior of this object
- # is undefined. Defaults to 2.
- # ie_hack::
- # If true, the printer will insert whitespace before closing empty
- # tags, thereby allowing Internet Explorer's XML parser to
- # function. Defaults to false.
- def initialize( indentation=2, ie_hack=false )
- @indentation = indentation
- @level = 0
- @ie_hack = ie_hack
- @width = 80
- @compact = false
- end
-
- protected
- def write_element(node, output)
- output << ' '*@level
- output << "<#{node.expanded_name}"
-
- node.attributes.each_attribute do |attr|
- output << " "
- attr.write( output )
- end unless node.attributes.empty?
-
- if node.children.empty?
- if @ie_hack
- output << " "
- end
- output << "/"
- else
- output << ">"
- # If compact and all children are text, and if the formatted output
- # is less than the specified width, then try to print everything on
- # one line
- skip = false
- if compact
- if node.children.inject(true) {|s,c| s & c.kind_of?(Text)}
- string = ""
- old_level = @level
- @level = 0
- node.children.each { |child| write( child, string ) }
- @level = old_level
- if string.length < @width
- output << string
- skip = true
- end
- end
- end
- unless skip
- output << "\n"
- @level += @indentation
- node.children.each { |child|
- next if child.kind_of?(Text) and child.to_s.strip.length == 0
- write( child, output )
- output << "\n"
- }
- @level -= @indentation
- output << ' '*@level
- end
- output << "</#{node.expanded_name}"
- end
- output << ">"
- end
-
- def write_text( node, output )
- s = node.to_s()
- s.gsub!(/\s/,' ')
- s.squeeze!(" ")
- s = wrap(s, @width - @level)
- s = indent_text(s, @level, " ", true)
- output << (' '*@level + s)
- end
-
- def write_comment( node, output)
- output << ' ' * @level
- super
- end
-
- def write_cdata( node, output)
- output << ' ' * @level
- super
- end
-
- def write_document( node, output )
- # Ok, this is a bit odd. All XML documents have an XML declaration,
- # but it may not write itself if the user didn't specifically add it,
- # either through the API or in the input document. If it doesn't write
- # itself, then we don't need a carriage return... which makes this
- # logic more complex.
- node.children.each { |child|
- next if child == node.children[-1] and child.instance_of?(Text)
- unless child == node.children[0] or child.instance_of?(Text) or
- (child == node.children[1] and !node.children[0].writethis)
- output << "\n"
- end
- write( child, output )
- }
- end
-
- private
- def indent_text(string, level=1, style="\t", indentfirstline=true)
- return string if level < 0
- string.gsub(/\n/, "\n#{style*level}")
- end
-
- def wrap(string, width)
- parts = []
- while string.length > width and place = string.rindex(' ', width)
- parts << string[0...place]
- string = string[place+1..-1]
- end
- parts << string
- parts.join("\n")
- end
-
- end
- end
-end
-
diff --git a/ruby_2_2/lib/rexml/formatters/transitive.rb b/ruby_2_2/lib/rexml/formatters/transitive.rb
deleted file mode 100644
index 6cc690d922..0000000000
--- a/ruby_2_2/lib/rexml/formatters/transitive.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-require 'rexml/formatters/pretty'
-
-module REXML
- module Formatters
- # The Transitive formatter writes an XML document that parses to an
- # identical document as the source document. This means that no extra
- # whitespace nodes are inserted, and whitespace within text nodes is
- # preserved. Within these constraints, the document is pretty-printed,
- # with whitespace inserted into the metadata to introduce formatting.
- #
- # Note that this is only useful if the original XML is not already
- # formatted. Since this formatter does not alter whitespace nodes, the
- # results of formatting already formatted XML will be odd.
- class Transitive < Default
- def initialize( indentation=2, ie_hack=false )
- @indentation = indentation
- @level = 0
- @ie_hack = ie_hack
- end
-
- protected
- def write_element( node, output )
- output << "<#{node.expanded_name}"
-
- node.attributes.each_attribute do |attr|
- output << " "
- attr.write( output )
- end unless node.attributes.empty?
-
- output << "\n"
- output << ' '*@level
- if node.children.empty?
- output << " " if @ie_hack
- output << "/"
- else
- output << ">"
- # If compact and all children are text, and if the formatted output
- # is less than the specified width, then try to print everything on
- # one line
- @level += @indentation
- node.children.each { |child|
- write( child, output )
- }
- @level -= @indentation
- output << "</#{node.expanded_name}"
- output << "\n"
- output << ' '*@level
- end
- output << ">"
- end
-
- def write_text( node, output )
- output << node.to_s()
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/functions.rb b/ruby_2_2/lib/rexml/functions.rb
deleted file mode 100644
index 2010be14e0..0000000000
--- a/ruby_2_2/lib/rexml/functions.rb
+++ /dev/null
@@ -1,394 +0,0 @@
-module REXML
- # If you add a method, keep in mind two things:
- # (1) the first argument will always be a list of nodes from which to
- # filter. In the case of context methods (such as position), the function
- # should return an array with a value for each child in the array.
- # (2) all method calls from XML will have "-" replaced with "_".
- # Therefore, in XML, "local-name()" is identical (and actually becomes)
- # "local_name()"
- module Functions
- @@context = nil
- @@namespace_context = {}
- @@variables = {}
-
- def Functions::namespace_context=(x) ; @@namespace_context=x ; end
- def Functions::variables=(x) ; @@variables=x ; end
- def Functions::namespace_context ; @@namespace_context ; end
- def Functions::variables ; @@variables ; end
-
- def Functions::context=(value); @@context = value; end
-
- def Functions::text( )
- if @@context[:node].node_type == :element
- return @@context[:node].find_all{|n| n.node_type == :text}.collect{|n| n.value}
- elsif @@context[:node].node_type == :text
- return @@context[:node].value
- else
- return false
- end
- end
-
- # Returns the last node of the given list of nodes.
- def Functions::last( )
- @@context[:size]
- end
-
- def Functions::position( )
- @@context[:index]
- end
-
- # Returns the size of the given list of nodes.
- def Functions::count( node_set )
- node_set.size
- end
-
- # Since REXML is non-validating, this method is not implemented as it
- # requires a DTD
- def Functions::id( object )
- end
-
- # UNTESTED
- def Functions::local_name( node_set=nil )
- get_namespace( node_set ) do |node|
- return node.local_name
- end
- end
-
- def Functions::namespace_uri( node_set=nil )
- get_namespace( node_set ) {|node| node.namespace}
- end
-
- def Functions::name( node_set=nil )
- get_namespace( node_set ) do |node|
- node.expanded_name
- end
- end
-
- # Helper method.
- def Functions::get_namespace( node_set = nil )
- if node_set == nil
- yield @@context[:node] if defined? @@context[:node].namespace
- else
- if node_set.respond_to? :each
- node_set.each { |node| yield node if defined? node.namespace }
- elsif node_set.respond_to? :namespace
- yield node_set
- end
- end
- end
-
- # A node-set is converted to a string by returning the string-value of the
- # node in the node-set that is first in document order. If the node-set is
- # empty, an empty string is returned.
- #
- # A number is converted to a string as follows
- #
- # NaN is converted to the string NaN
- #
- # positive zero is converted to the string 0
- #
- # negative zero is converted to the string 0
- #
- # positive infinity is converted to the string Infinity
- #
- # negative infinity is converted to the string -Infinity
- #
- # if the number is an integer, the number is represented in decimal form
- # as a Number with no decimal point and no leading zeros, preceded by a
- # minus sign (-) if the number is negative
- #
- # otherwise, the number is represented in decimal form as a Number
- # including a decimal point with at least one digit before the decimal
- # point and at least one digit after the decimal point, preceded by a
- # minus sign (-) if the number is negative; there must be no leading zeros
- # before the decimal point apart possibly from the one required digit
- # immediately before the decimal point; beyond the one required digit
- # after the decimal point there must be as many, but only as many, more
- # digits as are needed to uniquely distinguish the number from all other
- # IEEE 754 numeric values.
- #
- # The boolean false value is converted to the string false. The boolean
- # true value is converted to the string true.
- #
- # An object of a type other than the four basic types is converted to a
- # string in a way that is dependent on that type.
- def Functions::string( object=nil )
- #object = @context unless object
- if object.instance_of? Array
- string( object[0] )
- elsif defined? object.node_type
- if object.node_type == :attribute
- object.value
- elsif object.node_type == :element || object.node_type == :document
- string_value(object)
- else
- object.to_s
- end
- elsif object.nil?
- return ""
- else
- object.to_s
- end
- end
-
- # A node-set is converted to a string by
- # returning the concatenation of the string-value
- # of each of the children of the node in the
- # node-set that is first in document order.
- # If the node-set is empty, an empty string is returned.
- def Functions::string_value( o )
- rv = ""
- o.children.each { |e|
- if e.node_type == :text
- rv << e.to_s
- elsif e.node_type == :element
- rv << string_value( e )
- end
- }
- rv
- end
-
- # UNTESTED
- def Functions::concat( *objects )
- objects.join
- end
-
- # Fixed by Mike Stok
- def Functions::starts_with( string, test )
- string(string).index(string(test)) == 0
- end
-
- # Fixed by Mike Stok
- def Functions::contains( string, test )
- string(string).include?(string(test))
- end
-
- # Kouhei fixed this
- def Functions::substring_before( string, test )
- ruby_string = string(string)
- ruby_index = ruby_string.index(string(test))
- if ruby_index.nil?
- ""
- else
- ruby_string[ 0...ruby_index ]
- end
- end
-
- # Kouhei fixed this too
- def Functions::substring_after( string, test )
- ruby_string = string(string)
- return $1 if ruby_string =~ /#{test}(.*)/
- ""
- end
-
- # Take equal portions of Mike Stok and Sean Russell; mix
- # vigorously, and pour into a tall, chilled glass. Serves 10,000.
- def Functions::substring( string, start, length=nil )
- ruby_string = string(string)
- ruby_length = if length.nil?
- ruby_string.length.to_f
- else
- number(length)
- end
- ruby_start = number(start)
-
- # Handle the special cases
- return '' if (
- ruby_length.nan? or
- ruby_start.nan? or
- ruby_start.infinite?
- )
-
- infinite_length = ruby_length.infinite? == 1
- ruby_length = ruby_string.length if infinite_length
-
- # Now, get the bounds. The XPath bounds are 1..length; the ruby bounds
- # are 0..length. Therefore, we have to offset the bounds by one.
- ruby_start = ruby_start.round - 1
- ruby_length = ruby_length.round
-
- if ruby_start < 0
- ruby_length += ruby_start unless infinite_length
- ruby_start = 0
- end
- return '' if ruby_length <= 0
- ruby_string[ruby_start,ruby_length]
- end
-
- # UNTESTED
- def Functions::string_length( string )
- string(string).length
- end
-
- # UNTESTED
- def Functions::normalize_space( string=nil )
- string = string(@@context[:node]) if string.nil?
- if string.kind_of? Array
- string.collect{|x| string.to_s.strip.gsub(/\s+/um, ' ') if string}
- else
- string.to_s.strip.gsub(/\s+/um, ' ')
- end
- end
-
- # This is entirely Mike Stok's beast
- def Functions::translate( string, tr1, tr2 )
- from = string(tr1)
- to = string(tr2)
-
- # the map is our translation table.
- #
- # if a character occurs more than once in the
- # from string then we ignore the second &
- # subsequent mappings
- #
- # if a character maps to nil then we delete it
- # in the output. This happens if the from
- # string is longer than the to string
- #
- # there's nothing about - or ^ being special in
- # http://www.w3.org/TR/xpath#function-translate
- # so we don't build ranges or negated classes
-
- map = Hash.new
- 0.upto(from.length - 1) { |pos|
- from_char = from[pos]
- unless map.has_key? from_char
- map[from_char] =
- if pos < to.length
- to[pos]
- else
- nil
- end
- end
- }
-
- if ''.respond_to? :chars
- string(string).chars.collect { |c|
- if map.has_key? c then map[c] else c end
- }.compact.join
- else
- string(string).unpack('U*').collect { |c|
- if map.has_key? c then map[c] else c end
- }.compact.pack('U*')
- end
- end
-
- # UNTESTED
- def Functions::boolean( object=nil )
- if object.kind_of? String
- if object =~ /\d+/u
- return object.to_f != 0
- else
- return object.size > 0
- end
- elsif object.kind_of? Array
- object = object.find{|x| x and true}
- end
- return object ? true : false
- end
-
- # UNTESTED
- def Functions::not( object )
- not boolean( object )
- end
-
- # UNTESTED
- def Functions::true( )
- true
- end
-
- # UNTESTED
- def Functions::false( )
- false
- end
-
- # UNTESTED
- def Functions::lang( language )
- lang = false
- node = @@context[:node]
- attr = nil
- until node.nil?
- if node.node_type == :element
- attr = node.attributes["xml:lang"]
- unless attr.nil?
- lang = compare_language(string(language), attr)
- break
- else
- end
- end
- node = node.parent
- end
- lang
- end
-
- def Functions::compare_language lang1, lang2
- lang2.downcase.index(lang1.downcase) == 0
- end
-
- # a string that consists of optional whitespace followed by an optional
- # minus sign followed by a Number followed by whitespace is converted to
- # the IEEE 754 number that is nearest (according to the IEEE 754
- # round-to-nearest rule) to the mathematical value represented by the
- # string; any other string is converted to NaN
- #
- # boolean true is converted to 1; boolean false is converted to 0
- #
- # a node-set is first converted to a string as if by a call to the string
- # function and then converted in the same way as a string argument
- #
- # an object of a type other than the four basic types is converted to a
- # number in a way that is dependent on that type
- def Functions::number( object=nil )
- object = @@context[:node] unless object
- case object
- when true
- Float(1)
- when false
- Float(0)
- when Array
- number(string( object ))
- when Numeric
- object.to_f
- else
- str = string( object )
- # If XPath ever gets scientific notation...
- #if str =~ /^\s*-?(\d*\.?\d+|\d+\.)([Ee]\d*)?\s*$/
- if str =~ /^\s*-?(\d*\.?\d+|\d+\.)\s*$/
- str.to_f
- else
- (0.0 / 0.0)
- end
- end
- end
-
- def Functions::sum( nodes )
- nodes = [nodes] unless nodes.kind_of? Array
- nodes.inject(0) { |r,n| r + number(string(n)) }
- end
-
- def Functions::floor( number )
- number(number).floor
- end
-
- def Functions::ceiling( number )
- number(number).ceil
- end
-
- def Functions::round( number )
- begin
- number(number).round
- rescue FloatDomainError
- number(number)
- end
- end
-
- def Functions::processing_instruction( node )
- node.node_type == :processing_instruction
- end
-
- def Functions::method_missing( id )
- puts "METHOD MISSING #{id.id2name}"
- XPath.match( @@context[:node], id.id2name )
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/instruction.rb b/ruby_2_2/lib/rexml/instruction.rb
deleted file mode 100644
index f8b734a5b5..0000000000
--- a/ruby_2_2/lib/rexml/instruction.rb
+++ /dev/null
@@ -1,70 +0,0 @@
-require "rexml/child"
-require "rexml/source"
-
-module REXML
- # Represents an XML Instruction; IE, <? ... ?>
- # TODO: Add parent arg (3rd arg) to constructor
- class Instruction < Child
- START = '<\?'
- STOP = '\?>'
-
- # target is the "name" of the Instruction; IE, the "tag" in <?tag ...?>
- # content is everything else.
- attr_accessor :target, :content
-
- # Constructs a new Instruction
- # @param target can be one of a number of things. If String, then
- # the target of this instruction is set to this. If an Instruction,
- # then the Instruction is shallowly cloned (target and content are
- # copied). If a Source, then the source is scanned and parsed for
- # an Instruction declaration.
- # @param content Must be either a String, or a Parent. Can only
- # be a Parent if the target argument is a Source. Otherwise, this
- # String is set as the content of this instruction.
- def initialize(target, content=nil)
- if target.kind_of? String
- super()
- @target = target
- @content = content
- elsif target.kind_of? Instruction
- super(content)
- @target = target.target
- @content = target.content
- end
- @content.strip! if @content
- end
-
- def clone
- Instruction.new self
- end
-
- # == DEPRECATED
- # See the rexml/formatters package
- #
- def write writer, indent=-1, transitive=false, ie_hack=false
- Kernel.warn( "#{self.class.name}.write is deprecated" )
- indent(writer, indent)
- writer << START.sub(/\\/u, '')
- writer << @target
- writer << ' '
- writer << @content
- writer << STOP.sub(/\\/u, '')
- end
-
- # @return true if other is an Instruction, and the content and target
- # of the other matches the target and content of this object.
- def ==( other )
- other.kind_of? Instruction and
- other.target == @target and
- other.content == @content
- end
-
- def node_type
- :processing_instruction
- end
-
- def inspect
- "<?p-i #{target} ...?>"
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/light/node.rb b/ruby_2_2/lib/rexml/light/node.rb
deleted file mode 100644
index b33f78f7ce..0000000000
--- a/ruby_2_2/lib/rexml/light/node.rb
+++ /dev/null
@@ -1,195 +0,0 @@
-require 'rexml/xmltokens'
-
-# [ :element, parent, name, attributes, children* ]
- # a = Node.new
- # a << "B" # => <a>B</a>
- # a.b # => <a>B<b/></a>
- # a.b[1] # => <a>B<b/><b/><a>
- # a.b[1]["x"] = "y" # => <a>B<b/><b x="y"/></a>
- # a.b[0].c # => <a>B<b><c/></b><b x="y"/></a>
- # a.b.c << "D" # => <a>B<b><c>D</c></b><b x="y"/></a>
-module REXML
- module Light
- # Represents a tagged XML element. Elements are characterized by
- # having children, attributes, and names, and can themselves be
- # children.
- class Node
- NAMESPLIT = /^(?:(#{XMLTokens::NCNAME_STR}):)?(#{XMLTokens::NCNAME_STR})/u
- PARENTS = [ :element, :document, :doctype ]
- # Create a new element.
- def initialize node=nil
- @node = node
- if node.kind_of? String
- node = [ :text, node ]
- elsif node.nil?
- node = [ :document, nil, nil ]
- elsif node[0] == :start_element
- node[0] = :element
- elsif node[0] == :start_doctype
- node[0] = :doctype
- elsif node[0] == :start_document
- node[0] = :document
- end
- end
-
- def size
- if PARENTS.include? @node[0]
- @node[-1].size
- else
- 0
- end
- end
-
- def each
- size.times { |x| yield( at(x+4) ) }
- end
-
- def name
- at(2)
- end
-
- def name=( name_str, ns=nil )
- pfx = ''
- pfx = "#{prefix(ns)}:" if ns
- _old_put(2, "#{pfx}#{name_str}")
- end
-
- def parent=( node )
- _old_put(1,node)
- end
-
- def local_name
- namesplit
- @name
- end
-
- def local_name=( name_str )
- _old_put( 1, "#@prefix:#{name_str}" )
- end
-
- def prefix( namespace=nil )
- prefix_of( self, namespace )
- end
-
- def namespace( prefix=prefix() )
- namespace_of( self, prefix )
- end
-
- def namespace=( namespace )
- @prefix = prefix( namespace )
- pfx = ''
- pfx = "#@prefix:" if @prefix.size > 0
- _old_put(1, "#{pfx}#@name")
- end
-
- def []( reference, ns=nil )
- if reference.kind_of? String
- pfx = ''
- pfx = "#{prefix(ns)}:" if ns
- at(3)["#{pfx}#{reference}"]
- elsif reference.kind_of? Range
- _old_get( Range.new(4+reference.begin, reference.end, reference.exclude_end?) )
- else
- _old_get( 4+reference )
- end
- end
-
- def =~( path )
- XPath.match( self, path )
- end
-
- # Doesn't handle namespaces yet
- def []=( reference, ns, value=nil )
- if reference.kind_of? String
- value = ns unless value
- at( 3 )[reference] = value
- elsif reference.kind_of? Range
- _old_put( Range.new(3+reference.begin, reference.end, reference.exclude_end?), ns )
- else
- if value
- _old_put( 4+reference, ns, value )
- else
- _old_put( 4+reference, ns )
- end
- end
- end
-
- # Append a child to this element, optionally under a provided namespace.
- # The namespace argument is ignored if the element argument is an Element
- # object. Otherwise, the element argument is a string, the namespace (if
- # provided) is the namespace the element is created in.
- def << element
- if node_type() == :text
- at(-1) << element
- else
- newnode = Node.new( element )
- newnode.parent = self
- self.push( newnode )
- end
- at(-1)
- end
-
- def node_type
- _old_get(0)
- end
-
- def text=( foo )
- replace = at(4).kind_of?(String)? 1 : 0
- self._old_put(4,replace, normalizefoo)
- end
-
- def root
- context = self
- context = context.at(1) while context.at(1)
- end
-
- def has_name?( name, namespace = '' )
- at(3) == name and namespace() == namespace
- end
-
- def children
- self
- end
-
- def parent
- at(1)
- end
-
- def to_s
-
- end
-
- private
-
- def namesplit
- return if @name.defined?
- at(2) =~ NAMESPLIT
- @prefix = '' || $1
- @name = $2
- end
-
- def namespace_of( node, prefix=nil )
- if not prefix
- name = at(2)
- name =~ NAMESPLIT
- prefix = $1
- end
- to_find = 'xmlns'
- to_find = "xmlns:#{prefix}" if not prefix.nil?
- ns = at(3)[ to_find ]
- ns ? ns : namespace_of( @node[0], prefix )
- end
-
- def prefix_of( node, namespace=nil )
- if not namespace
- name = node.name
- name =~ NAMESPLIT
- $1
- else
- ns = at(3).find { |k,v| v == namespace }
- ns ? ns : prefix_of( node.parent, namespace )
- end
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/namespace.rb b/ruby_2_2/lib/rexml/namespace.rb
deleted file mode 100644
index aeb339ee83..0000000000
--- a/ruby_2_2/lib/rexml/namespace.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-require 'rexml/xmltokens'
-
-module REXML
- # Adds named attributes to an object.
- module Namespace
- # The name of the object, valid if set
- attr_reader :name, :expanded_name
- # The expanded name of the object, valid if name is set
- attr_accessor :prefix
- include XMLTokens
- NAMESPLIT = /^(?:(#{NCNAME_STR}):)?(#{NCNAME_STR})/u
-
- # Sets the name and the expanded name
- def name=( name )
- @expanded_name = name
- name =~ NAMESPLIT
- if $1
- @prefix = $1
- else
- @prefix = ""
- @namespace = ""
- end
- @name = $2
- end
-
- # Compares names optionally WITH namespaces
- def has_name?( other, ns=nil )
- if ns
- return (namespace() == ns and name() == other)
- elsif other.include? ":"
- return fully_expanded_name == other
- else
- return name == other
- end
- end
-
- alias :local_name :name
-
- # Fully expand the name, even if the prefix wasn't specified in the
- # source file.
- def fully_expanded_name
- ns = prefix
- return "#{ns}:#@name" if ns.size > 0
- return @name
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/node.rb b/ruby_2_2/lib/rexml/node.rb
deleted file mode 100644
index cab6e9fddb..0000000000
--- a/ruby_2_2/lib/rexml/node.rb
+++ /dev/null
@@ -1,75 +0,0 @@
-require "rexml/parseexception"
-require "rexml/formatters/pretty"
-require "rexml/formatters/default"
-
-module REXML
- # Represents a node in the tree. Nodes are never encountered except as
- # superclasses of other objects. Nodes have siblings.
- module Node
- # @return the next sibling (nil if unset)
- def next_sibling_node
- return nil if @parent.nil?
- @parent[ @parent.index(self) + 1 ]
- end
-
- # @return the previous sibling (nil if unset)
- def previous_sibling_node
- return nil if @parent.nil?
- ind = @parent.index(self)
- return nil if ind == 0
- @parent[ ind - 1 ]
- end
-
- # indent::
- # *DEPRECATED* This parameter is now ignored. See the formatters in the
- # REXML::Formatters package for changing the output style.
- def to_s indent=nil
- unless indent.nil?
- Kernel.warn( "#{self.class.name}.to_s(indent) parameter is deprecated" )
- f = REXML::Formatters::Pretty.new( indent )
- f.write( self, rv = "" )
- else
- f = REXML::Formatters::Default.new
- f.write( self, rv = "" )
- end
- return rv
- end
-
- def indent to, ind
- if @parent and @parent.context and not @parent.context[:indentstyle].nil? then
- indentstyle = @parent.context[:indentstyle]
- else
- indentstyle = ' '
- end
- to << indentstyle*ind unless ind<1
- end
-
- def parent?
- false;
- end
-
-
- # Visit all subnodes of +self+ recursively
- def each_recursive(&block) # :yields: node
- self.elements.each {|node|
- block.call(node)
- node.each_recursive(&block)
- }
- end
-
- # Find (and return) first subnode (recursively) for which the block
- # evaluates to true. Returns +nil+ if none was found.
- def find_first_recursive(&block) # :yields: node
- each_recursive {|node|
- return node if block.call(node)
- }
- return nil
- end
-
- # Returns the position that +self+ holds in its parent's array, indexed
- # from 1.
- def index_in_parent
- parent.index(self)+1
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/output.rb b/ruby_2_2/lib/rexml/output.rb
deleted file mode 100644
index 0c6cc7a7f8..0000000000
--- a/ruby_2_2/lib/rexml/output.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-require 'rexml/encoding'
-
-module REXML
- class Output
- include Encoding
-
- attr_reader :encoding
-
- def initialize real_IO, encd="iso-8859-1"
- @output = real_IO
- self.encoding = encd
-
- @to_utf = encoding != 'UTF-8'
-
- if encoding == "UTF-16"
- @output << "\ufeff".encode("UTF-16BE")
- self.encoding = "UTF-16BE"
- end
- end
-
- def <<( content )
- @output << (@to_utf ? self.encode(content) : content)
- end
-
- def to_s
- "Output[#{encoding}]"
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/parent.rb b/ruby_2_2/lib/rexml/parent.rb
deleted file mode 100644
index 2a07fcacbd..0000000000
--- a/ruby_2_2/lib/rexml/parent.rb
+++ /dev/null
@@ -1,165 +0,0 @@
-require "rexml/child"
-
-module REXML
- # A parent has children, and has methods for accessing them. The Parent
- # class is never encountered except as the superclass for some other
- # object.
- class Parent < Child
- include Enumerable
-
- # Constructor
- # @param parent if supplied, will be set as the parent of this object
- def initialize parent=nil
- super(parent)
- @children = []
- end
-
- def add( object )
- object.parent = self
- @children << object
- object
- end
-
- alias :push :add
- alias :<< :push
-
- def unshift( object )
- object.parent = self
- @children.unshift object
- end
-
- def delete( object )
- found = false
- @children.delete_if {|c| c.equal?(object) and found = true }
- object.parent = nil if found
- found ? object : nil
- end
-
- def each(&block)
- @children.each(&block)
- end
-
- def delete_if( &block )
- @children.delete_if(&block)
- end
-
- def delete_at( index )
- @children.delete_at index
- end
-
- def each_index( &block )
- @children.each_index(&block)
- end
-
- # Fetches a child at a given index
- # @param index the Integer index of the child to fetch
- def []( index )
- @children[index]
- end
-
- alias :each_child :each
-
-
-
- # Set an index entry. See Array.[]=
- # @param index the index of the element to set
- # @param opt either the object to set, or an Integer length
- # @param child if opt is an Integer, this is the child to set
- # @return the parent (self)
- def []=( *args )
- args[-1].parent = self
- @children[*args[0..-2]] = args[-1]
- end
-
- # Inserts an child before another child
- # @param child1 this is either an xpath or an Element. If an Element,
- # child2 will be inserted before child1 in the child list of the parent.
- # If an xpath, child2 will be inserted before the first child to match
- # the xpath.
- # @param child2 the child to insert
- # @return the parent (self)
- def insert_before( child1, child2 )
- if child1.kind_of? String
- child1 = XPath.first( self, child1 )
- child1.parent.insert_before child1, child2
- else
- ind = index(child1)
- child2.parent.delete(child2) if child2.parent
- @children[ind,0] = child2
- child2.parent = self
- end
- self
- end
-
- # Inserts an child after another child
- # @param child1 this is either an xpath or an Element. If an Element,
- # child2 will be inserted after child1 in the child list of the parent.
- # If an xpath, child2 will be inserted after the first child to match
- # the xpath.
- # @param child2 the child to insert
- # @return the parent (self)
- def insert_after( child1, child2 )
- if child1.kind_of? String
- child1 = XPath.first( self, child1 )
- child1.parent.insert_after child1, child2
- else
- ind = index(child1)+1
- child2.parent.delete(child2) if child2.parent
- @children[ind,0] = child2
- child2.parent = self
- end
- self
- end
-
- def to_a
- @children.dup
- end
-
- # Fetches the index of a given child
- # @param child the child to get the index of
- # @return the index of the child, or nil if the object is not a child
- # of this parent.
- def index( child )
- count = -1
- @children.find { |i| count += 1 ; i.hash == child.hash }
- count
- end
-
- # @return the number of children of this parent
- def size
- @children.size
- end
-
- alias :length :size
-
- # Replaces one child with another, making sure the nodelist is correct
- # @param to_replace the child to replace (must be a Child)
- # @param replacement the child to insert into the nodelist (must be a
- # Child)
- def replace_child( to_replace, replacement )
- @children.map! {|c| c.equal?( to_replace ) ? replacement : c }
- to_replace.parent = nil
- replacement.parent = self
- end
-
- # Deeply clones this object. This creates a complete duplicate of this
- # Parent, including all descendants.
- def deep_clone
- cl = clone()
- each do |child|
- if child.kind_of? Parent
- cl << child.deep_clone
- else
- cl << child.clone
- end
- end
- cl
- end
-
- alias :children :to_a
-
- def parent?
- true
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/parseexception.rb b/ruby_2_2/lib/rexml/parseexception.rb
deleted file mode 100644
index 0c4d55abda..0000000000
--- a/ruby_2_2/lib/rexml/parseexception.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-module REXML
- class ParseException < RuntimeError
- attr_accessor :source, :parser, :continued_exception
-
- def initialize( message, source=nil, parser=nil, exception=nil )
- super(message)
- @source = source
- @parser = parser
- @continued_exception = exception
- end
-
- def to_s
- # Quote the original exception, if there was one
- if @continued_exception
- err = @continued_exception.inspect
- err << "\n"
- err << @continued_exception.backtrace.join("\n")
- err << "\n...\n"
- else
- err = ""
- end
-
- # Get the stack trace and error message
- err << super
-
- # Add contextual information
- if @source
- err << "\nLine: #{line}\n"
- err << "Position: #{position}\n"
- err << "Last 80 unconsumed characters:\n"
- err << @source.buffer[0..80].force_encoding("ASCII-8BIT").gsub(/\n/, ' ')
- end
-
- err
- end
-
- def position
- @source.current_line[0] if @source and defined? @source.current_line and
- @source.current_line
- end
-
- def line
- @source.current_line[2] if @source and defined? @source.current_line and
- @source.current_line
- end
-
- def context
- @source.current_line
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/parsers/baseparser.rb b/ruby_2_2/lib/rexml/parsers/baseparser.rb
deleted file mode 100644
index 6a08b8661d..0000000000
--- a/ruby_2_2/lib/rexml/parsers/baseparser.rb
+++ /dev/null
@@ -1,532 +0,0 @@
-require 'rexml/parseexception'
-require 'rexml/undefinednamespaceexception'
-require 'rexml/source'
-require 'set'
-
-module REXML
- module Parsers
- # = Using the Pull Parser
- # <em>This API is experimental, and subject to change.</em>
- # parser = PullParser.new( "<a>text<b att='val'/>txet</a>" )
- # while parser.has_next?
- # res = parser.next
- # puts res[1]['att'] if res.start_tag? and res[0] == 'b'
- # end
- # See the PullEvent class for information on the content of the results.
- # The data is identical to the arguments passed for the various events to
- # the StreamListener API.
- #
- # Notice that:
- # parser = PullParser.new( "<a>BAD DOCUMENT" )
- # while parser.has_next?
- # res = parser.next
- # raise res[1] if res.error?
- # end
- #
- # Nat Price gave me some good ideas for the API.
- class BaseParser
- LETTER = '[:alpha:]'
- DIGIT = '[:digit:]'
-
- COMBININGCHAR = '' # TODO
- EXTENDER = '' # TODO
-
- NCNAME_STR= "[#{LETTER}_:][-[:alnum:]._:#{COMBININGCHAR}#{EXTENDER}]*"
- NAME_STR= "(?:(#{NCNAME_STR}):)?(#{NCNAME_STR})"
- UNAME_STR= "(?:#{NCNAME_STR}:)?#{NCNAME_STR}"
-
- NAMECHAR = '[\-\w\.:]'
- NAME = "([\\w:]#{NAMECHAR}*)"
- NMTOKEN = "(?:#{NAMECHAR})+"
- NMTOKENS = "#{NMTOKEN}(\\s+#{NMTOKEN})*"
- REFERENCE = "&(?:#{NAME};|#\\d+;|#x[0-9a-fA-F]+;)"
- REFERENCE_RE = /#{REFERENCE}/
-
- DOCTYPE_START = /\A\s*<!DOCTYPE\s/um
- DOCTYPE_END = /\A\s*\]\s*>/um
- DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/um
- ATTRIBUTE_PATTERN = /\s*(#{NAME_STR})\s*=\s*(["'])(.*?)\4/um
- COMMENT_START = /\A<!--/u
- COMMENT_PATTERN = /<!--(.*?)-->/um
- CDATA_START = /\A<!\[CDATA\[/u
- CDATA_END = /\A\s*\]\s*>/um
- CDATA_PATTERN = /<!\[CDATA\[(.*?)\]\]>/um
- XMLDECL_START = /\A<\?xml\s/u;
- XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>/um
- INSTRUCTION_START = /\A<\?/u
- INSTRUCTION_PATTERN = /<\?(.*?)(\s+.*?)?\?>/um
- TAG_MATCH = /^<((?>#{NAME_STR}))\s*((?>\s+#{UNAME_STR}\s*=\s*(["']).*?\5)*)\s*(\/)?>/um
- CLOSE_MATCH = /^\s*<\/(#{NAME_STR})\s*>/um
-
- VERSION = /\bversion\s*=\s*["'](.*?)['"]/um
- ENCODING = /\bencoding\s*=\s*["'](.*?)['"]/um
- STANDALONE = /\bstandalone\s*=\s*["'](.*?)['"]/um
-
- ENTITY_START = /\A\s*<!ENTITY/
- IDENTITY = /^([!\*\w\-]+)(\s+#{NCNAME_STR})?(\s+["'](.*?)['"])?(\s+['"](.*?)["'])?/u
- ELEMENTDECL_START = /\A\s*<!ELEMENT/um
- ELEMENTDECL_PATTERN = /\A\s*(<!ELEMENT.*?)>/um
- SYSTEMENTITY = /\A\s*(%.*?;)\s*$/um
- ENUMERATION = "\\(\\s*#{NMTOKEN}(?:\\s*\\|\\s*#{NMTOKEN})*\\s*\\)"
- NOTATIONTYPE = "NOTATION\\s+\\(\\s*#{NAME}(?:\\s*\\|\\s*#{NAME})*\\s*\\)"
- ENUMERATEDTYPE = "(?:(?:#{NOTATIONTYPE})|(?:#{ENUMERATION}))"
- ATTTYPE = "(CDATA|ID|IDREF|IDREFS|ENTITY|ENTITIES|NMTOKEN|NMTOKENS|#{ENUMERATEDTYPE})"
- ATTVALUE = "(?:\"((?:[^<&\"]|#{REFERENCE})*)\")|(?:'((?:[^<&']|#{REFERENCE})*)')"
- DEFAULTDECL = "(#REQUIRED|#IMPLIED|(?:(#FIXED\\s+)?#{ATTVALUE}))"
- ATTDEF = "\\s+#{NAME}\\s+#{ATTTYPE}\\s+#{DEFAULTDECL}"
- ATTDEF_RE = /#{ATTDEF}/
- ATTLISTDECL_START = /\A\s*<!ATTLIST/um
- ATTLISTDECL_PATTERN = /\A\s*<!ATTLIST\s+#{NAME}(?:#{ATTDEF})*\s*>/um
- NOTATIONDECL_START = /\A\s*<!NOTATION/um
- PUBLIC = /\A\s*<!NOTATION\s+(\w[\-\w]*)\s+(PUBLIC)\s+(["'])(.*?)\3(?:\s+(["'])(.*?)\5)?\s*>/um
- SYSTEM = /\A\s*<!NOTATION\s+(\w[\-\w]*)\s+(SYSTEM)\s+(["'])(.*?)\3\s*>/um
-
- TEXT_PATTERN = /\A([^<]*)/um
-
- # Entity constants
- PUBIDCHAR = "\x20\x0D\x0Aa-zA-Z0-9\\-()+,./:=?;!*@$_%#"
- SYSTEMLITERAL = %Q{((?:"[^"]*")|(?:'[^']*'))}
- PUBIDLITERAL = %Q{("[#{PUBIDCHAR}']*"|'[#{PUBIDCHAR}]*')}
- EXTERNALID = "(?:(?:(SYSTEM)\\s+#{SYSTEMLITERAL})|(?:(PUBLIC)\\s+#{PUBIDLITERAL}\\s+#{SYSTEMLITERAL}))"
- NDATADECL = "\\s+NDATA\\s+#{NAME}"
- PEREFERENCE = "%#{NAME};"
- ENTITYVALUE = %Q{((?:"(?:[^%&"]|#{PEREFERENCE}|#{REFERENCE})*")|(?:'([^%&']|#{PEREFERENCE}|#{REFERENCE})*'))}
- PEDEF = "(?:#{ENTITYVALUE}|#{EXTERNALID})"
- ENTITYDEF = "(?:#{ENTITYVALUE}|(?:#{EXTERNALID}(#{NDATADECL})?))"
- PEDECL = "<!ENTITY\\s+(%)\\s+#{NAME}\\s+#{PEDEF}\\s*>"
- GEDECL = "<!ENTITY\\s+#{NAME}\\s+#{ENTITYDEF}\\s*>"
- ENTITYDECL = /\s*(?:#{GEDECL})|(?:#{PEDECL})/um
-
- EREFERENCE = /&(?!#{NAME};)/
-
- DEFAULT_ENTITIES = {
- 'gt' => [/&gt;/, '&gt;', '>', />/],
- 'lt' => [/&lt;/, '&lt;', '<', /</],
- 'quot' => [/&quot;/, '&quot;', '"', /"/],
- "apos" => [/&apos;/, "&apos;", "'", /'/]
- }
-
-
- ######################################################################
- # These are patterns to identify common markup errors, to make the
- # error messages more informative.
- ######################################################################
- MISSING_ATTRIBUTE_QUOTES = /^<#{NAME_STR}\s+#{NAME_STR}\s*=\s*[^"']/um
-
- def initialize( source )
- self.stream = source
- @listeners = []
- end
-
- def add_listener( listener )
- @listeners << listener
- end
-
- attr_reader :source
-
- def stream=( source )
- @source = SourceFactory.create_from( source )
- @closed = nil
- @document_status = nil
- @tags = []
- @stack = []
- @entities = []
- @nsstack = []
- end
-
- def position
- if @source.respond_to? :position
- @source.position
- else
- # FIXME
- 0
- end
- end
-
- # Returns true if there are no more events
- def empty?
- return (@source.empty? and @stack.empty?)
- end
-
- # Returns true if there are more events. Synonymous with !empty?
- def has_next?
- return !(@source.empty? and @stack.empty?)
- end
-
- # Push an event back on the head of the stream. This method
- # has (theoretically) infinite depth.
- def unshift token
- @stack.unshift(token)
- end
-
- # Peek at the +depth+ event in the stack. The first element on the stack
- # is at depth 0. If +depth+ is -1, will parse to the end of the input
- # stream and return the last event, which is always :end_document.
- # Be aware that this causes the stream to be parsed up to the +depth+
- # event, so you can effectively pre-parse the entire document (pull the
- # entire thing into memory) using this method.
- def peek depth=0
- raise %Q[Illegal argument "#{depth}"] if depth < -1
- temp = []
- if depth == -1
- temp.push(pull()) until empty?
- else
- while @stack.size+temp.size < depth+1
- temp.push(pull())
- end
- end
- @stack += temp if temp.size > 0
- @stack[depth]
- end
-
- # Returns the next event. This is a +PullEvent+ object.
- def pull
- pull_event.tap do |event|
- @listeners.each do |listener|
- listener.receive event
- end
- end
- end
-
- def pull_event
- if @closed
- x, @closed = @closed, nil
- return [ :end_element, x ]
- end
- return [ :end_document ] if empty?
- return @stack.shift if @stack.size > 0
- #STDERR.puts @source.encoding
- @source.read if @source.buffer.size<2
- #STDERR.puts "BUFFER = #{@source.buffer.inspect}"
- if @document_status == nil
- #@source.consume( /^\s*/um )
- word = @source.match( /^((?:\s+)|(?:<[^>]*>))/um )
- word = word[1] unless word.nil?
- #STDERR.puts "WORD = #{word.inspect}"
- case word
- when COMMENT_START
- return [ :comment, @source.match( COMMENT_PATTERN, true )[1] ]
- when XMLDECL_START
- #STDERR.puts "XMLDECL"
- results = @source.match( XMLDECL_PATTERN, true )[1]
- version = VERSION.match( results )
- version = version[1] unless version.nil?
- encoding = ENCODING.match(results)
- encoding = encoding[1] unless encoding.nil?
- if need_source_encoding_update?(encoding)
- @source.encoding = encoding
- end
- if encoding.nil? and /\AUTF-16(?:BE|LE)\z/i =~ @source.encoding
- encoding = "UTF-16"
- end
- standalone = STANDALONE.match(results)
- standalone = standalone[1] unless standalone.nil?
- return [ :xmldecl, version, encoding, standalone ]
- when INSTRUCTION_START
- return [ :processing_instruction, *@source.match(INSTRUCTION_PATTERN, true)[1,2] ]
- when DOCTYPE_START
- md = @source.match( DOCTYPE_PATTERN, true )
- @nsstack.unshift(curr_ns=Set.new)
- identity = md[1]
- close = md[2]
- identity =~ IDENTITY
- name = $1
- raise REXML::ParseException.new("DOCTYPE is missing a name") if name.nil?
- pub_sys = $2.nil? ? nil : $2.strip
- long_name = $4.nil? ? nil : $4.strip
- uri = $6.nil? ? nil : $6.strip
- args = [ :start_doctype, name, pub_sys, long_name, uri ]
- if close == ">"
- @document_status = :after_doctype
- @source.read if @source.buffer.size<2
- md = @source.match(/^\s*/um, true)
- @stack << [ :end_doctype ]
- else
- @document_status = :in_doctype
- end
- return args
- when /^\s+/
- else
- @document_status = :after_doctype
- @source.read if @source.buffer.size<2
- md = @source.match(/\s*/um, true)
- if @source.encoding == "UTF-8"
- @source.buffer.force_encoding(::Encoding::UTF_8)
- end
- end
- end
- if @document_status == :in_doctype
- md = @source.match(/\s*(.*?>)/um)
- case md[1]
- when SYSTEMENTITY
- match = @source.match( SYSTEMENTITY, true )[1]
- return [ :externalentity, match ]
-
- when ELEMENTDECL_START
- return [ :elementdecl, @source.match( ELEMENTDECL_PATTERN, true )[1] ]
-
- when ENTITY_START
- match = @source.match( ENTITYDECL, true ).to_a.compact
- match[0] = :entitydecl
- ref = false
- if match[1] == '%'
- ref = true
- match.delete_at 1
- end
- # Now we have to sort out what kind of entity reference this is
- if match[2] == 'SYSTEM'
- # External reference
- match[3] = match[3][1..-2] # PUBID
- match.delete_at(4) if match.size > 4 # Chop out NDATA decl
- # match is [ :entity, name, SYSTEM, pubid(, ndata)? ]
- elsif match[2] == 'PUBLIC'
- # External reference
- match[3] = match[3][1..-2] # PUBID
- match[4] = match[4][1..-2] # HREF
- match.delete_at(5) if match.size > 5 # Chop out NDATA decl
- # match is [ :entity, name, PUBLIC, pubid, href(, ndata)? ]
- else
- match[2] = match[2][1..-2]
- match.pop if match.size == 4
- # match is [ :entity, name, value ]
- end
- match << '%' if ref
- return match
- when ATTLISTDECL_START
- md = @source.match( ATTLISTDECL_PATTERN, true )
- raise REXML::ParseException.new( "Bad ATTLIST declaration!", @source ) if md.nil?
- element = md[1]
- contents = md[0]
-
- pairs = {}
- values = md[0].scan( ATTDEF_RE )
- values.each do |attdef|
- unless attdef[3] == "#IMPLIED"
- attdef.compact!
- val = attdef[3]
- val = attdef[4] if val == "#FIXED "
- pairs[attdef[0]] = val
- if attdef[0] =~ /^xmlns:(.*)/
- @nsstack[0] << $1
- end
- end
- end
- return [ :attlistdecl, element, pairs, contents ]
- when NOTATIONDECL_START
- md = nil
- if @source.match( PUBLIC )
- md = @source.match( PUBLIC, true )
- vals = [md[1],md[2],md[4],md[6]]
- elsif @source.match( SYSTEM )
- md = @source.match( SYSTEM, true )
- vals = [md[1],md[2],nil,md[4]]
- else
- raise REXML::ParseException.new( "error parsing notation: no matching pattern", @source )
- end
- return [ :notationdecl, *vals ]
- when DOCTYPE_END
- @document_status = :after_doctype
- @source.match( DOCTYPE_END, true )
- return [ :end_doctype ]
- end
- end
- begin
- if @source.buffer[0] == ?<
- if @source.buffer[1] == ?/
- @nsstack.shift
- last_tag = @tags.pop
- #md = @source.match_to_consume( '>', CLOSE_MATCH)
- md = @source.match( CLOSE_MATCH, true )
- raise REXML::ParseException.new( "Missing end tag for "+
- "'#{last_tag}' (got \"#{md[1]}\")",
- @source) unless last_tag == md[1]
- return [ :end_element, last_tag ]
- elsif @source.buffer[1] == ?!
- md = @source.match(/\A(\s*[^>]*>)/um)
- #STDERR.puts "SOURCE BUFFER = #{source.buffer}, #{source.buffer.size}"
- raise REXML::ParseException.new("Malformed node", @source) unless md
- if md[0][2] == ?-
- md = @source.match( COMMENT_PATTERN, true )
-
- case md[1]
- when /--/, /-\z/
- raise REXML::ParseException.new("Malformed comment", @source)
- end
-
- return [ :comment, md[1] ] if md
- else
- md = @source.match( CDATA_PATTERN, true )
- return [ :cdata, md[1] ] if md
- end
- raise REXML::ParseException.new( "Declarations can only occur "+
- "in the doctype declaration.", @source)
- elsif @source.buffer[1] == ??
- md = @source.match( INSTRUCTION_PATTERN, true )
- return [ :processing_instruction, md[1], md[2] ] if md
- raise REXML::ParseException.new( "Bad instruction declaration",
- @source)
- else
- # Get the next tag
- md = @source.match(TAG_MATCH, true)
- unless md
- # Check for missing attribute quotes
- raise REXML::ParseException.new("missing attribute quote", @source) if @source.match(MISSING_ATTRIBUTE_QUOTES )
- raise REXML::ParseException.new("malformed XML: missing tag start", @source)
- end
- attributes = {}
- prefixes = Set.new
- prefixes << md[2] if md[2]
- @nsstack.unshift(curr_ns=Set.new)
- if md[4].size > 0
- attrs = md[4].scan( ATTRIBUTE_PATTERN )
- raise REXML::ParseException.new( "error parsing attributes: [#{attrs.join ', '}], excess = \"#$'\"", @source) if $' and $'.strip.size > 0
- attrs.each do |attr_name, prefix, local_part, quote, value|
- if prefix == "xmlns"
- if local_part == "xml"
- if value != "http://www.w3.org/XML/1998/namespace"
- msg = "The 'xml' prefix must not be bound to any other namespace "+
- "(http://www.w3.org/TR/REC-xml-names/#ns-decl)"
- raise REXML::ParseException.new( msg, @source, self )
- end
- elsif local_part == "xmlns"
- msg = "The 'xmlns' prefix must not be declared "+
- "(http://www.w3.org/TR/REC-xml-names/#ns-decl)"
- raise REXML::ParseException.new( msg, @source, self)
- end
- curr_ns << local_part
- elsif prefix
- prefixes << prefix unless prefix == "xml"
- end
-
- if attributes.has_key?(attr_name)
- msg = "Duplicate attribute #{attr_name.inspect}"
- raise REXML::ParseException.new(msg, @source, self)
- end
-
- attributes[attr_name] = value
- end
- end
-
- # Verify that all of the prefixes have been defined
- for prefix in prefixes
- unless @nsstack.find{|k| k.member?(prefix)}
- raise UndefinedNamespaceException.new(prefix,@source,self)
- end
- end
-
- if md[6]
- @closed = md[1]
- @nsstack.shift
- else
- @tags.push( md[1] )
- end
- return [ :start_element, md[1], attributes ]
- end
- else
- md = @source.match( TEXT_PATTERN, true )
- if md[0].length == 0
- @source.match( /(\s+)/, true )
- end
- #STDERR.puts "GOT #{md[1].inspect}" unless md[0].length == 0
- #return [ :text, "" ] if md[0].length == 0
- # unnormalized = Text::unnormalize( md[1], self )
- # return PullEvent.new( :text, md[1], unnormalized )
- return [ :text, md[1] ]
- end
- rescue REXML::UndefinedNamespaceException
- raise
- rescue REXML::ParseException
- raise
- rescue Exception, NameError => error
- raise REXML::ParseException.new( "Exception parsing",
- @source, self, (error ? error : $!) )
- end
- return [ :dummy ]
- end
- private :pull_event
-
- def entity( reference, entities )
- value = nil
- value = entities[ reference ] if entities
- if not value
- value = DEFAULT_ENTITIES[ reference ]
- value = value[2] if value
- end
- unnormalize( value, entities ) if value
- end
-
- # Escapes all possible entities
- def normalize( input, entities=nil, entity_filter=nil )
- copy = input.clone
- # Doing it like this rather than in a loop improves the speed
- copy.gsub!( EREFERENCE, '&amp;' )
- entities.each do |key, value|
- copy.gsub!( value, "&#{key};" ) unless entity_filter and
- entity_filter.include?(entity)
- end if entities
- copy.gsub!( EREFERENCE, '&amp;' )
- DEFAULT_ENTITIES.each do |key, value|
- copy.gsub!( value[3], value[1] )
- end
- copy
- end
-
- # Unescapes all possible entities
- def unnormalize( string, entities=nil, filter=nil )
- rv = string.clone
- rv.gsub!( /\r\n?/, "\n" )
- matches = rv.scan( REFERENCE_RE )
- return rv if matches.size == 0
- rv.gsub!( /&#0*((?:\d+)|(?:x[a-fA-F0-9]+));/ ) {
- m=$1
- m = "0#{m}" if m[0] == ?x
- [Integer(m)].pack('U*')
- }
- matches.collect!{|x|x[0]}.compact!
- if matches.size > 0
- matches.each do |entity_reference|
- unless filter and filter.include?(entity_reference)
- entity_value = entity( entity_reference, entities )
- if entity_value
- re = /&#{entity_reference};/
- rv.gsub!( re, entity_value )
- else
- er = DEFAULT_ENTITIES[entity_reference]
- rv.gsub!( er[0], er[2] ) if er
- end
- end
- end
- rv.gsub!( /&amp;/, '&' )
- end
- rv
- end
-
- private
- def need_source_encoding_update?(xml_declaration_encoding)
- return false if xml_declaration_encoding.nil?
- return false if /\AUTF-16\z/i =~ xml_declaration_encoding
- true
- end
- end
- end
-end
-
-=begin
- case event[0]
- when :start_element
- when :text
- when :end_element
- when :processing_instruction
- when :cdata
- when :comment
- when :xmldecl
- when :start_doctype
- when :end_doctype
- when :externalentity
- when :elementdecl
- when :entity
- when :attlistdecl
- when :notationdecl
- when :end_doctype
- end
-=end
diff --git a/ruby_2_2/lib/rexml/parsers/lightparser.rb b/ruby_2_2/lib/rexml/parsers/lightparser.rb
deleted file mode 100644
index 81041681c2..0000000000
--- a/ruby_2_2/lib/rexml/parsers/lightparser.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-require 'rexml/parsers/streamparser'
-require 'rexml/parsers/baseparser'
-require 'rexml/light/node'
-
-module REXML
- module Parsers
- class LightParser
- def initialize stream
- @stream = stream
- @parser = REXML::Parsers::BaseParser.new( stream )
- end
-
- def add_listener( listener )
- @parser.add_listener( listener )
- end
-
- def rewind
- @stream.rewind
- @parser.stream = @stream
- end
-
- def parse
- root = context = [ :document ]
- while true
- event = @parser.pull
- case event[0]
- when :end_document
- break
- when :start_element, :start_doctype
- new_node = event
- context << new_node
- new_node[1,0] = [context]
- context = new_node
- when :end_element, :end_doctype
- context = context[1]
- else
- new_node = event
- context << new_node
- new_node[1,0] = [context]
- end
- end
- root
- end
- end
-
- # An element is an array. The array contains:
- # 0 The parent element
- # 1 The tag name
- # 2 A hash of attributes
- # 3..-1 The child elements
- # An element is an array of size > 3
- # Text is a String
- # PIs are [ :processing_instruction, target, data ]
- # Comments are [ :comment, data ]
- # DocTypes are DocType structs
- # The root is an array with XMLDecls, Text, DocType, Array, Text
- end
-end
diff --git a/ruby_2_2/lib/rexml/parsers/pullparser.rb b/ruby_2_2/lib/rexml/parsers/pullparser.rb
deleted file mode 100644
index 68a4ff7eae..0000000000
--- a/ruby_2_2/lib/rexml/parsers/pullparser.rb
+++ /dev/null
@@ -1,196 +0,0 @@
-require 'forwardable'
-
-require 'rexml/parseexception'
-require 'rexml/parsers/baseparser'
-require 'rexml/xmltokens'
-
-module REXML
- module Parsers
- # = Using the Pull Parser
- # <em>This API is experimental, and subject to change.</em>
- # parser = PullParser.new( "<a>text<b att='val'/>txet</a>" )
- # while parser.has_next?
- # res = parser.next
- # puts res[1]['att'] if res.start_tag? and res[0] == 'b'
- # end
- # See the PullEvent class for information on the content of the results.
- # The data is identical to the arguments passed for the various events to
- # the StreamListener API.
- #
- # Notice that:
- # parser = PullParser.new( "<a>BAD DOCUMENT" )
- # while parser.has_next?
- # res = parser.next
- # raise res[1] if res.error?
- # end
- #
- # Nat Price gave me some good ideas for the API.
- class PullParser
- include XMLTokens
- extend Forwardable
-
- def_delegators( :@parser, :has_next? )
- def_delegators( :@parser, :entity )
- def_delegators( :@parser, :empty? )
- def_delegators( :@parser, :source )
-
- def initialize stream
- @entities = {}
- @listeners = nil
- @parser = BaseParser.new( stream )
- @my_stack = []
- end
-
- def add_listener( listener )
- @listeners = [] unless @listeners
- @listeners << listener
- end
-
- def each
- while has_next?
- yield self.pull
- end
- end
-
- def peek depth=0
- if @my_stack.length <= depth
- (depth - @my_stack.length + 1).times {
- e = PullEvent.new(@parser.pull)
- @my_stack.push(e)
- }
- end
- @my_stack[depth]
- end
-
- def pull
- return @my_stack.shift if @my_stack.length > 0
-
- event = @parser.pull
- case event[0]
- when :entitydecl
- @entities[ event[1] ] =
- event[2] unless event[2] =~ /PUBLIC|SYSTEM/
- when :text
- unnormalized = @parser.unnormalize( event[1], @entities )
- event << unnormalized
- end
- PullEvent.new( event )
- end
-
- def unshift token
- @my_stack.unshift token
- end
- end
-
- # A parsing event. The contents of the event are accessed as an +Array?,
- # and the type is given either by the ...? methods, or by accessing the
- # +type+ accessor. The contents of this object vary from event to event,
- # but are identical to the arguments passed to +StreamListener+s for each
- # event.
- class PullEvent
- # The type of this event. Will be one of :tag_start, :tag_end, :text,
- # :processing_instruction, :comment, :doctype, :attlistdecl, :entitydecl,
- # :notationdecl, :entity, :cdata, :xmldecl, or :error.
- def initialize(arg)
- @contents = arg
- end
-
- def []( start, endd=nil)
- if start.kind_of? Range
- @contents.slice( start.begin+1 .. start.end )
- elsif start.kind_of? Numeric
- if endd.nil?
- @contents.slice( start+1 )
- else
- @contents.slice( start+1, endd )
- end
- else
- raise "Illegal argument #{start.inspect} (#{start.class})"
- end
- end
-
- def event_type
- @contents[0]
- end
-
- # Content: [ String tag_name, Hash attributes ]
- def start_element?
- @contents[0] == :start_element
- end
-
- # Content: [ String tag_name ]
- def end_element?
- @contents[0] == :end_element
- end
-
- # Content: [ String raw_text, String unnormalized_text ]
- def text?
- @contents[0] == :text
- end
-
- # Content: [ String text ]
- def instruction?
- @contents[0] == :processing_instruction
- end
-
- # Content: [ String text ]
- def comment?
- @contents[0] == :comment
- end
-
- # Content: [ String name, String pub_sys, String long_name, String uri ]
- def doctype?
- @contents[0] == :start_doctype
- end
-
- # Content: [ String text ]
- def attlistdecl?
- @contents[0] == :attlistdecl
- end
-
- # Content: [ String text ]
- def elementdecl?
- @contents[0] == :elementdecl
- end
-
- # Due to the wonders of DTDs, an entity declaration can be just about
- # anything. There's no way to normalize it; you'll have to interpret the
- # content yourself. However, the following is true:
- #
- # * If the entity declaration is an internal entity:
- # [ String name, String value ]
- # Content: [ String text ]
- def entitydecl?
- @contents[0] == :entitydecl
- end
-
- # Content: [ String text ]
- def notationdecl?
- @contents[0] == :notationdecl
- end
-
- # Content: [ String text ]
- def entity?
- @contents[0] == :entity
- end
-
- # Content: [ String text ]
- def cdata?
- @contents[0] == :cdata
- end
-
- # Content: [ String version, String encoding, String standalone ]
- def xmldecl?
- @contents[0] == :xmldecl
- end
-
- def error?
- @contents[0] == :error
- end
-
- def inspect
- @contents[0].to_s + ": " + @contents[1..-1].inspect
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/parsers/sax2parser.rb b/ruby_2_2/lib/rexml/parsers/sax2parser.rb
deleted file mode 100644
index a72c0a7971..0000000000
--- a/ruby_2_2/lib/rexml/parsers/sax2parser.rb
+++ /dev/null
@@ -1,272 +0,0 @@
-require 'rexml/parsers/baseparser'
-require 'rexml/parseexception'
-require 'rexml/namespace'
-require 'rexml/text'
-
-module REXML
- module Parsers
- # SAX2Parser
- class SAX2Parser
- def initialize source
- @parser = BaseParser.new(source)
- @listeners = []
- @procs = []
- @namespace_stack = []
- @has_listeners = false
- @tag_stack = []
- @entities = {}
- end
-
- def source
- @parser.source
- end
-
- def add_listener( listener )
- @parser.add_listener( listener )
- end
-
- # Listen arguments:
- #
- # Symbol, Array, Block
- # Listen to Symbol events on Array elements
- # Symbol, Block
- # Listen to Symbol events
- # Array, Listener
- # Listen to all events on Array elements
- # Array, Block
- # Listen to :start_element events on Array elements
- # Listener
- # Listen to All events
- #
- # Symbol can be one of: :start_element, :end_element,
- # :start_prefix_mapping, :end_prefix_mapping, :characters,
- # :processing_instruction, :doctype, :attlistdecl, :elementdecl,
- # :entitydecl, :notationdecl, :cdata, :xmldecl, :comment
- #
- # There is an additional symbol that can be listened for: :progress.
- # This will be called for every event generated, passing in the current
- # stream position.
- #
- # Array contains regular expressions or strings which will be matched
- # against fully qualified element names.
- #
- # Listener must implement the methods in SAX2Listener
- #
- # Block will be passed the same arguments as a SAX2Listener method would
- # be, where the method name is the same as the matched Symbol.
- # See the SAX2Listener for more information.
- def listen( *args, &blok )
- if args[0].kind_of? Symbol
- if args.size == 2
- args[1].each { |match| @procs << [args[0], match, blok] }
- else
- add( [args[0], nil, blok] )
- end
- elsif args[0].kind_of? Array
- if args.size == 2
- args[0].each { |match| add( [nil, match, args[1]] ) }
- else
- args[0].each { |match| add( [ :start_element, match, blok ] ) }
- end
- else
- add([nil, nil, args[0]])
- end
- end
-
- def deafen( listener=nil, &blok )
- if listener
- @listeners.delete_if {|item| item[-1] == listener }
- @has_listeners = false if @listeners.size == 0
- else
- @procs.delete_if {|item| item[-1] == blok }
- end
- end
-
- def parse
- @procs.each { |sym,match,block| block.call if sym == :start_document }
- @listeners.each { |sym,match,block|
- block.start_document if sym == :start_document or sym.nil?
- }
- context = []
- while true
- event = @parser.pull
- case event[0]
- when :end_document
- handle( :end_document )
- break
- when :start_doctype
- handle( :doctype, *event[1..-1])
- when :end_doctype
- context = context[1]
- when :start_element
- @tag_stack.push(event[1])
- # find the observers for namespaces
- procs = get_procs( :start_prefix_mapping, event[1] )
- listeners = get_listeners( :start_prefix_mapping, event[1] )
- if procs or listeners
- # break out the namespace declarations
- # The attributes live in event[2]
- event[2].each {|n, v| event[2][n] = @parser.normalize(v)}
- nsdecl = event[2].find_all { |n, value| n =~ /^xmlns(:|$)/ }
- nsdecl.collect! { |n, value| [ n[6..-1], value ] }
- @namespace_stack.push({})
- nsdecl.each do |n,v|
- @namespace_stack[-1][n] = v
- # notify observers of namespaces
- procs.each { |ob| ob.call( n, v ) } if procs
- listeners.each { |ob| ob.start_prefix_mapping(n, v) } if listeners
- end
- end
- event[1] =~ Namespace::NAMESPLIT
- prefix = $1
- local = $2
- uri = get_namespace(prefix)
- # find the observers for start_element
- procs = get_procs( :start_element, event[1] )
- listeners = get_listeners( :start_element, event[1] )
- # notify observers
- procs.each { |ob| ob.call( uri, local, event[1], event[2] ) } if procs
- listeners.each { |ob|
- ob.start_element( uri, local, event[1], event[2] )
- } if listeners
- when :end_element
- @tag_stack.pop
- event[1] =~ Namespace::NAMESPLIT
- prefix = $1
- local = $2
- uri = get_namespace(prefix)
- # find the observers for start_element
- procs = get_procs( :end_element, event[1] )
- listeners = get_listeners( :end_element, event[1] )
- # notify observers
- procs.each { |ob| ob.call( uri, local, event[1] ) } if procs
- listeners.each { |ob|
- ob.end_element( uri, local, event[1] )
- } if listeners
-
- namespace_mapping = @namespace_stack.pop
- # find the observers for namespaces
- procs = get_procs( :end_prefix_mapping, event[1] )
- listeners = get_listeners( :end_prefix_mapping, event[1] )
- if procs or listeners
- namespace_mapping.each do |ns_prefix, ns_uri|
- # notify observers of namespaces
- procs.each { |ob| ob.call( ns_prefix ) } if procs
- listeners.each { |ob| ob.end_prefix_mapping(ns_prefix) } if listeners
- end
- end
- when :text
- #normalized = @parser.normalize( event[1] )
- #handle( :characters, normalized )
- copy = event[1].clone
-
- esub = proc { |match|
- if @entities.has_key?($1)
- @entities[$1].gsub(Text::REFERENCE, &esub)
- else
- match
- end
- }
-
- copy.gsub!( Text::REFERENCE, &esub )
- copy.gsub!( Text::NUMERICENTITY ) {|m|
- m=$1
- m = "0#{m}" if m[0] == ?x
- [Integer(m)].pack('U*')
- }
- handle( :characters, copy )
- when :entitydecl
- handle_entitydecl( event )
- when :processing_instruction, :comment, :attlistdecl,
- :elementdecl, :cdata, :notationdecl, :xmldecl
- handle( *event )
- end
- handle( :progress, @parser.position )
- end
- end
-
- private
- def handle( symbol, *arguments )
- tag = @tag_stack[-1]
- procs = get_procs( symbol, tag )
- listeners = get_listeners( symbol, tag )
- # notify observers
- procs.each { |ob| ob.call( *arguments ) } if procs
- listeners.each { |l|
- l.send( symbol.to_s, *arguments )
- } if listeners
- end
-
- def handle_entitydecl( event )
- @entities[ event[1] ] = event[2] if event.size == 3
- parameter_reference_p = false
- case event[2]
- when "SYSTEM"
- if event.size == 5
- if event.last == "%"
- parameter_reference_p = true
- else
- event[4, 0] = "NDATA"
- end
- end
- when "PUBLIC"
- if event.size == 6
- if event.last == "%"
- parameter_reference_p = true
- else
- event[5, 0] = "NDATA"
- end
- end
- else
- parameter_reference_p = (event.size == 4)
- end
- event[1, 0] = event.pop if parameter_reference_p
- handle( event[0], event[1..-1] )
- end
-
- # The following methods are duplicates, but it is faster than using
- # a helper
- def get_procs( symbol, name )
- return nil if @procs.size == 0
- @procs.find_all do |sym, match, block|
- (
- (sym.nil? or symbol == sym) and
- ((name.nil? and match.nil?) or match.nil? or (
- (name == match) or
- (match.kind_of? Regexp and name =~ match)
- )
- )
- )
- end.collect{|x| x[-1]}
- end
- def get_listeners( symbol, name )
- return nil if @listeners.size == 0
- @listeners.find_all do |sym, match, block|
- (
- (sym.nil? or symbol == sym) and
- ((name.nil? and match.nil?) or match.nil? or (
- (name == match) or
- (match.kind_of? Regexp and name =~ match)
- )
- )
- )
- end.collect{|x| x[-1]}
- end
-
- def add( pair )
- if pair[-1].respond_to? :call
- @procs << pair unless @procs.include? pair
- else
- @listeners << pair unless @listeners.include? pair
- @has_listeners = true
- end
- end
-
- def get_namespace( prefix )
- uris = (@namespace_stack.find_all { |ns| not ns[prefix].nil? }) ||
- (@namespace_stack.find { |ns| not ns[nil].nil? })
- uris[-1][prefix] unless uris.nil? or 0 == uris.size
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/parsers/streamparser.rb b/ruby_2_2/lib/rexml/parsers/streamparser.rb
deleted file mode 100644
index 9ea65ed3d1..0000000000
--- a/ruby_2_2/lib/rexml/parsers/streamparser.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-require "rexml/parsers/baseparser"
-
-module REXML
- module Parsers
- class StreamParser
- def initialize source, listener
- @listener = listener
- @parser = BaseParser.new( source )
- end
-
- def add_listener( listener )
- @parser.add_listener( listener )
- end
-
- def parse
- # entity string
- while true
- event = @parser.pull
- case event[0]
- when :end_document
- return
- when :start_element
- attrs = event[2].each do |n, v|
- event[2][n] = @parser.unnormalize( v )
- end
- @listener.tag_start( event[1], attrs )
- when :end_element
- @listener.tag_end( event[1] )
- when :text
- normalized = @parser.unnormalize( event[1] )
- @listener.text( normalized )
- when :processing_instruction
- @listener.instruction( *event[1,2] )
- when :start_doctype
- @listener.doctype( *event[1..-1] )
- when :end_doctype
- # FIXME: remove this condition for milestone:3.2
- @listener.doctype_end if @listener.respond_to? :doctype_end
- when :comment, :attlistdecl, :cdata, :xmldecl, :elementdecl
- @listener.send( event[0].to_s, *event[1..-1] )
- when :entitydecl, :notationdecl
- @listener.send( event[0].to_s, event[1..-1] )
- when :externalentity
- entity_reference = event[1]
- content = entity_reference.gsub(/\A%|;\z/, "")
- @listener.entity(content)
- end
- end
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/parsers/treeparser.rb b/ruby_2_2/lib/rexml/parsers/treeparser.rb
deleted file mode 100644
index 68edb77759..0000000000
--- a/ruby_2_2/lib/rexml/parsers/treeparser.rb
+++ /dev/null
@@ -1,100 +0,0 @@
-require 'rexml/validation/validationexception'
-require 'rexml/undefinednamespaceexception'
-
-module REXML
- module Parsers
- class TreeParser
- def initialize( source, build_context = Document.new )
- @build_context = build_context
- @parser = Parsers::BaseParser.new( source )
- end
-
- def add_listener( listener )
- @parser.add_listener( listener )
- end
-
- def parse
- tag_stack = []
- in_doctype = false
- entities = nil
- begin
- while true
- event = @parser.pull
- #STDERR.puts "TREEPARSER GOT #{event.inspect}"
- case event[0]
- when :end_document
- unless tag_stack.empty?
- raise ParseException.new("No close tag for #{@build_context.xpath}",
- @parser.source, @parser)
- end
- return
- when :start_element
- tag_stack.push(event[1])
- el = @build_context = @build_context.add_element( event[1] )
- event[2].each do |key, value|
- el.attributes[key]=Attribute.new(key,value,self)
- end
- when :end_element
- tag_stack.pop
- @build_context = @build_context.parent
- when :text
- if not in_doctype
- if @build_context[-1].instance_of? Text
- @build_context[-1] << event[1]
- else
- @build_context.add(
- Text.new(event[1], @build_context.whitespace, nil, true)
- ) unless (
- @build_context.ignore_whitespace_nodes and
- event[1].strip.size==0
- )
- end
- end
- when :comment
- c = Comment.new( event[1] )
- @build_context.add( c )
- when :cdata
- c = CData.new( event[1] )
- @build_context.add( c )
- when :processing_instruction
- @build_context.add( Instruction.new( event[1], event[2] ) )
- when :end_doctype
- in_doctype = false
- entities.each { |k,v| entities[k] = @build_context.entities[k].value }
- @build_context = @build_context.parent
- when :start_doctype
- doctype = DocType.new( event[1..-1], @build_context )
- @build_context = doctype
- entities = {}
- in_doctype = true
- when :attlistdecl
- n = AttlistDecl.new( event[1..-1] )
- @build_context.add( n )
- when :externalentity
- n = ExternalEntity.new( event[1] )
- @build_context.add( n )
- when :elementdecl
- n = ElementDecl.new( event[1] )
- @build_context.add(n)
- when :entitydecl
- entities[ event[1] ] = event[2] unless event[2] =~ /PUBLIC|SYSTEM/
- @build_context.add(Entity.new(event))
- when :notationdecl
- n = NotationDecl.new( *event[1..-1] )
- @build_context.add( n )
- when :xmldecl
- x = XMLDecl.new( event[1], event[2], event[3] )
- @build_context.add( x )
- end
- end
- rescue REXML::Validation::ValidationException
- raise
- rescue REXML::ParseException
- raise
- rescue
- raise ParseException.new( $!.message, @parser.source, @parser, $! )
- end
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/parsers/ultralightparser.rb b/ruby_2_2/lib/rexml/parsers/ultralightparser.rb
deleted file mode 100644
index 4e2d7a81cf..0000000000
--- a/ruby_2_2/lib/rexml/parsers/ultralightparser.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-require 'rexml/parsers/streamparser'
-require 'rexml/parsers/baseparser'
-
-module REXML
- module Parsers
- class UltraLightParser
- def initialize stream
- @stream = stream
- @parser = REXML::Parsers::BaseParser.new( stream )
- end
-
- def add_listener( listener )
- @parser.add_listener( listener )
- end
-
- def rewind
- @stream.rewind
- @parser.stream = @stream
- end
-
- def parse
- root = context = []
- while true
- event = @parser.pull
- case event[0]
- when :end_document
- break
- when :end_doctype
- context = context[1]
- when :start_element, :start_doctype
- context << event
- event[1,0] = [context]
- context = event
- when :end_element
- context = context[1]
- else
- context << event
- end
- end
- root
- end
- end
-
- # An element is an array. The array contains:
- # 0 The parent element
- # 1 The tag name
- # 2 A hash of attributes
- # 3..-1 The child elements
- # An element is an array of size > 3
- # Text is a String
- # PIs are [ :processing_instruction, target, data ]
- # Comments are [ :comment, data ]
- # DocTypes are DocType structs
- # The root is an array with XMLDecls, Text, DocType, Array, Text
- end
-end
diff --git a/ruby_2_2/lib/rexml/parsers/xpathparser.rb b/ruby_2_2/lib/rexml/parsers/xpathparser.rb
deleted file mode 100644
index 57767fbcd1..0000000000
--- a/ruby_2_2/lib/rexml/parsers/xpathparser.rb
+++ /dev/null
@@ -1,656 +0,0 @@
-require 'rexml/namespace'
-require 'rexml/xmltokens'
-
-module REXML
- module Parsers
- # You don't want to use this class. Really. Use XPath, which is a wrapper
- # for this class. Believe me. You don't want to poke around in here.
- # There is strange, dark magic at work in this code. Beware. Go back! Go
- # back while you still can!
- class XPathParser
- include XMLTokens
- LITERAL = /^'([^']*)'|^"([^"]*)"/u
-
- def namespaces=( namespaces )
- Functions::namespace_context = namespaces
- @namespaces = namespaces
- end
-
- def parse path
- path = path.dup
- path.gsub!(/([\(\[])\s+/, '\1') # Strip ignorable spaces
- path.gsub!( /\s+([\]\)])/, '\1')
- parsed = []
- OrExpr(path, parsed)
- parsed
- end
-
- def predicate path
- parsed = []
- Predicate( "[#{path}]", parsed )
- parsed
- end
-
- def abbreviate( path )
- path = path.kind_of?(String) ? parse( path ) : path
- string = ""
- document = false
- while path.size > 0
- op = path.shift
- case op
- when :node
- when :attribute
- string << "/" if string.size > 0
- string << "@"
- when :child
- string << "/" if string.size > 0
- when :descendant_or_self
- string << "/"
- when :self
- string << "."
- when :parent
- string << ".."
- when :any
- string << "*"
- when :text
- string << "text()"
- when :following, :following_sibling,
- :ancestor, :ancestor_or_self, :descendant,
- :namespace, :preceding, :preceding_sibling
- string << "/" unless string.size == 0
- string << op.to_s.tr("_", "-")
- string << "::"
- when :qname
- prefix = path.shift
- name = path.shift
- string << prefix+":" if prefix.size > 0
- string << name
- when :predicate
- string << '['
- string << predicate_to_string( path.shift ) {|x| abbreviate( x ) }
- string << ']'
- when :document
- document = true
- when :function
- string << path.shift
- string << "( "
- string << predicate_to_string( path.shift[0] ) {|x| abbreviate( x )}
- string << " )"
- when :literal
- string << %Q{ "#{path.shift}" }
- else
- string << "/" unless string.size == 0
- string << "UNKNOWN("
- string << op.inspect
- string << ")"
- end
- end
- string = "/"+string if document
- return string
- end
-
- def expand( path )
- path = path.kind_of?(String) ? parse( path ) : path
- string = ""
- document = false
- while path.size > 0
- op = path.shift
- case op
- when :node
- string << "node()"
- when :attribute, :child, :following, :following_sibling,
- :ancestor, :ancestor_or_self, :descendant, :descendant_or_self,
- :namespace, :preceding, :preceding_sibling, :self, :parent
- string << "/" unless string.size == 0
- string << op.to_s.tr("_", "-")
- string << "::"
- when :any
- string << "*"
- when :qname
- prefix = path.shift
- name = path.shift
- string << prefix+":" if prefix.size > 0
- string << name
- when :predicate
- string << '['
- string << predicate_to_string( path.shift ) { |x| expand(x) }
- string << ']'
- when :document
- document = true
- else
- string << "/" unless string.size == 0
- string << "UNKNOWN("
- string << op.inspect
- string << ")"
- end
- end
- string = "/"+string if document
- return string
- end
-
- def predicate_to_string( path, &block )
- string = ""
- case path[0]
- when :and, :or, :mult, :plus, :minus, :neq, :eq, :lt, :gt, :lteq, :gteq, :div, :mod, :union
- op = path.shift
- case op
- when :eq
- op = "="
- when :lt
- op = "<"
- when :gt
- op = ">"
- when :lteq
- op = "<="
- when :gteq
- op = ">="
- when :neq
- op = "!="
- when :union
- op = "|"
- end
- left = predicate_to_string( path.shift, &block )
- right = predicate_to_string( path.shift, &block )
- string << " "
- string << left
- string << " "
- string << op.to_s
- string << " "
- string << right
- string << " "
- when :function
- path.shift
- name = path.shift
- string << name
- string << "( "
- string << predicate_to_string( path.shift, &block )
- string << " )"
- when :literal
- path.shift
- string << " "
- string << path.shift.inspect
- string << " "
- else
- string << " "
- string << yield( path )
- string << " "
- end
- return string.squeeze(" ")
- end
-
- private
- #LocationPath
- # | RelativeLocationPath
- # | '/' RelativeLocationPath?
- # | '//' RelativeLocationPath
- def LocationPath path, parsed
- path = path.strip
- if path[0] == ?/
- parsed << :document
- if path[1] == ?/
- parsed << :descendant_or_self
- parsed << :node
- path = path[2..-1]
- else
- path = path[1..-1]
- end
- end
- return RelativeLocationPath( path, parsed ) if path.size > 0
- end
-
- #RelativeLocationPath
- # | Step
- # | (AXIS_NAME '::' | '@' | '') AxisSpecifier
- # NodeTest
- # Predicate
- # | '.' | '..' AbbreviatedStep
- # | RelativeLocationPath '/' Step
- # | RelativeLocationPath '//' Step
- AXIS = /^(ancestor|ancestor-or-self|attribute|child|descendant|descendant-or-self|following|following-sibling|namespace|parent|preceding|preceding-sibling|self)::/
- def RelativeLocationPath path, parsed
- while path.size > 0
- # (axis or @ or <child::>) nodetest predicate >
- # OR > / Step
- # (. or ..) >
- if path[0] == ?.
- if path[1] == ?.
- parsed << :parent
- parsed << :node
- path = path[2..-1]
- else
- parsed << :self
- parsed << :node
- path = path[1..-1]
- end
- else
- if path[0] == ?@
- parsed << :attribute
- path = path[1..-1]
- # Goto Nodetest
- elsif path =~ AXIS
- parsed << $1.tr('-','_').intern
- path = $'
- # Goto Nodetest
- else
- parsed << :child
- end
-
- n = []
- path = NodeTest( path, n)
-
- if path[0] == ?[
- path = Predicate( path, n )
- end
-
- parsed.concat(n)
- end
-
- if path.size > 0
- if path[0] == ?/
- if path[1] == ?/
- parsed << :descendant_or_self
- parsed << :node
- path = path[2..-1]
- else
- path = path[1..-1]
- end
- else
- return path
- end
- end
- end
- return path
- end
-
- # Returns a 1-1 map of the nodeset
- # The contents of the resulting array are either:
- # true/false, if a positive match
- # String, if a name match
- #NodeTest
- # | ('*' | NCNAME ':' '*' | QNAME) NameTest
- # | NODE_TYPE '(' ')' NodeType
- # | PI '(' LITERAL ')' PI
- # | '[' expr ']' Predicate
- NCNAMETEST= /^(#{NCNAME_STR}):\*/u
- QNAME = Namespace::NAMESPLIT
- NODE_TYPE = /^(comment|text|node)\(\s*\)/m
- PI = /^processing-instruction\(/
- def NodeTest path, parsed
- case path
- when /^\*/
- path = $'
- parsed << :any
- when NODE_TYPE
- type = $1
- path = $'
- parsed << type.tr('-', '_').intern
- when PI
- path = $'
- literal = nil
- if path !~ /^\s*\)/
- path =~ LITERAL
- literal = $1
- path = $'
- raise ParseException.new("Missing ')' after processing instruction") if path[0] != ?)
- path = path[1..-1]
- end
- parsed << :processing_instruction
- parsed << (literal || '')
- when NCNAMETEST
- prefix = $1
- path = $'
- parsed << :namespace
- parsed << prefix
- when QNAME
- prefix = $1
- name = $2
- path = $'
- prefix = "" unless prefix
- parsed << :qname
- parsed << prefix
- parsed << name
- end
- return path
- end
-
- # Filters the supplied nodeset on the predicate(s)
- def Predicate path, parsed
- return nil unless path[0] == ?[
- predicates = []
- while path[0] == ?[
- path, expr = get_group(path)
- predicates << expr[1..-2] if expr
- end
- predicates.each{ |pred|
- preds = []
- parsed << :predicate
- parsed << preds
- OrExpr(pred, preds)
- }
- path
- end
-
- # The following return arrays of true/false, a 1-1 mapping of the
- # supplied nodeset, except for axe(), which returns a filtered
- # nodeset
-
- #| OrExpr S 'or' S AndExpr
- #| AndExpr
- def OrExpr path, parsed
- n = []
- rest = AndExpr( path, n )
- if rest != path
- while rest =~ /^\s*( or )/
- n = [ :or, n, [] ]
- rest = AndExpr( $', n[-1] )
- end
- end
- if parsed.size == 0 and n.size != 0
- parsed.replace(n)
- elsif n.size > 0
- parsed << n
- end
- rest
- end
-
- #| AndExpr S 'and' S EqualityExpr
- #| EqualityExpr
- def AndExpr path, parsed
- n = []
- rest = EqualityExpr( path, n )
- if rest != path
- while rest =~ /^\s*( and )/
- n = [ :and, n, [] ]
- rest = EqualityExpr( $', n[-1] )
- end
- end
- if parsed.size == 0 and n.size != 0
- parsed.replace(n)
- elsif n.size > 0
- parsed << n
- end
- rest
- end
-
- #| EqualityExpr ('=' | '!=') RelationalExpr
- #| RelationalExpr
- def EqualityExpr path, parsed
- n = []
- rest = RelationalExpr( path, n )
- if rest != path
- while rest =~ /^\s*(!?=)\s*/
- if $1[0] == ?!
- n = [ :neq, n, [] ]
- else
- n = [ :eq, n, [] ]
- end
- rest = RelationalExpr( $', n[-1] )
- end
- end
- if parsed.size == 0 and n.size != 0
- parsed.replace(n)
- elsif n.size > 0
- parsed << n
- end
- rest
- end
-
- #| RelationalExpr ('<' | '>' | '<=' | '>=') AdditiveExpr
- #| AdditiveExpr
- def RelationalExpr path, parsed
- n = []
- rest = AdditiveExpr( path, n )
- if rest != path
- while rest =~ /^\s*([<>]=?)\s*/
- if $1[0] == ?<
- sym = "lt"
- else
- sym = "gt"
- end
- sym << "eq" if $1[-1] == ?=
- n = [ sym.intern, n, [] ]
- rest = AdditiveExpr( $', n[-1] )
- end
- end
- if parsed.size == 0 and n.size != 0
- parsed.replace(n)
- elsif n.size > 0
- parsed << n
- end
- rest
- end
-
- #| AdditiveExpr ('+' | S '-') MultiplicativeExpr
- #| MultiplicativeExpr
- def AdditiveExpr path, parsed
- n = []
- rest = MultiplicativeExpr( path, n )
- if rest != path
- while rest =~ /^\s*(\+| -)\s*/
- if $1[0] == ?+
- n = [ :plus, n, [] ]
- else
- n = [ :minus, n, [] ]
- end
- rest = MultiplicativeExpr( $', n[-1] )
- end
- end
- if parsed.size == 0 and n.size != 0
- parsed.replace(n)
- elsif n.size > 0
- parsed << n
- end
- rest
- end
-
- #| MultiplicativeExpr ('*' | S ('div' | 'mod') S) UnaryExpr
- #| UnaryExpr
- def MultiplicativeExpr path, parsed
- n = []
- rest = UnaryExpr( path, n )
- if rest != path
- while rest =~ /^\s*(\*| div | mod )\s*/
- if $1[0] == ?*
- n = [ :mult, n, [] ]
- elsif $1.include?( "div" )
- n = [ :div, n, [] ]
- else
- n = [ :mod, n, [] ]
- end
- rest = UnaryExpr( $', n[-1] )
- end
- end
- if parsed.size == 0 and n.size != 0
- parsed.replace(n)
- elsif n.size > 0
- parsed << n
- end
- rest
- end
-
- #| '-' UnaryExpr
- #| UnionExpr
- def UnaryExpr path, parsed
- path =~ /^(\-*)/
- path = $'
- if $1 and (($1.size % 2) != 0)
- mult = -1
- else
- mult = 1
- end
- parsed << :neg if mult < 0
-
- n = []
- path = UnionExpr( path, n )
- parsed.concat( n )
- path
- end
-
- #| UnionExpr '|' PathExpr
- #| PathExpr
- def UnionExpr path, parsed
- n = []
- rest = PathExpr( path, n )
- if rest != path
- while rest =~ /^\s*(\|)\s*/
- n = [ :union, n, [] ]
- rest = PathExpr( $', n[-1] )
- end
- end
- if parsed.size == 0 and n.size != 0
- parsed.replace( n )
- elsif n.size > 0
- parsed << n
- end
- rest
- end
-
- #| LocationPath
- #| FilterExpr ('/' | '//') RelativeLocationPath
- def PathExpr path, parsed
- path =~ /^\s*/
- path = $'
- n = []
- rest = FilterExpr( path, n )
- if rest != path
- if rest and rest[0] == ?/
- return RelativeLocationPath(rest, n)
- end
- end
- rest = LocationPath(rest, n) if rest =~ /\A[\/\.\@\[\w*]/
- parsed.concat(n)
- return rest
- end
-
- #| FilterExpr Predicate
- #| PrimaryExpr
- def FilterExpr path, parsed
- n = []
- path = PrimaryExpr( path, n )
- path = Predicate(path, n) if path and path[0] == ?[
- parsed.concat(n)
- path
- end
-
- #| VARIABLE_REFERENCE
- #| '(' expr ')'
- #| LITERAL
- #| NUMBER
- #| FunctionCall
- VARIABLE_REFERENCE = /^\$(#{NAME_STR})/u
- NUMBER = /^(\d*\.?\d+)/
- NT = /^comment|text|processing-instruction|node$/
- def PrimaryExpr path, parsed
- case path
- when VARIABLE_REFERENCE
- varname = $1
- path = $'
- parsed << :variable
- parsed << varname
- #arry << @variables[ varname ]
- when /^(\w[-\w]*)(?:\()/
- fname = $1
- tmp = $'
- return path if fname =~ NT
- path = tmp
- parsed << :function
- parsed << fname
- path = FunctionCall(path, parsed)
- when NUMBER
- varname = $1.nil? ? $2 : $1
- path = $'
- parsed << :literal
- parsed << (varname.include?('.') ? varname.to_f : varname.to_i)
- when LITERAL
- varname = $1.nil? ? $2 : $1
- path = $'
- parsed << :literal
- parsed << varname
- when /^\(/ #/
- path, contents = get_group(path)
- contents = contents[1..-2]
- n = []
- OrExpr( contents, n )
- parsed.concat(n)
- end
- path
- end
-
- #| FUNCTION_NAME '(' ( expr ( ',' expr )* )? ')'
- def FunctionCall rest, parsed
- path, arguments = parse_args(rest)
- argset = []
- for argument in arguments
- args = []
- OrExpr( argument, args )
- argset << args
- end
- parsed << argset
- path
- end
-
- # get_group( '[foo]bar' ) -> ['bar', '[foo]']
- def get_group string
- ind = 0
- depth = 0
- st = string[0,1]
- en = (st == "(" ? ")" : "]")
- begin
- case string[ind,1]
- when st
- depth += 1
- when en
- depth -= 1
- end
- ind += 1
- end while depth > 0 and ind < string.length
- return nil unless depth==0
- [string[ind..-1], string[0..ind-1]]
- end
-
- def parse_args( string )
- arguments = []
- ind = 0
- inquot = false
- inapos = false
- depth = 1
- begin
- case string[ind]
- when ?"
- inquot = !inquot unless inapos
- when ?'
- inapos = !inapos unless inquot
- else
- unless inquot or inapos
- case string[ind]
- when ?(
- depth += 1
- if depth == 1
- string = string[1..-1]
- ind -= 1
- end
- when ?)
- depth -= 1
- if depth == 0
- s = string[0,ind].strip
- arguments << s unless s == ""
- string = string[ind+1..-1]
- end
- when ?,
- if depth == 1
- s = string[0,ind].strip
- arguments << s unless s == ""
- string = string[ind+1..-1]
- ind = -1
- end
- end
- end
- end
- ind += 1
- end while depth > 0 and ind < string.length
- return nil unless depth==0
- [string,arguments]
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/quickpath.rb b/ruby_2_2/lib/rexml/quickpath.rb
deleted file mode 100644
index 9bec2158dd..0000000000
--- a/ruby_2_2/lib/rexml/quickpath.rb
+++ /dev/null
@@ -1,265 +0,0 @@
-require 'rexml/functions'
-require 'rexml/xmltokens'
-
-module REXML
- class QuickPath
- include Functions
- include XMLTokens
-
- # A base Hash object to be used when initializing a
- # default empty namespaces set.
- EMPTY_HASH = {}
-
- def QuickPath::first element, path, namespaces=EMPTY_HASH
- match(element, path, namespaces)[0]
- end
-
- def QuickPath::each element, path, namespaces=EMPTY_HASH, &block
- path = "*" unless path
- match(element, path, namespaces).each( &block )
- end
-
- def QuickPath::match element, path, namespaces=EMPTY_HASH
- raise "nil is not a valid xpath" unless path
- results = nil
- Functions::namespace_context = namespaces
- case path
- when /^\/([^\/]|$)/u
- # match on root
- path = path[1..-1]
- return [element.root.parent] if path == ''
- results = filter([element.root], path)
- when /^[-\w]*::/u
- results = filter([element], path)
- when /^\*/u
- results = filter(element.to_a, path)
- when /^[\[!\w:]/u
- # match on child
- children = element.to_a
- results = filter(children, path)
- else
- results = filter([element], path)
- end
- return results
- end
-
- # Given an array of nodes it filters the array based on the path. The
- # result is that when this method returns, the array will contain elements
- # which match the path
- def QuickPath::filter elements, path
- return elements if path.nil? or path == '' or elements.size == 0
- case path
- when /^\/\//u # Descendant
- return axe( elements, "descendant-or-self", $' )
- when /^\/?\b(\w[-\w]*)\b::/u # Axe
- return axe( elements, $1, $' )
- when /^\/(?=\b([:!\w][-\.\w]*:)?[-!\*\.\w]*\b([^:(]|$)|\*)/u # Child
- rest = $'
- results = []
- elements.each do |element|
- results |= filter( element.to_a, rest )
- end
- return results
- when /^\/?(\w[-\w]*)\(/u # / Function
- return function( elements, $1, $' )
- when Namespace::NAMESPLIT # Element name
- name = $2
- ns = $1
- rest = $'
- elements.delete_if do |element|
- !(element.kind_of? Element and
- (element.expanded_name == name or
- (element.name == name and
- element.namespace == Functions.namespace_context[ns])))
- end
- return filter( elements, rest )
- when /^\/\[/u
- matches = []
- elements.each do |element|
- matches |= predicate( element.to_a, path[1..-1] ) if element.kind_of? Element
- end
- return matches
- when /^\[/u # Predicate
- return predicate( elements, path )
- when /^\/?\.\.\./u # Ancestor
- return axe( elements, "ancestor", $' )
- when /^\/?\.\./u # Parent
- return filter( elements.collect{|e|e.parent}, $' )
- when /^\/?\./u # Self
- return filter( elements, $' )
- when /^\*/u # Any
- results = []
- elements.each do |element|
- results |= filter( [element], $' ) if element.kind_of? Element
- #if element.kind_of? Element
- # children = element.to_a
- # children.delete_if { |child| !child.kind_of?(Element) }
- # results |= filter( children, $' )
- #end
- end
- return results
- end
- return []
- end
-
- def QuickPath::axe( elements, axe_name, rest )
- matches = []
- matches = filter( elements.dup, rest ) if axe_name =~ /-or-self$/u
- case axe_name
- when /^descendant/u
- elements.each do |element|
- matches |= filter( element.to_a, "descendant-or-self::#{rest}" ) if element.kind_of? Element
- end
- when /^ancestor/u
- elements.each do |element|
- while element.parent
- matches << element.parent
- element = element.parent
- end
- end
- matches = filter( matches, rest )
- when "self"
- matches = filter( elements, rest )
- when "child"
- elements.each do |element|
- matches |= filter( element.to_a, rest ) if element.kind_of? Element
- end
- when "attribute"
- elements.each do |element|
- matches << element.attributes[ rest ] if element.kind_of? Element
- end
- when "parent"
- matches = filter(elements.collect{|element| element.parent}.uniq, rest)
- when "following-sibling"
- matches = filter(elements.collect{|element| element.next_sibling}.uniq,
- rest)
- when "previous-sibling"
- matches = filter(elements.collect{|element|
- element.previous_sibling}.uniq, rest )
- end
- return matches.uniq
- end
-
- OPERAND_ = '((?=(?:(?!and|or).)*[^\s<>=])[^\s<>=]+)'
- # A predicate filters a node-set with respect to an axis to produce a
- # new node-set. For each node in the node-set to be filtered, the
- # PredicateExpr is evaluated with that node as the context node, with
- # the number of nodes in the node-set as the context size, and with the
- # proximity position of the node in the node-set with respect to the
- # axis as the context position; if PredicateExpr evaluates to true for
- # that node, the node is included in the new node-set; otherwise, it is
- # not included.
- #
- # A PredicateExpr is evaluated by evaluating the Expr and converting
- # the result to a boolean. If the result is a number, the result will
- # be converted to true if the number is equal to the context position
- # and will be converted to false otherwise; if the result is not a
- # number, then the result will be converted as if by a call to the
- # boolean function. Thus a location path para[3] is equivalent to
- # para[position()=3].
- def QuickPath::predicate( elements, path )
- ind = 1
- bcount = 1
- while bcount > 0
- bcount += 1 if path[ind] == ?[
- bcount -= 1 if path[ind] == ?]
- ind += 1
- end
- ind -= 1
- predicate = path[1..ind-1]
- rest = path[ind+1..-1]
-
- # have to change 'a [=<>] b [=<>] c' into 'a [=<>] b and b [=<>] c'
- #
- predicate.gsub!(
- /#{OPERAND_}\s*([<>=])\s*#{OPERAND_}\s*([<>=])\s*#{OPERAND_}/u,
- '\1 \2 \3 and \3 \4 \5' )
- # Let's do some Ruby trickery to avoid some work:
- predicate.gsub!( /&/u, "&&" )
- predicate.gsub!( /=/u, "==" )
- predicate.gsub!( /@(\w[-\w.]*)/u, 'attribute("\1")' )
- predicate.gsub!( /\bmod\b/u, "%" )
- predicate.gsub!( /\b(\w[-\w.]*\()/u ) {
- fname = $1
- fname.gsub( /-/u, "_" )
- }
-
- Functions.pair = [ 0, elements.size ]
- results = []
- elements.each do |element|
- Functions.pair[0] += 1
- Functions.node = element
- res = eval( predicate )
- case res
- when true
- results << element
- when Fixnum
- results << element if Functions.pair[0] == res
- when String
- results << element
- end
- end
- return filter( results, rest )
- end
-
- def QuickPath::attribute( name )
- return Functions.node.attributes[name] if Functions.node.kind_of? Element
- end
-
- def QuickPath::name()
- return Functions.node.name if Functions.node.kind_of? Element
- end
-
- def QuickPath::method_missing( id, *args )
- begin
- Functions.send( id.id2name, *args )
- rescue Exception
- raise "METHOD: #{id.id2name}(#{args.join ', '})\n#{$!.message}"
- end
- end
-
- def QuickPath::function( elements, fname, rest )
- args = parse_args( elements, rest )
- Functions.pair = [0, elements.size]
- results = []
- elements.each do |element|
- Functions.pair[0] += 1
- Functions.node = element
- res = Functions.send( fname, *args )
- case res
- when true
- results << element
- when Fixnum
- results << element if Functions.pair[0] == res
- end
- end
- return results
- end
-
- def QuickPath::parse_args( element, string )
- # /.*?(?:\)|,)/
- arguments = []
- buffer = ""
- while string and string != ""
- c = string[0]
- string.sub!(/^./u, "")
- case c
- when ?,
- # if depth = 1, then we start a new argument
- arguments << evaluate( buffer )
- #arguments << evaluate( string[0..count] )
- when ?(
- # start a new method call
- function( element, buffer, string )
- buffer = ""
- when ?)
- # close the method call and return arguments
- return arguments
- else
- buffer << c
- end
- end
- ""
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/rexml.rb b/ruby_2_2/lib/rexml/rexml.rb
deleted file mode 100644
index f89951171a..0000000000
--- a/ruby_2_2/lib/rexml/rexml.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-# -*- encoding: utf-8 -*-
-# REXML is an XML toolkit for Ruby[http://www.ruby-lang.org], in Ruby.
-#
-# REXML is a _pure_ Ruby, XML 1.0 conforming,
-# non-validating[http://www.w3.org/TR/2004/REC-xml-20040204/#sec-conformance]
-# toolkit with an intuitive API. REXML passes 100% of the non-validating Oasis
-# tests[http://www.oasis-open.org/committees/xml-conformance/xml-test-suite.shtml],
-# and provides tree, stream, SAX2, pull, and lightweight APIs. REXML also
-# includes a full XPath[http://www.w3c.org/tr/xpath] 1.0 implementation. Since
-# Ruby 1.8, REXML is included in the standard Ruby distribution.
-#
-# Main page:: http://www.germane-software.com/software/rexml
-# Author:: Sean Russell <serATgermaneHYPHENsoftwareDOTcom>
-# Date:: 2008/019
-# Version:: 3.1.7.3
-#
-# This API documentation can be downloaded from the REXML home page, or can
-# be accessed online[http://www.germane-software.com/software/rexml_doc]
-#
-# A tutorial is available in the REXML distribution in docs/tutorial.html,
-# or can be accessed
-# online[http://www.germane-software.com/software/rexml/docs/tutorial.html]
-module REXML
- COPYRIGHT = "Copyright © 2001-2008 Sean Russell <ser@germane-software.com>"
- DATE = "2008/019"
- VERSION = "3.1.7.3"
- REVISION = %w$Revision$[1] || ''
-
- Copyright = COPYRIGHT
- Version = VERSION
-end
diff --git a/ruby_2_2/lib/rexml/sax2listener.rb b/ruby_2_2/lib/rexml/sax2listener.rb
deleted file mode 100644
index 9f276eb4ed..0000000000
--- a/ruby_2_2/lib/rexml/sax2listener.rb
+++ /dev/null
@@ -1,97 +0,0 @@
-module REXML
- # A template for stream parser listeners.
- # Note that the declarations (attlistdecl, elementdecl, etc) are trivially
- # processed; REXML doesn't yet handle doctype entity declarations, so you
- # have to parse them out yourself.
- # === Missing methods from SAX2
- # ignorable_whitespace
- # === Methods extending SAX2
- # +WARNING+
- # These methods are certainly going to change, until DTDs are fully
- # supported. Be aware of this.
- # start_document
- # end_document
- # doctype
- # elementdecl
- # attlistdecl
- # entitydecl
- # notationdecl
- # cdata
- # xmldecl
- # comment
- module SAX2Listener
- def start_document
- end
- def end_document
- end
- def start_prefix_mapping prefix, uri
- end
- def end_prefix_mapping prefix
- end
- def start_element uri, localname, qname, attributes
- end
- def end_element uri, localname, qname
- end
- def characters text
- end
- def processing_instruction target, data
- end
- # Handles a doctype declaration. Any attributes of the doctype which are
- # not supplied will be nil. # EG, <!DOCTYPE me PUBLIC "foo" "bar">
- # @p name the name of the doctype; EG, "me"
- # @p pub_sys "PUBLIC", "SYSTEM", or nil. EG, "PUBLIC"
- # @p long_name the supplied long name, or nil. EG, "foo"
- # @p uri the uri of the doctype, or nil. EG, "bar"
- def doctype name, pub_sys, long_name, uri
- end
- # If a doctype includes an ATTLIST declaration, it will cause this
- # method to be called. The content is the declaration itself, unparsed.
- # EG, <!ATTLIST el attr CDATA #REQUIRED> will come to this method as "el
- # attr CDATA #REQUIRED". This is the same for all of the .*decl
- # methods.
- def attlistdecl(element, pairs, contents)
- end
- # <!ELEMENT ...>
- def elementdecl content
- end
- # <!ENTITY ...>
- # The argument passed to this method is an array of the entity
- # declaration. It can be in a number of formats, but in general it
- # returns (example, result):
- # <!ENTITY % YN '"Yes"'>
- # ["%", "YN", "\"Yes\""]
- # <!ENTITY % YN 'Yes'>
- # ["%", "YN", "Yes"]
- # <!ENTITY WhatHeSaid "He said %YN;">
- # ["WhatHeSaid", "He said %YN;"]
- # <!ENTITY open-hatch SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml">
- # ["open-hatch", "SYSTEM", "http://www.textuality.com/boilerplate/OpenHatch.xml"]
- # <!ENTITY open-hatch PUBLIC "-//Textuality//TEXT Standard open-hatch boilerplate//EN" "http://www.textuality.com/boilerplate/OpenHatch.xml">
- # ["open-hatch", "PUBLIC", "-//Textuality//TEXT Standard open-hatch boilerplate//EN", "http://www.textuality.com/boilerplate/OpenHatch.xml"]
- # <!ENTITY hatch-pic SYSTEM "../grafix/OpenHatch.gif" NDATA gif>
- # ["hatch-pic", "SYSTEM", "../grafix/OpenHatch.gif", "NDATA", "gif"]
- def entitydecl declaration
- end
- # <!NOTATION ...>
- def notationdecl name, public_or_system, public_id, system_id
- end
- # Called when <![CDATA[ ... ]]> is encountered in a document.
- # @p content "..."
- def cdata content
- end
- # Called when an XML PI is encountered in the document.
- # EG: <?xml version="1.0" encoding="utf"?>
- # @p version the version attribute value. EG, "1.0"
- # @p encoding the encoding attribute value, or nil. EG, "utf"
- # @p standalone the standalone attribute value, or nil. EG, nil
- # @p spaced the declaration is followed by a line break
- def xmldecl version, encoding, standalone
- end
- # Called when a comment is encountered.
- # @p comment The content of the comment
- def comment comment
- end
- def progress position
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/security.rb b/ruby_2_2/lib/rexml/security.rb
deleted file mode 100644
index 593b652dc6..0000000000
--- a/ruby_2_2/lib/rexml/security.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-module REXML
- module Security
- @@entity_expansion_limit = 10_000
-
- # Set the entity expansion limit. By default the limit is set to 10000.
- def self.entity_expansion_limit=( val )
- @@entity_expansion_limit = val
- end
-
- # Get the entity expansion limit. By default the limit is set to 10000.
- def self.entity_expansion_limit
- return @@entity_expansion_limit
- end
-
- @@entity_expansion_text_limit = 10_240
-
- # Set the entity expansion limit. By default the limit is set to 10240.
- def self.entity_expansion_text_limit=( val )
- @@entity_expansion_text_limit = val
- end
-
- # Get the entity expansion limit. By default the limit is set to 10240.
- def self.entity_expansion_text_limit
- return @@entity_expansion_text_limit
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/source.rb b/ruby_2_2/lib/rexml/source.rb
deleted file mode 100644
index cfafdbd67a..0000000000
--- a/ruby_2_2/lib/rexml/source.rb
+++ /dev/null
@@ -1,296 +0,0 @@
-# coding: US-ASCII
-require 'rexml/encoding'
-
-module REXML
- # Generates Source-s. USE THIS CLASS.
- class SourceFactory
- # Generates a Source object
- # @param arg Either a String, or an IO
- # @return a Source, or nil if a bad argument was given
- def SourceFactory::create_from(arg)
- if arg.respond_to? :read and
- arg.respond_to? :readline and
- arg.respond_to? :nil? and
- arg.respond_to? :eof?
- IOSource.new(arg)
- elsif arg.respond_to? :to_str
- require 'stringio'
- IOSource.new(StringIO.new(arg))
- elsif arg.kind_of? Source
- arg
- else
- raise "#{arg.class} is not a valid input stream. It must walk \n"+
- "like either a String, an IO, or a Source."
- end
- end
- end
-
- # A Source can be searched for patterns, and wraps buffers and other
- # objects and provides consumption of text
- class Source
- include Encoding
- # The current buffer (what we're going to read next)
- attr_reader :buffer
- # The line number of the last consumed text
- attr_reader :line
- attr_reader :encoding
-
- # Constructor
- # @param arg must be a String, and should be a valid XML document
- # @param encoding if non-null, sets the encoding of the source to this
- # value, overriding all encoding detection
- def initialize(arg, encoding=nil)
- @orig = @buffer = arg
- if encoding
- self.encoding = encoding
- else
- detect_encoding
- end
- @line = 0
- end
-
-
- # Inherited from Encoding
- # Overridden to support optimized en/decoding
- def encoding=(enc)
- return unless super
- encoding_updated
- end
-
- # Scans the source for a given pattern. Note, that this is not your
- # usual scan() method. For one thing, the pattern argument has some
- # requirements; for another, the source can be consumed. You can easily
- # confuse this method. Originally, the patterns were easier
- # to construct and this method more robust, because this method
- # generated search regexps on the fly; however, this was
- # computationally expensive and slowed down the entire REXML package
- # considerably, since this is by far the most commonly called method.
- # @param pattern must be a Regexp, and must be in the form of
- # /^\s*(#{your pattern, with no groups})(.*)/. The first group
- # will be returned; the second group is used if the consume flag is
- # set.
- # @param consume if true, the pattern returned will be consumed, leaving
- # everything after it in the Source.
- # @return the pattern, if found, or nil if the Source is empty or the
- # pattern is not found.
- def scan(pattern, cons=false)
- return nil if @buffer.nil?
- rv = @buffer.scan(pattern)
- @buffer = $' if cons and rv.size>0
- rv
- end
-
- def read
- end
-
- def consume( pattern )
- @buffer = $' if pattern.match( @buffer )
- end
-
- def match_to( char, pattern )
- return pattern.match(@buffer)
- end
-
- def match_to_consume( char, pattern )
- md = pattern.match(@buffer)
- @buffer = $'
- return md
- end
-
- def match(pattern, cons=false)
- md = pattern.match(@buffer)
- @buffer = $' if cons and md
- return md
- end
-
- # @return true if the Source is exhausted
- def empty?
- @buffer == ""
- end
-
- def position
- @orig.index( @buffer )
- end
-
- # @return the current line in the source
- def current_line
- lines = @orig.split
- res = lines.grep @buffer[0..30]
- res = res[-1] if res.kind_of? Array
- lines.index( res ) if res
- end
-
- private
- def detect_encoding
- buffer_encoding = @buffer.encoding
- detected_encoding = "UTF-8"
- begin
- @buffer.force_encoding("ASCII-8BIT")
- if @buffer[0, 2] == "\xfe\xff"
- @buffer[0, 2] = ""
- detected_encoding = "UTF-16BE"
- elsif @buffer[0, 2] == "\xff\xfe"
- @buffer[0, 2] = ""
- detected_encoding = "UTF-16LE"
- elsif @buffer[0, 3] == "\xef\xbb\xbf"
- @buffer[0, 3] = ""
- detected_encoding = "UTF-8"
- end
- ensure
- @buffer.force_encoding(buffer_encoding)
- end
- self.encoding = detected_encoding
- end
-
- def encoding_updated
- if @encoding != 'UTF-8'
- @buffer = decode(@buffer)
- @to_utf = true
- else
- @to_utf = false
- @buffer.force_encoding ::Encoding::UTF_8
- end
- end
- end
-
- # A Source that wraps an IO. See the Source class for method
- # documentation
- class IOSource < Source
- #attr_reader :block_size
-
- # block_size has been deprecated
- def initialize(arg, block_size=500, encoding=nil)
- @er_source = @source = arg
- @to_utf = false
- @pending_buffer = nil
-
- if encoding
- super("", encoding)
- else
- super(@source.read(3) || "")
- end
-
- if !@to_utf and
- @buffer.respond_to?(:force_encoding) and
- @source.respond_to?(:external_encoding) and
- @source.external_encoding != ::Encoding::UTF_8
- @force_utf8 = true
- else
- @force_utf8 = false
- end
- end
-
- def scan(pattern, cons=false)
- rv = super
- # You'll notice that this next section is very similar to the same
- # section in match(), but just a liiittle different. This is
- # because it is a touch faster to do it this way with scan()
- # than the way match() does it; enough faster to warrent duplicating
- # some code
- if rv.size == 0
- until @buffer =~ pattern or @source.nil?
- begin
- @buffer << readline
- rescue Iconv::IllegalSequence
- raise
- rescue
- @source = nil
- end
- end
- rv = super
- end
- rv.taint
- rv
- end
-
- def read
- begin
- @buffer << readline
- rescue Exception, NameError
- @source = nil
- end
- end
-
- def consume( pattern )
- match( pattern, true )
- end
-
- def match( pattern, cons=false )
- rv = pattern.match(@buffer)
- @buffer = $' if cons and rv
- while !rv and @source
- begin
- @buffer << readline
- rv = pattern.match(@buffer)
- @buffer = $' if cons and rv
- rescue
- @source = nil
- end
- end
- rv.taint
- rv
- end
-
- def empty?
- super and ( @source.nil? || @source.eof? )
- end
-
- def position
- @er_source.pos rescue 0
- end
-
- # @return the current line in the source
- def current_line
- begin
- pos = @er_source.pos # The byte position in the source
- lineno = @er_source.lineno # The XML < position in the source
- @er_source.rewind
- line = 0 # The \r\n position in the source
- begin
- while @er_source.pos < pos
- @er_source.readline
- line += 1
- end
- rescue
- end
- rescue IOError
- pos = -1
- line = -1
- end
- [pos, lineno, line]
- end
-
- private
- def readline
- str = @source.readline(@line_break)
- if @pending_buffer
- if str.nil?
- str = @pending_buffer
- else
- str = @pending_buffer + str
- end
- @pending_buffer = nil
- end
- return nil if str.nil?
-
- if @to_utf
- decode(str)
- else
- str.force_encoding(::Encoding::UTF_8) if @force_utf8
- str
- end
- end
-
- def encoding_updated
- case @encoding
- when "UTF-16BE", "UTF-16LE"
- @source.binmode
- @source.set_encoding(@encoding, @encoding)
- end
- @line_break = encode(">")
- @pending_buffer, @buffer = @buffer, ""
- @pending_buffer.force_encoding(@encoding)
- super
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/streamlistener.rb b/ruby_2_2/lib/rexml/streamlistener.rb
deleted file mode 100644
index 3a0528c102..0000000000
--- a/ruby_2_2/lib/rexml/streamlistener.rb
+++ /dev/null
@@ -1,92 +0,0 @@
-module REXML
- # A template for stream parser listeners.
- # Note that the declarations (attlistdecl, elementdecl, etc) are trivially
- # processed; REXML doesn't yet handle doctype entity declarations, so you
- # have to parse them out yourself.
- module StreamListener
- # Called when a tag is encountered.
- # @p name the tag name
- # @p attrs an array of arrays of attribute/value pairs, suitable for
- # use with assoc or rassoc. IE, <tag attr1="value1" attr2="value2">
- # will result in
- # tag_start( "tag", # [["attr1","value1"],["attr2","value2"]])
- def tag_start name, attrs
- end
- # Called when the end tag is reached. In the case of <tag/>, tag_end
- # will be called immediately after tag_start
- # @p the name of the tag
- def tag_end name
- end
- # Called when text is encountered in the document
- # @p text the text content.
- def text text
- end
- # Called when an instruction is encountered. EG: <?xsl sheet='foo'?>
- # @p name the instruction name; in the example, "xsl"
- # @p instruction the rest of the instruction. In the example,
- # "sheet='foo'"
- def instruction name, instruction
- end
- # Called when a comment is encountered.
- # @p comment The content of the comment
- def comment comment
- end
- # Handles a doctype declaration. Any attributes of the doctype which are
- # not supplied will be nil. # EG, <!DOCTYPE me PUBLIC "foo" "bar">
- # @p name the name of the doctype; EG, "me"
- # @p pub_sys "PUBLIC", "SYSTEM", or nil. EG, "PUBLIC"
- # @p long_name the supplied long name, or nil. EG, "foo"
- # @p uri the uri of the doctype, or nil. EG, "bar"
- def doctype name, pub_sys, long_name, uri
- end
- # Called when the doctype is done
- def doctype_end
- end
- # If a doctype includes an ATTLIST declaration, it will cause this
- # method to be called. The content is the declaration itself, unparsed.
- # EG, <!ATTLIST el attr CDATA #REQUIRED> will come to this method as "el
- # attr CDATA #REQUIRED". This is the same for all of the .*decl
- # methods.
- def attlistdecl element_name, attributes, raw_content
- end
- # <!ELEMENT ...>
- def elementdecl content
- end
- # <!ENTITY ...>
- # The argument passed to this method is an array of the entity
- # declaration. It can be in a number of formats, but in general it
- # returns (example, result):
- # <!ENTITY % YN '"Yes"'>
- # ["YN", "\"Yes\"", "%"]
- # <!ENTITY % YN 'Yes'>
- # ["YN", "Yes", "%"]
- # <!ENTITY WhatHeSaid "He said %YN;">
- # ["WhatHeSaid", "He said %YN;"]
- # <!ENTITY open-hatch SYSTEM "http://www.textuality.com/boilerplate/OpenHatch.xml">
- # ["open-hatch", "SYSTEM", "http://www.textuality.com/boilerplate/OpenHatch.xml"]
- # <!ENTITY open-hatch PUBLIC "-//Textuality//TEXT Standard open-hatch boilerplate//EN" "http://www.textuality.com/boilerplate/OpenHatch.xml">
- # ["open-hatch", "PUBLIC", "-//Textuality//TEXT Standard open-hatch boilerplate//EN", "http://www.textuality.com/boilerplate/OpenHatch.xml"]
- # <!ENTITY hatch-pic SYSTEM "../grafix/OpenHatch.gif" NDATA gif>
- # ["hatch-pic", "SYSTEM", "../grafix/OpenHatch.gif", "gif"]
- def entitydecl content
- end
- # <!NOTATION ...>
- def notationdecl content
- end
- # Called when %foo; is encountered in a doctype declaration.
- # @p content "foo"
- def entity content
- end
- # Called when <![CDATA[ ... ]]> is encountered in a document.
- # @p content "..."
- def cdata content
- end
- # Called when an XML PI is encountered in the document.
- # EG: <?xml version="1.0" encoding="utf"?>
- # @p version the version attribute value. EG, "1.0"
- # @p encoding the encoding attribute value, or nil. EG, "utf"
- # @p standalone the standalone attribute value, or nil. EG, nil
- def xmldecl version, encoding, standalone
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/syncenumerator.rb b/ruby_2_2/lib/rexml/syncenumerator.rb
deleted file mode 100644
index 11609bdf3d..0000000000
--- a/ruby_2_2/lib/rexml/syncenumerator.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-module REXML
- class SyncEnumerator
- include Enumerable
-
- # Creates a new SyncEnumerator which enumerates rows of given
- # Enumerable objects.
- def initialize(*enums)
- @gens = enums
- @length = @gens.collect {|x| x.size }.max
- end
-
- # Returns the number of enumerated Enumerable objects, i.e. the size
- # of each row.
- def size
- @gens.size
- end
-
- # Returns the number of enumerated Enumerable objects, i.e. the size
- # of each row.
- def length
- @gens.length
- end
-
- # Enumerates rows of the Enumerable objects.
- def each
- @length.times {|i|
- yield @gens.collect {|x| x[i]}
- }
- self
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/text.rb b/ruby_2_2/lib/rexml/text.rb
deleted file mode 100644
index d3242ee46d..0000000000
--- a/ruby_2_2/lib/rexml/text.rb
+++ /dev/null
@@ -1,425 +0,0 @@
-require 'rexml/security'
-require 'rexml/entity'
-require 'rexml/doctype'
-require 'rexml/child'
-require 'rexml/doctype'
-require 'rexml/parseexception'
-
-module REXML
- # Represents text nodes in an XML document
- class Text < Child
- include Comparable
- # The order in which the substitutions occur
- SPECIALS = [ /&(?!#?[\w-]+;)/u, /</u, />/u, /"/u, /'/u, /\r/u ]
- SUBSTITUTES = ['&amp;', '&lt;', '&gt;', '&quot;', '&apos;', '&#13;']
- # Characters which are substituted in written strings
- SLAICEPS = [ '<', '>', '"', "'", '&' ]
- SETUTITSBUS = [ /&lt;/u, /&gt;/u, /&quot;/u, /&apos;/u, /&amp;/u ]
-
- # If +raw+ is true, then REXML leaves the value alone
- attr_accessor :raw
-
- NEEDS_A_SECOND_CHECK = /(<|&((#{Entity::NAME});|(#0*((?:\d+)|(?:x[a-fA-F0-9]+)));)?)/um
- NUMERICENTITY = /&#0*((?:\d+)|(?:x[a-fA-F0-9]+));/
- VALID_CHAR = [
- 0x9, 0xA, 0xD,
- (0x20..0xD7FF),
- (0xE000..0xFFFD),
- (0x10000..0x10FFFF)
- ]
-
- if String.method_defined? :encode
- VALID_XML_CHARS = Regexp.new('^['+
- VALID_CHAR.map { |item|
- case item
- when Fixnum
- [item].pack('U').force_encoding('utf-8')
- when Range
- [item.first, '-'.ord, item.last].pack('UUU').force_encoding('utf-8')
- end
- }.join +
- ']*$')
- else
- VALID_XML_CHARS = /^(
- [\x09\x0A\x0D\x20-\x7E] # ASCII
- | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
- | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
- | [\xE1-\xEC\xEE][\x80-\xBF]{2} # straight 3-byte
- | \xEF[\x80-\xBE]{2} #
- | \xEF\xBF[\x80-\xBD] # excluding U+fffe and U+ffff
- | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
- | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
- | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
- | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
- )*$/nx;
- end
-
- # Constructor
- # +arg+ if a String, the content is set to the String. If a Text,
- # the object is shallowly cloned.
- #
- # +respect_whitespace+ (boolean, false) if true, whitespace is
- # respected
- #
- # +parent+ (nil) if this is a Parent object, the parent
- # will be set to this.
- #
- # +raw+ (nil) This argument can be given three values.
- # If true, then the value of used to construct this object is expected to
- # contain no unescaped XML markup, and REXML will not change the text. If
- # this value is false, the string may contain any characters, and REXML will
- # escape any and all defined entities whose values are contained in the
- # text. If this value is nil (the default), then the raw value of the
- # parent will be used as the raw value for this node. If there is no raw
- # value for the parent, and no value is supplied, the default is false.
- # Use this field if you have entities defined for some text, and you don't
- # want REXML to escape that text in output.
- # Text.new( "<&", false, nil, false ) #-> "&lt;&amp;"
- # Text.new( "&lt;&amp;", false, nil, false ) #-> "&amp;lt;&amp;amp;"
- # Text.new( "<&", false, nil, true ) #-> Parse exception
- # Text.new( "&lt;&amp;", false, nil, true ) #-> "&lt;&amp;"
- # # Assume that the entity "s" is defined to be "sean"
- # # and that the entity "r" is defined to be "russell"
- # Text.new( "sean russell" ) #-> "&s; &r;"
- # Text.new( "sean russell", false, nil, true ) #-> "sean russell"
- #
- # +entity_filter+ (nil) This can be an array of entities to match in the
- # supplied text. This argument is only useful if +raw+ is set to false.
- # Text.new( "sean russell", false, nil, false, ["s"] ) #-> "&s; russell"
- # Text.new( "sean russell", false, nil, true, ["s"] ) #-> "sean russell"
- # In the last example, the +entity_filter+ argument is ignored.
- #
- # +illegal+ INTERNAL USE ONLY
- def initialize(arg, respect_whitespace=false, parent=nil, raw=nil,
- entity_filter=nil, illegal=NEEDS_A_SECOND_CHECK )
-
- @raw = false
- @parent = nil
-
- if parent
- super( parent )
- @raw = parent.raw
- end
-
- @raw = raw unless raw.nil?
- @entity_filter = entity_filter
- clear_cache
-
- if arg.kind_of? String
- @string = arg.dup
- @string.squeeze!(" \n\t") unless respect_whitespace
- elsif arg.kind_of? Text
- @string = arg.to_s
- @raw = arg.raw
- elsif
- raise "Illegal argument of type #{arg.type} for Text constructor (#{arg})"
- end
-
- @string.gsub!( /\r\n?/, "\n" )
-
- Text.check(@string, illegal, doctype) if @raw
- end
-
- def parent= parent
- super(parent)
- Text.check(@string, NEEDS_A_SECOND_CHECK, doctype) if @raw and @parent
- end
-
- # check for illegal characters
- def Text.check string, pattern, doctype
-
- # illegal anywhere
- if string !~ VALID_XML_CHARS
- if String.method_defined? :encode
- string.chars.each do |c|
- case c.ord
- when *VALID_CHAR
- else
- raise "Illegal character #{c.inspect} in raw string \"#{string}\""
- end
- end
- else
- string.scan(/[\x00-\x7F]|[\x80-\xBF][\xC0-\xF0]*|[\xC0-\xF0]/n) do |c|
- case c.unpack('U')
- when *VALID_CHAR
- else
- raise "Illegal character #{c.inspect} in raw string \"#{string}\""
- end
- end
- end
- end
-
- # context sensitive
- string.scan(pattern) do
- if $1[-1] != ?;
- raise "Illegal character '#{$1}' in raw string \"#{string}\""
- elsif $1[0] == ?&
- if $5 and $5[0] == ?#
- case ($5[1] == ?x ? $5[2..-1].to_i(16) : $5[1..-1].to_i)
- when *VALID_CHAR
- else
- raise "Illegal character '#{$1}' in raw string \"#{string}\""
- end
- # FIXME: below can't work but this needs API change.
- # elsif @parent and $3 and !SUBSTITUTES.include?($1)
- # if !doctype or !doctype.entities.has_key?($3)
- # raise "Undeclared entity '#{$1}' in raw string \"#{string}\""
- # end
- end
- end
- end
- end
-
- def node_type
- :text
- end
-
- def empty?
- @string.size==0
- end
-
-
- def clone
- return Text.new(self)
- end
-
-
- # Appends text to this text node. The text is appended in the +raw+ mode
- # of this text node.
- #
- # +returns+ the text itself to enable method chain like
- # 'text << "XXX" << "YYY"'.
- def <<( to_append )
- @string << to_append.gsub( /\r\n?/, "\n" )
- clear_cache
- self
- end
-
-
- # +other+ a String or a Text
- # +returns+ the result of (to_s <=> arg.to_s)
- def <=>( other )
- to_s() <=> other.to_s
- end
-
- def doctype
- if @parent
- doc = @parent.document
- doc.doctype if doc
- end
- end
-
- REFERENCE = /#{Entity::REFERENCE}/
- # Returns the string value of this text node. This string is always
- # escaped, meaning that it is a valid XML text node string, and all
- # entities that can be escaped, have been inserted. This method respects
- # the entity filter set in the constructor.
- #
- # # Assume that the entity "s" is defined to be "sean", and that the
- # # entity "r" is defined to be "russell"
- # t = Text.new( "< & sean russell", false, nil, false, ['s'] )
- # t.to_s #-> "&lt; &amp; &s; russell"
- # t = Text.new( "< & &s; russell", false, nil, false )
- # t.to_s #-> "&lt; &amp; &s; russell"
- # u = Text.new( "sean russell", false, nil, true )
- # u.to_s #-> "sean russell"
- def to_s
- return @string if @raw
- return @normalized if @normalized
-
- @normalized = Text::normalize( @string, doctype, @entity_filter )
- end
-
- def inspect
- @string.inspect
- end
-
- # Returns the string value of this text. This is the text without
- # entities, as it might be used programmatically, or printed to the
- # console. This ignores the 'raw' attribute setting, and any
- # entity_filter.
- #
- # # Assume that the entity "s" is defined to be "sean", and that the
- # # entity "r" is defined to be "russell"
- # t = Text.new( "< & sean russell", false, nil, false, ['s'] )
- # t.value #-> "< & sean russell"
- # t = Text.new( "< & &s; russell", false, nil, false )
- # t.value #-> "< & sean russell"
- # u = Text.new( "sean russell", false, nil, true )
- # u.value #-> "sean russell"
- def value
- return @unnormalized if @unnormalized
- @unnormalized = Text::unnormalize( @string, doctype )
- end
-
- # Sets the contents of this text node. This expects the text to be
- # unnormalized. It returns self.
- #
- # e = Element.new( "a" )
- # e.add_text( "foo" ) # <a>foo</a>
- # e[0].value = "bar" # <a>bar</a>
- # e[0].value = "<a>" # <a>&lt;a&gt;</a>
- def value=( val )
- @string = val.gsub( /\r\n?/, "\n" )
- clear_cache
- @raw = false
- end
-
- def wrap(string, width, addnewline=false)
- # Recursively wrap string at width.
- return string if string.length <= width
- place = string.rindex(' ', width) # Position in string with last ' ' before cutoff
- if addnewline then
- return "\n" + string[0,place] + "\n" + wrap(string[place+1..-1], width)
- else
- return string[0,place] + "\n" + wrap(string[place+1..-1], width)
- end
- end
-
- def indent_text(string, level=1, style="\t", indentfirstline=true)
- return string if level < 0
- new_string = ''
- string.each_line { |line|
- indent_string = style * level
- new_line = (indent_string + line).sub(/[\s]+$/,'')
- new_string << new_line
- }
- new_string.strip! unless indentfirstline
- return new_string
- end
-
- # == DEPRECATED
- # See REXML::Formatters
- #
- def write( writer, indent=-1, transitive=false, ie_hack=false )
- Kernel.warn("#{self.class.name}.write is deprecated. See REXML::Formatters")
- formatter = if indent > -1
- REXML::Formatters::Pretty.new( indent )
- else
- REXML::Formatters::Default.new
- end
- formatter.write( self, writer )
- end
-
- # FIXME
- # This probably won't work properly
- def xpath
- path = @parent.xpath
- path += "/text()"
- return path
- end
-
- # Writes out text, substituting special characters beforehand.
- # +out+ A String, IO, or any other object supporting <<( String )
- # +input+ the text to substitute and the write out
- #
- # z=utf8.unpack("U*")
- # ascOut=""
- # z.each{|r|
- # if r < 0x100
- # ascOut.concat(r.chr)
- # else
- # ascOut.concat(sprintf("&#x%x;", r))
- # end
- # }
- # puts ascOut
- def write_with_substitution out, input
- copy = input.clone
- # Doing it like this rather than in a loop improves the speed
- copy.gsub!( SPECIALS[0], SUBSTITUTES[0] )
- copy.gsub!( SPECIALS[1], SUBSTITUTES[1] )
- copy.gsub!( SPECIALS[2], SUBSTITUTES[2] )
- copy.gsub!( SPECIALS[3], SUBSTITUTES[3] )
- copy.gsub!( SPECIALS[4], SUBSTITUTES[4] )
- copy.gsub!( SPECIALS[5], SUBSTITUTES[5] )
- out << copy
- end
-
- private
- def clear_cache
- @normalized = nil
- @unnormalized = nil
- end
-
- # Reads text, substituting entities
- def Text::read_with_substitution( input, illegal=nil )
- copy = input.clone
-
- if copy =~ illegal
- raise ParseException.new( "malformed text: Illegal character #$& in \"#{copy}\"" )
- end if illegal
-
- copy.gsub!( /\r\n?/, "\n" )
- if copy.include? ?&
- copy.gsub!( SETUTITSBUS[0], SLAICEPS[0] )
- copy.gsub!( SETUTITSBUS[1], SLAICEPS[1] )
- copy.gsub!( SETUTITSBUS[2], SLAICEPS[2] )
- copy.gsub!( SETUTITSBUS[3], SLAICEPS[3] )
- copy.gsub!( SETUTITSBUS[4], SLAICEPS[4] )
- copy.gsub!( /&#0*((?:\d+)|(?:x[a-f0-9]+));/ ) {
- m=$1
- #m='0' if m==''
- m = "0#{m}" if m[0] == ?x
- [Integer(m)].pack('U*')
- }
- end
- copy
- end
-
- EREFERENCE = /&(?!#{Entity::NAME};)/
- # Escapes all possible entities
- def Text::normalize( input, doctype=nil, entity_filter=nil )
- copy = input.to_s
- # Doing it like this rather than in a loop improves the speed
- #copy = copy.gsub( EREFERENCE, '&amp;' )
- copy = copy.gsub( "&", "&amp;" )
- if doctype
- # Replace all ampersands that aren't part of an entity
- doctype.entities.each_value do |entity|
- copy = copy.gsub( entity.value,
- "&#{entity.name};" ) if entity.value and
- not( entity_filter and entity_filter.include?(entity.name) )
- end
- else
- # Replace all ampersands that aren't part of an entity
- DocType::DEFAULT_ENTITIES.each_value do |entity|
- copy = copy.gsub(entity.value, "&#{entity.name};" )
- end
- end
- copy
- end
-
- # Unescapes all possible entities
- def Text::unnormalize( string, doctype=nil, filter=nil, illegal=nil )
- sum = 0
- string.gsub( /\r\n?/, "\n" ).gsub( REFERENCE ) {
- s = Text.expand($&, doctype, filter)
- if sum + s.bytesize > Security.entity_expansion_text_limit
- raise "entity expansion has grown too large"
- else
- sum += s.bytesize
- end
- s
- }
- end
-
- def Text.expand(ref, doctype, filter)
- if ref[1] == ?#
- if ref[2] == ?x
- [ref[3...-1].to_i(16)].pack('U*')
- else
- [ref[2...-1].to_i].pack('U*')
- end
- elsif ref == '&amp;'
- '&'
- elsif filter and filter.include?( ref[1...-1] )
- ref
- elsif doctype
- doctype.entity( ref[1...-1] ) or ref
- else
- entity_value = DocType::DEFAULT_ENTITIES[ ref[1...-1] ]
- entity_value ? entity_value.value : ref
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/undefinednamespaceexception.rb b/ruby_2_2/lib/rexml/undefinednamespaceexception.rb
deleted file mode 100644
index 8ebfdfd0a9..0000000000
--- a/ruby_2_2/lib/rexml/undefinednamespaceexception.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require 'rexml/parseexception'
-module REXML
- class UndefinedNamespaceException < ParseException
- def initialize( prefix, source, parser )
- super( "Undefined prefix #{prefix} found" )
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/validation/relaxng.rb b/ruby_2_2/lib/rexml/validation/relaxng.rb
deleted file mode 100644
index 370efd5a98..0000000000
--- a/ruby_2_2/lib/rexml/validation/relaxng.rb
+++ /dev/null
@@ -1,538 +0,0 @@
-require "rexml/validation/validation"
-require "rexml/parsers/baseparser"
-
-module REXML
- module Validation
- # Implemented:
- # * empty
- # * element
- # * attribute
- # * text
- # * optional
- # * choice
- # * oneOrMore
- # * zeroOrMore
- # * group
- # * value
- # * interleave
- # * mixed
- # * ref
- # * grammar
- # * start
- # * define
- #
- # Not implemented:
- # * data
- # * param
- # * include
- # * externalRef
- # * notAllowed
- # * anyName
- # * nsName
- # * except
- # * name
- class RelaxNG
- include Validator
-
- INFINITY = 1.0 / 0.0
- EMPTY = Event.new( nil )
- TEXT = [:start_element, "text"]
- attr_accessor :current
- attr_accessor :count
- attr_reader :references
-
- # FIXME: Namespaces
- def initialize source
- parser = REXML::Parsers::BaseParser.new( source )
-
- @count = 0
- @references = {}
- @root = @current = Sequence.new(self)
- @root.previous = true
- states = [ @current ]
- begin
- event = parser.pull
- case event[0]
- when :start_element
- case event[1]
- when "empty"
- when "element", "attribute", "text", "value"
- states[-1] << event
- when "optional"
- states << Optional.new( self )
- states[-2] << states[-1]
- when "choice"
- states << Choice.new( self )
- states[-2] << states[-1]
- when "oneOrMore"
- states << OneOrMore.new( self )
- states[-2] << states[-1]
- when "zeroOrMore"
- states << ZeroOrMore.new( self )
- states[-2] << states[-1]
- when "group"
- states << Sequence.new( self )
- states[-2] << states[-1]
- when "interleave"
- states << Interleave.new( self )
- states[-2] << states[-1]
- when "mixed"
- states << Interleave.new( self )
- states[-2] << states[-1]
- states[-1] << TEXT
- when "define"
- states << [ event[2]["name"] ]
- when "ref"
- states[-1] << Ref.new( event[2]["name"] )
- when "anyName"
- states << AnyName.new( self )
- states[-2] << states[-1]
- when "nsName"
- when "except"
- when "name"
- when "data"
- when "param"
- when "include"
- when "grammar"
- when "start"
- when "externalRef"
- when "notAllowed"
- end
- when :end_element
- case event[1]
- when "element", "attribute"
- states[-1] << event
- when "zeroOrMore", "oneOrMore", "choice", "optional",
- "interleave", "group", "mixed"
- states.pop
- when "define"
- ref = states.pop
- @references[ ref.shift ] = ref
- #when "empty"
- end
- when :end_document
- states[-1] << event
- when :text
- states[-1] << event
- end
- end while event[0] != :end_document
- end
-
- def receive event
- validate( event )
- end
- end
-
- class State
- def initialize( context )
- @previous = []
- @events = []
- @current = 0
- @count = context.count += 1
- @references = context.references
- @value = false
- end
-
- def reset
- return if @current == 0
- @current = 0
- @events.each {|s| s.reset if s.kind_of? State }
- end
-
- def previous=( previous )
- @previous << previous
- end
-
- def next( event )
- #print "In next with #{event.inspect}. "
- #p @previous
- return @previous.pop.next( event ) if @events[@current].nil?
- expand_ref_in( @events, @current ) if @events[@current].class == Ref
- if ( @events[@current].kind_of? State )
- @current += 1
- @events[@current-1].previous = self
- return @events[@current-1].next( event )
- end
- if ( @events[@current].matches?(event) )
- @current += 1
- if @events[@current].nil?
- return @previous.pop
- elsif @events[@current].kind_of? State
- @current += 1
- @events[@current-1].previous = self
- return @events[@current-1]
- else
- return self
- end
- else
- return nil
- end
- end
-
- def to_s
- # Abbreviated:
- self.class.name =~ /(?:::)(\w)\w+$/
- # Full:
- #self.class.name =~ /(?:::)(\w+)$/
- "#$1.#@count"
- end
-
- def inspect
- "< #{to_s} #{@events.collect{|e|
- pre = e == @events[@current] ? '#' : ''
- pre + e.inspect unless self == e
- }.join(', ')} >"
- end
-
- def expected
- return [@events[@current]]
- end
-
- def <<( event )
- add_event_to_arry( @events, event )
- end
-
-
- protected
- def expand_ref_in( arry, ind )
- new_events = []
- @references[ arry[ind].to_s ].each{ |evt|
- add_event_to_arry(new_events,evt)
- }
- arry[ind,1] = new_events
- end
-
- def add_event_to_arry( arry, evt )
- evt = generate_event( evt )
- if evt.kind_of? String
- arry[-1].event_arg = evt if arry[-1].kind_of? Event and @value
- @value = false
- else
- arry << evt
- end
- end
-
- def generate_event( event )
- return event if event.kind_of? State or event.class == Ref
- evt = nil
- arg = nil
- case event[0]
- when :start_element
- case event[1]
- when "element"
- evt = :start_element
- arg = event[2]["name"]
- when "attribute"
- evt = :start_attribute
- arg = event[2]["name"]
- when "text"
- evt = :text
- when "value"
- evt = :text
- @value = true
- end
- when :text
- return event[1]
- when :end_document
- return Event.new( event[0] )
- else # then :end_element
- case event[1]
- when "element"
- evt = :end_element
- when "attribute"
- evt = :end_attribute
- end
- end
- return Event.new( evt, arg )
- end
- end
-
-
- class Sequence < State
- def matches?(event)
- @events[@current].matches?( event )
- end
- end
-
-
- class Optional < State
- def next( event )
- if @current == 0
- rv = super
- return rv if rv
- @prior = @previous.pop
- return @prior.next( event )
- end
- super
- end
-
- def matches?(event)
- @events[@current].matches?(event) ||
- (@current == 0 and @previous[-1].matches?(event))
- end
-
- def expected
- return [ @prior.expected, @events[0] ].flatten if @current == 0
- return [@events[@current]]
- end
- end
-
-
- class ZeroOrMore < Optional
- def next( event )
- expand_ref_in( @events, @current ) if @events[@current].class == Ref
- if ( @events[@current].matches?(event) )
- @current += 1
- if @events[@current].nil?
- @current = 0
- return self
- elsif @events[@current].kind_of? State
- @current += 1
- @events[@current-1].previous = self
- return @events[@current-1]
- else
- return self
- end
- else
- @prior = @previous.pop
- return @prior.next( event ) if @current == 0
- return nil
- end
- end
-
- def expected
- return [ @prior.expected, @events[0] ].flatten if @current == 0
- return [@events[@current]]
- end
- end
-
-
- class OneOrMore < State
- def initialize context
- super
- @ord = 0
- end
-
- def reset
- super
- @ord = 0
- end
-
- def next( event )
- expand_ref_in( @events, @current ) if @events[@current].class == Ref
- if ( @events[@current].matches?(event) )
- @current += 1
- @ord += 1
- if @events[@current].nil?
- @current = 0
- return self
- elsif @events[@current].kind_of? State
- @current += 1
- @events[@current-1].previous = self
- return @events[@current-1]
- else
- return self
- end
- else
- return @previous.pop.next( event ) if @current == 0 and @ord > 0
- return nil
- end
- end
-
- def matches?( event )
- @events[@current].matches?(event) ||
- (@current == 0 and @ord > 0 and @previous[-1].matches?(event))
- end
-
- def expected
- if @current == 0 and @ord > 0
- return [@previous[-1].expected, @events[0]].flatten
- else
- return [@events[@current]]
- end
- end
- end
-
-
- class Choice < State
- def initialize context
- super
- @choices = []
- end
-
- def reset
- super
- @events = []
- @choices.each { |c| c.each { |s| s.reset if s.kind_of? State } }
- end
-
- def <<( event )
- add_event_to_arry( @choices, event )
- end
-
- def next( event )
- # Make the choice if we haven't
- if @events.size == 0
- c = 0 ; max = @choices.size
- while c < max
- if @choices[c][0].class == Ref
- expand_ref_in( @choices[c], 0 )
- @choices += @choices[c]
- @choices.delete( @choices[c] )
- max -= 1
- else
- c += 1
- end
- end
- @events = @choices.find { |evt| evt[0].matches? event }
- # Remove the references
- # Find the events
- end
- unless @events
- @events = []
- return nil
- end
- super
- end
-
- def matches?( event )
- return @events[@current].matches?( event ) if @events.size > 0
- !@choices.find{|evt| evt[0].matches?(event)}.nil?
- end
-
- def expected
- return [@events[@current]] if @events.size > 0
- return @choices.collect do |x|
- if x[0].kind_of? State
- x[0].expected
- else
- x[0]
- end
- end.flatten
- end
-
- def inspect
- "< #{to_s} #{@choices.collect{|e| e.collect{|f|f.to_s}.join(', ')}.join(' or ')} >"
- end
-
- protected
- def add_event_to_arry( arry, evt )
- if evt.kind_of? State or evt.class == Ref
- arry << [evt]
- elsif evt[0] == :text
- if arry[-1] and
- arry[-1][-1].kind_of?( Event ) and
- arry[-1][-1].event_type == :text and @value
-
- arry[-1][-1].event_arg = evt[1]
- @value = false
- end
- else
- arry << [] if evt[0] == :start_element
- arry[-1] << generate_event( evt )
- end
- end
- end
-
-
- class Interleave < Choice
- def initialize context
- super
- @choice = 0
- end
-
- def reset
- @choice = 0
- end
-
- def next_current( event )
- # Expand references
- c = 0 ; max = @choices.size
- while c < max
- if @choices[c][0].class == Ref
- expand_ref_in( @choices[c], 0 )
- @choices += @choices[c]
- @choices.delete( @choices[c] )
- max -= 1
- else
- c += 1
- end
- end
- @events = @choices[@choice..-1].find { |evt| evt[0].matches? event }
- @current = 0
- if @events
- # reorder the choices
- old = @choices[@choice]
- idx = @choices.index( @events )
- @choices[@choice] = @events
- @choices[idx] = old
- @choice += 1
- end
-
- @events = [] unless @events
- end
-
-
- def next( event )
- # Find the next series
- next_current(event) unless @events[@current]
- return nil unless @events[@current]
-
- expand_ref_in( @events, @current ) if @events[@current].class == Ref
- if ( @events[@current].kind_of? State )
- @current += 1
- @events[@current-1].previous = self
- return @events[@current-1].next( event )
- end
- return @previous.pop.next( event ) if @events[@current].nil?
- if ( @events[@current].matches?(event) )
- @current += 1
- if @events[@current].nil?
- return self unless @choices[@choice].nil?
- return @previous.pop
- elsif @events[@current].kind_of? State
- @current += 1
- @events[@current-1].previous = self
- return @events[@current-1]
- else
- return self
- end
- else
- return nil
- end
- end
-
- def matches?( event )
- return @events[@current].matches?( event ) if @events[@current]
- !@choices[@choice..-1].find{|evt| evt[0].matches?(event)}.nil?
- end
-
- def expected
- return [@events[@current]] if @events[@current]
- return @choices[@choice..-1].collect do |x|
- if x[0].kind_of? State
- x[0].expected
- else
- x[0]
- end
- end.flatten
- end
-
- def inspect
- "< #{to_s} #{@choices.collect{|e| e.collect{|f|f.to_s}.join(', ')}.join(' and ')} >"
- end
- end
-
- class Ref
- def initialize value
- @value = value
- end
- def to_s
- @value
- end
- def inspect
- "{#{to_s}}"
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/validation/validation.rb b/ruby_2_2/lib/rexml/validation/validation.rb
deleted file mode 100644
index bab7f225a5..0000000000
--- a/ruby_2_2/lib/rexml/validation/validation.rb
+++ /dev/null
@@ -1,143 +0,0 @@
-require 'rexml/validation/validationexception'
-
-module REXML
- module Validation
- module Validator
- NILEVENT = [ nil ]
- def reset
- @current = @root
- @root.reset
- @root.previous = true
- @attr_stack = []
- self
- end
- def dump
- puts @root.inspect
- end
- def validate( event )
- @attr_stack = [] unless defined? @attr_stack
- match = @current.next(event)
- raise ValidationException.new( "Validation error. Expected: "+
- @current.expected.join( " or " )+" from #{@current.inspect} "+
- " but got #{Event.new( event[0], event[1] ).inspect}" ) unless match
- @current = match
-
- # Check for attributes
- case event[0]
- when :start_element
- @attr_stack << event[2]
- begin
- sattr = [:start_attribute, nil]
- eattr = [:end_attribute]
- text = [:text, nil]
- k, = event[2].find { |key,value|
- sattr[1] = key
- m = @current.next( sattr )
- if m
- # If the state has text children...
- if m.matches?( eattr )
- @current = m
- else
- text[1] = value
- m = m.next( text )
- text[1] = nil
- return false unless m
- @current = m if m
- end
- m = @current.next( eattr )
- if m
- @current = m
- true
- else
- false
- end
- else
- false
- end
- }
- event[2].delete(k) if k
- end while k
- when :end_element
- attrs = @attr_stack.pop
- raise ValidationException.new( "Validation error. Illegal "+
- " attributes: #{attrs.inspect}") if attrs.length > 0
- end
- end
- end
-
- class Event
- def initialize(event_type, event_arg=nil )
- @event_type = event_type
- @event_arg = event_arg
- end
-
- attr_reader :event_type
- attr_accessor :event_arg
-
- def done?
- @done
- end
-
- def single?
- return (@event_type != :start_element and @event_type != :start_attribute)
- end
-
- def matches?( event )
- return false unless event[0] == @event_type
- case event[0]
- when nil
- return true
- when :start_element
- return true if event[1] == @event_arg
- when :end_element
- return true
- when :start_attribute
- return true if event[1] == @event_arg
- when :end_attribute
- return true
- when :end_document
- return true
- when :text
- return (@event_arg.nil? or @event_arg == event[1])
-=begin
- when :processing_instruction
- false
- when :xmldecl
- false
- when :start_doctype
- false
- when :end_doctype
- false
- when :externalentity
- false
- when :elementdecl
- false
- when :entity
- false
- when :attlistdecl
- false
- when :notationdecl
- false
- when :end_doctype
- false
-=end
- else
- false
- end
- end
-
- def ==( other )
- return false unless other.kind_of? Event
- @event_type == other.event_type and @event_arg == other.event_arg
- end
-
- def to_s
- inspect
- end
-
- def inspect
- "#{@event_type.inspect}( #@event_arg )"
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/validation/validationexception.rb b/ruby_2_2/lib/rexml/validation/validationexception.rb
deleted file mode 100644
index 4723d9e4d3..0000000000
--- a/ruby_2_2/lib/rexml/validation/validationexception.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-module REXML
- module Validation
- class ValidationException < RuntimeError
- def initialize msg
- super
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/xmldecl.rb b/ruby_2_2/lib/rexml/xmldecl.rb
deleted file mode 100644
index 465e6abeb7..0000000000
--- a/ruby_2_2/lib/rexml/xmldecl.rb
+++ /dev/null
@@ -1,115 +0,0 @@
-require 'rexml/encoding'
-require 'rexml/source'
-
-module REXML
- # NEEDS DOCUMENTATION
- class XMLDecl < Child
- include Encoding
-
- DEFAULT_VERSION = "1.0";
- DEFAULT_ENCODING = "UTF-8";
- DEFAULT_STANDALONE = "no";
- START = '<\?xml';
- STOP = '\?>';
-
- attr_accessor :version, :standalone
- attr_reader :writeencoding, :writethis
-
- def initialize(version=DEFAULT_VERSION, encoding=nil, standalone=nil)
- @writethis = true
- @writeencoding = !encoding.nil?
- if version.kind_of? XMLDecl
- super()
- @version = version.version
- self.encoding = version.encoding
- @writeencoding = version.writeencoding
- @standalone = version.standalone
- else
- super()
- @version = version
- self.encoding = encoding
- @standalone = standalone
- end
- @version = DEFAULT_VERSION if @version.nil?
- end
-
- def clone
- XMLDecl.new(self)
- end
-
- # indent::
- # Ignored. There must be no whitespace before an XML declaration
- # transitive::
- # Ignored
- # ie_hack::
- # Ignored
- def write(writer, indent=-1, transitive=false, ie_hack=false)
- return nil unless @writethis or writer.kind_of? Output
- writer << START.sub(/\\/u, '')
- writer << " #{content encoding}"
- writer << STOP.sub(/\\/u, '')
- end
-
- def ==( other )
- other.kind_of?(XMLDecl) and
- other.version == @version and
- other.encoding == self.encoding and
- other.standalone == @standalone
- end
-
- def xmldecl version, encoding, standalone
- @version = version
- self.encoding = encoding
- @standalone = standalone
- end
-
- def node_type
- :xmldecl
- end
-
- alias :stand_alone? :standalone
- alias :old_enc= :encoding=
-
- def encoding=( enc )
- if enc.nil?
- self.old_enc = "UTF-8"
- @writeencoding = false
- else
- self.old_enc = enc
- @writeencoding = true
- end
- self.dowrite
- end
-
- # Only use this if you do not want the XML declaration to be written;
- # this object is ignored by the XML writer. Otherwise, instantiate your
- # own XMLDecl and add it to the document.
- #
- # Note that XML 1.1 documents *must* include an XML declaration
- def XMLDecl.default
- rv = XMLDecl.new( "1.0" )
- rv.nowrite
- rv
- end
-
- def nowrite
- @writethis = false
- end
-
- def dowrite
- @writethis = true
- end
-
- def inspect
- START.sub(/\\/u, '') + " ... " + STOP.sub(/\\/u, '')
- end
-
- private
- def content(enc)
- rv = "version='#@version'"
- rv << " encoding='#{enc}'" if @writeencoding || enc !~ /\Autf-8\z/i
- rv << " standalone='#@standalone'" if @standalone
- rv
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/xmltokens.rb b/ruby_2_2/lib/rexml/xmltokens.rb
deleted file mode 100644
index 4d4dd27f2d..0000000000
--- a/ruby_2_2/lib/rexml/xmltokens.rb
+++ /dev/null
@@ -1,84 +0,0 @@
-module REXML
- # Defines a number of tokens used for parsing XML. Not for general
- # consumption.
- module XMLTokens
- # From http://www.w3.org/TR/REC-xml/#sec-common-syn
- #
- # [4] NameStartChar ::=
- # ":" |
- # [A-Z] |
- # "_" |
- # [a-z] |
- # [#xC0-#xD6] |
- # [#xD8-#xF6] |
- # [#xF8-#x2FF] |
- # [#x370-#x37D] |
- # [#x37F-#x1FFF] |
- # [#x200C-#x200D] |
- # [#x2070-#x218F] |
- # [#x2C00-#x2FEF] |
- # [#x3001-#xD7FF] |
- # [#xF900-#xFDCF] |
- # [#xFDF0-#xFFFD] |
- # [#x10000-#xEFFFF]
- name_start_chars = [
- ":",
- "A-Z",
- "_",
- "a-z",
- "\\u00C0-\\u00D6",
- "\\u00D8-\\u00F6",
- "\\u00F8-\\u02FF",
- "\\u0370-\\u037D",
- "\\u037F-\\u1FFF",
- "\\u200C-\\u200D",
- "\\u2070-\\u218F",
- "\\u2C00-\\u2FEF",
- "\\u3001-\\uD7FF",
- "\\uF900-\\uFDCF",
- "\\uFDF0-\\uFFFD",
- "\\u{10000}-\\u{EFFFF}",
- ]
- # From http://www.w3.org/TR/REC-xml/#sec-common-syn
- #
- # [4a] NameChar ::=
- # NameStartChar |
- # "-" |
- # "." |
- # [0-9] |
- # #xB7 |
- # [#x0300-#x036F] |
- # [#x203F-#x2040]
- name_chars = name_start_chars + [
- "\\-",
- "\\.",
- "0-9",
- "\\u00B7",
- "\\u0300-\\u036F",
- "\\u203F-\\u2040",
- ]
- NAME_START_CHAR = "[#{name_start_chars.join('')}]"
- NAME_CHAR = "[#{name_chars.join('')}]"
- NAMECHAR = NAME_CHAR # deprecated. Use NAME_CHAR instead.
-
- # From http://www.w3.org/TR/xml-names11/#NT-NCName
- #
- # [6] NCNameStartChar ::= NameStartChar - ':'
- ncname_start_chars = name_start_chars - [":"]
- # From http://www.w3.org/TR/xml-names11/#NT-NCName
- #
- # [5] NCNameChar ::= NameChar - ':'
- ncname_chars = name_chars - [":"]
- NCNAME_STR = "[#{ncname_start_chars.join('')}][#{ncname_chars.join('')}]*"
- NAME_STR = "(?:#{NCNAME_STR}:)?#{NCNAME_STR}"
-
- NAME = "(#{NAME_START_CHAR}#{NAME_CHAR}*)"
- NMTOKEN = "(?:#{NAME_CHAR})+"
- NMTOKENS = "#{NMTOKEN}(\\s+#{NMTOKEN})*"
- REFERENCE = "(?:&#{NAME};|&#\\d+;|&#x[0-9a-fA-F]+;)"
-
- #REFERENCE = "(?:#{ENTITYREF}|#{CHARREF})"
- #ENTITYREF = "&#{NAME};"
- #CHARREF = "&#\\d+;|&#x[0-9a-fA-F]+;"
- end
-end
diff --git a/ruby_2_2/lib/rexml/xpath.rb b/ruby_2_2/lib/rexml/xpath.rb
deleted file mode 100644
index 0f99808def..0000000000
--- a/ruby_2_2/lib/rexml/xpath.rb
+++ /dev/null
@@ -1,80 +0,0 @@
-require 'rexml/functions'
-require 'rexml/xpath_parser'
-
-module REXML
- # Wrapper class. Use this class to access the XPath functions.
- class XPath
- include Functions
- # A base Hash object, supposing to be used when initializing a
- # default empty namespaces set, but is currently unused.
- # TODO: either set the namespaces=EMPTY_HASH, or deprecate this.
- EMPTY_HASH = {}
-
- # Finds and returns the first node that matches the supplied xpath.
- # element::
- # The context element
- # path::
- # The xpath to search for. If not supplied or nil, returns the first
- # node matching '*'.
- # namespaces::
- # If supplied, a Hash which defines a namespace mapping.
- # variables::
- # If supplied, a Hash which maps $variables in the query
- # to values. This can be used to avoid XPath injection attacks
- # or to automatically handle escaping string values.
- #
- # XPath.first( node )
- # XPath.first( doc, "//b"} )
- # XPath.first( node, "a/x:b", { "x"=>"http://doofus" } )
- # XPath.first( node, '/book/publisher/text()=$publisher', {}, {"publisher"=>"O'Reilly"})
- def XPath::first element, path=nil, namespaces=nil, variables={}
- raise "The namespaces argument, if supplied, must be a hash object." unless namespaces.nil? or namespaces.kind_of?(Hash)
- raise "The variables argument, if supplied, must be a hash object." unless variables.kind_of?(Hash)
- parser = XPathParser.new
- parser.namespaces = namespaces
- parser.variables = variables
- path = "*" unless path
- element = [element] unless element.kind_of? Array
- parser.parse(path, element).flatten[0]
- end
-
- # Iterates over nodes that match the given path, calling the supplied
- # block with the match.
- # element::
- # The context element
- # path::
- # The xpath to search for. If not supplied or nil, defaults to '*'
- # namespaces::
- # If supplied, a Hash which defines a namespace mapping
- # variables::
- # If supplied, a Hash which maps $variables in the query
- # to values. This can be used to avoid XPath injection attacks
- # or to automatically handle escaping string values.
- #
- # XPath.each( node ) { |el| ... }
- # XPath.each( node, '/*[@attr='v']' ) { |el| ... }
- # XPath.each( node, 'ancestor::x' ) { |el| ... }
- # XPath.each( node, '/book/publisher/text()=$publisher', {}, {"publisher"=>"O'Reilly"}) \
- # {|el| ... }
- def XPath::each element, path=nil, namespaces=nil, variables={}, &block
- raise "The namespaces argument, if supplied, must be a hash object." unless namespaces.nil? or namespaces.kind_of?(Hash)
- raise "The variables argument, if supplied, must be a hash object." unless variables.kind_of?(Hash)
- parser = XPathParser.new
- parser.namespaces = namespaces
- parser.variables = variables
- path = "*" unless path
- element = [element] unless element.kind_of? Array
- parser.parse(path, element).each( &block )
- end
-
- # Returns an array of nodes matching a given XPath.
- def XPath::match element, path=nil, namespaces=nil, variables={}
- parser = XPathParser.new
- parser.namespaces = namespaces
- parser.variables = variables
- path = "*" unless path
- element = [element] unless element.kind_of? Array
- parser.parse(path,element)
- end
- end
-end
diff --git a/ruby_2_2/lib/rexml/xpath_parser.rb b/ruby_2_2/lib/rexml/xpath_parser.rb
deleted file mode 100644
index ef49a32fba..0000000000
--- a/ruby_2_2/lib/rexml/xpath_parser.rb
+++ /dev/null
@@ -1,703 +0,0 @@
-require 'rexml/namespace'
-require 'rexml/xmltokens'
-require 'rexml/attribute'
-require 'rexml/syncenumerator'
-require 'rexml/parsers/xpathparser'
-
-class Object
- # provides a unified +clone+ operation, for REXML::XPathParser
- # to use across multiple Object types
- def dclone
- clone
- end
-end
-class Symbol
- # provides a unified +clone+ operation, for REXML::XPathParser
- # to use across multiple Object types
- def dclone ; self ; end
-end
-class Fixnum
- # provides a unified +clone+ operation, for REXML::XPathParser
- # to use across multiple Object types
- def dclone ; self ; end
-end
-class Float
- # provides a unified +clone+ operation, for REXML::XPathParser
- # to use across multiple Object types
- def dclone ; self ; end
-end
-class Array
- # provides a unified +clone+ operation, for REXML::XPathParser
- # to use across multiple Object+ types
- def dclone
- klone = self.clone
- klone.clear
- self.each{|v| klone << v.dclone}
- klone
- end
-end
-
-module REXML
- # You don't want to use this class. Really. Use XPath, which is a wrapper
- # for this class. Believe me. You don't want to poke around in here.
- # There is strange, dark magic at work in this code. Beware. Go back! Go
- # back while you still can!
- class XPathParser
- include XMLTokens
- LITERAL = /^'([^']*)'|^"([^"]*)"/u
-
- def initialize( )
- @parser = REXML::Parsers::XPathParser.new
- @namespaces = nil
- @variables = {}
- end
-
- def namespaces=( namespaces={} )
- Functions::namespace_context = namespaces
- @namespaces = namespaces
- end
-
- def variables=( vars={} )
- Functions::variables = vars
- @variables = vars
- end
-
- def parse path, nodeset
- path_stack = @parser.parse( path )
- match( path_stack, nodeset )
- end
-
- def get_first path, nodeset
- path_stack = @parser.parse( path )
- first( path_stack, nodeset )
- end
-
- def predicate path, nodeset
- path_stack = @parser.parse( path )
- expr( path_stack, nodeset )
- end
-
- def []=( variable_name, value )
- @variables[ variable_name ] = value
- end
-
-
- # Performs a depth-first (document order) XPath search, and returns the
- # first match. This is the fastest, lightest way to return a single result.
- #
- # FIXME: This method is incomplete!
- def first( path_stack, node )
- return nil if path.size == 0
-
- case path[0]
- when :document
- # do nothing
- return first( path[1..-1], node )
- when :child
- for c in node.children
- r = first( path[1..-1], c )
- return r if r
- end
- when :qname
- name = path[2]
- if node.name == name
- return node if path.size == 3
- return first( path[3..-1], node )
- else
- return nil
- end
- when :descendant_or_self
- r = first( path[1..-1], node )
- return r if r
- for c in node.children
- r = first( path, c )
- return r if r
- end
- when :node
- return first( path[1..-1], node )
- when :any
- return first( path[1..-1], node )
- end
- return nil
- end
-
-
- def match( path_stack, nodeset )
- r = expr( path_stack, nodeset )
- r
- end
-
- private
-
-
- # Returns a String namespace for a node, given a prefix
- # The rules are:
- #
- # 1. Use the supplied namespace mapping first.
- # 2. If no mapping was supplied, use the context node to look up the namespace
- def get_namespace( node, prefix )
- if @namespaces
- return @namespaces[prefix] || ''
- else
- return node.namespace( prefix ) if node.node_type == :element
- return ''
- end
- end
-
-
- # Expr takes a stack of path elements and a set of nodes (either a Parent
- # or an Array and returns an Array of matching nodes
- ALL = [ :attribute, :element, :text, :processing_instruction, :comment ]
- ELEMENTS = [ :element ]
- def expr( path_stack, nodeset, context=nil )
- node_types = ELEMENTS
- return nodeset if path_stack.length == 0 || nodeset.length == 0
- while path_stack.length > 0
- if nodeset.length == 0
- path_stack.clear
- return []
- end
- case (op = path_stack.shift)
- when :document
- nodeset = [ nodeset[0].root_node ]
-
- when :qname
- prefix = path_stack.shift
- name = path_stack.shift
- nodeset.delete_if do |node|
- # FIXME: This DOUBLES the time XPath searches take
- ns = get_namespace( node, prefix )
- if node.node_type == :element
- if node.name == name
- end
- end
- !(node.node_type == :element and
- node.name == name and
- node.namespace == ns )
- end
- node_types = ELEMENTS
-
- when :any
- nodeset.delete_if { |node| !node_types.include?(node.node_type) }
-
- when :self
- # This space left intentionally blank
-
- when :processing_instruction
- target = path_stack.shift
- nodeset.delete_if do |node|
- (node.node_type != :processing_instruction) or
- ( target!='' and ( node.target != target ) )
- end
-
- when :text
- nodeset.delete_if { |node| node.node_type != :text }
-
- when :comment
- nodeset.delete_if { |node| node.node_type != :comment }
-
- when :node
- # This space left intentionally blank
- node_types = ALL
-
- when :child
- new_nodeset = []
- nt = nil
- nodeset.each do |node|
- nt = node.node_type
- new_nodeset += node.children if nt == :element or nt == :document
- end
- nodeset = new_nodeset
- node_types = ELEMENTS
-
- when :literal
- return path_stack.shift
-
- when :attribute
- new_nodeset = []
- case path_stack.shift
- when :qname
- prefix = path_stack.shift
- name = path_stack.shift
- for element in nodeset
- if element.node_type == :element
- attrib = element.attribute( name, get_namespace(element, prefix) )
- new_nodeset << attrib if attrib
- end
- end
- when :any
- for element in nodeset
- if element.node_type == :element
- new_nodeset += element.attributes.to_a
- end
- end
- end
- nodeset = new_nodeset
-
- when :parent
- nodeset = nodeset.collect{|n| n.parent}.compact
- #nodeset = expr(path_stack.dclone, nodeset.collect{|n| n.parent}.compact)
- node_types = ELEMENTS
-
- when :ancestor
- new_nodeset = []
- nodeset.each do |node|
- while node.parent
- node = node.parent
- new_nodeset << node unless new_nodeset.include? node
- end
- end
- nodeset = new_nodeset
- node_types = ELEMENTS
-
- when :ancestor_or_self
- new_nodeset = []
- nodeset.each do |node|
- if node.node_type == :element
- new_nodeset << node
- while ( node.parent )
- node = node.parent
- new_nodeset << node unless new_nodeset.include? node
- end
- end
- end
- nodeset = new_nodeset
- node_types = ELEMENTS
-
- when :predicate
- new_nodeset = []
- subcontext = { :size => nodeset.size }
- pred = path_stack.shift
- nodeset.each_with_index { |node, index|
- subcontext[ :node ] = node
- subcontext[ :index ] = index+1
- pc = pred.dclone
- result = expr( pc, [node], subcontext )
- result = result[0] if result.kind_of? Array and result.length == 1
- if result.kind_of? Numeric
- new_nodeset << node if result == (index+1)
- elsif result.instance_of? Array
- if result.size > 0 and result.inject(false) {|k,s| s or k}
- new_nodeset << node if result.size > 0
- end
- else
- new_nodeset << node if result
- end
- }
- nodeset = new_nodeset
-=begin
- predicate = path_stack.shift
- ns = nodeset.clone
- result = expr( predicate, ns )
- if result.kind_of? Array
- nodeset = result.zip(ns).collect{|m,n| n if m}.compact
- else
- nodeset = result ? nodeset : []
- end
-=end
-
- when :descendant_or_self
- rv = descendant_or_self( path_stack, nodeset )
- path_stack.clear
- nodeset = rv
- node_types = ELEMENTS
-
- when :descendant
- results = []
- nt = nil
- nodeset.each do |node|
- nt = node.node_type
- results += expr( path_stack.dclone.unshift( :descendant_or_self ),
- node.children ) if nt == :element or nt == :document
- end
- nodeset = results
- node_types = ELEMENTS
-
- when :following_sibling
- results = []
- nodeset.each do |node|
- next if node.parent.nil?
- all_siblings = node.parent.children
- current_index = all_siblings.index( node )
- following_siblings = all_siblings[ current_index+1 .. -1 ]
- results += expr( path_stack.dclone, following_siblings )
- end
- nodeset = results
-
- when :preceding_sibling
- results = []
- nodeset.each do |node|
- next if node.parent.nil?
- all_siblings = node.parent.children
- current_index = all_siblings.index( node )
- preceding_siblings = all_siblings[ 0, current_index ].reverse
- results += preceding_siblings
- end
- nodeset = results
- node_types = ELEMENTS
-
- when :preceding
- new_nodeset = []
- nodeset.each do |node|
- new_nodeset += preceding( node )
- end
- nodeset = new_nodeset
- node_types = ELEMENTS
-
- when :following
- new_nodeset = []
- nodeset.each do |node|
- new_nodeset += following( node )
- end
- nodeset = new_nodeset
- node_types = ELEMENTS
-
- when :namespace
- new_nodeset = []
- prefix = path_stack.shift
- nodeset.each do |node|
- if (node.node_type == :element or node.node_type == :attribute)
- if @namespaces
- namespaces = @namespaces
- elsif (node.node_type == :element)
- namespaces = node.namespaces
- else
- namespaces = node.element.namesapces
- end
- if (node.namespace == namespaces[prefix])
- new_nodeset << node
- end
- end
- end
- nodeset = new_nodeset
-
- when :variable
- var_name = path_stack.shift
- return @variables[ var_name ]
-
- # :and, :or, :eq, :neq, :lt, :lteq, :gt, :gteq
- # TODO: Special case for :or and :and -- not evaluate the right
- # operand if the left alone determines result (i.e. is true for
- # :or and false for :and).
- when :eq, :neq, :lt, :lteq, :gt, :gteq, :or
- left = expr( path_stack.shift, nodeset.dup, context )
- right = expr( path_stack.shift, nodeset.dup, context )
- res = equality_relational_compare( left, op, right )
- return res
-
- when :and
- left = expr( path_stack.shift, nodeset.dup, context )
- return [] unless left
- if left.respond_to?(:inject) and !left.inject(false) {|a,b| a | b}
- return []
- end
- right = expr( path_stack.shift, nodeset.dup, context )
- res = equality_relational_compare( left, op, right )
- return res
-
- when :div
- left = Functions::number(expr(path_stack.shift, nodeset, context)).to_f
- right = Functions::number(expr(path_stack.shift, nodeset, context)).to_f
- return (left / right)
-
- when :mod
- left = Functions::number(expr(path_stack.shift, nodeset, context )).to_f
- right = Functions::number(expr(path_stack.shift, nodeset, context )).to_f
- return (left % right)
-
- when :mult
- left = Functions::number(expr(path_stack.shift, nodeset, context )).to_f
- right = Functions::number(expr(path_stack.shift, nodeset, context )).to_f
- return (left * right)
-
- when :plus
- left = Functions::number(expr(path_stack.shift, nodeset, context )).to_f
- right = Functions::number(expr(path_stack.shift, nodeset, context )).to_f
- return (left + right)
-
- when :minus
- left = Functions::number(expr(path_stack.shift, nodeset, context )).to_f
- right = Functions::number(expr(path_stack.shift, nodeset, context )).to_f
- return (left - right)
-
- when :union
- left = expr( path_stack.shift, nodeset, context )
- right = expr( path_stack.shift, nodeset, context )
- return (left | right)
-
- when :neg
- res = expr( path_stack, nodeset, context )
- return -(res.to_f)
-
- when :not
- when :function
- func_name = path_stack.shift.tr('-','_')
- arguments = path_stack.shift
- subcontext = context ? nil : { :size => nodeset.size }
-
- res = []
- cont = context
- nodeset.each_with_index { |n, i|
- if subcontext
- subcontext[:node] = n
- subcontext[:index] = i
- cont = subcontext
- end
- arg_clone = arguments.dclone
- args = arg_clone.collect { |arg|
- expr( arg, [n], cont )
- }
- Functions.context = cont
- res << Functions.send( func_name, *args )
- }
- return res
-
- end
- end # while
- return nodeset
- end
-
-
- ##########################################################
- # FIXME
- # The next two methods are BAD MOJO!
- # This is my achilles heel. If anybody thinks of a better
- # way of doing this, be my guest. This really sucks, but
- # it is a wonder it works at all.
- # ########################################################
-
- def descendant_or_self( path_stack, nodeset )
- rs = []
- d_o_s( path_stack, nodeset, rs )
- document_order(rs.flatten.compact)
- #rs.flatten.compact
- end
-
- def d_o_s( p, ns, r )
- nt = nil
- ns.each_index do |i|
- n = ns[i]
- x = expr( p.dclone, [ n ] )
- nt = n.node_type
- d_o_s( p, n.children, x ) if nt == :element or nt == :document and n.children.size > 0
- r.concat(x) if x.size > 0
- end
- end
-
-
- # Reorders an array of nodes so that they are in document order
- # It tries to do this efficiently.
- #
- # FIXME: I need to get rid of this, but the issue is that most of the XPath
- # interpreter functions as a filter, which means that we lose context going
- # in and out of function calls. If I knew what the index of the nodes was,
- # I wouldn't have to do this. Maybe add a document IDX for each node?
- # Problems with mutable documents. Or, rewrite everything.
- def document_order( array_of_nodes )
- new_arry = []
- array_of_nodes.each { |node|
- node_idx = []
- np = node.node_type == :attribute ? node.element : node
- while np.parent and np.parent.node_type == :element
- node_idx << np.parent.index( np )
- np = np.parent
- end
- new_arry << [ node_idx.reverse, node ]
- }
- new_arry.sort{ |s1, s2| s1[0] <=> s2[0] }.collect{ |s| s[1] }
- end
-
-
- def recurse( nodeset, &block )
- for node in nodeset
- yield node
- recurse( node, &block ) if node.node_type == :element
- end
- end
-
-
-
- # Builds a nodeset of all of the preceding nodes of the supplied node,
- # in reverse document order
- # preceding:: includes every element in the document that precedes this node,
- # except for ancestors
- def preceding( node )
- ancestors = []
- p = node.parent
- while p
- ancestors << p
- p = p.parent
- end
-
- acc = []
- p = preceding_node_of( node )
- while p
- if ancestors.include? p
- ancestors.delete(p)
- else
- acc << p
- end
- p = preceding_node_of( p )
- end
- acc
- end
-
- def preceding_node_of( node )
- psn = node.previous_sibling_node
- if psn.nil?
- if node.parent.nil? or node.parent.class == Document
- return nil
- end
- return node.parent
- #psn = preceding_node_of( node.parent )
- end
- while psn and psn.kind_of? Element and psn.children.size > 0
- psn = psn.children[-1]
- end
- psn
- end
-
- def following( node )
- acc = []
- p = next_sibling_node( node )
- while p
- acc << p
- p = following_node_of( p )
- end
- acc
- end
-
- def following_node_of( node )
- if node.kind_of? Element and node.children.size > 0
- return node.children[0]
- end
- return next_sibling_node(node)
- end
-
- def next_sibling_node(node)
- psn = node.next_sibling_node
- while psn.nil?
- if node.parent.nil? or node.parent.class == Document
- return nil
- end
- node = node.parent
- psn = node.next_sibling_node
- end
- return psn
- end
-
- def norm b
- case b
- when true, false
- return b
- when 'true', 'false'
- return Functions::boolean( b )
- when /^\d+(\.\d+)?$/
- return Functions::number( b )
- else
- return Functions::string( b )
- end
- end
-
- def equality_relational_compare( set1, op, set2 )
- if set1.kind_of? Array and set2.kind_of? Array
- if set1.size == 1 and set2.size == 1
- set1 = set1[0]
- set2 = set2[0]
- elsif set1.size == 0 or set2.size == 0
- nd = set1.size==0 ? set2 : set1
- rv = nd.collect { |il| compare( il, op, nil ) }
- return rv
- else
- res = []
- SyncEnumerator.new( set1, set2 ).each { |i1, i2|
- i1 = norm( i1 )
- i2 = norm( i2 )
- res << compare( i1, op, i2 )
- }
- return res
- end
- end
- # If one is nodeset and other is number, compare number to each item
- # in nodeset s.t. number op number(string(item))
- # If one is nodeset and other is string, compare string to each item
- # in nodeset s.t. string op string(item)
- # If one is nodeset and other is boolean, compare boolean to each item
- # in nodeset s.t. boolean op boolean(item)
- if set1.kind_of? Array or set2.kind_of? Array
- if set1.kind_of? Array
- a = set1
- b = set2
- else
- a = set2
- b = set1
- end
-
- case b
- when true, false
- return a.collect {|v| compare( Functions::boolean(v), op, b ) }
- when Numeric
- return a.collect {|v| compare( Functions::number(v), op, b )}
- when /^\d+(\.\d+)?$/
- b = Functions::number( b )
- return a.collect {|v| compare( Functions::number(v), op, b )}
- else
- b = Functions::string( b )
- return a.collect { |v| compare( Functions::string(v), op, b ) }
- end
- else
- # If neither is nodeset,
- # If op is = or !=
- # If either boolean, convert to boolean
- # If either number, convert to number
- # Else, convert to string
- # Else
- # Convert both to numbers and compare
- s1 = set1.to_s
- s2 = set2.to_s
- if s1 == 'true' or s1 == 'false' or s2 == 'true' or s2 == 'false'
- set1 = Functions::boolean( set1 )
- set2 = Functions::boolean( set2 )
- else
- if op == :eq or op == :neq
- if s1 =~ /^\d+(\.\d+)?$/ or s2 =~ /^\d+(\.\d+)?$/
- set1 = Functions::number( s1 )
- set2 = Functions::number( s2 )
- else
- set1 = Functions::string( set1 )
- set2 = Functions::string( set2 )
- end
- else
- set1 = Functions::number( set1 )
- set2 = Functions::number( set2 )
- end
- end
- return compare( set1, op, set2 )
- end
- return false
- end
-
- def compare a, op, b
- case op
- when :eq
- a == b
- when :neq
- a != b
- when :lt
- a < b
- when :lteq
- a <= b
- when :gt
- a > b
- when :gteq
- a >= b
- when :and
- a and b
- when :or
- a or b
- else
- false
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rinda/rinda.rb b/ruby_2_2/lib/rinda/rinda.rb
deleted file mode 100644
index d9cd3782a0..0000000000
--- a/ruby_2_2/lib/rinda/rinda.rb
+++ /dev/null
@@ -1,327 +0,0 @@
-require 'drb/drb'
-require 'thread'
-
-##
-# A module to implement the Linda distributed computing paradigm in Ruby.
-#
-# Rinda is part of DRb (dRuby).
-#
-# == Example(s)
-#
-# See the sample/drb/ directory in the Ruby distribution, from 1.8.2 onwards.
-#
-#--
-# TODO
-# == Introduction to Linda/rinda?
-#
-# == Why is this library separate from DRb?
-
-module Rinda
-
- ##
- # Rinda error base class
-
- class RindaError < RuntimeError; end
-
- ##
- # Raised when a hash-based tuple has an invalid key.
-
- class InvalidHashTupleKey < RindaError; end
-
- ##
- # Raised when trying to use a canceled tuple.
-
- class RequestCanceledError < ThreadError; end
-
- ##
- # Raised when trying to use an expired tuple.
-
- class RequestExpiredError < ThreadError; end
-
- ##
- # A tuple is the elementary object in Rinda programming.
- # Tuples may be matched against templates if the tuple and
- # the template are the same size.
-
- class Tuple
-
- ##
- # Creates a new Tuple from +ary_or_hash+ which must be an Array or Hash.
-
- def initialize(ary_or_hash)
- if hash?(ary_or_hash)
- init_with_hash(ary_or_hash)
- else
- init_with_ary(ary_or_hash)
- end
- end
-
- ##
- # The number of elements in the tuple.
-
- def size
- @tuple.size
- end
-
- ##
- # Accessor method for elements of the tuple.
-
- def [](k)
- @tuple[k]
- end
-
- ##
- # Fetches item +k+ from the tuple.
-
- def fetch(k)
- @tuple.fetch(k)
- end
-
- ##
- # Iterate through the tuple, yielding the index or key, and the
- # value, thus ensuring arrays are iterated similarly to hashes.
-
- def each # FIXME
- if Hash === @tuple
- @tuple.each { |k, v| yield(k, v) }
- else
- @tuple.each_with_index { |v, k| yield(k, v) }
- end
- end
-
- ##
- # Return the tuple itself
- def value
- @tuple
- end
-
- private
-
- def hash?(ary_or_hash)
- ary_or_hash.respond_to?(:keys)
- end
-
- ##
- # Munges +ary+ into a valid Tuple.
-
- def init_with_ary(ary)
- @tuple = Array.new(ary.size)
- @tuple.size.times do |i|
- @tuple[i] = ary[i]
- end
- end
-
- ##
- # Ensures +hash+ is a valid Tuple.
-
- def init_with_hash(hash)
- @tuple = Hash.new
- hash.each do |k, v|
- raise InvalidHashTupleKey unless String === k
- @tuple[k] = v
- end
- end
-
- end
-
- ##
- # Templates are used to match tuples in Rinda.
-
- class Template < Tuple
-
- ##
- # Matches this template against +tuple+. The +tuple+ must be the same
- # size as the template. An element with a +nil+ value in a template acts
- # as a wildcard, matching any value in the corresponding position in the
- # tuple. Elements of the template match the +tuple+ if the are #== or
- # #===.
- #
- # Template.new([:foo, 5]).match Tuple.new([:foo, 5]) # => true
- # Template.new([:foo, nil]).match Tuple.new([:foo, 5]) # => true
- # Template.new([String]).match Tuple.new(['hello']) # => true
- #
- # Template.new([:foo]).match Tuple.new([:foo, 5]) # => false
- # Template.new([:foo, 6]).match Tuple.new([:foo, 5]) # => false
- # Template.new([:foo, nil]).match Tuple.new([:foo]) # => false
- # Template.new([:foo, 6]).match Tuple.new([:foo]) # => false
-
- def match(tuple)
- return false unless tuple.respond_to?(:size)
- return false unless tuple.respond_to?(:fetch)
- return false unless self.size == tuple.size
- each do |k, v|
- begin
- it = tuple.fetch(k)
- rescue
- return false
- end
- next if v.nil?
- next if v == it
- next if v === it
- return false
- end
- return true
- end
-
- ##
- # Alias for #match.
-
- def ===(tuple)
- match(tuple)
- end
-
- end
-
- ##
- # <i>Documentation?</i>
-
- class DRbObjectTemplate
-
- ##
- # Creates a new DRbObjectTemplate that will match against +uri+ and +ref+.
-
- def initialize(uri=nil, ref=nil)
- @drb_uri = uri
- @drb_ref = ref
- end
-
- ##
- # This DRbObjectTemplate matches +ro+ if the remote object's drburi and
- # drbref are the same. +nil+ is used as a wildcard.
-
- def ===(ro)
- return true if super(ro)
- unless @drb_uri.nil?
- return false unless (@drb_uri === ro.__drburi rescue false)
- end
- unless @drb_ref.nil?
- return false unless (@drb_ref === ro.__drbref rescue false)
- end
- true
- end
-
- end
-
- ##
- # TupleSpaceProxy allows a remote Tuplespace to appear as local.
-
- class TupleSpaceProxy
- ##
- # A Port ensures that a moved tuple arrives properly at its destination
- # and does not get lost.
- #
- # See https://bugs.ruby-lang.org/issues/8125
-
- class Port # :nodoc:
- attr_reader :value
-
- def self.deliver
- port = new
-
- begin
- yield(port)
- ensure
- port.close
- end
-
- port.value
- end
-
- def initialize
- @open = true
- @value = nil
- end
-
- ##
- # Don't let the DRb thread push to it when remote sends tuple
-
- def close
- @open = false
- end
-
- ##
- # Stores +value+ and ensure it does not get marshaled multiple times.
-
- def push value
- raise 'port closed' unless @open
-
- @value = value
-
- nil # avoid Marshal
- end
- end
-
- ##
- # Creates a new TupleSpaceProxy to wrap +ts+.
-
- def initialize(ts)
- @ts = ts
- end
-
- ##
- # Adds +tuple+ to the proxied TupleSpace. See TupleSpace#write.
-
- def write(tuple, sec=nil)
- @ts.write(tuple, sec)
- end
-
- ##
- # Takes +tuple+ from the proxied TupleSpace. See TupleSpace#take.
-
- def take(tuple, sec=nil, &block)
- Port.deliver do |port|
- @ts.move(DRbObject.new(port), tuple, sec, &block)
- end
- end
-
- ##
- # Reads +tuple+ from the proxied TupleSpace. See TupleSpace#read.
-
- def read(tuple, sec=nil, &block)
- @ts.read(tuple, sec, &block)
- end
-
- ##
- # Reads all tuples matching +tuple+ from the proxied TupleSpace. See
- # TupleSpace#read_all.
-
- def read_all(tuple)
- @ts.read_all(tuple)
- end
-
- ##
- # Registers for notifications of event +ev+ on the proxied TupleSpace.
- # See TupleSpace#notify
-
- def notify(ev, tuple, sec=nil)
- @ts.notify(ev, tuple, sec)
- end
-
- end
-
- ##
- # An SimpleRenewer allows a TupleSpace to check if a TupleEntry is still
- # alive.
-
- class SimpleRenewer
-
- include DRbUndumped
-
- ##
- # Creates a new SimpleRenewer that keeps an object alive for another +sec+
- # seconds.
-
- def initialize(sec=180)
- @sec = sec
- end
-
- ##
- # Called by the TupleSpace to check if the object is still alive.
-
- def renew
- @sec
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rinda/ring.rb b/ruby_2_2/lib/rinda/ring.rb
deleted file mode 100644
index fe33420494..0000000000
--- a/ruby_2_2/lib/rinda/ring.rb
+++ /dev/null
@@ -1,480 +0,0 @@
-#
-# Note: Rinda::Ring API is unstable.
-#
-require 'drb/drb'
-require 'rinda/rinda'
-require 'thread'
-require 'ipaddr'
-
-module Rinda
-
- ##
- # The default port Ring discovery will use.
-
- Ring_PORT = 7647
-
- ##
- # A RingServer allows a Rinda::TupleSpace to be located via UDP broadcasts.
- # Default service location uses the following steps:
- #
- # 1. A RingServer begins listening on the network broadcast UDP address.
- # 2. A RingFinger sends a UDP packet containing the DRb URI where it will
- # listen for a reply.
- # 3. The RingServer receives the UDP packet and connects back to the
- # provided DRb URI with the DRb service.
- #
- # A RingServer requires a TupleSpace:
- #
- # ts = Rinda::TupleSpace.new
- # rs = Rinda::RingServer.new
- #
- # RingServer can also listen on multicast addresses for announcements. This
- # allows multiple RingServers to run on the same host. To use network
- # broadcast and multicast:
- #
- # ts = Rinda::TupleSpace.new
- # rs = Rinda::RingServer.new ts, %w[Socket::INADDR_ANY, 239.0.0.1 ff02::1]
-
- class RingServer
-
- include DRbUndumped
-
- ##
- # Special renewer for the RingServer to allow shutdown
-
- class Renewer # :nodoc:
- include DRbUndumped
-
- ##
- # Set to false to shutdown future requests using this Renewer
-
- attr_writer :renew
-
- def initialize # :nodoc:
- @renew = true
- end
-
- def renew # :nodoc:
- @renew ? 1 : true
- end
- end
-
- ##
- # Advertises +ts+ on the given +addresses+ at +port+.
- #
- # If +addresses+ is omitted only the UDP broadcast address is used.
- #
- # +addresses+ can contain multiple addresses. If a multicast address is
- # given in +addresses+ then the RingServer will listen for multicast
- # queries.
- #
- # If you use IPv4 multicast you may need to set an address of the inbound
- # interface which joins a multicast group.
- #
- # ts = Rinda::TupleSpace.new
- # rs = Rinda::RingServer.new(ts, [['239.0.0.1', '9.5.1.1']])
- #
- # You can set addresses as an Array Object. The first element of the
- # Array is a multicast address and the second is an inbound interface
- # address. If the second is omitted then '0.0.0.0' is used.
- #
- # If you use IPv6 multicast you may need to set both the local interface
- # address and the inbound interface index:
- #
- # rs = Rinda::RingServer.new(ts, [['ff02::1', '::1', 1]])
- #
- # The first element is a multicast address and the second is an inbound
- # interface address. The third is an inbound interface index.
- #
- # At this time there is no easy way to get an interface index by name.
- #
- # If the second is omitted then '::1' is used.
- # If the third is omitted then 0 (default interface) is used.
-
- def initialize(ts, addresses=[Socket::INADDR_ANY], port=Ring_PORT)
- @port = port
-
- if Integer === addresses then
- addresses, @port = [Socket::INADDR_ANY], addresses
- end
-
- @renewer = Renewer.new
-
- @ts = ts
- @sockets = []
- addresses.each do |address|
- if Array === address
- make_socket(*address)
- else
- make_socket(address)
- end
- end
-
- @w_services = write_services
- @r_service = reply_service
- end
-
- ##
- # Creates a socket at +address+
- #
- # If +address+ is multicast address then +interface_address+ and
- # +multicast_interface+ can be set as optional.
- #
- # A created socket is bound to +interface_address+. If you use IPv4
- # multicast then the interface of +interface_address+ is used as the
- # inbound interface. If +interface_address+ is omitted or nil then
- # '0.0.0.0' or '::1' is used.
- #
- # If you use IPv6 multicast then +multicast_interface+ is used as the
- # inbound interface. +multicast_interface+ is a network interface index.
- # If +multicast_interface+ is omitted then 0 (default interface) is used.
-
- def make_socket(address, interface_address=nil, multicast_interface=0)
- addrinfo = Addrinfo.udp(address, @port)
-
- socket = Socket.new(addrinfo.pfamily, addrinfo.socktype,
- addrinfo.protocol)
- @sockets << socket
-
- if addrinfo.ipv4_multicast? or addrinfo.ipv6_multicast? then
- if Socket.const_defined?(:SO_REUSEPORT) then
- socket.setsockopt(:SOCKET, :SO_REUSEPORT, true)
- else
- socket.setsockopt(:SOCKET, :SO_REUSEADDR, true)
- end
-
- if addrinfo.ipv4_multicast? then
- interface_address = '0.0.0.0' if interface_address.nil?
- socket.bind(Addrinfo.udp(interface_address, @port))
-
- mreq = IPAddr.new(addrinfo.ip_address).hton +
- IPAddr.new(interface_address).hton
-
- socket.setsockopt(:IPPROTO_IP, :IP_ADD_MEMBERSHIP, mreq)
- else
- interface_address = '::1' if interface_address.nil?
- socket.bind(Addrinfo.udp(interface_address, @port))
-
- mreq = IPAddr.new(addrinfo.ip_address).hton +
- [multicast_interface].pack('I')
-
- socket.setsockopt(:IPPROTO_IPV6, :IPV6_JOIN_GROUP, mreq)
- end
- else
- socket.bind(addrinfo)
- end
-
- socket
- end
-
- ##
- # Creates threads that pick up UDP packets and passes them to do_write for
- # decoding.
-
- def write_services
- @sockets.map do |s|
- Thread.new(s) do |socket|
- loop do
- msg = socket.recv(1024)
- do_write(msg)
- end
- end
- end
- end
-
- ##
- # Extracts the response URI from +msg+ and adds it to TupleSpace where it
- # will be picked up by +reply_service+ for notification.
-
- def do_write(msg)
- Thread.new do
- begin
- tuple, sec = Marshal.load(msg)
- @ts.write(tuple, sec)
- rescue
- end
- end
- end
-
- ##
- # Creates a thread that notifies waiting clients from the TupleSpace.
-
- def reply_service
- Thread.new do
- loop do
- do_reply
- end
- end
- end
-
- ##
- # Pulls lookup tuples out of the TupleSpace and sends their DRb object the
- # address of the local TupleSpace.
-
- def do_reply
- tuple = @ts.take([:lookup_ring, nil], @renewer)
- Thread.new { tuple[1].call(@ts) rescue nil}
- rescue
- end
-
- ##
- # Shuts down the RingServer
-
- def shutdown
- @renewer.renew = false
-
- @w_services.each do |thread|
- thread.kill
- thread.join
- end
-
- @sockets.each do |socket|
- socket.close
- end
-
- @r_service.kill
- @r_service.join
- end
-
- end
-
- ##
- # RingFinger is used by RingServer clients to discover the RingServer's
- # TupleSpace. Typically, all a client needs to do is call
- # RingFinger.primary to retrieve the remote TupleSpace, which it can then
- # begin using.
- #
- # To find the first available remote TupleSpace:
- #
- # Rinda::RingFinger.primary
- #
- # To create a RingFinger that broadcasts to a custom list:
- #
- # rf = Rinda::RingFinger.new ['localhost', '192.0.2.1']
- # rf.primary
- #
- # Rinda::RingFinger also understands multicast addresses and sets them up
- # properly. This allows you to run multiple RingServers on the same host:
- #
- # rf = Rinda::RingFinger.new ['239.0.0.1']
- # rf.primary
- #
- # You can set the hop count (or TTL) for multicast searches using
- # #multicast_hops.
- #
- # If you use IPv6 multicast you may need to set both an address and the
- # outbound interface index:
- #
- # rf = Rinda::RingFinger.new ['ff02::1']
- # rf.multicast_interface = 1
- # rf.primary
- #
- # At this time there is no easy way to get an interface index by name.
-
- class RingFinger
-
- @@broadcast_list = ['<broadcast>', 'localhost']
-
- @@finger = nil
-
- ##
- # Creates a singleton RingFinger and looks for a RingServer. Returns the
- # created RingFinger.
-
- def self.finger
- unless @@finger
- @@finger = self.new
- @@finger.lookup_ring_any
- end
- @@finger
- end
-
- ##
- # Returns the first advertised TupleSpace.
-
- def self.primary
- finger.primary
- end
-
- ##
- # Contains all discovered TupleSpaces except for the primary.
-
- def self.to_a
- finger.to_a
- end
-
- ##
- # The list of addresses where RingFinger will send query packets.
-
- attr_accessor :broadcast_list
-
- ##
- # Maximum number of hops for sent multicast packets (if using a multicast
- # address in the broadcast list). The default is 1 (same as UDP
- # broadcast).
-
- attr_accessor :multicast_hops
-
- ##
- # The interface index to send IPv6 multicast packets from.
-
- attr_accessor :multicast_interface
-
- ##
- # The port that RingFinger will send query packets to.
-
- attr_accessor :port
-
- ##
- # Contain the first advertised TupleSpace after lookup_ring_any is called.
-
- attr_accessor :primary
-
- ##
- # Creates a new RingFinger that will look for RingServers at +port+ on
- # the addresses in +broadcast_list+.
- #
- # If +broadcast_list+ contains a multicast address then multicast queries
- # will be made using the given multicast_hops and multicast_interface.
-
- def initialize(broadcast_list=@@broadcast_list, port=Ring_PORT)
- @broadcast_list = broadcast_list || ['localhost']
- @port = port
- @primary = nil
- @rings = []
-
- @multicast_hops = 1
- @multicast_interface = 0
- end
-
- ##
- # Contains all discovered TupleSpaces except for the primary.
-
- def to_a
- @rings
- end
-
- ##
- # Iterates over all discovered TupleSpaces starting with the primary.
-
- def each
- lookup_ring_any unless @primary
- return unless @primary
- yield(@primary)
- @rings.each { |x| yield(x) }
- end
-
- ##
- # Looks up RingServers waiting +timeout+ seconds. RingServers will be
- # given +block+ as a callback, which will be called with the remote
- # TupleSpace.
-
- def lookup_ring(timeout=5, &block)
- return lookup_ring_any(timeout) unless block_given?
-
- msg = Marshal.dump([[:lookup_ring, DRbObject.new(block)], timeout])
- @broadcast_list.each do |it|
- send_message(it, msg)
- end
- sleep(timeout)
- end
-
- ##
- # Returns the first found remote TupleSpace. Any further recovered
- # TupleSpaces can be found by calling +to_a+.
-
- def lookup_ring_any(timeout=5)
- queue = Queue.new
-
- Thread.new do
- self.lookup_ring(timeout) do |ts|
- queue.push(ts)
- end
- queue.push(nil)
- end
-
- @primary = queue.pop
- raise('RingNotFound') if @primary.nil?
-
- Thread.new do
- while it = queue.pop
- @rings.push(it)
- end
- end
-
- @primary
- end
-
- ##
- # Creates a socket for +address+ with the appropriate multicast options
- # for multicast addresses.
-
- def make_socket(address) # :nodoc:
- addrinfo = Addrinfo.udp(address, @port)
-
- soc = Socket.new(addrinfo.pfamily, addrinfo.socktype, addrinfo.protocol)
- begin
- if addrinfo.ipv4_multicast? then
- soc.setsockopt(Socket::Option.ipv4_multicast_loop(1))
- soc.setsockopt(Socket::Option.ipv4_multicast_ttl(@multicast_hops))
- elsif addrinfo.ipv6_multicast? then
- soc.setsockopt(:IPPROTO_IPV6, :IPV6_MULTICAST_LOOP, true)
- soc.setsockopt(:IPPROTO_IPV6, :IPV6_MULTICAST_HOPS,
- [@multicast_hops].pack('I'))
- soc.setsockopt(:IPPROTO_IPV6, :IPV6_MULTICAST_IF,
- [@multicast_interface].pack('I'))
- else
- soc.setsockopt(:SOL_SOCKET, :SO_BROADCAST, true)
- end
-
- soc.connect(addrinfo)
- rescue Exception
- soc.close
- raise
- end
-
- soc
- end
-
- def send_message(address, message) # :nodoc:
- soc = make_socket(address)
-
- soc.send(message, 0)
- rescue
- nil
- ensure
- soc.close if soc
- end
-
- end
-
- ##
- # RingProvider uses a RingServer advertised TupleSpace as a name service.
- # TupleSpace clients can register themselves with the remote TupleSpace and
- # look up other provided services via the remote TupleSpace.
- #
- # Services are registered with a tuple of the format [:name, klass,
- # DRbObject, description].
-
- class RingProvider
-
- ##
- # Creates a RingProvider that will provide a +klass+ service running on
- # +front+, with a +description+. +renewer+ is optional.
-
- def initialize(klass, front, desc, renewer = nil)
- @tuple = [:name, klass, front, desc]
- @renewer = renewer || Rinda::SimpleRenewer.new
- end
-
- ##
- # Advertises this service on the primary remote TupleSpace.
-
- def provide
- ts = Rinda::RingFinger.primary
- ts.write(@tuple, @renewer)
- end
-
- end
-
-end
diff --git a/ruby_2_2/lib/rinda/tuplespace.rb b/ruby_2_2/lib/rinda/tuplespace.rb
deleted file mode 100644
index 11532fd161..0000000000
--- a/ruby_2_2/lib/rinda/tuplespace.rb
+++ /dev/null
@@ -1,642 +0,0 @@
-require 'monitor'
-require 'thread'
-require 'drb/drb'
-require 'rinda/rinda'
-require 'enumerator'
-require 'forwardable'
-
-module Rinda
-
- ##
- # A TupleEntry is a Tuple (i.e. a possible entry in some Tuplespace)
- # together with expiry and cancellation data.
-
- class TupleEntry
-
- include DRbUndumped
-
- attr_accessor :expires
-
- ##
- # Creates a TupleEntry based on +ary+ with an optional renewer or expiry
- # time +sec+.
- #
- # A renewer must implement the +renew+ method which returns a Numeric,
- # nil, or true to indicate when the tuple has expired.
-
- def initialize(ary, sec=nil)
- @cancel = false
- @expires = nil
- @tuple = make_tuple(ary)
- @renewer = nil
- renew(sec)
- end
-
- ##
- # Marks this TupleEntry as canceled.
-
- def cancel
- @cancel = true
- end
-
- ##
- # A TupleEntry is dead when it is canceled or expired.
-
- def alive?
- !canceled? && !expired?
- end
-
- ##
- # Return the object which makes up the tuple itself: the Array
- # or Hash.
-
- def value; @tuple.value; end
-
- ##
- # Returns the canceled status.
-
- def canceled?; @cancel; end
-
- ##
- # Has this tuple expired? (true/false).
- #
- # A tuple has expired when its expiry timer based on the +sec+ argument to
- # #initialize runs out.
-
- def expired?
- return true unless @expires
- return false if @expires > Time.now
- return true if @renewer.nil?
- renew(@renewer)
- return true unless @expires
- return @expires < Time.now
- end
-
- ##
- # Reset the expiry time according to +sec_or_renewer+.
- #
- # +nil+:: it is set to expire in the far future.
- # +true+:: it has expired.
- # Numeric:: it will expire in that many seconds.
- #
- # Otherwise the argument refers to some kind of renewer object
- # which will reset its expiry time.
-
- def renew(sec_or_renewer)
- sec, @renewer = get_renewer(sec_or_renewer)
- @expires = make_expires(sec)
- end
-
- ##
- # Returns an expiry Time based on +sec+ which can be one of:
- # Numeric:: +sec+ seconds into the future
- # +true+:: the expiry time is the start of 1970 (i.e. expired)
- # +nil+:: it is Tue Jan 19 03:14:07 GMT Standard Time 2038 (i.e. when
- # UNIX clocks will die)
-
- def make_expires(sec=nil)
- case sec
- when Numeric
- Time.now + sec
- when true
- Time.at(1)
- when nil
- Time.at(2**31-1)
- end
- end
-
- ##
- # Retrieves +key+ from the tuple.
-
- def [](key)
- @tuple[key]
- end
-
- ##
- # Fetches +key+ from the tuple.
-
- def fetch(key)
- @tuple.fetch(key)
- end
-
- ##
- # The size of the tuple.
-
- def size
- @tuple.size
- end
-
- ##
- # Creates a Rinda::Tuple for +ary+.
-
- def make_tuple(ary)
- Rinda::Tuple.new(ary)
- end
-
- private
-
- ##
- # Returns a valid argument to make_expires and the renewer or nil.
- #
- # Given +true+, +nil+, or Numeric, returns that value and +nil+ (no actual
- # renewer). Otherwise it returns an expiry value from calling +it.renew+
- # and the renewer.
-
- def get_renewer(it)
- case it
- when Numeric, true, nil
- return it, nil
- else
- begin
- return it.renew, it
- rescue Exception
- return it, nil
- end
- end
- end
-
- end
-
- ##
- # A TemplateEntry is a Template together with expiry and cancellation data.
-
- class TemplateEntry < TupleEntry
- ##
- # Matches this TemplateEntry against +tuple+. See Template#match for
- # details on how a Template matches a Tuple.
-
- def match(tuple)
- @tuple.match(tuple)
- end
-
- alias === match
-
- def make_tuple(ary) # :nodoc:
- Rinda::Template.new(ary)
- end
-
- end
-
- ##
- # <i>Documentation?</i>
-
- class WaitTemplateEntry < TemplateEntry
-
- attr_reader :found
-
- def initialize(place, ary, expires=nil)
- super(ary, expires)
- @place = place
- @cond = place.new_cond
- @found = nil
- end
-
- def cancel
- super
- signal
- end
-
- def wait
- @cond.wait
- end
-
- def read(tuple)
- @found = tuple
- signal
- end
-
- def signal
- @place.synchronize do
- @cond.signal
- end
- end
-
- end
-
- ##
- # A NotifyTemplateEntry is returned by TupleSpace#notify and is notified of
- # TupleSpace changes. You may receive either your subscribed event or the
- # 'close' event when iterating over notifications.
- #
- # See TupleSpace#notify_event for valid notification types.
- #
- # == Example
- #
- # ts = Rinda::TupleSpace.new
- # observer = ts.notify 'write', [nil]
- #
- # Thread.start do
- # observer.each { |t| p t }
- # end
- #
- # 3.times { |i| ts.write [i] }
- #
- # Outputs:
- #
- # ['write', [0]]
- # ['write', [1]]
- # ['write', [2]]
-
- class NotifyTemplateEntry < TemplateEntry
-
- ##
- # Creates a new NotifyTemplateEntry that watches +place+ for +event+s that
- # match +tuple+.
-
- def initialize(place, event, tuple, expires=nil)
- ary = [event, Rinda::Template.new(tuple)]
- super(ary, expires)
- @queue = Queue.new
- @done = false
- end
-
- ##
- # Called by TupleSpace to notify this NotifyTemplateEntry of a new event.
-
- def notify(ev)
- @queue.push(ev)
- end
-
- ##
- # Retrieves a notification. Raises RequestExpiredError when this
- # NotifyTemplateEntry expires.
-
- def pop
- raise RequestExpiredError if @done
- it = @queue.pop
- @done = true if it[0] == 'close'
- return it
- end
-
- ##
- # Yields event/tuple pairs until this NotifyTemplateEntry expires.
-
- def each # :yields: event, tuple
- while !@done
- it = pop
- yield(it)
- end
- rescue
- ensure
- cancel
- end
-
- end
-
- ##
- # TupleBag is an unordered collection of tuples. It is the basis
- # of Tuplespace.
-
- class TupleBag
- class TupleBin
- extend Forwardable
- def_delegators '@bin', :find_all, :delete_if, :each, :empty?
-
- def initialize
- @bin = []
- end
-
- def add(tuple)
- @bin.push(tuple)
- end
-
- def delete(tuple)
- idx = @bin.rindex(tuple)
- @bin.delete_at(idx) if idx
- end
-
- def find
- @bin.reverse_each do |x|
- return x if yield(x)
- end
- nil
- end
- end
-
- def initialize # :nodoc:
- @hash = {}
- @enum = enum_for(:each_entry)
- end
-
- ##
- # +true+ if the TupleBag to see if it has any expired entries.
-
- def has_expires?
- @enum.find do |tuple|
- tuple.expires
- end
- end
-
- ##
- # Add +tuple+ to the TupleBag.
-
- def push(tuple)
- key = bin_key(tuple)
- @hash[key] ||= TupleBin.new
- @hash[key].add(tuple)
- end
-
- ##
- # Removes +tuple+ from the TupleBag.
-
- def delete(tuple)
- key = bin_key(tuple)
- bin = @hash[key]
- return nil unless bin
- bin.delete(tuple)
- @hash.delete(key) if bin.empty?
- tuple
- end
-
- ##
- # Finds all live tuples that match +template+.
- def find_all(template)
- bin_for_find(template).find_all do |tuple|
- tuple.alive? && template.match(tuple)
- end
- end
-
- ##
- # Finds a live tuple that matches +template+.
-
- def find(template)
- bin_for_find(template).find do |tuple|
- tuple.alive? && template.match(tuple)
- end
- end
-
- ##
- # Finds all tuples in the TupleBag which when treated as templates, match
- # +tuple+ and are alive.
-
- def find_all_template(tuple)
- @enum.find_all do |template|
- template.alive? && template.match(tuple)
- end
- end
-
- ##
- # Delete tuples which dead tuples from the TupleBag, returning the deleted
- # tuples.
-
- def delete_unless_alive
- deleted = []
- @hash.each do |key, bin|
- bin.delete_if do |tuple|
- if tuple.alive?
- false
- else
- deleted.push(tuple)
- true
- end
- end
- end
- deleted
- end
-
- private
- def each_entry(&blk)
- @hash.each do |k, v|
- v.each(&blk)
- end
- end
-
- def bin_key(tuple)
- head = tuple[0]
- if head.class == Symbol
- return head
- else
- false
- end
- end
-
- def bin_for_find(template)
- key = bin_key(template)
- key ? @hash.fetch(key, []) : @enum
- end
- end
-
- ##
- # The Tuplespace manages access to the tuples it contains,
- # ensuring mutual exclusion requirements are met.
- #
- # The +sec+ option for the write, take, move, read and notify methods may
- # either be a number of seconds or a Renewer object.
-
- class TupleSpace
-
- include DRbUndumped
- include MonitorMixin
-
- ##
- # Creates a new TupleSpace. +period+ is used to control how often to look
- # for dead tuples after modifications to the TupleSpace.
- #
- # If no dead tuples are found +period+ seconds after the last
- # modification, the TupleSpace will stop looking for dead tuples.
-
- def initialize(period=60)
- super()
- @bag = TupleBag.new
- @read_waiter = TupleBag.new
- @take_waiter = TupleBag.new
- @notify_waiter = TupleBag.new
- @period = period
- @keeper = nil
- end
-
- ##
- # Adds +tuple+
-
- def write(tuple, sec=nil)
- entry = create_entry(tuple, sec)
- synchronize do
- if entry.expired?
- @read_waiter.find_all_template(entry).each do |template|
- template.read(tuple)
- end
- notify_event('write', entry.value)
- notify_event('delete', entry.value)
- else
- @bag.push(entry)
- start_keeper if entry.expires
- @read_waiter.find_all_template(entry).each do |template|
- template.read(tuple)
- end
- @take_waiter.find_all_template(entry).each do |template|
- template.signal
- end
- notify_event('write', entry.value)
- end
- end
- entry
- end
-
- ##
- # Removes +tuple+
-
- def take(tuple, sec=nil, &block)
- move(nil, tuple, sec, &block)
- end
-
- ##
- # Moves +tuple+ to +port+.
-
- def move(port, tuple, sec=nil)
- template = WaitTemplateEntry.new(self, tuple, sec)
- yield(template) if block_given?
- synchronize do
- entry = @bag.find(template)
- if entry
- port.push(entry.value) if port
- @bag.delete(entry)
- notify_event('take', entry.value)
- return port ? nil : entry.value
- end
- raise RequestExpiredError if template.expired?
-
- begin
- @take_waiter.push(template)
- start_keeper if template.expires
- while true
- raise RequestCanceledError if template.canceled?
- raise RequestExpiredError if template.expired?
- entry = @bag.find(template)
- if entry
- port.push(entry.value) if port
- @bag.delete(entry)
- notify_event('take', entry.value)
- return port ? nil : entry.value
- end
- template.wait
- end
- ensure
- @take_waiter.delete(template)
- end
- end
- end
-
- ##
- # Reads +tuple+, but does not remove it.
-
- def read(tuple, sec=nil)
- template = WaitTemplateEntry.new(self, tuple, sec)
- yield(template) if block_given?
- synchronize do
- entry = @bag.find(template)
- return entry.value if entry
- raise RequestExpiredError if template.expired?
-
- begin
- @read_waiter.push(template)
- start_keeper if template.expires
- template.wait
- raise RequestCanceledError if template.canceled?
- raise RequestExpiredError if template.expired?
- return template.found
- ensure
- @read_waiter.delete(template)
- end
- end
- end
-
- ##
- # Returns all tuples matching +tuple+. Does not remove the found tuples.
-
- def read_all(tuple)
- template = WaitTemplateEntry.new(self, tuple, nil)
- synchronize do
- entry = @bag.find_all(template)
- entry.collect do |e|
- e.value
- end
- end
- end
-
- ##
- # Registers for notifications of +event+. Returns a NotifyTemplateEntry.
- # See NotifyTemplateEntry for examples of how to listen for notifications.
- #
- # +event+ can be:
- # 'write':: A tuple was added
- # 'take':: A tuple was taken or moved
- # 'delete':: A tuple was lost after being overwritten or expiring
- #
- # The TupleSpace will also notify you of the 'close' event when the
- # NotifyTemplateEntry has expired.
-
- def notify(event, tuple, sec=nil)
- template = NotifyTemplateEntry.new(self, event, tuple, sec)
- synchronize do
- @notify_waiter.push(template)
- end
- template
- end
-
- private
-
- def create_entry(tuple, sec)
- TupleEntry.new(tuple, sec)
- end
-
- ##
- # Removes dead tuples.
-
- def keep_clean
- synchronize do
- @read_waiter.delete_unless_alive.each do |e|
- e.signal
- end
- @take_waiter.delete_unless_alive.each do |e|
- e.signal
- end
- @notify_waiter.delete_unless_alive.each do |e|
- e.notify(['close'])
- end
- @bag.delete_unless_alive.each do |e|
- notify_event('delete', e.value)
- end
- end
- end
-
- ##
- # Notifies all registered listeners for +event+ of a status change of
- # +tuple+.
-
- def notify_event(event, tuple)
- ev = [event, tuple]
- @notify_waiter.find_all_template(ev).each do |template|
- template.notify(ev)
- end
- end
-
- ##
- # Creates a thread that scans the tuplespace for expired tuples.
-
- def start_keeper
- return if @keeper && @keeper.alive?
- @keeper = Thread.new do
- while true
- sleep(@period)
- synchronize do
- break unless need_keeper?
- keep_clean
- end
- end
- end
- end
-
- ##
- # Checks the tuplespace to see if it needs cleaning.
-
- def need_keeper?
- return true if @bag.has_expires?
- return true if @read_waiter.has_expires?
- return true if @take_waiter.has_expires?
- return true if @notify_waiter.has_expires?
- end
-
- end
-
-end
-
diff --git a/ruby_2_2/lib/rss.rb b/ruby_2_2/lib/rss.rb
deleted file mode 100644
index fd7364645b..0000000000
--- a/ruby_2_2/lib/rss.rb
+++ /dev/null
@@ -1,91 +0,0 @@
-##
-# = RSS reading and writing
-#
-# Really Simple Syndication (RSS) is a family of formats that describe 'feeds,'
-# specially constructed XML documents that allow an interested person to
-# subscribe and receive updates from a particular web service. This portion of
-# the standard library provides tooling to read and create these feeds.
-#
-# The standard library supports RSS 0.91, 1.0, 2.0, and Atom, a related format.
-# Here are some links to the standards documents for these formats:
-#
-# * RSS
-# * 0.9.1[http://www.rssboard.org/rss-0-9-1-netscape]
-# * 1.0[http://web.resource.org/rss/1.0/]
-# * 2.0[http://www.rssboard.org/rss-specification]
-# * Atom[http://tools.ietf.org/html/rfc4287]
-#
-# == Consuming RSS
-#
-# If you'd like to read someone's RSS feed with your Ruby code, you've come to
-# the right place. It's really easy to do this, but we'll need the help of
-# open-uri:
-#
-# require 'rss'
-# require 'open-uri'
-#
-# url = 'http://www.ruby-lang.org/en/feeds/news.rss'
-# open(url) do |rss|
-# feed = RSS::Parser.parse(rss)
-# puts "Title: #{feed.channel.title}"
-# feed.items.each do |item|
-# puts "Item: #{item.title}"
-# end
-# end
-#
-# As you can see, the workhorse is RSS::Parser#parse, which takes the source of
-# the feed and a parameter that performs validation on the feed. We get back an
-# object that has all of the data from our feed, accessible through methods.
-# This example shows getting the title out of the channel element, and looping
-# through the list of items.
-#
-# == Producing RSS
-#
-# Producing our own RSS feeds is easy as well. Let's make a very basic feed:
-#
-# require "rss"
-#
-# rss = RSS::Maker.make("atom") do |maker|
-# maker.channel.author = "matz"
-# maker.channel.updated = Time.now.to_s
-# maker.channel.about = "http://www.ruby-lang.org/en/feeds/news.rss"
-# maker.channel.title = "Example Feed"
-#
-# maker.items.new_item do |item|
-# item.link = "http://www.ruby-lang.org/en/news/2010/12/25/ruby-1-9-2-p136-is-released/"
-# item.title = "Ruby 1.9.2-p136 is released"
-# item.updated = Time.now.to_s
-# end
-# end
-#
-# puts rss
-#
-# As you can see, this is a very Builder-like DSL. This code will spit out an
-# Atom feed with one item. If we needed a second item, we'd make another block
-# with maker.items.new_item and build a second one.
-#
-# == Copyright
-#
-# Copyright (c) 2003-2007 Kouhei Sutou <kou@cozmixng.org>
-#
-# You can redistribute it and/or modify it under the same terms as Ruby.
-#
-# There is an additional tutorial by the author of RSS at:
-# http://www.cozmixng.org/~rwiki/?cmd=view;name=RSS+Parser%3A%3ATutorial.en
-
-module RSS
-end
-
-require 'rss/1.0'
-require 'rss/2.0'
-require 'rss/atom'
-require 'rss/content'
-require 'rss/dublincore'
-require 'rss/image'
-require 'rss/itunes'
-require 'rss/slash'
-require 'rss/syndication'
-require 'rss/taxonomy'
-require 'rss/trackback'
-
-require "rss/maker"
diff --git a/ruby_2_2/lib/rss/0.9.rb b/ruby_2_2/lib/rss/0.9.rb
deleted file mode 100644
index 77b2de131c..0000000000
--- a/ruby_2_2/lib/rss/0.9.rb
+++ /dev/null
@@ -1,461 +0,0 @@
-require "rss/parser"
-
-module RSS
-
- ##
- # = RSS 0.9 support
- #
- # RSS has three different versions. This module contains support for version
- # 0.9.1[http://www.rssboard.org/rss-0-9-1-netscape].
- #
- # == Producing RSS 0.9
- #
- # Producing our own RSS feeds is easy as well. Let's make a very basic feed:
- #
- # require "rss"
- #
- # rss = RSS::Maker.make("0.91") do |maker|
- # maker.channel.language = "en"
- # maker.channel.author = "matz"
- # maker.channel.updated = Time.now.to_s
- # maker.channel.link = "http://www.ruby-lang.org/en/feeds/news.rss"
- # maker.channel.title = "Example Feed"
- # maker.channel.description = "A longer description of my feed."
- # maker.image.url = "http://www.ruby-lang.org/images/logo.gif"
- # maker.image.title = "An image"
- # maker.items.new_item do |item|
- # item.link = "http://www.ruby-lang.org/en/news/2010/12/25/ruby-1-9-2-p136-is-released/"
- # item.title = "Ruby 1.9.2-p136 is released"
- # item.updated = Time.now.to_s
- # end
- # end
- #
- # puts rss
- #
- # As you can see, this is a very Builder-like DSL. This code will spit out an
- # RSS 0.9 feed with one item. If we needed a second item, we'd make another
- # block with maker.items.new_item and build a second one.
- module RSS09
- NSPOOL = {}
- ELEMENTS = []
-
- def self.append_features(klass)
- super
-
- klass.install_must_call_validator('', "")
- end
- end
-
- class Rss < Element
-
- include RSS09
- include RootElementMixin
-
- %w(channel).each do |name|
- install_have_child_element(name, "", nil)
- end
-
- attr_writer :feed_version
- alias_method(:rss_version, :feed_version)
- alias_method(:rss_version=, :feed_version=)
-
- def initialize(feed_version, version=nil, encoding=nil, standalone=nil)
- super
- @feed_type = "rss"
- end
-
- def items
- if @channel
- @channel.items
- else
- []
- end
- end
-
- def image
- if @channel
- @channel.image
- else
- nil
- end
- end
-
- def textinput
- if @channel
- @channel.textInput
- else
- nil
- end
- end
-
- def setup_maker_elements(maker)
- super
- items.each do |item|
- item.setup_maker(maker.items)
- end
- image.setup_maker(maker) if image
- textinput.setup_maker(maker) if textinput
- end
-
- private
- def _attrs
- [
- ["version", true, "feed_version"],
- ]
- end
-
- class Channel < Element
-
- include RSS09
-
- [
- ["title", nil, :text],
- ["link", nil, :text],
- ["description", nil, :text],
- ["language", nil, :text],
- ["copyright", "?", :text],
- ["managingEditor", "?", :text],
- ["webMaster", "?", :text],
- ["rating", "?", :text],
- ["pubDate", "?", :date, :rfc822],
- ["lastBuildDate", "?", :date, :rfc822],
- ["docs", "?", :text],
- ["cloud", "?", :have_attribute],
- ["skipDays", "?", :have_child],
- ["skipHours", "?", :have_child],
- ["image", nil, :have_child],
- ["item", "*", :have_children],
- ["textInput", "?", :have_child],
- ].each do |name, occurs, type, *args|
- __send__("install_#{type}_element", name, "", occurs, name, *args)
- end
- alias date pubDate
- alias date= pubDate=
-
- private
- def maker_target(maker)
- maker.channel
- end
-
- def setup_maker_elements(channel)
- super
- [
- [skipDays, "day"],
- [skipHours, "hour"],
- ].each do |skip, key|
- if skip
- skip.__send__("#{key}s").each do |val|
- target_skips = channel.__send__("skip#{key.capitalize}s")
- new_target = target_skips.__send__("new_#{key}")
- new_target.content = val.content
- end
- end
- end
- end
-
- def not_need_to_call_setup_maker_variables
- %w(image textInput)
- end
-
- class SkipDays < Element
- include RSS09
-
- [
- ["day", "*"]
- ].each do |name, occurs|
- install_have_children_element(name, "", occurs)
- end
-
- class Day < Element
- include RSS09
-
- content_setup
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.content = args[0]
- end
- end
-
- end
-
- end
-
- class SkipHours < Element
- include RSS09
-
- [
- ["hour", "*"]
- ].each do |name, occurs|
- install_have_children_element(name, "", occurs)
- end
-
- class Hour < Element
- include RSS09
-
- content_setup(:integer)
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.content = args[0]
- end
- end
- end
-
- end
-
- class Image < Element
-
- include RSS09
-
- %w(url title link).each do |name|
- install_text_element(name, "", nil)
- end
- [
- ["width", :integer],
- ["height", :integer],
- ["description"],
- ].each do |name, type|
- install_text_element(name, "", "?", name, type)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.url = args[0]
- self.title = args[1]
- self.link = args[2]
- self.width = args[3]
- self.height = args[4]
- self.description = args[5]
- end
- end
-
- private
- def maker_target(maker)
- maker.image
- end
- end
-
- class Cloud < Element
-
- include RSS09
-
- [
- ["domain", "", true],
- ["port", "", true, :integer],
- ["path", "", true],
- ["registerProcedure", "", true],
- ["protocol", "", true],
- ].each do |name, uri, required, type|
- install_get_attribute(name, uri, required, type)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.domain = args[0]
- self.port = args[1]
- self.path = args[2]
- self.registerProcedure = args[3]
- self.protocol = args[4]
- end
- end
- end
-
- class Item < Element
-
- include RSS09
-
- [
- ["title", '?', :text],
- ["link", '?', :text],
- ["description", '?', :text],
- ["category", '*', :have_children, "categories"],
- ["source", '?', :have_child],
- ["enclosure", '?', :have_child],
- ].each do |tag, occurs, type, *args|
- __send__("install_#{type}_element", tag, "", occurs, tag, *args)
- end
-
- private
- def maker_target(items)
- if items.respond_to?("items")
- # For backward compatibility
- items = items.items
- end
- items.new_item
- end
-
- def setup_maker_element(item)
- super
- @enclosure.setup_maker(item) if @enclosure
- @source.setup_maker(item) if @source
- end
-
- class Source < Element
-
- include RSS09
-
- [
- ["url", "", true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- content_setup
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.url = args[0]
- self.content = args[1]
- end
- end
-
- private
- def maker_target(item)
- item.source
- end
-
- def setup_maker_attributes(source)
- source.url = url
- source.content = content
- end
- end
-
- class Enclosure < Element
-
- include RSS09
-
- [
- ["url", "", true],
- ["length", "", true, :integer],
- ["type", "", true],
- ].each do |name, uri, required, type|
- install_get_attribute(name, uri, required, type)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.url = args[0]
- self.length = args[1]
- self.type = args[2]
- end
- end
-
- private
- def maker_target(item)
- item.enclosure
- end
-
- def setup_maker_attributes(enclosure)
- enclosure.url = url
- enclosure.length = length
- enclosure.type = type
- end
- end
-
- class Category < Element
-
- include RSS09
-
- [
- ["domain", "", false]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- content_setup
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.domain = args[0]
- self.content = args[1]
- end
- end
-
- private
- def maker_target(item)
- item.new_category
- end
-
- def setup_maker_attributes(category)
- category.domain = domain
- category.content = content
- end
-
- end
-
- end
-
- class TextInput < Element
-
- include RSS09
-
- %w(title description name link).each do |name|
- install_text_element(name, "", nil)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.title = args[0]
- self.description = args[1]
- self.name = args[2]
- self.link = args[3]
- end
- end
-
- private
- def maker_target(maker)
- maker.textinput
- end
- end
-
- end
-
- end
-
- RSS09::ELEMENTS.each do |name|
- BaseListener.install_get_text_element("", name, name)
- end
-
- module ListenerMixin
- private
- def initial_start_rss(tag_name, prefix, attrs, ns)
- check_ns(tag_name, prefix, ns, "", false)
-
- @rss = Rss.new(attrs['version'], @version, @encoding, @standalone)
- @rss.do_validate = @do_validate
- @rss.xml_stylesheets = @xml_stylesheets
- @last_element = @rss
- pr = Proc.new do |text, tags|
- @rss.validate_for_stream(tags, @ignore_unknown_element) if @do_validate
- end
- @proc_stack.push(pr)
- end
-
- end
-
-end
diff --git a/ruby_2_2/lib/rss/1.0.rb b/ruby_2_2/lib/rss/1.0.rb
deleted file mode 100644
index a2d88d459e..0000000000
--- a/ruby_2_2/lib/rss/1.0.rb
+++ /dev/null
@@ -1,484 +0,0 @@
-require "rss/parser"
-
-module RSS
-
- ##
- # = RSS 1.0 support
- #
- # RSS has three different versions. This module contains support for version
- # 1.0[http://web.resource.org/rss/1.0/]
- #
- # == Producing RSS 1.0
- #
- # Producing our own RSS feeds is easy as well. Let's make a very basic feed:
- #
- # require "rss"
- #
- # rss = RSS::Maker.make("1.0") do |maker|
- # maker.channel.language = "en"
- # maker.channel.author = "matz"
- # maker.channel.about = "About my feed."
- # maker.channel.updated = Time.now.to_s
- # maker.channel.link = "http://www.ruby-lang.org/en/feeds/news.rss"
- # maker.channel.title = "Example Feed"
- # maker.channel.description = "A longer description of my feed."
- # maker.items.new_item do |item|
- # item.link = "http://www.ruby-lang.org/en/news/2010/12/25/ruby-1-9-2-p136-is-released/"
- # item.title = "Ruby 1.9.2-p136 is released"
- # item.updated = Time.now.to_s
- # end
- # end
- #
- # puts rss
- #
- # As you can see, this is a very Builder-like DSL. This code will spit out an
- # RSS 1.0 feed with one item. If we needed a second item, we'd make another
- # block with maker.items.new_item and build a second one.
- module RSS10
- NSPOOL = {}
- ELEMENTS = []
-
- def self.append_features(klass)
- super
-
- klass.install_must_call_validator('', ::RSS::URI)
- end
-
- end
-
- class RDF < Element
-
- include RSS10
- include RootElementMixin
-
- class << self
-
- def required_uri
- URI
- end
-
- end
-
- @tag_name = 'RDF'
-
- PREFIX = 'rdf'
- URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-
- install_ns('', ::RSS::URI)
- install_ns(PREFIX, URI)
-
- [
- ["channel", nil],
- ["image", "?"],
- ["item", "+", :children],
- ["textinput", "?"],
- ].each do |tag, occurs, type|
- type ||= :child
- __send__("install_have_#{type}_element", tag, ::RSS::URI, occurs)
- end
-
- alias_method(:rss_version, :feed_version)
- def initialize(version=nil, encoding=nil, standalone=nil)
- super('1.0', version, encoding, standalone)
- @feed_type = "rss"
- end
-
- def full_name
- tag_name_with_prefix(PREFIX)
- end
-
- class Li < Element
-
- include RSS10
-
- class << self
- def required_uri
- URI
- end
- end
-
- [
- ["resource", [URI, ""], true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.resource = args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(PREFIX)
- end
- end
-
- class Seq < Element
-
- include RSS10
-
- Li = ::RSS::RDF::Li
-
- class << self
- def required_uri
- URI
- end
- end
-
- @tag_name = 'Seq'
-
- install_have_children_element("li", URI, "*")
- install_must_call_validator('rdf', ::RSS::RDF::URI)
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- @li = args[0] if args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(PREFIX)
- end
-
- def setup_maker(target)
- lis.each do |li|
- target << li.resource
- end
- end
- end
-
- class Bag < Element
-
- include RSS10
-
- Li = ::RSS::RDF::Li
-
- class << self
- def required_uri
- URI
- end
- end
-
- @tag_name = 'Bag'
-
- install_have_children_element("li", URI, "*")
- install_must_call_validator('rdf', URI)
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- @li = args[0] if args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(PREFIX)
- end
-
- def setup_maker(target)
- lis.each do |li|
- target << li.resource
- end
- end
- end
-
- class Channel < Element
-
- include RSS10
-
- class << self
-
- def required_uri
- ::RSS::URI
- end
-
- end
-
- [
- ["about", URI, true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required, nil, nil,
- "#{PREFIX}:#{name}")
- end
-
- [
- ['title', nil, :text],
- ['link', nil, :text],
- ['description', nil, :text],
- ['image', '?', :have_child],
- ['items', nil, :have_child],
- ['textinput', '?', :have_child],
- ].each do |tag, occurs, type|
- __send__("install_#{type}_element", tag, ::RSS::URI, occurs)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.about = args[0]
- end
- end
-
- private
- def maker_target(maker)
- maker.channel
- end
-
- def setup_maker_attributes(channel)
- channel.about = about
- end
-
- class Image < Element
-
- include RSS10
-
- class << self
-
- def required_uri
- ::RSS::URI
- end
-
- end
-
- [
- ["resource", URI, true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required, nil, nil,
- "#{PREFIX}:#{name}")
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.resource = args[0]
- end
- end
- end
-
- class Textinput < Element
-
- include RSS10
-
- class << self
-
- def required_uri
- ::RSS::URI
- end
-
- end
-
- [
- ["resource", URI, true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required, nil, nil,
- "#{PREFIX}:#{name}")
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.resource = args[0]
- end
- end
- end
-
- class Items < Element
-
- include RSS10
-
- Seq = ::RSS::RDF::Seq
-
- class << self
-
- def required_uri
- ::RSS::URI
- end
-
- end
-
- install_have_child_element("Seq", URI, nil)
- install_must_call_validator('rdf', URI)
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.Seq = args[0]
- end
- self.Seq ||= Seq.new
- end
-
- def resources
- if @Seq
- @Seq.lis.collect do |li|
- li.resource
- end
- else
- []
- end
- end
- end
- end
-
- class Image < Element
-
- include RSS10
-
- class << self
-
- def required_uri
- ::RSS::URI
- end
-
- end
-
- [
- ["about", URI, true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required, nil, nil,
- "#{PREFIX}:#{name}")
- end
-
- %w(title url link).each do |name|
- install_text_element(name, ::RSS::URI, nil)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.about = args[0]
- end
- end
-
- private
- def maker_target(maker)
- maker.image
- end
- end
-
- class Item < Element
-
- include RSS10
-
- class << self
-
- def required_uri
- ::RSS::URI
- end
-
- end
-
-
- [
- ["about", URI, true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required, nil, nil,
- "#{PREFIX}:#{name}")
- end
-
- [
- ["title", nil],
- ["link", nil],
- ["description", "?"],
- ].each do |tag, occurs|
- install_text_element(tag, ::RSS::URI, occurs)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.about = args[0]
- end
- end
-
- private
- def maker_target(items)
- if items.respond_to?("items")
- # For backward compatibility
- items = items.items
- end
- items.new_item
- end
- end
-
- class Textinput < Element
-
- include RSS10
-
- class << self
-
- def required_uri
- ::RSS::URI
- end
-
- end
-
- [
- ["about", URI, true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required, nil, nil,
- "#{PREFIX}:#{name}")
- end
-
- %w(title description name link).each do |name|
- install_text_element(name, ::RSS::URI, nil)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.about = args[0]
- end
- end
-
- private
- def maker_target(maker)
- maker.textinput
- end
- end
-
- end
-
- RSS10::ELEMENTS.each do |name|
- BaseListener.install_get_text_element(URI, name, name)
- end
-
- module ListenerMixin
- private
- def initial_start_RDF(tag_name, prefix, attrs, ns)
- check_ns(tag_name, prefix, ns, RDF::URI, false)
-
- @rss = RDF.new(@version, @encoding, @standalone)
- @rss.do_validate = @do_validate
- @rss.xml_stylesheets = @xml_stylesheets
- @last_element = @rss
- pr = Proc.new do |text, tags|
- @rss.validate_for_stream(tags, @ignore_unknown_element) if @do_validate
- end
- @proc_stack.push(pr)
- end
- end
-
-end
diff --git a/ruby_2_2/lib/rss/2.0.rb b/ruby_2_2/lib/rss/2.0.rb
deleted file mode 100644
index 5c0caecd73..0000000000
--- a/ruby_2_2/lib/rss/2.0.rb
+++ /dev/null
@@ -1,142 +0,0 @@
-require "rss/0.9"
-
-module RSS
-
- ##
- # = RSS 2.0 support
- #
- # RSS has three different versions. This module contains support for version
- # 2.0[http://www.rssboard.org/rss-specification]
- #
- # == Producing RSS 2.0
- #
- # Producing our own RSS feeds is easy as well. Let's make a very basic feed:
- #
- # require "rss"
- #
- # rss = RSS::Maker.make("2.0") do |maker|
- # maker.channel.language = "en"
- # maker.channel.author = "matz"
- # maker.channel.updated = Time.now.to_s
- # maker.channel.link = "http://www.ruby-lang.org/en/feeds/news.rss"
- # maker.channel.title = "Example Feed"
- # maker.channel.description = "A longer description of my feed."
- # maker.items.new_item do |item|
- # item.link = "http://www.ruby-lang.org/en/news/2010/12/25/ruby-1-9-2-p136-is-released/"
- # item.title = "Ruby 1.9.2-p136 is released"
- # item.updated = Time.now.to_s
- # end
- # end
- #
- # puts rss
- #
- # As you can see, this is a very Builder-like DSL. This code will spit out an
- # RSS 2.0 feed with one item. If we needed a second item, we'd make another
- # block with maker.items.new_item and build a second one.
- class Rss
-
- class Channel
-
- [
- ["generator"],
- ["ttl", :integer],
- ].each do |name, type|
- install_text_element(name, "", "?", name, type)
- end
-
- [
- %w(category categories),
- ].each do |name, plural_name|
- install_have_children_element(name, "", "*", name, plural_name)
- end
-
- [
- ["image", "?"],
- ["language", "?"],
- ].each do |name, occurs|
- install_model(name, "", occurs)
- end
-
- Category = Item::Category
-
- class Item
-
- [
- ["comments", "?"],
- ["author", "?"],
- ].each do |name, occurs|
- install_text_element(name, "", occurs)
- end
-
- [
- ["pubDate", '?'],
- ].each do |name, occurs|
- install_date_element(name, "", occurs, name, 'rfc822')
- end
- alias date pubDate
- alias date= pubDate=
-
- [
- ["guid", '?'],
- ].each do |name, occurs|
- install_have_child_element(name, "", occurs)
- end
-
- private
- alias _setup_maker_element setup_maker_element
- def setup_maker_element(item)
- _setup_maker_element(item)
- @guid.setup_maker(item) if @guid
- end
-
- class Guid < Element
-
- include RSS09
-
- [
- ["isPermaLink", "", false, :boolean]
- ].each do |name, uri, required, type|
- install_get_attribute(name, uri, required, type)
- end
-
- content_setup
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.isPermaLink = args[0]
- self.content = args[1]
- end
- end
-
- alias_method :_PermaLink?, :PermaLink?
- private :_PermaLink?
- def PermaLink?
- perma = _PermaLink?
- perma or perma.nil?
- end
-
- private
- def maker_target(item)
- item.guid
- end
-
- def setup_maker_attributes(guid)
- guid.isPermaLink = isPermaLink
- guid.content = content
- end
- end
-
- end
-
- end
-
- end
-
- RSS09::ELEMENTS.each do |name|
- BaseListener.install_get_text_element("", name, name)
- end
-
-end
diff --git a/ruby_2_2/lib/rss/atom.rb b/ruby_2_2/lib/rss/atom.rb
deleted file mode 100644
index d3524231ff..0000000000
--- a/ruby_2_2/lib/rss/atom.rb
+++ /dev/null
@@ -1,839 +0,0 @@
-require 'rss/parser'
-
-module RSS
- ##
- # Atom is an XML-based document format that is used to describe 'feeds' of related information.
- # A typical use is in a news feed where the information is periodically updated and which users
- # can subscribe to. The Atom format is described in http://tools.ietf.org/html/rfc4287
- #
- # The Atom module provides support in reading and creating feeds.
- #
- # See the RSS module for examples consuming and creating feeds.
- module Atom
-
- ##
- # The Atom URI W3C Namespace
-
- URI = "http://www.w3.org/2005/Atom"
-
- ##
- # The XHTML URI W3C Namespace
-
- XHTML_URI = "http://www.w3.org/1999/xhtml"
-
- module CommonModel
- NSPOOL = {}
- ELEMENTS = []
-
- def self.append_features(klass)
- super
- klass.install_must_call_validator("atom", URI)
- [
- ["lang", :xml],
- ["base", :xml],
- ].each do |name, uri, required|
- klass.install_get_attribute(name, uri, required, [nil, :inherit])
- end
- klass.class_eval do
- class << self
- def required_uri
- URI
- end
-
- def need_parent?
- true
- end
- end
- end
- end
- end
-
- module ContentModel
- module ClassMethods
- def content_type
- @content_type ||= nil
- end
- end
-
- class << self
- def append_features(klass)
- super
- klass.extend(ClassMethods)
- klass.content_setup(klass.content_type, klass.tag_name)
- end
- end
-
- def maker_target(target)
- target
- end
-
- private
- def setup_maker_element_writer
- "#{self.class.name.split(/::/).last.downcase}="
- end
-
- def setup_maker_element(target)
- target.__send__(setup_maker_element_writer, content)
- super
- end
- end
-
- module URIContentModel
- class << self
- def append_features(klass)
- super
- klass.class_eval do
- @content_type = [nil, :uri]
- include(ContentModel)
- end
- end
- end
- end
-
- # The TextConstruct module is used to define a Text construct Atom element,
- # which is used to store small quantities of human-readable text
- #
- # The TextConstruct has a type attribute, e.g. text, html, xhtml
- module TextConstruct
- def self.append_features(klass)
- super
- klass.class_eval do
- [
- ["type", ""],
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required, :text_type)
- end
-
- content_setup
- add_need_initialize_variable("xhtml")
-
- class << self
- def xml_getter
- "xhtml"
- end
-
- def xml_setter
- "xhtml="
- end
- end
- end
- end
-
- attr_writer :xhtml
-
- def xhtml
- return @xhtml if @xhtml.nil?
- if @xhtml.is_a?(XML::Element) and
- [@xhtml.name, @xhtml.uri] == ["div", XHTML_URI]
- return @xhtml
- end
-
- children = @xhtml
- children = [children] unless children.is_a?(Array)
- XML::Element.new("div", nil, XHTML_URI,
- {"xmlns" => XHTML_URI}, children)
- end
-
- # Returns true if type is "xhtml"
- def have_xml_content?
- @type == "xhtml"
- end
-
- def atom_validate(ignore_unknown_element, tags, uri)
- if have_xml_content?
- if @xhtml.nil?
- raise MissingTagError.new("div", tag_name)
- end
- unless [@xhtml.name, @xhtml.uri] == ["div", XHTML_URI]
- raise NotExpectedTagError.new(@xhtml.name, @xhtml.uri, tag_name)
- end
- end
- end
-
- private
- def maker_target(target)
- target.__send__(self.class.name.split(/::/).last.downcase) {|x| x}
- end
-
- def setup_maker_attributes(target)
- target.type = type
- target.content = content
- target.xml_content = @xhtml
- end
- end
-
- # The PersonConstruct module is used to define a Person Atom element that can be
- # used to describe a person, corporation, or similar entity
- #
- # The PersonConstruct has a Name, Uri, and Email child elements
- module PersonConstruct
-
- # Adds attributes for name, uri, and email to the +klass+
- def self.append_features(klass)
- super
- klass.class_eval do
- [
- ["name", nil],
- ["uri", "?"],
- ["email", "?"],
- ].each do |tag, occurs|
- install_have_attribute_element(tag, URI, occurs, nil, :content)
- end
- end
- end
-
- def maker_target(target)
- target.__send__("new_#{self.class.name.split(/::/).last.downcase}")
- end
-
- # The name of the person or entity
- class Name < RSS::Element
- include CommonModel
- include ContentModel
- end
-
- # The URI of the person or entity
- class Uri < RSS::Element
- include CommonModel
- include URIContentModel
- end
-
- # The email of the person or entity
- class Email < RSS::Element
- include CommonModel
- include ContentModel
- end
- end
-
- # Element used to describe an Atom date and time in the ISO 8601 format
- #
- # Examples:
- # * 2013-03-04T15:30:02Z
- # * 2013-03-04T10:30:02-05:00
- module DateConstruct
- def self.append_features(klass)
- super
- klass.class_eval do
- @content_type = :w3cdtf
- include(ContentModel)
- end
- end
-
- # Raises NotAvailableValueError if element content is nil
- def atom_validate(ignore_unknown_element, tags, uri)
- raise NotAvailableValueError.new(tag_name, "") if content.nil?
- end
- end
-
- module DuplicateLinkChecker
- # Checks if there are duplicate links with the same type and hreflang attributes
- # that have an alternate (or empty) rel attribute
- #
- # Raises a TooMuchTagError if there are duplicates found
- def validate_duplicate_links(links)
- link_infos = {}
- links.each do |link|
- rel = link.rel || "alternate"
- next unless rel == "alternate"
- key = [link.hreflang, link.type]
- if link_infos.has_key?(key)
- raise TooMuchTagError.new("link", tag_name)
- end
- link_infos[key] = true
- end
- end
- end
-
- # Atom feed element
- #
- # A Feed has several metadata attributes in addition to a number of Entry child elements
- class Feed < RSS::Element
- include RootElementMixin
- include CommonModel
- include DuplicateLinkChecker
-
- install_ns('', URI)
-
- [
- ["author", "*", :children],
- ["category", "*", :children, "categories"],
- ["contributor", "*", :children],
- ["generator", "?"],
- ["icon", "?", nil, :content],
- ["id", nil, nil, :content],
- ["link", "*", :children],
- ["logo", "?"],
- ["rights", "?"],
- ["subtitle", "?", nil, :content],
- ["title", nil, nil, :content],
- ["updated", nil, nil, :content],
- ["entry", "*", :children, "entries"],
- ].each do |tag, occurs, type, *args|
- type ||= :child
- __send__("install_have_#{type}_element",
- tag, URI, occurs, tag, *args)
- end
-
- # Creates a new Atom feed
- def initialize(version=nil, encoding=nil, standalone=nil)
- super("1.0", version, encoding, standalone)
- @feed_type = "atom"
- @feed_subtype = "feed"
- end
-
- alias_method :items, :entries
-
- # Returns true if there are any authors for the feed or any of the Entry
- # child elements have an author
- def have_author?
- authors.any? {|author| !author.to_s.empty?} or
- entries.any? {|entry| entry.have_author?(false)}
- end
-
- private
- def atom_validate(ignore_unknown_element, tags, uri)
- unless have_author?
- raise MissingTagError.new("author", tag_name)
- end
- validate_duplicate_links(links)
- end
-
- def have_required_elements?
- super and have_author?
- end
-
- def maker_target(maker)
- maker.channel
- end
-
- def setup_maker_element(channel)
- prev_dc_dates = channel.dc_dates.to_a.dup
- super
- channel.about = id.content if id
- channel.dc_dates.replace(prev_dc_dates)
- end
-
- def setup_maker_elements(channel)
- super
- items = channel.maker.items
- entries.each do |entry|
- entry.setup_maker(items)
- end
- end
-
- class Author < RSS::Element
- include CommonModel
- include PersonConstruct
- end
-
- class Category < RSS::Element
- include CommonModel
-
- [
- ["term", "", true],
- ["scheme", "", false, [nil, :uri]],
- ["label", ""],
- ].each do |name, uri, required, type|
- install_get_attribute(name, uri, required, type)
- end
-
- private
- def maker_target(target)
- target.new_category
- end
- end
-
- class Contributor < RSS::Element
- include CommonModel
- include PersonConstruct
- end
-
- class Generator < RSS::Element
- include CommonModel
- include ContentModel
-
- [
- ["uri", "", false, [nil, :uri]],
- ["version", ""],
- ].each do |name, uri, required, type|
- install_get_attribute(name, uri, required, type)
- end
-
- private
- def setup_maker_attributes(target)
- target.generator do |generator|
- generator.uri = uri if uri
- generator.version = version if version
- end
- end
- end
-
- # Atom Icon element
- #
- # Image that provides a visual identification for the Feed. Image should have an aspect
- # ratio of 1:1
- class Icon < RSS::Element
- include CommonModel
- include URIContentModel
- end
-
- # Atom ID element
- #
- # Universally Unique Identifier (UUID) for the Feed
- class Id < RSS::Element
- include CommonModel
- include URIContentModel
- end
-
- # Defines an Atom Link element
- #
- # A Link has the following attributes:
- # * href
- # * rel
- # * type
- # * hreflang
- # * title
- # * length
- class Link < RSS::Element
- include CommonModel
-
- [
- ["href", "", true, [nil, :uri]],
- ["rel", ""],
- ["type", ""],
- ["hreflang", ""],
- ["title", ""],
- ["length", ""],
- ].each do |name, uri, required, type|
- install_get_attribute(name, uri, required, type)
- end
-
- private
- def maker_target(target)
- target.new_link
- end
- end
-
- # Atom Logo element
- #
- # Image that provides a visual identification for the Feed. Image should have an aspect
- # ratio of 2:1 (horizontal:vertical)
- class Logo < RSS::Element
- include CommonModel
- include URIContentModel
-
- def maker_target(target)
- target.maker.image
- end
-
- private
- def setup_maker_element_writer
- "url="
- end
- end
-
- # Atom Rights element
- #
- # TextConstruct that contains copyright information regarding the content in an Entry or Feed
- class Rights < RSS::Element
- include CommonModel
- include TextConstruct
- end
-
- # Atom Subtitle element
- #
- # TextConstruct that conveys a description or subtitle for a Feed
- class Subtitle < RSS::Element
- include CommonModel
- include TextConstruct
- end
-
- # Atom Title element
- #
- # TextConstruct that conveys a description or title for a feed or Entry
- class Title < RSS::Element
- include CommonModel
- include TextConstruct
- end
-
- # Atom Updated element
- #
- # DateConstruct indicating the most recent time when an Entry or Feed was modified
- # in a way the publisher considers significant
- class Updated < RSS::Element
- include CommonModel
- include DateConstruct
- end
-
- # Defines a child Atom Entry element for an Atom Feed
- class Entry < RSS::Element
- include CommonModel
- include DuplicateLinkChecker
-
- [
- ["author", "*", :children],
- ["category", "*", :children, "categories"],
- ["content", "?", :child],
- ["contributor", "*", :children],
- ["id", nil, nil, :content],
- ["link", "*", :children],
- ["published", "?", :child, :content],
- ["rights", "?", :child],
- ["source", "?"],
- ["summary", "?", :child],
- ["title", nil],
- ["updated", nil, :child, :content],
- ].each do |tag, occurs, type, *args|
- type ||= :attribute
- __send__("install_have_#{type}_element",
- tag, URI, occurs, tag, *args)
- end
-
- # Returns whether any of the following are true
- # * There are any authors in the feed
- # * If the parent element has an author and the +check_parent+ parameter was given.
- # * There is a source element that has an author
- def have_author?(check_parent=true)
- authors.any? {|author| !author.to_s.empty?} or
- (check_parent and @parent and @parent.have_author?) or
- (source and source.have_author?)
- end
-
- private
- def atom_validate(ignore_unknown_element, tags, uri)
- unless have_author?
- raise MissingTagError.new("author", tag_name)
- end
- validate_duplicate_links(links)
- end
-
- def have_required_elements?
- super and have_author?
- end
-
- def maker_target(items)
- if items.respond_to?("items")
- # For backward compatibility
- items = items.items
- end
- items.new_item
- end
-
- Author = Feed::Author
- Category = Feed::Category
-
- class Content < RSS::Element
- include CommonModel
-
- class << self
- def xml_setter
- "xml="
- end
-
- def xml_getter
- "xml"
- end
- end
-
- [
- ["type", ""],
- ["src", "", false, [nil, :uri]],
- ].each do |name, uri, required, type|
- install_get_attribute(name, uri, required, type)
- end
-
- content_setup
- add_need_initialize_variable("xml")
-
- attr_writer :xml
- def have_xml_content?
- inline_xhtml? or inline_other_xml?
- end
-
- def xml
- return @xml unless inline_xhtml?
- return @xml if @xml.nil?
- if @xml.is_a?(XML::Element) and
- [@xml.name, @xml.uri] == ["div", XHTML_URI]
- return @xml
- end
-
- children = @xml
- children = [children] unless children.is_a?(Array)
- XML::Element.new("div", nil, XHTML_URI,
- {"xmlns" => XHTML_URI}, children)
- end
-
- def xhtml
- if inline_xhtml?
- xml
- else
- nil
- end
- end
-
- def atom_validate(ignore_unknown_element, tags, uri)
- if out_of_line?
- raise MissingAttributeError.new(tag_name, "type") if @type.nil?
- unless (content.nil? or content.empty?)
- raise NotAvailableValueError.new(tag_name, content)
- end
- elsif inline_xhtml?
- if @xml.nil?
- raise MissingTagError.new("div", tag_name)
- end
- unless @xml.name == "div" and @xml.uri == XHTML_URI
- raise NotExpectedTagError.new(@xml.name, @xml.uri, tag_name)
- end
- end
- end
-
- def inline_text?
- !out_of_line? and [nil, "text", "html"].include?(@type)
- end
-
- def inline_html?
- return false if out_of_line?
- @type == "html" or mime_split == ["text", "html"]
- end
-
- def inline_xhtml?
- !out_of_line? and @type == "xhtml"
- end
-
- def inline_other?
- return false if out_of_line?
- media_type, subtype = mime_split
- return false if media_type.nil? or subtype.nil?
- true
- end
-
- def inline_other_text?
- return false unless inline_other?
- return false if inline_other_xml?
-
- media_type, = mime_split
- return true if "text" == media_type.downcase
- false
- end
-
- def inline_other_xml?
- return false unless inline_other?
-
- media_type, subtype = mime_split
- normalized_mime_type = "#{media_type}/#{subtype}".downcase
- if /(?:\+xml|^xml)$/ =~ subtype or
- %w(text/xml-external-parsed-entity
- application/xml-external-parsed-entity
- application/xml-dtd).find {|x| x == normalized_mime_type}
- return true
- end
- false
- end
-
- def inline_other_base64?
- inline_other? and !inline_other_text? and !inline_other_xml?
- end
-
- def out_of_line?
- not @src.nil?
- end
-
- def mime_split
- media_type = subtype = nil
- if /\A\s*([a-z]+)\/([a-z\+]+)\s*(?:;.*)?\z/i =~ @type.to_s
- media_type = $1.downcase
- subtype = $2.downcase
- end
- [media_type, subtype]
- end
-
- def need_base64_encode?
- inline_other_base64?
- end
-
- private
- def empty_content?
- out_of_line? or super
- end
- end
-
- Contributor = Feed::Contributor
- Id = Feed::Id
- Link = Feed::Link
-
- class Published < RSS::Element
- include CommonModel
- include DateConstruct
- end
-
- Rights = Feed::Rights
-
- class Source < RSS::Element
- include CommonModel
-
- [
- ["author", "*", :children],
- ["category", "*", :children, "categories"],
- ["contributor", "*", :children],
- ["generator", "?"],
- ["icon", "?"],
- ["id", "?", nil, :content],
- ["link", "*", :children],
- ["logo", "?"],
- ["rights", "?"],
- ["subtitle", "?"],
- ["title", "?"],
- ["updated", "?", nil, :content],
- ].each do |tag, occurs, type, *args|
- type ||= :attribute
- __send__("install_have_#{type}_element",
- tag, URI, occurs, tag, *args)
- end
-
- def have_author?
- !author.to_s.empty?
- end
-
- Author = Feed::Author
- Category = Feed::Category
- Contributor = Feed::Contributor
- Generator = Feed::Generator
- Icon = Feed::Icon
- Id = Feed::Id
- Link = Feed::Link
- Logo = Feed::Logo
- Rights = Feed::Rights
- Subtitle = Feed::Subtitle
- Title = Feed::Title
- Updated = Feed::Updated
- end
-
- class Summary < RSS::Element
- include CommonModel
- include TextConstruct
- end
-
- Title = Feed::Title
- Updated = Feed::Updated
- end
- end
-
- # Defines a top-level Atom Entry element
- #
- class Entry < RSS::Element
- include RootElementMixin
- include CommonModel
- include DuplicateLinkChecker
-
- [
- ["author", "*", :children],
- ["category", "*", :children, "categories"],
- ["content", "?"],
- ["contributor", "*", :children],
- ["id", nil, nil, :content],
- ["link", "*", :children],
- ["published", "?", :child, :content],
- ["rights", "?"],
- ["source", "?"],
- ["summary", "?"],
- ["title", nil],
- ["updated", nil, nil, :content],
- ].each do |tag, occurs, type, *args|
- type ||= :attribute
- __send__("install_have_#{type}_element",
- tag, URI, occurs, tag, *args)
- end
-
- # Creates a new Atom Entry element
- def initialize(version=nil, encoding=nil, standalone=nil)
- super("1.0", version, encoding, standalone)
- @feed_type = "atom"
- @feed_subtype = "entry"
- end
-
- # Returns the Entry in an array
- def items
- [self]
- end
-
- # sets up the +maker+ for constructing Entry elements
- def setup_maker(maker)
- maker = maker.maker if maker.respond_to?("maker")
- super(maker)
- end
-
- # Returns where there are any authors present or there is a source with an author
- def have_author?
- authors.any? {|author| !author.to_s.empty?} or
- (source and source.have_author?)
- end
-
- private
- def atom_validate(ignore_unknown_element, tags, uri)
- unless have_author?
- raise MissingTagError.new("author", tag_name)
- end
- validate_duplicate_links(links)
- end
-
- def have_required_elements?
- super and have_author?
- end
-
- def maker_target(maker)
- maker.items.new_item
- end
-
- Author = Feed::Entry::Author
- Category = Feed::Entry::Category
- Content = Feed::Entry::Content
- Contributor = Feed::Entry::Contributor
- Id = Feed::Entry::Id
- Link = Feed::Entry::Link
- Published = Feed::Entry::Published
- Rights = Feed::Entry::Rights
- Source = Feed::Entry::Source
- Summary = Feed::Entry::Summary
- Title = Feed::Entry::Title
- Updated = Feed::Entry::Updated
- end
- end
-
- Atom::CommonModel::ELEMENTS.each do |name|
- BaseListener.install_get_text_element(Atom::URI, name, "#{name}=")
- end
-
- module ListenerMixin
- private
- def initial_start_feed(tag_name, prefix, attrs, ns)
- check_ns(tag_name, prefix, ns, Atom::URI, false)
-
- @rss = Atom::Feed.new(@version, @encoding, @standalone)
- @rss.do_validate = @do_validate
- @rss.xml_stylesheets = @xml_stylesheets
- @rss.lang = attrs["xml:lang"]
- @rss.base = attrs["xml:base"]
- @last_element = @rss
- pr = Proc.new do |text, tags|
- @rss.validate_for_stream(tags) if @do_validate
- end
- @proc_stack.push(pr)
- end
-
- def initial_start_entry(tag_name, prefix, attrs, ns)
- check_ns(tag_name, prefix, ns, Atom::URI, false)
-
- @rss = Atom::Entry.new(@version, @encoding, @standalone)
- @rss.do_validate = @do_validate
- @rss.xml_stylesheets = @xml_stylesheets
- @rss.lang = attrs["xml:lang"]
- @rss.base = attrs["xml:base"]
- @last_element = @rss
- pr = Proc.new do |text, tags|
- @rss.validate_for_stream(tags) if @do_validate
- end
- @proc_stack.push(pr)
- end
- end
-end
diff --git a/ruby_2_2/lib/rss/content.rb b/ruby_2_2/lib/rss/content.rb
deleted file mode 100644
index 5a2120c067..0000000000
--- a/ruby_2_2/lib/rss/content.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-require "rss/rss"
-
-module RSS
- # The prefix for the Content XML namespace.
- CONTENT_PREFIX = 'content'
- # The URI of the Content specification.
- CONTENT_URI = "http://purl.org/rss/1.0/modules/content/"
-
- module ContentModel
- extend BaseModel
-
- ELEMENTS = ["#{CONTENT_PREFIX}_encoded"]
-
- def self.append_features(klass)
- super
-
- klass.install_must_call_validator(CONTENT_PREFIX, CONTENT_URI)
- ELEMENTS.each do |full_name|
- name = full_name[(CONTENT_PREFIX.size + 1)..-1]
- klass.install_text_element(name, CONTENT_URI, "?", full_name)
- end
- end
- end
-
- prefix_size = CONTENT_PREFIX.size + 1
- ContentModel::ELEMENTS.each do |full_name|
- name = full_name[prefix_size..-1]
- BaseListener.install_get_text_element(CONTENT_URI, name, full_name)
- end
-end
-
-require 'rss/content/1.0'
-require 'rss/content/2.0'
diff --git a/ruby_2_2/lib/rss/content/1.0.rb b/ruby_2_2/lib/rss/content/1.0.rb
deleted file mode 100644
index e5dc857930..0000000000
--- a/ruby_2_2/lib/rss/content/1.0.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require 'rss/1.0'
-
-module RSS
- RDF.install_ns(CONTENT_PREFIX, CONTENT_URI)
-
- class RDF
- class Item; include ContentModel; end
- end
-end
diff --git a/ruby_2_2/lib/rss/content/2.0.rb b/ruby_2_2/lib/rss/content/2.0.rb
deleted file mode 100644
index 8491a99937..0000000000
--- a/ruby_2_2/lib/rss/content/2.0.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require "rss/2.0"
-
-module RSS
- Rss.install_ns(CONTENT_PREFIX, CONTENT_URI)
-
- class Rss
- class Channel
- class Item; include ContentModel; end
- end
- end
-end
diff --git a/ruby_2_2/lib/rss/converter.rb b/ruby_2_2/lib/rss/converter.rb
deleted file mode 100644
index 3e79eba4fb..0000000000
--- a/ruby_2_2/lib/rss/converter.rb
+++ /dev/null
@@ -1,170 +0,0 @@
-require "rss/utils"
-
-module RSS
-
- class Converter
-
- include Utils
-
- def initialize(to_enc, from_enc=nil)
- if "".respond_to?(:encode)
- @to_encoding = to_enc
- return
- end
- normalized_to_enc = to_enc.downcase.gsub(/-/, '_')
- from_enc ||= 'utf-8'
- normalized_from_enc = from_enc.downcase.gsub(/-/, '_')
- if normalized_to_enc == normalized_from_enc
- def_same_enc()
- else
- def_diff_enc = "def_to_#{normalized_to_enc}_from_#{normalized_from_enc}"
- if respond_to?(def_diff_enc)
- __send__(def_diff_enc)
- else
- def_else_enc(to_enc, from_enc)
- end
- end
- end
-
- def convert(value)
- if value.is_a?(String) and value.respond_to?(:encode)
- value.encode(@to_encoding)
- else
- value
- end
- end
-
- def def_convert(depth=0)
- instance_eval(<<-EOC, *get_file_and_line_from_caller(depth))
- def convert(value)
- if value.kind_of?(String)
- #{yield('value')}
- else
- value
- end
- end
- EOC
- end
-
- def def_iconv_convert(to_enc, from_enc, depth=0)
- begin
- require "iconv"
- @iconv = Iconv.new(to_enc, from_enc)
- def_convert(depth+1) do |value|
- <<-EOC
- begin
- @iconv.iconv(#{value})
- rescue Iconv::Failure
- raise ConversionError.new(#{value}, "#{to_enc}", "#{from_enc}")
- end
- EOC
- end
- rescue LoadError, ArgumentError, SystemCallError
- raise UnknownConversionMethodError.new(to_enc, from_enc)
- end
- end
-
- def def_else_enc(to_enc, from_enc)
- def_iconv_convert(to_enc, from_enc, 0)
- end
-
- def def_same_enc()
- def_convert do |value|
- value
- end
- end
-
- def def_uconv_convert_if_can(meth, to_enc, from_enc, nkf_arg)
- begin
- require "uconv"
- def_convert(1) do |value|
- <<-EOC
- begin
- Uconv.#{meth}(#{value})
- rescue Uconv::Error
- raise ConversionError.new(#{value}, "#{to_enc}", "#{from_enc}")
- end
- EOC
- end
- rescue LoadError
- require 'nkf'
- if NKF.const_defined?(:UTF8)
- def_convert(1) do |value|
- "NKF.nkf(#{nkf_arg.dump}, #{value})"
- end
- else
- def_iconv_convert(to_enc, from_enc, 1)
- end
- end
- end
-
- def def_to_euc_jp_from_utf_8
- def_uconv_convert_if_can('u8toeuc', 'EUC-JP', 'UTF-8', '-We')
- end
-
- def def_to_utf_8_from_euc_jp
- def_uconv_convert_if_can('euctou8', 'UTF-8', 'EUC-JP', '-Ew')
- end
-
- def def_to_shift_jis_from_utf_8
- def_uconv_convert_if_can('u8tosjis', 'Shift_JIS', 'UTF-8', '-Ws')
- end
-
- def def_to_utf_8_from_shift_jis
- def_uconv_convert_if_can('sjistou8', 'UTF-8', 'Shift_JIS', '-Sw')
- end
-
- def def_to_euc_jp_from_shift_jis
- require "nkf"
- def_convert do |value|
- "NKF.nkf('-Se', #{value})"
- end
- end
-
- def def_to_shift_jis_from_euc_jp
- require "nkf"
- def_convert do |value|
- "NKF.nkf('-Es', #{value})"
- end
- end
-
- def def_to_euc_jp_from_iso_2022_jp
- require "nkf"
- def_convert do |value|
- "NKF.nkf('-Je', #{value})"
- end
- end
-
- def def_to_iso_2022_jp_from_euc_jp
- require "nkf"
- def_convert do |value|
- "NKF.nkf('-Ej', #{value})"
- end
- end
-
- def def_to_utf_8_from_iso_8859_1
- def_convert do |value|
- "#{value}.unpack('C*').pack('U*')"
- end
- end
-
- def def_to_iso_8859_1_from_utf_8
- def_convert do |value|
- <<-EOC
- array_utf8 = #{value}.unpack('U*')
- array_enc = []
- array_utf8.each do |num|
- if num <= 0xFF
- array_enc << num
- else
- array_enc.concat "&\#\#{num};".unpack('C*')
- end
- end
- array_enc.pack('C*')
- EOC
- end
- end
-
- end
-
-end
diff --git a/ruby_2_2/lib/rss/dublincore.rb b/ruby_2_2/lib/rss/dublincore.rb
deleted file mode 100644
index 58424141cd..0000000000
--- a/ruby_2_2/lib/rss/dublincore.rb
+++ /dev/null
@@ -1,163 +0,0 @@
-require "rss/rss"
-
-module RSS
- # The prefix for the Dublin Core XML namespace.
- DC_PREFIX = 'dc'
- # The URI of the Dublin Core specification.
- DC_URI = "http://purl.org/dc/elements/1.1/"
-
- module BaseDublinCoreModel
- def append_features(klass)
- super
-
- return if klass.instance_of?(Module)
- DublinCoreModel::ELEMENT_NAME_INFOS.each do |name, plural_name|
- plural = plural_name || "#{name}s"
- full_name = "#{DC_PREFIX}_#{name}"
- full_plural_name = "#{DC_PREFIX}_#{plural}"
- klass_name = "DublinCore#{Utils.to_class_name(name)}"
- klass.install_must_call_validator(DC_PREFIX, DC_URI)
- klass.install_have_children_element(name, DC_URI, "*",
- full_name, full_plural_name)
- klass.module_eval(<<-EOC, *get_file_and_line_from_caller(0))
- remove_method :#{full_name}
- remove_method :#{full_name}=
- remove_method :set_#{full_name}
-
- def #{full_name}
- @#{full_name}.first and @#{full_name}.first.value
- end
-
- def #{full_name}=(new_value)
- @#{full_name}[0] = Utils.new_with_value_if_need(#{klass_name}, new_value)
- end
- alias set_#{full_name} #{full_name}=
- EOC
- end
- klass.module_eval(<<-EOC, *get_file_and_line_from_caller(0))
- if method_defined?(:date)
- alias date_without_#{DC_PREFIX}_date= date=
-
- def date=(value)
- self.date_without_#{DC_PREFIX}_date = value
- self.#{DC_PREFIX}_date = value
- end
- else
- alias date #{DC_PREFIX}_date
- alias date= #{DC_PREFIX}_date=
- end
-
- # For backward compatibility
- alias #{DC_PREFIX}_rightses #{DC_PREFIX}_rights_list
- EOC
- end
- end
-
- module DublinCoreModel
-
- extend BaseModel
- extend BaseDublinCoreModel
-
- TEXT_ELEMENTS = {
- "title" => nil,
- "description" => nil,
- "creator" => nil,
- "subject" => nil,
- "publisher" => nil,
- "contributor" => nil,
- "type" => nil,
- "format" => nil,
- "identifier" => nil,
- "source" => nil,
- "language" => nil,
- "relation" => nil,
- "coverage" => nil,
- "rights" => "rights_list"
- }
-
- DATE_ELEMENTS = {
- "date" => "w3cdtf",
- }
-
- ELEMENT_NAME_INFOS = DublinCoreModel::TEXT_ELEMENTS.to_a
- DublinCoreModel::DATE_ELEMENTS.each do |name, |
- ELEMENT_NAME_INFOS << [name, nil]
- end
-
- ELEMENTS = TEXT_ELEMENTS.keys + DATE_ELEMENTS.keys
-
- ELEMENTS.each do |name, plural_name|
- module_eval(<<-EOC, *get_file_and_line_from_caller(0))
- class DublinCore#{Utils.to_class_name(name)} < Element
- include RSS10
-
- content_setup
-
- class << self
- def required_prefix
- DC_PREFIX
- end
-
- def required_uri
- DC_URI
- end
- end
-
- @tag_name = #{name.dump}
-
- alias_method(:value, :content)
- alias_method(:value=, :content=)
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.content = args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(DC_PREFIX)
- end
-
- def maker_target(target)
- target.new_#{name}
- end
-
- def setup_maker_attributes(#{name})
- #{name}.content = content
- end
- end
- EOC
- end
-
- DATE_ELEMENTS.each do |name, type|
- tag_name = "#{DC_PREFIX}:#{name}"
- module_eval(<<-EOC, *get_file_and_line_from_caller(0))
- class DublinCore#{Utils.to_class_name(name)} < Element
- remove_method(:content=)
- remove_method(:value=)
-
- date_writer("content", #{type.dump}, #{tag_name.dump})
-
- alias_method(:value=, :content=)
- end
- EOC
- end
- end
-
- # For backward compatibility
- DublincoreModel = DublinCoreModel
-
- DublinCoreModel::ELEMENTS.each do |name|
- class_name = Utils.to_class_name(name)
- BaseListener.install_class_name(DC_URI, name, "DublinCore#{class_name}")
- end
-
- DublinCoreModel::ELEMENTS.collect! {|name| "#{DC_PREFIX}_#{name}"}
-end
-
-require 'rss/dublincore/1.0'
-require 'rss/dublincore/2.0'
-require 'rss/dublincore/atom'
diff --git a/ruby_2_2/lib/rss/dublincore/1.0.rb b/ruby_2_2/lib/rss/dublincore/1.0.rb
deleted file mode 100644
index efe2f5dad4..0000000000
--- a/ruby_2_2/lib/rss/dublincore/1.0.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require "rss/1.0"
-
-module RSS
- RDF.install_ns(DC_PREFIX, DC_URI)
-
- class RDF
- class Channel; include DublinCoreModel; end
- class Image; include DublinCoreModel; end
- class Item; include DublinCoreModel; end
- class Textinput; include DublinCoreModel; end
- end
-end
diff --git a/ruby_2_2/lib/rss/dublincore/2.0.rb b/ruby_2_2/lib/rss/dublincore/2.0.rb
deleted file mode 100644
index a79c1e84a4..0000000000
--- a/ruby_2_2/lib/rss/dublincore/2.0.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require "rss/2.0"
-
-module RSS
- Rss.install_ns(DC_PREFIX, DC_URI)
-
- class Rss
- class Channel
- include DublinCoreModel
- class Item; include DublinCoreModel; end
- end
- end
-end
diff --git a/ruby_2_2/lib/rss/dublincore/atom.rb b/ruby_2_2/lib/rss/dublincore/atom.rb
deleted file mode 100644
index 8db9066bb8..0000000000
--- a/ruby_2_2/lib/rss/dublincore/atom.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-require "rss/atom"
-
-module RSS
- module Atom
- Feed.install_ns(DC_PREFIX, DC_URI)
-
- class Feed
- include DublinCoreModel
- class Entry; include DublinCoreModel; end
- end
-
- class Entry
- include DublinCoreModel
- end
- end
-end
diff --git a/ruby_2_2/lib/rss/image.rb b/ruby_2_2/lib/rss/image.rb
deleted file mode 100644
index b0619141bb..0000000000
--- a/ruby_2_2/lib/rss/image.rb
+++ /dev/null
@@ -1,197 +0,0 @@
-require 'rss/1.0'
-require 'rss/dublincore'
-
-module RSS
-
- # The prefix for the Image XML namespace.
- IMAGE_PREFIX = 'image'
- # The URI for the Image specification.
- IMAGE_URI = 'http://purl.org/rss/1.0/modules/image/'
-
- RDF.install_ns(IMAGE_PREFIX, IMAGE_URI)
-
- # This constant holds strings which contain the names of
- # image elements, with the appropriate prefix.
- IMAGE_ELEMENTS = []
-
- %w(item favicon).each do |name|
- class_name = Utils.to_class_name(name)
- BaseListener.install_class_name(IMAGE_URI, name, "Image#{class_name}")
- IMAGE_ELEMENTS << "#{IMAGE_PREFIX}_#{name}"
- end
-
- module ImageModelUtils
- def validate_one_tag_name(ignore_unknown_element, name, tags)
- if !ignore_unknown_element
- invalid = tags.find {|tag| tag != name}
- raise UnknownTagError.new(invalid, IMAGE_URI) if invalid
- end
- raise TooMuchTagError.new(name, tag_name) if tags.size > 1
- end
- end
-
- module ImageItemModel
- include ImageModelUtils
- extend BaseModel
-
- def self.append_features(klass)
- super
-
- klass.install_have_child_element("item", IMAGE_URI, "?",
- "#{IMAGE_PREFIX}_item")
- klass.install_must_call_validator(IMAGE_PREFIX, IMAGE_URI)
- end
-
- class ImageItem < Element
- include RSS10
- include DublinCoreModel
-
- @tag_name = "item"
-
- class << self
- def required_prefix
- IMAGE_PREFIX
- end
-
- def required_uri
- IMAGE_URI
- end
- end
-
- install_must_call_validator(IMAGE_PREFIX, IMAGE_URI)
-
- [
- ["about", ::RSS::RDF::URI, true],
- ["resource", ::RSS::RDF::URI, false],
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required, nil, nil,
- "#{::RSS::RDF::PREFIX}:#{name}")
- end
-
- %w(width height).each do |tag|
- full_name = "#{IMAGE_PREFIX}_#{tag}"
- disp_name = "#{IMAGE_PREFIX}:#{tag}"
- install_text_element(tag, IMAGE_URI, "?",
- full_name, :integer, disp_name)
- BaseListener.install_get_text_element(IMAGE_URI, tag, full_name)
- end
-
- alias width= image_width=
- alias width image_width
- alias height= image_height=
- alias height image_height
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.about = args[0]
- self.resource = args[1]
- end
- end
-
- def full_name
- tag_name_with_prefix(IMAGE_PREFIX)
- end
-
- private
- def maker_target(target)
- target.image_item
- end
-
- def setup_maker_attributes(item)
- item.about = self.about
- item.resource = self.resource
- end
- end
- end
-
- module ImageFaviconModel
- include ImageModelUtils
- extend BaseModel
-
- def self.append_features(klass)
- super
-
- unless klass.class == Module
- klass.install_have_child_element("favicon", IMAGE_URI, "?",
- "#{IMAGE_PREFIX}_favicon")
- klass.install_must_call_validator(IMAGE_PREFIX, IMAGE_URI)
- end
- end
-
- class ImageFavicon < Element
- include RSS10
- include DublinCoreModel
-
- @tag_name = "favicon"
-
- class << self
- def required_prefix
- IMAGE_PREFIX
- end
-
- def required_uri
- IMAGE_URI
- end
- end
-
- [
- ["about", ::RSS::RDF::URI, true, ::RSS::RDF::PREFIX],
- ["size", IMAGE_URI, true, IMAGE_PREFIX],
- ].each do |name, uri, required, prefix|
- install_get_attribute(name, uri, required, nil, nil,
- "#{prefix}:#{name}")
- end
-
- AVAILABLE_SIZES = %w(small medium large)
- alias_method :set_size, :size=
- private :set_size
- def size=(new_value)
- if @do_validate and !new_value.nil?
- new_value = new_value.strip
- unless AVAILABLE_SIZES.include?(new_value)
- attr_name = "#{IMAGE_PREFIX}:size"
- raise NotAvailableValueError.new(full_name, new_value, attr_name)
- end
- end
- set_size(new_value)
- end
-
- alias image_size= size=
- alias image_size size
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.about = args[0]
- self.size = args[1]
- end
- end
-
- def full_name
- tag_name_with_prefix(IMAGE_PREFIX)
- end
-
- private
- def maker_target(target)
- target.image_favicon
- end
-
- def setup_maker_attributes(favicon)
- favicon.about = self.about
- favicon.size = self.size
- end
- end
-
- end
-
- class RDF
- class Channel; include ImageFaviconModel; end
- class Item; include ImageItemModel; end
- end
-
-end
diff --git a/ruby_2_2/lib/rss/itunes.rb b/ruby_2_2/lib/rss/itunes.rb
deleted file mode 100644
index e6de5c1ca2..0000000000
--- a/ruby_2_2/lib/rss/itunes.rb
+++ /dev/null
@@ -1,412 +0,0 @@
-require 'rss/2.0'
-
-module RSS
- # The prefix for the iTunes XML namespace.
- ITUNES_PREFIX = 'itunes'
- # The URI of the iTunes specification.
- ITUNES_URI = 'http://www.itunes.com/dtds/podcast-1.0.dtd'
-
- Rss.install_ns(ITUNES_PREFIX, ITUNES_URI)
-
- module ITunesModelUtils
- include Utils
-
- def def_class_accessor(klass, name, type, *args)
- normalized_name = name.gsub(/-/, "_")
- full_name = "#{ITUNES_PREFIX}_#{normalized_name}"
- klass_name = "ITunes#{Utils.to_class_name(normalized_name)}"
-
- case type
- when :element, :attribute
- klass::ELEMENTS << full_name
- def_element_class_accessor(klass, name, full_name, klass_name, *args)
- when :elements
- klass::ELEMENTS << full_name
- def_elements_class_accessor(klass, name, full_name, klass_name, *args)
- else
- klass.install_must_call_validator(ITUNES_PREFIX, ITUNES_URI)
- klass.install_text_element(normalized_name, ITUNES_URI, "?",
- full_name, type, name)
- end
- end
-
- def def_element_class_accessor(klass, name, full_name, klass_name,
- recommended_attribute_name=nil)
- klass.install_have_child_element(name, ITUNES_PREFIX, "?", full_name)
- end
-
- def def_elements_class_accessor(klass, name, full_name, klass_name,
- plural_name, recommended_attribute_name=nil)
- full_plural_name = "#{ITUNES_PREFIX}_#{plural_name}"
- klass.install_have_children_element(name, ITUNES_PREFIX, "*",
- full_name, full_plural_name)
- end
- end
-
- module ITunesBaseModel
- extend ITunesModelUtils
-
- ELEMENTS = []
-
- ELEMENT_INFOS = [["author"],
- ["block", :yes_other],
- ["explicit", :yes_clean_other],
- ["keywords", :csv],
- ["subtitle"],
- ["summary"]]
- end
-
- module ITunesChannelModel
- extend BaseModel
- extend ITunesModelUtils
- include ITunesBaseModel
-
- ELEMENTS = []
-
- class << self
- def append_features(klass)
- super
-
- return if klass.instance_of?(Module)
- ELEMENT_INFOS.each do |name, type, *additional_infos|
- def_class_accessor(klass, name, type, *additional_infos)
- end
- end
- end
-
- ELEMENT_INFOS = [
- ["category", :elements, "categories", "text"],
- ["image", :attribute, "href"],
- ["owner", :element],
- ["new-feed-url"],
- ] + ITunesBaseModel::ELEMENT_INFOS
-
- class ITunesCategory < Element
- include RSS09
-
- @tag_name = "category"
-
- class << self
- def required_prefix
- ITUNES_PREFIX
- end
-
- def required_uri
- ITUNES_URI
- end
- end
-
- [
- ["text", "", true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- ITunesCategory = self
- install_have_children_element("category", ITUNES_URI, "*",
- "#{ITUNES_PREFIX}_category",
- "#{ITUNES_PREFIX}_categories")
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.text = args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(ITUNES_PREFIX)
- end
-
- private
- def maker_target(categories)
- if text or !itunes_categories.empty?
- categories.new_category
- else
- nil
- end
- end
-
- def setup_maker_attributes(category)
- category.text = text if text
- end
-
- def setup_maker_elements(category)
- super(category)
- itunes_categories.each do |sub_category|
- sub_category.setup_maker(category)
- end
- end
- end
-
- class ITunesImage < Element
- include RSS09
-
- @tag_name = "image"
-
- class << self
- def required_prefix
- ITUNES_PREFIX
- end
-
- def required_uri
- ITUNES_URI
- end
- end
-
- [
- ["href", "", true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required)
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.href = args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(ITUNES_PREFIX)
- end
-
- private
- def maker_target(target)
- if href
- target.itunes_image {|image| image}
- else
- nil
- end
- end
-
- def setup_maker_attributes(image)
- image.href = href
- end
- end
-
- class ITunesOwner < Element
- include RSS09
-
- @tag_name = "owner"
-
- class << self
- def required_prefix
- ITUNES_PREFIX
- end
-
- def required_uri
- ITUNES_URI
- end
- end
-
- install_must_call_validator(ITUNES_PREFIX, ITUNES_URI)
- [
- ["name"],
- ["email"],
- ].each do |name,|
- ITunesBaseModel::ELEMENT_INFOS << name
- install_text_element(name, ITUNES_URI, nil, "#{ITUNES_PREFIX}_#{name}")
- end
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.itunes_name = args[0]
- self.itunes_email = args[1]
- end
- end
-
- def full_name
- tag_name_with_prefix(ITUNES_PREFIX)
- end
-
- private
- def maker_target(target)
- target.itunes_owner
- end
-
- def setup_maker_element(owner)
- super(owner)
- owner.itunes_name = itunes_name
- owner.itunes_email = itunes_email
- end
- end
- end
-
- module ITunesItemModel
- extend BaseModel
- extend ITunesModelUtils
- include ITunesBaseModel
-
- class << self
- def append_features(klass)
- super
-
- return if klass.instance_of?(Module)
- ELEMENT_INFOS.each do |name, type|
- def_class_accessor(klass, name, type)
- end
- end
- end
-
- ELEMENT_INFOS = ITunesBaseModel::ELEMENT_INFOS +
- [["duration", :element, "content"]]
-
- class ITunesDuration < Element
- include RSS09
-
- @tag_name = "duration"
-
- class << self
- def required_prefix
- ITUNES_PREFIX
- end
-
- def required_uri
- ITUNES_URI
- end
-
- def parse(duration, do_validate=true)
- if do_validate and /\A(?:
- \d?\d:[0-5]\d:[0-5]\d|
- [0-5]?\d:[0-5]\d
- )\z/x !~ duration
- raise ArgumentError,
- "must be one of HH:MM:SS, H:MM:SS, MM::SS, M:SS: " +
- duration.inspect
- end
-
- components = duration.split(':')
- components[3..-1] = nil if components.size > 3
-
- components.unshift("00") until components.size == 3
-
- components.collect do |component|
- component.to_i
- end
- end
-
- def construct(hour, minute, second)
- components = [minute, second]
- if components.include?(nil)
- nil
- else
- components.unshift(hour) if hour and hour > 0
- components.collect do |component|
- "%02d" % component
- end.join(":")
- end
- end
- end
-
- content_setup
- alias_method(:value, :content)
- remove_method(:content=)
-
- attr_reader :hour, :minute, :second
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- args = args[0] if args.size == 1 and args[0].is_a?(Array)
- if args.size == 1
- self.content = args[0]
- elsif args.size > 3
- raise ArgumentError,
- "must be (do_validate, params), (content), " +
- "(minute, second), ([minute, second]), " +
- "(hour, minute, second) or ([hour, minute, second]): " +
- args.inspect
- else
- @second, @minute, @hour = args.reverse
- update_content
- end
- end
- end
-
- def content=(value)
- if value.nil?
- @content = nil
- elsif value.is_a?(self.class)
- self.content = value.content
- else
- begin
- @hour, @minute, @second = self.class.parse(value, @do_validate)
- rescue ArgumentError
- raise NotAvailableValueError.new(tag_name, value)
- end
- @content = value
- end
- end
- alias_method(:value=, :content=)
-
- def hour=(hour)
- @hour = @do_validate ? Integer(hour) : hour.to_i
- update_content
- hour
- end
-
- def minute=(minute)
- @minute = @do_validate ? Integer(minute) : minute.to_i
- update_content
- minute
- end
-
- def second=(second)
- @second = @do_validate ? Integer(second) : second.to_i
- update_content
- second
- end
-
- def full_name
- tag_name_with_prefix(ITUNES_PREFIX)
- end
-
- private
- def update_content
- @content = self.class.construct(hour, minute, second)
- end
-
- def maker_target(target)
- if @content
- target.itunes_duration {|duration| duration}
- else
- nil
- end
- end
-
- def setup_maker_element(duration)
- super(duration)
- duration.content = @content
- end
- end
- end
-
- class Rss
- class Channel
- include ITunesChannelModel
- class Item; include ITunesItemModel; end
- end
- end
-
- element_infos =
- ITunesChannelModel::ELEMENT_INFOS + ITunesItemModel::ELEMENT_INFOS
- element_infos.each do |name, type|
- case type
- when :element, :elements, :attribute
- class_name = Utils.to_class_name(name)
- BaseListener.install_class_name(ITUNES_URI, name, "ITunes#{class_name}")
- else
- accessor_base = "#{ITUNES_PREFIX}_#{name.gsub(/-/, '_')}"
- BaseListener.install_get_text_element(ITUNES_URI, name, accessor_base)
- end
- end
-end
diff --git a/ruby_2_2/lib/rss/maker.rb b/ruby_2_2/lib/rss/maker.rb
deleted file mode 100644
index 824b2b2dcd..0000000000
--- a/ruby_2_2/lib/rss/maker.rb
+++ /dev/null
@@ -1,78 +0,0 @@
-require "rss/rss"
-
-module RSS
- ##
- #
- # Provides a set of builders for various RSS objects
- #
- # * Feeds
- # * RSS 0.91
- # * RSS 1.0
- # * RSS 2.0
- # * Atom 1.0
- #
- # * Elements
- # * Atom::Entry
-
- module Maker
-
- # Collection of supported makers
- MAKERS = {}
-
- class << self
- # Builder for an RSS object
- # Creates an object of the type passed in +args+
- #
- # Executes the +block+ to populate elements of the created RSS object
- def make(version, &block)
- self[version].make(&block)
- end
-
- # Returns the maker for the +version+
- def [](version)
- maker_info = maker(version)
- raise UnsupportedMakerVersionError.new(version) if maker_info.nil?
- maker_info[:maker]
- end
-
- # Adds a maker to the set of supported makers
- def add_maker(version, normalized_version, maker)
- MAKERS[version] = {:maker => maker, :version => normalized_version}
- end
-
- # Returns collection of supported maker versions
- def versions
- MAKERS.keys.uniq.sort
- end
-
- # Returns collection of supported makers
- def makers
- MAKERS.values.collect { |info| info[:maker] }.uniq
- end
-
- # Returns true if the version is supported
- def supported?(version)
- versions.include?(version)
- end
-
- private
- # Can I remove this method?
- def maker(version)
- MAKERS[version]
- end
- end
- end
-end
-
-require "rss/maker/1.0"
-require "rss/maker/2.0"
-require "rss/maker/feed"
-require "rss/maker/entry"
-require "rss/maker/content"
-require "rss/maker/dublincore"
-require "rss/maker/slash"
-require "rss/maker/syndication"
-require "rss/maker/taxonomy"
-require "rss/maker/trackback"
-require "rss/maker/image"
-require "rss/maker/itunes"
diff --git a/ruby_2_2/lib/rss/maker/0.9.rb b/ruby_2_2/lib/rss/maker/0.9.rb
deleted file mode 100644
index c398343ec4..0000000000
--- a/ruby_2_2/lib/rss/maker/0.9.rb
+++ /dev/null
@@ -1,508 +0,0 @@
-require "rss/0.9"
-
-require "rss/maker/base"
-
-module RSS
- module Maker
-
- class RSS09 < RSSBase
-
- def initialize(feed_version)
- super
- @feed_type = "rss"
- end
-
- private
- def make_feed
- Rss.new(@feed_version, @version, @encoding, @standalone)
- end
-
- def setup_elements(rss)
- setup_channel(rss)
- end
-
- class Channel < ChannelBase
- def to_feed(rss)
- channel = Rss::Channel.new
- setup_values(channel)
- _not_set_required_variables = not_set_required_variables
- if _not_set_required_variables.empty?
- rss.channel = channel
- set_parent(channel, rss)
- setup_items(rss)
- setup_image(rss)
- setup_textinput(rss)
- setup_other_elements(rss, channel)
- rss
- else
- raise NotSetError.new("maker.channel", _not_set_required_variables)
- end
- end
-
- private
- def setup_items(rss)
- @maker.items.to_feed(rss)
- end
-
- def setup_image(rss)
- @maker.image.to_feed(rss)
- end
-
- def setup_textinput(rss)
- @maker.textinput.to_feed(rss)
- end
-
- def variables
- super + ["pubDate"]
- end
-
- def required_variable_names
- %w(link language)
- end
-
- def not_set_required_variables
- vars = super
- vars << "description" unless description {|d| d.have_required_values?}
- vars << "title" unless title {|t| t.have_required_values?}
- vars
- end
-
- class SkipDays < SkipDaysBase
- def to_feed(rss, channel)
- unless @days.empty?
- skipDays = Rss::Channel::SkipDays.new
- channel.skipDays = skipDays
- set_parent(skipDays, channel)
- @days.each do |day|
- day.to_feed(rss, skipDays.days)
- end
- end
- end
-
- class Day < DayBase
- def to_feed(rss, days)
- day = Rss::Channel::SkipDays::Day.new
- set = setup_values(day)
- if set
- days << day
- set_parent(day, days)
- setup_other_elements(rss, day)
- end
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
- end
-
- class SkipHours < SkipHoursBase
- def to_feed(rss, channel)
- unless @hours.empty?
- skipHours = Rss::Channel::SkipHours.new
- channel.skipHours = skipHours
- set_parent(skipHours, channel)
- @hours.each do |hour|
- hour.to_feed(rss, skipHours.hours)
- end
- end
- end
-
- class Hour < HourBase
- def to_feed(rss, hours)
- hour = Rss::Channel::SkipHours::Hour.new
- set = setup_values(hour)
- if set
- hours << hour
- set_parent(hour, hours)
- setup_other_elements(rss, hour)
- end
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
- end
-
- class Cloud < CloudBase
- def to_feed(*args)
- end
- end
-
- class Categories < CategoriesBase
- def to_feed(*args)
- end
-
- class Category < CategoryBase
- end
- end
-
- class Links < LinksBase
- def to_feed(rss, channel)
- return if @links.empty?
- @links.first.to_feed(rss, channel)
- end
-
- class Link < LinkBase
- def to_feed(rss, channel)
- if have_required_values?
- channel.link = href
- else
- raise NotSetError.new("maker.channel.link",
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(href)
- end
- end
- end
-
- class Authors < AuthorsBase
- def to_feed(rss, channel)
- end
-
- class Author < AuthorBase
- def to_feed(rss, channel)
- end
- end
- end
-
- class Contributors < ContributorsBase
- def to_feed(rss, channel)
- end
-
- class Contributor < ContributorBase
- end
- end
-
- class Generator < GeneratorBase
- def to_feed(rss, channel)
- end
- end
-
- class Copyright < CopyrightBase
- def to_feed(rss, channel)
- channel.copyright = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
-
- class Description < DescriptionBase
- def to_feed(rss, channel)
- channel.description = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
-
- class Title < TitleBase
- def to_feed(rss, channel)
- channel.title = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
- end
-
- class Image < ImageBase
- def to_feed(rss)
- image = Rss::Channel::Image.new
- set = setup_values(image)
- if set
- image.link = link
- rss.channel.image = image
- set_parent(image, rss.channel)
- setup_other_elements(rss, image)
- elsif required_element?
- raise NotSetError.new("maker.image", not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(url title link)
- end
-
- def required_element?
- true
- end
- end
-
- class Items < ItemsBase
- def to_feed(rss)
- if rss.channel
- normalize.each do |item|
- item.to_feed(rss)
- end
- setup_other_elements(rss, rss.items)
- end
- end
-
- class Item < ItemBase
- def to_feed(rss)
- item = Rss::Channel::Item.new
- setup_values(item)
- _not_set_required_variables = not_set_required_variables
- if _not_set_required_variables.empty?
- rss.items << item
- set_parent(item, rss.channel)
- setup_other_elements(rss, item)
- elsif variable_is_set?
- raise NotSetError.new("maker.items", _not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- []
- end
-
- def not_set_required_variables
- vars = super
- if @maker.feed_version == "0.91"
- vars << "title" unless title {|t| t.have_required_values?}
- vars << "link" unless link {|l| l.have_required_values?}
- end
- vars
- end
-
- class Guid < GuidBase
- def to_feed(*args)
- end
- end
-
- class Enclosure < EnclosureBase
- def to_feed(*args)
- end
- end
-
- class Source < SourceBase
- def to_feed(*args)
- end
-
- class Authors < AuthorsBase
- def to_feed(*args)
- end
-
- class Author < AuthorBase
- end
- end
-
- class Categories < CategoriesBase
- def to_feed(*args)
- end
-
- class Category < CategoryBase
- end
- end
-
- class Contributors < ContributorsBase
- def to_feed(*args)
- end
-
- class Contributor < ContributorBase
- end
- end
-
- class Generator < GeneratorBase
- def to_feed(*args)
- end
- end
-
- class Icon < IconBase
- def to_feed(*args)
- end
- end
-
- class Links < LinksBase
- def to_feed(*args)
- end
-
- class Link < LinkBase
- end
- end
-
- class Logo < LogoBase
- def to_feed(*args)
- end
- end
-
- class Rights < RightsBase
- def to_feed(*args)
- end
- end
-
- class Subtitle < SubtitleBase
- def to_feed(*args)
- end
- end
-
- class Title < TitleBase
- def to_feed(*args)
- end
- end
- end
-
- class Categories < CategoriesBase
- def to_feed(*args)
- end
-
- class Category < CategoryBase
- end
- end
-
- class Authors < AuthorsBase
- def to_feed(*args)
- end
-
- class Author < AuthorBase
- end
- end
-
- class Links < LinksBase
- def to_feed(rss, item)
- return if @links.empty?
- @links.first.to_feed(rss, item)
- end
-
- class Link < LinkBase
- def to_feed(rss, item)
- if have_required_values?
- item.link = href
- else
- raise NotSetError.new("maker.link",
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(href)
- end
- end
- end
-
- class Contributors < ContributorsBase
- def to_feed(rss, item)
- end
-
- class Contributor < ContributorBase
- end
- end
-
- class Rights < RightsBase
- def to_feed(rss, item)
- end
- end
-
- class Description < DescriptionBase
- def to_feed(rss, item)
- item.description = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
-
- class Content < ContentBase
- def to_feed(rss, item)
- end
- end
-
- class Title < TitleBase
- def to_feed(rss, item)
- item.title = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
- end
- end
-
- class Textinput < TextinputBase
- def to_feed(rss)
- textInput = Rss::Channel::TextInput.new
- set = setup_values(textInput)
- if set
- rss.channel.textInput = textInput
- set_parent(textInput, rss.channel)
- setup_other_elements(rss, textInput)
- end
- end
-
- private
- def required_variable_names
- %w(title description name link)
- end
- end
- end
-
- class RSS091 < RSS09
- def initialize(feed_version="0.91")
- super
- end
-
- class Channel < RSS09::Channel
- end
-
- class Items < RSS09::Items
- class Item < RSS09::Items::Item
- end
- end
-
- class Image < RSS09::Image
- end
-
- class Textinput < RSS09::Textinput
- end
- end
-
- class RSS092 < RSS09
- def initialize(feed_version="0.92")
- super
- end
-
- class Channel < RSS09::Channel
- end
-
- class Items < RSS09::Items
- class Item < RSS09::Items::Item
- end
- end
-
- class Image < RSS09::Image
- end
-
- class Textinput < RSS09::Textinput
- end
- end
-
- add_maker("0.9", "0.92", RSS092)
- add_maker("0.91", "0.91", RSS091)
- add_maker("0.92", "0.92", RSS092)
- add_maker("rss0.9", "0.92", RSS092)
- add_maker("rss0.91", "0.91", RSS091)
- add_maker("rss0.92", "0.92", RSS092)
- end
-end
diff --git a/ruby_2_2/lib/rss/maker/1.0.rb b/ruby_2_2/lib/rss/maker/1.0.rb
deleted file mode 100644
index 1b9f7c3b79..0000000000
--- a/ruby_2_2/lib/rss/maker/1.0.rb
+++ /dev/null
@@ -1,435 +0,0 @@
-require "rss/1.0"
-
-require "rss/maker/base"
-
-module RSS
- module Maker
-
- class RSS10 < RSSBase
-
- def initialize(feed_version="1.0")
- super
- @feed_type = "rss"
- end
-
- private
- def make_feed
- RDF.new(@version, @encoding, @standalone)
- end
-
- def setup_elements(rss)
- setup_channel(rss)
- setup_image(rss)
- setup_items(rss)
- setup_textinput(rss)
- end
-
- class Channel < ChannelBase
- include SetupDefaultLanguage
-
- def to_feed(rss)
- set_default_values do
- _not_set_required_variables = not_set_required_variables
- if _not_set_required_variables.empty?
- channel = RDF::Channel.new(@about)
- setup_values(channel)
- channel.dc_dates.clear
- rss.channel = channel
- set_parent(channel, rss)
- setup_items(rss)
- setup_image(rss)
- setup_textinput(rss)
- setup_other_elements(rss, channel)
- else
- raise NotSetError.new("maker.channel", _not_set_required_variables)
- end
- end
- end
-
- private
- def setup_items(rss)
- items = RDF::Channel::Items.new
- seq = items.Seq
- set_parent(items, seq)
- target_items = @maker.items.normalize
- raise NotSetError.new("maker", ["items"]) if target_items.empty?
- target_items.each do |item|
- li = RDF::Channel::Items::Seq::Li.new(item.link)
- seq.lis << li
- set_parent(li, seq)
- end
- rss.channel.items = items
- set_parent(rss.channel, items)
- end
-
- def setup_image(rss)
- if @maker.image.have_required_values?
- image = RDF::Channel::Image.new(@maker.image.url)
- rss.channel.image = image
- set_parent(image, rss.channel)
- end
- end
-
- def setup_textinput(rss)
- if @maker.textinput.have_required_values?
- textinput = RDF::Channel::Textinput.new(@maker.textinput.link)
- rss.channel.textinput = textinput
- set_parent(textinput, rss.channel)
- end
- end
-
- def required_variable_names
- %w(about link)
- end
-
- def not_set_required_variables
- vars = super
- vars << "description" unless description {|d| d.have_required_values?}
- vars << "title" unless title {|t| t.have_required_values?}
- vars
- end
-
- class SkipDays < SkipDaysBase
- def to_feed(*args)
- end
-
- class Day < DayBase
- end
- end
-
- class SkipHours < SkipHoursBase
- def to_feed(*args)
- end
-
- class Hour < HourBase
- end
- end
-
- class Cloud < CloudBase
- def to_feed(*args)
- end
- end
-
- class Categories < CategoriesBase
- def to_feed(*args)
- end
-
- class Category < CategoryBase
- end
- end
-
- class Links < LinksBase
- def to_feed(rss, channel)
- return if @links.empty?
- @links.first.to_feed(rss, channel)
- end
-
- class Link < LinkBase
- def to_feed(rss, channel)
- if have_required_values?
- channel.link = href
- else
- raise NotSetError.new("maker.channel.link",
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(href)
- end
- end
- end
-
- class Authors < AuthorsBase
- def to_feed(rss, channel)
- end
-
- class Author < AuthorBase
- def to_feed(rss, channel)
- end
- end
- end
-
- class Contributors < ContributorsBase
- def to_feed(rss, channel)
- end
-
- class Contributor < ContributorBase
- end
- end
-
- class Generator < GeneratorBase
- def to_feed(rss, channel)
- end
- end
-
- class Copyright < CopyrightBase
- def to_feed(rss, channel)
- end
- end
-
- class Description < DescriptionBase
- def to_feed(rss, channel)
- channel.description = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
-
- class Title < TitleBase
- def to_feed(rss, channel)
- channel.title = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
- end
-
- class Image < ImageBase
- def to_feed(rss)
- if @url
- image = RDF::Image.new(@url)
- set = setup_values(image)
- if set
- rss.image = image
- set_parent(image, rss)
- setup_other_elements(rss, image)
- end
- end
- end
-
- def have_required_values?
- super and @maker.channel.have_required_values?
- end
-
- private
- def variables
- super + ["link"]
- end
-
- def required_variable_names
- %w(url title link)
- end
- end
-
- class Items < ItemsBase
- def to_feed(rss)
- if rss.channel
- normalize.each do |item|
- item.to_feed(rss)
- end
- setup_other_elements(rss, rss.items)
- end
- end
-
- class Item < ItemBase
- def to_feed(rss)
- set_default_values do
- item = RDF::Item.new(link)
- set = setup_values(item)
- if set
- item.dc_dates.clear
- rss.items << item
- set_parent(item, rss)
- setup_other_elements(rss, item)
- elsif !have_required_values?
- raise NotSetError.new("maker.item", not_set_required_variables)
- end
- end
- end
-
- private
- def required_variable_names
- %w(link)
- end
-
- def variables
- super + %w(link)
- end
-
- def not_set_required_variables
- set_default_values do
- vars = super
- vars << "title" unless title {|t| t.have_required_values?}
- vars
- end
- end
-
- class Guid < GuidBase
- def to_feed(*args)
- end
- end
-
- class Enclosure < EnclosureBase
- def to_feed(*args)
- end
- end
-
- class Source < SourceBase
- def to_feed(*args)
- end
-
- class Authors < AuthorsBase
- def to_feed(*args)
- end
-
- class Author < AuthorBase
- end
- end
-
- class Categories < CategoriesBase
- def to_feed(*args)
- end
-
- class Category < CategoryBase
- end
- end
-
- class Contributors < ContributorsBase
- def to_feed(*args)
- end
-
- class Contributor < ContributorBase
- end
- end
-
- class Generator < GeneratorBase
- def to_feed(*args)
- end
- end
-
- class Icon < IconBase
- def to_feed(*args)
- end
- end
-
- class Links < LinksBase
- def to_feed(*args)
- end
-
- class Link < LinkBase
- end
- end
-
- class Logo < LogoBase
- def to_feed(*args)
- end
- end
-
- class Rights < RightsBase
- def to_feed(*args)
- end
- end
-
- class Subtitle < SubtitleBase
- def to_feed(*args)
- end
- end
-
- class Title < TitleBase
- def to_feed(*args)
- end
- end
- end
-
- class Categories < CategoriesBase
- def to_feed(*args)
- end
-
- class Category < CategoryBase
- end
- end
-
- class Authors < AuthorsBase
- def to_feed(*args)
- end
-
- class Author < AuthorBase
- end
- end
-
- class Links < LinksBase
- def to_feed(*args)
- end
-
- class Link < LinkBase
- end
- end
-
- class Contributors < ContributorsBase
- def to_feed(rss, item)
- end
-
- class Contributor < ContributorBase
- end
- end
-
- class Rights < RightsBase
- def to_feed(rss, item)
- end
- end
-
- class Description < DescriptionBase
- def to_feed(rss, item)
- item.description = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
-
- class Content < ContentBase
- def to_feed(rss, item)
- end
- end
-
- class Title < TitleBase
- def to_feed(rss, item)
- item.title = content if have_required_values?
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
- end
- end
-
- class Textinput < TextinputBase
- def to_feed(rss)
- if @link
- textinput = RDF::Textinput.new(@link)
- set = setup_values(textinput)
- if set
- rss.textinput = textinput
- set_parent(textinput, rss)
- setup_other_elements(rss, textinput)
- end
- end
- end
-
- def have_required_values?
- super and @maker.channel.have_required_values?
- end
-
- private
- def required_variable_names
- %w(title description name link)
- end
- end
- end
-
- add_maker("1.0", "1.0", RSS10)
- add_maker("rss1.0", "1.0", RSS10)
- end
-end
diff --git a/ruby_2_2/lib/rss/maker/2.0.rb b/ruby_2_2/lib/rss/maker/2.0.rb
deleted file mode 100644
index 15b1349c2a..0000000000
--- a/ruby_2_2/lib/rss/maker/2.0.rb
+++ /dev/null
@@ -1,223 +0,0 @@
-require "rss/2.0"
-
-require "rss/maker/0.9"
-
-module RSS
- module Maker
-
- class RSS20 < RSS09
-
- def initialize(feed_version="2.0")
- super
- end
-
- class Channel < RSS09::Channel
-
- private
- def required_variable_names
- %w(link)
- end
-
- class SkipDays < RSS09::Channel::SkipDays
- class Day < RSS09::Channel::SkipDays::Day
- end
- end
-
- class SkipHours < RSS09::Channel::SkipHours
- class Hour < RSS09::Channel::SkipHours::Hour
- end
- end
-
- class Cloud < RSS09::Channel::Cloud
- def to_feed(rss, channel)
- cloud = Rss::Channel::Cloud.new
- set = setup_values(cloud)
- if set
- channel.cloud = cloud
- set_parent(cloud, channel)
- setup_other_elements(rss, cloud)
- end
- end
-
- private
- def required_variable_names
- %w(domain port path registerProcedure protocol)
- end
- end
-
- class Categories < RSS09::Channel::Categories
- def to_feed(rss, channel)
- @categories.each do |category|
- category.to_feed(rss, channel)
- end
- end
-
- class Category < RSS09::Channel::Categories::Category
- def to_feed(rss, channel)
- category = Rss::Channel::Category.new
- set = setup_values(category)
- if set
- channel.categories << category
- set_parent(category, channel)
- setup_other_elements(rss, category)
- end
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
- end
-
- class Generator < GeneratorBase
- def to_feed(rss, channel)
- channel.generator = content
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
- end
-
- class Image < RSS09::Image
- private
- def required_element?
- false
- end
- end
-
- class Items < RSS09::Items
- class Item < RSS09::Items::Item
- private
- def required_variable_names
- []
- end
-
- def not_set_required_variables
- vars = super
- if !title {|t| t.have_required_values?} and
- !description {|d| d.have_required_values?}
- vars << "title or description"
- end
- vars
- end
-
- def variables
- super + ["pubDate"]
- end
-
- class Guid < RSS09::Items::Item::Guid
- def to_feed(rss, item)
- guid = Rss::Channel::Item::Guid.new
- set = setup_values(guid)
- if set
- item.guid = guid
- set_parent(guid, item)
- setup_other_elements(rss, guid)
- end
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
-
- class Enclosure < RSS09::Items::Item::Enclosure
- def to_feed(rss, item)
- enclosure = Rss::Channel::Item::Enclosure.new
- set = setup_values(enclosure)
- if set
- item.enclosure = enclosure
- set_parent(enclosure, item)
- setup_other_elements(rss, enclosure)
- end
- end
-
- private
- def required_variable_names
- %w(url length type)
- end
- end
-
- class Source < RSS09::Items::Item::Source
- def to_feed(rss, item)
- source = Rss::Channel::Item::Source.new
- set = setup_values(source)
- if set
- item.source = source
- set_parent(source, item)
- setup_other_elements(rss, source)
- end
- end
-
- private
- def required_variable_names
- %w(url content)
- end
-
- class Links < RSS09::Items::Item::Source::Links
- def to_feed(rss, source)
- return if @links.empty?
- @links.first.to_feed(rss, source)
- end
-
- class Link < RSS09::Items::Item::Source::Links::Link
- def to_feed(rss, source)
- source.url = href
- end
- end
- end
- end
-
- class Categories < RSS09::Items::Item::Categories
- def to_feed(rss, item)
- @categories.each do |category|
- category.to_feed(rss, item)
- end
- end
-
- class Category < RSS09::Items::Item::Categories::Category
- def to_feed(rss, item)
- category = Rss::Channel::Item::Category.new
- set = setup_values(category)
- if set
- item.categories << category
- set_parent(category, item)
- setup_other_elements(rss)
- end
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
- end
-
- class Authors < RSS09::Items::Item::Authors
- def to_feed(rss, item)
- return if @authors.empty?
- @authors.first.to_feed(rss, item)
- end
-
- class Author < RSS09::Items::Item::Authors::Author
- def to_feed(rss, item)
- item.author = name
- end
- end
- end
- end
- end
-
- class Textinput < RSS09::Textinput
- end
- end
-
- add_maker("2.0", "2.0", RSS20)
- add_maker("rss2.0", "2.0", RSS20)
- end
-end
diff --git a/ruby_2_2/lib/rss/maker/atom.rb b/ruby_2_2/lib/rss/maker/atom.rb
deleted file mode 100644
index fd3198cd9e..0000000000
--- a/ruby_2_2/lib/rss/maker/atom.rb
+++ /dev/null
@@ -1,172 +0,0 @@
-require "rss/atom"
-
-require "rss/maker/base"
-
-module RSS
- module Maker
- module AtomPersons
- module_function
- def def_atom_persons(klass, name, maker_name, plural=nil)
- plural ||= "#{name}s"
- klass_name = Utils.to_class_name(name)
- plural_klass_name = Utils.to_class_name(plural)
-
- klass.class_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class #{plural_klass_name} < #{plural_klass_name}Base
- class #{klass_name} < #{klass_name}Base
- def to_feed(feed, current)
- #{name} = feed.class::#{klass_name}.new
- set = setup_values(#{name})
- unless set
- raise NotSetError.new(#{maker_name.dump},
- not_set_required_variables)
- end
- current.#{plural} << #{name}
- set_parent(#{name}, current)
- setup_other_elements(#{name})
- end
-
- private
- def required_variable_names
- %w(name)
- end
- end
- end
-EOC
- end
- end
-
- module AtomTextConstruct
- class << self
- def def_atom_text_construct(klass, name, maker_name, klass_name=nil,
- atom_klass_name=nil)
- klass_name ||= Utils.to_class_name(name)
- atom_klass_name ||= Utils.to_class_name(name)
-
- klass.class_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class #{klass_name} < #{klass_name}Base
- include #{self.name}
- def to_feed(feed, current)
- #{name} = current.class::#{atom_klass_name}.new
- if setup_values(#{name})
- current.#{name} = #{name}
- set_parent(#{name}, current)
- setup_other_elements(feed)
- elsif variable_is_set?
- raise NotSetError.new(#{maker_name.dump},
- not_set_required_variables)
- end
- end
- end
- EOC
- end
- end
-
- private
- def required_variable_names
- if type == "xhtml"
- %w(xml_content)
- else
- %w(content)
- end
- end
-
- def variables
- if type == "xhtml"
- super + %w(xhtml)
- else
- super
- end
- end
- end
-
- module AtomCategory
- def to_feed(feed, current)
- category = feed.class::Category.new
- set = setup_values(category)
- if set
- current.categories << category
- set_parent(category, current)
- setup_other_elements(feed)
- else
- raise NotSetError.new(self.class.not_set_name,
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(term)
- end
-
- def variables
- super + ["term", "scheme"]
- end
- end
-
- module AtomLink
- def to_feed(feed, current)
- link = feed.class::Link.new
- set = setup_values(link)
- if set
- current.links << link
- set_parent(link, current)
- setup_other_elements(feed)
- else
- raise NotSetError.new(self.class.not_set_name,
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(href)
- end
- end
-
- module AtomGenerator
- def to_feed(feed, current)
- generator = current.class::Generator.new
- if setup_values(generator)
- current.generator = generator
- set_parent(generator, current)
- setup_other_elements(feed)
- elsif variable_is_set?
- raise NotSetError.new(self.class.not_set_name,
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(content)
- end
- end
-
- module AtomLogo
- def to_feed(feed, current)
- logo = current.class::Logo.new
- class << logo
- alias_method(:uri=, :content=)
- end
- set = setup_values(logo)
- class << logo
- remove_method(:uri=)
- end
- if set
- current.logo = logo
- set_parent(logo, current)
- setup_other_elements(feed)
- elsif variable_is_set?
- raise NotSetError.new(self.class.not_set_name,
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(uri)
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rss/maker/base.rb b/ruby_2_2/lib/rss/maker/base.rb
deleted file mode 100644
index 0f2fc11103..0000000000
--- a/ruby_2_2/lib/rss/maker/base.rb
+++ /dev/null
@@ -1,944 +0,0 @@
-require 'forwardable'
-
-require 'rss/rss'
-
-module RSS
- module Maker
- class Base
- extend Utils::InheritedReader
-
- OTHER_ELEMENTS = []
- NEED_INITIALIZE_VARIABLES = []
-
- class << self
- def other_elements
- inherited_array_reader("OTHER_ELEMENTS")
- end
- def need_initialize_variables
- inherited_array_reader("NEED_INITIALIZE_VARIABLES")
- end
-
- def inherited_base
- ::RSS::Maker::Base
- end
-
- def inherited(subclass)
- subclass.const_set(:OTHER_ELEMENTS, [])
- subclass.const_set(:NEED_INITIALIZE_VARIABLES, [])
- end
-
- def add_other_element(variable_name)
- self::OTHER_ELEMENTS << variable_name
- end
-
- def add_need_initialize_variable(variable_name, init_value=nil,
- &init_block)
- init_value ||= init_block
- self::NEED_INITIALIZE_VARIABLES << [variable_name, init_value]
- end
-
- def def_array_element(name, plural=nil, klass_name=nil)
- include Enumerable
- extend Forwardable
-
- plural ||= "#{name}s"
- klass_name ||= Utils.to_class_name(name)
- def_delegators("@#{plural}", :<<, :[], :[]=, :first, :last)
- def_delegators("@#{plural}", :push, :pop, :shift, :unshift)
- def_delegators("@#{plural}", :each, :size, :empty?, :clear)
-
- add_need_initialize_variable(plural) {[]}
-
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def new_#{name}
- #{name} = self.class::#{klass_name}.new(@maker)
- @#{plural} << #{name}
- if block_given?
- yield #{name}
- else
- #{name}
- end
- end
- alias new_child new_#{name}
-
- def to_feed(*args)
- @#{plural}.each do |#{name}|
- #{name}.to_feed(*args)
- end
- end
-
- def replace(elements)
- @#{plural}.replace(elements.to_a)
- end
- EOC
- end
-
- def def_classed_element_without_accessor(name, class_name=nil)
- class_name ||= Utils.to_class_name(name)
- add_other_element(name)
- add_need_initialize_variable(name) do |object|
- object.send("make_#{name}")
- end
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- private
- def setup_#{name}(feed, current)
- @#{name}.to_feed(feed, current)
- end
-
- def make_#{name}
- self.class::#{class_name}.new(@maker)
- end
- EOC
- end
-
- def def_classed_element(name, class_name=nil, attribute_name=nil)
- def_classed_element_without_accessor(name, class_name)
- if attribute_name
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}
- if block_given?
- yield(@#{name})
- else
- @#{name}.#{attribute_name}
- end
- end
-
- def #{name}=(new_value)
- @#{name}.#{attribute_name} = new_value
- end
- EOC
- else
- attr_reader name
- end
- end
-
- def def_classed_elements(name, attribute, plural_class_name=nil,
- plural_name=nil, new_name=nil)
- plural_name ||= "#{name}s"
- new_name ||= name
- def_classed_element(plural_name, plural_class_name)
- local_variable_name = "_#{name}"
- new_value_variable_name = "new_value"
- additional_setup_code = nil
- if block_given?
- additional_setup_code = yield(local_variable_name,
- new_value_variable_name)
- end
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}
- #{local_variable_name} = #{plural_name}.first
- #{local_variable_name} ? #{local_variable_name}.#{attribute} : nil
- end
-
- def #{name}=(#{new_value_variable_name})
- #{local_variable_name} =
- #{plural_name}.first || #{plural_name}.new_#{new_name}
- #{additional_setup_code}
- #{local_variable_name}.#{attribute} = #{new_value_variable_name}
- end
- EOC
- end
-
- def def_other_element(name)
- attr_accessor name
- def_other_element_without_accessor(name)
- end
-
- def def_other_element_without_accessor(name)
- add_need_initialize_variable(name)
- add_other_element(name)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def setup_#{name}(feed, current)
- if !@#{name}.nil? and current.respond_to?(:#{name}=)
- current.#{name} = @#{name}
- end
- end
- EOC
- end
-
- def def_csv_element(name, type=nil)
- def_other_element_without_accessor(name)
- attr_reader(name)
- converter = ""
- if type == :integer
- converter = "{|v| Integer(v)}"
- end
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}=(value)
- @#{name} = Utils::CSV.parse(value)#{converter}
- end
- EOC
- end
- end
-
- attr_reader :maker
- def initialize(maker)
- @maker = maker
- @default_values_are_set = false
- initialize_variables
- end
-
- def have_required_values?
- not_set_required_variables.empty?
- end
-
- def variable_is_set?
- variables.any? {|var| not __send__(var).nil?}
- end
-
- private
- def initialize_variables
- self.class.need_initialize_variables.each do |variable_name, init_value|
- if init_value.nil?
- value = nil
- else
- if init_value.respond_to?(:call)
- value = init_value.call(self)
- elsif init_value.is_a?(String)
- # just for backward compatibility
- value = instance_eval(init_value, __FILE__, __LINE__)
- else
- value = init_value
- end
- end
- instance_variable_set("@#{variable_name}", value)
- end
- end
-
- def setup_other_elements(feed, current=nil)
- current ||= current_element(feed)
- self.class.other_elements.each do |element|
- __send__("setup_#{element}", feed, current)
- end
- end
-
- def current_element(feed)
- feed
- end
-
- def set_default_values(&block)
- return yield if @default_values_are_set
-
- begin
- @default_values_are_set = true
- _set_default_values(&block)
- ensure
- @default_values_are_set = false
- end
- end
-
- def _set_default_values(&block)
- yield
- end
-
- def setup_values(target)
- set = false
- if have_required_values?
- variables.each do |var|
- setter = "#{var}="
- if target.respond_to?(setter)
- value = __send__(var)
- unless value.nil?
- target.__send__(setter, value)
- set = true
- end
- end
- end
- end
- set
- end
-
- def set_parent(target, parent)
- target.parent = parent if target.class.need_parent?
- end
-
- def variables
- self.class.need_initialize_variables.find_all do |name, init|
- # init == "nil" is just for backward compatibility
- init.nil? or init == "nil"
- end.collect do |name, init|
- name
- end
- end
-
- def not_set_required_variables
- required_variable_names.find_all do |var|
- __send__(var).nil?
- end
- end
-
- def required_variables_are_set?
- required_variable_names.each do |var|
- return false if __send__(var).nil?
- end
- true
- end
- end
-
- module AtomPersonConstructBase
- def self.append_features(klass)
- super
-
- klass.class_eval(<<-EOC, __FILE__, __LINE__ + 1)
- %w(name uri email).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- EOC
- end
- end
-
- module AtomTextConstructBase
- module EnsureXMLContent
- class << self
- def included(base)
- super
- base.class_eval do
- %w(type content xml_content).each do |element|
- attr_reader element
- attr_writer element if element != "xml_content"
- add_need_initialize_variable(element)
- end
-
- alias_method(:xhtml, :xml_content)
- end
- end
- end
-
- def ensure_xml_content(content)
- xhtml_uri = ::RSS::Atom::XHTML_URI
- unless content.is_a?(RSS::XML::Element) and
- ["div", xhtml_uri] == [content.name, content.uri]
- children = content
- children = [children] unless content.is_a?(Array)
- children = set_xhtml_uri_as_default_uri(children)
- content = RSS::XML::Element.new("div", nil, xhtml_uri,
- {"xmlns" => xhtml_uri},
- children)
- end
- content
- end
-
- def xml_content=(content)
- @xml_content = ensure_xml_content(content)
- end
-
- def xhtml=(content)
- self.xml_content = content
- end
-
- private
- def set_xhtml_uri_as_default_uri(children)
- children.collect do |child|
- if child.is_a?(RSS::XML::Element) and
- child.prefix.nil? and child.uri.nil?
- RSS::XML::Element.new(child.name, nil, ::RSS::Atom::XHTML_URI,
- child.attributes.dup,
- set_xhtml_uri_as_default_uri(child.children))
- else
- child
- end
- end
- end
- end
-
- def self.append_features(klass)
- super
-
- klass.class_eval do
- include EnsureXMLContent
- end
- end
- end
-
- module SetupDefaultDate
- private
- def _set_default_values
- keep = {
- :date => date,
- :dc_dates => dc_dates.to_a.dup,
- }
- _date = _parse_date_if_needed(date)
- if _date and !dc_dates.any? {|dc_date| dc_date.value == _date}
- dc_date = self.class::DublinCoreDates::DublinCoreDate.new(self)
- dc_date.value = _date.dup
- dc_dates.unshift(dc_date)
- end
- self.date ||= self.dc_date
- super
- ensure
- self.date = keep[:date]
- dc_dates.replace(keep[:dc_dates])
- end
-
- def _parse_date_if_needed(date_value)
- date_value = Time.parse(date_value) if date_value.is_a?(String)
- date_value
- end
- end
-
- module SetupDefaultLanguage
- private
- def _set_default_values
- keep = {
- :dc_languages => dc_languages.to_a.dup,
- }
- _language = language
- if _language and
- !dc_languages.any? {|dc_language| dc_language.value == _language}
- dc_language = self.class::DublinCoreLanguages::DublinCoreLanguage.new(self)
- dc_language.value = _language.dup
- dc_languages.unshift(dc_language)
- end
- super
- ensure
- dc_languages.replace(keep[:dc_languages])
- end
- end
-
- class RSSBase < Base
- class << self
- def make(*args, &block)
- new(*args).make(&block)
- end
- end
-
- %w(xml_stylesheets channel image items textinput).each do |element|
- attr_reader element
- add_need_initialize_variable(element) do |object|
- object.send("make_#{element}")
- end
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- private
- def setup_#{element}(feed)
- @#{element}.to_feed(feed)
- end
-
- def make_#{element}
- self.class::#{Utils.to_class_name(element)}.new(self)
- end
- EOC
- end
-
- attr_reader :feed_version
- alias_method(:rss_version, :feed_version)
- attr_accessor :version, :encoding, :standalone
-
- def initialize(feed_version)
- super(self)
- @feed_type = nil
- @feed_subtype = nil
- @feed_version = feed_version
- @version = "1.0"
- @encoding = "UTF-8"
- @standalone = nil
- end
-
- def make
- yield(self)
- to_feed
- end
-
- def to_feed
- feed = make_feed
- setup_xml_stylesheets(feed)
- setup_elements(feed)
- setup_other_elements(feed)
- feed.validate
- feed
- end
-
- private
- remove_method :make_xml_stylesheets
- def make_xml_stylesheets
- XMLStyleSheets.new(self)
- end
- end
-
- class XMLStyleSheets < Base
- def_array_element("xml_stylesheet", nil, "XMLStyleSheet")
-
- class XMLStyleSheet < Base
-
- ::RSS::XMLStyleSheet::ATTRIBUTES.each do |attribute|
- attr_accessor attribute
- add_need_initialize_variable(attribute)
- end
-
- def to_feed(feed)
- xss = ::RSS::XMLStyleSheet.new
- guess_type_if_need(xss)
- set = setup_values(xss)
- if set
- feed.xml_stylesheets << xss
- end
- end
-
- private
- def guess_type_if_need(xss)
- if @type.nil?
- xss.href = @href
- @type = xss.type
- end
- end
-
- def required_variable_names
- %w(href type)
- end
- end
- end
-
- class ChannelBase < Base
- include SetupDefaultDate
-
- %w(cloud categories skipDays skipHours).each do |name|
- def_classed_element(name)
- end
-
- %w(generator copyright description title).each do |name|
- def_classed_element(name, nil, "content")
- end
-
- [
- ["link", "href", Proc.new {|target,| "#{target}.href = 'self'"}],
- ["author", "name"],
- ["contributor", "name"],
- ].each do |name, attribute, additional_setup_maker|
- def_classed_elements(name, attribute, &additional_setup_maker)
- end
-
- %w(id about language
- managingEditor webMaster rating docs ttl).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
-
- %w(date lastBuildDate).each do |date_element|
- attr_reader date_element
- add_need_initialize_variable(date_element)
- end
-
- def date=(_date)
- @date = _parse_date_if_needed(_date)
- end
-
- def lastBuildDate=(_date)
- @lastBuildDate = _parse_date_if_needed(_date)
- end
-
- def pubDate
- date
- end
-
- def pubDate=(date)
- self.date = date
- end
-
- def updated
- date
- end
-
- def updated=(date)
- self.date = date
- end
-
- alias_method(:rights, :copyright)
- alias_method(:rights=, :copyright=)
-
- alias_method(:subtitle, :description)
- alias_method(:subtitle=, :description=)
-
- def icon
- image_favicon.about
- end
-
- def icon=(url)
- image_favicon.about = url
- end
-
- def logo
- maker.image.url
- end
-
- def logo=(url)
- maker.image.url = url
- end
-
- class SkipDaysBase < Base
- def_array_element("day")
-
- class DayBase < Base
- %w(content).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
- end
-
- class SkipHoursBase < Base
- def_array_element("hour")
-
- class HourBase < Base
- %w(content).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
- end
-
- class CloudBase < Base
- %w(domain port path registerProcedure protocol).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
-
- class CategoriesBase < Base
- def_array_element("category", "categories")
-
- class CategoryBase < Base
- %w(domain content label).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
-
- alias_method(:term, :domain)
- alias_method(:term=, :domain=)
- alias_method(:scheme, :content)
- alias_method(:scheme=, :content=)
- end
- end
-
- class LinksBase < Base
- def_array_element("link")
-
- class LinkBase < Base
- %w(href rel type hreflang title length).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
- end
-
- class AuthorsBase < Base
- def_array_element("author")
-
- class AuthorBase < Base
- include AtomPersonConstructBase
- end
- end
-
- class ContributorsBase < Base
- def_array_element("contributor")
-
- class ContributorBase < Base
- include AtomPersonConstructBase
- end
- end
-
- class GeneratorBase < Base
- %w(uri version content).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
-
- class CopyrightBase < Base
- include AtomTextConstructBase
- end
-
- class DescriptionBase < Base
- include AtomTextConstructBase
- end
-
- class TitleBase < Base
- include AtomTextConstructBase
- end
- end
-
- class ImageBase < Base
- %w(title url width height description).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
-
- def link
- @maker.channel.link
- end
- end
-
- class ItemsBase < Base
- def_array_element("item")
-
- attr_accessor :do_sort, :max_size
-
- def initialize(maker)
- super
- @do_sort = false
- @max_size = -1
- end
-
- def normalize
- if @max_size >= 0
- sort_if_need[0...@max_size]
- else
- sort_if_need[0..@max_size]
- end
- end
-
- private
- def sort_if_need
- if @do_sort.respond_to?(:call)
- @items.sort do |x, y|
- @do_sort.call(x, y)
- end
- elsif @do_sort
- @items.sort do |x, y|
- y <=> x
- end
- else
- @items
- end
- end
-
- class ItemBase < Base
- include SetupDefaultDate
-
- %w(guid enclosure source categories content).each do |name|
- def_classed_element(name)
- end
-
- %w(rights description title).each do |name|
- def_classed_element(name, nil, "content")
- end
-
- [
- ["author", "name"],
- ["link", "href", Proc.new {|target,| "#{target}.href = 'alternate'"}],
- ["contributor", "name"],
- ].each do |name, attribute|
- def_classed_elements(name, attribute)
- end
-
- %w(comments id published).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
-
- %w(date).each do |date_element|
- attr_reader date_element
- add_need_initialize_variable(date_element)
- end
-
- def date=(_date)
- @date = _parse_date_if_needed(_date)
- end
-
- def pubDate
- date
- end
-
- def pubDate=(date)
- self.date = date
- end
-
- def updated
- date
- end
-
- def updated=(date)
- self.date = date
- end
-
- alias_method(:summary, :description)
- alias_method(:summary=, :description=)
-
- def <=>(other)
- _date = date || dc_date
- _other_date = other.date || other.dc_date
- if _date and _other_date
- _date <=> _other_date
- elsif _date
- 1
- elsif _other_date
- -1
- else
- 0
- end
- end
-
- class GuidBase < Base
- %w(isPermaLink content).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
-
- def permanent_link?
- isPermaLink
- end
-
- def permanent_link=(bool)
- self.isPermaLink = bool
- end
- end
-
- class EnclosureBase < Base
- %w(url length type).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
-
- class SourceBase < Base
- include SetupDefaultDate
-
- %w(authors categories contributors generator icon
- logo rights subtitle title).each do |name|
- def_classed_element(name)
- end
-
- [
- ["link", "href"],
- ].each do |name, attribute|
- def_classed_elements(name, attribute)
- end
-
- %w(id content).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
-
- alias_method(:url, :link)
- alias_method(:url=, :link=)
-
- %w(date).each do |date_element|
- attr_reader date_element
- add_need_initialize_variable(date_element)
- end
-
- def date=(_date)
- @date = _parse_date_if_needed(_date)
- end
-
- def updated
- date
- end
-
- def updated=(date)
- self.date = date
- end
-
- private
- AuthorsBase = ChannelBase::AuthorsBase
- CategoriesBase = ChannelBase::CategoriesBase
- ContributorsBase = ChannelBase::ContributorsBase
- GeneratorBase = ChannelBase::GeneratorBase
-
- class IconBase < Base
- %w(url).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
-
- LinksBase = ChannelBase::LinksBase
-
- class LogoBase < Base
- %w(uri).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
-
- class RightsBase < Base
- include AtomTextConstructBase
- end
-
- class SubtitleBase < Base
- include AtomTextConstructBase
- end
-
- class TitleBase < Base
- include AtomTextConstructBase
- end
- end
-
- CategoriesBase = ChannelBase::CategoriesBase
- AuthorsBase = ChannelBase::AuthorsBase
- LinksBase = ChannelBase::LinksBase
- ContributorsBase = ChannelBase::ContributorsBase
-
- class RightsBase < Base
- include AtomTextConstructBase
- end
-
- class DescriptionBase < Base
- include AtomTextConstructBase
- end
-
- class ContentBase < Base
- include AtomTextConstructBase::EnsureXMLContent
-
- %w(src).each do |element|
- attr_accessor(element)
- add_need_initialize_variable(element)
- end
-
- def xml_content=(content)
- content = ensure_xml_content(content) if inline_xhtml?
- @xml_content = content
- end
-
- alias_method(:xml, :xml_content)
- alias_method(:xml=, :xml_content=)
-
- def inline_text?
- [nil, "text", "html"].include?(@type)
- end
-
- def inline_html?
- @type == "html"
- end
-
- def inline_xhtml?
- @type == "xhtml"
- end
-
- def inline_other?
- !out_of_line? and ![nil, "text", "html", "xhtml"].include?(@type)
- end
-
- def inline_other_text?
- return false if @type.nil? or out_of_line?
- /\Atext\//i.match(@type) ? true : false
- end
-
- def inline_other_xml?
- return false if @type.nil? or out_of_line?
- /[\+\/]xml\z/i.match(@type) ? true : false
- end
-
- def inline_other_base64?
- return false if @type.nil? or out_of_line?
- @type.include?("/") and !inline_other_text? and !inline_other_xml?
- end
-
- def out_of_line?
- not @src.nil? and @content.nil?
- end
- end
-
- class TitleBase < Base
- include AtomTextConstructBase
- end
- end
- end
-
- class TextinputBase < Base
- %w(title description name link).each do |element|
- attr_accessor element
- add_need_initialize_variable(element)
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rss/maker/content.rb b/ruby_2_2/lib/rss/maker/content.rb
deleted file mode 100644
index 46c4911f73..0000000000
--- a/ruby_2_2/lib/rss/maker/content.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require 'rss/content'
-require 'rss/maker/1.0'
-require 'rss/maker/2.0'
-
-module RSS
- module Maker
- module ContentModel
- def self.append_features(klass)
- super
-
- ::RSS::ContentModel::ELEMENTS.each do |name|
- klass.def_other_element(name)
- end
- end
- end
-
- class ItemsBase
- class ItemBase; include ContentModel; end
- end
- end
-end
diff --git a/ruby_2_2/lib/rss/maker/dublincore.rb b/ruby_2_2/lib/rss/maker/dublincore.rb
deleted file mode 100644
index 717b074fae..0000000000
--- a/ruby_2_2/lib/rss/maker/dublincore.rb
+++ /dev/null
@@ -1,121 +0,0 @@
-require 'rss/dublincore'
-require 'rss/maker/1.0'
-
-module RSS
- module Maker
- module DublinCoreModel
- def self.append_features(klass)
- super
-
- ::RSS::DublinCoreModel::ELEMENT_NAME_INFOS.each do |name, plural_name|
- plural_name ||= "#{name}s"
- full_name = "#{RSS::DC_PREFIX}_#{name}"
- full_plural_name = "#{RSS::DC_PREFIX}_#{plural_name}"
- plural_klass_name = "DublinCore#{Utils.to_class_name(plural_name)}"
- klass.def_classed_elements(full_name, "value", plural_klass_name,
- full_plural_name, name)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def new_#{full_name}(value=nil)
- _#{full_name} = #{full_plural_name}.new_#{name}
- _#{full_name}.value = value
- if block_given?
- yield _#{full_name}
- else
- _#{full_name}
- end
- end
- EOC
- end
-
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- # For backward compatibility
- alias #{DC_PREFIX}_rightses #{DC_PREFIX}_rights_list
- EOC
- end
-
- ::RSS::DublinCoreModel::ELEMENT_NAME_INFOS.each do |name, plural_name|
- plural_name ||= "#{name}s"
- full_name ||= "#{DC_PREFIX}_#{name}"
- full_plural_name ||= "#{DC_PREFIX}_#{plural_name}"
- klass_name = Utils.to_class_name(name)
- full_klass_name = "DublinCore#{klass_name}"
- plural_klass_name = "DublinCore#{Utils.to_class_name(plural_name)}"
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class #{plural_klass_name}Base < Base
- def_array_element(#{name.dump}, #{full_plural_name.dump},
- #{full_klass_name.dump})
-
- class #{full_klass_name}Base < Base
- attr_accessor :value
- add_need_initialize_variable("value")
- alias_method(:content, :value)
- alias_method(:content=, :value=)
-
- def have_required_values?
- @value
- end
-
- def to_feed(feed, current)
- if value and current.respond_to?(:#{full_name})
- new_item = current.class::#{full_klass_name}.new(value)
- current.#{full_plural_name} << new_item
- end
- end
- end
- #{klass_name}Base = #{full_klass_name}Base
- end
- EOC
- end
-
- def self.install_dublin_core(klass)
- ::RSS::DublinCoreModel::ELEMENT_NAME_INFOS.each do |name, plural_name|
- plural_name ||= "#{name}s"
- klass_name = Utils.to_class_name(name)
- full_klass_name = "DublinCore#{klass_name}"
- plural_klass_name = "DublinCore#{Utils.to_class_name(plural_name)}"
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class #{plural_klass_name} < #{plural_klass_name}Base
- class #{full_klass_name} < #{full_klass_name}Base
- end
- #{klass_name} = #{full_klass_name}
- end
-EOC
- end
- end
- end
-
- class ChannelBase
- include DublinCoreModel
- end
-
- class ImageBase; include DublinCoreModel; end
- class ItemsBase
- class ItemBase
- include DublinCoreModel
- end
- end
- class TextinputBase; include DublinCoreModel; end
-
- makers.each do |maker|
- maker.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class Channel
- DublinCoreModel.install_dublin_core(self)
- end
-
- class Image
- DublinCoreModel.install_dublin_core(self)
- end
-
- class Items
- class Item
- DublinCoreModel.install_dublin_core(self)
- end
- end
-
- class Textinput
- DublinCoreModel.install_dublin_core(self)
- end
- EOC
- end
- end
-end
diff --git a/ruby_2_2/lib/rss/maker/entry.rb b/ruby_2_2/lib/rss/maker/entry.rb
deleted file mode 100644
index f8f5469f2c..0000000000
--- a/ruby_2_2/lib/rss/maker/entry.rb
+++ /dev/null
@@ -1,163 +0,0 @@
-require "rss/maker/atom"
-require "rss/maker/feed"
-
-module RSS
- module Maker
- module Atom
- class Entry < RSSBase
- def initialize(feed_version="1.0")
- super
- @feed_type = "atom"
- @feed_subtype = "entry"
- end
-
- private
- def make_feed
- ::RSS::Atom::Entry.new(@version, @encoding, @standalone)
- end
-
- def setup_elements(entry)
- setup_items(entry)
- end
-
- class Channel < ChannelBase
- class SkipDays < SkipDaysBase
- class Day < DayBase
- end
- end
-
- class SkipHours < SkipHoursBase
- class Hour < HourBase
- end
- end
-
- class Cloud < CloudBase
- end
-
- Categories = Feed::Channel::Categories
- Links = Feed::Channel::Links
- Authors = Feed::Channel::Authors
- Contributors = Feed::Channel::Contributors
-
- class Generator < GeneratorBase
- include AtomGenerator
-
- def self.not_set_name
- "maker.channel.generator"
- end
- end
-
- Copyright = Feed::Channel::Copyright
-
- class Description < DescriptionBase
- end
-
- Title = Feed::Channel::Title
- end
-
- class Image < ImageBase
- end
-
- class Items < ItemsBase
- def to_feed(entry)
- (normalize.first || Item.new(@maker)).to_feed(entry)
- end
-
- class Item < ItemBase
- def to_feed(entry)
- set_default_values do
- setup_values(entry)
- entry.dc_dates.clear
- setup_other_elements(entry)
- unless have_required_values?
- raise NotSetError.new("maker.item", not_set_required_variables)
- end
- end
- end
-
- private
- def required_variable_names
- %w(id updated)
- end
-
- def variables
- super + ["updated"]
- end
-
- def variable_is_set?
- super or !authors.empty?
- end
-
- def not_set_required_variables
- set_default_values do
- vars = super
- if authors.all? {|author| !author.have_required_values?}
- vars << "author"
- end
- vars << "title" unless title {|t| t.have_required_values?}
- vars
- end
- end
-
- def _set_default_values
- keep = {
- :authors => authors.to_a.dup,
- :contributors => contributors.to_a.dup,
- :categories => categories.to_a.dup,
- :id => id,
- :links => links.to_a.dup,
- :rights => @rights,
- :title => @title,
- :updated => updated,
- }
- authors.replace(@maker.channel.authors) if keep[:authors].empty?
- if keep[:contributors].empty?
- contributors.replace(@maker.channel.contributors)
- end
- if keep[:categories].empty?
- categories.replace(@maker.channel.categories)
- end
- self.id ||= link || @maker.channel.id
- links.replace(@maker.channel.links) if keep[:links].empty?
- unless keep[:rights].variable_is_set?
- @maker.channel.rights {|r| @rights = r}
- end
- unless keep[:title].variable_is_set?
- @maker.channel.title {|t| @title = t}
- end
- self.updated ||= @maker.channel.updated
- super
- ensure
- authors.replace(keep[:authors])
- contributors.replace(keep[:contributors])
- categories.replace(keep[:categories])
- links.replace(keep[:links])
- self.id = keep[:id]
- @rights = keep[:rights]
- @title = keep[:title]
- self.updated = keep[:updated]
- end
-
- Guid = Feed::Items::Item::Guid
- Enclosure = Feed::Items::Item::Enclosure
- Source = Feed::Items::Item::Source
- Categories = Feed::Items::Item::Categories
- Authors = Feed::Items::Item::Authors
- Contributors = Feed::Items::Item::Contributors
- Links = Feed::Items::Item::Links
- Rights = Feed::Items::Item::Rights
- Description = Feed::Items::Item::Description
- Title = Feed::Items::Item::Title
- Content = Feed::Items::Item::Content
- end
- end
-
- class Textinput < TextinputBase
- end
- end
- end
-
- add_maker("atom:entry", "1.0", Atom::Entry)
- add_maker("atom1.0:entry", "1.0", Atom::Entry)
- end
-end
diff --git a/ruby_2_2/lib/rss/maker/feed.rb b/ruby_2_2/lib/rss/maker/feed.rb
deleted file mode 100644
index 0129218b0c..0000000000
--- a/ruby_2_2/lib/rss/maker/feed.rb
+++ /dev/null
@@ -1,426 +0,0 @@
-require "rss/maker/atom"
-
-module RSS
- module Maker
- module Atom
- class Feed < RSSBase
- def initialize(feed_version="1.0")
- super
- @feed_type = "atom"
- @feed_subtype = "feed"
- end
-
- private
- def make_feed
- ::RSS::Atom::Feed.new(@version, @encoding, @standalone)
- end
-
- def setup_elements(feed)
- setup_channel(feed)
- setup_image(feed)
- setup_items(feed)
- end
-
- class Channel < ChannelBase
- include SetupDefaultLanguage
-
- def to_feed(feed)
- set_default_values do
- setup_values(feed)
- feed.dc_dates.clear
- setup_other_elements(feed)
- if image_favicon.about
- icon = feed.class::Icon.new
- icon.content = image_favicon.about
- feed.icon = icon
- end
- unless have_required_values?
- raise NotSetError.new("maker.channel",
- not_set_required_variables)
- end
- end
- end
-
- def have_required_values?
- super and
- (!authors.empty? or
- @maker.items.any? {|item| !item.authors.empty?})
- end
-
- private
- def required_variable_names
- %w(id updated)
- end
-
- def variables
- super + %w(id updated)
- end
-
- def variable_is_set?
- super or !authors.empty?
- end
-
- def not_set_required_variables
- vars = super
- if authors.empty? and
- @maker.items.all? {|item| item.author.to_s.empty?}
- vars << "author"
- end
- vars << "title" unless title {|t| t.have_required_values?}
- vars
- end
-
- def _set_default_values(&block)
- keep = {
- :id => id,
- }
- self.id ||= about
- super(&block)
- ensure
- self.id = keep[:id]
- end
-
- class SkipDays < SkipDaysBase
- def to_feed(*args)
- end
-
- class Day < DayBase
- end
- end
-
- class SkipHours < SkipHoursBase
- def to_feed(*args)
- end
-
- class Hour < HourBase
- end
- end
-
- class Cloud < CloudBase
- def to_feed(*args)
- end
- end
-
- class Categories < CategoriesBase
- class Category < CategoryBase
- include AtomCategory
-
- def self.not_set_name
- "maker.channel.category"
- end
- end
- end
-
- class Links < LinksBase
- class Link < LinkBase
- include AtomLink
-
- def self.not_set_name
- "maker.channel.link"
- end
- end
- end
-
- AtomPersons.def_atom_persons(self, "author", "maker.channel.author")
- AtomPersons.def_atom_persons(self, "contributor",
- "maker.channel.contributor")
-
- class Generator < GeneratorBase
- include AtomGenerator
-
- def self.not_set_name
- "maker.channel.generator"
- end
- end
-
- AtomTextConstruct.def_atom_text_construct(self, "rights",
- "maker.channel.copyright",
- "Copyright")
- AtomTextConstruct.def_atom_text_construct(self, "subtitle",
- "maker.channel.description",
- "Description")
- AtomTextConstruct.def_atom_text_construct(self, "title",
- "maker.channel.title")
- end
-
- class Image < ImageBase
- def to_feed(feed)
- logo = feed.class::Logo.new
- class << logo
- alias_method(:url=, :content=)
- end
- set = setup_values(logo)
- class << logo
- remove_method(:url=)
- end
- if set
- feed.logo = logo
- set_parent(logo, feed)
- setup_other_elements(feed, logo)
- elsif variable_is_set?
- raise NotSetError.new("maker.image", not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(url)
- end
- end
-
- class Items < ItemsBase
- def to_feed(feed)
- normalize.each do |item|
- item.to_feed(feed)
- end
- setup_other_elements(feed, feed.entries)
- end
-
- class Item < ItemBase
- def to_feed(feed)
- set_default_values do
- entry = feed.class::Entry.new
- set = setup_values(entry)
- entry.dc_dates.clear
- setup_other_elements(feed, entry)
- if set
- feed.entries << entry
- set_parent(entry, feed)
- elsif variable_is_set?
- raise NotSetError.new("maker.item", not_set_required_variables)
- end
- end
- end
-
- def have_required_values?
- set_default_values do
- super and title {|t| t.have_required_values?}
- end
- end
-
- private
- def required_variable_names
- %w(id updated)
- end
-
- def variables
- super + ["updated"]
- end
-
- def not_set_required_variables
- vars = super
- vars << "title" unless title {|t| t.have_required_values?}
- vars
- end
-
- def _set_default_values(&block)
- keep = {
- :id => id,
- }
- self.id ||= link
- super(&block)
- ensure
- self.id = keep[:id]
- end
-
- class Guid < GuidBase
- def to_feed(feed, current)
- end
- end
-
- class Enclosure < EnclosureBase
- def to_feed(feed, current)
- end
- end
-
- class Source < SourceBase
- def to_feed(feed, current)
- source = current.class::Source.new
- setup_values(source)
- current.source = source
- set_parent(source, current)
- setup_other_elements(feed, source)
- current.source = nil if source.to_s == "<source/>"
- end
-
- private
- def required_variable_names
- []
- end
-
- def variables
- super + ["updated"]
- end
-
- AtomPersons.def_atom_persons(self, "author",
- "maker.item.source.author")
- AtomPersons.def_atom_persons(self, "contributor",
- "maker.item.source.contributor")
-
- class Categories < CategoriesBase
- class Category < CategoryBase
- include AtomCategory
-
- def self.not_set_name
- "maker.item.source.category"
- end
- end
- end
-
- class Generator < GeneratorBase
- include AtomGenerator
-
- def self.not_set_name
- "maker.item.source.generator"
- end
- end
-
- class Icon < IconBase
- def to_feed(feed, current)
- icon = current.class::Icon.new
- class << icon
- alias_method(:url=, :content=)
- end
- set = setup_values(icon)
- class << icon
- remove_method(:url=)
- end
- if set
- current.icon = icon
- set_parent(icon, current)
- setup_other_elements(feed, icon)
- elsif variable_is_set?
- raise NotSetError.new("maker.item.source.icon",
- not_set_required_variables)
- end
- end
-
- private
- def required_variable_names
- %w(url)
- end
- end
-
- class Links < LinksBase
- class Link < LinkBase
- include AtomLink
-
- def self.not_set_name
- "maker.item.source.link"
- end
- end
- end
-
- class Logo < LogoBase
- include AtomLogo
-
- def self.not_set_name
- "maker.item.source.logo"
- end
- end
-
- maker_name_base = "maker.item.source."
- maker_name = "#{maker_name_base}rights"
- AtomTextConstruct.def_atom_text_construct(self, "rights",
- maker_name)
- maker_name = "#{maker_name_base}subtitle"
- AtomTextConstruct.def_atom_text_construct(self, "subtitle",
- maker_name)
- maker_name = "#{maker_name_base}title"
- AtomTextConstruct.def_atom_text_construct(self, "title",
- maker_name)
- end
-
- class Categories < CategoriesBase
- class Category < CategoryBase
- include AtomCategory
-
- def self.not_set_name
- "maker.item.category"
- end
- end
- end
-
- AtomPersons.def_atom_persons(self, "author", "maker.item.author")
- AtomPersons.def_atom_persons(self, "contributor",
- "maker.item.contributor")
-
- class Links < LinksBase
- class Link < LinkBase
- include AtomLink
-
- def self.not_set_name
- "maker.item.link"
- end
- end
- end
-
- AtomTextConstruct.def_atom_text_construct(self, "rights",
- "maker.item.rights")
- AtomTextConstruct.def_atom_text_construct(self, "summary",
- "maker.item.description",
- "Description")
- AtomTextConstruct.def_atom_text_construct(self, "title",
- "maker.item.title")
-
- class Content < ContentBase
- def to_feed(feed, current)
- content = current.class::Content.new
- if setup_values(content)
- content.src = nil if content.src and content.content
- current.content = content
- set_parent(content, current)
- setup_other_elements(feed, content)
- elsif variable_is_set?
- raise NotSetError.new("maker.item.content",
- not_set_required_variables)
- end
- end
-
- alias_method(:xml, :xml_content)
-
- private
- def required_variable_names
- if out_of_line?
- %w(type)
- elsif xml_type?
- %w(xml_content)
- else
- %w(content)
- end
- end
-
- def variables
- if out_of_line?
- super
- elsif xml_type?
- super + %w(xml)
- else
- super
- end
- end
-
- def xml_type?
- _type = type
- return false if _type.nil?
- _type == "xhtml" or
- /(?:\+xml|\/xml)$/i =~ _type or
- %w(text/xml-external-parsed-entity
- application/xml-external-parsed-entity
- application/xml-dtd).include?(_type.downcase)
- end
- end
- end
- end
-
- class Textinput < TextinputBase
- end
- end
- end
-
- add_maker("atom", "1.0", Atom::Feed)
- add_maker("atom:feed", "1.0", Atom::Feed)
- add_maker("atom1.0", "1.0", Atom::Feed)
- add_maker("atom1.0:feed", "1.0", Atom::Feed)
- end
-end
diff --git a/ruby_2_2/lib/rss/maker/image.rb b/ruby_2_2/lib/rss/maker/image.rb
deleted file mode 100644
index 06084b4af4..0000000000
--- a/ruby_2_2/lib/rss/maker/image.rb
+++ /dev/null
@@ -1,111 +0,0 @@
-require 'rss/image'
-require 'rss/maker/1.0'
-require 'rss/maker/dublincore'
-
-module RSS
- module Maker
- module ImageItemModel
- def self.append_features(klass)
- super
-
- name = "#{RSS::IMAGE_PREFIX}_item"
- klass.def_classed_element(name)
- end
-
- def self.install_image_item(klass)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class ImageItem < ImageItemBase
- DublinCoreModel.install_dublin_core(self)
- end
-EOC
- end
-
- class ImageItemBase < Base
- include Maker::DublinCoreModel
-
- attr_accessor :about, :resource, :image_width, :image_height
- add_need_initialize_variable("about")
- add_need_initialize_variable("resource")
- add_need_initialize_variable("image_width")
- add_need_initialize_variable("image_height")
- alias width= image_width=
- alias width image_width
- alias height= image_height=
- alias height image_height
-
- def have_required_values?
- @about
- end
-
- def to_feed(feed, current)
- if current.respond_to?(:image_item=) and have_required_values?
- item = current.class::ImageItem.new
- setup_values(item)
- setup_other_elements(item)
- current.image_item = item
- end
- end
- end
- end
-
- module ImageFaviconModel
- def self.append_features(klass)
- super
-
- name = "#{RSS::IMAGE_PREFIX}_favicon"
- klass.def_classed_element(name)
- end
-
- def self.install_image_favicon(klass)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class ImageFavicon < ImageFaviconBase
- DublinCoreModel.install_dublin_core(self)
- end
- EOC
- end
-
- class ImageFaviconBase < Base
- include Maker::DublinCoreModel
-
- attr_accessor :about, :image_size
- add_need_initialize_variable("about")
- add_need_initialize_variable("image_size")
- alias size image_size
- alias size= image_size=
-
- def have_required_values?
- @about and @image_size
- end
-
- def to_feed(feed, current)
- if current.respond_to?(:image_favicon=) and have_required_values?
- favicon = current.class::ImageFavicon.new
- setup_values(favicon)
- setup_other_elements(favicon)
- current.image_favicon = favicon
- end
- end
- end
- end
-
- class ChannelBase; include Maker::ImageFaviconModel; end
-
- class ItemsBase
- class ItemBase; include Maker::ImageItemModel; end
- end
-
- makers.each do |maker|
- maker.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class Channel
- ImageFaviconModel.install_image_favicon(self)
- end
-
- class Items
- class Item
- ImageItemModel.install_image_item(self)
- end
- end
- EOC
- end
- end
-end
diff --git a/ruby_2_2/lib/rss/maker/itunes.rb b/ruby_2_2/lib/rss/maker/itunes.rb
deleted file mode 100644
index 8b7420da3c..0000000000
--- a/ruby_2_2/lib/rss/maker/itunes.rb
+++ /dev/null
@@ -1,242 +0,0 @@
-require 'rss/itunes'
-require 'rss/maker/2.0'
-
-module RSS
- module Maker
- module ITunesBaseModel
- def def_class_accessor(klass, name, type, *args)
- name = name.gsub(/-/, "_").gsub(/^itunes_/, '')
- full_name = "#{RSS::ITUNES_PREFIX}_#{name}"
- case type
- when nil
- klass.def_other_element(full_name)
- when :yes_other
- def_yes_other_accessor(klass, full_name)
- when :yes_clean_other
- def_yes_clean_other_accessor(klass, full_name)
- when :csv
- def_csv_accessor(klass, full_name)
- when :element, :attribute
- recommended_attribute_name, = *args
- klass_name = "ITunes#{Utils.to_class_name(name)}"
- klass.def_classed_element(full_name, klass_name,
- recommended_attribute_name)
- when :elements
- plural_name, recommended_attribute_name = args
- plural_name ||= "#{name}s"
- full_plural_name = "#{RSS::ITUNES_PREFIX}_#{plural_name}"
- klass_name = "ITunes#{Utils.to_class_name(name)}"
- plural_klass_name = "ITunes#{Utils.to_class_name(plural_name)}"
- def_elements_class_accessor(klass, name, full_name, full_plural_name,
- klass_name, plural_klass_name,
- recommended_attribute_name)
- end
- end
-
- def def_yes_other_accessor(klass, full_name)
- klass.def_other_element(full_name)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{full_name}?
- Utils::YesOther.parse(@#{full_name})
- end
- EOC
- end
-
- def def_yes_clean_other_accessor(klass, full_name)
- klass.def_other_element(full_name)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{full_name}?
- Utils::YesCleanOther.parse(#{full_name})
- end
- EOC
- end
-
- def def_csv_accessor(klass, full_name)
- klass.def_csv_element(full_name)
- end
-
- def def_elements_class_accessor(klass, name, full_name, full_plural_name,
- klass_name, plural_klass_name,
- recommended_attribute_name=nil)
- if recommended_attribute_name
- klass.def_classed_elements(full_name, recommended_attribute_name,
- plural_klass_name, full_plural_name)
- else
- klass.def_classed_element(full_plural_name, plural_klass_name)
- end
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def new_#{full_name}(text=nil)
- #{full_name} = @#{full_plural_name}.new_#{name}
- #{full_name}.text = text
- if block_given?
- yield #{full_name}
- else
- #{full_name}
- end
- end
- EOC
- end
- end
-
- module ITunesChannelModel
- extend ITunesBaseModel
-
- class << self
- def append_features(klass)
- super
-
- ::RSS::ITunesChannelModel::ELEMENT_INFOS.each do |name, type, *args|
- def_class_accessor(klass, name, type, *args)
- end
- end
- end
-
- class ITunesCategoriesBase < Base
- def_array_element("category", "itunes_categories",
- "ITunesCategory")
- class ITunesCategoryBase < Base
- attr_accessor :text
- add_need_initialize_variable("text")
- def_array_element("category", "itunes_categories",
- "ITunesCategory")
-
- def have_required_values?
- text
- end
-
- alias_method :to_feed_for_categories, :to_feed
- def to_feed(feed, current)
- if text and current.respond_to?(:itunes_category)
- new_item = current.class::ITunesCategory.new(text)
- to_feed_for_categories(feed, new_item)
- current.itunes_categories << new_item
- end
- end
- end
- end
-
- class ITunesImageBase < Base
- add_need_initialize_variable("href")
- attr_accessor("href")
-
- def to_feed(feed, current)
- if @href and current.respond_to?(:itunes_image)
- current.itunes_image ||= current.class::ITunesImage.new
- current.itunes_image.href = @href
- end
- end
- end
-
- class ITunesOwnerBase < Base
- %w(itunes_name itunes_email).each do |name|
- add_need_initialize_variable(name)
- attr_accessor(name)
- end
-
- def to_feed(feed, current)
- if current.respond_to?(:itunes_owner=)
- _not_set_required_variables = not_set_required_variables
- if (required_variable_names - _not_set_required_variables).empty?
- return
- end
-
- unless have_required_values?
- raise NotSetError.new("maker.channel.itunes_owner",
- _not_set_required_variables)
- end
- current.itunes_owner ||= current.class::ITunesOwner.new
- current.itunes_owner.itunes_name = @itunes_name
- current.itunes_owner.itunes_email = @itunes_email
- end
- end
-
- private
- def required_variable_names
- %w(itunes_name itunes_email)
- end
- end
- end
-
- module ITunesItemModel
- extend ITunesBaseModel
-
- class << self
- def append_features(klass)
- super
-
- ::RSS::ITunesItemModel::ELEMENT_INFOS.each do |name, type, *args|
- def_class_accessor(klass, name, type, *args)
- end
- end
- end
-
- class ITunesDurationBase < Base
- attr_reader :content
- add_need_initialize_variable("content")
-
- %w(hour minute second).each do |name|
- attr_reader(name)
- add_need_initialize_variable(name, 0)
- end
-
- def content=(content)
- if content.nil?
- @hour, @minute, @second, @content = nil
- else
- @hour, @minute, @second =
- ::RSS::ITunesItemModel::ITunesDuration.parse(content)
- @content = content
- end
- end
-
- def hour=(hour)
- @hour = Integer(hour)
- update_content
- end
-
- def minute=(minute)
- @minute = Integer(minute)
- update_content
- end
-
- def second=(second)
- @second = Integer(second)
- update_content
- end
-
- def to_feed(feed, current)
- if @content and current.respond_to?(:itunes_duration=)
- current.itunes_duration ||= current.class::ITunesDuration.new
- current.itunes_duration.content = @content
- end
- end
-
- private
- def update_content
- components = [@hour, @minute, @second]
- @content =
- ::RSS::ITunesItemModel::ITunesDuration.construct(*components)
- end
- end
- end
-
- class ChannelBase
- include Maker::ITunesChannelModel
- class ITunesCategories < ITunesCategoriesBase
- class ITunesCategory < ITunesCategoryBase
- ITunesCategory = self
- end
- end
-
- class ITunesImage < ITunesImageBase; end
- class ITunesOwner < ITunesOwnerBase; end
- end
-
- class ItemsBase
- class ItemBase
- include Maker::ITunesItemModel
- class ITunesDuration < ITunesDurationBase; end
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rss/maker/slash.rb b/ruby_2_2/lib/rss/maker/slash.rb
deleted file mode 100644
index 27adef3832..0000000000
--- a/ruby_2_2/lib/rss/maker/slash.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-require 'rss/slash'
-require 'rss/maker/1.0'
-
-module RSS
- module Maker
- module SlashModel
- def self.append_features(klass)
- super
-
- ::RSS::SlashModel::ELEMENT_INFOS.each do |name, type|
- full_name = "#{RSS::SLASH_PREFIX}_#{name}"
- case type
- when :csv_integer
- klass.def_csv_element(full_name, :integer)
- else
- klass.def_other_element(full_name)
- end
- end
-
- klass.module_eval do
- alias_method(:slash_hit_parades, :slash_hit_parade)
- alias_method(:slash_hit_parades=, :slash_hit_parade=)
- end
- end
- end
-
- class ItemsBase
- class ItemBase
- include SlashModel
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rss/maker/syndication.rb b/ruby_2_2/lib/rss/maker/syndication.rb
deleted file mode 100644
index b81230457c..0000000000
--- a/ruby_2_2/lib/rss/maker/syndication.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require 'rss/syndication'
-require 'rss/maker/1.0'
-
-module RSS
- module Maker
- module SyndicationModel
- def self.append_features(klass)
- super
-
- ::RSS::SyndicationModel::ELEMENTS.each do |name|
- klass.def_other_element(name)
- end
- end
- end
-
- class ChannelBase; include SyndicationModel; end
- end
-end
diff --git a/ruby_2_2/lib/rss/maker/taxonomy.rb b/ruby_2_2/lib/rss/maker/taxonomy.rb
deleted file mode 100644
index 13ae9aa805..0000000000
--- a/ruby_2_2/lib/rss/maker/taxonomy.rb
+++ /dev/null
@@ -1,118 +0,0 @@
-require 'rss/taxonomy'
-require 'rss/maker/1.0'
-require 'rss/maker/dublincore'
-
-module RSS
- module Maker
- module TaxonomyTopicsModel
- def self.append_features(klass)
- super
-
- klass.def_classed_element("#{RSS::TAXO_PREFIX}_topics",
- "TaxonomyTopics")
- end
-
- def self.install_taxo_topics(klass)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class TaxonomyTopics < TaxonomyTopicsBase
- def to_feed(feed, current)
- if current.respond_to?(:taxo_topics)
- topics = current.class::TaxonomyTopics.new
- bag = topics.Bag
- @resources.each do |resource|
- bag.lis << RDF::Bag::Li.new(resource)
- end
- current.taxo_topics = topics
- end
- end
- end
-EOC
- end
-
- class TaxonomyTopicsBase < Base
- attr_reader :resources
- def_array_element("resource")
- remove_method :new_resource
- end
- end
-
- module TaxonomyTopicModel
- def self.append_features(klass)
- super
-
- class_name = "TaxonomyTopics"
- klass.def_classed_elements("#{TAXO_PREFIX}_topic", "value", class_name)
- end
-
- def self.install_taxo_topic(klass)
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class TaxonomyTopics < TaxonomyTopicsBase
- class TaxonomyTopic < TaxonomyTopicBase
- DublinCoreModel.install_dublin_core(self)
- TaxonomyTopicsModel.install_taxo_topics(self)
-
- def to_feed(feed, current)
- if current.respond_to?(:taxo_topics)
- topic = current.class::TaxonomyTopic.new(value)
- topic.taxo_link = value
- taxo_topics.to_feed(feed, topic) if taxo_topics
- current.taxo_topics << topic
- setup_other_elements(feed, topic)
- end
- end
- end
- end
-EOC
- end
-
- class TaxonomyTopicsBase < Base
- def_array_element("topic", nil, "TaxonomyTopic")
- alias_method(:new_taxo_topic, :new_topic) # For backward compatibility
-
- class TaxonomyTopicBase < Base
- include DublinCoreModel
- include TaxonomyTopicsModel
-
- attr_accessor :value
- add_need_initialize_variable("value")
- alias_method(:taxo_link, :value)
- alias_method(:taxo_link=, :value=)
-
- def have_required_values?
- @value
- end
- end
- end
- end
-
- class RSSBase
- include TaxonomyTopicModel
- end
-
- class ChannelBase
- include TaxonomyTopicsModel
- end
-
- class ItemsBase
- class ItemBase
- include TaxonomyTopicsModel
- end
- end
-
- makers.each do |maker|
- maker.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- TaxonomyTopicModel.install_taxo_topic(self)
-
- class Channel
- TaxonomyTopicsModel.install_taxo_topics(self)
- end
-
- class Items
- class Item
- TaxonomyTopicsModel.install_taxo_topics(self)
- end
- end
- EOC
- end
- end
-end
diff --git a/ruby_2_2/lib/rss/maker/trackback.rb b/ruby_2_2/lib/rss/maker/trackback.rb
deleted file mode 100644
index 00f001cb85..0000000000
--- a/ruby_2_2/lib/rss/maker/trackback.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-require 'rss/trackback'
-require 'rss/maker/1.0'
-require 'rss/maker/2.0'
-
-module RSS
- module Maker
- module TrackBackModel
- def self.append_features(klass)
- super
-
- klass.def_other_element("#{RSS::TRACKBACK_PREFIX}_ping")
- klass.def_classed_elements("#{RSS::TRACKBACK_PREFIX}_about", "value",
- "TrackBackAbouts")
- end
-
- class TrackBackAboutsBase < Base
- def_array_element("about", nil, "TrackBackAbout")
-
- class TrackBackAboutBase < Base
- attr_accessor :value
- add_need_initialize_variable("value")
-
- alias_method(:resource, :value)
- alias_method(:resource=, :value=)
- alias_method(:content, :value)
- alias_method(:content=, :value=)
-
- def have_required_values?
- @value
- end
-
- def to_feed(feed, current)
- if current.respond_to?(:trackback_abouts) and have_required_values?
- about = current.class::TrackBackAbout.new
- setup_values(about)
- setup_other_elements(about)
- current.trackback_abouts << about
- end
- end
- end
- end
- end
-
- class ItemsBase
- class ItemBase; include TrackBackModel; end
- end
-
- makers.each do |maker|
- maker.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- class Items
- class Item
- class TrackBackAbouts < TrackBackAboutsBase
- class TrackBackAbout < TrackBackAboutBase
- end
- end
- end
- end
- EOC
- end
- end
-end
diff --git a/ruby_2_2/lib/rss/parser.rb b/ruby_2_2/lib/rss/parser.rb
deleted file mode 100644
index 1b6e4e9596..0000000000
--- a/ruby_2_2/lib/rss/parser.rb
+++ /dev/null
@@ -1,570 +0,0 @@
-require "forwardable"
-require "open-uri"
-
-require "rss/rss"
-require "rss/xml"
-
-module RSS
-
- class NotWellFormedError < Error
- attr_reader :line, :element
-
- # Create a new NotWellFormedError for an error at +line+
- # in +element+. If a block is given the return value of
- # the block ends up in the error message.
- def initialize(line=nil, element=nil)
- message = "This is not well formed XML"
- if element or line
- message << "\nerror occurred"
- message << " in #{element}" if element
- message << " at about #{line} line" if line
- end
- message << "\n#{yield}" if block_given?
- super(message)
- end
- end
-
- class XMLParserNotFound < Error
- def initialize
- super("available XML parser was not found in " <<
- "#{AVAILABLE_PARSER_LIBRARIES.inspect}.")
- end
- end
-
- class NotValidXMLParser < Error
- def initialize(parser)
- super("#{parser} is not an available XML parser. " <<
- "Available XML parser" <<
- (AVAILABLE_PARSERS.size > 1 ? "s are " : " is ") <<
- "#{AVAILABLE_PARSERS.inspect}.")
- end
- end
-
- class NSError < InvalidRSSError
- attr_reader :tag, :prefix, :uri
- def initialize(tag, prefix, require_uri)
- @tag, @prefix, @uri = tag, prefix, require_uri
- super("prefix <#{prefix}> doesn't associate uri " <<
- "<#{require_uri}> in tag <#{tag}>")
- end
- end
-
- class Parser
-
- extend Forwardable
-
- class << self
-
- @@default_parser = nil
-
- def default_parser
- @@default_parser || AVAILABLE_PARSERS.first
- end
-
- # Set @@default_parser to new_value if it is one of the
- # available parsers. Else raise NotValidXMLParser error.
- def default_parser=(new_value)
- if AVAILABLE_PARSERS.include?(new_value)
- @@default_parser = new_value
- else
- raise NotValidXMLParser.new(new_value)
- end
- end
-
- def parse(rss, do_validate=true, ignore_unknown_element=true,
- parser_class=default_parser)
- parser = new(rss, parser_class)
- parser.do_validate = do_validate
- parser.ignore_unknown_element = ignore_unknown_element
- parser.parse
- end
- end
-
- def_delegators(:@parser, :parse, :rss,
- :ignore_unknown_element,
- :ignore_unknown_element=, :do_validate,
- :do_validate=)
-
- def initialize(rss, parser_class=self.class.default_parser)
- @parser = parser_class.new(normalize_rss(rss))
- end
-
- private
-
- # Try to get the XML associated with +rss+.
- # Return +rss+ if it already looks like XML, or treat it as a URI,
- # or a file to get the XML,
- def normalize_rss(rss)
- return rss if maybe_xml?(rss)
-
- uri = to_uri(rss)
-
- if uri.respond_to?(:read)
- uri.read
- elsif !rss.tainted? and File.readable?(rss)
- File.open(rss) {|f| f.read}
- else
- rss
- end
- end
-
- # maybe_xml? tests if source is a string that looks like XML.
- def maybe_xml?(source)
- source.is_a?(String) and /</ =~ source
- end
-
- # Attempt to convert rss to a URI, but just return it if
- # there's a ::URI::Error
- def to_uri(rss)
- return rss if rss.is_a?(::URI::Generic)
-
- begin
- ::URI.parse(rss)
- rescue ::URI::Error
- rss
- end
- end
- end
-
- class BaseParser
-
- class << self
- def raise_for_undefined_entity?
- listener.raise_for_undefined_entity?
- end
- end
-
- def initialize(rss)
- @listener = self.class.listener.new
- @rss = rss
- end
-
- def rss
- @listener.rss
- end
-
- def ignore_unknown_element
- @listener.ignore_unknown_element
- end
-
- def ignore_unknown_element=(new_value)
- @listener.ignore_unknown_element = new_value
- end
-
- def do_validate
- @listener.do_validate
- end
-
- def do_validate=(new_value)
- @listener.do_validate = new_value
- end
-
- def parse
- if @listener.rss.nil?
- _parse
- end
- @listener.rss
- end
-
- end
-
- class BaseListener
-
- extend Utils
-
- class << self
-
- @@accessor_bases = {}
- @@registered_uris = {}
- @@class_names = {}
-
- # return the setter for the uri, tag_name pair, or nil.
- def setter(uri, tag_name)
- _getter = getter(uri, tag_name)
- if _getter
- "#{_getter}="
- else
- nil
- end
- end
-
- def getter(uri, tag_name)
- (@@accessor_bases[uri] || {})[tag_name]
- end
-
- # return the tag_names for setters associated with uri
- def available_tags(uri)
- (@@accessor_bases[uri] || {}).keys
- end
-
- # register uri against this name.
- def register_uri(uri, name)
- @@registered_uris[name] ||= {}
- @@registered_uris[name][uri] = nil
- end
-
- # test if this uri is registered against this name
- def uri_registered?(uri, name)
- @@registered_uris[name].has_key?(uri)
- end
-
- # record class_name for the supplied uri and tag_name
- def install_class_name(uri, tag_name, class_name)
- @@class_names[uri] ||= {}
- @@class_names[uri][tag_name] = class_name
- end
-
- # retrieve class_name for the supplied uri and tag_name
- # If it doesn't exist, capitalize the tag_name
- def class_name(uri, tag_name)
- name = (@@class_names[uri] || {})[tag_name]
- return name if name
-
- tag_name = tag_name.gsub(/[_\-]([a-z]?)/) {$1.upcase}
- tag_name[0, 1].upcase + tag_name[1..-1]
- end
-
- def install_get_text_element(uri, name, accessor_base)
- install_accessor_base(uri, name, accessor_base)
- def_get_text_element(uri, name, *get_file_and_line_from_caller(1))
- end
-
- def raise_for_undefined_entity?
- true
- end
-
- private
- # set the accessor for the uri, tag_name pair
- def install_accessor_base(uri, tag_name, accessor_base)
- @@accessor_bases[uri] ||= {}
- @@accessor_bases[uri][tag_name] = accessor_base.chomp("=")
- end
-
- def def_get_text_element(uri, element_name, file, line)
- register_uri(uri, element_name)
- method_name = "start_#{element_name}"
- unless private_method_defined?(method_name)
- define_method(method_name) do |name, prefix, attrs, ns|
- uri = _ns(ns, prefix)
- if self.class.uri_registered?(uri, element_name)
- start_get_text_element(name, prefix, ns, uri)
- else
- start_else_element(name, prefix, attrs, ns)
- end
- end
- private(method_name)
- end
- end
- end
- end
-
- module ListenerMixin
- attr_reader :rss
-
- attr_accessor :ignore_unknown_element
- attr_accessor :do_validate
-
- def initialize
- @rss = nil
- @ignore_unknown_element = true
- @do_validate = true
- @ns_stack = [{"xml" => :xml}]
- @tag_stack = [[]]
- @text_stack = ['']
- @proc_stack = []
- @last_element = nil
- @version = @encoding = @standalone = nil
- @xml_stylesheets = []
- @xml_child_mode = false
- @xml_element = nil
- @last_xml_element = nil
- end
-
- # set instance vars for version, encoding, standalone
- def xmldecl(version, encoding, standalone)
- @version, @encoding, @standalone = version, encoding, standalone
- end
-
- def instruction(name, content)
- if name == "xml-stylesheet"
- params = parse_pi_content(content)
- if params.has_key?("href")
- @xml_stylesheets << XMLStyleSheet.new(params)
- end
- end
- end
-
- def tag_start(name, attributes)
- @text_stack.push('')
-
- ns = @ns_stack.last.dup
- attrs = {}
- attributes.each do |n, v|
- if /\Axmlns(?:\z|:)/ =~ n
- ns[$POSTMATCH] = v
- else
- attrs[n] = v
- end
- end
- @ns_stack.push(ns)
-
- prefix, local = split_name(name)
- @tag_stack.last.push([_ns(ns, prefix), local])
- @tag_stack.push([])
- if @xml_child_mode
- previous = @last_xml_element
- element_attrs = attributes.dup
- unless previous
- ns.each do |ns_prefix, value|
- next if ns_prefix == "xml"
- key = ns_prefix.empty? ? "xmlns" : "xmlns:#{ns_prefix}"
- element_attrs[key] ||= value
- end
- end
- next_element = XML::Element.new(local,
- prefix.empty? ? nil : prefix,
- _ns(ns, prefix),
- element_attrs)
- previous << next_element if previous
- @last_xml_element = next_element
- pr = Proc.new do |text, tags|
- if previous
- @last_xml_element = previous
- else
- @xml_element = @last_xml_element
- @last_xml_element = nil
- end
- end
- @proc_stack.push(pr)
- else
- if @rss.nil? and respond_to?("initial_start_#{local}", true)
- __send__("initial_start_#{local}", local, prefix, attrs, ns.dup)
- elsif respond_to?("start_#{local}", true)
- __send__("start_#{local}", local, prefix, attrs, ns.dup)
- else
- start_else_element(local, prefix, attrs, ns.dup)
- end
- end
- end
-
- def tag_end(name)
- if DEBUG
- p "end tag #{name}"
- p @tag_stack
- end
- text = @text_stack.pop
- tags = @tag_stack.pop
- pr = @proc_stack.pop
- pr.call(text, tags) unless pr.nil?
- @ns_stack.pop
- end
-
- def text(data)
- if @xml_child_mode
- @last_xml_element << data if @last_xml_element
- else
- @text_stack.last << data
- end
- end
-
- private
- def _ns(ns, prefix)
- ns.fetch(prefix, "")
- end
-
- CONTENT_PATTERN = /\s*([^=]+)=(["'])([^\2]+?)\2/
- # Extract the first name="value" pair from content.
- # Works with single quotes according to the constant
- # CONTENT_PATTERN. Return a Hash.
- def parse_pi_content(content)
- params = {}
- content.scan(CONTENT_PATTERN) do |name, quote, value|
- params[name] = value
- end
- params
- end
-
- def start_else_element(local, prefix, attrs, ns)
- class_name = self.class.class_name(_ns(ns, prefix), local)
- current_class = @last_element.class
- if known_class?(current_class, class_name)
- next_class = current_class.const_get(class_name)
- start_have_something_element(local, prefix, attrs, ns, next_class)
- else
- if !@do_validate or @ignore_unknown_element
- @proc_stack.push(setup_next_element_in_unknown_element)
- else
- parent = "ROOT ELEMENT???"
- if current_class.tag_name
- parent = current_class.tag_name
- end
- raise NotExpectedTagError.new(local, _ns(ns, prefix), parent)
- end
- end
- end
-
- if Module.method(:const_defined?).arity == -1
- def known_class?(target_class, class_name)
- class_name and
- (target_class.const_defined?(class_name, false) or
- target_class.constants.include?(class_name.to_sym))
- end
- else
- def known_class?(target_class, class_name)
- class_name and
- (target_class.const_defined?(class_name) or
- target_class.constants.include?(class_name))
- end
- end
-
- NAMESPLIT = /^(?:([\w:][-\w.]*):)?([\w:][-\w.]*)/
- def split_name(name)
- name =~ NAMESPLIT
- [$1 || '', $2]
- end
-
- def check_ns(tag_name, prefix, ns, require_uri, ignore_unknown_element=nil)
- if _ns(ns, prefix) == require_uri
- true
- else
- if ignore_unknown_element.nil?
- ignore_unknown_element = @ignore_unknown_element
- end
-
- if ignore_unknown_element
- false
- elsif @do_validate
- raise NSError.new(tag_name, prefix, require_uri)
- else
- # Force bind required URI with prefix
- @ns_stack.last[prefix] = require_uri
- true
- end
- end
- end
-
- def start_get_text_element(tag_name, prefix, ns, required_uri)
- pr = Proc.new do |text, tags|
- setter = self.class.setter(required_uri, tag_name)
- if setter and @last_element.respond_to?(setter)
- if @do_validate
- getter = self.class.getter(required_uri, tag_name)
- if @last_element.__send__(getter)
- raise TooMuchTagError.new(tag_name, @last_element.tag_name)
- end
- end
- @last_element.__send__(setter, text.to_s)
- else
- if @do_validate and !@ignore_unknown_element
- raise NotExpectedTagError.new(tag_name, _ns(ns, prefix),
- @last_element.tag_name)
- end
- end
- end
- @proc_stack.push(pr)
- end
-
- def start_have_something_element(tag_name, prefix, attrs, ns, klass)
- if check_ns(tag_name, prefix, ns, klass.required_uri)
- attributes = collect_attributes(tag_name, prefix, attrs, ns, klass)
- @proc_stack.push(setup_next_element(tag_name, klass, attributes))
- else
- @proc_stack.push(setup_next_element_in_unknown_element)
- end
- end
-
- def collect_attributes(tag_name, prefix, attrs, ns, klass)
- attributes = {}
- klass.get_attributes.each do |a_name, a_uri, required, element_name|
- if a_uri.is_a?(String) or !a_uri.respond_to?(:include?)
- a_uri = [a_uri]
- end
- unless a_uri == [""]
- for prefix, uri in ns
- if a_uri.include?(uri)
- val = attrs["#{prefix}:#{a_name}"]
- break if val
- end
- end
- end
- if val.nil? and a_uri.include?("")
- val = attrs[a_name]
- end
-
- if @do_validate and required and val.nil?
- unless a_uri.include?("")
- for prefix, uri in ns
- if a_uri.include?(uri)
- a_name = "#{prefix}:#{a_name}"
- end
- end
- end
- raise MissingAttributeError.new(tag_name, a_name)
- end
-
- attributes[a_name] = val
- end
- attributes
- end
-
- def setup_next_element(tag_name, klass, attributes)
- previous = @last_element
- next_element = klass.new(@do_validate, attributes)
- previous.set_next_element(tag_name, next_element)
- @last_element = next_element
- @last_element.parent = previous if klass.need_parent?
- @xml_child_mode = @last_element.have_xml_content?
-
- Proc.new do |text, tags|
- p(@last_element.class) if DEBUG
- if @xml_child_mode
- @last_element.content = @xml_element.to_s
- xml_setter = @last_element.class.xml_setter
- @last_element.__send__(xml_setter, @xml_element)
- @xml_element = nil
- @xml_child_mode = false
- else
- if klass.have_content?
- if @last_element.need_base64_encode?
- text = text.lstrip.unpack("m").first
- end
- @last_element.content = text
- end
- end
- if @do_validate
- @last_element.validate_for_stream(tags, @ignore_unknown_element)
- end
- @last_element = previous
- end
- end
-
- def setup_next_element_in_unknown_element
- current_element, @last_element = @last_element, nil
- Proc.new {@last_element = current_element}
- end
- end
-
- unless const_defined? :AVAILABLE_PARSER_LIBRARIES
- # The list of all available libraries for parsing.
- AVAILABLE_PARSER_LIBRARIES = [
- ["rss/xmlparser", :XMLParserParser],
- ["rss/xmlscanner", :XMLScanParser],
- ["rss/rexmlparser", :REXMLParser],
- ]
- end
-
- # The list of all available parsers, in constant form.
- AVAILABLE_PARSERS = []
-
- AVAILABLE_PARSER_LIBRARIES.each do |lib, parser|
- begin
- require lib
- AVAILABLE_PARSERS.push(const_get(parser))
- rescue LoadError
- end
- end
-
- if AVAILABLE_PARSERS.empty?
- raise XMLParserNotFound
- end
-end
diff --git a/ruby_2_2/lib/rss/rexmlparser.rb b/ruby_2_2/lib/rss/rexmlparser.rb
deleted file mode 100644
index a5a2a2edbe..0000000000
--- a/ruby_2_2/lib/rss/rexmlparser.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-require "rexml/document"
-require "rexml/streamlistener"
-
-module RSS
-
- class REXMLParser < BaseParser
-
- class << self
- def listener
- REXMLListener
- end
- end
-
- private
- def _parse
- begin
- REXML::Document.parse_stream(@rss, @listener)
- rescue RuntimeError => e
- raise NotWellFormedError.new{e.message}
- rescue REXML::ParseException => e
- context = e.context
- line = context[0] if context
- raise NotWellFormedError.new(line){e.message}
- end
- end
-
- end
-
- class REXMLListener < BaseListener
-
- include REXML::StreamListener
- include ListenerMixin
-
- class << self
- def raise_for_undefined_entity?
- false
- end
- end
-
- def xmldecl(version, encoding, standalone)
- super(version, encoding, standalone == "yes")
- # Encoding is converted to UTF-8 when REXML parse XML.
- @encoding = 'UTF-8'
- end
-
- alias_method(:cdata, :text)
- end
-
-end
diff --git a/ruby_2_2/lib/rss/rss.rb b/ruby_2_2/lib/rss/rss.rb
deleted file mode 100644
index dbea3b5344..0000000000
--- a/ruby_2_2/lib/rss/rss.rb
+++ /dev/null
@@ -1,1352 +0,0 @@
-require "time"
-
-class Time
- class << self
- unless respond_to?(:w3cdtf)
- # This method converts a W3CDTF string date/time format to Time object.
- #
- # The W3CDTF format is defined here: http://www.w3.org/TR/NOTE-datetime
- #
- # Time.w3cdtf('2003-02-15T13:50:05-05:00')
- # # => 2003-02-15 10:50:05 -0800
- # Time.w3cdtf('2003-02-15T13:50:05-05:00').class
- # # => Time
- def w3cdtf(date)
- if /\A\s*
- (-?\d+)-(\d\d)-(\d\d)
- (?:T
- (\d\d):(\d\d)(?::(\d\d))?
- (\.\d+)?
- (Z|[+-]\d\d:\d\d)?)?
- \s*\z/ix =~ date and (($5 and $8) or (!$5 and !$8))
- datetime = [$1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i]
- usec = 0
- usec = $7.to_f * 1000000 if $7
- zone = $8
- if zone
- off = zone_offset(zone, datetime[0])
- datetime = apply_offset(*(datetime + [off]))
- datetime << usec
- time = Time.utc(*datetime)
- force_zone!(time, zone, off)
- time
- else
- datetime << usec
- Time.local(*datetime)
- end
- else
- raise ArgumentError.new("invalid date: #{date.inspect}")
- end
- end
- end
- end
-
- unless method_defined?(:w3cdtf)
- # This method converts a Time object to a String. The String contains the
- # time in W3CDTF date/time format.
- #
- # The W3CDTF format is defined here: http://www.w3.org/TR/NOTE-datetime
- #
- # Time.now.w3cdtf
- # # => "2013-08-26T14:12:10.817124-07:00"
- def w3cdtf
- if usec.zero?
- fraction_digits = 0
- else
- fraction_digits = strftime('%6N').index(/0*\z/)
- end
- xmlschema(fraction_digits)
- end
- end
-end
-
-
-require "English"
-require "rss/utils"
-require "rss/converter"
-require "rss/xml-stylesheet"
-
-module RSS
-
- # The current version of RSS
- VERSION = "0.2.7"
-
- # The URI of the RSS 1.0 specification
- URI = "http://purl.org/rss/1.0/"
-
- DEBUG = false # :nodoc:
-
- # The basic error all other RSS errors stem from. Rescue this error if you
- # want to handle any given RSS error and you don't care about the details.
- class Error < StandardError; end
-
- # RSS, being an XML-based format, has namespace support. If two namespaces are
- # declared with the same name, an OverlappedPrefixError will be raised.
- class OverlappedPrefixError < Error
- attr_reader :prefix
- def initialize(prefix)
- @prefix = prefix
- end
- end
-
- # The InvalidRSSError error is the base class for a variety of errors
- # related to a poorly-formed RSS feed. Rescue this error if you only
- # care that a file could be invalid, but don't care how it is invalid.
- class InvalidRSSError < Error; end
-
- # Since RSS is based on XML, it must have opening and closing tags that
- # match. If they don't, a MissingTagError will be raised.
- class MissingTagError < InvalidRSSError
- attr_reader :tag, :parent
- def initialize(tag, parent)
- @tag, @parent = tag, parent
- super("tag <#{tag}> is missing in tag <#{parent}>")
- end
- end
-
- # Some tags must only exist a specific number of times in a given RSS feed.
- # If a feed has too many occurrences of one of these tags, a TooMuchTagError
- # will be raised.
- class TooMuchTagError < InvalidRSSError
- attr_reader :tag, :parent
- def initialize(tag, parent)
- @tag, @parent = tag, parent
- super("tag <#{tag}> is too much in tag <#{parent}>")
- end
- end
-
- # Certain attributes are required on specific tags in an RSS feed. If a feed
- # is missing one of these attributes, a MissingAttributeError is raised.
- class MissingAttributeError < InvalidRSSError
- attr_reader :tag, :attribute
- def initialize(tag, attribute)
- @tag, @attribute = tag, attribute
- super("attribute <#{attribute}> is missing in tag <#{tag}>")
- end
- end
-
- # RSS does not allow for free-form tag names, so if an RSS feed contains a
- # tag that we don't know about, an UnknownTagError is raised.
- class UnknownTagError < InvalidRSSError
- attr_reader :tag, :uri
- def initialize(tag, uri)
- @tag, @uri = tag, uri
- super("tag <#{tag}> is unknown in namespace specified by uri <#{uri}>")
- end
- end
-
- # Raised when an unexpected tag is encountered.
- class NotExpectedTagError < InvalidRSSError
- attr_reader :tag, :uri, :parent
- def initialize(tag, uri, parent)
- @tag, @uri, @parent = tag, uri, parent
- super("tag <{#{uri}}#{tag}> is not expected in tag <#{parent}>")
- end
- end
- # For backward compatibility :X
- NotExceptedTagError = NotExpectedTagError # :nodoc:
-
- # Attributes are in key-value form, and if there's no value provided for an
- # attribute, a NotAvailableValueError will be raised.
- class NotAvailableValueError < InvalidRSSError
- attr_reader :tag, :value, :attribute
- def initialize(tag, value, attribute=nil)
- @tag, @value, @attribute = tag, value, attribute
- message = "value <#{value}> of "
- message << "attribute <#{attribute}> of " if attribute
- message << "tag <#{tag}> is not available."
- super(message)
- end
- end
-
- # Raised when an unknown conversion error occurs.
- class UnknownConversionMethodError < Error
- attr_reader :to, :from
- def initialize(to, from)
- @to = to
- @from = from
- super("can't convert to #{to} from #{from}.")
- end
- end
- # for backward compatibility
- UnknownConvertMethod = UnknownConversionMethodError # :nodoc:
-
- # Raised when a conversion failure occurs.
- class ConversionError < Error
- attr_reader :string, :to, :from
- def initialize(string, to, from)
- @string = string
- @to = to
- @from = from
- super("can't convert #{@string} to #{to} from #{from}.")
- end
- end
-
- # Raised when a required variable is not set.
- class NotSetError < Error
- attr_reader :name, :variables
- def initialize(name, variables)
- @name = name
- @variables = variables
- super("required variables of #{@name} are not set: #{@variables.join(', ')}")
- end
- end
-
- # Raised when a RSS::Maker attempts to use an unknown maker.
- class UnsupportedMakerVersionError < Error
- attr_reader :version
- def initialize(version)
- @version = version
- super("Maker doesn't support version: #{@version}")
- end
- end
-
- module BaseModel
- include Utils
-
- def install_have_child_element(tag_name, uri, occurs, name=nil, type=nil)
- name ||= tag_name
- add_need_initialize_variable(name)
- install_model(tag_name, uri, occurs, name)
-
- writer_type, reader_type = type
- def_corresponded_attr_writer name, writer_type
- def_corresponded_attr_reader name, reader_type
- install_element(name) do |n, elem_name|
- <<-EOC
- if @#{n}
- "\#{@#{n}.to_s(need_convert, indent)}"
- else
- ''
- end
-EOC
- end
- end
- alias_method(:install_have_attribute_element, :install_have_child_element)
-
- def install_have_children_element(tag_name, uri, occurs, name=nil, plural_name=nil)
- name ||= tag_name
- plural_name ||= "#{name}s"
- add_have_children_element(name, plural_name)
- add_plural_form(name, plural_name)
- install_model(tag_name, uri, occurs, plural_name, true)
-
- def_children_accessor(name, plural_name)
- install_element(name, "s") do |n, elem_name|
- <<-EOC
- rv = []
- @#{n}.each do |x|
- value = "\#{x.to_s(need_convert, indent)}"
- rv << value if /\\A\\s*\\z/ !~ value
- end
- rv.join("\n")
-EOC
- end
- end
-
- def install_text_element(tag_name, uri, occurs, name=nil, type=nil,
- disp_name=nil)
- name ||= tag_name
- disp_name ||= name
- self::ELEMENTS << name unless self::ELEMENTS.include?(name)
- add_need_initialize_variable(name)
- install_model(tag_name, uri, occurs, name)
-
- def_corresponded_attr_writer(name, type, disp_name)
- def_corresponded_attr_reader(name, type || :convert)
- install_element(name) do |n, elem_name|
- <<-EOC
- if respond_to?(:#{n}_content)
- content = #{n}_content
- else
- content = @#{n}
- end
- if content
- rv = "\#{indent}<#{elem_name}>"
- value = html_escape(content)
- if need_convert
- rv << convert(value)
- else
- rv << value
- end
- rv << "</#{elem_name}>"
- rv
- else
- ''
- end
-EOC
- end
- end
-
- def install_date_element(tag_name, uri, occurs, name=nil, type=nil, disp_name=nil)
- name ||= tag_name
- type ||= :w3cdtf
- disp_name ||= name
- self::ELEMENTS << name
- add_need_initialize_variable(name)
- install_model(tag_name, uri, occurs, name)
-
- # accessor
- convert_attr_reader name
- date_writer(name, type, disp_name)
-
- install_element(name) do |n, elem_name|
- <<-EOC
- if @#{n}
- rv = "\#{indent}<#{elem_name}>"
- value = html_escape(@#{n}.#{type})
- if need_convert
- rv << convert(value)
- else
- rv << value
- end
- rv << "</#{elem_name}>"
- rv
- else
- ''
- end
-EOC
- end
-
- end
-
- private
- def install_element(name, postfix="")
- elem_name = name.sub('_', ':')
- method_name = "#{name}_element#{postfix}"
- add_to_element_method(method_name)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{method_name}(need_convert=true, indent='')
- #{yield(name, elem_name)}
- end
- private :#{method_name}
-EOC
- end
-
- def inherit_convert_attr_reader(*attrs)
- attrs.each do |attr|
- attr = attr.id2name if attr.kind_of?(Integer)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{attr}_without_inherit
- convert(@#{attr})
- end
-
- def #{attr}
- if @#{attr}
- #{attr}_without_inherit
- elsif @parent
- @parent.#{attr}
- else
- nil
- end
- end
-EOC
- end
- end
-
- def uri_convert_attr_reader(*attrs)
- attrs.each do |attr|
- attr = attr.id2name if attr.kind_of?(Integer)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{attr}_without_base
- convert(@#{attr})
- end
-
- def #{attr}
- value = #{attr}_without_base
- return nil if value.nil?
- if /\\A[a-z][a-z0-9+.\\-]*:/i =~ value
- value
- else
- "\#{base}\#{value}"
- end
- end
-EOC
- end
- end
-
- def convert_attr_reader(*attrs)
- attrs.each do |attr|
- attr = attr.id2name if attr.kind_of?(Integer)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{attr}
- convert(@#{attr})
- end
-EOC
- end
- end
-
- def yes_clean_other_attr_reader(*attrs)
- attrs.each do |attr|
- attr = attr.id2name if attr.kind_of?(Integer)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- attr_reader(:#{attr})
- def #{attr}?
- YesCleanOther.parse(@#{attr})
- end
- EOC
- end
- end
-
- def yes_other_attr_reader(*attrs)
- attrs.each do |attr|
- attr = attr.id2name if attr.kind_of?(Integer)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- attr_reader(:#{attr})
- def #{attr}?
- Utils::YesOther.parse(@#{attr})
- end
- EOC
- end
- end
-
- def csv_attr_reader(*attrs)
- separator = nil
- if attrs.last.is_a?(Hash)
- options = attrs.pop
- separator = options[:separator]
- end
- separator ||= ", "
- attrs.each do |attr|
- attr = attr.id2name if attr.kind_of?(Integer)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- attr_reader(:#{attr})
- def #{attr}_content
- if @#{attr}.nil?
- @#{attr}
- else
- @#{attr}.join(#{separator.dump})
- end
- end
- EOC
- end
- end
-
- def date_writer(name, type, disp_name=name)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{name}=(new_value)
- if new_value.nil?
- @#{name} = new_value
- elsif new_value.kind_of?(Time)
- @#{name} = new_value.dup
- else
- if @do_validate
- begin
- @#{name} = Time.__send__('#{type}', new_value)
- rescue ArgumentError
- raise NotAvailableValueError.new('#{disp_name}', new_value)
- end
- else
- @#{name} = nil
- if /\\A\\s*\\z/ !~ new_value.to_s
- begin
- unless Date._parse(new_value, false).empty?
- @#{name} = Time.parse(new_value)
- end
- rescue ArgumentError
- end
- end
- end
- end
-
- # Is it need?
- if @#{name}
- class << @#{name}
- undef_method(:to_s)
- alias_method(:to_s, :#{type})
- end
- end
-
- end
-EOC
- end
-
- def integer_writer(name, disp_name=name)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{name}=(new_value)
- if new_value.nil?
- @#{name} = new_value
- else
- if @do_validate
- begin
- @#{name} = Integer(new_value)
- rescue ArgumentError
- raise NotAvailableValueError.new('#{disp_name}', new_value)
- end
- else
- @#{name} = new_value.to_i
- end
- end
- end
-EOC
- end
-
- def positive_integer_writer(name, disp_name=name)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{name}=(new_value)
- if new_value.nil?
- @#{name} = new_value
- else
- if @do_validate
- begin
- tmp = Integer(new_value)
- raise ArgumentError if tmp <= 0
- @#{name} = tmp
- rescue ArgumentError
- raise NotAvailableValueError.new('#{disp_name}', new_value)
- end
- else
- @#{name} = new_value.to_i
- end
- end
- end
-EOC
- end
-
- def boolean_writer(name, disp_name=name)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{name}=(new_value)
- if new_value.nil?
- @#{name} = new_value
- else
- if @do_validate and
- ![true, false, "true", "false"].include?(new_value)
- raise NotAvailableValueError.new('#{disp_name}', new_value)
- end
- if [true, false].include?(new_value)
- @#{name} = new_value
- else
- @#{name} = new_value == "true"
- end
- end
- end
-EOC
- end
-
- def text_type_writer(name, disp_name=name)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{name}=(new_value)
- if @do_validate and
- !["text", "html", "xhtml", nil].include?(new_value)
- raise NotAvailableValueError.new('#{disp_name}', new_value)
- end
- @#{name} = new_value
- end
-EOC
- end
-
- def content_writer(name, disp_name=name)
- klass_name = "self.class::#{Utils.to_class_name(name)}"
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{name}=(new_value)
- if new_value.is_a?(#{klass_name})
- @#{name} = new_value
- else
- @#{name} = #{klass_name}.new
- @#{name}.content = new_value
- end
- end
-EOC
- end
-
- def yes_clean_other_writer(name, disp_name=name)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}=(value)
- value = (value ? "yes" : "no") if [true, false].include?(value)
- @#{name} = value
- end
- EOC
- end
-
- def yes_other_writer(name, disp_name=name)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}=(new_value)
- if [true, false].include?(new_value)
- new_value = new_value ? "yes" : "no"
- end
- @#{name} = new_value
- end
- EOC
- end
-
- def csv_writer(name, disp_name=name)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}=(new_value)
- @#{name} = Utils::CSV.parse(new_value)
- end
- EOC
- end
-
- def csv_integer_writer(name, disp_name=name)
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- def #{name}=(new_value)
- @#{name} = Utils::CSV.parse(new_value) {|v| Integer(v)}
- end
- EOC
- end
-
- def def_children_accessor(accessor_name, plural_name)
- module_eval(<<-EOC, *get_file_and_line_from_caller(2))
- def #{plural_name}
- @#{accessor_name}
- end
-
- def #{accessor_name}(*args)
- if args.empty?
- @#{accessor_name}.first
- else
- @#{accessor_name}[*args]
- end
- end
-
- def #{accessor_name}=(*args)
- receiver = self.class.name
- warn("Warning:\#{caller.first.sub(/:in `.*'\z/, '')}: " \
- "Don't use `\#{receiver}\##{accessor_name} = XXX'/" \
- "`\#{receiver}\#set_#{accessor_name}(XXX)'. " \
- "Those APIs are not sense of Ruby. " \
- "Use `\#{receiver}\##{plural_name} << XXX' instead of them.")
- if args.size == 1
- @#{accessor_name}.push(args[0])
- else
- @#{accessor_name}.__send__("[]=", *args)
- end
- end
- alias_method(:set_#{accessor_name}, :#{accessor_name}=)
-EOC
- end
- end
-
- module SetupMaker
- def setup_maker(maker)
- target = maker_target(maker)
- unless target.nil?
- setup_maker_attributes(target)
- setup_maker_element(target)
- setup_maker_elements(target)
- end
- end
-
- private
- def maker_target(maker)
- nil
- end
-
- def setup_maker_attributes(target)
- end
-
- def setup_maker_element(target)
- self.class.need_initialize_variables.each do |var|
- value = __send__(var)
- next if value.nil?
- if value.respond_to?("setup_maker") and
- !not_need_to_call_setup_maker_variables.include?(var)
- value.setup_maker(target)
- else
- setter = "#{var}="
- if target.respond_to?(setter)
- target.__send__(setter, value)
- end
- end
- end
- end
-
- def not_need_to_call_setup_maker_variables
- []
- end
-
- def setup_maker_elements(parent)
- self.class.have_children_elements.each do |name, plural_name|
- if parent.respond_to?(plural_name)
- target = parent.__send__(plural_name)
- __send__(plural_name).each do |elem|
- elem.setup_maker(target)
- end
- end
- end
- end
- end
-
- class Element
- extend BaseModel
- include Utils
- extend Utils::InheritedReader
- include SetupMaker
-
- INDENT = " "
-
- MUST_CALL_VALIDATORS = {}
- MODELS = []
- GET_ATTRIBUTES = []
- HAVE_CHILDREN_ELEMENTS = []
- TO_ELEMENT_METHODS = []
- NEED_INITIALIZE_VARIABLES = []
- PLURAL_FORMS = {}
-
- class << self
- def must_call_validators
- inherited_hash_reader("MUST_CALL_VALIDATORS")
- end
- def models
- inherited_array_reader("MODELS")
- end
- def get_attributes
- inherited_array_reader("GET_ATTRIBUTES")
- end
- def have_children_elements
- inherited_array_reader("HAVE_CHILDREN_ELEMENTS")
- end
- def to_element_methods
- inherited_array_reader("TO_ELEMENT_METHODS")
- end
- def need_initialize_variables
- inherited_array_reader("NEED_INITIALIZE_VARIABLES")
- end
- def plural_forms
- inherited_hash_reader("PLURAL_FORMS")
- end
-
- def inherited_base
- ::RSS::Element
- end
-
- def inherited(klass)
- klass.const_set(:MUST_CALL_VALIDATORS, {})
- klass.const_set(:MODELS, [])
- klass.const_set(:GET_ATTRIBUTES, [])
- klass.const_set(:HAVE_CHILDREN_ELEMENTS, [])
- klass.const_set(:TO_ELEMENT_METHODS, [])
- klass.const_set(:NEED_INITIALIZE_VARIABLES, [])
- klass.const_set(:PLURAL_FORMS, {})
-
- tag_name = klass.name.split(/::/).last
- tag_name[0, 1] = tag_name[0, 1].downcase
- klass.instance_variable_set(:@tag_name, tag_name)
- klass.instance_variable_set(:@have_content, false)
- end
-
- def install_must_call_validator(prefix, uri)
- self::MUST_CALL_VALIDATORS[uri] = prefix
- end
-
- def install_model(tag, uri, occurs=nil, getter=nil, plural=false)
- getter ||= tag
- if m = self::MODELS.find {|t, u, o, g, p| t == tag and u == uri}
- m[2] = occurs
- else
- self::MODELS << [tag, uri, occurs, getter, plural]
- end
- end
-
- def install_get_attribute(name, uri, required=true,
- type=nil, disp_name=nil,
- element_name=nil)
- disp_name ||= name
- element_name ||= name
- writer_type, reader_type = type
- def_corresponded_attr_writer name, writer_type, disp_name
- def_corresponded_attr_reader name, reader_type
- if type == :boolean and /^is/ =~ name
- alias_method "#{$POSTMATCH}?", name
- end
- self::GET_ATTRIBUTES << [name, uri, required, element_name]
- add_need_initialize_variable(disp_name)
- end
-
- def def_corresponded_attr_writer(name, type=nil, disp_name=nil)
- disp_name ||= name
- case type
- when :integer
- integer_writer name, disp_name
- when :positive_integer
- positive_integer_writer name, disp_name
- when :boolean
- boolean_writer name, disp_name
- when :w3cdtf, :rfc822, :rfc2822
- date_writer name, type, disp_name
- when :text_type
- text_type_writer name, disp_name
- when :content
- content_writer name, disp_name
- when :yes_clean_other
- yes_clean_other_writer name, disp_name
- when :yes_other
- yes_other_writer name, disp_name
- when :csv
- csv_writer name
- when :csv_integer
- csv_integer_writer name
- else
- attr_writer name
- end
- end
-
- def def_corresponded_attr_reader(name, type=nil)
- case type
- when :inherit
- inherit_convert_attr_reader name
- when :uri
- uri_convert_attr_reader name
- when :yes_clean_other
- yes_clean_other_attr_reader name
- when :yes_other
- yes_other_attr_reader name
- when :csv
- csv_attr_reader name
- when :csv_integer
- csv_attr_reader name, :separator => ","
- else
- convert_attr_reader name
- end
- end
-
- def content_setup(type=nil, disp_name=nil)
- writer_type, reader_type = type
- def_corresponded_attr_writer :content, writer_type, disp_name
- def_corresponded_attr_reader :content, reader_type
- @have_content = true
- end
-
- def have_content?
- @have_content
- end
-
- def add_have_children_element(variable_name, plural_name)
- self::HAVE_CHILDREN_ELEMENTS << [variable_name, plural_name]
- end
-
- def add_to_element_method(method_name)
- self::TO_ELEMENT_METHODS << method_name
- end
-
- def add_need_initialize_variable(variable_name)
- self::NEED_INITIALIZE_VARIABLES << variable_name
- end
-
- def add_plural_form(singular, plural)
- self::PLURAL_FORMS[singular] = plural
- end
-
- def required_prefix
- nil
- end
-
- def required_uri
- ""
- end
-
- def need_parent?
- false
- end
-
- def install_ns(prefix, uri)
- if self::NSPOOL.has_key?(prefix)
- raise OverlappedPrefixError.new(prefix)
- end
- self::NSPOOL[prefix] = uri
- end
-
- def tag_name
- @tag_name
- end
- end
-
- attr_accessor :parent, :do_validate
-
- def initialize(do_validate=true, attrs=nil)
- @parent = nil
- @converter = nil
- if attrs.nil? and (do_validate.is_a?(Hash) or do_validate.is_a?(Array))
- do_validate, attrs = true, do_validate
- end
- @do_validate = do_validate
- initialize_variables(attrs || {})
- end
-
- def tag_name
- self.class.tag_name
- end
-
- def full_name
- tag_name
- end
-
- def converter=(converter)
- @converter = converter
- targets = children.dup
- self.class.have_children_elements.each do |variable_name, plural_name|
- targets.concat(__send__(plural_name))
- end
- targets.each do |target|
- target.converter = converter unless target.nil?
- end
- end
-
- def convert(value)
- if @converter
- @converter.convert(value)
- else
- value
- end
- end
-
- def valid?(ignore_unknown_element=true)
- validate(ignore_unknown_element)
- true
- rescue RSS::Error
- false
- end
-
- def validate(ignore_unknown_element=true)
- do_validate = @do_validate
- @do_validate = true
- validate_attribute
- __validate(ignore_unknown_element)
- ensure
- @do_validate = do_validate
- end
-
- def validate_for_stream(tags, ignore_unknown_element=true)
- validate_attribute
- __validate(ignore_unknown_element, tags, false)
- end
-
- def to_s(need_convert=true, indent='')
- if self.class.have_content?
- return "" if !empty_content? and !content_is_set?
- rv = tag(indent) do |next_indent|
- if empty_content?
- ""
- else
- xmled_content
- end
- end
- else
- rv = tag(indent) do |next_indent|
- self.class.to_element_methods.collect do |method_name|
- __send__(method_name, false, next_indent)
- end
- end
- end
- rv = convert(rv) if need_convert
- rv
- end
-
- def have_xml_content?
- false
- end
-
- def need_base64_encode?
- false
- end
-
- def set_next_element(tag_name, next_element)
- klass = next_element.class
- prefix = ""
- prefix << "#{klass.required_prefix}_" if klass.required_prefix
- key = "#{prefix}#{tag_name.gsub(/-/, '_')}"
- if self.class.plural_forms.has_key?(key)
- ary = __send__("#{self.class.plural_forms[key]}")
- ary << next_element
- else
- __send__("#{key}=", next_element)
- end
- end
-
- protected
- def have_required_elements?
- self.class::MODELS.all? do |tag, uri, occurs, getter|
- if occurs.nil? or occurs == "+"
- child = __send__(getter)
- if child.is_a?(Array)
- children = child
- children.any? {|c| c.have_required_elements?}
- else
- !child.to_s.empty?
- end
- else
- true
- end
- end
- end
-
- private
- def initialize_variables(attrs)
- normalized_attrs = {}
- attrs.each do |key, value|
- normalized_attrs[key.to_s] = value
- end
- self.class.need_initialize_variables.each do |variable_name|
- value = normalized_attrs[variable_name.to_s]
- if value
- __send__("#{variable_name}=", value)
- else
- instance_variable_set("@#{variable_name}", nil)
- end
- end
- initialize_have_children_elements
- @content = normalized_attrs["content"] if self.class.have_content?
- end
-
- def initialize_have_children_elements
- self.class.have_children_elements.each do |variable_name, plural_name|
- instance_variable_set("@#{variable_name}", [])
- end
- end
-
- def tag(indent, additional_attrs={}, &block)
- next_indent = indent + INDENT
-
- attrs = collect_attrs
- return "" if attrs.nil?
-
- return "" unless have_required_elements?
-
- attrs.update(additional_attrs)
- start_tag = make_start_tag(indent, next_indent, attrs.dup)
-
- if block
- content = block.call(next_indent)
- else
- content = []
- end
-
- if content.is_a?(String)
- content = [content]
- start_tag << ">"
- end_tag = "</#{full_name}>"
- else
- content = content.reject{|x| x.empty?}
- if content.empty?
- return "" if attrs.empty?
- end_tag = "/>"
- else
- start_tag << ">\n"
- end_tag = "\n#{indent}</#{full_name}>"
- end
- end
-
- start_tag + content.join("\n") + end_tag
- end
-
- def make_start_tag(indent, next_indent, attrs)
- start_tag = ["#{indent}<#{full_name}"]
- unless attrs.empty?
- start_tag << attrs.collect do |key, value|
- %Q[#{h key}="#{h value}"]
- end.join("\n#{next_indent}")
- end
- start_tag.join(" ")
- end
-
- def collect_attrs
- attrs = {}
- _attrs.each do |name, required, alias_name|
- value = __send__(alias_name || name)
- return nil if required and value.nil?
- next if value.nil?
- return nil if attrs.has_key?(name)
- attrs[name] = value
- end
- attrs
- end
-
- def tag_name_with_prefix(prefix)
- "#{prefix}:#{tag_name}"
- end
-
- # For backward compatibility
- def calc_indent
- ''
- end
-
- def children
- rv = []
- self.class.models.each do |name, uri, occurs, getter|
- value = __send__(getter)
- next if value.nil?
- value = [value] unless value.is_a?(Array)
- value.each do |v|
- rv << v if v.is_a?(Element)
- end
- end
- rv
- end
-
- def _tags
- rv = []
- self.class.models.each do |name, uri, occurs, getter, plural|
- value = __send__(getter)
- next if value.nil?
- if plural and value.is_a?(Array)
- rv.concat([[uri, name]] * value.size)
- else
- rv << [uri, name]
- end
- end
- rv
- end
-
- def _attrs
- self.class.get_attributes.collect do |name, uri, required, element_name|
- [element_name, required, name]
- end
- end
-
- def __validate(ignore_unknown_element, tags=_tags, recursive=true)
- if recursive
- children.compact.each do |child|
- child.validate
- end
- end
- must_call_validators = self.class.must_call_validators
- tags = tag_filter(tags.dup)
- p tags if DEBUG
- must_call_validators.each do |uri, prefix|
- _validate(ignore_unknown_element, tags[uri], uri)
- meth = "#{prefix}_validate"
- if !prefix.empty? and respond_to?(meth, true)
- __send__(meth, ignore_unknown_element, tags[uri], uri)
- end
- end
- end
-
- def validate_attribute
- _attrs.each do |a_name, required, alias_name|
- value = instance_variable_get("@#{alias_name || a_name}")
- if required and value.nil?
- raise MissingAttributeError.new(tag_name, a_name)
- end
- __send__("#{alias_name || a_name}=", value)
- end
- end
-
- def _validate(ignore_unknown_element, tags, uri, models=self.class.models)
- count = 1
- do_redo = false
- not_shift = false
- tag = nil
- models = models.find_all {|model| model[1] == uri}
- element_names = models.collect {|model| model[0]}
- if tags
- tags_size = tags.size
- tags = tags.sort_by {|x| element_names.index(x) || tags_size}
- end
-
- models.each_with_index do |model, i|
- name, _, occurs, = model
-
- if DEBUG
- p "before"
- p tags
- p model
- end
-
- if not_shift
- not_shift = false
- elsif tags
- tag = tags.shift
- end
-
- if DEBUG
- p "mid"
- p count
- end
-
- case occurs
- when '?'
- if count > 2
- raise TooMuchTagError.new(name, tag_name)
- else
- if name == tag
- do_redo = true
- else
- not_shift = true
- end
- end
- when '*'
- if name == tag
- do_redo = true
- else
- not_shift = true
- end
- when '+'
- if name == tag
- do_redo = true
- else
- if count > 1
- not_shift = true
- else
- raise MissingTagError.new(name, tag_name)
- end
- end
- else
- if name == tag
- if models[i+1] and models[i+1][0] != name and
- tags and tags.first == name
- raise TooMuchTagError.new(name, tag_name)
- end
- else
- raise MissingTagError.new(name, tag_name)
- end
- end
-
- if DEBUG
- p "after"
- p not_shift
- p do_redo
- p tag
- end
-
- if do_redo
- do_redo = false
- count += 1
- redo
- else
- count = 1
- end
-
- end
-
- if !ignore_unknown_element and !tags.nil? and !tags.empty?
- raise NotExpectedTagError.new(tags.first, uri, tag_name)
- end
-
- end
-
- def tag_filter(tags)
- rv = {}
- tags.each do |tag|
- rv[tag[0]] = [] unless rv.has_key?(tag[0])
- rv[tag[0]].push(tag[1])
- end
- rv
- end
-
- def empty_content?
- false
- end
-
- def content_is_set?
- if have_xml_content?
- __send__(self.class.xml_getter)
- else
- content
- end
- end
-
- def xmled_content
- if have_xml_content?
- __send__(self.class.xml_getter).to_s
- else
- _content = content
- _content = [_content].pack("m").delete("\n") if need_base64_encode?
- h(_content)
- end
- end
- end
-
- module RootElementMixin
-
- include XMLStyleSheetMixin
-
- attr_reader :output_encoding
- attr_reader :feed_type, :feed_subtype, :feed_version
- attr_accessor :version, :encoding, :standalone
- def initialize(feed_version, version=nil, encoding=nil, standalone=nil)
- super()
- @feed_type = nil
- @feed_subtype = nil
- @feed_version = feed_version
- @version = version || '1.0'
- @encoding = encoding
- @standalone = standalone
- @output_encoding = nil
- end
-
- def feed_info
- [@feed_type, @feed_version, @feed_subtype]
- end
-
- def output_encoding=(enc)
- @output_encoding = enc
- self.converter = Converter.new(@output_encoding, @encoding)
- end
-
- def setup_maker(maker)
- maker.version = version
- maker.encoding = encoding
- maker.standalone = standalone
-
- xml_stylesheets.each do |xss|
- xss.setup_maker(maker)
- end
-
- super
- end
-
- def to_feed(type, &block)
- Maker.make(type) do |maker|
- setup_maker(maker)
- block.call(maker) if block
- end
- end
-
- def to_rss(type, &block)
- to_feed("rss#{type}", &block)
- end
-
- def to_atom(type, &block)
- to_feed("atom:#{type}", &block)
- end
-
- def to_xml(type=nil, &block)
- if type.nil? or same_feed_type?(type)
- to_s
- else
- to_feed(type, &block).to_s
- end
- end
-
- private
- def same_feed_type?(type)
- if /^(atom|rss)?(\d+\.\d+)?(?::(.+))?$/i =~ type
- feed_type = ($1 || @feed_type).downcase
- feed_version = $2 || @feed_version
- feed_subtype = $3 || @feed_subtype
- [feed_type, feed_version, feed_subtype] == feed_info
- else
- false
- end
- end
-
- def tag(indent, attrs={}, &block)
- rv = super(indent, ns_declarations.merge(attrs), &block)
- return rv if rv.empty?
- "#{xmldecl}#{xml_stylesheet_pi}#{rv}"
- end
-
- def xmldecl
- rv = %Q[<?xml version="#{@version}"]
- if @output_encoding or @encoding
- rv << %Q[ encoding="#{@output_encoding or @encoding}"]
- end
- rv << %Q[ standalone="yes"] if @standalone
- rv << "?>\n"
- rv
- end
-
- def ns_declarations
- decls = {}
- self.class::NSPOOL.collect do |prefix, uri|
- prefix = ":#{prefix}" unless prefix.empty?
- decls["xmlns#{prefix}"] = uri
- end
- decls
- end
-
- def maker_target(target)
- target
- end
- end
-end
diff --git a/ruby_2_2/lib/rss/slash.rb b/ruby_2_2/lib/rss/slash.rb
deleted file mode 100644
index 65c61142e1..0000000000
--- a/ruby_2_2/lib/rss/slash.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-require 'rss/1.0'
-
-module RSS
- # The prefix for the Slash XML namespace.
- SLASH_PREFIX = 'slash'
- # The URI of the Slash specification.
- SLASH_URI = "http://purl.org/rss/1.0/modules/slash/"
-
- RDF.install_ns(SLASH_PREFIX, SLASH_URI)
-
- module SlashModel
- extend BaseModel
-
- ELEMENT_INFOS = \
- [
- ["section"],
- ["department"],
- ["comments", :positive_integer],
- ["hit_parade", :csv_integer],
- ]
-
- class << self
- def append_features(klass)
- super
-
- return if klass.instance_of?(Module)
- klass.install_must_call_validator(SLASH_PREFIX, SLASH_URI)
- ELEMENT_INFOS.each do |name, type, *additional_infos|
- full_name = "#{SLASH_PREFIX}_#{name}"
- klass.install_text_element(full_name, SLASH_URI, "?",
- full_name, type, name)
- end
-
- klass.module_eval do
- alias_method(:slash_hit_parades, :slash_hit_parade)
- undef_method(:slash_hit_parade)
- alias_method(:slash_hit_parade, :slash_hit_parade_content)
- end
- end
- end
- end
-
- class RDF
- class Item; include SlashModel; end
- end
-
- SlashModel::ELEMENT_INFOS.each do |name, type|
- accessor_base = "#{SLASH_PREFIX}_#{name}"
- BaseListener.install_get_text_element(SLASH_URI, name, accessor_base)
- end
-end
diff --git a/ruby_2_2/lib/rss/syndication.rb b/ruby_2_2/lib/rss/syndication.rb
deleted file mode 100644
index 77a84b9a2a..0000000000
--- a/ruby_2_2/lib/rss/syndication.rb
+++ /dev/null
@@ -1,68 +0,0 @@
-require "rss/1.0"
-
-module RSS
- # The prefix for the Syndication XML namespace.
- SY_PREFIX = 'sy'
- # The URI of the Syndication specification.
- SY_URI = "http://purl.org/rss/1.0/modules/syndication/"
-
- RDF.install_ns(SY_PREFIX, SY_URI)
-
- module SyndicationModel
-
- extend BaseModel
-
- ELEMENTS = []
-
- def self.append_features(klass)
- super
-
- klass.install_must_call_validator(SY_PREFIX, SY_URI)
- klass.module_eval do
- [
- ["updatePeriod"],
- ["updateFrequency", :positive_integer]
- ].each do |name, type|
- install_text_element(name, SY_URI, "?",
- "#{SY_PREFIX}_#{name}", type,
- "#{SY_PREFIX}:#{name}")
- end
-
- %w(updateBase).each do |name|
- install_date_element(name, SY_URI, "?",
- "#{SY_PREFIX}_#{name}", 'w3cdtf',
- "#{SY_PREFIX}:#{name}")
- end
- end
-
- klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
- alias_method(:_sy_updatePeriod=, :sy_updatePeriod=)
- def sy_updatePeriod=(new_value)
- new_value = new_value.strip
- validate_sy_updatePeriod(new_value) if @do_validate
- self._sy_updatePeriod = new_value
- end
- EOC
- end
-
- private
- SY_UPDATEPERIOD_AVAILABLE_VALUES = %w(hourly daily weekly monthly yearly)
- def validate_sy_updatePeriod(value)
- unless SY_UPDATEPERIOD_AVAILABLE_VALUES.include?(value)
- raise NotAvailableValueError.new("updatePeriod", value)
- end
- end
- end
-
- class RDF
- class Channel; include SyndicationModel; end
- end
-
- prefix_size = SY_PREFIX.size + 1
- SyndicationModel::ELEMENTS.uniq!
- SyndicationModel::ELEMENTS.each do |full_name|
- name = full_name[prefix_size..-1]
- BaseListener.install_get_text_element(SY_URI, name, full_name)
- end
-
-end
diff --git a/ruby_2_2/lib/rss/taxonomy.rb b/ruby_2_2/lib/rss/taxonomy.rb
deleted file mode 100644
index b7fbe6b0de..0000000000
--- a/ruby_2_2/lib/rss/taxonomy.rb
+++ /dev/null
@@ -1,147 +0,0 @@
-require "rss/1.0"
-require "rss/dublincore"
-
-module RSS
- # The prefix for the Taxonomy XML namespace.
- TAXO_PREFIX = "taxo"
- # The URI for the specification of the Taxonomy XML namespace.
- TAXO_URI = "http://purl.org/rss/1.0/modules/taxonomy/"
-
- RDF.install_ns(TAXO_PREFIX, TAXO_URI)
-
- # The listing of all the taxonomy elements, with the appropriate namespace.
- TAXO_ELEMENTS = []
-
- %w(link).each do |name|
- full_name = "#{TAXO_PREFIX}_#{name}"
- BaseListener.install_get_text_element(TAXO_URI, name, full_name)
- TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{name}"
- end
-
- %w(topic topics).each do |name|
- class_name = Utils.to_class_name(name)
- BaseListener.install_class_name(TAXO_URI, name, "Taxonomy#{class_name}")
- TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{name}"
- end
-
- module TaxonomyTopicsModel
- extend BaseModel
-
- def self.append_features(klass)
- super
-
- klass.install_must_call_validator(TAXO_PREFIX, TAXO_URI)
- %w(topics).each do |name|
- klass.install_have_child_element(name, TAXO_URI, "?",
- "#{TAXO_PREFIX}_#{name}")
- end
- end
-
- class TaxonomyTopics < Element
- include RSS10
-
- Bag = ::RSS::RDF::Bag
-
- class << self
- def required_prefix
- TAXO_PREFIX
- end
-
- def required_uri
- TAXO_URI
- end
- end
-
- @tag_name = "topics"
-
- install_have_child_element("Bag", RDF::URI, nil)
- install_must_call_validator('rdf', RDF::URI)
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.Bag = args[0]
- end
- self.Bag ||= Bag.new
- end
-
- def full_name
- tag_name_with_prefix(TAXO_PREFIX)
- end
-
- def maker_target(target)
- target.taxo_topics
- end
-
- def resources
- if @Bag
- @Bag.lis.collect do |li|
- li.resource
- end
- else
- []
- end
- end
- end
- end
-
- module TaxonomyTopicModel
- extend BaseModel
-
- def self.append_features(klass)
- super
- var_name = "#{TAXO_PREFIX}_topic"
- klass.install_have_children_element("topic", TAXO_URI, "*", var_name)
- end
-
- class TaxonomyTopic < Element
- include RSS10
-
- include DublinCoreModel
- include TaxonomyTopicsModel
-
- class << self
- def required_prefix
- TAXO_PREFIX
- end
-
- def required_uri
- TAXO_URI
- end
- end
-
- @tag_name = "topic"
-
- install_get_attribute("about", ::RSS::RDF::URI, true, nil, nil,
- "#{RDF::PREFIX}:about")
- install_text_element("link", TAXO_URI, "?", "#{TAXO_PREFIX}_link")
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.about = args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(TAXO_PREFIX)
- end
-
- def maker_target(target)
- target.new_taxo_topic
- end
- end
- end
-
- class RDF
- include TaxonomyTopicModel
- class Channel
- include TaxonomyTopicsModel
- end
- class Item; include TaxonomyTopicsModel; end
- end
-end
diff --git a/ruby_2_2/lib/rss/trackback.rb b/ruby_2_2/lib/rss/trackback.rb
deleted file mode 100644
index 577bf0cef7..0000000000
--- a/ruby_2_2/lib/rss/trackback.rb
+++ /dev/null
@@ -1,290 +0,0 @@
-# This file contains the implementation of trackbacks. It is entirely internal
-# and not useful to outside developers.
-require 'rss/1.0'
-require 'rss/2.0'
-
-module RSS # :nodoc: all
-
- TRACKBACK_PREFIX = 'trackback'
- TRACKBACK_URI = 'http://madskills.com/public/xml/rss/module/trackback/'
-
- RDF.install_ns(TRACKBACK_PREFIX, TRACKBACK_URI)
- Rss.install_ns(TRACKBACK_PREFIX, TRACKBACK_URI)
-
- module TrackBackUtils
- private
- def trackback_validate(ignore_unknown_element, tags, uri)
- return if tags.nil?
- if tags.find {|tag| tag == "about"} and
- !tags.find {|tag| tag == "ping"}
- raise MissingTagError.new("#{TRACKBACK_PREFIX}:ping", tag_name)
- end
- end
- end
-
- module BaseTrackBackModel
-
- ELEMENTS = %w(ping about)
-
- def append_features(klass)
- super
-
- unless klass.class == Module
- klass.module_eval {include TrackBackUtils}
-
- klass.install_must_call_validator(TRACKBACK_PREFIX, TRACKBACK_URI)
- %w(ping).each do |name|
- var_name = "#{TRACKBACK_PREFIX}_#{name}"
- klass_name = "TrackBack#{Utils.to_class_name(name)}"
- klass.install_have_child_element(name, TRACKBACK_URI, "?", var_name)
- klass.module_eval(<<-EOC, __FILE__, __LINE__)
- remove_method :#{var_name}
- def #{var_name}
- @#{var_name} and @#{var_name}.value
- end
-
- remove_method :#{var_name}=
- def #{var_name}=(value)
- @#{var_name} = Utils.new_with_value_if_need(#{klass_name}, value)
- end
- EOC
- end
-
- [%w(about s)].each do |name, postfix|
- var_name = "#{TRACKBACK_PREFIX}_#{name}"
- klass_name = "TrackBack#{Utils.to_class_name(name)}"
- klass.install_have_children_element(name, TRACKBACK_URI, "*",
- var_name)
- klass.module_eval(<<-EOC, __FILE__, __LINE__)
- remove_method :#{var_name}
- def #{var_name}(*args)
- if args.empty?
- @#{var_name}.first and @#{var_name}.first.value
- else
- ret = @#{var_name}.__send__("[]", *args)
- if ret.is_a?(Array)
- ret.collect {|x| x.value}
- else
- ret.value
- end
- end
- end
-
- remove_method :#{var_name}=
- remove_method :set_#{var_name}
- def #{var_name}=(*args)
- if args.size == 1
- item = Utils.new_with_value_if_need(#{klass_name}, args[0])
- @#{var_name}.push(item)
- else
- new_val = args.last
- if new_val.is_a?(Array)
- new_val = new_value.collect do |val|
- Utils.new_with_value_if_need(#{klass_name}, val)
- end
- else
- new_val = Utils.new_with_value_if_need(#{klass_name}, new_val)
- end
- @#{var_name}.__send__("[]=", *(args[0..-2] + [new_val]))
- end
- end
- alias set_#{var_name} #{var_name}=
- EOC
- end
- end
- end
- end
-
- module TrackBackModel10
- extend BaseModel
- extend BaseTrackBackModel
-
- class TrackBackPing < Element
- include RSS10
-
- class << self
-
- def required_prefix
- TRACKBACK_PREFIX
- end
-
- def required_uri
- TRACKBACK_URI
- end
-
- end
-
- @tag_name = "ping"
-
- [
- ["resource", ::RSS::RDF::URI, true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required, nil, nil,
- "#{::RSS::RDF::PREFIX}:#{name}")
- end
-
- alias_method(:value, :resource)
- alias_method(:value=, :resource=)
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.resource = args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(TRACKBACK_PREFIX)
- end
- end
-
- class TrackBackAbout < Element
- include RSS10
-
- class << self
-
- def required_prefix
- TRACKBACK_PREFIX
- end
-
- def required_uri
- TRACKBACK_URI
- end
-
- end
-
- @tag_name = "about"
-
- [
- ["resource", ::RSS::RDF::URI, true]
- ].each do |name, uri, required|
- install_get_attribute(name, uri, required, nil, nil,
- "#{::RSS::RDF::PREFIX}:#{name}")
- end
-
- alias_method(:value, :resource)
- alias_method(:value=, :resource=)
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.resource = args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(TRACKBACK_PREFIX)
- end
-
- private
- def maker_target(abouts)
- abouts.new_about
- end
-
- def setup_maker_attributes(about)
- about.resource = self.resource
- end
-
- end
- end
-
- module TrackBackModel20
- extend BaseModel
- extend BaseTrackBackModel
-
- class TrackBackPing < Element
- include RSS09
-
- @tag_name = "ping"
-
- content_setup
-
- class << self
-
- def required_prefix
- TRACKBACK_PREFIX
- end
-
- def required_uri
- TRACKBACK_URI
- end
-
- end
-
- alias_method(:value, :content)
- alias_method(:value=, :content=)
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.content = args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(TRACKBACK_PREFIX)
- end
-
- end
-
- class TrackBackAbout < Element
- include RSS09
-
- @tag_name = "about"
-
- content_setup
-
- class << self
-
- def required_prefix
- TRACKBACK_PREFIX
- end
-
- def required_uri
- TRACKBACK_URI
- end
-
- end
-
- alias_method(:value, :content)
- alias_method(:value=, :content=)
-
- def initialize(*args)
- if Utils.element_initialize_arguments?(args)
- super
- else
- super()
- self.content = args[0]
- end
- end
-
- def full_name
- tag_name_with_prefix(TRACKBACK_PREFIX)
- end
-
- end
- end
-
- class RDF
- class Item; include TrackBackModel10; end
- end
-
- class Rss
- class Channel
- class Item; include TrackBackModel20; end
- end
- end
-
- BaseTrackBackModel::ELEMENTS.each do |name|
- class_name = Utils.to_class_name(name)
- BaseListener.install_class_name(TRACKBACK_URI, name,
- "TrackBack#{class_name}")
- end
-
- BaseTrackBackModel::ELEMENTS.collect! {|name| "#{TRACKBACK_PREFIX}_#{name}"}
-end
diff --git a/ruby_2_2/lib/rss/utils.rb b/ruby_2_2/lib/rss/utils.rb
deleted file mode 100644
index b420e6b24c..0000000000
--- a/ruby_2_2/lib/rss/utils.rb
+++ /dev/null
@@ -1,199 +0,0 @@
-module RSS
-
- ##
- # RSS::Utils is a module that holds various utility functions that are used
- # across many parts of the rest of the RSS library. Like most modules named
- # some variant of 'util', its methods are probably not particularly useful
- # to those who aren't developing the library itself.
- module Utils
- module_function
-
- # Given a +name+ in a name_with_underscores or a name-with-dashes format,
- # returns the CamelCase version of +name+.
- #
- # If the +name+ is already CamelCased, nothing happens.
- #
- # Examples:
- #
- # require 'rss/utils'
- #
- # RSS::Utils.to_class_name("sample_name")
- # # => "SampleName"
- # RSS::Utils.to_class_name("with-dashes")
- # # => "WithDashes"
- # RSS::Utils.to_class_name("CamelCase")
- # # => "CamelCase"
- def to_class_name(name)
- name.split(/[_\-]/).collect do |part|
- "#{part[0, 1].upcase}#{part[1..-1]}"
- end.join("")
- end
-
- # Returns an array of two elements: the filename where the calling method
- # is located, and the line number where it is defined.
- #
- # Takes an optional argument +i+, which specifies how many callers up the
- # stack to look.
- #
- # Examples:
- #
- # require 'rss/utils'
- #
- # def foo
- # p RSS::Utils.get_file_and_line_from_caller
- # p RSS::Utils.get_file_and_line_from_caller(1)
- # end
- #
- # def bar
- # foo
- # end
- #
- # def baz
- # bar
- # end
- #
- # baz
- # # => ["test.rb", 5]
- # # => ["test.rb", 9]
- #
- # If +i+ is not given, or is the default value of 0, it attempts to figure
- # out the correct value. This is useful when in combination with
- # instance_eval. For example:
- #
- # require 'rss/utils'
- #
- # def foo
- # p RSS::Utils.get_file_and_line_from_caller(1)
- # end
- #
- # def bar
- # foo
- # end
- #
- # instance_eval <<-RUBY, *RSS::Utils.get_file_and_line_from_caller
- # def baz
- # bar
- # end
- # RUBY
- #
- # baz
- #
- # # => ["test.rb", 8]
- def get_file_and_line_from_caller(i=0)
- file, line, = caller[i].split(':')
- line = line.to_i
- line += 1 if i.zero?
- [file, line]
- end
-
- # Takes a string +s+ with some HTML in it, and escapes '&', '"', '<' and '>', by
- # replacing them with the appropriate entities.
- #
- # This method is also aliased to h, for convenience.
- #
- # Examples:
- #
- # require 'rss/utils'
- #
- # RSS::Utils.html_escape("Dungeons & Dragons")
- # # => "Dungeons &amp; Dragons"
- # RSS::Utils.h(">_>")
- # # => "&gt;_&gt;"
- def html_escape(s)
- s.to_s.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
- end
- alias h html_escape
-
- # If +value+ is an instance of class +klass+, return it, else
- # create a new instance of +klass+ with value +value+.
- def new_with_value_if_need(klass, value)
- if value.is_a?(klass)
- value
- else
- klass.new(value)
- end
- end
-
- # This method is used inside of several different objects to determine
- # if special behavior is needed in the constructor.
- #
- # Special behavior is needed if the array passed in as +args+ has
- # +true+ or +false+ as its value, and if the second element of +args+
- # is a hash.
- def element_initialize_arguments?(args)
- [true, false].include?(args[0]) and args[1].is_a?(Hash)
- end
-
- module YesCleanOther
- module_function
- def parse(value)
- if [true, false, nil].include?(value)
- value
- else
- case value.to_s
- when /\Ayes\z/i
- true
- when /\Aclean\z/i
- false
- else
- nil
- end
- end
- end
- end
-
- module YesOther
- module_function
- def parse(value)
- if [true, false].include?(value)
- value
- else
- /\Ayes\z/i.match(value.to_s) ? true : false
- end
- end
- end
-
- module CSV
- module_function
- def parse(value, &block)
- if value.is_a?(String)
- value = value.strip.split(/\s*,\s*/)
- value = value.collect(&block) if block_given?
- value
- else
- value
- end
- end
- end
-
- module InheritedReader
- def inherited_reader(constant_name)
- base_class = inherited_base
- result = base_class.const_get(constant_name)
- found_base_class = false
- ancestors.reverse_each do |klass|
- if found_base_class
- if klass.const_defined?(constant_name)
- result = yield(result, klass.const_get(constant_name))
- end
- else
- found_base_class = klass == base_class
- end
- end
- result
- end
-
- def inherited_array_reader(constant_name)
- inherited_reader(constant_name) do |result, current|
- current + result
- end
- end
-
- def inherited_hash_reader(constant_name)
- inherited_reader(constant_name) do |result, current|
- result.merge(current)
- end
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rss/xml-stylesheet.rb b/ruby_2_2/lib/rss/xml-stylesheet.rb
deleted file mode 100644
index 96ee95050e..0000000000
--- a/ruby_2_2/lib/rss/xml-stylesheet.rb
+++ /dev/null
@@ -1,105 +0,0 @@
-require "rss/utils"
-
-module RSS
-
- module XMLStyleSheetMixin
- attr_accessor :xml_stylesheets
- def initialize(*args)
- super
- @xml_stylesheets = []
- end
-
- private
- def xml_stylesheet_pi
- xsss = @xml_stylesheets.collect do |xss|
- pi = xss.to_s
- pi = nil if /\A\s*\z/ =~ pi
- pi
- end.compact
- xsss.push("") unless xsss.empty?
- xsss.join("\n")
- end
- end
-
- class XMLStyleSheet
-
- include Utils
-
- ATTRIBUTES = %w(href type title media charset alternate)
-
- GUESS_TABLE = {
- "xsl" => "text/xsl",
- "css" => "text/css",
- }
-
- attr_accessor(*ATTRIBUTES)
- attr_accessor(:do_validate)
- def initialize(*attrs)
- if attrs.size == 1 and
- (attrs.first.is_a?(Hash) or attrs.first.is_a?(Array))
- attrs = attrs.first
- end
- @do_validate = true
- ATTRIBUTES.each do |attr|
- __send__("#{attr}=", nil)
- end
- vars = ATTRIBUTES.dup
- vars.unshift(:do_validate)
- attrs.each do |name, value|
- if vars.include?(name.to_s)
- __send__("#{name}=", value)
- end
- end
- end
-
- def to_s
- rv = ""
- if @href
- rv << %Q[<?xml-stylesheet]
- ATTRIBUTES.each do |name|
- if __send__(name)
- rv << %Q[ #{name}="#{h __send__(name)}"]
- end
- end
- rv << %Q[?>]
- end
- rv
- end
-
- remove_method(:href=)
- def href=(value)
- @href = value
- if @href and @type.nil?
- @type = guess_type(@href)
- end
- @href
- end
-
- remove_method(:alternate=)
- def alternate=(value)
- if value.nil? or /\A(?:yes|no)\z/ =~ value
- @alternate = value
- else
- if @do_validate
- args = ["?xml-stylesheet?", %Q[alternate="#{value}"]]
- raise NotAvailableValueError.new(*args)
- end
- end
- @alternate
- end
-
- def setup_maker(maker)
- xss = maker.xml_stylesheets.new_xml_stylesheet
- ATTRIBUTES.each do |attr|
- xss.__send__("#{attr}=", __send__(attr))
- end
- end
-
- private
- def guess_type(filename)
- /\.([^.]+)$/ =~ filename
- GUESS_TABLE[$1]
- end
-
- end
-end
diff --git a/ruby_2_2/lib/rss/xml.rb b/ruby_2_2/lib/rss/xml.rb
deleted file mode 100644
index 1ae878b772..0000000000
--- a/ruby_2_2/lib/rss/xml.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-require "rss/utils"
-
-module RSS
- module XML
- class Element
- include Enumerable
-
- attr_reader :name, :prefix, :uri, :attributes, :children
- def initialize(name, prefix=nil, uri=nil, attributes={}, children=[])
- @name = name
- @prefix = prefix
- @uri = uri
- @attributes = attributes
- if children.is_a?(String) or !children.respond_to?(:each)
- @children = [children]
- else
- @children = children
- end
- end
-
- def [](name)
- @attributes[name]
- end
-
- def []=(name, value)
- @attributes[name] = value
- end
-
- def <<(child)
- @children << child
- end
-
- def each(&block)
- @children.each(&block)
- end
-
- def ==(other)
- other.kind_of?(self.class) and
- @name == other.name and
- @uri == other.uri and
- @attributes == other.attributes and
- @children == other.children
- end
-
- def to_s
- rv = "<#{full_name}"
- attributes.each do |key, value|
- rv << " #{Utils.html_escape(key)}=\"#{Utils.html_escape(value)}\""
- end
- if children.empty?
- rv << "/>"
- else
- rv << ">"
- children.each do |child|
- rv << child.to_s
- end
- rv << "</#{full_name}>"
- end
- rv
- end
-
- def full_name
- if @prefix
- "#{@prefix}:#{@name}"
- else
- @name
- end
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rss/xmlparser.rb b/ruby_2_2/lib/rss/xmlparser.rb
deleted file mode 100644
index 46df94a320..0000000000
--- a/ruby_2_2/lib/rss/xmlparser.rb
+++ /dev/null
@@ -1,94 +0,0 @@
-begin
- require "xml/parser"
-rescue LoadError
- require "xmlparser"
-end
-
-begin
- require "xml/encoding-ja"
-rescue LoadError
- require "xmlencoding-ja"
- if defined?(Kconv)
- module XMLEncoding_ja
- class SJISHandler
- include Kconv
- end
- end
- end
-end
-
-module XML
- class Parser
- unless defined?(Error)
- # This error is legacy, so we just set it to the new one
- Error = ::XMLParserError # :nodoc:
- end
- end
-end
-
-module RSS
-
- class REXMLLikeXMLParser < ::XML::Parser
-
- include ::XML::Encoding_ja
-
- def listener=(listener)
- @listener = listener
- end
-
- def startElement(name, attrs)
- @listener.tag_start(name, attrs)
- end
-
- def endElement(name)
- @listener.tag_end(name)
- end
-
- def character(data)
- @listener.text(data)
- end
-
- def xmlDecl(version, encoding, standalone)
- @listener.xmldecl(version, encoding, standalone == 1)
- end
-
- def processingInstruction(target, content)
- @listener.instruction(target, content)
- end
-
- end
-
- class XMLParserParser < BaseParser
-
- class << self
- def listener
- XMLParserListener
- end
- end
-
- private
- def _parse
- begin
- parser = REXMLLikeXMLParser.new
- parser.listener = @listener
- parser.parse(@rss)
- rescue ::XML::Parser::Error => e
- raise NotWellFormedError.new(parser.line){e.message}
- end
- end
-
- end
-
- class XMLParserListener < BaseListener
-
- include ListenerMixin
-
- def xmldecl(version, encoding, standalone)
- super
- # Encoding is converted to UTF-8 when XMLParser parses XML.
- @encoding = 'UTF-8'
- end
-
- end
-
-end
diff --git a/ruby_2_2/lib/rss/xmlscanner.rb b/ruby_2_2/lib/rss/xmlscanner.rb
deleted file mode 100644
index 1cdf81c0c3..0000000000
--- a/ruby_2_2/lib/rss/xmlscanner.rb
+++ /dev/null
@@ -1,121 +0,0 @@
-require 'xmlscan/scanner'
-require 'stringio'
-
-module RSS
-
- class XMLScanParser < BaseParser
-
- class << self
- def listener
- XMLScanListener
- end
- end
-
- private
- def _parse
- begin
- if @rss.is_a?(String)
- input = StringIO.new(@rss)
- else
- input = @rss
- end
- scanner = XMLScan::XMLScanner.new(@listener)
- scanner.parse(input)
- rescue XMLScan::Error => e
- lineno = e.lineno || scanner.lineno || input.lineno
- raise NotWellFormedError.new(lineno){e.message}
- end
- end
-
- end
-
- class XMLScanListener < BaseListener
-
- include XMLScan::Visitor
- include ListenerMixin
-
- ENTITIES = {
- 'lt' => '<',
- 'gt' => '>',
- 'amp' => '&',
- 'quot' => '"',
- 'apos' => '\''
- }
-
- def on_xmldecl_version(str)
- @version = str
- end
-
- def on_xmldecl_encoding(str)
- @encoding = str
- end
-
- def on_xmldecl_standalone(str)
- @standalone = str
- end
-
- def on_xmldecl_end
- xmldecl(@version, @encoding, @standalone == "yes")
- end
-
- alias_method(:on_pi, :instruction)
- alias_method(:on_chardata, :text)
- alias_method(:on_cdata, :text)
-
- def on_etag(name)
- tag_end(name)
- end
-
- def on_entityref(ref)
- text(entity(ref))
- end
-
- def on_charref(code)
- text([code].pack('U'))
- end
-
- alias_method(:on_charref_hex, :on_charref)
-
- def on_stag(name)
- @attrs = {}
- end
-
- def on_attribute(name)
- @attrs[name] = @current_attr = ''
- end
-
- def on_attr_value(str)
- @current_attr << str
- end
-
- def on_attr_entityref(ref)
- @current_attr << entity(ref)
- end
-
- def on_attr_charref(code)
- @current_attr << [code].pack('U')
- end
-
- alias_method(:on_attr_charref_hex, :on_attr_charref)
-
- def on_stag_end(name)
- tag_start(name, @attrs)
- end
-
- def on_stag_end_empty(name)
- tag_start(name, @attrs)
- tag_end(name)
- end
-
- private
- def entity(ref)
- ent = ENTITIES[ref]
- if ent
- ent
- else
- wellformed_error("undefined entity: #{ref}")
- end
- end
- end
-
-end
diff --git a/ruby_2_2/lib/rubygems.rb b/ruby_2_2/lib/rubygems.rb
deleted file mode 100644
index 6a30e315de..0000000000
--- a/ruby_2_2/lib/rubygems.rb
+++ /dev/null
@@ -1,1246 +0,0 @@
-# -*- ruby -*-
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'rbconfig'
-require 'thread'
-
-module Gem
- VERSION = '2.4.5.4'
-end
-
-# Must be first since it unloads the prelude from 1.9.2
-require 'rubygems/compatibility'
-
-require 'rubygems/defaults'
-require 'rubygems/deprecate'
-require 'rubygems/errors'
-
-##
-# RubyGems is the Ruby standard for publishing and managing third party
-# libraries.
-#
-# For user documentation, see:
-#
-# * <tt>gem help</tt> and <tt>gem help [command]</tt>
-# * {RubyGems User Guide}[http://docs.rubygems.org/read/book/1]
-# * {Frequently Asked Questions}[http://docs.rubygems.org/read/book/3]
-#
-# For gem developer documentation see:
-#
-# * {Creating Gems}[http://docs.rubygems.org/read/chapter/5]
-# * Gem::Specification
-# * Gem::Version for version dependency notes
-#
-# Further RubyGems documentation can be found at:
-#
-# * {RubyGems Guides}[http://guides.rubygems.org]
-# * {RubyGems API}[http://rubygems.rubyforge.org/rdoc] (also available from
-# <tt>gem server</tt>)
-#
-# == RubyGems Plugins
-#
-# As of RubyGems 1.3.2, RubyGems will load plugins installed in gems or
-# $LOAD_PATH. Plugins must be named 'rubygems_plugin' (.rb, .so, etc) and
-# placed at the root of your gem's #require_path. Plugins are discovered via
-# Gem::find_files then loaded. Take care when implementing a plugin as your
-# plugin file may be loaded multiple times if multiple versions of your gem
-# are installed.
-#
-# For an example plugin, see the graph gem which adds a `gem graph` command.
-#
-# == RubyGems Defaults, Packaging
-#
-# RubyGems defaults are stored in rubygems/defaults.rb. If you're packaging
-# RubyGems or implementing Ruby you can change RubyGems' defaults.
-#
-# For RubyGems packagers, provide lib/rubygems/defaults/operating_system.rb
-# and override any defaults from lib/rubygems/defaults.rb.
-#
-# For Ruby implementers, provide lib/rubygems/defaults/#{RUBY_ENGINE}.rb and
-# override any defaults from lib/rubygems/defaults.rb.
-#
-# If you need RubyGems to perform extra work on install or uninstall, your
-# defaults override file can set pre and post install and uninstall hooks.
-# See Gem::pre_install, Gem::pre_uninstall, Gem::post_install,
-# Gem::post_uninstall.
-#
-# == Bugs
-#
-# You can submit bugs to the
-# {RubyGems bug tracker}[https://github.com/rubygems/rubygems/issues]
-# on GitHub
-#
-# == Credits
-#
-# RubyGems is currently maintained by Eric Hodel.
-#
-# RubyGems was originally developed at RubyConf 2003 by:
-#
-# * Rich Kilmer -- rich(at)infoether.com
-# * Chad Fowler -- chad(at)chadfowler.com
-# * David Black -- dblack(at)wobblini.net
-# * Paul Brannan -- paul(at)atdesk.com
-# * Jim Weirich -- jim(at)weirichhouse.org
-#
-# Contributors:
-#
-# * Gavin Sinclair -- gsinclair(at)soyabean.com.au
-# * George Marrows -- george.marrows(at)ntlworld.com
-# * Dick Davies -- rasputnik(at)hellooperator.net
-# * Mauricio Fernandez -- batsman.geo(at)yahoo.com
-# * Simon Strandgaard -- neoneye(at)adslhome.dk
-# * Dave Glasser -- glasser(at)mit.edu
-# * Paul Duncan -- pabs(at)pablotron.org
-# * Ville Aine -- vaine(at)cs.helsinki.fi
-# * Eric Hodel -- drbrain(at)segment7.net
-# * Daniel Berger -- djberg96(at)gmail.com
-# * Phil Hagelberg -- technomancy(at)gmail.com
-# * Ryan Davis -- ryand-ruby(at)zenspider.com
-# * Evan Phoenix -- evan(at)fallingsnow.net
-# * Steve Klabnik -- steve(at)steveklabnik.com
-#
-# (If your name is missing, PLEASE let us know!)
-#
-# See {LICENSE.txt}[rdoc-ref:lib/rubygems/LICENSE.txt] for permissions.
-#
-# Thanks!
-#
-# -The RubyGems Team
-
-
-module Gem
- RUBYGEMS_DIR = File.dirname File.expand_path(__FILE__)
-
- ##
- # An Array of Regexps that match windows Ruby platforms.
-
- WIN_PATTERNS = [
- /bccwin/i,
- /cygwin/i,
- /djgpp/i,
- /mingw/i,
- /mswin/i,
- /wince/i,
- ]
-
- GEM_DEP_FILES = %w[
- gem.deps.rb
- Gemfile
- Isolate
- ]
-
- ##
- # Subdirectories in a gem repository
-
- REPOSITORY_SUBDIRECTORIES = %w[
- build_info
- cache
- doc
- extensions
- gems
- specifications
- ]
-
- ##
- # Subdirectories in a gem repository for default gems
-
- REPOSITORY_DEFAULT_GEM_SUBDIRECTORIES = %w[
- gems
- specifications/default
- ]
-
- @@win_platform = nil
-
- @configuration = nil
- @loaded_specs = {}
- LOADED_SPECS_MUTEX = Mutex.new
- @path_to_default_spec_map = {}
- @platforms = []
- @ruby = nil
- @ruby_api_version = nil
- @sources = nil
-
- @post_build_hooks ||= []
- @post_install_hooks ||= []
- @post_uninstall_hooks ||= []
- @pre_uninstall_hooks ||= []
- @pre_install_hooks ||= []
- @pre_reset_hooks ||= []
- @post_reset_hooks ||= []
-
- ##
- # Try to activate a gem containing +path+. Returns true if
- # activation succeeded or wasn't needed because it was already
- # activated. Returns false if it can't find the path in a gem.
-
- def self.try_activate path
- # finds the _latest_ version... regardless of loaded specs and their deps
- # if another gem had a requirement that would mean we shouldn't
- # activate the latest version, then either it would already be activated
- # or if it was ambiguous (and thus unresolved) the code in our custom
- # require will try to activate the more specific version.
-
- spec = Gem::Specification.find_inactive_by_path path
-
- unless spec
- spec = Gem::Specification.find_by_path path
- return true if spec && spec.activated?
- return false
- end
-
- begin
- spec.activate
- rescue Gem::LoadError # this could fail due to gem dep collisions, go lax
- Gem::Specification.find_by_name(spec.name).activate
- end
-
- return true
- end
-
- def self.needs
- rs = Gem::RequestSet.new
-
- yield rs
-
- finish_resolve rs
- end
-
- def self.finish_resolve(request_set=Gem::RequestSet.new)
- request_set.import Gem::Specification.unresolved_deps.values
-
- request_set.resolve_current.each do |s|
- s.full_spec.activate
- end
- end
-
- ##
- # Find the full path to the executable for gem +name+. If the +exec_name+
- # is not given, the gem's default_executable is chosen, otherwise the
- # specified executable's path is returned. +requirements+ allows
- # you to specify specific gem versions.
-
- def self.bin_path(name, exec_name = nil, *requirements)
- # TODO: fails test_self_bin_path_bin_file_gone_in_latest
- # Gem::Specification.find_by_name(name, *requirements).bin_file exec_name
-
- raise ArgumentError, "you must supply exec_name" unless exec_name
-
- requirements = Gem::Requirement.default if
- requirements.empty?
-
- dep = Gem::Dependency.new name, requirements
-
- loaded = Gem.loaded_specs[name]
-
- return loaded.bin_file exec_name if loaded && dep.matches_spec?(loaded)
-
- specs = dep.matching_specs(true)
-
- raise Gem::GemNotFoundException,
- "can't find gem #{name} (#{requirements})" if specs.empty?
-
- specs = specs.find_all { |spec|
- spec.executables.include? exec_name
- } if exec_name
-
- unless spec = specs.last
- msg = "can't find gem #{name} (#{requirements}) with executable #{exec_name}"
- raise Gem::GemNotFoundException, msg
- end
-
- spec.bin_file exec_name
- end
-
- ##
- # The mode needed to read a file as straight binary.
-
- def self.binary_mode
- 'rb'
- end
-
- ##
- # The path where gem executables are to be installed.
-
- def self.bindir(install_dir=Gem.dir)
- return File.join install_dir, 'bin' unless
- install_dir.to_s == Gem.default_dir.to_s
- Gem.default_bindir
- end
-
- ##
- # Reset the +dir+ and +path+ values. The next time +dir+ or +path+
- # is requested, the values will be calculated from scratch. This is
- # mainly used by the unit tests to provide test isolation.
-
- def self.clear_paths
- @paths = nil
- @user_home = nil
- Gem::Specification.reset
- Gem::Security.reset if defined?(Gem::Security)
- end
-
- ##
- # The path to standard location of the user's .gemrc file.
-
- def self.config_file
- @config_file ||= File.join Gem.user_home, '.gemrc'
- end
-
- ##
- # The standard configuration object for gems.
-
- def self.configuration
- @configuration ||= Gem::ConfigFile.new []
- end
-
- ##
- # Use the given configuration object (which implements the ConfigFile
- # protocol) as the standard configuration object.
-
- def self.configuration=(config)
- @configuration = config
- end
-
- ##
- # The path to the data directory specified by the gem name. If the
- # package is not available as a gem, return nil.
-
- def self.datadir(gem_name)
-# TODO: deprecate and move to Gem::Specification
-# and drop the extra ", gem_name" which is uselessly redundant
- spec = @loaded_specs[gem_name]
- return nil if spec.nil?
- File.join spec.full_gem_path, "data", gem_name
- end
-
- ##
- # A Zlib::Deflate.deflate wrapper
-
- def self.deflate(data)
- require 'zlib'
- Zlib::Deflate.deflate data
- end
-
- # Retrieve the PathSupport object that RubyGems uses to
- # lookup files.
-
- def self.paths
- @paths ||= Gem::PathSupport.new
- end
-
- # Initialize the filesystem paths to use from +env+.
- # +env+ is a hash-like object (typically ENV) that
- # is queried for 'GEM_HOME', 'GEM_PATH', and 'GEM_SPEC_CACHE'
-
- def self.paths=(env)
- clear_paths
- @paths = Gem::PathSupport.new env
- Gem::Specification.dirs = @paths.path
- end
-
- ##
- # The path where gems are to be installed.
- #--
- # FIXME deprecate these once everything else has been done -ebh
-
- def self.dir
- paths.home
- end
-
- def self.path
- paths.path
- end
-
- def self.spec_cache_dir
- paths.spec_cache_dir
- end
-
- ##
- # Quietly ensure the Gem directory +dir+ contains all the proper
- # subdirectories. If we can't create a directory due to a permission
- # problem, then we will silently continue.
- #
- # If +mode+ is given, missing directories are created with this mode.
- #
- # World-writable directories will never be created.
-
- def self.ensure_gem_subdirectories dir = Gem.dir, mode = nil
- ensure_subdirectories(dir, mode, REPOSITORY_SUBDIRECTORIES)
- end
-
- ##
- # Quietly ensure the Gem directory +dir+ contains all the proper
- # subdirectories for handling default gems. If we can't create a
- # directory due to a permission problem, then we will silently continue.
- #
- # If +mode+ is given, missing directories are created with this mode.
- #
- # World-writable directories will never be created.
-
- def self.ensure_default_gem_subdirectories dir = Gem.dir, mode = nil
- ensure_subdirectories(dir, mode, REPOSITORY_DEFAULT_GEM_SUBDIRECTORIES)
- end
-
- def self.ensure_subdirectories dir, mode, subdirs # :nodoc:
- old_umask = File.umask
- File.umask old_umask | 002
-
- require 'fileutils'
-
- options = {}
-
- options[:mode] = mode if mode
-
- subdirs.each do |name|
- subdir = File.join dir, name
- next if File.exist? subdir
- FileUtils.mkdir_p subdir, options rescue nil
- end
- ensure
- File.umask old_umask
- end
-
- ##
- # The extension API version of ruby. This includes the static vs non-static
- # distinction as extensions cannot be shared between the two.
-
- def self.extension_api_version # :nodoc:
- if 'no' == RbConfig::CONFIG['ENABLE_SHARED'] then
- "#{ruby_api_version}-static"
- else
- ruby_api_version
- end
- end
-
- ##
- # Returns a list of paths matching +glob+ that can be used by a gem to pick
- # up features from other gems. For example:
- #
- # Gem.find_files('rdoc/discover').each do |path| load path end
- #
- # if +check_load_path+ is true (the default), then find_files also searches
- # $LOAD_PATH for files as well as gems.
- #
- # Note that find_files will return all files even if they are from different
- # versions of the same gem. See also find_latest_files
-
- def self.find_files(glob, check_load_path=true)
- files = []
-
- files = find_files_from_load_path glob if check_load_path
-
- files.concat Gem::Specification.map { |spec|
- spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}")
- }.flatten
-
- # $LOAD_PATH might contain duplicate entries or reference
- # the spec dirs directly, so we prune.
- files.uniq! if check_load_path
-
- return files
- end
-
- def self.find_files_from_load_path glob # :nodoc:
- $LOAD_PATH.map { |load_path|
- Dir["#{File.expand_path glob, load_path}#{Gem.suffix_pattern}"]
- }.flatten.select { |file| File.file? file.untaint }
- end
-
- ##
- # Returns a list of paths matching +glob+ from the latest gems that can be
- # used by a gem to pick up features from other gems. For example:
- #
- # Gem.find_latest_files('rdoc/discover').each do |path| load path end
- #
- # if +check_load_path+ is true (the default), then find_latest_files also
- # searches $LOAD_PATH for files as well as gems.
- #
- # Unlike find_files, find_latest_files will return only files from the
- # latest version of a gem.
-
- def self.find_latest_files(glob, check_load_path=true)
- files = []
-
- files = find_files_from_load_path glob if check_load_path
-
- files.concat Gem::Specification.latest_specs(true).map { |spec|
- spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}")
- }.flatten
-
- # $LOAD_PATH might contain duplicate entries or reference
- # the spec dirs directly, so we prune.
- files.uniq! if check_load_path
-
- return files
- end
-
- ##
- # Finds the user's home directory.
- #--
- # Some comments from the ruby-talk list regarding finding the home
- # directory:
- #
- # I have HOME, USERPROFILE and HOMEDRIVE + HOMEPATH. Ruby seems
- # to be depending on HOME in those code samples. I propose that
- # it should fallback to USERPROFILE and HOMEDRIVE + HOMEPATH (at
- # least on Win32).
- #++
- #--
- #
- # FIXME move to pathsupport
- #
- #++
-
- def self.find_home
- windows = File::ALT_SEPARATOR
- if not windows or RUBY_VERSION >= '1.9' then
- File.expand_path "~"
- else
- ['HOME', 'USERPROFILE'].each do |key|
- return File.expand_path ENV[key] if ENV[key]
- end
-
- if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] then
- File.expand_path "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}"
- end
- end
- rescue
- if windows then
- File.expand_path File.join(ENV['HOMEDRIVE'] || ENV['SystemDrive'], '/')
- else
- File.expand_path "/"
- end
- end
-
- private_class_method :find_home
-
- # FIXME deprecate these in 3.0
-
- ##
- # Zlib::GzipReader wrapper that unzips +data+.
-
- def self.gunzip(data)
- require 'rubygems/util'
- Gem::Util.gunzip data
- end
-
- ##
- # Zlib::GzipWriter wrapper that zips +data+.
-
- def self.gzip(data)
- require 'rubygems/util'
- Gem::Util.gzip data
- end
-
- ##
- # A Zlib::Inflate#inflate wrapper
-
- def self.inflate(data)
- require 'rubygems/util'
- Gem::Util.inflate data
- end
-
- ##
- # Top level install helper method. Allows you to install gems interactively:
- #
- # % irb
- # >> Gem.install "minitest"
- # Fetching: minitest-3.0.1.gem (100%)
- # => [#<Gem::Specification:0x1013b4528 @name="minitest", ...>]
-
- def self.install name, version = Gem::Requirement.default, *options
- require "rubygems/dependency_installer"
- inst = Gem::DependencyInstaller.new(*options)
- inst.install name, version
- inst.installed_gems
- end
-
- ##
- # Get the default RubyGems API host. This is normally
- # <tt>https://rubygems.org</tt>.
-
- def self.host
- # TODO: move to utils
- @host ||= Gem::DEFAULT_HOST
- end
-
- ## Set the default RubyGems API host.
-
- def self.host= host
- # TODO: move to utils
- @host = host
- end
-
- ##
- # The index to insert activated gem paths into the $LOAD_PATH. The activated
- # gem's paths are inserted before site lib directory by default.
-
- def self.load_path_insert_index
- index = $LOAD_PATH.index RbConfig::CONFIG['sitelibdir']
-
- index
- end
-
- @yaml_loaded = false
-
- ##
- # Loads YAML, preferring Psych
-
- def self.load_yaml
- return if @yaml_loaded
- return unless defined?(gem)
-
- test_syck = ENV['TEST_SYCK']
-
- unless test_syck
- begin
- gem 'psych', '~> 2.0.0'
- rescue Gem::LoadError
- # It's OK if the user does not have the psych gem installed. We will
- # attempt to require the stdlib version
- end
-
- begin
- # Try requiring the gem version *or* stdlib version of psych.
- require 'psych'
- rescue ::LoadError
- # If we can't load psych, thats fine, go on.
- else
- # If 'yaml' has already been required, then we have to
- # be sure to switch it over to the newly loaded psych.
- if defined?(YAML::ENGINE) && YAML::ENGINE.yamler != "psych"
- YAML::ENGINE.yamler = "psych"
- end
-
- require 'rubygems/psych_additions'
- require 'rubygems/psych_tree'
- end
- end
-
- require 'yaml'
- require 'rubygems/safe_yaml'
-
- # If we're supposed to be using syck, then we may have to force
- # activate it via the YAML::ENGINE API.
- if test_syck and defined?(YAML::ENGINE)
- YAML::ENGINE.yamler = "syck" unless YAML::ENGINE.syck?
- end
-
- # Now that we're sure some kind of yaml library is loaded, pull
- # in our hack to deal with Syck's DefaultKey ugliness.
- require 'rubygems/syck_hack'
-
- @yaml_loaded = true
- end
-
- ##
- # The file name and line number of the caller of the caller of this method.
-
- def self.location_of_caller
- caller[1] =~ /(.*?):(\d+).*?$/i
- file = $1
- lineno = $2.to_i
-
- [file, lineno]
- end
-
- ##
- # The version of the Marshal format for your Ruby.
-
- def self.marshal_version
- "#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}"
- end
-
- ##
- # Set array of platforms this RubyGems supports (primarily for testing).
-
- def self.platforms=(platforms)
- @platforms = platforms
- end
-
- ##
- # Array of platforms this RubyGems supports.
-
- def self.platforms
- @platforms ||= []
- if @platforms.empty?
- @platforms = [Gem::Platform::RUBY, Gem::Platform.local]
- end
- @platforms
- end
-
- ##
- # Adds a post-build hook that will be passed an Gem::Installer instance
- # when Gem::Installer#install is called. The hook is called after the gem
- # has been extracted and extensions have been built but before the
- # executables or gemspec has been written. If the hook returns +false+ then
- # the gem's files will be removed and the install will be aborted.
-
- def self.post_build(&hook)
- @post_build_hooks << hook
- end
-
- ##
- # Adds a post-install hook that will be passed an Gem::Installer instance
- # when Gem::Installer#install is called
-
- def self.post_install(&hook)
- @post_install_hooks << hook
- end
-
- ##
- # Adds a post-installs hook that will be passed a Gem::DependencyInstaller
- # and a list of installed specifications when
- # Gem::DependencyInstaller#install is complete
-
- def self.done_installing(&hook)
- @done_installing_hooks << hook
- end
-
- ##
- # Adds a hook that will get run after Gem::Specification.reset is
- # run.
-
- def self.post_reset(&hook)
- @post_reset_hooks << hook
- end
-
- ##
- # Adds a post-uninstall hook that will be passed a Gem::Uninstaller instance
- # and the spec that was uninstalled when Gem::Uninstaller#uninstall is
- # called
-
- def self.post_uninstall(&hook)
- @post_uninstall_hooks << hook
- end
-
- ##
- # Adds a pre-install hook that will be passed an Gem::Installer instance
- # when Gem::Installer#install is called. If the hook returns +false+ then
- # the install will be aborted.
-
- def self.pre_install(&hook)
- @pre_install_hooks << hook
- end
-
- ##
- # Adds a hook that will get run before Gem::Specification.reset is
- # run.
-
- def self.pre_reset(&hook)
- @pre_reset_hooks << hook
- end
-
- ##
- # Adds a pre-uninstall hook that will be passed an Gem::Uninstaller instance
- # and the spec that will be uninstalled when Gem::Uninstaller#uninstall is
- # called
-
- def self.pre_uninstall(&hook)
- @pre_uninstall_hooks << hook
- end
-
- ##
- # The directory prefix this RubyGems was installed at. If your
- # prefix is in a standard location (ie, rubygems is installed where
- # you'd expect it to be), then prefix returns nil.
-
- def self.prefix
- prefix = File.dirname RUBYGEMS_DIR
-
- if prefix != File.expand_path(RbConfig::CONFIG['sitelibdir']) and
- prefix != File.expand_path(RbConfig::CONFIG['libdir']) and
- 'lib' == File.basename(RUBYGEMS_DIR) then
- prefix
- end
- end
-
- ##
- # Refresh available gems from disk.
-
- def self.refresh
- Gem::Specification.reset
- end
-
- ##
- # Safely read a file in binary mode on all platforms.
-
- def self.read_binary(path)
- open path, 'rb+' do |f|
- f.flock(File::LOCK_EX)
- f.read
- end
- rescue Errno::EACCES
- open path, 'rb' do |f|
- f.read
- end
- end
-
- ##
- # The path to the running Ruby interpreter.
-
- def self.ruby
- if @ruby.nil? then
- @ruby = File.join(RbConfig::CONFIG['bindir'],
- "#{RbConfig::CONFIG['ruby_install_name']}#{RbConfig::CONFIG['EXEEXT']}")
-
- @ruby = "\"#{@ruby}\"" if @ruby =~ /\s/
- end
-
- @ruby
- end
-
- ##
- # Returns a String containing the API compatibility version of Ruby
-
- def self.ruby_api_version
- @ruby_api_version ||= RbConfig::CONFIG['ruby_version'].dup
- end
-
- ##
- # Returns the latest release-version specification for the gem +name+.
-
- def self.latest_spec_for name
- dependency = Gem::Dependency.new name
- fetcher = Gem::SpecFetcher.fetcher
- spec_tuples, = fetcher.spec_for_dependency dependency
-
- spec, = spec_tuples.first
-
- spec
- end
-
- ##
- # Returns the latest release version of RubyGems.
-
- def self.latest_rubygems_version
- latest_version_for('rubygems-update') or
- raise "Can't find 'rubygems-update' in any repo. Check `gem source list`."
- end
-
- ##
- # Returns the version of the latest release-version of gem +name+
-
- def self.latest_version_for name
- spec = latest_spec_for name
- spec and spec.version
- end
-
- ##
- # A Gem::Version for the currently running Ruby.
-
- def self.ruby_version
- return @ruby_version if defined? @ruby_version
- version = RUBY_VERSION.dup
-
- if defined?(RUBY_PATCHLEVEL) && RUBY_PATCHLEVEL != -1 then
- version << ".#{RUBY_PATCHLEVEL}"
- elsif defined?(RUBY_REVISION) then
- version << ".dev.#{RUBY_REVISION}"
- end
-
- @ruby_version = Gem::Version.new version
- end
-
- ##
- # A Gem::Version for the currently running RubyGems
-
- def self.rubygems_version
- return @rubygems_version if defined? @rubygems_version
- @rubygems_version = Gem::Version.new Gem::VERSION
- end
-
- ##
- # Returns an Array of sources to fetch remote gems from. Uses
- # default_sources if the sources list is empty.
-
- def self.sources
- @sources ||= Gem::SourceList.from(default_sources)
- end
-
- ##
- # Need to be able to set the sources without calling
- # Gem.sources.replace since that would cause an infinite loop.
- #
- # DOC: This comment is not documentation about the method itself, it's
- # more of a code comment about the implementation.
-
- def self.sources= new_sources
- if !new_sources
- @sources = nil
- else
- @sources = Gem::SourceList.from(new_sources)
- end
- end
-
- ##
- # Glob pattern for require-able path suffixes.
-
- def self.suffix_pattern
- @suffix_pattern ||= "{#{suffixes.join(',')}}"
- end
-
- ##
- # Suffixes for require-able paths.
-
- def self.suffixes
- @suffixes ||= ['',
- '.rb',
- *%w(DLEXT DLEXT2).map { |key|
- val = RbConfig::CONFIG[key]
- next unless val and not val.empty?
- ".#{val}"
- }
- ].compact.uniq
- end
-
- ##
- # Prints the amount of time the supplied block takes to run using the debug
- # UI output.
-
- def self.time(msg, width = 0, display = Gem.configuration.verbose)
- now = Time.now
-
- value = yield
-
- elapsed = Time.now - now
-
- ui.say "%2$*1$s: %3$3.3fs" % [-width, msg, elapsed] if display
-
- value
- end
-
- ##
- # Lazily loads DefaultUserInteraction and returns the default UI.
-
- def self.ui
- require 'rubygems/user_interaction'
-
- Gem::DefaultUserInteraction.ui
- end
-
- ##
- # Use the +home+ and +paths+ values for Gem.dir and Gem.path. Used mainly
- # by the unit tests to provide environment isolation.
-
- def self.use_paths(home, *paths)
- paths = nil if paths == [nil]
- paths = paths.first if Array === Array(paths).first
- self.paths = { "GEM_HOME" => home, "GEM_PATH" => paths }
- end
-
- ##
- # The home directory for the user.
-
- def self.user_home
- @user_home ||= find_home.untaint
- end
-
- ##
- # Is this a windows platform?
-
- def self.win_platform?
- if @@win_platform.nil? then
- ruby_platform = RbConfig::CONFIG['host_os']
- @@win_platform = !!WIN_PATTERNS.find { |r| ruby_platform =~ r }
- end
-
- @@win_platform
- end
-
- ##
- # Load +plugins+ as Ruby files
-
- def self.load_plugin_files plugins # :nodoc:
- plugins.each do |plugin|
-
- # Skip older versions of the GemCutter plugin: Its commands are in
- # RubyGems proper now.
-
- next if plugin =~ /gemcutter-0\.[0-3]/
-
- begin
- load plugin
- rescue ::Exception => e
- details = "#{plugin.inspect}: #{e.message} (#{e.class})"
- warn "Error loading RubyGems plugin #{details}"
- end
- end
- end
-
- ##
- # Find the 'rubygems_plugin' files in the latest installed gems and load
- # them
-
- def self.load_plugins
- # Remove this env var by at least 3.0
- if ENV['RUBYGEMS_LOAD_ALL_PLUGINS']
- load_plugin_files find_files('rubygems_plugin', false)
- else
- load_plugin_files find_latest_files('rubygems_plugin', false)
- end
- end
-
- ##
- # Find all 'rubygems_plugin' files in $LOAD_PATH and load them
-
- def self.load_env_plugins
- path = "rubygems_plugin"
-
- files = []
- $LOAD_PATH.each do |load_path|
- globbed = Dir["#{File.expand_path path, load_path}#{Gem.suffix_pattern}"]
-
- globbed.each do |load_path_file|
- files << load_path_file if File.file?(load_path_file.untaint)
- end
- end
-
- load_plugin_files files
- end
-
- ##
- # Looks for a gem dependency file at +path+ and activates the gems in the
- # file if found. If the file is not found an ArgumentError is raised.
- #
- # If +path+ is not given the RUBYGEMS_GEMDEPS environment variable is used,
- # but if no file is found no exception is raised.
- #
- # If '-' is given for +path+ RubyGems searches up from the current working
- # directory for gem dependency files (gem.deps.rb, Gemfile, Isolate) and
- # activates the gems in the first one found.
- #
- # You can run this automatically when rubygems starts. To enable, set
- # the <code>RUBYGEMS_GEMDEPS</code> environment variable to either the path
- # of your gem dependencies file or "-" to auto-discover in parent
- # directories.
- #
- # NOTE: Enabling automatic discovery on multiuser systems can lead to
- # execution of arbitrary code when used from directories outside your
- # control.
-
- def self.use_gemdeps path = nil
- raise_exception = path
-
- path ||= ENV['RUBYGEMS_GEMDEPS']
- return unless path
-
- path = path.dup
-
- if path == "-" then
- require 'rubygems/util'
-
- Gem::Util.traverse_parents Dir.pwd do |directory|
- dep_file = GEM_DEP_FILES.find { |f| File.file?(f) }
-
- next unless dep_file
-
- path = File.join directory, dep_file
- break
- end
- end
-
- path.untaint
-
- unless File.file? path then
- return unless raise_exception
-
- raise ArgumentError, "Unable to find gem dependencies file at #{path}"
- end
-
- rs = Gem::RequestSet.new
- rs.load_gemdeps path
-
- rs.resolve_current.map do |s|
- sp = s.full_spec
- sp.activate
- sp
- end
- rescue Gem::LoadError, Gem::UnsatisfiableDependencyError => e
- warn e.message
- warn "You may need to `gem install -g` to install missing gems"
- warn ""
- end
-
- class << self
- ##
- # TODO remove with RubyGems 3.0
-
- alias detect_gemdeps use_gemdeps # :nodoc:
- end
-
- # FIX: Almost everywhere else we use the `def self.` way of defining class
- # methods, and then we switch over to `class << self` here. Pick one or the
- # other.
- class << self
-
- ##
- # Hash of loaded Gem::Specification keyed by name
-
- attr_reader :loaded_specs
-
- ##
- # Register a Gem::Specification for default gem.
- #
- # Two formats for the specification are supported:
- #
- # * MRI 2.0 style, where spec.files contains unprefixed require names.
- # The spec's filenames will be registered as-is.
- # * New style, where spec.files contains files prefixed with paths
- # from spec.require_paths. The prefixes are stripped before
- # registering the spec's filenames. Unprefixed files are omitted.
- #
-
- def register_default_spec(spec)
- new_format = Gem.default_gems_use_full_paths? || spec.require_paths.any? {|path| spec.files.any? {|f| f.start_with? path } }
-
- if new_format
- prefix_group = spec.require_paths.map {|f| f + "/"}.join("|")
- prefix_pattern = /^(#{prefix_group})/
- end
-
- spec.files.each do |file|
- if new_format
- file = file.sub(prefix_pattern, "")
- next unless $~
- end
-
- @path_to_default_spec_map[file] = spec
- end
- end
-
- ##
- # Find a Gem::Specification of default gem from +path+
-
- def find_unresolved_default_spec(path)
- Gem.suffixes.each do |suffix|
- spec = @path_to_default_spec_map["#{path}#{suffix}"]
- return spec if spec
- end
- nil
- end
-
- ##
- # Remove needless Gem::Specification of default gem from
- # unresolved default gem list
-
- def remove_unresolved_default_spec(spec)
- spec.files.each do |file|
- @path_to_default_spec_map.delete(file)
- end
- end
-
- ##
- # Clear default gem related variables. It is for test
-
- def clear_default_specs
- @path_to_default_spec_map.clear
- end
-
- ##
- # The list of hooks to be run after Gem::Installer#install extracts files
- # and builds extensions
-
- attr_reader :post_build_hooks
-
- ##
- # The list of hooks to be run after Gem::Installer#install completes
- # installation
-
- attr_reader :post_install_hooks
-
- ##
- # The list of hooks to be run after Gem::DependencyInstaller installs a
- # set of gems
-
- attr_reader :done_installing_hooks
-
- ##
- # The list of hooks to be run after Gem::Specification.reset is run.
-
- attr_reader :post_reset_hooks
-
- ##
- # The list of hooks to be run after Gem::Uninstaller#uninstall completes
- # installation
-
- attr_reader :post_uninstall_hooks
-
- ##
- # The list of hooks to be run before Gem::Installer#install does any work
-
- attr_reader :pre_install_hooks
-
- ##
- # The list of hooks to be run before Gem::Specification.reset is run.
-
- attr_reader :pre_reset_hooks
-
- ##
- # The list of hooks to be run before Gem::Uninstaller#uninstall does any
- # work
-
- attr_reader :pre_uninstall_hooks
- end
-
- ##
- # Location of Marshal quick gemspecs on remote repositories
-
- MARSHAL_SPEC_DIR = "quick/Marshal.#{Gem.marshal_version}/"
-
- autoload :ConfigFile, 'rubygems/config_file'
- autoload :Dependency, 'rubygems/dependency'
- autoload :DependencyList, 'rubygems/dependency_list'
- autoload :DependencyResolver, 'rubygems/resolver'
- autoload :Installer, 'rubygems/installer'
- autoload :PathSupport, 'rubygems/path_support'
- autoload :Platform, 'rubygems/platform'
- autoload :RequestSet, 'rubygems/request_set'
- autoload :Requirement, 'rubygems/requirement'
- autoload :Resolver, 'rubygems/resolver'
- autoload :Source, 'rubygems/source'
- autoload :SourceList, 'rubygems/source_list'
- autoload :SpecFetcher, 'rubygems/spec_fetcher'
- autoload :Specification, 'rubygems/specification'
- autoload :Version, 'rubygems/version'
-
- require "rubygems/specification"
-end
-
-require 'rubygems/exceptions'
-
-# REFACTOR: This should be pulled out into some kind of hacks file.
-gem_preluded = Gem::GEM_PRELUDE_SUCKAGE and defined? Gem
-unless gem_preluded then # TODO: remove guard after 1.9.2 dropped
- begin
- ##
- # Defaults the operating system (or packager) wants to provide for RubyGems.
-
- require 'rubygems/defaults/operating_system'
- rescue LoadError
- end
-
- if defined?(RUBY_ENGINE) then
- begin
- ##
- # Defaults the Ruby implementation wants to provide for RubyGems
-
- require "rubygems/defaults/#{RUBY_ENGINE}"
- rescue LoadError
- end
- end
-end
-
-##
-# Loads the default specs.
-Gem::Specification.load_defaults
-
-require 'rubygems/core_ext/kernel_gem'
-require 'rubygems/core_ext/kernel_require'
-
-Gem.use_gemdeps
-
diff --git a/ruby_2_2/lib/rubygems/LICENSE.txt b/ruby_2_2/lib/rubygems/LICENSE.txt
deleted file mode 100644
index 8a0a51dec1..0000000000
--- a/ruby_2_2/lib/rubygems/LICENSE.txt
+++ /dev/null
@@ -1,54 +0,0 @@
-RubyGems is copyrighted free software by Chad Fowler, Rich Kilmer, Jim
-Weirich and others. You can redistribute it and/or modify it under
-either the terms of the MIT license (see the file MIT.txt), or the
-conditions below:
-
-1. You may make and give away verbatim copies of the source form of the
- software without restriction, provided that you duplicate all of the
- original copyright notices and associated disclaimers.
-
-2. You may modify your copy of the software in any way, provided that
- you do at least ONE of the following:
-
- a. place your modifications in the Public Domain or otherwise
- make them Freely Available, such as by posting said
- modifications to Usenet or an equivalent medium, or by allowing
- the author to include your modifications in the software.
-
- b. use the modified software only within your corporation or
- organization.
-
- c. give non-standard executables non-standard names, with
- instructions on where to get the original software distribution.
-
- d. make other distribution arrangements with the author.
-
-3. You may distribute the software in object code or executable
- form, provided that you do at least ONE of the following:
-
- a. distribute the executables and library files of the software,
- together with instructions (in the manual page or equivalent)
- on where to get the original distribution.
-
- b. accompany the distribution with the machine-readable source of
- the software.
-
- c. give non-standard executables non-standard names, with
- instructions on where to get the original software distribution.
-
- d. make other distribution arrangements with the author.
-
-4. You may modify and include the part of the software into any other
- software (possibly commercial).
-
-5. The scripts and library files supplied as input to or produced as
- output from the software do not automatically fall under the
- copyright of the software, but belong to whomever generated them,
- and may be sold commercially, and may be aggregated with this
- software.
-
-6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- PURPOSE.
-
diff --git a/ruby_2_2/lib/rubygems/available_set.rb b/ruby_2_2/lib/rubygems/available_set.rb
deleted file mode 100644
index dae254b385..0000000000
--- a/ruby_2_2/lib/rubygems/available_set.rb
+++ /dev/null
@@ -1,164 +0,0 @@
-class Gem::AvailableSet
-
- include Enumerable
-
- Tuple = Struct.new(:spec, :source)
-
- attr_accessor :remote # :nodoc:
-
- def initialize
- @set = []
- @sorted = nil
- @remote = true
- end
-
- attr_reader :set
-
- def add(spec, source)
- @set << Tuple.new(spec, source)
- @sorted = nil
- self
- end
-
- def <<(o)
- case o
- when Gem::AvailableSet
- s = o.set
- when Array
- s = o.map do |sp,so|
- if !sp.kind_of?(Gem::Specification) or !so.kind_of?(Gem::Source)
- raise TypeError, "Array must be in [[spec, source], ...] form"
- end
-
- Tuple.new(sp,so)
- end
- else
- raise TypeError, "must be a Gem::AvailableSet"
- end
-
- @set += s
- @sorted = nil
-
- self
- end
-
- ##
- # Yields each Tuple in this AvailableSet
-
- def each
- return enum_for __method__ unless block_given?
-
- @set.each do |tuple|
- yield tuple
- end
- end
-
- ##
- # Yields the Gem::Specification for each Tuple in this AvailableSet
-
- def each_spec
- return enum_for __method__ unless block_given?
-
- each do |tuple|
- yield tuple.spec
- end
- end
-
- def empty?
- @set.empty?
- end
-
- def all_specs
- @set.map { |t| t.spec }
- end
-
- def match_platform!
- @set.reject! { |t| !Gem::Platform.match(t.spec.platform) }
- @sorted = nil
- self
- end
-
- def sorted
- @sorted ||= @set.sort do |a,b|
- i = b.spec <=> a.spec
- i != 0 ? i : (a.source <=> b.source)
- end
- end
-
- def size
- @set.size
- end
-
- def source_for(spec)
- f = @set.find { |t| t.spec == spec }
- f.source
- end
-
- ##
- # Converts this AvailableSet into a RequestSet that can be used to install
- # gems.
- #
- # If +development+ is :none then no development dependencies are installed.
- # Other options are :shallow for only direct development dependencies of the
- # gems in this set or :all for all development dependencies.
-
- def to_request_set development = :none
- request_set = Gem::RequestSet.new
- request_set.development = :all == development
-
- each_spec do |spec|
- request_set.always_install << spec
-
- request_set.gem spec.name, spec.version
- request_set.import spec.development_dependencies if
- :shallow == development
- end
-
- request_set
- end
-
- ##
- #
- # Used by the Resolver, the protocol to use a AvailableSet as a
- # search Set.
-
- def find_all(req)
- dep = req.dependency
-
- match = @set.find_all do |t|
- dep.match? t.spec
- end
-
- match.map do |t|
- Gem::Resolver::LocalSpecification.new(self, t.spec, t.source)
- end
- end
-
- def prefetch(reqs)
- end
-
- def pick_best!
- return self if empty?
-
- @set = [sorted.first]
- @sorted = nil
- self
- end
-
- def remove_installed!(dep)
- @set.reject! do |t|
- # already locally installed
- Gem::Specification.any? do |installed_spec|
- dep.name == installed_spec.name and
- dep.requirement.satisfied_by? installed_spec.version
- end
- end
-
- @sorted = nil
- self
- end
-
- def inject_into_list(dep_list)
- @set.each { |t| dep_list.add t.spec }
- end
-end
diff --git a/ruby_2_2/lib/rubygems/basic_specification.rb b/ruby_2_2/lib/rubygems/basic_specification.rb
deleted file mode 100644
index f5fb0f5d97..0000000000
--- a/ruby_2_2/lib/rubygems/basic_specification.rb
+++ /dev/null
@@ -1,290 +0,0 @@
-##
-# BasicSpecification is an abstract class which implements some common code
-# used by both Specification and StubSpecification.
-
-class Gem::BasicSpecification
-
- ##
- # Allows installation of extensions for git: gems.
-
- attr_writer :base_dir # :nodoc:
-
- ##
- # Sets the directory where extensions for this gem will be installed.
-
- attr_writer :extension_dir # :nodoc:
-
- ##
- # Is this specification ignored for activation purposes?
-
- attr_writer :ignored # :nodoc:
-
- ##
- # The path this gemspec was loaded from. This attribute is not persisted.
-
- attr_reader :loaded_from
-
- ##
- # Allows correct activation of git: and path: gems.
-
- attr_writer :full_gem_path # :nodoc:
-
- def self.default_specifications_dir
- File.join(Gem.default_dir, "specifications", "default")
- end
-
- ##
- # True when the gem has been activated
-
- def activated?
- raise NotImplementedError
- end
-
- ##
- # Returns the full path to the base gem directory.
- #
- # eg: /usr/local/lib/ruby/gems/1.8
-
- def base_dir
- return Gem.dir unless loaded_from
- @base_dir ||= if default_gem? then
- File.dirname File.dirname File.dirname loaded_from
- else
- File.dirname File.dirname loaded_from
- end
- end
-
- ##
- # Return true if this spec can require +file+.
-
- def contains_requirable_file? file
- @contains_requirable_file ||= {}
- @contains_requirable_file[file] ||=
- begin
- if instance_variable_defined?(:@ignored) or
- instance_variable_defined?('@ignored') then
- return false
- elsif missing_extensions? then
- @ignored = true
-
- warn "Ignoring #{full_name} because its extensions are not built. " +
- "Try: gem pristine #{name} --version #{version}"
- return false
- end
-
- suffixes = Gem.suffixes
-
- full_require_paths.any? do |dir|
- base = "#{dir}/#{file}"
- suffixes.any? { |suf| File.file? "#{base}#{suf}" }
- end
- end ? :yes : :no
- @contains_requirable_file[file] == :yes
- end
-
- def default_gem?
- loaded_from &&
- File.dirname(loaded_from) == self.class.default_specifications_dir
- end
-
- ##
- # Returns full path to the directory where gem's extensions are installed.
-
- def extension_dir
- @extension_dir ||= File.expand_path File.join(extensions_dir, full_name)
- end
-
- ##
- # Returns path to the extensions directory.
-
- def extensions_dir
- @extensions_dir ||= Gem.default_ext_dir_for(base_dir) ||
- File.join(base_dir, 'extensions', Gem::Platform.local.to_s,
- Gem.extension_api_version)
- end
-
- def find_full_gem_path # :nodoc:
- # TODO: also, shouldn't it default to full_name if it hasn't been written?
- path = File.expand_path File.join(gems_dir, full_name)
- path.untaint
- path if File.directory? path
- end
-
- private :find_full_gem_path
-
- ##
- # The full path to the gem (install path + full name).
-
- def full_gem_path
- # TODO: This is a heavily used method by gems, so we'll need
- # to aleast just alias it to #gem_dir rather than remove it.
- @full_gem_path ||= find_full_gem_path
- end
-
- ##
- # Returns the full name (name-version) of this Gem. Platform information
- # is included (name-version-platform) if it is specified and not the
- # default Ruby platform.
-
- def full_name
- if platform == Gem::Platform::RUBY or platform.nil? then
- "#{name}-#{version}".untaint
- else
- "#{name}-#{version}-#{platform}".untaint
- end
- end
-
- ##
- # Full paths in the gem to add to <code>$LOAD_PATH</code> when this gem is
- # activated.
-
- def full_require_paths
- @full_require_paths ||=
- begin
- full_paths = raw_require_paths.map do |path|
- File.join full_gem_path, path
- end
-
- full_paths.unshift extension_dir unless @extensions.nil? || @extensions.empty?
-
- full_paths
- end
- end
-
- ##
- # Full path of the target library file.
- # If the file is not in this gem, return nil.
-
- def to_fullpath path
- if activated? then
- @paths_map ||= {}
- @paths_map[path] ||=
- begin
- fullpath = nil
- suffixes = Gem.suffixes
- full_require_paths.find do |dir|
- suffixes.find do |suf|
- File.file?(fullpath = "#{dir}/#{path}#{suf}")
- end
- end ? fullpath : nil
- end
- else
- nil
- end
- end
-
- ##
- # Returns the full path to this spec's gem directory.
- # eg: /usr/local/lib/ruby/1.8/gems/mygem-1.0
-
- def gem_dir
- @gem_dir ||= File.expand_path File.join(gems_dir, full_name)
- end
-
- ##
- # Returns the full path to the gems directory containing this spec's
- # gem directory. eg: /usr/local/lib/ruby/1.8/gems
-
- def gems_dir
- # TODO: this logic seems terribly broken, but tests fail if just base_dir
- @gems_dir ||= File.join(loaded_from && base_dir || Gem.dir, "gems")
- end
-
- ##
- # Set the path the Specification was loaded from. +path+ is converted to a
- # String.
-
- def loaded_from= path
- @loaded_from = path && path.to_s
-
- @extension_dir = nil
- @extensions_dir = nil
- @full_gem_path = nil
- @gem_dir = nil
- @gems_dir = nil
- @base_dir = nil
- end
-
- ##
- # Name of the gem
-
- def name
- raise NotImplementedError
- end
-
- ##
- # Platform of the gem
-
- def platform
- raise NotImplementedError
- end
-
- def raw_require_paths # :nodoc:
- Array(@require_paths)
- end
-
- ##
- # Paths in the gem to add to <code>$LOAD_PATH</code> when this gem is
- # activated.
- #
- # See also #require_paths=
- #
- # If you have an extension you do not need to add <code>"ext"</code> to the
- # require path, the extension build process will copy the extension files
- # into "lib" for you.
- #
- # The default value is <code>"lib"</code>
- #
- # Usage:
- #
- # # If all library files are in the root directory...
- # spec.require_path = '.'
-
- def require_paths
- return raw_require_paths if @extensions.nil? || @extensions.empty?
-
- [extension_dir].concat raw_require_paths
- end
-
- ##
- # Returns the paths to the source files for use with analysis and
- # documentation tools. These paths are relative to full_gem_path.
-
- def source_paths
- paths = raw_require_paths.dup
-
- if @extensions then
- ext_dirs = @extensions.map do |extension|
- extension.split(File::SEPARATOR, 2).first
- end.uniq
-
- paths.concat ext_dirs
- end
-
- paths.uniq
- end
-
- ##
- # Return a Gem::Specification from this gem
-
- def to_spec
- raise NotImplementedError
- end
-
- ##
- # Version of the gem
-
- def version
- raise NotImplementedError
- end
-
- ##
- # Whether this specification is stubbed - i.e. we have information
- # about the gem from a stub line, without having to evaluate the
- # entire gemspec file.
- def stubbed?
- raise NotImplementedError
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/command.rb b/ruby_2_2/lib/rubygems/command.rb
deleted file mode 100644
index 0c6abec56c..0000000000
--- a/ruby_2_2/lib/rubygems/command.rb
+++ /dev/null
@@ -1,582 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'optparse'
-require 'rubygems/requirement'
-require 'rubygems/user_interaction'
-
-##
-# Base class for all Gem commands. When creating a new gem command, define
-# #initialize, #execute, #arguments, #defaults_str, #description and #usage
-# (as appropriate). See the above mentioned methods for details.
-#
-# A very good example to look at is Gem::Commands::ContentsCommand
-
-class Gem::Command
-
- include Gem::UserInteraction
-
- ##
- # The name of the command.
-
- attr_reader :command
-
- ##
- # The options for the command.
-
- attr_reader :options
-
- ##
- # The default options for the command.
-
- attr_accessor :defaults
-
- ##
- # The name of the command for command-line invocation.
-
- attr_accessor :program_name
-
- ##
- # A short description of the command.
-
- attr_accessor :summary
-
- ##
- # Arguments used when building gems
-
- def self.build_args
- @build_args ||= []
- end
-
- def self.build_args=(value)
- @build_args = value
- end
-
- def self.common_options
- @common_options ||= []
- end
-
- def self.add_common_option(*args, &handler)
- Gem::Command.common_options << [args, handler]
- end
-
- def self.extra_args
- @extra_args ||= []
- end
-
- def self.extra_args=(value)
- case value
- when Array
- @extra_args = value
- when String
- @extra_args = value.split
- end
- end
-
- ##
- # Return an array of extra arguments for the command. The extra arguments
- # come from the gem configuration file read at program startup.
-
- def self.specific_extra_args(cmd)
- specific_extra_args_hash[cmd]
- end
-
- ##
- # Add a list of extra arguments for the given command. +args+ may be an
- # array or a string to be split on white space.
-
- def self.add_specific_extra_args(cmd,args)
- args = args.split(/\s+/) if args.kind_of? String
- specific_extra_args_hash[cmd] = args
- end
-
- ##
- # Accessor for the specific extra args hash (self initializing).
-
- def self.specific_extra_args_hash
- @specific_extra_args_hash ||= Hash.new do |h,k|
- h[k] = Array.new
- end
- end
-
- ##
- # Initializes a generic gem command named +command+. +summary+ is a short
- # description displayed in `gem help commands`. +defaults+ are the default
- # options. Defaults should be mirrored in #defaults_str, unless there are
- # none.
- #
- # When defining a new command subclass, use add_option to add command-line
- # switches.
- #
- # Unhandled arguments (gem names, files, etc.) are left in
- # <tt>options[:args]</tt>.
-
- def initialize(command, summary=nil, defaults={})
- @command = command
- @summary = summary
- @program_name = "gem #{command}"
- @defaults = defaults
- @options = defaults.dup
- @option_groups = Hash.new { |h,k| h[k] = [] }
- @parser = nil
- @when_invoked = nil
- end
-
- ##
- # True if +long+ begins with the characters from +short+.
-
- def begins?(long, short)
- return false if short.nil?
- long[0, short.length] == short
- end
-
- ##
- # Override to provide command handling.
- #
- # #options will be filled in with your parsed options, unparsed options will
- # be left in <tt>options[:args]</tt>.
- #
- # See also: #get_all_gem_names, #get_one_gem_name,
- # #get_one_optional_argument
-
- def execute
- raise Gem::Exception, "generic command has no actions"
- end
-
- ##
- # Display to the user that a gem couldn't be found and reasons why
- #--
- # TODO: replace +domain+ with a parameter to suppress suggestions
-
- def show_lookup_failure(gem_name, version, errors, domain)
- if errors and !errors.empty?
- msg = "Could not find a valid gem '#{gem_name}' (#{version}), here is why:\n"
- errors.each { |x| msg << " #{x.wordy}\n" }
- alert_error msg
- else
- alert_error "Could not find a valid gem '#{gem_name}' (#{version}) in any repository"
- end
-
- unless domain == :local then # HACK
- suggestions = Gem::SpecFetcher.fetcher.suggest_gems_from_name gem_name
-
- unless suggestions.empty?
- alert_error "Possible alternatives: #{suggestions.join(", ")}"
- end
- end
- end
-
- ##
- # Get all gem names from the command line.
-
- def get_all_gem_names
- args = options[:args]
-
- if args.nil? or args.empty? then
- raise Gem::CommandLineError,
- "Please specify at least one gem name (e.g. gem build GEMNAME)"
- end
-
- args.select { |arg| arg !~ /^-/ }
- end
-
- ##
- # Get all [gem, version] from the command line.
- #
- # An argument in the form gem:ver is pull apart into the gen name and version,
- # respectively.
- def get_all_gem_names_and_versions
- get_all_gem_names.map do |name|
- if /\A(.*):(#{Gem::Requirement::PATTERN_RAW})\z/ =~ name
- [$1, $2]
- else
- [name]
- end
- end
- end
-
- ##
- # Get a single gem name from the command line. Fail if there is no gem name
- # or if there is more than one gem name given.
-
- def get_one_gem_name
- args = options[:args]
-
- if args.nil? or args.empty? then
- raise Gem::CommandLineError,
- "Please specify a gem name on the command line (e.g. gem build GEMNAME)"
- end
-
- if args.size > 1 then
- raise Gem::CommandLineError,
- "Too many gem names (#{args.join(', ')}); please specify only one"
- end
-
- args.first
- end
-
- ##
- # Get a single optional argument from the command line. If more than one
- # argument is given, return only the first. Return nil if none are given.
-
- def get_one_optional_argument
- args = options[:args] || []
- args.first
- end
-
- ##
- # Override to provide details of the arguments a command takes. It should
- # return a left-justified string, one argument per line.
- #
- # For example:
- #
- # def usage
- # "#{program_name} FILE [FILE ...]"
- # end
- #
- # def arguments
- # "FILE name of file to find"
- # end
-
- def arguments
- ""
- end
-
- ##
- # Override to display the default values of the command options. (similar to
- # +arguments+, but displays the default values).
- #
- # For example:
- #
- # def defaults_str
- # --no-gems-first --no-all
- # end
-
- def defaults_str
- ""
- end
-
- ##
- # Override to display a longer description of what this command does.
-
- def description
- nil
- end
-
- ##
- # Override to display the usage for an individual gem command.
- #
- # The text "[options]" is automatically appended to the usage text.
-
- def usage
- program_name
- end
-
- ##
- # Display the help message for the command.
-
- def show_help
- parser.program_name = usage
- say parser
- end
-
- ##
- # Invoke the command with the given list of arguments.
-
- def invoke(*args)
- invoke_with_build_args args, nil
- end
-
- ##
- # Invoke the command with the given list of normal arguments
- # and additional build arguments.
-
- def invoke_with_build_args(args, build_args)
- handle_options args
-
- options[:build_args] = build_args
-
- if options[:help] then
- show_help
- elsif @when_invoked then
- @when_invoked.call options
- else
- execute
- end
- end
-
- ##
- # Call the given block when invoked.
- #
- # Normal command invocations just executes the +execute+ method of the
- # command. Specifying an invocation block allows the test methods to
- # override the normal action of a command to determine that it has been
- # invoked correctly.
-
- def when_invoked(&block)
- @when_invoked = block
- end
-
- ##
- # Add a command-line option and handler to the command.
- #
- # See OptionParser#make_switch for an explanation of +opts+.
- #
- # +handler+ will be called with two values, the value of the argument and
- # the options hash.
- #
- # If the first argument of add_option is a Symbol, it's used to group
- # options in output. See `gem help list` for an example.
-
- def add_option(*opts, &handler) # :yields: value, options
- group_name = Symbol === opts.first ? opts.shift : :options
-
- @option_groups[group_name] << [opts, handler]
- end
-
- ##
- # Remove previously defined command-line argument +name+.
-
- def remove_option(name)
- @option_groups.each do |_, option_list|
- option_list.reject! { |args, _| args.any? { |x| x =~ /^#{name}/ } }
- end
- end
-
- ##
- # Merge a set of command options with the set of default options (without
- # modifying the default option hash).
-
- def merge_options(new_options)
- @options = @defaults.clone
- new_options.each do |k,v| @options[k] = v end
- end
-
- ##
- # True if the command handles the given argument list.
-
- def handles?(args)
- begin
- parser.parse!(args.dup)
- return true
- rescue
- return false
- end
- end
-
- ##
- # Handle the given list of arguments by parsing them and recording the
- # results.
-
- def handle_options(args)
- args = add_extra_args(args)
- @options = Marshal.load Marshal.dump @defaults # deep copy
- parser.parse!(args)
- @options[:args] = args
- end
-
- ##
- # Adds extra args from ~/.gemrc
-
- def add_extra_args(args)
- result = []
-
- s_extra = Gem::Command.specific_extra_args(@command)
- extra = Gem::Command.extra_args + s_extra
-
- until extra.empty? do
- ex = []
- ex << extra.shift
- ex << extra.shift if extra.first.to_s =~ /^[^-]/
- result << ex if handles?(ex)
- end
-
- result.flatten!
- result.concat(args)
- result
- end
-
- private
-
- def add_parser_description # :nodoc:
- return unless description
-
- formatted = description.split("\n\n").map do |chunk|
- wrap chunk, 80 - 4
- end.join "\n"
-
- @parser.separator nil
- @parser.separator " Description:"
- formatted.split("\n").each do |line|
- @parser.separator " #{line.rstrip}"
- end
- end
-
- def add_parser_options # :nodoc:
- @parser.separator nil
-
- regular_options = @option_groups.delete :options
-
- configure_options "", regular_options
-
- @option_groups.sort_by { |n,_| n.to_s }.each do |group_name, option_list|
- @parser.separator nil
- configure_options group_name, option_list
- end
- end
-
- ##
- # Adds a section with +title+ and +content+ to the parser help view. Used
- # for adding command arguments and default arguments.
-
- def add_parser_run_info title, content
- return if content.empty?
-
- @parser.separator nil
- @parser.separator " #{title}:"
- content.split(/\n/).each do |line|
- @parser.separator " #{line}"
- end
- end
-
- def add_parser_summary # :nodoc:
- return unless @summary
-
- @parser.separator nil
- @parser.separator " Summary:"
- wrap(@summary, 80 - 4).split("\n").each do |line|
- @parser.separator " #{line.strip}"
- end
- end
-
- ##
- # Create on demand parser.
-
- def parser
- create_option_parser if @parser.nil?
- @parser
- end
-
- ##
- # Creates an option parser and fills it in with the help info for the
- # command.
-
- def create_option_parser
- @parser = OptionParser.new
-
- add_parser_options
-
- @parser.separator nil
- configure_options "Common", Gem::Command.common_options
-
- add_parser_run_info "Arguments", arguments
- add_parser_summary
- add_parser_description
- add_parser_run_info "Defaults", defaults_str
- end
-
- def configure_options(header, option_list)
- return if option_list.nil? or option_list.empty?
-
- header = header.to_s.empty? ? '' : "#{header} "
- @parser.separator " #{header}Options:"
-
- option_list.each do |args, handler|
- args.select { |arg| arg =~ /^-/ }
- @parser.on(*args) do |value|
- handler.call(value, @options)
- end
- end
-
- @parser.separator ''
- end
-
- ##
- # Wraps +text+ to +width+
-
- def wrap(text, width) # :doc:
- text.gsub(/(.{1,#{width}})( +|$\n?)|(.{1,#{width}})/, "\\1\\3\n")
- end
-
- # ----------------------------------------------------------------
- # Add the options common to all commands.
-
- add_common_option('-h', '--help',
- 'Get help on this command') do |value, options|
- options[:help] = true
- end
-
- add_common_option('-V', '--[no-]verbose',
- 'Set the verbose level of output') do |value, options|
- # Set us to "really verbose" so the progress meter works
- if Gem.configuration.verbose and value then
- Gem.configuration.verbose = 1
- else
- Gem.configuration.verbose = value
- end
- end
-
- add_common_option('-q', '--quiet', 'Silence commands') do |value, options|
- Gem.configuration.verbose = false
- end
-
- # Backtrace and config-file are added so they show up in the help
- # commands. Both options are actually handled before the other
- # options get parsed.
-
- add_common_option('--config-file FILE',
- 'Use this config file instead of default') do
- end
-
- add_common_option('--backtrace',
- 'Show stack backtrace on errors') do
- end
-
- add_common_option('--debug',
- 'Turn on Ruby debugging') do
- end
-
- # :stopdoc:
-
- HELP = <<-HELP
-RubyGems is a sophisticated package manager for Ruby. This is a
-basic help message containing pointers to more information.
-
- Usage:
- gem -h/--help
- gem -v/--version
- gem command [arguments...] [options...]
-
- Examples:
- gem install rake
- gem list --local
- gem build package.gemspec
- gem help install
-
- Further help:
- gem help commands list all 'gem' commands
- gem help examples show some examples of usage
- gem help gem_dependencies gem dependencies file guide
- gem help platforms gem platforms guide
- gem help <COMMAND> show help on COMMAND
- (e.g. 'gem help install')
- gem server present a web page at
- http://localhost:8808/
- with info about installed gems
- Further information:
- http://guides.rubygems.org
- HELP
-
- # :startdoc:
-
-end
-
-##
-# \Commands will be placed in this namespace
-
-module Gem::Commands
-end
-
diff --git a/ruby_2_2/lib/rubygems/command_manager.rb b/ruby_2_2/lib/rubygems/command_manager.rb
deleted file mode 100644
index 53d18c29cc..0000000000
--- a/ruby_2_2/lib/rubygems/command_manager.rb
+++ /dev/null
@@ -1,218 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'rubygems/command'
-require 'rubygems/user_interaction'
-
-##
-# The command manager registers and installs all the individual sub-commands
-# supported by the gem command.
-#
-# Extra commands can be provided by writing a rubygems_plugin.rb
-# file in an installed gem. You should register your command against the
-# Gem::CommandManager instance, like this:
-#
-# # file rubygems_plugin.rb
-# require 'rubygems/command_manager'
-#
-# Gem::CommandManager.instance.register_command :edit
-#
-# You should put the implementation of your command in rubygems/commands.
-#
-# # file rubygems/commands/edit_command.rb
-# class Gem::Commands::EditCommand < Gem::Command
-# # ...
-# end
-#
-# See Gem::Command for instructions on writing gem commands.
-
-class Gem::CommandManager
-
- include Gem::UserInteraction
-
- BUILTIN_COMMANDS = [ # :nodoc:
- :build,
- :cert,
- :check,
- :cleanup,
- :contents,
- :dependency,
- :environment,
- :fetch,
- :generate_index,
- :help,
- :install,
- :list,
- :lock,
- :mirror,
- :open,
- :outdated,
- :owner,
- :pristine,
- :push,
- :query,
- :rdoc,
- :search,
- :server,
- :sources,
- :specification,
- :stale,
- :uninstall,
- :unpack,
- :update,
- :which,
- :yank,
- ]
-
- ##
- # Return the authoritative instance of the command manager.
-
- def self.instance
- @command_manager ||= new
- end
-
- ##
- # Returns self. Allows a CommandManager instance to stand
- # in for the class itself.
-
- def instance
- self
- end
-
- ##
- # Reset the authoritative instance of the command manager.
-
- def self.reset
- @command_manager = nil
- end
-
- ##
- # Register all the subcommands supported by the gem command.
-
- def initialize
- require 'timeout'
- @commands = {}
-
- BUILTIN_COMMANDS.each do |name|
- register_command name
- end
- end
-
- ##
- # Register the Symbol +command+ as a gem command.
-
- def register_command(command, obj=false)
- @commands[command] = obj
- end
-
- ##
- # Unregister the Symbol +command+ as a gem command.
-
- def unregister_command(command)
- @commands.delete command
- end
-
- ##
- # Returns a Command instance for +command_name+
-
- def [](command_name)
- command_name = command_name.intern
- return nil if @commands[command_name].nil?
- @commands[command_name] ||= load_and_instantiate(command_name)
- end
-
- ##
- # Return a sorted list of all command names as strings.
-
- def command_names
- @commands.keys.collect {|key| key.to_s}.sort
- end
-
- ##
- # Run the command specified by +args+.
-
- def run(args, build_args=nil)
- process_args(args, build_args)
- rescue StandardError, Timeout::Error => ex
- alert_error "While executing gem ... (#{ex.class})\n #{ex}"
- ui.backtrace ex
-
- terminate_interaction(1)
- rescue Interrupt
- alert_error "Interrupted"
- terminate_interaction(1)
- end
-
- def process_args(args, build_args=nil)
- if args.empty? then
- say Gem::Command::HELP
- terminate_interaction 1
- end
-
- case args.first
- when '-h', '--help' then
- say Gem::Command::HELP
- terminate_interaction 0
- when '-v', '--version' then
- say Gem::VERSION
- terminate_interaction 0
- when /^-/ then
- alert_error "Invalid option: #{args.first}. See 'gem --help'."
- terminate_interaction 1
- else
- cmd_name = args.shift.downcase
- cmd = find_command cmd_name
- cmd.invoke_with_build_args args, build_args
- end
- end
-
- def find_command(cmd_name)
- possibilities = find_command_possibilities cmd_name
-
- if possibilities.size > 1 then
- raise Gem::CommandLineError,
- "Ambiguous command #{cmd_name} matches [#{possibilities.join(', ')}]"
- elsif possibilities.empty? then
- raise Gem::CommandLineError, "Unknown command #{cmd_name}"
- end
-
- self[possibilities.first]
- end
-
- def find_command_possibilities(cmd_name)
- len = cmd_name.length
-
- found = command_names.select { |name| cmd_name == name[0, len] }
-
- exact = found.find { |name| name == cmd_name }
-
- exact ? [exact] : found
- end
-
- private
-
- def load_and_instantiate(command_name)
- command_name = command_name.to_s
- const_name = command_name.capitalize.gsub(/_(.)/) { $1.upcase } << "Command"
- load_error = nil
-
- begin
- begin
- require "rubygems/commands/#{command_name}_command"
- rescue LoadError => e
- load_error = e
- end
- Gem::Commands.const_get(const_name).new
- rescue Exception => e
- e = load_error if load_error
-
- alert_error "Loading command: #{command_name} (#{e.class})\n\t#{e}"
- ui.backtrace e
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/build_command.rb b/ruby_2_2/lib/rubygems/commands/build_command.rb
deleted file mode 100644
index d975429fe8..0000000000
--- a/ruby_2_2/lib/rubygems/commands/build_command.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/package'
-
-class Gem::Commands::BuildCommand < Gem::Command
-
- def initialize
- super 'build', 'Build a gem from a gemspec'
-
- add_option '--force', 'skip validation of the spec' do |value, options|
- options[:force] = true
- end
- end
-
- def arguments # :nodoc:
- "GEMSPEC_FILE gemspec file name to build a gem for"
- end
-
- def description # :nodoc:
- <<-EOF
-The build command allows you to create a gem from a ruby gemspec.
-
-The best way to build a gem is to use a Rakefile and the Gem::PackageTask
-which ships with RubyGems.
-
-The gemspec can either be created by hand or extracted from an existing gem
-with gem spec:
-
- $ gem unpack my_gem-1.0.gem
- Unpacked gem: '.../my_gem-1.0'
- $ gem spec my_gem-1.0.gem --ruby > my_gem-1.0/my_gem-1.0.gemspec
- $ cd my_gem-1.0
- [edit gem contents]
- $ gem build my_gem-1.0.gemspec
- EOF
- end
-
- def usage # :nodoc:
- "#{program_name} GEMSPEC_FILE"
- end
-
- def execute
- gemspec = get_one_gem_name
-
- if File.exist? gemspec then
- spec = Gem::Specification.load gemspec
-
- if spec then
- Gem::Package.build spec, options[:force]
- else
- alert_error "Error loading gemspec. Aborting."
- terminate_interaction 1
- end
- else
- alert_error "Gemspec file not found: #{gemspec}"
- terminate_interaction 1
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/cert_command.rb b/ruby_2_2/lib/rubygems/commands/cert_command.rb
deleted file mode 100644
index a920e7fcc3..0000000000
--- a/ruby_2_2/lib/rubygems/commands/cert_command.rb
+++ /dev/null
@@ -1,276 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/security'
-begin
- require 'openssl'
-rescue LoadError => e
- raise unless (e.respond_to?(:path) && e.path == 'openssl') ||
- e.message =~ / -- openssl$/
-end
-
-class Gem::Commands::CertCommand < Gem::Command
-
- def initialize
- super 'cert', 'Manage RubyGems certificates and signing settings',
- :add => [], :remove => [], :list => [], :build => [], :sign => []
-
- OptionParser.accept OpenSSL::X509::Certificate do |certificate|
- begin
- OpenSSL::X509::Certificate.new File.read certificate
- rescue Errno::ENOENT
- raise OptionParser::InvalidArgument, "#{certificate}: does not exist"
- rescue OpenSSL::X509::CertificateError
- raise OptionParser::InvalidArgument,
- "#{certificate}: invalid X509 certificate"
- end
- end
-
- OptionParser.accept OpenSSL::PKey::RSA do |key_file|
- begin
- passphrase = ENV['GEM_PRIVATE_KEY_PASSPHRASE']
- key = OpenSSL::PKey::RSA.new File.read(key_file), passphrase
- rescue Errno::ENOENT
- raise OptionParser::InvalidArgument, "#{key_file}: does not exist"
- rescue OpenSSL::PKey::RSAError
- raise OptionParser::InvalidArgument, "#{key_file}: invalid RSA key"
- end
-
- raise OptionParser::InvalidArgument,
- "#{key_file}: private key not found" unless key.private?
-
- key
- end
-
- add_option('-a', '--add CERT', OpenSSL::X509::Certificate,
- 'Add a trusted certificate.') do |cert, options|
- options[:add] << cert
- end
-
- add_option('-l', '--list [FILTER]',
- 'List trusted certificates where the',
- 'subject contains FILTER') do |filter, options|
- filter ||= ''
-
- options[:list] << filter
- end
-
- add_option('-r', '--remove FILTER',
- 'Remove trusted certificates where the',
- 'subject contains FILTER') do |filter, options|
- options[:remove] << filter
- end
-
- add_option('-b', '--build EMAIL_ADDR',
- 'Build private key and self-signed',
- 'certificate for EMAIL_ADDR') do |email_address, options|
- options[:build] << email_address
- end
-
- add_option('-C', '--certificate CERT', OpenSSL::X509::Certificate,
- 'Signing certificate for --sign') do |cert, options|
- options[:issuer_cert] = cert
- end
-
- add_option('-K', '--private-key KEY', OpenSSL::PKey::RSA,
- 'Key for --sign or --build') do |key, options|
- options[:key] = key
- end
-
- add_option('-s', '--sign CERT',
- 'Signs CERT with the key from -K',
- 'and the certificate from -C') do |cert_file, options|
- raise OptionParser::InvalidArgument, "#{cert_file}: does not exist" unless
- File.file? cert_file
-
- options[:sign] << cert_file
- end
- end
-
- def add_certificate certificate # :nodoc:
- Gem::Security.trust_dir.trust_cert certificate
-
- say "Added '#{certificate.subject}'"
- end
-
- def execute
- options[:add].each do |certificate|
- add_certificate certificate
- end
-
- options[:remove].each do |filter|
- remove_certificates_matching filter
- end
-
- options[:list].each do |filter|
- list_certificates_matching filter
- end
-
- options[:build].each do |name|
- build name
- end
-
- sign_certificates unless options[:sign].empty?
- end
-
- def build name
- key, key_path = build_key
- cert_path = build_cert name, key
-
- say "Certificate: #{cert_path}"
-
- if key_path
- say "Private Key: #{key_path}"
- say "Don't forget to move the key file to somewhere private!"
- end
- end
-
- def build_cert name, key # :nodoc:
- cert = Gem::Security.create_cert_email name, key
- Gem::Security.write cert, "gem-public_cert.pem"
- end
-
- def build_key # :nodoc:
- return options[:key] if options[:key]
-
- passphrase = ask_for_password 'Passphrase for your Private Key:'
- say "\n"
-
- passphrase_confirmation = ask_for_password 'Please repeat the passphrase for your Private Key:'
- say "\n"
-
- raise Gem::CommandLineError,
- "Passphrase and passphrase confirmation don't match" unless passphrase == passphrase_confirmation
-
- key = Gem::Security.create_key
- key_path = Gem::Security.write key, "gem-private_key.pem", 0600, passphrase
-
- return key, key_path
- end
-
- def certificates_matching filter
- return enum_for __method__, filter unless block_given?
-
- Gem::Security.trusted_certificates.select do |certificate, _|
- subject = certificate.subject.to_s
- subject.downcase.index filter
- end.sort_by do |certificate, _|
- certificate.subject.to_a.map { |name, data,| [name, data] }
- end.each do |certificate, path|
- yield certificate, path
- end
- end
-
- def description # :nodoc:
- <<-EOF
-The cert command manages signing keys and certificates for creating signed
-gems. Your signing certificate and private key are typically stored in
-~/.gem/gem-public_cert.pem and ~/.gem/gem-private_key.pem respectively.
-
-To build a certificate for signing gems:
-
- gem cert --build you@example
-
-If you already have an RSA key, or are creating a new certificate for an
-existing key:
-
- gem cert --build you@example --private-key /path/to/key.pem
-
-If you wish to trust a certificate you can add it to the trust list with:
-
- gem cert --add /path/to/cert.pem
-
-You can list trusted certificates with:
-
- gem cert --list
-
-or:
-
- gem cert --list cert_subject_substring
-
-If you wish to remove a previously trusted certificate:
-
- gem cert --remove cert_subject_substring
-
-To sign another gem author's certificate:
-
- gem cert --sign /path/to/other_cert.pem
-
-For further reading on signing gems see `ri Gem::Security`.
- EOF
- end
-
- def list_certificates_matching filter # :nodoc:
- certificates_matching filter do |certificate, _|
- # this could probably be formatted more gracefully
- say certificate.subject.to_s
- end
- end
-
- def load_default_cert
- cert_file = File.join Gem.default_cert_path
- cert = File.read cert_file
- options[:issuer_cert] = OpenSSL::X509::Certificate.new cert
- rescue Errno::ENOENT
- alert_error \
- "--certificate not specified and ~/.gem/gem-public_cert.pem does not exist"
-
- terminate_interaction 1
- rescue OpenSSL::X509::CertificateError
- alert_error \
- "--certificate not specified and ~/.gem/gem-public_cert.pem is not valid"
-
- terminate_interaction 1
- end
-
- def load_default_key
- key_file = File.join Gem.default_key_path
- key = File.read key_file
- passphrase = ENV['GEM_PRIVATE_KEY_PASSPHRASE']
- options[:key] = OpenSSL::PKey::RSA.new key, passphrase
- rescue Errno::ENOENT
- alert_error \
- "--private-key not specified and ~/.gem/gem-private_key.pem does not exist"
-
- terminate_interaction 1
- rescue OpenSSL::PKey::RSAError
- alert_error \
- "--private-key not specified and ~/.gem/gem-private_key.pem is not valid"
-
- terminate_interaction 1
- end
-
- def load_defaults # :nodoc:
- load_default_cert unless options[:issuer_cert]
- load_default_key unless options[:key]
- end
-
- def remove_certificates_matching filter # :nodoc:
- certificates_matching filter do |certificate, path|
- FileUtils.rm path
- say "Removed '#{certificate.subject}'"
- end
- end
-
- def sign cert_file
- cert = File.read cert_file
- cert = OpenSSL::X509::Certificate.new cert
-
- permissions = File.stat(cert_file).mode & 0777
-
- issuer_cert = options[:issuer_cert]
- issuer_key = options[:key]
-
- cert = Gem::Security.sign cert, issuer_key, issuer_cert
-
- Gem::Security.write cert, cert_file, permissions
- end
-
- def sign_certificates # :nodoc:
- load_defaults unless options[:sign].empty?
-
- options[:sign].each do |cert_file|
- sign cert_file
- end
- end
-
-end if defined?(OpenSSL::SSL)
-
diff --git a/ruby_2_2/lib/rubygems/commands/check_command.rb b/ruby_2_2/lib/rubygems/commands/check_command.rb
deleted file mode 100644
index 8893b9c3b2..0000000000
--- a/ruby_2_2/lib/rubygems/commands/check_command.rb
+++ /dev/null
@@ -1,93 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/version_option'
-require 'rubygems/validator'
-require 'rubygems/doctor'
-
-class Gem::Commands::CheckCommand < Gem::Command
-
- include Gem::VersionOption
-
- def initialize
- super 'check', 'Check a gem repository for added or missing files',
- :alien => true, :doctor => false, :dry_run => false, :gems => true
-
- add_option('-a', '--[no-]alien',
- 'Report "unmanaged" or rogue files in the',
- 'gem repository') do |value, options|
- options[:alien] = value
- end
-
- add_option('--[no-]doctor',
- 'Clean up uninstalled gems and broken',
- 'specifications') do |value, options|
- options[:doctor] = value
- end
-
- add_option('--[no-]dry-run',
- 'Do not remove files, only report what',
- 'would be removed') do |value, options|
- options[:dry_run] = value
- end
-
- add_option('--[no-]gems',
- 'Check installed gems for problems') do |value, options|
- options[:gems] = value
- end
-
- add_version_option 'check'
- end
-
- def check_gems
- say 'Checking gems...'
- say
- gems = get_all_gem_names rescue []
-
- Gem::Validator.new.alien(gems).sort.each do |key, val|
- unless val.empty? then
- say "#{key} has #{val.size} problems"
- val.each do |error_entry|
- say " #{error_entry.path}:"
- say " #{error_entry.problem}"
- end
- else
- say "#{key} is error-free" if Gem.configuration.verbose
- end
- say
- end
- end
-
- def doctor
- say 'Checking for files from uninstalled gems...'
- say
-
- Gem.path.each do |gem_repo|
- doctor = Gem::Doctor.new gem_repo, options[:dry_run]
- doctor.doctor
- end
- end
-
- def execute
- check_gems if options[:gems]
- doctor if options[:doctor]
- end
-
- def arguments # :nodoc:
- 'GEMNAME name of gem to check'
- end
-
- def defaults_str # :nodoc:
- '--gems --alien'
- end
-
- def description # :nodoc:
- <<-EOF
-The check command can list and repair problems with installed gems and
-specifications and will clean up gems that have been partially uninstalled.
- EOF
- end
-
- def usage # :nodoc:
- "#{program_name} [OPTIONS] [GEMNAME ...]"
- end
-
-end
diff --git a/ruby_2_2/lib/rubygems/commands/cleanup_command.rb b/ruby_2_2/lib/rubygems/commands/cleanup_command.rb
deleted file mode 100644
index 69975640fe..0000000000
--- a/ruby_2_2/lib/rubygems/commands/cleanup_command.rb
+++ /dev/null
@@ -1,165 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/dependency_list'
-require 'rubygems/uninstaller'
-
-class Gem::Commands::CleanupCommand < Gem::Command
-
- def initialize
- super 'cleanup',
- 'Clean up old versions of installed gems',
- :force => false, :install_dir => Gem.dir
-
- add_option('-n', '-d', '--dryrun',
- 'Do not uninstall gems') do |value, options|
- options[:dryrun] = true
- end
-
- @candidate_gems = nil
- @default_gems = []
- @full = nil
- @gems_to_cleanup = nil
- @original_home = nil
- @original_path = nil
- @primary_gems = nil
- end
-
- def arguments # :nodoc:
- "GEMNAME name of gem to cleanup"
- end
-
- def defaults_str # :nodoc:
- "--no-dryrun"
- end
-
- def description # :nodoc:
- <<-EOF
-The cleanup command removes old versions of gems from GEM_HOME that are not
-required to meet a dependency. If a gem is installed elsewhere in GEM_PATH
-the cleanup command won't delete it.
-
-If no gems are named all gems in GEM_HOME are cleaned.
- EOF
- end
-
- def usage # :nodoc:
- "#{program_name} [GEMNAME ...]"
- end
-
- def execute
- say "Cleaning up installed gems..."
-
- if options[:args].empty? then
- done = false
- last_set = nil
-
- until done do
- clean_gems
-
- this_set = @gems_to_cleanup.map { |spec| spec.full_name }.sort
-
- done = this_set.empty? || last_set == this_set
-
- last_set = this_set
- end
- else
- clean_gems
- end
-
- say "Clean Up Complete"
-
- verbose do
- skipped = @default_gems.map { |spec| spec.full_name }
-
- "Skipped default gems: #{skipped.join ', '}"
- end
- end
-
- def clean_gems
- get_primary_gems
- get_candidate_gems
- get_gems_to_cleanup
-
- @full = Gem::DependencyList.from_specs
-
- deplist = Gem::DependencyList.new
- @gems_to_cleanup.each do |spec| deplist.add spec end
-
- deps = deplist.strongly_connected_components.flatten
-
- @original_home = Gem.dir
- @original_path = Gem.path
-
- deps.reverse_each do |spec|
- uninstall_dep spec
- end
-
- Gem::Specification.reset
- end
-
- def get_candidate_gems
- @candidate_gems = unless options[:args].empty? then
- options[:args].map do |gem_name|
- Gem::Specification.find_all_by_name gem_name
- end.flatten
- else
- Gem::Specification.to_a
- end
- end
-
- def get_gems_to_cleanup
- gems_to_cleanup = @candidate_gems.select { |spec|
- @primary_gems[spec.name].version != spec.version
- }
-
- default_gems, gems_to_cleanup = gems_to_cleanup.partition { |spec|
- spec.default_gem?
- }
-
- @default_gems += default_gems
- @default_gems.uniq!
- @gems_to_cleanup = gems_to_cleanup.uniq
- end
-
- def get_primary_gems
- @primary_gems = {}
-
- Gem::Specification.each do |spec|
- if @primary_gems[spec.name].nil? or
- @primary_gems[spec.name].version < spec.version then
- @primary_gems[spec.name] = spec
- end
- end
- end
-
- def uninstall_dep spec
- return unless @full.ok_to_remove?(spec.full_name)
-
- if options[:dryrun] then
- say "Dry Run Mode: Would uninstall #{spec.full_name}"
- return
- end
-
- say "Attempting to uninstall #{spec.full_name}"
-
- uninstall_options = {
- :executables => false,
- :version => "= #{spec.version}",
- }
-
- uninstall_options[:user_install] = Gem.user_dir == spec.base_dir
-
- uninstaller = Gem::Uninstaller.new spec.name, uninstall_options
-
- begin
- uninstaller.uninstall
- rescue Gem::DependencyRemovalException, Gem::InstallError,
- Gem::GemNotInHomeException, Gem::FilePermissionError => e
- say "Unable to uninstall #{spec.full_name}:"
- say "\t#{e.class}: #{e.message}"
- end
- ensure
- # Restore path Gem::Uninstaller may have changed
- Gem.use_paths @original_home, *@original_path
- end
-
-end
diff --git a/ruby_2_2/lib/rubygems/commands/contents_command.rb b/ruby_2_2/lib/rubygems/commands/contents_command.rb
deleted file mode 100644
index 4b944f18be..0000000000
--- a/ruby_2_2/lib/rubygems/commands/contents_command.rb
+++ /dev/null
@@ -1,190 +0,0 @@
-require 'English'
-require 'rubygems/command'
-require 'rubygems/version_option'
-
-class Gem::Commands::ContentsCommand < Gem::Command
-
- include Gem::VersionOption
-
- def initialize
- super 'contents', 'Display the contents of the installed gems',
- :specdirs => [], :lib_only => false, :prefix => true,
- :show_install_dir => false
-
- add_version_option
-
- add_option( '--all',
- "Contents for all gems") do |all, options|
- options[:all] = all
- end
-
- add_option('-s', '--spec-dir a,b,c', Array,
- "Search for gems under specific paths") do |spec_dirs, options|
- options[:specdirs] = spec_dirs
- end
-
- add_option('-l', '--[no-]lib-only',
- "Only return files in the Gem's lib_dirs") do |lib_only, options|
- options[:lib_only] = lib_only
- end
-
- add_option( '--[no-]prefix',
- "Don't include installed path prefix") do |prefix, options|
- options[:prefix] = prefix
- end
-
- add_option( '--[no-]show-install-dir',
- 'Show only the gem install dir') do |show, options|
- options[:show_install_dir] = show
- end
-
- @path_kind = nil
- @spec_dirs = nil
- @version = nil
- end
-
- def arguments # :nodoc:
- "GEMNAME name of gem to list contents for"
- end
-
- def defaults_str # :nodoc:
- "--no-lib-only --prefix"
- end
-
- def description # :nodoc:
- <<-EOF
-The contents command lists the files in an installed gem. The listing can
-be given as full file names, file names without the installed directory
-prefix or only the files that are requireable.
- EOF
- end
-
- def usage # :nodoc:
- "#{program_name} GEMNAME [GEMNAME ...]"
- end
-
- def execute
- @version = options[:version] || Gem::Requirement.default
- @spec_dirs = specification_directories
- @path_kind = path_description @spec_dirs
-
- names = gem_names
-
- names.each do |name|
- found =
- if options[:show_install_dir] then
- gem_install_dir name
- else
- gem_contents name
- end
-
- terminate_interaction 1 unless found or names.length > 1
- end
- end
-
- def files_in spec
- if spec.default_gem? then
- files_in_default_gem spec
- else
- files_in_gem spec
- end
- end
-
- def files_in_gem spec
- gem_path = spec.full_gem_path
- extra = "/{#{spec.require_paths.join ','}}" if options[:lib_only]
- glob = "#{gem_path}#{extra}/**/*"
- prefix_re = /#{Regexp.escape(gem_path)}\//
-
- Dir[glob].map do |file|
- [gem_path, file.sub(prefix_re, "")]
- end
- end
-
- def files_in_default_gem spec
- spec.files.map do |file|
- case file
- when /\A#{spec.bindir}\//
- [RbConfig::CONFIG['bindir'], $POSTMATCH]
- when /\.so\z/
- [RbConfig::CONFIG['archdir'], file]
- else
- [RbConfig::CONFIG['rubylibdir'], file]
- end
- end
- end
-
- def gem_contents name
- spec = spec_for name
-
- return false unless spec
-
- files = files_in spec
-
- show_files files
-
- true
- end
-
- def gem_install_dir name
- spec = spec_for name
-
- return false unless spec
-
- say spec.gem_dir
-
- true
- end
-
- def gem_names # :nodoc:
- if options[:all] then
- Gem::Specification.map(&:name)
- else
- get_all_gem_names
- end
- end
-
- def path_description spec_dirs # :nodoc:
- if spec_dirs.empty? then
- "default gem paths"
- else
- "specified path"
- end
- end
-
- def show_files files
- files.sort.each do |prefix, basename|
- absolute_path = File.join(prefix, basename)
- next if File.directory? absolute_path
-
- if options[:prefix] then
- say absolute_path
- else
- say basename
- end
- end
- end
-
- def spec_for name
- spec = Gem::Specification.find_all_by_name(name, @version).last
-
- return spec if spec
-
- say "Unable to find gem '#{name}' in #{@path_kind}"
-
- if Gem.configuration.verbose then
- say "\nDirectories searched:"
- @spec_dirs.sort.each { |dir| say dir }
- end
-
- return nil
- end
-
- def specification_directories # :nodoc:
- options[:specdirs].map do |i|
- [i, File.join(i, "specifications")]
- end.flatten
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/dependency_command.rb b/ruby_2_2/lib/rubygems/commands/dependency_command.rb
deleted file mode 100644
index 4a54a3e385..0000000000
--- a/ruby_2_2/lib/rubygems/commands/dependency_command.rb
+++ /dev/null
@@ -1,207 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/local_remote_options'
-require 'rubygems/version_option'
-
-class Gem::Commands::DependencyCommand < Gem::Command
-
- include Gem::LocalRemoteOptions
- include Gem::VersionOption
-
- def initialize
- super 'dependency',
- 'Show the dependencies of an installed gem',
- :version => Gem::Requirement.default, :domain => :local
-
- add_version_option
- add_platform_option
- add_prerelease_option
-
- add_option('-R', '--[no-]reverse-dependencies',
- 'Include reverse dependencies in the output') do
- |value, options|
- options[:reverse_dependencies] = value
- end
-
- add_option('-p', '--pipe',
- "Pipe Format (name --version ver)") do |value, options|
- options[:pipe_format] = value
- end
-
- add_local_remote_options
- end
-
- def arguments # :nodoc:
- "REGEXP show dependencies for gems whose names start with REGEXP"
- end
-
- def defaults_str # :nodoc:
- "--local --version '#{Gem::Requirement.default}' --no-reverse-dependencies"
- end
-
- def description # :nodoc:
- <<-EOF
-The dependency commands lists which other gems a given gem depends on. For
-local gems only the reverse dependencies can be shown (which gems depend on
-the named gem).
-
-The dependency list can be displayed in a format suitable for piping for
-use with other commands.
- EOF
- end
-
- def usage # :nodoc:
- "#{program_name} REGEXP"
- end
-
- def fetch_remote_specs dependency # :nodoc:
- fetcher = Gem::SpecFetcher.fetcher
-
- ss, = fetcher.spec_for_dependency dependency
-
- ss.map { |spec, _| spec }
- end
-
- def fetch_specs dependency # :nodoc:
- specs = []
-
- specs.concat dependency.matching_specs if local?
- specs.concat fetch_remote_specs dependency if remote?
-
- ensure_specs specs
-
- specs.uniq.sort
- end
-
- def gem_dependency args, version, prerelease # :nodoc:
- args << '' if args.empty?
-
- pattern = if args.length == 1 and args.first =~ /\A\/(.*)\/(i)?\z/m then
- flags = $2 ? Regexp::IGNORECASE : nil
- Regexp.new $1, flags
- else
- /\A#{Regexp.union(*args)}/
- end
-
- dependency = Gem::Deprecate.skip_during {
- Gem::Dependency.new pattern, version
- }
-
- dependency.prerelease = prerelease
-
- dependency
- end
-
- def display_pipe specs # :nodoc:
- specs.each do |spec|
- unless spec.dependencies.empty? then
- spec.dependencies.sort_by { |dep| dep.name }.each do |dep|
- say "#{dep.name} --version '#{dep.requirement}'"
- end
- end
- end
- end
-
- def display_readable specs, reverse # :nodoc:
- response = ''
-
- specs.each do |spec|
- response << print_dependencies(spec)
- unless reverse[spec.full_name].empty? then
- response << " Used by\n"
- reverse[spec.full_name].each do |sp, dep|
- response << " #{sp} (#{dep})\n"
- end
- end
- response << "\n"
- end
-
- say response
- end
-
- def execute
- ensure_local_only_reverse_dependencies
-
- dependency =
- gem_dependency options[:args], options[:version], options[:prerelease]
-
- specs = fetch_specs dependency
-
- reverse = reverse_dependencies specs
-
- if options[:pipe_format] then
- display_pipe specs
- else
- display_readable specs, reverse
- end
- end
-
- def ensure_local_only_reverse_dependencies # :nodoc:
- if options[:reverse_dependencies] and remote? and not local? then
- alert_error 'Only reverse dependencies for local gems are supported.'
- terminate_interaction 1
- end
- end
-
- def ensure_specs specs # :nodoc:
- return unless specs.empty?
-
- patterns = options[:args].join ','
- say "No gems found matching #{patterns} (#{options[:version]})" if
- Gem.configuration.verbose
-
- terminate_interaction 1
- end
-
- def print_dependencies(spec, level = 0) # :nodoc:
- response = ''
- response << ' ' * level + "Gem #{spec.full_name}\n"
- unless spec.dependencies.empty? then
- spec.dependencies.sort_by { |dep| dep.name }.each do |dep|
- response << ' ' * level + " #{dep}\n"
- end
- end
- response
- end
-
- def remote_specs dependency # :nodoc:
- fetcher = Gem::SpecFetcher.fetcher
-
- ss, _ = fetcher.spec_for_dependency dependency
-
- ss.map { |s,o| s }
- end
-
- def reverse_dependencies specs # :nodoc:
- reverse = Hash.new { |h, k| h[k] = [] }
-
- return reverse unless options[:reverse_dependencies]
-
- specs.each do |spec|
- reverse[spec.full_name] = find_reverse_dependencies spec
- end
-
- reverse
- end
-
- ##
- # Returns an Array of [specification, dep] that are satisfied by +spec+.
-
- def find_reverse_dependencies spec # :nodoc:
- result = []
-
- Gem::Specification.each do |sp|
- sp.dependencies.each do |dep|
- dep = Gem::Dependency.new(*dep) unless Gem::Dependency === dep
-
- if spec.name == dep.name and
- dep.requirement.satisfied_by?(spec.version) then
- result << [sp.full_name, dep]
- end
- end
- end
-
- result
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/environment_command.rb b/ruby_2_2/lib/rubygems/commands/environment_command.rb
deleted file mode 100644
index 067d0b1607..0000000000
--- a/ruby_2_2/lib/rubygems/commands/environment_command.rb
+++ /dev/null
@@ -1,158 +0,0 @@
-require 'rubygems/command'
-
-class Gem::Commands::EnvironmentCommand < Gem::Command
-
- def initialize
- super 'environment', 'Display information about the RubyGems environment'
- end
-
- def arguments # :nodoc:
- args = <<-EOF
- packageversion display the package version
- gemdir display the path where gems are installed
- gempath display path used to search for gems
- version display the gem format version
- remotesources display the remote gem servers
- platform display the supported gem platforms
- <omitted> display everything
- EOF
- return args.gsub(/^\s+/, '')
- end
-
- def description # :nodoc:
- <<-EOF
-The environment command lets you query rubygems for its configuration for
-use in shell scripts or as a debugging aid.
-
-The RubyGems environment can be controlled through command line arguments,
-gemrc files, environment variables and built-in defaults.
-
-Command line argument defaults and some RubyGems defaults can be set in a
-~/.gemrc file for individual users and a gemrc in the SYSTEM CONFIGURATION
-DIRECTORY for all users. These files are YAML files with the following YAML
-keys:
-
- :sources: A YAML array of remote gem repositories to install gems from
- :verbose: Verbosity of the gem command. false, true, and :really are the
- levels
- :update_sources: Enable/disable automatic updating of repository metadata
- :backtrace: Print backtrace when RubyGems encounters an error
- :gempath: The paths in which to look for gems
- :disable_default_gem_server: Force specification of gem server host on push
- <gem_command>: A string containing arguments for the specified gem command
-
-Example:
-
- :verbose: false
- install: --no-wrappers
- update: --no-wrappers
- :disable_default_gem_server: true
-
-RubyGems' default local repository can be overridden with the GEM_PATH and
-GEM_HOME environment variables. GEM_HOME sets the default repository to
-install into. GEM_PATH allows multiple local repositories to be searched for
-gems.
-
-If you are behind a proxy server, RubyGems uses the HTTP_PROXY,
-HTTP_PROXY_USER and HTTP_PROXY_PASS environment variables to discover the
-proxy server.
-
-If you would like to push gems to a private gem server the RUBYGEMS_HOST
-environment variable can be set to the URI for that server.
-
-If you are packaging RubyGems all of RubyGems' defaults are in
-lib/rubygems/defaults.rb. You may override these in
-lib/rubygems/defaults/operating_system.rb
- EOF
- end
-
- def usage # :nodoc:
- "#{program_name} [arg]"
- end
-
- def execute
- out = ''
- arg = options[:args][0]
- out <<
- case arg
- when /^packageversion/ then
- Gem::RubyGemsPackageVersion
- when /^version/ then
- Gem::VERSION
- when /^gemdir/, /^gemhome/, /^home/, /^GEM_HOME/ then
- Gem.dir
- when /^gempath/, /^path/, /^GEM_PATH/ then
- Gem.path.join(File::PATH_SEPARATOR)
- when /^remotesources/ then
- Gem.sources.to_a.join("\n")
- when /^platform/ then
- Gem.platforms.join(File::PATH_SEPARATOR)
- when nil then
- show_environment
- else
- raise Gem::CommandLineError, "Unknown environment option [#{arg}]"
- end
- say out
- true
- end
-
- def add_path out, path
- path.each do |component|
- out << " - #{component}\n"
- end
- end
-
- def show_environment # :nodoc:
- out = "RubyGems Environment:\n"
-
- out << " - RUBYGEMS VERSION: #{Gem::VERSION}\n"
-
- out << " - RUBY VERSION: #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}"
- out << " patchlevel #{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL
- out << ") [#{RUBY_PLATFORM}]\n"
-
- out << " - INSTALLATION DIRECTORY: #{Gem.dir}\n"
-
- out << " - RUBYGEMS PREFIX: #{Gem.prefix}\n" unless Gem.prefix.nil?
-
- out << " - RUBY EXECUTABLE: #{Gem.ruby}\n"
-
- out << " - EXECUTABLE DIRECTORY: #{Gem.bindir}\n"
-
- out << " - SPEC CACHE DIRECTORY: #{Gem.spec_cache_dir}\n"
-
- out << " - SYSTEM CONFIGURATION DIRECTORY: #{Gem::ConfigFile::SYSTEM_CONFIG_PATH}\n"
-
- out << " - RUBYGEMS PLATFORMS:\n"
- Gem.platforms.each do |platform|
- out << " - #{platform}\n"
- end
-
- out << " - GEM PATHS:\n"
- out << " - #{Gem.dir}\n"
-
- gem_path = Gem.path.dup
- gem_path.delete Gem.dir
- add_path out, gem_path
-
- out << " - GEM CONFIGURATION:\n"
- Gem.configuration.each do |name, value|
- value = value.gsub(/./, '*') if name == 'gemcutter_key'
- out << " - #{name.inspect} => #{value.inspect}\n"
- end
-
- out << " - REMOTE SOURCES:\n"
- Gem.sources.each do |s|
- out << " - #{s}\n"
- end
-
- out << " - SHELL PATH:\n"
-
- shell_path = ENV['PATH'].split(File::PATH_SEPARATOR)
- add_path out, shell_path
-
- out
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/fetch_command.rb b/ruby_2_2/lib/rubygems/commands/fetch_command.rb
deleted file mode 100644
index c57ab0089a..0000000000
--- a/ruby_2_2/lib/rubygems/commands/fetch_command.rb
+++ /dev/null
@@ -1,77 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/local_remote_options'
-require 'rubygems/version_option'
-
-class Gem::Commands::FetchCommand < Gem::Command
-
- include Gem::LocalRemoteOptions
- include Gem::VersionOption
-
- def initialize
- super 'fetch', 'Download a gem and place it in the current directory'
-
- add_bulk_threshold_option
- add_proxy_option
- add_source_option
- add_clear_sources_option
-
- add_version_option
- add_platform_option
- add_prerelease_option
- end
-
- def arguments # :nodoc:
- 'GEMNAME name of gem to download'
- end
-
- def defaults_str # :nodoc:
- "--version '#{Gem::Requirement.default}'"
- end
-
- def description # :nodoc:
- <<-EOF
-The fetch command fetches gem files that can be stored for later use or
-unpacked to examine their contents.
-
-See the build command help for an example of unpacking a gem, modifying it,
-then repackaging it.
- EOF
- end
-
- def usage # :nodoc:
- "#{program_name} GEMNAME [GEMNAME ...]"
- end
-
- def execute
- version = options[:version] || Gem::Requirement.default
-
- platform = Gem.platforms.last
- gem_names = get_all_gem_names
-
- gem_names.each do |gem_name|
- dep = Gem::Dependency.new gem_name, version
- dep.prerelease = options[:prerelease]
-
- specs_and_sources, errors =
- Gem::SpecFetcher.fetcher.spec_for_dependency dep
-
- if platform then
- filtered = specs_and_sources.select { |s,| s.platform == platform }
- specs_and_sources = filtered unless filtered.empty?
- end
-
- spec, source = specs_and_sources.max_by { |s,| s.version }
-
- if spec.nil? then
- show_lookup_failure gem_name, version, errors, options[:domain]
- next
- end
-
- source.download spec
-
- say "Downloaded #{spec.full_name}"
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/generate_index_command.rb b/ruby_2_2/lib/rubygems/commands/generate_index_command.rb
deleted file mode 100644
index ca6f694bc5..0000000000
--- a/ruby_2_2/lib/rubygems/commands/generate_index_command.rb
+++ /dev/null
@@ -1,84 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/indexer'
-
-##
-# Generates a index files for use as a gem server.
-#
-# See `gem help generate_index`
-
-class Gem::Commands::GenerateIndexCommand < Gem::Command
-
- def initialize
- super 'generate_index',
- 'Generates the index files for a gem server directory',
- :directory => '.', :build_modern => true
-
- add_option '-d', '--directory=DIRNAME',
- 'repository base dir containing gems subdir' do |dir, options|
- options[:directory] = File.expand_path dir
- end
-
- add_option '--[no-]modern',
- 'Generate indexes for RubyGems',
- '(always true)' do |value, options|
- options[:build_modern] = value
- end
-
- add_option '--update',
- 'Update modern indexes with gems added',
- 'since the last update' do |value, options|
- options[:update] = value
- end
- end
-
- def defaults_str # :nodoc:
- "--directory . --modern"
- end
-
- def description # :nodoc:
- <<-EOF
-The generate_index command creates a set of indexes for serving gems
-statically. The command expects a 'gems' directory under the path given to
-the --directory option. The given directory will be the directory you serve
-as the gem repository.
-
-For `gem generate_index --directory /path/to/repo`, expose /path/to/repo via
-your HTTP server configuration (not /path/to/repo/gems).
-
-When done, it will generate a set of files like this:
-
- gems/*.gem # .gem files you want to
- # index
-
- specs.<version>.gz # specs index
- latest_specs.<version>.gz # latest specs index
- prerelease_specs.<version>.gz # prerelease specs index
- quick/Marshal.<version>/<gemname>.gemspec.rz # Marshal quick index file
-
-The .rz extension files are compressed with the inflate algorithm.
-The Marshal version number comes from ruby's Marshal::MAJOR_VERSION and
-Marshal::MINOR_VERSION constants. It is used to ensure compatibility.
- EOF
- end
-
- def execute
- # This is always true because it's the only way now.
- options[:build_modern] = true
-
- if not File.exist?(options[:directory]) or
- not File.directory?(options[:directory]) then
- alert_error "unknown directory name #{directory}."
- terminate_interaction 1
- else
- indexer = Gem::Indexer.new options.delete(:directory), options
-
- if options[:update] then
- indexer.update_index
- else
- indexer.generate_index
- end
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/help_command.rb b/ruby_2_2/lib/rubygems/commands/help_command.rb
deleted file mode 100644
index ed81ad6e25..0000000000
--- a/ruby_2_2/lib/rubygems/commands/help_command.rb
+++ /dev/null
@@ -1,384 +0,0 @@
-require 'rubygems/command'
-
-class Gem::Commands::HelpCommand < Gem::Command
-
- # :stopdoc:
- EXAMPLES = <<-EOF
-Some examples of 'gem' usage.
-
-* Install 'rake', either from local directory or remote server:
-
- gem install rake
-
-* Install 'rake', only from remote server:
-
- gem install rake --remote
-
-* Install 'rake', but only version 0.3.1, even if dependencies
- are not met, and into a user-specific directory:
-
- gem install rake --version 0.3.1 --force --user-install
-
-* List local gems whose name begins with 'D':
-
- gem list D
-
-* List local and remote gems whose name contains 'log':
-
- gem search log --both
-
-* List only remote gems whose name contains 'log':
-
- gem search log --remote
-
-* Uninstall 'rake':
-
- gem uninstall rake
-
-* Create a gem:
-
- See http://guides.rubygems.org/make-your-own-gem/
-
-* See information about RubyGems:
-
- gem environment
-
-* Update all gems on your system:
-
- gem update
-
-* Update your local version of RubyGems
-
- gem update --system
- EOF
-
- GEM_DEPENDENCIES = <<-EOF
-A gem dependencies file allows installation of a consistent set of gems across
-multiple environments. The RubyGems implementation is designed to be
-compatible with Bundler's Gemfile format. You can see additional
-documentation on the format at:
-
- http://bundler.io
-
-RubyGems automatically looks for these gem dependencies files:
-
-* gem.deps.rb
-* Gemfile
-* Isolate
-
-These files are looked up automatically using `gem install -g`, or you can
-specify a custom file.
-
-When the RUBYGEMS_GEMDEPS environment variable is set to a gem dependencies
-file the gems from that file will be activated at startup time. Set it to a
-specific filename or to "-" to have RubyGems automatically discover the gem
-dependencies file by walking up from the current directory.
-
-You can also activate gem dependencies at program startup using
-Gem.use_gemdeps.
-
-NOTE: Enabling automatic discovery on multiuser systems can lead to execution
-of arbitrary code when used from directories outside your control.
-
-Gem Dependencies
-================
-
-Use #gem to declare which gems you directly depend upon:
-
- gem 'rake'
-
-To depend on a specific set of versions:
-
- gem 'rake', '~> 10.3', '>= 10.3.2'
-
-RubyGems will require the gem name when activating the gem using
-the RUBYGEMS_GEMDEPS environment variable or Gem::use_gemdeps. Use the
-require: option to override this behavior if the gem does not have a file of
-that name or you don't want to require those files:
-
- gem 'my_gem', require: 'other_file'
-
-To prevent RubyGems from requiring any files use:
-
- gem 'my_gem', require: false
-
-To load dependencies from a .gemspec file:
-
- gemspec
-
-RubyGems looks for the first .gemspec file in the current directory. To
-override this use the name: option:
-
- gemspec name: 'specific_gem'
-
-To look in a different directory use the path: option:
-
- gemspec name: 'specific_gem', path: 'gemspecs'
-
-To depend on a gem unpacked into a local directory:
-
- gem 'modified_gem', path: 'vendor/modified_gem'
-
-To depend on a gem from git:
-
- gem 'private_gem', git: 'git@my.company.example:private_gem.git'
-
-To depend on a gem from github:
-
- gem 'private_gem', github: 'my_company/private_gem'
-
-To depend on a gem from a github gist:
-
- gem 'bang', gist: '1232884'
-
-Git, github and gist support the ref:, branch: and tag: options to specify a
-commit reference or hash, branch or tag respectively to use for the gem.
-
-Setting the submodules: option to true for git, github and gist dependencies
-causes fetching of submodules when fetching the repository.
-
-You can depend on multiple gems from a single repository with the git method:
-
- git 'https://github.com/rails/rails.git' do
- gem 'activesupport'
- gem 'activerecord'
- end
-
-Gem Sources
-===========
-
-RubyGems uses the default sources for regular `gem install` for gem
-dependencies files. Unlike bundler, you do need to specify a source.
-
-You can override the sources used for downloading gems with:
-
- source 'https://gem_server.example'
-
-You may specify multiple sources. Unlike bundler the prepend: option is not
-supported. Sources are used in-order, to prepend a source place it at the
-front of the list.
-
-Gem Platform
-============
-
-You can restrict gem dependencies to specific platforms with the #platform
-and #platforms methods:
-
- platform :ruby_21 do
- gem 'debugger'
- end
-
-See the bundler Gemfile manual page for a list of platforms supported in a gem
-dependencies file.:
-
- http://bundler.io/v1.6/man/gemfile.5.html
-
-Ruby Version and Engine Dependency
-==================================
-
-You can specifiy the version, engine and engine version of ruby to use with
-your gem dependencies file. If you are not running the specified version
-RubyGems will raise an exception.
-
-To depend on a specific version of ruby:
-
- ruby '2.1.2'
-
-To depend on a specific ruby engine:
-
- ruby '1.9.3', engine: 'jruby'
-
-To depend on a specific ruby engine version:
-
- ruby '1.9.3', engine: 'jruby', engine_version: '1.7.11'
-
-Grouping Dependencies
-=====================
-
-Gem dependencies may be placed in groups that can be excluded from install.
-Dependencies required for development or testing of your code may be excluded
-when installed in a production environment.
-
-A #gem dependency may be placed in a group using the group: option:
-
- gem 'minitest', group: :test
-
-To install dependencies from a gemfile without specific groups use the
-`--without` option for `gem install -g`:
-
- $ gem install -g --without test
-
-The group: option also accepts multiple groups if the gem fits in multiple
-categories.
-
-Multiple groups may be excluded during install by comma-separating the groups for `--without` or by specifying `--without` multiple times.
-
-The #group method can also be used to place gems in groups:
-
- group :test do
- gem 'minitest'
- gem 'minitest-emoji'
- end
-
-The #group method allows multiple groups.
-
-The #gemspec development dependencies are placed in the :development group by
-default. This may be overriden with the :development_group option:
-
- gemspec development_group: :other
-
- EOF
-
- PLATFORMS = <<-'EOF'
-RubyGems platforms are composed of three parts, a CPU, an OS, and a
-version. These values are taken from values in rbconfig.rb. You can view
-your current platform by running `gem environment`.
-
-RubyGems matches platforms as follows:
-
- * The CPU must match exactly unless one of the platforms has
- "universal" as the CPU or the local CPU starts with "arm" and the gem's
- CPU is exactly "arm" (for gems that support generic ARM architecture).
- * The OS must match exactly.
- * The versions must match exactly unless one of the versions is nil.
-
-For commands that install, uninstall and list gems, you can override what
-RubyGems thinks your platform is with the --platform option. The platform
-you pass must match "#{cpu}-#{os}" or "#{cpu}-#{os}-#{version}". On mswin
-platforms, the version is the compiler version, not the OS version. (Ruby
-compiled with VC6 uses "60" as the compiler version, VC8 uses "80".)
-
-For the ARM architecture, gems with a platform of "arm-linux" should run on a
-reasonable set of ARM CPUs and not depend on instructions present on a limited
-subset of the architecture. For example, the binary should run on platforms
-armv5, armv6hf, armv6l, armv7, etc. If you use the "arm-linux" platform
-please test your gem on a variety of ARM hardware before release to ensure it
-functions correctly.
-
-Example platforms:
-
- x86-freebsd # Any FreeBSD version on an x86 CPU
- universal-darwin-8 # Darwin 8 only gems that run on any CPU
- x86-mswin32-80 # Windows gems compiled with VC8
- armv7-linux # Gem complied for an ARMv7 CPU running linux
- arm-linux # Gem compiled for any ARM CPU running linux
-
-When building platform gems, set the platform in the gem specification to
-Gem::Platform::CURRENT. This will correctly mark the gem with your ruby's
-platform.
- EOF
-
- # NOTE when updating also update Gem::Command::HELP
-
- SUBCOMMANDS = [
- ["commands", :show_commands],
- ["options", Gem::Command::HELP],
- ["examples", EXAMPLES],
- ["gem_dependencies", GEM_DEPENDENCIES],
- ["platforms", PLATFORMS],
- ]
- # :startdoc:
-
- def initialize
- super 'help', "Provide help on the 'gem' command"
-
- @command_manager = Gem::CommandManager.instance
- end
-
- def usage # :nodoc:
- "#{program_name} ARGUMENT"
- end
-
- def execute
- arg = options[:args][0]
-
- _, help = SUBCOMMANDS.find do |command,|
- begins? command, arg
- end
-
- if help then
- if Symbol === help then
- send help
- else
- say help
- end
- return
- end
-
- if options[:help] then
- show_help
-
- elsif arg then
- show_command_help arg
-
- else
- say Gem::Command::HELP
- end
- end
-
- def show_commands # :nodoc:
- out = []
- out << "GEM commands are:"
- out << nil
-
- margin_width = 4
-
- desc_width = @command_manager.command_names.map { |n| n.size }.max + 4
-
- summary_width = 80 - margin_width - desc_width
- wrap_indent = ' ' * (margin_width + desc_width)
- format = "#{' ' * margin_width}%-#{desc_width}s%s"
-
- @command_manager.command_names.each do |cmd_name|
- command = @command_manager[cmd_name]
-
- summary =
- if command then
- command.summary
- else
- "[No command found for #{cmd_name}]"
- end
-
- summary = wrap(summary, summary_width).split "\n"
- out << sprintf(format, cmd_name, summary.shift)
- until summary.empty? do
- out << "#{wrap_indent}#{summary.shift}"
- end
- end
-
- out << nil
- out << "For help on a particular command, use 'gem help COMMAND'."
- out << nil
- out << "Commands may be abbreviated, so long as they are unambiguous."
- out << "e.g. 'gem i rake' is short for 'gem install rake'."
-
- say out.join("\n")
- end
-
- def show_command_help command_name # :nodoc:
- command_name = command_name.downcase
-
- possibilities = @command_manager.find_command_possibilities command_name
-
- if possibilities.size == 1 then
- command = @command_manager[possibilities.first]
- command.invoke("--help")
- elsif possibilities.size > 1 then
- alert_warning "Ambiguous command #{command_name} (#{possibilities.join(', ')})"
- else
- alert_warning "Unknown command #{command_name}. Try: gem help commands"
- end
- end
-
- def show_help # :nodoc:
- command = @command_manager[options[:help]]
- if command then
- # help with provided command
- command.invoke("--help")
- else
- alert_error "Unknown command #{options[:help]}. Try 'gem help commands'"
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/install_command.rb b/ruby_2_2/lib/rubygems/commands/install_command.rb
deleted file mode 100644
index 1bf5928ebb..0000000000
--- a/ruby_2_2/lib/rubygems/commands/install_command.rb
+++ /dev/null
@@ -1,347 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/install_update_options'
-require 'rubygems/dependency_installer'
-require 'rubygems/local_remote_options'
-require 'rubygems/validator'
-require 'rubygems/version_option'
-
-##
-# Gem installer command line tool
-#
-# See `gem help install`
-
-class Gem::Commands::InstallCommand < Gem::Command
-
- attr_reader :installed_specs # :nodoc:
-
- include Gem::VersionOption
- include Gem::LocalRemoteOptions
- include Gem::InstallUpdateOptions
-
- def initialize
- defaults = Gem::DependencyInstaller::DEFAULT_OPTIONS.merge({
- :format_executable => false,
- :lock => true,
- :suggest_alternate => true,
- :version => Gem::Requirement.default,
- :without_groups => [],
- })
-
- super 'install', 'Install a gem into the local repository', defaults
-
- add_install_update_options
- add_local_remote_options
- add_platform_option
- add_version_option
- add_prerelease_option "to be installed. (Only for listed gems)"
-
- add_option(:"Install/Update", '-g', '--file [FILE]',
- 'Read from a gem dependencies API file and',
- 'install the listed gems') do |v,o|
- v = Gem::GEM_DEP_FILES.find do |file|
- File.exist? file
- end unless v
-
- unless v then
- message = v ? v : "(tried #{Gem::GEM_DEP_FILES.join ', '})"
-
- raise OptionParser::InvalidArgument,
- "cannot find gem dependencies file #{message}"
- end
-
- o[:gemdeps] = v
- end
-
- add_option(:"Install/Update", '--without GROUPS', Array,
- 'Omit the named groups (comma separated)',
- 'when installing from a gem dependencies',
- 'file') do |v,o|
- o[:without_groups].concat v.map { |without| without.intern }
- end
-
- add_option(:"Install/Update", '--default',
- 'Add the gem\'s full specification to',
- 'specifications/default and extract only its bin') do |v,o|
- o[:install_as_default] = v
- end
-
- add_option(:"Install/Update", '--explain',
- 'Rather than install the gems, indicate which would',
- 'be installed') do |v,o|
- o[:explain] = v
- end
-
- add_option(:"Install/Update", '--[no-]lock',
- 'Create a lock file (when used with -g/--file)') do |v,o|
- o[:lock] = v
- end
-
- add_option(:"Install/Update", '--[no-]suggestions',
- 'Suggest alternates when gems are not found') do |v,o|
- o[:suggest_alternate] = v
- end
-
- @installed_specs = []
- end
-
- def arguments # :nodoc:
- "GEMNAME name of gem to install"
- end
-
- def defaults_str # :nodoc:
- "--both --version '#{Gem::Requirement.default}' --document --no-force\n" +
- "--install-dir #{Gem.dir} --lock"
- end
-
- def description # :nodoc:
- <<-EOF
-The install command installs local or remote gem into a gem repository.
-
-For gems with executables ruby installs a wrapper file into the executable
-directory by default. This can be overridden with the --no-wrappers option.
-The wrapper allows you to choose among alternate gem versions using _version_.
-
-For example `rake _0.7.3_ --version` will run rake version 0.7.3 if a newer
-version is also installed.
-
-Gem Dependency Files
-====================
-
-RubyGems can install a consistent set of gems across multiple environments
-using `gem install -g` when a gem dependencies file (gem.deps.rb, Gemfile or
-Isolate) is present. If no explicit file is given RubyGems attempts to find
-one in the current directory.
-
-When the RUBYGEMS_GEMDEPS environment variable is set to a gem dependencies
-file the gems from that file will be activated at startup time. Set it to a
-specific filename or to "-" to have RubyGems automatically discover the gem
-dependencies file by walking up from the current directory.
-
-NOTE: Enabling automatic discovery on multiuser systems can lead to
-execution of arbitrary code when used from directories outside your control.
-
-Extension Install Failures
-==========================
-
-If an extension fails to compile during gem installation the gem
-specification is not written out, but the gem remains unpacked in the
-repository. You may need to specify the path to the library's headers and
-libraries to continue. You can do this by adding a -- between RubyGems'
-options and the extension's build options:
-
- $ gem install some_extension_gem
- [build fails]
- Gem files will remain installed in \\
- /path/to/gems/some_extension_gem-1.0 for inspection.
- Results logged to /path/to/gems/some_extension_gem-1.0/gem_make.out
- $ gem install some_extension_gem -- --with-extension-lib=/path/to/lib
- [build succeeds]
- $ gem list some_extension_gem
-
- *** LOCAL GEMS ***
-
- some_extension_gem (1.0)
- $
-
-If you correct the compilation errors by editing the gem files you will need
-to write the specification by hand. For example:
-
- $ gem install some_extension_gem
- [build fails]
- Gem files will remain installed in \\
- /path/to/gems/some_extension_gem-1.0 for inspection.
- Results logged to /path/to/gems/some_extension_gem-1.0/gem_make.out
- $ [cd /path/to/gems/some_extension_gem-1.0]
- $ [edit files or what-have-you and run make]
- $ gem spec ../../cache/some_extension_gem-1.0.gem --ruby > \\
- ../../specifications/some_extension_gem-1.0.gemspec
- $ gem list some_extension_gem
-
- *** LOCAL GEMS ***
-
- some_extension_gem (1.0)
- $
-
- EOF
- end
-
- def usage # :nodoc:
- "#{program_name} GEMNAME [GEMNAME ...] [options] -- --build-flags"
- end
-
- def check_install_dir # :nodoc:
- if options[:install_dir] and options[:user_install] then
- alert_error "Use --install-dir or --user-install but not both"
- terminate_interaction 1
- end
- end
-
- def check_version # :nodoc:
- if options[:version] != Gem::Requirement.default and
- get_all_gem_names.size > 1 then
- alert_error "Can't use --version w/ multiple gems. Use name:ver instead."
- terminate_interaction 1
- end
- end
-
- def execute
- if options.include? :gemdeps then
- install_from_gemdeps
- return # not reached
- end
-
- @installed_specs = []
-
- ENV.delete 'GEM_PATH' if options[:install_dir].nil? and RUBY_VERSION > '1.9'
-
- check_install_dir
- check_version
-
- load_hooks
-
- exit_code = install_gems
-
- show_installed
-
- terminate_interaction exit_code
- end
-
- def install_from_gemdeps # :nodoc:
- require 'rubygems/request_set'
- rs = Gem::RequestSet.new
-
- specs = rs.install_from_gemdeps options do |req, inst|
- s = req.full_spec
-
- if inst
- say "Installing #{s.name} (#{s.version})"
- else
- say "Using #{s.name} (#{s.version})"
- end
- end
-
- @installed_specs = specs
-
- terminate_interaction
- end
-
- def install_gem name, version # :nodoc:
- return if options[:conservative] and
- not Gem::Dependency.new(name, version).matching_specs.empty?
-
- req = Gem::Requirement.create(version)
-
- if options[:ignore_dependencies] then
- install_gem_without_dependencies name, req
- else
- inst = Gem::DependencyInstaller.new options
- request_set = inst.resolve_dependencies name, req
-
- if options[:explain]
- puts "Gems to install:"
-
- request_set.sorted_requests.each do |s|
- puts " #{s.full_name}"
- end
-
- return
- else
- @installed_specs.concat request_set.install options
- end
-
- show_install_errors inst.errors
- end
- end
-
- def install_gem_without_dependencies name, req # :nodoc:
- gem = nil
-
- if local? then
- if name =~ /\.gem$/ and File.file? name then
- source = Gem::Source::SpecificFile.new name
- spec = source.spec
- else
- source = Gem::Source::Local.new
- spec = source.find_gem name, req
- end
- gem = source.download spec if spec
- end
-
- if remote? and not gem then
- dependency = Gem::Dependency.new name, req
- dependency.prerelease = options[:prerelease]
-
- fetcher = Gem::RemoteFetcher.fetcher
- gem = fetcher.download_to_cache dependency
- end
-
- inst = Gem::Installer.new gem, options
- inst.install
-
- require 'rubygems/dependency_installer'
- dinst = Gem::DependencyInstaller.new options
- dinst.installed_gems.replace [inst.spec]
-
- Gem.done_installing_hooks.each do |hook|
- hook.call dinst, [inst.spec]
- end unless Gem.done_installing_hooks.empty?
-
- @installed_specs.push(inst.spec)
- end
-
- def install_gems # :nodoc:
- exit_code = 0
-
- get_all_gem_names_and_versions.each do |gem_name, gem_version|
- gem_version ||= options[:version]
-
- begin
- install_gem gem_name, gem_version
- rescue Gem::InstallError => e
- alert_error "Error installing #{gem_name}:\n\t#{e.message}"
- exit_code |= 1
- rescue Gem::GemNotFoundException, Gem::UnsatisfiableDependencyError => e
- domain = options[:domain]
- domain = :local unless options[:suggest_alternate]
- show_lookup_failure e.name, e.version, e.errors, domain
-
- exit_code |= 2
- end
- end
-
- exit_code
- end
-
- ##
- # Loads post-install hooks
-
- def load_hooks # :nodoc:
- if options[:install_as_default]
- require 'rubygems/install_default_message'
- else
- require 'rubygems/install_message'
- end
- require 'rubygems/rdoc'
- end
-
- def show_install_errors errors # :nodoc:
- return unless errors
-
- errors.each do |x|
- return unless Gem::SourceFetchProblem === x
-
- msg = "Unable to pull data from '#{x.source.uri}': #{x.error.message}"
-
- alert_warning msg
- end
- end
-
- def show_installed # :nodoc:
- return if @installed_specs.empty?
-
- gems = @installed_specs.length == 1 ? 'gem' : 'gems'
- say "#{@installed_specs.length} #{gems} installed"
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/list_command.rb b/ruby_2_2/lib/rubygems/commands/list_command.rb
deleted file mode 100644
index c6ff237311..0000000000
--- a/ruby_2_2/lib/rubygems/commands/list_command.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/commands/query_command'
-
-##
-# An alternate to Gem::Commands::QueryCommand that searches for gems starting
-# with the the supplied argument.
-
-class Gem::Commands::ListCommand < Gem::Commands::QueryCommand
-
- def initialize
- super 'list', 'Display local gems whose name matches REGEXP'
-
- remove_option('--name-matches')
- end
-
- def arguments # :nodoc:
- "REGEXP regexp to look for in gem name"
- end
-
- def defaults_str # :nodoc:
- "--local --no-details"
- end
-
- def description # :nodoc:
- <<-EOF
-The list command is used to view the gems you have installed locally.
-
-The --details option displays additional details including the summary, the
-homepage, the author, the locations of different versions of the gem.
-
-To search for remote gems use the search command.
- EOF
- end
-
- def usage # :nodoc:
- "#{program_name} [STRING ...]"
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/lock_command.rb b/ruby_2_2/lib/rubygems/commands/lock_command.rb
deleted file mode 100644
index 6b4b25a281..0000000000
--- a/ruby_2_2/lib/rubygems/commands/lock_command.rb
+++ /dev/null
@@ -1,110 +0,0 @@
-require 'rubygems/command'
-
-class Gem::Commands::LockCommand < Gem::Command
-
- def initialize
- super 'lock', 'Generate a lockdown list of gems',
- :strict => false
-
- add_option '-s', '--[no-]strict',
- 'fail if unable to satisfy a dependency' do |strict, options|
- options[:strict] = strict
- end
- end
-
- def arguments # :nodoc:
- "GEMNAME name of gem to lock\nVERSION version of gem to lock"
- end
-
- def defaults_str # :nodoc:
- "--no-strict"
- end
-
- def description # :nodoc:
- <<-EOF
-The lock command will generate a list of +gem+ statements that will lock down
-the versions for the gem given in the command line. It will specify exact
-versions in the requirements list to ensure that the gems loaded will always
-be consistent. A full recursive search of all effected gems will be
-generated.
-
-Example:
-
- gem lock rails-1.0.0 > lockdown.rb
-
-will produce in lockdown.rb:
-
- require "rubygems"
- gem 'rails', '= 1.0.0'
- gem 'rake', '= 0.7.0.1'
- gem 'activesupport', '= 1.2.5'
- gem 'activerecord', '= 1.13.2'
- gem 'actionpack', '= 1.11.2'
- gem 'actionmailer', '= 1.1.5'
- gem 'actionwebservice', '= 1.0.0'
-
-Just load lockdown.rb from your application to ensure that the current
-versions are loaded. Make sure that lockdown.rb is loaded *before* any
-other require statements.
-
-Notice that rails 1.0.0 only requires that rake 0.6.2 or better be used.
-Rake-0.7.0.1 is the most recent version installed that satisfies that, so we
-lock it down to the exact version.
- EOF
- end
-
- def usage # :nodoc:
- "#{program_name} GEMNAME-VERSION [GEMNAME-VERSION ...]"
- end
-
- def complain(message)
- if options[:strict] then
- raise Gem::Exception, message
- else
- say "# #{message}"
- end
- end
-
- def execute
- say "require 'rubygems'"
-
- locked = {}
-
- pending = options[:args]
-
- until pending.empty? do
- full_name = pending.shift
-
- spec = Gem::Specification.load spec_path(full_name)
-
- if spec.nil? then
- complain "Could not find gem #{full_name}, try using the full name"
- next
- end
-
- say "gem '#{spec.name}', '= #{spec.version}'" unless locked[spec.name]
- locked[spec.name] = true
-
- spec.runtime_dependencies.each do |dep|
- next if locked[dep.name]
- candidates = dep.matching_specs
-
- if candidates.empty? then
- complain "Unable to satisfy '#{dep}' from currently installed gems"
- else
- pending << candidates.last.full_name
- end
- end
- end
- end
-
- def spec_path(gem_full_name)
- gemspecs = Gem.path.map { |path|
- File.join path, "specifications", "#{gem_full_name}.gemspec"
- }
-
- gemspecs.find { |path| File.exist? path }
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/mirror_command.rb b/ruby_2_2/lib/rubygems/commands/mirror_command.rb
deleted file mode 100644
index 24fb668d54..0000000000
--- a/ruby_2_2/lib/rubygems/commands/mirror_command.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require 'rubygems/command'
-
-unless defined? Gem::Commands::MirrorCommand
- class Gem::Commands::MirrorCommand < Gem::Command
- def initialize
- super('mirror', 'Mirror all gem files (requires rubygems-mirror)')
- begin
- Gem::Specification.find_by_name('rubygems-mirror').activate
- rescue Gem::LoadError
- # no-op
- end
- end
-
- def description # :nodoc:
- <<-EOF
-The mirror command has been moved to the rubygems-mirror gem.
- EOF
- end
-
- def execute
- alert_error "Install the rubygems-mirror gem for the mirror command"
- end
-
- end
-end
diff --git a/ruby_2_2/lib/rubygems/commands/open_command.rb b/ruby_2_2/lib/rubygems/commands/open_command.rb
deleted file mode 100644
index 91963bba73..0000000000
--- a/ruby_2_2/lib/rubygems/commands/open_command.rb
+++ /dev/null
@@ -1,74 +0,0 @@
-require 'English'
-require 'rubygems/command'
-require 'rubygems/version_option'
-require 'rubygems/util'
-
-class Gem::Commands::OpenCommand < Gem::Command
-
- include Gem::VersionOption
-
- def initialize
- super 'open', 'Open gem sources in editor'
-
- add_option('-e', '--editor EDITOR', String,
- "Opens gem sources in EDITOR") do |editor, options|
- options[:editor] = editor || get_env_editor
- end
- end
-
- def arguments # :nodoc:
- "GEMNAME name of gem to open in editor"
- end
-
- def defaults_str # :nodoc:
- "-e #{get_env_editor}"
- end
-
- def description # :nodoc:
- <<-EOF
- The open command opens gem in editor and changes current path
- to gem's source directory. Editor can be specified with -e option,
- otherwise rubygems will look for editor in $EDITOR, $VISUAL and
- $GEM_EDITOR variables.
- EOF
- end
-
- def usage # :nodoc:
- "#{program_name} GEMNAME [-e EDITOR]"
- end
-
- def get_env_editor
- ENV['GEM_EDITOR'] ||
- ENV['VISUAL'] ||
- ENV['EDITOR'] ||
- 'vi'
- end
-
- def execute
- @version = options[:version] || Gem::Requirement.default
- @editor = options[:editor] || get_env_editor
-
- found = open_gem(get_one_gem_name)
-
- terminate_interaction 1 unless found
- end
-
- def open_gem name
- spec = spec_for name
- return false unless spec
-
- open_editor(spec.full_gem_path)
- end
-
- def open_editor path
- system(*@editor.split(/\s+/) + [path])
- end
-
- def spec_for name
- spec = Gem::Specification.find_all_by_name(name, @version).last
-
- return spec if spec
-
- say "Unable to find gem '#{name}'"
- end
-end
diff --git a/ruby_2_2/lib/rubygems/commands/outdated_command.rb b/ruby_2_2/lib/rubygems/commands/outdated_command.rb
deleted file mode 100644
index 7159dbb984..0000000000
--- a/ruby_2_2/lib/rubygems/commands/outdated_command.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/local_remote_options'
-require 'rubygems/spec_fetcher'
-require 'rubygems/version_option'
-
-class Gem::Commands::OutdatedCommand < Gem::Command
-
- include Gem::LocalRemoteOptions
- include Gem::VersionOption
-
- def initialize
- super 'outdated', 'Display all gems that need updates'
-
- add_local_remote_options
- add_platform_option
- end
-
- def description # :nodoc:
- <<-EOF
-The outdated command lists gems you may wish to upgrade to a newer version.
-
-You can check for dependency mismatches using the dependency command and
-update the gems with the update or install commands.
- EOF
- end
-
- def execute
- Gem::Specification.outdated_and_latest_version.each do |spec, remote_version|
- say "#{spec.name} (#{spec.version} < #{remote_version})"
- end
- end
-end
diff --git a/ruby_2_2/lib/rubygems/commands/owner_command.rb b/ruby_2_2/lib/rubygems/commands/owner_command.rb
deleted file mode 100644
index 322bf6590a..0000000000
--- a/ruby_2_2/lib/rubygems/commands/owner_command.rb
+++ /dev/null
@@ -1,99 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/local_remote_options'
-require 'rubygems/gemcutter_utilities'
-
-class Gem::Commands::OwnerCommand < Gem::Command
- include Gem::LocalRemoteOptions
- include Gem::GemcutterUtilities
-
- def description # :nodoc:
- <<-EOF
-The owner command lets you add and remove owners of a gem on a push
-server (the default is https://rubygems.org).
-
-The owner of a gem has the permission to push new versions, yank existing
-versions or edit the HTML page of the gem. Be careful of who you give push
-permission to.
- EOF
- end
-
- def arguments # :nodoc:
- "GEM gem to manage owners for"
- end
-
- def usage # :nodoc:
- "#{program_name} GEM"
- end
-
- def initialize
- super 'owner', 'Manage gem owners of a gem on the push server'
- add_proxy_option
- add_key_option
- defaults.merge! :add => [], :remove => []
-
- add_option '-a', '--add EMAIL', 'Add an owner' do |value, options|
- options[:add] << value
- end
-
- add_option '-r', '--remove EMAIL', 'Remove an owner' do |value, options|
- options[:remove] << value
- end
-
- add_option '-h', '--host HOST', 'Use another gemcutter-compatible host' do |value, options|
- options[:host] = value
- end
- end
-
- def execute
- @host = options[:host]
-
- sign_in
- name = get_one_gem_name
-
- add_owners name, options[:add]
- remove_owners name, options[:remove]
- show_owners name
- end
-
- def show_owners name
- response = rubygems_api_request :get, "api/v1/gems/#{name}/owners.yaml" do |request|
- request.add_field "Authorization", api_key
- end
-
- with_response response do |resp|
- owners = YAML.load resp.body
-
- say "Owners for gem: #{name}"
- owners.each do |owner|
- say "- #{owner['email']}"
- end
- end
- end
-
- def add_owners name, owners
- manage_owners :post, name, owners
- end
-
- def remove_owners name, owners
- manage_owners :delete, name, owners
- end
-
- def manage_owners method, name, owners
- owners.each do |owner|
- begin
- response = rubygems_api_request method, "api/v1/gems/#{name}/owners" do |request|
- request.set_form_data 'email' => owner
- request.add_field "Authorization", api_key
- end
-
- action = method == :delete ? "Removing" : "Adding"
-
- with_response response, "#{action} #{owner}"
- rescue
- # ignore
- end
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/pristine_command.rb b/ruby_2_2/lib/rubygems/commands/pristine_command.rb
deleted file mode 100644
index dcd5bb76fb..0000000000
--- a/ruby_2_2/lib/rubygems/commands/pristine_command.rb
+++ /dev/null
@@ -1,165 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/package'
-require 'rubygems/installer'
-require 'rubygems/version_option'
-
-class Gem::Commands::PristineCommand < Gem::Command
-
- include Gem::VersionOption
-
- def initialize
- super 'pristine',
- 'Restores installed gems to pristine condition from files located in the gem cache',
- :version => Gem::Requirement.default,
- :extensions => true,
- :extensions_set => false,
- :all => false
-
- add_option('--all',
- 'Restore all installed gems to pristine',
- 'condition') do |value, options|
- options[:all] = value
- end
-
- add_option('--[no-]extensions',
- 'Restore gems with extensions',
- 'in addition to regular gems') do |value, options|
- options[:extensions_set] = true
- options[:extensions] = value
- end
-
- add_option('--only-executables',
- 'Only restore executables') do |value, options|
- options[:only_executables] = value
- end
-
- add_option('-E', '--[no-]env-shebang',
- 'Rewrite executables with a shebang',
- 'of /usr/bin/env') do |value, options|
- options[:env_shebang] = value
- end
-
- add_version_option('restore to', 'pristine condition')
- end
-
- def arguments # :nodoc:
- "GEMNAME gem to restore to pristine condition (unless --all)"
- end
-
- def defaults_str # :nodoc:
- '--extensions'
- end
-
- def description # :nodoc:
- <<-EOF
-The pristine command compares an installed gem with the contents of its
-cached .gem file and restores any files that don't match the cached .gem's
-copy.
-
-If you have made modifications to an installed gem, the pristine command
-will revert them. All extensions are rebuilt and all bin stubs for the gem
-are regenerated after checking for modifications.
-
-If the cached gem cannot be found it will be downloaded.
-
-If --no-extensions is provided pristine will not attempt to restore a gem
-with an extension.
-
-If --extensions is given (but not --all or gem names) only gems with
-extensions will be restored.
- EOF
- end
-
- def usage # :nodoc:
- "#{program_name} [GEMNAME ...]"
- end
-
- def execute
- specs = if options[:all] then
- Gem::Specification.map
-
- # `--extensions` must be explicitly given to pristine only gems
- # with extensions.
- elsif options[:extensions_set] and
- options[:extensions] and options[:args].empty? then
- Gem::Specification.select do |spec|
- spec.extensions and not spec.extensions.empty?
- end
- else
- get_all_gem_names.map do |gem_name|
- Gem::Specification.find_all_by_name gem_name, options[:version]
- end.flatten
- end
-
- if specs.to_a.empty? then
- raise Gem::Exception,
- "Failed to find gems #{options[:args]} #{options[:version]}"
- end
-
- install_dir = Gem.dir # TODO use installer option
-
- raise Gem::FilePermissionError.new(install_dir) unless
- File.writable?(install_dir)
-
- say "Restoring gems to pristine condition..."
-
- specs.each do |spec|
- if spec.default_gem?
- say "Skipped #{spec.full_name}, it is a default gem"
- next
- end
-
- if spec.bundled_gem_in_old_ruby?
- say "Skipped #{spec.full_name}, it is bundled with old Ruby"
- next
- end
-
- unless spec.extensions.empty? or options[:extensions] then
- say "Skipped #{spec.full_name}, it needs to compile an extension"
- next
- end
-
- gem = spec.cache_file
-
- unless File.exist? gem then
- require 'rubygems/remote_fetcher'
-
- say "Cached gem for #{spec.full_name} not found, attempting to fetch..."
-
- dep = Gem::Dependency.new spec.name, spec.version
- found, _ = Gem::SpecFetcher.fetcher.spec_for_dependency dep
-
- if found.empty?
- say "Skipped #{spec.full_name}, it was not found from cache and remote sources"
- next
- end
-
- spec_candidate, source = found.first
- Gem::RemoteFetcher.fetcher.download spec_candidate, source.uri.to_s, spec.base_dir
- end
-
- env_shebang =
- if options.include? :env_shebang then
- options[:env_shebang]
- else
- install_defaults = Gem::ConfigFile::PLATFORM_DEFAULTS['install']
- install_defaults.to_s['--env-shebang']
- end
-
- installer = Gem::Installer.new(gem,
- :wrappers => true,
- :force => true,
- :install_dir => spec.base_dir,
- :env_shebang => env_shebang,
- :build_args => spec.build_args)
-
- if options[:only_executables] then
- installer.generate_bin
- else
- installer.install
- end
-
- say "Restored #{spec.full_name}"
- end
- end
-end
diff --git a/ruby_2_2/lib/rubygems/commands/push_command.rb b/ruby_2_2/lib/rubygems/commands/push_command.rb
deleted file mode 100644
index 6899b489ad..0000000000
--- a/ruby_2_2/lib/rubygems/commands/push_command.rb
+++ /dev/null
@@ -1,98 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/local_remote_options'
-require 'rubygems/gemcutter_utilities'
-require 'rubygems/package'
-
-class Gem::Commands::PushCommand < Gem::Command
- include Gem::LocalRemoteOptions
- include Gem::GemcutterUtilities
-
- def description # :nodoc:
- <<-EOF
-The push command uploads a gem to the push server (the default is
-https://rubygems.org) and adds it to the index.
-
-The gem can be removed from the index (but only the index) using the yank
-command. For further discussion see the help for the yank command.
- EOF
- end
-
- def arguments # :nodoc:
- "GEM built gem to push up"
- end
-
- def usage # :nodoc:
- "#{program_name} GEM"
- end
-
- def initialize
- super 'push', 'Push a gem up to the gem server', :host => self.host
-
- add_proxy_option
- add_key_option
-
- add_option('--host HOST',
- 'Push to another gemcutter-compatible host') do |value, options|
- options[:host] = value
- end
-
- @host = nil
- end
-
- def execute
- @host = options[:host]
-
- sign_in @host
-
- send_gem get_one_gem_name
- end
-
- def send_gem name
- args = [:post, "api/v1/gems"]
-
- latest_rubygems_version = Gem.latest_rubygems_version
-
- if latest_rubygems_version < Gem.rubygems_version and
- Gem.rubygems_version.prerelease? and
- Gem::Version.new('2.0.0.rc.2') != Gem.rubygems_version then
- alert_error <<-ERROR
-You are using a beta release of RubyGems (#{Gem::VERSION}) which is not
-allowed to push gems. Please downgrade or upgrade to a release version.
-
-The latest released RubyGems version is #{latest_rubygems_version}
-
-You can upgrade or downgrade to the latest release version with:
-
- gem update --system=#{latest_rubygems_version}
-
- ERROR
- terminate_interaction 1
- end
-
- gem_data = Gem::Package.new(name)
-
- unless @host then
- @host = gem_data.spec.metadata['default_gem_server']
- end
-
- # Always include this, even if it's nil
- args << @host
-
- if gem_data.spec.metadata.has_key?('allowed_push_host')
- args << gem_data.spec.metadata['allowed_push_host']
- end
-
- say "Pushing gem to #{@host || Gem.host}..."
-
- response = rubygems_api_request(*args) do |request|
- request.body = Gem.read_binary name
- request.add_field "Content-Length", request.body.size
- request.add_field "Content-Type", "application/octet-stream"
- request.add_field "Authorization", api_key
- end
-
- with_response response
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/query_command.rb b/ruby_2_2/lib/rubygems/commands/query_command.rb
deleted file mode 100644
index 44364cfab2..0000000000
--- a/ruby_2_2/lib/rubygems/commands/query_command.rb
+++ /dev/null
@@ -1,344 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/local_remote_options'
-require 'rubygems/spec_fetcher'
-require 'rubygems/version_option'
-require 'rubygems/text'
-
-class Gem::Commands::QueryCommand < Gem::Command
-
- include Gem::Text
- include Gem::LocalRemoteOptions
- include Gem::VersionOption
-
- def initialize(name = 'query',
- summary = 'Query gem information in local or remote repositories')
- super name, summary,
- :name => //, :domain => :local, :details => false, :versions => true,
- :installed => nil, :version => Gem::Requirement.default
-
- add_option('-i', '--[no-]installed',
- 'Check for installed gem') do |value, options|
- options[:installed] = value
- end
-
- add_option('-I', 'Equivalent to --no-installed') do |value, options|
- options[:installed] = false
- end
-
- add_version_option command, "for use with --installed"
-
- add_option('-n', '--name-matches REGEXP',
- 'Name of gem(s) to query on matches the',
- 'provided REGEXP') do |value, options|
- options[:name] = /#{value}/i
- end
-
- add_option('-d', '--[no-]details',
- 'Display detailed information of gem(s)') do |value, options|
- options[:details] = value
- end
-
- add_option( '--[no-]versions',
- 'Display only gem names') do |value, options|
- options[:versions] = value
- options[:details] = false unless value
- end
-
- add_option('-a', '--all',
- 'Display all gem versions') do |value, options|
- options[:all] = value
- end
-
- add_option( '--[no-]prerelease',
- 'Display prerelease versions') do |value, options|
- options[:prerelease] = value
- end
-
- add_local_remote_options
- end
-
- def defaults_str # :nodoc:
- "--local --name-matches // --no-details --versions --no-installed"
- end
-
- def description # :nodoc:
- <<-EOF
-The query command is the basis for the list and search commands.
-
-You should really use the list and search commands instead. This command
-is too hard to use.
- EOF
- end
-
- def execute
- exit_code = 0
- if options[:args].to_a.empty? and options[:name].source.empty?
- name = options[:name]
- no_name = true
- elsif !options[:name].source.empty?
- name = Array(options[:name])
- else
- name = options[:args].to_a.map{|arg| /#{arg}/i }
- end
-
- prerelease = options[:prerelease]
-
- unless options[:installed].nil? then
- if no_name then
- alert_error "You must specify a gem name"
- exit_code |= 4
- elsif name.count > 1
- alert_error "You must specify only ONE gem!"
- exit_code |= 4
- else
- installed = installed? name.first, options[:version]
- installed = !installed unless options[:installed]
-
- if installed then
- say "true"
- else
- say "false"
- exit_code |= 1
- end
- end
-
- terminate_interaction exit_code
- end
-
- names = Array(name)
- names.each { |n| show_gems n, prerelease }
- end
-
- private
-
- def display_header type
- if (ui.outs.tty? and Gem.configuration.verbose) or both? then
- say
- say "*** #{type} GEMS ***"
- say
- end
- end
-
- #Guts of original execute
- def show_gems name, prerelease
- req = Gem::Requirement.default
- # TODO: deprecate for real
- dep = Gem::Deprecate.skip_during { Gem::Dependency.new name, req }
- dep.prerelease = prerelease
-
- if local? then
- if prerelease and not both? then
- alert_warning "prereleases are always shown locally"
- end
-
- display_header 'LOCAL'
-
- specs = Gem::Specification.find_all { |s|
- s.name =~ name and req =~ s.version
- }
-
- spec_tuples = specs.map do |spec|
- [spec.name_tuple, spec]
- end
-
- output_query_results spec_tuples
- end
-
- if remote? then
- display_header 'REMOTE'
-
- fetcher = Gem::SpecFetcher.fetcher
-
- type = if options[:all]
- if options[:prerelease]
- :complete
- else
- :released
- end
- elsif options[:prerelease]
- :prerelease
- else
- :latest
- end
-
- if name.source.empty?
- spec_tuples = fetcher.detect(type) { true }
- else
- spec_tuples = fetcher.detect(type) do |name_tuple|
- name === name_tuple.name
- end
- end
-
- output_query_results spec_tuples
- end
- end
-
- ##
- # Check if gem +name+ version +version+ is installed.
-
- def installed?(name, req = Gem::Requirement.default)
- Gem::Specification.any? { |s| s.name =~ name and req =~ s.version }
- end
-
- def output_query_results(spec_tuples)
- output = []
- versions = Hash.new { |h,name| h[name] = [] }
-
- spec_tuples.each do |spec_tuple, source|
- versions[spec_tuple.name] << [spec_tuple, source]
- end
-
- versions = versions.sort_by do |(n,_),_|
- n.downcase
- end
-
- output_versions output, versions
-
- say output.join(options[:details] ? "\n\n" : "\n")
- end
-
- def output_versions output, versions
- versions.each do |gem_name, matching_tuples|
- matching_tuples = matching_tuples.sort_by { |n,_| n.version }.reverse
-
- platforms = Hash.new { |h,version| h[version] = [] }
-
- matching_tuples.each do |n, _|
- platforms[n.version] << n.platform if n.platform
- end
-
- seen = {}
-
- matching_tuples.delete_if do |n,_|
- if seen[n.version] then
- true
- else
- seen[n.version] = true
- false
- end
- end
-
- output << clean_text(make_entry(matching_tuples, platforms))
- end
- end
-
- def entry_details entry, detail_tuple, specs, platforms
- return unless options[:details]
-
- name_tuple, spec = detail_tuple
-
- spec = spec.fetch_spec name_tuple unless Gem::Specification === spec
-
- entry << "\n"
-
- spec_platforms entry, platforms
- spec_authors entry, spec
- spec_homepage entry, spec
- spec_license entry, spec
- spec_loaded_from entry, spec, specs
- spec_summary entry, spec
- end
-
- def entry_versions entry, name_tuples, platforms
- return unless options[:versions]
-
- list =
- if platforms.empty? or options[:details] then
- name_tuples.map { |n| n.version }.uniq
- else
- platforms.sort.reverse.map do |version, pls|
- if pls == [Gem::Platform::RUBY] then
- version
- else
- ruby = pls.delete Gem::Platform::RUBY
- platform_list = [ruby, *pls.sort].compact
- "#{version} #{platform_list.join ' '}"
- end
- end
- end
-
- entry << " (#{list.join ', '})"
- end
-
- def make_entry entry_tuples, platforms
- detail_tuple = entry_tuples.first
-
- name_tuples, specs = entry_tuples.flatten.partition do |item|
- Gem::NameTuple === item
- end
-
- entry = [name_tuples.first.name]
-
- entry_versions entry, name_tuples, platforms
- entry_details entry, detail_tuple, specs, platforms
-
- entry.join
- end
-
- def spec_authors entry, spec
- authors = "Author#{spec.authors.length > 1 ? 's' : ''}: "
- authors << spec.authors.join(', ')
- entry << format_text(authors, 68, 4)
- end
-
- def spec_homepage entry, spec
- return if spec.homepage.nil? or spec.homepage.empty?
-
- entry << "\n" << format_text("Homepage: #{spec.homepage}", 68, 4)
- end
-
- def spec_license entry, spec
- return if spec.license.nil? or spec.license.empty?
-
- licenses = "License#{spec.licenses.length > 1 ? 's' : ''}: "
- licenses << spec.licenses.join(', ')
- entry << "\n" << format_text(licenses, 68, 4)
- end
-
- def spec_loaded_from entry, spec, specs
- return unless spec.loaded_from
-
- if specs.length == 1 then
- default = spec.default_gem? ? ' (default)' : nil
- entry << "\n" << " Installed at#{default}: #{spec.base_dir}"
- else
- label = 'Installed at'
- specs.each do |s|
- version = s.version.to_s
- version << ', default' if s.default_gem?
- entry << "\n" << " #{label} (#{version}): #{s.base_dir}"
- label = ' ' * label.length
- end
- end
- end
-
- def spec_platforms entry, platforms
- non_ruby = platforms.any? do |_, pls|
- pls.any? { |pl| pl != Gem::Platform::RUBY }
- end
-
- return unless non_ruby
-
- if platforms.length == 1 then
- title = platforms.values.length == 1 ? 'Platform' : 'Platforms'
- entry << " #{title}: #{platforms.values.sort.join ', '}\n"
- else
- entry << " Platforms:\n"
- platforms.sort_by do |version,|
- version
- end.each do |version, pls|
- label = " #{version}: "
- data = format_text pls.sort.join(', '), 68, label.length
- data[0, label.length] = label
- entry << data << "\n"
- end
- end
- end
-
- def spec_summary entry, spec
- summary = truncate_text(spec.summary, "the summary for #{spec.full_name}")
- entry << "\n\n" << format_text(summary, 68, 4)
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/rdoc_command.rb b/ruby_2_2/lib/rubygems/commands/rdoc_command.rb
deleted file mode 100644
index 86597f99a6..0000000000
--- a/ruby_2_2/lib/rubygems/commands/rdoc_command.rb
+++ /dev/null
@@ -1,96 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/version_option'
-require 'rubygems/rdoc'
-require 'fileutils'
-
-class Gem::Commands::RdocCommand < Gem::Command
- include Gem::VersionOption
-
- def initialize
- super 'rdoc', 'Generates RDoc for pre-installed gems',
- :version => Gem::Requirement.default,
- :include_rdoc => false, :include_ri => true, :overwrite => false
-
- add_option('--all',
- 'Generate RDoc/RI documentation for all',
- 'installed gems') do |value, options|
- options[:all] = value
- end
-
- add_option('--[no-]rdoc',
- 'Generate RDoc HTML') do |value, options|
- options[:include_rdoc] = value
- end
-
- add_option('--[no-]ri',
- 'Generate RI data') do |value, options|
- options[:include_ri] = value
- end
-
- add_option('--[no-]overwrite',
- 'Overwrite installed documents') do |value, options|
- options[:overwrite] = value
- end
-
- add_version_option
- end
-
- def arguments # :nodoc:
- "GEMNAME gem to generate documentation for (unless --all)"
- end
-
- def defaults_str # :nodoc:
- "--version '#{Gem::Requirement.default}' --ri --no-overwrite"
- end
-
- def description # :nodoc:
- <<-DESC
-The rdoc command builds documentation for installed gems. By default
-only documentation is built using rdoc, but additional types of
-documentation may be built through rubygems plugins and the
-Gem.post_installs hook.
-
-Use --overwrite to force rebuilding of documentation.
- DESC
- end
-
- def usage # :nodoc:
- "#{program_name} [args]"
- end
-
- def execute
- specs = if options[:all] then
- Gem::Specification.to_a
- else
- get_all_gem_names.map do |name|
- Gem::Specification.find_by_name name, options[:version]
- end.flatten.uniq
- end
-
- if specs.empty? then
- alert_error 'No matching gems found'
- terminate_interaction 1
- end
-
- specs.each do |spec|
- doc = Gem::RDoc.new spec, options[:include_rdoc], options[:include_ri]
-
- doc.force = options[:overwrite]
-
- if options[:overwrite] then
- FileUtils.rm_rf File.join(spec.doc_dir, 'ri')
- FileUtils.rm_rf File.join(spec.doc_dir, 'rdoc')
- end
-
- begin
- doc.generate
- rescue Errno::ENOENT => e
- e.message =~ / - /
- alert_error "Unable to document #{spec.full_name}, #{$'} is missing, skipping"
- terminate_interaction 1 if specs.length == 1
- end
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/search_command.rb b/ruby_2_2/lib/rubygems/commands/search_command.rb
deleted file mode 100644
index a1e2c1a00e..0000000000
--- a/ruby_2_2/lib/rubygems/commands/search_command.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/commands/query_command'
-
-class Gem::Commands::SearchCommand < Gem::Commands::QueryCommand
-
- def initialize
- super 'search', 'Display remote gems whose name matches REGEXP'
-
- remove_option '--name-matches'
-
- defaults[:domain] = :remote
- end
-
- def arguments # :nodoc:
- "REGEXP regexp to search for in gem name"
- end
-
- def defaults_str # :nodoc:
- "--remote --no-details"
- end
-
- def description # :nodoc:
- <<-EOF
-The search command displays remote gems whose name matches the given
-regexp.
-
-The --details option displays additional details from the gem but will
-take a little longer to complete as it must download the information
-individually from the index.
-
-To list local gems use the list command.
- EOF
- end
-
- def usage # :nodoc:
- "#{program_name} [REGEXP]"
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/server_command.rb b/ruby_2_2/lib/rubygems/commands/server_command.rb
deleted file mode 100644
index 4796ce2ad6..0000000000
--- a/ruby_2_2/lib/rubygems/commands/server_command.rb
+++ /dev/null
@@ -1,86 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/server'
-
-class Gem::Commands::ServerCommand < Gem::Command
-
- def initialize
- super 'server', 'Documentation and gem repository HTTP server',
- :port => 8808, :gemdir => [], :daemon => false
-
- OptionParser.accept :Port do |port|
- if port =~ /\A\d+\z/ then
- port = Integer port
- raise OptionParser::InvalidArgument, "#{port}: not a port number" if
- port > 65535
-
- port
- else
- begin
- Socket.getservbyname port
- rescue SocketError
- raise OptionParser::InvalidArgument, "#{port}: no such named service"
- end
- end
- end
-
- add_option '-p', '--port=PORT', :Port,
- 'port to listen on' do |port, options|
- options[:port] = port
- end
-
- add_option '-d', '--dir=GEMDIR',
- 'directories from which to serve gems',
- 'multiple directories may be provided' do |gemdir, options|
- options[:gemdir] << File.expand_path(gemdir)
- end
-
- add_option '--[no-]daemon', 'run as a daemon' do |daemon, options|
- options[:daemon] = daemon
- end
-
- add_option '-b', '--bind=HOST,HOST',
- 'addresses to bind', Array do |address, options|
- options[:addresses] ||= []
- options[:addresses].push(*address)
- end
-
- add_option '-l', '--launch[=COMMAND]',
- 'launches a browser window',
- "COMMAND defaults to 'start' on Windows",
- "and 'open' on all other platforms" do |launch, options|
- launch ||= Gem.win_platform? ? 'start' : 'open'
- options[:launch] = launch
- end
- end
-
- def defaults_str # :nodoc:
- "--port 8808 --dir #{Gem.dir} --no-daemon"
- end
-
- def description # :nodoc:
- <<-EOF
-The server command starts up a web server that hosts the RDoc for your
-installed gems and can operate as a server for installation of gems on other
-machines.
-
-The cache files for installed gems must exist to use the server as a source
-for gem installation.
-
-To install gems from a running server, use `gem install GEMNAME --source
-http://gem_server_host:8808`
-
-You can set up a shortcut to gem server documentation using the URL:
-
- http://localhost:8808/rdoc?q=%s - Firefox
- http://localhost:8808/rdoc?q=* - LaunchBar
-
- EOF
- end
-
- def execute
- options[:gemdir] = Gem.path if options[:gemdir].empty?
- Gem::Server.run options
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/setup_command.rb b/ruby_2_2/lib/rubygems/commands/setup_command.rb
deleted file mode 100644
index 6617396780..0000000000
--- a/ruby_2_2/lib/rubygems/commands/setup_command.rb
+++ /dev/null
@@ -1,483 +0,0 @@
-require 'rubygems/command'
-
-##
-# Installs RubyGems itself. This command is ordinarily only available from a
-# RubyGems checkout or tarball.
-
-class Gem::Commands::SetupCommand < Gem::Command
- HISTORY_HEADER = /^===\s*[\d.]+\s*\/\s*\d{4}-\d{2}-\d{2}\s*$/
- VERSION_MATCHER = /^===\s*([\d.]+)\s*\/\s*\d{4}-\d{2}-\d{2}\s*$/
-
- def initialize
- require 'tmpdir'
-
- super 'setup', 'Install RubyGems',
- :format_executable => true, :document => %w[ri],
- :site_or_vendor => 'sitelibdir',
- :destdir => '', :prefix => '', :previous_version => ''
-
- add_option '--previous-version=VERSION',
- 'Previous version of rubygems',
- 'Used for changelog processing' do |version, options|
- options[:previous_version] = version
- end
-
- add_option '--prefix=PREFIX',
- 'Prefix path for installing RubyGems',
- 'Will not affect gem repository location' do |prefix, options|
- options[:prefix] = File.expand_path prefix
- end
-
- add_option '--destdir=DESTDIR',
- 'Root directory to install RubyGems into',
- 'Mainly used for packaging RubyGems' do |destdir, options|
- options[:destdir] = File.expand_path destdir
- end
-
- add_option '--[no-]vendor',
- 'Install into vendorlibdir not sitelibdir' do |vendor, options|
- options[:site_or_vendor] = vendor ? 'vendorlibdir' : 'sitelibdir'
- end
-
- add_option '--[no-]format-executable',
- 'Makes `gem` match ruby',
- 'If ruby is ruby18, gem will be gem18' do |value, options|
- options[:format_executable] = value
- end
-
- add_option '--[no-]document [TYPES]', Array,
- 'Generate documentation for RubyGems.',
- 'List the documentation types you wish to',
- 'generate. For example: rdoc,ri' do |value, options|
- options[:document] = case value
- when nil then %w[rdoc ri]
- when false then []
- else value
- end
- end
-
- add_option '--[no-]rdoc',
- 'Generate RDoc documentation for RubyGems' do |value, options|
- if value then
- options[:document] << 'rdoc'
- else
- options[:document].delete 'rdoc'
- end
-
- options[:document].uniq!
- end
-
- add_option '--[no-]ri',
- 'Generate RI documentation for RubyGems' do |value, options|
- if value then
- options[:document] << 'ri'
- else
- options[:document].delete 'ri'
- end
-
- options[:document].uniq!
- end
-
- @verbose = nil
- end
-
- def check_ruby_version
- required_version = Gem::Requirement.new '>= 1.8.7'
-
- unless required_version.satisfied_by? Gem.ruby_version then
- alert_error "Expected Ruby version #{required_version}, is #{Gem.ruby_version}"
- terminate_interaction 1
- end
- end
-
- def defaults_str # :nodoc:
- "--format-executable --document ri"
- end
-
- def description # :nodoc:
- <<-EOF
-Installs RubyGems itself.
-
-RubyGems installs RDoc for itself in GEM_HOME. By default this is:
- #{Gem.dir}
-
-If you prefer a different directory, set the GEM_HOME environment variable.
-
-RubyGems will install the gem command with a name matching ruby's
-prefix and suffix. If ruby was installed as `ruby18`, gem will be
-installed as `gem18`.
-
-By default, this RubyGems will install gem as:
- #{Gem.default_exec_format % 'gem'}
- EOF
- end
-
- def execute
- @verbose = Gem.configuration.really_verbose
-
- install_destdir = options[:destdir]
-
- unless install_destdir.empty? then
- ENV['GEM_HOME'] ||= File.join(install_destdir,
- Gem.default_dir.gsub(/^[a-zA-Z]:/, ''))
- end
-
- check_ruby_version
-
- require 'fileutils'
- if Gem.configuration.really_verbose then
- extend FileUtils::Verbose
- else
- extend FileUtils
- end
-
- lib_dir, bin_dir = make_destination_dirs install_destdir
-
- install_lib lib_dir
-
- install_executables bin_dir
-
- remove_old_bin_files bin_dir
-
- remove_old_lib_files lib_dir
-
- say "RubyGems #{Gem::VERSION} installed"
-
- uninstall_old_gemcutter
-
- documentation_success = install_rdoc
-
- say
- if @verbose then
- say "-" * 78
- say
- end
-
- if options[:previous_version].empty?
- options[:previous_version] = Gem::VERSION.sub(/[0-9]+$/, '0')
- end
-
- options[:previous_version] = Gem::Version.new(options[:previous_version])
-
- show_release_notes
-
- say
- say "-" * 78
- say
-
- say "RubyGems installed the following executables:"
- say @bin_file_names.map { |name| "\t#{name}\n" }
- say
-
- unless @bin_file_names.grep(/#{File::SEPARATOR}gem$/) then
- say "If `gem` was installed by a previous RubyGems installation, you may need"
- say "to remove it by hand."
- say
- end
-
- if documentation_success
- if options[:document].include? 'rdoc' then
- say "Rdoc documentation was installed. You may now invoke:"
- say " gem server"
- say "and then peruse beautifully formatted documentation for your gems"
- say "with your web browser."
- say "If you do not wish to install this documentation in the future, use the"
- say "--no-document flag, or set it as the default in your ~/.gemrc file. See"
- say "'gem help env' for details."
- say
- end
-
- if options[:document].include? 'ri' then
- say "Ruby Interactive (ri) documentation was installed. ri is kind of like man "
- say "pages for ruby libraries. You may access it like this:"
- say " ri Classname"
- say " ri Classname.class_method"
- say " ri Classname#instance_method"
- say "If you do not wish to install this documentation in the future, use the"
- say "--no-document flag, or set it as the default in your ~/.gemrc file. See"
- say "'gem help env' for details."
- say
- end
- end
- end
-
- def install_executables(bin_dir)
- say "Installing gem executable" if @verbose
-
- @bin_file_names = []
-
- Dir.chdir 'bin' do
- bin_files = Dir['*']
-
- bin_files.delete 'update_rubygems'
-
- bin_files.each do |bin_file|
- bin_file_formatted = if options[:format_executable] then
- Gem.default_exec_format % bin_file
- else
- bin_file
- end
-
- dest_file = File.join bin_dir, bin_file_formatted
- bin_tmp_file = File.join Dir.tmpdir, "#{bin_file}.#{$$}"
-
- begin
- bin = File.readlines bin_file
- bin[0] = "#!#{Gem.ruby}\n"
-
- File.open bin_tmp_file, 'w' do |fp|
- fp.puts bin.join
- end
-
- install bin_tmp_file, dest_file, :mode => 0755
- @bin_file_names << dest_file
- ensure
- rm bin_tmp_file
- end
-
- next unless Gem.win_platform?
-
- begin
- bin_cmd_file = File.join Dir.tmpdir, "#{bin_file}.bat"
-
- File.open bin_cmd_file, 'w' do |file|
- file.puts <<-TEXT
-@ECHO OFF
-IF NOT "%~f0" == "~f0" GOTO :WinNT
-@"#{File.basename(Gem.ruby).chomp('"')}" "#{dest_file}" %1 %2 %3 %4 %5 %6 %7 %8 %9
-GOTO :EOF
-:WinNT
-@"#{File.basename(Gem.ruby).chomp('"')}" "%~dpn0" %*
-TEXT
- end
-
- install bin_cmd_file, "#{dest_file}.bat", :mode => 0755
- ensure
- rm bin_cmd_file
- end
- end
- end
- end
-
- def install_file file, dest_dir
- dest_file = File.join dest_dir, file
- dest_dir = File.dirname dest_file
- mkdir_p dest_dir unless File.directory? dest_dir
-
- install file, dest_file, :mode => 0644
- end
-
- def install_lib(lib_dir)
- say "Installing RubyGems" if @verbose
-
- lib_files = rb_files_in 'lib'
- pem_files = pem_files_in 'lib'
-
- Dir.chdir 'lib' do
- lib_files.each do |lib_file|
- install_file lib_file, lib_dir
- end
-
- pem_files.each do |pem_file|
- install_file pem_file, lib_dir
- end
- end
- end
-
- def install_rdoc
- gem_doc_dir = File.join Gem.dir, 'doc'
- rubygems_name = "rubygems-#{Gem::VERSION}"
- rubygems_doc_dir = File.join gem_doc_dir, rubygems_name
-
- begin
- Gem.ensure_gem_subdirectories Gem.dir
- rescue SystemCallError
- # ignore
- end
-
- if File.writable? gem_doc_dir and
- (not File.exist? rubygems_doc_dir or
- File.writable? rubygems_doc_dir) then
- say "Removing old RubyGems RDoc and ri" if @verbose
- Dir[File.join(Gem.dir, 'doc', 'rubygems-[0-9]*')].each do |dir|
- rm_rf dir
- end
-
- require 'rubygems/rdoc'
-
- fake_spec = Gem::Specification.new 'rubygems', Gem::VERSION
- def fake_spec.full_gem_path
- File.expand_path '../../../..', __FILE__
- end
-
- generate_ri = options[:document].include? 'ri'
- generate_rdoc = options[:document].include? 'rdoc'
-
- rdoc = Gem::RDoc.new fake_spec, generate_rdoc, generate_ri
- rdoc.generate
-
- return true
- elsif @verbose then
- say "Skipping RDoc generation, #{gem_doc_dir} not writable"
- say "Set the GEM_HOME environment variable if you want RDoc generated"
- end
-
- return false
- end
-
- def make_destination_dirs(install_destdir)
- lib_dir, bin_dir = Gem.default_rubygems_dirs
-
- unless lib_dir
- lib_dir, bin_dir = generate_default_dirs(install_destdir)
- end
-
- mkdir_p lib_dir
- mkdir_p bin_dir
-
- return lib_dir, bin_dir
- end
-
- def generate_default_dirs(install_destdir)
- prefix = options[:prefix]
- site_or_vendor = options[:site_or_vendor]
-
- if prefix.empty? then
- lib_dir = RbConfig::CONFIG[site_or_vendor]
- bin_dir = RbConfig::CONFIG['bindir']
- else
- # Apple installed RubyGems into libdir, and RubyGems <= 1.1.0 gets
- # confused about installation location, so switch back to
- # sitelibdir/vendorlibdir.
- if defined?(APPLE_GEM_HOME) and
- # just in case Apple and RubyGems don't get this patched up proper.
- (prefix == RbConfig::CONFIG['libdir'] or
- # this one is important
- prefix == File.join(RbConfig::CONFIG['libdir'], 'ruby')) then
- lib_dir = RbConfig::CONFIG[site_or_vendor]
- bin_dir = RbConfig::CONFIG['bindir']
- else
- lib_dir = File.join prefix, 'lib'
- bin_dir = File.join prefix, 'bin'
- end
- end
-
- unless install_destdir.empty? then
- lib_dir = File.join install_destdir, lib_dir.gsub(/^[a-zA-Z]:/, '')
- bin_dir = File.join install_destdir, bin_dir.gsub(/^[a-zA-Z]:/, '')
- end
-
- [lib_dir, bin_dir]
- end
-
- def pem_files_in dir
- Dir.chdir dir do
- Dir[File.join('**', '*pem')]
- end
- end
-
- def rb_files_in dir
- Dir.chdir dir do
- Dir[File.join('**', '*rb')]
- end
- end
-
- def remove_old_bin_files(bin_dir)
- old_bin_files = {
- 'gem_mirror' => 'gem mirror',
- 'gem_server' => 'gem server',
- 'gemlock' => 'gem lock',
- 'gemri' => 'ri',
- 'gemwhich' => 'gem which',
- 'index_gem_repository.rb' => 'gem generate_index',
- }
-
- old_bin_files.each do |old_bin_file, new_name|
- old_bin_path = File.join bin_dir, old_bin_file
- next unless File.exist? old_bin_path
-
- deprecation_message = "`#{old_bin_file}` has been deprecated. Use `#{new_name}` instead."
-
- File.open old_bin_path, 'w' do |fp|
- fp.write <<-EOF
-#!#{Gem.ruby}
-
-abort "#{deprecation_message}"
- EOF
- end
-
- next unless Gem.win_platform?
-
- File.open "#{old_bin_path}.bat", 'w' do |fp|
- fp.puts %{@ECHO.#{deprecation_message}}
- end
- end
- end
-
- def remove_old_lib_files lib_dir
- rubygems_dir = File.join lib_dir, 'rubygems'
- lib_files = rb_files_in 'lib/rubygems'
-
- old_lib_files = rb_files_in rubygems_dir
-
- to_remove = old_lib_files - lib_files
-
- to_remove.delete_if do |file|
- file.start_with? 'defaults'
- end
-
- Dir.chdir rubygems_dir do
- to_remove.each do |file|
- FileUtils.rm_f file
-
- warn "unable to remove old file #{file} please remove it by hand" if
- File.exist? file
- end
- end
- end
-
- def show_release_notes
- release_notes = File.join Dir.pwd, 'History.txt'
-
- release_notes =
- if File.exist? release_notes then
- history = File.read release_notes
-
- history.force_encoding Encoding::UTF_8 if
- Object.const_defined? :Encoding
-
- history = history.sub(/^# coding:.*?(?=^=)/m, '')
-
- text = history.split(HISTORY_HEADER)
- text.shift # correct an off-by-one generated by split
- version_lines = history.scan(HISTORY_HEADER)
- versions = history.scan(VERSION_MATCHER).flatten.map do |x|
- Gem::Version.new(x)
- end
-
- history_string = ""
-
- until versions.length == 0 or
- versions.shift < options[:previous_version] do
- history_string += version_lines.shift + text.shift
- end
-
- history_string
- else
- "Oh-no! Unable to find release notes!"
- end
-
- say release_notes
- end
-
- def uninstall_old_gemcutter
- require 'rubygems/uninstaller'
-
- ui = Gem::Uninstaller.new('gemcutter', :all => true, :ignore => true,
- :version => '< 0.4')
- ui.uninstall
- rescue Gem::InstallError
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/sources_command.rb b/ruby_2_2/lib/rubygems/commands/sources_command.rb
deleted file mode 100644
index 81ff07babc..0000000000
--- a/ruby_2_2/lib/rubygems/commands/sources_command.rb
+++ /dev/null
@@ -1,210 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/remote_fetcher'
-require 'rubygems/spec_fetcher'
-require 'rubygems/local_remote_options'
-
-class Gem::Commands::SourcesCommand < Gem::Command
-
- include Gem::LocalRemoteOptions
-
- def initialize
- require 'fileutils'
-
- super 'sources',
- 'Manage the sources and cache file RubyGems uses to search for gems'
-
- add_option '-a', '--add SOURCE_URI', 'Add source' do |value, options|
- options[:add] = value
- end
-
- add_option '-l', '--list', 'List sources' do |value, options|
- options[:list] = value
- end
-
- add_option '-r', '--remove SOURCE_URI', 'Remove source' do |value, options|
- options[:remove] = value
- end
-
- add_option '-c', '--clear-all',
- 'Remove all sources (clear the cache)' do |value, options|
- options[:clear_all] = value
- end
-
- add_option '-u', '--update', 'Update source cache' do |value, options|
- options[:update] = value
- end
-
- add_proxy_option
- end
-
- def add_source source_uri # :nodoc:
- check_rubygems_https source_uri
-
- source = Gem::Source.new source_uri
-
- begin
- if Gem.sources.include? source_uri then
- say "source #{source_uri} already present in the cache"
- else
- source.load_specs :released
- Gem.sources << source
- Gem.configuration.write
-
- say "#{source_uri} added to sources"
- end
- rescue URI::Error, ArgumentError
- say "#{source_uri} is not a URI"
- terminate_interaction 1
- rescue Gem::RemoteFetcher::FetchError => e
- say "Error fetching #{source_uri}:\n\t#{e.message}"
- terminate_interaction 1
- end
- end
-
- def check_rubygems_https source_uri # :nodoc:
- uri = URI source_uri
-
- if uri.scheme and uri.scheme.downcase == 'http' and
- uri.host.downcase == 'rubygems.org' then
- question = <<-QUESTION.chomp
-https://rubygems.org is recommended for security over #{uri}
-
-Do you want to add this insecure source?
- QUESTION
-
- terminate_interaction 1 unless ask_yes_no question
- end
- end
-
- def clear_all # :nodoc:
- path = Gem.spec_cache_dir
- FileUtils.rm_rf path
-
- unless File.exist? path then
- say "*** Removed specs cache ***"
- else
- unless File.writable? path then
- say "*** Unable to remove source cache (write protected) ***"
- else
- say "*** Unable to remove source cache ***"
- end
-
- terminate_interaction 1
- end
- end
-
- def defaults_str # :nodoc:
- '--list'
- end
-
- def description # :nodoc:
- <<-EOF
-RubyGems fetches gems from the sources you have configured (stored in your
-~/.gemrc).
-
-The default source is https://rubygems.org, but you may have older sources
-configured. This guide will help you update your sources or configure
-yourself to use your own gem server.
-
-Without any arguments the sources lists your currently configured sources:
-
- $ gem sources
- *** CURRENT SOURCES ***
-
- https://rubygems.org
-
-This may list multiple sources or non-rubygems sources. You probably
-configured them before or have an old `~/.gemrc`. If you have sources you
-do not recognize you should remove them.
-
-RubyGems has been configured to serve gems via the following URLs through
-its history:
-
-* http://gems.rubyforge.org (RubyGems 1.3.6 and earlier)
-* http://rubygems.org (RubyGems 1.3.7 through 1.8.25)
-* https://rubygems.org (RubyGems 2.0.1 and newer)
-
-Since all of these sources point to the same set of gems you only need one
-of them in your list. https://rubygems.org is recommended as it brings the
-protections of an SSL connection to gem downloads.
-
-To add a source use the --add argument:
-
- $ gem sources --add https://rubygems.org
- https://rubygems.org added to sources
-
-RubyGems will check to see if gems can be installed from the source given
-before it is added.
-
-To remove a source use the --remove argument:
-
- $ gem sources --remove http://rubygems.org
- http://rubygems.org removed from sources
-
- EOF
- end
-
- def list # :nodoc:
- say "*** CURRENT SOURCES ***"
- say
-
- Gem.sources.each do |src|
- say src
- end
- end
-
- def list? # :nodoc:
- !(options[:add] ||
- options[:clear_all] ||
- options[:remove] ||
- options[:update])
- end
-
- def execute
- clear_all if options[:clear_all]
-
- source_uri = options[:add]
- add_source source_uri if source_uri
-
- source_uri = options[:remove]
- remove_source source_uri if source_uri
-
- update if options[:update]
-
- list if list?
- end
-
- def remove_source source_uri # :nodoc:
- unless Gem.sources.include? source_uri then
- say "source #{source_uri} not present in cache"
- else
- Gem.sources.delete source_uri
- Gem.configuration.write
-
- say "#{source_uri} removed from sources"
- end
- end
-
- def update # :nodoc:
- Gem.sources.each_source do |src|
- src.load_specs :released
- src.load_specs :latest
- end
-
- say "source cache successfully updated"
- end
-
- def remove_cache_file desc, path # :nodoc:
- FileUtils.rm_rf path
-
- if not File.exist?(path) then
- say "*** Removed #{desc} source cache ***"
- elsif not File.writable?(path) then
- say "*** Unable to remove #{desc} source cache (write protected) ***"
- else
- say "*** Unable to remove #{desc} source cache ***"
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/specification_command.rb b/ruby_2_2/lib/rubygems/commands/specification_command.rb
deleted file mode 100644
index 3bc02a9c14..0000000000
--- a/ruby_2_2/lib/rubygems/commands/specification_command.rb
+++ /dev/null
@@ -1,145 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/local_remote_options'
-require 'rubygems/version_option'
-require 'rubygems/package'
-
-class Gem::Commands::SpecificationCommand < Gem::Command
-
- include Gem::LocalRemoteOptions
- include Gem::VersionOption
-
- def initialize
- Gem.load_yaml
-
- super 'specification', 'Display gem specification (in yaml)',
- :domain => :local, :version => Gem::Requirement.default,
- :format => :yaml
-
- add_version_option('examine')
- add_platform_option
- add_prerelease_option
-
- add_option('--all', 'Output specifications for all versions of',
- 'the gem') do |value, options|
- options[:all] = true
- end
-
- add_option('--ruby', 'Output ruby format') do |value, options|
- options[:format] = :ruby
- end
-
- add_option('--yaml', 'Output YAML format') do |value, options|
- options[:format] = :yaml
- end
-
- add_option('--marshal', 'Output Marshal format') do |value, options|
- options[:format] = :marshal
- end
-
- add_local_remote_options
- end
-
- def arguments # :nodoc:
- <<-ARGS
-GEMFILE name of gem to show the gemspec for
-FIELD name of gemspec field to show
- ARGS
- end
-
- def defaults_str # :nodoc:
- "--local --version '#{Gem::Requirement.default}' --yaml"
- end
-
- def description # :nodoc:
- <<-EOF
-The specification command allows you to extract the specification from
-a gem for examination.
-
-The specification can be output in YAML, ruby or Marshal formats.
-
-Specific fields in the specification can be extracted in YAML format:
-
- $ gem spec rake summary
- --- Ruby based make-like utility.
- ...
-
- EOF
- end
-
- def usage # :nodoc:
- "#{program_name} [GEMFILE] [FIELD]"
- end
-
- def execute
- specs = []
- gem = options[:args].shift
-
- unless gem then
- raise Gem::CommandLineError,
- "Please specify a gem name or file on the command line"
- end
-
- case v = options[:version]
- when String
- req = Gem::Requirement.create v
- when Gem::Requirement
- req = v
- else
- raise Gem::CommandLineError, "Unsupported version type: '#{v}'"
- end
-
- if !req.none? and options[:all]
- alert_error "Specify --all or -v, not both"
- terminate_interaction 1
- end
-
- if options[:all]
- dep = Gem::Dependency.new gem
- else
- dep = Gem::Dependency.new gem, req
- end
-
- field = get_one_optional_argument
-
- raise Gem::CommandLineError, "--ruby and FIELD are mutually exclusive" if
- field and options[:format] == :ruby
-
- if local? then
- if File.exist? gem then
- specs << Gem::Package.new(gem).spec rescue nil
- end
-
- if specs.empty? then
- specs.push(*dep.matching_specs)
- end
- end
-
- if remote? then
- dep.prerelease = options[:prerelease]
- found, _ = Gem::SpecFetcher.fetcher.spec_for_dependency dep
-
- specs.push(*found.map { |spec,| spec })
- end
-
- if specs.empty? then
- alert_error "No gem matching '#{dep}' found"
- terminate_interaction 1
- end
-
- unless options[:all] then
- specs = [specs.max_by { |s| s.version }]
- end
-
- specs.each do |s|
- s = s.send field if field
-
- say case options[:format]
- when :ruby then s.to_ruby
- when :marshal then Marshal.dump s
- else s.to_yaml
- end
-
- say "\n"
- end
- end
-end
diff --git a/ruby_2_2/lib/rubygems/commands/stale_command.rb b/ruby_2_2/lib/rubygems/commands/stale_command.rb
deleted file mode 100644
index 0ef0755960..0000000000
--- a/ruby_2_2/lib/rubygems/commands/stale_command.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-require 'rubygems/command'
-
-class Gem::Commands::StaleCommand < Gem::Command
- def initialize
- super('stale', 'List gems along with access times')
- end
-
- def description # :nodoc:
- <<-EOF
-The stale command lists the latest access time for all the files in your
-installed gems.
-
-You can use this command to discover gems and gem versions you are no
-longer using.
- EOF
- end
-
- def usage # :nodoc:
- "#{program_name}"
- end
-
- def execute
- gem_to_atime = {}
- Gem::Specification.each do |spec|
- name = spec.full_name
- Dir["#{spec.full_gem_path}/**/*.*"].each do |file|
- next if File.directory?(file)
- stat = File.stat(file)
- gem_to_atime[name] ||= stat.atime
- gem_to_atime[name] = stat.atime if gem_to_atime[name] < stat.atime
- end
- end
-
- gem_to_atime.sort_by { |_, atime| atime }.each do |name, atime|
- say "#{name} at #{atime.strftime '%c'}"
- end
- end
-end
diff --git a/ruby_2_2/lib/rubygems/commands/uninstall_command.rb b/ruby_2_2/lib/rubygems/commands/uninstall_command.rb
deleted file mode 100644
index 9285e57b77..0000000000
--- a/ruby_2_2/lib/rubygems/commands/uninstall_command.rb
+++ /dev/null
@@ -1,164 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/version_option'
-require 'rubygems/uninstaller'
-require 'fileutils'
-
-##
-# Gem uninstaller command line tool
-#
-# See `gem help uninstall`
-
-class Gem::Commands::UninstallCommand < Gem::Command
-
- include Gem::VersionOption
-
- def initialize
- super 'uninstall', 'Uninstall gems from the local repository',
- :version => Gem::Requirement.default, :user_install => true,
- :check_dev => false, :vendor => false
-
- add_option('-a', '--[no-]all',
- 'Uninstall all matching versions'
- ) do |value, options|
- options[:all] = value
- end
-
- add_option('-I', '--[no-]ignore-dependencies',
- 'Ignore dependency requirements while',
- 'uninstalling') do |value, options|
- options[:ignore] = value
- end
-
- add_option('-D', '--[no-]-check-development',
- 'Check development dependencies while uninstalling',
- '(default: false)') do |value, options|
- options[:check_dev] = value
- end
-
- add_option('-x', '--[no-]executables',
- 'Uninstall applicable executables without',
- 'confirmation') do |value, options|
- options[:executables] = value
- end
-
- add_option('-i', '--install-dir DIR',
- 'Directory to uninstall gem from') do |value, options|
- options[:install_dir] = File.expand_path(value)
- end
-
- add_option('-n', '--bindir DIR',
- 'Directory to remove binaries from') do |value, options|
- options[:bin_dir] = File.expand_path(value)
- end
-
- add_option('--[no-]user-install',
- 'Uninstall from user\'s home directory',
- 'in addition to GEM_HOME.') do |value, options|
- options[:user_install] = value
- end
-
- add_option('--[no-]format-executable',
- 'Assume executable names match Ruby\'s prefix and suffix.') do |value, options|
- options[:format_executable] = value
- end
-
- add_option('--[no-]force',
- 'Uninstall all versions of the named gems',
- 'ignoring dependencies') do |value, options|
- options[:force] = value
- end
-
- add_option('--[no-]abort-on-dependent',
- 'Prevent uninstalling gems that are',
- 'depended on by other gems.') do |value, options|
- options[:abort_on_dependent] = value
- end
-
- add_version_option
- add_platform_option
-
- add_option('--vendor',
- 'Uninstall gem from the vendor directory.',
- 'Only for use by gem repackagers.') do |value, options|
- unless Gem.vendor_dir then
- raise OptionParser::InvalidOption.new 'your platform is not supported'
- end
-
- alert_warning 'Use your OS package manager to uninstall vendor gems'
- options[:vendor] = true
- options[:install_dir] = Gem.vendor_dir
- end
- end
-
- def arguments # :nodoc:
- "GEMNAME name of gem to uninstall"
- end
-
- def defaults_str # :nodoc:
- "--version '#{Gem::Requirement.default}' --no-force " +
- "--user-install"
- end
-
- def description # :nodoc:
- <<-EOF
-The uninstall command removes a previously installed gem.
-
-RubyGems will ask for confirmation if you are attempting to uninstall a gem
-that is a dependency of an existing gem. You can use the
---ignore-dependencies option to skip this check.
- EOF
- end
-
- def usage # :nodoc:
- "#{program_name} GEMNAME [GEMNAME ...]"
- end
-
- def execute
- if options[:all] and not options[:args].empty? then
- uninstall_specific
- elsif options[:all] then
- uninstall_all
- else
- uninstall_specific
- end
- end
-
- def uninstall_all
- specs = Gem::Specification.reject { |spec| spec.default_gem? }
-
- specs.each do |spec|
- options[:version] = spec.version
-
- begin
- Gem::Uninstaller.new(spec.name, options).uninstall
- rescue Gem::InstallError
- end
- end
-
- alert "Uninstalled all gems in #{options[:install_dir]}"
- end
-
- def uninstall_specific
- deplist = Gem::DependencyList.new
-
- get_all_gem_names.uniq.each do |name|
- Gem::Specification.find_all_by_name(name).each do |spec|
- deplist.add spec
- end
- end
-
- deps = deplist.strongly_connected_components.flatten.reverse
-
- deps.map(&:name).uniq.each do |gem_name|
- begin
- Gem::Uninstaller.new(gem_name, options).uninstall
- rescue Gem::GemNotInHomeException => e
- spec = e.spec
- alert("In order to remove #{spec.name}, please execute:\n" +
- "\tgem uninstall #{spec.name} --install-dir=#{spec.installation_path}")
- end
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/unpack_command.rb b/ruby_2_2/lib/rubygems/commands/unpack_command.rb
deleted file mode 100644
index 5a05ad0a81..0000000000
--- a/ruby_2_2/lib/rubygems/commands/unpack_command.rb
+++ /dev/null
@@ -1,182 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/installer'
-require 'rubygems/version_option'
-require 'rubygems/remote_fetcher'
-
-class Gem::Commands::UnpackCommand < Gem::Command
-
- include Gem::VersionOption
-
- def initialize
- require 'fileutils'
-
- super 'unpack', 'Unpack an installed gem to the current directory',
- :version => Gem::Requirement.default,
- :target => Dir.pwd
-
- add_option('--target=DIR',
- 'target directory for unpacking') do |value, options|
- options[:target] = value
- end
-
- add_option('--spec', 'unpack the gem specification') do |value, options|
- options[:spec] = true
- end
-
- add_version_option
- end
-
- def arguments # :nodoc:
- "GEMNAME name of gem to unpack"
- end
-
- def defaults_str # :nodoc:
- "--version '#{Gem::Requirement.default}'"
- end
-
- def description
- <<-EOF
-The unpack command allows you to examine the contents of a gem or modify
-them to help diagnose a bug.
-
-You can add the contents of the unpacked gem to the load path using the
-RUBYLIB environment variable or -I:
-
- $ gem unpack my_gem
- Unpacked gem: '.../my_gem-1.0'
- [edit my_gem-1.0/lib/my_gem.rb]
- $ ruby -Imy_gem-1.0/lib -S other_program
-
-You can repackage an unpacked gem using the build command. See the build
-command help for an example.
- EOF
- end
-
- def usage # :nodoc:
- "#{program_name} GEMNAME"
- end
-
- #--
- # TODO: allow, e.g., 'gem unpack rake-0.3.1'. Find a general solution for
- # this, so that it works for uninstall as well. (And check other commands
- # at the same time.)
-
- def execute
- get_all_gem_names.each do |name|
- dependency = Gem::Dependency.new name, options[:version]
- path = get_path dependency
-
- unless path then
- alert_error "Gem '#{name}' not installed nor fetchable."
- next
- end
-
- if @options[:spec] then
- spec, metadata = get_metadata path
-
- if metadata.nil? then
- alert_error "--spec is unsupported on '#{name}' (old format gem)"
- next
- end
-
- spec_file = File.basename spec.spec_file
-
- open spec_file, 'w' do |io|
- io.write metadata
- end
- else
- basename = File.basename path, '.gem'
- target_dir = File.expand_path basename, options[:target]
-
- package = Gem::Package.new path
- package.extract_files target_dir
-
- say "Unpacked gem: '#{target_dir}'"
- end
- end
- end
-
- ##
- #
- # Find cached filename in Gem.path. Returns nil if the file cannot be found.
- #
- #--
- # TODO: see comments in get_path() about general service.
-
- def find_in_cache(filename)
- Gem.path.each do |path|
- this_path = File.join(path, "cache", filename)
- return this_path if File.exist? this_path
- end
-
- return nil
- end
-
- ##
- # Return the full path to the cached gem file matching the given
- # name and version requirement. Returns 'nil' if no match.
- #
- # Example:
- #
- # get_path 'rake', '> 0.4' # "/usr/lib/ruby/gems/1.8/cache/rake-0.4.2.gem"
- # get_path 'rake', '< 0.1' # nil
- # get_path 'rak' # nil (exact name required)
- #--
- # TODO: This should be refactored so that it's a general service. I don't
- # think any of our existing classes are the right place though. Just maybe
- # 'Cache'?
- #
- # TODO: It just uses Gem.dir for now. What's an easy way to get the list of
- # source directories?
-
- def get_path dependency
- return dependency.name if dependency.name =~ /\.gem$/i
-
- specs = dependency.matching_specs
-
- selected = specs.max_by { |s| s.version }
-
- return Gem::RemoteFetcher.fetcher.download_to_cache(dependency) unless
- selected
-
- return unless dependency.name =~ /^#{selected.name}$/i
-
- # We expect to find (basename).gem in the 'cache' directory. Furthermore,
- # the name match must be exact (ignoring case).
-
- path = find_in_cache File.basename selected.cache_file
-
- return Gem::RemoteFetcher.fetcher.download_to_cache(dependency) unless path
-
- path
- end
-
- ##
- # Extracts the Gem::Specification and raw metadata from the .gem file at
- # +path+.
- #--
- # TODO move to Gem::Package as #raw_spec or something
-
- def get_metadata path
- format = Gem::Package.new path
- spec = format.spec
-
- metadata = nil
-
- open path, Gem.binary_mode do |io|
- tar = Gem::Package::TarReader.new io
- tar.each_entry do |entry|
- case entry.full_name
- when 'metadata' then
- metadata = entry.read
- when 'metadata.gz' then
- metadata = Gem.gunzip entry.read
- end
- end
- end
-
- return spec, metadata
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/update_command.rb b/ruby_2_2/lib/rubygems/commands/update_command.rb
deleted file mode 100644
index 001dd777cc..0000000000
--- a/ruby_2_2/lib/rubygems/commands/update_command.rb
+++ /dev/null
@@ -1,277 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/command_manager'
-require 'rubygems/dependency_installer'
-require 'rubygems/install_update_options'
-require 'rubygems/local_remote_options'
-require 'rubygems/spec_fetcher'
-require 'rubygems/version_option'
-require 'rubygems/install_message' # must come before rdoc for messaging
-require 'rubygems/rdoc'
-
-class Gem::Commands::UpdateCommand < Gem::Command
-
- include Gem::InstallUpdateOptions
- include Gem::LocalRemoteOptions
- include Gem::VersionOption
-
- attr_reader :installer # :nodoc:
-
- attr_reader :updated # :nodoc:
-
- def initialize
- super 'update', 'Update installed gems to the latest version',
- :document => %w[rdoc ri],
- :force => false
-
- add_install_update_options
-
- OptionParser.accept Gem::Version do |value|
- Gem::Version.new value
-
- value
- end
-
- add_option('--system [VERSION]', Gem::Version,
- 'Update the RubyGems system software') do |value, options|
- value = true unless value
-
- options[:system] = value
- end
-
- add_local_remote_options
- add_platform_option
- add_prerelease_option "as update targets"
-
- @updated = []
- @installer = nil
- end
-
- def arguments # :nodoc:
- "REGEXP regexp to search for in gem name"
- end
-
- def defaults_str # :nodoc:
- "--document --no-force --install-dir #{Gem.dir}"
- end
-
- def description # :nodoc:
- <<-EOF
-The update command will update your gems to the latest version.
-
-The update command does not remove the previous version. Use the cleanup
-command to remove old versions.
- EOF
- end
-
- def usage # :nodoc:
- "#{program_name} REGEXP [REGEXP ...]"
- end
-
- def check_latest_rubygems version # :nodoc:
- if Gem.rubygems_version == version then
- say "Latest version currently installed. Aborting."
- terminate_interaction
- end
-
- options[:user_install] = false
- end
-
- def check_update_arguments # :nodoc:
- unless options[:args].empty? then
- alert_error "Gem names are not allowed with the --system option"
- terminate_interaction 1
- end
- end
-
- def execute
- if options[:system] then
- update_rubygems
- return
- end
-
- say "Updating installed gems"
-
- hig = highest_installed_gems
-
- gems_to_update = which_to_update hig, options[:args].uniq
-
- updated = update_gems gems_to_update
-
- updated_names = updated.map { |spec| spec.name }
- not_updated_names = options[:args].uniq - updated_names
-
- if updated.empty? then
- say "Nothing to update"
- else
- say "Gems updated: #{updated_names.join(' ')}"
- say "Gems already up-to-date: #{not_updated_names.join(' ')}" unless not_updated_names.empty?
- end
- end
-
- def fetch_remote_gems spec # :nodoc:
- dependency = Gem::Dependency.new spec.name, "> #{spec.version}"
- dependency.prerelease = options[:prerelease]
-
- fetcher = Gem::SpecFetcher.fetcher
-
- spec_tuples, errors = fetcher.search_for_dependency dependency
-
- error = errors.find { |e| e.respond_to? :exception }
-
- raise error if error
-
- spec_tuples
- end
-
- def highest_installed_gems # :nodoc:
- hig = {} # highest installed gems
-
- Gem::Specification.each do |spec|
- if hig[spec.name].nil? or hig[spec.name].version < spec.version then
- hig[spec.name] = spec
- end
- end
-
- hig
- end
-
- def highest_remote_version spec # :nodoc:
- spec_tuples = fetch_remote_gems spec
-
- matching_gems = spec_tuples.select do |g,_|
- g.name == spec.name and g.match_platform?
- end
-
- highest_remote_gem = matching_gems.max_by { |g,_| g.version }
-
- highest_remote_gem ||= [Gem::NameTuple.null]
-
- highest_remote_gem.first.version
- end
-
- def install_rubygems version # :nodoc:
- args = update_rubygems_arguments
-
- update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}"
-
- Dir.chdir update_dir do
- say "Installing RubyGems #{version}"
-
- # Make sure old rubygems isn't loaded
- old = ENV["RUBYOPT"]
- ENV.delete("RUBYOPT") if old
- installed = system Gem.ruby, 'setup.rb', *args
- say "RubyGems system software updated" if installed
- ENV["RUBYOPT"] = old if old
- end
- end
-
- def rubygems_target_version
- version = options[:system]
- update_latest = version == true
-
- if update_latest then
- version = Gem::Version.new Gem::VERSION
- requirement = Gem::Requirement.new ">= #{Gem::VERSION}"
- else
- version = Gem::Version.new version
- requirement = Gem::Requirement.new version
- end
-
- rubygems_update = Gem::Specification.new
- rubygems_update.name = 'rubygems-update'
- rubygems_update.version = version
-
- hig = {
- 'rubygems-update' => rubygems_update
- }
-
- gems_to_update = which_to_update hig, options[:args], :system
- _, up_ver = gems_to_update.first
-
- target = if update_latest then
- up_ver
- else
- version
- end
-
- return target, requirement
- end
-
- def update_gem name, version = Gem::Requirement.default
- return if @updated.any? { |spec| spec.name == name }
-
- update_options = options.dup
- update_options[:prerelease] = version.prerelease?
-
- @installer = Gem::DependencyInstaller.new update_options
-
- say "Updating #{name}"
- begin
- @installer.install name, Gem::Requirement.new(version)
- rescue Gem::InstallError, Gem::DependencyError => e
- alert_error "Error installing #{name}:\n\t#{e.message}"
- end
-
- @installer.installed_gems.each do |spec|
- @updated << spec
- end
- end
-
- def update_gems gems_to_update
- gems_to_update.uniq.sort.each do |(name, version)|
- update_gem name, version
- end
-
- @updated
- end
-
- ##
- # Update RubyGems software to the latest version.
-
- def update_rubygems
- check_update_arguments
-
- version, requirement = rubygems_target_version
-
- check_latest_rubygems version
-
- update_gem 'rubygems-update', version
-
- installed_gems = Gem::Specification.find_all_by_name 'rubygems-update', requirement
- version = installed_gems.last.version
-
- install_rubygems version
- end
-
- def update_rubygems_arguments # :nodoc:
- args = []
- args << '--prefix' << Gem.prefix if Gem.prefix
- # TODO use --document for >= 1.9 , --no-rdoc --no-ri < 1.9
- args << '--no-rdoc' unless options[:document].include? 'rdoc'
- args << '--no-ri' unless options[:document].include? 'ri'
- args << '--no-format-executable' if options[:no_format_executable]
- args << '--previous-version' << Gem::VERSION if
- options[:system] == true or
- Gem::Version.new(options[:system]) >= Gem::Version.new(2)
- args
- end
-
- def which_to_update highest_installed_gems, gem_names, system = false
- result = []
-
- highest_installed_gems.each do |l_name, l_spec|
- next if not gem_names.empty? and
- gem_names.none? { |name| name == l_spec.name }
-
- highest_remote_ver = highest_remote_version l_spec
-
- if system or (l_spec.version < highest_remote_ver) then
- result << [l_spec.name, [l_spec.version, highest_remote_ver].max]
- end
- end
-
- result
- end
-
-end
diff --git a/ruby_2_2/lib/rubygems/commands/which_command.rb b/ruby_2_2/lib/rubygems/commands/which_command.rb
deleted file mode 100644
index 96eeb86288..0000000000
--- a/ruby_2_2/lib/rubygems/commands/which_command.rb
+++ /dev/null
@@ -1,90 +0,0 @@
-require 'rubygems/command'
-
-class Gem::Commands::WhichCommand < Gem::Command
- def initialize
- super 'which', 'Find the location of a library file you can require',
- :search_gems_first => false, :show_all => false
-
- add_option '-a', '--[no-]all', 'show all matching files' do |show_all, options|
- options[:show_all] = show_all
- end
-
- add_option '-g', '--[no-]gems-first',
- 'search gems before non-gems' do |gems_first, options|
- options[:search_gems_first] = gems_first
- end
- end
-
- def arguments # :nodoc:
- "FILE name of file to find"
- end
-
- def defaults_str # :nodoc:
- "--no-gems-first --no-all"
- end
-
- def description # :nodoc:
- <<-EOF
-The which command is like the shell which command and shows you where
-the file you wish to require lives.
-
-You can use the which command to help determine why you are requiring a
-version you did not expect or to look at the content of a file you are
-requiring to see why it does not behave as you expect.
- EOF
- end
-
- def execute
- found = true
-
- options[:args].each do |arg|
- arg = arg.sub(/#{Regexp.union(*Gem.suffixes)}$/, '')
- dirs = $LOAD_PATH
-
- spec = Gem::Specification.find_by_path arg
-
- if spec then
- if options[:search_gems_first] then
- dirs = spec.full_require_paths + $LOAD_PATH
- else
- dirs = $LOAD_PATH + spec.full_require_paths
- end
- end
-
- # TODO: this is totally redundant and stupid
- paths = find_paths arg, dirs
-
- if paths.empty? then
- alert_error "Can't find ruby library file or shared library #{arg}"
-
- found &&= false
- else
- say paths
- end
- end
-
- terminate_interaction 1 unless found
- end
-
- def find_paths(package_name, dirs)
- result = []
-
- dirs.each do |dir|
- Gem.suffixes.each do |ext|
- full_path = File.join dir, "#{package_name}#{ext}"
- if File.exist? full_path and not File.directory? full_path then
- result << full_path
- return result unless options[:show_all]
- end
- end
- end
-
- result
- end
-
- def usage # :nodoc:
- "#{program_name} FILE [FILE ...]"
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/commands/yank_command.rb b/ruby_2_2/lib/rubygems/commands/yank_command.rb
deleted file mode 100644
index 3c7859e763..0000000000
--- a/ruby_2_2/lib/rubygems/commands/yank_command.rb
+++ /dev/null
@@ -1,107 +0,0 @@
-require 'rubygems/command'
-require 'rubygems/local_remote_options'
-require 'rubygems/version_option'
-require 'rubygems/gemcutter_utilities'
-
-class Gem::Commands::YankCommand < Gem::Command
- include Gem::LocalRemoteOptions
- include Gem::VersionOption
- include Gem::GemcutterUtilities
-
- def description # :nodoc:
- <<-EOF
-The yank command removes a gem you pushed to a server from the server's
-index.
-
-Note that if you push a gem to rubygems.org the yank command does not
-prevent other people from downloading the gem via the download link.
-
-Once you have pushed a gem several downloads will happen automatically
-via the webhooks. If you accidentally pushed passwords or other sensitive
-data you will need to change them immediately and yank your gem.
-
-If you are yanking a gem due to intellectual property reasons contact
-http://help.rubygems.org for permanant removal. Be sure to mention this
-as the reason for the removal request.
- EOF
- end
-
- def arguments # :nodoc:
- "GEM name of gem"
- end
-
- def usage # :nodoc:
- "#{program_name} GEM -v VERSION [-p PLATFORM] [--undo] [--key KEY_NAME]"
- end
-
- def initialize
- super 'yank', 'Remove a pushed gem from the index'
-
- add_version_option("remove")
- add_platform_option("remove")
-
- add_option('--undo') do |value, options|
- options[:undo] = true
- end
-
- add_key_option
- end
-
- def execute
- sign_in
-
- version = get_version_from_requirements(options[:version])
- platform = get_platform_from_requirements(options)
-
- if version then
- if options[:undo] then
- unyank_gem(version, platform)
- else
- yank_gem(version, platform)
- end
- else
- say "A version argument is required: #{usage}"
- terminate_interaction
- end
- end
-
- def yank_gem(version, platform)
- say "Yanking gem from #{self.host}..."
- yank_api_request(:delete, version, platform, "api/v1/gems/yank")
- end
-
- def unyank_gem(version, platform)
- say "Unyanking gem from #{host}..."
- yank_api_request(:put, version, platform, "api/v1/gems/unyank")
- end
-
- private
-
- def yank_api_request(method, version, platform, api)
- name = get_one_gem_name
- response = rubygems_api_request(method, api) do |request|
- request.add_field("Authorization", api_key)
-
- data = {
- 'gem_name' => name,
- 'version' => version,
- }
- data['platform'] = platform if platform
-
- request.set_form_data data
- end
- say response.body
- end
-
- def get_version_from_requirements(requirements)
- requirements.requirements.first[1].version
- rescue
- nil
- end
-
- def get_platform_from_requirements(requirements)
- Gem.platforms[1].to_s if requirements.key? :added_platform
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/compatibility.rb b/ruby_2_2/lib/rubygems/compatibility.rb
deleted file mode 100644
index 6a00a199f9..0000000000
--- a/ruby_2_2/lib/rubygems/compatibility.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-# :stopdoc:
-
-#--
-# This file contains all sorts of little compatibility hacks that we've
-# had to introduce over the years. Quarantining them into one file helps
-# us know when we can get rid of them.
-#
-# Ruby 1.9.x has introduced some things that are awkward, and we need to
-# support them, so we define some constants to use later.
-#++
-module Gem
- # Only MRI 1.9.2 has the custom prelude.
- GEM_PRELUDE_SUCKAGE = RUBY_VERSION =~ /^1\.9\.2/ and RUBY_ENGINE == "ruby"
-end
-
-# Gem::QuickLoader exists in the gem prelude code in ruby 1.9.2 itself.
-# We gotta get rid of it if it's there, before we do anything else.
-if Gem::GEM_PRELUDE_SUCKAGE and defined?(Gem::QuickLoader) then
- Gem::QuickLoader.remove
-
- $LOADED_FEATURES.delete Gem::QuickLoader.path_to_full_rubygems_library
-
- if path = $LOADED_FEATURES.find {|n| n.end_with? '/rubygems.rb'} then
- raise LoadError, "another rubygems is already loaded from #{path}"
- end
-
- class << Gem
- remove_method :try_activate if Gem.respond_to?(:try_activate, true)
- end
-end
-
-module Gem
- RubyGemsVersion = VERSION
-
- # TODO remove at RubyGems 3
-
- RbConfigPriorities = %w[
- MAJOR
- MINOR
- TEENY
- EXEEXT RUBY_SO_NAME arch bindir datadir libdir ruby_install_name
- ruby_version rubylibprefix sitedir sitelibdir vendordir vendorlibdir
- rubylibdir
- ]
-
- unless defined?(ConfigMap)
- ##
- # Configuration settings from ::RbConfig
- ConfigMap = Hash.new do |cm, key| # TODO remove at RubyGems 3
- cm[key] = RbConfig::CONFIG[key.to_s]
- end
- else
- RbConfigPriorities.each do |key|
- ConfigMap[key.to_sym] = RbConfig::CONFIG[key]
- end
- end
-
- RubyGemsPackageVersion = VERSION
-end
diff --git a/ruby_2_2/lib/rubygems/config_file.rb b/ruby_2_2/lib/rubygems/config_file.rb
deleted file mode 100644
index f075b93aab..0000000000
--- a/ruby_2_2/lib/rubygems/config_file.rb
+++ /dev/null
@@ -1,483 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'rubygems/user_interaction'
-require 'rbconfig'
-
-##
-# Gem::ConfigFile RubyGems options and gem command options from gemrc.
-#
-# gemrc is a YAML file that uses strings to match gem command arguments and
-# symbols to match RubyGems options.
-#
-# Gem command arguments use a String key that matches the command name and
-# allow you to specify default arguments:
-#
-# install: --no-rdoc --no-ri
-# update: --no-rdoc --no-ri
-#
-# You can use <tt>gem:</tt> to set default arguments for all commands.
-#
-# RubyGems options use symbol keys. Valid options are:
-#
-# +:backtrace+:: See #backtrace
-# +:sources+:: Sets Gem::sources
-# +:verbose+:: See #verbose
-#
-# gemrc files may exist in various locations and are read and merged in
-# the following order:
-#
-# - system wide (/etc/gemrc)
-# - per user (~/.gemrc)
-# - per environment (gemrc files listed in the GEMRC environment variable)
-
-class Gem::ConfigFile
-
- include Gem::UserInteraction
-
- DEFAULT_BACKTRACE = false
- DEFAULT_BULK_THRESHOLD = 1000
- DEFAULT_VERBOSITY = true
- DEFAULT_UPDATE_SOURCES = true
-
- ##
- # For Ruby packagers to set configuration defaults. Set in
- # rubygems/defaults/operating_system.rb
-
- OPERATING_SYSTEM_DEFAULTS = {}
-
- ##
- # For Ruby implementers to set configuration defaults. Set in
- # rubygems/defaults/#{RUBY_ENGINE}.rb
-
- PLATFORM_DEFAULTS = {}
-
- # :stopdoc:
-
- SYSTEM_CONFIG_PATH =
- begin
- require "etc"
- Etc.sysconfdir
- rescue LoadError, NoMethodError
- begin
- # TODO: remove after we drop 1.8.7 and 1.9.1
- require 'Win32API'
-
- CSIDL_COMMON_APPDATA = 0x0023
- path = 0.chr * 260
- if RUBY_VERSION > '1.9' then
- SHGetFolderPath = Win32API.new 'shell32', 'SHGetFolderPath', 'PLPLP',
- 'L', :stdcall
- SHGetFolderPath.call nil, CSIDL_COMMON_APPDATA, nil, 1, path
- else
- SHGetFolderPath = Win32API.new 'shell32', 'SHGetFolderPath', 'LLLLP',
- 'L'
- SHGetFolderPath.call 0, CSIDL_COMMON_APPDATA, 0, 1, path
- end
-
- path.strip
- rescue LoadError
- RbConfig::CONFIG["sysconfdir"] || "/etc"
- end
- end
-
- # :startdoc:
-
- SYSTEM_WIDE_CONFIG_FILE = File.join SYSTEM_CONFIG_PATH, 'gemrc'
-
- ##
- # List of arguments supplied to the config file object.
-
- attr_reader :args
-
- ##
- # Where to look for gems (deprecated)
-
- attr_accessor :path
-
- ##
- # Where to install gems (deprecated)
-
- attr_accessor :home
-
- ##
- # True if we print backtraces on errors.
-
- attr_writer :backtrace
-
- ##
- # Bulk threshold value. If the number of missing gems are above this
- # threshold value, then a bulk download technique is used. (deprecated)
-
- attr_accessor :bulk_threshold
-
- ##
- # Verbose level of output:
- # * false -- No output
- # * true -- Normal output
- # * :loud -- Extra output
-
- attr_accessor :verbose
-
- ##
- # True if we want to update the SourceInfoCache every time, false otherwise
-
- attr_accessor :update_sources
-
- ##
- # True if we want to force specification of gem server when pushing a gem
-
- attr_accessor :disable_default_gem_server
-
- # openssl verify mode value, used for remote https connection
-
- attr_reader :ssl_verify_mode
-
- ##
- # Path name of directory or file of openssl CA certificate, used for remote
- # https connection
-
- attr_accessor :ssl_ca_cert
-
- ##
- # Path name of directory or file of openssl client certificate, used for remote https connection with client authentication
-
- attr_reader :ssl_client_cert
-
- ##
- # Create the config file object. +args+ is the list of arguments
- # from the command line.
- #
- # The following command line options are handled early here rather
- # than later at the time most command options are processed.
- #
- # <tt>--config-file</tt>, <tt>--config-file==NAME</tt>::
- # Obviously these need to be handled by the ConfigFile object to ensure we
- # get the right config file.
- #
- # <tt>--backtrace</tt>::
- # Backtrace needs to be turned on early so that errors before normal
- # option parsing can be properly handled.
- #
- # <tt>--debug</tt>::
- # Enable Ruby level debug messages. Handled early for the same reason as
- # --backtrace.
- #--
- # TODO: parse options upstream, pass in options directly
-
- def initialize(args)
- @config_file_name = nil
- need_config_file_name = false
-
- arg_list = []
-
- args.each do |arg|
- if need_config_file_name then
- @config_file_name = arg
- need_config_file_name = false
- elsif arg =~ /^--config-file=(.*)/ then
- @config_file_name = $1
- elsif arg =~ /^--config-file$/ then
- need_config_file_name = true
- else
- arg_list << arg
- end
- end
-
- @backtrace = DEFAULT_BACKTRACE
- @bulk_threshold = DEFAULT_BULK_THRESHOLD
- @verbose = DEFAULT_VERBOSITY
- @update_sources = DEFAULT_UPDATE_SOURCES
-
- operating_system_config = Marshal.load Marshal.dump(OPERATING_SYSTEM_DEFAULTS)
- platform_config = Marshal.load Marshal.dump(PLATFORM_DEFAULTS)
- system_config = load_file SYSTEM_WIDE_CONFIG_FILE
- user_config = load_file config_file_name.dup.untaint
- environment_config = (ENV['GEMRC'] || '').split(/[:;]/).inject({}) do |result, file|
- result.merge load_file file
- end
-
-
- @hash = operating_system_config.merge platform_config
- @hash = @hash.merge system_config
- @hash = @hash.merge user_config
- @hash = @hash.merge environment_config
-
- # HACK these override command-line args, which is bad
- @backtrace = @hash[:backtrace] if @hash.key? :backtrace
- @bulk_threshold = @hash[:bulk_threshold] if @hash.key? :bulk_threshold
- @home = @hash[:gemhome] if @hash.key? :gemhome
- @path = @hash[:gempath] if @hash.key? :gempath
- @update_sources = @hash[:update_sources] if @hash.key? :update_sources
- @verbose = @hash[:verbose] if @hash.key? :verbose
- @disable_default_gem_server = @hash[:disable_default_gem_server] if @hash.key? :disable_default_gem_server
-
- @ssl_verify_mode = @hash[:ssl_verify_mode] if @hash.key? :ssl_verify_mode
- @ssl_ca_cert = @hash[:ssl_ca_cert] if @hash.key? :ssl_ca_cert
- @ssl_client_cert = @hash[:ssl_client_cert] if @hash.key? :ssl_client_cert
-
- @api_keys = nil
- @rubygems_api_key = nil
-
- Gem.sources = @hash[:sources] if @hash.key? :sources
- handle_arguments arg_list
- end
-
- ##
- # Hash of RubyGems.org and alternate API keys
-
- def api_keys
- load_api_keys unless @api_keys
-
- @api_keys
- end
-
- ##
- # Checks the permissions of the credentials file. If they are not 0600 an
- # error message is displayed and RubyGems aborts.
-
- def check_credentials_permissions
- return if Gem.win_platform? # windows doesn't write 0600 as 0600
- return unless File.exist? credentials_path
-
- existing_permissions = File.stat(credentials_path).mode & 0777
-
- return if existing_permissions == 0600
-
- alert_error <<-ERROR
-Your gem push credentials file located at:
-
-\t#{credentials_path}
-
-has file permissions of 0#{existing_permissions.to_s 8} but 0600 is required.
-
-To fix this error run:
-
-\tchmod 0600 #{credentials_path}
-
-You should reset your credentials at:
-
-\thttps://rubygems.org/profile/edit
-
-if you believe they were disclosed to a third party.
- ERROR
-
- terminate_interaction 1
- end
-
- ##
- # Location of RubyGems.org credentials
-
- def credentials_path
- File.join Gem.user_home, '.gem', 'credentials'
- end
-
- def load_api_keys
- check_credentials_permissions
-
- @api_keys = if File.exist? credentials_path then
- load_file(credentials_path)
- else
- @hash
- end
-
- if @api_keys.key? :rubygems_api_key then
- @rubygems_api_key = @api_keys[:rubygems_api_key]
- @api_keys[:rubygems] = @api_keys.delete :rubygems_api_key unless
- @api_keys.key? :rubygems
- end
- end
-
- ##
- # Returns the RubyGems.org API key
-
- def rubygems_api_key
- load_api_keys unless @rubygems_api_key
-
- @rubygems_api_key
- end
-
- ##
- # Sets the RubyGems.org API key to +api_key+
-
- def rubygems_api_key= api_key
- check_credentials_permissions
-
- config = load_file(credentials_path).merge(:rubygems_api_key => api_key)
-
- dirname = File.dirname credentials_path
- Dir.mkdir(dirname) unless File.exist? dirname
-
- Gem.load_yaml
-
- permissions = 0600 & (~File.umask)
- File.open(credentials_path, 'w', permissions) do |f|
- f.write config.to_yaml
- end
-
- @rubygems_api_key = api_key
- end
-
- YAMLErrors = [ArgumentError]
- YAMLErrors << Psych::SyntaxError if defined?(Psych::SyntaxError)
-
- def load_file(filename)
- Gem.load_yaml
-
- return {} unless filename and File.exist? filename
-
- begin
- content = Gem::SafeYAML.load(File.read(filename))
- unless content.kind_of? Hash
- warn "Failed to load #{filename} because it doesn't contain valid YAML hash"
- return {}
- end
- return content
- rescue *YAMLErrors => e
- warn "Failed to load #{filename}, #{e}"
- rescue Errno::EACCES
- warn "Failed to load #{filename} due to permissions problem."
- end
-
- {}
- end
-
- # True if the backtrace option has been specified, or debug is on.
- def backtrace
- @backtrace or $DEBUG
- end
-
- # The name of the configuration file.
- def config_file_name
- @config_file_name || Gem.config_file
- end
-
- # Delegates to @hash
- def each(&block)
- hash = @hash.dup
- hash.delete :update_sources
- hash.delete :verbose
- hash.delete :backtrace
- hash.delete :bulk_threshold
-
- yield :update_sources, @update_sources
- yield :verbose, @verbose
- yield :backtrace, @backtrace
- yield :bulk_threshold, @bulk_threshold
-
- yield 'config_file_name', @config_file_name if @config_file_name
-
- hash.each(&block)
- end
-
- # Handle the command arguments.
- def handle_arguments(arg_list)
- @args = []
-
- arg_list.each do |arg|
- case arg
- when /^--(backtrace|traceback)$/ then
- @backtrace = true
- when /^--debug$/ then
- $DEBUG = true
-
- warn 'NOTE: Debugging mode prints all exceptions even when rescued'
- else
- @args << arg
- end
- end
- end
-
- # Really verbose mode gives you extra output.
- def really_verbose
- case verbose
- when true, false, nil then
- false
- else
- true
- end
- end
-
- # to_yaml only overwrites things you can't override on the command line.
- def to_yaml # :nodoc:
- yaml_hash = {}
- yaml_hash[:backtrace] = if @hash.key?(:backtrace)
- @hash[:backtrace]
- else
- DEFAULT_BACKTRACE
- end
-
- yaml_hash[:bulk_threshold] = if @hash.key?(:bulk_threshold)
- @hash[:bulk_threshold]
- else
- DEFAULT_BULK_THRESHOLD
- end
-
- yaml_hash[:sources] = Gem.sources.to_a
-
- yaml_hash[:update_sources] = if @hash.key?(:update_sources)
- @hash[:update_sources]
- else
- DEFAULT_UPDATE_SOURCES
- end
-
- yaml_hash[:verbose] = if @hash.key?(:verbose)
- @hash[:verbose]
- else
- DEFAULT_VERBOSITY
- end
-
- yaml_hash[:ssl_verify_mode] =
- @hash[:ssl_verify_mode] if @hash.key? :ssl_verify_mode
-
- yaml_hash[:ssl_ca_cert] =
- @hash[:ssl_ca_cert] if @hash.key? :ssl_ca_cert
-
- yaml_hash[:ssl_client_cert] =
- @hash[:ssl_client_cert] if @hash.key? :ssl_client_cert
-
- keys = yaml_hash.keys.map { |key| key.to_s }
- keys << 'debug'
- re = Regexp.union(*keys)
-
- @hash.each do |key, value|
- key = key.to_s
- next if key =~ re
- yaml_hash[key.to_s] = value
- end
-
- yaml_hash.to_yaml
- end
-
- # Writes out this config file, replacing its source.
- def write
- open config_file_name, 'w' do |io|
- io.write to_yaml
- end
- end
-
- # Return the configuration information for +key+.
- def [](key)
- @hash[key.to_s]
- end
-
- # Set configuration option +key+ to +value+.
- def []=(key, value)
- @hash[key.to_s] = value
- end
-
- def ==(other) # :nodoc:
- self.class === other and
- @backtrace == other.backtrace and
- @bulk_threshold == other.bulk_threshold and
- @verbose == other.verbose and
- @update_sources == other.update_sources and
- @hash == other.hash
- end
-
- attr_reader :hash
- protected :hash
-end
diff --git a/ruby_2_2/lib/rubygems/core_ext/kernel_gem.rb b/ruby_2_2/lib/rubygems/core_ext/kernel_gem.rb
deleted file mode 100644
index 61e77fe3c5..0000000000
--- a/ruby_2_2/lib/rubygems/core_ext/kernel_gem.rb
+++ /dev/null
@@ -1,73 +0,0 @@
-##
-# RubyGems adds the #gem method to allow activation of specific gem versions
-# and overrides the #require method on Kernel to make gems appear as if they
-# live on the <code>$LOAD_PATH</code>. See the documentation of these methods
-# for further detail.
-
-module Kernel
-
- # REFACTOR: This should be pulled out into some kind of hacks file.
- remove_method :gem if 'method' == defined? gem # from gem_prelude.rb on 1.9
-
- ##
- # Use Kernel#gem to activate a specific version of +gem_name+.
- #
- # +requirements+ is a list of version requirements that the
- # specified gem must match, most commonly "= example.version.number". See
- # Gem::Requirement for how to specify a version requirement.
- #
- # If you will be activating the latest version of a gem, there is no need to
- # call Kernel#gem, Kernel#require will do the right thing for you.
- #
- # Kernel#gem returns true if the gem was activated, otherwise false. If the
- # gem could not be found, didn't match the version requirements, or a
- # different version was already activated, an exception will be raised.
- #
- # Kernel#gem should be called *before* any require statements (otherwise
- # RubyGems may load a conflicting library version).
- #
- # Kernel#gem only loads prerelease versions when prerelease +requirements+
- # are given:
- #
- # gem 'rake', '>= 1.1.a', '< 2'
- #
- # In older RubyGems versions, the environment variable GEM_SKIP could be
- # used to skip activation of specified gems, for example to test out changes
- # that haven't been installed yet. Now RubyGems defers to -I and the
- # RUBYLIB environment variable to skip activation of a gem.
- #
- # Example:
- #
- # GEM_SKIP=libA:libB ruby -I../libA -I../libB ./mycode.rb
-
- def gem(gem_name, *requirements) # :doc:
- skip_list = (ENV['GEM_SKIP'] || "").split(/:/)
- raise Gem::LoadError, "skipping #{gem_name}" if skip_list.include? gem_name
-
- if gem_name.kind_of? Gem::Dependency
- unless Gem::Deprecate.skip
- warn "#{Gem.location_of_caller.join ':'}:Warning: Kernel.gem no longer "\
- "accepts a Gem::Dependency object, please pass the name "\
- "and requirements directly"
- end
-
- requirements = gem_name.requirement
- gem_name = gem_name.name
- end
-
- dep = Gem::Dependency.new(gem_name, *requirements)
-
- loaded = Gem.loaded_specs[gem_name]
-
- return false if loaded && dep.matches_spec?(loaded)
-
- spec = dep.to_spec
-
- Gem::LOADED_SPECS_MUTEX.synchronize {
- spec.activate
- } if spec
- end
-
- private :gem
-
-end
diff --git a/ruby_2_2/lib/rubygems/core_ext/kernel_require.rb b/ruby_2_2/lib/rubygems/core_ext/kernel_require.rb
deleted file mode 100755
index 8f2cddee4d..0000000000
--- a/ruby_2_2/lib/rubygems/core_ext/kernel_require.rb
+++ /dev/null
@@ -1,139 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'monitor'
-
-module Kernel
-
- RUBYGEMS_ACTIVATION_MONITOR = Monitor.new # :nodoc:
-
- if defined?(gem_original_require) then
- # Ruby ships with a custom_require, override its require
- remove_method :require
- else
- ##
- # The Kernel#require from before RubyGems was loaded.
-
- alias gem_original_require require
- private :gem_original_require
- end
-
- ##
- # When RubyGems is required, Kernel#require is replaced with our own which
- # is capable of loading gems on demand.
- #
- # When you call <tt>require 'x'</tt>, this is what happens:
- # * If the file can be loaded from the existing Ruby loadpath, it
- # is.
- # * Otherwise, installed gems are searched for a file that matches.
- # If it's found in gem 'y', that gem is activated (added to the
- # loadpath).
- #
- # The normal <tt>require</tt> functionality of returning false if
- # that file has already been loaded is preserved.
-
- def require path
- RUBYGEMS_ACTIVATION_MONITOR.enter
-
- path = path.to_path if path.respond_to? :to_path
-
- spec = Gem.find_unresolved_default_spec(path)
- if spec
- Gem.remove_unresolved_default_spec(spec)
- gem(spec.name)
- end
-
- # If there are no unresolved deps, then we can use just try
- # normal require handle loading a gem from the rescue below.
-
- if Gem::Specification.unresolved_deps.empty? then
- RUBYGEMS_ACTIVATION_MONITOR.exit
- return gem_original_require(path)
- end
-
- # If +path+ is for a gem that has already been loaded, don't
- # bother trying to find it in an unresolved gem, just go straight
- # to normal require.
- #--
- # TODO request access to the C implementation of this to speed up RubyGems
-
- spec = Gem::Specification.stubs.find { |s|
- s.activated? and s.contains_requirable_file? path
- }
-
- begin
- RUBYGEMS_ACTIVATION_MONITOR.exit
- return gem_original_require(spec.to_fullpath(path) || path)
- end if spec
-
- # Attempt to find +path+ in any unresolved gems...
-
- found_specs = Gem::Specification.find_in_unresolved path
-
- # If there are no directly unresolved gems, then try and find +path+
- # in any gems that are available via the currently unresolved gems.
- # For example, given:
- #
- # a => b => c => d
- #
- # If a and b are currently active with c being unresolved and d.rb is
- # requested, then find_in_unresolved_tree will find d.rb in d because
- # it's a dependency of c.
- #
- if found_specs.empty? then
- found_specs = Gem::Specification.find_in_unresolved_tree path
-
- found_specs.each do |found_spec|
- found_spec.activate
- end
-
- # We found +path+ directly in an unresolved gem. Now we figure out, of
- # the possible found specs, which one we should activate.
- else
-
- # Check that all the found specs are just different
- # versions of the same gem
- names = found_specs.map(&:name).uniq
-
- if names.size > 1 then
- RUBYGEMS_ACTIVATION_MONITOR.exit
- raise Gem::LoadError, "#{path} found in multiple gems: #{names.join ', '}"
- end
-
- # Ok, now find a gem that has no conflicts, starting
- # at the highest version.
- valid = found_specs.select { |s| s.conflicts.empty? }.last
-
- unless valid then
- le = Gem::LoadError.new "unable to find a version of '#{names.first}' to activate"
- le.name = names.first
- RUBYGEMS_ACTIVATION_MONITOR.exit
- raise le
- end
-
- valid.activate
- end
-
- RUBYGEMS_ACTIVATION_MONITOR.exit
- return gem_original_require(path)
- rescue LoadError => load_error
- RUBYGEMS_ACTIVATION_MONITOR.enter
-
- if load_error.message.start_with?("Could not find") or
- (load_error.message.end_with?(path) and Gem.try_activate(path)) then
- RUBYGEMS_ACTIVATION_MONITOR.exit
- return gem_original_require(path)
- else
- RUBYGEMS_ACTIVATION_MONITOR.exit
- end
-
- raise load_error
- end
-
- private :require
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/defaults.rb b/ruby_2_2/lib/rubygems/defaults.rb
deleted file mode 100644
index 55ca080c96..0000000000
--- a/ruby_2_2/lib/rubygems/defaults.rb
+++ /dev/null
@@ -1,177 +0,0 @@
-module Gem
- DEFAULT_HOST = "https://rubygems.org"
-
- @post_install_hooks ||= []
- @done_installing_hooks ||= []
- @post_uninstall_hooks ||= []
- @pre_uninstall_hooks ||= []
- @pre_install_hooks ||= []
-
- ##
- # An Array of the default sources that come with RubyGems
-
- def self.default_sources
- %w[https://rubygems.org/]
- end
-
- ##
- # Default spec directory path to be used if an alternate value is not
- # specified in the environment
-
- def self.default_spec_cache_dir
- File.join Gem.user_home, '.gem', 'specs'
- end
-
- ##
- # Default home directory path to be used if an alternate value is not
- # specified in the environment
-
- def self.default_dir
- path = if defined? RUBY_FRAMEWORK_VERSION then
- [
- File.dirname(RbConfig::CONFIG['sitedir']),
- 'Gems',
- RbConfig::CONFIG['ruby_version']
- ]
- elsif RbConfig::CONFIG['rubylibprefix'] then
- [
- RbConfig::CONFIG['rubylibprefix'],
- 'gems',
- RbConfig::CONFIG['ruby_version']
- ]
- else
- [
- RbConfig::CONFIG['libdir'],
- ruby_engine,
- 'gems',
- RbConfig::CONFIG['ruby_version']
- ]
- end
-
- @default_dir ||= File.join(*path)
- end
-
- ##
- # Returns binary extensions dir for specified RubyGems base dir or nil
- # if such directory cannot be determined.
- #
- # By default, the binary extensions are located side by side with their
- # Ruby counterparts, therefore nil is returned
-
- def self.default_ext_dir_for base_dir
- nil
- end
-
- ##
- # Paths where RubyGems' .rb files and bin files are installed
-
- def self.default_rubygems_dirs
- nil # default to standard layout
- end
-
- ##
- # Path for gems in the user's home directory
-
- def self.user_dir
- parts = [Gem.user_home, '.gem', ruby_engine]
- parts << RbConfig::CONFIG['ruby_version'] unless RbConfig::CONFIG['ruby_version'].empty?
- File.join parts
- end
-
- ##
- # How String Gem paths should be split. Overridable for esoteric platforms.
-
- def self.path_separator
- File::PATH_SEPARATOR
- end
-
- ##
- # Default gem load path
-
- def self.default_path
- path = []
- path << user_dir if user_home && File.exist?(user_home)
- path << default_dir
- path << vendor_dir if vendor_dir and File.directory? vendor_dir
- path
- end
-
- ##
- # Deduce Ruby's --program-prefix and --program-suffix from its install name
-
- def self.default_exec_format
- exec_format = RbConfig::CONFIG['ruby_install_name'].sub('ruby', '%s') rescue '%s'
-
- unless exec_format =~ /%s/ then
- raise Gem::Exception,
- "[BUG] invalid exec_format #{exec_format.inspect}, no %s"
- end
-
- exec_format
- end
-
- ##
- # The default directory for binaries
-
- def self.default_bindir
- if defined? RUBY_FRAMEWORK_VERSION then # mac framework support
- '/usr/bin'
- else # generic install
- RbConfig::CONFIG['bindir']
- end
- end
-
- ##
- # A wrapper around RUBY_ENGINE const that may not be defined
-
- def self.ruby_engine
- if defined? RUBY_ENGINE then
- RUBY_ENGINE
- else
- 'ruby'
- end
- end
-
- ##
- # The default signing key path
-
- def self.default_key_path
- File.join Gem.user_home, ".gem", "gem-private_key.pem"
- end
-
- ##
- # The default signing certificate chain path
-
- def self.default_cert_path
- File.join Gem.user_home, ".gem", "gem-public_cert.pem"
- end
-
- ##
- # Whether to expect full paths in default gems - true for non-MRI
- # ruby implementations
- def self.default_gems_use_full_paths?
- ruby_engine != 'ruby'
- end
-
- ##
- # Install extensions into lib as well as into the extension directory.
-
- def self.install_extension_in_lib # :nodoc:
- true
- end
-
- ##
- # Directory where vendor gems are installed.
-
- def self.vendor_dir # :nodoc:
- if vendor_dir = ENV['GEM_VENDOR'] then
- return vendor_dir.dup
- end
-
- return nil unless RbConfig::CONFIG.key? 'vendordir'
-
- File.join RbConfig::CONFIG['vendordir'], 'gems',
- RbConfig::CONFIG['ruby_version']
- end
-
-end
diff --git a/ruby_2_2/lib/rubygems/dependency.rb b/ruby_2_2/lib/rubygems/dependency.rb
deleted file mode 100644
index 5924d2fc6b..0000000000
--- a/ruby_2_2/lib/rubygems/dependency.rb
+++ /dev/null
@@ -1,334 +0,0 @@
-##
-# The Dependency class holds a Gem name and a Gem::Requirement.
-
-require "rubygems/requirement"
-
-class Gem::Dependency
-
- ##
- # Valid dependency types.
- #--
- # When this list is updated, be sure to change
- # Gem::Specification::CURRENT_SPECIFICATION_VERSION as well.
- #
- # REFACTOR: This type of constant, TYPES, indicates we might want
- # two classes, used via inheritance or duck typing.
-
- TYPES = [
- :development,
- :runtime,
- ]
-
- ##
- # Dependency name or regular expression.
-
- attr_accessor :name
-
- ##
- # Allows you to force this dependency to be a prerelease.
-
- attr_writer :prerelease
-
- ##
- # Constructs a dependency with +name+ and +requirements+. The last
- # argument can optionally be the dependency type, which defaults to
- # <tt>:runtime</tt>.
-
- def initialize name, *requirements
- case name
- when String then # ok
- when Regexp then
- msg = ["NOTE: Dependency.new w/ a regexp is deprecated.",
- "Dependency.new called from #{Gem.location_of_caller.join(":")}"]
- warn msg.join("\n") unless Gem::Deprecate.skip
- else
- raise ArgumentError,
- "dependency name must be a String, was #{name.inspect}"
- end
-
- type = Symbol === requirements.last ? requirements.pop : :runtime
- requirements = requirements.first if 1 == requirements.length # unpack
-
- unless TYPES.include? type
- raise ArgumentError, "Valid types are #{TYPES.inspect}, " +
- "not #{type.inspect}"
- end
-
- @name = name
- @requirement = Gem::Requirement.create requirements
- @type = type
- @prerelease = false
-
- # This is for Marshal backwards compatibility. See the comments in
- # +requirement+ for the dirty details.
-
- @version_requirements = @requirement
- end
-
- ##
- # A dependency's hash is the XOR of the hashes of +name+, +type+,
- # and +requirement+.
-
- def hash # :nodoc:
- name.hash ^ type.hash ^ requirement.hash
- end
-
- def inspect # :nodoc:
- if prerelease? then
- "<%s type=%p name=%p requirements=%p prerelease=ok>" %
- [self.class, self.type, self.name, requirement.to_s]
- else
- "<%s type=%p name=%p requirements=%p>" %
- [self.class, self.type, self.name, requirement.to_s]
- end
- end
-
- ##
- # Does this dependency require a prerelease?
-
- def prerelease?
- @prerelease || requirement.prerelease?
- end
-
- ##
- # Is this dependency simply asking for the latest version
- # of a gem?
-
- def latest_version?
- @requirement.none?
- end
-
- def pretty_print q # :nodoc:
- q.group 1, 'Gem::Dependency.new(', ')' do
- q.pp name
- q.text ','
- q.breakable
-
- q.pp requirement
-
- q.text ','
- q.breakable
-
- q.pp type
- end
- end
-
- ##
- # What does this dependency require?
-
- def requirement
- return @requirement if defined?(@requirement) and @requirement
-
- # @version_requirements and @version_requirement are legacy ivar
- # names, and supported here because older gems need to keep
- # working and Dependency doesn't implement marshal_dump and
- # marshal_load. In a happier world, this would be an
- # attr_accessor. The horrifying instance_variable_get you see
- # below is also the legacy of some old restructurings.
- #
- # Note also that because of backwards compatibility (loading new
- # gems in an old RubyGems installation), we can't add explicit
- # marshaling to this class until we want to make a big
- # break. Maybe 2.0.
- #
- # Children, define explicit marshal and unmarshal behavior for
- # public classes. Marshal formats are part of your public API.
-
- # REFACTOR: See above
-
- if defined?(@version_requirement) && @version_requirement
- version = @version_requirement.instance_variable_get :@version
- @version_requirement = nil
- @version_requirements = Gem::Requirement.new version
- end
-
- @requirement = @version_requirements if defined?(@version_requirements)
- end
-
- def requirements_list
- requirement.as_list
- end
-
- def to_s # :nodoc:
- if type != :runtime then
- "#{name} (#{requirement}, #{type})"
- else
- "#{name} (#{requirement})"
- end
- end
-
- ##
- # Dependency type.
-
- def type
- @type ||= :runtime
- end
-
- def == other # :nodoc:
- Gem::Dependency === other &&
- self.name == other.name &&
- self.type == other.type &&
- self.requirement == other.requirement
- end
-
- ##
- # Dependencies are ordered by name.
-
- def <=> other
- self.name <=> other.name
- end
-
- ##
- # Uses this dependency as a pattern to compare to +other+. This
- # dependency will match if the name matches the other's name, and
- # other has only an equal version requirement that satisfies this
- # dependency.
-
- def =~ other
- unless Gem::Dependency === other
- return unless other.respond_to?(:name) && other.respond_to?(:version)
- other = Gem::Dependency.new other.name, other.version
- end
-
- return false unless name === other.name
-
- reqs = other.requirement.requirements
-
- return false unless reqs.length == 1
- return false unless reqs.first.first == '='
-
- version = reqs.first.last
-
- requirement.satisfied_by? version
- end
-
- alias === =~
-
- ##
- # :call-seq:
- # dep.match? name => true or false
- # dep.match? name, version => true or false
- # dep.match? spec => true or false
- #
- # Does this dependency match the specification described by +name+ and
- # +version+ or match +spec+?
- #
- # NOTE: Unlike #matches_spec? this method does not return true when the
- # version is a prerelease version unless this is a prerelease dependency.
-
- def match? obj, version=nil, allow_prerelease=false
- if !version
- name = obj.name
- version = obj.version
- else
- name = obj
- end
-
- return false unless self.name === name
-
- version = Gem::Version.new version
-
- return true if requirement.none? and not version.prerelease?
- return false if version.prerelease? and
- not allow_prerelease and
- not prerelease?
-
- requirement.satisfied_by? version
- end
-
- ##
- # Does this dependency match +spec+?
- #
- # NOTE: This is not a convenience method. Unlike #match? this method
- # returns true when +spec+ is a prerelease version even if this dependency
- # is not a prerelease dependency.
-
- def matches_spec? spec
- return false unless name === spec.name
- return true if requirement.none?
-
- requirement.satisfied_by?(spec.version)
- end
-
- ##
- # Merges the requirements of +other+ into this dependency
-
- def merge other
- unless name == other.name then
- raise ArgumentError,
- "#{self} and #{other} have different names"
- end
-
- default = Gem::Requirement.default
- self_req = self.requirement
- other_req = other.requirement
-
- return self.class.new name, self_req if other_req == default
- return self.class.new name, other_req if self_req == default
-
- self.class.new name, self_req.as_list.concat(other_req.as_list)
- end
-
- def matching_specs platform_only = false
- matches = Gem::Specification.stubs.find_all { |spec|
- self.name === spec.name and # TODO: == instead of ===
- requirement.satisfied_by? spec.version
- }.map(&:to_spec)
-
- if platform_only
- matches.reject! { |spec|
- not Gem::Platform.match spec.platform
- }
- end
-
- matches.sort_by { |s| s.sort_obj } # HACK: shouldn't be needed
- end
-
- ##
- # True if the dependency will not always match the latest version.
-
- def specific?
- @requirement.specific?
- end
-
- def to_specs
- matches = matching_specs true
-
- # TODO: check Gem.activated_spec[self.name] in case matches falls outside
-
- if matches.empty? then
- specs = Gem::Specification.find_all { |s|
- s.name == name
- }.map { |x| x.full_name }
-
- if specs.empty?
- total = Gem::Specification.to_a.size
- msg = "Could not find '#{name}' (#{requirement}) among #{total} total gem(s)\n"
- else
- msg = "Could not find '#{name}' (#{requirement}) - did find: [#{specs.join ','}]\n"
- end
- msg << "Checked in 'GEM_PATH=#{Gem.path.join(File::PATH_SEPARATOR)}', execute `gem env` for more information"
-
- error = Gem::LoadError.new(msg)
- error.name = self.name
- error.requirement = self.requirement
- raise error
- end
-
- # TODO: any other resolver validations should go here
-
- matches
- end
-
- def to_spec
- matches = self.to_specs
-
- active = matches.find { |spec| spec.activated? }
-
- return active if active
-
- matches.delete_if { |spec| spec.version.prerelease? } unless prerelease?
-
- matches.last
- end
-end
diff --git a/ruby_2_2/lib/rubygems/dependency_installer.rb b/ruby_2_2/lib/rubygems/dependency_installer.rb
deleted file mode 100644
index 039d046da2..0000000000
--- a/ruby_2_2/lib/rubygems/dependency_installer.rb
+++ /dev/null
@@ -1,480 +0,0 @@
-require 'rubygems'
-require 'rubygems/dependency_list'
-require 'rubygems/package'
-require 'rubygems/installer'
-require 'rubygems/spec_fetcher'
-require 'rubygems/user_interaction'
-require 'rubygems/source'
-require 'rubygems/available_set'
-
-##
-# Installs a gem along with all its dependencies from local and remote gems.
-
-class Gem::DependencyInstaller
-
- include Gem::UserInteraction
-
- DEFAULT_OPTIONS = { # :nodoc:
- :env_shebang => false,
- :document => %w[ri],
- :domain => :both, # HACK dup
- :force => false,
- :format_executable => false, # HACK dup
- :ignore_dependencies => false,
- :prerelease => false,
- :security_policy => nil, # HACK NoSecurity requires OpenSSL. AlmostNo? Low?
- :wrappers => true,
- :build_args => nil,
- :build_docs_in_background => false,
- :install_as_default => false
- }.freeze
-
- ##
- # Documentation types. For use by the Gem.done_installing hook
-
- attr_reader :document
-
- ##
- # Errors from SpecFetcher while searching for remote specifications
-
- attr_reader :errors
-
- ##
- #--
- # TODO remove, no longer used
-
- attr_reader :gems_to_install # :nodoc:
-
- ##
- # List of gems installed by #install in alphabetic order
-
- attr_reader :installed_gems
-
- ##
- # Creates a new installer instance.
- #
- # Options are:
- # :cache_dir:: Alternate repository path to store .gem files in.
- # :domain:: :local, :remote, or :both. :local only searches gems in the
- # current directory. :remote searches only gems in Gem::sources.
- # :both searches both.
- # :env_shebang:: See Gem::Installer::new.
- # :force:: See Gem::Installer#install.
- # :format_executable:: See Gem::Installer#initialize.
- # :ignore_dependencies:: Don't install any dependencies.
- # :install_dir:: See Gem::Installer#install.
- # :prerelease:: Allow prerelease versions. See #install.
- # :security_policy:: See Gem::Installer::new and Gem::Security.
- # :user_install:: See Gem::Installer.new
- # :wrappers:: See Gem::Installer::new
- # :build_args:: See Gem::Installer::new
-
- def initialize options = {}
- @only_install_dir = !!options[:install_dir]
- @install_dir = options[:install_dir] || Gem.dir
- @build_root = options[:build_root]
-
- options = DEFAULT_OPTIONS.merge options
-
- @bin_dir = options[:bin_dir]
- @dev_shallow = options[:dev_shallow]
- @development = options[:development]
- @document = options[:document]
- @domain = options[:domain]
- @env_shebang = options[:env_shebang]
- @force = options[:force]
- @format_executable = options[:format_executable]
- @ignore_dependencies = options[:ignore_dependencies]
- @prerelease = options[:prerelease]
- @security_policy = options[:security_policy]
- @user_install = options[:user_install]
- @wrappers = options[:wrappers]
- @build_args = options[:build_args]
- @build_docs_in_background = options[:build_docs_in_background]
- @install_as_default = options[:install_as_default]
-
- # Indicates that we should not try to update any deps unless
- # we absolutely must.
- @minimal_deps = options[:minimal_deps]
-
- @available = nil
- @installed_gems = []
- @toplevel_specs = nil
-
- @cache_dir = options[:cache_dir] || @install_dir
-
- @errors = []
- end
-
- ##
- #--
- # TODO remove, no longer used
-
- def add_found_dependencies to_do, dependency_list # :nodoc:
- seen = {}
- dependencies = Hash.new { |h, name| h[name] = Gem::Dependency.new name }
-
- until to_do.empty? do
- spec = to_do.shift
-
- # HACK why is spec nil?
- next if spec.nil? or seen[spec.name]
- seen[spec.name] = true
-
- deps = spec.runtime_dependencies
-
- if @development
- if @dev_shallow
- if @toplevel_specs.include? spec.full_name
- deps |= spec.development_dependencies
- end
- else
- deps |= spec.development_dependencies
- end
- end
-
- deps.each do |dep|
- dependencies[dep.name] = dependencies[dep.name].merge dep
-
- if @minimal_deps
- next if Gem::Specification.any? do |installed_spec|
- dep.name == installed_spec.name and
- dep.requirement.satisfied_by? installed_spec.version
- end
- end
-
- results = find_gems_with_sources(dep)
-
- results.sorted.each do |t|
- to_do.push t.spec
- end
-
- results.remove_installed! dep
-
- @available << results
- results.inject_into_list dependency_list
- end
- end
-
- dependency_list.remove_specs_unsatisfied_by dependencies
- end
-
- ##
- # Creates an AvailableSet to install from based on +dep_or_name+ and
- # +version+
-
- def available_set_for dep_or_name, version # :nodoc:
- if String === dep_or_name then
- find_spec_by_name_and_version dep_or_name, version, @prerelease
- else
- dep = dep_or_name.dup
- dep.prerelease = @prerelease
- @available = find_gems_with_sources dep
- end
-
- @available.pick_best!
- end
-
- ##
- # Indicated, based on the requested domain, if local
- # gems should be considered.
-
- def consider_local?
- @domain == :both or @domain == :local
- end
-
- ##
- # Indicated, based on the requested domain, if remote
- # gems should be considered.
-
- def consider_remote?
- @domain == :both or @domain == :remote
- end
-
- ##
- # Returns a list of pairs of gemspecs and source_uris that match
- # Gem::Dependency +dep+ from both local (Dir.pwd) and remote (Gem.sources)
- # sources. Gems are sorted with newer gems preferred over older gems, and
- # local gems preferred over remote gems.
-
- def find_gems_with_sources dep, best_only=false # :nodoc:
- set = Gem::AvailableSet.new
-
- if consider_local?
- sl = Gem::Source::Local.new
-
- if spec = sl.find_gem(dep.name)
- if dep.matches_spec? spec
- set.add spec, sl
- end
- end
- end
-
- if consider_remote?
- begin
- # TODO this is pulled from #spec_for_dependency to allow
- # us to filter tuples before fetching specs.
- #
- tuples, errors = Gem::SpecFetcher.fetcher.search_for_dependency dep
-
- if best_only && !tuples.empty?
- tuples.sort! { |a,b| b[0].version <=> a[0].version }
- tuples = [tuples.first]
- end
-
- specs = []
- tuples.each do |tup, source|
- begin
- spec = source.fetch_spec(tup)
- rescue Gem::RemoteFetcher::FetchError => e
- errors << Gem::SourceFetchProblem.new(source, e)
- else
- specs << [spec, source]
- end
- end
-
- if @errors
- @errors += errors
- else
- @errors = errors
- end
-
- set << specs
-
- rescue Gem::RemoteFetcher::FetchError => e
- # FIX if there is a problem talking to the network, we either need to always tell
- # the user (no really_verbose) or fail hard, not silently tell them that we just
- # couldn't find their requested gem.
- verbose do
- "Error fetching remote data:\t\t#{e.message}\n" \
- "Falling back to local-only install"
- end
- @domain = :local
- end
- end
-
- set
- end
-
- ##
- # Finds a spec and the source_uri it came from for gem +gem_name+ and
- # +version+. Returns an Array of specs and sources required for
- # installation of the gem.
-
- def find_spec_by_name_and_version gem_name,
- version = Gem::Requirement.default,
- prerelease = false
- set = Gem::AvailableSet.new
-
- if consider_local?
- if gem_name =~ /\.gem$/ and File.file? gem_name then
- src = Gem::Source::SpecificFile.new(gem_name)
- set.add src.spec, src
- elsif gem_name =~ /\.gem$/ then
- Dir[gem_name].each do |name|
- begin
- src = Gem::Source::SpecificFile.new name
- set.add src.spec, src
- rescue Gem::Package::FormatError
- end
- end
- else
- local = Gem::Source::Local.new
-
- if s = local.find_gem(gem_name, version)
- set.add s, local
- end
- end
- end
-
- if set.empty?
- dep = Gem::Dependency.new gem_name, version
- dep.prerelease = true if prerelease
-
- set = find_gems_with_sources(dep, true)
- set.match_platform!
- end
-
- if set.empty?
- raise Gem::SpecificGemNotFoundException.new(gem_name, version, @errors)
- end
-
- @available = set
- end
-
- ##
- # Gathers all dependencies necessary for the installation from local and
- # remote sources unless the ignore_dependencies was given.
- #--
- # TODO remove at RubyGems 3
-
- def gather_dependencies # :nodoc:
- specs = @available.all_specs
-
- # these gems were listed by the user, always install them
- keep_names = specs.map { |spec| spec.full_name }
-
- if @dev_shallow
- @toplevel_specs = keep_names
- end
-
- dependency_list = Gem::DependencyList.new @development
- dependency_list.add(*specs)
- to_do = specs.dup
- add_found_dependencies to_do, dependency_list unless @ignore_dependencies
-
- # REFACTOR maybe abstract away using Gem::Specification.include? so
- # that this isn't dependent only on the currently installed gems
- dependency_list.specs.reject! { |spec|
- not keep_names.include?(spec.full_name) and
- Gem::Specification.include?(spec)
- }
-
- unless dependency_list.ok? or @ignore_dependencies or @force then
- reason = dependency_list.why_not_ok?.map { |k,v|
- "#{k} requires #{v.join(", ")}"
- }.join("; ")
- raise Gem::DependencyError, "Unable to resolve dependencies: #{reason}"
- end
-
- @gems_to_install = dependency_list.dependency_order.reverse
- end
-
- def in_background what # :nodoc:
- fork_happened = false
- if @build_docs_in_background and Process.respond_to?(:fork)
- begin
- Process.fork do
- yield
- end
- fork_happened = true
- say "#{what} in a background process."
- rescue NotImplementedError
- end
- end
- yield unless fork_happened
- end
-
- ##
- # Installs the gem +dep_or_name+ and all its dependencies. Returns an Array
- # of installed gem specifications.
- #
- # If the +:prerelease+ option is set and there is a prerelease for
- # +dep_or_name+ the prerelease version will be installed.
- #
- # Unless explicitly specified as a prerelease dependency, prerelease gems
- # that +dep_or_name+ depend on will not be installed.
- #
- # If c-1.a depends on b-1 and a-1.a and there is a gem b-1.a available then
- # c-1.a, b-1 and a-1.a will be installed. b-1.a will need to be installed
- # separately.
-
- def install dep_or_name, version = Gem::Requirement.default
- request_set = resolve_dependencies dep_or_name, version
-
- @installed_gems = []
-
- options = {
- :bin_dir => @bin_dir,
- :build_args => @build_args,
- :document => @document,
- :env_shebang => @env_shebang,
- :force => @force,
- :format_executable => @format_executable,
- :ignore_dependencies => @ignore_dependencies,
- :prerelease => @prerelease,
- :security_policy => @security_policy,
- :user_install => @user_install,
- :wrappers => @wrappers,
- :build_root => @build_root,
- :install_as_default => @install_as_default
- }
- options[:install_dir] = @install_dir if @only_install_dir
-
- request_set.install options do |_, installer|
- @installed_gems << installer.spec if installer
- end
-
- @installed_gems.sort!
-
- # Since this is currently only called for docs, we can be lazy and just say
- # it's documentation. Ideally the hook adder could decide whether to be in
- # the background or not, and what to call it.
- in_background "Installing documentation" do
- Gem.done_installing_hooks.each do |hook|
- hook.call self, @installed_gems
- end
- end unless Gem.done_installing_hooks.empty?
-
- @installed_gems
- end
-
- def install_development_deps # :nodoc:
- if @development and @dev_shallow then
- :shallow
- elsif @development then
- :all
- else
- :none
- end
- end
-
- def resolve_dependencies dep_or_name, version # :nodoc:
- request_set = Gem::RequestSet.new
- request_set.development = @development
- request_set.development_shallow = @dev_shallow
- request_set.soft_missing = @force
- request_set.prerelease = @prerelease
- request_set.remote = false unless consider_remote?
-
- installer_set = Gem::Resolver::InstallerSet.new @domain
- installer_set.ignore_installed = @only_install_dir
-
- if consider_local?
- if dep_or_name =~ /\.gem$/ and File.file? dep_or_name then
- src = Gem::Source::SpecificFile.new dep_or_name
- installer_set.add_local dep_or_name, src.spec, src
- version = src.spec.version if version == Gem::Requirement.default
- elsif dep_or_name =~ /\.gem$/ then
- Dir[dep_or_name].each do |name|
- begin
- src = Gem::Source::SpecificFile.new name
- installer_set.add_local dep_or_name, src.spec, src
- rescue Gem::Package::FormatError
- end
- end
- # else This is a dependency. InstallerSet handles this case
- end
- end
-
- dependency =
- if spec = installer_set.local?(dep_or_name) then
- Gem::Dependency.new spec.name, version
- elsif String === dep_or_name then
- Gem::Dependency.new dep_or_name, version
- else
- dep_or_name
- end
-
- dependency.prerelease = @prerelease
-
- request_set.import [dependency]
-
- installer_set.add_always_install dependency
-
- request_set.always_install = installer_set.always_install
-
- if @ignore_dependencies then
- installer_set.ignore_dependencies = true
- request_set.ignore_dependencies = true
- request_set.soft_missing = true
- end
-
- request_set.resolve installer_set
-
- @errors.concat request_set.errors
-
- request_set
- end
-
-end
diff --git a/ruby_2_2/lib/rubygems/dependency_list.rb b/ruby_2_2/lib/rubygems/dependency_list.rb
deleted file mode 100644
index ad7a82a86e..0000000000
--- a/ruby_2_2/lib/rubygems/dependency_list.rb
+++ /dev/null
@@ -1,240 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'tsort'
-require 'rubygems/deprecate'
-
-##
-# Gem::DependencyList is used for installing and uninstalling gems in the
-# correct order to avoid conflicts.
-#--
-# TODO: It appears that all but topo-sort functionality is being duplicated
-# (or is planned to be duplicated) elsewhere in rubygems. Is the majority of
-# this class necessary anymore? Especially #ok?, #why_not_ok?
-
-class Gem::DependencyList
- attr_reader :specs
-
- include Enumerable
- include TSort
-
- ##
- # Allows enabling/disabling use of development dependencies
-
- attr_accessor :development
-
- ##
- # Creates a DependencyList from the current specs.
-
- def self.from_specs
- list = new
- list.add(*Gem::Specification.to_a)
- list
- end
-
- ##
- # Creates a new DependencyList. If +development+ is true, development
- # dependencies will be included.
-
- def initialize development = false
- @specs = []
-
- @development = development
- end
-
- ##
- # Adds +gemspecs+ to the dependency list.
-
- def add(*gemspecs)
- @specs.concat gemspecs
- end
-
- def clear
- @specs.clear
- end
-
- ##
- # Return a list of the gem specifications in the dependency list, sorted in
- # order so that no gemspec in the list depends on a gemspec earlier in the
- # list.
- #
- # This is useful when removing gems from a set of installed gems. By
- # removing them in the returned order, you don't get into as many dependency
- # issues.
- #
- # If there are circular dependencies (yuck!), then gems will be returned in
- # order until only the circular dependents and anything they reference are
- # left. Then arbitrary gemspecs will be returned until the circular
- # dependency is broken, after which gems will be returned in dependency
- # order again.
-
- def dependency_order
- sorted = strongly_connected_components.flatten
-
- result = []
- seen = {}
-
- sorted.each do |spec|
- if index = seen[spec.name] then
- if result[index].version < spec.version then
- result[index] = spec
- end
- else
- seen[spec.name] = result.length
- result << spec
- end
- end
-
- result.reverse
- end
-
- ##
- # Iterator over dependency_order
-
- def each(&block)
- dependency_order.each(&block)
- end
-
- def find_name(full_name)
- @specs.find { |spec| spec.full_name == full_name }
- end
-
- def inspect # :nodoc:
- "#<%s:0x%x %p>" % [self.class, object_id, map { |s| s.full_name }]
- end
-
- ##
- # Are all the dependencies in the list satisfied?
-
- def ok?
- why_not_ok?(:quick).empty?
- end
-
- def why_not_ok? quick = false
- unsatisfied = Hash.new { |h,k| h[k] = [] }
- each do |spec|
- spec.runtime_dependencies.each do |dep|
- inst = Gem::Specification.any? { |installed_spec|
- dep.name == installed_spec.name and
- dep.requirement.satisfied_by? installed_spec.version
- }
-
- unless inst or @specs.find { |s| s.satisfies_requirement? dep } then
- unsatisfied[spec.name] << dep
- return unsatisfied if quick
- end
- end
- end
-
- unsatisfied
- end
-
- ##
- # Is is ok to remove a gemspec from the dependency list?
- #
- # If removing the gemspec creates breaks a currently ok dependency, then it
- # is NOT ok to remove the gemspec.
-
- def ok_to_remove?(full_name, check_dev=true)
- gem_to_remove = find_name full_name
-
- siblings = @specs.find_all { |s|
- s.name == gem_to_remove.name &&
- s.full_name != gem_to_remove.full_name
- }
-
- deps = []
-
- @specs.each do |spec|
- check = check_dev ? spec.dependencies : spec.runtime_dependencies
-
- check.each do |dep|
- deps << dep if gem_to_remove.satisfies_requirement?(dep)
- end
- end
-
- deps.all? { |dep|
- siblings.any? { |s|
- s.satisfies_requirement? dep
- }
- }
- end
-
- ##
- # Remove everything in the DependencyList that matches but doesn't
- # satisfy items in +dependencies+ (a hash of gem names to arrays of
- # dependencies).
-
- def remove_specs_unsatisfied_by dependencies
- specs.reject! { |spec|
- dep = dependencies[spec.name]
- dep and not dep.requirement.satisfied_by? spec.version
- }
- end
-
- ##
- # Removes the gemspec matching +full_name+ from the dependency list
-
- def remove_by_name(full_name)
- @specs.delete_if { |spec| spec.full_name == full_name }
- end
-
- ##
- # Return a hash of predecessors. <tt>result[spec]</tt> is an Array of
- # gemspecs that have a dependency satisfied by the named gemspec.
-
- def spec_predecessors
- result = Hash.new { |h,k| h[k] = [] }
-
- specs = @specs.sort.reverse
-
- specs.each do |spec|
- specs.each do |other|
- next if spec == other
-
- other.dependencies.each do |dep|
- if spec.satisfies_requirement? dep then
- result[spec] << other
- end
- end
- end
- end
-
- result
- end
-
- def tsort_each_node(&block)
- @specs.each(&block)
- end
-
- def tsort_each_child(node)
- specs = @specs.sort.reverse
-
- dependencies = node.runtime_dependencies
- dependencies.push(*node.development_dependencies) if @development
-
- dependencies.each do |dep|
- specs.each do |spec|
- if spec.satisfies_requirement? dep then
- yield spec
- break
- end
- end
- end
- end
-
- private
-
- ##
- # Count the number of gemspecs in the list +specs+ that are not in
- # +ignored+.
-
- def active_count(specs, ignored)
- specs.count { |spec| ignored[spec.full_name].nil? }
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/deprecate.rb b/ruby_2_2/lib/rubygems/deprecate.rb
deleted file mode 100644
index e19360da13..0000000000
--- a/ruby_2_2/lib/rubygems/deprecate.rb
+++ /dev/null
@@ -1,70 +0,0 @@
-##
-# Provides a single method +deprecate+ to be used to declare when
-# something is going away.
-#
-# class Legacy
-# def self.klass_method
-# # ...
-# end
-#
-# def instance_method
-# # ...
-# end
-#
-# extend Gem::Deprecate
-# deprecate :instance_method, "X.z", 2011, 4
-#
-# class << self
-# extend Gem::Deprecate
-# deprecate :klass_method, :none, 2011, 4
-# end
-# end
-
-module Gem::Deprecate
-
- def self.skip # :nodoc:
- @skip ||= false
- end
-
- def self.skip= v # :nodoc:
- @skip = v
- end
-
- ##
- # Temporarily turn off warnings. Intended for tests only.
-
- def skip_during
- Gem::Deprecate.skip, original = true, Gem::Deprecate.skip
- yield
- ensure
- Gem::Deprecate.skip = original
- end
-
- ##
- # Simple deprecation method that deprecates +name+ by wrapping it up
- # in a dummy method. It warns on each call to the dummy method
- # telling the user of +repl+ (unless +repl+ is :none) and the
- # year/month that it is planned to go away.
-
- def deprecate name, repl, year, month
- class_eval {
- old = "_deprecated_#{name}"
- alias_method old, name
- define_method name do |*args, &block|
- klass = self.kind_of? Module
- target = klass ? "#{self}." : "#{self.class}#"
- msg = [ "NOTE: #{target}#{name} is deprecated",
- repl == :none ? " with no replacement" : "; use #{repl} instead",
- ". It will be removed on or after %4d-%02d-01." % [year, month],
- "\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}",
- ]
- warn "#{msg.join}." unless Gem::Deprecate.skip
- send old, *args, &block
- end
- }
- end
-
- module_function :deprecate, :skip_during
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/doctor.rb b/ruby_2_2/lib/rubygems/doctor.rb
deleted file mode 100644
index 3c71fd5aa4..0000000000
--- a/ruby_2_2/lib/rubygems/doctor.rb
+++ /dev/null
@@ -1,131 +0,0 @@
-require 'rubygems'
-require 'rubygems/user_interaction'
-
-##
-# Cleans up after a partially-failed uninstall or for an invalid
-# Gem::Specification.
-#
-# If a specification was removed by hand this will remove any remaining files.
-#
-# If a corrupt specification was installed this will clean up warnings by
-# removing the bogus specification.
-
-class Gem::Doctor
-
- include Gem::UserInteraction
-
- ##
- # Maps a gem subdirectory to the files that are expected to exist in the
- # subdirectory.
-
- REPOSITORY_EXTENSION_MAP = [ # :nodoc:
- ['specifications', '.gemspec'],
- ['build_info', '.info'],
- ['cache', '.gem'],
- ['doc', ''],
- ['extensions', ''],
- ['gems', ''],
- ]
-
- missing =
- Gem::REPOSITORY_SUBDIRECTORIES.sort -
- REPOSITORY_EXTENSION_MAP.map { |(k,_)| k }.sort
-
- raise "Update REPOSITORY_EXTENSION_MAP, missing: #{missing.join ', '}" unless
- missing.empty?
-
- ##
- # Creates a new Gem::Doctor that will clean up +gem_repository+. Only one
- # gem repository may be cleaned at a time.
- #
- # If +dry_run+ is true no files or directories will be removed.
-
- def initialize gem_repository, dry_run = false
- @gem_repository = gem_repository
- @dry_run = dry_run
-
- @installed_specs = nil
- end
-
- ##
- # Specs installed in this gem repository
-
- def installed_specs # :nodoc:
- @installed_specs ||= Gem::Specification.map { |s| s.full_name }
- end
-
- ##
- # Are we doctoring a gem repository?
-
- def gem_repository?
- not installed_specs.empty?
- end
-
- ##
- # Cleans up uninstalled files and invalid gem specifications
-
- def doctor
- @orig_home = Gem.dir
- @orig_path = Gem.path
-
- say "Checking #{@gem_repository}"
-
- Gem.use_paths @gem_repository.to_s
-
- unless gem_repository? then
- say 'This directory does not appear to be a RubyGems repository, ' +
- 'skipping'
- say
- return
- end
-
- doctor_children
-
- say
- ensure
- Gem.use_paths @orig_home, *@orig_path
- end
-
- ##
- # Cleans up children of this gem repository
-
- def doctor_children # :nodoc:
- REPOSITORY_EXTENSION_MAP.each do |sub_directory, extension|
- doctor_child sub_directory, extension
- end
- end
-
- ##
- # Removes files in +sub_directory+ with +extension+
-
- def doctor_child sub_directory, extension # :nodoc:
- directory = File.join(@gem_repository, sub_directory)
-
- Dir.entries(directory).sort.each do |ent|
- next if ent == "." || ent == ".."
-
- child = File.join(directory, ent)
- next unless File.exist?(child)
-
- basename = File.basename(child, extension)
- next if installed_specs.include? basename
- next if /^rubygems-\d/ =~ basename
- next if 'specifications' == sub_directory and 'default' == basename
-
- type = File.directory?(child) ? 'directory' : 'file'
-
- action = if @dry_run then
- 'Extra'
- else
- FileUtils.rm_r(child)
- 'Removed'
- end
-
- say "#{action} #{type} #{sub_directory}/#{File.basename(child)}"
- end
- rescue Errno::ENOENT
- # ignore
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/errors.rb b/ruby_2_2/lib/rubygems/errors.rb
deleted file mode 100644
index 9defb9ee9b..0000000000
--- a/ruby_2_2/lib/rubygems/errors.rb
+++ /dev/null
@@ -1,137 +0,0 @@
-#--
-# This file contains all the various exceptions and other errors that are used
-# inside of RubyGems.
-#
-# DOC: Confirm _all_
-#++
-
-module Gem
- ##
- # Raised when RubyGems is unable to load or activate a gem. Contains the
- # name and version requirements of the gem that either conflicts with
- # already activated gems or that RubyGems is otherwise unable to activate.
-
- class LoadError < ::LoadError
- # Name of gem
- attr_accessor :name
-
- # Version requirement of gem
- attr_accessor :requirement
- end
-
- # Raised when there are conflicting gem specs loaded
-
- class ConflictError < LoadError
-
- ##
- # A Hash mapping conflicting specifications to the dependencies that
- # caused the conflict
-
- attr_reader :conflicts
-
- ##
- # The specification that had the conflict
-
- attr_reader :target
-
- def initialize target, conflicts
- @target = target
- @conflicts = conflicts
- @name = target.name
-
- reason = conflicts.map { |act, dependencies|
- "#{act.full_name} conflicts with #{dependencies.join(", ")}"
- }.join ", "
-
- # TODO: improve message by saying who activated `con`
-
- super("Unable to activate #{target.full_name}, because #{reason}")
- end
- end
-
- class ErrorReason; end
-
- # Generated when trying to lookup a gem to indicate that the gem
- # was found, but that it isn't usable on the current platform.
- #
- # fetch and install read these and report them to the user to aid
- # in figuring out why a gem couldn't be installed.
- #
- class PlatformMismatch < ErrorReason
-
- ##
- # the name of the gem
- attr_reader :name
-
- ##
- # the version
- attr_reader :version
-
- ##
- # The platforms that are mismatched
- attr_reader :platforms
-
- def initialize(name, version)
- @name = name
- @version = version
- @platforms = []
- end
-
- ##
- # append a platform to the list of mismatched platforms.
- #
- # Platforms are added via this instead of injected via the constructor
- # so that we can loop over a list of mismatches and just add them rather
- # than perform some kind of calculation mismatch summary before creation.
- def add_platform(platform)
- @platforms << platform
- end
-
- ##
- # A wordy description of the error.
- def wordy
- "Found %s (%s), but was for platform%s %s" %
- [@name,
- @version,
- @platforms.size == 1 ? '' : 's',
- @platforms.join(' ,')]
- end
- end
-
- ##
- # An error that indicates we weren't able to fetch some
- # data from a source
-
- class SourceFetchProblem < ErrorReason
-
- ##
- # Creates a new SourceFetchProblem for the given +source+ and +error+.
-
- def initialize(source, error)
- @source = source
- @error = error
- end
-
- ##
- # The source that had the fetch problem.
-
- attr_reader :source
-
- ##
- # The fetch error which is an Exception subclass.
-
- attr_reader :error
-
- ##
- # An English description of the error.
-
- def wordy
- "Unable to download data from #{@source.uri} - #{@error.message}"
- end
-
- ##
- # The "exception" alias allows you to call raise on a SourceFetchProblem.
-
- alias exception error
- end
-end
diff --git a/ruby_2_2/lib/rubygems/exceptions.rb b/ruby_2_2/lib/rubygems/exceptions.rb
deleted file mode 100644
index 2a9875cd24..0000000000
--- a/ruby_2_2/lib/rubygems/exceptions.rb
+++ /dev/null
@@ -1,270 +0,0 @@
-# TODO: the documentation in here is terrible.
-#
-# Each exception needs a brief description and the scenarios where it is
-# likely to be raised
-
-##
-# Base exception class for RubyGems. All exception raised by RubyGems are a
-# subclass of this one.
-class Gem::Exception < RuntimeError
-
- ##
- #--
- # TODO: remove in RubyGems 3, nobody sets this
-
- attr_accessor :source_exception # :nodoc:
-
-end
-
-class Gem::CommandLineError < Gem::Exception; end
-
-class Gem::DependencyError < Gem::Exception; end
-
-class Gem::DependencyRemovalException < Gem::Exception; end
-
-##
-# Raised by Gem::Resolver when a Gem::Dependency::Conflict reaches the
-# toplevel. Indicates which dependencies were incompatible through #conflict
-# and #conflicting_dependencies
-
-class Gem::DependencyResolutionError < Gem::DependencyError
-
- attr_reader :conflict
-
- def initialize conflict
- @conflict = conflict
- a, b = conflicting_dependencies
-
- super "conflicting dependencies #{a} and #{b}\n#{@conflict.explanation}"
- end
-
- def conflicting_dependencies
- @conflict.conflicting_dependencies
- end
-
-end
-
-##
-# Raised when attempting to uninstall a gem that isn't in GEM_HOME.
-
-class Gem::GemNotInHomeException < Gem::Exception
- attr_accessor :spec
-end
-
-class Gem::DocumentError < Gem::Exception; end
-
-##
-# Potentially raised when a specification is validated.
-class Gem::EndOfYAMLException < Gem::Exception; end
-
-##
-# Signals that a file permission error is preventing the user from
-# operating on the given directory.
-
-class Gem::FilePermissionError < Gem::Exception
-
- attr_reader :directory
-
- def initialize directory
- @directory = directory
-
- super "You don't have write permissions for the #{directory} directory."
- end
-
-end
-
-##
-# Used to raise parsing and loading errors
-class Gem::FormatException < Gem::Exception
- attr_accessor :file_path
-end
-
-class Gem::GemNotFoundException < Gem::Exception; end
-
-##
-# Raised by the DependencyInstaller when a specific gem cannot be found
-
-class Gem::SpecificGemNotFoundException < Gem::GemNotFoundException
-
- ##
- # Creates a new SpecificGemNotFoundException for a gem with the given +name+
- # and +version+. Any +errors+ encountered when attempting to find the gem
- # are also stored.
-
- def initialize(name, version, errors=nil)
- super "Could not find a valid gem '#{name}' (#{version}) locally or in a repository"
-
- @name = name
- @version = version
- @errors = errors
- end
-
- ##
- # The name of the gem that could not be found.
-
- attr_reader :name
-
- ##
- # The version of the gem that could not be found.
-
- attr_reader :version
-
- ##
- # Errors encountered attempting to find the gem.
-
- attr_reader :errors
-
-end
-
-##
-# Raised by Gem::Resolver when dependencies conflict and create the
-# inability to find a valid possible spec for a request.
-
-class Gem::ImpossibleDependenciesError < Gem::Exception
-
- attr_reader :conflicts
- attr_reader :request
-
- def initialize request, conflicts
- @request = request
- @conflicts = conflicts
-
- super build_message
- end
-
- def build_message # :nodoc:
- requester = @request.requester
- requester = requester ? requester.spec.full_name : 'The user'
- dependency = @request.dependency
-
- message = "#{requester} requires #{dependency} but it conflicted:\n"
-
- @conflicts.each do |_, conflict|
- message << conflict.explanation
- end
-
- message
- end
-
- def dependency
- @request.dependency
- end
-
-end
-
-class Gem::InstallError < Gem::Exception; end
-
-##
-# Potentially raised when a specification is validated.
-class Gem::InvalidSpecificationException < Gem::Exception; end
-
-class Gem::OperationNotSupportedError < Gem::Exception; end
-
-##
-# Signals that a remote operation cannot be conducted, probably due to not
-# being connected (or just not finding host).
-#--
-# TODO: create a method that tests connection to the preferred gems server.
-# All code dealing with remote operations will want this. Failure in that
-# method should raise this error.
-class Gem::RemoteError < Gem::Exception; end
-
-class Gem::RemoteInstallationCancelled < Gem::Exception; end
-
-class Gem::RemoteInstallationSkipped < Gem::Exception; end
-
-##
-# Represents an error communicating via HTTP.
-class Gem::RemoteSourceException < Gem::Exception; end
-
-##
-# Raised when a gem dependencies file specifies a ruby version that does not
-# match the current version.
-
-class Gem::RubyVersionMismatch < Gem::Exception; end
-
-##
-# Raised by Gem::Validator when something is not right in a gem.
-
-class Gem::VerificationError < Gem::Exception; end
-
-##
-# Raised to indicate that a system exit should occur with the specified
-# exit_code
-
-class Gem::SystemExitException < SystemExit
-
- ##
- # The exit code for the process
-
- attr_accessor :exit_code
-
- ##
- # Creates a new SystemExitException with the given +exit_code+
-
- def initialize(exit_code)
- @exit_code = exit_code
-
- super "Exiting RubyGems with exit_code #{exit_code}"
- end
-
-end
-
-##
-# Raised by Resolver when a dependency requests a gem for which
-# there is no spec.
-
-class Gem::UnsatisfiableDependencyError < Gem::DependencyError
-
- ##
- # The unsatisfiable dependency. This is a
- # Gem::Resolver::DependencyRequest, not a Gem::Dependency
-
- attr_reader :dependency
-
- ##
- # Errors encountered which may have contributed to this exception
-
- attr_accessor :errors
-
- ##
- # Creates a new UnsatisfiableDependencyError for the unsatisfiable
- # Gem::Resolver::DependencyRequest +dep+
-
- def initialize dep, platform_mismatch=nil
- if platform_mismatch and !platform_mismatch.empty?
- plats = platform_mismatch.map { |x| x.platform.to_s }.sort.uniq
- super "Unable to resolve dependency: No match for '#{dep}' on this platform. Found: #{plats.join(', ')}"
- else
- if dep.explicit?
- super "Unable to resolve dependency: user requested '#{dep}'"
- else
- super "Unable to resolve dependency: '#{dep.request_context}' requires '#{dep}'"
- end
- end
-
- @dependency = dep
- @errors = []
- end
-
- ##
- # The name of the unresolved dependency
-
- def name
- @dependency.name
- end
-
- ##
- # The Requirement of the unresolved dependency (not Version).
-
- def version
- @dependency.requirement
- end
-
-end
-
-##
-# Backwards compatible typo'd exception class for early RubyGems 2.0.x
-
-Gem::UnsatisfiableDepedencyError = Gem::UnsatisfiableDependencyError # :nodoc:
-
diff --git a/ruby_2_2/lib/rubygems/ext.rb b/ruby_2_2/lib/rubygems/ext.rb
deleted file mode 100644
index 5af6bbf39e..0000000000
--- a/ruby_2_2/lib/rubygems/ext.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-##
-# Classes for building C extensions live here.
-
-module Gem::Ext; end
-
-require 'rubygems/ext/build_error'
-require 'rubygems/ext/builder'
-require 'rubygems/ext/configure_builder'
-require 'rubygems/ext/ext_conf_builder'
-require 'rubygems/ext/rake_builder'
-require 'rubygems/ext/cmake_builder'
-
diff --git a/ruby_2_2/lib/rubygems/ext/build_error.rb b/ruby_2_2/lib/rubygems/ext/build_error.rb
deleted file mode 100644
index bfe85ffc11..0000000000
--- a/ruby_2_2/lib/rubygems/ext/build_error.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-##
-# Raised when there is an error while building extensions.
-
-class Gem::Ext::BuildError < Gem::InstallError
-end
-
diff --git a/ruby_2_2/lib/rubygems/ext/builder.rb b/ruby_2_2/lib/rubygems/ext/builder.rb
deleted file mode 100644
index 548f1262a8..0000000000
--- a/ruby_2_2/lib/rubygems/ext/builder.rb
+++ /dev/null
@@ -1,218 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'rubygems/user_interaction'
-require 'thread'
-
-class Gem::Ext::Builder
-
- include Gem::UserInteraction
-
- ##
- # The builder shells-out to run various commands after changing the
- # directory. This means multiple installations cannot be allowed to build
- # extensions in parallel as they may change each other's directories leading
- # to broken extensions or failed installations.
-
- CHDIR_MUTEX = Mutex.new # :nodoc:
-
- attr_accessor :build_args # :nodoc:
-
- def self.class_name
- name =~ /Ext::(.*)Builder/
- $1.downcase
- end
-
- def self.make(dest_path, results)
- unless File.exist? 'Makefile' then
- raise Gem::InstallError, 'Makefile not found'
- end
-
- # try to find make program from Ruby configure arguments first
- RbConfig::CONFIG['configure_args'] =~ /with-make-prog\=(\w+)/
- make_program = ENV['MAKE'] || ENV['make'] || $1
- unless make_program then
- make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
- end
-
- destdir = '"DESTDIR=%s"' % ENV['DESTDIR'] if RUBY_VERSION > '2.0'
-
- ['clean', '', 'install'].each do |target|
- # Pass DESTDIR via command line to override what's in MAKEFLAGS
- cmd = [
- make_program,
- destdir,
- target
- ].join(' ').rstrip
- begin
- run(cmd, results, "make #{target}".rstrip)
- rescue Gem::InstallError
- raise unless target == 'clean' # ignore clean failure
- end
- end
- end
-
- def self.redirector
- '2>&1'
- end
-
- def self.run(command, results, command_name = nil)
- verbose = Gem.configuration.really_verbose
-
- begin
- # TODO use Process.spawn when ruby 1.8 support is dropped.
- rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], nil
- if verbose
- puts(command)
- system(command)
- else
- results << command
- results << `#{command} #{redirector}`
- end
- ensure
- ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
- end
-
- unless $?.success? then
- results << "Building has failed. See above output for more information on the failure." if verbose
-
- exit_reason =
- if $?.exited? then
- ", exit code #{$?.exitstatus}"
- elsif $?.signaled? then
- ", uncaught signal #{$?.termsig}"
- end
-
- raise Gem::InstallError, "#{command_name || class_name} failed#{exit_reason}"
- end
- end
-
- ##
- # Creates a new extension builder for +spec+. If the +spec+ does not yet
- # have build arguments, saved, set +build_args+ which is an ARGV-style
- # array.
-
- def initialize spec, build_args = spec.build_args
- @spec = spec
- @build_args = build_args
- @gem_dir = spec.full_gem_path
-
- @ran_rake = nil
- end
-
- ##
- # Chooses the extension builder class for +extension+
-
- def builder_for extension # :nodoc:
- case extension
- when /extconf/ then
- Gem::Ext::ExtConfBuilder
- when /configure/ then
- Gem::Ext::ConfigureBuilder
- when /rakefile/i, /mkrf_conf/i then
- @ran_rake = true
- Gem::Ext::RakeBuilder
- when /CMakeLists.txt/ then
- Gem::Ext::CmakeBuilder
- else
- extension_dir = File.join @gem_dir, File.dirname(extension)
-
- message = "No builder for extension '#{extension}'"
- build_error extension_dir, message
- end
- end
-
- ##
- # Logs the build +output+ in +build_dir+, then raises Gem::Ext::BuildError.
-
- def build_error build_dir, output, backtrace = nil # :nodoc:
- gem_make_out = write_gem_make_out output
-
- message = <<-EOF
-ERROR: Failed to build gem native extension.
-
- #{output}
-
-Gem files will remain installed in #{@gem_dir} for inspection.
-Results logged to #{gem_make_out}
-EOF
-
- raise Gem::Ext::BuildError, message, backtrace
- end
-
- def build_extension extension, dest_path # :nodoc:
- results = []
-
- extension ||= '' # I wish I knew why this line existed
- extension_dir =
- File.expand_path File.join @gem_dir, File.dirname(extension)
- lib_dir = File.join @spec.full_gem_path, @spec.raw_require_paths.first
-
- builder = builder_for extension
-
- begin
- FileUtils.mkdir_p dest_path
-
- CHDIR_MUTEX.synchronize do
- Dir.chdir extension_dir do
- results = builder.build(extension, @gem_dir, dest_path,
- results, @build_args, lib_dir)
-
- verbose { results.join("\n") }
- end
- end
-
- write_gem_make_out results.join "\n"
- rescue => e
- results << e.message
- build_error extension_dir, results.join("\n"), $@
- end
- end
-
- ##
- # Builds extensions. Valid types of extensions are extconf.rb files,
- # configure scripts and rakefiles or mkrf_conf files.
-
- def build_extensions
- return if @spec.extensions.empty?
-
- if @build_args.empty?
- say "Building native extensions. This could take a while..."
- else
- say "Building native extensions with: '#{@build_args.join ' '}'"
- say "This could take a while..."
- end
-
- dest_path = @spec.extension_dir
-
- FileUtils.rm_f @spec.gem_build_complete_path
-
- @ran_rake = false # only run rake once
-
- @spec.extensions.each do |extension|
- break if @ran_rake
-
- build_extension extension, dest_path
- end
-
- FileUtils.touch @spec.gem_build_complete_path
- end
-
- ##
- # Writes +output+ to gem_make.out in the extension install directory.
-
- def write_gem_make_out output # :nodoc:
- destination = File.join @spec.extension_dir, 'gem_make.out'
-
- FileUtils.mkdir_p @spec.extension_dir
-
- open destination, 'wb' do |io| io.puts output end
-
- destination
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/ext/cmake_builder.rb b/ruby_2_2/lib/rubygems/ext/cmake_builder.rb
deleted file mode 100644
index 24531bc75c..0000000000
--- a/ruby_2_2/lib/rubygems/ext/cmake_builder.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-require 'rubygems/command'
-
-class Gem::Ext::CmakeBuilder < Gem::Ext::Builder
- def self.build(extension, directory, dest_path, results, args=[], lib_dir=nil)
- unless File.exist?('Makefile') then
- cmd = "cmake . -DCMAKE_INSTALL_PREFIX=#{dest_path}"
- cmd << " #{Gem::Command.build_args.join ' '}" unless Gem::Command.build_args.empty?
-
- run cmd, results
- end
-
- make dest_path, results
-
- results
- end
-end
diff --git a/ruby_2_2/lib/rubygems/ext/configure_builder.rb b/ruby_2_2/lib/rubygems/ext/configure_builder.rb
deleted file mode 100644
index f66e39387a..0000000000
--- a/ruby_2_2/lib/rubygems/ext/configure_builder.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-class Gem::Ext::ConfigureBuilder < Gem::Ext::Builder
-
- def self.build(extension, directory, dest_path, results, args=[], lib_dir=nil)
- unless File.exist?('Makefile') then
- cmd = "sh ./configure --prefix=#{dest_path}"
- cmd << " #{args.join ' '}" unless args.empty?
-
- run cmd, results
- end
-
- make dest_path, results
-
- results
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/ext/ext_conf_builder.rb b/ruby_2_2/lib/rubygems/ext/ext_conf_builder.rb
deleted file mode 100644
index d11d1ac328..0000000000
--- a/ruby_2_2/lib/rubygems/ext/ext_conf_builder.rb
+++ /dev/null
@@ -1,78 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'fileutils'
-require 'tempfile'
-
-class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
- FileEntry = FileUtils::Entry_ # :nodoc:
-
- def self.build(extension, directory, dest_path, results, args=[], lib_dir=nil)
- # relative path required as some versions of mktmpdir return an absolute
- # path which breaks make if it includes a space in the name
- tmp_dest = get_relative_path(Dir.mktmpdir(".gem.", "."))
-
- t = nil
- Tempfile.open %w"siteconf .rb", "." do |siteconf|
- t = siteconf
- siteconf.puts "require 'rbconfig'"
- siteconf.puts "dest_path = #{tmp_dest.dump}"
- %w[sitearchdir sitelibdir].each do |dir|
- siteconf.puts "RbConfig::MAKEFILE_CONFIG['#{dir}'] = dest_path"
- siteconf.puts "RbConfig::CONFIG['#{dir}'] = dest_path"
- end
-
- siteconf.flush
-
- destdir = ENV["DESTDIR"]
-
- begin
- cmd = [Gem.ruby, "-r", get_relative_path(siteconf.path), File.basename(extension), *args].join ' '
-
- begin
- run cmd, results
- ensure
- FileUtils.mv 'mkmf.log', dest_path if File.exist? 'mkmf.log'
- siteconf.unlink
- end
-
- ENV["DESTDIR"] = nil
-
- make dest_path, results
-
- if tmp_dest
- # TODO remove in RubyGems 3
- if Gem.install_extension_in_lib and lib_dir then
- FileUtils.mkdir_p lib_dir
- entries = Dir.entries(tmp_dest) - %w[. ..]
- entries = entries.map { |entry| File.join tmp_dest, entry }
- FileUtils.cp_r entries, lib_dir, :remove_destination => true
- end
-
- FileEntry.new(tmp_dest).traverse do |ent|
- destent = ent.class.new(dest_path, ent.rel)
- destent.exist? or FileUtils.mv(ent.path, destent.path)
- end
- end
- ensure
- ENV["DESTDIR"] = destdir
- end
- end
- t.unlink if t and t.path
-
- results
- ensure
- FileUtils.rm_rf tmp_dest if tmp_dest
- end
-
- private
- def self.get_relative_path(path)
- path[0..Dir.pwd.length-1] = '.' if path.start_with?(Dir.pwd)
- path
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/ext/rake_builder.rb b/ruby_2_2/lib/rubygems/ext/rake_builder.rb
deleted file mode 100644
index d5ebf597ae..0000000000
--- a/ruby_2_2/lib/rubygems/ext/rake_builder.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-class Gem::Ext::RakeBuilder < Gem::Ext::Builder
-
- def self.build(extension, directory, dest_path, results, args=[], lib_dir=nil)
- if File.basename(extension) =~ /mkrf_conf/i then
- cmd = "#{Gem.ruby} #{File.basename extension}"
- cmd << " #{args.join " "}" unless args.empty?
- run cmd, results
- end
-
- # Deal with possible spaces in the path, e.g. C:/Program Files
- dest_path = '"' + dest_path.to_s + '"' if dest_path.to_s.include?(' ')
-
- rake = ENV['rake']
-
- rake ||= begin
- "#{Gem.ruby} -rubygems #{Gem.bin_path('rake', 'rake')}"
- rescue Gem::Exception
- end
-
- rake ||= Gem.default_exec_format % 'rake'
-
- cmd = "#{rake} RUBYARCHDIR=#{dest_path} RUBYLIBDIR=#{dest_path}" # ENV is frozen
-
- run cmd, results
-
- results
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/gem_runner.rb b/ruby_2_2/lib/rubygems/gem_runner.rb
deleted file mode 100644
index 7a3fd6b116..0000000000
--- a/ruby_2_2/lib/rubygems/gem_runner.rb
+++ /dev/null
@@ -1,81 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'rubygems'
-require 'rubygems/command_manager'
-require 'rubygems/config_file'
-
-##
-# Load additional plugins from $LOAD_PATH
-
-Gem.load_env_plugins rescue nil
-
-##
-# Run an instance of the gem program.
-#
-# Gem::GemRunner is only intended for internal use by RubyGems itself. It
-# does not form any public API and may change at any time for any reason.
-#
-# If you would like to duplicate functionality of `gem` commands, use the
-# classes they call directly.
-
-class Gem::GemRunner
-
- def initialize(options={})
- # TODO: nuke these options
- @command_manager_class = options[:command_manager] || Gem::CommandManager
- @config_file_class = options[:config_file] || Gem::ConfigFile
- end
-
- ##
- # Run the gem command with the following arguments.
-
- def run args
- build_args = extract_build_args args
-
- do_configuration args
-
- cmd = @command_manager_class.instance
-
- cmd.command_names.each do |command_name|
- config_args = Gem.configuration[command_name]
- config_args = case config_args
- when String
- config_args.split ' '
- else
- Array(config_args)
- end
- Gem::Command.add_specific_extra_args command_name, config_args
- end
-
- cmd.run Gem.configuration.args, build_args
- end
-
- ##
- # Separates the build arguments (those following <code>--</code>) from the
- # other arguments in the list.
-
- def extract_build_args args # :nodoc:
- return [] unless offset = args.index('--')
-
- build_args = args.slice!(offset...args.length)
-
- build_args.shift
-
- build_args
- end
-
- private
-
- def do_configuration(args)
- Gem.configuration = @config_file_class.new(args)
- Gem.use_paths Gem.configuration[:gemhome], Gem.configuration[:gempath]
- Gem::Command.extra_args = Gem.configuration[:gem]
- end
-
-end
-
-Gem.load_plugins
diff --git a/ruby_2_2/lib/rubygems/gemcutter_utilities.rb b/ruby_2_2/lib/rubygems/gemcutter_utilities.rb
deleted file mode 100644
index 4ecf7376e0..0000000000
--- a/ruby_2_2/lib/rubygems/gemcutter_utilities.rb
+++ /dev/null
@@ -1,154 +0,0 @@
-require 'rubygems/remote_fetcher'
-
-##
-# Utility methods for using the RubyGems API.
-
-module Gem::GemcutterUtilities
-
- # TODO: move to Gem::Command
- OptionParser.accept Symbol do |value|
- value.to_sym
- end
-
- attr_writer :host
-
- ##
- # Add the --key option
-
- def add_key_option
- add_option('-k', '--key KEYNAME', Symbol,
- 'Use the given API key',
- 'from ~/.gem/credentials') do |value,options|
- options[:key] = value
- end
- end
-
- ##
- # The API key from the command options or from the user's configuration.
-
- def api_key
- if options[:key] then
- verify_api_key options[:key]
- elsif Gem.configuration.api_keys.key?(host)
- Gem.configuration.api_keys[host]
- else
- Gem.configuration.rubygems_api_key
- end
- end
-
- ##
- # The host to connect to either from the RUBYGEMS_HOST environment variable
- # or from the user's configuration
-
- def host
- configured_host = Gem.host unless
- Gem.configuration.disable_default_gem_server
-
- @host ||=
- begin
- env_rubygems_host = ENV['RUBYGEMS_HOST']
- env_rubygems_host = nil if
- env_rubygems_host and env_rubygems_host.empty?
-
- env_rubygems_host|| configured_host
- end
- end
-
- ##
- # Creates an RubyGems API to +host+ and +path+ with the given HTTP +method+.
- #
- # If +allowed_push_host+ metadata is present, then it will only allow that host.
-
- def rubygems_api_request(method, path, host = nil, allowed_push_host = nil, &block)
- require 'net/http'
-
- self.host = host if host
- unless self.host
- alert_error "You must specify a gem server"
- terminate_interaction 1 # TODO: question this
- end
-
- if allowed_push_host and self.host != allowed_push_host
- alert_error "#{self.host.inspect} is not allowed by the gemspec, which only allows #{allowed_push_host.inspect}"
- terminate_interaction 1
- end
-
- uri = URI.parse "#{self.host}/#{path}"
-
- request_method = Net::HTTP.const_get method.to_s.capitalize
-
- Gem::RemoteFetcher.fetcher.request(uri, request_method, &block)
- end
-
- ##
- # Signs in with the RubyGems API at +sign_in_host+ and sets the rubygems API
- # key.
-
- def sign_in sign_in_host = nil
- sign_in_host ||= self.host
- return if api_key
-
- pretty_host = if Gem::DEFAULT_HOST == sign_in_host then
- 'RubyGems.org'
- else
- sign_in_host
- end
-
- say "Enter your #{pretty_host} credentials."
- say "Don't have an account yet? " +
- "Create one at #{sign_in_host}/sign_up"
-
- email = ask " Email: "
- password = ask_for_password "Password: "
- say "\n"
-
- response = rubygems_api_request(:get, "api/v1/api_key",
- sign_in_host) do |request|
- request.basic_auth email, password
- end
-
- with_response response do |resp|
- say "Signed in."
- Gem.configuration.rubygems_api_key = resp.body
- end
- end
-
- ##
- # Retrieves the pre-configured API key +key+ or terminates interaction with
- # an error.
-
- def verify_api_key(key)
- if Gem.configuration.api_keys.key? key then
- Gem.configuration.api_keys[key]
- else
- alert_error "No such API key. Please add it to your configuration (done automatically on initial `gem push`)."
- terminate_interaction 1 # TODO: question this
- end
- end
-
- ##
- # If +response+ is an HTTP Success (2XX) response, yields the response if a
- # block was given or shows the response body to the user.
- #
- # If the response was not successful, shows an error to the user including
- # the +error_prefix+ and the response body.
-
- def with_response response, error_prefix = nil
- case response
- when Net::HTTPSuccess then
- if block_given? then
- yield response
- else
- say response.body
- end
- else
- message = response.body
- message = "#{error_prefix}: #{message}" if error_prefix
-
- say message
- terminate_interaction 1 # TODO: question this
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/indexer.rb b/ruby_2_2/lib/rubygems/indexer.rb
deleted file mode 100644
index f94fb1bcb8..0000000000
--- a/ruby_2_2/lib/rubygems/indexer.rb
+++ /dev/null
@@ -1,498 +0,0 @@
-require 'rubygems'
-require 'rubygems/package'
-require 'time'
-
-begin
- gem 'builder'
- require 'builder/xchar'
-rescue LoadError
-end
-
-##
-# Top level class for building the gem repository index.
-
-class Gem::Indexer
-
- include Gem::UserInteraction
-
- ##
- # Build indexes for RubyGems 1.2.0 and newer when true
-
- attr_accessor :build_modern
-
- ##
- # Index install location
-
- attr_reader :dest_directory
-
- ##
- # Specs index install location
-
- attr_reader :dest_specs_index
-
- ##
- # Latest specs index install location
-
- attr_reader :dest_latest_specs_index
-
- ##
- # Prerelease specs index install location
-
- attr_reader :dest_prerelease_specs_index
-
- ##
- # Index build directory
-
- attr_reader :directory
-
- ##
- # Create an indexer that will index the gems in +directory+.
-
- def initialize(directory, options = {})
- require 'fileutils'
- require 'tmpdir'
- require 'zlib'
-
- unless defined?(Builder::XChar) then
- raise "Gem::Indexer requires that the XML Builder library be installed:" +
- "\n\tgem install builder"
- end
-
- options = { :build_modern => true }.merge options
-
- @build_modern = options[:build_modern]
-
- @dest_directory = directory
- @directory = File.join(Dir.tmpdir, "gem_generate_index_#{$$}")
-
- marshal_name = "Marshal.#{Gem.marshal_version}"
-
- @master_index = File.join @directory, 'yaml'
- @marshal_index = File.join @directory, marshal_name
-
- @quick_dir = File.join @directory, 'quick'
- @quick_marshal_dir = File.join @quick_dir, marshal_name
- @quick_marshal_dir_base = File.join "quick", marshal_name # FIX: UGH
-
- @quick_index = File.join @quick_dir, 'index'
- @latest_index = File.join @quick_dir, 'latest_index'
-
- @specs_index = File.join @directory, "specs.#{Gem.marshal_version}"
- @latest_specs_index =
- File.join(@directory, "latest_specs.#{Gem.marshal_version}")
- @prerelease_specs_index =
- File.join(@directory, "prerelease_specs.#{Gem.marshal_version}")
- @dest_specs_index =
- File.join(@dest_directory, "specs.#{Gem.marshal_version}")
- @dest_latest_specs_index =
- File.join(@dest_directory, "latest_specs.#{Gem.marshal_version}")
- @dest_prerelease_specs_index =
- File.join(@dest_directory, "prerelease_specs.#{Gem.marshal_version}")
-
- @files = []
- end
-
- ##
- # Abbreviate the spec for downloading. Abbreviated specs are only used for
- # searching, downloading and related activities and do not need deployment
- # specific information (e.g. list of files). So we abbreviate the spec,
- # making it much smaller for quicker downloads.
- #--
- # TODO move to Gem::Specification
-
- def abbreviate(spec)
- spec.files = []
- spec.test_files = []
- spec.rdoc_options = []
- spec.extra_rdoc_files = []
- spec.cert_chain = []
- spec
- end
-
- ##
- # Build various indicies
-
- def build_indicies
- Gem::Specification.dirs = []
- Gem::Specification.add_specs(*map_gems_to_specs(gem_file_list))
-
- build_marshal_gemspecs
- build_modern_indicies if @build_modern
-
- compress_indicies
- end
-
- ##
- # Builds Marshal quick index gemspecs.
-
- def build_marshal_gemspecs
- count = Gem::Specification.count { |s| not s.default_gem? }
- progress = ui.progress_reporter count,
- "Generating Marshal quick index gemspecs for #{count} gems",
- "Complete"
-
- files = []
-
- Gem.time 'Generated Marshal quick index gemspecs' do
- Gem::Specification.each do |spec|
- next if spec.default_gem?
- spec_file_name = "#{spec.original_name}.gemspec.rz"
- marshal_name = File.join @quick_marshal_dir, spec_file_name
-
- marshal_zipped = Gem.deflate Marshal.dump(spec)
- open marshal_name, 'wb' do |io| io.write marshal_zipped end
-
- files << marshal_name
-
- progress.updated spec.original_name
- end
-
- progress.done
- end
-
- @files << @quick_marshal_dir
-
- files
- end
-
- ##
- # Build a single index for RubyGems 1.2 and newer
-
- def build_modern_index(index, file, name)
- say "Generating #{name} index"
-
- Gem.time "Generated #{name} index" do
- open(file, 'wb') do |io|
- specs = index.map do |*spec|
- # We have to splat here because latest_specs is an array, while the
- # others are hashes.
- spec = spec.flatten.last
- platform = spec.original_platform
-
- # win32-api-1.0.4-x86-mswin32-60
- unless String === platform then
- alert_warning "Skipping invalid platform in gem: #{spec.full_name}"
- next
- end
-
- platform = Gem::Platform::RUBY if platform.nil? or platform.empty?
- [spec.name, spec.version, platform]
- end
-
- specs = compact_specs(specs)
- Marshal.dump(specs, io)
- end
- end
- end
-
- ##
- # Builds indicies for RubyGems 1.2 and newer. Handles full, latest, prerelease
-
- def build_modern_indicies
- specs = Gem::Specification.reject { |s| s.default_gem? }
-
- prerelease, released = specs.partition { |s|
- s.version.prerelease?
- }
- latest_specs =
- Gem::Specification.latest_specs.reject { |s| s.default_gem? }
-
- build_modern_index(released.sort, @specs_index, 'specs')
- build_modern_index(latest_specs.sort, @latest_specs_index, 'latest specs')
- build_modern_index(prerelease.sort, @prerelease_specs_index,
- 'prerelease specs')
-
- @files += [@specs_index,
- "#{@specs_index}.gz",
- @latest_specs_index,
- "#{@latest_specs_index}.gz",
- @prerelease_specs_index,
- "#{@prerelease_specs_index}.gz"]
- end
-
- def map_gems_to_specs gems
- gems.map { |gemfile|
- if File.size(gemfile) == 0 then
- alert_warning "Skipping zero-length gem: #{gemfile}"
- next
- end
-
- begin
- spec = Gem::Package.new(gemfile).spec
- spec.loaded_from = gemfile
-
- # HACK: fuck this shit - borks all tests that use pl1
- # if File.basename(gemfile, ".gem") != spec.original_name then
- # exp = spec.full_name
- # exp << " (#{spec.original_name})" if
- # spec.original_name != spec.full_name
- # msg = "Skipping misnamed gem: #{gemfile} should be named #{exp}"
- # alert_warning msg
- # next
- # end
-
- abbreviate spec
- sanitize spec
-
- spec
- rescue SignalException
- alert_error "Received signal, exiting"
- raise
- rescue Exception => e
- msg = ["Unable to process #{gemfile}",
- "#{e.message} (#{e.class})",
- "\t#{e.backtrace.join "\n\t"}"].join("\n")
- alert_error msg
- end
- }.compact
- end
-
- ##
- # Compresses indicies on disk
- #--
- # All future files should be compressed using gzip, not deflate
-
- def compress_indicies
- say "Compressing indicies"
-
- Gem.time 'Compressed indicies' do
- if @build_modern then
- gzip @specs_index
- gzip @latest_specs_index
- gzip @prerelease_specs_index
- end
- end
- end
-
- ##
- # Compacts Marshal output for the specs index data source by using identical
- # objects as much as possible.
-
- def compact_specs(specs)
- names = {}
- versions = {}
- platforms = {}
-
- specs.map do |(name, version, platform)|
- names[name] = name unless names.include? name
- versions[version] = version unless versions.include? version
- platforms[platform] = platform unless platforms.include? platform
-
- [names[name], versions[version], platforms[platform]]
- end
- end
-
- ##
- # Compress +filename+ with +extension+.
-
- def compress(filename, extension)
- data = Gem.read_binary filename
-
- zipped = Gem.deflate data
-
- open "#{filename}.#{extension}", 'wb' do |io|
- io.write zipped
- end
- end
-
- ##
- # List of gem file names to index.
-
- def gem_file_list
- Dir[File.join(@dest_directory, "gems", '*.gem')]
- end
-
- ##
- # Builds and installs indicies.
-
- def generate_index
- make_temp_directories
- build_indicies
- install_indicies
- rescue SignalException
- ensure
- FileUtils.rm_rf @directory
- end
-
- ##
- # Zlib::GzipWriter wrapper that gzips +filename+ on disk.
-
- def gzip(filename)
- Zlib::GzipWriter.open "#{filename}.gz" do |io|
- io.write Gem.read_binary(filename)
- end
- end
-
- ##
- # Install generated indicies into the destination directory.
-
- def install_indicies
- verbose = Gem.configuration.really_verbose
-
- say "Moving index into production dir #{@dest_directory}" if verbose
-
- files = @files
- files.delete @quick_marshal_dir if files.include? @quick_dir
-
- if files.include? @quick_marshal_dir and not files.include? @quick_dir then
- files.delete @quick_marshal_dir
-
- dst_name = File.join(@dest_directory, @quick_marshal_dir_base)
-
- FileUtils.mkdir_p File.dirname(dst_name), :verbose => verbose
- FileUtils.rm_rf dst_name, :verbose => verbose
- FileUtils.mv(@quick_marshal_dir, dst_name,
- :verbose => verbose, :force => true)
- end
-
- files = files.map do |path|
- path.sub(/^#{Regexp.escape @directory}\/?/, '') # HACK?
- end
-
- files.each do |file|
- src_name = File.join @directory, file
- dst_name = File.join @dest_directory, file
-
- FileUtils.rm_rf dst_name, :verbose => verbose
- FileUtils.mv(src_name, @dest_directory,
- :verbose => verbose, :force => true)
- end
- end
-
- ##
- # Make directories for index generation
-
- def make_temp_directories
- FileUtils.rm_rf @directory
- FileUtils.mkdir_p @directory, :mode => 0700
- FileUtils.mkdir_p @quick_marshal_dir
- end
-
- ##
- # Ensure +path+ and path with +extension+ are identical.
-
- def paranoid(path, extension)
- data = Gem.read_binary path
- compressed_data = Gem.read_binary "#{path}.#{extension}"
-
- unless data == Gem.inflate(compressed_data) then
- raise "Compressed file #{compressed_path} does not match uncompressed file #{path}"
- end
- end
-
- ##
- # Sanitize the descriptive fields in the spec. Sometimes non-ASCII
- # characters will garble the site index. Non-ASCII characters will
- # be replaced by their XML entity equivalent.
-
- def sanitize(spec)
- spec.summary = sanitize_string(spec.summary)
- spec.description = sanitize_string(spec.description)
- spec.post_install_message = sanitize_string(spec.post_install_message)
- spec.authors = spec.authors.collect { |a| sanitize_string(a) }
-
- spec
- end
-
- ##
- # Sanitize a single string.
-
- def sanitize_string(string)
- return string unless string
-
- # HACK the #to_s is in here because RSpec has an Array of Arrays of
- # Strings for authors. Need a way to disallow bad values on gemspec
- # generation. (Probably won't happen.)
- string = string.to_s
-
- begin
- Builder::XChar.encode string
- rescue NameError, NoMethodError
- string.to_xs
- end
- end
-
- ##
- # Perform an in-place update of the repository from newly added gems.
-
- def update_index
- make_temp_directories
-
- specs_mtime = File.stat(@dest_specs_index).mtime
- newest_mtime = Time.at 0
-
- updated_gems = gem_file_list.select do |gem|
- gem_mtime = File.stat(gem).mtime
- newest_mtime = gem_mtime if gem_mtime > newest_mtime
- gem_mtime >= specs_mtime
- end
-
- if updated_gems.empty? then
- say 'No new gems'
- terminate_interaction 0
- end
-
- specs = map_gems_to_specs updated_gems
- prerelease, released = specs.partition { |s| s.version.prerelease? }
-
- Gem::Specification.dirs = []
- Gem::Specification.add_specs(*specs)
-
- files = build_marshal_gemspecs
-
- Gem.time 'Updated indexes' do
- update_specs_index released, @dest_specs_index, @specs_index
- update_specs_index released, @dest_latest_specs_index, @latest_specs_index
- update_specs_index(prerelease,
- @dest_prerelease_specs_index,
- @prerelease_specs_index)
- end
-
- compress_indicies
-
- verbose = Gem.configuration.really_verbose
-
- say "Updating production dir #{@dest_directory}" if verbose
-
- files << @specs_index
- files << "#{@specs_index}.gz"
- files << @latest_specs_index
- files << "#{@latest_specs_index}.gz"
- files << @prerelease_specs_index
- files << "#{@prerelease_specs_index}.gz"
-
- files = files.map do |path|
- path.sub(/^#{Regexp.escape @directory}\/?/, '') # HACK?
- end
-
- files.each do |file|
- src_name = File.join @directory, file
- dst_name = File.join @dest_directory, file # REFACTOR: duped above
-
- FileUtils.mv src_name, dst_name, :verbose => verbose,
- :force => true
-
- File.utime newest_mtime, newest_mtime, dst_name
- end
- end
-
- ##
- # Combines specs in +index+ and +source+ then writes out a new copy to
- # +dest+. For a latest index, does not ensure the new file is minimal.
-
- def update_specs_index(index, source, dest)
- specs_index = Marshal.load Gem.read_binary(source)
-
- index.each do |spec|
- platform = spec.original_platform
- platform = Gem::Platform::RUBY if platform.nil? or platform.empty?
- specs_index << [spec.name, spec.version, platform]
- end
-
- specs_index = compact_specs specs_index.uniq.sort
-
- open dest, 'wb' do |io|
- Marshal.dump specs_index, io
- end
- end
-end
diff --git a/ruby_2_2/lib/rubygems/install_default_message.rb b/ruby_2_2/lib/rubygems/install_default_message.rb
deleted file mode 100644
index 458ba3da96..0000000000
--- a/ruby_2_2/lib/rubygems/install_default_message.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require 'rubygems'
-require 'rubygems/user_interaction'
-
-##
-# A post-install hook that displays "Successfully installed
-# some_gem-1.0 as a default gem"
-
-Gem.post_install do |installer|
- ui = Gem::DefaultUserInteraction.ui
- ui.say "Successfully installed #{installer.spec.full_name} as a default gem"
-end
-
diff --git a/ruby_2_2/lib/rubygems/install_message.rb b/ruby_2_2/lib/rubygems/install_message.rb
deleted file mode 100644
index c1979c1549..0000000000
--- a/ruby_2_2/lib/rubygems/install_message.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require 'rubygems'
-require 'rubygems/user_interaction'
-
-##
-# A default post-install hook that displays "Successfully installed
-# some_gem-1.0"
-
-Gem.post_install do |installer|
- ui = Gem::DefaultUserInteraction.ui
- ui.say "Successfully installed #{installer.spec.full_name}"
-end
-
diff --git a/ruby_2_2/lib/rubygems/install_update_options.rb b/ruby_2_2/lib/rubygems/install_update_options.rb
deleted file mode 100644
index a503b7fca4..0000000000
--- a/ruby_2_2/lib/rubygems/install_update_options.rb
+++ /dev/null
@@ -1,186 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'rubygems'
-
-# forward-declare
-
-module Gem::Security # :nodoc:
- class Policy # :nodoc:
- end
-end
-
-##
-# Mixin methods for install and update options for Gem::Commands
-
-module Gem::InstallUpdateOptions
-
- ##
- # Add the install/update options to the option parser.
-
- def add_install_update_options
- # TODO: use @parser.accept
- OptionParser.accept Gem::Security::Policy do |value|
- require 'rubygems/security'
-
- raise OptionParser::InvalidArgument, 'OpenSSL not installed' unless
- defined?(Gem::Security::HighSecurity)
-
- value = Gem::Security::Policies[value]
- valid = Gem::Security::Policies.keys.sort
- message = "#{value} (#{valid.join ', '} are valid)"
- raise OptionParser::InvalidArgument, message if value.nil?
- value
- end
-
- add_option(:"Install/Update", '-i', '--install-dir DIR',
- 'Gem repository directory to get installed',
- 'gems') do |value, options|
- options[:install_dir] = File.expand_path(value)
- end
-
- add_option(:"Install/Update", '-n', '--bindir DIR',
- 'Directory where binary files are',
- 'located') do |value, options|
- options[:bin_dir] = File.expand_path(value)
- end
-
- add_option(:"Install/Update", '--[no-]document [TYPES]', Array,
- 'Generate documentation for installed gems',
- 'List the documentation types you wish to',
- 'generate. For example: rdoc,ri') do |value, options|
- options[:document] = case value
- when nil then %w[ri]
- when false then []
- else value
- end
- end
-
- add_option(:"Install/Update", '--build-root DIR',
- 'Temporary installation root. Useful for building',
- 'packages. Do not use this when installing remote gems.') do |value, options|
- options[:build_root] = File.expand_path(value)
- end
-
- add_option(:"Install/Update", '--vendor',
- 'Install gem into the vendor directory.',
- 'Only for use by gem repackagers.') do |value, options|
- unless Gem.vendor_dir then
- raise OptionParser::InvalidOption.new 'your platform is not supported'
- end
-
- options[:vendor] = true
- options[:install_dir] = Gem.vendor_dir
- end
-
- add_option(:"Install/Update", '-N', '--no-document',
- 'Disable documentation generation') do |value, options|
- options[:document] = []
- end
-
- add_option(:Deprecated, '--[no-]rdoc',
- 'Generate RDoc for installed gems',
- 'Use --document instead') do |value, options|
- if value then
- options[:document] << 'rdoc'
- else
- options[:document].delete 'rdoc'
- end
-
- options[:document].uniq!
- end
-
- add_option(:Deprecated, '--[no-]ri',
- 'Generate ri data for installed gems.',
- 'Use --document instead') do |value, options|
- if value then
- options[:document] << 'ri'
- else
- options[:document].delete 'ri'
- end
-
- options[:document].uniq!
- end
-
- add_option(:"Install/Update", '-E', '--[no-]env-shebang',
- "Rewrite the shebang line on installed",
- "scripts to use /usr/bin/env") do |value, options|
- options[:env_shebang] = value
- end
-
- add_option(:"Install/Update", '-f', '--[no-]force',
- 'Force gem to install, bypassing dependency',
- 'checks') do |value, options|
- options[:force] = value
- end
-
- add_option(:"Install/Update", '-w', '--[no-]wrappers',
- 'Use bin wrappers for executables',
- 'Not available on dosish platforms') do |value, options|
- options[:wrappers] = value
- end
-
- add_option(:"Install/Update", '-P', '--trust-policy POLICY',
- Gem::Security::Policy,
- 'Specify gem trust policy') do |value, options|
- options[:security_policy] = value
- end
-
- add_option(:"Install/Update", '--ignore-dependencies',
- 'Do not install any required dependent gems') do |value, options|
- options[:ignore_dependencies] = value
- end
-
- add_option(:"Install/Update", '--[no-]format-executable',
- 'Make installed executable names match ruby.',
- 'If ruby is ruby18, foo_exec will be',
- 'foo_exec18') do |value, options|
- options[:format_executable] = value
- end
-
- add_option(:"Install/Update", '--[no-]user-install',
- 'Install in user\'s home directory instead',
- 'of GEM_HOME.') do |value, options|
- options[:user_install] = value
- end
-
- add_option(:"Install/Update", "--development",
- "Install additional development",
- "dependencies") do |value, options|
- options[:development] = true
- options[:dev_shallow] = true
- end
-
- add_option(:"Install/Update", "--development-all",
- "Install development dependencies for all",
- "gems (including dev deps themselves)") do |value, options|
- options[:development] = true
- options[:dev_shallow] = false
- end
-
- add_option(:"Install/Update", "--conservative",
- "Don't attempt to upgrade gems already",
- "meeting version requirement") do |value, options|
- options[:conservative] = true
- options[:minimal_deps] = true
- end
-
- add_option(:"Install/Update", "--minimal-deps",
- "Don't upgrade any dependencies that already",
- "meet version requirements") do |value, options|
- options[:minimal_deps] = true
- end
- end
-
- ##
- # Default options for the gem install command.
-
- def install_update_defaults_str
- '--document=rdoc,ri --wrappers'
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/installer.rb b/ruby_2_2/lib/rubygems/installer.rb
deleted file mode 100644
index a27569fe2e..0000000000
--- a/ruby_2_2/lib/rubygems/installer.rb
+++ /dev/null
@@ -1,826 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'rubygems/command'
-require 'rubygems/exceptions'
-require 'rubygems/package'
-require 'rubygems/ext'
-require 'rubygems/user_interaction'
-require 'fileutils'
-
-##
-# The installer installs the files contained in the .gem into the Gem.home.
-#
-# Gem::Installer does the work of putting files in all the right places on the
-# filesystem including unpacking the gem into its gem dir, installing the
-# gemspec in the specifications dir, storing the cached gem in the cache dir,
-# and installing either wrappers or symlinks for executables.
-#
-# The installer invokes pre and post install hooks. Hooks can be added either
-# through a rubygems_plugin.rb file in an installed gem or via a
-# rubygems/defaults/#{RUBY_ENGINE}.rb or rubygems/defaults/operating_system.rb
-# file. See Gem.pre_install and Gem.post_install for details.
-
-class Gem::Installer
-
- ##
- # Paths where env(1) might live. Some systems are broken and have it in
- # /bin
-
- ENV_PATHS = %w[/usr/bin/env /bin/env]
-
- ##
- # Deprecated in favor of Gem::Ext::BuildError
-
- ExtensionBuildError = Gem::Ext::BuildError # :nodoc:
-
- include Gem::UserInteraction
-
- ##
- # Filename of the gem being installed.
-
- attr_reader :gem
-
- ##
- # The directory a gem's executables will be installed into
-
- attr_reader :bin_dir
-
- attr_reader :build_root # :nodoc:
-
- ##
- # The gem repository the gem will be installed into
-
- attr_reader :gem_home
-
- ##
- # The options passed when the Gem::Installer was instantiated.
-
- attr_reader :options
-
- ##
- # Sets the specification for .gem-less installs.
-
- attr_writer :spec
-
- @path_warning = false
-
- @install_lock = Mutex.new
-
- class << self
-
- ##
- # True if we've warned about PATH not including Gem.bindir
-
- attr_accessor :path_warning
-
- ##
- # Certain aspects of the install process are not thread-safe. This lock is
- # used to allow multiple threads to install Gems at the same time.
-
- attr_reader :install_lock
-
- ##
- # Overrides the executable format.
- #
- # This is a sprintf format with a "%s" which will be replaced with the
- # executable name. It is based off the ruby executable name's difference
- # from "ruby".
-
- attr_writer :exec_format
-
- # Defaults to use Ruby's program prefix and suffix.
- def exec_format
- @exec_format ||= Gem.default_exec_format
- end
-
- end
-
- ##
- # Constructs an Installer instance that will install the gem located at
- # +gem+. +options+ is a Hash with the following keys:
- #
- # :bin_dir:: Where to put a bin wrapper if needed.
- # :development:: Whether or not development dependencies should be installed.
- # :env_shebang:: Use /usr/bin/env in bin wrappers.
- # :force:: Overrides all version checks and security policy checks, except
- # for a signed-gems-only policy.
- # :format_executable:: Format the executable the same as the Ruby executable.
- # If your Ruby is ruby18, foo_exec will be installed as
- # foo_exec18.
- # :ignore_dependencies:: Don't raise if a dependency is missing.
- # :install_dir:: The directory to install the gem into.
- # :security_policy:: Use the specified security policy. See Gem::Security
- # :user_install:: Indicate that the gem should be unpacked into the users
- # personal gem directory.
- # :only_install_dir:: Only validate dependencies against what is in the
- # install_dir
- # :wrappers:: Install wrappers if true, symlinks if false.
- # :build_args:: An Array of arguments to pass to the extension builder
- # process. If not set, then Gem::Command.build_args is used
-
- def initialize(gem, options={})
- require 'fileutils'
-
- @gem = gem
- @options = options
- @package = Gem::Package.new @gem
-
- process_options
-
- @package.security_policy = @security_policy
-
- if options[:user_install] and not options[:unpack] then
- @gem_home = Gem.user_dir
- @bin_dir = Gem.bindir gem_home unless options[:bin_dir]
- check_that_user_bin_dir_is_in_path
- end
- end
-
- ##
- # Checks if +filename+ exists in +@bin_dir+.
- #
- # If +@force+ is set +filename+ is overwritten.
- #
- # If +filename+ exists and is a RubyGems wrapper for different gem the user
- # is consulted.
- #
- # If +filename+ exists and +@bin_dir+ is Gem.default_bindir (/usr/local) the
- # user is consulted.
- #
- # Otherwise +filename+ is overwritten.
-
- def check_executable_overwrite filename # :nodoc:
- return if @force
-
- generated_bin = File.join @bin_dir, formatted_program_filename(filename)
-
- return unless File.exist? generated_bin
-
- ruby_executable = false
- existing = nil
-
- open generated_bin, 'rb' do |io|
- next unless io.gets =~ /^#!/ # shebang
- io.gets # blankline
-
- # TODO detect a specially formatted comment instead of trying
- # to run a regexp against Ruby code.
- next unless io.gets =~ /This file was generated by RubyGems/
-
- ruby_executable = true
- existing = io.read.slice(/^gem (['"])(.*?)(\1),/, 2)
- end
-
- return if spec.name == existing
-
- # somebody has written to RubyGems' directory, overwrite, too bad
- return if Gem.default_bindir != @bin_dir and not ruby_executable
-
- question = "#{spec.name}'s executable \"#{filename}\" conflicts with "
-
- if ruby_executable then
- question << existing
-
- return if ask_yes_no "#{question}\nOverwrite the executable?", false
-
- conflict = "installed executable from #{existing}"
- else
- question << generated_bin
-
- return if ask_yes_no "#{question}\nOverwrite the executable?", false
-
- conflict = generated_bin
- end
-
- raise Gem::InstallError,
- "\"#{filename}\" from #{spec.name} conflicts with #{conflict}"
- end
-
- ##
- # Lazy accessor for the spec's gem directory.
-
- def gem_dir
- @gem_dir ||= File.join(gem_home, "gems", spec.full_name)
- end
-
- ##
- # Lazy accessor for the installer's spec.
-
- def spec
- @spec ||= @package.spec
- rescue Gem::Package::Error => e
- raise Gem::InstallError, "invalid gem: #{e.message}"
- end
-
- ##
- # Installs the gem and returns a loaded Gem::Specification for the installed
- # gem.
- #
- # The gem will be installed with the following structure:
- #
- # @gem_home/
- # cache/<gem-version>.gem #=> a cached copy of the installed gem
- # gems/<gem-version>/... #=> extracted files
- # specifications/<gem-version>.gemspec #=> the Gem::Specification
-
- def install
- pre_install_checks
-
- FileUtils.rm_f File.join gem_home, 'specifications', @spec.spec_name
-
- run_pre_install_hooks
-
- # Completely remove any previous gem files
- FileUtils.rm_rf gem_dir
-
- FileUtils.mkdir_p gem_dir
-
- spec.loaded_from = spec_file
-
- if @options[:install_as_default]
- extract_bin
- write_default_spec
- else
- extract_files
-
- build_extensions
- write_build_info_file
- run_post_build_hooks
-
- generate_bin
- write_spec
- write_cache_file
- end
-
- say spec.post_install_message unless spec.post_install_message.nil?
-
- Gem::Installer.install_lock.synchronize { Gem::Specification.add_spec spec }
-
- run_post_install_hooks
-
- spec
-
- # TODO This rescue is in the wrong place. What is raising this exception?
- # move this rescue to around the code that actually might raise it.
- rescue Zlib::GzipFile::Error
- raise Gem::InstallError, "gzip error installing #{gem}"
- end
-
- def run_pre_install_hooks # :nodoc:
- Gem.pre_install_hooks.each do |hook|
- if hook.call(self) == false then
- location = " at #{$1}" if hook.inspect =~ /@(.*:\d+)/
-
- message = "pre-install hook#{location} failed for #{spec.full_name}"
- raise Gem::InstallError, message
- end
- end
- end
-
- def run_post_build_hooks # :nodoc:
- Gem.post_build_hooks.each do |hook|
- if hook.call(self) == false then
- FileUtils.rm_rf gem_dir
-
- location = " at #{$1}" if hook.inspect =~ /@(.*:\d+)/
-
- message = "post-build hook#{location} failed for #{spec.full_name}"
- raise Gem::InstallError, message
- end
- end
- end
-
- def run_post_install_hooks # :nodoc:
- Gem.post_install_hooks.each do |hook|
- hook.call self
- end
- end
-
- ##
- #
- # Return an Array of Specifications contained within the gem_home
- # we'll be installing into.
-
- def installed_specs
- @specs ||= begin
- specs = []
-
- Dir[File.join(gem_home, "specifications", "*.gemspec")].each do |path|
- spec = Gem::Specification.load path.untaint
- specs << spec if spec
- end
-
- specs
- end
- end
-
- ##
- # Ensure that the dependency is satisfied by the current installation of
- # gem. If it is not an exception is raised.
- #
- # spec :: Gem::Specification
- # dependency :: Gem::Dependency
-
- def ensure_dependency(spec, dependency)
- unless installation_satisfies_dependency? dependency then
- raise Gem::InstallError, "#{spec.name} requires #{dependency}"
- end
- true
- end
-
- ##
- # True if the gems in the system satisfy +dependency+.
-
- def installation_satisfies_dependency?(dependency)
- return true if @options[:development] and dependency.type == :development
- return true if installed_specs.detect { |s| dependency.matches_spec? s }
- return false if @only_install_dir
- not dependency.matching_specs.empty?
- end
-
- ##
- # Unpacks the gem into the given directory.
-
- def unpack(directory)
- @gem_dir = directory
- extract_files
- end
-
- ##
- # The location of of the spec file that is installed.
- #
-
- def spec_file
- File.join gem_home, "specifications", "#{spec.full_name}.gemspec"
- end
-
- ##
- # The location of of the default spec file for default gems.
- #
-
- def default_spec_file
- File.join gem_home, "specifications/default", "#{spec.full_name}.gemspec"
- end
-
- ##
- # Writes the .gemspec specification (in Ruby) to the gem home's
- # specifications directory.
-
- def write_spec
- open spec_file, 'w' do |file|
- spec.installed_by_version = Gem.rubygems_version
-
- file.puts spec.to_ruby_for_cache
-
- file.fsync rescue nil # for filesystems without fsync(2)
- end
- end
-
- ##
- # Writes the full .gemspec specification (in Ruby) to the gem home's
- # specifications/default directory.
-
- def write_default_spec
- File.open(default_spec_file, "w") do |file|
- file.puts spec.to_ruby
- end
- end
-
- ##
- # Creates windows .bat files for easy running of commands
-
- def generate_windows_script(filename, bindir)
- if Gem.win_platform? then
- script_name = filename + ".bat"
- script_path = File.join bindir, File.basename(script_name)
- File.open script_path, 'w' do |file|
- file.puts windows_stub_script(bindir, filename)
- end
-
- verbose script_path
- end
- end
-
- def generate_bin # :nodoc:
- return if spec.executables.nil? or spec.executables.empty?
-
- Dir.mkdir @bin_dir unless File.exist? @bin_dir
- raise Gem::FilePermissionError.new(@bin_dir) unless File.writable? @bin_dir
-
- spec.executables.each do |filename|
- filename.untaint
- bin_path = File.join gem_dir, spec.bindir, filename
-
- unless File.exist? bin_path then
- # TODO change this to a more useful warning
- warn "#{bin_path} maybe `gem pristine #{spec.name}` will fix it?"
- next
- end
-
- mode = File.stat(bin_path).mode
- FileUtils.chmod mode | 0111, bin_path unless (mode | 0111) == mode
-
- check_executable_overwrite filename
-
- if @wrappers then
- generate_bin_script filename, @bin_dir
- else
- generate_bin_symlink filename, @bin_dir
- end
-
- end
- end
-
- ##
- # Creates the scripts to run the applications in the gem.
- #--
- # The Windows script is generated in addition to the regular one due to a
- # bug or misfeature in the Windows shell's pipe. See
- # http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/193379
-
- def generate_bin_script(filename, bindir)
- bin_script_path = File.join bindir, formatted_program_filename(filename)
-
- FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers
-
- File.open bin_script_path, 'wb', 0755 do |file|
- file.print app_script_text(filename)
- end
-
- verbose bin_script_path
-
- generate_windows_script filename, bindir
- end
-
- ##
- # Creates the symlinks to run the applications in the gem. Moves
- # the symlink if the gem being installed has a newer version.
-
- def generate_bin_symlink(filename, bindir)
- if Gem.win_platform? then
- alert_warning "Unable to use symlinks on Windows, installing wrapper"
- generate_bin_script filename, bindir
- return
- end
-
- src = File.join gem_dir, spec.bindir, filename
- dst = File.join bindir, formatted_program_filename(filename)
-
- if File.exist? dst then
- if File.symlink? dst then
- link = File.readlink(dst).split File::SEPARATOR
- cur_version = Gem::Version.create(link[-3].sub(/^.*-/, ''))
- return if spec.version < cur_version
- end
- File.unlink dst
- end
-
- FileUtils.symlink src, dst, :verbose => Gem.configuration.really_verbose
- end
-
- ##
- # Generates a #! line for +bin_file_name+'s wrapper copying arguments if
- # necessary.
- #
- # If the :custom_shebang config is set, then it is used as a template
- # for how to create the shebang used for to run a gem's executables.
- #
- # The template supports 4 expansions:
- #
- # $env the path to the unix env utility
- # $ruby the path to the currently running ruby interpreter
- # $exec the path to the gem's executable
- # $name the name of the gem the executable is for
- #
-
- def shebang(bin_file_name)
- ruby_name = RbConfig::CONFIG['ruby_install_name'] if @env_shebang
- path = File.join gem_dir, spec.bindir, bin_file_name
- first_line = File.open(path, "rb") {|file| file.gets}
-
- if /\A#!/ =~ first_line then
- # Preserve extra words on shebang line, like "-w". Thanks RPA.
- shebang = first_line.sub(/\A\#!.*?ruby\S*((\s+\S+)+)/, "#!#{Gem.ruby}")
- opts = $1
- shebang.strip! # Avoid nasty ^M issues.
- end
-
- if which = Gem.configuration[:custom_shebang]
- # replace bin_file_name with "ruby" to avoid endless loops
- which = which.gsub(/ #{bin_file_name}$/," #{RbConfig::CONFIG['ruby_install_name']}")
-
- which = which.gsub(/\$(\w+)/) do
- case $1
- when "env"
- @env_path ||= ENV_PATHS.find {|env_path| File.executable? env_path }
- when "ruby"
- "#{Gem.ruby}#{opts}"
- when "exec"
- bin_file_name
- when "name"
- spec.name
- end
- end
-
- "#!#{which}"
- elsif not ruby_name then
- "#!#{Gem.ruby}#{opts}"
- elsif opts then
- "#!/bin/sh\n'exec' #{ruby_name.dump} '-x' \"$0\" \"$@\"\n#{shebang}"
- else
- # Create a plain shebang line.
- @env_path ||= ENV_PATHS.find {|env_path| File.executable? env_path }
- "#!#{@env_path} #{ruby_name}"
- end
- end
-
- ##
- # Ensures the Gem::Specification written out for this gem is loadable upon
- # installation.
-
- def ensure_loadable_spec
- ruby = spec.to_ruby_for_cache
- ruby.untaint
-
- begin
- eval ruby
- rescue StandardError, SyntaxError => e
- raise Gem::InstallError,
- "The specification for #{spec.full_name} is corrupt (#{e.class})"
- end
- end
-
- def ensure_required_ruby_version_met # :nodoc:
- if rrv = spec.required_ruby_version then
- unless rrv.satisfied_by? Gem.ruby_version then
- raise Gem::InstallError, "#{spec.name} requires Ruby version #{rrv}."
- end
- end
- end
-
- def ensure_required_rubygems_version_met # :nodoc:
- if rrgv = spec.required_rubygems_version then
- unless rrgv.satisfied_by? Gem.rubygems_version then
- raise Gem::InstallError,
- "#{spec.name} requires RubyGems version #{rrgv}. " +
- "Try 'gem update --system' to update RubyGems itself."
- end
- end
- end
-
- def ensure_dependencies_met # :nodoc:
- deps = spec.runtime_dependencies
- deps |= spec.development_dependencies if @development
-
- deps.each do |dep_gem|
- ensure_dependency spec, dep_gem
- end
- end
-
- def process_options # :nodoc:
- @options = {
- :bin_dir => nil,
- :env_shebang => false,
- :force => false,
- :only_install_dir => false
- }.merge options
-
- @env_shebang = options[:env_shebang]
- @force = options[:force]
- @install_dir = options[:install_dir]
- @gem_home = options[:install_dir] || Gem.dir
- @ignore_dependencies = options[:ignore_dependencies]
- @format_executable = options[:format_executable]
- @security_policy = options[:security_policy]
- @wrappers = options[:wrappers]
- @only_install_dir = options[:only_install_dir]
-
- # If the user has asked for the gem to be installed in a directory that is
- # the system gem directory, then use the system bin directory, else create
- # (or use) a new bin dir under the gem_home.
- @bin_dir = options[:bin_dir] || Gem.bindir(gem_home)
- @development = options[:development]
- @build_root = options[:build_root]
-
- @build_args = options[:build_args] || Gem::Command.build_args
-
- unless @build_root.nil?
- require 'pathname'
- @build_root = Pathname.new(@build_root).expand_path
- @bin_dir = File.join(@build_root, options[:bin_dir] || Gem.bindir(@gem_home))
- @gem_home = File.join(@build_root, @gem_home)
- alert_warning "You build with buildroot.\n Build root: #{@build_root}\n Bin dir: #{@bin_dir}\n Gem home: #{@gem_home}"
- end
- end
-
- def check_that_user_bin_dir_is_in_path # :nodoc:
- user_bin_dir = @bin_dir || Gem.bindir(gem_home)
- user_bin_dir = user_bin_dir.gsub(File::SEPARATOR, File::ALT_SEPARATOR) if
- File::ALT_SEPARATOR
-
- path = ENV['PATH']
- if Gem.win_platform? then
- path = path.downcase
- user_bin_dir = user_bin_dir.downcase
- end
-
- path = path.split(File::PATH_SEPARATOR)
-
- unless path.include? user_bin_dir then
- unless !Gem.win_platform? && (path.include? user_bin_dir.sub(ENV['HOME'], '~'))
- unless self.class.path_warning then
- alert_warning "You don't have #{user_bin_dir} in your PATH,\n\t gem executables will not run."
- self.class.path_warning = true
- end
- end
- end
- end
-
- def verify_gem_home(unpack = false) # :nodoc:
- FileUtils.mkdir_p gem_home
- raise Gem::FilePermissionError, gem_home unless
- unpack or File.writable?(gem_home)
- end
-
- def verify_spec_name
- return if spec.name =~ Gem::Specification::VALID_NAME_PATTERN
- raise Gem::InstallError, "#{spec} has an invalid name"
- end
-
- ##
- # Return the text for an application file.
-
- def app_script_text(bin_file_name)
- return <<-TEXT
-#{shebang bin_file_name}
-#
-# This file was generated by RubyGems.
-#
-# The application '#{spec.name}' is installed as part of a gem, and
-# this file is here to facilitate running it.
-#
-
-require 'rubygems'
-
-version = "#{Gem::Requirement.default}"
-
-if ARGV.first
- str = ARGV.first
- str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
- if str =~ /\\A_(.*)_\\z/ and Gem::Version.correct?($1) then
- version = $1
- ARGV.shift
- end
-end
-
-gem '#{spec.name}', version
-load Gem.bin_path('#{spec.name}', '#{bin_file_name}', version)
-TEXT
- end
-
- ##
- # return the stub script text used to launch the true Ruby script
-
- def windows_stub_script(bindir, bin_file_name)
- ruby = Gem.ruby.gsub(/^\"|\"$/, "").tr(File::SEPARATOR, "\\")
- return <<-TEXT
-@ECHO OFF
-IF NOT "%~f0" == "~f0" GOTO :WinNT
-@"#{ruby}" "#{File.join(bindir, bin_file_name)}" %1 %2 %3 %4 %5 %6 %7 %8 %9
-GOTO :EOF
-:WinNT
-@"#{ruby}" "%~dpn0" %*
-TEXT
- end
-
- ##
- # Builds extensions. Valid types of extensions are extconf.rb files,
- # configure scripts and rakefiles or mkrf_conf files.
-
- def build_extensions
- builder = Gem::Ext::Builder.new spec, @build_args
-
- builder.build_extensions
- end
-
- ##
- # Logs the build +output+ in +build_dir+, then raises Gem::Ext::BuildError.
- #
- # TODO: Delete this for RubyGems 3. It remains for API compatibility
-
- def extension_build_error(build_dir, output, backtrace = nil) # :nodoc:
- builder = Gem::Ext::Builder.new spec, @build_args
-
- builder.build_error build_dir, output, backtrace
- end
-
- ##
- # Reads the file index and extracts each file into the gem directory.
- #
- # Ensures that files can't be installed outside the gem directory.
-
- def extract_files
- @package.extract_files gem_dir
- end
-
- ##
- # Extracts only the bin/ files from the gem into the gem directory.
- # This is used by default gems to allow a gem-aware stub to function
- # without the full gem installed.
-
- def extract_bin
- @package.extract_files gem_dir, "bin/*"
- end
-
- ##
- # Prefix and suffix the program filename the same as ruby.
-
- def formatted_program_filename(filename)
- if @format_executable then
- self.class.exec_format % File.basename(filename)
- else
- filename
- end
- end
-
- ##
- #
- # Return the target directory where the gem is to be installed. This
- # directory is not guaranteed to be populated.
- #
-
- def dir
- gem_dir.to_s
- end
-
- ##
- # Performs various checks before installing the gem such as the install
- # repository is writable and its directories exist, required Ruby and
- # rubygems versions are met and that dependencies are installed.
- #
- # Version and dependency checks are skipped if this install is forced.
- #
- # The dependent check will be skipped this install is ignoring dependencies.
-
- def pre_install_checks
- verify_gem_home options[:unpack]
-
- # If we're forcing the install then disable security unless the security
- # policy says that we only install signed gems.
- @security_policy = nil if
- @force and @security_policy and not @security_policy.only_signed
-
- ensure_loadable_spec
-
- verify_spec_name
-
- if options[:install_as_default]
- Gem.ensure_default_gem_subdirectories gem_home
- else
- Gem.ensure_gem_subdirectories gem_home
- end
-
- return true if @force
-
- ensure_required_ruby_version_met
- ensure_required_rubygems_version_met
- ensure_dependencies_met unless @ignore_dependencies
-
- true
- end
-
- ##
- # Writes the file containing the arguments for building this gem's
- # extensions.
-
- def write_build_info_file
- return if @build_args.empty?
-
- build_info_dir = File.join gem_home, 'build_info'
-
- FileUtils.mkdir_p build_info_dir
-
- build_info_file = File.join build_info_dir, "#{spec.full_name}.info"
-
- open build_info_file, 'w' do |io|
- @build_args.each do |arg|
- io.puts arg
- end
- end
- end
-
- ##
- # Writes the .gem file to the cache directory
-
- def write_cache_file
- cache_file = File.join gem_home, 'cache', spec.file_name
-
- FileUtils.cp @gem, cache_file unless File.exist? cache_file
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/installer_test_case.rb b/ruby_2_2/lib/rubygems/installer_test_case.rb
deleted file mode 100644
index 549de011e4..0000000000
--- a/ruby_2_2/lib/rubygems/installer_test_case.rb
+++ /dev/null
@@ -1,193 +0,0 @@
-require 'rubygems/test_case'
-require 'rubygems/installer'
-
-class Gem::Installer
-
- ##
- # Available through requiring rubygems/installer_test_case
-
- attr_writer :bin_dir
-
- ##
- # Available through requiring rubygems/installer_test_case
-
- attr_writer :build_args
-
- ##
- # Available through requiring rubygems/installer_test_case
-
- attr_writer :gem_dir
-
- ##
- # Available through requiring rubygems/installer_test_case
-
- attr_writer :force
-
- ##
- # Available through requiring rubygems/installer_test_case
-
- attr_writer :format
-
- ##
- # Available through requiring rubygems/installer_test_case
-
- attr_writer :gem_home
-
- ##
- # Available through requiring rubygems/installer_test_case
-
- attr_writer :env_shebang
-
- ##
- # Available through requiring rubygems/installer_test_case
-
- attr_writer :ignore_dependencies
-
- ##
- # Available through requiring rubygems/installer_test_case
-
- attr_writer :format_executable
-
- ##
- # Available through requiring rubygems/installer_test_case
-
- attr_writer :security_policy
-
- ##
- # Available through requiring rubygems/installer_test_case
-
- attr_writer :wrappers
-end
-
-##
-# A test case for Gem::Installer.
-
-class Gem::InstallerTestCase < Gem::TestCase
-
- ##
- # Creates the following instance variables:
- #
- # @spec::
- # a spec named 'a', intended for regular installs
- # @user_spec::
- # a spec named 'b', intended for user installs
-
- # @gem::
- # the path to a built gem from @spec
- # @user_spec::
- # the path to a built gem from @user_spec
- #
- # @installer::
- # a Gem::Installer for the @spec that installs into @gemhome
- # @user_installer::
- # a Gem::Installer for the @user_spec that installs into Gem.user_dir
-
- def setup
- super
-
- @spec = quick_gem 'a' do |spec|
- util_make_exec spec
- end
-
- @user_spec = quick_gem 'b' do |spec|
- util_make_exec spec
- end
-
- util_build_gem @spec
- util_build_gem @user_spec
-
- @gem = @spec.cache_file
- @user_gem = @user_spec.cache_file
-
- @installer = util_installer @spec, @gemhome
- @user_installer = util_installer @user_spec, Gem.user_dir, :user
-
- Gem::Installer.path_warning = false
- end
-
- def util_gem_bindir spec = @spec # :nodoc:
- # TODO: deprecate
- spec.bin_dir
- end
-
- def util_gem_dir spec = @spec # :nodoc:
- # TODO: deprecate
- spec.gem_dir
- end
-
- ##
- # The path where installed executables live
-
- def util_inst_bindir
- File.join @gemhome, "bin"
- end
-
- ##
- # Adds an executable named "executable" to +spec+ with the given +shebang+.
- #
- # The executable is also written to the bin dir in @tmpdir and the installed
- # gem directory for +spec+.
-
- def util_make_exec(spec = @spec, shebang = "#!/usr/bin/ruby")
- spec.executables = %w[executable]
- spec.files << 'bin/executable'
-
- exec_path = spec.bin_file "executable"
- write_file exec_path do |io|
- io.puts shebang
- end
-
- bin_path = File.join @tempdir, "bin", "executable"
- write_file bin_path do |io|
- io.puts shebang
- end
- end
-
- ##
- # Builds the @spec gem and returns an installer for it. The built gem
- # includes:
- #
- # bin/executable
- # lib/code.rb
- # ext/a/mkrf_conf.rb
-
- def util_setup_gem(ui = @ui) # HACK fix use_ui to make this automatic
- @spec.files << File.join('lib', 'code.rb')
- @spec.extensions << File.join('ext', 'a', 'mkrf_conf.rb')
-
- Dir.chdir @tempdir do
- FileUtils.mkdir_p 'bin'
- FileUtils.mkdir_p 'lib'
- FileUtils.mkdir_p File.join('ext', 'a')
- File.open File.join('bin', 'executable'), 'w' do |f|
- f.puts "raise 'ran executable'"
- end
- File.open File.join('lib', 'code.rb'), 'w' do |f| f.puts '1' end
- File.open File.join('ext', 'a', 'mkrf_conf.rb'), 'w' do |f|
- f << <<-EOF
- File.open 'Rakefile', 'w' do |rf| rf.puts "task :default" end
- EOF
- end
-
- use_ui ui do
- FileUtils.rm_f @gem
-
- @gem = Gem::Package.build @spec
- end
- end
-
- @installer = Gem::Installer.new @gem
- end
-
- ##
- # Creates an installer for +spec+ that will install into +gem_home+. If
- # +user+ is true a user-install will be performed.
-
- def util_installer(spec, gem_home, user=false)
- Gem::Installer.new(spec.cache_file,
- :install_dir => gem_home,
- :user_install => user)
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/local_remote_options.rb b/ruby_2_2/lib/rubygems/local_remote_options.rb
deleted file mode 100644
index db23d9f974..0000000000
--- a/ruby_2_2/lib/rubygems/local_remote_options.rb
+++ /dev/null
@@ -1,148 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'uri'
-require 'rubygems'
-
-##
-# Mixin methods for local and remote Gem::Command options.
-
-module Gem::LocalRemoteOptions
-
- ##
- # Allows OptionParser to handle HTTP URIs.
-
- def accept_uri_http
- OptionParser.accept URI::HTTP do |value|
- begin
- uri = URI.parse value
- rescue URI::InvalidURIError
- raise OptionParser::InvalidArgument, value
- end
-
- unless ['http', 'https', 'file'].include?(uri.scheme)
- raise OptionParser::InvalidArgument, value
- end
-
- value
- end
- end
-
- ##
- # Add local/remote options to the command line parser.
-
- def add_local_remote_options
- add_option(:"Local/Remote", '-l', '--local',
- 'Restrict operations to the LOCAL domain') do |value, options|
- options[:domain] = :local
- end
-
- add_option(:"Local/Remote", '-r', '--remote',
- 'Restrict operations to the REMOTE domain') do |value, options|
- options[:domain] = :remote
- end
-
- add_option(:"Local/Remote", '-b', '--both',
- 'Allow LOCAL and REMOTE operations') do |value, options|
- options[:domain] = :both
- end
-
- add_bulk_threshold_option
- add_clear_sources_option
- add_source_option
- add_proxy_option
- add_update_sources_option
- end
-
- ##
- # Add the --bulk-threshold option
-
- def add_bulk_threshold_option
- add_option(:"Local/Remote", '-B', '--bulk-threshold COUNT',
- "Threshold for switching to bulk",
- "synchronization (default #{Gem.configuration.bulk_threshold})") do
- |value, options|
- Gem.configuration.bulk_threshold = value.to_i
- end
- end
-
- ##
- # Add the --clear-sources option
-
- def add_clear_sources_option
- add_option(:"Local/Remote", '--clear-sources',
- 'Clear the gem sources') do |value, options|
-
- Gem.sources = nil
- options[:sources_cleared] = true
- end
- end
-
- ##
- # Add the --http-proxy option
-
- def add_proxy_option
- accept_uri_http
-
- add_option(:"Local/Remote", '-p', '--[no-]http-proxy [URL]', URI::HTTP,
- 'Use HTTP proxy for remote operations') do |value, options|
- options[:http_proxy] = (value == false) ? :no_proxy : value
- Gem.configuration[:http_proxy] = options[:http_proxy]
- end
- end
-
- ##
- # Add the --source option
-
- def add_source_option
- accept_uri_http
-
- add_option(:"Local/Remote", '-s', '--source URL', URI::HTTP,
- 'Append URL to list of remote gem sources') do |source, options|
-
- source << '/' if source !~ /\/\z/
-
- if options.delete :sources_cleared then
- Gem.sources = [source]
- else
- Gem.sources << source unless Gem.sources.include?(source)
- end
- end
- end
-
- ##
- # Add the --update-sources option
-
- def add_update_sources_option
- add_option(:Deprecated, '-u', '--[no-]update-sources',
- 'Update local source cache') do |value, options|
- Gem.configuration.update_sources = value
- end
- end
-
- ##
- # Is fetching of local and remote information enabled?
-
- def both?
- options[:domain] == :both
- end
-
- ##
- # Is local fetching enabled?
-
- def local?
- options[:domain] == :local || options[:domain] == :both
- end
-
- ##
- # Is remote fetching enabled?
-
- def remote?
- options[:domain] == :remote || options[:domain] == :both
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/mock_gem_ui.rb b/ruby_2_2/lib/rubygems/mock_gem_ui.rb
deleted file mode 100644
index 76a9389676..0000000000
--- a/ruby_2_2/lib/rubygems/mock_gem_ui.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-require 'stringio'
-require 'rubygems/user_interaction'
-
-##
-# This Gem::StreamUI subclass records input and output to StringIO for
-# retrieval during tests.
-
-class Gem::MockGemUi < Gem::StreamUI
- ##
- # Raised when you haven't provided enough input to your MockGemUi
-
- class InputEOFError < RuntimeError
-
- def initialize question
- super "Out of input for MockGemUi on #{question.inspect}"
- end
-
- end
-
- class TermError < RuntimeError
- attr_reader :exit_code
-
- def initialize exit_code
- super
- @exit_code = exit_code
- end
- end
- class SystemExitException < RuntimeError; end
-
- module TTY
-
- attr_accessor :tty
-
- def tty?()
- @tty = true unless defined?(@tty)
- @tty
- end
-
- def noecho
- yield self
- end
- end
-
- def initialize(input = "")
- ins = StringIO.new input
- outs = StringIO.new
- errs = StringIO.new
-
- ins.extend TTY
- outs.extend TTY
- errs.extend TTY
-
- super ins, outs, errs, true
-
- @terminated = false
- end
-
- def ask question
- raise InputEOFError, question if @ins.eof?
-
- super
- end
-
- def input
- @ins.string
- end
-
- def output
- @outs.string
- end
-
- def error
- @errs.string
- end
-
- def terminated?
- @terminated
- end
-
- def terminate_interaction(status=0)
- @terminated = true
-
- raise TermError, status if status != 0
- raise SystemExitException
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/name_tuple.rb b/ruby_2_2/lib/rubygems/name_tuple.rb
deleted file mode 100644
index 60323db408..0000000000
--- a/ruby_2_2/lib/rubygems/name_tuple.rb
+++ /dev/null
@@ -1,123 +0,0 @@
-##
-#
-# Represents a gem of name +name+ at +version+ of +platform+. These
-# wrap the data returned from the indexes.
-
-require 'rubygems/platform'
-
-class Gem::NameTuple
- def initialize(name, version, platform="ruby")
- @name = name
- @version = version
-
- unless platform.kind_of? Gem::Platform
- platform = "ruby" if !platform or platform.empty?
- end
-
- @platform = platform
- end
-
- attr_reader :name, :version, :platform
-
- ##
- # Turn an array of [name, version, platform] into an array of
- # NameTuple objects.
-
- def self.from_list list
- list.map { |t| new(*t) }
- end
-
- ##
- # Turn an array of NameTuple objects back into an array of
- # [name, version, platform] tuples.
-
- def self.to_basic list
- list.map { |t| t.to_a }
- end
-
- ##
- # A null NameTuple, ie name=nil, version=0
-
- def self.null
- new nil, Gem::Version.new(0), nil
- end
-
- ##
- # Returns the full name (name-version) of this Gem. Platform information is
- # included if it is not the default Ruby platform. This mimics the behavior
- # of Gem::Specification#full_name.
-
- def full_name
- case @platform
- when nil, 'ruby', ''
- "#{@name}-#{@version}"
- else
- "#{@name}-#{@version}-#{@platform}"
- end.untaint
- end
-
- ##
- # Indicate if this NameTuple matches the current platform.
-
- def match_platform?
- Gem::Platform.match @platform
- end
-
- ##
- # Indicate if this NameTuple is for a prerelease version.
- def prerelease?
- @version.prerelease?
- end
-
- ##
- # Return the name that the gemspec file would be
-
- def spec_name
- "#{full_name}.gemspec"
- end
-
- ##
- # Convert back to the [name, version, platform] tuple
-
- def to_a
- [@name, @version, @platform]
- end
-
- def inspect # :nodoc:
- "#<Gem::NameTuple #{@name}, #{@version}, #{@platform}>"
- end
-
- alias to_s inspect # :nodoc:
-
- def <=> other
- [@name, @version, @platform == Gem::Platform::RUBY ? -1 : 1] <=>
- [other.name, other.version,
- other.platform == Gem::Platform::RUBY ? -1 : 1]
- end
-
- include Comparable
-
- ##
- # Compare with +other+. Supports another NameTuple or an Array
- # in the [name, version, platform] format.
-
- def == other
- case other
- when self.class
- @name == other.name and
- @version == other.version and
- @platform == other.platform
- when Array
- to_a == other
- else
- false
- end
- end
-
- alias_method :eql?, :==
-
- def hash
- to_a.hash
- end
-
-end
diff --git a/ruby_2_2/lib/rubygems/package.rb b/ruby_2_2/lib/rubygems/package.rb
deleted file mode 100644
index 4d2a2edc80..0000000000
--- a/ruby_2_2/lib/rubygems/package.rb
+++ /dev/null
@@ -1,614 +0,0 @@
-# -*- coding: utf-8 -*-
-#--
-# Copyright (C) 2004 Mauricio Julio Fernández Pradier
-# See LICENSE.txt for additional licensing information.
-#++
-#
-# Example using a Gem::Package
-#
-# Builds a .gem file given a Gem::Specification. A .gem file is a tarball
-# which contains a data.tar.gz and metadata.gz, and possibly signatures.
-#
-# require 'rubygems'
-# require 'rubygems/package'
-#
-# spec = Gem::Specification.new do |s|
-# s.summary = "Ruby based make-like utility."
-# s.name = 'rake'
-# s.version = PKG_VERSION
-# s.requirements << 'none'
-# s.files = PKG_FILES
-# s.description = <<-EOF
-# Rake is a Make-like program implemented in Ruby. Tasks
-# and dependencies are specified in standard Ruby syntax.
-# EOF
-# end
-#
-# Gem::Package.build spec
-#
-# Reads a .gem file.
-#
-# require 'rubygems'
-# require 'rubygems/package'
-#
-# the_gem = Gem::Package.new(path_to_dot_gem)
-# the_gem.contents # get the files in the gem
-# the_gem.extract_files destination_directory # extract the gem into a directory
-# the_gem.spec # get the spec out of the gem
-# the_gem.verify # check the gem is OK (contains valid gem specification, contains a not corrupt contents archive)
-#
-# #files are the files in the .gem tar file, not the Ruby files in the gem
-# #extract_files and #contents automatically call #verify
-
-require 'rubygems/security'
-require 'rubygems/specification'
-require 'rubygems/user_interaction'
-require 'zlib'
-
-class Gem::Package
-
- include Gem::UserInteraction
-
- class Error < Gem::Exception; end
-
- class FormatError < Error
- attr_reader :path
-
- def initialize message, source = nil
- if source
- @path = source.path
-
- message << " in #{path}" if path
- end
-
- super message
- end
-
- end
-
- class PathError < Error
- def initialize destination, destination_dir
- super "installing into parent path %s of %s is not allowed" %
- [destination, destination_dir]
- end
- end
-
- class NonSeekableIO < Error; end
-
- class TooLongFileName < Error; end
-
- ##
- # Raised when a tar file is corrupt
-
- class TarInvalidError < Error; end
-
-
- attr_accessor :build_time # :nodoc:
-
- ##
- # Checksums for the contents of the package
-
- attr_reader :checksums
-
- ##
- # The files in this package. This is not the contents of the gem, just the
- # files in the top-level container.
-
- attr_reader :files
-
- ##
- # The security policy used for verifying the contents of this package.
-
- attr_accessor :security_policy
-
- ##
- # Sets the Gem::Specification to use to build this package.
-
- attr_writer :spec
-
- def self.build spec, skip_validation=false
- gem_file = spec.file_name
-
- package = new gem_file
- package.spec = spec
- package.build skip_validation
-
- gem_file
- end
-
- ##
- # Creates a new Gem::Package for the file at +gem+. +gem+ can also be
- # provided as an IO object.
- #
- # If +gem+ is an existing file in the old format a Gem::Package::Old will be
- # returned.
-
- def self.new gem
- gem = if gem.is_a?(Gem::Package::Source)
- gem
- elsif gem.respond_to? :read
- Gem::Package::IOSource.new gem
- else
- Gem::Package::FileSource.new gem
- end
-
- return super(gem) unless Gem::Package == self
- return super unless gem.present?
-
- return super unless gem.start
- return super unless gem.start.include? 'MD5SUM ='
-
- Gem::Package::Old.new gem
- end
-
- ##
- # Creates a new package that will read or write to the file +gem+.
-
- def initialize gem # :notnew:
- @gem = gem
-
- @build_time = Time.now
- @checksums = {}
- @contents = nil
- @digests = Hash.new { |h, algorithm| h[algorithm] = {} }
- @files = nil
- @security_policy = nil
- @signatures = {}
- @signer = nil
- @spec = nil
- end
-
- ##
- # Adds a checksum for each entry in the gem to checksums.yaml.gz.
-
- def add_checksums tar
- Gem.load_yaml
-
- checksums_by_algorithm = Hash.new { |h, algorithm| h[algorithm] = {} }
-
- @checksums.each do |name, digests|
- digests.each do |algorithm, digest|
- checksums_by_algorithm[algorithm][name] = digest.hexdigest
- end
- end
-
- tar.add_file_signed 'checksums.yaml.gz', 0444, @signer do |io|
- gzip_to io do |gz_io|
- YAML.dump checksums_by_algorithm, gz_io
- end
- end
- end
-
- ##
- # Adds the files listed in the packages's Gem::Specification to data.tar.gz
- # and adds this file to the +tar+.
-
- def add_contents tar # :nodoc:
- digests = tar.add_file_signed 'data.tar.gz', 0444, @signer do |io|
- gzip_to io do |gz_io|
- Gem::Package::TarWriter.new gz_io do |data_tar|
- add_files data_tar
- end
- end
- end
-
- @checksums['data.tar.gz'] = digests
- end
-
- ##
- # Adds files included the package's Gem::Specification to the +tar+ file
-
- def add_files tar # :nodoc:
- @spec.files.each do |file|
- stat = File.stat file
-
- next unless stat.file?
-
- tar.add_file_simple file, stat.mode, stat.size do |dst_io|
- open file, 'rb' do |src_io|
- dst_io.write src_io.read 16384 until src_io.eof?
- end
- end
- end
- end
-
- ##
- # Adds the package's Gem::Specification to the +tar+ file
-
- def add_metadata tar # :nodoc:
- digests = tar.add_file_signed 'metadata.gz', 0444, @signer do |io|
- gzip_to io do |gz_io|
- gz_io.write @spec.to_yaml
- end
- end
-
- @checksums['metadata.gz'] = digests
- end
-
- ##
- # Builds this package based on the specification set by #spec=
-
- def build skip_validation = false
- Gem.load_yaml
- require 'rubygems/security'
-
- @spec.mark_version
- @spec.validate unless skip_validation
-
- setup_signer
-
- @gem.with_write_io do |gem_io|
- Gem::Package::TarWriter.new gem_io do |gem|
- add_metadata gem
- add_contents gem
- add_checksums gem
- end
- end
-
- say <<-EOM
- Successfully built RubyGem
- Name: #{@spec.name}
- Version: #{@spec.version}
- File: #{File.basename @spec.cache_file}
-EOM
- ensure
- @signer = nil
- end
-
- ##
- # A list of file names contained in this gem
-
- def contents
- return @contents if @contents
-
- verify unless @spec
-
- @contents = []
-
- @gem.with_read_io do |io|
- gem_tar = Gem::Package::TarReader.new io
-
- gem_tar.each do |entry|
- next unless entry.full_name == 'data.tar.gz'
-
- open_tar_gz entry do |pkg_tar|
- pkg_tar.each do |contents_entry|
- @contents << contents_entry.full_name
- end
- end
-
- return @contents
- end
- end
- end
-
- ##
- # Creates a digest of the TarEntry +entry+ from the digest algorithm set by
- # the security policy.
-
- def digest entry # :nodoc:
- algorithms = if @checksums then
- @checksums.keys
- else
- [Gem::Security::DIGEST_NAME].compact
- end
-
- algorithms.each do |algorithm|
- digester =
- if defined?(OpenSSL::Digest) then
- OpenSSL::Digest.new algorithm
- else
- Digest.const_get(algorithm).new
- end
-
- digester << entry.read(16384) until entry.eof?
-
- entry.rewind
-
- @digests[algorithm][entry.full_name] = digester
- end
-
- @digests
- end
-
- ##
- # Extracts the files in this package into +destination_dir+
- #
- # If +pattern+ is specified, only entries matching that glob will be
- # extracted.
-
- def extract_files destination_dir, pattern = "*"
- verify unless @spec
-
- FileUtils.mkdir_p destination_dir
-
- @gem.with_read_io do |io|
- reader = Gem::Package::TarReader.new io
-
- reader.each do |entry|
- next unless entry.full_name == 'data.tar.gz'
-
- extract_tar_gz entry, destination_dir, pattern
-
- return # ignore further entries
- end
- end
- end
-
- ##
- # Extracts all the files in the gzipped tar archive +io+ into
- # +destination_dir+.
- #
- # If an entry in the archive contains a relative path above
- # +destination_dir+ or an absolute path is encountered an exception is
- # raised.
- #
- # If +pattern+ is specified, only entries matching that glob will be
- # extracted.
-
- def extract_tar_gz io, destination_dir, pattern = "*" # :nodoc:
- open_tar_gz io do |tar|
- tar.each do |entry|
- next unless File.fnmatch pattern, entry.full_name, File::FNM_DOTMATCH
-
- destination = install_location entry.full_name, destination_dir
-
- FileUtils.rm_rf destination
-
- mkdir_options = {}
- mkdir_options[:mode] = entry.header.mode if entry.directory?
- mkdir =
- if entry.directory? then
- destination
- else
- File.dirname destination
- end
-
- FileUtils.mkdir_p mkdir, mkdir_options
-
- open destination, 'wb' do |out|
- out.write entry.read
- FileUtils.chmod entry.header.mode, destination
- end if entry.file?
-
- verbose destination
- end
- end
- end
-
- ##
- # Gzips content written to +gz_io+ to +io+.
- #--
- # Also sets the gzip modification time to the package build time to ease
- # testing.
-
- def gzip_to io # :yields: gz_io
- gz_io = Zlib::GzipWriter.new io, Zlib::BEST_COMPRESSION
- gz_io.mtime = @build_time
-
- yield gz_io
- ensure
- gz_io.close
- end
-
- ##
- # Returns the full path for installing +filename+.
- #
- # If +filename+ is not inside +destination_dir+ an exception is raised.
-
- def install_location filename, destination_dir # :nodoc:
- raise Gem::Package::PathError.new(filename, destination_dir) if
- filename.start_with? '/'
-
- destination_dir = File.realpath destination_dir if
- File.respond_to? :realpath
- destination_dir = File.expand_path destination_dir
-
- destination = File.join destination_dir, filename
- destination = File.expand_path destination
-
- raise Gem::Package::PathError.new(destination, destination_dir) unless
- destination.start_with? destination_dir
-
- destination.untaint
- destination
- end
-
- ##
- # Loads a Gem::Specification from the TarEntry +entry+
-
- def load_spec entry # :nodoc:
- case entry.full_name
- when 'metadata' then
- @spec = Gem::Specification.from_yaml entry.read
- when 'metadata.gz' then
- args = [entry]
- args << { :external_encoding => Encoding::UTF_8 } if
- Object.const_defined?(:Encoding) &&
- Zlib::GzipReader.method(:wrap).arity != 1
-
- Zlib::GzipReader.wrap(*args) do |gzio|
- @spec = Gem::Specification.from_yaml gzio.read
- end
- end
- end
-
- ##
- # Opens +io+ as a gzipped tar archive
-
- def open_tar_gz io # :nodoc:
- Zlib::GzipReader.wrap io do |gzio|
- tar = Gem::Package::TarReader.new gzio
-
- yield tar
- end
- end
-
- ##
- # Reads and loads checksums.yaml.gz from the tar file +gem+
-
- def read_checksums gem
- Gem.load_yaml
-
- @checksums = gem.seek 'checksums.yaml.gz' do |entry|
- Zlib::GzipReader.wrap entry do |gz_io|
- Gem::SafeYAML.safe_load gz_io.read
- end
- end
- end
-
- ##
- # Prepares the gem for signing and checksum generation. If a signing
- # certificate and key are not present only checksum generation is set up.
-
- def setup_signer
- passphrase = ENV['GEM_PRIVATE_KEY_PASSPHRASE']
- if @spec.signing_key then
- @signer = Gem::Security::Signer.new @spec.signing_key, @spec.cert_chain, passphrase
- @spec.signing_key = nil
- @spec.cert_chain = @signer.cert_chain.map { |cert| cert.to_s }
- else
- @signer = Gem::Security::Signer.new nil, nil, passphrase
- @spec.cert_chain = @signer.cert_chain.map { |cert| cert.to_pem } if
- @signer.cert_chain
- end
- end
-
- ##
- # The spec for this gem.
- #
- # If this is a package for a built gem the spec is loaded from the
- # gem and returned. If this is a package for a gem being built the provided
- # spec is returned.
-
- def spec
- verify unless @spec
-
- @spec
- end
-
- ##
- # Verifies that this gem:
- #
- # * Contains a valid gem specification
- # * Contains a contents archive
- # * The contents archive is not corrupt
- #
- # After verification the gem specification from the gem is available from
- # #spec
-
- def verify
- @files = []
- @spec = nil
-
- @gem.with_read_io do |io|
- Gem::Package::TarReader.new io do |reader|
- read_checksums reader
-
- verify_files reader
- end
- end
-
- verify_checksums @digests, @checksums
-
- @security_policy.verify_signatures @spec, @digests, @signatures if
- @security_policy
-
- true
- rescue Gem::Security::Exception
- @spec = nil
- @files = []
- raise
- rescue Errno::ENOENT => e
- raise Gem::Package::FormatError.new e.message
- rescue Gem::Package::TarInvalidError => e
- raise Gem::Package::FormatError.new e.message, @gem
- end
-
- ##
- # Verifies the +checksums+ against the +digests+. This check is not
- # cryptographically secure. Missing checksums are ignored.
-
- def verify_checksums digests, checksums # :nodoc:
- return unless checksums
-
- checksums.sort.each do |algorithm, gem_digests|
- gem_digests.sort.each do |file_name, gem_hexdigest|
- computed_digest = digests[algorithm][file_name]
-
- unless computed_digest.hexdigest == gem_hexdigest then
- raise Gem::Package::FormatError.new \
- "#{algorithm} checksum mismatch for #{file_name}", @gem
- end
- end
- end
- end
-
- ##
- # Verifies +entry+ in a .gem file.
-
- def verify_entry entry
- file_name = entry.full_name
- @files << file_name
-
- case file_name
- when /\.sig$/ then
- @signatures[$`] = entry.read if @security_policy
- return
- else
- digest entry
- end
-
- case file_name
- when /^metadata(.gz)?$/ then
- load_spec entry
- when 'data.tar.gz' then
- verify_gz entry
- end
- rescue => e
- message = "package is corrupt, exception while verifying: " +
- "#{e.message} (#{e.class})"
- raise Gem::Package::FormatError.new message, @gem
- end
-
- ##
- # Verifies the files of the +gem+
-
- def verify_files gem
- gem.each do |entry|
- verify_entry entry
- end
-
- unless @spec then
- raise Gem::Package::FormatError.new 'package metadata is missing', @gem
- end
-
- unless @files.include? 'data.tar.gz' then
- raise Gem::Package::FormatError.new \
- 'package content (data.tar.gz) is missing', @gem
- end
- end
-
- ##
- # Verifies that +entry+ is a valid gzipped file.
-
- def verify_gz entry # :nodoc:
- Zlib::GzipReader.wrap entry do |gzio|
- gzio.read 16384 until gzio.eof? # gzip checksum verification
- end
- rescue Zlib::GzipFile::Error => e
- raise Gem::Package::FormatError.new(e.message, entry.full_name)
- end
-
-end
-
-require 'rubygems/package/digest_io'
-require 'rubygems/package/source'
-require 'rubygems/package/file_source'
-require 'rubygems/package/io_source'
-require 'rubygems/package/old'
-require 'rubygems/package/tar_header'
-require 'rubygems/package/tar_reader'
-require 'rubygems/package/tar_reader/entry'
-require 'rubygems/package/tar_writer'
-
diff --git a/ruby_2_2/lib/rubygems/package/digest_io.rb b/ruby_2_2/lib/rubygems/package/digest_io.rb
deleted file mode 100644
index f8bde0f557..0000000000
--- a/ruby_2_2/lib/rubygems/package/digest_io.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-##
-# IO wrapper that creates digests of contents written to the IO it wraps.
-
-class Gem::Package::DigestIO
-
- ##
- # Collected digests for wrapped writes.
- #
- # {
- # 'SHA1' => #<OpenSSL::Digest: [...]>,
- # 'SHA512' => #<OpenSSL::Digest: [...]>,
- # }
-
- attr_reader :digests
-
- ##
- # Wraps +io+ and updates digest for each of the digest algorithms in
- # the +digests+ Hash. Returns the digests hash. Example:
- #
- # io = StringIO.new
- # digests = {
- # 'SHA1' => OpenSSL::Digest.new('SHA1'),
- # 'SHA512' => OpenSSL::Digest.new('SHA512'),
- # }
- #
- # Gem::Package::DigestIO.wrap io, digests do |digest_io|
- # digest_io.write "hello"
- # end
- #
- # digests['SHA1'].hexdigest #=> "aaf4c61d[...]"
- # digests['SHA512'].hexdigest #=> "9b71d224[...]"
-
- def self.wrap io, digests
- digest_io = new io, digests
-
- yield digest_io
-
- return digests
- end
-
- ##
- # Creates a new DigestIO instance. Using ::wrap is recommended, see the
- # ::wrap documentation for documentation of +io+ and +digests+.
-
- def initialize io, digests
- @io = io
- @digests = digests
- end
-
- ##
- # Writes +data+ to the underlying IO and updates the digests
-
- def write data
- result = @io.write data
-
- @digests.each do |_, digest|
- digest << data
- end
-
- result
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/package/file_source.rb b/ruby_2_2/lib/rubygems/package/file_source.rb
deleted file mode 100644
index 85316f62e7..0000000000
--- a/ruby_2_2/lib/rubygems/package/file_source.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-##
-# The primary source of gems is a file on disk, including all usages
-# internal to rubygems.
-#
-# This is a private class, do not depend on it directly. Instead, pass a path
-# object to `Gem::Package.new`.
-
-class Gem::Package::FileSource < Gem::Package::Source # :nodoc: all
-
- attr_reader :path
-
- def initialize path
- @path = path
- end
-
- def start
- @start ||= File.read path, 20
- end
-
- def present?
- File.exist? path
- end
-
- def with_write_io &block
- open path, 'wb', &block
- end
-
- def with_read_io &block
- open path, 'rb', &block
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/package/io_source.rb b/ruby_2_2/lib/rubygems/package/io_source.rb
deleted file mode 100644
index f89593dd2d..0000000000
--- a/ruby_2_2/lib/rubygems/package/io_source.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-##
-# Supports reading and writing gems from/to a generic IO object. This is
-# useful for other applications built on top of rubygems, such as
-# rubygems.org.
-#
-# This is a private class, do not depend on it directly. Instead, pass an IO
-# object to `Gem::Package.new`.
-
-class Gem::Package::IOSource < Gem::Package::Source # :nodoc: all
-
- attr_reader :io
-
- def initialize io
- @io = io
- end
-
- def start
- @start ||= begin
- if io.pos > 0
- raise Gem::Package::Error, "Cannot read start unless IO is at start"
- end
-
- value = io.read 20
- io.rewind
- value
- end
- end
-
- def present?
- true
- end
-
- def with_read_io
- yield io
- end
-
- def with_write_io
- yield io
- end
-
- def path
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/package/old.rb b/ruby_2_2/lib/rubygems/package/old.rb
deleted file mode 100644
index 7a9a9015c1..0000000000
--- a/ruby_2_2/lib/rubygems/package/old.rb
+++ /dev/null
@@ -1,178 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-##
-# The format class knows the guts of the ancient .gem file format and provides
-# the capability to read such ancient gems.
-#
-# Please pretend this doesn't exist.
-
-class Gem::Package::Old < Gem::Package
-
- undef_method :spec=
-
- ##
- # Creates a new old-format package reader for +gem+. Old-format packages
- # cannot be written.
-
- def initialize gem
- require 'fileutils'
- require 'zlib'
- Gem.load_yaml
-
- @contents = nil
- @gem = gem
- @security_policy = nil
- @spec = nil
- end
-
- ##
- # A list of file names contained in this gem
-
- def contents
- verify
-
- return @contents if @contents
-
- @gem.with_read_io do |io|
- read_until_dashes io # spec
- header = file_list io
-
- @contents = header.map { |file| file['path'] }
- end
- end
-
- ##
- # Extracts the files in this package into +destination_dir+
-
- def extract_files destination_dir
- verify
-
- errstr = "Error reading files from gem"
-
- @gem.with_read_io do |io|
- read_until_dashes io # spec
- header = file_list io
- raise Gem::Exception, errstr unless header
-
- header.each do |entry|
- full_name = entry['path']
-
- destination = install_location full_name, destination_dir
-
- file_data = ''
-
- read_until_dashes io do |line|
- file_data << line
- end
-
- file_data = file_data.strip.unpack("m")[0]
- file_data = Zlib::Inflate.inflate file_data
-
- raise Gem::Package::FormatError, "#{full_name} in #{@gem} is corrupt" if
- file_data.length != entry['size'].to_i
-
- FileUtils.rm_rf destination
-
- FileUtils.mkdir_p File.dirname destination
-
- open destination, 'wb', entry['mode'] do |out|
- out.write file_data
- end
-
- verbose destination
- end
- end
- rescue Zlib::DataError
- raise Gem::Exception, errstr
- end
-
- ##
- # Reads the file list section from the old-format gem +io+
-
- def file_list io # :nodoc:
- header = ''
-
- read_until_dashes io do |line|
- header << line
- end
-
- Gem::SafeYAML.safe_load header
- end
-
- ##
- # Reads lines until a "---" separator is found
-
- def read_until_dashes io # :nodoc:
- while (line = io.gets) && line.chomp.strip != "---" do
- yield line if block_given?
- end
- end
-
- ##
- # Skips the Ruby self-install header in +io+.
-
- def skip_ruby io # :nodoc:
- loop do
- line = io.gets
-
- return if line.chomp == '__END__'
- break unless line
- end
-
- raise Gem::Exception, "Failed to find end of ruby script while reading gem"
- end
-
- ##
- # The specification for this gem
-
- def spec
- verify
-
- return @spec if @spec
-
- yaml = ''
-
- @gem.with_read_io do |io|
- skip_ruby io
- read_until_dashes io do |line|
- yaml << line
- end
- end
-
- yaml_error = if RUBY_VERSION < '1.9' then
- YAML::ParseError
- elsif YAML.const_defined?(:ENGINE) && YAML::ENGINE.yamler == 'syck' then
- YAML::ParseError
- else
- YAML::SyntaxError
- end
-
- begin
- @spec = Gem::Specification.from_yaml yaml
- rescue yaml_error
- raise Gem::Exception, "Failed to parse gem specification out of gem file"
- end
- rescue ArgumentError
- raise Gem::Exception, "Failed to parse gem specification out of gem file"
- end
-
- ##
- # Raises an exception if a security policy that verifies data is active.
- # Old format gems cannot be verified as signed.
-
- def verify
- return true unless @security_policy
-
- raise Gem::Security::Exception,
- 'old format gems do not contain signatures and cannot be verified' if
- @security_policy.verify_data
-
- true
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/package/source.rb b/ruby_2_2/lib/rubygems/package/source.rb
deleted file mode 100644
index 1f18d479da..0000000000
--- a/ruby_2_2/lib/rubygems/package/source.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-class Gem::Package::Source # :nodoc:
-end
-
diff --git a/ruby_2_2/lib/rubygems/package/tar_header.rb b/ruby_2_2/lib/rubygems/package/tar_header.rb
deleted file mode 100644
index f9ab13aca7..0000000000
--- a/ruby_2_2/lib/rubygems/package/tar_header.rb
+++ /dev/null
@@ -1,229 +0,0 @@
-# -*- coding: utf-8 -*-
-#--
-# Copyright (C) 2004 Mauricio Julio Fernández Pradier
-# See LICENSE.txt for additional licensing information.
-#++
-
-##
-#--
-# struct tarfile_entry_posix {
-# char name[100]; # ASCII + (Z unless filled)
-# char mode[8]; # 0 padded, octal, null
-# char uid[8]; # ditto
-# char gid[8]; # ditto
-# char size[12]; # 0 padded, octal, null
-# char mtime[12]; # 0 padded, octal, null
-# char checksum[8]; # 0 padded, octal, null, space
-# char typeflag[1]; # file: "0" dir: "5"
-# char linkname[100]; # ASCII + (Z unless filled)
-# char magic[6]; # "ustar\0"
-# char version[2]; # "00"
-# char uname[32]; # ASCIIZ
-# char gname[32]; # ASCIIZ
-# char devmajor[8]; # 0 padded, octal, null
-# char devminor[8]; # o padded, octal, null
-# char prefix[155]; # ASCII + (Z unless filled)
-# };
-#++
-# A header for a tar file
-
-class Gem::Package::TarHeader
-
- ##
- # Fields in the tar header
-
- FIELDS = [
- :checksum,
- :devmajor,
- :devminor,
- :gid,
- :gname,
- :linkname,
- :magic,
- :mode,
- :mtime,
- :name,
- :prefix,
- :size,
- :typeflag,
- :uid,
- :uname,
- :version,
- ]
-
- ##
- # Pack format for a tar header
-
- PACK_FORMAT = 'a100' + # name
- 'a8' + # mode
- 'a8' + # uid
- 'a8' + # gid
- 'a12' + # size
- 'a12' + # mtime
- 'a7a' + # chksum
- 'a' + # typeflag
- 'a100' + # linkname
- 'a6' + # magic
- 'a2' + # version
- 'a32' + # uname
- 'a32' + # gname
- 'a8' + # devmajor
- 'a8' + # devminor
- 'a155' # prefix
-
- ##
- # Unpack format for a tar header
-
- UNPACK_FORMAT = 'A100' + # name
- 'A8' + # mode
- 'A8' + # uid
- 'A8' + # gid
- 'A12' + # size
- 'A12' + # mtime
- 'A8' + # checksum
- 'A' + # typeflag
- 'A100' + # linkname
- 'A6' + # magic
- 'A2' + # version
- 'A32' + # uname
- 'A32' + # gname
- 'A8' + # devmajor
- 'A8' + # devminor
- 'A155' # prefix
-
- attr_reader(*FIELDS)
-
- ##
- # Creates a tar header from IO +stream+
-
- def self.from(stream)
- header = stream.read 512
- empty = (header == "\0" * 512)
-
- fields = header.unpack UNPACK_FORMAT
-
- new :name => fields.shift,
- :mode => fields.shift.oct,
- :uid => fields.shift.oct,
- :gid => fields.shift.oct,
- :size => fields.shift.oct,
- :mtime => fields.shift.oct,
- :checksum => fields.shift.oct,
- :typeflag => fields.shift,
- :linkname => fields.shift,
- :magic => fields.shift,
- :version => fields.shift.oct,
- :uname => fields.shift,
- :gname => fields.shift,
- :devmajor => fields.shift.oct,
- :devminor => fields.shift.oct,
- :prefix => fields.shift,
-
- :empty => empty
- end
-
- ##
- # Creates a new TarHeader using +vals+
-
- def initialize(vals)
- unless vals[:name] && vals[:size] && vals[:prefix] && vals[:mode] then
- raise ArgumentError, ":name, :size, :prefix and :mode required"
- end
-
- vals[:uid] ||= 0
- vals[:gid] ||= 0
- vals[:mtime] ||= 0
- vals[:checksum] ||= ""
- vals[:typeflag] = "0" if vals[:typeflag].nil? || vals[:typeflag].empty?
- vals[:magic] ||= "ustar"
- vals[:version] ||= "00"
- vals[:uname] ||= "wheel"
- vals[:gname] ||= "wheel"
- vals[:devmajor] ||= 0
- vals[:devminor] ||= 0
-
- FIELDS.each do |name|
- instance_variable_set "@#{name}", vals[name]
- end
-
- @empty = vals[:empty]
- end
-
- ##
- # Is the tar entry empty?
-
- def empty?
- @empty
- end
-
- def ==(other) # :nodoc:
- self.class === other and
- @checksum == other.checksum and
- @devmajor == other.devmajor and
- @devminor == other.devminor and
- @gid == other.gid and
- @gname == other.gname and
- @linkname == other.linkname and
- @magic == other.magic and
- @mode == other.mode and
- @mtime == other.mtime and
- @name == other.name and
- @prefix == other.prefix and
- @size == other.size and
- @typeflag == other.typeflag and
- @uid == other.uid and
- @uname == other.uname and
- @version == other.version
- end
-
- def to_s # :nodoc:
- update_checksum
- header
- end
-
- ##
- # Updates the TarHeader's checksum
-
- def update_checksum
- header = header " " * 8
- @checksum = oct calculate_checksum(header), 6
- end
-
- private
-
- def calculate_checksum(header)
- header.unpack("C*").inject { |a, b| a + b }
- end
-
- def header(checksum = @checksum)
- header = [
- name,
- oct(mode, 7),
- oct(uid, 7),
- oct(gid, 7),
- oct(size, 11),
- oct(mtime, 11),
- checksum,
- " ",
- typeflag,
- linkname,
- magic,
- oct(version, 2),
- uname,
- gname,
- oct(devmajor, 7),
- oct(devminor, 7),
- prefix
- ]
-
- header = header.pack PACK_FORMAT
-
- header << ("\0" * ((512 - header.size) % 512))
- end
-
- def oct(num, len)
- "%0#{len}o" % num
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/package/tar_reader.rb b/ruby_2_2/lib/rubygems/package/tar_reader.rb
deleted file mode 100644
index e257fdd846..0000000000
--- a/ruby_2_2/lib/rubygems/package/tar_reader.rb
+++ /dev/null
@@ -1,123 +0,0 @@
-# -*- coding: utf-8 -*-
-#--
-# Copyright (C) 2004 Mauricio Julio Fernández Pradier
-# See LICENSE.txt for additional licensing information.
-#++
-
-##
-# TarReader reads tar files and allows iteration over their items
-
-class Gem::Package::TarReader
-
- include Enumerable
-
- ##
- # Raised if the tar IO is not seekable
-
- class UnexpectedEOF < StandardError; end
-
- ##
- # Creates a new TarReader on +io+ and yields it to the block, if given.
-
- def self.new(io)
- reader = super
-
- return reader unless block_given?
-
- begin
- yield reader
- ensure
- reader.close
- end
-
- nil
- end
-
- ##
- # Creates a new tar file reader on +io+ which needs to respond to #pos,
- # #eof?, #read, #getc and #pos=
-
- def initialize(io)
- @io = io
- @init_pos = io.pos
- end
-
- ##
- # Close the tar file
-
- def close
- end
-
- ##
- # Iterates over files in the tarball yielding each entry
-
- def each
- return enum_for __method__ unless block_given?
-
- until @io.eof? do
- header = Gem::Package::TarHeader.from @io
- return if header.empty?
-
- entry = Gem::Package::TarReader::Entry.new header, @io
- size = entry.header.size
-
- yield entry
-
- skip = (512 - (size % 512)) % 512
- pending = size - entry.bytes_read
-
- begin
- # avoid reading...
- @io.seek pending, IO::SEEK_CUR
- pending = 0
- rescue Errno::EINVAL, NameError
- while pending > 0 do
- bytes_read = @io.read([pending, 4096].min).size
- raise UnexpectedEOF if @io.eof?
- pending -= bytes_read
- end
- end
-
- @io.read skip # discard trailing zeros
-
- # make sure nobody can use #read, #getc or #rewind anymore
- entry.close
- end
- end
-
- alias each_entry each
-
- ##
- # NOTE: Do not call #rewind during #each
-
- def rewind
- if @init_pos == 0 then
- raise Gem::Package::NonSeekableIO unless @io.respond_to? :rewind
- @io.rewind
- else
- raise Gem::Package::NonSeekableIO unless @io.respond_to? :pos=
- @io.pos = @init_pos
- end
- end
-
- ##
- # Seeks through the tar file until it finds the +entry+ with +name+ and
- # yields it. Rewinds the tar file to the beginning when the block
- # terminates.
-
- def seek name # :yields: entry
- found = find do |entry|
- entry.full_name == name
- end
-
- return unless found
-
- return yield found
- ensure
- rewind
- end
-
-end
-
-require 'rubygems/package/tar_reader/entry'
-
diff --git a/ruby_2_2/lib/rubygems/package/tar_reader/entry.rb b/ruby_2_2/lib/rubygems/package/tar_reader/entry.rb
deleted file mode 100644
index 737c7639c6..0000000000
--- a/ruby_2_2/lib/rubygems/package/tar_reader/entry.rb
+++ /dev/null
@@ -1,147 +0,0 @@
-# -*- coding: utf-8 -*-
-#++
-# Copyright (C) 2004 Mauricio Julio Fernández Pradier
-# See LICENSE.txt for additional licensing information.
-#--
-
-##
-# Class for reading entries out of a tar file
-
-class Gem::Package::TarReader::Entry
-
- ##
- # Header for this tar entry
-
- attr_reader :header
-
- ##
- # Creates a new tar entry for +header+ that will be read from +io+
-
- def initialize(header, io)
- @closed = false
- @header = header
- @io = io
- @orig_pos = @io.pos
- @read = 0
- end
-
- def check_closed # :nodoc:
- raise IOError, "closed #{self.class}" if closed?
- end
-
- ##
- # Number of bytes read out of the tar entry
-
- def bytes_read
- @read
- end
-
- ##
- # Closes the tar entry
-
- def close
- @closed = true
- end
-
- ##
- # Is the tar entry closed?
-
- def closed?
- @closed
- end
-
- ##
- # Are we at the end of the tar entry?
-
- def eof?
- check_closed
-
- @read >= @header.size
- end
-
- ##
- # Full name of the tar entry
-
- def full_name
- if @header.prefix != "" then
- File.join @header.prefix, @header.name
- else
- @header.name
- end
- rescue ArgumentError => e
- raise unless e.message == 'string contains null byte'
- raise Gem::Package::TarInvalidError,
- 'tar is corrupt, name contains null byte'
- end
-
- ##
- # Read one byte from the tar entry
-
- def getc
- check_closed
-
- return nil if @read >= @header.size
-
- ret = @io.getc
- @read += 1 if ret
-
- ret
- end
-
- ##
- # Is this tar entry a directory?
-
- def directory?
- @header.typeflag == "5"
- end
-
- ##
- # Is this tar entry a file?
-
- def file?
- @header.typeflag == "0"
- end
-
- ##
- # The position in the tar entry
-
- def pos
- check_closed
-
- bytes_read
- end
-
- ##
- # Reads +len+ bytes from the tar file entry, or the rest of the entry if
- # nil
-
- def read(len = nil)
- check_closed
-
- return nil if @read >= @header.size
-
- len ||= @header.size - @read
- max_read = [len, @header.size - @read].min
-
- ret = @io.read max_read
- @read += ret.size
-
- ret
- end
-
- alias readpartial read # :nodoc:
-
- ##
- # Rewinds to the beginning of the tar file entry
-
- def rewind
- check_closed
-
- raise Gem::Package::NonSeekableIO unless @io.respond_to? :pos=
-
- @io.pos = @orig_pos
- @read = 0
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/package/tar_test_case.rb b/ruby_2_2/lib/rubygems/package/tar_test_case.rb
deleted file mode 100644
index 5253e32f36..0000000000
--- a/ruby_2_2/lib/rubygems/package/tar_test_case.rb
+++ /dev/null
@@ -1,137 +0,0 @@
-require 'rubygems/test_case'
-require 'rubygems/package'
-
-##
-# A test case for Gem::Package::Tar* classes
-
-class Gem::Package::TarTestCase < Gem::TestCase
-
- def ASCIIZ(str, length)
- str + "\0" * (length - str.length)
- end
-
- def SP(s)
- s + " "
- end
-
- def SP_Z(s)
- s + " \0"
- end
-
- def Z(s)
- s + "\0"
- end
-
- def assert_headers_equal(expected, actual)
- expected = expected.to_s unless String === expected
- actual = actual.to_s unless String === actual
-
- fields = %w[
- name 100
- mode 8
- uid 8
- gid 8
- size 12
- mtime 12
- checksum 8
- typeflag 1
- linkname 100
- magic 6
- version 2
- uname 32
- gname 32
- devmajor 8
- devminor 8
- prefix 155
- ]
-
- offset = 0
-
- until fields.empty? do
- name = fields.shift
- length = fields.shift.to_i
-
- if name == "checksum" then
- chksum_off = offset
- offset += length
- next
- end
-
- assert_equal expected[offset, length], actual[offset, length],
- "Field #{name} of the tar header differs."
-
- offset += length
- end
-
- assert_equal expected[chksum_off, 8], actual[chksum_off, 8]
- end
-
- def calc_checksum(header)
- sum = header.unpack("C*").inject{|s,a| s + a}
- SP(Z(to_oct(sum, 6)))
- end
-
- def header(type, fname, dname, length, mode, mtime, checksum = nil)
- checksum ||= " " * 8
-
- arr = [ # struct tarfile_entry_posix
- ASCIIZ(fname, 100), # char name[100]; ASCII + (Z unless filled)
- Z(to_oct(mode, 7)), # char mode[8]; 0 padded, octal null
- Z(to_oct(0, 7)), # char uid[8]; ditto
- Z(to_oct(0, 7)), # char gid[8]; ditto
- Z(to_oct(length, 11)), # char size[12]; 0 padded, octal, null
- Z(to_oct(mtime, 11)), # char mtime[12]; 0 padded, octal, null
- checksum, # char checksum[8]; 0 padded, octal, null, space
- type, # char typeflag[1]; file: "0" dir: "5"
- "\0" * 100, # char linkname[100]; ASCII + (Z unless filled)
- "ustar\0", # char magic[6]; "ustar\0"
- "00", # char version[2]; "00"
- ASCIIZ("wheel", 32), # char uname[32]; ASCIIZ
- ASCIIZ("wheel", 32), # char gname[32]; ASCIIZ
- Z(to_oct(0, 7)), # char devmajor[8]; 0 padded, octal, null
- Z(to_oct(0, 7)), # char devminor[8]; 0 padded, octal, null
- ASCIIZ(dname, 155) # char prefix[155]; ASCII + (Z unless filled)
- ]
-
- format = "C100C8C8C8C12C12C8CC100C6C2C32C32C8C8C155"
- h = if RUBY_VERSION >= "1.9" then
- arr.join
- else
- arr = arr.join("").split(//).map{|x| x[0]}
- arr.pack format
- end
- ret = h + "\0" * (512 - h.size)
- assert_equal(512, ret.size)
- ret
- end
-
- def tar_dir_header(name, prefix, mode, mtime)
- h = header("5", name, prefix, 0, mode, mtime)
- checksum = calc_checksum(h)
- header("5", name, prefix, 0, mode, mtime, checksum)
- end
-
- def tar_file_header(fname, dname, mode, length, mtime)
- h = header("0", fname, dname, length, mode, mtime)
- checksum = calc_checksum(h)
- header("0", fname, dname, length, mode, mtime, checksum)
- end
-
- def to_oct(n, pad_size)
- "%0#{pad_size}o" % n
- end
-
- def util_entry(tar)
- io = TempIO.new tar
-
- header = Gem::Package::TarHeader.from io
-
- Gem::Package::TarReader::Entry.new header, io
- end
-
- def util_dir_entry
- util_entry tar_dir_header("foo", "bar", 0, Time.now)
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/package/tar_writer.rb b/ruby_2_2/lib/rubygems/package/tar_writer.rb
deleted file mode 100644
index dfd635724b..0000000000
--- a/ruby_2_2/lib/rubygems/package/tar_writer.rb
+++ /dev/null
@@ -1,326 +0,0 @@
-# -*- coding: utf-8 -*-
-#--
-# Copyright (C) 2004 Mauricio Julio Fernández Pradier
-# See LICENSE.txt for additional licensing information.
-#++
-
-require 'digest'
-
-##
-# Allows writing of tar files
-
-class Gem::Package::TarWriter
-
- class FileOverflow < StandardError; end
-
- ##
- # IO wrapper that allows writing a limited amount of data
-
- class BoundedStream
-
- ##
- # Maximum number of bytes that can be written
-
- attr_reader :limit
-
- ##
- # Number of bytes written
-
- attr_reader :written
-
- ##
- # Wraps +io+ and allows up to +limit+ bytes to be written
-
- def initialize(io, limit)
- @io = io
- @limit = limit
- @written = 0
- end
-
- ##
- # Writes +data+ onto the IO, raising a FileOverflow exception if the
- # number of bytes will be more than #limit
-
- def write(data)
- if data.bytesize + @written > @limit
- raise FileOverflow, "You tried to feed more data than fits in the file."
- end
- @io.write data
- @written += data.bytesize
- data.bytesize
- end
-
- end
-
- ##
- # IO wrapper that provides only #write
-
- class RestrictedStream
-
- ##
- # Creates a new RestrictedStream wrapping +io+
-
- def initialize(io)
- @io = io
- end
-
- ##
- # Writes +data+ onto the IO
-
- def write(data)
- @io.write data
- end
-
- end
-
- ##
- # Creates a new TarWriter, yielding it if a block is given
-
- def self.new(io)
- writer = super
-
- return writer unless block_given?
-
- begin
- yield writer
- ensure
- writer.close
- end
-
- nil
- end
-
- ##
- # Creates a new TarWriter that will write to +io+
-
- def initialize(io)
- @io = io
- @closed = false
- end
-
- ##
- # Adds file +name+ with permissions +mode+, and yields an IO for writing the
- # file to
-
- def add_file(name, mode) # :yields: io
- check_closed
-
- raise Gem::Package::NonSeekableIO unless @io.respond_to? :pos=
-
- name, prefix = split_name name
-
- init_pos = @io.pos
- @io.write "\0" * 512 # placeholder for the header
-
- yield RestrictedStream.new(@io) if block_given?
-
- size = @io.pos - init_pos - 512
-
- remainder = (512 - (size % 512)) % 512
- @io.write "\0" * remainder
-
- final_pos = @io.pos
- @io.pos = init_pos
-
- header = Gem::Package::TarHeader.new :name => name, :mode => mode,
- :size => size, :prefix => prefix,
- :mtime => Time.now
-
- @io.write header
- @io.pos = final_pos
-
- self
- end
-
- ##
- # Adds +name+ with permissions +mode+ to the tar, yielding +io+ for writing
- # the file. The +digest_algorithm+ is written to a read-only +name+.sum
- # file following the given file contents containing the digest name and
- # hexdigest separated by a tab.
- #
- # The created digest object is returned.
-
- def add_file_digest name, mode, digest_algorithms # :yields: io
- digests = digest_algorithms.map do |digest_algorithm|
- digest = digest_algorithm.new
- digest_name =
- if digest.respond_to? :name then
- digest.name
- else
- /::([^:]+)$/ =~ digest_algorithm.name
- $1
- end
-
- [digest_name, digest]
- end
-
- digests = Hash[*digests.flatten]
-
- add_file name, mode do |io|
- Gem::Package::DigestIO.wrap io, digests do |digest_io|
- yield digest_io
- end
- end
-
- digests
- end
-
- ##
- # Adds +name+ with permissions +mode+ to the tar, yielding +io+ for writing
- # the file. The +signer+ is used to add a digest file using its
- # digest_algorithm per add_file_digest and a cryptographic signature in
- # +name+.sig. If the signer has no key only the checksum file is added.
- #
- # Returns the digest.
-
- def add_file_signed name, mode, signer
- digest_algorithms = [
- signer.digest_algorithm,
- Digest::SHA512,
- ].compact.uniq
-
- digests = add_file_digest name, mode, digest_algorithms do |io|
- yield io
- end
-
- signature_digest = digests.values.compact.find do |digest|
- digest_name =
- if digest.respond_to? :name then
- digest.name
- else
- /::([^:]+)$/ =~ digest.class.name
- $1
- end
-
- digest_name == signer.digest_name
- end
-
- if signer.key then
- signature = signer.sign signature_digest.digest
-
- add_file_simple "#{name}.sig", 0444, signature.length do |io|
- io.write signature
- end
- end
-
- digests
- end
-
- ##
- # Add file +name+ with permissions +mode+ +size+ bytes long. Yields an IO
- # to write the file to.
-
- def add_file_simple(name, mode, size) # :yields: io
- check_closed
-
- name, prefix = split_name name
-
- header = Gem::Package::TarHeader.new(:name => name, :mode => mode,
- :size => size, :prefix => prefix,
- :mtime => Time.now).to_s
-
- @io.write header
- os = BoundedStream.new @io, size
-
- yield os if block_given?
-
- min_padding = size - os.written
- @io.write("\0" * min_padding)
-
- remainder = (512 - (size % 512)) % 512
- @io.write("\0" * remainder)
-
- self
- end
-
- ##
- # Raises IOError if the TarWriter is closed
-
- def check_closed
- raise IOError, "closed #{self.class}" if closed?
- end
-
- ##
- # Closes the TarWriter
-
- def close
- check_closed
-
- @io.write "\0" * 1024
- flush
-
- @closed = true
- end
-
- ##
- # Is the TarWriter closed?
-
- def closed?
- @closed
- end
-
- ##
- # Flushes the TarWriter's IO
-
- def flush
- check_closed
-
- @io.flush if @io.respond_to? :flush
- end
-
- ##
- # Creates a new directory in the tar file +name+ with +mode+
-
- def mkdir(name, mode)
- check_closed
-
- name, prefix = split_name(name)
-
- header = Gem::Package::TarHeader.new :name => name, :mode => mode,
- :typeflag => "5", :size => 0,
- :prefix => prefix,
- :mtime => Time.now
-
- @io.write header
-
- self
- end
-
- ##
- # Splits +name+ into a name and prefix that can fit in the TarHeader
-
- def split_name(name) # :nodoc:
- if name.bytesize > 256
- raise Gem::Package::TooLongFileName.new("File \"#{name}\" has a too long path (should be 256 or less)")
- end
-
- if name.bytesize <= 100 then
- prefix = ""
- else
- parts = name.split(/\//)
- newname = parts.pop
- nxt = ""
-
- loop do
- nxt = parts.pop
- break if newname.bytesize + 1 + nxt.bytesize > 100
- newname = nxt + "/" + newname
- end
-
- prefix = (parts + [nxt]).join "/"
- name = newname
-
- if name.bytesize > 100
- raise Gem::Package::TooLongFileName.new("File \"#{prefix}/#{name}\" has a too long name (should be 100 or less)")
- end
-
- if prefix.bytesize > 155 then
- raise Gem::Package::TooLongFileName.new("File \"#{prefix}/#{name}\" has a too long base path (should be 155 or less)")
- end
- end
-
- return name, prefix
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/package_task.rb b/ruby_2_2/lib/rubygems/package_task.rb
deleted file mode 100644
index 09384cc0e7..0000000000
--- a/ruby_2_2/lib/rubygems/package_task.rb
+++ /dev/null
@@ -1,128 +0,0 @@
-# Copyright (c) 2003, 2004 Jim Weirich, 2009 Eric Hodel
-#
-# Permission is hereby granted, free of charge, to any person obtaining
-# a copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice shall be
-# included in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-require 'rubygems'
-require 'rubygems/package'
-begin
- gem 'rake'
-rescue Gem::LoadError
-end
-
-require 'rake/packagetask'
-
-##
-# Create a package based upon a Gem::Specification. Gem packages, as well as
-# zip files and tar/gzipped packages can be produced by this task.
-#
-# In addition to the Rake targets generated by Rake::PackageTask, a
-# Gem::PackageTask will also generate the following tasks:
-#
-# [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.gem"</b>]
-# Create a RubyGems package with the given name and version.
-#
-# Example using a Gem::Specification:
-#
-# require 'rubygems'
-# require 'rubygems/package_task'
-#
-# spec = Gem::Specification.new do |s|
-# s.summary = "Ruby based make-like utility."
-# s.name = 'rake'
-# s.version = PKG_VERSION
-# s.requirements << 'none'
-# s.files = PKG_FILES
-# s.description = <<-EOF
-# Rake is a Make-like program implemented in Ruby. Tasks
-# and dependencies are specified in standard Ruby syntax.
-# EOF
-# end
-#
-# Gem::PackageTask.new(spec) do |pkg|
-# pkg.need_zip = true
-# pkg.need_tar = true
-# end
-
-class Gem::PackageTask < Rake::PackageTask
-
- ##
- # Ruby Gem::Specification containing the metadata for this package. The
- # name, version and package_files are automatically determined from the
- # gemspec and don't need to be explicitly provided.
-
- attr_accessor :gem_spec
-
- ##
- # Create a Gem Package task library. Automatically define the gem if a
- # block is given. If no block is supplied, then #define needs to be called
- # to define the task.
-
- def initialize(gem_spec)
- init gem_spec
- yield self if block_given?
- define if block_given?
- end
-
- ##
- # Initialization tasks without the "yield self" or define operations.
-
- def init(gem)
- super gem.full_name, :noversion
- @gem_spec = gem
- @package_files += gem_spec.files if gem_spec.files
- end
-
- ##
- # Create the Rake tasks and actions specified by this Gem::PackageTask.
- # (+define+ is automatically called if a block is given to +new+).
-
- def define
- super
-
- gem_file = File.basename gem_spec.cache_file
- gem_path = File.join package_dir, gem_file
- gem_dir = File.join package_dir, gem_spec.full_name
-
- task :package => [:gem]
-
- directory package_dir
- directory gem_dir
-
- desc "Build the gem file #{gem_file}"
- task :gem => [gem_path]
-
- trace = Rake.application.options.trace
- Gem.configuration.verbose = trace
-
- file gem_path => [package_dir, gem_dir] + @gem_spec.files do
- chdir(gem_dir) do
- when_writing "Creating #{gem_spec.file_name}" do
- Gem::Package.build gem_spec
-
- verbose trace do
- mv gem_file, '..'
- end
- end
- end
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/path_support.rb b/ruby_2_2/lib/rubygems/path_support.rb
deleted file mode 100644
index 2af303eecf..0000000000
--- a/ruby_2_2/lib/rubygems/path_support.rb
+++ /dev/null
@@ -1,87 +0,0 @@
-##
-#
-# Gem::PathSupport facilitates the GEM_HOME and GEM_PATH environment settings
-# to the rest of RubyGems.
-#
-class Gem::PathSupport
- ##
- # The default system path for managing Gems.
- attr_reader :home
-
- ##
- # Array of paths to search for Gems.
- attr_reader :path
-
- ##
- # Directory with spec cache
- attr_reader :spec_cache_dir # :nodoc:
-
- ##
- #
- # Constructor. Takes a single argument which is to be treated like a
- # hashtable, or defaults to ENV, the system environment.
- #
- def initialize(env=ENV)
- @env = env
-
- # note 'env' vs 'ENV'...
- @home = env["GEM_HOME"] || ENV["GEM_HOME"] || Gem.default_dir
-
- if File::ALT_SEPARATOR then
- @home = @home.gsub(File::ALT_SEPARATOR, File::SEPARATOR)
- end
-
- self.path = env["GEM_PATH"] || ENV["GEM_PATH"]
-
- @spec_cache_dir =
- env["GEM_SPEC_CACHE"] || ENV["GEM_SPEC_CACHE"] ||
- Gem.default_spec_cache_dir
-
- @spec_cache_dir = @spec_cache_dir.dup.untaint
- end
-
- private
-
- ##
- # Set the Gem home directory (as reported by Gem.dir).
-
- def home=(home)
- @home = home.to_s
- end
-
- ##
- # Set the Gem search path (as reported by Gem.path).
-
- def path=(gpaths)
- # FIX: it should be [home, *path], not [*path, home]
-
- gem_path = []
-
- # FIX: I can't tell wtf this is doing.
- gpaths ||= (ENV['GEM_PATH'] || "").empty? ? nil : ENV["GEM_PATH"]
-
- if gpaths
- if gpaths.kind_of?(Array)
- gem_path = gpaths.dup
- else
- gem_path = gpaths.split(Gem.path_separator)
- end
-
- if File::ALT_SEPARATOR then
- gem_path.map! do |this_path|
- this_path.gsub File::ALT_SEPARATOR, File::SEPARATOR
- end
- end
-
- gem_path << @home
- else
- gem_path = Gem.default_path + [@home]
-
- if defined?(APPLE_GEM_HOME)
- gem_path << APPLE_GEM_HOME
- end
- end
-
- @path = gem_path.uniq
- end
-end
diff --git a/ruby_2_2/lib/rubygems/platform.rb b/ruby_2_2/lib/rubygems/platform.rb
deleted file mode 100644
index fa56141631..0000000000
--- a/ruby_2_2/lib/rubygems/platform.rb
+++ /dev/null
@@ -1,204 +0,0 @@
-require "rubygems/deprecate"
-
-##
-# Available list of platforms for targeting Gem installations.
-#
-# See `gem help platform` for information on platform matching.
-
-class Gem::Platform
-
- @local = nil
-
- attr_accessor :cpu
-
- attr_accessor :os
-
- attr_accessor :version
-
- def self.local
- arch = RbConfig::CONFIG['arch']
- arch = "#{arch}_60" if arch =~ /mswin(?:32|64)$/
- @local ||= new(arch)
- end
-
- def self.match(platform)
- Gem.platforms.any? do |local_platform|
- platform.nil? or
- local_platform == platform or
- (local_platform != Gem::Platform::RUBY and local_platform =~ platform)
- end
- end
-
- def self.installable?(spec)
- if spec.respond_to? :installable_platform?
- spec.installable_platform?
- else
- match spec.platform
- end
- end
-
- def self.new(arch) # :nodoc:
- case arch
- when Gem::Platform::CURRENT then
- Gem::Platform.local
- when Gem::Platform::RUBY, nil, '' then
- Gem::Platform::RUBY
- else
- super
- end
- end
-
- def initialize(arch)
- case arch
- when Array then
- @cpu, @os, @version = arch
- when String then
- arch = arch.split '-'
-
- if arch.length > 2 and arch.last !~ /\d/ then # reassemble x86-linux-gnu
- extra = arch.pop
- arch.last << "-#{extra}"
- end
-
- cpu = arch.shift
-
- @cpu = case cpu
- when /i\d86/ then 'x86'
- else cpu
- end
-
- if arch.length == 2 and arch.last =~ /^\d+(\.\d+)?$/ then # for command-line
- @os, @version = arch
- return
- end
-
- os, = arch
- @cpu, os = nil, cpu if os.nil? # legacy jruby
-
- @os, @version = case os
- when /aix(\d+)?/ then [ 'aix', $1 ]
- when /cygwin/ then [ 'cygwin', nil ]
- when /darwin(\d+)?/ then [ 'darwin', $1 ]
- when /^macruby$/ then [ 'macruby', nil ]
- when /freebsd(\d+)?/ then [ 'freebsd', $1 ]
- when /hpux(\d+)?/ then [ 'hpux', $1 ]
- when /^java$/, /^jruby$/ then [ 'java', nil ]
- when /^java([\d.]*)/ then [ 'java', $1 ]
- when /^dalvik(\d+)?$/ then [ 'dalvik', $1 ]
- when /^dotnet$/ then [ 'dotnet', nil ]
- when /^dotnet([\d.]*)/ then [ 'dotnet', $1 ]
- when /linux/ then [ 'linux', $1 ]
- when /mingw32/ then [ 'mingw32', nil ]
- when /(mswin\d+)(\_(\d+))?/ then
- os, version = $1, $3
- @cpu = 'x86' if @cpu.nil? and os =~ /32$/
- [os, version]
- when /netbsdelf/ then [ 'netbsdelf', nil ]
- when /openbsd(\d+\.\d+)?/ then [ 'openbsd', $1 ]
- when /solaris(\d+\.\d+)?/ then [ 'solaris', $1 ]
- # test
- when /^(\w+_platform)(\d+)?/ then [ $1, $2 ]
- else [ 'unknown', nil ]
- end
- when Gem::Platform then
- @cpu = arch.cpu
- @os = arch.os
- @version = arch.version
- else
- raise ArgumentError, "invalid argument #{arch.inspect}"
- end
- end
-
- def inspect
- "#<%s:0x%x @cpu=%p, @os=%p, @version=%p>" % [self.class, object_id, *to_a]
- end
-
- def to_a
- [@cpu, @os, @version]
- end
-
- def to_s
- to_a.compact.join '-'
- end
-
- ##
- # Is +other+ equal to this platform? Two platforms are equal if they have
- # the same CPU, OS and version.
-
- def ==(other)
- self.class === other and to_a == other.to_a
- end
-
- alias :eql? :==
-
- def hash # :nodoc:
- to_a.hash
- end
-
- ##
- # Does +other+ match this platform? Two platforms match if they have the
- # same CPU, or either has a CPU of 'universal', they have the same OS, and
- # they have the same version, or either has no version.
- #
- # Additionally, the platform will match if the local CPU is 'arm' and the
- # other CPU starts with "arm" (for generic ARM family support).
-
- def ===(other)
- return nil unless Gem::Platform === other
-
- # cpu
- (@cpu == 'universal' or other.cpu == 'universal' or @cpu == other.cpu or
- (@cpu == 'arm' and other.cpu =~ /\Aarm/)) and
-
- # os
- @os == other.os and
-
- # version
- (@version.nil? or other.version.nil? or @version == other.version)
- end
-
- ##
- # Does +other+ match this platform? If +other+ is a String it will be
- # converted to a Gem::Platform first. See #=== for matching rules.
-
- def =~(other)
- case other
- when Gem::Platform then # nop
- when String then
- # This data is from http://gems.rubyforge.org/gems/yaml on 19 Aug 2007
- other = case other
- when /^i686-darwin(\d)/ then ['x86', 'darwin', $1 ]
- when /^i\d86-linux/ then ['x86', 'linux', nil ]
- when 'java', 'jruby' then [nil, 'java', nil ]
- when /^dalvik(\d+)?$/ then [nil, 'dalvik', $1 ]
- when /dotnet(\-(\d+\.\d+))?/ then ['universal','dotnet', $2 ]
- when /mswin32(\_(\d+))?/ then ['x86', 'mswin32', $2 ]
- when /mswin64(\_(\d+))?/ then ['x64', 'mswin64', $2 ]
- when 'powerpc-darwin' then ['powerpc', 'darwin', nil ]
- when /powerpc-darwin(\d)/ then ['powerpc', 'darwin', $1 ]
- when /sparc-solaris2.8/ then ['sparc', 'solaris', '2.8' ]
- when /universal-darwin(\d)/ then ['universal', 'darwin', $1 ]
- else other
- end
-
- other = Gem::Platform.new other
- else
- return nil
- end
-
- self === other
- end
-
- ##
- # A pure-Ruby gem that may use Gem::Specification#extensions to build
- # binary files.
-
- RUBY = 'ruby'
-
- ##
- # A platform-specific gem that is built for the packaging Ruby's platform.
- # This will be replaced with Gem::Platform::local.
-
- CURRENT = 'current'
-end
-
diff --git a/ruby_2_2/lib/rubygems/psych_additions.rb b/ruby_2_2/lib/rubygems/psych_additions.rb
deleted file mode 100644
index 0e4ebbd50c..0000000000
--- a/ruby_2_2/lib/rubygems/psych_additions.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-# This exists just to satify bugs in marshal'd gemspecs that
-# contain a reference to YAML::PrivateType. We prune these out
-# in Specification._load, but if we don't have the constant, Marshal
-# blows up.
-
-module Psych # :nodoc:
- class PrivateType # :nodoc:
- end
-end
diff --git a/ruby_2_2/lib/rubygems/psych_tree.rb b/ruby_2_2/lib/rubygems/psych_tree.rb
deleted file mode 100644
index e3f1d1a08a..0000000000
--- a/ruby_2_2/lib/rubygems/psych_tree.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-module Gem
- if defined? ::Psych::Visitors
- class NoAliasYAMLTree < Psych::Visitors::YAMLTree
- def self.create
- new({})
- end unless respond_to? :create
-
- def visit_String(str)
- return super unless str == '=' # or whatever you want
-
- quote = Psych::Nodes::Scalar::SINGLE_QUOTED
- @emitter.scalar str, nil, nil, false, true, quote
- end
-
- # Noop this out so there are no anchors
- def register(target, obj)
- end
-
- # This is ported over from the yaml_tree in 1.9.3
- def format_time time
- if time.utc?
- time.strftime("%Y-%m-%d %H:%M:%S.%9N Z")
- else
- time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z")
- end
- end
-
- private :format_time
- end
- end
-end
diff --git a/ruby_2_2/lib/rubygems/rdoc.rb b/ruby_2_2/lib/rubygems/rdoc.rb
deleted file mode 100644
index 180b95fbf3..0000000000
--- a/ruby_2_2/lib/rubygems/rdoc.rb
+++ /dev/null
@@ -1,335 +0,0 @@
-require 'rubygems'
-require 'rubygems/user_interaction'
-require 'fileutils'
-
-begin
- gem 'rdoc'
-rescue Gem::LoadError
- # swallow
-else
- # This will force any deps that 'rdoc' might have
- # (such as json) that are ambiguous to be activated, which
- # is important because we end up using Specification.reset
- # and we don't want the warning it pops out.
- Gem.finish_resolve
-end
-
-loaded_hook = false
-
-begin
- require 'rdoc/rubygems_hook'
- loaded_hook = true
- module Gem
- RDoc = RDoc::RubygemsHook
- end
-rescue LoadError
-end
-
-##
-# Gem::RDoc provides methods to generate RDoc and ri data for installed gems.
-# It works for RDoc 1.0.1 (in Ruby 1.8) up to RDoc 3.6.
-#
-# This implementation is considered obsolete. The RDoc project is the
-# appropriate location to find this functionality. This file provides the
-# hooks to load RDoc generation code from the "rdoc" gem and a fallback in
-# case the installed version of RDoc does not have them.
-
-class Gem::RDoc # :nodoc: all
-
- include Gem::UserInteraction
- extend Gem::UserInteraction
-
- @rdoc_version = nil
- @specs = []
-
- ##
- # Force installation of documentation?
-
- attr_accessor :force
-
- ##
- # Generate rdoc?
-
- attr_accessor :generate_rdoc
-
- ##
- # Generate ri data?
-
- attr_accessor :generate_ri
-
- class << self
-
- ##
- # Loaded version of RDoc. Set by ::load_rdoc
-
- attr_reader :rdoc_version
-
- end
-
- ##
- # Post installs hook that generates documentation for each specification in
- # +specs+
-
- def self.generation_hook installer, specs
- start = Time.now
- types = installer.document
-
- generate_rdoc = types.include? 'rdoc'
- generate_ri = types.include? 'ri'
-
- specs.each do |spec|
- new(spec, generate_rdoc, generate_ri).generate
- end
-
- return unless generate_rdoc or generate_ri
-
- duration = (Time.now - start).to_i
- names = specs.map(&:name).join ', '
-
- say "Done installing documentation for #{names} after #{duration} seconds"
- end
-
- ##
- # Loads the RDoc generator
-
- def self.load_rdoc
- return if @rdoc_version
-
- require 'rdoc/rdoc'
-
- @rdoc_version = if ::RDoc.const_defined? :VERSION then
- Gem::Version.new ::RDoc::VERSION
- else
- Gem::Version.new '1.0.1'
- end
-
- rescue LoadError => e
- raise Gem::DocumentError, "RDoc is not installed: #{e}"
- end
-
- ##
- # Creates a new documentation generator for +spec+. RDoc and ri data
- # generation can be enabled or disabled through +generate_rdoc+ and
- # +generate_ri+ respectively.
- #
- # Only +generate_ri+ is enabled by default.
-
- def initialize spec, generate_rdoc = true, generate_ri = true
- @doc_dir = spec.doc_dir
- @file_info = nil
- @force = false
- @rdoc = nil
- @spec = spec
-
- @generate_rdoc = generate_rdoc
- @generate_ri = generate_ri
-
- @rdoc_dir = spec.doc_dir 'rdoc'
- @ri_dir = spec.doc_dir 'ri'
- end
-
- ##
- # Removes legacy rdoc arguments from +args+
- #--
- # TODO move to RDoc::Options
-
- def delete_legacy_args args
- args.delete '--inline-source'
- args.delete '--promiscuous'
- args.delete '-p'
- args.delete '--one-file'
- end
-
- ##
- # Generates documentation using the named +generator+ ("darkfish" or "ri")
- # and following the given +options+.
- #
- # Documentation will be generated into +destination+
-
- def document generator, options, destination
- generator_name = generator
-
- options = options.dup
- options.exclude ||= [] # TODO maybe move to RDoc::Options#finish
- options.setup_generator generator
- options.op_dir = destination
- options.finish
-
- generator = options.generator.new @rdoc.store, options
-
- @rdoc.options = options
- @rdoc.generator = generator
-
- say "Installing #{generator_name} documentation for #{@spec.full_name}"
-
- FileUtils.mkdir_p options.op_dir
-
- Dir.chdir options.op_dir do
- begin
- @rdoc.class.current = @rdoc
- @rdoc.generator.generate @file_info
- ensure
- @rdoc.class.current = nil
- end
- end
- end
-
- ##
- # Generates RDoc and ri data
-
- def generate
- return unless @generate_ri or @generate_rdoc
-
- setup
-
- options = nil
-
- if Gem::Requirement.new('< 3').satisfied_by? self.class.rdoc_version then
- generate_legacy
- return
- end
-
- ::RDoc::TopLevel.reset # TODO ::RDoc::RDoc.reset
- ::RDoc::Parser::C.reset
-
- args = @spec.rdoc_options
- args.concat @spec.source_paths
- args.concat @spec.extra_rdoc_files
-
- case config_args = Gem.configuration[:rdoc]
- when String then
- args = args.concat config_args.split
- when Array then
- args = args.concat config_args
- end
-
- delete_legacy_args args
-
- Dir.chdir @spec.full_gem_path do
- options = ::RDoc::Options.new
- options.default_title = "#{@spec.full_name} Documentation"
- options.parse args
- end
-
- options.quiet = !Gem.configuration.really_verbose
-
- @rdoc = new_rdoc
- @rdoc.options = options
-
- say "Parsing documentation for #{@spec.full_name}"
-
- Dir.chdir @spec.full_gem_path do
- @file_info = @rdoc.parse_files options.files
- end
-
- document 'ri', options, @ri_dir if
- @generate_ri and (@force or not File.exist? @ri_dir)
-
- document 'darkfish', options, @rdoc_dir if
- @generate_rdoc and (@force or not File.exist? @rdoc_dir)
- end
-
- ##
- # Generates RDoc and ri data for legacy RDoc versions. This method will not
- # exist in future versions.
-
- def generate_legacy
- if @generate_rdoc then
- FileUtils.rm_rf @rdoc_dir
- say "Installing RDoc documentation for #{@spec.full_name}"
- legacy_rdoc '--op', @rdoc_dir
- end
-
- if @generate_ri then
- FileUtils.rm_rf @ri_dir
- say "Installing ri documentation for #{@spec.full_name}"
- legacy_rdoc '--ri', '--op', @ri_dir
- end
- end
-
- ##
- # Generates RDoc using a legacy version of RDoc from the ARGV-like +args+.
- # This method will not exist in future versions.
-
- def legacy_rdoc *args
- args << @spec.rdoc_options
- args << '--quiet'
- args << @spec.require_paths.clone
- args << @spec.extra_rdoc_files
- args << '--title' << "#{@spec.full_name} Documentation"
- args = args.flatten.map do |arg| arg.to_s end
-
- delete_legacy_args args if
- Gem::Requirement.new('>= 2.4.0') =~ self.class.rdoc_version
-
- r = new_rdoc
- verbose { "rdoc #{args.join ' '}" }
-
- Dir.chdir @spec.full_gem_path do
- begin
- r.document args
- rescue Errno::EACCES => e
- dirname = File.dirname e.message.split("-")[1].strip
- raise Gem::FilePermissionError, dirname
- rescue Interrupt => e
- raise e
- rescue Exception => ex
- alert_error "While generating documentation for #{@spec.full_name}"
- ui.errs.puts "... MESSAGE: #{ex}"
- ui.errs.puts "... RDOC args: #{args.join(' ')}"
- ui.backtrace ex
- ui.errs.puts "(continuing with the rest of the installation)"
- end
- end
- end
-
- ##
- # #new_rdoc creates a new RDoc instance. This method is provided only to
- # make testing easier.
-
- def new_rdoc # :nodoc:
- ::RDoc::RDoc.new
- end
-
- ##
- # Is rdoc documentation installed?
-
- def rdoc_installed?
- File.exist? @rdoc_dir
- end
-
- ##
- # Removes generated RDoc and ri data
-
- def remove
- base_dir = @spec.base_dir
-
- raise Gem::FilePermissionError, base_dir unless File.writable? base_dir
-
- FileUtils.rm_rf @rdoc_dir
- FileUtils.rm_rf @ri_dir
- end
-
- ##
- # Is ri data installed?
-
- def ri_installed?
- File.exist? @ri_dir
- end
-
- ##
- # Prepares the spec for documentation generation
-
- def setup
- self.class.load_rdoc
-
- raise Gem::FilePermissionError, @doc_dir if
- File.exist?(@doc_dir) and not File.writable?(@doc_dir)
-
- FileUtils.mkdir_p @doc_dir unless File.exist? @doc_dir
- end
-
-end unless loaded_hook
-
-Gem.done_installing(&Gem::RDoc.method(:generation_hook))
-
diff --git a/ruby_2_2/lib/rubygems/remote_fetcher.rb b/ruby_2_2/lib/rubygems/remote_fetcher.rb
deleted file mode 100644
index 2b9d61c0a1..0000000000
--- a/ruby_2_2/lib/rubygems/remote_fetcher.rb
+++ /dev/null
@@ -1,404 +0,0 @@
-require 'rubygems'
-require 'rubygems/request'
-require 'rubygems/uri_formatter'
-require 'rubygems/user_interaction'
-require 'rubygems/request/connection_pools'
-require 'resolv'
-
-##
-# RemoteFetcher handles the details of fetching gems and gem information from
-# a remote source.
-
-class Gem::RemoteFetcher
-
- include Gem::UserInteraction
-
- ##
- # A FetchError exception wraps up the various possible IO and HTTP failures
- # that could happen while downloading from the internet.
-
- class FetchError < Gem::Exception
-
- ##
- # The URI which was being accessed when the exception happened.
-
- attr_accessor :uri
-
- def initialize(message, uri)
- super message
- @uri = uri
- end
-
- def to_s # :nodoc:
- "#{super} (#{uri})"
- end
-
- end
-
- ##
- # A FetchError that indicates that the reason for not being
- # able to fetch data was that the host could not be contacted
-
- class UnknownHostError < FetchError
- end
-
- @fetcher = nil
-
- ##
- # Cached RemoteFetcher instance.
-
- def self.fetcher
- @fetcher ||= self.new Gem.configuration[:http_proxy]
- end
-
- ##
- # Initialize a remote fetcher using the source URI and possible proxy
- # information.
- #
- # +proxy+
- # * [String]: explicit specification of proxy; overrides any environment
- # variable setting
- # * nil: respect environment variables (HTTP_PROXY, HTTP_PROXY_USER,
- # HTTP_PROXY_PASS)
- # * <tt>:no_proxy</tt>: ignore environment variables and _don't_ use a proxy
- #
- # +dns+: An object to use for DNS resolution of the API endpoint.
- # By default, use Resolv::DNS.
-
- def initialize(proxy=nil, dns=Resolv::DNS.new)
- require 'net/http'
- require 'stringio'
- require 'time'
- require 'uri'
-
- Socket.do_not_reverse_lookup = true
-
- @proxy = proxy
- @pools = {}
- @pool_lock = Mutex.new
- @cert_files = Gem::Request.get_cert_files
-
- @dns = dns
- end
-
- ##
- # Given a source at +uri+, calculate what hostname to actually
- # connect to query the data for it.
-
- def api_endpoint(uri)
- host = uri.host
-
- begin
- res = @dns.getresource "_rubygems._tcp.#{host}",
- Resolv::DNS::Resource::IN::SRV
- rescue Resolv::ResolvError
- uri
- else
- target = res.target.to_s.strip
-
- if URI("http://" + target).host.end_with?(".#{host}")
- return URI.parse "#{uri.scheme}://#{target}#{uri.path}"
- end
-
- uri
- end
- end
-
- ##
- # Given a name and requirement, downloads this gem into cache and returns the
- # filename. Returns nil if the gem cannot be located.
- #--
- # Should probably be integrated with #download below, but that will be a
- # larger, more emcompassing effort. -erikh
-
- def download_to_cache dependency
- found, _ = Gem::SpecFetcher.fetcher.spec_for_dependency dependency
-
- return if found.empty?
-
- spec, source = found.max_by { |(s,_)| s.version }
-
- download spec, source.uri.to_s
- end
-
- ##
- # Moves the gem +spec+ from +source_uri+ to the cache dir unless it is
- # already there. If the source_uri is local the gem cache dir copy is
- # always replaced.
-
- def download(spec, source_uri, install_dir = Gem.dir)
- cache_dir =
- if Dir.pwd == install_dir then # see fetch_command
- install_dir
- elsif File.writable? install_dir then
- File.join install_dir, "cache"
- else
- File.join Gem.user_dir, "cache"
- end
-
- gem_file_name = File.basename spec.cache_file
- local_gem_path = File.join cache_dir, gem_file_name
-
- FileUtils.mkdir_p cache_dir rescue nil unless File.exist? cache_dir
-
- # Always escape URI's to deal with potential spaces and such
- # It should also be considered that source_uri may already be
- # a valid URI with escaped characters. e.g. "{DESede}" is encoded
- # as "%7BDESede%7D". If this is escaped again the percentage
- # symbols will be escaped.
- unless source_uri.is_a?(URI::Generic)
- begin
- source_uri = URI.parse(source_uri)
- rescue
- source_uri = URI.parse(URI.const_defined?(:DEFAULT_PARSER) ?
- URI::DEFAULT_PARSER.escape(source_uri.to_s) :
- URI.escape(source_uri.to_s))
- end
- end
-
- scheme = source_uri.scheme
-
- # URI.parse gets confused by MS Windows paths with forward slashes.
- scheme = nil if scheme =~ /^[a-z]$/i
-
- # REFACTOR: split this up and dispatch on scheme (eg download_http)
- # REFACTOR: be sure to clean up fake fetcher when you do this... cleaner
- case scheme
- when 'http', 'https', 's3' then
- unless File.exist? local_gem_path then
- begin
- verbose "Downloading gem #{gem_file_name}"
-
- remote_gem_path = source_uri + "gems/#{gem_file_name}"
-
- self.cache_update_path remote_gem_path, local_gem_path
- rescue Gem::RemoteFetcher::FetchError
- raise if spec.original_platform == spec.platform
-
- alternate_name = "#{spec.original_name}.gem"
-
- verbose "Failed, downloading gem #{alternate_name}"
-
- remote_gem_path = source_uri + "gems/#{alternate_name}"
-
- self.cache_update_path remote_gem_path, local_gem_path
- end
- end
- when 'file' then
- begin
- path = source_uri.path
- path = File.dirname(path) if File.extname(path) == '.gem'
-
- remote_gem_path = correct_for_windows_path(File.join(path, 'gems', gem_file_name))
-
- FileUtils.cp(remote_gem_path, local_gem_path)
- rescue Errno::EACCES
- local_gem_path = source_uri.to_s
- end
-
- verbose "Using local gem #{local_gem_path}"
- when nil then # TODO test for local overriding cache
- source_path = if Gem.win_platform? && source_uri.scheme &&
- !source_uri.path.include?(':') then
- "#{source_uri.scheme}:#{source_uri.path}"
- else
- source_uri.path
- end
-
- source_path = Gem::UriFormatter.new(source_path).unescape
-
- begin
- FileUtils.cp source_path, local_gem_path unless
- File.identical?(source_path, local_gem_path)
- rescue Errno::EACCES
- local_gem_path = source_uri.to_s
- end
-
- verbose "Using local gem #{local_gem_path}"
- else
- raise ArgumentError, "unsupported URI scheme #{source_uri.scheme}"
- end
-
- local_gem_path
- end
-
- ##
- # File Fetcher. Dispatched by +fetch_path+. Use it instead.
-
- def fetch_file uri, *_
- Gem.read_binary correct_for_windows_path uri.path
- end
-
- ##
- # HTTP Fetcher. Dispatched by +fetch_path+. Use it instead.
-
- def fetch_http uri, last_modified = nil, head = false, depth = 0
- fetch_type = head ? Net::HTTP::Head : Net::HTTP::Get
- response = request uri, fetch_type, last_modified
-
- case response
- when Net::HTTPOK, Net::HTTPNotModified then
- response.uri = uri if response.respond_to? :uri
- head ? response : response.body
- when Net::HTTPMovedPermanently, Net::HTTPFound, Net::HTTPSeeOther,
- Net::HTTPTemporaryRedirect then
- raise FetchError.new('too many redirects', uri) if depth > 10
-
- location = URI.parse response['Location']
-
- if https?(uri) && !https?(location)
- raise FetchError.new("redirecting to non-https resource: #{location}", uri)
- end
-
- fetch_http(location, last_modified, head, depth + 1)
- else
- raise FetchError.new("bad response #{response.message} #{response.code}", uri)
- end
- end
-
- alias :fetch_https :fetch_http
-
- ##
- # Downloads +uri+ and returns it as a String.
-
- def fetch_path(uri, mtime = nil, head = false)
- uri = URI.parse uri unless URI::Generic === uri
-
- raise ArgumentError, "bad uri: #{uri}" unless uri
-
- unless uri.scheme
- raise ArgumentError, "uri scheme is invalid: #{uri.scheme.inspect}"
- end
-
- data = send "fetch_#{uri.scheme}", uri, mtime, head
-
- if data and !head and uri.to_s =~ /\.gz$/
- begin
- data = Gem.gunzip data
- rescue Zlib::GzipFile::Error
- raise FetchError.new("server did not return a valid file", uri.to_s)
- end
- end
-
- data
- rescue FetchError
- raise
- rescue Timeout::Error
- raise UnknownHostError.new('timed out', uri.to_s)
- rescue IOError, SocketError, SystemCallError => e
- if e.message =~ /getaddrinfo/
- raise UnknownHostError.new('no such name', uri.to_s)
- else
- raise FetchError.new("#{e.class}: #{e}", uri.to_s)
- end
- end
-
- def fetch_s3(uri, mtime = nil, head = false)
- public_uri = sign_s3_url(uri)
- fetch_https public_uri, mtime, head
- end
-
- ##
- # Downloads +uri+ to +path+ if necessary. If no path is given, it just
- # passes the data.
-
- def cache_update_path uri, path = nil, update = true
- mtime = path && File.stat(path).mtime rescue nil
-
- data = fetch_path(uri, mtime)
-
- if data == nil # indicates the server returned 304 Not Modified
- return Gem.read_binary(path)
- end
-
- if update and path
- open(path, 'wb') do |io|
- io.flock(File::LOCK_EX)
- io.write data
- end
- end
-
- data
- end
-
- ##
- # Returns the size of +uri+ in bytes.
-
- def fetch_size(uri) # TODO: phase this out
- response = fetch_path(uri, nil, true)
-
- response['content-length'].to_i
- end
-
- def correct_for_windows_path(path)
- if path[0].chr == '/' && path[1].chr =~ /[a-z]/i && path[2].chr == ':'
- path[1..-1]
- else
- path
- end
- end
-
- ##
- # Performs a Net::HTTP request of type +request_class+ on +uri+ returning
- # a Net::HTTP response object. request maintains a table of persistent
- # connections to reduce connect overhead.
-
- def request(uri, request_class, last_modified = nil)
- proxy = proxy_for @proxy, uri
- pool = pools_for(proxy).pool_for uri
-
- request = Gem::Request.new uri, request_class, last_modified, pool
-
- request.fetch do |req|
- yield req if block_given?
- end
- end
-
- def https?(uri)
- uri.scheme.downcase == 'https'
- end
-
- def close_all
- @pools.each_value {|pool| pool.close_all}
- end
-
- protected
-
- # we have our own signing code here to avoid a dependency on the aws-sdk gem
- # fortunately, a simple GET request isn't too complex to sign properly
- def sign_s3_url(uri, expiration = nil)
- require 'base64'
- require 'openssl'
-
- unless uri.user && uri.password
- raise FetchError.new("credentials needed in s3 source, like s3://key:secret@bucket-name/", uri.to_s)
- end
-
- expiration ||= s3_expiration
- canonical_path = "/#{uri.host}#{uri.path}"
- payload = "GET\n\n\n#{expiration}\n#{canonical_path}"
- digest = OpenSSL::HMAC.digest('sha1', uri.password, payload)
- # URI.escape is deprecated, and there isn't yet a replacement that does quite what we want
- signature = Base64.encode64(digest).gsub("\n", '').gsub(/[\+\/=]/) { |c| BASE64_URI_TRANSLATE[c] }
- URI.parse("https://#{uri.host}.s3.amazonaws.com#{uri.path}?AWSAccessKeyId=#{uri.user}&Expires=#{expiration}&Signature=#{signature}")
- end
-
- def s3_expiration
- (Time.now + 3600).to_i # one hour from now
- end
-
- BASE64_URI_TRANSLATE = { '+' => '%2B', '/' => '%2F', '=' => '%3D' }.freeze
-
- private
-
- def proxy_for proxy, uri
- Gem::Request.proxy_uri(proxy || Gem::Request.get_proxy_from_env(uri.scheme))
- end
-
- def pools_for proxy
- @pool_lock.synchronize do
- @pools[proxy] ||= Gem::Request::ConnectionPools.new proxy, @cert_files
- end
- end
-end
-
diff --git a/ruby_2_2/lib/rubygems/request.rb b/ruby_2_2/lib/rubygems/request.rb
deleted file mode 100644
index 702769c500..0000000000
--- a/ruby_2_2/lib/rubygems/request.rb
+++ /dev/null
@@ -1,244 +0,0 @@
-require 'net/http'
-require 'thread'
-require 'time'
-require 'rubygems/user_interaction'
-
-class Gem::Request
-
- include Gem::UserInteraction
-
- ###
- # Legacy. This is used in tests.
- def self.create_with_proxy uri, request_class, last_modified, proxy # :nodoc:
- cert_files = get_cert_files
- proxy ||= get_proxy_from_env(uri.scheme)
- pool = ConnectionPools.new proxy_uri(proxy), cert_files
-
- new(uri, request_class, last_modified, pool.pool_for(uri))
- end
-
- def self.proxy_uri proxy # :nodoc:
- case proxy
- when :no_proxy then nil
- when URI::HTTP then proxy
- else URI.parse(proxy)
- end
- end
-
- def initialize(uri, request_class, last_modified, pool)
- @uri = uri
- @request_class = request_class
- @last_modified = last_modified
- @requests = Hash.new 0
- @user_agent = user_agent
-
- @connection_pool = pool
- end
-
- def proxy_uri; @connection_pool.proxy_uri; end
- def cert_files; @connection_pool.cert_files; end
-
- def self.get_cert_files
- pattern = File.expand_path("./ssl_certs/*.pem", File.dirname(__FILE__))
- Dir.glob(pattern)
- end
-
- def self.configure_connection_for_https(connection, cert_files)
- require 'net/https'
- connection.use_ssl = true
- connection.verify_mode =
- Gem.configuration.ssl_verify_mode || OpenSSL::SSL::VERIFY_PEER
- store = OpenSSL::X509::Store.new
-
- if Gem.configuration.ssl_client_cert then
- pem = File.read Gem.configuration.ssl_client_cert
- connection.cert = OpenSSL::X509::Certificate.new pem
- connection.key = OpenSSL::PKey::RSA.new pem
- end
-
- store.set_default_paths
- cert_files.each do |ssl_cert_file|
- store.add_file ssl_cert_file
- end
- if Gem.configuration.ssl_ca_cert
- if File.directory? Gem.configuration.ssl_ca_cert
- store.add_path Gem.configuration.ssl_ca_cert
- else
- store.add_file Gem.configuration.ssl_ca_cert
- end
- end
- connection.cert_store = store
- connection
- rescue LoadError => e
- raise unless (e.respond_to?(:path) && e.path == 'openssl') ||
- e.message =~ / -- openssl$/
-
- raise Gem::Exception.new(
- 'Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources')
- end
-
- ##
- # Creates or an HTTP connection based on +uri+, or retrieves an existing
- # connection, using a proxy if needed.
-
- def connection_for(uri)
- @connection_pool.checkout
- rescue defined?(OpenSSL::SSL) ? OpenSSL::SSL::SSLError : Errno::EHOSTDOWN,
- Errno::EHOSTDOWN => e
- raise Gem::RemoteFetcher::FetchError.new(e.message, uri)
- end
-
- def fetch
- request = @request_class.new @uri.request_uri
-
- unless @uri.nil? || @uri.user.nil? || @uri.user.empty? then
- request.basic_auth Gem::UriFormatter.new(@uri.user).unescape,
- Gem::UriFormatter.new(@uri.password).unescape
- end
-
- request.add_field 'User-Agent', @user_agent
- request.add_field 'Connection', 'keep-alive'
- request.add_field 'Keep-Alive', '30'
-
- if @last_modified then
- request.add_field 'If-Modified-Since', @last_modified.httpdate
- end
-
- yield request if block_given?
-
- perform_request request
- end
-
- ##
- # Returns a proxy URI for the given +scheme+ if one is set in the
- # environment variables.
-
- def self.get_proxy_from_env scheme = 'http'
- _scheme = scheme.downcase
- _SCHEME = scheme.upcase
- env_proxy = ENV["#{_scheme}_proxy"] || ENV["#{_SCHEME}_PROXY"]
-
- no_env_proxy = env_proxy.nil? || env_proxy.empty?
-
- return get_proxy_from_env 'http' if no_env_proxy and _scheme != 'http'
- return :no_proxy if no_env_proxy
-
- uri = URI(Gem::UriFormatter.new(env_proxy).normalize)
-
- if uri and uri.user.nil? and uri.password.nil? then
- user = ENV["#{_scheme}_proxy_user"] || ENV["#{_SCHEME}_PROXY_USER"]
- password = ENV["#{_scheme}_proxy_pass"] || ENV["#{_SCHEME}_PROXY_PASS"]
-
- uri.user = Gem::UriFormatter.new(user).escape
- uri.password = Gem::UriFormatter.new(password).escape
- end
-
- uri
- end
-
- def perform_request request # :nodoc:
- connection = connection_for @uri
-
- retried = false
- bad_response = false
-
- begin
- @requests[connection.object_id] += 1
-
- verbose "#{request.method} #{@uri}"
-
- file_name = File.basename(@uri.path)
- # perform download progress reporter only for gems
- if request.response_body_permitted? && file_name =~ /\.gem$/
- reporter = ui.download_reporter
- response = connection.request(request) do |incomplete_response|
- if Net::HTTPOK === incomplete_response
- reporter.fetch(file_name, incomplete_response.content_length)
- downloaded = 0
- data = ''
-
- incomplete_response.read_body do |segment|
- data << segment
- downloaded += segment.length
- reporter.update(downloaded)
- end
- reporter.done
- if incomplete_response.respond_to? :body=
- incomplete_response.body = data
- else
- incomplete_response.instance_variable_set(:@body, data)
- end
- end
- end
- else
- response = connection.request request
- end
-
- verbose "#{response.code} #{response.message}"
-
- rescue Net::HTTPBadResponse
- verbose "bad response"
-
- reset connection
-
- raise Gem::RemoteFetcher::FetchError.new('too many bad responses', @uri) if bad_response
-
- bad_response = true
- retry
- # HACK work around EOFError bug in Net::HTTP
- # NOTE Errno::ECONNABORTED raised a lot on Windows, and make impossible
- # to install gems.
- rescue EOFError, Timeout::Error,
- Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EPIPE
-
- requests = @requests[connection.object_id]
- verbose "connection reset after #{requests} requests, retrying"
-
- raise Gem::RemoteFetcher::FetchError.new('too many connection resets', @uri) if retried
-
- reset connection
-
- retried = true
- retry
- end
-
- response
- ensure
- @connection_pool.checkin connection
- end
-
- ##
- # Resets HTTP connection +connection+.
-
- def reset(connection)
- @requests.delete connection.object_id
-
- connection.finish
- connection.start
- end
-
- def user_agent
- ua = "RubyGems/#{Gem::VERSION} #{Gem::Platform.local}"
-
- ruby_version = RUBY_VERSION
- ruby_version += 'dev' if RUBY_PATCHLEVEL == -1
-
- ua << " Ruby/#{ruby_version} (#{RUBY_RELEASE_DATE}"
- if RUBY_PATCHLEVEL >= 0 then
- ua << " patchlevel #{RUBY_PATCHLEVEL}"
- elsif defined?(RUBY_REVISION) then
- ua << " revision #{RUBY_REVISION}"
- end
- ua << ")"
-
- ua << " #{RUBY_ENGINE}" if defined?(RUBY_ENGINE) and RUBY_ENGINE != 'ruby'
-
- ua
- end
-
-end
-
-require 'rubygems/request/http_pool'
-require 'rubygems/request/https_pool'
-require 'rubygems/request/connection_pools'
-
diff --git a/ruby_2_2/lib/rubygems/request/connection_pools.rb b/ruby_2_2/lib/rubygems/request/connection_pools.rb
deleted file mode 100644
index 7a0a6e6e74..0000000000
--- a/ruby_2_2/lib/rubygems/request/connection_pools.rb
+++ /dev/null
@@ -1,83 +0,0 @@
-require 'thread'
-
-class Gem::Request::ConnectionPools # :nodoc:
-
- @client = Net::HTTP
-
- class << self
- attr_accessor :client
- end
-
- def initialize proxy_uri, cert_files
- @proxy_uri = proxy_uri
- @cert_files = cert_files
- @pools = {}
- @pool_mutex = Mutex.new
- end
-
- def pool_for uri
- http_args = net_http_args(uri, @proxy_uri)
- key = http_args + [https?(uri)]
- @pool_mutex.synchronize do
- @pools[key] ||=
- if https? uri then
- Gem::Request::HTTPSPool.new(http_args, @cert_files, @proxy_uri)
- else
- Gem::Request::HTTPPool.new(http_args, @cert_files, @proxy_uri)
- end
- end
- end
-
- def close_all
- @pools.each_value {|pool| pool.close_all}
- end
-
- private
-
- ##
- # Returns list of no_proxy entries (if any) from the environment
-
- def get_no_proxy_from_env
- env_no_proxy = ENV['no_proxy'] || ENV['NO_PROXY']
-
- return [] if env_no_proxy.nil? or env_no_proxy.empty?
-
- env_no_proxy.split(/\s*,\s*/)
- end
-
- def https? uri
- uri.scheme.downcase == 'https'
- end
-
- def no_proxy? host, env_no_proxy
- host = host.downcase
-
- env_no_proxy.any? do |pattern|
- pattern = pattern.downcase
-
- host[-pattern.length, pattern.length] == pattern or
- (pattern.start_with? '.' and pattern[1..-1] == host)
- end
- end
-
- def net_http_args uri, proxy_uri
- net_http_args = [uri.host, uri.port]
-
- no_proxy = get_no_proxy_from_env
-
- if proxy_uri and not no_proxy?(uri.host, no_proxy) then
- net_http_args + [
- proxy_uri.host,
- proxy_uri.port,
- Gem::UriFormatter.new(proxy_uri.user).unescape,
- Gem::UriFormatter.new(proxy_uri.password).unescape,
- ]
- elsif no_proxy? uri.host, no_proxy then
- net_http_args + [nil, nil]
- else
- net_http_args
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/request/http_pool.rb b/ruby_2_2/lib/rubygems/request/http_pool.rb
deleted file mode 100644
index c9a1858b98..0000000000
--- a/ruby_2_2/lib/rubygems/request/http_pool.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-##
-# A connection "pool" that only manages one connection for now. Provides
-# thread safe `checkout` and `checkin` methods. The pool consists of one
-# connection that corresponds to `http_args`. This class is private, do not
-# use it.
-
-class Gem::Request::HTTPPool # :nodoc:
- attr_reader :cert_files, :proxy_uri
-
- def initialize http_args, cert_files, proxy_uri
- @http_args = http_args
- @cert_files = cert_files
- @proxy_uri = proxy_uri
- @queue = SizedQueue.new 1
- @queue << nil
- end
-
- def checkout
- @queue.pop || make_connection
- end
-
- def checkin connection
- @queue.push connection
- end
-
- def close_all
- until @queue.empty?
- if connection = @queue.pop(true) and connection.started?
- connection.finish
- end
- end
- @queue.push(nil)
- end
-
- private
-
- def make_connection
- setup_connection Gem::Request::ConnectionPools.client.new(*@http_args)
- end
-
- def setup_connection connection
- connection.start
- connection
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/request/https_pool.rb b/ruby_2_2/lib/rubygems/request/https_pool.rb
deleted file mode 100644
index 2e3da0a44e..0000000000
--- a/ruby_2_2/lib/rubygems/request/https_pool.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-class Gem::Request::HTTPSPool < Gem::Request::HTTPPool # :nodoc:
- private
-
- def setup_connection connection
- Gem::Request.configure_connection_for_https(connection, @cert_files)
- super
- end
-end
-
-
diff --git a/ruby_2_2/lib/rubygems/request_set.rb b/ruby_2_2/lib/rubygems/request_set.rb
deleted file mode 100644
index 05bfcbee2c..0000000000
--- a/ruby_2_2/lib/rubygems/request_set.rb
+++ /dev/null
@@ -1,413 +0,0 @@
-require 'tsort'
-
-##
-# A RequestSet groups a request to activate a set of dependencies.
-#
-# nokogiri = Gem::Dependency.new 'nokogiri', '~> 1.6'
-# pg = Gem::Dependency.new 'pg', '~> 0.14'
-#
-# set = Gem::RequestSet.new nokogiri, pg
-#
-# requests = set.resolve
-#
-# p requests.map { |r| r.full_name }
-# #=> ["nokogiri-1.6.0", "mini_portile-0.5.1", "pg-0.17.0"]
-
-class Gem::RequestSet
-
- include TSort
-
- ##
- # Array of gems to install even if already installed
-
- attr_accessor :always_install
-
- attr_reader :dependencies
-
- attr_accessor :development
-
- ##
- # Errors fetching gems during resolution.
-
- attr_reader :errors
-
- ##
- # Set to true if you want to install only direct development dependencies.
-
- attr_accessor :development_shallow
-
- ##
- # The set of git gems imported via load_gemdeps.
-
- attr_reader :git_set # :nodoc:
-
- ##
- # When true, dependency resolution is not performed, only the requested gems
- # are installed.
-
- attr_accessor :ignore_dependencies
-
- attr_reader :install_dir # :nodoc:
-
- ##
- # If true, allow dependencies to match prerelease gems.
-
- attr_accessor :prerelease
-
- ##
- # When false no remote sets are used for resolving gems.
-
- attr_accessor :remote
-
- attr_reader :resolver # :nodoc:
-
- ##
- # Sets used for resolution
-
- attr_reader :sets # :nodoc:
-
- ##
- # Treat missing dependencies as silent errors
-
- attr_accessor :soft_missing
-
- ##
- # The set of vendor gems imported via load_gemdeps.
-
- attr_reader :vendor_set # :nodoc:
-
- ##
- # Creates a RequestSet for a list of Gem::Dependency objects, +deps+. You
- # can then #resolve and #install the resolved list of dependencies.
- #
- # nokogiri = Gem::Dependency.new 'nokogiri', '~> 1.6'
- # pg = Gem::Dependency.new 'pg', '~> 0.14'
- #
- # set = Gem::RequestSet.new nokogiri, pg
-
- def initialize *deps
- @dependencies = deps
-
- @always_install = []
- @conservative = false
- @dependency_names = {}
- @development = false
- @development_shallow = false
- @errors = []
- @git_set = nil
- @ignore_dependencies = false
- @install_dir = Gem.dir
- @prerelease = false
- @remote = true
- @requests = []
- @sets = []
- @soft_missing = false
- @sorted = nil
- @specs = nil
- @vendor_set = nil
-
- yield self if block_given?
- end
-
- ##
- # Declare that a gem of name +name+ with +reqs+ requirements is needed.
-
- def gem name, *reqs
- if dep = @dependency_names[name] then
- dep.requirement.concat reqs
- else
- dep = Gem::Dependency.new name, reqs
- @dependency_names[name] = dep
- @dependencies << dep
- end
- end
-
- ##
- # Add +deps+ Gem::Dependency objects to the set.
-
- def import deps
- @dependencies.concat deps
- end
-
- ##
- # Installs gems for this RequestSet using the Gem::Installer +options+.
- #
- # If a +block+ is given an activation +request+ and +installer+ are yielded.
- # The +installer+ will be +nil+ if a gem matching the request was already
- # installed.
-
- def install options, &block # :yields: request, installer
- if dir = options[:install_dir]
- requests = install_into dir, false, options, &block
- return requests
- end
-
- cache_dir = options[:cache_dir] || Gem.dir
- @prerelease = options[:prerelease]
-
- requests = []
-
- sorted_requests.each do |req|
- if req.installed? then
- req.spec.spec.build_extensions
-
- if @always_install.none? { |spec| spec == req.spec.spec } then
- yield req, nil if block_given?
- next
- end
- end
-
- path = req.download cache_dir
-
- inst = Gem::Installer.new path, options
-
- yield req, inst if block_given?
-
- requests << inst.install
- end
-
- requests
- ensure
- raise if $!
- return requests if options[:gemdeps]
-
- specs = requests.map do |request|
- case request
- when Gem::Resolver::ActivationRequest then
- request.spec.spec
- else
- request
- end
- end
-
- require 'rubygems/dependency_installer'
- inst = Gem::DependencyInstaller.new options
- inst.installed_gems.replace specs
-
- Gem.done_installing_hooks.each do |hook|
- hook.call inst, specs
- end unless Gem.done_installing_hooks.empty?
- end
-
- ##
- # Installs from the gem dependencies files in the +:gemdeps+ option in
- # +options+, yielding to the +block+ as in #install.
- #
- # If +:without_groups+ is given in the +options+, those groups in the gem
- # dependencies file are not used. See Gem::Installer for other +options+.
-
- def install_from_gemdeps options, &block
- gemdeps = options[:gemdeps]
-
- @install_dir = options[:install_dir] || Gem.dir
- @prerelease = options[:prerelease]
- @remote = options[:domain] != :local
- @conservative = true if options[:conservative]
-
- gem_deps_api = load_gemdeps gemdeps, options[:without_groups], true
-
- resolve
-
- if options[:explain]
- puts "Gems to install:"
-
- sorted_requests.each do |spec|
- puts " #{spec.full_name}"
- end
-
- if Gem.configuration.really_verbose
- @resolver.stats.display
- end
- else
- installed = install options, &block
-
- if options.fetch :lock, true then
- lockfile =
- Gem::RequestSet::Lockfile.new self, gemdeps, gem_deps_api.dependencies
- lockfile.write
- end
-
- installed
- end
- end
-
- def install_into dir, force = true, options = {}
- gem_home, ENV['GEM_HOME'] = ENV['GEM_HOME'], dir
-
- existing = force ? [] : specs_in(dir)
- existing.delete_if { |s| @always_install.include? s }
-
- dir = File.expand_path dir
-
- installed = []
-
- options[:development] = false
- options[:install_dir] = dir
- options[:only_install_dir] = true
- @prerelease = options[:prerelease]
-
- sorted_requests.each do |request|
- spec = request.spec
-
- if existing.find { |s| s.full_name == spec.full_name } then
- yield request, nil if block_given?
- next
- end
-
- spec.install options do |installer|
- yield request, installer if block_given?
- end
-
- installed << request
- end
-
- installed
- ensure
- ENV['GEM_HOME'] = gem_home
- end
-
- ##
- # Load a dependency management file.
-
- def load_gemdeps path, without_groups = [], installing = false
- @git_set = Gem::Resolver::GitSet.new
- @vendor_set = Gem::Resolver::VendorSet.new
-
- @git_set.root_dir = @install_dir
-
- lockfile = Gem::RequestSet::Lockfile.new self, path
- lockfile.parse
-
- gf = Gem::RequestSet::GemDependencyAPI.new self, path
- gf.installing = installing
- gf.without_groups = without_groups if without_groups
- gf.load
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[RequestSet:', ']' do
- q.breakable
-
- if @remote then
- q.text 'remote'
- q.breakable
- end
-
- if @prerelease then
- q.text 'prerelease'
- q.breakable
- end
-
- if @development_shallow then
- q.text 'shallow development'
- q.breakable
- elsif @development then
- q.text 'development'
- q.breakable
- end
-
- if @soft_missing then
- q.text 'soft missing'
- end
-
- q.group 2, '[dependencies:', ']' do
- q.breakable
- @dependencies.map do |dep|
- q.text dep.to_s
- q.breakable
- end
- end
-
- q.breakable
- q.text 'sets:'
-
- q.breakable
- q.pp @sets.map { |set| set.class }
- end
- end
-
- ##
- # Resolve the requested dependencies and return an Array of Specification
- # objects to be activated.
-
- def resolve set = Gem::Resolver::BestSet.new
- @sets << set
- @sets << @git_set
- @sets << @vendor_set
-
- set = Gem::Resolver.compose_sets(*@sets)
- set.remote = @remote
- set.prerelease = @prerelease
-
- resolver = Gem::Resolver.new @dependencies, set
- resolver.development = @development
- resolver.development_shallow = @development_shallow
- resolver.ignore_dependencies = @ignore_dependencies
- resolver.soft_missing = @soft_missing
-
- if @conservative
- installed_gems = {}
- Gem::Specification.find_all do |spec|
- (installed_gems[spec.name] ||= []) << spec
- end
- resolver.skip_gems = installed_gems
- end
-
- @resolver = resolver
-
- @requests = resolver.resolve
-
- @errors = set.errors
-
- @requests
- end
-
- ##
- # Resolve the requested dependencies against the gems available via Gem.path
- # and return an Array of Specification objects to be activated.
-
- def resolve_current
- resolve Gem::Resolver::CurrentSet.new
- end
-
- def sorted_requests
- @sorted ||= strongly_connected_components.flatten
- end
-
- def specs
- @specs ||= @requests.map { |r| r.full_spec }
- end
-
- def specs_in dir
- Dir["#{dir}/specifications/*.gemspec"].map do |g|
- Gem::Specification.load g
- end
- end
-
- def tsort_each_node &block # :nodoc:
- @requests.each(&block)
- end
-
- def tsort_each_child node # :nodoc:
- node.spec.dependencies.each do |dep|
- next if dep.type == :development and not @development
-
- match = @requests.find { |r|
- dep.match? r.spec.name, r.spec.version, @prerelease
- }
-
- unless match then
- next if dep.type == :development and @development_shallow
- next if @soft_missing
- raise Gem::DependencyError,
- "Unresolved dependency found during sorting - #{dep} (requested by #{node.spec.full_name})"
- end
-
- yield match
- end
- end
-
-end
-
-require 'rubygems/request_set/gem_dependency_api'
-require 'rubygems/request_set/lockfile'
diff --git a/ruby_2_2/lib/rubygems/request_set/gem_dependency_api.rb b/ruby_2_2/lib/rubygems/request_set/gem_dependency_api.rb
deleted file mode 100644
index 9aad5ab5d3..0000000000
--- a/ruby_2_2/lib/rubygems/request_set/gem_dependency_api.rb
+++ /dev/null
@@ -1,801 +0,0 @@
-##
-# A semi-compatible DSL for the Bundler Gemfile and Isolate gem dependencies
-# files.
-#
-# To work with both the Bundler Gemfile and Isolate formats this
-# implementation takes some liberties to allow compatibility with each, most
-# notably in #source.
-#
-# A basic gem dependencies file will look like the following:
-#
-# source 'https://rubygems.org'
-#
-# gem 'rails', '3.2.14a
-# gem 'devise', '~> 2.1', '>= 2.1.3'
-# gem 'cancan'
-# gem 'airbrake'
-# gem 'pg'
-#
-# RubyGems recommends saving this as gem.deps.rb over Gemfile or Isolate.
-#
-# To install the gems in this Gemfile use `gem install -g` to install it and
-# create a lockfile. The lockfile will ensure that when you make changes to
-# your gem dependencies file a minimum amount of change is made to the
-# dependencies of your gems.
-#
-# RubyGems can activate all the gems in your dependencies file at startup
-# using the RUBYGEMS_GEMDEPS environment variable or through Gem.use_gemdeps.
-# See Gem.use_gemdeps for details and warnings.
-#
-# See `gem help install` and `gem help gem_dependencies` for further details.
-
-class Gem::RequestSet::GemDependencyAPI
-
- ENGINE_MAP = { # :nodoc:
- :jruby => %w[jruby],
- :jruby_18 => %w[jruby],
- :jruby_19 => %w[jruby],
- :maglev => %w[maglev],
- :mri => %w[ruby],
- :mri_18 => %w[ruby],
- :mri_19 => %w[ruby],
- :mri_20 => %w[ruby],
- :mri_21 => %w[ruby],
- :rbx => %w[rbx],
- :ruby => %w[ruby rbx maglev],
- :ruby_18 => %w[ruby rbx maglev],
- :ruby_19 => %w[ruby rbx maglev],
- :ruby_20 => %w[ruby rbx maglev],
- :ruby_21 => %w[ruby rbx maglev],
- }
-
- mswin = Gem::Platform.new 'x86-mswin32'
- mswin64 = Gem::Platform.new 'x64-mswin64'
- x86_mingw = Gem::Platform.new 'x86-mingw32'
- x64_mingw = Gem::Platform.new 'x64-mingw32'
-
- PLATFORM_MAP = { # :nodoc:
- :jruby => Gem::Platform::RUBY,
- :jruby_18 => Gem::Platform::RUBY,
- :jruby_19 => Gem::Platform::RUBY,
- :maglev => Gem::Platform::RUBY,
- :mingw => x86_mingw,
- :mingw_18 => x86_mingw,
- :mingw_19 => x86_mingw,
- :mingw_20 => x86_mingw,
- :mingw_21 => x86_mingw,
- :mri => Gem::Platform::RUBY,
- :mri_18 => Gem::Platform::RUBY,
- :mri_19 => Gem::Platform::RUBY,
- :mri_20 => Gem::Platform::RUBY,
- :mri_21 => Gem::Platform::RUBY,
- :mswin => mswin,
- :mswin_18 => mswin,
- :mswin_19 => mswin,
- :mswin_20 => mswin,
- :mswin_21 => mswin,
- :mswin64 => mswin64,
- :mswin64_19 => mswin64,
- :mswin64_20 => mswin64,
- :mswin64_21 => mswin64,
- :rbx => Gem::Platform::RUBY,
- :ruby => Gem::Platform::RUBY,
- :ruby_18 => Gem::Platform::RUBY,
- :ruby_19 => Gem::Platform::RUBY,
- :ruby_20 => Gem::Platform::RUBY,
- :ruby_21 => Gem::Platform::RUBY,
- :x64_mingw => x64_mingw,
- :x64_mingw_20 => x64_mingw,
- :x64_mingw_21 => x64_mingw
- }
-
- gt_eq_0 = Gem::Requirement.new '>= 0'
- tilde_gt_1_8_0 = Gem::Requirement.new '~> 1.8.0'
- tilde_gt_1_9_0 = Gem::Requirement.new '~> 1.9.0'
- tilde_gt_2_0_0 = Gem::Requirement.new '~> 2.0.0'
- tilde_gt_2_1_0 = Gem::Requirement.new '~> 2.1.0'
-
- VERSION_MAP = { # :nodoc:
- :jruby => gt_eq_0,
- :jruby_18 => tilde_gt_1_8_0,
- :jruby_19 => tilde_gt_1_9_0,
- :maglev => gt_eq_0,
- :mingw => gt_eq_0,
- :mingw_18 => tilde_gt_1_8_0,
- :mingw_19 => tilde_gt_1_9_0,
- :mingw_20 => tilde_gt_2_0_0,
- :mingw_21 => tilde_gt_2_1_0,
- :mri => gt_eq_0,
- :mri_18 => tilde_gt_1_8_0,
- :mri_19 => tilde_gt_1_9_0,
- :mri_20 => tilde_gt_2_0_0,
- :mri_21 => tilde_gt_2_1_0,
- :mswin => gt_eq_0,
- :mswin_18 => tilde_gt_1_8_0,
- :mswin_19 => tilde_gt_1_9_0,
- :mswin_20 => tilde_gt_2_0_0,
- :mswin_21 => tilde_gt_2_1_0,
- :mswin64 => gt_eq_0,
- :mswin64_19 => tilde_gt_1_9_0,
- :mswin64_20 => tilde_gt_2_0_0,
- :mswin64_21 => tilde_gt_2_1_0,
- :rbx => gt_eq_0,
- :ruby => gt_eq_0,
- :ruby_18 => tilde_gt_1_8_0,
- :ruby_19 => tilde_gt_1_9_0,
- :ruby_20 => tilde_gt_2_0_0,
- :ruby_21 => tilde_gt_2_1_0,
- :x64_mingw => gt_eq_0,
- :x64_mingw_20 => tilde_gt_2_0_0,
- :x64_mingw_21 => tilde_gt_2_1_0,
- }
-
- WINDOWS = { # :nodoc:
- :mingw => :only,
- :mingw_18 => :only,
- :mingw_19 => :only,
- :mingw_20 => :only,
- :mingw_21 => :only,
- :mri => :never,
- :mri_18 => :never,
- :mri_19 => :never,
- :mri_20 => :never,
- :mri_21 => :never,
- :mswin => :only,
- :mswin_18 => :only,
- :mswin_19 => :only,
- :mswin_20 => :only,
- :mswin_21 => :only,
- :mswin64 => :only,
- :mswin64_19 => :only,
- :mswin64_20 => :only,
- :mswin64_21 => :only,
- :rbx => :never,
- :ruby => :never,
- :ruby_18 => :never,
- :ruby_19 => :never,
- :ruby_20 => :never,
- :ruby_21 => :never,
- :x64_mingw => :only,
- :x64_mingw_20 => :only,
- :x64_mingw_21 => :only,
- }
-
- ##
- # The gems required by #gem statements in the gem.deps.rb file
-
- attr_reader :dependencies
-
- ##
- # A set of gems that are loaded via the +:git+ option to #gem
-
- attr_reader :git_set # :nodoc:
-
- ##
- # A Hash containing gem names and files to require from those gems.
-
- attr_reader :requires # :nodoc:
-
- ##
- # A set of gems that are loaded via the +:path+ option to #gem
-
- attr_reader :vendor_set # :nodoc:
-
- ##
- # The groups of gems to exclude from installation
-
- attr_accessor :without_groups # :nodoc:
-
- ##
- # Creates a new GemDependencyAPI that will add dependencies to the
- # Gem::RequestSet +set+ based on the dependency API description in +path+.
-
- def initialize set, path
- @set = set
- @path = path
-
- @current_groups = nil
- @current_platforms = nil
- @current_repository = nil
- @dependencies = {}
- @default_sources = true
- @git_set = @set.git_set
- @git_sources = {}
- @installing = false
- @requires = Hash.new { |h, name| h[name] = [] }
- @vendor_set = @set.vendor_set
- @gem_sources = {}
- @without_groups = []
-
- git_source :github do |repo_name|
- repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include? "/"
-
- "git://github.com/#{repo_name}.git"
- end
-
- git_source :bitbucket do |repo_name|
- repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include? "/"
-
- user, = repo_name.split "/", 2
-
- "https://#{user}@bitbucket.org/#{repo_name}.git"
- end
- end
-
- ##
- # Adds +dependencies+ to the request set if any of the +groups+ are allowed.
- # This is used for gemspec dependencies.
-
- def add_dependencies groups, dependencies # :nodoc:
- return unless (groups & @without_groups).empty?
-
- dependencies.each do |dep|
- @set.gem dep.name, *dep.requirement
- end
- end
-
- private :add_dependencies
-
- ##
- # Finds a gemspec with the given +name+ that lives at +path+.
-
- def find_gemspec name, path # :nodoc:
- glob = File.join path, "#{name}.gemspec"
-
- spec_files = Dir[glob]
-
- case spec_files.length
- when 1 then
- spec_file = spec_files.first
-
- spec = Gem::Specification.load spec_file
-
- return spec if spec
-
- raise ArgumentError, "invalid gemspec #{spec_file}"
- when 0 then
- raise ArgumentError, "no gemspecs found at #{Dir.pwd}"
- else
- raise ArgumentError,
- "found multiple gemspecs at #{Dir.pwd}, " +
- "use the name: option to specify the one you want"
- end
- end
-
- ##
- # Changes the behavior of gem dependency file loading to installing mode.
- # In installing mode certain restrictions are ignored such as ruby version
- # mismatch checks.
-
- def installing= installing # :nodoc:
- @installing = installing
- end
-
- ##
- # Loads the gem dependency file and returns self.
-
- def load
- instance_eval File.read(@path).untaint, @path, 1
-
- self
- end
-
- ##
- # :category: Gem Dependencies DSL
- #
- # :call-seq:
- # gem(name)
- # gem(name, *requirements)
- # gem(name, *requirements, options)
- #
- # Specifies a gem dependency with the given +name+ and +requirements+. You
- # may also supply +options+ following the +requirements+
- #
- # +options+ include:
- #
- # require: ::
- # RubyGems does not provide any autorequire features so requires in a gem
- # dependencies file are recorded but ignored.
- #
- # In bundler the require: option overrides the file to require during
- # Bundler.require. By default the name of the dependency is required in
- # Bundler. A single file or an Array of files may be given.
- #
- # To disable requiring any file give +false+:
- #
- # gem 'rake', require: false
- #
- # group: ::
- # Place the dependencies in the given dependency group. A single group or
- # an Array of groups may be given.
- #
- # See also #group
- #
- # platform: ::
- # Only install the dependency on the given platform. A single platform or
- # an Array of platforms may be given.
- #
- # See #platform for a list of platforms available.
- #
- # path: ::
- # Install this dependency from an unpacked gem in the given directory.
- #
- # gem 'modified_gem', path: 'vendor/modified_gem'
- #
- # git: ::
- # Install this dependency from a git repository:
- #
- # gem 'private_gem', git: git@my.company.example:private_gem.git'
- #
- # gist: ::
- # Install this dependency from the gist ID:
- #
- # gem 'bang', gist: '1232884'
- #
- # github: ::
- # Install this dependency from a github git repository:
- #
- # gem 'private_gem', github: 'my_company/private_gem'
- #
- # submodules: ::
- # Set to +true+ to include submodules when fetching the git repository for
- # git:, gist: and github: dependencies.
- #
- # ref: ::
- # Use the given commit name or SHA for git:, gist: and github:
- # dependencies.
- #
- # branch: ::
- # Use the given branch for git:, gist: and github: dependencies.
- #
- # tag: ::
- # Use the given tag for git:, gist: and github: dependencies.
-
- def gem name, *requirements
- options = requirements.pop if requirements.last.kind_of?(Hash)
- options ||= {}
-
- options[:git] = @current_repository if @current_repository
-
- source_set = false
-
- source_set ||= gem_path name, options
- source_set ||= gem_git name, options
- source_set ||= gem_git_source name, options
-
- duplicate = @dependencies.include? name
-
- @dependencies[name] =
- if requirements.empty? and not source_set then
- nil
- elsif source_set then
- '!'
- else
- requirements
- end
-
- return unless gem_platforms options
-
- groups = gem_group name, options
-
- return unless (groups & @without_groups).empty?
-
- pin_gem_source name, :default unless source_set
-
- gem_requires name, options
-
- if duplicate then
- warn <<-WARNING
-Gem dependencies file #{@path} requires #{name} more than once.
- WARNING
- end
-
- @set.gem name, *requirements
- end
-
- ##
- # Handles the git: option from +options+ for gem +name+.
- #
- # Returns +true+ if the path option was handled.
-
- def gem_git name, options # :nodoc:
- if gist = options.delete(:gist) then
- options[:git] = "https://gist.github.com/#{gist}.git"
- end
-
- return unless repository = options.delete(:git)
-
- pin_gem_source name, :git, repository
-
- reference = nil
- reference ||= options.delete :ref
- reference ||= options.delete :branch
- reference ||= options.delete :tag
- reference ||= 'master'
-
- submodules = options.delete :submodules
-
- @git_set.add_git_gem name, repository, reference, submodules
-
- true
- end
-
- private :gem_git
-
- ##
- # Handles a git gem option from +options+ for gem +name+ for a git source
- # registered through git_source.
- #
- # Returns +true+ if the custom source option was handled.
-
- def gem_git_source name, options # :nodoc:
- return unless git_source = (@git_sources.keys & options.keys).last
-
- source_callback = @git_sources[git_source]
- source_param = options.delete git_source
-
- git_url = source_callback.call source_param
-
- options[:git] = git_url
-
- gem_git name, options
-
- true
- end
-
- private :gem_git_source
-
- ##
- # Handles the :group and :groups +options+ for the gem with the given
- # +name+.
-
- def gem_group name, options # :nodoc:
- g = options.delete :group
- all_groups = g ? Array(g) : []
-
- groups = options.delete :groups
- all_groups |= groups if groups
-
- all_groups |= @current_groups if @current_groups
-
- all_groups
- end
-
- private :gem_group
-
- ##
- # Handles the path: option from +options+ for gem +name+.
- #
- # Returns +true+ if the path option was handled.
-
- def gem_path name, options # :nodoc:
- return unless directory = options.delete(:path)
-
- pin_gem_source name, :path, directory
-
- @vendor_set.add_vendor_gem name, directory
-
- true
- end
-
- private :gem_path
-
- ##
- # Handles the platforms: option from +options+. Returns true if the
- # platform matches the current platform.
-
- def gem_platforms options # :nodoc:
- platform_names = Array(options.delete :platform)
- platform_names.concat Array(options.delete :platforms)
- platform_names.concat @current_platforms if @current_platforms
-
- return true if platform_names.empty?
-
- platform_names.any? do |platform_name|
- raise ArgumentError, "unknown platform #{platform_name.inspect}" unless
- platform = PLATFORM_MAP[platform_name]
-
- next false unless Gem::Platform.match platform
-
- if engines = ENGINE_MAP[platform_name] then
- next false unless engines.include? Gem.ruby_engine
- end
-
- case WINDOWS[platform_name]
- when :only then
- next false unless Gem.win_platform?
- when :never then
- next false if Gem.win_platform?
- end
-
- VERSION_MAP[platform_name].satisfied_by? Gem.ruby_version
- end
- end
-
- private :gem_platforms
-
- ##
- # Records the require: option from +options+ and adds those files, or the
- # default file to the require list for +name+.
-
- def gem_requires name, options # :nodoc:
- if options.include? :require then
- if requires = options.delete(:require) then
- @requires[name].concat Array requires
- end
- else
- @requires[name] << name
- end
- end
-
- private :gem_requires
-
- ##
- # :category: Gem Dependencies DSL
- #
- # Block form for specifying gems from a git +repository+.
- #
- # git 'https://github.com/rails/rails.git' do
- # gem 'activesupport'
- # gem 'activerecord'
- # end
-
- def git repository
- @current_repository = repository
-
- yield
-
- ensure
- @current_repository = nil
- end
-
- ##
- # Defines a custom git source that uses +name+ to expand git repositories
- # for use in gems built from git repositories. You must provide a block
- # that accepts a git repository name for expansion.
-
- def git_source name, &callback
- @git_sources[name] = callback
- end
-
- ##
- # Returns the basename of the file the dependencies were loaded from
-
- def gem_deps_file # :nodoc:
- File.basename @path
- end
-
- ##
- # :category: Gem Dependencies DSL
- #
- # Loads dependencies from a gemspec file.
- #
- # +options+ include:
- #
- # name: ::
- # The name portion of the gemspec file. Defaults to searching for any
- # gemspec file in the current directory.
- #
- # gemspec name: 'my_gem'
- #
- # path: ::
- # The path the gemspec lives in. Defaults to the current directory:
- #
- # gemspec 'my_gem', path: 'gemspecs', name: 'my_gem'
- #
- # development_group: ::
- # The group to add development dependencies to. By default this is
- # :development. Only one group may be specified.
-
- def gemspec options = {}
- name = options.delete(:name) || '{,*}'
- path = options.delete(:path) || '.'
- development_group = options.delete(:development_group) || :development
-
- spec = find_gemspec name, path
-
- groups = gem_group spec.name, {}
-
- self_dep = Gem::Dependency.new spec.name, spec.version
-
- add_dependencies groups, [self_dep]
- add_dependencies groups, spec.runtime_dependencies
-
- @dependencies[spec.name] = '!'
-
- spec.dependencies.each do |dep|
- @dependencies[dep.name] = dep.requirement
- end
-
- groups << development_group
-
- add_dependencies groups, spec.development_dependencies
-
- gem_requires spec.name, options
- end
-
- ##
- # :category: Gem Dependencies DSL
- #
- # Block form for placing a dependency in the given +groups+.
- #
- # group :development do
- # gem 'debugger'
- # end
- #
- # group :development, :test do
- # gem 'minitest'
- # end
- #
- # Groups can be excluded at install time using `gem install -g --without
- # development`. See `gem help install` and `gem help gem_dependencies` for
- # further details.
-
- def group *groups
- @current_groups = groups
-
- yield
-
- ensure
- @current_groups = nil
- end
-
- ##
- # Pins the gem +name+ to the given +source+. Adding a gem with the same
- # name from a different +source+ will raise an exception.
-
- def pin_gem_source name, type = :default, source = nil
- source_description =
- case type
- when :default then '(default)'
- when :path then "path: #{source}"
- when :git then "git: #{source}"
- else '(unknown)'
- end
-
- raise ArgumentError,
- "duplicate source #{source_description} for gem #{name}" if
- @gem_sources.fetch(name, source) != source
-
- @gem_sources[name] = source
- end
-
- private :pin_gem_source
-
- ##
- # :category: Gem Dependencies DSL
- #
- # Block form for restricting gems to a set of platforms.
- #
- # The gem dependencies platform is different from Gem::Platform. A platform
- # gem.deps.rb platform matches on the ruby engine, the ruby version and
- # whether or not windows is allowed.
- #
- # :ruby, :ruby_XY ::
- # Matches non-windows, non-jruby implementations where X and Y can be used
- # to match releases in the 1.8, 1.9, 2.0 or 2.1 series.
- #
- # :mri, :mri_XY ::
- # Matches non-windows C Ruby (Matz Ruby) or only the 1.8, 1.9, 2.0 or
- # 2.1 series.
- #
- # :mingw, :mingw_XY ::
- # Matches 32 bit C Ruby on MinGW or only the 1.8, 1.9, 2.0 or 2.1 series.
- #
- # :x64_mingw, :x64_mingw_XY ::
- # Matches 64 bit C Ruby on MinGW or only the 1.8, 1.9, 2.0 or 2.1 series.
- #
- # :mswin, :mswin_XY ::
- # Matches 32 bit C Ruby on Microsoft Windows or only the 1.8, 1.9, 2.0 or
- # 2.1 series.
- #
- # :mswin64, :mswin64_XY ::
- # Matches 64 bit C Ruby on Microsoft Windows or only the 1.8, 1.9, 2.0 or
- # 2.1 series.
- #
- # :jruby, :jruby_XY ::
- # Matches JRuby or JRuby in 1.8 or 1.9 mode.
- #
- # :maglev ::
- # Matches Maglev
- #
- # :rbx ::
- # Matches non-windows Rubinius
- #
- # NOTE: There is inconsistency in what environment a platform matches. You
- # may need to read the source to know the exact details.
-
- def platform *platforms
- @current_platforms = platforms
-
- yield
-
- ensure
- @current_platforms = nil
- end
-
- ##
- # :category: Gem Dependencies DSL
- #
- # Block form for restricting gems to a particular set of platforms. See
- # #platform.
-
- alias :platforms :platform
-
- ##
- # :category: Gem Dependencies DSL
- #
- # Restricts this gem dependencies file to the given ruby +version+.
- #
- # You may also provide +engine:+ and +engine_version:+ options to restrict
- # this gem dependencies file to a particular ruby engine and its engine
- # version. This matching is performed by using the RUBY_ENGINE and
- # engine_specific VERSION constants. (For JRuby, JRUBY_VERSION).
-
- def ruby version, options = {}
- engine = options[:engine]
- engine_version = options[:engine_version]
-
- raise ArgumentError,
- 'you must specify engine_version along with the ruby engine' if
- engine and not engine_version
-
- return true if @installing
-
- unless RUBY_VERSION == version then
- message = "Your Ruby version is #{RUBY_VERSION}, " +
- "but your #{gem_deps_file} requires #{version}"
-
- raise Gem::RubyVersionMismatch, message
- end
-
- if engine and engine != Gem.ruby_engine then
- message = "Your ruby engine is #{Gem.ruby_engine}, " +
- "but your #{gem_deps_file} requires #{engine}"
-
- raise Gem::RubyVersionMismatch, message
- end
-
- if engine_version then
- my_engine_version = Object.const_get "#{Gem.ruby_engine.upcase}_VERSION"
-
- if engine_version != my_engine_version then
- message =
- "Your ruby engine version is #{Gem.ruby_engine} #{my_engine_version}, " +
- "but your #{gem_deps_file} requires #{engine} #{engine_version}"
-
- raise Gem::RubyVersionMismatch, message
- end
- end
-
- return true
- end
-
- ##
- # :category: Gem Dependencies DSL
- #
- # Sets +url+ as a source for gems for this dependency API. RubyGems uses
- # the default configured sources if no source was given. If a source is set
- # only that source is used.
- #
- # This method differs in behavior from Bundler:
- #
- # * The +:gemcutter+, # +:rubygems+ and +:rubyforge+ sources are not
- # supported as they are deprecated in bundler.
- # * The +prepend:+ option is not supported. If you wish to order sources
- # then list them in your preferred order.
-
- def source url
- Gem.sources.clear if @default_sources
-
- @default_sources = false
-
- Gem.sources << url
- end
-
- # TODO: remove this typo name at RubyGems 3.0
-
- Gem::RequestSet::GemDepedencyAPI = self # :nodoc:
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/request_set/lockfile.rb b/ruby_2_2/lib/rubygems/request_set/lockfile.rb
deleted file mode 100644
index 4f2fa0933f..0000000000
--- a/ruby_2_2/lib/rubygems/request_set/lockfile.rb
+++ /dev/null
@@ -1,650 +0,0 @@
-require 'strscan'
-
-##
-# Parses a gem.deps.rb.lock file and constructs a LockSet containing the
-# dependencies found inside. If the lock file is missing no LockSet is
-# constructed.
-
-class Gem::RequestSet::Lockfile
-
- ##
- # Raised when a lockfile cannot be parsed
-
- class ParseError < Gem::Exception
-
- ##
- # The column where the error was encountered
-
- attr_reader :column
-
- ##
- # The line where the error was encountered
-
- attr_reader :line
-
- ##
- # The location of the lock file
-
- attr_reader :path
-
- ##
- # Raises a ParseError with the given +message+ which was encountered at a
- # +line+ and +column+ while parsing.
-
- def initialize message, column, line, path
- @line = line
- @column = column
- @path = path
- super "#{message} (at line #{line} column #{column})"
- end
-
- end
-
- ##
- # The platforms for this Lockfile
-
- attr_reader :platforms
-
- ##
- # Creates a new Lockfile for the given +request_set+ and +gem_deps_file+
- # location.
-
- def initialize request_set, gem_deps_file, dependencies = nil
- @set = request_set
- @dependencies = dependencies
- @gem_deps_file = File.expand_path(gem_deps_file)
- @gem_deps_dir = File.dirname(@gem_deps_file)
-
- @gem_deps_file.untaint unless gem_deps_file.tainted?
-
- @current_token = nil
- @line = 0
- @line_pos = 0
- @platforms = []
- @tokens = []
- end
-
- def add_DEPENDENCIES out # :nodoc:
- out << "DEPENDENCIES"
-
- dependencies =
- if @dependencies then
- @dependencies.sort_by { |name,| name }.map do |name, requirement|
- requirement_string =
- if '!' == requirement then
- requirement
- else
- Gem::Requirement.new(requirement).for_lockfile
- end
-
- [name, requirement_string]
- end
- else
- @requests.sort_by { |r| r.name }.map do |request|
- spec = request.spec
- name = request.name
- requirement = request.request.dependency.requirement
-
- requirement_string =
- if [Gem::Resolver::VendorSpecification,
- Gem::Resolver::GitSpecification].include? spec.class then
- "!"
- else
- requirement.for_lockfile
- end
-
- [name, requirement_string]
- end
- end
-
- dependencies = dependencies.map do |name, requirement_string|
- " #{name}#{requirement_string}"
- end
-
- out.concat dependencies
-
- out << nil
- end
-
- def add_GEM out # :nodoc:
- return if @spec_groups.empty?
-
- source_groups = @spec_groups.values.flatten.group_by do |request|
- request.spec.source.uri
- end
-
- source_groups.sort_by { |group,| group.to_s }.map do |group, requests|
- out << "GEM"
- out << " remote: #{group}"
- out << " specs:"
-
- requests.sort_by { |request| request.name }.each do |request|
- next if request.spec.name == 'bundler'
- platform = "-#{request.spec.platform}" unless
- Gem::Platform::RUBY == request.spec.platform
-
- out << " #{request.name} (#{request.version}#{platform})"
-
- request.full_spec.dependencies.sort.each do |dependency|
- next if dependency.type == :development
-
- requirement = dependency.requirement
- out << " #{dependency.name}#{requirement.for_lockfile}"
- end
- end
- out << nil
- end
- end
-
- def add_GIT out
- return unless git_requests =
- @spec_groups.delete(Gem::Resolver::GitSpecification)
-
- by_repository_revision = git_requests.group_by do |request|
- source = request.spec.source
- [source.repository, source.rev_parse]
- end
-
- out << "GIT"
- by_repository_revision.each do |(repository, revision), requests|
- out << " remote: #{repository}"
- out << " revision: #{revision}"
- out << " specs:"
-
- requests.sort_by { |request| request.name }.each do |request|
- out << " #{request.name} (#{request.version})"
-
- dependencies = request.spec.dependencies.sort_by { |dep| dep.name }
- dependencies.each do |dep|
- out << " #{dep.name}#{dep.requirement.for_lockfile}"
- end
- end
- end
-
- out << nil
- end
-
- def relative_path_from dest, base # :nodoc:
- dest = File.expand_path(dest)
- base = File.expand_path(base)
-
- if dest.index(base) == 0 then
- offset = dest[base.size+1..-1]
-
- return '.' unless offset
-
- offset
- else
- dest
- end
- end
-
- def add_PATH out # :nodoc:
- return unless path_requests =
- @spec_groups.delete(Gem::Resolver::VendorSpecification)
-
- out << "PATH"
- path_requests.each do |request|
- directory = File.expand_path(request.spec.source.uri)
-
- out << " remote: #{relative_path_from directory, @gem_deps_dir}"
- out << " specs:"
- out << " #{request.name} (#{request.version})"
- end
-
- out << nil
- end
-
- def add_PLATFORMS out # :nodoc:
- out << "PLATFORMS"
-
- platforms = @requests.map { |request| request.spec.platform }.uniq
-
- platforms = platforms.sort_by { |platform| platform.to_s }
-
- platforms.sort.each do |platform|
- out << " #{platform}"
- end
-
- out << nil
- end
-
- ##
- # Gets the next token for a Lockfile
-
- def get expected_types = nil, expected_value = nil # :nodoc:
- @current_token = @tokens.shift
-
- type, value, column, line = @current_token
-
- if expected_types and not Array(expected_types).include? type then
- unget
-
- message = "unexpected token [#{type.inspect}, #{value.inspect}], " +
- "expected #{expected_types.inspect}"
-
- raise ParseError.new message, column, line, "#{@gem_deps_file}.lock"
- end
-
- if expected_value and expected_value != value then
- unget
-
- message = "unexpected token [#{type.inspect}, #{value.inspect}], " +
- "expected [#{expected_types.inspect}, " +
- "#{expected_value.inspect}]"
-
- raise ParseError.new message, column, line, "#{@gem_deps_file}.lock"
- end
-
- @current_token
- end
-
- def parse # :nodoc:
- tokenize
-
- until @tokens.empty? do
- type, data, column, line = get
-
- case type
- when :section then
- skip :newline
-
- case data
- when 'DEPENDENCIES' then
- parse_DEPENDENCIES
- when 'GIT' then
- parse_GIT
- when 'GEM' then
- parse_GEM
- when 'PATH' then
- parse_PATH
- when 'PLATFORMS' then
- parse_PLATFORMS
- else
- type, = get until @tokens.empty? or peek.first == :section
- end
- else
- raise "BUG: unhandled token #{type} (#{data.inspect}) at line #{line} column #{column}"
- end
- end
- end
-
- def parse_DEPENDENCIES # :nodoc:
- while not @tokens.empty? and :text == peek.first do
- _, name, = get :text
-
- requirements = []
-
- case peek[0]
- when :bang then
- get :bang
-
- requirements << pinned_requirement(name)
- when :l_paren then
- get :l_paren
-
- loop do
- _, op, = get :requirement
- _, version, = get :text
-
- requirements << "#{op} #{version}"
-
- break unless peek[0] == :comma
-
- get :comma
- end
-
- get :r_paren
-
- if peek[0] == :bang then
- requirements.clear
- requirements << pinned_requirement(name)
-
- get :bang
- end
- end
-
- @set.gem name, *requirements
-
- skip :newline
- end
- end
-
- def parse_GEM # :nodoc:
- sources = []
-
- while [:entry, 'remote'] == peek.first(2) do
- get :entry, 'remote'
- _, data, = get :text
- skip :newline
-
- sources << Gem::Source.new(data)
- end
-
- sources << Gem::Source.new(Gem::DEFAULT_HOST) if sources.empty?
-
- get :entry, 'specs'
-
- skip :newline
-
- set = Gem::Resolver::LockSet.new sources
- last_specs = nil
-
- while not @tokens.empty? and :text == peek.first do
- _, name, column, = get :text
-
- case peek[0]
- when :newline then
- last_specs.each do |spec|
- spec.add_dependency Gem::Dependency.new name if column == 6
- end
- when :l_paren then
- get :l_paren
-
- type, data, = get [:text, :requirement]
-
- if type == :text and column == 4 then
- version, platform = data.split '-', 2
-
- platform =
- platform ? Gem::Platform.new(platform) : Gem::Platform::RUBY
-
- last_specs = set.add name, version, platform
- else
- dependency = parse_dependency name, data
-
- last_specs.each do |spec|
- spec.add_dependency dependency
- end
- end
-
- get :r_paren
- else
- raise "BUG: unknown token #{peek}"
- end
-
- skip :newline
- end
-
- @set.sets << set
- end
-
- def parse_GIT # :nodoc:
- get :entry, 'remote'
- _, repository, = get :text
-
- skip :newline
-
- get :entry, 'revision'
- _, revision, = get :text
-
- skip :newline
-
- type, value = peek.first 2
- if type == :entry and %w[branch ref tag].include? value then
- get
- get :text
-
- skip :newline
- end
-
- get :entry, 'specs'
-
- skip :newline
-
- set = Gem::Resolver::GitSet.new
- set.root_dir = @set.install_dir
-
- last_spec = nil
-
- while not @tokens.empty? and :text == peek.first do
- _, name, column, = get :text
-
- case peek[0]
- when :newline then
- last_spec.add_dependency Gem::Dependency.new name if column == 6
- when :l_paren then
- get :l_paren
-
- type, data, = get [:text, :requirement]
-
- if type == :text and column == 4 then
- last_spec = set.add_git_spec name, data, repository, revision, true
- else
- dependency = parse_dependency name, data
-
- last_spec.add_dependency dependency
- end
-
- get :r_paren
- else
- raise "BUG: unknown token #{peek}"
- end
-
- skip :newline
- end
-
- @set.sets << set
- end
-
- def parse_PATH # :nodoc:
- get :entry, 'remote'
- _, directory, = get :text
-
- skip :newline
-
- get :entry, 'specs'
-
- skip :newline
-
- set = Gem::Resolver::VendorSet.new
- last_spec = nil
-
- while not @tokens.empty? and :text == peek.first do
- _, name, column, = get :text
-
- case peek[0]
- when :newline then
- last_spec.add_dependency Gem::Dependency.new name if column == 6
- when :l_paren then
- get :l_paren
-
- type, data, = get [:text, :requirement]
-
- if type == :text and column == 4 then
- last_spec = set.add_vendor_gem name, directory
- else
- dependency = parse_dependency name, data
-
- last_spec.dependencies << dependency
- end
-
- get :r_paren
- else
- raise "BUG: unknown token #{peek}"
- end
-
- skip :newline
- end
-
- @set.sets << set
- end
-
- def parse_PLATFORMS # :nodoc:
- while not @tokens.empty? and :text == peek.first do
- _, name, = get :text
-
- @platforms << name
-
- skip :newline
- end
- end
-
- ##
- # Parses the requirements following the dependency +name+ and the +op+ for
- # the first token of the requirements and returns a Gem::Dependency object.
-
- def parse_dependency name, op # :nodoc:
- return Gem::Dependency.new name, op unless peek[0] == :text
-
- _, version, = get :text
-
- requirements = ["#{op} #{version}"]
-
- while peek[0] == :comma do
- get :comma
- _, op, = get :requirement
- _, version, = get :text
-
- requirements << "#{op} #{version}"
- end
-
- Gem::Dependency.new name, requirements
- end
-
- ##
- # Peeks at the next token for Lockfile
-
- def peek # :nodoc:
- @tokens.first || [:EOF]
- end
-
- def pinned_requirement name # :nodoc:
- spec = @set.sets.select { |set|
- Gem::Resolver::GitSet === set or
- Gem::Resolver::VendorSet === set
- }.map { |set|
- set.specs[name]
- }.compact.first
-
- spec.version
- end
-
- def skip type # :nodoc:
- get while not @tokens.empty? and peek.first == type
- end
-
- ##
- # The contents of the lock file.
-
- def to_s
- @set.resolve
-
- out = []
-
- @requests = @set.sorted_requests
-
- @spec_groups = @requests.group_by do |request|
- request.spec.class
- end
-
- add_PATH out
-
- add_GIT out
-
- add_GEM out
-
- add_PLATFORMS out
-
- add_DEPENDENCIES out
-
- out.join "\n"
- end
-
- ##
- # Calculates the column (by byte) and the line of the current token based on
- # +byte_offset+.
-
- def token_pos byte_offset # :nodoc:
- [byte_offset - @line_pos, @line]
- end
-
- ##
- # Converts a lock file into an Array of tokens. If the lock file is missing
- # an empty Array is returned.
-
- def tokenize # :nodoc:
- @line = 0
- @line_pos = 0
-
- @platforms = []
- @tokens = []
- @current_token = nil
-
- lock_file = "#{@gem_deps_file}.lock"
-
- @input = File.read lock_file
- s = StringScanner.new @input
-
- until s.eos? do
- pos = s.pos
-
- pos = s.pos if leading_whitespace = s.scan(/ +/)
-
- if s.scan(/[<|=>]{7}/) then
- message = "your #{lock_file} contains merge conflict markers"
- column, line = token_pos pos
-
- raise ParseError.new message, column, line, lock_file
- end
-
- @tokens <<
- case
- when s.scan(/\r?\n/) then
- token = [:newline, nil, *token_pos(pos)]
- @line_pos = s.pos
- @line += 1
- token
- when s.scan(/[A-Z]+/) then
- if leading_whitespace then
- text = s.matched
- text += s.scan(/[^\s)]*/).to_s # in case of no match
- [:text, text, *token_pos(pos)]
- else
- [:section, s.matched, *token_pos(pos)]
- end
- when s.scan(/([a-z]+):\s/) then
- s.pos -= 1 # rewind for possible newline
- [:entry, s[1], *token_pos(pos)]
- when s.scan(/\(/) then
- [:l_paren, nil, *token_pos(pos)]
- when s.scan(/\)/) then
- [:r_paren, nil, *token_pos(pos)]
- when s.scan(/<=|>=|=|~>|<|>|!=/) then
- [:requirement, s.matched, *token_pos(pos)]
- when s.scan(/,/) then
- [:comma, nil, *token_pos(pos)]
- when s.scan(/!/) then
- [:bang, nil, *token_pos(pos)]
- when s.scan(/[^\s),!]*/) then
- [:text, s.matched, *token_pos(pos)]
- else
- raise "BUG: can't create token for: #{s.string[s.pos..-1].inspect}"
- end
- end
-
- @tokens
- rescue Errno::ENOENT
- @tokens
- end
-
- ##
- # Ungets the last token retrieved by #get
-
- def unget # :nodoc:
- @tokens.unshift @current_token
- end
-
- ##
- # Writes the lock file alongside the gem dependencies file
-
- def write
- content = to_s
-
- open "#{@gem_deps_file}.lock", 'w' do |io|
- io.write content
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/requirement.rb b/ruby_2_2/lib/rubygems/requirement.rb
deleted file mode 100644
index 8b6a81612c..0000000000
--- a/ruby_2_2/lib/rubygems/requirement.rb
+++ /dev/null
@@ -1,273 +0,0 @@
-require "rubygems/version"
-require "rubygems/deprecate"
-
-# If we're being loaded after yaml was already required, then
-# load our yaml + workarounds now.
-Gem.load_yaml if defined? ::YAML
-
-##
-# A Requirement is a set of one or more version restrictions. It supports a
-# few (<tt>=, !=, >, <, >=, <=, ~></tt>) different restriction operators.
-#
-# See Gem::Version for a description on how versions and requirements work
-# together in RubyGems.
-
-class Gem::Requirement
- OPS = { #:nodoc:
- "=" => lambda { |v, r| v == r },
- "!=" => lambda { |v, r| v != r },
- ">" => lambda { |v, r| v > r },
- "<" => lambda { |v, r| v < r },
- ">=" => lambda { |v, r| v >= r },
- "<=" => lambda { |v, r| v <= r },
- "~>" => lambda { |v, r| v >= r && v.release < r.bump }
- }
-
- quoted = OPS.keys.map { |k| Regexp.quote k }.join "|"
- PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{Gem::Version::VERSION_PATTERN})\\s*" # :nodoc:
-
- ##
- # A regular expression that matches a requirement
-
- PATTERN = /\A#{PATTERN_RAW}\z/
-
- ##
- # The default requirement matches any version
-
- DefaultRequirement = [">=", Gem::Version.new(0)]
-
- ##
- # Raised when a bad requirement is encountered
-
- class BadRequirementError < ArgumentError; end
-
- ##
- # Factory method to create a Gem::Requirement object. Input may be
- # a Version, a String, or nil. Intended to simplify client code.
- #
- # If the input is "weird", the default version requirement is
- # returned.
-
- def self.create input
- case input
- when Gem::Requirement then
- input
- when Gem::Version, Array then
- new input
- else
- if input.respond_to? :to_str then
- new [input.to_str]
- else
- default
- end
- end
- end
-
- ##
- # A default "version requirement" can surely _only_ be '>= 0'.
-
- def self.default
- new '>= 0'
- end
-
- ##
- # Parse +obj+, returning an <tt>[op, version]</tt> pair. +obj+ can
- # be a String or a Gem::Version.
- #
- # If +obj+ is a String, it can be either a full requirement
- # specification, like <tt>">= 1.2"</tt>, or a simple version number,
- # like <tt>"1.2"</tt>.
- #
- # parse("> 1.0") # => [">", "1.0"]
- # parse("1.0") # => ["=", "1.0"]
- # parse(Gem::Version.new("1.0")) # => ["=, "1.0"]
-
- def self.parse obj
- return ["=", obj] if Gem::Version === obj
-
- unless PATTERN =~ obj.to_s
- raise BadRequirementError, "Illformed requirement [#{obj.inspect}]"
- end
-
- if $1 == ">=" && $2 == "0"
- DefaultRequirement
- else
- [$1 || "=", Gem::Version.new($2)]
- end
- end
-
- ##
- # An array of requirement pairs. The first element of the pair is
- # the op, and the second is the Gem::Version.
-
- attr_reader :requirements #:nodoc:
-
- ##
- # Constructs a requirement from +requirements+. Requirements can be
- # Strings, Gem::Versions, or Arrays of those. +nil+ and duplicate
- # requirements are ignored. An empty set of +requirements+ is the
- # same as <tt>">= 0"</tt>.
-
- def initialize *requirements
- requirements = requirements.flatten
- requirements.compact!
- requirements.uniq!
-
- if requirements.empty?
- @requirements = [DefaultRequirement]
- else
- @requirements = requirements.map! { |r| self.class.parse r }
- end
- end
-
- ##
- # Concatenates the +new+ requirements onto this requirement.
-
- def concat new
- new = new.flatten
- new.compact!
- new.uniq!
- new = new.map { |r| self.class.parse r }
-
- @requirements.concat new
- end
-
- ##
- # Formats this requirement for use in a Gem::RequestSet::Lockfile.
-
- def for_lockfile # :nodoc:
- return if [DefaultRequirement] == @requirements
-
- list = requirements.sort_by { |_, version|
- version
- }.map { |op, version|
- "#{op} #{version}"
- }.uniq
-
- " (#{list.join ', '})"
- end
-
- ##
- # true if this gem has no requirements.
-
- def none?
- if @requirements.size == 1
- @requirements[0] == DefaultRequirement
- else
- false
- end
- end
-
- ##
- # true if the requirement is for only an exact version
-
- def exact?
- return false unless @requirements.size == 1
- @requirements[0][0] == "="
- end
-
- def as_list # :nodoc:
- requirements.map { |op, version| "#{op} #{version}" }.sort
- end
-
- def hash # :nodoc:
- requirements.hash
- end
-
- def marshal_dump # :nodoc:
- fix_syck_default_key_in_requirements
-
- [@requirements]
- end
-
- def marshal_load array # :nodoc:
- @requirements = array[0]
-
- fix_syck_default_key_in_requirements
- end
-
- def yaml_initialize(tag, vals) # :nodoc:
- vals.each do |ivar, val|
- instance_variable_set "@#{ivar}", val
- end
-
- Gem.load_yaml
- fix_syck_default_key_in_requirements
- end
-
- def init_with coder # :nodoc:
- yaml_initialize coder.tag, coder.map
- end
-
- def to_yaml_properties # :nodoc:
- ["@requirements"]
- end
-
- def encode_with coder # :nodoc:
- coder.add 'requirements', @requirements
- end
-
- ##
- # A requirement is a prerelease if any of the versions inside of it
- # are prereleases
-
- def prerelease?
- requirements.any? { |r| r.last.prerelease? }
- end
-
- def pretty_print q # :nodoc:
- q.group 1, 'Gem::Requirement.new(', ')' do
- q.pp as_list
- end
- end
-
- ##
- # True if +version+ satisfies this Requirement.
-
- def satisfied_by? version
- raise ArgumentError, "Need a Gem::Version: #{version.inspect}" unless
- Gem::Version === version
- # #28965: syck has a bug with unquoted '=' YAML.loading as YAML::DefaultKey
- requirements.all? { |op, rv| (OPS[op] || OPS["="]).call version, rv }
- end
-
- alias :=== :satisfied_by?
- alias :=~ :satisfied_by?
-
- ##
- # True if the requirement will not always match the latest version.
-
- def specific?
- return true if @requirements.length > 1 # GIGO, > 1, > 2 is silly
-
- not %w[> >=].include? @requirements.first.first # grab the operator
- end
-
- def to_s # :nodoc:
- as_list.join ", "
- end
-
- def == other # :nodoc:
- Gem::Requirement === other and to_s == other.to_s
- end
-
- private
-
- def fix_syck_default_key_in_requirements # :nodoc:
- Gem.load_yaml
-
- # Fixup the Syck DefaultKey bug
- @requirements.each do |r|
- if r[0].kind_of? Gem::SyckDefaultKey
- r[0] = "="
- end
- end
- end
-end
-
-class Gem::Version
- # This is needed for compatibility with older yaml
- # gemspecs.
-
- Requirement = Gem::Requirement # :nodoc:
-end
diff --git a/ruby_2_2/lib/rubygems/resolver.rb b/ruby_2_2/lib/rubygems/resolver.rb
deleted file mode 100644
index ef17d682ac..0000000000
--- a/ruby_2_2/lib/rubygems/resolver.rb
+++ /dev/null
@@ -1,485 +0,0 @@
-require 'rubygems/dependency'
-require 'rubygems/exceptions'
-require 'rubygems/util/list'
-
-require 'uri'
-require 'net/http'
-
-##
-# Given a set of Gem::Dependency objects as +needed+ and a way to query the
-# set of available specs via +set+, calculates a set of ActivationRequest
-# objects which indicate all the specs that should be activated to meet the
-# all the requirements.
-
-class Gem::Resolver
-
- ##
- # If the DEBUG_RESOLVER environment variable is set then debugging mode is
- # enabled for the resolver. This will display information about the state
- # of the resolver while a set of dependencies is being resolved.
-
- DEBUG_RESOLVER = !ENV['DEBUG_RESOLVER'].nil?
-
- require 'pp' if DEBUG_RESOLVER
-
- ##
- # Contains all the conflicts encountered while doing resolution
-
- attr_reader :conflicts
-
- ##
- # Set to true if all development dependencies should be considered.
-
- attr_accessor :development
-
- ##
- # Set to true if immediate development dependencies should be considered.
-
- attr_accessor :development_shallow
-
- ##
- # When true, no dependencies are looked up for requested gems.
-
- attr_accessor :ignore_dependencies
-
- ##
- # List of dependencies that could not be found in the configured sources.
-
- attr_reader :missing
-
- attr_reader :stats
-
- ##
- # Hash of gems to skip resolution. Keyed by gem name, with arrays of
- # gem specifications as values.
-
- attr_accessor :skip_gems
-
- ##
- # When a missing dependency, don't stop. Just go on and record what was
- # missing.
-
- attr_accessor :soft_missing
-
- ##
- # Combines +sets+ into a ComposedSet that allows specification lookup in a
- # uniform manner. If one of the +sets+ is itself a ComposedSet its sets are
- # flattened into the result ComposedSet.
-
- def self.compose_sets *sets
- sets.compact!
-
- sets = sets.map do |set|
- case set
- when Gem::Resolver::BestSet then
- set
- when Gem::Resolver::ComposedSet then
- set.sets
- else
- set
- end
- end.flatten
-
- case sets.length
- when 0 then
- raise ArgumentError, 'one set in the composition must be non-nil'
- when 1 then
- sets.first
- else
- Gem::Resolver::ComposedSet.new(*sets)
- end
- end
-
- ##
- # Creates a Resolver that queries only against the already installed gems
- # for the +needed+ dependencies.
-
- def self.for_current_gems needed
- new needed, Gem::Resolver::CurrentSet.new
- end
-
- ##
- # Create Resolver object which will resolve the tree starting
- # with +needed+ Dependency objects.
- #
- # +set+ is an object that provides where to look for specifications to
- # satisfy the Dependencies. This defaults to IndexSet, which will query
- # rubygems.org.
-
- def initialize needed, set = nil
- @set = set || Gem::Resolver::IndexSet.new
- @needed = needed
-
- @conflicts = []
- @development = false
- @development_shallow = false
- @ignore_dependencies = false
- @missing = []
- @skip_gems = {}
- @soft_missing = false
- @stats = Gem::Resolver::Stats.new
- end
-
- def explain stage, *data # :nodoc:
- return unless DEBUG_RESOLVER
-
- d = data.map { |x| x.pretty_inspect }.join(", ")
- $stderr.printf "%10s %s\n", stage.to_s.upcase, d
- end
-
- def explain_list stage # :nodoc:
- return unless DEBUG_RESOLVER
-
- data = yield
- $stderr.printf "%10s (%d entries)\n", stage.to_s.upcase, data.size
- PP.pp data, $stderr unless data.empty?
- end
-
- ##
- # Creates an ActivationRequest for the given +dep+ and the last +possible+
- # specification.
- #
- # Returns the Specification and the ActivationRequest
-
- def activation_request dep, possible # :nodoc:
- spec = possible.pop
-
- explain :activate, [spec.full_name, possible.size]
- explain :possible, possible
-
- activation_request =
- Gem::Resolver::ActivationRequest.new spec, dep, possible
-
- return spec, activation_request
- end
-
- def requests s, act, reqs=nil # :nodoc:
- return reqs if @ignore_dependencies
-
- s.fetch_development_dependencies if @development
-
- s.dependencies.reverse_each do |d|
- next if d.type == :development and not @development
- next if d.type == :development and @development_shallow and
- act.development?
- next if d.type == :development and @development_shallow and
- act.parent
-
- reqs.add Gem::Resolver::DependencyRequest.new(d, act)
- @stats.requirement!
- end
-
- @set.prefetch reqs
-
- @stats.record_requirements reqs
-
- reqs
- end
-
- ##
- # Proceed with resolution! Returns an array of ActivationRequest objects.
-
- def resolve
- @conflicts = []
-
- needed = Gem::Resolver::RequirementList.new
-
- @needed.reverse_each do |n|
- request = Gem::Resolver::DependencyRequest.new n, nil
-
- needed.add request
- @stats.requirement!
- end
-
- @stats.record_requirements needed
-
- res = resolve_for needed, nil
-
- raise Gem::DependencyResolutionError, res if
- res.kind_of? Gem::Resolver::Conflict
-
- res.to_a
- end
-
- ##
- # Extracts the specifications that may be able to fulfill +dependency+ and
- # returns those that match the local platform and all those that match.
-
- def find_possible dependency # :nodoc:
- all = @set.find_all dependency
-
- if (skip_dep_gems = skip_gems[dependency.name]) && !skip_dep_gems.empty?
- matching = all.select do |api_spec|
- skip_dep_gems.any? { |s| api_spec.version == s.version }
- end
-
- all = matching unless matching.empty?
- end
-
- matching_platform = select_local_platforms all
-
- return matching_platform, all
- end
-
- def handle_conflict(dep, existing) # :nodoc:
- # There is a conflict! We return the conflict object which will be seen by
- # the caller and be handled at the right level.
-
- # If the existing activation indicates that there are other possibles for
- # it, then issue the conflict on the dependency for the activation itself.
- # Otherwise, if there was a requester, issue it on the requester's
- # request itself.
- # Finally, if the existing request has no requester (toplevel) unwind to
- # it anyway.
-
- if existing.others_possible?
- conflict =
- Gem::Resolver::Conflict.new dep, existing
- elsif dep.requester
- depreq = dep.requester.request
- conflict =
- Gem::Resolver::Conflict.new depreq, existing, dep
- elsif existing.request.requester.nil?
- conflict =
- Gem::Resolver::Conflict.new dep, existing
- else
- raise Gem::DependencyError, "Unable to figure out how to unwind conflict"
- end
-
- @conflicts << conflict unless @conflicts.include? conflict
-
- return conflict
- end
-
- # Contains the state for attempting activation of a set of possible specs.
- # +needed+ is a Gem::List of DependencyRequest objects that, well, need
- # to be satisfied.
- # +specs+ is the List of ActivationRequest that are being tested.
- # +dep+ is the DependencyRequest that was used to generate this state.
- # +spec+ is the Specification for this state.
- # +possible+ is List of DependencyRequest objects that can be tried to
- # find a complete set.
- # +conflicts+ is a [DependencyRequest, Conflict] hit tried to
- # activate the state.
- #
- State = Struct.new(:needed, :specs, :dep, :spec, :possibles, :conflicts) do
- def summary # :nodoc:
- nd = needed.map { |s| s.to_s }.sort if nd
-
- if specs then
- ss = specs.map { |s| s.full_name }.sort
- ss.unshift ss.length
- end
-
- d = dep.to_s
- d << " from #{dep.requester.full_name}" if dep.requester
-
- ps = possibles.map { |p| p.full_name }.sort
- ps.unshift ps.length
-
- cs = conflicts.map do |(s, c)|
- [s.full_name, c.conflicting_dependencies.map { |cd| cd.to_s }]
- end
-
- { :needed => nd, :specs => ss, :dep => d, :spec => spec.full_name,
- :possibles => ps, :conflicts => cs }
- end
- end
-
- ##
- # The meat of the algorithm. Given +needed+ DependencyRequest objects and
- # +specs+ being a list to ActivationRequest, calculate a new list of
- # ActivationRequest objects.
-
- def resolve_for needed, specs # :nodoc:
- # The State objects that are used to attempt the activation tree.
- states = []
-
- while !needed.empty?
- @stats.iteration!
-
- dep = needed.remove
- explain :try, [dep, dep.requester ? dep.requester.request : :toplevel]
- explain_list(:next5) { needed.next5 }
- explain_list(:specs) { Array(specs).map { |x| x.full_name }.sort }
-
- # If there is already a spec activated for the requested name...
- if specs && existing = specs.find { |s| dep.name == s.name }
- # then we're done since this new dep matches the existing spec.
- next if dep.matches_spec? existing
-
- conflict = handle_conflict dep, existing
-
- return conflict unless dep.requester
-
- explain :conflict, dep, :existing, existing.full_name
-
- depreq = dep.requester.request
-
- state = nil
- until states.empty?
- x = states.pop
-
- i = existing.request.requester
- explain :consider, x.spec.full_name, [depreq.name, dep.name, i ? i.name : :top]
-
- if x.spec.name == depreq.name or
- x.spec.name == dep.name or
- (i && (i.name == x.spec.name))
- explain :found, x.spec.full_name
- state = x
- break
- end
- end
-
- return conflict unless state
-
- @stats.backtracking!
-
- needed, specs = resolve_for_conflict needed, specs, state
-
- states << state unless state.possibles.empty?
-
- next
- end
-
- matching, all = find_possible dep
-
- case matching.size
- when 0
- resolve_for_zero dep, all
- when 1
- needed, specs =
- resolve_for_single needed, specs, dep, matching
- else
- needed, specs =
- resolve_for_multiple needed, specs, states, dep, matching
- end
- end
-
- specs
- end
-
- ##
- # Rewinds +needed+ and +specs+ to a previous state in +state+ for a conflict
- # between +dep+ and +existing+.
-
- def resolve_for_conflict needed, specs, state # :nodoc:
- # We exhausted the possibles so it's definitely not going to work out,
- # bail out.
- raise Gem::ImpossibleDependenciesError.new state.dep, state.conflicts if
- state.possibles.empty?
-
- # Retry resolution with this spec and add it's dependencies
- spec, act = activation_request state.dep, state.possibles
-
- needed = requests spec, act, state.needed.dup
- specs = Gem::List.prepend state.specs, act
-
- return needed, specs
- end
-
- ##
- # There are multiple +possible+ specifications for this +dep+. Updates
- # +needed+, +specs+ and +states+ for further resolution of the +possible+
- # choices.
-
- def resolve_for_multiple needed, specs, states, dep, possible # :nodoc:
- # Sort them so that we try the highest versions first.
- possible = possible.sort_by do |s|
- [s.source, s.version, s.platform == Gem::Platform::RUBY ? -1 : 1]
- end
-
- spec, act = activation_request dep, possible
-
- # We may need to try all of +possible+, so we setup state to unwind back
- # to current +needed+ and +specs+ so we can try another. This is code is
- # what makes conflict resolution possible.
- states << State.new(needed.dup, specs, dep, spec, possible, [])
-
- @stats.record_depth states
-
- explain :states, states.map { |s| s.dep }
-
- needed = requests spec, act, needed
- specs = Gem::List.prepend specs, act
-
- return needed, specs
- end
-
- ##
- # Add the spec from the +possible+ list to +specs+ and process the spec's
- # dependencies by adding them to +needed+.
-
- def resolve_for_single needed, specs, dep, possible # :nodoc:
- spec, act = activation_request dep, possible
-
- specs = Gem::List.prepend specs, act
-
- # Put the deps for at the beginning of needed
- # rather than the end to match the depth first
- # searching done by the multiple case code below.
- #
- # This keeps the error messages consistent.
- needed = requests spec, act, needed
-
- return needed, specs
- end
-
- ##
- # When there are no possible specifications for +dep+ our work is done.
-
- def resolve_for_zero dep, platform_mismatch # :nodoc:
- @missing << dep
-
- unless @soft_missing
- exc = Gem::UnsatisfiableDependencyError.new dep, platform_mismatch
- exc.errors = @set.errors
-
- raise exc
- end
- end
-
- ##
- # Returns the gems in +specs+ that match the local platform.
-
- def select_local_platforms specs # :nodoc:
- specs.select do |spec|
- Gem::Platform.installable? spec
- end
- end
-
-end
-
-##
-# TODO remove in RubyGems 3
-
-Gem::DependencyResolver = Gem::Resolver # :nodoc:
-
-require 'rubygems/resolver/activation_request'
-require 'rubygems/resolver/conflict'
-require 'rubygems/resolver/dependency_request'
-require 'rubygems/resolver/requirement_list'
-require 'rubygems/resolver/stats'
-
-require 'rubygems/resolver/set'
-require 'rubygems/resolver/api_set'
-require 'rubygems/resolver/composed_set'
-require 'rubygems/resolver/best_set'
-require 'rubygems/resolver/current_set'
-require 'rubygems/resolver/git_set'
-require 'rubygems/resolver/index_set'
-require 'rubygems/resolver/installer_set'
-require 'rubygems/resolver/lock_set'
-require 'rubygems/resolver/vendor_set'
-
-require 'rubygems/resolver/specification'
-require 'rubygems/resolver/spec_specification'
-require 'rubygems/resolver/api_specification'
-require 'rubygems/resolver/git_specification'
-require 'rubygems/resolver/index_specification'
-require 'rubygems/resolver/installed_specification'
-require 'rubygems/resolver/local_specification'
-require 'rubygems/resolver/lock_specification'
-require 'rubygems/resolver/vendor_specification'
-
diff --git a/ruby_2_2/lib/rubygems/resolver/activation_request.rb b/ruby_2_2/lib/rubygems/resolver/activation_request.rb
deleted file mode 100644
index 56c6363e4f..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/activation_request.rb
+++ /dev/null
@@ -1,172 +0,0 @@
-##
-# Specifies a Specification object that should be activated. Also contains a
-# dependency that was used to introduce this activation.
-
-class Gem::Resolver::ActivationRequest
-
- ##
- # The parent request for this activation request.
-
- attr_reader :request
-
- ##
- # The specification to be activated.
-
- attr_reader :spec
-
- ##
- # Creates a new ActivationRequest that will activate +spec+. The parent
- # +request+ is used to provide diagnostics in case of conflicts.
- #
- # +others_possible+ indicates that other specifications may also match this
- # activation request.
-
- def initialize spec, request, others_possible = true
- @spec = spec
- @request = request
- @others_possible = others_possible
- end
-
- def == other # :nodoc:
- case other
- when Gem::Specification
- @spec == other
- when Gem::Resolver::ActivationRequest
- @spec == other.spec && @request == other.request
- else
- false
- end
- end
-
- ##
- # Is this activation request for a development dependency?
-
- def development?
- @request.development?
- end
-
- ##
- # Downloads a gem at +path+ and returns the file path.
-
- def download path
- if @spec.respond_to? :source
- source = @spec.source
- else
- source = Gem.sources.first
- end
-
- Gem.ensure_gem_subdirectories path
-
- source.download full_spec, path
- end
-
- ##
- # The full name of the specification to be activated.
-
- def full_name
- @spec.full_name
- end
-
- ##
- # The Gem::Specification for this activation request.
-
- def full_spec
- Gem::Specification === @spec ? @spec : @spec.spec
- end
-
- def inspect # :nodoc:
- others =
- case @others_possible
- when true then # TODO remove at RubyGems 3
- ' (others possible)'
- when false then # TODO remove at RubyGems 3
- nil
- else
- unless @others_possible.empty? then
- others = @others_possible.map { |s| s.full_name }
- " (others possible: #{others.join ', '})"
- end
- end
-
- '#<%s for %p from %s%s>' % [
- self.class, @spec, @request, others
- ]
- end
-
- ##
- # True if the requested gem has already been installed.
-
- def installed?
- case @spec
- when Gem::Resolver::VendorSpecification then
- true
- else
- this_spec = full_spec
-
- Gem::Specification.any? do |s|
- s == this_spec
- end
- end
- end
-
- ##
- # The name of this activation request's specification
-
- def name
- @spec.name
- end
-
- ##
- # Indicate if this activation is one of a set of possible
- # requests for the same Dependency request.
-
- def others_possible?
- case @others_possible
- when true, false then
- @others_possible
- else
- not @others_possible.empty?
- end
- end
-
- ##
- # Return the ActivationRequest that contained the dependency
- # that we were activated for.
-
- def parent
- @request.requester
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[Activation request', ']' do
- q.breakable
- q.pp @spec
-
- q.breakable
- q.text ' for '
- q.pp @request
-
- case @others_possible
- when false then
- when true then
- q.breakable
- q.text 'others possible'
- else
- unless @others_possible.empty? then
- q.breakable
- q.text 'others '
- q.pp @others_possible.map { |s| s.full_name }
- end
- end
- end
- end
-
- ##
- # The version of this activation request's specification
-
- def version
- @spec.version
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/resolver/api_set.rb b/ruby_2_2/lib/rubygems/resolver/api_set.rb
deleted file mode 100644
index 17d602f987..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/api_set.rb
+++ /dev/null
@@ -1,125 +0,0 @@
-##
-# The global rubygems pool, available via the rubygems.org API.
-# Returns instances of APISpecification.
-
-class Gem::Resolver::APISet < Gem::Resolver::Set
-
- ##
- # The URI for the dependency API this APISet uses.
-
- attr_reader :dep_uri # :nodoc:
-
- ##
- # The Gem::Source that gems are fetched from
-
- attr_reader :source
-
- ##
- # The corresponding place to fetch gems.
-
- attr_reader :uri
-
- ##
- # Creates a new APISet that will retrieve gems from +uri+ using the RubyGems
- # API URL +dep_uri+ which is described at
- # http://guides.rubygems.org/rubygems-org-api
-
- def initialize dep_uri = 'https://rubygems.org/api/v1/dependencies'
- super()
-
- dep_uri = URI dep_uri unless URI === dep_uri # for ruby 1.8
-
- @dep_uri = dep_uri
- @uri = dep_uri + '../..'
-
- @data = Hash.new { |h,k| h[k] = [] }
- @source = Gem::Source.new @uri
-
- @to_fetch = []
- end
-
- ##
- # Return an array of APISpecification objects matching
- # DependencyRequest +req+.
-
- def find_all req
- res = []
-
- return res unless @remote
-
- if @to_fetch.include?(req.name)
- prefetch_now
- end
-
- versions(req.name).each do |ver|
- if req.dependency.match? req.name, ver[:number]
- res << Gem::Resolver::APISpecification.new(self, ver)
- end
- end
-
- res
- end
-
- ##
- # A hint run by the resolver to allow the Set to fetch
- # data for DependencyRequests +reqs+.
-
- def prefetch reqs
- return unless @remote
- names = reqs.map { |r| r.dependency.name }
- needed = names - @data.keys - @to_fetch
-
- @to_fetch += needed
- end
-
- def prefetch_now # :nodoc:
- needed, @to_fetch = @to_fetch, []
-
- uri = @dep_uri + "?gems=#{needed.sort.join ','}"
- str = Gem::RemoteFetcher.fetcher.fetch_path uri
-
- loaded = []
-
- Marshal.load(str).each do |ver|
- name = ver[:name]
-
- @data[name] << ver
- loaded << name
- end
-
- (needed - loaded).each do |missing|
- @data[missing] = []
- end
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[APISet', ']' do
- q.breakable
- q.text "URI: #{@dep_uri}"
-
- q.breakable
- q.text 'gem names:'
- q.pp @data.keys
- end
- end
-
- ##
- # Return data for all versions of the gem +name+.
-
- def versions name # :nodoc:
- if @data.key?(name)
- return @data[name]
- end
-
- uri = @dep_uri + "?gems=#{name}"
- str = Gem::RemoteFetcher.fetcher.fetch_path uri
-
- Marshal.load(str).each do |ver|
- @data[ver[:name]] << ver
- end
-
- @data[name]
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/resolver/api_specification.rb b/ruby_2_2/lib/rubygems/resolver/api_specification.rb
deleted file mode 100644
index 4960e66934..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/api_specification.rb
+++ /dev/null
@@ -1,85 +0,0 @@
-##
-# Represents a specification retrieved via the rubygems.org API.
-#
-# This is used to avoid loading the full Specification object when all we need
-# is the name, version, and dependencies.
-
-class Gem::Resolver::APISpecification < Gem::Resolver::Specification
-
- ##
- # Creates an APISpecification for the given +set+ from the rubygems.org
- # +api_data+.
- #
- # See http://guides.rubygems.org/rubygems-org-api/#misc_methods for the
- # format of the +api_data+.
-
- def initialize(set, api_data)
- super()
-
- @set = set
- @name = api_data[:name]
- @version = Gem::Version.new api_data[:number]
- @platform = Gem::Platform.new api_data[:platform]
- @dependencies = api_data[:dependencies].map do |name, ver|
- Gem::Dependency.new name, ver.split(/\s*,\s*/)
- end
- end
-
- def == other # :nodoc:
- self.class === other and
- @set == other.set and
- @name == other.name and
- @version == other.version and
- @platform == other.platform and
- @dependencies == other.dependencies
- end
-
- def fetch_development_dependencies # :nodoc:
- spec = source.fetch_spec Gem::NameTuple.new @name, @version, @platform
-
- @dependencies = spec.dependencies
- end
-
- def installable_platform? # :nodoc:
- Gem::Platform.match @platform
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[APISpecification', ']' do
- q.breakable
- q.text "name: #{name}"
-
- q.breakable
- q.text "version: #{version}"
-
- q.breakable
- q.text "platform: #{platform}"
-
- q.breakable
- q.text 'dependencies:'
- q.breakable
- q.pp @dependencies
-
- q.breakable
- q.text "set uri: #{@set.dep_uri}"
- end
- end
-
- ##
- # Fetches a Gem::Specification for this APISpecification.
-
- def spec # :nodoc:
- @spec ||=
- begin
- tuple = Gem::NameTuple.new @name, @version, @platform
-
- source.fetch_spec tuple
- end
- end
-
- def source # :nodoc:
- @set.source
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/resolver/best_set.rb b/ruby_2_2/lib/rubygems/resolver/best_set.rb
deleted file mode 100644
index 7e2d7e2647..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/best_set.rb
+++ /dev/null
@@ -1,78 +0,0 @@
-##
-# The BestSet chooses the best available method to query a remote index.
-#
-# It combines IndexSet and APISet
-
-class Gem::Resolver::BestSet < Gem::Resolver::ComposedSet
-
- ##
- # Creates a BestSet for the given +sources+ or Gem::sources if none are
- # specified. +sources+ must be a Gem::SourceList.
-
- def initialize sources = Gem.sources
- super()
-
- @sources = sources
- end
-
- ##
- # Picks which sets to use for the configured sources.
-
- def pick_sets # :nodoc:
- @sources.each_source do |source|
- @sets << source.dependency_resolver_set
- end
- end
-
- def find_all req # :nodoc:
- pick_sets if @remote and @sets.empty?
-
- super
- rescue Gem::RemoteFetcher::FetchError => e
- replace_failed_api_set e
-
- retry
- end
-
- def prefetch reqs # :nodoc:
- pick_sets if @remote and @sets.empty?
-
- super
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[BestSet', ']' do
- q.breakable
- q.text 'sets:'
-
- q.breakable
- q.pp @sets
- end
- end
-
- ##
- # Replaces a failed APISet for the URI in +error+ with an IndexSet.
- #
- # If no matching APISet can be found the original +error+ is raised.
- #
- # The calling method must retry the exception to repeat the lookup.
-
- def replace_failed_api_set error # :nodoc:
- uri = error.uri
- uri = URI uri unless URI === uri
- uri.query = nil
-
- raise error unless api_set = @sets.find { |set|
- Gem::Resolver::APISet === set and set.dep_uri == uri
- }
-
- index_set = Gem::Resolver::IndexSet.new api_set.source
-
- @sets.map! do |set|
- next set unless set == api_set
- index_set
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/resolver/composed_set.rb b/ruby_2_2/lib/rubygems/resolver/composed_set.rb
deleted file mode 100644
index 5b08f128ed..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/composed_set.rb
+++ /dev/null
@@ -1,66 +0,0 @@
-##
-# A ComposedSet allows multiple sets to be queried like a single set.
-#
-# To create a composed set with any number of sets use:
-#
-# Gem::Resolver.compose_sets set1, set2
-#
-# This method will eliminate nesting of composed sets.
-
-class Gem::Resolver::ComposedSet < Gem::Resolver::Set
-
- attr_reader :sets # :nodoc:
-
- ##
- # Creates a new ComposedSet containing +sets+. Use
- # Gem::Resolver::compose_sets instead.
-
- def initialize *sets
- super()
-
- @sets = sets
- end
-
- ##
- # When +allow_prerelease+ is set to +true+ prereleases gems are allowed to
- # match dependencies.
-
- def prerelease= allow_prerelease
- super
-
- sets.each do |set|
- set.prerelease = allow_prerelease
- end
- end
-
- ##
- # Sets the remote network access for all composed sets.
-
- def remote= remote
- super
-
- @sets.each { |set| set.remote = remote }
- end
-
- def errors
- @errors + @sets.map { |set| set.errors }.flatten
- end
-
- ##
- # Finds all specs matching +req+ in all sets.
-
- def find_all req
- @sets.map do |s|
- s.find_all req
- end.flatten
- end
-
- ##
- # Prefetches +reqs+ in all sets.
-
- def prefetch reqs
- @sets.each { |s| s.prefetch(reqs) }
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/resolver/conflict.rb b/ruby_2_2/lib/rubygems/resolver/conflict.rb
deleted file mode 100644
index 902c286b6b..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/conflict.rb
+++ /dev/null
@@ -1,160 +0,0 @@
-##
-# Used internally to indicate that a dependency conflicted
-# with a spec that would be activated.
-
-class Gem::Resolver::Conflict
-
- ##
- # The specification that was activated prior to the conflict
-
- attr_reader :activated
-
- ##
- # The dependency that is in conflict with the activated gem.
-
- attr_reader :dependency
-
- attr_reader :failed_dep # :nodoc:
-
- ##
- # Creates a new resolver conflict when +dependency+ is in conflict with an
- # already +activated+ specification.
-
- def initialize(dependency, activated, failed_dep=dependency)
- @dependency = dependency
- @activated = activated
- @failed_dep = failed_dep
- end
-
- def == other # :nodoc:
- self.class === other and
- @dependency == other.dependency and
- @activated == other.activated and
- @failed_dep == other.failed_dep
- end
-
- ##
- # A string explanation of the conflict.
-
- def explain
- "<Conflict wanted: #{@failed_dep}, had: #{activated.spec.full_name}>"
- end
-
- ##
- # Return the 2 dependency objects that conflicted
-
- def conflicting_dependencies
- [@failed_dep.dependency, @activated.request.dependency]
- end
-
- ##
- # Explanation of the conflict used by exceptions to print useful messages
-
- def explanation
- activated = @activated.spec.full_name
- dependency = @failed_dep.dependency
- requirement = dependency.requirement
- alternates = dependency.matching_specs.map { |spec| spec.full_name }
-
- unless alternates.empty? then
- matching = <<-MATCHING.chomp
-
- Gems matching %s:
- %s
- MATCHING
-
- matching = matching % [
- dependency,
- alternates.join(', '),
- ]
- end
-
- explanation = <<-EXPLANATION
- Activated %s
- which does not match conflicting dependency (%s)
-
- Conflicting dependency chains:
- %s
-
- versus:
- %s
-%s
- EXPLANATION
-
- explanation % [
- activated, requirement,
- request_path(@activated).reverse.join(", depends on\n "),
- request_path(@failed_dep).reverse.join(", depends on\n "),
- matching,
- ]
- end
-
- ##
- # Returns true if the conflicting dependency's name matches +spec+.
-
- def for_spec?(spec)
- @dependency.name == spec.name
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[Dependency conflict: ', ']' do
- q.breakable
-
- q.text 'activated '
- q.pp @activated
-
- q.breakable
- q.text ' dependency '
- q.pp @dependency
-
- q.breakable
- if @dependency == @failed_dep then
- q.text ' failed'
- else
- q.text ' failed dependency '
- q.pp @failed_dep
- end
- end
- end
-
- ##
- # Path of activations from the +current+ list.
-
- def request_path current
- path = []
-
- while current do
- case current
- when Gem::Resolver::ActivationRequest then
- path <<
- "#{current.request.dependency}, #{current.spec.version} activated"
-
- current = current.parent
- when Gem::Resolver::DependencyRequest then
- path << "#{current.dependency}"
-
- current = current.requester
- else
- raise Gem::Exception, "[BUG] unknown request class #{current.class}"
- end
- end
-
- path = ['user request (gem command or Gemfile)'] if path.empty?
-
- path
- end
-
- ##
- # Return the Specification that listed the dependency
-
- def requester
- @failed_dep.requester
- end
-
-end
-
-##
-# TODO: Remove in RubyGems 3
-
-Gem::Resolver::DependencyConflict = Gem::Resolver::Conflict # :nodoc:
-
diff --git a/ruby_2_2/lib/rubygems/resolver/current_set.rb b/ruby_2_2/lib/rubygems/resolver/current_set.rb
deleted file mode 100644
index 4e8d34026b..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/current_set.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-##
-# A set which represents the installed gems. Respects
-# all the normal settings that control where to look
-# for installed gems.
-
-class Gem::Resolver::CurrentSet < Gem::Resolver::Set
-
- def find_all req
- req.dependency.matching_specs
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/resolver/dependency_request.rb b/ruby_2_2/lib/rubygems/resolver/dependency_request.rb
deleted file mode 100644
index 79690bec4c..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/dependency_request.rb
+++ /dev/null
@@ -1,116 +0,0 @@
-##
-# Used Internally. Wraps a Dependency object to also track which spec
-# contained the Dependency.
-
-class Gem::Resolver::DependencyRequest
-
- ##
- # The wrapped Gem::Dependency
-
- attr_reader :dependency
-
- ##
- # The request for this dependency.
-
- attr_reader :requester
-
- ##
- # Creates a new DependencyRequest for +dependency+ from +requester+.
- # +requester may be nil if the request came from a user.
-
- def initialize dependency, requester
- @dependency = dependency
- @requester = requester
- end
-
- def == other # :nodoc:
- case other
- when Gem::Dependency
- @dependency == other
- when Gem::Resolver::DependencyRequest
- @dependency == other.dependency && @requester == other.requester
- else
- false
- end
- end
-
- ##
- # Is this dependency a development dependency?
-
- def development?
- @dependency.type == :development
- end
-
- ##
- # Does this dependency request match +spec+?
- #
- # NOTE: #match? only matches prerelease versions when #dependency is a
- # prerelease dependency.
-
- def match? spec, allow_prerelease = false
- @dependency.match? spec, nil, allow_prerelease
- end
-
- ##
- # Does this dependency request match +spec+?
- #
- # NOTE: #matches_spec? matches prerelease versions. See also #match?
-
- def matches_spec?(spec)
- @dependency.matches_spec? spec
- end
-
- ##
- # The name of the gem this dependency request is requesting.
-
- def name
- @dependency.name
- end
-
- ##
- # Indicate that the request is for a gem explicitly requested by the user
-
- def explicit?
- @requester.nil?
- end
-
- ##
- # Indicate that the request is for a gem requested as a dependency of
- # another gem
-
- def implicit?
- !explicit?
- end
-
- ##
- # Return a String indicating who caused this request to be added (only
- # valid for implicit requests)
-
- def request_context
- @requester ? @requester.request : "(unknown)"
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[Dependency request ', ']' do
- q.breakable
- q.text @dependency.to_s
-
- q.breakable
- q.text ' requested by '
- q.pp @requester
- end
- end
-
- ##
- # The version requirement for this dependency request
-
- def requirement
- @dependency.requirement
- end
-
- def to_s # :nodoc:
- @dependency.to_s
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/resolver/git_set.rb b/ruby_2_2/lib/rubygems/resolver/git_set.rb
deleted file mode 100644
index 5f1b368ac1..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/git_set.rb
+++ /dev/null
@@ -1,122 +0,0 @@
-##
-# A GitSet represents gems that are sourced from git repositories.
-#
-# This is used for gem dependency file support.
-#
-# Example:
-#
-# set = Gem::Resolver::GitSet.new
-# set.add_git_gem 'rake', 'git://example/rake.git', tag: 'rake-10.1.0'
-
-class Gem::Resolver::GitSet < Gem::Resolver::Set
-
- ##
- # The root directory for git gems in this set. This is usually Gem.dir, the
- # installation directory for regular gems.
-
- attr_accessor :root_dir
-
- ##
- # Contains repositories needing submodules
-
- attr_reader :need_submodules # :nodoc:
-
- ##
- # A Hash containing git gem names for keys and a Hash of repository and
- # git commit reference as values.
-
- attr_reader :repositories # :nodoc:
-
- ##
- # A hash of gem names to Gem::Resolver::GitSpecifications
-
- attr_reader :specs # :nodoc:
-
- def initialize # :nodoc:
- super()
-
- @git = ENV['git'] || 'git'
- @need_submodules = {}
- @repositories = {}
- @root_dir = Gem.dir
- @specs = {}
- end
-
- def add_git_gem name, repository, reference, submodules # :nodoc:
- @repositories[name] = [repository, reference]
- @need_submodules[repository] = submodules
- end
-
- ##
- # Adds and returns a GitSpecification with the given +name+ and +version+
- # which came from a +repository+ at the given +reference+. If +submodules+
- # is true they are checked out along with the repository.
- #
- # This fills in the prefetch information as enough information about the gem
- # is present in the arguments.
-
- def add_git_spec name, version, repository, reference, submodules # :nodoc:
- add_git_gem name, repository, reference, submodules
-
- source = Gem::Source::Git.new name, repository, reference
- source.root_dir = @root_dir
-
- spec = Gem::Specification.new do |s|
- s.name = name
- s.version = version
- end
-
- git_spec = Gem::Resolver::GitSpecification.new self, spec, source
-
- @specs[spec.name] = git_spec
-
- git_spec
- end
-
- ##
- # Finds all git gems matching +req+
-
- def find_all req
- prefetch nil
-
- specs.values.select do |spec|
- req.match? spec
- end
- end
-
- ##
- # Prefetches specifications from the git repositories in this set.
-
- def prefetch reqs
- return unless @specs.empty?
-
- @repositories.each do |name, (repository, reference)|
- source = Gem::Source::Git.new name, repository, reference
- source.root_dir = @root_dir
- source.remote = @remote
-
- source.specs.each do |spec|
- git_spec = Gem::Resolver::GitSpecification.new self, spec, source
-
- @specs[spec.name] = git_spec
- end
- end
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[GitSet', ']' do
- next if @repositories.empty?
- q.breakable
-
- repos = @repositories.map do |name, (repository, reference)|
- "#{name}: #{repository}@#{reference}"
- end
-
- q.seplist repos do |repo|
- q.text repo
- end
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/resolver/git_specification.rb b/ruby_2_2/lib/rubygems/resolver/git_specification.rb
deleted file mode 100644
index 55e180e525..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/git_specification.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-##
-# A GitSpecification represents a gem that is sourced from a git repository
-# and is being loaded through a gem dependencies file through the +git:+
-# option.
-
-class Gem::Resolver::GitSpecification < Gem::Resolver::SpecSpecification
-
- def == other # :nodoc:
- self.class === other and
- @set == other.set and
- @spec == other.spec and
- @source == other.source
- end
-
- def add_dependency dependency # :nodoc:
- spec.dependencies << dependency
- end
-
- ##
- # Installing a git gem only involves building the extensions and generating
- # the executables.
-
- def install options = {}
- require 'rubygems/installer'
-
- installer = Gem::Installer.new '', options
- installer.spec = spec
-
- yield installer if block_given?
-
- installer.run_pre_install_hooks
- installer.build_extensions
- installer.run_post_build_hooks
- installer.generate_bin
- installer.run_post_install_hooks
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[GitSpecification', ']' do
- q.breakable
- q.text "name: #{name}"
-
- q.breakable
- q.text "version: #{version}"
-
- q.breakable
- q.text 'dependencies:'
- q.breakable
- q.pp dependencies
-
- q.breakable
- q.text "source:"
- q.breakable
- q.pp @source
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/resolver/index_set.rb b/ruby_2_2/lib/rubygems/resolver/index_set.rb
deleted file mode 100644
index 7c56c2bf99..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/index_set.rb
+++ /dev/null
@@ -1,80 +0,0 @@
-##
-# The global rubygems pool represented via the traditional
-# source index.
-
-class Gem::Resolver::IndexSet < Gem::Resolver::Set
-
- def initialize source = nil # :nodoc:
- super()
-
- @f =
- if source then
- sources = Gem::SourceList.from [source]
-
- Gem::SpecFetcher.new sources
- else
- Gem::SpecFetcher.fetcher
- end
-
- @all = Hash.new { |h,k| h[k] = [] }
-
- list, errors = @f.available_specs :complete
-
- @errors.concat errors
-
- list.each do |uri, specs|
- specs.each do |n|
- @all[n.name] << [uri, n]
- end
- end
-
- @specs = {}
- end
-
- ##
- # Return an array of IndexSpecification objects matching
- # DependencyRequest +req+.
-
- def find_all req
- res = []
-
- return res unless @remote
-
- name = req.dependency.name
-
- @all[name].each do |uri, n|
- if req.match? n, @prerelease then
- res << Gem::Resolver::IndexSpecification.new(
- self, n.name, n.version, uri, n.platform)
- end
- end
-
- res
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[IndexSet', ']' do
- q.breakable
- q.text 'sources:'
- q.breakable
- q.pp @f.sources
-
- q.breakable
- q.text 'specs:'
-
- q.breakable
-
- names = @all.values.map do |tuples|
- tuples.map do |_, tuple|
- tuple.full_name
- end
- end.flatten
-
- q.seplist names do |name|
- q.text name
- end
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/resolver/index_specification.rb b/ruby_2_2/lib/rubygems/resolver/index_specification.rb
deleted file mode 100644
index 56fecb5753..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/index_specification.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-##
-# Represents a possible Specification object returned from IndexSet. Used to
-# delay needed to download full Specification objects when only the +name+
-# and +version+ are needed.
-
-class Gem::Resolver::IndexSpecification < Gem::Resolver::Specification
-
- ##
- # An IndexSpecification is created from the index format described in `gem
- # help generate_index`.
- #
- # The +set+ contains other specifications for this (URL) +source+.
- #
- # The +name+, +version+ and +platform+ are the name, version and platform of
- # the gem.
-
- def initialize set, name, version, source, platform
- super()
-
- @set = set
- @name = name
- @version = version
- @source = source
- @platform = platform.to_s
-
- @spec = nil
- end
-
- ##
- # The dependencies of the gem for this specification
-
- def dependencies
- spec.dependencies
- end
-
- def inspect # :nodoc:
- '#<%s %s source %s>' % [self.class, full_name, @source]
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[Index specification', ']' do
- q.breakable
- q.text full_name
-
- unless Gem::Platform::RUBY == @platform then
- q.breakable
- q.text @platform.to_s
- end
-
- q.breakable
- q.text 'source '
- q.pp @source
- end
- end
-
- ##
- # Fetches a Gem::Specification for this IndexSpecification from the #source.
-
- def spec # :nodoc:
- @spec ||=
- begin
- tuple = Gem::NameTuple.new @name, @version, @platform
-
- @source.fetch_spec tuple
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/resolver/installed_specification.rb b/ruby_2_2/lib/rubygems/resolver/installed_specification.rb
deleted file mode 100644
index 2a2b89a6c2..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/installed_specification.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-##
-# An InstalledSpecification represents a gem that is already installed
-# locally.
-
-class Gem::Resolver::InstalledSpecification < Gem::Resolver::SpecSpecification
-
- def == other # :nodoc:
- self.class === other and
- @set == other.set and
- @spec == other.spec
- end
-
- ##
- # This is a null install as this specification is already installed.
- # +options+ are ignored.
-
- def install options = {}
- yield nil
- end
-
- ##
- # Returns +true+ if this gem is installable for the current platform.
-
- def installable_platform?
- # BACKCOMPAT If the file is coming out of a specified file, then we
- # ignore the platform. This code can be removed in RG 3.0.
- return true if @source.kind_of? Gem::Source::SpecificFile
-
- super
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[InstalledSpecification', ']' do
- q.breakable
- q.text "name: #{name}"
-
- q.breakable
- q.text "version: #{version}"
-
- q.breakable
- q.text "platform: #{platform}"
-
- q.breakable
- q.text 'dependencies:'
- q.breakable
- q.pp spec.dependencies
- end
- end
-
- ##
- # The source for this specification
-
- def source
- @source ||= Gem::Source::Installed.new
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/resolver/installer_set.rb b/ruby_2_2/lib/rubygems/resolver/installer_set.rb
deleted file mode 100644
index a68ff09dbd..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/installer_set.rb
+++ /dev/null
@@ -1,224 +0,0 @@
-##
-# A set of gems for installation sourced from remote sources and local .gem
-# files
-
-class Gem::Resolver::InstallerSet < Gem::Resolver::Set
-
- ##
- # List of Gem::Specification objects that must always be installed.
-
- attr_reader :always_install # :nodoc:
-
- ##
- # Only install gems in the always_install list
-
- attr_accessor :ignore_dependencies # :nodoc:
-
- ##
- # Do not look in the installed set when finding specifications. This is
- # used by the --install-dir option to `gem install`
-
- attr_accessor :ignore_installed # :nodoc:
-
- ##
- # The remote_set looks up remote gems for installation.
-
- attr_reader :remote_set # :nodoc:
-
- ##
- # Creates a new InstallerSet that will look for gems in +domain+.
-
- def initialize domain
- super()
-
- @domain = domain
- @remote = consider_remote?
-
- @f = Gem::SpecFetcher.fetcher
-
- @always_install = []
- @ignore_dependencies = false
- @ignore_installed = false
- @local = {}
- @remote_set = Gem::Resolver::BestSet.new
- @specs = {}
- end
-
- ##
- # Looks up the latest specification for +dependency+ and adds it to the
- # always_install list.
-
- def add_always_install dependency
- request = Gem::Resolver::DependencyRequest.new dependency, nil
-
- found = find_all request
-
- found.delete_if { |s|
- s.version.prerelease? and not s.local?
- } unless dependency.prerelease?
-
- found = found.select do |s|
- Gem::Source::SpecificFile === s.source or
- Gem::Platform::RUBY == s.platform or
- Gem::Platform.local === s.platform
- end
-
- if found.empty? then
- exc = Gem::UnsatisfiableDependencyError.new request
- exc.errors = errors
-
- raise exc
- end
-
- newest = found.max_by do |s|
- [s.version, s.platform == Gem::Platform::RUBY ? -1 : 1]
- end
-
- @always_install << newest.spec
- end
-
- ##
- # Adds a local gem requested using +dep_name+ with the given +spec+ that can
- # be loaded and installed using the +source+.
-
- def add_local dep_name, spec, source
- @local[dep_name] = [spec, source]
- end
-
- ##
- # Should local gems should be considered?
-
- def consider_local? # :nodoc:
- @domain == :both or @domain == :local
- end
-
- ##
- # Should remote gems should be considered?
-
- def consider_remote? # :nodoc:
- @domain == :both or @domain == :remote
- end
-
- ##
- # Errors encountered while resolving gems
-
- def errors
- @errors + @remote_set.errors
- end
-
- ##
- # Returns an array of IndexSpecification objects matching DependencyRequest
- # +req+.
-
- def find_all req
- res = []
-
- dep = req.dependency
-
- return res if @ignore_dependencies and
- @always_install.none? { |spec| dep.match? spec }
-
- name = dep.name
-
- dep.matching_specs.each do |gemspec|
- next if @always_install.any? { |spec| spec.name == gemspec.name }
-
- res << Gem::Resolver::InstalledSpecification.new(self, gemspec)
- end unless @ignore_installed
-
- if consider_local? then
- matching_local = @local.values.select do |spec, _|
- req.match? spec
- end.map do |spec, source|
- Gem::Resolver::LocalSpecification.new self, spec, source
- end
-
- res.concat matching_local
-
- local_source = Gem::Source::Local.new
-
- if local_spec = local_source.find_gem(name, dep.requirement) then
- res << Gem::Resolver::IndexSpecification.new(
- self, local_spec.name, local_spec.version,
- local_source, local_spec.platform)
- end
- end
-
- res.delete_if do |spec|
- spec.version.prerelease? and not dep.prerelease?
- end
-
- res.concat @remote_set.find_all req if consider_remote?
-
- res
- end
-
- def prefetch(reqs)
- @remote_set.prefetch(reqs) if consider_remote?
- end
-
- def prerelease= allow_prerelease
- super
-
- @remote_set.prerelease = allow_prerelease
- end
-
- def inspect # :nodoc:
- always_install = @always_install.map { |s| s.full_name }
-
- '#<%s domain: %s specs: %p always install: %p>' % [
- self.class, @domain, @specs.keys, always_install,
- ]
- end
-
- ##
- # Called from IndexSpecification to get a true Specification
- # object.
-
- def load_spec name, ver, platform, source # :nodoc:
- key = "#{name}-#{ver}-#{platform}"
-
- @specs.fetch key do
- tuple = Gem::NameTuple.new name, ver, platform
-
- @specs[key] = source.fetch_spec tuple
- end
- end
-
- ##
- # Has a local gem for +dep_name+ been added to this set?
-
- def local? dep_name # :nodoc:
- spec, = @local[dep_name]
-
- spec
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[InstallerSet', ']' do
- q.breakable
- q.text "domain: #{@domain}"
-
- q.breakable
- q.text 'specs: '
- q.pp @specs.keys
-
- q.breakable
- q.text 'always install: '
- q.pp @always_install
- end
- end
-
- def remote= remote # :nodoc:
- case @domain
- when :local then
- @domain = :both if remote
- when :remote then
- @domain = nil unless remote
- when :both then
- @domain = :local unless remote
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/resolver/local_specification.rb b/ruby_2_2/lib/rubygems/resolver/local_specification.rb
deleted file mode 100644
index 20a283f0ba..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/local_specification.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-##
-# A LocalSpecification comes from a .gem file on the local filesystem.
-
-class Gem::Resolver::LocalSpecification < Gem::Resolver::SpecSpecification
-
- ##
- # Returns +true+ if this gem is installable for the current platform.
-
- def installable_platform?
- return true if @source.kind_of? Gem::Source::SpecificFile
-
- super
- end
-
- def local? # :nodoc:
- true
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[LocalSpecification', ']' do
- q.breakable
- q.text "name: #{name}"
-
- q.breakable
- q.text "version: #{version}"
-
- q.breakable
- q.text "platform: #{platform}"
-
- q.breakable
- q.text 'dependencies:'
- q.breakable
- q.pp dependencies
-
- q.breakable
- q.text "source: #{@source.path}"
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/resolver/lock_set.rb b/ruby_2_2/lib/rubygems/resolver/lock_set.rb
deleted file mode 100644
index 4ede5971fb..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/lock_set.rb
+++ /dev/null
@@ -1,84 +0,0 @@
-##
-# A set of gems from a gem dependencies lockfile.
-
-class Gem::Resolver::LockSet < Gem::Resolver::Set
-
- attr_reader :specs # :nodoc:
-
- ##
- # Creates a new LockSet from the given +sources+
-
- def initialize sources
- super()
-
- @sources = sources.map do |source|
- Gem::Source::Lock.new source
- end
-
- @specs = []
- end
-
- ##
- # Creates a new IndexSpecification in this set using the given +name+,
- # +version+ and +platform+.
- #
- # The specification's set will be the current set, and the source will be
- # the current set's source.
-
- def add name, version, platform # :nodoc:
- version = Gem::Version.new version
-
- specs = @sources.map do |source|
- Gem::Resolver::LockSpecification.new self, name, version, source,
- platform
- end
-
- @specs.concat specs
-
- specs
- end
-
- ##
- # Returns an Array of IndexSpecification objects matching the
- # DependencyRequest +req+.
-
- def find_all req
- @specs.select do |spec|
- req.match? spec
- end
- end
-
- ##
- # Loads a Gem::Specification with the given +name+, +version+ and
- # +platform+. +source+ is ignored.
-
- def load_spec name, version, platform, source # :nodoc:
- dep = Gem::Dependency.new name, version
-
- found = @specs.find do |spec|
- dep.matches_spec? spec and spec.platform == platform
- end
-
- tuple = Gem::NameTuple.new found.name, found.version, found.platform
-
- found.source.fetch_spec tuple
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[LockSet', ']' do
- q.breakable
- q.text 'source:'
-
- q.breakable
- q.pp @source
-
- q.breakable
- q.text 'specs:'
-
- q.breakable
- q.pp @specs.map { |spec| spec.full_name }
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/resolver/lock_specification.rb b/ruby_2_2/lib/rubygems/resolver/lock_specification.rb
deleted file mode 100644
index 0013171469..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/lock_specification.rb
+++ /dev/null
@@ -1,84 +0,0 @@
-##
-# The LockSpecification comes from a lockfile (Gem::RequestSet::Lockfile).
-#
-# A LockSpecification's dependency information is pre-filled from the
-# lockfile.
-
-class Gem::Resolver::LockSpecification < Gem::Resolver::Specification
-
- def initialize set, name, version, source, platform
- super()
-
- @name = name
- @platform = platform
- @set = set
- @source = source
- @version = version
-
- @dependencies = []
- @spec = nil
- end
-
- ##
- # This is a null install as a locked specification is considered installed.
- # +options+ are ignored.
-
- def install options = {}
- destination = options[:install_dir] || Gem.dir
-
- if File.exist? File.join(destination, 'specifications', spec.spec_name) then
- yield nil
- return
- end
-
- super
- end
-
- ##
- # Adds +dependency+ from the lockfile to this specification
-
- def add_dependency dependency # :nodoc:
- @dependencies << dependency
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[LockSpecification', ']' do
- q.breakable
- q.text "name: #{@name}"
-
- q.breakable
- q.text "version: #{@version}"
-
- unless @platform == Gem::Platform::RUBY then
- q.breakable
- q.text "platform: #{@platform}"
- end
-
- unless @dependencies.empty? then
- q.breakable
- q.text 'dependencies:'
- q.breakable
- q.pp @dependencies
- end
- end
- end
-
- ##
- # A specification constructed from the lockfile is returned
-
- def spec
- @spec ||= Gem::Specification.find { |spec|
- spec.name == @name and spec.version == @version
- }
-
- @spec ||= Gem::Specification.new do |s|
- s.name = @name
- s.version = @version
- s.platform = @platform
-
- s.dependencies.concat @dependencies
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/resolver/requirement_list.rb b/ruby_2_2/lib/rubygems/resolver/requirement_list.rb
deleted file mode 100644
index a6bfaab307..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/requirement_list.rb
+++ /dev/null
@@ -1,81 +0,0 @@
-##
-# The RequirementList is used to hold the requirements being considered
-# while resolving a set of gems.
-#
-# The RequirementList acts like a queue where the oldest items are removed
-# first.
-
-class Gem::Resolver::RequirementList
-
- include Enumerable
-
- ##
- # Creates a new RequirementList.
-
- def initialize
- @exact = []
- @list = []
- end
-
- def initialize_copy other # :nodoc:
- @exact = @exact.dup
- @list = @list.dup
- end
-
- ##
- # Adds Resolver::DependencyRequest +req+ to this requirements list.
-
- def add(req)
- if req.requirement.exact?
- @exact.push req
- else
- @list.push req
- end
- req
- end
-
- ##
- # Enumerates requirements in the list
-
- def each # :nodoc:
- return enum_for __method__ unless block_given?
-
- @exact.each do |requirement|
- yield requirement
- end
-
- @list.each do |requirement|
- yield requirement
- end
- end
-
- ##
- # How many elements are in the list
-
- def size
- @exact.size + @list.size
- end
-
- ##
- # Is the list empty?
-
- def empty?
- @exact.empty? && @list.empty?
- end
-
- ##
- # Remove the oldest DependencyRequest from the list.
-
- def remove
- return @exact.shift unless @exact.empty?
- @list.shift
- end
-
- ##
- # Returns the oldest five entries from the list.
-
- def next5
- x = @exact[0,5]
- x + @list[0,5 - x.size]
- end
-end
diff --git a/ruby_2_2/lib/rubygems/resolver/set.rb b/ruby_2_2/lib/rubygems/resolver/set.rb
deleted file mode 100644
index b26dc45c7b..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/set.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-##
-# Resolver sets are used to look up specifications (and their
-# dependencies) used in resolution. This set is abstract.
-
-class Gem::Resolver::Set
-
- ##
- # Set to true to disable network access for this set
-
- attr_accessor :remote
-
- ##
- # Errors encountered when resolving gems
-
- attr_accessor :errors
-
- ##
- # When true, allows matching of requests to prerelease gems.
-
- attr_accessor :prerelease
-
- def initialize # :nodoc:
- @prerelease = false
- @remote = true
- @errors = []
- end
-
- ##
- # The find_all method must be implemented. It returns all Resolver
- # Specification objects matching the given DependencyRequest +req+.
-
- def find_all req
- raise NotImplementedError
- end
-
- ##
- # The #prefetch method may be overridden, but this is not necessary. This
- # default implementation does nothing, which is suitable for sets where
- # looking up a specification is cheap (such as installed gems).
- #
- # When overridden, the #prefetch method should look up specifications
- # matching +reqs+.
-
- def prefetch reqs
- end
-
- ##
- # When true, this set is allowed to access the network when looking up
- # specifications or dependencies.
-
- def remote? # :nodoc:
- @remote
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/resolver/spec_specification.rb b/ruby_2_2/lib/rubygems/resolver/spec_specification.rb
deleted file mode 100644
index 1350e8a7ab..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/spec_specification.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-##
-# The Resolver::SpecSpecification contains common functionality for
-# Resolver specifications that are backed by a Gem::Specification.
-
-class Gem::Resolver::SpecSpecification < Gem::Resolver::Specification
-
- ##
- # A SpecSpecification is created for a +set+ for a Gem::Specification in
- # +spec+. The +source+ is either where the +spec+ came from, or should be
- # loaded from.
-
- def initialize set, spec, source = nil
- @set = set
- @source = source
- @spec = spec
- end
-
- ##
- # The dependencies of the gem for this specification
-
- def dependencies
- spec.dependencies
- end
-
- ##
- # The name and version of the specification.
- #
- # Unlike Gem::Specification#full_name, the platform is not included.
-
- def full_name
- "#{spec.name}-#{spec.version}"
- end
-
- ##
- # The name of the gem for this specification
-
- def name
- spec.name
- end
-
- ##
- # The platform this gem works on.
-
- def platform
- spec.platform
- end
-
- ##
- # The version of the gem for this specification.
-
- def version
- spec.version
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/resolver/specification.rb b/ruby_2_2/lib/rubygems/resolver/specification.rb
deleted file mode 100644
index 4d77293262..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/specification.rb
+++ /dev/null
@@ -1,110 +0,0 @@
-##
-# A Resolver::Specification contains a subset of the information
-# contained in a Gem::Specification. Only the information necessary for
-# dependency resolution in the resolver is included.
-
-class Gem::Resolver::Specification
-
- ##
- # The dependencies of the gem for this specification
-
- attr_reader :dependencies
-
- ##
- # The name of the gem for this specification
-
- attr_reader :name
-
- ##
- # The platform this gem works on.
-
- attr_reader :platform
-
- ##
- # The set this specification came from.
-
- attr_reader :set
-
- ##
- # The source for this specification
-
- attr_reader :source
-
- ##
- # The Gem::Specification for this Resolver::Specification.
- #
- # Implementers, note that #install updates @spec, so be sure to cache the
- # Gem::Specification in @spec when overriding.
-
- attr_reader :spec
-
- ##
- # The version of the gem for this specification.
-
- attr_reader :version
-
- ##
- # Sets default instance variables for the specification.
-
- def initialize
- @dependencies = nil
- @name = nil
- @platform = nil
- @set = nil
- @source = nil
- @version = nil
- end
-
- ##
- # Fetches development dependencies if the source does not provide them by
- # default (see APISpecification).
-
- def fetch_development_dependencies # :nodoc:
- end
-
- ##
- # The name and version of the specification.
- #
- # Unlike Gem::Specification#full_name, the platform is not included.
-
- def full_name
- "#{@name}-#{@version}"
- end
-
- ##
- # Installs this specification using the Gem::Installer +options+. The
- # install method yields a Gem::Installer instance, which indicates the
- # gem will be installed, or +nil+, which indicates the gem is already
- # installed.
- #
- # After installation #spec is updated to point to the just-installed
- # specification.
-
- def install options = {}
- require 'rubygems/installer'
-
- destination = options[:install_dir] || Gem.dir
-
- Gem.ensure_gem_subdirectories destination
-
- gem = source.download spec, destination
-
- installer = Gem::Installer.new gem, options
-
- yield installer if block_given?
-
- @spec = installer.install
- end
-
- ##
- # Returns true if this specification is installable on this platform.
-
- def installable_platform?
- Gem::Platform.match spec.platform
- end
-
- def local? # :nodoc:
- false
- end
-end
-
diff --git a/ruby_2_2/lib/rubygems/resolver/stats.rb b/ruby_2_2/lib/rubygems/resolver/stats.rb
deleted file mode 100644
index c31e5be962..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/stats.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-class Gem::Resolver::Stats
- def initialize
- @max_depth = 0
- @max_requirements = 0
- @requirements = 0
- @backtracking = 0
- @iterations = 0
- end
-
- def record_depth(stack)
- if stack.size > @max_depth
- @max_depth = stack.size
- end
- end
-
- def record_requirements(reqs)
- if reqs.size > @max_requirements
- @max_requirements = reqs.size
- end
- end
-
- def requirement!
- @requirements += 1
- end
-
- def backtracking!
- @backtracking += 1
- end
-
- def iteration!
- @iterations += 1
- end
-
- PATTERN = "%20s: %d\n"
-
- def display
- $stdout.puts "=== Resolver Statistics ==="
- $stdout.printf PATTERN, "Max Depth", @max_depth
- $stdout.printf PATTERN, "Total Requirements", @requirements
- $stdout.printf PATTERN, "Max Requirements", @max_requirements
- $stdout.printf PATTERN, "Backtracking #", @backtracking
- $stdout.printf PATTERN, "Iteration #", @iterations
- end
-end
diff --git a/ruby_2_2/lib/rubygems/resolver/vendor_set.rb b/ruby_2_2/lib/rubygems/resolver/vendor_set.rb
deleted file mode 100644
index 614bd05382..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/vendor_set.rb
+++ /dev/null
@@ -1,87 +0,0 @@
-##
-# A VendorSet represents gems that have been unpacked into a specific
-# directory that contains a gemspec.
-#
-# This is used for gem dependency file support.
-#
-# Example:
-#
-# set = Gem::Resolver::VendorSet.new
-#
-# set.add_vendor_gem 'rake', 'vendor/rake'
-#
-# The directory vendor/rake must contain an unpacked rake gem along with a
-# rake.gemspec (watching the given name).
-
-class Gem::Resolver::VendorSet < Gem::Resolver::Set
-
- ##
- # The specifications for this set.
-
- attr_reader :specs # :nodoc:
-
- def initialize # :nodoc:
- super()
-
- @directories = {}
- @specs = {}
- end
-
- ##
- # Adds a specification to the set with the given +name+ which has been
- # unpacked into the given +directory+.
-
- def add_vendor_gem name, directory # :nodoc:
- gemspec = File.join directory, "#{name}.gemspec"
-
- spec = Gem::Specification.load gemspec
-
- raise Gem::GemNotFoundException,
- "unable to find #{gemspec} for gem #{name}" unless spec
-
- spec.full_gem_path = File.expand_path directory
-
- @specs[spec.name] = spec
- @directories[spec] = directory
-
- spec
- end
-
- ##
- # Returns an Array of VendorSpecification objects matching the
- # DependencyRequest +req+.
-
- def find_all req
- @specs.values.select do |spec|
- req.match? spec
- end.map do |spec|
- source = Gem::Source::Vendor.new @directories[spec]
- Gem::Resolver::VendorSpecification.new self, spec, source
- end
- end
-
- ##
- # Loads a spec with the given +name+. +version+, +platform+ and +source+ are
- # ignored.
-
- def load_spec name, version, platform, source # :nodoc:
- @specs.fetch name
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[VendorSet', ']' do
- next if @directories.empty?
- q.breakable
-
- dirs = @directories.map do |spec, directory|
- "#{spec.full_name}: #{directory}"
- end
-
- q.seplist dirs do |dir|
- q.text dir
- end
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/resolver/vendor_specification.rb b/ruby_2_2/lib/rubygems/resolver/vendor_specification.rb
deleted file mode 100644
index a99b5f3cc1..0000000000
--- a/ruby_2_2/lib/rubygems/resolver/vendor_specification.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-##
-# A VendorSpecification represents a gem that has been unpacked into a project
-# and is being loaded through a gem dependencies file through the +path:+
-# option.
-
-class Gem::Resolver::VendorSpecification < Gem::Resolver::SpecSpecification
-
- def == other # :nodoc:
- self.class === other and
- @set == other.set and
- @spec == other.spec and
- @source == other.source
- end
-
- ##
- # This is a null install as this gem was unpacked into a directory.
- # +options+ are ignored.
-
- def install options = {}
- yield nil
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/safe_yaml.rb b/ruby_2_2/lib/rubygems/safe_yaml.rb
deleted file mode 100644
index b98cfaa5e6..0000000000
--- a/ruby_2_2/lib/rubygems/safe_yaml.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-module Gem
-
- ###
- # This module is used for safely loading YAML specs from a gem. The
- # `safe_load` method defined on this module is specifically designed for
- # loading Gem specifications. For loading other YAML safely, please see
- # Psych.safe_load
-
- module SafeYAML
- WHITELISTED_CLASSES = %w(
- Symbol
- Time
- Date
- Gem::Dependency
- Gem::Platform
- Gem::Requirement
- Gem::Specification
- Gem::Version
- Gem::Version::Requirement
- YAML::Syck::DefaultKey
- Syck::DefaultKey
- )
-
- WHITELISTED_SYMBOLS = %w(
- development
- runtime
- )
-
- if ::YAML.respond_to? :safe_load
- def self.safe_load input
- ::YAML.safe_load(input, WHITELISTED_CLASSES, WHITELISTED_SYMBOLS, true)
- end
-
- def self.load input
- ::YAML.safe_load(input, [::Symbol])
- end
- else
- warn "YAML safe loading is not available. Please upgrade psych to a version that supports safe loading (>= 2.0)."
- def self.safe_load input, *args
- ::YAML.load input
- end
-
- def self.load input
- ::YAML.load input
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/rubygems/security.rb b/ruby_2_2/lib/rubygems/security.rb
deleted file mode 100644
index 8c5fb7d9f2..0000000000
--- a/ruby_2_2/lib/rubygems/security.rb
+++ /dev/null
@@ -1,595 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'rubygems/exceptions'
-require 'fileutils'
-
-begin
- require 'openssl'
-rescue LoadError => e
- raise unless (e.respond_to?(:path) && e.path == 'openssl') ||
- e.message =~ / -- openssl$/
-end
-
-##
-# = Signing gems
-#
-# The Gem::Security implements cryptographic signatures for gems. The section
-# below is a step-by-step guide to using signed gems and generating your own.
-#
-# == Walkthrough
-#
-# === Building your certificate
-#
-# In order to start signing your gems, you'll need to build a private key and
-# a self-signed certificate. Here's how:
-#
-# # build a private key and certificate for yourself:
-# $ gem cert --build you@example.com
-#
-# This could take anywhere from a few seconds to a minute or two, depending on
-# the speed of your computer (public key algorithms aren't exactly the
-# speediest crypto algorithms in the world). When it's finished, you'll see
-# the files "gem-private_key.pem" and "gem-public_cert.pem" in the current
-# directory.
-#
-# First things first: Move both files to ~/.gem if you don't already have a
-# key and certificate in that directory. Ensure the file permissions make the
-# key unreadable by others (by default the file is saved securely).
-#
-# Keep your private key hidden; if it's compromised, someone can sign packages
-# as you (note: PKI has ways of mitigating the risk of stolen keys; more on
-# that later).
-#
-# === Signing Gems
-#
-# In RubyGems 2 and newer there is no extra work to sign a gem. RubyGems will
-# automatically find your key and certificate in your home directory and use
-# them to sign newly packaged gems.
-#
-# If your certificate is not self-signed (signed by a third party) RubyGems
-# will attempt to load the certificate chain from the trusted certificates.
-# Use <code>gem cert --add signing_cert.pem</code> to add your signers as
-# trusted certificates. See below for further information on certificate
-# chains.
-#
-# If you build your gem it will automatically be signed. If you peek inside
-# your gem file, you'll see a couple of new files have been added:
-#
-# $ tar tf your-gem-1.0.gem
-# metadata.gz
-# metadata.gz.sum
-# metadata.gz.sig # metadata signature
-# data.tar.gz
-# data.tar.gz.sum
-# data.tar.gz.sig # data signature
-#
-# === Manually signing gems
-#
-# If you wish to store your key in a separate secure location you'll need to
-# set your gems up for signing by hand. To do this, set the
-# <code>signing_key</code> and <code>cert_chain</code> in the gemspec before
-# packaging your gem:
-#
-# s.signing_key = '/secure/path/to/gem-private_key.pem'
-# s.cert_chain = %w[/secure/path/to/gem-public_cert.pem]
-#
-# When you package your gem with these options set RubyGems will automatically
-# load your key and certificate from the secure paths.
-#
-# === Signed gems and security policies
-#
-# Now let's verify the signature. Go ahead and install the gem, but add the
-# following options: <code>-P HighSecurity</code>, like this:
-#
-# # install the gem with using the security policy "HighSecurity"
-# $ sudo gem install your.gem -P HighSecurity
-#
-# The <code>-P</code> option sets your security policy -- we'll talk about
-# that in just a minute. Eh, what's this?
-#
-# $ gem install -P HighSecurity your-gem-1.0.gem
-# ERROR: While executing gem ... (Gem::Security::Exception)
-# root cert /CN=you/DC=example is not trusted
-#
-# The culprit here is the security policy. RubyGems has several different
-# security policies. Let's take a short break and go over the security
-# policies. Here's a list of the available security policies, and a brief
-# description of each one:
-#
-# * NoSecurity - Well, no security at all. Signed packages are treated like
-# unsigned packages.
-# * LowSecurity - Pretty much no security. If a package is signed then
-# RubyGems will make sure the signature matches the signing
-# certificate, and that the signing certificate hasn't expired, but
-# that's it. A malicious user could easily circumvent this kind of
-# security.
-# * MediumSecurity - Better than LowSecurity and NoSecurity, but still
-# fallible. Package contents are verified against the signing
-# certificate, and the signing certificate is checked for validity,
-# and checked against the rest of the certificate chain (if you don't
-# know what a certificate chain is, stay tuned, we'll get to that).
-# The biggest improvement over LowSecurity is that MediumSecurity
-# won't install packages that are signed by untrusted sources.
-# Unfortunately, MediumSecurity still isn't totally secure -- a
-# malicious user can still unpack the gem, strip the signatures, and
-# distribute the gem unsigned.
-# * HighSecurity - Here's the bugger that got us into this mess.
-# The HighSecurity policy is identical to the MediumSecurity policy,
-# except that it does not allow unsigned gems. A malicious user
-# doesn't have a whole lot of options here; they can't modify the
-# package contents without invalidating the signature, and they can't
-# modify or remove signature or the signing certificate chain, or
-# RubyGems will simply refuse to install the package. Oh well, maybe
-# they'll have better luck causing problems for CPAN users instead :).
-#
-# The reason RubyGems refused to install your shiny new signed gem was because
-# it was from an untrusted source. Well, your code is infallible (naturally),
-# so you need to add yourself as a trusted source:
-#
-# # add trusted certificate
-# gem cert --add ~/.gem/gem-public_cert.pem
-#
-# You've now added your public certificate as a trusted source. Now you can
-# install packages signed by your private key without any hassle. Let's try
-# the install command above again:
-#
-# # install the gem with using the HighSecurity policy (and this time
-# # without any shenanigans)
-# $ gem install -P HighSecurity your-gem-1.0.gem
-# Successfully installed your-gem-1.0
-# 1 gem installed
-#
-# This time RubyGems will accept your signed package and begin installing.
-#
-# While you're waiting for RubyGems to work it's magic, have a look at some of
-# the other security commands by running <code>gem help cert</code>:
-#
-# Options:
-# -a, --add CERT Add a trusted certificate.
-# -l, --list [FILTER] List trusted certificates where the
-# subject contains FILTER
-# -r, --remove FILTER Remove trusted certificates where the
-# subject contains FILTER
-# -b, --build EMAIL_ADDR Build private key and self-signed
-# certificate for EMAIL_ADDR
-# -C, --certificate CERT Signing certificate for --sign
-# -K, --private-key KEY Key for --sign or --build
-# -s, --sign CERT Signs CERT with the key from -K
-# and the certificate from -C
-#
-# We've already covered the <code>--build</code> option, and the
-# <code>--add</code>, <code>--list</code>, and <code>--remove</code> commands
-# seem fairly straightforward; they allow you to add, list, and remove the
-# certificates in your trusted certificate list. But what's with this
-# <code>--sign</code> option?
-#
-# === Certificate chains
-#
-# To answer that question, let's take a look at "certificate chains", a
-# concept I mentioned earlier. There are a couple of problems with
-# self-signed certificates: first of all, self-signed certificates don't offer
-# a whole lot of security. Sure, the certificate says Yukihiro Matsumoto, but
-# how do I know it was actually generated and signed by matz himself unless he
-# gave me the certificate in person?
-#
-# The second problem is scalability. Sure, if there are 50 gem authors, then
-# I have 50 trusted certificates, no problem. What if there are 500 gem
-# authors? 1000? Having to constantly add new trusted certificates is a
-# pain, and it actually makes the trust system less secure by encouraging
-# RubyGems users to blindly trust new certificates.
-#
-# Here's where certificate chains come in. A certificate chain establishes an
-# arbitrarily long chain of trust between an issuing certificate and a child
-# certificate. So instead of trusting certificates on a per-developer basis,
-# we use the PKI concept of certificate chains to build a logical hierarchy of
-# trust. Here's a hypothetical example of a trust hierarchy based (roughly)
-# on geography:
-#
-# --------------------------
-# | rubygems@rubygems.org |
-# --------------------------
-# |
-# -----------------------------------
-# | |
-# ---------------------------- -----------------------------
-# | seattlerb@seattlerb.org | | dcrubyists@richkilmer.com |
-# ---------------------------- -----------------------------
-# | | | |
-# --------------- ---------------- ----------- --------------
-# | drbrain | | zenspider | | pabs@dc | | tomcope@dc |
-# --------------- ---------------- ----------- --------------
-#
-#
-# Now, rather than having 4 trusted certificates (one for drbrain, zenspider,
-# pabs@dc, and tomecope@dc), a user could actually get by with one
-# certificate, the "rubygems@rubygems.org" certificate.
-#
-# Here's how it works:
-#
-# I install "rdoc-3.12.gem", a package signed by "drbrain". I've never heard
-# of "drbrain", but his certificate has a valid signature from the
-# "seattle.rb@seattlerb.org" certificate, which in turn has a valid signature
-# from the "rubygems@rubygems.org" certificate. Voila! At this point, it's
-# much more reasonable for me to trust a package signed by "drbrain", because
-# I can establish a chain to "rubygems@rubygems.org", which I do trust.
-#
-# === Signing certificates
-#
-# The <code>--sign</code> option allows all this to happen. A developer
-# creates their build certificate with the <code>--build</code> option, then
-# has their certificate signed by taking it with them to their next regional
-# Ruby meetup (in our hypothetical example), and it's signed there by the
-# person holding the regional RubyGems signing certificate, which is signed at
-# the next RubyConf by the holder of the top-level RubyGems certificate. At
-# each point the issuer runs the same command:
-#
-# # sign a certificate with the specified key and certificate
-# # (note that this modifies client_cert.pem!)
-# $ gem cert -K /mnt/floppy/issuer-priv_key.pem -C issuer-pub_cert.pem
-# --sign client_cert.pem
-#
-# Then the holder of issued certificate (in this case, your buddy "drbrain"),
-# can start using this signed certificate to sign RubyGems. By the way, in
-# order to let everyone else know about his new fancy signed certificate,
-# "drbrain" would save his newly signed certificate as
-# <code>~/.gem/gem-public_cert.pem</code>
-#
-# Obviously this RubyGems trust infrastructure doesn't exist yet. Also, in
-# the "real world", issuers actually generate the child certificate from a
-# certificate request, rather than sign an existing certificate. And our
-# hypothetical infrastructure is missing a certificate revocation system.
-# These are that can be fixed in the future...
-#
-# At this point you should know how to do all of these new and interesting
-# things:
-#
-# * build a gem signing key and certificate
-# * adjust your security policy
-# * modify your trusted certificate list
-# * sign a certificate
-#
-# == Manually verifying signatures
-#
-# In case you don't trust RubyGems you can verify gem signatures manually:
-#
-# 1. Fetch and unpack the gem
-#
-# gem fetch some_signed_gem
-# tar -xf some_signed_gem-1.0.gem
-#
-# 2. Grab the public key from the gemspec
-#
-# gem spec some_signed_gem-1.0.gem cert_chain | \
-# ruby -ryaml -e 'puts YAML.load_documents($stdin)' > public_key.crt
-#
-# 3. Generate a SHA1 hash of the data.tar.gz
-#
-# openssl dgst -sha1 < data.tar.gz > my.hash
-#
-# 4. Verify the signature
-#
-# openssl rsautl -verify -inkey public_key.crt -certin \
-# -in data.tar.gz.sig > verified.hash
-#
-# 5. Compare your hash to the verified hash
-#
-# diff -s verified.hash my.hash
-#
-# 6. Repeat 5 and 6 with metadata.gz
-#
-# == OpenSSL Reference
-#
-# The .pem files generated by --build and --sign are PEM files. Here's a
-# couple of useful OpenSSL commands for manipulating them:
-#
-# # convert a PEM format X509 certificate into DER format:
-# # (note: Windows .cer files are X509 certificates in DER format)
-# $ openssl x509 -in input.pem -outform der -out output.der
-#
-# # print out the certificate in a human-readable format:
-# $ openssl x509 -in input.pem -noout -text
-#
-# And you can do the same thing with the private key file as well:
-#
-# # convert a PEM format RSA key into DER format:
-# $ openssl rsa -in input_key.pem -outform der -out output_key.der
-#
-# # print out the key in a human readable format:
-# $ openssl rsa -in input_key.pem -noout -text
-#
-# == Bugs/TODO
-#
-# * There's no way to define a system-wide trust list.
-# * custom security policies (from a YAML file, etc)
-# * Simple method to generate a signed certificate request
-# * Support for OCSP, SCVP, CRLs, or some other form of cert status check
-# (list is in order of preference)
-# * Support for encrypted private keys
-# * Some sort of semi-formal trust hierarchy (see long-winded explanation
-# above)
-# * Path discovery (for gem certificate chains that don't have a self-signed
-# root) -- by the way, since we don't have this, THE ROOT OF THE CERTIFICATE
-# CHAIN MUST BE SELF SIGNED if Policy#verify_root is true (and it is for the
-# MediumSecurity and HighSecurity policies)
-# * Better explanation of X509 naming (ie, we don't have to use email
-# addresses)
-# * Honor AIA field (see note about OCSP above)
-# * Honor extension restrictions
-# * Might be better to store the certificate chain as a PKCS#7 or PKCS#12
-# file, instead of an array embedded in the metadata.
-# * Flexible signature and key algorithms, not hard-coded to RSA and SHA1.
-#
-# == Original author
-#
-# Paul Duncan <pabs@pablotron.org>
-# http://pablotron.org/
-
-module Gem::Security
-
- ##
- # Gem::Security default exception type
-
- class Exception < Gem::Exception; end
-
- ##
- # Digest algorithm used to sign gems
-
- DIGEST_ALGORITHM =
- if defined?(OpenSSL::Digest) then
- OpenSSL::Digest::SHA1
- end
-
- ##
- # Used internally to select the signing digest from all computed digests
-
- DIGEST_NAME = # :nodoc:
- if DIGEST_ALGORITHM then
- DIGEST_ALGORITHM.new.name
- end
-
- ##
- # Algorithm for creating the key pair used to sign gems
-
- KEY_ALGORITHM =
- if defined?(OpenSSL::PKey) then
- OpenSSL::PKey::RSA
- end
-
- ##
- # Length of keys created by KEY_ALGORITHM
-
- KEY_LENGTH = 2048
-
- ##
- # Cipher used to encrypt the key pair used to sign gems.
- # Must be in the list returned by OpenSSL::Cipher.ciphers
-
- KEY_CIPHER = OpenSSL::Cipher.new('AES-256-CBC') if defined?(OpenSSL::Cipher)
-
- ##
- # One year in seconds
-
- ONE_YEAR = 86400 * 365
-
- ##
- # The default set of extensions are:
- #
- # * The certificate is not a certificate authority
- # * The key for the certificate may be used for key and data encipherment
- # and digital signatures
- # * The certificate contains a subject key identifier
-
- EXTENSIONS = {
- 'basicConstraints' => 'CA:FALSE',
- 'keyUsage' =>
- 'keyEncipherment,dataEncipherment,digitalSignature',
- 'subjectKeyIdentifier' => 'hash',
- }
-
- def self.alt_name_or_x509_entry certificate, x509_entry
- alt_name = certificate.extensions.find do |extension|
- extension.oid == "#{x509_entry}AltName"
- end
-
- return alt_name.value if alt_name
-
- certificate.send x509_entry
- end
-
- ##
- # Creates an unsigned certificate for +subject+ and +key+. The lifetime of
- # the key is from the current time to +age+ which defaults to one year.
- #
- # The +extensions+ restrict the key to the indicated uses.
-
- def self.create_cert subject, key, age = ONE_YEAR, extensions = EXTENSIONS,
- serial = 1
- cert = OpenSSL::X509::Certificate.new
-
- cert.public_key = key.public_key
- cert.version = 2
- cert.serial = serial
-
- cert.not_before = Time.now
- cert.not_after = Time.now + age
-
- cert.subject = subject
-
- ef = OpenSSL::X509::ExtensionFactory.new nil, cert
-
- cert.extensions = extensions.map do |ext_name, value|
- ef.create_extension ext_name, value
- end
-
- cert
- end
-
- ##
- # Creates a self-signed certificate with an issuer and subject from +email+,
- # a subject alternative name of +email+ and the given +extensions+ for the
- # +key+.
-
- def self.create_cert_email email, key, age = ONE_YEAR, extensions = EXTENSIONS
- subject = email_to_name email
-
- extensions = extensions.merge "subjectAltName" => "email:#{email}"
-
- create_cert_self_signed subject, key, age, extensions
- end
-
- ##
- # Creates a self-signed certificate with an issuer and subject of +subject+
- # and the given +extensions+ for the +key+.
-
- def self.create_cert_self_signed subject, key, age = ONE_YEAR,
- extensions = EXTENSIONS, serial = 1
- certificate = create_cert subject, key, age, extensions
-
- sign certificate, key, certificate, age, extensions, serial
- end
-
- ##
- # Creates a new key pair of the specified +length+ and +algorithm+. The
- # default is a 2048 bit RSA key.
-
- def self.create_key length = KEY_LENGTH, algorithm = KEY_ALGORITHM
- algorithm.new length
- end
-
- ##
- # Turns +email_address+ into an OpenSSL::X509::Name
-
- def self.email_to_name email_address
- email_address = email_address.gsub(/[^\w@.-]+/i, '_')
-
- cn, dcs = email_address.split '@'
-
- dcs = dcs.split '.'
-
- name = "CN=#{cn}/#{dcs.map { |dc| "DC=#{dc}" }.join '/'}"
-
- OpenSSL::X509::Name.parse name
- end
-
- ##
- # Signs +expired_certificate+ with +private_key+ if the keys match and the
- # expired certificate was self-signed.
- #--
- # TODO increment serial
-
- def self.re_sign expired_certificate, private_key, age = ONE_YEAR,
- extensions = EXTENSIONS
- raise Gem::Security::Exception,
- "incorrect signing key for re-signing " +
- "#{expired_certificate.subject}" unless
- expired_certificate.public_key.to_pem == private_key.public_key.to_pem
-
- unless expired_certificate.subject.to_s ==
- expired_certificate.issuer.to_s then
- subject = alt_name_or_x509_entry expired_certificate, :subject
- issuer = alt_name_or_x509_entry expired_certificate, :issuer
-
- raise Gem::Security::Exception,
- "#{subject} is not self-signed, contact #{issuer} " +
- "to obtain a valid certificate"
- end
-
- serial = expired_certificate.serial + 1
-
- create_cert_self_signed(expired_certificate.subject, private_key, age,
- extensions, serial)
- end
-
- ##
- # Resets the trust directory for verifying gems.
-
- def self.reset
- @trust_dir = nil
- end
-
- ##
- # Sign the public key from +certificate+ with the +signing_key+ and
- # +signing_cert+, using the Gem::Security::DIGEST_ALGORITHM. Uses the
- # default certificate validity range and extensions.
- #
- # Returns the newly signed certificate.
-
- def self.sign certificate, signing_key, signing_cert,
- age = ONE_YEAR, extensions = EXTENSIONS, serial = 1
- signee_subject = certificate.subject
- signee_key = certificate.public_key
-
- alt_name = certificate.extensions.find do |extension|
- extension.oid == 'subjectAltName'
- end
-
- extensions = extensions.merge 'subjectAltName' => alt_name.value if
- alt_name
-
- issuer_alt_name = signing_cert.extensions.find do |extension|
- extension.oid == 'subjectAltName'
- end
-
- extensions = extensions.merge 'issuerAltName' => issuer_alt_name.value if
- issuer_alt_name
-
- signed = create_cert signee_subject, signee_key, age, extensions, serial
- signed.issuer = signing_cert.subject
-
- signed.sign signing_key, Gem::Security::DIGEST_ALGORITHM.new
- end
-
- ##
- # Returns a Gem::Security::TrustDir which wraps the directory where trusted
- # certificates live.
-
- def self.trust_dir
- return @trust_dir if @trust_dir
-
- dir = File.join Gem.user_home, '.gem', 'trust'
-
- @trust_dir ||= Gem::Security::TrustDir.new dir
- end
-
- ##
- # Enumerates the trusted certificates via Gem::Security::TrustDir.
-
- def self.trusted_certificates &block
- trust_dir.each_certificate(&block)
- end
-
- ##
- # Writes +pemmable+, which must respond to +to_pem+ to +path+ with the given
- # +permissions+. If passed +cipher+ and +passphrase+ those arguments will be
- # passed to +to_pem+.
-
- def self.write pemmable, path, permissions = 0600, passphrase = nil, cipher = KEY_CIPHER
- path = File.expand_path path
-
- open path, 'wb', permissions do |io|
- if passphrase and cipher
- io.write pemmable.to_pem cipher, passphrase
- else
- io.write pemmable.to_pem
- end
- end
-
- path
- end
-
- reset
-
-end
-
-if defined?(OpenSSL::SSL) then
- require 'rubygems/security/policy'
- require 'rubygems/security/policies'
- require 'rubygems/security/trust_dir'
-end
-
-require 'rubygems/security/signer'
-
diff --git a/ruby_2_2/lib/rubygems/security/policies.rb b/ruby_2_2/lib/rubygems/security/policies.rb
deleted file mode 100644
index a976ecaf59..0000000000
--- a/ruby_2_2/lib/rubygems/security/policies.rb
+++ /dev/null
@@ -1,115 +0,0 @@
-module Gem::Security
-
- ##
- # No security policy: all package signature checks are disabled.
-
- NoSecurity = Policy.new(
- 'No Security',
- :verify_data => false,
- :verify_signer => false,
- :verify_chain => false,
- :verify_root => false,
- :only_trusted => false,
- :only_signed => false
- )
-
- ##
- # AlmostNo security policy: only verify that the signing certificate is the
- # one that actually signed the data. Make no attempt to verify the signing
- # certificate chain.
- #
- # This policy is basically useless. better than nothing, but can still be
- # easily spoofed, and is not recommended.
-
- AlmostNoSecurity = Policy.new(
- 'Almost No Security',
- :verify_data => true,
- :verify_signer => false,
- :verify_chain => false,
- :verify_root => false,
- :only_trusted => false,
- :only_signed => false
- )
-
- ##
- # Low security policy: only verify that the signing certificate is actually
- # the gem signer, and that the signing certificate is valid.
- #
- # This policy is better than nothing, but can still be easily spoofed, and
- # is not recommended.
-
- LowSecurity = Policy.new(
- 'Low Security',
- :verify_data => true,
- :verify_signer => true,
- :verify_chain => false,
- :verify_root => false,
- :only_trusted => false,
- :only_signed => false
- )
-
- ##
- # Medium security policy: verify the signing certificate, verify the signing
- # certificate chain all the way to the root certificate, and only trust root
- # certificates that we have explicitly allowed trust for.
- #
- # This security policy is reasonable, but it allows unsigned packages, so a
- # malicious person could simply delete the package signature and pass the
- # gem off as unsigned.
-
- MediumSecurity = Policy.new(
- 'Medium Security',
- :verify_data => true,
- :verify_signer => true,
- :verify_chain => true,
- :verify_root => true,
- :only_trusted => true,
- :only_signed => false
- )
-
- ##
- # High security policy: only allow signed gems to be installed, verify the
- # signing certificate, verify the signing certificate chain all the way to
- # the root certificate, and only trust root certificates that we have
- # explicitly allowed trust for.
- #
- # This security policy is significantly more difficult to bypass, and offers
- # a reasonable guarantee that the contents of the gem have not been altered.
-
- HighSecurity = Policy.new(
- 'High Security',
- :verify_data => true,
- :verify_signer => true,
- :verify_chain => true,
- :verify_root => true,
- :only_trusted => true,
- :only_signed => true
- )
-
- ##
- # Policy used to verify a certificate and key when signing a gem
-
- SigningPolicy = Policy.new(
- 'Signing Policy',
- :verify_data => false,
- :verify_signer => true,
- :verify_chain => true,
- :verify_root => true,
- :only_trusted => false,
- :only_signed => false
- )
-
- ##
- # Hash of configured security policies
-
- Policies = {
- 'NoSecurity' => NoSecurity,
- 'AlmostNoSecurity' => AlmostNoSecurity,
- 'LowSecurity' => LowSecurity,
- 'MediumSecurity' => MediumSecurity,
- 'HighSecurity' => HighSecurity,
- # SigningPolicy is not intended for use by `gem -P` so do not list it
- }
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/security/policy.rb b/ruby_2_2/lib/rubygems/security/policy.rb
deleted file mode 100644
index b9bcb17525..0000000000
--- a/ruby_2_2/lib/rubygems/security/policy.rb
+++ /dev/null
@@ -1,295 +0,0 @@
-require 'rubygems/user_interaction'
-
-##
-# A Gem::Security::Policy object encapsulates the settings for verifying
-# signed gem files. This is the base class. You can either declare an
-# instance of this or use one of the preset security policies in
-# Gem::Security::Policies.
-
-class Gem::Security::Policy
-
- include Gem::UserInteraction
-
- attr_reader :name
-
- attr_accessor :only_signed
- attr_accessor :only_trusted
- attr_accessor :verify_chain
- attr_accessor :verify_data
- attr_accessor :verify_root
- attr_accessor :verify_signer
-
- ##
- # Create a new Gem::Security::Policy object with the given mode and
- # options.
-
- def initialize name, policy = {}, opt = {}
- require 'openssl'
-
- @name = name
-
- @opt = opt
-
- # Default to security
- @only_signed = true
- @only_trusted = true
- @verify_chain = true
- @verify_data = true
- @verify_root = true
- @verify_signer = true
-
- policy.each_pair do |key, val|
- case key
- when :verify_data then @verify_data = val
- when :verify_signer then @verify_signer = val
- when :verify_chain then @verify_chain = val
- when :verify_root then @verify_root = val
- when :only_trusted then @only_trusted = val
- when :only_signed then @only_signed = val
- end
- end
- end
-
- ##
- # Verifies each certificate in +chain+ has signed the following certificate
- # and is valid for the given +time+.
-
- def check_chain chain, time
- raise Gem::Security::Exception, 'missing signing chain' unless chain
- raise Gem::Security::Exception, 'empty signing chain' if chain.empty?
-
- begin
- chain.each_cons 2 do |issuer, cert|
- check_cert cert, issuer, time
- end
-
- true
- rescue Gem::Security::Exception => e
- raise Gem::Security::Exception, "invalid signing chain: #{e.message}"
- end
- end
-
- ##
- # Verifies that +data+ matches the +signature+ created by +public_key+ and
- # the +digest+ algorithm.
-
- def check_data public_key, digest, signature, data
- raise Gem::Security::Exception, "invalid signature" unless
- public_key.verify digest.new, signature, data.digest
-
- true
- end
-
- ##
- # Ensures that +signer+ is valid for +time+ and was signed by the +issuer+.
- # If the +issuer+ is +nil+ no verification is performed.
-
- def check_cert signer, issuer, time
- raise Gem::Security::Exception, 'missing signing certificate' unless
- signer
-
- message = "certificate #{signer.subject}"
-
- if not_before = signer.not_before and not_before > time then
- raise Gem::Security::Exception,
- "#{message} not valid before #{not_before}"
- end
-
- if not_after = signer.not_after and not_after < time then
- raise Gem::Security::Exception, "#{message} not valid after #{not_after}"
- end
-
- if issuer and not signer.verify issuer.public_key then
- raise Gem::Security::Exception,
- "#{message} was not issued by #{issuer.subject}"
- end
-
- true
- end
-
- ##
- # Ensures the public key of +key+ matches the public key in +signer+
-
- def check_key signer, key
- unless signer and key then
- return true unless @only_signed
-
- raise Gem::Security::Exception, 'missing key or signature'
- end
-
- raise Gem::Security::Exception,
- "certificate #{signer.subject} does not match the signing key" unless
- signer.public_key.to_pem == key.public_key.to_pem
-
- true
- end
-
- ##
- # Ensures the root certificate in +chain+ is self-signed and valid for
- # +time+.
-
- def check_root chain, time
- raise Gem::Security::Exception, 'missing signing chain' unless chain
-
- root = chain.first
-
- raise Gem::Security::Exception, 'missing root certificate' unless root
-
- raise Gem::Security::Exception,
- "root certificate #{root.subject} is not self-signed " +
- "(issuer #{root.issuer})" if
- root.issuer.to_s != root.subject.to_s # HACK to_s is for ruby 1.8
-
- check_cert root, root, time
- end
-
- ##
- # Ensures the root of +chain+ has a trusted certificate in +trust_dir+ and
- # the digests of the two certificates match according to +digester+
-
- def check_trust chain, digester, trust_dir
- raise Gem::Security::Exception, 'missing signing chain' unless chain
-
- root = chain.first
-
- raise Gem::Security::Exception, 'missing root certificate' unless root
-
- path = Gem::Security.trust_dir.cert_path root
-
- unless File.exist? path then
- message = "root cert #{root.subject} is not trusted"
-
- message << " (root of signing cert #{chain.last.subject})" if
- chain.length > 1
-
- raise Gem::Security::Exception, message
- end
-
- save_cert = OpenSSL::X509::Certificate.new File.read path
- save_dgst = digester.digest save_cert.public_key.to_s
-
- pkey_str = root.public_key.to_s
- cert_dgst = digester.digest pkey_str
-
- raise Gem::Security::Exception,
- "trusted root certificate #{root.subject} checksum " +
- "does not match signing root certificate checksum" unless
- save_dgst == cert_dgst
-
- true
- end
-
- ##
- # Extracts the email or subject from +certificate+
-
- def subject certificate # :nodoc:
- certificate.extensions.each do |extension|
- next unless extension.oid == 'subjectAltName'
-
- return extension.value
- end
-
- certificate.subject.to_s
- end
-
- def inspect # :nodoc:
- ("[Policy: %s - data: %p signer: %p chain: %p root: %p " +
- "signed-only: %p trusted-only: %p]") % [
- @name, @verify_chain, @verify_data, @verify_root, @verify_signer,
- @only_signed, @only_trusted,
- ]
- end
-
- ##
- # For +full_name+, verifies the certificate +chain+ is valid, the +digests+
- # match the signatures +signatures+ created by the signer depending on the
- # +policy+ settings.
- #
- # If +key+ is given it is used to validate the signing certificate.
-
- def verify chain, key = nil, digests = {}, signatures = {},
- full_name = '(unknown)'
- if signatures.empty? then
- if @only_signed then
- raise Gem::Security::Exception,
- "unsigned gems are not allowed by the #{name} policy"
- elsif digests.empty? then
- # lack of signatures is irrelevant if there is nothing to check
- # against
- else
- alert_warning "#{full_name} is not signed"
- return
- end
- end
-
- opt = @opt
- digester = Gem::Security::DIGEST_ALGORITHM
- trust_dir = opt[:trust_dir]
- time = Time.now
-
- _, signer_digests = digests.find do |algorithm, file_digests|
- file_digests.values.first.name == Gem::Security::DIGEST_NAME
- end
-
- if @verify_data then
- raise Gem::Security::Exception, 'no digests provided (probable bug)' if
- signer_digests.nil? or signer_digests.empty?
- else
- signer_digests = {}
- end
-
- signer = chain.last
-
- check_key signer, key if key
-
- check_cert signer, nil, time if @verify_signer
-
- check_chain chain, time if @verify_chain
-
- check_root chain, time if @verify_root
-
- if @only_trusted then
- check_trust chain, digester, trust_dir
- elsif signatures.empty? and digests.empty? then
- # trust is irrelevant if there's no signatures to verify
- else
- alert_warning "#{subject signer} is not trusted for #{full_name}"
- end
-
- signatures.each do |file, _|
- digest = signer_digests[file]
-
- raise Gem::Security::Exception, "missing digest for #{file}" unless
- digest
- end
-
- signer_digests.each do |file, digest|
- signature = signatures[file]
-
- raise Gem::Security::Exception, "missing signature for #{file}" unless
- signature
-
- check_data signer.public_key, digester, signature, digest if @verify_data
- end
-
- true
- end
-
- ##
- # Extracts the certificate chain from the +spec+ and calls #verify to ensure
- # the signatures and certificate chain is valid according to the policy..
-
- def verify_signatures spec, digests, signatures
- chain = spec.cert_chain.map do |cert_pem|
- OpenSSL::X509::Certificate.new cert_pem
- end
-
- verify chain, nil, digests, signatures, spec.full_name
-
- true
- end
-
- alias to_s name # :nodoc:
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/security/signer.rb b/ruby_2_2/lib/rubygems/security/signer.rb
deleted file mode 100644
index bb1eae7cf2..0000000000
--- a/ruby_2_2/lib/rubygems/security/signer.rb
+++ /dev/null
@@ -1,154 +0,0 @@
-##
-# Basic OpenSSL-based package signing class.
-
-class Gem::Security::Signer
-
- ##
- # The chain of certificates for signing including the signing certificate
-
- attr_accessor :cert_chain
-
- ##
- # The private key for the signing certificate
-
- attr_accessor :key
-
- ##
- # The digest algorithm used to create the signature
-
- attr_reader :digest_algorithm
-
- ##
- # The name of the digest algorithm, used to pull digests out of the hash by
- # name.
-
- attr_reader :digest_name # :nodoc:
-
- ##
- # Creates a new signer with an RSA +key+ or path to a key, and a certificate
- # +chain+ containing X509 certificates, encoding certificates or paths to
- # certificates.
-
- def initialize key, cert_chain, passphrase = nil
- @cert_chain = cert_chain
- @key = key
-
- unless @key then
- default_key = File.join Gem.default_key_path
- @key = default_key if File.exist? default_key
- end
-
- unless @cert_chain then
- default_cert = File.join Gem.default_cert_path
- @cert_chain = [default_cert] if File.exist? default_cert
- end
-
- @digest_algorithm = Gem::Security::DIGEST_ALGORITHM
- @digest_name = Gem::Security::DIGEST_NAME
-
- @key = OpenSSL::PKey::RSA.new File.read(@key), passphrase if
- @key and not OpenSSL::PKey::RSA === @key
-
- if @cert_chain then
- @cert_chain = @cert_chain.compact.map do |cert|
- next cert if OpenSSL::X509::Certificate === cert
-
- cert = File.read cert if File.exist? cert
-
- OpenSSL::X509::Certificate.new cert
- end
-
- load_cert_chain
- end
- end
-
- ##
- # Extracts the full name of +cert+. If the certificate has a subjectAltName
- # this value is preferred, otherwise the subject is used.
-
- def extract_name cert # :nodoc:
- subject_alt_name = cert.extensions.find { |e| 'subjectAltName' == e.oid }
-
- if subject_alt_name then
- /\Aemail:/ =~ subject_alt_name.value
-
- $' || subject_alt_name.value
- else
- cert.subject
- end
- end
-
- ##
- # Loads any missing issuers in the cert chain from the trusted certificates.
- #
- # If the issuer does not exist it is ignored as it will be checked later.
-
- def load_cert_chain # :nodoc:
- return if @cert_chain.empty?
-
- while @cert_chain.first.issuer.to_s != @cert_chain.first.subject.to_s do
- issuer = Gem::Security.trust_dir.issuer_of @cert_chain.first
-
- break unless issuer # cert chain is verified later
-
- @cert_chain.unshift issuer
- end
- end
-
- ##
- # Sign data with given digest algorithm
-
- def sign data
- return unless @key
-
- if @cert_chain.length == 1 and @cert_chain.last.not_after < Time.now then
- re_sign_key
- end
-
- full_name = extract_name @cert_chain.last
-
- Gem::Security::SigningPolicy.verify @cert_chain, @key, {}, {}, full_name
-
- @key.sign @digest_algorithm.new, data
- end
-
- ##
- # Attempts to re-sign the private key if the signing certificate is expired.
- #
- # The key will be re-signed if:
- # * The expired certificate is self-signed
- # * The expired certificate is saved at ~/.gem/gem-public_cert.pem
- # * There is no file matching the expiry date at
- # ~/.gem/gem-public_cert.pem.expired.%Y%m%d%H%M%S
- #
- # If the signing certificate can be re-signed the expired certificate will
- # be saved as ~/.gem/gem-pubilc_cert.pem.expired.%Y%m%d%H%M%S where the
- # expiry time (not after) is used for the timestamp.
-
- def re_sign_key # :nodoc:
- old_cert = @cert_chain.last
-
- disk_cert_path = File.join Gem.default_cert_path
- disk_cert = File.read disk_cert_path rescue nil
- disk_key =
- File.read File.join(Gem.default_key_path) rescue nil
-
- if disk_key == @key.to_pem and disk_cert == old_cert.to_pem then
- expiry = old_cert.not_after.strftime '%Y%m%d%H%M%S'
- old_cert_file = "gem-public_cert.pem.expired.#{expiry}"
- old_cert_path = File.join Gem.user_home, ".gem", old_cert_file
-
- unless File.exist? old_cert_path then
- Gem::Security.write old_cert, old_cert_path
-
- cert = Gem::Security.re_sign old_cert, @key
-
- Gem::Security.write cert, disk_cert_path
-
- @cert_chain = [cert]
- end
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/security/trust_dir.rb b/ruby_2_2/lib/rubygems/security/trust_dir.rb
deleted file mode 100644
index 76ef89af7f..0000000000
--- a/ruby_2_2/lib/rubygems/security/trust_dir.rb
+++ /dev/null
@@ -1,118 +0,0 @@
-##
-# The TrustDir manages the trusted certificates for gem signature
-# verification.
-
-class Gem::Security::TrustDir
-
- ##
- # Default permissions for the trust directory and its contents
-
- DEFAULT_PERMISSIONS = {
- :trust_dir => 0700,
- :trusted_cert => 0600,
- }
-
- ##
- # The directory where trusted certificates will be stored.
-
- attr_reader :dir
-
- ##
- # Creates a new TrustDir using +dir+ where the directory and file
- # permissions will be checked according to +permissions+
-
- def initialize dir, permissions = DEFAULT_PERMISSIONS
- @dir = dir
- @permissions = permissions
-
- @digester = Gem::Security::DIGEST_ALGORITHM
- end
-
- ##
- # Returns the path to the trusted +certificate+
-
- def cert_path certificate
- name_path certificate.subject
- end
-
- ##
- # Enumerates trusted certificates.
-
- def each_certificate
- return enum_for __method__ unless block_given?
-
- glob = File.join @dir, '*.pem'
-
- Dir[glob].each do |certificate_file|
- begin
- certificate = load_certificate certificate_file
-
- yield certificate, certificate_file
- rescue OpenSSL::X509::CertificateError
- next # HACK warn
- end
- end
- end
-
- ##
- # Returns the issuer certificate of the given +certificate+ if it exists in
- # the trust directory.
-
- def issuer_of certificate
- path = name_path certificate.issuer
-
- return unless File.exist? path
-
- load_certificate path
- end
-
- ##
- # Returns the path to the trusted certificate with the given ASN.1 +name+
-
- def name_path name
- digest = @digester.hexdigest name.to_s
-
- File.join @dir, "cert-#{digest}.pem"
- end
-
- ##
- # Loads the given +certificate_file+
-
- def load_certificate certificate_file
- pem = File.read certificate_file
-
- OpenSSL::X509::Certificate.new pem
- end
-
- ##
- # Add a certificate to trusted certificate list.
-
- def trust_cert certificate
- verify
-
- destination = cert_path certificate
-
- open destination, 'wb', @permissions[:trusted_cert] do |io|
- io.write certificate.to_pem
- end
- end
-
- ##
- # Make sure the trust directory exists. If it does exist, make sure it's
- # actually a directory. If not, then create it with the appropriate
- # permissions.
-
- def verify
- if File.exist? @dir then
- raise Gem::Security::Exception,
- "trust directory #{@dir} is not a directory" unless
- File.directory? @dir
-
- FileUtils.chmod 0700, @dir
- else
- FileUtils.mkdir_p @dir, :mode => @permissions[:trust_dir]
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/server.rb b/ruby_2_2/lib/rubygems/server.rb
deleted file mode 100644
index 7655be22ce..0000000000
--- a/ruby_2_2/lib/rubygems/server.rb
+++ /dev/null
@@ -1,868 +0,0 @@
-require 'webrick'
-require 'zlib'
-require 'erb'
-
-require 'rubygems'
-require 'rubygems/rdoc'
-
-##
-# Gem::Server and allows users to serve gems for consumption by
-# `gem --remote-install`.
-#
-# gem_server starts an HTTP server on the given port and serves the following:
-# * "/" - Browsing of gem spec files for installed gems
-# * "/specs.#{Gem.marshal_version}.gz" - specs name/version/platform index
-# * "/latest_specs.#{Gem.marshal_version}.gz" - latest specs
-# name/version/platform index
-# * "/quick/" - Individual gemspecs
-# * "/gems" - Direct access to download the installable gems
-# * "/rdoc?q=" - Search for installed rdoc documentation
-#
-# == Usage
-#
-# gem_server = Gem::Server.new Gem.dir, 8089, false
-# gem_server.run
-#
-#--
-# TODO Refactor into a real WEBrick servlet to remove code duplication.
-
-class Gem::Server
-
- attr_reader :spec_dirs
-
- include ERB::Util
- include Gem::UserInteraction
-
- SEARCH = <<-SEARCH
- <form class="headerSearch" name="headerSearchForm" method="get" action="/rdoc">
- <div id="search" style="float:right">
- <label for="q">Filter/Search</label>
- <input id="q" type="text" style="width:10em" name="q">
- <button type="submit" style="display:none"></button>
- </div>
- </form>
- SEARCH
-
- DOC_TEMPLATE = <<-'DOC_TEMPLATE'
- <?xml version="1.0" encoding="iso-8859-1"?>
- <!DOCTYPE html
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>RubyGems Documentation Index</title>
- <link rel="stylesheet" href="gem-server-rdoc-style.css" type="text/css" media="screen" />
- </head>
- <body>
- <div id="fileHeader">
-<%= SEARCH %>
- <h1>RubyGems Documentation Index</h1>
- </div>
- <!-- banner header -->
-
- <div id="bodyContent">
- <div id="contextContent">
- <div id="description">
- <h1>Summary</h1>
- <p>There are <%=values["gem_count"]%> gems installed:</p>
- <p>
- <%= values["specs"].map { |v| "<a href=\"##{v["name"]}\">#{v["name"]}</a>" }.join ', ' %>.
- <h1>Gems</h1>
-
- <dl>
- <% values["specs"].each do |spec| %>
- <dt>
- <% if spec["first_name_entry"] then %>
- <a name="<%=spec["name"]%>"></a>
- <% end %>
-
- <b><%=spec["name"]%> <%=spec["version"]%></b>
-
- <% if spec["ri_installed"] then %>
- <a href="<%=spec["doc_path"]%>">[rdoc]</a>
- <% elsif spec["rdoc_installed"] then %>
- <a href="<%=spec["doc_path"]%>">[rdoc]</a>
- <% else %>
- <span title="rdoc not installed">[rdoc]</span>
- <% end %>
-
- <% if spec["homepage"] then %>
- <a href="<%=spec["homepage"]%>" title="<%=spec["homepage"]%>">[www]</a>
- <% else %>
- <span title="no homepage available">[www]</span>
- <% end %>
-
- <% if spec["has_deps"] then %>
- - depends on
- <%= spec["dependencies"].map { |v| "<a href=\"##{v["name"]}\">#{v["name"]}</a>" }.join ', ' %>.
- <% end %>
- </dt>
- <dd>
- <%=spec["summary"]%>
- <% if spec["executables"] then %>
- <br/>
-
- <% if spec["only_one_executable"] then %>
- Executable is
- <% else %>
- Executables are
- <%end%>
-
- <%= spec["executables"].map { |v| "<span class=\"context-item-name\">#{v["executable"]}</span>"}.join ', ' %>.
-
- <%end%>
- <br/>
- <br/>
- </dd>
- <% end %>
- </dl>
-
- </div>
- </div>
- </div>
- <div id="validator-badges">
- <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
- </div>
- </body>
- </html>
- DOC_TEMPLATE
-
- # CSS is copy & paste from rdoc-style.css, RDoc V1.0.1 - 20041108
- RDOC_CSS = <<-RDOC_CSS
-body {
- font-family: Verdana,Arial,Helvetica,sans-serif;
- font-size: 90%;
- margin: 0;
- margin-left: 40px;
- padding: 0;
- background: white;
-}
-
-h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; }
-h1 { font-size: 150%; }
-h2,h3,h4 { margin-top: 1em; }
-
-a { background: #eef; color: #039; text-decoration: none; }
-a:hover { background: #039; color: #eef; }
-
-/* Override the base stylesheets Anchor inside a table cell */
-td > a {
- background: transparent;
- color: #039;
- text-decoration: none;
-}
-
-/* and inside a section title */
-.section-title > a {
- background: transparent;
- color: #eee;
- text-decoration: none;
-}
-
-/* === Structural elements =================================== */
-
-div#index {
- margin: 0;
- margin-left: -40px;
- padding: 0;
- font-size: 90%;
-}
-
-
-div#index a {
- margin-left: 0.7em;
-}
-
-div#index .section-bar {
- margin-left: 0px;
- padding-left: 0.7em;
- background: #ccc;
- font-size: small;
-}
-
-
-div#classHeader, div#fileHeader {
- width: auto;
- color: white;
- padding: 0.5em 1.5em 0.5em 1.5em;
- margin: 0;
- margin-left: -40px;
- border-bottom: 3px solid #006;
-}
-
-div#classHeader a, div#fileHeader a {
- background: inherit;
- color: white;
-}
-
-div#classHeader td, div#fileHeader td {
- background: inherit;
- color: white;
-}
-
-
-div#fileHeader {
- background: #057;
-}
-
-div#classHeader {
- background: #048;
-}
-
-
-.class-name-in-header {
- font-size: 180%;
- font-weight: bold;
-}
-
-
-div#bodyContent {
- padding: 0 1.5em 0 1.5em;
-}
-
-div#description {
- padding: 0.5em 1.5em;
- background: #efefef;
- border: 1px dotted #999;
-}
-
-div#description h1,h2,h3,h4,h5,h6 {
- color: #125;;
- background: transparent;
-}
-
-div#validator-badges {
- text-align: center;
-}
-div#validator-badges img { border: 0; }
-
-div#copyright {
- color: #333;
- background: #efefef;
- font: 0.75em sans-serif;
- margin-top: 5em;
- margin-bottom: 0;
- padding: 0.5em 2em;
-}
-
-
-/* === Classes =================================== */
-
-table.header-table {
- color: white;
- font-size: small;
-}
-
-.type-note {
- font-size: small;
- color: #DEDEDE;
-}
-
-.xxsection-bar {
- background: #eee;
- color: #333;
- padding: 3px;
-}
-
-.section-bar {
- color: #333;
- border-bottom: 1px solid #999;
- margin-left: -20px;
-}
-
-
-.section-title {
- background: #79a;
- color: #eee;
- padding: 3px;
- margin-top: 2em;
- margin-left: -30px;
- border: 1px solid #999;
-}
-
-.top-aligned-row { vertical-align: top }
-.bottom-aligned-row { vertical-align: bottom }
-
-/* --- Context section classes ----------------------- */
-
-.context-row { }
-.context-item-name { font-family: monospace; font-weight: bold; color: black; }
-.context-item-value { font-size: small; color: #448; }
-.context-item-desc { color: #333; padding-left: 2em; }
-
-/* --- Method classes -------------------------- */
-.method-detail {
- background: #efefef;
- padding: 0;
- margin-top: 0.5em;
- margin-bottom: 1em;
- border: 1px dotted #ccc;
-}
-.method-heading {
- color: black;
- background: #ccc;
- border-bottom: 1px solid #666;
- padding: 0.2em 0.5em 0 0.5em;
-}
-.method-signature { color: black; background: inherit; }
-.method-name { font-weight: bold; }
-.method-args { font-style: italic; }
-.method-description { padding: 0 0.5em 0 0.5em; }
-
-/* --- Source code sections -------------------- */
-
-a.source-toggle { font-size: 90%; }
-div.method-source-code {
- background: #262626;
- color: #ffdead;
- margin: 1em;
- padding: 0.5em;
- border: 1px dashed #999;
- overflow: hidden;
-}
-
-div.method-source-code pre { color: #ffdead; overflow: hidden; }
-
-/* --- Ruby keyword styles --------------------- */
-
-.standalone-code { background: #221111; color: #ffdead; overflow: hidden; }
-
-.ruby-constant { color: #7fffd4; background: transparent; }
-.ruby-keyword { color: #00ffff; background: transparent; }
-.ruby-ivar { color: #eedd82; background: transparent; }
-.ruby-operator { color: #00ffee; background: transparent; }
-.ruby-identifier { color: #ffdead; background: transparent; }
-.ruby-node { color: #ffa07a; background: transparent; }
-.ruby-comment { color: #b22222; font-weight: bold; background: transparent; }
-.ruby-regexp { color: #ffa07a; background: transparent; }
-.ruby-value { color: #7fffd4; background: transparent; }
- RDOC_CSS
-
- RDOC_NO_DOCUMENTATION = <<-'NO_DOC'
-<?xml version="1.0" encoding="iso-8859-1"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>Found documentation</title>
- <link rel="stylesheet" href="gem-server-rdoc-style.css" type="text/css" media="screen" />
- </head>
- <body>
- <div id="fileHeader">
-<%= SEARCH %>
- <h1>No documentation found</h1>
- </div>
-
- <div id="bodyContent">
- <div id="contextContent">
- <div id="description">
- <p>No gems matched <%= h query.inspect %></p>
-
- <p>
- Back to <a href="/">complete gem index</a>
- </p>
-
- </div>
- </div>
- </div>
- <div id="validator-badges">
- <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
- </div>
- </body>
-</html>
- NO_DOC
-
- RDOC_SEARCH_TEMPLATE = <<-'RDOC_SEARCH'
-<?xml version="1.0" encoding="iso-8859-1"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>Found documentation</title>
- <link rel="stylesheet" href="gem-server-rdoc-style.css" type="text/css" media="screen" />
- </head>
- <body>
- <div id="fileHeader">
-<%= SEARCH %>
- <h1>Found documentation</h1>
- </div>
- <!-- banner header -->
-
- <div id="bodyContent">
- <div id="contextContent">
- <div id="description">
- <h1>Summary</h1>
- <p><%=doc_items.length%> documentation topics found.</p>
- <h1>Topics</h1>
-
- <dl>
- <% doc_items.each do |doc_item| %>
- <dt>
- <b><%=doc_item[:name]%></b>
- <a href="<%=doc_item[:url]%>">[rdoc]</a>
- </dt>
- <dd>
- <%=doc_item[:summary]%>
- <br/>
- <br/>
- </dd>
- <% end %>
- </dl>
-
- <p>
- Back to <a href="/">complete gem index</a>
- </p>
-
- </div>
- </div>
- </div>
- <div id="validator-badges">
- <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
- </div>
- </body>
-</html>
- RDOC_SEARCH
-
- def self.run(options)
- new(options[:gemdir], options[:port], options[:daemon],
- options[:launch], options[:addresses]).run
- end
-
- def initialize(gem_dirs, port, daemon, launch = nil, addresses = nil)
- Gem::RDoc.load_rdoc
- Socket.do_not_reverse_lookup = true
-
- @gem_dirs = Array gem_dirs
- @port = port
- @daemon = daemon
- @launch = launch
- @addresses = addresses
-
- logger = WEBrick::Log.new nil, WEBrick::BasicLog::FATAL
- @server = WEBrick::HTTPServer.new :DoNotListen => true, :Logger => logger
-
- @spec_dirs = @gem_dirs.map { |gem_dir| File.join gem_dir, 'specifications' }
- @spec_dirs.reject! { |spec_dir| !File.directory? spec_dir }
-
- reset_gems
-
- @have_rdoc_4_plus = nil
- end
-
- def add_date res
- res['date'] = @spec_dirs.map do |spec_dir|
- File.stat(spec_dir).mtime
- end.max
- end
-
- def doc_root gem_name
- if have_rdoc_4_plus? then
- "/doc_root/#{gem_name}/"
- else
- "/doc_root/#{gem_name}/rdoc/index.html"
- end
- end
-
- def have_rdoc_4_plus?
- @have_rdoc_4_plus ||=
- Gem::Requirement.new('>= 4.0.0.preview2').satisfied_by? Gem::RDoc.rdoc_version
- end
-
- def latest_specs(req, res)
- reset_gems
-
- res['content-type'] = 'application/x-gzip'
-
- add_date res
-
- latest_specs = Gem::Specification.latest_specs
-
- specs = latest_specs.sort.map do |spec|
- platform = spec.original_platform || Gem::Platform::RUBY
- [spec.name, spec.version, platform]
- end
-
- specs = Marshal.dump specs
-
- if req.path =~ /\.gz$/ then
- specs = Gem.gzip specs
- res['content-type'] = 'application/x-gzip'
- else
- res['content-type'] = 'application/octet-stream'
- end
-
- if req.request_method == 'HEAD' then
- res['content-length'] = specs.length
- else
- res.body << specs
- end
- end
-
- ##
- # Creates server sockets based on the addresses option. If no addresses
- # were given a server socket for all interfaces is created.
-
- def listen addresses = @addresses
- addresses = [nil] unless addresses
-
- listeners = 0
-
- addresses.each do |address|
- begin
- @server.listen address, @port
- @server.listeners[listeners..-1].each do |listener|
- host, port = listener.addr.values_at 2, 1
- host = "[#{host}]" if host =~ /:/ # we don't reverse lookup
- say "Server started at http://#{host}:#{port}"
- end
-
- listeners = @server.listeners.length
- rescue SystemCallError
- next
- end
- end
-
- if @server.listeners.empty? then
- say "Unable to start a server."
- say "Check for running servers or your --bind and --port arguments"
- terminate_interaction 1
- end
- end
-
- def prerelease_specs req, res
- reset_gems
-
- res['content-type'] = 'application/x-gzip'
-
- add_date res
-
- specs = Gem::Specification.select do |spec|
- spec.version.prerelease?
- end.sort.map do |spec|
- platform = spec.original_platform || Gem::Platform::RUBY
- [spec.name, spec.version, platform]
- end
-
- specs = Marshal.dump specs
-
- if req.path =~ /\.gz$/ then
- specs = Gem.gzip specs
- res['content-type'] = 'application/x-gzip'
- else
- res['content-type'] = 'application/octet-stream'
- end
-
- if req.request_method == 'HEAD' then
- res['content-length'] = specs.length
- else
- res.body << specs
- end
- end
-
- def quick(req, res)
- reset_gems
-
- res['content-type'] = 'text/plain'
- add_date res
-
- case req.request_uri.path
- when %r|^/quick/(Marshal.#{Regexp.escape Gem.marshal_version}/)?(.*?)-([0-9.]+[^-]*?)(-.*?)?\.gemspec\.rz$| then
- marshal_format, name, version, platform = $1, $2, $3, $4
- specs = Gem::Specification.find_all_by_name name, version
-
- selector = [name, version, platform].map(&:inspect).join ' '
-
- platform = if platform then
- Gem::Platform.new platform.sub(/^-/, '')
- else
- Gem::Platform::RUBY
- end
-
- specs = specs.select { |s| s.platform == platform }
-
- if specs.empty? then
- res.status = 404
- res.body = "No gems found matching #{selector}"
- elsif specs.length > 1 then
- res.status = 500
- res.body = "Multiple gems found matching #{selector}"
- elsif marshal_format then
- res['content-type'] = 'application/x-deflate'
- res.body << Gem.deflate(Marshal.dump(specs.first))
- end
- else
- raise WEBrick::HTTPStatus::NotFound, "`#{req.path}' not found."
- end
- end
-
- def root(req, res)
- reset_gems
-
- add_date res
-
- raise WEBrick::HTTPStatus::NotFound, "`#{req.path}' not found." unless
- req.path == '/'
-
- specs = []
- total_file_count = 0
-
- Gem::Specification.each do |spec|
- total_file_count += spec.files.size
- deps = spec.dependencies.map { |dep|
- {
- "name" => dep.name,
- "type" => dep.type,
- "version" => dep.requirement.to_s,
- }
- }
-
- deps = deps.sort_by { |dep| [dep["name"].downcase, dep["version"]] }
- deps.last["is_last"] = true unless deps.empty?
-
- # executables
- executables = spec.executables.sort.collect { |exec| {"executable" => exec} }
- executables = nil if executables.empty?
- executables.last["is_last"] = true if executables
-
- specs << {
- "authors" => spec.authors.sort.join(", "),
- "date" => spec.date.to_s,
- "dependencies" => deps,
- "doc_path" => doc_root(spec.full_name),
- "executables" => executables,
- "only_one_executable" => (executables && executables.size == 1),
- "full_name" => spec.full_name,
- "has_deps" => !deps.empty?,
- "homepage" => spec.homepage,
- "name" => spec.name,
- "rdoc_installed" => Gem::RDoc.new(spec).rdoc_installed?,
- "ri_installed" => Gem::RDoc.new(spec).ri_installed?,
- "summary" => spec.summary,
- "version" => spec.version.to_s,
- }
- end
-
- specs << {
- "authors" => "Chad Fowler, Rich Kilmer, Jim Weirich, Eric Hodel and others",
- "dependencies" => [],
- "doc_path" => doc_root("rubygems-#{Gem::VERSION}"),
- "executables" => [{"executable" => 'gem', "is_last" => true}],
- "only_one_executable" => true,
- "full_name" => "rubygems-#{Gem::VERSION}",
- "has_deps" => false,
- "homepage" => "http://docs.rubygems.org/",
- "name" => 'rubygems',
- "ri_installed" => true,
- "summary" => "RubyGems itself",
- "version" => Gem::VERSION,
- }
-
- specs = specs.sort_by { |spec| [spec["name"].downcase, spec["version"]] }
- specs.last["is_last"] = true
-
- # tag all specs with first_name_entry
- last_spec = nil
- specs.each do |spec|
- is_first = last_spec.nil? || (last_spec["name"].downcase != spec["name"].downcase)
- spec["first_name_entry"] = is_first
- last_spec = spec
- end
-
- # create page from template
- template = ERB.new(DOC_TEMPLATE)
- res['content-type'] = 'text/html'
-
- values = { "gem_count" => specs.size.to_s, "specs" => specs,
- "total_file_count" => total_file_count.to_s }
-
- # suppress 1.9.3dev warning about unused variable
- values = values
-
- result = template.result binding
- res.body = result
- end
-
- ##
- # Can be used for quick navigation to the rdoc documentation. You can then
- # define a search shortcut for your browser. E.g. in Firefox connect
- # 'shortcut:rdoc' to http://localhost:8808/rdoc?q=%s template. Then you can
- # directly open the ActionPack documentation by typing 'rdoc actionp'. If
- # there are multiple hits for the search term, they are presented as a list
- # with links.
- #
- # Search algorithm aims for an intuitive search:
- # 1. first try to find the gems and documentation folders which name
- # starts with the search term
- # 2. search for entries, that *contain* the search term
- # 3. show all the gems
- #
- # If there is only one search hit, user is immediately redirected to the
- # documentation for the particular gem, otherwise a list with results is
- # shown.
- #
- # === Additional trick - install documentation for Ruby core
- #
- # Note: please adjust paths accordingly use for example 'locate yaml.rb' and
- # 'gem environment' to identify directories, that are specific for your
- # local installation
- #
- # 1. install Ruby sources
- # cd /usr/src
- # sudo apt-get source ruby
- #
- # 2. generate documentation
- # rdoc -o /usr/lib/ruby/gems/1.8/doc/core/rdoc \
- # /usr/lib/ruby/1.8 ruby1.8-1.8.7.72
- #
- # By typing 'rdoc core' you can now access the core documentation
-
- def rdoc(req, res)
- query = req.query['q']
- show_rdoc_for_pattern("#{query}*", res) && return
- show_rdoc_for_pattern("*#{query}*", res) && return
-
- template = ERB.new RDOC_NO_DOCUMENTATION
-
- res['content-type'] = 'text/html'
- res.body = template.result binding
- end
-
- ##
- # Updates the server to use the latest installed gems.
-
- def reset_gems # :nodoc:
- Gem::Specification.dirs = @gem_dirs
- end
-
- ##
- # Returns true and prepares http response, if rdoc for the requested gem
- # name pattern was found.
- #
- # The search is based on the file system content, not on the gems metadata.
- # This allows additional documentation folders like 'core' for the Ruby core
- # documentation - just put it underneath the main doc folder.
-
- def show_rdoc_for_pattern(pattern, res)
- found_gems = Dir.glob("{#{@gem_dirs.join ','}}/doc/#{pattern}").select {|path|
- File.exist? File.join(path, 'rdoc/index.html')
- }
- case found_gems.length
- when 0
- return false
- when 1
- new_path = File.basename(found_gems[0])
- res.status = 302
- res['Location'] = doc_root new_path
- return true
- else
- doc_items = []
- found_gems.each do |file_name|
- base_name = File.basename(file_name)
- doc_items << {
- :name => base_name,
- :url => doc_root(new_path),
- :summary => ''
- }
- end
-
- template = ERB.new(RDOC_SEARCH_TEMPLATE)
- res['content-type'] = 'text/html'
- result = template.result binding
- res.body = result
- return true
- end
- end
-
- def run
- listen
-
- WEBrick::Daemon.start if @daemon
-
- @server.mount_proc "/specs.#{Gem.marshal_version}", method(:specs)
- @server.mount_proc "/specs.#{Gem.marshal_version}.gz", method(:specs)
-
- @server.mount_proc "/latest_specs.#{Gem.marshal_version}",
- method(:latest_specs)
- @server.mount_proc "/latest_specs.#{Gem.marshal_version}.gz",
- method(:latest_specs)
-
- @server.mount_proc "/prerelease_specs.#{Gem.marshal_version}",
- method(:prerelease_specs)
- @server.mount_proc "/prerelease_specs.#{Gem.marshal_version}.gz",
- method(:prerelease_specs)
-
- @server.mount_proc "/quick/", method(:quick)
-
- @server.mount_proc("/gem-server-rdoc-style.css") do |req, res|
- res['content-type'] = 'text/css'
- add_date res
- res.body << RDOC_CSS
- end
-
- @server.mount_proc "/", method(:root)
-
- @server.mount_proc "/rdoc", method(:rdoc)
-
- file_handlers = {
- '/gems' => '/cache/',
- }
-
- if have_rdoc_4_plus? then
- @server.mount '/doc_root', RDoc::Servlet, '/doc_root'
- else
- file_handlers['/doc_root'] = '/doc/'
- end
-
- @gem_dirs.each do |gem_dir|
- file_handlers.each do |mount_point, mount_dir|
- @server.mount(mount_point, WEBrick::HTTPServlet::FileHandler,
- File.join(gem_dir, mount_dir), true)
- end
- end
-
- trap("INT") { @server.shutdown; exit! }
- trap("TERM") { @server.shutdown; exit! }
-
- launch if @launch
-
- @server.start
- end
-
- def specs(req, res)
- reset_gems
-
- add_date res
-
- specs = Gem::Specification.sort_by(&:sort_obj).map do |spec|
- platform = spec.original_platform || Gem::Platform::RUBY
- [spec.name, spec.version, platform]
- end
-
- specs = Marshal.dump specs
-
- if req.path =~ /\.gz$/ then
- specs = Gem.gzip specs
- res['content-type'] = 'application/x-gzip'
- else
- res['content-type'] = 'application/octet-stream'
- end
-
- if req.request_method == 'HEAD' then
- res['content-length'] = specs.length
- else
- res.body << specs
- end
- end
-
- def launch
- listeners = @server.listeners.map{|l| l.addr[2] }
-
- # TODO: 0.0.0.0 == any, not localhost.
- host = listeners.any?{|l| l == '0.0.0.0'} ? 'localhost' : listeners.first
-
- say "Launching browser to http://#{host}:#{@port}"
-
- system("#{@launch} http://#{host}:#{@port}")
- end
-end
diff --git a/ruby_2_2/lib/rubygems/source.rb b/ruby_2_2/lib/rubygems/source.rb
deleted file mode 100644
index e5995f005f..0000000000
--- a/ruby_2_2/lib/rubygems/source.rb
+++ /dev/null
@@ -1,234 +0,0 @@
-require 'uri'
-require 'fileutils'
-
-##
-# A Source knows how to list and fetch gems from a RubyGems marshal index.
-#
-# There are other Source subclasses for installed gems, local gems, the
-# bundler dependency API and so-forth.
-
-class Gem::Source
-
- include Comparable
-
- FILES = { # :nodoc:
- :released => 'specs',
- :latest => 'latest_specs',
- :prerelease => 'prerelease_specs',
- }
-
- ##
- # The URI this source will fetch gems from.
-
- attr_reader :uri
-
- ##
- # Creates a new Source which will use the index located at +uri+.
-
- def initialize(uri)
- begin
- unless uri.kind_of? URI
- uri = URI.parse(uri.to_s)
- end
- rescue URI::InvalidURIError
- raise if Gem::Source == self.class
- end
-
- @uri = uri
- @api_uri = nil
- end
-
- ##
- # Use an SRV record on the host to look up the true endpoint for the index.
-
- def api_uri # :nodoc:
- require 'rubygems/remote_fetcher'
- @api_uri ||= Gem::RemoteFetcher.fetcher.api_endpoint uri
- end
-
- ##
- # Sources are ordered by installation preference.
-
- def <=>(other)
- case other
- when Gem::Source::Installed,
- Gem::Source::Local,
- Gem::Source::Lock,
- Gem::Source::SpecificFile,
- Gem::Source::Git,
- Gem::Source::Vendor then
- -1
- when Gem::Source then
- if !@uri
- return 0 unless other.uri
- return 1
- end
-
- return -1 if !other.uri
-
- @uri.to_s <=> other.uri.to_s
- else
- nil
- end
- end
-
- def == other # :nodoc:
- self.class === other and @uri == other.uri
- end
-
- alias_method :eql?, :== # :nodoc:
-
- ##
- # Returns a Set that can fetch specifications from this source.
-
- def dependency_resolver_set # :nodoc:
- return Gem::Resolver::IndexSet.new self if 'file' == api_uri.scheme
-
- bundler_api_uri = api_uri + './api/v1/dependencies'
-
- begin
- fetcher = Gem::RemoteFetcher.fetcher
- response = fetcher.fetch_path bundler_api_uri, nil, true
- rescue Gem::RemoteFetcher::FetchError
- Gem::Resolver::IndexSet.new self
- else
- if response.respond_to? :uri then
- Gem::Resolver::APISet.new response.uri
- else
- Gem::Resolver::APISet.new bundler_api_uri
- end
- end
- end
-
- def hash # :nodoc:
- @uri.hash
- end
-
- ##
- # Returns the local directory to write +uri+ to.
-
- def cache_dir(uri)
- # Correct for windows paths
- escaped_path = uri.path.sub(/^\/([a-z]):\//i, '/\\1-/')
- escaped_path.untaint
-
- File.join Gem.spec_cache_dir, "#{uri.host}%#{uri.port}", File.dirname(escaped_path)
- end
-
- ##
- # Returns true when it is possible and safe to update the cache directory.
-
- def update_cache?
- @update_cache ||=
- begin
- File.stat(Gem.user_home).uid == Process.uid
- rescue Errno::ENOENT
- false
- end
- end
-
- ##
- # Fetches a specification for the given +name_tuple+.
-
- def fetch_spec name_tuple
- fetcher = Gem::RemoteFetcher.fetcher
-
- spec_file_name = name_tuple.spec_name
-
- uri = api_uri + "#{Gem::MARSHAL_SPEC_DIR}#{spec_file_name}"
-
- cache_dir = cache_dir uri
-
- local_spec = File.join cache_dir, spec_file_name
-
- if File.exist? local_spec then
- spec = Gem.read_binary local_spec
- spec = Marshal.load(spec) rescue nil
- return spec if spec
- end
-
- uri.path << '.rz'
-
- spec = fetcher.fetch_path uri
- spec = Gem.inflate spec
-
- if update_cache? then
- FileUtils.mkdir_p cache_dir
-
- open local_spec, 'wb' do |io|
- io.write spec
- end
- end
-
- # TODO: Investigate setting Gem::Specification#loaded_from to a URI
- Marshal.load spec
- end
-
- ##
- # Loads +type+ kind of specs fetching from +@uri+ if the on-disk cache is
- # out of date.
- #
- # +type+ is one of the following:
- #
- # :released => Return the list of all released specs
- # :latest => Return the list of only the highest version of each gem
- # :prerelease => Return the list of all prerelease only specs
- #
-
- def load_specs(type)
- file = FILES[type]
- fetcher = Gem::RemoteFetcher.fetcher
- file_name = "#{file}.#{Gem.marshal_version}"
- spec_path = api_uri + "#{file_name}.gz"
- cache_dir = cache_dir spec_path
- local_file = File.join(cache_dir, file_name)
- retried = false
-
- FileUtils.mkdir_p cache_dir if update_cache?
-
- spec_dump = fetcher.cache_update_path spec_path, local_file, update_cache?
-
- begin
- Gem::NameTuple.from_list Marshal.load(spec_dump)
- rescue ArgumentError
- if update_cache? && !retried
- FileUtils.rm local_file
- retried = true
- retry
- else
- raise Gem::Exception.new("Invalid spec cache file in #{local_file}")
- end
- end
- end
-
- ##
- # Downloads +spec+ and writes it to +dir+. See also
- # Gem::RemoteFetcher#download.
-
- def download(spec, dir=Dir.pwd)
- fetcher = Gem::RemoteFetcher.fetcher
- fetcher.download spec, api_uri.to_s, dir
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[Remote:', ']' do
- q.breakable
- q.text @uri.to_s
-
- if api = api_uri
- q.breakable
- q.text 'API URI: '
- q.text api.to_s
- end
- end
- end
-
-end
-
-require 'rubygems/source/git'
-require 'rubygems/source/installed'
-require 'rubygems/source/specific_file'
-require 'rubygems/source/local'
-require 'rubygems/source/lock'
-require 'rubygems/source/vendor'
-
diff --git a/ruby_2_2/lib/rubygems/source/git.rb b/ruby_2_2/lib/rubygems/source/git.rb
deleted file mode 100644
index 35c2270a74..0000000000
--- a/ruby_2_2/lib/rubygems/source/git.rb
+++ /dev/null
@@ -1,240 +0,0 @@
-require 'digest'
-require 'rubygems/util'
-
-##
-# A git gem for use in a gem dependencies file.
-#
-# Example:
-#
-# source =
-# Gem::Source::Git.new 'rake', 'git@example:rake.git', 'rake-10.1.0', false
-#
-# source.specs
-
-class Gem::Source::Git < Gem::Source
-
- ##
- # The name of the gem created by this git gem.
-
- attr_reader :name
-
- ##
- # The commit reference used for checking out this git gem.
-
- attr_reader :reference
-
- ##
- # When false the cache for this repository will not be updated.
-
- attr_accessor :remote
-
- ##
- # The git repository this gem is sourced from.
-
- attr_reader :repository
-
- ##
- # The directory for cache and git gem installation
-
- attr_accessor :root_dir
-
- ##
- # Does this repository need submodules checked out too?
-
- attr_reader :need_submodules
-
- ##
- # Creates a new git gem source for a gems from loaded from +repository+ at
- # the given +reference+. The +name+ is only used to track the repository
- # back to a gem dependencies file, it has no real significance as a git
- # repository may contain multiple gems. If +submodules+ is true, submodules
- # will be checked out when the gem is installed.
-
- def initialize name, repository, reference, submodules = false
- super repository
-
- @name = name
- @repository = repository
- @reference = reference
- @need_submodules = submodules
-
- @remote = true
- @root_dir = Gem.dir
- @git = ENV['git'] || 'git'
- end
-
- def <=> other
- case other
- when Gem::Source::Git then
- 0
- when Gem::Source::Vendor,
- Gem::Source::Lock then
- -1
- when Gem::Source then
- 1
- else
- nil
- end
- end
-
- def == other # :nodoc:
- super and
- @name == other.name and
- @repository == other.repository and
- @reference == other.reference and
- @need_submodules == other.need_submodules
- end
-
- ##
- # Checks out the files for the repository into the install_dir.
-
- def checkout # :nodoc:
- cache
-
- return false unless File.exist? repo_cache_dir
-
- unless File.exist? install_dir then
- system @git, 'clone', '--quiet', '--no-checkout',
- repo_cache_dir, install_dir
- end
-
- Dir.chdir install_dir do
- system @git, 'fetch', '--quiet', '--force', '--tags', install_dir
-
- success = system @git, 'reset', '--quiet', '--hard', rev_parse
-
- success &&=
- Gem::Util.silent_system @git, 'submodule', 'update',
- '--quiet', '--init', '--recursive' if @need_submodules
-
- success
- end
- end
-
- ##
- # Creates a local cache repository for the git gem.
-
- def cache # :nodoc:
- return unless @remote
-
- if File.exist? repo_cache_dir then
- Dir.chdir repo_cache_dir do
- system @git, 'fetch', '--quiet', '--force', '--tags',
- @repository, 'refs/heads/*:refs/heads/*'
- end
- else
- system @git, 'clone', '--quiet', '--bare', '--no-hardlinks',
- @repository, repo_cache_dir
- end
- end
-
- ##
- # Directory where git gems get unpacked and so-forth.
-
- def base_dir # :nodoc:
- File.join @root_dir, 'bundler'
- end
-
- ##
- # A short reference for use in git gem directories
-
- def dir_shortref # :nodoc:
- rev_parse[0..11]
- end
-
- ##
- # Nothing to download for git gems
-
- def download full_spec, path # :nodoc:
- end
-
- ##
- # The directory where the git gem will be installed.
-
- def install_dir # :nodoc:
- return unless File.exist? repo_cache_dir
-
- File.join base_dir, 'gems', "#{@name}-#{dir_shortref}"
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[Git: ', ']' do
- q.breakable
- q.text @repository
-
- q.breakable
- q.text @reference
- end
- end
-
- ##
- # The directory where the git gem's repository will be cached.
-
- def repo_cache_dir # :nodoc:
- File.join @root_dir, 'cache', 'bundler', 'git', "#{@name}-#{uri_hash}"
- end
-
- ##
- # Converts the git reference for the repository into a commit hash.
-
- def rev_parse # :nodoc:
- hash = nil
-
- Dir.chdir repo_cache_dir do
- hash = Gem::Util.popen(@git, 'rev-parse', @reference).strip
- end
-
- raise Gem::Exception,
- "unable to find reference #{@reference} in #{@repository}" unless
- $?.success?
-
- hash
- end
-
- ##
- # Loads all gemspecs in the repository
-
- def specs
- checkout
-
- return [] unless install_dir
-
- Dir.chdir install_dir do
- Dir['{,*,*/*}.gemspec'].map do |spec_file|
- directory = File.dirname spec_file
- file = File.basename spec_file
-
- Dir.chdir directory do
- spec = Gem::Specification.load file
- if spec then
- spec.base_dir = base_dir
-
- spec.extension_dir =
- File.join base_dir, 'extensions', Gem::Platform.local.to_s,
- Gem.extension_api_version, "#{name}-#{dir_shortref}"
-
- spec.full_gem_path = File.dirname spec.loaded_from if spec
- end
- spec
- end
- end.compact
- end
- end
-
- ##
- # A hash for the git gem based on the git repository URI.
-
- def uri_hash # :nodoc:
- normalized =
- if @repository =~ %r%^\w+://(\w+@)?% then
- uri = URI(@repository).normalize.to_s.sub %r%/$%,''
- uri.sub(/\A(\w+)/) { $1.downcase }
- else
- @repository
- end
-
- Digest::SHA1.hexdigest normalized
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/source/installed.rb b/ruby_2_2/lib/rubygems/source/installed.rb
deleted file mode 100644
index bd05c75af1..0000000000
--- a/ruby_2_2/lib/rubygems/source/installed.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-##
-# Represents an installed gem. This is used for dependency resolution.
-
-class Gem::Source::Installed < Gem::Source
-
- def initialize # :nodoc:
- @uri = nil
- end
-
- ##
- # Installed sources sort before all other sources
-
- def <=> other
- case other
- when Gem::Source::Git,
- Gem::Source::Lock,
- Gem::Source::Vendor then
- -1
- when Gem::Source::Installed then
- 0
- when Gem::Source then
- 1
- else
- nil
- end
- end
-
- ##
- # We don't need to download an installed gem
-
- def download spec, path
- nil
- end
-
- def pretty_print q # :nodoc:
- q.text '[Installed]'
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/source/local.rb b/ruby_2_2/lib/rubygems/source/local.rb
deleted file mode 100644
index 8057921163..0000000000
--- a/ruby_2_2/lib/rubygems/source/local.rb
+++ /dev/null
@@ -1,129 +0,0 @@
-##
-# The local source finds gems in the current directory for fulfilling
-# dependencies.
-
-class Gem::Source::Local < Gem::Source
-
- def initialize # :nodoc:
- @specs = nil
- @api_uri = nil
- @uri = nil
- end
-
- ##
- # Local sorts before Gem::Source and after Gem::Source::Installed
-
- def <=> other
- case other
- when Gem::Source::Installed,
- Gem::Source::Lock then
- -1
- when Gem::Source::Local then
- 0
- when Gem::Source then
- 1
- else
- nil
- end
- end
-
- def inspect # :nodoc:
- keys = @specs ? @specs.keys.sort : 'NOT LOADED'
- "#<%s specs: %p>" % [self.class, keys]
- end
-
- def load_specs type # :nodoc:
- names = []
-
- @specs = {}
-
- Dir["*.gem"].each do |file|
- begin
- pkg = Gem::Package.new(file)
- rescue SystemCallError, Gem::Package::FormatError
- # ignore
- else
- tup = pkg.spec.name_tuple
- @specs[tup] = [File.expand_path(file), pkg]
-
- case type
- when :released
- unless pkg.spec.version.prerelease?
- names << pkg.spec.name_tuple
- end
- when :prerelease
- if pkg.spec.version.prerelease?
- names << pkg.spec.name_tuple
- end
- when :latest
- tup = pkg.spec.name_tuple
-
- cur = names.find { |x| x.name == tup.name }
- if !cur
- names << tup
- elsif cur.version < tup.version
- names.delete cur
- names << tup
- end
- else
- names << pkg.spec.name_tuple
- end
- end
- end
-
- names
- end
-
- def find_gem gem_name, version = Gem::Requirement.default, # :nodoc:
- prerelease = false
- load_specs :complete
-
- found = []
-
- @specs.each do |n, data|
- if n.name == gem_name
- s = data[1].spec
-
- if version.satisfied_by?(s.version)
- if prerelease
- found << s
- elsif !s.version.prerelease?
- found << s
- end
- end
- end
- end
-
- found.max_by { |s| s.version }
- end
-
- def fetch_spec name # :nodoc:
- load_specs :complete
-
- if data = @specs[name]
- data.last.spec
- else
- raise Gem::Exception, "Unable to find spec for #{name.inspect}"
- end
- end
-
- def download spec, cache_dir = nil # :nodoc:
- load_specs :complete
-
- @specs.each do |name, data|
- return data[0] if data[1].spec == spec
- end
-
- raise Gem::Exception, "Unable to find file for '#{spec.full_name}'"
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[Local gems:', ']' do
- q.breakable
- q.seplist @specs.keys do |v|
- q.text v.full_name
- end
- end
- end
-
-end
diff --git a/ruby_2_2/lib/rubygems/source/lock.rb b/ruby_2_2/lib/rubygems/source/lock.rb
deleted file mode 100644
index 2ba7702bda..0000000000
--- a/ruby_2_2/lib/rubygems/source/lock.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-##
-# A Lock source wraps an installed gem's source and sorts before other sources
-# during dependency resolution. This allows RubyGems to prefer gems from
-# dependency lock files.
-
-class Gem::Source::Lock < Gem::Source
-
- ##
- # The wrapped Gem::Source
-
- attr_reader :wrapped
-
- ##
- # Creates a new Lock source that wraps +source+ and moves it earlier in the
- # sort list.
-
- def initialize source
- @wrapped = source
- end
-
- def <=> other # :nodoc:
- case other
- when Gem::Source::Lock then
- @wrapped <=> other.wrapped
- when Gem::Source then
- 1
- else
- nil
- end
- end
-
- def == other # :nodoc:
- 0 == (self <=> other)
- end
-
- ##
- # Delegates to the wrapped source's fetch_spec method.
-
- def fetch_spec name_tuple
- @wrapped.fetch_spec name_tuple
- end
-
- def uri # :nodoc:
- @wrapped.uri
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/source/specific_file.rb b/ruby_2_2/lib/rubygems/source/specific_file.rb
deleted file mode 100644
index 250a839203..0000000000
--- a/ruby_2_2/lib/rubygems/source/specific_file.rb
+++ /dev/null
@@ -1,72 +0,0 @@
-##
-# A source representing a single .gem file. This is used for installation of
-# local gems.
-
-class Gem::Source::SpecificFile < Gem::Source
-
- ##
- # The path to the gem for this specific file.
-
- attr_reader :path
-
- ##
- # Creates a new SpecificFile for the gem in +file+
-
- def initialize(file)
- @uri = nil
- @path = ::File.expand_path(file)
-
- @package = Gem::Package.new @path
- @spec = @package.spec
- @name = @spec.name_tuple
- end
-
- ##
- # The Gem::Specification extracted from this .gem.
-
- attr_reader :spec
-
- def load_specs *a # :nodoc:
- [@name]
- end
-
- def fetch_spec name # :nodoc:
- return @spec if name == @name
- raise Gem::Exception, "Unable to find '#{name}'"
- @spec
- end
-
- def download spec, dir = nil # :nodoc:
- return @path if spec == @spec
- raise Gem::Exception, "Unable to download '#{spec.full_name}'"
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[SpecificFile:', ']' do
- q.breakable
- q.text @path
- end
- end
-
- ##
- # Orders this source against +other+.
- #
- # If +other+ is a SpecificFile from a different gem name +nil+ is returned.
- #
- # If +other+ is a SpecificFile from the same gem name the versions are
- # compared using Gem::Version#<=>
- #
- # Otherwise Gem::Source#<=> is used.
-
- def <=> other
- case other
- when Gem::Source::SpecificFile then
- return nil if @spec.name != other.spec.name
-
- @spec.version <=> other.spec.version
- else
- super
- end
- end
-
-end
diff --git a/ruby_2_2/lib/rubygems/source/vendor.rb b/ruby_2_2/lib/rubygems/source/vendor.rb
deleted file mode 100644
index 2d936231c1..0000000000
--- a/ruby_2_2/lib/rubygems/source/vendor.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-##
-# This represents a vendored source that is similar to an installed gem.
-
-class Gem::Source::Vendor < Gem::Source::Installed
-
- ##
- # Creates a new Vendor source for a gem that was unpacked at +path+.
-
- def initialize path
- @uri = path
- end
-
- def <=> other
- case other
- when Gem::Source::Lock then
- -1
- when Gem::Source::Vendor then
- 0
- when Gem::Source then
- 1
- else
- nil
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/source_list.rb b/ruby_2_2/lib/rubygems/source_list.rb
deleted file mode 100644
index e01f11cc1e..0000000000
--- a/ruby_2_2/lib/rubygems/source_list.rb
+++ /dev/null
@@ -1,149 +0,0 @@
-require 'rubygems/source'
-
-##
-# The SourceList represents the sources rubygems has been configured to use.
-# A source may be created from an array of sources:
-#
-# Gem::SourceList.from %w[https://rubygems.example https://internal.example]
-#
-# Or by adding them:
-#
-# sources = Gem::SourceList.new
-# sources.add 'https://rubygems.example'
-#
-# The most common way to get a SourceList is Gem.sources.
-
-class Gem::SourceList
-
- include Enumerable
-
- ##
- # Creates a new SourceList
-
- def initialize
- @sources = []
- end
-
- ##
- # The sources in this list
-
- attr_reader :sources
-
- ##
- # Creates a new SourceList from an array of sources.
-
- def self.from(ary)
- list = new
-
- list.replace ary
-
- return list
- end
-
- def initialize_copy(other) # :nodoc:
- @sources = @sources.dup
- end
-
- ##
- # Appends +obj+ to the source list which may be a Gem::Source, URI or URI
- # String.
-
- def <<(obj)
- src = case obj
- when URI
- Gem::Source.new(obj)
- when Gem::Source
- obj
- else
- Gem::Source.new(URI.parse(obj))
- end
-
- @sources << src
- src
- end
-
- ##
- # Replaces this SourceList with the sources in +other+ See #<< for
- # acceptable items in +other+.
-
- def replace(other)
- clear
-
- other.each do |x|
- self << x
- end
-
- self
- end
-
- ##
- # Removes all sources from the SourceList.
-
- def clear
- @sources.clear
- end
-
- ##
- # Yields each source URI in the list.
-
- def each
- @sources.each { |s| yield s.uri.to_s }
- end
-
- ##
- # Yields each source in the list.
-
- def each_source(&b)
- @sources.each(&b)
- end
-
- ##
- # Returns true if there are no sources in this SourceList.
-
- def empty?
- @sources.empty?
- end
-
- def == other # :nodoc:
- to_a == other
- end
-
- ##
- # Returns an Array of source URI Strings.
-
- def to_a
- @sources.map { |x| x.uri.to_s }
- end
-
- alias_method :to_ary, :to_a
-
- ##
- # Returns the first source in the list.
-
- def first
- @sources.first
- end
-
- ##
- # Returns true if this source list includes +other+ which may be a
- # Gem::Source or a source URI.
-
- def include?(other)
- if other.kind_of? Gem::Source
- @sources.include? other
- else
- @sources.find { |x| x.uri.to_s == other.to_s }
- end
- end
-
- ##
- # Deletes +source+ from the source list which may be a Gem::Source or a URI.
-
- def delete source
- if source.kind_of? Gem::Source
- @sources.delete source
- else
- @sources.delete_if { |x| x.uri.to_s == source.to_s }
- end
- end
-end
diff --git a/ruby_2_2/lib/rubygems/source_local.rb b/ruby_2_2/lib/rubygems/source_local.rb
deleted file mode 100644
index 0808f4694a..0000000000
--- a/ruby_2_2/lib/rubygems/source_local.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require 'rubygems/source'
-require 'rubygems/source_local'
-
-# TODO warn upon require, this file is deprecated.
-
diff --git a/ruby_2_2/lib/rubygems/source_specific_file.rb b/ruby_2_2/lib/rubygems/source_specific_file.rb
deleted file mode 100644
index f785c2667c..0000000000
--- a/ruby_2_2/lib/rubygems/source_specific_file.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'rubygems/source/specific_file'
-
-# TODO warn upon require, this file is deprecated.
-
diff --git a/ruby_2_2/lib/rubygems/spec_fetcher.rb b/ruby_2_2/lib/rubygems/spec_fetcher.rb
deleted file mode 100644
index 4967c4a40b..0000000000
--- a/ruby_2_2/lib/rubygems/spec_fetcher.rb
+++ /dev/null
@@ -1,269 +0,0 @@
-require 'rubygems/remote_fetcher'
-require 'rubygems/user_interaction'
-require 'rubygems/errors'
-require 'rubygems/text'
-require 'rubygems/name_tuple'
-
-##
-# SpecFetcher handles metadata updates from remote gem repositories.
-
-class Gem::SpecFetcher
-
- include Gem::UserInteraction
- include Gem::Text
-
- ##
- # Cache of latest specs
-
- attr_reader :latest_specs # :nodoc:
-
- ##
- # Sources for this SpecFetcher
-
- attr_reader :sources # :nodoc:
-
- ##
- # Cache of all released specs
-
- attr_reader :specs # :nodoc:
-
- ##
- # Cache of prerelease specs
-
- attr_reader :prerelease_specs # :nodoc:
-
- @fetcher = nil
-
- ##
- # Default fetcher instance. Use this instead of ::new to reduce object
- # allocation.
-
- def self.fetcher
- @fetcher ||= new
- end
-
- def self.fetcher=(fetcher) # :nodoc:
- @fetcher = fetcher
- end
-
- ##
- # Creates a new SpecFetcher. Ordinarily you want to use the default fetcher
- # from Gem::SpecFetcher::fetcher which uses the Gem.sources.
- #
- # If you need to retrieve specifications from a different +source+, you can
- # send it as an argument.
-
- def initialize sources = nil
- @sources = sources || Gem.sources
-
- @update_cache =
- begin
- File.stat(Gem.user_home).uid == Process.uid
- rescue Errno::EACCES, Errno::ENOENT
- false
- end
-
- @specs = {}
- @latest_specs = {}
- @prerelease_specs = {}
-
- @caches = {
- :latest => @latest_specs,
- :prerelease => @prerelease_specs,
- :released => @specs,
- }
-
- @fetcher = Gem::RemoteFetcher.fetcher
- end
-
- ##
- #
- # Find and fetch gem name tuples that match +dependency+.
- #
- # If +matching_platform+ is false, gems for all platforms are returned.
-
- def search_for_dependency(dependency, matching_platform=true)
- found = {}
-
- rejected_specs = {}
-
- if dependency.prerelease?
- if dependency.specific?
- type = :complete
- else
- type = :abs_latest
- end
- elsif dependency.latest_version?
- type = :latest
- else
- type = :released
- end
-
- list, errors = available_specs(type)
- list.each do |source, specs|
- if dependency.name.is_a?(String) && specs.respond_to?(:bsearch)
- start_index = (0 ... specs.length).bsearch{ |i| specs[i].name >= dependency.name }
- end_index = (0 ... specs.length).bsearch{ |i| specs[i].name > dependency.name }
- specs = specs[start_index ... end_index] if start_index && end_index
- end
-
- found[source] = specs.select do |tup|
- if dependency.match?(tup)
- if matching_platform and !Gem::Platform.match(tup.platform)
- pm = (
- rejected_specs[dependency] ||= \
- Gem::PlatformMismatch.new(tup.name, tup.version))
- pm.add_platform tup.platform
- false
- else
- true
- end
- end
- end
- end
-
- errors += rejected_specs.values
-
- tuples = []
-
- found.each do |source, specs|
- specs.each do |s|
- tuples << [s, source]
- end
- end
-
- tuples = tuples.sort_by { |x| x[0] }
-
- return [tuples, errors]
- end
-
-
- ##
- # Return all gem name tuples who's names match +obj+
-
- def detect(type=:complete)
- tuples = []
-
- list, _ = available_specs(type)
- list.each do |source, specs|
- specs.each do |tup|
- if yield(tup)
- tuples << [tup, source]
- end
- end
- end
-
- tuples
- end
-
-
- ##
- # Find and fetch specs that match +dependency+.
- #
- # If +matching_platform+ is false, gems for all platforms are returned.
-
- def spec_for_dependency(dependency, matching_platform=true)
- tuples, errors = search_for_dependency(dependency, matching_platform)
-
- specs = []
- tuples.each do |tup, source|
- begin
- spec = source.fetch_spec(tup)
- rescue Gem::RemoteFetcher::FetchError => e
- errors << Gem::SourceFetchProblem.new(source, e)
- else
- specs << [spec, source]
- end
- end
-
- return [specs, errors]
- end
-
- ##
- # Suggests gems based on the supplied +gem_name+. Returns an array of
- # alternative gem names.
-
- def suggest_gems_from_name gem_name
- gem_name = gem_name.downcase.tr('_-', '')
- max = gem_name.size / 2
- names = available_specs(:latest).first.values.flatten(1)
-
- matches = names.map { |n|
- next unless n.match_platform?
-
- distance = levenshtein_distance gem_name, n.name.downcase.tr('_-', '')
-
- next if distance >= max
-
- return [n.name] if distance == 0
-
- [n.name, distance]
- }.compact
-
- matches = matches.uniq.sort_by { |name, dist| dist }
-
- matches.first(5).map { |name, dist| name }
- end
-
- ##
- # Returns a list of gems available for each source in Gem::sources.
- #
- # +type+ can be one of 3 values:
- # :released => Return the list of all released specs
- # :complete => Return the list of all specs
- # :latest => Return the list of only the highest version of each gem
- # :prerelease => Return the list of all prerelease only specs
- #
-
- def available_specs(type)
- errors = []
- list = {}
-
- @sources.each_source do |source|
- begin
- names = case type
- when :latest
- tuples_for source, :latest
- when :released
- tuples_for source, :released
- when :complete
- names =
- tuples_for(source, :prerelease, true) +
- tuples_for(source, :released)
-
- names.sort
- when :abs_latest
- names =
- tuples_for(source, :prerelease, true) +
- tuples_for(source, :latest)
-
- names.sort
- when :prerelease
- tuples_for(source, :prerelease)
- else
- raise Gem::Exception, "Unknown type - :#{type}"
- end
- rescue Gem::RemoteFetcher::FetchError => e
- errors << Gem::SourceFetchProblem.new(source, e)
- else
- list[source] = names
- end
- end
-
- [list, errors]
- end
-
- ##
- # Retrieves NameTuples from +source+ of the given +type+ (:prerelease,
- # etc.). If +gracefully_ignore+ is true, errors are ignored.
-
- def tuples_for(source, type, gracefully_ignore=false) # :nodoc:
- @caches[type][source.uri] ||=
- source.load_specs(type).sort_by { |tup| tup.name }
- rescue Gem::RemoteFetcher::FetchError
- raise unless gracefully_ignore
- []
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/specification.rb b/ruby_2_2/lib/rubygems/specification.rb
deleted file mode 100644
index 6d46621823..0000000000
--- a/ruby_2_2/lib/rubygems/specification.rb
+++ /dev/null
@@ -1,2808 +0,0 @@
-# -*- coding: utf-8 -*-
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-
-require 'rubygems/version'
-require 'rubygems/requirement'
-require 'rubygems/platform'
-require 'rubygems/deprecate'
-require 'rubygems/basic_specification'
-require 'rubygems/stub_specification'
-require 'rubygems/util/stringio'
-
-##
-# The Specification class contains the information for a Gem. Typically
-# defined in a .gemspec file or a Rakefile, and looks like this:
-#
-# Gem::Specification.new do |s|
-# s.name = 'example'
-# s.version = '0.1.0'
-# s.licenses = ['MIT']
-# s.summary = "This is an example!"
-# s.description = "Much longer explanation of the example!"
-# s.authors = ["Ruby Coder"]
-# s.email = 'rubycoder@example.com'
-# s.files = ["lib/example.rb"]
-# s.homepage = 'https://rubygems.org/gems/example'
-# end
-#
-# Starting in RubyGems 2.0, a Specification can hold arbitrary
-# metadata. See #metadata for restrictions on the format and size of metadata
-# items you may add to a specification.
-
-class Gem::Specification < Gem::BasicSpecification
-
- # REFACTOR: Consider breaking out this version stuff into a separate
- # module. There's enough special stuff around it that it may justify
- # a separate class.
-
- ##
- # The version number of a specification that does not specify one
- # (i.e. RubyGems 0.7 or earlier).
-
- NONEXISTENT_SPECIFICATION_VERSION = -1
-
- ##
- # The specification version applied to any new Specification instances
- # created. This should be bumped whenever something in the spec format
- # changes.
- #
- # Specification Version History:
- #
- # spec ruby
- # ver ver yyyy-mm-dd description
- # -1 <0.8.0 pre-spec-version-history
- # 1 0.8.0 2004-08-01 Deprecated "test_suite_file" for "test_files"
- # "test_file=x" is a shortcut for "test_files=[x]"
- # 2 0.9.5 2007-10-01 Added "required_rubygems_version"
- # Now forward-compatible with future versions
- # 3 1.3.2 2009-01-03 Added Fixnum validation to specification_version
- # 4 1.9.0 2011-06-07 Added metadata
- #--
- # When updating this number, be sure to also update #to_ruby.
- #
- # NOTE RubyGems < 1.2 cannot load specification versions > 2.
-
- CURRENT_SPECIFICATION_VERSION = 4 # :nodoc:
-
- ##
- # An informal list of changes to the specification. The highest-valued
- # key should be equal to the CURRENT_SPECIFICATION_VERSION.
-
- SPECIFICATION_VERSION_HISTORY = { # :nodoc:
- -1 => ['(RubyGems versions up to and including 0.7 did not have versioned specifications)'],
- 1 => [
- 'Deprecated "test_suite_file" in favor of the new, but equivalent, "test_files"',
- '"test_file=x" is a shortcut for "test_files=[x]"'
- ],
- 2 => [
- 'Added "required_rubygems_version"',
- 'Now forward-compatible with future versions',
- ],
- 3 => [
- 'Added Fixnum validation to the specification_version'
- ],
- 4 => [
- 'Added sandboxed freeform metadata to the specification version.'
- ]
- }
-
- MARSHAL_FIELDS = { # :nodoc:
- -1 => 16,
- 1 => 16,
- 2 => 16,
- 3 => 17,
- 4 => 18,
- }
-
- today = Time.now.utc
- TODAY = Time.utc(today.year, today.month, today.day) # :nodoc:
-
- LOAD_CACHE = {} # :nodoc:
-
- private_constant :LOAD_CACHE if defined? private_constant
-
- VALID_NAME_PATTERN = /\A[a-zA-Z0-9\.\-\_]+\z/ # :nodoc:
-
- # :startdoc:
-
- ##
- # List of attribute names: [:name, :version, ...]
-
- @@required_attributes = [:rubygems_version,
- :specification_version,
- :name,
- :version,
- :date,
- :summary,
- :require_paths]
-
- ##
- # Map of attribute names to default values.
-
- @@default_value = {
- :authors => [],
- :autorequire => nil,
- :bindir => 'bin',
- :cert_chain => [],
- :date => TODAY,
- :dependencies => [],
- :description => nil,
- :email => nil,
- :executables => [],
- :extensions => [],
- :extra_rdoc_files => [],
- :files => [],
- :homepage => nil,
- :licenses => [],
- :metadata => {},
- :name => nil,
- :platform => Gem::Platform::RUBY,
- :post_install_message => nil,
- :rdoc_options => [],
- :require_paths => ['lib'],
- :required_ruby_version => Gem::Requirement.default,
- :required_rubygems_version => Gem::Requirement.default,
- :requirements => [],
- :rubyforge_project => nil,
- :rubygems_version => Gem::VERSION,
- :signing_key => nil,
- :specification_version => CURRENT_SPECIFICATION_VERSION,
- :summary => nil,
- :test_files => [],
- :version => nil,
- }
-
- Dupable = { } # :nodoc:
-
- @@default_value.each do |k,v|
- case v
- when Time, Numeric, Symbol, true, false, nil
- Dupable[k] = false
- else
- Dupable[k] = true
- end
- end
-
- @@attributes = @@default_value.keys.sort_by { |s| s.to_s }
- @@array_attributes = @@default_value.reject { |k,v| v != [] }.keys
- @@nil_attributes, @@non_nil_attributes = @@default_value.keys.partition { |k|
- @@default_value[k].nil?
- }
-
- ######################################################################
- # :section: Required gemspec attributes
-
- ##
- # This gem's name.
- #
- # Usage:
- #
- # spec.name = 'rake'
-
- attr_accessor :name
-
- ##
- # This gem's version.
- #
- # The version string can contain numbers and periods, such as +1.0.0+.
- # A gem is a 'prerelease' gem if the version has a letter in it, such as
- # +1.0.0.pre+.
- #
- # Usage:
- #
- # spec.version = '0.4.1'
-
- attr_reader :version
-
- ##
- # Paths in the gem to add to <code>$LOAD_PATH</code> when this gem is
- # activated.
- #
- # See also #require_paths
- #
- # If you have an extension you do not need to add <code>"ext"</code> to the
- # require path, the extension build process will copy the extension files
- # into "lib" for you.
- #
- # The default value is <code>"lib"</code>
- #
- # Usage:
- #
- # # If all library files are in the root directory...
- # spec.require_paths = ['.']
-
- def require_paths=(val)
- @require_paths = Array(val)
- end
-
- ##
- # The version of RubyGems used to create this gem.
- #
- # Do not set this, it is set automatically when the gem is packaged.
-
- attr_accessor :rubygems_version
-
- ##
- # A short summary of this gem's description. Displayed in `gem list -d`.
- #
- # The #description should be more detailed than the summary.
- #
- # Usage:
- #
- # spec.summary = "This is a small summary of my gem"
-
- attr_reader :summary
-
- ##
- # Singular writer for #authors
- #
- # Usage:
- #
- # spec.author = 'John Jones'
-
- def author= o
- self.authors = [o]
- end
-
- ##
- # Sets the list of authors, ensuring it is an array.
- #
- # Usage:
- #
- # spec.authors = ['John Jones', 'Mary Smith']
-
- def authors= value
- @authors = Array(value).flatten.grep(String)
- end
-
- ##
- # The platform this gem runs on.
- #
- # This is usually Gem::Platform::RUBY or Gem::Platform::CURRENT.
- #
- # Most gems contain pure Ruby code; they should simply leave the default
- # value in place. Some gems contain C (or other) code to be compiled into a
- # Ruby "extension". The gem should leave the default value in place unless
- # the code will only compile on a certain type of system. Some gems consist
- # of pre-compiled code ("binary gems"). It's especially important that they
- # set the platform attribute appropriately. A shortcut is to set the
- # platform to Gem::Platform::CURRENT, which will cause the gem builder to set
- # the platform to the appropriate value for the system on which the build is
- # being performed.
- #
- # If this attribute is set to a non-default value, it will be included in
- # the filename of the gem when it is built such as:
- # nokogiri-1.6.0-x86-mingw32.gem
- #
- # Usage:
- #
- # spec.platform = Gem::Platform.local
-
- def platform= platform
- if @original_platform.nil? or
- @original_platform == Gem::Platform::RUBY then
- @original_platform = platform
- end
-
- case platform
- when Gem::Platform::CURRENT then
- @new_platform = Gem::Platform.local
- @original_platform = @new_platform.to_s
-
- when Gem::Platform then
- @new_platform = platform
-
- # legacy constants
- when nil, Gem::Platform::RUBY then
- @new_platform = Gem::Platform::RUBY
- when 'mswin32' then # was Gem::Platform::WIN32
- @new_platform = Gem::Platform.new 'x86-mswin32'
- when 'i586-linux' then # was Gem::Platform::LINUX_586
- @new_platform = Gem::Platform.new 'x86-linux'
- when 'powerpc-darwin' then # was Gem::Platform::DARWIN
- @new_platform = Gem::Platform.new 'ppc-darwin'
- else
- @new_platform = Gem::Platform.new platform
- end
-
- @platform = @new_platform.to_s
-
- invalidate_memoized_attributes
-
- @new_platform
- end
-
- ##
- # Files included in this gem. You cannot append to this accessor, you must
- # assign to it.
- #
- # Only add files you can require to this list, not directories, etc.
- #
- # Directories are automatically stripped from this list when building a gem,
- # other non-files cause an error.
- #
- # Usage:
- #
- # require 'rake'
- # spec.files = FileList['lib/**/*.rb',
- # 'bin/*',
- # '[A-Z]*',
- # 'test/**/*'].to_a
- #
- # # or without Rake...
- # spec.files = Dir['lib/**/*.rb'] + Dir['bin/*']
- # spec.files += Dir['[A-Z]*'] + Dir['test/**/*']
- # spec.files.reject! { |fn| fn.include? "CVS" }
-
- def files
- # DO NOT CHANGE TO ||= ! This is not a normal accessor. (yes, it sucks)
- # DOC: Why isn't it normal? Why does it suck? How can we fix this?
- @files = [@files,
- @test_files,
- add_bindir(@executables),
- @extra_rdoc_files,
- @extensions,
- ].flatten.uniq.compact.sort
- end
-
- ######################################################################
- # :section: Optional gemspec attributes
-
- ##
- # The path in the gem for executable scripts. Usually 'bin'
- #
- # Usage:
- #
- # spec.bindir = 'bin'
-
- attr_accessor :bindir
-
- ##
- # The certificate chain used to sign this gem. See Gem::Security for
- # details.
-
- attr_accessor :cert_chain
-
- ##
- # A long description of this gem
- #
- # The description should be more detailed than the summary but not
- # excessively long. A few paragraphs is a recommended length with no
- # examples or formatting.
- #
- # Usage:
- #
- # spec.description = <<-EOF
- # Rake is a Make-like program implemented in Ruby. Tasks and
- # dependencies are specified in standard Ruby syntax.
- # EOF
-
- attr_reader :description
-
- ##
- # A contact email address (or addresses) for this gem
- #
- # Usage:
- #
- # spec.email = 'john.jones@example.com'
- # spec.email = ['jack@example.com', 'jill@example.com']
-
- attr_accessor :email
-
- ##
- # The URL of this gem's home page
- #
- # Usage:
- #
- # spec.homepage = 'http://rake.rubyforge.org'
-
- attr_accessor :homepage
-
- ##
- # A message that gets displayed after the gem is installed.
- #
- # Usage:
- #
- # spec.post_install_message = "Thanks for installing!"
-
- attr_accessor :post_install_message
-
- ##
- # The version of Ruby required by this gem
-
- attr_reader :required_ruby_version
-
- ##
- # The RubyGems version required by this gem
-
- attr_reader :required_rubygems_version
-
- ##
- # The key used to sign this gem. See Gem::Security for details.
-
- attr_accessor :signing_key
-
- ##
- # :attr_accessor: metadata
- #
- # The metadata holds extra data for this gem that may be useful to other
- # consumers and is settable by gem authors without requiring an update to
- # the rubygems software.
- #
- # Metadata items have the following restrictions:
- #
- # * The metadata must be a Hash object
- # * All keys and values must be Strings
- # * Keys can be a maximum of 128 bytes and values can be a maximum of 1024
- # bytes
- # * All strings must be UTF-8, no binary data is allowed
- #
- # To add metadata for the location of a issue tracker:
- #
- # s.metadata = { "issue_tracker" => "https://example/issues" }
-
- attr_accessor :metadata
-
- ##
- # Adds a development dependency named +gem+ with +requirements+ to this
- # gem.
- #
- # Usage:
- #
- # spec.add_development_dependency 'example', '~> 1.1', '>= 1.1.4'
- #
- # Development dependencies aren't installed by default and aren't
- # activated when a gem is required.
-
- def add_development_dependency(gem, *requirements)
- add_dependency_with_type(gem, :development, *requirements)
- end
-
- ##
- # Adds a runtime dependency named +gem+ with +requirements+ to this gem.
- #
- # Usage:
- #
- # spec.add_runtime_dependency 'example', '~> 1.1', '>= 1.1.4'
-
- def add_runtime_dependency(gem, *requirements)
- add_dependency_with_type(gem, :runtime, *requirements)
- end
-
- ##
- # Executables included in the gem.
- #
- # For example, the rake gem has rake as an executable. You don’t specify the
- # full path (as in bin/rake); all application-style files are expected to be
- # found in bindir. These files must be executable Ruby files. Files that
- # use bash or other interpreters will not work.
- #
- # Executables included may only be ruby scripts, not scripts for other
- # languages or compiled binaries.
- #
- # Usage:
- #
- # spec.executables << 'rake'
-
- def executables
- @executables ||= []
- end
-
- ##
- # Extensions to build when installing the gem, specifically the paths to
- # extconf.rb-style files used to compile extensions.
- #
- # These files will be run when the gem is installed, causing the C (or
- # whatever) code to be compiled on the user’s machine.
- #
- # Usage:
- #
- # spec.extensions << 'ext/rmagic/extconf.rb'
- #
- # See Gem::Ext::Builder for information about writing extensions for gems.
-
- def extensions
- @extensions ||= []
- end
-
- ##
- # Extra files to add to RDoc such as README or doc/examples.txt
- #
- # When the user elects to generate the RDoc documentation for a gem (typically
- # at install time), all the library files are sent to RDoc for processing.
- # This option allows you to have some non-code files included for a more
- # complete set of documentation.
- #
- # Usage:
- #
- # spec.extra_rdoc_files = ['README', 'doc/user-guide.txt']
-
- def extra_rdoc_files
- @extra_rdoc_files ||= []
- end
-
- ##
- # The version of RubyGems that installed this gem. Returns
- # <code>Gem::Version.new(0)</code> for gems installed by versions earlier
- # than RubyGems 2.2.0.
-
- def installed_by_version # :nodoc:
- @installed_by_version ||= Gem::Version.new(0)
- end
-
- ##
- # Sets the version of RubyGems that installed this gem. See also
- # #installed_by_version.
-
- def installed_by_version= version # :nodoc:
- @installed_by_version = Gem::Version.new version
- end
-
- ##
- # :category: Recommended gemspec attributes
- #
- # The license for this gem.
- #
- # The license must be no more than 64 characters.
- #
- # This should just be the name of your license. The full text of the license
- # should be inside of the gem (at the top level) when you build it.
- #
- # The simplest way, is to specify the standard SPDX ID
- # https://spdx.org/licenses/ for the license.
- # Ideally you should pick one that is OSI (Open Source Initiative)
- # http://opensource.org/licenses/alphabetical approved.
- #
- # The most commonly used OSI approved licenses are BSD-3-Clause and MIT.
- # GitHub also provides a license picker at http://choosealicense.com/.
- #
- # You should specify a license for your gem so that people know how they are
- # permitted to use it, and any restrictions you're placing on it. Not
- # specifying a license means all rights are reserved; others have no rights
- # to use the code for any purpose.
- #
- # You can set multiple licenses with #licenses=
- #
- # Usage:
- # spec.license = 'MIT'
-
- def license=o
- self.licenses = [o]
- end
-
- ##
- # :category: Recommended gemspec attributes
- # The license(s) for the library.
- #
- # Each license must be a short name, no more than 64 characters.
- #
- # This should just be the name of your license. The full
- # text of the license should be inside of the gem when you build it.
- #
- # See #license= for more discussion
- #
- # Usage:
- # spec.licenses = ['MIT', 'GPL-2']
-
- def licenses= licenses
- @licenses = Array licenses
- end
-
- ##
- # Specifies the rdoc options to be used when generating API documentation.
- #
- # Usage:
- #
- # spec.rdoc_options << '--title' << 'Rake -- Ruby Make' <<
- # '--main' << 'README' <<
- # '--line-numbers'
-
- def rdoc_options
- @rdoc_options ||= []
- end
-
- ##
- # The version of Ruby required by this gem. The ruby version can be
- # specified to the patch-level:
- #
- # $ ruby -v -e 'p Gem.ruby_version'
- # ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
- # #<Gem::Version "2.0.0.247">
- #
- # Usage:
- #
- # # This gem will work with 1.8.6 or greater...
- # spec.required_ruby_version = '>= 1.8.6'
- #
- # # Only with ruby 2.0.x
- # spec.required_ruby_version = '~> 2.0'
-
- def required_ruby_version= req
- @required_ruby_version = Gem::Requirement.create req
- end
-
- ##
- # The RubyGems version required by this gem
-
- def required_rubygems_version= req
- @required_rubygems_version = Gem::Requirement.create req
- end
-
- ##
- # Lists the external (to RubyGems) requirements that must be met for this gem
- # to work. It's simply information for the user.
- #
- # Usage:
- #
- # spec.requirements << 'libmagick, v6.0'
- # spec.requirements << 'A good graphics card'
-
- def requirements
- @requirements ||= []
- end
-
- ##
- # A collection of unit test files. They will be loaded as unit tests when
- # the user requests a gem to be unit tested.
- #
- # Usage:
- # spec.test_files = Dir.glob('test/tc_*.rb')
- # spec.test_files = ['tests/test-suite.rb']
-
- def test_files= files # :nodoc:
- @test_files = Array files
- end
-
- ######################################################################
- # :section: Specification internals
-
- ##
- # True when this gemspec has been activated. This attribute is not persisted.
-
- attr_accessor :activated
-
- alias :activated? :activated
-
- ##
- # Autorequire was used by old RubyGems to automatically require a file.
- #
- # Deprecated: It is neither supported nor functional.
-
- attr_accessor :autorequire # :nodoc:
-
- ##
- # Sets the default executable for this gem.
- #
- # Deprecated: You must now specify the executable name to Gem.bin_path.
-
- attr_writer :default_executable
-
- ##
- # Allows deinstallation of gems with legacy platforms.
-
- attr_writer :original_platform # :nodoc:
-
- ##
- # The rubyforge project this gem lives under. i.e. RubyGems'
- # rubyforge_project is "rubygems".
- #
- # This option is deprecated.
-
- attr_accessor :rubyforge_project
-
- ##
- # The Gem::Specification version of this gemspec.
- #
- # Do not set this, it is set automatically when the gem is packaged.
-
- attr_accessor :specification_version
-
- def self._all # :nodoc:
- unless defined?(@@all) && @@all then
- @@all = stubs.map(&:to_spec)
-
- # After a reset, make sure already loaded specs
- # are still marked as activated.
- specs = {}
- Gem.loaded_specs.each_value{|s| specs[s] = true}
- @@all.each{|s| s.activated = true if specs[s]}
- end
- @@all
- end
-
- def self._clear_load_cache # :nodoc:
- LOAD_CACHE.clear
- end
-
- def self.each_gemspec(dirs) # :nodoc:
- dirs.each do |dir|
- Dir[File.join(dir, "*.gemspec")].each do |path|
- yield path.untaint
- end
- end
- end
-
- def self.each_stub(dirs) # :nodoc:
- each_gemspec(dirs) do |path|
- stub = Gem::StubSpecification.new(path)
- yield stub if stub.valid?
- end
- end
-
- def self.each_spec(dirs) # :nodoc:
- each_gemspec(dirs) do |path|
- spec = self.load path
- yield spec if spec
- end
- end
-
- ##
- # Returns a Gem::StubSpecification for every installed gem
-
- def self.stubs
- @@stubs ||= begin
- stubs = {}
- each_stub([default_specifications_dir] + dirs) do |stub|
- stubs[stub.full_name] ||= stub
- end
-
- stubs = stubs.values
- _resort!(stubs)
- stubs
- end
- end
-
- def self._resort!(specs) # :nodoc:
- specs.sort! { |a, b|
- names = a.name <=> b.name
- next names if names.nonzero?
- b.version <=> a.version
- }
- end
-
- ##
- # Loads the default specifications. It should be called only once.
-
- def self.load_defaults
- each_spec([default_specifications_dir]) do |spec|
- # #load returns nil if the spec is bad, so we just ignore
- # it at this stage
- Gem.register_default_spec(spec)
- end
- end
-
- ##
- # Adds +spec+ to the known specifications, keeping the collection
- # properly sorted.
-
- def self.add_spec spec
- # TODO: find all extraneous adds
- # puts
- # p :add_spec => [spec.full_name, caller.reject { |s| s =~ /minitest/ }]
-
- # TODO: flush the rest of the crap from the tests
- # raise "no dupes #{spec.full_name} in #{all_names.inspect}" if
- # _all.include? spec
-
- raise "nil spec!" unless spec # TODO: remove once we're happy with tests
-
- return if _all.include? spec
-
- _all << spec
- stubs << spec
- _resort!(_all)
- _resort!(stubs)
- end
-
- ##
- # Adds multiple specs to the known specifications.
-
- def self.add_specs *specs
- raise "nil spec!" if specs.any?(&:nil?) # TODO: remove once we're happy
-
- # TODO: this is much more efficient, but we need the extra checks for now
- # _all.concat specs
- # _resort!
-
- specs.each do |spec| # TODO: slow
- add_spec spec
- end
- end
-
- ##
- # Returns all specifications. This method is discouraged from use.
- # You probably want to use one of the Enumerable methods instead.
-
- def self.all
- warn "NOTE: Specification.all called from #{caller.first}" unless
- Gem::Deprecate.skip
- _all
- end
-
- ##
- # Sets the known specs to +specs+. Not guaranteed to work for you in
- # the future. Use at your own risk. Caveat emptor. Doomy doom doom.
- # Etc etc.
- #
- #--
- # Makes +specs+ the known specs
- # Listen, time is a river
- # Winter comes, code breaks
- #
- # -- wilsonb
-
- def self.all= specs
- @@all = @@stubs = specs
- end
-
- ##
- # Return full names of all specs in sorted order.
-
- def self.all_names
- self._all.map(&:full_name)
- end
-
- ##
- # Return the list of all array-oriented instance variables.
- #--
- # Not sure why we need to use so much stupid reflection in here...
-
- def self.array_attributes
- @@array_attributes.dup
- end
-
- ##
- # Return the list of all instance variables.
- #--
- # Not sure why we need to use so much stupid reflection in here...
-
- def self.attribute_names
- @@attributes.dup
- end
-
- ##
- # Return the directories that Specification uses to find specs.
-
- def self.dirs
- @@dirs ||= Gem.path.collect { |dir|
- File.join dir.dup.untaint, "specifications"
- }
- end
-
- ##
- # Set the directories that Specification uses to find specs. Setting
- # this resets the list of known specs.
-
- def self.dirs= dirs
- self.reset
-
- @@dirs = Array(dirs).map { |dir| File.join dir, "specifications" }
- end
-
- extend Enumerable
-
- ##
- # Enumerate every known spec. See ::dirs= and ::add_spec to set the list of
- # specs.
-
- def self.each
- return enum_for(:each) unless block_given?
-
- self._all.each do |x|
- yield x
- end
- end
-
- ##
- # Returns every spec that matches +name+ and optional +requirements+.
-
- def self.find_all_by_name name, *requirements
- requirements = Gem::Requirement.default if requirements.empty?
-
- # TODO: maybe try: find_all { |s| spec === dep }
-
- Gem::Dependency.new(name, *requirements).matching_specs
- end
-
- ##
- # Find the best specification matching a +name+ and +requirements+. Raises
- # if the dependency doesn't resolve to a valid specification.
-
- def self.find_by_name name, *requirements
- requirements = Gem::Requirement.default if requirements.empty?
-
- # TODO: maybe try: find { |s| spec === dep }
-
- Gem::Dependency.new(name, *requirements).to_spec
- end
-
- ##
- # Return the best specification that contains the file matching +path+.
-
- def self.find_by_path path
- self.find { |spec|
- spec.contains_requirable_file? path
- }
- end
-
- ##
- # Return the best specification that contains the file matching +path+
- # amongst the specs that are not activated.
-
- def self.find_inactive_by_path path
- stub = stubs.find { |s|
- s.contains_requirable_file? path unless s.activated?
- }
- stub && stub.to_spec
- end
-
- ##
- # Return currently unresolved specs that contain the file matching +path+.
-
- def self.find_in_unresolved path
- # TODO: do we need these?? Kill it
- specs = unresolved_deps.values.map { |dep| dep.to_specs }.flatten
-
- specs.find_all { |spec| spec.contains_requirable_file? path }
- end
-
- ##
- # Search through all unresolved deps and sub-dependencies and return
- # specs that contain the file matching +path+.
-
- def self.find_in_unresolved_tree path
- specs = unresolved_deps.values.map { |dep| dep.to_specs }.flatten
-
- specs.reverse_each do |spec|
- trails = []
- spec.traverse do |from_spec, dep, to_spec, trail|
- next unless to_spec.conflicts.empty?
- trails << trail if to_spec.contains_requirable_file? path
- end
-
- next if trails.empty?
-
- return trails.map(&:reverse).sort.first.reverse
- end
-
- []
- end
-
- ##
- # Special loader for YAML files. When a Specification object is loaded
- # from a YAML file, it bypasses the normal Ruby object initialization
- # routine (#initialize). This method makes up for that and deals with
- # gems of different ages.
- #
- # +input+ can be anything that YAML.load() accepts: String or IO.
-
- def self.from_yaml(input)
- Gem.load_yaml
-
- input = normalize_yaml_input input
- spec = Gem::SafeYAML.safe_load input
-
- if spec && spec.class == FalseClass then
- raise Gem::EndOfYAMLException
- end
-
- unless Gem::Specification === spec then
- raise Gem::Exception, "YAML data doesn't evaluate to gem specification"
- end
-
- spec.specification_version ||= NONEXISTENT_SPECIFICATION_VERSION
- spec.reset_nil_attributes_to_default
-
- spec
- end
-
- ##
- # Return the latest specs, optionally including prerelease specs if
- # +prerelease+ is true.
-
- def self.latest_specs prerelease = false
- result = Hash.new { |h,k| h[k] = {} }
- native = {}
-
- Gem::Specification.reverse_each do |spec|
- next if spec.version.prerelease? unless prerelease
-
- native[spec.name] = spec.version if spec.platform == Gem::Platform::RUBY
- result[spec.name][spec.platform] = spec
- end
-
- result.map(&:last).map(&:values).flatten.reject { |spec|
- minimum = native[spec.name]
- minimum && spec.version < minimum
- }.sort_by{ |tup| tup.name }
- end
-
- ##
- # Loads Ruby format gemspec from +file+.
-
- def self.load file
- return unless file
- file = file.dup.untaint
- return unless File.file?(file)
-
- spec = LOAD_CACHE[file]
- return spec if spec
-
- code = if defined? Encoding
- File.read file, :mode => 'r:UTF-8:-'
- else
- File.read file
- end
-
- code.untaint
-
- begin
- spec = eval code, binding, file
-
- if Gem::Specification === spec
- spec.loaded_from = File.expand_path file.to_s
- LOAD_CACHE[file] = spec
- return spec
- end
-
- warn "[#{file}] isn't a Gem::Specification (#{spec.class} instead)."
- rescue SignalException, SystemExit
- raise
- rescue SyntaxError, Exception => e
- warn "Invalid gemspec in [#{file}]: #{e}"
- end
-
- nil
- end
-
- ##
- # Specification attributes that must be non-nil
-
- def self.non_nil_attributes
- @@non_nil_attributes.dup
- end
-
- ##
- # Make sure the YAML specification is properly formatted with dashes
-
- def self.normalize_yaml_input(input)
- result = input.respond_to?(:read) ? input.read : input
- result = "--- " + result unless result =~ /\A--- /
- result.gsub!(/ !!null \n/, " \n")
- # date: 2011-04-26 00:00:00.000000000Z
- # date: 2011-04-26 00:00:00.000000000 Z
- result.gsub!(/^(date: \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+?)Z/, '\1 Z')
- result
- end
-
- ##
- # Return a list of all outdated local gem names. This method is HEAVY
- # as it must go fetch specifications from the server.
- #
- # Use outdated_and_latest_version if you wish to retrieve the latest remote
- # version as well.
-
- def self.outdated
- outdated_and_latest_version.map { |local, _| local.name }
- end
-
- ##
- # Enumerates the outdated local gems yielding the local specification and
- # the latest remote version.
- #
- # This method may take some time to return as it must check each local gem
- # against the server's index.
-
- def self.outdated_and_latest_version
- return enum_for __method__ unless block_given?
-
- # TODO: maybe we should switch to rubygems' version service?
- fetcher = Gem::SpecFetcher.fetcher
-
- latest_specs(true).each do |local_spec|
- dependency =
- Gem::Dependency.new local_spec.name, ">= #{local_spec.version}"
-
- remotes, = fetcher.search_for_dependency dependency
- remotes = remotes.map { |n, _| n.version }
-
- latest_remote = remotes.sort.last
-
- yield [local_spec, latest_remote] if
- latest_remote and local_spec.version < latest_remote
- end
-
- nil
- end
-
- ##
- # Removes +spec+ from the known specs.
-
- def self.remove_spec spec
- _all.delete spec
- stubs.delete_if { |s| s.full_name == spec.full_name }
- end
-
- ##
- # Is +name+ a required attribute?
-
- def self.required_attribute?(name)
- @@required_attributes.include? name.to_sym
- end
-
- ##
- # Required specification attributes
-
- def self.required_attributes
- @@required_attributes.dup
- end
-
- ##
- # Reset the list of known specs, running pre and post reset hooks
- # registered in Gem.
-
- def self.reset
- @@dirs = nil
- Gem.pre_reset_hooks.each { |hook| hook.call }
- @@all = nil
- @@stubs = nil
- _clear_load_cache
- unresolved = unresolved_deps
- unless unresolved.empty? then
- w = "W" + "ARN"
- warn "#{w}: Unresolved specs during Gem::Specification.reset:"
- unresolved.values.each do |dep|
- warn " #{dep}"
- end
- warn "#{w}: Clearing out unresolved specs."
- warn "Please report a bug if this causes problems."
- unresolved.clear
- end
- Gem.post_reset_hooks.each { |hook| hook.call }
- end
-
- # DOC: This method needs documented or nodoc'd
- def self.unresolved_deps
- @unresolved_deps ||= Hash.new { |h, n| h[n] = Gem::Dependency.new n }
- end
-
- ##
- # Load custom marshal format, re-initializing defaults as needed
-
- def self._load(str)
- array = Marshal.load str
-
- spec = Gem::Specification.new
- spec.instance_variable_set :@specification_version, array[1]
-
- current_version = CURRENT_SPECIFICATION_VERSION
-
- field_count = if spec.specification_version > current_version then
- spec.instance_variable_set :@specification_version,
- current_version
- MARSHAL_FIELDS[current_version]
- else
- MARSHAL_FIELDS[spec.specification_version]
- end
-
- if array.size < field_count then
- raise TypeError, "invalid Gem::Specification format #{array.inspect}"
- end
-
- # Cleanup any YAML::PrivateType. They only show up for an old bug
- # where nil => null, so just convert them to nil based on the type.
-
- array.map! { |e| e.kind_of?(YAML::PrivateType) ? nil : e }
-
- spec.instance_variable_set :@rubygems_version, array[0]
- # spec version
- spec.instance_variable_set :@name, array[2]
- spec.instance_variable_set :@version, array[3]
- spec.date = array[4]
- spec.instance_variable_set :@summary, array[5]
- spec.instance_variable_set :@required_ruby_version, array[6]
- spec.instance_variable_set :@required_rubygems_version, array[7]
- spec.instance_variable_set :@original_platform, array[8]
- spec.instance_variable_set :@dependencies, array[9]
- spec.instance_variable_set :@rubyforge_project, array[10]
- spec.instance_variable_set :@email, array[11]
- spec.instance_variable_set :@authors, array[12]
- spec.instance_variable_set :@description, array[13]
- spec.instance_variable_set :@homepage, array[14]
- spec.instance_variable_set :@has_rdoc, array[15]
- spec.instance_variable_set :@new_platform, array[16]
- spec.instance_variable_set :@platform, array[16].to_s
- spec.instance_variable_set :@license, array[17]
- spec.instance_variable_set :@metadata, array[18]
- spec.instance_variable_set :@loaded, false
- spec.instance_variable_set :@activated, false
-
- spec
- end
-
- def <=>(other) # :nodoc:
- sort_obj <=> other.sort_obj
- end
-
- def == other # :nodoc:
- self.class === other &&
- name == other.name &&
- version == other.version &&
- platform == other.platform
- end
-
- ##
- # Dump only crucial instance variables.
- #--
- # MAINTAIN ORDER!
- # (down with the man)
-
- def _dump(limit)
- Marshal.dump [
- @rubygems_version,
- @specification_version,
- @name,
- @version,
- date,
- @summary,
- @required_ruby_version,
- @required_rubygems_version,
- @original_platform,
- @dependencies,
- @rubyforge_project,
- @email,
- @authors,
- @description,
- @homepage,
- true, # has_rdoc
- @new_platform,
- @licenses,
- @metadata
- ]
- end
-
- ##
- # Activate this spec, registering it as a loaded spec and adding
- # it's lib paths to $LOAD_PATH. Returns true if the spec was
- # activated, false if it was previously activated. Freaks out if
- # there are conflicts upon activation.
-
- def activate
- other = Gem.loaded_specs[self.name]
- if other then
- check_version_conflict other
- return false
- end
-
- raise_if_conflicts
-
- activate_dependencies
- add_self_to_load_path
-
- Gem.loaded_specs[self.name] = self
- @activated = true
- @loaded = true
-
- return true
- end
-
- ##
- # Activate all unambiguously resolved runtime dependencies of this
- # spec. Add any ambiguous dependencies to the unresolved list to be
- # resolved later, as needed.
-
- def activate_dependencies
- unresolved = Gem::Specification.unresolved_deps
-
- self.runtime_dependencies.each do |spec_dep|
- if loaded = Gem.loaded_specs[spec_dep.name]
- next if spec_dep.matches_spec? loaded
-
- msg = "can't satisfy '#{spec_dep}', already activated '#{loaded.full_name}'"
- e = Gem::LoadError.new msg
- e.name = spec_dep.name
-
- raise e
- end
-
- specs = spec_dep.to_specs
-
- if specs.size == 1 then
- specs.first.activate
- else
- name = spec_dep.name
- unresolved[name] = unresolved[name].merge spec_dep
- end
- end
-
- unresolved.delete self.name
- end
-
- ##
- # Returns an array with bindir attached to each executable in the
- # +executables+ list
-
- def add_bindir(executables)
- return nil if executables.nil?
-
- if @bindir then
- Array(executables).map { |e| File.join(@bindir, e) }
- else
- executables
- end
- rescue
- return nil
- end
-
- ##
- # Adds a dependency on gem +dependency+ with type +type+ that requires
- # +requirements+. Valid types are currently <tt>:runtime</tt> and
- # <tt>:development</tt>.
-
- def add_dependency_with_type(dependency, type, *requirements)
- requirements = if requirements.empty? then
- Gem::Requirement.default
- else
- requirements.flatten
- end
-
- unless dependency.respond_to?(:name) &&
- dependency.respond_to?(:version_requirements)
- dependency = Gem::Dependency.new(dependency.to_s, requirements, type)
- end
-
- dependencies << dependency
- end
-
- private :add_dependency_with_type
-
- alias add_dependency add_runtime_dependency
-
- ##
- # Adds this spec's require paths to LOAD_PATH, in the proper location.
-
- def add_self_to_load_path
- return if default_gem?
-
- paths = full_require_paths
-
- # gem directories must come after -I and ENV['RUBYLIB']
- insert_index = Gem.load_path_insert_index
-
- if insert_index then
- # gem directories must come after -I and ENV['RUBYLIB']
- $LOAD_PATH.insert(insert_index, *paths)
- else
- # we are probably testing in core, -I and RUBYLIB don't apply
- $LOAD_PATH.unshift(*paths)
- end
- end
-
- ##
- # Singular reader for #authors. Returns the first author in the list
-
- def author
- val = authors and val.first
- end
-
- ##
- # The list of author names who wrote this gem.
- #
- # spec.authors = ['Chad Fowler', 'Jim Weirich', 'Rich Kilmer']
-
- def authors
- @authors ||= []
- end
-
- ##
- # Returns the full path to installed gem's bin directory.
- #
- # NOTE: do not confuse this with +bindir+, which is just 'bin', not
- # a full path.
-
- def bin_dir
- @bin_dir ||= File.join gem_dir, bindir # TODO: this is unfortunate
- end
-
- ##
- # Returns the full path to an executable named +name+ in this gem.
-
- def bin_file name
- File.join bin_dir, name
- end
-
- ##
- # Returns the build_args used to install the gem
-
- def build_args
- if File.exist? build_info_file
- build_info = File.readlines build_info_file
- build_info = build_info.map { |x| x.strip }
- build_info.delete ""
- build_info
- else
- []
- end
- end
-
- ##
- # Builds extensions for this platform if the gem has extensions listed and
- # the gem.build_complete file is missing.
-
- def build_extensions # :nodoc:
- return if default_gem?
- return if extensions.empty?
- return if installed_by_version < Gem::Version.new('2.2.0.preview.2')
- return if File.exist? gem_build_complete_path
- return if !File.writable?(base_dir)
- return if !File.exist?(File.join(base_dir, 'extensions'))
-
- begin
- # We need to require things in $LOAD_PATH without looking for the
- # extension we are about to build.
- unresolved_deps = Gem::Specification.unresolved_deps.dup
- Gem::Specification.unresolved_deps.clear
-
- require 'rubygems/config_file'
- require 'rubygems/ext'
- require 'rubygems/user_interaction'
-
- ui = Gem::SilentUI.new
- Gem::DefaultUserInteraction.use_ui ui do
- builder = Gem::Ext::Builder.new self
- builder.build_extensions
- end
- ensure
- ui.close if ui
- Gem::Specification.unresolved_deps.replace unresolved_deps
- end
- end
-
- ##
- # Returns the full path to the build info directory
-
- def build_info_dir
- File.join base_dir, "build_info"
- end
-
- ##
- # Returns the full path to the file containing the build
- # information generated when the gem was installed
-
- def build_info_file
- File.join build_info_dir, "#{full_name}.info"
- end
-
- ##
- # Used to detect if the gem is bundled in older version of Ruby, but not
- # detectable as default gem (see BasicSpecification#default_gem?).
-
- def bundled_gem_in_old_ruby?
- !default_gem? &&
- RUBY_VERSION < "2.0.0" &&
- summary == "This #{name} is bundled with Ruby"
- end
-
- ##
- # Returns the full path to the cache directory containing this
- # spec's cached gem.
-
- def cache_dir
- @cache_dir ||= File.join base_dir, "cache"
- end
-
- ##
- # Returns the full path to the cached gem for this spec.
-
- def cache_file
- @cache_file ||= File.join cache_dir, "#{full_name}.gem"
- end
-
- ##
- # Return any possible conflicts against the currently loaded specs.
-
- def conflicts
- conflicts = {}
- self.runtime_dependencies.each { |dep|
- spec = Gem.loaded_specs[dep.name]
- if spec and not spec.satisfies_requirement? dep
- (conflicts[spec] ||= []) << dep
- end
- }
- conflicts
- end
-
- ##
- # The date this gem was created. Lazily defaults to the current UTC date.
- #
- # There is no need to set this in your gem specification.
-
- def date
- @date ||= TODAY
- end
-
- DateLike = Object.new # :nodoc:
- def DateLike.===(obj) # :nodoc:
- defined?(::Date) and Date === obj
- end
-
- DateTimeFormat = # :nodoc:
- /\A
- (\d{4})-(\d{2})-(\d{2})
- (\s+ \d{2}:\d{2}:\d{2}\.\d+ \s* (Z | [-+]\d\d:\d\d) )?
- \Z/x
-
- ##
- # The date this gem was created
- #
- # DO NOT set this, it is set automatically when the gem is packaged.
-
- def date= date
- # We want to end up with a Time object with one-day resolution.
- # This is the cleanest, most-readable, faster-than-using-Date
- # way to do it.
- @date = case date
- when String then
- if DateTimeFormat =~ date then
- Time.utc($1.to_i, $2.to_i, $3.to_i)
-
- # Workaround for where the date format output from psych isn't
- # parsed as a Time object by syck and thus comes through as a
- # string.
- elsif /\A(\d{4})-(\d{2})-(\d{2}) \d{2}:\d{2}:\d{2}\.\d+?Z\z/ =~ date then
- Time.utc($1.to_i, $2.to_i, $3.to_i)
- else
- raise(Gem::InvalidSpecificationException,
- "invalid date format in specification: #{date.inspect}")
- end
- when Time, DateLike then
- Time.utc(date.year, date.month, date.day)
- else
- TODAY
- end
- end
-
- ##
- # The default executable for this gem.
- #
- # Deprecated: The name of the gem is assumed to be the name of the
- # executable now. See Gem.bin_path.
-
- def default_executable # :nodoc:
- if defined?(@default_executable) and @default_executable
- result = @default_executable
- elsif @executables and @executables.size == 1
- result = Array(@executables).first
- else
- result = nil
- end
- result
- end
-
- ##
- # The default value for specification attribute +name+
-
- def default_value name
- @@default_value[name]
- end
-
- ##
- # A list of Gem::Dependency objects this gem depends on.
- #
- # Use #add_dependency or #add_development_dependency to add dependencies to
- # a gem.
-
- def dependencies
- @dependencies ||= []
- end
-
- ##
- # Return a list of all gems that have a dependency on this gemspec. The
- # list is structured with entries that conform to:
- #
- # [depending_gem, dependency, [list_of_gems_that_satisfy_dependency]]
-
- def dependent_gems
- out = []
- Gem::Specification.each do |spec|
- spec.dependencies.each do |dep|
- if self.satisfies_requirement?(dep) then
- sats = []
- find_all_satisfiers(dep) do |sat|
- sats << sat
- end
- out << [spec, dep, sats]
- end
- end
- end
- out
- end
-
- ##
- # Returns all specs that matches this spec's runtime dependencies.
-
- def dependent_specs
- runtime_dependencies.map { |dep| dep.to_specs }.flatten
- end
-
- ##
- # A detailed description of this gem. See also #summary
-
- def description= str
- @description = str.to_s
- end
-
- ##
- # List of dependencies that are used for development
-
- def development_dependencies
- dependencies.select { |d| d.type == :development }
- end
-
- ##
- # Returns the full path to this spec's documentation directory. If +type+
- # is given it will be appended to the end. For example:
- #
- # spec.doc_dir # => "/path/to/gem_repo/doc/a-1"
- #
- # spec.doc_dir 'ri' # => "/path/to/gem_repo/doc/a-1/ri"
-
- def doc_dir type = nil
- @doc_dir ||= File.join base_dir, 'doc', full_name
-
- if type then
- File.join @doc_dir, type
- else
- @doc_dir
- end
- end
-
- def encode_with coder # :nodoc:
- mark_version
-
- coder.add 'name', @name
- coder.add 'version', @version
- platform = case @original_platform
- when nil, '' then
- 'ruby'
- when String then
- @original_platform
- else
- @original_platform.to_s
- end
- coder.add 'platform', platform
-
- attributes = @@attributes.map(&:to_s) - %w[name version platform]
- attributes.each do |name|
- coder.add name, instance_variable_get("@#{name}")
- end
- end
-
- def eql? other # :nodoc:
- self.class === other && same_attributes?(other)
- end
-
- ##
- # Singular accessor for #executables
-
- def executable
- val = executables and val.first
- end
-
- ##
- # Singular accessor for #executables
-
- def executable=o
- self.executables = [o]
- end
-
- ##
- # Sets executables to +value+, ensuring it is an array. Don't
- # use this, push onto the array instead.
-
- def executables= value
- # TODO: warn about setting instead of pushing
- @executables = Array(value)
- end
-
- ##
- # Sets extensions to +extensions+, ensuring it is an array. Don't
- # use this, push onto the array instead.
-
- def extensions= extensions
- # TODO: warn about setting instead of pushing
- @extensions = Array extensions
- end
-
- ##
- # Sets extra_rdoc_files to +files+, ensuring it is an array. Don't
- # use this, push onto the array instead.
-
- def extra_rdoc_files= files
- # TODO: warn about setting instead of pushing
- @extra_rdoc_files = Array files
- end
-
- ##
- # The default (generated) file name of the gem. See also #spec_name.
- #
- # spec.file_name # => "example-1.0.gem"
-
- def file_name
- "#{full_name}.gem"
- end
-
- ##
- # Sets files to +files+, ensuring it is an array.
-
- def files= files
- @files = Array files
- end
-
- ##
- # Finds all gems that satisfy +dep+
-
- def find_all_satisfiers dep
- Gem::Specification.each do |spec|
- yield spec if spec.satisfies_requirement? dep
- end
- end
-
- private :find_all_satisfiers
-
- ##
- # Creates a duplicate spec without large blobs that aren't used at runtime.
-
- def for_cache
- spec = dup
-
- spec.files = nil
- spec.test_files = nil
-
- spec
- end
-
- def find_full_gem_path # :nodoc:
- super || File.expand_path(File.join(gems_dir, original_name))
- end
- private :find_full_gem_path
-
- def full_name
- @full_name ||= super
- end
-
- ##
- # The path to the gem.build_complete file within the extension install
- # directory.
-
- def gem_build_complete_path # :nodoc:
- File.join extension_dir, 'gem.build_complete'
- end
-
- ##
- # Work around bundler removing my methods
-
- def gem_dir # :nodoc:
- super
- end
-
- ##
- # Deprecated and ignored, defaults to true.
- #
- # Formerly used to indicate this gem was RDoc-capable.
-
- def has_rdoc # :nodoc:
- true
- end
-
- ##
- # Deprecated and ignored.
- #
- # Formerly used to indicate this gem was RDoc-capable.
-
- def has_rdoc= ignored # :nodoc:
- @has_rdoc = true
- end
-
- alias :has_rdoc? :has_rdoc # :nodoc:
-
- ##
- # True if this gem has files in test_files
-
- def has_unit_tests? # :nodoc:
- not test_files.empty?
- end
-
- # :stopdoc:
- alias has_test_suite? has_unit_tests?
- # :startdoc:
-
- def hash # :nodoc:
- name.hash ^ version.hash
- end
-
- def init_with coder # :nodoc:
- @installed_by_version ||= nil
- yaml_initialize coder.tag, coder.map
- end
-
- ##
- # Specification constructor. Assigns the default values to the attributes
- # and yields itself for further initialization. Optionally takes +name+ and
- # +version+.
-
- def initialize name = nil, version = nil
- @loaded = false
- @activated = false
- self.loaded_from = nil
- @original_platform = nil
- @installed_by_version = nil
-
- @@nil_attributes.each do |key|
- instance_variable_set "@#{key}", nil
- end
-
- @@non_nil_attributes.each do |key|
- default = default_value(key)
- value = Dupable[key] ? default.dup : default
- instance_variable_set "@#{key}", value
- end
-
- @new_platform = Gem::Platform::RUBY
-
- self.name = name if name
- self.version = version if version
-
- yield self if block_given?
- end
-
- ##
- # Duplicates array_attributes from +other_spec+ so state isn't shared.
-
- def initialize_copy other_spec
- self.class.array_attributes.each do |name|
- name = :"@#{name}"
- next unless other_spec.instance_variable_defined? name
-
- begin
- val = other_spec.instance_variable_get(name)
- if val then
- instance_variable_set name, val.dup
- elsif Gem.configuration.really_verbose
- warn "WARNING: #{full_name} has an invalid nil value for #{name}"
- end
- rescue TypeError
- e = Gem::FormatException.new \
- "#{full_name} has an invalid value for #{name}"
-
- e.file_path = loaded_from
- raise e
- end
- end
- end
-
- ##
- # Expire memoized instance variables that can incorrectly generate, replace
- # or miss files due changes in certain attributes used to compute them.
-
- def invalidate_memoized_attributes
- @full_name = nil
- @cache_file = nil
- end
-
- private :invalidate_memoized_attributes
-
- def inspect # :nodoc:
- if $DEBUG
- super
- else
- "#<#{self.class}:0x#{__id__.to_s(16)} #{full_name}>"
- end
- end
-
- ##
- # Returns a string usable in Dir.glob to match all requirable paths
- # for this spec.
-
- def lib_dirs_glob
- dirs = if self.require_paths.size > 1 then
- "{#{self.require_paths.join(',')}}"
- else
- self.require_paths.first
- end
-
- "#{self.full_gem_path}/#{dirs}"
- end
-
- ##
- # Files in the Gem under one of the require_paths
-
- def lib_files
- @files.select do |file|
- require_paths.any? do |path|
- file.start_with? path
- end
- end
- end
-
- ##
- # Singular accessor for #licenses
-
- def license
- val = licenses and val.first
- end
-
- ##
- # Plural accessor for setting licenses
- #
- # See #license= for details
-
- def licenses
- @licenses ||= []
- end
-
- def loaded_from= path # :nodoc:
- super
-
- @bin_dir = nil
- @cache_dir = nil
- @cache_file = nil
- @doc_dir = nil
- @ri_dir = nil
- @spec_dir = nil
- @spec_file = nil
- end
-
- ##
- # Sets the rubygems_version to the current RubyGems version.
-
- def mark_version
- @rubygems_version = Gem::VERSION
- end
-
- ##
- # Return all files in this gem that match for +glob+.
-
- def matches_for_glob glob # TODO: rename?
- # TODO: do we need these?? Kill it
- glob = File.join(self.lib_dirs_glob, glob)
-
- Dir[glob].map { |f| f.untaint } # FIX our tests are broken, run w/ SAFE=1
- end
-
- ##
- # Warn about unknown attributes while loading a spec.
-
- def method_missing(sym, *a, &b) # :nodoc:
- if @specification_version > CURRENT_SPECIFICATION_VERSION and
- sym.to_s =~ /=$/ then
- warn "ignoring #{sym} loading #{full_name}" if $DEBUG
- else
- super
- end
- end
-
- ##
- # Is this specification missing its extensions? When this returns true you
- # probably want to build_extensions
-
- def missing_extensions?
- return false if default_gem?
- return false if extensions.empty?
- return false if installed_by_version < Gem::Version.new('2.2.0.preview.2')
- return false if File.exist? gem_build_complete_path
-
- true
- end
-
- ##
- # Normalize the list of files so that:
- # * All file lists have redundancies removed.
- # * Files referenced in the extra_rdoc_files are included in the package
- # file list.
-
- def normalize
- if defined?(@extra_rdoc_files) and @extra_rdoc_files then
- @extra_rdoc_files.uniq!
- @files ||= []
- @files.concat(@extra_rdoc_files)
- end
-
- @files = @files.uniq if @files
- @extensions = @extensions.uniq if @extensions
- @test_files = @test_files.uniq if @test_files
- @executables = @executables.uniq if @executables
- @extra_rdoc_files = @extra_rdoc_files.uniq if @extra_rdoc_files
- end
-
- ##
- # Return a NameTuple that represents this Specification
-
- def name_tuple
- Gem::NameTuple.new name, version, original_platform
- end
-
- ##
- # Returns the full name (name-version) of this gemspec using the original
- # platform. For use with legacy gems.
-
- def original_name # :nodoc:
- if platform == Gem::Platform::RUBY or platform.nil? then
- "#{@name}-#{@version}"
- else
- "#{@name}-#{@version}-#{@original_platform}"
- end
- end
-
- ##
- # Cruft. Use +platform+.
-
- def original_platform # :nodoc:
- @original_platform ||= platform
- end
-
- ##
- # The platform this gem runs on. See Gem::Platform for details.
-
- def platform
- @new_platform ||= Gem::Platform::RUBY
- end
-
- def pretty_print(q) # :nodoc:
- q.group 2, 'Gem::Specification.new do |s|', 'end' do
- q.breakable
-
- attributes = @@attributes - [:name, :version]
- attributes.unshift :installed_by_version
- attributes.unshift :version
- attributes.unshift :name
-
- attributes.each do |attr_name|
- current_value = self.send attr_name
- if current_value != default_value(attr_name) or
- self.class.required_attribute? attr_name then
-
- q.text "s.#{attr_name} = "
-
- if attr_name == :date then
- current_value = current_value.utc
-
- q.text "Time.utc(#{current_value.year}, #{current_value.month}, #{current_value.day})"
- else
- q.pp current_value
- end
-
- q.breakable
- end
- end
- end
- end
-
- ##
- # Raise an exception if the version of this spec conflicts with the one
- # that is already loaded (+other+)
-
- def check_version_conflict other # :nodoc:
- return if self.version == other.version
-
- # This gem is already loaded. If the currently loaded gem is not in the
- # list of candidate gems, then we have a version conflict.
-
- msg = "can't activate #{full_name}, already activated #{other.full_name}"
-
- e = Gem::LoadError.new msg
- e.name = self.name
- # TODO: e.requirement = dep.requirement
-
- raise e
- end
-
- private :check_version_conflict
-
- ##
- # Check the spec for possible conflicts and freak out if there are any.
-
- def raise_if_conflicts # :nodoc:
- conf = self.conflicts
-
- unless conf.empty? then
- raise Gem::ConflictError.new self, conf
- end
- end
-
- ##
- # Sets rdoc_options to +value+, ensuring it is an array. Don't
- # use this, push onto the array instead.
-
- def rdoc_options= options
- # TODO: warn about setting instead of pushing
- @rdoc_options = Array options
- end
-
- ##
- # Singular accessor for #require_paths
-
- def require_path
- val = require_paths and val.first
- end
-
- ##
- # Singular accessor for #require_paths
-
- def require_path= path
- self.require_paths = Array(path)
- end
-
- ##
- # Set requirements to +req+, ensuring it is an array. Don't
- # use this, push onto the array instead.
-
- def requirements= req
- # TODO: warn about setting instead of pushing
- @requirements = Array req
- end
-
- def respond_to_missing? m, include_private = false # :nodoc:
- false
- end
-
- ##
- # Returns the full path to this spec's ri directory.
-
- def ri_dir
- @ri_dir ||= File.join base_dir, 'ri', full_name
- end
-
- ##
- # Return a string containing a Ruby code representation of the given
- # object.
-
- def ruby_code(obj)
- case obj
- when String then obj.dump
- when Array then '[' + obj.map { |x| ruby_code x }.join(", ") + ']'
- when Hash then
- seg = obj.keys.sort.map { |k| "#{k.to_s.dump} => #{obj[k].to_s.dump}" }
- "{ #{seg.join(', ')} }"
- when Gem::Version then obj.to_s.dump
- when DateLike then obj.strftime('%Y-%m-%d').dump
- when Time then obj.strftime('%Y-%m-%d').dump
- when Numeric then obj.inspect
- when true, false, nil then obj.inspect
- when Gem::Platform then "Gem::Platform.new(#{obj.to_a.inspect})"
- when Gem::Requirement then
- list = obj.as_list
- "Gem::Requirement.new(#{ruby_code(list.size == 1 ? obj.to_s : list)})"
- else raise Gem::Exception, "ruby_code case not handled: #{obj.class}"
- end
- end
-
- private :ruby_code
-
- ##
- # List of dependencies that will automatically be activated at runtime.
-
- def runtime_dependencies
- dependencies.select { |d| d.type == :runtime }
- end
-
- ##
- # True if this gem has the same attributes as +other+.
-
- def same_attributes? spec
- @@attributes.all? { |name, default| self.send(name) == spec.send(name) }
- end
-
- private :same_attributes?
-
- ##
- # Checks if this specification meets the requirement of +dependency+.
-
- def satisfies_requirement? dependency
- return @name == dependency.name &&
- dependency.requirement.satisfied_by?(@version)
- end
-
- ##
- # Returns an object you can use to sort specifications in #sort_by.
-
- def sort_obj
- [@name, @version, @new_platform == Gem::Platform::RUBY ? -1 : 1]
- end
-
- ##
- # Used by Gem::Resolver to order Gem::Specification objects
-
- def source # :nodoc:
- Gem::Source::Installed.new
- end
-
- ##
- # Returns the full path to the directory containing this spec's
- # gemspec file. eg: /usr/local/lib/ruby/gems/1.8/specifications
-
- def spec_dir
- @spec_dir ||= File.join base_dir, "specifications"
- end
-
- ##
- # Returns the full path to this spec's gemspec file.
- # eg: /usr/local/lib/ruby/gems/1.8/specifications/mygem-1.0.gemspec
-
- def spec_file
- @spec_file ||= File.join spec_dir, "#{full_name}.gemspec"
- end
-
- ##
- # The default name of the gemspec. See also #file_name
- #
- # spec.spec_name # => "example-1.0.gemspec"
-
- def spec_name
- "#{full_name}.gemspec"
- end
-
- ##
- # A short summary of this gem's description.
-
- def summary= str
- @summary = str.to_s.strip.
- gsub(/(\w-)\n[ \t]*(\w)/, '\1\2').gsub(/\n[ \t]*/, " ") # so. weird.
- end
-
- ##
- # Singular accessor for #test_files
-
- def test_file # :nodoc:
- val = test_files and val.first
- end
-
- ##
- # Singular mutator for #test_files
-
- def test_file= file # :nodoc:
- self.test_files = [file]
- end
-
- ##
- # Test files included in this gem. You cannot append to this accessor, you
- # must assign to it.
-
- def test_files # :nodoc:
- # Handle the possibility that we have @test_suite_file but not
- # @test_files. This will happen when an old gem is loaded via
- # YAML.
- if defined? @test_suite_file then
- @test_files = [@test_suite_file].flatten
- @test_suite_file = nil
- end
- if defined?(@test_files) and @test_files then
- @test_files
- else
- @test_files = []
- end
- end
-
- ##
- # Returns a Ruby code representation of this specification, such that it can
- # be eval'ed and reconstruct the same specification later. Attributes that
- # still have their default values are omitted.
-
- def to_ruby
- mark_version
- result = []
- result << "# -*- encoding: utf-8 -*-"
- result << "#{Gem::StubSpecification::PREFIX}#{name} #{version} #{platform} #{raw_require_paths.join("\0")}"
- result << "#{Gem::StubSpecification::PREFIX}#{extensions.join "\0"}" unless
- extensions.empty?
- result << nil
- result << "Gem::Specification.new do |s|"
-
- result << " s.name = #{ruby_code name}"
- result << " s.version = #{ruby_code version}"
- unless platform.nil? or platform == Gem::Platform::RUBY then
- result << " s.platform = #{ruby_code original_platform}"
- end
- result << ""
- result << " s.required_rubygems_version = #{ruby_code required_rubygems_version} if s.respond_to? :required_rubygems_version="
-
- if metadata and !metadata.empty?
- result << " s.metadata = #{ruby_code metadata} if s.respond_to? :metadata="
- end
- result << " s.require_paths = #{ruby_code raw_require_paths}"
-
- handled = [
- :dependencies,
- :name,
- :platform,
- :require_paths,
- :required_rubygems_version,
- :specification_version,
- :version,
- :has_rdoc,
- :default_executable,
- :metadata
- ]
-
- @@attributes.each do |attr_name|
- next if handled.include? attr_name
- current_value = self.send(attr_name)
- if current_value != default_value(attr_name) or
- self.class.required_attribute? attr_name then
- result << " s.#{attr_name} = #{ruby_code current_value}"
- end
- end
-
- if @installed_by_version then
- result << nil
- result << " s.installed_by_version = \"#{Gem::VERSION}\" if s.respond_to? :installed_by_version"
- end
-
- unless dependencies.empty? then
- result << nil
- result << " if s.respond_to? :specification_version then"
- result << " s.specification_version = #{specification_version}"
- result << nil
-
- result << " if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then"
-
- dependencies.each do |dep|
- req = dep.requirements_list.inspect
- dep.instance_variable_set :@type, :runtime if dep.type.nil? # HACK
- result << " s.add_#{dep.type}_dependency(%q<#{dep.name}>, #{req})"
- end
-
- result << " else"
-
- dependencies.each do |dep|
- version_reqs_param = dep.requirements_list.inspect
- result << " s.add_dependency(%q<#{dep.name}>, #{version_reqs_param})"
- end
-
- result << ' end'
-
- result << " else"
- dependencies.each do |dep|
- version_reqs_param = dep.requirements_list.inspect
- result << " s.add_dependency(%q<#{dep.name}>, #{version_reqs_param})"
- end
- result << " end"
- end
-
- result << "end"
- result << nil
-
- result.join "\n"
- end
-
- ##
- # Returns a Ruby lighter-weight code representation of this specification,
- # used for indexing only.
- #
- # See #to_ruby.
-
- def to_ruby_for_cache
- for_cache.to_ruby
- end
-
- def to_s # :nodoc:
- "#<Gem::Specification name=#{@name} version=#{@version}>"
- end
-
- ##
- # Returns self
-
- def to_spec
- self
- end
-
- def to_yaml(opts = {}) # :nodoc:
- if (YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck?) ||
- (defined?(Psych) && YAML == Psych) then
- # Because the user can switch the YAML engine behind our
- # back, we have to check again here to make sure that our
- # psych code was properly loaded, and load it if not.
- unless Gem.const_defined?(:NoAliasYAMLTree)
- require 'rubygems/psych_tree'
- end
-
- builder = Gem::NoAliasYAMLTree.create
- builder << self
- ast = builder.tree
-
- io = Gem::StringSink.new
- io.set_encoding Encoding::UTF_8 if Object.const_defined? :Encoding
-
- Psych::Visitors::Emitter.new(io).accept(ast)
-
- io.string.gsub(/ !!null \n/, " \n")
- else
- YAML.quick_emit object_id, opts do |out|
- out.map taguri, to_yaml_style do |map|
- encode_with map
- end
- end
- end
- end
-
- ##
- # Recursively walk dependencies of this spec, executing the +block+ for each
- # hop.
-
- def traverse trail = [], &block
- trail = trail + [self]
- runtime_dependencies.each do |dep|
- dep.to_specs.each do |dep_spec|
- block[self, dep, dep_spec, trail + [dep_spec]]
- dep_spec.traverse(trail, &block) unless
- trail.map(&:name).include? dep_spec.name
- end
- end
- end
-
- ##
- # Checks that the specification contains all required fields, and does a
- # very basic sanity check.
- #
- # Raises InvalidSpecificationException if the spec does not pass the
- # checks..
-
- def validate packaging = true
- @warnings = 0
- require 'rubygems/user_interaction'
- extend Gem::UserInteraction
- normalize
-
- nil_attributes = self.class.non_nil_attributes.find_all do |attrname|
- instance_variable_get("@#{attrname}").nil?
- end
-
- unless nil_attributes.empty? then
- raise Gem::InvalidSpecificationException,
- "#{nil_attributes.join ', '} must not be nil"
- end
-
- if packaging and rubygems_version != Gem::VERSION then
- raise Gem::InvalidSpecificationException,
- "expected RubyGems version #{Gem::VERSION}, was #{rubygems_version}"
- end
-
- @@required_attributes.each do |symbol|
- unless self.send symbol then
- raise Gem::InvalidSpecificationException,
- "missing value for attribute #{symbol}"
- end
- end
-
- if !name.is_a?(String) then
- raise Gem::InvalidSpecificationException,
- "invalid value for attribute name: \"#{name.inspect}\" must be a string"
- elsif name !~ /[a-zA-Z]/ then
- raise Gem::InvalidSpecificationException,
- "invalid value for attribute name: #{name.dump} must include at least one letter"
- elsif name !~ VALID_NAME_PATTERN then
- raise Gem::InvalidSpecificationException,
- "invalid value for attribute name: #{name.dump} can only include letters, numbers, dashes, and underscores"
- end
-
- if raw_require_paths.empty? then
- raise Gem::InvalidSpecificationException,
- 'specification must have at least one require_path'
- end
-
- @files.delete_if { |x| File.directory?(x) }
- @test_files.delete_if { |x| File.directory?(x) }
- @executables.delete_if { |x| File.directory?(File.join(@bindir, x)) }
- @extra_rdoc_files.delete_if { |x| File.directory?(x) }
- @extensions.delete_if { |x| File.directory?(x) }
-
- non_files = files.reject { |x| File.file?(x) }
-
- unless not packaging or non_files.empty? then
- raise Gem::InvalidSpecificationException,
- "[\"#{non_files.join "\", \""}\"] are not files"
- end
-
- if files.include? file_name then
- raise Gem::InvalidSpecificationException,
- "#{full_name} contains itself (#{file_name}), check your files list"
- end
-
- unless specification_version.is_a?(Fixnum)
- raise Gem::InvalidSpecificationException,
- 'specification_version must be a Fixnum (did you mean version?)'
- end
-
- case platform
- when Gem::Platform, Gem::Platform::RUBY then # ok
- else
- raise Gem::InvalidSpecificationException,
- "invalid platform #{platform.inspect}, see Gem::Platform"
- end
-
- self.class.array_attributes.each do |field|
- val = self.send field
- klass = case field
- when :dependencies
- Gem::Dependency
- else
- String
- end
-
- unless Array === val and val.all? { |x| x.kind_of?(klass) } then
- raise(Gem::InvalidSpecificationException,
- "#{field} must be an Array of #{klass}")
- end
- end
-
- [:authors].each do |field|
- val = self.send field
- raise Gem::InvalidSpecificationException, "#{field} may not be empty" if
- val.empty?
- end
-
- unless Hash === metadata
- raise Gem::InvalidSpecificationException,
- 'metadata must be a hash'
- end
-
- metadata.keys.each do |k|
- if !k.kind_of?(String)
- raise Gem::InvalidSpecificationException,
- 'metadata keys must be a String'
- end
-
- if k.size > 128
- raise Gem::InvalidSpecificationException,
- "metadata key too large (#{k.size} > 128)"
- end
- end
-
- metadata.values.each do |k|
- if !k.kind_of?(String)
- raise Gem::InvalidSpecificationException,
- 'metadata values must be a String'
- end
-
- if k.size > 1024
- raise Gem::InvalidSpecificationException,
- "metadata value too large (#{k.size} > 1024)"
- end
- end
-
- licenses.each { |license|
- if license.length > 64
- raise Gem::InvalidSpecificationException,
- "each license must be 64 characters or less"
- end
- }
-
- warning <<-warning if licenses.empty?
-licenses is empty, but is recommended. Use a license abbreviation from:
-http://opensource.org/licenses/alphabetical
- warning
-
- validate_permissions
-
- # reject lazy developers:
-
- lazy = '"FIxxxXME" or "TOxxxDO"'.gsub(/xxx/, '')
-
- unless authors.grep(/FI XME|TO DO/x).empty? then
- raise Gem::InvalidSpecificationException, "#{lazy} is not an author"
- end
-
- unless Array(email).grep(/FI XME|TO DO/x).empty? then
- raise Gem::InvalidSpecificationException, "#{lazy} is not an email"
- end
-
- if description =~ /FI XME|TO DO/x then
- raise Gem::InvalidSpecificationException, "#{lazy} is not a description"
- end
-
- if summary =~ /FI XME|TO DO/x then
- raise Gem::InvalidSpecificationException, "#{lazy} is not a summary"
- end
-
- if homepage and not homepage.empty? and
- homepage !~ /\A[a-z][a-z\d+.-]*:/i then
- raise Gem::InvalidSpecificationException,
- "\"#{homepage}\" is not a URI"
- end
-
- # Warnings
-
- %w[author description email homepage summary].each do |attribute|
- value = self.send attribute
- warning "no #{attribute} specified" if value.nil? or value.empty?
- end
-
- if description == summary then
- warning 'description and summary are identical'
- end
-
- # TODO: raise at some given date
- warning "deprecated autorequire specified" if autorequire
-
- executables.each do |executable|
- executable_path = File.join(bindir, executable)
- shebang = File.read(executable_path, 2) == '#!'
-
- warning "#{executable_path} is missing #! line" unless shebang
- end
-
- validate_dependencies
-
- true
- ensure
- if $! or @warnings > 0 then
- alert_warning "See http://guides.rubygems.org/specification-reference/ for help"
- end
- end
-
- ##
- # Checks that dependencies use requirements as we recommend. Warnings are
- # issued when dependencies are open-ended or overly strict for semantic
- # versioning.
-
- def validate_dependencies # :nodoc:
- seen = {}
-
- dependencies.each do |dep|
- if prev = seen[dep.name] then
- raise Gem::InvalidSpecificationException, <<-MESSAGE
-duplicate dependency on #{dep}, (#{prev.requirement}) use:
- add_runtime_dependency '#{dep.name}', '#{dep.requirement}', '#{prev.requirement}'
- MESSAGE
- end
-
- seen[dep.name] = dep
-
- prerelease_dep = dep.requirements_list.any? do |req|
- Gem::Requirement.new(req).prerelease?
- end
-
- warning "prerelease dependency on #{dep} is not recommended" if
- prerelease_dep
-
- overly_strict = dep.requirement.requirements.length == 1 &&
- dep.requirement.requirements.any? do |op, version|
- op == '~>' and
- not version.prerelease? and
- version.segments.length > 2 and
- version.segments.first != 0
- end
-
- if overly_strict then
- _, dep_version = dep.requirement.requirements.first
-
- base = dep_version.segments.first 2
-
- warning <<-WARNING
-pessimistic dependency on #{dep} may be overly strict
- if #{dep.name} is semantically versioned, use:
- add_#{dep.type}_dependency '#{dep.name}', '~> #{base.join '.'}', '>= #{dep_version}'
- WARNING
- end
-
- open_ended = dep.requirement.requirements.all? do |op, version|
- not version.prerelease? and (op == '>' or op == '>=')
- end
-
- if open_ended then
- op, dep_version = dep.requirement.requirements.first
-
- base = dep_version.segments.first 2
-
- bugfix = if op == '>' then
- ", '> #{dep_version}'"
- elsif op == '>=' and base != dep_version.segments then
- ", '>= #{dep_version}'"
- end
-
- warning <<-WARNING
-open-ended dependency on #{dep} is not recommended
- if #{dep.name} is semantically versioned, use:
- add_#{dep.type}_dependency '#{dep.name}', '~> #{base.join '.'}'#{bugfix}
- WARNING
- end
- end
- end
-
- ##
- # Checks to see if the files to be packaged are world-readable.
-
- def validate_permissions
- return if Gem.win_platform?
-
- files.each do |file|
- next if File.stat(file).mode & 0444 == 0444
- warning "#{file} is not world-readable"
- end
-
- executables.each do |name|
- exec = File.join @bindir, name
- next if File.stat(exec).executable?
- warning "#{exec} is not executable"
- end
- end
-
- ##
- # Set the version to +version+, potentially also setting
- # required_rubygems_version if +version+ indicates it is a
- # prerelease.
-
- def version= version
- @version = Gem::Version.create(version)
- self.required_rubygems_version = '> 1.3.1' if @version.prerelease?
- invalidate_memoized_attributes
-
- return @version
- end
-
- def stubbed?
- false
- end
-
- def yaml_initialize(tag, vals) # :nodoc:
- vals.each do |ivar, val|
- case ivar
- when "date"
- # Force Date to go through the extra coerce logic in date=
- self.date = val.untaint
- else
- instance_variable_set "@#{ivar}", val.untaint
- end
- end
-
- @original_platform = @platform # for backwards compatibility
- self.platform = Gem::Platform.new @platform
- end
-
- ##
- # Reset nil attributes to their default values to make the spec valid
-
- def reset_nil_attributes_to_default
- nil_attributes = self.class.non_nil_attributes.find_all do |name|
- !instance_variable_defined?("@#{name}") || instance_variable_get("@#{name}").nil?
- end
-
- nil_attributes.each do |attribute|
- default = self.default_value attribute
-
- value = case default
- when Time, Numeric, Symbol, true, false, nil then default
- else default.dup
- end
-
- instance_variable_set "@#{attribute}", value
- end
-
- @installed_by_version ||= nil
- end
-
- def warning statement # :nodoc:
- @warnings += 1
-
- alert_warning statement
- end
-
- extend Gem::Deprecate
-
- # TODO:
- # deprecate :has_rdoc, :none, 2011, 10
- # deprecate :has_rdoc?, :none, 2011, 10
- # deprecate :has_rdoc=, :none, 2011, 10
- # deprecate :default_executable, :none, 2011, 10
- # deprecate :default_executable=, :none, 2011, 10
- # deprecate :file_name, :cache_file, 2011, 10
- # deprecate :full_gem_path, :cache_file, 2011, 10
-end
-
-# DOC: What is this and why is it here, randomly, at the end of this file?
-Gem.clear_paths
diff --git a/ruby_2_2/lib/rubygems/ssl_certs/.document b/ruby_2_2/lib/rubygems/ssl_certs/.document
deleted file mode 100644
index fb66f13c33..0000000000
--- a/ruby_2_2/lib/rubygems/ssl_certs/.document
+++ /dev/null
@@ -1 +0,0 @@
-# Ignore all files in this directory
diff --git a/ruby_2_2/lib/rubygems/ssl_certs/AddTrustExternalCARoot-2048.pem b/ruby_2_2/lib/rubygems/ssl_certs/AddTrustExternalCARoot-2048.pem
deleted file mode 100644
index 20585f1c01..0000000000
--- a/ruby_2_2/lib/rubygems/ssl_certs/AddTrustExternalCARoot-2048.pem
+++ /dev/null
@@ -1,25 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIENjCCAx6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBvMQswCQYDVQQGEwJTRTEU
-MBIGA1UEChMLQWRkVHJ1c3QgQUIxJjAkBgNVBAsTHUFkZFRydXN0IEV4dGVybmFs
-IFRUUCBOZXR3b3JrMSIwIAYDVQQDExlBZGRUcnVzdCBFeHRlcm5hbCBDQSBSb290
-MB4XDTAwMDUzMDEwNDgzOFoXDTIwMDUzMDEwNDgzOFowbzELMAkGA1UEBhMCU0Ux
-FDASBgNVBAoTC0FkZFRydXN0IEFCMSYwJAYDVQQLEx1BZGRUcnVzdCBFeHRlcm5h
-bCBUVFAgTmV0d29yazEiMCAGA1UEAxMZQWRkVHJ1c3QgRXh0ZXJuYWwgQ0EgUm9v
-dDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALf3GjPm8gAELTngTlvt
-H7xsD821+iO2zt6bETOXpClMfZOfvUq8k+0DGuOPz+VtUFrWlymUWoCwSXrbLpX9
-uMq/NzgtHj6RQa1wVsfwTz/oMp50ysiQVOnGXw94nZpAPA6sYapeFI+eh6FqUNzX
-mk6vBbOmcZSccbNQYArHE504B4YCqOmoaSYYkKtMsE8jqzpPhNjfzp/haW+710LX
-a0Tkx63ubUFfclpxCDezeWWkWaCUN/cALw3CknLa0Dhy2xSoRcRdKn23tNbE7qzN
-E0S3ySvdQwAl+mG5aWpYIxG3pzOPVnVZ9c0p10a3CitlttNCbxWyuHv77+ldU9U0
-WicCAwEAAaOB3DCB2TAdBgNVHQ4EFgQUrb2YejS0Jvf6xCZU7wO94CTLVBowCwYD
-VR0PBAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wgZkGA1UdIwSBkTCBjoAUrb2YejS0
-Jvf6xCZU7wO94CTLVBqhc6RxMG8xCzAJBgNVBAYTAlNFMRQwEgYDVQQKEwtBZGRU
-cnVzdCBBQjEmMCQGA1UECxMdQWRkVHJ1c3QgRXh0ZXJuYWwgVFRQIE5ldHdvcmsx
-IjAgBgNVBAMTGUFkZFRydXN0IEV4dGVybmFsIENBIFJvb3SCAQEwDQYJKoZIhvcN
-AQEFBQADggEBALCb4IUlwtYj4g+WBpKdQZic2YR5gdkeWxQHIzZlj7DYd7usQWxH
-YINRsPkyPef89iYTx4AWpb9a/IfPeHmJIZriTAcKhjW88t5RxNKWt9x+Tu5w/Rw5
-6wwCURQtjr0W4MHfRnXnJK3s9EK0hZNwEGe6nQY1ShjTK3rMUUKhemPR5ruhxSvC
-Nr4TDea9Y355e6cJDUCrat2PisP29owaQgVR1EX1n6diIWgVIEM8med8vSTYqZEX
-c4g/VhsxOBi0cQ+azcgOno4uG+GMmIPLHzHxREzGBHNJdmAPx/i9F4BrLunMTA5a
-mnkPIAou1Z5jJh5VkpTYghdae9C8x49OhgQ=
------END CERTIFICATE-----
diff --git a/ruby_2_2/lib/rubygems/ssl_certs/AddTrustExternalCARoot.pem b/ruby_2_2/lib/rubygems/ssl_certs/AddTrustExternalCARoot.pem
deleted file mode 100644
index 6fbdf52b17..0000000000
--- a/ruby_2_2/lib/rubygems/ssl_certs/AddTrustExternalCARoot.pem
+++ /dev/null
@@ -1,32 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIFdDCCBFygAwIBAgIQJ2buVutJ846r13Ci/ITeIjANBgkqhkiG9w0BAQwFADBv
-MQswCQYDVQQGEwJTRTEUMBIGA1UEChMLQWRkVHJ1c3QgQUIxJjAkBgNVBAsTHUFk
-ZFRydXN0IEV4dGVybmFsIFRUUCBOZXR3b3JrMSIwIAYDVQQDExlBZGRUcnVzdCBF
-eHRlcm5hbCBDQSBSb290MB4XDTAwMDUzMDEwNDgzOFoXDTIwMDUzMDEwNDgzOFow
-gYUxCzAJBgNVBAYTAkdCMRswGQYDVQQIExJHcmVhdGVyIE1hbmNoZXN0ZXIxEDAO
-BgNVBAcTB1NhbGZvcmQxGjAYBgNVBAoTEUNPTU9ETyBDQSBMaW1pdGVkMSswKQYD
-VQQDEyJDT01PRE8gUlNBIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIICIjANBgkq
-hkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAkehUktIKVrGsDSTdxc9EZ3SZKzejfSNw
-AHG8U9/E+ioSj0t/EFa9n3Byt2F/yUsPF6c947AEYe7/EZfH9IY+Cvo+XPmT5jR6
-2RRr55yzhaCCenavcZDX7P0N+pxs+t+wgvQUfvm+xKYvT3+Zf7X8Z0NyvQwA1onr
-ayzT7Y+YHBSrfuXjbvzYqOSSJNpDa2K4Vf3qwbxstovzDo2a5JtsaZn4eEgwRdWt
-4Q08RWD8MpZRJ7xnw8outmvqRsfHIKCxH2XeSAi6pE6p8oNGN4Tr6MyBSENnTnIq
-m1y9TBsoilwie7SrmNnu4FGDwwlGTm0+mfqVF9p8M1dBPI1R7Qu2XK8sYxrfV8g/
-vOldxJuvRZnio1oktLqpVj3Pb6r/SVi+8Kj/9Lit6Tf7urj0Czr56ENCHonYhMsT
-8dm74YlguIwoVqwUHZwK53Hrzw7dPamWoUi9PPevtQ0iTMARgexWO/bTouJbt7IE
-IlKVgJNp6I5MZfGRAy1wdALqi2cVKWlSArvX31BqVUa/oKMoYX9w0MOiqiwhqkfO
-KJwGRXa/ghgntNWutMtQ5mv0TIZxMOmm3xaG4Nj/QN370EKIf6MzOi5cHkERgWPO
-GHFrK+ymircxXDpqR+DDeVnWIBqv8mqYqnK8V0rSS527EPywTEHl7R09XiidnMy/
-s1Hap0flhFMCAwEAAaOB9DCB8TAfBgNVHSMEGDAWgBStvZh6NLQm9/rEJlTvA73g
-JMtUGjAdBgNVHQ4EFgQUu69+Aj36pvE8hI6t7jiY7NkyMtQwDgYDVR0PAQH/BAQD
-AgGGMA8GA1UdEwEB/wQFMAMBAf8wEQYDVR0gBAowCDAGBgRVHSAAMEQGA1UdHwQ9
-MDswOaA3oDWGM2h0dHA6Ly9jcmwudXNlcnRydXN0LmNvbS9BZGRUcnVzdEV4dGVy
-bmFsQ0FSb290LmNybDA1BggrBgEFBQcBAQQpMCcwJQYIKwYBBQUHMAGGGWh0dHA6
-Ly9vY3NwLnVzZXJ0cnVzdC5jb20wDQYJKoZIhvcNAQEMBQADggEBAGS/g/FfmoXQ
-zbihKVcN6Fr30ek+8nYEbvFScLsePP9NDXRqzIGCJdPDoCpdTPW6i6FtxFQJdcfj
-Jw5dhHk3QBN39bSsHNA7qxcS1u80GH4r6XnTq1dFDK8o+tDb5VCViLvfhVdpfZLY
-Uspzgb8c8+a4bmYRBbMelC1/kZWSWfFMzqORcUx8Rww7Cxn2obFshj5cqsQugsv5
-B5a6SE2Q8pTIqXOi6wZ7I53eovNNVZ96YUWYGGjHXkBrI/V5eu+MtWuLt29G9Hvx
-PUsE2JOAWVrgQSQdso8VYFhH2+9uRv0V9dlfmrPb2LjkQLPNlzmuhbsdjrzch5vR
-pu/xO28QOG8=
------END CERTIFICATE-----
diff --git a/ruby_2_2/lib/rubygems/ssl_certs/Class3PublicPrimaryCertificationAuthority.pem b/ruby_2_2/lib/rubygems/ssl_certs/Class3PublicPrimaryCertificationAuthority.pem
deleted file mode 100644
index 87676acf5f..0000000000
--- a/ruby_2_2/lib/rubygems/ssl_certs/Class3PublicPrimaryCertificationAuthority.pem
+++ /dev/null
@@ -1,14 +0,0 @@
------BEGIN CERTIFICATE-----
-MIICPDCCAaUCEHC65B0Q2Sk0tjjKewPMur8wDQYJKoZIhvcNAQECBQAwXzELMAkG
-A1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFz
-cyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2
-MDEyOTAwMDAwMFoXDTI4MDgwMTIzNTk1OVowXzELMAkGA1UEBhMCVVMxFzAVBgNV
-BAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAzIFB1YmxpYyBQcmlt
-YXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGfMA0GCSqGSIb3DQEBAQUAA4GN
-ADCBiQKBgQDJXFme8huKARS0EN8EQNvjV69qRUCPhAwL0TPZ2RHP7gJYHyX3KqhE
-BarsAx94f56TuZoAqiN91qyFomNFx3InzPRMxnVx0jnvT0Lwdd8KkMaOIG+YD/is
-I19wKTakyYbnsZogy1Olhec9vn2a/iRFM9x2Fe0PonFkTGUugWhFpwIDAQABMA0G
-CSqGSIb3DQEBAgUAA4GBALtMEivPLCYATxQT3ab7/AoRhIzzKBxnki98tsX63/Do
-lbwdj2wsqFHMc9ikwFPwTtYmwHYBV4GSXiHx0bH/59AhWM1pF+NEHJwZRDmJXNyc
-AA9WjQKZ7aKQRUzkuxCkPfAyAw7xzvjoyVGM5mKf5p/AfbdynMk2OmufTqj/ZA1k
------END CERTIFICATE-----
diff --git a/ruby_2_2/lib/rubygems/ssl_certs/DigiCertHighAssuranceEVRootCA.pem b/ruby_2_2/lib/rubygems/ssl_certs/DigiCertHighAssuranceEVRootCA.pem
deleted file mode 100644
index 9e6810ab70..0000000000
--- a/ruby_2_2/lib/rubygems/ssl_certs/DigiCertHighAssuranceEVRootCA.pem
+++ /dev/null
@@ -1,23 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBs
-MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
-d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5j
-ZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAwMFoXDTMxMTExMDAwMDAwMFowbDEL
-MAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3
-LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFuY2Ug
-RVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm
-+9S75S0tMqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTW
-PNt0OKRKzE0lgvdKpVMSOO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEM
-xChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFB
-Ik5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQNAQTXKFx01p8VdteZOE3
-hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUeh10aUAsg
-EsxBu24LUTi4S8sCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQF
-MAMBAf8wHQYDVR0OBBYEFLE+w2kD+L9HAdSYJhoIAu9jZCvDMB8GA1UdIwQYMBaA
-FLE+w2kD+L9HAdSYJhoIAu9jZCvDMA0GCSqGSIb3DQEBBQUAA4IBAQAcGgaX3Nec
-nzyIZgYIVyHbIUf4KmeqvxgydkAQV8GK83rZEWWONfqe/EW1ntlMMUu4kehDLI6z
-eM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFpmyPInngiK3BD41VHMWEZ71jF
-hS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkKmNEVX58Svnw2
-Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe
-vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep
-+OkuE6N36B9K
------END CERTIFICATE-----
diff --git a/ruby_2_2/lib/rubygems/ssl_certs/EntrustnetSecureServerCertificationAuthority.pem b/ruby_2_2/lib/rubygems/ssl_certs/EntrustnetSecureServerCertificationAuthority.pem
deleted file mode 100644
index 4b8939ccba..0000000000
--- a/ruby_2_2/lib/rubygems/ssl_certs/EntrustnetSecureServerCertificationAuthority.pem
+++ /dev/null
@@ -1,28 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIE2DCCBEGgAwIBAgIEN0rSQzANBgkqhkiG9w0BAQUFADCBwzELMAkGA1UEBhMC
-VVMxFDASBgNVBAoTC0VudHJ1c3QubmV0MTswOQYDVQQLEzJ3d3cuZW50cnVzdC5u
-ZXQvQ1BTIGluY29ycC4gYnkgcmVmLiAobGltaXRzIGxpYWIuKTElMCMGA1UECxMc
-KGMpIDE5OTkgRW50cnVzdC5uZXQgTGltaXRlZDE6MDgGA1UEAxMxRW50cnVzdC5u
-ZXQgU2VjdXJlIFNlcnZlciBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05OTA1
-MjUxNjA5NDBaFw0xOTA1MjUxNjM5NDBaMIHDMQswCQYDVQQGEwJVUzEUMBIGA1UE
-ChMLRW50cnVzdC5uZXQxOzA5BgNVBAsTMnd3dy5lbnRydXN0Lm5ldC9DUFMgaW5j
-b3JwLiBieSByZWYuIChsaW1pdHMgbGlhYi4pMSUwIwYDVQQLExwoYykgMTk5OSBF
-bnRydXN0Lm5ldCBMaW1pdGVkMTowOAYDVQQDEzFFbnRydXN0Lm5ldCBTZWN1cmUg
-U2VydmVyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGdMA0GCSqGSIb3DQEBAQUA
-A4GLADCBhwKBgQDNKIM0VBuJ8w+vN5Ex/68xYMmo6LIQaO2f55M28Qpku0f1BBc/
-I0dNxScZgSYMVHINiC3ZH5oSn7yzcdOAGT9HZnuMNSjSuQrfJNqc1lB5gXpa0zf3
-wkrYKZImZNHkmGw6AIr1NJtl+O3jEP/9uElY3KDegjlrgbEWGWG5VLbmQwIBA6OC
-AdcwggHTMBEGCWCGSAGG+EIBAQQEAwIABzCCARkGA1UdHwSCARAwggEMMIHeoIHb
-oIHYpIHVMIHSMQswCQYDVQQGEwJVUzEUMBIGA1UEChMLRW50cnVzdC5uZXQxOzA5
-BgNVBAsTMnd3dy5lbnRydXN0Lm5ldC9DUFMgaW5jb3JwLiBieSByZWYuIChsaW1p
-dHMgbGlhYi4pMSUwIwYDVQQLExwoYykgMTk5OSBFbnRydXN0Lm5ldCBMaW1pdGVk
-MTowOAYDVQQDEzFFbnRydXN0Lm5ldCBTZWN1cmUgU2VydmVyIENlcnRpZmljYXRp
-b24gQXV0aG9yaXR5MQ0wCwYDVQQDEwRDUkwxMCmgJ6AlhiNodHRwOi8vd3d3LmVu
-dHJ1c3QubmV0L0NSTC9uZXQxLmNybDArBgNVHRAEJDAigA8xOTk5MDUyNTE2MDk0
-MFqBDzIwMTkwNTI1MTYwOTQwWjALBgNVHQ8EBAMCAQYwHwYDVR0jBBgwFoAU8Bdi
-E1U9s/8KAGv7UISX8+1i0BowHQYDVR0OBBYEFPAXYhNVPbP/CgBr+1CEl/PtYtAa
-MAwGA1UdEwQFMAMBAf8wGQYJKoZIhvZ9B0EABAwwChsEVjQuMAMCBJAwDQYJKoZI
-hvcNAQEFBQADgYEAkNwwAvpkdMKnCqV8IY00F6j7Rw7/JXyNEwr75Ji174z4xRAN
-95K+8cPV1ZVqBLssziY2ZcgxxufuP+NXdYR6Ee9GTxj005i7qIcyunL2POI9n9cd
-2cNgQ4xYDiKWL2KjLB+6rQXvqzJ4h6BUcxm1XAX5Uj5tLUUL9wqT6u0G+bI=
------END CERTIFICATE-----
diff --git a/ruby_2_2/lib/rubygems/ssl_certs/GeoTrustGlobalCA.pem b/ruby_2_2/lib/rubygems/ssl_certs/GeoTrustGlobalCA.pem
deleted file mode 100644
index bcb2529761..0000000000
--- a/ruby_2_2/lib/rubygems/ssl_certs/GeoTrustGlobalCA.pem
+++ /dev/null
@@ -1,20 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIDVDCCAjygAwIBAgIDAjRWMA0GCSqGSIb3DQEBBQUAMEIxCzAJBgNVBAYTAlVT
-MRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMRswGQYDVQQDExJHZW9UcnVzdCBHbG9i
-YWwgQ0EwHhcNMDIwNTIxMDQwMDAwWhcNMjIwNTIxMDQwMDAwWjBCMQswCQYDVQQG
-EwJVUzEWMBQGA1UEChMNR2VvVHJ1c3QgSW5jLjEbMBkGA1UEAxMSR2VvVHJ1c3Qg
-R2xvYmFsIENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2swYYzD9
-9BcjGlZ+W988bDjkcbd4kdS8odhM+KhDtgPpTSEHCIjaWC9mOSm9BXiLnTjoBbdq
-fnGk5sRgprDvgOSJKA+eJdbtg/OtppHHmMlCGDUUna2YRpIuT8rxh0PBFpVXLVDv
-iS2Aelet8u5fa9IAjbkU+BQVNdnARqN7csiRv8lVK83Qlz6cJmTM386DGXHKTubU
-1XupGc1V3sjs0l44U+VcT4wt/lAjNvxm5suOpDkZALeVAjmRCw7+OC7RHQWa9k0+
-bw8HHa8sHo9gOeL6NlMTOdReJivbPagUvTLrGAMoUgRx5aszPeE4uwc2hGKceeoW
-MPRfwCvocWvk+QIDAQABo1MwUTAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBTA
-ephojYn7qwVkDBF9qn1luMrMTjAfBgNVHSMEGDAWgBTAephojYn7qwVkDBF9qn1l
-uMrMTjANBgkqhkiG9w0BAQUFAAOCAQEANeMpauUvXVSOKVCUn5kaFOSPeCpilKIn
-Z57QzxpeR+nBsqTP3UEaBU6bS+5Kb1VSsyShNwrrZHYqLizz/Tt1kL/6cdjHPTfS
-tQWVYrmm3ok9Nns4d0iXrKYgjy6myQzCsplFAMfOEVEiIuCl6rYVSAlk6l5PdPcF
-PseKUgzbFbS9bZvlxrFUaKnjaZC2mqUPuLk/IH2uSrW4nOQdtqvmlKXBx4Ot2/Un
-hw4EbNX/3aBd7YdStysVAq45pmp06drE57xNNB6pXE0zX5IJL4hmXXeXxx12E6nV
-5fEWCRE11azbJHFwLJhWC9kXtNHjUStedejV0NxPNO3CBWaAocvmMw==
------END CERTIFICATE-----
diff --git a/ruby_2_2/lib/rubygems/ssl_certs/GlobalSignRootCA.pem b/ruby_2_2/lib/rubygems/ssl_certs/GlobalSignRootCA.pem
deleted file mode 100644
index f4ce4ca43d..0000000000
--- a/ruby_2_2/lib/rubygems/ssl_certs/GlobalSignRootCA.pem
+++ /dev/null
@@ -1,21 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIDdTCCAl2gAwIBAgILBAAAAAABFUtaw5QwDQYJKoZIhvcNAQEFBQAwVzELMAkG
-A1UEBhMCQkUxGTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jv
-b3QgQ0ExGzAZBgNVBAMTEkdsb2JhbFNpZ24gUm9vdCBDQTAeFw05ODA5MDExMjAw
-MDBaFw0yODAxMjgxMjAwMDBaMFcxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9i
-YWxTaWduIG52LXNhMRAwDgYDVQQLEwdSb290IENBMRswGQYDVQQDExJHbG9iYWxT
-aWduIFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDaDuaZ
-jc6j40+Kfvvxi4Mla+pIH/EqsLmVEQS98GPR4mdmzxzdzxtIK+6NiY6arymAZavp
-xy0Sy6scTHAHoT0KMM0VjU/43dSMUBUc71DuxC73/OlS8pF94G3VNTCOXkNz8kHp
-1Wrjsok6Vjk4bwY8iGlbKk3Fp1S4bInMm/k8yuX9ifUSPJJ4ltbcdG6TRGHRjcdG
-snUOhugZitVtbNV4FpWi6cgKOOvyJBNPc1STE4U6G7weNLWLBYy5d4ux2x8gkasJ
-U26Qzns3dLlwR5EiUWMWea6xrkEmCMgZK9FGqkjWZCrXgzT/LCrBbBlDSgeF59N8
-9iFo7+ryUp9/k5DPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8E
-BTADAQH/MB0GA1UdDgQWBBRge2YaRQ2XyolQL30EzTSo//z9SzANBgkqhkiG9w0B
-AQUFAAOCAQEA1nPnfE920I2/7LqivjTFKDK1fPxsnCwrvQmeU79rXqoRSLblCKOz
-yj1hTdNGCbM+w6DjY1Ub8rrvrTnhQ7k4o+YviiY776BQVvnGCv04zcQLcFGUl5gE
-38NflNUVyRRBnMRddWQVDf9VMOyGj/8N7yy5Y0b2qvzfvGn9LhJIZJrglfCm7ymP
-AbEVtQwdpf5pLGkkeB6zpxxxYu7KyJesF12KwvhHhm4qxFYxldBniYUr+WymXUad
-DKqC5JlR3XC321Y9YeRq4VzW9v493kHMB65jUr9TU/Qr6cf9tveCX4XSQRjbgbME
-HMUfpIBvFSDJ3gyICh3WZlXi/EjJKSZp4A==
------END CERTIFICATE-----
diff --git a/ruby_2_2/lib/rubygems/stub_specification.rb b/ruby_2_2/lib/rubygems/stub_specification.rb
deleted file mode 100644
index b184d29d5e..0000000000
--- a/ruby_2_2/lib/rubygems/stub_specification.rb
+++ /dev/null
@@ -1,196 +0,0 @@
-##
-# Gem::StubSpecification reads the stub: line from the gemspec. This prevents
-# us having to eval the entire gemspec in order to find out certain
-# information.
-
-class Gem::StubSpecification < Gem::BasicSpecification
- # :nodoc:
- PREFIX = "# stub: "
-
- OPEN_MODE = # :nodoc:
- if Object.const_defined? :Encoding then
- 'r:UTF-8:-'
- else
- 'r'
- end
-
- class StubLine # :nodoc: all
- attr_reader :parts
-
- def initialize(data)
- @parts = data[PREFIX.length..-1].split(" ")
- end
-
- def name
- @parts[0]
- end
-
- def version
- Gem::Version.new @parts[1]
- end
-
- def platform
- Gem::Platform.new @parts[2]
- end
-
- def require_paths
- @parts[3..-1].join(" ").split("\0")
- end
- end
-
- def initialize(filename)
- self.loaded_from = filename
- @data = nil
- @extensions = nil
- @name = nil
- @spec = nil
- end
-
- ##
- # True when this gem has been activated
-
- def activated?
- @activated ||=
- begin
- loaded = Gem.loaded_specs[name]
- loaded && loaded.version == version
- end
- end
-
- def build_extensions # :nodoc:
- return if default_gem?
- return if extensions.empty?
-
- to_spec.build_extensions
- end
-
- ##
- # If the gemspec contains a stubline, returns a StubLine instance. Otherwise
- # returns the full Gem::Specification.
-
- def data
- unless @data
- @extensions = []
-
- open loaded_from, OPEN_MODE do |file|
- begin
- file.readline # discard encoding line
- stubline = file.readline.chomp
- if stubline.start_with?(PREFIX) then
- @data = StubLine.new stubline
-
- @extensions = $'.split "\0" if
- /\A#{PREFIX}/ =~ file.readline.chomp
- end
- rescue EOFError
- end
- end
- end
-
- @data ||= to_spec
- end
-
- private :data
-
- ##
- # Extensions for this gem
-
- def extensions
- return @extensions if @extensions
-
- data # load
-
- @extensions
- end
-
- ##
- # If a gem has a stub specification it doesn't need to bother with
- # compatibility with original_name gems. It was installed with the
- # normalized name.
-
- def find_full_gem_path # :nodoc:
- path = File.expand_path File.join gems_dir, full_name
- path.untaint
- path
- end
-
- ##
- # Full paths in the gem to add to <code>$LOAD_PATH</code> when this gem is
- # activated.
-
- def full_require_paths
- @require_paths ||= data.require_paths
-
- super
- end
-
- def missing_extensions?
- return false if default_gem?
- return false if extensions.empty?
-
- to_spec.missing_extensions?
- end
-
- ##
- # Name of the gem
-
- def name
- @name ||= data.name
- end
-
- ##
- # Platform of the gem
-
- def platform
- @platform ||= data.platform
- end
-
- ##
- # Require paths of the gem
-
- def require_paths
- @require_paths ||= data.require_paths
-
- super
- end
-
- ##
- # The full Gem::Specification for this gem, loaded from evalling its gemspec
-
- def to_spec
- @spec ||= if @data then
- Gem.loaded_specs.values.find { |spec|
- spec.name == name and spec.version == version
- }
- end
-
- @spec ||= Gem::Specification.load(loaded_from)
- @spec.ignored = @ignored if instance_variable_defined? :@ignored
-
- @spec
- end
-
- ##
- # Is this StubSpecification valid? i.e. have we found a stub line, OR does
- # the filename contain a valid gemspec?
-
- def valid?
- data
- end
-
- ##
- # Version of the gem
-
- def version
- @version ||= data.version
- end
-
- ##
- # Is there a stub line present for this StubSpecification?
-
- def stubbed?
- data.is_a? StubLine
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/syck_hack.rb b/ruby_2_2/lib/rubygems/syck_hack.rb
deleted file mode 100644
index 92179abb53..0000000000
--- a/ruby_2_2/lib/rubygems/syck_hack.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-# :stopdoc:
-
-# Hack to handle syck's DefaultKey bug
-#
-# This file is always loaded AFTER either syck or psych are already
-# loaded. It then looks at what constants are available and creates
-# a consistent view on all rubys.
-#
-# All this is so that there is always a YAML::Syck::DefaultKey
-# class no matter if the full yaml library has loaded or not.
-#
-
-module YAML # :nodoc:
- # In newer 1.9.2, there is a Syck toplevel constant instead of it
- # being underneath YAML. If so, reference it back under YAML as
- # well.
- if defined? ::Syck
- # for tests that change YAML::ENGINE
- # 1.8 does not support the second argument to const_defined?
- remove_const :Syck rescue nil
-
- Syck = ::Syck
-
- # JRuby's "Syck" is called "Yecht"
- elsif defined? YAML::Yecht
- Syck = YAML::Yecht
-
- # Otherwise, if there is no YAML::Syck, then we've got just psych
- # loaded, so lets define a stub for DefaultKey.
- elsif !defined? YAML::Syck
- module Syck
- class DefaultKey # :nodoc:
- end
- end
- end
-
- # Now that we've got something that is always here, define #to_s
- # so when code tries to use this, it at least just shows up like it
- # should.
- module Syck
- class DefaultKey
- remove_method :to_s rescue nil
-
- def to_s
- '='
- end
- end
- end
-
- SyntaxError = Error unless defined? SyntaxError
-end
-
-# Sometime in the 1.9 dev cycle, the Syck constant was moved from under YAML
-# to be a toplevel constant. So gemspecs created under these versions of Syck
-# will have references to Syck::DefaultKey.
-#
-# So we need to be sure that we reference Syck at the toplevel too so that
-# we can always load these kind of gemspecs.
-#
-if !defined?(Syck)
- Syck = YAML::Syck
-end
-
-# Now that we've got Syck setup in all the right places, store
-# a reference to the DefaultKey class inside Gem. We do this so that
-# if later on YAML, etc are redefined, we've still got a consistent
-# place to find the DefaultKey class for comparison.
-
-module Gem
- # for tests that change YAML::ENGINE
- remove_const :SyckDefaultKey if const_defined? :SyckDefaultKey
-
- SyckDefaultKey = YAML::Syck::DefaultKey
-end
-
-# :startdoc:
diff --git a/ruby_2_2/lib/rubygems/test_case.rb b/ruby_2_2/lib/rubygems/test_case.rb
deleted file mode 100644
index cd83453e14..0000000000
--- a/ruby_2_2/lib/rubygems/test_case.rb
+++ /dev/null
@@ -1,1441 +0,0 @@
-# TODO: $SAFE = 1
-
-begin
- gem 'minitest', '~> 4.0'
-rescue NoMethodError, Gem::LoadError
- # for ruby tests
-end
-
-if defined? Gem::QuickLoader
- Gem::QuickLoader.load_full_rubygems_library
-else
- require 'rubygems'
-end
-
-begin
- gem 'minitest'
-rescue Gem::LoadError
-end
-
-# We have to load these up front because otherwise we'll try to load
-# them while we're testing rubygems, and thus we can't actually load them.
-unless Gem::Dependency.new('rdoc', '>= 3.10').matching_specs.empty?
- gem 'rdoc'
- gem 'json'
-end
-
-require 'minitest/autorun'
-
-require 'rubygems/deprecate'
-
-require 'fileutils'
-require 'pathname'
-require 'pp'
-require 'rubygems/package'
-require 'shellwords'
-require 'tmpdir'
-require 'uri'
-require 'zlib'
-
-Gem.load_yaml
-
-require 'rubygems/mock_gem_ui'
-
-module Gem
-
- ##
- # Allows setting the gem path searcher. This method is available when
- # requiring 'rubygems/test_case'
-
- def self.searcher=(searcher)
- @searcher = searcher
- end
-
- ##
- # Allows toggling Windows behavior. This method is available when requiring
- # 'rubygems/test_case'
-
- def self.win_platform=(val)
- @@win_platform = val
- end
-
- ##
- # Allows setting path to Ruby. This method is available when requiring
- # 'rubygems/test_case'
-
- def self.ruby= ruby
- @ruby = ruby
- end
-
- ##
- # When rubygems/test_case is required the default user interaction is a
- # MockGemUi.
-
- module DefaultUserInteraction
- @ui = Gem::MockGemUi.new
- end
-end
-
-##
-# RubyGemTestCase provides a variety of methods for testing rubygems and
-# gem-related behavior in a sandbox. Through RubyGemTestCase you can install
-# and uninstall gems, fetch remote gems through a stub fetcher and be assured
-# your normal set of gems is not affected.
-#
-# Tests are always run at a safe level of 1.
-
-class Gem::TestCase < MiniTest::Unit::TestCase
-
- attr_accessor :fetcher # :nodoc:
-
- attr_accessor :gem_repo # :nodoc:
-
- attr_accessor :uri # :nodoc:
-
- def assert_activate expected, *specs
- specs.each do |spec|
- case spec
- when String then
- Gem::Specification.find_by_name(spec).activate
- when Gem::Specification then
- spec.activate
- else
- flunk spec.inspect
- end
- end
-
- loaded = Gem.loaded_specs.values.map(&:full_name)
-
- assert_equal expected.sort, loaded.sort if expected
- end
-
- # TODO: move to minitest
- def assert_path_exists path, msg = nil
- msg = message(msg) { "Expected path '#{path}' to exist" }
- assert File.exist?(path), msg
- end
-
- ##
- # Sets the ENABLE_SHARED entry in RbConfig::CONFIG to +value+ and restores
- # the original value when the block ends
-
- def enable_shared value
- enable_shared = RbConfig::CONFIG['ENABLE_SHARED']
- RbConfig::CONFIG['ENABLE_SHARED'] = value
-
- yield
- ensure
- if enable_shared then
- RbConfig::CONFIG['enable_shared'] = enable_shared
- else
- RbConfig::CONFIG.delete 'enable_shared'
- end
- end
-
- # TODO: move to minitest
- def refute_path_exists path, msg = nil
- msg = message(msg) { "Expected path '#{path}' to not exist" }
- refute File.exist?(path), msg
- end
-
- def scan_make_command_lines(output)
- output.scan(/^#{Regexp.escape make_command}(?:[[:blank:]].*)?$/)
- end
-
- def parse_make_command_line(line)
- command, *args = line.shellsplit
-
- targets = []
- macros = {}
-
- args.each do |arg|
- case arg
- when /\A(\w+)=/
- macros[$1] = $'
- else
- targets << arg
- end
- end
-
- targets << '' if targets.empty?
-
- {
- :command => command,
- :targets => targets,
- :macros => macros,
- }
- end
-
- def assert_contains_make_command(target, output, msg = nil)
- if output.match(/\n/)
- msg = message(msg) {
- 'Expected output containing make command "%s": %s' % [
- ('%s %s' % [make_command, target]).rstrip,
- output.inspect
- ]
- }
- else
- msg = message(msg) {
- 'Expected make command "%s": %s' % [
- ('%s %s' % [make_command, target]).rstrip,
- output.inspect
- ]
- }
- end
-
- assert scan_make_command_lines(output).any? { |line|
- make = parse_make_command_line(line)
-
- if make[:targets].include?(target)
- yield make, line if block_given?
- true
- else
- false
- end
- }, msg
- end
-
- include Gem::DefaultUserInteraction
-
- undef_method :default_test if instance_methods.include? 'default_test' or
- instance_methods.include? :default_test
-
- @@project_dir = Dir.pwd.untaint unless defined?(@@project_dir)
-
- @@initial_reset = false
-
- ##
- # #setup prepares a sandboxed location to install gems. All installs are
- # directed to a temporary directory. All install plugins are removed.
- #
- # If the +RUBY+ environment variable is set the given path is used for
- # Gem::ruby. The local platform is set to <tt>i386-mswin32</tt> for Windows
- # or <tt>i686-darwin8.10.1</tt> otherwise.
- #
- # If the +KEEP_FILES+ environment variable is set the files will not be
- # removed from <tt>/tmp/test_rubygems_#{$$}.#{Time.now.to_i}</tt>.
-
- def setup
- super
-
- @orig_gem_home = ENV['GEM_HOME']
- @orig_gem_path = ENV['GEM_PATH']
- @orig_gem_vendor = ENV['GEM_VENDOR']
-
- ENV['GEM_VENDOR'] = nil
-
- @current_dir = Dir.pwd
- @fetcher = nil
- @ui = Gem::MockGemUi.new
-
- tmpdir = File.expand_path Dir.tmpdir
- tmpdir.untaint
-
- if ENV['KEEP_FILES'] then
- @tempdir = File.join(tmpdir, "test_rubygems_#{$$}.#{Time.now.to_i}")
- else
- @tempdir = File.join(tmpdir, "test_rubygems_#{$$}")
- end
- @tempdir.untaint
-
- FileUtils.mkdir_p @tempdir
-
- # This makes the tempdir consistent on OS X.
- # File.expand_path Dir.tmpdir #=> "/var/..."
- # Dir.chdir Dir.tmpdir do File.expand_path '.' end #=> "/private/var/..."
- # TODO use File#realpath above instead of #expand_path once 1.8 support is
- # dropped.
- Dir.chdir @tempdir do
- @tempdir = File.expand_path '.'
- @tempdir.untaint
- end
-
- # This makes the tempdir consistent on Windows.
- # Dir.tmpdir may return short path name, but Dir[Dir.tmpdir] returns long
- # path name. https://bugs.ruby-lang.org/issues/10819
- # File.expand_path or File.realpath doesn't convert path name to long path
- # name. Only Dir[] (= Dir.glob) works.
- # Short and long path name is specific to Windows filesystem.
- if win_platform?
- @tempdir = Dir[@tempdir][0]
- @tempdir.untaint
- end
-
- @gemhome = File.join @tempdir, 'gemhome'
- @userhome = File.join @tempdir, 'userhome'
- ENV["GEM_SPEC_CACHE"] = File.join @tempdir, 'spec_cache'
-
- @orig_ruby = if ENV['RUBY'] then
- ruby = Gem.ruby
- Gem.ruby = ENV['RUBY']
- ruby
- end
-
- @git = ENV['GIT'] || 'git'
-
- Gem.ensure_gem_subdirectories @gemhome
-
- @orig_LOAD_PATH = $LOAD_PATH.dup
- $LOAD_PATH.map! { |s| File.expand_path(s).untaint }
-
- Dir.chdir @tempdir
-
- @orig_ENV_HOME = ENV['HOME']
- ENV['HOME'] = @userhome
- Gem.instance_variable_set :@user_home, nil
- Gem.send :remove_instance_variable, :@ruby_version if
- Gem.instance_variables.include? :@ruby_version
-
- FileUtils.mkdir_p @gemhome
- FileUtils.mkdir_p @userhome
-
- @orig_gem_private_key_passphrase = ENV['GEM_PRIVATE_KEY_PASSPHRASE']
- ENV['GEM_PRIVATE_KEY_PASSPHRASE'] = PRIVATE_KEY_PASSPHRASE
-
- @default_dir = File.join @tempdir, 'default'
- @default_spec_dir = File.join @default_dir, "specifications", "default"
- Gem.instance_variable_set :@default_dir, @default_dir
- FileUtils.mkdir_p @default_spec_dir
-
- # We use Gem::Specification.reset the first time only so that if there
- # are unresolved deps that leak into the whole test suite, they're at least
- # reported once.
- if @@initial_reset
- Gem::Specification.unresolved_deps.clear # done to avoid cross-test warnings
- else
- @@initial_reset = true
- Gem::Specification.reset
- end
- Gem.use_paths(@gemhome)
-
- Gem::Security.reset
-
- Gem.loaded_specs.clear
- Gem.clear_default_specs
- Gem::Specification.unresolved_deps.clear
-
- Gem.configuration.verbose = true
- Gem.configuration.update_sources = true
-
- Gem::RemoteFetcher.fetcher = Gem::FakeFetcher.new
-
- @gem_repo = "http://gems.example.com/"
- @uri = URI.parse @gem_repo
- Gem.sources.replace [@gem_repo]
-
- Gem.searcher = nil
- Gem::SpecFetcher.fetcher = nil
- @orig_BASERUBY = RbConfig::CONFIG['BASERUBY']
- RbConfig::CONFIG['BASERUBY'] = RbConfig::CONFIG['ruby_install_name']
-
- @orig_arch = RbConfig::CONFIG['arch']
-
- if win_platform?
- util_set_arch 'i386-mswin32'
- else
- util_set_arch 'i686-darwin8.10.1'
- end
-
- @marshal_version = "#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}"
- end
-
- ##
- # #teardown restores the process to its original state and removes the
- # tempdir unless the +KEEP_FILES+ environment variable was set.
-
- def teardown
- $LOAD_PATH.replace @orig_LOAD_PATH if @orig_LOAD_PATH
-
- if @orig_BASERUBY
- RbConfig::CONFIG['BASERUBY'] = @orig_BASERUBY
- else
- RbConfig::CONFIG.delete('BASERUBY')
- end
- RbConfig::CONFIG['arch'] = @orig_arch
-
- if defined? Gem::RemoteFetcher then
- Gem::RemoteFetcher.fetcher = nil
- end
-
- Dir.chdir @current_dir
-
- FileUtils.rm_rf @tempdir unless ENV['KEEP_FILES']
-
- ENV['GEM_HOME'] = @orig_gem_home
- ENV['GEM_PATH'] = @orig_gem_path
- ENV['GEM_VENDOR'] = @orig_gem_vendor
-
- Gem.ruby = @orig_ruby if @orig_ruby
-
- if @orig_ENV_HOME then
- ENV['HOME'] = @orig_ENV_HOME
- else
- ENV.delete 'HOME'
- end
-
- Gem.instance_variable_set :@default_dir, nil
-
- ENV['GEM_PRIVATE_KEY_PASSPHRASE'] = @orig_gem_private_key_passphrase
-
- Gem::Specification._clear_load_cache
- end
-
- def common_installer_setup
- common_installer_teardown
-
- Gem.post_build do |installer|
- @post_build_hook_arg = installer
- true
- end
-
- Gem.post_install do |installer|
- @post_install_hook_arg = installer
- end
-
- Gem.post_uninstall do |uninstaller|
- @post_uninstall_hook_arg = uninstaller
- end
-
- Gem.pre_install do |installer|
- @pre_install_hook_arg = installer
- true
- end
-
- Gem.pre_uninstall do |uninstaller|
- @pre_uninstall_hook_arg = uninstaller
- end
- end
-
- def common_installer_teardown
- Gem.post_build_hooks.clear
- Gem.post_install_hooks.clear
- Gem.done_installing_hooks.clear
- Gem.post_reset_hooks.clear
- Gem.post_uninstall_hooks.clear
- Gem.pre_install_hooks.clear
- Gem.pre_reset_hooks.clear
- Gem.pre_uninstall_hooks.clear
- end
-
- ##
- # A git_gem is used with a gem dependencies file. The gem created here
- # has no files, just a gem specification for the given +name+ and +version+.
- #
- # Yields the +specification+ to the block, if given
-
- def git_gem name = 'a', version = 1
- have_git?
-
- directory = File.join 'git', name
- directory = File.expand_path directory
-
- git_spec = Gem::Specification.new name, version do |specification|
- yield specification if block_given?
- end
-
- FileUtils.mkdir_p directory
-
- gemspec = "#{name}.gemspec"
-
- open File.join(directory, gemspec), 'w' do |io|
- io.write git_spec.to_ruby
- end
-
- head = nil
-
- Dir.chdir directory do
- unless File.exist? '.git' then
- system @git, 'init', '--quiet'
- system @git, 'config', 'user.name', 'RubyGems Tests'
- system @git, 'config', 'user.email', 'rubygems@example'
- end
-
- system @git, 'add', gemspec
- system @git, 'commit', '-a', '-m', 'a non-empty commit message', '--quiet'
- head = Gem::Util.popen('git', 'rev-parse', 'master').strip
- end
-
- return name, git_spec.version, directory, head
- end
-
- ##
- # Skips this test unless you have a git executable
-
- def have_git?
- return if in_path? @git
-
- skip 'cannot find git executable, use GIT environment variable to set'
- end
-
- def in_path? executable # :nodoc:
- return true if %r%\A([A-Z]:|/)% =~ executable and File.exist? executable
-
- ENV['PATH'].split(File::PATH_SEPARATOR).any? do |directory|
- File.exist? File.join directory, executable
- end
- end
-
- ##
- # Builds and installs the Gem::Specification +spec+
-
- def install_gem spec, options = {}
- require 'rubygems/installer'
-
- gem = File.join @tempdir, "gems", "#{spec.full_name}.gem"
-
- unless File.exist? gem then
- use_ui Gem::MockGemUi.new do
- Dir.chdir @tempdir do
- Gem::Package.build spec
- end
- end
-
- gem = File.join(@tempdir, File.basename(spec.cache_file)).untaint
- end
-
- Gem::Installer.new(gem, options.merge({:wrappers => true})).install
- end
-
- ##
- # Builds and installs the Gem::Specification +spec+ into the user dir
-
- def install_gem_user spec
- install_gem spec, :user_install => true
- end
-
- ##
- # Uninstalls the Gem::Specification +spec+
- def uninstall_gem spec
- require 'rubygems/uninstaller'
-
- Gem::Uninstaller.new(spec.name,
- :executables => true, :user_install => true).uninstall
- end
-
- ##
- # creates a temporary directory with hax
- # TODO: deprecate and remove
-
- def create_tmpdir
- tmpdir = nil
- Dir.chdir Dir.tmpdir do tmpdir = Dir.pwd end # HACK OSX /private/tmp
- tmpdir = File.join tmpdir, "test_rubygems_#{$$}"
- FileUtils.mkdir_p tmpdir
- return tmpdir
- end
-
- ##
- # Enables pretty-print for all tests
-
- def mu_pp(obj)
- s = ''
- s = PP.pp obj, s
- s = s.force_encoding(Encoding.default_external) if defined? Encoding
- s.chomp
- end
-
- ##
- # Reads a Marshal file at +path+
-
- def read_cache(path)
- open path.dup.untaint, 'rb' do |io|
- Marshal.load io.read
- end
- end
-
- ##
- # Reads a binary file at +path+
-
- def read_binary(path)
- Gem.read_binary path
- end
-
- ##
- # Writes a binary file to +path+ which is relative to +@gemhome+
-
- def write_file(path)
- path = File.join @gemhome, path unless Pathname.new(path).absolute?
- dir = File.dirname path
- FileUtils.mkdir_p dir
-
- open path, 'wb' do |io|
- yield io if block_given?
- end
-
- path
- end
-
- def all_spec_names
- Gem::Specification.map(&:full_name)
- end
-
- ##
- # Creates a Gem::Specification with a minimum of extra work. +name+ and
- # +version+ are the gem's name and version, platform, author, email,
- # homepage, summary and description are defaulted. The specification is
- # yielded for customization.
- #
- # The gem is added to the installed gems in +@gemhome+ and the runtime.
- #
- # Use this with #write_file to build an installed gem.
-
- def quick_gem(name, version='2')
- require 'rubygems/specification'
-
- spec = Gem::Specification.new do |s|
- s.platform = Gem::Platform::RUBY
- s.name = name
- s.version = version
- s.author = 'A User'
- s.email = 'example@example.com'
- s.homepage = 'http://example.com'
- s.summary = "this is a summary"
- s.description = "This is a test description"
-
- yield(s) if block_given?
- end
-
- Gem::Specification.map # HACK: force specs to (re-)load before we write
-
- written_path = write_file spec.spec_file do |io|
- io.write spec.to_ruby_for_cache
- end
-
- spec.loaded_from = spec.loaded_from = written_path
-
- Gem::Specification.add_spec spec.for_cache
-
- return spec
- end
-
- ##
- # TODO: remove in RubyGems 3.0
-
- def quick_spec name, version = '2' # :nodoc:
- util_spec name, version
- end
-
- ##
- # Builds a gem from +spec+ and places it in <tt>File.join @gemhome,
- # 'cache'</tt>. Automatically creates files based on +spec.files+
-
- def util_build_gem(spec)
- dir = spec.gem_dir
- FileUtils.mkdir_p dir
-
- Dir.chdir dir do
- spec.files.each do |file|
- next if File.exist? file
- FileUtils.mkdir_p File.dirname(file)
- File.open file, 'w' do |fp| fp.puts "# #{file}" end
- end
-
- use_ui Gem::MockGemUi.new do
- Gem::Package.build spec
- end
-
- cache = spec.cache_file
- FileUtils.mv File.basename(cache), cache
- end
- end
-
- def util_remove_gem(spec)
- FileUtils.rm_rf spec.cache_file
- FileUtils.rm_rf spec.spec_file
- end
-
- ##
- # Removes all installed gems from +@gemhome+.
-
- def util_clear_gems
- FileUtils.rm_rf File.join(@gemhome, "gems") # TODO: use Gem::Dirs
- FileUtils.mkdir File.join(@gemhome, "gems")
- FileUtils.rm_rf File.join(@gemhome, "specifications")
- FileUtils.mkdir File.join(@gemhome, "specifications")
- Gem::Specification.reset
- end
-
- ##
- # Install the provided specs
-
- def install_specs(*specs)
- Gem::Specification.add_specs(*specs)
- Gem.searcher = nil
- end
-
- ##
- # Installs the provided default specs including writing the spec file
-
- def install_default_gems(*specs)
- install_default_specs(*specs)
-
- specs.each do |spec|
- open spec.loaded_from, 'w' do |io|
- io.write spec.to_ruby_for_cache
- end
- end
- end
-
- ##
- # Install the provided default specs
-
- def install_default_specs(*specs)
- install_specs(*specs)
- specs.each do |spec|
- Gem.register_default_spec(spec)
- end
- end
-
- def loaded_spec_names
- Gem.loaded_specs.values.map(&:full_name).sort
- end
-
- def unresolved_names
- Gem::Specification.unresolved_deps.values.map(&:to_s).sort
- end
-
- def save_loaded_features
- old_loaded_features = $LOADED_FEATURES.dup
- yield
- ensure
- $LOADED_FEATURES.replace old_loaded_features
- end
-
- ##
- # new_spec is deprecated as it is never used.
- #
- # TODO: remove in RubyGems 3.0
-
- def new_spec name, version, deps = nil, *files # :nodoc:
- require 'rubygems/specification'
-
- spec = Gem::Specification.new do |s|
- s.platform = Gem::Platform::RUBY
- s.name = name
- s.version = version
- s.author = 'A User'
- s.email = 'example@example.com'
- s.homepage = 'http://example.com'
- s.summary = "this is a summary"
- s.description = "This is a test description"
-
- Array(deps).each do |n, req|
- s.add_dependency n, (req || '>= 0')
- end
-
- s.files.push(*files) unless files.empty?
-
- yield s if block_given?
- end
-
- spec.loaded_from = spec.spec_file
-
- unless files.empty? then
- write_file spec.spec_file do |io|
- io.write spec.to_ruby_for_cache
- end
-
- util_build_gem spec
-
- cache_file = File.join @tempdir, 'gems', "#{spec.full_name}.gem"
- FileUtils.mkdir_p File.dirname cache_file
- FileUtils.mv spec.cache_file, cache_file
- FileUtils.rm spec.spec_file
- end
-
- spec
- end
-
- def new_default_spec(name, version, deps = nil, *files)
- spec = util_spec name, version, deps
-
- spec.loaded_from = File.join(@default_spec_dir, spec.spec_name)
- spec.files = files
-
- lib_dir = File.join(@tempdir, "default_gems", "lib")
- $LOAD_PATH.unshift(lib_dir)
- files.each do |file|
- rb_path = File.join(lib_dir, file)
- FileUtils.mkdir_p(File.dirname(rb_path))
- File.open(rb_path, "w") do |rb|
- rb << "# #{file}"
- end
- end
-
- spec
- end
-
- ##
- # Creates a spec with +name+, +version+. +deps+ can specify the dependency
- # or a +block+ can be given for full customization of the specification.
-
- def util_spec name, version = 2, deps = nil # :yields: specification
- raise "deps or block, not both" if deps and block_given?
-
- spec = Gem::Specification.new do |s|
- s.platform = Gem::Platform::RUBY
- s.name = name
- s.version = version
- s.author = 'A User'
- s.email = 'example@example.com'
- s.homepage = 'http://example.com'
- s.summary = "this is a summary"
- s.description = "This is a test description"
-
- yield s if block_given?
- end
-
- if deps then
- # Since Hash#each is unordered in 1.8, sort the keys and iterate that
- # way so the tests are deterministic on all implementations.
- deps.keys.sort.each do |n|
- spec.add_dependency n, (deps[n] || '>= 0')
- end
- end
-
- spec.loaded_from = spec.spec_file
-
- Gem::Specification.add_spec spec
-
- return spec
- end
-
- ##
- # Creates a gem with +name+, +version+ and +deps+. The specification will
- # be yielded before gem creation for customization. The gem will be placed
- # in <tt>File.join @tempdir, 'gems'</tt>. The specification and .gem file
- # location are returned.
-
- def util_gem(name, version, deps = nil, &block)
- # TODO: deprecate
- raise "deps or block, not both" if deps and block
-
- if deps then
- block = proc do |s|
- # Since Hash#each is unordered in 1.8, sort
- # the keys and iterate that way so the tests are
- # deterministic on all implementations.
- deps.keys.sort.each do |n|
- s.add_dependency n, (deps[n] || '>= 0')
- end
- end
- end
-
- spec = quick_gem(name, version, &block)
-
- util_build_gem spec
-
- cache_file = File.join @tempdir, 'gems', "#{spec.original_name}.gem"
- FileUtils.mkdir_p File.dirname cache_file
- FileUtils.mv spec.cache_file, cache_file
- FileUtils.rm spec.spec_file
-
- spec.loaded_from = nil
-
- [spec, cache_file]
- end
-
- ##
- # Gzips +data+.
-
- def util_gzip(data)
- out = StringIO.new
-
- Zlib::GzipWriter.wrap out do |io|
- io.write data
- end
-
- out.string
- end
-
- ##
- # Creates several default gems which all have a lib/code.rb file. The gems
- # are not installed but are available in the cache dir.
- #
- # +@a1+:: gem a version 1, this is the best-described gem.
- # +@a2+:: gem a version 2
- # +@a3a:: gem a version 3.a
- # +@a_evil9+:: gem a_evil version 9, use this to ensure similarly-named gems
- # don't collide with a.
- # +@b2+:: gem b version 2
- # +@c1_2+:: gem c version 1.2
- # +@pl1+:: gem pl version 1, this gem has a legacy platform of i386-linux.
- #
- # Additional +prerelease+ gems may also be created:
- #
- # +@a2_pre+:: gem a version 2.a
- # TODO: nuke this and fix tests. this should speed up a lot
-
- def util_make_gems(prerelease = false)
- @a1 = quick_gem 'a', '1' do |s|
- s.files = %w[lib/code.rb]
- s.require_paths = %w[lib]
- s.date = Gem::Specification::TODAY - 86400
- s.homepage = 'http://a.example.com'
- s.email = %w[example@example.com example2@example.com]
- s.authors = %w[Example Example2]
- s.description = <<-DESC
-This line is really, really long. So long, in fact, that it is more than eighty characters long! The purpose of this line is for testing wrapping behavior because sometimes people don't wrap their text to eighty characters. Without the wrapping, the text might not look good in the RSS feed.
-
-Also, a list:
- * An entry that\'s actually kind of sort
- * an entry that\'s really long, which will probably get wrapped funny. That's ok, somebody wasn't thinking straight when they made it more than eighty characters.
- DESC
- end
-
- init = proc do |s|
- s.files = %w[lib/code.rb]
- s.require_paths = %w[lib]
- end
-
- @a2 = quick_gem('a', '2', &init)
- @a3a = quick_gem('a', '3.a', &init)
- @a_evil9 = quick_gem('a_evil', '9', &init)
- @b2 = quick_gem('b', '2', &init)
- @c1_2 = quick_gem('c', '1.2', &init)
- @x = quick_gem('x', '1', &init)
- @dep_x = quick_gem('dep_x', '1') do |s|
- s.files = %w[lib/code.rb]
- s.require_paths = %w[lib]
- s.add_dependency 'x', '>= 1'
- end
-
- @pl1 = quick_gem 'pl', '1' do |s| # l for legacy
- s.files = %w[lib/code.rb]
- s.require_paths = %w[lib]
- s.platform = Gem::Platform.new 'i386-linux'
- s.instance_variable_set :@original_platform, 'i386-linux'
- end
-
- if prerelease
- @a2_pre = quick_gem('a', '2.a', &init)
- write_file File.join(*%W[gems #{@a2_pre.original_name} lib code.rb])
- util_build_gem @a2_pre
- end
-
- write_file File.join(*%W[gems #{@a1.original_name} lib code.rb])
- write_file File.join(*%W[gems #{@a2.original_name} lib code.rb])
- write_file File.join(*%W[gems #{@a3a.original_name} lib code.rb])
- write_file File.join(*%W[gems #{@a_evil9.original_name} lib code.rb])
- write_file File.join(*%W[gems #{@b2.original_name} lib code.rb])
- write_file File.join(*%W[gems #{@c1_2.original_name} lib code.rb])
- write_file File.join(*%W[gems #{@pl1.original_name} lib code.rb])
- write_file File.join(*%W[gems #{@x.original_name} lib code.rb])
- write_file File.join(*%W[gems #{@dep_x.original_name} lib code.rb])
-
- [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2, @pl1, @x, @dep_x].each do |spec|
- util_build_gem spec
- end
-
- FileUtils.rm_r File.join(@gemhome, "gems", @pl1.original_name)
- end
-
- ##
- # Set the platform to +arch+
-
- def util_set_arch(arch)
- RbConfig::CONFIG['arch'] = arch
- platform = Gem::Platform.new arch
-
- Gem.instance_variable_set :@platforms, nil
- Gem::Platform.instance_variable_set :@local, nil
-
- platform
- end
-
- ##
- # Sets up a fake fetcher using the gems from #util_make_gems. Optionally
- # additional +prerelease+ gems may be included.
- #
- # Gems created by this method may be fetched using Gem::RemoteFetcher.
-
- def util_setup_fake_fetcher(prerelease = false)
- require 'zlib'
- require 'socket'
- require 'rubygems/remote_fetcher'
-
- @fetcher = Gem::FakeFetcher.new
-
- util_make_gems(prerelease)
- Gem::Specification.reset
-
- @all_gems = [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2].sort
- @all_gem_names = @all_gems.map { |gem| gem.full_name }
-
- gem_names = [@a1.full_name, @a2.full_name, @a3a.full_name, @b2.full_name]
- @gem_names = gem_names.sort.join("\n")
-
- Gem::RemoteFetcher.fetcher = @fetcher
- end
-
- ##
- # Add +spec+ to +@fetcher+ serving the data in the file +path+.
- # +repo+ indicates which repo to make +spec+ appear to be in.
-
- def add_to_fetcher(spec, path=nil, repo=@gem_repo)
- path ||= spec.cache_file
- @fetcher.data["#{@gem_repo}gems/#{spec.file_name}"] = read_binary(path)
- end
-
- ##
- # Sets up Gem::SpecFetcher to return information from the gems in +specs+.
- # Best used with +@all_gems+ from #util_setup_fake_fetcher.
-
- def util_setup_spec_fetcher(*specs)
- specs -= Gem::Specification._all
- Gem::Specification.add_specs(*specs)
-
- spec_fetcher = Gem::SpecFetcher.fetcher
-
- prerelease, all = Gem::Specification.partition { |spec|
- spec.version.prerelease?
- }
-
- spec_fetcher.specs[@uri] = []
- all.each do |spec|
- spec_fetcher.specs[@uri] << spec.name_tuple
- end
-
- spec_fetcher.latest_specs[@uri] = []
- Gem::Specification.latest_specs.each do |spec|
- spec_fetcher.latest_specs[@uri] << spec.name_tuple
- end
-
- spec_fetcher.prerelease_specs[@uri] = []
- prerelease.each do |spec|
- spec_fetcher.prerelease_specs[@uri] << spec.name_tuple
- end
-
- # HACK for test_download_to_cache
- unless Gem::RemoteFetcher === @fetcher then
- v = Gem.marshal_version
-
- specs = all.map { |spec| spec.name_tuple }
- s_zip = util_gzip Marshal.dump Gem::NameTuple.to_basic specs
-
- latest_specs = Gem::Specification.latest_specs.map do |spec|
- spec.name_tuple
- end
-
- l_zip = util_gzip Marshal.dump Gem::NameTuple.to_basic latest_specs
-
- prerelease_specs = prerelease.map { |spec| spec.name_tuple }
- p_zip = util_gzip Marshal.dump Gem::NameTuple.to_basic prerelease_specs
-
- @fetcher.data["#{@gem_repo}specs.#{v}.gz"] = s_zip
- @fetcher.data["#{@gem_repo}latest_specs.#{v}.gz"] = l_zip
- @fetcher.data["#{@gem_repo}prerelease_specs.#{v}.gz"] = p_zip
-
- v = Gem.marshal_version
-
- Gem::Specification.each do |spec|
- path = "#{@gem_repo}quick/Marshal.#{v}/#{spec.original_name}.gemspec.rz"
- data = Marshal.dump spec
- data_deflate = Zlib::Deflate.deflate data
- @fetcher.data[path] = data_deflate
- end
- end
-
- nil # force errors
- end
-
- ##
- # Deflates +data+
-
- def util_zip(data)
- Zlib::Deflate.deflate data
- end
-
- def util_set_RUBY_VERSION(version, patchlevel = nil, revision = nil)
- if Gem.instance_variables.include? :@ruby_version or
- Gem.instance_variables.include? '@ruby_version' then
- Gem.send :remove_instance_variable, :@ruby_version
- end
-
- @RUBY_VERSION = RUBY_VERSION
- @RUBY_PATCHLEVEL = RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
- @RUBY_REVISION = RUBY_REVISION if defined?(RUBY_REVISION)
-
- Object.send :remove_const, :RUBY_VERSION
- Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
- Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
-
- Object.const_set :RUBY_VERSION, version
- Object.const_set :RUBY_PATCHLEVEL, patchlevel if patchlevel
- Object.const_set :RUBY_REVISION, revision if revision
- end
-
- def util_restore_RUBY_VERSION
- Object.send :remove_const, :RUBY_VERSION
- Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
- Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
-
- Object.const_set :RUBY_VERSION, @RUBY_VERSION
- Object.const_set :RUBY_PATCHLEVEL, @RUBY_PATCHLEVEL if
- defined?(@RUBY_PATCHLEVEL)
- Object.const_set :RUBY_REVISION, @RUBY_REVISION if
- defined?(@RUBY_REVISION)
- end
-
- ##
- # Is this test being run on a Windows platform?
-
- def self.win_platform?
- Gem.win_platform?
- end
-
- ##
- # Is this test being run on a Windows platform?
-
- def win_platform?
- Gem.win_platform?
- end
-
- ##
- # Returns whether or not we're on a version of Ruby built with VC++ (or
- # Borland) versus Cygwin, Mingw, etc.
-
- def self.vc_windows?
- RUBY_PLATFORM.match('mswin')
- end
-
- ##
- # Returns whether or not we're on a version of Ruby built with VC++ (or
- # Borland) versus Cygwin, Mingw, etc.
-
- def vc_windows?
- RUBY_PLATFORM.match('mswin')
- end
-
- ##
- # Returns the make command for the current platform. For versions of Ruby
- # built on MS Windows with VC++ or Borland it will return 'nmake'. On all
- # other platforms, including Cygwin, it will return 'make'.
-
- def self.make_command
- ENV["make"] || (vc_windows? ? 'nmake' : 'make')
- end
-
- ##
- # Returns the make command for the current platform. For versions of Ruby
- # built on MS Windows with VC++ or Borland it will return 'nmake'. On all
- # other platforms, including Cygwin, it will return 'make'.
-
- def make_command
- ENV["make"] || (vc_windows? ? 'nmake' : 'make')
- end
-
- ##
- # Returns whether or not the nmake command could be found.
-
- def nmake_found?
- system('nmake /? 1>NUL 2>&1')
- end
-
- # In case we're building docs in a background process, this method waits for
- # that process to exit (or if it's already been reaped, or never happened,
- # swallows the Errno::ECHILD error).
- def wait_for_child_process_to_exit
- Process.wait if Process.respond_to?(:fork)
- rescue Errno::ECHILD
- end
-
- ##
- # Allows tests to use a random (but controlled) port number instead of
- # a hardcoded one. This helps CI tools when running parallels builds on
- # the same builder slave.
-
- def self.process_based_port
- @@process_based_port ||= 8000 + $$ % 1000
- end
-
- ##
- # See ::process_based_port
-
- def process_based_port
- self.class.process_based_port
- end
-
- ##
- # Allows the proper version of +rake+ to be used for the test.
-
- def build_rake_in(good=true)
- gem_ruby = Gem.ruby
- Gem.ruby = @@ruby
- env_rake = ENV["rake"]
- rake = (good ? @@good_rake : @@bad_rake)
- ENV["rake"] = rake
- yield rake
- ensure
- Gem.ruby = gem_ruby
- if env_rake
- ENV["rake"] = env_rake
- else
- ENV.delete("rake")
- end
- end
-
- ##
- # Finds the path to the Ruby executable
-
- def self.rubybin
- ruby = ENV["RUBY"]
- return ruby if ruby
- ruby = "ruby"
- rubyexe = "#{ruby}.exe"
-
- 3.times do
- if File.exist? ruby and File.executable? ruby and !File.directory? ruby
- return File.expand_path(ruby)
- end
- if File.exist? rubyexe and File.executable? rubyexe
- return File.expand_path(rubyexe)
- end
- ruby = File.join("..", ruby)
- end
-
- begin
- require "rbconfig"
- File.join(RbConfig::CONFIG["bindir"],
- RbConfig::CONFIG["ruby_install_name"] +
- RbConfig::CONFIG["EXEEXT"])
- rescue LoadError
- "ruby"
- end
- end
-
- @@ruby = rubybin
- @@good_rake = "#{rubybin} #{File.expand_path('../../../test/rubygems/good_rake.rb', __FILE__)}"
- @@bad_rake = "#{rubybin} #{File.expand_path('../../../test/rubygems/bad_rake.rb', __FILE__)}"
-
- ##
- # Construct a new Gem::Dependency.
-
- def dep name, *requirements
- Gem::Dependency.new name, *requirements
- end
-
- ##
- # Constructs a Gem::Resolver::DependencyRequest from a
- # Gem::Dependency +dep+, a +from_name+ and +from_version+ requesting the
- # dependency and a +parent+ DependencyRequest
-
- def dependency_request dep, from_name, from_version, parent = nil
- remote = Gem::Source.new @uri
-
- unless parent then
- parent_dep = dep from_name, from_version
- parent = Gem::Resolver::DependencyRequest.new parent_dep, nil
- end
-
- spec = Gem::Resolver::IndexSpecification.new \
- nil, from_name, from_version, remote, Gem::Platform::RUBY
- activation = Gem::Resolver::ActivationRequest.new spec, parent
-
- Gem::Resolver::DependencyRequest.new dep, activation
- end
-
- ##
- # Constructs a new Gem::Requirement.
-
- def req *requirements
- return requirements.first if Gem::Requirement === requirements.first
- Gem::Requirement.create requirements
- end
-
- ##
- # Constructs a new Gem::Specification.
-
- def spec name, version, &block
- Gem::Specification.new name, v(version), &block
- end
-
- ##
- # Creates a SpecFetcher pre-filled with the gems or specs defined in the
- # block.
- #
- # Yields a +fetcher+ object that responds to +spec+ and +gem+. +spec+ adds
- # a specification to the SpecFetcher while +gem+ adds both a specification
- # and the gem data to the RemoteFetcher so the built gem can be downloaded.
- #
- # If only the a-3 gem is supposed to be downloaded you can save setup
- # time by creating only specs for the other versions:
- #
- # spec_fetcher do |fetcher|
- # fetcher.spec 'a', 1
- # fetcher.spec 'a', 2, 'b' => 3 # dependency on b = 3
- # fetcher.gem 'a', 3 do |spec|
- # # spec is a Gem::Specification
- # # ...
- # end
- # end
-
- def spec_fetcher repository = @gem_repo
- Gem::TestCase::SpecFetcherSetup.declare self, repository do |spec_fetcher_setup|
- yield spec_fetcher_setup if block_given?
- end
- end
-
- ##
- # Construct a new Gem::Version.
-
- def v string
- Gem::Version.create string
- end
-
- ##
- # A vendor_gem is used with a gem dependencies file. The gem created here
- # has no files, just a gem specification for the given +name+ and +version+.
- #
- # Yields the +specification+ to the block, if given
-
- def vendor_gem name = 'a', version = 1
- directory = File.join 'vendor', name
-
- vendor_spec = Gem::Specification.new name, version do |specification|
- yield specification if block_given?
- end
-
- FileUtils.mkdir_p directory
-
- open File.join(directory, "#{name}.gemspec"), 'w' do |io|
- io.write vendor_spec.to_ruby
- end
-
- return name, vendor_spec.version, directory
- end
-
- ##
- # The StaticSet is a static set of gem specifications used for testing only.
- # It is available by requiring Gem::TestCase.
-
- class StaticSet < Gem::Resolver::Set
-
- ##
- # A StaticSet ignores remote because it has a fixed set of gems.
-
- attr_accessor :remote
-
- ##
- # Creates a new StaticSet for the given +specs+
-
- def initialize(specs)
- super()
-
- @specs = specs
-
- @remote = true
- end
-
- ##
- # Adds +spec+ to this set.
-
- def add spec
- @specs << spec
- end
-
- ##
- # Finds +dep+ in this set.
-
- def find_spec(dep)
- @specs.reverse_each do |s|
- return s if dep.matches_spec? s
- end
- end
-
- ##
- # Finds all gems matching +dep+ in this set.
-
- def find_all(dep)
- @specs.find_all { |s| dep.match? s, @prerelease }
- end
-
- ##
- # Loads a Gem::Specification from this set which has the given +name+,
- # version +ver+, +platform+. The +source+ is ignored.
-
- def load_spec name, ver, platform, source
- dep = Gem::Dependency.new name, ver
- spec = find_spec dep
-
- Gem::Specification.new spec.name, spec.version do |s|
- s.platform = spec.platform
- end
- end
-
- def prefetch reqs # :nodoc:
- end
- end
-
- ##
- # Loads certificate named +cert_name+ from <tt>test/rubygems/</tt>.
-
- def self.load_cert cert_name
- cert_file = cert_path cert_name
-
- cert = File.read cert_file
-
- OpenSSL::X509::Certificate.new cert
- end
-
- ##
- # Returns the path to the certificate named +cert_name+ from
- # <tt>test/rubygems/</tt>.
-
- def self.cert_path cert_name
- if 32 == (Time.at(2**32) rescue 32) then
- cert_file =
- File.expand_path "../../../test/rubygems/#{cert_name}_cert_32.pem",
- __FILE__
-
- return cert_file if File.exist? cert_file
- end
-
- File.expand_path "../../../test/rubygems/#{cert_name}_cert.pem", __FILE__
- end
-
- ##
- # Loads an RSA private key named +key_name+ with +passphrase+ in <tt>test/rubygems/</tt>
-
- def self.load_key key_name, passphrase = nil
- key_file = key_path key_name
-
- key = File.read key_file
-
- OpenSSL::PKey::RSA.new key, passphrase
- end
-
- ##
- # Returns the path to the key named +key_name+ from <tt>test/rubygems</tt>
-
- def self.key_path key_name
- File.expand_path "../../../test/rubygems/#{key_name}_key.pem", __FILE__
- end
-
- # :stopdoc:
- # only available in RubyGems tests
-
- PRIVATE_KEY_PASSPHRASE = 'Foo bar'
-
- begin
- PRIVATE_KEY = load_key 'private'
- PRIVATE_KEY_PATH = key_path 'private'
-
- # ENCRYPTED_PRIVATE_KEY is PRIVATE_KEY encrypted with PRIVATE_KEY_PASSPHRASE
- ENCRYPTED_PRIVATE_KEY = load_key 'encrypted_private', PRIVATE_KEY_PASSPHRASE
- ENCRYPTED_PRIVATE_KEY_PATH = key_path 'encrypted_private'
-
- PUBLIC_KEY = PRIVATE_KEY.public_key
-
- PUBLIC_CERT = load_cert 'public'
- PUBLIC_CERT_PATH = cert_path 'public'
- rescue Errno::ENOENT
- PRIVATE_KEY = nil
- PUBLIC_KEY = nil
- PUBLIC_CERT = nil
- end if defined?(OpenSSL::SSL)
-
-end
-
-require 'rubygems/test_utilities'
-
diff --git a/ruby_2_2/lib/rubygems/test_utilities.rb b/ruby_2_2/lib/rubygems/test_utilities.rb
deleted file mode 100644
index 25786e6a21..0000000000
--- a/ruby_2_2/lib/rubygems/test_utilities.rb
+++ /dev/null
@@ -1,383 +0,0 @@
-require 'tempfile'
-require 'rubygems'
-require 'rubygems/remote_fetcher'
-
-##
-# A fake Gem::RemoteFetcher for use in tests or to avoid real live HTTP
-# requests when testing code that uses RubyGems.
-#
-# Example:
-#
-# @fetcher = Gem::FakeFetcher.new
-# @fetcher.data['http://gems.example.com/yaml'] = source_index.to_yaml
-# Gem::RemoteFetcher.fetcher = @fetcher
-#
-# # invoke RubyGems code
-#
-# paths = @fetcher.paths
-# assert_equal 'http://gems.example.com/yaml', paths.shift
-# assert paths.empty?, paths.join(', ')
-#
-# See RubyGems' tests for more examples of FakeFetcher.
-
-class Gem::FakeFetcher
-
- attr_reader :data
- attr_reader :last_request
- attr_reader :api_endpoints
- attr_accessor :paths
-
- def initialize
- @data = {}
- @paths = []
- @api_endpoints = {}
- end
-
- def api_endpoint(uri)
- @api_endpoints[uri] || uri
- end
-
- def find_data(path)
- return File.read path.path if URI === path and 'file' == path.scheme
-
- if URI === path and "URI::#{path.scheme.upcase}" != path.class.name then
- raise ArgumentError,
- "mismatch for scheme #{path.scheme} and class #{path.class}"
- end
-
- path = path.to_s
- @paths << path
- raise ArgumentError, 'need full URI' unless path =~ %r'^https?://'
-
- unless @data.key? path then
- raise Gem::RemoteFetcher::FetchError.new("no data for #{path}", path)
- end
-
- @data[path]
- end
-
- def fetch_path path, mtime = nil, head = false
- data = find_data(path)
-
- if data.respond_to?(:call) then
- data.call
- else
- if path.to_s =~ /gz$/ and not data.nil? and not data.empty? then
- data = Gem.gunzip data
- end
-
- data
- end
- end
-
- def cache_update_path uri, path = nil, update = true
- if data = fetch_path(uri)
- open(path, 'wb') { |io| io.write data } if path and update
- data
- else
- Gem.read_binary(path) if path
- end
- end
-
- # Thanks, FakeWeb!
- def open_uri_or_path(path)
- data = find_data(path)
- body, code, msg = data
-
- response = Net::HTTPResponse.send(:response_class, code.to_s).new("1.0", code.to_s, msg)
- response.instance_variable_set(:@body, body)
- response.instance_variable_set(:@read, true)
- response
- end
-
- def request(uri, request_class, last_modified = nil)
- data = find_data(uri)
- body, code, msg = data
-
- @last_request = request_class.new uri.request_uri
- yield @last_request if block_given?
-
- response = Net::HTTPResponse.send(:response_class, code.to_s).new("1.0", code.to_s, msg)
- response.instance_variable_set(:@body, body)
- response.instance_variable_set(:@read, true)
- response
- end
-
- def pretty_print q # :nodoc:
- q.group 2, '[FakeFetcher', ']' do
- q.breakable
- q.text 'URIs:'
-
- q.breakable
- q.pp @data.keys
-
- unless @api_endpoints.empty? then
- q.breakable
- q.text 'API endpoints:'
-
- q.breakable
- q.pp @api_endpoints.keys
- end
- end
- end
-
- def fetch_size(path)
- path = path.to_s
- @paths << path
-
- raise ArgumentError, 'need full URI' unless path =~ %r'^http://'
-
- unless @data.key? path then
- raise Gem::RemoteFetcher::FetchError.new("no data for #{path}", path)
- end
-
- data = @data[path]
-
- data.respond_to?(:call) ? data.call : data.length
- end
-
- def download spec, source_uri, install_dir = Gem.dir
- name = File.basename spec.cache_file
- path = if Dir.pwd == install_dir then # see fetch_command
- install_dir
- else
- File.join install_dir, "cache"
- end
-
- path = File.join path, name
-
- if source_uri =~ /^http/ then
- File.open(path, "wb") do |f|
- f.write fetch_path(File.join(source_uri, "gems", name))
- end
- else
- FileUtils.cp source_uri, path
- end
-
- path
- end
-
- def download_to_cache dependency
- found, _ = Gem::SpecFetcher.fetcher.spec_for_dependency dependency
-
- return if found.empty?
-
- spec, source = found.first
-
- download spec, source.uri.to_s
- end
-
-end
-
-# :stopdoc:
-class Gem::RemoteFetcher
-
- def self.fetcher=(fetcher)
- @fetcher = fetcher
- end
-
-end
-# :startdoc:
-
-##
-# The SpecFetcherSetup allows easy setup of a remote source in RubyGems tests:
-#
-# spec_fetcher do |f|
-# f.gem 'a', 1
-# f.spec 'a', 2
-# f.gem 'b', 1' 'a' => '~> 1.0'
-# f.clear
-# end
-#
-# The above declaration creates two gems, a-1 and b-1, with a dependency from
-# b to a. The declaration creates an additional spec a-2, but no gem for it
-# (so it cannot be installed).
-#
-# After the gems are created they are removed from Gem.dir.
-
-class Gem::TestCase::SpecFetcherSetup
-
- ##
- # Executes a SpecFetcher setup block. Yields an instance then creates the
- # gems and specifications defined in the instance.
-
- def self.declare test, repository
- setup = new test, repository
-
- yield setup
-
- setup.execute
- end
-
- def initialize test, repository # :nodoc:
- @test = test
- @repository = repository
-
- @gems = {}
- @installed = []
- @operations = []
- end
-
- ##
- # Removes any created gems or specifications from Gem.dir (the default
- # install location).
-
- def clear
- @operations << [:clear]
- end
-
- ##
- # Returns a Hash of created Specification full names and the corresponding
- # Specification.
-
- def created_specs
- created = {}
-
- @gems.keys.each do |spec|
- created[spec.full_name] = spec
- end
-
- created
- end
-
- ##
- # Creates any defined gems or specifications
-
- def execute # :nodoc:
- execute_operations
-
- setup_fetcher
-
- created_specs
- end
-
- def execute_operations # :nodoc:
- @operations.each do |operation, *arguments|
- case operation
- when :clear then
- @test.util_clear_gems
- @installed.clear
- when :gem then
- spec, gem = @test.util_gem(*arguments, &arguments.pop)
-
- write_spec spec
-
- @gems[spec] = gem
- @installed << spec
- when :spec then
- spec = @test.util_spec(*arguments, &arguments.pop)
-
- write_spec spec
-
- @gems[spec] = nil
- @installed << spec
- end
- end
- end
-
- ##
- # Creates a gem with +name+, +version+ and +deps+. The created gem can be
- # downloaded and installed.
- #
- # The specification will be yielded before gem creation for customization,
- # but only the block or the dependencies may be set, not both.
-
- def gem name, version, dependencies = nil, &block
- @operations << [:gem, name, version, dependencies, block]
- end
-
- ##
- # Creates a legacy platform spec with the name 'pl' and version 1
-
- def legacy_platform
- spec 'pl', 1 do |s|
- s.platform = Gem::Platform.new 'i386-linux'
- s.instance_variable_set :@original_platform, 'i386-linux'
- end
- end
-
- def setup_fetcher # :nodoc:
- require 'zlib'
- require 'socket'
- require 'rubygems/remote_fetcher'
-
- unless @test.fetcher then
- @test.fetcher = Gem::FakeFetcher.new
- Gem::RemoteFetcher.fetcher = @test.fetcher
- end
-
- Gem::Specification.reset
-
- begin
- gem_repo, @test.gem_repo = @test.gem_repo, @repository
- @test.uri = URI @repository
-
- @test.util_setup_spec_fetcher(*@gems.keys)
- ensure
- @test.gem_repo = gem_repo
- @test.uri = URI gem_repo
- end
-
- # This works around util_setup_spec_fetcher adding all created gems to the
- # installed set.
- Gem::Specification.reset
- Gem::Specification.add_specs(*@installed)
-
- @gems.each do |spec, gem|
- next unless gem
-
- @test.fetcher.data["#{@repository}gems/#{spec.file_name}"] =
- Gem.read_binary(gem)
-
- FileUtils.cp gem, spec.cache_file
- end
- end
-
- ##
- # Creates a spec with +name+, +version+ and +deps+. The created gem can be
- # downloaded and installed.
- #
- # The specification will be yielded before creation for customization,
- # but only the block or the dependencies may be set, not both.
-
- def spec name, version, dependencies = nil, &block
- @operations << [:spec, name, version, dependencies, block]
- end
-
- def write_spec spec # :nodoc:
- open spec.spec_file, 'w' do |io|
- io.write spec.to_ruby_for_cache
- end
- end
-
-end
-
-##
-# A StringIO duck-typed class that uses Tempfile instead of String as the
-# backing store.
-#
-# This is available when rubygems/test_utilities is required.
-#--
-# This class was added to flush out problems in Rubinius' IO implementation.
-
-class TempIO < Tempfile
-
- ##
- # Creates a new TempIO that will be initialized to contain +string+.
-
- def initialize(string = '')
- super "TempIO"
- binmode
- write string
- rewind
- end
-
- ##
- # The content of the TempIO as a String.
-
- def string
- flush
- Gem.read_binary path
- end
-end
-
diff --git a/ruby_2_2/lib/rubygems/text.rb b/ruby_2_2/lib/rubygems/text.rb
deleted file mode 100644
index 86a722ffc0..0000000000
--- a/ruby_2_2/lib/rubygems/text.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-require 'rubygems'
-
-##
-# A collection of text-wrangling methods
-
-module Gem::Text
-
- ##
- # Remove any non-printable characters and make the text suitable for
- # printing.
- def clean_text(text)
- text.gsub(/[\000-\b\v-\f\016-\037\177]/, ".".freeze)
- end
-
- def truncate_text(text, description, max_length = 100_000)
- raise ArgumentError, "max_length must be positive" unless max_length > 0
- return text if text.size <= max_length
- "Truncating #{description} to #{max_length.to_s.reverse.gsub(/...(?=.)/,'\&,').reverse} characters:\n" + text[0, max_length]
- end
-
- ##
- # Wraps +text+ to +wrap+ characters and optionally indents by +indent+
- # characters
-
- def format_text(text, wrap, indent=0)
- result = []
- work = clean_text(text)
-
- while work.length > wrap do
- if work =~ /^(.{0,#{wrap}})[ \n]/ then
- result << $1.rstrip
- work.slice!(0, $&.length)
- else
- result << work.slice!(0, wrap)
- end
- end
-
- result << work if work.length.nonzero?
- result.join("\n").gsub(/^/, " " * indent)
- end
-
- def min3 a, b, c # :nodoc:
- if a < b && a < c then
- a
- elsif b < c then
- b
- else
- c
- end
- end
-
- # This code is based directly on the Text gem implementation
- # Returns a value representing the "cost" of transforming str1 into str2
- def levenshtein_distance str1, str2
- s = str1
- t = str2
- n = s.length
- m = t.length
- max = n/2
-
- return m if (0 == n)
- return n if (0 == m)
- return n if (n - m).abs > max
-
- d = (0..m).to_a
- x = nil
-
- str1.each_char.each_with_index do |char1,i|
- e = i+1
-
- str2.each_char.each_with_index do |char2,j|
- cost = (char1 == char2) ? 0 : 1
- x = min3(
- d[j+1] + 1, # insertion
- e + 1, # deletion
- d[j] + cost # substitution
- )
- d[j] = e
- e = x
- end
-
- d[m] = x
- end
-
- return x
- end
-end
-
diff --git a/ruby_2_2/lib/rubygems/uninstaller.rb b/ruby_2_2/lib/rubygems/uninstaller.rb
deleted file mode 100644
index 2a6edc6131..0000000000
--- a/ruby_2_2/lib/rubygems/uninstaller.rb
+++ /dev/null
@@ -1,345 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'fileutils'
-require 'rubygems'
-require 'rubygems/dependency_list'
-require 'rubygems/rdoc'
-require 'rubygems/user_interaction'
-
-##
-# An Uninstaller.
-#
-# The uninstaller fires pre and post uninstall hooks. Hooks can be added
-# either through a rubygems_plugin.rb file in an installed gem or via a
-# rubygems/defaults/#{RUBY_ENGINE}.rb or rubygems/defaults/operating_system.rb
-# file. See Gem.pre_uninstall and Gem.post_uninstall for details.
-
-class Gem::Uninstaller
-
- include Gem::UserInteraction
-
- ##
- # The directory a gem's executables will be installed into
-
- attr_reader :bin_dir
-
- ##
- # The gem repository the gem will be installed into
-
- attr_reader :gem_home
-
- ##
- # The Gem::Specification for the gem being uninstalled, only set during
- # #uninstall_gem
-
- attr_reader :spec
-
- ##
- # Constructs an uninstaller that will uninstall +gem+
-
- def initialize(gem, options = {})
- # TODO document the valid options
- @gem = gem
- @version = options[:version] || Gem::Requirement.default
- @gem_home = File.expand_path(options[:install_dir] || Gem.dir)
- @force_executables = options[:executables]
- @force_all = options[:all]
- @force_ignore = options[:ignore]
- @bin_dir = options[:bin_dir]
- @format_executable = options[:format_executable]
- @abort_on_dependent = options[:abort_on_dependent]
-
- # Indicate if development dependencies should be checked when
- # uninstalling. (default: false)
- #
- @check_dev = options[:check_dev]
-
- if options[:force]
- @force_all = true
- @force_ignore = true
- end
-
- # only add user directory if install_dir is not set
- @user_install = false
- @user_install = options[:user_install] unless options[:install_dir]
- end
-
- ##
- # Performs the uninstall of the gem. This removes the spec, the Gem
- # directory, and the cached .gem file.
-
- def uninstall
- dependency = Gem::Dependency.new @gem, @version
-
- list = []
-
- dirs =
- Gem::Specification.dirs +
- [Gem::Specification.default_specifications_dir]
-
- Gem::Specification.each_spec dirs do |spec|
- next unless dependency.matches_spec? spec
-
- list << spec
- end
-
- default_specs, list = list.partition do |spec|
- spec.default_gem?
- end
-
- list, other_repo_specs = list.partition do |spec|
- @gem_home == spec.base_dir or
- (@user_install and spec.base_dir == Gem.user_dir)
- end
-
- list.sort!
-
- if list.empty? then
- if other_repo_specs.empty?
- if default_specs.empty?
- raise Gem::InstallError, "gem #{@gem.inspect} is not installed"
- else
- message =
- "gem #{@gem.inspect} cannot be uninstalled " +
- "because it is a default gem"
- raise Gem::InstallError, message
- end
- end
-
- other_repos = other_repo_specs.map { |spec| spec.base_dir }.uniq
-
- message = ["#{@gem} is not installed in GEM_HOME, try:"]
- message.concat other_repos.map { |repo|
- "\tgem uninstall -i #{repo} #{@gem}"
- }
-
- raise Gem::InstallError, message.join("\n")
- elsif @force_all then
- remove_all list
-
- elsif list.size > 1 then
- gem_names = list.map { |gem| gem.full_name }
- gem_names << "All versions"
-
- say
- _, index = choose_from_list "Select gem to uninstall:", gem_names
-
- if index == list.size then
- remove_all list
- elsif index >= 0 && index < list.size then
- uninstall_gem list[index]
- else
- say "Error: must enter a number [1-#{list.size+1}]"
- end
- else
- uninstall_gem list.first
- end
- end
-
- ##
- # Uninstalls gem +spec+
-
- def uninstall_gem(spec)
- @spec = spec
-
- unless dependencies_ok? spec
- if abort_on_dependent? || !ask_if_ok(spec)
- raise Gem::DependencyRemovalException,
- "Uninstallation aborted due to dependent gem(s)"
- end
- end
-
- Gem.pre_uninstall_hooks.each do |hook|
- hook.call self
- end
-
- remove_executables @spec
- remove @spec
-
- Gem.post_uninstall_hooks.each do |hook|
- hook.call self
- end
-
- @spec = nil
- end
-
- ##
- # Removes installed executables and batch files (windows only) for
- # +gemspec+.
-
- def remove_executables(spec)
- return if spec.nil? or spec.executables.empty?
-
- executables = spec.executables.clone
-
- # Leave any executables created by other installed versions
- # of this gem installed.
-
- list = Gem::Specification.find_all { |s|
- s.name == spec.name && s.version != spec.version
- }
-
- list.each do |s|
- s.executables.each do |exe_name|
- executables.delete exe_name
- end
- end
-
- return if executables.empty?
-
- executables = executables.map { |exec| formatted_program_filename exec }
-
- remove = if @force_executables.nil? then
- ask_yes_no("Remove executables:\n" +
- "\t#{executables.join ', '}\n\n" +
- "in addition to the gem?",
- true)
- else
- @force_executables
- end
-
- if remove then
- bin_dir = @bin_dir || Gem.bindir(spec.base_dir)
-
- raise Gem::FilePermissionError, bin_dir unless File.writable? bin_dir
-
- executables.each do |exe_name|
- say "Removing #{exe_name}"
-
- exe_file = File.join bin_dir, exe_name
-
- FileUtils.rm_f exe_file
- FileUtils.rm_f "#{exe_file}.bat"
- end
- else
- say "Executables and scripts will remain installed."
- end
- end
-
- ##
- # Removes all gems in +list+.
- #
- # NOTE: removes uninstalled gems from +list+.
-
- def remove_all(list)
- list.each { |spec| uninstall_gem spec }
- end
-
- ##
- # spec:: the spec of the gem to be uninstalled
- # list:: the list of all such gems
- #
- # Warning: this method modifies the +list+ parameter. Once it has
- # uninstalled a gem, it is removed from that list.
-
- def remove(spec)
- unless path_ok?(@gem_home, spec) or
- (@user_install and path_ok?(Gem.user_dir, spec)) then
- e = Gem::GemNotInHomeException.new \
- "Gem '#{spec.full_name}' is not installed in directory #{@gem_home}"
- e.spec = spec
-
- raise e
- end
-
- raise Gem::FilePermissionError, spec.base_dir unless
- File.writable?(spec.base_dir)
-
- FileUtils.rm_rf spec.full_gem_path
- FileUtils.rm_rf spec.extension_dir
-
- old_platform_name = spec.original_name
- gemspec = spec.spec_file
-
- unless File.exist? gemspec then
- gemspec = File.join(File.dirname(gemspec), "#{old_platform_name}.gemspec")
- end
-
- FileUtils.rm_rf gemspec
-
- gem = spec.cache_file
- gem = File.join(spec.cache_dir, "#{old_platform_name}.gem") unless
- File.exist? gem
-
- FileUtils.rm_rf gem
-
- Gem::RDoc.new(spec).remove
-
- say "Successfully uninstalled #{spec.full_name}"
-
- Gem::Specification.remove_spec spec
- end
-
- ##
- # Is +spec+ in +gem_dir+?
-
- def path_ok?(gem_dir, spec)
- full_path = File.join gem_dir, 'gems', spec.full_name
- original_path = File.join gem_dir, 'gems', spec.original_name
-
- full_path == spec.full_gem_path || original_path == spec.full_gem_path
- end
-
- ##
- # Returns true if it is OK to remove +spec+ or this is a forced
- # uninstallation.
-
- def dependencies_ok? spec # :nodoc:
- return true if @force_ignore
-
- deplist = Gem::DependencyList.from_specs
- deplist.ok_to_remove?(spec.full_name, @check_dev)
- end
-
- ##
- # Should the uninstallation abort if a dependency will go unsatisfied?
- #
- # See ::new.
-
- def abort_on_dependent? # :nodoc:
- @abort_on_dependent
- end
-
- ##
- # Asks if it is OK to remove +spec+. Returns true if it is OK.
-
- def ask_if_ok spec # :nodoc:
- msg = ['']
- msg << 'You have requested to uninstall the gem:'
- msg << "\t#{spec.full_name}"
- msg << ''
-
- siblings = Gem::Specification.select do |s|
- s.name == spec.name && s.full_name != spec.full_name
- end
-
- spec.dependent_gems.each do |dep_spec, dep, satlist|
- unless siblings.any? { |s| s.satisfies_requirement? dep }
- msg << "#{dep_spec.name}-#{dep_spec.version} depends on #{dep}"
- end
- end
-
- msg << 'If you remove this gem, these dependencies will not be met.'
- msg << 'Continue with Uninstall?'
- return ask_yes_no(msg.join("\n"), false)
- end
-
- ##
- # Returns the formatted version of the executable +filename+
-
- def formatted_program_filename filename # :nodoc:
- # TODO perhaps the installer should leave a small manifest
- # of what it did for us to find rather than trying to recreate
- # it again.
- if @format_executable then
- require 'rubygems/installer'
- Gem::Installer.exec_format % File.basename(filename)
- else
- filename
- end
- end
-end
diff --git a/ruby_2_2/lib/rubygems/uri_formatter.rb b/ruby_2_2/lib/rubygems/uri_formatter.rb
deleted file mode 100644
index 68aacc6369..0000000000
--- a/ruby_2_2/lib/rubygems/uri_formatter.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-require 'cgi'
-require 'uri'
-
-##
-# The UriFormatter handles URIs from user-input and escaping.
-#
-# uf = Gem::UriFormatter.new 'example.com'
-#
-# p uf.normalize #=> 'http://example.com'
-
-class Gem::UriFormatter
-
- ##
- # The URI to be formatted.
-
- attr_reader :uri
-
- ##
- # Creates a new URI formatter for +uri+.
-
- def initialize uri
- @uri = uri
- end
-
- ##
- # Escapes the #uri for use as a CGI parameter
-
- def escape
- return unless @uri
- CGI.escape @uri
- end
-
- ##
- # Normalize the URI by adding "http://" if it is missing.
-
- def normalize
- (@uri =~ /^(https?|ftp|file):/i) ? @uri : "http://#{@uri}"
- end
-
- ##
- # Unescapes the #uri which came from a CGI parameter
-
- def unescape
- return unless @uri
- CGI.unescape @uri
- end
-
-end
-
diff --git a/ruby_2_2/lib/rubygems/user_interaction.rb b/ruby_2_2/lib/rubygems/user_interaction.rb
deleted file mode 100644
index 44ff2d33ff..0000000000
--- a/ruby_2_2/lib/rubygems/user_interaction.rb
+++ /dev/null
@@ -1,711 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-begin
- require 'io/console'
-rescue LoadError
-end
-
-##
-# Module that defines the default UserInteraction. Any class including this
-# module will have access to the +ui+ method that returns the default UI.
-
-module Gem::DefaultUserInteraction
-
- ##
- # The default UI is a class variable of the singleton class for this
- # module.
-
- @ui = nil
-
- ##
- # Return the default UI.
-
- def self.ui
- @ui ||= Gem::ConsoleUI.new
- end
-
- ##
- # Set the default UI. If the default UI is never explicitly set, a simple
- # console based UserInteraction will be used automatically.
-
- def self.ui=(new_ui)
- @ui = new_ui
- end
-
- ##
- # Use +new_ui+ for the duration of +block+.
-
- def self.use_ui(new_ui)
- old_ui = @ui
- @ui = new_ui
- yield
- ensure
- @ui = old_ui
- end
-
- ##
- # See DefaultUserInteraction::ui
-
- def ui
- Gem::DefaultUserInteraction.ui
- end
-
- ##
- # See DefaultUserInteraction::ui=
-
- def ui=(new_ui)
- Gem::DefaultUserInteraction.ui = new_ui
- end
-
- ##
- # See DefaultUserInteraction::use_ui
-
- def use_ui(new_ui, &block)
- Gem::DefaultUserInteraction.use_ui(new_ui, &block)
- end
-
-end
-
-##
-# UserInteraction allows RubyGems to interact with the user through standard
-# methods that can be replaced with more-specific UI methods for different
-# displays.
-#
-# Since UserInteraction dispatches to a concrete UI class you may need to
-# reference other classes for specific behavior such as Gem::ConsoleUI or
-# Gem::SilentUI.
-#
-# Example:
-#
-# class X
-# include Gem::UserInteraction
-#
-# def get_answer
-# n = ask("What is the meaning of life?")
-# end
-# end
-
-module Gem::UserInteraction
-
- include Gem::DefaultUserInteraction
-
- ##
- # Displays an alert +statement+. Asks a +question+ if given.
-
- def alert statement, question = nil
- ui.alert statement, question
- end
-
- ##
- # Displays an error +statement+ to the error output location. Asks a
- # +question+ if given.
-
- def alert_error statement, question = nil
- ui.alert_error statement, question
- end
-
- ##
- # Displays a warning +statement+ to the warning output location. Asks a
- # +question+ if given.
-
- def alert_warning statement, question = nil
- ui.alert_warning statement, question
- end
-
- ##
- # Asks a +question+ and returns the answer.
-
- def ask question
- ui.ask question
- end
-
- ##
- # Asks for a password with a +prompt+
-
- def ask_for_password prompt
- ui.ask_for_password prompt
- end
-
- ##
- # Asks a yes or no +question+. Returns true for yes, false for no.
-
- def ask_yes_no question, default = nil
- ui.ask_yes_no question, default
- end
-
- ##
- # Asks the user to answer +question+ with an answer from the given +list+.
-
- def choose_from_list question, list
- ui.choose_from_list question, list
- end
-
- ##
- # Displays the given +statement+ on the standard output (or equivalent).
-
- def say statement = ''
- ui.say statement
- end
-
- ##
- # Terminates the RubyGems process with the given +exit_code+
-
- def terminate_interaction exit_code = 0
- ui.terminate_interaction exit_code
- end
-
- ##
- # Calls +say+ with +msg+ or the results of the block if really_verbose
- # is true.
-
- def verbose msg = nil
- say(msg || yield) if Gem.configuration.really_verbose
- end
-end
-
-##
-# Gem::StreamUI implements a simple stream based user interface.
-
-class Gem::StreamUI
-
- ##
- # The input stream
-
- attr_reader :ins
-
- ##
- # The output stream
-
- attr_reader :outs
-
- ##
- # The error stream
-
- attr_reader :errs
-
- ##
- # Creates a new StreamUI wrapping +in_stream+ for user input, +out_stream+
- # for standard output, +err_stream+ for error output. If +usetty+ is true
- # then special operations (like asking for passwords) will use the TTY
- # commands to disable character echo.
-
- def initialize(in_stream, out_stream, err_stream=STDERR, usetty=true)
- @ins = in_stream
- @outs = out_stream
- @errs = err_stream
- @usetty = usetty
- end
-
- ##
- # Returns true if TTY methods should be used on this StreamUI.
-
- def tty?
- if RUBY_VERSION < '1.9.3' and RUBY_PLATFORM =~ /mingw|mswin/ then
- @usetty
- else
- @usetty && @ins.tty?
- end
- end
-
- ##
- # Prints a formatted backtrace to the errors stream if backtraces are
- # enabled.
-
- def backtrace exception
- return unless Gem.configuration.backtrace
-
- @errs.puts "\t#{exception.backtrace.join "\n\t"}"
- end
-
- ##
- # Choose from a list of options. +question+ is a prompt displayed above
- # the list. +list+ is a list of option strings. Returns the pair
- # [option_name, option_index].
-
- def choose_from_list(question, list)
- @outs.puts question
-
- list.each_with_index do |item, index|
- @outs.puts " #{index+1}. #{item}"
- end
-
- @outs.print "> "
- @outs.flush
-
- result = @ins.gets
-
- return nil, nil unless result
-
- result = result.strip.to_i - 1
- return list[result], result
- end
-
- ##
- # Ask a question. Returns a true for yes, false for no. If not connected
- # to a tty, raises an exception if default is nil, otherwise returns
- # default.
-
- def ask_yes_no(question, default=nil)
- unless tty? then
- if default.nil? then
- raise Gem::OperationNotSupportedError,
- "Not connected to a tty and no default specified"
- else
- return default
- end
- end
-
- default_answer = case default
- when nil
- 'yn'
- when true
- 'Yn'
- else
- 'yN'
- end
-
- result = nil
-
- while result.nil? do
- result = case ask "#{question} [#{default_answer}]"
- when /^y/i then true
- when /^n/i then false
- when /^$/ then default
- else nil
- end
- end
-
- return result
- end
-
- ##
- # Ask a question. Returns an answer if connected to a tty, nil otherwise.
-
- def ask(question)
- return nil if not tty?
-
- @outs.print(question + " ")
- @outs.flush
-
- result = @ins.gets
- result.chomp! if result
- result
- end
-
- ##
- # Ask for a password. Does not echo response to terminal.
-
- def ask_for_password(question)
- return nil if not tty?
-
- @outs.print(question, " ")
- @outs.flush
-
- password = _gets_noecho
- @outs.puts
- password.chomp! if password
- password
- end
-
- if IO.method_defined?(:noecho) then
- def _gets_noecho
- @ins.noecho {@ins.gets}
- end
- elsif Gem.win_platform?
- def _gets_noecho
- require "Win32API"
- password = ''
-
- while char = Win32API.new("crtdll", "_getch", [ ], "L").Call do
- break if char == 10 || char == 13 # received carriage return or newline
- if char == 127 || char == 8 # backspace and delete
- password.slice!(-1, 1)
- else
- password << char.chr
- end
- end
- password
- end
- else
- def _gets_noecho
- system "stty -echo"
- begin
- @ins.gets
- ensure
- system "stty echo"
- end
- end
- end
-
- ##
- # Display a statement.
-
- def say(statement="")
- @outs.puts statement
- end
-
- ##
- # Display an informational alert. Will ask +question+ if it is not nil.
-
- def alert(statement, question=nil)
- @outs.puts "INFO: #{statement}"
- ask(question) if question
- end
-
- ##
- # Display a warning on stderr. Will ask +question+ if it is not nil.
-
- def alert_warning(statement, question=nil)
- @errs.puts "WARNING: #{statement}"
- ask(question) if question
- end
-
- ##
- # Display an error message in a location expected to get error messages.
- # Will ask +question+ if it is not nil.
-
- def alert_error(statement, question=nil)
- @errs.puts "ERROR: #{statement}"
- ask(question) if question
- end
-
- ##
- # Display a debug message on the same location as error messages.
-
- def debug(statement)
- @errs.puts statement
- end
-
- ##
- # Terminate the application with exit code +status+, running any exit
- # handlers that might have been defined.
-
- def terminate_interaction(status = 0)
- close
- raise Gem::SystemExitException, status
- end
-
- def close
- end
-
- ##
- # Return a progress reporter object chosen from the current verbosity.
-
- def progress_reporter(*args)
- if self.kind_of?(Gem::SilentUI)
- return SilentProgressReporter.new(@outs, *args)
- end
-
- case Gem.configuration.verbose
- when nil, false
- SilentProgressReporter.new(@outs, *args)
- when true
- SimpleProgressReporter.new(@outs, *args)
- else
- VerboseProgressReporter.new(@outs, *args)
- end
- end
-
- ##
- # An absolutely silent progress reporter.
-
- class SilentProgressReporter
-
- ##
- # The count of items is never updated for the silent progress reporter.
-
- attr_reader :count
-
- ##
- # Creates a silent progress reporter that ignores all input arguments.
-
- def initialize(out_stream, size, initial_message, terminal_message = nil)
- end
-
- ##
- # Does not print +message+ when updated as this object has taken a vow of
- # silence.
-
- def updated(message)
- end
-
- ##
- # Does not print anything when complete as this object has taken a vow of
- # silence.
-
- def done
- end
- end
-
- ##
- # A basic dotted progress reporter.
-
- class SimpleProgressReporter
-
- include Gem::DefaultUserInteraction
-
- ##
- # The number of progress items counted so far.
-
- attr_reader :count
-
- ##
- # Creates a new progress reporter that will write to +out_stream+ for
- # +size+ items. Shows the given +initial_message+ when progress starts
- # and the +terminal_message+ when it is complete.
-
- def initialize(out_stream, size, initial_message,
- terminal_message = "complete")
- @out = out_stream
- @total = size
- @count = 0
- @terminal_message = terminal_message
-
- @out.puts initial_message
- end
-
- ##
- # Prints out a dot and ignores +message+.
-
- def updated(message)
- @count += 1
- @out.print "."
- @out.flush
- end
-
- ##
- # Prints out the terminal message.
-
- def done
- @out.puts "\n#{@terminal_message}"
- end
-
- end
-
- ##
- # A progress reporter that prints out messages about the current progress.
-
- class VerboseProgressReporter
-
- include Gem::DefaultUserInteraction
-
- ##
- # The number of progress items counted so far.
-
- attr_reader :count
-
- ##
- # Creates a new progress reporter that will write to +out_stream+ for
- # +size+ items. Shows the given +initial_message+ when progress starts
- # and the +terminal_message+ when it is complete.
-
- def initialize(out_stream, size, initial_message,
- terminal_message = 'complete')
- @out = out_stream
- @total = size
- @count = 0
- @terminal_message = terminal_message
-
- @out.puts initial_message
- end
-
- ##
- # Prints out the position relative to the total and the +message+.
-
- def updated(message)
- @count += 1
- @out.puts "#{@count}/#{@total}: #{message}"
- end
-
- ##
- # Prints out the terminal message.
-
- def done
- @out.puts @terminal_message
- end
- end
-
- ##
- # Return a download reporter object chosen from the current verbosity
-
- def download_reporter(*args)
- if self.kind_of?(Gem::SilentUI)
- return SilentDownloadReporter.new(@outs, *args)
- end
-
- case Gem.configuration.verbose
- when nil, false
- SilentDownloadReporter.new(@outs, *args)
- else
- VerboseDownloadReporter.new(@outs, *args)
- end
- end
-
- ##
- # An absolutely silent download reporter.
-
- class SilentDownloadReporter
-
- ##
- # The silent download reporter ignores all arguments
-
- def initialize(out_stream, *args)
- end
-
- ##
- # The silent download reporter does not display +filename+ or care about
- # +filesize+ because it is silent.
-
- def fetch(filename, filesize)
- end
-
- ##
- # Nothing can update the silent download reporter.
-
- def update(current)
- end
-
- ##
- # The silent download reporter won't tell you when the download is done.
- # Because it is silent.
-
- def done
- end
- end
-
- ##
- # A progress reporter that prints out messages about the current progress.
-
- class VerboseDownloadReporter
-
- ##
- # The current file name being displayed
-
- attr_reader :file_name
-
- ##
- # The total bytes in the file
-
- attr_reader :total_bytes
-
- ##
- # The current progress (0 to 100)
-
- attr_reader :progress
-
- ##
- # Creates a new verbose download reporter that will display on
- # +out_stream+. The other arguments are ignored.
-
- def initialize(out_stream, *args)
- @out = out_stream
- @progress = 0
- end
-
- ##
- # Tells the download reporter that the +file_name+ is being fetched and
- # contains +total_bytes+.
-
- def fetch(file_name, total_bytes)
- @file_name = file_name
- @total_bytes = total_bytes.to_i
- @units = @total_bytes.zero? ? 'B' : '%'
-
- update_display(false)
- end
-
- ##
- # Updates the verbose download reporter for the given number of +bytes+.
-
- def update(bytes)
- new_progress = if @units == 'B' then
- bytes
- else
- ((bytes.to_f * 100) / total_bytes.to_f).ceil
- end
-
- return if new_progress == @progress
-
- @progress = new_progress
- update_display
- end
-
- ##
- # Indicates the download is complete.
-
- def done
- @progress = 100 if @units == '%'
- update_display(true, true)
- end
-
- private
-
- def update_display(show_progress = true, new_line = false) # :nodoc:
- return unless @out.tty?
-
- if show_progress then
- @out.print "\rFetching: %s (%3d%s)" % [@file_name, @progress, @units]
- else
- @out.print "Fetching: %s" % @file_name
- end
- @out.puts if new_line
- end
- end
-end
-
-##
-# Subclass of StreamUI that instantiates the user interaction using STDIN,
-# STDOUT, and STDERR.
-
-class Gem::ConsoleUI < Gem::StreamUI
-
- ##
- # The Console UI has no arguments as it defaults to reading input from
- # stdin, output to stdout and warnings or errors to stderr.
-
- def initialize
- super STDIN, STDOUT, STDERR, true
- end
-end
-
-##
-# SilentUI is a UI choice that is absolutely silent.
-
-class Gem::SilentUI < Gem::StreamUI
-
- ##
- # The SilentUI has no arguments as it does not use any stream.
-
- def initialize
- reader, writer = nil, nil
-
- begin
- reader = File.open('/dev/null', 'r')
- writer = File.open('/dev/null', 'w')
- rescue Errno::ENOENT
- reader = File.open('nul', 'r')
- writer = File.open('nul', 'w')
- end
-
- super reader, writer, writer, false
- end
-
- def close
- super
- @ins.close
- @outs.close
- end
-
- def download_reporter(*args) # :nodoc:
- SilentDownloadReporter.new(@outs, *args)
- end
-
- def progress_reporter(*args) # :nodoc:
- SilentProgressReporter.new(@outs, *args)
- end
-end
-
diff --git a/ruby_2_2/lib/rubygems/util.rb b/ruby_2_2/lib/rubygems/util.rb
deleted file mode 100644
index cd0af4d8fe..0000000000
--- a/ruby_2_2/lib/rubygems/util.rb
+++ /dev/null
@@ -1,134 +0,0 @@
-##
-# This module contains various utility methods as module methods.
-
-module Gem::Util
-
- @silent_mutex = nil
-
- ##
- # Zlib::GzipReader wrapper that unzips +data+.
-
- def self.gunzip(data)
- require 'zlib'
- require 'rubygems/util/stringio'
- data = Gem::StringSource.new data
-
- unzipped = Zlib::GzipReader.new(data).read
- unzipped.force_encoding Encoding::BINARY if Object.const_defined? :Encoding
- unzipped
- end
-
- ##
- # Zlib::GzipWriter wrapper that zips +data+.
-
- def self.gzip(data)
- require 'zlib'
- require 'rubygems/util/stringio'
- zipped = Gem::StringSink.new
- zipped.set_encoding Encoding::BINARY if Object.const_defined? :Encoding
-
- Zlib::GzipWriter.wrap zipped do |io| io.write data end
-
- zipped.string
- end
-
- ##
- # A Zlib::Inflate#inflate wrapper
-
- def self.inflate(data)
- require 'zlib'
- Zlib::Inflate.inflate data
- end
-
- ##
- # This calls IO.popen where it accepts an array for a +command+ (Ruby 1.9+)
- # and implements an IO.popen-like behavior where it does not accept an array
- # for a command.
-
- def self.popen *command
- IO.popen command, &:read
- rescue TypeError # ruby 1.8 only supports string command
- r, w = IO.pipe
-
- pid = fork do
- STDIN.close
- STDOUT.reopen w
-
- exec(*command)
- end
-
- w.close
-
- begin
- return r.read
- ensure
- Process.wait pid
- end
- end
-
- NULL_DEVICE = defined?(IO::NULL) ? IO::NULL : Gem.win_platform? ? 'NUL' : '/dev/null'
-
- ##
- # Invokes system, but silences all output.
-
- def self.silent_system *command
- opt = {:out => NULL_DEVICE, :err => [:child, :out]}
- if Hash === command.last
- opt.update(command.last)
- cmds = command[0...-1]
- else
- cmds = command.dup
- end
- return system(*(cmds << opt))
- rescue TypeError
- require 'thread'
-
- @silent_mutex ||= Mutex.new
-
- null_device = NULL_DEVICE
-
- @silent_mutex.synchronize do
- begin
- stdout = STDOUT.dup
- stderr = STDERR.dup
-
- STDOUT.reopen null_device, 'w'
- STDERR.reopen null_device, 'w'
-
- return system(*command)
- ensure
- STDOUT.reopen stdout
- STDERR.reopen stderr
- stdout.close
- stderr.close
- end
- end
- end
-
- ##
- # Enumerates the parents of +directory+.
-
- def self.traverse_parents directory
- return enum_for __method__, directory unless block_given?
-
- here = File.expand_path directory
- start = here
-
- Dir.chdir start
-
- begin
- loop do
- yield here
-
- Dir.chdir '..'
-
- return if Dir.pwd == here # toplevel
-
- here = Dir.pwd
- end
- ensure
- Dir.chdir start
- end
- end
-
-end
diff --git a/ruby_2_2/lib/rubygems/util/list.rb b/ruby_2_2/lib/rubygems/util/list.rb
deleted file mode 100644
index 9bc11fe334..0000000000
--- a/ruby_2_2/lib/rubygems/util/list.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-module Gem
- List = Struct.new(:value, :tail)
-
- class List
- def each
- n = self
- while n
- yield n.value
- n = n.tail
- end
- end
-
- def to_a
- ary = []
- n = self
- while n
- ary.unshift n.value
- n = n.tail
- end
-
- ary
- end
-
- def find
- n = self
- while n
- v = n.value
- return v if yield(v)
- n = n.tail
- end
-
- nil
- end
-
- def prepend(value)
- List.new value, self
- end
-
- def pretty_print q # :nodoc:
- q.pp to_a
- end
-
- def self.prepend(list, value)
- return List.new(value) unless list
- List.new value, list
- end
- end
-end
diff --git a/ruby_2_2/lib/rubygems/util/stringio.rb b/ruby_2_2/lib/rubygems/util/stringio.rb
deleted file mode 100644
index 2ea69617bc..0000000000
--- a/ruby_2_2/lib/rubygems/util/stringio.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-class Gem::StringSink
- def initialize
- @string = ""
- end
-
- attr_reader :string
-
- def write(s)
- @string += s
- s.size
- end
-
- def set_encoding(enc)
- @string.force_encoding enc
- end
-end
-
-class Gem::StringSource
- def initialize(str)
- @string = str.dup
- end
-
- def read(count=nil)
- if count
- @string.slice!(0,count)
- else
- s = @string
- @string = ""
- s
- end
- end
-
- alias_method :readpartial, :read
-end
diff --git a/ruby_2_2/lib/rubygems/validator.rb b/ruby_2_2/lib/rubygems/validator.rb
deleted file mode 100644
index 6992af16ba..0000000000
--- a/ruby_2_2/lib/rubygems/validator.rb
+++ /dev/null
@@ -1,165 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'rubygems/package'
-require 'rubygems/installer'
-
-##
-# Validator performs various gem file and gem database validation
-
-class Gem::Validator
-
- include Gem::UserInteraction
-
- def initialize # :nodoc:
- require 'find'
- end
-
- ##
- # Given a gem file's contents, validates against its own MD5 checksum
- # gem_data:: [String] Contents of the gem file
-
- def verify_gem(gem_data)
- # TODO remove me? The code here only validate an MD5SUM that was
- # in some old formatted gems, but hasn't been for a long time.
- end
-
- ##
- # Given the path to a gem file, validates against its own MD5 checksum
- #
- # gem_path:: [String] Path to gem file
-
- def verify_gem_file(gem_path)
- open gem_path, Gem.binary_mode do |file|
- gem_data = file.read
- verify_gem gem_data
- end
- rescue Errno::ENOENT, Errno::EINVAL
- raise Gem::VerificationError, "missing gem file #{gem_path}"
- end
-
- private
-
- def find_files_for_gem(gem_directory)
- installed_files = []
-
- Find.find gem_directory do |file_name|
- fn = file_name[gem_directory.size..file_name.size-1].sub(/^\//, "")
- installed_files << fn unless
- fn =~ /CVS/ || fn.empty? || File.directory?(file_name)
- end
-
- installed_files
- end
-
- public
-
- ##
- # Describes a problem with a file in a gem.
-
- ErrorData = Struct.new :path, :problem do
- def <=> other # :nodoc:
- return nil unless self.class === other
-
- [path, problem] <=> [other.path, other.problem]
- end
- end
-
- ##
- # Checks the gem directory for the following potential
- # inconsistencies/problems:
- #
- # * Checksum gem itself
- # * For each file in each gem, check consistency of installed versions
- # * Check for files that aren't part of the gem but are in the gems directory
- # * 1 cache - 1 spec - 1 directory.
- #
- # returns a hash of ErrorData objects, keyed on the problem gem's name.
- #--
- # TODO needs further cleanup
-
- def alien(gems=[])
- errors = Hash.new { |h,k| h[k] = {} }
-
- Gem::Specification.each do |spec|
- next unless gems.include? spec.name unless gems.empty?
- next if spec.default_gem?
-
- gem_name = spec.file_name
- gem_path = spec.cache_file
- spec_path = spec.spec_file
- gem_directory = spec.full_gem_path
-
- unless File.directory? gem_directory then
- errors[gem_name][spec.full_name] =
- "Gem registered but doesn't exist at #{gem_directory}"
- next
- end
-
- unless File.exist? spec_path then
- errors[gem_name][spec_path] = "Spec file missing for installed gem"
- end
-
- begin
- verify_gem_file(gem_path)
-
- good, gone, unreadable = nil, nil, nil, nil
-
- open gem_path, Gem.binary_mode do |file|
- package = Gem::Package.new gem_path
-
- good, gone = package.contents.partition { |file_name|
- File.exist? File.join(gem_directory, file_name)
- }
-
- gone.sort.each do |path|
- errors[gem_name][path] = "Missing file"
- end
-
- good, unreadable = good.partition { |file_name|
- File.readable? File.join(gem_directory, file_name)
- }
-
- unreadable.sort.each do |path|
- errors[gem_name][path] = "Unreadable file"
- end
-
- good.each do |entry, data|
- begin
- next unless data # HACK `gem check -a mkrf`
-
- source = File.join gem_directory, entry['path']
-
- open source, Gem.binary_mode do |f|
- unless f.read == data then
- errors[gem_name][entry['path']] = "Modified from original"
- end
- end
- end
- end
- end
-
- installed_files = find_files_for_gem(gem_directory)
- extras = installed_files - good - unreadable
-
- extras.each do |extra|
- errors[gem_name][extra] = "Extra file"
- end
- rescue Gem::VerificationError => e
- errors[gem_name][gem_path] = e.message
- end
- end
-
- errors.each do |name, subhash|
- errors[name] = subhash.map do |path, msg|
- ErrorData.new path, msg
- end.sort
- end
-
- errors
- end
-end
-
diff --git a/ruby_2_2/lib/rubygems/version.rb b/ruby_2_2/lib/rubygems/version.rb
deleted file mode 100644
index 8335ebe182..0000000000
--- a/ruby_2_2/lib/rubygems/version.rb
+++ /dev/null
@@ -1,356 +0,0 @@
-##
-# The Version class processes string versions into comparable
-# values. A version string should normally be a series of numbers
-# separated by periods. Each part (digits separated by periods) is
-# considered its own number, and these are used for sorting. So for
-# instance, 3.10 sorts higher than 3.2 because ten is greater than
-# two.
-#
-# If any part contains letters (currently only a-z are supported) then
-# that version is considered prerelease. Versions with a prerelease
-# part in the Nth part sort less than versions with N-1
-# parts. Prerelease parts are sorted alphabetically using the normal
-# Ruby string sorting rules. If a prerelease part contains both
-# letters and numbers, it will be broken into multiple parts to
-# provide expected sort behavior (1.0.a10 becomes 1.0.a.10, and is
-# greater than 1.0.a9).
-#
-# Prereleases sort between real releases (newest to oldest):
-#
-# 1. 1.0
-# 2. 1.0.b1
-# 3. 1.0.a.2
-# 4. 0.9
-#
-# If you want to specify a version restriction that includes both prereleases
-# and regular releases of the 1.x series this is the best way:
-#
-# s.add_dependency 'example', '>= 1.0.0.a', '< 2.0.0'
-#
-# == How Software Changes
-#
-# Users expect to be able to specify a version constraint that gives them
-# some reasonable expectation that new versions of a library will work with
-# their software if the version constraint is true, and not work with their
-# software if the version constraint is false. In other words, the perfect
-# system will accept all compatible versions of the library and reject all
-# incompatible versions.
-#
-# Libraries change in 3 ways (well, more than 3, but stay focused here!).
-#
-# 1. The change may be an implementation detail only and have no effect on
-# the client software.
-# 2. The change may add new features, but do so in a way that client software
-# written to an earlier version is still compatible.
-# 3. The change may change the public interface of the library in such a way
-# that old software is no longer compatible.
-#
-# Some examples are appropriate at this point. Suppose I have a Stack class
-# that supports a <tt>push</tt> and a <tt>pop</tt> method.
-#
-# === Examples of Category 1 changes:
-#
-# * Switch from an array based implementation to a linked-list based
-# implementation.
-# * Provide an automatic (and transparent) backing store for large stacks.
-#
-# === Examples of Category 2 changes might be:
-#
-# * Add a <tt>depth</tt> method to return the current depth of the stack.
-# * Add a <tt>top</tt> method that returns the current top of stack (without
-# changing the stack).
-# * Change <tt>push</tt> so that it returns the item pushed (previously it
-# had no usable return value).
-#
-# === Examples of Category 3 changes might be:
-#
-# * Changes <tt>pop</tt> so that it no longer returns a value (you must use
-# <tt>top</tt> to get the top of the stack).
-# * Rename the methods to <tt>push_item</tt> and <tt>pop_item</tt>.
-#
-# == RubyGems Rational Versioning
-#
-# * Versions shall be represented by three non-negative integers, separated
-# by periods (e.g. 3.1.4). The first integers is the "major" version
-# number, the second integer is the "minor" version number, and the third
-# integer is the "build" number.
-#
-# * A category 1 change (implementation detail) will increment the build
-# number.
-#
-# * A category 2 change (backwards compatible) will increment the minor
-# version number and reset the build number.
-#
-# * A category 3 change (incompatible) will increment the major build number
-# and reset the minor and build numbers.
-#
-# * Any "public" release of a gem should have a different version. Normally
-# that means incrementing the build number. This means a developer can
-# generate builds all day long, but as soon as they make a public release,
-# the version must be updated.
-#
-# === Examples
-#
-# Let's work through a project lifecycle using our Stack example from above.
-#
-# Version 0.0.1:: The initial Stack class is release.
-# Version 0.0.2:: Switched to a linked=list implementation because it is
-# cooler.
-# Version 0.1.0:: Added a <tt>depth</tt> method.
-# Version 1.0.0:: Added <tt>top</tt> and made <tt>pop</tt> return nil
-# (<tt>pop</tt> used to return the old top item).
-# Version 1.1.0:: <tt>push</tt> now returns the value pushed (it used it
-# return nil).
-# Version 1.1.1:: Fixed a bug in the linked list implementation.
-# Version 1.1.2:: Fixed a bug introduced in the last fix.
-#
-# Client A needs a stack with basic push/pop capability. They write to the
-# original interface (no <tt>top</tt>), so their version constraint looks like:
-#
-# gem 'stack', '~> 0.0'
-#
-# Essentially, any version is OK with Client A. An incompatible change to
-# the library will cause them grief, but they are willing to take the chance
-# (we call Client A optimistic).
-#
-# Client B is just like Client A except for two things: (1) They use the
-# <tt>depth</tt> method and (2) they are worried about future
-# incompatibilities, so they write their version constraint like this:
-#
-# gem 'stack', '~> 0.1'
-#
-# The <tt>depth</tt> method was introduced in version 0.1.0, so that version
-# or anything later is fine, as long as the version stays below version 1.0
-# where incompatibilities are introduced. We call Client B pessimistic
-# because they are worried about incompatible future changes (it is OK to be
-# pessimistic!).
-#
-# == Preventing Version Catastrophe:
-#
-# From: http://blog.zenspider.com/2008/10/rubygems-howto-preventing-cata.html
-#
-# Let's say you're depending on the fnord gem version 2.y.z. If you
-# specify your dependency as ">= 2.0.0" then, you're good, right? What
-# happens if fnord 3.0 comes out and it isn't backwards compatible
-# with 2.y.z? Your stuff will break as a result of using ">=". The
-# better route is to specify your dependency with an "approximate" version
-# specifier ("~>"). They're a tad confusing, so here is how the dependency
-# specifiers work:
-#
-# Specification From ... To (exclusive)
-# ">= 3.0" 3.0 ... &infin;
-# "~> 3.0" 3.0 ... 4.0
-# "~> 3.0.0" 3.0.0 ... 3.1
-# "~> 3.5" 3.5 ... 4.0
-# "~> 3.5.0" 3.5.0 ... 3.6
-# "~> 3" 3.0 ... 4.0
-#
-# For the last example, single-digit versions are automatically extended with
-# a zero to give a sensible result.
-
-class Gem::Version
- autoload :Requirement, 'rubygems/requirement'
-
- include Comparable
-
- VERSION_PATTERN = '[0-9]+(?>\.[0-9a-zA-Z]+)*(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?' # :nodoc:
- ANCHORED_VERSION_PATTERN = /\A\s*(#{VERSION_PATTERN})?\s*\z/ # :nodoc:
-
- ##
- # A string representation of this Version.
-
- def version
- @version.dup
- end
-
- alias to_s version
-
- ##
- # True if the +version+ string matches RubyGems' requirements.
-
- def self.correct? version
- version.to_s =~ ANCHORED_VERSION_PATTERN
- end
-
- ##
- # Factory method to create a Version object. Input may be a Version
- # or a String. Intended to simplify client code.
- #
- # ver1 = Version.create('1.3.17') # -> (Version object)
- # ver2 = Version.create(ver1) # -> (ver1)
- # ver3 = Version.create(nil) # -> nil
-
- def self.create input
- if self === input then # check yourself before you wreck yourself
- input
- elsif input.nil? then
- nil
- else
- new input
- end
- end
-
- @@all = {}
-
- def self.new version # :nodoc:
- return super unless Gem::Version == self
-
- @@all[version] ||= super
- end
-
- ##
- # Constructs a Version from the +version+ string. A version string is a
- # series of digits or ASCII letters separated by dots.
-
- def initialize version
- raise ArgumentError, "Malformed version number string #{version}" unless
- self.class.correct?(version)
-
- @version = version.to_s.strip.gsub("-",".pre.")
- @segments = nil
- end
-
- ##
- # Return a new version object where the next to the last revision
- # number is one greater (e.g., 5.3.1 => 5.4).
- #
- # Pre-release (alpha) parts, e.g, 5.3.1.b.2 => 5.4, are ignored.
-
- def bump
- segments = self.segments.dup
- segments.pop while segments.any? { |s| String === s }
- segments.pop if segments.size > 1
-
- segments[-1] = segments[-1].succ
- self.class.new segments.join(".")
- end
-
- ##
- # A Version is only eql? to another version if it's specified to the
- # same precision. Version "1.0" is not the same as version "1".
-
- def eql? other
- self.class === other and @version == other.version
- end
-
- def hash # :nodoc:
- @hash ||= segments.hash
- end
-
- def init_with coder # :nodoc:
- yaml_initialize coder.tag, coder.map
- end
-
- def inspect # :nodoc:
- "#<#{self.class} #{version.inspect}>"
- end
-
- ##
- # Dump only the raw version string, not the complete object. It's a
- # string for backwards (RubyGems 1.3.5 and earlier) compatibility.
-
- def marshal_dump
- [version]
- end
-
- ##
- # Load custom marshal format. It's a string for backwards (RubyGems
- # 1.3.5 and earlier) compatibility.
-
- def marshal_load array
- initialize array[0]
- end
-
- def yaml_initialize(tag, map) # :nodoc:
- @version = map['version']
- @segments = nil
- @hash = nil
- end
-
- def to_yaml_properties # :nodoc:
- ["@version"]
- end
-
- def encode_with coder # :nodoc:
- coder.add 'version', @version
- end
-
- ##
- # A version is considered a prerelease if it contains a letter.
-
- def prerelease?
- @prerelease ||= !!(@version =~ /[a-zA-Z]/)
- end
-
- def pretty_print q # :nodoc:
- q.text "Gem::Version.new(#{version.inspect})"
- end
-
- ##
- # The release for this version (e.g. 1.2.0.a -> 1.2.0).
- # Non-prerelease versions return themselves.
-
- def release
- return self unless prerelease?
-
- segments = self.segments.dup
- segments.pop while segments.any? { |s| String === s }
- self.class.new segments.join('.')
- end
-
- def segments # :nodoc:
-
- # segments is lazy so it can pick up version values that come from
- # old marshaled versions, which don't go through marshal_load.
-
- @segments ||= @version.scan(/[0-9]+|[a-z]+/i).map do |s|
- /^\d+$/ =~ s ? s.to_i : s
- end
- end
-
- ##
- # A recommended version for use with a ~> Requirement.
-
- def approximate_recommendation
- segments = self.segments.dup
-
- segments.pop while segments.any? { |s| String === s }
- segments.pop while segments.size > 2
- segments.push 0 while segments.size < 2
-
- "~> #{segments.join(".")}"
- end
-
- ##
- # Compares this version with +other+ returning -1, 0, or 1 if the
- # other version is larger, the same, or smaller than this
- # one. Attempts to compare to something that's not a
- # <tt>Gem::Version</tt> return +nil+.
-
- def <=> other
- return unless Gem::Version === other
- return 0 if @version == other.version
-
- lhsegments = segments
- rhsegments = other.segments
-
- lhsize = lhsegments.size
- rhsize = rhsegments.size
- limit = (lhsize > rhsize ? lhsize : rhsize) - 1
-
- i = 0
-
- while i <= limit
- lhs, rhs = lhsegments[i] || 0, rhsegments[i] || 0
- i += 1
-
- next if lhs == rhs
- return -1 if String === lhs && Numeric === rhs
- return 1 if Numeric === lhs && String === rhs
-
- return lhs <=> rhs
- end
-
- return 0
- end
-end
diff --git a/ruby_2_2/lib/rubygems/version_option.rb b/ruby_2_2/lib/rubygems/version_option.rb
deleted file mode 100644
index a0755d5020..0000000000
--- a/ruby_2_2/lib/rubygems/version_option.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'rubygems'
-
-##
-# Mixin methods for --version and --platform Gem::Command options.
-
-module Gem::VersionOption
-
- ##
- # Add the --platform option to the option parser.
-
- def add_platform_option(task = command, *wrap)
- OptionParser.accept Gem::Platform do |value|
- if value == Gem::Platform::RUBY then
- value
- else
- Gem::Platform.new value
- end
- end
-
- add_option('--platform PLATFORM', Gem::Platform,
- "Specify the platform of gem to #{task}", *wrap) do
- |value, options|
- unless options[:added_platform] then
- Gem.platforms = [Gem::Platform::RUBY]
- options[:added_platform] = true
- end
-
- Gem.platforms << value unless Gem.platforms.include? value
- end
- end
-
- ##
- # Add the --prerelease option to the option parser.
-
- def add_prerelease_option(*wrap)
- add_option("--[no-]prerelease",
- "Allow prerelease versions of a gem", *wrap) do |value, options|
- options[:prerelease] = value
- options[:explicit_prerelease] = true
- end
- end
-
- ##
- # Add the --version option to the option parser.
-
- def add_version_option(task = command, *wrap)
- OptionParser.accept Gem::Requirement do |value|
- Gem::Requirement.new(*value.split(/\s*,\s*/))
- end
-
- add_option('-v', '--version VERSION', Gem::Requirement,
- "Specify version of gem to #{task}", *wrap) do
- |value, options|
- options[:version] = value
-
- explicit_prerelease_set = !options[:explicit_prerelease].nil?
- options[:explicit_prerelease] = false unless explicit_prerelease_set
-
- options[:prerelease] = value.prerelease? unless
- options[:explicit_prerelease]
- end
- end
-
-end
-
diff --git a/ruby_2_2/lib/scanf.rb b/ruby_2_2/lib/scanf.rb
deleted file mode 100644
index b6c5287664..0000000000
--- a/ruby_2_2/lib/scanf.rb
+++ /dev/null
@@ -1,776 +0,0 @@
-# scanf for Ruby
-#
-#--
-# $Release Version: 1.1.2 $
-# $Revision$
-# $Id$
-# $Author$
-#++
-#
-# == Description
-#
-# scanf is an implementation of the C function scanf(3), modified as necessary
-# for Ruby compatibility.
-#
-# the methods provided are String#scanf, IO#scanf, and
-# Kernel#scanf. Kernel#scanf is a wrapper around STDIN.scanf. IO#scanf
-# can be used on any IO stream, including file handles and sockets.
-# scanf can be called either with or without a block.
-#
-# Scanf scans an input string or stream according to a <b>format</b>, as
-# described below in Conversions, and returns an array of matches between
-# the format and the input. The format is defined in a string, and is
-# similar (though not identical) to the formats used in Kernel#printf and
-# Kernel#sprintf.
-#
-# The format may contain <b>conversion specifiers</b>, which tell scanf
-# what form (type) each particular matched substring should be converted
-# to (e.g., decimal integer, floating point number, literal string,
-# etc.) The matches and conversions take place from left to right, and
-# the conversions themselves are returned as an array.
-#
-# The format string may also contain characters other than those in the
-# conversion specifiers. White space (blanks, tabs, or newlines) in the
-# format string matches any amount of white space, including none, in
-# the input. Everything else matches only itself.
-#
-# Scanning stops, and scanf returns, when any input character fails to
-# match the specifications in the format string, or when input is
-# exhausted, or when everything in the format string has been
-# matched. All matches found up to the stopping point are returned in
-# the return array (or yielded to the block, if a block was given).
-#
-#
-# == Basic usage
-#
-# require 'scanf'
-#
-# # String#scanf and IO#scanf take a single argument, the format string
-# array = a_string.scanf("%d%s")
-# array = an_io.scanf("%d%s")
-#
-# # Kernel#scanf reads from STDIN
-# array = scanf("%d%s")
-#
-# == Block usage
-#
-# When called with a block, scanf keeps scanning the input, cycling back
-# to the beginning of the format string, and yields a new array of
-# conversions to the block every time the format string is matched
-# (including partial matches, but not including complete failures). The
-# actual return value of scanf when called with a block is an array
-# containing the results of all the executions of the block.
-#
-# str = "123 abc 456 def 789 ghi"
-# str.scanf("%d%s") { |num,str| [ num * 2, str.upcase ] }
-# # => [[246, "ABC"], [912, "DEF"], [1578, "GHI"]]
-#
-# == Conversions
-#
-# The single argument to scanf is a format string, which generally
-# includes one or more conversion specifiers. Conversion specifiers
-# begin with the percent character ('%') and include information about
-# what scanf should next scan for (string, decimal number, single
-# character, etc.).
-#
-# There may be an optional maximum field width, expressed as a decimal
-# integer, between the % and the conversion. If no width is given, a
-# default of `infinity' is used (with the exception of the %c specifier;
-# see below). Otherwise, given a field width of <em>n</em> for a given
-# conversion, at most <em>n</em> characters are scanned in processing
-# that conversion. Before conversion begins, most conversions skip
-# white space in the input string; this white space is not counted
-# against the field width.
-#
-# The following conversions are available.
-#
-# [%]
-# Matches a literal `%'. That is, `%%' in the format string matches a
-# single input `%' character. No conversion is done, and the resulting
-# '%' is not included in the return array.
-#
-# [d]
-# Matches an optionally signed decimal integer.
-#
-# [u]
-# Same as d.
-#
-# [i]
-# Matches an optionally signed integer. The integer is read in base
-# 16 if it begins with `0x' or `0X', in base 8 if it begins with `0',
-# and in base 10 other- wise. Only characters that correspond to the
-# base are recognized.
-#
-# [o]
-# Matches an optionally signed octal integer.
-#
-# [x, X]
-# Matches an optionally signed hexadecimal integer,
-#
-# [a, e, f, g, A, E, F, G]
-# Matches an optionally signed floating-point number.
-#
-# [s]
-# Matches a sequence of non-white-space character. The input string stops at
-# white space or at the maximum field width, whichever occurs first.
-#
-# [c]
-# Matches a single character, or a sequence of <em>n</em> characters if a
-# field width of <em>n</em> is specified. The usual skip of leading white
-# space is suppressed. To skip white space first, use an explicit space in
-# the format.
-#
-# [[]
-# Matches a nonempty sequence of characters from the specified set
-# of accepted characters. The usual skip of leading white space is
-# suppressed. This bracketed sub-expression is interpreted exactly like a
-# character class in a Ruby regular expression. (In fact, it is placed as-is
-# in a regular expression.) The matching against the input string ends with
-# the appearance of a character not in (or, with a circumflex, in) the set,
-# or when the field width runs out, whichever comes first.
-#
-# === Assignment suppression
-#
-# To require that a particular match occur, but without including the result
-# in the return array, place the <b>assignment suppression flag</b>, which is
-# the star character ('*'), immediately after the leading '%' of a format
-# specifier (just before the field width, if any).
-#
-# == scanf for Ruby compared with scanf in C
-#
-# scanf for Ruby is based on the C function scanf(3), but with modifications,
-# dictated mainly by the underlying differences between the languages.
-#
-# === Unimplemented flags and specifiers
-#
-# * The only flag implemented in scanf for Ruby is '<tt>*</tt>' (ignore
-# upcoming conversion). Many of the flags available in C versions of
-# scanf(3) have to do with the type of upcoming pointer arguments, and are
-# meaningless in Ruby.
-#
-# * The <tt>n</tt> specifier (store number of characters consumed so far in
-# next pointer) is not implemented.
-#
-# * The <tt>p</tt> specifier (match a pointer value) is not implemented.
-#
-# === Altered specifiers
-#
-# [o, u, x, X]
-# In scanf for Ruby, all of these specifiers scan for an optionally signed
-# integer, rather than for an unsigned integer like their C counterparts.
-#
-# === Return values
-#
-# scanf for Ruby returns an array of successful conversions, whereas
-# scanf(3) returns the number of conversions successfully
-# completed. (See below for more details on scanf for Ruby's return
-# values.)
-#
-# == Return values
-#
-# Without a block, scanf returns an array containing all the conversions
-# it has found. If none are found, scanf will return an empty array. An
-# unsuccessful match is never ignored, but rather always signals the end
-# of the scanning operation. If the first unsuccessful match takes place
-# after one or more successful matches have already taken place, the
-# returned array will contain the results of those successful matches.
-#
-# With a block scanf returns a 'map'-like array of transformations from
-# the block -- that is, an array reflecting what the block did with each
-# yielded result from the iterative scanf operation. (See "Block
-# usage", above.)
-#
-# == Current limitations and bugs
-#
-# When using IO#scanf under Windows, make sure you open your files in
-# binary mode:
-#
-# File.open("filename", "rb")
-#
-# so that scanf can keep track of characters correctly.
-#
-# Support for character classes is reasonably complete (since it
-# essentially piggy-backs on Ruby's regular expression handling of
-# character classes), but users are advised that character class testing
-# has not been exhaustive, and that they should exercise some caution
-# in using any of the more complex and/or arcane character class
-# idioms.
-#
-# == License and copyright
-#
-# Copyright:: (c) 2002-2003 David Alan Black
-# License:: Distributed on the same licensing terms as Ruby itself
-#
-# == Warranty disclaimer
-#
-# This software is provided "as is" and without any express or implied
-# warranties, including, without limitation, the implied warranties of
-# merchantability and fitness for a particular purpose.
-#
-# == Credits and acknowledgements
-#
-# scanf was developed as the major activity of the Austin Ruby Codefest
-# (Austin, Texas, August 2002).
-#
-# Principal author:: David Alan Black (mailto:dblack@superlink.net)
-# Co-author:: Hal Fulton (mailto:hal9000@hypermetrics.com)
-# Project contributors:: Nolan Darilek, Jason Johnston
-#
-# Thanks to Hal Fulton for hosting the Codefest.
-#
-# Thanks to Matz for suggestions about the class design.
-#
-# Thanks to Gavin Sinclair for some feedback on the documentation.
-#
-# The text for parts of this document, especially the Description and
-# Conversions sections, above, were adapted from the Linux Programmer's
-# Manual manpage for scanf(3), dated 1995-11-01.
-#
-# == Bugs and bug reports
-#
-# scanf for Ruby is based on something of an amalgam of C scanf
-# implementations and documentation, rather than on a single canonical
-# description. Suggestions for features and behaviors which appear in
-# other scanfs, and would be meaningful in Ruby, are welcome, as are
-# reports of suspicious behaviors and/or bugs. (Please see "Credits and
-# acknowledgements", above, for email addresses.)
-
-module Scanf
- # :stopdoc:
-
- # ==Technical notes
- #
- # ===Rationale behind scanf for Ruby
- #
- # The impetus for a scanf implementation in Ruby comes chiefly from the fact
- # that existing pattern matching operations, such as Regexp#match and
- # String#scan, return all results as strings, which have to be converted to
- # integers or floats explicitly in cases where what's ultimately wanted are
- # integer or float values.
- #
- # ===Design of scanf for Ruby
- #
- # scanf for Ruby is essentially a <format string>-to-<regular
- # expression> converter.
- #
- # When scanf is called, a FormatString object is generated from the
- # format string ("%d%s...") argument. The FormatString object breaks the
- # format string down into atoms ("%d", "%5f", "blah", etc.), and from
- # each atom it creates a FormatSpecifier object, which it
- # saves.
- #
- # Each FormatSpecifier has a regular expression fragment and a "handler"
- # associated with it. For example, the regular expression fragment
- # associated with the format "%d" is "([-+]?\d+)", and the handler
- # associated with it is a wrapper around String#to_i. scanf itself calls
- # FormatString#match, passing in the input string. FormatString#match
- # iterates through its FormatSpecifiers; for each one, it matches the
- # corresponding regular expression fragment against the string. If
- # there's a match, it sends the matched string to the handler associated
- # with the FormatSpecifier.
- #
- # Thus, to follow up the "%d" example: if "123" occurs in the input
- # string when a FormatSpecifier consisting of "%d" is reached, the "123"
- # will be matched against "([-+]?\d+)", and the matched string will be
- # rendered into an integer by a call to to_i.
- #
- # The rendered match is then saved to an accumulator array, and the
- # input string is reduced to the post-match substring. Thus the string
- # is "eaten" from the left as the FormatSpecifiers are applied in
- # sequence. (This is done to a duplicate string; the original string is
- # not altered.)
- #
- # As soon as a regular expression fragment fails to match the string, or
- # when the FormatString object runs out of FormatSpecifiers, scanning
- # stops and results accumulated so far are returned in an array.
-
- class FormatSpecifier
-
- attr_reader :re_string, :matched_string, :conversion, :matched
-
- private
-
- def skip; /^\s*%\*/.match(@spec_string); end
-
- def extract_float(s)
- return nil unless s &&! skip
- if /\A(?<sign>[-+]?)0[xX](?<frac>\.\h+|\h+(?:\.\h*)?)[pP](?<exp>[-+]\d+)/ =~ s
- f1, f2 = frac.split('.')
- f = f1.hex
- if f2
- len = f2.length
- if len > 0
- f += f2.hex / (16.0 ** len)
- end
- end
- (sign == ?- ? -1 : 1) * Math.ldexp(f, exp.to_i)
- elsif /\A([-+]?\d+)\.([eE][-+]\d+)/ =~ s
- ($1 << $2).to_f
- else
- s.to_f
- end
- end
- def extract_decimal(s); s.to_i if s &&! skip; end
- def extract_hex(s); s.hex if s &&! skip; end
- def extract_octal(s); s.oct if s &&! skip; end
- def extract_integer(s); Integer(s) if s &&! skip; end
- def extract_plain(s); s unless skip; end
-
- def nil_proc(s); nil; end
-
- public
-
- def to_s
- @spec_string
- end
-
- def count_space?
- /(?:\A|\S)%\*?\d*c|%\d*\[/.match(@spec_string)
- end
-
- def initialize(str)
- @spec_string = str
- h = '[A-Fa-f0-9]'
-
- @re_string, @handler =
- case @spec_string
-
- # %[[:...:]]
- when /%\*?(\[\[:[a-z]+:\]\])/
- [ "(#{$1}+)", :extract_plain ]
-
- # %5[[:...:]]
- when /%\*?(\d+)(\[\[:[a-z]+:\]\])/
- [ "(#{$2}{1,#{$1}})", :extract_plain ]
-
- # %[...]
- when /%\*?\[([^\]]*)\]/
- yes = $1
- if /^\^/.match(yes) then no = yes[1..-1] else no = '^' + yes end
- [ "([#{yes}]+)(?=[#{no}]|\\z)", :extract_plain ]
-
- # %5[...]
- when /%\*?(\d+)\[([^\]]*)\]/
- yes = $2
- w = $1
- [ "([#{yes}]{1,#{w}})", :extract_plain ]
-
- # %i
- when /%\*?i/
- [ "([-+]?(?:(?:0[0-7]+)|(?:0[Xx]#{h}+)|(?:[1-9]\\d*)))", :extract_integer ]
-
- # %5i
- when /%\*?(\d+)i/
- n = $1.to_i
- s = "("
- if n > 1 then s += "[1-9]\\d{1,#{n-1}}|" end
- if n > 1 then s += "0[0-7]{1,#{n-1}}|" end
- if n > 2 then s += "[-+]0[0-7]{1,#{n-2}}|" end
- if n > 2 then s += "[-+][1-9]\\d{1,#{n-2}}|" end
- if n > 2 then s += "0[Xx]#{h}{1,#{n-2}}|" end
- if n > 3 then s += "[-+]0[Xx]#{h}{1,#{n-3}}|" end
- s += "\\d"
- s += ")"
- [ s, :extract_integer ]
-
- # %d, %u
- when /%\*?[du]/
- [ '([-+]?\d+)', :extract_decimal ]
-
- # %5d, %5u
- when /%\*?(\d+)[du]/
- n = $1.to_i
- s = "("
- if n > 1 then s += "[-+]\\d{1,#{n-1}}|" end
- s += "\\d{1,#{$1}})"
- [ s, :extract_decimal ]
-
- # %x
- when /%\*?[Xx]/
- [ "([-+]?(?:0[Xx])?#{h}+)", :extract_hex ]
-
- # %5x
- when /%\*?(\d+)[Xx]/
- n = $1.to_i
- s = "("
- if n > 3 then s += "[-+]0[Xx]#{h}{1,#{n-3}}|" end
- if n > 2 then s += "0[Xx]#{h}{1,#{n-2}}|" end
- if n > 1 then s += "[-+]#{h}{1,#{n-1}}|" end
- s += "#{h}{1,#{n}}"
- s += ")"
- [ s, :extract_hex ]
-
- # %o
- when /%\*?o/
- [ '([-+]?[0-7]+)', :extract_octal ]
-
- # %5o
- when /%\*?(\d+)o/
- [ "([-+][0-7]{1,#{$1.to_i-1}}|[0-7]{1,#{$1}})", :extract_octal ]
-
- # %f
- when /%\*?[aefgAEFG]/
- [ '([-+]?(?:0[xX](?:\.\h+|\h+(?:\.\h*)?)[pP][-+]\d+|\d+(?![\d.])|\d*\.\d*(?:[eE][-+]?\d+)?))', :extract_float ]
-
- # %5f
- when /%\*?(\d+)[aefgAEFG]/
- [ '(?=[-+]?(?:0[xX](?:\.\h+|\h+(?:\.\h*)?)[pP][-+]\d+|\d+(?![\d.])|\d*\.\d*(?:[eE][-+]?\d+)?))' +
- "(\\S{1,#{$1}})", :extract_float ]
-
- # %5s
- when /%\*?(\d+)s/
- [ "(\\S{1,#{$1}})", :extract_plain ]
-
- # %s
- when /%\*?s/
- [ '(\S+)', :extract_plain ]
-
- # %c
- when /\s%\*?c/
- [ "\\s*(.)", :extract_plain ]
-
- # %c
- when /%\*?c/
- [ "(.)", :extract_plain ]
-
- # %5c (whitespace issues are handled by the count_*_space? methods)
- when /%\*?(\d+)c/
- [ "(.{1,#{$1}})", :extract_plain ]
-
- # %%
- when /%%/
- [ '(\s*%)', :nil_proc ]
-
- # literal characters
- else
- [ "(#{Regexp.escape(@spec_string)})", :nil_proc ]
- end
-
- @re_string = '\A' + @re_string
- end
-
- def to_re
- Regexp.new(@re_string,Regexp::MULTILINE)
- end
-
- def match(str)
- @matched = false
- s = str.dup
- s.sub!(/\A\s+/,'') unless count_space?
- res = to_re.match(s)
- if res
- @conversion = send(@handler, res[1])
- @matched_string = @conversion.to_s
- @matched = true
- end
- res
- end
-
- def letter
- @spec_string[/%\*?\d*([a-z\[])/, 1]
- end
-
- def width
- w = @spec_string[/%\*?(\d+)/, 1]
- w && w.to_i
- end
-
- def mid_match?
- return false unless @matched
- cc_no_width = letter == '[' &&! width
- c_or_cc_width = (letter == 'c' || letter == '[') && width
- width_left = c_or_cc_width && (matched_string.size < width)
-
- return width_left || cc_no_width
- end
-
- end
-
- class FormatString
-
- attr_reader :string_left, :last_spec_tried,
- :last_match_tried, :matched_count, :space
-
- SPECIFIERS = 'diuXxofFeEgGscaA'
- REGEX = /
- # possible space, followed by...
- (?:\s*
- # percent sign, followed by...
- %
- # another percent sign, or...
- (?:%|
- # optional assignment suppression flag
- \*?
- # optional maximum field width
- \d*
- # named character class, ...
- (?:\[\[:\w+:\]\]|
- # traditional character class, or...
- \[[^\]]*\]|
- # specifier letter.
- [#{SPECIFIERS}])))|
- # or miscellaneous characters
- [^%\s]+/ix
-
- def initialize(str)
- @specs = []
- @i = 1
- s = str.to_s
- return unless /\S/.match(s)
- @space = true if /\s\z/.match(s)
- @specs.replace s.scan(REGEX).map {|spec| FormatSpecifier.new(spec) }
- end
-
- def to_s
- @specs.join('')
- end
-
- def prune(n=matched_count)
- n.times { @specs.shift }
- end
-
- def spec_count
- @specs.size
- end
-
- def last_spec
- @i == spec_count - 1
- end
-
- def match(str)
- accum = []
- @string_left = str
- @matched_count = 0
-
- @specs.each_with_index do |spec,i|
- @i=i
- @last_spec_tried = spec
- @last_match_tried = spec.match(@string_left)
- break unless @last_match_tried
- @matched_count += 1
-
- accum << spec.conversion
-
- @string_left = @last_match_tried.post_match
- break if @string_left.empty?
- end
- return accum.compact
- end
- end
- # :startdoc:
-end
-
-class IO
-
- #:stopdoc:
- # The trick here is doing a match where you grab one *line*
- # of input at a time. The linebreak may or may not occur
- # at the boundary where the string matches a format specifier.
- # And if it does, some rule about whitespace may or may not
- # be in effect...
- #
- # That's why this is much more elaborate than the string
- # version.
- #
- # For each line:
- #
- # Match succeeds (non-emptily)
- # and the last attempted spec/string sub-match succeeded:
- #
- # could the last spec keep matching?
- # yes: save interim results and continue (next line)
- #
- # The last attempted spec/string did not match:
- #
- # are we on the next-to-last spec in the string?
- # yes:
- # is fmt_string.string_left all spaces?
- # yes: does current spec care about input space?
- # yes: fatal failure
- # no: save interim results and continue
- # no: continue [this state could be analyzed further]
- #
- #:startdoc:
-
- # Scans the current string until the match is exhausted,
- # yielding each match as it is encountered in the string.
- # A block is not necessary though, as the results will simply
- # be aggregated into the final array.
- #
- # "123 456".block_scanf("%d")
- # # => [123, 456]
- #
- # If a block is given, the value from that is returned from
- # the yield is added to an output array.
- #
- # "123 456".block_scanf("%d") do |digit,| # the ',' unpacks the Array
- # digit + 100
- # end
- # # => [223, 556]
- #
- # See Scanf for details on creating a format string.
- #
- # You will need to require 'scanf' to use use IO#scanf.
- def scanf(str,&b) #:yield: current_match
- return block_scanf(str,&b) if b
- return [] unless str.size > 0
-
- start_position = pos rescue 0
- matched_so_far = 0
- source_buffer = ""
- result_buffer = []
- final_result = []
-
- fstr = Scanf::FormatString.new(str)
-
- loop do
- if eof || (tty? &&! fstr.match(source_buffer))
- final_result.concat(result_buffer)
- break
- end
-
- source_buffer << gets
-
- current_match = fstr.match(source_buffer)
-
- spec = fstr.last_spec_tried
-
- if spec.matched
- if spec.mid_match?
- result_buffer.replace(current_match)
- next
- end
-
- elsif (fstr.matched_count == fstr.spec_count - 1)
- if /\A\s*\z/.match(fstr.string_left)
- break if spec.count_space?
- result_buffer.replace(current_match)
- next
- end
- end
-
- final_result.concat(current_match)
-
- matched_so_far += source_buffer.size
- source_buffer.replace(fstr.string_left)
- matched_so_far -= source_buffer.size
- break if fstr.last_spec
- fstr.prune
- end
-
- begin
- seek(start_position + matched_so_far, IO::SEEK_SET)
- rescue Errno::ESPIPE
- end
-
- soak_up_spaces if fstr.last_spec && fstr.space
-
- return final_result
- end
-
- private
-
- def soak_up_spaces
- c = getc
- ungetc(c) if c
- until eof ||! c || /\S/.match(c.chr)
- c = getc
- end
- ungetc(c) if (c && /\S/.match(c.chr))
- end
-
- def block_scanf(str)
- final = []
-# Sub-ideal, since another FS gets created in scanf.
-# But used here to determine the number of specifiers.
- fstr = Scanf::FormatString.new(str)
- last_spec = fstr.last_spec
- begin
- current = scanf(str)
- break if current.empty?
- final.push(yield(current))
- end until eof || fstr.last_spec_tried == last_spec
- return final
- end
-end
-
-class String
-
- # :section: scanf
- #
- # You will need to require 'scanf' to use these methods
-
- # Scans the current string. If a block is given, it
- # functions exactly like block_scanf.
- #
- # arr = "123 456".scanf("%d%d")
- # # => [123, 456]
- #
- # require 'pp'
- #
- # "this 123 read that 456 other".scanf("%s%d%s") {|m| pp m}
- #
- # # ["this", 123, "read"]
- # # ["that", 456, "other"]
- # # => [["this", 123, "read"], ["that", 456, "other"]]
- #
- # See Scanf for details on creating a format string.
- #
- # You will need to require 'scanf' to use String#scanf
- def scanf(fstr,&b) #:yield: current_match
- if b
- block_scanf(fstr,&b)
- else
- fs =
- if fstr.is_a? Scanf::FormatString
- fstr
- else
- Scanf::FormatString.new(fstr)
- end
- fs.match(self)
- end
- end
-
- # Scans the current string until the match is exhausted
- # yielding each match as it is encountered in the string.
- # A block is not necessary as the results will simply
- # be aggregated into the final array.
- #
- # "123 456".block_scanf("%d")
- # # => [123, 456]
- #
- # If a block is given, the value from that is returned from
- # the yield is added to an output array.
- #
- # "123 456".block_scanf("%d) do |digit,| # the ',' unpacks the Array
- # digit + 100
- # end
- # # => [223, 556]
- #
- # See Scanf for details on creating a format string.
- #
- # You will need to require 'scanf' to use String#block_scanf
- def block_scanf(fstr) #:yield: current_match
- fs = Scanf::FormatString.new(fstr)
- str = self.dup
- final = []
- begin
- current = str.scanf(fs)
- final.push(yield(current)) unless current.empty?
- str = fs.string_left
- end until current.empty? || str.empty?
- return final
- end
-end
-
-module Kernel
- private
- # Scans STDIN for data matching +format+. See IO#scanf for details.
- #
- # See Scanf for details on creating a format string.
- #
- # You will need to require 'scanf' to use Kernel#scanf.
- def scanf(format, &b) #:doc:
- STDIN.scanf(format ,&b)
- end
-end
diff --git a/ruby_2_2/lib/securerandom.rb b/ruby_2_2/lib/securerandom.rb
deleted file mode 100644
index 9c258603a6..0000000000
--- a/ruby_2_2/lib/securerandom.rb
+++ /dev/null
@@ -1,293 +0,0 @@
-# -*- coding: us-ascii -*-
-begin
- require 'openssl'
-rescue LoadError
-end
-
-# == Secure random number generator interface.
-#
-# This library is an interface for secure random number generator which is
-# suitable for generating session key in HTTP cookies, etc.
-#
-# You can use this library in your application by requiring it:
-#
-# require 'securerandom'
-#
-# It supports following secure random number generators.
-#
-# * openssl
-# * /dev/urandom
-# * Win32
-#
-# === Examples
-#
-# Hexadecimal string.
-#
-# require 'securerandom'
-#
-# p SecureRandom.hex(10) #=> "52750b30ffbc7de3b362"
-# p SecureRandom.hex(10) #=> "92b15d6c8dc4beb5f559"
-# p SecureRandom.hex(13) #=> "39b290146bea6ce975c37cfc23"
-#
-# Base64 string.
-#
-# p SecureRandom.base64(10) #=> "EcmTPZwWRAozdA=="
-# p SecureRandom.base64(10) #=> "KO1nIU+p9DKxGg=="
-# p SecureRandom.base64(12) #=> "7kJSM/MzBJI+75j8"
-#
-# Binary string.
-#
-# p SecureRandom.random_bytes(10) #=> "\016\t{\370g\310pbr\301"
-# p SecureRandom.random_bytes(10) #=> "\323U\030TO\234\357\020\a\337"
-module SecureRandom
- if /mswin|mingw/ =~ RUBY_PLATFORM
- require "fiddle/import"
-
- module AdvApi32 # :nodoc:
- extend Fiddle::Importer
- dlload "advapi32"
- extern "int CryptAcquireContext(void*, void*, void*, unsigned long, unsigned long)"
- extern "int CryptGenRandom(void*, unsigned long, void*)"
-
- def self.get_provider
- hProvStr = " " * Fiddle::SIZEOF_VOIDP
- prov_rsa_full = 1
- crypt_verifycontext = 0xF0000000
-
- if CryptAcquireContext(hProvStr, nil, nil, prov_rsa_full, crypt_verifycontext) == 0
- raise SystemCallError, "CryptAcquireContext failed: #{lastWin32ErrorMessage}"
- end
- type = Fiddle::SIZEOF_VOIDP == Fiddle::SIZEOF_LONG_LONG ? 'q' : 'l'
- hProv, = hProvStr.unpack(type)
- hProv
- end
-
- def self.gen_random(n)
- @hProv ||= get_provider
- bytes = " ".force_encoding("ASCII-8BIT") * n
- if CryptGenRandom(@hProv, bytes.size, bytes) == 0
- raise SystemCallError, "CryptGenRandom failed: #{Kernel32.last_error_message}"
- end
- bytes
- end
- end
-
- module Kernel32 # :nodoc:
- extend Fiddle::Importer
- dlload "kernel32"
- extern "unsigned long GetLastError()"
- extern "unsigned long FormatMessageA(unsigned long, void*, unsigned long, unsigned long, void*, unsigned long, void*)"
-
- # Following code is based on David Garamond's GUID library for Ruby.
- def self.last_error_message
- format_message_ignore_inserts = 0x00000200
- format_message_from_system = 0x00001000
-
- code = GetLastError()
- msg = "\0" * 1024
- len = FormatMessageA(format_message_ignore_inserts + format_message_from_system, 0, code, 0, msg, 1024, nil)
- msg[0, len].force_encoding("filesystem").tr("\r", '').chomp
- end
- end
- end
-
- # SecureRandom.random_bytes generates a random binary string.
- #
- # The argument _n_ specifies the length of the result string.
- #
- # If _n_ is not specified or is nil, 16 is assumed.
- # It may be larger in future.
- #
- # The result may contain any byte: "\x00" - "\xff".
- #
- # p SecureRandom.random_bytes #=> "\xD8\\\xE0\xF4\r\xB2\xFC*WM\xFF\x83\x18\xF45\xB6"
- # p SecureRandom.random_bytes #=> "m\xDC\xFC/\a\x00Uf\xB2\xB2P\xBD\xFF6S\x97"
- #
- # If secure random number generator is not available,
- # NotImplementedError is raised.
- def self.random_bytes(n=nil)
- n = n ? n.to_int : 16
- gen_random(n)
- end
-
- if defined?(OpenSSL::Random) && !defined?(AdvApi32)
- def self.gen_random(n)
- @pid = 0 unless defined?(@pid)
- pid = $$
- unless @pid == pid
- now = Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond)
- ary = [now, @pid, pid]
- OpenSSL::Random.random_add(ary.join("").to_s, 0.0)
- @pid = pid
- end
- return OpenSSL::Random.random_bytes(n)
- end
- elsif defined?(AdvApi32)
- def self.gen_random(n)
- return AdvApi32.gen_random(n)
- end
-
- def self.lastWin32ErrorMessage # :nodoc:
- # for compatibility
- return Kernel32.last_error_message
- end
- else
- def self.gen_random(n)
- flags = File::RDONLY
- flags |= File::NONBLOCK if defined? File::NONBLOCK
- flags |= File::NOCTTY if defined? File::NOCTTY
- begin
- File.open("/dev/urandom", flags) {|f|
- unless f.stat.chardev?
- break
- end
- ret = f.read(n)
- unless ret.length == n
- raise NotImplementedError, "Unexpected partial read from random device: only #{ret.length} for #{n} bytes"
- end
- return ret
- }
- rescue Errno::ENOENT
- end
-
- raise NotImplementedError, "No random device"
- end
- end
-
- # SecureRandom.hex generates a random hexadecimal string.
- #
- # The argument _n_ specifies the length, in bytes, of the random number to be generated.
- # The length of the resulting hexadecimal string is twice _n_.
- #
- # If _n_ is not specified or is nil, 16 is assumed.
- # It may be larger in future.
- #
- # The result may contain 0-9 and a-f.
- #
- # p SecureRandom.hex #=> "eb693ec8252cd630102fd0d0fb7c3485"
- # p SecureRandom.hex #=> "91dc3bfb4de5b11d029d376634589b61"
- #
- # If secure random number generator is not available,
- # NotImplementedError is raised.
- def self.hex(n=nil)
- random_bytes(n).unpack("H*")[0]
- end
-
- # SecureRandom.base64 generates a random base64 string.
- #
- # The argument _n_ specifies the length, in bytes, of the random number
- # to be generated. The length of the result string is about 4/3 of _n_.
- #
- # If _n_ is not specified or is nil, 16 is assumed.
- # It may be larger in future.
- #
- # The result may contain A-Z, a-z, 0-9, "+", "/" and "=".
- #
- # p SecureRandom.base64 #=> "/2BuBuLf3+WfSKyQbRcc/A=="
- # p SecureRandom.base64 #=> "6BbW0pxO0YENxn38HMUbcQ=="
- #
- # If secure random number generator is not available,
- # NotImplementedError is raised.
- #
- # See RFC 3548 for the definition of base64.
- def self.base64(n=nil)
- [random_bytes(n)].pack("m*").delete("\n")
- end
-
- # SecureRandom.urlsafe_base64 generates a random URL-safe base64 string.
- #
- # The argument _n_ specifies the length, in bytes, of the random number
- # to be generated. The length of the result string is about 4/3 of _n_.
- #
- # If _n_ is not specified or is nil, 16 is assumed.
- # It may be larger in future.
- #
- # The boolean argument _padding_ specifies the padding.
- # If it is false or nil, padding is not generated.
- # Otherwise padding is generated.
- # By default, padding is not generated because "=" may be used as a URL delimiter.
- #
- # The result may contain A-Z, a-z, 0-9, "-" and "_".
- # "=" is also used if _padding_ is true.
- #
- # p SecureRandom.urlsafe_base64 #=> "b4GOKm4pOYU_-BOXcrUGDg"
- # p SecureRandom.urlsafe_base64 #=> "UZLdOkzop70Ddx-IJR0ABg"
- #
- # p SecureRandom.urlsafe_base64(nil, true) #=> "i0XQ-7gglIsHGV2_BNPrdQ=="
- # p SecureRandom.urlsafe_base64(nil, true) #=> "-M8rLhr7JEpJlqFGUMmOxg=="
- #
- # If secure random number generator is not available,
- # NotImplementedError is raised.
- #
- # See RFC 3548 for the definition of URL-safe base64.
- def self.urlsafe_base64(n=nil, padding=false)
- s = [random_bytes(n)].pack("m*")
- s.delete!("\n")
- s.tr!("+/", "-_")
- s.delete!("=") unless padding
- s
- end
-
- # SecureRandom.random_number generates a random number.
- #
- # If a positive integer is given as _n_,
- # SecureRandom.random_number returns an integer:
- # 0 <= SecureRandom.random_number(n) < n.
- #
- # p SecureRandom.random_number(100) #=> 15
- # p SecureRandom.random_number(100) #=> 88
- #
- # If 0 is given or an argument is not given,
- # SecureRandom.random_number returns a float:
- # 0.0 <= SecureRandom.random_number() < 1.0.
- #
- # p SecureRandom.random_number #=> 0.596506046187744
- # p SecureRandom.random_number #=> 0.350621695741409
- #
- def self.random_number(n=0)
- if 0 < n
- if defined? OpenSSL::BN
- OpenSSL::BN.rand_range(n).to_i
- else
- hex = n.to_s(16)
- hex = '0' + hex if (hex.length & 1) == 1
- bin = [hex].pack("H*")
- mask = bin[0].ord
- mask |= mask >> 1
- mask |= mask >> 2
- mask |= mask >> 4
- begin
- rnd = SecureRandom.random_bytes(bin.length)
- rnd[0] = (rnd[0].ord & mask).chr
- end until rnd < bin
- rnd.unpack("H*")[0].hex
- end
- else
- # assumption: Float::MANT_DIG <= 64
- if defined? OpenSSL::BN
- i64 = OpenSSL::BN.rand(64, -1).to_i
- else
- i64 = SecureRandom.random_bytes(8).unpack("Q")[0]
- end
- Math.ldexp(i64 >> (64-Float::MANT_DIG), -Float::MANT_DIG)
- end
- end
-
- # SecureRandom.uuid generates a v4 random UUID (Universally Unique IDentifier).
- #
- # p SecureRandom.uuid #=> "2d931510-d99f-494a-8c67-87feb05e1594"
- # p SecureRandom.uuid #=> "bad85eb9-0713-4da7-8d36-07a8e4b00eab"
- # p SecureRandom.uuid #=> "62936e70-1815-439b-bf89-8492855a7e6b"
- #
- # The version 4 UUID is purely random (except the version).
- # It doesn't contain meaningful information such as MAC address, time, etc.
- #
- # See RFC 4122 for details of UUID.
- #
- def self.uuid
- ary = self.random_bytes(16).unpack("NnnnnN")
- ary[2] = (ary[2] & 0x0fff) | 0x4000
- ary[3] = (ary[3] & 0x3fff) | 0x8000
- "%08x-%04x-%04x-%04x-%04x%08x" % ary
- end
-end
diff --git a/ruby_2_2/lib/set.rb b/ruby_2_2/lib/set.rb
deleted file mode 100644
index f00cfac0c5..0000000000
--- a/ruby_2_2/lib/set.rb
+++ /dev/null
@@ -1,787 +0,0 @@
-#--
-# set.rb - defines the Set class
-#++
-# Copyright (c) 2002-2013 Akinori MUSHA <knu@iDaemons.org>
-#
-# Documentation by Akinori MUSHA and Gavin Sinclair.
-#
-# All rights reserved. You can redistribute and/or modify it under the same
-# terms as Ruby.
-#
-# $Id$
-#
-# == Overview
-#
-# This library provides the Set class, which deals with a collection
-# of unordered values with no duplicates. It is a hybrid of Array's
-# intuitive inter-operation facilities and Hash's fast lookup. If you
-# need to keep values sorted in some order, use the SortedSet class.
-#
-# The method +to_set+ is added to Enumerable for convenience.
-#
-# See the Set and SortedSet documentation for examples of usage.
-
-
-#
-# Set implements a collection of unordered values with no duplicates.
-# This is a hybrid of Array's intuitive inter-operation facilities and
-# Hash's fast lookup.
-#
-# Set is easy to use with Enumerable objects (implementing +each+).
-# Most of the initializer methods and binary operators accept generic
-# Enumerable objects besides sets and arrays. An Enumerable object
-# can be converted to Set using the +to_set+ method.
-#
-# Set uses Hash as storage, so you must note the following points:
-#
-# * Equality of elements is determined according to Object#eql? and
-# Object#hash.
-# * Set assumes that the identity of each element does not change
-# while it is stored. Modifying an element of a set will render the
-# set to an unreliable state.
-# * When a string is to be stored, a frozen copy of the string is
-# stored instead unless the original string is already frozen.
-#
-# == Comparison
-#
-# The comparison operators <, >, <= and >= are implemented as
-# shorthand for the {proper_,}{subset?,superset?} methods. However,
-# the <=> operator is intentionally left out because not every pair of
-# sets is comparable. ({x,y} vs. {x,z} for example)
-#
-# == Example
-#
-# require 'set'
-# s1 = Set.new [1, 2] # -> #<Set: {1, 2}>
-# s2 = [1, 2].to_set # -> #<Set: {1, 2}>
-# s1 == s2 # -> true
-# s1.add("foo") # -> #<Set: {1, 2, "foo"}>
-# s1.merge([2, 6]) # -> #<Set: {1, 2, "foo", 6}>
-# s1.subset? s2 # -> false
-# s2.subset? s1 # -> true
-#
-# == Contact
-#
-# - Akinori MUSHA <knu@iDaemons.org> (current maintainer)
-#
-class Set
- include Enumerable
-
- # Creates a new set containing the given objects.
- def self.[](*ary)
- new(ary)
- end
-
- # Creates a new set containing the elements of the given enumerable
- # object.
- #
- # If a block is given, the elements of enum are preprocessed by the
- # given block.
- def initialize(enum = nil, &block) # :yields: o
- @hash ||= Hash.new
-
- enum.nil? and return
-
- if block
- do_with_enum(enum) { |o| add(block[o]) }
- else
- merge(enum)
- end
- end
-
- def do_with_enum(enum, &block) # :nodoc:
- if enum.respond_to?(:each_entry)
- enum.each_entry(&block) if block
- elsif enum.respond_to?(:each)
- enum.each(&block) if block
- else
- raise ArgumentError, "value must be enumerable"
- end
- end
- private :do_with_enum
-
- # Dup internal hash.
- def initialize_dup(orig)
- super
- @hash = orig.instance_variable_get(:@hash).dup
- end
-
- # Clone internal hash.
- def initialize_clone(orig)
- super
- @hash = orig.instance_variable_get(:@hash).clone
- end
-
- def freeze # :nodoc:
- @hash.freeze
- super
- end
-
- def taint # :nodoc:
- @hash.taint
- super
- end
-
- def untaint # :nodoc:
- @hash.untaint
- super
- end
-
- # Returns the number of elements.
- def size
- @hash.size
- end
- alias length size
-
- # Returns true if the set contains no elements.
- def empty?
- @hash.empty?
- end
-
- # Removes all elements and returns self.
- def clear
- @hash.clear
- self
- end
-
- # Replaces the contents of the set with the contents of the given
- # enumerable object and returns self.
- def replace(enum)
- if enum.instance_of?(self.class)
- @hash.replace(enum.instance_variable_get(:@hash))
- self
- else
- do_with_enum(enum)
- clear
- merge(enum)
- end
- end
-
- # Converts the set to an array. The order of elements is uncertain.
- def to_a
- @hash.keys
- end
-
- # Returns self if no arguments are given. Otherwise, converts the
- # set to another with klass.new(self, *args, &block).
- #
- # In subclasses, returns klass.new(self, *args, &block) unless
- # overridden.
- def to_set(klass = Set, *args, &block)
- return self if instance_of?(Set) && klass == Set && block.nil? && args.empty?
- klass.new(self, *args, &block)
- end
-
- def flatten_merge(set, seen = Set.new) # :nodoc:
- set.each { |e|
- if e.is_a?(Set)
- if seen.include?(e_id = e.object_id)
- raise ArgumentError, "tried to flatten recursive Set"
- end
-
- seen.add(e_id)
- flatten_merge(e, seen)
- seen.delete(e_id)
- else
- add(e)
- end
- }
-
- self
- end
- protected :flatten_merge
-
- # Returns a new set that is a copy of the set, flattening each
- # containing set recursively.
- def flatten
- self.class.new.flatten_merge(self)
- end
-
- # Equivalent to Set#flatten, but replaces the receiver with the
- # result in place. Returns nil if no modifications were made.
- def flatten!
- if detect { |e| e.is_a?(Set) }
- replace(flatten())
- else
- nil
- end
- end
-
- # Returns true if the set contains the given object.
- def include?(o)
- @hash.include?(o)
- end
- alias member? include?
-
- # Returns true if the set is a superset of the given set.
- def superset?(set)
- set.is_a?(Set) or raise ArgumentError, "value must be a set"
- return false if size < set.size
- set.all? { |o| include?(o) }
- end
- alias >= superset?
-
- # Returns true if the set is a proper superset of the given set.
- def proper_superset?(set)
- set.is_a?(Set) or raise ArgumentError, "value must be a set"
- return false if size <= set.size
- set.all? { |o| include?(o) }
- end
- alias > proper_superset?
-
- # Returns true if the set is a subset of the given set.
- def subset?(set)
- set.is_a?(Set) or raise ArgumentError, "value must be a set"
- return false if set.size < size
- all? { |o| set.include?(o) }
- end
- alias <= subset?
-
- # Returns true if the set is a proper subset of the given set.
- def proper_subset?(set)
- set.is_a?(Set) or raise ArgumentError, "value must be a set"
- return false if set.size <= size
- all? { |o| set.include?(o) }
- end
- alias < proper_subset?
-
- # Returns true if the set and the given set have at least one
- # element in common.
- #
- # e.g.:
- #
- # require 'set'
- # Set[1, 2, 3].intersect? Set[4, 5] # => false
- # Set[1, 2, 3].intersect? Set[3, 4] # => true
- def intersect?(set)
- set.is_a?(Set) or raise ArgumentError, "value must be a set"
- if size < set.size
- any? { |o| set.include?(o) }
- else
- set.any? { |o| include?(o) }
- end
- end
-
- # Returns true if the set and the given set have no element in
- # common. This method is the opposite of +intersect?+.
- #
- # e.g.:
- #
- # require 'set'
- # Set[1, 2, 3].disjoint? Set[3, 4] # => false
- # Set[1, 2, 3].disjoint? Set[4, 5] # => true
-
- def disjoint?(set)
- !intersect?(set)
- end
-
- # Calls the given block once for each element in the set, passing
- # the element as parameter. Returns an enumerator if no block is
- # given.
- def each(&block)
- block or return enum_for(__method__)
- @hash.each_key(&block)
- self
- end
-
- # Adds the given object to the set and returns self. Use +merge+ to
- # add many elements at once.
- def add(o)
- @hash[o] = true
- self
- end
- alias << add
-
- # Adds the given object to the set and returns self. If the
- # object is already in the set, returns nil.
- def add?(o)
- if include?(o)
- nil
- else
- add(o)
- end
- end
-
- # Deletes the given object from the set and returns self. Use +subtract+ to
- # delete many items at once.
- def delete(o)
- @hash.delete(o)
- self
- end
-
- # Deletes the given object from the set and returns self. If the
- # object is not in the set, returns nil.
- def delete?(o)
- if include?(o)
- delete(o)
- else
- nil
- end
- end
-
- # Deletes every element of the set for which block evaluates to
- # true, and returns self.
- def delete_if
- block_given? or return enum_for(__method__)
- # @hash.delete_if should be faster, but using it breaks the order
- # of enumeration in subclasses.
- select { |o| yield o }.each { |o| @hash.delete(o) }
- self
- end
-
- # Deletes every element of the set for which block evaluates to
- # false, and returns self.
- def keep_if
- block_given? or return enum_for(__method__)
- # @hash.keep_if should be faster, but using it breaks the order of
- # enumeration in subclasses.
- reject { |o| yield o }.each { |o| @hash.delete(o) }
- self
- end
-
- # Replaces the elements with ones returned by collect().
- def collect!
- block_given? or return enum_for(__method__)
- set = self.class.new
- each { |o| set << yield(o) }
- replace(set)
- end
- alias map! collect!
-
- # Equivalent to Set#delete_if, but returns nil if no changes were
- # made.
- def reject!(&block)
- block or return enum_for(__method__)
- n = size
- delete_if(&block)
- size == n ? nil : self
- end
-
- # Equivalent to Set#keep_if, but returns nil if no changes were
- # made.
- def select!(&block)
- block or return enum_for(__method__)
- n = size
- keep_if(&block)
- size == n ? nil : self
- end
-
- # Merges the elements of the given enumerable object to the set and
- # returns self.
- def merge(enum)
- if enum.instance_of?(self.class)
- @hash.update(enum.instance_variable_get(:@hash))
- else
- do_with_enum(enum) { |o| add(o) }
- end
-
- self
- end
-
- # Deletes every element that appears in the given enumerable object
- # and returns self.
- def subtract(enum)
- do_with_enum(enum) { |o| delete(o) }
- self
- end
-
- # Returns a new set built by merging the set and the elements of the
- # given enumerable object.
- def |(enum)
- dup.merge(enum)
- end
- alias + | ##
- alias union | ##
-
- # Returns a new set built by duplicating the set, removing every
- # element that appears in the given enumerable object.
- def -(enum)
- dup.subtract(enum)
- end
- alias difference - ##
-
- # Returns a new set containing elements common to the set and the
- # given enumerable object.
- def &(enum)
- n = self.class.new
- do_with_enum(enum) { |o| n.add(o) if include?(o) }
- n
- end
- alias intersection & ##
-
- # Returns a new set containing elements exclusive between the set
- # and the given enumerable object. (set ^ enum) is equivalent to
- # ((set | enum) - (set & enum)).
- def ^(enum)
- n = Set.new(enum)
- each { |o| if n.include?(o) then n.delete(o) else n.add(o) end }
- n
- end
-
- # Returns true if two sets are equal. The equality of each couple
- # of elements is defined according to Object#eql?.
- def ==(other)
- if self.equal?(other)
- true
- elsif other.instance_of?(self.class)
- @hash == other.instance_variable_get(:@hash)
- elsif other.is_a?(Set) && self.size == other.size
- other.all? { |o| @hash.include?(o) }
- else
- false
- end
- end
-
- def hash # :nodoc:
- @hash.hash
- end
-
- def eql?(o) # :nodoc:
- return false unless o.is_a?(Set)
- @hash.eql?(o.instance_variable_get(:@hash))
- end
-
- # Classifies the set by the return value of the given block and
- # returns a hash of {value => set of elements} pairs. The block is
- # called once for each element of the set, passing the element as
- # parameter.
- #
- # e.g.:
- #
- # require 'set'
- # files = Set.new(Dir.glob("*.rb"))
- # hash = files.classify { |f| File.mtime(f).year }
- # p hash # => {2000=>#<Set: {"a.rb", "b.rb"}>,
- # # 2001=>#<Set: {"c.rb", "d.rb", "e.rb"}>,
- # # 2002=>#<Set: {"f.rb"}>}
- def classify # :yields: o
- block_given? or return enum_for(__method__)
-
- h = {}
-
- each { |i|
- x = yield(i)
- (h[x] ||= self.class.new).add(i)
- }
-
- h
- end
-
- # Divides the set into a set of subsets according to the commonality
- # defined by the given block.
- #
- # If the arity of the block is 2, elements o1 and o2 are in common
- # if block.call(o1, o2) is true. Otherwise, elements o1 and o2 are
- # in common if block.call(o1) == block.call(o2).
- #
- # e.g.:
- #
- # require 'set'
- # numbers = Set[1, 3, 4, 6, 9, 10, 11]
- # set = numbers.divide { |i,j| (i - j).abs == 1 }
- # p set # => #<Set: {#<Set: {1}>,
- # # #<Set: {11, 9, 10}>,
- # # #<Set: {3, 4}>,
- # # #<Set: {6}>}>
- def divide(&func)
- func or return enum_for(__method__)
-
- if func.arity == 2
- require 'tsort'
-
- class << dig = {} # :nodoc:
- include TSort
-
- alias tsort_each_node each_key
- def tsort_each_child(node, &block)
- fetch(node).each(&block)
- end
- end
-
- each { |u|
- dig[u] = a = []
- each{ |v| func.call(u, v) and a << v }
- }
-
- set = Set.new()
- dig.each_strongly_connected_component { |css|
- set.add(self.class.new(css))
- }
- set
- else
- Set.new(classify(&func).values)
- end
- end
-
- InspectKey = :__inspect_key__ # :nodoc:
-
- # Returns a string containing a human-readable representation of the
- # set. ("#<Set: {element1, element2, ...}>")
- def inspect
- ids = (Thread.current[InspectKey] ||= [])
-
- if ids.include?(object_id)
- return sprintf('#<%s: {...}>', self.class.name)
- end
-
- begin
- ids << object_id
- return sprintf('#<%s: {%s}>', self.class, to_a.inspect[1..-2])
- ensure
- ids.pop
- end
- end
-
- def pretty_print(pp) # :nodoc:
- pp.text sprintf('#<%s: {', self.class.name)
- pp.nest(1) {
- pp.seplist(self) { |o|
- pp.pp o
- }
- }
- pp.text "}>"
- end
-
- def pretty_print_cycle(pp) # :nodoc:
- pp.text sprintf('#<%s: {%s}>', self.class.name, empty? ? '' : '...')
- end
-end
-
-#
-# SortedSet implements a Set that guarantees that its elements are
-# yielded in sorted order (according to the return values of their
-# #<=> methods) when iterating over them.
-#
-# All elements that are added to a SortedSet must respond to the <=>
-# method for comparison.
-#
-# Also, all elements must be <em>mutually comparable</em>: <tt>el1 <=>
-# el2</tt> must not return <tt>nil</tt> for any elements <tt>el1</tt>
-# and <tt>el2</tt>, else an ArgumentError will be raised when
-# iterating over the SortedSet.
-#
-# == Example
-#
-# require "set"
-#
-# set = SortedSet.new([2, 1, 5, 6, 4, 5, 3, 3, 3])
-# ary = []
-#
-# set.each do |obj|
-# ary << obj
-# end
-#
-# p ary # => [1, 2, 3, 4, 5, 6]
-#
-# set2 = SortedSet.new([1, 2, "3"])
-# set2.each { |obj| } # => raises ArgumentError: comparison of Fixnum with String failed
-#
-class SortedSet < Set
- @@setup = false
-
- class << self
- def [](*ary) # :nodoc:
- new(ary)
- end
-
- def setup # :nodoc:
- @@setup and return
-
- module_eval {
- # a hack to shut up warning
- alias old_init initialize
- }
- begin
- require 'rbtree'
-
- module_eval <<-END, __FILE__, __LINE__+1
- def initialize(*args)
- @hash = RBTree.new
- super
- end
-
- def add(o)
- o.respond_to?(:<=>) or raise ArgumentError, "value must respond to <=>"
- super
- end
- alias << add
- END
- rescue LoadError
- module_eval <<-END, __FILE__, __LINE__+1
- def initialize(*args)
- @keys = nil
- super
- end
-
- def clear
- @keys = nil
- super
- end
-
- def replace(enum)
- @keys = nil
- super
- end
-
- def add(o)
- o.respond_to?(:<=>) or raise ArgumentError, "value must respond to <=>"
- @keys = nil
- super
- end
- alias << add
-
- def delete(o)
- @keys = nil
- @hash.delete(o)
- self
- end
-
- def delete_if
- block_given? or return enum_for(__method__)
- n = @hash.size
- super
- @keys = nil if @hash.size != n
- self
- end
-
- def keep_if
- block_given? or return enum_for(__method__)
- n = @hash.size
- super
- @keys = nil if @hash.size != n
- self
- end
-
- def merge(enum)
- @keys = nil
- super
- end
-
- def each(&block)
- block or return enum_for(__method__)
- to_a.each(&block)
- self
- end
-
- def to_a
- (@keys = @hash.keys).sort! unless @keys
- @keys
- end
- END
- end
- module_eval {
- # a hack to shut up warning
- remove_method :old_init
- }
-
- @@setup = true
- end
- end
-
- def initialize(*args, &block) # :nodoc:
- SortedSet.setup
- initialize(*args, &block)
- end
-end
-
-module Enumerable
- # Makes a set from the enumerable object with given arguments.
- # Needs to +require "set"+ to use this method.
- def to_set(klass = Set, *args, &block)
- klass.new(self, *args, &block)
- end
-end
-
-# =begin
-# == RestricedSet class
-# RestricedSet implements a set with restrictions defined by a given
-# block.
-#
-# === Super class
-# Set
-#
-# === Class Methods
-# --- RestricedSet::new(enum = nil) { |o| ... }
-# --- RestricedSet::new(enum = nil) { |rset, o| ... }
-# Creates a new restricted set containing the elements of the given
-# enumerable object. Restrictions are defined by the given block.
-#
-# If the block's arity is 2, it is called with the RestrictedSet
-# itself and an object to see if the object is allowed to be put in
-# the set.
-#
-# Otherwise, the block is called with an object to see if the object
-# is allowed to be put in the set.
-#
-# === Instance Methods
-# --- restriction_proc
-# Returns the restriction procedure of the set.
-#
-# =end
-#
-# class RestricedSet < Set
-# def initialize(*args, &block)
-# @proc = block or raise ArgumentError, "missing a block"
-#
-# if @proc.arity == 2
-# instance_eval %{
-# def add(o)
-# @hash[o] = true if @proc.call(self, o)
-# self
-# end
-# alias << add
-#
-# def add?(o)
-# if include?(o) || !@proc.call(self, o)
-# nil
-# else
-# @hash[o] = true
-# self
-# end
-# end
-#
-# def replace(enum)
-# enum.respond_to?(:each) or raise ArgumentError, "value must be enumerable"
-# clear
-# enum.each_entry { |o| add(o) }
-#
-# self
-# end
-#
-# def merge(enum)
-# enum.respond_to?(:each) or raise ArgumentError, "value must be enumerable"
-# enum.each_entry { |o| add(o) }
-#
-# self
-# end
-# }
-# else
-# instance_eval %{
-# def add(o)
-# if @proc.call(o)
-# @hash[o] = true
-# end
-# self
-# end
-# alias << add
-#
-# def add?(o)
-# if include?(o) || !@proc.call(o)
-# nil
-# else
-# @hash[o] = true
-# self
-# end
-# end
-# }
-# end
-#
-# super(*args)
-# end
-#
-# def restriction_proc
-# @proc
-# end
-# end
-
-# Tests have been moved to test/test_set.rb.
diff --git a/ruby_2_2/lib/shell.rb b/ruby_2_2/lib/shell.rb
deleted file mode 100644
index db2d687908..0000000000
--- a/ruby_2_2/lib/shell.rb
+++ /dev/null
@@ -1,458 +0,0 @@
-#
-# shell.rb -
-# $Release Version: 0.7 $
-# $Revision: 1.9 $
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-require "e2mmap"
-
-require "thread" unless defined?(Mutex)
-
-require "forwardable"
-
-require "shell/error"
-require "shell/command-processor"
-require "shell/process-controller"
-
-# Shell implements an idiomatic Ruby interface for common UNIX shell commands.
-#
-# It provides users the ability to execute commands with filters and pipes,
-# like +sh+/+csh+ by using native facilities of Ruby.
-#
-# == Examples
-#
-# === Temp file creation
-#
-# In this example we will create three +tmpFile+'s in three different folders
-# under the +/tmp+ directory.
-#
-# sh = Shell.cd("/tmp") # Change to the /tmp directory
-# sh.mkdir "shell-test-1" unless sh.exists?("shell-test-1")
-# # make the 'shell-test-1' directory if it doesn't already exist
-# sh.cd("shell-test-1") # Change to the /tmp/shell-test-1 directory
-# for dir in ["dir1", "dir3", "dir5"]
-# if !sh.exists?(dir)
-# sh.mkdir dir # make dir if it doesn't already exist
-# sh.cd(dir) do
-# # change to the `dir` directory
-# f = sh.open("tmpFile", "w") # open a new file in write mode
-# f.print "TEST\n" # write to the file
-# f.close # close the file handler
-# end
-# print sh.pwd # output the process working directory
-# end
-# end
-#
-# === Temp file creation with self
-#
-# This example is identical to the first, except we're using
-# CommandProcessor#transact.
-#
-# CommandProcessor#transact executes the given block against self, in this case
-# +sh+; our Shell object. Within the block we can substitute +sh.cd+ to +cd+,
-# because the scope within the block uses +sh+ already.
-#
-# sh = Shell.cd("/tmp")
-# sh.transact do
-# mkdir "shell-test-1" unless exists?("shell-test-1")
-# cd("shell-test-1")
-# for dir in ["dir1", "dir3", "dir5"]
-# if !exists?(dir)
-# mkdir dir
-# cd(dir) do
-# f = open("tmpFile", "w")
-# f.print "TEST\n"
-# f.close
-# end
-# print pwd
-# end
-# end
-# end
-#
-# === Pipe /etc/printcap into a file
-#
-# In this example we will read the operating system file +/etc/printcap+,
-# generated by +cupsd+, and then output it to a new file relative to the +pwd+
-# of +sh+.
-#
-# sh = Shell.new
-# sh.cat("/etc/printcap") | sh.tee("tee1") > "tee2"
-# (sh.cat < "/etc/printcap") | sh.tee("tee11") > "tee12"
-# sh.cat("/etc/printcap") | sh.tee("tee1") >> "tee2"
-# (sh.cat < "/etc/printcap") | sh.tee("tee11") >> "tee12"
-#
-class Shell
-
- include Error
- extend Exception2MessageMapper
-
- # debug: true -> normal debug
- # debug: 1 -> eval definition debug
- # debug: 2 -> detail inspect debug
- @debug = false
- @verbose = true
-
- @debug_display_process_id = false
- @debug_display_thread_id = true
- @debug_output_mutex = Mutex.new
-
- class << Shell
- extend Forwardable
-
- attr_accessor :cascade, :debug, :verbose
-
- alias debug? debug
- alias verbose? verbose
- @verbose = true
-
- def debug=(val)
- @debug = val
- @verbose = val if val
- end
-
-
- # call-seq:
- # Shell.cd(path)
- #
- # Creates a new Shell instance with the current working directory
- # set to +path+.
- def cd(path)
- new(path)
- end
-
- # Returns the directories in the current shell's PATH environment variable
- # as an array of directory names. This sets the system_path for all
- # instances of Shell.
- #
- # Example: If in your current shell, you did:
- #
- # $ echo $PATH
- # /usr/bin:/bin:/usr/local/bin
- #
- # Running this method in the above shell would then return:
- #
- # ["/usr/bin", "/bin", "/usr/local/bin"]
- #
- def default_system_path
- if @default_system_path
- @default_system_path
- else
- ENV["PATH"].split(":")
- end
- end
-
- # Sets the system_path that new instances of Shell should have as their
- # initial system_path.
- #
- # +path+ should be an array of directory name strings.
- def default_system_path=(path)
- @default_system_path = path
- end
-
- def default_record_separator
- if @default_record_separator
- @default_record_separator
- else
- $/
- end
- end
-
- def default_record_separator=(rs)
- @default_record_separator = rs
- end
-
- # os resource mutex
- mutex_methods = ["unlock", "lock", "locked?", "synchronize", "try_lock", "exclusive_unlock"]
- for m in mutex_methods
- def_delegator("@debug_output_mutex", m, "debug_output_"+m.to_s)
- end
-
- end
-
- # call-seq:
- # Shell.new(pwd, umask) -> obj
- #
- # Creates a Shell object which current directory is set to the process
- # current directory, unless otherwise specified by the +pwd+ argument.
- def initialize(pwd = Dir.pwd, umask = nil)
- @cwd = File.expand_path(pwd)
- @dir_stack = []
- @umask = umask
-
- @system_path = Shell.default_system_path
- @record_separator = Shell.default_record_separator
-
- @command_processor = CommandProcessor.new(self)
- @process_controller = ProcessController.new(self)
-
- @verbose = Shell.verbose
- @debug = Shell.debug
- end
-
- # Returns the command search path in an array
- attr_reader :system_path
-
- # Sets the system path (the Shell instance's PATH environment variable).
- #
- # +path+ should be an array of directory name strings.
- def system_path=(path)
- @system_path = path
- rehash
- end
-
-
- # Returns the umask
- attr_accessor :umask
- attr_accessor :record_separator
- attr_accessor :verbose, :debug
-
- def debug=(val)
- @debug = val
- @verbose = val if val
- end
-
- alias verbose? verbose
- alias debug? debug
-
- attr_reader :command_processor
- attr_reader :process_controller
-
- def expand_path(path)
- File.expand_path(path, @cwd)
- end
-
- # Most Shell commands are defined via CommandProcessor
-
- #
- # Dir related methods
- #
- # Shell#cwd/dir/getwd/pwd
- # Shell#chdir/cd
- # Shell#pushdir/pushd
- # Shell#popdir/popd
- # Shell#mkdir
- # Shell#rmdir
-
- # Returns the current working directory.
- attr_reader :cwd
- alias dir cwd
- alias getwd cwd
- alias pwd cwd
-
- attr_reader :dir_stack
- alias dirs dir_stack
-
- # call-seq:
- # Shell.chdir(path)
- #
- # Creates a Shell object which current directory is set to +path+.
- #
- # If a block is given, it restores the current directory when the block ends.
- #
- # If called as iterator, it restores the current directory when the
- # block ends.
- def chdir(path = nil, verbose = @verbose)
- check_point
-
- if iterator?
- notify("chdir(with block) #{path}") if verbose
- cwd_old = @cwd
- begin
- chdir(path, nil)
- yield
- ensure
- chdir(cwd_old, nil)
- end
- else
- notify("chdir #{path}") if verbose
- path = "~" unless path
- @cwd = expand_path(path)
- notify "current dir: #{@cwd}"
- rehash
- Void.new(self)
- end
- end
- alias cd chdir
-
- # call-seq:
- # pushdir(path)
- # pushdir(path) { &block }
- #
- # Pushes the current directory to the directory stack, changing the current
- # directory to +path+.
- #
- # If +path+ is omitted, it exchanges its current directory and the top of its
- # directory stack.
- #
- # If a block is given, it restores the current directory when the block ends.
- def pushdir(path = nil, verbose = @verbose)
- check_point
-
- if iterator?
- notify("pushdir(with block) #{path}") if verbose
- pushdir(path, nil)
- begin
- yield
- ensure
- popdir
- end
- elsif path
- notify("pushdir #{path}") if verbose
- @dir_stack.push @cwd
- chdir(path, nil)
- notify "dir stack: [#{@dir_stack.join ', '}]"
- self
- else
- notify("pushdir") if verbose
- if pop = @dir_stack.pop
- @dir_stack.push @cwd
- chdir pop
- notify "dir stack: [#{@dir_stack.join ', '}]"
- self
- else
- Shell.Fail DirStackEmpty
- end
- end
- Void.new(self)
- end
- alias pushd pushdir
-
- # Pops a directory from the directory stack, and sets the current directory
- # to it.
- def popdir
- check_point
-
- notify("popdir")
- if pop = @dir_stack.pop
- chdir pop
- notify "dir stack: [#{@dir_stack.join ', '}]"
- self
- else
- Shell.Fail DirStackEmpty
- end
- Void.new(self)
- end
- alias popd popdir
-
- # Returns a list of scheduled jobs.
- def jobs
- @process_controller.jobs
- end
-
- # call-seq:
- # kill(signal, job)
- #
- # Sends the given +signal+ to the given +job+
- def kill(sig, command)
- @process_controller.kill_job(sig, command)
- end
-
- # call-seq:
- # def_system_command(command, path = command)
- #
- # Convenience method for Shell::CommandProcessor.def_system_command.
- # Defines an instance method which will execute the given shell command.
- # If the executable is not in Shell.default_system_path, you must
- # supply the path to it.
- #
- # Shell.def_system_command('hostname')
- # Shell.new.hostname # => localhost
- #
- # # How to use an executable that's not in the default path
- #
- # Shell.def_system_command('run_my_program', "~/hello")
- # Shell.new.run_my_program # prints "Hello from a C program!"
- #
- def Shell.def_system_command(command, path = command)
- CommandProcessor.def_system_command(command, path)
- end
-
- # Convenience method for Shell::CommandProcessor.undef_system_command
- def Shell.undef_system_command(command)
- CommandProcessor.undef_system_command(command)
- end
-
- # call-seq:
- # alias_command(alias, command, *opts, &block)
- #
- # Convenience method for Shell::CommandProcessor.alias_command.
- # Defines an instance method which will execute a command under
- # an alternative name.
- #
- # Shell.def_system_command('date')
- # Shell.alias_command('date_in_utc', 'date', '-u')
- # Shell.new.date_in_utc # => Sat Jan 25 16:59:57 UTC 2014
- #
- def Shell.alias_command(ali, command, *opts, &block)
- CommandProcessor.alias_command(ali, command, *opts, &block)
- end
-
- # Convenience method for Shell::CommandProcessor.unalias_command
- def Shell.unalias_command(ali)
- CommandProcessor.unalias_command(ali)
- end
-
- # call-seq:
- # install_system_commands(pre = "sys_")
- #
- # Convenience method for Shell::CommandProcessor.install_system_commands.
- # Defines instance methods representing all the executable files found in
- # Shell.default_system_path, with the given prefix prepended to their
- # names.
- #
- # Shell.install_system_commands
- # Shell.new.sys_echo("hello") # => hello
- #
- def Shell.install_system_commands(pre = "sys_")
- CommandProcessor.install_system_commands(pre)
- end
-
- #
- def inspect
- if debug.kind_of?(Integer) && debug > 2
- super
- else
- to_s
- end
- end
-
- def self.notify(*opts)
- Shell::debug_output_synchronize do
- if opts[-1].kind_of?(String)
- yorn = verbose?
- else
- yorn = opts.pop
- end
- return unless yorn
-
- if @debug_display_thread_id
- if @debug_display_process_id
- prefix = "shell(##{Process.pid}:#{Thread.current.to_s.sub("Thread", "Th")}): "
- else
- prefix = "shell(#{Thread.current.to_s.sub("Thread", "Th")}): "
- end
- else
- prefix = "shell: "
- end
- _head = true
- STDERR.print opts.collect{|mes|
- mes = mes.dup
- yield mes if iterator?
- if _head
- _head = false
- prefix + mes
- else
- " "* prefix.size + mes
- end
- }.join("\n")+"\n"
- end
- end
-
- CommandProcessor.initialize
- CommandProcessor.run_config
-end
diff --git a/ruby_2_2/lib/shell/builtin-command.rb b/ruby_2_2/lib/shell/builtin-command.rb
deleted file mode 100644
index 80a0ce5534..0000000000
--- a/ruby_2_2/lib/shell/builtin-command.rb
+++ /dev/null
@@ -1,146 +0,0 @@
-#
-# shell/builtin-command.rb -
-# $Release Version: 0.7 $
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-require "shell/filter"
-
-class Shell
- class BuiltInCommand<Filter
- def wait?
- false
- end
- def active?
- true
- end
- end
-
- class Void < BuiltInCommand
- def initialize(sh, *opts)
- super sh
- end
-
- def each(rs = nil)
- # do nothing
- end
- end
-
- class Echo < BuiltInCommand
- def initialize(sh, *strings)
- super sh
- @strings = strings
- end
-
- def each(rs = nil)
- rs = @shell.record_separator unless rs
- for str in @strings
- yield str + rs
- end
- end
- end
-
- class Cat < BuiltInCommand
- def initialize(sh, *filenames)
- super sh
- @cat_files = filenames
- end
-
- def each(rs = nil)
- if @cat_files.empty?
- super
- else
- for src in @cat_files
- @shell.foreach(src, rs){|l| yield l}
- end
- end
- end
- end
-
- class Glob < BuiltInCommand
- def initialize(sh, pattern)
- super sh
-
- @pattern = pattern
- end
-
- def each(rs = nil)
- if @pattern[0] == ?/
- @files = Dir[@pattern]
- else
- prefix = @shell.pwd+"/"
- @files = Dir[prefix+@pattern].collect{|p| p.sub(prefix, "")}
- end
- rs = @shell.record_separator unless rs
- for f in @files
- yield f+rs
- end
- end
- end
-
- class AppendIO < BuiltInCommand
- def initialize(sh, io, filter)
- super sh
- @input = filter
- @io = io
- end
-
- def input=(filter)
- @input.input=filter
- for l in @input
- @io << l
- end
- end
-
- end
-
- class AppendFile < AppendIO
- def initialize(sh, to_filename, filter)
- @file_name = to_filename
- io = sh.open(to_filename, "a")
- super(sh, io, filter)
- end
-
- def input=(filter)
- begin
- super
- ensure
- @io.close
- end
- end
- end
-
- class Tee < BuiltInCommand
- def initialize(sh, filename)
- super sh
- @to_filename = filename
- end
-
- def each(rs = nil)
- to = @shell.open(@to_filename, "w")
- begin
- super{|l| to << l; yield l}
- ensure
- to.close
- end
- end
- end
-
- class Concat < BuiltInCommand
- def initialize(sh, *jobs)
- super(sh)
- @jobs = jobs
- end
-
- def each(rs = nil)
- while job = @jobs.shift
- job.each{|l| yield l}
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/shell/command-processor.rb b/ruby_2_2/lib/shell/command-processor.rb
deleted file mode 100644
index 13bc50c3fe..0000000000
--- a/ruby_2_2/lib/shell/command-processor.rb
+++ /dev/null
@@ -1,667 +0,0 @@
-#
-# shell/command-controller.rb -
-# $Release Version: 0.7 $
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-require "e2mmap"
-require "thread"
-
-require "shell/error"
-require "shell/filter"
-require "shell/system-command"
-require "shell/builtin-command"
-
-class Shell
- # In order to execute a command on your OS, you need to define it as a
- # Shell method.
- #
- # Alternatively, you can execute any command via
- # Shell::CommandProcessor#system even if it is not defined.
- class CommandProcessor
-
- #
- # initialize of Shell and related classes.
- #
- m = [:initialize, :expand_path]
- if Object.methods.first.kind_of?(String)
- NoDelegateMethods = m.collect{|x| x.id2name}
- else
- NoDelegateMethods = m
- end
-
- def self.initialize
-
- install_builtin_commands
-
- # define CommandProcessor#methods to Shell#methods and Filter#methods
- for m in CommandProcessor.instance_methods(false) - NoDelegateMethods
- add_delegate_command_to_shell(m)
- end
-
- def self.method_added(id)
- add_delegate_command_to_shell(id)
- end
- end
-
- #
- # include run file.
- #
- def self.run_config
- begin
- load File.expand_path("~/.rb_shell") if ENV.key?("HOME")
- rescue LoadError, Errno::ENOENT
- rescue
- print "load error: #{rc}\n"
- print $!.class, ": ", $!, "\n"
- for err in $@[0, $@.size - 2]
- print "\t", err, "\n"
- end
- end
- end
-
- def initialize(shell)
- @shell = shell
- @system_commands = {}
- end
-
- #
- # CommandProcessor#expand_path(path)
- # path: String
- # return: String
- # returns the absolute path for <path>
- #
- def expand_path(path)
- @shell.expand_path(path)
- end
-
- # call-seq:
- # foreach(path, record_separator) -> Enumerator
- # foreach(path, record_separator) { block }
- #
- # See IO.foreach when +path+ is a file.
- #
- # See Dir.foreach when +path+ is a directory.
- #
- def foreach(path = nil, *rs)
- path = "." unless path
- path = expand_path(path)
-
- if File.directory?(path)
- Dir.foreach(path){|fn| yield fn}
- else
- IO.foreach(path, *rs){|l| yield l}
- end
- end
-
- # call-seq:
- # open(path, mode, permissions) -> Enumerator
- # open(path, mode, permissions) { block }
- #
- # See IO.open when +path+ is a file.
- #
- # See Dir.open when +path+ is a directory.
- #
- def open(path, mode = nil, perm = 0666, &b)
- path = expand_path(path)
- if File.directory?(path)
- Dir.open(path, &b)
- else
- if @shell.umask
- f = File.open(path, mode, perm)
- File.chmod(perm & ~@shell.umask, path)
- if block_given?
- f.each(&b)
- end
- f
- else
- File.open(path, mode, perm, &b)
- end
- end
- end
-
- # call-seq:
- # unlink(path)
- #
- # See IO.unlink when +path+ is a file.
- #
- # See Dir.unlink when +path+ is a directory.
- #
- def unlink(path)
- @shell.check_point
-
- path = expand_path(path)
- if File.directory?(path)
- Dir.unlink(path)
- else
- IO.unlink(path)
- end
- Void.new(@shell)
- end
-
- # See Shell::CommandProcessor#test
- alias top_level_test test
- # call-seq:
- # test(command, file1, file2) -> true or false
- # [command, file1, file2] -> true or false
- #
- # Tests if the given +command+ exists in +file1+, or optionally +file2+.
- #
- # Example:
- # sh[?e, "foo"]
- # sh[:e, "foo"]
- # sh["e", "foo"]
- # sh[:exists?, "foo"]
- # sh["exists?", "foo"]
- #
- def test(command, file1, file2=nil)
- file1 = expand_path(file1)
- file2 = expand_path(file2) if file2
- command = command.id2name if command.kind_of?(Symbol)
-
- case command
- when Integer
- if file2
- top_level_test(command, file1, file2)
- else
- top_level_test(command, file1)
- end
- when String
- if command.size == 1
- if file2
- top_level_test(command, file1, file2)
- else
- top_level_test(command, file1)
- end
- else
- if file2
- FileTest.send(command, file1, file2)
- else
- FileTest.send(command, file1)
- end
- end
- end
- end
- # See Shell::CommandProcessor#test
- alias [] test
-
- # call-seq:
- # mkdir(path)
- #
- # Same as Dir.mkdir, except multiple directories are allowed.
- def mkdir(*path)
- @shell.check_point
- notify("mkdir #{path.join(' ')}")
-
- perm = nil
- if path.last.kind_of?(Integer)
- perm = path.pop
- end
- for dir in path
- d = expand_path(dir)
- if perm
- Dir.mkdir(d, perm)
- else
- Dir.mkdir(d)
- end
- File.chmod(d, 0666 & ~@shell.umask) if @shell.umask
- end
- Void.new(@shell)
- end
-
- # call-seq:
- # rmdir(path)
- #
- # Same as Dir.rmdir, except multiple directories are allowed.
- def rmdir(*path)
- @shell.check_point
- notify("rmdir #{path.join(' ')}")
-
- for dir in path
- Dir.rmdir(expand_path(dir))
- end
- Void.new(@shell)
- end
-
- # call-seq:
- # system(command, *options) -> SystemCommand
- #
- # Executes the given +command+ with the +options+ parameter.
- #
- # Example:
- # print sh.system("ls", "-l")
- # sh.system("ls", "-l") | sh.head > STDOUT
- #
- def system(command, *opts)
- if opts.empty?
- if command =~ /\*|\?|\{|\}|\[|\]|<|>|\(|\)|~|&|\||\\|\$|;|'|`|"|\n/
- return SystemCommand.new(@shell, find_system_command("sh"), "-c", command)
- else
- command, *opts = command.split(/\s+/)
- end
- end
- SystemCommand.new(@shell, find_system_command(command), *opts)
- end
-
- # call-seq:
- # rehash
- #
- # Clears the command hash table.
- def rehash
- @system_commands = {}
- end
-
- def check_point # :nodoc:
- @shell.process_controller.wait_all_jobs_execution
- end
- alias finish_all_jobs check_point # :nodoc:
-
- # call-seq:
- # transact { block }
- #
- # Executes a block as self
- #
- # Example:
- # sh.transact { system("ls", "-l") | head > STDOUT }
- def transact(&block)
- begin
- @shell.instance_eval(&block)
- ensure
- check_point
- end
- end
-
- # call-seq:
- # out(device) { block }
- #
- # Calls <code>device.print</code> on the result passing the _block_ to
- # #transact
- def out(dev = STDOUT, &block)
- dev.print transact(&block)
- end
-
- # call-seq:
- # echo(*strings) -> Echo
- #
- # Returns a Echo object, for the given +strings+
- def echo(*strings)
- Echo.new(@shell, *strings)
- end
-
- # call-seq:
- # cat(*filename) -> Cat
- #
- # Returns a Cat object, for the given +filenames+
- def cat(*filenames)
- Cat.new(@shell, *filenames)
- end
-
- # def sort(*filenames)
- # Sort.new(self, *filenames)
- # end
- # call-seq:
- # glob(pattern) -> Glob
- #
- # Returns a Glob filter object, with the given +pattern+ object
- def glob(pattern)
- Glob.new(@shell, pattern)
- end
-
- def append(to, filter)
- case to
- when String
- AppendFile.new(@shell, to, filter)
- when IO
- AppendIO.new(@shell, to, filter)
- else
- Shell.Fail Error::CantApplyMethod, "append", to.class
- end
- end
-
- # call-seq:
- # tee(file) -> Tee
- #
- # Returns a Tee filter object, with the given +file+ command
- def tee(file)
- Tee.new(@shell, file)
- end
-
- # call-seq:
- # concat(*jobs) -> Concat
- #
- # Returns a Concat object, for the given +jobs+
- def concat(*jobs)
- Concat.new(@shell, *jobs)
- end
-
- # %pwd, %cwd -> @pwd
- def notify(*opts)
- Shell.notify(*opts) {|mes|
- yield mes if iterator?
-
- mes.gsub!("%pwd", "#{@cwd}")
- mes.gsub!("%cwd", "#{@cwd}")
- }
- end
-
- #
- # private functions
- #
- def find_system_command(command)
- return command if /^\// =~ command
- case path = @system_commands[command]
- when String
- if exists?(path)
- return path
- else
- Shell.Fail Error::CommandNotFound, command
- end
- when false
- Shell.Fail Error::CommandNotFound, command
- end
-
- for p in @shell.system_path
- path = join(p, command)
- begin
- st = File.stat(path)
- rescue SystemCallError
- next
- else
- next unless st.executable? and !st.directory?
- @system_commands[command] = path
- return path
- end
- end
- @system_commands[command] = false
- Shell.Fail Error::CommandNotFound, command
- end
-
- # call-seq:
- # def_system_command(command, path) -> Shell::SystemCommand
- #
- # Defines a command, registering +path+ as a Shell method for the given
- # +command+.
- #
- # Shell::CommandProcessor.def_system_command "ls"
- # #=> Defines ls.
- #
- # Shell::CommandProcessor.def_system_command "sys_sort", "sort"
- # #=> Defines sys_sort as sort
- #
- def self.def_system_command(command, path = command)
- begin
- eval((d = %Q[def #{command}(*opts)
- SystemCommand.new(@shell, '#{path}', *opts)
- end]), nil, __FILE__, __LINE__ - 1)
- rescue SyntaxError
- Shell.notify "warn: Can't define #{command} path: #{path}."
- end
- Shell.notify "Define #{command} path: #{path}.", Shell.debug?
- Shell.notify("Definition of #{command}: ", d,
- Shell.debug.kind_of?(Integer) && Shell.debug > 1)
- end
-
- # call-seq:
- # undef_system_command(command) -> self
- #
- # Undefines a command
- def self.undef_system_command(command)
- command = command.id2name if command.kind_of?(Symbol)
- remove_method(command)
- Shell.module_eval{remove_method(command)}
- Filter.module_eval{remove_method(command)}
- self
- end
-
- @alias_map = {}
- # Returns a list of aliased commands
- def self.alias_map
- @alias_map
- end
- # call-seq:
- # alias_command(alias, command, *options) -> self
- #
- # Creates a command alias at the given +alias+ for the given +command+,
- # passing any +options+ along with it.
- #
- # Shell::CommandProcessor.alias_command "lsC", "ls", "-CBF", "--show-control-chars"
- # Shell::CommandProcessor.alias_command("lsC", "ls"){|*opts| ["-CBF", "--show-control-chars", *opts]}
- #
- def self.alias_command(ali, command, *opts)
- ali = ali.id2name if ali.kind_of?(Symbol)
- command = command.id2name if command.kind_of?(Symbol)
- begin
- if iterator?
- @alias_map[ali.intern] = proc
-
- eval((d = %Q[def #{ali}(*opts)
- @shell.__send__(:#{command},
- *(CommandProcessor.alias_map[:#{ali}].call *opts))
- end]), nil, __FILE__, __LINE__ - 1)
-
- else
- args = opts.collect{|opt| '"' + opt + '"'}.join(",")
- eval((d = %Q[def #{ali}(*opts)
- @shell.__send__(:#{command}, #{args}, *opts)
- end]), nil, __FILE__, __LINE__ - 1)
- end
- rescue SyntaxError
- Shell.notify "warn: Can't alias #{ali} command: #{command}."
- Shell.notify("Definition of #{ali}: ", d)
- raise
- end
- Shell.notify "Define #{ali} command: #{command}.", Shell.debug?
- Shell.notify("Definition of #{ali}: ", d,
- Shell.debug.kind_of?(Integer) && Shell.debug > 1)
- self
- end
-
- # call-seq:
- # unalias_command(alias) -> self
- #
- # Unaliases the given +alias+ command.
- def self.unalias_command(ali)
- ali = ali.id2name if ali.kind_of?(Symbol)
- @alias_map.delete ali.intern
- undef_system_command(ali)
- end
-
- # :nodoc:
- #
- # Delegates File and FileTest methods into Shell, including the following
- # commands:
- #
- # * Shell#blockdev?(file)
- # * Shell#chardev?(file)
- # * Shell#directory?(file)
- # * Shell#executable?(file)
- # * Shell#executable_real?(file)
- # * Shell#exist?(file)/Shell#exists?(file)
- # * Shell#file?(file)
- # * Shell#grpowned?(file)
- # * Shell#owned?(file)
- # * Shell#pipe?(file)
- # * Shell#readable?(file)
- # * Shell#readable_real?(file)
- # * Shell#setgid?(file)
- # * Shell#setuid?(file)
- # * Shell#size(file)/Shell#size?(file)
- # * Shell#socket?(file)
- # * Shell#sticky?(file)
- # * Shell#symlink?(file)
- # * Shell#writable?(file)
- # * Shell#writable_real?(file)
- # * Shell#zero?(file)
- # * Shell#syscopy(filename_from, filename_to)
- # * Shell#copy(filename_from, filename_to)
- # * Shell#move(filename_from, filename_to)
- # * Shell#compare(filename_from, filename_to)
- # * Shell#safe_unlink(*filenames)
- # * Shell#makedirs(*filenames)
- # * Shell#install(filename_from, filename_to, mode)
- #
- # And also, there are some aliases for convenience:
- #
- # * Shell#cmp <- Shell#compare
- # * Shell#mv <- Shell#move
- # * Shell#cp <- Shell#copy
- # * Shell#rm_f <- Shell#safe_unlink
- # * Shell#mkpath <- Shell#makedirs
- #
- def self.def_builtin_commands(delegation_class, command_specs)
- for meth, args in command_specs
- arg_str = args.collect{|arg| arg.downcase}.join(", ")
- call_arg_str = args.collect{
- |arg|
- case arg
- when /^(FILENAME.*)$/
- format("expand_path(%s)", $1.downcase)
- when /^(\*FILENAME.*)$/
- # \*FILENAME* -> filenames.collect{|fn| expand_path(fn)}.join(", ")
- $1.downcase + '.collect{|fn| expand_path(fn)}'
- else
- arg
- end
- }.join(", ")
- d = %Q[def #{meth}(#{arg_str})
- #{delegation_class}.#{meth}(#{call_arg_str})
- end]
- Shell.notify "Define #{meth}(#{arg_str})", Shell.debug?
- Shell.notify("Definition of #{meth}: ", d,
- Shell.debug.kind_of?(Integer) && Shell.debug > 1)
- eval d
- end
- end
-
- # call-seq:
- # install_system_commands(prefix = "sys_")
- #
- # Defines all commands in the Shell.default_system_path as Shell method,
- # all with given +prefix+ appended to their names.
- #
- # Any invalid character names are converted to +_+, and errors are passed
- # to Shell.notify.
- #
- # Methods already defined are skipped.
- def self.install_system_commands(pre = "sys_")
- defined_meth = {}
- for m in Shell.methods
- defined_meth[m] = true
- end
- sh = Shell.new
- for path in Shell.default_system_path
- next unless sh.directory? path
- sh.cd path
- sh.foreach do
- |cn|
- if !defined_meth[pre + cn] && sh.file?(cn) && sh.executable?(cn)
- command = (pre + cn).gsub(/\W/, "_").sub(/^([0-9])/, '_\1')
- begin
- def_system_command(command, sh.expand_path(cn))
- rescue
- Shell.notify "warn: Can't define #{command} path: #{cn}"
- end
- defined_meth[command] = command
- end
- end
- end
- end
-
- def self.add_delegate_command_to_shell(id) # :nodoc:
- id = id.intern if id.kind_of?(String)
- name = id.id2name
- if Shell.method_defined?(id)
- Shell.notify "warn: override definition of Shell##{name}."
- Shell.notify "warn: alias Shell##{name} to Shell##{name}_org.\n"
- Shell.module_eval "alias #{name}_org #{name}"
- end
- Shell.notify "method added: Shell##{name}.", Shell.debug?
- Shell.module_eval(%Q[def #{name}(*args, &block)
- begin
- @command_processor.__send__(:#{name}, *args, &block)
- rescue Exception
- $@.delete_if{|s| /:in `__getobj__'$/ =~ s} #`
- $@.delete_if{|s| /^\\(eval\\):/ =~ s}
- raise
- end
- end], __FILE__, __LINE__)
-
- if Shell::Filter.method_defined?(id)
- Shell.notify "warn: override definition of Shell::Filter##{name}."
- Shell.notify "warn: alias Shell##{name} to Shell::Filter##{name}_org."
- Filter.module_eval "alias #{name}_org #{name}"
- end
- Shell.notify "method added: Shell::Filter##{name}.", Shell.debug?
- Filter.module_eval(%Q[def #{name}(*args, &block)
- begin
- self | @shell.__send__(:#{name}, *args, &block)
- rescue Exception
- $@.delete_if{|s| /:in `__getobj__'$/ =~ s} #`
- $@.delete_if{|s| /^\\(eval\\):/ =~ s}
- raise
- end
- end], __FILE__, __LINE__)
- end
-
- # Delegates File methods into Shell, including the following commands:
- #
- # * Shell#atime(file)
- # * Shell#basename(file, *opt)
- # * Shell#chmod(mode, *files)
- # * Shell#chown(owner, group, *file)
- # * Shell#ctime(file)
- # * Shell#delete(*file)
- # * Shell#dirname(file)
- # * Shell#ftype(file)
- # * Shell#join(*file)
- # * Shell#link(file_from, file_to)
- # * Shell#lstat(file)
- # * Shell#mtime(file)
- # * Shell#readlink(file)
- # * Shell#rename(file_from, file_to)
- # * Shell#split(file)
- # * Shell#stat(file)
- # * Shell#symlink(file_from, file_to)
- # * Shell#truncate(file, length)
- # * Shell#utime(atime, mtime, *file)
- #
- def self.install_builtin_commands
- # method related File.
- # (exclude open/foreach/unlink)
- normal_delegation_file_methods = [
- ["atime", ["FILENAME"]],
- ["basename", ["fn", "*opts"]],
- ["chmod", ["mode", "*FILENAMES"]],
- ["chown", ["owner", "group", "*FILENAME"]],
- ["ctime", ["FILENAMES"]],
- ["delete", ["*FILENAMES"]],
- ["dirname", ["FILENAME"]],
- ["ftype", ["FILENAME"]],
- ["join", ["*items"]],
- ["link", ["FILENAME_O", "FILENAME_N"]],
- ["lstat", ["FILENAME"]],
- ["mtime", ["FILENAME"]],
- ["readlink", ["FILENAME"]],
- ["rename", ["FILENAME_FROM", "FILENAME_TO"]],
- ["split", ["pathname"]],
- ["stat", ["FILENAME"]],
- ["symlink", ["FILENAME_O", "FILENAME_N"]],
- ["truncate", ["FILENAME", "length"]],
- ["utime", ["atime", "mtime", "*FILENAMES"]]]
-
- def_builtin_commands(File, normal_delegation_file_methods)
- alias_method :rm, :delete
-
- # method related FileTest
- def_builtin_commands(FileTest,
- FileTest.singleton_methods(false).collect{|m| [m, ["FILENAME"]]})
-
- end
-
- end
-end
diff --git a/ruby_2_2/lib/shell/error.rb b/ruby_2_2/lib/shell/error.rb
deleted file mode 100644
index 2701338b5a..0000000000
--- a/ruby_2_2/lib/shell/error.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-#
-# shell/error.rb -
-# $Release Version: 0.7 $
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-require "e2mmap"
-
-class Shell
- module Error
- extend Exception2MessageMapper
- def_e2message TypeError, "wrong argument type %s (expected %s)"
-
- def_exception :DirStackEmpty, "Directory stack empty."
- def_exception :CantDefine, "Can't define method(%s, %s)."
- def_exception :CantApplyMethod, "This method(%s) does not apply to this type(%s)."
- def_exception :CommandNotFound, "Command not found(%s)."
- end
-end
-
diff --git a/ruby_2_2/lib/shell/filter.rb b/ruby_2_2/lib/shell/filter.rb
deleted file mode 100644
index 9fae07d23e..0000000000
--- a/ruby_2_2/lib/shell/filter.rb
+++ /dev/null
@@ -1,137 +0,0 @@
-#
-# shell/filter.rb -
-# $Release Version: 0.7 $
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-class Shell #:nodoc:
- # Any result of command execution is a Filter.
- #
- # This class includes Enumerable, therefore a Filter object can use all
- # Enumerable
- # facilities.
- #
- class Filter
- include Enumerable
-
- def initialize(sh)
- @shell = sh # parent shell
- @input = nil # input filter
- end
-
- attr_reader :input
-
- def input=(filter)
- @input = filter
- end
-
- # call-seq:
- # each(record_separator=nil) { block }
- #
- # Iterates a block for each line.
- def each(rs = nil)
- rs = @shell.record_separator unless rs
- if @input
- @input.each(rs){|l| yield l}
- end
- end
-
- # call-seq:
- # < source
- #
- # Inputs from +source+, which is either a string of a file name or an IO
- # object.
- def < (src)
- case src
- when String
- cat = Cat.new(@shell, src)
- cat | self
- when IO
- self.input = src
- self
- else
- Shell.Fail Error::CantApplyMethod, "<", to.class
- end
- end
-
- # call-seq:
- # > source
- #
- # Outputs from +source+, which is either a string of a file name or an IO
- # object.
- def > (to)
- case to
- when String
- dst = @shell.open(to, "w")
- begin
- each(){|l| dst << l}
- ensure
- dst.close
- end
- when IO
- each(){|l| to << l}
- else
- Shell.Fail Error::CantApplyMethod, ">", to.class
- end
- self
- end
-
- # call-seq:
- # >> source
- #
- # Appends the output to +source+, which is either a string of a file name
- # or an IO object.
- def >> (to)
- begin
- Shell.cd(@shell.pwd).append(to, self)
- rescue CantApplyMethod
- Shell.Fail Error::CantApplyMethod, ">>", to.class
- end
- end
-
- # call-seq:
- # | filter
- #
- # Processes a pipeline.
- def | (filter)
- filter.input = self
- if active?
- @shell.process_controller.start_job filter
- end
- filter
- end
-
- # call-seq:
- # filter1 + filter2
- #
- # Outputs +filter1+, and then +filter2+ using Join.new
- def + (filter)
- Join.new(@shell, self, filter)
- end
-
- def to_a
- ary = []
- each(){|l| ary.push l}
- ary
- end
-
- def to_s
- str = ""
- each(){|l| str.concat l}
- str
- end
-
- def inspect
- if @shell.debug.kind_of?(Integer) && @shell.debug > 2
- super
- else
- to_s
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/shell/process-controller.rb b/ruby_2_2/lib/shell/process-controller.rb
deleted file mode 100644
index d0cad0ec05..0000000000
--- a/ruby_2_2/lib/shell/process-controller.rb
+++ /dev/null
@@ -1,310 +0,0 @@
-#
-# shell/process-controller.rb -
-# $Release Version: 0.7 $
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-require "forwardable"
-
-require "thread"
-require "sync"
-
-class Shell
- class ProcessController
-
- @ProcessControllers = {}
- @ProcessControllersMonitor = Mutex.new
- @ProcessControllersCV = ConditionVariable.new
-
- @BlockOutputMonitor = Mutex.new
- @BlockOutputCV = ConditionVariable.new
-
- class << self
- extend Forwardable
-
- def_delegator("@ProcessControllersMonitor",
- "synchronize", "process_controllers_exclusive")
-
- def active_process_controllers
- process_controllers_exclusive do
- @ProcessControllers.dup
- end
- end
-
- def activate(pc)
- process_controllers_exclusive do
- @ProcessControllers[pc] ||= 0
- @ProcessControllers[pc] += 1
- end
- end
-
- def inactivate(pc)
- process_controllers_exclusive do
- if @ProcessControllers[pc]
- if (@ProcessControllers[pc] -= 1) == 0
- @ProcessControllers.delete(pc)
- @ProcessControllersCV.signal
- end
- end
- end
- end
-
- def each_active_object
- process_controllers_exclusive do
- for ref in @ProcessControllers.keys
- yield ref
- end
- end
- end
-
- def block_output_synchronize(&b)
- @BlockOutputMonitor.synchronize(&b)
- end
-
- def wait_to_finish_all_process_controllers
- process_controllers_exclusive do
- while !@ProcessControllers.empty?
- Shell::notify("Process finishing, but active shell exists",
- "You can use Shell#transact or Shell#check_point for more safe execution.")
- if Shell.debug?
- for pc in @ProcessControllers.keys
- Shell::notify(" Not finished jobs in "+pc.shell.to_s)
- for com in pc.jobs
- com.notify(" Jobs: %id")
- end
- end
- end
- @ProcessControllersCV.wait(@ProcessControllersMonitor)
- end
- end
- end
- end
-
- # for shell-command complete finish at this process exit.
- USING_AT_EXIT_WHEN_PROCESS_EXIT = true
- at_exit do
- wait_to_finish_all_process_controllers unless $@
- end
-
- def initialize(shell)
- @shell = shell
- @waiting_jobs = []
- @active_jobs = []
- @jobs_sync = Sync.new
-
- @job_monitor = Mutex.new
- @job_condition = ConditionVariable.new
- end
-
- attr_reader :shell
-
- def jobs
- jobs = []
- @jobs_sync.synchronize(:SH) do
- jobs.concat @waiting_jobs
- jobs.concat @active_jobs
- end
- jobs
- end
-
- def active_jobs
- @active_jobs
- end
-
- def waiting_jobs
- @waiting_jobs
- end
-
- def jobs_exist?
- @jobs_sync.synchronize(:SH) do
- @active_jobs.empty? or @waiting_jobs.empty?
- end
- end
-
- def active_jobs_exist?
- @jobs_sync.synchronize(:SH) do
- @active_jobs.empty?
- end
- end
-
- def waiting_jobs_exist?
- @jobs_sync.synchronize(:SH) do
- @waiting_jobs.empty?
- end
- end
-
- # schedule a command
- def add_schedule(command)
- @jobs_sync.synchronize(:EX) do
- ProcessController.activate(self)
- if @active_jobs.empty?
- start_job command
- else
- @waiting_jobs.push(command)
- end
- end
- end
-
- # start a job
- def start_job(command = nil)
- @jobs_sync.synchronize(:EX) do
- if command
- return if command.active?
- @waiting_jobs.delete command
- else
- command = @waiting_jobs.shift
-
- return unless command
- end
- @active_jobs.push command
- command.start
-
- # start all jobs that input from the job
- for job in @waiting_jobs.dup
- start_job(job) if job.input == command
- end
- end
- end
-
- def waiting_job?(job)
- @jobs_sync.synchronize(:SH) do
- @waiting_jobs.include?(job)
- end
- end
-
- def active_job?(job)
- @jobs_sync.synchronize(:SH) do
- @active_jobs.include?(job)
- end
- end
-
- # terminate a job
- def terminate_job(command)
- @jobs_sync.synchronize(:EX) do
- @active_jobs.delete command
- ProcessController.inactivate(self)
- if @active_jobs.empty?
- command.notify("start_job in terminate_job(%id)", Shell::debug?)
- start_job
- end
- end
- end
-
- # kill a job
- def kill_job(sig, command)
- @jobs_sync.synchronize(:EX) do
- if @waiting_jobs.delete command
- ProcessController.inactivate(self)
- return
- elsif @active_jobs.include?(command)
- begin
- r = command.kill(sig)
- ProcessController.inactivate(self)
- rescue
- print "Shell: Warn: $!\n" if @shell.verbose?
- return nil
- end
- @active_jobs.delete command
- r
- end
- end
- end
-
- # wait for all jobs to terminate
- def wait_all_jobs_execution
- @job_monitor.synchronize do
- begin
- while !jobs.empty?
- @job_condition.wait(@job_monitor)
- for job in jobs
- job.notify("waiting job(%id)", Shell::debug?)
- end
- end
- ensure
- redo unless jobs.empty?
- end
- end
- end
-
- # simple fork
- def sfork(command)
- pipe_me_in, pipe_peer_out = IO.pipe
- pipe_peer_in, pipe_me_out = IO.pipe
-
-
- pid = nil
- pid_mutex = Mutex.new
- pid_cv = ConditionVariable.new
-
- Thread.start do
- ProcessController.block_output_synchronize do
- STDOUT.flush
- ProcessController.each_active_object do |pc|
- for jobs in pc.active_jobs
- jobs.flush
- end
- end
-
- pid = fork {
- Thread.list.each do |th|
- th.kill unless Thread.current == th
- end
-
- STDIN.reopen(pipe_peer_in)
- STDOUT.reopen(pipe_peer_out)
-
- ObjectSpace.each_object(IO) do |io|
- if ![STDIN, STDOUT, STDERR].include?(io)
- io.close unless io.closed?
- end
- end
-
- yield
- }
- end
- pid_cv.signal
-
- pipe_peer_in.close
- pipe_peer_out.close
- command.notify "job(%name:##{pid}) start", @shell.debug?
-
- begin
- _pid = nil
- command.notify("job(%id) start to waiting finish.", @shell.debug?)
- _pid = Process.waitpid(pid, nil)
- rescue Errno::ECHILD
- command.notify "warn: job(%id) was done already waitpid."
- _pid = true
- ensure
- command.notify("Job(%id): Wait to finish when Process finished.", @shell.debug?)
- # when the process ends, wait until the command terminates
- if USING_AT_EXIT_WHEN_PROCESS_EXIT or _pid
- else
- command.notify("notice: Process finishing...",
- "wait for Job[%id] to finish.",
- "You can use Shell#transact or Shell#check_point for more safe execution.")
- redo
- end
-
- @job_monitor.synchronize do
- terminate_job(command)
- @job_condition.signal
- command.notify "job(%id) finish.", @shell.debug?
- end
- end
- end
-
- pid_mutex.synchronize do
- while !pid
- pid_cv.wait(pid_mutex)
- end
- end
-
- return pid, pipe_me_in, pipe_me_out
- end
- end
-end
diff --git a/ruby_2_2/lib/shell/system-command.rb b/ruby_2_2/lib/shell/system-command.rb
deleted file mode 100644
index 1fe37333d6..0000000000
--- a/ruby_2_2/lib/shell/system-command.rb
+++ /dev/null
@@ -1,158 +0,0 @@
-#
-# shell/system-command.rb -
-# $Release Version: 0.7 $
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-require "shell/filter"
-
-class Shell
- class SystemCommand < Filter
- def initialize(sh, command, *opts)
- if t = opts.find{|opt| !opt.kind_of?(String) && opt.class}
- Shell.Fail Error::TypeError, t.class, "String"
- end
- super(sh)
- @command = command
- @opts = opts
-
- @input_queue = Queue.new
- @pid = nil
-
- sh.process_controller.add_schedule(self)
- end
-
- attr_reader :command
- alias name command
-
- def wait?
- @shell.process_controller.waiting_job?(self)
- end
-
- def active?
- @shell.process_controller.active_job?(self)
- end
-
- def input=(inp)
- super
- if active?
- start_export
- end
- end
-
- def start
- notify([@command, *@opts].join(" "))
-
- @pid, @pipe_in, @pipe_out = @shell.process_controller.sfork(self) {
- Dir.chdir @shell.pwd
- $0 = @command
- exec(@command, *@opts)
- }
- if @input
- start_export
- end
- start_import
- end
-
- def flush
- @pipe_out.flush if @pipe_out and !@pipe_out.closed?
- end
-
- def terminate
- begin
- @pipe_in.close
- rescue IOError
- end
- begin
- @pipe_out.close
- rescue IOError
- end
- end
-
- def kill(sig)
- if @pid
- Process.kill(sig, @pid)
- end
- end
-
- def start_import
- notify "Job(%id) start imp-pipe.", @shell.debug?
- _eop = true
- Thread.start {
- begin
- while l = @pipe_in.gets
- @input_queue.push l
- end
- _eop = false
- rescue Errno::EPIPE
- _eop = false
- ensure
- if !ProcessController::USING_AT_EXIT_WHEN_PROCESS_EXIT and _eop
- notify("warn: Process finishing...",
- "wait for Job[%id] to finish pipe importing.",
- "You can use Shell#transact or Shell#check_point for more safe execution.")
- redo
- end
- notify "job(%id}) close imp-pipe.", @shell.debug?
- @input_queue.push :EOF
- @pipe_in.close
- end
- }
- end
-
- def start_export
- notify "job(%id) start exp-pipe.", @shell.debug?
- _eop = true
- Thread.start{
- begin
- @input.each do |l|
- ProcessController::block_output_synchronize do
- @pipe_out.print l
- end
- end
- _eop = false
- rescue Errno::EPIPE, Errno::EIO
- _eop = false
- ensure
- if !ProcessController::USING_AT_EXIT_WHEN_PROCESS_EXIT and _eop
- notify("shell: warn: Process finishing...",
- "wait for Job(%id) to finish pipe exporting.",
- "You can use Shell#transact or Shell#check_point for more safe execution.")
- redo
- end
- notify "job(%id) close exp-pipe.", @shell.debug?
- @pipe_out.close
- end
- }
- end
-
- alias super_each each
- def each(rs = nil)
- while (l = @input_queue.pop) != :EOF
- yield l
- end
- end
-
- # ex)
- # if you wish to output:
- # "shell: job(#{@command}:#{@pid}) close pipe-out."
- # then
- # mes: "job(%id) close pipe-out."
- # yorn: Boolean(@shell.debug? or @shell.verbose?)
- def notify(*opts)
- @shell.notify(*opts) do |mes|
- yield mes if iterator?
-
- mes.gsub!("%id", "#{@command}:##{@pid}")
- mes.gsub!("%name", "#{@command}")
- mes.gsub!("%pid", "#{@pid}")
- mes
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/shell/version.rb b/ruby_2_2/lib/shell/version.rb
deleted file mode 100644
index 2568627e2b..0000000000
--- a/ruby_2_2/lib/shell/version.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-#
-# version.rb - shell version definition file
-# $Release Version: 0.7$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
-#
-# --
-#
-#
-#
-
-class Shell # :nodoc:
- @RELEASE_VERSION = "0.7"
- @LAST_UPDATE_DATE = "07/03/20"
-end
diff --git a/ruby_2_2/lib/shellwords.rb b/ruby_2_2/lib/shellwords.rb
deleted file mode 100644
index 2b72750a6b..0000000000
--- a/ruby_2_2/lib/shellwords.rb
+++ /dev/null
@@ -1,215 +0,0 @@
-##
-# == Manipulates strings like the UNIX Bourne shell
-#
-# This module manipulates strings according to the word parsing rules
-# of the UNIX Bourne shell.
-#
-# The shellwords() function was originally a port of shellwords.pl,
-# but modified to conform to POSIX / SUSv3 (IEEE Std 1003.1-2001 [1]).
-#
-# === Usage
-#
-# You can use Shellwords to parse a string into a Bourne shell friendly Array.
-#
-# require 'shellwords'
-#
-# argv = Shellwords.split('three blind "mice"')
-# argv #=> ["three", "blind", "mice"]
-#
-# Once you've required Shellwords, you can use the #split alias
-# String#shellsplit.
-#
-# argv = "see how they run".shellsplit
-# argv #=> ["see", "how", "they", "run"]
-#
-# Be careful you don't leave a quote unmatched.
-#
-# argv = "they all ran after the farmer's wife".shellsplit
-# #=> ArgumentError: Unmatched double quote: ...
-#
-# In this case, you might want to use Shellwords.escape, or its alias
-# String#shellescape.
-#
-# This method will escape the String for you to safely use with a Bourne shell.
-#
-# argv = Shellwords.escape("special's.txt")
-# argv #=> "special\\'s.txt"
-# system("cat " + argv)
-#
-# Shellwords also comes with a core extension for Array, Array#shelljoin.
-#
-# argv = %w{ls -lta lib}
-# system(argv.shelljoin)
-#
-# You can use this method to create an escaped string out of an array of tokens
-# separated by a space. In this example we used the literal shortcut for
-# Array.new.
-#
-# === Authors
-# * Wakou Aoyama
-# * Akinori MUSHA <knu@iDaemons.org>
-#
-# === Contact
-# * Akinori MUSHA <knu@iDaemons.org> (current maintainer)
-#
-# === Resources
-#
-# 1: {IEEE Std 1003.1-2004}[http://pubs.opengroup.org/onlinepubs/009695399/toc.htm]
-
-module Shellwords
- # Splits a string into an array of tokens in the same way the UNIX
- # Bourne shell does.
- #
- # argv = Shellwords.split('here are "two words"')
- # argv #=> ["here", "are", "two words"]
- #
- # String#shellsplit is a shortcut for this function.
- #
- # argv = 'here are "two words"'.shellsplit
- # argv #=> ["here", "are", "two words"]
- def shellsplit(line)
- words = []
- field = ''
- line.scan(/\G\s*(?>([^\s\\\'\"]+)|'([^\']*)'|"((?:[^\"\\]|\\.)*)"|(\\.?)|(\S))(\s|\z)?/m) do
- |word, sq, dq, esc, garbage, sep|
- raise ArgumentError, "Unmatched double quote: #{line.inspect}" if garbage
- field << (word || sq || (dq || esc).gsub(/\\(.)/, '\\1'))
- if sep
- words << field
- field = ''
- end
- end
- words
- end
-
- alias shellwords shellsplit
-
- module_function :shellsplit, :shellwords
-
- class << self
- alias split shellsplit
- end
-
- # Escapes a string so that it can be safely used in a Bourne shell
- # command line. +str+ can be a non-string object that responds to
- # +to_s+.
- #
- # Note that a resulted string should be used unquoted and is not
- # intended for use in double quotes nor in single quotes.
- #
- # argv = Shellwords.escape("It's better to give than to receive")
- # argv #=> "It\\'s\\ better\\ to\\ give\\ than\\ to\\ receive"
- #
- # String#shellescape is a shorthand for this function.
- #
- # argv = "It's better to give than to receive".shellescape
- # argv #=> "It\\'s\\ better\\ to\\ give\\ than\\ to\\ receive"
- #
- # # Search files in lib for method definitions
- # pattern = "^[ \t]*def "
- # open("| grep -Ern #{pattern.shellescape} lib") { |grep|
- # grep.each_line { |line|
- # file, lineno, matched_line = line.split(':', 3)
- # # ...
- # }
- # }
- #
- # It is the caller's responsibility to encode the string in the right
- # encoding for the shell environment where this string is used.
- #
- # Multibyte characters are treated as multibyte characters, not as bytes.
- #
- # Returns an empty quoted String if +str+ has a length of zero.
- def shellescape(str)
- str = str.to_s
-
- # An empty argument will be skipped, so return empty quotes.
- return "''" if str.empty?
-
- str = str.dup
-
- # Treat multibyte characters as is. It is the caller's responsibility
- # to encode the string in the right encoding for the shell
- # environment.
- str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/, "\\\\\\1")
-
- # A LF cannot be escaped with a backslash because a backslash + LF
- # combo is regarded as a line continuation and simply ignored.
- str.gsub!(/\n/, "'\n'")
-
- return str
- end
-
- module_function :shellescape
-
- class << self
- alias escape shellescape
- end
-
- # Builds a command line string from an argument list, +array+.
- #
- # All elements are joined into a single string with fields separated by a
- # space, where each element is escaped for the Bourne shell and stringified
- # using +to_s+.
- #
- # ary = ["There's", "a", "time", "and", "place", "for", "everything"]
- # argv = Shellwords.join(ary)
- # argv #=> "There\\'s a time and place for everything"
- #
- # Array#shelljoin is a shortcut for this function.
- #
- # ary = ["Don't", "rock", "the", "boat"]
- # argv = ary.shelljoin
- # argv #=> "Don\\'t rock the boat"
- #
- # You can also mix non-string objects in the elements as allowed in Array#join.
- #
- # output = `#{['ps', '-p', $$].shelljoin}`
- #
- def shelljoin(array)
- array.map { |arg| shellescape(arg) }.join(' ')
- end
-
- module_function :shelljoin
-
- class << self
- alias join shelljoin
- end
-end
-
-class String
- # call-seq:
- # str.shellsplit => array
- #
- # Splits +str+ into an array of tokens in the same way the UNIX
- # Bourne shell does.
- #
- # See Shellwords.shellsplit for details.
- def shellsplit
- Shellwords.split(self)
- end
-
- # call-seq:
- # str.shellescape => string
- #
- # Escapes +str+ so that it can be safely used in a Bourne shell
- # command line.
- #
- # See Shellwords.shellescape for details.
- def shellescape
- Shellwords.escape(self)
- end
-end
-
-class Array
- # call-seq:
- # array.shelljoin => string
- #
- # Builds a command line string from an argument list +array+ joining
- # all elements escaped for the Bourne shell and separated by a space.
- #
- # See Shellwords.shelljoin for details.
- def shelljoin
- Shellwords.join(self)
- end
-end
diff --git a/ruby_2_2/lib/singleton.rb b/ruby_2_2/lib/singleton.rb
deleted file mode 100644
index be1f7ff6ca..0000000000
--- a/ruby_2_2/lib/singleton.rb
+++ /dev/null
@@ -1,172 +0,0 @@
-require 'thread'
-
-# The Singleton module implements the Singleton pattern.
-#
-# == Usage
-#
-# To use Singleton, include the module in your class.
-#
-# class Klass
-# include Singleton
-# # ...
-# end
-#
-# This ensures that only one instance of Klass can be created.
-#
-# a,b = Klass.instance, Klass.instance
-#
-# a == b
-# # => true
-#
-# Klass.new
-# # => NoMethodError - new is private ...
-#
-# The instance is created at upon the first call of Klass.instance().
-#
-# class OtherKlass
-# include Singleton
-# # ...
-# end
-#
-# ObjectSpace.each_object(OtherKlass){}
-# # => 0
-#
-# OtherKlass.instance
-# ObjectSpace.each_object(OtherKlass){}
-# # => 1
-#
-#
-# This behavior is preserved under inheritance and cloning.
-#
-# == Implementation
-#
-# This above is achieved by:
-#
-# * Making Klass.new and Klass.allocate private.
-#
-# * Overriding Klass.inherited(sub_klass) and Klass.clone() to ensure that the
-# Singleton properties are kept when inherited and cloned.
-#
-# * Providing the Klass.instance() method that returns the same object each
-# time it is called.
-#
-# * Overriding Klass._load(str) to call Klass.instance().
-#
-# * Overriding Klass#clone and Klass#dup to raise TypeErrors to prevent
-# cloning or duping.
-#
-# == Singleton and Marshal
-#
-# By default Singleton's #_dump(depth) returns the empty string. Marshalling by
-# default will strip state information, e.g. instance variables and taint
-# state, from the instance. Classes using Singleton can provide custom
-# _load(str) and _dump(depth) methods to retain some of the previous state of
-# the instance.
-#
-# require 'singleton'
-#
-# class Example
-# include Singleton
-# attr_accessor :keep, :strip
-# def _dump(depth)
-# # this strips the @strip information from the instance
-# Marshal.dump(@keep, depth)
-# end
-#
-# def self._load(str)
-# instance.keep = Marshal.load(str)
-# instance
-# end
-# end
-#
-# a = Example.instance
-# a.keep = "keep this"
-# a.strip = "get rid of this"
-# a.taint
-#
-# stored_state = Marshal.dump(a)
-#
-# a.keep = nil
-# a.strip = nil
-# b = Marshal.load(stored_state)
-# p a == b # => true
-# p a.keep # => "keep this"
-# p a.strip # => nil
-#
-module Singleton
- # Raises a TypeError to prevent cloning.
- def clone
- raise TypeError, "can't clone instance of singleton #{self.class}"
- end
-
- # Raises a TypeError to prevent duping.
- def dup
- raise TypeError, "can't dup instance of singleton #{self.class}"
- end
-
- # By default, do not retain any state when marshalling.
- def _dump(depth = -1)
- ''
- end
-
- module SingletonClassMethods # :nodoc:
-
- def clone # :nodoc:
- Singleton.__init__(super)
- end
-
- # By default calls instance(). Override to retain singleton state.
- def _load(str)
- instance
- end
-
- private
-
- def inherited(sub_klass)
- super
- Singleton.__init__(sub_klass)
- end
- end
-
- class << Singleton # :nodoc:
- def __init__(klass) # :nodoc:
- klass.instance_eval {
- @singleton__instance__ = nil
- @singleton__mutex__ = Mutex.new
- }
- def klass.instance # :nodoc:
- return @singleton__instance__ if @singleton__instance__
- @singleton__mutex__.synchronize {
- return @singleton__instance__ if @singleton__instance__
- @singleton__instance__ = new()
- }
- @singleton__instance__
- end
- klass
- end
-
- private
-
- # extending an object with Singleton is a bad idea
- undef_method :extend_object
-
- def append_features(mod)
- # help out people counting on transitive mixins
- unless mod.instance_of?(Class)
- raise TypeError, "Inclusion of the OO-Singleton module in module #{mod}"
- end
- super
- end
-
- def included(klass)
- super
- klass.private_class_method :new, :allocate
- klass.extend SingletonClassMethods
- Singleton.__init__(klass)
- end
- end
-
- ##
- # :singleton-method: _load
- # By default calls instance(). Override to retain singleton state.
-end
diff --git a/ruby_2_2/lib/sync.rb b/ruby_2_2/lib/sync.rb
deleted file mode 100644
index 09542d59f9..0000000000
--- a/ruby_2_2/lib/sync.rb
+++ /dev/null
@@ -1,328 +0,0 @@
-#
-# sync.rb - 2 phase lock with counter
-# $Release Version: 1.0$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ishitsuka.com)
-#
-# --
-# Sync_m, Synchronizer_m
-# Usage:
-# obj.extend(Sync_m)
-# or
-# class Foo
-# include Sync_m
-# :
-# end
-#
-# Sync_m#sync_mode
-# Sync_m#sync_locked?, locked?
-# Sync_m#sync_shared?, shared?
-# Sync_m#sync_exclusive?, sync_exclusive?
-# Sync_m#sync_try_lock, try_lock
-# Sync_m#sync_lock, lock
-# Sync_m#sync_unlock, unlock
-#
-# Sync, Synchronizer:
-# Usage:
-# sync = Sync.new
-#
-# Sync#mode
-# Sync#locked?
-# Sync#shared?
-# Sync#exclusive?
-# Sync#try_lock(mode) -- mode = :EX, :SH, :UN
-# Sync#lock(mode) -- mode = :EX, :SH, :UN
-# Sync#unlock
-# Sync#synchronize(mode) {...}
-#
-#
-
-unless defined? Thread
- raise "Thread not available for this ruby interpreter"
-end
-
-##
-# A module that provides a two-phase lock with a counter.
-
-module Sync_m
- # lock mode
- UN = :UN
- SH = :SH
- EX = :EX
-
- # exceptions
- class Err < StandardError
- def Err.Fail(*opt)
- fail self, sprintf(self::Message, *opt)
- end
-
- class UnknownLocker < Err
- Message = "Thread(%s) not locked."
- def UnknownLocker.Fail(th)
- super(th.inspect)
- end
- end
-
- class LockModeFailer < Err
- Message = "Unknown lock mode(%s)"
- def LockModeFailer.Fail(mode)
- if mode.id2name
- mode = id2name
- end
- super(mode)
- end
- end
- end
-
- def Sync_m.define_aliases(cl)
- cl.module_eval %q{
- alias locked? sync_locked?
- alias shared? sync_shared?
- alias exclusive? sync_exclusive?
- alias lock sync_lock
- alias unlock sync_unlock
- alias try_lock sync_try_lock
- alias synchronize sync_synchronize
- }
- end
-
- def Sync_m.append_features(cl)
- super
- # do nothing for Modules
- # make aliases for Classes.
- define_aliases(cl) unless cl.instance_of?(Module)
- self
- end
-
- def Sync_m.extend_object(obj)
- super
- obj.sync_extend
- end
-
- def sync_extend
- unless (defined? locked? and
- defined? shared? and
- defined? exclusive? and
- defined? lock and
- defined? unlock and
- defined? try_lock and
- defined? synchronize)
- Sync_m.define_aliases(singleton_class)
- end
- sync_initialize
- end
-
- # accessing
- def sync_locked?
- sync_mode != UN
- end
-
- def sync_shared?
- sync_mode == SH
- end
-
- def sync_exclusive?
- sync_mode == EX
- end
-
- # locking methods.
- def sync_try_lock(mode = EX)
- return unlock if mode == UN
- @sync_mutex.synchronize do
- sync_try_lock_sub(mode)
- end
- end
-
- def sync_lock(m = EX)
- return unlock if m == UN
- Thread.handle_interrupt(StandardError => :on_blocking) do
- while true
- @sync_mutex.synchronize do
- begin
- if sync_try_lock_sub(m)
- return self
- else
- if sync_sh_locker[Thread.current]
- sync_upgrade_waiting.push [Thread.current, sync_sh_locker[Thread.current]]
- sync_sh_locker.delete(Thread.current)
- else
- unless sync_waiting.include?(Thread.current) || sync_upgrade_waiting.reverse_each.any?{|w| w.first == Thread.current }
- sync_waiting.push Thread.current
- end
- end
- @sync_mutex.sleep
- end
- ensure
- sync_waiting.delete(Thread.current)
- end
- end
- end
- end
- self
- end
-
- def sync_unlock(m = EX)
- wakeup_threads = []
- @sync_mutex.synchronize do
- if sync_mode == UN
- Err::UnknownLocker.Fail(Thread.current)
- end
-
- m = sync_mode if m == EX and sync_mode == SH
-
- runnable = false
- case m
- when UN
- Err::UnknownLocker.Fail(Thread.current)
-
- when EX
- if sync_ex_locker == Thread.current
- if (self.sync_ex_count = sync_ex_count - 1) == 0
- self.sync_ex_locker = nil
- if sync_sh_locker.include?(Thread.current)
- self.sync_mode = SH
- else
- self.sync_mode = UN
- end
- runnable = true
- end
- else
- Err::UnknownLocker.Fail(Thread.current)
- end
-
- when SH
- if (count = sync_sh_locker[Thread.current]).nil?
- Err::UnknownLocker.Fail(Thread.current)
- else
- if (sync_sh_locker[Thread.current] = count - 1) == 0
- sync_sh_locker.delete(Thread.current)
- if sync_sh_locker.empty? and sync_ex_count == 0
- self.sync_mode = UN
- runnable = true
- end
- end
- end
- end
-
- if runnable
- if sync_upgrade_waiting.size > 0
- th, count = sync_upgrade_waiting.shift
- sync_sh_locker[th] = count
- th.wakeup
- wakeup_threads.push th
- else
- wait = sync_waiting
- self.sync_waiting = []
- for th in wait
- th.wakeup
- wakeup_threads.push th
- end
- end
- end
- end
- for th in wakeup_threads
- th.run
- end
- self
- end
-
- def sync_synchronize(mode = EX)
- Thread.handle_interrupt(StandardError => :on_blocking) do
- sync_lock(mode)
- begin
- yield
- ensure
- sync_unlock
- end
- end
- end
-
- attr_accessor :sync_mode
-
- attr_accessor :sync_waiting
- attr_accessor :sync_upgrade_waiting
- attr_accessor :sync_sh_locker
- attr_accessor :sync_ex_locker
- attr_accessor :sync_ex_count
-
- def sync_inspect
- sync_iv = instance_variables.select{|iv| /^@sync_/ =~ iv.id2name}.collect{|iv| iv.id2name + '=' + instance_eval(iv.id2name).inspect}.join(",")
- print "<#{self.class}.extend Sync_m: #{inspect}, <Sync_m: #{sync_iv}>"
- end
-
- private
-
- def sync_initialize
- @sync_mode = UN
- @sync_waiting = []
- @sync_upgrade_waiting = []
- @sync_sh_locker = Hash.new
- @sync_ex_locker = nil
- @sync_ex_count = 0
-
- @sync_mutex = Mutex.new
- end
-
- def initialize(*args)
- super
- sync_initialize
- end
-
- def sync_try_lock_sub(m)
- case m
- when SH
- case sync_mode
- when UN
- self.sync_mode = m
- sync_sh_locker[Thread.current] = 1
- ret = true
- when SH
- count = 0 unless count = sync_sh_locker[Thread.current]
- sync_sh_locker[Thread.current] = count + 1
- ret = true
- when EX
- # in EX mode, lock will upgrade to EX lock
- if sync_ex_locker == Thread.current
- self.sync_ex_count = sync_ex_count + 1
- ret = true
- else
- ret = false
- end
- end
- when EX
- if sync_mode == UN or
- sync_mode == SH && sync_sh_locker.size == 1 && sync_sh_locker.include?(Thread.current)
- self.sync_mode = m
- self.sync_ex_locker = Thread.current
- self.sync_ex_count = 1
- ret = true
- elsif sync_mode == EX && sync_ex_locker == Thread.current
- self.sync_ex_count = sync_ex_count + 1
- ret = true
- else
- ret = false
- end
- else
- Err::LockModeFailer.Fail mode
- end
- return ret
- end
-end
-
-##
-# An alias for Sync_m from sync.rb
-
-Synchronizer_m = Sync_m
-
-##
-# A class that provides two-phase lock with a counter. See Sync_m for
-# details.
-
-class Sync
- include Sync_m
-end
-
-##
-# An alias for Sync from sync.rb. See Sync_m for details.
-
-Synchronizer = Sync
diff --git a/ruby_2_2/lib/tempfile.rb b/ruby_2_2/lib/tempfile.rb
deleted file mode 100644
index 64441511fe..0000000000
--- a/ruby_2_2/lib/tempfile.rb
+++ /dev/null
@@ -1,367 +0,0 @@
-#
-# tempfile - manipulates temporary files
-#
-# $Id$
-#
-
-require 'delegate'
-require 'tmpdir'
-
-# A utility class for managing temporary files. When you create a Tempfile
-# object, it will create a temporary file with a unique filename. A Tempfile
-# objects behaves just like a File object, and you can perform all the usual
-# file operations on it: reading data, writing data, changing its permissions,
-# etc. So although this class does not explicitly document all instance methods
-# supported by File, you can in fact call any File instance method on a
-# Tempfile object.
-#
-# == Synopsis
-#
-# require 'tempfile'
-#
-# file = Tempfile.new('foo')
-# file.path # => A unique filename in the OS's temp directory,
-# # e.g.: "/tmp/foo.24722.0"
-# # This filename contains 'foo' in its basename.
-# file.write("hello world")
-# file.rewind
-# file.read # => "hello world"
-# file.close
-# file.unlink # deletes the temp file
-#
-# == Good practices
-#
-# === Explicit close
-#
-# When a Tempfile object is garbage collected, or when the Ruby interpreter
-# exits, its associated temporary file is automatically deleted. This means
-# that's it's unnecessary to explicitly delete a Tempfile after use, though
-# it's good practice to do so: not explicitly deleting unused Tempfiles can
-# potentially leave behind large amounts of tempfiles on the filesystem
-# until they're garbage collected. The existence of these temp files can make
-# it harder to determine a new Tempfile filename.
-#
-# Therefore, one should always call #unlink or close in an ensure block, like
-# this:
-#
-# file = Tempfile.new('foo')
-# begin
-# ...do something with file...
-# ensure
-# file.close
-# file.unlink # deletes the temp file
-# end
-#
-# === Unlink after creation
-#
-# On POSIX systems, it's possible to unlink a file right after creating it,
-# and before closing it. This removes the filesystem entry without closing
-# the file handle, so it ensures that only the processes that already had
-# the file handle open can access the file's contents. It's strongly
-# recommended that you do this if you do not want any other processes to
-# be able to read from or write to the Tempfile, and you do not need to
-# know the Tempfile's filename either.
-#
-# For example, a practical use case for unlink-after-creation would be this:
-# you need a large byte buffer that's too large to comfortably fit in RAM,
-# e.g. when you're writing a web server and you want to buffer the client's
-# file upload data.
-#
-# Please refer to #unlink for more information and a code example.
-#
-# == Minor notes
-#
-# Tempfile's filename picking method is both thread-safe and inter-process-safe:
-# it guarantees that no other threads or processes will pick the same filename.
-#
-# Tempfile itself however may not be entirely thread-safe. If you access the
-# same Tempfile object from multiple threads then you should protect it with a
-# mutex.
-class Tempfile < DelegateClass(File)
- # call-seq:
- # new(basename, [tmpdir = Dir.tmpdir], [options])
- #
- # Creates a temporary file with permissions 0600 (= only readable and
- # writable by the owner) and opens it with mode "w+".
- #
- # The +basename+ parameter is used to determine the name of the
- # temporary file. You can either pass a String or an Array with
- # 2 String elements. In the former form, the temporary file's base
- # name will begin with the given string. In the latter form,
- # the temporary file's base name will begin with the array's first
- # element, and end with the second element. For example:
- #
- # file = Tempfile.new('hello')
- # file.path # => something like: "/tmp/hello2843-8392-92849382--0"
- #
- # # Use the Array form to enforce an extension in the filename:
- # file = Tempfile.new(['hello', '.jpg'])
- # file.path # => something like: "/tmp/hello2843-8392-92849382--0.jpg"
- #
- # The temporary file will be placed in the directory as specified
- # by the +tmpdir+ parameter. By default, this is +Dir.tmpdir+.
- # When $SAFE > 0 and the given +tmpdir+ is tainted, it uses
- # '/tmp' as the temporary directory. Please note that ENV values
- # are tainted by default, and +Dir.tmpdir+'s return value might
- # come from environment variables (e.g. <tt>$TMPDIR</tt>).
- #
- # file = Tempfile.new('hello', '/home/aisaka')
- # file.path # => something like: "/home/aisaka/hello2843-8392-92849382--0"
- #
- # You can also pass an options hash. Under the hood, Tempfile creates
- # the temporary file using +File.open+. These options will be passed to
- # +File.open+. This is mostly useful for specifying encoding
- # options, e.g.:
- #
- # Tempfile.new('hello', '/home/aisaka', :encoding => 'ascii-8bit')
- #
- # # You can also omit the 'tmpdir' parameter:
- # Tempfile.new('hello', :encoding => 'ascii-8bit')
- #
- # === Exceptions
- #
- # If Tempfile.new cannot find a unique filename within a limited
- # number of tries, then it will raise an exception.
- def initialize(basename, tmpdir=nil, mode: 0, **options)
- if block_given?
- warn "Tempfile.new doesn't call the given block."
- end
- @data = []
- @clean_proc = Remover.new(@data)
- ObjectSpace.define_finalizer(self, @clean_proc)
-
- ::Dir::Tmpname.create(basename, tmpdir, options) do |tmpname, n, opts|
- mode |= File::RDWR|File::CREAT|File::EXCL
- opts[:perm] = 0600
- @data[1] = @tmpfile = File.open(tmpname, mode, opts)
- @data[0] = @tmpname = tmpname
- @mode = mode & ~(File::CREAT|File::EXCL)
- opts.freeze
- @opts = opts
- end
-
- super(@tmpfile)
- end
-
- # Opens or reopens the file with mode "r+".
- def open
- @tmpfile.close if @tmpfile
- @tmpfile = File.open(@tmpname, @mode, @opts)
- @data[1] = @tmpfile
- __setobj__(@tmpfile)
- end
-
- def _close # :nodoc:
- begin
- @tmpfile.close if @tmpfile
- ensure
- @tmpfile = nil
- @data[1] = nil if @data
- end
- end
- protected :_close
-
- # Closes the file. If +unlink_now+ is true, then the file will be unlinked
- # (deleted) after closing. Of course, you can choose to later call #unlink
- # if you do not unlink it now.
- #
- # If you don't explicitly unlink the temporary file, the removal
- # will be delayed until the object is finalized.
- def close(unlink_now=false)
- if unlink_now
- close!
- else
- _close
- end
- end
-
- # Closes and unlinks (deletes) the file. Has the same effect as called
- # <tt>close(true)</tt>.
- def close!
- _close
- unlink
- end
-
- # Unlinks (deletes) the file from the filesystem. One should always unlink
- # the file after using it, as is explained in the "Explicit close" good
- # practice section in the Tempfile overview:
- #
- # file = Tempfile.new('foo')
- # begin
- # ...do something with file...
- # ensure
- # file.close
- # file.unlink # deletes the temp file
- # end
- #
- # === Unlink-before-close
- #
- # On POSIX systems it's possible to unlink a file before closing it. This
- # practice is explained in detail in the Tempfile overview (section
- # "Unlink after creation"); please refer there for more information.
- #
- # However, unlink-before-close may not be supported on non-POSIX operating
- # systems. Microsoft Windows is the most notable case: unlinking a non-closed
- # file will result in an error, which this method will silently ignore. If
- # you want to practice unlink-before-close whenever possible, then you should
- # write code like this:
- #
- # file = Tempfile.new('foo')
- # file.unlink # On Windows this silently fails.
- # begin
- # ... do something with file ...
- # ensure
- # file.close! # Closes the file handle. If the file wasn't unlinked
- # # because #unlink failed, then this method will attempt
- # # to do so again.
- # end
- def unlink
- return unless @tmpname
- begin
- File.unlink(@tmpname)
- rescue Errno::ENOENT
- rescue Errno::EACCES
- # may not be able to unlink on Windows; just ignore
- return
- end
- # remove tmpname from remover
- @data[0] = @data[1] = nil
- @tmpname = nil
- ObjectSpace.undefine_finalizer(self)
- end
- alias delete unlink
-
- # Returns the full path name of the temporary file.
- # This will be nil if #unlink has been called.
- def path
- @tmpname
- end
-
- # Returns the size of the temporary file. As a side effect, the IO
- # buffer is flushed before determining the size.
- def size
- if @tmpfile
- @tmpfile.flush
- @tmpfile.stat.size
- elsif @tmpname
- File.size(@tmpname)
- else
- 0
- end
- end
- alias length size
-
- # :stopdoc:
- def inspect
- if closed?
- "#<#{self.class}:#{path} (closed)>"
- else
- "#<#{self.class}:#{path}>"
- end
- end
-
- class Remover
- def initialize(data)
- @pid = $$
- @data = data
- end
-
- def call(*args)
- return if @pid != $$
-
- path, tmpfile = @data
-
- STDERR.print "removing ", path, "..." if $DEBUG
-
- tmpfile.close if tmpfile
-
- if path
- begin
- File.unlink(path)
- rescue Errno::ENOENT
- end
- end
-
- STDERR.print "done\n" if $DEBUG
- end
- end
-
- class << self
- # :startdoc:
-
- # Creates a new Tempfile.
- #
- # If no block is given, this is a synonym for Tempfile.new.
- #
- # If a block is given, then a Tempfile object will be constructed,
- # and the block is run with said object as argument. The Tempfile
- # object will be automatically closed after the block terminates.
- # The call returns the value of the block.
- #
- # In any case, all arguments (+*args+) will be passed to Tempfile.new.
- #
- # Tempfile.open('foo', '/home/temp') do |f|
- # ... do something with f ...
- # end
- #
- # # Equivalent:
- # f = Tempfile.open('foo', '/home/temp')
- # begin
- # ... do something with f ...
- # ensure
- # f.close
- # end
- def open(*args)
- tempfile = new(*args)
-
- if block_given?
- begin
- yield(tempfile)
- ensure
- tempfile.close
- end
- else
- tempfile
- end
- end
- end
-end
-
-# Creates a temporally file as usual File object (not Tempfile).
-# It don't use finalizer and delegation.
-#
-# If no block is given, this is similar to Tempfile.new except
-# creating File instead of Tempfile.
-# The created file is not removed automatically.
-# You should use File.unlink to remove it.
-#
-# If a block is given, then a File object will be constructed,
-# and the block is invoked with the object as the argument.
-# The File object will be automatically closed and
-# the temporally file is removed after the block terminates.
-# The call returns the value of the block.
-#
-# In any case, all arguments (+*args+) will be treated as Tempfile.new.
-#
-# Tempfile.create('foo', '/home/temp') do |f|
-# ... do something with f ...
-# end
-#
-def Tempfile.create(basename, tmpdir=nil, mode: 0, **options)
- tmpfile = nil
- Dir::Tmpname.create(basename, tmpdir, options) do |tmpname, n, opts|
- mode |= File::RDWR|File::CREAT|File::EXCL
- opts[:perm] = 0600
- tmpfile = File.open(tmpname, mode, opts)
- end
- if block_given?
- begin
- yield tmpfile
- ensure
- tmpfile.close if !tmpfile.closed?
- File.unlink tmpfile
- end
- else
- tmpfile
- end
-end
diff --git a/ruby_2_2/lib/thwait.rb b/ruby_2_2/lib/thwait.rb
deleted file mode 100644
index d9750a406b..0000000000
--- a/ruby_2_2/lib/thwait.rb
+++ /dev/null
@@ -1,140 +0,0 @@
-#
-# thwait.rb - thread synchronization class
-# $Release Version: 0.9 $
-# $Revision: 1.3 $
-# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd.)
-
-require "thread.rb"
-require "e2mmap.rb"
-
-#
-# This class watches for termination of multiple threads. Basic functionality
-# (wait until specified threads have terminated) can be accessed through the
-# class method ThreadsWait::all_waits. Finer control can be gained using
-# instance methods.
-#
-# Example:
-#
-# ThreadsWait.all_waits(thr1, thr2, ...) do |t|
-# STDERR.puts "Thread #{t} has terminated."
-# end
-#
-#
-# th = ThreadsWait.new(thread1,...)
-# th.next_wait # next one to be done
-#
-#
-class ThreadsWait
- extend Exception2MessageMapper
- def_exception("ErrNoWaitingThread", "No threads for waiting.")
- def_exception("ErrNoFinishedThread", "No finished threads.")
-
- #
- # Waits until all specified threads have terminated. If a block is provided,
- # it is executed for each thread as they terminate.
- #
- def ThreadsWait.all_waits(*threads) # :yield: thread
- tw = ThreadsWait.new(*threads)
- if block_given?
- tw.all_waits do |th|
- yield th
- end
- else
- tw.all_waits
- end
- end
-
- #
- # Creates a ThreadsWait object, specifying the threads to wait on.
- # Non-blocking.
- #
- def initialize(*threads)
- @threads = []
- @wait_queue = Queue.new
- join_nowait(*threads) unless threads.empty?
- end
-
- # Returns the array of threads that have not terminated yet.
- attr_reader :threads
-
- #
- # Returns +true+ if there are no threads in the pool still running.
- #
- def empty?
- @threads.empty?
- end
-
- #
- # Returns +true+ if any thread has terminated and is ready to be collected.
- #
- def finished?
- !@wait_queue.empty?
- end
-
- #
- # Waits for specified threads to terminate, and returns when one of
- # the threads terminated.
- #
- def join(*threads)
- join_nowait(*threads)
- next_wait
- end
-
- #
- # Specifies the threads that this object will wait for, but does not actually
- # wait.
- #
- def join_nowait(*threads)
- threads.flatten!
- @threads.concat threads
- for th in threads
- Thread.start(th) do |t|
- begin
- t.join
- ensure
- @wait_queue.push t
- end
- end
- end
- end
-
- #
- # Waits until any of the specified threads has terminated, and returns the one
- # that does.
- #
- # If there is no thread to wait, raises +ErrNoWaitingThread+. If +nonblock+
- # is true, and there is no terminated thread, raises +ErrNoFinishedThread+.
- #
- def next_wait(nonblock = nil)
- ThreadsWait.fail ErrNoWaitingThread if @threads.empty?
- begin
- @threads.delete(th = @wait_queue.pop(nonblock))
- th
- rescue ThreadError
- ThreadsWait.fail ErrNoFinishedThread
- end
- end
-
- #
- # Waits until all of the specified threads are terminated. If a block is
- # supplied for the method, it is executed for each thread termination.
- #
- # Raises exceptions in the same manner as +next_wait+.
- #
- def all_waits
- until @threads.empty?
- th = next_wait
- yield th if block_given?
- end
- end
-end
-
-##
-# An alias for ThreadsWait from thwait.rb
-
-ThWait = ThreadsWait
-
-# Documentation comments:
-# - Source of documentation is evenly split between Nutshell, existing
-# comments, and my own rephrasing.
-# - I'm not particularly confident that the comments are all exactly correct.
diff --git a/ruby_2_2/lib/time.rb b/ruby_2_2/lib/time.rb
deleted file mode 100644
index 134d0af0ac..0000000000
--- a/ruby_2_2/lib/time.rb
+++ /dev/null
@@ -1,682 +0,0 @@
-require 'date'
-
-# = time.rb
-#
-# When 'time' is required, Time is extended with additional methods for parsing
-# and converting Times.
-#
-# == Features
-#
-# This library extends the Time class with the following conversions between
-# date strings and Time objects:
-#
-# * date-time defined by {RFC 2822}[http://www.ietf.org/rfc/rfc2822.txt]
-# * HTTP-date defined by {RFC 2616}[http://www.ietf.org/rfc/rfc2616.txt]
-# * dateTime defined by XML Schema Part 2: Datatypes ({ISO
-# 8601}[http://www.iso.org/iso/date_and_time_format])
-# * various formats handled by Date._parse
-# * custom formats handled by Date._strptime
-#
-# == Examples
-#
-# All examples assume you have loaded Time with:
-#
-# require 'time'
-#
-# All of these examples were done using the EST timezone which is GMT-5.
-#
-# === Converting to a String
-#
-# t = Time.now
-# t.iso8601 # => "2011-10-05T22:26:12-04:00"
-# t.rfc2822 # => "Wed, 05 Oct 2011 22:26:12 -0400"
-# t.httpdate # => "Thu, 06 Oct 2011 02:26:12 GMT"
-#
-# === Time.parse
-#
-# #parse takes a string representation of a Time and attempts to parse it
-# using a heuristic.
-#
-# Date.parse("2010-10-31") #=> 2010-10-31 00:00:00 -0500
-#
-# Any missing pieces of the date are inferred based on the current date.
-#
-# # assuming the current date is "2011-10-31"
-# Time.parse("12:00") #=> 2011-10-31 12:00:00 -0500
-#
-# We can change the date used to infer our missing elements by passing a second
-# object that responds to #mon, #day and #year, such as Date, Time or DateTime.
-# We can also use our own object.
-#
-# class MyDate
-# attr_reader :mon, :day, :year
-#
-# def initialize(mon, day, year)
-# @mon, @day, @year = mon, day, year
-# end
-# end
-#
-# d = Date.parse("2010-10-28")
-# t = Time.parse("2010-10-29")
-# dt = DateTime.parse("2010-10-30")
-# md = MyDate.new(10,31,2010)
-#
-# Time.parse("12:00", d) #=> 2010-10-28 12:00:00 -0500
-# Time.parse("12:00", t) #=> 2010-10-29 12:00:00 -0500
-# Time.parse("12:00", dt) #=> 2010-10-30 12:00:00 -0500
-# Time.parse("12:00", md) #=> 2010-10-31 12:00:00 -0500
-#
-# #parse also accepts an optional block. You can use this block to specify how
-# to handle the year component of the date. This is specifically designed for
-# handling two digit years. For example, if you wanted to treat all two digit
-# years prior to 70 as the year 2000+ you could write this:
-#
-# Time.parse("01-10-31") {|year| year + (year < 70 ? 2000 : 1900)}
-# #=> 2001-10-31 00:00:00 -0500
-# Time.parse("70-10-31") {|year| year + (year < 70 ? 2000 : 1900)}
-# #=> 1970-10-31 00:00:00 -0500
-#
-# === Time.strptime
-#
-# #strptime works similar to +parse+ except that instead of using a heuristic
-# to detect the format of the input string, you provide a second argument that
-# describes the format of the string. For example:
-#
-# Time.strptime("2000-10-31", "%Y-%m-%d") #=> 2000-10-31 00:00:00 -0500
-
-class Time
- class << Time
-
- #
- # A hash of timezones mapped to hour differences from UTC. The
- # set of time zones corresponds to the ones specified by RFC 2822
- # and ISO 8601.
- #
- ZoneOffset = { # :nodoc:
- 'UTC' => 0,
- # ISO 8601
- 'Z' => 0,
- # RFC 822
- 'UT' => 0, 'GMT' => 0,
- 'EST' => -5, 'EDT' => -4,
- 'CST' => -6, 'CDT' => -5,
- 'MST' => -7, 'MDT' => -6,
- 'PST' => -8, 'PDT' => -7,
- # Following definition of military zones is original one.
- # See RFC 1123 and RFC 2822 for the error in RFC 822.
- 'A' => +1, 'B' => +2, 'C' => +3, 'D' => +4, 'E' => +5, 'F' => +6,
- 'G' => +7, 'H' => +8, 'I' => +9, 'K' => +10, 'L' => +11, 'M' => +12,
- 'N' => -1, 'O' => -2, 'P' => -3, 'Q' => -4, 'R' => -5, 'S' => -6,
- 'T' => -7, 'U' => -8, 'V' => -9, 'W' => -10, 'X' => -11, 'Y' => -12,
- }
-
- #
- # Return the number of seconds the specified time zone differs
- # from UTC.
- #
- # Numeric time zones that include minutes, such as
- # <code>-10:00</code> or <code>+1330</code> will work, as will
- # simpler hour-only time zones like <code>-10</code> or
- # <code>+13</code>.
- #
- # Textual time zones listed in ZoneOffset are also supported.
- #
- # If the time zone does not match any of the above, +zone_offset+
- # will check if the local time zone (both with and without
- # potential Daylight Saving \Time changes being in effect) matches
- # +zone+. Specifying a value for +year+ will change the year used
- # to find the local time zone.
- #
- # If +zone_offset+ is unable to determine the offset, nil will be
- # returned.
- def zone_offset(zone, year=self.now.year)
- off = nil
- zone = zone.upcase
- if /\A([+-])(\d\d):?(\d\d)\z/ =~ zone
- off = ($1 == '-' ? -1 : 1) * ($2.to_i * 60 + $3.to_i) * 60
- elsif /\A[+-]\d\d\z/ =~ zone
- off = zone.to_i * 3600
- elsif ZoneOffset.include?(zone)
- off = ZoneOffset[zone] * 3600
- elsif ((t = self.local(year, 1, 1)).zone.upcase == zone rescue false)
- off = t.utc_offset
- elsif ((t = self.local(year, 7, 1)).zone.upcase == zone rescue false)
- off = t.utc_offset
- end
- off
- end
-
- def zone_utc?(zone)
- # * +0000
- # In RFC 2822, +0000 indicate a time zone at Universal Time.
- # Europe/Lisbon is "a time zone at Universal Time" in Winter.
- # Atlantic/Reykjavik is "a time zone at Universal Time".
- # Africa/Dakar is "a time zone at Universal Time".
- # So +0000 is a local time such as Europe/London, etc.
- # * GMT
- # GMT is used as a time zone abbreviation in Europe/London,
- # Africa/Dakar, etc.
- # So it is a local time.
- #
- # * -0000, -00:00
- # In RFC 2822, -0000 the date-time contains no information about the
- # local time zone.
- # In RFC 3339, -00:00 is used for the time in UTC is known,
- # but the offset to local time is unknown.
- # They are not appropriate for specific time zone such as
- # Europe/London because time zone neutral,
- # So -00:00 and -0000 are treated as UTC.
- if /\A(?:-00:00|-0000|-00|UTC|Z|UT)\z/i =~ zone
- true
- else
- false
- end
- end
- private :zone_utc?
-
- def force_zone!(t, zone, offset=nil)
- if zone_utc?(zone)
- t.utc
- elsif offset ||= zone_offset(zone)
- # Prefer the local timezone over the fixed offset timezone because
- # the former is a real timezone and latter is an artificial timezone.
- t.localtime
- if t.utc_offset != offset
- # Use the fixed offset timezone only if the local timezone cannot
- # represent the given offset.
- t.localtime(offset)
- end
- else
- t.localtime
- end
- end
- private :force_zone!
-
- LeapYearMonthDays = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] # :nodoc:
- CommonYearMonthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] # :nodoc:
- def month_days(y, m)
- if ((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)
- LeapYearMonthDays[m-1]
- else
- CommonYearMonthDays[m-1]
- end
- end
- private :month_days
-
- def apply_offset(year, mon, day, hour, min, sec, off)
- if off < 0
- off = -off
- off, o = off.divmod(60)
- if o != 0 then sec += o; o, sec = sec.divmod(60); off += o end
- off, o = off.divmod(60)
- if o != 0 then min += o; o, min = min.divmod(60); off += o end
- off, o = off.divmod(24)
- if o != 0 then hour += o; o, hour = hour.divmod(24); off += o end
- if off != 0
- day += off
- days = month_days(year, mon)
- if days and days < day
- mon += 1
- if 12 < mon
- mon = 1
- year += 1
- end
- day = 1
- end
- end
- elsif 0 < off
- off, o = off.divmod(60)
- if o != 0 then sec -= o; o, sec = sec.divmod(60); off -= o end
- off, o = off.divmod(60)
- if o != 0 then min -= o; o, min = min.divmod(60); off -= o end
- off, o = off.divmod(24)
- if o != 0 then hour -= o; o, hour = hour.divmod(24); off -= o end
- if off != 0 then
- day -= off
- if day < 1
- mon -= 1
- if mon < 1
- year -= 1
- mon = 12
- end
- day = month_days(year, mon)
- end
- end
- end
- return year, mon, day, hour, min, sec
- end
- private :apply_offset
-
- def make_time(date, year, mon, day, hour, min, sec, sec_fraction, zone, now)
- if !year && !mon && !day && !hour && !min && !sec && !sec_fraction
- raise ArgumentError, "no time information in #{date.inspect}"
- end
-
- off_year = year || now.year
- off = nil
- off = zone_offset(zone, off_year) if zone
-
- if off
- now = now.getlocal(off) if now.utc_offset != off
- else
- now = now.getlocal
- end
-
- usec = nil
- usec = sec_fraction * 1000000 if sec_fraction
-
- if now
- begin
- break if year; year = now.year
- break if mon; mon = now.mon
- break if day; day = now.day
- break if hour; hour = now.hour
- break if min; min = now.min
- break if sec; sec = now.sec
- break if sec_fraction; usec = now.tv_usec
- end until true
- end
-
- year ||= 1970
- mon ||= 1
- day ||= 1
- hour ||= 0
- min ||= 0
- sec ||= 0
- usec ||= 0
-
- if year != off_year
- off = nil
- off = zone_offset(zone, year) if zone
- end
-
- if off
- year, mon, day, hour, min, sec =
- apply_offset(year, mon, day, hour, min, sec, off)
- t = self.utc(year, mon, day, hour, min, sec, usec)
- force_zone!(t, zone, off)
- t
- else
- self.local(year, mon, day, hour, min, sec, usec)
- end
- end
- private :make_time
-
- #
- # Parses +date+ using Date._parse and converts it to a Time object.
- #
- # If a block is given, the year described in +date+ is converted by the
- # block. For example:
- #
- # Time.parse(...) {|y| 0 <= y && y < 100 ? (y >= 69 ? y + 1900 : y + 2000) : y}
- #
- # If the upper components of the given time are broken or missing, they are
- # supplied with those of +now+. For the lower components, the minimum
- # values (1 or 0) are assumed if broken or missing. For example:
- #
- # # Suppose it is "Thu Nov 29 14:33:20 2001" now and
- # # your time zone is EST which is GMT-5.
- # now = Time.parse("Thu Nov 29 14:33:20 2001")
- # Time.parse("16:30", now) #=> 2001-11-29 16:30:00 -0500
- # Time.parse("7/23", now) #=> 2001-07-23 00:00:00 -0500
- # Time.parse("Aug 31", now) #=> 2001-08-31 00:00:00 -0500
- # Time.parse("Aug 2000", now) #=> 2000-08-01 00:00:00 -0500
- #
- # Since there are numerous conflicts among locally defined time zone
- # abbreviations all over the world, this method is not intended to
- # understand all of them. For example, the abbreviation "CST" is
- # used variously as:
- #
- # -06:00 in America/Chicago,
- # -05:00 in America/Havana,
- # +08:00 in Asia/Harbin,
- # +09:30 in Australia/Darwin,
- # +10:30 in Australia/Adelaide,
- # etc.
- #
- # Based on this fact, this method only understands the time zone
- # abbreviations described in RFC 822 and the system time zone, in the
- # order named. (i.e. a definition in RFC 822 overrides the system
- # time zone definition.) The system time zone is taken from
- # <tt>Time.local(year, 1, 1).zone</tt> and
- # <tt>Time.local(year, 7, 1).zone</tt>.
- # If the extracted time zone abbreviation does not match any of them,
- # it is ignored and the given time is regarded as a local time.
- #
- # ArgumentError is raised if Date._parse cannot extract information from
- # +date+ or if the Time class cannot represent specified date.
- #
- # This method can be used as a fail-safe for other parsing methods as:
- #
- # Time.rfc2822(date) rescue Time.parse(date)
- # Time.httpdate(date) rescue Time.parse(date)
- # Time.xmlschema(date) rescue Time.parse(date)
- #
- # A failure of Time.parse should be checked, though.
- #
- # You must require 'time' to use this method.
- #
- def parse(date, now=self.now)
- comp = !block_given?
- d = Date._parse(date, comp)
- year = d[:year]
- year = yield(year) if year && !comp
- make_time(date, year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
- end
-
- #
- # Parses +date+ using Date._strptime and converts it to a Time object.
- #
- # If a block is given, the year described in +date+ is converted by the
- # block. For example:
- #
- # Time.strptime(...) {|y| y < 100 ? (y >= 69 ? y + 1900 : y + 2000) : y}
- #
- # Below is a list of the formatting options:
- #
- # %a :: The abbreviated weekday name ("Sun")
- # %A :: The full weekday name ("Sunday")
- # %b :: The abbreviated month name ("Jan")
- # %B :: The full month name ("January")
- # %c :: The preferred local date and time representation
- # %C :: Century (20 in 2009)
- # %d :: Day of the month (01..31)
- # %D :: Date (%m/%d/%y)
- # %e :: Day of the month, blank-padded ( 1..31)
- # %F :: Equivalent to %Y-%m-%d (the ISO 8601 date format)
- # %h :: Equivalent to %b
- # %H :: Hour of the day, 24-hour clock (00..23)
- # %I :: Hour of the day, 12-hour clock (01..12)
- # %j :: Day of the year (001..366)
- # %k :: hour, 24-hour clock, blank-padded ( 0..23)
- # %l :: hour, 12-hour clock, blank-padded ( 0..12)
- # %L :: Millisecond of the second (000..999)
- # %m :: Month of the year (01..12)
- # %M :: Minute of the hour (00..59)
- # %n :: Newline (\n)
- # %N :: Fractional seconds digits, default is 9 digits (nanosecond)
- # %3N :: millisecond (3 digits)
- # %6N :: microsecond (6 digits)
- # %9N :: nanosecond (9 digits)
- # %p :: Meridian indicator ("AM" or "PM")
- # %P :: Meridian indicator ("am" or "pm")
- # %r :: time, 12-hour (same as %I:%M:%S %p)
- # %R :: time, 24-hour (%H:%M)
- # %s :: Number of seconds since 1970-01-01 00:00:00 UTC.
- # %S :: Second of the minute (00..60)
- # %t :: Tab character (\t)
- # %T :: time, 24-hour (%H:%M:%S)
- # %u :: Day of the week as a decimal, Monday being 1. (1..7)
- # %U :: Week number of the current year, starting with the first Sunday as
- # the first day of the first week (00..53)
- # %v :: VMS date (%e-%b-%Y)
- # %V :: Week number of year according to ISO 8601 (01..53)
- # %W :: Week number of the current year, starting with the first Monday
- # as the first day of the first week (00..53)
- # %w :: Day of the week (Sunday is 0, 0..6)
- # %x :: Preferred representation for the date alone, no time
- # %X :: Preferred representation for the time alone, no date
- # %y :: Year without a century (00..99)
- # %Y :: Year which may include century, if provided
- # %z :: Time zone as hour offset from UTC (e.g. +0900)
- # %Z :: Time zone name
- # %% :: Literal "%" character
-
- def strptime(date, format, now=self.now)
- d = Date._strptime(date, format)
- raise ArgumentError, "invalid strptime format - `#{format}'" unless d
- if seconds = d[:seconds]
- if sec_fraction = d[:sec_fraction]
- usec = sec_fraction * 1000000
- usec *= -1 if seconds < 0
- else
- usec = 0
- end
- t = Time.at(seconds, usec)
- if zone = d[:zone]
- force_zone!(t, zone)
- end
- else
- year = d[:year]
- year = yield(year) if year && block_given?
- t = make_time(date, year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
- end
- t
- end
-
- MonthValue = { # :nodoc:
- 'JAN' => 1, 'FEB' => 2, 'MAR' => 3, 'APR' => 4, 'MAY' => 5, 'JUN' => 6,
- 'JUL' => 7, 'AUG' => 8, 'SEP' => 9, 'OCT' =>10, 'NOV' =>11, 'DEC' =>12
- }
-
- #
- # Parses +date+ as date-time defined by RFC 2822 and converts it to a Time
- # object. The format is identical to the date format defined by RFC 822 and
- # updated by RFC 1123.
- #
- # ArgumentError is raised if +date+ is not compliant with RFC 2822
- # or if the Time class cannot represent specified date.
- #
- # See #rfc2822 for more information on this format.
- #
- # You must require 'time' to use this method.
- #
- def rfc2822(date)
- if /\A\s*
- (?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s*,\s*)?
- (\d{1,2})\s+
- (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+
- (\d{2,})\s+
- (\d{2})\s*
- :\s*(\d{2})\s*
- (?::\s*(\d{2}))?\s+
- ([+-]\d{4}|
- UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|[A-IK-Z])/ix =~ date
- # Since RFC 2822 permit comments, the regexp has no right anchor.
- day = $1.to_i
- mon = MonthValue[$2.upcase]
- year = $3.to_i
- short_year_p = $3.length <= 3
- hour = $4.to_i
- min = $5.to_i
- sec = $6 ? $6.to_i : 0
- zone = $7
-
- if short_year_p
- # following year completion is compliant with RFC 2822.
- year = if year < 50
- 2000 + year
- else
- 1900 + year
- end
- end
-
- off = zone_offset(zone)
- year, mon, day, hour, min, sec =
- apply_offset(year, mon, day, hour, min, sec, off)
- t = self.utc(year, mon, day, hour, min, sec)
- force_zone!(t, zone, off)
- t
- else
- raise ArgumentError.new("not RFC 2822 compliant date: #{date.inspect}")
- end
- end
- alias rfc822 rfc2822
-
- #
- # Parses +date+ as an HTTP-date defined by RFC 2616 and converts it to a
- # Time object.
- #
- # ArgumentError is raised if +date+ is not compliant with RFC 2616 or if
- # the Time class cannot represent specified date.
- #
- # See #httpdate for more information on this format.
- #
- # You must require 'time' to use this method.
- #
- def httpdate(date)
- if /\A\s*
- (?:Mon|Tue|Wed|Thu|Fri|Sat|Sun),\x20
- (\d{2})\x20
- (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\x20
- (\d{4})\x20
- (\d{2}):(\d{2}):(\d{2})\x20
- GMT
- \s*\z/ix =~ date
- self.rfc2822(date).utc
- elsif /\A\s*
- (?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday),\x20
- (\d\d)-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d\d)\x20
- (\d\d):(\d\d):(\d\d)\x20
- GMT
- \s*\z/ix =~ date
- year = $3.to_i
- if year < 50
- year += 2000
- else
- year += 1900
- end
- self.utc(year, $2, $1.to_i, $4.to_i, $5.to_i, $6.to_i)
- elsif /\A\s*
- (?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\x20
- (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\x20
- (\d\d|\x20\d)\x20
- (\d\d):(\d\d):(\d\d)\x20
- (\d{4})
- \s*\z/ix =~ date
- self.utc($6.to_i, MonthValue[$1.upcase], $2.to_i,
- $3.to_i, $4.to_i, $5.to_i)
- else
- raise ArgumentError.new("not RFC 2616 compliant date: #{date.inspect}")
- end
- end
-
- #
- # Parses +date+ as a dateTime defined by the XML Schema and converts it to
- # a Time object. The format is a restricted version of the format defined
- # by ISO 8601.
- #
- # ArgumentError is raised if +date+ is not compliant with the format or if
- # the Time class cannot represent specified date.
- #
- # See #xmlschema for more information on this format.
- #
- # You must require 'time' to use this method.
- #
- def xmlschema(date)
- if /\A\s*
- (-?\d+)-(\d\d)-(\d\d)
- T
- (\d\d):(\d\d):(\d\d)
- (\.\d+)?
- (Z|[+-]\d\d:\d\d)?
- \s*\z/ix =~ date
- year = $1.to_i
- mon = $2.to_i
- day = $3.to_i
- hour = $4.to_i
- min = $5.to_i
- sec = $6.to_i
- usec = 0
- if $7
- usec = Rational($7) * 1000000
- end
- if $8
- zone = $8
- off = zone_offset(zone)
- year, mon, day, hour, min, sec =
- apply_offset(year, mon, day, hour, min, sec, off)
- t = self.utc(year, mon, day, hour, min, sec, usec)
- force_zone!(t, zone, off)
- t
- else
- self.local(year, mon, day, hour, min, sec, usec)
- end
- else
- raise ArgumentError.new("invalid date: #{date.inspect}")
- end
- end
- alias iso8601 xmlschema
- end # class << self
-
- #
- # Returns a string which represents the time as date-time defined by RFC 2822:
- #
- # day-of-week, DD month-name CCYY hh:mm:ss zone
- #
- # where zone is [+-]hhmm.
- #
- # If +self+ is a UTC time, -0000 is used as zone.
- #
- # You must require 'time' to use this method.
- #
- def rfc2822
- sprintf('%s, %02d %s %0*d %02d:%02d:%02d ',
- RFC2822_DAY_NAME[wday],
- day, RFC2822_MONTH_NAME[mon-1], year < 0 ? 5 : 4, year,
- hour, min, sec) +
- if utc?
- '-0000'
- else
- off = utc_offset
- sign = off < 0 ? '-' : '+'
- sprintf('%s%02d%02d', sign, *(off.abs / 60).divmod(60))
- end
- end
- alias rfc822 rfc2822
-
-
- RFC2822_DAY_NAME = [ # :nodoc:
- 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'
- ]
-
- RFC2822_MONTH_NAME = [ # :nodoc:
- 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
- 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
- ]
-
- #
- # Returns a string which represents the time as RFC 1123 date of HTTP-date
- # defined by RFC 2616:
- #
- # day-of-week, DD month-name CCYY hh:mm:ss GMT
- #
- # Note that the result is always UTC (GMT).
- #
- # You must require 'time' to use this method.
- #
- def httpdate
- t = dup.utc
- sprintf('%s, %02d %s %0*d %02d:%02d:%02d GMT',
- RFC2822_DAY_NAME[t.wday],
- t.day, RFC2822_MONTH_NAME[t.mon-1], t.year < 0 ? 5 : 4, t.year,
- t.hour, t.min, t.sec)
- end
-
- #
- # Returns a string which represents the time as a dateTime defined by XML
- # Schema:
- #
- # CCYY-MM-DDThh:mm:ssTZD
- # CCYY-MM-DDThh:mm:ss.sssTZD
- #
- # where TZD is Z or [+-]hh:mm.
- #
- # If self is a UTC time, Z is used as TZD. [+-]hh:mm is used otherwise.
- #
- # +fractional_digits+ specifies a number of digits to use for fractional
- # seconds. Its default value is 0.
- #
- # You must require 'time' to use this method.
- #
- def xmlschema(fraction_digits=0)
- fraction_digits = fraction_digits.to_i
- s = strftime("%FT%T")
- if fraction_digits > 0
- s << strftime(".%#{fraction_digits}N")
- end
- s << (utc? ? 'Z' : strftime("%:z"))
- end
- alias iso8601 xmlschema
-end
-
diff --git a/ruby_2_2/lib/timeout.rb b/ruby_2_2/lib/timeout.rb
deleted file mode 100644
index 123f600ccb..0000000000
--- a/ruby_2_2/lib/timeout.rb
+++ /dev/null
@@ -1,129 +0,0 @@
-# Timeout long-running blocks
-#
-# == Synopsis
-#
-# require 'timeout'
-# status = Timeout::timeout(5) {
-# # Something that should be interrupted if it takes more than 5 seconds...
-# }
-#
-# == Description
-#
-# Timeout provides a way to auto-terminate a potentially long-running
-# operation if it hasn't finished in a fixed amount of time.
-#
-# Previous versions didn't use a module for namespacing, however
-# #timeout is provided for backwards compatibility. You
-# should prefer Timeout#timeout instead.
-#
-# == Copyright
-#
-# Copyright:: (C) 2000 Network Applied Communication Laboratory, Inc.
-# Copyright:: (C) 2000 Information-technology Promotion Agency, Japan
-
-module Timeout
- # Raised by Timeout#timeout when the block times out.
- class Error < RuntimeError
- attr_reader :thread
-
- def self.catch(*args)
- exc = new(*args)
- exc.instance_variable_set(:@thread, Thread.current)
- ::Kernel.catch(exc) {yield exc}
- end
-
- def exception(*)
- # TODO: use Fiber.current to see if self can be thrown
- if self.thread == Thread.current
- bt = caller
- begin
- throw(self, bt)
- rescue UncaughtThrowError
- end
- end
- self
- end
- end
- ExitException = Error
-
- # :stopdoc:
- THIS_FILE = /\A#{Regexp.quote(__FILE__)}:/o
- CALLER_OFFSET = ((c = caller[0]) && THIS_FILE =~ c) ? 1 : 0
- # :startdoc:
-
- # Perform an operation in a block, raising an error if it takes longer than
- # +sec+ seconds to complete.
- #
- # +sec+:: Number of seconds to wait for the block to terminate. Any number
- # may be used, including Floats to specify fractional seconds. A
- # value of 0 or +nil+ will execute the block without any timeout.
- # +klass+:: Exception Class to raise if the block fails to terminate
- # in +sec+ seconds. Omitting will use the default, Timeout::Error
- #
- # Returns the result of the block *if* the block completed before
- # +sec+ seconds, otherwise throws an exception, based on the value of +klass+.
- #
- # The exception thrown to terminate the given block cannot be rescued inside
- # the block unless +klass+ is given explicitly.
- #
- # Note that this is both a method of module Timeout, so you can <tt>include
- # Timeout</tt> into your classes so they have a #timeout method, as well as
- # a module method, so you can call it directly as Timeout.timeout().
- def timeout(sec, klass = nil) #:yield: +sec+
- return yield(sec) if sec == nil or sec.zero?
- message = "execution expired"
- e = Error
- bl = proc do |exception|
- begin
- x = Thread.current
- y = Thread.start {
- begin
- sleep sec
- rescue => e
- x.raise e
- else
- x.raise exception, message
- end
- }
- return yield(sec)
- ensure
- if y
- y.kill
- y.join # make sure y is dead.
- end
- end
- end
- if klass
- begin
- bl.call(klass)
- rescue klass => e
- bt = e.backtrace
- end
- else
- bt = Error.catch(message, &bl)
- end
- rej = /\A#{Regexp.quote(__FILE__)}:#{__LINE__-4}\z/o
- bt.reject! {|m| rej =~ m}
- level = -caller(CALLER_OFFSET).size
- while THIS_FILE =~ bt[level]
- bt.delete_at(level)
- end
- raise(e, message, bt)
- end
-
- module_function :timeout
-end
-
-# Identical to:
-#
-# Timeout::timeout(n, e, &block).
-#
-# This method is deprecated and provided only for backwards compatibility.
-# You should use Timeout#timeout instead.
-def timeout(n, e = nil, &block)
- Timeout::timeout(n, e, &block)
-end
-
-# Another name for Timeout::Error, defined for backwards compatibility with
-# earlier versions of timeout.rb.
-TimeoutError = Timeout::Error
diff --git a/ruby_2_2/lib/tmpdir.rb b/ruby_2_2/lib/tmpdir.rb
deleted file mode 100644
index 494725cb33..0000000000
--- a/ruby_2_2/lib/tmpdir.rb
+++ /dev/null
@@ -1,139 +0,0 @@
-#
-# tmpdir - retrieve temporary directory path
-#
-# $Id$
-#
-
-require 'fileutils'
-begin
- require 'etc.so'
-rescue LoadError # rescue LoadError for miniruby
-end
-
-class Dir
-
- @@systmpdir ||= defined?(Etc.systmpdir) ? Etc.systmpdir : '/tmp'
-
- ##
- # Returns the operating system's temporary file path.
-
- def self.tmpdir
- if $SAFE > 0
- @@systmpdir
- else
- tmp = nil
- [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp', '.'].each do |dir|
- next if !dir
- dir = File.expand_path(dir)
- if stat = File.stat(dir) and stat.directory? and stat.writable? and
- (!stat.world_writable? or stat.sticky?)
- tmp = dir
- break
- end rescue nil
- end
- raise ArgumentError, "could not find a temporary directory" unless tmp
- tmp
- end
- end
-
- # Dir.mktmpdir creates a temporary directory.
- #
- # The directory is created with 0700 permission.
- # Application should not change the permission to make the temporary directory accessible from other users.
- #
- # The prefix and suffix of the name of the directory is specified by
- # the optional first argument, <i>prefix_suffix</i>.
- # - If it is not specified or nil, "d" is used as the prefix and no suffix is used.
- # - If it is a string, it is used as the prefix and no suffix is used.
- # - If it is an array, first element is used as the prefix and second element is used as a suffix.
- #
- # Dir.mktmpdir {|dir| dir is ".../d..." }
- # Dir.mktmpdir("foo") {|dir| dir is ".../foo..." }
- # Dir.mktmpdir(["foo", "bar"]) {|dir| dir is ".../foo...bar" }
- #
- # The directory is created under Dir.tmpdir or
- # the optional second argument <i>tmpdir</i> if non-nil value is given.
- #
- # Dir.mktmpdir {|dir| dir is "#{Dir.tmpdir}/d..." }
- # Dir.mktmpdir(nil, "/var/tmp") {|dir| dir is "/var/tmp/d..." }
- #
- # If a block is given,
- # it is yielded with the path of the directory.
- # The directory and its contents are removed
- # using FileUtils.remove_entry before Dir.mktmpdir returns.
- # The value of the block is returned.
- #
- # Dir.mktmpdir {|dir|
- # # use the directory...
- # open("#{dir}/foo", "w") { ... }
- # }
- #
- # If a block is not given,
- # The path of the directory is returned.
- # In this case, Dir.mktmpdir doesn't remove the directory.
- #
- # dir = Dir.mktmpdir
- # begin
- # # use the directory...
- # open("#{dir}/foo", "w") { ... }
- # ensure
- # # remove the directory.
- # FileUtils.remove_entry dir
- # end
- #
- def Dir.mktmpdir(prefix_suffix=nil, *rest)
- path = Tmpname.create(prefix_suffix || "d", *rest) {|n| mkdir(n, 0700)}
- if block_given?
- begin
- yield path
- ensure
- stat = File.stat(File.dirname(path))
- if stat.world_writable? and !stat.sticky?
- raise ArgumentError, "parent directory is world writable but not sticky"
- end
- FileUtils.remove_entry path
- end
- else
- path
- end
- end
-
- module Tmpname # :nodoc:
- module_function
-
- def tmpdir
- Dir.tmpdir
- end
-
- def make_tmpname((prefix, suffix), n)
- prefix = (String.try_convert(prefix) or
- raise ArgumentError, "unexpected prefix: #{prefix.inspect}")
- suffix &&= (String.try_convert(suffix) or
- raise ArgumentError, "unexpected suffix: #{suffix.inspect}")
- t = Time.now.strftime("%Y%m%d")
- path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
- path << "-#{n}" if n
- path << suffix if suffix
- path
- end
-
- def create(basename, tmpdir=nil, max_try: nil, **opts)
- if $SAFE > 0 and tmpdir.tainted?
- tmpdir = '/tmp'
- else
- tmpdir ||= tmpdir()
- end
- n = nil
- begin
- path = File.join(tmpdir, make_tmpname(basename, n))
- yield(path, n, opts)
- rescue Errno::EEXIST
- n ||= 0
- n += 1
- retry if !max_try or n < max_try
- raise "cannot generate temporary name using `#{basename}' under `#{tmpdir}'"
- end
- path
- end
- end
-end
diff --git a/ruby_2_2/lib/tracer.rb b/ruby_2_2/lib/tracer.rb
deleted file mode 100644
index 1d6b019bcf..0000000000
--- a/ruby_2_2/lib/tracer.rb
+++ /dev/null
@@ -1,286 +0,0 @@
-#--
-# $Release Version: 0.3$
-# $Revision: 1.12 $
-require "thread"
-
-##
-# Outputs a source level execution trace of a Ruby program.
-#
-# It does this by registering an event handler with Kernel#set_trace_func for
-# processing incoming events. It also provides methods for filtering unwanted
-# trace output (see Tracer.add_filter, Tracer.on, and Tracer.off).
-#
-# == Example
-#
-# Consider the following Ruby script
-#
-# class A
-# def square(a)
-# return a*a
-# end
-# end
-#
-# a = A.new
-# a.square(5)
-#
-# Running the above script using <code>ruby -r tracer example.rb</code> will
-# output the following trace to STDOUT (Note you can also explicitly
-# <code>require 'tracer'</code>)
-#
-# #0:<internal:lib/rubygems/custom_require>:38:Kernel:<: -
-# #0:example.rb:3::-: class A
-# #0:example.rb:3::C: class A
-# #0:example.rb:4::-: def square(a)
-# #0:example.rb:7::E: end
-# #0:example.rb:9::-: a = A.new
-# #0:example.rb:10::-: a.square(5)
-# #0:example.rb:4:A:>: def square(a)
-# #0:example.rb:5:A:-: return a*a
-# #0:example.rb:6:A:<: end
-# | | | | |
-# | | | | ---------------------+ event
-# | | | ------------------------+ class
-# | | --------------------------+ line
-# | ------------------------------------+ filename
-# ---------------------------------------+ thread
-#
-# Symbol table used for displaying incoming events:
-#
-# +}+:: call a C-language routine
-# +{+:: return from a C-language routine
-# +>+:: call a Ruby method
-# +C+:: start a class or module definition
-# +E+:: finish a class or module definition
-# +-+:: execute code on a new line
-# +^+:: raise an exception
-# +<+:: return from a Ruby method
-#
-# == Copyright
-#
-# by Keiju ISHITSUKA(keiju@ishitsuka.com)
-#
-class Tracer
- class << self
- # display additional debug information (defaults to false)
- attr_accessor :verbose
- alias verbose? verbose
-
- # output stream used to output trace (defaults to STDOUT)
- attr_accessor :stdout
-
- # mutex lock used by tracer for displaying trace output
- attr_reader :stdout_mutex
-
- # display process id in trace output (defaults to false)
- attr_accessor :display_process_id
- alias display_process_id? display_process_id
-
- # display thread id in trace output (defaults to true)
- attr_accessor :display_thread_id
- alias display_thread_id? display_thread_id
-
- # display C-routine calls in trace output (defaults to false)
- attr_accessor :display_c_call
- alias display_c_call? display_c_call
- end
-
- Tracer::stdout = STDOUT
- Tracer::verbose = false
- Tracer::display_process_id = false
- Tracer::display_thread_id = true
- Tracer::display_c_call = false
-
- @stdout_mutex = Mutex.new
-
- # Symbol table used for displaying trace information
- EVENT_SYMBOL = {
- "line" => "-",
- "call" => ">",
- "return" => "<",
- "class" => "C",
- "end" => "E",
- "raise" => "^",
- "c-call" => "}",
- "c-return" => "{",
- "unknown" => "?"
- }
-
- def initialize # :nodoc:
- @threads = Hash.new
- if defined? Thread.main
- @threads[Thread.main.object_id] = 0
- else
- @threads[Thread.current.object_id] = 0
- end
-
- @get_line_procs = {}
-
- @filters = []
- end
-
- def stdout # :nodoc:
- Tracer.stdout
- end
-
- def on # :nodoc:
- if block_given?
- on
- begin
- yield
- ensure
- off
- end
- else
- set_trace_func method(:trace_func).to_proc
- stdout.print "Trace on\n" if Tracer.verbose?
- end
- end
-
- def off # :nodoc:
- set_trace_func nil
- stdout.print "Trace off\n" if Tracer.verbose?
- end
-
- def add_filter(p = proc) # :nodoc:
- @filters.push p
- end
-
- def set_get_line_procs(file, p = proc) # :nodoc:
- @get_line_procs[file] = p
- end
-
- def get_line(file, line) # :nodoc:
- if p = @get_line_procs[file]
- return p.call(line)
- end
-
- unless list = SCRIPT_LINES__[file]
- list = File.readlines(file) rescue []
- SCRIPT_LINES__[file] = list
- end
-
- if l = list[line - 1]
- l
- else
- "-\n"
- end
- end
-
- def get_thread_no # :nodoc:
- if no = @threads[Thread.current.object_id]
- no
- else
- @threads[Thread.current.object_id] = @threads.size
- end
- end
-
- def trace_func(event, file, line, id, binding, klass, *) # :nodoc:
- return if file == __FILE__
-
- for p in @filters
- return unless p.call event, file, line, id, binding, klass
- end
-
- return unless Tracer::display_c_call? or
- event != "c-call" && event != "c-return"
-
- Tracer::stdout_mutex.synchronize do
- if EVENT_SYMBOL[event]
- stdout.printf("<%d>", $$) if Tracer::display_process_id?
- stdout.printf("#%d:", get_thread_no) if Tracer::display_thread_id?
- if line == 0
- source = "?\n"
- else
- source = get_line(file, line)
- end
- stdout.printf("%s:%d:%s:%s: %s",
- file,
- line,
- klass || '',
- EVENT_SYMBOL[event],
- source)
- end
- end
-
- end
-
- # Reference to singleton instance of Tracer
- Single = new
-
- ##
- # Start tracing
- #
- # === Example
- #
- # Tracer.on
- # # code to trace here
- # Tracer.off
- #
- # You can also pass a block:
- #
- # Tracer.on {
- # # trace everything in this block
- # }
-
- def Tracer.on
- if block_given?
- Single.on{yield}
- else
- Single.on
- end
- end
-
- ##
- # Disable tracing
-
- def Tracer.off
- Single.off
- end
-
- ##
- # Register an event handler <code>p</code> which is called everytime a line
- # in +file_name+ is executed.
- #
- # Example:
- #
- # Tracer.set_get_line_procs("example.rb", lambda { |line|
- # puts "line number executed is #{line}"
- # })
-
- def Tracer.set_get_line_procs(file_name, p = proc)
- Single.set_get_line_procs(file_name, p)
- end
-
- ##
- # Used to filter unwanted trace output
- #
- # Example which only outputs lines of code executed within the Kernel class:
- #
- # Tracer.add_filter do |event, file, line, id, binding, klass, *rest|
- # "Kernel" == klass.to_s
- # end
-
- def Tracer.add_filter(p = proc)
- Single.add_filter(p)
- end
-end
-
-# :stopdoc:
-SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
-
-if $0 == __FILE__
- # direct call
-
- $0 = ARGV[0]
- ARGV.shift
- Tracer.on
- require $0
-else
- # call Tracer.on only if required by -r command-line option
- count = caller.count {|bt| %r%/rubygems/core_ext/kernel_require\.rb:% !~ bt}
- if (defined?(Gem) and count == 0) or
- (!defined?(Gem) and count <= 1)
- Tracer.on
- end
-end
-# :startdoc:
diff --git a/ruby_2_2/lib/tsort.rb b/ruby_2_2/lib/tsort.rb
deleted file mode 100644
index c40f9c41b2..0000000000
--- a/ruby_2_2/lib/tsort.rb
+++ /dev/null
@@ -1,450 +0,0 @@
-#--
-# tsort.rb - provides a module for topological sorting and strongly connected components.
-#++
-#
-
-#
-# TSort implements topological sorting using Tarjan's algorithm for
-# strongly connected components.
-#
-# TSort is designed to be able to be used with any object which can be
-# interpreted as a directed graph.
-#
-# TSort requires two methods to interpret an object as a graph,
-# tsort_each_node and tsort_each_child.
-#
-# * tsort_each_node is used to iterate for all nodes over a graph.
-# * tsort_each_child is used to iterate for child nodes of a given node.
-#
-# The equality of nodes are defined by eql? and hash since
-# TSort uses Hash internally.
-#
-# == A Simple Example
-#
-# The following example demonstrates how to mix the TSort module into an
-# existing class (in this case, Hash). Here, we're treating each key in
-# the hash as a node in the graph, and so we simply alias the required
-# #tsort_each_node method to Hash's #each_key method. For each key in the
-# hash, the associated value is an array of the node's child nodes. This
-# choice in turn leads to our implementation of the required #tsort_each_child
-# method, which fetches the array of child nodes and then iterates over that
-# array using the user-supplied block.
-#
-# require 'tsort'
-#
-# class Hash
-# include TSort
-# alias tsort_each_node each_key
-# def tsort_each_child(node, &block)
-# fetch(node).each(&block)
-# end
-# end
-#
-# {1=>[2, 3], 2=>[3], 3=>[], 4=>[]}.tsort
-# #=> [3, 2, 1, 4]
-#
-# {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}.strongly_connected_components
-# #=> [[4], [2, 3], [1]]
-#
-# == A More Realistic Example
-#
-# A very simple `make' like tool can be implemented as follows:
-#
-# require 'tsort'
-#
-# class Make
-# def initialize
-# @dep = {}
-# @dep.default = []
-# end
-#
-# def rule(outputs, inputs=[], &block)
-# triple = [outputs, inputs, block]
-# outputs.each {|f| @dep[f] = [triple]}
-# @dep[triple] = inputs
-# end
-#
-# def build(target)
-# each_strongly_connected_component_from(target) {|ns|
-# if ns.length != 1
-# fs = ns.delete_if {|n| Array === n}
-# raise TSort::Cyclic.new("cyclic dependencies: #{fs.join ', '}")
-# end
-# n = ns.first
-# if Array === n
-# outputs, inputs, block = n
-# inputs_time = inputs.map {|f| File.mtime f}.max
-# begin
-# outputs_time = outputs.map {|f| File.mtime f}.min
-# rescue Errno::ENOENT
-# outputs_time = nil
-# end
-# if outputs_time == nil ||
-# inputs_time != nil && outputs_time <= inputs_time
-# sleep 1 if inputs_time != nil && inputs_time.to_i == Time.now.to_i
-# block.call
-# end
-# end
-# }
-# end
-#
-# def tsort_each_child(node, &block)
-# @dep[node].each(&block)
-# end
-# include TSort
-# end
-#
-# def command(arg)
-# print arg, "\n"
-# system arg
-# end
-#
-# m = Make.new
-# m.rule(%w[t1]) { command 'date > t1' }
-# m.rule(%w[t2]) { command 'date > t2' }
-# m.rule(%w[t3]) { command 'date > t3' }
-# m.rule(%w[t4], %w[t1 t3]) { command 'cat t1 t3 > t4' }
-# m.rule(%w[t5], %w[t4 t2]) { command 'cat t4 t2 > t5' }
-# m.build('t5')
-#
-# == Bugs
-#
-# * 'tsort.rb' is wrong name because this library uses
-# Tarjan's algorithm for strongly connected components.
-# Although 'strongly_connected_components.rb' is correct but too long.
-#
-# == References
-#
-# R. E. Tarjan, "Depth First Search and Linear Graph Algorithms",
-# <em>SIAM Journal on Computing</em>, Vol. 1, No. 2, pp. 146-160, June 1972.
-#
-
-module TSort
- class Cyclic < StandardError
- end
-
- # Returns a topologically sorted array of nodes.
- # The array is sorted from children to parents, i.e.
- # the first element has no child and the last node has no parent.
- #
- # If there is a cycle, TSort::Cyclic is raised.
- #
- # class G
- # include TSort
- # def initialize(g)
- # @g = g
- # end
- # def tsort_each_child(n, &b) @g[n].each(&b) end
- # def tsort_each_node(&b) @g.each_key(&b) end
- # end
- #
- # graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
- # p graph.tsort #=> [4, 2, 3, 1]
- #
- # graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
- # p graph.tsort # raises TSort::Cyclic
- #
- def tsort
- each_node = method(:tsort_each_node)
- each_child = method(:tsort_each_child)
- TSort.tsort(each_node, each_child)
- end
-
- # Returns a topologically sorted array of nodes.
- # The array is sorted from children to parents, i.e.
- # the first element has no child and the last node has no parent.
- #
- # The graph is represented by _each_node_ and _each_child_.
- # _each_node_ should have +call+ method which yields for each node in the graph.
- # _each_child_ should have +call+ method which takes a node argument and yields for each child node.
- #
- # If there is a cycle, TSort::Cyclic is raised.
- #
- # g = {1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]}
- # each_node = lambda {|&b| g.each_key(&b) }
- # each_child = lambda {|n, &b| g[n].each(&b) }
- # p TSort.tsort(each_node, each_child) #=> [4, 2, 3, 1]
- #
- # g = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}
- # each_node = lambda {|&b| g.each_key(&b) }
- # each_child = lambda {|n, &b| g[n].each(&b) }
- # p TSort.tsort(each_node, each_child) # raises TSort::Cyclic
- #
- def TSort.tsort(each_node, each_child)
- TSort.tsort_each(each_node, each_child).to_a
- end
-
- # The iterator version of the #tsort method.
- # <tt><em>obj</em>.tsort_each</tt> is similar to <tt><em>obj</em>.tsort.each</tt>, but
- # modification of _obj_ during the iteration may lead to unexpected results.
- #
- # #tsort_each returns +nil+.
- # If there is a cycle, TSort::Cyclic is raised.
- #
- # class G
- # include TSort
- # def initialize(g)
- # @g = g
- # end
- # def tsort_each_child(n, &b) @g[n].each(&b) end
- # def tsort_each_node(&b) @g.each_key(&b) end
- # end
- #
- # graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
- # graph.tsort_each {|n| p n }
- # #=> 4
- # # 2
- # # 3
- # # 1
- #
- def tsort_each(&block) # :yields: node
- each_node = method(:tsort_each_node)
- each_child = method(:tsort_each_child)
- TSort.tsort_each(each_node, each_child, &block)
- end
-
- # The iterator version of the TSort.tsort method.
- #
- # The graph is represented by _each_node_ and _each_child_.
- # _each_node_ should have +call+ method which yields for each node in the graph.
- # _each_child_ should have +call+ method which takes a node argument and yields for each child node.
- #
- # g = {1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]}
- # each_node = lambda {|&b| g.each_key(&b) }
- # each_child = lambda {|n, &b| g[n].each(&b) }
- # TSort.tsort_each(each_node, each_child) {|n| p n }
- # #=> 4
- # # 2
- # # 3
- # # 1
- #
- def TSort.tsort_each(each_node, each_child) # :yields: node
- return to_enum(__method__, each_node, each_child) unless block_given?
-
- TSort.each_strongly_connected_component(each_node, each_child) {|component|
- if component.size == 1
- yield component.first
- else
- raise Cyclic.new("topological sort failed: #{component.inspect}")
- end
- }
- end
-
- # Returns strongly connected components as an array of arrays of nodes.
- # The array is sorted from children to parents.
- # Each elements of the array represents a strongly connected component.
- #
- # class G
- # include TSort
- # def initialize(g)
- # @g = g
- # end
- # def tsort_each_child(n, &b) @g[n].each(&b) end
- # def tsort_each_node(&b) @g.each_key(&b) end
- # end
- #
- # graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
- # p graph.strongly_connected_components #=> [[4], [2], [3], [1]]
- #
- # graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
- # p graph.strongly_connected_components #=> [[4], [2, 3], [1]]
- #
- def strongly_connected_components
- each_node = method(:tsort_each_node)
- each_child = method(:tsort_each_child)
- TSort.strongly_connected_components(each_node, each_child)
- end
-
- # Returns strongly connected components as an array of arrays of nodes.
- # The array is sorted from children to parents.
- # Each elements of the array represents a strongly connected component.
- #
- # The graph is represented by _each_node_ and _each_child_.
- # _each_node_ should have +call+ method which yields for each node in the graph.
- # _each_child_ should have +call+ method which takes a node argument and yields for each child node.
- #
- # g = {1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]}
- # each_node = lambda {|&b| g.each_key(&b) }
- # each_child = lambda {|n, &b| g[n].each(&b) }
- # p TSort.strongly_connected_components(each_node, each_child)
- # #=> [[4], [2], [3], [1]]
- #
- # g = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}
- # each_node = lambda {|&b| g.each_key(&b) }
- # each_child = lambda {|n, &b| g[n].each(&b) }
- # p TSort.strongly_connected_components(each_node, each_child)
- # #=> [[4], [2, 3], [1]]
- #
- def TSort.strongly_connected_components(each_node, each_child)
- TSort.each_strongly_connected_component(each_node, each_child).to_a
- end
-
- # The iterator version of the #strongly_connected_components method.
- # <tt><em>obj</em>.each_strongly_connected_component</tt> is similar to
- # <tt><em>obj</em>.strongly_connected_components.each</tt>, but
- # modification of _obj_ during the iteration may lead to unexpected results.
- #
- # #each_strongly_connected_component returns +nil+.
- #
- # class G
- # include TSort
- # def initialize(g)
- # @g = g
- # end
- # def tsort_each_child(n, &b) @g[n].each(&b) end
- # def tsort_each_node(&b) @g.each_key(&b) end
- # end
- #
- # graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
- # graph.each_strongly_connected_component {|scc| p scc }
- # #=> [4]
- # # [2]
- # # [3]
- # # [1]
- #
- # graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
- # graph.each_strongly_connected_component {|scc| p scc }
- # #=> [4]
- # # [2, 3]
- # # [1]
- #
- def each_strongly_connected_component(&block) # :yields: nodes
- each_node = method(:tsort_each_node)
- each_child = method(:tsort_each_child)
- TSort.each_strongly_connected_component(each_node, each_child, &block)
- end
-
- # The iterator version of the TSort.strongly_connected_components method.
- #
- # The graph is represented by _each_node_ and _each_child_.
- # _each_node_ should have +call+ method which yields for each node in the graph.
- # _each_child_ should have +call+ method which takes a node argument and yields for each child node.
- #
- # g = {1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]}
- # each_node = lambda {|&b| g.each_key(&b) }
- # each_child = lambda {|n, &b| g[n].each(&b) }
- # TSort.each_strongly_connected_component(each_node, each_child) {|scc| p scc }
- # #=> [4]
- # # [2]
- # # [3]
- # # [1]
- #
- # g = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}
- # each_node = lambda {|&b| g.each_key(&b) }
- # each_child = lambda {|n, &b| g[n].each(&b) }
- # TSort.each_strongly_connected_component(each_node, each_child) {|scc| p scc }
- # #=> [4]
- # # [2, 3]
- # # [1]
- #
- def TSort.each_strongly_connected_component(each_node, each_child) # :yields: nodes
- return to_enum(__method__, each_node, each_child) unless block_given?
-
- id_map = {}
- stack = []
- each_node.call {|node|
- unless id_map.include? node
- TSort.each_strongly_connected_component_from(node, each_child, id_map, stack) {|c|
- yield c
- }
- end
- }
- nil
- end
-
- # Iterates over strongly connected component in the subgraph reachable from
- # _node_.
- #
- # Return value is unspecified.
- #
- # #each_strongly_connected_component_from doesn't call #tsort_each_node.
- #
- # class G
- # include TSort
- # def initialize(g)
- # @g = g
- # end
- # def tsort_each_child(n, &b) @g[n].each(&b) end
- # def tsort_each_node(&b) @g.each_key(&b) end
- # end
- #
- # graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
- # graph.each_strongly_connected_component_from(2) {|scc| p scc }
- # #=> [4]
- # # [2]
- #
- # graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
- # graph.each_strongly_connected_component_from(2) {|scc| p scc }
- # #=> [4]
- # # [2, 3]
- #
- def each_strongly_connected_component_from(node, id_map={}, stack=[], &block) # :yields: nodes
- TSort.each_strongly_connected_component_from(node, method(:tsort_each_child), id_map, stack, &block)
- end
-
- # Iterates over strongly connected components in a graph.
- # The graph is represented by _node_ and _each_child_.
- #
- # _node_ is the first node.
- # _each_child_ should have +call+ method which takes a node argument
- # and yields for each child node.
- #
- # Return value is unspecified.
- #
- # #TSort.each_strongly_connected_component_from is a class method and
- # it doesn't need a class to represent a graph which includes TSort.
- #
- # graph = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}
- # each_child = lambda {|n, &b| graph[n].each(&b) }
- # TSort.each_strongly_connected_component_from(1, each_child) {|scc|
- # p scc
- # }
- # #=> [4]
- # # [2, 3]
- # # [1]
- #
- def TSort.each_strongly_connected_component_from(node, each_child, id_map={}, stack=[]) # :yields: nodes
- return to_enum(__method__, node, each_child, id_map, stack) unless block_given?
-
- minimum_id = node_id = id_map[node] = id_map.size
- stack_length = stack.length
- stack << node
-
- each_child.call(node) {|child|
- if id_map.include? child
- child_id = id_map[child]
- minimum_id = child_id if child_id && child_id < minimum_id
- else
- sub_minimum_id =
- TSort.each_strongly_connected_component_from(child, each_child, id_map, stack) {|c|
- yield c
- }
- minimum_id = sub_minimum_id if sub_minimum_id < minimum_id
- end
- }
-
- if node_id == minimum_id
- component = stack.slice!(stack_length .. -1)
- component.each {|n| id_map[n] = nil}
- yield component
- end
-
- minimum_id
- end
-
- # Should be implemented by a extended class.
- #
- # #tsort_each_node is used to iterate for all nodes over a graph.
- #
- def tsort_each_node # :yields: node
- raise NotImplementedError.new
- end
-
- # Should be implemented by a extended class.
- #
- # #tsort_each_child is used to iterate for child nodes of _node_.
- #
- def tsort_each_child(node) # :yields: child
- raise NotImplementedError.new
- end
-end
diff --git a/ruby_2_2/lib/ubygems.rb b/ruby_2_2/lib/ubygems.rb
deleted file mode 100644
index fec880f73b..0000000000
--- a/ruby_2_2/lib/ubygems.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-# This file allows for the running of rubygems with a nice
-# command line look-and-feel: ruby -rubygems foo.rb
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-
-require 'rubygems'
diff --git a/ruby_2_2/lib/un.rb b/ruby_2_2/lib/un.rb
deleted file mode 100644
index 487ba9eb75..0000000000
--- a/ruby_2_2/lib/un.rb
+++ /dev/null
@@ -1,375 +0,0 @@
-#
-# = un.rb
-#
-# Copyright (c) 2003 WATANABE Hirofumi <eban@ruby-lang.org>
-#
-# This program is free software.
-# You can distribute/modify this program under the same terms of Ruby.
-#
-# == Utilities to replace common UNIX commands in Makefiles etc
-#
-# == SYNOPSIS
-#
-# ruby -run -e cp -- [OPTION] SOURCE DEST
-# ruby -run -e ln -- [OPTION] TARGET LINK_NAME
-# ruby -run -e mv -- [OPTION] SOURCE DEST
-# ruby -run -e rm -- [OPTION] FILE
-# ruby -run -e mkdir -- [OPTION] DIRS
-# ruby -run -e rmdir -- [OPTION] DIRS
-# ruby -run -e install -- [OPTION] SOURCE DEST
-# ruby -run -e chmod -- [OPTION] OCTAL-MODE FILE
-# ruby -run -e touch -- [OPTION] FILE
-# ruby -run -e wait_writable -- [OPTION] FILE
-# ruby -run -e mkmf -- [OPTION] EXTNAME [OPTION]
-# ruby -run -e httpd -- [OPTION] DocumentRoot
-# ruby -run -e help [COMMAND]
-
-require "fileutils"
-require "optparse"
-
-module FileUtils
-# @fileutils_label = ""
- @fileutils_output = $stdout
-end
-
-# :nodoc:
-def setup(options = "", *long_options)
- caller = caller_locations(1, 1)[0].label
- opt_hash = {}
- argv = []
- OptionParser.new do |o|
- options.scan(/.:?/) do |s|
- opt_name = s.delete(":").intern
- o.on("-" + s.tr(":", " ")) do |val|
- opt_hash[opt_name] = val
- end
- end
- long_options.each do |s|
- opt_name, arg_name = s.split(/(?=[\s=])/, 2)
- opt_name.sub!(/\A--/, '')
- s = "--#{opt_name.gsub(/([A-Z]+|[a-z])([A-Z])/, '\1-\2').downcase}#{arg_name}"
- puts "#{opt_name}=>#{s}" if $DEBUG
- opt_name = opt_name.intern
- o.on(s) do |val|
- opt_hash[opt_name] = val
- end
- end
- o.on("-v") do opt_hash[:verbose] = true end
- o.on("--help") do
- UN.help([caller])
- exit
- end
- o.order!(ARGV) do |x|
- if /[*?\[{]/ =~ x
- argv.concat(Dir[x])
- else
- argv << x
- end
- end
- end
- yield argv, opt_hash
-end
-
-##
-# Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY
-#
-# ruby -run -e cp -- [OPTION] SOURCE DEST
-#
-# -p preserve file attributes if possible
-# -r copy recursively
-# -v verbose
-#
-
-def cp
- setup("pr") do |argv, options|
- cmd = "cp"
- cmd += "_r" if options.delete :r
- options[:preserve] = true if options.delete :p
- dest = argv.pop
- argv = argv[0] if argv.size == 1
- FileUtils.send cmd, argv, dest, options
- end
-end
-
-##
-# Create a link to the specified TARGET with LINK_NAME.
-#
-# ruby -run -e ln -- [OPTION] TARGET LINK_NAME
-#
-# -s make symbolic links instead of hard links
-# -f remove existing destination files
-# -v verbose
-#
-
-def ln
- setup("sf") do |argv, options|
- cmd = "ln"
- cmd += "_s" if options.delete :s
- options[:force] = true if options.delete :f
- dest = argv.pop
- argv = argv[0] if argv.size == 1
- FileUtils.send cmd, argv, dest, options
- end
-end
-
-##
-# Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
-#
-# ruby -run -e mv -- [OPTION] SOURCE DEST
-#
-# -v verbose
-#
-
-def mv
- setup do |argv, options|
- dest = argv.pop
- argv = argv[0] if argv.size == 1
- FileUtils.mv argv, dest, options
- end
-end
-
-##
-# Remove the FILE
-#
-# ruby -run -e rm -- [OPTION] FILE
-#
-# -f ignore nonexistent files
-# -r remove the contents of directories recursively
-# -v verbose
-#
-
-def rm
- setup("fr") do |argv, options|
- cmd = "rm"
- cmd += "_r" if options.delete :r
- options[:force] = true if options.delete :f
- FileUtils.send cmd, argv, options
- end
-end
-
-##
-# Create the DIR, if they do not already exist.
-#
-# ruby -run -e mkdir -- [OPTION] DIR
-#
-# -p no error if existing, make parent directories as needed
-# -v verbose
-#
-
-def mkdir
- setup("p") do |argv, options|
- cmd = "mkdir"
- cmd += "_p" if options.delete :p
- FileUtils.send cmd, argv, options
- end
-end
-
-##
-# Remove the DIR.
-#
-# ruby -run -e rmdir -- [OPTION] DIR
-#
-# -p remove DIRECTORY and its ancestors.
-# -v verbose
-#
-
-def rmdir
- setup("p") do |argv, options|
- options[:parents] = true if options.delete :p
- FileUtils.rmdir argv, options
- end
-end
-
-##
-# Copy SOURCE to DEST.
-#
-# ruby -run -e install -- [OPTION] SOURCE DEST
-#
-# -p apply access/modification times of SOURCE files to
-# corresponding destination files
-# -m set permission mode (as in chmod), instead of 0755
-# -v verbose
-#
-
-def install
- setup("pm:") do |argv, options|
- options[:mode] = (mode = options.delete :m) ? mode.oct : 0755
- options[:preserve] = true if options.delete :p
- dest = argv.pop
- argv = argv[0] if argv.size == 1
- FileUtils.install argv, dest, options
- end
-end
-
-##
-# Change the mode of each FILE to OCTAL-MODE.
-#
-# ruby -run -e chmod -- [OPTION] OCTAL-MODE FILE
-#
-# -v verbose
-#
-
-def chmod
- setup do |argv, options|
- mode = argv.shift.oct
- FileUtils.chmod mode, argv, options
- end
-end
-
-##
-# Update the access and modification times of each FILE to the current time.
-#
-# ruby -run -e touch -- [OPTION] FILE
-#
-# -v verbose
-#
-
-def touch
- setup do |argv, options|
- FileUtils.touch argv, options
- end
-end
-
-##
-# Wait until the file becomes writable.
-#
-# ruby -run -e wait_writable -- [OPTION] FILE
-#
-# -n RETRY count to retry
-# -w SEC each wait time in seconds
-# -v verbose
-#
-
-def wait_writable
- setup("n:w:v") do |argv, options|
- verbose = options[:verbose]
- n = options[:n] and n = Integer(n)
- wait = (wait = options[:w]) ? Float(wait) : 0.2
- argv.each do |file|
- begin
- open(file, "r+b")
- rescue Errno::ENOENT
- break
- rescue Errno::EACCES => e
- raise if n and (n -= 1) <= 0
- if verbose
- puts e
- STDOUT.flush
- end
- sleep wait
- retry
- end
- end
- end
-end
-
-##
-# Create makefile using mkmf.
-#
-# ruby -run -e mkmf -- [OPTION] EXTNAME [OPTION]
-#
-# -d ARGS run dir_config
-# -h ARGS run have_header
-# -l ARGS run have_library
-# -f ARGS run have_func
-# -v ARGS run have_var
-# -t ARGS run have_type
-# -m ARGS run have_macro
-# -c ARGS run have_const
-# --vendor install to vendor_ruby
-#
-
-def mkmf
- setup("d:h:l:f:v:t:m:c:", "vendor") do |argv, options|
- require 'mkmf'
- opt = options[:d] and opt.split(/:/).each {|n| dir_config(*n.split(/,/))}
- opt = options[:h] and opt.split(/:/).each {|n| have_header(*n.split(/,/))}
- opt = options[:l] and opt.split(/:/).each {|n| have_library(*n.split(/,/))}
- opt = options[:f] and opt.split(/:/).each {|n| have_func(*n.split(/,/))}
- opt = options[:v] and opt.split(/:/).each {|n| have_var(*n.split(/,/))}
- opt = options[:t] and opt.split(/:/).each {|n| have_type(*n.split(/,/))}
- opt = options[:m] and opt.split(/:/).each {|n| have_macro(*n.split(/,/))}
- opt = options[:c] and opt.split(/:/).each {|n| have_const(*n.split(/,/))}
- $configure_args["--vendor"] = true if options[:vendor]
- create_makefile(*argv)
- end
-end
-
-##
-# Run WEBrick HTTP server.
-#
-# ruby -run -e httpd -- [OPTION] DocumentRoot
-#
-# --bind-address=ADDR address to bind
-# --port=NUM listening port number
-# --max-clients=MAX max number of simultaneous clients
-# --temp-dir=DIR temporary directory
-# --do-not-reverse-lookup disable reverse lookup
-# --request-timeout=SECOND request timeout in seconds
-# --http-version=VERSION HTTP version
-# -v verbose
-#
-
-def httpd
- setup("", "BindAddress=ADDR", "Port=PORT", "MaxClients=NUM", "TempDir=DIR",
- "DoNotReverseLookup", "RequestTimeout=SECOND", "HTTPVersion=VERSION") do
- |argv, options|
- require 'webrick'
- opt = options[:RequestTimeout] and options[:RequestTimeout] = opt.to_i
- [:Port, :MaxClients].each do |name|
- opt = options[name] and (options[name] = Integer(opt)) rescue nil
- end
- unless argv.size == 1
- raise ArgumentError, "DocumentRoot is mandatory"
- end
- options[:DocumentRoot] = argv.shift
- s = WEBrick::HTTPServer.new(options)
- shut = proc {s.shutdown}
- siglist = %w"TERM QUIT"
- siglist.concat(%w"HUP INT") if STDIN.tty?
- siglist &= Signal.list.keys
- siglist.each do |sig|
- Signal.trap(sig, shut)
- end
- s.start
- end
-end
-
-##
-# Display help message.
-#
-# ruby -run -e help [COMMAND]
-#
-
-def help
- setup do |argv,|
- UN.help(argv)
- end
-end
-
-module UN # :nodoc:
- module_function
- def help(argv, output: $stdout)
- all = argv.empty?
- cmd = nil
- if all
- store = proc {|msg| output << msg}
- else
- messages = {}
- store = proc {|msg| messages[cmd] = msg}
- end
- open(__FILE__) do |me|
- while me.gets("##\n")
- if help = me.gets("\n\n")
- if all or argv.include?(cmd = help[/^#\s*ruby\s.*-e\s+(\w+)/, 1])
- store[help.gsub(/^# ?/, "")]
- break unless all or argv.size > messages.size
- end
- end
- end
- end
- if messages
- argv.each {|cmd| output << messages[cmd]}
- end
- end
-end
diff --git a/ruby_2_2/lib/unicode_normalize.rb b/ruby_2_2/lib/unicode_normalize.rb
deleted file mode 100644
index e79f41d1a2..0000000000
--- a/ruby_2_2/lib/unicode_normalize.rb
+++ /dev/null
@@ -1,78 +0,0 @@
-# coding: utf-8
-
-# Copyright Ayumu Nojima (野島 歩) and Martin J. Dürst (duerst@it.aoyama.ac.jp)
-
-# additions to class String for Unicode normalization
-class String
- # === Unicode Normalization
- #
- # :call-seq:
- # str.unicode_normalize(form=:nfc)
- #
- # Returns a normalized form of +str+, using Unicode normalizations
- # NFC, NFD, NFKC, or NFKD. The normalization form used is determined
- # by +form+, which is any of the four values :nfc, :nfd, :nfkc, or :nfkd.
- # The default is :nfc.
- #
- # If the string is not in a Unicode Encoding, then an Exception is raised.
- # In this context, 'Unicode Encoding' means any of UTF-8, UTF-16BE/LE,
- # and UTF-32BE/LE, as well as GB18030, UCS_2BE, and UCS_4BE. Anything
- # else than UTF-8 is implemented by converting to UTF-8,
- # which makes it slower than UTF-8.
- #
- # _Examples_
- #
- # "a\u0300".unicode_normalize #=> 'à' (same as "\u00E0")
- # "a\u0300".unicode_normalize(:nfc) #=> 'à' (same as "\u00E0")
- # "\u00E0".unicode_normalize(:nfd) #=> 'à' (same as "a\u0300")
- # "\xE0".force_encoding('ISO-8859-1').unicode_normalize(:nfd)
- # #=> Encoding::CompatibilityError raised
- #
- def unicode_normalize(form = :nfc)
- require 'unicode_normalize/normalize.rb' unless defined? UnicodeNormalize
- ## The following line can be uncommented to avoid repeated checking for
- ## UnicodeNormalize. However, tests didn't show any noticeable speedup
- ## when doing this. This comment also applies to the commented out lines
- ## in String#unicode_normalize! and String#unicode_normalized?.
- # String.send(:define_method, :unicode_normalize, ->(form = :nfc) { UnicodeNormalize.normalize(self, form) } )
- UnicodeNormalize.normalize(self, form)
- end
-
- # :call-seq:
- # str.unicode_normalize!(form=:nfc)
- #
- # Destructive version of String#unicode_normalize, doing Unicode
- # normalization in place.
- #
- def unicode_normalize!(form = :nfc)
- require 'unicode_normalize/normalize.rb' unless defined? UnicodeNormalize
- # String.send(:define_method, :unicode_normalize!, ->(form = :nfc) { replace(unicode_normalize(form)) } )
- replace(unicode_normalize(form))
- end
-
- # :call-seq:
- # str.unicode_normalized?(form=:nfc)
- #
- # Checks whether +str+ is in Unicode normalization form +form+,
- # which is any of the four values :nfc, :nfd, :nfkc, or :nfkd.
- # The default is :nfc.
- #
- # If the string is not in a Unicode Encoding, then an Exception is raised.
- # For details, see String#unicode_normalize.
- #
- # _Examples_
- #
- # "a\u0300".unicode_normalized? #=> false
- # "a\u0300".unicode_normalized?(:nfd) #=> true
- # "\u00E0".unicode_normalized? #=> true
- # "\u00E0".unicode_normalized?(:nfd) #=> false
- # "\xE0".force_encoding('ISO-8859-1').unicode_normalized?
- # #=> Encoding::CompatibilityError raised
- #
- def unicode_normalized?(form = :nfc)
- require 'unicode_normalize/normalize.rb' unless defined? UnicodeNormalize
- # String.send(:define_method, :unicode_normalized?, ->(form = :nfc) { UnicodeNormalize.normalized?(self, form) } )
- UnicodeNormalize.normalized?(self, form)
- end
-end
-
diff --git a/ruby_2_2/lib/unicode_normalize/normalize.rb b/ruby_2_2/lib/unicode_normalize/normalize.rb
deleted file mode 100644
index 1511f75f8a..0000000000
--- a/ruby_2_2/lib/unicode_normalize/normalize.rb
+++ /dev/null
@@ -1,168 +0,0 @@
-# coding: utf-8
-
-# Copyright Ayumu Nojima (野島 歩) and Martin J. Dürst (duerst@it.aoyama.ac.jp)
-
-require 'unicode_normalize/tables.rb'
-
-
-module UnicodeNormalize
- ## Constant for max hash capacity to avoid DoS attack
- MAX_HASH_LENGTH = 18000 # enough for all test cases, otherwise tests get slow
-
- ## Regular Expressions and Hash Constants
- REGEXP_D = Regexp.compile(REGEXP_D_STRING, Regexp::EXTENDED)
- REGEXP_C = Regexp.compile(REGEXP_C_STRING, Regexp::EXTENDED)
- REGEXP_K = Regexp.compile(REGEXP_K_STRING, Regexp::EXTENDED)
- NF_HASH_D = Hash.new do |hash, key|
- hash.shift if hash.length>MAX_HASH_LENGTH # prevent DoS attack
- hash[key] = nfd_one(key)
- end
- NF_HASH_C = Hash.new do |hash, key|
- hash.shift if hash.length>MAX_HASH_LENGTH # prevent DoS attack
- hash[key] = nfc_one(key)
- end
- NF_HASH_K = Hash.new do |hash, key|
- hash.shift if hash.length>MAX_HASH_LENGTH # prevent DoS attack
- hash[key] = nfkd_one(key)
- end
-
- ## Constants For Hangul
- # for details such as the meaning of the identifiers below, please see
- # http://www.unicode.org/versions/Unicode7.0.0/ch03.pdf, pp. 144/145
- SBASE = 0xAC00
- LBASE = 0x1100
- VBASE = 0x1161
- TBASE = 0x11A7
- LCOUNT = 19
- VCOUNT = 21
- TCOUNT = 28
- NCOUNT = VCOUNT * TCOUNT
- SCOUNT = LCOUNT * NCOUNT
-
- # Unicode-based encodings (except UTF-8)
- UNICODE_ENCODINGS = [Encoding::UTF_16BE, Encoding::UTF_16LE, Encoding::UTF_32BE, Encoding::UTF_32LE,
- Encoding::GB18030, Encoding::UCS_2BE, Encoding::UCS_4BE]
-
- ## Hangul Algorithm
- def self.hangul_decomp_one(target)
- syllable_index = target.ord - SBASE
- return target if syllable_index < 0 || syllable_index >= SCOUNT
- l = LBASE + syllable_index / NCOUNT
- v = VBASE + (syllable_index % NCOUNT) / TCOUNT
- t = TBASE + syllable_index % TCOUNT
- (t==TBASE ? [l, v] : [l, v, t]).pack('U*') + target[1..-1]
- end
-
- def self.hangul_comp_one(string)
- length = string.length
- if length>1 and 0 <= (lead =string[0].ord-LBASE) and lead < LCOUNT and
- 0 <= (vowel=string[1].ord-VBASE) and vowel < VCOUNT
- lead_vowel = SBASE + (lead * VCOUNT + vowel) * TCOUNT
- if length>2 and 0 <= (trail=string[2].ord-TBASE) and trail < TCOUNT
- (lead_vowel + trail).chr(Encoding::UTF_8) + string[3..-1]
- else
- lead_vowel.chr(Encoding::UTF_8) + string[2..-1]
- end
- else
- string
- end
- end
-
- ## Canonical Ordering
- def self.canonical_ordering_one(string)
- sorting = string.each_char.collect { |c| [c, CLASS_TABLE[c]] }
- (sorting.length-2).downto(0) do |i| # almost, but not exactly bubble sort
- (0..i).each do |j|
- later_class = sorting[j+1].last
- if 0<later_class and later_class<sorting[j].last
- sorting[j], sorting[j+1] = sorting[j+1], sorting[j]
- end
- end
- end
- return sorting.collect(&:first).join('')
- end
-
- ## Normalization Forms for Patterns (not whole Strings)
- def self.nfd_one(string)
- string = string.chars.map! {|c| DECOMPOSITION_TABLE[c] || c}.join('')
- canonical_ordering_one(hangul_decomp_one(string))
- end
-
- def self.nfkd_one(string)
- string.chars.map! {|c| KOMPATIBLE_TABLE[c] || c}.join('')
- end
-
- def self.nfc_one(string)
- nfd_string = nfd_one string
- start = nfd_string[0]
- last_class = CLASS_TABLE[start]-1
- accents = ''
- nfd_string[1..-1].each_char do |accent|
- accent_class = CLASS_TABLE[accent]
- if last_class<accent_class and composite = COMPOSITION_TABLE[start+accent]
- start = composite
- else
- accents << accent
- last_class = accent_class
- end
- end
- hangul_comp_one(start+accents)
- end
-
- def self.normalize(string, form = :nfc)
- encoding = string.encoding
- case encoding
- when Encoding::UTF_8
- case form
- when :nfc then
- string.gsub REGEXP_C, NF_HASH_C
- when :nfd then
- string.gsub REGEXP_D, NF_HASH_D
- when :nfkc then
- string.gsub(REGEXP_K, NF_HASH_K).gsub REGEXP_C, NF_HASH_C
- when :nfkd then
- string.gsub(REGEXP_K, NF_HASH_K).gsub REGEXP_D, NF_HASH_D
- else
- raise ArgumentError, "Invalid normalization form #{form}."
- end
- when Encoding::US_ASCII
- string
- when *UNICODE_ENCODINGS
- normalize(string.encode(Encoding::UTF_8), form).encode(encoding)
- else
- raise Encoding::CompatibilityError, "Unicode Normalization not appropriate for #{encoding}"
- end
- end
-
- def self.normalized?(string, form = :nfc)
- encoding = string.encoding
- case encoding
- when Encoding::UTF_8
- case form
- when :nfc then
- string.scan REGEXP_C do |match|
- return false if NF_HASH_C[match] != match
- end
- true
- when :nfd then
- string.scan REGEXP_D do |match|
- return false if NF_HASH_D[match] != match
- end
- true
- when :nfkc then
- normalized?(string, :nfc) and string !~ REGEXP_K
- when :nfkd then
- normalized?(string, :nfd) and string !~ REGEXP_K
- else
- raise ArgumentError, "Invalid normalization form #{form}."
- end
- when Encoding::US_ASCII
- true
- when *UNICODE_ENCODINGS
- normalized? string.encode(Encoding::UTF_8), form
- else
- raise Encoding::CompatibilityError, "Unicode Normalization not appropriate for #{encoding}"
- end
- end
-
-end # module
diff --git a/ruby_2_2/lib/unicode_normalize/tables.rb b/ruby_2_2/lib/unicode_normalize/tables.rb
deleted file mode 100644
index 8720898389..0000000000
--- a/ruby_2_2/lib/unicode_normalize/tables.rb
+++ /dev/null
@@ -1,1163 +0,0 @@
-# coding: us-ascii
-
-# automatically generated by template/unicode_norm_gen.tmpl
-
-module UnicodeNormalize
- UNICODE_VERSION = "7.0.0".freeze
-
- accents = "" \
- "[\u0300-\u034E\u0350-\u036F\u0483-\u0487\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7" \
- "\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711" \
- "\u0730-\u074A\u07EB-\u07F3\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08E4-\u08FF" \
- "\u093C\u094D\u0951-\u0954\u09BC\u09BE\u09CD\u09D7\u0A3C" \
- "\u0A4D\u0ABC\u0ACD\u0B3C\u0B3E\u0B4D\u0B56\u0B57\u0BBE" \
- "\u0BCD\u0BD7\u0C4D\u0C55\u0C56\u0CBC\u0CC2\u0CCD\u0CD5\u0CD6" \
- "\u0D3E\u0D4D\u0D57\u0DCA\u0DCF\u0DDF\u0E38-\u0E3A\u0E48-\u0E4B" \
- "\u0EB8\u0EB9\u0EC8-\u0ECB\u0F18\u0F19\u0F35\u0F37\u0F39\u0F71\u0F72\u0F74" \
- "\u0F7A-\u0F7D\u0F80\u0F82-\u0F84\u0F86\u0F87\u0FC6\u102E\u1037\u1039\u103A" \
- "\u108D\u135D-\u135F\u1714\u1734\u17D2\u17DD\u18A9\u1939-\u193B" \
- "\u1A17\u1A18\u1A60\u1A75-\u1A7C\u1A7F\u1AB0-\u1ABD\u1B34\u1B35\u1B44\u1B6B-\u1B73" \
- "\u1BAA\u1BAB\u1BE6\u1BF2\u1BF3\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE0\u1CE2-\u1CE8\u1CED" \
- "\u1CF4\u1CF8\u1CF9\u1DC0-\u1DF5\u1DFC-\u1DFF\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2CEF-\u2CF1" \
- "\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F\uA674-\uA67D\uA69F\uA6F0\uA6F1" \
- "\uA806\uA8C4\uA8E0-\uA8F1\uA92B-\uA92D\uA953\uA9B3\uA9C0\uAAB0" \
- "\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAF6\uABED\uFB1E\uFE20-\uFE2D" \
- "\u{101FD}\u{102E0}\u{10376}-\u{1037A}\u{10A0D}\u{10A0F}\u{10A38}-\u{10A3A}\u{10A3F}\u{10AE5}\u{10AE6}" \
- "\u{11046}\u{1107F}\u{110B9}\u{110BA}\u{11100}-\u{11102}\u{11127}\u{11133}\u{11134}\u{11173}\u{111C0}" \
- "\u{11235}\u{11236}\u{112E9}\u{112EA}\u{1133C}\u{1133E}\u{1134D}\u{11357}\u{11366}-\u{1136C}\u{11370}-\u{11374}" \
- "\u{114B0}\u{114BA}\u{114BD}\u{114C2}\u{114C3}\u{115AF}\u{115BF}\u{115C0}\u{1163F}\u{116B6}\u{116B7}" \
- "\u{16AF0}-\u{16AF4}\u{16B30}-\u{16B36}\u{1BC9E}\u{1D165}-\u{1D169}\u{1D16D}-\u{1D172}\u{1D17B}-\u{1D182}\u{1D185}-\u{1D18B}\u{1D1AA}-\u{1D1AD}" \
- "\u{1D242}-\u{1D244}\u{1E8D0}-\u{1E8D6}" \
- "]" \
- "".freeze
- ACCENTS = accents
- REGEXP_D_STRING = "#{'' # composition starters and composition exclusions
- }" \
- "[\u00C0-\u00C5\u00C7-\u00CF\u00D1-\u00D6\u00D9-\u00DD\u00E0-\u00E5\u00E7-\u00EF\u00F1-\u00F6\u00F9-\u00FD" \
- "\u00FF-\u010F\u0112-\u0125\u0128-\u0130\u0134-\u0137\u0139-\u013E\u0143-\u0148\u014C-\u0151\u0154-\u0165" \
- "\u0168-\u017E\u01A0\u01A1\u01AF\u01B0\u01CD-\u01DC\u01DE-\u01E3\u01E6-\u01F0\u01F4\u01F5\u01F8-\u021B" \
- "\u021E\u021F\u0226-\u0233\u0340\u0341\u0343\u0344\u0374\u037E\u0385-\u038A\u038C" \
- "\u038E-\u0390\u03AA-\u03B0\u03CA-\u03CE\u03D3\u03D4\u0400\u0401\u0403\u0407\u040C-\u040E" \
- "\u0419\u0439\u0450\u0451\u0453\u0457\u045C-\u045E\u0476\u0477\u04C1\u04C2" \
- "\u04D0-\u04D3\u04D6\u04D7\u04DA-\u04DF\u04E2-\u04E7\u04EA-\u04F5\u04F8\u04F9\u0622-\u0626\u06C0" \
- "\u06C2\u06D3\u0929\u0931\u0934\u0958-\u095F\u09CB\u09CC\u09DC\u09DD" \
- "\u09DF\u0A33\u0A36\u0A59-\u0A5B\u0A5E\u0B48\u0B4B\u0B4C\u0B5C\u0B5D" \
- "\u0B94\u0BCA-\u0BCC\u0C48\u0CC0\u0CC7\u0CC8\u0CCA\u0CCB\u0D4A-\u0D4C\u0DDA" \
- "\u0DDC-\u0DDE\u0F43\u0F4D\u0F52\u0F57\u0F5C\u0F69\u0F73" \
- "\u0F75\u0F76\u0F78\u0F81\u0F93\u0F9D\u0FA2\u0FA7\u0FAC" \
- "\u0FB9\u1026\u1B06\u1B08\u1B0A\u1B0C\u1B0E\u1B12" \
- "\u1B3B\u1B3D\u1B40\u1B41\u1B43\u1E00-\u1E99\u1E9B\u1EA0-\u1EF9\u1F00-\u1F15" \
- "\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D" \
- "\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC1-\u1FC4\u1FC6-\u1FD3\u1FD6-\u1FDB\u1FDD-\u1FEF\u1FF2-\u1FF4" \
- "\u1FF6-\u1FFD\u2000\u2001\u2126\u212A\u212B\u219A\u219B\u21AE\u21CD-\u21CF\u2204" \
- "\u2209\u220C\u2224\u2226\u2241\u2244\u2247\u2249" \
- "\u2260\u2262\u226D-\u2271\u2274\u2275\u2278\u2279\u2280\u2281\u2284\u2285\u2288\u2289" \
- "\u22AC-\u22AF\u22E0-\u22E3\u22EA-\u22ED\u2329\u232A\u2ADC\u304C\u304E\u3050" \
- "\u3052\u3054\u3056\u3058\u305A\u305C\u305E\u3060" \
- "\u3062\u3065\u3067\u3069\u3070\u3071\u3073\u3074\u3076\u3077\u3079\u307A" \
- "\u307C\u307D\u3094\u309E\u30AC\u30AE\u30B0\u30B2\u30B4" \
- "\u30B6\u30B8\u30BA\u30BC\u30BE\u30C0\u30C2\u30C5" \
- "\u30C7\u30C9\u30D0\u30D1\u30D3\u30D4\u30D6\u30D7\u30D9\u30DA\u30DC\u30DD\u30F4" \
- "\u30F7-\u30FA\u30FE\uF900-\uFA0D\uFA10\uFA12\uFA15-\uFA1E\uFA20\uFA22" \
- "\uFA25\uFA26\uFA2A-\uFA6D\uFA70-\uFAD9\uFB1D\uFB1F\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E" \
- "\uFB40\uFB41\uFB43\uFB44\uFB46-\uFB4E\u{1109A}\u{1109C}\u{110AB}\u{1112E}\u{1112F}\u{1134B}\u{1134C}" \
- "\u{114BB}\u{114BC}\u{114BE}\u{115BA}\u{115BB}\u{1D15E}-\u{1D164}\u{1D1BB}-\u{1D1C0}\u{2F800}-\u{2FA1D}" \
- "]#{accents}*" \
- "|#{'' # characters that can be the result of a composition, except composition starters
- }" \
- "[<->A-PR-Za-pr-z\u00A8\u00C6\u00D8" \
- "\u00E6\u00F8\u017F\u01B7\u0292\u0391\u0395\u0397" \
- "\u0399\u039F\u03A1\u03A5\u03A9\u03B1\u03B5\u03B7" \
- "\u03B9\u03BF\u03C1\u03C5\u03C9\u03D2\u0406\u0410" \
- "\u0413\u0415-\u0418\u041A\u041E\u0423\u0427\u042B\u042D" \
- "\u0430\u0433\u0435-\u0438\u043A\u043E\u0443\u0447\u044B" \
- "\u044D\u0456\u0474\u0475\u04D8\u04D9\u04E8\u04E9\u0627\u0648\u064A" \
- "\u06C1\u06D2\u06D5\u0928\u0930\u0933\u09C7\u0B47" \
- "\u0B92\u0BC6\u0BC7\u0C46\u0CBF\u0CC6\u0D46\u0D47\u0DD9\u1025" \
- "\u1B05\u1B07\u1B09\u1B0B\u1B0D\u1B11\u1B3A\u1B3C" \
- "\u1B3E\u1B3F\u1B42\u1FBF\u1FFE\u2190\u2192\u2194\u21D0" \
- "\u21D2\u21D4\u2203\u2208\u220B\u2223\u2225\u223C" \
- "\u2243\u2245\u2248\u224D\u2261\u2264\u2265\u2272\u2273\u2276\u2277" \
- "\u227A-\u227D\u2282\u2283\u2286\u2287\u2291\u2292\u22A2\u22A8\u22A9\u22AB\u22B2-\u22B5" \
- "\u3046\u304B\u304D\u304F\u3051\u3053\u3055\u3057" \
- "\u3059\u305B\u305D\u305F\u3061\u3064\u3066\u3068" \
- "\u306F\u3072\u3075\u3078\u307B\u309D\u30A6\u30AB" \
- "\u30AD\u30AF\u30B1\u30B3\u30B5\u30B7\u30B9\u30BB" \
- "\u30BD\u30BF\u30C1\u30C4\u30C6\u30C8\u30CF\u30D2" \
- "\u30D5\u30D8\u30DB\u30EF-\u30F2\u30FD\u{11099}\u{1109B}\u{110A5}" \
- "\u{11131}\u{11132}\u{11347}\u{114B9}\u{115B8}\u{115B9}" \
- "]?#{accents}+" \
- "|#{'' # precomposed Hangul syllables
- }" \
- "[\u{AC00}-\u{D7A4}]" \
- "".freeze
- REGEXP_C_STRING = "#{'' # composition exclusions
- }" \
- "[\u0340\u0341\u0343\u0344\u0374\u037E\u0387\u0958-\u095F\u09DC\u09DD\u09DF" \
- "\u0A33\u0A36\u0A59-\u0A5B\u0A5E\u0B5C\u0B5D\u0F43\u0F4D\u0F52" \
- "\u0F57\u0F5C\u0F69\u0F73\u0F75\u0F76\u0F78\u0F81\u0F93" \
- "\u0F9D\u0FA2\u0FA7\u0FAC\u0FB9\u1F71\u1F73\u1F75" \
- "\u1F77\u1F79\u1F7B\u1F7D\u1FBB\u1FBE\u1FC9\u1FCB" \
- "\u1FD3\u1FDB\u1FE3\u1FEB\u1FEE\u1FEF\u1FF9\u1FFB\u1FFD" \
- "\u2000\u2001\u2126\u212A\u212B\u2329\u232A\u2ADC\uF900-\uFA0D\uFA10\uFA12" \
- "\uFA15-\uFA1E\uFA20\uFA22\uFA25\uFA26\uFA2A-\uFA6D\uFA70-\uFAD9\uFB1D\uFB1F" \
- "\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFB4E\u{1D15E}-\u{1D164}\u{1D1BB}-\u{1D1C0}" \
- "\u{2F800}-\u{2FA1D}" \
- "]#{accents}*" \
- "|#{'' # composition starters and characters that can be the result of a composition
- }" \
- "[<->A-PR-Za-pr-z\u00A8\u00C0-\u00CF\u00D1-\u00D6" \
- "\u00D8-\u00DD\u00E0-\u00EF\u00F1-\u00F6\u00F8-\u00FD\u00FF-\u010F\u0112-\u0125\u0128-\u0130\u0134-\u0137" \
- "\u0139-\u013E\u0143-\u0148\u014C-\u0151\u0154-\u0165\u0168-\u017F\u01A0\u01A1\u01AF\u01B0\u01B7" \
- "\u01CD-\u01DC\u01DE-\u01E3\u01E6-\u01F0\u01F4\u01F5\u01F8-\u021B\u021E\u021F\u0226-\u0233\u0292" \
- "\u0385\u0386\u0388-\u038A\u038C\u038E-\u0391\u0395\u0397\u0399\u039F" \
- "\u03A1\u03A5\u03A9-\u03B1\u03B5\u03B7\u03B9\u03BF\u03C1" \
- "\u03C5\u03C9-\u03CE\u03D2-\u03D4\u0400\u0401\u0403\u0406\u0407\u040C-\u040E\u0410" \
- "\u0413\u0415-\u041A\u041E\u0423\u0427\u042B\u042D\u0430" \
- "\u0433\u0435-\u043A\u043E\u0443\u0447\u044B\u044D\u0450\u0451" \
- "\u0453\u0456\u0457\u045C-\u045E\u0474-\u0477\u04C1\u04C2\u04D0-\u04D3\u04D6-\u04DF\u04E2-\u04F5" \
- "\u04F8\u04F9\u0622-\u0627\u0648\u064A\u06C0-\u06C2\u06D2\u06D3\u06D5\u0928\u0929" \
- "\u0930\u0931\u0933\u0934\u09C7\u09CB\u09CC\u0B47\u0B48\u0B4B\u0B4C\u0B92\u0B94" \
- "\u0BC6\u0BC7\u0BCA-\u0BCC\u0C46\u0C48\u0CBF\u0CC0\u0CC6-\u0CC8\u0CCA\u0CCB\u0D46\u0D47" \
- "\u0D4A-\u0D4C\u0DD9\u0DDA\u0DDC-\u0DDE\u1025\u1026\u1B05-\u1B0E\u1B11\u1B12\u1B3A-\u1B43\u1E00-\u1E99" \
- "\u1E9B\u1EA0-\u1EF9\u1F00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59" \
- "\u1F5B\u1F5D\u1F5F-\u1F70\u1F72\u1F74\u1F76\u1F78\u1F7A" \
- "\u1F7C\u1F80-\u1FB4\u1FB6-\u1FBA\u1FBC\u1FBF\u1FC1-\u1FC4\u1FC6-\u1FC8\u1FCA" \
- "\u1FCC-\u1FD2\u1FD6-\u1FDA\u1FDD-\u1FE2\u1FE4-\u1FEA\u1FEC\u1FED\u1FF2-\u1FF4\u1FF6-\u1FF8\u1FFA" \
- "\u1FFC\u1FFE\u2190\u2192\u2194\u219A\u219B\u21AE\u21CD-\u21D0" \
- "\u21D2\u21D4\u2203\u2204\u2208\u2209\u220B\u220C\u2223-\u2226\u223C\u2241" \
- "\u2243-\u2245\u2247-\u2249\u224D\u2260-\u2262\u2264\u2265\u226D-\u227D\u2280-\u2289\u2291\u2292" \
- "\u22A2\u22A8\u22A9\u22AB-\u22AF\u22B2-\u22B5\u22E0-\u22E3\u22EA-\u22ED\u3046\u304B-\u3062" \
- "\u3064-\u3069\u306F-\u307D\u3094\u309D\u309E\u30A6\u30AB-\u30C2\u30C4-\u30C9\u30CF-\u30DD" \
- "\u30EF-\u30F2\u30F4\u30F7-\u30FA\u30FD\u30FE\u{11099}-\u{1109C}\u{110A5}\u{110AB}\u{1112E}\u{1112F}" \
- "\u{11131}\u{11132}\u{11347}\u{1134B}\u{1134C}\u{114B9}\u{114BB}\u{114BC}\u{114BE}\u{115B8}-\u{115BB}" \
- "]?#{accents}+" \
- "|#{'' # Hangul syllables with separate trailer
- }" \
- "[\uAC00\uAC1C\uAC38\uAC54\uAC70\uAC8C\uACA8\uACC4" \
- "\uACE0\uACFC\uAD18\uAD34\uAD50\uAD6C\uAD88\uADA4" \
- "\uADC0\uADDC\uADF8\uAE14\uAE30\uAE4C\uAE68\uAE84" \
- "\uAEA0\uAEBC\uAED8\uAEF4\uAF10\uAF2C\uAF48\uAF64" \
- "\uAF80\uAF9C\uAFB8\uAFD4\uAFF0\uB00C\uB028\uB044" \
- "\uB060\uB07C\uB098\uB0B4\uB0D0\uB0EC\uB108\uB124" \
- "\uB140\uB15C\uB178\uB194\uB1B0\uB1CC\uB1E8\uB204" \
- "\uB220\uB23C\uB258\uB274\uB290\uB2AC\uB2C8\uB2E4" \
- "\uB300\uB31C\uB338\uB354\uB370\uB38C\uB3A8\uB3C4" \
- "\uB3E0\uB3FC\uB418\uB434\uB450\uB46C\uB488\uB4A4" \
- "\uB4C0\uB4DC\uB4F8\uB514\uB530\uB54C\uB568\uB584" \
- "\uB5A0\uB5BC\uB5D8\uB5F4\uB610\uB62C\uB648\uB664" \
- "\uB680\uB69C\uB6B8\uB6D4\uB6F0\uB70C\uB728\uB744" \
- "\uB760\uB77C\uB798\uB7B4\uB7D0\uB7EC\uB808\uB824" \
- "\uB840\uB85C\uB878\uB894\uB8B0\uB8CC\uB8E8\uB904" \
- "\uB920\uB93C\uB958\uB974\uB990\uB9AC\uB9C8\uB9E4" \
- "\uBA00\uBA1C\uBA38\uBA54\uBA70\uBA8C\uBAA8\uBAC4" \
- "\uBAE0\uBAFC\uBB18\uBB34\uBB50\uBB6C\uBB88\uBBA4" \
- "\uBBC0\uBBDC\uBBF8\uBC14\uBC30\uBC4C\uBC68\uBC84" \
- "\uBCA0\uBCBC\uBCD8\uBCF4\uBD10\uBD2C\uBD48\uBD64" \
- "\uBD80\uBD9C\uBDB8\uBDD4\uBDF0\uBE0C\uBE28\uBE44" \
- "\uBE60\uBE7C\uBE98\uBEB4\uBED0\uBEEC\uBF08\uBF24" \
- "\uBF40\uBF5C\uBF78\uBF94\uBFB0\uBFCC\uBFE8\uC004" \
- "\uC020\uC03C\uC058\uC074\uC090\uC0AC\uC0C8\uC0E4" \
- "\uC100\uC11C\uC138\uC154\uC170\uC18C\uC1A8\uC1C4" \
- "\uC1E0\uC1FC\uC218\uC234\uC250\uC26C\uC288\uC2A4" \
- "\uC2C0\uC2DC\uC2F8\uC314\uC330\uC34C\uC368\uC384" \
- "\uC3A0\uC3BC\uC3D8\uC3F4\uC410\uC42C\uC448\uC464" \
- "\uC480\uC49C\uC4B8\uC4D4\uC4F0\uC50C\uC528\uC544" \
- "\uC560\uC57C\uC598\uC5B4\uC5D0\uC5EC\uC608\uC624" \
- "\uC640\uC65C\uC678\uC694\uC6B0\uC6CC\uC6E8\uC704" \
- "\uC720\uC73C\uC758\uC774\uC790\uC7AC\uC7C8\uC7E4" \
- "\uC800\uC81C\uC838\uC854\uC870\uC88C\uC8A8\uC8C4" \
- "\uC8E0\uC8FC\uC918\uC934\uC950\uC96C\uC988\uC9A4" \
- "\uC9C0\uC9DC\uC9F8\uCA14\uCA30\uCA4C\uCA68\uCA84" \
- "\uCAA0\uCABC\uCAD8\uCAF4\uCB10\uCB2C\uCB48\uCB64" \
- "\uCB80\uCB9C\uCBB8\uCBD4\uCBF0\uCC0C\uCC28\uCC44" \
- "\uCC60\uCC7C\uCC98\uCCB4\uCCD0\uCCEC\uCD08\uCD24" \
- "\uCD40\uCD5C\uCD78\uCD94\uCDB0\uCDCC\uCDE8\uCE04" \
- "\uCE20\uCE3C\uCE58\uCE74\uCE90\uCEAC\uCEC8\uCEE4" \
- "\uCF00\uCF1C\uCF38\uCF54\uCF70\uCF8C\uCFA8\uCFC4" \
- "\uCFE0\uCFFC\uD018\uD034\uD050\uD06C\uD088\uD0A4" \
- "\uD0C0\uD0DC\uD0F8\uD114\uD130\uD14C\uD168\uD184" \
- "\uD1A0\uD1BC\uD1D8\uD1F4\uD210\uD22C\uD248\uD264" \
- "\uD280\uD29C\uD2B8\uD2D4\uD2F0\uD30C\uD328\uD344" \
- "\uD360\uD37C\uD398\uD3B4\uD3D0\uD3EC\uD408\uD424" \
- "\uD440\uD45C\uD478\uD494\uD4B0\uD4CC\uD4E8\uD504" \
- "\uD520\uD53C\uD558\uD574\uD590\uD5AC\uD5C8\uD5E4" \
- "\uD600\uD61C\uD638\uD654\uD670\uD68C\uD6A8\uD6C4" \
- "\uD6E0\uD6FC\uD718\uD734\uD750\uD76C\uD788" \
- "][\u11A8-\u11C2]" \
- "|#{'' # decomposed Hangul syllables
- }" \
- "[\u1100-\u1112][\u1161-\u1175][\u11A8-\u11C2]?" \
- "".freeze
- REGEXP_K_STRING = "" \
- "[\u00A0\u00A8\u00AA\u00AF\u00B2-\u00B5\u00B8-\u00BA\u00BC-\u00BE\u0132\u0133" \
- "\u013F\u0140\u0149\u017F\u01C4-\u01CC\u01F1-\u01F3\u02B0-\u02B8\u02D8-\u02DD\u02E0-\u02E4" \
- "\u037A\u0384\u0385\u03D0-\u03D6\u03F0-\u03F2\u03F4\u03F5\u03F9\u0587\u0675-\u0678" \
- "\u0E33\u0EB3\u0EDC\u0EDD\u0F0C\u0F77\u0F79\u10FC\u1D2C-\u1D2E" \
- "\u1D30-\u1D3A\u1D3C-\u1D4D\u1D4F-\u1D6A\u1D78\u1D9B-\u1DBF\u1E9A\u1E9B\u1FBD\u1FBF-\u1FC1" \
- "\u1FCD-\u1FCF\u1FDD-\u1FDF\u1FED\u1FEE\u1FFD\u1FFE\u2000-\u200A\u2011\u2017\u2024-\u2026" \
- "\u202F\u2033\u2034\u2036\u2037\u203C\u203E\u2047-\u2049\u2057\u205F" \
- "\u2070\u2071\u2074-\u208E\u2090-\u209C\u20A8\u2100-\u2103\u2105-\u2107\u2109-\u2113\u2115\u2116" \
- "\u2119-\u211D\u2120-\u2122\u2124\u2128\u212C\u212D\u212F-\u2131\u2133-\u2139\u213B-\u2140" \
- "\u2145-\u2149\u2150-\u217F\u2189\u222C\u222D\u222F\u2230\u2460-\u24EA\u2A0C\u2A74-\u2A76" \
- "\u2C7C\u2C7D\u2D6F\u2E9F\u2EF3\u2F00-\u2FD5\u3000\u3036\u3038-\u303A" \
- "\u309B\u309C\u309F\u30FF\u3131-\u318E\u3192-\u319F\u3200-\u321E\u3220-\u3247\u3250-\u327E" \
- "\u3280-\u32FE\u3300-\u33FF\uA69C\uA69D\uA770\uA7F8\uA7F9\uAB5C-\uAB5F\uFB00-\uFB06\uFB13-\uFB17" \
- "\uFB20-\uFB29\uFB4F-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFC\uFE10-\uFE19\uFE30-\uFE44" \
- "\uFE47-\uFE52\uFE54-\uFE66\uFE68-\uFE6B\uFE70-\uFE72\uFE74\uFE76-\uFEFC\uFF01-\uFFBE\uFFC2-\uFFC7" \
- "\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC\uFFE0-\uFFE6\uFFE8-\uFFEE\u{1D400}-\u{1D454}\u{1D456}-\u{1D49C}\u{1D49E}\u{1D49F}" \
- "\u{1D4A2}\u{1D4A5}\u{1D4A6}\u{1D4A9}-\u{1D4AC}\u{1D4AE}-\u{1D4B9}\u{1D4BB}\u{1D4BD}-\u{1D4C3}\u{1D4C5}-\u{1D505}\u{1D507}-\u{1D50A}" \
- "\u{1D50D}-\u{1D514}\u{1D516}-\u{1D51C}\u{1D51E}-\u{1D539}\u{1D53B}-\u{1D53E}\u{1D540}-\u{1D544}\u{1D546}\u{1D54A}-\u{1D550}\u{1D552}-\u{1D6A5}" \
- "\u{1D6A8}-\u{1D7CB}\u{1D7CE}-\u{1D7FF}\u{1EE00}-\u{1EE03}\u{1EE05}-\u{1EE1F}\u{1EE21}\u{1EE22}\u{1EE24}\u{1EE27}\u{1EE29}-\u{1EE32}" \
- "\u{1EE34}-\u{1EE37}\u{1EE39}\u{1EE3B}\u{1EE42}\u{1EE47}\u{1EE49}\u{1EE4B}\u{1EE4D}-\u{1EE4F}" \
- "\u{1EE51}\u{1EE52}\u{1EE54}\u{1EE57}\u{1EE59}\u{1EE5B}\u{1EE5D}\u{1EE5F}\u{1EE61}\u{1EE62}" \
- "\u{1EE64}\u{1EE67}-\u{1EE6A}\u{1EE6C}-\u{1EE72}\u{1EE74}-\u{1EE77}\u{1EE79}-\u{1EE7C}\u{1EE7E}\u{1EE80}-\u{1EE89}\u{1EE8B}-\u{1EE9B}" \
- "\u{1EEA1}-\u{1EEA3}\u{1EEA5}-\u{1EEA9}\u{1EEAB}-\u{1EEBB}\u{1F100}-\u{1F10A}\u{1F110}-\u{1F12E}\u{1F130}-\u{1F14F}\u{1F16A}\u{1F16B}\u{1F190}" \
- "\u{1F200}-\u{1F202}\u{1F210}-\u{1F23A}\u{1F240}-\u{1F248}\u{1F250}\u{1F251}" \
- "]" \
- "".freeze
-
- class_table = {
- "\u0300"=>230, "\u0301"=>230, "\u0302"=>230, "\u0303"=>230, "\u0304"=>230, "\u0305"=>230, "\u0306"=>230, "\u0307"=>230,
- "\u0308"=>230, "\u0309"=>230, "\u030A"=>230, "\u030B"=>230, "\u030C"=>230, "\u030D"=>230, "\u030E"=>230, "\u030F"=>230,
- "\u0310"=>230, "\u0311"=>230, "\u0312"=>230, "\u0313"=>230, "\u0314"=>230, "\u0315"=>232, "\u0316"=>220, "\u0317"=>220,
- "\u0318"=>220, "\u0319"=>220, "\u031A"=>232, "\u031B"=>216, "\u031C"=>220, "\u031D"=>220, "\u031E"=>220, "\u031F"=>220,
- "\u0320"=>220, "\u0321"=>202, "\u0322"=>202, "\u0323"=>220, "\u0324"=>220, "\u0325"=>220, "\u0326"=>220, "\u0327"=>202,
- "\u0328"=>202, "\u0329"=>220, "\u032A"=>220, "\u032B"=>220, "\u032C"=>220, "\u032D"=>220, "\u032E"=>220, "\u032F"=>220,
- "\u0330"=>220, "\u0331"=>220, "\u0332"=>220, "\u0333"=>220, "\u0334"=>1, "\u0335"=>1, "\u0336"=>1, "\u0337"=>1,
- "\u0338"=>1, "\u0339"=>220, "\u033A"=>220, "\u033B"=>220, "\u033C"=>220, "\u033D"=>230, "\u033E"=>230, "\u033F"=>230,
- "\u0340"=>230, "\u0341"=>230, "\u0342"=>230, "\u0343"=>230, "\u0344"=>230, "\u0345"=>240, "\u0346"=>230, "\u0347"=>220,
- "\u0348"=>220, "\u0349"=>220, "\u034A"=>230, "\u034B"=>230, "\u034C"=>230, "\u034D"=>220, "\u034E"=>220, "\u0350"=>230,
- "\u0351"=>230, "\u0352"=>230, "\u0353"=>220, "\u0354"=>220, "\u0355"=>220, "\u0356"=>220, "\u0357"=>230, "\u0358"=>232,
- "\u0359"=>220, "\u035A"=>220, "\u035B"=>230, "\u035C"=>233, "\u035D"=>234, "\u035E"=>234, "\u035F"=>233, "\u0360"=>234,
- "\u0361"=>234, "\u0362"=>233, "\u0363"=>230, "\u0364"=>230, "\u0365"=>230, "\u0366"=>230, "\u0367"=>230, "\u0368"=>230,
- "\u0369"=>230, "\u036A"=>230, "\u036B"=>230, "\u036C"=>230, "\u036D"=>230, "\u036E"=>230, "\u036F"=>230, "\u0483"=>230,
- "\u0484"=>230, "\u0485"=>230, "\u0486"=>230, "\u0487"=>230, "\u0591"=>220, "\u0592"=>230, "\u0593"=>230, "\u0594"=>230,
- "\u0595"=>230, "\u0596"=>220, "\u0597"=>230, "\u0598"=>230, "\u0599"=>230, "\u059A"=>222, "\u059B"=>220, "\u059C"=>230,
- "\u059D"=>230, "\u059E"=>230, "\u059F"=>230, "\u05A0"=>230, "\u05A1"=>230, "\u05A2"=>220, "\u05A3"=>220, "\u05A4"=>220,
- "\u05A5"=>220, "\u05A6"=>220, "\u05A7"=>220, "\u05A8"=>230, "\u05A9"=>230, "\u05AA"=>220, "\u05AB"=>230, "\u05AC"=>230,
- "\u05AD"=>222, "\u05AE"=>228, "\u05AF"=>230, "\u05B0"=>10, "\u05B1"=>11, "\u05B2"=>12, "\u05B3"=>13, "\u05B4"=>14,
- "\u05B5"=>15, "\u05B6"=>16, "\u05B7"=>17, "\u05B8"=>18, "\u05B9"=>19, "\u05BA"=>19, "\u05BB"=>20, "\u05BC"=>21,
- "\u05BD"=>22, "\u05BF"=>23, "\u05C1"=>24, "\u05C2"=>25, "\u05C4"=>230, "\u05C5"=>220, "\u05C7"=>18, "\u0610"=>230,
- "\u0611"=>230, "\u0612"=>230, "\u0613"=>230, "\u0614"=>230, "\u0615"=>230, "\u0616"=>230, "\u0617"=>230, "\u0618"=>30,
- "\u0619"=>31, "\u061A"=>32, "\u064B"=>27, "\u064C"=>28, "\u064D"=>29, "\u064E"=>30, "\u064F"=>31, "\u0650"=>32,
- "\u0651"=>33, "\u0652"=>34, "\u0653"=>230, "\u0654"=>230, "\u0655"=>220, "\u0656"=>220, "\u0657"=>230, "\u0658"=>230,
- "\u0659"=>230, "\u065A"=>230, "\u065B"=>230, "\u065C"=>220, "\u065D"=>230, "\u065E"=>230, "\u065F"=>220, "\u0670"=>35,
- "\u06D6"=>230, "\u06D7"=>230, "\u06D8"=>230, "\u06D9"=>230, "\u06DA"=>230, "\u06DB"=>230, "\u06DC"=>230, "\u06DF"=>230,
- "\u06E0"=>230, "\u06E1"=>230, "\u06E2"=>230, "\u06E3"=>220, "\u06E4"=>230, "\u06E7"=>230, "\u06E8"=>230, "\u06EA"=>220,
- "\u06EB"=>230, "\u06EC"=>230, "\u06ED"=>220, "\u0711"=>36, "\u0730"=>230, "\u0731"=>220, "\u0732"=>230, "\u0733"=>230,
- "\u0734"=>220, "\u0735"=>230, "\u0736"=>230, "\u0737"=>220, "\u0738"=>220, "\u0739"=>220, "\u073A"=>230, "\u073B"=>220,
- "\u073C"=>220, "\u073D"=>230, "\u073E"=>220, "\u073F"=>230, "\u0740"=>230, "\u0741"=>230, "\u0742"=>220, "\u0743"=>230,
- "\u0744"=>220, "\u0745"=>230, "\u0746"=>220, "\u0747"=>230, "\u0748"=>220, "\u0749"=>230, "\u074A"=>230, "\u07EB"=>230,
- "\u07EC"=>230, "\u07ED"=>230, "\u07EE"=>230, "\u07EF"=>230, "\u07F0"=>230, "\u07F1"=>230, "\u07F2"=>220, "\u07F3"=>230,
- "\u0816"=>230, "\u0817"=>230, "\u0818"=>230, "\u0819"=>230, "\u081B"=>230, "\u081C"=>230, "\u081D"=>230, "\u081E"=>230,
- "\u081F"=>230, "\u0820"=>230, "\u0821"=>230, "\u0822"=>230, "\u0823"=>230, "\u0825"=>230, "\u0826"=>230, "\u0827"=>230,
- "\u0829"=>230, "\u082A"=>230, "\u082B"=>230, "\u082C"=>230, "\u082D"=>230, "\u0859"=>220, "\u085A"=>220, "\u085B"=>220,
- "\u08E4"=>230, "\u08E5"=>230, "\u08E6"=>220, "\u08E7"=>230, "\u08E8"=>230, "\u08E9"=>220, "\u08EA"=>230, "\u08EB"=>230,
- "\u08EC"=>230, "\u08ED"=>220, "\u08EE"=>220, "\u08EF"=>220, "\u08F0"=>27, "\u08F1"=>28, "\u08F2"=>29, "\u08F3"=>230,
- "\u08F4"=>230, "\u08F5"=>230, "\u08F6"=>220, "\u08F7"=>230, "\u08F8"=>230, "\u08F9"=>220, "\u08FA"=>220, "\u08FB"=>230,
- "\u08FC"=>230, "\u08FD"=>230, "\u08FE"=>230, "\u08FF"=>230, "\u093C"=>7, "\u094D"=>9, "\u0951"=>230, "\u0952"=>220,
- "\u0953"=>230, "\u0954"=>230, "\u09BC"=>7, "\u09CD"=>9, "\u0A3C"=>7, "\u0A4D"=>9, "\u0ABC"=>7, "\u0ACD"=>9,
- "\u0B3C"=>7, "\u0B4D"=>9, "\u0BCD"=>9, "\u0C4D"=>9, "\u0C55"=>84, "\u0C56"=>91, "\u0CBC"=>7, "\u0CCD"=>9,
- "\u0D4D"=>9, "\u0DCA"=>9, "\u0E38"=>103, "\u0E39"=>103, "\u0E3A"=>9, "\u0E48"=>107, "\u0E49"=>107, "\u0E4A"=>107,
- "\u0E4B"=>107, "\u0EB8"=>118, "\u0EB9"=>118, "\u0EC8"=>122, "\u0EC9"=>122, "\u0ECA"=>122, "\u0ECB"=>122, "\u0F18"=>220,
- "\u0F19"=>220, "\u0F35"=>220, "\u0F37"=>220, "\u0F39"=>216, "\u0F71"=>129, "\u0F72"=>130, "\u0F74"=>132, "\u0F7A"=>130,
- "\u0F7B"=>130, "\u0F7C"=>130, "\u0F7D"=>130, "\u0F80"=>130, "\u0F82"=>230, "\u0F83"=>230, "\u0F84"=>9, "\u0F86"=>230,
- "\u0F87"=>230, "\u0FC6"=>220, "\u1037"=>7, "\u1039"=>9, "\u103A"=>9, "\u108D"=>220, "\u135D"=>230, "\u135E"=>230,
- "\u135F"=>230, "\u1714"=>9, "\u1734"=>9, "\u17D2"=>9, "\u17DD"=>230, "\u18A9"=>228, "\u1939"=>222, "\u193A"=>230,
- "\u193B"=>220, "\u1A17"=>230, "\u1A18"=>220, "\u1A60"=>9, "\u1A75"=>230, "\u1A76"=>230, "\u1A77"=>230, "\u1A78"=>230,
- "\u1A79"=>230, "\u1A7A"=>230, "\u1A7B"=>230, "\u1A7C"=>230, "\u1A7F"=>220, "\u1AB0"=>230, "\u1AB1"=>230, "\u1AB2"=>230,
- "\u1AB3"=>230, "\u1AB4"=>230, "\u1AB5"=>220, "\u1AB6"=>220, "\u1AB7"=>220, "\u1AB8"=>220, "\u1AB9"=>220, "\u1ABA"=>220,
- "\u1ABB"=>230, "\u1ABC"=>230, "\u1ABD"=>220, "\u1B34"=>7, "\u1B44"=>9, "\u1B6B"=>230, "\u1B6C"=>220, "\u1B6D"=>230,
- "\u1B6E"=>230, "\u1B6F"=>230, "\u1B70"=>230, "\u1B71"=>230, "\u1B72"=>230, "\u1B73"=>230, "\u1BAA"=>9, "\u1BAB"=>9,
- "\u1BE6"=>7, "\u1BF2"=>9, "\u1BF3"=>9, "\u1C37"=>7, "\u1CD0"=>230, "\u1CD1"=>230, "\u1CD2"=>230, "\u1CD4"=>1,
- "\u1CD5"=>220, "\u1CD6"=>220, "\u1CD7"=>220, "\u1CD8"=>220, "\u1CD9"=>220, "\u1CDA"=>230, "\u1CDB"=>230, "\u1CDC"=>220,
- "\u1CDD"=>220, "\u1CDE"=>220, "\u1CDF"=>220, "\u1CE0"=>230, "\u1CE2"=>1, "\u1CE3"=>1, "\u1CE4"=>1, "\u1CE5"=>1,
- "\u1CE6"=>1, "\u1CE7"=>1, "\u1CE8"=>1, "\u1CED"=>220, "\u1CF4"=>230, "\u1CF8"=>230, "\u1CF9"=>230, "\u1DC0"=>230,
- "\u1DC1"=>230, "\u1DC2"=>220, "\u1DC3"=>230, "\u1DC4"=>230, "\u1DC5"=>230, "\u1DC6"=>230, "\u1DC7"=>230, "\u1DC8"=>230,
- "\u1DC9"=>230, "\u1DCA"=>220, "\u1DCB"=>230, "\u1DCC"=>230, "\u1DCD"=>234, "\u1DCE"=>214, "\u1DCF"=>220, "\u1DD0"=>202,
- "\u1DD1"=>230, "\u1DD2"=>230, "\u1DD3"=>230, "\u1DD4"=>230, "\u1DD5"=>230, "\u1DD6"=>230, "\u1DD7"=>230, "\u1DD8"=>230,
- "\u1DD9"=>230, "\u1DDA"=>230, "\u1DDB"=>230, "\u1DDC"=>230, "\u1DDD"=>230, "\u1DDE"=>230, "\u1DDF"=>230, "\u1DE0"=>230,
- "\u1DE1"=>230, "\u1DE2"=>230, "\u1DE3"=>230, "\u1DE4"=>230, "\u1DE5"=>230, "\u1DE6"=>230, "\u1DE7"=>230, "\u1DE8"=>230,
- "\u1DE9"=>230, "\u1DEA"=>230, "\u1DEB"=>230, "\u1DEC"=>230, "\u1DED"=>230, "\u1DEE"=>230, "\u1DEF"=>230, "\u1DF0"=>230,
- "\u1DF1"=>230, "\u1DF2"=>230, "\u1DF3"=>230, "\u1DF4"=>230, "\u1DF5"=>230, "\u1DFC"=>233, "\u1DFD"=>220, "\u1DFE"=>230,
- "\u1DFF"=>220, "\u20D0"=>230, "\u20D1"=>230, "\u20D2"=>1, "\u20D3"=>1, "\u20D4"=>230, "\u20D5"=>230, "\u20D6"=>230,
- "\u20D7"=>230, "\u20D8"=>1, "\u20D9"=>1, "\u20DA"=>1, "\u20DB"=>230, "\u20DC"=>230, "\u20E1"=>230, "\u20E5"=>1,
- "\u20E6"=>1, "\u20E7"=>230, "\u20E8"=>220, "\u20E9"=>230, "\u20EA"=>1, "\u20EB"=>1, "\u20EC"=>220, "\u20ED"=>220,
- "\u20EE"=>220, "\u20EF"=>220, "\u20F0"=>230, "\u2CEF"=>230, "\u2CF0"=>230, "\u2CF1"=>230, "\u2D7F"=>9, "\u2DE0"=>230,
- "\u2DE1"=>230, "\u2DE2"=>230, "\u2DE3"=>230, "\u2DE4"=>230, "\u2DE5"=>230, "\u2DE6"=>230, "\u2DE7"=>230, "\u2DE8"=>230,
- "\u2DE9"=>230, "\u2DEA"=>230, "\u2DEB"=>230, "\u2DEC"=>230, "\u2DED"=>230, "\u2DEE"=>230, "\u2DEF"=>230, "\u2DF0"=>230,
- "\u2DF1"=>230, "\u2DF2"=>230, "\u2DF3"=>230, "\u2DF4"=>230, "\u2DF5"=>230, "\u2DF6"=>230, "\u2DF7"=>230, "\u2DF8"=>230,
- "\u2DF9"=>230, "\u2DFA"=>230, "\u2DFB"=>230, "\u2DFC"=>230, "\u2DFD"=>230, "\u2DFE"=>230, "\u2DFF"=>230, "\u302A"=>218,
- "\u302B"=>228, "\u302C"=>232, "\u302D"=>222, "\u302E"=>224, "\u302F"=>224, "\u3099"=>8, "\u309A"=>8, "\uA66F"=>230,
- "\uA674"=>230, "\uA675"=>230, "\uA676"=>230, "\uA677"=>230, "\uA678"=>230, "\uA679"=>230, "\uA67A"=>230, "\uA67B"=>230,
- "\uA67C"=>230, "\uA67D"=>230, "\uA69F"=>230, "\uA6F0"=>230, "\uA6F1"=>230, "\uA806"=>9, "\uA8C4"=>9, "\uA8E0"=>230,
- "\uA8E1"=>230, "\uA8E2"=>230, "\uA8E3"=>230, "\uA8E4"=>230, "\uA8E5"=>230, "\uA8E6"=>230, "\uA8E7"=>230, "\uA8E8"=>230,
- "\uA8E9"=>230, "\uA8EA"=>230, "\uA8EB"=>230, "\uA8EC"=>230, "\uA8ED"=>230, "\uA8EE"=>230, "\uA8EF"=>230, "\uA8F0"=>230,
- "\uA8F1"=>230, "\uA92B"=>220, "\uA92C"=>220, "\uA92D"=>220, "\uA953"=>9, "\uA9B3"=>7, "\uA9C0"=>9, "\uAAB0"=>230,
- "\uAAB2"=>230, "\uAAB3"=>230, "\uAAB4"=>220, "\uAAB7"=>230, "\uAAB8"=>230, "\uAABE"=>230, "\uAABF"=>230, "\uAAC1"=>230,
- "\uAAF6"=>9, "\uABED"=>9, "\uFB1E"=>26, "\uFE20"=>230, "\uFE21"=>230, "\uFE22"=>230, "\uFE23"=>230, "\uFE24"=>230,
- "\uFE25"=>230, "\uFE26"=>230, "\uFE27"=>220, "\uFE28"=>220, "\uFE29"=>220, "\uFE2A"=>220, "\uFE2B"=>220, "\uFE2C"=>220,
- "\uFE2D"=>220, "\u{101FD}"=>220, "\u{102E0}"=>220, "\u{10376}"=>230, "\u{10377}"=>230, "\u{10378}"=>230, "\u{10379}"=>230, "\u{1037A}"=>230,
- "\u{10A0D}"=>220, "\u{10A0F}"=>230, "\u{10A38}"=>230, "\u{10A39}"=>1, "\u{10A3A}"=>220, "\u{10A3F}"=>9, "\u{10AE5}"=>230, "\u{10AE6}"=>220,
- "\u{11046}"=>9, "\u{1107F}"=>9, "\u{110B9}"=>9, "\u{110BA}"=>7, "\u{11100}"=>230, "\u{11101}"=>230, "\u{11102}"=>230, "\u{11133}"=>9,
- "\u{11134}"=>9, "\u{11173}"=>7, "\u{111C0}"=>9, "\u{11235}"=>9, "\u{11236}"=>7, "\u{112E9}"=>7, "\u{112EA}"=>9, "\u{1133C}"=>7,
- "\u{1134D}"=>9, "\u{11366}"=>230, "\u{11367}"=>230, "\u{11368}"=>230, "\u{11369}"=>230, "\u{1136A}"=>230, "\u{1136B}"=>230, "\u{1136C}"=>230,
- "\u{11370}"=>230, "\u{11371}"=>230, "\u{11372}"=>230, "\u{11373}"=>230, "\u{11374}"=>230, "\u{114C2}"=>9, "\u{114C3}"=>7, "\u{115BF}"=>9,
- "\u{115C0}"=>7, "\u{1163F}"=>9, "\u{116B6}"=>9, "\u{116B7}"=>7, "\u{16AF0}"=>1, "\u{16AF1}"=>1, "\u{16AF2}"=>1, "\u{16AF3}"=>1,
- "\u{16AF4}"=>1, "\u{16B30}"=>230, "\u{16B31}"=>230, "\u{16B32}"=>230, "\u{16B33}"=>230, "\u{16B34}"=>230, "\u{16B35}"=>230, "\u{16B36}"=>230,
- "\u{1BC9E}"=>1, "\u{1D165}"=>216, "\u{1D166}"=>216, "\u{1D167}"=>1, "\u{1D168}"=>1, "\u{1D169}"=>1, "\u{1D16D}"=>226, "\u{1D16E}"=>216,
- "\u{1D16F}"=>216, "\u{1D170}"=>216, "\u{1D171}"=>216, "\u{1D172}"=>216, "\u{1D17B}"=>220, "\u{1D17C}"=>220, "\u{1D17D}"=>220, "\u{1D17E}"=>220,
- "\u{1D17F}"=>220, "\u{1D180}"=>220, "\u{1D181}"=>220, "\u{1D182}"=>220, "\u{1D185}"=>230, "\u{1D186}"=>230, "\u{1D187}"=>230, "\u{1D188}"=>230,
- "\u{1D189}"=>230, "\u{1D18A}"=>220, "\u{1D18B}"=>220, "\u{1D1AA}"=>230, "\u{1D1AB}"=>230, "\u{1D1AC}"=>230, "\u{1D1AD}"=>230, "\u{1D242}"=>230,
- "\u{1D243}"=>230, "\u{1D244}"=>230, "\u{1E8D0}"=>220, "\u{1E8D1}"=>220, "\u{1E8D2}"=>220, "\u{1E8D3}"=>220, "\u{1E8D4}"=>220, "\u{1E8D5}"=>220,
- "\u{1E8D6}"=>220,
- }
- class_table.default = 0
- CLASS_TABLE = class_table.freeze
-
- DECOMPOSITION_TABLE = {
- "\u00C0"=>"A\u0300".freeze, "\u00C1"=>"A\u0301".freeze, "\u00C2"=>"A\u0302".freeze, "\u00C3"=>"A\u0303".freeze, "\u00C4"=>"A\u0308".freeze, "\u00C5"=>"A\u030A".freeze, "\u00C7"=>"C\u0327".freeze, "\u00C8"=>"E\u0300".freeze,
- "\u00C9"=>"E\u0301".freeze, "\u00CA"=>"E\u0302".freeze, "\u00CB"=>"E\u0308".freeze, "\u00CC"=>"I\u0300".freeze, "\u00CD"=>"I\u0301".freeze, "\u00CE"=>"I\u0302".freeze, "\u00CF"=>"I\u0308".freeze, "\u00D1"=>"N\u0303".freeze,
- "\u00D2"=>"O\u0300".freeze, "\u00D3"=>"O\u0301".freeze, "\u00D4"=>"O\u0302".freeze, "\u00D5"=>"O\u0303".freeze, "\u00D6"=>"O\u0308".freeze, "\u00D9"=>"U\u0300".freeze, "\u00DA"=>"U\u0301".freeze, "\u00DB"=>"U\u0302".freeze,
- "\u00DC"=>"U\u0308".freeze, "\u00DD"=>"Y\u0301".freeze, "\u00E0"=>"a\u0300".freeze, "\u00E1"=>"a\u0301".freeze, "\u00E2"=>"a\u0302".freeze, "\u00E3"=>"a\u0303".freeze, "\u00E4"=>"a\u0308".freeze, "\u00E5"=>"a\u030A".freeze,
- "\u00E7"=>"c\u0327".freeze, "\u00E8"=>"e\u0300".freeze, "\u00E9"=>"e\u0301".freeze, "\u00EA"=>"e\u0302".freeze, "\u00EB"=>"e\u0308".freeze, "\u00EC"=>"i\u0300".freeze, "\u00ED"=>"i\u0301".freeze, "\u00EE"=>"i\u0302".freeze,
- "\u00EF"=>"i\u0308".freeze, "\u00F1"=>"n\u0303".freeze, "\u00F2"=>"o\u0300".freeze, "\u00F3"=>"o\u0301".freeze, "\u00F4"=>"o\u0302".freeze, "\u00F5"=>"o\u0303".freeze, "\u00F6"=>"o\u0308".freeze, "\u00F9"=>"u\u0300".freeze,
- "\u00FA"=>"u\u0301".freeze, "\u00FB"=>"u\u0302".freeze, "\u00FC"=>"u\u0308".freeze, "\u00FD"=>"y\u0301".freeze, "\u00FF"=>"y\u0308".freeze, "\u0100"=>"A\u0304".freeze, "\u0101"=>"a\u0304".freeze, "\u0102"=>"A\u0306".freeze,
- "\u0103"=>"a\u0306".freeze, "\u0104"=>"A\u0328".freeze, "\u0105"=>"a\u0328".freeze, "\u0106"=>"C\u0301".freeze, "\u0107"=>"c\u0301".freeze, "\u0108"=>"C\u0302".freeze, "\u0109"=>"c\u0302".freeze, "\u010A"=>"C\u0307".freeze,
- "\u010B"=>"c\u0307".freeze, "\u010C"=>"C\u030C".freeze, "\u010D"=>"c\u030C".freeze, "\u010E"=>"D\u030C".freeze, "\u010F"=>"d\u030C".freeze, "\u0112"=>"E\u0304".freeze, "\u0113"=>"e\u0304".freeze, "\u0114"=>"E\u0306".freeze,
- "\u0115"=>"e\u0306".freeze, "\u0116"=>"E\u0307".freeze, "\u0117"=>"e\u0307".freeze, "\u0118"=>"E\u0328".freeze, "\u0119"=>"e\u0328".freeze, "\u011A"=>"E\u030C".freeze, "\u011B"=>"e\u030C".freeze, "\u011C"=>"G\u0302".freeze,
- "\u011D"=>"g\u0302".freeze, "\u011E"=>"G\u0306".freeze, "\u011F"=>"g\u0306".freeze, "\u0120"=>"G\u0307".freeze, "\u0121"=>"g\u0307".freeze, "\u0122"=>"G\u0327".freeze, "\u0123"=>"g\u0327".freeze, "\u0124"=>"H\u0302".freeze,
- "\u0125"=>"h\u0302".freeze, "\u0128"=>"I\u0303".freeze, "\u0129"=>"i\u0303".freeze, "\u012A"=>"I\u0304".freeze, "\u012B"=>"i\u0304".freeze, "\u012C"=>"I\u0306".freeze, "\u012D"=>"i\u0306".freeze, "\u012E"=>"I\u0328".freeze,
- "\u012F"=>"i\u0328".freeze, "\u0130"=>"I\u0307".freeze, "\u0134"=>"J\u0302".freeze, "\u0135"=>"j\u0302".freeze, "\u0136"=>"K\u0327".freeze, "\u0137"=>"k\u0327".freeze, "\u0139"=>"L\u0301".freeze, "\u013A"=>"l\u0301".freeze,
- "\u013B"=>"L\u0327".freeze, "\u013C"=>"l\u0327".freeze, "\u013D"=>"L\u030C".freeze, "\u013E"=>"l\u030C".freeze, "\u0143"=>"N\u0301".freeze, "\u0144"=>"n\u0301".freeze, "\u0145"=>"N\u0327".freeze, "\u0146"=>"n\u0327".freeze,
- "\u0147"=>"N\u030C".freeze, "\u0148"=>"n\u030C".freeze, "\u014C"=>"O\u0304".freeze, "\u014D"=>"o\u0304".freeze, "\u014E"=>"O\u0306".freeze, "\u014F"=>"o\u0306".freeze, "\u0150"=>"O\u030B".freeze, "\u0151"=>"o\u030B".freeze,
- "\u0154"=>"R\u0301".freeze, "\u0155"=>"r\u0301".freeze, "\u0156"=>"R\u0327".freeze, "\u0157"=>"r\u0327".freeze, "\u0158"=>"R\u030C".freeze, "\u0159"=>"r\u030C".freeze, "\u015A"=>"S\u0301".freeze, "\u015B"=>"s\u0301".freeze,
- "\u015C"=>"S\u0302".freeze, "\u015D"=>"s\u0302".freeze, "\u015E"=>"S\u0327".freeze, "\u015F"=>"s\u0327".freeze, "\u0160"=>"S\u030C".freeze, "\u0161"=>"s\u030C".freeze, "\u0162"=>"T\u0327".freeze, "\u0163"=>"t\u0327".freeze,
- "\u0164"=>"T\u030C".freeze, "\u0165"=>"t\u030C".freeze, "\u0168"=>"U\u0303".freeze, "\u0169"=>"u\u0303".freeze, "\u016A"=>"U\u0304".freeze, "\u016B"=>"u\u0304".freeze, "\u016C"=>"U\u0306".freeze, "\u016D"=>"u\u0306".freeze,
- "\u016E"=>"U\u030A".freeze, "\u016F"=>"u\u030A".freeze, "\u0170"=>"U\u030B".freeze, "\u0171"=>"u\u030B".freeze, "\u0172"=>"U\u0328".freeze, "\u0173"=>"u\u0328".freeze, "\u0174"=>"W\u0302".freeze, "\u0175"=>"w\u0302".freeze,
- "\u0176"=>"Y\u0302".freeze, "\u0177"=>"y\u0302".freeze, "\u0178"=>"Y\u0308".freeze, "\u0179"=>"Z\u0301".freeze, "\u017A"=>"z\u0301".freeze, "\u017B"=>"Z\u0307".freeze, "\u017C"=>"z\u0307".freeze, "\u017D"=>"Z\u030C".freeze,
- "\u017E"=>"z\u030C".freeze, "\u01A0"=>"O\u031B".freeze, "\u01A1"=>"o\u031B".freeze, "\u01AF"=>"U\u031B".freeze, "\u01B0"=>"u\u031B".freeze, "\u01CD"=>"A\u030C".freeze, "\u01CE"=>"a\u030C".freeze, "\u01CF"=>"I\u030C".freeze,
- "\u01D0"=>"i\u030C".freeze, "\u01D1"=>"O\u030C".freeze, "\u01D2"=>"o\u030C".freeze, "\u01D3"=>"U\u030C".freeze, "\u01D4"=>"u\u030C".freeze, "\u01D5"=>"U\u0308\u0304".freeze, "\u01D6"=>"u\u0308\u0304".freeze, "\u01D7"=>"U\u0308\u0301".freeze,
- "\u01D8"=>"u\u0308\u0301".freeze, "\u01D9"=>"U\u0308\u030C".freeze, "\u01DA"=>"u\u0308\u030C".freeze, "\u01DB"=>"U\u0308\u0300".freeze, "\u01DC"=>"u\u0308\u0300".freeze, "\u01DE"=>"A\u0308\u0304".freeze, "\u01DF"=>"a\u0308\u0304".freeze, "\u01E0"=>"A\u0307\u0304".freeze,
- "\u01E1"=>"a\u0307\u0304".freeze, "\u01E2"=>"\u00C6\u0304".freeze, "\u01E3"=>"\u00E6\u0304".freeze, "\u01E6"=>"G\u030C".freeze, "\u01E7"=>"g\u030C".freeze, "\u01E8"=>"K\u030C".freeze, "\u01E9"=>"k\u030C".freeze, "\u01EA"=>"O\u0328".freeze,
- "\u01EB"=>"o\u0328".freeze, "\u01EC"=>"O\u0328\u0304".freeze, "\u01ED"=>"o\u0328\u0304".freeze, "\u01EE"=>"\u01B7\u030C".freeze, "\u01EF"=>"\u0292\u030C".freeze, "\u01F0"=>"j\u030C".freeze, "\u01F4"=>"G\u0301".freeze, "\u01F5"=>"g\u0301".freeze,
- "\u01F8"=>"N\u0300".freeze, "\u01F9"=>"n\u0300".freeze, "\u01FA"=>"A\u030A\u0301".freeze, "\u01FB"=>"a\u030A\u0301".freeze, "\u01FC"=>"\u00C6\u0301".freeze, "\u01FD"=>"\u00E6\u0301".freeze, "\u01FE"=>"\u00D8\u0301".freeze, "\u01FF"=>"\u00F8\u0301".freeze,
- "\u0200"=>"A\u030F".freeze, "\u0201"=>"a\u030F".freeze, "\u0202"=>"A\u0311".freeze, "\u0203"=>"a\u0311".freeze, "\u0204"=>"E\u030F".freeze, "\u0205"=>"e\u030F".freeze, "\u0206"=>"E\u0311".freeze, "\u0207"=>"e\u0311".freeze,
- "\u0208"=>"I\u030F".freeze, "\u0209"=>"i\u030F".freeze, "\u020A"=>"I\u0311".freeze, "\u020B"=>"i\u0311".freeze, "\u020C"=>"O\u030F".freeze, "\u020D"=>"o\u030F".freeze, "\u020E"=>"O\u0311".freeze, "\u020F"=>"o\u0311".freeze,
- "\u0210"=>"R\u030F".freeze, "\u0211"=>"r\u030F".freeze, "\u0212"=>"R\u0311".freeze, "\u0213"=>"r\u0311".freeze, "\u0214"=>"U\u030F".freeze, "\u0215"=>"u\u030F".freeze, "\u0216"=>"U\u0311".freeze, "\u0217"=>"u\u0311".freeze,
- "\u0218"=>"S\u0326".freeze, "\u0219"=>"s\u0326".freeze, "\u021A"=>"T\u0326".freeze, "\u021B"=>"t\u0326".freeze, "\u021E"=>"H\u030C".freeze, "\u021F"=>"h\u030C".freeze, "\u0226"=>"A\u0307".freeze, "\u0227"=>"a\u0307".freeze,
- "\u0228"=>"E\u0327".freeze, "\u0229"=>"e\u0327".freeze, "\u022A"=>"O\u0308\u0304".freeze, "\u022B"=>"o\u0308\u0304".freeze, "\u022C"=>"O\u0303\u0304".freeze, "\u022D"=>"o\u0303\u0304".freeze, "\u022E"=>"O\u0307".freeze, "\u022F"=>"o\u0307".freeze,
- "\u0230"=>"O\u0307\u0304".freeze, "\u0231"=>"o\u0307\u0304".freeze, "\u0232"=>"Y\u0304".freeze, "\u0233"=>"y\u0304".freeze, "\u0340"=>"\u0300".freeze, "\u0341"=>"\u0301".freeze, "\u0343"=>"\u0313".freeze, "\u0344"=>"\u0308\u0301".freeze,
- "\u0374"=>"\u02B9".freeze, "\u037E"=>";".freeze, "\u0385"=>"\u00A8\u0301".freeze, "\u0386"=>"\u0391\u0301".freeze, "\u0387"=>"\u00B7".freeze, "\u0388"=>"\u0395\u0301".freeze, "\u0389"=>"\u0397\u0301".freeze, "\u038A"=>"\u0399\u0301".freeze,
- "\u038C"=>"\u039F\u0301".freeze, "\u038E"=>"\u03A5\u0301".freeze, "\u038F"=>"\u03A9\u0301".freeze, "\u0390"=>"\u03B9\u0308\u0301".freeze, "\u03AA"=>"\u0399\u0308".freeze, "\u03AB"=>"\u03A5\u0308".freeze, "\u03AC"=>"\u03B1\u0301".freeze, "\u03AD"=>"\u03B5\u0301".freeze,
- "\u03AE"=>"\u03B7\u0301".freeze, "\u03AF"=>"\u03B9\u0301".freeze, "\u03B0"=>"\u03C5\u0308\u0301".freeze, "\u03CA"=>"\u03B9\u0308".freeze, "\u03CB"=>"\u03C5\u0308".freeze, "\u03CC"=>"\u03BF\u0301".freeze, "\u03CD"=>"\u03C5\u0301".freeze, "\u03CE"=>"\u03C9\u0301".freeze,
- "\u03D3"=>"\u03D2\u0301".freeze, "\u03D4"=>"\u03D2\u0308".freeze, "\u0400"=>"\u0415\u0300".freeze, "\u0401"=>"\u0415\u0308".freeze, "\u0403"=>"\u0413\u0301".freeze, "\u0407"=>"\u0406\u0308".freeze, "\u040C"=>"\u041A\u0301".freeze, "\u040D"=>"\u0418\u0300".freeze,
- "\u040E"=>"\u0423\u0306".freeze, "\u0419"=>"\u0418\u0306".freeze, "\u0439"=>"\u0438\u0306".freeze, "\u0450"=>"\u0435\u0300".freeze, "\u0451"=>"\u0435\u0308".freeze, "\u0453"=>"\u0433\u0301".freeze, "\u0457"=>"\u0456\u0308".freeze, "\u045C"=>"\u043A\u0301".freeze,
- "\u045D"=>"\u0438\u0300".freeze, "\u045E"=>"\u0443\u0306".freeze, "\u0476"=>"\u0474\u030F".freeze, "\u0477"=>"\u0475\u030F".freeze, "\u04C1"=>"\u0416\u0306".freeze, "\u04C2"=>"\u0436\u0306".freeze, "\u04D0"=>"\u0410\u0306".freeze, "\u04D1"=>"\u0430\u0306".freeze,
- "\u04D2"=>"\u0410\u0308".freeze, "\u04D3"=>"\u0430\u0308".freeze, "\u04D6"=>"\u0415\u0306".freeze, "\u04D7"=>"\u0435\u0306".freeze, "\u04DA"=>"\u04D8\u0308".freeze, "\u04DB"=>"\u04D9\u0308".freeze, "\u04DC"=>"\u0416\u0308".freeze, "\u04DD"=>"\u0436\u0308".freeze,
- "\u04DE"=>"\u0417\u0308".freeze, "\u04DF"=>"\u0437\u0308".freeze, "\u04E2"=>"\u0418\u0304".freeze, "\u04E3"=>"\u0438\u0304".freeze, "\u04E4"=>"\u0418\u0308".freeze, "\u04E5"=>"\u0438\u0308".freeze, "\u04E6"=>"\u041E\u0308".freeze, "\u04E7"=>"\u043E\u0308".freeze,
- "\u04EA"=>"\u04E8\u0308".freeze, "\u04EB"=>"\u04E9\u0308".freeze, "\u04EC"=>"\u042D\u0308".freeze, "\u04ED"=>"\u044D\u0308".freeze, "\u04EE"=>"\u0423\u0304".freeze, "\u04EF"=>"\u0443\u0304".freeze, "\u04F0"=>"\u0423\u0308".freeze, "\u04F1"=>"\u0443\u0308".freeze,
- "\u04F2"=>"\u0423\u030B".freeze, "\u04F3"=>"\u0443\u030B".freeze, "\u04F4"=>"\u0427\u0308".freeze, "\u04F5"=>"\u0447\u0308".freeze, "\u04F8"=>"\u042B\u0308".freeze, "\u04F9"=>"\u044B\u0308".freeze, "\u0622"=>"\u0627\u0653".freeze, "\u0623"=>"\u0627\u0654".freeze,
- "\u0624"=>"\u0648\u0654".freeze, "\u0625"=>"\u0627\u0655".freeze, "\u0626"=>"\u064A\u0654".freeze, "\u06C0"=>"\u06D5\u0654".freeze, "\u06C2"=>"\u06C1\u0654".freeze, "\u06D3"=>"\u06D2\u0654".freeze, "\u0929"=>"\u0928\u093C".freeze, "\u0931"=>"\u0930\u093C".freeze,
- "\u0934"=>"\u0933\u093C".freeze, "\u0958"=>"\u0915\u093C".freeze, "\u0959"=>"\u0916\u093C".freeze, "\u095A"=>"\u0917\u093C".freeze, "\u095B"=>"\u091C\u093C".freeze, "\u095C"=>"\u0921\u093C".freeze, "\u095D"=>"\u0922\u093C".freeze, "\u095E"=>"\u092B\u093C".freeze,
- "\u095F"=>"\u092F\u093C".freeze, "\u09CB"=>"\u09C7\u09BE".freeze, "\u09CC"=>"\u09C7\u09D7".freeze, "\u09DC"=>"\u09A1\u09BC".freeze, "\u09DD"=>"\u09A2\u09BC".freeze, "\u09DF"=>"\u09AF\u09BC".freeze, "\u0A33"=>"\u0A32\u0A3C".freeze, "\u0A36"=>"\u0A38\u0A3C".freeze,
- "\u0A59"=>"\u0A16\u0A3C".freeze, "\u0A5A"=>"\u0A17\u0A3C".freeze, "\u0A5B"=>"\u0A1C\u0A3C".freeze, "\u0A5E"=>"\u0A2B\u0A3C".freeze, "\u0B48"=>"\u0B47\u0B56".freeze, "\u0B4B"=>"\u0B47\u0B3E".freeze, "\u0B4C"=>"\u0B47\u0B57".freeze, "\u0B5C"=>"\u0B21\u0B3C".freeze,
- "\u0B5D"=>"\u0B22\u0B3C".freeze, "\u0B94"=>"\u0B92\u0BD7".freeze, "\u0BCA"=>"\u0BC6\u0BBE".freeze, "\u0BCB"=>"\u0BC7\u0BBE".freeze, "\u0BCC"=>"\u0BC6\u0BD7".freeze, "\u0C48"=>"\u0C46\u0C56".freeze, "\u0CC0"=>"\u0CBF\u0CD5".freeze, "\u0CC7"=>"\u0CC6\u0CD5".freeze,
- "\u0CC8"=>"\u0CC6\u0CD6".freeze, "\u0CCA"=>"\u0CC6\u0CC2".freeze, "\u0CCB"=>"\u0CC6\u0CC2\u0CD5".freeze, "\u0D4A"=>"\u0D46\u0D3E".freeze, "\u0D4B"=>"\u0D47\u0D3E".freeze, "\u0D4C"=>"\u0D46\u0D57".freeze, "\u0DDA"=>"\u0DD9\u0DCA".freeze, "\u0DDC"=>"\u0DD9\u0DCF".freeze,
- "\u0DDD"=>"\u0DD9\u0DCF\u0DCA".freeze, "\u0DDE"=>"\u0DD9\u0DDF".freeze, "\u0F43"=>"\u0F42\u0FB7".freeze, "\u0F4D"=>"\u0F4C\u0FB7".freeze, "\u0F52"=>"\u0F51\u0FB7".freeze, "\u0F57"=>"\u0F56\u0FB7".freeze, "\u0F5C"=>"\u0F5B\u0FB7".freeze, "\u0F69"=>"\u0F40\u0FB5".freeze,
- "\u0F73"=>"\u0F71\u0F72".freeze, "\u0F75"=>"\u0F71\u0F74".freeze, "\u0F76"=>"\u0FB2\u0F80".freeze, "\u0F78"=>"\u0FB3\u0F80".freeze, "\u0F81"=>"\u0F71\u0F80".freeze, "\u0F93"=>"\u0F92\u0FB7".freeze, "\u0F9D"=>"\u0F9C\u0FB7".freeze, "\u0FA2"=>"\u0FA1\u0FB7".freeze,
- "\u0FA7"=>"\u0FA6\u0FB7".freeze, "\u0FAC"=>"\u0FAB\u0FB7".freeze, "\u0FB9"=>"\u0F90\u0FB5".freeze, "\u1026"=>"\u1025\u102E".freeze, "\u1B06"=>"\u1B05\u1B35".freeze, "\u1B08"=>"\u1B07\u1B35".freeze, "\u1B0A"=>"\u1B09\u1B35".freeze, "\u1B0C"=>"\u1B0B\u1B35".freeze,
- "\u1B0E"=>"\u1B0D\u1B35".freeze, "\u1B12"=>"\u1B11\u1B35".freeze, "\u1B3B"=>"\u1B3A\u1B35".freeze, "\u1B3D"=>"\u1B3C\u1B35".freeze, "\u1B40"=>"\u1B3E\u1B35".freeze, "\u1B41"=>"\u1B3F\u1B35".freeze, "\u1B43"=>"\u1B42\u1B35".freeze, "\u1E00"=>"A\u0325".freeze,
- "\u1E01"=>"a\u0325".freeze, "\u1E02"=>"B\u0307".freeze, "\u1E03"=>"b\u0307".freeze, "\u1E04"=>"B\u0323".freeze, "\u1E05"=>"b\u0323".freeze, "\u1E06"=>"B\u0331".freeze, "\u1E07"=>"b\u0331".freeze, "\u1E08"=>"C\u0327\u0301".freeze,
- "\u1E09"=>"c\u0327\u0301".freeze, "\u1E0A"=>"D\u0307".freeze, "\u1E0B"=>"d\u0307".freeze, "\u1E0C"=>"D\u0323".freeze, "\u1E0D"=>"d\u0323".freeze, "\u1E0E"=>"D\u0331".freeze, "\u1E0F"=>"d\u0331".freeze, "\u1E10"=>"D\u0327".freeze,
- "\u1E11"=>"d\u0327".freeze, "\u1E12"=>"D\u032D".freeze, "\u1E13"=>"d\u032D".freeze, "\u1E14"=>"E\u0304\u0300".freeze, "\u1E15"=>"e\u0304\u0300".freeze, "\u1E16"=>"E\u0304\u0301".freeze, "\u1E17"=>"e\u0304\u0301".freeze, "\u1E18"=>"E\u032D".freeze,
- "\u1E19"=>"e\u032D".freeze, "\u1E1A"=>"E\u0330".freeze, "\u1E1B"=>"e\u0330".freeze, "\u1E1C"=>"E\u0327\u0306".freeze, "\u1E1D"=>"e\u0327\u0306".freeze, "\u1E1E"=>"F\u0307".freeze, "\u1E1F"=>"f\u0307".freeze, "\u1E20"=>"G\u0304".freeze,
- "\u1E21"=>"g\u0304".freeze, "\u1E22"=>"H\u0307".freeze, "\u1E23"=>"h\u0307".freeze, "\u1E24"=>"H\u0323".freeze, "\u1E25"=>"h\u0323".freeze, "\u1E26"=>"H\u0308".freeze, "\u1E27"=>"h\u0308".freeze, "\u1E28"=>"H\u0327".freeze,
- "\u1E29"=>"h\u0327".freeze, "\u1E2A"=>"H\u032E".freeze, "\u1E2B"=>"h\u032E".freeze, "\u1E2C"=>"I\u0330".freeze, "\u1E2D"=>"i\u0330".freeze, "\u1E2E"=>"I\u0308\u0301".freeze, "\u1E2F"=>"i\u0308\u0301".freeze, "\u1E30"=>"K\u0301".freeze,
- "\u1E31"=>"k\u0301".freeze, "\u1E32"=>"K\u0323".freeze, "\u1E33"=>"k\u0323".freeze, "\u1E34"=>"K\u0331".freeze, "\u1E35"=>"k\u0331".freeze, "\u1E36"=>"L\u0323".freeze, "\u1E37"=>"l\u0323".freeze, "\u1E38"=>"L\u0323\u0304".freeze,
- "\u1E39"=>"l\u0323\u0304".freeze, "\u1E3A"=>"L\u0331".freeze, "\u1E3B"=>"l\u0331".freeze, "\u1E3C"=>"L\u032D".freeze, "\u1E3D"=>"l\u032D".freeze, "\u1E3E"=>"M\u0301".freeze, "\u1E3F"=>"m\u0301".freeze, "\u1E40"=>"M\u0307".freeze,
- "\u1E41"=>"m\u0307".freeze, "\u1E42"=>"M\u0323".freeze, "\u1E43"=>"m\u0323".freeze, "\u1E44"=>"N\u0307".freeze, "\u1E45"=>"n\u0307".freeze, "\u1E46"=>"N\u0323".freeze, "\u1E47"=>"n\u0323".freeze, "\u1E48"=>"N\u0331".freeze,
- "\u1E49"=>"n\u0331".freeze, "\u1E4A"=>"N\u032D".freeze, "\u1E4B"=>"n\u032D".freeze, "\u1E4C"=>"O\u0303\u0301".freeze, "\u1E4D"=>"o\u0303\u0301".freeze, "\u1E4E"=>"O\u0303\u0308".freeze, "\u1E4F"=>"o\u0303\u0308".freeze, "\u1E50"=>"O\u0304\u0300".freeze,
- "\u1E51"=>"o\u0304\u0300".freeze, "\u1E52"=>"O\u0304\u0301".freeze, "\u1E53"=>"o\u0304\u0301".freeze, "\u1E54"=>"P\u0301".freeze, "\u1E55"=>"p\u0301".freeze, "\u1E56"=>"P\u0307".freeze, "\u1E57"=>"p\u0307".freeze, "\u1E58"=>"R\u0307".freeze,
- "\u1E59"=>"r\u0307".freeze, "\u1E5A"=>"R\u0323".freeze, "\u1E5B"=>"r\u0323".freeze, "\u1E5C"=>"R\u0323\u0304".freeze, "\u1E5D"=>"r\u0323\u0304".freeze, "\u1E5E"=>"R\u0331".freeze, "\u1E5F"=>"r\u0331".freeze, "\u1E60"=>"S\u0307".freeze,
- "\u1E61"=>"s\u0307".freeze, "\u1E62"=>"S\u0323".freeze, "\u1E63"=>"s\u0323".freeze, "\u1E64"=>"S\u0301\u0307".freeze, "\u1E65"=>"s\u0301\u0307".freeze, "\u1E66"=>"S\u030C\u0307".freeze, "\u1E67"=>"s\u030C\u0307".freeze, "\u1E68"=>"S\u0323\u0307".freeze,
- "\u1E69"=>"s\u0323\u0307".freeze, "\u1E6A"=>"T\u0307".freeze, "\u1E6B"=>"t\u0307".freeze, "\u1E6C"=>"T\u0323".freeze, "\u1E6D"=>"t\u0323".freeze, "\u1E6E"=>"T\u0331".freeze, "\u1E6F"=>"t\u0331".freeze, "\u1E70"=>"T\u032D".freeze,
- "\u1E71"=>"t\u032D".freeze, "\u1E72"=>"U\u0324".freeze, "\u1E73"=>"u\u0324".freeze, "\u1E74"=>"U\u0330".freeze, "\u1E75"=>"u\u0330".freeze, "\u1E76"=>"U\u032D".freeze, "\u1E77"=>"u\u032D".freeze, "\u1E78"=>"U\u0303\u0301".freeze,
- "\u1E79"=>"u\u0303\u0301".freeze, "\u1E7A"=>"U\u0304\u0308".freeze, "\u1E7B"=>"u\u0304\u0308".freeze, "\u1E7C"=>"V\u0303".freeze, "\u1E7D"=>"v\u0303".freeze, "\u1E7E"=>"V\u0323".freeze, "\u1E7F"=>"v\u0323".freeze, "\u1E80"=>"W\u0300".freeze,
- "\u1E81"=>"w\u0300".freeze, "\u1E82"=>"W\u0301".freeze, "\u1E83"=>"w\u0301".freeze, "\u1E84"=>"W\u0308".freeze, "\u1E85"=>"w\u0308".freeze, "\u1E86"=>"W\u0307".freeze, "\u1E87"=>"w\u0307".freeze, "\u1E88"=>"W\u0323".freeze,
- "\u1E89"=>"w\u0323".freeze, "\u1E8A"=>"X\u0307".freeze, "\u1E8B"=>"x\u0307".freeze, "\u1E8C"=>"X\u0308".freeze, "\u1E8D"=>"x\u0308".freeze, "\u1E8E"=>"Y\u0307".freeze, "\u1E8F"=>"y\u0307".freeze, "\u1E90"=>"Z\u0302".freeze,
- "\u1E91"=>"z\u0302".freeze, "\u1E92"=>"Z\u0323".freeze, "\u1E93"=>"z\u0323".freeze, "\u1E94"=>"Z\u0331".freeze, "\u1E95"=>"z\u0331".freeze, "\u1E96"=>"h\u0331".freeze, "\u1E97"=>"t\u0308".freeze, "\u1E98"=>"w\u030A".freeze,
- "\u1E99"=>"y\u030A".freeze, "\u1E9B"=>"\u017F\u0307".freeze, "\u1EA0"=>"A\u0323".freeze, "\u1EA1"=>"a\u0323".freeze, "\u1EA2"=>"A\u0309".freeze, "\u1EA3"=>"a\u0309".freeze, "\u1EA4"=>"A\u0302\u0301".freeze, "\u1EA5"=>"a\u0302\u0301".freeze,
- "\u1EA6"=>"A\u0302\u0300".freeze, "\u1EA7"=>"a\u0302\u0300".freeze, "\u1EA8"=>"A\u0302\u0309".freeze, "\u1EA9"=>"a\u0302\u0309".freeze, "\u1EAA"=>"A\u0302\u0303".freeze, "\u1EAB"=>"a\u0302\u0303".freeze, "\u1EAC"=>"A\u0323\u0302".freeze, "\u1EAD"=>"a\u0323\u0302".freeze,
- "\u1EAE"=>"A\u0306\u0301".freeze, "\u1EAF"=>"a\u0306\u0301".freeze, "\u1EB0"=>"A\u0306\u0300".freeze, "\u1EB1"=>"a\u0306\u0300".freeze, "\u1EB2"=>"A\u0306\u0309".freeze, "\u1EB3"=>"a\u0306\u0309".freeze, "\u1EB4"=>"A\u0306\u0303".freeze, "\u1EB5"=>"a\u0306\u0303".freeze,
- "\u1EB6"=>"A\u0323\u0306".freeze, "\u1EB7"=>"a\u0323\u0306".freeze, "\u1EB8"=>"E\u0323".freeze, "\u1EB9"=>"e\u0323".freeze, "\u1EBA"=>"E\u0309".freeze, "\u1EBB"=>"e\u0309".freeze, "\u1EBC"=>"E\u0303".freeze, "\u1EBD"=>"e\u0303".freeze,
- "\u1EBE"=>"E\u0302\u0301".freeze, "\u1EBF"=>"e\u0302\u0301".freeze, "\u1EC0"=>"E\u0302\u0300".freeze, "\u1EC1"=>"e\u0302\u0300".freeze, "\u1EC2"=>"E\u0302\u0309".freeze, "\u1EC3"=>"e\u0302\u0309".freeze, "\u1EC4"=>"E\u0302\u0303".freeze, "\u1EC5"=>"e\u0302\u0303".freeze,
- "\u1EC6"=>"E\u0323\u0302".freeze, "\u1EC7"=>"e\u0323\u0302".freeze, "\u1EC8"=>"I\u0309".freeze, "\u1EC9"=>"i\u0309".freeze, "\u1ECA"=>"I\u0323".freeze, "\u1ECB"=>"i\u0323".freeze, "\u1ECC"=>"O\u0323".freeze, "\u1ECD"=>"o\u0323".freeze,
- "\u1ECE"=>"O\u0309".freeze, "\u1ECF"=>"o\u0309".freeze, "\u1ED0"=>"O\u0302\u0301".freeze, "\u1ED1"=>"o\u0302\u0301".freeze, "\u1ED2"=>"O\u0302\u0300".freeze, "\u1ED3"=>"o\u0302\u0300".freeze, "\u1ED4"=>"O\u0302\u0309".freeze, "\u1ED5"=>"o\u0302\u0309".freeze,
- "\u1ED6"=>"O\u0302\u0303".freeze, "\u1ED7"=>"o\u0302\u0303".freeze, "\u1ED8"=>"O\u0323\u0302".freeze, "\u1ED9"=>"o\u0323\u0302".freeze, "\u1EDA"=>"O\u031B\u0301".freeze, "\u1EDB"=>"o\u031B\u0301".freeze, "\u1EDC"=>"O\u031B\u0300".freeze, "\u1EDD"=>"o\u031B\u0300".freeze,
- "\u1EDE"=>"O\u031B\u0309".freeze, "\u1EDF"=>"o\u031B\u0309".freeze, "\u1EE0"=>"O\u031B\u0303".freeze, "\u1EE1"=>"o\u031B\u0303".freeze, "\u1EE2"=>"O\u031B\u0323".freeze, "\u1EE3"=>"o\u031B\u0323".freeze, "\u1EE4"=>"U\u0323".freeze, "\u1EE5"=>"u\u0323".freeze,
- "\u1EE6"=>"U\u0309".freeze, "\u1EE7"=>"u\u0309".freeze, "\u1EE8"=>"U\u031B\u0301".freeze, "\u1EE9"=>"u\u031B\u0301".freeze, "\u1EEA"=>"U\u031B\u0300".freeze, "\u1EEB"=>"u\u031B\u0300".freeze, "\u1EEC"=>"U\u031B\u0309".freeze, "\u1EED"=>"u\u031B\u0309".freeze,
- "\u1EEE"=>"U\u031B\u0303".freeze, "\u1EEF"=>"u\u031B\u0303".freeze, "\u1EF0"=>"U\u031B\u0323".freeze, "\u1EF1"=>"u\u031B\u0323".freeze, "\u1EF2"=>"Y\u0300".freeze, "\u1EF3"=>"y\u0300".freeze, "\u1EF4"=>"Y\u0323".freeze, "\u1EF5"=>"y\u0323".freeze,
- "\u1EF6"=>"Y\u0309".freeze, "\u1EF7"=>"y\u0309".freeze, "\u1EF8"=>"Y\u0303".freeze, "\u1EF9"=>"y\u0303".freeze, "\u1F00"=>"\u03B1\u0313".freeze, "\u1F01"=>"\u03B1\u0314".freeze, "\u1F02"=>"\u03B1\u0313\u0300".freeze, "\u1F03"=>"\u03B1\u0314\u0300".freeze,
- "\u1F04"=>"\u03B1\u0313\u0301".freeze, "\u1F05"=>"\u03B1\u0314\u0301".freeze, "\u1F06"=>"\u03B1\u0313\u0342".freeze, "\u1F07"=>"\u03B1\u0314\u0342".freeze, "\u1F08"=>"\u0391\u0313".freeze, "\u1F09"=>"\u0391\u0314".freeze, "\u1F0A"=>"\u0391\u0313\u0300".freeze, "\u1F0B"=>"\u0391\u0314\u0300".freeze,
- "\u1F0C"=>"\u0391\u0313\u0301".freeze, "\u1F0D"=>"\u0391\u0314\u0301".freeze, "\u1F0E"=>"\u0391\u0313\u0342".freeze, "\u1F0F"=>"\u0391\u0314\u0342".freeze, "\u1F10"=>"\u03B5\u0313".freeze, "\u1F11"=>"\u03B5\u0314".freeze, "\u1F12"=>"\u03B5\u0313\u0300".freeze, "\u1F13"=>"\u03B5\u0314\u0300".freeze,
- "\u1F14"=>"\u03B5\u0313\u0301".freeze, "\u1F15"=>"\u03B5\u0314\u0301".freeze, "\u1F18"=>"\u0395\u0313".freeze, "\u1F19"=>"\u0395\u0314".freeze, "\u1F1A"=>"\u0395\u0313\u0300".freeze, "\u1F1B"=>"\u0395\u0314\u0300".freeze, "\u1F1C"=>"\u0395\u0313\u0301".freeze, "\u1F1D"=>"\u0395\u0314\u0301".freeze,
- "\u1F20"=>"\u03B7\u0313".freeze, "\u1F21"=>"\u03B7\u0314".freeze, "\u1F22"=>"\u03B7\u0313\u0300".freeze, "\u1F23"=>"\u03B7\u0314\u0300".freeze, "\u1F24"=>"\u03B7\u0313\u0301".freeze, "\u1F25"=>"\u03B7\u0314\u0301".freeze, "\u1F26"=>"\u03B7\u0313\u0342".freeze, "\u1F27"=>"\u03B7\u0314\u0342".freeze,
- "\u1F28"=>"\u0397\u0313".freeze, "\u1F29"=>"\u0397\u0314".freeze, "\u1F2A"=>"\u0397\u0313\u0300".freeze, "\u1F2B"=>"\u0397\u0314\u0300".freeze, "\u1F2C"=>"\u0397\u0313\u0301".freeze, "\u1F2D"=>"\u0397\u0314\u0301".freeze, "\u1F2E"=>"\u0397\u0313\u0342".freeze, "\u1F2F"=>"\u0397\u0314\u0342".freeze,
- "\u1F30"=>"\u03B9\u0313".freeze, "\u1F31"=>"\u03B9\u0314".freeze, "\u1F32"=>"\u03B9\u0313\u0300".freeze, "\u1F33"=>"\u03B9\u0314\u0300".freeze, "\u1F34"=>"\u03B9\u0313\u0301".freeze, "\u1F35"=>"\u03B9\u0314\u0301".freeze, "\u1F36"=>"\u03B9\u0313\u0342".freeze, "\u1F37"=>"\u03B9\u0314\u0342".freeze,
- "\u1F38"=>"\u0399\u0313".freeze, "\u1F39"=>"\u0399\u0314".freeze, "\u1F3A"=>"\u0399\u0313\u0300".freeze, "\u1F3B"=>"\u0399\u0314\u0300".freeze, "\u1F3C"=>"\u0399\u0313\u0301".freeze, "\u1F3D"=>"\u0399\u0314\u0301".freeze, "\u1F3E"=>"\u0399\u0313\u0342".freeze, "\u1F3F"=>"\u0399\u0314\u0342".freeze,
- "\u1F40"=>"\u03BF\u0313".freeze, "\u1F41"=>"\u03BF\u0314".freeze, "\u1F42"=>"\u03BF\u0313\u0300".freeze, "\u1F43"=>"\u03BF\u0314\u0300".freeze, "\u1F44"=>"\u03BF\u0313\u0301".freeze, "\u1F45"=>"\u03BF\u0314\u0301".freeze, "\u1F48"=>"\u039F\u0313".freeze, "\u1F49"=>"\u039F\u0314".freeze,
- "\u1F4A"=>"\u039F\u0313\u0300".freeze, "\u1F4B"=>"\u039F\u0314\u0300".freeze, "\u1F4C"=>"\u039F\u0313\u0301".freeze, "\u1F4D"=>"\u039F\u0314\u0301".freeze, "\u1F50"=>"\u03C5\u0313".freeze, "\u1F51"=>"\u03C5\u0314".freeze, "\u1F52"=>"\u03C5\u0313\u0300".freeze, "\u1F53"=>"\u03C5\u0314\u0300".freeze,
- "\u1F54"=>"\u03C5\u0313\u0301".freeze, "\u1F55"=>"\u03C5\u0314\u0301".freeze, "\u1F56"=>"\u03C5\u0313\u0342".freeze, "\u1F57"=>"\u03C5\u0314\u0342".freeze, "\u1F59"=>"\u03A5\u0314".freeze, "\u1F5B"=>"\u03A5\u0314\u0300".freeze, "\u1F5D"=>"\u03A5\u0314\u0301".freeze, "\u1F5F"=>"\u03A5\u0314\u0342".freeze,
- "\u1F60"=>"\u03C9\u0313".freeze, "\u1F61"=>"\u03C9\u0314".freeze, "\u1F62"=>"\u03C9\u0313\u0300".freeze, "\u1F63"=>"\u03C9\u0314\u0300".freeze, "\u1F64"=>"\u03C9\u0313\u0301".freeze, "\u1F65"=>"\u03C9\u0314\u0301".freeze, "\u1F66"=>"\u03C9\u0313\u0342".freeze, "\u1F67"=>"\u03C9\u0314\u0342".freeze,
- "\u1F68"=>"\u03A9\u0313".freeze, "\u1F69"=>"\u03A9\u0314".freeze, "\u1F6A"=>"\u03A9\u0313\u0300".freeze, "\u1F6B"=>"\u03A9\u0314\u0300".freeze, "\u1F6C"=>"\u03A9\u0313\u0301".freeze, "\u1F6D"=>"\u03A9\u0314\u0301".freeze, "\u1F6E"=>"\u03A9\u0313\u0342".freeze, "\u1F6F"=>"\u03A9\u0314\u0342".freeze,
- "\u1F70"=>"\u03B1\u0300".freeze, "\u1F71"=>"\u03B1\u0301".freeze, "\u1F72"=>"\u03B5\u0300".freeze, "\u1F73"=>"\u03B5\u0301".freeze, "\u1F74"=>"\u03B7\u0300".freeze, "\u1F75"=>"\u03B7\u0301".freeze, "\u1F76"=>"\u03B9\u0300".freeze, "\u1F77"=>"\u03B9\u0301".freeze,
- "\u1F78"=>"\u03BF\u0300".freeze, "\u1F79"=>"\u03BF\u0301".freeze, "\u1F7A"=>"\u03C5\u0300".freeze, "\u1F7B"=>"\u03C5\u0301".freeze, "\u1F7C"=>"\u03C9\u0300".freeze, "\u1F7D"=>"\u03C9\u0301".freeze, "\u1F80"=>"\u03B1\u0313\u0345".freeze, "\u1F81"=>"\u03B1\u0314\u0345".freeze,
- "\u1F82"=>"\u03B1\u0313\u0300\u0345".freeze, "\u1F83"=>"\u03B1\u0314\u0300\u0345".freeze, "\u1F84"=>"\u03B1\u0313\u0301\u0345".freeze, "\u1F85"=>"\u03B1\u0314\u0301\u0345".freeze, "\u1F86"=>"\u03B1\u0313\u0342\u0345".freeze, "\u1F87"=>"\u03B1\u0314\u0342\u0345".freeze, "\u1F88"=>"\u0391\u0313\u0345".freeze, "\u1F89"=>"\u0391\u0314\u0345".freeze,
- "\u1F8A"=>"\u0391\u0313\u0300\u0345".freeze, "\u1F8B"=>"\u0391\u0314\u0300\u0345".freeze, "\u1F8C"=>"\u0391\u0313\u0301\u0345".freeze, "\u1F8D"=>"\u0391\u0314\u0301\u0345".freeze, "\u1F8E"=>"\u0391\u0313\u0342\u0345".freeze, "\u1F8F"=>"\u0391\u0314\u0342\u0345".freeze, "\u1F90"=>"\u03B7\u0313\u0345".freeze, "\u1F91"=>"\u03B7\u0314\u0345".freeze,
- "\u1F92"=>"\u03B7\u0313\u0300\u0345".freeze, "\u1F93"=>"\u03B7\u0314\u0300\u0345".freeze, "\u1F94"=>"\u03B7\u0313\u0301\u0345".freeze, "\u1F95"=>"\u03B7\u0314\u0301\u0345".freeze, "\u1F96"=>"\u03B7\u0313\u0342\u0345".freeze, "\u1F97"=>"\u03B7\u0314\u0342\u0345".freeze, "\u1F98"=>"\u0397\u0313\u0345".freeze, "\u1F99"=>"\u0397\u0314\u0345".freeze,
- "\u1F9A"=>"\u0397\u0313\u0300\u0345".freeze, "\u1F9B"=>"\u0397\u0314\u0300\u0345".freeze, "\u1F9C"=>"\u0397\u0313\u0301\u0345".freeze, "\u1F9D"=>"\u0397\u0314\u0301\u0345".freeze, "\u1F9E"=>"\u0397\u0313\u0342\u0345".freeze, "\u1F9F"=>"\u0397\u0314\u0342\u0345".freeze, "\u1FA0"=>"\u03C9\u0313\u0345".freeze, "\u1FA1"=>"\u03C9\u0314\u0345".freeze,
- "\u1FA2"=>"\u03C9\u0313\u0300\u0345".freeze, "\u1FA3"=>"\u03C9\u0314\u0300\u0345".freeze, "\u1FA4"=>"\u03C9\u0313\u0301\u0345".freeze, "\u1FA5"=>"\u03C9\u0314\u0301\u0345".freeze, "\u1FA6"=>"\u03C9\u0313\u0342\u0345".freeze, "\u1FA7"=>"\u03C9\u0314\u0342\u0345".freeze, "\u1FA8"=>"\u03A9\u0313\u0345".freeze, "\u1FA9"=>"\u03A9\u0314\u0345".freeze,
- "\u1FAA"=>"\u03A9\u0313\u0300\u0345".freeze, "\u1FAB"=>"\u03A9\u0314\u0300\u0345".freeze, "\u1FAC"=>"\u03A9\u0313\u0301\u0345".freeze, "\u1FAD"=>"\u03A9\u0314\u0301\u0345".freeze, "\u1FAE"=>"\u03A9\u0313\u0342\u0345".freeze, "\u1FAF"=>"\u03A9\u0314\u0342\u0345".freeze, "\u1FB0"=>"\u03B1\u0306".freeze, "\u1FB1"=>"\u03B1\u0304".freeze,
- "\u1FB2"=>"\u03B1\u0300\u0345".freeze, "\u1FB3"=>"\u03B1\u0345".freeze, "\u1FB4"=>"\u03B1\u0301\u0345".freeze, "\u1FB6"=>"\u03B1\u0342".freeze, "\u1FB7"=>"\u03B1\u0342\u0345".freeze, "\u1FB8"=>"\u0391\u0306".freeze, "\u1FB9"=>"\u0391\u0304".freeze, "\u1FBA"=>"\u0391\u0300".freeze,
- "\u1FBB"=>"\u0391\u0301".freeze, "\u1FBC"=>"\u0391\u0345".freeze, "\u1FBE"=>"\u03B9".freeze, "\u1FC1"=>"\u00A8\u0342".freeze, "\u1FC2"=>"\u03B7\u0300\u0345".freeze, "\u1FC3"=>"\u03B7\u0345".freeze, "\u1FC4"=>"\u03B7\u0301\u0345".freeze, "\u1FC6"=>"\u03B7\u0342".freeze,
- "\u1FC7"=>"\u03B7\u0342\u0345".freeze, "\u1FC8"=>"\u0395\u0300".freeze, "\u1FC9"=>"\u0395\u0301".freeze, "\u1FCA"=>"\u0397\u0300".freeze, "\u1FCB"=>"\u0397\u0301".freeze, "\u1FCC"=>"\u0397\u0345".freeze, "\u1FCD"=>"\u1FBF\u0300".freeze, "\u1FCE"=>"\u1FBF\u0301".freeze,
- "\u1FCF"=>"\u1FBF\u0342".freeze, "\u1FD0"=>"\u03B9\u0306".freeze, "\u1FD1"=>"\u03B9\u0304".freeze, "\u1FD2"=>"\u03B9\u0308\u0300".freeze, "\u1FD3"=>"\u03B9\u0308\u0301".freeze, "\u1FD6"=>"\u03B9\u0342".freeze, "\u1FD7"=>"\u03B9\u0308\u0342".freeze, "\u1FD8"=>"\u0399\u0306".freeze,
- "\u1FD9"=>"\u0399\u0304".freeze, "\u1FDA"=>"\u0399\u0300".freeze, "\u1FDB"=>"\u0399\u0301".freeze, "\u1FDD"=>"\u1FFE\u0300".freeze, "\u1FDE"=>"\u1FFE\u0301".freeze, "\u1FDF"=>"\u1FFE\u0342".freeze, "\u1FE0"=>"\u03C5\u0306".freeze, "\u1FE1"=>"\u03C5\u0304".freeze,
- "\u1FE2"=>"\u03C5\u0308\u0300".freeze, "\u1FE3"=>"\u03C5\u0308\u0301".freeze, "\u1FE4"=>"\u03C1\u0313".freeze, "\u1FE5"=>"\u03C1\u0314".freeze, "\u1FE6"=>"\u03C5\u0342".freeze, "\u1FE7"=>"\u03C5\u0308\u0342".freeze, "\u1FE8"=>"\u03A5\u0306".freeze, "\u1FE9"=>"\u03A5\u0304".freeze,
- "\u1FEA"=>"\u03A5\u0300".freeze, "\u1FEB"=>"\u03A5\u0301".freeze, "\u1FEC"=>"\u03A1\u0314".freeze, "\u1FED"=>"\u00A8\u0300".freeze, "\u1FEE"=>"\u00A8\u0301".freeze, "\u1FEF"=>"`".freeze, "\u1FF2"=>"\u03C9\u0300\u0345".freeze, "\u1FF3"=>"\u03C9\u0345".freeze,
- "\u1FF4"=>"\u03C9\u0301\u0345".freeze, "\u1FF6"=>"\u03C9\u0342".freeze, "\u1FF7"=>"\u03C9\u0342\u0345".freeze, "\u1FF8"=>"\u039F\u0300".freeze, "\u1FF9"=>"\u039F\u0301".freeze, "\u1FFA"=>"\u03A9\u0300".freeze, "\u1FFB"=>"\u03A9\u0301".freeze, "\u1FFC"=>"\u03A9\u0345".freeze,
- "\u1FFD"=>"\u00B4".freeze, "\u2000"=>"\u2002".freeze, "\u2001"=>"\u2003".freeze, "\u2126"=>"\u03A9".freeze, "\u212A"=>"K".freeze, "\u212B"=>"A\u030A".freeze, "\u219A"=>"\u2190\u0338".freeze, "\u219B"=>"\u2192\u0338".freeze,
- "\u21AE"=>"\u2194\u0338".freeze, "\u21CD"=>"\u21D0\u0338".freeze, "\u21CE"=>"\u21D4\u0338".freeze, "\u21CF"=>"\u21D2\u0338".freeze, "\u2204"=>"\u2203\u0338".freeze, "\u2209"=>"\u2208\u0338".freeze, "\u220C"=>"\u220B\u0338".freeze, "\u2224"=>"\u2223\u0338".freeze,
- "\u2226"=>"\u2225\u0338".freeze, "\u2241"=>"\u223C\u0338".freeze, "\u2244"=>"\u2243\u0338".freeze, "\u2247"=>"\u2245\u0338".freeze, "\u2249"=>"\u2248\u0338".freeze, "\u2260"=>"=\u0338".freeze, "\u2262"=>"\u2261\u0338".freeze, "\u226D"=>"\u224D\u0338".freeze,
- "\u226E"=>"<\u0338".freeze, "\u226F"=>">\u0338".freeze, "\u2270"=>"\u2264\u0338".freeze, "\u2271"=>"\u2265\u0338".freeze, "\u2274"=>"\u2272\u0338".freeze, "\u2275"=>"\u2273\u0338".freeze, "\u2278"=>"\u2276\u0338".freeze, "\u2279"=>"\u2277\u0338".freeze,
- "\u2280"=>"\u227A\u0338".freeze, "\u2281"=>"\u227B\u0338".freeze, "\u2284"=>"\u2282\u0338".freeze, "\u2285"=>"\u2283\u0338".freeze, "\u2288"=>"\u2286\u0338".freeze, "\u2289"=>"\u2287\u0338".freeze, "\u22AC"=>"\u22A2\u0338".freeze, "\u22AD"=>"\u22A8\u0338".freeze,
- "\u22AE"=>"\u22A9\u0338".freeze, "\u22AF"=>"\u22AB\u0338".freeze, "\u22E0"=>"\u227C\u0338".freeze, "\u22E1"=>"\u227D\u0338".freeze, "\u22E2"=>"\u2291\u0338".freeze, "\u22E3"=>"\u2292\u0338".freeze, "\u22EA"=>"\u22B2\u0338".freeze, "\u22EB"=>"\u22B3\u0338".freeze,
- "\u22EC"=>"\u22B4\u0338".freeze, "\u22ED"=>"\u22B5\u0338".freeze, "\u2329"=>"\u3008".freeze, "\u232A"=>"\u3009".freeze, "\u2ADC"=>"\u2ADD\u0338".freeze, "\u304C"=>"\u304B\u3099".freeze, "\u304E"=>"\u304D\u3099".freeze, "\u3050"=>"\u304F\u3099".freeze,
- "\u3052"=>"\u3051\u3099".freeze, "\u3054"=>"\u3053\u3099".freeze, "\u3056"=>"\u3055\u3099".freeze, "\u3058"=>"\u3057\u3099".freeze, "\u305A"=>"\u3059\u3099".freeze, "\u305C"=>"\u305B\u3099".freeze, "\u305E"=>"\u305D\u3099".freeze, "\u3060"=>"\u305F\u3099".freeze,
- "\u3062"=>"\u3061\u3099".freeze, "\u3065"=>"\u3064\u3099".freeze, "\u3067"=>"\u3066\u3099".freeze, "\u3069"=>"\u3068\u3099".freeze, "\u3070"=>"\u306F\u3099".freeze, "\u3071"=>"\u306F\u309A".freeze, "\u3073"=>"\u3072\u3099".freeze, "\u3074"=>"\u3072\u309A".freeze,
- "\u3076"=>"\u3075\u3099".freeze, "\u3077"=>"\u3075\u309A".freeze, "\u3079"=>"\u3078\u3099".freeze, "\u307A"=>"\u3078\u309A".freeze, "\u307C"=>"\u307B\u3099".freeze, "\u307D"=>"\u307B\u309A".freeze, "\u3094"=>"\u3046\u3099".freeze, "\u309E"=>"\u309D\u3099".freeze,
- "\u30AC"=>"\u30AB\u3099".freeze, "\u30AE"=>"\u30AD\u3099".freeze, "\u30B0"=>"\u30AF\u3099".freeze, "\u30B2"=>"\u30B1\u3099".freeze, "\u30B4"=>"\u30B3\u3099".freeze, "\u30B6"=>"\u30B5\u3099".freeze, "\u30B8"=>"\u30B7\u3099".freeze, "\u30BA"=>"\u30B9\u3099".freeze,
- "\u30BC"=>"\u30BB\u3099".freeze, "\u30BE"=>"\u30BD\u3099".freeze, "\u30C0"=>"\u30BF\u3099".freeze, "\u30C2"=>"\u30C1\u3099".freeze, "\u30C5"=>"\u30C4\u3099".freeze, "\u30C7"=>"\u30C6\u3099".freeze, "\u30C9"=>"\u30C8\u3099".freeze, "\u30D0"=>"\u30CF\u3099".freeze,
- "\u30D1"=>"\u30CF\u309A".freeze, "\u30D3"=>"\u30D2\u3099".freeze, "\u30D4"=>"\u30D2\u309A".freeze, "\u30D6"=>"\u30D5\u3099".freeze, "\u30D7"=>"\u30D5\u309A".freeze, "\u30D9"=>"\u30D8\u3099".freeze, "\u30DA"=>"\u30D8\u309A".freeze, "\u30DC"=>"\u30DB\u3099".freeze,
- "\u30DD"=>"\u30DB\u309A".freeze, "\u30F4"=>"\u30A6\u3099".freeze, "\u30F7"=>"\u30EF\u3099".freeze, "\u30F8"=>"\u30F0\u3099".freeze, "\u30F9"=>"\u30F1\u3099".freeze, "\u30FA"=>"\u30F2\u3099".freeze, "\u30FE"=>"\u30FD\u3099".freeze, "\uF900"=>"\u8C48".freeze,
- "\uF901"=>"\u66F4".freeze, "\uF902"=>"\u8ECA".freeze, "\uF903"=>"\u8CC8".freeze, "\uF904"=>"\u6ED1".freeze, "\uF905"=>"\u4E32".freeze, "\uF906"=>"\u53E5".freeze, "\uF907"=>"\u9F9C".freeze, "\uF908"=>"\u9F9C".freeze,
- "\uF909"=>"\u5951".freeze, "\uF90A"=>"\u91D1".freeze, "\uF90B"=>"\u5587".freeze, "\uF90C"=>"\u5948".freeze, "\uF90D"=>"\u61F6".freeze, "\uF90E"=>"\u7669".freeze, "\uF90F"=>"\u7F85".freeze, "\uF910"=>"\u863F".freeze,
- "\uF911"=>"\u87BA".freeze, "\uF912"=>"\u88F8".freeze, "\uF913"=>"\u908F".freeze, "\uF914"=>"\u6A02".freeze, "\uF915"=>"\u6D1B".freeze, "\uF916"=>"\u70D9".freeze, "\uF917"=>"\u73DE".freeze, "\uF918"=>"\u843D".freeze,
- "\uF919"=>"\u916A".freeze, "\uF91A"=>"\u99F1".freeze, "\uF91B"=>"\u4E82".freeze, "\uF91C"=>"\u5375".freeze, "\uF91D"=>"\u6B04".freeze, "\uF91E"=>"\u721B".freeze, "\uF91F"=>"\u862D".freeze, "\uF920"=>"\u9E1E".freeze,
- "\uF921"=>"\u5D50".freeze, "\uF922"=>"\u6FEB".freeze, "\uF923"=>"\u85CD".freeze, "\uF924"=>"\u8964".freeze, "\uF925"=>"\u62C9".freeze, "\uF926"=>"\u81D8".freeze, "\uF927"=>"\u881F".freeze, "\uF928"=>"\u5ECA".freeze,
- "\uF929"=>"\u6717".freeze, "\uF92A"=>"\u6D6A".freeze, "\uF92B"=>"\u72FC".freeze, "\uF92C"=>"\u90CE".freeze, "\uF92D"=>"\u4F86".freeze, "\uF92E"=>"\u51B7".freeze, "\uF92F"=>"\u52DE".freeze, "\uF930"=>"\u64C4".freeze,
- "\uF931"=>"\u6AD3".freeze, "\uF932"=>"\u7210".freeze, "\uF933"=>"\u76E7".freeze, "\uF934"=>"\u8001".freeze, "\uF935"=>"\u8606".freeze, "\uF936"=>"\u865C".freeze, "\uF937"=>"\u8DEF".freeze, "\uF938"=>"\u9732".freeze,
- "\uF939"=>"\u9B6F".freeze, "\uF93A"=>"\u9DFA".freeze, "\uF93B"=>"\u788C".freeze, "\uF93C"=>"\u797F".freeze, "\uF93D"=>"\u7DA0".freeze, "\uF93E"=>"\u83C9".freeze, "\uF93F"=>"\u9304".freeze, "\uF940"=>"\u9E7F".freeze,
- "\uF941"=>"\u8AD6".freeze, "\uF942"=>"\u58DF".freeze, "\uF943"=>"\u5F04".freeze, "\uF944"=>"\u7C60".freeze, "\uF945"=>"\u807E".freeze, "\uF946"=>"\u7262".freeze, "\uF947"=>"\u78CA".freeze, "\uF948"=>"\u8CC2".freeze,
- "\uF949"=>"\u96F7".freeze, "\uF94A"=>"\u58D8".freeze, "\uF94B"=>"\u5C62".freeze, "\uF94C"=>"\u6A13".freeze, "\uF94D"=>"\u6DDA".freeze, "\uF94E"=>"\u6F0F".freeze, "\uF94F"=>"\u7D2F".freeze, "\uF950"=>"\u7E37".freeze,
- "\uF951"=>"\u964B".freeze, "\uF952"=>"\u52D2".freeze, "\uF953"=>"\u808B".freeze, "\uF954"=>"\u51DC".freeze, "\uF955"=>"\u51CC".freeze, "\uF956"=>"\u7A1C".freeze, "\uF957"=>"\u7DBE".freeze, "\uF958"=>"\u83F1".freeze,
- "\uF959"=>"\u9675".freeze, "\uF95A"=>"\u8B80".freeze, "\uF95B"=>"\u62CF".freeze, "\uF95C"=>"\u6A02".freeze, "\uF95D"=>"\u8AFE".freeze, "\uF95E"=>"\u4E39".freeze, "\uF95F"=>"\u5BE7".freeze, "\uF960"=>"\u6012".freeze,
- "\uF961"=>"\u7387".freeze, "\uF962"=>"\u7570".freeze, "\uF963"=>"\u5317".freeze, "\uF964"=>"\u78FB".freeze, "\uF965"=>"\u4FBF".freeze, "\uF966"=>"\u5FA9".freeze, "\uF967"=>"\u4E0D".freeze, "\uF968"=>"\u6CCC".freeze,
- "\uF969"=>"\u6578".freeze, "\uF96A"=>"\u7D22".freeze, "\uF96B"=>"\u53C3".freeze, "\uF96C"=>"\u585E".freeze, "\uF96D"=>"\u7701".freeze, "\uF96E"=>"\u8449".freeze, "\uF96F"=>"\u8AAA".freeze, "\uF970"=>"\u6BBA".freeze,
- "\uF971"=>"\u8FB0".freeze, "\uF972"=>"\u6C88".freeze, "\uF973"=>"\u62FE".freeze, "\uF974"=>"\u82E5".freeze, "\uF975"=>"\u63A0".freeze, "\uF976"=>"\u7565".freeze, "\uF977"=>"\u4EAE".freeze, "\uF978"=>"\u5169".freeze,
- "\uF979"=>"\u51C9".freeze, "\uF97A"=>"\u6881".freeze, "\uF97B"=>"\u7CE7".freeze, "\uF97C"=>"\u826F".freeze, "\uF97D"=>"\u8AD2".freeze, "\uF97E"=>"\u91CF".freeze, "\uF97F"=>"\u52F5".freeze, "\uF980"=>"\u5442".freeze,
- "\uF981"=>"\u5973".freeze, "\uF982"=>"\u5EEC".freeze, "\uF983"=>"\u65C5".freeze, "\uF984"=>"\u6FFE".freeze, "\uF985"=>"\u792A".freeze, "\uF986"=>"\u95AD".freeze, "\uF987"=>"\u9A6A".freeze, "\uF988"=>"\u9E97".freeze,
- "\uF989"=>"\u9ECE".freeze, "\uF98A"=>"\u529B".freeze, "\uF98B"=>"\u66C6".freeze, "\uF98C"=>"\u6B77".freeze, "\uF98D"=>"\u8F62".freeze, "\uF98E"=>"\u5E74".freeze, "\uF98F"=>"\u6190".freeze, "\uF990"=>"\u6200".freeze,
- "\uF991"=>"\u649A".freeze, "\uF992"=>"\u6F23".freeze, "\uF993"=>"\u7149".freeze, "\uF994"=>"\u7489".freeze, "\uF995"=>"\u79CA".freeze, "\uF996"=>"\u7DF4".freeze, "\uF997"=>"\u806F".freeze, "\uF998"=>"\u8F26".freeze,
- "\uF999"=>"\u84EE".freeze, "\uF99A"=>"\u9023".freeze, "\uF99B"=>"\u934A".freeze, "\uF99C"=>"\u5217".freeze, "\uF99D"=>"\u52A3".freeze, "\uF99E"=>"\u54BD".freeze, "\uF99F"=>"\u70C8".freeze, "\uF9A0"=>"\u88C2".freeze,
- "\uF9A1"=>"\u8AAA".freeze, "\uF9A2"=>"\u5EC9".freeze, "\uF9A3"=>"\u5FF5".freeze, "\uF9A4"=>"\u637B".freeze, "\uF9A5"=>"\u6BAE".freeze, "\uF9A6"=>"\u7C3E".freeze, "\uF9A7"=>"\u7375".freeze, "\uF9A8"=>"\u4EE4".freeze,
- "\uF9A9"=>"\u56F9".freeze, "\uF9AA"=>"\u5BE7".freeze, "\uF9AB"=>"\u5DBA".freeze, "\uF9AC"=>"\u601C".freeze, "\uF9AD"=>"\u73B2".freeze, "\uF9AE"=>"\u7469".freeze, "\uF9AF"=>"\u7F9A".freeze, "\uF9B0"=>"\u8046".freeze,
- "\uF9B1"=>"\u9234".freeze, "\uF9B2"=>"\u96F6".freeze, "\uF9B3"=>"\u9748".freeze, "\uF9B4"=>"\u9818".freeze, "\uF9B5"=>"\u4F8B".freeze, "\uF9B6"=>"\u79AE".freeze, "\uF9B7"=>"\u91B4".freeze, "\uF9B8"=>"\u96B8".freeze,
- "\uF9B9"=>"\u60E1".freeze, "\uF9BA"=>"\u4E86".freeze, "\uF9BB"=>"\u50DA".freeze, "\uF9BC"=>"\u5BEE".freeze, "\uF9BD"=>"\u5C3F".freeze, "\uF9BE"=>"\u6599".freeze, "\uF9BF"=>"\u6A02".freeze, "\uF9C0"=>"\u71CE".freeze,
- "\uF9C1"=>"\u7642".freeze, "\uF9C2"=>"\u84FC".freeze, "\uF9C3"=>"\u907C".freeze, "\uF9C4"=>"\u9F8D".freeze, "\uF9C5"=>"\u6688".freeze, "\uF9C6"=>"\u962E".freeze, "\uF9C7"=>"\u5289".freeze, "\uF9C8"=>"\u677B".freeze,
- "\uF9C9"=>"\u67F3".freeze, "\uF9CA"=>"\u6D41".freeze, "\uF9CB"=>"\u6E9C".freeze, "\uF9CC"=>"\u7409".freeze, "\uF9CD"=>"\u7559".freeze, "\uF9CE"=>"\u786B".freeze, "\uF9CF"=>"\u7D10".freeze, "\uF9D0"=>"\u985E".freeze,
- "\uF9D1"=>"\u516D".freeze, "\uF9D2"=>"\u622E".freeze, "\uF9D3"=>"\u9678".freeze, "\uF9D4"=>"\u502B".freeze, "\uF9D5"=>"\u5D19".freeze, "\uF9D6"=>"\u6DEA".freeze, "\uF9D7"=>"\u8F2A".freeze, "\uF9D8"=>"\u5F8B".freeze,
- "\uF9D9"=>"\u6144".freeze, "\uF9DA"=>"\u6817".freeze, "\uF9DB"=>"\u7387".freeze, "\uF9DC"=>"\u9686".freeze, "\uF9DD"=>"\u5229".freeze, "\uF9DE"=>"\u540F".freeze, "\uF9DF"=>"\u5C65".freeze, "\uF9E0"=>"\u6613".freeze,
- "\uF9E1"=>"\u674E".freeze, "\uF9E2"=>"\u68A8".freeze, "\uF9E3"=>"\u6CE5".freeze, "\uF9E4"=>"\u7406".freeze, "\uF9E5"=>"\u75E2".freeze, "\uF9E6"=>"\u7F79".freeze, "\uF9E7"=>"\u88CF".freeze, "\uF9E8"=>"\u88E1".freeze,
- "\uF9E9"=>"\u91CC".freeze, "\uF9EA"=>"\u96E2".freeze, "\uF9EB"=>"\u533F".freeze, "\uF9EC"=>"\u6EBA".freeze, "\uF9ED"=>"\u541D".freeze, "\uF9EE"=>"\u71D0".freeze, "\uF9EF"=>"\u7498".freeze, "\uF9F0"=>"\u85FA".freeze,
- "\uF9F1"=>"\u96A3".freeze, "\uF9F2"=>"\u9C57".freeze, "\uF9F3"=>"\u9E9F".freeze, "\uF9F4"=>"\u6797".freeze, "\uF9F5"=>"\u6DCB".freeze, "\uF9F6"=>"\u81E8".freeze, "\uF9F7"=>"\u7ACB".freeze, "\uF9F8"=>"\u7B20".freeze,
- "\uF9F9"=>"\u7C92".freeze, "\uF9FA"=>"\u72C0".freeze, "\uF9FB"=>"\u7099".freeze, "\uF9FC"=>"\u8B58".freeze, "\uF9FD"=>"\u4EC0".freeze, "\uF9FE"=>"\u8336".freeze, "\uF9FF"=>"\u523A".freeze, "\uFA00"=>"\u5207".freeze,
- "\uFA01"=>"\u5EA6".freeze, "\uFA02"=>"\u62D3".freeze, "\uFA03"=>"\u7CD6".freeze, "\uFA04"=>"\u5B85".freeze, "\uFA05"=>"\u6D1E".freeze, "\uFA06"=>"\u66B4".freeze, "\uFA07"=>"\u8F3B".freeze, "\uFA08"=>"\u884C".freeze,
- "\uFA09"=>"\u964D".freeze, "\uFA0A"=>"\u898B".freeze, "\uFA0B"=>"\u5ED3".freeze, "\uFA0C"=>"\u5140".freeze, "\uFA0D"=>"\u55C0".freeze, "\uFA10"=>"\u585A".freeze, "\uFA12"=>"\u6674".freeze, "\uFA15"=>"\u51DE".freeze,
- "\uFA16"=>"\u732A".freeze, "\uFA17"=>"\u76CA".freeze, "\uFA18"=>"\u793C".freeze, "\uFA19"=>"\u795E".freeze, "\uFA1A"=>"\u7965".freeze, "\uFA1B"=>"\u798F".freeze, "\uFA1C"=>"\u9756".freeze, "\uFA1D"=>"\u7CBE".freeze,
- "\uFA1E"=>"\u7FBD".freeze, "\uFA20"=>"\u8612".freeze, "\uFA22"=>"\u8AF8".freeze, "\uFA25"=>"\u9038".freeze, "\uFA26"=>"\u90FD".freeze, "\uFA2A"=>"\u98EF".freeze, "\uFA2B"=>"\u98FC".freeze, "\uFA2C"=>"\u9928".freeze,
- "\uFA2D"=>"\u9DB4".freeze, "\uFA2E"=>"\u90DE".freeze, "\uFA2F"=>"\u96B7".freeze, "\uFA30"=>"\u4FAE".freeze, "\uFA31"=>"\u50E7".freeze, "\uFA32"=>"\u514D".freeze, "\uFA33"=>"\u52C9".freeze, "\uFA34"=>"\u52E4".freeze,
- "\uFA35"=>"\u5351".freeze, "\uFA36"=>"\u559D".freeze, "\uFA37"=>"\u5606".freeze, "\uFA38"=>"\u5668".freeze, "\uFA39"=>"\u5840".freeze, "\uFA3A"=>"\u58A8".freeze, "\uFA3B"=>"\u5C64".freeze, "\uFA3C"=>"\u5C6E".freeze,
- "\uFA3D"=>"\u6094".freeze, "\uFA3E"=>"\u6168".freeze, "\uFA3F"=>"\u618E".freeze, "\uFA40"=>"\u61F2".freeze, "\uFA41"=>"\u654F".freeze, "\uFA42"=>"\u65E2".freeze, "\uFA43"=>"\u6691".freeze, "\uFA44"=>"\u6885".freeze,
- "\uFA45"=>"\u6D77".freeze, "\uFA46"=>"\u6E1A".freeze, "\uFA47"=>"\u6F22".freeze, "\uFA48"=>"\u716E".freeze, "\uFA49"=>"\u722B".freeze, "\uFA4A"=>"\u7422".freeze, "\uFA4B"=>"\u7891".freeze, "\uFA4C"=>"\u793E".freeze,
- "\uFA4D"=>"\u7949".freeze, "\uFA4E"=>"\u7948".freeze, "\uFA4F"=>"\u7950".freeze, "\uFA50"=>"\u7956".freeze, "\uFA51"=>"\u795D".freeze, "\uFA52"=>"\u798D".freeze, "\uFA53"=>"\u798E".freeze, "\uFA54"=>"\u7A40".freeze,
- "\uFA55"=>"\u7A81".freeze, "\uFA56"=>"\u7BC0".freeze, "\uFA57"=>"\u7DF4".freeze, "\uFA58"=>"\u7E09".freeze, "\uFA59"=>"\u7E41".freeze, "\uFA5A"=>"\u7F72".freeze, "\uFA5B"=>"\u8005".freeze, "\uFA5C"=>"\u81ED".freeze,
- "\uFA5D"=>"\u8279".freeze, "\uFA5E"=>"\u8279".freeze, "\uFA5F"=>"\u8457".freeze, "\uFA60"=>"\u8910".freeze, "\uFA61"=>"\u8996".freeze, "\uFA62"=>"\u8B01".freeze, "\uFA63"=>"\u8B39".freeze, "\uFA64"=>"\u8CD3".freeze,
- "\uFA65"=>"\u8D08".freeze, "\uFA66"=>"\u8FB6".freeze, "\uFA67"=>"\u9038".freeze, "\uFA68"=>"\u96E3".freeze, "\uFA69"=>"\u97FF".freeze, "\uFA6A"=>"\u983B".freeze, "\uFA6B"=>"\u6075".freeze, "\uFA6C"=>"\u{242EE}".freeze,
- "\uFA6D"=>"\u8218".freeze, "\uFA70"=>"\u4E26".freeze, "\uFA71"=>"\u51B5".freeze, "\uFA72"=>"\u5168".freeze, "\uFA73"=>"\u4F80".freeze, "\uFA74"=>"\u5145".freeze, "\uFA75"=>"\u5180".freeze, "\uFA76"=>"\u52C7".freeze,
- "\uFA77"=>"\u52FA".freeze, "\uFA78"=>"\u559D".freeze, "\uFA79"=>"\u5555".freeze, "\uFA7A"=>"\u5599".freeze, "\uFA7B"=>"\u55E2".freeze, "\uFA7C"=>"\u585A".freeze, "\uFA7D"=>"\u58B3".freeze, "\uFA7E"=>"\u5944".freeze,
- "\uFA7F"=>"\u5954".freeze, "\uFA80"=>"\u5A62".freeze, "\uFA81"=>"\u5B28".freeze, "\uFA82"=>"\u5ED2".freeze, "\uFA83"=>"\u5ED9".freeze, "\uFA84"=>"\u5F69".freeze, "\uFA85"=>"\u5FAD".freeze, "\uFA86"=>"\u60D8".freeze,
- "\uFA87"=>"\u614E".freeze, "\uFA88"=>"\u6108".freeze, "\uFA89"=>"\u618E".freeze, "\uFA8A"=>"\u6160".freeze, "\uFA8B"=>"\u61F2".freeze, "\uFA8C"=>"\u6234".freeze, "\uFA8D"=>"\u63C4".freeze, "\uFA8E"=>"\u641C".freeze,
- "\uFA8F"=>"\u6452".freeze, "\uFA90"=>"\u6556".freeze, "\uFA91"=>"\u6674".freeze, "\uFA92"=>"\u6717".freeze, "\uFA93"=>"\u671B".freeze, "\uFA94"=>"\u6756".freeze, "\uFA95"=>"\u6B79".freeze, "\uFA96"=>"\u6BBA".freeze,
- "\uFA97"=>"\u6D41".freeze, "\uFA98"=>"\u6EDB".freeze, "\uFA99"=>"\u6ECB".freeze, "\uFA9A"=>"\u6F22".freeze, "\uFA9B"=>"\u701E".freeze, "\uFA9C"=>"\u716E".freeze, "\uFA9D"=>"\u77A7".freeze, "\uFA9E"=>"\u7235".freeze,
- "\uFA9F"=>"\u72AF".freeze, "\uFAA0"=>"\u732A".freeze, "\uFAA1"=>"\u7471".freeze, "\uFAA2"=>"\u7506".freeze, "\uFAA3"=>"\u753B".freeze, "\uFAA4"=>"\u761D".freeze, "\uFAA5"=>"\u761F".freeze, "\uFAA6"=>"\u76CA".freeze,
- "\uFAA7"=>"\u76DB".freeze, "\uFAA8"=>"\u76F4".freeze, "\uFAA9"=>"\u774A".freeze, "\uFAAA"=>"\u7740".freeze, "\uFAAB"=>"\u78CC".freeze, "\uFAAC"=>"\u7AB1".freeze, "\uFAAD"=>"\u7BC0".freeze, "\uFAAE"=>"\u7C7B".freeze,
- "\uFAAF"=>"\u7D5B".freeze, "\uFAB0"=>"\u7DF4".freeze, "\uFAB1"=>"\u7F3E".freeze, "\uFAB2"=>"\u8005".freeze, "\uFAB3"=>"\u8352".freeze, "\uFAB4"=>"\u83EF".freeze, "\uFAB5"=>"\u8779".freeze, "\uFAB6"=>"\u8941".freeze,
- "\uFAB7"=>"\u8986".freeze, "\uFAB8"=>"\u8996".freeze, "\uFAB9"=>"\u8ABF".freeze, "\uFABA"=>"\u8AF8".freeze, "\uFABB"=>"\u8ACB".freeze, "\uFABC"=>"\u8B01".freeze, "\uFABD"=>"\u8AFE".freeze, "\uFABE"=>"\u8AED".freeze,
- "\uFABF"=>"\u8B39".freeze, "\uFAC0"=>"\u8B8A".freeze, "\uFAC1"=>"\u8D08".freeze, "\uFAC2"=>"\u8F38".freeze, "\uFAC3"=>"\u9072".freeze, "\uFAC4"=>"\u9199".freeze, "\uFAC5"=>"\u9276".freeze, "\uFAC6"=>"\u967C".freeze,
- "\uFAC7"=>"\u96E3".freeze, "\uFAC8"=>"\u9756".freeze, "\uFAC9"=>"\u97DB".freeze, "\uFACA"=>"\u97FF".freeze, "\uFACB"=>"\u980B".freeze, "\uFACC"=>"\u983B".freeze, "\uFACD"=>"\u9B12".freeze, "\uFACE"=>"\u9F9C".freeze,
- "\uFACF"=>"\u{2284A}".freeze, "\uFAD0"=>"\u{22844}".freeze, "\uFAD1"=>"\u{233D5}".freeze, "\uFAD2"=>"\u3B9D".freeze, "\uFAD3"=>"\u4018".freeze, "\uFAD4"=>"\u4039".freeze, "\uFAD5"=>"\u{25249}".freeze, "\uFAD6"=>"\u{25CD0}".freeze,
- "\uFAD7"=>"\u{27ED3}".freeze, "\uFAD8"=>"\u9F43".freeze, "\uFAD9"=>"\u9F8E".freeze, "\uFB1D"=>"\u05D9\u05B4".freeze, "\uFB1F"=>"\u05F2\u05B7".freeze, "\uFB2A"=>"\u05E9\u05C1".freeze, "\uFB2B"=>"\u05E9\u05C2".freeze, "\uFB2C"=>"\u05E9\u05BC\u05C1".freeze,
- "\uFB2D"=>"\u05E9\u05BC\u05C2".freeze, "\uFB2E"=>"\u05D0\u05B7".freeze, "\uFB2F"=>"\u05D0\u05B8".freeze, "\uFB30"=>"\u05D0\u05BC".freeze, "\uFB31"=>"\u05D1\u05BC".freeze, "\uFB32"=>"\u05D2\u05BC".freeze, "\uFB33"=>"\u05D3\u05BC".freeze, "\uFB34"=>"\u05D4\u05BC".freeze,
- "\uFB35"=>"\u05D5\u05BC".freeze, "\uFB36"=>"\u05D6\u05BC".freeze, "\uFB38"=>"\u05D8\u05BC".freeze, "\uFB39"=>"\u05D9\u05BC".freeze, "\uFB3A"=>"\u05DA\u05BC".freeze, "\uFB3B"=>"\u05DB\u05BC".freeze, "\uFB3C"=>"\u05DC\u05BC".freeze, "\uFB3E"=>"\u05DE\u05BC".freeze,
- "\uFB40"=>"\u05E0\u05BC".freeze, "\uFB41"=>"\u05E1\u05BC".freeze, "\uFB43"=>"\u05E3\u05BC".freeze, "\uFB44"=>"\u05E4\u05BC".freeze, "\uFB46"=>"\u05E6\u05BC".freeze, "\uFB47"=>"\u05E7\u05BC".freeze, "\uFB48"=>"\u05E8\u05BC".freeze, "\uFB49"=>"\u05E9\u05BC".freeze,
- "\uFB4A"=>"\u05EA\u05BC".freeze, "\uFB4B"=>"\u05D5\u05B9".freeze, "\uFB4C"=>"\u05D1\u05BF".freeze, "\uFB4D"=>"\u05DB\u05BF".freeze, "\uFB4E"=>"\u05E4\u05BF".freeze, "\u{1109A}"=>"\u{11099}\u{110BA}".freeze, "\u{1109C}"=>"\u{1109B}\u{110BA}".freeze, "\u{110AB}"=>"\u{110A5}\u{110BA}".freeze,
- "\u{1112E}"=>"\u{11131}\u{11127}".freeze, "\u{1112F}"=>"\u{11132}\u{11127}".freeze, "\u{1134B}"=>"\u{11347}\u{1133E}".freeze, "\u{1134C}"=>"\u{11347}\u{11357}".freeze, "\u{114BB}"=>"\u{114B9}\u{114BA}".freeze, "\u{114BC}"=>"\u{114B9}\u{114B0}".freeze, "\u{114BE}"=>"\u{114B9}\u{114BD}".freeze, "\u{115BA}"=>"\u{115B8}\u{115AF}".freeze,
- "\u{115BB}"=>"\u{115B9}\u{115AF}".freeze, "\u{1D15E}"=>"\u{1D157}\u{1D165}".freeze, "\u{1D15F}"=>"\u{1D158}\u{1D165}".freeze, "\u{1D160}"=>"\u{1D158}\u{1D165}\u{1D16E}".freeze, "\u{1D161}"=>"\u{1D158}\u{1D165}\u{1D16F}".freeze, "\u{1D162}"=>"\u{1D158}\u{1D165}\u{1D170}".freeze, "\u{1D163}"=>"\u{1D158}\u{1D165}\u{1D171}".freeze, "\u{1D164}"=>"\u{1D158}\u{1D165}\u{1D172}".freeze,
- "\u{1D1BB}"=>"\u{1D1B9}\u{1D165}".freeze, "\u{1D1BC}"=>"\u{1D1BA}\u{1D165}".freeze, "\u{1D1BD}"=>"\u{1D1B9}\u{1D165}\u{1D16E}".freeze, "\u{1D1BE}"=>"\u{1D1BA}\u{1D165}\u{1D16E}".freeze, "\u{1D1BF}"=>"\u{1D1B9}\u{1D165}\u{1D16F}".freeze, "\u{1D1C0}"=>"\u{1D1BA}\u{1D165}\u{1D16F}".freeze, "\u{2F800}"=>"\u4E3D".freeze, "\u{2F801}"=>"\u4E38".freeze,
- "\u{2F802}"=>"\u4E41".freeze, "\u{2F803}"=>"\u{20122}".freeze, "\u{2F804}"=>"\u4F60".freeze, "\u{2F805}"=>"\u4FAE".freeze, "\u{2F806}"=>"\u4FBB".freeze, "\u{2F807}"=>"\u5002".freeze, "\u{2F808}"=>"\u507A".freeze, "\u{2F809}"=>"\u5099".freeze,
- "\u{2F80A}"=>"\u50E7".freeze, "\u{2F80B}"=>"\u50CF".freeze, "\u{2F80C}"=>"\u349E".freeze, "\u{2F80D}"=>"\u{2063A}".freeze, "\u{2F80E}"=>"\u514D".freeze, "\u{2F80F}"=>"\u5154".freeze, "\u{2F810}"=>"\u5164".freeze, "\u{2F811}"=>"\u5177".freeze,
- "\u{2F812}"=>"\u{2051C}".freeze, "\u{2F813}"=>"\u34B9".freeze, "\u{2F814}"=>"\u5167".freeze, "\u{2F815}"=>"\u518D".freeze, "\u{2F816}"=>"\u{2054B}".freeze, "\u{2F817}"=>"\u5197".freeze, "\u{2F818}"=>"\u51A4".freeze, "\u{2F819}"=>"\u4ECC".freeze,
- "\u{2F81A}"=>"\u51AC".freeze, "\u{2F81B}"=>"\u51B5".freeze, "\u{2F81C}"=>"\u{291DF}".freeze, "\u{2F81D}"=>"\u51F5".freeze, "\u{2F81E}"=>"\u5203".freeze, "\u{2F81F}"=>"\u34DF".freeze, "\u{2F820}"=>"\u523B".freeze, "\u{2F821}"=>"\u5246".freeze,
- "\u{2F822}"=>"\u5272".freeze, "\u{2F823}"=>"\u5277".freeze, "\u{2F824}"=>"\u3515".freeze, "\u{2F825}"=>"\u52C7".freeze, "\u{2F826}"=>"\u52C9".freeze, "\u{2F827}"=>"\u52E4".freeze, "\u{2F828}"=>"\u52FA".freeze, "\u{2F829}"=>"\u5305".freeze,
- "\u{2F82A}"=>"\u5306".freeze, "\u{2F82B}"=>"\u5317".freeze, "\u{2F82C}"=>"\u5349".freeze, "\u{2F82D}"=>"\u5351".freeze, "\u{2F82E}"=>"\u535A".freeze, "\u{2F82F}"=>"\u5373".freeze, "\u{2F830}"=>"\u537D".freeze, "\u{2F831}"=>"\u537F".freeze,
- "\u{2F832}"=>"\u537F".freeze, "\u{2F833}"=>"\u537F".freeze, "\u{2F834}"=>"\u{20A2C}".freeze, "\u{2F835}"=>"\u7070".freeze, "\u{2F836}"=>"\u53CA".freeze, "\u{2F837}"=>"\u53DF".freeze, "\u{2F838}"=>"\u{20B63}".freeze, "\u{2F839}"=>"\u53EB".freeze,
- "\u{2F83A}"=>"\u53F1".freeze, "\u{2F83B}"=>"\u5406".freeze, "\u{2F83C}"=>"\u549E".freeze, "\u{2F83D}"=>"\u5438".freeze, "\u{2F83E}"=>"\u5448".freeze, "\u{2F83F}"=>"\u5468".freeze, "\u{2F840}"=>"\u54A2".freeze, "\u{2F841}"=>"\u54F6".freeze,
- "\u{2F842}"=>"\u5510".freeze, "\u{2F843}"=>"\u5553".freeze, "\u{2F844}"=>"\u5563".freeze, "\u{2F845}"=>"\u5584".freeze, "\u{2F846}"=>"\u5584".freeze, "\u{2F847}"=>"\u5599".freeze, "\u{2F848}"=>"\u55AB".freeze, "\u{2F849}"=>"\u55B3".freeze,
- "\u{2F84A}"=>"\u55C2".freeze, "\u{2F84B}"=>"\u5716".freeze, "\u{2F84C}"=>"\u5606".freeze, "\u{2F84D}"=>"\u5717".freeze, "\u{2F84E}"=>"\u5651".freeze, "\u{2F84F}"=>"\u5674".freeze, "\u{2F850}"=>"\u5207".freeze, "\u{2F851}"=>"\u58EE".freeze,
- "\u{2F852}"=>"\u57CE".freeze, "\u{2F853}"=>"\u57F4".freeze, "\u{2F854}"=>"\u580D".freeze, "\u{2F855}"=>"\u578B".freeze, "\u{2F856}"=>"\u5832".freeze, "\u{2F857}"=>"\u5831".freeze, "\u{2F858}"=>"\u58AC".freeze, "\u{2F859}"=>"\u{214E4}".freeze,
- "\u{2F85A}"=>"\u58F2".freeze, "\u{2F85B}"=>"\u58F7".freeze, "\u{2F85C}"=>"\u5906".freeze, "\u{2F85D}"=>"\u591A".freeze, "\u{2F85E}"=>"\u5922".freeze, "\u{2F85F}"=>"\u5962".freeze, "\u{2F860}"=>"\u{216A8}".freeze, "\u{2F861}"=>"\u{216EA}".freeze,
- "\u{2F862}"=>"\u59EC".freeze, "\u{2F863}"=>"\u5A1B".freeze, "\u{2F864}"=>"\u5A27".freeze, "\u{2F865}"=>"\u59D8".freeze, "\u{2F866}"=>"\u5A66".freeze, "\u{2F867}"=>"\u36EE".freeze, "\u{2F868}"=>"\u36FC".freeze, "\u{2F869}"=>"\u5B08".freeze,
- "\u{2F86A}"=>"\u5B3E".freeze, "\u{2F86B}"=>"\u5B3E".freeze, "\u{2F86C}"=>"\u{219C8}".freeze, "\u{2F86D}"=>"\u5BC3".freeze, "\u{2F86E}"=>"\u5BD8".freeze, "\u{2F86F}"=>"\u5BE7".freeze, "\u{2F870}"=>"\u5BF3".freeze, "\u{2F871}"=>"\u{21B18}".freeze,
- "\u{2F872}"=>"\u5BFF".freeze, "\u{2F873}"=>"\u5C06".freeze, "\u{2F874}"=>"\u5F53".freeze, "\u{2F875}"=>"\u5C22".freeze, "\u{2F876}"=>"\u3781".freeze, "\u{2F877}"=>"\u5C60".freeze, "\u{2F878}"=>"\u5C6E".freeze, "\u{2F879}"=>"\u5CC0".freeze,
- "\u{2F87A}"=>"\u5C8D".freeze, "\u{2F87B}"=>"\u{21DE4}".freeze, "\u{2F87C}"=>"\u5D43".freeze, "\u{2F87D}"=>"\u{21DE6}".freeze, "\u{2F87E}"=>"\u5D6E".freeze, "\u{2F87F}"=>"\u5D6B".freeze, "\u{2F880}"=>"\u5D7C".freeze, "\u{2F881}"=>"\u5DE1".freeze,
- "\u{2F882}"=>"\u5DE2".freeze, "\u{2F883}"=>"\u382F".freeze, "\u{2F884}"=>"\u5DFD".freeze, "\u{2F885}"=>"\u5E28".freeze, "\u{2F886}"=>"\u5E3D".freeze, "\u{2F887}"=>"\u5E69".freeze, "\u{2F888}"=>"\u3862".freeze, "\u{2F889}"=>"\u{22183}".freeze,
- "\u{2F88A}"=>"\u387C".freeze, "\u{2F88B}"=>"\u5EB0".freeze, "\u{2F88C}"=>"\u5EB3".freeze, "\u{2F88D}"=>"\u5EB6".freeze, "\u{2F88E}"=>"\u5ECA".freeze, "\u{2F88F}"=>"\u{2A392}".freeze, "\u{2F890}"=>"\u5EFE".freeze, "\u{2F891}"=>"\u{22331}".freeze,
- "\u{2F892}"=>"\u{22331}".freeze, "\u{2F893}"=>"\u8201".freeze, "\u{2F894}"=>"\u5F22".freeze, "\u{2F895}"=>"\u5F22".freeze, "\u{2F896}"=>"\u38C7".freeze, "\u{2F897}"=>"\u{232B8}".freeze, "\u{2F898}"=>"\u{261DA}".freeze, "\u{2F899}"=>"\u5F62".freeze,
- "\u{2F89A}"=>"\u5F6B".freeze, "\u{2F89B}"=>"\u38E3".freeze, "\u{2F89C}"=>"\u5F9A".freeze, "\u{2F89D}"=>"\u5FCD".freeze, "\u{2F89E}"=>"\u5FD7".freeze, "\u{2F89F}"=>"\u5FF9".freeze, "\u{2F8A0}"=>"\u6081".freeze, "\u{2F8A1}"=>"\u393A".freeze,
- "\u{2F8A2}"=>"\u391C".freeze, "\u{2F8A3}"=>"\u6094".freeze, "\u{2F8A4}"=>"\u{226D4}".freeze, "\u{2F8A5}"=>"\u60C7".freeze, "\u{2F8A6}"=>"\u6148".freeze, "\u{2F8A7}"=>"\u614C".freeze, "\u{2F8A8}"=>"\u614E".freeze, "\u{2F8A9}"=>"\u614C".freeze,
- "\u{2F8AA}"=>"\u617A".freeze, "\u{2F8AB}"=>"\u618E".freeze, "\u{2F8AC}"=>"\u61B2".freeze, "\u{2F8AD}"=>"\u61A4".freeze, "\u{2F8AE}"=>"\u61AF".freeze, "\u{2F8AF}"=>"\u61DE".freeze, "\u{2F8B0}"=>"\u61F2".freeze, "\u{2F8B1}"=>"\u61F6".freeze,
- "\u{2F8B2}"=>"\u6210".freeze, "\u{2F8B3}"=>"\u621B".freeze, "\u{2F8B4}"=>"\u625D".freeze, "\u{2F8B5}"=>"\u62B1".freeze, "\u{2F8B6}"=>"\u62D4".freeze, "\u{2F8B7}"=>"\u6350".freeze, "\u{2F8B8}"=>"\u{22B0C}".freeze, "\u{2F8B9}"=>"\u633D".freeze,
- "\u{2F8BA}"=>"\u62FC".freeze, "\u{2F8BB}"=>"\u6368".freeze, "\u{2F8BC}"=>"\u6383".freeze, "\u{2F8BD}"=>"\u63E4".freeze, "\u{2F8BE}"=>"\u{22BF1}".freeze, "\u{2F8BF}"=>"\u6422".freeze, "\u{2F8C0}"=>"\u63C5".freeze, "\u{2F8C1}"=>"\u63A9".freeze,
- "\u{2F8C2}"=>"\u3A2E".freeze, "\u{2F8C3}"=>"\u6469".freeze, "\u{2F8C4}"=>"\u647E".freeze, "\u{2F8C5}"=>"\u649D".freeze, "\u{2F8C6}"=>"\u6477".freeze, "\u{2F8C7}"=>"\u3A6C".freeze, "\u{2F8C8}"=>"\u654F".freeze, "\u{2F8C9}"=>"\u656C".freeze,
- "\u{2F8CA}"=>"\u{2300A}".freeze, "\u{2F8CB}"=>"\u65E3".freeze, "\u{2F8CC}"=>"\u66F8".freeze, "\u{2F8CD}"=>"\u6649".freeze, "\u{2F8CE}"=>"\u3B19".freeze, "\u{2F8CF}"=>"\u6691".freeze, "\u{2F8D0}"=>"\u3B08".freeze, "\u{2F8D1}"=>"\u3AE4".freeze,
- "\u{2F8D2}"=>"\u5192".freeze, "\u{2F8D3}"=>"\u5195".freeze, "\u{2F8D4}"=>"\u6700".freeze, "\u{2F8D5}"=>"\u669C".freeze, "\u{2F8D6}"=>"\u80AD".freeze, "\u{2F8D7}"=>"\u43D9".freeze, "\u{2F8D8}"=>"\u6717".freeze, "\u{2F8D9}"=>"\u671B".freeze,
- "\u{2F8DA}"=>"\u6721".freeze, "\u{2F8DB}"=>"\u675E".freeze, "\u{2F8DC}"=>"\u6753".freeze, "\u{2F8DD}"=>"\u{233C3}".freeze, "\u{2F8DE}"=>"\u3B49".freeze, "\u{2F8DF}"=>"\u67FA".freeze, "\u{2F8E0}"=>"\u6785".freeze, "\u{2F8E1}"=>"\u6852".freeze,
- "\u{2F8E2}"=>"\u6885".freeze, "\u{2F8E3}"=>"\u{2346D}".freeze, "\u{2F8E4}"=>"\u688E".freeze, "\u{2F8E5}"=>"\u681F".freeze, "\u{2F8E6}"=>"\u6914".freeze, "\u{2F8E7}"=>"\u3B9D".freeze, "\u{2F8E8}"=>"\u6942".freeze, "\u{2F8E9}"=>"\u69A3".freeze,
- "\u{2F8EA}"=>"\u69EA".freeze, "\u{2F8EB}"=>"\u6AA8".freeze, "\u{2F8EC}"=>"\u{236A3}".freeze, "\u{2F8ED}"=>"\u6ADB".freeze, "\u{2F8EE}"=>"\u3C18".freeze, "\u{2F8EF}"=>"\u6B21".freeze, "\u{2F8F0}"=>"\u{238A7}".freeze, "\u{2F8F1}"=>"\u6B54".freeze,
- "\u{2F8F2}"=>"\u3C4E".freeze, "\u{2F8F3}"=>"\u6B72".freeze, "\u{2F8F4}"=>"\u6B9F".freeze, "\u{2F8F5}"=>"\u6BBA".freeze, "\u{2F8F6}"=>"\u6BBB".freeze, "\u{2F8F7}"=>"\u{23A8D}".freeze, "\u{2F8F8}"=>"\u{21D0B}".freeze, "\u{2F8F9}"=>"\u{23AFA}".freeze,
- "\u{2F8FA}"=>"\u6C4E".freeze, "\u{2F8FB}"=>"\u{23CBC}".freeze, "\u{2F8FC}"=>"\u6CBF".freeze, "\u{2F8FD}"=>"\u6CCD".freeze, "\u{2F8FE}"=>"\u6C67".freeze, "\u{2F8FF}"=>"\u6D16".freeze, "\u{2F900}"=>"\u6D3E".freeze, "\u{2F901}"=>"\u6D77".freeze,
- "\u{2F902}"=>"\u6D41".freeze, "\u{2F903}"=>"\u6D69".freeze, "\u{2F904}"=>"\u6D78".freeze, "\u{2F905}"=>"\u6D85".freeze, "\u{2F906}"=>"\u{23D1E}".freeze, "\u{2F907}"=>"\u6D34".freeze, "\u{2F908}"=>"\u6E2F".freeze, "\u{2F909}"=>"\u6E6E".freeze,
- "\u{2F90A}"=>"\u3D33".freeze, "\u{2F90B}"=>"\u6ECB".freeze, "\u{2F90C}"=>"\u6EC7".freeze, "\u{2F90D}"=>"\u{23ED1}".freeze, "\u{2F90E}"=>"\u6DF9".freeze, "\u{2F90F}"=>"\u6F6E".freeze, "\u{2F910}"=>"\u{23F5E}".freeze, "\u{2F911}"=>"\u{23F8E}".freeze,
- "\u{2F912}"=>"\u6FC6".freeze, "\u{2F913}"=>"\u7039".freeze, "\u{2F914}"=>"\u701E".freeze, "\u{2F915}"=>"\u701B".freeze, "\u{2F916}"=>"\u3D96".freeze, "\u{2F917}"=>"\u704A".freeze, "\u{2F918}"=>"\u707D".freeze, "\u{2F919}"=>"\u7077".freeze,
- "\u{2F91A}"=>"\u70AD".freeze, "\u{2F91B}"=>"\u{20525}".freeze, "\u{2F91C}"=>"\u7145".freeze, "\u{2F91D}"=>"\u{24263}".freeze, "\u{2F91E}"=>"\u719C".freeze, "\u{2F91F}"=>"\u{243AB}".freeze, "\u{2F920}"=>"\u7228".freeze, "\u{2F921}"=>"\u7235".freeze,
- "\u{2F922}"=>"\u7250".freeze, "\u{2F923}"=>"\u{24608}".freeze, "\u{2F924}"=>"\u7280".freeze, "\u{2F925}"=>"\u7295".freeze, "\u{2F926}"=>"\u{24735}".freeze, "\u{2F927}"=>"\u{24814}".freeze, "\u{2F928}"=>"\u737A".freeze, "\u{2F929}"=>"\u738B".freeze,
- "\u{2F92A}"=>"\u3EAC".freeze, "\u{2F92B}"=>"\u73A5".freeze, "\u{2F92C}"=>"\u3EB8".freeze, "\u{2F92D}"=>"\u3EB8".freeze, "\u{2F92E}"=>"\u7447".freeze, "\u{2F92F}"=>"\u745C".freeze, "\u{2F930}"=>"\u7471".freeze, "\u{2F931}"=>"\u7485".freeze,
- "\u{2F932}"=>"\u74CA".freeze, "\u{2F933}"=>"\u3F1B".freeze, "\u{2F934}"=>"\u7524".freeze, "\u{2F935}"=>"\u{24C36}".freeze, "\u{2F936}"=>"\u753E".freeze, "\u{2F937}"=>"\u{24C92}".freeze, "\u{2F938}"=>"\u7570".freeze, "\u{2F939}"=>"\u{2219F}".freeze,
- "\u{2F93A}"=>"\u7610".freeze, "\u{2F93B}"=>"\u{24FA1}".freeze, "\u{2F93C}"=>"\u{24FB8}".freeze, "\u{2F93D}"=>"\u{25044}".freeze, "\u{2F93E}"=>"\u3FFC".freeze, "\u{2F93F}"=>"\u4008".freeze, "\u{2F940}"=>"\u76F4".freeze, "\u{2F941}"=>"\u{250F3}".freeze,
- "\u{2F942}"=>"\u{250F2}".freeze, "\u{2F943}"=>"\u{25119}".freeze, "\u{2F944}"=>"\u{25133}".freeze, "\u{2F945}"=>"\u771E".freeze, "\u{2F946}"=>"\u771F".freeze, "\u{2F947}"=>"\u771F".freeze, "\u{2F948}"=>"\u774A".freeze, "\u{2F949}"=>"\u4039".freeze,
- "\u{2F94A}"=>"\u778B".freeze, "\u{2F94B}"=>"\u4046".freeze, "\u{2F94C}"=>"\u4096".freeze, "\u{2F94D}"=>"\u{2541D}".freeze, "\u{2F94E}"=>"\u784E".freeze, "\u{2F94F}"=>"\u788C".freeze, "\u{2F950}"=>"\u78CC".freeze, "\u{2F951}"=>"\u40E3".freeze,
- "\u{2F952}"=>"\u{25626}".freeze, "\u{2F953}"=>"\u7956".freeze, "\u{2F954}"=>"\u{2569A}".freeze, "\u{2F955}"=>"\u{256C5}".freeze, "\u{2F956}"=>"\u798F".freeze, "\u{2F957}"=>"\u79EB".freeze, "\u{2F958}"=>"\u412F".freeze, "\u{2F959}"=>"\u7A40".freeze,
- "\u{2F95A}"=>"\u7A4A".freeze, "\u{2F95B}"=>"\u7A4F".freeze, "\u{2F95C}"=>"\u{2597C}".freeze, "\u{2F95D}"=>"\u{25AA7}".freeze, "\u{2F95E}"=>"\u{25AA7}".freeze, "\u{2F95F}"=>"\u7AEE".freeze, "\u{2F960}"=>"\u4202".freeze, "\u{2F961}"=>"\u{25BAB}".freeze,
- "\u{2F962}"=>"\u7BC6".freeze, "\u{2F963}"=>"\u7BC9".freeze, "\u{2F964}"=>"\u4227".freeze, "\u{2F965}"=>"\u{25C80}".freeze, "\u{2F966}"=>"\u7CD2".freeze, "\u{2F967}"=>"\u42A0".freeze, "\u{2F968}"=>"\u7CE8".freeze, "\u{2F969}"=>"\u7CE3".freeze,
- "\u{2F96A}"=>"\u7D00".freeze, "\u{2F96B}"=>"\u{25F86}".freeze, "\u{2F96C}"=>"\u7D63".freeze, "\u{2F96D}"=>"\u4301".freeze, "\u{2F96E}"=>"\u7DC7".freeze, "\u{2F96F}"=>"\u7E02".freeze, "\u{2F970}"=>"\u7E45".freeze, "\u{2F971}"=>"\u4334".freeze,
- "\u{2F972}"=>"\u{26228}".freeze, "\u{2F973}"=>"\u{26247}".freeze, "\u{2F974}"=>"\u4359".freeze, "\u{2F975}"=>"\u{262D9}".freeze, "\u{2F976}"=>"\u7F7A".freeze, "\u{2F977}"=>"\u{2633E}".freeze, "\u{2F978}"=>"\u7F95".freeze, "\u{2F979}"=>"\u7FFA".freeze,
- "\u{2F97A}"=>"\u8005".freeze, "\u{2F97B}"=>"\u{264DA}".freeze, "\u{2F97C}"=>"\u{26523}".freeze, "\u{2F97D}"=>"\u8060".freeze, "\u{2F97E}"=>"\u{265A8}".freeze, "\u{2F97F}"=>"\u8070".freeze, "\u{2F980}"=>"\u{2335F}".freeze, "\u{2F981}"=>"\u43D5".freeze,
- "\u{2F982}"=>"\u80B2".freeze, "\u{2F983}"=>"\u8103".freeze, "\u{2F984}"=>"\u440B".freeze, "\u{2F985}"=>"\u813E".freeze, "\u{2F986}"=>"\u5AB5".freeze, "\u{2F987}"=>"\u{267A7}".freeze, "\u{2F988}"=>"\u{267B5}".freeze, "\u{2F989}"=>"\u{23393}".freeze,
- "\u{2F98A}"=>"\u{2339C}".freeze, "\u{2F98B}"=>"\u8201".freeze, "\u{2F98C}"=>"\u8204".freeze, "\u{2F98D}"=>"\u8F9E".freeze, "\u{2F98E}"=>"\u446B".freeze, "\u{2F98F}"=>"\u8291".freeze, "\u{2F990}"=>"\u828B".freeze, "\u{2F991}"=>"\u829D".freeze,
- "\u{2F992}"=>"\u52B3".freeze, "\u{2F993}"=>"\u82B1".freeze, "\u{2F994}"=>"\u82B3".freeze, "\u{2F995}"=>"\u82BD".freeze, "\u{2F996}"=>"\u82E6".freeze, "\u{2F997}"=>"\u{26B3C}".freeze, "\u{2F998}"=>"\u82E5".freeze, "\u{2F999}"=>"\u831D".freeze,
- "\u{2F99A}"=>"\u8363".freeze, "\u{2F99B}"=>"\u83AD".freeze, "\u{2F99C}"=>"\u8323".freeze, "\u{2F99D}"=>"\u83BD".freeze, "\u{2F99E}"=>"\u83E7".freeze, "\u{2F99F}"=>"\u8457".freeze, "\u{2F9A0}"=>"\u8353".freeze, "\u{2F9A1}"=>"\u83CA".freeze,
- "\u{2F9A2}"=>"\u83CC".freeze, "\u{2F9A3}"=>"\u83DC".freeze, "\u{2F9A4}"=>"\u{26C36}".freeze, "\u{2F9A5}"=>"\u{26D6B}".freeze, "\u{2F9A6}"=>"\u{26CD5}".freeze, "\u{2F9A7}"=>"\u452B".freeze, "\u{2F9A8}"=>"\u84F1".freeze, "\u{2F9A9}"=>"\u84F3".freeze,
- "\u{2F9AA}"=>"\u8516".freeze, "\u{2F9AB}"=>"\u{273CA}".freeze, "\u{2F9AC}"=>"\u8564".freeze, "\u{2F9AD}"=>"\u{26F2C}".freeze, "\u{2F9AE}"=>"\u455D".freeze, "\u{2F9AF}"=>"\u4561".freeze, "\u{2F9B0}"=>"\u{26FB1}".freeze, "\u{2F9B1}"=>"\u{270D2}".freeze,
- "\u{2F9B2}"=>"\u456B".freeze, "\u{2F9B3}"=>"\u8650".freeze, "\u{2F9B4}"=>"\u865C".freeze, "\u{2F9B5}"=>"\u8667".freeze, "\u{2F9B6}"=>"\u8669".freeze, "\u{2F9B7}"=>"\u86A9".freeze, "\u{2F9B8}"=>"\u8688".freeze, "\u{2F9B9}"=>"\u870E".freeze,
- "\u{2F9BA}"=>"\u86E2".freeze, "\u{2F9BB}"=>"\u8779".freeze, "\u{2F9BC}"=>"\u8728".freeze, "\u{2F9BD}"=>"\u876B".freeze, "\u{2F9BE}"=>"\u8786".freeze, "\u{2F9BF}"=>"\u45D7".freeze, "\u{2F9C0}"=>"\u87E1".freeze, "\u{2F9C1}"=>"\u8801".freeze,
- "\u{2F9C2}"=>"\u45F9".freeze, "\u{2F9C3}"=>"\u8860".freeze, "\u{2F9C4}"=>"\u8863".freeze, "\u{2F9C5}"=>"\u{27667}".freeze, "\u{2F9C6}"=>"\u88D7".freeze, "\u{2F9C7}"=>"\u88DE".freeze, "\u{2F9C8}"=>"\u4635".freeze, "\u{2F9C9}"=>"\u88FA".freeze,
- "\u{2F9CA}"=>"\u34BB".freeze, "\u{2F9CB}"=>"\u{278AE}".freeze, "\u{2F9CC}"=>"\u{27966}".freeze, "\u{2F9CD}"=>"\u46BE".freeze, "\u{2F9CE}"=>"\u46C7".freeze, "\u{2F9CF}"=>"\u8AA0".freeze, "\u{2F9D0}"=>"\u8AED".freeze, "\u{2F9D1}"=>"\u8B8A".freeze,
- "\u{2F9D2}"=>"\u8C55".freeze, "\u{2F9D3}"=>"\u{27CA8}".freeze, "\u{2F9D4}"=>"\u8CAB".freeze, "\u{2F9D5}"=>"\u8CC1".freeze, "\u{2F9D6}"=>"\u8D1B".freeze, "\u{2F9D7}"=>"\u8D77".freeze, "\u{2F9D8}"=>"\u{27F2F}".freeze, "\u{2F9D9}"=>"\u{20804}".freeze,
- "\u{2F9DA}"=>"\u8DCB".freeze, "\u{2F9DB}"=>"\u8DBC".freeze, "\u{2F9DC}"=>"\u8DF0".freeze, "\u{2F9DD}"=>"\u{208DE}".freeze, "\u{2F9DE}"=>"\u8ED4".freeze, "\u{2F9DF}"=>"\u8F38".freeze, "\u{2F9E0}"=>"\u{285D2}".freeze, "\u{2F9E1}"=>"\u{285ED}".freeze,
- "\u{2F9E2}"=>"\u9094".freeze, "\u{2F9E3}"=>"\u90F1".freeze, "\u{2F9E4}"=>"\u9111".freeze, "\u{2F9E5}"=>"\u{2872E}".freeze, "\u{2F9E6}"=>"\u911B".freeze, "\u{2F9E7}"=>"\u9238".freeze, "\u{2F9E8}"=>"\u92D7".freeze, "\u{2F9E9}"=>"\u92D8".freeze,
- "\u{2F9EA}"=>"\u927C".freeze, "\u{2F9EB}"=>"\u93F9".freeze, "\u{2F9EC}"=>"\u9415".freeze, "\u{2F9ED}"=>"\u{28BFA}".freeze, "\u{2F9EE}"=>"\u958B".freeze, "\u{2F9EF}"=>"\u4995".freeze, "\u{2F9F0}"=>"\u95B7".freeze, "\u{2F9F1}"=>"\u{28D77}".freeze,
- "\u{2F9F2}"=>"\u49E6".freeze, "\u{2F9F3}"=>"\u96C3".freeze, "\u{2F9F4}"=>"\u5DB2".freeze, "\u{2F9F5}"=>"\u9723".freeze, "\u{2F9F6}"=>"\u{29145}".freeze, "\u{2F9F7}"=>"\u{2921A}".freeze, "\u{2F9F8}"=>"\u4A6E".freeze, "\u{2F9F9}"=>"\u4A76".freeze,
- "\u{2F9FA}"=>"\u97E0".freeze, "\u{2F9FB}"=>"\u{2940A}".freeze, "\u{2F9FC}"=>"\u4AB2".freeze, "\u{2F9FD}"=>"\u{29496}".freeze, "\u{2F9FE}"=>"\u980B".freeze, "\u{2F9FF}"=>"\u980B".freeze, "\u{2FA00}"=>"\u9829".freeze, "\u{2FA01}"=>"\u{295B6}".freeze,
- "\u{2FA02}"=>"\u98E2".freeze, "\u{2FA03}"=>"\u4B33".freeze, "\u{2FA04}"=>"\u9929".freeze, "\u{2FA05}"=>"\u99A7".freeze, "\u{2FA06}"=>"\u99C2".freeze, "\u{2FA07}"=>"\u99FE".freeze, "\u{2FA08}"=>"\u4BCE".freeze, "\u{2FA09}"=>"\u{29B30}".freeze,
- "\u{2FA0A}"=>"\u9B12".freeze, "\u{2FA0B}"=>"\u9C40".freeze, "\u{2FA0C}"=>"\u9CFD".freeze, "\u{2FA0D}"=>"\u4CCE".freeze, "\u{2FA0E}"=>"\u4CED".freeze, "\u{2FA0F}"=>"\u9D67".freeze, "\u{2FA10}"=>"\u{2A0CE}".freeze, "\u{2FA11}"=>"\u4CF8".freeze,
- "\u{2FA12}"=>"\u{2A105}".freeze, "\u{2FA13}"=>"\u{2A20E}".freeze, "\u{2FA14}"=>"\u{2A291}".freeze, "\u{2FA15}"=>"\u9EBB".freeze, "\u{2FA16}"=>"\u4D56".freeze, "\u{2FA17}"=>"\u9EF9".freeze, "\u{2FA18}"=>"\u9EFE".freeze, "\u{2FA19}"=>"\u9F05".freeze,
- "\u{2FA1A}"=>"\u9F0F".freeze, "\u{2FA1B}"=>"\u9F16".freeze, "\u{2FA1C}"=>"\u9F3B".freeze, "\u{2FA1D}"=>"\u{2A600}".freeze,
- }.freeze
-
- KOMPATIBLE_TABLE = {
- "\u00A0"=>" ".freeze, "\u00A8"=>" \u0308".freeze, "\u00AA"=>"a".freeze, "\u00AF"=>" \u0304".freeze, "\u00B2"=>"2".freeze, "\u00B3"=>"3".freeze, "\u00B4"=>" \u0301".freeze, "\u00B5"=>"\u03BC".freeze,
- "\u00B8"=>" \u0327".freeze, "\u00B9"=>"1".freeze, "\u00BA"=>"o".freeze, "\u00BC"=>"1\u20444".freeze, "\u00BD"=>"1\u20442".freeze, "\u00BE"=>"3\u20444".freeze, "\u0132"=>"IJ".freeze, "\u0133"=>"ij".freeze,
- "\u013F"=>"L\u00B7".freeze, "\u0140"=>"l\u00B7".freeze, "\u0149"=>"\u02BCn".freeze, "\u017F"=>"s".freeze, "\u01C4"=>"D\u017D".freeze, "\u01C5"=>"D\u017E".freeze, "\u01C6"=>"d\u017E".freeze, "\u01C7"=>"LJ".freeze,
- "\u01C8"=>"Lj".freeze, "\u01C9"=>"lj".freeze, "\u01CA"=>"NJ".freeze, "\u01CB"=>"Nj".freeze, "\u01CC"=>"nj".freeze, "\u01F1"=>"DZ".freeze, "\u01F2"=>"Dz".freeze, "\u01F3"=>"dz".freeze,
- "\u02B0"=>"h".freeze, "\u02B1"=>"\u0266".freeze, "\u02B2"=>"j".freeze, "\u02B3"=>"r".freeze, "\u02B4"=>"\u0279".freeze, "\u02B5"=>"\u027B".freeze, "\u02B6"=>"\u0281".freeze, "\u02B7"=>"w".freeze,
- "\u02B8"=>"y".freeze, "\u02D8"=>" \u0306".freeze, "\u02D9"=>" \u0307".freeze, "\u02DA"=>" \u030A".freeze, "\u02DB"=>" \u0328".freeze, "\u02DC"=>" \u0303".freeze, "\u02DD"=>" \u030B".freeze, "\u02E0"=>"\u0263".freeze,
- "\u02E1"=>"l".freeze, "\u02E2"=>"s".freeze, "\u02E3"=>"x".freeze, "\u02E4"=>"\u0295".freeze, "\u037A"=>" \u0345".freeze, "\u0384"=>" \u0301".freeze, "\u03D0"=>"\u03B2".freeze, "\u03D1"=>"\u03B8".freeze,
- "\u03D2"=>"\u03A5".freeze, "\u03D5"=>"\u03C6".freeze, "\u03D6"=>"\u03C0".freeze, "\u03F0"=>"\u03BA".freeze, "\u03F1"=>"\u03C1".freeze, "\u03F2"=>"\u03C2".freeze, "\u03F4"=>"\u0398".freeze, "\u03F5"=>"\u03B5".freeze,
- "\u03F9"=>"\u03A3".freeze, "\u0587"=>"\u0565\u0582".freeze, "\u0675"=>"\u0627\u0674".freeze, "\u0676"=>"\u0648\u0674".freeze, "\u0677"=>"\u06C7\u0674".freeze, "\u0678"=>"\u064A\u0674".freeze, "\u0E33"=>"\u0E4D\u0E32".freeze, "\u0EB3"=>"\u0ECD\u0EB2".freeze,
- "\u0EDC"=>"\u0EAB\u0E99".freeze, "\u0EDD"=>"\u0EAB\u0EA1".freeze, "\u0F0C"=>"\u0F0B".freeze, "\u0F77"=>"\u0FB2\u0F81".freeze, "\u0F79"=>"\u0FB3\u0F81".freeze, "\u10FC"=>"\u10DC".freeze, "\u1D2C"=>"A".freeze, "\u1D2D"=>"\u00C6".freeze,
- "\u1D2E"=>"B".freeze, "\u1D30"=>"D".freeze, "\u1D31"=>"E".freeze, "\u1D32"=>"\u018E".freeze, "\u1D33"=>"G".freeze, "\u1D34"=>"H".freeze, "\u1D35"=>"I".freeze, "\u1D36"=>"J".freeze,
- "\u1D37"=>"K".freeze, "\u1D38"=>"L".freeze, "\u1D39"=>"M".freeze, "\u1D3A"=>"N".freeze, "\u1D3C"=>"O".freeze, "\u1D3D"=>"\u0222".freeze, "\u1D3E"=>"P".freeze, "\u1D3F"=>"R".freeze,
- "\u1D40"=>"T".freeze, "\u1D41"=>"U".freeze, "\u1D42"=>"W".freeze, "\u1D43"=>"a".freeze, "\u1D44"=>"\u0250".freeze, "\u1D45"=>"\u0251".freeze, "\u1D46"=>"\u1D02".freeze, "\u1D47"=>"b".freeze,
- "\u1D48"=>"d".freeze, "\u1D49"=>"e".freeze, "\u1D4A"=>"\u0259".freeze, "\u1D4B"=>"\u025B".freeze, "\u1D4C"=>"\u025C".freeze, "\u1D4D"=>"g".freeze, "\u1D4F"=>"k".freeze, "\u1D50"=>"m".freeze,
- "\u1D51"=>"\u014B".freeze, "\u1D52"=>"o".freeze, "\u1D53"=>"\u0254".freeze, "\u1D54"=>"\u1D16".freeze, "\u1D55"=>"\u1D17".freeze, "\u1D56"=>"p".freeze, "\u1D57"=>"t".freeze, "\u1D58"=>"u".freeze,
- "\u1D59"=>"\u1D1D".freeze, "\u1D5A"=>"\u026F".freeze, "\u1D5B"=>"v".freeze, "\u1D5C"=>"\u1D25".freeze, "\u1D5D"=>"\u03B2".freeze, "\u1D5E"=>"\u03B3".freeze, "\u1D5F"=>"\u03B4".freeze, "\u1D60"=>"\u03C6".freeze,
- "\u1D61"=>"\u03C7".freeze, "\u1D62"=>"i".freeze, "\u1D63"=>"r".freeze, "\u1D64"=>"u".freeze, "\u1D65"=>"v".freeze, "\u1D66"=>"\u03B2".freeze, "\u1D67"=>"\u03B3".freeze, "\u1D68"=>"\u03C1".freeze,
- "\u1D69"=>"\u03C6".freeze, "\u1D6A"=>"\u03C7".freeze, "\u1D78"=>"\u043D".freeze, "\u1D9B"=>"\u0252".freeze, "\u1D9C"=>"c".freeze, "\u1D9D"=>"\u0255".freeze, "\u1D9E"=>"\u00F0".freeze, "\u1D9F"=>"\u025C".freeze,
- "\u1DA0"=>"f".freeze, "\u1DA1"=>"\u025F".freeze, "\u1DA2"=>"\u0261".freeze, "\u1DA3"=>"\u0265".freeze, "\u1DA4"=>"\u0268".freeze, "\u1DA5"=>"\u0269".freeze, "\u1DA6"=>"\u026A".freeze, "\u1DA7"=>"\u1D7B".freeze,
- "\u1DA8"=>"\u029D".freeze, "\u1DA9"=>"\u026D".freeze, "\u1DAA"=>"\u1D85".freeze, "\u1DAB"=>"\u029F".freeze, "\u1DAC"=>"\u0271".freeze, "\u1DAD"=>"\u0270".freeze, "\u1DAE"=>"\u0272".freeze, "\u1DAF"=>"\u0273".freeze,
- "\u1DB0"=>"\u0274".freeze, "\u1DB1"=>"\u0275".freeze, "\u1DB2"=>"\u0278".freeze, "\u1DB3"=>"\u0282".freeze, "\u1DB4"=>"\u0283".freeze, "\u1DB5"=>"\u01AB".freeze, "\u1DB6"=>"\u0289".freeze, "\u1DB7"=>"\u028A".freeze,
- "\u1DB8"=>"\u1D1C".freeze, "\u1DB9"=>"\u028B".freeze, "\u1DBA"=>"\u028C".freeze, "\u1DBB"=>"z".freeze, "\u1DBC"=>"\u0290".freeze, "\u1DBD"=>"\u0291".freeze, "\u1DBE"=>"\u0292".freeze, "\u1DBF"=>"\u03B8".freeze,
- "\u1E9A"=>"a\u02BE".freeze, "\u1FBD"=>" \u0313".freeze, "\u1FBF"=>" \u0313".freeze, "\u1FC0"=>" \u0342".freeze, "\u1FFE"=>" \u0314".freeze, "\u2002"=>" ".freeze, "\u2003"=>" ".freeze, "\u2004"=>" ".freeze,
- "\u2005"=>" ".freeze, "\u2006"=>" ".freeze, "\u2007"=>" ".freeze, "\u2008"=>" ".freeze, "\u2009"=>" ".freeze, "\u200A"=>" ".freeze, "\u2011"=>"\u2010".freeze, "\u2017"=>" \u0333".freeze,
- "\u2024"=>".".freeze, "\u2025"=>"..".freeze, "\u2026"=>"...".freeze, "\u202F"=>" ".freeze, "\u2033"=>"\u2032\u2032".freeze, "\u2034"=>"\u2032\u2032\u2032".freeze, "\u2036"=>"\u2035\u2035".freeze, "\u2037"=>"\u2035\u2035\u2035".freeze,
- "\u203C"=>"!!".freeze, "\u203E"=>" \u0305".freeze, "\u2047"=>"??".freeze, "\u2048"=>"?!".freeze, "\u2049"=>"!?".freeze, "\u2057"=>"\u2032\u2032\u2032\u2032".freeze, "\u205F"=>" ".freeze, "\u2070"=>"0".freeze,
- "\u2071"=>"i".freeze, "\u2074"=>"4".freeze, "\u2075"=>"5".freeze, "\u2076"=>"6".freeze, "\u2077"=>"7".freeze, "\u2078"=>"8".freeze, "\u2079"=>"9".freeze, "\u207A"=>"+".freeze,
- "\u207B"=>"\u2212".freeze, "\u207C"=>"=".freeze, "\u207D"=>"(".freeze, "\u207E"=>")".freeze, "\u207F"=>"n".freeze, "\u2080"=>"0".freeze, "\u2081"=>"1".freeze, "\u2082"=>"2".freeze,
- "\u2083"=>"3".freeze, "\u2084"=>"4".freeze, "\u2085"=>"5".freeze, "\u2086"=>"6".freeze, "\u2087"=>"7".freeze, "\u2088"=>"8".freeze, "\u2089"=>"9".freeze, "\u208A"=>"+".freeze,
- "\u208B"=>"\u2212".freeze, "\u208C"=>"=".freeze, "\u208D"=>"(".freeze, "\u208E"=>")".freeze, "\u2090"=>"a".freeze, "\u2091"=>"e".freeze, "\u2092"=>"o".freeze, "\u2093"=>"x".freeze,
- "\u2094"=>"\u0259".freeze, "\u2095"=>"h".freeze, "\u2096"=>"k".freeze, "\u2097"=>"l".freeze, "\u2098"=>"m".freeze, "\u2099"=>"n".freeze, "\u209A"=>"p".freeze, "\u209B"=>"s".freeze,
- "\u209C"=>"t".freeze, "\u20A8"=>"Rs".freeze, "\u2100"=>"a/c".freeze, "\u2101"=>"a/s".freeze, "\u2102"=>"C".freeze, "\u2103"=>"\u00B0C".freeze, "\u2105"=>"c/o".freeze, "\u2106"=>"c/u".freeze,
- "\u2107"=>"\u0190".freeze, "\u2109"=>"\u00B0F".freeze, "\u210A"=>"g".freeze, "\u210B"=>"H".freeze, "\u210C"=>"H".freeze, "\u210D"=>"H".freeze, "\u210E"=>"h".freeze, "\u210F"=>"\u0127".freeze,
- "\u2110"=>"I".freeze, "\u2111"=>"I".freeze, "\u2112"=>"L".freeze, "\u2113"=>"l".freeze, "\u2115"=>"N".freeze, "\u2116"=>"No".freeze, "\u2119"=>"P".freeze, "\u211A"=>"Q".freeze,
- "\u211B"=>"R".freeze, "\u211C"=>"R".freeze, "\u211D"=>"R".freeze, "\u2120"=>"SM".freeze, "\u2121"=>"TEL".freeze, "\u2122"=>"TM".freeze, "\u2124"=>"Z".freeze, "\u2128"=>"Z".freeze,
- "\u212C"=>"B".freeze, "\u212D"=>"C".freeze, "\u212F"=>"e".freeze, "\u2130"=>"E".freeze, "\u2131"=>"F".freeze, "\u2133"=>"M".freeze, "\u2134"=>"o".freeze, "\u2135"=>"\u05D0".freeze,
- "\u2136"=>"\u05D1".freeze, "\u2137"=>"\u05D2".freeze, "\u2138"=>"\u05D3".freeze, "\u2139"=>"i".freeze, "\u213B"=>"FAX".freeze, "\u213C"=>"\u03C0".freeze, "\u213D"=>"\u03B3".freeze, "\u213E"=>"\u0393".freeze,
- "\u213F"=>"\u03A0".freeze, "\u2140"=>"\u2211".freeze, "\u2145"=>"D".freeze, "\u2146"=>"d".freeze, "\u2147"=>"e".freeze, "\u2148"=>"i".freeze, "\u2149"=>"j".freeze, "\u2150"=>"1\u20447".freeze,
- "\u2151"=>"1\u20449".freeze, "\u2152"=>"1\u204410".freeze, "\u2153"=>"1\u20443".freeze, "\u2154"=>"2\u20443".freeze, "\u2155"=>"1\u20445".freeze, "\u2156"=>"2\u20445".freeze, "\u2157"=>"3\u20445".freeze, "\u2158"=>"4\u20445".freeze,
- "\u2159"=>"1\u20446".freeze, "\u215A"=>"5\u20446".freeze, "\u215B"=>"1\u20448".freeze, "\u215C"=>"3\u20448".freeze, "\u215D"=>"5\u20448".freeze, "\u215E"=>"7\u20448".freeze, "\u215F"=>"1\u2044".freeze, "\u2160"=>"I".freeze,
- "\u2161"=>"II".freeze, "\u2162"=>"III".freeze, "\u2163"=>"IV".freeze, "\u2164"=>"V".freeze, "\u2165"=>"VI".freeze, "\u2166"=>"VII".freeze, "\u2167"=>"VIII".freeze, "\u2168"=>"IX".freeze,
- "\u2169"=>"X".freeze, "\u216A"=>"XI".freeze, "\u216B"=>"XII".freeze, "\u216C"=>"L".freeze, "\u216D"=>"C".freeze, "\u216E"=>"D".freeze, "\u216F"=>"M".freeze, "\u2170"=>"i".freeze,
- "\u2171"=>"ii".freeze, "\u2172"=>"iii".freeze, "\u2173"=>"iv".freeze, "\u2174"=>"v".freeze, "\u2175"=>"vi".freeze, "\u2176"=>"vii".freeze, "\u2177"=>"viii".freeze, "\u2178"=>"ix".freeze,
- "\u2179"=>"x".freeze, "\u217A"=>"xi".freeze, "\u217B"=>"xii".freeze, "\u217C"=>"l".freeze, "\u217D"=>"c".freeze, "\u217E"=>"d".freeze, "\u217F"=>"m".freeze, "\u2189"=>"0\u20443".freeze,
- "\u222C"=>"\u222B\u222B".freeze, "\u222D"=>"\u222B\u222B\u222B".freeze, "\u222F"=>"\u222E\u222E".freeze, "\u2230"=>"\u222E\u222E\u222E".freeze, "\u2460"=>"1".freeze, "\u2461"=>"2".freeze, "\u2462"=>"3".freeze, "\u2463"=>"4".freeze,
- "\u2464"=>"5".freeze, "\u2465"=>"6".freeze, "\u2466"=>"7".freeze, "\u2467"=>"8".freeze, "\u2468"=>"9".freeze, "\u2469"=>"10".freeze, "\u246A"=>"11".freeze, "\u246B"=>"12".freeze,
- "\u246C"=>"13".freeze, "\u246D"=>"14".freeze, "\u246E"=>"15".freeze, "\u246F"=>"16".freeze, "\u2470"=>"17".freeze, "\u2471"=>"18".freeze, "\u2472"=>"19".freeze, "\u2473"=>"20".freeze,
- "\u2474"=>"(1)".freeze, "\u2475"=>"(2)".freeze, "\u2476"=>"(3)".freeze, "\u2477"=>"(4)".freeze, "\u2478"=>"(5)".freeze, "\u2479"=>"(6)".freeze, "\u247A"=>"(7)".freeze, "\u247B"=>"(8)".freeze,
- "\u247C"=>"(9)".freeze, "\u247D"=>"(10)".freeze, "\u247E"=>"(11)".freeze, "\u247F"=>"(12)".freeze, "\u2480"=>"(13)".freeze, "\u2481"=>"(14)".freeze, "\u2482"=>"(15)".freeze, "\u2483"=>"(16)".freeze,
- "\u2484"=>"(17)".freeze, "\u2485"=>"(18)".freeze, "\u2486"=>"(19)".freeze, "\u2487"=>"(20)".freeze, "\u2488"=>"1.".freeze, "\u2489"=>"2.".freeze, "\u248A"=>"3.".freeze, "\u248B"=>"4.".freeze,
- "\u248C"=>"5.".freeze, "\u248D"=>"6.".freeze, "\u248E"=>"7.".freeze, "\u248F"=>"8.".freeze, "\u2490"=>"9.".freeze, "\u2491"=>"10.".freeze, "\u2492"=>"11.".freeze, "\u2493"=>"12.".freeze,
- "\u2494"=>"13.".freeze, "\u2495"=>"14.".freeze, "\u2496"=>"15.".freeze, "\u2497"=>"16.".freeze, "\u2498"=>"17.".freeze, "\u2499"=>"18.".freeze, "\u249A"=>"19.".freeze, "\u249B"=>"20.".freeze,
- "\u249C"=>"(a)".freeze, "\u249D"=>"(b)".freeze, "\u249E"=>"(c)".freeze, "\u249F"=>"(d)".freeze, "\u24A0"=>"(e)".freeze, "\u24A1"=>"(f)".freeze, "\u24A2"=>"(g)".freeze, "\u24A3"=>"(h)".freeze,
- "\u24A4"=>"(i)".freeze, "\u24A5"=>"(j)".freeze, "\u24A6"=>"(k)".freeze, "\u24A7"=>"(l)".freeze, "\u24A8"=>"(m)".freeze, "\u24A9"=>"(n)".freeze, "\u24AA"=>"(o)".freeze, "\u24AB"=>"(p)".freeze,
- "\u24AC"=>"(q)".freeze, "\u24AD"=>"(r)".freeze, "\u24AE"=>"(s)".freeze, "\u24AF"=>"(t)".freeze, "\u24B0"=>"(u)".freeze, "\u24B1"=>"(v)".freeze, "\u24B2"=>"(w)".freeze, "\u24B3"=>"(x)".freeze,
- "\u24B4"=>"(y)".freeze, "\u24B5"=>"(z)".freeze, "\u24B6"=>"A".freeze, "\u24B7"=>"B".freeze, "\u24B8"=>"C".freeze, "\u24B9"=>"D".freeze, "\u24BA"=>"E".freeze, "\u24BB"=>"F".freeze,
- "\u24BC"=>"G".freeze, "\u24BD"=>"H".freeze, "\u24BE"=>"I".freeze, "\u24BF"=>"J".freeze, "\u24C0"=>"K".freeze, "\u24C1"=>"L".freeze, "\u24C2"=>"M".freeze, "\u24C3"=>"N".freeze,
- "\u24C4"=>"O".freeze, "\u24C5"=>"P".freeze, "\u24C6"=>"Q".freeze, "\u24C7"=>"R".freeze, "\u24C8"=>"S".freeze, "\u24C9"=>"T".freeze, "\u24CA"=>"U".freeze, "\u24CB"=>"V".freeze,
- "\u24CC"=>"W".freeze, "\u24CD"=>"X".freeze, "\u24CE"=>"Y".freeze, "\u24CF"=>"Z".freeze, "\u24D0"=>"a".freeze, "\u24D1"=>"b".freeze, "\u24D2"=>"c".freeze, "\u24D3"=>"d".freeze,
- "\u24D4"=>"e".freeze, "\u24D5"=>"f".freeze, "\u24D6"=>"g".freeze, "\u24D7"=>"h".freeze, "\u24D8"=>"i".freeze, "\u24D9"=>"j".freeze, "\u24DA"=>"k".freeze, "\u24DB"=>"l".freeze,
- "\u24DC"=>"m".freeze, "\u24DD"=>"n".freeze, "\u24DE"=>"o".freeze, "\u24DF"=>"p".freeze, "\u24E0"=>"q".freeze, "\u24E1"=>"r".freeze, "\u24E2"=>"s".freeze, "\u24E3"=>"t".freeze,
- "\u24E4"=>"u".freeze, "\u24E5"=>"v".freeze, "\u24E6"=>"w".freeze, "\u24E7"=>"x".freeze, "\u24E8"=>"y".freeze, "\u24E9"=>"z".freeze, "\u24EA"=>"0".freeze, "\u2A0C"=>"\u222B\u222B\u222B\u222B".freeze,
- "\u2A74"=>"::=".freeze, "\u2A75"=>"==".freeze, "\u2A76"=>"===".freeze, "\u2C7C"=>"j".freeze, "\u2C7D"=>"V".freeze, "\u2D6F"=>"\u2D61".freeze, "\u2E9F"=>"\u6BCD".freeze, "\u2EF3"=>"\u9F9F".freeze,
- "\u2F00"=>"\u4E00".freeze, "\u2F01"=>"\u4E28".freeze, "\u2F02"=>"\u4E36".freeze, "\u2F03"=>"\u4E3F".freeze, "\u2F04"=>"\u4E59".freeze, "\u2F05"=>"\u4E85".freeze, "\u2F06"=>"\u4E8C".freeze, "\u2F07"=>"\u4EA0".freeze,
- "\u2F08"=>"\u4EBA".freeze, "\u2F09"=>"\u513F".freeze, "\u2F0A"=>"\u5165".freeze, "\u2F0B"=>"\u516B".freeze, "\u2F0C"=>"\u5182".freeze, "\u2F0D"=>"\u5196".freeze, "\u2F0E"=>"\u51AB".freeze, "\u2F0F"=>"\u51E0".freeze,
- "\u2F10"=>"\u51F5".freeze, "\u2F11"=>"\u5200".freeze, "\u2F12"=>"\u529B".freeze, "\u2F13"=>"\u52F9".freeze, "\u2F14"=>"\u5315".freeze, "\u2F15"=>"\u531A".freeze, "\u2F16"=>"\u5338".freeze, "\u2F17"=>"\u5341".freeze,
- "\u2F18"=>"\u535C".freeze, "\u2F19"=>"\u5369".freeze, "\u2F1A"=>"\u5382".freeze, "\u2F1B"=>"\u53B6".freeze, "\u2F1C"=>"\u53C8".freeze, "\u2F1D"=>"\u53E3".freeze, "\u2F1E"=>"\u56D7".freeze, "\u2F1F"=>"\u571F".freeze,
- "\u2F20"=>"\u58EB".freeze, "\u2F21"=>"\u5902".freeze, "\u2F22"=>"\u590A".freeze, "\u2F23"=>"\u5915".freeze, "\u2F24"=>"\u5927".freeze, "\u2F25"=>"\u5973".freeze, "\u2F26"=>"\u5B50".freeze, "\u2F27"=>"\u5B80".freeze,
- "\u2F28"=>"\u5BF8".freeze, "\u2F29"=>"\u5C0F".freeze, "\u2F2A"=>"\u5C22".freeze, "\u2F2B"=>"\u5C38".freeze, "\u2F2C"=>"\u5C6E".freeze, "\u2F2D"=>"\u5C71".freeze, "\u2F2E"=>"\u5DDB".freeze, "\u2F2F"=>"\u5DE5".freeze,
- "\u2F30"=>"\u5DF1".freeze, "\u2F31"=>"\u5DFE".freeze, "\u2F32"=>"\u5E72".freeze, "\u2F33"=>"\u5E7A".freeze, "\u2F34"=>"\u5E7F".freeze, "\u2F35"=>"\u5EF4".freeze, "\u2F36"=>"\u5EFE".freeze, "\u2F37"=>"\u5F0B".freeze,
- "\u2F38"=>"\u5F13".freeze, "\u2F39"=>"\u5F50".freeze, "\u2F3A"=>"\u5F61".freeze, "\u2F3B"=>"\u5F73".freeze, "\u2F3C"=>"\u5FC3".freeze, "\u2F3D"=>"\u6208".freeze, "\u2F3E"=>"\u6236".freeze, "\u2F3F"=>"\u624B".freeze,
- "\u2F40"=>"\u652F".freeze, "\u2F41"=>"\u6534".freeze, "\u2F42"=>"\u6587".freeze, "\u2F43"=>"\u6597".freeze, "\u2F44"=>"\u65A4".freeze, "\u2F45"=>"\u65B9".freeze, "\u2F46"=>"\u65E0".freeze, "\u2F47"=>"\u65E5".freeze,
- "\u2F48"=>"\u66F0".freeze, "\u2F49"=>"\u6708".freeze, "\u2F4A"=>"\u6728".freeze, "\u2F4B"=>"\u6B20".freeze, "\u2F4C"=>"\u6B62".freeze, "\u2F4D"=>"\u6B79".freeze, "\u2F4E"=>"\u6BB3".freeze, "\u2F4F"=>"\u6BCB".freeze,
- "\u2F50"=>"\u6BD4".freeze, "\u2F51"=>"\u6BDB".freeze, "\u2F52"=>"\u6C0F".freeze, "\u2F53"=>"\u6C14".freeze, "\u2F54"=>"\u6C34".freeze, "\u2F55"=>"\u706B".freeze, "\u2F56"=>"\u722A".freeze, "\u2F57"=>"\u7236".freeze,
- "\u2F58"=>"\u723B".freeze, "\u2F59"=>"\u723F".freeze, "\u2F5A"=>"\u7247".freeze, "\u2F5B"=>"\u7259".freeze, "\u2F5C"=>"\u725B".freeze, "\u2F5D"=>"\u72AC".freeze, "\u2F5E"=>"\u7384".freeze, "\u2F5F"=>"\u7389".freeze,
- "\u2F60"=>"\u74DC".freeze, "\u2F61"=>"\u74E6".freeze, "\u2F62"=>"\u7518".freeze, "\u2F63"=>"\u751F".freeze, "\u2F64"=>"\u7528".freeze, "\u2F65"=>"\u7530".freeze, "\u2F66"=>"\u758B".freeze, "\u2F67"=>"\u7592".freeze,
- "\u2F68"=>"\u7676".freeze, "\u2F69"=>"\u767D".freeze, "\u2F6A"=>"\u76AE".freeze, "\u2F6B"=>"\u76BF".freeze, "\u2F6C"=>"\u76EE".freeze, "\u2F6D"=>"\u77DB".freeze, "\u2F6E"=>"\u77E2".freeze, "\u2F6F"=>"\u77F3".freeze,
- "\u2F70"=>"\u793A".freeze, "\u2F71"=>"\u79B8".freeze, "\u2F72"=>"\u79BE".freeze, "\u2F73"=>"\u7A74".freeze, "\u2F74"=>"\u7ACB".freeze, "\u2F75"=>"\u7AF9".freeze, "\u2F76"=>"\u7C73".freeze, "\u2F77"=>"\u7CF8".freeze,
- "\u2F78"=>"\u7F36".freeze, "\u2F79"=>"\u7F51".freeze, "\u2F7A"=>"\u7F8A".freeze, "\u2F7B"=>"\u7FBD".freeze, "\u2F7C"=>"\u8001".freeze, "\u2F7D"=>"\u800C".freeze, "\u2F7E"=>"\u8012".freeze, "\u2F7F"=>"\u8033".freeze,
- "\u2F80"=>"\u807F".freeze, "\u2F81"=>"\u8089".freeze, "\u2F82"=>"\u81E3".freeze, "\u2F83"=>"\u81EA".freeze, "\u2F84"=>"\u81F3".freeze, "\u2F85"=>"\u81FC".freeze, "\u2F86"=>"\u820C".freeze, "\u2F87"=>"\u821B".freeze,
- "\u2F88"=>"\u821F".freeze, "\u2F89"=>"\u826E".freeze, "\u2F8A"=>"\u8272".freeze, "\u2F8B"=>"\u8278".freeze, "\u2F8C"=>"\u864D".freeze, "\u2F8D"=>"\u866B".freeze, "\u2F8E"=>"\u8840".freeze, "\u2F8F"=>"\u884C".freeze,
- "\u2F90"=>"\u8863".freeze, "\u2F91"=>"\u897E".freeze, "\u2F92"=>"\u898B".freeze, "\u2F93"=>"\u89D2".freeze, "\u2F94"=>"\u8A00".freeze, "\u2F95"=>"\u8C37".freeze, "\u2F96"=>"\u8C46".freeze, "\u2F97"=>"\u8C55".freeze,
- "\u2F98"=>"\u8C78".freeze, "\u2F99"=>"\u8C9D".freeze, "\u2F9A"=>"\u8D64".freeze, "\u2F9B"=>"\u8D70".freeze, "\u2F9C"=>"\u8DB3".freeze, "\u2F9D"=>"\u8EAB".freeze, "\u2F9E"=>"\u8ECA".freeze, "\u2F9F"=>"\u8F9B".freeze,
- "\u2FA0"=>"\u8FB0".freeze, "\u2FA1"=>"\u8FB5".freeze, "\u2FA2"=>"\u9091".freeze, "\u2FA3"=>"\u9149".freeze, "\u2FA4"=>"\u91C6".freeze, "\u2FA5"=>"\u91CC".freeze, "\u2FA6"=>"\u91D1".freeze, "\u2FA7"=>"\u9577".freeze,
- "\u2FA8"=>"\u9580".freeze, "\u2FA9"=>"\u961C".freeze, "\u2FAA"=>"\u96B6".freeze, "\u2FAB"=>"\u96B9".freeze, "\u2FAC"=>"\u96E8".freeze, "\u2FAD"=>"\u9751".freeze, "\u2FAE"=>"\u975E".freeze, "\u2FAF"=>"\u9762".freeze,
- "\u2FB0"=>"\u9769".freeze, "\u2FB1"=>"\u97CB".freeze, "\u2FB2"=>"\u97ED".freeze, "\u2FB3"=>"\u97F3".freeze, "\u2FB4"=>"\u9801".freeze, "\u2FB5"=>"\u98A8".freeze, "\u2FB6"=>"\u98DB".freeze, "\u2FB7"=>"\u98DF".freeze,
- "\u2FB8"=>"\u9996".freeze, "\u2FB9"=>"\u9999".freeze, "\u2FBA"=>"\u99AC".freeze, "\u2FBB"=>"\u9AA8".freeze, "\u2FBC"=>"\u9AD8".freeze, "\u2FBD"=>"\u9ADF".freeze, "\u2FBE"=>"\u9B25".freeze, "\u2FBF"=>"\u9B2F".freeze,
- "\u2FC0"=>"\u9B32".freeze, "\u2FC1"=>"\u9B3C".freeze, "\u2FC2"=>"\u9B5A".freeze, "\u2FC3"=>"\u9CE5".freeze, "\u2FC4"=>"\u9E75".freeze, "\u2FC5"=>"\u9E7F".freeze, "\u2FC6"=>"\u9EA5".freeze, "\u2FC7"=>"\u9EBB".freeze,
- "\u2FC8"=>"\u9EC3".freeze, "\u2FC9"=>"\u9ECD".freeze, "\u2FCA"=>"\u9ED1".freeze, "\u2FCB"=>"\u9EF9".freeze, "\u2FCC"=>"\u9EFD".freeze, "\u2FCD"=>"\u9F0E".freeze, "\u2FCE"=>"\u9F13".freeze, "\u2FCF"=>"\u9F20".freeze,
- "\u2FD0"=>"\u9F3B".freeze, "\u2FD1"=>"\u9F4A".freeze, "\u2FD2"=>"\u9F52".freeze, "\u2FD3"=>"\u9F8D".freeze, "\u2FD4"=>"\u9F9C".freeze, "\u2FD5"=>"\u9FA0".freeze, "\u3000"=>" ".freeze, "\u3036"=>"\u3012".freeze,
- "\u3038"=>"\u5341".freeze, "\u3039"=>"\u5344".freeze, "\u303A"=>"\u5345".freeze, "\u309B"=>" \u3099".freeze, "\u309C"=>" \u309A".freeze, "\u309F"=>"\u3088\u308A".freeze, "\u30FF"=>"\u30B3\u30C8".freeze, "\u3131"=>"\u1100".freeze,
- "\u3132"=>"\u1101".freeze, "\u3133"=>"\u11AA".freeze, "\u3134"=>"\u1102".freeze, "\u3135"=>"\u11AC".freeze, "\u3136"=>"\u11AD".freeze, "\u3137"=>"\u1103".freeze, "\u3138"=>"\u1104".freeze, "\u3139"=>"\u1105".freeze,
- "\u313A"=>"\u11B0".freeze, "\u313B"=>"\u11B1".freeze, "\u313C"=>"\u11B2".freeze, "\u313D"=>"\u11B3".freeze, "\u313E"=>"\u11B4".freeze, "\u313F"=>"\u11B5".freeze, "\u3140"=>"\u111A".freeze, "\u3141"=>"\u1106".freeze,
- "\u3142"=>"\u1107".freeze, "\u3143"=>"\u1108".freeze, "\u3144"=>"\u1121".freeze, "\u3145"=>"\u1109".freeze, "\u3146"=>"\u110A".freeze, "\u3147"=>"\u110B".freeze, "\u3148"=>"\u110C".freeze, "\u3149"=>"\u110D".freeze,
- "\u314A"=>"\u110E".freeze, "\u314B"=>"\u110F".freeze, "\u314C"=>"\u1110".freeze, "\u314D"=>"\u1111".freeze, "\u314E"=>"\u1112".freeze, "\u314F"=>"\u1161".freeze, "\u3150"=>"\u1162".freeze, "\u3151"=>"\u1163".freeze,
- "\u3152"=>"\u1164".freeze, "\u3153"=>"\u1165".freeze, "\u3154"=>"\u1166".freeze, "\u3155"=>"\u1167".freeze, "\u3156"=>"\u1168".freeze, "\u3157"=>"\u1169".freeze, "\u3158"=>"\u116A".freeze, "\u3159"=>"\u116B".freeze,
- "\u315A"=>"\u116C".freeze, "\u315B"=>"\u116D".freeze, "\u315C"=>"\u116E".freeze, "\u315D"=>"\u116F".freeze, "\u315E"=>"\u1170".freeze, "\u315F"=>"\u1171".freeze, "\u3160"=>"\u1172".freeze, "\u3161"=>"\u1173".freeze,
- "\u3162"=>"\u1174".freeze, "\u3163"=>"\u1175".freeze, "\u3164"=>"\u1160".freeze, "\u3165"=>"\u1114".freeze, "\u3166"=>"\u1115".freeze, "\u3167"=>"\u11C7".freeze, "\u3168"=>"\u11C8".freeze, "\u3169"=>"\u11CC".freeze,
- "\u316A"=>"\u11CE".freeze, "\u316B"=>"\u11D3".freeze, "\u316C"=>"\u11D7".freeze, "\u316D"=>"\u11D9".freeze, "\u316E"=>"\u111C".freeze, "\u316F"=>"\u11DD".freeze, "\u3170"=>"\u11DF".freeze, "\u3171"=>"\u111D".freeze,
- "\u3172"=>"\u111E".freeze, "\u3173"=>"\u1120".freeze, "\u3174"=>"\u1122".freeze, "\u3175"=>"\u1123".freeze, "\u3176"=>"\u1127".freeze, "\u3177"=>"\u1129".freeze, "\u3178"=>"\u112B".freeze, "\u3179"=>"\u112C".freeze,
- "\u317A"=>"\u112D".freeze, "\u317B"=>"\u112E".freeze, "\u317C"=>"\u112F".freeze, "\u317D"=>"\u1132".freeze, "\u317E"=>"\u1136".freeze, "\u317F"=>"\u1140".freeze, "\u3180"=>"\u1147".freeze, "\u3181"=>"\u114C".freeze,
- "\u3182"=>"\u11F1".freeze, "\u3183"=>"\u11F2".freeze, "\u3184"=>"\u1157".freeze, "\u3185"=>"\u1158".freeze, "\u3186"=>"\u1159".freeze, "\u3187"=>"\u1184".freeze, "\u3188"=>"\u1185".freeze, "\u3189"=>"\u1188".freeze,
- "\u318A"=>"\u1191".freeze, "\u318B"=>"\u1192".freeze, "\u318C"=>"\u1194".freeze, "\u318D"=>"\u119E".freeze, "\u318E"=>"\u11A1".freeze, "\u3192"=>"\u4E00".freeze, "\u3193"=>"\u4E8C".freeze, "\u3194"=>"\u4E09".freeze,
- "\u3195"=>"\u56DB".freeze, "\u3196"=>"\u4E0A".freeze, "\u3197"=>"\u4E2D".freeze, "\u3198"=>"\u4E0B".freeze, "\u3199"=>"\u7532".freeze, "\u319A"=>"\u4E59".freeze, "\u319B"=>"\u4E19".freeze, "\u319C"=>"\u4E01".freeze,
- "\u319D"=>"\u5929".freeze, "\u319E"=>"\u5730".freeze, "\u319F"=>"\u4EBA".freeze, "\u3200"=>"(\u1100)".freeze, "\u3201"=>"(\u1102)".freeze, "\u3202"=>"(\u1103)".freeze, "\u3203"=>"(\u1105)".freeze, "\u3204"=>"(\u1106)".freeze,
- "\u3205"=>"(\u1107)".freeze, "\u3206"=>"(\u1109)".freeze, "\u3207"=>"(\u110B)".freeze, "\u3208"=>"(\u110C)".freeze, "\u3209"=>"(\u110E)".freeze, "\u320A"=>"(\u110F)".freeze, "\u320B"=>"(\u1110)".freeze, "\u320C"=>"(\u1111)".freeze,
- "\u320D"=>"(\u1112)".freeze, "\u320E"=>"(\u1100\u1161)".freeze, "\u320F"=>"(\u1102\u1161)".freeze, "\u3210"=>"(\u1103\u1161)".freeze, "\u3211"=>"(\u1105\u1161)".freeze, "\u3212"=>"(\u1106\u1161)".freeze, "\u3213"=>"(\u1107\u1161)".freeze, "\u3214"=>"(\u1109\u1161)".freeze,
- "\u3215"=>"(\u110B\u1161)".freeze, "\u3216"=>"(\u110C\u1161)".freeze, "\u3217"=>"(\u110E\u1161)".freeze, "\u3218"=>"(\u110F\u1161)".freeze, "\u3219"=>"(\u1110\u1161)".freeze, "\u321A"=>"(\u1111\u1161)".freeze, "\u321B"=>"(\u1112\u1161)".freeze, "\u321C"=>"(\u110C\u116E)".freeze,
- "\u321D"=>"(\u110B\u1169\u110C\u1165\u11AB)".freeze, "\u321E"=>"(\u110B\u1169\u1112\u116E)".freeze, "\u3220"=>"(\u4E00)".freeze, "\u3221"=>"(\u4E8C)".freeze, "\u3222"=>"(\u4E09)".freeze, "\u3223"=>"(\u56DB)".freeze, "\u3224"=>"(\u4E94)".freeze, "\u3225"=>"(\u516D)".freeze,
- "\u3226"=>"(\u4E03)".freeze, "\u3227"=>"(\u516B)".freeze, "\u3228"=>"(\u4E5D)".freeze, "\u3229"=>"(\u5341)".freeze, "\u322A"=>"(\u6708)".freeze, "\u322B"=>"(\u706B)".freeze, "\u322C"=>"(\u6C34)".freeze, "\u322D"=>"(\u6728)".freeze,
- "\u322E"=>"(\u91D1)".freeze, "\u322F"=>"(\u571F)".freeze, "\u3230"=>"(\u65E5)".freeze, "\u3231"=>"(\u682A)".freeze, "\u3232"=>"(\u6709)".freeze, "\u3233"=>"(\u793E)".freeze, "\u3234"=>"(\u540D)".freeze, "\u3235"=>"(\u7279)".freeze,
- "\u3236"=>"(\u8CA1)".freeze, "\u3237"=>"(\u795D)".freeze, "\u3238"=>"(\u52B4)".freeze, "\u3239"=>"(\u4EE3)".freeze, "\u323A"=>"(\u547C)".freeze, "\u323B"=>"(\u5B66)".freeze, "\u323C"=>"(\u76E3)".freeze, "\u323D"=>"(\u4F01)".freeze,
- "\u323E"=>"(\u8CC7)".freeze, "\u323F"=>"(\u5354)".freeze, "\u3240"=>"(\u796D)".freeze, "\u3241"=>"(\u4F11)".freeze, "\u3242"=>"(\u81EA)".freeze, "\u3243"=>"(\u81F3)".freeze, "\u3244"=>"\u554F".freeze, "\u3245"=>"\u5E7C".freeze,
- "\u3246"=>"\u6587".freeze, "\u3247"=>"\u7B8F".freeze, "\u3250"=>"PTE".freeze, "\u3251"=>"21".freeze, "\u3252"=>"22".freeze, "\u3253"=>"23".freeze, "\u3254"=>"24".freeze, "\u3255"=>"25".freeze,
- "\u3256"=>"26".freeze, "\u3257"=>"27".freeze, "\u3258"=>"28".freeze, "\u3259"=>"29".freeze, "\u325A"=>"30".freeze, "\u325B"=>"31".freeze, "\u325C"=>"32".freeze, "\u325D"=>"33".freeze,
- "\u325E"=>"34".freeze, "\u325F"=>"35".freeze, "\u3260"=>"\u1100".freeze, "\u3261"=>"\u1102".freeze, "\u3262"=>"\u1103".freeze, "\u3263"=>"\u1105".freeze, "\u3264"=>"\u1106".freeze, "\u3265"=>"\u1107".freeze,
- "\u3266"=>"\u1109".freeze, "\u3267"=>"\u110B".freeze, "\u3268"=>"\u110C".freeze, "\u3269"=>"\u110E".freeze, "\u326A"=>"\u110F".freeze, "\u326B"=>"\u1110".freeze, "\u326C"=>"\u1111".freeze, "\u326D"=>"\u1112".freeze,
- "\u326E"=>"\u1100\u1161".freeze, "\u326F"=>"\u1102\u1161".freeze, "\u3270"=>"\u1103\u1161".freeze, "\u3271"=>"\u1105\u1161".freeze, "\u3272"=>"\u1106\u1161".freeze, "\u3273"=>"\u1107\u1161".freeze, "\u3274"=>"\u1109\u1161".freeze, "\u3275"=>"\u110B\u1161".freeze,
- "\u3276"=>"\u110C\u1161".freeze, "\u3277"=>"\u110E\u1161".freeze, "\u3278"=>"\u110F\u1161".freeze, "\u3279"=>"\u1110\u1161".freeze, "\u327A"=>"\u1111\u1161".freeze, "\u327B"=>"\u1112\u1161".freeze, "\u327C"=>"\u110E\u1161\u11B7\u1100\u1169".freeze, "\u327D"=>"\u110C\u116E\u110B\u1174".freeze,
- "\u327E"=>"\u110B\u116E".freeze, "\u3280"=>"\u4E00".freeze, "\u3281"=>"\u4E8C".freeze, "\u3282"=>"\u4E09".freeze, "\u3283"=>"\u56DB".freeze, "\u3284"=>"\u4E94".freeze, "\u3285"=>"\u516D".freeze, "\u3286"=>"\u4E03".freeze,
- "\u3287"=>"\u516B".freeze, "\u3288"=>"\u4E5D".freeze, "\u3289"=>"\u5341".freeze, "\u328A"=>"\u6708".freeze, "\u328B"=>"\u706B".freeze, "\u328C"=>"\u6C34".freeze, "\u328D"=>"\u6728".freeze, "\u328E"=>"\u91D1".freeze,
- "\u328F"=>"\u571F".freeze, "\u3290"=>"\u65E5".freeze, "\u3291"=>"\u682A".freeze, "\u3292"=>"\u6709".freeze, "\u3293"=>"\u793E".freeze, "\u3294"=>"\u540D".freeze, "\u3295"=>"\u7279".freeze, "\u3296"=>"\u8CA1".freeze,
- "\u3297"=>"\u795D".freeze, "\u3298"=>"\u52B4".freeze, "\u3299"=>"\u79D8".freeze, "\u329A"=>"\u7537".freeze, "\u329B"=>"\u5973".freeze, "\u329C"=>"\u9069".freeze, "\u329D"=>"\u512A".freeze, "\u329E"=>"\u5370".freeze,
- "\u329F"=>"\u6CE8".freeze, "\u32A0"=>"\u9805".freeze, "\u32A1"=>"\u4F11".freeze, "\u32A2"=>"\u5199".freeze, "\u32A3"=>"\u6B63".freeze, "\u32A4"=>"\u4E0A".freeze, "\u32A5"=>"\u4E2D".freeze, "\u32A6"=>"\u4E0B".freeze,
- "\u32A7"=>"\u5DE6".freeze, "\u32A8"=>"\u53F3".freeze, "\u32A9"=>"\u533B".freeze, "\u32AA"=>"\u5B97".freeze, "\u32AB"=>"\u5B66".freeze, "\u32AC"=>"\u76E3".freeze, "\u32AD"=>"\u4F01".freeze, "\u32AE"=>"\u8CC7".freeze,
- "\u32AF"=>"\u5354".freeze, "\u32B0"=>"\u591C".freeze, "\u32B1"=>"36".freeze, "\u32B2"=>"37".freeze, "\u32B3"=>"38".freeze, "\u32B4"=>"39".freeze, "\u32B5"=>"40".freeze, "\u32B6"=>"41".freeze,
- "\u32B7"=>"42".freeze, "\u32B8"=>"43".freeze, "\u32B9"=>"44".freeze, "\u32BA"=>"45".freeze, "\u32BB"=>"46".freeze, "\u32BC"=>"47".freeze, "\u32BD"=>"48".freeze, "\u32BE"=>"49".freeze,
- "\u32BF"=>"50".freeze, "\u32C0"=>"1\u6708".freeze, "\u32C1"=>"2\u6708".freeze, "\u32C2"=>"3\u6708".freeze, "\u32C3"=>"4\u6708".freeze, "\u32C4"=>"5\u6708".freeze, "\u32C5"=>"6\u6708".freeze, "\u32C6"=>"7\u6708".freeze,
- "\u32C7"=>"8\u6708".freeze, "\u32C8"=>"9\u6708".freeze, "\u32C9"=>"10\u6708".freeze, "\u32CA"=>"11\u6708".freeze, "\u32CB"=>"12\u6708".freeze, "\u32CC"=>"Hg".freeze, "\u32CD"=>"erg".freeze, "\u32CE"=>"eV".freeze,
- "\u32CF"=>"LTD".freeze, "\u32D0"=>"\u30A2".freeze, "\u32D1"=>"\u30A4".freeze, "\u32D2"=>"\u30A6".freeze, "\u32D3"=>"\u30A8".freeze, "\u32D4"=>"\u30AA".freeze, "\u32D5"=>"\u30AB".freeze, "\u32D6"=>"\u30AD".freeze,
- "\u32D7"=>"\u30AF".freeze, "\u32D8"=>"\u30B1".freeze, "\u32D9"=>"\u30B3".freeze, "\u32DA"=>"\u30B5".freeze, "\u32DB"=>"\u30B7".freeze, "\u32DC"=>"\u30B9".freeze, "\u32DD"=>"\u30BB".freeze, "\u32DE"=>"\u30BD".freeze,
- "\u32DF"=>"\u30BF".freeze, "\u32E0"=>"\u30C1".freeze, "\u32E1"=>"\u30C4".freeze, "\u32E2"=>"\u30C6".freeze, "\u32E3"=>"\u30C8".freeze, "\u32E4"=>"\u30CA".freeze, "\u32E5"=>"\u30CB".freeze, "\u32E6"=>"\u30CC".freeze,
- "\u32E7"=>"\u30CD".freeze, "\u32E8"=>"\u30CE".freeze, "\u32E9"=>"\u30CF".freeze, "\u32EA"=>"\u30D2".freeze, "\u32EB"=>"\u30D5".freeze, "\u32EC"=>"\u30D8".freeze, "\u32ED"=>"\u30DB".freeze, "\u32EE"=>"\u30DE".freeze,
- "\u32EF"=>"\u30DF".freeze, "\u32F0"=>"\u30E0".freeze, "\u32F1"=>"\u30E1".freeze, "\u32F2"=>"\u30E2".freeze, "\u32F3"=>"\u30E4".freeze, "\u32F4"=>"\u30E6".freeze, "\u32F5"=>"\u30E8".freeze, "\u32F6"=>"\u30E9".freeze,
- "\u32F7"=>"\u30EA".freeze, "\u32F8"=>"\u30EB".freeze, "\u32F9"=>"\u30EC".freeze, "\u32FA"=>"\u30ED".freeze, "\u32FB"=>"\u30EF".freeze, "\u32FC"=>"\u30F0".freeze, "\u32FD"=>"\u30F1".freeze, "\u32FE"=>"\u30F2".freeze,
- "\u3300"=>"\u30A2\u30D1\u30FC\u30C8".freeze, "\u3301"=>"\u30A2\u30EB\u30D5\u30A1".freeze, "\u3302"=>"\u30A2\u30F3\u30DA\u30A2".freeze, "\u3303"=>"\u30A2\u30FC\u30EB".freeze, "\u3304"=>"\u30A4\u30CB\u30F3\u30B0".freeze, "\u3305"=>"\u30A4\u30F3\u30C1".freeze, "\u3306"=>"\u30A6\u30A9\u30F3".freeze, "\u3307"=>"\u30A8\u30B9\u30AF\u30FC\u30C9".freeze,
- "\u3308"=>"\u30A8\u30FC\u30AB\u30FC".freeze, "\u3309"=>"\u30AA\u30F3\u30B9".freeze, "\u330A"=>"\u30AA\u30FC\u30E0".freeze, "\u330B"=>"\u30AB\u30A4\u30EA".freeze, "\u330C"=>"\u30AB\u30E9\u30C3\u30C8".freeze, "\u330D"=>"\u30AB\u30ED\u30EA\u30FC".freeze, "\u330E"=>"\u30AC\u30ED\u30F3".freeze, "\u330F"=>"\u30AC\u30F3\u30DE".freeze,
- "\u3310"=>"\u30AE\u30AC".freeze, "\u3311"=>"\u30AE\u30CB\u30FC".freeze, "\u3312"=>"\u30AD\u30E5\u30EA\u30FC".freeze, "\u3313"=>"\u30AE\u30EB\u30C0\u30FC".freeze, "\u3314"=>"\u30AD\u30ED".freeze, "\u3315"=>"\u30AD\u30ED\u30B0\u30E9\u30E0".freeze, "\u3316"=>"\u30AD\u30ED\u30E1\u30FC\u30C8\u30EB".freeze, "\u3317"=>"\u30AD\u30ED\u30EF\u30C3\u30C8".freeze,
- "\u3318"=>"\u30B0\u30E9\u30E0".freeze, "\u3319"=>"\u30B0\u30E9\u30E0\u30C8\u30F3".freeze, "\u331A"=>"\u30AF\u30EB\u30BC\u30A4\u30ED".freeze, "\u331B"=>"\u30AF\u30ED\u30FC\u30CD".freeze, "\u331C"=>"\u30B1\u30FC\u30B9".freeze, "\u331D"=>"\u30B3\u30EB\u30CA".freeze, "\u331E"=>"\u30B3\u30FC\u30DD".freeze, "\u331F"=>"\u30B5\u30A4\u30AF\u30EB".freeze,
- "\u3320"=>"\u30B5\u30F3\u30C1\u30FC\u30E0".freeze, "\u3321"=>"\u30B7\u30EA\u30F3\u30B0".freeze, "\u3322"=>"\u30BB\u30F3\u30C1".freeze, "\u3323"=>"\u30BB\u30F3\u30C8".freeze, "\u3324"=>"\u30C0\u30FC\u30B9".freeze, "\u3325"=>"\u30C7\u30B7".freeze, "\u3326"=>"\u30C9\u30EB".freeze, "\u3327"=>"\u30C8\u30F3".freeze,
- "\u3328"=>"\u30CA\u30CE".freeze, "\u3329"=>"\u30CE\u30C3\u30C8".freeze, "\u332A"=>"\u30CF\u30A4\u30C4".freeze, "\u332B"=>"\u30D1\u30FC\u30BB\u30F3\u30C8".freeze, "\u332C"=>"\u30D1\u30FC\u30C4".freeze, "\u332D"=>"\u30D0\u30FC\u30EC\u30EB".freeze, "\u332E"=>"\u30D4\u30A2\u30B9\u30C8\u30EB".freeze, "\u332F"=>"\u30D4\u30AF\u30EB".freeze,
- "\u3330"=>"\u30D4\u30B3".freeze, "\u3331"=>"\u30D3\u30EB".freeze, "\u3332"=>"\u30D5\u30A1\u30E9\u30C3\u30C9".freeze, "\u3333"=>"\u30D5\u30A3\u30FC\u30C8".freeze, "\u3334"=>"\u30D6\u30C3\u30B7\u30A7\u30EB".freeze, "\u3335"=>"\u30D5\u30E9\u30F3".freeze, "\u3336"=>"\u30D8\u30AF\u30BF\u30FC\u30EB".freeze, "\u3337"=>"\u30DA\u30BD".freeze,
- "\u3338"=>"\u30DA\u30CB\u30D2".freeze, "\u3339"=>"\u30D8\u30EB\u30C4".freeze, "\u333A"=>"\u30DA\u30F3\u30B9".freeze, "\u333B"=>"\u30DA\u30FC\u30B8".freeze, "\u333C"=>"\u30D9\u30FC\u30BF".freeze, "\u333D"=>"\u30DD\u30A4\u30F3\u30C8".freeze, "\u333E"=>"\u30DC\u30EB\u30C8".freeze, "\u333F"=>"\u30DB\u30F3".freeze,
- "\u3340"=>"\u30DD\u30F3\u30C9".freeze, "\u3341"=>"\u30DB\u30FC\u30EB".freeze, "\u3342"=>"\u30DB\u30FC\u30F3".freeze, "\u3343"=>"\u30DE\u30A4\u30AF\u30ED".freeze, "\u3344"=>"\u30DE\u30A4\u30EB".freeze, "\u3345"=>"\u30DE\u30C3\u30CF".freeze, "\u3346"=>"\u30DE\u30EB\u30AF".freeze, "\u3347"=>"\u30DE\u30F3\u30B7\u30E7\u30F3".freeze,
- "\u3348"=>"\u30DF\u30AF\u30ED\u30F3".freeze, "\u3349"=>"\u30DF\u30EA".freeze, "\u334A"=>"\u30DF\u30EA\u30D0\u30FC\u30EB".freeze, "\u334B"=>"\u30E1\u30AC".freeze, "\u334C"=>"\u30E1\u30AC\u30C8\u30F3".freeze, "\u334D"=>"\u30E1\u30FC\u30C8\u30EB".freeze, "\u334E"=>"\u30E4\u30FC\u30C9".freeze, "\u334F"=>"\u30E4\u30FC\u30EB".freeze,
- "\u3350"=>"\u30E6\u30A2\u30F3".freeze, "\u3351"=>"\u30EA\u30C3\u30C8\u30EB".freeze, "\u3352"=>"\u30EA\u30E9".freeze, "\u3353"=>"\u30EB\u30D4\u30FC".freeze, "\u3354"=>"\u30EB\u30FC\u30D6\u30EB".freeze, "\u3355"=>"\u30EC\u30E0".freeze, "\u3356"=>"\u30EC\u30F3\u30C8\u30B2\u30F3".freeze, "\u3357"=>"\u30EF\u30C3\u30C8".freeze,
- "\u3358"=>"0\u70B9".freeze, "\u3359"=>"1\u70B9".freeze, "\u335A"=>"2\u70B9".freeze, "\u335B"=>"3\u70B9".freeze, "\u335C"=>"4\u70B9".freeze, "\u335D"=>"5\u70B9".freeze, "\u335E"=>"6\u70B9".freeze, "\u335F"=>"7\u70B9".freeze,
- "\u3360"=>"8\u70B9".freeze, "\u3361"=>"9\u70B9".freeze, "\u3362"=>"10\u70B9".freeze, "\u3363"=>"11\u70B9".freeze, "\u3364"=>"12\u70B9".freeze, "\u3365"=>"13\u70B9".freeze, "\u3366"=>"14\u70B9".freeze, "\u3367"=>"15\u70B9".freeze,
- "\u3368"=>"16\u70B9".freeze, "\u3369"=>"17\u70B9".freeze, "\u336A"=>"18\u70B9".freeze, "\u336B"=>"19\u70B9".freeze, "\u336C"=>"20\u70B9".freeze, "\u336D"=>"21\u70B9".freeze, "\u336E"=>"22\u70B9".freeze, "\u336F"=>"23\u70B9".freeze,
- "\u3370"=>"24\u70B9".freeze, "\u3371"=>"hPa".freeze, "\u3372"=>"da".freeze, "\u3373"=>"AU".freeze, "\u3374"=>"bar".freeze, "\u3375"=>"oV".freeze, "\u3376"=>"pc".freeze, "\u3377"=>"dm".freeze,
- "\u3378"=>"dm2".freeze, "\u3379"=>"dm3".freeze, "\u337A"=>"IU".freeze, "\u337B"=>"\u5E73\u6210".freeze, "\u337C"=>"\u662D\u548C".freeze, "\u337D"=>"\u5927\u6B63".freeze, "\u337E"=>"\u660E\u6CBB".freeze, "\u337F"=>"\u682A\u5F0F\u4F1A\u793E".freeze,
- "\u3380"=>"pA".freeze, "\u3381"=>"nA".freeze, "\u3382"=>"\u03BCA".freeze, "\u3383"=>"mA".freeze, "\u3384"=>"kA".freeze, "\u3385"=>"KB".freeze, "\u3386"=>"MB".freeze, "\u3387"=>"GB".freeze,
- "\u3388"=>"cal".freeze, "\u3389"=>"kcal".freeze, "\u338A"=>"pF".freeze, "\u338B"=>"nF".freeze, "\u338C"=>"\u03BCF".freeze, "\u338D"=>"\u03BCg".freeze, "\u338E"=>"mg".freeze, "\u338F"=>"kg".freeze,
- "\u3390"=>"Hz".freeze, "\u3391"=>"kHz".freeze, "\u3392"=>"MHz".freeze, "\u3393"=>"GHz".freeze, "\u3394"=>"THz".freeze, "\u3395"=>"\u03BCl".freeze, "\u3396"=>"ml".freeze, "\u3397"=>"dl".freeze,
- "\u3398"=>"kl".freeze, "\u3399"=>"fm".freeze, "\u339A"=>"nm".freeze, "\u339B"=>"\u03BCm".freeze, "\u339C"=>"mm".freeze, "\u339D"=>"cm".freeze, "\u339E"=>"km".freeze, "\u339F"=>"mm2".freeze,
- "\u33A0"=>"cm2".freeze, "\u33A1"=>"m2".freeze, "\u33A2"=>"km2".freeze, "\u33A3"=>"mm3".freeze, "\u33A4"=>"cm3".freeze, "\u33A5"=>"m3".freeze, "\u33A6"=>"km3".freeze, "\u33A7"=>"m\u2215s".freeze,
- "\u33A8"=>"m\u2215s2".freeze, "\u33A9"=>"Pa".freeze, "\u33AA"=>"kPa".freeze, "\u33AB"=>"MPa".freeze, "\u33AC"=>"GPa".freeze, "\u33AD"=>"rad".freeze, "\u33AE"=>"rad\u2215s".freeze, "\u33AF"=>"rad\u2215s2".freeze,
- "\u33B0"=>"ps".freeze, "\u33B1"=>"ns".freeze, "\u33B2"=>"\u03BCs".freeze, "\u33B3"=>"ms".freeze, "\u33B4"=>"pV".freeze, "\u33B5"=>"nV".freeze, "\u33B6"=>"\u03BCV".freeze, "\u33B7"=>"mV".freeze,
- "\u33B8"=>"kV".freeze, "\u33B9"=>"MV".freeze, "\u33BA"=>"pW".freeze, "\u33BB"=>"nW".freeze, "\u33BC"=>"\u03BCW".freeze, "\u33BD"=>"mW".freeze, "\u33BE"=>"kW".freeze, "\u33BF"=>"MW".freeze,
- "\u33C0"=>"k\u03A9".freeze, "\u33C1"=>"M\u03A9".freeze, "\u33C2"=>"a.m.".freeze, "\u33C3"=>"Bq".freeze, "\u33C4"=>"cc".freeze, "\u33C5"=>"cd".freeze, "\u33C6"=>"C\u2215kg".freeze, "\u33C7"=>"Co.".freeze,
- "\u33C8"=>"dB".freeze, "\u33C9"=>"Gy".freeze, "\u33CA"=>"ha".freeze, "\u33CB"=>"HP".freeze, "\u33CC"=>"in".freeze, "\u33CD"=>"KK".freeze, "\u33CE"=>"KM".freeze, "\u33CF"=>"kt".freeze,
- "\u33D0"=>"lm".freeze, "\u33D1"=>"ln".freeze, "\u33D2"=>"log".freeze, "\u33D3"=>"lx".freeze, "\u33D4"=>"mb".freeze, "\u33D5"=>"mil".freeze, "\u33D6"=>"mol".freeze, "\u33D7"=>"PH".freeze,
- "\u33D8"=>"p.m.".freeze, "\u33D9"=>"PPM".freeze, "\u33DA"=>"PR".freeze, "\u33DB"=>"sr".freeze, "\u33DC"=>"Sv".freeze, "\u33DD"=>"Wb".freeze, "\u33DE"=>"V\u2215m".freeze, "\u33DF"=>"A\u2215m".freeze,
- "\u33E0"=>"1\u65E5".freeze, "\u33E1"=>"2\u65E5".freeze, "\u33E2"=>"3\u65E5".freeze, "\u33E3"=>"4\u65E5".freeze, "\u33E4"=>"5\u65E5".freeze, "\u33E5"=>"6\u65E5".freeze, "\u33E6"=>"7\u65E5".freeze, "\u33E7"=>"8\u65E5".freeze,
- "\u33E8"=>"9\u65E5".freeze, "\u33E9"=>"10\u65E5".freeze, "\u33EA"=>"11\u65E5".freeze, "\u33EB"=>"12\u65E5".freeze, "\u33EC"=>"13\u65E5".freeze, "\u33ED"=>"14\u65E5".freeze, "\u33EE"=>"15\u65E5".freeze, "\u33EF"=>"16\u65E5".freeze,
- "\u33F0"=>"17\u65E5".freeze, "\u33F1"=>"18\u65E5".freeze, "\u33F2"=>"19\u65E5".freeze, "\u33F3"=>"20\u65E5".freeze, "\u33F4"=>"21\u65E5".freeze, "\u33F5"=>"22\u65E5".freeze, "\u33F6"=>"23\u65E5".freeze, "\u33F7"=>"24\u65E5".freeze,
- "\u33F8"=>"25\u65E5".freeze, "\u33F9"=>"26\u65E5".freeze, "\u33FA"=>"27\u65E5".freeze, "\u33FB"=>"28\u65E5".freeze, "\u33FC"=>"29\u65E5".freeze, "\u33FD"=>"30\u65E5".freeze, "\u33FE"=>"31\u65E5".freeze, "\u33FF"=>"gal".freeze,
- "\uA69C"=>"\u044A".freeze, "\uA69D"=>"\u044C".freeze, "\uA770"=>"\uA76F".freeze, "\uA7F8"=>"\u0126".freeze, "\uA7F9"=>"\u0153".freeze, "\uAB5C"=>"\uA727".freeze, "\uAB5D"=>"\uAB37".freeze, "\uAB5E"=>"\u026B".freeze,
- "\uAB5F"=>"\uAB52".freeze, "\uFB00"=>"ff".freeze, "\uFB01"=>"fi".freeze, "\uFB02"=>"fl".freeze, "\uFB03"=>"ffi".freeze, "\uFB04"=>"ffl".freeze, "\uFB05"=>"st".freeze, "\uFB06"=>"st".freeze,
- "\uFB13"=>"\u0574\u0576".freeze, "\uFB14"=>"\u0574\u0565".freeze, "\uFB15"=>"\u0574\u056B".freeze, "\uFB16"=>"\u057E\u0576".freeze, "\uFB17"=>"\u0574\u056D".freeze, "\uFB20"=>"\u05E2".freeze, "\uFB21"=>"\u05D0".freeze, "\uFB22"=>"\u05D3".freeze,
- "\uFB23"=>"\u05D4".freeze, "\uFB24"=>"\u05DB".freeze, "\uFB25"=>"\u05DC".freeze, "\uFB26"=>"\u05DD".freeze, "\uFB27"=>"\u05E8".freeze, "\uFB28"=>"\u05EA".freeze, "\uFB29"=>"+".freeze, "\uFB4F"=>"\u05D0\u05DC".freeze,
- "\uFB50"=>"\u0671".freeze, "\uFB51"=>"\u0671".freeze, "\uFB52"=>"\u067B".freeze, "\uFB53"=>"\u067B".freeze, "\uFB54"=>"\u067B".freeze, "\uFB55"=>"\u067B".freeze, "\uFB56"=>"\u067E".freeze, "\uFB57"=>"\u067E".freeze,
- "\uFB58"=>"\u067E".freeze, "\uFB59"=>"\u067E".freeze, "\uFB5A"=>"\u0680".freeze, "\uFB5B"=>"\u0680".freeze, "\uFB5C"=>"\u0680".freeze, "\uFB5D"=>"\u0680".freeze, "\uFB5E"=>"\u067A".freeze, "\uFB5F"=>"\u067A".freeze,
- "\uFB60"=>"\u067A".freeze, "\uFB61"=>"\u067A".freeze, "\uFB62"=>"\u067F".freeze, "\uFB63"=>"\u067F".freeze, "\uFB64"=>"\u067F".freeze, "\uFB65"=>"\u067F".freeze, "\uFB66"=>"\u0679".freeze, "\uFB67"=>"\u0679".freeze,
- "\uFB68"=>"\u0679".freeze, "\uFB69"=>"\u0679".freeze, "\uFB6A"=>"\u06A4".freeze, "\uFB6B"=>"\u06A4".freeze, "\uFB6C"=>"\u06A4".freeze, "\uFB6D"=>"\u06A4".freeze, "\uFB6E"=>"\u06A6".freeze, "\uFB6F"=>"\u06A6".freeze,
- "\uFB70"=>"\u06A6".freeze, "\uFB71"=>"\u06A6".freeze, "\uFB72"=>"\u0684".freeze, "\uFB73"=>"\u0684".freeze, "\uFB74"=>"\u0684".freeze, "\uFB75"=>"\u0684".freeze, "\uFB76"=>"\u0683".freeze, "\uFB77"=>"\u0683".freeze,
- "\uFB78"=>"\u0683".freeze, "\uFB79"=>"\u0683".freeze, "\uFB7A"=>"\u0686".freeze, "\uFB7B"=>"\u0686".freeze, "\uFB7C"=>"\u0686".freeze, "\uFB7D"=>"\u0686".freeze, "\uFB7E"=>"\u0687".freeze, "\uFB7F"=>"\u0687".freeze,
- "\uFB80"=>"\u0687".freeze, "\uFB81"=>"\u0687".freeze, "\uFB82"=>"\u068D".freeze, "\uFB83"=>"\u068D".freeze, "\uFB84"=>"\u068C".freeze, "\uFB85"=>"\u068C".freeze, "\uFB86"=>"\u068E".freeze, "\uFB87"=>"\u068E".freeze,
- "\uFB88"=>"\u0688".freeze, "\uFB89"=>"\u0688".freeze, "\uFB8A"=>"\u0698".freeze, "\uFB8B"=>"\u0698".freeze, "\uFB8C"=>"\u0691".freeze, "\uFB8D"=>"\u0691".freeze, "\uFB8E"=>"\u06A9".freeze, "\uFB8F"=>"\u06A9".freeze,
- "\uFB90"=>"\u06A9".freeze, "\uFB91"=>"\u06A9".freeze, "\uFB92"=>"\u06AF".freeze, "\uFB93"=>"\u06AF".freeze, "\uFB94"=>"\u06AF".freeze, "\uFB95"=>"\u06AF".freeze, "\uFB96"=>"\u06B3".freeze, "\uFB97"=>"\u06B3".freeze,
- "\uFB98"=>"\u06B3".freeze, "\uFB99"=>"\u06B3".freeze, "\uFB9A"=>"\u06B1".freeze, "\uFB9B"=>"\u06B1".freeze, "\uFB9C"=>"\u06B1".freeze, "\uFB9D"=>"\u06B1".freeze, "\uFB9E"=>"\u06BA".freeze, "\uFB9F"=>"\u06BA".freeze,
- "\uFBA0"=>"\u06BB".freeze, "\uFBA1"=>"\u06BB".freeze, "\uFBA2"=>"\u06BB".freeze, "\uFBA3"=>"\u06BB".freeze, "\uFBA4"=>"\u06C0".freeze, "\uFBA5"=>"\u06C0".freeze, "\uFBA6"=>"\u06C1".freeze, "\uFBA7"=>"\u06C1".freeze,
- "\uFBA8"=>"\u06C1".freeze, "\uFBA9"=>"\u06C1".freeze, "\uFBAA"=>"\u06BE".freeze, "\uFBAB"=>"\u06BE".freeze, "\uFBAC"=>"\u06BE".freeze, "\uFBAD"=>"\u06BE".freeze, "\uFBAE"=>"\u06D2".freeze, "\uFBAF"=>"\u06D2".freeze,
- "\uFBB0"=>"\u06D3".freeze, "\uFBB1"=>"\u06D3".freeze, "\uFBD3"=>"\u06AD".freeze, "\uFBD4"=>"\u06AD".freeze, "\uFBD5"=>"\u06AD".freeze, "\uFBD6"=>"\u06AD".freeze, "\uFBD7"=>"\u06C7".freeze, "\uFBD8"=>"\u06C7".freeze,
- "\uFBD9"=>"\u06C6".freeze, "\uFBDA"=>"\u06C6".freeze, "\uFBDB"=>"\u06C8".freeze, "\uFBDC"=>"\u06C8".freeze, "\uFBDD"=>"\u06C7\u0674".freeze, "\uFBDE"=>"\u06CB".freeze, "\uFBDF"=>"\u06CB".freeze, "\uFBE0"=>"\u06C5".freeze,
- "\uFBE1"=>"\u06C5".freeze, "\uFBE2"=>"\u06C9".freeze, "\uFBE3"=>"\u06C9".freeze, "\uFBE4"=>"\u06D0".freeze, "\uFBE5"=>"\u06D0".freeze, "\uFBE6"=>"\u06D0".freeze, "\uFBE7"=>"\u06D0".freeze, "\uFBE8"=>"\u0649".freeze,
- "\uFBE9"=>"\u0649".freeze, "\uFBEA"=>"\u0626\u0627".freeze, "\uFBEB"=>"\u0626\u0627".freeze, "\uFBEC"=>"\u0626\u06D5".freeze, "\uFBED"=>"\u0626\u06D5".freeze, "\uFBEE"=>"\u0626\u0648".freeze, "\uFBEF"=>"\u0626\u0648".freeze, "\uFBF0"=>"\u0626\u06C7".freeze,
- "\uFBF1"=>"\u0626\u06C7".freeze, "\uFBF2"=>"\u0626\u06C6".freeze, "\uFBF3"=>"\u0626\u06C6".freeze, "\uFBF4"=>"\u0626\u06C8".freeze, "\uFBF5"=>"\u0626\u06C8".freeze, "\uFBF6"=>"\u0626\u06D0".freeze, "\uFBF7"=>"\u0626\u06D0".freeze, "\uFBF8"=>"\u0626\u06D0".freeze,
- "\uFBF9"=>"\u0626\u0649".freeze, "\uFBFA"=>"\u0626\u0649".freeze, "\uFBFB"=>"\u0626\u0649".freeze, "\uFBFC"=>"\u06CC".freeze, "\uFBFD"=>"\u06CC".freeze, "\uFBFE"=>"\u06CC".freeze, "\uFBFF"=>"\u06CC".freeze, "\uFC00"=>"\u0626\u062C".freeze,
- "\uFC01"=>"\u0626\u062D".freeze, "\uFC02"=>"\u0626\u0645".freeze, "\uFC03"=>"\u0626\u0649".freeze, "\uFC04"=>"\u0626\u064A".freeze, "\uFC05"=>"\u0628\u062C".freeze, "\uFC06"=>"\u0628\u062D".freeze, "\uFC07"=>"\u0628\u062E".freeze, "\uFC08"=>"\u0628\u0645".freeze,
- "\uFC09"=>"\u0628\u0649".freeze, "\uFC0A"=>"\u0628\u064A".freeze, "\uFC0B"=>"\u062A\u062C".freeze, "\uFC0C"=>"\u062A\u062D".freeze, "\uFC0D"=>"\u062A\u062E".freeze, "\uFC0E"=>"\u062A\u0645".freeze, "\uFC0F"=>"\u062A\u0649".freeze, "\uFC10"=>"\u062A\u064A".freeze,
- "\uFC11"=>"\u062B\u062C".freeze, "\uFC12"=>"\u062B\u0645".freeze, "\uFC13"=>"\u062B\u0649".freeze, "\uFC14"=>"\u062B\u064A".freeze, "\uFC15"=>"\u062C\u062D".freeze, "\uFC16"=>"\u062C\u0645".freeze, "\uFC17"=>"\u062D\u062C".freeze, "\uFC18"=>"\u062D\u0645".freeze,
- "\uFC19"=>"\u062E\u062C".freeze, "\uFC1A"=>"\u062E\u062D".freeze, "\uFC1B"=>"\u062E\u0645".freeze, "\uFC1C"=>"\u0633\u062C".freeze, "\uFC1D"=>"\u0633\u062D".freeze, "\uFC1E"=>"\u0633\u062E".freeze, "\uFC1F"=>"\u0633\u0645".freeze, "\uFC20"=>"\u0635\u062D".freeze,
- "\uFC21"=>"\u0635\u0645".freeze, "\uFC22"=>"\u0636\u062C".freeze, "\uFC23"=>"\u0636\u062D".freeze, "\uFC24"=>"\u0636\u062E".freeze, "\uFC25"=>"\u0636\u0645".freeze, "\uFC26"=>"\u0637\u062D".freeze, "\uFC27"=>"\u0637\u0645".freeze, "\uFC28"=>"\u0638\u0645".freeze,
- "\uFC29"=>"\u0639\u062C".freeze, "\uFC2A"=>"\u0639\u0645".freeze, "\uFC2B"=>"\u063A\u062C".freeze, "\uFC2C"=>"\u063A\u0645".freeze, "\uFC2D"=>"\u0641\u062C".freeze, "\uFC2E"=>"\u0641\u062D".freeze, "\uFC2F"=>"\u0641\u062E".freeze, "\uFC30"=>"\u0641\u0645".freeze,
- "\uFC31"=>"\u0641\u0649".freeze, "\uFC32"=>"\u0641\u064A".freeze, "\uFC33"=>"\u0642\u062D".freeze, "\uFC34"=>"\u0642\u0645".freeze, "\uFC35"=>"\u0642\u0649".freeze, "\uFC36"=>"\u0642\u064A".freeze, "\uFC37"=>"\u0643\u0627".freeze, "\uFC38"=>"\u0643\u062C".freeze,
- "\uFC39"=>"\u0643\u062D".freeze, "\uFC3A"=>"\u0643\u062E".freeze, "\uFC3B"=>"\u0643\u0644".freeze, "\uFC3C"=>"\u0643\u0645".freeze, "\uFC3D"=>"\u0643\u0649".freeze, "\uFC3E"=>"\u0643\u064A".freeze, "\uFC3F"=>"\u0644\u062C".freeze, "\uFC40"=>"\u0644\u062D".freeze,
- "\uFC41"=>"\u0644\u062E".freeze, "\uFC42"=>"\u0644\u0645".freeze, "\uFC43"=>"\u0644\u0649".freeze, "\uFC44"=>"\u0644\u064A".freeze, "\uFC45"=>"\u0645\u062C".freeze, "\uFC46"=>"\u0645\u062D".freeze, "\uFC47"=>"\u0645\u062E".freeze, "\uFC48"=>"\u0645\u0645".freeze,
- "\uFC49"=>"\u0645\u0649".freeze, "\uFC4A"=>"\u0645\u064A".freeze, "\uFC4B"=>"\u0646\u062C".freeze, "\uFC4C"=>"\u0646\u062D".freeze, "\uFC4D"=>"\u0646\u062E".freeze, "\uFC4E"=>"\u0646\u0645".freeze, "\uFC4F"=>"\u0646\u0649".freeze, "\uFC50"=>"\u0646\u064A".freeze,
- "\uFC51"=>"\u0647\u062C".freeze, "\uFC52"=>"\u0647\u0645".freeze, "\uFC53"=>"\u0647\u0649".freeze, "\uFC54"=>"\u0647\u064A".freeze, "\uFC55"=>"\u064A\u062C".freeze, "\uFC56"=>"\u064A\u062D".freeze, "\uFC57"=>"\u064A\u062E".freeze, "\uFC58"=>"\u064A\u0645".freeze,
- "\uFC59"=>"\u064A\u0649".freeze, "\uFC5A"=>"\u064A\u064A".freeze, "\uFC5B"=>"\u0630\u0670".freeze, "\uFC5C"=>"\u0631\u0670".freeze, "\uFC5D"=>"\u0649\u0670".freeze, "\uFC5E"=>" \u064C\u0651".freeze, "\uFC5F"=>" \u064D\u0651".freeze, "\uFC60"=>" \u064E\u0651".freeze,
- "\uFC61"=>" \u064F\u0651".freeze, "\uFC62"=>" \u0650\u0651".freeze, "\uFC63"=>" \u0651\u0670".freeze, "\uFC64"=>"\u0626\u0631".freeze, "\uFC65"=>"\u0626\u0632".freeze, "\uFC66"=>"\u0626\u0645".freeze, "\uFC67"=>"\u0626\u0646".freeze, "\uFC68"=>"\u0626\u0649".freeze,
- "\uFC69"=>"\u0626\u064A".freeze, "\uFC6A"=>"\u0628\u0631".freeze, "\uFC6B"=>"\u0628\u0632".freeze, "\uFC6C"=>"\u0628\u0645".freeze, "\uFC6D"=>"\u0628\u0646".freeze, "\uFC6E"=>"\u0628\u0649".freeze, "\uFC6F"=>"\u0628\u064A".freeze, "\uFC70"=>"\u062A\u0631".freeze,
- "\uFC71"=>"\u062A\u0632".freeze, "\uFC72"=>"\u062A\u0645".freeze, "\uFC73"=>"\u062A\u0646".freeze, "\uFC74"=>"\u062A\u0649".freeze, "\uFC75"=>"\u062A\u064A".freeze, "\uFC76"=>"\u062B\u0631".freeze, "\uFC77"=>"\u062B\u0632".freeze, "\uFC78"=>"\u062B\u0645".freeze,
- "\uFC79"=>"\u062B\u0646".freeze, "\uFC7A"=>"\u062B\u0649".freeze, "\uFC7B"=>"\u062B\u064A".freeze, "\uFC7C"=>"\u0641\u0649".freeze, "\uFC7D"=>"\u0641\u064A".freeze, "\uFC7E"=>"\u0642\u0649".freeze, "\uFC7F"=>"\u0642\u064A".freeze, "\uFC80"=>"\u0643\u0627".freeze,
- "\uFC81"=>"\u0643\u0644".freeze, "\uFC82"=>"\u0643\u0645".freeze, "\uFC83"=>"\u0643\u0649".freeze, "\uFC84"=>"\u0643\u064A".freeze, "\uFC85"=>"\u0644\u0645".freeze, "\uFC86"=>"\u0644\u0649".freeze, "\uFC87"=>"\u0644\u064A".freeze, "\uFC88"=>"\u0645\u0627".freeze,
- "\uFC89"=>"\u0645\u0645".freeze, "\uFC8A"=>"\u0646\u0631".freeze, "\uFC8B"=>"\u0646\u0632".freeze, "\uFC8C"=>"\u0646\u0645".freeze, "\uFC8D"=>"\u0646\u0646".freeze, "\uFC8E"=>"\u0646\u0649".freeze, "\uFC8F"=>"\u0646\u064A".freeze, "\uFC90"=>"\u0649\u0670".freeze,
- "\uFC91"=>"\u064A\u0631".freeze, "\uFC92"=>"\u064A\u0632".freeze, "\uFC93"=>"\u064A\u0645".freeze, "\uFC94"=>"\u064A\u0646".freeze, "\uFC95"=>"\u064A\u0649".freeze, "\uFC96"=>"\u064A\u064A".freeze, "\uFC97"=>"\u0626\u062C".freeze, "\uFC98"=>"\u0626\u062D".freeze,
- "\uFC99"=>"\u0626\u062E".freeze, "\uFC9A"=>"\u0626\u0645".freeze, "\uFC9B"=>"\u0626\u0647".freeze, "\uFC9C"=>"\u0628\u062C".freeze, "\uFC9D"=>"\u0628\u062D".freeze, "\uFC9E"=>"\u0628\u062E".freeze, "\uFC9F"=>"\u0628\u0645".freeze, "\uFCA0"=>"\u0628\u0647".freeze,
- "\uFCA1"=>"\u062A\u062C".freeze, "\uFCA2"=>"\u062A\u062D".freeze, "\uFCA3"=>"\u062A\u062E".freeze, "\uFCA4"=>"\u062A\u0645".freeze, "\uFCA5"=>"\u062A\u0647".freeze, "\uFCA6"=>"\u062B\u0645".freeze, "\uFCA7"=>"\u062C\u062D".freeze, "\uFCA8"=>"\u062C\u0645".freeze,
- "\uFCA9"=>"\u062D\u062C".freeze, "\uFCAA"=>"\u062D\u0645".freeze, "\uFCAB"=>"\u062E\u062C".freeze, "\uFCAC"=>"\u062E\u0645".freeze, "\uFCAD"=>"\u0633\u062C".freeze, "\uFCAE"=>"\u0633\u062D".freeze, "\uFCAF"=>"\u0633\u062E".freeze, "\uFCB0"=>"\u0633\u0645".freeze,
- "\uFCB1"=>"\u0635\u062D".freeze, "\uFCB2"=>"\u0635\u062E".freeze, "\uFCB3"=>"\u0635\u0645".freeze, "\uFCB4"=>"\u0636\u062C".freeze, "\uFCB5"=>"\u0636\u062D".freeze, "\uFCB6"=>"\u0636\u062E".freeze, "\uFCB7"=>"\u0636\u0645".freeze, "\uFCB8"=>"\u0637\u062D".freeze,
- "\uFCB9"=>"\u0638\u0645".freeze, "\uFCBA"=>"\u0639\u062C".freeze, "\uFCBB"=>"\u0639\u0645".freeze, "\uFCBC"=>"\u063A\u062C".freeze, "\uFCBD"=>"\u063A\u0645".freeze, "\uFCBE"=>"\u0641\u062C".freeze, "\uFCBF"=>"\u0641\u062D".freeze, "\uFCC0"=>"\u0641\u062E".freeze,
- "\uFCC1"=>"\u0641\u0645".freeze, "\uFCC2"=>"\u0642\u062D".freeze, "\uFCC3"=>"\u0642\u0645".freeze, "\uFCC4"=>"\u0643\u062C".freeze, "\uFCC5"=>"\u0643\u062D".freeze, "\uFCC6"=>"\u0643\u062E".freeze, "\uFCC7"=>"\u0643\u0644".freeze, "\uFCC8"=>"\u0643\u0645".freeze,
- "\uFCC9"=>"\u0644\u062C".freeze, "\uFCCA"=>"\u0644\u062D".freeze, "\uFCCB"=>"\u0644\u062E".freeze, "\uFCCC"=>"\u0644\u0645".freeze, "\uFCCD"=>"\u0644\u0647".freeze, "\uFCCE"=>"\u0645\u062C".freeze, "\uFCCF"=>"\u0645\u062D".freeze, "\uFCD0"=>"\u0645\u062E".freeze,
- "\uFCD1"=>"\u0645\u0645".freeze, "\uFCD2"=>"\u0646\u062C".freeze, "\uFCD3"=>"\u0646\u062D".freeze, "\uFCD4"=>"\u0646\u062E".freeze, "\uFCD5"=>"\u0646\u0645".freeze, "\uFCD6"=>"\u0646\u0647".freeze, "\uFCD7"=>"\u0647\u062C".freeze, "\uFCD8"=>"\u0647\u0645".freeze,
- "\uFCD9"=>"\u0647\u0670".freeze, "\uFCDA"=>"\u064A\u062C".freeze, "\uFCDB"=>"\u064A\u062D".freeze, "\uFCDC"=>"\u064A\u062E".freeze, "\uFCDD"=>"\u064A\u0645".freeze, "\uFCDE"=>"\u064A\u0647".freeze, "\uFCDF"=>"\u0626\u0645".freeze, "\uFCE0"=>"\u0626\u0647".freeze,
- "\uFCE1"=>"\u0628\u0645".freeze, "\uFCE2"=>"\u0628\u0647".freeze, "\uFCE3"=>"\u062A\u0645".freeze, "\uFCE4"=>"\u062A\u0647".freeze, "\uFCE5"=>"\u062B\u0645".freeze, "\uFCE6"=>"\u062B\u0647".freeze, "\uFCE7"=>"\u0633\u0645".freeze, "\uFCE8"=>"\u0633\u0647".freeze,
- "\uFCE9"=>"\u0634\u0645".freeze, "\uFCEA"=>"\u0634\u0647".freeze, "\uFCEB"=>"\u0643\u0644".freeze, "\uFCEC"=>"\u0643\u0645".freeze, "\uFCED"=>"\u0644\u0645".freeze, "\uFCEE"=>"\u0646\u0645".freeze, "\uFCEF"=>"\u0646\u0647".freeze, "\uFCF0"=>"\u064A\u0645".freeze,
- "\uFCF1"=>"\u064A\u0647".freeze, "\uFCF2"=>"\u0640\u064E\u0651".freeze, "\uFCF3"=>"\u0640\u064F\u0651".freeze, "\uFCF4"=>"\u0640\u0650\u0651".freeze, "\uFCF5"=>"\u0637\u0649".freeze, "\uFCF6"=>"\u0637\u064A".freeze, "\uFCF7"=>"\u0639\u0649".freeze, "\uFCF8"=>"\u0639\u064A".freeze,
- "\uFCF9"=>"\u063A\u0649".freeze, "\uFCFA"=>"\u063A\u064A".freeze, "\uFCFB"=>"\u0633\u0649".freeze, "\uFCFC"=>"\u0633\u064A".freeze, "\uFCFD"=>"\u0634\u0649".freeze, "\uFCFE"=>"\u0634\u064A".freeze, "\uFCFF"=>"\u062D\u0649".freeze, "\uFD00"=>"\u062D\u064A".freeze,
- "\uFD01"=>"\u062C\u0649".freeze, "\uFD02"=>"\u062C\u064A".freeze, "\uFD03"=>"\u062E\u0649".freeze, "\uFD04"=>"\u062E\u064A".freeze, "\uFD05"=>"\u0635\u0649".freeze, "\uFD06"=>"\u0635\u064A".freeze, "\uFD07"=>"\u0636\u0649".freeze, "\uFD08"=>"\u0636\u064A".freeze,
- "\uFD09"=>"\u0634\u062C".freeze, "\uFD0A"=>"\u0634\u062D".freeze, "\uFD0B"=>"\u0634\u062E".freeze, "\uFD0C"=>"\u0634\u0645".freeze, "\uFD0D"=>"\u0634\u0631".freeze, "\uFD0E"=>"\u0633\u0631".freeze, "\uFD0F"=>"\u0635\u0631".freeze, "\uFD10"=>"\u0636\u0631".freeze,
- "\uFD11"=>"\u0637\u0649".freeze, "\uFD12"=>"\u0637\u064A".freeze, "\uFD13"=>"\u0639\u0649".freeze, "\uFD14"=>"\u0639\u064A".freeze, "\uFD15"=>"\u063A\u0649".freeze, "\uFD16"=>"\u063A\u064A".freeze, "\uFD17"=>"\u0633\u0649".freeze, "\uFD18"=>"\u0633\u064A".freeze,
- "\uFD19"=>"\u0634\u0649".freeze, "\uFD1A"=>"\u0634\u064A".freeze, "\uFD1B"=>"\u062D\u0649".freeze, "\uFD1C"=>"\u062D\u064A".freeze, "\uFD1D"=>"\u062C\u0649".freeze, "\uFD1E"=>"\u062C\u064A".freeze, "\uFD1F"=>"\u062E\u0649".freeze, "\uFD20"=>"\u062E\u064A".freeze,
- "\uFD21"=>"\u0635\u0649".freeze, "\uFD22"=>"\u0635\u064A".freeze, "\uFD23"=>"\u0636\u0649".freeze, "\uFD24"=>"\u0636\u064A".freeze, "\uFD25"=>"\u0634\u062C".freeze, "\uFD26"=>"\u0634\u062D".freeze, "\uFD27"=>"\u0634\u062E".freeze, "\uFD28"=>"\u0634\u0645".freeze,
- "\uFD29"=>"\u0634\u0631".freeze, "\uFD2A"=>"\u0633\u0631".freeze, "\uFD2B"=>"\u0635\u0631".freeze, "\uFD2C"=>"\u0636\u0631".freeze, "\uFD2D"=>"\u0634\u062C".freeze, "\uFD2E"=>"\u0634\u062D".freeze, "\uFD2F"=>"\u0634\u062E".freeze, "\uFD30"=>"\u0634\u0645".freeze,
- "\uFD31"=>"\u0633\u0647".freeze, "\uFD32"=>"\u0634\u0647".freeze, "\uFD33"=>"\u0637\u0645".freeze, "\uFD34"=>"\u0633\u062C".freeze, "\uFD35"=>"\u0633\u062D".freeze, "\uFD36"=>"\u0633\u062E".freeze, "\uFD37"=>"\u0634\u062C".freeze, "\uFD38"=>"\u0634\u062D".freeze,
- "\uFD39"=>"\u0634\u062E".freeze, "\uFD3A"=>"\u0637\u0645".freeze, "\uFD3B"=>"\u0638\u0645".freeze, "\uFD3C"=>"\u0627\u064B".freeze, "\uFD3D"=>"\u0627\u064B".freeze, "\uFD50"=>"\u062A\u062C\u0645".freeze, "\uFD51"=>"\u062A\u062D\u062C".freeze, "\uFD52"=>"\u062A\u062D\u062C".freeze,
- "\uFD53"=>"\u062A\u062D\u0645".freeze, "\uFD54"=>"\u062A\u062E\u0645".freeze, "\uFD55"=>"\u062A\u0645\u062C".freeze, "\uFD56"=>"\u062A\u0645\u062D".freeze, "\uFD57"=>"\u062A\u0645\u062E".freeze, "\uFD58"=>"\u062C\u0645\u062D".freeze, "\uFD59"=>"\u062C\u0645\u062D".freeze, "\uFD5A"=>"\u062D\u0645\u064A".freeze,
- "\uFD5B"=>"\u062D\u0645\u0649".freeze, "\uFD5C"=>"\u0633\u062D\u062C".freeze, "\uFD5D"=>"\u0633\u062C\u062D".freeze, "\uFD5E"=>"\u0633\u062C\u0649".freeze, "\uFD5F"=>"\u0633\u0645\u062D".freeze, "\uFD60"=>"\u0633\u0645\u062D".freeze, "\uFD61"=>"\u0633\u0645\u062C".freeze, "\uFD62"=>"\u0633\u0645\u0645".freeze,
- "\uFD63"=>"\u0633\u0645\u0645".freeze, "\uFD64"=>"\u0635\u062D\u062D".freeze, "\uFD65"=>"\u0635\u062D\u062D".freeze, "\uFD66"=>"\u0635\u0645\u0645".freeze, "\uFD67"=>"\u0634\u062D\u0645".freeze, "\uFD68"=>"\u0634\u062D\u0645".freeze, "\uFD69"=>"\u0634\u062C\u064A".freeze, "\uFD6A"=>"\u0634\u0645\u062E".freeze,
- "\uFD6B"=>"\u0634\u0645\u062E".freeze, "\uFD6C"=>"\u0634\u0645\u0645".freeze, "\uFD6D"=>"\u0634\u0645\u0645".freeze, "\uFD6E"=>"\u0636\u062D\u0649".freeze, "\uFD6F"=>"\u0636\u062E\u0645".freeze, "\uFD70"=>"\u0636\u062E\u0645".freeze, "\uFD71"=>"\u0637\u0645\u062D".freeze, "\uFD72"=>"\u0637\u0645\u062D".freeze,
- "\uFD73"=>"\u0637\u0645\u0645".freeze, "\uFD74"=>"\u0637\u0645\u064A".freeze, "\uFD75"=>"\u0639\u062C\u0645".freeze, "\uFD76"=>"\u0639\u0645\u0645".freeze, "\uFD77"=>"\u0639\u0645\u0645".freeze, "\uFD78"=>"\u0639\u0645\u0649".freeze, "\uFD79"=>"\u063A\u0645\u0645".freeze, "\uFD7A"=>"\u063A\u0645\u064A".freeze,
- "\uFD7B"=>"\u063A\u0645\u0649".freeze, "\uFD7C"=>"\u0641\u062E\u0645".freeze, "\uFD7D"=>"\u0641\u062E\u0645".freeze, "\uFD7E"=>"\u0642\u0645\u062D".freeze, "\uFD7F"=>"\u0642\u0645\u0645".freeze, "\uFD80"=>"\u0644\u062D\u0645".freeze, "\uFD81"=>"\u0644\u062D\u064A".freeze, "\uFD82"=>"\u0644\u062D\u0649".freeze,
- "\uFD83"=>"\u0644\u062C\u062C".freeze, "\uFD84"=>"\u0644\u062C\u062C".freeze, "\uFD85"=>"\u0644\u062E\u0645".freeze, "\uFD86"=>"\u0644\u062E\u0645".freeze, "\uFD87"=>"\u0644\u0645\u062D".freeze, "\uFD88"=>"\u0644\u0645\u062D".freeze, "\uFD89"=>"\u0645\u062D\u062C".freeze, "\uFD8A"=>"\u0645\u062D\u0645".freeze,
- "\uFD8B"=>"\u0645\u062D\u064A".freeze, "\uFD8C"=>"\u0645\u062C\u062D".freeze, "\uFD8D"=>"\u0645\u062C\u0645".freeze, "\uFD8E"=>"\u0645\u062E\u062C".freeze, "\uFD8F"=>"\u0645\u062E\u0645".freeze, "\uFD92"=>"\u0645\u062C\u062E".freeze, "\uFD93"=>"\u0647\u0645\u062C".freeze, "\uFD94"=>"\u0647\u0645\u0645".freeze,
- "\uFD95"=>"\u0646\u062D\u0645".freeze, "\uFD96"=>"\u0646\u062D\u0649".freeze, "\uFD97"=>"\u0646\u062C\u0645".freeze, "\uFD98"=>"\u0646\u062C\u0645".freeze, "\uFD99"=>"\u0646\u062C\u0649".freeze, "\uFD9A"=>"\u0646\u0645\u064A".freeze, "\uFD9B"=>"\u0646\u0645\u0649".freeze, "\uFD9C"=>"\u064A\u0645\u0645".freeze,
- "\uFD9D"=>"\u064A\u0645\u0645".freeze, "\uFD9E"=>"\u0628\u062E\u064A".freeze, "\uFD9F"=>"\u062A\u062C\u064A".freeze, "\uFDA0"=>"\u062A\u062C\u0649".freeze, "\uFDA1"=>"\u062A\u062E\u064A".freeze, "\uFDA2"=>"\u062A\u062E\u0649".freeze, "\uFDA3"=>"\u062A\u0645\u064A".freeze, "\uFDA4"=>"\u062A\u0645\u0649".freeze,
- "\uFDA5"=>"\u062C\u0645\u064A".freeze, "\uFDA6"=>"\u062C\u062D\u0649".freeze, "\uFDA7"=>"\u062C\u0645\u0649".freeze, "\uFDA8"=>"\u0633\u062E\u0649".freeze, "\uFDA9"=>"\u0635\u062D\u064A".freeze, "\uFDAA"=>"\u0634\u062D\u064A".freeze, "\uFDAB"=>"\u0636\u062D\u064A".freeze, "\uFDAC"=>"\u0644\u062C\u064A".freeze,
- "\uFDAD"=>"\u0644\u0645\u064A".freeze, "\uFDAE"=>"\u064A\u062D\u064A".freeze, "\uFDAF"=>"\u064A\u062C\u064A".freeze, "\uFDB0"=>"\u064A\u0645\u064A".freeze, "\uFDB1"=>"\u0645\u0645\u064A".freeze, "\uFDB2"=>"\u0642\u0645\u064A".freeze, "\uFDB3"=>"\u0646\u062D\u064A".freeze, "\uFDB4"=>"\u0642\u0645\u062D".freeze,
- "\uFDB5"=>"\u0644\u062D\u0645".freeze, "\uFDB6"=>"\u0639\u0645\u064A".freeze, "\uFDB7"=>"\u0643\u0645\u064A".freeze, "\uFDB8"=>"\u0646\u062C\u062D".freeze, "\uFDB9"=>"\u0645\u062E\u064A".freeze, "\uFDBA"=>"\u0644\u062C\u0645".freeze, "\uFDBB"=>"\u0643\u0645\u0645".freeze, "\uFDBC"=>"\u0644\u062C\u0645".freeze,
- "\uFDBD"=>"\u0646\u062C\u062D".freeze, "\uFDBE"=>"\u062C\u062D\u064A".freeze, "\uFDBF"=>"\u062D\u062C\u064A".freeze, "\uFDC0"=>"\u0645\u062C\u064A".freeze, "\uFDC1"=>"\u0641\u0645\u064A".freeze, "\uFDC2"=>"\u0628\u062D\u064A".freeze, "\uFDC3"=>"\u0643\u0645\u0645".freeze, "\uFDC4"=>"\u0639\u062C\u0645".freeze,
- "\uFDC5"=>"\u0635\u0645\u0645".freeze, "\uFDC6"=>"\u0633\u062E\u064A".freeze, "\uFDC7"=>"\u0646\u062C\u064A".freeze, "\uFDF0"=>"\u0635\u0644\u06D2".freeze, "\uFDF1"=>"\u0642\u0644\u06D2".freeze, "\uFDF2"=>"\u0627\u0644\u0644\u0647".freeze, "\uFDF3"=>"\u0627\u0643\u0628\u0631".freeze, "\uFDF4"=>"\u0645\u062D\u0645\u062F".freeze,
- "\uFDF5"=>"\u0635\u0644\u0639\u0645".freeze, "\uFDF6"=>"\u0631\u0633\u0648\u0644".freeze, "\uFDF7"=>"\u0639\u0644\u064A\u0647".freeze, "\uFDF8"=>"\u0648\u0633\u0644\u0645".freeze, "\uFDF9"=>"\u0635\u0644\u0649".freeze, "\uFDFA"=>"\u0635\u0644\u0649 \u0627\u0644\u0644\u0647 \u0639\u0644\u064A\u0647 \u0648\u0633\u0644\u0645".freeze, "\uFDFB"=>"\u062C\u0644 \u062C\u0644\u0627\u0644\u0647".freeze, "\uFDFC"=>"\u0631\u06CC\u0627\u0644".freeze,
- "\uFE10"=>",".freeze, "\uFE11"=>"\u3001".freeze, "\uFE12"=>"\u3002".freeze, "\uFE13"=>":".freeze, "\uFE14"=>";".freeze, "\uFE15"=>"!".freeze, "\uFE16"=>"?".freeze, "\uFE17"=>"\u3016".freeze,
- "\uFE18"=>"\u3017".freeze, "\uFE19"=>"...".freeze, "\uFE30"=>"..".freeze, "\uFE31"=>"\u2014".freeze, "\uFE32"=>"\u2013".freeze, "\uFE33"=>"_".freeze, "\uFE34"=>"_".freeze, "\uFE35"=>"(".freeze,
- "\uFE36"=>")".freeze, "\uFE37"=>"{".freeze, "\uFE38"=>"}".freeze, "\uFE39"=>"\u3014".freeze, "\uFE3A"=>"\u3015".freeze, "\uFE3B"=>"\u3010".freeze, "\uFE3C"=>"\u3011".freeze, "\uFE3D"=>"\u300A".freeze,
- "\uFE3E"=>"\u300B".freeze, "\uFE3F"=>"\u3008".freeze, "\uFE40"=>"\u3009".freeze, "\uFE41"=>"\u300C".freeze, "\uFE42"=>"\u300D".freeze, "\uFE43"=>"\u300E".freeze, "\uFE44"=>"\u300F".freeze, "\uFE47"=>"[".freeze,
- "\uFE48"=>"]".freeze, "\uFE49"=>" \u0305".freeze, "\uFE4A"=>" \u0305".freeze, "\uFE4B"=>" \u0305".freeze, "\uFE4C"=>" \u0305".freeze, "\uFE4D"=>"_".freeze, "\uFE4E"=>"_".freeze, "\uFE4F"=>"_".freeze,
- "\uFE50"=>",".freeze, "\uFE51"=>"\u3001".freeze, "\uFE52"=>".".freeze, "\uFE54"=>";".freeze, "\uFE55"=>":".freeze, "\uFE56"=>"?".freeze, "\uFE57"=>"!".freeze, "\uFE58"=>"\u2014".freeze,
- "\uFE59"=>"(".freeze, "\uFE5A"=>")".freeze, "\uFE5B"=>"{".freeze, "\uFE5C"=>"}".freeze, "\uFE5D"=>"\u3014".freeze, "\uFE5E"=>"\u3015".freeze, "\uFE5F"=>"#".freeze, "\uFE60"=>"&".freeze,
- "\uFE61"=>"*".freeze, "\uFE62"=>"+".freeze, "\uFE63"=>"-".freeze, "\uFE64"=>"<".freeze, "\uFE65"=>">".freeze, "\uFE66"=>"=".freeze, "\uFE68"=>"\\".freeze, "\uFE69"=>"$".freeze,
- "\uFE6A"=>"%".freeze, "\uFE6B"=>"@".freeze, "\uFE70"=>" \u064B".freeze, "\uFE71"=>"\u0640\u064B".freeze, "\uFE72"=>" \u064C".freeze, "\uFE74"=>" \u064D".freeze, "\uFE76"=>" \u064E".freeze, "\uFE77"=>"\u0640\u064E".freeze,
- "\uFE78"=>" \u064F".freeze, "\uFE79"=>"\u0640\u064F".freeze, "\uFE7A"=>" \u0650".freeze, "\uFE7B"=>"\u0640\u0650".freeze, "\uFE7C"=>" \u0651".freeze, "\uFE7D"=>"\u0640\u0651".freeze, "\uFE7E"=>" \u0652".freeze, "\uFE7F"=>"\u0640\u0652".freeze,
- "\uFE80"=>"\u0621".freeze, "\uFE81"=>"\u0622".freeze, "\uFE82"=>"\u0622".freeze, "\uFE83"=>"\u0623".freeze, "\uFE84"=>"\u0623".freeze, "\uFE85"=>"\u0624".freeze, "\uFE86"=>"\u0624".freeze, "\uFE87"=>"\u0625".freeze,
- "\uFE88"=>"\u0625".freeze, "\uFE89"=>"\u0626".freeze, "\uFE8A"=>"\u0626".freeze, "\uFE8B"=>"\u0626".freeze, "\uFE8C"=>"\u0626".freeze, "\uFE8D"=>"\u0627".freeze, "\uFE8E"=>"\u0627".freeze, "\uFE8F"=>"\u0628".freeze,
- "\uFE90"=>"\u0628".freeze, "\uFE91"=>"\u0628".freeze, "\uFE92"=>"\u0628".freeze, "\uFE93"=>"\u0629".freeze, "\uFE94"=>"\u0629".freeze, "\uFE95"=>"\u062A".freeze, "\uFE96"=>"\u062A".freeze, "\uFE97"=>"\u062A".freeze,
- "\uFE98"=>"\u062A".freeze, "\uFE99"=>"\u062B".freeze, "\uFE9A"=>"\u062B".freeze, "\uFE9B"=>"\u062B".freeze, "\uFE9C"=>"\u062B".freeze, "\uFE9D"=>"\u062C".freeze, "\uFE9E"=>"\u062C".freeze, "\uFE9F"=>"\u062C".freeze,
- "\uFEA0"=>"\u062C".freeze, "\uFEA1"=>"\u062D".freeze, "\uFEA2"=>"\u062D".freeze, "\uFEA3"=>"\u062D".freeze, "\uFEA4"=>"\u062D".freeze, "\uFEA5"=>"\u062E".freeze, "\uFEA6"=>"\u062E".freeze, "\uFEA7"=>"\u062E".freeze,
- "\uFEA8"=>"\u062E".freeze, "\uFEA9"=>"\u062F".freeze, "\uFEAA"=>"\u062F".freeze, "\uFEAB"=>"\u0630".freeze, "\uFEAC"=>"\u0630".freeze, "\uFEAD"=>"\u0631".freeze, "\uFEAE"=>"\u0631".freeze, "\uFEAF"=>"\u0632".freeze,
- "\uFEB0"=>"\u0632".freeze, "\uFEB1"=>"\u0633".freeze, "\uFEB2"=>"\u0633".freeze, "\uFEB3"=>"\u0633".freeze, "\uFEB4"=>"\u0633".freeze, "\uFEB5"=>"\u0634".freeze, "\uFEB6"=>"\u0634".freeze, "\uFEB7"=>"\u0634".freeze,
- "\uFEB8"=>"\u0634".freeze, "\uFEB9"=>"\u0635".freeze, "\uFEBA"=>"\u0635".freeze, "\uFEBB"=>"\u0635".freeze, "\uFEBC"=>"\u0635".freeze, "\uFEBD"=>"\u0636".freeze, "\uFEBE"=>"\u0636".freeze, "\uFEBF"=>"\u0636".freeze,
- "\uFEC0"=>"\u0636".freeze, "\uFEC1"=>"\u0637".freeze, "\uFEC2"=>"\u0637".freeze, "\uFEC3"=>"\u0637".freeze, "\uFEC4"=>"\u0637".freeze, "\uFEC5"=>"\u0638".freeze, "\uFEC6"=>"\u0638".freeze, "\uFEC7"=>"\u0638".freeze,
- "\uFEC8"=>"\u0638".freeze, "\uFEC9"=>"\u0639".freeze, "\uFECA"=>"\u0639".freeze, "\uFECB"=>"\u0639".freeze, "\uFECC"=>"\u0639".freeze, "\uFECD"=>"\u063A".freeze, "\uFECE"=>"\u063A".freeze, "\uFECF"=>"\u063A".freeze,
- "\uFED0"=>"\u063A".freeze, "\uFED1"=>"\u0641".freeze, "\uFED2"=>"\u0641".freeze, "\uFED3"=>"\u0641".freeze, "\uFED4"=>"\u0641".freeze, "\uFED5"=>"\u0642".freeze, "\uFED6"=>"\u0642".freeze, "\uFED7"=>"\u0642".freeze,
- "\uFED8"=>"\u0642".freeze, "\uFED9"=>"\u0643".freeze, "\uFEDA"=>"\u0643".freeze, "\uFEDB"=>"\u0643".freeze, "\uFEDC"=>"\u0643".freeze, "\uFEDD"=>"\u0644".freeze, "\uFEDE"=>"\u0644".freeze, "\uFEDF"=>"\u0644".freeze,
- "\uFEE0"=>"\u0644".freeze, "\uFEE1"=>"\u0645".freeze, "\uFEE2"=>"\u0645".freeze, "\uFEE3"=>"\u0645".freeze, "\uFEE4"=>"\u0645".freeze, "\uFEE5"=>"\u0646".freeze, "\uFEE6"=>"\u0646".freeze, "\uFEE7"=>"\u0646".freeze,
- "\uFEE8"=>"\u0646".freeze, "\uFEE9"=>"\u0647".freeze, "\uFEEA"=>"\u0647".freeze, "\uFEEB"=>"\u0647".freeze, "\uFEEC"=>"\u0647".freeze, "\uFEED"=>"\u0648".freeze, "\uFEEE"=>"\u0648".freeze, "\uFEEF"=>"\u0649".freeze,
- "\uFEF0"=>"\u0649".freeze, "\uFEF1"=>"\u064A".freeze, "\uFEF2"=>"\u064A".freeze, "\uFEF3"=>"\u064A".freeze, "\uFEF4"=>"\u064A".freeze, "\uFEF5"=>"\u0644\u0622".freeze, "\uFEF6"=>"\u0644\u0622".freeze, "\uFEF7"=>"\u0644\u0623".freeze,
- "\uFEF8"=>"\u0644\u0623".freeze, "\uFEF9"=>"\u0644\u0625".freeze, "\uFEFA"=>"\u0644\u0625".freeze, "\uFEFB"=>"\u0644\u0627".freeze, "\uFEFC"=>"\u0644\u0627".freeze, "\uFF01"=>"!".freeze, "\uFF02"=>"\"".freeze, "\uFF03"=>"#".freeze,
- "\uFF04"=>"$".freeze, "\uFF05"=>"%".freeze, "\uFF06"=>"&".freeze, "\uFF07"=>"'".freeze, "\uFF08"=>"(".freeze, "\uFF09"=>")".freeze, "\uFF0A"=>"*".freeze, "\uFF0B"=>"+".freeze,
- "\uFF0C"=>",".freeze, "\uFF0D"=>"-".freeze, "\uFF0E"=>".".freeze, "\uFF0F"=>"/".freeze, "\uFF10"=>"0".freeze, "\uFF11"=>"1".freeze, "\uFF12"=>"2".freeze, "\uFF13"=>"3".freeze,
- "\uFF14"=>"4".freeze, "\uFF15"=>"5".freeze, "\uFF16"=>"6".freeze, "\uFF17"=>"7".freeze, "\uFF18"=>"8".freeze, "\uFF19"=>"9".freeze, "\uFF1A"=>":".freeze, "\uFF1B"=>";".freeze,
- "\uFF1C"=>"<".freeze, "\uFF1D"=>"=".freeze, "\uFF1E"=>">".freeze, "\uFF1F"=>"?".freeze, "\uFF20"=>"@".freeze, "\uFF21"=>"A".freeze, "\uFF22"=>"B".freeze, "\uFF23"=>"C".freeze,
- "\uFF24"=>"D".freeze, "\uFF25"=>"E".freeze, "\uFF26"=>"F".freeze, "\uFF27"=>"G".freeze, "\uFF28"=>"H".freeze, "\uFF29"=>"I".freeze, "\uFF2A"=>"J".freeze, "\uFF2B"=>"K".freeze,
- "\uFF2C"=>"L".freeze, "\uFF2D"=>"M".freeze, "\uFF2E"=>"N".freeze, "\uFF2F"=>"O".freeze, "\uFF30"=>"P".freeze, "\uFF31"=>"Q".freeze, "\uFF32"=>"R".freeze, "\uFF33"=>"S".freeze,
- "\uFF34"=>"T".freeze, "\uFF35"=>"U".freeze, "\uFF36"=>"V".freeze, "\uFF37"=>"W".freeze, "\uFF38"=>"X".freeze, "\uFF39"=>"Y".freeze, "\uFF3A"=>"Z".freeze, "\uFF3B"=>"[".freeze,
- "\uFF3C"=>"\\".freeze, "\uFF3D"=>"]".freeze, "\uFF3E"=>"^".freeze, "\uFF3F"=>"_".freeze, "\uFF40"=>"`".freeze, "\uFF41"=>"a".freeze, "\uFF42"=>"b".freeze, "\uFF43"=>"c".freeze,
- "\uFF44"=>"d".freeze, "\uFF45"=>"e".freeze, "\uFF46"=>"f".freeze, "\uFF47"=>"g".freeze, "\uFF48"=>"h".freeze, "\uFF49"=>"i".freeze, "\uFF4A"=>"j".freeze, "\uFF4B"=>"k".freeze,
- "\uFF4C"=>"l".freeze, "\uFF4D"=>"m".freeze, "\uFF4E"=>"n".freeze, "\uFF4F"=>"o".freeze, "\uFF50"=>"p".freeze, "\uFF51"=>"q".freeze, "\uFF52"=>"r".freeze, "\uFF53"=>"s".freeze,
- "\uFF54"=>"t".freeze, "\uFF55"=>"u".freeze, "\uFF56"=>"v".freeze, "\uFF57"=>"w".freeze, "\uFF58"=>"x".freeze, "\uFF59"=>"y".freeze, "\uFF5A"=>"z".freeze, "\uFF5B"=>"{".freeze,
- "\uFF5C"=>"|".freeze, "\uFF5D"=>"}".freeze, "\uFF5E"=>"~".freeze, "\uFF5F"=>"\u2985".freeze, "\uFF60"=>"\u2986".freeze, "\uFF61"=>"\u3002".freeze, "\uFF62"=>"\u300C".freeze, "\uFF63"=>"\u300D".freeze,
- "\uFF64"=>"\u3001".freeze, "\uFF65"=>"\u30FB".freeze, "\uFF66"=>"\u30F2".freeze, "\uFF67"=>"\u30A1".freeze, "\uFF68"=>"\u30A3".freeze, "\uFF69"=>"\u30A5".freeze, "\uFF6A"=>"\u30A7".freeze, "\uFF6B"=>"\u30A9".freeze,
- "\uFF6C"=>"\u30E3".freeze, "\uFF6D"=>"\u30E5".freeze, "\uFF6E"=>"\u30E7".freeze, "\uFF6F"=>"\u30C3".freeze, "\uFF70"=>"\u30FC".freeze, "\uFF71"=>"\u30A2".freeze, "\uFF72"=>"\u30A4".freeze, "\uFF73"=>"\u30A6".freeze,
- "\uFF74"=>"\u30A8".freeze, "\uFF75"=>"\u30AA".freeze, "\uFF76"=>"\u30AB".freeze, "\uFF77"=>"\u30AD".freeze, "\uFF78"=>"\u30AF".freeze, "\uFF79"=>"\u30B1".freeze, "\uFF7A"=>"\u30B3".freeze, "\uFF7B"=>"\u30B5".freeze,
- "\uFF7C"=>"\u30B7".freeze, "\uFF7D"=>"\u30B9".freeze, "\uFF7E"=>"\u30BB".freeze, "\uFF7F"=>"\u30BD".freeze, "\uFF80"=>"\u30BF".freeze, "\uFF81"=>"\u30C1".freeze, "\uFF82"=>"\u30C4".freeze, "\uFF83"=>"\u30C6".freeze,
- "\uFF84"=>"\u30C8".freeze, "\uFF85"=>"\u30CA".freeze, "\uFF86"=>"\u30CB".freeze, "\uFF87"=>"\u30CC".freeze, "\uFF88"=>"\u30CD".freeze, "\uFF89"=>"\u30CE".freeze, "\uFF8A"=>"\u30CF".freeze, "\uFF8B"=>"\u30D2".freeze,
- "\uFF8C"=>"\u30D5".freeze, "\uFF8D"=>"\u30D8".freeze, "\uFF8E"=>"\u30DB".freeze, "\uFF8F"=>"\u30DE".freeze, "\uFF90"=>"\u30DF".freeze, "\uFF91"=>"\u30E0".freeze, "\uFF92"=>"\u30E1".freeze, "\uFF93"=>"\u30E2".freeze,
- "\uFF94"=>"\u30E4".freeze, "\uFF95"=>"\u30E6".freeze, "\uFF96"=>"\u30E8".freeze, "\uFF97"=>"\u30E9".freeze, "\uFF98"=>"\u30EA".freeze, "\uFF99"=>"\u30EB".freeze, "\uFF9A"=>"\u30EC".freeze, "\uFF9B"=>"\u30ED".freeze,
- "\uFF9C"=>"\u30EF".freeze, "\uFF9D"=>"\u30F3".freeze, "\uFF9E"=>"\u3099".freeze, "\uFF9F"=>"\u309A".freeze, "\uFFA0"=>"\u1160".freeze, "\uFFA1"=>"\u1100".freeze, "\uFFA2"=>"\u1101".freeze, "\uFFA3"=>"\u11AA".freeze,
- "\uFFA4"=>"\u1102".freeze, "\uFFA5"=>"\u11AC".freeze, "\uFFA6"=>"\u11AD".freeze, "\uFFA7"=>"\u1103".freeze, "\uFFA8"=>"\u1104".freeze, "\uFFA9"=>"\u1105".freeze, "\uFFAA"=>"\u11B0".freeze, "\uFFAB"=>"\u11B1".freeze,
- "\uFFAC"=>"\u11B2".freeze, "\uFFAD"=>"\u11B3".freeze, "\uFFAE"=>"\u11B4".freeze, "\uFFAF"=>"\u11B5".freeze, "\uFFB0"=>"\u111A".freeze, "\uFFB1"=>"\u1106".freeze, "\uFFB2"=>"\u1107".freeze, "\uFFB3"=>"\u1108".freeze,
- "\uFFB4"=>"\u1121".freeze, "\uFFB5"=>"\u1109".freeze, "\uFFB6"=>"\u110A".freeze, "\uFFB7"=>"\u110B".freeze, "\uFFB8"=>"\u110C".freeze, "\uFFB9"=>"\u110D".freeze, "\uFFBA"=>"\u110E".freeze, "\uFFBB"=>"\u110F".freeze,
- "\uFFBC"=>"\u1110".freeze, "\uFFBD"=>"\u1111".freeze, "\uFFBE"=>"\u1112".freeze, "\uFFC2"=>"\u1161".freeze, "\uFFC3"=>"\u1162".freeze, "\uFFC4"=>"\u1163".freeze, "\uFFC5"=>"\u1164".freeze, "\uFFC6"=>"\u1165".freeze,
- "\uFFC7"=>"\u1166".freeze, "\uFFCA"=>"\u1167".freeze, "\uFFCB"=>"\u1168".freeze, "\uFFCC"=>"\u1169".freeze, "\uFFCD"=>"\u116A".freeze, "\uFFCE"=>"\u116B".freeze, "\uFFCF"=>"\u116C".freeze, "\uFFD2"=>"\u116D".freeze,
- "\uFFD3"=>"\u116E".freeze, "\uFFD4"=>"\u116F".freeze, "\uFFD5"=>"\u1170".freeze, "\uFFD6"=>"\u1171".freeze, "\uFFD7"=>"\u1172".freeze, "\uFFDA"=>"\u1173".freeze, "\uFFDB"=>"\u1174".freeze, "\uFFDC"=>"\u1175".freeze,
- "\uFFE0"=>"\u00A2".freeze, "\uFFE1"=>"\u00A3".freeze, "\uFFE2"=>"\u00AC".freeze, "\uFFE3"=>" \u0304".freeze, "\uFFE4"=>"\u00A6".freeze, "\uFFE5"=>"\u00A5".freeze, "\uFFE6"=>"\u20A9".freeze, "\uFFE8"=>"\u2502".freeze,
- "\uFFE9"=>"\u2190".freeze, "\uFFEA"=>"\u2191".freeze, "\uFFEB"=>"\u2192".freeze, "\uFFEC"=>"\u2193".freeze, "\uFFED"=>"\u25A0".freeze, "\uFFEE"=>"\u25CB".freeze, "\u{1D400}"=>"A".freeze, "\u{1D401}"=>"B".freeze,
- "\u{1D402}"=>"C".freeze, "\u{1D403}"=>"D".freeze, "\u{1D404}"=>"E".freeze, "\u{1D405}"=>"F".freeze, "\u{1D406}"=>"G".freeze, "\u{1D407}"=>"H".freeze, "\u{1D408}"=>"I".freeze, "\u{1D409}"=>"J".freeze,
- "\u{1D40A}"=>"K".freeze, "\u{1D40B}"=>"L".freeze, "\u{1D40C}"=>"M".freeze, "\u{1D40D}"=>"N".freeze, "\u{1D40E}"=>"O".freeze, "\u{1D40F}"=>"P".freeze, "\u{1D410}"=>"Q".freeze, "\u{1D411}"=>"R".freeze,
- "\u{1D412}"=>"S".freeze, "\u{1D413}"=>"T".freeze, "\u{1D414}"=>"U".freeze, "\u{1D415}"=>"V".freeze, "\u{1D416}"=>"W".freeze, "\u{1D417}"=>"X".freeze, "\u{1D418}"=>"Y".freeze, "\u{1D419}"=>"Z".freeze,
- "\u{1D41A}"=>"a".freeze, "\u{1D41B}"=>"b".freeze, "\u{1D41C}"=>"c".freeze, "\u{1D41D}"=>"d".freeze, "\u{1D41E}"=>"e".freeze, "\u{1D41F}"=>"f".freeze, "\u{1D420}"=>"g".freeze, "\u{1D421}"=>"h".freeze,
- "\u{1D422}"=>"i".freeze, "\u{1D423}"=>"j".freeze, "\u{1D424}"=>"k".freeze, "\u{1D425}"=>"l".freeze, "\u{1D426}"=>"m".freeze, "\u{1D427}"=>"n".freeze, "\u{1D428}"=>"o".freeze, "\u{1D429}"=>"p".freeze,
- "\u{1D42A}"=>"q".freeze, "\u{1D42B}"=>"r".freeze, "\u{1D42C}"=>"s".freeze, "\u{1D42D}"=>"t".freeze, "\u{1D42E}"=>"u".freeze, "\u{1D42F}"=>"v".freeze, "\u{1D430}"=>"w".freeze, "\u{1D431}"=>"x".freeze,
- "\u{1D432}"=>"y".freeze, "\u{1D433}"=>"z".freeze, "\u{1D434}"=>"A".freeze, "\u{1D435}"=>"B".freeze, "\u{1D436}"=>"C".freeze, "\u{1D437}"=>"D".freeze, "\u{1D438}"=>"E".freeze, "\u{1D439}"=>"F".freeze,
- "\u{1D43A}"=>"G".freeze, "\u{1D43B}"=>"H".freeze, "\u{1D43C}"=>"I".freeze, "\u{1D43D}"=>"J".freeze, "\u{1D43E}"=>"K".freeze, "\u{1D43F}"=>"L".freeze, "\u{1D440}"=>"M".freeze, "\u{1D441}"=>"N".freeze,
- "\u{1D442}"=>"O".freeze, "\u{1D443}"=>"P".freeze, "\u{1D444}"=>"Q".freeze, "\u{1D445}"=>"R".freeze, "\u{1D446}"=>"S".freeze, "\u{1D447}"=>"T".freeze, "\u{1D448}"=>"U".freeze, "\u{1D449}"=>"V".freeze,
- "\u{1D44A}"=>"W".freeze, "\u{1D44B}"=>"X".freeze, "\u{1D44C}"=>"Y".freeze, "\u{1D44D}"=>"Z".freeze, "\u{1D44E}"=>"a".freeze, "\u{1D44F}"=>"b".freeze, "\u{1D450}"=>"c".freeze, "\u{1D451}"=>"d".freeze,
- "\u{1D452}"=>"e".freeze, "\u{1D453}"=>"f".freeze, "\u{1D454}"=>"g".freeze, "\u{1D456}"=>"i".freeze, "\u{1D457}"=>"j".freeze, "\u{1D458}"=>"k".freeze, "\u{1D459}"=>"l".freeze, "\u{1D45A}"=>"m".freeze,
- "\u{1D45B}"=>"n".freeze, "\u{1D45C}"=>"o".freeze, "\u{1D45D}"=>"p".freeze, "\u{1D45E}"=>"q".freeze, "\u{1D45F}"=>"r".freeze, "\u{1D460}"=>"s".freeze, "\u{1D461}"=>"t".freeze, "\u{1D462}"=>"u".freeze,
- "\u{1D463}"=>"v".freeze, "\u{1D464}"=>"w".freeze, "\u{1D465}"=>"x".freeze, "\u{1D466}"=>"y".freeze, "\u{1D467}"=>"z".freeze, "\u{1D468}"=>"A".freeze, "\u{1D469}"=>"B".freeze, "\u{1D46A}"=>"C".freeze,
- "\u{1D46B}"=>"D".freeze, "\u{1D46C}"=>"E".freeze, "\u{1D46D}"=>"F".freeze, "\u{1D46E}"=>"G".freeze, "\u{1D46F}"=>"H".freeze, "\u{1D470}"=>"I".freeze, "\u{1D471}"=>"J".freeze, "\u{1D472}"=>"K".freeze,
- "\u{1D473}"=>"L".freeze, "\u{1D474}"=>"M".freeze, "\u{1D475}"=>"N".freeze, "\u{1D476}"=>"O".freeze, "\u{1D477}"=>"P".freeze, "\u{1D478}"=>"Q".freeze, "\u{1D479}"=>"R".freeze, "\u{1D47A}"=>"S".freeze,
- "\u{1D47B}"=>"T".freeze, "\u{1D47C}"=>"U".freeze, "\u{1D47D}"=>"V".freeze, "\u{1D47E}"=>"W".freeze, "\u{1D47F}"=>"X".freeze, "\u{1D480}"=>"Y".freeze, "\u{1D481}"=>"Z".freeze, "\u{1D482}"=>"a".freeze,
- "\u{1D483}"=>"b".freeze, "\u{1D484}"=>"c".freeze, "\u{1D485}"=>"d".freeze, "\u{1D486}"=>"e".freeze, "\u{1D487}"=>"f".freeze, "\u{1D488}"=>"g".freeze, "\u{1D489}"=>"h".freeze, "\u{1D48A}"=>"i".freeze,
- "\u{1D48B}"=>"j".freeze, "\u{1D48C}"=>"k".freeze, "\u{1D48D}"=>"l".freeze, "\u{1D48E}"=>"m".freeze, "\u{1D48F}"=>"n".freeze, "\u{1D490}"=>"o".freeze, "\u{1D491}"=>"p".freeze, "\u{1D492}"=>"q".freeze,
- "\u{1D493}"=>"r".freeze, "\u{1D494}"=>"s".freeze, "\u{1D495}"=>"t".freeze, "\u{1D496}"=>"u".freeze, "\u{1D497}"=>"v".freeze, "\u{1D498}"=>"w".freeze, "\u{1D499}"=>"x".freeze, "\u{1D49A}"=>"y".freeze,
- "\u{1D49B}"=>"z".freeze, "\u{1D49C}"=>"A".freeze, "\u{1D49E}"=>"C".freeze, "\u{1D49F}"=>"D".freeze, "\u{1D4A2}"=>"G".freeze, "\u{1D4A5}"=>"J".freeze, "\u{1D4A6}"=>"K".freeze, "\u{1D4A9}"=>"N".freeze,
- "\u{1D4AA}"=>"O".freeze, "\u{1D4AB}"=>"P".freeze, "\u{1D4AC}"=>"Q".freeze, "\u{1D4AE}"=>"S".freeze, "\u{1D4AF}"=>"T".freeze, "\u{1D4B0}"=>"U".freeze, "\u{1D4B1}"=>"V".freeze, "\u{1D4B2}"=>"W".freeze,
- "\u{1D4B3}"=>"X".freeze, "\u{1D4B4}"=>"Y".freeze, "\u{1D4B5}"=>"Z".freeze, "\u{1D4B6}"=>"a".freeze, "\u{1D4B7}"=>"b".freeze, "\u{1D4B8}"=>"c".freeze, "\u{1D4B9}"=>"d".freeze, "\u{1D4BB}"=>"f".freeze,
- "\u{1D4BD}"=>"h".freeze, "\u{1D4BE}"=>"i".freeze, "\u{1D4BF}"=>"j".freeze, "\u{1D4C0}"=>"k".freeze, "\u{1D4C1}"=>"l".freeze, "\u{1D4C2}"=>"m".freeze, "\u{1D4C3}"=>"n".freeze, "\u{1D4C5}"=>"p".freeze,
- "\u{1D4C6}"=>"q".freeze, "\u{1D4C7}"=>"r".freeze, "\u{1D4C8}"=>"s".freeze, "\u{1D4C9}"=>"t".freeze, "\u{1D4CA}"=>"u".freeze, "\u{1D4CB}"=>"v".freeze, "\u{1D4CC}"=>"w".freeze, "\u{1D4CD}"=>"x".freeze,
- "\u{1D4CE}"=>"y".freeze, "\u{1D4CF}"=>"z".freeze, "\u{1D4D0}"=>"A".freeze, "\u{1D4D1}"=>"B".freeze, "\u{1D4D2}"=>"C".freeze, "\u{1D4D3}"=>"D".freeze, "\u{1D4D4}"=>"E".freeze, "\u{1D4D5}"=>"F".freeze,
- "\u{1D4D6}"=>"G".freeze, "\u{1D4D7}"=>"H".freeze, "\u{1D4D8}"=>"I".freeze, "\u{1D4D9}"=>"J".freeze, "\u{1D4DA}"=>"K".freeze, "\u{1D4DB}"=>"L".freeze, "\u{1D4DC}"=>"M".freeze, "\u{1D4DD}"=>"N".freeze,
- "\u{1D4DE}"=>"O".freeze, "\u{1D4DF}"=>"P".freeze, "\u{1D4E0}"=>"Q".freeze, "\u{1D4E1}"=>"R".freeze, "\u{1D4E2}"=>"S".freeze, "\u{1D4E3}"=>"T".freeze, "\u{1D4E4}"=>"U".freeze, "\u{1D4E5}"=>"V".freeze,
- "\u{1D4E6}"=>"W".freeze, "\u{1D4E7}"=>"X".freeze, "\u{1D4E8}"=>"Y".freeze, "\u{1D4E9}"=>"Z".freeze, "\u{1D4EA}"=>"a".freeze, "\u{1D4EB}"=>"b".freeze, "\u{1D4EC}"=>"c".freeze, "\u{1D4ED}"=>"d".freeze,
- "\u{1D4EE}"=>"e".freeze, "\u{1D4EF}"=>"f".freeze, "\u{1D4F0}"=>"g".freeze, "\u{1D4F1}"=>"h".freeze, "\u{1D4F2}"=>"i".freeze, "\u{1D4F3}"=>"j".freeze, "\u{1D4F4}"=>"k".freeze, "\u{1D4F5}"=>"l".freeze,
- "\u{1D4F6}"=>"m".freeze, "\u{1D4F7}"=>"n".freeze, "\u{1D4F8}"=>"o".freeze, "\u{1D4F9}"=>"p".freeze, "\u{1D4FA}"=>"q".freeze, "\u{1D4FB}"=>"r".freeze, "\u{1D4FC}"=>"s".freeze, "\u{1D4FD}"=>"t".freeze,
- "\u{1D4FE}"=>"u".freeze, "\u{1D4FF}"=>"v".freeze, "\u{1D500}"=>"w".freeze, "\u{1D501}"=>"x".freeze, "\u{1D502}"=>"y".freeze, "\u{1D503}"=>"z".freeze, "\u{1D504}"=>"A".freeze, "\u{1D505}"=>"B".freeze,
- "\u{1D507}"=>"D".freeze, "\u{1D508}"=>"E".freeze, "\u{1D509}"=>"F".freeze, "\u{1D50A}"=>"G".freeze, "\u{1D50D}"=>"J".freeze, "\u{1D50E}"=>"K".freeze, "\u{1D50F}"=>"L".freeze, "\u{1D510}"=>"M".freeze,
- "\u{1D511}"=>"N".freeze, "\u{1D512}"=>"O".freeze, "\u{1D513}"=>"P".freeze, "\u{1D514}"=>"Q".freeze, "\u{1D516}"=>"S".freeze, "\u{1D517}"=>"T".freeze, "\u{1D518}"=>"U".freeze, "\u{1D519}"=>"V".freeze,
- "\u{1D51A}"=>"W".freeze, "\u{1D51B}"=>"X".freeze, "\u{1D51C}"=>"Y".freeze, "\u{1D51E}"=>"a".freeze, "\u{1D51F}"=>"b".freeze, "\u{1D520}"=>"c".freeze, "\u{1D521}"=>"d".freeze, "\u{1D522}"=>"e".freeze,
- "\u{1D523}"=>"f".freeze, "\u{1D524}"=>"g".freeze, "\u{1D525}"=>"h".freeze, "\u{1D526}"=>"i".freeze, "\u{1D527}"=>"j".freeze, "\u{1D528}"=>"k".freeze, "\u{1D529}"=>"l".freeze, "\u{1D52A}"=>"m".freeze,
- "\u{1D52B}"=>"n".freeze, "\u{1D52C}"=>"o".freeze, "\u{1D52D}"=>"p".freeze, "\u{1D52E}"=>"q".freeze, "\u{1D52F}"=>"r".freeze, "\u{1D530}"=>"s".freeze, "\u{1D531}"=>"t".freeze, "\u{1D532}"=>"u".freeze,
- "\u{1D533}"=>"v".freeze, "\u{1D534}"=>"w".freeze, "\u{1D535}"=>"x".freeze, "\u{1D536}"=>"y".freeze, "\u{1D537}"=>"z".freeze, "\u{1D538}"=>"A".freeze, "\u{1D539}"=>"B".freeze, "\u{1D53B}"=>"D".freeze,
- "\u{1D53C}"=>"E".freeze, "\u{1D53D}"=>"F".freeze, "\u{1D53E}"=>"G".freeze, "\u{1D540}"=>"I".freeze, "\u{1D541}"=>"J".freeze, "\u{1D542}"=>"K".freeze, "\u{1D543}"=>"L".freeze, "\u{1D544}"=>"M".freeze,
- "\u{1D546}"=>"O".freeze, "\u{1D54A}"=>"S".freeze, "\u{1D54B}"=>"T".freeze, "\u{1D54C}"=>"U".freeze, "\u{1D54D}"=>"V".freeze, "\u{1D54E}"=>"W".freeze, "\u{1D54F}"=>"X".freeze, "\u{1D550}"=>"Y".freeze,
- "\u{1D552}"=>"a".freeze, "\u{1D553}"=>"b".freeze, "\u{1D554}"=>"c".freeze, "\u{1D555}"=>"d".freeze, "\u{1D556}"=>"e".freeze, "\u{1D557}"=>"f".freeze, "\u{1D558}"=>"g".freeze, "\u{1D559}"=>"h".freeze,
- "\u{1D55A}"=>"i".freeze, "\u{1D55B}"=>"j".freeze, "\u{1D55C}"=>"k".freeze, "\u{1D55D}"=>"l".freeze, "\u{1D55E}"=>"m".freeze, "\u{1D55F}"=>"n".freeze, "\u{1D560}"=>"o".freeze, "\u{1D561}"=>"p".freeze,
- "\u{1D562}"=>"q".freeze, "\u{1D563}"=>"r".freeze, "\u{1D564}"=>"s".freeze, "\u{1D565}"=>"t".freeze, "\u{1D566}"=>"u".freeze, "\u{1D567}"=>"v".freeze, "\u{1D568}"=>"w".freeze, "\u{1D569}"=>"x".freeze,
- "\u{1D56A}"=>"y".freeze, "\u{1D56B}"=>"z".freeze, "\u{1D56C}"=>"A".freeze, "\u{1D56D}"=>"B".freeze, "\u{1D56E}"=>"C".freeze, "\u{1D56F}"=>"D".freeze, "\u{1D570}"=>"E".freeze, "\u{1D571}"=>"F".freeze,
- "\u{1D572}"=>"G".freeze, "\u{1D573}"=>"H".freeze, "\u{1D574}"=>"I".freeze, "\u{1D575}"=>"J".freeze, "\u{1D576}"=>"K".freeze, "\u{1D577}"=>"L".freeze, "\u{1D578}"=>"M".freeze, "\u{1D579}"=>"N".freeze,
- "\u{1D57A}"=>"O".freeze, "\u{1D57B}"=>"P".freeze, "\u{1D57C}"=>"Q".freeze, "\u{1D57D}"=>"R".freeze, "\u{1D57E}"=>"S".freeze, "\u{1D57F}"=>"T".freeze, "\u{1D580}"=>"U".freeze, "\u{1D581}"=>"V".freeze,
- "\u{1D582}"=>"W".freeze, "\u{1D583}"=>"X".freeze, "\u{1D584}"=>"Y".freeze, "\u{1D585}"=>"Z".freeze, "\u{1D586}"=>"a".freeze, "\u{1D587}"=>"b".freeze, "\u{1D588}"=>"c".freeze, "\u{1D589}"=>"d".freeze,
- "\u{1D58A}"=>"e".freeze, "\u{1D58B}"=>"f".freeze, "\u{1D58C}"=>"g".freeze, "\u{1D58D}"=>"h".freeze, "\u{1D58E}"=>"i".freeze, "\u{1D58F}"=>"j".freeze, "\u{1D590}"=>"k".freeze, "\u{1D591}"=>"l".freeze,
- "\u{1D592}"=>"m".freeze, "\u{1D593}"=>"n".freeze, "\u{1D594}"=>"o".freeze, "\u{1D595}"=>"p".freeze, "\u{1D596}"=>"q".freeze, "\u{1D597}"=>"r".freeze, "\u{1D598}"=>"s".freeze, "\u{1D599}"=>"t".freeze,
- "\u{1D59A}"=>"u".freeze, "\u{1D59B}"=>"v".freeze, "\u{1D59C}"=>"w".freeze, "\u{1D59D}"=>"x".freeze, "\u{1D59E}"=>"y".freeze, "\u{1D59F}"=>"z".freeze, "\u{1D5A0}"=>"A".freeze, "\u{1D5A1}"=>"B".freeze,
- "\u{1D5A2}"=>"C".freeze, "\u{1D5A3}"=>"D".freeze, "\u{1D5A4}"=>"E".freeze, "\u{1D5A5}"=>"F".freeze, "\u{1D5A6}"=>"G".freeze, "\u{1D5A7}"=>"H".freeze, "\u{1D5A8}"=>"I".freeze, "\u{1D5A9}"=>"J".freeze,
- "\u{1D5AA}"=>"K".freeze, "\u{1D5AB}"=>"L".freeze, "\u{1D5AC}"=>"M".freeze, "\u{1D5AD}"=>"N".freeze, "\u{1D5AE}"=>"O".freeze, "\u{1D5AF}"=>"P".freeze, "\u{1D5B0}"=>"Q".freeze, "\u{1D5B1}"=>"R".freeze,
- "\u{1D5B2}"=>"S".freeze, "\u{1D5B3}"=>"T".freeze, "\u{1D5B4}"=>"U".freeze, "\u{1D5B5}"=>"V".freeze, "\u{1D5B6}"=>"W".freeze, "\u{1D5B7}"=>"X".freeze, "\u{1D5B8}"=>"Y".freeze, "\u{1D5B9}"=>"Z".freeze,
- "\u{1D5BA}"=>"a".freeze, "\u{1D5BB}"=>"b".freeze, "\u{1D5BC}"=>"c".freeze, "\u{1D5BD}"=>"d".freeze, "\u{1D5BE}"=>"e".freeze, "\u{1D5BF}"=>"f".freeze, "\u{1D5C0}"=>"g".freeze, "\u{1D5C1}"=>"h".freeze,
- "\u{1D5C2}"=>"i".freeze, "\u{1D5C3}"=>"j".freeze, "\u{1D5C4}"=>"k".freeze, "\u{1D5C5}"=>"l".freeze, "\u{1D5C6}"=>"m".freeze, "\u{1D5C7}"=>"n".freeze, "\u{1D5C8}"=>"o".freeze, "\u{1D5C9}"=>"p".freeze,
- "\u{1D5CA}"=>"q".freeze, "\u{1D5CB}"=>"r".freeze, "\u{1D5CC}"=>"s".freeze, "\u{1D5CD}"=>"t".freeze, "\u{1D5CE}"=>"u".freeze, "\u{1D5CF}"=>"v".freeze, "\u{1D5D0}"=>"w".freeze, "\u{1D5D1}"=>"x".freeze,
- "\u{1D5D2}"=>"y".freeze, "\u{1D5D3}"=>"z".freeze, "\u{1D5D4}"=>"A".freeze, "\u{1D5D5}"=>"B".freeze, "\u{1D5D6}"=>"C".freeze, "\u{1D5D7}"=>"D".freeze, "\u{1D5D8}"=>"E".freeze, "\u{1D5D9}"=>"F".freeze,
- "\u{1D5DA}"=>"G".freeze, "\u{1D5DB}"=>"H".freeze, "\u{1D5DC}"=>"I".freeze, "\u{1D5DD}"=>"J".freeze, "\u{1D5DE}"=>"K".freeze, "\u{1D5DF}"=>"L".freeze, "\u{1D5E0}"=>"M".freeze, "\u{1D5E1}"=>"N".freeze,
- "\u{1D5E2}"=>"O".freeze, "\u{1D5E3}"=>"P".freeze, "\u{1D5E4}"=>"Q".freeze, "\u{1D5E5}"=>"R".freeze, "\u{1D5E6}"=>"S".freeze, "\u{1D5E7}"=>"T".freeze, "\u{1D5E8}"=>"U".freeze, "\u{1D5E9}"=>"V".freeze,
- "\u{1D5EA}"=>"W".freeze, "\u{1D5EB}"=>"X".freeze, "\u{1D5EC}"=>"Y".freeze, "\u{1D5ED}"=>"Z".freeze, "\u{1D5EE}"=>"a".freeze, "\u{1D5EF}"=>"b".freeze, "\u{1D5F0}"=>"c".freeze, "\u{1D5F1}"=>"d".freeze,
- "\u{1D5F2}"=>"e".freeze, "\u{1D5F3}"=>"f".freeze, "\u{1D5F4}"=>"g".freeze, "\u{1D5F5}"=>"h".freeze, "\u{1D5F6}"=>"i".freeze, "\u{1D5F7}"=>"j".freeze, "\u{1D5F8}"=>"k".freeze, "\u{1D5F9}"=>"l".freeze,
- "\u{1D5FA}"=>"m".freeze, "\u{1D5FB}"=>"n".freeze, "\u{1D5FC}"=>"o".freeze, "\u{1D5FD}"=>"p".freeze, "\u{1D5FE}"=>"q".freeze, "\u{1D5FF}"=>"r".freeze, "\u{1D600}"=>"s".freeze, "\u{1D601}"=>"t".freeze,
- "\u{1D602}"=>"u".freeze, "\u{1D603}"=>"v".freeze, "\u{1D604}"=>"w".freeze, "\u{1D605}"=>"x".freeze, "\u{1D606}"=>"y".freeze, "\u{1D607}"=>"z".freeze, "\u{1D608}"=>"A".freeze, "\u{1D609}"=>"B".freeze,
- "\u{1D60A}"=>"C".freeze, "\u{1D60B}"=>"D".freeze, "\u{1D60C}"=>"E".freeze, "\u{1D60D}"=>"F".freeze, "\u{1D60E}"=>"G".freeze, "\u{1D60F}"=>"H".freeze, "\u{1D610}"=>"I".freeze, "\u{1D611}"=>"J".freeze,
- "\u{1D612}"=>"K".freeze, "\u{1D613}"=>"L".freeze, "\u{1D614}"=>"M".freeze, "\u{1D615}"=>"N".freeze, "\u{1D616}"=>"O".freeze, "\u{1D617}"=>"P".freeze, "\u{1D618}"=>"Q".freeze, "\u{1D619}"=>"R".freeze,
- "\u{1D61A}"=>"S".freeze, "\u{1D61B}"=>"T".freeze, "\u{1D61C}"=>"U".freeze, "\u{1D61D}"=>"V".freeze, "\u{1D61E}"=>"W".freeze, "\u{1D61F}"=>"X".freeze, "\u{1D620}"=>"Y".freeze, "\u{1D621}"=>"Z".freeze,
- "\u{1D622}"=>"a".freeze, "\u{1D623}"=>"b".freeze, "\u{1D624}"=>"c".freeze, "\u{1D625}"=>"d".freeze, "\u{1D626}"=>"e".freeze, "\u{1D627}"=>"f".freeze, "\u{1D628}"=>"g".freeze, "\u{1D629}"=>"h".freeze,
- "\u{1D62A}"=>"i".freeze, "\u{1D62B}"=>"j".freeze, "\u{1D62C}"=>"k".freeze, "\u{1D62D}"=>"l".freeze, "\u{1D62E}"=>"m".freeze, "\u{1D62F}"=>"n".freeze, "\u{1D630}"=>"o".freeze, "\u{1D631}"=>"p".freeze,
- "\u{1D632}"=>"q".freeze, "\u{1D633}"=>"r".freeze, "\u{1D634}"=>"s".freeze, "\u{1D635}"=>"t".freeze, "\u{1D636}"=>"u".freeze, "\u{1D637}"=>"v".freeze, "\u{1D638}"=>"w".freeze, "\u{1D639}"=>"x".freeze,
- "\u{1D63A}"=>"y".freeze, "\u{1D63B}"=>"z".freeze, "\u{1D63C}"=>"A".freeze, "\u{1D63D}"=>"B".freeze, "\u{1D63E}"=>"C".freeze, "\u{1D63F}"=>"D".freeze, "\u{1D640}"=>"E".freeze, "\u{1D641}"=>"F".freeze,
- "\u{1D642}"=>"G".freeze, "\u{1D643}"=>"H".freeze, "\u{1D644}"=>"I".freeze, "\u{1D645}"=>"J".freeze, "\u{1D646}"=>"K".freeze, "\u{1D647}"=>"L".freeze, "\u{1D648}"=>"M".freeze, "\u{1D649}"=>"N".freeze,
- "\u{1D64A}"=>"O".freeze, "\u{1D64B}"=>"P".freeze, "\u{1D64C}"=>"Q".freeze, "\u{1D64D}"=>"R".freeze, "\u{1D64E}"=>"S".freeze, "\u{1D64F}"=>"T".freeze, "\u{1D650}"=>"U".freeze, "\u{1D651}"=>"V".freeze,
- "\u{1D652}"=>"W".freeze, "\u{1D653}"=>"X".freeze, "\u{1D654}"=>"Y".freeze, "\u{1D655}"=>"Z".freeze, "\u{1D656}"=>"a".freeze, "\u{1D657}"=>"b".freeze, "\u{1D658}"=>"c".freeze, "\u{1D659}"=>"d".freeze,
- "\u{1D65A}"=>"e".freeze, "\u{1D65B}"=>"f".freeze, "\u{1D65C}"=>"g".freeze, "\u{1D65D}"=>"h".freeze, "\u{1D65E}"=>"i".freeze, "\u{1D65F}"=>"j".freeze, "\u{1D660}"=>"k".freeze, "\u{1D661}"=>"l".freeze,
- "\u{1D662}"=>"m".freeze, "\u{1D663}"=>"n".freeze, "\u{1D664}"=>"o".freeze, "\u{1D665}"=>"p".freeze, "\u{1D666}"=>"q".freeze, "\u{1D667}"=>"r".freeze, "\u{1D668}"=>"s".freeze, "\u{1D669}"=>"t".freeze,
- "\u{1D66A}"=>"u".freeze, "\u{1D66B}"=>"v".freeze, "\u{1D66C}"=>"w".freeze, "\u{1D66D}"=>"x".freeze, "\u{1D66E}"=>"y".freeze, "\u{1D66F}"=>"z".freeze, "\u{1D670}"=>"A".freeze, "\u{1D671}"=>"B".freeze,
- "\u{1D672}"=>"C".freeze, "\u{1D673}"=>"D".freeze, "\u{1D674}"=>"E".freeze, "\u{1D675}"=>"F".freeze, "\u{1D676}"=>"G".freeze, "\u{1D677}"=>"H".freeze, "\u{1D678}"=>"I".freeze, "\u{1D679}"=>"J".freeze,
- "\u{1D67A}"=>"K".freeze, "\u{1D67B}"=>"L".freeze, "\u{1D67C}"=>"M".freeze, "\u{1D67D}"=>"N".freeze, "\u{1D67E}"=>"O".freeze, "\u{1D67F}"=>"P".freeze, "\u{1D680}"=>"Q".freeze, "\u{1D681}"=>"R".freeze,
- "\u{1D682}"=>"S".freeze, "\u{1D683}"=>"T".freeze, "\u{1D684}"=>"U".freeze, "\u{1D685}"=>"V".freeze, "\u{1D686}"=>"W".freeze, "\u{1D687}"=>"X".freeze, "\u{1D688}"=>"Y".freeze, "\u{1D689}"=>"Z".freeze,
- "\u{1D68A}"=>"a".freeze, "\u{1D68B}"=>"b".freeze, "\u{1D68C}"=>"c".freeze, "\u{1D68D}"=>"d".freeze, "\u{1D68E}"=>"e".freeze, "\u{1D68F}"=>"f".freeze, "\u{1D690}"=>"g".freeze, "\u{1D691}"=>"h".freeze,
- "\u{1D692}"=>"i".freeze, "\u{1D693}"=>"j".freeze, "\u{1D694}"=>"k".freeze, "\u{1D695}"=>"l".freeze, "\u{1D696}"=>"m".freeze, "\u{1D697}"=>"n".freeze, "\u{1D698}"=>"o".freeze, "\u{1D699}"=>"p".freeze,
- "\u{1D69A}"=>"q".freeze, "\u{1D69B}"=>"r".freeze, "\u{1D69C}"=>"s".freeze, "\u{1D69D}"=>"t".freeze, "\u{1D69E}"=>"u".freeze, "\u{1D69F}"=>"v".freeze, "\u{1D6A0}"=>"w".freeze, "\u{1D6A1}"=>"x".freeze,
- "\u{1D6A2}"=>"y".freeze, "\u{1D6A3}"=>"z".freeze, "\u{1D6A4}"=>"\u0131".freeze, "\u{1D6A5}"=>"\u0237".freeze, "\u{1D6A8}"=>"\u0391".freeze, "\u{1D6A9}"=>"\u0392".freeze, "\u{1D6AA}"=>"\u0393".freeze, "\u{1D6AB}"=>"\u0394".freeze,
- "\u{1D6AC}"=>"\u0395".freeze, "\u{1D6AD}"=>"\u0396".freeze, "\u{1D6AE}"=>"\u0397".freeze, "\u{1D6AF}"=>"\u0398".freeze, "\u{1D6B0}"=>"\u0399".freeze, "\u{1D6B1}"=>"\u039A".freeze, "\u{1D6B2}"=>"\u039B".freeze, "\u{1D6B3}"=>"\u039C".freeze,
- "\u{1D6B4}"=>"\u039D".freeze, "\u{1D6B5}"=>"\u039E".freeze, "\u{1D6B6}"=>"\u039F".freeze, "\u{1D6B7}"=>"\u03A0".freeze, "\u{1D6B8}"=>"\u03A1".freeze, "\u{1D6B9}"=>"\u0398".freeze, "\u{1D6BA}"=>"\u03A3".freeze, "\u{1D6BB}"=>"\u03A4".freeze,
- "\u{1D6BC}"=>"\u03A5".freeze, "\u{1D6BD}"=>"\u03A6".freeze, "\u{1D6BE}"=>"\u03A7".freeze, "\u{1D6BF}"=>"\u03A8".freeze, "\u{1D6C0}"=>"\u03A9".freeze, "\u{1D6C1}"=>"\u2207".freeze, "\u{1D6C2}"=>"\u03B1".freeze, "\u{1D6C3}"=>"\u03B2".freeze,
- "\u{1D6C4}"=>"\u03B3".freeze, "\u{1D6C5}"=>"\u03B4".freeze, "\u{1D6C6}"=>"\u03B5".freeze, "\u{1D6C7}"=>"\u03B6".freeze, "\u{1D6C8}"=>"\u03B7".freeze, "\u{1D6C9}"=>"\u03B8".freeze, "\u{1D6CA}"=>"\u03B9".freeze, "\u{1D6CB}"=>"\u03BA".freeze,
- "\u{1D6CC}"=>"\u03BB".freeze, "\u{1D6CD}"=>"\u03BC".freeze, "\u{1D6CE}"=>"\u03BD".freeze, "\u{1D6CF}"=>"\u03BE".freeze, "\u{1D6D0}"=>"\u03BF".freeze, "\u{1D6D1}"=>"\u03C0".freeze, "\u{1D6D2}"=>"\u03C1".freeze, "\u{1D6D3}"=>"\u03C2".freeze,
- "\u{1D6D4}"=>"\u03C3".freeze, "\u{1D6D5}"=>"\u03C4".freeze, "\u{1D6D6}"=>"\u03C5".freeze, "\u{1D6D7}"=>"\u03C6".freeze, "\u{1D6D8}"=>"\u03C7".freeze, "\u{1D6D9}"=>"\u03C8".freeze, "\u{1D6DA}"=>"\u03C9".freeze, "\u{1D6DB}"=>"\u2202".freeze,
- "\u{1D6DC}"=>"\u03B5".freeze, "\u{1D6DD}"=>"\u03B8".freeze, "\u{1D6DE}"=>"\u03BA".freeze, "\u{1D6DF}"=>"\u03C6".freeze, "\u{1D6E0}"=>"\u03C1".freeze, "\u{1D6E1}"=>"\u03C0".freeze, "\u{1D6E2}"=>"\u0391".freeze, "\u{1D6E3}"=>"\u0392".freeze,
- "\u{1D6E4}"=>"\u0393".freeze, "\u{1D6E5}"=>"\u0394".freeze, "\u{1D6E6}"=>"\u0395".freeze, "\u{1D6E7}"=>"\u0396".freeze, "\u{1D6E8}"=>"\u0397".freeze, "\u{1D6E9}"=>"\u0398".freeze, "\u{1D6EA}"=>"\u0399".freeze, "\u{1D6EB}"=>"\u039A".freeze,
- "\u{1D6EC}"=>"\u039B".freeze, "\u{1D6ED}"=>"\u039C".freeze, "\u{1D6EE}"=>"\u039D".freeze, "\u{1D6EF}"=>"\u039E".freeze, "\u{1D6F0}"=>"\u039F".freeze, "\u{1D6F1}"=>"\u03A0".freeze, "\u{1D6F2}"=>"\u03A1".freeze, "\u{1D6F3}"=>"\u0398".freeze,
- "\u{1D6F4}"=>"\u03A3".freeze, "\u{1D6F5}"=>"\u03A4".freeze, "\u{1D6F6}"=>"\u03A5".freeze, "\u{1D6F7}"=>"\u03A6".freeze, "\u{1D6F8}"=>"\u03A7".freeze, "\u{1D6F9}"=>"\u03A8".freeze, "\u{1D6FA}"=>"\u03A9".freeze, "\u{1D6FB}"=>"\u2207".freeze,
- "\u{1D6FC}"=>"\u03B1".freeze, "\u{1D6FD}"=>"\u03B2".freeze, "\u{1D6FE}"=>"\u03B3".freeze, "\u{1D6FF}"=>"\u03B4".freeze, "\u{1D700}"=>"\u03B5".freeze, "\u{1D701}"=>"\u03B6".freeze, "\u{1D702}"=>"\u03B7".freeze, "\u{1D703}"=>"\u03B8".freeze,
- "\u{1D704}"=>"\u03B9".freeze, "\u{1D705}"=>"\u03BA".freeze, "\u{1D706}"=>"\u03BB".freeze, "\u{1D707}"=>"\u03BC".freeze, "\u{1D708}"=>"\u03BD".freeze, "\u{1D709}"=>"\u03BE".freeze, "\u{1D70A}"=>"\u03BF".freeze, "\u{1D70B}"=>"\u03C0".freeze,
- "\u{1D70C}"=>"\u03C1".freeze, "\u{1D70D}"=>"\u03C2".freeze, "\u{1D70E}"=>"\u03C3".freeze, "\u{1D70F}"=>"\u03C4".freeze, "\u{1D710}"=>"\u03C5".freeze, "\u{1D711}"=>"\u03C6".freeze, "\u{1D712}"=>"\u03C7".freeze, "\u{1D713}"=>"\u03C8".freeze,
- "\u{1D714}"=>"\u03C9".freeze, "\u{1D715}"=>"\u2202".freeze, "\u{1D716}"=>"\u03B5".freeze, "\u{1D717}"=>"\u03B8".freeze, "\u{1D718}"=>"\u03BA".freeze, "\u{1D719}"=>"\u03C6".freeze, "\u{1D71A}"=>"\u03C1".freeze, "\u{1D71B}"=>"\u03C0".freeze,
- "\u{1D71C}"=>"\u0391".freeze, "\u{1D71D}"=>"\u0392".freeze, "\u{1D71E}"=>"\u0393".freeze, "\u{1D71F}"=>"\u0394".freeze, "\u{1D720}"=>"\u0395".freeze, "\u{1D721}"=>"\u0396".freeze, "\u{1D722}"=>"\u0397".freeze, "\u{1D723}"=>"\u0398".freeze,
- "\u{1D724}"=>"\u0399".freeze, "\u{1D725}"=>"\u039A".freeze, "\u{1D726}"=>"\u039B".freeze, "\u{1D727}"=>"\u039C".freeze, "\u{1D728}"=>"\u039D".freeze, "\u{1D729}"=>"\u039E".freeze, "\u{1D72A}"=>"\u039F".freeze, "\u{1D72B}"=>"\u03A0".freeze,
- "\u{1D72C}"=>"\u03A1".freeze, "\u{1D72D}"=>"\u0398".freeze, "\u{1D72E}"=>"\u03A3".freeze, "\u{1D72F}"=>"\u03A4".freeze, "\u{1D730}"=>"\u03A5".freeze, "\u{1D731}"=>"\u03A6".freeze, "\u{1D732}"=>"\u03A7".freeze, "\u{1D733}"=>"\u03A8".freeze,
- "\u{1D734}"=>"\u03A9".freeze, "\u{1D735}"=>"\u2207".freeze, "\u{1D736}"=>"\u03B1".freeze, "\u{1D737}"=>"\u03B2".freeze, "\u{1D738}"=>"\u03B3".freeze, "\u{1D739}"=>"\u03B4".freeze, "\u{1D73A}"=>"\u03B5".freeze, "\u{1D73B}"=>"\u03B6".freeze,
- "\u{1D73C}"=>"\u03B7".freeze, "\u{1D73D}"=>"\u03B8".freeze, "\u{1D73E}"=>"\u03B9".freeze, "\u{1D73F}"=>"\u03BA".freeze, "\u{1D740}"=>"\u03BB".freeze, "\u{1D741}"=>"\u03BC".freeze, "\u{1D742}"=>"\u03BD".freeze, "\u{1D743}"=>"\u03BE".freeze,
- "\u{1D744}"=>"\u03BF".freeze, "\u{1D745}"=>"\u03C0".freeze, "\u{1D746}"=>"\u03C1".freeze, "\u{1D747}"=>"\u03C2".freeze, "\u{1D748}"=>"\u03C3".freeze, "\u{1D749}"=>"\u03C4".freeze, "\u{1D74A}"=>"\u03C5".freeze, "\u{1D74B}"=>"\u03C6".freeze,
- "\u{1D74C}"=>"\u03C7".freeze, "\u{1D74D}"=>"\u03C8".freeze, "\u{1D74E}"=>"\u03C9".freeze, "\u{1D74F}"=>"\u2202".freeze, "\u{1D750}"=>"\u03B5".freeze, "\u{1D751}"=>"\u03B8".freeze, "\u{1D752}"=>"\u03BA".freeze, "\u{1D753}"=>"\u03C6".freeze,
- "\u{1D754}"=>"\u03C1".freeze, "\u{1D755}"=>"\u03C0".freeze, "\u{1D756}"=>"\u0391".freeze, "\u{1D757}"=>"\u0392".freeze, "\u{1D758}"=>"\u0393".freeze, "\u{1D759}"=>"\u0394".freeze, "\u{1D75A}"=>"\u0395".freeze, "\u{1D75B}"=>"\u0396".freeze,
- "\u{1D75C}"=>"\u0397".freeze, "\u{1D75D}"=>"\u0398".freeze, "\u{1D75E}"=>"\u0399".freeze, "\u{1D75F}"=>"\u039A".freeze, "\u{1D760}"=>"\u039B".freeze, "\u{1D761}"=>"\u039C".freeze, "\u{1D762}"=>"\u039D".freeze, "\u{1D763}"=>"\u039E".freeze,
- "\u{1D764}"=>"\u039F".freeze, "\u{1D765}"=>"\u03A0".freeze, "\u{1D766}"=>"\u03A1".freeze, "\u{1D767}"=>"\u0398".freeze, "\u{1D768}"=>"\u03A3".freeze, "\u{1D769}"=>"\u03A4".freeze, "\u{1D76A}"=>"\u03A5".freeze, "\u{1D76B}"=>"\u03A6".freeze,
- "\u{1D76C}"=>"\u03A7".freeze, "\u{1D76D}"=>"\u03A8".freeze, "\u{1D76E}"=>"\u03A9".freeze, "\u{1D76F}"=>"\u2207".freeze, "\u{1D770}"=>"\u03B1".freeze, "\u{1D771}"=>"\u03B2".freeze, "\u{1D772}"=>"\u03B3".freeze, "\u{1D773}"=>"\u03B4".freeze,
- "\u{1D774}"=>"\u03B5".freeze, "\u{1D775}"=>"\u03B6".freeze, "\u{1D776}"=>"\u03B7".freeze, "\u{1D777}"=>"\u03B8".freeze, "\u{1D778}"=>"\u03B9".freeze, "\u{1D779}"=>"\u03BA".freeze, "\u{1D77A}"=>"\u03BB".freeze, "\u{1D77B}"=>"\u03BC".freeze,
- "\u{1D77C}"=>"\u03BD".freeze, "\u{1D77D}"=>"\u03BE".freeze, "\u{1D77E}"=>"\u03BF".freeze, "\u{1D77F}"=>"\u03C0".freeze, "\u{1D780}"=>"\u03C1".freeze, "\u{1D781}"=>"\u03C2".freeze, "\u{1D782}"=>"\u03C3".freeze, "\u{1D783}"=>"\u03C4".freeze,
- "\u{1D784}"=>"\u03C5".freeze, "\u{1D785}"=>"\u03C6".freeze, "\u{1D786}"=>"\u03C7".freeze, "\u{1D787}"=>"\u03C8".freeze, "\u{1D788}"=>"\u03C9".freeze, "\u{1D789}"=>"\u2202".freeze, "\u{1D78A}"=>"\u03B5".freeze, "\u{1D78B}"=>"\u03B8".freeze,
- "\u{1D78C}"=>"\u03BA".freeze, "\u{1D78D}"=>"\u03C6".freeze, "\u{1D78E}"=>"\u03C1".freeze, "\u{1D78F}"=>"\u03C0".freeze, "\u{1D790}"=>"\u0391".freeze, "\u{1D791}"=>"\u0392".freeze, "\u{1D792}"=>"\u0393".freeze, "\u{1D793}"=>"\u0394".freeze,
- "\u{1D794}"=>"\u0395".freeze, "\u{1D795}"=>"\u0396".freeze, "\u{1D796}"=>"\u0397".freeze, "\u{1D797}"=>"\u0398".freeze, "\u{1D798}"=>"\u0399".freeze, "\u{1D799}"=>"\u039A".freeze, "\u{1D79A}"=>"\u039B".freeze, "\u{1D79B}"=>"\u039C".freeze,
- "\u{1D79C}"=>"\u039D".freeze, "\u{1D79D}"=>"\u039E".freeze, "\u{1D79E}"=>"\u039F".freeze, "\u{1D79F}"=>"\u03A0".freeze, "\u{1D7A0}"=>"\u03A1".freeze, "\u{1D7A1}"=>"\u0398".freeze, "\u{1D7A2}"=>"\u03A3".freeze, "\u{1D7A3}"=>"\u03A4".freeze,
- "\u{1D7A4}"=>"\u03A5".freeze, "\u{1D7A5}"=>"\u03A6".freeze, "\u{1D7A6}"=>"\u03A7".freeze, "\u{1D7A7}"=>"\u03A8".freeze, "\u{1D7A8}"=>"\u03A9".freeze, "\u{1D7A9}"=>"\u2207".freeze, "\u{1D7AA}"=>"\u03B1".freeze, "\u{1D7AB}"=>"\u03B2".freeze,
- "\u{1D7AC}"=>"\u03B3".freeze, "\u{1D7AD}"=>"\u03B4".freeze, "\u{1D7AE}"=>"\u03B5".freeze, "\u{1D7AF}"=>"\u03B6".freeze, "\u{1D7B0}"=>"\u03B7".freeze, "\u{1D7B1}"=>"\u03B8".freeze, "\u{1D7B2}"=>"\u03B9".freeze, "\u{1D7B3}"=>"\u03BA".freeze,
- "\u{1D7B4}"=>"\u03BB".freeze, "\u{1D7B5}"=>"\u03BC".freeze, "\u{1D7B6}"=>"\u03BD".freeze, "\u{1D7B7}"=>"\u03BE".freeze, "\u{1D7B8}"=>"\u03BF".freeze, "\u{1D7B9}"=>"\u03C0".freeze, "\u{1D7BA}"=>"\u03C1".freeze, "\u{1D7BB}"=>"\u03C2".freeze,
- "\u{1D7BC}"=>"\u03C3".freeze, "\u{1D7BD}"=>"\u03C4".freeze, "\u{1D7BE}"=>"\u03C5".freeze, "\u{1D7BF}"=>"\u03C6".freeze, "\u{1D7C0}"=>"\u03C7".freeze, "\u{1D7C1}"=>"\u03C8".freeze, "\u{1D7C2}"=>"\u03C9".freeze, "\u{1D7C3}"=>"\u2202".freeze,
- "\u{1D7C4}"=>"\u03B5".freeze, "\u{1D7C5}"=>"\u03B8".freeze, "\u{1D7C6}"=>"\u03BA".freeze, "\u{1D7C7}"=>"\u03C6".freeze, "\u{1D7C8}"=>"\u03C1".freeze, "\u{1D7C9}"=>"\u03C0".freeze, "\u{1D7CA}"=>"\u03DC".freeze, "\u{1D7CB}"=>"\u03DD".freeze,
- "\u{1D7CE}"=>"0".freeze, "\u{1D7CF}"=>"1".freeze, "\u{1D7D0}"=>"2".freeze, "\u{1D7D1}"=>"3".freeze, "\u{1D7D2}"=>"4".freeze, "\u{1D7D3}"=>"5".freeze, "\u{1D7D4}"=>"6".freeze, "\u{1D7D5}"=>"7".freeze,
- "\u{1D7D6}"=>"8".freeze, "\u{1D7D7}"=>"9".freeze, "\u{1D7D8}"=>"0".freeze, "\u{1D7D9}"=>"1".freeze, "\u{1D7DA}"=>"2".freeze, "\u{1D7DB}"=>"3".freeze, "\u{1D7DC}"=>"4".freeze, "\u{1D7DD}"=>"5".freeze,
- "\u{1D7DE}"=>"6".freeze, "\u{1D7DF}"=>"7".freeze, "\u{1D7E0}"=>"8".freeze, "\u{1D7E1}"=>"9".freeze, "\u{1D7E2}"=>"0".freeze, "\u{1D7E3}"=>"1".freeze, "\u{1D7E4}"=>"2".freeze, "\u{1D7E5}"=>"3".freeze,
- "\u{1D7E6}"=>"4".freeze, "\u{1D7E7}"=>"5".freeze, "\u{1D7E8}"=>"6".freeze, "\u{1D7E9}"=>"7".freeze, "\u{1D7EA}"=>"8".freeze, "\u{1D7EB}"=>"9".freeze, "\u{1D7EC}"=>"0".freeze, "\u{1D7ED}"=>"1".freeze,
- "\u{1D7EE}"=>"2".freeze, "\u{1D7EF}"=>"3".freeze, "\u{1D7F0}"=>"4".freeze, "\u{1D7F1}"=>"5".freeze, "\u{1D7F2}"=>"6".freeze, "\u{1D7F3}"=>"7".freeze, "\u{1D7F4}"=>"8".freeze, "\u{1D7F5}"=>"9".freeze,
- "\u{1D7F6}"=>"0".freeze, "\u{1D7F7}"=>"1".freeze, "\u{1D7F8}"=>"2".freeze, "\u{1D7F9}"=>"3".freeze, "\u{1D7FA}"=>"4".freeze, "\u{1D7FB}"=>"5".freeze, "\u{1D7FC}"=>"6".freeze, "\u{1D7FD}"=>"7".freeze,
- "\u{1D7FE}"=>"8".freeze, "\u{1D7FF}"=>"9".freeze, "\u{1EE00}"=>"\u0627".freeze, "\u{1EE01}"=>"\u0628".freeze, "\u{1EE02}"=>"\u062C".freeze, "\u{1EE03}"=>"\u062F".freeze, "\u{1EE05}"=>"\u0648".freeze, "\u{1EE06}"=>"\u0632".freeze,
- "\u{1EE07}"=>"\u062D".freeze, "\u{1EE08}"=>"\u0637".freeze, "\u{1EE09}"=>"\u064A".freeze, "\u{1EE0A}"=>"\u0643".freeze, "\u{1EE0B}"=>"\u0644".freeze, "\u{1EE0C}"=>"\u0645".freeze, "\u{1EE0D}"=>"\u0646".freeze, "\u{1EE0E}"=>"\u0633".freeze,
- "\u{1EE0F}"=>"\u0639".freeze, "\u{1EE10}"=>"\u0641".freeze, "\u{1EE11}"=>"\u0635".freeze, "\u{1EE12}"=>"\u0642".freeze, "\u{1EE13}"=>"\u0631".freeze, "\u{1EE14}"=>"\u0634".freeze, "\u{1EE15}"=>"\u062A".freeze, "\u{1EE16}"=>"\u062B".freeze,
- "\u{1EE17}"=>"\u062E".freeze, "\u{1EE18}"=>"\u0630".freeze, "\u{1EE19}"=>"\u0636".freeze, "\u{1EE1A}"=>"\u0638".freeze, "\u{1EE1B}"=>"\u063A".freeze, "\u{1EE1C}"=>"\u066E".freeze, "\u{1EE1D}"=>"\u06BA".freeze, "\u{1EE1E}"=>"\u06A1".freeze,
- "\u{1EE1F}"=>"\u066F".freeze, "\u{1EE21}"=>"\u0628".freeze, "\u{1EE22}"=>"\u062C".freeze, "\u{1EE24}"=>"\u0647".freeze, "\u{1EE27}"=>"\u062D".freeze, "\u{1EE29}"=>"\u064A".freeze, "\u{1EE2A}"=>"\u0643".freeze, "\u{1EE2B}"=>"\u0644".freeze,
- "\u{1EE2C}"=>"\u0645".freeze, "\u{1EE2D}"=>"\u0646".freeze, "\u{1EE2E}"=>"\u0633".freeze, "\u{1EE2F}"=>"\u0639".freeze, "\u{1EE30}"=>"\u0641".freeze, "\u{1EE31}"=>"\u0635".freeze, "\u{1EE32}"=>"\u0642".freeze, "\u{1EE34}"=>"\u0634".freeze,
- "\u{1EE35}"=>"\u062A".freeze, "\u{1EE36}"=>"\u062B".freeze, "\u{1EE37}"=>"\u062E".freeze, "\u{1EE39}"=>"\u0636".freeze, "\u{1EE3B}"=>"\u063A".freeze, "\u{1EE42}"=>"\u062C".freeze, "\u{1EE47}"=>"\u062D".freeze, "\u{1EE49}"=>"\u064A".freeze,
- "\u{1EE4B}"=>"\u0644".freeze, "\u{1EE4D}"=>"\u0646".freeze, "\u{1EE4E}"=>"\u0633".freeze, "\u{1EE4F}"=>"\u0639".freeze, "\u{1EE51}"=>"\u0635".freeze, "\u{1EE52}"=>"\u0642".freeze, "\u{1EE54}"=>"\u0634".freeze, "\u{1EE57}"=>"\u062E".freeze,
- "\u{1EE59}"=>"\u0636".freeze, "\u{1EE5B}"=>"\u063A".freeze, "\u{1EE5D}"=>"\u06BA".freeze, "\u{1EE5F}"=>"\u066F".freeze, "\u{1EE61}"=>"\u0628".freeze, "\u{1EE62}"=>"\u062C".freeze, "\u{1EE64}"=>"\u0647".freeze, "\u{1EE67}"=>"\u062D".freeze,
- "\u{1EE68}"=>"\u0637".freeze, "\u{1EE69}"=>"\u064A".freeze, "\u{1EE6A}"=>"\u0643".freeze, "\u{1EE6C}"=>"\u0645".freeze, "\u{1EE6D}"=>"\u0646".freeze, "\u{1EE6E}"=>"\u0633".freeze, "\u{1EE6F}"=>"\u0639".freeze, "\u{1EE70}"=>"\u0641".freeze,
- "\u{1EE71}"=>"\u0635".freeze, "\u{1EE72}"=>"\u0642".freeze, "\u{1EE74}"=>"\u0634".freeze, "\u{1EE75}"=>"\u062A".freeze, "\u{1EE76}"=>"\u062B".freeze, "\u{1EE77}"=>"\u062E".freeze, "\u{1EE79}"=>"\u0636".freeze, "\u{1EE7A}"=>"\u0638".freeze,
- "\u{1EE7B}"=>"\u063A".freeze, "\u{1EE7C}"=>"\u066E".freeze, "\u{1EE7E}"=>"\u06A1".freeze, "\u{1EE80}"=>"\u0627".freeze, "\u{1EE81}"=>"\u0628".freeze, "\u{1EE82}"=>"\u062C".freeze, "\u{1EE83}"=>"\u062F".freeze, "\u{1EE84}"=>"\u0647".freeze,
- "\u{1EE85}"=>"\u0648".freeze, "\u{1EE86}"=>"\u0632".freeze, "\u{1EE87}"=>"\u062D".freeze, "\u{1EE88}"=>"\u0637".freeze, "\u{1EE89}"=>"\u064A".freeze, "\u{1EE8B}"=>"\u0644".freeze, "\u{1EE8C}"=>"\u0645".freeze, "\u{1EE8D}"=>"\u0646".freeze,
- "\u{1EE8E}"=>"\u0633".freeze, "\u{1EE8F}"=>"\u0639".freeze, "\u{1EE90}"=>"\u0641".freeze, "\u{1EE91}"=>"\u0635".freeze, "\u{1EE92}"=>"\u0642".freeze, "\u{1EE93}"=>"\u0631".freeze, "\u{1EE94}"=>"\u0634".freeze, "\u{1EE95}"=>"\u062A".freeze,
- "\u{1EE96}"=>"\u062B".freeze, "\u{1EE97}"=>"\u062E".freeze, "\u{1EE98}"=>"\u0630".freeze, "\u{1EE99}"=>"\u0636".freeze, "\u{1EE9A}"=>"\u0638".freeze, "\u{1EE9B}"=>"\u063A".freeze, "\u{1EEA1}"=>"\u0628".freeze, "\u{1EEA2}"=>"\u062C".freeze,
- "\u{1EEA3}"=>"\u062F".freeze, "\u{1EEA5}"=>"\u0648".freeze, "\u{1EEA6}"=>"\u0632".freeze, "\u{1EEA7}"=>"\u062D".freeze, "\u{1EEA8}"=>"\u0637".freeze, "\u{1EEA9}"=>"\u064A".freeze, "\u{1EEAB}"=>"\u0644".freeze, "\u{1EEAC}"=>"\u0645".freeze,
- "\u{1EEAD}"=>"\u0646".freeze, "\u{1EEAE}"=>"\u0633".freeze, "\u{1EEAF}"=>"\u0639".freeze, "\u{1EEB0}"=>"\u0641".freeze, "\u{1EEB1}"=>"\u0635".freeze, "\u{1EEB2}"=>"\u0642".freeze, "\u{1EEB3}"=>"\u0631".freeze, "\u{1EEB4}"=>"\u0634".freeze,
- "\u{1EEB5}"=>"\u062A".freeze, "\u{1EEB6}"=>"\u062B".freeze, "\u{1EEB7}"=>"\u062E".freeze, "\u{1EEB8}"=>"\u0630".freeze, "\u{1EEB9}"=>"\u0636".freeze, "\u{1EEBA}"=>"\u0638".freeze, "\u{1EEBB}"=>"\u063A".freeze, "\u{1F100}"=>"0.".freeze,
- "\u{1F101}"=>"0,".freeze, "\u{1F102}"=>"1,".freeze, "\u{1F103}"=>"2,".freeze, "\u{1F104}"=>"3,".freeze, "\u{1F105}"=>"4,".freeze, "\u{1F106}"=>"5,".freeze, "\u{1F107}"=>"6,".freeze, "\u{1F108}"=>"7,".freeze,
- "\u{1F109}"=>"8,".freeze, "\u{1F10A}"=>"9,".freeze, "\u{1F110}"=>"(A)".freeze, "\u{1F111}"=>"(B)".freeze, "\u{1F112}"=>"(C)".freeze, "\u{1F113}"=>"(D)".freeze, "\u{1F114}"=>"(E)".freeze, "\u{1F115}"=>"(F)".freeze,
- "\u{1F116}"=>"(G)".freeze, "\u{1F117}"=>"(H)".freeze, "\u{1F118}"=>"(I)".freeze, "\u{1F119}"=>"(J)".freeze, "\u{1F11A}"=>"(K)".freeze, "\u{1F11B}"=>"(L)".freeze, "\u{1F11C}"=>"(M)".freeze, "\u{1F11D}"=>"(N)".freeze,
- "\u{1F11E}"=>"(O)".freeze, "\u{1F11F}"=>"(P)".freeze, "\u{1F120}"=>"(Q)".freeze, "\u{1F121}"=>"(R)".freeze, "\u{1F122}"=>"(S)".freeze, "\u{1F123}"=>"(T)".freeze, "\u{1F124}"=>"(U)".freeze, "\u{1F125}"=>"(V)".freeze,
- "\u{1F126}"=>"(W)".freeze, "\u{1F127}"=>"(X)".freeze, "\u{1F128}"=>"(Y)".freeze, "\u{1F129}"=>"(Z)".freeze, "\u{1F12A}"=>"\u3014S\u3015".freeze, "\u{1F12B}"=>"C".freeze, "\u{1F12C}"=>"R".freeze, "\u{1F12D}"=>"CD".freeze,
- "\u{1F12E}"=>"WZ".freeze, "\u{1F130}"=>"A".freeze, "\u{1F131}"=>"B".freeze, "\u{1F132}"=>"C".freeze, "\u{1F133}"=>"D".freeze, "\u{1F134}"=>"E".freeze, "\u{1F135}"=>"F".freeze, "\u{1F136}"=>"G".freeze,
- "\u{1F137}"=>"H".freeze, "\u{1F138}"=>"I".freeze, "\u{1F139}"=>"J".freeze, "\u{1F13A}"=>"K".freeze, "\u{1F13B}"=>"L".freeze, "\u{1F13C}"=>"M".freeze, "\u{1F13D}"=>"N".freeze, "\u{1F13E}"=>"O".freeze,
- "\u{1F13F}"=>"P".freeze, "\u{1F140}"=>"Q".freeze, "\u{1F141}"=>"R".freeze, "\u{1F142}"=>"S".freeze, "\u{1F143}"=>"T".freeze, "\u{1F144}"=>"U".freeze, "\u{1F145}"=>"V".freeze, "\u{1F146}"=>"W".freeze,
- "\u{1F147}"=>"X".freeze, "\u{1F148}"=>"Y".freeze, "\u{1F149}"=>"Z".freeze, "\u{1F14A}"=>"HV".freeze, "\u{1F14B}"=>"MV".freeze, "\u{1F14C}"=>"SD".freeze, "\u{1F14D}"=>"SS".freeze, "\u{1F14E}"=>"PPV".freeze,
- "\u{1F14F}"=>"WC".freeze, "\u{1F16A}"=>"MC".freeze, "\u{1F16B}"=>"MD".freeze, "\u{1F190}"=>"DJ".freeze, "\u{1F200}"=>"\u307B\u304B".freeze, "\u{1F201}"=>"\u30B3\u30B3".freeze, "\u{1F202}"=>"\u30B5".freeze, "\u{1F210}"=>"\u624B".freeze,
- "\u{1F211}"=>"\u5B57".freeze, "\u{1F212}"=>"\u53CC".freeze, "\u{1F213}"=>"\u30C7".freeze, "\u{1F214}"=>"\u4E8C".freeze, "\u{1F215}"=>"\u591A".freeze, "\u{1F216}"=>"\u89E3".freeze, "\u{1F217}"=>"\u5929".freeze, "\u{1F218}"=>"\u4EA4".freeze,
- "\u{1F219}"=>"\u6620".freeze, "\u{1F21A}"=>"\u7121".freeze, "\u{1F21B}"=>"\u6599".freeze, "\u{1F21C}"=>"\u524D".freeze, "\u{1F21D}"=>"\u5F8C".freeze, "\u{1F21E}"=>"\u518D".freeze, "\u{1F21F}"=>"\u65B0".freeze, "\u{1F220}"=>"\u521D".freeze,
- "\u{1F221}"=>"\u7D42".freeze, "\u{1F222}"=>"\u751F".freeze, "\u{1F223}"=>"\u8CA9".freeze, "\u{1F224}"=>"\u58F0".freeze, "\u{1F225}"=>"\u5439".freeze, "\u{1F226}"=>"\u6F14".freeze, "\u{1F227}"=>"\u6295".freeze, "\u{1F228}"=>"\u6355".freeze,
- "\u{1F229}"=>"\u4E00".freeze, "\u{1F22A}"=>"\u4E09".freeze, "\u{1F22B}"=>"\u904A".freeze, "\u{1F22C}"=>"\u5DE6".freeze, "\u{1F22D}"=>"\u4E2D".freeze, "\u{1F22E}"=>"\u53F3".freeze, "\u{1F22F}"=>"\u6307".freeze, "\u{1F230}"=>"\u8D70".freeze,
- "\u{1F231}"=>"\u6253".freeze, "\u{1F232}"=>"\u7981".freeze, "\u{1F233}"=>"\u7A7A".freeze, "\u{1F234}"=>"\u5408".freeze, "\u{1F235}"=>"\u6E80".freeze, "\u{1F236}"=>"\u6709".freeze, "\u{1F237}"=>"\u6708".freeze, "\u{1F238}"=>"\u7533".freeze,
- "\u{1F239}"=>"\u5272".freeze, "\u{1F23A}"=>"\u55B6".freeze, "\u{1F240}"=>"\u3014\u672C\u3015".freeze, "\u{1F241}"=>"\u3014\u4E09\u3015".freeze, "\u{1F242}"=>"\u3014\u4E8C\u3015".freeze, "\u{1F243}"=>"\u3014\u5B89\u3015".freeze, "\u{1F244}"=>"\u3014\u70B9\u3015".freeze, "\u{1F245}"=>"\u3014\u6253\u3015".freeze,
- "\u{1F246}"=>"\u3014\u76D7\u3015".freeze, "\u{1F247}"=>"\u3014\u52DD\u3015".freeze, "\u{1F248}"=>"\u3014\u6557\u3015".freeze, "\u{1F250}"=>"\u5F97".freeze, "\u{1F251}"=>"\u53EF".freeze, "\u0385"=>" \u0308\u0301".freeze, "\u03D3"=>"\u03A5\u0301".freeze, "\u03D4"=>"\u03A5\u0308".freeze,
- "\u1E9B"=>"s\u0307".freeze, "\u1FC1"=>" \u0308\u0342".freeze, "\u1FCD"=>" \u0313\u0300".freeze, "\u1FCE"=>" \u0313\u0301".freeze, "\u1FCF"=>" \u0313\u0342".freeze, "\u1FDD"=>" \u0314\u0300".freeze, "\u1FDE"=>" \u0314\u0301".freeze, "\u1FDF"=>" \u0314\u0342".freeze,
- "\u1FED"=>" \u0308\u0300".freeze, "\u1FEE"=>" \u0308\u0301".freeze, "\u1FFD"=>" \u0301".freeze, "\u2000"=>" ".freeze, "\u2001"=>" ".freeze,
- }.freeze
-
- COMPOSITION_TABLE = {
- "A\u0300"=>"\u00C0".freeze, "A\u0301"=>"\u00C1".freeze, "A\u0302"=>"\u00C2".freeze, "A\u0303"=>"\u00C3".freeze, "A\u0308"=>"\u00C4".freeze, "A\u030A"=>"\u00C5".freeze, "C\u0327"=>"\u00C7".freeze, "E\u0300"=>"\u00C8".freeze,
- "E\u0301"=>"\u00C9".freeze, "E\u0302"=>"\u00CA".freeze, "E\u0308"=>"\u00CB".freeze, "I\u0300"=>"\u00CC".freeze, "I\u0301"=>"\u00CD".freeze, "I\u0302"=>"\u00CE".freeze, "I\u0308"=>"\u00CF".freeze, "N\u0303"=>"\u00D1".freeze,
- "O\u0300"=>"\u00D2".freeze, "O\u0301"=>"\u00D3".freeze, "O\u0302"=>"\u00D4".freeze, "O\u0303"=>"\u00D5".freeze, "O\u0308"=>"\u00D6".freeze, "U\u0300"=>"\u00D9".freeze, "U\u0301"=>"\u00DA".freeze, "U\u0302"=>"\u00DB".freeze,
- "U\u0308"=>"\u00DC".freeze, "Y\u0301"=>"\u00DD".freeze, "a\u0300"=>"\u00E0".freeze, "a\u0301"=>"\u00E1".freeze, "a\u0302"=>"\u00E2".freeze, "a\u0303"=>"\u00E3".freeze, "a\u0308"=>"\u00E4".freeze, "a\u030A"=>"\u00E5".freeze,
- "c\u0327"=>"\u00E7".freeze, "e\u0300"=>"\u00E8".freeze, "e\u0301"=>"\u00E9".freeze, "e\u0302"=>"\u00EA".freeze, "e\u0308"=>"\u00EB".freeze, "i\u0300"=>"\u00EC".freeze, "i\u0301"=>"\u00ED".freeze, "i\u0302"=>"\u00EE".freeze,
- "i\u0308"=>"\u00EF".freeze, "n\u0303"=>"\u00F1".freeze, "o\u0300"=>"\u00F2".freeze, "o\u0301"=>"\u00F3".freeze, "o\u0302"=>"\u00F4".freeze, "o\u0303"=>"\u00F5".freeze, "o\u0308"=>"\u00F6".freeze, "u\u0300"=>"\u00F9".freeze,
- "u\u0301"=>"\u00FA".freeze, "u\u0302"=>"\u00FB".freeze, "u\u0308"=>"\u00FC".freeze, "y\u0301"=>"\u00FD".freeze, "y\u0308"=>"\u00FF".freeze, "A\u0304"=>"\u0100".freeze, "a\u0304"=>"\u0101".freeze, "A\u0306"=>"\u0102".freeze,
- "a\u0306"=>"\u0103".freeze, "A\u0328"=>"\u0104".freeze, "a\u0328"=>"\u0105".freeze, "C\u0301"=>"\u0106".freeze, "c\u0301"=>"\u0107".freeze, "C\u0302"=>"\u0108".freeze, "c\u0302"=>"\u0109".freeze, "C\u0307"=>"\u010A".freeze,
- "c\u0307"=>"\u010B".freeze, "C\u030C"=>"\u010C".freeze, "c\u030C"=>"\u010D".freeze, "D\u030C"=>"\u010E".freeze, "d\u030C"=>"\u010F".freeze, "E\u0304"=>"\u0112".freeze, "e\u0304"=>"\u0113".freeze, "E\u0306"=>"\u0114".freeze,
- "e\u0306"=>"\u0115".freeze, "E\u0307"=>"\u0116".freeze, "e\u0307"=>"\u0117".freeze, "E\u0328"=>"\u0118".freeze, "e\u0328"=>"\u0119".freeze, "E\u030C"=>"\u011A".freeze, "e\u030C"=>"\u011B".freeze, "G\u0302"=>"\u011C".freeze,
- "g\u0302"=>"\u011D".freeze, "G\u0306"=>"\u011E".freeze, "g\u0306"=>"\u011F".freeze, "G\u0307"=>"\u0120".freeze, "g\u0307"=>"\u0121".freeze, "G\u0327"=>"\u0122".freeze, "g\u0327"=>"\u0123".freeze, "H\u0302"=>"\u0124".freeze,
- "h\u0302"=>"\u0125".freeze, "I\u0303"=>"\u0128".freeze, "i\u0303"=>"\u0129".freeze, "I\u0304"=>"\u012A".freeze, "i\u0304"=>"\u012B".freeze, "I\u0306"=>"\u012C".freeze, "i\u0306"=>"\u012D".freeze, "I\u0328"=>"\u012E".freeze,
- "i\u0328"=>"\u012F".freeze, "I\u0307"=>"\u0130".freeze, "J\u0302"=>"\u0134".freeze, "j\u0302"=>"\u0135".freeze, "K\u0327"=>"\u0136".freeze, "k\u0327"=>"\u0137".freeze, "L\u0301"=>"\u0139".freeze, "l\u0301"=>"\u013A".freeze,
- "L\u0327"=>"\u013B".freeze, "l\u0327"=>"\u013C".freeze, "L\u030C"=>"\u013D".freeze, "l\u030C"=>"\u013E".freeze, "N\u0301"=>"\u0143".freeze, "n\u0301"=>"\u0144".freeze, "N\u0327"=>"\u0145".freeze, "n\u0327"=>"\u0146".freeze,
- "N\u030C"=>"\u0147".freeze, "n\u030C"=>"\u0148".freeze, "O\u0304"=>"\u014C".freeze, "o\u0304"=>"\u014D".freeze, "O\u0306"=>"\u014E".freeze, "o\u0306"=>"\u014F".freeze, "O\u030B"=>"\u0150".freeze, "o\u030B"=>"\u0151".freeze,
- "R\u0301"=>"\u0154".freeze, "r\u0301"=>"\u0155".freeze, "R\u0327"=>"\u0156".freeze, "r\u0327"=>"\u0157".freeze, "R\u030C"=>"\u0158".freeze, "r\u030C"=>"\u0159".freeze, "S\u0301"=>"\u015A".freeze, "s\u0301"=>"\u015B".freeze,
- "S\u0302"=>"\u015C".freeze, "s\u0302"=>"\u015D".freeze, "S\u0327"=>"\u015E".freeze, "s\u0327"=>"\u015F".freeze, "S\u030C"=>"\u0160".freeze, "s\u030C"=>"\u0161".freeze, "T\u0327"=>"\u0162".freeze, "t\u0327"=>"\u0163".freeze,
- "T\u030C"=>"\u0164".freeze, "t\u030C"=>"\u0165".freeze, "U\u0303"=>"\u0168".freeze, "u\u0303"=>"\u0169".freeze, "U\u0304"=>"\u016A".freeze, "u\u0304"=>"\u016B".freeze, "U\u0306"=>"\u016C".freeze, "u\u0306"=>"\u016D".freeze,
- "U\u030A"=>"\u016E".freeze, "u\u030A"=>"\u016F".freeze, "U\u030B"=>"\u0170".freeze, "u\u030B"=>"\u0171".freeze, "U\u0328"=>"\u0172".freeze, "u\u0328"=>"\u0173".freeze, "W\u0302"=>"\u0174".freeze, "w\u0302"=>"\u0175".freeze,
- "Y\u0302"=>"\u0176".freeze, "y\u0302"=>"\u0177".freeze, "Y\u0308"=>"\u0178".freeze, "Z\u0301"=>"\u0179".freeze, "z\u0301"=>"\u017A".freeze, "Z\u0307"=>"\u017B".freeze, "z\u0307"=>"\u017C".freeze, "Z\u030C"=>"\u017D".freeze,
- "z\u030C"=>"\u017E".freeze, "O\u031B"=>"\u01A0".freeze, "o\u031B"=>"\u01A1".freeze, "U\u031B"=>"\u01AF".freeze, "u\u031B"=>"\u01B0".freeze, "A\u030C"=>"\u01CD".freeze, "a\u030C"=>"\u01CE".freeze, "I\u030C"=>"\u01CF".freeze,
- "i\u030C"=>"\u01D0".freeze, "O\u030C"=>"\u01D1".freeze, "o\u030C"=>"\u01D2".freeze, "U\u030C"=>"\u01D3".freeze, "u\u030C"=>"\u01D4".freeze, "\u00DC\u0304"=>"\u01D5".freeze, "\u00FC\u0304"=>"\u01D6".freeze, "\u00DC\u0301"=>"\u01D7".freeze,
- "\u00FC\u0301"=>"\u01D8".freeze, "\u00DC\u030C"=>"\u01D9".freeze, "\u00FC\u030C"=>"\u01DA".freeze, "\u00DC\u0300"=>"\u01DB".freeze, "\u00FC\u0300"=>"\u01DC".freeze, "\u00C4\u0304"=>"\u01DE".freeze, "\u00E4\u0304"=>"\u01DF".freeze, "\u0226\u0304"=>"\u01E0".freeze,
- "\u0227\u0304"=>"\u01E1".freeze, "\u00C6\u0304"=>"\u01E2".freeze, "\u00E6\u0304"=>"\u01E3".freeze, "G\u030C"=>"\u01E6".freeze, "g\u030C"=>"\u01E7".freeze, "K\u030C"=>"\u01E8".freeze, "k\u030C"=>"\u01E9".freeze, "O\u0328"=>"\u01EA".freeze,
- "o\u0328"=>"\u01EB".freeze, "\u01EA\u0304"=>"\u01EC".freeze, "\u01EB\u0304"=>"\u01ED".freeze, "\u01B7\u030C"=>"\u01EE".freeze, "\u0292\u030C"=>"\u01EF".freeze, "j\u030C"=>"\u01F0".freeze, "G\u0301"=>"\u01F4".freeze, "g\u0301"=>"\u01F5".freeze,
- "N\u0300"=>"\u01F8".freeze, "n\u0300"=>"\u01F9".freeze, "\u00C5\u0301"=>"\u01FA".freeze, "\u00E5\u0301"=>"\u01FB".freeze, "\u00C6\u0301"=>"\u01FC".freeze, "\u00E6\u0301"=>"\u01FD".freeze, "\u00D8\u0301"=>"\u01FE".freeze, "\u00F8\u0301"=>"\u01FF".freeze,
- "A\u030F"=>"\u0200".freeze, "a\u030F"=>"\u0201".freeze, "A\u0311"=>"\u0202".freeze, "a\u0311"=>"\u0203".freeze, "E\u030F"=>"\u0204".freeze, "e\u030F"=>"\u0205".freeze, "E\u0311"=>"\u0206".freeze, "e\u0311"=>"\u0207".freeze,
- "I\u030F"=>"\u0208".freeze, "i\u030F"=>"\u0209".freeze, "I\u0311"=>"\u020A".freeze, "i\u0311"=>"\u020B".freeze, "O\u030F"=>"\u020C".freeze, "o\u030F"=>"\u020D".freeze, "O\u0311"=>"\u020E".freeze, "o\u0311"=>"\u020F".freeze,
- "R\u030F"=>"\u0210".freeze, "r\u030F"=>"\u0211".freeze, "R\u0311"=>"\u0212".freeze, "r\u0311"=>"\u0213".freeze, "U\u030F"=>"\u0214".freeze, "u\u030F"=>"\u0215".freeze, "U\u0311"=>"\u0216".freeze, "u\u0311"=>"\u0217".freeze,
- "S\u0326"=>"\u0218".freeze, "s\u0326"=>"\u0219".freeze, "T\u0326"=>"\u021A".freeze, "t\u0326"=>"\u021B".freeze, "H\u030C"=>"\u021E".freeze, "h\u030C"=>"\u021F".freeze, "A\u0307"=>"\u0226".freeze, "a\u0307"=>"\u0227".freeze,
- "E\u0327"=>"\u0228".freeze, "e\u0327"=>"\u0229".freeze, "\u00D6\u0304"=>"\u022A".freeze, "\u00F6\u0304"=>"\u022B".freeze, "\u00D5\u0304"=>"\u022C".freeze, "\u00F5\u0304"=>"\u022D".freeze, "O\u0307"=>"\u022E".freeze, "o\u0307"=>"\u022F".freeze,
- "\u022E\u0304"=>"\u0230".freeze, "\u022F\u0304"=>"\u0231".freeze, "Y\u0304"=>"\u0232".freeze, "y\u0304"=>"\u0233".freeze, "\u00A8\u0301"=>"\u0385".freeze, "\u0391\u0301"=>"\u0386".freeze, "\u0395\u0301"=>"\u0388".freeze, "\u0397\u0301"=>"\u0389".freeze,
- "\u0399\u0301"=>"\u038A".freeze, "\u039F\u0301"=>"\u038C".freeze, "\u03A5\u0301"=>"\u038E".freeze, "\u03A9\u0301"=>"\u038F".freeze, "\u03CA\u0301"=>"\u0390".freeze, "\u0399\u0308"=>"\u03AA".freeze, "\u03A5\u0308"=>"\u03AB".freeze, "\u03B1\u0301"=>"\u03AC".freeze,
- "\u03B5\u0301"=>"\u03AD".freeze, "\u03B7\u0301"=>"\u03AE".freeze, "\u03B9\u0301"=>"\u03AF".freeze, "\u03CB\u0301"=>"\u03B0".freeze, "\u03B9\u0308"=>"\u03CA".freeze, "\u03C5\u0308"=>"\u03CB".freeze, "\u03BF\u0301"=>"\u03CC".freeze, "\u03C5\u0301"=>"\u03CD".freeze,
- "\u03C9\u0301"=>"\u03CE".freeze, "\u03D2\u0301"=>"\u03D3".freeze, "\u03D2\u0308"=>"\u03D4".freeze, "\u0415\u0300"=>"\u0400".freeze, "\u0415\u0308"=>"\u0401".freeze, "\u0413\u0301"=>"\u0403".freeze, "\u0406\u0308"=>"\u0407".freeze, "\u041A\u0301"=>"\u040C".freeze,
- "\u0418\u0300"=>"\u040D".freeze, "\u0423\u0306"=>"\u040E".freeze, "\u0418\u0306"=>"\u0419".freeze, "\u0438\u0306"=>"\u0439".freeze, "\u0435\u0300"=>"\u0450".freeze, "\u0435\u0308"=>"\u0451".freeze, "\u0433\u0301"=>"\u0453".freeze, "\u0456\u0308"=>"\u0457".freeze,
- "\u043A\u0301"=>"\u045C".freeze, "\u0438\u0300"=>"\u045D".freeze, "\u0443\u0306"=>"\u045E".freeze, "\u0474\u030F"=>"\u0476".freeze, "\u0475\u030F"=>"\u0477".freeze, "\u0416\u0306"=>"\u04C1".freeze, "\u0436\u0306"=>"\u04C2".freeze, "\u0410\u0306"=>"\u04D0".freeze,
- "\u0430\u0306"=>"\u04D1".freeze, "\u0410\u0308"=>"\u04D2".freeze, "\u0430\u0308"=>"\u04D3".freeze, "\u0415\u0306"=>"\u04D6".freeze, "\u0435\u0306"=>"\u04D7".freeze, "\u04D8\u0308"=>"\u04DA".freeze, "\u04D9\u0308"=>"\u04DB".freeze, "\u0416\u0308"=>"\u04DC".freeze,
- "\u0436\u0308"=>"\u04DD".freeze, "\u0417\u0308"=>"\u04DE".freeze, "\u0437\u0308"=>"\u04DF".freeze, "\u0418\u0304"=>"\u04E2".freeze, "\u0438\u0304"=>"\u04E3".freeze, "\u0418\u0308"=>"\u04E4".freeze, "\u0438\u0308"=>"\u04E5".freeze, "\u041E\u0308"=>"\u04E6".freeze,
- "\u043E\u0308"=>"\u04E7".freeze, "\u04E8\u0308"=>"\u04EA".freeze, "\u04E9\u0308"=>"\u04EB".freeze, "\u042D\u0308"=>"\u04EC".freeze, "\u044D\u0308"=>"\u04ED".freeze, "\u0423\u0304"=>"\u04EE".freeze, "\u0443\u0304"=>"\u04EF".freeze, "\u0423\u0308"=>"\u04F0".freeze,
- "\u0443\u0308"=>"\u04F1".freeze, "\u0423\u030B"=>"\u04F2".freeze, "\u0443\u030B"=>"\u04F3".freeze, "\u0427\u0308"=>"\u04F4".freeze, "\u0447\u0308"=>"\u04F5".freeze, "\u042B\u0308"=>"\u04F8".freeze, "\u044B\u0308"=>"\u04F9".freeze, "\u0627\u0653"=>"\u0622".freeze,
- "\u0627\u0654"=>"\u0623".freeze, "\u0648\u0654"=>"\u0624".freeze, "\u0627\u0655"=>"\u0625".freeze, "\u064A\u0654"=>"\u0626".freeze, "\u06D5\u0654"=>"\u06C0".freeze, "\u06C1\u0654"=>"\u06C2".freeze, "\u06D2\u0654"=>"\u06D3".freeze, "\u0928\u093C"=>"\u0929".freeze,
- "\u0930\u093C"=>"\u0931".freeze, "\u0933\u093C"=>"\u0934".freeze, "\u09C7\u09BE"=>"\u09CB".freeze, "\u09C7\u09D7"=>"\u09CC".freeze, "\u0B47\u0B56"=>"\u0B48".freeze, "\u0B47\u0B3E"=>"\u0B4B".freeze, "\u0B47\u0B57"=>"\u0B4C".freeze, "\u0B92\u0BD7"=>"\u0B94".freeze,
- "\u0BC6\u0BBE"=>"\u0BCA".freeze, "\u0BC7\u0BBE"=>"\u0BCB".freeze, "\u0BC6\u0BD7"=>"\u0BCC".freeze, "\u0C46\u0C56"=>"\u0C48".freeze, "\u0CBF\u0CD5"=>"\u0CC0".freeze, "\u0CC6\u0CD5"=>"\u0CC7".freeze, "\u0CC6\u0CD6"=>"\u0CC8".freeze, "\u0CC6\u0CC2"=>"\u0CCA".freeze,
- "\u0CCA\u0CD5"=>"\u0CCB".freeze, "\u0D46\u0D3E"=>"\u0D4A".freeze, "\u0D47\u0D3E"=>"\u0D4B".freeze, "\u0D46\u0D57"=>"\u0D4C".freeze, "\u0DD9\u0DCA"=>"\u0DDA".freeze, "\u0DD9\u0DCF"=>"\u0DDC".freeze, "\u0DDC\u0DCA"=>"\u0DDD".freeze, "\u0DD9\u0DDF"=>"\u0DDE".freeze,
- "\u1025\u102E"=>"\u1026".freeze, "\u1B05\u1B35"=>"\u1B06".freeze, "\u1B07\u1B35"=>"\u1B08".freeze, "\u1B09\u1B35"=>"\u1B0A".freeze, "\u1B0B\u1B35"=>"\u1B0C".freeze, "\u1B0D\u1B35"=>"\u1B0E".freeze, "\u1B11\u1B35"=>"\u1B12".freeze, "\u1B3A\u1B35"=>"\u1B3B".freeze,
- "\u1B3C\u1B35"=>"\u1B3D".freeze, "\u1B3E\u1B35"=>"\u1B40".freeze, "\u1B3F\u1B35"=>"\u1B41".freeze, "\u1B42\u1B35"=>"\u1B43".freeze, "A\u0325"=>"\u1E00".freeze, "a\u0325"=>"\u1E01".freeze, "B\u0307"=>"\u1E02".freeze, "b\u0307"=>"\u1E03".freeze,
- "B\u0323"=>"\u1E04".freeze, "b\u0323"=>"\u1E05".freeze, "B\u0331"=>"\u1E06".freeze, "b\u0331"=>"\u1E07".freeze, "\u00C7\u0301"=>"\u1E08".freeze, "\u00E7\u0301"=>"\u1E09".freeze, "D\u0307"=>"\u1E0A".freeze, "d\u0307"=>"\u1E0B".freeze,
- "D\u0323"=>"\u1E0C".freeze, "d\u0323"=>"\u1E0D".freeze, "D\u0331"=>"\u1E0E".freeze, "d\u0331"=>"\u1E0F".freeze, "D\u0327"=>"\u1E10".freeze, "d\u0327"=>"\u1E11".freeze, "D\u032D"=>"\u1E12".freeze, "d\u032D"=>"\u1E13".freeze,
- "\u0112\u0300"=>"\u1E14".freeze, "\u0113\u0300"=>"\u1E15".freeze, "\u0112\u0301"=>"\u1E16".freeze, "\u0113\u0301"=>"\u1E17".freeze, "E\u032D"=>"\u1E18".freeze, "e\u032D"=>"\u1E19".freeze, "E\u0330"=>"\u1E1A".freeze, "e\u0330"=>"\u1E1B".freeze,
- "\u0228\u0306"=>"\u1E1C".freeze, "\u0229\u0306"=>"\u1E1D".freeze, "F\u0307"=>"\u1E1E".freeze, "f\u0307"=>"\u1E1F".freeze, "G\u0304"=>"\u1E20".freeze, "g\u0304"=>"\u1E21".freeze, "H\u0307"=>"\u1E22".freeze, "h\u0307"=>"\u1E23".freeze,
- "H\u0323"=>"\u1E24".freeze, "h\u0323"=>"\u1E25".freeze, "H\u0308"=>"\u1E26".freeze, "h\u0308"=>"\u1E27".freeze, "H\u0327"=>"\u1E28".freeze, "h\u0327"=>"\u1E29".freeze, "H\u032E"=>"\u1E2A".freeze, "h\u032E"=>"\u1E2B".freeze,
- "I\u0330"=>"\u1E2C".freeze, "i\u0330"=>"\u1E2D".freeze, "\u00CF\u0301"=>"\u1E2E".freeze, "\u00EF\u0301"=>"\u1E2F".freeze, "K\u0301"=>"\u1E30".freeze, "k\u0301"=>"\u1E31".freeze, "K\u0323"=>"\u1E32".freeze, "k\u0323"=>"\u1E33".freeze,
- "K\u0331"=>"\u1E34".freeze, "k\u0331"=>"\u1E35".freeze, "L\u0323"=>"\u1E36".freeze, "l\u0323"=>"\u1E37".freeze, "\u1E36\u0304"=>"\u1E38".freeze, "\u1E37\u0304"=>"\u1E39".freeze, "L\u0331"=>"\u1E3A".freeze, "l\u0331"=>"\u1E3B".freeze,
- "L\u032D"=>"\u1E3C".freeze, "l\u032D"=>"\u1E3D".freeze, "M\u0301"=>"\u1E3E".freeze, "m\u0301"=>"\u1E3F".freeze, "M\u0307"=>"\u1E40".freeze, "m\u0307"=>"\u1E41".freeze, "M\u0323"=>"\u1E42".freeze, "m\u0323"=>"\u1E43".freeze,
- "N\u0307"=>"\u1E44".freeze, "n\u0307"=>"\u1E45".freeze, "N\u0323"=>"\u1E46".freeze, "n\u0323"=>"\u1E47".freeze, "N\u0331"=>"\u1E48".freeze, "n\u0331"=>"\u1E49".freeze, "N\u032D"=>"\u1E4A".freeze, "n\u032D"=>"\u1E4B".freeze,
- "\u00D5\u0301"=>"\u1E4C".freeze, "\u00F5\u0301"=>"\u1E4D".freeze, "\u00D5\u0308"=>"\u1E4E".freeze, "\u00F5\u0308"=>"\u1E4F".freeze, "\u014C\u0300"=>"\u1E50".freeze, "\u014D\u0300"=>"\u1E51".freeze, "\u014C\u0301"=>"\u1E52".freeze, "\u014D\u0301"=>"\u1E53".freeze,
- "P\u0301"=>"\u1E54".freeze, "p\u0301"=>"\u1E55".freeze, "P\u0307"=>"\u1E56".freeze, "p\u0307"=>"\u1E57".freeze, "R\u0307"=>"\u1E58".freeze, "r\u0307"=>"\u1E59".freeze, "R\u0323"=>"\u1E5A".freeze, "r\u0323"=>"\u1E5B".freeze,
- "\u1E5A\u0304"=>"\u1E5C".freeze, "\u1E5B\u0304"=>"\u1E5D".freeze, "R\u0331"=>"\u1E5E".freeze, "r\u0331"=>"\u1E5F".freeze, "S\u0307"=>"\u1E60".freeze, "s\u0307"=>"\u1E61".freeze, "S\u0323"=>"\u1E62".freeze, "s\u0323"=>"\u1E63".freeze,
- "\u015A\u0307"=>"\u1E64".freeze, "\u015B\u0307"=>"\u1E65".freeze, "\u0160\u0307"=>"\u1E66".freeze, "\u0161\u0307"=>"\u1E67".freeze, "\u1E62\u0307"=>"\u1E68".freeze, "\u1E63\u0307"=>"\u1E69".freeze, "T\u0307"=>"\u1E6A".freeze, "t\u0307"=>"\u1E6B".freeze,
- "T\u0323"=>"\u1E6C".freeze, "t\u0323"=>"\u1E6D".freeze, "T\u0331"=>"\u1E6E".freeze, "t\u0331"=>"\u1E6F".freeze, "T\u032D"=>"\u1E70".freeze, "t\u032D"=>"\u1E71".freeze, "U\u0324"=>"\u1E72".freeze, "u\u0324"=>"\u1E73".freeze,
- "U\u0330"=>"\u1E74".freeze, "u\u0330"=>"\u1E75".freeze, "U\u032D"=>"\u1E76".freeze, "u\u032D"=>"\u1E77".freeze, "\u0168\u0301"=>"\u1E78".freeze, "\u0169\u0301"=>"\u1E79".freeze, "\u016A\u0308"=>"\u1E7A".freeze, "\u016B\u0308"=>"\u1E7B".freeze,
- "V\u0303"=>"\u1E7C".freeze, "v\u0303"=>"\u1E7D".freeze, "V\u0323"=>"\u1E7E".freeze, "v\u0323"=>"\u1E7F".freeze, "W\u0300"=>"\u1E80".freeze, "w\u0300"=>"\u1E81".freeze, "W\u0301"=>"\u1E82".freeze, "w\u0301"=>"\u1E83".freeze,
- "W\u0308"=>"\u1E84".freeze, "w\u0308"=>"\u1E85".freeze, "W\u0307"=>"\u1E86".freeze, "w\u0307"=>"\u1E87".freeze, "W\u0323"=>"\u1E88".freeze, "w\u0323"=>"\u1E89".freeze, "X\u0307"=>"\u1E8A".freeze, "x\u0307"=>"\u1E8B".freeze,
- "X\u0308"=>"\u1E8C".freeze, "x\u0308"=>"\u1E8D".freeze, "Y\u0307"=>"\u1E8E".freeze, "y\u0307"=>"\u1E8F".freeze, "Z\u0302"=>"\u1E90".freeze, "z\u0302"=>"\u1E91".freeze, "Z\u0323"=>"\u1E92".freeze, "z\u0323"=>"\u1E93".freeze,
- "Z\u0331"=>"\u1E94".freeze, "z\u0331"=>"\u1E95".freeze, "h\u0331"=>"\u1E96".freeze, "t\u0308"=>"\u1E97".freeze, "w\u030A"=>"\u1E98".freeze, "y\u030A"=>"\u1E99".freeze, "\u017F\u0307"=>"\u1E9B".freeze, "A\u0323"=>"\u1EA0".freeze,
- "a\u0323"=>"\u1EA1".freeze, "A\u0309"=>"\u1EA2".freeze, "a\u0309"=>"\u1EA3".freeze, "\u00C2\u0301"=>"\u1EA4".freeze, "\u00E2\u0301"=>"\u1EA5".freeze, "\u00C2\u0300"=>"\u1EA6".freeze, "\u00E2\u0300"=>"\u1EA7".freeze, "\u00C2\u0309"=>"\u1EA8".freeze,
- "\u00E2\u0309"=>"\u1EA9".freeze, "\u00C2\u0303"=>"\u1EAA".freeze, "\u00E2\u0303"=>"\u1EAB".freeze, "\u1EA0\u0302"=>"\u1EAC".freeze, "\u1EA1\u0302"=>"\u1EAD".freeze, "\u0102\u0301"=>"\u1EAE".freeze, "\u0103\u0301"=>"\u1EAF".freeze, "\u0102\u0300"=>"\u1EB0".freeze,
- "\u0103\u0300"=>"\u1EB1".freeze, "\u0102\u0309"=>"\u1EB2".freeze, "\u0103\u0309"=>"\u1EB3".freeze, "\u0102\u0303"=>"\u1EB4".freeze, "\u0103\u0303"=>"\u1EB5".freeze, "\u1EA0\u0306"=>"\u1EB6".freeze, "\u1EA1\u0306"=>"\u1EB7".freeze, "E\u0323"=>"\u1EB8".freeze,
- "e\u0323"=>"\u1EB9".freeze, "E\u0309"=>"\u1EBA".freeze, "e\u0309"=>"\u1EBB".freeze, "E\u0303"=>"\u1EBC".freeze, "e\u0303"=>"\u1EBD".freeze, "\u00CA\u0301"=>"\u1EBE".freeze, "\u00EA\u0301"=>"\u1EBF".freeze, "\u00CA\u0300"=>"\u1EC0".freeze,
- "\u00EA\u0300"=>"\u1EC1".freeze, "\u00CA\u0309"=>"\u1EC2".freeze, "\u00EA\u0309"=>"\u1EC3".freeze, "\u00CA\u0303"=>"\u1EC4".freeze, "\u00EA\u0303"=>"\u1EC5".freeze, "\u1EB8\u0302"=>"\u1EC6".freeze, "\u1EB9\u0302"=>"\u1EC7".freeze, "I\u0309"=>"\u1EC8".freeze,
- "i\u0309"=>"\u1EC9".freeze, "I\u0323"=>"\u1ECA".freeze, "i\u0323"=>"\u1ECB".freeze, "O\u0323"=>"\u1ECC".freeze, "o\u0323"=>"\u1ECD".freeze, "O\u0309"=>"\u1ECE".freeze, "o\u0309"=>"\u1ECF".freeze, "\u00D4\u0301"=>"\u1ED0".freeze,
- "\u00F4\u0301"=>"\u1ED1".freeze, "\u00D4\u0300"=>"\u1ED2".freeze, "\u00F4\u0300"=>"\u1ED3".freeze, "\u00D4\u0309"=>"\u1ED4".freeze, "\u00F4\u0309"=>"\u1ED5".freeze, "\u00D4\u0303"=>"\u1ED6".freeze, "\u00F4\u0303"=>"\u1ED7".freeze, "\u1ECC\u0302"=>"\u1ED8".freeze,
- "\u1ECD\u0302"=>"\u1ED9".freeze, "\u01A0\u0301"=>"\u1EDA".freeze, "\u01A1\u0301"=>"\u1EDB".freeze, "\u01A0\u0300"=>"\u1EDC".freeze, "\u01A1\u0300"=>"\u1EDD".freeze, "\u01A0\u0309"=>"\u1EDE".freeze, "\u01A1\u0309"=>"\u1EDF".freeze, "\u01A0\u0303"=>"\u1EE0".freeze,
- "\u01A1\u0303"=>"\u1EE1".freeze, "\u01A0\u0323"=>"\u1EE2".freeze, "\u01A1\u0323"=>"\u1EE3".freeze, "U\u0323"=>"\u1EE4".freeze, "u\u0323"=>"\u1EE5".freeze, "U\u0309"=>"\u1EE6".freeze, "u\u0309"=>"\u1EE7".freeze, "\u01AF\u0301"=>"\u1EE8".freeze,
- "\u01B0\u0301"=>"\u1EE9".freeze, "\u01AF\u0300"=>"\u1EEA".freeze, "\u01B0\u0300"=>"\u1EEB".freeze, "\u01AF\u0309"=>"\u1EEC".freeze, "\u01B0\u0309"=>"\u1EED".freeze, "\u01AF\u0303"=>"\u1EEE".freeze, "\u01B0\u0303"=>"\u1EEF".freeze, "\u01AF\u0323"=>"\u1EF0".freeze,
- "\u01B0\u0323"=>"\u1EF1".freeze, "Y\u0300"=>"\u1EF2".freeze, "y\u0300"=>"\u1EF3".freeze, "Y\u0323"=>"\u1EF4".freeze, "y\u0323"=>"\u1EF5".freeze, "Y\u0309"=>"\u1EF6".freeze, "y\u0309"=>"\u1EF7".freeze, "Y\u0303"=>"\u1EF8".freeze,
- "y\u0303"=>"\u1EF9".freeze, "\u03B1\u0313"=>"\u1F00".freeze, "\u03B1\u0314"=>"\u1F01".freeze, "\u1F00\u0300"=>"\u1F02".freeze, "\u1F01\u0300"=>"\u1F03".freeze, "\u1F00\u0301"=>"\u1F04".freeze, "\u1F01\u0301"=>"\u1F05".freeze, "\u1F00\u0342"=>"\u1F06".freeze,
- "\u1F01\u0342"=>"\u1F07".freeze, "\u0391\u0313"=>"\u1F08".freeze, "\u0391\u0314"=>"\u1F09".freeze, "\u1F08\u0300"=>"\u1F0A".freeze, "\u1F09\u0300"=>"\u1F0B".freeze, "\u1F08\u0301"=>"\u1F0C".freeze, "\u1F09\u0301"=>"\u1F0D".freeze, "\u1F08\u0342"=>"\u1F0E".freeze,
- "\u1F09\u0342"=>"\u1F0F".freeze, "\u03B5\u0313"=>"\u1F10".freeze, "\u03B5\u0314"=>"\u1F11".freeze, "\u1F10\u0300"=>"\u1F12".freeze, "\u1F11\u0300"=>"\u1F13".freeze, "\u1F10\u0301"=>"\u1F14".freeze, "\u1F11\u0301"=>"\u1F15".freeze, "\u0395\u0313"=>"\u1F18".freeze,
- "\u0395\u0314"=>"\u1F19".freeze, "\u1F18\u0300"=>"\u1F1A".freeze, "\u1F19\u0300"=>"\u1F1B".freeze, "\u1F18\u0301"=>"\u1F1C".freeze, "\u1F19\u0301"=>"\u1F1D".freeze, "\u03B7\u0313"=>"\u1F20".freeze, "\u03B7\u0314"=>"\u1F21".freeze, "\u1F20\u0300"=>"\u1F22".freeze,
- "\u1F21\u0300"=>"\u1F23".freeze, "\u1F20\u0301"=>"\u1F24".freeze, "\u1F21\u0301"=>"\u1F25".freeze, "\u1F20\u0342"=>"\u1F26".freeze, "\u1F21\u0342"=>"\u1F27".freeze, "\u0397\u0313"=>"\u1F28".freeze, "\u0397\u0314"=>"\u1F29".freeze, "\u1F28\u0300"=>"\u1F2A".freeze,
- "\u1F29\u0300"=>"\u1F2B".freeze, "\u1F28\u0301"=>"\u1F2C".freeze, "\u1F29\u0301"=>"\u1F2D".freeze, "\u1F28\u0342"=>"\u1F2E".freeze, "\u1F29\u0342"=>"\u1F2F".freeze, "\u03B9\u0313"=>"\u1F30".freeze, "\u03B9\u0314"=>"\u1F31".freeze, "\u1F30\u0300"=>"\u1F32".freeze,
- "\u1F31\u0300"=>"\u1F33".freeze, "\u1F30\u0301"=>"\u1F34".freeze, "\u1F31\u0301"=>"\u1F35".freeze, "\u1F30\u0342"=>"\u1F36".freeze, "\u1F31\u0342"=>"\u1F37".freeze, "\u0399\u0313"=>"\u1F38".freeze, "\u0399\u0314"=>"\u1F39".freeze, "\u1F38\u0300"=>"\u1F3A".freeze,
- "\u1F39\u0300"=>"\u1F3B".freeze, "\u1F38\u0301"=>"\u1F3C".freeze, "\u1F39\u0301"=>"\u1F3D".freeze, "\u1F38\u0342"=>"\u1F3E".freeze, "\u1F39\u0342"=>"\u1F3F".freeze, "\u03BF\u0313"=>"\u1F40".freeze, "\u03BF\u0314"=>"\u1F41".freeze, "\u1F40\u0300"=>"\u1F42".freeze,
- "\u1F41\u0300"=>"\u1F43".freeze, "\u1F40\u0301"=>"\u1F44".freeze, "\u1F41\u0301"=>"\u1F45".freeze, "\u039F\u0313"=>"\u1F48".freeze, "\u039F\u0314"=>"\u1F49".freeze, "\u1F48\u0300"=>"\u1F4A".freeze, "\u1F49\u0300"=>"\u1F4B".freeze, "\u1F48\u0301"=>"\u1F4C".freeze,
- "\u1F49\u0301"=>"\u1F4D".freeze, "\u03C5\u0313"=>"\u1F50".freeze, "\u03C5\u0314"=>"\u1F51".freeze, "\u1F50\u0300"=>"\u1F52".freeze, "\u1F51\u0300"=>"\u1F53".freeze, "\u1F50\u0301"=>"\u1F54".freeze, "\u1F51\u0301"=>"\u1F55".freeze, "\u1F50\u0342"=>"\u1F56".freeze,
- "\u1F51\u0342"=>"\u1F57".freeze, "\u03A5\u0314"=>"\u1F59".freeze, "\u1F59\u0300"=>"\u1F5B".freeze, "\u1F59\u0301"=>"\u1F5D".freeze, "\u1F59\u0342"=>"\u1F5F".freeze, "\u03C9\u0313"=>"\u1F60".freeze, "\u03C9\u0314"=>"\u1F61".freeze, "\u1F60\u0300"=>"\u1F62".freeze,
- "\u1F61\u0300"=>"\u1F63".freeze, "\u1F60\u0301"=>"\u1F64".freeze, "\u1F61\u0301"=>"\u1F65".freeze, "\u1F60\u0342"=>"\u1F66".freeze, "\u1F61\u0342"=>"\u1F67".freeze, "\u03A9\u0313"=>"\u1F68".freeze, "\u03A9\u0314"=>"\u1F69".freeze, "\u1F68\u0300"=>"\u1F6A".freeze,
- "\u1F69\u0300"=>"\u1F6B".freeze, "\u1F68\u0301"=>"\u1F6C".freeze, "\u1F69\u0301"=>"\u1F6D".freeze, "\u1F68\u0342"=>"\u1F6E".freeze, "\u1F69\u0342"=>"\u1F6F".freeze, "\u03B1\u0300"=>"\u1F70".freeze, "\u03B5\u0300"=>"\u1F72".freeze, "\u03B7\u0300"=>"\u1F74".freeze,
- "\u03B9\u0300"=>"\u1F76".freeze, "\u03BF\u0300"=>"\u1F78".freeze, "\u03C5\u0300"=>"\u1F7A".freeze, "\u03C9\u0300"=>"\u1F7C".freeze, "\u1F00\u0345"=>"\u1F80".freeze, "\u1F01\u0345"=>"\u1F81".freeze, "\u1F02\u0345"=>"\u1F82".freeze, "\u1F03\u0345"=>"\u1F83".freeze,
- "\u1F04\u0345"=>"\u1F84".freeze, "\u1F05\u0345"=>"\u1F85".freeze, "\u1F06\u0345"=>"\u1F86".freeze, "\u1F07\u0345"=>"\u1F87".freeze, "\u1F08\u0345"=>"\u1F88".freeze, "\u1F09\u0345"=>"\u1F89".freeze, "\u1F0A\u0345"=>"\u1F8A".freeze, "\u1F0B\u0345"=>"\u1F8B".freeze,
- "\u1F0C\u0345"=>"\u1F8C".freeze, "\u1F0D\u0345"=>"\u1F8D".freeze, "\u1F0E\u0345"=>"\u1F8E".freeze, "\u1F0F\u0345"=>"\u1F8F".freeze, "\u1F20\u0345"=>"\u1F90".freeze, "\u1F21\u0345"=>"\u1F91".freeze, "\u1F22\u0345"=>"\u1F92".freeze, "\u1F23\u0345"=>"\u1F93".freeze,
- "\u1F24\u0345"=>"\u1F94".freeze, "\u1F25\u0345"=>"\u1F95".freeze, "\u1F26\u0345"=>"\u1F96".freeze, "\u1F27\u0345"=>"\u1F97".freeze, "\u1F28\u0345"=>"\u1F98".freeze, "\u1F29\u0345"=>"\u1F99".freeze, "\u1F2A\u0345"=>"\u1F9A".freeze, "\u1F2B\u0345"=>"\u1F9B".freeze,
- "\u1F2C\u0345"=>"\u1F9C".freeze, "\u1F2D\u0345"=>"\u1F9D".freeze, "\u1F2E\u0345"=>"\u1F9E".freeze, "\u1F2F\u0345"=>"\u1F9F".freeze, "\u1F60\u0345"=>"\u1FA0".freeze, "\u1F61\u0345"=>"\u1FA1".freeze, "\u1F62\u0345"=>"\u1FA2".freeze, "\u1F63\u0345"=>"\u1FA3".freeze,
- "\u1F64\u0345"=>"\u1FA4".freeze, "\u1F65\u0345"=>"\u1FA5".freeze, "\u1F66\u0345"=>"\u1FA6".freeze, "\u1F67\u0345"=>"\u1FA7".freeze, "\u1F68\u0345"=>"\u1FA8".freeze, "\u1F69\u0345"=>"\u1FA9".freeze, "\u1F6A\u0345"=>"\u1FAA".freeze, "\u1F6B\u0345"=>"\u1FAB".freeze,
- "\u1F6C\u0345"=>"\u1FAC".freeze, "\u1F6D\u0345"=>"\u1FAD".freeze, "\u1F6E\u0345"=>"\u1FAE".freeze, "\u1F6F\u0345"=>"\u1FAF".freeze, "\u03B1\u0306"=>"\u1FB0".freeze, "\u03B1\u0304"=>"\u1FB1".freeze, "\u1F70\u0345"=>"\u1FB2".freeze, "\u03B1\u0345"=>"\u1FB3".freeze,
- "\u03AC\u0345"=>"\u1FB4".freeze, "\u03B1\u0342"=>"\u1FB6".freeze, "\u1FB6\u0345"=>"\u1FB7".freeze, "\u0391\u0306"=>"\u1FB8".freeze, "\u0391\u0304"=>"\u1FB9".freeze, "\u0391\u0300"=>"\u1FBA".freeze, "\u0391\u0345"=>"\u1FBC".freeze, "\u00A8\u0342"=>"\u1FC1".freeze,
- "\u1F74\u0345"=>"\u1FC2".freeze, "\u03B7\u0345"=>"\u1FC3".freeze, "\u03AE\u0345"=>"\u1FC4".freeze, "\u03B7\u0342"=>"\u1FC6".freeze, "\u1FC6\u0345"=>"\u1FC7".freeze, "\u0395\u0300"=>"\u1FC8".freeze, "\u0397\u0300"=>"\u1FCA".freeze, "\u0397\u0345"=>"\u1FCC".freeze,
- "\u1FBF\u0300"=>"\u1FCD".freeze, "\u1FBF\u0301"=>"\u1FCE".freeze, "\u1FBF\u0342"=>"\u1FCF".freeze, "\u03B9\u0306"=>"\u1FD0".freeze, "\u03B9\u0304"=>"\u1FD1".freeze, "\u03CA\u0300"=>"\u1FD2".freeze, "\u03B9\u0342"=>"\u1FD6".freeze, "\u03CA\u0342"=>"\u1FD7".freeze,
- "\u0399\u0306"=>"\u1FD8".freeze, "\u0399\u0304"=>"\u1FD9".freeze, "\u0399\u0300"=>"\u1FDA".freeze, "\u1FFE\u0300"=>"\u1FDD".freeze, "\u1FFE\u0301"=>"\u1FDE".freeze, "\u1FFE\u0342"=>"\u1FDF".freeze, "\u03C5\u0306"=>"\u1FE0".freeze, "\u03C5\u0304"=>"\u1FE1".freeze,
- "\u03CB\u0300"=>"\u1FE2".freeze, "\u03C1\u0313"=>"\u1FE4".freeze, "\u03C1\u0314"=>"\u1FE5".freeze, "\u03C5\u0342"=>"\u1FE6".freeze, "\u03CB\u0342"=>"\u1FE7".freeze, "\u03A5\u0306"=>"\u1FE8".freeze, "\u03A5\u0304"=>"\u1FE9".freeze, "\u03A5\u0300"=>"\u1FEA".freeze,
- "\u03A1\u0314"=>"\u1FEC".freeze, "\u00A8\u0300"=>"\u1FED".freeze, "\u1F7C\u0345"=>"\u1FF2".freeze, "\u03C9\u0345"=>"\u1FF3".freeze, "\u03CE\u0345"=>"\u1FF4".freeze, "\u03C9\u0342"=>"\u1FF6".freeze, "\u1FF6\u0345"=>"\u1FF7".freeze, "\u039F\u0300"=>"\u1FF8".freeze,
- "\u03A9\u0300"=>"\u1FFA".freeze, "\u03A9\u0345"=>"\u1FFC".freeze, "\u2190\u0338"=>"\u219A".freeze, "\u2192\u0338"=>"\u219B".freeze, "\u2194\u0338"=>"\u21AE".freeze, "\u21D0\u0338"=>"\u21CD".freeze, "\u21D4\u0338"=>"\u21CE".freeze, "\u21D2\u0338"=>"\u21CF".freeze,
- "\u2203\u0338"=>"\u2204".freeze, "\u2208\u0338"=>"\u2209".freeze, "\u220B\u0338"=>"\u220C".freeze, "\u2223\u0338"=>"\u2224".freeze, "\u2225\u0338"=>"\u2226".freeze, "\u223C\u0338"=>"\u2241".freeze, "\u2243\u0338"=>"\u2244".freeze, "\u2245\u0338"=>"\u2247".freeze,
- "\u2248\u0338"=>"\u2249".freeze, "=\u0338"=>"\u2260".freeze, "\u2261\u0338"=>"\u2262".freeze, "\u224D\u0338"=>"\u226D".freeze, "<\u0338"=>"\u226E".freeze, ">\u0338"=>"\u226F".freeze, "\u2264\u0338"=>"\u2270".freeze, "\u2265\u0338"=>"\u2271".freeze,
- "\u2272\u0338"=>"\u2274".freeze, "\u2273\u0338"=>"\u2275".freeze, "\u2276\u0338"=>"\u2278".freeze, "\u2277\u0338"=>"\u2279".freeze, "\u227A\u0338"=>"\u2280".freeze, "\u227B\u0338"=>"\u2281".freeze, "\u2282\u0338"=>"\u2284".freeze, "\u2283\u0338"=>"\u2285".freeze,
- "\u2286\u0338"=>"\u2288".freeze, "\u2287\u0338"=>"\u2289".freeze, "\u22A2\u0338"=>"\u22AC".freeze, "\u22A8\u0338"=>"\u22AD".freeze, "\u22A9\u0338"=>"\u22AE".freeze, "\u22AB\u0338"=>"\u22AF".freeze, "\u227C\u0338"=>"\u22E0".freeze, "\u227D\u0338"=>"\u22E1".freeze,
- "\u2291\u0338"=>"\u22E2".freeze, "\u2292\u0338"=>"\u22E3".freeze, "\u22B2\u0338"=>"\u22EA".freeze, "\u22B3\u0338"=>"\u22EB".freeze, "\u22B4\u0338"=>"\u22EC".freeze, "\u22B5\u0338"=>"\u22ED".freeze, "\u304B\u3099"=>"\u304C".freeze, "\u304D\u3099"=>"\u304E".freeze,
- "\u304F\u3099"=>"\u3050".freeze, "\u3051\u3099"=>"\u3052".freeze, "\u3053\u3099"=>"\u3054".freeze, "\u3055\u3099"=>"\u3056".freeze, "\u3057\u3099"=>"\u3058".freeze, "\u3059\u3099"=>"\u305A".freeze, "\u305B\u3099"=>"\u305C".freeze, "\u305D\u3099"=>"\u305E".freeze,
- "\u305F\u3099"=>"\u3060".freeze, "\u3061\u3099"=>"\u3062".freeze, "\u3064\u3099"=>"\u3065".freeze, "\u3066\u3099"=>"\u3067".freeze, "\u3068\u3099"=>"\u3069".freeze, "\u306F\u3099"=>"\u3070".freeze, "\u306F\u309A"=>"\u3071".freeze, "\u3072\u3099"=>"\u3073".freeze,
- "\u3072\u309A"=>"\u3074".freeze, "\u3075\u3099"=>"\u3076".freeze, "\u3075\u309A"=>"\u3077".freeze, "\u3078\u3099"=>"\u3079".freeze, "\u3078\u309A"=>"\u307A".freeze, "\u307B\u3099"=>"\u307C".freeze, "\u307B\u309A"=>"\u307D".freeze, "\u3046\u3099"=>"\u3094".freeze,
- "\u309D\u3099"=>"\u309E".freeze, "\u30AB\u3099"=>"\u30AC".freeze, "\u30AD\u3099"=>"\u30AE".freeze, "\u30AF\u3099"=>"\u30B0".freeze, "\u30B1\u3099"=>"\u30B2".freeze, "\u30B3\u3099"=>"\u30B4".freeze, "\u30B5\u3099"=>"\u30B6".freeze, "\u30B7\u3099"=>"\u30B8".freeze,
- "\u30B9\u3099"=>"\u30BA".freeze, "\u30BB\u3099"=>"\u30BC".freeze, "\u30BD\u3099"=>"\u30BE".freeze, "\u30BF\u3099"=>"\u30C0".freeze, "\u30C1\u3099"=>"\u30C2".freeze, "\u30C4\u3099"=>"\u30C5".freeze, "\u30C6\u3099"=>"\u30C7".freeze, "\u30C8\u3099"=>"\u30C9".freeze,
- "\u30CF\u3099"=>"\u30D0".freeze, "\u30CF\u309A"=>"\u30D1".freeze, "\u30D2\u3099"=>"\u30D3".freeze, "\u30D2\u309A"=>"\u30D4".freeze, "\u30D5\u3099"=>"\u30D6".freeze, "\u30D5\u309A"=>"\u30D7".freeze, "\u30D8\u3099"=>"\u30D9".freeze, "\u30D8\u309A"=>"\u30DA".freeze,
- "\u30DB\u3099"=>"\u30DC".freeze, "\u30DB\u309A"=>"\u30DD".freeze, "\u30A6\u3099"=>"\u30F4".freeze, "\u30EF\u3099"=>"\u30F7".freeze, "\u30F0\u3099"=>"\u30F8".freeze, "\u30F1\u3099"=>"\u30F9".freeze, "\u30F2\u3099"=>"\u30FA".freeze, "\u30FD\u3099"=>"\u30FE".freeze,
- "\u{11099}\u{110BA}"=>"\u{1109A}".freeze, "\u{1109B}\u{110BA}"=>"\u{1109C}".freeze, "\u{110A5}\u{110BA}"=>"\u{110AB}".freeze, "\u{11131}\u{11127}"=>"\u{1112E}".freeze, "\u{11132}\u{11127}"=>"\u{1112F}".freeze, "\u{11347}\u{1133E}"=>"\u{1134B}".freeze, "\u{11347}\u{11357}"=>"\u{1134C}".freeze, "\u{114B9}\u{114BA}"=>"\u{114BB}".freeze,
- "\u{114B9}\u{114B0}"=>"\u{114BC}".freeze, "\u{114B9}\u{114BD}"=>"\u{114BE}".freeze, "\u{115B8}\u{115AF}"=>"\u{115BA}".freeze, "\u{115B9}\u{115AF}"=>"\u{115BB}".freeze,
- }.freeze
-end
diff --git a/ruby_2_2/lib/uri.rb b/ruby_2_2/lib/uri.rb
deleted file mode 100644
index 2a48621471..0000000000
--- a/ruby_2_2/lib/uri.rb
+++ /dev/null
@@ -1,111 +0,0 @@
-# URI is a module providing classes to handle Uniform Resource Identifiers
-# (RFC2396[http://tools.ietf.org/html/rfc2396])
-#
-# == Features
-#
-# * Uniform handling of handling URIs
-# * Flexibility to introduce custom URI schemes
-# * Flexibility to have an alternate URI::Parser (or just different patterns
-# and regexp's)
-#
-# == Basic example
-#
-# require 'uri'
-#
-# uri = URI("http://foo.com/posts?id=30&limit=5#time=1305298413")
-# #=> #<URI::HTTP:0x00000000b14880
-# URL:http://foo.com/posts?id=30&limit=5#time=1305298413>
-# uri.scheme
-# #=> "http"
-# uri.host
-# #=> "foo.com"
-# uri.path
-# #=> "/posts"
-# uri.query
-# #=> "id=30&limit=5"
-# uri.fragment
-# #=> "time=1305298413"
-#
-# uri.to_s
-# #=> "http://foo.com/posts?id=30&limit=5#time=1305298413"
-#
-# == Adding custom URIs
-#
-# module URI
-# class RSYNC < Generic
-# DEFAULT_PORT = 873
-# end
-# @@schemes['RSYNC'] = RSYNC
-# end
-# #=> URI::RSYNC
-#
-# URI.scheme_list
-# #=> {"FTP"=>URI::FTP, "HTTP"=>URI::HTTP, "HTTPS"=>URI::HTTPS,
-# "LDAP"=>URI::LDAP, "LDAPS"=>URI::LDAPS, "MAILTO"=>URI::MailTo,
-# "RSYNC"=>URI::RSYNC}
-#
-# uri = URI("rsync://rsync.foo.com")
-# #=> #<URI::RSYNC:0x00000000f648c8 URL:rsync://rsync.foo.com>
-#
-# == RFC References
-#
-# A good place to view an RFC spec is http://www.ietf.org/rfc.html
-#
-# Here is a list of all related RFC's.
-# - RFC822[http://tools.ietf.org/html/rfc822]
-# - RFC1738[http://tools.ietf.org/html/rfc1738]
-# - RFC2255[http://tools.ietf.org/html/rfc2255]
-# - RFC2368[http://tools.ietf.org/html/rfc2368]
-# - RFC2373[http://tools.ietf.org/html/rfc2373]
-# - RFC2396[http://tools.ietf.org/html/rfc2396]
-# - RFC2732[http://tools.ietf.org/html/rfc2732]
-# - RFC3986[http://tools.ietf.org/html/rfc3986]
-#
-# == Class tree
-#
-# - URI::Generic (in uri/generic.rb)
-# - URI::FTP - (in uri/ftp.rb)
-# - URI::HTTP - (in uri/http.rb)
-# - URI::HTTPS - (in uri/https.rb)
-# - URI::LDAP - (in uri/ldap.rb)
-# - URI::LDAPS - (in uri/ldaps.rb)
-# - URI::MailTo - (in uri/mailto.rb)
-# - URI::Parser - (in uri/common.rb)
-# - URI::REGEXP - (in uri/common.rb)
-# - URI::REGEXP::PATTERN - (in uri/common.rb)
-# - URI::Util - (in uri/common.rb)
-# - URI::Escape - (in uri/common.rb)
-# - URI::Error - (in uri/common.rb)
-# - URI::InvalidURIError - (in uri/common.rb)
-# - URI::InvalidComponentError - (in uri/common.rb)
-# - URI::BadURIError - (in uri/common.rb)
-#
-# == Copyright Info
-#
-# Author:: Akira Yamada <akira@ruby-lang.org>
-# Documentation::
-# Akira Yamada <akira@ruby-lang.org>
-# Dmitry V. Sabanin <sdmitry@lrn.ru>
-# Vincent Batts <vbatts@hashbangbash.com>
-# License::
-# Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
-# You can redistribute it and/or modify it under the same term as Ruby.
-# Revision:: $Id$
-#
-
-module URI
- # :stopdoc:
- VERSION_CODE = '001000'.freeze
- VERSION = VERSION_CODE.scan(/../).collect{|n| n.to_i}.join('.').freeze
- # :startdoc:
-
-end
-
-require 'uri/common'
-require 'uri/generic'
-require 'uri/ftp'
-require 'uri/http'
-require 'uri/https'
-require 'uri/ldap'
-require 'uri/ldaps'
-require 'uri/mailto'
diff --git a/ruby_2_2/lib/uri/common.rb b/ruby_2_2/lib/uri/common.rb
deleted file mode 100644
index facca4b08b..0000000000
--- a/ruby_2_2/lib/uri/common.rb
+++ /dev/null
@@ -1,720 +0,0 @@
-#--
-# = uri/common.rb
-#
-# Author:: Akira Yamada <akira@ruby-lang.org>
-# Revision:: $Id$
-# License::
-# You can redistribute it and/or modify it under the same term as Ruby.
-#
-# See URI for general documentation
-#
-
-require "uri/rfc2396_parser"
-require "uri/rfc3986_parser"
-
-module URI
- REGEXP = RFC2396_REGEXP
- Parser = RFC2396_Parser
- RFC3986_PARSER = RFC3986_Parser.new
-
- # URI::Parser.new
- DEFAULT_PARSER = Parser.new
- DEFAULT_PARSER.pattern.each_pair do |sym, str|
- unless REGEXP::PATTERN.const_defined?(sym)
- REGEXP::PATTERN.const_set(sym, str)
- end
- end
- DEFAULT_PARSER.regexp.each_pair do |sym, str|
- const_set(sym, str)
- end
-
- module Util # :nodoc:
- def make_components_hash(klass, array_hash)
- tmp = {}
- if array_hash.kind_of?(Array) &&
- array_hash.size == klass.component.size - 1
- klass.component[1..-1].each_index do |i|
- begin
- tmp[klass.component[i + 1]] = array_hash[i].clone
- rescue TypeError
- tmp[klass.component[i + 1]] = array_hash[i]
- end
- end
-
- elsif array_hash.kind_of?(Hash)
- array_hash.each do |key, value|
- begin
- tmp[key] = value.clone
- rescue TypeError
- tmp[key] = value
- end
- end
- else
- raise ArgumentError,
- "expected Array of or Hash of components of #{klass} (#{klass.component[1..-1].join(', ')})"
- end
- tmp[:scheme] = klass.to_s.sub(/\A.*::/, '').downcase
-
- return tmp
- end
- module_function :make_components_hash
- end
-
- # module for escaping unsafe characters with codes.
- module Escape
- #
- # == Synopsis
- #
- # URI.escape(str [, unsafe])
- #
- # == Args
- #
- # +str+::
- # String to replaces in.
- # +unsafe+::
- # Regexp that matches all symbols that must be replaced with codes.
- # By default uses <tt>REGEXP::UNSAFE</tt>.
- # When this argument is a String, it represents a character set.
- #
- # == Description
- #
- # Escapes the string, replacing all unsafe characters with codes.
- #
- # == Usage
- #
- # require 'uri'
- #
- # enc_uri = URI.escape("http://example.com/?a=\11\15")
- # p enc_uri
- # # => "http://example.com/?a=%09%0D"
- #
- # p URI.unescape(enc_uri)
- # # => "http://example.com/?a=\t\r"
- #
- # p URI.escape("@?@!", "!?")
- # # => "@%3F@%21"
- #
- def escape(*arg)
- warn "#{caller(1)[0]}: warning: URI.escape is obsolete" if $VERBOSE
- DEFAULT_PARSER.escape(*arg)
- end
- alias encode escape
- #
- # == Synopsis
- #
- # URI.unescape(str)
- #
- # == Args
- #
- # +str+::
- # Unescapes the string.
- #
- # == Usage
- #
- # require 'uri'
- #
- # enc_uri = URI.escape("http://example.com/?a=\11\15")
- # p enc_uri
- # # => "http://example.com/?a=%09%0D"
- #
- # p URI.unescape(enc_uri)
- # # => "http://example.com/?a=\t\r"
- #
- def unescape(*arg)
- warn "#{caller(1)[0]}: warning: URI.unescape is obsolete" if $VERBOSE
- DEFAULT_PARSER.unescape(*arg)
- end
- alias decode unescape
- end # module Escape
-
- extend Escape
- include REGEXP
-
- @@schemes = {}
- # Returns a Hash of the defined schemes
- def self.scheme_list
- @@schemes
- end
-
- #
- # Base class for all URI exceptions.
- #
- class Error < StandardError; end
- #
- # Not a URI.
- #
- class InvalidURIError < Error; end
- #
- # Not a URI component.
- #
- class InvalidComponentError < Error; end
- #
- # URI is valid, bad usage is not.
- #
- class BadURIError < Error; end
-
- #
- # == Synopsis
- #
- # URI::split(uri)
- #
- # == Args
- #
- # +uri+::
- # String with URI.
- #
- # == Description
- #
- # Splits the string on following parts and returns array with result:
- #
- # * Scheme
- # * Userinfo
- # * Host
- # * Port
- # * Registry
- # * Path
- # * Opaque
- # * Query
- # * Fragment
- #
- # == Usage
- #
- # require 'uri'
- #
- # p URI.split("http://www.ruby-lang.org/")
- # # => ["http", nil, "www.ruby-lang.org", nil, nil, "/", nil, nil, nil]
- #
- def self.split(uri)
- RFC3986_PARSER.split(uri)
- end
-
- #
- # == Synopsis
- #
- # URI::parse(uri_str)
- #
- # == Args
- #
- # +uri_str+::
- # String with URI.
- #
- # == Description
- #
- # Creates one of the URI's subclasses instance from the string.
- #
- # == Raises
- #
- # URI::InvalidURIError
- # Raised if URI given is not a correct one.
- #
- # == Usage
- #
- # require 'uri'
- #
- # uri = URI.parse("http://www.ruby-lang.org/")
- # p uri
- # # => #<URI::HTTP:0x202281be URL:http://www.ruby-lang.org/>
- # p uri.scheme
- # # => "http"
- # p uri.host
- # # => "www.ruby-lang.org"
- #
- # It's recommended to first ::escape the provided +uri_str+ if there are any
- # invalid URI characters.
- #
- def self.parse(uri)
- RFC3986_PARSER.parse(uri)
- end
-
- #
- # == Synopsis
- #
- # URI::join(str[, str, ...])
- #
- # == Args
- #
- # +str+::
- # String(s) to work with, will be converted to RFC3986 URIs before merging.
- #
- # == Description
- #
- # Joins URIs.
- #
- # == Usage
- #
- # require 'uri'
- #
- # p URI.join("http://example.com/","main.rbx")
- # # => #<URI::HTTP:0x2022ac02 URL:http://localhost/main.rbx>
- #
- # p URI.join('http://example.com', 'foo')
- # # => #<URI::HTTP:0x01ab80a0 URL:http://example.com/foo>
- #
- # p URI.join('http://example.com', '/foo', '/bar')
- # # => #<URI::HTTP:0x01aaf0b0 URL:http://example.com/bar>
- #
- # p URI.join('http://example.com', '/foo', 'bar')
- # # => #<URI::HTTP:0x801a92af0 URL:http://example.com/bar>
- #
- # p URI.join('http://example.com', '/foo/', 'bar')
- # # => #<URI::HTTP:0x80135a3a0 URL:http://example.com/foo/bar>
- #
- #
- def self.join(*str)
- RFC3986_PARSER.join(*str)
- end
-
- #
- # == Synopsis
- #
- # URI::extract(str[, schemes][,&blk])
- #
- # == Args
- #
- # +str+::
- # String to extract URIs from.
- # +schemes+::
- # Limit URI matching to a specific schemes.
- #
- # == Description
- #
- # Extracts URIs from a string. If block given, iterates through all matched URIs.
- # Returns nil if block given or array with matches.
- #
- # == Usage
- #
- # require "uri"
- #
- # URI.extract("text here http://foo.example.org/bla and here mailto:test@example.com and here also.")
- # # => ["http://foo.example.com/bla", "mailto:test@example.com"]
- #
- def self.extract(str, schemes = nil, &block)
- warn "#{caller(1)[0]}: warning: URI.extract is obsolete" if $VERBOSE
- DEFAULT_PARSER.extract(str, schemes, &block)
- end
-
- #
- # == Synopsis
- #
- # URI::regexp([match_schemes])
- #
- # == Args
- #
- # +match_schemes+::
- # Array of schemes. If given, resulting regexp matches to URIs
- # whose scheme is one of the match_schemes.
- #
- # == Description
- # Returns a Regexp object which matches to URI-like strings.
- # The Regexp object returned by this method includes arbitrary
- # number of capture group (parentheses). Never rely on it's number.
- #
- # == Usage
- #
- # require 'uri'
- #
- # # extract first URI from html_string
- # html_string.slice(URI.regexp)
- #
- # # remove ftp URIs
- # html_string.sub(URI.regexp(['ftp'])
- #
- # # You should not rely on the number of parentheses
- # html_string.scan(URI.regexp) do |*matches|
- # p $&
- # end
- #
- def self.regexp(schemes = nil)
- warn "#{caller(1)[0]}: warning: URI.regexp is obsolete" if $VERBOSE
- DEFAULT_PARSER.make_regexp(schemes)
- end
-
- TBLENCWWWCOMP_ = {} # :nodoc:
- 256.times do |i|
- TBLENCWWWCOMP_[i.chr] = '%%%02X' % i
- end
- TBLENCWWWCOMP_[' '] = '+'
- TBLENCWWWCOMP_.freeze
- TBLDECWWWCOMP_ = {} # :nodoc:
- 256.times do |i|
- h, l = i>>4, i&15
- TBLDECWWWCOMP_['%%%X%X' % [h, l]] = i.chr
- TBLDECWWWCOMP_['%%%x%X' % [h, l]] = i.chr
- TBLDECWWWCOMP_['%%%X%x' % [h, l]] = i.chr
- TBLDECWWWCOMP_['%%%x%x' % [h, l]] = i.chr
- end
- TBLDECWWWCOMP_['+'] = ' '
- TBLDECWWWCOMP_.freeze
-
- HTML5ASCIIINCOMPAT = [Encoding::UTF_7, Encoding::UTF_16BE, Encoding::UTF_16LE,
- Encoding::UTF_32BE, Encoding::UTF_32LE] # :nodoc:
-
- # Encode given +str+ to URL-encoded form data.
- #
- # This method doesn't convert *, -, ., 0-9, A-Z, _, a-z, but does convert SP
- # (ASCII space) to + and converts others to %XX.
- #
- # If +enc+ is given, convert +str+ to the encoding before percent encoding.
- #
- # This is an implementation of
- # http://www.w3.org/TR/2013/CR-html5-20130806/forms.html#url-encoded-form-data
- #
- # See URI.decode_www_form_component, URI.encode_www_form
- def self.encode_www_form_component(str, enc=nil)
- str = str.to_s.dup
- if str.encoding != Encoding::ASCII_8BIT
- if enc && enc != Encoding::ASCII_8BIT
- str.encode!(Encoding::UTF_8, invalid: :replace, undef: :replace)
- str.encode!(enc, fallback: ->(x){"&#{x.ord};"})
- end
- str.force_encoding(Encoding::ASCII_8BIT)
- end
- str.gsub!(/[^*\-.0-9A-Z_a-z]/, TBLENCWWWCOMP_)
- str.force_encoding(Encoding::US_ASCII)
- end
-
- # Decode given +str+ of URL-encoded form data.
- #
- # This decodes + to SP.
- #
- # See URI.encode_www_form_component, URI.decode_www_form
- def self.decode_www_form_component(str, enc=Encoding::UTF_8)
- raise ArgumentError, "invalid %-encoding (#{str})" if /%(?!\h\h)/ =~ str
- str.b.gsub(/\+|%\h\h/, TBLDECWWWCOMP_).force_encoding(enc)
- end
-
- # Generate URL-encoded form data from given +enum+.
- #
- # This generates application/x-www-form-urlencoded data defined in HTML5
- # from given an Enumerable object.
- #
- # This internally uses URI.encode_www_form_component(str).
- #
- # This method doesn't convert the encoding of given items, so convert them
- # before call this method if you want to send data as other than original
- # encoding or mixed encoding data. (Strings which are encoded in an HTML5
- # ASCII incompatible encoding are converted to UTF-8.)
- #
- # This method doesn't handle files. When you send a file, use
- # multipart/form-data.
- #
- # This refers http://url.spec.whatwg.org/#concept-urlencoded-serializer
- #
- # URI.encode_www_form([["q", "ruby"], ["lang", "en"]])
- # #=> "q=ruby&lang=en"
- # URI.encode_www_form("q" => "ruby", "lang" => "en")
- # #=> "q=ruby&lang=en"
- # URI.encode_www_form("q" => ["ruby", "perl"], "lang" => "en")
- # #=> "q=ruby&q=perl&lang=en"
- # URI.encode_www_form([["q", "ruby"], ["q", "perl"], ["lang", "en"]])
- # #=> "q=ruby&q=perl&lang=en"
- #
- # See URI.encode_www_form_component, URI.decode_www_form
- def self.encode_www_form(enum, enc=nil)
- enum.map do |k,v|
- if v.nil?
- encode_www_form_component(k, enc)
- elsif v.respond_to?(:to_ary)
- v.to_ary.map do |w|
- str = encode_www_form_component(k, enc)
- unless w.nil?
- str << '='
- str << encode_www_form_component(w, enc)
- end
- end.join('&')
- else
- str = encode_www_form_component(k, enc)
- str << '='
- str << encode_www_form_component(v, enc)
- end
- end.join('&')
- end
-
- # Decode URL-encoded form data from given +str+.
- #
- # This decodes application/x-www-form-urlencoded data
- # and returns array of key-value array.
- #
- # This refers http://url.spec.whatwg.org/#concept-urlencoded-parser ,
- # so this supports only &-separator, don't support ;-separator.
- #
- # ary = URI.decode_www_form("a=1&a=2&b=3")
- # p ary #=> [['a', '1'], ['a', '2'], ['b', '3']]
- # p ary.assoc('a').last #=> '1'
- # p ary.assoc('b').last #=> '3'
- # p ary.rassoc('a').last #=> '2'
- # p Hash[ary] # => {"a"=>"2", "b"=>"3"}
- #
- # See URI.decode_www_form_component, URI.encode_www_form
- def self.decode_www_form(str, enc=Encoding::UTF_8, separator: '&', use__charset_: false, isindex: false)
- raise ArgumentError, "the input of #{self.name}.#{__method__} must be ASCII only string" unless str.ascii_only?
- ary = []
- return ary if str.empty?
- enc = Encoding.find(enc)
- str.b.each_line(separator) do |string|
- string.chomp!(separator)
- key, sep, val = string.partition('=')
- if isindex
- if sep.empty?
- val = key
- key = ''
- end
- isindex = false
- end
-
- if use__charset_ and key == '_charset_' and e = get_encoding(val)
- enc = e
- use__charset_ = false
- end
-
- key.gsub!(/\+|%\h\h/, TBLDECWWWCOMP_)
- if val
- val.gsub!(/\+|%\h\h/, TBLDECWWWCOMP_)
- else
- val = ''
- end
-
- ary << [key, val]
- end
- ary.each do |k, v|
- k.force_encoding(enc)
- k.scrub!
- v.force_encoding(enc)
- v.scrub!
- end
- ary
- end
-
- private
- # curl http://encoding.spec.whatwg.org/encodings.json|rb -rpp -rjson -e'H={};h={"shift_jis"=>"Windows-31J","euc-jp"=>"cp51932","iso-2022-jp"=>"cp50221","x-mac-cyrillic"=>"macCyrillic"};JSON($<.read).map{|x|x["encodings"]}.flatten.each{|x|Encoding.find(n=h.fetch(n=x["name"],n))rescue next;x["labels"].each{|y|H[y]=n}};pp H'
- WEB_ENCODINGS_ = {
- "unicode-1-1-utf-8"=>"utf-8",
- "utf-8"=>"utf-8",
- "utf8"=>"utf-8",
- "866"=>"ibm866",
- "cp866"=>"ibm866",
- "csibm866"=>"ibm866",
- "ibm866"=>"ibm866",
- "csisolatin2"=>"iso-8859-2",
- "iso-8859-2"=>"iso-8859-2",
- "iso-ir-101"=>"iso-8859-2",
- "iso8859-2"=>"iso-8859-2",
- "iso88592"=>"iso-8859-2",
- "iso_8859-2"=>"iso-8859-2",
- "iso_8859-2:1987"=>"iso-8859-2",
- "l2"=>"iso-8859-2",
- "latin2"=>"iso-8859-2",
- "csisolatin3"=>"iso-8859-3",
- "iso-8859-3"=>"iso-8859-3",
- "iso-ir-109"=>"iso-8859-3",
- "iso8859-3"=>"iso-8859-3",
- "iso88593"=>"iso-8859-3",
- "iso_8859-3"=>"iso-8859-3",
- "iso_8859-3:1988"=>"iso-8859-3",
- "l3"=>"iso-8859-3",
- "latin3"=>"iso-8859-3",
- "csisolatin4"=>"iso-8859-4",
- "iso-8859-4"=>"iso-8859-4",
- "iso-ir-110"=>"iso-8859-4",
- "iso8859-4"=>"iso-8859-4",
- "iso88594"=>"iso-8859-4",
- "iso_8859-4"=>"iso-8859-4",
- "iso_8859-4:1988"=>"iso-8859-4",
- "l4"=>"iso-8859-4",
- "latin4"=>"iso-8859-4",
- "csisolatincyrillic"=>"iso-8859-5",
- "cyrillic"=>"iso-8859-5",
- "iso-8859-5"=>"iso-8859-5",
- "iso-ir-144"=>"iso-8859-5",
- "iso8859-5"=>"iso-8859-5",
- "iso88595"=>"iso-8859-5",
- "iso_8859-5"=>"iso-8859-5",
- "iso_8859-5:1988"=>"iso-8859-5",
- "arabic"=>"iso-8859-6",
- "asmo-708"=>"iso-8859-6",
- "csiso88596e"=>"iso-8859-6",
- "csiso88596i"=>"iso-8859-6",
- "csisolatinarabic"=>"iso-8859-6",
- "ecma-114"=>"iso-8859-6",
- "iso-8859-6"=>"iso-8859-6",
- "iso-8859-6-e"=>"iso-8859-6",
- "iso-8859-6-i"=>"iso-8859-6",
- "iso-ir-127"=>"iso-8859-6",
- "iso8859-6"=>"iso-8859-6",
- "iso88596"=>"iso-8859-6",
- "iso_8859-6"=>"iso-8859-6",
- "iso_8859-6:1987"=>"iso-8859-6",
- "csisolatingreek"=>"iso-8859-7",
- "ecma-118"=>"iso-8859-7",
- "elot_928"=>"iso-8859-7",
- "greek"=>"iso-8859-7",
- "greek8"=>"iso-8859-7",
- "iso-8859-7"=>"iso-8859-7",
- "iso-ir-126"=>"iso-8859-7",
- "iso8859-7"=>"iso-8859-7",
- "iso88597"=>"iso-8859-7",
- "iso_8859-7"=>"iso-8859-7",
- "iso_8859-7:1987"=>"iso-8859-7",
- "sun_eu_greek"=>"iso-8859-7",
- "csiso88598e"=>"iso-8859-8",
- "csisolatinhebrew"=>"iso-8859-8",
- "hebrew"=>"iso-8859-8",
- "iso-8859-8"=>"iso-8859-8",
- "iso-8859-8-e"=>"iso-8859-8",
- "iso-ir-138"=>"iso-8859-8",
- "iso8859-8"=>"iso-8859-8",
- "iso88598"=>"iso-8859-8",
- "iso_8859-8"=>"iso-8859-8",
- "iso_8859-8:1988"=>"iso-8859-8",
- "visual"=>"iso-8859-8",
- "csisolatin6"=>"iso-8859-10",
- "iso-8859-10"=>"iso-8859-10",
- "iso-ir-157"=>"iso-8859-10",
- "iso8859-10"=>"iso-8859-10",
- "iso885910"=>"iso-8859-10",
- "l6"=>"iso-8859-10",
- "latin6"=>"iso-8859-10",
- "iso-8859-13"=>"iso-8859-13",
- "iso8859-13"=>"iso-8859-13",
- "iso885913"=>"iso-8859-13",
- "iso-8859-14"=>"iso-8859-14",
- "iso8859-14"=>"iso-8859-14",
- "iso885914"=>"iso-8859-14",
- "csisolatin9"=>"iso-8859-15",
- "iso-8859-15"=>"iso-8859-15",
- "iso8859-15"=>"iso-8859-15",
- "iso885915"=>"iso-8859-15",
- "iso_8859-15"=>"iso-8859-15",
- "l9"=>"iso-8859-15",
- "iso-8859-16"=>"iso-8859-16",
- "cskoi8r"=>"koi8-r",
- "koi"=>"koi8-r",
- "koi8"=>"koi8-r",
- "koi8-r"=>"koi8-r",
- "koi8_r"=>"koi8-r",
- "koi8-u"=>"koi8-u",
- "dos-874"=>"windows-874",
- "iso-8859-11"=>"windows-874",
- "iso8859-11"=>"windows-874",
- "iso885911"=>"windows-874",
- "tis-620"=>"windows-874",
- "windows-874"=>"windows-874",
- "cp1250"=>"windows-1250",
- "windows-1250"=>"windows-1250",
- "x-cp1250"=>"windows-1250",
- "cp1251"=>"windows-1251",
- "windows-1251"=>"windows-1251",
- "x-cp1251"=>"windows-1251",
- "ansi_x3.4-1968"=>"windows-1252",
- "ascii"=>"windows-1252",
- "cp1252"=>"windows-1252",
- "cp819"=>"windows-1252",
- "csisolatin1"=>"windows-1252",
- "ibm819"=>"windows-1252",
- "iso-8859-1"=>"windows-1252",
- "iso-ir-100"=>"windows-1252",
- "iso8859-1"=>"windows-1252",
- "iso88591"=>"windows-1252",
- "iso_8859-1"=>"windows-1252",
- "iso_8859-1:1987"=>"windows-1252",
- "l1"=>"windows-1252",
- "latin1"=>"windows-1252",
- "us-ascii"=>"windows-1252",
- "windows-1252"=>"windows-1252",
- "x-cp1252"=>"windows-1252",
- "cp1253"=>"windows-1253",
- "windows-1253"=>"windows-1253",
- "x-cp1253"=>"windows-1253",
- "cp1254"=>"windows-1254",
- "csisolatin5"=>"windows-1254",
- "iso-8859-9"=>"windows-1254",
- "iso-ir-148"=>"windows-1254",
- "iso8859-9"=>"windows-1254",
- "iso88599"=>"windows-1254",
- "iso_8859-9"=>"windows-1254",
- "iso_8859-9:1989"=>"windows-1254",
- "l5"=>"windows-1254",
- "latin5"=>"windows-1254",
- "windows-1254"=>"windows-1254",
- "x-cp1254"=>"windows-1254",
- "cp1255"=>"windows-1255",
- "windows-1255"=>"windows-1255",
- "x-cp1255"=>"windows-1255",
- "cp1256"=>"windows-1256",
- "windows-1256"=>"windows-1256",
- "x-cp1256"=>"windows-1256",
- "cp1257"=>"windows-1257",
- "windows-1257"=>"windows-1257",
- "x-cp1257"=>"windows-1257",
- "cp1258"=>"windows-1258",
- "windows-1258"=>"windows-1258",
- "x-cp1258"=>"windows-1258",
- "x-mac-cyrillic"=>"macCyrillic",
- "x-mac-ukrainian"=>"macCyrillic",
- "chinese"=>"gbk",
- "csgb2312"=>"gbk",
- "csiso58gb231280"=>"gbk",
- "gb2312"=>"gbk",
- "gb_2312"=>"gbk",
- "gb_2312-80"=>"gbk",
- "gbk"=>"gbk",
- "iso-ir-58"=>"gbk",
- "x-gbk"=>"gbk",
- "gb18030"=>"gb18030",
- "big5"=>"big5",
- "big5-hkscs"=>"big5",
- "cn-big5"=>"big5",
- "csbig5"=>"big5",
- "x-x-big5"=>"big5",
- "cseucpkdfmtjapanese"=>"cp51932",
- "euc-jp"=>"cp51932",
- "x-euc-jp"=>"cp51932",
- "csiso2022jp"=>"cp50221",
- "iso-2022-jp"=>"cp50221",
- "csshiftjis"=>"Windows-31J",
- "ms_kanji"=>"Windows-31J",
- "shift-jis"=>"Windows-31J",
- "shift_jis"=>"Windows-31J",
- "sjis"=>"Windows-31J",
- "windows-31j"=>"Windows-31J",
- "x-sjis"=>"Windows-31J",
- "cseuckr"=>"euc-kr",
- "csksc56011987"=>"euc-kr",
- "euc-kr"=>"euc-kr",
- "iso-ir-149"=>"euc-kr",
- "korean"=>"euc-kr",
- "ks_c_5601-1987"=>"euc-kr",
- "ks_c_5601-1989"=>"euc-kr",
- "ksc5601"=>"euc-kr",
- "ksc_5601"=>"euc-kr",
- "windows-949"=>"euc-kr",
- "utf-16be"=>"utf-16be",
- "utf-16"=>"utf-16le",
- "utf-16le"=>"utf-16le"
- } # :nodoc:
-
- # :nodoc:
- # return encoding or nil
- # http://encoding.spec.whatwg.org/#concept-encoding-get
- def self.get_encoding(label)
- Encoding.find(WEB_ENCODINGS_[label.to_str.strip.downcase]) rescue nil
- end
-end # module URI
-
-module Kernel
-
- #
- # Returns +uri+ converted to a URI object.
- #
- def URI(uri)
- if uri.is_a?(URI::Generic)
- uri
- elsif uri = String.try_convert(uri)
- URI.parse(uri)
- else
- raise ArgumentError,
- "bad argument (expected URI object or URI string)"
- end
- end
- module_function :URI
-end
diff --git a/ruby_2_2/lib/uri/ftp.rb b/ruby_2_2/lib/uri/ftp.rb
deleted file mode 100644
index 557e1fda33..0000000000
--- a/ruby_2_2/lib/uri/ftp.rb
+++ /dev/null
@@ -1,266 +0,0 @@
-# = uri/ftp.rb
-#
-# Author:: Akira Yamada <akira@ruby-lang.org>
-# License:: You can redistribute it and/or modify it under the same term as Ruby.
-# Revision:: $Id$
-#
-# See URI for general documentation
-#
-
-require 'uri/generic'
-
-module URI
-
- #
- # FTP URI syntax is defined by RFC1738 section 3.2.
- #
- # This class will be redesigned because of difference of implementations;
- # the structure of its path. draft-hoffman-ftp-uri-04 is a draft but it
- # is a good summary about the de facto spec.
- # http://tools.ietf.org/html/draft-hoffman-ftp-uri-04
- #
- class FTP < Generic
- # A Default port of 21 for URI::FTP
- DEFAULT_PORT = 21
-
- #
- # An Array of the available components for URI::FTP
- #
- COMPONENT = [
- :scheme,
- :userinfo, :host, :port,
- :path, :typecode
- ].freeze
-
- #
- # Typecode is "a", "i" or "d".
- #
- # * "a" indicates a text file (the FTP command was ASCII)
- # * "i" indicates a binary file (FTP command IMAGE)
- # * "d" indicates the contents of a directory should be displayed
- #
- TYPECODE = ['a', 'i', 'd'].freeze
-
- # Typecode prefix
- # ';type='
- TYPECODE_PREFIX = ';type='.freeze
-
- def self.new2(user, password, host, port, path,
- typecode = nil, arg_check = true) # :nodoc:
- # Do not use this method! Not tested. [Bug #7301]
- # This methods remains just for compatibility,
- # Keep it undocumented until the active maintainer is assigned.
- typecode = nil if typecode.size == 0
- if typecode && !TYPECODE.include?(typecode)
- raise ArgumentError,
- "bad typecode is specified: #{typecode}"
- end
-
- # do escape
-
- self.new('ftp',
- [user, password],
- host, port, nil,
- typecode ? path + TYPECODE_PREFIX + typecode : path,
- nil, nil, nil, arg_check)
- end
-
- #
- # == Description
- #
- # Creates a new URI::FTP object from components, with syntax checking.
- #
- # The components accepted are +userinfo+, +host+, +port+, +path+ and
- # +typecode+.
- #
- # The components should be provided either as an Array, or as a Hash
- # with keys formed by preceding the component names with a colon.
- #
- # If an Array is used, the components must be passed in the order
- # [userinfo, host, port, path, typecode]
- #
- # If the path supplied is absolute, it will be escaped in order to
- # make it absolute in the URI. Examples:
- #
- # require 'uri'
- #
- # uri = URI::FTP.build(['user:password', 'ftp.example.com', nil,
- # '/path/file.> zip', 'i'])
- # puts uri.to_s -> ftp://user:password@ftp.example.com/%2Fpath/file.zip;type=a
- #
- # uri2 = URI::FTP.build({:host => 'ftp.example.com',
- # :path => 'ruby/src'})
- # puts uri2.to_s -> ftp://ftp.example.com/ruby/src
- #
- def self.build(args)
-
- # Fix the incoming path to be generic URL syntax
- # FTP path -> URL path
- # foo/bar /foo/bar
- # /foo/bar /%2Ffoo/bar
- #
- if args.kind_of?(Array)
- args[3] = '/' + args[3].sub(/^\//, '%2F')
- else
- args[:path] = '/' + args[:path].sub(/^\//, '%2F')
- end
-
- tmp = Util::make_components_hash(self, args)
-
- if tmp[:typecode]
- if tmp[:typecode].size == 1
- tmp[:typecode] = TYPECODE_PREFIX + tmp[:typecode]
- end
- tmp[:path] << tmp[:typecode]
- end
-
- return super(tmp)
- end
-
- #
- # == Description
- #
- # Creates a new URI::FTP object from generic URL components with no
- # syntax checking.
- #
- # Unlike build(), this method does not escape the path component as
- # required by RFC1738; instead it is treated as per RFC2396.
- #
- # Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
- # +opaque+, +query+ and +fragment+, in that order.
- #
- def initialize(scheme,
- userinfo, host, port, registry,
- path, opaque,
- query,
- fragment,
- parser = nil,
- arg_check = false)
- raise InvalidURIError unless path
- path = path.sub(/^\//,'')
- path.sub!(/^%2F/,'/')
- super(scheme, userinfo, host, port, registry, path, opaque,
- query, fragment, parser, arg_check)
- @typecode = nil
- if tmp = @path.index(TYPECODE_PREFIX)
- typecode = @path[tmp + TYPECODE_PREFIX.size..-1]
- @path = @path[0..tmp - 1]
-
- if arg_check
- self.typecode = typecode
- else
- self.set_typecode(typecode)
- end
- end
- end
-
- # typecode accessor
- #
- # see URI::FTP::COMPONENT
- attr_reader :typecode
-
- # validates typecode +v+,
- # returns a +true+ or +false+ boolean
- #
- def check_typecode(v)
- if TYPECODE.include?(v)
- return true
- else
- raise InvalidComponentError,
- "bad typecode(expected #{TYPECODE.join(', ')}): #{v}"
- end
- end
- private :check_typecode
-
- # Private setter for the typecode +v+
- #
- # see also URI::FTP.typecode=
- #
- def set_typecode(v)
- @typecode = v
- end
- protected :set_typecode
-
- #
- # == Args
- #
- # +v+::
- # String
- #
- # == Description
- #
- # public setter for the typecode +v+.
- # (with validation)
- #
- # see also URI::FTP.check_typecode
- #
- # == Usage
- #
- # require 'uri'
- #
- # uri = URI.parse("ftp://john@ftp.example.com/my_file.img")
- # #=> #<URI::FTP:0x00000000923650 URL:ftp://john@ftp.example.com/my_file.img>
- # uri.typecode = "i"
- # # => "i"
- # uri
- # #=> #<URI::FTP:0x00000000923650 URL:ftp://john@ftp.example.com/my_file.img;type=i>
- #
- def typecode=(typecode)
- check_typecode(typecode)
- set_typecode(typecode)
- typecode
- end
-
- def merge(oth) # :nodoc:
- tmp = super(oth)
- if self != tmp
- tmp.set_typecode(oth.typecode)
- end
-
- return tmp
- end
-
- # Returns the path from an FTP URI.
- #
- # RFC 1738 specifically states that the path for an FTP URI does not
- # include the / which separates the URI path from the URI host. Example:
- #
- # ftp://ftp.example.com/pub/ruby
- #
- # The above URI indicates that the client should connect to
- # ftp.example.com then cd pub/ruby from the initial login directory.
- #
- # If you want to cd to an absolute directory, you must include an
- # escaped / (%2F) in the path. Example:
- #
- # ftp://ftp.example.com/%2Fpub/ruby
- #
- # This method will then return "/pub/ruby"
- #
- def path
- return @path.sub(/^\//,'').sub(/^%2F/,'/')
- end
-
- # Private setter for the path of the URI::FTP
- def set_path(v)
- super("/" + v.sub(/^\//, "%2F"))
- end
- protected :set_path
-
- # Returns a String representation of the URI::FTP
- def to_s
- save_path = nil
- if @typecode
- save_path = @path
- @path = @path + TYPECODE_PREFIX + @typecode
- end
- str = super
- if @typecode
- @path = save_path
- end
-
- return str
- end
- end
- @@schemes['FTP'] = FTP
-end
diff --git a/ruby_2_2/lib/uri/generic.rb b/ruby_2_2/lib/uri/generic.rb
deleted file mode 100644
index c608f0b045..0000000000
--- a/ruby_2_2/lib/uri/generic.rb
+++ /dev/null
@@ -1,1557 +0,0 @@
-# = uri/generic.rb
-#
-# Author:: Akira Yamada <akira@ruby-lang.org>
-# License:: You can redistribute it and/or modify it under the same term as Ruby.
-# Revision:: $Id$
-#
-# See URI for general documentation
-#
-
-require 'uri/common'
-
-module URI
-
- #
- # Base class for all URI classes.
- # Implements generic URI syntax as per RFC 2396.
- #
- class Generic
- include URI
-
- #
- # A Default port of nil for URI::Generic
- #
- DEFAULT_PORT = nil
-
- #
- # Returns default port
- #
- def self.default_port
- self::DEFAULT_PORT
- end
-
- #
- # Returns default port
- #
- def default_port
- self.class.default_port
- end
-
- #
- # An Array of the available components for URI::Generic
- #
- COMPONENT = [
- :scheme,
- :userinfo, :host, :port, :registry,
- :path, :opaque,
- :query,
- :fragment
- ].freeze
-
- #
- # Components of the URI in the order.
- #
- def self.component
- self::COMPONENT
- end
-
- USE_REGISTRY = false # :nodoc:
-
- def self.use_registry # :nodoc:
- self::USE_REGISTRY
- end
-
- #
- # == Synopsis
- #
- # See #new
- #
- # == Description
- #
- # At first, tries to create a new URI::Generic instance using
- # URI::Generic::build. But, if exception URI::InvalidComponentError is raised,
- # then it URI::Escape.escape all URI components and tries again.
- #
- #
- def self.build2(args)
- begin
- return self.build(args)
- rescue InvalidComponentError
- if args.kind_of?(Array)
- return self.build(args.collect{|x|
- if x.is_a?(String)
- DEFAULT_PARSER.escape(x)
- else
- x
- end
- })
- elsif args.kind_of?(Hash)
- tmp = {}
- args.each do |key, value|
- tmp[key] = if value
- DEFAULT_PARSER.escape(value)
- else
- value
- end
- end
- return self.build(tmp)
- end
- end
- end
-
- #
- # == Synopsis
- #
- # See #new
- #
- # == Description
- #
- # Creates a new URI::Generic instance from components of URI::Generic
- # with check. Components are: scheme, userinfo, host, port, registry, path,
- # opaque, query and fragment. You can provide arguments either by an Array or a Hash.
- # See #new for hash keys to use or for order of array items.
- #
- def self.build(args)
- if args.kind_of?(Array) &&
- args.size == ::URI::Generic::COMPONENT.size
- tmp = args.dup
- elsif args.kind_of?(Hash)
- tmp = ::URI::Generic::COMPONENT.collect do |c|
- if args.include?(c)
- args[c]
- else
- nil
- end
- end
- else
- component = self.class.component rescue ::URI::Generic::COMPONENT
- raise ArgumentError,
- "expected Array of or Hash of components of #{self.class} (#{component.join(', ')})"
- end
-
- tmp << nil
- tmp << true
- return self.new(*tmp)
- end
- #
- # == Args
- #
- # +scheme+::
- # Protocol scheme, i.e. 'http','ftp','mailto' and so on.
- # +userinfo+::
- # User name and password, i.e. 'sdmitry:bla'
- # +host+::
- # Server host name
- # +port+::
- # Server port
- # +registry+::
- # Registry of naming authorities.
- # +path+::
- # Path on server
- # +opaque+::
- # Opaque part
- # +query+::
- # Query data
- # +fragment+::
- # A part of URI after '#' sign
- # +parser+::
- # Parser for internal use [URI::DEFAULT_PARSER by default]
- # +arg_check+::
- # Check arguments [false by default]
- #
- # == Description
- #
- # Creates a new URI::Generic instance from ``generic'' components without check.
- #
- def initialize(scheme,
- userinfo, host, port, registry,
- path, opaque,
- query,
- fragment,
- parser = DEFAULT_PARSER,
- arg_check = false)
- @scheme = nil
- @user = nil
- @password = nil
- @host = nil
- @port = nil
- @path = nil
- @query = nil
- @opaque = nil
- @fragment = nil
- @parser = parser == DEFAULT_PARSER ? nil : parser
-
- if arg_check
- self.scheme = scheme
- self.userinfo = userinfo
- self.hostname = host
- self.port = port
- self.path = path
- self.query = query
- self.opaque = opaque
- self.fragment = fragment
- else
- self.set_scheme(scheme)
- self.set_userinfo(userinfo)
- self.set_host(host)
- self.set_port(port)
- self.set_path(path)
- self.query = query
- self.set_opaque(opaque)
- self.fragment=(fragment)
- end
- if registry
- raise InvalidURIError,
- "the scheme #{@scheme} does not accept registry part: #{registry} (or bad hostname?)"
- end
-
- @scheme.freeze if @scheme
- self.set_path('') if !@path && !@opaque # (see RFC2396 Section 5.2)
- self.set_port(self.default_port) if self.default_port && !@port
- end
-
- #
- # returns the scheme component of the URI.
- #
- # URI("http://foo/bar/baz").scheme #=> "http"
- #
- attr_reader :scheme
-
- # returns the host component of the URI.
- #
- # URI("http://foo/bar/baz").host #=> "foo"
- #
- # It returns nil if no host component.
- #
- # URI("mailto:foo@example.org").host #=> nil
- #
- # The component doesn't contains the port number.
- #
- # URI("http://foo:8080/bar/baz").host #=> "foo"
- #
- # Since IPv6 addresses are wrapped by brackets in URIs,
- # this method returns IPv6 addresses wrapped by brackets.
- # This form is not appropriate to pass socket methods such as TCPSocket.open.
- # If unwrapped host names are required, use "hostname" method.
- #
- # URI("http://[::1]/bar/baz").host #=> "[::1]"
- # URI("http://[::1]/bar/baz").hostname #=> "::1"
- #
- attr_reader :host
-
- # returns the port component of the URI.
- #
- # URI("http://foo/bar/baz").port #=> "80"
- #
- # URI("http://foo:8080/bar/baz").port #=> "8080"
- #
- attr_reader :port
-
- def registry # :nodoc:
- nil
- end
-
- # returns the path component of the URI.
- #
- # URI("http://foo/bar/baz").path #=> "/bar/baz"
- #
- attr_reader :path
-
- # returns the query component of the URI.
- #
- # URI("http://foo/bar/baz?search=FooBar").query #=> "search=FooBar"
- #
- attr_reader :query
-
- # returns the opaque part of the URI.
- #
- # URI("mailto:foo@example.org").opaque #=> "foo@example.org"
- #
- # Portion of the path that does make use of the slash '/'.
- # The path typically refers to the absolute path and the opaque part.
- # (see RFC2396 Section 3 and 5.2)
- #
- attr_reader :opaque
-
- # returns the fragment component of the URI.
- #
- # URI("http://foo/bar/baz?search=FooBar#ponies").fragment #=> "ponies"
- #
- attr_reader :fragment
-
- # returns the parser to be used.
- #
- # Unless a URI::Parser is defined, then DEFAULT_PARSER is used.
- #
- def parser
- if !defined?(@parser) || !@parser
- DEFAULT_PARSER
- else
- @parser || DEFAULT_PARSER
- end
- end
-
- # replace self by other URI object
- def replace!(oth)
- if self.class != oth.class
- raise ArgumentError, "expected #{self.class} object"
- end
-
- component.each do |c|
- self.__send__("#{c}=", oth.__send__(c))
- end
- end
- private :replace!
-
- #
- # Components of the URI in the order.
- #
- def component
- self.class.component
- end
-
- #
- # check the scheme +v+ component against the URI::Parser Regexp for :SCHEME
- #
- def check_scheme(v)
- if v && parser.regexp[:SCHEME] !~ v
- raise InvalidComponentError,
- "bad component(expected scheme component): #{v}"
- end
-
- return true
- end
- private :check_scheme
-
- # protected setter for the scheme component +v+
- #
- # see also URI::Generic.scheme=
- #
- def set_scheme(v)
- @scheme = v ? v.downcase : v
- end
- protected :set_scheme
-
- #
- # == Args
- #
- # +v+::
- # String
- #
- # == Description
- #
- # public setter for the scheme component +v+.
- # (with validation)
- #
- # see also URI::Generic.check_scheme
- #
- # == Usage
- #
- # require 'uri'
- #
- # uri = URI.parse("http://my.example.com")
- # uri.scheme = "https"
- # # => "https"
- # uri
- # #=> #<URI::HTTP:0x000000008e89e8 URL:https://my.example.com>
- #
- def scheme=(v)
- check_scheme(v)
- set_scheme(v)
- v
- end
-
- #
- # check the +user+ and +password+.
- #
- # If +password+ is not provided, then +user+ is
- # split, using URI::Generic.split_userinfo, to
- # pull +user+ and +password.
- #
- # see also URI::Generic.check_user, URI::Generic.check_password
- #
- def check_userinfo(user, password = nil)
- if !password
- user, password = split_userinfo(user)
- end
- check_user(user)
- check_password(password, user)
-
- return true
- end
- private :check_userinfo
-
- #
- # check the user +v+ component for RFC2396 compliance
- # and against the URI::Parser Regexp for :USERINFO
- #
- # Can not have a registry or opaque component defined,
- # with a user component defined.
- #
- def check_user(v)
- if @opaque
- raise InvalidURIError,
- "can not set user with opaque"
- end
-
- return v unless v
-
- if parser.regexp[:USERINFO] !~ v
- raise InvalidComponentError,
- "bad component(expected userinfo component or user component): #{v}"
- end
-
- return true
- end
- private :check_user
-
- #
- # check the password +v+ component for RFC2396 compliance
- # and against the URI::Parser Regexp for :USERINFO
- #
- # Can not have a registry or opaque component defined,
- # with a user component defined.
- #
- def check_password(v, user = @user)
- if @opaque
- raise InvalidURIError,
- "can not set password with opaque"
- end
- return v unless v
-
- if !user
- raise InvalidURIError,
- "password component depends user component"
- end
-
- if parser.regexp[:USERINFO] !~ v
- raise InvalidComponentError,
- "bad password component"
- end
-
- return true
- end
- private :check_password
-
- #
- # Sets userinfo, argument is string like 'name:pass'
- #
- def userinfo=(userinfo)
- if userinfo.nil?
- return nil
- end
- check_userinfo(*userinfo)
- set_userinfo(*userinfo)
- # returns userinfo
- end
-
- #
- # == Args
- #
- # +v+::
- # String
- #
- # == Description
- #
- # public setter for the +user+ component.
- # (with validation)
- #
- # see also URI::Generic.check_user
- #
- # == Usage
- #
- # require 'uri'
- #
- # uri = URI.parse("http://john:S3nsit1ve@my.example.com")
- # uri.user = "sam"
- # # => "sam"
- # uri
- # #=> #<URI::HTTP:0x00000000881d90 URL:http://sam:V3ry_S3nsit1ve@my.example.com>
- #
- def user=(user)
- check_user(user)
- set_user(user)
- # returns user
- end
-
- #
- # == Args
- #
- # +v+::
- # String
- #
- # == Description
- #
- # public setter for the +password+ component.
- # (with validation)
- #
- # see also URI::Generic.check_password
- #
- # == Usage
- #
- # require 'uri'
- #
- # uri = URI.parse("http://john:S3nsit1ve@my.example.com")
- # uri.password = "V3ry_S3nsit1ve"
- # # => "V3ry_S3nsit1ve"
- # uri
- # #=> #<URI::HTTP:0x00000000881d90 URL:http://john:V3ry_S3nsit1ve@my.example.com>
- #
- def password=(password)
- check_password(password)
- set_password(password)
- # returns password
- end
-
- # protect setter for the +user+ component, and +password+ if available.
- # (with validation)
- #
- # see also URI::Generic.userinfo=
- #
- def set_userinfo(user, password = nil)
- unless password
- user, password = split_userinfo(user)
- end
- @user = user
- @password = password if password
-
- [@user, @password]
- end
- protected :set_userinfo
-
- # protected setter for the user component +v+
- #
- # see also URI::Generic.user=
- #
- def set_user(v)
- set_userinfo(v, @password)
- v
- end
- protected :set_user
-
- # protected setter for the password component +v+
- #
- # see also URI::Generic.password=
- #
- def set_password(v)
- @password = v
- # returns v
- end
- protected :set_password
-
- # returns the userinfo +ui+ as user, password
- # if properly formatted as 'user:password'
- def split_userinfo(ui)
- return nil, nil unless ui
- user, password = ui.split(':'.freeze, 2)
-
- return user, password
- end
- private :split_userinfo
-
- # escapes 'user:password' +v+ based on RFC 1738 section 3.1
- def escape_userpass(v)
- parser.escape(v, /[@:\/]/o) # RFC 1738 section 3.1 #/
- end
- private :escape_userpass
-
- # returns the userinfo, either as 'user' or 'user:password'
- def userinfo
- if @user.nil?
- nil
- elsif @password.nil?
- @user
- else
- @user + ':' + @password
- end
- end
-
- # returns the user component
- def user
- @user
- end
-
- # returns the password component
- def password
- @password
- end
-
- #
- # check the host +v+ component for RFC2396 compliance
- # and against the URI::Parser Regexp for :HOST
- #
- # Can not have a registry or opaque component defined,
- # with a host component defined.
- #
- def check_host(v)
- return v unless v
-
- if @opaque
- raise InvalidURIError,
- "can not set host with registry or opaque"
- elsif parser.regexp[:HOST] !~ v
- raise InvalidComponentError,
- "bad component(expected host component): #{v}"
- end
-
- return true
- end
- private :check_host
-
- # protected setter for the host component +v+
- #
- # see also URI::Generic.host=
- #
- def set_host(v)
- @host = v
- end
- protected :set_host
-
- #
- # == Args
- #
- # +v+::
- # String
- #
- # == Description
- #
- # public setter for the host component +v+.
- # (with validation)
- #
- # see also URI::Generic.check_host
- #
- # == Usage
- #
- # require 'uri'
- #
- # uri = URI.parse("http://my.example.com")
- # uri.host = "foo.com"
- # # => "foo.com"
- # uri
- # #=> #<URI::HTTP:0x000000008e89e8 URL:http://foo.com>
- #
- def host=(v)
- check_host(v)
- set_host(v)
- v
- end
-
- # extract the host part of the URI and unwrap brackets for IPv6 addresses.
- #
- # This method is same as URI::Generic#host except
- # brackets for IPv6 (and future IP) addresses are removed.
- #
- # u = URI("http://[::1]/bar")
- # p u.hostname #=> "::1"
- # p u.host #=> "[::1]"
- #
- def hostname
- v = self.host
- /\A\[(.*)\]\z/ =~ v ? $1 : v
- end
-
- # set the host part of the URI as the argument with brackets for IPv6 addresses.
- #
- # This method is same as URI::Generic#host= except
- # the argument can be bare IPv6 address.
- #
- # u = URI("http://foo/bar")
- # p u.to_s #=> "http://foo/bar"
- # u.hostname = "::1"
- # p u.to_s #=> "http://[::1]/bar"
- #
- # If the argument seems IPv6 address,
- # it is wrapped by brackets.
- #
- def hostname=(v)
- v = "[#{v}]" if /\A\[.*\]\z/ !~ v && /:/ =~ v
- self.host = v
- end
-
- #
- # check the port +v+ component for RFC2396 compliance
- # and against the URI::Parser Regexp for :PORT
- #
- # Can not have a registry or opaque component defined,
- # with a port component defined.
- #
- def check_port(v)
- return v unless v
-
- if @opaque
- raise InvalidURIError,
- "can not set port with registry or opaque"
- elsif !v.kind_of?(Fixnum) && parser.regexp[:PORT] !~ v
- raise InvalidComponentError,
- "bad component(expected port component): #{v.inspect}"
- end
-
- return true
- end
- private :check_port
-
- # protected setter for the port component +v+
- #
- # see also URI::Generic.port=
- #
- def set_port(v)
- v = v.empty? ? nil : v.to_i unless !v || v.kind_of?(Fixnum)
- @port = v
- end
- protected :set_port
-
- #
- # == Args
- #
- # +v+::
- # String
- #
- # == Description
- #
- # public setter for the port component +v+.
- # (with validation)
- #
- # see also URI::Generic.check_port
- #
- # == Usage
- #
- # require 'uri'
- #
- # uri = URI.parse("http://my.example.com")
- # uri.port = 8080
- # # => 8080
- # uri
- # #=> #<URI::HTTP:0x000000008e89e8 URL:http://my.example.com:8080>
- #
- def port=(v)
- check_port(v)
- set_port(v)
- port
- end
-
- def check_registry(v) # :nodoc:
- raise InvalidURIError, "can not set registry"
- end
- private :check_registry
-
- def set_registry(v) #:nodoc:
- raise InvalidURIError, "can not set registry"
- end
- protected :set_registry
-
- def registry=(v)
- raise InvalidURIError, "can not set registry"
- end
-
- #
- # check the path +v+ component for RFC2396 compliance
- # and against the URI::Parser Regexp
- # for :ABS_PATH and :REL_PATH
- #
- # Can not have a opaque component defined,
- # with a path component defined.
- #
- def check_path(v)
- # raise if both hier and opaque are not nil, because:
- # absoluteURI = scheme ":" ( hier_part | opaque_part )
- # hier_part = ( net_path | abs_path ) [ "?" query ]
- if v && @opaque
- raise InvalidURIError,
- "path conflicts with opaque"
- end
-
- # If scheme is ftp, path may be relative.
- # See RFC 1738 section 3.2.2, and RFC 2396.
- if @scheme && @scheme != "ftp".freeze
- if v && v != ''.freeze && parser.regexp[:ABS_PATH] !~ v
- raise InvalidComponentError,
- "bad component(expected absolute path component): #{v}"
- end
- else
- if v && v != ''.freeze && parser.regexp[:ABS_PATH] !~ v &&
- parser.regexp[:REL_PATH] !~ v
- raise InvalidComponentError,
- "bad component(expected relative path component): #{v}"
- end
- end
-
- return true
- end
- private :check_path
-
- # protected setter for the path component +v+
- #
- # see also URI::Generic.path=
- #
- def set_path(v)
- @path = v
- end
- protected :set_path
-
- #
- # == Args
- #
- # +v+::
- # String
- #
- # == Description
- #
- # public setter for the path component +v+.
- # (with validation)
- #
- # see also URI::Generic.check_path
- #
- # == Usage
- #
- # require 'uri'
- #
- # uri = URI.parse("http://my.example.com/pub/files")
- # uri.path = "/faq/"
- # # => "/faq/"
- # uri
- # #=> #<URI::HTTP:0x000000008e89e8 URL:http://my.example.com/faq/>
- #
- def path=(v)
- check_path(v)
- set_path(v)
- v
- end
-
- #
- # == Args
- #
- # +v+::
- # String
- #
- # == Description
- #
- # public setter for the query component +v+.
- #
- # == Usage
- #
- # require 'uri'
- #
- # uri = URI.parse("http://my.example.com/?id=25")
- # uri.query = "id=1"
- # # => "id=1"
- # uri
- # #=> #<URI::HTTP:0x000000008e89e8 URL:http://my.example.com/?id=1>
- #
- def query=(v)
- return @query = nil unless v
- raise InvalidURIError, "query conflicts with opaque" if @opaque
-
- x = v.to_str
- v = x.dup if x.equal? v
- v.encode!(Encoding::UTF_8) rescue nil
- v.delete!("\t\r\n".freeze)
- v.force_encoding(Encoding::ASCII_8BIT)
- v.gsub!(/(?!%\h\h|[!$-&(-;=?-_a-~])./n.freeze){'%%%02X'.freeze % $&.ord}
- v.force_encoding(Encoding::US_ASCII)
- @query = v
- end
-
- #
- # check the opaque +v+ component for RFC2396 compliance and
- # against the URI::Parser Regexp for :OPAQUE
- #
- # Can not have a host, port, user or path component defined,
- # with an opaque component defined.
- #
- def check_opaque(v)
- return v unless v
-
- # raise if both hier and opaque are not nil, because:
- # absoluteURI = scheme ":" ( hier_part | opaque_part )
- # hier_part = ( net_path | abs_path ) [ "?" query ]
- if @host || @port || @user || @path # userinfo = @user + ':' + @password
- raise InvalidURIError,
- "can not set opaque with host, port, userinfo or path"
- elsif v && parser.regexp[:OPAQUE] !~ v
- raise InvalidComponentError,
- "bad component(expected opaque component): #{v}"
- end
-
- return true
- end
- private :check_opaque
-
- # protected setter for the opaque component +v+
- #
- # see also URI::Generic.opaque=
- #
- def set_opaque(v)
- @opaque = v
- end
- protected :set_opaque
-
- #
- # == Args
- #
- # +v+::
- # String
- #
- # == Description
- #
- # public setter for the opaque component +v+.
- # (with validation)
- #
- # see also URI::Generic.check_opaque
- #
- def opaque=(v)
- check_opaque(v)
- set_opaque(v)
- v
- end
-
- #
- # check the fragment +v+ component against the URI::Parser Regexp for :FRAGMENT
- #
- #
- # == Args
- #
- # +v+::
- # String
- #
- # == Description
- #
- # public setter for the fragment component +v+.
- # (with validation)
- #
- # == Usage
- #
- # require 'uri'
- #
- # uri = URI.parse("http://my.example.com/?id=25#time=1305212049")
- # uri.fragment = "time=1305212086"
- # # => "time=1305212086"
- # uri
- # #=> #<URI::HTTP:0x000000007a81f8 URL:http://my.example.com/?id=25#time=1305212086>
- #
- def fragment=(v)
- return @fragment = nil unless v
-
- x = v.to_str
- v = x.dup if x.equal? v
- v.encode!(Encoding::UTF_8) rescue nil
- v.delete!("\t\r\n".freeze)
- v.force_encoding(Encoding::ASCII_8BIT)
- v.gsub!(/(?!%\h\h|[!-~])./n){'%%%02X'.freeze % $&.ord}
- v.force_encoding(Encoding::US_ASCII)
- @fragment = v
- end
-
- #
- # Checks if URI has a path
- #
- def hierarchical?
- if @path
- true
- else
- false
- end
- end
-
- #
- # Checks if URI is an absolute one
- #
- def absolute?
- if @scheme
- true
- else
- false
- end
- end
- alias absolute absolute?
-
- #
- # Checks if URI is relative
- #
- def relative?
- !absolute?
- end
-
- #
- # returns an Array of the path split on '/'
- #
- def split_path(path)
- path.split(%r{/+}, -1)
- end
- private :split_path
-
- #
- # Merges a base path +base+, with relative path +rel+,
- # returns a modified base path.
- #
- def merge_path(base, rel)
-
- # RFC2396, Section 5.2, 5)
- # RFC2396, Section 5.2, 6)
- base_path = split_path(base)
- rel_path = split_path(rel)
-
- # RFC2396, Section 5.2, 6), a)
- base_path << '' if base_path.last == '..'
- while i = base_path.index('..')
- base_path.slice!(i - 1, 2)
- end
-
- if (first = rel_path.first) and first.empty?
- base_path.clear
- rel_path.shift
- end
-
- # RFC2396, Section 5.2, 6), c)
- # RFC2396, Section 5.2, 6), d)
- rel_path.push('') if rel_path.last == '.' || rel_path.last == '..'
- rel_path.delete('.')
-
- # RFC2396, Section 5.2, 6), e)
- tmp = []
- rel_path.each do |x|
- if x == '..' &&
- !(tmp.empty? || tmp.last == '..')
- tmp.pop
- else
- tmp << x
- end
- end
-
- add_trailer_slash = !tmp.empty?
- if base_path.empty?
- base_path = [''] # keep '/' for root directory
- elsif add_trailer_slash
- base_path.pop
- end
- while x = tmp.shift
- if x == '..'
- # RFC2396, Section 4
- # a .. or . in an absolute path has no special meaning
- base_path.pop if base_path.size > 1
- else
- # if x == '..'
- # valid absolute (but abnormal) path "/../..."
- # else
- # valid absolute path
- # end
- base_path << x
- tmp.each {|t| base_path << t}
- add_trailer_slash = false
- break
- end
- end
- base_path.push('') if add_trailer_slash
-
- return base_path.join('/')
- end
- private :merge_path
-
- #
- # == Args
- #
- # +oth+::
- # URI or String
- #
- # == Description
- #
- # Destructive form of #merge
- #
- # == Usage
- #
- # require 'uri'
- #
- # uri = URI.parse("http://my.example.com")
- # uri.merge!("/main.rbx?page=1")
- # p uri
- # # => #<URI::HTTP:0x2021f3b0 URL:http://my.example.com/main.rbx?page=1>
- #
- def merge!(oth)
- t = merge(oth)
- if self == t
- nil
- else
- replace!(t)
- self
- end
- end
-
- #
- # == Args
- #
- # +oth+::
- # URI or String
- #
- # == Description
- #
- # Merges two URI's.
- #
- # == Usage
- #
- # require 'uri'
- #
- # uri = URI.parse("http://my.example.com")
- # p uri.merge("/main.rbx?page=1")
- # # => #<URI::HTTP:0x2021f3b0 URL:http://my.example.com/main.rbx?page=1>
- #
- def merge(oth)
- begin
- base, rel = merge0(oth)
- rescue
- raise $!.class, $!.message
- end
-
- if base == rel
- return base
- end
-
- authority = rel.userinfo || rel.host || rel.port
-
- # RFC2396, Section 5.2, 2)
- if (rel.path.nil? || rel.path.empty?) && !authority && !rel.query
- base.fragment=(rel.fragment) if rel.fragment
- return base
- end
-
- base.query = nil
- base.fragment=(nil)
-
- # RFC2396, Section 5.2, 4)
- if !authority
- base.set_path(merge_path(base.path, rel.path)) if base.path && rel.path
- else
- # RFC2396, Section 5.2, 4)
- base.set_path(rel.path) if rel.path
- end
-
- # RFC2396, Section 5.2, 7)
- base.set_userinfo(rel.userinfo) if rel.userinfo
- base.set_host(rel.host) if rel.host
- base.set_port(rel.port) if rel.port
- base.query = rel.query if rel.query
- base.fragment=(rel.fragment) if rel.fragment
-
- return base
- end # merge
- alias + merge
-
- # return base and rel.
- # you can modify `base', but can not `rel'.
- def merge0(oth)
- oth = parser.send(:convert_to_uri, oth)
-
- if self.relative? && oth.relative?
- raise BadURIError,
- "both URI are relative"
- end
-
- if self.absolute? && oth.absolute?
- #raise BadURIError,
- # "both URI are absolute"
- # hmm... should return oth for usability?
- return oth, oth
- end
-
- if self.absolute?
- return self.dup, oth
- else
- return oth, oth
- end
- end
- private :merge0
-
- # :stopdoc:
- def route_from_path(src, dst)
- case dst
- when src
- # RFC2396, Section 4.2
- return ''
- when %r{(?:\A|/)\.\.?(?:/|\z)}
- # dst has abnormal absolute path,
- # like "/./", "/../", "/x/../", ...
- return dst.dup
- end
-
- src_path = src.scan(%r{(?:\A|[^/]+)/})
- dst_path = dst.scan(%r{(?:\A|[^/]+)/?})
-
- # discard same parts
- while !dst_path.empty? && dst_path.first == src_path.first
- src_path.shift
- dst_path.shift
- end
-
- tmp = dst_path.join
-
- # calculate
- if src_path.empty?
- if tmp.empty?
- return './'
- elsif dst_path.first.include?(':') # (see RFC2396 Section 5)
- return './' + tmp
- else
- return tmp
- end
- end
-
- return '../' * src_path.size + tmp
- end
- private :route_from_path
- # :startdoc:
-
- # :stopdoc:
- def route_from0(oth)
- oth = parser.send(:convert_to_uri, oth)
- if self.relative?
- raise BadURIError,
- "relative URI: #{self}"
- end
- if oth.relative?
- raise BadURIError,
- "relative URI: #{oth}"
- end
-
- if self.scheme != oth.scheme
- return self, self.dup
- end
- rel = URI::Generic.new(nil, # it is relative URI
- self.userinfo, self.host, self.port,
- nil, self.path, self.opaque,
- self.query, self.fragment, parser)
-
- if rel.userinfo != oth.userinfo ||
- rel.host.to_s.downcase != oth.host.to_s.downcase ||
- rel.port != oth.port
-
- if self.userinfo.nil? && self.host.nil?
- return self, self.dup
- end
-
- rel.set_port(nil) if rel.port == oth.default_port
- return rel, rel
- end
- rel.set_userinfo(nil)
- rel.set_host(nil)
- rel.set_port(nil)
-
- if rel.path && rel.path == oth.path
- rel.set_path('')
- rel.query = nil if rel.query == oth.query
- return rel, rel
- elsif rel.opaque && rel.opaque == oth.opaque
- rel.set_opaque('')
- rel.query = nil if rel.query == oth.query
- return rel, rel
- end
-
- # you can modify `rel', but can not `oth'.
- return oth, rel
- end
- private :route_from0
- # :startdoc:
-
- #
- # == Args
- #
- # +oth+::
- # URI or String
- #
- # == Description
- #
- # Calculates relative path from oth to self
- #
- # == Usage
- #
- # require 'uri'
- #
- # uri = URI.parse('http://my.example.com/main.rbx?page=1')
- # p uri.route_from('http://my.example.com')
- # #=> #<URI::Generic:0x20218858 URL:/main.rbx?page=1>
- #
- def route_from(oth)
- # you can modify `rel', but can not `oth'.
- begin
- oth, rel = route_from0(oth)
- rescue
- raise $!.class, $!.message
- end
- if oth == rel
- return rel
- end
-
- rel.set_path(route_from_path(oth.path, self.path))
- if rel.path == './' && self.query
- # "./?foo" -> "?foo"
- rel.set_path('')
- end
-
- return rel
- end
-
- alias - route_from
-
- #
- # == Args
- #
- # +oth+::
- # URI or String
- #
- # == Description
- #
- # Calculates relative path to oth from self
- #
- # == Usage
- #
- # require 'uri'
- #
- # uri = URI.parse('http://my.example.com')
- # p uri.route_to('http://my.example.com/main.rbx?page=1')
- # #=> #<URI::Generic:0x2020c2f6 URL:/main.rbx?page=1>
- #
- def route_to(oth)
- parser.send(:convert_to_uri, oth).route_from(self)
- end
-
- #
- # Returns normalized URI
- #
- def normalize
- uri = dup
- uri.normalize!
- uri
- end
-
- #
- # Destructive version of #normalize
- #
- def normalize!
- if path && path.empty?
- set_path('/')
- end
- if scheme && scheme != scheme.downcase
- set_scheme(self.scheme.downcase)
- end
- if host && host != host.downcase
- set_host(self.host.downcase)
- end
- end
-
- #
- # Constructs String from URI
- #
- def to_s
- str = ''
- if @scheme
- str << @scheme
- str << ':'.freeze
- end
-
- if @opaque
- str << @opaque
- else
- if @host
- str << '//'.freeze
- end
- if self.userinfo
- str << self.userinfo
- str << '@'.freeze
- end
- if @host
- str << @host
- end
- if @port && @port != self.default_port
- str << ':'.freeze
- str << @port.to_s
- end
- str << @path
- if @query
- str << '?'.freeze
- str << @query
- end
- end
- if @fragment
- str << '#'.freeze
- str << @fragment
- end
- str
- end
-
- #
- # Compares to URI's
- #
- def ==(oth)
- if self.class == oth.class
- self.normalize.component_ary == oth.normalize.component_ary
- else
- false
- end
- end
-
- def hash
- self.component_ary.hash
- end
-
- def eql?(oth)
- self.class == oth.class &&
- parser == oth.parser &&
- self.component_ary.eql?(oth.component_ary)
- end
-
-=begin
-
---- URI::Generic#===(oth)
-
-=end
-# def ===(oth)
-# raise NotImplementedError
-# end
-
-=begin
-=end
-
-
- # returns an Array of the components defined from the COMPONENT Array
- def component_ary
- component.collect do |x|
- self.send(x)
- end
- end
- protected :component_ary
-
- # == Args
- #
- # +components+::
- # Multiple Symbol arguments defined in URI::HTTP
- #
- # == Description
- #
- # Selects specified components from URI
- #
- # == Usage
- #
- # require 'uri'
- #
- # uri = URI.parse('http://myuser:mypass@my.example.com/test.rbx')
- # p uri.select(:userinfo, :host, :path)
- # # => ["myuser:mypass", "my.example.com", "/test.rbx"]
- #
- def select(*components)
- components.collect do |c|
- if component.include?(c)
- self.send(c)
- else
- raise ArgumentError,
- "expected of components of #{self.class} (#{self.class.component.join(', ')})"
- end
- end
- end
-
- def inspect
- "#<#{self.class} #{self}>"
- end
-
- #
- # == Args
- #
- # +v+::
- # URI or String
- #
- # == Description
- #
- # attempt to parse other URI +oth+
- # return [parsed_oth, self]
- #
- # == Usage
- #
- # require 'uri'
- #
- # uri = URI.parse("http://my.example.com")
- # uri.coerce("http://foo.com")
- # #=> [#<URI::HTTP:0x00000000bcb028 URL:http://foo.com/>, #<URI::HTTP:0x00000000d92178 URL:http://my.example.com>]
- #
- def coerce(oth)
- case oth
- when String
- oth = parser.parse(oth)
- else
- super
- end
-
- return oth, self
- end
-
- # returns a proxy URI.
- # The proxy URI is obtained from environment variables such as http_proxy,
- # ftp_proxy, no_proxy, etc.
- # If there is no proper proxy, nil is returned.
- #
- # Note that capitalized variables (HTTP_PROXY, FTP_PROXY, NO_PROXY, etc.)
- # are examined too.
- #
- # But http_proxy and HTTP_PROXY is treated specially under CGI environment.
- # It's because HTTP_PROXY may be set by Proxy: header.
- # So HTTP_PROXY is not used.
- # http_proxy is not used too if the variable is case insensitive.
- # CGI_HTTP_PROXY can be used instead.
- def find_proxy
- raise BadURIError, "relative URI: #{self}" if self.relative?
- name = self.scheme.downcase + '_proxy'
- proxy_uri = nil
- if name == 'http_proxy' && ENV.include?('REQUEST_METHOD') # CGI?
- # HTTP_PROXY conflicts with *_proxy for proxy settings and
- # HTTP_* for header information in CGI.
- # So it should be careful to use it.
- pairs = ENV.reject {|k, v| /\Ahttp_proxy\z/i !~ k }
- case pairs.length
- when 0 # no proxy setting anyway.
- proxy_uri = nil
- when 1
- k, _ = pairs.shift
- if k == 'http_proxy' && ENV[k.upcase] == nil
- # http_proxy is safe to use because ENV is case sensitive.
- proxy_uri = ENV[name]
- else
- proxy_uri = nil
- end
- else # http_proxy is safe to use because ENV is case sensitive.
- proxy_uri = ENV.to_hash[name]
- end
- if !proxy_uri
- # Use CGI_HTTP_PROXY. cf. libwww-perl.
- proxy_uri = ENV["CGI_#{name.upcase}"]
- end
- elsif name == 'http_proxy'
- unless proxy_uri = ENV[name]
- if proxy_uri = ENV[name.upcase]
- warn 'The environment variable HTTP_PROXY is discouraged. Use http_proxy.'
- end
- end
- else
- proxy_uri = ENV[name] || ENV[name.upcase]
- end
-
- if proxy_uri.nil? || proxy_uri.empty?
- return nil
- end
-
- if self.hostname
- require 'socket'
- begin
- addr = IPSocket.getaddress(self.hostname)
- return nil if /\A127\.|\A::1\z/ =~ addr
- rescue SocketError
- end
- end
-
- name = 'no_proxy'
- if no_proxy = ENV[name] || ENV[name.upcase]
- no_proxy.scan(/([^:,]*)(?::(\d+))?/) {|host, port|
- if /(\A|\.)#{Regexp.quote host}\z/i =~ self.host &&
- (!port || self.port == port.to_i)
- return nil
- end
- }
- end
- URI.parse(proxy_uri)
- end
- end
-end
diff --git a/ruby_2_2/lib/uri/http.rb b/ruby_2_2/lib/uri/http.rb
deleted file mode 100644
index 56d29f3432..0000000000
--- a/ruby_2_2/lib/uri/http.rb
+++ /dev/null
@@ -1,108 +0,0 @@
-# = uri/http.rb
-#
-# Author:: Akira Yamada <akira@ruby-lang.org>
-# License:: You can redistribute it and/or modify it under the same term as Ruby.
-# Revision:: $Id$
-#
-# See URI for general documentation
-#
-
-require 'uri/generic'
-
-module URI
-
- #
- # The syntax of HTTP URIs is defined in RFC1738 section 3.3.
- #
- # Note that the Ruby URI library allows HTTP URLs containing usernames and
- # passwords. This is not legal as per the RFC, but used to be
- # supported in Internet Explorer 5 and 6, before the MS04-004 security
- # update. See <URL:http://support.microsoft.com/kb/834489>.
- #
- class HTTP < Generic
- # A Default port of 80 for URI::HTTP
- DEFAULT_PORT = 80
-
- # An Array of the available components for URI::HTTP
- COMPONENT = [
- :scheme,
- :userinfo, :host, :port,
- :path,
- :query,
- :fragment
- ].freeze
-
- #
- # == Description
- #
- # Create a new URI::HTTP object from components, with syntax checking.
- #
- # The components accepted are userinfo, host, port, path, query and
- # fragment.
- #
- # The components should be provided either as an Array, or as a Hash
- # with keys formed by preceding the component names with a colon.
- #
- # If an Array is used, the components must be passed in the order
- # [userinfo, host, port, path, query, fragment].
- #
- # Example:
- #
- # newuri = URI::HTTP.build({:host => 'www.example.com',
- # :path => '/foo/bar'})
- #
- # newuri = URI::HTTP.build([nil, "www.example.com", nil, "/path",
- # "query", 'fragment'])
- #
- # Currently, if passed userinfo components this method generates
- # invalid HTTP URIs as per RFC 1738.
- #
- def self.build(args)
- tmp = Util::make_components_hash(self, args)
- return super(tmp)
- end
-
-=begin
- #
- # == Description
- #
- # Create a new URI::HTTP object from generic URI components as per
- # RFC 2396. No HTTP-specific syntax checking (as per RFC 1738) is
- # performed.
- #
- # Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
- # +opaque+, +query+ and +fragment+, in that order.
- #
- # Example:
- #
- # uri = URI::HTTP.new("http", nil, "www.example.com", nil, nil,
- # "/path", nil, "query", "fragment")
- #
- #
- # See also URI::Generic.new
- #
- def initialize(*arg)
- super(*arg)
- end
-=end
-
- #
- # == Description
- #
- # Returns the full path for an HTTP request, as required by Net::HTTP::Get.
- #
- # If the URI contains a query, the full path is URI#path + '?' + URI#query.
- # Otherwise, the path is simply URI#path.
- #
- def request_uri
- return nil unless @path
- if @path.start_with?(?/.freeze)
- @query ? "#@path?#@query" : @path.dup
- else
- @query ? "/#@path?#@query" : "/#@path"
- end
- end
- end
-
- @@schemes['HTTP'] = HTTP
-end
diff --git a/ruby_2_2/lib/uri/https.rb b/ruby_2_2/lib/uri/https.rb
deleted file mode 100644
index 7d242e7e79..0000000000
--- a/ruby_2_2/lib/uri/https.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# = uri/https.rb
-#
-# Author:: Akira Yamada <akira@ruby-lang.org>
-# License:: You can redistribute it and/or modify it under the same term as Ruby.
-# Revision:: $Id$
-#
-# See URI for general documentation
-#
-
-require 'uri/http'
-
-module URI
-
- # The default port for HTTPS URIs is 443, and the scheme is 'https:' rather
- # than 'http:'. Other than that, HTTPS URIs are identical to HTTP URIs;
- # see URI::HTTP.
- class HTTPS < HTTP
- # A Default port of 443 for URI::HTTPS
- DEFAULT_PORT = 443
- end
- @@schemes['HTTPS'] = HTTPS
-end
diff --git a/ruby_2_2/lib/uri/ldap.rb b/ruby_2_2/lib/uri/ldap.rb
deleted file mode 100644
index 56d748e59e..0000000000
--- a/ruby_2_2/lib/uri/ldap.rb
+++ /dev/null
@@ -1,260 +0,0 @@
-# = uri/ldap.rb
-#
-# Author::
-# Takaaki Tateishi <ttate@jaist.ac.jp>
-# Akira Yamada <akira@ruby-lang.org>
-# License::
-# URI::LDAP is copyrighted free software by Takaaki Tateishi and Akira Yamada.
-# You can redistribute it and/or modify it under the same term as Ruby.
-# Revision:: $Id$
-#
-# See URI for general documentation
-#
-
-require 'uri/generic'
-
-module URI
-
- #
- # LDAP URI SCHEMA (described in RFC2255)
- # ldap://<host>/<dn>[?<attrs>[?<scope>[?<filter>[?<extensions>]]]]
- #
- class LDAP < Generic
-
- # A Default port of 389 for URI::LDAP
- DEFAULT_PORT = 389
-
- # An Array of the available components for URI::LDAP
- COMPONENT = [
- :scheme,
- :host, :port,
- :dn,
- :attributes,
- :scope,
- :filter,
- :extensions,
- ].freeze
-
- # Scopes available for the starting point.
- #
- # * SCOPE_BASE - the Base DN
- # * SCOPE_ONE - one level under the Base DN, not including the base DN and
- # not including any entries under this.
- # * SCOPE_SUB - subtress, all entries at all levels
- #
- SCOPE = [
- SCOPE_ONE = 'one',
- SCOPE_SUB = 'sub',
- SCOPE_BASE = 'base',
- ].freeze
-
- #
- # == Description
- #
- # Create a new URI::LDAP object from components, with syntax checking.
- #
- # The components accepted are host, port, dn, attributes,
- # scope, filter, and extensions.
- #
- # The components should be provided either as an Array, or as a Hash
- # with keys formed by preceding the component names with a colon.
- #
- # If an Array is used, the components must be passed in the order
- # [host, port, dn, attributes, scope, filter, extensions].
- #
- # Example:
- #
- # newuri = URI::LDAP.build({:host => 'ldap.example.com',
- # :dn> => '/dc=example'})
- #
- # newuri = URI::LDAP.build(["ldap.example.com", nil,
- # "/dc=example;dc=com", "query", nil, nil, nil])
- #
- def self.build(args)
- tmp = Util::make_components_hash(self, args)
-
- if tmp[:dn]
- tmp[:path] = tmp[:dn]
- end
-
- query = []
- [:extensions, :filter, :scope, :attributes].collect do |x|
- next if !tmp[x] && query.size == 0
- query.unshift(tmp[x])
- end
-
- tmp[:query] = query.join('?')
-
- return super(tmp)
- end
-
- #
- # == Description
- #
- # Create a new URI::LDAP object from generic URI components as per
- # RFC 2396. No LDAP-specific syntax checking is performed.
- #
- # Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
- # +opaque+, +query+ and +fragment+, in that order.
- #
- # Example:
- #
- # uri = URI::LDAP.new("ldap", nil, "ldap.example.com", nil,
- # "/dc=example;dc=com", "query", nil, nil, nil, nil)
- #
- #
- # See also URI::Generic.new
- #
- def initialize(*arg)
- super(*arg)
-
- if @fragment
- raise InvalidURIError, 'bad LDAP URL'
- end
-
- parse_dn
- parse_query
- end
-
- # private method to cleanup +dn+ from using the +path+ component attribute
- def parse_dn
- @dn = @path[1..-1]
- end
- private :parse_dn
-
- # private method to cleanup +attributes+, +scope+, +filter+ and +extensions+,
- # from using the +query+ component attribute
- def parse_query
- @attributes = nil
- @scope = nil
- @filter = nil
- @extensions = nil
-
- if @query
- attrs, scope, filter, extensions = @query.split('?')
-
- @attributes = attrs if attrs && attrs.size > 0
- @scope = scope if scope && scope.size > 0
- @filter = filter if filter && filter.size > 0
- @extensions = extensions if extensions && extensions.size > 0
- end
- end
- private :parse_query
-
- # private method to assemble +query+ from +attributes+, +scope+, +filter+ and +extensions+.
- def build_path_query
- @path = '/' + @dn
-
- query = []
- [@extensions, @filter, @scope, @attributes].each do |x|
- next if !x && query.size == 0
- query.unshift(x)
- end
- @query = query.join('?')
- end
- private :build_path_query
-
- # returns dn.
- def dn
- @dn
- end
-
- # private setter for dn +val+
- def set_dn(val)
- @dn = val
- build_path_query
- @dn
- end
- protected :set_dn
-
- # setter for dn +val+
- def dn=(val)
- set_dn(val)
- val
- end
-
- # returns attributes.
- def attributes
- @attributes
- end
-
- # private setter for attributes +val+
- def set_attributes(val)
- @attributes = val
- build_path_query
- @attributes
- end
- protected :set_attributes
-
- # setter for attributes +val+
- def attributes=(val)
- set_attributes(val)
- val
- end
-
- # returns scope.
- def scope
- @scope
- end
-
- # private setter for scope +val+
- def set_scope(val)
- @scope = val
- build_path_query
- @scope
- end
- protected :set_scope
-
- # setter for scope +val+
- def scope=(val)
- set_scope(val)
- val
- end
-
- # returns filter.
- def filter
- @filter
- end
-
- # private setter for filter +val+
- def set_filter(val)
- @filter = val
- build_path_query
- @filter
- end
- protected :set_filter
-
- # setter for filter +val+
- def filter=(val)
- set_filter(val)
- val
- end
-
- # returns extensions.
- def extensions
- @extensions
- end
-
- # private setter for extensions +val+
- def set_extensions(val)
- @extensions = val
- build_path_query
- @extensions
- end
- protected :set_extensions
-
- # setter for extensions +val+
- def extensions=(val)
- set_extensions(val)
- val
- end
-
- # Checks if URI has a path
- # For URI::LDAP this will return +false+
- def hierarchical?
- false
- end
- end
-
- @@schemes['LDAP'] = LDAP
-end
diff --git a/ruby_2_2/lib/uri/ldaps.rb b/ruby_2_2/lib/uri/ldaps.rb
deleted file mode 100644
index 42bbfe86ba..0000000000
--- a/ruby_2_2/lib/uri/ldaps.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# = uri/ldap.rb
-#
-# License:: You can redistribute it and/or modify it under the same term as Ruby.
-#
-# See URI for general documentation
-#
-
-require 'uri/ldap'
-
-module URI
-
- # The default port for LDAPS URIs is 636, and the scheme is 'ldaps:' rather
- # than 'ldap:'. Other than that, LDAPS URIs are identical to LDAP URIs;
- # see URI::LDAP.
- class LDAPS < LDAP
- # A Default port of 636 for URI::LDAPS
- DEFAULT_PORT = 636
- end
- @@schemes['LDAPS'] = LDAPS
-end
diff --git a/ruby_2_2/lib/uri/mailto.rb b/ruby_2_2/lib/uri/mailto.rb
deleted file mode 100644
index 282dcbe404..0000000000
--- a/ruby_2_2/lib/uri/mailto.rb
+++ /dev/null
@@ -1,293 +0,0 @@
-# = uri/mailto.rb
-#
-# Author:: Akira Yamada <akira@ruby-lang.org>
-# License:: You can redistribute it and/or modify it under the same term as Ruby.
-# Revision:: $Id$
-#
-# See URI for general documentation
-#
-
-require 'uri/generic'
-
-module URI
-
- #
- # RFC6068, The mailto URL scheme
- #
- class MailTo < Generic
- include REGEXP
-
- # A Default port of nil for URI::MailTo
- DEFAULT_PORT = nil
-
- # An Array of the available components for URI::MailTo
- COMPONENT = [ :scheme, :to, :headers ].freeze
-
- # :stopdoc:
- # "hname" and "hvalue" are encodings of an RFC 822 header name and
- # value, respectively. As with "to", all URL reserved characters must
- # be encoded.
- #
- # "#mailbox" is as specified in RFC 822 [RFC822]. This means that it
- # consists of zero or more comma-separated mail addresses, possibly
- # including "phrase" and "comment" components. Note that all URL
- # reserved characters in "to" must be encoded: in particular,
- # parentheses, commas, and the percent sign ("%"), which commonly occur
- # in the "mailbox" syntax.
- #
- # Within mailto URLs, the characters "?", "=", "&" are reserved.
-
- # ; RFC 6068
- # hfields = "?" hfield *( "&" hfield )
- # hfield = hfname "=" hfvalue
- # hfname = *qchar
- # hfvalue = *qchar
- # qchar = unreserved / pct-encoded / some-delims
- # some-delims = "!" / "$" / "'" / "(" / ")" / "*"
- # / "+" / "," / ";" / ":" / "@"
- #
- # ; RFC3986
- # unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
- # pct-encoded = "%" HEXDIG HEXDIG
- HEADER_REGEXP = /\A(?<hfield>(?:%\h\h|[!$'-.0-;@-Z_a-z~])*=(?:%\h\h|[!$'-.0-;@-Z_a-z~])*)(?:&\g<hfield>)*\z/
- # practical regexp for email address
- # http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#valid-e-mail-address
- EMAIL_REGEXP = /\A[a-zA-Z0-9.!\#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\z/
- # :startdoc:
-
- #
- # == Description
- #
- # Creates a new URI::MailTo object from components, with syntax checking.
- #
- # Components can be provided as an Array or Hash. If an Array is used,
- # the components must be supplied as [to, headers].
- #
- # If a Hash is used, the keys are the component names preceded by colons.
- #
- # The headers can be supplied as a pre-encoded string, such as
- # "subject=subscribe&cc=address", or as an Array of Arrays like
- # [['subject', 'subscribe'], ['cc', 'address']]
- #
- # Examples:
- #
- # require 'uri'
- #
- # m1 = URI::MailTo.build(['joe@example.com', 'subject=Ruby'])
- # puts m1.to_s -> mailto:joe@example.com?subject=Ruby
- #
- # m2 = URI::MailTo.build(['john@example.com', [['Subject', 'Ruby'], ['Cc', 'jack@example.com']]])
- # puts m2.to_s -> mailto:john@example.com?Subject=Ruby&Cc=jack@example.com
- #
- # m3 = URI::MailTo.build({:to => 'listman@example.com', :headers => [['subject', 'subscribe']]})
- # puts m3.to_s -> mailto:listman@example.com?subject=subscribe
- #
- def self.build(args)
- tmp = Util::make_components_hash(self, args)
-
- case tmp[:to]
- when Array
- tmp[:opaque] = tmp[:to].join(',')
- when String
- tmp[:opaque] = tmp[:to].dup
- else
- tmp[:opaque] = ''
- end
-
- if tmp[:headers]
- query =
- case tmp[:headers]
- when Array
- tmp[:headers].collect { |x|
- if x.kind_of?(Array)
- x[0] + '=' + x[1..-1].join
- else
- x.to_s
- end
- }.join('&')
- when Hash
- tmp[:headers].collect { |h,v|
- h + '=' + v
- }.join('&')
- else
- tmp[:headers].to_s
- end
- unless query.empty?
- tmp[:opaque] << '?' << query
- end
- end
-
- return super(tmp)
- end
-
- #
- # == Description
- #
- # Creates a new URI::MailTo object from generic URL components with
- # no syntax checking.
- #
- # This method is usually called from URI::parse, which checks
- # the validity of each component.
- #
- def initialize(*arg)
- super(*arg)
-
- @to = nil
- @headers = []
-
- # The RFC3986 parser does not normally populate opaque
- @opaque = "?#{@query}" if @query && !@opaque
-
- unless @opaque
- raise InvalidComponentError,
- "missing opaque part for mailto URL"
- end
- to, header = @opaque.split('?', 2)
- # allow semicolon as a addr-spec separator
- # http://support.microsoft.com/kb/820868
- unless /\A(?:[^@,;]+@[^@,;]+(?:\z|[,;]))*\z/ =~ to
- raise InvalidComponentError,
- "unrecognised opaque part for mailtoURL: #{@opaque}"
- end
-
- if arg[10] # arg_check
- self.to = to
- self.headers = header
- else
- set_to(to)
- set_headers(header)
- end
- end
-
- # The primary e-mail address of the URL, as a String
- attr_reader :to
-
- # E-mail headers set by the URL, as an Array of Arrays
- attr_reader :headers
-
- # check the to +v+ component
- def check_to(v)
- return true unless v
- return true if v.size == 0
-
- v.split(/[,;]/).each do |addr|
- # check url safety as path-rootless
- if /\A(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*\z/ !~ addr
- raise InvalidComponentError,
- "an address in 'to' is invalid as URI #{addr.dump}"
- end
-
- # check addr-spec
- # don't s/\+/ /g
- addr.gsub!(/%\h\h/, URI::TBLDECWWWCOMP_)
- if EMAIL_REGEXP !~ addr
- raise InvalidComponentError,
- "an address in 'to' is invalid as uri-escaped addr-spec #{addr.dump}"
- end
- end
-
- return true
- end
- private :check_to
-
- # private setter for to +v+
- def set_to(v)
- @to = v
- end
- protected :set_to
-
- # setter for to +v+
- def to=(v)
- check_to(v)
- set_to(v)
- v
- end
-
- # check the headers +v+ component against either
- # * HEADER_REGEXP
- def check_headers(v)
- return true unless v
- return true if v.size == 0
- if HEADER_REGEXP !~ v
- raise InvalidComponentError,
- "bad component(expected opaque component): #{v}"
- end
-
- return true
- end
- private :check_headers
-
- # private setter for headers +v+
- def set_headers(v)
- @headers = []
- if v
- v.split('&').each do |x|
- @headers << x.split(/=/, 2)
- end
- end
- end
- protected :set_headers
-
- # setter for headers +v+
- def headers=(v)
- check_headers(v)
- set_headers(v)
- v
- end
-
- # Constructs String from URI
- def to_s
- @scheme + ':' +
- if @to
- @to
- else
- ''
- end +
- if @headers.size > 0
- '?' + @headers.collect{|x| x.join('=')}.join('&')
- else
- ''
- end +
- if @fragment
- '#' + @fragment
- else
- ''
- end
- end
-
- # Returns the RFC822 e-mail text equivalent of the URL, as a String.
- #
- # Example:
- #
- # require 'uri'
- #
- # uri = URI.parse("mailto:ruby-list@ruby-lang.org?Subject=subscribe&cc=myaddr")
- # uri.to_mailtext
- # # => "To: ruby-list@ruby-lang.org\nSubject: subscribe\nCc: myaddr\n\n\n"
- #
- def to_mailtext
- to = parser.unescape(@to)
- head = ''
- body = ''
- @headers.each do |x|
- case x[0]
- when 'body'
- body = parser.unescape(x[1])
- when 'to'
- to << ', ' + parser.unescape(x[1])
- else
- head << parser.unescape(x[0]).capitalize + ': ' +
- parser.unescape(x[1]) + "\n"
- end
- end
-
- return "To: #{to}
-#{head}
-#{body}
-"
- end
- alias to_rfc822text to_mailtext
- end
-
- @@schemes['MAILTO'] = MailTo
-end
diff --git a/ruby_2_2/lib/uri/rfc2396_parser.rb b/ruby_2_2/lib/uri/rfc2396_parser.rb
deleted file mode 100644
index c192f65ec1..0000000000
--- a/ruby_2_2/lib/uri/rfc2396_parser.rb
+++ /dev/null
@@ -1,543 +0,0 @@
-#--
-# = uri/common.rb
-#
-# Author:: Akira Yamada <akira@ruby-lang.org>
-# Revision:: $Id$
-# License::
-# You can redistribute it and/or modify it under the same term as Ruby.
-#
-# See URI for general documentation
-#
-
-module URI
- #
- # Includes URI::REGEXP::PATTERN
- #
- module RFC2396_REGEXP
- #
- # Patterns used to parse URI's
- #
- module PATTERN
- # :stopdoc:
-
- # RFC 2396 (URI Generic Syntax)
- # RFC 2732 (IPv6 Literal Addresses in URL's)
- # RFC 2373 (IPv6 Addressing Architecture)
-
- # alpha = lowalpha | upalpha
- ALPHA = "a-zA-Z"
- # alphanum = alpha | digit
- ALNUM = "#{ALPHA}\\d"
-
- # hex = digit | "A" | "B" | "C" | "D" | "E" | "F" |
- # "a" | "b" | "c" | "d" | "e" | "f"
- HEX = "a-fA-F\\d"
- # escaped = "%" hex hex
- ESCAPED = "%[#{HEX}]{2}"
- # mark = "-" | "_" | "." | "!" | "~" | "*" | "'" |
- # "(" | ")"
- # unreserved = alphanum | mark
- UNRESERVED = "\\-_.!~*'()#{ALNUM}"
- # reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
- # "$" | ","
- # reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
- # "$" | "," | "[" | "]" (RFC 2732)
- RESERVED = ";/?:@&=+$,\\[\\]"
-
- # domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
- DOMLABEL = "(?:[#{ALNUM}](?:[-#{ALNUM}]*[#{ALNUM}])?)"
- # toplabel = alpha | alpha *( alphanum | "-" ) alphanum
- TOPLABEL = "(?:[#{ALPHA}](?:[-#{ALNUM}]*[#{ALNUM}])?)"
- # hostname = *( domainlabel "." ) toplabel [ "." ]
- HOSTNAME = "(?:#{DOMLABEL}\\.)*#{TOPLABEL}\\.?"
-
- # :startdoc:
- end # PATTERN
-
- # :startdoc:
- end # REGEXP
-
- # class that Parses String's into URI's
- #
- # It contains a Hash set of patterns and Regexp's that match and validate.
- #
- class RFC2396_Parser
- include RFC2396_REGEXP
-
- #
- # == Synopsis
- #
- # URI::Parser.new([opts])
- #
- # == Args
- #
- # The constructor accepts a hash as options for parser.
- # Keys of options are pattern names of URI components
- # and values of options are pattern strings.
- # The constructor generates set of regexps for parsing URIs.
- #
- # You can use the following keys:
- #
- # * :ESCAPED (URI::PATTERN::ESCAPED in default)
- # * :UNRESERVED (URI::PATTERN::UNRESERVED in default)
- # * :DOMLABEL (URI::PATTERN::DOMLABEL in default)
- # * :TOPLABEL (URI::PATTERN::TOPLABEL in default)
- # * :HOSTNAME (URI::PATTERN::HOSTNAME in default)
- #
- # == Examples
- #
- # p = URI::Parser.new(:ESCAPED => "(?:%[a-fA-F0-9]{2}|%u[a-fA-F0-9]{4})")
- # u = p.parse("http://example.jp/%uABCD") #=> #<URI::HTTP:0xb78cf4f8 URL:http://example.jp/%uABCD>
- # URI.parse(u.to_s) #=> raises URI::InvalidURIError
- #
- # s = "http://example.com/ABCD"
- # u1 = p.parse(s) #=> #<URI::HTTP:0xb78c3220 URL:http://example.com/ABCD>
- # u2 = URI.parse(s) #=> #<URI::HTTP:0xb78b6d54 URL:http://example.com/ABCD>
- # u1 == u2 #=> true
- # u1.eql?(u2) #=> false
- #
- def initialize(opts = {})
- @pattern = initialize_pattern(opts)
- @pattern.each_value(&:freeze)
- @pattern.freeze
-
- @regexp = initialize_regexp(@pattern)
- @regexp.each_value(&:freeze)
- @regexp.freeze
- end
-
- # The Hash of patterns.
- #
- # see also URI::Parser.initialize_pattern
- attr_reader :pattern
-
- # The Hash of Regexp
- #
- # see also URI::Parser.initialize_regexp
- attr_reader :regexp
-
- # Returns a split URI against regexp[:ABS_URI]
- def split(uri)
- case uri
- when ''
- # null uri
-
- when @regexp[:ABS_URI]
- scheme, opaque, userinfo, host, port,
- registry, path, query, fragment = $~[1..-1]
-
- # URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
-
- # absoluteURI = scheme ":" ( hier_part | opaque_part )
- # hier_part = ( net_path | abs_path ) [ "?" query ]
- # opaque_part = uric_no_slash *uric
-
- # abs_path = "/" path_segments
- # net_path = "//" authority [ abs_path ]
-
- # authority = server | reg_name
- # server = [ [ userinfo "@" ] hostport ]
-
- if !scheme
- raise InvalidURIError,
- "bad URI(absolute but no scheme): #{uri}"
- end
- if !opaque && (!path && (!host && !registry))
- raise InvalidURIError,
- "bad URI(absolute but no path): #{uri}"
- end
-
- when @regexp[:REL_URI]
- scheme = nil
- opaque = nil
-
- userinfo, host, port, registry,
- rel_segment, abs_path, query, fragment = $~[1..-1]
- if rel_segment && abs_path
- path = rel_segment + abs_path
- elsif rel_segment
- path = rel_segment
- elsif abs_path
- path = abs_path
- end
-
- # URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
-
- # relativeURI = ( net_path | abs_path | rel_path ) [ "?" query ]
-
- # net_path = "//" authority [ abs_path ]
- # abs_path = "/" path_segments
- # rel_path = rel_segment [ abs_path ]
-
- # authority = server | reg_name
- # server = [ [ userinfo "@" ] hostport ]
-
- else
- raise InvalidURIError, "bad URI(is not URI?): #{uri}"
- end
-
- path = '' if !path && !opaque # (see RFC2396 Section 5.2)
- ret = [
- scheme,
- userinfo, host, port, # X
- registry, # X
- path, # Y
- opaque, # Y
- query,
- fragment
- ]
- return ret
- end
-
- #
- # == Args
- #
- # +uri+::
- # String
- #
- # == Description
- #
- # parses +uri+ and constructs either matching URI scheme object
- # (FTP, HTTP, HTTPS, LDAP, LDAPS, or MailTo) or URI::Generic
- #
- # == Usage
- #
- # p = URI::Parser.new
- # p.parse("ldap://ldap.example.com/dc=example?user=john")
- # #=> #<URI::LDAP:0x00000000b9e7e8 URL:ldap://ldap.example.com/dc=example?user=john>
- #
- def parse(uri)
- scheme, userinfo, host, port,
- registry, path, opaque, query, fragment = self.split(uri)
-
- if scheme && URI.scheme_list.include?(scheme.upcase)
- URI.scheme_list[scheme.upcase].new(scheme, userinfo, host, port,
- registry, path, opaque, query,
- fragment, self)
- else
- Generic.new(scheme, userinfo, host, port,
- registry, path, opaque, query,
- fragment, self)
- end
- end
-
-
- #
- # == Args
- #
- # +uris+::
- # an Array of Strings
- #
- # == Description
- #
- # Attempts to parse and merge a set of URIs
- #
- def join(*uris)
- uris[0] = convert_to_uri(uris[0])
- uris.inject :merge
- end
-
- #
- # :call-seq:
- # extract( str )
- # extract( str, schemes )
- # extract( str, schemes ) {|item| block }
- #
- # == Args
- #
- # +str+::
- # String to search
- # +schemes+::
- # Patterns to apply to +str+
- #
- # == Description
- #
- # Attempts to parse and merge a set of URIs
- # If no +block+ given , then returns the result,
- # else it calls +block+ for each element in result.
- #
- # see also URI::Parser.make_regexp
- #
- def extract(str, schemes = nil)
- if block_given?
- str.scan(make_regexp(schemes)) { yield $& }
- nil
- else
- result = []
- str.scan(make_regexp(schemes)) { result.push $& }
- result
- end
- end
-
- # returns Regexp that is default self.regexp[:ABS_URI_REF],
- # unless +schemes+ is provided. Then it is a Regexp.union with self.pattern[:X_ABS_URI]
- def make_regexp(schemes = nil)
- unless schemes
- @regexp[:ABS_URI_REF]
- else
- /(?=#{Regexp.union(*schemes)}:)#{@pattern[:X_ABS_URI]}/x
- end
- end
-
- #
- # :call-seq:
- # escape( str )
- # escape( str, unsafe )
- #
- # == Args
- #
- # +str+::
- # String to make safe
- # +unsafe+::
- # Regexp to apply. Defaults to self.regexp[:UNSAFE]
- #
- # == Description
- #
- # constructs a safe String from +str+, removing unsafe characters,
- # replacing them with codes.
- #
- def escape(str, unsafe = @regexp[:UNSAFE])
- unless unsafe.kind_of?(Regexp)
- # perhaps unsafe is String object
- unsafe = Regexp.new("[#{Regexp.quote(unsafe)}]", false)
- end
- str.gsub(unsafe) do
- us = $&
- tmp = ''
- us.each_byte do |uc|
- tmp << sprintf('%%%02X', uc)
- end
- tmp
- end.force_encoding(Encoding::US_ASCII)
- end
-
- #
- # :call-seq:
- # unescape( str )
- # unescape( str, unsafe )
- #
- # == Args
- #
- # +str+::
- # String to remove escapes from
- # +unsafe+::
- # Regexp to apply. Defaults to self.regexp[:ESCAPED]
- #
- # == Description
- #
- # Removes escapes from +str+
- #
- def unescape(str, escaped = @regexp[:ESCAPED])
- str.gsub(escaped) { [$&[1, 2].hex].pack('C') }.force_encoding(str.encoding)
- end
-
- @@to_s = Kernel.instance_method(:to_s)
- def inspect
- @@to_s.bind(self).call
- end
-
- private
-
- # Constructs the default Hash of patterns
- def initialize_pattern(opts = {})
- ret = {}
- ret[:ESCAPED] = escaped = (opts.delete(:ESCAPED) || PATTERN::ESCAPED)
- ret[:UNRESERVED] = unreserved = opts.delete(:UNRESERVED) || PATTERN::UNRESERVED
- ret[:RESERVED] = reserved = opts.delete(:RESERVED) || PATTERN::RESERVED
- ret[:DOMLABEL] = opts.delete(:DOMLABEL) || PATTERN::DOMLABEL
- ret[:TOPLABEL] = opts.delete(:TOPLABEL) || PATTERN::TOPLABEL
- ret[:HOSTNAME] = hostname = opts.delete(:HOSTNAME)
-
- # RFC 2396 (URI Generic Syntax)
- # RFC 2732 (IPv6 Literal Addresses in URL's)
- # RFC 2373 (IPv6 Addressing Architecture)
-
- # uric = reserved | unreserved | escaped
- ret[:URIC] = uric = "(?:[#{unreserved}#{reserved}]|#{escaped})"
- # uric_no_slash = unreserved | escaped | ";" | "?" | ":" | "@" |
- # "&" | "=" | "+" | "$" | ","
- ret[:URIC_NO_SLASH] = uric_no_slash = "(?:[#{unreserved};?:@&=+$,]|#{escaped})"
- # query = *uric
- ret[:QUERY] = query = "#{uric}*"
- # fragment = *uric
- ret[:FRAGMENT] = fragment = "#{uric}*"
-
- # hostname = *( domainlabel "." ) toplabel [ "." ]
- # reg-name = *( unreserved / pct-encoded / sub-delims ) # RFC3986
- unless hostname
- ret[:HOSTNAME] = hostname = "(?:[a-zA-Z0-9\\-.]|%\\h\\h)+"
- end
-
- # RFC 2373, APPENDIX B:
- # IPv6address = hexpart [ ":" IPv4address ]
- # IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT
- # hexpart = hexseq | hexseq "::" [ hexseq ] | "::" [ hexseq ]
- # hexseq = hex4 *( ":" hex4)
- # hex4 = 1*4HEXDIG
- #
- # XXX: This definition has a flaw. "::" + IPv4address must be
- # allowed too. Here is a replacement.
- #
- # IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT
- ret[:IPV4ADDR] = ipv4addr = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
- # hex4 = 1*4HEXDIG
- hex4 = "[#{PATTERN::HEX}]{1,4}"
- # lastpart = hex4 | IPv4address
- lastpart = "(?:#{hex4}|#{ipv4addr})"
- # hexseq1 = *( hex4 ":" ) hex4
- hexseq1 = "(?:#{hex4}:)*#{hex4}"
- # hexseq2 = *( hex4 ":" ) lastpart
- hexseq2 = "(?:#{hex4}:)*#{lastpart}"
- # IPv6address = hexseq2 | [ hexseq1 ] "::" [ hexseq2 ]
- ret[:IPV6ADDR] = ipv6addr = "(?:#{hexseq2}|(?:#{hexseq1})?::(?:#{hexseq2})?)"
-
- # IPv6prefix = ( hexseq1 | [ hexseq1 ] "::" [ hexseq1 ] ) "/" 1*2DIGIT
- # unused
-
- # ipv6reference = "[" IPv6address "]" (RFC 2732)
- ret[:IPV6REF] = ipv6ref = "\\[#{ipv6addr}\\]"
-
- # host = hostname | IPv4address
- # host = hostname | IPv4address | IPv6reference (RFC 2732)
- ret[:HOST] = host = "(?:#{hostname}|#{ipv4addr}|#{ipv6ref})"
- # port = *digit
- port = '\d*'
- # hostport = host [ ":" port ]
- ret[:HOSTPORT] = hostport = "#{host}(?::#{port})?"
-
- # userinfo = *( unreserved | escaped |
- # ";" | ":" | "&" | "=" | "+" | "$" | "," )
- ret[:USERINFO] = userinfo = "(?:[#{unreserved};:&=+$,]|#{escaped})*"
-
- # pchar = unreserved | escaped |
- # ":" | "@" | "&" | "=" | "+" | "$" | ","
- pchar = "(?:[#{unreserved}:@&=+$,]|#{escaped})"
- # param = *pchar
- param = "#{pchar}*"
- # segment = *pchar *( ";" param )
- segment = "#{pchar}*(?:;#{param})*"
- # path_segments = segment *( "/" segment )
- ret[:PATH_SEGMENTS] = path_segments = "#{segment}(?:/#{segment})*"
-
- # server = [ [ userinfo "@" ] hostport ]
- server = "(?:#{userinfo}@)?#{hostport}"
- # reg_name = 1*( unreserved | escaped | "$" | "," |
- # ";" | ":" | "@" | "&" | "=" | "+" )
- ret[:REG_NAME] = reg_name = "(?:[#{unreserved}$,;:@&=+]|#{escaped})+"
- # authority = server | reg_name
- authority = "(?:#{server}|#{reg_name})"
-
- # rel_segment = 1*( unreserved | escaped |
- # ";" | "@" | "&" | "=" | "+" | "$" | "," )
- ret[:REL_SEGMENT] = rel_segment = "(?:[#{unreserved};@&=+$,]|#{escaped})+"
-
- # scheme = alpha *( alpha | digit | "+" | "-" | "." )
- ret[:SCHEME] = scheme = "[#{PATTERN::ALPHA}][\\-+.#{PATTERN::ALPHA}\\d]*"
-
- # abs_path = "/" path_segments
- ret[:ABS_PATH] = abs_path = "/#{path_segments}"
- # rel_path = rel_segment [ abs_path ]
- ret[:REL_PATH] = rel_path = "#{rel_segment}(?:#{abs_path})?"
- # net_path = "//" authority [ abs_path ]
- ret[:NET_PATH] = net_path = "//#{authority}(?:#{abs_path})?"
-
- # hier_part = ( net_path | abs_path ) [ "?" query ]
- ret[:HIER_PART] = hier_part = "(?:#{net_path}|#{abs_path})(?:\\?(?:#{query}))?"
- # opaque_part = uric_no_slash *uric
- ret[:OPAQUE_PART] = opaque_part = "#{uric_no_slash}#{uric}*"
-
- # absoluteURI = scheme ":" ( hier_part | opaque_part )
- ret[:ABS_URI] = abs_uri = "#{scheme}:(?:#{hier_part}|#{opaque_part})"
- # relativeURI = ( net_path | abs_path | rel_path ) [ "?" query ]
- ret[:REL_URI] = rel_uri = "(?:#{net_path}|#{abs_path}|#{rel_path})(?:\\?#{query})?"
-
- # URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
- ret[:URI_REF] = "(?:#{abs_uri}|#{rel_uri})?(?:##{fragment})?"
-
- ret[:X_ABS_URI] = "
- (#{scheme}): (?# 1: scheme)
- (?:
- (#{opaque_part}) (?# 2: opaque)
- |
- (?:(?:
- //(?:
- (?:(?:(#{userinfo})@)? (?# 3: userinfo)
- (?:(#{host})(?::(\\d*))?))? (?# 4: host, 5: port)
- |
- (#{reg_name}) (?# 6: registry)
- )
- |
- (?!//)) (?# XXX: '//' is the mark for hostport)
- (#{abs_path})? (?# 7: path)
- )(?:\\?(#{query}))? (?# 8: query)
- )
- (?:\\#(#{fragment}))? (?# 9: fragment)
- "
-
- ret[:X_REL_URI] = "
- (?:
- (?:
- //
- (?:
- (?:(#{userinfo})@)? (?# 1: userinfo)
- (#{host})?(?::(\\d*))? (?# 2: host, 3: port)
- |
- (#{reg_name}) (?# 4: registry)
- )
- )
- |
- (#{rel_segment}) (?# 5: rel_segment)
- )?
- (#{abs_path})? (?# 6: abs_path)
- (?:\\?(#{query}))? (?# 7: query)
- (?:\\#(#{fragment}))? (?# 8: fragment)
- "
-
- ret
- end
-
- # Constructs the default Hash of Regexp's
- def initialize_regexp(pattern)
- ret = {}
-
- # for URI::split
- ret[:ABS_URI] = Regexp.new('\A\s*' + pattern[:X_ABS_URI] + '\s*\z', Regexp::EXTENDED)
- ret[:REL_URI] = Regexp.new('\A\s*' + pattern[:X_REL_URI] + '\s*\z', Regexp::EXTENDED)
-
- # for URI::extract
- ret[:URI_REF] = Regexp.new(pattern[:URI_REF])
- ret[:ABS_URI_REF] = Regexp.new(pattern[:X_ABS_URI], Regexp::EXTENDED)
- ret[:REL_URI_REF] = Regexp.new(pattern[:X_REL_URI], Regexp::EXTENDED)
-
- # for URI::escape/unescape
- ret[:ESCAPED] = Regexp.new(pattern[:ESCAPED])
- ret[:UNSAFE] = Regexp.new("[^#{pattern[:UNRESERVED]}#{pattern[:RESERVED]}]")
-
- # for Generic#initialize
- ret[:SCHEME] = Regexp.new("\\A#{pattern[:SCHEME]}\\z")
- ret[:USERINFO] = Regexp.new("\\A#{pattern[:USERINFO]}\\z")
- ret[:HOST] = Regexp.new("\\A#{pattern[:HOST]}\\z")
- ret[:PORT] = Regexp.new("\\A#{pattern[:PORT]}\\z")
- ret[:OPAQUE] = Regexp.new("\\A#{pattern[:OPAQUE_PART]}\\z")
- ret[:REGISTRY] = Regexp.new("\\A#{pattern[:REG_NAME]}\\z")
- ret[:ABS_PATH] = Regexp.new("\\A#{pattern[:ABS_PATH]}\\z")
- ret[:REL_PATH] = Regexp.new("\\A#{pattern[:REL_PATH]}\\z")
- ret[:QUERY] = Regexp.new("\\A#{pattern[:QUERY]}\\z")
- ret[:FRAGMENT] = Regexp.new("\\A#{pattern[:FRAGMENT]}\\z")
-
- ret
- end
-
- def convert_to_uri(uri)
- if uri.is_a?(URI::Generic)
- uri
- elsif uri = String.try_convert(uri)
- parse(uri)
- else
- raise ArgumentError,
- "bad argument (expected URI object or URI string)"
- end
- end
-
- end # class Parser
-end # module URI
diff --git a/ruby_2_2/lib/uri/rfc3986_parser.rb b/ruby_2_2/lib/uri/rfc3986_parser.rb
deleted file mode 100644
index 3923b0699c..0000000000
--- a/ruby_2_2/lib/uri/rfc3986_parser.rb
+++ /dev/null
@@ -1,124 +0,0 @@
-module URI
- class RFC3986_Parser # :nodoc:
- # URI defined in RFC3986
- # this regexp is modified not to host is not empty string
- RFC3986_URI = /\A(?<URI>(?<scheme>[A-Za-z][+\-.0-9A-Za-z]*):(?<hier-part>\/\/(?<authority>(?:(?<userinfo>(?:%\h\h|[!$&-.0-;=A-Z_a-z~])*)@)?(?<host>(?<IP-literal>\[(?:(?<IPv6address>(?:\h{1,4}:){6}(?<ls32>\h{1,4}:\h{1,4}|(?<IPv4address>(?<dec-octet>[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]|\d)\.\g<dec-octet>\.\g<dec-octet>\.\g<dec-octet>))|::(?:\h{1,4}:){5}\g<ls32>|\h{1,4}?::(?:\h{1,4}:){4}\g<ls32>|(?:(?:\h{1,4}:)?\h{1,4})?::(?:\h{1,4}:){3}\g<ls32>|(?:(?:\h{1,4}:){,2}\h{1,4})?::(?:\h{1,4}:){2}\g<ls32>|(?:(?:\h{1,4}:){,3}\h{1,4})?::\h{1,4}:\g<ls32>|(?:(?:\h{1,4}:){,4}\h{1,4})?::\g<ls32>|(?:(?:\h{1,4}:){,5}\h{1,4})?::\h{1,4}|(?:(?:\h{1,4}:){,6}\h{1,4})?::)|(?<IPvFuture>v\h+\.[!$&-.0-;=A-Z_a-z~]+))\])|\g<IPv4address>|(?<reg-name>(?:%\h\h|[!$&-.0-9;=A-Z_a-z~])+))?(?::(?<port>\d*))?)(?<path-abempty>(?:\/(?<segment>(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*))*)|(?<path-absolute>\/(?:(?<segment-nz>(?:%\h\h|[!$&-.0-;=@-Z_a-z~])+)(?:\/\g<segment>)*)?)|(?<path-rootless>\g<segment-nz>(?:\/\g<segment>)*)|(?<path-empty>))(?:\?(?<query>[^#]*))?(?:\#(?<fragment>(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*))?)\z/
- RFC3986_relative_ref = /\A(?<relative-ref>(?<relative-part>\/\/(?<authority>(?:(?<userinfo>(?:%\h\h|[!$&-.0-;=A-Z_a-z~])*)@)?(?<host>(?<IP-literal>\[(?<IPv6address>(?:\h{1,4}:){6}(?<ls32>\h{1,4}:\h{1,4}|(?<IPv4address>(?<dec-octet>[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]|\d)\.\g<dec-octet>\.\g<dec-octet>\.\g<dec-octet>))|::(?:\h{1,4}:){5}\g<ls32>|\h{1,4}?::(?:\h{1,4}:){4}\g<ls32>|(?:(?:\h{1,4}:){,1}\h{1,4})?::(?:\h{1,4}:){3}\g<ls32>|(?:(?:\h{1,4}:){,2}\h{1,4})?::(?:\h{1,4}:){2}\g<ls32>|(?:(?:\h{1,4}:){,3}\h{1,4})?::\h{1,4}:\g<ls32>|(?:(?:\h{1,4}:){,4}\h{1,4})?::\g<ls32>|(?:(?:\h{1,4}:){,5}\h{1,4})?::\h{1,4}|(?:(?:\h{1,4}:){,6}\h{1,4})?::)|(?<IPvFuture>v\h+\.[!$&-.0-;=A-Z_a-z~]+)\])|\g<IPv4address>|(?<reg-name>(?:%\h\h|[!$&-.0-9;=A-Z_a-z~])+))?(?::(?<port>\d*))?)(?<path-abempty>(?:\/(?<segment>(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*))*)|(?<path-absolute>\/(?:(?<segment-nz>(?:%\h\h|[!$&-.0-;=@-Z_a-z~])+)(?:\/\g<segment>)*)?)|(?<path-noscheme>(?<segment-nz-nc>(?:%\h\h|[!$&-.0-9;=@-Z_a-z~])+)(?:\/\g<segment>)*)|(?<path-empty>))(?:\?(?<query>[^#]*))?(?:\#(?<fragment>(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*))?)\z/
- attr_reader :regexp
-
- def initialize
- @regexp = default_regexp.each_value(&:freeze).freeze
- end
-
- def split(uri) #:nodoc:
- begin
- uri = uri.to_str
- rescue NoMethodError
- raise InvalidURIError, "bad URI(is not URI?): #{uri}"
- end
- uri.ascii_only? or
- raise InvalidURIError, "URI must be ascii only #{uri.dump}"
- if m = RFC3986_URI.match(uri)
- query = m["query".freeze]
- scheme = m["scheme".freeze]
- opaque = m["path-rootless".freeze]
- if opaque
- opaque << "?#{query}" if query
- [ scheme,
- nil, # userinfo
- nil, # host
- nil, # port
- nil, # registry
- nil, # path
- opaque,
- nil, # query
- m["fragment".freeze]
- ]
- else # normal
- [ scheme,
- m["userinfo".freeze],
- m["host".freeze],
- m["port".freeze],
- nil, # registry
- (m["path-abempty".freeze] ||
- m["path-absolute".freeze] ||
- m["path-empty".freeze]),
- nil, # opaque
- query,
- m["fragment".freeze]
- ]
- end
- elsif m = RFC3986_relative_ref.match(uri)
- [ nil, # scheme
- m["userinfo".freeze],
- m["host".freeze],
- m["port".freeze],
- nil, # registry,
- (m["path-abempty".freeze] ||
- m["path-absolute".freeze] ||
- m["path-noscheme".freeze] ||
- m["path-empty".freeze]),
- nil, # opaque
- m["query".freeze],
- m["fragment".freeze]
- ]
- else
- raise InvalidURIError, "bad URI(is not URI?): #{uri}"
- end
- end
-
- def parse(uri) # :nodoc:
- scheme, userinfo, host, port,
- registry, path, opaque, query, fragment = self.split(uri)
- scheme_list = URI.scheme_list
- if scheme && scheme_list.include?(uc = scheme.upcase)
- scheme_list[uc].new(scheme, userinfo, host, port,
- registry, path, opaque, query,
- fragment, self)
- else
- Generic.new(scheme, userinfo, host, port,
- registry, path, opaque, query,
- fragment, self)
- end
- end
-
-
- def join(*uris) # :nodoc:
- uris[0] = convert_to_uri(uris[0])
- uris.inject :merge
- end
-
- @@to_s = Kernel.instance_method(:to_s)
- def inspect
- @@to_s.bind(self).call
- end
-
- private
-
- def default_regexp # :nodoc:
- {
- SCHEME: /\A[A-Za-z][A-Za-z0-9+\-.]*\z/,
- USERINFO: /\A(?:%\h\h|[!$&-.0-;=A-Z_a-z~])*\z/,
- HOST: /\A(?:(?<IP-literal>\[(?:(?<IPv6address>(?:\h{1,4}:){6}(?<ls32>\h{1,4}:\h{1,4}|(?<IPv4address>(?<dec-octet>[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]|\d)\.\g<dec-octet>\.\g<dec-octet>\.\g<dec-octet>))|::(?:\h{1,4}:){5}\g<ls32>|\h{,4}::(?:\h{1,4}:){4}\g<ls32>|(?:(?:\h{1,4}:)?\h{1,4})?::(?:\h{1,4}:){3}\g<ls32>|(?:(?:\h{1,4}:){,2}\h{1,4})?::(?:\h{1,4}:){2}\g<ls32>|(?:(?:\h{1,4}:){,3}\h{1,4})?::\h{1,4}:\g<ls32>|(?:(?:\h{1,4}:){,4}\h{1,4})?::\g<ls32>|(?:(?:\h{1,4}:){,5}\h{1,4})?::\h{1,4}|(?:(?:\h{1,4}:){,6}\h{1,4})?::)|(?<IPvFuture>v\h+\.[!$&-.0-;=A-Z_a-z~]+))\])|\g<IPv4address>|(?<reg-name>(?:%\h\h|[!$&-.0-9;=A-Z_a-z~])*))\z/,
- ABS_PATH: /\A\/(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*(?:\/(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*)*\z/,
- REL_PATH: /\A(?:%\h\h|[!$&-.0-;=@-Z_a-z~])+(?:\/(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*)*\z/,
- QUERY: /\A(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*\z/,
- FRAGMENT: /\A(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*\z/,
- OPAQUE: /\A(?:[^\/].*)?\z/,
- PORT: /\A[\x09\x0a\x0c\x0d ]*\d*[\x09\x0a\x0c\x0d ]*\z/,
- }
- end
-
- def convert_to_uri(uri)
- if uri.is_a?(URI::Generic)
- uri
- elsif uri = String.try_convert(uri)
- parse(uri)
- else
- raise ArgumentError,
- "bad argument (expected URI object or URI string)"
- end
- end
-
- end # class Parser
-end # module URI
diff --git a/ruby_2_2/lib/weakref.rb b/ruby_2_2/lib/weakref.rb
deleted file mode 100644
index cdcbabf77c..0000000000
--- a/ruby_2_2/lib/weakref.rb
+++ /dev/null
@@ -1,106 +0,0 @@
-require "delegate"
-
-# Weak Reference class that allows a referenced object to be
-# garbage-collected.
-#
-# A WeakRef may be used exactly like the object it references.
-#
-# Usage:
-#
-# foo = Object.new # create a new object instance
-# p foo.to_s # original's class
-# foo = WeakRef.new(foo) # reassign foo with WeakRef instance
-# p foo.to_s # should be same class
-# GC.start # start the garbage collector
-# p foo.to_s # should raise exception (recycled)
-#
-# == Example
-#
-# With help from WeakRef, we can implement our own rudimentary WeakHash class.
-#
-# We will call it WeakHash, since it's really just a Hash except all of it's
-# keys and values can be garbage collected.
-#
-# require 'weakref'
-#
-# class WeakHash < Hash
-# def []= key, obj
-# super WeakRef.new(key), WeakRef.new(obj)
-# end
-# end
-#
-# This is just a simple implementation, we've opened the Hash class and changed
-# Hash#store to create a new WeakRef object with +key+ and +obj+ parameters
-# before passing them as our key-value pair to the hash.
-#
-# With this you will have to limit your self to String keys, otherwise you
-# will get an ArgumentError because WeakRef cannot create a finalizer for a
-# Symbol. Symbols are immutable and cannot be garbage collected.
-#
-# Let's see it in action:
-#
-# omg = "lol"
-# c = WeakHash.new
-# c['foo'] = "bar"
-# c['baz'] = Object.new
-# c['qux'] = omg
-# puts c.inspect
-# #=> {"foo"=>"bar", "baz"=>#<Object:0x007f4ddfc6cb48>, "qux"=>"lol"}
-#
-# # Now run the garbage collector
-# GC.start
-# c['foo'] #=> nil
-# c['baz'] #=> nil
-# c['qux'] #=> nil
-# omg #=> "lol"
-#
-# puts c.inspect
-# #=> WeakRef::RefError: Invalid Reference - probably recycled
-#
-# You can see the local variable +omg+ stayed, although its reference in our
-# hash object was garbage collected, along with the rest of the keys and
-# values. Also, when we tried to inspect our hash, we got a WeakRef::RefError.
-# This is because these objects were also garbage collected.
-
-class WeakRef < Delegator
-
- ##
- # RefError is raised when a referenced object has been recycled by the
- # garbage collector
-
- class RefError < StandardError
- end
-
- @@__map = ::ObjectSpace::WeakMap.new
-
- ##
- # Creates a weak reference to +orig+
- #
- # Raises an ArgumentError if the given +orig+ is immutable, such as Symbol,
- # Fixnum, or Float.
-
- def initialize(orig)
- case orig
- when true, false, nil
- @delegate_sd_obj = orig
- else
- @@__map[self] = orig
- end
- super
- end
-
- def __getobj__ # :nodoc:
- @@__map[self] or defined?(@delegate_sd_obj) ? @delegate_sd_obj :
- Kernel::raise(RefError, "Invalid Reference - probably recycled", Kernel::caller(2))
- end
-
- def __setobj__(obj) # :nodoc:
- end
-
- ##
- # Returns true if the referenced object is still alive.
-
- def weakref_alive?
- @@__map.key?(self) or defined?(@delegate_sd_obj)
- end
-end
diff --git a/ruby_2_2/lib/webrick.rb b/ruby_2_2/lib/webrick.rb
deleted file mode 100644
index fd8522a6c5..0000000000
--- a/ruby_2_2/lib/webrick.rb
+++ /dev/null
@@ -1,226 +0,0 @@
-##
-# = WEB server toolkit.
-#
-# WEBrick is an HTTP server toolkit that can be configured as an HTTPS server,
-# a proxy server, and a virtual-host server. WEBrick features complete
-# logging of both server operations and HTTP access. WEBrick supports both
-# basic and digest authentication in addition to algorithms not in RFC 2617.
-#
-# A WEBrick server can be composed of multiple WEBrick servers or servlets to
-# provide differing behavior on a per-host or per-path basis. WEBrick
-# includes servlets for handling CGI scripts, ERb pages, Ruby blocks and
-# directory listings.
-#
-# WEBrick also includes tools for daemonizing a process and starting a process
-# at a higher privilege level and dropping permissions.
-#
-# == Starting an HTTP server
-#
-# To create a new WEBrick::HTTPServer that will listen to connections on port
-# 8000 and serve documents from the current user's public_html folder:
-#
-# require 'webrick'
-#
-# root = File.expand_path '~/public_html'
-# server = WEBrick::HTTPServer.new :Port => 8000, :DocumentRoot => root
-#
-# To run the server you will need to provide a suitable shutdown hook as
-# starting the server blocks the current thread:
-#
-# trap 'INT' do server.shutdown end
-#
-# server.start
-#
-# == Custom Behavior
-#
-# The easiest way to have a server perform custom operations is through
-# WEBrick::HTTPServer#mount_proc. The block given will be called with a
-# WEBrick::HTTPRequest with request info and a WEBrick::HTTPResponse which
-# must be filled in appropriately:
-#
-# server.mount_proc '/' do |req, res|
-# res.body = 'Hello, world!'
-# end
-#
-# Remember that +server.mount_proc+ must precede +server.start+.
-#
-# == Servlets
-#
-# Advanced custom behavior can be obtained through mounting a subclass of
-# WEBrick::HTTPServlet::AbstractServlet. Servlets provide more modularity
-# when writing an HTTP server than mount_proc allows. Here is a simple
-# servlet:
-#
-# class Simple < WEBrick::HTTPServlet::AbstractServlet
-# def do_GET request, response
-# status, content_type, body = do_stuff_with request
-#
-# response.status = 200
-# response['Content-Type'] = 'text/plain'
-# response.body = 'Hello, World!'
-# end
-# end
-#
-# To initialize the servlet you mount it on the server:
-#
-# server.mount '/simple', Simple
-#
-# See WEBrick::HTTPServlet::AbstractServlet for more details.
-#
-# == Virtual Hosts
-#
-# A server can act as a virtual host for multiple host names. After creating
-# the listening host, additional hosts that do not listen can be created and
-# attached as virtual hosts:
-#
-# server = WEBrick::HTTPServer.new # ...
-#
-# vhost = WEBrick::HTTPServer.new :ServerName => 'vhost.example',
-# :DoNotListen => true, # ...
-# vhost.mount '/', ...
-#
-# server.virtual_host vhost
-#
-# If no +:DocumentRoot+ is provided and no servlets or procs are mounted on the
-# main server it will return 404 for all URLs.
-#
-# == HTTPS
-#
-# To create an HTTPS server you only need to enable SSL and provide an SSL
-# certificate name:
-#
-# require 'webrick'
-# require 'webrick/https'
-#
-# cert_name = [
-# %w[CN localhost],
-# ]
-#
-# server = WEBrick::HTTPServer.new(:Port => 8000,
-# :SSLEnable => true,
-# :SSLCertName => cert_name)
-#
-# This will start the server with a self-generated self-signed certificate.
-# The certificate will be changed every time the server is restarted.
-#
-# To create a server with a pre-determined key and certificate you can provide
-# them:
-#
-# require 'webrick'
-# require 'webrick/https'
-# require 'openssl'
-#
-# cert = OpenSSL::X509::Certificate.new File.read '/path/to/cert.pem'
-# pkey = OpenSSL::PKey::RSA.new File.read '/path/to/pkey.pem'
-#
-# server = WEBrick::HTTPServer.new(:Port => 8000,
-# :SSLEnable => true,
-# :SSLCertificate => cert,
-# :SSLPrivateKey => pkey)
-#
-# == Proxy Server
-#
-# WEBrick can act as a proxy server:
-#
-# require 'webrick'
-# require 'webrick/httpproxy'
-#
-# proxy = WEBrick::HTTPProxyServer.new :Port => 8000
-#
-# trap 'INT' do proxy.shutdown end
-#
-# See WEBrick::HTTPProxy for further details including modifying proxied
-# responses.
-#
-# == Basic and Digest authentication
-#
-# WEBrick provides both Basic and Digest authentication for regular and proxy
-# servers. See WEBrick::HTTPAuth, WEBrick::HTTPAuth::BasicAuth and
-# WEBrick::HTTPAuth::DigestAuth.
-#
-# == WEBrick as a Production Web Server
-#
-# WEBrick can be run as a production server for small loads.
-#
-# === Daemonizing
-#
-# To start a WEBrick server as a daemon simple run WEBrick::Daemon.start
-# before starting the server.
-#
-# === Dropping Permissions
-#
-# WEBrick can be started as one user to gain permission to bind to port 80 or
-# 443 for serving HTTP or HTTPS traffic then can drop these permissions for
-# regular operation. To listen on all interfaces for HTTP traffic:
-#
-# sockets = WEBrick::Utils.create_listeners nil, 80
-#
-# Then drop privileges:
-#
-# WEBrick::Utils.su 'www'
-#
-# Then create a server that does not listen by default:
-#
-# server = WEBrick::HTTPServer.new :DoNotListen => true, # ...
-#
-# Then overwrite the listening sockets with the port 80 sockets:
-#
-# server.listeners.replace sockets
-#
-# === Logging
-#
-# WEBrick can separately log server operations and end-user access. For
-# server operations:
-#
-# log_file = File.open '/var/log/webrick.log', 'a+'
-# log = WEBrick::Log.new log_file
-#
-# For user access logging:
-#
-# access_log = [
-# [log_file, WEBrick::AccessLog::COMBINED_LOG_FORMAT],
-# ]
-#
-# server = WEBrick::HTTPServer.new :Logger => log, :AccessLog => access_log
-#
-# See WEBrick::AccessLog for further log formats.
-#
-# === Log Rotation
-#
-# To rotate logs in WEBrick on a HUP signal (like syslogd can send), open the
-# log file in 'a+' mode (as above) and trap 'HUP' to reopen the log file:
-#
-# trap 'HUP' do log_file.reopen '/path/to/webrick.log', 'a+'
-#
-# == Copyright
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-#
-# Copyright (c) 2000 TAKAHASHI Masayoshi, GOTOU YUUZOU
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#--
-# $IPR: webrick.rb,v 1.12 2002/10/01 17:16:31 gotoyuzo Exp $
-
-module WEBrick
-end
-
-require 'webrick/compat.rb'
-
-require 'webrick/version.rb'
-require 'webrick/config.rb'
-require 'webrick/log.rb'
-require 'webrick/server.rb'
-require 'webrick/utils.rb'
-require 'webrick/accesslog'
-
-require 'webrick/htmlutils.rb'
-require 'webrick/httputils.rb'
-require 'webrick/cookie.rb'
-require 'webrick/httpversion.rb'
-require 'webrick/httpstatus.rb'
-require 'webrick/httprequest.rb'
-require 'webrick/httpresponse.rb'
-require 'webrick/httpserver.rb'
-require 'webrick/httpservlet.rb'
-require 'webrick/httpauth.rb'
diff --git a/ruby_2_2/lib/webrick/accesslog.rb b/ruby_2_2/lib/webrick/accesslog.rb
deleted file mode 100644
index 4df27efc29..0000000000
--- a/ruby_2_2/lib/webrick/accesslog.rb
+++ /dev/null
@@ -1,158 +0,0 @@
-#--
-# accesslog.rb -- Access log handling utilities
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2002 keita yamaguchi
-# Copyright (c) 2002 Internet Programming with Ruby writers
-#
-# $IPR: accesslog.rb,v 1.1 2002/10/01 17:16:32 gotoyuzo Exp $
-
-module WEBrick
-
- ##
- # AccessLog provides logging to various files in various formats.
- #
- # Multiple logs may be written to at the same time:
- #
- # access_log = [
- # [$stderr, WEBrick::AccessLog::COMMON_LOG_FORMAT],
- # [$stderr, WEBrick::AccessLog::REFERER_LOG_FORMAT],
- # ]
- #
- # server = WEBrick::HTTPServer.new :AccessLog => access_log
- #
- # Custom log formats may be defined. WEBrick::AccessLog provides a subset
- # of the formatting from Apache's mod_log_config
- # http://httpd.apache.org/docs/mod/mod_log_config.html#formats. See
- # AccessLog::setup_params for a list of supported options
-
- module AccessLog
-
- ##
- # Raised if a parameter such as %e, %i, %o or %n is used without fetching
- # a specific field.
-
- class AccessLogError < StandardError; end
-
- ##
- # The Common Log Format's time format
-
- CLF_TIME_FORMAT = "[%d/%b/%Y:%H:%M:%S %Z]"
-
- ##
- # Common Log Format
-
- COMMON_LOG_FORMAT = "%h %l %u %t \"%r\" %s %b"
-
- ##
- # Short alias for Common Log Format
-
- CLF = COMMON_LOG_FORMAT
-
- ##
- # Referer Log Format
-
- REFERER_LOG_FORMAT = "%{Referer}i -> %U"
-
- ##
- # User-Agent Log Format
-
- AGENT_LOG_FORMAT = "%{User-Agent}i"
-
- ##
- # Combined Log Format
-
- COMBINED_LOG_FORMAT = "#{CLF} \"%{Referer}i\" \"%{User-agent}i\""
-
- module_function
-
- # This format specification is a subset of mod_log_config of Apache:
- #
- # %a:: Remote IP address
- # %b:: Total response size
- # %e{variable}:: Given variable in ENV
- # %f:: Response filename
- # %h:: Remote host name
- # %{header}i:: Given request header
- # %l:: Remote logname, always "-"
- # %m:: Request method
- # %{attr}n:: Given request attribute from <tt>req.attributes</tt>
- # %{header}o:: Given response header
- # %p:: Server's request port
- # %{format}p:: The canonical port of the server serving the request or the
- # actual port or the client's actual port. Valid formats are
- # canonical, local or remote.
- # %q:: Request query string
- # %r:: First line of the request
- # %s:: Request status
- # %t:: Time the request was received
- # %T:: Time taken to process the request
- # %u:: Remote user from auth
- # %U:: Unparsed URI
- # %%:: Literal %
-
- def setup_params(config, req, res)
- params = Hash.new("")
- params["a"] = req.peeraddr[3]
- params["b"] = res.sent_size
- params["e"] = ENV
- params["f"] = res.filename || ""
- params["h"] = req.peeraddr[2]
- params["i"] = req
- params["l"] = "-"
- params["m"] = req.request_method
- params["n"] = req.attributes
- params["o"] = res
- params["p"] = req.port
- params["q"] = req.query_string
- params["r"] = req.request_line.sub(/\x0d?\x0a\z/o, '')
- params["s"] = res.status # won't support "%>s"
- params["t"] = req.request_time
- params["T"] = Time.now - req.request_time
- params["u"] = req.user || "-"
- params["U"] = req.unparsed_uri
- params["v"] = config[:ServerName]
- params
- end
-
- ##
- # Formats +params+ according to +format_string+ which is described in
- # setup_params.
-
- def format(format_string, params)
- format_string.gsub(/\%(?:\{(.*?)\})?>?([a-zA-Z%])/){
- param, spec = $1, $2
- case spec[0]
- when ?e, ?i, ?n, ?o
- raise AccessLogError,
- "parameter is required for \"#{spec}\"" unless param
- (param = params[spec][param]) ? escape(param) : "-"
- when ?t
- params[spec].strftime(param || CLF_TIME_FORMAT)
- when ?p
- case param
- when 'remote'
- escape(params["i"].peeraddr[1].to_s)
- else
- escape(params["p"].to_s)
- end
- when ?%
- "%"
- else
- escape(params[spec].to_s)
- end
- }
- end
-
- ##
- # Escapes control characters in +data+
-
- def escape(data)
- if data.tainted?
- data.gsub(/[[:cntrl:]\\]+/) {$&.dump[1...-1]}.untaint
- else
- data
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/webrick/cgi.rb b/ruby_2_2/lib/webrick/cgi.rb
deleted file mode 100644
index 80f636edc3..0000000000
--- a/ruby_2_2/lib/webrick/cgi.rb
+++ /dev/null
@@ -1,308 +0,0 @@
-#
-# cgi.rb -- Yet another CGI library
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2003 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $Id$
-
-require "webrick/httprequest"
-require "webrick/httpresponse"
-require "webrick/config"
-require "stringio"
-
-module WEBrick
-
- # A CGI library using WEBrick requests and responses.
- #
- # Example:
- #
- # class MyCGI < WEBrick::CGI
- # def do_GET req, res
- # res.body = 'it worked!'
- # res.status = 200
- # end
- # end
- #
- # MyCGI.new.start
-
- class CGI
-
- # The CGI error exception class
-
- CGIError = Class.new(StandardError)
-
- ##
- # The CGI configuration. This is based on WEBrick::Config::HTTP
-
- attr_reader :config
-
- ##
- # The CGI logger
-
- attr_reader :logger
-
- ##
- # Creates a new CGI interface.
- #
- # The first argument in +args+ is a configuration hash which would update
- # WEBrick::Config::HTTP.
- #
- # Any remaining arguments are stored in the <code>@options</code> instance
- # variable for use by a subclass.
-
- def initialize(*args)
- if defined?(MOD_RUBY)
- unless ENV.has_key?("GATEWAY_INTERFACE")
- Apache.request.setup_cgi_env
- end
- end
- if %r{HTTP/(\d+\.\d+)} =~ ENV["SERVER_PROTOCOL"]
- httpv = $1
- end
- @config = WEBrick::Config::HTTP.dup.update(
- :ServerSoftware => ENV["SERVER_SOFTWARE"] || "null",
- :HTTPVersion => HTTPVersion.new(httpv || "1.0"),
- :RunOnCGI => true, # to detect if it runs on CGI.
- :NPH => false # set true to run as NPH script.
- )
- if config = args.shift
- @config.update(config)
- end
- @config[:Logger] ||= WEBrick::BasicLog.new($stderr)
- @logger = @config[:Logger]
- @options = args
- end
-
- ##
- # Reads +key+ from the configuration
-
- def [](key)
- @config[key]
- end
-
- ##
- # Starts the CGI process with the given environment +env+ and standard
- # input and output +stdin+ and +stdout+.
-
- def start(env=ENV, stdin=$stdin, stdout=$stdout)
- sock = WEBrick::CGI::Socket.new(@config, env, stdin, stdout)
- req = HTTPRequest.new(@config)
- res = HTTPResponse.new(@config)
- unless @config[:NPH] or defined?(MOD_RUBY)
- def res.setup_header
- unless @header["status"]
- phrase = HTTPStatus::reason_phrase(@status)
- @header["status"] = "#{@status} #{phrase}"
- end
- super
- end
- def res.status_line
- ""
- end
- end
-
- begin
- req.parse(sock)
- req.script_name = (env["SCRIPT_NAME"] || File.expand_path($0)).dup
- req.path_info = (env["PATH_INFO"] || "").dup
- req.query_string = env["QUERY_STRING"]
- req.user = env["REMOTE_USER"]
- res.request_method = req.request_method
- res.request_uri = req.request_uri
- res.request_http_version = req.http_version
- res.keep_alive = req.keep_alive?
- self.service(req, res)
- rescue HTTPStatus::Error => ex
- res.set_error(ex)
- rescue HTTPStatus::Status => ex
- res.status = ex.code
- rescue Exception => ex
- @logger.error(ex)
- res.set_error(ex, true)
- ensure
- req.fixup
- if defined?(MOD_RUBY)
- res.setup_header
- Apache.request.status_line = "#{res.status} #{res.reason_phrase}"
- Apache.request.status = res.status
- table = Apache.request.headers_out
- res.header.each{|key, val|
- case key
- when /^content-encoding$/i
- Apache::request.content_encoding = val
- when /^content-type$/i
- Apache::request.content_type = val
- else
- table[key] = val.to_s
- end
- }
- res.cookies.each{|cookie|
- table.add("Set-Cookie", cookie.to_s)
- }
- Apache.request.send_http_header
- res.send_body(sock)
- else
- res.send_response(sock)
- end
- end
- end
-
- ##
- # Services the request +req+ which will fill in the response +res+. See
- # WEBrick::HTTPServlet::AbstractServlet#service for details.
-
- def service(req, res)
- method_name = "do_" + req.request_method.gsub(/-/, "_")
- if respond_to?(method_name)
- __send__(method_name, req, res)
- else
- raise HTTPStatus::MethodNotAllowed,
- "unsupported method `#{req.request_method}'."
- end
- end
-
- ##
- # Provides HTTP socket emulation from the CGI environment
-
- class Socket # :nodoc:
- include Enumerable
-
- private
-
- def initialize(config, env, stdin, stdout)
- @config = config
- @env = env
- @header_part = StringIO.new
- @body_part = stdin
- @out_port = stdout
- @out_port.binmode
-
- @server_addr = @env["SERVER_ADDR"] || "0.0.0.0"
- @server_name = @env["SERVER_NAME"]
- @server_port = @env["SERVER_PORT"]
- @remote_addr = @env["REMOTE_ADDR"]
- @remote_host = @env["REMOTE_HOST"] || @remote_addr
- @remote_port = @env["REMOTE_PORT"] || 0
-
- begin
- @header_part << request_line << CRLF
- setup_header
- @header_part << CRLF
- @header_part.rewind
- rescue Exception
- raise CGIError, "invalid CGI environment"
- end
- end
-
- def request_line
- meth = @env["REQUEST_METHOD"] || "GET"
- unless url = @env["REQUEST_URI"]
- url = (@env["SCRIPT_NAME"] || File.expand_path($0)).dup
- url << @env["PATH_INFO"].to_s
- url = WEBrick::HTTPUtils.escape_path(url)
- if query_string = @env["QUERY_STRING"]
- unless query_string.empty?
- url << "?" << query_string
- end
- end
- end
- # we cannot get real HTTP version of client ;)
- httpv = @config[:HTTPVersion]
- return "#{meth} #{url} HTTP/#{httpv}"
- end
-
- def setup_header
- @env.each{|key, value|
- case key
- when "CONTENT_TYPE", "CONTENT_LENGTH"
- add_header(key.gsub(/_/, "-"), value)
- when /^HTTP_(.*)/
- add_header($1.gsub(/_/, "-"), value)
- end
- }
- end
-
- def add_header(hdrname, value)
- unless value.empty?
- @header_part << hdrname << ": " << value << CRLF
- end
- end
-
- def input
- @header_part.eof? ? @body_part : @header_part
- end
-
- public
-
- def peeraddr
- [nil, @remote_port, @remote_host, @remote_addr]
- end
-
- def addr
- [nil, @server_port, @server_name, @server_addr]
- end
-
- def gets(eol=LF, size=nil)
- input.gets(eol, size)
- end
-
- def read(size=nil)
- input.read(size)
- end
-
- def each
- input.each{|line| yield(line) }
- end
-
- def eof?
- input.eof?
- end
-
- def <<(data)
- @out_port << data
- end
-
- def cert
- return nil unless defined?(OpenSSL)
- if pem = @env["SSL_SERVER_CERT"]
- OpenSSL::X509::Certificate.new(pem) unless pem.empty?
- end
- end
-
- def peer_cert
- return nil unless defined?(OpenSSL)
- if pem = @env["SSL_CLIENT_CERT"]
- OpenSSL::X509::Certificate.new(pem) unless pem.empty?
- end
- end
-
- def peer_cert_chain
- return nil unless defined?(OpenSSL)
- if @env["SSL_CLIENT_CERT_CHAIN_0"]
- keys = @env.keys
- certs = keys.sort.collect{|k|
- if /^SSL_CLIENT_CERT_CHAIN_\d+$/ =~ k
- if pem = @env[k]
- OpenSSL::X509::Certificate.new(pem) unless pem.empty?
- end
- end
- }
- certs.compact
- end
- end
-
- def cipher
- return nil unless defined?(OpenSSL)
- if cipher = @env["SSL_CIPHER"]
- ret = [ cipher ]
- ret << @env["SSL_PROTOCOL"]
- ret << @env["SSL_CIPHER_USEKEYSIZE"]
- ret << @env["SSL_CIPHER_ALGKEYSIZE"]
- ret
- end
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/webrick/compat.rb b/ruby_2_2/lib/webrick/compat.rb
deleted file mode 100644
index d2bc3ef6b4..0000000000
--- a/ruby_2_2/lib/webrick/compat.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-#
-# compat.rb -- cross platform compatibility
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2002 GOTOU Yuuzou
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: compat.rb,v 1.6 2002/10/01 17:16:32 gotoyuzo Exp $
-
-##
-# System call error module used by webrick for cross platform compatibility.
-#
-# EPROTO:: protocol error
-# ECONNRESET:: remote host reset the connection request
-# ECONNABORTED:: Client sent TCP reset (RST) before server has accepted the
-# connection requested by client.
-#
-module Errno
- ##
- # Protocol error.
-
- class EPROTO < SystemCallError; end
-
- ##
- # Remote host reset the connection request.
-
- class ECONNRESET < SystemCallError; end
-
- ##
- # Client sent TCP reset (RST) before server has accepted the connection
- # requested by client.
-
- class ECONNABORTED < SystemCallError; end
-end
diff --git a/ruby_2_2/lib/webrick/config.rb b/ruby_2_2/lib/webrick/config.rb
deleted file mode 100644
index c347da4be6..0000000000
--- a/ruby_2_2/lib/webrick/config.rb
+++ /dev/null
@@ -1,151 +0,0 @@
-#
-# config.rb -- Default configurations.
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2000, 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
-# Copyright (c) 2003 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: config.rb,v 1.52 2003/07/22 19:20:42 gotoyuzo Exp $
-
-require 'webrick/version'
-require 'webrick/httpversion'
-require 'webrick/httputils'
-require 'webrick/utils'
-require 'webrick/log'
-
-module WEBrick
- module Config
- LIBDIR = File::dirname(__FILE__) # :nodoc:
-
- # for GenericServer
- General = {
- :ServerName => Utils::getservername,
- :BindAddress => nil, # "0.0.0.0" or "::" or nil
- :Port => nil, # users MUST specify this!!
- :MaxClients => 100, # maximum number of the concurrent connections
- :ServerType => nil, # default: WEBrick::SimpleServer
- :Logger => nil, # default: WEBrick::Log.new
- :ServerSoftware => "WEBrick/#{WEBrick::VERSION} " +
- "(Ruby/#{RUBY_VERSION}/#{RUBY_RELEASE_DATE})",
- :TempDir => ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'/tmp',
- :DoNotListen => false,
- :StartCallback => nil,
- :StopCallback => nil,
- :AcceptCallback => nil,
- :DoNotReverseLookup => nil,
- :ShutdownSocketWithoutClose => false,
- }
-
- # for HTTPServer, HTTPRequest, HTTPResponse ...
- HTTP = General.dup.update(
- :Port => 80,
- :RequestTimeout => 30,
- :HTTPVersion => HTTPVersion.new("1.1"),
- :AccessLog => nil,
- :MimeTypes => HTTPUtils::DefaultMimeTypes,
- :DirectoryIndex => ["index.html","index.htm","index.cgi","index.rhtml"],
- :DocumentRoot => nil,
- :DocumentRootOptions => { :FancyIndexing => true },
- :RequestCallback => nil,
- :ServerAlias => nil,
- :InputBufferSize => 65536, # input buffer size in reading request body
- :OutputBufferSize => 65536, # output buffer size in sending File or IO
-
- # for HTTPProxyServer
- :ProxyAuthProc => nil,
- :ProxyContentHandler => nil,
- :ProxyVia => true,
- :ProxyTimeout => true,
- :ProxyURI => nil,
-
- :CGIInterpreter => nil,
- :CGIPathEnv => nil,
-
- # workaround: if Request-URIs contain 8bit chars,
- # they should be escaped before calling of URI::parse().
- :Escape8bitURI => false
- )
-
- ##
- # Default configuration for WEBrick::HTTPServlet::FileHandler
- #
- # :AcceptableLanguages::
- # Array of languages allowed for accept-language. There is no default
- # :DirectoryCallback::
- # Allows preprocessing of directory requests. There is no default
- # callback.
- # :FancyIndexing::
- # If true, show an index for directories. The default is true.
- # :FileCallback::
- # Allows preprocessing of file requests. There is no default callback.
- # :HandlerCallback::
- # Allows preprocessing of requests. There is no default callback.
- # :HandlerTable::
- # Maps file suffixes to file handlers. DefaultFileHandler is used by
- # default but any servlet can be used.
- # :NondisclosureName::
- # Do not show files matching this array of globs. .ht* and *~ are
- # excluded by default.
- # :UserDir::
- # Directory inside ~user to serve content from for /~user requests.
- # Only works if mounted on /. Disabled by default.
-
- FileHandler = {
- :NondisclosureName => [".ht*", "*~"],
- :FancyIndexing => false,
- :HandlerTable => {},
- :HandlerCallback => nil,
- :DirectoryCallback => nil,
- :FileCallback => nil,
- :UserDir => nil, # e.g. "public_html"
- :AcceptableLanguages => [] # ["en", "ja", ... ]
- }
-
- ##
- # Default configuration for WEBrick::HTTPAuth::BasicAuth
- #
- # :AutoReloadUserDB:: Reload the user database provided by :UserDB
- # automatically?
-
- BasicAuth = {
- :AutoReloadUserDB => true,
- }
-
- ##
- # Default configuration for WEBrick::HTTPAuth::DigestAuth.
- #
- # :Algorithm:: MD5, MD5-sess (default), SHA1, SHA1-sess
- # :Domain:: An Array of URIs that define the protected space
- # :Qop:: 'auth' for authentication, 'auth-int' for integrity protection or
- # both
- # :UseOpaque:: Should the server send opaque values to the client? This
- # helps prevent replay attacks.
- # :CheckNc:: Should the server check the nonce count? This helps the
- # server detect replay attacks.
- # :UseAuthenticationInfoHeader:: Should the server send an
- # AuthenticationInfo header?
- # :AutoReloadUserDB:: Reload the user database provided by :UserDB
- # automatically?
- # :NonceExpirePeriod:: How long should we store used nonces? Default is
- # 30 minutes.
- # :NonceExpireDelta:: How long is a nonce valid? Default is 1 minute
- # :InternetExplorerHack:: Hack which allows Internet Explorer to work.
- # :OperaHack:: Hack which allows Opera to work.
-
- DigestAuth = {
- :Algorithm => 'MD5-sess', # or 'MD5'
- :Domain => nil, # an array includes domain names.
- :Qop => [ 'auth' ], # 'auth' or 'auth-int' or both.
- :UseOpaque => true,
- :UseNextNonce => false,
- :CheckNc => false,
- :UseAuthenticationInfoHeader => true,
- :AutoReloadUserDB => true,
- :NonceExpirePeriod => 30*60,
- :NonceExpireDelta => 60,
- :InternetExplorerHack => true,
- :OperaHack => true,
- }
- end
-end
diff --git a/ruby_2_2/lib/webrick/cookie.rb b/ruby_2_2/lib/webrick/cookie.rb
deleted file mode 100644
index d8df23133d..0000000000
--- a/ruby_2_2/lib/webrick/cookie.rb
+++ /dev/null
@@ -1,171 +0,0 @@
-#
-# cookie.rb -- Cookie class
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2000, 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: cookie.rb,v 1.16 2002/09/21 12:23:35 gotoyuzo Exp $
-
-require 'time'
-require 'webrick/httputils'
-
-module WEBrick
-
- ##
- # Processes HTTP cookies
-
- class Cookie
-
- ##
- # The cookie name
-
- attr_reader :name
-
- ##
- # The cookie value
-
- attr_accessor :value
-
- ##
- # The cookie version
-
- attr_accessor :version
-
- ##
- # The cookie domain
- attr_accessor :domain
-
- ##
- # The cookie path
-
- attr_accessor :path
-
- ##
- # Is this a secure cookie?
-
- attr_accessor :secure
-
- ##
- # The cookie comment
-
- attr_accessor :comment
-
- ##
- # The maximum age of the cookie
-
- attr_accessor :max_age
-
- #attr_accessor :comment_url, :discard, :port
-
- ##
- # Creates a new cookie with the given +name+ and +value+
-
- def initialize(name, value)
- @name = name
- @value = value
- @version = 0 # Netscape Cookie
-
- @domain = @path = @secure = @comment = @max_age =
- @expires = @comment_url = @discard = @port = nil
- end
-
- ##
- # Sets the cookie expiration to the time +t+. The expiration time may be
- # a false value to disable expiration or a Time or HTTP format time string
- # to set the expiration date.
-
- def expires=(t)
- @expires = t && (t.is_a?(Time) ? t.httpdate : t.to_s)
- end
-
- ##
- # Retrieves the expiration time as a Time
-
- def expires
- @expires && Time.parse(@expires)
- end
-
- ##
- # The cookie string suitable for use in an HTTP header
-
- def to_s
- ret = ""
- ret << @name << "=" << @value
- ret << "; " << "Version=" << @version.to_s if @version > 0
- ret << "; " << "Domain=" << @domain if @domain
- ret << "; " << "Expires=" << @expires if @expires
- ret << "; " << "Max-Age=" << @max_age.to_s if @max_age
- ret << "; " << "Comment=" << @comment if @comment
- ret << "; " << "Path=" << @path if @path
- ret << "; " << "Secure" if @secure
- ret
- end
-
- ##
- # Parses a Cookie field sent from the user-agent. Returns an array of
- # cookies.
-
- def self.parse(str)
- if str
- ret = []
- cookie = nil
- ver = 0
- str.split(/[;,]\s+/).each{|x|
- key, val = x.split(/=/,2)
- val = val ? HTTPUtils::dequote(val) : ""
- case key
- when "$Version"; ver = val.to_i
- when "$Path"; cookie.path = val
- when "$Domain"; cookie.domain = val
- when "$Port"; cookie.port = val
- else
- ret << cookie if cookie
- cookie = self.new(key, val)
- cookie.version = ver
- end
- }
- ret << cookie if cookie
- ret
- end
- end
-
- ##
- # Parses the cookie in +str+
-
- def self.parse_set_cookie(str)
- cookie_elem = str.split(/;/)
- first_elem = cookie_elem.shift
- first_elem.strip!
- key, value = first_elem.split(/=/, 2)
- cookie = new(key, HTTPUtils.dequote(value))
- cookie_elem.each{|pair|
- pair.strip!
- key, value = pair.split(/=/, 2)
- if value
- value = HTTPUtils.dequote(value.strip)
- end
- case key.downcase
- when "domain" then cookie.domain = value
- when "path" then cookie.path = value
- when "expires" then cookie.expires = value
- when "max-age" then cookie.max_age = Integer(value)
- when "comment" then cookie.comment = value
- when "version" then cookie.version = Integer(value)
- when "secure" then cookie.secure = true
- end
- }
- return cookie
- end
-
- ##
- # Parses the cookies in +str+
-
- def self.parse_set_cookies(str)
- return str.split(/,(?=[^;,]*=)|,$/).collect{|c|
- parse_set_cookie(c)
- }
- end
- end
-end
diff --git a/ruby_2_2/lib/webrick/htmlutils.rb b/ruby_2_2/lib/webrick/htmlutils.rb
deleted file mode 100644
index 4cb3d0d7f6..0000000000
--- a/ruby_2_2/lib/webrick/htmlutils.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-#--
-# htmlutils.rb -- HTMLUtils Module
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2000, 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: htmlutils.rb,v 1.7 2002/09/21 12:23:35 gotoyuzo Exp $
-
-module WEBrick
- module HTMLUtils
-
- ##
- # Escapes &, ", > and < in +string+
-
- def escape(string)
- return "" unless string
- str = string.b
- str.gsub!(/&/n, '&amp;')
- str.gsub!(/\"/n, '&quot;')
- str.gsub!(/>/n, '&gt;')
- str.gsub!(/</n, '&lt;')
- str.force_encoding(string.encoding)
- end
- module_function :escape
-
- end
-end
diff --git a/ruby_2_2/lib/webrick/httpauth.rb b/ruby_2_2/lib/webrick/httpauth.rb
deleted file mode 100644
index 96d479b2d7..0000000000
--- a/ruby_2_2/lib/webrick/httpauth.rb
+++ /dev/null
@@ -1,95 +0,0 @@
-#
-# httpauth.rb -- HTTP access authentication
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2000, 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: httpauth.rb,v 1.14 2003/07/22 19:20:42 gotoyuzo Exp $
-
-require 'webrick/httpauth/basicauth'
-require 'webrick/httpauth/digestauth'
-require 'webrick/httpauth/htpasswd'
-require 'webrick/httpauth/htdigest'
-require 'webrick/httpauth/htgroup'
-
-module WEBrick
-
- ##
- # HTTPAuth provides both basic and digest authentication.
- #
- # To enable authentication for requests in WEBrick you will need a user
- # database and an authenticator. To start, here's an Htpasswd database for
- # use with a DigestAuth authenticator:
- #
- # config = { :Realm => 'DigestAuth example realm' }
- #
- # htpasswd = WEBrick::HTTPAuth::Htpasswd.new 'my_password_file'
- # htpasswd.auth_type = WEBrick::HTTPAuth::DigestAuth
- # htpasswd.set_passwd config[:Realm], 'username', 'password'
- # htpasswd.flush
- #
- # The +:Realm+ is used to provide different access to different groups
- # across several resources on a server. Typically you'll need only one
- # realm for a server.
- #
- # This database can be used to create an authenticator:
- #
- # config[:UserDB] = htpasswd
- #
- # digest_auth = WEBrick::HTTPAuth::DigestAuth.new config
- #
- # To authenticate a request call #authenticate with a request and response
- # object in a servlet:
- #
- # def do_GET req, res
- # @authenticator.authenticate req, res
- # end
- #
- # For digest authentication the authenticator must not be created every
- # request, it must be passed in as an option via WEBrick::HTTPServer#mount.
-
- module HTTPAuth
- module_function
-
- def _basic_auth(req, res, realm, req_field, res_field, err_type,
- block) # :nodoc:
- user = pass = nil
- if /^Basic\s+(.*)/o =~ req[req_field]
- userpass = $1
- user, pass = userpass.unpack("m*")[0].split(":", 2)
- end
- if block.call(user, pass)
- req.user = user
- return
- end
- res[res_field] = "Basic realm=\"#{realm}\""
- raise err_type
- end
-
- ##
- # Simple wrapper for providing basic authentication for a request. When
- # called with a request +req+, response +res+, authentication +realm+ and
- # +block+ the block will be called with a +username+ and +password+. If
- # the block returns true the request is allowed to continue, otherwise an
- # HTTPStatus::Unauthorized error is raised.
-
- def basic_auth(req, res, realm, &block) # :yield: username, password
- _basic_auth(req, res, realm, "Authorization", "WWW-Authenticate",
- HTTPStatus::Unauthorized, block)
- end
-
- ##
- # Simple wrapper for providing basic authentication for a proxied request.
- # When called with a request +req+, response +res+, authentication +realm+
- # and +block+ the block will be called with a +username+ and +password+.
- # If the block returns true the request is allowed to continue, otherwise
- # an HTTPStatus::ProxyAuthenticationRequired error is raised.
-
- def proxy_basic_auth(req, res, realm, &block) # :yield: username, password
- _basic_auth(req, res, realm, "Proxy-Authorization", "Proxy-Authenticate",
- HTTPStatus::ProxyAuthenticationRequired, block)
- end
- end
-end
diff --git a/ruby_2_2/lib/webrick/httpauth/authenticator.rb b/ruby_2_2/lib/webrick/httpauth/authenticator.rb
deleted file mode 100644
index f6d4ab844f..0000000000
--- a/ruby_2_2/lib/webrick/httpauth/authenticator.rb
+++ /dev/null
@@ -1,116 +0,0 @@
-#--
-# httpauth/authenticator.rb -- Authenticator mix-in module.
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2003 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: authenticator.rb,v 1.3 2003/02/20 07:15:47 gotoyuzo Exp $
-
-module WEBrick
- module HTTPAuth
-
- ##
- # Module providing generic support for both Digest and Basic
- # authentication schemes.
-
- module Authenticator
-
- RequestField = "Authorization" # :nodoc:
- ResponseField = "WWW-Authenticate" # :nodoc:
- ResponseInfoField = "Authentication-Info" # :nodoc:
- AuthException = HTTPStatus::Unauthorized # :nodoc:
-
- ##
- # Method of authentication, must be overridden by the including class
-
- AuthScheme = nil
-
- ##
- # The realm this authenticator covers
-
- attr_reader :realm
-
- ##
- # The user database for this authenticator
-
- attr_reader :userdb
-
- ##
- # The logger for this authenticator
-
- attr_reader :logger
-
- private
-
- # :stopdoc:
-
- ##
- # Initializes the authenticator from +config+
-
- def check_init(config)
- [:UserDB, :Realm].each{|sym|
- unless config[sym]
- raise ArgumentError, "Argument #{sym.inspect} missing."
- end
- }
- @realm = config[:Realm]
- @userdb = config[:UserDB]
- @logger = config[:Logger] || Log::new($stderr)
- @reload_db = config[:AutoReloadUserDB]
- @request_field = self::class::RequestField
- @response_field = self::class::ResponseField
- @resp_info_field = self::class::ResponseInfoField
- @auth_exception = self::class::AuthException
- @auth_scheme = self::class::AuthScheme
- end
-
- ##
- # Ensures +req+ has credentials that can be authenticated.
-
- def check_scheme(req)
- unless credentials = req[@request_field]
- error("no credentials in the request.")
- return nil
- end
- unless match = /^#{@auth_scheme}\s+/i.match(credentials)
- error("invalid scheme in %s.", credentials)
- info("%s: %s", @request_field, credentials) if $DEBUG
- return nil
- end
- return match.post_match
- end
-
- def log(meth, fmt, *args)
- msg = format("%s %s: ", @auth_scheme, @realm)
- msg << fmt % args
- @logger.send(meth, msg)
- end
-
- def error(fmt, *args)
- if @logger.error?
- log(:error, fmt, *args)
- end
- end
-
- def info(fmt, *args)
- if @logger.info?
- log(:info, fmt, *args)
- end
- end
-
- # :startdoc:
- end
-
- ##
- # Module providing generic support for both Digest and Basic
- # authentication schemes for proxies.
-
- module ProxyAuthenticator
- RequestField = "Proxy-Authorization" # :nodoc:
- ResponseField = "Proxy-Authenticate" # :nodoc:
- InfoField = "Proxy-Authentication-Info" # :nodoc:
- AuthException = HTTPStatus::ProxyAuthenticationRequired # :nodoc:
- end
- end
-end
diff --git a/ruby_2_2/lib/webrick/httpauth/basicauth.rb b/ruby_2_2/lib/webrick/httpauth/basicauth.rb
deleted file mode 100644
index 3ff20b56d2..0000000000
--- a/ruby_2_2/lib/webrick/httpauth/basicauth.rb
+++ /dev/null
@@ -1,108 +0,0 @@
-#
-# httpauth/basicauth.rb -- HTTP basic access authentication
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2003 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: basicauth.rb,v 1.5 2003/02/20 07:15:47 gotoyuzo Exp $
-
-require 'webrick/config'
-require 'webrick/httpstatus'
-require 'webrick/httpauth/authenticator'
-
-module WEBrick
- module HTTPAuth
-
- ##
- # Basic Authentication for WEBrick
- #
- # Use this class to add basic authentication to a WEBrick servlet.
- #
- # Here is an example of how to set up a BasicAuth:
- #
- # config = { :Realm => 'BasicAuth example realm' }
- #
- # htpasswd = WEBrick::HTTPAuth::Htpasswd.new 'my_password_file'
- # htpasswd.set_passwd config[:Realm], 'username', 'password'
- # htpasswd.flush
- #
- # config[:UserDB] = htpasswd
- #
- # basic_auth = WEBrick::HTTPAuth::BasicAuth.new config
-
- class BasicAuth
- include Authenticator
-
- AuthScheme = "Basic" # :nodoc:
-
- ##
- # Used by UserDB to create a basic password entry
-
- def self.make_passwd(realm, user, pass)
- pass ||= ""
- pass.crypt(Utils::random_string(2))
- end
-
- attr_reader :realm, :userdb, :logger
-
- ##
- # Creates a new BasicAuth instance.
- #
- # See WEBrick::Config::BasicAuth for default configuration entries
- #
- # You must supply the following configuration entries:
- #
- # :Realm:: The name of the realm being protected.
- # :UserDB:: A database of usernames and passwords.
- # A WEBrick::HTTPAuth::Htpasswd instance should be used.
-
- def initialize(config, default=Config::BasicAuth)
- check_init(config)
- @config = default.dup.update(config)
- end
-
- ##
- # Authenticates a +req+ and returns a 401 Unauthorized using +res+ if
- # the authentication was not correct.
-
- def authenticate(req, res)
- unless basic_credentials = check_scheme(req)
- challenge(req, res)
- end
- userid, password = basic_credentials.unpack("m*")[0].split(":", 2)
- password ||= ""
- if userid.empty?
- error("user id was not given.")
- challenge(req, res)
- end
- unless encpass = @userdb.get_passwd(@realm, userid, @reload_db)
- error("%s: the user is not allowed.", userid)
- challenge(req, res)
- end
- if password.crypt(encpass) != encpass
- error("%s: password unmatch.", userid)
- challenge(req, res)
- end
- info("%s: authentication succeeded.", userid)
- req.user = userid
- end
-
- ##
- # Returns a challenge response which asks for for authentication
- # information
-
- def challenge(req, res)
- res[@response_field] = "#{@auth_scheme} realm=\"#{@realm}\""
- raise @auth_exception
- end
- end
-
- ##
- # Basic authentication for proxy servers. See BasicAuth for details.
-
- class ProxyBasicAuth < BasicAuth
- include ProxyAuthenticator
- end
- end
-end
diff --git a/ruby_2_2/lib/webrick/httpauth/digestauth.rb b/ruby_2_2/lib/webrick/httpauth/digestauth.rb
deleted file mode 100644
index 0eea94774f..0000000000
--- a/ruby_2_2/lib/webrick/httpauth/digestauth.rb
+++ /dev/null
@@ -1,408 +0,0 @@
-#
-# httpauth/digestauth.rb -- HTTP digest access authentication
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2003 Internet Programming with Ruby writers.
-# Copyright (c) 2003 H.M.
-#
-# The original implementation is provided by H.M.
-# URL: http://rwiki.jin.gr.jp/cgi-bin/rw-cgi.rb?cmd=view;name=
-# %C7%A7%BE%DA%B5%A1%C7%BD%A4%F2%B2%FE%C2%A4%A4%B7%A4%C6%A4%DF%A4%EB
-#
-# $IPR: digestauth.rb,v 1.5 2003/02/20 07:15:47 gotoyuzo Exp $
-
-require 'webrick/config'
-require 'webrick/httpstatus'
-require 'webrick/httpauth/authenticator'
-require 'digest/md5'
-require 'digest/sha1'
-
-module WEBrick
- module HTTPAuth
-
- ##
- # RFC 2617 Digest Access Authentication for WEBrick
- #
- # Use this class to add digest authentication to a WEBrick servlet.
- #
- # Here is an example of how to set up DigestAuth:
- #
- # config = { :Realm => 'DigestAuth example realm' }
- #
- # htdigest = WEBrick::HTTPAuth::Htdigest.new 'my_password_file'
- # htdigest.set_passwd config[:Realm], 'username', 'password'
- # htdigest.flush
- #
- # config[:UserDB] = htdigest
- #
- # digest_auth = WEBrick::HTTPAuth::DigestAuth.new config
- #
- # When using this as with a servlet be sure not to create a new DigestAuth
- # object in the servlet's #initialize. By default WEBrick creates a new
- # servlet instance for every request and the DigestAuth object must be
- # used across requests.
-
- class DigestAuth
- include Authenticator
-
- AuthScheme = "Digest" # :nodoc:
-
- ##
- # Struct containing the opaque portion of the digest authentication
-
- OpaqueInfo = Struct.new(:time, :nonce, :nc) # :nodoc:
-
- ##
- # Digest authentication algorithm
-
- attr_reader :algorithm
-
- ##
- # Quality of protection. RFC 2617 defines "auth" and "auth-int"
-
- attr_reader :qop
-
- ##
- # Used by UserDB to create a digest password entry
-
- def self.make_passwd(realm, user, pass)
- pass ||= ""
- Digest::MD5::hexdigest([user, realm, pass].join(":"))
- end
-
- ##
- # Creates a new DigestAuth instance. Be sure to use the same DigestAuth
- # instance for multiple requests as it saves state between requests in
- # order to perform authentication.
- #
- # See WEBrick::Config::DigestAuth for default configuration entries
- #
- # You must supply the following configuration entries:
- #
- # :Realm:: The name of the realm being protected.
- # :UserDB:: A database of usernames and passwords.
- # A WEBrick::HTTPAuth::Htdigest instance should be used.
-
- def initialize(config, default=Config::DigestAuth)
- check_init(config)
- @config = default.dup.update(config)
- @algorithm = @config[:Algorithm]
- @domain = @config[:Domain]
- @qop = @config[:Qop]
- @use_opaque = @config[:UseOpaque]
- @use_next_nonce = @config[:UseNextNonce]
- @check_nc = @config[:CheckNc]
- @use_auth_info_header = @config[:UseAuthenticationInfoHeader]
- @nonce_expire_period = @config[:NonceExpirePeriod]
- @nonce_expire_delta = @config[:NonceExpireDelta]
- @internet_explorer_hack = @config[:InternetExplorerHack]
-
- case @algorithm
- when 'MD5','MD5-sess'
- @h = Digest::MD5
- when 'SHA1','SHA1-sess' # it is a bonus feature :-)
- @h = Digest::SHA1
- else
- msg = format('Algorithm "%s" is not supported.', @algorithm)
- raise ArgumentError.new(msg)
- end
-
- @instance_key = hexdigest(self.__id__, Time.now.to_i, Process.pid)
- @opaques = {}
- @last_nonce_expire = Time.now
- @mutex = Mutex.new
- end
-
- ##
- # Authenticates a +req+ and returns a 401 Unauthorized using +res+ if
- # the authentication was not correct.
-
- def authenticate(req, res)
- unless result = @mutex.synchronize{ _authenticate(req, res) }
- challenge(req, res)
- end
- if result == :nonce_is_stale
- challenge(req, res, true)
- end
- return true
- end
-
- ##
- # Returns a challenge response which asks for for authentication
- # information
-
- def challenge(req, res, stale=false)
- nonce = generate_next_nonce(req)
- if @use_opaque
- opaque = generate_opaque(req)
- @opaques[opaque].nonce = nonce
- end
-
- param = Hash.new
- param["realm"] = HTTPUtils::quote(@realm)
- param["domain"] = HTTPUtils::quote(@domain.to_a.join(" ")) if @domain
- param["nonce"] = HTTPUtils::quote(nonce)
- param["opaque"] = HTTPUtils::quote(opaque) if opaque
- param["stale"] = stale.to_s
- param["algorithm"] = @algorithm
- param["qop"] = HTTPUtils::quote(@qop.to_a.join(",")) if @qop
-
- res[@response_field] =
- "#{@auth_scheme} " + param.map{|k,v| "#{k}=#{v}" }.join(", ")
- info("%s: %s", @response_field, res[@response_field]) if $DEBUG
- raise @auth_exception
- end
-
- private
-
- # :stopdoc:
-
- MustParams = ['username','realm','nonce','uri','response']
- MustParamsAuth = ['cnonce','nc']
-
- def _authenticate(req, res)
- unless digest_credentials = check_scheme(req)
- return false
- end
-
- auth_req = split_param_value(digest_credentials)
- if auth_req['qop'] == "auth" || auth_req['qop'] == "auth-int"
- req_params = MustParams + MustParamsAuth
- else
- req_params = MustParams
- end
- req_params.each{|key|
- unless auth_req.has_key?(key)
- error('%s: parameter missing. "%s"', auth_req['username'], key)
- raise HTTPStatus::BadRequest
- end
- }
-
- if !check_uri(req, auth_req)
- raise HTTPStatus::BadRequest
- end
-
- if auth_req['realm'] != @realm
- error('%s: realm unmatch. "%s" for "%s"',
- auth_req['username'], auth_req['realm'], @realm)
- return false
- end
-
- auth_req['algorithm'] ||= 'MD5'
- if auth_req['algorithm'].upcase != @algorithm.upcase
- error('%s: algorithm unmatch. "%s" for "%s"',
- auth_req['username'], auth_req['algorithm'], @algorithm)
- return false
- end
-
- if (@qop.nil? && auth_req.has_key?('qop')) ||
- (@qop && (! @qop.member?(auth_req['qop'])))
- error('%s: the qop is not allowed. "%s"',
- auth_req['username'], auth_req['qop'])
- return false
- end
-
- password = @userdb.get_passwd(@realm, auth_req['username'], @reload_db)
- unless password
- error('%s: the user is not allowed.', auth_req['username'])
- return false
- end
-
- nonce_is_invalid = false
- if @use_opaque
- info("@opaque = %s", @opaque.inspect) if $DEBUG
- if !(opaque = auth_req['opaque'])
- error('%s: opaque is not given.', auth_req['username'])
- nonce_is_invalid = true
- elsif !(opaque_struct = @opaques[opaque])
- error('%s: invalid opaque is given.', auth_req['username'])
- nonce_is_invalid = true
- elsif !check_opaque(opaque_struct, req, auth_req)
- @opaques.delete(auth_req['opaque'])
- nonce_is_invalid = true
- end
- elsif !check_nonce(req, auth_req)
- nonce_is_invalid = true
- end
-
- if /-sess$/i =~ auth_req['algorithm']
- ha1 = hexdigest(password, auth_req['nonce'], auth_req['cnonce'])
- else
- ha1 = password
- end
-
- if auth_req['qop'] == "auth" || auth_req['qop'] == nil
- ha2 = hexdigest(req.request_method, auth_req['uri'])
- ha2_res = hexdigest("", auth_req['uri'])
- elsif auth_req['qop'] == "auth-int"
- ha2 = hexdigest(req.request_method, auth_req['uri'],
- hexdigest(req.body))
- ha2_res = hexdigest("", auth_req['uri'], hexdigest(res.body))
- end
-
- if auth_req['qop'] == "auth" || auth_req['qop'] == "auth-int"
- param2 = ['nonce', 'nc', 'cnonce', 'qop'].map{|key|
- auth_req[key]
- }.join(':')
- digest = hexdigest(ha1, param2, ha2)
- digest_res = hexdigest(ha1, param2, ha2_res)
- else
- digest = hexdigest(ha1, auth_req['nonce'], ha2)
- digest_res = hexdigest(ha1, auth_req['nonce'], ha2_res)
- end
-
- if digest != auth_req['response']
- error("%s: digest unmatch.", auth_req['username'])
- return false
- elsif nonce_is_invalid
- error('%s: digest is valid, but nonce is not valid.',
- auth_req['username'])
- return :nonce_is_stale
- elsif @use_auth_info_header
- auth_info = {
- 'nextnonce' => generate_next_nonce(req),
- 'rspauth' => digest_res
- }
- if @use_opaque
- opaque_struct.time = req.request_time
- opaque_struct.nonce = auth_info['nextnonce']
- opaque_struct.nc = "%08x" % (auth_req['nc'].hex + 1)
- end
- if auth_req['qop'] == "auth" || auth_req['qop'] == "auth-int"
- ['qop','cnonce','nc'].each{|key|
- auth_info[key] = auth_req[key]
- }
- end
- res[@resp_info_field] = auth_info.keys.map{|key|
- if key == 'nc'
- key + '=' + auth_info[key]
- else
- key + "=" + HTTPUtils::quote(auth_info[key])
- end
- }.join(', ')
- end
- info('%s: authentication succeeded.', auth_req['username'])
- req.user = auth_req['username']
- return true
- end
-
- def split_param_value(string)
- ret = {}
- while string.bytesize != 0
- case string
- when /^\s*([\w\-\.\*\%\!]+)=\s*\"((\\.|[^\"])*)\"\s*,?/
- key = $1
- matched = $2
- string = $'
- ret[key] = matched.gsub(/\\(.)/, "\\1")
- when /^\s*([\w\-\.\*\%\!]+)=\s*([^,\"]*),?/
- key = $1
- matched = $2
- string = $'
- ret[key] = matched.clone
- when /^s*^,/
- string = $'
- else
- break
- end
- end
- ret
- end
-
- def generate_next_nonce(req)
- now = "%012d" % req.request_time.to_i
- pk = hexdigest(now, @instance_key)[0,32]
- nonce = [now + ":" + pk].pack("m*").chop # it has 60 length of chars.
- nonce
- end
-
- def check_nonce(req, auth_req)
- username = auth_req['username']
- nonce = auth_req['nonce']
-
- pub_time, pk = nonce.unpack("m*")[0].split(":", 2)
- if (!pub_time || !pk)
- error("%s: empty nonce is given", username)
- return false
- elsif (hexdigest(pub_time, @instance_key)[0,32] != pk)
- error("%s: invalid private-key: %s for %s",
- username, hexdigest(pub_time, @instance_key)[0,32], pk)
- return false
- end
-
- diff_time = req.request_time.to_i - pub_time.to_i
- if (diff_time < 0)
- error("%s: difference of time-stamp is negative.", username)
- return false
- elsif diff_time > @nonce_expire_period
- error("%s: nonce is expired.", username)
- return false
- end
-
- return true
- end
-
- def generate_opaque(req)
- @mutex.synchronize{
- now = req.request_time
- if now - @last_nonce_expire > @nonce_expire_delta
- @opaques.delete_if{|key,val|
- (now - val.time) > @nonce_expire_period
- }
- @last_nonce_expire = now
- end
- begin
- opaque = Utils::random_string(16)
- end while @opaques[opaque]
- @opaques[opaque] = OpaqueInfo.new(now, nil, '00000001')
- opaque
- }
- end
-
- def check_opaque(opaque_struct, req, auth_req)
- if (@use_next_nonce && auth_req['nonce'] != opaque_struct.nonce)
- error('%s: nonce unmatched. "%s" for "%s"',
- auth_req['username'], auth_req['nonce'], opaque_struct.nonce)
- return false
- elsif !check_nonce(req, auth_req)
- return false
- end
- if (@check_nc && auth_req['nc'] != opaque_struct.nc)
- error('%s: nc unmatched."%s" for "%s"',
- auth_req['username'], auth_req['nc'], opaque_struct.nc)
- return false
- end
- true
- end
-
- def check_uri(req, auth_req)
- uri = auth_req['uri']
- if uri != req.request_uri.to_s && uri != req.unparsed_uri &&
- (@internet_explorer_hack && uri != req.path)
- error('%s: uri unmatch. "%s" for "%s"', auth_req['username'],
- auth_req['uri'], req.request_uri.to_s)
- return false
- end
- true
- end
-
- def hexdigest(*args)
- @h.hexdigest(args.join(":"))
- end
-
- # :startdoc:
- end
-
- ##
- # Digest authentication for proxy servers. See DigestAuth for details.
-
- class ProxyDigestAuth < DigestAuth
- include ProxyAuthenticator
-
- private
- def check_uri(req, auth_req) # :nodoc:
- return true
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/webrick/httpauth/htdigest.rb b/ruby_2_2/lib/webrick/httpauth/htdigest.rb
deleted file mode 100644
index 5fb0635e2a..0000000000
--- a/ruby_2_2/lib/webrick/httpauth/htdigest.rb
+++ /dev/null
@@ -1,131 +0,0 @@
-#
-# httpauth/htdigest.rb -- Apache compatible htdigest file
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2003 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: htdigest.rb,v 1.4 2003/07/22 19:20:45 gotoyuzo Exp $
-
-require 'webrick/httpauth/userdb'
-require 'webrick/httpauth/digestauth'
-require 'tempfile'
-
-module WEBrick
- module HTTPAuth
-
- ##
- # Htdigest accesses apache-compatible digest password files. Passwords are
- # matched to a realm where they are valid. For security, the path for a
- # digest password database should be stored outside of the paths available
- # to the HTTP server.
- #
- # Htdigest is intended for use with WEBrick::HTTPAuth::DigestAuth and
- # stores passwords using cryptographic hashes.
- #
- # htpasswd = WEBrick::HTTPAuth::Htdigest.new 'my_password_file'
- # htpasswd.set_passwd 'my realm', 'username', 'password'
- # htpasswd.flush
-
- class Htdigest
- include UserDB
-
- ##
- # Open a digest password database at +path+
-
- def initialize(path)
- @path = path
- @mtime = Time.at(0)
- @digest = Hash.new
- @mutex = Mutex::new
- @auth_type = DigestAuth
- open(@path,"a").close unless File::exist?(@path)
- reload
- end
-
- ##
- # Reloads passwords from the database
-
- def reload
- mtime = File::mtime(@path)
- if mtime > @mtime
- @digest.clear
- open(@path){|io|
- while line = io.gets
- line.chomp!
- user, realm, pass = line.split(/:/, 3)
- unless @digest[realm]
- @digest[realm] = Hash.new
- end
- @digest[realm][user] = pass
- end
- }
- @mtime = mtime
- end
- end
-
- ##
- # Flush the password database. If +output+ is given the database will
- # be written there instead of to the original path.
-
- def flush(output=nil)
- output ||= @path
- tmp = Tempfile.create("htpasswd", File::dirname(output))
- renamed = false
- begin
- each{|item| tmp.puts(item.join(":")) }
- tmp.close
- File::rename(tmp.path, output)
- renamed = true
- ensure
- tmp.close if !tmp.closed?
- File.unlink(tmp.path) if !renamed
- end
- end
-
- ##
- # Retrieves a password from the database for +user+ in +realm+. If
- # +reload_db+ is true the database will be reloaded first.
-
- def get_passwd(realm, user, reload_db)
- reload() if reload_db
- if hash = @digest[realm]
- hash[user]
- end
- end
-
- ##
- # Sets a password in the database for +user+ in +realm+ to +pass+.
-
- def set_passwd(realm, user, pass)
- @mutex.synchronize{
- unless @digest[realm]
- @digest[realm] = Hash.new
- end
- @digest[realm][user] = make_passwd(realm, user, pass)
- }
- end
-
- ##
- # Removes a password from the database for +user+ in +realm+.
-
- def delete_passwd(realm, user)
- if hash = @digest[realm]
- hash.delete(user)
- end
- end
-
- ##
- # Iterate passwords in the database.
-
- def each # :yields: [user, realm, password_hash]
- @digest.keys.sort.each{|realm|
- hash = @digest[realm]
- hash.keys.sort.each{|user|
- yield([user, realm, hash[user]])
- }
- }
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/webrick/httpauth/htgroup.rb b/ruby_2_2/lib/webrick/httpauth/htgroup.rb
deleted file mode 100644
index 0ecabef820..0000000000
--- a/ruby_2_2/lib/webrick/httpauth/htgroup.rb
+++ /dev/null
@@ -1,93 +0,0 @@
-#
-# httpauth/htgroup.rb -- Apache compatible htgroup file
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2003 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: htgroup.rb,v 1.1 2003/02/16 22:22:56 gotoyuzo Exp $
-
-require 'tempfile'
-
-module WEBrick
- module HTTPAuth
-
- ##
- # Htgroup accesses apache-compatible group files. Htgroup can be used to
- # provide group-based authentication for users. Currently Htgroup is not
- # directly integrated with any authenticators in WEBrick. For security,
- # the path for a digest password database should be stored outside of the
- # paths available to the HTTP server.
- #
- # Example:
- #
- # htgroup = WEBrick::HTTPAuth::Htgroup.new 'my_group_file'
- # htgroup.add 'superheroes', %w[spiderman batman]
- #
- # htgroup.members('superheroes').include? 'magneto' # => false
-
- class Htgroup
-
- ##
- # Open a group database at +path+
-
- def initialize(path)
- @path = path
- @mtime = Time.at(0)
- @group = Hash.new
- open(@path,"a").close unless File::exist?(@path)
- reload
- end
-
- ##
- # Reload groups from the database
-
- def reload
- if (mtime = File::mtime(@path)) > @mtime
- @group.clear
- open(@path){|io|
- while line = io.gets
- line.chomp!
- group, members = line.split(/:\s*/)
- @group[group] = members.split(/\s+/)
- end
- }
- @mtime = mtime
- end
- end
-
- ##
- # Flush the group database. If +output+ is given the database will be
- # written there instead of to the original path.
-
- def flush(output=nil)
- output ||= @path
- tmp = Tempfile.new("htgroup", File::dirname(output))
- begin
- @group.keys.sort.each{|group|
- tmp.puts(format("%s: %s", group, self.members(group).join(" ")))
- }
- tmp.close
- File::rename(tmp.path, output)
- rescue
- tmp.close(true)
- end
- end
-
- ##
- # Retrieve the list of members from +group+
-
- def members(group)
- reload
- @group[group] || []
- end
-
- ##
- # Add an Array of +members+ to +group+
-
- def add(group, members)
- @group[group] = members(group) | members
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/webrick/httpauth/htpasswd.rb b/ruby_2_2/lib/webrick/httpauth/htpasswd.rb
deleted file mode 100644
index 69b739fbfe..0000000000
--- a/ruby_2_2/lib/webrick/httpauth/htpasswd.rb
+++ /dev/null
@@ -1,124 +0,0 @@
-#
-# httpauth/htpasswd -- Apache compatible htpasswd file
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2003 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: htpasswd.rb,v 1.4 2003/07/22 19:20:45 gotoyuzo Exp $
-
-require 'webrick/httpauth/userdb'
-require 'webrick/httpauth/basicauth'
-require 'tempfile'
-
-module WEBrick
- module HTTPAuth
-
- ##
- # Htpasswd accesses apache-compatible password files. Passwords are
- # matched to a realm where they are valid. For security, the path for a
- # password database should be stored outside of the paths available to the
- # HTTP server.
- #
- # Htpasswd is intended for use with WEBrick::HTTPAuth::BasicAuth.
- #
- # To create an Htpasswd database with a single user:
- #
- # htpasswd = WEBrick::HTTPAuth::Htpasswd.new 'my_password_file'
- # htpasswd.set_passwd 'my realm', 'username', 'password'
- # htpasswd.flush
-
- class Htpasswd
- include UserDB
-
- ##
- # Open a password database at +path+
-
- def initialize(path)
- @path = path
- @mtime = Time.at(0)
- @passwd = Hash.new
- @auth_type = BasicAuth
- open(@path,"a").close unless File::exist?(@path)
- reload
- end
-
- ##
- # Reload passwords from the database
-
- def reload
- mtime = File::mtime(@path)
- if mtime > @mtime
- @passwd.clear
- open(@path){|io|
- while line = io.gets
- line.chomp!
- case line
- when %r!\A[^:]+:[a-zA-Z0-9./]{13}\z!
- user, pass = line.split(":")
- when /:\$/, /:{SHA}/
- raise NotImplementedError,
- 'MD5, SHA1 .htpasswd file not supported'
- else
- raise StandardError, 'bad .htpasswd file'
- end
- @passwd[user] = pass
- end
- }
- @mtime = mtime
- end
- end
-
- ##
- # Flush the password database. If +output+ is given the database will
- # be written there instead of to the original path.
-
- def flush(output=nil)
- output ||= @path
- tmp = Tempfile.create("htpasswd", File::dirname(output))
- renamed = false
- begin
- each{|item| tmp.puts(item.join(":")) }
- tmp.close
- File::rename(tmp.path, output)
- renamed = true
- ensure
- tmp.close if !tmp.closed?
- File.unlink(tmp.path) if !renamed
- end
- end
-
- ##
- # Retrieves a password from the database for +user+ in +realm+. If
- # +reload_db+ is true the database will be reloaded first.
-
- def get_passwd(realm, user, reload_db)
- reload() if reload_db
- @passwd[user]
- end
-
- ##
- # Sets a password in the database for +user+ in +realm+ to +pass+.
-
- def set_passwd(realm, user, pass)
- @passwd[user] = make_passwd(realm, user, pass)
- end
-
- ##
- # Removes a password from the database for +user+ in +realm+.
-
- def delete_passwd(realm, user)
- @passwd.delete(user)
- end
-
- ##
- # Iterate passwords in the database.
-
- def each # :yields: [user, password]
- @passwd.keys.sort.each{|user|
- yield([user, @passwd[user]])
- }
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/webrick/httpauth/userdb.rb b/ruby_2_2/lib/webrick/httpauth/userdb.rb
deleted file mode 100644
index 005c18dfd0..0000000000
--- a/ruby_2_2/lib/webrick/httpauth/userdb.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-#--
-# httpauth/userdb.rb -- UserDB mix-in module.
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2003 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: userdb.rb,v 1.2 2003/02/20 07:15:48 gotoyuzo Exp $
-
-module WEBrick
- module HTTPAuth
-
- ##
- # User database mixin for HTTPAuth. This mixin dispatches user record
- # access to the underlying auth_type for this database.
-
- module UserDB
-
- ##
- # The authentication type.
- #
- # WEBrick::HTTPAuth::BasicAuth or WEBrick::HTTPAuth::DigestAuth are
- # built-in.
-
- attr_accessor :auth_type
-
- ##
- # Creates an obscured password in +realm+ with +user+ and +password+
- # using the auth_type of this database.
-
- def make_passwd(realm, user, pass)
- @auth_type::make_passwd(realm, user, pass)
- end
-
- ##
- # Sets a password in +realm+ with +user+ and +password+ for the
- # auth_type of this database.
-
- def set_passwd(realm, user, pass)
- self[user] = pass
- end
-
- ##
- # Retrieves a password in +realm+ for +user+ for the auth_type of this
- # database. +reload_db+ is a dummy value.
-
- def get_passwd(realm, user, reload_db=false)
- make_passwd(realm, user, self[user])
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/webrick/httpproxy.rb b/ruby_2_2/lib/webrick/httpproxy.rb
deleted file mode 100644
index cbba2d80f7..0000000000
--- a/ruby_2_2/lib/webrick/httpproxy.rb
+++ /dev/null
@@ -1,337 +0,0 @@
-#
-# httpproxy.rb -- HTTPProxy Class
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2002 GOTO Kentaro
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: httpproxy.rb,v 1.18 2003/03/08 18:58:10 gotoyuzo Exp $
-# $kNotwork: straw.rb,v 1.3 2002/02/12 15:13:07 gotoken Exp $
-
-require "webrick/httpserver"
-require "net/http"
-
-module WEBrick
-
- NullReader = Object.new # :nodoc:
- class << NullReader # :nodoc:
- def read(*args)
- nil
- end
- alias gets read
- end
-
- FakeProxyURI = Object.new # :nodoc:
- class << FakeProxyURI # :nodoc:
- def method_missing(meth, *args)
- if %w(scheme host port path query userinfo).member?(meth.to_s)
- return nil
- end
- super
- end
- end
-
- # :startdoc:
-
- ##
- # An HTTP Proxy server which proxies GET, HEAD and POST requests.
- #
- # To create a simple proxy server:
- #
- # require 'webrick'
- # require 'webrick/httpproxy'
- #
- # proxy = WEBrick::HTTPProxyServer.new Port: 8000
- #
- # trap 'INT' do proxy.shutdown end
- # trap 'TERM' do proxy.shutdown end
- #
- # proxy.start
- #
- # See ::new for proxy-specific configuration items.
- #
- # == Modifying proxied responses
- #
- # To modify content the proxy server returns use the +:ProxyContentHandler+
- # option:
- #
- # handler = proc do |req, res|
- # if res['content-type'] == 'text/plain' then
- # res.body << "\nThis content was proxied!\n"
- # end
- # end
- #
- # proxy =
- # WEBrick::HTTPProxyServer.new Port: 8000, ProxyContentHandler: handler
-
- class HTTPProxyServer < HTTPServer
-
- ##
- # Proxy server configurations. The proxy server handles the following
- # configuration items in addition to those supported by HTTPServer:
- #
- # :ProxyAuthProc:: Called with a request and response to authorize a
- # request
- # :ProxyVia:: Appended to the via header
- # :ProxyURI:: The proxy server's URI
- # :ProxyContentHandler:: Called with a request and response and allows
- # modification of the response
- # :ProxyTimeout:: Sets the proxy timeouts to 30 seconds for open and 60
- # seconds for read operations
-
- def initialize(config={}, default=Config::HTTP)
- super(config, default)
- c = @config
- @via = "#{c[:HTTPVersion]} #{c[:ServerName]}:#{c[:Port]}"
- end
-
- # :stopdoc:
- def service(req, res)
- if req.request_method == "CONNECT"
- do_CONNECT(req, res)
- elsif req.unparsed_uri =~ %r!^http://!
- proxy_service(req, res)
- else
- super(req, res)
- end
- end
-
- def proxy_auth(req, res)
- if proc = @config[:ProxyAuthProc]
- proc.call(req, res)
- end
- req.header.delete("proxy-authorization")
- end
-
- def proxy_uri(req, res)
- # should return upstream proxy server's URI
- return @config[:ProxyURI]
- end
-
- def proxy_service(req, res)
- # Proxy Authentication
- proxy_auth(req, res)
-
- begin
- self.send("do_#{req.request_method}", req, res)
- rescue NoMethodError
- raise HTTPStatus::MethodNotAllowed,
- "unsupported method `#{req.request_method}'."
- rescue => err
- logger.debug("#{err.class}: #{err.message}")
- raise HTTPStatus::ServiceUnavailable, err.message
- end
-
- # Process contents
- if handler = @config[:ProxyContentHandler]
- handler.call(req, res)
- end
- end
-
- def do_CONNECT(req, res)
- # Proxy Authentication
- proxy_auth(req, res)
-
- ua = Thread.current[:WEBrickSocket] # User-Agent
- raise HTTPStatus::InternalServerError,
- "[BUG] cannot get socket" unless ua
-
- host, port = req.unparsed_uri.split(":", 2)
- # Proxy authentication for upstream proxy server
- if proxy = proxy_uri(req, res)
- proxy_request_line = "CONNECT #{host}:#{port} HTTP/1.0"
- if proxy.userinfo
- credentials = "Basic " + [proxy.userinfo].pack("m").delete("\n")
- end
- host, port = proxy.host, proxy.port
- end
-
- begin
- @logger.debug("CONNECT: upstream proxy is `#{host}:#{port}'.")
- os = TCPSocket.new(host, port) # origin server
-
- if proxy
- @logger.debug("CONNECT: sending a Request-Line")
- os << proxy_request_line << CRLF
- @logger.debug("CONNECT: > #{proxy_request_line}")
- if credentials
- @logger.debug("CONNECT: sending a credentials")
- os << "Proxy-Authorization: " << credentials << CRLF
- end
- os << CRLF
- proxy_status_line = os.gets(LF)
- @logger.debug("CONNECT: read a Status-Line form the upstream server")
- @logger.debug("CONNECT: < #{proxy_status_line}")
- if %r{^HTTP/\d+\.\d+\s+200\s*} =~ proxy_status_line
- while line = os.gets(LF)
- break if /\A(#{CRLF}|#{LF})\z/om =~ line
- end
- else
- raise HTTPStatus::BadGateway
- end
- end
- @logger.debug("CONNECT #{host}:#{port}: succeeded")
- res.status = HTTPStatus::RC_OK
- rescue => ex
- @logger.debug("CONNECT #{host}:#{port}: failed `#{ex.message}'")
- res.set_error(ex)
- raise HTTPStatus::EOFError
- ensure
- if handler = @config[:ProxyContentHandler]
- handler.call(req, res)
- end
- res.send_response(ua)
- access_log(@config, req, res)
-
- # Should clear request-line not to send the response twice.
- # see: HTTPServer#run
- req.parse(NullReader) rescue nil
- end
-
- begin
- while fds = IO::select([ua, os])
- if fds[0].member?(ua)
- buf = ua.sysread(1024);
- @logger.debug("CONNECT: #{buf.bytesize} byte from User-Agent")
- os.syswrite(buf)
- elsif fds[0].member?(os)
- buf = os.sysread(1024);
- @logger.debug("CONNECT: #{buf.bytesize} byte from #{host}:#{port}")
- ua.syswrite(buf)
- end
- end
- rescue
- os.close
- @logger.debug("CONNECT #{host}:#{port}: closed")
- end
-
- raise HTTPStatus::EOFError
- end
-
- def do_GET(req, res)
- perform_proxy_request(req, res) do |http, path, header|
- http.get(path, header)
- end
- end
-
- def do_HEAD(req, res)
- perform_proxy_request(req, res) do |http, path, header|
- http.head(path, header)
- end
- end
-
- def do_POST(req, res)
- perform_proxy_request(req, res) do |http, path, header|
- http.post(path, req.body || "", header)
- end
- end
-
- def do_OPTIONS(req, res)
- res['allow'] = "GET,HEAD,POST,OPTIONS,CONNECT"
- end
-
- private
-
- # Some header fields should not be transferred.
- HopByHop = %w( connection keep-alive proxy-authenticate upgrade
- proxy-authorization te trailers transfer-encoding )
- ShouldNotTransfer = %w( set-cookie proxy-connection )
- def split_field(f) f ? f.split(/,\s+/).collect{|i| i.downcase } : [] end
-
- def choose_header(src, dst)
- connections = split_field(src['connection'])
- src.each{|key, value|
- key = key.downcase
- if HopByHop.member?(key) || # RFC2616: 13.5.1
- connections.member?(key) || # RFC2616: 14.10
- ShouldNotTransfer.member?(key) # pragmatics
- @logger.debug("choose_header: `#{key}: #{value}'")
- next
- end
- dst[key] = value
- }
- end
-
- # Net::HTTP is stupid about the multiple header fields.
- # Here is workaround:
- def set_cookie(src, dst)
- if str = src['set-cookie']
- cookies = []
- str.split(/,\s*/).each{|token|
- if /^[^=]+;/o =~ token
- cookies[-1] << ", " << token
- elsif /=/o =~ token
- cookies << token
- else
- cookies[-1] << ", " << token
- end
- }
- dst.cookies.replace(cookies)
- end
- end
-
- def set_via(h)
- if @config[:ProxyVia]
- if h['via']
- h['via'] << ", " << @via
- else
- h['via'] = @via
- end
- end
- end
-
- def setup_proxy_header(req, res)
- # Choose header fields to transfer
- header = Hash.new
- choose_header(req, header)
- set_via(header)
- return header
- end
-
- def setup_upstream_proxy_authentication(req, res, header)
- if upstream = proxy_uri(req, res)
- if upstream.userinfo
- header['proxy-authorization'] =
- "Basic " + [upstream.userinfo].pack("m").delete("\n")
- end
- return upstream
- end
- return FakeProxyURI
- end
-
- def perform_proxy_request(req, res)
- uri = req.request_uri
- path = uri.path.dup
- path << "?" << uri.query if uri.query
- header = setup_proxy_header(req, res)
- upstream = setup_upstream_proxy_authentication(req, res, header)
- response = nil
-
- http = Net::HTTP.new(uri.host, uri.port, upstream.host, upstream.port)
- http.start do
- if @config[:ProxyTimeout]
- ################################## these issues are
- http.open_timeout = 30 # secs # necessary (maybe because
- http.read_timeout = 60 # secs # Ruby's bug, but why?)
- ##################################
- end
- response = yield(http, path, header)
- end
-
- # Persistent connection requirements are mysterious for me.
- # So I will close the connection in every response.
- res['proxy-connection'] = "close"
- res['connection'] = "close"
-
- # Convert Net::HTTP::HTTPResponse to WEBrick::HTTPResponse
- res.status = response.code.to_i
- choose_header(response, res)
- set_cookie(response, res)
- set_via(res)
- res.body = response.body
- end
-
- # :stopdoc:
- end
-end
diff --git a/ruby_2_2/lib/webrick/httprequest.rb b/ruby_2_2/lib/webrick/httprequest.rb
deleted file mode 100644
index 6aa2d1c1f2..0000000000
--- a/ruby_2_2/lib/webrick/httprequest.rb
+++ /dev/null
@@ -1,584 +0,0 @@
-#
-# httprequest.rb -- HTTPRequest Class
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2000, 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: httprequest.rb,v 1.64 2003/07/13 17:18:22 gotoyuzo Exp $
-
-require 'uri'
-require 'webrick/httpversion'
-require 'webrick/httpstatus'
-require 'webrick/httputils'
-require 'webrick/cookie'
-
-module WEBrick
-
- ##
- # An HTTP request. This is consumed by service and do_* methods in
- # WEBrick servlets
-
- class HTTPRequest
-
- BODY_CONTAINABLE_METHODS = [ "POST", "PUT" ] # :nodoc:
-
- # :section: Request line
-
- ##
- # The complete request line such as:
- #
- # GET / HTTP/1.1
-
- attr_reader :request_line
-
- ##
- # The request method, GET, POST, PUT, etc.
-
- attr_reader :request_method
-
- ##
- # The unparsed URI of the request
-
- attr_reader :unparsed_uri
-
- ##
- # The HTTP version of the request
-
- attr_reader :http_version
-
- # :section: Request-URI
-
- ##
- # The parsed URI of the request
-
- attr_reader :request_uri
-
- ##
- # The request path
-
- attr_reader :path
-
- ##
- # The script name (CGI variable)
-
- attr_accessor :script_name
-
- ##
- # The path info (CGI variable)
-
- attr_accessor :path_info
-
- ##
- # The query from the URI of the request
-
- attr_accessor :query_string
-
- # :section: Header and entity body
-
- ##
- # The raw header of the request
-
- attr_reader :raw_header
-
- ##
- # The parsed header of the request
-
- attr_reader :header
-
- ##
- # The parsed request cookies
-
- attr_reader :cookies
-
- ##
- # The Accept header value
-
- attr_reader :accept
-
- ##
- # The Accept-Charset header value
-
- attr_reader :accept_charset
-
- ##
- # The Accept-Encoding header value
-
- attr_reader :accept_encoding
-
- ##
- # The Accept-Language header value
-
- attr_reader :accept_language
-
- # :section:
-
- ##
- # The remote user (CGI variable)
-
- attr_accessor :user
-
- ##
- # The socket address of the server
-
- attr_reader :addr
-
- ##
- # The socket address of the client
-
- attr_reader :peeraddr
-
- ##
- # Hash of request attributes
-
- attr_reader :attributes
-
- ##
- # Is this a keep-alive connection?
-
- attr_reader :keep_alive
-
- ##
- # The local time this request was received
-
- attr_reader :request_time
-
- ##
- # Creates a new HTTP request. WEBrick::Config::HTTP is the default
- # configuration.
-
- def initialize(config)
- @config = config
- @buffer_size = @config[:InputBufferSize]
- @logger = config[:Logger]
-
- @request_line = @request_method =
- @unparsed_uri = @http_version = nil
-
- @request_uri = @host = @port = @path = nil
- @script_name = @path_info = nil
- @query_string = nil
- @query = nil
- @form_data = nil
-
- @raw_header = Array.new
- @header = nil
- @cookies = []
- @accept = []
- @accept_charset = []
- @accept_encoding = []
- @accept_language = []
- @body = ""
-
- @addr = @peeraddr = nil
- @attributes = {}
- @user = nil
- @keep_alive = false
- @request_time = nil
-
- @remaining_size = nil
- @socket = nil
-
- @forwarded_proto = @forwarded_host = @forwarded_port =
- @forwarded_server = @forwarded_for = nil
- end
-
- ##
- # Parses a request from +socket+. This is called internally by
- # WEBrick::HTTPServer.
-
- def parse(socket=nil)
- @socket = socket
- begin
- @peeraddr = socket.respond_to?(:peeraddr) ? socket.peeraddr : []
- @addr = socket.respond_to?(:addr) ? socket.addr : []
- rescue Errno::ENOTCONN
- raise HTTPStatus::EOFError
- end
-
- read_request_line(socket)
- if @http_version.major > 0
- read_header(socket)
- @header['cookie'].each{|cookie|
- @cookies += Cookie::parse(cookie)
- }
- @accept = HTTPUtils.parse_qvalues(self['accept'])
- @accept_charset = HTTPUtils.parse_qvalues(self['accept-charset'])
- @accept_encoding = HTTPUtils.parse_qvalues(self['accept-encoding'])
- @accept_language = HTTPUtils.parse_qvalues(self['accept-language'])
- end
- return if @request_method == "CONNECT"
- return if @unparsed_uri == "*"
-
- begin
- setup_forwarded_info
- @request_uri = parse_uri(@unparsed_uri)
- @path = HTTPUtils::unescape(@request_uri.path)
- @path = HTTPUtils::normalize_path(@path)
- @host = @request_uri.host
- @port = @request_uri.port
- @query_string = @request_uri.query
- @script_name = ""
- @path_info = @path.dup
- rescue
- raise HTTPStatus::BadRequest, "bad URI `#{@unparsed_uri}'."
- end
-
- if /close/io =~ self["connection"]
- @keep_alive = false
- elsif /keep-alive/io =~ self["connection"]
- @keep_alive = true
- elsif @http_version < "1.1"
- @keep_alive = false
- else
- @keep_alive = true
- end
- end
-
- ##
- # Generate HTTP/1.1 100 continue response if the client expects it,
- # otherwise does nothing.
-
- def continue # :nodoc:
- if self['expect'] == '100-continue' && @config[:HTTPVersion] >= "1.1"
- @socket << "HTTP/#{@config[:HTTPVersion]} 100 continue#{CRLF}#{CRLF}"
- @header.delete('expect')
- end
- end
-
- ##
- # Returns the request body.
-
- def body(&block) # :yields: body_chunk
- block ||= Proc.new{|chunk| @body << chunk }
- read_body(@socket, block)
- @body.empty? ? nil : @body
- end
-
- ##
- # Request query as a Hash
-
- def query
- unless @query
- parse_query()
- end
- @query
- end
-
- ##
- # The content-length header
-
- def content_length
- return Integer(self['content-length'])
- end
-
- ##
- # The content-type header
-
- def content_type
- return self['content-type']
- end
-
- ##
- # Retrieves +header_name+
-
- def [](header_name)
- if @header
- value = @header[header_name.downcase]
- value.empty? ? nil : value.join(", ")
- end
- end
-
- ##
- # Iterates over the request headers
-
- def each
- if @header
- @header.each{|k, v|
- value = @header[k]
- yield(k, value.empty? ? nil : value.join(", "))
- }
- end
- end
-
- ##
- # The host this request is for
-
- def host
- return @forwarded_host || @host
- end
-
- ##
- # The port this request is for
-
- def port
- return @forwarded_port || @port
- end
-
- ##
- # The server name this request is for
-
- def server_name
- return @forwarded_server || @config[:ServerName]
- end
-
- ##
- # The client's IP address
-
- def remote_ip
- return self["client-ip"] || @forwarded_for || @peeraddr[3]
- end
-
- ##
- # Is this an SSL request?
-
- def ssl?
- return @request_uri.scheme == "https"
- end
-
- ##
- # Should the connection this request was made on be kept alive?
-
- def keep_alive?
- @keep_alive
- end
-
- def to_s # :nodoc:
- ret = @request_line.dup
- @raw_header.each{|line| ret << line }
- ret << CRLF
- ret << body if body
- ret
- end
-
- ##
- # Consumes any remaining body and updates keep-alive status
-
- def fixup() # :nodoc:
- begin
- body{|chunk| } # read remaining body
- rescue HTTPStatus::Error => ex
- @logger.error("HTTPRequest#fixup: #{ex.class} occurred.")
- @keep_alive = false
- rescue => ex
- @logger.error(ex)
- @keep_alive = false
- end
- end
-
- # This method provides the metavariables defined by the revision 3
- # of "The WWW Common Gateway Interface Version 1.1"
- # To browse the current document of CGI Version 1.1, see below:
- # http://tools.ietf.org/html/rfc3875
-
- def meta_vars
- meta = Hash.new
-
- cl = self["Content-Length"]
- ct = self["Content-Type"]
- meta["CONTENT_LENGTH"] = cl if cl.to_i > 0
- meta["CONTENT_TYPE"] = ct.dup if ct
- meta["GATEWAY_INTERFACE"] = "CGI/1.1"
- meta["PATH_INFO"] = @path_info ? @path_info.dup : ""
- #meta["PATH_TRANSLATED"] = nil # no plan to be provided
- meta["QUERY_STRING"] = @query_string ? @query_string.dup : ""
- meta["REMOTE_ADDR"] = @peeraddr[3]
- meta["REMOTE_HOST"] = @peeraddr[2]
- #meta["REMOTE_IDENT"] = nil # no plan to be provided
- meta["REMOTE_USER"] = @user
- meta["REQUEST_METHOD"] = @request_method.dup
- meta["REQUEST_URI"] = @request_uri.to_s
- meta["SCRIPT_NAME"] = @script_name.dup
- meta["SERVER_NAME"] = @host
- meta["SERVER_PORT"] = @port.to_s
- meta["SERVER_PROTOCOL"] = "HTTP/" + @config[:HTTPVersion].to_s
- meta["SERVER_SOFTWARE"] = @config[:ServerSoftware].dup
-
- self.each{|key, val|
- next if /^content-type$/i =~ key
- next if /^content-length$/i =~ key
- name = "HTTP_" + key
- name.gsub!(/-/o, "_")
- name.upcase!
- meta[name] = val
- }
-
- meta
- end
-
- private
-
- # :stopdoc:
-
- MAX_URI_LENGTH = 2083 # :nodoc:
-
- def read_request_line(socket)
- @request_line = read_line(socket, MAX_URI_LENGTH) if socket
- if @request_line.bytesize >= MAX_URI_LENGTH and @request_line[-1, 1] != LF
- raise HTTPStatus::RequestURITooLarge
- end
- @request_time = Time.now
- raise HTTPStatus::EOFError unless @request_line
- if /^(\S+)\s+(\S++)(?:\s+HTTP\/(\d+\.\d+))?\r?\n/mo =~ @request_line
- @request_method = $1
- @unparsed_uri = $2
- @http_version = HTTPVersion.new($3 ? $3 : "0.9")
- else
- rl = @request_line.sub(/\x0d?\x0a\z/o, '')
- raise HTTPStatus::BadRequest, "bad Request-Line `#{rl}'."
- end
- end
-
- def read_header(socket)
- if socket
- while line = read_line(socket)
- break if /\A(#{CRLF}|#{LF})\z/om =~ line
- @raw_header << line
- end
- end
- @header = HTTPUtils::parse_header(@raw_header.join)
- end
-
- def parse_uri(str, scheme="http")
- if @config[:Escape8bitURI]
- str = HTTPUtils::escape8bit(str)
- end
- str.sub!(%r{\A/+}o, '/')
- uri = URI::parse(str)
- return uri if uri.absolute?
- if @forwarded_host
- host, port = @forwarded_host, @forwarded_port
- elsif self["host"]
- pattern = /\A(#{URI::REGEXP::PATTERN::HOST})(?::(\d+))?\z/n
- host, port = *self['host'].scan(pattern)[0]
- elsif @addr.size > 0
- host, port = @addr[2], @addr[1]
- else
- host, port = @config[:ServerName], @config[:Port]
- end
- uri.scheme = @forwarded_proto || scheme
- uri.host = host
- uri.port = port ? port.to_i : nil
- return URI::parse(uri.to_s)
- end
-
- def read_body(socket, block)
- return unless socket
- if tc = self['transfer-encoding']
- case tc
- when /chunked/io then read_chunked(socket, block)
- else raise HTTPStatus::NotImplemented, "Transfer-Encoding: #{tc}."
- end
- elsif self['content-length'] || @remaining_size
- @remaining_size ||= self['content-length'].to_i
- while @remaining_size > 0
- sz = [@buffer_size, @remaining_size].min
- break unless buf = read_data(socket, sz)
- @remaining_size -= buf.bytesize
- block.call(buf)
- end
- if @remaining_size > 0 && @socket.eof?
- raise HTTPStatus::BadRequest, "invalid body size."
- end
- elsif BODY_CONTAINABLE_METHODS.member?(@request_method)
- raise HTTPStatus::LengthRequired
- end
- return @body
- end
-
- def read_chunk_size(socket)
- line = read_line(socket)
- if /^([0-9a-fA-F]+)(?:;(\S+))?/ =~ line
- chunk_size = $1.hex
- chunk_ext = $2
- [ chunk_size, chunk_ext ]
- else
- raise HTTPStatus::BadRequest, "bad chunk `#{line}'."
- end
- end
-
- def read_chunked(socket, block)
- chunk_size, = read_chunk_size(socket)
- while chunk_size > 0
- data = read_data(socket, chunk_size) # read chunk-data
- if data.nil? || data.bytesize != chunk_size
- raise BadRequest, "bad chunk data size."
- end
- read_line(socket) # skip CRLF
- block.call(data)
- chunk_size, = read_chunk_size(socket)
- end
- read_header(socket) # trailer + CRLF
- @header.delete("transfer-encoding")
- @remaining_size = 0
- end
-
- def _read_data(io, method, *arg)
- begin
- WEBrick::Utils.timeout(@config[:RequestTimeout]){
- return io.__send__(method, *arg)
- }
- rescue Errno::ECONNRESET
- return nil
- rescue Timeout::Error
- raise HTTPStatus::RequestTimeout
- end
- end
-
- def read_line(io, size=4096)
- _read_data(io, :gets, LF, size)
- end
-
- def read_data(io, size)
- _read_data(io, :read, size)
- end
-
- def parse_query()
- begin
- if @request_method == "GET" || @request_method == "HEAD"
- @query = HTTPUtils::parse_query(@query_string)
- elsif self['content-type'] =~ /^application\/x-www-form-urlencoded/
- @query = HTTPUtils::parse_query(body)
- elsif self['content-type'] =~ /^multipart\/form-data; boundary=(.+)/
- boundary = HTTPUtils::dequote($1)
- @query = HTTPUtils::parse_form_data(body, boundary)
- else
- @query = Hash.new
- end
- rescue => ex
- raise HTTPStatus::BadRequest, ex.message
- end
- end
-
- PrivateNetworkRegexp = /
- ^unknown$|
- ^((::ffff:)?127.0.0.1|::1)$|
- ^(::ffff:)?(10|172\.(1[6-9]|2[0-9]|3[01])|192\.168)\.
- /ixo
-
- # It's said that all X-Forwarded-* headers will contain more than one
- # (comma-separated) value if the original request already contained one of
- # these headers. Since we could use these values as Host header, we choose
- # the initial(first) value. (apr_table_mergen() adds new value after the
- # existing value with ", " prefix)
- def setup_forwarded_info
- if @forwarded_server = self["x-forwarded-server"]
- @forwarded_server = @forwarded_server.split(",", 2).first
- end
- @forwarded_proto = self["x-forwarded-proto"]
- if host_port = self["x-forwarded-host"]
- host_port = host_port.split(",", 2).first
- @forwarded_host, tmp = host_port.split(":", 2)
- @forwarded_port = (tmp || (@forwarded_proto == "https" ? 443 : 80)).to_i
- end
- if addrs = self["x-forwarded-for"]
- addrs = addrs.split(",").collect(&:strip)
- addrs.reject!{|ip| PrivateNetworkRegexp =~ ip }
- @forwarded_for = addrs.first
- end
- end
-
- # :startdoc:
- end
-end
diff --git a/ruby_2_2/lib/webrick/httpresponse.rb b/ruby_2_2/lib/webrick/httpresponse.rb
deleted file mode 100644
index e897e8c01b..0000000000
--- a/ruby_2_2/lib/webrick/httpresponse.rb
+++ /dev/null
@@ -1,466 +0,0 @@
-#
-# httpresponse.rb -- HTTPResponse Class
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2000, 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: httpresponse.rb,v 1.45 2003/07/11 11:02:25 gotoyuzo Exp $
-
-require 'time'
-require 'webrick/httpversion'
-require 'webrick/htmlutils'
-require 'webrick/httputils'
-require 'webrick/httpstatus'
-
-module WEBrick
- ##
- # An HTTP response. This is filled in by the service or do_* methods of a
- # WEBrick HTTP Servlet.
-
- class HTTPResponse
-
- ##
- # HTTP Response version
-
- attr_reader :http_version
-
- ##
- # Response status code (200)
-
- attr_reader :status
-
- ##
- # Response header
-
- attr_reader :header
-
- ##
- # Response cookies
-
- attr_reader :cookies
-
- ##
- # Response reason phrase ("OK")
-
- attr_accessor :reason_phrase
-
- ##
- # Body may be a String or IO-like object that responds to #read and
- # #readpartial.
-
- attr_accessor :body
-
- ##
- # Request method for this response
-
- attr_accessor :request_method
-
- ##
- # Request URI for this response
-
- attr_accessor :request_uri
-
- ##
- # Request HTTP version for this response
-
- attr_accessor :request_http_version
-
- ##
- # Filename of the static file in this response. Only used by the
- # FileHandler servlet.
-
- attr_accessor :filename
-
- ##
- # Is this a keep-alive response?
-
- attr_accessor :keep_alive
-
- ##
- # Configuration for this response
-
- attr_reader :config
-
- ##
- # Bytes sent in this response
-
- attr_reader :sent_size
-
- ##
- # Creates a new HTTP response object. WEBrick::Config::HTTP is the
- # default configuration.
-
- def initialize(config)
- @config = config
- @buffer_size = config[:OutputBufferSize]
- @logger = config[:Logger]
- @header = Hash.new
- @status = HTTPStatus::RC_OK
- @reason_phrase = nil
- @http_version = HTTPVersion::convert(@config[:HTTPVersion])
- @body = ''
- @keep_alive = true
- @cookies = []
- @request_method = nil
- @request_uri = nil
- @request_http_version = @http_version # temporary
- @chunked = false
- @filename = nil
- @sent_size = 0
- end
-
- ##
- # The response's HTTP status line
-
- def status_line
- "HTTP/#@http_version #@status #@reason_phrase #{CRLF}"
- end
-
- ##
- # Sets the response's status to the +status+ code
-
- def status=(status)
- @status = status
- @reason_phrase = HTTPStatus::reason_phrase(status)
- end
-
- ##
- # Retrieves the response header +field+
-
- def [](field)
- @header[field.downcase]
- end
-
- ##
- # Sets the response header +field+ to +value+
-
- def []=(field, value)
- @header[field.downcase] = value.to_s
- end
-
- ##
- # The content-length header
-
- def content_length
- if len = self['content-length']
- return Integer(len)
- end
- end
-
- ##
- # Sets the content-length header to +len+
-
- def content_length=(len)
- self['content-length'] = len.to_s
- end
-
- ##
- # The content-type header
-
- def content_type
- self['content-type']
- end
-
- ##
- # Sets the content-type header to +type+
-
- def content_type=(type)
- self['content-type'] = type
- end
-
- ##
- # Iterates over each header in the response
-
- def each
- @header.each{|field, value| yield(field, value) }
- end
-
- ##
- # Will this response body be returned using chunked transfer-encoding?
-
- def chunked?
- @chunked
- end
-
- ##
- # Enables chunked transfer encoding.
-
- def chunked=(val)
- @chunked = val ? true : false
- end
-
- ##
- # Will this response's connection be kept alive?
-
- def keep_alive?
- @keep_alive
- end
-
- ##
- # Sends the response on +socket+
-
- def send_response(socket) # :nodoc:
- begin
- setup_header()
- send_header(socket)
- send_body(socket)
- rescue Errno::EPIPE, Errno::ECONNRESET, Errno::ENOTCONN => ex
- @logger.debug(ex)
- @keep_alive = false
- rescue Exception => ex
- @logger.error(ex)
- @keep_alive = false
- end
- end
-
- ##
- # Sets up the headers for sending
-
- def setup_header() # :nodoc:
- @reason_phrase ||= HTTPStatus::reason_phrase(@status)
- @header['server'] ||= @config[:ServerSoftware]
- @header['date'] ||= Time.now.httpdate
-
- # HTTP/0.9 features
- if @request_http_version < "1.0"
- @http_version = HTTPVersion.new("0.9")
- @keep_alive = false
- end
-
- # HTTP/1.0 features
- if @request_http_version < "1.1"
- if chunked?
- @chunked = false
- ver = @request_http_version.to_s
- msg = "chunked is set for an HTTP/#{ver} request. (ignored)"
- @logger.warn(msg)
- end
- end
-
- # Determine the message length (RFC2616 -- 4.4 Message Length)
- if @status == 304 || @status == 204 || HTTPStatus::info?(@status)
- @header.delete('content-length')
- @body = ""
- elsif chunked?
- @header["transfer-encoding"] = "chunked"
- @header.delete('content-length')
- elsif %r{^multipart/byteranges} =~ @header['content-type']
- @header.delete('content-length')
- elsif @header['content-length'].nil?
- unless @body.is_a?(IO)
- @header['content-length'] = @body ? @body.bytesize : 0
- end
- end
-
- # Keep-Alive connection.
- if @header['connection'] == "close"
- @keep_alive = false
- elsif keep_alive?
- if chunked? || @header['content-length'] || @status == 304 || @status == 204 || HTTPStatus.info?(@status)
- @header['connection'] = "Keep-Alive"
- else
- msg = "Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true"
- @logger.warn(msg)
- @header['connection'] = "close"
- @keep_alive = false
- end
- else
- @header['connection'] = "close"
- end
-
- # Location is a single absoluteURI.
- if location = @header['location']
- if @request_uri
- @header['location'] = @request_uri.merge(location)
- end
- end
- end
-
- ##
- # Sends the headers on +socket+
-
- def send_header(socket) # :nodoc:
- if @http_version.major > 0
- data = status_line()
- @header.each{|key, value|
- tmp = key.gsub(/\bwww|^te$|\b\w/){ $&.upcase }
- data << "#{tmp}: #{value}" << CRLF
- }
- @cookies.each{|cookie|
- data << "Set-Cookie: " << cookie.to_s << CRLF
- }
- data << CRLF
- _write_data(socket, data)
- end
- end
-
- ##
- # Sends the body on +socket+
-
- def send_body(socket) # :nodoc:
- if @body.respond_to? :readpartial then
- send_body_io(socket)
- else
- send_body_string(socket)
- end
- end
-
- def to_s # :nodoc:
- ret = ""
- send_response(ret)
- ret
- end
-
- ##
- # Redirects to +url+ with a WEBrick::HTTPStatus::Redirect +status+.
- #
- # Example:
- #
- # res.set_redirect WEBrick::HTTPStatus::TemporaryRedirect
-
- def set_redirect(status, url)
- @body = "<HTML><A HREF=\"#{url}\">#{url}</A>.</HTML>\n"
- @header['location'] = url.to_s
- raise status
- end
-
- ##
- # Creates an error page for exception +ex+ with an optional +backtrace+
-
- def set_error(ex, backtrace=false)
- case ex
- when HTTPStatus::Status
- @keep_alive = false if HTTPStatus::error?(ex.code)
- self.status = ex.code
- else
- @keep_alive = false
- self.status = HTTPStatus::RC_INTERNAL_SERVER_ERROR
- end
- @header['content-type'] = "text/html; charset=ISO-8859-1"
-
- if respond_to?(:create_error_page)
- create_error_page()
- return
- end
-
- if @request_uri
- host, port = @request_uri.host, @request_uri.port
- else
- host, port = @config[:ServerName], @config[:Port]
- end
-
- @body = ''
- @body << <<-_end_of_html_
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
-<HTML>
- <HEAD><TITLE>#{HTMLUtils::escape(@reason_phrase)}</TITLE></HEAD>
- <BODY>
- <H1>#{HTMLUtils::escape(@reason_phrase)}</H1>
- #{HTMLUtils::escape(ex.message)}
- <HR>
- _end_of_html_
-
- if backtrace && $DEBUG
- @body << "backtrace of `#{HTMLUtils::escape(ex.class.to_s)}' "
- @body << "#{HTMLUtils::escape(ex.message)}"
- @body << "<PRE>"
- ex.backtrace.each{|line| @body << "\t#{line}\n"}
- @body << "</PRE><HR>"
- end
-
- @body << <<-_end_of_html_
- <ADDRESS>
- #{HTMLUtils::escape(@config[:ServerSoftware])} at
- #{host}:#{port}
- </ADDRESS>
- </BODY>
-</HTML>
- _end_of_html_
- end
-
- private
-
- # :stopdoc:
-
- def send_body_io(socket)
- begin
- if @request_method == "HEAD"
- # do nothing
- elsif chunked?
- begin
- buf = ''
- data = ''
- while true
- @body.readpartial( @buffer_size, buf ) # there is no need to clear buf?
- data << format("%x", buf.bytesize) << CRLF
- data << buf << CRLF
- _write_data(socket, data)
- data.clear
- @sent_size += buf.bytesize
- end
- rescue EOFError # do nothing
- end
- _write_data(socket, "0#{CRLF}#{CRLF}")
- else
- size = @header['content-length'].to_i
- _send_file(socket, @body, 0, size)
- @sent_size = size
- end
- ensure
- @body.close
- end
- end
-
- def send_body_string(socket)
- if @request_method == "HEAD"
- # do nothing
- elsif chunked?
- body ? @body.bytesize : 0
- while buf = @body[@sent_size, @buffer_size]
- break if buf.empty?
- data = ""
- data << format("%x", buf.bytesize) << CRLF
- data << buf << CRLF
- _write_data(socket, data)
- @sent_size += buf.bytesize
- end
- _write_data(socket, "0#{CRLF}#{CRLF}")
- else
- if @body && @body.bytesize > 0
- _write_data(socket, @body)
- @sent_size = @body.bytesize
- end
- end
- end
-
- def _send_file(output, input, offset, size)
- while offset > 0
- sz = @buffer_size < size ? @buffer_size : size
- buf = input.read(sz)
- offset -= buf.bytesize
- end
-
- if size == 0
- while buf = input.read(@buffer_size)
- _write_data(output, buf)
- end
- else
- while size > 0
- sz = @buffer_size < size ? @buffer_size : size
- buf = input.read(sz)
- _write_data(output, buf)
- size -= buf.bytesize
- end
- end
- end
-
- def _write_data(socket, data)
- socket << data
- end
-
- # :startdoc:
- end
-
-end
diff --git a/ruby_2_2/lib/webrick/https.rb b/ruby_2_2/lib/webrick/https.rb
deleted file mode 100644
index 9194f9411c..0000000000
--- a/ruby_2_2/lib/webrick/https.rb
+++ /dev/null
@@ -1,86 +0,0 @@
-#
-# https.rb -- SSL/TLS enhancement for HTTPServer
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2001 GOTOU Yuuzou
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: https.rb,v 1.15 2003/07/22 19:20:42 gotoyuzo Exp $
-
-require 'webrick/ssl'
-
-module WEBrick
- module Config
- HTTP.update(SSL)
- end
-
- ##
- #--
- # Adds SSL functionality to WEBrick::HTTPRequest
-
- class HTTPRequest
-
- ##
- # HTTP request SSL cipher
-
- attr_reader :cipher
-
- ##
- # HTTP request server certificate
-
- attr_reader :server_cert
-
- ##
- # HTTP request client certificate
-
- attr_reader :client_cert
-
- # :stopdoc:
-
- alias orig_parse parse
-
- def parse(socket=nil)
- if socket.respond_to?(:cert)
- @server_cert = socket.cert || @config[:SSLCertificate]
- @client_cert = socket.peer_cert
- @client_cert_chain = socket.peer_cert_chain
- @cipher = socket.cipher
- end
- orig_parse(socket)
- end
-
- alias orig_parse_uri parse_uri
-
- def parse_uri(str, scheme="https")
- if server_cert
- return orig_parse_uri(str, scheme)
- end
- return orig_parse_uri(str)
- end
- private :parse_uri
-
- alias orig_meta_vars meta_vars
-
- def meta_vars
- meta = orig_meta_vars
- if server_cert
- meta["HTTPS"] = "on"
- meta["SSL_SERVER_CERT"] = @server_cert.to_pem
- meta["SSL_CLIENT_CERT"] = @client_cert ? @client_cert.to_pem : ""
- if @client_cert_chain
- @client_cert_chain.each_with_index{|cert, i|
- meta["SSL_CLIENT_CERT_CHAIN_#{i}"] = cert.to_pem
- }
- end
- meta["SSL_CIPHER"] = @cipher[0]
- meta["SSL_PROTOCOL"] = @cipher[1]
- meta["SSL_CIPHER_USEKEYSIZE"] = @cipher[2].to_s
- meta["SSL_CIPHER_ALGKEYSIZE"] = @cipher[3].to_s
- end
- meta
- end
-
- # :startdoc:
- end
-end
diff --git a/ruby_2_2/lib/webrick/httpserver.rb b/ruby_2_2/lib/webrick/httpserver.rb
deleted file mode 100644
index 0618489c53..0000000000
--- a/ruby_2_2/lib/webrick/httpserver.rb
+++ /dev/null
@@ -1,278 +0,0 @@
-#
-# httpserver.rb -- HTTPServer Class
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2000, 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: httpserver.rb,v 1.63 2002/10/01 17:16:32 gotoyuzo Exp $
-
-require 'webrick/server'
-require 'webrick/httputils'
-require 'webrick/httpstatus'
-require 'webrick/httprequest'
-require 'webrick/httpresponse'
-require 'webrick/httpservlet'
-require 'webrick/accesslog'
-
-module WEBrick
- class HTTPServerError < ServerError; end
-
- ##
- # An HTTP Server
-
- class HTTPServer < ::WEBrick::GenericServer
- ##
- # Creates a new HTTP server according to +config+
- #
- # An HTTP server uses the following attributes:
- #
- # :AccessLog:: An array of access logs. See WEBrick::AccessLog
- # :BindAddress:: Local address for the server to bind to
- # :DocumentRoot:: Root path to serve files from
- # :DocumentRootOptions:: Options for the default HTTPServlet::FileHandler
- # :HTTPVersion:: The HTTP version of this server
- # :Port:: Port to listen on
- # :RequestCallback:: Called with a request and response before each
- # request is serviced.
- # :RequestTimeout:: Maximum time to wait between requests
- # :ServerAlias:: Array of alternate names for this server for virtual
- # hosting
- # :ServerName:: Name for this server for virtual hosting
-
- def initialize(config={}, default=Config::HTTP)
- super(config, default)
- @http_version = HTTPVersion::convert(@config[:HTTPVersion])
-
- @mount_tab = MountTable.new
- if @config[:DocumentRoot]
- mount("/", HTTPServlet::FileHandler, @config[:DocumentRoot],
- @config[:DocumentRootOptions])
- end
-
- unless @config[:AccessLog]
- @config[:AccessLog] = [
- [ $stderr, AccessLog::COMMON_LOG_FORMAT ],
- [ $stderr, AccessLog::REFERER_LOG_FORMAT ]
- ]
- end
-
- @virtual_hosts = Array.new
- end
-
- ##
- # Processes requests on +sock+
-
- def run(sock)
- while true
- res = HTTPResponse.new(@config)
- req = HTTPRequest.new(@config)
- server = self
- begin
- timeout = @config[:RequestTimeout]
- while timeout > 0
- break if IO.select([sock], nil, nil, 0.5)
- break if @status != :Running
- timeout -= 0.5
- end
- raise HTTPStatus::EOFError if timeout <= 0 || @status != :Running
- raise HTTPStatus::EOFError if sock.eof?
- req.parse(sock)
- res.request_method = req.request_method
- res.request_uri = req.request_uri
- res.request_http_version = req.http_version
- res.keep_alive = req.keep_alive?
- server = lookup_server(req) || self
- if callback = server[:RequestCallback]
- callback.call(req, res)
- elsif callback = server[:RequestHandler]
- msg = ":RequestHandler is deprecated, please use :RequestCallback"
- @logger.warn(msg)
- callback.call(req, res)
- end
- server.service(req, res)
- rescue HTTPStatus::EOFError, HTTPStatus::RequestTimeout => ex
- res.set_error(ex)
- rescue HTTPStatus::Error => ex
- @logger.error(ex.message)
- res.set_error(ex)
- rescue HTTPStatus::Status => ex
- res.status = ex.code
- rescue StandardError => ex
- @logger.error(ex)
- res.set_error(ex, true)
- ensure
- if req.request_line
- if req.keep_alive? && res.keep_alive?
- req.fixup()
- end
- res.send_response(sock)
- server.access_log(@config, req, res)
- end
- end
- break if @http_version < "1.1"
- break unless req.keep_alive?
- break unless res.keep_alive?
- end
- end
-
- ##
- # Services +req+ and fills in +res+
-
- def service(req, res)
- if req.unparsed_uri == "*"
- if req.request_method == "OPTIONS"
- do_OPTIONS(req, res)
- raise HTTPStatus::OK
- end
- raise HTTPStatus::NotFound, "`#{req.unparsed_uri}' not found."
- end
-
- servlet, options, script_name, path_info = search_servlet(req.path)
- raise HTTPStatus::NotFound, "`#{req.path}' not found." unless servlet
- req.script_name = script_name
- req.path_info = path_info
- si = servlet.get_instance(self, *options)
- @logger.debug(format("%s is invoked.", si.class.name))
- si.service(req, res)
- end
-
- ##
- # The default OPTIONS request handler says GET, HEAD, POST and OPTIONS
- # requests are allowed.
-
- def do_OPTIONS(req, res)
- res["allow"] = "GET,HEAD,POST,OPTIONS"
- end
-
- ##
- # Mounts +servlet+ on +dir+ passing +options+ to the servlet at creation
- # time
-
- def mount(dir, servlet, *options)
- @logger.debug(sprintf("%s is mounted on %s.", servlet.inspect, dir))
- @mount_tab[dir] = [ servlet, options ]
- end
-
- ##
- # Mounts +proc+ or +block+ on +dir+ and calls it with a
- # WEBrick::HTTPRequest and WEBrick::HTTPResponse
-
- def mount_proc(dir, proc=nil, &block)
- proc ||= block
- raise HTTPServerError, "must pass a proc or block" unless proc
- mount(dir, HTTPServlet::ProcHandler.new(proc))
- end
-
- ##
- # Unmounts +dir+
-
- def unmount(dir)
- @logger.debug(sprintf("unmount %s.", dir))
- @mount_tab.delete(dir)
- end
- alias umount unmount
-
- ##
- # Finds a servlet for +path+
-
- def search_servlet(path)
- script_name, path_info = @mount_tab.scan(path)
- servlet, options = @mount_tab[script_name]
- if servlet
- [ servlet, options, script_name, path_info ]
- end
- end
-
- ##
- # Adds +server+ as a virtual host.
-
- def virtual_host(server)
- @virtual_hosts << server
- @virtual_hosts = @virtual_hosts.sort_by{|s|
- num = 0
- num -= 4 if s[:BindAddress]
- num -= 2 if s[:Port]
- num -= 1 if s[:ServerName]
- num
- }
- end
-
- ##
- # Finds the appropriate virtual host to handle +req+
-
- def lookup_server(req)
- @virtual_hosts.find{|s|
- (s[:BindAddress].nil? || req.addr[3] == s[:BindAddress]) &&
- (s[:Port].nil? || req.port == s[:Port]) &&
- ((s[:ServerName].nil? || req.host == s[:ServerName]) ||
- (!s[:ServerAlias].nil? && s[:ServerAlias].find{|h| h === req.host}))
- }
- end
-
- ##
- # Logs +req+ and +res+ in the access logs. +config+ is used for the
- # server name.
-
- def access_log(config, req, res)
- param = AccessLog::setup_params(config, req, res)
- @config[:AccessLog].each{|logger, fmt|
- logger << AccessLog::format(fmt+"\n", param)
- }
- end
-
- ##
- # Mount table for the path a servlet is mounted on in the directory space
- # of the server. Users of WEBrick can only access this indirectly via
- # WEBrick::HTTPServer#mount, WEBrick::HTTPServer#unmount and
- # WEBrick::HTTPServer#search_servlet
-
- class MountTable # :nodoc:
- def initialize
- @tab = Hash.new
- compile
- end
-
- def [](dir)
- dir = normalize(dir)
- @tab[dir]
- end
-
- def []=(dir, val)
- dir = normalize(dir)
- @tab[dir] = val
- compile
- val
- end
-
- def delete(dir)
- dir = normalize(dir)
- res = @tab.delete(dir)
- compile
- res
- end
-
- def scan(path)
- @scanner =~ path
- [ $&, $' ]
- end
-
- private
-
- def compile
- k = @tab.keys
- k.sort!
- k.reverse!
- k.collect!{|path| Regexp.escape(path) }
- @scanner = Regexp.new("^(" + k.join("|") +")(?=/|$)")
- end
-
- def normalize(dir)
- ret = dir ? dir.dup : ""
- ret.sub!(%r|/+$|, "")
- ret
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/webrick/httpservlet.rb b/ruby_2_2/lib/webrick/httpservlet.rb
deleted file mode 100644
index ac7c022bd7..0000000000
--- a/ruby_2_2/lib/webrick/httpservlet.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-#
-# httpservlet.rb -- HTTPServlet Utility File
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2000, 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: httpservlet.rb,v 1.21 2003/02/23 12:24:46 gotoyuzo Exp $
-
-require 'webrick/httpservlet/abstract'
-require 'webrick/httpservlet/filehandler'
-require 'webrick/httpservlet/cgihandler'
-require 'webrick/httpservlet/erbhandler'
-require 'webrick/httpservlet/prochandler'
-
-module WEBrick
- module HTTPServlet
- FileHandler.add_handler("cgi", CGIHandler)
- FileHandler.add_handler("rhtml", ERBHandler)
- end
-end
diff --git a/ruby_2_2/lib/webrick/httpservlet/abstract.rb b/ruby_2_2/lib/webrick/httpservlet/abstract.rb
deleted file mode 100644
index d3b00ab4e1..0000000000
--- a/ruby_2_2/lib/webrick/httpservlet/abstract.rb
+++ /dev/null
@@ -1,153 +0,0 @@
-#
-# httpservlet.rb -- HTTPServlet Module
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2000 TAKAHASHI Masayoshi, GOTOU Yuuzou
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: abstract.rb,v 1.24 2003/07/11 11:16:46 gotoyuzo Exp $
-
-require 'thread'
-
-require 'webrick/htmlutils'
-require 'webrick/httputils'
-require 'webrick/httpstatus'
-
-module WEBrick
- module HTTPServlet
- class HTTPServletError < StandardError; end
-
- ##
- # AbstractServlet allows HTTP server modules to be reused across multiple
- # servers and allows encapsulation of functionality.
- #
- # By default a servlet will respond to GET, HEAD (through an alias to GET)
- # and OPTIONS requests.
- #
- # By default a new servlet is initialized for every request. A servlet
- # instance can be reused by overriding ::get_instance in the
- # AbstractServlet subclass.
- #
- # == A Simple Servlet
- #
- # class Simple < WEBrick::HTTPServlet::AbstractServlet
- # def do_GET request, response
- # status, content_type, body = do_stuff_with request
- #
- # response.status = status
- # response['Content-Type'] = content_type
- # response.body = body
- # end
- #
- # def do_stuff_with request
- # return 200, 'text/plain', 'you got a page'
- # end
- # end
- #
- # This servlet can be mounted on a server at a given path:
- #
- # server.mount '/simple', Simple
- #
- # == Servlet Configuration
- #
- # Servlets can be configured via initialize. The first argument is the
- # HTTP server the servlet is being initialized for.
- #
- # class Configurable < Simple
- # def initialize server, color, size
- # super server
- # @color = color
- # @size = size
- # end
- #
- # def do_stuff_with request
- # content = "<p " \
- # %q{style="color: #{@color}; font-size: #{@size}"} \
- # ">Hello, World!"
- #
- # return 200, "text/html", content
- # end
- # end
- #
- # This servlet must be provided two arguments at mount time:
- #
- # server.mount '/configurable', Configurable, 'red', '2em'
-
- class AbstractServlet
-
- ##
- # Factory for servlet instances that will handle a request from +server+
- # using +options+ from the mount point. By default a new servlet
- # instance is created for every call.
-
- def self.get_instance(server, *options)
- self.new(server, *options)
- end
-
- ##
- # Initializes a new servlet for +server+ using +options+ which are
- # stored as-is in +@options+. +@logger+ is also provided.
-
- def initialize(server, *options)
- @server = @config = server
- @logger = @server[:Logger]
- @options = options
- end
-
- ##
- # Dispatches to a +do_+ method based on +req+ if such a method is
- # available. (+do_GET+ for a GET request). Raises a MethodNotAllowed
- # exception if the method is not implemented.
-
- def service(req, res)
- method_name = "do_" + req.request_method.gsub(/-/, "_")
- if respond_to?(method_name)
- __send__(method_name, req, res)
- else
- raise HTTPStatus::MethodNotAllowed,
- "unsupported method `#{req.request_method}'."
- end
- end
-
- ##
- # Raises a NotFound exception
-
- def do_GET(req, res)
- raise HTTPStatus::NotFound, "not found."
- end
-
- ##
- # Dispatches to do_GET
-
- def do_HEAD(req, res)
- do_GET(req, res)
- end
-
- ##
- # Returns the allowed HTTP request methods
-
- def do_OPTIONS(req, res)
- m = self.methods.grep(/\Ado_([A-Z]+)\z/) {$1}
- m.sort!
- res["allow"] = m.join(",")
- end
-
- private
-
- ##
- # Redirects to a path ending in /
-
- def redirect_to_directory_uri(req, res)
- if req.path[-1] != ?/
- location = WEBrick::HTTPUtils.escape_path(req.path + "/")
- if req.query_string && req.query_string.bytesize > 0
- location << "?" << req.query_string
- end
- res.set_redirect(HTTPStatus::MovedPermanently, location)
- end
- end
- end
-
- end
-end
diff --git a/ruby_2_2/lib/webrick/httpservlet/cgi_runner.rb b/ruby_2_2/lib/webrick/httpservlet/cgi_runner.rb
deleted file mode 100644
index 32ecb6fe00..0000000000
--- a/ruby_2_2/lib/webrick/httpservlet/cgi_runner.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-#
-# cgi_runner.rb -- CGI launcher.
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2000 TAKAHASHI Masayoshi, GOTOU YUUZOU
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: cgi_runner.rb,v 1.9 2002/09/25 11:33:15 gotoyuzo Exp $
-
-def sysread(io, size)
- buf = ""
- while size > 0
- tmp = io.sysread(size)
- buf << tmp
- size -= tmp.bytesize
- end
- return buf
-end
-
-STDIN.binmode
-
-len = sysread(STDIN, 8).to_i
-out = sysread(STDIN, len)
-STDOUT.reopen(open(out, "w"))
-
-len = sysread(STDIN, 8).to_i
-err = sysread(STDIN, len)
-STDERR.reopen(open(err, "w"))
-
-len = sysread(STDIN, 8).to_i
-dump = sysread(STDIN, len)
-hash = Marshal.restore(dump)
-ENV.keys.each{|name| ENV.delete(name) }
-hash.each{|k, v| ENV[k] = v if v }
-
-dir = File::dirname(ENV["SCRIPT_FILENAME"])
-Dir::chdir dir
-
-if ARGV[0]
- argv = ARGV.dup
- argv << ENV["SCRIPT_FILENAME"]
- exec(*argv)
- # NOTREACHED
-end
-exec ENV["SCRIPT_FILENAME"]
diff --git a/ruby_2_2/lib/webrick/httpservlet/cgihandler.rb b/ruby_2_2/lib/webrick/httpservlet/cgihandler.rb
deleted file mode 100644
index 40b0e0b97d..0000000000
--- a/ruby_2_2/lib/webrick/httpservlet/cgihandler.rb
+++ /dev/null
@@ -1,121 +0,0 @@
-#
-# cgihandler.rb -- CGIHandler Class
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: cgihandler.rb,v 1.27 2003/03/21 19:56:01 gotoyuzo Exp $
-
-require 'rbconfig'
-require 'tempfile'
-require 'webrick/config'
-require 'webrick/httpservlet/abstract'
-
-module WEBrick
- module HTTPServlet
-
- ##
- # Servlet for handling CGI scripts
- #
- # Example:
- #
- # server.mount('/cgi/my_script', WEBrick::HTTPServlet::CGIHandler,
- # '/path/to/my_script')
-
- class CGIHandler < AbstractServlet
- Ruby = RbConfig.ruby # :nodoc:
- CGIRunner = "\"#{Ruby}\" \"#{WEBrick::Config::LIBDIR}/httpservlet/cgi_runner.rb\"" # :nodoc:
-
- ##
- # Creates a new CGI script servlet for the script at +name+
-
- def initialize(server, name)
- super(server, name)
- @script_filename = name
- @tempdir = server[:TempDir]
- @cgicmd = "#{CGIRunner} #{server[:CGIInterpreter]}"
- end
-
- # :stopdoc:
-
- def do_GET(req, res)
- cgi_in = IO::popen(@cgicmd, "wb")
- cgi_out = Tempfile.new("webrick.cgiout.", @tempdir, mode: IO::BINARY)
- cgi_out.set_encoding("ASCII-8BIT")
- cgi_err = Tempfile.new("webrick.cgierr.", @tempdir, mode: IO::BINARY)
- cgi_err.set_encoding("ASCII-8BIT")
- begin
- cgi_in.sync = true
- meta = req.meta_vars
- meta["SCRIPT_FILENAME"] = @script_filename
- meta["PATH"] = @config[:CGIPathEnv]
- meta.delete("HTTP_PROXY")
- if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM
- meta["SystemRoot"] = ENV["SystemRoot"]
- end
- dump = Marshal.dump(meta)
-
- cgi_in.write("%8d" % cgi_out.path.bytesize)
- cgi_in.write(cgi_out.path)
- cgi_in.write("%8d" % cgi_err.path.bytesize)
- cgi_in.write(cgi_err.path)
- cgi_in.write("%8d" % dump.bytesize)
- cgi_in.write(dump)
-
- if req.body and req.body.bytesize > 0
- cgi_in.write(req.body)
- end
- ensure
- cgi_in.close
- status = $?.exitstatus
- sleep 0.1 if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM
- data = cgi_out.read
- cgi_out.close(true)
- if errmsg = cgi_err.read
- if errmsg.bytesize > 0
- @logger.error("CGIHandler: #{@script_filename}:\n" + errmsg)
- end
- end
- cgi_err.close(true)
- end
-
- if status != 0
- @logger.error("CGIHandler: #{@script_filename} exit with #{status}")
- end
-
- data = "" unless data
- raw_header, body = data.split(/^[\xd\xa]+/, 2)
- raise HTTPStatus::InternalServerError,
- "Premature end of script headers: #{@script_filename}" if body.nil?
-
- begin
- header = HTTPUtils::parse_header(raw_header)
- if /^(\d+)/ =~ header['status'][0]
- res.status = $1.to_i
- header.delete('status')
- end
- if header.has_key?('location')
- # RFC 3875 6.2.3, 6.2.4
- res.status = 302 unless (300...400) === res.status
- end
- if header.has_key?('set-cookie')
- header['set-cookie'].each{|k|
- res.cookies << Cookie.parse_set_cookie(k)
- }
- header.delete('set-cookie')
- end
- header.each{|key, val| res[key] = val.join(", ") }
- rescue => ex
- raise HTTPStatus::InternalServerError, ex.message
- end
- res.body = body
- end
- alias do_POST do_GET
-
- # :startdoc:
- end
-
- end
-end
diff --git a/ruby_2_2/lib/webrick/httpservlet/erbhandler.rb b/ruby_2_2/lib/webrick/httpservlet/erbhandler.rb
deleted file mode 100644
index 1b8a82d67b..0000000000
--- a/ruby_2_2/lib/webrick/httpservlet/erbhandler.rb
+++ /dev/null
@@ -1,87 +0,0 @@
-#
-# erbhandler.rb -- ERBHandler Class
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: erbhandler.rb,v 1.25 2003/02/24 19:25:31 gotoyuzo Exp $
-
-require 'webrick/httpservlet/abstract.rb'
-
-require 'erb'
-
-module WEBrick
- module HTTPServlet
-
- ##
- # ERBHandler evaluates an ERB file and returns the result. This handler
- # is automatically used if there are .rhtml files in a directory served by
- # the FileHandler.
- #
- # ERBHandler supports GET and POST methods.
- #
- # The ERB file is evaluated with the local variables +servlet_request+ and
- # +servlet_response+ which are a WEBrick::HTTPRequest and
- # WEBrick::HTTPResponse respectively.
- #
- # Example .rhtml file:
- #
- # Request to <%= servlet_request.request_uri %>
- #
- # Query params <%= servlet_request.query.inspect %>
-
- class ERBHandler < AbstractServlet
-
- ##
- # Creates a new ERBHandler on +server+ that will evaluate and serve the
- # ERB file +name+
-
- def initialize(server, name)
- super(server, name)
- @script_filename = name
- end
-
- ##
- # Handles GET requests
-
- def do_GET(req, res)
- unless defined?(ERB)
- @logger.warn "#{self.class}: ERB not defined."
- raise HTTPStatus::Forbidden, "ERBHandler cannot work."
- end
- begin
- data = open(@script_filename){|io| io.read }
- res.body = evaluate(ERB.new(data), req, res)
- res['content-type'] ||=
- HTTPUtils::mime_type(@script_filename, @config[:MimeTypes])
- rescue StandardError
- raise
- rescue Exception => ex
- @logger.error(ex)
- raise HTTPStatus::InternalServerError, ex.message
- end
- end
-
- ##
- # Handles POST requests
-
- alias do_POST do_GET
-
- private
-
- ##
- # Evaluates +erb+ providing +servlet_request+ and +servlet_response+ as
- # local variables.
-
- def evaluate(erb, servlet_request, servlet_response)
- Module.new.module_eval{
- servlet_request.meta_vars
- servlet_request.query
- erb.result(binding)
- }
- end
- end
- end
-end
diff --git a/ruby_2_2/lib/webrick/httpservlet/filehandler.rb b/ruby_2_2/lib/webrick/httpservlet/filehandler.rb
deleted file mode 100644
index cc9db4a870..0000000000
--- a/ruby_2_2/lib/webrick/httpservlet/filehandler.rb
+++ /dev/null
@@ -1,521 +0,0 @@
-#
-# filehandler.rb -- FileHandler Module
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
-# Copyright (c) 2003 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: filehandler.rb,v 1.44 2003/06/07 01:34:51 gotoyuzo Exp $
-
-require 'thread'
-require 'time'
-
-require 'webrick/htmlutils'
-require 'webrick/httputils'
-require 'webrick/httpstatus'
-
-module WEBrick
- module HTTPServlet
-
- ##
- # Servlet for serving a single file. You probably want to use the
- # FileHandler servlet instead as it handles directories and fancy indexes.
- #
- # Example:
- #
- # server.mount('/my_page.txt', WEBrick::HTTPServlet::DefaultFileHandler,
- # '/path/to/my_page.txt')
- #
- # This servlet handles If-Modified-Since and Range requests.
-
- class DefaultFileHandler < AbstractServlet
-
- ##
- # Creates a DefaultFileHandler instance for the file at +local_path+.
-
- def initialize(server, local_path)
- super(server, local_path)
- @local_path = local_path
- end
-
- # :stopdoc:
-
- def do_GET(req, res)
- st = File::stat(@local_path)
- mtime = st.mtime
- res['etag'] = sprintf("%x-%x-%x", st.ino, st.size, st.mtime.to_i)
-
- if not_modified?(req, res, mtime, res['etag'])
- res.body = ''
- raise HTTPStatus::NotModified
- elsif req['range']
- make_partial_content(req, res, @local_path, st.size)
- raise HTTPStatus::PartialContent
- else
- mtype = HTTPUtils::mime_type(@local_path, @config[:MimeTypes])
- res['content-type'] = mtype
- res['content-length'] = st.size
- res['last-modified'] = mtime.httpdate
- res.body = open(@local_path, "rb")
- end
- end
-
- def not_modified?(req, res, mtime, etag)
- if ir = req['if-range']
- begin
- if Time.httpdate(ir) >= mtime
- return true
- end
- rescue
- if HTTPUtils::split_header_value(ir).member?(res['etag'])
- return true
- end
- end
- end
-
- if (ims = req['if-modified-since']) && Time.parse(ims) >= mtime
- return true
- end
-
- if (inm = req['if-none-match']) &&
- HTTPUtils::split_header_value(inm).member?(res['etag'])
- return true
- end
-
- return false
- end
-
- def make_partial_content(req, res, filename, filesize)
- mtype = HTTPUtils::mime_type(filename, @config[:MimeTypes])
- unless ranges = HTTPUtils::parse_range_header(req['range'])
- raise HTTPStatus::BadRequest,
- "Unrecognized range-spec: \"#{req['range']}\""
- end
- open(filename, "rb"){|io|
- if ranges.size > 1
- time = Time.now
- boundary = "#{time.sec}_#{time.usec}_#{Process::pid}"
- body = ''
- ranges.each{|range|
- first, last = prepare_range(range, filesize)
- next if first < 0
- io.pos = first
- content = io.read(last-first+1)
- body << "--" << boundary << CRLF
- body << "Content-Type: #{mtype}" << CRLF
- body << "Content-Range: bytes #{first}-#{last}/#{filesize}" << CRLF
- body << CRLF
- body << content
- body << CRLF
- }
- raise HTTPStatus::RequestRangeNotSatisfiable if body.empty?
- body << "--" << boundary << "--" << CRLF
- res["content-type"] = "multipart/byteranges; boundary=#{boundary}"
- res.body = body
- elsif range = ranges[0]
- first, last = prepare_range(range, filesize)
- raise HTTPStatus::RequestRangeNotSatisfiable if first < 0
- if last == filesize - 1
- content = io.dup
- content.pos = first
- else
- io.pos = first
- content = io.read(last-first+1)
- end
- res['content-type'] = mtype
- res['content-range'] = "bytes #{first}-#{last}/#{filesize}"
- res['content-length'] = last - first + 1
- res.body = content
- else
- raise HTTPStatus::BadRequest
- end
- }
- end
-
- def prepare_range(range, filesize)
- first = range.first < 0 ? filesize + range.first : range.first
- return -1, -1 if first < 0 || first >= filesize
- last = range.last < 0 ? filesize + range.last : range.last
- last = filesize - 1 if last >= filesize
- return first, last
- end
-
- # :startdoc:
- end
-
- ##
- # Serves a directory including fancy indexing and a variety of other
- # options.
- #
- # Example:
- #
- # server.mount '/assets', WEBrick::FileHandler, '/path/to/assets'
-
- class FileHandler < AbstractServlet
- HandlerTable = Hash.new # :nodoc:
-
- ##
- # Allow custom handling of requests for files with +suffix+ by class
- # +handler+
-
- def self.add_handler(suffix, handler)
- HandlerTable[suffix] = handler
- end
-
- ##
- # Remove custom handling of requests for files with +suffix+
-
- def self.remove_handler(suffix)
- HandlerTable.delete(suffix)
- end
-
- ##
- # Creates a FileHandler servlet on +server+ that serves files starting
- # at directory +root+
- #
- # +options+ may be a Hash containing keys from
- # WEBrick::Config::FileHandler or +true+ or +false+.
- #
- # If +options+ is true or false then +:FancyIndexing+ is enabled or
- # disabled respectively.
-
- def initialize(server, root, options={}, default=Config::FileHandler)
- @config = server.config
- @logger = @config[:Logger]
- @root = File.expand_path(root)
- if options == true || options == false
- options = { :FancyIndexing => options }
- end
- @options = default.dup.update(options)
- end
-
- # :stopdoc:
-
- def service(req, res)
- # if this class is mounted on "/" and /~username is requested.
- # we're going to override path informations before invoking service.
- if defined?(Etc) && @options[:UserDir] && req.script_name.empty?
- if %r|^(/~([^/]+))| =~ req.path_info
- script_name, user = $1, $2
- path_info = $'
- begin
- passwd = Etc::getpwnam(user)
- @root = File::join(passwd.dir, @options[:UserDir])
- req.script_name = script_name
- req.path_info = path_info
- rescue
- @logger.debug "#{self.class}#do_GET: getpwnam(#{user}) failed"
- end
- end
- end
- prevent_directory_traversal(req, res)
- super(req, res)
- end
-
- def do_GET(req, res)
- unless exec_handler(req, res)
- set_dir_list(req, res)
- end
- end
-
- def do_POST(req, res)
- unless exec_handler(req, res)
- raise HTTPStatus::NotFound, "`#{req.path}' not found."
- end
- end
-
- def do_OPTIONS(req, res)
- unless exec_handler(req, res)
- super(req, res)
- end
- end
-
- # ToDo
- # RFC2518: HTTP Extensions for Distributed Authoring -- WEBDAV
- #
- # PROPFIND PROPPATCH MKCOL DELETE PUT COPY MOVE
- # LOCK UNLOCK
-
- # RFC3253: Versioning Extensions to WebDAV
- # (Web Distributed Authoring and Versioning)
- #
- # VERSION-CONTROL REPORT CHECKOUT CHECK_IN UNCHECKOUT
- # MKWORKSPACE UPDATE LABEL MERGE ACTIVITY
-
- private
-
- def trailing_pathsep?(path)
- # check for trailing path separator:
- # File.dirname("/aaaa/bbbb/") #=> "/aaaa")
- # File.dirname("/aaaa/bbbb/x") #=> "/aaaa/bbbb")
- # File.dirname("/aaaa/bbbb") #=> "/aaaa")
- # File.dirname("/aaaa/bbbbx") #=> "/aaaa")
- return File.dirname(path) != File.dirname(path+"x")
- end
-
- def prevent_directory_traversal(req, res)
- # Preventing directory traversal on Windows platforms;
- # Backslashes (0x5c) in path_info are not interpreted as special
- # character in URI notation. So the value of path_info should be
- # normalize before accessing to the filesystem.
-
- # dirty hack for filesystem encoding; in nature, File.expand_path
- # should not be used for path normalization. [Bug #3345]
- path = req.path_info.dup.force_encoding(Encoding.find("filesystem"))
- if trailing_pathsep?(req.path_info)
- # File.expand_path removes the trailing path separator.
- # Adding a character is a workaround to save it.
- # File.expand_path("/aaa/") #=> "/aaa"
- # File.expand_path("/aaa/" + "x") #=> "/aaa/x"
- expanded = File.expand_path(path + "x")
- expanded.chop! # remove trailing "x"
- else
- expanded = File.expand_path(path)
- end
- expanded.force_encoding(req.path_info.encoding)
- req.path_info = expanded
- end
-
- def exec_handler(req, res)
- raise HTTPStatus::NotFound, "`#{req.path}' not found" unless @root
- if set_filename(req, res)
- handler = get_handler(req, res)
- call_callback(:HandlerCallback, req, res)
- h = handler.get_instance(@config, res.filename)
- h.service(req, res)
- return true
- end
- call_callback(:HandlerCallback, req, res)
- return false
- end
-
- def get_handler(req, res)
- suffix1 = (/\.(\w+)\z/ =~ res.filename) && $1.downcase
- if /\.(\w+)\.([\w\-]+)\z/ =~ res.filename
- if @options[:AcceptableLanguages].include?($2.downcase)
- suffix2 = $1.downcase
- end
- end
- handler_table = @options[:HandlerTable]
- return handler_table[suffix1] || handler_table[suffix2] ||
- HandlerTable[suffix1] || HandlerTable[suffix2] ||
- DefaultFileHandler
- end
-
- def set_filename(req, res)
- res.filename = @root.dup
- path_info = req.path_info.scan(%r|/[^/]*|)
-
- path_info.unshift("") # dummy for checking @root dir
- while base = path_info.first
- break if base == "/"
- break unless File.directory?(File.expand_path(res.filename + base))
- shift_path_info(req, res, path_info)
- call_callback(:DirectoryCallback, req, res)
- end
-
- if base = path_info.first
- if base == "/"
- if file = search_index_file(req, res)
- shift_path_info(req, res, path_info, file)
- call_callback(:FileCallback, req, res)
- return true
- end
- shift_path_info(req, res, path_info)
- elsif file = search_file(req, res, base)
- shift_path_info(req, res, path_info, file)
- call_callback(:FileCallback, req, res)
- return true
- else
- raise HTTPStatus::NotFound, "`#{req.path}' not found."
- end
- end
-
- return false
- end
-
- def check_filename(req, res, name)
- if nondisclosure_name?(name) || windows_ambiguous_name?(name)
- @logger.warn("the request refers nondisclosure name `#{name}'.")
- raise HTTPStatus::NotFound, "`#{req.path}' not found."
- end
- end
-
- def shift_path_info(req, res, path_info, base=nil)
- tmp = path_info.shift
- base = base || tmp
- req.path_info = path_info.join
- req.script_name << base
- res.filename = File.expand_path(res.filename + base)
- check_filename(req, res, File.basename(res.filename))
- end
-
- def search_index_file(req, res)
- @config[:DirectoryIndex].each{|index|
- if file = search_file(req, res, "/"+index)
- return file
- end
- }
- return nil
- end
-
- def search_file(req, res, basename)
- langs = @options[:AcceptableLanguages]
- path = res.filename + basename
- if File.file?(path)
- return basename
- elsif langs.size > 0
- req.accept_language.each{|lang|
- path_with_lang = path + ".#{lang}"
- if langs.member?(lang) && File.file?(path_with_lang)
- return basename + ".#{lang}"
- end
- }
- (langs - req.accept_language).each{|lang|
- path_with_lang = path + ".#{lang}"
- if File.file?(path_with_lang)
- return basename + ".#{lang}"
- end
- }
- end
- return nil
- end
-
- def call_callback(callback_name, req, res)
- if cb = @options[callback_name]
- cb.call(req, res)
- end
- end
-
- def windows_ambiguous_name?(name)
- return true if /[. ]+\z/ =~ name
- return true if /::\$DATA\z/ =~ name
- return false
- end
-
- def nondisclosure_name?(name)
- @options[:NondisclosureName].each{|pattern|
- if File.fnmatch(pattern, name, File::FNM_CASEFOLD)
- return true
- end
- }
- return false
- end
-
- def set_dir_list(req, res)
- redirect_to_directory_uri(req, res)
- unless @options[:FancyIndexing]
- raise HTTPStatus::Forbidden, "no access permission to `#{req.path}'"
- end
- local_path = res.filename
- list = Dir::entries(local_path).collect{|name|
- next if name == "." || name == ".."
- next if nondisclosure_name?(name)
- next if windows_ambiguous_name?(name)
- st = (File::stat(File.join(local_path, name)) rescue nil)
- if st.nil?
- [ name, nil, -1 ]
- elsif st.directory?
- [ name + "/", st.mtime, -1 ]
- else
- [ name, st.mtime, st.size ]
- end
- }
- list.compact!
-
- query = req.query
-
- d0 = nil
- idx = nil
- %w[N M S].each_with_index do |q, i|
- if d = query.delete(q)
- idx ||= i
- d0 ||= d
- end
- end
- d0 ||= "A"
- idx ||= 0
- d1 = (d0 == "A") ? "D" : "A"
-
- if d0 == "A"
- list.sort!{|a,b| a[idx] <=> b[idx] }
- else
- list.sort!{|a,b| b[idx] <=> a[idx] }
- end
-
- namewidth = query["NameWidth"]
- if namewidth == "*"
- namewidth = nil
- elsif !namewidth or (namewidth = namewidth.to_i) < 2
- namewidth = 25
- end
- query = query.inject('') {|s, (k, v)| s << '&' << HTMLUtils::escape("#{k}=#{v}")}
-
- type = "text/html"
- case enc = Encoding.find('filesystem')
- when Encoding::US_ASCII, Encoding::ASCII_8BIT
- else
- type << "; charset=\"#{enc.name}\""
- end
- res['content-type'] = type
-
- title = "Index of #{HTMLUtils::escape(req.path)}"
- res.body = <<-_end_of_html_
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<HTML>
- <HEAD>
- <TITLE>#{title}</TITLE>
- <style type="text/css">
- <!--
- .name, .mtime { text-align: left; }
- .size { text-align: right; }
- td { text-overflow: ellipsis; white-space: nowrap; overflow: hidden; }
- table { border-collapse: collapse; }
- tr th { border-bottom: 2px groove; }
- //-->
- </style>
- </HEAD>
- <BODY>
- <H1>#{title}</H1>
- _end_of_html_
-
- res.body << "<TABLE width=\"100%\"><THEAD><TR>\n"
- res.body << "<TH class=\"name\"><A HREF=\"?N=#{d1}#{query}\">Name</A></TH>"
- res.body << "<TH class=\"mtime\"><A HREF=\"?M=#{d1}#{query}\">Last modified</A></TH>"
- res.body << "<TH class=\"size\"><A HREF=\"?S=#{d1}#{query}\">Size</A></TH>\n"
- res.body << "</TR></THEAD>\n"
- res.body << "<TBODY>\n"
-
- query.sub!(/\A&/, '?')
- list.unshift [ "..", File::mtime(local_path+"/.."), -1 ]
- list.each{ |name, time, size|
- if name == ".."
- dname = "Parent Directory"
- elsif namewidth and name.size > namewidth
- dname = name[0...(namewidth - 2)] << '..'
- else
- dname = name
- end
- s = "<TR><TD class=\"name\"><A HREF=\"#{HTTPUtils::escape(name)}#{query if name.end_with?('/')}\">#{HTMLUtils::escape(dname)}</A></TD>"
- s << "<TD class=\"mtime\">" << (time ? time.strftime("%Y/%m/%d %H:%M") : "") << "</TD>"
- s << "<TD class=\"size\">" << (size >= 0 ? size.to_s : "-") << "</TD></TR>\n"
- res.body << s
- }
- res.body << "</TBODY></TABLE>"
- res.body << "<HR>"
-
- res.body << <<-_end_of_html_
- <ADDRESS>
- #{HTMLUtils::escape(@config[:ServerSoftware])}<BR>
- at #{req.host}:#{req.port}
- </ADDRESS>
- </BODY>
-</HTML>
- _end_of_html_
- end
-
- # :startdoc:
- end
- end
-end
diff --git a/ruby_2_2/lib/webrick/httpservlet/prochandler.rb b/ruby_2_2/lib/webrick/httpservlet/prochandler.rb
deleted file mode 100644
index 2f5aa66f45..0000000000
--- a/ruby_2_2/lib/webrick/httpservlet/prochandler.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-#
-# prochandler.rb -- ProcHandler Class
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: prochandler.rb,v 1.7 2002/09/21 12:23:42 gotoyuzo Exp $
-
-require 'webrick/httpservlet/abstract.rb'
-
-module WEBrick
- module HTTPServlet
-
- ##
- # Mounts a proc at a path that accepts a request and response.
- #
- # Instead of mounting this servlet with WEBrick::HTTPServer#mount use
- # WEBrick::HTTPServer#mount_proc:
- #
- # server.mount_proc '/' do |req, res|
- # res.body = 'it worked!'
- # res.status = 200
- # end
-
- class ProcHandler < AbstractServlet
- # :stopdoc:
- def get_instance(server, *options)
- self
- end
-
- def initialize(proc)
- @proc = proc
- end
-
- def do_GET(request, response)
- @proc.call(request, response)
- end
-
- alias do_POST do_GET
- # :startdoc:
- end
-
- end
-end
diff --git a/ruby_2_2/lib/webrick/httpstatus.rb b/ruby_2_2/lib/webrick/httpstatus.rb
deleted file mode 100644
index 5dc136f88f..0000000000
--- a/ruby_2_2/lib/webrick/httpstatus.rb
+++ /dev/null
@@ -1,192 +0,0 @@
-#--
-# httpstatus.rb -- HTTPStatus Class
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2000, 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: httpstatus.rb,v 1.11 2003/03/24 20:18:55 gotoyuzo Exp $
-
-require 'webrick/accesslog'
-
-module WEBrick
-
- ##
- # This module is used to manager HTTP status codes.
- #
- # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for more
- # information.
- module HTTPStatus
-
- ##
- # Root of the HTTP status class hierarchy
- class Status < StandardError
- class << self
- attr_reader :code, :reason_phrase # :nodoc:
- end
-
- # Returns the HTTP status code
- def code() self::class::code end
-
- # Returns the HTTP status description
- def reason_phrase() self::class::reason_phrase end
-
- alias to_i code # :nodoc:
- end
-
- # Root of the HTTP info statuses
- class Info < Status; end
- # Root of the HTTP success statuses
- class Success < Status; end
- # Root of the HTTP redirect statuses
- class Redirect < Status; end
- # Root of the HTTP error statuses
- class Error < Status; end
- # Root of the HTTP client error statuses
- class ClientError < Error; end
- # Root of the HTTP server error statuses
- class ServerError < Error; end
-
- class EOFError < StandardError; end
-
- # HTTP status codes and descriptions
- StatusMessage = { # :nodoc:
- 100 => 'Continue',
- 101 => 'Switching Protocols',
- 200 => 'OK',
- 201 => 'Created',
- 202 => 'Accepted',
- 203 => 'Non-Authoritative Information',
- 204 => 'No Content',
- 205 => 'Reset Content',
- 206 => 'Partial Content',
- 207 => 'Multi-Status',
- 300 => 'Multiple Choices',
- 301 => 'Moved Permanently',
- 302 => 'Found',
- 303 => 'See Other',
- 304 => 'Not Modified',
- 305 => 'Use Proxy',
- 307 => 'Temporary Redirect',
- 400 => 'Bad Request',
- 401 => 'Unauthorized',
- 402 => 'Payment Required',
- 403 => 'Forbidden',
- 404 => 'Not Found',
- 405 => 'Method Not Allowed',
- 406 => 'Not Acceptable',
- 407 => 'Proxy Authentication Required',
- 408 => 'Request Timeout',
- 409 => 'Conflict',
- 410 => 'Gone',
- 411 => 'Length Required',
- 412 => 'Precondition Failed',
- 413 => 'Request Entity Too Large',
- 414 => 'Request-URI Too Large',
- 415 => 'Unsupported Media Type',
- 416 => 'Request Range Not Satisfiable',
- 417 => 'Expectation Failed',
- 422 => 'Unprocessable Entity',
- 423 => 'Locked',
- 424 => 'Failed Dependency',
- 426 => 'Upgrade Required',
- 428 => 'Precondition Required',
- 429 => 'Too Many Requests',
- 431 => 'Request Header Fields Too Large',
- 500 => 'Internal Server Error',
- 501 => 'Not Implemented',
- 502 => 'Bad Gateway',
- 503 => 'Service Unavailable',
- 504 => 'Gateway Timeout',
- 505 => 'HTTP Version Not Supported',
- 507 => 'Insufficient Storage',
- 511 => 'Network Authentication Required',
- }
-
- # Maps a status code to the corresponding Status class
- CodeToError = {} # :nodoc:
-
- # Creates a status or error class for each status code and
- # populates the CodeToError map.
- StatusMessage.each{|code, message|
- message.freeze
- var_name = message.gsub(/[ \-]/,'_').upcase
- err_name = message.gsub(/[ \-]/,'')
-
- case code
- when 100...200; parent = Info
- when 200...300; parent = Success
- when 300...400; parent = Redirect
- when 400...500; parent = ClientError
- when 500...600; parent = ServerError
- end
-
- const_set("RC_#{var_name}", code)
- err_class = Class.new(parent)
- err_class.instance_variable_set(:@code, code)
- err_class.instance_variable_set(:@reason_phrase, message)
- const_set(err_name, err_class)
- CodeToError[code] = err_class
- }
-
- ##
- # Returns the description corresponding to the HTTP status +code+
- #
- # WEBrick::HTTPStatus.reason_phrase 404
- # => "Not Found"
- def reason_phrase(code)
- StatusMessage[code.to_i]
- end
-
- ##
- # Is +code+ an informational status?
- def info?(code)
- code.to_i >= 100 and code.to_i < 200
- end
-
- ##
- # Is +code+ a successful status?
- def success?(code)
- code.to_i >= 200 and code.to_i < 300
- end
-
- ##
- # Is +code+ a redirection status?
- def redirect?(code)
- code.to_i >= 300 and code.to_i < 400
- end
-
- ##
- # Is +code+ an error status?
- def error?(code)
- code.to_i >= 400 and code.to_i < 600
- end
-
- ##
- # Is +code+ a client error status?
- def client_error?(code)
- code.to_i >= 400 and code.to_i < 500
- end
-
- ##
- # Is +code+ a server error status?
- def server_error?(code)
- code.to_i >= 500 and code.to_i < 600
- end
-
- ##
- # Returns the status class corresponding to +code+
- #
- # WEBrick::HTTPStatus[302]
- # => WEBrick::HTTPStatus::NotFound
- #
- def self.[](code)
- CodeToError[code]
- end
-
- module_function :reason_phrase
- module_function :info?, :success?, :redirect?, :error?
- module_function :client_error?, :server_error?
- end
-end
diff --git a/ruby_2_2/lib/webrick/httputils.rb b/ruby_2_2/lib/webrick/httputils.rb
deleted file mode 100644
index a5f0632b86..0000000000
--- a/ruby_2_2/lib/webrick/httputils.rb
+++ /dev/null
@@ -1,509 +0,0 @@
-#
-# httputils.rb -- HTTPUtils Module
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2000, 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: httputils.rb,v 1.34 2003/06/05 21:34:08 gotoyuzo Exp $
-
-require 'socket'
-require 'tempfile'
-
-module WEBrick
- CR = "\x0d" # :nodoc:
- LF = "\x0a" # :nodoc:
- CRLF = "\x0d\x0a" # :nodoc:
-
- ##
- # HTTPUtils provides utility methods for working with the HTTP protocol.
- #
- # This module is generally used internally by WEBrick
-
- module HTTPUtils
-
- ##
- # Normalizes a request path. Raises an exception if the path cannot be
- # normalized.
-
- def normalize_path(path)
- raise "abnormal path `#{path}'" if path[0] != ?/
- ret = path.dup
-
- ret.gsub!(%r{/+}o, '/') # // => /
- while ret.sub!(%r'/\.(?:/|\Z)', '/'); end # /. => /
- while ret.sub!(%r'/(?!\.\./)[^/]+/\.\.(?:/|\Z)', '/'); end # /foo/.. => /foo
-
- raise "abnormal path `#{path}'" if %r{/\.\.(/|\Z)} =~ ret
- ret
- end
- module_function :normalize_path
-
- ##
- # Default mime types
-
- DefaultMimeTypes = {
- "ai" => "application/postscript",
- "asc" => "text/plain",
- "avi" => "video/x-msvideo",
- "bin" => "application/octet-stream",
- "bmp" => "image/bmp",
- "class" => "application/octet-stream",
- "cer" => "application/pkix-cert",
- "crl" => "application/pkix-crl",
- "crt" => "application/x-x509-ca-cert",
- #"crl" => "application/x-pkcs7-crl",
- "css" => "text/css",
- "dms" => "application/octet-stream",
- "doc" => "application/msword",
- "dvi" => "application/x-dvi",
- "eps" => "application/postscript",
- "etx" => "text/x-setext",
- "exe" => "application/octet-stream",
- "gif" => "image/gif",
- "htm" => "text/html",
- "html" => "text/html",
- "jpe" => "image/jpeg",
- "jpeg" => "image/jpeg",
- "jpg" => "image/jpeg",
- "js" => "application/javascript",
- "lha" => "application/octet-stream",
- "lzh" => "application/octet-stream",
- "mov" => "video/quicktime",
- "mpe" => "video/mpeg",
- "mpeg" => "video/mpeg",
- "mpg" => "video/mpeg",
- "pbm" => "image/x-portable-bitmap",
- "pdf" => "application/pdf",
- "pgm" => "image/x-portable-graymap",
- "png" => "image/png",
- "pnm" => "image/x-portable-anymap",
- "ppm" => "image/x-portable-pixmap",
- "ppt" => "application/vnd.ms-powerpoint",
- "ps" => "application/postscript",
- "qt" => "video/quicktime",
- "ras" => "image/x-cmu-raster",
- "rb" => "text/plain",
- "rd" => "text/plain",
- "rtf" => "application/rtf",
- "sgm" => "text/sgml",
- "sgml" => "text/sgml",
- "svg" => "image/svg+xml",
- "tif" => "image/tiff",
- "tiff" => "image/tiff",
- "txt" => "text/plain",
- "xbm" => "image/x-xbitmap",
- "xhtml" => "text/html",
- "xls" => "application/vnd.ms-excel",
- "xml" => "text/xml",
- "xpm" => "image/x-xpixmap",
- "xwd" => "image/x-xwindowdump",
- "zip" => "application/zip",
- }
-
- ##
- # Loads Apache-compatible mime.types in +file+.
-
- def load_mime_types(file)
- open(file){ |io|
- hash = Hash.new
- io.each{ |line|
- next if /^#/ =~ line
- line.chomp!
- mimetype, ext0 = line.split(/\s+/, 2)
- next unless ext0
- next if ext0.empty?
- ext0.split(/\s+/).each{ |ext| hash[ext] = mimetype }
- }
- hash
- }
- end
- module_function :load_mime_types
-
- ##
- # Returns the mime type of +filename+ from the list in +mime_tab+. If no
- # mime type was found application/octet-stream is returned.
-
- def mime_type(filename, mime_tab)
- suffix1 = (/\.(\w+)$/ =~ filename && $1.downcase)
- suffix2 = (/\.(\w+)\.[\w\-]+$/ =~ filename && $1.downcase)
- mime_tab[suffix1] || mime_tab[suffix2] || "application/octet-stream"
- end
- module_function :mime_type
-
- ##
- # Parses an HTTP header +raw+ into a hash of header fields with an Array
- # of values.
-
- def parse_header(raw)
- header = Hash.new([].freeze)
- field = nil
- raw.each_line{|line|
- case line
- when /^([A-Za-z0-9!\#$%&'*+\-.^_`|~]+):\s*(.*?)\s*\z/om
- field, value = $1, $2
- field.downcase!
- header[field] = [] unless header.has_key?(field)
- header[field] << value
- when /^\s+(.*?)\s*\z/om
- value = $1
- unless field
- raise HTTPStatus::BadRequest, "bad header '#{line}'."
- end
- header[field][-1] << " " << value
- else
- raise HTTPStatus::BadRequest, "bad header '#{line}'."
- end
- }
- header.each{|key, values|
- values.each{|value|
- value.strip!
- value.gsub!(/\s+/, " ")
- }
- }
- header
- end
- module_function :parse_header
-
- ##
- # Splits a header value +str+ according to HTTP specification.
-
- def split_header_value(str)
- str.scan(%r'\G((?:"(?:\\.|[^"])+?"|[^",]+)+)
- (?:,\s*|\Z)'xn).flatten
- end
- module_function :split_header_value
-
- ##
- # Parses a Range header value +ranges_specifier+
-
- def parse_range_header(ranges_specifier)
- if /^bytes=(.*)/ =~ ranges_specifier
- byte_range_set = split_header_value($1)
- byte_range_set.collect{|range_spec|
- case range_spec
- when /^(\d+)-(\d+)/ then $1.to_i .. $2.to_i
- when /^(\d+)-/ then $1.to_i .. -1
- when /^-(\d+)/ then -($1.to_i) .. -1
- else return nil
- end
- }
- end
- end
- module_function :parse_range_header
-
- ##
- # Parses q values in +value+ as used in Accept headers.
-
- def parse_qvalues(value)
- tmp = []
- if value
- parts = value.split(/,\s*/)
- parts.each {|part|
- if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part)
- val = m[1]
- q = (m[2] or 1).to_f
- tmp.push([val, q])
- end
- }
- tmp = tmp.sort_by{|val, q| -q}
- tmp.collect!{|val, q| val}
- end
- return tmp
- end
- module_function :parse_qvalues
-
- ##
- # Removes quotes and escapes from +str+
-
- def dequote(str)
- ret = (/\A"(.*)"\Z/ =~ str) ? $1 : str.dup
- ret.gsub!(/\\(.)/, "\\1")
- ret
- end
- module_function :dequote
-
- ##
- # Quotes and escapes quotes in +str+
-
- def quote(str)
- '"' << str.gsub(/[\\\"]/o, "\\\1") << '"'
- end
- module_function :quote
-
- ##
- # Stores multipart form data. FormData objects are created when
- # WEBrick::HTTPUtils.parse_form_data is called.
-
- class FormData < String
- EmptyRawHeader = [].freeze # :nodoc:
- EmptyHeader = {}.freeze # :nodoc:
-
- ##
- # The name of the form data part
-
- attr_accessor :name
-
- ##
- # The filename of the form data part
-
- attr_accessor :filename
-
- attr_accessor :next_data # :nodoc:
- protected :next_data
-
- ##
- # Creates a new FormData object.
- #
- # +args+ is an Array of form data entries. One FormData will be created
- # for each entry.
- #
- # This is called by WEBrick::HTTPUtils.parse_form_data for you
-
- def initialize(*args)
- @name = @filename = @next_data = nil
- if args.empty?
- @raw_header = []
- @header = nil
- super("")
- else
- @raw_header = EmptyRawHeader
- @header = EmptyHeader
- super(args.shift)
- unless args.empty?
- @next_data = self.class.new(*args)
- end
- end
- end
-
- ##
- # Retrieves the header at the first entry in +key+
-
- def [](*key)
- begin
- @header[key[0].downcase].join(", ")
- rescue StandardError, NameError
- super
- end
- end
-
- ##
- # Adds +str+ to this FormData which may be the body, a header or a
- # header entry.
- #
- # This is called by WEBrick::HTTPUtils.parse_form_data for you
-
- def <<(str)
- if @header
- super
- elsif str == CRLF
- @header = HTTPUtils::parse_header(@raw_header.join)
- if cd = self['content-disposition']
- if /\s+name="(.*?)"/ =~ cd then @name = $1 end
- if /\s+filename="(.*?)"/ =~ cd then @filename = $1 end
- end
- else
- @raw_header << str
- end
- self
- end
-
- ##
- # Adds +data+ at the end of the chain of entries
- #
- # This is called by WEBrick::HTTPUtils.parse_form_data for you.
-
- def append_data(data)
- tmp = self
- while tmp
- unless tmp.next_data
- tmp.next_data = data
- break
- end
- tmp = tmp.next_data
- end
- self
- end
-
- ##
- # Yields each entry in this FormData
-
- def each_data
- tmp = self
- while tmp
- next_data = tmp.next_data
- yield(tmp)
- tmp = next_data
- end
- end
-
- ##
- # Returns all the FormData as an Array
-
- def list
- ret = []
- each_data{|data|
- ret << data.to_s
- }
- ret
- end
-
- ##
- # A FormData will behave like an Array
-
- alias :to_ary :list
-
- ##
- # This FormData's body
-
- def to_s
- String.new(self)
- end
- end
-
- ##
- # Parses the query component of a URI in +str+
-
- def parse_query(str)
- query = Hash.new
- if str
- str.split(/[&;]/).each{|x|
- next if x.empty?
- key, val = x.split(/=/,2)
- key = unescape_form(key)
- val = unescape_form(val.to_s)
- val = FormData.new(val)
- val.name = key
- if query.has_key?(key)
- query[key].append_data(val)
- next
- end
- query[key] = val
- }
- end
- query
- end
- module_function :parse_query
-
- ##
- # Parses form data in +io+ with the given +boundary+
-
- def parse_form_data(io, boundary)
- boundary_regexp = /\A--#{Regexp.quote(boundary)}(--)?#{CRLF}\z/
- form_data = Hash.new
- return form_data unless io
- data = nil
- io.each_line{|line|
- if boundary_regexp =~ line
- if data
- data.chop!
- key = data.name
- if form_data.has_key?(key)
- form_data[key].append_data(data)
- else
- form_data[key] = data
- end
- end
- data = FormData.new
- next
- else
- if data
- data << line
- end
- end
- }
- return form_data
- end
- module_function :parse_form_data
-
- #####
-
- reserved = ';/?:@&=+$,'
- num = '0123456789'
- lowalpha = 'abcdefghijklmnopqrstuvwxyz'
- upalpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- mark = '-_.!~*\'()'
- unreserved = num + lowalpha + upalpha + mark
- control = (0x0..0x1f).collect{|c| c.chr }.join + "\x7f"
- space = " "
- delims = '<>#%"'
- unwise = '{}|\\^[]`'
- nonascii = (0x80..0xff).collect{|c| c.chr }.join
-
- module_function
-
- # :stopdoc:
-
- def _make_regex(str) /([#{Regexp.escape(str)}])/n end
- def _make_regex!(str) /([^#{Regexp.escape(str)}])/n end
- def _escape(str, regex)
- str = str.b
- str.gsub!(regex) {"%%%02X" % $1.ord}
- # %-escaped string should contain US-ASCII only
- str.force_encoding(Encoding::US_ASCII)
- end
- def _unescape(str, regex)
- str = str.b
- str.gsub!(regex) {$1.hex.chr}
- # encoding of %-unescaped string is unknown
- str
- end
-
- UNESCAPED = _make_regex(control+space+delims+unwise+nonascii)
- UNESCAPED_FORM = _make_regex(reserved+control+delims+unwise+nonascii)
- NONASCII = _make_regex(nonascii)
- ESCAPED = /%([0-9a-fA-F]{2})/
- UNESCAPED_PCHAR = _make_regex!(unreserved+":@&=+$,")
-
- # :startdoc:
-
- ##
- # Escapes HTTP reserved and unwise characters in +str+
-
- def escape(str)
- _escape(str, UNESCAPED)
- end
-
- ##
- # Unescapes HTTP reserved and unwise characters in +str+
-
- def unescape(str)
- _unescape(str, ESCAPED)
- end
-
- ##
- # Escapes form reserved characters in +str+
-
- def escape_form(str)
- ret = _escape(str, UNESCAPED_FORM)
- ret.gsub!(/ /, "+")
- ret
- end
-
- ##
- # Unescapes form reserved characters in +str+
-
- def unescape_form(str)
- _unescape(str.gsub(/\+/, " "), ESCAPED)
- end
-
- ##
- # Escapes path +str+
-
- def escape_path(str)
- result = ""
- str.scan(%r{/([^/]*)}).each{|i|
- result << "/" << _escape(i[0], UNESCAPED_PCHAR)
- }
- return result
- end
-
- ##
- # Escapes 8 bit characters in +str+
-
- def escape8bit(str)
- _escape(str, NONASCII)
- end
- end
-end
diff --git a/ruby_2_2/lib/webrick/httpversion.rb b/ruby_2_2/lib/webrick/httpversion.rb
deleted file mode 100644
index cdfb957296..0000000000
--- a/ruby_2_2/lib/webrick/httpversion.rb
+++ /dev/null
@@ -1,75 +0,0 @@
-#--
-# HTTPVersion.rb -- presentation of HTTP version
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: httpversion.rb,v 1.5 2002/09/21 12:23:37 gotoyuzo Exp $
-
-module WEBrick
-
- ##
- # Represents an HTTP protocol version
-
- class HTTPVersion
- include Comparable
-
- ##
- # The major protocol version number
-
- attr_accessor :major
-
- ##
- # The minor protocol version number
-
- attr_accessor :minor
-
- ##
- # Converts +version+ into an HTTPVersion
-
- def self.convert(version)
- version.is_a?(self) ? version : new(version)
- end
-
- ##
- # Creates a new HTTPVersion from +version+.
-
- def initialize(version)
- case version
- when HTTPVersion
- @major, @minor = version.major, version.minor
- when String
- if /^(\d+)\.(\d+)$/ =~ version
- @major, @minor = $1.to_i, $2.to_i
- end
- end
- if @major.nil? || @minor.nil?
- raise ArgumentError,
- format("cannot convert %s into %s", version.class, self.class)
- end
- end
-
- ##
- # Compares this version with +other+ according to the HTTP specification
- # rules.
-
- def <=>(other)
- unless other.is_a?(self.class)
- other = self.class.new(other)
- end
- if (ret = @major <=> other.major) == 0
- return @minor <=> other.minor
- end
- return ret
- end
-
- ##
- # The HTTP version as show in the HTTP request and response. For example,
- # "1.1"
-
- def to_s
- format("%d.%d", @major, @minor)
- end
- end
-end
diff --git a/ruby_2_2/lib/webrick/log.rb b/ruby_2_2/lib/webrick/log.rb
deleted file mode 100644
index 4f069ac0c5..0000000000
--- a/ruby_2_2/lib/webrick/log.rb
+++ /dev/null
@@ -1,155 +0,0 @@
-#--
-# log.rb -- Log Class
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2000, 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: log.rb,v 1.26 2002/10/06 17:06:10 gotoyuzo Exp $
-
-module WEBrick
-
- ##
- # A generic logging class
-
- class BasicLog
-
- # Fatal log level which indicates a server crash
-
- FATAL = 1
-
- # Error log level which indicates a recoverable error
-
- ERROR = 2
-
- # Warning log level which indicates a possible problem
-
- WARN = 3
-
- # Information log level which indicates possibly useful information
-
- INFO = 4
-
- # Debugging error level for messages used in server development or
- # debugging
-
- DEBUG = 5
-
- # log-level, messages above this level will be logged
- attr_accessor :level
-
- ##
- # Initializes a new logger for +log_file+ that outputs messages at +level+
- # or higher. +log_file+ can be a filename, an IO-like object that
- # responds to #<< or nil which outputs to $stderr.
- #
- # If no level is given INFO is chosen by default
-
- def initialize(log_file=nil, level=nil)
- @level = level || INFO
- case log_file
- when String
- @log = open(log_file, "a+")
- @log.sync = true
- @opened = true
- when NilClass
- @log = $stderr
- else
- @log = log_file # requires "<<". (see BasicLog#log)
- end
- end
-
- ##
- # Closes the logger (also closes the log device associated to the logger)
- def close
- @log.close if @opened
- @log = nil
- end
-
- ##
- # Logs +data+ at +level+ if the given level is above the current log
- # level.
-
- def log(level, data)
- if @log && level <= @level
- data += "\n" if /\n\Z/ !~ data
- @log << data
- end
- end
-
- ##
- # Synonym for log(INFO, obj.to_s)
- def <<(obj)
- log(INFO, obj.to_s)
- end
-
- # Shortcut for logging a FATAL message
- def fatal(msg) log(FATAL, "FATAL " << format(msg)); end
- # Shortcut for logging an ERROR message
- def error(msg) log(ERROR, "ERROR " << format(msg)); end
- # Shortcut for logging a WARN message
- def warn(msg) log(WARN, "WARN " << format(msg)); end
- # Shortcut for logging an INFO message
- def info(msg) log(INFO, "INFO " << format(msg)); end
- # Shortcut for logging a DEBUG message
- def debug(msg) log(DEBUG, "DEBUG " << format(msg)); end
-
- # Will the logger output FATAL messages?
- def fatal?; @level >= FATAL; end
- # Will the logger output ERROR messages?
- def error?; @level >= ERROR; end
- # Will the logger output WARN messages?
- def warn?; @level >= WARN; end
- # Will the logger output INFO messages?
- def info?; @level >= INFO; end
- # Will the logger output DEBUG messages?
- def debug?; @level >= DEBUG; end
-
- private
-
- ##
- # Formats +arg+ for the logger
- #
- # * If +arg+ is an Exception, it will format the error message and
- # the back trace.
- # * If +arg+ responds to #to_str, it will return it.
- # * Otherwise it will return +arg+.inspect.
- def format(arg)
- if arg.is_a?(Exception)
- "#{arg.class}: #{AccessLog.escape(arg.message)}\n\t" <<
- arg.backtrace.join("\n\t") << "\n"
- elsif arg.respond_to?(:to_str)
- AccessLog.escape(arg.to_str)
- else
- arg.inspect
- end
- end
- end
-
- ##
- # A logging class that prepends a timestamp to each message.
-
- class Log < BasicLog
- # Format of the timestamp which is applied to each logged line. The
- # default is <tt>"[%Y-%m-%d %H:%M:%S]"</tt>
- attr_accessor :time_format
-
- ##
- # Same as BasicLog#initialize
- #
- # You can set the timestamp format through #time_format
- def initialize(log_file=nil, level=nil)
- super(log_file, level)
- @time_format = "[%Y-%m-%d %H:%M:%S]"
- end
-
- ##
- # Same as BasicLog#log
- def log(level, data)
- tmp = Time.now.strftime(@time_format)
- tmp << " " << data
- super(level, tmp)
- end
- end
-end
diff --git a/ruby_2_2/lib/webrick/server.rb b/ruby_2_2/lib/webrick/server.rb
deleted file mode 100644
index 4aafd1e7fe..0000000000
--- a/ruby_2_2/lib/webrick/server.rb
+++ /dev/null
@@ -1,365 +0,0 @@
-#
-# server.rb -- GenericServer Class
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2000, 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: server.rb,v 1.62 2003/07/22 19:20:43 gotoyuzo Exp $
-
-require 'thread'
-require 'socket'
-require 'webrick/config'
-require 'webrick/log'
-
-module WEBrick
-
- ##
- # Server error exception
-
- class ServerError < StandardError; end
-
- ##
- # Base server class
-
- class SimpleServer
-
- ##
- # A SimpleServer only yields when you start it
-
- def SimpleServer.start
- yield
- end
- end
-
- ##
- # A generic module for daemonizing a process
-
- class Daemon
-
- ##
- # Performs the standard operations for daemonizing a process. Runs a
- # block, if given.
-
- def Daemon.start
- exit!(0) if fork
- Process::setsid
- exit!(0) if fork
- Dir::chdir("/")
- File::umask(0)
- STDIN.reopen("/dev/null")
- STDOUT.reopen("/dev/null", "w")
- STDERR.reopen("/dev/null", "w")
- yield if block_given?
- end
- end
-
- ##
- # Base TCP server class. You must subclass GenericServer and provide a #run
- # method.
-
- class GenericServer
-
- ##
- # The server status. One of :Stop, :Running or :Shutdown
-
- attr_reader :status
-
- ##
- # The server configuration
-
- attr_reader :config
-
- ##
- # The server logger. This is independent from the HTTP access log.
-
- attr_reader :logger
-
- ##
- # Tokens control the number of outstanding clients. The
- # <code>:MaxClients</code> configuration sets this.
-
- attr_reader :tokens
-
- ##
- # Sockets listening for connections.
-
- attr_reader :listeners
-
- ##
- # Creates a new generic server from +config+. The default configuration
- # comes from +default+.
-
- def initialize(config={}, default=Config::General)
- @config = default.dup.update(config)
- @status = :Stop
- @config[:Logger] ||= Log::new
- @logger = @config[:Logger]
-
- @tokens = SizedQueue.new(@config[:MaxClients])
- @config[:MaxClients].times{ @tokens.push(nil) }
-
- webrickv = WEBrick::VERSION
- rubyv = "#{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
- @logger.info("WEBrick #{webrickv}")
- @logger.info("ruby #{rubyv}")
-
- @listeners = []
- @shutdown_pipe = nil
- unless @config[:DoNotListen]
- if @config[:Listen]
- warn(":Listen option is deprecated; use GenericServer#listen")
- end
- listen(@config[:BindAddress], @config[:Port])
- if @config[:Port] == 0
- @config[:Port] = @listeners[0].addr[1]
- end
- end
- end
-
- ##
- # Retrieves +key+ from the configuration
-
- def [](key)
- @config[key]
- end
-
- ##
- # Adds listeners from +address+ and +port+ to the server. See
- # WEBrick::Utils::create_listeners for details.
-
- def listen(address, port)
- @listeners += Utils::create_listeners(address, port, @logger)
- setup_shutdown_pipe
- end
-
- ##
- # Starts the server and runs the +block+ for each connection. This method
- # does not return until the server is stopped from a signal handler or
- # another thread using #stop or #shutdown.
- #
- # If the block raises a subclass of StandardError the exception is logged
- # and ignored. If an IOError or Errno::EBADF exception is raised the
- # exception is ignored. If an Exception subclass is raised the exception
- # is logged and re-raised which stops the server.
- #
- # To completely shut down a server call #shutdown from ensure:
- #
- # server = WEBrick::GenericServer.new
- # # or WEBrick::HTTPServer.new
- #
- # begin
- # server.start
- # ensure
- # server.shutdown
- # end
-
- def start(&block)
- raise ServerError, "already started." if @status != :Stop
- server_type = @config[:ServerType] || SimpleServer
-
- server_type.start{
- @logger.info \
- "#{self.class}#start: pid=#{$$} port=#{@config[:Port]}"
- call_callback(:StartCallback)
-
- shutdown_pipe = @shutdown_pipe
-
- thgroup = ThreadGroup.new
- @status = :Running
- begin
- while @status == :Running
- begin
- if svrs = IO.select([shutdown_pipe[0], *@listeners], nil, nil, 2.0)
- if svrs[0].include? shutdown_pipe[0]
- break
- end
- svrs[0].each{|svr|
- @tokens.pop # blocks while no token is there.
- if sock = accept_client(svr)
- sock.do_not_reverse_lookup = config[:DoNotReverseLookup]
- th = start_thread(sock, &block)
- th[:WEBrickThread] = true
- thgroup.add(th)
- else
- @tokens.push(nil)
- end
- }
- end
- rescue Errno::EBADF, Errno::ENOTSOCK, IOError => ex
- # if the listening socket was closed in GenericServer#shutdown,
- # IO::select raise it.
- rescue StandardError => ex
- msg = "#{ex.class}: #{ex.message}\n\t#{ex.backtrace[0]}"
- @logger.error msg
- rescue Exception => ex
- @logger.fatal ex
- raise
- end
- end
- ensure
- cleanup_shutdown_pipe(shutdown_pipe)
- cleanup_listener
- @status = :Shutdown
- @logger.info "going to shutdown ..."
- thgroup.list.each{|th| th.join if th[:WEBrickThread] }
- call_callback(:StopCallback)
- @logger.info "#{self.class}#start done."
- @status = :Stop
- end
- }
- end
-
- ##
- # Stops the server from accepting new connections.
-
- def stop
- if @status == :Running
- @status = :Shutdown
- end
- end
-
- ##
- # Shuts down the server and all listening sockets. New listeners must be
- # provided to restart the server.
-
- def shutdown
- stop
-
- shutdown_pipe = @shutdown_pipe # another thread may modify @shutdown_pipe.
- if shutdown_pipe
- if !shutdown_pipe[1].closed?
- begin
- shutdown_pipe[1].close
- rescue IOError # closed by another thread.
- end
- end
- end
- end
-
- ##
- # You must subclass GenericServer and implement \#run which accepts a TCP
- # client socket
-
- def run(sock)
- @logger.fatal "run() must be provided by user."
- end
-
- private
-
- # :stopdoc:
-
- ##
- # Accepts a TCP client socket from the TCP server socket +svr+ and returns
- # the client socket.
-
- def accept_client(svr)
- sock = nil
- begin
- sock = svr.accept
- sock.sync = true
- Utils::set_non_blocking(sock)
- Utils::set_close_on_exec(sock)
- rescue Errno::ECONNRESET, Errno::ECONNABORTED,
- Errno::EPROTO, Errno::EINVAL
- rescue StandardError => ex
- msg = "#{ex.class}: #{ex.message}\n\t#{ex.backtrace[0]}"
- @logger.error msg
- end
- return sock
- end
-
- ##
- # Starts a server thread for the client socket +sock+ that runs the given
- # +block+.
- #
- # Sets the socket to the <code>:WEBrickSocket</code> thread local variable
- # in the thread.
- #
- # If any errors occur in the block they are logged and handled.
-
- def start_thread(sock, &block)
- Thread.start{
- begin
- Thread.current[:WEBrickSocket] = sock
- begin
- addr = sock.peeraddr
- @logger.debug "accept: #{addr[3]}:#{addr[1]}"
- rescue SocketError
- @logger.debug "accept: <address unknown>"
- raise
- end
- call_callback(:AcceptCallback, sock)
- block ? block.call(sock) : run(sock)
- rescue Errno::ENOTCONN
- @logger.debug "Errno::ENOTCONN raised"
- rescue ServerError => ex
- msg = "#{ex.class}: #{ex.message}\n\t#{ex.backtrace[0]}"
- @logger.error msg
- rescue Exception => ex
- @logger.error ex
- ensure
- @tokens.push(nil)
- Thread.current[:WEBrickSocket] = nil
- if addr
- @logger.debug "close: #{addr[3]}:#{addr[1]}"
- else
- @logger.debug "close: <address unknown>"
- end
- sock.close unless sock.closed?
- end
- }
- end
-
- ##
- # Calls the callback +callback_name+ from the configuration with +args+
-
- def call_callback(callback_name, *args)
- if cb = @config[callback_name]
- cb.call(*args)
- end
- end
-
- def setup_shutdown_pipe
- if !@shutdown_pipe
- @shutdown_pipe = IO.pipe
- end
- @shutdown_pipe
- end
-
- def cleanup_shutdown_pipe(shutdown_pipe)
- @shutdown_pipe = nil
- shutdown_pipe.each {|io|
- if !io.closed?
- begin
- io.close
- rescue IOError # another thread closed io.
- end
- end
- }
- end
-
- def cleanup_listener
- @listeners.each{|s|
- if @logger.debug?
- addr = s.addr
- @logger.debug("close TCPSocket(#{addr[2]}, #{addr[1]})")
- end
- begin
- s.shutdown
- rescue Errno::ENOTCONN
- # when `Errno::ENOTCONN: Socket is not connected' on some platforms,
- # call #close instead of #shutdown.
- # (ignore @config[:ShutdownSocketWithoutClose])
- s.close
- else
- unless @config[:ShutdownSocketWithoutClose]
- s.close
- end
- end
- }
- @listeners.clear
- end
- end # end of GenericServer
-end
diff --git a/ruby_2_2/lib/webrick/ssl.rb b/ruby_2_2/lib/webrick/ssl.rb
deleted file mode 100644
index 19c1e104da..0000000000
--- a/ruby_2_2/lib/webrick/ssl.rb
+++ /dev/null
@@ -1,196 +0,0 @@
-#
-# ssl.rb -- SSL/TLS enhancement for GenericServer
-#
-# Copyright (c) 2003 GOTOU Yuuzou All rights reserved.
-#
-# $Id$
-
-require 'webrick'
-require 'openssl'
-
-module WEBrick
- module Config
- svrsoft = General[:ServerSoftware]
- osslv = ::OpenSSL::OPENSSL_VERSION.split[1]
-
- ##
- # Default SSL server configuration.
- #
- # WEBrick can automatically create a self-signed certificate if
- # <code>:SSLCertName</code> is set. For more information on the various
- # SSL options see OpenSSL::SSL::SSLContext.
- #
- # :ServerSoftware ::
- # The server software name used in the Server: header.
- # :SSLEnable :: false,
- # Enable SSL for this server. Defaults to false.
- # :SSLCertificate ::
- # The SSL certificate for the server.
- # :SSLPrivateKey ::
- # The SSL private key for the server certificate.
- # :SSLClientCA :: nil,
- # Array of certificates that will be sent to the client.
- # :SSLExtraChainCert :: nil,
- # Array of certificates that will be added to the certificate chain
- # :SSLCACertificateFile :: nil,
- # Path to a CA certificate file
- # :SSLCACertificatePath :: nil,
- # Path to a directory containing CA certificates
- # :SSLCertificateStore :: nil,
- # OpenSSL::X509::Store used for certificate validation of the client
- # :SSLTmpDhCallback :: nil,
- # Callback invoked when DH parameters are required.
- # :SSLVerifyClient ::
- # Sets whether the client is verified. This defaults to VERIFY_NONE
- # which is typical for an HTTPS server.
- # :SSLVerifyDepth ::
- # Number of CA certificates to walk when verifying a certificate chain
- # :SSLVerifyCallback ::
- # Custom certificate verification callback
- # :SSLTimeout ::
- # Maximum session lifetime
- # :SSLOptions ::
- # Various SSL options
- # :SSLStartImmediately ::
- # Immediately start SSL upon connection? Defaults to true
- # :SSLCertName ::
- # SSL certificate name. Must be set to enable automatic certificate
- # creation.
- # :SSLCertComment ::
- # Comment used during automatic certificate creation.
-
- SSL = {
- :ServerSoftware => "#{svrsoft} OpenSSL/#{osslv}",
- :SSLEnable => false,
- :SSLCertificate => nil,
- :SSLPrivateKey => nil,
- :SSLClientCA => nil,
- :SSLExtraChainCert => nil,
- :SSLCACertificateFile => nil,
- :SSLCACertificatePath => nil,
- :SSLCertificateStore => nil,
- :SSLTmpDhCallback => nil,
- :SSLVerifyClient => ::OpenSSL::SSL::VERIFY_NONE,
- :SSLVerifyDepth => nil,
- :SSLVerifyCallback => nil, # custom verification
- :SSLTimeout => nil,
- :SSLOptions => nil,
- :SSLStartImmediately => true,
- # Must specify if you use auto generated certificate.
- :SSLCertName => nil,
- :SSLCertComment => "Generated by Ruby/OpenSSL"
- }
- General.update(SSL)
- end
-
- module Utils
- ##
- # Creates a self-signed certificate with the given number of +bits+,
- # the issuer +cn+ and a +comment+ to be stored in the certificate.
-
- def create_self_signed_cert(bits, cn, comment)
- rsa = OpenSSL::PKey::RSA.new(bits){|p, n|
- case p
- when 0; $stderr.putc "." # BN_generate_prime
- when 1; $stderr.putc "+" # BN_generate_prime
- when 2; $stderr.putc "*" # searching good prime,
- # n = #of try,
- # but also data from BN_generate_prime
- when 3; $stderr.putc "\n" # found good prime, n==0 - p, n==1 - q,
- # but also data from BN_generate_prime
- else; $stderr.putc "*" # BN_generate_prime
- end
- }
- cert = OpenSSL::X509::Certificate.new
- cert.version = 2
- cert.serial = 1
- name = OpenSSL::X509::Name.new(cn)
- cert.subject = name
- cert.issuer = name
- cert.not_before = Time.now
- cert.not_after = Time.now + (365*24*60*60)
- cert.public_key = rsa.public_key
-
- ef = OpenSSL::X509::ExtensionFactory.new(nil,cert)
- ef.issuer_certificate = cert
- cert.extensions = [
- ef.create_extension("basicConstraints","CA:FALSE"),
- ef.create_extension("keyUsage", "keyEncipherment"),
- ef.create_extension("subjectKeyIdentifier", "hash"),
- ef.create_extension("extendedKeyUsage", "serverAuth"),
- ef.create_extension("nsComment", comment),
- ]
- aki = ef.create_extension("authorityKeyIdentifier",
- "keyid:always,issuer:always")
- cert.add_extension(aki)
- cert.sign(rsa, OpenSSL::Digest::SHA1.new)
-
- return [ cert, rsa ]
- end
- module_function :create_self_signed_cert
- end
-
- ##
- #--
- # Updates WEBrick::GenericServer with SSL functionality
-
- class GenericServer
-
- ##
- # SSL context for the server when run in SSL mode
-
- def ssl_context # :nodoc:
- @ssl_context ||= nil
- end
-
- undef listen
-
- ##
- # Updates +listen+ to enable SSL when the SSL configuration is active.
-
- def listen(address, port) # :nodoc:
- listeners = Utils::create_listeners(address, port, @logger)
- if @config[:SSLEnable]
- unless ssl_context
- @ssl_context = setup_ssl_context(@config)
- @logger.info("\n" + @config[:SSLCertificate].to_text)
- end
- listeners.collect!{|svr|
- ssvr = ::OpenSSL::SSL::SSLServer.new(svr, ssl_context)
- ssvr.start_immediately = @config[:SSLStartImmediately]
- ssvr
- }
- end
- @listeners += listeners
- setup_shutdown_pipe
- end
-
- ##
- # Sets up an SSL context for +config+
-
- def setup_ssl_context(config) # :nodoc:
- unless config[:SSLCertificate]
- cn = config[:SSLCertName]
- comment = config[:SSLCertComment]
- cert, key = Utils::create_self_signed_cert(1024, cn, comment)
- config[:SSLCertificate] = cert
- config[:SSLPrivateKey] = key
- end
- ctx = OpenSSL::SSL::SSLContext.new
- ctx.key = config[:SSLPrivateKey]
- ctx.cert = config[:SSLCertificate]
- ctx.client_ca = config[:SSLClientCA]
- ctx.extra_chain_cert = config[:SSLExtraChainCert]
- ctx.ca_file = config[:SSLCACertificateFile]
- ctx.ca_path = config[:SSLCACertificatePath]
- ctx.cert_store = config[:SSLCertificateStore]
- ctx.tmp_dh_callback = config[:SSLTmpDhCallback]
- ctx.verify_mode = config[:SSLVerifyClient]
- ctx.verify_depth = config[:SSLVerifyDepth]
- ctx.verify_callback = config[:SSLVerifyCallback]
- ctx.timeout = config[:SSLTimeout]
- ctx.options = config[:SSLOptions]
- ctx
- end
- end
-end
diff --git a/ruby_2_2/lib/webrick/utils.rb b/ruby_2_2/lib/webrick/utils.rb
deleted file mode 100644
index 606ede5ac3..0000000000
--- a/ruby_2_2/lib/webrick/utils.rb
+++ /dev/null
@@ -1,230 +0,0 @@
-#
-# utils.rb -- Miscellaneous utilities
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
-# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: utils.rb,v 1.10 2003/02/16 22:22:54 gotoyuzo Exp $
-
-require 'socket'
-require 'fcntl'
-require 'etc'
-
-module WEBrick
- module Utils
- ##
- # Sets IO operations on +io+ to be non-blocking
- def set_non_blocking(io)
- flag = File::NONBLOCK
- if defined?(Fcntl::F_GETFL)
- flag |= io.fcntl(Fcntl::F_GETFL)
- end
- io.fcntl(Fcntl::F_SETFL, flag)
- end
- module_function :set_non_blocking
-
- ##
- # Sets the close on exec flag for +io+
- def set_close_on_exec(io)
- if defined?(Fcntl::FD_CLOEXEC)
- io.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
- end
- end
- module_function :set_close_on_exec
-
- ##
- # Changes the process's uid and gid to the ones of +user+
- def su(user)
- if pw = Etc.getpwnam(user)
- Process::initgroups(user, pw.gid)
- Process::Sys::setgid(pw.gid)
- Process::Sys::setuid(pw.uid)
- else
- warn("WEBrick::Utils::su doesn't work on this platform")
- end
- end
- module_function :su
-
- ##
- # The server hostname
- def getservername
- host = Socket::gethostname
- begin
- Socket::gethostbyname(host)[0]
- rescue
- host
- end
- end
- module_function :getservername
-
- ##
- # Creates TCP server sockets bound to +address+:+port+ and returns them.
- #
- # It will create IPV4 and IPV6 sockets on all interfaces.
- def create_listeners(address, port, logger=nil)
- unless port
- raise ArgumentError, "must specify port"
- end
- sockets = Socket.tcp_server_sockets(address, port)
- sockets = sockets.map {|s|
- s.autoclose = false
- ts = TCPServer.for_fd(s.fileno)
- s.close
- ts
- }
- return sockets
- end
- module_function :create_listeners
-
- ##
- # Characters used to generate random strings
- RAND_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
- "0123456789" +
- "abcdefghijklmnopqrstuvwxyz"
-
- ##
- # Generates a random string of length +len+
- def random_string(len)
- rand_max = RAND_CHARS.bytesize
- ret = ""
- len.times{ ret << RAND_CHARS[rand(rand_max)] }
- ret
- end
- module_function :random_string
-
- ###########
-
- require "thread"
- require "timeout"
- require "singleton"
-
- ##
- # Class used to manage timeout handlers across multiple threads.
- #
- # Timeout handlers should be managed by using the class methods which are
- # synchronized.
- #
- # id = TimeoutHandler.register(10, Timeout::Error)
- # begin
- # sleep 20
- # puts 'foo'
- # ensure
- # TimeoutHandler.cancel(id)
- # end
- #
- # will raise Timeout::Error
- #
- # id = TimeoutHandler.register(10, Timeout::Error)
- # begin
- # sleep 5
- # puts 'foo'
- # ensure
- # TimeoutHandler.cancel(id)
- # end
- #
- # will print 'foo'
- #
- class TimeoutHandler
- include Singleton
-
- class Thread < ::Thread; end
-
- ##
- # Mutex used to synchronize access across threads
- TimeoutMutex = Mutex.new # :nodoc:
-
- ##
- # Registers a new timeout handler
- #
- # +time+:: Timeout in seconds
- # +exception+:: Exception to raise when timeout elapsed
- def TimeoutHandler.register(seconds, exception)
- TimeoutMutex.synchronize{
- instance.register(Thread.current, Time.now + seconds, exception)
- }
- end
-
- ##
- # Cancels the timeout handler +id+
- def TimeoutHandler.cancel(id)
- TimeoutMutex.synchronize{
- instance.cancel(Thread.current, id)
- }
- end
-
- ##
- # Creates a new TimeoutHandler. You should use ::register and ::cancel
- # instead of creating the timeout handler directly.
- def initialize
- @timeout_info = Hash.new
- Thread.start{
- while true
- now = Time.now
- @timeout_info.keys.each{|thread|
- ary = @timeout_info[thread]
- next unless ary
- ary.dup.each{|info|
- time, exception = *info
- interrupt(thread, info.object_id, exception) if time < now
- }
- }
- sleep 0.5
- end
- }
- end
-
- ##
- # Interrupts the timeout handler +id+ and raises +exception+
- def interrupt(thread, id, exception)
- TimeoutMutex.synchronize{
- if cancel(thread, id) && thread.alive?
- thread.raise(exception, "execution timeout")
- end
- }
- end
-
- ##
- # Registers a new timeout handler
- #
- # +time+:: Timeout in seconds
- # +exception+:: Exception to raise when timeout elapsed
- def register(thread, time, exception)
- @timeout_info[thread] ||= Array.new
- @timeout_info[thread] << [time, exception]
- return @timeout_info[thread].last.object_id
- end
-
- ##
- # Cancels the timeout handler +id+
- def cancel(thread, id)
- if ary = @timeout_info[thread]
- ary.delete_if{|info| info.object_id == id }
- if ary.empty?
- @timeout_info.delete(thread)
- end
- return true
- end
- return false
- end
- end
-
- ##
- # Executes the passed block and raises +exception+ if execution takes more
- # than +seconds+.
- #
- # If +seconds+ is zero or nil, simply executes the block
- def timeout(seconds, exception=Timeout::Error)
- return yield if seconds.nil? or seconds.zero?
- # raise ThreadError, "timeout within critical session" if Thread.critical
- id = TimeoutHandler.register(seconds, exception)
- begin
- yield(seconds)
- ensure
- TimeoutHandler.cancel(id)
- end
- end
- module_function :timeout
- end
-end
diff --git a/ruby_2_2/lib/webrick/version.rb b/ruby_2_2/lib/webrick/version.rb
deleted file mode 100644
index 48bdc6d94d..0000000000
--- a/ruby_2_2/lib/webrick/version.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-#--
-# version.rb -- version and release date
-#
-# Author: IPR -- Internet Programming with Ruby -- writers
-# Copyright (c) 2000 TAKAHASHI Masayoshi, GOTOU YUUZOU
-# Copyright (c) 2003 Internet Programming with Ruby writers. All rights
-# reserved.
-#
-# $IPR: version.rb,v 1.74 2003/07/22 19:20:43 gotoyuzo Exp $
-
-module WEBrick
-
- ##
- # The WEBrick version
-
- VERSION = "1.3.1"
-end
diff --git a/ruby_2_2/lib/xmlrpc.rb b/ruby_2_2/lib/xmlrpc.rb
deleted file mode 100644
index 511c57d269..0000000000
--- a/ruby_2_2/lib/xmlrpc.rb
+++ /dev/null
@@ -1,301 +0,0 @@
-# == Author and Copyright
-#
-# Copyright (C) 2001-2004 by Michael Neumann (mailto:mneumann@ntecs.de)
-#
-# Released under the same term of license as Ruby.
-#
-# == Overview
-#
-# XMLRPC is a lightweight protocol that enables remote procedure calls over
-# HTTP. It is defined at http://www.xmlrpc.com.
-#
-# XMLRPC allows you to create simple distributed computing solutions that span
-# computer languages. Its distinctive feature is its simplicity compared to
-# other approaches like SOAP and CORBA.
-#
-# The Ruby standard library package 'xmlrpc' enables you to create a server that
-# implements remote procedures and a client that calls them. Very little code
-# is required to achieve either of these.
-#
-# == Example
-#
-# Try the following code. It calls a standard demonstration remote procedure.
-#
-# require 'xmlrpc/client'
-# require 'pp'
-#
-# server = XMLRPC::Client.new2("http://xmlrpc-c.sourceforge.net/api/sample.php")
-# result = server.call("sample.sumAndDifference", 5, 3)
-# pp result
-#
-# == Documentation
-#
-# See http://www.ntecs.de/ruby/xmlrpc4r/. There is plenty of detail there to
-# use the client and implement a server.
-#
-# == Features of XMLRPC for Ruby
-#
-# * Extensions
-# * Introspection
-# * multiCall
-# * optionally nil values and integers larger than 32 Bit
-#
-# * Server
-# * Standalone XML-RPC server
-# * CGI-based (works with FastCGI)
-# * Apache mod_ruby server
-# * WEBrick servlet
-#
-# * Client
-# * synchronous/asynchronous calls
-# * Basic HTTP-401 Authentication
-# * HTTPS protocol (SSL)
-#
-# * Parsers
-# * NQXML (XMLParser::NQXMLStreamParser, XMLParser::NQXMLTreeParser)
-# * Expat (XMLParser::XMLStreamParser, XMLParser::XMLTreeParser)
-# * REXML (XMLParser::REXMLStreamParser)
-# * xml-scan (XMLParser::XMLScanStreamParser)
-# * Fastest parser is Expat's XMLParser::XMLStreamParser!
-#
-# * General
-# * possible to choose between XMLParser module (Expat wrapper) and REXML/NQXML (pure Ruby) parsers
-# * Marshalling Ruby objects to Hashs and reconstruct them later from a Hash
-# * SandStorm component architecture XMLRPC::Client interface
-#
-# == Howto
-#
-# === Client
-#
-# require "xmlrpc/client"
-#
-# # Make an object to represent the XML-RPC server.
-# server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php")
-#
-# # Call the remote server and get our result
-# result = server.call("sample.sumAndDifference", 5, 3)
-#
-# sum = result["sum"]
-# difference = result["difference"]
-#
-# puts "Sum: #{sum}, Difference: #{difference}"
-#
-# === XMLRPC::Client with XML-RPC fault-structure handling
-#
-# There are two possible ways, of handling a fault-structure:
-#
-# ==== by catching a XMLRPC::FaultException exception
-#
-# require "xmlrpc/client"
-#
-# # Make an object to represent the XML-RPC server.
-# server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php")
-#
-# begin
-# # Call the remote server and get our result
-# result = server.call("sample.sumAndDifference", 5, 3)
-#
-# sum = result["sum"]
-# difference = result["difference"]
-#
-# puts "Sum: #{sum}, Difference: #{difference}"
-#
-# rescue XMLRPC::FaultException => e
-# puts "Error: "
-# puts e.faultCode
-# puts e.faultString
-# end
-#
-# ==== by calling "call2" which returns a boolean
-#
-# require "xmlrpc/client"
-#
-# # Make an object to represent the XML-RPC server.
-# server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php")
-#
-# # Call the remote server and get our result
-# ok, result = server.call2("sample.sumAndDifference", 5, 3)
-#
-# if ok
-# sum = result["sum"]
-# difference = result["difference"]
-#
-# puts "Sum: #{sum}, Difference: #{difference}"
-# else
-# puts "Error: "
-# puts result.faultCode
-# puts result.faultString
-# end
-#
-# === Using XMLRPC::Client::Proxy
-#
-# You can create a Proxy object onto which you can call methods. This way it
-# looks nicer. Both forms, _call_ and _call2_ are supported through _proxy_ and
-# _proxy2_. You can additionally give arguments to the Proxy, which will be
-# given to each XML-RPC call using that Proxy.
-#
-# require "xmlrpc/client"
-#
-# # Make an object to represent the XML-RPC server.
-# server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php")
-#
-# # Create a Proxy object
-# sample = server.proxy("sample")
-#
-# # Call the remote server and get our result
-# result = sample.sumAndDifference(5,3)
-#
-# sum = result["sum"]
-# difference = result["difference"]
-#
-# puts "Sum: #{sum}, Difference: #{difference}"
-#
-# === CGI-based server using XMLRPC::CGIServer
-#
-# There are also two ways to define handler, the first is
-# like C/PHP, the second like Java, of course both ways
-# can be mixed:
-#
-# ==== C/PHP-like (handler functions)
-#
-# require "xmlrpc/server"
-#
-# s = XMLRPC::CGIServer.new
-#
-# s.add_handler("sample.sumAndDifference") do |a,b|
-# { "sum" => a + b, "difference" => a - b }
-# end
-#
-# s.serve
-#
-# ==== Java-like (handler classes)
-#
-# require "xmlrpc/server"
-#
-# s = XMLRPC::CGIServer.new
-#
-# class MyHandler
-# def sumAndDifference(a, b)
-# { "sum" => a + b, "difference" => a - b }
-# end
-# end
-#
-# # NOTE: Security Hole (read below)!!!
-# s.add_handler("sample", MyHandler.new)
-# s.serve
-#
-#
-# To return a fault-structure you have to raise an XMLRPC::FaultException e.g.:
-#
-# raise XMLRPC::FaultException.new(3, "division by Zero")
-#
-# ===== Security Note
-#
-# From Brian Candler:
-#
-# Above code sample has an extremely nasty security hole, in that you can now call
-# any method of 'MyHandler' remotely, including methods inherited from Object
-# and Kernel! For example, in the client code, you can use
-#
-# puts server.call("sample.send","`","ls")
-#
-# (backtick being the method name for running system processes). Needless to
-# say, 'ls' can be replaced with something else.
-#
-# The version which binds proc objects (or the version presented below in the next section)
-# doesn't have this problem, but people may be tempted to use the second version because it's
-# so nice and 'Rubyesque'. I think it needs a big red disclaimer.
-#
-#
-# From Michael:
-#
-# A solution is to undef insecure methods or to use
-# XMLRPC::Service::PublicInstanceMethodsInterface as shown below:
-#
-# class MyHandler
-# def sumAndDifference(a, b)
-# { "sum" => a + b, "difference" => a - b }
-# end
-# end
-#
-# # ... server initialization ...
-#
-# s.add_handler(XMLRPC::iPIMethods("sample"), MyHandler.new)
-#
-# # ...
-#
-# This adds only public instance methods explicitly declared in class MyHandler
-# (and not those inherited from any other class).
-#
-# ==== With interface declarations
-#
-# Code sample from the book Ruby Developer's Guide:
-#
-# require "xmlrpc/server"
-#
-# class Num
-# INTERFACE = XMLRPC::interface("num") {
-# meth 'int add(int, int)', 'Add two numbers', 'add'
-# meth 'int div(int, int)', 'Divide two numbers'
-# }
-#
-# def add(a, b) a + b end
-# def div(a, b) a / b end
-# end
-#
-#
-# s = XMLRPC::CGIServer.new
-# s.add_handler(Num::INTERFACE, Num.new)
-# s.serve
-#
-# === Standalone XMLRPC::Server
-#
-# Same as CGI-based server, the only difference being
-#
-# server = XMLRPC::CGIServer.new
-#
-# must be changed to
-#
-# server = XMLRPC::Server.new(8080)
-#
-# if you want a server listening on port 8080.
-# The rest is the same.
-#
-# === Choosing a different XMLParser or XMLWriter
-#
-# The examples above all use the default parser (which is now since 1.8
-# XMLParser::REXMLStreamParser) and a default XMLRPC::XMLWriter.
-# If you want to use a different XMLParser, then you have to call the
-# ParserWriterChooseMixin#set_parser method of XMLRPC::Client instances
-# or instances of subclasses of XMLRPC::BasicServer or by editing
-# xmlrpc/config.rb.
-#
-# XMLRPC::Client Example:
-#
-# # ...
-# server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php")
-# server.set_parser(XMLRPC::XMLParser::XMLParser.new)
-# # ...
-#
-# XMLRPC::Server Example:
-#
-# # ...
-# s = XMLRPC::CGIServer.new
-# s.set_parser(XMLRPC::XMLParser::XMLStreamParser.new)
-# # ...
-#
-# or:
-#
-# # ...
-# server = XMLRPC::Server.new(8080)
-# server.set_parser(XMLRPC::XMLParser::NQXMLParser.new)
-# # ...
-#
-#
-# Note that XMLParser::XMLStreamParser is incredible faster (and uses less memory) than any
-# other parser and scales well for large documents. For example for a 0.5 MB XML
-# document with many tags, XMLParser::XMLStreamParser is ~350 (!) times faster than
-# XMLParser::NQXMLTreeParser and still ~18 times as fast as XMLParser::XMLTreeParser.
-#
-# You can change the XML-writer by calling method ParserWriterChooseMixin#set_writer.
-module XMLRPC; end
diff --git a/ruby_2_2/lib/xmlrpc/base64.rb b/ruby_2_2/lib/xmlrpc/base64.rb
deleted file mode 100644
index 4aac3520c5..0000000000
--- a/ruby_2_2/lib/xmlrpc/base64.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-#
-# xmlrpc/base64.rb
-# Copyright (C) 2001, 2002, 2003 by Michael Neumann (mneumann@ntecs.de)
-#
-# Released under the same term of license as Ruby.
-
-module XMLRPC # :nodoc:
-
-# This class is necessary for 'xmlrpc4r' to determine that a string should
-# be transmitted base64-encoded and not as a raw-string.
-#
-# You can use XMLRPC::Base64 on the client and server-side as a
-# parameter and/or return-value.
-class Base64
-
- # Creates a new XMLRPC::Base64 instance with string +str+ as the
- # internal string. When +state+ is +:dec+ it assumes that the
- # string +str+ is not in base64 format (perhaps already decoded),
- # otherwise if +state+ is +:enc+ it decodes +str+
- # and stores it as the internal string.
- def initialize(str, state = :dec)
- case state
- when :enc
- @str = Base64.decode(str)
- when :dec
- @str = str
- else
- raise ArgumentError, "wrong argument; either :enc or :dec"
- end
- end
-
- # Returns the decoded internal string.
- def decoded
- @str
- end
-
- # Returns the base64 encoded internal string.
- def encoded
- Base64.encode(@str)
- end
-
-
- # Decodes string +str+ with base64 and returns that value.
- def Base64.decode(str)
- str.gsub(/\s+/, "").unpack("m")[0]
- end
-
- # Encodes string +str+ with base64 and returns that value.
- def Base64.encode(str)
- [str].pack("m")
- end
-
-end
-
-
-end # module XMLRPC
-
-
-=begin
-= History
- $Id$
-=end
diff --git a/ruby_2_2/lib/xmlrpc/client.rb b/ruby_2_2/lib/xmlrpc/client.rb
deleted file mode 100644
index 0947b95ef5..0000000000
--- a/ruby_2_2/lib/xmlrpc/client.rb
+++ /dev/null
@@ -1,628 +0,0 @@
-# xmlrpc/client.rb
-# Copyright (C) 2001, 2002, 2003 by Michael Neumann (mneumann@ntecs.de)
-#
-# Released under the same term of license as Ruby.
-#
-# History
-# $Id$
-#
-require "xmlrpc/parser"
-require "xmlrpc/create"
-require "xmlrpc/config"
-require "xmlrpc/utils" # ParserWriterChooseMixin
-require "net/http"
-require "uri"
-
-module XMLRPC # :nodoc:
-
- # Provides remote procedure calls to a XML-RPC server.
- #
- # After setting the connection-parameters with XMLRPC::Client.new which
- # creates a new XMLRPC::Client instance, you can execute a remote procedure
- # by sending the XMLRPC::Client#call or XMLRPC::Client#call2
- # message to this new instance.
- #
- # The given parameters indicate which method to call on the remote-side and
- # of course the parameters for the remote procedure.
- #
- # require "xmlrpc/client"
- #
- # server = XMLRPC::Client.new("www.ruby-lang.org", "/RPC2", 80)
- # begin
- # param = server.call("michael.add", 4, 5)
- # puts "4 + 5 = #{param}"
- # rescue XMLRPC::FaultException => e
- # puts "Error:"
- # puts e.faultCode
- # puts e.faultString
- # end
- #
- # or
- #
- # require "xmlrpc/client"
- #
- # server = XMLRPC::Client.new("www.ruby-lang.org", "/RPC2", 80)
- # ok, param = server.call2("michael.add", 4, 5)
- # if ok then
- # puts "4 + 5 = #{param}"
- # else
- # puts "Error:"
- # puts param.faultCode
- # puts param.faultString
- # end
- class Client
-
- USER_AGENT = "XMLRPC::Client (Ruby #{RUBY_VERSION})"
-
- include ParserWriterChooseMixin
- include ParseContentType
-
-
- # Creates an object which represents the remote XML-RPC server on the
- # given +host+. If the server is CGI-based, +path+ is the
- # path to the CGI-script, which will be called, otherwise (in the
- # case of a standalone server) +path+ should be <tt>"/RPC2"</tt>.
- # +port+ is the port on which the XML-RPC server listens.
- #
- # If +proxy_host+ is given, then a proxy server listening at
- # +proxy_host+ is used. +proxy_port+ is the port of the
- # proxy server.
- #
- # Default values for +host+, +path+ and +port+ are 'localhost', '/RPC2' and
- # '80' respectively using SSL '443'.
- #
- # If +user+ and +password+ are given, each time a request is sent,
- # an Authorization header is sent. Currently only Basic Authentication is
- # implemented, no Digest.
- #
- # If +use_ssl+ is set to +true+, communication over SSL is enabled.
- #
- # Parameter +timeout+ is the time to wait for a XML-RPC response, defaults to 30.
- def initialize(host=nil, path=nil, port=nil, proxy_host=nil, proxy_port=nil,
- user=nil, password=nil, use_ssl=nil, timeout=nil)
-
- @http_header_extra = nil
- @http_last_response = nil
- @cookie = nil
-
- @host = host || "localhost"
- @path = path || "/RPC2"
- @proxy_host = proxy_host
- @proxy_port = proxy_port
- @proxy_host ||= 'localhost' if @proxy_port != nil
- @proxy_port ||= 8080 if @proxy_host != nil
- @use_ssl = use_ssl || false
- @timeout = timeout || 30
-
- if use_ssl
- require "net/https"
- @port = port || 443
- else
- @port = port || 80
- end
-
- @user, @password = user, password
-
- set_auth
-
- # convert ports to integers
- @port = @port.to_i if @port != nil
- @proxy_port = @proxy_port.to_i if @proxy_port != nil
-
- # HTTP object for synchronous calls
- @http = net_http(@host, @port, @proxy_host, @proxy_port)
- @http.use_ssl = @use_ssl if @use_ssl
- @http.read_timeout = @timeout
- @http.open_timeout = @timeout
-
- @parser = nil
- @create = nil
- end
-
-
- class << self
-
- # Creates an object which represents the remote XML-RPC server at the
- # given +uri+. The URI should have a host, port, path, user and password.
- # Example: https://user:password@host:port/path
- #
- # Raises an ArgumentError if the +uri+ is invalid,
- # or if the protocol isn't http or https.
- #
- # If a +proxy+ is given it should be in the form of "host:port".
- #
- # The optional +timeout+ defaults to 30 seconds.
- def new2(uri, proxy=nil, timeout=nil)
- begin
- url = URI(uri)
- rescue URI::InvalidURIError => e
- raise ArgumentError, e.message, e.backtrace
- end
-
- unless URI::HTTP === url
- raise ArgumentError, "Wrong protocol specified. Only http or https allowed!"
- end
-
- proto = url.scheme
- user = url.user
- passwd = url.password
- host = url.host
- port = url.port
- path = url.path.empty? ? nil : url.request_uri
-
- proxy_host, proxy_port = (proxy || "").split(":")
- proxy_port = proxy_port.to_i if proxy_port
-
- self.new(host, path, port, proxy_host, proxy_port, user, passwd, (proto == "https"), timeout)
- end
-
- alias new_from_uri new2
-
- # Receives a Hash and calls XMLRPC::Client.new
- # with the corresponding values.
- #
- # The +hash+ parameter has following case-insensitive keys:
- # * host
- # * path
- # * port
- # * proxy_host
- # * proxy_port
- # * user
- # * password
- # * use_ssl
- # * timeout
- def new3(hash={})
-
- # convert all keys into lowercase strings
- h = {}
- hash.each { |k,v| h[k.to_s.downcase] = v }
-
- self.new(h['host'], h['path'], h['port'], h['proxy_host'], h['proxy_port'], h['user'], h['password'],
- h['use_ssl'], h['timeout'])
- end
-
- alias new_from_hash new3
-
- end
-
-
- # Returns the Net::HTTP object for the client. If you want to
- # change HTTP client options except header, cookie, timeout,
- # user and password, use Net::HTTP directly.
- #
- # Since 2.1.0.
- attr_reader :http
-
- # Add additional HTTP headers to the request
- attr_accessor :http_header_extra
-
- # Returns the Net::HTTPResponse object of the last RPC.
- attr_reader :http_last_response
-
- # Get and set the HTTP Cookie header.
- attr_accessor :cookie
-
-
- # Return the corresponding attributes.
- attr_reader :timeout, :user, :password
-
- # Sets the Net::HTTP#read_timeout and Net::HTTP#open_timeout to
- # +new_timeout+
- def timeout=(new_timeout)
- @timeout = new_timeout
- @http.read_timeout = @timeout
- @http.open_timeout = @timeout
- end
-
- # Changes the user for the Basic Authentication header to +new_user+
- def user=(new_user)
- @user = new_user
- set_auth
- end
-
- # Changes the password for the Basic Authentication header to
- # +new_password+
- def password=(new_password)
- @password = new_password
- set_auth
- end
-
- # Invokes the method named +method+ with the parameters given by
- # +args+ on the XML-RPC server.
- #
- # The +method+ parameter is converted into a String and should
- # be a valid XML-RPC method-name.
- #
- # Each parameter of +args+ must be of one of the following types,
- # where Hash, Struct and Array can contain any of these listed _types_:
- #
- # * Fixnum, Bignum
- # * TrueClass, FalseClass, +true+, +false+
- # * String, Symbol
- # * Float
- # * Hash, Struct
- # * Array
- # * Date, Time, XMLRPC::DateTime
- # * XMLRPC::Base64
- # * A Ruby object which class includes XMLRPC::Marshallable
- # (only if Config::ENABLE_MARSHALLING is +true+).
- # That object is converted into a hash, with one additional key/value
- # pair <code>___class___</code> which contains the class name
- # for restoring that object later.
- #
- # The method returns the return-value from the Remote Procedure Call.
- #
- # The type of the return-value is one of the types shown above.
- #
- # A Bignum is only allowed when it fits in 32-bit. A XML-RPC
- # +dateTime.iso8601+ type is always returned as a XMLRPC::DateTime object.
- # Struct is never returned, only a Hash, the same for a Symbol, where as a
- # String is always returned. XMLRPC::Base64 is returned as a String from
- # xmlrpc4r version 1.6.1 on.
- #
- # If the remote procedure returned a fault-structure, then a
- # XMLRPC::FaultException exception is raised, which has two accessor-methods
- # +faultCode+ an Integer, and +faultString+ a String.
- def call(method, *args)
- ok, param = call2(method, *args)
- if ok
- param
- else
- raise param
- end
- end
-
- # The difference between this method and XMLRPC::Client#call is, that
- # this method will <b>NOT</b> raise a XMLRPC::FaultException exception.
- #
- # The method returns an array of two values. The first value indicates if
- # the second value is +true+ or an XMLRPC::FaultException.
- #
- # Both are explained in XMLRPC::Client#call.
- #
- # Simple to remember: The "2" in "call2" denotes the number of values it returns.
- def call2(method, *args)
- request = create().methodCall(method, *args)
- data = do_rpc(request, false)
- parser().parseMethodResponse(data)
- end
-
- # Similar to XMLRPC::Client#call, however can be called concurrently and
- # use a new connection for each request. In contrast to the corresponding
- # method without the +_async+ suffix, which use connect-alive (one
- # connection for all requests).
- #
- # Note, that you have to use Thread to call these methods concurrently.
- # The following example calls two methods concurrently:
- #
- # Thread.new {
- # p client.call_async("michael.add", 4, 5)
- # }
- #
- # Thread.new {
- # p client.call_async("michael.div", 7, 9)
- # }
- #
- def call_async(method, *args)
- ok, param = call2_async(method, *args)
- if ok
- param
- else
- raise param
- end
- end
-
- # Same as XMLRPC::Client#call2, but can be called concurrently.
- #
- # See also XMLRPC::Client#call_async
- def call2_async(method, *args)
- request = create().methodCall(method, *args)
- data = do_rpc(request, true)
- parser().parseMethodResponse(data)
- end
-
-
- # You can use this method to execute several methods on a XMLRPC server
- # which support the multi-call extension.
- #
- # s.multicall(
- # ['michael.add', 3, 4],
- # ['michael.sub', 4, 5]
- # )
- # # => [7, -1]
- def multicall(*methods)
- ok, params = multicall2(*methods)
- if ok
- params
- else
- raise params
- end
- end
-
- # Same as XMLRPC::Client#multicall, but returns two parameters instead of
- # raising an XMLRPC::FaultException.
- #
- # See XMLRPC::Client#call2
- def multicall2(*methods)
- gen_multicall(methods, false)
- end
-
- # Similar to XMLRPC::Client#multicall, however can be called concurrently and
- # use a new connection for each request. In contrast to the corresponding
- # method without the +_async+ suffix, which use connect-alive (one
- # connection for all requests).
- #
- # Note, that you have to use Thread to call these methods concurrently.
- # The following example calls two methods concurrently:
- #
- # Thread.new {
- # p client.multicall_async("michael.add", 4, 5)
- # }
- #
- # Thread.new {
- # p client.multicall_async("michael.div", 7, 9)
- # }
- #
- def multicall_async(*methods)
- ok, params = multicall2_async(*methods)
- if ok
- params
- else
- raise params
- end
- end
-
- # Same as XMLRPC::Client#multicall2, but can be called concurrently.
- #
- # See also XMLRPC::Client#multicall_async
- def multicall2_async(*methods)
- gen_multicall(methods, true)
- end
-
-
- # Returns an object of class XMLRPC::Client::Proxy, initialized with
- # +prefix+ and +args+.
- #
- # A proxy object returned by this method behaves like XMLRPC::Client#call,
- # i.e. a call on that object will raise a XMLRPC::FaultException when a
- # fault-structure is returned by that call.
- def proxy(prefix=nil, *args)
- Proxy.new(self, prefix, args, :call)
- end
-
- # Almost the same like XMLRPC::Client#proxy only that a call on the returned
- # XMLRPC::Client::Proxy object will return two parameters.
- #
- # See XMLRPC::Client#call2
- def proxy2(prefix=nil, *args)
- Proxy.new(self, prefix, args, :call2)
- end
-
- # Similar to XMLRPC::Client#proxy, however can be called concurrently and
- # use a new connection for each request. In contrast to the corresponding
- # method without the +_async+ suffix, which use connect-alive (one
- # connection for all requests).
- #
- # Note, that you have to use Thread to call these methods concurrently.
- # The following example calls two methods concurrently:
- #
- # Thread.new {
- # p client.proxy_async("michael.add", 4, 5)
- # }
- #
- # Thread.new {
- # p client.proxy_async("michael.div", 7, 9)
- # }
- #
- def proxy_async(prefix=nil, *args)
- Proxy.new(self, prefix, args, :call_async)
- end
-
- # Same as XMLRPC::Client#proxy2, but can be called concurrently.
- #
- # See also XMLRPC::Client#proxy_async
- def proxy2_async(prefix=nil, *args)
- Proxy.new(self, prefix, args, :call2_async)
- end
-
-
- private
-
- def net_http(host, port, proxy_host, proxy_port)
- Net::HTTP.new host, port, proxy_host, proxy_port
- end
-
- def dup_net_http
- http = net_http(@http.address,
- @http.port,
- @http.proxy_address,
- @http.proxy_port)
- http.proxy_user = @http.proxy_user
- http.proxy_pass = @http.proxy_pass
- if @http.use_ssl?
- http.use_ssl = true
- Net::HTTP::SSL_ATTRIBUTES.each do |attribute|
- http.__send__("#{attribute}=", @http.__send__(attribute))
- end
- end
- http.read_timeout = @http.read_timeout
- http.open_timeout = @http.open_timeout
- http
- end
-
- def set_auth
- if @user.nil?
- @auth = nil
- else
- a = "#@user"
- a << ":#@password" if @password != nil
- @auth = "Basic " + [a].pack("m0")
- end
- end
-
- def do_rpc(request, async=false)
- header = {
- "User-Agent" => USER_AGENT,
- "Content-Type" => "text/xml; charset=utf-8",
- "Content-Length" => request.bytesize.to_s,
- "Connection" => (async ? "close" : "keep-alive")
- }
-
- header["Cookie"] = @cookie if @cookie
- header.update(@http_header_extra) if @http_header_extra
-
- if @auth != nil
- # add authorization header
- header["Authorization"] = @auth
- end
-
- resp = nil
- @http_last_response = nil
-
- if async
- # use a new HTTP object for each call
- http = dup_net_http
-
- # post request
- http.start {
- resp = http.request_post(@path, request, header)
- }
- else
- # reuse the HTTP object for each call => connection alive is possible
- # we must start connection explicitly first time so that http.request
- # does not assume that we don't want keepalive
- @http.start if not @http.started?
-
- # post request
- resp = @http.request_post(@path, request, header)
- end
-
- @http_last_response = resp
-
- data = resp.body
-
- if resp.code == "401"
- # Authorization Required
- raise "Authorization failed.\nHTTP-Error: #{resp.code} #{resp.message}"
- elsif resp.code[0,1] != "2"
- raise "HTTP-Error: #{resp.code} #{resp.message}"
- end
-
- # assume text/xml on instances where Content-Type header is not set
- ct_expected = resp["Content-Type"] || 'text/xml'
- ct = parse_content_type(ct_expected).first
- if ct != "text/xml"
- if ct == "text/html"
- raise "Wrong content-type (received '#{ct}' but expected 'text/xml'): \n#{data}"
- else
- raise "Wrong content-type (received '#{ct}' but expected 'text/xml')"
- end
- end
-
- expected = resp["Content-Length"] || "<unknown>"
- if data.nil? or data.bytesize == 0
- raise "Wrong size. Was #{data.bytesize}, should be #{expected}"
- end
-
- parse_set_cookies(resp.get_fields("Set-Cookie"))
-
- return data
- end
-
- def parse_set_cookies(set_cookies)
- return if set_cookies.nil?
- return if set_cookies.empty?
- require 'webrick/cookie'
- pairs = {}
- set_cookies.each do |set_cookie|
- cookie = WEBrick::Cookie.parse_set_cookie(set_cookie)
- pairs.delete(cookie.name)
- pairs[cookie.name] = cookie.value
- end
- cookies = pairs.collect do |name, value|
- WEBrick::Cookie.new(name, value).to_s
- end
- @cookie = cookies.join("; ")
- end
-
- def gen_multicall(methods=[], async=false)
- meth = :call2
- meth = :call2_async if async
-
- ok, params = self.send(meth, "system.multicall",
- methods.collect {|m| {'methodName' => m[0], 'params' => m[1..-1]} }
- )
-
- if ok
- params = params.collect do |param|
- if param.is_a? Array
- param[0]
- elsif param.is_a? Hash
- XMLRPC::FaultException.new(param["faultCode"], param["faultString"])
- else
- raise "Wrong multicall return value"
- end
- end
- end
-
- return ok, params
- end
-
-
-
- # XML-RPC calls look nicer!
- #
- # You can call any method onto objects of that class - the object handles
- # XMLRPC::Client::Proxy#method_missing and will forward the method call to
- # a XML-RPC server.
- #
- # Don't use this class directly, instead use the public instance method
- # XMLRPC::Client#proxy or XMLRPC::Client#proxy2.
- #
- # require "xmlrpc/client"
- #
- # server = XMLRPC::Client.new("www.ruby-lang.org", "/RPC2", 80)
- #
- # michael = server.proxy("michael")
- # michael2 = server.proxy("michael", 4)
- #
- # # both calls should return the same value '9'.
- # p michael.add(4,5)
- # p michael2.add(5)
- class Proxy
-
- # Creates an object which provides XMLRPC::Client::Proxy#method_missing.
- #
- # The given +server+ must be an instance of XMLRPC::Client, which is the
- # XML-RPC server to be used for a XML-RPC call.
- #
- # +prefix+ and +delim+ will be prepended to the method name called onto this object.
- #
- # An optional parameter +meth+ is the method to use for a RPC.
- # It can be either, call, call2, call_async, call2_async
- #
- # +args+ are arguments which are automatically given to every XML-RPC
- # call before being provided through +method_missing+.
- def initialize(server, prefix, args=[], meth=:call, delim=".")
- @server = server
- @prefix = prefix ? prefix + delim : ""
- @args = args
- @meth = meth
- end
-
- # Every method call is forwarded to the XML-RPC server defined in
- # XMLRPC::Client::Proxy#new.
- #
- # Note: Inherited methods from class Object cannot be used as XML-RPC
- # names, because they get around +method_missing+.
- def method_missing(mid, *args)
- pre = @prefix + mid.to_s
- arg = @args + args
- @server.send(@meth, pre, *arg)
- end
-
- end # class Proxy
-
- end # class Client
-
-end # module XMLRPC
diff --git a/ruby_2_2/lib/xmlrpc/config.rb b/ruby_2_2/lib/xmlrpc/config.rb
deleted file mode 100644
index 7923f3a26e..0000000000
--- a/ruby_2_2/lib/xmlrpc/config.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-#
-# $Id$
-# Configuration file for XML-RPC for Ruby
-#
-
-module XMLRPC # :nodoc:
-
- module Config
-
- # or XMLWriter::XMLParser
- DEFAULT_WRITER = XMLWriter::Simple
-
- # === Available parsers
- #
- # * XMLParser::NQXMLTreeParser
- # * XMLParser::NQXMLStreamParser
- # * XMLParser::XMLTreeParser
- # * XMLParser::XMLStreamParser (fastest)
- # * XMLParser::REXMLStreamParser
- # * XMLParser::XMLScanStreamParser
- # * XMLParser::LibXMLStreamParser
- DEFAULT_PARSER = XMLParser::REXMLStreamParser
-
- # enable <code><nil/></code> tag
- ENABLE_NIL_CREATE = false
- ENABLE_NIL_PARSER = false
-
- # allows integers greater than 32-bit if +true+
- ENABLE_BIGINT = false
-
- # enable marshalling Ruby objects which include XMLRPC::Marshallable
- ENABLE_MARSHALLING = true
-
- # enable multiCall extension by default
- ENABLE_MULTICALL = false
-
- # enable Introspection extension by default
- ENABLE_INTROSPECTION = false
-
- end
-
-end
-
diff --git a/ruby_2_2/lib/xmlrpc/create.rb b/ruby_2_2/lib/xmlrpc/create.rb
deleted file mode 100644
index 13c9cd8faa..0000000000
--- a/ruby_2_2/lib/xmlrpc/create.rb
+++ /dev/null
@@ -1,286 +0,0 @@
-#
-# Copyright (C) 2001, 2002, 2003 by Michael Neumann (mneumann@ntecs.de)
-#
-# $Id$
-#
-
-require "date"
-require "xmlrpc/base64"
-
-module XMLRPC # :nodoc:
-
- module XMLWriter
-
- class Abstract
- def ele(name, *children)
- element(name, nil, *children)
- end
-
- def tag(name, txt)
- element(name, nil, text(txt))
- end
- end
-
-
- class Simple < Abstract
-
- def document_to_str(doc)
- doc
- end
-
- def document(*params)
- params.join("")
- end
-
- def pi(name, *params)
- "<?#{name} " + params.join(" ") + " ?>"
- end
-
- def element(name, attrs, *children)
- raise "attributes not yet implemented" unless attrs.nil?
- if children.empty?
- "<#{name}/>"
- else
- "<#{name}>" + children.join("") + "</#{name}>"
- end
- end
-
- def text(txt)
- cleaned = txt.dup
- cleaned.gsub!(/&/, '&amp;')
- cleaned.gsub!(/</, '&lt;')
- cleaned.gsub!(/>/, '&gt;')
- cleaned
- end
-
- end # class Simple
-
-
- class XMLParser < Abstract
-
- def initialize
- require "xmltreebuilder"
- end
-
- def document_to_str(doc)
- doc.to_s
- end
-
- def document(*params)
- XML::SimpleTree::Document.new(*params)
- end
-
- def pi(name, *params)
- XML::SimpleTree::ProcessingInstruction.new(name, *params)
- end
-
- def element(name, attrs, *children)
- XML::SimpleTree::Element.new(name, attrs, *children)
- end
-
- def text(txt)
- XML::SimpleTree::Text.new(txt)
- end
-
- end # class XMLParser
-
- Classes = [Simple, XMLParser]
-
- # yields an instance of each installed XML writer
- def self.each_installed_writer
- XMLRPC::XMLWriter::Classes.each do |klass|
- begin
- yield klass.new
- rescue LoadError
- end
- end
- end
-
- end # module XMLWriter
-
- # Creates XML-RPC call/response documents
- #
- class Create
-
- def initialize(xml_writer = nil)
- @writer = xml_writer || Config::DEFAULT_WRITER.new
- end
-
-
- def methodCall(name, *params)
- name = name.to_s
-
- if name !~ /[a-zA-Z0-9_.:\/]+/
- raise ArgumentError, "Wrong XML-RPC method-name"
- end
-
- parameter = params.collect do |param|
- @writer.ele("param", conv2value(param))
- end
-
- tree = @writer.document(
- @writer.pi("xml", 'version="1.0"'),
- @writer.ele("methodCall",
- @writer.tag("methodName", name),
- @writer.ele("params", *parameter)
- )
- )
-
- @writer.document_to_str(tree) + "\n"
- end
-
-
-
- #
- # Generates a XML-RPC methodResponse document
- #
- # When +is_ret+ is +false+ then the +params+ array must
- # contain only one element, which is a structure
- # of a fault return-value.
- #
- # When +is_ret+ is +true+ then a normal
- # return-value of all the given +params+ is created.
- #
- def methodResponse(is_ret, *params)
-
- if is_ret
- resp = params.collect do |param|
- @writer.ele("param", conv2value(param))
- end
-
- resp = [@writer.ele("params", *resp)]
- else
- if params.size != 1 or params[0] === XMLRPC::FaultException
- raise ArgumentError, "no valid fault-structure given"
- end
- resp = @writer.ele("fault", conv2value(params[0].to_h))
- end
-
-
- tree = @writer.document(
- @writer.pi("xml", 'version="1.0"'),
- @writer.ele("methodResponse", resp)
- )
-
- @writer.document_to_str(tree) + "\n"
- end
-
-
-
- private
-
- #
- # Converts a Ruby object into a XML-RPC <code><value></code> tag
- #
- def conv2value(param) # :doc:
-
- val = case param
- when Fixnum, Bignum
- # XML-RPC's int is 32bit int, and Fixnum also may be beyond 32bit
- if Config::ENABLE_BIGINT
- @writer.tag("i4", param.to_s)
- else
- if param >= -(2**31) and param <= (2**31-1)
- @writer.tag("i4", param.to_s)
- else
- raise "Bignum is too big! Must be signed 32-bit integer!"
- end
- end
- when TrueClass, FalseClass
- @writer.tag("boolean", param ? "1" : "0")
-
- when Symbol
- @writer.tag("string", param.to_s)
-
- when String
- @writer.tag("string", param)
-
- when NilClass
- if Config::ENABLE_NIL_CREATE
- @writer.ele("nil")
- else
- raise "Wrong type NilClass. Not allowed!"
- end
-
- when Float
- raise "Wrong value #{param}. Not allowed!" unless param.finite?
- @writer.tag("double", param.to_s)
-
- when Struct
- h = param.members.collect do |key|
- value = param[key]
- @writer.ele("member",
- @writer.tag("name", key.to_s),
- conv2value(value)
- )
- end
-
- @writer.ele("struct", *h)
-
- when Hash
- # TODO: can a Hash be empty?
-
- h = param.collect do |key, value|
- @writer.ele("member",
- @writer.tag("name", key.to_s),
- conv2value(value)
- )
- end
-
- @writer.ele("struct", *h)
-
- when Array
- # TODO: can an Array be empty?
- a = param.collect {|v| conv2value(v) }
-
- @writer.ele("array",
- @writer.ele("data", *a)
- )
-
- when Time, Date, ::DateTime
- @writer.tag("dateTime.iso8601", param.strftime("%Y%m%dT%H:%M:%S"))
-
- when XMLRPC::DateTime
- @writer.tag("dateTime.iso8601",
- format("%.4d%02d%02dT%02d:%02d:%02d", *param.to_a))
-
- when XMLRPC::Base64
- @writer.tag("base64", param.encoded)
-
- else
- if Config::ENABLE_MARSHALLING and param.class.included_modules.include? XMLRPC::Marshallable
- # convert Ruby object into Hash
- ret = {"___class___" => param.class.name}
- param.instance_variables.each {|v|
- name = v[1..-1]
- val = param.instance_variable_get(v)
-
- if val.nil?
- ret[name] = val if Config::ENABLE_NIL_CREATE
- else
- ret[name] = val
- end
- }
- return conv2value(ret)
- else
- ok, pa = wrong_type(param)
- if ok
- return conv2value(pa)
- else
- raise "Wrong type!"
- end
- end
- end
-
- @writer.ele("value", val)
- end
-
- def wrong_type(value)
- false
- end
-
-
- end # class Create
-
-end # module XMLRPC
-
diff --git a/ruby_2_2/lib/xmlrpc/datetime.rb b/ruby_2_2/lib/xmlrpc/datetime.rb
deleted file mode 100644
index 444a29f176..0000000000
--- a/ruby_2_2/lib/xmlrpc/datetime.rb
+++ /dev/null
@@ -1,129 +0,0 @@
-#
-# xmlrpc/datetime.rb
-# Copyright (C) 2001, 2002, 2003 by Michael Neumann (mneumann@ntecs.de)
-#
-# Released under the same term of license as Ruby.
-#
-require "date"
-
-module XMLRPC # :nodoc:
-
-# This class is important to handle XMLRPC +dateTime.iso8601+ values,
-# correctly, because normal UNIX-dates, ie: Date, only handle dates
-# from year 1970 on, and ruby's native Time class handles dates without the
-# time component.
-#
-# XMLRPC::DateTime is able to store a XMLRPC +dateTime.iso8601+ value correctly.
-class DateTime
-
- # Return the value of the specified date/time component.
- attr_reader :year, :month, :day, :hour, :min, :sec
-
- # Set +value+ as the new date/time component.
- #
- # Raises ArgumentError if the given +value+ is out of range, or in the case
- # of XMLRPC::DateTime#year= if +value+ is not of type Integer.
- def year= (value)
- raise ArgumentError, "date/time out of range" unless value.is_a? Integer
- @year = value
- end
-
- # Set +value+ as the new date/time component.
- #
- # Raises an ArgumentError if the given +value+ isn't between 1 and 12.
- def month= (value)
- raise ArgumentError, "date/time out of range" unless (1..12).include? value
- @month = value
- end
-
- # Set +value+ as the new date/time component.
- #
- # Raises an ArgumentError if the given +value+ isn't between 1 and 31.
- def day= (value)
- raise ArgumentError, "date/time out of range" unless (1..31).include? value
- @day = value
- end
-
- # Set +value+ as the new date/time component.
- #
- # Raises an ArgumentError if the given +value+ isn't between 0 and 24.
- def hour= (value)
- raise ArgumentError, "date/time out of range" unless (0..24).include? value
- @hour = value
- end
-
- # Set +value+ as the new date/time component.
- #
- # Raises an ArgumentError if the given +value+ isn't between 0 and 59.
- def min= (value)
- raise ArgumentError, "date/time out of range" unless (0..59).include? value
- @min = value
- end
-
- # Set +value+ as the new date/time component.
- #
- # Raises an ArgumentError if the given +value+ isn't between 0 and 59.
- def sec= (value)
- raise ArgumentError, "date/time out of range" unless (0..59).include? value
- @sec = value
- end
-
- # Alias for XMLRPC::DateTime#month.
- alias mon month
- # Alias for XMLRPC::DateTime#month=.
- alias mon= month=
-
-
- # Creates a new XMLRPC::DateTime instance with the
- # parameters +year+, +month+, +day+ as date and
- # +hour+, +min+, +sec+ as time.
- #
- # Raises an ArgumentError if a parameter is out of range,
- # or if +year+ is not of the Integer type.
- def initialize(year, month, day, hour, min, sec)
- self.year, self.month, self.day = year, month, day
- self.hour, self.min, self.sec = hour, min, sec
- end
-
- # Return a Time object of the date/time which represents +self+.
- # If the <code>@year</code> is below 1970, this method returns +nil+,
- # because Time cannot handle years below 1970.
- #
- # The timezone used is GMT.
- def to_time
- if @year >= 1970
- Time.gm(*to_a)
- else
- nil
- end
- end
-
- # Return a Date object of the date which represents +self+.
- #
- # The Date object do _not_ contain the time component (only date).
- def to_date
- Date.new(*to_a[0,3])
- end
-
- # Returns all date/time components in an array.
- #
- # Returns +[year, month, day, hour, min, sec]+.
- def to_a
- [@year, @month, @day, @hour, @min, @sec]
- end
-
- # Returns whether or not all date/time components are an array.
- def ==(o)
- self.to_a == Array(o) rescue false
- end
-
-end
-
-
-end # module XMLRPC
-
-
-=begin
-= History
- $Id$
-=end
diff --git a/ruby_2_2/lib/xmlrpc/marshal.rb b/ruby_2_2/lib/xmlrpc/marshal.rb
deleted file mode 100644
index ef1234f801..0000000000
--- a/ruby_2_2/lib/xmlrpc/marshal.rb
+++ /dev/null
@@ -1,66 +0,0 @@
-#
-# Copyright (C) 2001, 2002, 2003 by Michael Neumann (mneumann@ntecs.de)
-#
-# $Id$
-#
-
-require "xmlrpc/parser"
-require "xmlrpc/create"
-require "xmlrpc/config"
-require "xmlrpc/utils"
-
-module XMLRPC # :nodoc:
-
- # Marshalling of XMLRPC::Create#methodCall and XMLRPC::Create#methodResponse
- class Marshal
- include ParserWriterChooseMixin
-
- class << self
-
- def dump_call( methodName, *params )
- new.dump_call( methodName, *params )
- end
-
- def dump_response( param )
- new.dump_response( param )
- end
-
- def load_call( stringOrReadable )
- new.load_call( stringOrReadable )
- end
-
- def load_response( stringOrReadable )
- new.load_response( stringOrReadable )
- end
-
- alias dump dump_response
- alias load load_response
-
- end # class self
-
- def initialize( parser = nil, writer = nil )
- set_parser( parser )
- set_writer( writer )
- end
-
- def dump_call( methodName, *params )
- create.methodCall( methodName, *params )
- end
-
- def dump_response( param )
- create.methodResponse( ! param.kind_of?( XMLRPC::FaultException ) , param )
- end
-
- # Returns <code>[ methodname, params ]</code>
- def load_call( stringOrReadable )
- parser.parseMethodCall( stringOrReadable )
- end
-
- # Returns +paramOrFault+
- def load_response( stringOrReadable )
- parser.parseMethodResponse( stringOrReadable )[1]
- end
-
- end # class Marshal
-
-end
diff --git a/ruby_2_2/lib/xmlrpc/parser.rb b/ruby_2_2/lib/xmlrpc/parser.rb
deleted file mode 100644
index be8accfd6b..0000000000
--- a/ruby_2_2/lib/xmlrpc/parser.rb
+++ /dev/null
@@ -1,870 +0,0 @@
-# Copyright (C) 2001, 2002, 2003 by Michael Neumann (mneumann@ntecs.de)
-#
-# $Id$
-#
-
-
-require "date"
-require "xmlrpc/base64"
-require "xmlrpc/datetime"
-
-
-module NQXML
- class Node
-
- def removeChild(node)
- @children.delete(node)
- end
- def childNodes
- @children
- end
- def hasChildNodes
- not @children.empty?
- end
- def [] (index)
- @children[index]
- end
-
- def nodeType
- if @entity.instance_of? NQXML::Text then :TEXT
- elsif @entity.instance_of? NQXML::Comment then :COMMENT
- #elsif @entity.instance_of? NQXML::Element then :ELEMENT
- elsif @entity.instance_of? NQXML::Tag then :ELEMENT
- else :ELSE
- end
- end
-
- def nodeValue
- #TODO: error when wrong Entity-type
- @entity.text
- end
- def nodeName
- #TODO: error when wrong Entity-type
- @entity.name
- end
- end # class Node
-end # module NQXML
-
-module XMLRPC # :nodoc:
-
- # Raised when the remote procedure returns a fault-structure, which has two
- # accessor-methods +faultCode+ an Integer, and +faultString+ a String.
- class FaultException < StandardError
- attr_reader :faultCode, :faultString
-
- # Creates a new XMLRPC::FaultException instance.
- #
- # +faultString+ is passed to StandardError as the +msg+ of the Exception.
- def initialize(faultCode, faultString)
- @faultCode = faultCode
- @faultString = faultString
- super(@faultString)
- end
-
- # The +faultCode+ and +faultString+ of the exception in a Hash.
- def to_h
- {"faultCode" => @faultCode, "faultString" => @faultString}
- end
- end
-
- # Helper class used to convert types.
- module Convert
-
- # Converts a String to an Integer
- #
- # See also String.to_i
- def self.int(str)
- str.to_i
- end
-
- # Converts a String to +true+ or +false+
- #
- # Raises an exception if +str+ is not +0+ or +1+
- def self.boolean(str)
- case str
- when "0" then false
- when "1" then true
- else
- raise "RPC-value of type boolean is wrong"
- end
- end
-
- # Converts a String to a Float
- #
- # See also String.to_f
- def self.double(str)
- str.to_f
- end
-
- # Converts a the given +str+ to a +dateTime.iso8601+ formatted date.
- #
- # Raises an exception if the String isn't in +dateTime.iso8601+ format.
- #
- # See also, XMLRPC::DateTime
- def self.dateTime(str)
- case str
- when /^(-?\d\d\d\d)-?(\d\d)-?(\d\d)T(\d\d):(\d\d):(\d\d)(?:Z|([+-])(\d\d):?(\d\d))?$/
- a = [$1, $2, $3, $4, $5, $6].collect{|i| i.to_i}
- if $7
- ofs = $8.to_i*3600 + $9.to_i*60
- ofs = -ofs if $7=='+'
- utc = Time.utc(*a) + ofs
- a = [ utc.year, utc.month, utc.day, utc.hour, utc.min, utc.sec ]
- end
- XMLRPC::DateTime.new(*a)
- when /^(-?\d\d)-?(\d\d)-?(\d\d)T(\d\d):(\d\d):(\d\d)(Z|([+-]\d\d):(\d\d))?$/
- a = [$1, $2, $3, $4, $5, $6].collect{|i| i.to_i}
- if a[0] < 70
- a[0] += 2000
- else
- a[0] += 1900
- end
- if $7
- ofs = $8.to_i*3600 + $9.to_i*60
- ofs = -ofs if $7=='+'
- utc = Time.utc(*a) + ofs
- a = [ utc.year, utc.month, utc.day, utc.hour, utc.min, utc.sec ]
- end
- XMLRPC::DateTime.new(*a)
- else
- raise "wrong dateTime.iso8601 format " + str
- end
- end
-
- # Decodes the given +str+ using XMLRPC::Base64.decode
- def self.base64(str)
- XMLRPC::Base64.decode(str)
- end
-
- # Converts the given +hash+ to a marshalled object.
- #
- # Returns the given +hash+ if an exception occurs.
- def self.struct(hash)
- # convert to marshalled object
- klass = hash["___class___"]
- if klass.nil? or Config::ENABLE_MARSHALLING == false
- hash
- else
- begin
- mod = Module
- klass.split("::").each {|const| mod = mod.const_get(const.strip)}
-
- obj = mod.allocate
-
- hash.delete "___class___"
- hash.each {|key, value|
- obj.instance_variable_set("@#{ key }", value) if key =~ /^([a-zA-Z_]\w*)$/
- }
- obj
- rescue
- hash
- end
- end
- end
-
- # Converts the given +hash+ to an XMLRPC::FaultException object by passing
- # the +faultCode+ and +faultString+ attributes of the Hash to
- # XMLRPC::FaultException.new
- #
- # Raises an Exception if the given +hash+ doesn't meet the requirements.
- # Those requirements being:
- # * 2 keys
- # * <code>'faultCode'</code> key is an Integer
- # * <code>'faultString'</code> key is a String
- def self.fault(hash)
- if hash.kind_of? Hash and hash.size == 2 and
- hash.has_key? "faultCode" and hash.has_key? "faultString" and
- hash["faultCode"].kind_of? Integer and hash["faultString"].kind_of? String
-
- XMLRPC::FaultException.new(hash["faultCode"], hash["faultString"])
- else
- raise "wrong fault-structure: #{hash.inspect}"
- end
- end
-
- end # module Convert
-
- # Parser for XML-RPC call and response
- module XMLParser
-
- class AbstractTreeParser
-
- def parseMethodResponse(str)
- methodResponse_document(createCleanedTree(str))
- end
-
- def parseMethodCall(str)
- methodCall_document(createCleanedTree(str))
- end
-
- private
-
- # Removes all whitespaces but in the tags i4, i8, int, boolean....
- # and all comments
- def removeWhitespacesAndComments(node)
- remove = []
- childs = node.childNodes.to_a
- childs.each do |nd|
- case _nodeType(nd)
- when :TEXT
- # TODO: add nil?
- unless %w(i4 i8 int boolean string double dateTime.iso8601 base64).include? node.nodeName
-
- if node.nodeName == "value"
- if not node.childNodes.to_a.detect {|n| _nodeType(n) == :ELEMENT}.nil?
- remove << nd if nd.nodeValue.strip == ""
- end
- else
- remove << nd if nd.nodeValue.strip == ""
- end
- end
- when :COMMENT
- remove << nd
- else
- removeWhitespacesAndComments(nd)
- end
- end
-
- remove.each { |i| node.removeChild(i) }
- end
-
-
- def nodeMustBe(node, name)
- cmp = case name
- when Array
- name.include?(node.nodeName)
- when String
- name == node.nodeName
- else
- raise "error"
- end
-
- if not cmp then
- raise "wrong xml-rpc (name)"
- end
-
- node
- end
-
- # Returns, when successfully the only child-node
- def hasOnlyOneChild(node, name=nil)
- if node.childNodes.to_a.size != 1
- raise "wrong xml-rpc (size)"
- end
- if name != nil then
- nodeMustBe(node.firstChild, name)
- end
- end
-
-
- def assert(b)
- if not b then
- raise "assert-fail"
- end
- end
-
- # The node `node` has empty string or string
- def text_zero_one(node)
- nodes = node.childNodes.to_a.size
-
- if nodes == 1
- text(node.firstChild)
- elsif nodes == 0
- ""
- else
- raise "wrong xml-rpc (size)"
- end
- end
-
-
- def integer(node)
- #TODO: check string for float because to_i returnsa
- # 0 when wrong string
- nodeMustBe(node, %w(i4 i8 int))
- hasOnlyOneChild(node)
-
- Convert.int(text(node.firstChild))
- end
-
- def boolean(node)
- nodeMustBe(node, "boolean")
- hasOnlyOneChild(node)
-
- Convert.boolean(text(node.firstChild))
- end
-
- def v_nil(node)
- nodeMustBe(node, "nil")
- assert( node.childNodes.to_a.size == 0 )
- nil
- end
-
- def string(node)
- nodeMustBe(node, "string")
- text_zero_one(node)
- end
-
- def double(node)
- #TODO: check string for float because to_f returnsa
- # 0.0 when wrong string
- nodeMustBe(node, "double")
- hasOnlyOneChild(node)
-
- Convert.double(text(node.firstChild))
- end
-
- def dateTime(node)
- nodeMustBe(node, "dateTime.iso8601")
- hasOnlyOneChild(node)
-
- Convert.dateTime( text(node.firstChild) )
- end
-
- def base64(node)
- nodeMustBe(node, "base64")
- #hasOnlyOneChild(node)
-
- Convert.base64(text_zero_one(node))
- end
-
- def member(node)
- nodeMustBe(node, "member")
- assert( node.childNodes.to_a.size == 2 )
-
- [ name(node[0]), value(node[1]) ]
- end
-
- def name(node)
- nodeMustBe(node, "name")
- #hasOnlyOneChild(node)
- text_zero_one(node)
- end
-
- def array(node)
- nodeMustBe(node, "array")
- hasOnlyOneChild(node, "data")
- data(node.firstChild)
- end
-
- def data(node)
- nodeMustBe(node, "data")
-
- node.childNodes.to_a.collect do |val|
- value(val)
- end
- end
-
- def param(node)
- nodeMustBe(node, "param")
- hasOnlyOneChild(node, "value")
- value(node.firstChild)
- end
-
- def methodResponse(node)
- nodeMustBe(node, "methodResponse")
- hasOnlyOneChild(node, %w(params fault))
- child = node.firstChild
-
- case child.nodeName
- when "params"
- [ true, params(child,false) ]
- when "fault"
- [ false, fault(child) ]
- else
- raise "unexpected error"
- end
-
- end
-
- def methodName(node)
- nodeMustBe(node, "methodName")
- hasOnlyOneChild(node)
- text(node.firstChild)
- end
-
- def params(node, call=true)
- nodeMustBe(node, "params")
-
- if call
- node.childNodes.to_a.collect do |n|
- param(n)
- end
- else # response (only one param)
- hasOnlyOneChild(node)
- param(node.firstChild)
- end
- end
-
- def fault(node)
- nodeMustBe(node, "fault")
- hasOnlyOneChild(node, "value")
- f = value(node.firstChild)
- Convert.fault(f)
- end
-
-
-
- # _nodeType is defined in the subclass
- def text(node)
- assert( _nodeType(node) == :TEXT )
- assert( node.hasChildNodes == false )
- assert( node.nodeValue != nil )
-
- node.nodeValue.to_s
- end
-
- def struct(node)
- nodeMustBe(node, "struct")
-
- hash = {}
- node.childNodes.to_a.each do |me|
- n, v = member(me)
- hash[n] = v
- end
-
- Convert.struct(hash)
- end
-
-
- def value(node)
- nodeMustBe(node, "value")
- nodes = node.childNodes.to_a.size
- if nodes == 0
- return ""
- elsif nodes > 1
- raise "wrong xml-rpc (size)"
- end
-
- child = node.firstChild
-
- case _nodeType(child)
- when :TEXT
- text_zero_one(node)
- when :ELEMENT
- case child.nodeName
- when "i4", "i8", "int" then integer(child)
- when "boolean" then boolean(child)
- when "string" then string(child)
- when "double" then double(child)
- when "dateTime.iso8601" then dateTime(child)
- when "base64" then base64(child)
- when "struct" then struct(child)
- when "array" then array(child)
- when "nil"
- if Config::ENABLE_NIL_PARSER
- v_nil(child)
- else
- raise "wrong/unknown XML-RPC type 'nil'"
- end
- else
- raise "wrong/unknown XML-RPC type"
- end
- else
- raise "wrong type of node"
- end
-
- end
-
- def methodCall(node)
- nodeMustBe(node, "methodCall")
- assert( (1..2).include?( node.childNodes.to_a.size ) )
- name = methodName(node[0])
-
- if node.childNodes.to_a.size == 2 then
- pa = params(node[1])
- else # no parameters given
- pa = []
- end
- [name, pa]
- end
-
- end # module TreeParserMixin
-
- class AbstractStreamParser
- def parseMethodResponse(str)
- parser = @parser_class.new
- parser.parse(str)
- raise "No valid method response!" if parser.method_name != nil
- if parser.fault != nil
- # is a fault structure
- [false, parser.fault]
- else
- # is a normal return value
- raise "Missing return value!" if parser.params.size == 0
- raise "Too many return values. Only one allowed!" if parser.params.size > 1
- [true, parser.params[0]]
- end
- end
-
- def parseMethodCall(str)
- parser = @parser_class.new
- parser.parse(str)
- raise "No valid method call - missing method name!" if parser.method_name.nil?
- [parser.method_name, parser.params]
- end
- end
-
- module StreamParserMixin
- attr_reader :params
- attr_reader :method_name
- attr_reader :fault
-
- def initialize(*a)
- super(*a)
- @params = []
- @values = []
- @val_stack = []
-
- @names = []
- @name = []
-
- @structs = []
- @struct = {}
-
- @method_name = nil
- @fault = nil
-
- @data = nil
- end
-
- def startElement(name, attrs=[])
- @data = nil
- case name
- when "value"
- @value = nil
- when "nil"
- raise "wrong/unknown XML-RPC type 'nil'" unless Config::ENABLE_NIL_PARSER
- @value = :nil
- when "array"
- @val_stack << @values
- @values = []
- when "struct"
- @names << @name
- @name = []
-
- @structs << @struct
- @struct = {}
- end
- end
-
- def endElement(name)
- @data ||= ""
- case name
- when "string"
- @value = @data
- when "i4", "i8", "int"
- @value = Convert.int(@data)
- when "boolean"
- @value = Convert.boolean(@data)
- when "double"
- @value = Convert.double(@data)
- when "dateTime.iso8601"
- @value = Convert.dateTime(@data)
- when "base64"
- @value = Convert.base64(@data)
- when "value"
- @value = @data if @value.nil?
- @values << (@value == :nil ? nil : @value)
- when "array"
- @value = @values
- @values = @val_stack.pop
- when "struct"
- @value = Convert.struct(@struct)
-
- @name = @names.pop
- @struct = @structs.pop
- when "name"
- @name[0] = @data
- when "member"
- @struct[@name[0]] = @values.pop
-
- when "param"
- @params << @values[0]
- @values = []
-
- when "fault"
- @fault = Convert.fault(@values[0])
-
- when "methodName"
- @method_name = @data
- end
-
- @data = nil
- end
-
- def character(data)
- if @data
- @data << data
- else
- @data = data
- end
- end
-
- end # module StreamParserMixin
-
- class XMLStreamParser < AbstractStreamParser
- def initialize
- require "xmlparser"
- @parser_class = Class.new(::XMLParser) {
- include StreamParserMixin
- }
- end
- end # class XMLStreamParser
-
- class NQXMLStreamParser < AbstractStreamParser
- def initialize
- require "nqxml/streamingparser"
- @parser_class = XMLRPCParser
- end
-
- class XMLRPCParser
- include StreamParserMixin
-
- def parse(str)
- parser = NQXML::StreamingParser.new(str)
- parser.each do |ele|
- case ele
- when NQXML::Text
- @data = ele.text
- #character(ele.text)
- when NQXML::Tag
- if ele.isTagEnd
- endElement(ele.name)
- else
- startElement(ele.name, ele.attrs)
- end
- end
- end # do
- end # method parse
- end # class XMLRPCParser
-
- end # class NQXMLStreamParser
-
- class XMLTreeParser < AbstractTreeParser
-
- def initialize
- require "xmltreebuilder"
-
- # The new XMLParser library (0.6.2+) uses a slightly different DOM implementation.
- # The following code removes the differences between both versions.
- if defined? XML::DOM::Builder
- return if defined? XML::DOM::Node::DOCUMENT # code below has been already executed
- klass = XML::DOM::Node
- klass.const_set(:DOCUMENT, klass::DOCUMENT_NODE)
- klass.const_set(:TEXT, klass::TEXT_NODE)
- klass.const_set(:COMMENT, klass::COMMENT_NODE)
- klass.const_set(:ELEMENT, klass::ELEMENT_NODE)
- end
- end
-
- private
-
- def _nodeType(node)
- tp = node.nodeType
- if tp == XML::SimpleTree::Node::TEXT then :TEXT
- elsif tp == XML::SimpleTree::Node::COMMENT then :COMMENT
- elsif tp == XML::SimpleTree::Node::ELEMENT then :ELEMENT
- else :ELSE
- end
- end
-
-
- def methodResponse_document(node)
- assert( node.nodeType == XML::SimpleTree::Node::DOCUMENT )
- hasOnlyOneChild(node, "methodResponse")
-
- methodResponse(node.firstChild)
- end
-
- def methodCall_document(node)
- assert( node.nodeType == XML::SimpleTree::Node::DOCUMENT )
- hasOnlyOneChild(node, "methodCall")
-
- methodCall(node.firstChild)
- end
-
- def createCleanedTree(str)
- doc = XML::SimpleTreeBuilder.new.parse(str)
- doc.documentElement.normalize
- removeWhitespacesAndComments(doc)
- doc
- end
-
- end # class XMLParser
-
- class NQXMLTreeParser < AbstractTreeParser
-
- def initialize
- require "nqxml/treeparser"
- end
-
- private
-
- def _nodeType(node)
- node.nodeType
- end
-
- def methodResponse_document(node)
- methodResponse(node)
- end
-
- def methodCall_document(node)
- methodCall(node)
- end
-
- def createCleanedTree(str)
- doc = ::NQXML::TreeParser.new(str).document.rootNode
- removeWhitespacesAndComments(doc)
- doc
- end
-
- end # class NQXMLTreeParser
-
- class REXMLStreamParser < AbstractStreamParser
- def initialize
- require "rexml/document"
- @parser_class = StreamListener
- end
-
- class StreamListener
- include StreamParserMixin
-
- alias :tag_start :startElement
- alias :tag_end :endElement
- alias :text :character
- alias :cdata :character
-
- def method_missing(*a)
- # ignore
- end
-
- def parse(str)
- REXML::Document.parse_stream(str, self)
- end
- end
-
- end
-
- class XMLScanStreamParser < AbstractStreamParser
- def initialize
- require "xmlscan/parser"
- @parser_class = XMLScanParser
- end
-
- class XMLScanParser
- include StreamParserMixin
-
- Entities = {
- "lt" => "<",
- "gt" => ">",
- "amp" => "&",
- "quot" => '"',
- "apos" => "'"
- }
-
- def parse(str)
- parser = XMLScan::XMLParser.new(self)
- parser.parse(str)
- end
-
- alias :on_stag :startElement
- alias :on_etag :endElement
-
- def on_stag_end(name); end
-
- def on_stag_end_empty(name)
- startElement(name)
- endElement(name)
- end
-
- def on_chardata(str)
- character(str)
- end
-
- def on_cdata(str)
- character(str)
- end
-
- def on_entityref(ent)
- str = Entities[ent]
- if str
- character(str)
- else
- raise "unknown entity"
- end
- end
-
- def on_charref(code)
- character(code.chr)
- end
-
- def on_charref_hex(code)
- character(code.chr)
- end
-
- def method_missing(*a)
- end
-
- # TODO: call/implement?
- # valid_name?
- # valid_chardata?
- # valid_char?
- # parse_error
-
- end
- end
-
- class LibXMLStreamParser < AbstractStreamParser
- def initialize
- require 'libxml'
- @parser_class = LibXMLStreamListener
- end
-
- class LibXMLStreamListener
- include StreamParserMixin
-
- def on_start_element_ns(name, attributes, prefix, uri, namespaces)
- startElement(name)
- end
-
- def on_end_element_ns(name, prefix, uri)
- endElement(name)
- end
-
- alias :on_characters :character
- alias :on_cdata_block :character
-
- def method_missing(*a)
- end
-
- def parse(str)
- parser = LibXML::XML::SaxParser.string(str)
- parser.callbacks = self
- parser.parse()
- end
- end
- end
-
- XMLParser = XMLTreeParser
- NQXMLParser = NQXMLTreeParser
-
- Classes = [XMLStreamParser, XMLTreeParser,
- NQXMLStreamParser, NQXMLTreeParser,
- REXMLStreamParser, XMLScanStreamParser,
- LibXMLStreamParser]
-
- # yields an instance of each installed parser
- def self.each_installed_parser
- XMLRPC::XMLParser::Classes.each do |klass|
- begin
- yield klass.new
- rescue LoadError
- end
- end
- end
-
- end # module XMLParser
-
-
-end # module XMLRPC
-
diff --git a/ruby_2_2/lib/xmlrpc/server.rb b/ruby_2_2/lib/xmlrpc/server.rb
deleted file mode 100644
index 64856ea1fa..0000000000
--- a/ruby_2_2/lib/xmlrpc/server.rb
+++ /dev/null
@@ -1,707 +0,0 @@
-# xmlrpc/server.rb
-# Copyright (C) 2001, 2002, 2003, 2005 by Michael Neumann (mneumann@ntecs.de)
-#
-# Released under the same term of license as Ruby.
-
-require "xmlrpc/parser"
-require "xmlrpc/create"
-require "xmlrpc/config"
-require "xmlrpc/utils" # ParserWriterChooseMixin
-
-
-
-module XMLRPC # :nodoc:
-
-
-# This is the base class for all XML-RPC server-types (CGI, standalone).
-# You can add handler and set a default handler.
-# Do not use this server, as this is/should be an abstract class.
-#
-# === How the method to call is found
-# The arity (number of accepted arguments) of a handler (method or Proc
-# object) is compared to the given arguments submitted by the client for a
-# RPC, or Remote Procedure Call.
-#
-# A handler is only called if it accepts the number of arguments, otherwise
-# the search for another handler will go on. When at the end no handler was
-# found, the default_handler, XMLRPC::BasicServer#set_default_handler will be
-# called.
-#
-# With this technique it is possible to do overloading by number of parameters, but
-# only for Proc handler, because you cannot define two methods of the same name in
-# the same class.
-class BasicServer
-
- include ParserWriterChooseMixin
- include ParseContentType
-
- ERR_METHOD_MISSING = 1
- ERR_UNCAUGHT_EXCEPTION = 2
- ERR_MC_WRONG_PARAM = 3
- ERR_MC_MISSING_PARAMS = 4
- ERR_MC_MISSING_METHNAME = 5
- ERR_MC_RECURSIVE_CALL = 6
- ERR_MC_WRONG_PARAM_PARAMS = 7
- ERR_MC_EXPECTED_STRUCT = 8
-
-
- # Creates a new XMLRPC::BasicServer instance, which should not be
- # done, because XMLRPC::BasicServer is an abstract class. This
- # method should be called from a subclass indirectly by a +super+ call
- # in the initialize method.
- #
- # The parameter +class_delim+ is used by add_handler, see
- # XMLRPC::BasicServer#add_handler, when an object is added as a handler, to
- # delimit the object-prefix and the method-name.
- def initialize(class_delim=".")
- @handler = []
- @default_handler = nil
- @service_hook = nil
-
- @class_delim = class_delim
- @create = nil
- @parser = nil
-
- add_multicall if Config::ENABLE_MULTICALL
- add_introspection if Config::ENABLE_INTROSPECTION
- end
-
- # Adds +aBlock+ to the list of handlers, with +name+ as the name of
- # the method.
- #
- # Parameters +signature+ and +help+ are used by the Introspection method if
- # specified, where +signature+ is either an Array containing strings each
- # representing a type of it's signature (the first is the return value) or
- # an Array of Arrays if the method has multiple signatures.
- #
- # Value type-names are "int, boolean, double, string, dateTime.iso8601,
- # base64, array, struct".
- #
- # Parameter +help+ is a String with information about how to call this method etc.
- #
- # When a method fails, it can tell the client by throwing an
- # XMLRPC::FaultException like in this example:
- #
- # s.add_handler("michael.div") do |a,b|
- # if b == 0
- # raise XMLRPC::FaultException.new(1, "division by zero")
- # else
- # a / b
- # end
- # end
- #
- # In the case of <code>b==0</code> the client gets an object back of type
- # XMLRPC::FaultException that has a +faultCode+ and +faultString+ field.
- #
- # This is the second form of ((<add_handler|XMLRPC::BasicServer#add_handler>)).
- # To add an object write:
- #
- # server.add_handler("michael", MyHandlerClass.new)
- #
- # All public methods of MyHandlerClass are accessible to
- # the XML-RPC clients by <code>michael."name of method"</code>. This is
- # where the +class_delim+ in XMLRPC::BasicServer.new plays it's role, a
- # XML-RPC method-name is defined by +prefix+ + +class_delim+ + <code>"name
- # of method"</code>.
- #
- # The third form of +add_handler is to use XMLRPC::Service::Interface to
- # generate an object, which represents an interface (with signature and
- # help text) for a handler class.
- #
- # The +interface+ parameter must be an instance of XMLRPC::Service::Interface.
- # Adds all methods of +obj+ which are defined in the +interface+ to the server.
- #
- # This is the recommended way of adding services to a server!
- def add_handler(prefix, obj_or_signature=nil, help=nil, &block)
- if block_given?
- # proc-handler
- @handler << [prefix, block, obj_or_signature, help]
- else
- if prefix.kind_of? String
- # class-handler
- raise ArgumentError, "Expected non-nil value" if obj_or_signature.nil?
- @handler << [prefix + @class_delim, obj_or_signature]
- elsif prefix.kind_of? XMLRPC::Service::BasicInterface
- # class-handler with interface
- # add all methods
- @handler += prefix.get_methods(obj_or_signature, @class_delim)
- else
- raise ArgumentError, "Wrong type for parameter 'prefix'"
- end
- end
- self
- end
-
- # Returns the service-hook, which is called on each service request (RPC)
- # unless it's +nil+.
- def get_service_hook
- @service_hook
- end
-
- # A service-hook is called for each service request (RPC).
- #
- # You can use a service-hook for example to wrap existing methods and catch
- # exceptions of them or convert values to values recognized by XMLRPC.
- #
- # You can disable it by passing +nil+ as the +handler+ parameter.
- #
- # The service-hook is called with a Proc object along with any parameters.
- #
- # An example:
- #
- # server.set_service_hook {|obj, *args|
- # begin
- # ret = obj.call(*args) # call the original service-method
- # # could convert the return value
- # rescue
- # # rescue exceptions
- # end
- # }
- #
- def set_service_hook(&handler)
- @service_hook = handler
- self
- end
-
- # Returns the default-handler, which is called when no handler for
- # a method-name is found.
- #
- # It is either a Proc object or +nil+.
- def get_default_handler
- @default_handler
- end
-
- # Sets +handler+ as the default-handler, which is called when
- # no handler for a method-name is found.
- #
- # +handler+ is a code-block.
- #
- # The default-handler is called with the (XML-RPC) method-name as first
- # argument, and the other arguments are the parameters given by the
- # client-call.
- #
- # If no block is specified the default of XMLRPC::BasicServer is
- # used, which raises a XMLRPC::FaultException saying "method missing".
- def set_default_handler(&handler)
- @default_handler = handler
- self
- end
-
- # Adds the multi-call handler <code>"system.multicall"</code>.
- def add_multicall
- add_handler("system.multicall", %w(array array), "Multicall Extension") do |arrStructs|
- unless arrStructs.is_a? Array
- raise XMLRPC::FaultException.new(ERR_MC_WRONG_PARAM, "system.multicall expects an array")
- end
-
- arrStructs.collect {|call|
- if call.is_a? Hash
- methodName = call["methodName"]
- params = call["params"]
-
- if params.nil?
- multicall_fault(ERR_MC_MISSING_PARAMS, "Missing params")
- elsif methodName.nil?
- multicall_fault(ERR_MC_MISSING_METHNAME, "Missing methodName")
- else
- if methodName == "system.multicall"
- multicall_fault(ERR_MC_RECURSIVE_CALL, "Recursive system.multicall forbidden")
- else
- unless params.is_a? Array
- multicall_fault(ERR_MC_WRONG_PARAM_PARAMS, "Parameter params have to be an Array")
- else
- ok, val = call_method(methodName, *params)
- if ok
- # correct return value
- [val]
- else
- # exception
- multicall_fault(val.faultCode, val.faultString)
- end
- end
- end
- end
-
- else
- multicall_fault(ERR_MC_EXPECTED_STRUCT, "system.multicall expected struct")
- end
- }
- end # end add_handler
- self
- end
-
- # Adds the introspection handlers <code>"system.listMethods"</code>,
- # <code>"system.methodSignature"</code> and
- # <code>"system.methodHelp"</code>, where only the first one works.
- def add_introspection
- add_handler("system.listMethods",%w(array), "List methods available on this XML-RPC server") do
- methods = []
- @handler.each do |name, obj|
- if obj.kind_of? Proc
- methods << name
- else
- obj.class.public_instance_methods(false).each do |meth|
- methods << "#{name}#{meth}"
- end
- end
- end
- methods
- end
-
- add_handler("system.methodSignature", %w(array string), "Returns method signature") do |meth|
- sigs = []
- @handler.each do |name, obj, sig|
- if obj.kind_of? Proc and sig != nil and name == meth
- if sig[0].kind_of? Array
- # sig contains multiple signatures, e.g. [["array"], ["array", "string"]]
- sig.each {|s| sigs << s}
- else
- # sig is a single signature, e.g. ["array"]
- sigs << sig
- end
- end
- end
- sigs.uniq! || sigs # remove eventually duplicated signatures
- end
-
- add_handler("system.methodHelp", %w(string string), "Returns help on using this method") do |meth|
- help = nil
- @handler.each do |name, obj, sig, hlp|
- if obj.kind_of? Proc and name == meth
- help = hlp
- break
- end
- end
- help || ""
- end
-
- self
- end
-
-
-
- def process(data)
- method, params = parser().parseMethodCall(data)
- handle(method, *params)
- end
-
- private
-
- def multicall_fault(nr, str)
- {"faultCode" => nr, "faultString" => str}
- end
-
- def dispatch(methodname, *args)
- for name, obj in @handler
- if obj.kind_of? Proc
- next unless methodname == name
- else
- next unless methodname =~ /^#{name}(.+)$/
- next unless obj.respond_to? $1
- obj = obj.method($1)
- end
-
- if check_arity(obj, args.size)
- if @service_hook.nil?
- return obj.call(*args)
- else
- return @service_hook.call(obj, *args)
- end
- end
- end
-
- if @default_handler.nil?
- raise XMLRPC::FaultException.new(ERR_METHOD_MISSING, "Method #{methodname} missing or wrong number of parameters!")
- else
- @default_handler.call(methodname, *args)
- end
- end
-
-
- # Returns +true+, if the arity of +obj+ matches +n_args+
- def check_arity(obj, n_args)
- ary = obj.arity
-
- if ary >= 0
- n_args == ary
- else
- n_args >= (ary+1).abs
- end
- end
-
-
-
- def call_method(methodname, *args)
- begin
- [true, dispatch(methodname, *args)]
- rescue XMLRPC::FaultException => e
- [false, e]
- rescue Exception => e
- [false, XMLRPC::FaultException.new(ERR_UNCAUGHT_EXCEPTION, "Uncaught exception #{e.message} in method #{methodname}")]
- end
- end
-
- def handle(methodname, *args)
- create().methodResponse(*call_method(methodname, *args))
- end
-
-
-end
-
-
-# Implements a CGI-based XML-RPC server.
-#
-# require "xmlrpc/server"
-#
-# s = XMLRPC::CGIServer.new
-#
-# s.add_handler("michael.add") do |a,b|
-# a + b
-# end
-#
-# s.add_handler("michael.div") do |a,b|
-# if b == 0
-# raise XMLRPC::FaultException.new(1, "division by zero")
-# else
-# a / b
-# end
-# end
-#
-# s.set_default_handler do |name, *args|
-# raise XMLRPC::FaultException.new(-99, "Method #{name} missing" +
-# " or wrong number of parameters!")
-# end
-#
-# s.serve
-#
-#
-# <b>Note:</b> Make sure that you don't write to standard-output in a
-# handler, or in any other part of your program, this would cause a CGI-based
-# server to fail!
-class CGIServer < BasicServer
- @@obj = nil
-
- # Creates a new XMLRPC::CGIServer instance.
- #
- # All parameters given are by-passed to XMLRPC::BasicServer.new.
- #
- # You can only create <b>one</b> XMLRPC::CGIServer instance, because more
- # than one makes no sense.
- def CGIServer.new(*a)
- @@obj = super(*a) if @@obj.nil?
- @@obj
- end
-
- def initialize(*a)
- super(*a)
- end
-
- # Call this after you have added all you handlers to the server.
- #
- # This method processes a XML-RPC method call and sends the answer
- # back to the client.
- def serve
- catch(:exit_serve) {
- length = ENV['CONTENT_LENGTH'].to_i
-
- http_error(405, "Method Not Allowed") unless ENV['REQUEST_METHOD'] == "POST"
- http_error(400, "Bad Request") unless parse_content_type(ENV['CONTENT_TYPE']).first == "text/xml"
- http_error(411, "Length Required") unless length > 0
-
- # TODO: do we need a call to binmode?
- $stdin.binmode if $stdin.respond_to? :binmode
- data = $stdin.read(length)
-
- http_error(400, "Bad Request") if data.nil? or data.bytesize != length
-
- http_write(process(data), "Content-type" => "text/xml; charset=utf-8")
- }
- end
-
-
- private
-
- def http_error(status, message)
- err = "#{status} #{message}"
- msg = <<-"MSGEND"
- <html>
- <head>
- <title>#{err}</title>
- </head>
- <body>
- <h1>#{err}</h1>
- <p>Unexpected error occurred while processing XML-RPC request!</p>
- </body>
- </html>
- MSGEND
-
- http_write(msg, "Status" => err, "Content-type" => "text/html")
- throw :exit_serve # exit from the #serve method
- end
-
- def http_write(body, header)
- h = {}
- header.each {|key, value| h[key.to_s.capitalize] = value}
- h['Status'] ||= "200 OK"
- h['Content-length'] ||= body.bytesize.to_s
-
- str = ""
- h.each {|key, value| str << "#{key}: #{value}\r\n"}
- str << "\r\n#{body}"
-
- print str
- end
-
-end
-
-
-# Implements a XML-RPC server, which works with Apache mod_ruby.
-#
-# Use it in the same way as XMLRPC::CGIServer!
-class ModRubyServer < BasicServer
-
- # Creates a new XMLRPC::ModRubyServer instance.
- #
- # All parameters given are by-passed to XMLRPC::BasicServer.new.
- def initialize(*a)
- @ap = Apache::request
- super(*a)
- end
-
- # Call this after you have added all you handlers to the server.
- #
- # This method processes a XML-RPC method call and sends the answer
- # back to the client.
- def serve
- catch(:exit_serve) {
- header = {}
- @ap.headers_in.each {|key, value| header[key.capitalize] = value}
-
- length = header['Content-length'].to_i
-
- http_error(405, "Method Not Allowed") unless @ap.request_method == "POST"
- http_error(400, "Bad Request") unless parse_content_type(header['Content-type']).first == "text/xml"
- http_error(411, "Length Required") unless length > 0
-
- # TODO: do we need a call to binmode?
- @ap.binmode
- data = @ap.read(length)
-
- http_error(400, "Bad Request") if data.nil? or data.bytesize != length
-
- http_write(process(data), 200, "Content-type" => "text/xml; charset=utf-8")
- }
- end
-
-
- private
-
- def http_error(status, message)
- err = "#{status} #{message}"
- msg = <<-"MSGEND"
- <html>
- <head>
- <title>#{err}</title>
- </head>
- <body>
- <h1>#{err}</h1>
- <p>Unexpected error occurred while processing XML-RPC request!</p>
- </body>
- </html>
- MSGEND
-
- http_write(msg, status, "Status" => err, "Content-type" => "text/html")
- throw :exit_serve # exit from the #serve method
- end
-
- def http_write(body, status, header)
- h = {}
- header.each {|key, value| h[key.to_s.capitalize] = value}
- h['Status'] ||= "200 OK"
- h['Content-length'] ||= body.bytesize.to_s
-
- h.each {|key, value| @ap.headers_out[key] = value }
- @ap.content_type = h["Content-type"]
- @ap.status = status.to_i
- @ap.send_http_header
-
- @ap.print body
- end
-
-end
-
-
-class WEBrickServlet < BasicServer; end # forward declaration
-
-# Implements a standalone XML-RPC server. The method XMLRPC::Server#serve is
-# left if a SIGHUP is sent to the program.
-#
-# require "xmlrpc/server"
-#
-# s = XMLRPC::Server.new(8080)
-#
-# s.add_handler("michael.add") do |a,b|
-# a + b
-# end
-#
-# s.add_handler("michael.div") do |a,b|
-# if b == 0
-# raise XMLRPC::FaultException.new(1, "division by zero")
-# else
-# a / b
-# end
-# end
-#
-# s.set_default_handler do |name, *args|
-# raise XMLRPC::FaultException.new(-99, "Method #{name} missing" +
-# " or wrong number of parameters!")
-# end
-#
-# s.serve
-class Server < WEBrickServlet
-
- # Creates a new XMLRPC::Server instance, which is a XML-RPC server
- # listening on the given +port+ and accepts requests for the given +host+,
- # which is +localhost+ by default.
- #
- # The server is not started, to start it you have to call
- # XMLRPC::Server#serve.
- #
- # The optional +audit+ and +debug+ parameters are obsolete!
- #
- # All additionally provided parameters in <code>*a</code> are by-passed to
- # XMLRPC::BasicServer.new.
- def initialize(port=8080, host="127.0.0.1", maxConnections=4, stdlog=$stdout, audit=true, debug=true, *a)
- super(*a)
- require 'webrick'
- @server = WEBrick::HTTPServer.new(:Port => port, :BindAddress => host, :MaxClients => maxConnections,
- :Logger => WEBrick::Log.new(stdlog))
- @server.mount("/", self)
- end
-
- # Call this after you have added all you handlers to the server.
- # This method starts the server to listen for XML-RPC requests and answer them.
- def serve
- signals = %w[INT TERM HUP] & Signal.list.keys
- signals.each { |signal| trap(signal) { @server.shutdown } }
-
- @server.start
- end
-
- # Stops and shuts the server down.
- def shutdown
- @server.shutdown
- end
-
-end
-
-
-# Implements a servlet for use with WEBrick, a pure Ruby (HTTP) server
-# framework.
-#
-# require "webrick"
-# require "xmlrpc/server"
-#
-# s = XMLRPC::WEBrickServlet.new
-# s.add_handler("michael.add") do |a,b|
-# a + b
-# end
-#
-# s.add_handler("michael.div") do |a,b|
-# if b == 0
-# raise XMLRPC::FaultException.new(1, "division by zero")
-# else
-# a / b
-# end
-# end
-#
-# s.set_default_handler do |name, *args|
-# raise XMLRPC::FaultException.new(-99, "Method #{name} missing" +
-# " or wrong number of parameters!")
-# end
-#
-# httpserver = WEBrick::HTTPServer.new(:Port => 8080)
-# httpserver.mount("/RPC2", s)
-# trap("HUP") { httpserver.shutdown } # use 1 instead of "HUP" on Windows
-# httpserver.start
-class WEBrickServlet < BasicServer
- def initialize(*a)
- super
- require "webrick/httpstatus"
- @valid_ip = nil
- end
-
- # Deprecated from WEBrick/1.2.2, but does not break anything.
- def require_path_info?
- false
- end
-
- def get_instance(config, *options)
- # TODO: set config & options
- self
- end
-
- # Specifies the valid IP addresses that are allowed to connect to the server.
- #
- # Each IP is either a String or a Regexp.
- def set_valid_ip(*ip_addr)
- if ip_addr.size == 1 and ip_addr[0].nil?
- @valid_ip = nil
- else
- @valid_ip = ip_addr
- end
- end
-
- # Return the valid IP addresses that are allowed to connect to the server.
- #
- # See also, XMLRPC::Server#set_valid_ip
- def get_valid_ip
- @valid_ip
- end
-
- def service(request, response)
-
- if @valid_ip
- raise WEBrick::HTTPStatus::Forbidden unless @valid_ip.any? { |ip| request.peeraddr[3] =~ ip }
- end
-
- if request.request_method != "POST"
- raise WEBrick::HTTPStatus::MethodNotAllowed,
- "unsupported method `#{request.request_method}'."
- end
-
- if parse_content_type(request['Content-type']).first != "text/xml"
- raise WEBrick::HTTPStatus::BadRequest
- end
-
- length = (request['Content-length'] || 0).to_i
-
- raise WEBrick::HTTPStatus::LengthRequired unless length > 0
-
- data = request.body
-
- if data.nil? or data.bytesize != length
- raise WEBrick::HTTPStatus::BadRequest
- end
-
- resp = process(data)
- if resp.nil? or resp.bytesize <= 0
- raise WEBrick::HTTPStatus::InternalServerError
- end
-
- response.status = 200
- response['Content-Length'] = resp.bytesize
- response['Content-Type'] = "text/xml; charset=utf-8"
- response.body = resp
- end
-end
-
-
-end # module XMLRPC
-
-
-=begin
-= History
- $Id$
-=end
-
diff --git a/ruby_2_2/lib/xmlrpc/utils.rb b/ruby_2_2/lib/xmlrpc/utils.rb
deleted file mode 100644
index 186938a56e..0000000000
--- a/ruby_2_2/lib/xmlrpc/utils.rb
+++ /dev/null
@@ -1,171 +0,0 @@
-#
-# Copyright (C) 2001, 2002, 2003 by Michael Neumann (mneumann@ntecs.de)
-#
-# $Id$
-#
-module XMLRPC # :nodoc:
-
-
- # This module enables a user-class to be marshalled
- # by XML-RPC for Ruby into a Hash, with one additional
- # key/value pair <code>___class___ => ClassName</code>
- #
- module Marshallable
- end
-
-
- # Defines ParserWriterChooseMixin, which makes it possible to choose a
- # different XMLWriter and/or XMLParser then the default one.
- #
- # The Mixin is used in client.rb (class XMLRPC::Client)
- # and server.rb (class XMLRPC::BasicServer)
- module ParserWriterChooseMixin
-
- # Sets the XMLWriter to use for generating XML output.
- #
- # Should be an instance of a class from module XMLRPC::XMLWriter.
- #
- # If this method is not called, then XMLRPC::Config::DEFAULT_WRITER is used.
- def set_writer(writer)
- @create = Create.new(writer)
- self
- end
-
- # Sets the XMLParser to use for parsing XML documents.
- #
- # Should be an instance of a class from module XMLRPC::XMLParser.
- #
- # If this method is not called, then XMLRPC::Config::DEFAULT_PARSER is used.
- def set_parser(parser)
- @parser = parser
- self
- end
-
- private
-
- def create
- # if set_writer was not already called then call it now
- if @create.nil? then
- set_writer(Config::DEFAULT_WRITER.new)
- end
- @create
- end
-
- def parser
- # if set_parser was not already called then call it now
- if @parser.nil? then
- set_parser(Config::DEFAULT_PARSER.new)
- end
- @parser
- end
-
- end # module ParserWriterChooseMixin
-
-
- module Service
-
- # Base class for XMLRPC::Service::Interface definitions, used
- # by XMLRPC::BasicServer#add_handler
- class BasicInterface
- attr_reader :prefix, :methods
-
- def initialize(prefix)
- @prefix = prefix
- @methods = []
- end
-
- def add_method(sig, help=nil, meth_name=nil)
- mname = nil
- sig = [sig] if sig.kind_of? String
-
- sig = sig.collect do |s|
- name, si = parse_sig(s)
- raise "Wrong signatures!" if mname != nil and name != mname
- mname = name
- si
- end
-
- @methods << [mname, meth_name || mname, sig, help]
- end
-
- private
-
- def parse_sig(sig)
- # sig is a String
- if sig =~ /^\s*(\w+)\s+([^(]+)(\(([^)]*)\))?\s*$/
- params = [$1]
- name = $2.strip
- $4.split(",").each {|i| params << i.strip} if $4 != nil
- return name, params
- else
- raise "Syntax error in signature"
- end
- end
-
- end # class BasicInterface
-
- #
- # Class which wraps a XMLRPC::Service::Interface definition, used
- # by XMLRPC::BasicServer#add_handler
- #
- class Interface < BasicInterface
- def initialize(prefix, &p)
- raise "No interface specified" if p.nil?
- super(prefix)
- instance_eval(&p)
- end
-
- def get_methods(obj, delim=".")
- prefix = @prefix + delim
- @methods.collect { |name, meth, sig, help|
- [prefix + name.to_s, obj.method(meth).to_proc, sig, help]
- }
- end
-
- private
-
- def meth(*a)
- add_method(*a)
- end
-
- end # class Interface
-
- class PublicInstanceMethodsInterface < BasicInterface
- def initialize(prefix)
- super(prefix)
- end
-
- def get_methods(obj, delim=".")
- prefix = @prefix + delim
- obj.class.public_instance_methods(false).collect { |name|
- [prefix + name.to_s, obj.method(name).to_proc, nil, nil]
- }
- end
- end
-
-
- end # module Service
-
-
- #
- # Short-form to create a XMLRPC::Service::Interface
- #
- def self.interface(prefix, &p)
- Service::Interface.new(prefix, &p)
- end
-
- # Short-cut for creating a XMLRPC::Service::PublicInstanceMethodsInterface
- def self.iPIMethods(prefix)
- Service::PublicInstanceMethodsInterface.new(prefix)
- end
-
-
- module ParseContentType
- def parse_content_type(str)
- a, *b = str.split(";")
- return a.strip.downcase, *b
- end
- end
-
-end # module XMLRPC
-
diff --git a/ruby_2_2/lib/yaml.rb b/ruby_2_2/lib/yaml.rb
deleted file mode 100644
index c0ffcf877b..0000000000
--- a/ruby_2_2/lib/yaml.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-##
-# The YAML module is an alias of Psych, the YAML engine for Ruby.
-
-begin
- require 'psych'
-rescue LoadError
- warn "#{caller[0]}:"
- warn "It seems your ruby installation is missing psych (for YAML output)."
- warn "To eliminate this warning, please install libyaml and reinstall your ruby."
- raise
-end
-
-YAML = Psych # :nodoc:
-
-# YAML Ain't Markup Language
-#
-# This module provides a Ruby interface for data serialization in YAML format.
-#
-# The underlying implementation is the libyaml wrapper Psych.
-#
-# == Usage
-#
-# Working with YAML can be very simple, for example:
-#
-# require 'yaml'
-# # Parse a YAML string
-# YAML.load("--- foo") #=> "foo"
-#
-# # Emit some YAML
-# YAML.dump("foo") # => "--- foo\n...\n"
-# { :a => 'b'}.to_yaml # => "---\n:a: b\n"
-#
-# == Security
-#
-# Do not use YAML to load untrusted data. Doing so is unsafe and could allow
-# malicious input to execute arbitrary code inside your application. Please see
-# doc/security.rdoc for more information.
-#
-# == History
-#
-# Syck was the original for YAML implementation in Ruby's standard library
-# developed by why the lucky stiff.
-#
-# You can still use Syck, if you prefer, for parsing and emitting YAML, but you
-# must install the 'syck' gem now in order to use it.
-#
-# In older Ruby versions, ie. <= 1.9, Syck is still provided, however it was
-# completely removed with the release of Ruby 2.0.0.
-#
-# == More info
-#
-# For more advanced details on the implementation see Psych, and also check out
-# http://yaml.org for spec details and other helpful information.
-#
-# Pysch is maintained by Aaron Patterson on github: https://github.com/tenderlove/psych
-#
-# Syck can also be found on github: https://github.com/tenderlove/syck
-module YAML
-end
diff --git a/ruby_2_2/lib/yaml/dbm.rb b/ruby_2_2/lib/yaml/dbm.rb
deleted file mode 100644
index 24a68bfa71..0000000000
--- a/ruby_2_2/lib/yaml/dbm.rb
+++ /dev/null
@@ -1,279 +0,0 @@
-require 'yaml'
-require 'dbm'
-
-module YAML
-
-# YAML + DBM = YDBM
-#
-# YAML::DBM provides the same interface as ::DBM.
-#
-# However, while DBM only allows strings for both keys and values,
-# this library allows one to use most Ruby objects for values
-# by first converting them to YAML. Keys must be strings.
-#
-# Conversion to and from YAML is performed automatically.
-#
-# See the documentation for ::DBM and ::YAML for more information.
-class DBM < ::DBM
- VERSION = "0.1" # :nodoc:
-
- # :call-seq:
- # ydbm[key] -> value
- #
- # Return value associated with +key+ from database.
- #
- # Returns +nil+ if there is no such +key+.
- #
- # See #fetch for more information.
- def []( key )
- fetch( key )
- end
-
- # :call-seq:
- # ydbm[key] = value
- #
- # Set +key+ to +value+ in database.
- #
- # +value+ will be converted to YAML before storage.
- #
- # See #store for more information.
- def []=( key, val )
- store( key, val )
- end
-
- # :call-seq:
- # ydbm.fetch( key, ifnone = nil )
- # ydbm.fetch( key ) { |key| ... }
- #
- # Return value associated with +key+.
- #
- # If there is no value for +key+ and no block is given, returns +ifnone+.
- #
- # Otherwise, calls block passing in the given +key+.
- #
- # See ::DBM#fetch for more information.
- def fetch( keystr, ifnone = nil )
- begin
- val = super( keystr )
- return YAML.load( val ) if String === val
- rescue IndexError
- end
- if block_given?
- yield keystr
- else
- ifnone
- end
- end
-
- # Deprecated, used YAML::DBM#key instead.
- # ----
- # Note:
- # YAML::DBM#index makes warning from internal of ::DBM#index.
- # It says 'DBM#index is deprecated; use DBM#key', but DBM#key
- # behaves not same as DBM#index.
- #
- def index( keystr )
- super( keystr.to_yaml )
- end
-
- # :call-seq:
- # ydbm.key(value) -> string
- #
- # Returns the key for the specified value.
- def key( keystr )
- invert[keystr]
- end
-
- # :call-seq:
- # ydbm.values_at(*keys)
- #
- # Returns an array containing the values associated with the given keys.
- def values_at( *keys )
- keys.collect { |k| fetch( k ) }
- end
-
- # :call-seq:
- # ydbm.delete(key)
- #
- # Deletes value from database associated with +key+.
- #
- # Returns value or +nil+.
- def delete( key )
- v = super( key )
- if String === v
- v = YAML.load( v )
- end
- v
- end
-
- # :call-seq:
- # ydbm.delete_if { |key, value| ... }
- #
- # Calls the given block once for each +key+, +value+ pair in the database.
- # Deletes all entries for which the block returns true.
- #
- # Returns +self+.
- def delete_if # :yields: [key, value]
- del_keys = keys.dup
- del_keys.delete_if { |k| yield( k, fetch( k ) ) == false }
- del_keys.each { |k| delete( k ) }
- self
- end
-
- # :call-seq:
- # ydbm.reject { |key, value| ... }
- #
- # Converts the contents of the database to an in-memory Hash, then calls
- # Hash#reject with the specified code block, returning a new Hash.
- def reject
- hsh = self.to_hash
- hsh.reject { |k,v| yield k, v }
- end
-
- # :call-seq:
- # ydbm.each_pair { |key, value| ... }
- #
- # Calls the given block once for each +key+, +value+ pair in the database.
- #
- # Returns +self+.
- def each_pair # :yields: [key, value]
- keys.each { |k| yield k, fetch( k ) }
- self
- end
-
- # :call-seq:
- # ydbm.each_value { |value| ... }
- #
- # Calls the given block for each value in database.
- #
- # Returns +self+.
- def each_value # :yields: value
- super { |v| yield YAML.load( v ) }
- self
- end
-
- # :call-seq:
- # ydbm.values
- #
- # Returns an array of values from the database.
- def values
- super.collect { |v| YAML.load( v ) }
- end
-
- # :call-seq:
- # ydbm.has_value?(value)
- #
- # Returns true if specified +value+ is found in the database.
- def has_value?( val )
- each_value { |v| return true if v == val }
- return false
- end
-
- # :call-seq:
- # ydbm.invert -> hash
- #
- # Returns a Hash (not a DBM database) created by using each value in the
- # database as a key, with the corresponding key as its value.
- #
- # Note that all values in the hash will be Strings, but the keys will be
- # actual objects.
- def invert
- h = {}
- keys.each { |k| h[ self.fetch( k ) ] = k }
- h
- end
-
- # :call-seq:
- # ydbm.replace(hash) -> ydbm
- #
- # Replaces the contents of the database with the contents of the specified
- # object. Takes any object which implements the each_pair method, including
- # Hash and DBM objects.
- def replace( hsh )
- clear
- update( hsh )
- end
-
- # :call-seq:
- # ydbm.shift -> [key, value]
- #
- # Removes a [key, value] pair from the database, and returns it.
- # If the database is empty, returns +nil+.
- #
- # The order in which values are removed/returned is not guaranteed.
- def shift
- a = super
- a[1] = YAML.load( a[1] ) if a
- a
- end
-
- # :call-seq:
- # ydbm.select { |key, value| ... }
- # ydbm.select(*keys)
- #
- # If a block is provided, returns a new array containing [key, value] pairs
- # for which the block returns true.
- #
- # Otherwise, same as #values_at
- def select( *keys )
- if block_given?
- self.keys.collect { |k| v = self[k]; [k, v] if yield k, v }.compact
- else
- values_at( *keys )
- end
- end
-
- # :call-seq:
- # ydbm.store(key, value) -> value
- #
- # Stores +value+ in database with +key+ as the index. +value+ is converted
- # to YAML before being stored.
- #
- # Returns +value+
- def store( key, val )
- super( key, val.to_yaml )
- val
- end
-
- # :call-seq:
- # ydbm.update(hash) -> ydbm
- #
- # Updates the database with multiple values from the specified object.
- # Takes any object which implements the each_pair method, including
- # Hash and DBM objects.
- #
- # Returns +self+.
- def update( hsh )
- hsh.each_pair do |k,v|
- self.store( k, v )
- end
- self
- end
-
- # :call-seq:
- # ydbm.to_a -> array
- #
- # Converts the contents of the database to an array of [key, value] arrays,
- # and returns it.
- def to_a
- a = []
- keys.each { |k| a.push [ k, self.fetch( k ) ] }
- a
- end
-
-
- # :call-seq:
- # ydbm.to_hash -> hash
- #
- # Converts the contents of the database to an in-memory Hash object, and
- # returns it.
- def to_hash
- h = {}
- keys.each { |k| h[ k ] = self.fetch( k ) }
- h
- end
-
- alias :each :each_pair
-end
-
-end
diff --git a/ruby_2_2/lib/yaml/store.rb b/ruby_2_2/lib/yaml/store.rb
deleted file mode 100644
index b0b580ba1a..0000000000
--- a/ruby_2_2/lib/yaml/store.rb
+++ /dev/null
@@ -1,81 +0,0 @@
-#
-# YAML::Store
-#
-require 'yaml'
-require 'pstore'
-
-# YAML::Store provides the same functionality as PStore, except it uses YAML
-# to dump objects instead of Marshal.
-#
-# == Example
-#
-# require 'yaml/store'
-#
-# Person = Struct.new :first_name, :last_name
-#
-# people = [Person.new("Bob", "Smith"), Person.new("Mary", "Johnson")]
-#
-# store = YAML::Store.new "test.store"
-#
-# store.transaction do
-# store["people"] = people
-# store["greeting"] = { "hello" => "world" }
-# end
-#
-# After running the above code, the contents of "test.store" will be:
-#
-# ---
-# people:
-# - !ruby/struct:Person
-# first_name: Bob
-# last_name: Smith
-# - !ruby/struct:Person
-# first_name: Mary
-# last_name: Johnson
-# greeting:
-# hello: world
-
-class YAML::Store < PStore
-
- # :call-seq:
- # initialize( file_name, yaml_opts = {} )
- #
- # Creates a new YAML::Store object, which will store data in +file_name+.
- # If the file does not already exist, it will be created.
- #
- #
- # Options passed in through +yaml_opts+ will be used when converting the
- # store to YAML via Hash#to_yaml().
- def initialize file_name, yaml_opts = {}
- @opt = yaml_opts
- super
- end
-
- # :stopdoc:
-
- def dump(table)
- YAML.dump @table
- end
-
- def load(content)
- table = YAML.load(content)
- if table == false
- {}
- else
- table
- end
- end
-
- def marshal_dump_supports_canonical_option?
- false
- end
-
- EMPTY_MARSHAL_DATA = YAML.dump({})
- EMPTY_MARSHAL_CHECKSUM = Digest::MD5.digest(EMPTY_MARSHAL_DATA)
- def empty_marshal_data
- EMPTY_MARSHAL_DATA
- end
- def empty_marshal_checksum
- EMPTY_MARSHAL_CHECKSUM
- end
-end