def encode(self, lname, max_length=<NUM_LIT:4>, german=False):
lname = unicode_normalize('<STR_LIT>', text_type(lname.upper()))<EOL>lname = lname.replace('<STR_LIT>', '<STR_LIT>')<EOL>lname = '<STR_LIT>'.join(c for c in lname if c in self._uc_set)<EOL>if lname[:<NUM_LIT:3>] == '<STR_LIT>' or lname[:<NUM_LIT:3>] == '<STR_LIT>':<EOL><INDENT>lname = lname[<NUM_LIT:3>:].strip()<EOL><DEDENT>if not german:<EOL><INDENT>if lname[:<NUM_LIT:3>] == '<STR_LIT>':<EOL><INDENT>lname = '<STR_LIT:M>' + lname[<NUM_LIT:3>:]<EOL><DEDENT>elif lname[:<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>lname = '<STR_LIT:M>' + lname[<NUM_LIT:2>:]<EOL><DEDENT><DEDENT>if lname[:<NUM_LIT:1>] in {'<STR_LIT:E>', '<STR_LIT:I>', '<STR_LIT:O>', '<STR_LIT>'}:<EOL><INDENT>lname = '<STR_LIT:A>' + lname[<NUM_LIT:1>:]<EOL><DEDENT>elif lname[:<NUM_LIT:2>] in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>lname = '<STR_LIT>' + lname[<NUM_LIT:1>:]<EOL><DEDENT>elif lname[:<NUM_LIT:2>] in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>lname = '<STR_LIT:S>' + lname[<NUM_LIT:1>:]<EOL><DEDENT>elif lname[:<NUM_LIT:3>] == '<STR_LIT>':<EOL><INDENT>lname = '<STR_LIT>' + lname[<NUM_LIT:1>:]<EOL><DEDENT>elif lname[:<NUM_LIT:1>] == '<STR_LIT:C>' and lname[:<NUM_LIT:2>] != '<STR_LIT>':<EOL><INDENT>lname = '<STR_LIT>' + lname[<NUM_LIT:1>:]<EOL><DEDENT>if lname[:<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>lname = '<STR_LIT:N>' + lname[<NUM_LIT:1>:]<EOL><DEDENT>elif lname[:<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>lname = '<STR_LIT:F>' + lname[<NUM_LIT:1>:]<EOL><DEDENT>elif lname[:<NUM_LIT:3>] in {'<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>lname = '<STR_LIT>' + lname[<NUM_LIT:1>:]<EOL><DEDENT>if german and lname[:<NUM_LIT:1>] in {'<STR_LIT>', '<STR_LIT:M>', '<STR_LIT:Y>', '<STR_LIT>'}:<EOL><INDENT>lname = {'<STR_LIT>': '<STR_LIT>', '<STR_LIT:M>': '<STR_LIT:N>', '<STR_LIT:Y>': '<STR_LIT>', '<STR_LIT>': '<STR_LIT:S>'}[lname[<NUM_LIT:0>]] + lname[<EOL><NUM_LIT:1>:<EOL>]<EOL><DEDENT>code = lname[:<NUM_LIT:1>]<EOL>if german:  <EOL><INDENT>if lname[-<NUM_LIT:3>:] == '<STR_LIT>':<EOL><INDENT>lname = lname[:-<NUM_LIT:3>]<EOL><DEDENT>elif lname[-<NUM_LIT:2>:] == '<STR_LIT>':<EOL><INDENT>lname = lname[:-<NUM_LIT:2>]<EOL><DEDENT>if lname[-<NUM_LIT:3>:] == '<STR_LIT>':<EOL><INDENT>lname = lname[:-<NUM_LIT:3>]<EOL><DEDENT>elif lname[-<NUM_LIT:2>:] == '<STR_LIT>':<EOL><INDENT>lname = lname[:-<NUM_LIT:2>]<EOL><DEDENT>if lname[-<NUM_LIT:1>:] == '<STR_LIT>':<EOL><INDENT>lname = lname[:-<NUM_LIT:1>]<EOL><DEDENT>elif lname[-<NUM_LIT:2>:] == '<STR_LIT>':<EOL><INDENT>lname = lname[:-<NUM_LIT:2>]<EOL><DEDENT><DEDENT>if lname[-<NUM_LIT:1>:] == '<STR_LIT:R>':<EOL><INDENT>lname = lname[:-<NUM_LIT:1>] + '<STR_LIT:N>'<EOL><DEDENT>elif lname[-<NUM_LIT:2>:] in {'<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>lname = lname[:-<NUM_LIT:2>]<EOL><DEDENT>if lname[-<NUM_LIT:2>:] == '<STR_LIT>':<EOL><INDENT>lname = lname[:-<NUM_LIT:2>]<EOL><DEDENT>elif lname[-<NUM_LIT:1>:] == '<STR_LIT:S>':<EOL><INDENT>lname = lname[:-<NUM_LIT:1>]<EOL><DEDENT>if not german:<EOL><INDENT>l5_repl = {'<STR_LIT>': '<STR_LIT>', '<STR_LIT>': '<STR_LIT>'}<EOL>l4_repl = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>if lname[-<NUM_LIT:5>:] in l5_repl:<EOL><INDENT>lname = lname[:-<NUM_LIT:5>] + l5_repl[lname[-<NUM_LIT:5>:]]<EOL><DEDENT>elif lname[-<NUM_LIT:4>:] in l4_repl:<EOL><INDENT>lname = lname[:-<NUM_LIT:4>] + l4_repl[lname[-<NUM_LIT:4>:]]<EOL><DEDENT><DEDENT>if lname[-<NUM_LIT:2>:] in {'<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>lname = lname[:-<NUM_LIT:1>]<EOL><DEDENT>if not german and lname[-<NUM_LIT:3>:] in {'<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>lname = lname[:-<NUM_LIT:3>] + '<STR_LIT:A>' + lname[-<NUM_LIT:2>:]<EOL><DEDENT>lname = lname.replace('<STR_LIT>', '<STR_LIT:C>')<EOL>lname = lname.replace('<STR_LIT>', '<STR_LIT:S>')<EOL>lname = lname.replace('<STR_LIT>', '<STR_LIT:T>')<EOL>lname = lname.replace('<STR_LIT>', '<STR_LIT:N>')<EOL>lname = lname.replace('<STR_LIT>', '<STR_LIT:N>')<EOL>lname = lname.replace('<STR_LIT>', '<STR_LIT:M>')<EOL>lname = lname.replace('<STR_LIT>', '<STR_LIT:M>')<EOL>lname = lname.replace('<STR_LIT>', '<STR_LIT>')<EOL>lname = lname.replace('<STR_LIT>', '<STR_LIT>')<EOL>lname = lname.translate(self._trans)<EOL>lname = self._delete_consecutive_repeats(lname)<EOL>code += lname[<NUM_LIT:1>:]<EOL>code = code.replace('<STR_LIT:0>', '<STR_LIT>')  <EOL>if max_length != -<NUM_LIT:1>:<EOL><INDENT>if len(code) < max_length:<EOL><INDENT>code += '<STR_LIT:0>' * (max_length - len(code))<EOL><DEDENT>else:<EOL><INDENT>code = code[:max_length]<EOL><DEDENT><DEDENT>return code<EOL>
Calculate the PSHP Soundex/Viewex Coding of a last name.

        Parameters
        ----------
        lname : str
            The last name to encode
        max_length : int
            The length of the code returned (defaults to 4)
        german : bool
            Set to True if the name is German (different rules apply)

        Returns
        -------
        str
            The PSHP Soundex/Viewex Coding

        Examples
        --------
        >>> pe = PSHPSoundexLast()
        >>> pe.encode('Smith')
        'S530'
        >>> pe.encode('Waters')
        'W350'
        >>> pe.encode('James')
        'J500'
        >>> pe.encode('Schmidt')
        'S530'
        >>> pe.encode('Ashcroft')
        'A225'