本文整理汇总了Python中common.file_props.FilesProp类的典型用法代码示例。如果您正苦于以下问题:Python FilesProp类的具体用法?Python FilesProp怎么用?Python FilesProp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FilesProp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _remove_transfer
def _remove_transfer(self, iter_, sid, file_props):
self.model.remove(iter_)
if not file_props:
return
if file_props.tt_account:
# file transfer is set
account = file_props.tt_account
if account in gajim.connections:
# there is a connection to the account
gajim.connections[account].remove_transfer(file_props)
if file_props.type_ == 'r': # we receive a file
other = file_props.sender
else: # we send a file
other = file_props.receiver
if isinstance(other, str):
jid = gajim.get_jid_without_resource(other)
else: # It's a Contact instance
jid = other.jid
for ev_type in ('file-error', 'file-completed', 'file-request-error',
'file-send-error', 'file-stopped'):
for event in gajim.events.get_events(account, jid, [ev_type]):
if event.parameters.sid == file_props.sid:
gajim.events.remove_events(account, jid, event)
gajim.interface.roster.draw_contact(jid, account)
gajim.interface.roster.show_title()
FilesProp.deleteFileProp(file_props)
del(file_props)
示例2: _bytestreamSetCB
def _bytestreamSetCB(self, con, iq_obj):
target = iq_obj.getAttr('to')
id_ = iq_obj.getAttr('id')
query = iq_obj.getTag('query')
sid = query.getAttr('sid')
file_props = FilesProp.getFileProp(self.name, sid)
streamhosts = []
for item in query.getChildren():
if item.getName() == 'streamhost':
host_dict = {
'state': 0,
'target': target,
'id': id_,
'sid': sid,
'initiator': self._ft_get_from(iq_obj)
}
for attr in item.getAttrs():
host_dict[attr] = item.getAttr(attr)
if 'host' not in host_dict:
continue
if 'jid' not in host_dict:
continue
if 'port' not in host_dict:
continue
streamhosts.append(host_dict)
file_props = FilesProp.getFilePropBySid(sid)
if file_props is not None:
if file_props.type_ == 's': # FIXME: remove fast xmlns
# only psi do this
if file_props.streamhosts:
file_props.streamhosts.extend(streamhosts)
else:
file_props.streamhosts = streamhosts
gajim.socks5queue.connect_to_hosts(self.name, sid,
self.send_success_connect_reply, None)
raise nbxmpp.NodeProcessed
else:
log.warning('Gajim got streamhosts for unknown transfer. Ignoring it.')
raise nbxmpp.NodeProcessed
file_props.streamhosts = streamhosts
def _connection_error(sid):
self._connect_error(sid, 'item-not-found', 'cancel',
msg='Could not connect to given hosts')
if file_props.type_ == 'r':
gajim.socks5queue.connect_to_hosts(self.name, sid,
self.send_success_connect_reply, _connection_error)
raise nbxmpp.NodeProcessed
示例3: on_yes
def on_yes(dummy, fjid, file_props, account):
# Delete old file
os.remove(file_props.file_name)
jid, resource = gajim.get_room_and_nick_from_fjid(fjid)
if resource:
contact = gajim.contacts.get_contact(account, jid, resource)
else:
contact = gajim.contacts.get_contact_with_highest_priority(
account, jid)
fjid = contact.get_full_jid()
# Request the file to the sender
sid = helpers.get_random_string_16()
new_file_props = FilesProp.getNewFileProp(account, sid)
new_file_props.file_name = file_props.file_name
new_file_props.name = file_props.name
new_file_props.desc = file_props.desc
new_file_props.size = file_props.size
new_file_props.date = file_props.date
new_file_props.hash_ = file_props.hash_
new_file_props.type_ = 'r'
tsid = gajim.connections[account].start_file_transfer(fjid,
new_file_props,
True)
new_file_props.transport_sid = tsid
self.add_transfer(account, contact, new_file_props)
示例4: _siResultCB
def _siResultCB(self, con, iq_obj):
file_props = FilesProp.getFileProp(self.name, iq_obj.getAttr('id'))
if not file_props:
return
if file_props.request_id:
# we have already sent streamhosts info
return
file_props.receiver = self._ft_get_from(iq_obj)
si = iq_obj.getTag('si')
file_tag = si.getTag('file')
range_tag = None
if file_tag:
range_tag = file_tag.getTag('range')
if range_tag:
offset = range_tag.getAttr('offset')
if offset:
file_props.offset = int(offset)
length = range_tag.getAttr('length')
if length:
file_props.length = int(length)
feature = si.setTag('feature')
if feature.getNamespace() != nbxmpp.NS_FEATURE:
return
form_tag = feature.getTag('x')
form = nbxmpp.DataForm(node=form_tag)
field = form.getField('stream-method')
if field.getValue() == nbxmpp.NS_BYTESTREAM:
self._send_socks5_info(file_props)
raise nbxmpp.NodeProcessed
if field.getValue() == nbxmpp.NS_IBB:
sid = file_props.sid
file_props.transport_sid = sid
fp = open(file_props.file_name, 'r')
self.OpenStream(sid, file_props.receiver, fp)
raise nbxmpp.NodeProcessed
示例5: _result_socks5_sid
def _result_socks5_sid(self, sid, hash_id):
"""
Store the result of SHA message from auth
"""
file_props = FilesProp.getFilePropBySid(sid)
file_props.hash_ = hash_id
return
示例6: _connect_error
def _connect_error(self,sid, code=404):
"""
Called when there is an error establishing BS connection, or when
connection is rejected
"""
if not self.connection or self.connected < 2:
return
file_props = FilesProp.getFileProp(self.name, sid)
if file_props is None:
log.error('can not send iq error on failed transfer')
return
msg_dict = {
404: 'Could not connect to given hosts',
405: 'Cancel',
406: 'Not acceptable',
}
msg = msg_dict[code]
if file_props.type_ == 's':
to = file_props.receiver
else:
to = file_props.sender
iq = nbxmpp.Iq(to=to, typ='error')
iq.setAttr('id', file_props.sid)
err = iq.setTag('error')
err.setAttr('code', unicode(code))
err.setData(msg)
self.connection.send(iq)
if code == 404:
self.disconnect_transfer(file_props)
file_props.error = -3
from common.connection_handlers_events import \
FileRequestErrorEvent
gajim.nec.push_incoming_event(FileRequestErrorEvent(None,
conn=self, jid=to, file_props=file_props, error_msg=msg))
示例7: OpenStream
def OpenStream(self, sid, to, fp, blocksize=4096):
"""
Start new stream. You should provide stream id 'sid', the endpoind jid
'to', the file object containing info for send 'fp'. Also the desired
blocksize can be specified.
Take into account that recommended stanza size is 4k and IBB uses
base64 encoding that increases size of data by 1/3.
"""
if not nbxmpp.JID(to).getResource():
return
file_props = FilesProp.getFilePropBySid(sid)
file_props.direction = '|>' + to
file_props.block_size = blocksize
file_props.fp = fp
file_props.seq = 0
file_props.error = 0
file_props.paused = False
file_props.received_len = 0
file_props.last_time = time.time()
file_props.connected = True
file_props.completed = False
file_props.disconnect_cb = None
file_props.continue_cb = None
syn = nbxmpp.Protocol('iq', to, 'set', payload=[nbxmpp.Node(
nbxmpp.NS_IBB + ' open', {'sid': file_props.transport_sid,
'block-size': blocksize, 'stanza': 'iq'})])
self.connection.send(syn)
file_props.syn_id = syn.getID()
return file_props
示例8: get_send_file_props
def get_send_file_props(self, account, contact, file_path, file_name,
file_desc=''):
"""
Create new file_props object and set initial file transfer
properties in it
"""
if os.path.isfile(file_path):
stat = os.stat(file_path)
else:
dialogs.ErrorDialog(_('Invalid File'), _('File: ') + file_path)
return None
if stat[6] == 0:
dialogs.ErrorDialog(_('Invalid File'),
_('It is not possible to send empty files'))
return None
file_props = FilesProp.getNewFileProp(account,
sid=helpers.get_random_string_16())
mod_date = os.path.getmtime(file_path)
file_props.file_name = file_path
file_props.name = file_name
file_props.date = self.__convert_date(mod_date)
file_props.type_ = 's'
file_props.desc = file_desc
file_props.elapsed_time = 0
file_props.size = stat[6]
file_props.sender = account
file_props.receiver = contact
file_props.tt_account = account
return file_props
示例9: _connect_error
def _connect_error(self, sid, error, error_type, msg=None):
"""
Called when there is an error establishing BS connection, or when
connection is rejected
"""
if not self.connection or self.connected < 2:
return
file_props = FilesProp.getFileProp(self.name, sid)
if file_props is None:
log.error('can not send iq error on failed transfer')
return
if file_props.type_ == 's':
to = file_props.receiver
else:
to = file_props.sender
iq = nbxmpp.Iq(to=to, typ='error')
iq.setAttr('id', file_props.request_id)
err = iq.setTag('error')
err.setAttr('type', error_type)
err.setTag(error, namespace=nbxmpp.NS_STANZAS)
self.connection.send(iq)
if msg:
self.disconnect_transfer(file_props)
file_props.error = -3
from common.connection_handlers_events import \
FileRequestErrorEvent
gajim.nec.push_incoming_event(FileRequestErrorEvent(None,
conn=self, jid=to, file_props=file_props, error_msg=msg))
示例10: on_remove_menuitem_activate
def on_remove_menuitem_activate(self, widget):
selected = self.tree.get_selection().get_selected()
if not selected or not selected[1]:
return
s_iter = selected[1]
sid = self.model[s_iter][C_SID]
file_props = FilesProp.getFilePropByType(sid[0], sid[1:])
self._remove_transfer(s_iter, sid, file_props)
self.set_all_insensitive()
示例11: disconnect
def disconnect(self, connection):
if self.host_tester:
self.host_tester.disconnect()
FilesProp.deleteFileProp(self.host_tester.file_props)
self.host_tester = None
if self.receiver_tester:
self.receiver_tester.disconnect()
FilesProp.deleteFileProp(self.receiver_tester.file_props)
self.receiver_tester = None
try:
self.connections.remove(connection)
except ValueError:
pass
if connection == self.active_connection:
self.active_connection = None
if self.state != S_FINISHED:
self.state = S_INITIAL
self.try_next_connection()
示例12: on_cleanup_button_clicked
def on_cleanup_button_clicked(self, widget):
i = len(self.model) - 1
while i >= 0:
iter_ = self.model.get_iter((i))
sid = self.model[iter_][C_SID]
file_props = FilesProp.getFilePropByType(sid[0], sid[1:])
if is_transfer_stopped(file_props):
self._remove_transfer(iter_, sid, file_props)
i -= 1
self.tree.get_selection().unselect_all()
self.set_all_insensitive()
示例13: on_open_folder_menuitem_activate
def on_open_folder_menuitem_activate(self, widget):
selected = self.tree.get_selection().get_selected()
if not selected or not selected[1]:
return
s_iter = selected[1]
sid = self.model[s_iter][C_SID]
file_props = FilesProp.getFilePropByType(sid[0], sid[1:])
if not file_props.file_name:
return
path = os.path.split(file_props.file_name)[0]
if os.path.exists(path) and os.path.isdir(path):
helpers.launch_file_manager(path)
示例14: IBBAllIqHandler
def IBBAllIqHandler(self, conn, stanza):
"""
Handle remote side reply about if it agree or not to receive our
datastream.
Used internally. Raises xmpppy event specfiying if the data transfer
is agreed upon.
"""
syn_id = stanza.getID()
log.debug('IBBAllIqHandler called syn_id->%s' % syn_id)
for file_props in FilesProp.getAllFileProp():
if not file_props.direction or not file_props.connected:
# It's socks5 bytestream
# Or we closed the IBB stream
continue
if file_props.syn_id == syn_id:
if stanza.getType() == 'error':
if file_props.direction[0] == '<':
conn.Event('IBB', 'ERROR ON RECEIVE', file_props)
else:
conn.Event('IBB', 'ERROR ON SEND', file_props)
elif stanza.getType() == 'result':
if file_props.direction[0] == '|':
file_props.direction = file_props.direction[1:]
self.SendHandler()
else:
conn.send(nbxmpp.Error(stanza,
nbxmpp.ERR_UNEXPECTED_REQUEST))
break
else:
if stanza.getTag('data'):
sid = stanza.getTagAttr('data', 'sid')
file_props = FilesProp.getFilePropByTransportSid(self.name, sid)
if file_props.connected and self.IBBMessageHandler(conn,
stanza):
reply = stanza.buildReply('result')
reply.delChild('data')
conn.send(reply)
raise nbxmpp.NodeProcessed
elif syn_id == self.last_sent_ibb_id:
self.SendHandler()
示例15: _siErrorCB
def _siErrorCB(self, con, iq_obj):
si = iq_obj.getTag('si')
profile = si.getAttr('profile')
if profile != nbxmpp.NS_FILE:
return
file_props = FilesProp.getFileProp(self.name, iq_obj.getAttr('id'))
if not file_props:
return
jid = self._ft_get_from(iq_obj)
file_props.error = -3
from common.connection_handlers_events import FileRequestErrorEvent
gajim.nec.push_incoming_event(FileRequestErrorEvent(None, conn=self,
jid=jid, file_props=file_props, error_msg=''))
raise nbxmpp.NodeProcessed