'Return a by-subreddit dict representing merged OAuth2Scopes.
Takes an iterable of OAuth2Scopes. For each of those,
if it defines scopes on multiple subreddits, it is split
into one OAuth2Scope per subreddit. If multiple passed in
OAuth2Scopes reference the same scopes, they\'ll be combined.'

@classmethod
def merge_scopes(cls, scopes):

    merged = {}
    for scope in scopes:
        srs = (scope.subreddits if scope.subreddit_only else (None,))
        for sr in srs:
            if (sr in merged):
                merged[sr].scopes.update(scope.scopes)
            else:
                new_scope = cls()
                new_scope.subreddits = {sr}
                new_scope.scopes = scope.scopes
                if (sr is not None):
                    new_scope.subreddit_only = True
                merged[sr] = new_scope
    return merged
