repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
listlengths
20
707
docstring
stringlengths
3
17.3k
docstring_tokens
listlengths
3
222
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
idx
int64
0
252k
siznax/wptools
wptools/page.py
WPToolsPage._update_data
def _update_data(self, datapoint, key, new_data): """ update or assign new data to datapoint """ if new_data: try: self.data[datapoint].update({key: new_data}) except KeyError: self.data[datapoint] = {key: new_data}
python
def _update_data(self, datapoint, key, new_data): """ update or assign new data to datapoint """ if new_data: try: self.data[datapoint].update({key: new_data}) except KeyError: self.data[datapoint] = {key: new_data}
[ "def", "_update_data", "(", "self", ",", "datapoint", ",", "key", ",", "new_data", ")", ":", "if", "new_data", ":", "try", ":", "self", ".", "data", "[", "datapoint", "]", ".", "update", "(", "{", "key", ":", "new_data", "}", ")", "except", "KeyError", ":", "self", ".", "data", "[", "datapoint", "]", "=", "{", "key", ":", "new_data", "}" ]
update or assign new data to datapoint
[ "update", "or", "assign", "new", "data", "to", "datapoint" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L451-L459
train
237,100
siznax/wptools
wptools/page.py
WPToolsPage._update_params
def _update_params(self): """ update params from response data """ if self.data.get('title'): self.params['title'] = self.data.get('title') if self.data.get('pageid'): self.params['pageid'] = self.data.get('pageid') if self.data.get('wikibase'): self.params['wikibase'] = self.data.get('wikibase')
python
def _update_params(self): """ update params from response data """ if self.data.get('title'): self.params['title'] = self.data.get('title') if self.data.get('pageid'): self.params['pageid'] = self.data.get('pageid') if self.data.get('wikibase'): self.params['wikibase'] = self.data.get('wikibase')
[ "def", "_update_params", "(", "self", ")", ":", "if", "self", ".", "data", ".", "get", "(", "'title'", ")", ":", "self", ".", "params", "[", "'title'", "]", "=", "self", ".", "data", ".", "get", "(", "'title'", ")", "if", "self", ".", "data", ".", "get", "(", "'pageid'", ")", ":", "self", ".", "params", "[", "'pageid'", "]", "=", "self", ".", "data", ".", "get", "(", "'pageid'", ")", "if", "self", ".", "data", ".", "get", "(", "'wikibase'", ")", ":", "self", ".", "params", "[", "'wikibase'", "]", "=", "self", ".", "data", ".", "get", "(", "'wikibase'", ")" ]
update params from response data
[ "update", "params", "from", "response", "data" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L472-L481
train
237,101
siznax/wptools
wptools/page.py
WPToolsPage.skip_action
def skip_action(self, action): """ append action to skip flag """ if 'skip' not in self.flags: self.flags['skip'] = [] self.flags['skip'].append(action)
python
def skip_action(self, action): """ append action to skip flag """ if 'skip' not in self.flags: self.flags['skip'] = [] self.flags['skip'].append(action)
[ "def", "skip_action", "(", "self", ",", "action", ")", ":", "if", "'skip'", "not", "in", "self", ".", "flags", ":", "self", ".", "flags", "[", "'skip'", "]", "=", "[", "]", "self", ".", "flags", "[", "'skip'", "]", ".", "append", "(", "action", ")" ]
append action to skip flag
[ "append", "action", "to", "skip", "flag" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L483-L489
train
237,102
siznax/wptools
wptools/page.py
WPToolsPage.images
def images(self, fields=None, token=None): """ Returns image info keys for kind containing token Args: - fields: <list> image info values wanted - token: <str> substring to match image kind EXAMPLES Get all available image info: >>> page.images() Get all image kinds: >>> page.images('kind') Get only "query" (kind) image info >>> page.images(token='query') Get only file, url fields from "wikidata" images >>> page.images(['file', 'url'], token='wikidata') """ if 'image' not in self.data: return out = [] for img in self.data['image']: if token and token not in img['kind']: continue info = {} for key in img: if fields and key not in fields: continue info.update({key: img[key]}) if info: out.append(info) return out
python
def images(self, fields=None, token=None): """ Returns image info keys for kind containing token Args: - fields: <list> image info values wanted - token: <str> substring to match image kind EXAMPLES Get all available image info: >>> page.images() Get all image kinds: >>> page.images('kind') Get only "query" (kind) image info >>> page.images(token='query') Get only file, url fields from "wikidata" images >>> page.images(['file', 'url'], token='wikidata') """ if 'image' not in self.data: return out = [] for img in self.data['image']: if token and token not in img['kind']: continue info = {} for key in img: if fields and key not in fields: continue info.update({key: img[key]}) if info: out.append(info) return out
[ "def", "images", "(", "self", ",", "fields", "=", "None", ",", "token", "=", "None", ")", ":", "if", "'image'", "not", "in", "self", ".", "data", ":", "return", "out", "=", "[", "]", "for", "img", "in", "self", ".", "data", "[", "'image'", "]", ":", "if", "token", "and", "token", "not", "in", "img", "[", "'kind'", "]", ":", "continue", "info", "=", "{", "}", "for", "key", "in", "img", ":", "if", "fields", "and", "key", "not", "in", "fields", ":", "continue", "info", ".", "update", "(", "{", "key", ":", "img", "[", "key", "]", "}", ")", "if", "info", ":", "out", ".", "append", "(", "info", ")", "return", "out" ]
Returns image info keys for kind containing token Args: - fields: <list> image info values wanted - token: <str> substring to match image kind EXAMPLES Get all available image info: >>> page.images() Get all image kinds: >>> page.images('kind') Get only "query" (kind) image info >>> page.images(token='query') Get only file, url fields from "wikidata" images >>> page.images(['file', 'url'], token='wikidata')
[ "Returns", "image", "info", "keys", "for", "kind", "containing", "token" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/page.py#L700-L738
train
237,103
siznax/wptools
wptools/request.py
WPToolsRequest.get
def get(self, url, status): """ in favor of python-requests for speed """ # consistently faster than requests by 3x # # r = requests.get(url, # headers={'User-Agent': self.user_agent}) # return r.text crl = self.cobj try: crl.setopt(pycurl.URL, url) except UnicodeEncodeError: crl.setopt(pycurl.URL, url.encode('utf-8')) if not self.silent: print(status, file=sys.stderr) if self.DISABLED: print("Requests DISABLED", file=sys.stderr) else: return self.curl_perform(crl)
python
def get(self, url, status): """ in favor of python-requests for speed """ # consistently faster than requests by 3x # # r = requests.get(url, # headers={'User-Agent': self.user_agent}) # return r.text crl = self.cobj try: crl.setopt(pycurl.URL, url) except UnicodeEncodeError: crl.setopt(pycurl.URL, url.encode('utf-8')) if not self.silent: print(status, file=sys.stderr) if self.DISABLED: print("Requests DISABLED", file=sys.stderr) else: return self.curl_perform(crl)
[ "def", "get", "(", "self", ",", "url", ",", "status", ")", ":", "# consistently faster than requests by 3x", "#", "# r = requests.get(url,", "# headers={'User-Agent': self.user_agent})", "# return r.text", "crl", "=", "self", ".", "cobj", "try", ":", "crl", ".", "setopt", "(", "pycurl", ".", "URL", ",", "url", ")", "except", "UnicodeEncodeError", ":", "crl", ".", "setopt", "(", "pycurl", ".", "URL", ",", "url", ".", "encode", "(", "'utf-8'", ")", ")", "if", "not", "self", ".", "silent", ":", "print", "(", "status", ",", "file", "=", "sys", ".", "stderr", ")", "if", "self", ".", "DISABLED", ":", "print", "(", "\"Requests DISABLED\"", ",", "file", "=", "sys", ".", "stderr", ")", "else", ":", "return", "self", ".", "curl_perform", "(", "crl", ")" ]
in favor of python-requests for speed
[ "in", "favor", "of", "python", "-", "requests", "for", "speed" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/request.py#L52-L76
train
237,104
siznax/wptools
wptools/request.py
WPToolsRequest.curl_perform
def curl_perform(self, crl): """ performs HTTP GET and returns body of response """ bfr = BytesIO() crl.setopt(crl.WRITEFUNCTION, bfr.write) crl.perform() info = curl_info(crl) if info: if self.verbose and not self.silent: for item in sorted(info): print(" %s: %s" % (item, info[item]), file=sys.stderr) self.info = info body = bfr.getvalue() bfr.close() return body
python
def curl_perform(self, crl): """ performs HTTP GET and returns body of response """ bfr = BytesIO() crl.setopt(crl.WRITEFUNCTION, bfr.write) crl.perform() info = curl_info(crl) if info: if self.verbose and not self.silent: for item in sorted(info): print(" %s: %s" % (item, info[item]), file=sys.stderr) self.info = info body = bfr.getvalue() bfr.close() return body
[ "def", "curl_perform", "(", "self", ",", "crl", ")", ":", "bfr", "=", "BytesIO", "(", ")", "crl", ".", "setopt", "(", "crl", ".", "WRITEFUNCTION", ",", "bfr", ".", "write", ")", "crl", ".", "perform", "(", ")", "info", "=", "curl_info", "(", "crl", ")", "if", "info", ":", "if", "self", ".", "verbose", "and", "not", "self", ".", "silent", ":", "for", "item", "in", "sorted", "(", "info", ")", ":", "print", "(", "\" %s: %s\"", "%", "(", "item", ",", "info", "[", "item", "]", ")", ",", "file", "=", "sys", ".", "stderr", ")", "self", ".", "info", "=", "info", "body", "=", "bfr", ".", "getvalue", "(", ")", "bfr", ".", "close", "(", ")", "return", "body" ]
performs HTTP GET and returns body of response
[ "performs", "HTTP", "GET", "and", "returns", "body", "of", "response" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/request.py#L78-L93
train
237,105
siznax/wptools
wptools/query.py
safequote_restbase
def safequote_restbase(title): """ Safequote restbase title possibly having slash in title """ try: return quote(title.encode('utf-8'), safe='') except UnicodeDecodeError: return quote(title, safe='')
python
def safequote_restbase(title): """ Safequote restbase title possibly having slash in title """ try: return quote(title.encode('utf-8'), safe='') except UnicodeDecodeError: return quote(title, safe='')
[ "def", "safequote_restbase", "(", "title", ")", ":", "try", ":", "return", "quote", "(", "title", ".", "encode", "(", "'utf-8'", ")", ",", "safe", "=", "''", ")", "except", "UnicodeDecodeError", ":", "return", "quote", "(", "title", ",", "safe", "=", "''", ")" ]
Safequote restbase title possibly having slash in title
[ "Safequote", "restbase", "title", "possibly", "having", "slash", "in", "title" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L416-L423
train
237,106
siznax/wptools
wptools/query.py
WPToolsQuery.category
def category(self, title, pageid=None, cparams=None, namespace=None): """ Returns category query string """ query = self.LIST.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, LIST='categorymembers') status = pageid or title query += "&cmlimit=500" if namespace is not None: query += "&cmnamespace=%d" % namespace if title and pageid: title = None if title: query += "&cmtitle=" + safequote(title) if pageid: query += "&cmpageid=%d" % pageid if cparams: query += cparams status += ' (%s)' % cparams self.set_status('categorymembers', status) return query
python
def category(self, title, pageid=None, cparams=None, namespace=None): """ Returns category query string """ query = self.LIST.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, LIST='categorymembers') status = pageid or title query += "&cmlimit=500" if namespace is not None: query += "&cmnamespace=%d" % namespace if title and pageid: title = None if title: query += "&cmtitle=" + safequote(title) if pageid: query += "&cmpageid=%d" % pageid if cparams: query += cparams status += ' (%s)' % cparams self.set_status('categorymembers', status) return query
[ "def", "category", "(", "self", ",", "title", ",", "pageid", "=", "None", ",", "cparams", "=", "None", ",", "namespace", "=", "None", ")", ":", "query", "=", "self", ".", "LIST", ".", "substitute", "(", "WIKI", "=", "self", ".", "uri", ",", "ENDPOINT", "=", "self", ".", "endpoint", ",", "LIST", "=", "'categorymembers'", ")", "status", "=", "pageid", "or", "title", "query", "+=", "\"&cmlimit=500\"", "if", "namespace", "is", "not", "None", ":", "query", "+=", "\"&cmnamespace=%d\"", "%", "namespace", "if", "title", "and", "pageid", ":", "title", "=", "None", "if", "title", ":", "query", "+=", "\"&cmtitle=\"", "+", "safequote", "(", "title", ")", "if", "pageid", ":", "query", "+=", "\"&cmpageid=%d\"", "%", "pageid", "if", "cparams", ":", "query", "+=", "cparams", "status", "+=", "' (%s)'", "%", "cparams", "self", ".", "set_status", "(", "'categorymembers'", ",", "status", ")", "return", "query" ]
Returns category query string
[ "Returns", "category", "query", "string" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L129-L159
train
237,107
siznax/wptools
wptools/query.py
WPToolsQuery.labels
def labels(self, qids): """ Returns Wikidata labels query string """ if len(qids) > 50: raise ValueError("The limit is 50.") self.domain = 'www.wikidata.org' self.uri = self.wiki_uri(self.domain) query = self.WIKIDATA.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, LANG=self.variant or self.lang, PROPS='labels') qids = '|'.join(qids) query += "&ids=%s" % qids self.set_status('labels', qids) return query
python
def labels(self, qids): """ Returns Wikidata labels query string """ if len(qids) > 50: raise ValueError("The limit is 50.") self.domain = 'www.wikidata.org' self.uri = self.wiki_uri(self.domain) query = self.WIKIDATA.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, LANG=self.variant or self.lang, PROPS='labels') qids = '|'.join(qids) query += "&ids=%s" % qids self.set_status('labels', qids) return query
[ "def", "labels", "(", "self", ",", "qids", ")", ":", "if", "len", "(", "qids", ")", ">", "50", ":", "raise", "ValueError", "(", "\"The limit is 50.\"", ")", "self", ".", "domain", "=", "'www.wikidata.org'", "self", ".", "uri", "=", "self", ".", "wiki_uri", "(", "self", ".", "domain", ")", "query", "=", "self", ".", "WIKIDATA", ".", "substitute", "(", "WIKI", "=", "self", ".", "uri", ",", "ENDPOINT", "=", "self", ".", "endpoint", ",", "LANG", "=", "self", ".", "variant", "or", "self", ".", "lang", ",", "PROPS", "=", "'labels'", ")", "qids", "=", "'|'", ".", "join", "(", "qids", ")", "query", "+=", "\"&ids=%s\"", "%", "qids", "self", ".", "set_status", "(", "'labels'", ",", "qids", ")", "return", "query" ]
Returns Wikidata labels query string
[ "Returns", "Wikidata", "labels", "query", "string" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L161-L182
train
237,108
siznax/wptools
wptools/query.py
WPToolsQuery.imageinfo
def imageinfo(self, files): """ Returns imageinfo query string """ files = '|'.join([safequote(x) for x in files]) self.set_status('imageinfo', files) return self.IMAGEINFO.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, FILES=files)
python
def imageinfo(self, files): """ Returns imageinfo query string """ files = '|'.join([safequote(x) for x in files]) self.set_status('imageinfo', files) return self.IMAGEINFO.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, FILES=files)
[ "def", "imageinfo", "(", "self", ",", "files", ")", ":", "files", "=", "'|'", ".", "join", "(", "[", "safequote", "(", "x", ")", "for", "x", "in", "files", "]", ")", "self", ".", "set_status", "(", "'imageinfo'", ",", "files", ")", "return", "self", ".", "IMAGEINFO", ".", "substitute", "(", "WIKI", "=", "self", ".", "uri", ",", "ENDPOINT", "=", "self", ".", "endpoint", ",", "FILES", "=", "files", ")" ]
Returns imageinfo query string
[ "Returns", "imageinfo", "query", "string" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L184-L195
train
237,109
siznax/wptools
wptools/query.py
WPToolsQuery.parse
def parse(self, title, pageid=None): """ Returns Mediawiki action=parse query string """ qry = self.PARSE.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, PAGE=safequote(title) or pageid) if pageid and not title: qry = qry.replace('&page=', '&pageid=').replace('&redirects', '') if self.variant: qry += '&variant=' + self.variant self.set_status('parse', pageid or title) return qry
python
def parse(self, title, pageid=None): """ Returns Mediawiki action=parse query string """ qry = self.PARSE.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, PAGE=safequote(title) or pageid) if pageid and not title: qry = qry.replace('&page=', '&pageid=').replace('&redirects', '') if self.variant: qry += '&variant=' + self.variant self.set_status('parse', pageid or title) return qry
[ "def", "parse", "(", "self", ",", "title", ",", "pageid", "=", "None", ")", ":", "qry", "=", "self", ".", "PARSE", ".", "substitute", "(", "WIKI", "=", "self", ".", "uri", ",", "ENDPOINT", "=", "self", ".", "endpoint", ",", "PAGE", "=", "safequote", "(", "title", ")", "or", "pageid", ")", "if", "pageid", "and", "not", "title", ":", "qry", "=", "qry", ".", "replace", "(", "'&page='", ",", "'&pageid='", ")", ".", "replace", "(", "'&redirects'", ",", "''", ")", "if", "self", ".", "variant", ":", "qry", "+=", "'&variant='", "+", "self", ".", "variant", "self", ".", "set_status", "(", "'parse'", ",", "pageid", "or", "title", ")", "return", "qry" ]
Returns Mediawiki action=parse query string
[ "Returns", "Mediawiki", "action", "=", "parse", "query", "string" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L197-L214
train
237,110
siznax/wptools
wptools/query.py
WPToolsQuery.query
def query(self, titles, pageids=None, cparams=None): """ Returns MediaWiki action=query query string """ query = self.QUERY.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, TITLES=safequote(titles) or pageids) status = titles or pageids if pageids and not titles: query = query.replace('&titles=', '&pageids=') if cparams: query += cparams status += " (%s)" % cparams if self.variant: query += '&variant=' + self.variant self.set_status('query', status) return query
python
def query(self, titles, pageids=None, cparams=None): """ Returns MediaWiki action=query query string """ query = self.QUERY.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, TITLES=safequote(titles) or pageids) status = titles or pageids if pageids and not titles: query = query.replace('&titles=', '&pageids=') if cparams: query += cparams status += " (%s)" % cparams if self.variant: query += '&variant=' + self.variant self.set_status('query', status) return query
[ "def", "query", "(", "self", ",", "titles", ",", "pageids", "=", "None", ",", "cparams", "=", "None", ")", ":", "query", "=", "self", ".", "QUERY", ".", "substitute", "(", "WIKI", "=", "self", ".", "uri", ",", "ENDPOINT", "=", "self", ".", "endpoint", ",", "TITLES", "=", "safequote", "(", "titles", ")", "or", "pageids", ")", "status", "=", "titles", "or", "pageids", "if", "pageids", "and", "not", "titles", ":", "query", "=", "query", ".", "replace", "(", "'&titles='", ",", "'&pageids='", ")", "if", "cparams", ":", "query", "+=", "cparams", "status", "+=", "\" (%s)\"", "%", "cparams", "if", "self", ".", "variant", ":", "query", "+=", "'&variant='", "+", "self", ".", "variant", "self", ".", "set_status", "(", "'query'", ",", "status", ")", "return", "query" ]
Returns MediaWiki action=query query string
[ "Returns", "MediaWiki", "action", "=", "query", "query", "string" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L216-L238
train
237,111
siznax/wptools
wptools/query.py
WPToolsQuery.random
def random(self, namespace=0): """ Returns query string for random page """ query = self.LIST.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, LIST='random') query += "&rnlimit=1&rnnamespace=%d" % namespace emoji = [ u'\U0001f32f', # burrito or wrap u'\U0001f355', # slice of pizza u'\U0001f35c', # steaming bowl of ramen u'\U0001f363', # sushi u'\U0001f369', # doughnut u'\U0001f36a', # cookie u'\U0001f36d', # lollipop u'\U0001f370', # strawberry shortcake ] action = 'random' if namespace: action = 'random:%d' % namespace self.set_status(action, random.choice(emoji)) return query
python
def random(self, namespace=0): """ Returns query string for random page """ query = self.LIST.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, LIST='random') query += "&rnlimit=1&rnnamespace=%d" % namespace emoji = [ u'\U0001f32f', # burrito or wrap u'\U0001f355', # slice of pizza u'\U0001f35c', # steaming bowl of ramen u'\U0001f363', # sushi u'\U0001f369', # doughnut u'\U0001f36a', # cookie u'\U0001f36d', # lollipop u'\U0001f370', # strawberry shortcake ] action = 'random' if namespace: action = 'random:%d' % namespace self.set_status(action, random.choice(emoji)) return query
[ "def", "random", "(", "self", ",", "namespace", "=", "0", ")", ":", "query", "=", "self", ".", "LIST", ".", "substitute", "(", "WIKI", "=", "self", ".", "uri", ",", "ENDPOINT", "=", "self", ".", "endpoint", ",", "LIST", "=", "'random'", ")", "query", "+=", "\"&rnlimit=1&rnnamespace=%d\"", "%", "namespace", "emoji", "=", "[", "u'\\U0001f32f'", ",", "# burrito or wrap", "u'\\U0001f355'", ",", "# slice of pizza", "u'\\U0001f35c'", ",", "# steaming bowl of ramen", "u'\\U0001f363'", ",", "# sushi", "u'\\U0001f369'", ",", "# doughnut", "u'\\U0001f36a'", ",", "# cookie", "u'\\U0001f36d'", ",", "# lollipop", "u'\\U0001f370'", ",", "# strawberry shortcake", "]", "action", "=", "'random'", "if", "namespace", ":", "action", "=", "'random:%d'", "%", "namespace", "self", ".", "set_status", "(", "action", ",", "random", ".", "choice", "(", "emoji", ")", ")", "return", "query" ]
Returns query string for random page
[ "Returns", "query", "string", "for", "random", "page" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L266-L293
train
237,112
siznax/wptools
wptools/query.py
WPToolsQuery.restbase
def restbase(self, endpoint, title): """ Returns RESTBase query string """ if not endpoint: raise ValueError("invalid endpoint: %s" % endpoint) route = endpoint if title and endpoint != '/page/': route = endpoint + safequote_restbase(title) self.set_status('restbase', route) return "%s/api/rest_v1/%s" % (self.uri, route[1:])
python
def restbase(self, endpoint, title): """ Returns RESTBase query string """ if not endpoint: raise ValueError("invalid endpoint: %s" % endpoint) route = endpoint if title and endpoint != '/page/': route = endpoint + safequote_restbase(title) self.set_status('restbase', route) return "%s/api/rest_v1/%s" % (self.uri, route[1:])
[ "def", "restbase", "(", "self", ",", "endpoint", ",", "title", ")", ":", "if", "not", "endpoint", ":", "raise", "ValueError", "(", "\"invalid endpoint: %s\"", "%", "endpoint", ")", "route", "=", "endpoint", "if", "title", "and", "endpoint", "!=", "'/page/'", ":", "route", "=", "endpoint", "+", "safequote_restbase", "(", "title", ")", "self", ".", "set_status", "(", "'restbase'", ",", "route", ")", "return", "\"%s/api/rest_v1/%s\"", "%", "(", "self", ".", "uri", ",", "route", "[", "1", ":", "]", ")" ]
Returns RESTBase query string
[ "Returns", "RESTBase", "query", "string" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L295-L308
train
237,113
siznax/wptools
wptools/query.py
WPToolsQuery.site
def site(self, action): """ Returns site query """ query = None viewdays = 7 hostpath = self.uri + self.endpoint if action == 'siteinfo': query = hostpath + ( '?action=query' '&meta=siteinfo|siteviews' '&siprop=general|statistics' '&list=mostviewed&pvimlimit=max') query += '&pvisdays=%d' % viewdays # meta=siteviews self.set_status('query', 'siteinfo|siteviews|mostviewed') elif action == 'sitematrix': query = hostpath + '?action=sitematrix' self.set_status('sitematrix', 'all') elif action == 'sitevisitors': query = hostpath + ( '?action=query' '&meta=siteviews&pvismetric=uniques') query += '&pvisdays=%d' % viewdays # meta=siteviews self.set_status('query', 'siteviews:uniques') if not query: raise ValueError("Could not form query") query += '&format=json&formatversion=2' return query
python
def site(self, action): """ Returns site query """ query = None viewdays = 7 hostpath = self.uri + self.endpoint if action == 'siteinfo': query = hostpath + ( '?action=query' '&meta=siteinfo|siteviews' '&siprop=general|statistics' '&list=mostviewed&pvimlimit=max') query += '&pvisdays=%d' % viewdays # meta=siteviews self.set_status('query', 'siteinfo|siteviews|mostviewed') elif action == 'sitematrix': query = hostpath + '?action=sitematrix' self.set_status('sitematrix', 'all') elif action == 'sitevisitors': query = hostpath + ( '?action=query' '&meta=siteviews&pvismetric=uniques') query += '&pvisdays=%d' % viewdays # meta=siteviews self.set_status('query', 'siteviews:uniques') if not query: raise ValueError("Could not form query") query += '&format=json&formatversion=2' return query
[ "def", "site", "(", "self", ",", "action", ")", ":", "query", "=", "None", "viewdays", "=", "7", "hostpath", "=", "self", ".", "uri", "+", "self", ".", "endpoint", "if", "action", "==", "'siteinfo'", ":", "query", "=", "hostpath", "+", "(", "'?action=query'", "'&meta=siteinfo|siteviews'", "'&siprop=general|statistics'", "'&list=mostviewed&pvimlimit=max'", ")", "query", "+=", "'&pvisdays=%d'", "%", "viewdays", "# meta=siteviews", "self", ".", "set_status", "(", "'query'", ",", "'siteinfo|siteviews|mostviewed'", ")", "elif", "action", "==", "'sitematrix'", ":", "query", "=", "hostpath", "+", "'?action=sitematrix'", "self", ".", "set_status", "(", "'sitematrix'", ",", "'all'", ")", "elif", "action", "==", "'sitevisitors'", ":", "query", "=", "hostpath", "+", "(", "'?action=query'", "'&meta=siteviews&pvismetric=uniques'", ")", "query", "+=", "'&pvisdays=%d'", "%", "viewdays", "# meta=siteviews", "self", ".", "set_status", "(", "'query'", ",", "'siteviews:uniques'", ")", "if", "not", "query", ":", "raise", "ValueError", "(", "\"Could not form query\"", ")", "query", "+=", "'&format=json&formatversion=2'", "return", "query" ]
Returns site query
[ "Returns", "site", "query" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L329-L360
train
237,114
siznax/wptools
wptools/query.py
WPToolsQuery.wikidata
def wikidata(self, title, wikibase=None): """ Returns Wikidata query string """ self.domain = 'www.wikidata.org' self.uri = self.wiki_uri(self.domain) query = self.WIKIDATA.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, LANG=self.variant or self.lang, PROPS="aliases|info|claims|descriptions|labels|sitelinks") if wikibase: query += "&ids=%s" % wikibase elif title: title = safequote(title) query += "&sites=%swiki" % self.lang query += "&titles=%s" % title self.set_status('wikidata', wikibase or title) return query
python
def wikidata(self, title, wikibase=None): """ Returns Wikidata query string """ self.domain = 'www.wikidata.org' self.uri = self.wiki_uri(self.domain) query = self.WIKIDATA.substitute( WIKI=self.uri, ENDPOINT=self.endpoint, LANG=self.variant or self.lang, PROPS="aliases|info|claims|descriptions|labels|sitelinks") if wikibase: query += "&ids=%s" % wikibase elif title: title = safequote(title) query += "&sites=%swiki" % self.lang query += "&titles=%s" % title self.set_status('wikidata', wikibase or title) return query
[ "def", "wikidata", "(", "self", ",", "title", ",", "wikibase", "=", "None", ")", ":", "self", ".", "domain", "=", "'www.wikidata.org'", "self", ".", "uri", "=", "self", ".", "wiki_uri", "(", "self", ".", "domain", ")", "query", "=", "self", ".", "WIKIDATA", ".", "substitute", "(", "WIKI", "=", "self", ".", "uri", ",", "ENDPOINT", "=", "self", ".", "endpoint", ",", "LANG", "=", "self", ".", "variant", "or", "self", ".", "lang", ",", "PROPS", "=", "\"aliases|info|claims|descriptions|labels|sitelinks\"", ")", "if", "wikibase", ":", "query", "+=", "\"&ids=%s\"", "%", "wikibase", "elif", "title", ":", "title", "=", "safequote", "(", "title", ")", "query", "+=", "\"&sites=%swiki\"", "%", "self", ".", "lang", "query", "+=", "\"&titles=%s\"", "%", "title", "self", ".", "set_status", "(", "'wikidata'", ",", "wikibase", "or", "title", ")", "return", "query" ]
Returns Wikidata query string
[ "Returns", "Wikidata", "query", "string" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/query.py#L370-L392
train
237,115
siznax/wptools
wptools/restbase.py
WPToolsRESTBase._handle_response
def _handle_response(self): """ returns RESTBase response if appropriate """ content = self.cache['restbase']['info']['content-type'] if content.startswith('text/html'): html = self.cache['restbase']['response'] if isinstance(html, bytes): html = html.decode('utf-8') self.data['html'] = html return response = self._load_response('restbase') http_status = self.cache['restbase']['info']['status'] if http_status == 404: raise LookupError(self.cache['restbase']['query']) if self.params.get('endpoint') == '/page/': msg = "RESTBase /page/ entry points: %s" % response.get('items') utils.stderr(msg) del self.cache['restbase'] return return response
python
def _handle_response(self): """ returns RESTBase response if appropriate """ content = self.cache['restbase']['info']['content-type'] if content.startswith('text/html'): html = self.cache['restbase']['response'] if isinstance(html, bytes): html = html.decode('utf-8') self.data['html'] = html return response = self._load_response('restbase') http_status = self.cache['restbase']['info']['status'] if http_status == 404: raise LookupError(self.cache['restbase']['query']) if self.params.get('endpoint') == '/page/': msg = "RESTBase /page/ entry points: %s" % response.get('items') utils.stderr(msg) del self.cache['restbase'] return return response
[ "def", "_handle_response", "(", "self", ")", ":", "content", "=", "self", ".", "cache", "[", "'restbase'", "]", "[", "'info'", "]", "[", "'content-type'", "]", "if", "content", ".", "startswith", "(", "'text/html'", ")", ":", "html", "=", "self", ".", "cache", "[", "'restbase'", "]", "[", "'response'", "]", "if", "isinstance", "(", "html", ",", "bytes", ")", ":", "html", "=", "html", ".", "decode", "(", "'utf-8'", ")", "self", ".", "data", "[", "'html'", "]", "=", "html", "return", "response", "=", "self", ".", "_load_response", "(", "'restbase'", ")", "http_status", "=", "self", ".", "cache", "[", "'restbase'", "]", "[", "'info'", "]", "[", "'status'", "]", "if", "http_status", "==", "404", ":", "raise", "LookupError", "(", "self", ".", "cache", "[", "'restbase'", "]", "[", "'query'", "]", ")", "if", "self", ".", "params", ".", "get", "(", "'endpoint'", ")", "==", "'/page/'", ":", "msg", "=", "\"RESTBase /page/ entry points: %s\"", "%", "response", ".", "get", "(", "'items'", ")", "utils", ".", "stderr", "(", "msg", ")", "del", "self", ".", "cache", "[", "'restbase'", "]", "return", "return", "response" ]
returns RESTBase response if appropriate
[ "returns", "RESTBase", "response", "if", "appropriate" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/restbase.py#L41-L65
train
237,116
siznax/wptools
wptools/restbase.py
WPToolsRESTBase._query
def _query(self, action, qobj): """ returns WPToolsQuery string from action """ return qobj.restbase(self.params['rest_endpoint'], self.params.get('title'))
python
def _query(self, action, qobj): """ returns WPToolsQuery string from action """ return qobj.restbase(self.params['rest_endpoint'], self.params.get('title'))
[ "def", "_query", "(", "self", ",", "action", ",", "qobj", ")", ":", "return", "qobj", ".", "restbase", "(", "self", ".", "params", "[", "'rest_endpoint'", "]", ",", "self", ".", "params", ".", "get", "(", "'title'", ")", ")" ]
returns WPToolsQuery string from action
[ "returns", "WPToolsQuery", "string", "from", "action" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/restbase.py#L67-L72
train
237,117
siznax/wptools
wptools/restbase.py
WPToolsRESTBase._unpack_images
def _unpack_images(self, rdata): """ Set image data from RESTBase response """ image = rdata.get('image') # /page/mobile-sections-lead originalimage = rdata.get('originalimage') # /page/summary thumbnail = rdata.get('thumbnail') # /page/summary if image or originalimage or thumbnail: if 'image' not in self.data: self.data['image'] = [] def file_url(info): """ put image source in url and set file key """ if 'source' in info: info['url'] = info['source'] info['file'] = info['source'].split('/')[-1] del info['source'] return info if image: img = {'kind': 'restbase-image'} img.update(image) self.data['image'].append(file_url(img)) if originalimage: img = {'kind': 'restbase-original'} img.update(originalimage) self.data['image'].append(file_url(img)) if thumbnail: img = {'kind': 'restbase-thumb'} img.update(thumbnail) self.data['image'].append(file_url(img))
python
def _unpack_images(self, rdata): """ Set image data from RESTBase response """ image = rdata.get('image') # /page/mobile-sections-lead originalimage = rdata.get('originalimage') # /page/summary thumbnail = rdata.get('thumbnail') # /page/summary if image or originalimage or thumbnail: if 'image' not in self.data: self.data['image'] = [] def file_url(info): """ put image source in url and set file key """ if 'source' in info: info['url'] = info['source'] info['file'] = info['source'].split('/')[-1] del info['source'] return info if image: img = {'kind': 'restbase-image'} img.update(image) self.data['image'].append(file_url(img)) if originalimage: img = {'kind': 'restbase-original'} img.update(originalimage) self.data['image'].append(file_url(img)) if thumbnail: img = {'kind': 'restbase-thumb'} img.update(thumbnail) self.data['image'].append(file_url(img))
[ "def", "_unpack_images", "(", "self", ",", "rdata", ")", ":", "image", "=", "rdata", ".", "get", "(", "'image'", ")", "# /page/mobile-sections-lead", "originalimage", "=", "rdata", ".", "get", "(", "'originalimage'", ")", "# /page/summary", "thumbnail", "=", "rdata", ".", "get", "(", "'thumbnail'", ")", "# /page/summary", "if", "image", "or", "originalimage", "or", "thumbnail", ":", "if", "'image'", "not", "in", "self", ".", "data", ":", "self", ".", "data", "[", "'image'", "]", "=", "[", "]", "def", "file_url", "(", "info", ")", ":", "\"\"\"\n put image source in url and set file key\n \"\"\"", "if", "'source'", "in", "info", ":", "info", "[", "'url'", "]", "=", "info", "[", "'source'", "]", "info", "[", "'file'", "]", "=", "info", "[", "'source'", "]", ".", "split", "(", "'/'", ")", "[", "-", "1", "]", "del", "info", "[", "'source'", "]", "return", "info", "if", "image", ":", "img", "=", "{", "'kind'", ":", "'restbase-image'", "}", "img", ".", "update", "(", "image", ")", "self", ".", "data", "[", "'image'", "]", ".", "append", "(", "file_url", "(", "img", ")", ")", "if", "originalimage", ":", "img", "=", "{", "'kind'", ":", "'restbase-original'", "}", "img", ".", "update", "(", "originalimage", ")", "self", ".", "data", "[", "'image'", "]", ".", "append", "(", "file_url", "(", "img", ")", ")", "if", "thumbnail", ":", "img", "=", "{", "'kind'", ":", "'restbase-thumb'", "}", "img", ".", "update", "(", "thumbnail", ")", "self", ".", "data", "[", "'image'", "]", ".", "append", "(", "file_url", "(", "img", ")", ")" ]
Set image data from RESTBase response
[ "Set", "image", "data", "from", "RESTBase", "response" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/restbase.py#L120-L155
train
237,118
siznax/wptools
wptools/utils.py
is_text
def is_text(obj, name=None): """ returns True if object is text-like """ try: # python2 ans = isinstance(obj, basestring) except NameError: # python3 ans = isinstance(obj, str) if name: print("is_text: (%s) %s = %s" % (ans, name, obj.__class__), file=sys.stderr) return ans
python
def is_text(obj, name=None): """ returns True if object is text-like """ try: # python2 ans = isinstance(obj, basestring) except NameError: # python3 ans = isinstance(obj, str) if name: print("is_text: (%s) %s = %s" % (ans, name, obj.__class__), file=sys.stderr) return ans
[ "def", "is_text", "(", "obj", ",", "name", "=", "None", ")", ":", "try", ":", "# python2", "ans", "=", "isinstance", "(", "obj", ",", "basestring", ")", "except", "NameError", ":", "# python3", "ans", "=", "isinstance", "(", "obj", ",", "str", ")", "if", "name", ":", "print", "(", "\"is_text: (%s) %s = %s\"", "%", "(", "ans", ",", "name", ",", "obj", ".", "__class__", ")", ",", "file", "=", "sys", ".", "stderr", ")", "return", "ans" ]
returns True if object is text-like
[ "returns", "True", "if", "object", "is", "text", "-", "like" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/utils.py#L67-L78
train
237,119
siznax/wptools
wptools/utils.py
json_loads
def json_loads(data): """ python-version-safe json.loads """ try: return json.loads(data, encoding='utf-8') except TypeError: return json.loads(data.decode('utf-8'))
python
def json_loads(data): """ python-version-safe json.loads """ try: return json.loads(data, encoding='utf-8') except TypeError: return json.loads(data.decode('utf-8'))
[ "def", "json_loads", "(", "data", ")", ":", "try", ":", "return", "json", ".", "loads", "(", "data", ",", "encoding", "=", "'utf-8'", ")", "except", "TypeError", ":", "return", "json", ".", "loads", "(", "data", ".", "decode", "(", "'utf-8'", ")", ")" ]
python-version-safe json.loads
[ "python", "-", "version", "-", "safe", "json", ".", "loads" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/utils.py#L90-L97
train
237,120
siznax/wptools
wptools/utils.py
stderr
def stderr(msg, silent=False): """ write msg to stderr if not silent """ if not silent: print(msg, file=sys.stderr)
python
def stderr(msg, silent=False): """ write msg to stderr if not silent """ if not silent: print(msg, file=sys.stderr)
[ "def", "stderr", "(", "msg", ",", "silent", "=", "False", ")", ":", "if", "not", "silent", ":", "print", "(", "msg", ",", "file", "=", "sys", ".", "stderr", ")" ]
write msg to stderr if not silent
[ "write", "msg", "to", "stderr", "if", "not", "silent" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/utils.py#L110-L115
train
237,121
siznax/wptools
wptools/utils.py
template_to_dict
def template_to_dict(tree, debug=0, find=False): """ returns wikitext template as dict debug = 1 prints minimal debug info to stdout debug > 1 compares _iter() versus _find() results find = True sets values from _find() algorithm (default _iter()) """ # you can compare (most) raw Infobox wikitext like this: # https://en.wikipedia.org/wiki/TITLE?action=raw&section=0 obj = defaultdict(str) errors = [] for item in tree: try: name = item.findtext('name').strip() if debug: template_to_dict_debug(name, item, debug) find_val = template_to_dict_find(item, debug) # DEPRECATED iter_val = template_to_dict_iter(item, debug) value = iter_val if find: value = find_val if name and value: obj[name] = value.strip() except AttributeError: if isinstance(item, lxml.etree.ElementBase): name = item.tag.strip() text = item.text.strip() if item.tag == 'title': obj['infobox'] = text else: obj[name] = text except: errors.append(lxml.etree.tostring(item)) if errors: obj['errors'] = errors return dict(obj)
python
def template_to_dict(tree, debug=0, find=False): """ returns wikitext template as dict debug = 1 prints minimal debug info to stdout debug > 1 compares _iter() versus _find() results find = True sets values from _find() algorithm (default _iter()) """ # you can compare (most) raw Infobox wikitext like this: # https://en.wikipedia.org/wiki/TITLE?action=raw&section=0 obj = defaultdict(str) errors = [] for item in tree: try: name = item.findtext('name').strip() if debug: template_to_dict_debug(name, item, debug) find_val = template_to_dict_find(item, debug) # DEPRECATED iter_val = template_to_dict_iter(item, debug) value = iter_val if find: value = find_val if name and value: obj[name] = value.strip() except AttributeError: if isinstance(item, lxml.etree.ElementBase): name = item.tag.strip() text = item.text.strip() if item.tag == 'title': obj['infobox'] = text else: obj[name] = text except: errors.append(lxml.etree.tostring(item)) if errors: obj['errors'] = errors return dict(obj)
[ "def", "template_to_dict", "(", "tree", ",", "debug", "=", "0", ",", "find", "=", "False", ")", ":", "# you can compare (most) raw Infobox wikitext like this:", "# https://en.wikipedia.org/wiki/TITLE?action=raw&section=0", "obj", "=", "defaultdict", "(", "str", ")", "errors", "=", "[", "]", "for", "item", "in", "tree", ":", "try", ":", "name", "=", "item", ".", "findtext", "(", "'name'", ")", ".", "strip", "(", ")", "if", "debug", ":", "template_to_dict_debug", "(", "name", ",", "item", ",", "debug", ")", "find_val", "=", "template_to_dict_find", "(", "item", ",", "debug", ")", "# DEPRECATED", "iter_val", "=", "template_to_dict_iter", "(", "item", ",", "debug", ")", "value", "=", "iter_val", "if", "find", ":", "value", "=", "find_val", "if", "name", "and", "value", ":", "obj", "[", "name", "]", "=", "value", ".", "strip", "(", ")", "except", "AttributeError", ":", "if", "isinstance", "(", "item", ",", "lxml", ".", "etree", ".", "ElementBase", ")", ":", "name", "=", "item", ".", "tag", ".", "strip", "(", ")", "text", "=", "item", ".", "text", ".", "strip", "(", ")", "if", "item", ".", "tag", "==", "'title'", ":", "obj", "[", "'infobox'", "]", "=", "text", "else", ":", "obj", "[", "name", "]", "=", "text", "except", ":", "errors", ".", "append", "(", "lxml", ".", "etree", ".", "tostring", "(", "item", ")", ")", "if", "errors", ":", "obj", "[", "'errors'", "]", "=", "errors", "return", "dict", "(", "obj", ")" ]
returns wikitext template as dict debug = 1 prints minimal debug info to stdout debug > 1 compares _iter() versus _find() results find = True sets values from _find() algorithm (default _iter())
[ "returns", "wikitext", "template", "as", "dict" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/utils.py#L118-L168
train
237,122
siznax/wptools
wptools/utils.py
template_to_dict_debug
def template_to_dict_debug(name, item, debug): """ Print debug statements to compare algorithms """ if debug == 1: print("\n%s = " % name) elif debug > 1: print("\n%s" % name) print("=" * 64) print(lxml.etree.tostring(item)) print()
python
def template_to_dict_debug(name, item, debug): """ Print debug statements to compare algorithms """ if debug == 1: print("\n%s = " % name) elif debug > 1: print("\n%s" % name) print("=" * 64) print(lxml.etree.tostring(item)) print()
[ "def", "template_to_dict_debug", "(", "name", ",", "item", ",", "debug", ")", ":", "if", "debug", "==", "1", ":", "print", "(", "\"\\n%s = \"", "%", "name", ")", "elif", "debug", ">", "1", ":", "print", "(", "\"\\n%s\"", "%", "name", ")", "print", "(", "\"=\"", "*", "64", ")", "print", "(", "lxml", ".", "etree", ".", "tostring", "(", "item", ")", ")", "print", "(", ")" ]
Print debug statements to compare algorithms
[ "Print", "debug", "statements", "to", "compare", "algorithms" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/utils.py#L202-L212
train
237,123
siznax/wptools
wptools/utils.py
template_to_dict_iter_debug
def template_to_dict_iter_debug(elm): """ Print expanded element on stdout for debugging """ if elm.text is not None: print(" <%s>%s</%s>" % (elm.tag, elm.text, elm.tag), end='') if elm.tail is not None: print(elm.tail) else: print() else: if elm.tail is not None: print(" <%s>%s" % (elm.tag, elm.tail)) else: print(" <%s>" % elm.tag)
python
def template_to_dict_iter_debug(elm): """ Print expanded element on stdout for debugging """ if elm.text is not None: print(" <%s>%s</%s>" % (elm.tag, elm.text, elm.tag), end='') if elm.tail is not None: print(elm.tail) else: print() else: if elm.tail is not None: print(" <%s>%s" % (elm.tag, elm.tail)) else: print(" <%s>" % elm.tag)
[ "def", "template_to_dict_iter_debug", "(", "elm", ")", ":", "if", "elm", ".", "text", "is", "not", "None", ":", "print", "(", "\" <%s>%s</%s>\"", "%", "(", "elm", ".", "tag", ",", "elm", ".", "text", ",", "elm", ".", "tag", ")", ",", "end", "=", "''", ")", "if", "elm", ".", "tail", "is", "not", "None", ":", "print", "(", "elm", ".", "tail", ")", "else", ":", "print", "(", ")", "else", ":", "if", "elm", ".", "tail", "is", "not", "None", ":", "print", "(", "\" <%s>%s\"", "%", "(", "elm", ".", "tag", ",", "elm", ".", "tail", ")", ")", "else", ":", "print", "(", "\" <%s>\"", "%", "elm", ".", "tag", ")" ]
Print expanded element on stdout for debugging
[ "Print", "expanded", "element", "on", "stdout", "for", "debugging" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/utils.py#L280-L294
train
237,124
siznax/wptools
wptools/utils.py
template_to_text
def template_to_text(tmpl, debug=0): """ convert parse tree template to text """ tarr = [] for item in tmpl.itertext(): tarr.append(item) text = "{{%s}}" % "|".join(tarr).strip() if debug > 1: print("+ template_to_text:") print(" %s" % text) return text
python
def template_to_text(tmpl, debug=0): """ convert parse tree template to text """ tarr = [] for item in tmpl.itertext(): tarr.append(item) text = "{{%s}}" % "|".join(tarr).strip() if debug > 1: print("+ template_to_text:") print(" %s" % text) return text
[ "def", "template_to_text", "(", "tmpl", ",", "debug", "=", "0", ")", ":", "tarr", "=", "[", "]", "for", "item", "in", "tmpl", ".", "itertext", "(", ")", ":", "tarr", ".", "append", "(", "item", ")", "text", "=", "\"{{%s}}\"", "%", "\"|\"", ".", "join", "(", "tarr", ")", ".", "strip", "(", ")", "if", "debug", ">", "1", ":", "print", "(", "\"+ template_to_text:\"", ")", "print", "(", "\" %s\"", "%", "text", ")", "return", "text" ]
convert parse tree template to text
[ "convert", "parse", "tree", "template", "to", "text" ]
100eaea585c34aa9ad87a9eda8982bb4898f6ec9
https://github.com/siznax/wptools/blob/100eaea585c34aa9ad87a9eda8982bb4898f6ec9/wptools/utils.py#L297-L311
train
237,125
phaethon/kamene
kamene/contrib/igmpv3.py
IGMPv3gr.post_build
def post_build(self, p, pay): """Called implicitly before a packet is sent. """ p += pay if self.auxdlen != 0: print("NOTICE: A properly formatted and complaint V3 Group Record should have an Auxiliary Data length of zero (0).") print(" Subsequent Group Records are lost!") return p
python
def post_build(self, p, pay): """Called implicitly before a packet is sent. """ p += pay if self.auxdlen != 0: print("NOTICE: A properly formatted and complaint V3 Group Record should have an Auxiliary Data length of zero (0).") print(" Subsequent Group Records are lost!") return p
[ "def", "post_build", "(", "self", ",", "p", ",", "pay", ")", ":", "p", "+=", "pay", "if", "self", ".", "auxdlen", "!=", "0", ":", "print", "(", "\"NOTICE: A properly formatted and complaint V3 Group Record should have an Auxiliary Data length of zero (0).\"", ")", "print", "(", "\" Subsequent Group Records are lost!\"", ")", "return", "p" ]
Called implicitly before a packet is sent.
[ "Called", "implicitly", "before", "a", "packet", "is", "sent", "." ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/igmpv3.py#L55-L62
train
237,126
phaethon/kamene
kamene/contrib/igmpv3.py
IGMPv3.post_build
def post_build(self, p, pay): """Called implicitly before a packet is sent to compute and place IGMPv3 checksum. Parameters: self The instantiation of an IGMPv3 class p The IGMPv3 message in hex in network byte order pay Additional payload for the IGMPv3 message """ p += pay if self.type in [0, 0x31, 0x32, 0x22]: # for these, field is reserved (0) p = p[:1]+chr(0)+p[2:] if self.chksum is None: ck = checksum(p[:2]+p[4:]) p = p[:2]+ck.to_bytes(2, 'big')+p[4:] return p
python
def post_build(self, p, pay): """Called implicitly before a packet is sent to compute and place IGMPv3 checksum. Parameters: self The instantiation of an IGMPv3 class p The IGMPv3 message in hex in network byte order pay Additional payload for the IGMPv3 message """ p += pay if self.type in [0, 0x31, 0x32, 0x22]: # for these, field is reserved (0) p = p[:1]+chr(0)+p[2:] if self.chksum is None: ck = checksum(p[:2]+p[4:]) p = p[:2]+ck.to_bytes(2, 'big')+p[4:] return p
[ "def", "post_build", "(", "self", ",", "p", ",", "pay", ")", ":", "p", "+=", "pay", "if", "self", ".", "type", "in", "[", "0", ",", "0x31", ",", "0x32", ",", "0x22", "]", ":", "# for these, field is reserved (0)", "p", "=", "p", "[", ":", "1", "]", "+", "chr", "(", "0", ")", "+", "p", "[", "2", ":", "]", "if", "self", ".", "chksum", "is", "None", ":", "ck", "=", "checksum", "(", "p", "[", ":", "2", "]", "+", "p", "[", "4", ":", "]", ")", "p", "=", "p", "[", ":", "2", "]", "+", "ck", ".", "to_bytes", "(", "2", ",", "'big'", ")", "+", "p", "[", "4", ":", "]", "return", "p" ]
Called implicitly before a packet is sent to compute and place IGMPv3 checksum. Parameters: self The instantiation of an IGMPv3 class p The IGMPv3 message in hex in network byte order pay Additional payload for the IGMPv3 message
[ "Called", "implicitly", "before", "a", "packet", "is", "sent", "to", "compute", "and", "place", "IGMPv3", "checksum", "." ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/igmpv3.py#L144-L158
train
237,127
phaethon/kamene
kamene/contrib/igmpv3.py
IGMPv3.mysummary
def mysummary(self): """Display a summary of the IGMPv3 object.""" if isinstance(self.underlayer, IP): return self.underlayer.sprintf("IGMPv3: %IP.src% > %IP.dst% %IGMPv3.type% %IGMPv3.gaddr%") else: return self.sprintf("IGMPv3 %IGMPv3.type% %IGMPv3.gaddr%")
python
def mysummary(self): """Display a summary of the IGMPv3 object.""" if isinstance(self.underlayer, IP): return self.underlayer.sprintf("IGMPv3: %IP.src% > %IP.dst% %IGMPv3.type% %IGMPv3.gaddr%") else: return self.sprintf("IGMPv3 %IGMPv3.type% %IGMPv3.gaddr%")
[ "def", "mysummary", "(", "self", ")", ":", "if", "isinstance", "(", "self", ".", "underlayer", ",", "IP", ")", ":", "return", "self", ".", "underlayer", ".", "sprintf", "(", "\"IGMPv3: %IP.src% > %IP.dst% %IGMPv3.type% %IGMPv3.gaddr%\"", ")", "else", ":", "return", "self", ".", "sprintf", "(", "\"IGMPv3 %IGMPv3.type% %IGMPv3.gaddr%\"", ")" ]
Display a summary of the IGMPv3 object.
[ "Display", "a", "summary", "of", "the", "IGMPv3", "object", "." ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/igmpv3.py#L161-L167
train
237,128
phaethon/kamene
kamene/contrib/igmpv3.py
IGMPv3.adjust_ether
def adjust_ether (self, ip=None, ether=None): """Called to explicitely fixup an associated Ethernet header The function adjusts the ethernet header destination MAC address based on the destination IP address. """ # The rules are: # 1. send to the group mac address address corresponding to the IP.dst if ip != None and ip.haslayer(IP) and ether != None and ether.haslayer(Ether): iplong = atol(ip.dst) ether.dst = "01:00:5e:%02x:%02x:%02x" % ( (iplong>>16)&0x7F, (iplong>>8)&0xFF, (iplong)&0xFF ) # print "igmpize ip " + ip.dst + " as mac " + ether.dst return True else: return False
python
def adjust_ether (self, ip=None, ether=None): """Called to explicitely fixup an associated Ethernet header The function adjusts the ethernet header destination MAC address based on the destination IP address. """ # The rules are: # 1. send to the group mac address address corresponding to the IP.dst if ip != None and ip.haslayer(IP) and ether != None and ether.haslayer(Ether): iplong = atol(ip.dst) ether.dst = "01:00:5e:%02x:%02x:%02x" % ( (iplong>>16)&0x7F, (iplong>>8)&0xFF, (iplong)&0xFF ) # print "igmpize ip " + ip.dst + " as mac " + ether.dst return True else: return False
[ "def", "adjust_ether", "(", "self", ",", "ip", "=", "None", ",", "ether", "=", "None", ")", ":", "# The rules are:", "# 1. send to the group mac address address corresponding to the IP.dst", "if", "ip", "!=", "None", "and", "ip", ".", "haslayer", "(", "IP", ")", "and", "ether", "!=", "None", "and", "ether", ".", "haslayer", "(", "Ether", ")", ":", "iplong", "=", "atol", "(", "ip", ".", "dst", ")", "ether", ".", "dst", "=", "\"01:00:5e:%02x:%02x:%02x\"", "%", "(", "(", "iplong", ">>", "16", ")", "&", "0x7F", ",", "(", "iplong", ">>", "8", ")", "&", "0xFF", ",", "(", "iplong", ")", "&", "0xFF", ")", "# print \"igmpize ip \" + ip.dst + \" as mac \" + ether.dst ", "return", "True", "else", ":", "return", "False" ]
Called to explicitely fixup an associated Ethernet header The function adjusts the ethernet header destination MAC address based on the destination IP address.
[ "Called", "to", "explicitely", "fixup", "an", "associated", "Ethernet", "header" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/igmpv3.py#L208-L222
train
237,129
phaethon/kamene
kamene/contrib/igmpv3.py
IGMPv3.adjust_ip
def adjust_ip (self, ip=None): """Called to explicitely fixup an associated IP header The function adjusts the IP header based on conformance rules and the group address encoded in the IGMP message. The rules are: 1. Send General Group Query to 224.0.0.1 (all systems) 2. Send Leave Group to 224.0.0.2 (all routers) 3a.Otherwise send the packet to the group address 3b.Send reports/joins to the group address 4. ttl = 1 (RFC 2236, section 2) 5. send the packet with the router alert IP option (RFC 2236, section 2) """ if ip != None and ip.haslayer(IP): if (self.type == 0x11): if (self.gaddr == "0.0.0.0"): ip.dst = "224.0.0.1" # IP rule 1 retCode = True elif isValidMCAddr(self.gaddr): ip.dst = self.gaddr # IP rule 3a retCode = True else: print("Warning: Using invalid Group Address") retCode = False elif ((self.type == 0x17) and isValidMCAddr(self.gaddr)): ip.dst = "224.0.0.2" # IP rule 2 retCode = True elif ((self.type == 0x12) or (self.type == 0x16)) and (isValidMCAddr(self.gaddr)): ip.dst = self.gaddr # IP rule 3b retCode = True else: print("Warning: Using invalid IGMP Type") retCode = False else: print("Warning: No IGMP Group Address set") retCode = False if retCode == True: ip.ttl=1 # IP Rule 4 ip.options=[IPOption_Router_Alert()] # IP rule 5 return retCode
python
def adjust_ip (self, ip=None): """Called to explicitely fixup an associated IP header The function adjusts the IP header based on conformance rules and the group address encoded in the IGMP message. The rules are: 1. Send General Group Query to 224.0.0.1 (all systems) 2. Send Leave Group to 224.0.0.2 (all routers) 3a.Otherwise send the packet to the group address 3b.Send reports/joins to the group address 4. ttl = 1 (RFC 2236, section 2) 5. send the packet with the router alert IP option (RFC 2236, section 2) """ if ip != None and ip.haslayer(IP): if (self.type == 0x11): if (self.gaddr == "0.0.0.0"): ip.dst = "224.0.0.1" # IP rule 1 retCode = True elif isValidMCAddr(self.gaddr): ip.dst = self.gaddr # IP rule 3a retCode = True else: print("Warning: Using invalid Group Address") retCode = False elif ((self.type == 0x17) and isValidMCAddr(self.gaddr)): ip.dst = "224.0.0.2" # IP rule 2 retCode = True elif ((self.type == 0x12) or (self.type == 0x16)) and (isValidMCAddr(self.gaddr)): ip.dst = self.gaddr # IP rule 3b retCode = True else: print("Warning: Using invalid IGMP Type") retCode = False else: print("Warning: No IGMP Group Address set") retCode = False if retCode == True: ip.ttl=1 # IP Rule 4 ip.options=[IPOption_Router_Alert()] # IP rule 5 return retCode
[ "def", "adjust_ip", "(", "self", ",", "ip", "=", "None", ")", ":", "if", "ip", "!=", "None", "and", "ip", ".", "haslayer", "(", "IP", ")", ":", "if", "(", "self", ".", "type", "==", "0x11", ")", ":", "if", "(", "self", ".", "gaddr", "==", "\"0.0.0.0\"", ")", ":", "ip", ".", "dst", "=", "\"224.0.0.1\"", "# IP rule 1", "retCode", "=", "True", "elif", "isValidMCAddr", "(", "self", ".", "gaddr", ")", ":", "ip", ".", "dst", "=", "self", ".", "gaddr", "# IP rule 3a", "retCode", "=", "True", "else", ":", "print", "(", "\"Warning: Using invalid Group Address\"", ")", "retCode", "=", "False", "elif", "(", "(", "self", ".", "type", "==", "0x17", ")", "and", "isValidMCAddr", "(", "self", ".", "gaddr", ")", ")", ":", "ip", ".", "dst", "=", "\"224.0.0.2\"", "# IP rule 2", "retCode", "=", "True", "elif", "(", "(", "self", ".", "type", "==", "0x12", ")", "or", "(", "self", ".", "type", "==", "0x16", ")", ")", "and", "(", "isValidMCAddr", "(", "self", ".", "gaddr", ")", ")", ":", "ip", ".", "dst", "=", "self", ".", "gaddr", "# IP rule 3b", "retCode", "=", "True", "else", ":", "print", "(", "\"Warning: Using invalid IGMP Type\"", ")", "retCode", "=", "False", "else", ":", "print", "(", "\"Warning: No IGMP Group Address set\"", ")", "retCode", "=", "False", "if", "retCode", "==", "True", ":", "ip", ".", "ttl", "=", "1", "# IP Rule 4", "ip", ".", "options", "=", "[", "IPOption_Router_Alert", "(", ")", "]", "# IP rule 5", "return", "retCode" ]
Called to explicitely fixup an associated IP header The function adjusts the IP header based on conformance rules and the group address encoded in the IGMP message. The rules are: 1. Send General Group Query to 224.0.0.1 (all systems) 2. Send Leave Group to 224.0.0.2 (all routers) 3a.Otherwise send the packet to the group address 3b.Send reports/joins to the group address 4. ttl = 1 (RFC 2236, section 2) 5. send the packet with the router alert IP option (RFC 2236, section 2)
[ "Called", "to", "explicitely", "fixup", "an", "associated", "IP", "header" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/igmpv3.py#L225-L264
train
237,130
phaethon/kamene
kamene/contrib/ospf.py
ospf_lsa_checksum
def ospf_lsa_checksum(lsa): """ Fletcher checksum for OSPF LSAs, returned as a 2 byte string. Give the whole LSA packet as argument. For details on the algorithm, see RFC 2328 chapter 12.1.7 and RFC 905 Annex B. """ # This is based on the GPLed C implementation in Zebra <http://www.zebra.org/> CHKSUM_OFFSET = 16 if len(lsa) < CHKSUM_OFFSET: raise Exception("LSA Packet too short (%s bytes)" % len(lsa)) c0 = c1 = 0 # Calculation is done with checksum set to zero lsa = lsa[:CHKSUM_OFFSET] + lsa[CHKSUM_OFFSET + 2:] for char in lsa[2:]: # leave out age c0 += char c1 += c0 c0 %= 255 c1 %= 255 x = ((len(lsa) - CHKSUM_OFFSET - 1) * c0 - c1) % 255 if (x <= 0): x += 255 y = 510 - c0 - x if (y > 255): y -= 255 checksum = (x << 8) + y return checksum
python
def ospf_lsa_checksum(lsa): """ Fletcher checksum for OSPF LSAs, returned as a 2 byte string. Give the whole LSA packet as argument. For details on the algorithm, see RFC 2328 chapter 12.1.7 and RFC 905 Annex B. """ # This is based on the GPLed C implementation in Zebra <http://www.zebra.org/> CHKSUM_OFFSET = 16 if len(lsa) < CHKSUM_OFFSET: raise Exception("LSA Packet too short (%s bytes)" % len(lsa)) c0 = c1 = 0 # Calculation is done with checksum set to zero lsa = lsa[:CHKSUM_OFFSET] + lsa[CHKSUM_OFFSET + 2:] for char in lsa[2:]: # leave out age c0 += char c1 += c0 c0 %= 255 c1 %= 255 x = ((len(lsa) - CHKSUM_OFFSET - 1) * c0 - c1) % 255 if (x <= 0): x += 255 y = 510 - c0 - x if (y > 255): y -= 255 checksum = (x << 8) + y return checksum
[ "def", "ospf_lsa_checksum", "(", "lsa", ")", ":", "# This is based on the GPLed C implementation in Zebra <http://www.zebra.org/>", "CHKSUM_OFFSET", "=", "16", "if", "len", "(", "lsa", ")", "<", "CHKSUM_OFFSET", ":", "raise", "Exception", "(", "\"LSA Packet too short (%s bytes)\"", "%", "len", "(", "lsa", ")", ")", "c0", "=", "c1", "=", "0", "# Calculation is done with checksum set to zero", "lsa", "=", "lsa", "[", ":", "CHKSUM_OFFSET", "]", "+", "lsa", "[", "CHKSUM_OFFSET", "+", "2", ":", "]", "for", "char", "in", "lsa", "[", "2", ":", "]", ":", "# leave out age", "c0", "+=", "char", "c1", "+=", "c0", "c0", "%=", "255", "c1", "%=", "255", "x", "=", "(", "(", "len", "(", "lsa", ")", "-", "CHKSUM_OFFSET", "-", "1", ")", "*", "c0", "-", "c1", ")", "%", "255", "if", "(", "x", "<=", "0", ")", ":", "x", "+=", "255", "y", "=", "510", "-", "c0", "-", "x", "if", "(", "y", ">", "255", ")", ":", "y", "-=", "255", "checksum", "=", "(", "x", "<<", "8", ")", "+", "y", "return", "checksum" ]
Fletcher checksum for OSPF LSAs, returned as a 2 byte string. Give the whole LSA packet as argument. For details on the algorithm, see RFC 2328 chapter 12.1.7 and RFC 905 Annex B.
[ "Fletcher", "checksum", "for", "OSPF", "LSAs", "returned", "as", "a", "2", "byte", "string", "." ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/ospf.py#L208-L243
train
237,131
phaethon/kamene
kamene/contrib/ospf.py
_LSAGuessPayloadClass
def _LSAGuessPayloadClass(p, **kargs): """ Guess the correct LSA class for a given payload """ # This is heavily based on scapy-cdp.py by Nicolas Bareil and Arnaud Ebalard # XXX: This only works if all payload cls = conf.raw_layer if len(p) >= 4: typ = p[3] clsname = _OSPF_LSclasses.get(typ, "Raw") cls = globals()[clsname] return cls(p, **kargs)
python
def _LSAGuessPayloadClass(p, **kargs): """ Guess the correct LSA class for a given payload """ # This is heavily based on scapy-cdp.py by Nicolas Bareil and Arnaud Ebalard # XXX: This only works if all payload cls = conf.raw_layer if len(p) >= 4: typ = p[3] clsname = _OSPF_LSclasses.get(typ, "Raw") cls = globals()[clsname] return cls(p, **kargs)
[ "def", "_LSAGuessPayloadClass", "(", "p", ",", "*", "*", "kargs", ")", ":", "# This is heavily based on scapy-cdp.py by Nicolas Bareil and Arnaud Ebalard", "# XXX: This only works if all payload", "cls", "=", "conf", ".", "raw_layer", "if", "len", "(", "p", ")", ">=", "4", ":", "typ", "=", "p", "[", "3", "]", "clsname", "=", "_OSPF_LSclasses", ".", "get", "(", "typ", ",", "\"Raw\"", ")", "cls", "=", "globals", "(", ")", "[", "clsname", "]", "return", "cls", "(", "p", ",", "*", "*", "kargs", ")" ]
Guess the correct LSA class for a given payload
[ "Guess", "the", "correct", "LSA", "class", "for", "a", "given", "payload" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/ospf.py#L283-L292
train
237,132
phaethon/kamene
kamene/modules/geoip.py
locate_ip
def locate_ip(ip): """Get geographic coordinates from IP using geoip database""" ip=map(int,ip.split(".")) ip = ip[3]+(ip[2]<<8)+(ip[1]<<16)+(ip[0]<<24) cloc = country_loc_kdb.get_base() db = IP_country_kdb.get_base() d=0 f=len(db)-1 while (f-d) > 1: guess = (d+f)/2 if ip > db[guess][0]: d = guess else: f = guess s,e,c = db[guess] if s <= ip and ip <= e: return cloc.get(c,None)
python
def locate_ip(ip): """Get geographic coordinates from IP using geoip database""" ip=map(int,ip.split(".")) ip = ip[3]+(ip[2]<<8)+(ip[1]<<16)+(ip[0]<<24) cloc = country_loc_kdb.get_base() db = IP_country_kdb.get_base() d=0 f=len(db)-1 while (f-d) > 1: guess = (d+f)/2 if ip > db[guess][0]: d = guess else: f = guess s,e,c = db[guess] if s <= ip and ip <= e: return cloc.get(c,None)
[ "def", "locate_ip", "(", "ip", ")", ":", "ip", "=", "map", "(", "int", ",", "ip", ".", "split", "(", "\".\"", ")", ")", "ip", "=", "ip", "[", "3", "]", "+", "(", "ip", "[", "2", "]", "<<", "8", ")", "+", "(", "ip", "[", "1", "]", "<<", "16", ")", "+", "(", "ip", "[", "0", "]", "<<", "24", ")", "cloc", "=", "country_loc_kdb", ".", "get_base", "(", ")", "db", "=", "IP_country_kdb", ".", "get_base", "(", ")", "d", "=", "0", "f", "=", "len", "(", "db", ")", "-", "1", "while", "(", "f", "-", "d", ")", ">", "1", ":", "guess", "=", "(", "d", "+", "f", ")", "/", "2", "if", "ip", ">", "db", "[", "guess", "]", "[", "0", "]", ":", "d", "=", "guess", "else", ":", "f", "=", "guess", "s", ",", "e", ",", "c", "=", "db", "[", "guess", "]", "if", "s", "<=", "ip", "and", "ip", "<=", "e", ":", "return", "cloc", ".", "get", "(", "c", ",", "None", ")" ]
Get geographic coordinates from IP using geoip database
[ "Get", "geographic", "coordinates", "from", "IP", "using", "geoip", "database" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/modules/geoip.py#L52-L70
train
237,133
phaethon/kamene
kamene/layers/inet6.py
AS_resolver6._resolve_one
def _resolve_one(self, ip): """ overloaded version to provide a Whois resolution on the embedded IPv4 address if the address is 6to4 or Teredo. Otherwise, the native IPv6 address is passed. """ if in6_isaddr6to4(ip): # for 6to4, use embedded @ tmp = inet_pton(socket.AF_INET6, ip) addr = inet_ntop(socket.AF_INET, tmp[2:6]) elif in6_isaddrTeredo(ip): # for Teredo, use mapped address addr = teredoAddrExtractInfo(ip)[2] else: addr = ip _, asn, desc = AS_resolver_riswhois._resolve_one(self, addr) return ip,asn,desc
python
def _resolve_one(self, ip): """ overloaded version to provide a Whois resolution on the embedded IPv4 address if the address is 6to4 or Teredo. Otherwise, the native IPv6 address is passed. """ if in6_isaddr6to4(ip): # for 6to4, use embedded @ tmp = inet_pton(socket.AF_INET6, ip) addr = inet_ntop(socket.AF_INET, tmp[2:6]) elif in6_isaddrTeredo(ip): # for Teredo, use mapped address addr = teredoAddrExtractInfo(ip)[2] else: addr = ip _, asn, desc = AS_resolver_riswhois._resolve_one(self, addr) return ip,asn,desc
[ "def", "_resolve_one", "(", "self", ",", "ip", ")", ":", "if", "in6_isaddr6to4", "(", "ip", ")", ":", "# for 6to4, use embedded @", "tmp", "=", "inet_pton", "(", "socket", ".", "AF_INET6", ",", "ip", ")", "addr", "=", "inet_ntop", "(", "socket", ".", "AF_INET", ",", "tmp", "[", "2", ":", "6", "]", ")", "elif", "in6_isaddrTeredo", "(", "ip", ")", ":", "# for Teredo, use mapped address", "addr", "=", "teredoAddrExtractInfo", "(", "ip", ")", "[", "2", "]", "else", ":", "addr", "=", "ip", "_", ",", "asn", ",", "desc", "=", "AS_resolver_riswhois", ".", "_resolve_one", "(", "self", ",", "addr", ")", "return", "ip", ",", "asn", ",", "desc" ]
overloaded version to provide a Whois resolution on the embedded IPv4 address if the address is 6to4 or Teredo. Otherwise, the native IPv6 address is passed.
[ "overloaded", "version", "to", "provide", "a", "Whois", "resolution", "on", "the", "embedded", "IPv4", "address", "if", "the", "address", "is", "6to4", "or", "Teredo", ".", "Otherwise", "the", "native", "IPv6", "address", "is", "passed", "." ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/layers/inet6.py#L2882-L2899
train
237,134
phaethon/kamene
kamene/utils6.py
in6_6to4ExtractAddr
def in6_6to4ExtractAddr(addr): """ Extract IPv4 address embbeded in 6to4 address. Passed address must be a 6to4 addrees. None is returned on error. """ try: addr = inet_pton(socket.AF_INET6, addr) except: return None if addr[:2] != b" \x02": return None return inet_ntop(socket.AF_INET, addr[2:6])
python
def in6_6to4ExtractAddr(addr): """ Extract IPv4 address embbeded in 6to4 address. Passed address must be a 6to4 addrees. None is returned on error. """ try: addr = inet_pton(socket.AF_INET6, addr) except: return None if addr[:2] != b" \x02": return None return inet_ntop(socket.AF_INET, addr[2:6])
[ "def", "in6_6to4ExtractAddr", "(", "addr", ")", ":", "try", ":", "addr", "=", "inet_pton", "(", "socket", ".", "AF_INET6", ",", "addr", ")", "except", ":", "return", "None", "if", "addr", "[", ":", "2", "]", "!=", "b\" \\x02\"", ":", "return", "None", "return", "inet_ntop", "(", "socket", ".", "AF_INET", ",", "addr", "[", "2", ":", "6", "]", ")" ]
Extract IPv4 address embbeded in 6to4 address. Passed address must be a 6to4 addrees. None is returned on error.
[ "Extract", "IPv4", "address", "embbeded", "in", "6to4", "address", ".", "Passed", "address", "must", "be", "a", "6to4", "addrees", ".", "None", "is", "returned", "on", "error", "." ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/utils6.py#L386-L397
train
237,135
phaethon/kamene
kamene/utils6.py
in6_getLocalUniquePrefix
def in6_getLocalUniquePrefix(): """ Returns a pseudo-randomly generated Local Unique prefix. Function follows recommandation of Section 3.2.2 of RFC 4193 for prefix generation. """ # Extracted from RFC 1305 (NTP) : # NTP timestamps are represented as a 64-bit unsigned fixed-point number, # in seconds relative to 0h on 1 January 1900. The integer part is in the # first 32 bits and the fraction part in the last 32 bits. # epoch = (1900, 1, 1, 0, 0, 0, 5, 1, 0) # x = time.time() # from time import gmtime, strftime, gmtime, mktime # delta = mktime(gmtime(0)) - mktime(self.epoch) # x = x-delta tod = time.time() # time of day. Will bother with epoch later i = int(tod) j = int((tod - i)*(2**32)) tod = struct.pack("!II", i,j) # TODO: Add some check regarding system address gathering rawmac = get_if_raw_hwaddr(conf.iface6) mac = b":".join(map(lambda x: b"%.02x" % ord(x), list(rawmac))) # construct modified EUI-64 ID eui64 = inet_pton(socket.AF_INET6, '::' + in6_mactoifaceid(mac))[8:] import sha globalid = sha.new(tod+eui64).digest()[:5] return inet_ntop(socket.AF_INET6, b'\xfd' + globalid + b'\x00'*10)
python
def in6_getLocalUniquePrefix(): """ Returns a pseudo-randomly generated Local Unique prefix. Function follows recommandation of Section 3.2.2 of RFC 4193 for prefix generation. """ # Extracted from RFC 1305 (NTP) : # NTP timestamps are represented as a 64-bit unsigned fixed-point number, # in seconds relative to 0h on 1 January 1900. The integer part is in the # first 32 bits and the fraction part in the last 32 bits. # epoch = (1900, 1, 1, 0, 0, 0, 5, 1, 0) # x = time.time() # from time import gmtime, strftime, gmtime, mktime # delta = mktime(gmtime(0)) - mktime(self.epoch) # x = x-delta tod = time.time() # time of day. Will bother with epoch later i = int(tod) j = int((tod - i)*(2**32)) tod = struct.pack("!II", i,j) # TODO: Add some check regarding system address gathering rawmac = get_if_raw_hwaddr(conf.iface6) mac = b":".join(map(lambda x: b"%.02x" % ord(x), list(rawmac))) # construct modified EUI-64 ID eui64 = inet_pton(socket.AF_INET6, '::' + in6_mactoifaceid(mac))[8:] import sha globalid = sha.new(tod+eui64).digest()[:5] return inet_ntop(socket.AF_INET6, b'\xfd' + globalid + b'\x00'*10)
[ "def", "in6_getLocalUniquePrefix", "(", ")", ":", "# Extracted from RFC 1305 (NTP) :", "# NTP timestamps are represented as a 64-bit unsigned fixed-point number, ", "# in seconds relative to 0h on 1 January 1900. The integer part is in the ", "# first 32 bits and the fraction part in the last 32 bits.", "# epoch = (1900, 1, 1, 0, 0, 0, 5, 1, 0) ", "# x = time.time()", "# from time import gmtime, strftime, gmtime, mktime", "# delta = mktime(gmtime(0)) - mktime(self.epoch)", "# x = x-delta", "tod", "=", "time", ".", "time", "(", ")", "# time of day. Will bother with epoch later", "i", "=", "int", "(", "tod", ")", "j", "=", "int", "(", "(", "tod", "-", "i", ")", "*", "(", "2", "**", "32", ")", ")", "tod", "=", "struct", ".", "pack", "(", "\"!II\"", ",", "i", ",", "j", ")", "# TODO: Add some check regarding system address gathering", "rawmac", "=", "get_if_raw_hwaddr", "(", "conf", ".", "iface6", ")", "mac", "=", "b\":\"", ".", "join", "(", "map", "(", "lambda", "x", ":", "b\"%.02x\"", "%", "ord", "(", "x", ")", ",", "list", "(", "rawmac", ")", ")", ")", "# construct modified EUI-64 ID", "eui64", "=", "inet_pton", "(", "socket", ".", "AF_INET6", ",", "'::'", "+", "in6_mactoifaceid", "(", "mac", ")", ")", "[", "8", ":", "]", "import", "sha", "globalid", "=", "sha", ".", "new", "(", "tod", "+", "eui64", ")", ".", "digest", "(", ")", "[", ":", "5", "]", "return", "inet_ntop", "(", "socket", ".", "AF_INET6", ",", "b'\\xfd'", "+", "globalid", "+", "b'\\x00'", "*", "10", ")" ]
Returns a pseudo-randomly generated Local Unique prefix. Function follows recommandation of Section 3.2.2 of RFC 4193 for prefix generation.
[ "Returns", "a", "pseudo", "-", "randomly", "generated", "Local", "Unique", "prefix", ".", "Function", "follows", "recommandation", "of", "Section", "3", ".", "2", ".", "2", "of", "RFC", "4193", "for", "prefix", "generation", "." ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/utils6.py#L400-L428
train
237,136
phaethon/kamene
kamene/utils6.py
in6_getnsmac
def in6_getnsmac(a): # return multicast Ethernet address associated with multicast v6 destination """ Return the multicast mac address associated with provided IPv6 address. Passed address must be in network format. """ a = struct.unpack('16B', a)[-4:] mac = '33:33:' mac += (':'.join(map(lambda x: '%.2x' %x, a))) return mac
python
def in6_getnsmac(a): # return multicast Ethernet address associated with multicast v6 destination """ Return the multicast mac address associated with provided IPv6 address. Passed address must be in network format. """ a = struct.unpack('16B', a)[-4:] mac = '33:33:' mac += (':'.join(map(lambda x: '%.2x' %x, a))) return mac
[ "def", "in6_getnsmac", "(", "a", ")", ":", "# return multicast Ethernet address associated with multicast v6 destination", "a", "=", "struct", ".", "unpack", "(", "'16B'", ",", "a", ")", "[", "-", "4", ":", "]", "mac", "=", "'33:33:'", "mac", "+=", "(", "':'", ".", "join", "(", "map", "(", "lambda", "x", ":", "'%.2x'", "%", "x", ",", "a", ")", ")", ")", "return", "mac" ]
Return the multicast mac address associated with provided IPv6 address. Passed address must be in network format.
[ "Return", "the", "multicast", "mac", "address", "associated", "with", "provided", "IPv6", "address", ".", "Passed", "address", "must", "be", "in", "network", "format", "." ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/utils6.py#L646-L655
train
237,137
phaethon/kamene
kamene/arch/windows/__init__.py
_where
def _where(filename, dirs=[], env="PATH"): """Find file in current dir or system path""" if not isinstance(dirs, list): dirs = [dirs] if glob(filename): return filename paths = [os.curdir] + os.environ[env].split(os.path.pathsep) + dirs for path in paths: for match in glob(os.path.join(path, filename)): if match: return os.path.normpath(match) raise IOError("File not found: %s" % filename)
python
def _where(filename, dirs=[], env="PATH"): """Find file in current dir or system path""" if not isinstance(dirs, list): dirs = [dirs] if glob(filename): return filename paths = [os.curdir] + os.environ[env].split(os.path.pathsep) + dirs for path in paths: for match in glob(os.path.join(path, filename)): if match: return os.path.normpath(match) raise IOError("File not found: %s" % filename)
[ "def", "_where", "(", "filename", ",", "dirs", "=", "[", "]", ",", "env", "=", "\"PATH\"", ")", ":", "if", "not", "isinstance", "(", "dirs", ",", "list", ")", ":", "dirs", "=", "[", "dirs", "]", "if", "glob", "(", "filename", ")", ":", "return", "filename", "paths", "=", "[", "os", ".", "curdir", "]", "+", "os", ".", "environ", "[", "env", "]", ".", "split", "(", "os", ".", "path", ".", "pathsep", ")", "+", "dirs", "for", "path", "in", "paths", ":", "for", "match", "in", "glob", "(", "os", ".", "path", ".", "join", "(", "path", ",", "filename", ")", ")", ":", "if", "match", ":", "return", "os", ".", "path", ".", "normpath", "(", "match", ")", "raise", "IOError", "(", "\"File not found: %s\"", "%", "filename", ")" ]
Find file in current dir or system path
[ "Find", "file", "in", "current", "dir", "or", "system", "path" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/arch/windows/__init__.py#L30-L41
train
237,138
phaethon/kamene
kamene/arch/windows/__init__.py
win_find_exe
def win_find_exe(filename, installsubdir=None, env="ProgramFiles"): """Find executable in current dir, system path or given ProgramFiles subdir""" for fn in [filename, filename+".exe"]: try: if installsubdir is None: path = _where(fn) else: path = _where(fn, dirs=[os.path.join(os.environ[env], installsubdir)]) except IOError: path = filename else: break return path
python
def win_find_exe(filename, installsubdir=None, env="ProgramFiles"): """Find executable in current dir, system path or given ProgramFiles subdir""" for fn in [filename, filename+".exe"]: try: if installsubdir is None: path = _where(fn) else: path = _where(fn, dirs=[os.path.join(os.environ[env], installsubdir)]) except IOError: path = filename else: break return path
[ "def", "win_find_exe", "(", "filename", ",", "installsubdir", "=", "None", ",", "env", "=", "\"ProgramFiles\"", ")", ":", "for", "fn", "in", "[", "filename", ",", "filename", "+", "\".exe\"", "]", ":", "try", ":", "if", "installsubdir", "is", "None", ":", "path", "=", "_where", "(", "fn", ")", "else", ":", "path", "=", "_where", "(", "fn", ",", "dirs", "=", "[", "os", ".", "path", ".", "join", "(", "os", ".", "environ", "[", "env", "]", ",", "installsubdir", ")", "]", ")", "except", "IOError", ":", "path", "=", "filename", "else", ":", "break", "return", "path" ]
Find executable in current dir, system path or given ProgramFiles subdir
[ "Find", "executable", "in", "current", "dir", "system", "path", "or", "given", "ProgramFiles", "subdir" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/arch/windows/__init__.py#L43-L55
train
237,139
phaethon/kamene
kamene/arch/windows/__init__.py
NetworkInterface.init_loopback
def init_loopback(self, data): """Just initialize the object for our Pseudo Loopback""" self.name = data["name"] self.description = data['description'] self.win_index = data['win_index'] self.mac = data["mac"] self.guid = data["guid"] self.ip = "127.0.0.1"
python
def init_loopback(self, data): """Just initialize the object for our Pseudo Loopback""" self.name = data["name"] self.description = data['description'] self.win_index = data['win_index'] self.mac = data["mac"] self.guid = data["guid"] self.ip = "127.0.0.1"
[ "def", "init_loopback", "(", "self", ",", "data", ")", ":", "self", ".", "name", "=", "data", "[", "\"name\"", "]", "self", ".", "description", "=", "data", "[", "'description'", "]", "self", ".", "win_index", "=", "data", "[", "'win_index'", "]", "self", ".", "mac", "=", "data", "[", "\"mac\"", "]", "self", ".", "guid", "=", "data", "[", "\"guid\"", "]", "self", ".", "ip", "=", "\"127.0.0.1\"" ]
Just initialize the object for our Pseudo Loopback
[ "Just", "initialize", "the", "object", "for", "our", "Pseudo", "Loopback" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/arch/windows/__init__.py#L120-L127
train
237,140
phaethon/kamene
kamene/arch/windows/__init__.py
NetworkInterface.update
def update(self, data): """Update info about network interface according to given dnet dictionary""" self.name = data["name"] self.description = data['description'] self.win_index = data['win_index'] # Other attributes are optional if conf.use_winpcapy: self._update_pcapdata() try: self.ip = socket.inet_ntoa(get_if_raw_addr(data['guid'])) except (KeyError, AttributeError, NameError): pass try: self.mac = data['mac'] except KeyError: pass
python
def update(self, data): """Update info about network interface according to given dnet dictionary""" self.name = data["name"] self.description = data['description'] self.win_index = data['win_index'] # Other attributes are optional if conf.use_winpcapy: self._update_pcapdata() try: self.ip = socket.inet_ntoa(get_if_raw_addr(data['guid'])) except (KeyError, AttributeError, NameError): pass try: self.mac = data['mac'] except KeyError: pass
[ "def", "update", "(", "self", ",", "data", ")", ":", "self", ".", "name", "=", "data", "[", "\"name\"", "]", "self", ".", "description", "=", "data", "[", "'description'", "]", "self", ".", "win_index", "=", "data", "[", "'win_index'", "]", "# Other attributes are optional", "if", "conf", ".", "use_winpcapy", ":", "self", ".", "_update_pcapdata", "(", ")", "try", ":", "self", ".", "ip", "=", "socket", ".", "inet_ntoa", "(", "get_if_raw_addr", "(", "data", "[", "'guid'", "]", ")", ")", "except", "(", "KeyError", ",", "AttributeError", ",", "NameError", ")", ":", "pass", "try", ":", "self", ".", "mac", "=", "data", "[", "'mac'", "]", "except", "KeyError", ":", "pass" ]
Update info about network interface according to given dnet dictionary
[ "Update", "info", "about", "network", "interface", "according", "to", "given", "dnet", "dictionary" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/arch/windows/__init__.py#L129-L144
train
237,141
phaethon/kamene
kamene/arch/windows/__init__.py
NetworkInterfaceDict.pcap_name
def pcap_name(self, devname): """Return pcap device name for given Windows device name.""" try: pcap_name = self.data[devname].pcap_name except KeyError: raise ValueError("Unknown network interface %r" % devname) else: return pcap_name
python
def pcap_name(self, devname): """Return pcap device name for given Windows device name.""" try: pcap_name = self.data[devname].pcap_name except KeyError: raise ValueError("Unknown network interface %r" % devname) else: return pcap_name
[ "def", "pcap_name", "(", "self", ",", "devname", ")", ":", "try", ":", "pcap_name", "=", "self", ".", "data", "[", "devname", "]", ".", "pcap_name", "except", "KeyError", ":", "raise", "ValueError", "(", "\"Unknown network interface %r\"", "%", "devname", ")", "else", ":", "return", "pcap_name" ]
Return pcap device name for given Windows device name.
[ "Return", "pcap", "device", "name", "for", "given", "Windows", "device", "name", "." ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/arch/windows/__init__.py#L175-L183
train
237,142
phaethon/kamene
kamene/layers/dns.py
bitmap2RRlist
def bitmap2RRlist(bitmap): """ Decode the 'Type Bit Maps' field of the NSEC Resource Record into an integer list. """ # RFC 4034, 4.1.2. The Type Bit Maps Field RRlist = [] while bitmap: if len(bitmap) < 2: warning("bitmap too short (%i)" % len(bitmap)) return #window_block = ord(bitmap[0]) # window number window_block = (bitmap[0]) # window number offset = 256*window_block # offset of the Ressource Record #bitmap_len = ord(bitmap[0]) # length of the bitmap in bytes bitmap_len = (bitmap[1]) # length of the bitmap in bytes if bitmap_len <= 0 or bitmap_len > 32: warning("bitmap length is no valid (%i)" % bitmap_len) return tmp_bitmap = bitmap[2:2+bitmap_len] # Let's compare each bit of tmp_bitmap and compute the real RR value for b in range(len(tmp_bitmap)): v = 128 for i in range(8): #if ord(tmp_bitmap[b]) & v: if (tmp_bitmap[b]) & v: # each of the RR is encoded as a bit RRlist += [ offset + b*8 + i ] v = v >> 1 # Next block if any bitmap = bitmap[2+bitmap_len:] return RRlist
python
def bitmap2RRlist(bitmap): """ Decode the 'Type Bit Maps' field of the NSEC Resource Record into an integer list. """ # RFC 4034, 4.1.2. The Type Bit Maps Field RRlist = [] while bitmap: if len(bitmap) < 2: warning("bitmap too short (%i)" % len(bitmap)) return #window_block = ord(bitmap[0]) # window number window_block = (bitmap[0]) # window number offset = 256*window_block # offset of the Ressource Record #bitmap_len = ord(bitmap[0]) # length of the bitmap in bytes bitmap_len = (bitmap[1]) # length of the bitmap in bytes if bitmap_len <= 0 or bitmap_len > 32: warning("bitmap length is no valid (%i)" % bitmap_len) return tmp_bitmap = bitmap[2:2+bitmap_len] # Let's compare each bit of tmp_bitmap and compute the real RR value for b in range(len(tmp_bitmap)): v = 128 for i in range(8): #if ord(tmp_bitmap[b]) & v: if (tmp_bitmap[b]) & v: # each of the RR is encoded as a bit RRlist += [ offset + b*8 + i ] v = v >> 1 # Next block if any bitmap = bitmap[2+bitmap_len:] return RRlist
[ "def", "bitmap2RRlist", "(", "bitmap", ")", ":", "# RFC 4034, 4.1.2. The Type Bit Maps Field", "RRlist", "=", "[", "]", "while", "bitmap", ":", "if", "len", "(", "bitmap", ")", "<", "2", ":", "warning", "(", "\"bitmap too short (%i)\"", "%", "len", "(", "bitmap", ")", ")", "return", "#window_block = ord(bitmap[0]) # window number", "window_block", "=", "(", "bitmap", "[", "0", "]", ")", "# window number", "offset", "=", "256", "*", "window_block", "# offset of the Ressource Record", "#bitmap_len = ord(bitmap[0]) # length of the bitmap in bytes", "bitmap_len", "=", "(", "bitmap", "[", "1", "]", ")", "# length of the bitmap in bytes", "if", "bitmap_len", "<=", "0", "or", "bitmap_len", ">", "32", ":", "warning", "(", "\"bitmap length is no valid (%i)\"", "%", "bitmap_len", ")", "return", "tmp_bitmap", "=", "bitmap", "[", "2", ":", "2", "+", "bitmap_len", "]", "# Let's compare each bit of tmp_bitmap and compute the real RR value", "for", "b", "in", "range", "(", "len", "(", "tmp_bitmap", ")", ")", ":", "v", "=", "128", "for", "i", "in", "range", "(", "8", ")", ":", "#if ord(tmp_bitmap[b]) & v:", "if", "(", "tmp_bitmap", "[", "b", "]", ")", "&", "v", ":", "# each of the RR is encoded as a bit", "RRlist", "+=", "[", "offset", "+", "b", "*", "8", "+", "i", "]", "v", "=", "v", ">>", "1", "# Next block if any", "bitmap", "=", "bitmap", "[", "2", "+", "bitmap_len", ":", "]", "return", "RRlist" ]
Decode the 'Type Bit Maps' field of the NSEC Resource Record into an integer list.
[ "Decode", "the", "Type", "Bit", "Maps", "field", "of", "the", "NSEC", "Resource", "Record", "into", "an", "integer", "list", "." ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/layers/dns.py#L376-L416
train
237,143
phaethon/kamene
kamene/contrib/gtp.py
IE_Dispatcher
def IE_Dispatcher(s): """Choose the correct Information Element class.""" if len(s) < 1: return Raw(s) # Get the IE type ietype = ord(s[0]) cls = ietypecls.get(ietype, Raw) # if ietype greater than 128 are TLVs if cls == Raw and ietype & 128 == 128: cls = IE_NotImplementedTLV return cls(s)
python
def IE_Dispatcher(s): """Choose the correct Information Element class.""" if len(s) < 1: return Raw(s) # Get the IE type ietype = ord(s[0]) cls = ietypecls.get(ietype, Raw) # if ietype greater than 128 are TLVs if cls == Raw and ietype & 128 == 128: cls = IE_NotImplementedTLV return cls(s)
[ "def", "IE_Dispatcher", "(", "s", ")", ":", "if", "len", "(", "s", ")", "<", "1", ":", "return", "Raw", "(", "s", ")", "# Get the IE type", "ietype", "=", "ord", "(", "s", "[", "0", "]", ")", "cls", "=", "ietypecls", ".", "get", "(", "ietype", ",", "Raw", ")", "# if ietype greater than 128 are TLVs", "if", "cls", "==", "Raw", "and", "ietype", "&", "128", "==", "128", ":", "cls", "=", "IE_NotImplementedTLV", "return", "cls", "(", "s", ")" ]
Choose the correct Information Element class.
[ "Choose", "the", "correct", "Information", "Element", "class", "." ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gtp.py#L399-L413
train
237,144
phaethon/kamene
kamene/plist.py
PacketList.filter
def filter(self, func): """Returns a packet list filtered by a truth function""" return self.__class__(list(filter(func,self.res)), name="filtered %s"%self.listname)
python
def filter(self, func): """Returns a packet list filtered by a truth function""" return self.__class__(list(filter(func,self.res)), name="filtered %s"%self.listname)
[ "def", "filter", "(", "self", ",", "func", ")", ":", "return", "self", ".", "__class__", "(", "list", "(", "filter", "(", "func", ",", "self", ".", "res", ")", ")", ",", "name", "=", "\"filtered %s\"", "%", "self", ".", "listname", ")" ]
Returns a packet list filtered by a truth function
[ "Returns", "a", "packet", "list", "filtered", "by", "a", "truth", "function" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/plist.py#L133-L136
train
237,145
phaethon/kamene
kamene/plist.py
PacketList.multiplot
def multiplot(self, f, lfilter=None, **kargs): """Uses a function that returns a label and a value for this label, then plots all the values label by label""" d = defaultdict(list) for i in self.res: if lfilter and not lfilter(i): continue k, v = f(i) d[k].append(v) figure = plt.figure() ax = figure.add_axes(plt.axes()) for i in d: ax.plot(d[i], **kargs) return figure
python
def multiplot(self, f, lfilter=None, **kargs): """Uses a function that returns a label and a value for this label, then plots all the values label by label""" d = defaultdict(list) for i in self.res: if lfilter and not lfilter(i): continue k, v = f(i) d[k].append(v) figure = plt.figure() ax = figure.add_axes(plt.axes()) for i in d: ax.plot(d[i], **kargs) return figure
[ "def", "multiplot", "(", "self", ",", "f", ",", "lfilter", "=", "None", ",", "*", "*", "kargs", ")", ":", "d", "=", "defaultdict", "(", "list", ")", "for", "i", "in", "self", ".", "res", ":", "if", "lfilter", "and", "not", "lfilter", "(", "i", ")", ":", "continue", "k", ",", "v", "=", "f", "(", "i", ")", "d", "[", "k", "]", ".", "append", "(", "v", ")", "figure", "=", "plt", ".", "figure", "(", ")", "ax", "=", "figure", ".", "add_axes", "(", "plt", ".", "axes", "(", ")", ")", "for", "i", "in", "d", ":", "ax", ".", "plot", "(", "d", "[", "i", "]", ",", "*", "*", "kargs", ")", "return", "figure" ]
Uses a function that returns a label and a value for this label, then plots all the values label by label
[ "Uses", "a", "function", "that", "returns", "a", "label", "and", "a", "value", "for", "this", "label", "then", "plots", "all", "the", "values", "label", "by", "label" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/plist.py#L151-L165
train
237,146
phaethon/kamene
kamene/plist.py
SndRcvList.filter
def filter(self, func): """Returns a SndRcv list filtered by a truth function""" return self.__class__( [ i for i in self.res if func(*i) ], name='filtered %s'%self.listname)
python
def filter(self, func): """Returns a SndRcv list filtered by a truth function""" return self.__class__( [ i for i in self.res if func(*i) ], name='filtered %s'%self.listname)
[ "def", "filter", "(", "self", ",", "func", ")", ":", "return", "self", ".", "__class__", "(", "[", "i", "for", "i", "in", "self", ".", "res", "if", "func", "(", "*", "i", ")", "]", ",", "name", "=", "'filtered %s'", "%", "self", ".", "listname", ")" ]
Returns a SndRcv list filtered by a truth function
[ "Returns", "a", "SndRcv", "list", "filtered", "by", "a", "truth", "function" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/plist.py#L504-L506
train
237,147
phaethon/kamene
kamene/contrib/ppi.py
_PPIGuessPayloadClass
def _PPIGuessPayloadClass(p, **kargs): """ This function tells the PacketListField how it should extract the TLVs from the payload. We pass cls only the length string pfh_len says it needs. If a payload is returned, that means part of the sting was unused. This converts to a Raw layer, and the remainder of p is added as Raw's payload. If there is no payload, the remainder of p is added as out's payload. """ if len(p) >= 4: t,pfh_len = struct.unpack("<HH", p[:4]) # Find out if the value t is in the dict _ppi_types. # If not, return the default TLV class cls = getPPIType(t, "default") pfh_len += 4 out = cls(p[:pfh_len], **kargs) if (out.payload): out.payload = conf.raw_layer(out.payload.load) if (len(p) > pfh_len): out.payload.payload = conf.padding_layer(p[pfh_len:]) elif (len(p) > pfh_len): out.payload = conf.padding_layer(p[pfh_len:]) else: out = conf.raw_layer(p, **kargs) return out
python
def _PPIGuessPayloadClass(p, **kargs): """ This function tells the PacketListField how it should extract the TLVs from the payload. We pass cls only the length string pfh_len says it needs. If a payload is returned, that means part of the sting was unused. This converts to a Raw layer, and the remainder of p is added as Raw's payload. If there is no payload, the remainder of p is added as out's payload. """ if len(p) >= 4: t,pfh_len = struct.unpack("<HH", p[:4]) # Find out if the value t is in the dict _ppi_types. # If not, return the default TLV class cls = getPPIType(t, "default") pfh_len += 4 out = cls(p[:pfh_len], **kargs) if (out.payload): out.payload = conf.raw_layer(out.payload.load) if (len(p) > pfh_len): out.payload.payload = conf.padding_layer(p[pfh_len:]) elif (len(p) > pfh_len): out.payload = conf.padding_layer(p[pfh_len:]) else: out = conf.raw_layer(p, **kargs) return out
[ "def", "_PPIGuessPayloadClass", "(", "p", ",", "*", "*", "kargs", ")", ":", "if", "len", "(", "p", ")", ">=", "4", ":", "t", ",", "pfh_len", "=", "struct", ".", "unpack", "(", "\"<HH\"", ",", "p", "[", ":", "4", "]", ")", "# Find out if the value t is in the dict _ppi_types.\r", "# If not, return the default TLV class\r", "cls", "=", "getPPIType", "(", "t", ",", "\"default\"", ")", "pfh_len", "+=", "4", "out", "=", "cls", "(", "p", "[", ":", "pfh_len", "]", ",", "*", "*", "kargs", ")", "if", "(", "out", ".", "payload", ")", ":", "out", ".", "payload", "=", "conf", ".", "raw_layer", "(", "out", ".", "payload", ".", "load", ")", "if", "(", "len", "(", "p", ")", ">", "pfh_len", ")", ":", "out", ".", "payload", ".", "payload", "=", "conf", ".", "padding_layer", "(", "p", "[", "pfh_len", ":", "]", ")", "elif", "(", "len", "(", "p", ")", ">", "pfh_len", ")", ":", "out", ".", "payload", "=", "conf", ".", "padding_layer", "(", "p", "[", "pfh_len", ":", "]", ")", "else", ":", "out", "=", "conf", ".", "raw_layer", "(", "p", ",", "*", "*", "kargs", ")", "return", "out" ]
This function tells the PacketListField how it should extract the TLVs from the payload. We pass cls only the length string pfh_len says it needs. If a payload is returned, that means part of the sting was unused. This converts to a Raw layer, and the remainder of p is added as Raw's payload. If there is no payload, the remainder of p is added as out's payload.
[ "This", "function", "tells", "the", "PacketListField", "how", "it", "should", "extract", "the", "TLVs", "from", "the", "payload", ".", "We", "pass", "cls", "only", "the", "length", "string", "pfh_len", "says", "it", "needs", ".", "If", "a", "payload", "is", "returned", "that", "means", "part", "of", "the", "sting", "was", "unused", ".", "This", "converts", "to", "a", "Raw", "layer", "and", "the", "remainder", "of", "p", "is", "added", "as", "Raw", "s", "payload", ".", "If", "there", "is", "no", "payload", "the", "remainder", "of", "p", "is", "added", "as", "out", "s", "payload", "." ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/ppi.py#L38-L62
train
237,148
phaethon/kamene
kamene/fields.py
Field.i2b
def i2b(self, pkt, x): """Convert internal value to internal value""" if type(x) is str: x = bytes([ ord(i) for i in x ]) return x
python
def i2b(self, pkt, x): """Convert internal value to internal value""" if type(x) is str: x = bytes([ ord(i) for i in x ]) return x
[ "def", "i2b", "(", "self", ",", "pkt", ",", "x", ")", ":", "if", "type", "(", "x", ")", "is", "str", ":", "x", "=", "bytes", "(", "[", "ord", "(", "i", ")", "for", "i", "in", "x", "]", ")", "return", "x" ]
Convert internal value to internal value
[ "Convert", "internal", "value", "to", "internal", "value" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/fields.py#L45-L49
train
237,149
phaethon/kamene
kamene/fields.py
Field.randval
def randval(self): """Return a volatile object whose value is both random and suitable for this field""" fmtt = self.fmt[-1] if fmtt in "BHIQ": return {"B":RandByte,"H":RandShort,"I":RandInt, "Q":RandLong}[fmtt]() elif fmtt == "s": if self.fmt[0] in "0123456789": l = int(self.fmt[:-1]) else: l = int(self.fmt[1:-1]) return RandBin(l) else: warning("no random class for [%s] (fmt=%s)." % (self.name, self.fmt))
python
def randval(self): """Return a volatile object whose value is both random and suitable for this field""" fmtt = self.fmt[-1] if fmtt in "BHIQ": return {"B":RandByte,"H":RandShort,"I":RandInt, "Q":RandLong}[fmtt]() elif fmtt == "s": if self.fmt[0] in "0123456789": l = int(self.fmt[:-1]) else: l = int(self.fmt[1:-1]) return RandBin(l) else: warning("no random class for [%s] (fmt=%s)." % (self.name, self.fmt))
[ "def", "randval", "(", "self", ")", ":", "fmtt", "=", "self", ".", "fmt", "[", "-", "1", "]", "if", "fmtt", "in", "\"BHIQ\"", ":", "return", "{", "\"B\"", ":", "RandByte", ",", "\"H\"", ":", "RandShort", ",", "\"I\"", ":", "RandInt", ",", "\"Q\"", ":", "RandLong", "}", "[", "fmtt", "]", "(", ")", "elif", "fmtt", "==", "\"s\"", ":", "if", "self", ".", "fmt", "[", "0", "]", "in", "\"0123456789\"", ":", "l", "=", "int", "(", "self", ".", "fmt", "[", ":", "-", "1", "]", ")", "else", ":", "l", "=", "int", "(", "self", ".", "fmt", "[", "1", ":", "-", "1", "]", ")", "return", "RandBin", "(", "l", ")", "else", ":", "warning", "(", "\"no random class for [%s] (fmt=%s).\"", "%", "(", "self", ".", "name", ",", "self", ".", "fmt", ")", ")" ]
Return a volatile object whose value is both random and suitable for this field
[ "Return", "a", "volatile", "object", "whose", "value", "is", "both", "random", "and", "suitable", "for", "this", "field" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/fields.py#L93-L105
train
237,150
phaethon/kamene
kamene/utils.py
str2bytes
def str2bytes(x): """Convert input argument to bytes""" if type(x) is bytes: return x elif type(x) is str: return bytes([ ord(i) for i in x ]) else: return str2bytes(str(x))
python
def str2bytes(x): """Convert input argument to bytes""" if type(x) is bytes: return x elif type(x) is str: return bytes([ ord(i) for i in x ]) else: return str2bytes(str(x))
[ "def", "str2bytes", "(", "x", ")", ":", "if", "type", "(", "x", ")", "is", "bytes", ":", "return", "x", "elif", "type", "(", "x", ")", "is", "str", ":", "return", "bytes", "(", "[", "ord", "(", "i", ")", "for", "i", "in", "x", "]", ")", "else", ":", "return", "str2bytes", "(", "str", "(", "x", ")", ")" ]
Convert input argument to bytes
[ "Convert", "input", "argument", "to", "bytes" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/utils.py#L41-L48
train
237,151
phaethon/kamene
kamene/utils.py
is_private_addr
def is_private_addr(x): """Returns True if the IPv4 Address is an RFC 1918 private address.""" paddrs = ['10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16'] found = False for ipr in paddrs: try: if ipaddress.ip_address(x) in ipaddress.ip_network(ipr): found = True continue except: break return found
python
def is_private_addr(x): """Returns True if the IPv4 Address is an RFC 1918 private address.""" paddrs = ['10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16'] found = False for ipr in paddrs: try: if ipaddress.ip_address(x) in ipaddress.ip_network(ipr): found = True continue except: break return found
[ "def", "is_private_addr", "(", "x", ")", ":", "paddrs", "=", "[", "'10.0.0.0/8'", ",", "'172.16.0.0/12'", ",", "'192.168.0.0/16'", "]", "found", "=", "False", "for", "ipr", "in", "paddrs", ":", "try", ":", "if", "ipaddress", ".", "ip_address", "(", "x", ")", "in", "ipaddress", ".", "ip_network", "(", "ipr", ")", ":", "found", "=", "True", "continue", "except", ":", "break", "return", "found" ]
Returns True if the IPv4 Address is an RFC 1918 private address.
[ "Returns", "True", "if", "the", "IPv4", "Address", "is", "an", "RFC", "1918", "private", "address", "." ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/utils.py#L96-L107
train
237,152
phaethon/kamene
kamene/utils.py
corrupt_bytes
def corrupt_bytes(s, p=0.01, n=None): """Corrupt a given percentage or number of bytes from bytes""" s = bytes(s) s = array.array("B",s) l = len(s) if n is None: n = max(1,int(l*p)) for i in random.sample(range(l), n): s[i] = (s[i]+random.randint(1,255))%256 return s.tobytes()
python
def corrupt_bytes(s, p=0.01, n=None): """Corrupt a given percentage or number of bytes from bytes""" s = bytes(s) s = array.array("B",s) l = len(s) if n is None: n = max(1,int(l*p)) for i in random.sample(range(l), n): s[i] = (s[i]+random.randint(1,255))%256 return s.tobytes()
[ "def", "corrupt_bytes", "(", "s", ",", "p", "=", "0.01", ",", "n", "=", "None", ")", ":", "s", "=", "bytes", "(", "s", ")", "s", "=", "array", ".", "array", "(", "\"B\"", ",", "s", ")", "l", "=", "len", "(", "s", ")", "if", "n", "is", "None", ":", "n", "=", "max", "(", "1", ",", "int", "(", "l", "*", "p", ")", ")", "for", "i", "in", "random", ".", "sample", "(", "range", "(", "l", ")", ",", "n", ")", ":", "s", "[", "i", "]", "=", "(", "s", "[", "i", "]", "+", "random", ".", "randint", "(", "1", ",", "255", ")", ")", "%", "256", "return", "s", ".", "tobytes", "(", ")" ]
Corrupt a given percentage or number of bytes from bytes
[ "Corrupt", "a", "given", "percentage", "or", "number", "of", "bytes", "from", "bytes" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/utils.py#L516-L525
train
237,153
phaethon/kamene
kamene/utils.py
wireshark
def wireshark(pktlist, *args): """Run wireshark on a list of packets""" fname = get_temp_file() wrpcap(fname, pktlist) subprocess.Popen([conf.prog.wireshark, "-r", fname] + list(args))
python
def wireshark(pktlist, *args): """Run wireshark on a list of packets""" fname = get_temp_file() wrpcap(fname, pktlist) subprocess.Popen([conf.prog.wireshark, "-r", fname] + list(args))
[ "def", "wireshark", "(", "pktlist", ",", "*", "args", ")", ":", "fname", "=", "get_temp_file", "(", ")", "wrpcap", "(", "fname", ",", "pktlist", ")", "subprocess", ".", "Popen", "(", "[", "conf", ".", "prog", ".", "wireshark", ",", "\"-r\"", ",", "fname", "]", "+", "list", "(", "args", ")", ")" ]
Run wireshark on a list of packets
[ "Run", "wireshark", "on", "a", "list", "of", "packets" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/utils.py#L1003-L1007
train
237,154
phaethon/kamene
kamene/utils.py
tdecode
def tdecode(pkt, *args): """Run tshark to decode and display the packet. If no args defined uses -V""" if not args: args = [ "-V" ] fname = get_temp_file() wrpcap(fname,[pkt]) subprocess.call(["tshark", "-r", fname] + list(args))
python
def tdecode(pkt, *args): """Run tshark to decode and display the packet. If no args defined uses -V""" if not args: args = [ "-V" ] fname = get_temp_file() wrpcap(fname,[pkt]) subprocess.call(["tshark", "-r", fname] + list(args))
[ "def", "tdecode", "(", "pkt", ",", "*", "args", ")", ":", "if", "not", "args", ":", "args", "=", "[", "\"-V\"", "]", "fname", "=", "get_temp_file", "(", ")", "wrpcap", "(", "fname", ",", "[", "pkt", "]", ")", "subprocess", ".", "call", "(", "[", "\"tshark\"", ",", "\"-r\"", ",", "fname", "]", "+", "list", "(", "args", ")", ")" ]
Run tshark to decode and display the packet. If no args defined uses -V
[ "Run", "tshark", "to", "decode", "and", "display", "the", "packet", ".", "If", "no", "args", "defined", "uses", "-", "V" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/utils.py#L1010-L1016
train
237,155
phaethon/kamene
kamene/utils.py
hexedit
def hexedit(x): """Run external hex editor on a packet or bytes. Set editor in conf.prog.hexedit""" x = bytes(x) fname = get_temp_file() with open(fname,"wb") as f: f.write(x) subprocess.call([conf.prog.hexedit, fname]) with open(fname, "rb") as f: x = f.read() return x
python
def hexedit(x): """Run external hex editor on a packet or bytes. Set editor in conf.prog.hexedit""" x = bytes(x) fname = get_temp_file() with open(fname,"wb") as f: f.write(x) subprocess.call([conf.prog.hexedit, fname]) with open(fname, "rb") as f: x = f.read() return x
[ "def", "hexedit", "(", "x", ")", ":", "x", "=", "bytes", "(", "x", ")", "fname", "=", "get_temp_file", "(", ")", "with", "open", "(", "fname", ",", "\"wb\"", ")", "as", "f", ":", "f", ".", "write", "(", "x", ")", "subprocess", ".", "call", "(", "[", "conf", ".", "prog", ".", "hexedit", ",", "fname", "]", ")", "with", "open", "(", "fname", ",", "\"rb\"", ")", "as", "f", ":", "x", "=", "f", ".", "read", "(", ")", "return", "x" ]
Run external hex editor on a packet or bytes. Set editor in conf.prog.hexedit
[ "Run", "external", "hex", "editor", "on", "a", "packet", "or", "bytes", ".", "Set", "editor", "in", "conf", ".", "prog", ".", "hexedit" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/utils.py#L1019-L1028
train
237,156
phaethon/kamene
kamene/utils.py
RawPcapWriter._write_packet
def _write_packet(self, packet, sec=None, usec=None, caplen=None, wirelen=None): """writes a single packet to the pcap file """ if caplen is None: caplen = len(packet) if wirelen is None: wirelen = caplen if sec is None or usec is None: t=time.time() it = int(t) if sec is None: sec = it if usec is None: usec = int(round((t-it)*1000000)) self.f.write(struct.pack(self.endian+"IIII", sec, usec, caplen, wirelen)) self.f.write(packet) if self.gz and self.sync: self.f.flush()
python
def _write_packet(self, packet, sec=None, usec=None, caplen=None, wirelen=None): """writes a single packet to the pcap file """ if caplen is None: caplen = len(packet) if wirelen is None: wirelen = caplen if sec is None or usec is None: t=time.time() it = int(t) if sec is None: sec = it if usec is None: usec = int(round((t-it)*1000000)) self.f.write(struct.pack(self.endian+"IIII", sec, usec, caplen, wirelen)) self.f.write(packet) if self.gz and self.sync: self.f.flush()
[ "def", "_write_packet", "(", "self", ",", "packet", ",", "sec", "=", "None", ",", "usec", "=", "None", ",", "caplen", "=", "None", ",", "wirelen", "=", "None", ")", ":", "if", "caplen", "is", "None", ":", "caplen", "=", "len", "(", "packet", ")", "if", "wirelen", "is", "None", ":", "wirelen", "=", "caplen", "if", "sec", "is", "None", "or", "usec", "is", "None", ":", "t", "=", "time", ".", "time", "(", ")", "it", "=", "int", "(", "t", ")", "if", "sec", "is", "None", ":", "sec", "=", "it", "if", "usec", "is", "None", ":", "usec", "=", "int", "(", "round", "(", "(", "t", "-", "it", ")", "*", "1000000", ")", ")", "self", ".", "f", ".", "write", "(", "struct", ".", "pack", "(", "self", ".", "endian", "+", "\"IIII\"", ",", "sec", ",", "usec", ",", "caplen", ",", "wirelen", ")", ")", "self", ".", "f", ".", "write", "(", "packet", ")", "if", "self", ".", "gz", "and", "self", ".", "sync", ":", "self", ".", "f", ".", "flush", "(", ")" ]
writes a single packet to the pcap file
[ "writes", "a", "single", "packet", "to", "the", "pcap", "file" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/utils.py#L905-L922
train
237,157
phaethon/kamene
kamene/utils.py
PcapWriter.get_packet_time
def get_packet_time(self, pkt): """Return the second and micro-second timestamp components for a packet.""" if pkt.sent_time: t = pkt.sent_time sec = int(t) else: t = pkt.time sec = int(t) usec = int(round((t-sec)*1000000)) return (sec,usec)
python
def get_packet_time(self, pkt): """Return the second and micro-second timestamp components for a packet.""" if pkt.sent_time: t = pkt.sent_time sec = int(t) else: t = pkt.time sec = int(t) usec = int(round((t-sec)*1000000)) return (sec,usec)
[ "def", "get_packet_time", "(", "self", ",", "pkt", ")", ":", "if", "pkt", ".", "sent_time", ":", "t", "=", "pkt", ".", "sent_time", "sec", "=", "int", "(", "t", ")", "else", ":", "t", "=", "pkt", ".", "time", "sec", "=", "int", "(", "t", ")", "usec", "=", "int", "(", "round", "(", "(", "t", "-", "sec", ")", "*", "1000000", ")", ")", "return", "(", "sec", ",", "usec", ")" ]
Return the second and micro-second timestamp components for a packet.
[ "Return", "the", "second", "and", "micro", "-", "second", "timestamp", "components", "for", "a", "packet", "." ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/utils.py#L949-L958
train
237,158
phaethon/kamene
kamene/layers/ipsec.py
zero_mutable_fields
def zero_mutable_fields(pkt, sending=False): """ When using AH, all "mutable" fields must be "zeroed" before calculating the ICV. See RFC 4302, Section 3.3.3.1. Handling Mutable Fields. @param pkt: an IP(v6) packet containing an AH layer. NOTE: The packet will be modified @param sending: if true, ipv6 routing headers will not be reordered """ if pkt.haslayer(AH): pkt[AH].icv = chr(0) * len(pkt[AH].icv) else: raise TypeError('no AH layer found') if pkt.version == 4: # the tos field has been replaced by DSCP and ECN # Routers may rewrite the DS field as needed to provide a # desired local or end-to-end service pkt.tos = 0 # an intermediate router might set the DF bit, even if the source # did not select it. pkt.flags = 0 # changed en route as a normal course of processing by routers pkt.ttl = 0 # will change if any of these other fields change pkt.chksum = 0 immutable_opts = [] for opt in pkt.options: if opt.option in IMMUTABLE_IPV4_OPTIONS: immutable_opts.append(opt) else: immutable_opts.append(Raw(chr(0) * len(opt))) pkt.options = immutable_opts else: # holds DSCP and ECN pkt.tc = 0 # The flow label described in AHv1 was mutable, and in RFC 2460 [DH98] # was potentially mutable. To retain compatibility with existing AH # implementations, the flow label is not included in the ICV in AHv2. pkt.fl = 0 # same as ttl pkt.hlim = 0 next_hdr = pkt.payload while isinstance(next_hdr, (IPv6ExtHdrHopByHop, IPv6ExtHdrRouting, IPv6ExtHdrDestOpt)): if isinstance(next_hdr, (IPv6ExtHdrHopByHop, IPv6ExtHdrDestOpt)): for opt in next_hdr.options: if opt.otype & 0x20: # option data can change en-route and must be zeroed opt.optdata = chr(0) * opt.optlen elif isinstance(next_hdr, IPv6ExtHdrRouting) and sending: # The sender must order the field so that it appears as it # will at the receiver, prior to performing the ICV computation. next_hdr.segleft = 0 if next_hdr.addresses: final = next_hdr.addresses.pop() next_hdr.addresses.insert(0, pkt.dst) pkt.dst = final else: break next_hdr = next_hdr.payload return pkt
python
def zero_mutable_fields(pkt, sending=False): """ When using AH, all "mutable" fields must be "zeroed" before calculating the ICV. See RFC 4302, Section 3.3.3.1. Handling Mutable Fields. @param pkt: an IP(v6) packet containing an AH layer. NOTE: The packet will be modified @param sending: if true, ipv6 routing headers will not be reordered """ if pkt.haslayer(AH): pkt[AH].icv = chr(0) * len(pkt[AH].icv) else: raise TypeError('no AH layer found') if pkt.version == 4: # the tos field has been replaced by DSCP and ECN # Routers may rewrite the DS field as needed to provide a # desired local or end-to-end service pkt.tos = 0 # an intermediate router might set the DF bit, even if the source # did not select it. pkt.flags = 0 # changed en route as a normal course of processing by routers pkt.ttl = 0 # will change if any of these other fields change pkt.chksum = 0 immutable_opts = [] for opt in pkt.options: if opt.option in IMMUTABLE_IPV4_OPTIONS: immutable_opts.append(opt) else: immutable_opts.append(Raw(chr(0) * len(opt))) pkt.options = immutable_opts else: # holds DSCP and ECN pkt.tc = 0 # The flow label described in AHv1 was mutable, and in RFC 2460 [DH98] # was potentially mutable. To retain compatibility with existing AH # implementations, the flow label is not included in the ICV in AHv2. pkt.fl = 0 # same as ttl pkt.hlim = 0 next_hdr = pkt.payload while isinstance(next_hdr, (IPv6ExtHdrHopByHop, IPv6ExtHdrRouting, IPv6ExtHdrDestOpt)): if isinstance(next_hdr, (IPv6ExtHdrHopByHop, IPv6ExtHdrDestOpt)): for opt in next_hdr.options: if opt.otype & 0x20: # option data can change en-route and must be zeroed opt.optdata = chr(0) * opt.optlen elif isinstance(next_hdr, IPv6ExtHdrRouting) and sending: # The sender must order the field so that it appears as it # will at the receiver, prior to performing the ICV computation. next_hdr.segleft = 0 if next_hdr.addresses: final = next_hdr.addresses.pop() next_hdr.addresses.insert(0, pkt.dst) pkt.dst = final else: break next_hdr = next_hdr.payload return pkt
[ "def", "zero_mutable_fields", "(", "pkt", ",", "sending", "=", "False", ")", ":", "if", "pkt", ".", "haslayer", "(", "AH", ")", ":", "pkt", "[", "AH", "]", ".", "icv", "=", "chr", "(", "0", ")", "*", "len", "(", "pkt", "[", "AH", "]", ".", "icv", ")", "else", ":", "raise", "TypeError", "(", "'no AH layer found'", ")", "if", "pkt", ".", "version", "==", "4", ":", "# the tos field has been replaced by DSCP and ECN", "# Routers may rewrite the DS field as needed to provide a", "# desired local or end-to-end service", "pkt", ".", "tos", "=", "0", "# an intermediate router might set the DF bit, even if the source", "# did not select it.", "pkt", ".", "flags", "=", "0", "# changed en route as a normal course of processing by routers", "pkt", ".", "ttl", "=", "0", "# will change if any of these other fields change", "pkt", ".", "chksum", "=", "0", "immutable_opts", "=", "[", "]", "for", "opt", "in", "pkt", ".", "options", ":", "if", "opt", ".", "option", "in", "IMMUTABLE_IPV4_OPTIONS", ":", "immutable_opts", ".", "append", "(", "opt", ")", "else", ":", "immutable_opts", ".", "append", "(", "Raw", "(", "chr", "(", "0", ")", "*", "len", "(", "opt", ")", ")", ")", "pkt", ".", "options", "=", "immutable_opts", "else", ":", "# holds DSCP and ECN", "pkt", ".", "tc", "=", "0", "# The flow label described in AHv1 was mutable, and in RFC 2460 [DH98]", "# was potentially mutable. To retain compatibility with existing AH", "# implementations, the flow label is not included in the ICV in AHv2.", "pkt", ".", "fl", "=", "0", "# same as ttl", "pkt", ".", "hlim", "=", "0", "next_hdr", "=", "pkt", ".", "payload", "while", "isinstance", "(", "next_hdr", ",", "(", "IPv6ExtHdrHopByHop", ",", "IPv6ExtHdrRouting", ",", "IPv6ExtHdrDestOpt", ")", ")", ":", "if", "isinstance", "(", "next_hdr", ",", "(", "IPv6ExtHdrHopByHop", ",", "IPv6ExtHdrDestOpt", ")", ")", ":", "for", "opt", "in", "next_hdr", ".", "options", ":", "if", "opt", ".", "otype", "&", "0x20", ":", "# option data can change en-route and must be zeroed", "opt", ".", "optdata", "=", "chr", "(", "0", ")", "*", "opt", ".", "optlen", "elif", "isinstance", "(", "next_hdr", ",", "IPv6ExtHdrRouting", ")", "and", "sending", ":", "# The sender must order the field so that it appears as it", "# will at the receiver, prior to performing the ICV computation.", "next_hdr", ".", "segleft", "=", "0", "if", "next_hdr", ".", "addresses", ":", "final", "=", "next_hdr", ".", "addresses", ".", "pop", "(", ")", "next_hdr", ".", "addresses", ".", "insert", "(", "0", ",", "pkt", ".", "dst", ")", "pkt", ".", "dst", "=", "final", "else", ":", "break", "next_hdr", "=", "next_hdr", ".", "payload", "return", "pkt" ]
When using AH, all "mutable" fields must be "zeroed" before calculating the ICV. See RFC 4302, Section 3.3.3.1. Handling Mutable Fields. @param pkt: an IP(v6) packet containing an AH layer. NOTE: The packet will be modified @param sending: if true, ipv6 routing headers will not be reordered
[ "When", "using", "AH", "all", "mutable", "fields", "must", "be", "zeroed", "before", "calculating", "the", "ICV", ".", "See", "RFC", "4302", "Section", "3", ".", "3", ".", "3", ".", "1", ".", "Handling", "Mutable", "Fields", "." ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/layers/ipsec.py#L655-L722
train
237,159
phaethon/kamene
kamene/layers/ipsec.py
CryptAlgo.decrypt
def decrypt(self, esp, key, icv_size=None): """ Decrypt an ESP packet @param esp: an encrypted ESP packet @param key: the secret key used for encryption @param icv_size: the length of the icv used for integrity check @return: a valid ESP packet encrypted with this algorithm @raise IPSecIntegrityError: if the integrity check fails with an AEAD algorithm """ if icv_size is None: icv_size = self.icv_size if self.is_aead else 0 iv = esp.data[:self.iv_size] data = esp.data[self.iv_size:len(esp.data) - icv_size] icv = esp.data[len(esp.data) - icv_size:] if self.cipher: cipher = self.new_cipher(key, iv, icv) decryptor = cipher.decryptor() if self.is_aead: # Tag value check is done during the finalize method decryptor.authenticate_additional_data( struct.pack('!LL', esp.spi, esp.seq) ) try: data = decryptor.update(data) + decryptor.finalize() except InvalidTag as err: raise IPSecIntegrityError(err) # extract padlen and nh padlen = (data[-2]) nh = data[-1] # then use padlen to determine data and padding data = data[:len(data) - padlen - 2] padding = data[len(data) - padlen - 2: len(data) - 2] return _ESPPlain(spi=esp.spi, seq=esp.seq, iv=iv, data=data, padding=padding, padlen=padlen, nh=nh, icv=icv)
python
def decrypt(self, esp, key, icv_size=None): """ Decrypt an ESP packet @param esp: an encrypted ESP packet @param key: the secret key used for encryption @param icv_size: the length of the icv used for integrity check @return: a valid ESP packet encrypted with this algorithm @raise IPSecIntegrityError: if the integrity check fails with an AEAD algorithm """ if icv_size is None: icv_size = self.icv_size if self.is_aead else 0 iv = esp.data[:self.iv_size] data = esp.data[self.iv_size:len(esp.data) - icv_size] icv = esp.data[len(esp.data) - icv_size:] if self.cipher: cipher = self.new_cipher(key, iv, icv) decryptor = cipher.decryptor() if self.is_aead: # Tag value check is done during the finalize method decryptor.authenticate_additional_data( struct.pack('!LL', esp.spi, esp.seq) ) try: data = decryptor.update(data) + decryptor.finalize() except InvalidTag as err: raise IPSecIntegrityError(err) # extract padlen and nh padlen = (data[-2]) nh = data[-1] # then use padlen to determine data and padding data = data[:len(data) - padlen - 2] padding = data[len(data) - padlen - 2: len(data) - 2] return _ESPPlain(spi=esp.spi, seq=esp.seq, iv=iv, data=data, padding=padding, padlen=padlen, nh=nh, icv=icv)
[ "def", "decrypt", "(", "self", ",", "esp", ",", "key", ",", "icv_size", "=", "None", ")", ":", "if", "icv_size", "is", "None", ":", "icv_size", "=", "self", ".", "icv_size", "if", "self", ".", "is_aead", "else", "0", "iv", "=", "esp", ".", "data", "[", ":", "self", ".", "iv_size", "]", "data", "=", "esp", ".", "data", "[", "self", ".", "iv_size", ":", "len", "(", "esp", ".", "data", ")", "-", "icv_size", "]", "icv", "=", "esp", ".", "data", "[", "len", "(", "esp", ".", "data", ")", "-", "icv_size", ":", "]", "if", "self", ".", "cipher", ":", "cipher", "=", "self", ".", "new_cipher", "(", "key", ",", "iv", ",", "icv", ")", "decryptor", "=", "cipher", ".", "decryptor", "(", ")", "if", "self", ".", "is_aead", ":", "# Tag value check is done during the finalize method", "decryptor", ".", "authenticate_additional_data", "(", "struct", ".", "pack", "(", "'!LL'", ",", "esp", ".", "spi", ",", "esp", ".", "seq", ")", ")", "try", ":", "data", "=", "decryptor", ".", "update", "(", "data", ")", "+", "decryptor", ".", "finalize", "(", ")", "except", "InvalidTag", "as", "err", ":", "raise", "IPSecIntegrityError", "(", "err", ")", "# extract padlen and nh", "padlen", "=", "(", "data", "[", "-", "2", "]", ")", "nh", "=", "data", "[", "-", "1", "]", "# then use padlen to determine data and padding", "data", "=", "data", "[", ":", "len", "(", "data", ")", "-", "padlen", "-", "2", "]", "padding", "=", "data", "[", "len", "(", "data", ")", "-", "padlen", "-", "2", ":", "len", "(", "data", ")", "-", "2", "]", "return", "_ESPPlain", "(", "spi", "=", "esp", ".", "spi", ",", "seq", "=", "esp", ".", "seq", ",", "iv", "=", "iv", ",", "data", "=", "data", ",", "padding", "=", "padding", ",", "padlen", "=", "padlen", ",", "nh", "=", "nh", ",", "icv", "=", "icv", ")" ]
Decrypt an ESP packet @param esp: an encrypted ESP packet @param key: the secret key used for encryption @param icv_size: the length of the icv used for integrity check @return: a valid ESP packet encrypted with this algorithm @raise IPSecIntegrityError: if the integrity check fails with an AEAD algorithm
[ "Decrypt", "an", "ESP", "packet" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/layers/ipsec.py#L338-L387
train
237,160
phaethon/kamene
kamene/contrib/igmp.py
IGMP.igmpize
def igmpize(self, ip=None, ether=None): """Called to explicitely fixup associated IP and Ethernet headers Parameters: self The instantiation of an IGMP class. ip The instantiation of the associated IP class. ether The instantiation of the associated Ethernet. Returns: True The tuple ether/ip/self passed all check and represents a proper IGMP packet. False One of more validation checks failed and no fields were adjusted. The function will examine the IGMP message to assure proper format. Corrections will be attempted if possible. The IP header is then properly adjusted to ensure correct formatting and assignment. The Ethernet header is then adjusted to the proper IGMP packet format. """ # The rules are: # 1. the Max Response time is meaningful only in Membership Queries and should be zero # otherwise (RFC 2236, section 2.2) if (self.type != 0x11): #rule 1 self.mrtime = 0 if (self.adjust_ip(ip) == True): if (self.adjust_ether(ip, ether) == True): return True return False
python
def igmpize(self, ip=None, ether=None): """Called to explicitely fixup associated IP and Ethernet headers Parameters: self The instantiation of an IGMP class. ip The instantiation of the associated IP class. ether The instantiation of the associated Ethernet. Returns: True The tuple ether/ip/self passed all check and represents a proper IGMP packet. False One of more validation checks failed and no fields were adjusted. The function will examine the IGMP message to assure proper format. Corrections will be attempted if possible. The IP header is then properly adjusted to ensure correct formatting and assignment. The Ethernet header is then adjusted to the proper IGMP packet format. """ # The rules are: # 1. the Max Response time is meaningful only in Membership Queries and should be zero # otherwise (RFC 2236, section 2.2) if (self.type != 0x11): #rule 1 self.mrtime = 0 if (self.adjust_ip(ip) == True): if (self.adjust_ether(ip, ether) == True): return True return False
[ "def", "igmpize", "(", "self", ",", "ip", "=", "None", ",", "ether", "=", "None", ")", ":", "# The rules are:", "# 1. the Max Response time is meaningful only in Membership Queries and should be zero ", "# otherwise (RFC 2236, section 2.2)", "if", "(", "self", ".", "type", "!=", "0x11", ")", ":", "#rule 1", "self", ".", "mrtime", "=", "0", "if", "(", "self", ".", "adjust_ip", "(", "ip", ")", "==", "True", ")", ":", "if", "(", "self", ".", "adjust_ether", "(", "ip", ",", "ether", ")", "==", "True", ")", ":", "return", "True", "return", "False" ]
Called to explicitely fixup associated IP and Ethernet headers Parameters: self The instantiation of an IGMP class. ip The instantiation of the associated IP class. ether The instantiation of the associated Ethernet. Returns: True The tuple ether/ip/self passed all check and represents a proper IGMP packet. False One of more validation checks failed and no fields were adjusted. The function will examine the IGMP message to assure proper format. Corrections will be attempted if possible. The IP header is then properly adjusted to ensure correct formatting and assignment. The Ethernet header is then adjusted to the proper IGMP packet format.
[ "Called", "to", "explicitely", "fixup", "associated", "IP", "and", "Ethernet", "headers" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/igmp.py#L78-L107
train
237,161
phaethon/kamene
kamene/contrib/gsm_um.py
additionalAssignment
def additionalAssignment(MobileAllocation_presence=0, StartingTime_presence=0): """ADDITIONAL ASSIGNMENT Section 9.1.1""" # Mandatory a = TpPd(pd=0x6) b = MessageType(mesType=0x3B) # 00111011 c = ChannelDescription() packet = a / b / c # Not Mandatory if MobileAllocation_presence is 1: d = MobileAllocationHdr(ieiMA=0x72, eightBitMA=0x0) packet = packet / d if StartingTime_presence is 1: e = StartingTimeHdr(ieiST=0x7C, eightBitST=0x0) packet = packet / e return packet
python
def additionalAssignment(MobileAllocation_presence=0, StartingTime_presence=0): """ADDITIONAL ASSIGNMENT Section 9.1.1""" # Mandatory a = TpPd(pd=0x6) b = MessageType(mesType=0x3B) # 00111011 c = ChannelDescription() packet = a / b / c # Not Mandatory if MobileAllocation_presence is 1: d = MobileAllocationHdr(ieiMA=0x72, eightBitMA=0x0) packet = packet / d if StartingTime_presence is 1: e = StartingTimeHdr(ieiST=0x7C, eightBitST=0x0) packet = packet / e return packet
[ "def", "additionalAssignment", "(", "MobileAllocation_presence", "=", "0", ",", "StartingTime_presence", "=", "0", ")", ":", "# Mandatory", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0x3B", ")", "# 00111011", "c", "=", "ChannelDescription", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "# Not Mandatory", "if", "MobileAllocation_presence", "is", "1", ":", "d", "=", "MobileAllocationHdr", "(", "ieiMA", "=", "0x72", ",", "eightBitMA", "=", "0x0", ")", "packet", "=", "packet", "/", "d", "if", "StartingTime_presence", "is", "1", ":", "e", "=", "StartingTimeHdr", "(", "ieiST", "=", "0x7C", ",", "eightBitST", "=", "0x0", ")", "packet", "=", "packet", "/", "e", "return", "packet" ]
ADDITIONAL ASSIGNMENT Section 9.1.1
[ "ADDITIONAL", "ASSIGNMENT", "Section", "9", ".", "1", ".", "1" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L180-L195
train
237,162
phaethon/kamene
kamene/contrib/gsm_um.py
assignmentComplete
def assignmentComplete(): """ASSIGNMENT COMPLETE Section 9.1.3""" a = TpPd(pd=0x6) b = MessageType(mesType=0x29) # 00101001 c = RrCause() packet = a / b / c return packet
python
def assignmentComplete(): """ASSIGNMENT COMPLETE Section 9.1.3""" a = TpPd(pd=0x6) b = MessageType(mesType=0x29) # 00101001 c = RrCause() packet = a / b / c return packet
[ "def", "assignmentComplete", "(", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0x29", ")", "# 00101001", "c", "=", "RrCause", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "return", "packet" ]
ASSIGNMENT COMPLETE Section 9.1.3
[ "ASSIGNMENT", "COMPLETE", "Section", "9", ".", "1", ".", "3" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L296-L302
train
237,163
phaethon/kamene
kamene/contrib/gsm_um.py
channelModeModify
def channelModeModify(VgcsTargetModeIdentication_presence=0, MultiRateConfiguration_presence=0): """CHANNEL MODE MODIFY Section 9.1.5""" a = TpPd(pd=0x6) b = MessageType(mesType=0x8) # 0001000 c = ChannelDescription2() d = ChannelMode() packet = a / b / c / d if VgcsTargetModeIdentication is 1: e = VgcsTargetModeIdenticationHdr(ieiVTMI=0x01, eightBitVTMI=0x0) packet = packet / e if MultiRateConfiguration is 1: f = MultiRateConfigurationHdr(ieiMRC=0x03, eightBitMRC=0x0) packet = packet / f return packet
python
def channelModeModify(VgcsTargetModeIdentication_presence=0, MultiRateConfiguration_presence=0): """CHANNEL MODE MODIFY Section 9.1.5""" a = TpPd(pd=0x6) b = MessageType(mesType=0x8) # 0001000 c = ChannelDescription2() d = ChannelMode() packet = a / b / c / d if VgcsTargetModeIdentication is 1: e = VgcsTargetModeIdenticationHdr(ieiVTMI=0x01, eightBitVTMI=0x0) packet = packet / e if MultiRateConfiguration is 1: f = MultiRateConfigurationHdr(ieiMRC=0x03, eightBitMRC=0x0) packet = packet / f return packet
[ "def", "channelModeModify", "(", "VgcsTargetModeIdentication_presence", "=", "0", ",", "MultiRateConfiguration_presence", "=", "0", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0x8", ")", "# 0001000", "c", "=", "ChannelDescription2", "(", ")", "d", "=", "ChannelMode", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "if", "VgcsTargetModeIdentication", "is", "1", ":", "e", "=", "VgcsTargetModeIdenticationHdr", "(", "ieiVTMI", "=", "0x01", ",", "eightBitVTMI", "=", "0x0", ")", "packet", "=", "packet", "/", "e", "if", "MultiRateConfiguration", "is", "1", ":", "f", "=", "MultiRateConfigurationHdr", "(", "ieiMRC", "=", "0x03", ",", "eightBitMRC", "=", "0x0", ")", "packet", "=", "packet", "/", "f", "return", "packet" ]
CHANNEL MODE MODIFY Section 9.1.5
[ "CHANNEL", "MODE", "MODIFY", "Section", "9", ".", "1", ".", "5" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L316-L330
train
237,164
phaethon/kamene
kamene/contrib/gsm_um.py
channelModeModifyAcknowledge
def channelModeModifyAcknowledge(): """CHANNEL MODE MODIFY ACKNOWLEDGE Section 9.1.6""" a = TpPd(pd=0x6) b = MessageType(mesType=0x17) # 00010111 c = ChannelDescription2() d = ChannelMode() packet = a / b / c / d return packet
python
def channelModeModifyAcknowledge(): """CHANNEL MODE MODIFY ACKNOWLEDGE Section 9.1.6""" a = TpPd(pd=0x6) b = MessageType(mesType=0x17) # 00010111 c = ChannelDescription2() d = ChannelMode() packet = a / b / c / d return packet
[ "def", "channelModeModifyAcknowledge", "(", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0x17", ")", "# 00010111", "c", "=", "ChannelDescription2", "(", ")", "d", "=", "ChannelMode", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "return", "packet" ]
CHANNEL MODE MODIFY ACKNOWLEDGE Section 9.1.6
[ "CHANNEL", "MODE", "MODIFY", "ACKNOWLEDGE", "Section", "9", ".", "1", ".", "6" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L333-L340
train
237,165
phaethon/kamene
kamene/contrib/gsm_um.py
channelRelease
def channelRelease(BaRange_presence=0, GroupChannelDescription_presence=0, GroupCipherKeyNumber_presence=0, GprsResumption_presence=0, BaListPref_presence=0): """CHANNEL RELEASE Section 9.1.7""" a = TpPd(pd=0x6) b = MessageType(mesType=0xD) # 00001101 c = RrCause() packet = a / b / c if BaRange_presence is 1: d = BaRangeHdr(ieiBR=0x73, eightBitBR=0x0) packet = packet / d if GroupChannelDescription_presence is 1: e = GroupChannelDescriptionHdr(ieiGCD=0x74, eightBitGCD=0x0) packet = packet / e if GroupCipherKeyNumber_presence is 1: f = GroupCipherKeyNumber(ieiGCKN=0x8) packet = packet / f if GprsResumption_presence is 1: g = GprsResumptionHdr(ieiGR=0xC, eightBitGR=0x0) packet = packet / g if BaListPref_presence is 1: h = BaListPrefHdr(ieiBLP=0x75, eightBitBLP=0x0) packet = packet / h return packet
python
def channelRelease(BaRange_presence=0, GroupChannelDescription_presence=0, GroupCipherKeyNumber_presence=0, GprsResumption_presence=0, BaListPref_presence=0): """CHANNEL RELEASE Section 9.1.7""" a = TpPd(pd=0x6) b = MessageType(mesType=0xD) # 00001101 c = RrCause() packet = a / b / c if BaRange_presence is 1: d = BaRangeHdr(ieiBR=0x73, eightBitBR=0x0) packet = packet / d if GroupChannelDescription_presence is 1: e = GroupChannelDescriptionHdr(ieiGCD=0x74, eightBitGCD=0x0) packet = packet / e if GroupCipherKeyNumber_presence is 1: f = GroupCipherKeyNumber(ieiGCKN=0x8) packet = packet / f if GprsResumption_presence is 1: g = GprsResumptionHdr(ieiGR=0xC, eightBitGR=0x0) packet = packet / g if BaListPref_presence is 1: h = BaListPrefHdr(ieiBLP=0x75, eightBitBLP=0x0) packet = packet / h return packet
[ "def", "channelRelease", "(", "BaRange_presence", "=", "0", ",", "GroupChannelDescription_presence", "=", "0", ",", "GroupCipherKeyNumber_presence", "=", "0", ",", "GprsResumption_presence", "=", "0", ",", "BaListPref_presence", "=", "0", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0xD", ")", "# 00001101", "c", "=", "RrCause", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "if", "BaRange_presence", "is", "1", ":", "d", "=", "BaRangeHdr", "(", "ieiBR", "=", "0x73", ",", "eightBitBR", "=", "0x0", ")", "packet", "=", "packet", "/", "d", "if", "GroupChannelDescription_presence", "is", "1", ":", "e", "=", "GroupChannelDescriptionHdr", "(", "ieiGCD", "=", "0x74", ",", "eightBitGCD", "=", "0x0", ")", "packet", "=", "packet", "/", "e", "if", "GroupCipherKeyNumber_presence", "is", "1", ":", "f", "=", "GroupCipherKeyNumber", "(", "ieiGCKN", "=", "0x8", ")", "packet", "=", "packet", "/", "f", "if", "GprsResumption_presence", "is", "1", ":", "g", "=", "GprsResumptionHdr", "(", "ieiGR", "=", "0xC", ",", "eightBitGR", "=", "0x0", ")", "packet", "=", "packet", "/", "g", "if", "BaListPref_presence", "is", "1", ":", "h", "=", "BaListPrefHdr", "(", "ieiBLP", "=", "0x75", ",", "eightBitBLP", "=", "0x0", ")", "packet", "=", "packet", "/", "h", "return", "packet" ]
CHANNEL RELEASE Section 9.1.7
[ "CHANNEL", "RELEASE", "Section", "9", ".", "1", ".", "7" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L344-L367
train
237,166
phaethon/kamene
kamene/contrib/gsm_um.py
cipheringModeCommand
def cipheringModeCommand(): """CIPHERING MODE COMMAND Section 9.1.9""" a = TpPd(pd=0x6) b = MessageType(mesType=0x35) # 00110101 c = RrCause() #d=cipherModeSetting() #e=cipherResponse() # FIX d = CipherModeSettingAndcipherResponse() packet = a / b / c / d return packet
python
def cipheringModeCommand(): """CIPHERING MODE COMMAND Section 9.1.9""" a = TpPd(pd=0x6) b = MessageType(mesType=0x35) # 00110101 c = RrCause() #d=cipherModeSetting() #e=cipherResponse() # FIX d = CipherModeSettingAndcipherResponse() packet = a / b / c / d return packet
[ "def", "cipheringModeCommand", "(", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0x35", ")", "# 00110101", "c", "=", "RrCause", "(", ")", "#d=cipherModeSetting()", "#e=cipherResponse()", "# FIX", "d", "=", "CipherModeSettingAndcipherResponse", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "return", "packet" ]
CIPHERING MODE COMMAND Section 9.1.9
[ "CIPHERING", "MODE", "COMMAND", "Section", "9", ".", "1", ".", "9" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L383-L393
train
237,167
phaethon/kamene
kamene/contrib/gsm_um.py
cipheringModeComplete
def cipheringModeComplete(MobileId_presence=0): """CIPHERING MODE COMPLETE Section 9.1.10""" a = TpPd(pd=0x6) b = MessageType(mesType=0x32) # 00110010 packet = a / b if MobileId_presence is 1: c = MobileIdHdr(ieiMI=0x17, eightBitMI=0x0) packet = packet / c return packet
python
def cipheringModeComplete(MobileId_presence=0): """CIPHERING MODE COMPLETE Section 9.1.10""" a = TpPd(pd=0x6) b = MessageType(mesType=0x32) # 00110010 packet = a / b if MobileId_presence is 1: c = MobileIdHdr(ieiMI=0x17, eightBitMI=0x0) packet = packet / c return packet
[ "def", "cipheringModeComplete", "(", "MobileId_presence", "=", "0", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0x32", ")", "# 00110010", "packet", "=", "a", "/", "b", "if", "MobileId_presence", "is", "1", ":", "c", "=", "MobileIdHdr", "(", "ieiMI", "=", "0x17", ",", "eightBitMI", "=", "0x0", ")", "packet", "=", "packet", "/", "c", "return", "packet" ]
CIPHERING MODE COMPLETE Section 9.1.10
[ "CIPHERING", "MODE", "COMPLETE", "Section", "9", ".", "1", ".", "10" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L396-L404
train
237,168
phaethon/kamene
kamene/contrib/gsm_um.py
classmarkChange
def classmarkChange(MobileStationClassmark3_presence=0): """CLASSMARK CHANGE Section 9.1.11""" a = TpPd(pd=0x6) b = MessageType(mesType=0x16) # 00010110 c = MobileStationClassmark2() packet = a / b / c if MobileStationClassmark3_presence is 1: e = MobileStationClassmark3(ieiMSC3=0x20) packet = packet / e return packet
python
def classmarkChange(MobileStationClassmark3_presence=0): """CLASSMARK CHANGE Section 9.1.11""" a = TpPd(pd=0x6) b = MessageType(mesType=0x16) # 00010110 c = MobileStationClassmark2() packet = a / b / c if MobileStationClassmark3_presence is 1: e = MobileStationClassmark3(ieiMSC3=0x20) packet = packet / e return packet
[ "def", "classmarkChange", "(", "MobileStationClassmark3_presence", "=", "0", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0x16", ")", "# 00010110", "c", "=", "MobileStationClassmark2", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "if", "MobileStationClassmark3_presence", "is", "1", ":", "e", "=", "MobileStationClassmark3", "(", "ieiMSC3", "=", "0x20", ")", "packet", "=", "packet", "/", "e", "return", "packet" ]
CLASSMARK CHANGE Section 9.1.11
[ "CLASSMARK", "CHANGE", "Section", "9", ".", "1", ".", "11" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L408-L417
train
237,169
phaethon/kamene
kamene/contrib/gsm_um.py
classmarkEnquiry
def classmarkEnquiry(): """CLASSMARK ENQUIRY Section 9.1.12""" a = TpPd(pd=0x6) b = MessageType(mesType=0x13) # 00010011 packet = a / b return packet
python
def classmarkEnquiry(): """CLASSMARK ENQUIRY Section 9.1.12""" a = TpPd(pd=0x6) b = MessageType(mesType=0x13) # 00010011 packet = a / b return packet
[ "def", "classmarkEnquiry", "(", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0x13", ")", "# 00010011", "packet", "=", "a", "/", "b", "return", "packet" ]
CLASSMARK ENQUIRY Section 9.1.12
[ "CLASSMARK", "ENQUIRY", "Section", "9", ".", "1", ".", "12" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L421-L426
train
237,170
phaethon/kamene
kamene/contrib/gsm_um.py
configurationChangeCommand
def configurationChangeCommand(ChannelMode_presence=0, ChannelMode_presence1=0, ChannelMode_presence2=0, ChannelMode_presence3=0, ChannelMode_presence4=0, ChannelMode_presence5=0, ChannelMode_presence6=0, ChannelMode_presence7=0): """CONFIGURATION CHANGE COMMAND Section 9.1.12b""" a = TpPd(pd=0x6) b = MessageType(mesType=0x30) # 00110000 c = MultislotAllocation() packet = a / b / c if ChannelMode_presence is 1: d = ChannelModeHdr(ieiCM=0x63, eightBitCM=0x0) packet = packet / d if ChannelMode_presence1 is 1: e = ChannelModeHdr(ieiCM=0x11, eightBitCM=0x0) packet = packet / e if ChannelMode_presence2 is 1: f = ChannelModeHdr(ieiCM=0x13, eightBitCM=0x0) packet = packet / f if ChannelMode_presence3 is 1: g = ChannelModeHdr(ieiCM=0x14, eightBitCM=0x0) packet = packet / g if ChannelMode_presence4 is 1: h = ChannelModeHdr(ieiCM=0x15, eightBitCM=0x0) packet = packet / h if ChannelMode_presence5 is 1: i = ChannelModeHdr(ieiCM=0x16, eightBitCM=0x0) packet = packet / i if ChannelMode_presence6 is 1: j = ChannelModeHdr(ieiCM=0x17, eightBitCM=0x0) packet = packet / j if ChannelMode_presence7 is 1: k = ChannelModeHdr(ieiCM=0x18, eightBitCM=0x0) packet = packet / k return packet
python
def configurationChangeCommand(ChannelMode_presence=0, ChannelMode_presence1=0, ChannelMode_presence2=0, ChannelMode_presence3=0, ChannelMode_presence4=0, ChannelMode_presence5=0, ChannelMode_presence6=0, ChannelMode_presence7=0): """CONFIGURATION CHANGE COMMAND Section 9.1.12b""" a = TpPd(pd=0x6) b = MessageType(mesType=0x30) # 00110000 c = MultislotAllocation() packet = a / b / c if ChannelMode_presence is 1: d = ChannelModeHdr(ieiCM=0x63, eightBitCM=0x0) packet = packet / d if ChannelMode_presence1 is 1: e = ChannelModeHdr(ieiCM=0x11, eightBitCM=0x0) packet = packet / e if ChannelMode_presence2 is 1: f = ChannelModeHdr(ieiCM=0x13, eightBitCM=0x0) packet = packet / f if ChannelMode_presence3 is 1: g = ChannelModeHdr(ieiCM=0x14, eightBitCM=0x0) packet = packet / g if ChannelMode_presence4 is 1: h = ChannelModeHdr(ieiCM=0x15, eightBitCM=0x0) packet = packet / h if ChannelMode_presence5 is 1: i = ChannelModeHdr(ieiCM=0x16, eightBitCM=0x0) packet = packet / i if ChannelMode_presence6 is 1: j = ChannelModeHdr(ieiCM=0x17, eightBitCM=0x0) packet = packet / j if ChannelMode_presence7 is 1: k = ChannelModeHdr(ieiCM=0x18, eightBitCM=0x0) packet = packet / k return packet
[ "def", "configurationChangeCommand", "(", "ChannelMode_presence", "=", "0", ",", "ChannelMode_presence1", "=", "0", ",", "ChannelMode_presence2", "=", "0", ",", "ChannelMode_presence3", "=", "0", ",", "ChannelMode_presence4", "=", "0", ",", "ChannelMode_presence5", "=", "0", ",", "ChannelMode_presence6", "=", "0", ",", "ChannelMode_presence7", "=", "0", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0x30", ")", "# 00110000", "c", "=", "MultislotAllocation", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "if", "ChannelMode_presence", "is", "1", ":", "d", "=", "ChannelModeHdr", "(", "ieiCM", "=", "0x63", ",", "eightBitCM", "=", "0x0", ")", "packet", "=", "packet", "/", "d", "if", "ChannelMode_presence1", "is", "1", ":", "e", "=", "ChannelModeHdr", "(", "ieiCM", "=", "0x11", ",", "eightBitCM", "=", "0x0", ")", "packet", "=", "packet", "/", "e", "if", "ChannelMode_presence2", "is", "1", ":", "f", "=", "ChannelModeHdr", "(", "ieiCM", "=", "0x13", ",", "eightBitCM", "=", "0x0", ")", "packet", "=", "packet", "/", "f", "if", "ChannelMode_presence3", "is", "1", ":", "g", "=", "ChannelModeHdr", "(", "ieiCM", "=", "0x14", ",", "eightBitCM", "=", "0x0", ")", "packet", "=", "packet", "/", "g", "if", "ChannelMode_presence4", "is", "1", ":", "h", "=", "ChannelModeHdr", "(", "ieiCM", "=", "0x15", ",", "eightBitCM", "=", "0x0", ")", "packet", "=", "packet", "/", "h", "if", "ChannelMode_presence5", "is", "1", ":", "i", "=", "ChannelModeHdr", "(", "ieiCM", "=", "0x16", ",", "eightBitCM", "=", "0x0", ")", "packet", "=", "packet", "/", "i", "if", "ChannelMode_presence6", "is", "1", ":", "j", "=", "ChannelModeHdr", "(", "ieiCM", "=", "0x17", ",", "eightBitCM", "=", "0x0", ")", "packet", "=", "packet", "/", "j", "if", "ChannelMode_presence7", "is", "1", ":", "k", "=", "ChannelModeHdr", "(", "ieiCM", "=", "0x18", ",", "eightBitCM", "=", "0x0", ")", "packet", "=", "packet", "/", "k", "return", "packet" ]
CONFIGURATION CHANGE COMMAND Section 9.1.12b
[ "CONFIGURATION", "CHANGE", "COMMAND", "Section", "9", ".", "1", ".", "12b" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L431-L468
train
237,171
phaethon/kamene
kamene/contrib/gsm_um.py
configurationChangeAcknowledge
def configurationChangeAcknowledge(): """CONFIGURATION CHANGE ACKNOWLEDGE Section 9.1.12c""" a = TpPd(pd=0x6) b = MessageType(mesType=0x31) # 00110001 c = MobileId() packet = a / b / c return packet
python
def configurationChangeAcknowledge(): """CONFIGURATION CHANGE ACKNOWLEDGE Section 9.1.12c""" a = TpPd(pd=0x6) b = MessageType(mesType=0x31) # 00110001 c = MobileId() packet = a / b / c return packet
[ "def", "configurationChangeAcknowledge", "(", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0x31", ")", "# 00110001", "c", "=", "MobileId", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "return", "packet" ]
CONFIGURATION CHANGE ACKNOWLEDGE Section 9.1.12c
[ "CONFIGURATION", "CHANGE", "ACKNOWLEDGE", "Section", "9", ".", "1", ".", "12c" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L471-L477
train
237,172
phaethon/kamene
kamene/contrib/gsm_um.py
frequencyRedefinition
def frequencyRedefinition(CellChannelDescription_presence=0): """Frequency redefinition Section 9.1.13""" a = TpPd(pd=0x6) b = MessageType(mesType=0x14) # 00010100 c = ChannelDescription() d = MobileAllocation() e = StartingTime() packet = a / b / c / d / e if CellChannelDescription_presence is 1: f = CellChannelDescriptionHdr(ieiCCD=0x62, eightBitCCD=0x0) packet = packet / f return packet
python
def frequencyRedefinition(CellChannelDescription_presence=0): """Frequency redefinition Section 9.1.13""" a = TpPd(pd=0x6) b = MessageType(mesType=0x14) # 00010100 c = ChannelDescription() d = MobileAllocation() e = StartingTime() packet = a / b / c / d / e if CellChannelDescription_presence is 1: f = CellChannelDescriptionHdr(ieiCCD=0x62, eightBitCCD=0x0) packet = packet / f return packet
[ "def", "frequencyRedefinition", "(", "CellChannelDescription_presence", "=", "0", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0x14", ")", "# 00010100", "c", "=", "ChannelDescription", "(", ")", "d", "=", "MobileAllocation", "(", ")", "e", "=", "StartingTime", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "/", "e", "if", "CellChannelDescription_presence", "is", "1", ":", "f", "=", "CellChannelDescriptionHdr", "(", "ieiCCD", "=", "0x62", ",", "eightBitCCD", "=", "0x0", ")", "packet", "=", "packet", "/", "f", "return", "packet" ]
Frequency redefinition Section 9.1.13
[ "Frequency", "redefinition", "Section", "9", ".", "1", ".", "13" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L490-L501
train
237,173
phaethon/kamene
kamene/contrib/gsm_um.py
pdchAssignmentCommand
def pdchAssignmentCommand(ChannelDescription_presence=0, CellChannelDescription_presence=0, MobileAllocation_presence=0, StartingTime_presence=0, FrequencyList_presence=0, ChannelDescription_presence1=0, FrequencyChannelSequence_presence=0, MobileAllocation_presence1=0, PacketChannelDescription_presence=0, DedicatedModeOrTBF_presence=0): """PDCH ASSIGNMENT COMMAND Section 9.1.13a""" a = TpPd(pd=0x6) b = MessageType(mesType=0x23) # 00100011 c = ChannelDescription() packet = a / b / c if ChannelDescription_presence is 1: d = ChannelDescriptionHdr(ieiCD=0x62, eightBitCD=0x0) packet = packet / d if CellChannelDescription_presence is 1: e = CellChannelDescriptionHdr(ieiCCD=0x05, eightBitCCD=0x0) packet = packet / e if MobileAllocation_presence is 1: f = MobileAllocationHdr(ieiMA=0x72, eightBitMA=0x0) packet = packet / f if StartingTime_presence is 1: g = StartingTimeHdr(ieiST=0x7C, eightBitST=0x0) packet = packet / g if FrequencyList_presence is 1: h = FrequencyListHdr(ieiFL=0x19, eightBitFL=0x0) packet = packet / h if ChannelDescription_presence1 is 1: i = ChannelDescriptionHdr(ieiCD=0x1C, eightBitCD=0x0) packet = packet / i if FrequencyChannelSequence_presence is 1: j = FrequencyChannelSequenceHdr(ieiFCS=0x1E, eightBitFCS=0x0) packet = packet / j if MobileAllocation_presence1 is 1: k = MobileAllocationHdr(ieiMA=0x21, eightBitMA=0x0) packet = packet / k if PacketChannelDescription_presence is 1: l = PacketChannelDescription(ieiPCD=0x22) packet = packet / l if DedicatedModeOrTBF_presence is 1: m = DedicatedModeOrTBFHdr(ieiDMOT=0x23, eightBitDMOT=0x0) packet = packet / m return packet
python
def pdchAssignmentCommand(ChannelDescription_presence=0, CellChannelDescription_presence=0, MobileAllocation_presence=0, StartingTime_presence=0, FrequencyList_presence=0, ChannelDescription_presence1=0, FrequencyChannelSequence_presence=0, MobileAllocation_presence1=0, PacketChannelDescription_presence=0, DedicatedModeOrTBF_presence=0): """PDCH ASSIGNMENT COMMAND Section 9.1.13a""" a = TpPd(pd=0x6) b = MessageType(mesType=0x23) # 00100011 c = ChannelDescription() packet = a / b / c if ChannelDescription_presence is 1: d = ChannelDescriptionHdr(ieiCD=0x62, eightBitCD=0x0) packet = packet / d if CellChannelDescription_presence is 1: e = CellChannelDescriptionHdr(ieiCCD=0x05, eightBitCCD=0x0) packet = packet / e if MobileAllocation_presence is 1: f = MobileAllocationHdr(ieiMA=0x72, eightBitMA=0x0) packet = packet / f if StartingTime_presence is 1: g = StartingTimeHdr(ieiST=0x7C, eightBitST=0x0) packet = packet / g if FrequencyList_presence is 1: h = FrequencyListHdr(ieiFL=0x19, eightBitFL=0x0) packet = packet / h if ChannelDescription_presence1 is 1: i = ChannelDescriptionHdr(ieiCD=0x1C, eightBitCD=0x0) packet = packet / i if FrequencyChannelSequence_presence is 1: j = FrequencyChannelSequenceHdr(ieiFCS=0x1E, eightBitFCS=0x0) packet = packet / j if MobileAllocation_presence1 is 1: k = MobileAllocationHdr(ieiMA=0x21, eightBitMA=0x0) packet = packet / k if PacketChannelDescription_presence is 1: l = PacketChannelDescription(ieiPCD=0x22) packet = packet / l if DedicatedModeOrTBF_presence is 1: m = DedicatedModeOrTBFHdr(ieiDMOT=0x23, eightBitDMOT=0x0) packet = packet / m return packet
[ "def", "pdchAssignmentCommand", "(", "ChannelDescription_presence", "=", "0", ",", "CellChannelDescription_presence", "=", "0", ",", "MobileAllocation_presence", "=", "0", ",", "StartingTime_presence", "=", "0", ",", "FrequencyList_presence", "=", "0", ",", "ChannelDescription_presence1", "=", "0", ",", "FrequencyChannelSequence_presence", "=", "0", ",", "MobileAllocation_presence1", "=", "0", ",", "PacketChannelDescription_presence", "=", "0", ",", "DedicatedModeOrTBF_presence", "=", "0", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0x23", ")", "# 00100011", "c", "=", "ChannelDescription", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "if", "ChannelDescription_presence", "is", "1", ":", "d", "=", "ChannelDescriptionHdr", "(", "ieiCD", "=", "0x62", ",", "eightBitCD", "=", "0x0", ")", "packet", "=", "packet", "/", "d", "if", "CellChannelDescription_presence", "is", "1", ":", "e", "=", "CellChannelDescriptionHdr", "(", "ieiCCD", "=", "0x05", ",", "eightBitCCD", "=", "0x0", ")", "packet", "=", "packet", "/", "e", "if", "MobileAllocation_presence", "is", "1", ":", "f", "=", "MobileAllocationHdr", "(", "ieiMA", "=", "0x72", ",", "eightBitMA", "=", "0x0", ")", "packet", "=", "packet", "/", "f", "if", "StartingTime_presence", "is", "1", ":", "g", "=", "StartingTimeHdr", "(", "ieiST", "=", "0x7C", ",", "eightBitST", "=", "0x0", ")", "packet", "=", "packet", "/", "g", "if", "FrequencyList_presence", "is", "1", ":", "h", "=", "FrequencyListHdr", "(", "ieiFL", "=", "0x19", ",", "eightBitFL", "=", "0x0", ")", "packet", "=", "packet", "/", "h", "if", "ChannelDescription_presence1", "is", "1", ":", "i", "=", "ChannelDescriptionHdr", "(", "ieiCD", "=", "0x1C", ",", "eightBitCD", "=", "0x0", ")", "packet", "=", "packet", "/", "i", "if", "FrequencyChannelSequence_presence", "is", "1", ":", "j", "=", "FrequencyChannelSequenceHdr", "(", "ieiFCS", "=", "0x1E", ",", "eightBitFCS", "=", "0x0", ")", "packet", "=", "packet", "/", "j", "if", "MobileAllocation_presence1", "is", "1", ":", "k", "=", "MobileAllocationHdr", "(", "ieiMA", "=", "0x21", ",", "eightBitMA", "=", "0x0", ")", "packet", "=", "packet", "/", "k", "if", "PacketChannelDescription_presence", "is", "1", ":", "l", "=", "PacketChannelDescription", "(", "ieiPCD", "=", "0x22", ")", "packet", "=", "packet", "/", "l", "if", "DedicatedModeOrTBF_presence", "is", "1", ":", "m", "=", "DedicatedModeOrTBFHdr", "(", "ieiDMOT", "=", "0x23", ",", "eightBitDMOT", "=", "0x0", ")", "packet", "=", "packet", "/", "m", "return", "packet" ]
PDCH ASSIGNMENT COMMAND Section 9.1.13a
[ "PDCH", "ASSIGNMENT", "COMMAND", "Section", "9", ".", "1", ".", "13a" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L505-L549
train
237,174
phaethon/kamene
kamene/contrib/gsm_um.py
gprsSuspensionRequest
def gprsSuspensionRequest(): """GPRS SUSPENSION REQUEST Section 9.1.13b""" a = TpPd(pd=0x6) b = MessageType() c = Tlli() d = RoutingAreaIdentification() e = SuspensionCause() packet = a / b / c / d / e return packet
python
def gprsSuspensionRequest(): """GPRS SUSPENSION REQUEST Section 9.1.13b""" a = TpPd(pd=0x6) b = MessageType() c = Tlli() d = RoutingAreaIdentification() e = SuspensionCause() packet = a / b / c / d / e return packet
[ "def", "gprsSuspensionRequest", "(", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", ")", "c", "=", "Tlli", "(", ")", "d", "=", "RoutingAreaIdentification", "(", ")", "e", "=", "SuspensionCause", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "/", "e", "return", "packet" ]
GPRS SUSPENSION REQUEST Section 9.1.13b
[ "GPRS", "SUSPENSION", "REQUEST", "Section", "9", ".", "1", ".", "13b" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L552-L560
train
237,175
phaethon/kamene
kamene/contrib/gsm_um.py
handoverComplete
def handoverComplete(MobileTimeDifference_presence=0): """HANDOVER COMPLETE Section 9.1.16""" a = TpPd(pd=0x6) b = MessageType(mesType=0x2c) # 00101100 c = RrCause() packet = a / b / c if MobileTimeDifference_presence is 1: d = MobileTimeDifferenceHdr(ieiMTD=0x77, eightBitMTD=0x0) packet = packet / d return packet
python
def handoverComplete(MobileTimeDifference_presence=0): """HANDOVER COMPLETE Section 9.1.16""" a = TpPd(pd=0x6) b = MessageType(mesType=0x2c) # 00101100 c = RrCause() packet = a / b / c if MobileTimeDifference_presence is 1: d = MobileTimeDifferenceHdr(ieiMTD=0x77, eightBitMTD=0x0) packet = packet / d return packet
[ "def", "handoverComplete", "(", "MobileTimeDifference_presence", "=", "0", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0x2c", ")", "# 00101100", "c", "=", "RrCause", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "if", "MobileTimeDifference_presence", "is", "1", ":", "d", "=", "MobileTimeDifferenceHdr", "(", "ieiMTD", "=", "0x77", ",", "eightBitMTD", "=", "0x0", ")", "packet", "=", "packet", "/", "d", "return", "packet" ]
HANDOVER COMPLETE Section 9.1.16
[ "HANDOVER", "COMPLETE", "Section", "9", ".", "1", ".", "16" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L693-L702
train
237,176
phaethon/kamene
kamene/contrib/gsm_um.py
immediateAssignment
def immediateAssignment(ChannelDescription_presence=0, PacketChannelDescription_presence=0, StartingTime_presence=0): """IMMEDIATE ASSIGNMENT Section 9.1.18""" a = L2PseudoLength() b = TpPd(pd=0x6) c = MessageType(mesType=0x3F) # 00111111 d = PageModeAndDedicatedModeOrTBF() packet = a / b / c / d if ChannelDescription_presence is 1: f = ChannelDescription() packet = packet / f if PacketChannelDescription_presence is 1: g = PacketChannelDescription() packet = packet / g h = RequestReference() i = TimingAdvance() j = MobileAllocation() packet = packet / h / i / j if StartingTime_presence is 1: k = StartingTimeHdr(ieiST=0x7C, eightBitST=0x0) packet = packet / k l = IaRestOctets() packet = packet / l return packet
python
def immediateAssignment(ChannelDescription_presence=0, PacketChannelDescription_presence=0, StartingTime_presence=0): """IMMEDIATE ASSIGNMENT Section 9.1.18""" a = L2PseudoLength() b = TpPd(pd=0x6) c = MessageType(mesType=0x3F) # 00111111 d = PageModeAndDedicatedModeOrTBF() packet = a / b / c / d if ChannelDescription_presence is 1: f = ChannelDescription() packet = packet / f if PacketChannelDescription_presence is 1: g = PacketChannelDescription() packet = packet / g h = RequestReference() i = TimingAdvance() j = MobileAllocation() packet = packet / h / i / j if StartingTime_presence is 1: k = StartingTimeHdr(ieiST=0x7C, eightBitST=0x0) packet = packet / k l = IaRestOctets() packet = packet / l return packet
[ "def", "immediateAssignment", "(", "ChannelDescription_presence", "=", "0", ",", "PacketChannelDescription_presence", "=", "0", ",", "StartingTime_presence", "=", "0", ")", ":", "a", "=", "L2PseudoLength", "(", ")", "b", "=", "TpPd", "(", "pd", "=", "0x6", ")", "c", "=", "MessageType", "(", "mesType", "=", "0x3F", ")", "# 00111111", "d", "=", "PageModeAndDedicatedModeOrTBF", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "if", "ChannelDescription_presence", "is", "1", ":", "f", "=", "ChannelDescription", "(", ")", "packet", "=", "packet", "/", "f", "if", "PacketChannelDescription_presence", "is", "1", ":", "g", "=", "PacketChannelDescription", "(", ")", "packet", "=", "packet", "/", "g", "h", "=", "RequestReference", "(", ")", "i", "=", "TimingAdvance", "(", ")", "j", "=", "MobileAllocation", "(", ")", "packet", "=", "packet", "/", "h", "/", "i", "/", "j", "if", "StartingTime_presence", "is", "1", ":", "k", "=", "StartingTimeHdr", "(", "ieiST", "=", "0x7C", ",", "eightBitST", "=", "0x0", ")", "packet", "=", "packet", "/", "k", "l", "=", "IaRestOctets", "(", ")", "packet", "=", "packet", "/", "l", "return", "packet" ]
IMMEDIATE ASSIGNMENT Section 9.1.18
[ "IMMEDIATE", "ASSIGNMENT", "Section", "9", ".", "1", ".", "18" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L718-L742
train
237,177
phaethon/kamene
kamene/contrib/gsm_um.py
immediateAssignmentExtended
def immediateAssignmentExtended(StartingTime_presence=0): """IMMEDIATE ASSIGNMENT EXTENDED Section 9.1.19""" a = L2PseudoLength() b = TpPd(pd=0x6) c = MessageType(mesType=0x39) # 00111001 d = PageModeAndSpareHalfOctets() f = ChannelDescription() g = RequestReference() h = TimingAdvance() i = MobileAllocation() packet = a / b / c / d / f / g / h / i if StartingTime_presence is 1: j = StartingTimeHdr(ieiST=0x7C, eightBitST=0x0) packet = packet / j k = IaxRestOctets() packet = packet / k return packet
python
def immediateAssignmentExtended(StartingTime_presence=0): """IMMEDIATE ASSIGNMENT EXTENDED Section 9.1.19""" a = L2PseudoLength() b = TpPd(pd=0x6) c = MessageType(mesType=0x39) # 00111001 d = PageModeAndSpareHalfOctets() f = ChannelDescription() g = RequestReference() h = TimingAdvance() i = MobileAllocation() packet = a / b / c / d / f / g / h / i if StartingTime_presence is 1: j = StartingTimeHdr(ieiST=0x7C, eightBitST=0x0) packet = packet / j k = IaxRestOctets() packet = packet / k return packet
[ "def", "immediateAssignmentExtended", "(", "StartingTime_presence", "=", "0", ")", ":", "a", "=", "L2PseudoLength", "(", ")", "b", "=", "TpPd", "(", "pd", "=", "0x6", ")", "c", "=", "MessageType", "(", "mesType", "=", "0x39", ")", "# 00111001", "d", "=", "PageModeAndSpareHalfOctets", "(", ")", "f", "=", "ChannelDescription", "(", ")", "g", "=", "RequestReference", "(", ")", "h", "=", "TimingAdvance", "(", ")", "i", "=", "MobileAllocation", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "/", "f", "/", "g", "/", "h", "/", "i", "if", "StartingTime_presence", "is", "1", ":", "j", "=", "StartingTimeHdr", "(", "ieiST", "=", "0x7C", ",", "eightBitST", "=", "0x0", ")", "packet", "=", "packet", "/", "j", "k", "=", "IaxRestOctets", "(", ")", "packet", "=", "packet", "/", "k", "return", "packet" ]
IMMEDIATE ASSIGNMENT EXTENDED Section 9.1.19
[ "IMMEDIATE", "ASSIGNMENT", "EXTENDED", "Section", "9", ".", "1", ".", "19" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L750-L766
train
237,178
phaethon/kamene
kamene/contrib/gsm_um.py
immediateAssignmentReject
def immediateAssignmentReject(): """IMMEDIATE ASSIGNMENT REJECT Section 9.1.20""" a = L2PseudoLength(l2pLength=0x13) b = TpPd(pd=0x6) c = MessageType(mesType=0x3a) # 00111010 d = PageModeAndSpareHalfOctets() f = RequestReference() g = WaitIndication() h = RequestReference() i = WaitIndication() j = RequestReference() k = WaitIndication() l = RequestReference() m = WaitIndication() n = IraRestOctets() packet = a / b / c / d / f / g / h / i / j / k / l / m / n return packet
python
def immediateAssignmentReject(): """IMMEDIATE ASSIGNMENT REJECT Section 9.1.20""" a = L2PseudoLength(l2pLength=0x13) b = TpPd(pd=0x6) c = MessageType(mesType=0x3a) # 00111010 d = PageModeAndSpareHalfOctets() f = RequestReference() g = WaitIndication() h = RequestReference() i = WaitIndication() j = RequestReference() k = WaitIndication() l = RequestReference() m = WaitIndication() n = IraRestOctets() packet = a / b / c / d / f / g / h / i / j / k / l / m / n return packet
[ "def", "immediateAssignmentReject", "(", ")", ":", "a", "=", "L2PseudoLength", "(", "l2pLength", "=", "0x13", ")", "b", "=", "TpPd", "(", "pd", "=", "0x6", ")", "c", "=", "MessageType", "(", "mesType", "=", "0x3a", ")", "# 00111010", "d", "=", "PageModeAndSpareHalfOctets", "(", ")", "f", "=", "RequestReference", "(", ")", "g", "=", "WaitIndication", "(", ")", "h", "=", "RequestReference", "(", ")", "i", "=", "WaitIndication", "(", ")", "j", "=", "RequestReference", "(", ")", "k", "=", "WaitIndication", "(", ")", "l", "=", "RequestReference", "(", ")", "m", "=", "WaitIndication", "(", ")", "n", "=", "IraRestOctets", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "/", "f", "/", "g", "/", "h", "/", "i", "/", "j", "/", "k", "/", "l", "/", "m", "/", "n", "return", "packet" ]
IMMEDIATE ASSIGNMENT REJECT Section 9.1.20
[ "IMMEDIATE", "ASSIGNMENT", "REJECT", "Section", "9", ".", "1", ".", "20" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L771-L787
train
237,179
phaethon/kamene
kamene/contrib/gsm_um.py
measurementReport
def measurementReport(): """MEASUREMENT REPORT Section 9.1.21""" a = TpPd(pd=0x6) b = MessageType(mesType=0x15) # 00010101 c = MeasurementResults() packet = a / b / c return packet
python
def measurementReport(): """MEASUREMENT REPORT Section 9.1.21""" a = TpPd(pd=0x6) b = MessageType(mesType=0x15) # 00010101 c = MeasurementResults() packet = a / b / c return packet
[ "def", "measurementReport", "(", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0x15", ")", "# 00010101", "c", "=", "MeasurementResults", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "return", "packet" ]
MEASUREMENT REPORT Section 9.1.21
[ "MEASUREMENT", "REPORT", "Section", "9", ".", "1", ".", "21" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L790-L796
train
237,180
phaethon/kamene
kamene/contrib/gsm_um.py
notificationResponse
def notificationResponse(): """NOTIFICATION RESPONSE Section 9.1.21d""" a = TpPd(pd=0x6) b = MessageType(mesType=0x26) # 00100110 c = MobileStationClassmark2() d = MobileId() e = DescriptiveGroupOrBroadcastCallReference() packet = a / b / c / d / e return packet
python
def notificationResponse(): """NOTIFICATION RESPONSE Section 9.1.21d""" a = TpPd(pd=0x6) b = MessageType(mesType=0x26) # 00100110 c = MobileStationClassmark2() d = MobileId() e = DescriptiveGroupOrBroadcastCallReference() packet = a / b / c / d / e return packet
[ "def", "notificationResponse", "(", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0x26", ")", "# 00100110", "c", "=", "MobileStationClassmark2", "(", ")", "d", "=", "MobileId", "(", ")", "e", "=", "DescriptiveGroupOrBroadcastCallReference", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "/", "e", "return", "packet" ]
NOTIFICATION RESPONSE Section 9.1.21d
[ "NOTIFICATION", "RESPONSE", "Section", "9", ".", "1", ".", "21d" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L823-L831
train
237,181
phaethon/kamene
kamene/contrib/gsm_um.py
rrCellChangeOrder
def rrCellChangeOrder(): """RR-CELL CHANGE ORDER Section 9.1.21e""" a = TpPd(pd=0x6) b = MessageType(mesType=0x8) # 00001000 c = CellDescription() d = NcModeAndSpareHalfOctets() packet = a / b / c / d return packet
python
def rrCellChangeOrder(): """RR-CELL CHANGE ORDER Section 9.1.21e""" a = TpPd(pd=0x6) b = MessageType(mesType=0x8) # 00001000 c = CellDescription() d = NcModeAndSpareHalfOctets() packet = a / b / c / d return packet
[ "def", "rrCellChangeOrder", "(", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0x8", ")", "# 00001000", "c", "=", "CellDescription", "(", ")", "d", "=", "NcModeAndSpareHalfOctets", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "return", "packet" ]
RR-CELL CHANGE ORDER Section 9.1.21e
[ "RR", "-", "CELL", "CHANGE", "ORDER", "Section", "9", ".", "1", ".", "21e" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L835-L842
train
237,182
phaethon/kamene
kamene/contrib/gsm_um.py
pagingRequestType1
def pagingRequestType1(MobileId_presence=0): """PAGING REQUEST TYPE 1 Section 9.1.22""" #The L2 pseudo length of this message is the sum of lengths of all #information elements present in the message except #the P1 Rest Octets and L2 Pseudo Length information elements. a = L2PseudoLength() b = TpPd(pd=0x6) c = MessageType(mesType=0x21) # 00100001 d = PageModeAndChannelNeeded() f = MobileId() packet = a / b / c / d / f if MobileId_presence is 1: g = MobileIdHdr(ieiMI=0x17, eightBitMI=0x0) packet = packet / g h = P1RestOctets() packet = packet / h return packet
python
def pagingRequestType1(MobileId_presence=0): """PAGING REQUEST TYPE 1 Section 9.1.22""" #The L2 pseudo length of this message is the sum of lengths of all #information elements present in the message except #the P1 Rest Octets and L2 Pseudo Length information elements. a = L2PseudoLength() b = TpPd(pd=0x6) c = MessageType(mesType=0x21) # 00100001 d = PageModeAndChannelNeeded() f = MobileId() packet = a / b / c / d / f if MobileId_presence is 1: g = MobileIdHdr(ieiMI=0x17, eightBitMI=0x0) packet = packet / g h = P1RestOctets() packet = packet / h return packet
[ "def", "pagingRequestType1", "(", "MobileId_presence", "=", "0", ")", ":", "#The L2 pseudo length of this message is the sum of lengths of all", "#information elements present in the message except", "#the P1 Rest Octets and L2 Pseudo Length information elements.", "a", "=", "L2PseudoLength", "(", ")", "b", "=", "TpPd", "(", "pd", "=", "0x6", ")", "c", "=", "MessageType", "(", "mesType", "=", "0x21", ")", "# 00100001", "d", "=", "PageModeAndChannelNeeded", "(", ")", "f", "=", "MobileId", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "/", "f", "if", "MobileId_presence", "is", "1", ":", "g", "=", "MobileIdHdr", "(", "ieiMI", "=", "0x17", ",", "eightBitMI", "=", "0x0", ")", "packet", "=", "packet", "/", "g", "h", "=", "P1RestOctets", "(", ")", "packet", "=", "packet", "/", "h", "return", "packet" ]
PAGING REQUEST TYPE 1 Section 9.1.22
[ "PAGING", "REQUEST", "TYPE", "1", "Section", "9", ".", "1", ".", "22" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L846-L862
train
237,183
phaethon/kamene
kamene/contrib/gsm_um.py
pagingRequestType2
def pagingRequestType2(MobileId_presence=0): """PAGING REQUEST TYPE 2 Section 9.1.23""" a = L2PseudoLength() b = TpPd(pd=0x6) c = MessageType(mesType=0x22) # 00100010 d = PageModeAndChannelNeeded() f = MobileId() g = MobileId() packet = a / b / c / d / f / g if MobileId_presence is 1: h = MobileIdHdr(ieiMI=0x17, eightBitMI=0x0) packet = packet / h i = P2RestOctets() packet = packet / i return packet
python
def pagingRequestType2(MobileId_presence=0): """PAGING REQUEST TYPE 2 Section 9.1.23""" a = L2PseudoLength() b = TpPd(pd=0x6) c = MessageType(mesType=0x22) # 00100010 d = PageModeAndChannelNeeded() f = MobileId() g = MobileId() packet = a / b / c / d / f / g if MobileId_presence is 1: h = MobileIdHdr(ieiMI=0x17, eightBitMI=0x0) packet = packet / h i = P2RestOctets() packet = packet / i return packet
[ "def", "pagingRequestType2", "(", "MobileId_presence", "=", "0", ")", ":", "a", "=", "L2PseudoLength", "(", ")", "b", "=", "TpPd", "(", "pd", "=", "0x6", ")", "c", "=", "MessageType", "(", "mesType", "=", "0x22", ")", "# 00100010", "d", "=", "PageModeAndChannelNeeded", "(", ")", "f", "=", "MobileId", "(", ")", "g", "=", "MobileId", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "/", "f", "/", "g", "if", "MobileId_presence", "is", "1", ":", "h", "=", "MobileIdHdr", "(", "ieiMI", "=", "0x17", ",", "eightBitMI", "=", "0x0", ")", "packet", "=", "packet", "/", "h", "i", "=", "P2RestOctets", "(", ")", "packet", "=", "packet", "/", "i", "return", "packet" ]
PAGING REQUEST TYPE 2 Section 9.1.23
[ "PAGING", "REQUEST", "TYPE", "2", "Section", "9", ".", "1", ".", "23" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L868-L882
train
237,184
phaethon/kamene
kamene/contrib/gsm_um.py
pagingRequestType3
def pagingRequestType3(): """PAGING REQUEST TYPE 3 Section 9.1.24""" # This message has a L2 Pseudo Length of 19 a = L2PseudoLength(l2pLength=0x13) b = TpPd(pd=0x6) c = MessageType(mesType=0x24) # 00100100 d = PageModeAndChannelNeeded() e = TmsiPTmsi() f = TmsiPTmsi() g = TmsiPTmsi() h = TmsiPTmsi() i = P3RestOctets() packet = a / b / c / d / e / f / g / h / i return packet
python
def pagingRequestType3(): """PAGING REQUEST TYPE 3 Section 9.1.24""" # This message has a L2 Pseudo Length of 19 a = L2PseudoLength(l2pLength=0x13) b = TpPd(pd=0x6) c = MessageType(mesType=0x24) # 00100100 d = PageModeAndChannelNeeded() e = TmsiPTmsi() f = TmsiPTmsi() g = TmsiPTmsi() h = TmsiPTmsi() i = P3RestOctets() packet = a / b / c / d / e / f / g / h / i return packet
[ "def", "pagingRequestType3", "(", ")", ":", "# This message has a L2 Pseudo Length of 19", "a", "=", "L2PseudoLength", "(", "l2pLength", "=", "0x13", ")", "b", "=", "TpPd", "(", "pd", "=", "0x6", ")", "c", "=", "MessageType", "(", "mesType", "=", "0x24", ")", "# 00100100", "d", "=", "PageModeAndChannelNeeded", "(", ")", "e", "=", "TmsiPTmsi", "(", ")", "f", "=", "TmsiPTmsi", "(", ")", "g", "=", "TmsiPTmsi", "(", ")", "h", "=", "TmsiPTmsi", "(", ")", "i", "=", "P3RestOctets", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "/", "e", "/", "f", "/", "g", "/", "h", "/", "i", "return", "packet" ]
PAGING REQUEST TYPE 3 Section 9.1.24
[ "PAGING", "REQUEST", "TYPE", "3", "Section", "9", ".", "1", ".", "24" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L886-L899
train
237,185
phaethon/kamene
kamene/contrib/gsm_um.py
pagingResponse
def pagingResponse(): """PAGING RESPONSE Section 9.1.25""" a = TpPd(pd=0x6) b = MessageType(mesType=0x27) # 00100111 c = CiphKeySeqNrAndSpareHalfOctets() d = MobileStationClassmark2() e = MobileId() packet = a / b / c / d / e return packet
python
def pagingResponse(): """PAGING RESPONSE Section 9.1.25""" a = TpPd(pd=0x6) b = MessageType(mesType=0x27) # 00100111 c = CiphKeySeqNrAndSpareHalfOctets() d = MobileStationClassmark2() e = MobileId() packet = a / b / c / d / e return packet
[ "def", "pagingResponse", "(", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0x27", ")", "# 00100111", "c", "=", "CiphKeySeqNrAndSpareHalfOctets", "(", ")", "d", "=", "MobileStationClassmark2", "(", ")", "e", "=", "MobileId", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "/", "e", "return", "packet" ]
PAGING RESPONSE Section 9.1.25
[ "PAGING", "RESPONSE", "Section", "9", ".", "1", ".", "25" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L902-L910
train
237,186
phaethon/kamene
kamene/contrib/gsm_um.py
partialRelease
def partialRelease(): """PARTIAL RELEASE Section 9.1.26""" a = TpPd(pd=0x6) b = MessageType(mesType=0xa) # 00001010 c = ChannelDescription() packet = a / b / c return packet
python
def partialRelease(): """PARTIAL RELEASE Section 9.1.26""" a = TpPd(pd=0x6) b = MessageType(mesType=0xa) # 00001010 c = ChannelDescription() packet = a / b / c return packet
[ "def", "partialRelease", "(", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0xa", ")", "# 00001010", "c", "=", "ChannelDescription", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "return", "packet" ]
PARTIAL RELEASE Section 9.1.26
[ "PARTIAL", "RELEASE", "Section", "9", ".", "1", ".", "26" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L914-L920
train
237,187
phaethon/kamene
kamene/contrib/gsm_um.py
partialReleaseComplete
def partialReleaseComplete(): """PARTIAL RELEASE COMPLETE Section 9.1.27""" a = TpPd(pd=0x6) b = MessageType(mesType=0xf) # 00001111 packet = a / b return packet
python
def partialReleaseComplete(): """PARTIAL RELEASE COMPLETE Section 9.1.27""" a = TpPd(pd=0x6) b = MessageType(mesType=0xf) # 00001111 packet = a / b return packet
[ "def", "partialReleaseComplete", "(", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0xf", ")", "# 00001111", "packet", "=", "a", "/", "b", "return", "packet" ]
PARTIAL RELEASE COMPLETE Section 9.1.27
[ "PARTIAL", "RELEASE", "COMPLETE", "Section", "9", ".", "1", ".", "27" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L923-L928
train
237,188
phaethon/kamene
kamene/contrib/gsm_um.py
physicalInformation
def physicalInformation(): """PHYSICAL INFORMATION Section 9.1.28""" a = TpPd(pd=0x6) b = MessageType(mesType=0x2d) # 00101101 c = TimingAdvance() packet = a / b / c return packet
python
def physicalInformation(): """PHYSICAL INFORMATION Section 9.1.28""" a = TpPd(pd=0x6) b = MessageType(mesType=0x2d) # 00101101 c = TimingAdvance() packet = a / b / c return packet
[ "def", "physicalInformation", "(", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0x2d", ")", "# 00101101", "c", "=", "TimingAdvance", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "return", "packet" ]
PHYSICAL INFORMATION Section 9.1.28
[ "PHYSICAL", "INFORMATION", "Section", "9", ".", "1", ".", "28" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L932-L938
train
237,189
phaethon/kamene
kamene/contrib/gsm_um.py
rrInitialisationRequest
def rrInitialisationRequest(): """RR Initialisation Request Section 9.1.28.a""" a = TpPd(pd=0x6) b = MessageType(mesType=0x3c) # 00111100 c = CiphKeySeqNrAndMacModeAndChannelCodingRequest() e = MobileStationClassmark2() f = Tlli() g = ChannelRequestDescription() h = GprsMeasurementResults() packet = a / b / c / e / f / g / h return packet
python
def rrInitialisationRequest(): """RR Initialisation Request Section 9.1.28.a""" a = TpPd(pd=0x6) b = MessageType(mesType=0x3c) # 00111100 c = CiphKeySeqNrAndMacModeAndChannelCodingRequest() e = MobileStationClassmark2() f = Tlli() g = ChannelRequestDescription() h = GprsMeasurementResults() packet = a / b / c / e / f / g / h return packet
[ "def", "rrInitialisationRequest", "(", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "0x6", ")", "b", "=", "MessageType", "(", "mesType", "=", "0x3c", ")", "# 00111100", "c", "=", "CiphKeySeqNrAndMacModeAndChannelCodingRequest", "(", ")", "e", "=", "MobileStationClassmark2", "(", ")", "f", "=", "Tlli", "(", ")", "g", "=", "ChannelRequestDescription", "(", ")", "h", "=", "GprsMeasurementResults", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "e", "/", "f", "/", "g", "/", "h", "return", "packet" ]
RR Initialisation Request Section 9.1.28.a
[ "RR", "Initialisation", "Request", "Section", "9", ".", "1", ".", "28", ".", "a" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L941-L951
train
237,190
phaethon/kamene
kamene/contrib/gsm_um.py
systemInformationType1
def systemInformationType1(): """SYSTEM INFORMATION TYPE 1 Section 9.1.31""" a = L2PseudoLength(l2pLength=0x15) b = TpPd(pd=0x6) c = MessageType(mesType=0x19) # 00011001 d = CellChannelDescription() e = RachControlParameters() f = Si1RestOctets() packet = a / b / c / d / e / f return packet
python
def systemInformationType1(): """SYSTEM INFORMATION TYPE 1 Section 9.1.31""" a = L2PseudoLength(l2pLength=0x15) b = TpPd(pd=0x6) c = MessageType(mesType=0x19) # 00011001 d = CellChannelDescription() e = RachControlParameters() f = Si1RestOctets() packet = a / b / c / d / e / f return packet
[ "def", "systemInformationType1", "(", ")", ":", "a", "=", "L2PseudoLength", "(", "l2pLength", "=", "0x15", ")", "b", "=", "TpPd", "(", "pd", "=", "0x6", ")", "c", "=", "MessageType", "(", "mesType", "=", "0x19", ")", "# 00011001", "d", "=", "CellChannelDescription", "(", ")", "e", "=", "RachControlParameters", "(", ")", "f", "=", "Si1RestOctets", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "/", "e", "/", "f", "return", "packet" ]
SYSTEM INFORMATION TYPE 1 Section 9.1.31
[ "SYSTEM", "INFORMATION", "TYPE", "1", "Section", "9", ".", "1", ".", "31" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L983-L992
train
237,191
phaethon/kamene
kamene/contrib/gsm_um.py
systemInformationType2
def systemInformationType2(): """SYSTEM INFORMATION TYPE 2 Section 9.1.32""" a = L2PseudoLength(l2pLength=0x16) b = TpPd(pd=0x6) c = MessageType(mesType=0x1a) # 00011010 d = NeighbourCellsDescription() e = NccPermitted() f = RachControlParameters() packet = a / b / c / d / e / f return packet
python
def systemInformationType2(): """SYSTEM INFORMATION TYPE 2 Section 9.1.32""" a = L2PseudoLength(l2pLength=0x16) b = TpPd(pd=0x6) c = MessageType(mesType=0x1a) # 00011010 d = NeighbourCellsDescription() e = NccPermitted() f = RachControlParameters() packet = a / b / c / d / e / f return packet
[ "def", "systemInformationType2", "(", ")", ":", "a", "=", "L2PseudoLength", "(", "l2pLength", "=", "0x16", ")", "b", "=", "TpPd", "(", "pd", "=", "0x6", ")", "c", "=", "MessageType", "(", "mesType", "=", "0x1a", ")", "# 00011010", "d", "=", "NeighbourCellsDescription", "(", ")", "e", "=", "NccPermitted", "(", ")", "f", "=", "RachControlParameters", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "/", "e", "/", "f", "return", "packet" ]
SYSTEM INFORMATION TYPE 2 Section 9.1.32
[ "SYSTEM", "INFORMATION", "TYPE", "2", "Section", "9", ".", "1", ".", "32" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L997-L1006
train
237,192
phaethon/kamene
kamene/contrib/gsm_um.py
systemInformationType2bis
def systemInformationType2bis(): """SYSTEM INFORMATION TYPE 2bis Section 9.1.33""" a = L2PseudoLength(l2pLength=0x15) b = TpPd(pd=0x6) c = MessageType(mesType=0x2) # 00000010 d = NeighbourCellsDescription() e = RachControlParameters() f = Si2bisRestOctets() packet = a / b / c / d / e / f return packet
python
def systemInformationType2bis(): """SYSTEM INFORMATION TYPE 2bis Section 9.1.33""" a = L2PseudoLength(l2pLength=0x15) b = TpPd(pd=0x6) c = MessageType(mesType=0x2) # 00000010 d = NeighbourCellsDescription() e = RachControlParameters() f = Si2bisRestOctets() packet = a / b / c / d / e / f return packet
[ "def", "systemInformationType2bis", "(", ")", ":", "a", "=", "L2PseudoLength", "(", "l2pLength", "=", "0x15", ")", "b", "=", "TpPd", "(", "pd", "=", "0x6", ")", "c", "=", "MessageType", "(", "mesType", "=", "0x2", ")", "# 00000010", "d", "=", "NeighbourCellsDescription", "(", ")", "e", "=", "RachControlParameters", "(", ")", "f", "=", "Si2bisRestOctets", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "/", "e", "/", "f", "return", "packet" ]
SYSTEM INFORMATION TYPE 2bis Section 9.1.33
[ "SYSTEM", "INFORMATION", "TYPE", "2bis", "Section", "9", ".", "1", ".", "33" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L1011-L1020
train
237,193
phaethon/kamene
kamene/contrib/gsm_um.py
systemInformationType2ter
def systemInformationType2ter(): """SYSTEM INFORMATION TYPE 2ter Section 9.1.34""" a = L2PseudoLength(l2pLength=0x12) b = TpPd(pd=0x6) c = MessageType(mesType=0x3) # 00000011 d = NeighbourCellsDescription2() e = Si2terRestOctets() packet = a / b / c / d / e return packet
python
def systemInformationType2ter(): """SYSTEM INFORMATION TYPE 2ter Section 9.1.34""" a = L2PseudoLength(l2pLength=0x12) b = TpPd(pd=0x6) c = MessageType(mesType=0x3) # 00000011 d = NeighbourCellsDescription2() e = Si2terRestOctets() packet = a / b / c / d / e return packet
[ "def", "systemInformationType2ter", "(", ")", ":", "a", "=", "L2PseudoLength", "(", "l2pLength", "=", "0x12", ")", "b", "=", "TpPd", "(", "pd", "=", "0x6", ")", "c", "=", "MessageType", "(", "mesType", "=", "0x3", ")", "# 00000011", "d", "=", "NeighbourCellsDescription2", "(", ")", "e", "=", "Si2terRestOctets", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "/", "e", "return", "packet" ]
SYSTEM INFORMATION TYPE 2ter Section 9.1.34
[ "SYSTEM", "INFORMATION", "TYPE", "2ter", "Section", "9", ".", "1", ".", "34" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L1025-L1033
train
237,194
phaethon/kamene
kamene/contrib/gsm_um.py
systemInformationType3
def systemInformationType3(): """SYSTEM INFORMATION TYPE 3 Section 9.1.35""" a = L2PseudoLength(l2pLength=0x12) b = TpPd(pd=0x6) c = MessageType(mesType=0x1b) # 00011011 d = CellIdentity() e = LocalAreaId() f = ControlChannelDescription() g = CellOptionsBCCH() h = CellSelectionParameters() i = RachControlParameters() j = Si3RestOctets() packet = a / b / c / d / e / f / g / h / i / j return packet
python
def systemInformationType3(): """SYSTEM INFORMATION TYPE 3 Section 9.1.35""" a = L2PseudoLength(l2pLength=0x12) b = TpPd(pd=0x6) c = MessageType(mesType=0x1b) # 00011011 d = CellIdentity() e = LocalAreaId() f = ControlChannelDescription() g = CellOptionsBCCH() h = CellSelectionParameters() i = RachControlParameters() j = Si3RestOctets() packet = a / b / c / d / e / f / g / h / i / j return packet
[ "def", "systemInformationType3", "(", ")", ":", "a", "=", "L2PseudoLength", "(", "l2pLength", "=", "0x12", ")", "b", "=", "TpPd", "(", "pd", "=", "0x6", ")", "c", "=", "MessageType", "(", "mesType", "=", "0x1b", ")", "# 00011011", "d", "=", "CellIdentity", "(", ")", "e", "=", "LocalAreaId", "(", ")", "f", "=", "ControlChannelDescription", "(", ")", "g", "=", "CellOptionsBCCH", "(", ")", "h", "=", "CellSelectionParameters", "(", ")", "i", "=", "RachControlParameters", "(", ")", "j", "=", "Si3RestOctets", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "/", "e", "/", "f", "/", "g", "/", "h", "/", "i", "/", "j", "return", "packet" ]
SYSTEM INFORMATION TYPE 3 Section 9.1.35
[ "SYSTEM", "INFORMATION", "TYPE", "3", "Section", "9", ".", "1", ".", "35" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L1038-L1051
train
237,195
phaethon/kamene
kamene/contrib/gsm_um.py
systemInformationType4
def systemInformationType4(ChannelDescription_presence=0, MobileAllocation_presence=0): """SYSTEM INFORMATION TYPE 4 Section 9.1.36""" a = L2PseudoLength() b = TpPd(pd=0x6) c = MessageType(mesType=0x1C) # 000111100 d = LocalAreaId() e = CellSelectionParameters() f = RachControlParameters() packet = a / b / c / d / e / f if ChannelDescription_presence is 1: g = ChannelDescriptionHdr(ieiCD=0x64, eightBitCD=0x0) packet = packet / g if MobileAllocation_presence is 1: h = MobileAllocationHdr(ieiMA=0x72, eightBitMA=0x0) packet = packet / h i = Si4RestOctets() packet = packet / i return packet
python
def systemInformationType4(ChannelDescription_presence=0, MobileAllocation_presence=0): """SYSTEM INFORMATION TYPE 4 Section 9.1.36""" a = L2PseudoLength() b = TpPd(pd=0x6) c = MessageType(mesType=0x1C) # 000111100 d = LocalAreaId() e = CellSelectionParameters() f = RachControlParameters() packet = a / b / c / d / e / f if ChannelDescription_presence is 1: g = ChannelDescriptionHdr(ieiCD=0x64, eightBitCD=0x0) packet = packet / g if MobileAllocation_presence is 1: h = MobileAllocationHdr(ieiMA=0x72, eightBitMA=0x0) packet = packet / h i = Si4RestOctets() packet = packet / i return packet
[ "def", "systemInformationType4", "(", "ChannelDescription_presence", "=", "0", ",", "MobileAllocation_presence", "=", "0", ")", ":", "a", "=", "L2PseudoLength", "(", ")", "b", "=", "TpPd", "(", "pd", "=", "0x6", ")", "c", "=", "MessageType", "(", "mesType", "=", "0x1C", ")", "# 000111100", "d", "=", "LocalAreaId", "(", ")", "e", "=", "CellSelectionParameters", "(", ")", "f", "=", "RachControlParameters", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "/", "e", "/", "f", "if", "ChannelDescription_presence", "is", "1", ":", "g", "=", "ChannelDescriptionHdr", "(", "ieiCD", "=", "0x64", ",", "eightBitCD", "=", "0x0", ")", "packet", "=", "packet", "/", "g", "if", "MobileAllocation_presence", "is", "1", ":", "h", "=", "MobileAllocationHdr", "(", "ieiMA", "=", "0x72", ",", "eightBitMA", "=", "0x0", ")", "packet", "=", "packet", "/", "h", "i", "=", "Si4RestOctets", "(", ")", "packet", "=", "packet", "/", "i", "return", "packet" ]
SYSTEM INFORMATION TYPE 4 Section 9.1.36
[ "SYSTEM", "INFORMATION", "TYPE", "4", "Section", "9", ".", "1", ".", "36" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L1058-L1076
train
237,196
phaethon/kamene
kamene/contrib/gsm_um.py
systemInformationType5bis
def systemInformationType5bis(): """SYSTEM INFORMATION TYPE 5bis Section 9.1.38""" a = L2PseudoLength(l2pLength=0x12) b = TpPd(pd=0x6) c = MessageType(mesType=0x5) # 00000101 d = NeighbourCellsDescription() packet = a / b / c / d return packet
python
def systemInformationType5bis(): """SYSTEM INFORMATION TYPE 5bis Section 9.1.38""" a = L2PseudoLength(l2pLength=0x12) b = TpPd(pd=0x6) c = MessageType(mesType=0x5) # 00000101 d = NeighbourCellsDescription() packet = a / b / c / d return packet
[ "def", "systemInformationType5bis", "(", ")", ":", "a", "=", "L2PseudoLength", "(", "l2pLength", "=", "0x12", ")", "b", "=", "TpPd", "(", "pd", "=", "0x6", ")", "c", "=", "MessageType", "(", "mesType", "=", "0x5", ")", "# 00000101", "d", "=", "NeighbourCellsDescription", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "return", "packet" ]
SYSTEM INFORMATION TYPE 5bis Section 9.1.38
[ "SYSTEM", "INFORMATION", "TYPE", "5bis", "Section", "9", ".", "1", ".", "38" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L1093-L1100
train
237,197
phaethon/kamene
kamene/contrib/gsm_um.py
systemInformationType5ter
def systemInformationType5ter(): """SYSTEM INFORMATION TYPE 5ter Section 9.1.39""" a = L2PseudoLength(l2pLength=0x12) b = TpPd(pd=0x6) c = MessageType(mesType=0x6) # 00000110 d = NeighbourCellsDescription2() packet = a / b / c / d return packet
python
def systemInformationType5ter(): """SYSTEM INFORMATION TYPE 5ter Section 9.1.39""" a = L2PseudoLength(l2pLength=0x12) b = TpPd(pd=0x6) c = MessageType(mesType=0x6) # 00000110 d = NeighbourCellsDescription2() packet = a / b / c / d return packet
[ "def", "systemInformationType5ter", "(", ")", ":", "a", "=", "L2PseudoLength", "(", "l2pLength", "=", "0x12", ")", "b", "=", "TpPd", "(", "pd", "=", "0x6", ")", "c", "=", "MessageType", "(", "mesType", "=", "0x6", ")", "# 00000110", "d", "=", "NeighbourCellsDescription2", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "return", "packet" ]
SYSTEM INFORMATION TYPE 5ter Section 9.1.39
[ "SYSTEM", "INFORMATION", "TYPE", "5ter", "Section", "9", ".", "1", ".", "39" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L1105-L1112
train
237,198
phaethon/kamene
kamene/contrib/gsm_um.py
systemInformationType6
def systemInformationType6(): """SYSTEM INFORMATION TYPE 6 Section 9.1.40""" a = L2PseudoLength(l2pLength=0x0b) b = TpPd(pd=0x6) c = MessageType(mesType=0x1e) # 00011011 d = CellIdentity() e = LocalAreaId() f = CellOptionsBCCH() g = NccPermitted() h = Si6RestOctets() packet = a / b / c / d / e / f / g return packet
python
def systemInformationType6(): """SYSTEM INFORMATION TYPE 6 Section 9.1.40""" a = L2PseudoLength(l2pLength=0x0b) b = TpPd(pd=0x6) c = MessageType(mesType=0x1e) # 00011011 d = CellIdentity() e = LocalAreaId() f = CellOptionsBCCH() g = NccPermitted() h = Si6RestOctets() packet = a / b / c / d / e / f / g return packet
[ "def", "systemInformationType6", "(", ")", ":", "a", "=", "L2PseudoLength", "(", "l2pLength", "=", "0x0b", ")", "b", "=", "TpPd", "(", "pd", "=", "0x6", ")", "c", "=", "MessageType", "(", "mesType", "=", "0x1e", ")", "# 00011011", "d", "=", "CellIdentity", "(", ")", "e", "=", "LocalAreaId", "(", ")", "f", "=", "CellOptionsBCCH", "(", ")", "g", "=", "NccPermitted", "(", ")", "h", "=", "Si6RestOctets", "(", ")", "packet", "=", "a", "/", "b", "/", "c", "/", "d", "/", "e", "/", "f", "/", "g", "return", "packet" ]
SYSTEM INFORMATION TYPE 6 Section 9.1.40
[ "SYSTEM", "INFORMATION", "TYPE", "6", "Section", "9", ".", "1", ".", "40" ]
11d4064844f4f68ac5d7546f5633ac7d02082914
https://github.com/phaethon/kamene/blob/11d4064844f4f68ac5d7546f5633ac7d02082914/kamene/contrib/gsm_um.py#L1117-L1128
train
237,199