'Load a grammar from a pickle file'

def load_grammar(self, *args):

    filename = askopenfilename(filetypes=self.GRAMMAR_FILE_TYPES, defaultextension='.cfg')
    if (not filename):
        return
    try:
        if filename.endswith('.pickle'):
            with open(filename, 'rb') as infile:
                grammar = pickle.load(infile)
        else:
            with open(filename, 'r') as infile:
                grammar = CFG.fromstring(infile.read())
        self.set_grammar(grammar)
    except Exception as e:
        showerror('Error    Loading    Grammar', ('Unable    to    open    file:    %r' % filename))
