def encode(self, fname, max_length=<NUM_LIT:4>, german=False):
fname = unicode_normalize('<STR_LIT>', text_type(fname.upper()))<EOL>fname = fname.replace('<STR_LIT>', '<STR_LIT>')<EOL>fname = '<STR_LIT>'.join(c for c in fname if c in self._uc_set)<EOL>if fname == '<STR_LIT>':<EOL><INDENT>code = '<STR_LIT>'<EOL><DEDENT>elif fname == '<STR_LIT>':<EOL><INDENT>code = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>if fname[:<NUM_LIT:2>] in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>fname = '<STR_LIT>' + fname[<NUM_LIT:1>:]<EOL><DEDENT>elif fname[:<NUM_LIT:2>] in {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>fname = '<STR_LIT:S>' + fname[<NUM_LIT:1>:]<EOL><DEDENT>elif fname[:<NUM_LIT:3>] == '<STR_LIT>':<EOL><INDENT>fname = '<STR_LIT>' + fname[<NUM_LIT:1>:]<EOL><DEDENT>elif fname[:<NUM_LIT:1>] == '<STR_LIT:C>' and fname[:<NUM_LIT:2>] != '<STR_LIT>':<EOL><INDENT>fname = '<STR_LIT>' + fname[<NUM_LIT:1>:]<EOL><DEDENT>if fname[:<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>fname = '<STR_LIT:N>' + fname[<NUM_LIT:1>:]<EOL><DEDENT>elif fname[:<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>fname = '<STR_LIT:F>' + fname[<NUM_LIT:1>:]<EOL><DEDENT>elif fname[:<NUM_LIT:3>] in {'<STR_LIT>', '<STR_LIT>'}:<EOL><INDENT>fname = '<STR_LIT>' + fname[<NUM_LIT:1>:]<EOL><DEDENT>if german and fname[:<NUM_LIT:1>] in {'<STR_LIT>', '<STR_LIT:M>', '<STR_LIT:Y>', '<STR_LIT>'}:<EOL><INDENT>fname = {'<STR_LIT>': '<STR_LIT>', '<STR_LIT:M>': '<STR_LIT:N>', '<STR_LIT:Y>': '<STR_LIT>', '<STR_LIT>': '<STR_LIT:S>'}[<EOL>fname[<NUM_LIT:0>]<EOL>] + fname[<NUM_LIT:1>:]<EOL><DEDENT>code = fname[:<NUM_LIT:1>]<EOL>fname = fname.translate(self._trans)<EOL>fname = self._delete_consecutive_repeats(fname)<EOL>code += fname[<NUM_LIT:1>:]<EOL>syl_ptr = code.find('<STR_LIT:0>')<EOL>syl2_ptr = code[syl_ptr + <NUM_LIT:1> :].find('<STR_LIT:0>')<EOL>if syl_ptr != -<NUM_LIT:1> and syl2_ptr != -<NUM_LIT:1> and syl2_ptr - syl_ptr > -<NUM_LIT:1>:<EOL><INDENT>code = code[: syl_ptr + <NUM_LIT:2>]<EOL><DEDENT>code = code.replace('<STR_LIT:0>', '<STR_LIT>')  <EOL><DEDENT>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 first name.

        Parameters
        ----------
        fname : str
            The first 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 = PSHPSoundexFirst()
        >>> pe.encode('Smith')
        'S530'
        >>> pe.encode('Waters')
        'W352'
        >>> pe.encode('James')
        'J700'
        >>> pe.encode('Schmidt')
        'S500'
        >>> pe.encode('Ashcroft')
        'A220'
        >>> pe.encode('John')
        'J500'
        >>> pe.encode('Colin')
        'K400'
        >>> pe.encode('Niall')
        'N400'
        >>> pe.encode('Sally')
        'S400'
        >>> pe.encode('Jane')
        'J500'