FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/src/runtime/pytuple.cs at drop-python2 · filmor/pythonnet · GitHub
filmor
/
pythonnet
Public
forked from
pythonnet/pythonnet
Notifications
You must be signed in to change notification settings
Fork
1
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
src
/
runtime
/
pytuple.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
108 lines (97 loc) · 3.18 KB
Breadcrumbs
pythonnet
/
src
/
runtime
/
pytuple.cs
Copy path
File metadata and controls
108 lines (97 loc) · 3.18 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using
System
;
namespace
Python
.
Runtime
{
/// <summary>
/// Represents a Python tuple object. See the documentation at
/// PY2: https://docs.python.org/2/c-api/tupleObjects.html
/// PY3: https://docs.python.org/3/c-api/tupleObjects.html
/// for details.
/// </summary>
public
class
PyTuple
:
PySequence
{
/// <summary>
/// PyTuple Constructor
/// </summary>
/// <remarks>
/// Creates a new PyTuple from an existing object reference. Note
/// that the instance assumes ownership of the object reference.
/// The object reference is not checked for type-correctness.
/// </remarks>
public
PyTuple
(
IntPtr
ptr
)
:
base
(
ptr
)
{
}
/// <summary>
/// PyTuple Constructor
/// </summary>
/// <remarks>
/// Copy constructor - obtain a PyTuple from a generic PyObject. An
/// ArgumentException will be thrown if the given object is not a
/// Python tuple object.
/// </remarks>
public
PyTuple
(
PyObject
o
)
{
if
(
!
IsTupleType
(
o
)
)
{
throw
new
ArgumentException
(
"object is not a tuple"
)
;
}
Runtime
.
XIncref
(
o
.
obj
)
;
obj
=
o
.
obj
;
}
/// <summary>
/// PyTuple Constructor
/// </summary>
/// <remarks>
/// Creates a new empty PyTuple.
/// </remarks>
public
PyTuple
(
)
{
obj
=
Runtime
.
PyTuple_New
(
0
)
;
Runtime
.
CheckExceptionOccurred
(
)
;
}
/// <summary>
/// PyTuple Constructor
/// </summary>
/// <remarks>
/// Creates a new PyTuple from an array of PyObject instances.
/// <para />
/// See caveats about PyTuple_SetItem:
/// https://www.coursehero.com/file/p4j2ogg/important-exceptions-to-this-rule-PyTupleSetItem-and-PyListSetItem-These/
/// </remarks>
public
PyTuple
(
PyObject
[
]
items
)
{
int
count
=
items
.
Length
;
obj
=
Runtime
.
PyTuple_New
(
count
)
;
for
(
var
i
=
0
;
i
<
count
;
i
++
)
{
IntPtr
ptr
=
items
[
i
]
.
obj
;
Runtime
.
XIncref
(
ptr
)
;
Runtime
.
PyTuple_SetItem
(
obj
,
i
,
ptr
)
;
Runtime
.
CheckExceptionOccurred
(
)
;
}
}
/// <summary>
/// IsTupleType Method
/// </summary>
/// <remarks>
/// Returns true if the given object is a Python tuple.
/// </remarks>
public
static
bool
IsTupleType
(
PyObject
value
)
{
return
Runtime
.
PyTuple_Check
(
value
.
obj
)
;
}
/// <summary>
/// AsTuple Method
/// </summary>
/// <remarks>
/// Convert a Python object to a Python tuple if possible, raising
/// a PythonException if the conversion is not possible. This is
/// equivalent to the Python expression "tuple(object)".
/// </remarks>
public
static
PyTuple
AsTuple
(
PyObject
value
)
{
IntPtr
op
=
Runtime
.
PySequence_Tuple
(
value
.
obj
)
;
Runtime
.
CheckExceptionOccurred
(
)
;
return
new
PyTuple
(
op
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL