Use ecgi module instead of cgi
Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja> git-svn-id: file:///srv/svn/repo/chen/trunk@41 32723744-9b23-0b4a-b1da-9b2e968f9461
This commit is contained in:
parent
465ff0d59f
commit
962e87e34f
@ -1,51 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"log"
|
|
||||||
"gopkg.in/ini.v1"
|
|
||||||
|
|
||||||
"git.chaotic.ninja/yakumo_izuru/chen"
|
|
||||||
"github.com/jbuchbinder/go-xmppbot"
|
|
||||||
)
|
|
||||||
|
|
||||||
var config struct {
|
|
||||||
jid string
|
|
||||||
password string
|
|
||||||
prefix string
|
|
||||||
nick string
|
|
||||||
autojoin string
|
|
||||||
}
|
|
||||||
|
|
||||||
var confFile string
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
flag.StringVar(&confFile, "f", "", "Configuration file")
|
|
||||||
}
|
|
||||||
|
|
||||||
func readConf(file string) error {
|
|
||||||
cfg, err := ini.Load(file)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
config.jid = cfg.Section("chen").Key("jid").String()
|
|
||||||
config.password = cfg.Section("chen").Key("password").String()
|
|
||||||
config.prefix = cfg.Section("chen").Key("prefix").String()
|
|
||||||
config.nick = cfg.Section("chen").Key("nick").String()
|
|
||||||
config.autojoin = cfg.Section("chen").Key("autojoin").String()
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Parse()
|
|
||||||
if confFile != "" {
|
|
||||||
log.Println("Loading configuration file for Chen")
|
|
||||||
readConf(confFile)
|
|
||||||
} else {
|
|
||||||
log.Fatal("No configuration file has been provided")
|
|
||||||
}
|
|
||||||
log.Printf("Chen v%s starting with config %s\n", chen.FullVersion(), confFile)
|
|
||||||
}
|
|
13
go.mod
13
go.mod
@ -1,13 +0,0 @@
|
|||||||
module git.chaotic.ninja/yakumo_izuru/chen
|
|
||||||
|
|
||||||
go 1.20
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/jbuchbinder/go-xmppbot v0.0.0-20201202211837-603b6f40c1d1
|
|
||||||
gopkg.in/ini.v1 v1.67.0
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/mattn/go-xmpp v0.0.0-20190124093244-6093f50721ed // indirect
|
|
||||||
github.com/stretchr/testify v1.9.0 // indirect
|
|
||||||
)
|
|
11
go.sum
11
go.sum
@ -1,11 +0,0 @@
|
|||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/jbuchbinder/go-xmppbot v0.0.0-20201202211837-603b6f40c1d1 h1:D/19k3fV0YtcD2fot8lEqgPbY4xtRD+rck/IgWE23Z4=
|
|
||||||
github.com/jbuchbinder/go-xmppbot v0.0.0-20201202211837-603b6f40c1d1/go.mod h1:eWgqRsgB8cZqUd3VM03fsFR5Xmzqto5148/GO6WLPBk=
|
|
||||||
github.com/mattn/go-xmpp v0.0.0-20190124093244-6093f50721ed h1:A1hEQg5M0b3Wg06pm3q/B0wdZsPjVQ/a2IgauQ8wCZo=
|
|
||||||
github.com/mattn/go-xmpp v0.0.0-20190124093244-6093f50721ed/go.mod h1:Cs5mF0OsrRRmhkyOod//ldNPOwJsrBvJ+1WRspv0xoc=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
|
||||||
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
|
||||||
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|
4
main.py
4
main.py
@ -11,7 +11,7 @@ from collections import defaultdict
|
|||||||
from slixmpp import ClientXMPP
|
from slixmpp import ClientXMPP
|
||||||
from urllib.parse import urlparse, parse_qs, urlunparse
|
from urllib.parse import urlparse, parse_qs, urlunparse
|
||||||
from pantomime import normalize_mimetype
|
from pantomime import normalize_mimetype
|
||||||
import cgi
|
import ecgi
|
||||||
|
|
||||||
parser = "html.parser"
|
parser = "html.parser"
|
||||||
user_agent = "Mozilla/5.0 (X11; Linux x86_64; rv:10.0)"
|
user_agent = "Mozilla/5.0 (X11; Linux x86_64; rv:10.0)"
|
||||||
@ -124,7 +124,7 @@ class ChenBot(ClientXMPP):
|
|||||||
content_disposition = r.headers.get("content-disposition")
|
content_disposition = r.headers.get("content-disposition")
|
||||||
filename = None
|
filename = None
|
||||||
if content_disposition:
|
if content_disposition:
|
||||||
_, params = cgi.parse_header(content_disposition)
|
_, params = ecgi.parse_header(content_disposition)
|
||||||
filename = params.get("filename")
|
filename = params.get("filename")
|
||||||
else:
|
else:
|
||||||
filename = os.path.basename(uri.path)
|
filename = os.path.basename(uri.path)
|
||||||
|
@ -3,3 +3,4 @@ slixmpp
|
|||||||
beautifulsoup4
|
beautifulsoup4
|
||||||
pantomime
|
pantomime
|
||||||
aiohttp
|
aiohttp
|
||||||
|
git+https://git.chaotic.ninja/yakumo.izuru/ecgi#egg=ecgi
|
||||||
|
50
version.go
50
version.go
@ -1,50 +0,0 @@
|
|||||||
package chen
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"runtime/debug"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
defaultVersion = "0.0.0"
|
|
||||||
defaultCommit = "HEAD"
|
|
||||||
defaultBuild = "0000-01-01:00:00+00:00"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// Version is the tagged release version in the form <major>.<minor>.<patch>
|
|
||||||
// following semantic versioning and is overwritten by the build system.
|
|
||||||
Version = defaultVersion
|
|
||||||
|
|
||||||
// Commit is the commit sha of the build (normally from Git) and is overwritten
|
|
||||||
// by the build system.
|
|
||||||
Commit = defaultCommit
|
|
||||||
|
|
||||||
// Build is the date and time of the build as an RFC3339 formatted string
|
|
||||||
// and is overwritten by the build system.
|
|
||||||
Build = defaultBuild
|
|
||||||
)
|
|
||||||
|
|
||||||
// FullVersion display the full version and build
|
|
||||||
func FullVersion() string {
|
|
||||||
var sb strings.Builder
|
|
||||||
|
|
||||||
isDefault := Version == defaultVersion && Commit == defaultCommit && Build == defaultBuild
|
|
||||||
|
|
||||||
if !isDefault {
|
|
||||||
sb.WriteString(fmt.Sprintf("%s@%s %s", Version, Commit, Build))
|
|
||||||
}
|
|
||||||
|
|
||||||
if info, ok := debug.ReadBuildInfo(); ok {
|
|
||||||
if isDefault {
|
|
||||||
sb.WriteString(fmt.Sprintf(" %s", info.Main.Version))
|
|
||||||
}
|
|
||||||
sb.WriteString(fmt.Sprintf(" %s", info.GoVersion))
|
|
||||||
if info.Main.Sum != "" {
|
|
||||||
sb.WriteString(fmt.Sprintf(" %s", info.Main.Sum))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return sb.String()
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user