![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
github.com/aspose-words-cloud/aspose-words-cloud-go/v2208
/*
*/
package api_test
import ( "bufio" "bytes" "fmt" "io" "os" "path" "path/filepath" "regexp" "runtime" "testing"
"github.com/aspose-words-cloud/aspose-words-cloud-go/v2208/api"
"github.com/aspose-words-cloud/aspose-words-cloud-go/v2208/api/models"
)
func TestReadmeCode(t *testing.T) {
localFilePath := commonTestFile
remoteFolder := path.Join(remoteBaseTestDataFolder, "ReadmeCode")
remoteName := "ReadmeCode.docx"
remotePath := path.Join(remoteFolder, remoteName)
configFilePath := GetConfigFilePath()
// Start README example
// init words cloud api
config, _ := models.NewConfiguration(configFilePath)
wordsApi, ctx, _ := api.CreateWordsApi(config)
// upload test.docx to a cloud
// remote.docx is a name in the cloud
file, _ := os.Open(localFilePath)
uploadRequest := &models.UploadFileRequest{
FileContent: file,
Path: &remotePath,
}
wordsApi.UploadFile(ctx, uploadRequest)
// get a text for the first paragraph of the first section
options := map[string]interface{}{
"folder": remoteFolder,
}
request := &models.GetParagraphsRequest{
Name: &remoteName,
Optionals: options,
}
result, _, _ := wordsApi.GetParagraphs(ctx, request)
fmt.Println(result.Paragraphs.ParagraphLinkList[0].Text)
// End README example
writeToReadme(t)
}
func writeToReadme(t testing.T) { // set regexes startPatern := regexp.MustCompile("^\s// Start README example\s*$") endPattern := regexp.MustCompile("^\s*// End README example\s*$")
// set paths
_, filename, _, _ := runtime.Caller(0)
testFolder := filepath.Dir(filename)
sourcePath := filepath.Join(testFolder, "readme_test.go")
readmePath := filepath.Join(testFolder, "../../README.md")
// read the file
codeLines, err := readLines(sourcePath)
if err != nil {
t.Error(err)
}
// extract example code
var readmeCode []string
skipMode := true
for i := 0; i < len(codeLines); i++ {
if skipMode {
skipMode = !startPatern.Match([]byte(codeLines[i]))
}
if !skipMode {
readmeCode = append(readmeCode, codeLines[i])
skipMode = endPattern.Match([]byte(codeLines[i]))
}
}
if len(readmeCode) < 2 {
t.Error("Code has not found in readme_test.go")
}
// read readme.md
readmeLines, err := readLines(readmePath)
if err != nil {
t.Error(err)
}
// replace example code
var newReadmeLines []string
codeMode := false
for i := 0; i < len(readmeLines); i++ {
if !codeMode {
codeMode = startPatern.Match([]byte(readmeLines[i]))
if codeMode {
newReadmeLines = append(newReadmeLines, readmeCode...)
}
}
if codeMode {
codeMode = !endPattern.Match([]byte(readmeLines[i]))
continue
}
if !codeMode {
newReadmeLines = append(newReadmeLines, readmeLines[i])
}
}
// write new readme
err = writeLines(newReadmeLines, readmePath)
if err != nil {
t.Error(err)
}
}
// Read a whole file into the memory and store it as array of lines func readLines(path string) (lines []string, err error) { var ( file *os.File part []byte prefix bool ) if file, err = os.Open(path); err != nil { return } defer file.Close()
reader := bufio.NewReader(file)
buffer := bytes.NewBuffer(make([]byte, 0))
for {
if part, prefix, err = reader.ReadLine(); err != nil {
break
}
buffer.Write(part)
if !prefix {
lines = append(lines, buffer.String())
buffer.Reset()
}
}
if err == io.EOF {
err = nil
}
return
}
func writeLines(lines []string, path string) (err error) { var ( file *os.File )
if file, err = os.Create(path); err != nil {
return
}
defer file.Close()
for _, item := range lines {
_, err := file.WriteString(item + "\n")
if err != nil {
break
}
}
return
}
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.