[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/attackgithub/pythonnet/featured/src/runtime/pyansistring.cs [Back]  [Original]

using System;

namespace Python.Runtime
{
    public class PyAnsiString : PySequence
    {
        /// 
        /// PyAnsiString Constructor
        /// 
        /// 
        /// Creates a new PyAnsiString from an existing object reference. Note
        /// that the instance assumes ownership of the object reference.
        /// The object reference is not checked for type-correctness.
        /// 
        public PyAnsiString(IntPtr ptr) : base(ptr)
        {
        }


        /// 
        /// PyString Constructor
        /// 
        /// 
        /// Copy constructor - obtain a PyAnsiString from a generic PyObject.
        /// An ArgumentException will be thrown if the given object is not
        /// a Python string object.
        /// 
        public PyAnsiString(PyObject o)
        {
            if (!IsStringType(o))
            {
                throw new ArgumentException("object is not a string");
            }
            Runtime.XIncref(o.obj);
            obj = o.obj;
        }


        /// 
        /// PyAnsiString Constructor
        /// 
        /// 
        /// Creates a Python string from a managed string.
        /// 
        public PyAnsiString(string s)
        {
            obj = Runtime.PyString_FromString(s);
            Runtime.CheckExceptionOccurred();
        }


        /// 
        /// IsStringType Method
        /// 
        /// 
        /// Returns true if the given object is a Python string.
        /// 
        public static bool IsStringType(PyObject value)
        {
            return Runtime.PyString_Check(value.obj);
        }
    }
}

Web Proxy Viewer  |  New URL  |  Original Page