<commit_before>import sys
from pyccn import CCN, Name, Interest, ContentObject, Key, Closure

class ccnput(Closure.Closure):
	def __init__(self, name, content):
		self.handle = CCN.CCN()
		self.name = Name.Name(name)
		self.content = self.prepareContent(content, self.handle.getDefaultKey())

	# this is so we don't have to do signing each time someone requests data
	# if we will be serving content multiple times
	def prepareContent(self, content, key):
		co = ContentObject.ContentObject()

		# since they want us to use versions and segments append those to our name
		co.name = Name.Name(self.name) # making copy, so any changes to co.name won't change self.name
		co.name.appendVersion() # timestamp which is our version
		co.name += b'\x00' # first segment

		co.content = content

		si = co.signedInfo
		si.publisherPublicKeyDigest = key.publicKeyID
		si.type = ContentObject.CONTENT_DATA
		si.finalBlockID = b'\x00' # no more segments available
		si.keyLocator = Key.KeyLocator(key)

		co.sign(key)
		return co

	# Called when we receive interest
	# once data is sent signal ccn_run() to exit
	def upcall(self, kind, info):
		if kind != Closure.UPCALL_INTEREST:
			return Closure.RESULT_OK

		self.handle.put(self.content) # send the prepared data
		self.handle.setRunTimeout(0) # finish run()

		return Closure.RESULT_INTEREST_CONSUMED

	def start(self):
		# register our name, so upcall is called when interest arrives
		self.handle.setInterestFilter(self.name, self)

		print "listening ..."

		# enter ccn loop (upcalls won't be called without it, get
		# doesn't require it as well)
		# -1 means wait forever
		self.handle.run(-1)

def usage():
	print("Usage: %s <uri>" % sys.argv[0])
	print("Reads data from stdin and sends it")
	sys.exit(1)

if __name__ == '__main__':
	if len(sys.argv) != 2:
		usage()
	if sys.stdin.isatty():
		usage()

	name = sys.argv[1]
	content = sys.stdin.read()

	put = ccnput(name, content)
	put.start()<commit_msg>Modified ccnput.py to work with new PyCCN<commit_after>import sys
import pyccn

class ccnput(pyccn.Closure):
	def __init__(self, name, content):
		self.handle = pyccn.CCN()
		self.name = pyccn.Name(name)
		self.content = self.prepareContent(content, self.handle.getDefaultKey())

	# this is so we don't have to do signing each time someone requests data
	# if we will be serving content multiple times
	def prepareContent(self, content, key):
		# create a new data packet
		co = pyccn.ContentObject()

		# since they want us to use versions and segments append those to our name
		co.name = self.name.appendVersion().appendSegment(0)

		# place the content
		co.content = content

		si = co.signedInfo

		# key used to sign data (required by ccnx)
		si.publisherPublicKeyDigest = key.publicKeyID

		# how to obtain the key (required by ccn); here we attach the
		# key to the data (not too secure), we could also provide name
		# of the key under which it is stored in DER format
		si.keyLocator = pyccn.KeyLocator(key)

		# data type (not needed, since DATA is the default)
		si.type = pyccn.CONTENT_DATA

		# number of the last segment (0 - i.e. this is the only
		# segment)
		si.finalBlockID = pyccn.Name.num2seg(0)

		# signing the packet
		co.sign(key)

		return co

	# Called when we receive interest
	# once data is sent signal ccn_run() to exit
	def upcall(self, kind, info):
		if kind != pyccn.UPCALL_INTEREST:
			return pyccn.RESULT_OK

		self.handle.put(self.content) # send the prepared data
		self.handle.setRunTimeout(0) # finish run() by changing its timeout to 0

		return pyccn.RESULT_INTEREST_CONSUMED

	def start(self):
		# register our name, so upcall is called when interest arrives
		self.handle.setInterestFilter(self.name, self)

		print "listening ..."

		# enter ccn loop (upcalls won't be called without it, get
		# doesn't require it as well)
		# -1 means wait forever
		self.handle.run(-1)

def usage():
	print("Usage: %s <uri>" % sys.argv[0])
	print("Reads data from stdin and sends it")
	sys.exit(1)

if __name__ == '__main__':
	if len(sys.argv) != 2:
		usage()
	if sys.stdin.isatty():
		usage()

	name = sys.argv[1]
	content = sys.stdin.read()

	put = ccnput(name, content)
	put.start()

{'fraction_non_alphanumeric': 0.1039272030651341, 'fraction_numerical': 0.005507662835249042, 'mean_word_length': 3.8066743383199078, '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': '5959457', 'n_tokens_mistral': 1508, 'n_tokens_neox': 1387, 'n_words': 469}