review fix

This commit is contained in:
Shivaram Lingamneni 2018-06-25 22:50:57 -04:00
parent 2a33c1483b
commit a1bbe0c7f2
4 changed files with 13 additions and 15 deletions

View File

@ -15,12 +15,6 @@ from collections import namedtuple
CapDef = namedtuple("CapDef", ['identifier', 'name', 'url', 'standard'])
CAPDEFS = [
CapDef(
identifier="LabelTagName",
name="draft/label",
url="https://ircv3.net/specs/extensions/labeled-response.html",
standard="draft IRCv3 tag name",
),
CapDef(
identifier="AccountNotify",
name="account-notify",
@ -188,11 +182,13 @@ const (
print(file=output)
print(")", file=output)
print("// `capabilityNames[capab]` is the string name of the capability `capab`", file=output)
print("""var ( capabilityNames = [numCapabs]string{""", file=output)
for capdef in CAPDEFS:
print("\"%s\"," % (capdef.name,), file=output)
print("})", file=output)
# run the generated code through `gofmt -s`, which will print it to stdout
gofmt = subprocess.Popen(['gofmt', '-s'], stdin=subprocess.PIPE)
gofmt.communicate(input=output.getvalue().encode('utf-8'))
if gofmt.poll() != 0:

View File

@ -51,6 +51,12 @@ const (
NegotiatedState State = iota
)
const (
// LabelTagName is the tag name used for the labeled-response spec.
// https://ircv3.net/specs/extensions/labeled-response.html
LabelTagName = "draft/label"
)
func init() {
nameToCapability = make(map[string]Capability)
for capab, name := range capabilityNames {

View File

@ -7,16 +7,12 @@ package caps
const (
// number of recognized capabilities:
numCapabs = 21
numCapabs = 20
// length of the uint64 array that represents the bitset:
bitsetLen = 1
)
const (
// LabelTagName is the draft IRCv3 tag name capability named "draft/label":
// https://ircv3.net/specs/extensions/labeled-response.html
LabelTagName Capability = iota
// AccountNotify is the IRCv3 capability named "account-notify":
// https://ircv3.net/specs/extensions/account-notify-3.1.html
AccountNotify Capability = iota
@ -98,9 +94,9 @@ const (
UserhostInNames Capability = iota
)
// `capabilityNames[capab]` is the string name of the capability `capab`
var (
capabilityNames = [numCapabs]string{
"draft/label",
"account-notify",
"account-tag",
"away-notify",

View File

@ -23,7 +23,7 @@ type ResponseBuffer struct {
// GetLabel returns the label from the given message.
func GetLabel(msg ircmsg.IrcMessage) string {
return msg.Tags[caps.LabelTagName.Name()].Value
return msg.Tags[caps.LabelTagName].Value
}
// NewResponseBuffer returns a new ResponseBuffer.
@ -90,13 +90,13 @@ func (rb *ResponseBuffer) Send() error {
// if label but no batch, add label to first message
if useLabel && batch == nil {
message := rb.messages[0]
message.Tags[caps.LabelTagName.Name()] = ircmsg.MakeTagValue(rb.Label)
message.Tags[caps.LabelTagName] = ircmsg.MakeTagValue(rb.Label)
rb.messages[0] = message
}
// start batch if required
if batch != nil {
batch.Start(rb.target, ircmsg.MakeTags(caps.LabelTagName.Name(), rb.Label))
batch.Start(rb.target, ircmsg.MakeTags(caps.LabelTagName, rb.Label))
}
// send each message out