desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
':return: UIAccessibilityTraits :rtype: lldb.SBValue'
@property def traits(self):
if (self._traits is None): name = '_traits' if (self.element.GetIndexOfChildWithName(name) == NOT_FOUND): self._traits = fb.evaluateExpressionValue('(int)[{} traits]'.format(self.element_value)) else: self._traits = self.element.GetChildMemberWithName(name) return self._traits
':return: UIAccessibilityTraits value :rtype: int'
@property def traits_value(self):
return int(self.traits.GetValue())
':return: UIAccessibilityTraits summary :rtype: str'
@property def traits_summary(self):
return self.get_traits_value_string(self.traits_value)
':return: XCUIElement frame :rtype: lldb.SBValue'
@property def frame(self):
if (self._frame is None): import_uikit() name = '_frame' if (self.element.GetIndexOfChildWithName(name) == NOT_FOUND): self._frame = fb.evaluateExpressionValue('(CGRect)[{} frame]'.format(self.element_value)) else: self._frame = self.element.GetChildMemberWithName(name) return self._frame
':return: XCUIElement frame summary :rtype: str'
@property def frame_summary(self):
return CGRect(self.frame).summary()
':return: XCUIElement identifier :rtype: lldb.SBValue'
@property def identifier(self):
if (self._identifier is None): name = '_identifier' if (self.element.GetIndexOfChildWithName(name) == NOT_FOUND): self._identifier = fb.evaluateExpressionValue('(NSString *)[{} identifier]'.format(self.element_value)) else: self._identifier = self.element.GetChildMemberWithName(name) return self._identifier
':return: XCUIElement identifier value :rtype: str'
@property def identifier_value(self):
return normalize_summary(self.identifier.GetSummary())
':return: XCUIElement identifier summary :rtype: str | None'
@property def identifier_summary(self):
if (len(self.identifier_value) == 0): return None return "identifier: '{}'".format(self.identifier_value)
':return: XCUIElement value :rtype: lldb.SBValue'
@property def value(self):
if (self._value is None): name = '_value' if (self.element.GetIndexOfChildWithName(name) == NOT_FOUND): self._value = fb.evaluateExpressionValue('(NSString *)[{} value]'.format(self.element_value)) else: self._value = self.element.GetChildMemberWithName(name) return self._value
':return: XCUIElement value value :rtype: str'
@property def value_value(self):
return normalize_summary(self.value.GetSummary())
':return: XCUIElement value summary :rtype: str | None'
@property def value_summary(self):
if (len(self.value_value) == 0): return None return "value: '{}'".format(self.value_value)
':return: XCUIElement placeholder value :rtype: lldb.SBValue'
@property def placeholder(self):
if (self._placeholderValue is None): name = '_placeholderValue' if (self.element.GetIndexOfChildWithName(name) == NOT_FOUND): self._placeholderValue = fb.evaluateExpressionValue('(NSString *)[{} placeholderValue]'.format(self.element_value)) else: self._placeholderValue = self.element.GetChildMemberWithName(name) return self._placeholderValue
':return: XCUIElement placeholderValue value :rtype: str'
@property def placeholder_value(self):
return normalize_summary(self.placeholder.GetSummary())
':return: XCUIElement placeholderValue summary :rtype: str | None'
@property def placeholder_summary(self):
if (len(self.placeholder_value) == 0): return None return "placeholderValue: '{}'".format(self.placeholder_value)
':return: XCUIElement label :rtype: lldb.SBValue'
@property def label(self):
if (self._label is None): name = '_label' if (self.element.GetIndexOfChildWithName(name) == NOT_FOUND): self._label = fb.evaluateExpressionValue('(NSString *)[{} label]'.format(self.element_value)) else: self._label = self.element.GetChildMemberWithName(name) return self._label
':return: XCUIElement label value :rtype: str'
@property def label_value(self):
return normalize_summary(self.label.GetSummary())
':return: XCUIElement label summary :rtype: str | None'
@property def label_summary(self):
if (len(self.label_value) == 0): return None return "label: '{}'".format(self.label_value)
':return: XCUIElement title :rtype: lldb.SBValue'
@property def title(self):
if (self._title is None): name = '_title' if (self.element.GetIndexOfChildWithName(name) == NOT_FOUND): self._title = fb.evaluateExpressionValue('(NSString *)[{} title]'.format(self.element_value)) else: self._title = self.element.GetChildMemberWithName(name) return self._title
':return: XCUIElement title value :rtype: str'
@property def title_value(self):
return normalize_summary(self.title.GetSummary())
':return: XCUIElement title summary :rtype: str | None'
@property def title_summary(self):
if (len(self.title_value) == 0): return None return "title: '{}'".format(self.title_value)
':return: XCUIElement children :rtype: lldb.SBValue'
@property def children(self):
if (self._children is None): name = '_children' if (self.element.GetIndexOfChildWithName(name) == NOT_FOUND): self._children = fb.evaluateExpressionValue('(NSArray *)[{} children]'.format(self.element_value)) else: self._children = self.element.GetChildMemberWithName(name) return self._children
':return: XCUIElement children count :rtype: int'
@property def children_count(self):
return self.children.GetNumChildren()
':return: XCUIElement children list :rtype: list[lldb.SBValue]'
@property def children_list(self):
return [self.children.GetChildAtIndex(i) for i in xrange(0, self.children_count)]
':return: XCUIElement is enabled :rtype: lldb.SBValue'
@property def enabled(self):
if (self._enabled is None): name = '_enabled' if (self.element.GetIndexOfChildWithName(name) == NOT_FOUND): self._enabled = fb.evaluateExpressionValue('(BOOL)[{} enabled]'.format(self.element_value)) else: self._enabled = self.element.GetChildMemberWithName(name) return self._enabled
':return: XCUIElement is enabled value :rtype: bool'
@property def enabled_value(self):
return bool(self.enabled.GetValueAsSigned())
':return: XCUIElement is enabled summary :rtype: str | None'
@property def enabled_summary(self):
if (not self.enabled_value): return 'enabled: {}'.format(self.enabled_value) return None
':return: XCUIElement is selected :rtype: lldb.SBValue'
@property def selected(self):
if (self._selected is None): name = '_selected' if (self.element.GetIndexOfChildWithName(name) == NOT_FOUND): self._selected = fb.evaluateExpressionValue('(BOOL)[{} selected]'.format(self.element_value)) else: self._selected = self.element.GetChildMemberWithName(name) return self._selected
':return: XCUIElement is selected value :rtype: bool'
@property def selected_value(self):
return bool(self.selected.GetValueAsSigned())
':return: XCUIElement is selected summary :rtype: str | None'
@property def selected_summary(self):
if self.selected_value: return 'selected: {}'.format(self.selected_value) return None
':return: XCUIElement isMainWindow :rtype: lldb.SBValue'
@property def is_main_window(self):
if (self._isMainWindow is None): name = '_isMainWindow' if (self.element.GetIndexOfChildWithName(name) == NOT_FOUND): self._isMainWindow = fb.evaluateExpressionValue('(BOOL)[{} isMainWindow]'.format(self.element_value)) else: self._isMainWindow = self.element.GetChildMemberWithName(name) return self._isMainWindow
':return: XCUIElement isMainWindow value :rtype: bool'
@property def is_main_window_value(self):
return bool(self.is_main_window.GetValueAsSigned())
':return: XCUIElement isMainWindow summary :rtype: str | None'
@property def is_main_window_summary(self):
if self.is_main_window_value: return 'MainWindow' return None
':return: XCUIElement hasKeyboardFocus :rtype: lldb.SBValue'
@property def keyboard_focus(self):
if (self._hasKeyboardFocus is None): name = '_hasKeyboardFocus' if (self.element.GetIndexOfChildWithName(name) == NOT_FOUND): self._hasKeyboardFocus = fb.evaluateExpressionValue('(BOOL)[{} hasKeyboardFocus]'.format(self.element_value)) else: self._hasKeyboardFocus = self.element.GetChildMemberWithName(name) return self._hasKeyboardFocus
':return: XCUIElement hasKeyboardFocus value :rtype: bool'
@property def keyboard_focus_value(self):
return bool(self.keyboard_focus.GetValueAsSigned())
':return: XCUIElement hasKeyboardFocus summary :rtype: str | None'
@property def keyboard_focus_summary(self):
if self.keyboard_focus_value: return 'hasKeyboardFocus: {}'.format(self.keyboard_focus_value) return None
':return: XCUIElement hasFocus :rtype: lldb.SBValue'
@property def focus(self):
if (self._hasFocus is None): name = '_hasFocus' if (self.element.GetIndexOfChildWithName(name) == NOT_FOUND): self._hasFocus = fb.evaluateExpressionValue('(BOOL)[{} hasFocus]'.format(self.element_value)) else: self._hasFocus = self.element.GetChildMemberWithName(name) return self._hasFocus
':return: XCUIElement hasFocus value :rtype: bool'
@property def focus_value(self):
return bool(self.focus.GetValueAsSigned())
':return: XCUIElement hasFocus summary :rtype: str | None'
@property def focus_summary(self):
if self.focus_value: return 'hasFocus: {}'.format(self.focus_value) return None
':return: XCUIElement generation :rtype: lldb.SBValue'
@property def generation(self):
if (self._generation is None): name = '_generation' if (self.element.GetIndexOfChildWithName(name) == NOT_FOUND): self._generation = fb.evaluateExpressionValue('(unsigned int)[{} generation]'.format(self.element_value)) else: self._generation = self.element.GetChildMemberWithName(name) return self._generation
':return: XCUIElement generation value :rtype: int'
@property def generation_value(self):
return int(self.generation.GetValueAsUnsigned())
':return: XCUIElement horizontal size class :rtype: lldb.SBValue'
@property def horizontal_size_class(self):
if (self._horizontalSizeClass is None): name = '_horizontalSizeClass' if (self.element.GetIndexOfChildWithName(name) == NOT_FOUND): self._horizontalSizeClass = fb.evaluateExpressionValue('(int)[{} horizontalSizeClass]'.format(self.element_value)) else: self._horizontalSizeClass = self.element.GetChildMemberWithName(name) return self._horizontalSizeClass
':return: XCUIElement horizontal size class value :rtype: int'
@property def horizontal_size_class_value(self):
return int(self.horizontal_size_class.GetValue())
':return: XCUIElement horizontal size class summary'
@property def horizontal_size_class_summary(self):
return self.get_user_interface_size_class_string(self.horizontal_size_class_value)
':return: XCUIElement vertical size class :rtype: lldb.SBValue'
@property def vertical_size_class(self):
if (self._verticalSizeClass is None): name = '_verticalSizeClass' if (self.element.GetIndexOfChildWithName(name) == NOT_FOUND): self._verticalSizeClass = fb.evaluateExpressionValue('(int)[{} verticalSizeClass]'.format(self.element_value)) else: self._verticalSizeClass = self.element.GetChildMemberWithName(name) return self._verticalSizeClass
':return: XCUIElement vertical size class value :rtype: int'
@property def vertical_size_class_value(self):
return int(self.vertical_size_class.GetValue())
':return: XCUIElement vertical size class summary'
@property def vertical_size_class_summary(self):
return self.get_user_interface_size_class_string(self.vertical_size_class_value)
':return: XCUIElement uniquely identifying Objective-C code :rtype: lldb.SBValue'
@property def uniquely_identifying_objective_c_code(self):
return fb.evaluateExpressionValue('(id)[{} _uniquelyIdentifyingObjectiveCCode]'.format(self.element_value))
':return: XCUIElement uniquely identifying Objective-C code value :rtype: str'
@property def uniquely_identifying_objective_c_code_value(self):
return normalize_array_description(self.uniquely_identifying_objective_c_code.GetObjectDescription())
':return: XCUIElement uniquely identifying Swift code :rtype: lldb.SBValue'
@property def uniquely_identifying_swift_code(self):
return fb.evaluateExpressionValue('(id)[{} _uniquelyIdentifyingSwiftCode]'.format(self.element_value))
':return: XCUIElement uniquely identifying Swift code value :rtype: str'
@property def uniquely_identifying_swift_code_value(self):
return normalize_array_description(self.uniquely_identifying_swift_code.GetObjectDescription())
':return: XCUIElement is touch bar element :rtype: lldb.SBValue'
@property def is_touch_bar_element(self):
return fb.evaluateExpressionValue('(BOOL)[{} isTouchBarElement]'.format(self.element_value))
':return: XCUIElement is touch bar element value :rtype: bool'
@property def is_touch_bar_element_value(self):
return bool(self.is_touch_bar_element.GetValueAsSigned())
':return: XCUIElement is top level touch bar element :rtype: lldb.SBValue'
@property def is_top_level_touch_bar_element(self):
return fb.evaluateExpressionValue('(BOOL)[{} isTopLevelTouchBarElement]'.format(self.element_value))
':return: XCUIElement is top level touch bar element value :rtype: bool'
@property def is_top_level_touch_bar_element_value(self):
return bool(self.is_top_level_touch_bar_element.GetValueAsSigned())
':return: XCUIElement suggested hit points :rtype: lldb.SBValue'
@property def suggested_hit_points(self):
return fb.evaluateExpressionValue('(NSArray *)[{} suggestedHitpoints]'.format(self.element_value))
':return: XCUIElement suggested hit points :rtype: str'
@property def suggested_hit_points_value(self):
return normalize_array_description(self.suggested_hit_points.GetObjectDescription())
':return: XCUIElement visible frame :rtype: lldb.SBValue'
@property def visible_frame(self):
import_uikit() return fb.evaluateExpressionValue('(CGRect)[{} visibleFrame]'.format(self.element_value))
':return: XCUIElement visible frame :rtype: str'
@property def visible_frame_summary(self):
return CGRect(self.visible_frame).summary()
':return: XCUIElement depth :rtype: lldb.SBValue'
@property def depth(self):
return fb.evaluateExpressionValue('(int)[{} depth]'.format(self.element_value))
':return: XCUIElement depth :rtype: int'
@property def depth_value(self):
return int(self.depth.GetValue())
':return: XCUIElement hit point :rtype: lldb.SBValue'
@property def hit_point(self):
import_uikit() return fb.evaluateExpressionValue('(CGPoint)[{} hitPoint]'.format(self.element_value))
':return: XCUIElement hit point :rtype: str'
@property def hit_point_value(self):
return CGPoint(self.hit_point).summary()
':return: XCUIElement hit point for scrolling :rtype: lldb.SBValue'
@property def hit_point_for_scrolling(self):
import_uikit() return fb.evaluateExpressionValue('(CGPoint)[{} hitPointForScrolling]'.format(self.element_value))
':return: XCUIElement hit point for scrolling :rtype: str'
@property def hit_point_for_scrolling_value(self):
return CGPoint(self.hit_point_for_scrolling).summary()
'Returns XCElementSnapshot summary :param bool pointer: Print pointers :param bool trait: Print traits :param bool frame: Print frames :return: XCElementSnapshot summary :rtype: str'
def summary(self, pointer=False, trait=False, frame=False):
type_text = self.type_summary if pointer: type_text += ' {:#x}'.format(int(self.element_value, 16)) if trait: type_text += ' traits: {}({:#x})'.format(self.traits_summary, self.traits_value) frame_text = (self.frame_summary if frame else None) identifier = self.identifier_summary label = self.label_summary title = self.title_summary value = self.value_summary placeholder = self.placeholder_summary enabled = self.enabled_summary selected = self.selected_summary main_window = self.is_main_window_summary keyboard_focus = self.keyboard_focus_summary focus = self.focus_summary texts = [t for t in [frame_text, identifier, label, title, value, placeholder, enabled, selected, main_window, keyboard_focus, focus] if (t is not None)] return '{}: {}'.format(type_text, ', '.join(texts))
'Returns XCElementSnapshot detail summary :return: XCElementSnapshot detail summary :rtype: str'
def detail_summary(self):
texts = list() texts.append('Pointer: {:#x}'.format(int(self.element_value, 16))) texts.append('Type: {}'.format(self.type_summary)) texts.append('Depth: {}'.format(self.depth_value)) texts.append('Traits: {} ({:#x})'.format(self.traits_summary, self.traits_value)) texts.append('Frame: {}'.format(self.frame_summary)) texts.append('Visible frame: {}'.format(self.visible_frame_summary)) texts.append("Identifier: '{}'".format(self.identifier_value)) texts.append("Label: '{}'".format(self.label_value)) texts.append("Title: '{}'".format(self.title_value)) texts.append("Value: '{}'".format(self.value_value)) texts.append("Placeholder: '{}'".format(self.placeholder_value)) if (self.language != lldb.eLanguageTypeSwift): texts.append('Hit point: {}'.format(self.hit_point_value)) texts.append('Hit point for scrolling: {}'.format(self.hit_point_for_scrolling_value)) texts.append('Enabled: {}'.format(self.enabled_value)) texts.append('Selected: {}'.format(self.selected_value)) texts.append('Main Window: {}'.format(self.is_main_window_value)) texts.append('Keyboard focus: {}'.format(self.keyboard_focus_value)) texts.append('Focus: {}'.format(self.focus_value)) texts.append('Generation: {}'.format(self.generation_value)) texts.append('Horizontal size class: {}'.format(self.horizontal_size_class_summary)) texts.append('Vertical size class: {}'.format(self.vertical_size_class_summary)) texts.append('TouchBar element: {}'.format(self.is_touch_bar_element_value)) texts.append('TouchBar top level element: {}'.format(self.is_top_level_touch_bar_element_value)) texts.append('Unique Objective-C: {}'.format(self.uniquely_identifying_objective_c_code_value)) texts.append('Unique Swift: {}'.format(self.uniquely_identifying_swift_code_value)) texts.append('Suggested hit points: {}'.format(self.suggested_hit_points_value)) return '\n'.join(texts)
'Returns tree of elements in hierarchy :return: Elements hierarchy :rtype: _ElementList'
def tree(self):
children = [XCElementSnapshot(e, self.language).tree() for e in self.children_list] return _ElementList(self, children)
'Find element which has a label but doesn\'t have an identifier :param bool status_bar: Print status bar items :return: Hierarchy structure with items which has a label but doesn\'t have an identifier :rtype: _ElementList | None'
def find_missing_identifiers(self, status_bar):
if ((status_bar is not True) and (self.type_value == XCUIElementType.StatusBar)): return None children_missing = [XCElementSnapshot(e, self.language).find_missing_identifiers(status_bar=status_bar) for e in self.children_list] children_missing = [x for x in children_missing if (x is not None)] if ((self.is_missing_identifier is False) and (len(children_missing) == 0)): return None return _ElementList(self, children_missing)
'Get element type string from XCUIElementType (as int) :param int value: XCUIElementType (as int) :return: XCUIElementType string :rtype: str'
@staticmethod def get_type_value_string(value):
return XCUIElementType.name_for_value(value)
'Get element traits string from UIAccessibilityTraits (as int) :param int value: UIAccessibilityTraits (as int) :return: UIAccessibilityTraits string :rtype: str'
@staticmethod def get_traits_value_string(value):
return UIAccessibilityTraits.name_for_value(value)
'Get user interface size class string from UIUserInterfaceSizeClass (as int) :param value: UIAccessibilityTraits (as int) :return: UIUserInterfaceSizeClass string :rtype: str'
@staticmethod def get_user_interface_size_class_string(value):
return UIUserInterfaceSizeClass.name_for_value(value)
':return: Hash of all attributes and their values :rtype: dict[int, str]'
@classmethod def _attributes_by_value(cls):
class_attributes = (set(dir(cls)) - set(dir(object))) return dict([(getattr(cls, n), n) for n in class_attributes if ((not callable(getattr(cls, n))) and (not n.startswith('__')))])
'Get element type string from XCUIElementType (as int) :param int value: XCUIElementType (as int) :return: Name of type :rtype: str'
@classmethod def name_for_value(cls, value):
attributes = cls._attributes_by_value() if (value in attributes): return attributes[value] else: return 'Unknown ({:#x})'.format(value)
':return: Hash of all attributes and their values :rtype: dict[int, str]'
@classmethod def _attributes_by_value(cls):
class_attributes = (set(dir(cls)) - set(dir(object))) return dict([(getattr(cls, n), n) for n in class_attributes if ((not callable(getattr(cls, n))) and (not n.startswith('__')))])
'Get element traits string from UIAccessibilityTraits (as int) :param int value: UIAccessibilityTraits (as int) :return: UIAccessibilityTraits string :rtype: str'
@classmethod def name_for_value(cls, value):
if (value == 0): return 'None' traits = [] attributes = cls._attributes_by_value() for k in attributes.keys(): if (value & k): traits.append(attributes[k]) if (len(traits) == 0): return 'Unknown' else: return ', '.join(traits)
'Get user interface size class string from UIUserInterfaceSizeClass (as int) :param int value: UIAccessibilityTraits (as int) :return: UIUserInterfaceSizeClass string :rtype: str'
@classmethod def name_for_value(cls, value):
if (value == cls.Unspecified): return 'Unspecified' elif (value == cls.Compact): return 'Compact' elif (value == cls.Regular): return 'Regular' else: return 'Unknown ({:#x})'.format(value)
':param lldb.SBValue element: CGRect object'
def __init__(self, element):
super(CGRect, self).__init__() self.element = element
':return: CGRect summary :rtype: str'
def summary(self):
origin_element = self.element.GetChildMemberWithName('origin') origin = CGPoint(origin_element) size = self.element.GetChildMemberWithName('size') width = size.GetChildMemberWithName('width') height = size.GetChildMemberWithName('height') width_value = float(width.GetValue()) height_value = float(height.GetValue()) return '{{{}, {{{}, {}}}}}'.format(origin.summary(), width_value, height_value)
':return: CGPoint summary :rtype: str'
def summary(self):
x = self.element.GetChildMemberWithName('x') y = self.element.GetChildMemberWithName('y') x_value = float(x.GetValue()) y_value = float(y.GetValue()) return '{{{}, {}}}'.format(x_value, y_value)
'@brief Gets the uuid just used for login. @return Bool: whether operation succeed.'
def getuuid(self):
url = self.wx_conf['API_jsLogin'] params = {'appid': self.appid, 'fun': 'new', 'lang': self.wx_conf['LANG'], '_': int(time.time())} data = post(url, params, False) regx = 'window.QRLogin.code = (\\d+); window.QRLogin.uuid = "(\\S+?)"' pm = re.search(regx, data) if pm: code = pm.group(1) self.uuid = pm.group(2) return (code == '200') return False
'@brief outprint the qrcode to stdout on macos/linux or open image on windows'
def genqrcode(self):
if sys.platform.startswith('win'): url = (self.wx_conf['API_qrcode_img'] + self.uuid) params = {'t': 'webwx', '_': int(time.time())} data = post(url, params, False) if (data == ''): return qrcode_path = save_file('qrcode.jpg', data, './') os.startfile(qrcode_path) else: str2qr_terminal((self.wx_conf['API_qrcode'] + self.uuid))
'@brief wait for scaning qrcode to login @param tip 1: wait for scan qrcode 0: wait for confirm @return Bool: whether operation succeed'
def waitforlogin(self, tip=1):
time.sleep(tip) url = (self.wx_conf['API_login'] + ('?tip=%s&uuid=%s&_=%s' % (tip, self.uuid, int(time.time())))) data = get(url) pm = re.search('window.code=(\\d+);', data) code = pm.group(1) if (code == '201'): return True elif (code == '200'): pm = re.search('window.redirect_uri="(\\S+?)";', data) r_uri = (pm.group(1) + '&fun=new') self.redirect_uri = r_uri self.wx_host = r_uri.split('://')[1].split('/')[0] self.conf_factory() return True elif (code == '408'): echo(Constant.LOG_MSG_WAIT_LOGIN_ERR1) else: echo(Constant.LOG_MSG_WAIT_LOGIN_ERR2) return False
'@brief login redirect_uri 有效时闎是从扫码成功后算起 倧抂是 300 秒圚歀期闎可以重新登圕䜆获取的联系人和矀ID䌚改变 @return Bool: whether operation succeed'
def login(self):
data = get(self.redirect_uri) doc = xml.dom.minidom.parseString(data) root = doc.documentElement for node in root.childNodes: if (node.nodeName == 'ret'): if (node.childNodes[0].data != '0'): return False elif (node.nodeName == 'skey'): self.skey = node.childNodes[0].data elif (node.nodeName == 'wxsid'): self.sid = node.childNodes[0].data elif (node.nodeName == 'wxuin'): self.uin = node.childNodes[0].data elif (node.nodeName == 'pass_ticket'): self.pass_ticket = node.childNodes[0].data if ('' in (self.skey, self.sid, self.uin, self.pass_ticket)): return False self.base_request = {'Uin': int(self.uin), 'Sid': self.sid, 'Skey': self.skey, 'DeviceID': self.device_id} return True
'@brief wechat initial 掉线后 300 秒可以重新䜿甚歀 api 登圕 获取的联系人和矀ID保持䞍变 @return Bool: whether operation succeed'
def webwxinit(self):
url = (self.wx_conf['API_webwxinit'] + ('?pass_ticket=%s&skey=%s&r=%s' % (self.pass_ticket, self.skey, int(time.time())))) params = {'BaseRequest': self.base_request} dic = post(url, params) self.User = dic['User'] self.make_synckey(dic) return (dic['BaseResponse']['Ret'] == 0)
'@brief notify the mobile phone, this not necessary @return Bool: whether operation succeed'
def webwxstatusnotify(self):
url = (self.wx_conf['API_webwxstatusnotify'] + ('?lang=%s&pass_ticket=%s' % (self.wx_conf['LANG'], self.pass_ticket))) params = {'BaseRequest': self.base_request, 'Code': 3, 'FromUserName': self.User['UserName'], 'ToUserName': self.User['UserName'], 'ClientMsgId': int(time.time())} dic = post(url, params) return (dic['BaseResponse']['Ret'] == 0)
'@brief get all contacts: people, group, public user, special user @return Bool: whether operation succeed'
def webwxgetcontact(self):
SpecialUsers = self.wx_conf['SpecialUsers'] url = (self.wx_conf['API_webwxgetcontact'] + ('?pass_ticket=%s&skey=%s&r=%s' % (self.pass_ticket, self.skey, int(time.time())))) dic = post(url, {}) self.MemberCount = dic['MemberCount'] self.MemberList = dic['MemberList'] ContactList = self.MemberList[:] GroupList = self.GroupList[:] PublicUsersList = self.PublicUsersList[:] SpecialUsersList = self.SpecialUsersList[:] for i in xrange((len(ContactList) - 1), (-1), (-1)): Contact = ContactList[i] if ((Contact['VerifyFlag'] & 8) != 0): ContactList.remove(Contact) self.PublicUsersList.append(Contact) elif (Contact['UserName'] in SpecialUsers): ContactList.remove(Contact) self.SpecialUsersList.append(Contact) elif (Contact['UserName'].find('@@') != (-1)): ContactList.remove(Contact) self.GroupList.append(Contact) elif (Contact['UserName'] == self.User['UserName']): ContactList.remove(Contact) self.ContactList = ContactList return True
'@brief get group contacts @param gid_list, The list of group id @return List, list of group contacts'
def webwxbatchgetcontact(self, gid_list):
url = (self.wx_conf['API_webwxbatchgetcontact'] + ('?type=ex&r=%s&pass_ticket=%s' % (int(time.time()), self.pass_ticket))) params = {'BaseRequest': self.base_request, 'Count': len(gid_list), 'List': [{'UserName': gid, 'EncryChatRoomId': ''} for gid in gid_list]} dic = post(url, params) return dic['ContactList']
'@brief check whether there\'s a message @return [retcode, selector] retcode: 0 successful 1100 logout 1101 login otherwhere selector: 0 nothing 2 message 6 unkonwn 7 webwxsync'
def synccheck(self):
params = {'r': int(time.time()), 'sid': self.sid, 'uin': self.uin, 'skey': self.skey, 'deviceid': self.device_id, 'synckey': self.synckey, '_': int(time.time())} url = ((self.wx_conf['API_synccheck'] + '?') + urllib.urlencode(params)) data = get(url) reg = 'window.synccheck={retcode:"(\\d+)",selector:"(\\d+)"}' pm = re.search(reg, data) retcode = pm.group(1) selector = pm.group(2) return [retcode, selector]
'@brief sync the messages @return Dict{}'
def webwxsync(self):
url = (self.wx_conf['API_webwxsync'] + ('?sid=%s&skey=%s&pass_ticket=%s' % (self.sid, self.skey, self.pass_ticket))) params = {'BaseRequest': self.base_request, 'SyncKey': self.synckey_dic, 'rr': (~ int(time.time()))} dic = post(url, params) if (dic['BaseResponse']['Ret'] == 0): self.make_synckey(dic) return dic
'@brief get image in message @param msgid The id of message @return binary data of image'
def webwxgetmsgimg(self, msgid):
url = (self.wx_conf['API_webwxgetmsgimg'] + ('?MsgID=%s&skey=%s' % (msgid, self.skey))) data = get(url, api='webwxgetmsgimg') return data
'@brief get voice in message @param msgid The id of message @return binary data of voice'
def webwxgetvoice(self, msgid):
url = (self.wx_conf['API_webwxgetvoice'] + ('?msgid=%s&skey=%s' % (msgid, self.skey))) data = get(url, api='webwxgetvoice') return data
'@brief get video in message @param msgid The id of message @return binary data of video'
def webwxgetvideo(self, msgid):
url = (self.wx_conf['API_webwxgetvideo'] + ('?msgid=%s&skey=%s' % (msgid, self.skey))) data = get(url, api='webwxgetvideo') return data
'@brief get user small icon @param id String @return binary data of icon'
def webwxgeticon(self, id):
url = (self.wx_conf['API_webwxgeticon'] + ('?username=%s&skey=%s' % (id, self.skey))) data = get(url, api='webwxgeticon') return data
'@brief get user head image @param id String @return binary data of image'
def webwxgetheadimg(self, id):
url = (self.wx_conf['API_webwxgetheadimg'] + ('?username=%s&skey=%s' % (id, self.skey))) data = get(url, api='webwxgetheadimg') return data
'@brief send text message @param word String @param to User id @return dic Dict'
def webwxsendmsg(self, word, to='filehelper'):
url = (self.wx_conf['API_webwxsendmsg'] + ('?pass_ticket=%s' % self.pass_ticket)) clientMsgId = (str(int((time.time() * 1000))) + str(random.random())[:5].replace('.', '')) params = {'BaseRequest': self.base_request, 'Msg': {'Type': 1, 'Content': trans_coding(word), 'FromUserName': self.User['UserName'], 'ToUserName': to, 'LocalID': clientMsgId, 'ClientMsgId': clientMsgId}} dic = post(url, params) return dic
'@brief upload image @param file_path String @return Dict: json'
def webwxuploadmedia(self, file_path):
url = (self.wx_conf['API_webwxuploadmedia'] + '?f=json') self.media_count = (self.media_count + 1) fn = file_path mime_type = mimetypes.guess_type(fn, strict=False)[0] if (not mime_type): mime_type = 'text/plain' media_type = ('pic' if (mime_type.split('/')[0] == 'image') else 'doc') time_format = '%a %b %d %Y %T GMT%z (%Z)' last_modifie_date = time.strftime(time_format, time.localtime()) file_size = os.path.getsize(fn) pass_ticket = self.pass_ticket client_media_id = (str(int((time.time() * 1000))) + str(random.random())[:5].replace('.', '')) webwx_data_ticket = '' for item in self.cookie: if (item.name == 'webwx_data_ticket'): webwx_data_ticket = item.value break if (webwx_data_ticket == ''): Log.error('No Cookie\n') return None uploadmediarequest = json.dumps({'BaseRequest': self.base_request, 'ClientMediaId': client_media_id, 'TotalLen': file_size, 'StartPos': 0, 'DataLen': file_size, 'MediaType': 4}, ensure_ascii=False).encode('utf8') multipart_encoder = MultipartEncoder(fields={'id': ('WU_FILE_' + str(self.media_count)), 'name': fn, 'type': mime_type, 'lastModifieDate': last_modifie_date, 'size': str(file_size), 'mediatype': media_type, 'uploadmediarequest': uploadmediarequest, 'webwx_data_ticket': webwx_data_ticket, 'pass_ticket': pass_ticket, 'filename': (fn, open(fn, 'rb'), mime_type.split('/')[1])}, boundary='-----------------------------1575017231431605357584454111') headers = {'Host': self.wx_filehost, 'User-Agent': self.user_agent, 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'en-US,en;q=0.5', 'Accept-Encoding': 'gzip, deflate', 'Referer': ('https://' + self.wx_host), 'Content-Type': multipart_encoder.content_type, 'Origin': ('https://' + self.wx_host), 'Connection': 'keep-alive', 'Pragma': 'no-cache', 'Cache-Control': 'no-cache'} r = requests.post(url, data=multipart_encoder, headers=headers) dic = json.loads(r.text) if (dic['BaseResponse']['Ret'] == 0): return dic return None
'@brief send image @param user_id String @param media_id String @return Bool: whether operation succeed'
def webwxsendmsgimg(self, user_id, media_id):
url = (self.wx_conf['API_webwxsendmsgimg'] + ('?fun=async&f=json&pass_ticket=%s' % self.pass_ticket)) clientMsgId = (str(int((time.time() * 1000))) + str(random.random())[:5].replace('.', '')) data_json = {'BaseRequest': self.base_request, 'Msg': {'Type': 3, 'MediaId': media_id, 'FromUserName': self.User['UserName'], 'ToUserName': user_id, 'LocalID': clientMsgId, 'ClientMsgId': clientMsgId}} r = post(url, data_json) return (dic['BaseResponse']['Ret'] == 0)
'@brief send image @param user_id String @param media_id String @return Bool: whether operation succeed'
def webwxsendemoticon(self, user_id, media_id):
url = (self.wx_conf['API_webwxsendemoticon'] + ('?fun=sys&f=json&pass_ticket=%s' % self.pass_ticket)) clientMsgId = (str(int((time.time() * 1000))) + str(random.random())[:5].replace('.', '')) data_json = {'BaseRequest': self.base_request, 'Msg': {'Type': 47, 'EmojiFlag': 2, 'MediaId': media_id, 'FromUserName': self.User['UserName'], 'ToUserName': user_id, 'LocalID': clientMsgId, 'ClientMsgId': clientMsgId}} r = post(url, data_json) return (dic['BaseResponse']['Ret'] == 0)
'@brief send app msg @param user_id String @param data Dict @return Bool: whether operation succeed'
def webwxsendappmsg(self, user_id, data):
url = (self.wx_conf['API_webwxsendappmsg'] + ('?fun=sys&f=json&pass_ticket=%s' % self.pass_ticket)) clientMsgId = (str(int((time.time() * 1000))) + str(random.random())[:5].replace('.', '')) content = ''.join([("<appmsg appid='%s' sdkver=''>" % data['appid']), ('<title>%s</title>' % data['title']), '<des></des>', '<action></action>', ('<type>%d</type>' % data['type']), '<content></content>', '<url></url>', '<lowurl></lowurl>', '<appattach>', ('<totallen>%d</totallen>' % data['totallen']), ('<attachid>%s</attachid>' % data['attachid']), ('<fileext>%s</fileext>' % data['fileext']), '</appattach>', '<extinfo></extinfo>', '</appmsg>']) data_json = {'BaseRequest': self.base_request, 'Msg': {'Type': data['type'], 'Content': content, 'FromUserName': self.User['UserName'], 'ToUserName': user_id, 'LocalID': clientMsgId, 'ClientMsgId': clientMsgId}, 'Scene': 0} r = post(url, data_json) return (dic['BaseResponse']['Ret'] == 0)
'@brief create a chat group @param uid_arr [String] @return Bool: whether operation succeed'
def webwxcreatechatroom(self, uid_arr):
url = (self.wx_conf['API_webwxcreatechatroom'] + ('?r=%s' % int(time.time()))) params = {'BaseRequest': self.base_request, 'Topic': '', 'MemberCount': len(uid_arr), 'MemberList': [{'UserName': uid} for uid in uid_arr]} dic = post(url, params) return (dic['BaseResponse']['Ret'] == 0)