Skip to content

Commit f9f08a0

Browse files
committed
Move code to subdirectories and rename or split up
1 parent 7450c5c commit f9f08a0

File tree

113 files changed

+676
-687
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+676
-687
lines changed
File renamed without changes.
File renamed without changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace Python.Runtime;
2+
3+
using System;
4+
5+
/// <summary>
6+
/// Defines <see cref="PyObject"/> conversion to CLR types (unmarshalling)
7+
/// </summary>
8+
public interface IPyObjectDecoder
9+
{
10+
/// <summary>
11+
/// Checks if this decoder can decode from <paramref name="objectType"/> to <paramref name="targetType"/>
12+
/// </summary>
13+
bool CanDecode(PyType objectType, Type targetType);
14+
/// <summary>
15+
/// Attempts do decode <paramref name="pyObj"/> into a variable of specified type
16+
/// </summary>
17+
/// <typeparam name="T">CLR type to decode into</typeparam>
18+
/// <param name="pyObj">Object to decode</param>
19+
/// <param name="value">The variable, that will receive decoding result</param>
20+
/// <returns></returns>
21+
bool TryDecode<T>(PyObject pyObj, out T? value);
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace Python.Runtime;
2+
3+
using System;
4+
5+
/// <summary>
6+
/// Defines conversion from CLR objects into Python objects (e.g. <see cref="PyObject"/>) (marshalling)
7+
/// </summary>
8+
public interface IPyObjectEncoder
9+
{
10+
/// <summary>
11+
/// Checks if encoder can encode CLR objects of specified type
12+
/// </summary>
13+
bool CanEncode(Type type);
14+
/// <summary>
15+
/// Attempts to encode CLR object <paramref name="value"/> into Python object
16+
/// </summary>
17+
PyObject? TryEncode(object value);
18+
}

src/runtime/converterextensions.cs renamed to src/runtime/Codecs/PyObjectConversions.cs

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,8 @@ namespace Python.Runtime
66
using System.Diagnostics;
77
using System.Linq;
88
using System.Reflection;
9-
using Python.Runtime.Codecs;
10-
11-
/// <summary>
12-
/// Defines <see cref="PyObject"/> conversion to CLR types (unmarshalling)
13-
/// </summary>
14-
public interface IPyObjectDecoder
15-
{
16-
/// <summary>
17-
/// Checks if this decoder can decode from <paramref name="objectType"/> to <paramref name="targetType"/>
18-
/// </summary>
19-
bool CanDecode(PyType objectType, Type targetType);
20-
/// <summary>
21-
/// Attempts do decode <paramref name="pyObj"/> into a variable of specified type
22-
/// </summary>
23-
/// <typeparam name="T">CLR type to decode into</typeparam>
24-
/// <param name="pyObj">Object to decode</param>
25-
/// <param name="value">The variable, that will receive decoding result</param>
26-
/// <returns></returns>
27-
bool TryDecode<T>(PyObject pyObj, out T? value);
28-
}
299

30-
/// <summary>
31-
/// Defines conversion from CLR objects into Python objects (e.g. <see cref="PyObject"/>) (marshalling)
32-
/// </summary>
33-
public interface IPyObjectEncoder
34-
{
35-
/// <summary>
36-
/// Checks if encoder can encode CLR objects of specified type
37-
/// </summary>
38-
bool CanEncode(Type type);
39-
/// <summary>
40-
/// Attempts to encode CLR object <paramref name="value"/> into Python object
41-
/// </summary>
42-
PyObject? TryEncode(object value);
43-
}
10+
using Python.Runtime.Codecs;
4411

4512
/// <summary>
4613
/// This class allows to register additional marshalling codecs.
File renamed without changes.
File renamed without changes.

src/runtime/exceptions.cs renamed to src/runtime/Exceptions.cs

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -5,87 +5,6 @@
55

66
namespace Python.Runtime
77
{
8-
/// <summary>
9-
/// Base class for Python types that reflect managed exceptions based on
10-
/// System.Exception
11-
/// </summary>
12-
/// <remarks>
13-
/// The Python wrapper for managed exceptions LIES about its inheritance
14-
/// tree. Although the real System.Exception is a subclass of
15-
/// System.Object the Python type for System.Exception does NOT claim that
16-
/// it subclasses System.Object. Instead TypeManager.CreateType() uses
17-
/// Python's exception.Exception class as base class for System.Exception.
18-
/// </remarks>
19-
[Serializable]
20-
internal class ExceptionClassObject : ClassObject
21-
{
22-
internal ExceptionClassObject(Type tp) : base(tp)
23-
{
24-
}
25-
26-
internal static Exception? ToException(BorrowedReference ob)
27-
{
28-
var co = GetManagedObject(ob) as CLRObject;
29-
return co?.inst as Exception;
30-
}
31-
32-
/// <summary>
33-
/// Exception __repr__ implementation
34-
/// </summary>
35-
public new static NewReference tp_repr(BorrowedReference ob)
36-
{
37-
Exception? e = ToException(ob);
38-
if (e == null)
39-
{
40-
return Exceptions.RaiseTypeError("invalid object");
41-
}
42-
string name = e.GetType().Name;
43-
string message;
44-
if (e.Message != String.Empty)
45-
{
46-
message = String.Format("{0}('{1}')", name, e.Message);
47-
}
48-
else
49-
{
50-
message = String.Format("{0}()", name);
51-
}
52-
return Runtime.PyString_FromString(message);
53-
}
54-
55-
/// <summary>
56-
/// Exception __str__ implementation
57-
/// </summary>
58-
public new static NewReference tp_str(BorrowedReference ob)
59-
{
60-
Exception? e = ToException(ob);
61-
if (e == null)
62-
{
63-
return Exceptions.RaiseTypeError("invalid object");
64-
}
65-
66-
string message = e.ToString();
67-
string fullTypeName = e.GetType().FullName;
68-
string prefix = fullTypeName + ": ";
69-
if (message.StartsWith(prefix))
70-
{
71-
message = message.Substring(prefix.Length);
72-
}
73-
else if (message.StartsWith(fullTypeName))
74-
{
75-
message = message.Substring(fullTypeName.Length);
76-
}
77-
return Runtime.PyString_FromString(message);
78-
}
79-
80-
public override bool Init(BorrowedReference obj, BorrowedReference args, BorrowedReference kw)
81-
{
82-
if (!base.Init(obj, args, kw)) return false;
83-
84-
var e = (CLRObject)GetManagedObject(obj)!;
85-
86-
return Exceptions.SetArgsAndCause(obj, (Exception)e.inst);
87-
}
88-
}
898

909
/// <summary>
9110
/// Encapsulates the Python exception APIs.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)