Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Move code to subdirectories and rename or split up#1665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
filmor merged 2 commits intopythonnet:masterfromfilmor:move-everything-around
Jan 9, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletionssrc/runtime/Codecs/IPyObjectDecoder.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
namespace Python.Runtime;

using System;

/// <summary>
/// Defines <see cref="PyObject"/> conversion to CLR types (unmarshalling)
/// </summary>
public interface IPyObjectDecoder
{
/// <summary>
/// Checks if this decoder can decode from <paramref name="objectType"/> to <paramref name="targetType"/>
/// </summary>
bool CanDecode(PyType objectType, Type targetType);
/// <summary>
/// Attempts do decode <paramref name="pyObj"/> into a variable of specified type
/// </summary>
/// <typeparam name="T">CLR type to decode into</typeparam>
/// <param name="pyObj">Object to decode</param>
/// <param name="value">The variable, that will receive decoding result</param>
/// <returns></returns>
bool TryDecode<T>(PyObject pyObj, out T? value);
}
18 changes: 18 additions & 0 deletionssrc/runtime/Codecs/IPyObjectEncoder.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
namespace Python.Runtime;

using System;

/// <summary>
/// Defines conversion from CLR objects into Python objects (e.g. <see cref="PyObject"/>) (marshalling)
/// </summary>
public interface IPyObjectEncoder
{
/// <summary>
/// Checks if encoder can encode CLR objects of specified type
/// </summary>
bool CanEncode(Type type);
/// <summary>
/// Attempts to encode CLR object <paramref name="value"/> into Python object
/// </summary>
PyObject? TryEncode(object value);
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,41 +6,8 @@ namespace Python.Runtime
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Python.Runtime.Codecs;

/// <summary>
/// Defines <see cref="PyObject"/> conversion to CLR types (unmarshalling)
/// </summary>
public interface IPyObjectDecoder
{
/// <summary>
/// Checks if this decoder can decode from <paramref name="objectType"/> to <paramref name="targetType"/>
/// </summary>
bool CanDecode(PyType objectType, Type targetType);
/// <summary>
/// Attempts do decode <paramref name="pyObj"/> into a variable of specified type
/// </summary>
/// <typeparam name="T">CLR type to decode into</typeparam>
/// <param name="pyObj">Object to decode</param>
/// <param name="value">The variable, that will receive decoding result</param>
/// <returns></returns>
bool TryDecode<T>(PyObject pyObj, out T? value);
}

/// <summary>
/// Defines conversion from CLR objects into Python objects (e.g. <see cref="PyObject"/>) (marshalling)
/// </summary>
public interface IPyObjectEncoder
{
/// <summary>
/// Checks if encoder can encode CLR objects of specified type
/// </summary>
bool CanEncode(Type type);
/// <summary>
/// Attempts to encode CLR object <paramref name="value"/> into Python object
/// </summary>
PyObject? TryEncode(object value);
}
using Python.Runtime.Codecs;

/// <summary>
/// This class allows to register additional marshalling codecs.
Expand Down
File renamed without changes.
File renamed without changes.
81 changes: 0 additions & 81 deletionssrc/runtime/exceptions.cs → src/runtime/Exceptions.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,87 +5,6 @@

namespace Python.Runtime
{
/// <summary>
/// Base class for Python types that reflect managed exceptions based on
/// System.Exception
/// </summary>
/// <remarks>
/// The Python wrapper for managed exceptions LIES about its inheritance
/// tree. Although the real System.Exception is a subclass of
/// System.Object the Python type for System.Exception does NOT claim that
/// it subclasses System.Object. Instead TypeManager.CreateType() uses
/// Python's exception.Exception class as base class for System.Exception.
/// </remarks>
[Serializable]
internal class ExceptionClassObject : ClassObject
{
internal ExceptionClassObject(Type tp) : base(tp)
{
}

internal static Exception? ToException(BorrowedReference ob)
{
var co = GetManagedObject(ob) as CLRObject;
return co?.inst as Exception;
}

/// <summary>
/// Exception __repr__ implementation
/// </summary>
public new static NewReference tp_repr(BorrowedReference ob)
{
Exception? e = ToException(ob);
if (e == null)
{
return Exceptions.RaiseTypeError("invalid object");
}
string name = e.GetType().Name;
string message;
if (e.Message != String.Empty)
{
message = String.Format("{0}('{1}')", name, e.Message);
}
else
{
message = String.Format("{0}()", name);
}
return Runtime.PyString_FromString(message);
}

/// <summary>
/// Exception __str__ implementation
/// </summary>
public new static NewReference tp_str(BorrowedReference ob)
{
Exception? e = ToException(ob);
if (e == null)
{
return Exceptions.RaiseTypeError("invalid object");
}

string message = e.ToString();
string fullTypeName = e.GetType().FullName;
string prefix = fullTypeName + ": ";
if (message.StartsWith(prefix))
{
message = message.Substring(prefix.Length);
}
else if (message.StartsWith(fullTypeName))
{
message = message.Substring(fullTypeName.Length);
}
return Runtime.PyString_FromString(message);
}

public override bool Init(BorrowedReference obj, BorrowedReference args, BorrowedReference kw)
{
if (!base.Init(obj, args, kw)) return false;

var e = (CLRObject)GetManagedObject(obj)!;

return Exceptions.SetArgsAndCause(obj, (Exception)e.inst);
}
}

/// <summary>
/// Encapsulates the Python exception APIs.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletionssrc/runtime/Python.Runtime.csproj
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,10 +50,10 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="resources\clr.py">
<EmbeddedResource Include="Resources\clr.py">
<LogicalName>clr.py</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="resources\interop.py">
<EmbeddedResource Include="Resources\interop.py">
<LogicalName>interop.py</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="Mixins\*.py" />
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

[8]ページ先頭

©2009-2025 Movatter.jp