_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 31 13.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q248700 | pkg_resouces_get_default_cache | train | def pkg_resouces_get_default_cache():
"""
Determine the default cache location
This returns the ``PYTHON_EGG_CACHE`` environment variable, if set.
Otherwise, on Windows, it returns a 'Python-Eggs' subdirectory of the
'Application Data' directory. On all other systems, it's '~/.python-eggs'.
""... | python | {
"resource": ""
} |
q248701 | getAssemblies | train | def getAssemblies(pth):
"""
Return the dependent assemblies of a binary.
"""
if not os.path.isfile(pth):
pth = check_extract_from_egg(pth)[0][0]
if pth.lower().endswith(".manifest"):
return []
# check for manifest file
manifestnm = pth + ".manifest"
if os.path.isfile(mani... | python | {
"resource": ""
} |
q248702 | selectAssemblies | train | def selectAssemblies(pth, manifest=None):
"""
Return a binary's dependent assemblies files that should be included.
Return a list of pairs (name, fullpath)
"""
rv = []
if not os.path.isfile(pth):
pth = check_extract_from_egg(pth)[0][0]
if manifest:
_depNames = set([dep.name ... | python | {
"resource": ""
} |
q248703 | selectImports | train | def selectImports(pth, xtrapath=None):
"""
Return the dependencies of a binary that should be included.
Return a list of pairs (name, fullpath)
"""
rv = []
if xtrapath is None:
xtrapath = [os.path.dirname(pth)]
else:
assert isinstance(xtrapath, list)
xtrapath = [os.p... | python | {
"resource": ""
} |
q248704 | getImports | train | def getImports(pth):
"""Forwards to the correct getImports implementation for the platform.
"""
if not os.path.isfile(pth):
pth = check_extract_from_egg(pth)[0][0]
if is_win or is_cygwin:
if pth.lower().endswith(".manifest"):
return []
try:
return _getImpo... | python | {
"resource": ""
} |
q248705 | findLibrary | train | def findLibrary(name):
"""
Look for a library in the system.
Emulate the algorithm used by dlopen.
`name`must include the prefix, e.g. ``libpython2.4.so``
"""
assert is_unix, "Current implementation for Unix only (Linux, Solaris, AIX)"
lib = None
# Look in the LD_LIBRARY_PATH
lp =... | python | {
"resource": ""
} |
q248706 | getSoname | train | def getSoname(filename):
"""
Return the soname of a library.
"""
cmd = ["objdump", "-p", "-j", ".dynamic", filename]
m | python | {
"resource": ""
} |
q248707 | _os_bootstrap | train | def _os_bootstrap():
"""
Set up 'os' module replacement functions for use during import bootstrap.
"""
global _os_stat, _os_getcwd, _os_environ, _os_listdir
global _os_path_join, _os_path_dirname, _os_path_basename
global _os_sep
names = sys.builtin_module_names
join = dirname = envir... | python | {
"resource": ""
} |
q248708 | scan_code_for_ctypes | train | def scan_code_for_ctypes(co, instrs, i):
"""Detects ctypes dependencies, using reasonable heuristics that should
cover most common ctypes usages; returns a tuple of two lists, one
containing names of binaries detected as dependencies, the other containing
warnings.
"""
def _libFromConst(i):
... | python | {
"resource": ""
} |
q248709 | _resolveCtypesImports | train | def _resolveCtypesImports(cbinaries):
"""Completes ctypes BINARY entries for modules with their full path.
"""
if is_unix:
envvar = "LD_LIBRARY_PATH"
elif is_darwin:
envvar = "DYLD_LIBRARY_PATH"
else:
envvar = "PATH"
def _setPaths():
path = os.pathsep.join(PyInst... | python | {
"resource": ""
} |
q248710 | degree_dist | train | def degree_dist(graph, limits=(0,0), bin_num=10, mode='out'):
'''
Computes the degree distribution for a graph.
Returns a list of tuples where the first element of the tuple is the center of the bin
representing a range of degrees and the second element of the tuple are the number of nodes
with the... | python | {
"resource": ""
} |
q248711 | ObjectGraph.flatten | train | def flatten(self, condition=None, start=None):
"""
Iterate over the subgraph that is entirely reachable by condition
starting from the given start node or the ObjectGraph root
"""
if start is None:
| python | {
"resource": ""
} |
q248712 | ObjectGraph.filterStack | train | def filterStack(self, filters):
"""
Filter the ObjectGraph in-place by removing all edges to nodes that
do not match every filter in the given filter list
Returns a tuple containing the number of: (nodes_visited, nodes_removed, nodes_orphaned)
"""
visited, removes, orpha... | python | {
"resource": ""
} |
q248713 | ObjectGraph.removeNode | train | def removeNode(self, node):
"""
Remove the given node from the graph if it exists
"""
| python | {
"resource": ""
} |
q248714 | ObjectGraph.removeReference | train | def removeReference(self, fromnode, tonode):
"""
Remove all edges from fromnode to tonode
"""
if fromnode is None:
fromnode = self
fromident = self.getIdent(fromnode)
toident = self.getIdent(tonode)
if fromident is not None and toident is not None:
... | python | {
"resource": ""
} |
q248715 | ObjectGraph.getIdent | train | def getIdent(self, node):
"""
Get the graph identifier for a node
"""
ident = self.getRawIdent(node)
if ident is not None:
return ident
node | python | {
"resource": ""
} |
q248716 | ObjectGraph.getRawIdent | train | def getRawIdent(self, node):
"""
Get the identifier for a node object
"""
if node is self:
return node
| python | {
"resource": ""
} |
q248717 | ObjectGraph.findNode | train | def findNode(self, node):
"""
Find the node on the graph
"""
ident = self.getRawIdent(node)
if ident is None:
ident = node
try: | python | {
"resource": ""
} |
q248718 | ObjectGraph.addNode | train | def addNode(self, node):
"""
Add a node to the graph referenced by the root
"""
self.msg(4, "addNode", node)
try:
| python | {
"resource": ""
} |
q248719 | ObjectGraph.createReference | train | def createReference(self, fromnode, tonode, edge_data=None):
"""
Create a reference from fromnode to tonode
"""
if fromnode is None:
fromnode = self
fromident, toident = self.getIdent(fromnode), self.getIdent(tonode)
if fromident is None or toident is None:
... | python | {
"resource": ""
} |
q248720 | ObjectGraph.createNode | train | def createNode(self, cls, name, *args, **kw):
"""
Add a node of type cls to the graph if it does not already exist
by the given name
"""
m = self.findNode(name)
| python | {
"resource": ""
} |
q248721 | ObjectGraph.msg | train | def msg(self, level, s, *args):
"""
Print a debug message with the given level
| python | {
"resource": ""
} |
q248722 | dijkstra | train | def dijkstra(graph, start, end=None):
"""
Dijkstra's algorithm for shortest paths
`David Eppstein, UC Irvine, 4 April 2002 <http://www.ics.uci.edu/~eppstein/161/python/>`_
`Python Cookbook Recipe <http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/119466>`_
Find shortest paths from the star... | python | {
"resource": ""
} |
q248723 | _priorityDictionary.smallest | train | def smallest(self):
'''
Find smallest item after removing deleted items from front of heap.
'''
if len(self) == 0:
raise IndexError, "smallest of empty priorityDictionary"
heap = self.__heap
while heap[0][1] not in self or self[heap[0][1]] != heap[0][0]:
... | python | {
"resource": ""
} |
q248724 | _write_textfile | train | def _write_textfile(filename, text):
"""
Write `text` into file `filename`. If the target directory does
not exist, create it.
"""
dirname = os.path.dirname(filename)
if | python | {
"resource": ""
} |
q248725 | __add_options | train | def __add_options(parser):
"""
Add the `Configure` options to a option-parser instance or a
option group.
"""
parser.add_option('--upx-dir', default=None,
help='Directory containing UPX.')
parser.add_option('-C', '--configfile',
| python | {
"resource": ""
} |
q248726 | abspath | train | def abspath(path):
"""Return the absolute path to a file and canonicalize it
Path is returned without a trailing slash and without redundant slashes.
Caches the user's home directory.
:param path: A string for the path. This should not have any wildcards.
:returns: Absolute path to the file
:... | python | {
"resource": ""
} |
q248727 | cp | train | def cp(hdfs_src, hdfs_dst):
"""Copy a file
:param hdfs_src: Source (str)
:param hdfs_dst: Destination (str)
:raises: IOError: If unsuccessful
"""
| python | {
"resource": ""
} |
q248728 | stat | train | def stat(path, format):
"""Call stat on file
:param path: HDFS Path
:param format: Stat format
:returns: Stat output
:raises: IOError: If unsuccessful
"""
| python | {
"resource": ""
} |
q248729 | mv | train | def mv(hdfs_src, hdfs_dst):
"""Move a file on hdfs
:param hdfs_src: Source (str)
:param hdfs_dst: Destination (str)
:raises: IOError: If unsuccessful
"""
| python | {
"resource": ""
} |
q248730 | put | train | def put(local_path, hdfs_path):
"""Put a file on hdfs
:param local_path: Source (str)
:param hdfs_path: Destination (str)
:raises: IOError: If unsuccessful
"""
| python | {
"resource": ""
} |
q248731 | get | train | def get(hdfs_path, local_path):
"""Get a file from hdfs
:param hdfs_path: Destination (str)
:param local_path: Source (str)
:raises: IOError: If unsuccessful
"""
| python | {
"resource": ""
} |
q248732 | ls | train | def ls(path):
"""List files on HDFS.
:param path: A string (potentially with wildcards).
:rtype: A list of strings representing HDFS paths.
:raises: IOError: An error occurred listing the directory (e.g., not available).
"""
rcode, stdout, stderr = | python | {
"resource": ""
} |
q248733 | writetb | train | def writetb(path, kvs, java_mem_mb=256):
"""Write typedbytes sequence file to HDFS given an iterator of KeyValue pairs
:param path: HDFS path (string)
:param kvs: Iterator of (key, value)
:param java_mem_mb: Integer of java heap size in MB (default 256)
:raises: IOError: An error occurred while sav... | python | {
"resource": ""
} |
q248734 | writetb_parts | train | def writetb_parts(path, kvs, num_per_file, **kw):
"""Write typedbytes sequence files to HDFS given an iterator of KeyValue pairs
This is useful when a task is CPU bound and wish to break up its inputs
into pieces smaller than the HDFS block size. This causes Hadoop to launch
one Map task per file. As... | python | {
"resource": ""
} |
q248735 | Graph.add_node | train | def add_node(self, node, node_data=None):
"""
Adds a new node to the graph. Arbitrary data can be attached to the
node via the node_data parameter. Adding the same node twice will be
silently ignored.
The node must be a hashable value.
"""
#
# the nodes... | python | {
"resource": ""
} |
q248736 | Graph.add_edge | train | def add_edge(self, head_id, tail_id, edge_data=1, create_nodes=True):
"""
Adds a directed edge going from head_id to tail_id.
Arbitrary data can be attached to the edge via edge_data.
It may create the nodes if adding edges between nonexisting ones.
:param head_id: head node
... | python | {
"resource": ""
} |
q248737 | Graph.hide_edge | train | def hide_edge(self, edge):
"""
Hides an edge from the graph. The edge may be unhidden at some later
time.
"""
try:
head_id, tail_id, edge_data = self.hidden_edges[edge] = self.edges[edge]
self.nodes[tail_id][0].remove(edge) | python | {
"resource": ""
} |
q248738 | Graph.hide_node | train | def hide_node(self, node):
"""
Hides a node from the graph. The incoming and outgoing edges of the
node will also be hidden. The node may be unhidden at some later time.
"""
try:
all_edges = self.all_edges(node)
| python | {
"resource": ""
} |
q248739 | Graph.restore_node | train | def restore_node(self, node):
"""
Restores a previously hidden node back into the graph and restores
all of its incoming and outgoing edges.
"""
try:
self.nodes[node], all_edges = self.hidden_nodes[node]
for edge in | python | {
"resource": ""
} |
q248740 | Graph.restore_edge | train | def restore_edge(self, edge):
"""
Restores a previously hidden edge back into the graph.
"""
try:
head_id, tail_id, data = self.hidden_edges[edge]
self.nodes[tail_id][0].append(edge)
self.nodes[head_id][1].append(edge)
| python | {
"resource": ""
} |
q248741 | Graph.restore_all_edges | train | def restore_all_edges(self):
"""
Restores all hidden edges.
"""
for edge in | python | {
"resource": ""
} |
q248742 | Graph.describe_node | train | def describe_node(self, node):
"""
return node, node data, outgoing edges, incoming edges for node
"""
| python | {
"resource": ""
} |
q248743 | Graph.describe_edge | train | def describe_edge(self, edge):
"""
return edge, edge data, head, tail for edge
"""
| python | {
"resource": ""
} |
q248744 | Graph.out_nbrs | train | def out_nbrs(self, node):
"""
List of nodes connected by outgoing edges
"""
| python | {
"resource": ""
} |
q248745 | Graph.inc_nbrs | train | def inc_nbrs(self, node):
"""
List of nodes connected by incoming edges
"""
| python | {
"resource": ""
} |
q248746 | Graph.all_nbrs | train | def all_nbrs(self, node):
"""
List of nodes connected by incoming and outgoing edges
"""
| python | {
"resource": ""
} |
q248747 | Graph.out_edges | train | def out_edges(self, node):
"""
Returns a list of the outgoing edges
"""
try:
return list(self.nodes[node][1])
| python | {
"resource": ""
} |
q248748 | Graph.inc_edges | train | def inc_edges(self, node):
"""
Returns a list of the incoming edges
"""
try:
return list(self.nodes[node][0])
| python | {
"resource": ""
} |
q248749 | Graph.all_edges | train | def all_edges(self, node):
"""
Returns a list of incoming and outging edges.
"""
| python | {
"resource": ""
} |
q248750 | Graph._topo_sort | train | def _topo_sort(self, forward=True):
"""
Topological sort.
Returns a list of nodes where the successors (based on outgoing and
incoming edges selected by the forward parameter) of any given node
appear in the sequence after that node.
"""
topo_list = []
qu... | python | {
"resource": ""
} |
q248751 | Graph._bfs_subgraph | train | def _bfs_subgraph(self, start_id, forward=True):
"""
Private method creates a subgraph in a bfs order.
The forward parameter specifies whether it is a forward or backward
traversal.
"""
if forward:
get_bfs = self.forw_bfs
get_nbrs = self.out_nbrs... | python | {
"resource": ""
} |
q248752 | Graph.iterdfs | train | def iterdfs(self, start, end=None, forward=True):
"""
Collecting nodes in some depth first traversal.
The forward parameter specifies whether it is a forward or backward
traversal.
"""
visited, stack = set([start]), deque([start])
if forward:
get_edg... | python | {
"resource": ""
} |
q248753 | Graph._iterbfs | train | def _iterbfs(self, start, end=None, forward=True):
"""
The forward parameter specifies whether it is a forward or backward
traversal. Returns a list of tuples where the first value is the hop
value the second value is the node id.
"""
queue, visited = deque([(start, 0)])... | python | {
"resource": ""
} |
q248754 | Graph.forw_bfs | train | def forw_bfs(self, start, end=None):
"""
Returns a list of nodes in some forward BFS order.
Starting from the start node the breadth first search proceeds along
| python | {
"resource": ""
} |
q248755 | Graph.back_bfs | train | def back_bfs(self, start, end=None):
"""
Returns a list of nodes in some backward BFS order.
Starting from the start node the breadth first search proceeds along
| python | {
"resource": ""
} |
q248756 | Graph.forw_dfs | train | def forw_dfs(self, start, end=None):
"""
Returns a list of nodes in some forward DFS order.
Starting with the start node the depth first search proceeds along
| python | {
"resource": ""
} |
q248757 | Graph.back_dfs | train | def back_dfs(self, start, end=None):
"""
Returns a list of nodes in some backward DFS order.
Starting from the start node the depth first search proceeds along
| python | {
"resource": ""
} |
q248758 | Graph.clust_coef | train | def clust_coef(self, node):
"""
Computes and returns the local clustering coefficient of node. The
local cluster coefficient is proportion of the actual number of edges between
neighbours of node and the maximum number of edges between those neighbours.
See <http://en.wikipedia... | python | {
"resource": ""
} |
q248759 | Graph.get_hops | train | def get_hops(self, start, end=None, forward=True):
"""
Computes the hop distance to all nodes centered around a specified node.
First order neighbours are at hop 1, their neigbours are at hop 2 etc.
Uses :py:meth:`forw_bfs` or :py:meth:`back_bfs` depending on the value of the forward
... | python | {
"resource": ""
} |
q248760 | CTOC.frombinary | train | def frombinary(self, s):
"""Decode the binary string into an in memory list.
S is a binary string."""
entrylen = struct.calcsize(self.ENTRYSTRUCT)
p = 0
while p<len(s):
(slen, dpos, dlen, ulen, flag, typcd) = struct.unpack(self.ENTRYSTRUCT,
... | python | {
"resource": ""
} |
q248761 | CTOC.tobinary | train | def tobinary(self):
"""Return self as a binary string."""
entrylen = struct.calcsize(self.ENTRYSTRUCT)
rslt = []
for (dpos, dlen, ulen, flag, typcd, nm) in self.data:
nmlen = len(nm) + 1 # add 1 for a '\0'
# version 4
# rslt.append(struct.pack(se... | python | {
"resource": ""
} |
q248762 | CTOC.add | train | def add(self, dpos, dlen, ulen, flag, typcd, nm):
"""Add an entry to the table of contents.
DPOS is data position.
DLEN is data length.
ULEN is the uncompressed data len.
FLAG says if the data is compressed.
| python | {
"resource": ""
} |
q248763 | CTOC.find | train | def find(self, name):
"""Return the index of the toc entry with name NAME.
Return -1 for failure."""
for i, nm in enumerate(self.data):
| python | {
"resource": ""
} |
q248764 | CArchive.checkmagic | train | def checkmagic(self):
"""Verify that self is a valid CArchive.
Magic signature is at end of the archive."""
#magic is at EOF; if we're embedded, we need to figure where that is
if self.len:
self.lib.seek(self.start+self.len, 0)
else:
self.lib.seek(0, ... | python | {
"resource": ""
} |
q248765 | CArchive.loadtoc | train | def loadtoc(self):
"""Load the table of contents into memory."""
self.toc = self.TOCTMPLT()
| python | {
"resource": ""
} |
q248766 | CArchive.extract | train | def extract(self, name):
"""Get the contents of an entry.
NAME is an entry name.
Return the tuple (ispkg, contents).
For non-Python resoures, ispkg is meaningless (and 0).
Used by the import mechanism."""
if type(name) == type(''):
ndx = self.toc.... | python | {
"resource": ""
} |
q248767 | CArchive.contents | train | def contents(self):
"""Return the names of the entries"""
rslt = []
for (dpos, dlen, ulen, flag, typcd, nm) in | python | {
"resource": ""
} |
q248768 | CArchive.add | train | def add(self, entry):
"""Add an ENTRY to the CArchive.
ENTRY must have:
entry[0] is name (under which it will be saved).
entry[1] is fullpathname of the file.
entry[2] is a flag for it's storage format (0==uncompressed,
1==compressed)
... | python | {
"resource": ""
} |
q248769 | CArchive.save_toc | train | def save_toc(self, tocpos):
"""Save the table of contents to disk."""
self.tocpos = tocpos
tocstr = self.toc.tobinary()
| python | {
"resource": ""
} |
q248770 | CArchive.save_trailer | train | def save_trailer(self, tocpos):
"""Save the trailer to disk.
CArchives can be opened from the end - the trailer points
back to the start. """
totallen = tocpos + self.toclen + self.TRLLEN
pyvers = sys.version_info[0]*10 + sys.version_info[1]
trl = | python | {
"resource": ""
} |
q248771 | CArchive.openEmbedded | train | def openEmbedded(self, name):
"""Open a CArchive of name NAME embedded within this CArchive."""
ndx = self.toc.find(name)
if ndx == -1:
raise KeyError, "Member '%s' | python | {
"resource": ""
} |
q248772 | _find_hstreaming | train | def _find_hstreaming():
"""Finds the whole path to the hadoop streaming jar.
If the environmental var HADOOP_HOME is specified, then start the search
from there.
Returns:
Full path to the hadoop streaming jar if found, else return an empty
string.
"""
global WARNED_HADOOP_HOME,... | python | {
"resource": ""
} |
q248773 | _listeq_to_dict | train | def _listeq_to_dict(jobconfs):
"""Convert iterators of 'key=val' into a dictionary with later values taking priority."""
if not isinstance(jobconfs, dict):
jobconfs = | python | {
"resource": ""
} |
q248774 | launch_frozen | train | def launch_frozen(in_name, out_name, script_path, frozen_tar_path=None,
temp_path='_hadoopy_temp', cache=True, check_script=False,
**kw):
"""Freezes a script and then launches it.
This function will freeze your python program, and place it on HDFS
in 'temp_path'. It wil... | python | {
"resource": ""
} |
q248775 | include_library | train | def include_library(libname):
"""Check if a dynamic library should be included with application or not."""
# For configuration phase we need to have exclude / include lists None
# so these checking is skipped and library gets included.
if exclude_list:
if exclude_list.search(libname) and not inc... | python | {
"resource": ""
} |
q248776 | mac_set_relative_dylib_deps | train | def mac_set_relative_dylib_deps(libname):
"""
On Mac OS X set relative paths to dynamic library dependencies of `libname`.
Relative paths allow to avoid using environment variable DYLD_LIBRARY_PATH.
There are known some issues with DYLD_LIBRARY_PATH. Relative paths is
more flexible mechanism.
... | python | {
"resource": ""
} |
q248777 | from_settings | train | def from_settings(settings):
""" Factory method that returns an instance of channel
:param str connection_type: This field can be `blocking`
`asyncore`, `libev`, `select`, `tornado`, or `twisted`
See pika documentation for more details:
TODO: put pika url regarding connecti... | python | {
"resource": ""
} |
q248778 | RabbitMQMixin.setup_rabbitmq | train | def setup_rabbitmq(self):
""" Setup RabbitMQ connection.
Call this method after spider has set its crawler object.
:return: None
"""
if not self.rabbitmq_key:
| python | {
"resource": ""
} |
q248779 | RabbitMQMixin.schedule_next_request | train | def schedule_next_request(self):
""" Schedules a request, if exists.
:return:
"""
| python | {
"resource": ""
} |
q248780 | set_flags | train | def set_flags(obj, flag_field, flags):
"""Will process the flags and set attributes in the object accordingly.
The object "obj" will gain attributes named after the flags provided in
"flags" and valued True/False, matching the results of applying each
flag value from "flags" to flag_field.
"""
... | python | {
"resource": ""
} |
q248781 | UnicodeStringWrapperPostProcessor.ask_pascal_16 | train | def ask_pascal_16(self, next_rva_ptr):
"""The next RVA is taken to be the one immediately following this one.
Such RVA could indicate the natural end of the string and will be checked
with the possible length contained in the first word.
"""
| python | {
"resource": ""
} |
q248782 | Dump.add | train | def add(self, txt, indent=0):
"""Adds some text, no newline will be appended.
The text can be indented with the optional argument 'indent'.
"""
if isinstance(txt, unicode):
try:
txt = str(txt)
except UnicodeEncodeError:
... | python | {
"resource": ""
} |
q248783 | SectionStructure.contains_offset | train | def contains_offset(self, offset):
"""Check whether the section contains the file offset provided."""
if self.PointerToRawData is None:
# bss and other sections containing only uninitialized data must have 0
# and do not take space in the | python | {
"resource": ""
} |
q248784 | PE.parse_resource_entry | train | def parse_resource_entry(self, rva):
"""Parse a directory entry from the resources directory."""
try:
data = self.get_data( rva, Structure(self.__IMAGE_RESOURCE_DIRECTORY_ENTRY_format__).sizeof() )
except PEFormatError, excp:
# A warning will be added by the caller if th... | python | {
"resource": ""
} |
q248785 | PE.parse_imports | train | def parse_imports(self, original_first_thunk, first_thunk, forwarder_chain):
"""Parse the imported symbols.
It will fill a list, which will be available as the dictionary
attribute "imports". Its keys will be the DLL names and the values
all the symbols imported from that object... | python | {
"resource": ""
} |
q248786 | PE.get_data | train | def get_data(self, rva=0, length=None):
"""Get data regardless of the section where it lies on.
Given a RVA and the size of the chunk to retrieve, this method
will find the section where the data lies and return the data.
"""
s = self.get_section_by_rva(rva)
... | python | {
"resource": ""
} |
q248787 | PE.get_rva_from_offset | train | def get_rva_from_offset(self, offset):
"""Get the RVA corresponding to this file offset. """
s = self.get_section_by_offset(offset)
if not s:
if self.sections:
lowest_rva = min( [ adjust_SectionAlignment( s.VirtualAddress,
self.OPTIONAL_H... | python | {
"resource": ""
} |
q248788 | PE.get_offset_from_rva | train | def get_offset_from_rva(self, rva):
"""Get the file offset corresponding to this RVA.
Given a RVA , this method will find the section where the
data lies and return the offset within the file.
"""
s = self.get_section_by_rva(rva)
if not s:
#... | python | {
"resource": ""
} |
q248789 | PE.get_string_at_rva | train | def get_string_at_rva(self, rva):
"""Get an ASCII string located at the given address."""
s = self.get_section_by_rva(rva)
if not s:
| python | {
"resource": ""
} |
q248790 | PE.get_string_from_data | train | def get_string_from_data(self, offset, data):
"""Get an ASCII string from within the data."""
# OC Patch
b = None
try:
b = data[offset]
except IndexError:
return ''
s = ''
while ord(b):
s += b
| python | {
"resource": ""
} |
q248791 | PE.set_bytes_at_rva | train | def set_bytes_at_rva(self, rva, data):
"""Overwrite, with the given string, the bytes at the file offset corresponding to the given RVA.
Return True if successful, False otherwise. It can fail if the
offset is outside the file's boundaries.
"""
| python | {
"resource": ""
} |
q248792 | PE.merge_modified_section_data | train | def merge_modified_section_data(self):
"""Update the PE image content with any individual section data that has been modified."""
for section in self.sections:
section_data_start = adjust_FileAlignment( section.PointerToRawData,
self.OPTIONAL_HEADER.FileAlignment )
... | python | {
"resource": ""
} |
q248793 | PE.is_driver | train | def is_driver(self):
"""Check whether the file is a Windows driver.
This will return true only if there are reliable indicators of the image
being a driver.
"""
# Checking that the ImageBase field of the OptionalHeader is above or
# equal to 0x80000000 (that is,... | python | {
"resource": ""
} |
q248794 | _copytree | train | def _copytree(src, dst):
"""Similar to shutils.copytree, except that dst is already there
"""
try:
os.makedirs(dst)
except OSError:
pass # It must already exist
for file in os.listdir(src):
| python | {
"resource": ""
} |
q248795 | _md5_file | train | def _md5_file(fn, block_size=1048576):
"""Builds the MD5 of a file block by block
Args:
fn: File path
block_size: Size of the blocks to consider (default 1048576)
Returns:
File MD5
"""
h = hashlib.md5()
| python | {
"resource": ""
} |
q248796 | freeze_script | train | def freeze_script(script_path, cache=True, temp_path='_hadoopy_temp'):
"""Freezes a script, puts it on hdfs, and gives you the path
'frozen_tar_path' can be given to launch_frozen and it will use that
instead of making its own, this is useful for repeated calls. If a
file with the same md5 already exi... | python | {
"resource": ""
} |
q248797 | freeze | train | def freeze(script_path, target_dir='frozen', **kw):
"""Wraps pyinstaller and provides an easy to use interface
Args:
script_path: Absolute path to python script to be frozen.
Returns:
List of freeze commands ran
Raises:
subprocess.CalledProcessError: Freeze error.
OSEr... | python | {
"resource": ""
} |
q248798 | freeze_to_tar | train | def freeze_to_tar(script_path, freeze_fn, extra_files=None):
"""Freezes a script to a .tar or .tar.gz file
The script contains all of the files at the root of the tar
Args:
script_path: Path to python script to be frozen.
freeze_fn: Tar filename (must end in .tar or .tar.gz)
extra_... | python | {
"resource": ""
} |
q248799 | mobile_template | train | def mobile_template(template):
"""
Mark a function as mobile-ready and pass a mobile template if MOBILE.
For example::
@mobile_template('a/{mobile/}b.html')
def view(template=None):
...
if ``request.MOBILE=True`` the template will be `a/mobile/b.html`.
if ``request.MO... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.