<commit_before># encoding: utf-8
"""
community.py

Created by <NAME> on 2009-11-05.
Copyright (c) 2009-2015 Exa Networks. All rights reserved.
"""

# ============================================================== Communities (8)
# http://www.iana.org/assignments/bgp-extended-communities

from exabgp.bgp.message.update.attribute.attribute import Attribute
from exabgp.bgp.message.update.attribute.community.community import Community

from exabgp.bgp.message.notification import Notify


class Communities (Attribute):
	ID = Attribute.CODE.COMMUNITY
	FLAG = Attribute.Flag.TRANSITIVE | Attribute.Flag.OPTIONAL

	# __slots__ = ['communities']

	def __init__ (self, communities=None):
		# Must be None as = param is only evaluated once
		if communities:
			self.communities = communities
		else:
			self.communities = []

	def add (self, data):
		return self.communities.append(data)

	def pack (self, negotiated=None):
		if len(self.communities):
			return self._attribute(''.join([c.pack() for c in self.communities]))
		return ''

	def __repr__ (self):
		l = len(self.communities)
		if l > 1:
			return "[ %s ]" % " ".join(repr(community) for community in self.communities)
		if l == 1:
			return repr(self.communities[0])
		return ""
	
	def json (self):<commit_msg>Communities: sort the values in representation<commit_after># encoding: utf-8
"""
community.py

Created by <NAME> on 2009-11-05.
Copyright (c) 2009-2015 Exa Networks. All rights reserved.
"""

# ============================================================== Communities (8)
# http://www.iana.org/assignments/bgp-extended-communities

from exabgp.bgp.message.update.attribute.attribute import Attribute
from exabgp.bgp.message.update.attribute.community.community import Community

from exabgp.bgp.message.notification import Notify


class Communities (Attribute):
	ID = Attribute.CODE.COMMUNITY
	FLAG = Attribute.Flag.TRANSITIVE | Attribute.Flag.OPTIONAL

	# __slots__ = ['communities']

	def __init__ (self, communities=None):
		# Must be None as = param is only evaluated once
		if communities:
			self.communities = communities
		else:
			self.communities = []

	def add (self, data):
		return self.communities.append(data)

	def pack (self, negotiated=None):
		if len(self.communities):
			return self._attribute(''.join([c.pack() for c in self.communities]))
		return ''

	def __repr__ (self):
		l = len(self.communities)
		if l > 1:
			return "[ %s ]" % " ".join(repr(community) for community in sorted(self.communities))
		if l == 1:
			return repr(self.communities[0])
		return ""
	
	def json (self):
{'fraction_non_alphanumeric': 0.1672487388436166, 'fraction_numerical': 0.01629802095459837, 'mean_word_length': 4.485106382978723, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '677917', 'n_tokens_mistral': 899, 'n_tokens_neox': 791, 'n_words': 212}