<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def describe_topic(name, region=None, key=None, keyid=None, profile=None):
    '''
    Returns details about a specific SNS topic, specified by name or ARN.

    CLI example::

        salt my_favorite_client boto3_sns.describe_topic a_sns_topic_of_my_choice
    '''
    topics = list_topics(region=region, key=key, keyid=keyid, profile=profile)
    ret = {}
    for topic, arn in topics.items():
        if name in (topic, arn):
            ret = {'TopicArn': arn}
            ret['Attributes'] = get_topic_attributes(arn, region=region, key=key, keyid=keyid,
                    profile=profile)
            ret['Subscriptions'] = list_subscriptions_by_topic(arn, region=region, key=key,
                    keyid=keyid, profile=profile)
            # Grab extended attributes for the above subscriptions
            for sub in range(len(ret['Subscriptions'])):
                sub_arn = ret['Subscriptions'][sub]['SubscriptionArn']
                if not sub_arn.startswith('arn:aws:sns:'):
                    # Sometimes a sub is in e.g. PendingAccept or other
                    # wierd states and doesn't have an ARN yet
                    log.debug('Subscription with invalid ARN %s skipped...', sub_arn)
                    continue
                deets = get_subscription_attributes(SubscriptionArn=sub_arn, region=region,
                        key=key, keyid=keyid, profile=profile)
                ret['Subscriptions'][sub].update(deets)
    return ret