[#15846] Ruby M17N request — "K.Kosako" <kosako@...>

今書いているライブラリを、あらかじめRuby M17Nに対応させておこうとして、

62 messages 2002/02/04
[#15847] Re: Ruby M17N request — matz@... (Yukihiro Matsumoto) 2002/02/04

まつもと ゆきひろです

[#15854] Re: Ruby M17N request — "K.Kosako" <kosako@...> 2002/02/05

Yukihiro Matsumotoさんの<1012831868.125952.28017.nullmailer@ev.netlab.jp>から

[#16070] Re: Ruby M17N request — "K.Kosako" <kosako@...> 2002/02/25

<20020205045749.0AAA015B@helium.ruby-lang.org>から

[#16072] Re: Ruby M17N request — "Akinori MUSHA" <knu@...> 2002/02/25

At Mon, 25 Feb 2002 19:57:05 +0900,

[#16073] Re: Ruby M17N request — "Akinori MUSHA" <knu@...> 2002/02/25

At Mon, 25 Feb 2002 21:00:46 +0900,

[#16173] Re: Ruby M17N request — "Akinori MUSHA" <knu@...> 2002/03/02

At Mon, 25 Feb 2002 19:57:05 +0900,

[#16196] Oni Guruma imported into our repository — "Akinori MUSHA" <knu@...> 2002/03/04

At Sun, 3 Mar 2002 07:15:40 +0900,

[#16275] Re: Oni Guruma imported into our repository — matz@... (Yukihiro Matsumoto) 2002/03/08

まつもと ゆきひろです

[#16222] Re: Oni Guruma(Re: Ruby M17N request) — nobu.nakada@... 2002/03/05

なかだです。

[#16228] Re: Oni Guruma(Re: Ruby M17N request) — "K.Kosako" <kosako@...> 2002/03/06

nobu.nakada@nifty.ne.jpさんの

[#16237] Re: Oni Guruma(Re: Ruby M17N request) — nobu.nakada@... 2002/03/06

なかだです。

[#16241] Re: Oni Guruma(Re: Ruby M17N request) — "K.Kosako" <kosako@...> 2002/03/07

nobu.nakada@nifty.ne.jpさんの

[#16242] Re: Oni Guruma(Re: Ruby M17N request) — nobu.nakada@... 2002/03/07

なかだです。

[#16442] Re: Oni Guruma(Re: Ruby M17N request) — nobu.nakada@... 2002/03/17

なかだです。

[#15867] [BUG?] include after module definition and extend module — keiju@... (Keiju ISHITSUKA)

けいじゅ@日本ラショナルソフトウェアです.

15 messages 2002/02/08
[#15869] Re: [BUG?] include after module definition and extend module — matz@... (Yukihiro Matsumoto) 2002/02/08

まつもと ゆきひろです

[#15932] Re: [BUG?] include after module definition and extend module — keiju@... (石塚圭樹) 2002/02/18

けいじゅ@日本ラショナルソフトウェアです.

[#15938] Re: [BUG?] include after module definition and extend module — matz@... (Yukihiro Matsumoto) 2002/02/18

まつもと ゆきひろです

[#15914] making net/*.rb grok URI — "Akinori MUSHA" <knu@...>

 net/*.rb モジュール群をぜひとも標準添付となった URI クラスに

30 messages 2002/02/17
[#15915] Re: making net/*.rb grok URI — "Akinori MUSHA" <knu@...> 2002/02/17

At Mon, 18 Feb 2002 04:33:42 +0900,

[#15931] Re: making net/*.rb grok URI — Minero Aoki <aamine@...> 2002/02/18

あおきです。

[#15934] Re: making net/*.rb grok URI — "Akinori MUSHA" <knu@...> 2002/02/18

At Mon, 18 Feb 2002 15:24:22 +0900,

[#15937] Re: making net/*.rb grok URI — Minero Aoki <aamine@...> 2002/02/18

あおきです。

[#15958] Re: making net/*.rb grok URI — TAKAHASHI Masayoshi <maki@...> 2002/02/19

高橋征義です。

[#15978] Re: making net/*.rb grok URI — Tanaka Akira <akr@...17n.org> 2002/02/19

In article <200202190432.NAA18796@mx.inac.co.jp>,

[#16002] Re: making net/*.rb grok URI — TAKAHASHI Masayoshi <maki@...> 2002/02/20

高橋征義です。

[#16013] Re: making net/*.rb grok URI — Tanaka Akira <akr@...17n.org> 2002/02/20

In article <20020221020159R.maki@rubycolor.org>,

[#15988] Re: [rubyist:1097] Re: % 記法 — nobu.nakada@...

なかだです。

21 messages 2002/02/20
[#17594] Re: [rubyist:1097] Re: % 記法 — nobu.nakada@... 2002/06/26

なかだです。

[#16049] defined? autoload constant — Kazuhiro NISHIYAMA <zn@...>

西山和広です。

35 messages 2002/02/24
[#16058] Re: defined? autoload constant — matz@... (Yukihiro Matsumoto) 2002/02/25

まつもと ゆきひろです

[#16298] Re: defined? autoload constant — nobu.nakada@... 2002/03/09

なかだです。

[#16304] Re: defined? autoload constant — matz@... (Yukihiro Matsumoto) 2002/03/09

まつもと ゆきひろです

[#16375] Re: defined? autoload constant — keiju@... (石塚圭樹) 2002/03/14

けいじゅ@日本ラショナルソフトウェアです.

[#16380] Re: defined? autoload constant — nobu.nakada@... 2002/03/14

なかだです。

[#16398] Re: defined? autoload constant — keiju@... (石塚圭樹) 2002/03/14

けいじゅ@日本ラショナルソフトウェアです.

[#16399] Re: defined? autoload constant — nobu.nakada@... 2002/03/14

なかだです。

[#16400] Re: defined? autoload constant — keiju@... (石塚圭樹) 2002/03/14

けいじゅ@日本ラショナルソフトウェアです.

[#16403] Re: defined? autoload constant — matz@... (Yukihiro Matsumoto) 2002/03/14

まつもと ゆきひろです

[#16407] Re: defined? autoload constant — nobu.nakada@... 2002/03/15

なかだです。

[#16409] Re: defined? autoload constant — matz@... (Yukihiro Matsumoto) 2002/03/15

まつもと ゆきひろです

[#16481] Re: defined? autoload constant — keiju@... (石塚圭樹) 2002/03/19

けいじゅ@日本ラショナルソフトウェアです.

[#16482] Re: defined? autoload constant — matz@... (Yukihiro Matsumoto) 2002/03/19

まつもと ゆきひろです

[#16082] Array#select without block — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

14 messages 2002/02/25

[#16102] No trace_func event at if-elsif-else line — "NAKAMURA, Hiroshi" <nakahiro@...>

なひです。

21 messages 2002/02/26
[#16103] Re: No trace_func event at if-elsif-else line — matz@... (Yukihiro Matsumoto) 2002/02/26

まつもと ゆきひろです

[#16109] Re: No trace_func event at if-elsif-else line — "NAKAMURA, Hiroshi" <nakahiro@...> 2002/02/26

なひです。

[#16110] Re: No trace_func event at if-elsif-else line — matz@... (Yukihiro Matsumoto) 2002/02/26

まつもと ゆきひろです

[#16117] Re: No trace_func event at if-elsif-else line — "NAKAMURA, Hiroshi" <nakahiro@...> 2002/02/26

なひです。

[#16127] Re: No trace_func event at if-elsif-else line — matz@... (Yukihiro Matsumoto) 2002/02/26

まつもと ゆきひろです

[#16133] Re: No trace_func event at if-elsif-else line — "NAKAMURA, Hiroshi" <nakahiro@...> 2002/02/27

なひです。

[#16135] Re: No trace_func event at if-elsif-else line — matz@... (Yukihiro Matsumoto) 2002/02/27

まつもと ゆきひろです

[#16256] Rite debug API (was Re: No trace_func event at if-elsif-else line) — "NAKAMURA, Hiroshi" <nakahiro@...> 2002/03/07

なひです。どうせ一年も先の話なのでのんびりと。

[#16258] Re: Rite debug API (was Re: No trace_func event at if-elsif-else line) — matz@... (Yukihiro Matsumoto) 2002/03/07

まつもと ゆきひろです

[#16134] Defining (Python) Source Code Encoding — TAKAHASHI Masayoshi <maki@...>

高橋征義です。ruby-list の「localized document」ともやや関係あり?

13 messages 2002/02/27

[ruby-dev:16015] Re: making net/*.rb grok URI

From: Tanaka Akira <akr@...17n.org>
Date: 2002-02-21 04:31:32 UTC
List: ruby-dev #16015
In article <200202202350.g1KNoc731179@sharui.nakada.kanuma.tochigi.jp>,
  nobu.nakada@nifty.ne.jp writes:

> URI.openでは。

そりゃそうですね。そうしましょう。

でも、Kernel#open の修正にも惹かれるものがあります。open-uri.rb とか別
のファイルがいいのかな。

というわけで適当に作ってみました。
# 難しいところは実装してませんが。

  URI.open("http://www.ruby-lang.org/en/index.html") {|f|
    f.each_line {|line| p line}
    p f.content_type
    p f.content_encoding
    p f.last_modified
  }

というように使えます。

uri/open.rb というように新しいファイルを作るか、あるいは
uri/generic.rb, uri/http.rb, uri/ftp.rb あたりに分けるか、どっちがいい
かはよくわかりません。あと、つい StringIO を使ってしまったので、当然
StringIO が本体に入るまでは本体には入れられません。StringIO を使うとこ
ろを外すということはできますが。rough の uri に入れるかどうかは... や
まださんの意見を聞きたいところです。

少し使って思ったのですが、StringIO と IO で共通に使える size/length と
いうメソッドが欲しいです。中身はそれぞれ self.string.size と
self.stat.size でいいんですが、今は polymorphic に使えるものがありませ
ん。

あと、IO#truncate (とむろん StringIO#truncate)がないことにも気がつきま
した。ftruncate は SUSv2 にもありますから、あってもいいんじゃないかと
思います。これがないとバッファを切り詰められません。

require 'uri'
require 'stringio'
require 'tempfile'

module URI
  def URI.open(uri, *rest, &block)
    uri = URI.parse(uri) if String === uri
    uri.open(*rest, &block)
  end

  def URI.find_proxy(uri)
    name = uri.scheme + '_proxy'
    if proxy_uri = ENV[name] || ENV[name.upcase]
      proxy_uri = URI.parse(proxy_uri)
      name = 'no_proxy'
      if no_proxy = ENV[name] || ENV[name.upcase]
        no_proxy.scan(/([^:,]*)(?::(\d+))?/) {|host, port|
	  if /(\A|\.)#{Regexp.quote host}\z/i =~ proxy_uri.host &&
	     (!port || uri.port == port.to_i)
	    proxy_uri = nil
	    break
	  end
	}
      end
      proxy_uri
    else
      nil
    end
  end

  class HTTP
    def open(&block)
      Buf.open(lambda {|buf|
	require 'net/http'

	if proxy_uri = URI.find_proxy(self)
	  klass = Net::HTTP.Proxy(proxy_uri.host, proxy_uri.port)
	else
	  klass = Net::HTTP
	end

	resp = nil
	klass.start(self.host, self.port) {|http|
	  header = {}
	  resp, = http.get(self.request_uri, header, buf)
	}

	# If Redirection 3xx ...
	# If 401 Unauthorized ...

	unless resp.code == '200'
	  raise StandardError.new("HTTP fetch failed")
	end

	buf.stream.extend HTTPInfo
	buf.stream.init_httpinfo(resp)
      },
      &block)
    end
  end

  class FTP
    def open(&block)
      Buf.open(lambda {|buf|
	if proxy_uri = URI.find_proxy(uri)
	  require 'net/http'

	  resp = nil
	  Net::HTTP.start(proxy_uri.host, proxy_uri.port) {|http|
	    resp, = http.get(uri.to_s, nil, buf)
	  }

	  buf.stream.extend HTTPInfo
	  buf.stream.init_httpinfo(resp)
	else
	  require 'net/ftp'

	  # xxx: extract user/passwd from .netrc.
	  user = 'anonymous'
	  passwd = nil
	  if uri.userinfo
	    user, passwd = uri.userinfo.split(/:/)
	  end

	  ftp = Net::FTP.open(uri.host)
	  ftp.login(user, passwd)
	  ftp.getbinaryfile(uri.path, '/dev/null', Net::FTP::DEFAULT_BLOCKSIZE,
	    lambda {|data| buf << data})
	  ftp.close
	end
      },
      &block)
    end
  end

  module HTTPInfo
    def init_httpinfo(resp)
      @http_resp = resp
    end
    attr_reader :http_resp

    def content_type
      @http_resp['content-type']
    end

    def content_encoding
      @http_resp['content-encoding']
    end

    def last_modified
      if @http_resp.key? 'last-modified'
        require 'time'
        Time.httpdate(@http_resp['last-modified'])
      else
        nil
      end
    end
  end

  class Buf
    def Buf.open(init_contents=nil)
      buf = Buf.new
      if init_contents
	init_contents.call buf
	buf.stream.rewind
      end
      stream = buf.stream
      if block_given?
	begin
	  yield stream
	ensure
	  stream.close
	end
      else
	stream
      end
    end

    def initialize(basename='ruby-uri', size_limit=10240)
      @basename = basename
      @size_limit = size_limit
      @stream = StringIO.new('', 'w+')
      @size = 0
    end
    attr_reader :stream

    def <<(data)
      @size += data.length
      if @size_limit < @size && StringIO === @stream
	f = Tempfile.new(@basename)
	f << @stream.string
	@stream = f
      end
      @stream << data
    end
  end
end

module Kernel
  alias uri_original_open open
  def open(name, *rest, &block)
    if %r{\A(http|ftp)://} =~ name
      URI.open(name, *rest, &block)
    else
      uri_original_open(name, *rest, &block)
    end
  end
end
-- 
[田中 哲][たなか あきら][Tanaka Akira]
「ふえろ! わかめちゃん作戦です$(C⊇」(Little Worker, 桂遊生丸)

In This Thread