summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2009-07-17 16:07:03 +0200
committerJulian Andres Klode <jak@debian.org>2009-07-17 16:07:03 +0200
commitb34e27d4ebaf325df6d82fde17b28cf9a008dbfc (patch)
treeb46a775144473e2bf2fbea051e54096335f0e405 /python
parentb63d93492cba1ffd11454ab37e751ef6f938ff96 (diff)
downloadpython-apt-b34e27d4ebaf325df6d82fde17b28cf9a008dbfc.tar.gz
python: Use PyString_FromFormat instead of snprintf.
Diffstat (limited to 'python')
-rw-r--r--python/acquire.cc5
-rw-r--r--python/cache.cc67
-rw-r--r--python/generic.h1
-rw-r--r--python/hashstring.cc5
-rw-r--r--python/indexfile.cc5
-rw-r--r--python/metaindex.cc11
6 files changed, 40 insertions, 54 deletions
diff --git a/python/acquire.cc b/python/acquire.cc
index 05429d1b..50bdc949 100644
--- a/python/acquire.cc
+++ b/python/acquire.cc
@@ -287,8 +287,8 @@ static PyObject *AcquireItemRepr(PyObject *Self)
pkgAcquire::Item *Itm = acquireitem_tocpp(Self);
if (Itm == 0)
return 0;
- char S[300];
- snprintf(S,sizeof(S),"<%s object: "
+
+ return PyString_FromFormat("<%s object: "
"Status: %i Complete: %i Local: %i IsTrusted: %i "
"FileSize: %lu DestFile:'%s' "
"DescURI: '%s' ID:%lu ErrorText: '%s'>",
@@ -296,7 +296,6 @@ static PyObject *AcquireItemRepr(PyObject *Self)
Itm->Status, Itm->Complete, Itm->Local, Itm->IsTrusted(),
Itm->FileSize, Itm->DestFile.c_str(), Itm->DescURI().c_str(),
Itm->ID,Itm->ErrorText.c_str());
- return PyString_FromString(S);
}
static void AcquireItemDealloc(PyObject *self) {
diff --git a/python/cache.cc b/python/cache.cc
index c160cf69..c1f9eb2b 100644
--- a/python/cache.cc
+++ b/python/cache.cc
@@ -228,7 +228,7 @@ static PyObject *CacheMapOp(PyObject *Self,PyObject *Arg)
const char *Name = PyObject_AsString(Arg);
if (Name == NULL)
return 0;
-
+
// Search for the package
pkgCache::PkgIterator Pkg = Cache->FindPkg(Name);
@@ -534,11 +534,9 @@ static PyObject *PackageRepr(PyObject *Self)
{
pkgCache::PkgIterator &Pkg = GetCpp<pkgCache::PkgIterator>(Self);
- char S[300];
- snprintf(S,sizeof(S),"<pkgCache::Package object: Name:'%s' Section: '%s'"
- " ID:%u Flags:0x%lX>",
- Pkg.Name(),Pkg.Section(),Pkg->ID,Pkg->Flags);
- return PyString_FromString(S);
+ return PyString_FromFormat("<%s object: name:'%s' section: "
+ "'%s' id:%u>", Self->ob_type->tp_name,
+ Pkg.Name(), Pkg.Section(), Pkg->ID);
}
PyTypeObject PyPackage_Type =
@@ -621,12 +619,9 @@ static PyGetSetDef DescriptionGetSet[] = {
static PyObject *DescriptionRepr(PyObject *Self)
{
pkgCache::DescIterator &Desc = GetCpp<pkgCache::DescIterator>(Self);
-
- char S[300];
- snprintf(S,sizeof(S),
- "<pkgCache::Description object: language_code:'%s' md5:'%s' ",
- Desc.LanguageCode(), Desc.md5());
- return PyString_FromString(S);
+ return PyString_FromFormat("<%s object: language_code:'%s' md5:'%s' ",
+ Self->ob_type->tp_name, Desc.LanguageCode(),
+ Desc.md5());
}
PyTypeObject PyDescription_Type =
@@ -840,15 +835,14 @@ static PyObject *VersionGetIsTrusted(PyObject *Self, void*) {
static PyObject *VersionRepr(PyObject *Self)
{
pkgCache::VerIterator &Ver = GetCpp<pkgCache::VerIterator>(Self);
-
- char S[300];
- snprintf(S,sizeof(S),"<apt_pkg.Version object: Pkg:'%s' Ver:'%s' "
- "Section:'%s' Arch:'%s' Size:%lu ISize:%lu Hash:%u "
- "ID:%u Priority:%u>",
- Ver.ParentPkg().Name(),Ver.VerStr(),Ver.Section(),Ver.Arch(),
- (unsigned long)Ver->Size,(unsigned long)Ver->InstalledSize,
- Ver->Hash,Ver->ID,Ver->Priority);
- return PyString_FromString(S);
+ return PyString_FromFormat("<%s object: Pkg:'%s' Ver:'%s' Section:'%s' "
+ " Arch:'%s' Size:%lu ISize:%lu Hash:%u ID:%u "
+ "Priority:%u>", Self->ob_type->tp_name,
+ Ver.ParentPkg().Name(), Ver.VerStr(),
+ Ver.Section(), Ver.Arch(),
+ (unsigned long)Ver->Size,
+ (unsigned long)Ver->InstalledSize,
+ Ver->Hash, Ver->ID, Ver->Priority);
}
static PyGetSetDef VersionGetSet[] = {
@@ -1004,20 +998,22 @@ static PyObject *PackageFile_GetID(PyObject *Self,void*)
return Py_BuildValue("i",File->ID);
}
+#define S(s) (s == NULL ? "" : s)
static PyObject *PackageFileRepr(PyObject *Self)
{
pkgCache::PkgFileIterator &File = GetCpp<pkgCache::PkgFileIterator>(Self);
- char S[300];
- snprintf(S,sizeof(S),"<apt_pkg.PackageFile object: "
- "File:'%s' a=%s,c=%s,v=%s,o=%s,l=%s "
- "Arch='%s' Site='%s' IndexType='%s' Size=%lu "
- "Flags=0x%lX ID:%u>",
- File.FileName(),File.Archive(),File.Component(),File.Version(),
- File.Origin(),File.Label(),File.Architecture(),File.Site(),
- File.IndexType(),File->Size,File->Flags,File->ID);
- return PyString_FromString(S);
+ return PyString_FromFormat("<%s object: filename:'%s'"
+ " a=%s,c=%s,v=%s,o=%s,l=%s arch='%s' site='%s'"
+ " IndexType='%s' Size=%lu ID:%u>",
+ Self->ob_type->tp_name, File.FileName(),
+ S(File.Archive()),
+ S(File.Component()),S(File.Version()),
+ S(File.Origin()),S(File.Label()),
+ S(File.Architecture()),S(File.Site()),
+ S(File.IndexType()),File->Size,File->ID);
}
+#undef S
static PyGetSetDef PackageFileGetSet[] = {
{(char*)"architecture",PackageFile_GetArchitecture},
@@ -1089,13 +1085,10 @@ static PyObject *DependencyRepr(PyObject *Self)
{
pkgCache::DepIterator &Dep = GetCpp<pkgCache::DepIterator>(Self);
- char S[300];
- snprintf(S,sizeof(S),"<pkgCache::Dependency object: "
- "Pkg:'%s' Ver:'%s' Comp:'%s'>",
- Dep.TargetPkg().Name(),
- (Dep.TargetVer() == 0?"":Dep.TargetVer()),
- Dep.CompType());
- return PyString_FromString(S);
+ return PyString_FromFormat("<%s object: pkg:'%s' ver:'%s' comp:'%s'>",
+ Self->ob_type->tp_name, Dep.TargetPkg().Name(),
+ (Dep.TargetVer() == 0?"":Dep.TargetVer()),
+ Dep.CompType());
}
static PyObject *DepSmartTargetPkg(PyObject *Self,PyObject *Args)
diff --git a/python/generic.h b/python/generic.h
index 7f3a3809..4a55e9bf 100644
--- a/python/generic.h
+++ b/python/generic.h
@@ -53,6 +53,7 @@ typedef int Py_ssize_t;
#define PyString_FromString PyUnicode_FromString
#define PyString_FromStringAndSize PyUnicode_FromStringAndSize
#define PyString_AsString PyUnicode_AsString
+#define PyString_FromFormat PyUnicode_FromFormat
#define PyInt_Check PyLong_Check
#define PyInt_AsLong PyLong_AsLong
// Force 0.7 compatibility to be off in Python 3 builds
diff --git a/python/hashstring.cc b/python/hashstring.cc
index b76dc127..a8d97cd8 100644
--- a/python/hashstring.cc
+++ b/python/hashstring.cc
@@ -42,9 +42,8 @@ static PyObject *HashString_NEW(PyTypeObject *type,PyObject *Args,
static PyObject *HashString_Repr(PyObject *self)
{
HashString *hash = GetCpp<HashString*>(self);
- char repr[100];
- sprintf(repr, "<%s: \"%s\">", self->ob_type->tp_name, hash->toStr().c_str());
- return PyString_FromString(repr);
+ return PyString_FromFormat("<%s object: \"%s\">", self->ob_type->tp_name,
+ hash->toStr().c_str());
}
static PyObject *HashString_ToStr(PyObject *self)
diff --git a/python/indexfile.cc b/python/indexfile.cc
index 7bf646d0..74345ec9 100644
--- a/python/indexfile.cc
+++ b/python/indexfile.cc
@@ -58,16 +58,13 @@ static PyObject *PackageIndexFileGetIsTrusted(PyObject *Self,void*) {
static PyObject *PackageIndexFileRepr(PyObject *Self)
{
pkgIndexFile *File = GetCpp<pkgIndexFile*>(Self);
-
- char S[1024];
- snprintf(S,sizeof(S),"<pkIndexFile object: "
+ return PyString_FromFormat("<pkIndexFile object: "
"Label:'%s' Describe='%s' Exists='%i' "
"HasPackages='%i' Size='%lu' "
"IsTrusted='%i' ArchiveURI='%s'>",
File->GetType()->Label, File->Describe().c_str(), File->Exists(),
File->HasPackages(), File->Size(),
File->IsTrusted(), File->ArchiveURI("").c_str());
- return PyString_FromString(S);
}
static PyGetSetDef PackageIndexFileGetSet[] = {
diff --git a/python/metaindex.cc b/python/metaindex.cc
index d67c0ada..62ff6b90 100644
--- a/python/metaindex.cc
+++ b/python/metaindex.cc
@@ -64,13 +64,10 @@ static PyGetSetDef MetaIndexGetSet[] = {
static PyObject *MetaIndexRepr(PyObject *Self)
{
metaIndex *meta = GetCpp<metaIndex*>(Self);
-
- char S[1024];
- snprintf(S,sizeof(S),"<apt_pkg.MetaIndex object: "
- "Type='%s', URI:'%s' Dist='%s' IsTrusted='%i'>",
- meta->GetType(), meta->GetURI().c_str(), meta->GetDist().c_str(),
- meta->IsTrusted());
- return PyString_FromString(S);
+ return PyString_FromFormat("<%s object: type='%s', uri:'%s' dist='%s' "
+ "is_trusted='%i'>", Self->ob_type->tp_name,
+ meta->GetType(), meta->GetURI().c_str(),
+ meta->GetDist().c_str(), meta->IsTrusted());
}
PyTypeObject PyMetaIndex_Type =