diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-12-03 02:17:34 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-12-03 02:17:34 +0000 |
commit | 2fd401c8f190f1fe43e51a7f726f6ed6119a1f96 (patch) | |
tree | 7f76eff391f37fe6467ff4ffbc0c582c9959ea30 /libgo/go/mime | |
parent | 02e9018f1616b23f1276151797216717b3564202 (diff) | |
download | gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.zip gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.tar.gz gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.tar.bz2 |
libgo: Update to weekly.2011-11-02.
From-SVN: r181964
Diffstat (limited to 'libgo/go/mime')
-rw-r--r-- | libgo/go/mime/mediatype.go | 20 | ||||
-rw-r--r-- | libgo/go/mime/mediatype_test.go | 2 | ||||
-rw-r--r-- | libgo/go/mime/multipart/formdata.go | 21 | ||||
-rw-r--r-- | libgo/go/mime/multipart/multipart.go | 19 | ||||
-rw-r--r-- | libgo/go/mime/multipart/multipart_test.go | 11 | ||||
-rw-r--r-- | libgo/go/mime/multipart/writer.go | 20 | ||||
-rw-r--r-- | libgo/go/mime/type.go | 4 |
7 files changed, 48 insertions, 49 deletions
diff --git a/libgo/go/mime/mediatype.go b/libgo/go/mime/mediatype.go index 8ad8004..2bf7978 100644 --- a/libgo/go/mime/mediatype.go +++ b/libgo/go/mime/mediatype.go @@ -6,8 +6,8 @@ package mime import ( "bytes" + "errors" "fmt" - "os" "strings" "unicode" ) @@ -57,23 +57,23 @@ func FormatMediaType(t, sub string, param map[string]string) string { return b.String() } -func checkMediaTypeDisposition(s string) os.Error { +func checkMediaTypeDisposition(s string) error { typ, rest := consumeToken(s) if typ == "" { - return os.NewError("mime: no media type") + return errors.New("mime: no media type") } if rest == "" { return nil } if !strings.HasPrefix(rest, "/") { - return os.NewError("mime: expected slash after first token") + return errors.New("mime: expected slash after first token") } subtype, rest := consumeToken(rest[1:]) if subtype == "" { - return os.NewError("mime: expected token after slash") + return errors.New("mime: expected token after slash") } if rest != "" { - return os.NewError("mime: unexpected content after media subtype") + return errors.New("mime: unexpected content after media subtype") } return nil } @@ -85,7 +85,7 @@ func checkMediaTypeDisposition(s string) os.Error { // to lowercase and trimmed of white space and a non-nil map. // The returned map, params, maps from the lowercase // attribute to the attribute value with its case preserved. -func ParseMediaType(v string) (mediatype string, params map[string]string, err os.Error) { +func ParseMediaType(v string) (mediatype string, params map[string]string, err error) { i := strings.Index(v, ";") if i == -1 { i = len(v) @@ -118,7 +118,7 @@ func ParseMediaType(v string) (mediatype string, params map[string]string, err o return } // Parse error. - return "", nil, os.NewError("mime: invalid media parameter") + return "", nil, errors.New("mime: invalid media parameter") } pmap := params @@ -135,7 +135,7 @@ func ParseMediaType(v string) (mediatype string, params map[string]string, err o } if _, exists := pmap[key]; exists { // Duplicate parameter name is bogus. - return "", nil, os.NewError("mime: duplicate parameter name") + return "", nil, errors.New("mime: duplicate parameter name") } pmap[key] = value v = rest @@ -281,7 +281,7 @@ func consumeMediaParam(v string) (param, value, rest string) { return param, value, rest } -func percentHexUnescape(s string) (string, os.Error) { +func percentHexUnescape(s string) (string, error) { // Count %, check that they're well-formed. percents := 0 for i := 0; i < len(s); { diff --git a/libgo/go/mime/mediatype_test.go b/libgo/go/mime/mediatype_test.go index 884573e..c06f167 100644 --- a/libgo/go/mime/mediatype_test.go +++ b/libgo/go/mime/mediatype_test.go @@ -249,7 +249,7 @@ func TestParseMediaTypeBogus(t *testing.T) { if err == nil { t.Fatalf("expected an error parsing invalid media type; got type %q, params %#v", mt, params) } - if err.String() != "mime: invalid media parameter" { + if err.Error() != "mime: invalid media parameter" { t.Errorf("expected invalid media parameter; got error %q", err) } } diff --git a/libgo/go/mime/multipart/formdata.go b/libgo/go/mime/multipart/formdata.go index d114bfa..d9982e5 100644 --- a/libgo/go/mime/multipart/formdata.go +++ b/libgo/go/mime/multipart/formdata.go @@ -6,6 +6,7 @@ package multipart import ( "bytes" + "errors" "io" "io/ioutil" "net/textproto" @@ -19,7 +20,7 @@ import ( // a Content-Disposition of "form-data". // It stores up to maxMemory bytes of the file parts in memory // and the remainder on disk in temporary files. -func (r *Reader) ReadForm(maxMemory int64) (f *Form, err os.Error) { +func (r *Reader) ReadForm(maxMemory int64) (f *Form, err error) { form := &Form{make(map[string][]string), make(map[string][]*FileHeader)} defer func() { if err != nil { @@ -30,7 +31,7 @@ func (r *Reader) ReadForm(maxMemory int64) (f *Form, err os.Error) { maxValueBytes := int64(10 << 20) // 10 MB is a lot of text. for { p, err := r.NextPart() - if err == os.EOF { + if err == io.EOF { break } if err != nil { @@ -48,12 +49,12 @@ func (r *Reader) ReadForm(maxMemory int64) (f *Form, err os.Error) { if filename == "" { // value, store as string in memory n, err := io.CopyN(&b, p, maxValueBytes) - if err != nil && err != os.EOF { + if err != nil && err != io.EOF { return nil, err } maxValueBytes -= n if maxValueBytes == 0 { - return nil, os.NewError("multipart: message too large") + return nil, errors.New("multipart: message too large") } form.Value[name] = append(form.Value[name], b.String()) continue @@ -65,7 +66,7 @@ func (r *Reader) ReadForm(maxMemory int64) (f *Form, err os.Error) { Header: p.Header, } n, err := io.CopyN(&b, p, maxMemory+1) - if err != nil && err != os.EOF { + if err != nil && err != io.EOF { return nil, err } if n > maxMemory { @@ -102,8 +103,8 @@ type Form struct { } // RemoveAll removes any temporary files associated with a Form. -func (f *Form) RemoveAll() os.Error { - var err os.Error +func (f *Form) RemoveAll() error { + var err error for _, fhs := range f.File { for _, fh := range fhs { if fh.tmpfile != "" { @@ -127,7 +128,7 @@ type FileHeader struct { } // Open opens and returns the FileHeader's associated File. -func (fh *FileHeader) Open() (File, os.Error) { +func (fh *FileHeader) Open() (File, error) { if b := fh.content; b != nil { r := io.NewSectionReader(sliceReaderAt(b), 0, int64(len(b))) return sectionReadCloser{r}, nil @@ -151,13 +152,13 @@ type sectionReadCloser struct { *io.SectionReader } -func (rc sectionReadCloser) Close() os.Error { +func (rc sectionReadCloser) Close() error { return nil } type sliceReaderAt []byte -func (r sliceReaderAt) ReadAt(b []byte, off int64) (int, os.Error) { +func (r sliceReaderAt) ReadAt(b []byte, off int64) (int, error) { if int(off) >= len(r) || off < 0 { return 0, os.EINVAL } diff --git a/libgo/go/mime/multipart/multipart.go b/libgo/go/mime/multipart/multipart.go index d36e9e9..24b0e41 100644 --- a/libgo/go/mime/multipart/multipart.go +++ b/libgo/go/mime/multipart/multipart.go @@ -20,7 +20,6 @@ import ( "io/ioutil" "mime" "net/textproto" - "os" ) // TODO(bradfitz): inline these once the compiler can inline them in @@ -69,7 +68,7 @@ func (p *Part) FileName() string { func (p *Part) parseContentDisposition() { v := p.Header.Get("Content-Disposition") - var err os.Error + var err error p.disposition, p.dispositionParams, err = mime.ParseMediaType(v) if err != nil { p.dispositionParams = emptyParams @@ -90,7 +89,7 @@ func NewReader(reader io.Reader, boundary string) *Reader { } } -func newPart(mr *Reader) (*Part, os.Error) { +func newPart(mr *Reader) (*Part, error) { bp := &Part{ Header: make(map[string][]string), mr: mr, @@ -102,7 +101,7 @@ func newPart(mr *Reader) (*Part, os.Error) { return bp, nil } -func (bp *Part) populateHeaders() os.Error { +func (bp *Part) populateHeaders() error { r := textproto.NewReader(bp.mr.bufReader) header, err := r.ReadMIMEHeader() if err == nil { @@ -113,14 +112,14 @@ func (bp *Part) populateHeaders() os.Error { // Read reads the body of a part, after its headers and before the // next part (if any) begins. -func (bp *Part) Read(p []byte) (n int, err os.Error) { +func (bp *Part) Read(p []byte) (n int, err error) { if bp.buffer.Len() >= len(p) { // Internal buffer of unconsumed data is large enough for // the read request. No need to parse more at the moment. return bp.buffer.Read(p) } peek, err := bp.mr.bufReader.Peek(4096) // TODO(bradfitz): add buffer size accessor - unexpectedEof := err == os.EOF + unexpectedEof := err == io.EOF if err != nil && !unexpectedEof { return 0, fmt.Errorf("multipart: Part Read: %v", err) } @@ -151,7 +150,7 @@ func (bp *Part) Read(p []byte) (n int, err os.Error) { } } n, err = bp.buffer.Read(p) - if err == os.EOF && !foundBoundary { + if err == io.EOF && !foundBoundary { // If the boundary hasn't been reached there's more to // read, so don't pass through an EOF from the buffer err = nil @@ -159,7 +158,7 @@ func (bp *Part) Read(p []byte) (n int, err os.Error) { return } -func (bp *Part) Close() os.Error { +func (bp *Part) Close() error { io.Copy(ioutil.Discard, bp) return nil } @@ -178,7 +177,7 @@ type Reader struct { // NextPart returns the next part in the multipart or an error. // When there are no more parts, the error os.EOF is returned. -func (mr *Reader) NextPart() (*Part, os.Error) { +func (mr *Reader) NextPart() (*Part, error) { if mr.currentPart != nil { mr.currentPart.Close() } @@ -202,7 +201,7 @@ func (mr *Reader) NextPart() (*Part, os.Error) { if hasPrefixThenNewline(line, mr.dashBoundaryDash) { // Expected EOF - return nil, os.EOF + return nil, io.EOF } if expectNewPart { diff --git a/libgo/go/mime/multipart/multipart_test.go b/libgo/go/mime/multipart/multipart_test.go index 38079e5..dd5d7c1 100644 --- a/libgo/go/mime/multipart/multipart_test.go +++ b/libgo/go/mime/multipart/multipart_test.go @@ -10,7 +10,6 @@ import ( "io" "io/ioutil" "json" - "os" "strings" "testing" ) @@ -214,7 +213,7 @@ func testMultipart(t *testing.T, r io.Reader, onlyNewlines bool) { if part != nil { t.Error("Didn't expect a fifth part.") } - if err != os.EOF { + if err != io.EOF { t.Errorf("On fifth part expected os.EOF; got %v", err) } } @@ -259,7 +258,7 @@ func TestVariousTextLineEndings(t *testing.T) { if part != nil { t.Errorf("Unexpected part in test %d", testNum) } - if err != os.EOF { + if err != io.EOF { t.Errorf("On test %d expected os.EOF; got %v", testNum, err) } @@ -273,11 +272,11 @@ type maliciousReader struct { const maxReadThreshold = 1 << 20 -func (mr *maliciousReader) Read(b []byte) (n int, err os.Error) { +func (mr *maliciousReader) Read(b []byte) (n int, err error) { mr.n += len(b) if mr.n >= maxReadThreshold { mr.t.Fatal("too much was read") - return 0, os.EOF + return 0, io.EOF } return len(b), nil } @@ -346,7 +345,7 @@ type slowReader struct { r io.Reader } -func (s *slowReader) Read(p []byte) (int, os.Error) { +func (s *slowReader) Read(p []byte) (int, error) { if len(p) == 0 { return s.r.Read(p) } diff --git a/libgo/go/mime/multipart/writer.go b/libgo/go/mime/multipart/writer.go index 1bff02f..ec70be4 100644 --- a/libgo/go/mime/multipart/writer.go +++ b/libgo/go/mime/multipart/writer.go @@ -7,10 +7,10 @@ package multipart import ( "bytes" "crypto/rand" + "errors" "fmt" "io" "net/textproto" - "os" "strings" ) @@ -54,7 +54,7 @@ func randomBoundary() string { // header. The body of the part should be written to the returned // Writer. After calling CreatePart, any previous part may no longer // be written to. -func (w *Writer) CreatePart(header textproto.MIMEHeader) (io.Writer, os.Error) { +func (w *Writer) CreatePart(header textproto.MIMEHeader) (io.Writer, error) { if w.lastpart != nil { if err := w.lastpart.close(); err != nil { return nil, err @@ -93,7 +93,7 @@ func escapeQuotes(s string) string { // CreateFormFile is a convenience wrapper around CreatePart. It creates // a new form-data header with the provided field name and file name. -func (w *Writer) CreateFormFile(fieldname, filename string) (io.Writer, os.Error) { +func (w *Writer) CreateFormFile(fieldname, filename string) (io.Writer, error) { h := make(textproto.MIMEHeader) h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%s"; filename="%s"`, @@ -104,7 +104,7 @@ func (w *Writer) CreateFormFile(fieldname, filename string) (io.Writer, os.Error // CreateFormField calls CreatePart with a header using the // given field name. -func (w *Writer) CreateFormField(fieldname string) (io.Writer, os.Error) { +func (w *Writer) CreateFormField(fieldname string) (io.Writer, error) { h := make(textproto.MIMEHeader) h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%s"`, escapeQuotes(fieldname))) @@ -112,7 +112,7 @@ func (w *Writer) CreateFormField(fieldname string) (io.Writer, os.Error) { } // WriteField calls CreateFormField and then writes the given value. -func (w *Writer) WriteField(fieldname, value string) os.Error { +func (w *Writer) WriteField(fieldname, value string) error { p, err := w.CreateFormField(fieldname) if err != nil { return err @@ -123,7 +123,7 @@ func (w *Writer) WriteField(fieldname, value string) os.Error { // Close finishes the multipart message and writes the trailing // boundary end line to the output. -func (w *Writer) Close() os.Error { +func (w *Writer) Close() error { if w.lastpart != nil { if err := w.lastpart.close(); err != nil { return err @@ -137,17 +137,17 @@ func (w *Writer) Close() os.Error { type part struct { mw *Writer closed bool - we os.Error // last error that occurred writing + we error // last error that occurred writing } -func (p *part) close() os.Error { +func (p *part) close() error { p.closed = true return p.we } -func (p *part) Write(d []byte) (n int, err os.Error) { +func (p *part) Write(d []byte) (n int, err error) { if p.closed { - return 0, os.NewError("multipart: can't write to finished part") + return 0, errors.New("multipart: can't write to finished part") } n, err = p.mw.w.Write(d) if err != nil { diff --git a/libgo/go/mime/type.go b/libgo/go/mime/type.go index 39bf40e..ce72bb5f 100644 --- a/libgo/go/mime/type.go +++ b/libgo/go/mime/type.go @@ -92,7 +92,7 @@ func TypeByExtension(ext string) string { // AddExtensionType sets the MIME type associated with // the extension ext to typ. The extension should begin with // a leading dot, as in ".html". -func AddExtensionType(ext, typ string) os.Error { +func AddExtensionType(ext, typ string) error { if ext == "" || ext[0] != '.' { return fmt.Errorf(`mime: extension "%s" misses dot`, ext) } @@ -100,7 +100,7 @@ func AddExtensionType(ext, typ string) os.Error { return setExtensionType(ext, typ) } -func setExtensionType(extension, mimeType string) os.Error { +func setExtensionType(extension, mimeType string) error { full, param, err := ParseMediaType(mimeType) if err != nil { return err |