<commit_before>#!/usr/bin/env python
# encoding: utf-8
"""
api.py

Created by <NAME> on 2012-12-30.
Copyright (c) 2009-2013 Exa Networks. All rights reserved.
"""

import time

from exabgp.bgp.message.direction import IN
from exabgp.bgp.message import Message

from exabgp.configuration.environment import environment

class APIOptions (object):
	def __init__ (self):
		self.receive_packets = False
		self.send_packets = False

		self.neighbor_changes = False
		self.receive_notifications = False
		self.receive_opens = False
		self.receive_keepalives = False
		self.receive_updates = False
		self.receive_refresh = False
		self.receive_operational = False

def hexstring (value):
	def spaced (value):
		for v in value:
			yield '%02X' % ord(v)
	return ''.join(spaced(value))


class Text (object):
	def __init__ (self,version):
		self.version = version

	def reset (self,peer):
		return None

	def increase (self,peer):
		return None

	def up (self,peer):
		return 'neighbor %s up\n' % peer.neighbor.peer_address

	def connected (self,peer):
		return 'neighbor %s connected\n' % peer.neighbor.peer_address

	def down (self,peer,reason=''):
		return 'neighbor %s down - %s\n' % (peer.neighbor.peer_address,reason)

	def shutdown (self,peer_address):
		return 'shutdown %s\n' % peer_address

	def notification (self,peer,code,subcode,data):
		return 'notification code %d subcode %d data %s\n' % (code,subcode,hexstring(data))

	def receive (self,peer,category,header,body):
		return 'neighbor %s received %d header %s body %s\n' % (peer.neighbor.peer_address,category,hexstring(header),hexstring(body))

	def keepalive (self,peer):
		return 'neighbor %s keepalive\n' % peer.neighbor.peer_address

	def open (self,peer,direction,sent_open):
		return 'neighbor %s open direction %s version %d asn %d hold_time %s router_id %s capabilities [%s]\n' % (peer.neighbor.peer_address,direction,sent_open.version, sent_open.asn, sent_open.hold_time, sent_open.router_id,str(sent_open.capabilities).lower())

	def send (self,peer,category,header,body):
		return 'neighbor %s sent %d header %s body %s\n' % (peer.neighbor.peer_address,category,hexstring(header),hexstring(body))

	def update (self,peer,update):
		neighbor = peer.neighbor.peer_address
		r = 'neighbor %s update start\n' % neighbor
		attributes = str(update.attributes)
		for nlri in update.nlris:
			if nlri.action == IN.announced:
				if nlri.nexthop:
					r += 'neighbor %s announced route %s next-hop %s%s\n' % (neighbor,nlri.nlri(),nlri.nexthop.inet(),attributes)
				else:
					# This is an EOR
					r += 'neighbor %s announced %s %s\n' % (neighbor,nlri.nlri(),attributes)
			else:
				r += 'neighbor %s withdrawn route %s\n' % (neighbor,nlri.nlri())
		r += 'neighbor %s update end\n' % neighbor
		return r

	def refresh (self,peer,refresh):
		return 'neighbor %s route-refresh afi %s safi %s %s' % (
			peer.neighbor.peer_address,refresh.afi,refresh.safi,refresh.reserved
		)
<commit_msg>New setting is now also supported for the text encoder.<commit_after>#!/usr/bin/env python
# encoding: utf-8
"""
api.py

Created by <NAME> on 2012-12-30.
Copyright (c) 2009-2013 Exa Networks. All rights reserved.
"""

import time

from exabgp.bgp.message.direction import IN
from exabgp.bgp.message import Message

from exabgp.configuration.environment import environment

class APIOptions (object):
	def __init__ (self):
		self.receive_packets = False
		self.send_packets = False

		self.neighbor_changes = False
		self.receive_notifications = False
		self.receive_opens = False
		self.receive_keepalives = False
		self.receive_updates = False
		self.receive_refresh = False
		self.receive_operational = False

def hexstring (value):
	def spaced (value):
		for v in value:
			yield '%02X' % ord(v)
	return ''.join(spaced(value))


class Text (object):
	def __init__ (self,version):
		self.version = version
		
	def _header_body(self,header,body):
		header = 'header %s' % hexstring(header) if header else ''
		body = 'body %s' % hexstring(body) if body else ''
		
		return ' '.join([header,body])

	def reset (self,peer):
		return None

	def increase (self,peer):
		return None

	def up (self,peer):
		return 'neighbor %s up\n' % peer.neighbor.peer_address

	def connected (self,peer):
		return 'neighbor %s connected\n' % peer.neighbor.peer_address

	def down (self,peer,reason=''):
		return 'neighbor %s down - %s\n' % (peer.neighbor.peer_address,reason)

	def shutdown (self,peer_address):
		return 'shutdown %s\n' % peer_address

	def notification (self,peer,code,subcode,data):
		return 'notification code %d subcode %d data %s\n' % (code,subcode,hexstring(data))

	def receive (self,peer,category,header,body):
		return 'neighbor %s received %d header %s body %s\n' % (peer.neighbor.peer_address,category,hexstring(header),hexstring(body))

	def keepalive (self,peer,header,body):
		return 'neighbor %s keepalive %s\n' % (peer.neighbor.peer_address,self._header_body(header,body))

	def open (self,peer,direction,sent_open,header,body):
		return 'neighbor %s open direction %s version %d asn %d hold_time %s router_id %s capabilities [%s] %s\n' % (peer.neighbor.peer_address,direction,sent_open.version, sent_open.asn, sent_open.hold_time, sent_open.router_id,str(sent_open.capabilities).lower(),self._header_body(header,body))

	def send (self,peer,category,header,body):
		return 'neighbor %s sent %d header %s body %s\n' % (peer.neighbor.peer_address,category,hexstring(header),hexstring(body))

	def update (self,peer,update,header,body):	
		neighbor = peer.neighbor.peer_address
		r = 'neighbor %s update start\n' % neighbor
		attributes = str(update.attributes)
		for nlri in update.nlris:
			if nlri.action == IN.announced:
				if nlri.nexthop:
					r += 'neighbor %s announced route %s next-hop %s%s\n' % (neighbor,nlri.nlri(),nlri.nexthop.inet(),attributes)
				else:
					# This is an EOR
					r += 'neighbor %s announced %s %s\n' % (neighbor,nlri.nlri(),attributes)
			else:
				r += 'neighbor %s withdrawn route %s\n' % (neighbor,nlri.nlri())
		if header or body:
			r += '%s\n' % self._header_body(header,body)
		r += 'neighbor %s update end\n' % neighbor
		return r

	def refresh (self,peer,refresh,header,body):
		header = 'header %s' % hexstring(header) if header else ''
		body = 'body %s' % hexstring(body) if body else ''
		return 'neighbor %s route-refresh afi %s safi %s %s %s\n' % (
			peer.neighbor.peer_address,refresh.afi,refresh.safi,refresh.reserved,self._header_body(header,body)
		)

{'fraction_non_alphanumeric': 0.13218923933209648, 'fraction_numerical': 0.005875077303648732, 'mean_word_length': 4.644851657940663, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4103912', 'n_tokens_mistral': 2450, 'n_tokens_neox': 2243, 'n_words': 575}