Jython is not an option ?<br><br><div class="gmail_quote">On Sat, Feb 7, 2009 at 9:54 PM,  <span dir="ltr"><<a href="mailto:zaheer.agadi@gmail.com">zaheer.agadi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi<br>
<br>
I have a following class that is written Java and makes use of apache<br>
http client library,I am new to python can any one suggest me a python<br>
equivalent of this following class,<br>
<br>
Thanks ,<br>
<br>
public class Authenticate{<br>
<br>
 private String storageUserName=null;<br>
    private String storagePassword=null;<br>
    private String authorization=null;<br>
    private String identityHostName = null;<br>
    private String identityPortNumber = null;<br>
<br>
    private String accessKey=null;<br>
    private String secretKey=null;<br>
<br>
    public String getStoragePassword() {<br>
        return storagePassword;<br>
    }<br>
<br>
    public void setStoragePassword(String storagePassword) {<br>
        this.storagePassword = storagePassword;<br>
    }<br>
<br>
    public String getStorageUserName() {<br>
        return storageUserName;<br>
    }<br>
<br>
    public void setStorageUserName(String storageUserName) {<br>
        this.storageUserName = storageUserName;<br>
    }<br>
<br>
    public String getIdentityHostName() {<br>
        return identityHostName;<br>
    }<br>
<br>
    public void setIdentityHostName(String identityHostName) {<br>
        this.identityHostName = identityHostName;<br>
    }<br>
<br>
    public String getIdentityPortNumber() {<br>
        return identityPortNumber;<br>
    }<br>
<br>
    public void setIdentityPortNumber(String identityPortNumber) {<br>
        this.identityPortNumber = identityPortNumber;<br>
    }<br>
<br>
    public String getAccessKey() {<br>
        return accessKey;<br>
    }<br>
<br>
    public void setAccessKey(String accessKey) {<br>
        this.accessKey = accessKey;<br>
    }<br>
<br>
    public String getSecretKey() {<br>
        return secretKey;<br>
    }<br>
<br>
    public void setSecretKey(String secretKey) {<br>
        this.secretKey = secretKey;<br>
    }<br>
<br>
<br>
     /**<br>
     * <p>Convenience string for Base 64 encoding.</p><br>
     */<br>
    private static final String BASE64_CHARS =<br>
            "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +<br>
            "abcdefghijklmnopqrstuvwxyz" +<br>
            "0123456789+/";<br>
<br>
    /**<br>
     * <p>Encode the specified credentials into a String as required<br>
by<br>
     * HTTP Basic Authentication (<a href="<a href="http://www.ietf.org/rfc/
rfc2617.txt" target="_blank">http://www.ietf.org/rfc/<br>
rfc2617.txt</a>">RFC 2617</a>).</p><br>
     *<br>
     * @param username Username to be encoded<br>
     * @param password Password to be encoded<br>
     * @return String string containing encoded username and password.<br>
     */<br>
    public String encodeCredentialsBasic(String username, String<br>
password) {<br>
        String encode = username + ":" + password;<br>
        int paddingCount = (3 - (encode.length() % 3)) % 3;<br>
        encode += "\0\0".substring(0, paddingCount);<br>
        StringBuilder encoded = new StringBuilder();<br>
<br>
        for (int i = 0; i < encode.length(); i += 3) {<br>
        }<br>
        return encoded.toString();<br>
    }<br>
<br>
    public void fetchDetails(){<br>
        HttpClient client=new HttpClient();<br>
        //reqDetails = new RequestDetails();<br>
        //String identityURL=MessageUtil.getMessage<br>
("IDENTITY_INSTANCE");<br>
        //int portNumber=Integer.parseInt(MessageUtil.getMessage<br>
("IDENTITY_PORT"));<br>
        authorization="Basic " + encodeCredentialsBasic<br>
(storageUserName, storagePassword);<br>
        String url="https://"+identityHostName+<br>
                ":"+identityPortNumber+"/test/ndcsd2/persons/"+UserName<br>
+"/attributes/";<br>
<br>
        Protocol https=null;<br>
        //try {<br>
            https = new Protocol("https", new<br>
EasySSLProtocolSocketFactory(), Integer.parseInt(identityPortNumber));<br>
        /*} catch (GeneralSecurityException ex) {<br>
            Logger.getLogger(Authenticate.class.getName()).log<br>
(Level.SEVERE, null, ex);<br>
        } catch (IOException ex) {<br>
            Logger.getLogger(Authenticate.class.getName()).log<br>
(Level.SEVERE, null, ex);<br>
        }*/<br>
        Protocol.registerProtocol("https", https);<br>
        GetMethod method=new GetMethod(url);<br>
        method.setRequestHeader("Authorization",authorization);<br>
        method.setRequestHeader("Accept","application/xml");<br>
        try {<br>
            int responseCode=client.executeMethod(method);<br>
            if(responseCode==200){<br>
                InputStream is=method.getResponseBodyAsStream();<br>
                BufferedReader bis=new BufferedReader(new<br>
InputStreamReader(is));<br>
                String temp=null,sKey=null, aKey=null;<br>
                String accessKeySearchString="AccessKey</<br>
Name><Value>";<br>
                String secretKeySearchString="SecretKey</<br>
Name><Value>";<br>
                int searchStringLength=0;<br>
                while((temp=bis.readLine())!=null){<br>
                    if(temp.indexOf(accessKeySearchString)!=-1){<br>
                        int beginIndex=temp.indexOf<br>
(accessKeySearchString);<br>
                        searchStringLength=accessKeySearchString.length<br>
();<br>
                        int endIndex=temp.indexOf("</<br>
Value>",beginIndex);<br>
                        aKey=temp.substring(beginIndex<br>
+searchStringLength,endIndex);<br>
                    }<br>
                    if(temp.indexOf(secretKeySearchString)!=-1){<br>
                        int beginIndex=temp.indexOf<br>
(secretKeySearchString);<br>
                        searchStringLength=secretKeySearchString.length<br>
();<br>
                        int endIndex=temp.indexOf("</<br>
Value>",beginIndex);<br>
                        sKey=temp.substring(beginIndex<br>
+searchStringLength,endIndex);<br>
                    }<br>
                }<br>
                setSecretKey(sKey);<br>
                setAccessKey(aKey);<br>
            } else {<br>
                System.out.println("Not able to get the credentials.<br>
Returned : " + responseCode + " response code!!!");<br>
            }<br>
        } catch (IOException ex) {<br>
            Logger.getLogger(Authenticate.class.getName()).log<br>
(Level.SEVERE, null, ex);<br>
        }<br>
    }<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>regards,<br>Banibrata<br><a href="http://www.linkedin.com/in/bdutta">http://www.linkedin.com/in/bdutta</a><br>