Skip to content

Commit 8f3641d

Browse files
committed
webdav: rename the "etc/internal/xml" import.
There is no semantic change to this commit. A follow-up commit will change this package's behavior, but this preparatory commit will make the follow-up's diff smaller, and less noisy. Change-Id: I12e356fc1f29d3c4a7c3374aab4a1b1eefe01144 Reviewed-on: https://go-review.googlesource.com/21631 Reviewed-by: Andrew Gerrand <[email protected]>
1 parent bcb71dd commit 8f3641d

File tree

2 files changed

+87
-87
lines changed

2 files changed

+87
-87
lines changed

webdav/xml.go

+48-48
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import (
1414
"net/http"
1515
"time"
1616

17-
"golang.org/x/net/webdav/internal/xml"
17+
ixml "golang.org/x/net/webdav/internal/xml"
1818
)
1919

2020
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_lockinfo
2121
type lockInfo struct {
22-
XMLName xml.Name `xml:"lockinfo"`
22+
XMLName ixml.Name `xml:"lockinfo"`
2323
Exclusive *struct{} `xml:"lockscope>exclusive"`
2424
Shared *struct{} `xml:"lockscope>shared"`
2525
Write *struct{} `xml:"locktype>write"`
@@ -33,7 +33,7 @@ type owner struct {
3333

3434
func readLockInfo(r io.Reader) (li lockInfo, status int, err error) {
3535
c := &countingReader{r: r}
36-
if err = xml.NewDecoder(c).Decode(&li); err != nil {
36+
if err = ixml.NewDecoder(c).Decode(&li); err != nil {
3737
if err == io.EOF {
3838
if c.n == 0 {
3939
// An empty body means to refresh the lock.
@@ -88,7 +88,7 @@ func escape(s string) string {
8888
switch s[i] {
8989
case '"', '&', '\'', '<', '>':
9090
b := bytes.NewBuffer(nil)
91-
xml.EscapeText(b, []byte(s))
91+
ixml.EscapeText(b, []byte(s))
9292
return b.String()
9393
}
9494
}
@@ -100,14 +100,14 @@ func escape(s string) string {
100100
// and directives.
101101
// http://www.webdav.org/specs/rfc4918.html#property_values
102102
// http://www.webdav.org/specs/rfc4918.html#xml-extensibility
103-
func next(d *xml.Decoder) (xml.Token, error) {
103+
func next(d *ixml.Decoder) (ixml.Token, error) {
104104
for {
105105
t, err := d.Token()
106106
if err != nil {
107107
return t, err
108108
}
109109
switch t.(type) {
110-
case xml.Comment, xml.Directive, xml.ProcInst:
110+
case ixml.Comment, ixml.Directive, ixml.ProcInst:
111111
continue
112112
default:
113113
return t, nil
@@ -116,31 +116,31 @@ func next(d *xml.Decoder) (xml.Token, error) {
116116
}
117117

118118
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_prop (for propfind)
119-
type propfindProps []xml.Name
119+
type propfindProps []ixml.Name
120120

121121
// UnmarshalXML appends the property names enclosed within start to pn.
122122
//
123123
// It returns an error if start does not contain any properties or if
124124
// properties contain values. Character data between properties is ignored.
125-
func (pn *propfindProps) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
125+
func (pn *propfindProps) UnmarshalXML(d *ixml.Decoder, start ixml.StartElement) error {
126126
for {
127127
t, err := next(d)
128128
if err != nil {
129129
return err
130130
}
131131
switch t.(type) {
132-
case xml.EndElement:
132+
case ixml.EndElement:
133133
if len(*pn) == 0 {
134134
return fmt.Errorf("%s must not be empty", start.Name.Local)
135135
}
136136
return nil
137-
case xml.StartElement:
138-
name := t.(xml.StartElement).Name
137+
case ixml.StartElement:
138+
name := t.(ixml.StartElement).Name
139139
t, err = next(d)
140140
if err != nil {
141141
return err
142142
}
143-
if _, ok := t.(xml.EndElement); !ok {
143+
if _, ok := t.(ixml.EndElement); !ok {
144144
return fmt.Errorf("unexpected token %T", t)
145145
}
146146
*pn = append(*pn, name)
@@ -150,7 +150,7 @@ func (pn *propfindProps) UnmarshalXML(d *xml.Decoder, start xml.StartElement) er
150150

151151
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_propfind
152152
type propfind struct {
153-
XMLName xml.Name `xml:"DAV: propfind"`
153+
XMLName ixml.Name `xml:"DAV: propfind"`
154154
Allprop *struct{} `xml:"DAV: allprop"`
155155
Propname *struct{} `xml:"DAV: propname"`
156156
Prop propfindProps `xml:"DAV: prop"`
@@ -159,7 +159,7 @@ type propfind struct {
159159

160160
func readPropfind(r io.Reader) (pf propfind, status int, err error) {
161161
c := countingReader{r: r}
162-
if err = xml.NewDecoder(&c).Decode(&pf); err != nil {
162+
if err = ixml.NewDecoder(&c).Decode(&pf); err != nil {
163163
if err == io.EOF {
164164
if c.n == 0 {
165165
// An empty body means to propfind allprop.
@@ -190,7 +190,7 @@ func readPropfind(r io.Reader) (pf propfind, status int, err error) {
190190
// See http://www.webdav.org/specs/rfc4918.html#data.model.for.resource.properties
191191
type Property struct {
192192
// XMLName is the fully qualified name that identifies this property.
193-
XMLName xml.Name
193+
XMLName ixml.Name
194194

195195
// Lang is an optional xml:lang attribute.
196196
Lang string `xml:"xml:lang,attr,omitempty"`
@@ -209,8 +209,8 @@ type Property struct {
209209
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_error
210210
// See multistatusWriter for the "D:" namespace prefix.
211211
type xmlError struct {
212-
XMLName xml.Name `xml:"D:error"`
213-
InnerXML []byte `xml:",innerxml"`
212+
XMLName ixml.Name `xml:"D:error"`
213+
InnerXML []byte `xml:",innerxml"`
214214
}
215215

216216
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_propstat
@@ -224,10 +224,10 @@ type propstat struct {
224224

225225
// MarshalXML prepends the "D:" namespace prefix on properties in the DAV: namespace
226226
// before encoding. See multistatusWriter.
227-
func (ps propstat) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
227+
func (ps propstat) MarshalXML(e *ixml.Encoder, start ixml.StartElement) error {
228228
for k, prop := range ps.Prop {
229229
if prop.XMLName.Space == "DAV:" {
230-
prop.XMLName = xml.Name{Space: "", Local: "D:" + prop.XMLName.Local}
230+
prop.XMLName = ixml.Name{Space: "", Local: "D:" + prop.XMLName.Local}
231231
ps.Prop[k] = prop
232232
}
233233
}
@@ -239,7 +239,7 @@ func (ps propstat) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
239239
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_response
240240
// See multistatusWriter for the "D:" namespace prefix.
241241
type response struct {
242-
XMLName xml.Name `xml:"D:response"`
242+
XMLName ixml.Name `xml:"D:response"`
243243
Href []string `xml:"D:href"`
244244
Propstat []propstat `xml:"D:propstat"`
245245
Status string `xml:"D:status,omitempty"`
@@ -264,7 +264,7 @@ type multistatusWriter struct {
264264
responseDescription string
265265

266266
w http.ResponseWriter
267-
enc *xml.Encoder
267+
enc *ixml.Encoder
268268
}
269269

270270
// Write validates and emits a DAV response as part of a multistatus response
@@ -308,14 +308,14 @@ func (w *multistatusWriter) writeHeader() error {
308308
if err != nil {
309309
return err
310310
}
311-
w.enc = xml.NewEncoder(w.w)
312-
return w.enc.EncodeToken(xml.StartElement{
313-
Name: xml.Name{
311+
w.enc = ixml.NewEncoder(w.w)
312+
return w.enc.EncodeToken(ixml.StartElement{
313+
Name: ixml.Name{
314314
Space: "DAV:",
315315
Local: "multistatus",
316316
},
317-
Attr: []xml.Attr{{
318-
Name: xml.Name{Space: "xmlns", Local: "D"},
317+
Attr: []ixml.Attr{{
318+
Name: ixml.Name{Space: "xmlns", Local: "D"},
319319
Value: "DAV:",
320320
}},
321321
})
@@ -329,17 +329,17 @@ func (w *multistatusWriter) close() error {
329329
if w.enc == nil {
330330
return nil
331331
}
332-
var end []xml.Token
332+
var end []ixml.Token
333333
if w.responseDescription != "" {
334-
name := xml.Name{Space: "DAV:", Local: "responsedescription"}
334+
name := ixml.Name{Space: "DAV:", Local: "responsedescription"}
335335
end = append(end,
336-
xml.StartElement{Name: name},
337-
xml.CharData(w.responseDescription),
338-
xml.EndElement{Name: name},
336+
ixml.StartElement{Name: name},
337+
ixml.CharData(w.responseDescription),
338+
ixml.EndElement{Name: name},
339339
)
340340
}
341-
end = append(end, xml.EndElement{
342-
Name: xml.Name{Space: "DAV:", Local: "multistatus"},
341+
end = append(end, ixml.EndElement{
342+
Name: ixml.Name{Space: "DAV:", Local: "multistatus"},
343343
})
344344
for _, t := range end {
345345
err := w.enc.EncodeToken(t)
@@ -353,9 +353,9 @@ func (w *multistatusWriter) close() error {
353353
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_prop (for proppatch)
354354
type proppatchProps []Property
355355

356-
var xmlLangName = xml.Name{Space: "http://www.w3.org/XML/1998/namespace", Local: "lang"}
356+
var xmlLangName = ixml.Name{Space: "http://www.w3.org/XML/1998/namespace", Local: "lang"}
357357

358-
func xmlLang(s xml.StartElement, d string) string {
358+
func xmlLang(s ixml.StartElement, d string) string {
359359
for _, attr := range s.Attr {
360360
if attr.Name == xmlLangName {
361361
return attr.Value
@@ -366,19 +366,19 @@ func xmlLang(s xml.StartElement, d string) string {
366366

367367
type xmlValue []byte
368368

369-
func (v *xmlValue) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
369+
func (v *xmlValue) UnmarshalXML(d *ixml.Decoder, start ixml.StartElement) error {
370370
// The XML value of a property can be arbitrary, mixed-content XML.
371371
// To make sure that the unmarshalled value contains all required
372372
// namespaces, we encode all the property value XML tokens into a
373373
// buffer. This forces the encoder to redeclare any used namespaces.
374374
var b bytes.Buffer
375-
e := xml.NewEncoder(&b)
375+
e := ixml.NewEncoder(&b)
376376
for {
377377
t, err := next(d)
378378
if err != nil {
379379
return err
380380
}
381-
if e, ok := t.(xml.EndElement); ok && e.Name == start.Name {
381+
if e, ok := t.(ixml.EndElement); ok && e.Name == start.Name {
382382
break
383383
}
384384
if err = e.EncodeToken(t); err != nil {
@@ -401,23 +401,23 @@ func (v *xmlValue) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
401401
//
402402
// UnmarshalXML returns an error if start does not contain any properties or if
403403
// property values contain syntactically incorrect XML.
404-
func (ps *proppatchProps) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
404+
func (ps *proppatchProps) UnmarshalXML(d *ixml.Decoder, start ixml.StartElement) error {
405405
lang := xmlLang(start, "")
406406
for {
407407
t, err := next(d)
408408
if err != nil {
409409
return err
410410
}
411411
switch elem := t.(type) {
412-
case xml.EndElement:
412+
case ixml.EndElement:
413413
if len(*ps) == 0 {
414414
return fmt.Errorf("%s must not be empty", start.Name.Local)
415415
}
416416
return nil
417-
case xml.StartElement:
417+
case ixml.StartElement:
418418
p := Property{
419-
XMLName: t.(xml.StartElement).Name,
420-
Lang: xmlLang(t.(xml.StartElement), lang),
419+
XMLName: t.(ixml.StartElement).Name,
420+
Lang: xmlLang(t.(ixml.StartElement), lang),
421421
}
422422
err = d.DecodeElement(((*xmlValue)(&p.InnerXML)), &elem)
423423
if err != nil {
@@ -431,29 +431,29 @@ func (ps *proppatchProps) UnmarshalXML(d *xml.Decoder, start xml.StartElement) e
431431
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_set
432432
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_remove
433433
type setRemove struct {
434-
XMLName xml.Name
434+
XMLName ixml.Name
435435
Lang string `xml:"xml:lang,attr,omitempty"`
436436
Prop proppatchProps `xml:"DAV: prop"`
437437
}
438438

439439
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_propertyupdate
440440
type propertyupdate struct {
441-
XMLName xml.Name `xml:"DAV: propertyupdate"`
441+
XMLName ixml.Name `xml:"DAV: propertyupdate"`
442442
Lang string `xml:"xml:lang,attr,omitempty"`
443443
SetRemove []setRemove `xml:",any"`
444444
}
445445

446446
func readProppatch(r io.Reader) (patches []Proppatch, status int, err error) {
447447
var pu propertyupdate
448-
if err = xml.NewDecoder(r).Decode(&pu); err != nil {
448+
if err = ixml.NewDecoder(r).Decode(&pu); err != nil {
449449
return nil, http.StatusBadRequest, err
450450
}
451451
for _, op := range pu.SetRemove {
452452
remove := false
453453
switch op.XMLName {
454-
case xml.Name{Space: "DAV:", Local: "set"}:
454+
case ixml.Name{Space: "DAV:", Local: "set"}:
455455
// No-op.
456-
case xml.Name{Space: "DAV:", Local: "remove"}:
456+
case ixml.Name{Space: "DAV:", Local: "remove"}:
457457
for _, p := range op.Prop {
458458
if len(p.InnerXML) > 0 {
459459
return nil, http.StatusBadRequest, errInvalidProppatch

0 commit comments

Comments
 (0)