def _escape_node(node):
 result = []
 for (i, char) in enumerate(node):
  if (char == u'\\'):
   if (u''.join(node[i:(i + 3)]) in JID_ESCAPE_SEQUENCES):
    result.append(u'\\5c')
    continue
  result.append(char)
 for (i, char) in enumerate(result):
  if (char != u'\\'):
   result[i] = JID_ESCAPE_TRANSFORMATIONS.get(char, char)
 escaped = u''.join(result)
 if (escaped.startswith(u'\\20') or escaped.endswith(u'\\20')):
  raise InvalidJID(u'Escaped local part starts or ends with "\\20"')
 _validate_node(escaped)
 return escaped

def _escape_node ( node ) : result = [ ] for ( i , char ) in enumerate ( node ) : if ( char == u'\\' ) : if ( u'' . join ( node [ i : ( i + 3 ) ] ) in JID_ESCAPE_SEQUENCES ) : result . append ( u'\\5c' ) continue result . append ( char ) for ( i , char ) in enumerate ( result ) : if ( char != u'\\' ) : result [ i ] = JID_ESCAPE_TRANSFORMATIONS . get ( char , char ) escaped = u'' . join ( result ) if ( escaped . startswith ( u'\\20' ) or escaped . endswith ( u'\\20' ) ) : raise InvalidJID ( u'Escaped local part starts or ends with "\\20"' ) _validate_node ( escaped ) return escaped
escape the local portion of a jid .