예제 #1
0
//
// this method is called to retrieve the password
// for the certificate
//
// @param password
//
bool pysvn_context::contextSslClientCertPwPrompt
(
    std::string &_password,
    const std::string &_realm,
    bool &_may_save
)
{
    PythonDisallowThreads callback_permission( m_permission );

    // make sure we can call the users object
    if( !m_pyfn_SslClientCertPwPrompt.isCallable() )
    {
        m_error_message = "callback_ssl_client_cert_password_prompt required";

        return false;
    }

    Py::Callable callback( m_pyfn_SslClientCertPwPrompt );

    Py::Tuple args( 2 );
    args[0] = Py::String( _realm );
    args[1] = Py::Int( (long)_may_save );

    // bool, username, password
    Py::Tuple results;
    Py::Int retcode;
    Py::String username;
    Py::String password;
    Py::Int may_save_out;

    try
    {
        results = callback.apply( args );
        retcode = results[0];
        password = results[1];
        may_save_out = results[2];

        // true returned
        if( long( retcode ) != 0 )
        {
            // copy out the answers
            _password = password.as_std_string();
            _may_save = long( may_save_out ) != 0;

            return true;
        }
    }
    catch( Py::Exception &e )
    {
        PyErr_Print();
        e.clear();

        m_error_message = "unhandled exception in callback_ssl_client_cert_password_prompt";

        return false;
    }

    return false;
}
PyObject* Application::sAddWorkbenchHandler(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
{
    PyObject*   pcObject;
    std::string item;
    if (!PyArg_ParseTuple(args, "O", &pcObject))     // convert args: Python->C 
        return NULL;                    // NULL triggers exception 

    try {
        // get the class object 'Workbench' from the main module that is expected
        // to be base class for all workbench classes
        Py::Module module("__main__");
        Py::Object baseclass(module.getAttr(std::string("Workbench")));
        
        // check whether it is an instance or class object
        Py::Object object(pcObject);
        Py::String name;
        
        if (PyObject_IsSubclass(object.ptr(), baseclass.ptr()) == 1) {
            // create an instance of this class
            name = object.getAttr(std::string("__name__"));
            Py::Tuple args;
            Py::Callable creation(object);
            object = creation.apply(args);
        }
        else if (PyObject_IsInstance(object.ptr(), baseclass.ptr()) == 1) {
            // extract the class name of the instance
            PyErr_Clear(); // PyObject_IsSubclass set an exception
            Py::Object classobj = object.getAttr(std::string("__class__"));
            name = classobj.getAttr(std::string("__name__"));
        }
        else {
            PyErr_SetString(PyExc_TypeError, "arg must be a subclass or an instance of "
                                             "a subclass of 'Workbench'");
            return NULL;
        }

        // Search for some methods and members without invoking them
        Py::Callable(object.getAttr(std::string("Initialize")));
        Py::Callable(object.getAttr(std::string("GetClassName")));
        item = name.as_std_string();

        PyObject* wb = PyDict_GetItemString(Instance->_pcWorkbenchDictionary,item.c_str()); 
        if (wb) {
            PyErr_Format(PyExc_KeyError, "'%s' already exists.", item.c_str());
            return NULL;
        }

        PyDict_SetItemString(Instance->_pcWorkbenchDictionary,item.c_str(),object.ptr());
        Instance->signalAddWorkbench(item.c_str());
    }
    catch (const Py::Exception&) {
        return NULL;
    }

    Py_INCREF(Py_None);
    return Py_None;
}
예제 #3
0
void ToolPy::setToolType(Py::String arg)
{
    std::string typeStr(arg.as_std_string());
    if(typeStr=="Drill")
        getToolPtr()->Type = Tool::DRILL;
    else if(typeStr=="CenterDrill")
        getToolPtr()->Type = Tool::CENTERDRILL;
    else if(typeStr=="CounterSink")
        getToolPtr()->Type = Tool::COUNTERSINK;
    else if(typeStr=="CounterBore")
        getToolPtr()->Type = Tool::COUNTERBORE;
    else if(typeStr=="Reamer")
        getToolPtr()->Type = Tool::REAMER;
    else if(typeStr=="Tap")
        getToolPtr()->Type = Tool::TAP;
    else if(typeStr=="EndMill")
        getToolPtr()->Type = Tool::ENDMILL;
    else if(typeStr=="SlotCutter")
        getToolPtr()->Type = Tool::SLOTCUTTER;
    else if(typeStr=="BallEndMill")
        getToolPtr()->Type = Tool::BALLENDMILL;
    else if(typeStr=="ChamferMill")
        getToolPtr()->Type = Tool::CHAMFERMILL;
    else if(typeStr=="CornerRound")
        getToolPtr()->Type = Tool::CORNERROUND;

    else if(typeStr=="Engraver")
        getToolPtr()->Type = Tool::ENGRAVER;
    else 
        getToolPtr()->Type = Tool::UNDEFINED;
}
예제 #4
0
int CyPy_Task::setattro(const Py::String& name, const Py::Object& attr)
{

    auto nameStr = name.as_string();
    if (nameStr == "progress") {
        m_value->progress() = verifyNumeric(attr);
        return 0;
    }
    if (nameStr == "duration") {
        m_value->m_duration = verifyNumeric(attr);
        return 0;
    }
    if (nameStr == "tick_interval") {
        m_value->m_tick_interval = verifyNumeric(attr);
        return 0;
    }
    if (nameStr == "name") {
        m_value->name() = verifyString(attr);
        return 0;
    }

    auto element = CyPy_Element::asElement(attr);
    m_value->setAttr(nameStr, element);
    return 0;
}
예제 #5
0
Py::Object CyPy_WorldTime::getattro(const Py::String& name)
{
    auto element = get_value()[name.as_string()];
    if (!element.empty()) {
        return Py::String(element);
    }
    return PythonExtensionBase::getattro(name);
}
예제 #6
0
void WaypointPy::setType(Py::String arg)
{
    std::string typeStr(arg.as_std_string());
    if(typeStr=="PTP")
        getWaypointPtr()->Type = Waypoint::PTP;
    else if(typeStr=="LIN")
        getWaypointPtr()->Type = Waypoint::LINE;
    else if(typeStr=="CIRC")
        getWaypointPtr()->Type = Waypoint::CIRC;
    else if(typeStr=="WAIT")
        getWaypointPtr()->Type = Waypoint::WAIT;
    else
        throw Base::Exception("Unknown waypoint type! Only: PTP,LIN,CIRC,WAIT are allowed.");
}
예제 #7
0
void ToolPy::setMaterial(Py::String arg)
{
    std::string matStr(arg.as_std_string());
    if(matStr=="HighSpeedSteel")
        getToolPtr()->Material = Tool::HIGHSPEEDSTEEL;
    else if(matStr=="Carbide")
        getToolPtr()->Material = Tool::CARBIDE;
    else if(matStr=="HighCarbonToolSteel")
        getToolPtr()->Material = Tool::HIGHCARBONTOOLSTEEL;
    else if(matStr=="CastAlloy")
        getToolPtr()->Material = Tool::CASTALLOY;
    else if(matStr=="Ceramics")
        getToolPtr()->Material = Tool::CERAMICS;
    else if(matStr=="Diamond")
        getToolPtr()->Material = Tool::DIAMOND;
    else if(matStr=="Sialon")
        getToolPtr()->Material = Tool::SIALON;
    else 
        getToolPtr()->Material = Tool::MATUNDEFINED;
}
예제 #8
0
void WaypointPy::setName(Py::String arg)
{
    getWaypointPtr()->Name = arg.as_std_string();
}
예제 #9
0
void ToolPy::setName(Py::String arg)
{
    std::string name = arg.as_std_string();
    getToolPtr()->Name = name;
}
예제 #10
0
int CyPy_ElementMap::setattro(const Py::String& name, const Py::Object& attr)
{
    m_value.emplace(name.as_string(), CyPy_Element::asElement(attr));

    return 0;
}
예제 #11
0
Py::Object CyPy_Task::getattro(const Py::String& name)
{
    auto nameStr = name.as_string();
    if (nameStr == "usage") {
        return CyPy_UsageInstance::wrap(m_value->m_usageInstance);
    }
    if (nameStr == "actor") {
        return CyPy_LocatedEntity::wrap(m_value->m_usageInstance.actor);
    }
    if (nameStr == "tool") {
        return CyPy_LocatedEntity::wrap(m_value->m_usageInstance.tool);
    }
//    if (nameStr == "targets") {
//        Py::List list(m_value->m_usageInstance.targets.size());
//        for (size_t i = 0; i < m_value->m_usageInstance.targets.size(); ++i) {
//            list[i] = CyPy_EntityLocation::wrap(m_value->m_usageInstance.targets[i]);
//        }
//        return list;
//    }
//    if (nameStr == "consumed") {
//        Py::List list(m_value->m_usageInstance.consumed.size());
//        for (size_t i = 0; i < m_value->m_usageInstance.consumed.size(); ++i) {
//            list[i] = CyPy_EntityLocation::wrap(m_value->m_usageInstance.consumed[i]);
//        }
//        return list;
//    }
    if (nameStr == "definition") {
        return CyPy_Usage::wrap(m_value->m_usageInstance.definition);
    }
    if (nameStr == "op") {
        return CyPy_Operation::wrap(m_value->m_usageInstance.op);
    }


    if (nameStr == "progress") {
        return Py::Float(m_value->progress());
    }
    if (nameStr == "duration") {
        if (!m_value->m_duration) {
            return Py::None();
        }
        return Py::Float(*m_value->m_duration);
    }
    if (nameStr == "tick_interval") {
        if (!m_value->m_tick_interval) {
            return Py::None();
        }
        return Py::Float(*m_value->m_tick_interval);
    }
    if (nameStr == "name") {
        return Py::String(m_value->name());
    }
    Atlas::Message::Element val;
    if (m_value->getAttr(name, val) == 0) {
        if (val.isNone()) {
            return Py::None();
        } else {
            return CyPy_Element::wrap(val);
        }
    }

    return PythonExtensionBase::getattro(name);
}