def _format_token(self, dt, token, locale):
        """
        Formats a DateTime instance with a given token and locale.

        :param dt: The instance to format
        :type dt: pendulum.DateTime

        :param token: The token to use
        :type token: str

        :param locale: The locale to use
        :type locale: Locale

        :rtype: str
        """
        if token in self._DATE_FORMATS:
            fmt = locale.get("custom.date_formats.{}".format(token))
            if fmt is None:
                fmt = self._DEFAULT_DATE_FORMATS[token]

            return self.format(dt, fmt, locale)

        if token in self._LOCALIZABLE_TOKENS:
            return self._format_localizable_token(dt, token, locale)

        if token in self._TOKENS_RULES:
            return self._TOKENS_RULES[token](dt)

        # Timezone
        if token in ["ZZ", "Z"]:
            if dt.tzinfo is None:
                return ""

            separator = ":" if token == "Z" else ""
            offset = dt.utcoffset() or datetime.timedelta()
            minutes = offset.total_seconds() / 60

            if minutes >= 0:
                sign = "+"
            else:
                sign = "-"

            hour, minute = divmod(abs(int(minutes)), 60)

            return "{}{:02d}{}{:02d}".format(sign, hour, separator, minute)
def _format_token ( self , dt , token , locale ) : if token in self . _DATE_FORMATS : fmt = locale . get ( "custom.date_formats.{}" . format ( token ) ) if fmt is None : fmt = self . _DEFAULT_DATE_FORMATS [ token ] return self . format ( dt , fmt , locale ) if token in self . _LOCALIZABLE_TOKENS : return self . _format_localizable_token ( dt , token , locale ) if token in self . _TOKENS_RULES : return self . _TOKENS_RULES [ token ] ( dt ) if token in [ "ZZ" , "Z" ] : if dt . tzinfo is None : return "" separator = ":" if token == "Z" else "" offset = dt . utcoffset ( ) or datetime . timedelta ( ) minutes = offset . total_seconds ( ) / 60 if minutes >= 0 : sign = "+" else : sign = "-" hour , minute = divmod ( abs ( int ( minutes ) ) , 60 ) return "{}{:02d}{}{:02d}" . format ( sign , hour , separator , minute )
Formats a DateTime instance with a given token and locale.

        :param dt: The instance to format
        :type dt: pendulum.DateTime

        :param token: The token to use
        :type token: str

        :param locale: The locale to use
        :type locale: Locale

        :rtype: str