Wednesday, January 7, 2009

Python SUDS with Windows Authentication (SOAP)

While intergrating Plone with CRM4, I stumbled upon Suds. However, it didn't support NTLM. Then I found python-ntlm, and merged the two libs.

Below is the result.

You can add it at the bottom of suds/transport.py



[code]
class WindowsHttpAuthenticated(HttpAuthenticated):
"""
Provides Windows (NTLM) http authentication.
@ivar pm: The password manager.
@ivar handler: The authentication handler.
@author: Christopher Bess
"""

def __init__(self, options):
# try to import ntlm support
try:
from ntlm import HTTPNtlmAuthHandler
except ImportError:
raise Exception("Cannot import python-ntlm module")
return

HttpTransport.__init__(self, options)
self.pm = u2.HTTPPasswordMgrWithDefaultRealm()
self.handler = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(self.pm)
self.urlopener = u2.build_opener(self.handler)
u2.install_opener(self.urlopener)
pass # end class

[/code]


[code]
from suds import transport
#>>>
from suds import client
#>>>
from suds.options import Options
#>>>
options = Options(username='DOMAIN\username',
password='password')
#>>>
c = client.Client(url='http://0.0.0.0/mscrmservices/2007/CrmServiceWsdl.aspx',
username='DOMAIN\username',
password='password',
transport=transport.WindowsHttpAuthenticated(options))
#>>>
c
#---

[/code]

Friday, October 24, 2008

Plone: Reverse Folder Contents in TAL Define

Using TAL, I needed to display the folder contents with dates ascending (newest first). By default context/folderlistFolderContents returns the tuple descending.

So I fixed it by using a ternary statment hack, that evaluates both entries/blocks.



[code]
<metal:fill fill-slot="main">
<metal:main_macro define-macro="main"
tal:define="portal_type python:here.getPortalTypeName().lower().replace(' ', '_');
folder_list context/folderlistingFolderContents;

folder_list python: (folder_list.reverse(), folder_list)[1];

base_macros here/base/macros;
view_template python:'%s_view' % portal_type;
<!-- rest of code -->
[/code]

Plone: Reinstall Product Button

While creating Plone Products, I noticed that Plone will delete any created Portal objects, once a product associated with it has been uninstalled. Since I created a ZCatalog, which had data in it, I don't want that feature. After marching through the QuickInstaller code, I decided to add a "Reinstall Button" to all the respective products, to prevent uninstallation.

In your egg or product code root, simple add:
version.txt

Directory Structure Example (Python Pkg):
myproduct.stuff/myproduct/stuff/version.txt

The contents should be:
1.0-alpha build 1

When ever the version.txt is changed it will display the reinstall button.

Note: If you add the version.txt file to an existing product, you will have to manually uninstall the Product, then install it again. Otherwise, pressing "reinstall product" will anger the QuickInstaller (very bad).

The Fix for angry QuickInstaller:
If you manage to click "reinstall product" before you uninstall and install again, shame on you. To resolve, simply delete the QuickInstaller from the ZMI, then go to portal_setup, click the "Import" tab, select "QuickInstaller" from the list of profiles, then at the bottom, click "Import All Steps". This will cause all the installed products to go back to the "Products available for install" section, simply tick all the ones previously installed, and install them again.

Tuesday, September 2, 2008

ObjPCRE on iPhone

I have been having fun with my ObjPCRE framework and the iPhone SDK.

Just drop the contents of this archive in your Xcode project and build.

The archive contains the debug libs, for the simulator and the release builds, for iPhone.

ObjPCRE iPhone Libraries

If you use ObjPCRE for iPhone or anywhere else, please comment.

Wednesday, July 9, 2008

Custom Grep Format via Python



I really wanted a custom output format for the great grep, I used standard Python to do it.

Needs Python 2.4+

GrepOut is the name and grep formatting is it's game.

Its free, its BSD.

Download Here

Monday, May 26, 2008

Combat the WTF in iPhone Development

I thought I would share some information for those that may be new to iPhone development, or may have forgotten.

If you see this: __TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION__
popup during a runtime error, check here: Console.app
for a more verbose explanation.

Most of the time you will find the WTF.

Tuesday, May 20, 2008

Google Open Source Blog: Develop with Git on a Google Code Project

Google Open Source Blog: Develop with Git on a Google Code Project

Also check out: github.com (free 100MB git repo host)