| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,35 +1,35 @@ | |||
| 1 | - @ECHO OFF | ||
| 2 | - | ||
| 3 | - pushd %~dp0 | ||
| 4 | - | ||
| 5 | - REM Command file for Sphinx documentation | ||
| 6 | - | ||
| 7 | - if "%SPHINXBUILD%" == "" ( | ||
| 8 | - set SPHINXBUILD=sphinx-build | ||
| 9 | - ) | ||
| 10 | - set SOURCEDIR=source | ||
| 11 | - set BUILDDIR=build | ||
| 12 | - | ||
| 13 | - %SPHINXBUILD% >NUL 2>NUL | ||
| 14 | - if errorlevel 9009 ( | ||
| 15 | - echo. | ||
| 16 | - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx | ||
| 17 | - echo.installed, then set the SPHINXBUILD environment variable to point | ||
| 18 | - echo.to the full path of the 'sphinx-build' executable. Alternatively you | ||
| 19 | - echo.may add the Sphinx directory to PATH. | ||
| 20 | - echo. | ||
| 21 | - echo.If you don't have Sphinx installed, grab it from | ||
| 22 | - echo.https://www.sphinx-doc.org/ | ||
| 23 | - exit /b 1 | ||
| 24 | - ) | ||
| 25 | - | ||
| 26 | - if "%1" == "" goto help | ||
| 27 | - | ||
| 28 | - %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% | ||
| 29 | - goto end | ||
| 30 | - | ||
| 31 | - :help | ||
| 32 | - %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% | ||
| 33 | - | ||
| 34 | - :end | ||
| 35 | - popd | ||
| 1 | + @ECHO OFF | ||
| 2 | + | ||
| 3 | + pushd %~dp0 | ||
| 4 | + | ||
| 5 | + REM Command file for Sphinx documentation | ||
| 6 | + | ||
| 7 | + if "%SPHINXBUILD%" == "" ( | ||
| 8 | + set SPHINXBUILD=sphinx-build | ||
| 9 | + ) | ||
| 10 | + set SOURCEDIR=source | ||
| 11 | + set BUILDDIR=build | ||
| 12 | + | ||
| 13 | + %SPHINXBUILD% >NUL 2>NUL | ||
| 14 | + if errorlevel 9009 ( | ||
| 15 | + echo. | ||
| 16 | + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx | ||
| 17 | + echo.installed, then set the SPHINXBUILD environment variable to point | ||
| 18 | + echo.to the full path of the 'sphinx-build' executable. Alternatively you | ||
| 19 | + echo.may add the Sphinx directory to PATH. | ||
| 20 | + echo. | ||
| 21 | + echo.If you don't have Sphinx installed, grab it from | ||
| 22 | + echo.https://www.sphinx-doc.org/ | ||
| 23 | + exit /b 1 | ||
| 24 | + ) | ||
| 25 | + | ||
| 26 | + if "%1" == "" goto help | ||
| 27 | + | ||
| 28 | + %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% | ||
| 29 | + goto end | ||
| 30 | + | ||
| 31 | + :help | ||
| 32 | + %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% | ||
| 33 | + | ||
| 34 | + :end | ||
| 35 | + popd | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,55 +1,55 @@ | |||
| 1 | - using System; | ||
| 2 | - using System.Collections.Generic; | ||
| 3 | - | ||
| 4 | - namespace Python.Runtime.Codecs | ||
| 5 | - { | ||
| 6 | - public class IterableDecoder : IPyObjectDecoder | ||
| 7 | - { | ||
| 8 | - internal static bool IsIterable(Type targetType) | ||
| 9 | - { | ||
| 10 | - //if it is a plain IEnumerable, we can decode it using sequence protocol. | ||
| 11 | - if (targetType == typeof(System.Collections.IEnumerable)) | ||
| 12 | - return true; | ||
| 13 | - | ||
| 14 | - if (!targetType.IsGenericType) | ||
| 15 | - return false; | ||
| 16 | - | ||
| 17 | - return targetType.GetGenericTypeDefinition() == typeof(IEnumerable<>); | ||
| 18 | - } | ||
| 19 | - | ||
| 20 | - internal static bool IsIterable(PyType objectType) | ||
| 21 | - { | ||
| 22 | - return objectType.HasAttr("__iter__"); | ||
| 23 | - } | ||
| 24 | - | ||
| 25 | - public bool CanDecode(PyType objectType, Type targetType) | ||
| 26 | - { | ||
| 27 | - return IsIterable(objectType) && IsIterable(targetType); | ||
| 28 | - } | ||
| 29 | - | ||
| 30 | - public bool TryDecode<T>(PyObject pyObj, out T value) | ||
| 31 | - { | ||
| 32 | - //first see if T is a plan IEnumerable | ||
| 33 | - if (typeof(T) == typeof(System.Collections.IEnumerable)) | ||
| 34 | - { | ||
| 35 | - object enumerable = new CollectionWrappers.IterableWrapper<object>(pyObj); | ||
| 36 | - value = (T)enumerable; | ||
| 37 | - return true; | ||
| 38 | - } | ||
| 39 | - | ||
| 40 | - var elementType = typeof(T).GetGenericArguments()[0]; | ||
| 41 | - var collectionType = typeof(CollectionWrappers.IterableWrapper<>).MakeGenericType(elementType); | ||
| 42 | - | ||
| 43 | - var instance = Activator.CreateInstance(collectionType, new[] { pyObj }); | ||
| 44 | - value = (T)instance; | ||
| 45 | - return true; | ||
| 46 | - } | ||
| 47 | - | ||
| 48 | - public static IterableDecoder Instance { get; } = new IterableDecoder(); | ||
| 49 | - | ||
| 50 | - public static void Register() | ||
| 51 | - { | ||
| 52 | - PyObjectConversions.RegisterDecoder(Instance); | ||
| 53 | - } | ||
| 54 | - } | ||
| 55 | - } | ||
| 1 | + using System; | ||
| 2 | + using System.Collections.Generic; | ||
| 3 | + | ||
| 4 | + namespace Python.Runtime.Codecs | ||
| 5 | + { | ||
| 6 | + public class IterableDecoder : IPyObjectDecoder | ||
| 7 | + { | ||
| 8 | + internal static bool IsIterable(Type targetType) | ||
| 9 | + { | ||
| 10 | + //if it is a plain IEnumerable, we can decode it using sequence protocol. | ||
| 11 | + if (targetType == typeof(System.Collections.IEnumerable)) | ||
| 12 | + return true; | ||
| 13 | + | ||
| 14 | + if (!targetType.IsGenericType) | ||
| 15 | + return false; | ||
| 16 | + | ||
| 17 | + return targetType.GetGenericTypeDefinition() == typeof(IEnumerable<>); | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + internal static bool IsIterable(PyType objectType) | ||
| 21 | + { | ||
| 22 | + return objectType.HasAttr("__iter__"); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public bool CanDecode(PyType objectType, Type targetType) | ||
| 26 | + { | ||
| 27 | + return IsIterable(objectType) && IsIterable(targetType); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + public bool TryDecode<T>(PyObject pyObj, out T value) | ||
| 31 | + { | ||
| 32 | + //first see if T is a plan IEnumerable | ||
| 33 | + if (typeof(T) == typeof(System.Collections.IEnumerable)) | ||
| 34 | + { | ||
| 35 | + object enumerable = new CollectionWrappers.IterableWrapper<object>(pyObj); | ||
| 36 | + value = (T)enumerable; | ||
| 37 | + return true; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + var elementType = typeof(T).GetGenericArguments()[0]; | ||
| 41 | + var collectionType = typeof(CollectionWrappers.IterableWrapper<>).MakeGenericType(elementType); | ||
| 42 | + | ||
| 43 | + var instance = Activator.CreateInstance(collectionType, new[] { pyObj }); | ||
| 44 | + value = (T)instance; | ||
| 45 | + return true; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public static IterableDecoder Instance { get; } = new IterableDecoder(); | ||
| 49 | + | ||
| 50 | + public static void Register() | ||
| 51 | + { | ||
| 52 | + PyObjectConversions.RegisterDecoder(Instance); | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,50 +1,50 @@ | |||
| 1 | - using System; | ||
| 2 | - using System.Collections.Generic; | ||
| 3 | - | ||
| 4 | - namespace Python.Runtime.Codecs | ||
| 5 | - { | ||
| 6 | - public class ListDecoder : IPyObjectDecoder | ||
| 7 | - { | ||
| 8 | - private static bool IsList(Type targetType) | ||
| 9 | - { | ||
| 10 | - if (!targetType.IsGenericType) | ||
| 11 | - return false; | ||
| 12 | - | ||
| 13 | - return targetType.GetGenericTypeDefinition() == typeof(IList<>); | ||
| 14 | - } | ||
| 15 | - | ||
| 16 | - private static bool IsList(PyType objectType) | ||
| 17 | - { | ||
| 18 | - //TODO accept any python object that implements the sequence and list protocols | ||
| 19 | - //must implement sequence protocol to fully implement list protocol | ||
| 20 | - //if (!SequenceDecoder.IsSequence(objectType)) return false; | ||
| 21 | - | ||
| 22 | - //returns wheter the type is a list. | ||
| 23 | - return PythonReferenceComparer.Instance.Equals(objectType, Runtime.PyListType); | ||
| 24 | - } | ||
| 25 | - | ||
| 26 | - public bool CanDecode(PyType objectType, Type targetType) | ||
| 27 | - { | ||
| 28 | - return IsList(objectType) && IsList(targetType); | ||
| 29 | - } | ||
| 30 | - | ||
| 31 | - public bool TryDecode<T>(PyObject pyObj, out T value) | ||
| 32 | - { | ||
| 33 | - if (pyObj == null) throw new ArgumentNullException(nameof(pyObj)); | ||
| 34 | - | ||
| 35 | - var elementType = typeof(T).GetGenericArguments()[0]; | ||
| 36 | - Type collectionType = typeof(CollectionWrappers.ListWrapper<>).MakeGenericType(elementType); | ||
| 37 | - | ||
| 38 | - var instance = Activator.CreateInstance(collectionType, new[] { pyObj }); | ||
| 39 | - value = (T)instance; | ||
| 40 | - return true; | ||
| 41 | - } | ||
| 42 | - | ||
| 43 | - public static ListDecoder Instance { get; } = new ListDecoder(); | ||
| 44 | - | ||
| 45 | - public static void Register() | ||
| 46 | - { | ||
| 47 | - PyObjectConversions.RegisterDecoder(Instance); | ||
| 48 | - } | ||
| 49 | - } | ||
| 50 | - } | ||
| 1 | + using System; | ||
| 2 | + using System.Collections.Generic; | ||
| 3 | + | ||
| 4 | + namespace Python.Runtime.Codecs | ||
| 5 | + { | ||
| 6 | + public class ListDecoder : IPyObjectDecoder | ||
| 7 | + { | ||
| 8 | + private static bool IsList(Type targetType) | ||
| 9 | + { | ||
| 10 | + if (!targetType.IsGenericType) | ||
| 11 | + return false; | ||
| 12 | + | ||
| 13 | + return targetType.GetGenericTypeDefinition() == typeof(IList<>); | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + private static bool IsList(PyType objectType) | ||
| 17 | + { | ||
| 18 | + //TODO accept any python object that implements the sequence and list protocols | ||
| 19 | + //must implement sequence protocol to fully implement list protocol | ||
| 20 | + //if (!SequenceDecoder.IsSequence(objectType)) return false; | ||
| 21 | + | ||
| 22 | + //returns wheter the type is a list. | ||
| 23 | + return PythonReferenceComparer.Instance.Equals(objectType, Runtime.PyListType); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + public bool CanDecode(PyType objectType, Type targetType) | ||
| 27 | + { | ||
| 28 | + return IsList(objectType) && IsList(targetType); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public bool TryDecode<T>(PyObject pyObj, out T value) | ||
| 32 | + { | ||
| 33 | + if (pyObj == null) throw new ArgumentNullException(nameof(pyObj)); | ||
| 34 | + | ||
| 35 | + var elementType = typeof(T).GetGenericArguments()[0]; | ||
| 36 | + Type collectionType = typeof(CollectionWrappers.ListWrapper<>).MakeGenericType(elementType); | ||
| 37 | + | ||
| 38 | + var instance = Activator.CreateInstance(collectionType, new[] { pyObj }); | ||
| 39 | + value = (T)instance; | ||
| 40 | + return true; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public static ListDecoder Instance { get; } = new ListDecoder(); | ||
| 44 | + | ||
| 45 | + public static void Register() | ||
| 46 | + { | ||
| 47 | + PyObjectConversions.RegisterDecoder(Instance); | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,52 +1,52 @@ | |||
| 1 | - using System; | ||
| 2 | - using System.Collections.Generic; | ||
| 3 | - | ||
| 4 | - namespace Python.Runtime.Codecs | ||
| 5 | - { | ||
| 6 | - public class SequenceDecoder : IPyObjectDecoder | ||
| 7 | - { | ||
| 8 | - internal static bool IsSequence(Type targetType) | ||
| 9 | - { | ||
| 10 | - if (!targetType.IsGenericType) | ||
| 11 | - return false; | ||
| 12 | - | ||
| 13 | - return targetType.GetGenericTypeDefinition() == typeof(ICollection<>); | ||
| 14 | - } | ||
| 15 | - | ||
| 16 | - internal static bool IsSequence(PyType objectType) | ||
| 17 | - { | ||
| 18 | - //must implement iterable protocol to fully implement sequence protocol | ||
| 19 | - if (!IterableDecoder.IsIterable(objectType)) return false; | ||
| 20 | - | ||
| 1 | + using System; | ||
| 2 | + using System.Collections.Generic; | ||
| 3 | + | ||
| 4 | + namespace Python.Runtime.Codecs | ||
| 5 | + { | ||
| 6 | + public class SequenceDecoder : IPyObjectDecoder | ||
| 7 | + { | ||
| 8 | + internal static bool IsSequence(Type targetType) | ||
| 9 | + { | ||
| 10 | + if (!targetType.IsGenericType) | ||
| 11 | + return false; | ||
| 12 | + | ||
| 13 | + return targetType.GetGenericTypeDefinition() == typeof(ICollection<>); | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + internal static bool IsSequence(PyType objectType) | ||
| 17 | + { | ||
| 18 | + //must implement iterable protocol to fully implement sequence protocol | ||
| 19 | + if (!IterableDecoder.IsIterable(objectType)) return false; | ||
| 20 | + | ||
| 21 | 21 | //returns wheter it implements the sequence protocol | |
| 22 | 22 | //according to python doc this needs to exclude dict subclasses | |
| 23 | 23 | //but I don't know how to look for that given the objectType | |
| 24 | 24 | //rather than the instance. | |
| 25 | - return objectType.HasAttr("__getitem__"); | ||
| 26 | - } | ||
| 27 | - | ||
| 28 | - public bool CanDecode(PyType objectType, Type targetType) | ||
| 29 | - { | ||
| 30 | - return IsSequence(objectType) && IsSequence(targetType); | ||
| 31 | - } | ||
| 32 | - | ||
| 33 | - public bool TryDecode<T>(PyObject pyObj, out T value) | ||
| 34 | - { | ||
| 35 | - if (pyObj == null) throw new ArgumentNullException(nameof(pyObj)); | ||
| 36 | - | ||
| 37 | - var elementType = typeof(T).GetGenericArguments()[0]; | ||
| 38 | - Type collectionType = typeof(CollectionWrappers.SequenceWrapper<>).MakeGenericType(elementType); | ||
| 39 | - | ||
| 40 | - var instance = Activator.CreateInstance(collectionType, new[] { pyObj }); | ||
| 41 | - value = (T)instance; | ||
| 42 | - return true; | ||
| 43 | - } | ||
| 44 | - | ||
| 45 | - public static SequenceDecoder Instance { get; } = new SequenceDecoder(); | ||
| 46 | - | ||
| 47 | - public static void Register() | ||
| 48 | - { | ||
| 49 | - PyObjectConversions.RegisterDecoder(Instance); | ||
| 50 | - } | ||
| 51 | - } | ||
| 52 | - } | ||
| 25 | + return objectType.HasAttr("__getitem__"); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + public bool CanDecode(PyType objectType, Type targetType) | ||
| 29 | + { | ||
| 30 | + return IsSequence(objectType) && IsSequence(targetType); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public bool TryDecode<T>(PyObject pyObj, out T value) | ||
| 34 | + { | ||
| 35 | + if (pyObj == null) throw new ArgumentNullException(nameof(pyObj)); | ||
| 36 | + | ||
| 37 | + var elementType = typeof(T).GetGenericArguments()[0]; | ||
| 38 | + Type collectionType = typeof(CollectionWrappers.SequenceWrapper<>).MakeGenericType(elementType); | ||
| 39 | + | ||
| 40 | + var instance = Activator.CreateInstance(collectionType, new[] { pyObj }); | ||
| 41 | + value = (T)instance; | ||
| 42 | + return true; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public static SequenceDecoder Instance { get; } = new SequenceDecoder(); | ||
| 46 | + | ||
| 47 | + public static void Register() | ||
| 48 | + { | ||
| 49 | + PyObjectConversions.RegisterDecoder(Instance); | ||
| 50 | + } | ||
| 51 | + } | ||
| 52 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - <?xml version="1.0" encoding="utf-8"?> | ||
| 1 | + <?xml version="1.0" encoding="utf-8"?> | ||
| 2 | 2 | <ClassDiagram MajorVersion="1" MinorVersion="1"> | |
| 3 | 3 | <Class Name="Python.Runtime.ClassBase" Collapsed="true"> | |
| 4 | 4 | <Position X="15" Y="1.75" Width="1.5" /> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - <?xml version="1.0" encoding="utf-8" ?> | ||
| 1 | + <?xml version="1.0" encoding="utf-8" ?> | ||
| 2 | 2 | <configuration> | |
| 3 | 3 | <startup> | |
| 4 | 4 | <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> | |
| Back | FazBrowse Home | New Git URL |
0 commit comments