2 libloc - A library to determine the location of someone on the Internet
4 Copyright (C) 2017 IPFire Development Team <info@ipfire.org>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
19 #include <loc/libloc.h>
21 #include <loc/stringpool.h>
23 #include "locationmodule.h"
26 PyObject
* new_as(PyTypeObject
* type
, struct loc_as
* as
) {
27 ASObject
* self
= (ASObject
*)type
->tp_alloc(type
, 0);
29 self
->as
= loc_as_ref(as
);
32 return (PyObject
*)self
;
35 static PyObject
* AS_new(PyTypeObject
* type
, PyObject
* args
, PyObject
* kwds
) {
37 struct loc_stringpool
* pool
;
38 int r
= loc_stringpool_new(loc_ctx
, &pool
);
42 ASObject
* self
= (ASObject
*)type
->tp_alloc(type
, 0);
44 self
->ctx
= loc_ref(loc_ctx
);
48 return (PyObject
*)self
;
51 static void AS_dealloc(ASObject
* self
) {
53 loc_as_unref(self
->as
);
56 loc_stringpool_unref(self
->pool
);
61 Py_TYPE(self
)->tp_free((PyObject
* )self
);
64 static int AS_init(ASObject
* self
, PyObject
* args
, PyObject
* kwargs
) {
67 if (!PyArg_ParseTuple(args
, "i", &number
))
70 // Create the AS object
71 int r
= loc_as_new(self
->ctx
, self
->pool
, &self
->as
, number
);
78 static PyObject
* AS_get_number(ASObject
* self
) {
79 uint32_t number
= loc_as_get_number(self
->as
);
81 return PyLong_FromLong(number
);
84 static PyObject
* AS_get_name(ASObject
* self
) {
85 const char* name
= loc_as_get_name(self
->as
);
87 return PyUnicode_FromString(name
);
90 static struct PyGetSetDef AS_getsetters
[] = {
100 (getter
)AS_get_number
,
108 PyTypeObject ASType
= {
109 PyVarObject_HEAD_INIT(NULL
, 0)
110 tp_name
: "location.AS",
111 tp_basicsize
: sizeof(ASObject
),
112 tp_flags
: Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
,
114 tp_dealloc
: (destructor
)AS_dealloc
,
115 tp_init
: (initproc
)AS_init
,
117 tp_getset
: AS_getsetters
,