ruby_doc_updates-20110512_vbatts.patch

Vincent Batts, 05/13/2011 03:20 AM

Download (39 KB)

View differences:

lib/uri/common.rb
7 7
#
8 8

  
9 9
module URI
10
  # 
11
  # Includes URI::REGEXP::PATTERN
12
  # 
10 13
  module REGEXP
11 14
    #
12 15
    # Patterns used to parse URI's
......
51 54
    # :startdoc:
52 55
  end # REGEXP
53 56

  
57
  # class that Parses String's into URI's
58
  #
59
  # It contains a Hash set of patterns and Regexp's that match and validate.
60
  #
54 61
  class Parser
55 62
    include REGEXP
56 63

  
......
95 102
      @regexp.each_value {|v| v.freeze}
96 103
      @regexp.freeze
97 104
    end
98
    attr_reader :pattern, :regexp
99 105

  
106
    # The Hash of patterns.
107
    #
108
    # see also URI::Parser.initialize_pattern
109
    attr_reader :pattern
110

  
111
    # The Hash of Regexp 
112
    #
113
    # see also URI::Parser.initialize_regexp
114
    attr_reader :regexp
115

  
116
    # Returns a split URI against regexp[:ABS_URI]
100 117
    def split(uri)
101 118
      case uri
102 119
      when ''
......
169 186
      return ret
170 187
    end
171 188

  
189
    #
190
    # == Args
191
    #
192
    # +uri+::
193
    #    String
194
    #
195
    # == Description
196
    #
197
    # parses +uri+ and constructs either matching URI scheme object 
198
    # (FTP, HTTP, HTTPS, LDAP, LDAPS, or MailTo) or URI::Generic
199
    #
200
    # == Usage
201
    #
202
    #	p = URI::Parser.new
203
    #	p.parse("ldap://ldap.example.com/dc=example?user=john")
204
    #	#=> #<URI::LDAP:0x00000000b9e7e8 URL:ldap://ldap.example.com/dc=example?user=john>
205
    #
172 206
    def parse(uri)
173 207
      scheme, userinfo, host, port,
174 208
       	registry, path, opaque, query, fragment = self.split(uri)
......
184 218
      end
185 219
    end
186 220

  
221

  
222
    #
223
    # == Args
224
    #
225
    # +uris+::
226
    #    an Array of Strings
227
    #
228
    # == Description
229
    #
230
    # Attempts to parse and merge a set of URIs
231
    #
187 232
    def join(*uris)
188 233
      uris[0] = URI(uris[0], self)
189 234
      uris.inject :merge
190 235
    end
191 236

  
237
    # 
238
    # :call-seq:
239
    # 	extract( str )
240
    # 	extract( str, schemes )
241
    # 	extract( str, schemes ) {|item| block }
242
    #
243
    # == Args
244
    #
245
    # +str+::
246
    #    String to search
247
    # +schemes+::
248
    #    Patterns to apply to +str+
249
    #
250
    # == Description
251
    #
252
    # Attempts to parse and merge a set of URIs
253
    # If no +block+ given , then returns the result,
254
    # else it calls +block+ for each element in result.
255
    #
256
    # see also URI::Parser.make_regexp
257
    #
192 258
    def extract(str, schemes = nil, &block)
193 259
      if block_given?
194 260
       	str.scan(make_regexp(schemes)) { yield $& }
......
200 266
      end
201 267
    end
202 268

  
269
    # returns Regexp that is default self.regexp[:ABS_URI_REF],
270
    # unless +schemes+ is provided. Then it is a Regexp.union with self.pattern[:X_ABS_URI]
203 271
    def make_regexp(schemes = nil)
204 272
      unless schemes
205 273
       	@regexp[:ABS_URI_REF]
......
208 276
      end
209 277
    end
210 278

  
279
    # 
280
    # :call-seq:
281
    # 	escape( str )
282
    # 	escape( str, unsafe )
283
    #
284
    # == Args
285
    #
286
    # +str+::
287
    #    String to make safe
288
    # +unsafe+::
289
    #    Regexp to apply. Defaults to self.regexp[:UNSAFE]
290
    #
291
    # == Description
292
    #
293
    # constructs a safe String from +str+, removing unsafe characters, replacing them with codes.
294
    #
211 295
    def escape(str, unsafe = @regexp[:UNSAFE])
212 296
      unless unsafe.kind_of?(Regexp)
213 297
        # perhaps unsafe is String object
......
223 307
      end.force_encoding(Encoding::US_ASCII)
224 308
    end
225 309

  
310
    # 
311
    # :call-seq:
312
    # 	unescape( str )
313
    # 	unescape( str, unsafe )
314
    #
315
    # == Args
316
    #
317
    # +str+::
318
    #    String to remove escapes from
319
    # +unsafe+::
320
    #    Regexp to apply. Defaults to self.regexp[:ESCAPED]
321
    #
322
    # == Description
323
    #
324
    # Removes escapes from +str+
325
    #
226 326
    def unescape(str, escaped = @regexp[:ESCAPED])
227 327
      str.gsub(escaped) { [$&[1, 2].hex].pack('C') }.force_encoding(str.encoding)
228 328
    end
......
234 334

  
235 335
    private
236 336

  
337
    # Constructs the default Hash of patterns
237 338
    def initialize_pattern(opts = {})
238 339
      ret = {}
239 340
      ret[:ESCAPED] = escaped = (opts.delete(:ESCAPED) || PATTERN::ESCAPED)
......
391 492
      ret
392 493
    end
393 494

  
495
    # Constructs the default Hash of Regexp's
394 496
    def initialize_regexp(pattern)
395 497
      ret = {}
396 498

  
......
423 525
    end
424 526
  end # class Parser
425 527

  
528
  # URI::Parser.new
426 529
  DEFAULT_PARSER = Parser.new
427 530
  DEFAULT_PARSER.pattern.each_pair do |sym, str|
428 531
    unless REGEXP::PATTERN.const_defined?(sym)
......
465 568
    module_function :make_components_hash
466 569
  end
467 570

  
571
  # module for escaping unsafe characters with codes.
468 572
  module Escape
469 573
    #
470 574
    # == Synopsis
......
535 639
  include REGEXP
536 640

  
537 641
  @@schemes = {}
642
  # Returns a Hash of the defined schemes
538 643
  def self.scheme_list
539 644
    @@schemes
540 645
  end
lib/uri/ftp.rb
19 19
  # http://tools.ietf.org/html/draft-hoffman-ftp-uri-04
20 20
  #
21 21
  class FTP < Generic
22
    # A Default port of 21 for URI::FTP
22 23
    DEFAULT_PORT = 21
23 24

  
25
    #
26
    # An Array of the available components for URI::FTP
27
    #
24 28
    COMPONENT = [
25 29
      :scheme,
26 30
      :userinfo, :host, :port,
27 31
      :path, :typecode
28 32
    ].freeze
33

  
29 34
    #
30 35
    # Typecode is "a", "i" or "d".
31 36
    #
......
34 39
    # * "d" indicates the contents of a directory should be displayed
35 40
    #
36 41
    TYPECODE = ['a', 'i', 'd'].freeze
42

  
43
    # Typecode prefix
44
    #  ';type='
37 45
    TYPECODE_PREFIX = ';type='.freeze
38 46

  
47
    # alternate initialization
48
    # Creates a new URI::FTP object.
49
    #
50
    # Unlike build(), this method does not escape the path component as required by
51
    # RFC1738; instead it is treated as per RFC2396.
52
    #
53
    # Arguments are user, password, host, port, path, typecode,
54
    # and arg_check, in that order.
39 55
    def self.new2(user, password, host, port, path,
40 56
                  typecode = nil, arg_check = true)
41 57
      typecode = nil if typecode.size == 0
......
133 149
        end
134 150
      end
135 151
    end
152

  
153
    # typecode accessor 
154
    #
155
    # see URI::FTP::COMPONENT
136 156
    attr_reader :typecode
137 157

  
158
    # validates typecode +v+,
159
    # returns a +true+ or +false+ boolean
160
    #
138 161
    def check_typecode(v)
139 162
      if TYPECODE.include?(v)
140 163
        return true
......
145 168
    end
146 169
    private :check_typecode
147 170

  
171
    # private setter for the typecode +v+
172
    #
173
    # see also URI::FTP.typecode=
174
    #
148 175
    def set_typecode(v)
149 176
      @typecode = v
150 177
    end
151 178
    protected :set_typecode
152 179

  
180
    #
181
    # == Args
182
    #
183
    # +v+::
184
    #    String
185
    #
186
    # == Description
187
    #
188
    # public setter for the typecode +v+.
189
    # (with validation)
190
    #
191
    # see also URI::FTP.check_typecode
192
    #
193
    # == Usage
194
    #
195
    #   require 'uri'
196
    #
197
    #   uri = URI.parse("ftp://john@ftp.example.com/my_file.img")
198
    #   #=> #<URI::FTP:0x00000000923650 URL:ftp://john@ftp.example.com/my_file.img>
199
    #   uri.typecode = "i"
200
    #   # =>  "i"
201
    #   uri
202
    #   #=> #<URI::FTP:0x00000000923650 URL:ftp://john@ftp.example.com/my_file.img;type=i>
203
    #
153 204
    def typecode=(typecode)
154 205
      check_typecode(typecode)
155 206
      set_typecode(typecode)
lib/uri/generic.rb
18 18
  class Generic
19 19
    include URI
20 20

  
21
    #
22
    # A Default port of nil for URI::Generic
23
    #
21 24
    DEFAULT_PORT = nil
22 25

  
23 26
    #
......
27 30
      self::DEFAULT_PORT
28 31
    end
29 32

  
33
    #
34
    # Returns default port
35
    #
30 36
    def default_port
31 37
      self.class.default_port
32 38
    end
33 39

  
40
    #
41
    # An Array of the available components for URI::Generic
42
    #
34 43
    COMPONENT = [
35 44
      :scheme,
36 45
      :userinfo, :host, :port, :registry,
......
46 55
      self::COMPONENT
47 56
    end
48 57

  
58
    #
59
    # Default to not use the registry for a URI::Generic
60
    #
49 61
    USE_REGISTRY = false
50 62

  
51 63
    #
52
    # DOC: FIXME!
64
    # Returns whether a registry of naming
65
    # authorities are being used.
53 66
    #
54 67
    def self.use_registry
55 68
      self::USE_REGISTRY
......
138 151
    # +port+::
139 152
    #   Server port
140 153
    # +registry+::
141
    #   DOC: FIXME!
154
    #   Registry of naming authorities.
142 155
    # +path+::
143 156
    #   Path on server
144 157
    # +opaque+::
145
    #   DOC: FIXME!
158
    #   Opaque part
146 159
    # +query+::
147 160
    #   Query data
148 161
    # +fragment+::
......
206 219
      self.set_port(self.default_port) if self.default_port && !@port
207 220
    end
208 221

  
222
    #
223
    # returns the scheme component of the URI.
224
    #
225
    #   URI("http://foo/bar/baz").scheme #=> "http"
226
    #
209 227
    attr_reader :scheme
210 228

  
211 229
    # returns the host component of the URI.
......
230 248
    #
231 249
    attr_reader :host
232 250

  
251
    # returns the port component of the URI.
252
    #
253
    #   URI("http://foo/bar/baz").port #=> "80"
254
    # 
255
    #   URI("http://foo:8080/bar/baz").port #=> "8080"
256
    #
233 257
    attr_reader :port
258

  
259
    # returns the registry component of the URI.
260
    #
261
    #  (see RFC2396 Section 3.2)
262
    #
234 263
    attr_reader :registry
264

  
265
    # returns the path component of the URI.
266
    #
267
    #   URI("http://foo/bar/baz").path #=> "/bar/baz"
268
    # 
235 269
    attr_reader :path
270

  
271
    # returns the query component of the URI.
272
    #
273
    #   URI("http://foo/bar/baz?search=FooBar").query #=> "search=FooBar"
274
    # 
236 275
    attr_reader :query
276

  
277
    # returns the opaque part of the URI.
278
    #
279
    #   URI("mailto:foo@example.org").opaque #=> "foo@example.org"
280
    #
281
    # Portion of the path that does make use of the slash '/'.
282
    # The path typically refers to the absolute path and the opaque part.
283
    #  (see RFC2396 Section 3 and 5.2)
284
    #
237 285
    attr_reader :opaque
286

  
287
    # returns the fragment component of the URI.
288
    #
289
    #   URI("http://foo/bar/baz?search=FooBar#ponies").fragment #=> "ponies"
290
    # 
238 291
    attr_reader :fragment
239 292

  
293
    # returns the parser to be used.
294
    #
295
    # Unless a URI::Parser is defined, then DEFAULT_PARSER is used.
296
    #
240 297
    def parser
241 298
      if !defined?(@parser) || !@parser
242 299
        DEFAULT_PARSER
......
257 314
    end
258 315
    private :replace!
259 316

  
317
    #
318
    # Components of the URI in the order.
319
    #
260 320
    def component
261 321
      self.class.component
262 322
    end
263 323

  
324
    #
325
    # check the scheme +v+ component against the URI::Parser Regexp for :SCHEME
326
    #
264 327
    def check_scheme(v)
265 328
      if v && parser.regexp[:SCHEME] !~ v
266 329
        raise InvalidComponentError,
......
271 334
    end
272 335
    private :check_scheme
273 336

  
337
    # protected setter for the scheme component +v+
338
    #
339
    # see also URI::Generic.scheme=
340
    #
274 341
    def set_scheme(v)
275 342
      @scheme = v
276 343
    end
277 344
    protected :set_scheme
278 345

  
346
    #
347
    # == Args
348
    #
349
    # +v+::
350
    #    String
351
    #
352
    # == Description
353
    #
354
    # public setter for the scheme component +v+.
355
    # (with validation)
356
    #
357
    # see also URI::Generic.check_scheme
358
    #
359
    # == Usage
360
    #
361
    #   require 'uri'
362
    #
363
    #   uri = URI.parse("http://my.example.com")
364
    #   uri.scheme = "https"
365
    #   # =>  "https"
366
    #   uri
367
    #   #=> #<URI::HTTP:0x000000008e89e8 URL:https://my.example.com>
368
    #
279 369
    def scheme=(v)
280 370
      check_scheme(v)
281 371
      set_scheme(v)
282 372
      v
283 373
    end
284 374

  
375
    #
376
    # check the +user+ and +password+.
377
    #
378
    # If +password+ is not provided, then +user+ is
379
    # split, using URI::Generic.split_userinfo, to
380
    # pull +user+ and +password.
381
    #
382
    # see also URI::Generic.check_user, URI::Generic.check_password
383
    #
285 384
    def check_userinfo(user, password = nil)
286 385
      if !password
287 386
        user, password = split_userinfo(user)
......
293 392
    end
294 393
    private :check_userinfo
295 394

  
395
    #
396
    # check the user +v+ component for RFC2396 compliance
397
    # and against the URI::Parser Regexp for :USERINFO
398
    #
399
    # Can not have a registry or opaque component defined,
400
    # with a user component defined.
401
    #
296 402
    def check_user(v)
297 403
      if @registry || @opaque
298 404
        raise InvalidURIError,
......
310 416
    end
311 417
    private :check_user
312 418

  
419
    #
420
    # check the password +v+ component for RFC2396 compliance
421
    # and against the URI::Parser Regexp for :USERINFO
422
    #
423
    # Can not have a registry or opaque component defined,
424
    # with a user component defined.
425
    #
313 426
    def check_password(v, user = @user)
314 427
      if @registry || @opaque
315 428
        raise InvalidURIError,
......
343 456
      # returns userinfo
344 457
    end
345 458

  
459
    #
460
    # == Args
461
    #
462
    # +v+::
463
    #    String
464
    #
465
    # == Description
466
    #
467
    # public setter for the +user+ component.
468
    # (with validation)
469
    #
470
    # see also URI::Generic.check_user
471
    #
472
    # == Usage
473
    #
474
    #   require 'uri'
475
    #
476
    #   uri = URI.parse("http://john:S3nsit1ve@my.example.com")
477
    #   uri.user = "sam"
478
    #   # =>  "sam"
479
    #   uri
480
    #   #=> #<URI::HTTP:0x00000000881d90 URL:http://sam:V3ry_S3nsit1ve@my.example.com>
481
    #
346 482
    def user=(user)
347 483
      check_user(user)
348 484
      set_user(user)
349 485
      # returns user
350 486
    end
351 487

  
488
    #
489
    # == Args
490
    #
491
    # +v+::
492
    #    String
493
    #
494
    # == Description
495
    #
496
    # public setter for the +password+ component.
497
    # (with validation)
498
    #
499
    # see also URI::Generic.check_password
500
    #
501
    # == Usage
502
    #
503
    #   require 'uri'
504
    #
505
    #   uri = URI.parse("http://john:S3nsit1ve@my.example.com")
506
    #   uri.password = "V3ry_S3nsit1ve"
507
    #   # =>  "V3ry_S3nsit1ve"
508
    #   uri
509
    #   #=> #<URI::HTTP:0x00000000881d90 URL:http://john:V3ry_S3nsit1ve@my.example.com>
510
    #
352 511
    def password=(password)
353 512
      check_password(password)
354 513
      set_password(password)
355 514
      # returns password
356 515
    end
357 516

  
517
    # protect setter for the +user+ component, and +password+ if available.
518
    # (with validation)
519
    #
520
    # see also URI::Generic.userinfo=
521
    # 
358 522
    def set_userinfo(user, password = nil)
359 523
      unless password
360 524
        user, password = split_userinfo(user)
......
366 530
    end
367 531
    protected :set_userinfo
368 532

  
533
    # protected setter for the user component +v+
534
    #
535
    # see also URI::Generic.user=
536
    #
369 537
    def set_user(v)
370 538
      set_userinfo(v, @password)
371 539
      v
372 540
    end
373 541
    protected :set_user
374 542

  
543
    # protected setter for the password component +v+
544
    #
545
    # see also URI::Generic.password=
546
    #
375 547
    def set_password(v)
376 548
      @password = v
377 549
      # returns v
378 550
    end
379 551
    protected :set_password
380 552

  
553
    # returns the userinfo +ui+ as user, password
554
    # if properly formated as 'user:password'
381 555
    def split_userinfo(ui)
382 556
      return nil, nil unless ui
383 557
      user, password = ui.split(/:/, 2)
......
386 560
    end
387 561
    private :split_userinfo
388 562

  
563
    # escapes 'user:password' +v+ based on RFC 1738 section 3.1
389 564
    def escape_userpass(v)
390 565
      v = parser.escape(v, /[@:\/]/o) # RFC 1738 section 3.1 #/
391 566
    end
392 567
    private :escape_userpass
393 568

  
569
    # returns the userinfo, either as 'user' or 'user:password'
394 570
    def userinfo
395 571
      if @user.nil?
396 572
        nil
......
401 577
      end
402 578
    end
403 579

  
580
    # returns the user component
404 581
    def user
405 582
      @user
406 583
    end
407 584

  
585
    # returns the password component
408 586
    def password
409 587
      @password
410 588
    end
411 589

  
590
    #
591
    # check the host +v+ component for RFC2396 compliance
592
    # and against the URI::Parser Regexp for :HOST
593
    #
594
    # Can not have a registry or opaque component defined,
595
    # with a host component defined.
596
    #
412 597
    def check_host(v)
413 598
      return v unless v
414 599

  
......
424 609
    end
425 610
    private :check_host
426 611

  
612
    # protected setter for the host component +v+
613
    #
614
    # see also URI::Generic.host=
615
    #
427 616
    def set_host(v)
428 617
      @host = v
429 618
    end
430 619
    protected :set_host
431 620

  
621
    #
622
    # == Args
623
    #
624
    # +v+::
625
    #    String
626
    #
627
    # == Description
628
    #
629
    # public setter for the host component +v+.
630
    # (with validation)
631
    #
632
    # see also URI::Generic.check_host
633
    #
634
    # == Usage
635
    #
636
    #   require 'uri'
637
    #
638
    #   uri = URI.parse("http://my.example.com")
639
    #   uri.host = "foo.com"
640
    #   # =>  "foo.com"
641
    #   uri
642
    #   #=> #<URI::HTTP:0x000000008e89e8 URL:http://foo.com>
643
    #
432 644
    def host=(v)
433 645
      check_host(v)
434 646
      set_host(v)
......
467 679
      self.host = v
468 680
    end
469 681

  
682
    #
683
    # check the port +v+ component for RFC2396 compliance
684
    # and against the URI::Parser Regexp for :PORT
685
    #
686
    # Can not have a registry or opaque component defined,
687
    # with a port component defined.
688
    #
470 689
    def check_port(v)
471 690
      return v unless v
472 691

  
......
482 701
    end
483 702
    private :check_port
484 703

  
704
    # protected setter for the port component +v+
705
    #
706
    # see also URI::Generic.port=
707
    #
485 708
    def set_port(v)
486 709
      unless !v || v.kind_of?(Fixnum)
487 710
        if v.empty?
......
494 717
    end
495 718
    protected :set_port
496 719

  
720
    #
721
    # == Args
722
    #
723
    # +v+::
724
    #    String
725
    #
726
    # == Description
727
    #
728
    # public setter for the port component +v+.
729
    # (with validation)
730
    #
731
    # see also URI::Generic.check_port
732
    #
733
    # == Usage
734
    #
735
    #   require 'uri'
736
    #
737
    #   uri = URI.parse("http://my.example.com")
738
    #   uri.port = 8080
739
    #   # =>  8080
740
    #   uri
741
    #   #=> #<URI::HTTP:0x000000008e89e8 URL:http://my.example.com:8080>
742
    #
497 743
    def port=(v)
498 744
      check_port(v)
499 745
      set_port(v)
500 746
      port
501 747
    end
502 748

  
749
    #
750
    # check the registry +v+ component for RFC2396 compliance
751
    # and against the URI::Parser Regexp for :REGISTRY
752
    #
753
    # Can not have a host, port or user component defined,
754
    # with a registry component defined.
755
    #
503 756
    def check_registry(v)
504 757
      return v unless v
505 758

  
......
518 771
    end
519 772
    private :check_registry
520 773

  
774
    # protected setter for the registry component +v+
775
    #
776
    # see also URI::Generic.registry=
777
    #
521 778
    def set_registry(v)
522 779
      @registry = v
523 780
    end
524 781
    protected :set_registry
525 782

  
783
    #
784
    # == Args
785
    #
786
    # +v+::
787
    #    String
788
    #
789
    # == Description
790
    #
791
    # public setter for the registry component +v+.
792
    # (with validation)
793
    #
794
    # see also URI::Generic.check_registry
795
    #
526 796
    def registry=(v)
527 797
      check_registry(v)
528 798
      set_registry(v)
529 799
      v
530 800
    end
531 801

  
802
    #
803
    # check the path +v+ component for RFC2396 compliance
804
    # and against the URI::Parser Regexp
805
    # for :ABS_PATH and :REL_PATH
806
    #
807
    # Can not have a opaque component defined,
808
    # with a path component defined.
809
    #
532 810
    def check_path(v)
533 811
      # raise if both hier and opaque are not nil, because:
534 812
      # absoluteURI   = scheme ":" ( hier_part | opaque_part )
......
556 834
    end
557 835
    private :check_path
558 836

  
837
    # protected setter for the path component +v+
838
    #
839
    # see also URI::Generic.path=
840
    #
559 841
    def set_path(v)
560 842
      @path = v
561 843
    end
562 844
    protected :set_path
563 845

  
846
    #
847
    # == Args
848
    #
849
    # +v+::
850
    #    String
851
    #
852
    # == Description
853
    #
854
    # public setter for the path component +v+.
855
    # (with validation)
856
    #
857
    # see also URI::Generic.check_path
858
    #
859
    # == Usage
860
    #
861
    #   require 'uri'
862
    #
863
    #   uri = URI.parse("http://my.example.com/pub/files")
864
    #   uri.path = "/faq/"
865
    #   # =>  "/faq/"
866
    #   uri
867
    #   #=> #<URI::HTTP:0x000000008e89e8 URL:http://my.example.com/faq/>
868
    #
564 869
    def path=(v)
565 870
      check_path(v)
566 871
      set_path(v)
567 872
      v
568 873
    end
569 874

  
875
    #
876
    # check the query +v+ component for RFC2396 compliance
877
    # and against the URI::Parser Regexp for :QUERY
878
    #
879
    # Can not have a opaque component defined,
880
    # with a query component defined.
881
    #
570 882
    def check_query(v)
571 883
      return v unless v
572 884

  
......
587 899
    end
588 900
    private :check_query
589 901

  
902
    # protected setter for the query component +v+
903
    #
904
    # see also URI::Generic.query=
905
    #
590 906
    def set_query(v)
591 907
      @query = v
592 908
    end
593 909
    protected :set_query
594 910

  
911
    #
912
    # == Args
913
    #
914
    # +v+::
915
    #    String
916
    #
917
    # == Description
918
    #
919
    # public setter for the query component +v+.
920
    # (with validation)
921
    #
922
    # see also URI::Generic.check_query
923
    #
924
    # == Usage
925
    #
926
    #   require 'uri'
927
    #
928
    #   uri = URI.parse("http://my.example.com/?id=25")
929
    #   uri.query = "id=1"
930
    #   # =>  "id=1"
931
    #   uri
932
    #   #=> #<URI::HTTP:0x000000008e89e8 URL:http://my.example.com/?id=1>
933
    #
595 934
    def query=(v)
596 935
      check_query(v)
597 936
      set_query(v)
598 937
      v
599 938
    end
600 939

  
940
    #
941
    # check the opaque +v+ component for RFC2396 compliance and
942
    # against the URI::Parser Regexp for :OPAQUE
943
    #
944
    # Can not have a host, port, user or path component defined,
945
    # with an opaque component defined.
946
    #
601 947
    def check_opaque(v)
602 948
      return v unless v
603 949

  
......
616 962
    end
617 963
    private :check_opaque
618 964

  
965
    # protected setter for the opaque component +v+
966
    #
967
    # see also URI::Generic.opaque=
968
    #
619 969
    def set_opaque(v)
620 970
      @opaque = v
621 971
    end
622 972
    protected :set_opaque
623 973

  
974
    #
975
    # == Args
976
    #
977
    # +v+::
978
    #    String
979
    #
980
    # == Description
981
    #
982
    # public setter for the opaque component +v+.
983
    # (with validation)
984
    #
985
    # see also URI::Generic.check_opaque
986
    #
624 987
    def opaque=(v)
625 988
      check_opaque(v)
626 989
      set_opaque(v)
627 990
      v
628 991
    end
629 992

  
993
    #
994
    # check the fragment +v+ component against the URI::Parser Regexp for :FRAGMENT
995
    #
630 996
    def check_fragment(v)
631 997
      return v unless v
632 998

  
......
639 1005
    end
640 1006
    private :check_fragment
641 1007

  
1008
    # protected setter for the fragment component +v+
1009
    #
1010
    # see also URI::Generic.fragment=
1011
    #
642 1012
    def set_fragment(v)
643 1013
      @fragment = v
644 1014
    end
645 1015
    protected :set_fragment
646 1016

  
1017
    #
1018
    # == Args
1019
    #
1020
    # +v+::
1021
    #    String
1022
    #
1023
    # == Description
1024
    #
1025
    # public setter for the fragment component +v+.
1026
    # (with validation)
1027
    #
1028
    # see also URI::Generic.check_fragment
1029
    #
1030
    # == Usage
1031
    #
1032
    #   require 'uri'
1033
    #
1034
    #   uri = URI.parse("http://my.example.com/?id=25#time=1305212049")
1035
    #   uri.fragment = "time=1305212086"
1036
    #   # =>  "time=1305212086"
1037
    #   uri
1038
    #   #=> #<URI::HTTP:0x000000007a81f8 URL:http://my.example.com/?id=25#time=1305212086>
1039
    #
647 1040
    def fragment=(v)
648 1041
      check_fragment(v)
649 1042
      set_fragment(v)
......
680 1073
      !absolute?
681 1074
    end
682 1075

  
1076
    #
1077
    # returns an Array of the path split on '/'
1078
    #
683 1079
    def split_path(path)
684 1080
      path.split(%r{/+}, -1)
685 1081
    end
686 1082
    private :split_path
687 1083

  
1084
    # 
1085
    # Merges a base path +base+, with relative path +rel+,
1086
    # returns a modified base path.
1087
    #
688 1088
    def merge_path(base, rel)
689 1089

  
690 1090
      # RFC2396, Section 5.2, 5)
......
861 1261
    end
862 1262
    private :merge0
863 1263

  
1264
    # :stopdoc:
864 1265
    def route_from_path(src, dst)
865 1266
      case dst
866 1267
      when src
......
897 1298
      return '../' * src_path.size + tmp
898 1299
    end
899 1300
    private :route_from_path
1301
    # :startdoc:
900 1302

  
1303
    # :stopdoc:
901 1304
    def route_from0(oth)
902 1305
      oth = URI(oth, parser)
903 1306
      if self.relative?
......
944 1347
      return oth, rel
945 1348
    end
946 1349
    private :route_from0
1350
    # :startdoc:
1351

  
947 1352
    #
948 1353
    # == Args
949 1354
    #
......
1030 1435
      end
1031 1436
    end
1032 1437

  
1438
    # returns the assemble String with path and query components
1033 1439
    def path_query
1034 1440
      str = @path
1035 1441
      if @query
......
1115 1521

  
1116 1522
=begin
1117 1523
=end
1524

  
1525

  
1526
    # returns an Array of the components defined from the COMPONENT Array
1118 1527
    def component_ary
1119 1528
      component.collect do |x|
1120 1529
        self.send(x)
......
1155 1564
      @@to_s.bind(self).call.sub!(/>\z/) {" URL:#{self}>"}
1156 1565
    end
1157 1566

  
1567
    #
1568
    # == Args
1569
    #
1570
    # +v+::
1571
    #    URI or String
1572
    #
1573
    # == Description
1574
    #
1575
    #  attempt to parse other URI +oth+
1576
    #  return [parsed_oth, self]
1577
    #
1578
    # == Usage
1579
    #
1580
    #   require 'uri'
1581
    #
1582
    #   uri = URI.parse("http://my.example.com")
1583
    #   uri.coerce("http://foo.com")
1584
    #   #=> [#<URI::HTTP:0x00000000bcb028 URL:http://foo.com/>, #<URI::HTTP:0x00000000d92178 URL:http://my.example.com>]
1585
    #
1158 1586
    def coerce(oth)
1159 1587
      case oth
1160 1588
      when String
lib/uri/http.rb
19 19
  # update. See <URL:http://support.microsoft.com/kb/834489>.
20 20
  #
21 21
  class HTTP < Generic
22
    # A Default port of 80 for URI::HTTP
22 23
    DEFAULT_PORT = 80
23 24

  
25
    # An Array of the available components for URI::HTTP
24 26
    COMPONENT = [
25 27
      :scheme,
26 28
      :userinfo, :host, :port,
......
71 73
    #
72 74
    # Example:
73 75
    #
74
    #     uri = URI::HTTP.new(['http', nil, "www.example.com", nil, "/path",
75
    #       "query", 'fragment'])
76
    #     uri = URI::HTTP.new('http', nil, "www.example.com", nil, "/path",
77
    #       "query", 'fragment')
78
    #
79
    #
80
    # See also URI::Generic.new
76 81
    #
77 82
    def initialize(*arg)
78 83
      super(*arg)
lib/uri/https.rb
14 14
  # than 'http:'. Other than that, HTTPS URIs are identical to HTTP URIs;
15 15
  # see URI::HTTP.
16 16
  class HTTPS < HTTP
17
    # A Default port of 443 for URI::HTTPS
17 18
    DEFAULT_PORT = 443
18 19
  end
19 20
  @@schemes['HTTPS'] = HTTPS
lib/uri/ldap.rb
20 20
  #
21 21
  class LDAP < Generic
22 22

  
23
    # A Default port of 389 for URI::LDAP
23 24
    DEFAULT_PORT = 389
24 25

  
26
    # An Array of the available components for URI::LDAP
25 27
    COMPONENT = [
26 28
      :scheme,
27 29
      :host, :port,
......
32 34
      :extensions,
33 35
    ].freeze
34 36

  
37
    # Scopes available for the starting point.
38
    #
39
    # * SCOPE_BASE - the Base DN
40
    # * SCOPE_ONE  - one level under the Base DN, not including the base DN and not including any entries under this.
41
    # * SCOPE_SUB  - subtress, all entries at all levels 
42
    #
35 43
    SCOPE = [
36 44
      SCOPE_ONE = 'one',
37 45
      SCOPE_SUB = 'sub',
38 46
      SCOPE_BASE = 'base',
39 47
    ].freeze
40 48

  
49
    #
50
    # == Description
51
    #
52
    # Create a new URI::LDAP object from components, with syntax checking.
53
    #
54
    # The components accepted are host, port, dn, attributes,
55
    # scope, filter, and extensions.
56
    #
57
    # The components should be provided either as an Array, or as a Hash
58
    # with keys formed by preceding the component names with a colon.
59
    #
60
    # If an Array is used, the components must be passed in the order
61
    # [host, port, dn, attributes, scope, filter, extensions].
62
    #
63
    # Example:
64
    #
65
    #     newuri = URI::LDAP.build({:host => 'ldap.example.com',
66
    #       :dn> => '/dc=example'})
67
    #
68
    #     newuri = URI::LDAP.build(["ldap.example.com", nil,
69
    #       "/dc=example;dc=com", "query", nil, nil, nil])
70
    #
41 71
    def self.build(args)
42 72
      tmp = Util::make_components_hash(self, args)
43 73

  
......
56 86
      return super(tmp)
57 87
    end
58 88

  
89
    #
90
    # == Description
91
    #
92
    # Create a new URI::LDAP object from generic URI components as per
93
    # RFC 2396. No LDAP-specific syntax checking is performed.
94
    #
95
    # Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
96
    # +opaque+, +query+ and +fragment+, in that order.
97
    #
98
    # Example:
99
    #
100
    #     uri = URI::LDAP.new("ldap", nil, "ldap.example.com", nil,
101
    #       "/dc=example;dc=com", "query", nil, nil, nil, nil)
102
    #
103
    #
104
    # See also URI::Generic.new
105
    #
59 106
    def initialize(*arg)
60 107
      super(*arg)
61 108

  
......
67 114
      parse_query
68 115
    end
69 116

  
117
    # private method to cleanup +dn+ from using the +path+ component attribute
70 118
    def parse_dn
71 119
      @dn = @path[1..-1]
72 120
    end
73 121
    private :parse_dn
74 122

  
123
    # private method to cleanup +attributes+, +scope+, +filter+ and +extensions+,
124
    # from using the +query+ component attribute
75 125
    def parse_query
76 126
      @attributes = nil
77 127
      @scope      = nil
......
89 139
    end
90 140
    private :parse_query
91 141

  
142
    # private method to assemble +query+ from +attributes+, +scope+, +filter+ and +extensions+.
92 143
    def build_path_query
93 144
      @path = '/' + @dn
94 145

  
......
101 152
    end
102 153
    private :build_path_query
103 154

  
155
    # returns dn.
104 156
    def dn
105 157
      @dn
106 158
    end
107 159

  
160
    # private setter for dn +val+
108 161
    def set_dn(val)
109 162
      @dn = val
110 163
      build_path_query
......
112 165
    end
113 166
    protected :set_dn
114 167

  
168
    # setter for dn +val+
115 169
    def dn=(val)
116 170
      set_dn(val)
117 171
      val
118 172
    end
119 173

  
174
    # returns attributes.
120 175
    def attributes
121 176
      @attributes
122 177
    end
123 178

  
179
    # private setter for attributes +val+
124 180
    def set_attributes(val)
125 181
      @attributes = val
126 182
      build_path_query
......
128 184
    end
129 185
    protected :set_attributes
130 186

  
187
    # setter for attributes +val+
131 188
    def attributes=(val)
132 189
      set_attributes(val)
133 190
      val
134 191
    end
135 192

  
193
    # returns scope.
136 194
    def scope
137 195
      @scope
138 196
    end
139 197

  
198
    # private setter for scope +val+
140 199
    def set_scope(val)
141 200
      @scope = val
142 201
      build_path_query
......
144 203
    end
145 204
    protected :set_scope
146 205

  
206
    # setter for scope +val+
147 207
    def scope=(val)
148 208
      set_scope(val)
149 209
      val
150 210
    end
151 211

  
212
    # returns filter.
152 213
    def filter
153 214
      @filter
154 215
    end
155 216

  
217
    # private setter for filter +val+
156 218
    def set_filter(val)
157 219
      @filter = val
158 220
      build_path_query
......
160 222
    end
161 223
    protected :set_filter
162 224

  
225
    # setter for filter +val+
163 226
    def filter=(val)
164 227
      set_filter(val)
165 228
      val
166 229
    end
167 230

  
231
    # returns extensions.
168 232
    def extensions
169 233
      @extensions
170 234
    end
171 235

  
236
    # private setter for extensions +val+
172 237
    def set_extensions(val)
173 238
      @extensions = val
174 239
      build_path_query
......
176 241
    end
177 242
    protected :set_extensions
178 243

  
244
    # setter for extensions +val+
179 245
    def extensions=(val)
180 246
      set_extensions(val)
181 247
      val
182 248
    end
183 249

  
250
    # Checks if URI has a path
251
    # For URI::LDAP this will return +false+
184 252
    def hierarchical?
185 253
      false
186 254
    end
lib/uri/ldaps.rb
6 6
  # than 'ldap:'. Other than that, LDAPS URIs are identical to LDAP URIs;
7 7
  # see URI::LDAP.
8 8
  class LDAPS < LDAP
9
    # A Default port of 636 for URI::LDAPS
9 10
    DEFAULT_PORT = 636
10 11
  end
11 12
  @@schemes['LDAPS'] = LDAPS
lib/uri/mailto.rb
16 16
  class MailTo < Generic
17 17
    include REGEXP
18 18

  
19
    # A Default port of nil for URI::MailTo
19 20
    DEFAULT_PORT = nil
20 21

  
22
    # An Array of the available components for URI::MailTo
21 23
    COMPONENT = [ :scheme, :to, :headers ].freeze
22 24

  
23 25
    # :stopdoc:
......
155 157
    # E-mail headers set by the URL, as an Array of Arrays
156 158
    attr_reader :headers
157 159

  
160
    # check the to +v+ component against either
161
    # * URI::Parser Regexp for :OPAQUE
162
    # * MAILBOX_PATTERN
158 163
    def check_to(v)
159 164
      return true unless v
160 165
      return true if v.size == 0
......
168 173
    end
169 174
    private :check_to
170 175

  
176
    # private setter for to +v+
171 177
    def set_to(v)
172 178
      @to = v
173 179
    end
174 180
    protected :set_to
175 181

  
182
    # setter for to +v+
176 183
    def to=(v)
177 184
      check_to(v)
178 185
      set_to(v)
179 186
      v
180 187
    end
181 188

  
189
    # check the headers +v+ component against either
190
    # * URI::Parser Regexp for :OPAQUE
191
    # * HEADER_PATTERN
182 192
    def check_headers(v)
183 193
      return true unless v
184 194
      return true if v.size == 0
......
193 203
    end
194 204
    private :check_headers
195 205

  
206
    # private setter for headers +v+
196 207
    def set_headers(v)
197 208
      @headers = []
198 209
      if v
......
203 214
    end
204 215
    protected :set_headers
205 216

  
217
    # setter for headers +v+
206 218
    def headers=(v)
207 219
      check_headers(v)
208 220
      set_headers(v)
209 221
      v
210 222
    end
211 223

  
224
    # Constructs String from URI
212 225
    def to_s
213 226
      @scheme + ':' +
214 227
        if @to
process.c
5677 5677
    rb_mProcess = rb_define_module("Process");
5678 5678

  
5679 5679
#ifdef WNOHANG
5680
    /* see Process.wait */
5680 5681
    rb_define_const(rb_mProcess, "WNOHANG", INT2FIX(WNOHANG));
5681 5682
#else
5683
    /* see Process.wait */
5682 5684
    rb_define_const(rb_mProcess, "WNOHANG", INT2FIX(0));
5683 5685
#endif
5684 5686
#ifdef WUNTRACED
5687
    /* see Process.wait */
5685 5688
    rb_define_const(rb_mProcess, "WUNTRACED", INT2FIX(WUNTRACED));
5686 5689
#else
5690
    /* see Process.wait */
5687 5691
    rb_define_const(rb_mProcess, "WUNTRACED", INT2FIX(0));
5688 5692
#endif
5689 5693

  
......
5737 5741
    rb_define_module_function(rb_mProcess, "setpriority", proc_setpriority, 3);
5738 5742

  
5739 5743
#ifdef HAVE_GETPRIORITY
5744
    /* see Process.setpriority */
5740 5745
    rb_define_const(rb_mProcess, "PRIO_PROCESS", INT2FIX(PRIO_PROCESS));
5746
    /* see Process.setpriority */
5741 5747
    rb_define_const(rb_mProcess, "PRIO_PGRP", INT2FIX(PRIO_PGRP));
5748
    /* see Process.setpriority */
5742 5749
    rb_define_const(rb_mProcess, "PRIO_USER", INT2FIX(PRIO_USER));
5743 5750
#endif
5744 5751

  
......
5750 5757
#ifdef RLIM_SAVED_MAX
5751 5758
	{
5752 5759
	    VALUE v = RLIM_INFINITY == RLIM_SAVED_MAX ? inf : RLIM2NUM(RLIM_SAVED_MAX);
5760
	    /* see Process.setrlimit */
5753 5761
	    rb_define_const(rb_mProcess, "RLIM_SAVED_MAX", v);
5754 5762
	}
5755 5763
#endif
5764
	/* see Process.setrlimit */
5756 5765
        rb_define_const(rb_mProcess, "RLIM_INFINITY", inf);
5757 5766
#ifdef RLIM_SAVED_CUR
5758 5767
	{
5759 5768
	    VALUE v = RLIM_INFINITY == RLIM_SAVED_CUR ? inf : RLIM2NUM(RLIM_SAVED_CUR);
5769
	    /* see Process.setrlimit */
5760 5770
	    rb_define_const(rb_mProcess, "RLIM_SAVED_CUR", v);
5761 5771
	}
5762 5772
#endif
5763 5773
    }
5764 5774
#ifdef RLIMIT_AS
5775
    /* Maximum size of the process's virtual memory (address space) in bytes.
5776
     *
5777
     * see the system getrlimit(2) manual for details.
5778
     */
5765 5779
    rb_define_const(rb_mProcess, "RLIMIT_AS", INT2FIX(RLIMIT_AS));
5766 5780
#endif
5767 5781
#ifdef RLIMIT_CORE
5782
    /* Maximum size of the core file.
5783
     *
5784
     * see the system getrlimit(2) manual for details.
5785
     */
5768 5786
    rb_define_const(rb_mProcess, "RLIMIT_CORE", INT2FIX(RLIMIT_CORE));
5769 5787
#endif
5770 5788
#ifdef RLIMIT_CPU
5789
    /* CPU time limit in seconds.
5790
     *
5791
     * see the system getrlimit(2) manual for details.
5792
     */
5771 5793
    rb_define_const(rb_mProcess, "RLIMIT_CPU", INT2FIX(RLIMIT_CPU));
5772 5794
#endif
5773 5795
#ifdef RLIMIT_DATA
5796
    /* Maximum size of the process's data segment.
5797
     *
5798
     * see the system getrlimit(2) manual for details.
5799
     */
5774 5800
    rb_define_const(rb_mProcess, "RLIMIT_DATA", INT2FIX(RLIMIT_DATA));
5775 5801
#endif
... This diff was truncated because it exceeds the maximum size that can be displayed.