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 static PyObject
* AS_new(PyTypeObject
* type
, PyObject
* args
, PyObject
* kwds
) {
28 struct loc_stringpool
* pool
;
29 int r
= loc_stringpool_new(loc_ctx
, &pool
);
33 ASObject
* self
= (ASObject
*)type
->tp_alloc(type
, 0);
35 self
->ctx
= loc_ref(loc_ctx
);
39 return (PyObject
*)self
;
42 static void AS_dealloc(ASObject
* self
) {
44 loc_as_unref(self
->as
);
47 loc_stringpool_unref(self
->pool
);
52 Py_TYPE(self
)->tp_free((PyObject
* )self
);
55 static int AS_init(ASObject
* self
, PyObject
* args
, PyObject
* kwargs
) {
58 if (!PyArg_ParseTuple(args
, "i", &number
))
61 // Create the AS object
62 int r
= loc_as_new(self
->ctx
, self
->pool
, &self
->as
, number
);
69 static PyObject
* AS_get_number(ASObject
* self
) {
70 uint32_t number
= loc_as_get_number(self
->as
);
72 return PyLong_FromLong(number
);
75 static PyObject
* AS_get_name(ASObject
* self
) {
76 const char* name
= loc_as_get_name(self
->as
);
78 return PyUnicode_FromString(name
);
81 static struct PyGetSetDef AS_getsetters
[] = {
91 (getter
)AS_get_number
,
99 PyTypeObject ASType
= {
100 PyVarObject_HEAD_INIT(NULL
, 0)
101 tp_name
: "location.AS",
102 tp_basicsize
: sizeof(ASObject
),
103 tp_flags
: Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
,
105 tp_dealloc
: (destructor
)AS_dealloc
,
106 tp_init
: (initproc
)AS_init
,
108 tp_getset
: AS_getsetters
,