text
stringlengths
0
828
stream.write(chunk)
stream.seek(0)
return stream"
869,"def add(one, two=4, three=False):
''' This function adds two number.
:param one: first number to add
:param two: second number to add
:rtype: int
'''
s = str(int(one) + int(two))
logging.debug('logging sum from hello.py:' + s)
print 'printing sum from hello.py:', s
return s"
870,"def queue(self):
""""""Message queue queue.""""""
with self.connection_pool.acquire(block=True) as conn:
return Q(
self.routing_key,
exchange=self.exchange,
routing_key=self.routing_key
)(conn)"
871,"def exists(self):
""""""Test if this queue exists in the AMQP store.
Note: This doesn't work with redis as declaring queues has not effect
except creating the exchange.
:returns: True if the queue exists, else False.
:rtype: bool
""""""
try:
queue = self.queue
queue.queue_declare(passive=True)
except NotFound:
return False
except ChannelError as e:
if e.reply_code == '404':
return False
raise e
return True"
872,"def producer(self, conn):
""""""Get a consumer for a connection.""""""
return Producer(
conn,
exchange=self.exchange,
routing_key=self.routing_key,
auto_declare=True,
)"
873,"def consumer(self, conn):
""""""Get a consumer for a connection.""""""
return Consumer(
connection=conn,
queue=self.queue.name,
exchange=self.exchange.name,
exchange_type=self.exchange.type,
durable=self.exchange.durable,
auto_delete=self.exchange.auto_delete,
routing_key=self.routing_key,
no_ack=self.no_ack,
)"
874,"def create_producer(self):
""""""Context manager that yields an instance of ``Producer``.""""""
with self.connection_pool.acquire(block=True) as conn:
yield self.producer(conn)"
875,"def create_consumer(self):
""""""Context manager that yields an instance of ``Consumer``.""""""
with self.connection_pool.acquire(block=True) as conn:
yield self.consumer(conn)"
876,"def publish(self, events):
""""""Publish events.""""""
assert len(events) > 0
with self.create_producer() as producer:
for event in events:
producer.publish(event)"
877,"def consume(self, payload=True):
""""""Consume events.""""""
with self.create_consumer() as consumer:
for msg in consumer.iterqueue():
yield msg.payload if payload else msg"
878,"def get_initial(self, *args, **kwargs):
""""""
Gathers initial form values from user and profile objects
suitable for using as form's initial data.
""""""
initial = {}
for field in self.fields:
value = None
if hasattr(self.user, field):
value = getattr(self.user, field)
if hasattr(self.profile, field):
value = getattr(self.profile, field)
if value:
initial.update({
field: value
})
if hasattr(self.profile, 'dob'):