"""Service Functions"""
import re, os.path, globalv

def midToJid(murray_id, alias, resourcep):
        """Converts a Murray ID (hash, alias) to a Jabber ID.  If
        resourcep then append Murray as a resource."""

        jid = alias + "@" + murray_id + ".murray.p2p"
        if resourcep: jid += "/Murray"
        
        return jid

def jidToMid(self, jid):
    """Converts a Jabber ID (alias@hash.murray.p2p/resource) to a
    Murray ID.
    
    returns a (uid, alias) tuple"""

    rex = re.compile('@(.*)/')
    bacon = re.split(rex, sender)
    alias = bacon[0]
    uid = bacon[1].split('.')[0]
    return (uid, alias)

def buildPath(filename):
	"""creates a path to a file in the murray-home-directory"""
	return os.path.join(globalv.MURRAY_HOME, filename)

