Skip to content

Commit

Permalink
remove x/net codegen dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
lucix-aws committed Jun 14, 2024
1 parent 494f482 commit 51955d2
Show file tree
Hide file tree
Showing 19 changed files with 136 additions and 156 deletions.
7 changes: 1 addition & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@ module github.com/aws/aws-sdk-go

go 1.19

require (
github.com/jmespath/go-jmespath v0.4.0
golang.org/x/net v0.17.0
)

require golang.org/x/text v0.13.0 // indirect
require github.com/jmespath/go-jmespath v0.4.0
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfC
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
125 changes: 64 additions & 61 deletions private/model/api/docstring.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ package api
import (
"bufio"
"encoding/json"
"encoding/xml"
"fmt"
"html"
"io"
"log"
"os"
"regexp"
"strings"

xhtml "golang.org/x/net/html"
"golang.org/x/net/html/atom"
)

type apiDocumentation struct {
Expand Down Expand Up @@ -225,12 +223,17 @@ func getLeadingWhitespace(v string) string {

// generateDoc will generate the proper doc string for html encoded or plain text doc entries.
func generateDoc(htmlSrc string) string {
tokenizer := xhtml.NewTokenizer(strings.NewReader(htmlSrc))
tokenizer := xml.NewDecoder(strings.NewReader(htmlSrc))
tokenizer.Strict = false
tokenizer.AutoClose = xml.HTMLAutoClose
tokenizer.Entity = xml.HTMLEntity

// Some service docstrings are hopelessly malformed. Rather than throwing
// up our hands, the converter will map over as much as it can. If it
// returns an error, we stop there and go with whatever it was able to
// produce.
var builder strings.Builder
if err := encodeHTMLToText(&builder, tokenizer); err != nil {
panic(fmt.Sprintf("failed to generated docs, %v", err))
}

encodeHTMLToText(&builder, tokenizer)
return wrap(strings.Trim(builder.String(), "\n"), 72)
}

Expand All @@ -241,31 +244,30 @@ type stringWriter interface {
WriteString(string) (int, error)
}

func encodeHTMLToText(w stringWriter, z *xhtml.Tokenizer) error {
func encodeHTMLToText(w stringWriter, z *xml.Decoder) error {
encoder := newHTMLTokenEncoder(w)
defer encoder.Flush()

for {
tt := z.Next()
if tt == xhtml.ErrorToken {
if err := z.Err(); err == io.EOF {
return nil
} else if err != nil {
return err
}
tt, err := z.Token()
if err == io.EOF {
return nil
}
if err != nil {
return err
}

if err := encoder.Encode(z.Token()); err != nil {
if err := encoder.Encode(tt); err != nil {
return err
}
}
}

type htmlTokenHandler interface {
OnStartTagToken(xhtml.Token) htmlTokenHandler
OnEndTagToken(xhtml.Token, bool)
OnSelfClosingTagToken(xhtml.Token)
OnTextTagToken(xhtml.Token)
OnStartTagToken(xml.StartElement) htmlTokenHandler
OnEndTagToken(xml.Token, bool)
OnSelfClosingTagToken(xml.Token)
OnTextTagToken(xml.CharData)
}

type htmlTokenEncoder struct {
Expand Down Expand Up @@ -293,29 +295,29 @@ func newHTMLTokenEncoder(w stringWriter) *htmlTokenEncoder {
}

func (e *htmlTokenEncoder) Flush() error {
e.baseHandler.handler.OnEndTagToken(xhtml.Token{Type: xhtml.TextToken}, true)
e.baseHandler.handler.OnEndTagToken(xml.CharData([]byte{}), true)
return nil
}

func (e *htmlTokenEncoder) Encode(token xhtml.Token) error {
func (e *htmlTokenEncoder) Encode(token xml.Token) error {
h := e.baseHandler
if len(e.handlers) != 0 {
h = e.handlers[len(e.handlers)-1]
}

switch token.Type {
case xhtml.StartTagToken:
switch v := token.(type) {
case xml.StartElement:
e.depth++

next := h.handler.OnStartTagToken(token)
next := h.handler.OnStartTagToken(v)
if next != nil {
e.handlers = append(e.handlers, tokenHandlerItem{
handler: next,
depth: e.depth,
})
}

case xhtml.EndTagToken:
case xml.EndElement:
handlerBlockClosing := e.depth == h.depth

h.handler.OnEndTagToken(token, handlerBlockClosing)
Expand All @@ -330,11 +332,12 @@ func (e *htmlTokenEncoder) Encode(token xhtml.Token) error {
e.depth = 0
}

case xhtml.SelfClosingTagToken:
h.handler.OnSelfClosingTagToken(token)
// TODO
////case xml.SelfClosingTagToken:
//// h.handler.OnSelfClosingTagToken(token)

case xhtml.TextToken:
h.handler.OnTextTagToken(token)
case xml.CharData:
h.handler.OnTextTagToken(v)
}

return nil
Expand All @@ -344,11 +347,11 @@ type baseTokenHandler struct {
w stringWriter
}

func (e *baseTokenHandler) OnStartTagToken(token xhtml.Token) htmlTokenHandler { return nil }
func (e *baseTokenHandler) OnEndTagToken(token xhtml.Token, blockClosing bool) {}
func (e *baseTokenHandler) OnSelfClosingTagToken(token xhtml.Token) {}
func (e *baseTokenHandler) OnTextTagToken(token xhtml.Token) {
e.w.WriteString(token.Data)
func (e *baseTokenHandler) OnStartTagToken(token xml.StartElement) htmlTokenHandler { return nil }
func (e *baseTokenHandler) OnEndTagToken(token xml.Token, blockClosing bool) {}
func (e *baseTokenHandler) OnSelfClosingTagToken(token xml.Token) {}
func (e *baseTokenHandler) OnTextTagToken(token xml.CharData) {
e.w.WriteString(string(token))
}

type blockTokenHandler struct {
Expand All @@ -372,27 +375,27 @@ func newBlockTokenHandler(w stringWriter) *blockTokenHandler {
},
}
}
func (e *blockTokenHandler) OnStartTagToken(token xhtml.Token) htmlTokenHandler {
func (e *blockTokenHandler) OnStartTagToken(token xml.StartElement) htmlTokenHandler {
e.started = true
if e.newlineBeforeNextBlock {
e.w.WriteString("\n")
e.newlineBeforeNextBlock = false
}

switch token.DataAtom {
case atom.A:
switch token.Name.Local {
case "a":
return newLinkTokenHandler(e.w, token)
case atom.Ul:
case "ul":
e.w.WriteString("\n")
e.newlineBeforeNextBlock = true
return newListTokenHandler(e.w)

case atom.Div, atom.Dt, atom.P, atom.H1, atom.H2, atom.H3, atom.H4, atom.H5, atom.H6:
case "div", "dt", "p", "h1", "h2", "h3", "h4", "h5", "h6":
e.w.WriteString("\n")
e.newlineBeforeNextBlock = true
return newBlockTokenHandler(e.w)

case atom.Pre, atom.Code:
case "pre", "code":
if e.rootBlock {
e.w.WriteString("\n")
e.w.WriteString(indent)
Expand All @@ -403,7 +406,7 @@ func (e *blockTokenHandler) OnStartTagToken(token xhtml.Token) htmlTokenHandler

return nil
}
func (e *blockTokenHandler) OnEndTagToken(token xhtml.Token, blockClosing bool) {
func (e *blockTokenHandler) OnEndTagToken(token xml.Token, blockClosing bool) {
if !blockClosing {
return
}
Expand All @@ -417,34 +420,34 @@ func (e *blockTokenHandler) OnEndTagToken(token xhtml.Token, blockClosing bool)
e.strBuilder.Reset()
}

func (e *blockTokenHandler) OnTextTagToken(token xhtml.Token) {
func (e *blockTokenHandler) OnTextTagToken(token xml.CharData) {
if e.newlineBeforeNextBlock {
e.w.WriteString("\n")
e.newlineBeforeNextBlock = false
}
if !e.started {
token.Data = strings.TrimLeft(token.Data, " \t\n")
token = xml.CharData(strings.TrimLeft(string(token), " \t\n"))
}
if len(token.Data) != 0 {
if len(token) != 0 {
e.started = true
}
e.baseTokenHandler.OnTextTagToken(token)
}

type linkTokenHandler struct {
baseTokenHandler
linkToken xhtml.Token
linkToken xml.StartElement
}

func newLinkTokenHandler(w stringWriter, token xhtml.Token) *linkTokenHandler {
func newLinkTokenHandler(w stringWriter, token xml.StartElement) *linkTokenHandler {
return &linkTokenHandler{
baseTokenHandler: baseTokenHandler{
w: w,
},
linkToken: token,
}
}
func (e *linkTokenHandler) OnEndTagToken(token xhtml.Token, blockClosing bool) {
func (e *linkTokenHandler) OnEndTagToken(token xml.Token, blockClosing bool) {
if !blockClosing {
return
}
Expand All @@ -467,9 +470,9 @@ func newListTokenHandler(w stringWriter) *listTokenHandler {
},
}
}
func (e *listTokenHandler) OnStartTagToken(token xhtml.Token) htmlTokenHandler {
switch token.DataAtom {
case atom.Li:
func (e *listTokenHandler) OnStartTagToken(token xml.StartElement) htmlTokenHandler {
switch token.Name.Local {
case "li":
if e.items >= 1 {
e.w.WriteString("\n\n")
}
Expand All @@ -479,7 +482,7 @@ func (e *listTokenHandler) OnStartTagToken(token xhtml.Token) htmlTokenHandler {
return nil
}

func (e *listTokenHandler) OnTextTagToken(token xhtml.Token) {
func (e *listTokenHandler) OnTextTagToken(token xml.CharData) {
// Squash whitespace between list and items
}

Expand All @@ -500,14 +503,14 @@ func newListItemTokenHandler(w stringWriter) *listItemTokenHandler {
},
}
}
func (e *listItemTokenHandler) OnStartTagToken(token xhtml.Token) htmlTokenHandler {
switch token.DataAtom {
case atom.P:
func (e *listItemTokenHandler) OnStartTagToken(token xml.StartElement) htmlTokenHandler {
switch token.Name.Local {
case "p":
return newBlockTokenHandler(e.w)
}
return nil
}
func (e *listItemTokenHandler) OnEndTagToken(token xhtml.Token, blockClosing bool) {
func (e *listItemTokenHandler) OnEndTagToken(token xml.Token, blockClosing bool) {
if !blockClosing {
return
}
Expand All @@ -533,18 +536,18 @@ func newTrimSpaceTokenHandler(w stringWriter) *trimSpaceTokenHandler {
},
}
}
func (e *trimSpaceTokenHandler) OnEndTagToken(token xhtml.Token, blockClosing bool) {
func (e *trimSpaceTokenHandler) OnEndTagToken(token xml.Token, blockClosing bool) {
if !blockClosing {
return
}

e.origWriter.WriteString(strings.TrimSpace(e.strBuilder.String()))
}

func getHTMLTokenAttr(attr []xhtml.Attribute, name string) (string, bool) {
func getHTMLTokenAttr(attr []xml.Attr, name string) (string, bool) {
for _, a := range attr {
if strings.EqualFold(a.Key, name) {
return a.Val, true
if strings.EqualFold(a.Name.Local, name) {
return a.Value, true
}
}
return "", false
Expand Down
15 changes: 0 additions & 15 deletions private/protocol/eventstream/eventstreamtest/setup_server.go

This file was deleted.

6 changes: 6 additions & 0 deletions private/protocol/eventstream/eventstreamtest/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ const (
http2StreamError = "stream error: stream ID"
)

func setupServer(server *httptest.Server, useH2 bool) *http.Client {
server.Start()

return nil
}

// ServeEventStream provides serving EventStream messages from a HTTP server to
// the client. The events are sent sequentially to the client without delay.
type ServeEventStream struct {
Expand Down
6 changes: 6 additions & 0 deletions service/acmpca/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 51955d2

Please sign in to comment.