FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Simplify __repr__ implementations by using “%R” · httpsgithu/frida-python@12f1fdc · GitHub

Repository navigation

Commit 12f1fdc

Browse files
committed
Simplify __repr__ implementations by using “%R”
1 parent 4b2a512 commit 12f1fdc

1 file changed

Lines changed: 22 additions & 49 deletions

File tree

‎src/_frida.c‎

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,22 +2726,10 @@ PyDevice_dealloc (PyDevice * self)
27262726
static PyObject *
27272727
PyDevice_repr (PyDevice * self)
27282728
{
2729-
PyObject * id_bytes, * name_bytes, * type_bytes, * result;
2730-
2731-
id_bytes = PyUnicode_AsUTF8String (self->id);
2732-
name_bytes = PyUnicode_AsUTF8String (self->name);
2733-
type_bytes = PyUnicode_AsUTF8String (self->type);
2734-
2735-
result = PyRepr_FromFormat ("Device(id=\"%s\", name=\"%s\", type='%s')",
2736-
PyBytes_AsString (id_bytes),
2737-
PyBytes_AsString (name_bytes),
2738-
PyBytes_AsString (type_bytes));
2739-
2740-
Py_XDECREF (type_bytes);
2741-
Py_XDECREF (name_bytes);
2742-
Py_XDECREF (id_bytes);
2743-
2744-
return result;
2729+
return PyRepr_FromFormat ("Device(id=%R, name=%R, type=%R)",
2730+
self->id,
2731+
self->name,
2732+
self->type);
27452733
}
27462734

27472735
static PyObject *
@@ -3270,28 +3258,22 @@ PyApplication_dealloc (PyApplication * self)
32703258
static PyObject *
32713259
PyApplication_repr (PyApplication * self)
32723260
{
3273-
PyObject * identifier_bytes, * name_bytes, * result;
3274-
3275-
identifier_bytes = PyUnicode_AsUTF8String (self->identifier);
3276-
name_bytes = PyUnicode_AsUTF8String (self->name);
3261+
PyObject * result;
32773262

32783263
if (self->pid != 0)
32793264
{
3280-
result = PyRepr_FromFormat ("Application(identifier=\"%s\", name=\"%s\", pid=%u)",
3281-
PyBytes_AsString (identifier_bytes),
3282-
PyBytes_AsString (name_bytes),
3265+
result = PyRepr_FromFormat ("Application(identifier=%R, name=%R, pid=%u)",
3266+
self->identifier,
3267+
self->name,
32833268
self->pid);
32843269
}
32853270
else
32863271
{
3287-
result = PyRepr_FromFormat ("Application(identifier=\"%s\", name=\"%s\")",
3288-
PyBytes_AsString (identifier_bytes),
3289-
PyBytes_AsString (name_bytes));
3272+
result = PyRepr_FromFormat ("Application(identifier=%R, name=%R)",
3273+
self->identifier,
3274+
self->name);
32903275
}
32913276

3292-
Py_XDECREF (name_bytes);
3293-
Py_XDECREF (identifier_bytes);
3294-
32953277
return result;
32963278
}
32973279

@@ -3344,17 +3326,9 @@ PyProcess_dealloc (PyProcess * self)
33443326
static PyObject *
33453327
PyProcess_repr (PyProcess * self)
33463328
{
3347-
PyObject * name_bytes, * result;
3348-
3349-
name_bytes = PyUnicode_AsUTF8String (self->name);
3350-
3351-
result = PyRepr_FromFormat ("Process(pid=%u, name=\"%s\")",
3329+
return PyRepr_FromFormat ("Process(pid=%u, name=%R)",
33523330
self->pid,
3353-
PyBytes_AsString (name_bytes));
3354-
3355-
Py_XDECREF (name_bytes);
3356-
3357-
return result;
3331+
self->name);
33583332
}
33593333

33603334
static PyObject *
@@ -3410,15 +3384,9 @@ PySpawn_repr (PySpawn * self)
34103384

34113385
if (self->identifier != Py_None)
34123386
{
3413-
PyObject * identifier_bytes;
3414-
3415-
identifier_bytes = PyUnicode_AsUTF8String (self->identifier);
3416-
3417-
result = PyRepr_FromFormat ("Spawn(pid=%u, identifier=\"%s\")",
3387+
result = PyRepr_FromFormat ("Spawn(pid=%u, identifier=%R)",
34183388
self->pid,
3419-
PyBytes_AsString (identifier_bytes));
3420-
3421-
Py_XDECREF (identifier_bytes);
3389+
self->identifier);
34223390
}
34233391
else
34243392
{
@@ -3660,7 +3628,11 @@ PyIcon_dealloc (PyIcon * self)
36603628
static PyObject *
36613629
PyIcon_repr (PyIcon * self)
36623630
{
3663-
return PyRepr_FromFormat ("Icon(width=%d, height=%d, rowstride=%d, pixels=<%zd bytes>)", self->width, self->height, self->rowstride, PyBytes_Size (self->pixels));
3631+
return PyRepr_FromFormat ("Icon(width=%d, height=%d, rowstride=%d, pixels=<%zd bytes>)",
3632+
self->width,
3633+
self->height,
3634+
self->rowstride,
3635+
PyBytes_Size (self->pixels));
36643636
}
36653637

36663638

@@ -3735,7 +3707,8 @@ PySession_init_from_handle (PySession * self, FridaSession * handle)
37353707
static PyObject *
37363708
PySession_repr (PySession * self)
37373709
{
3738-
return PyRepr_FromFormat ("Session(pid=%u)", self->pid);
3710+
return PyRepr_FromFormat ("Session(pid=%u)",
3711+
self->pid);
37393712
}
37403713

37413714
static PyObject *

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL