Because Python isn’t strongly typed, sometimes PyDev doesn’t know what type a variable is – and therefore it cannot give you accurate code completions. Here’s how to make that better.
In simpler situations, PyDev works very well. For example:
emp = Employee()
Typing ‘emp.’ will get you a good autocomplete.
Now, let’s say you have something like this:
emp = something.find_employee("dave")
Then ‘emp.’ won’t get you anything – PyDev doesn’t necessarily know what type is being returned.
If you use python’s assert method:
emp = something.find_employee("dave") assert isinstance(emp, Employee)
PyDev now knows what type the variable is, and you’ll get more effective code completions.
When running in production, you can pass the “-O” flag to the interpreter, and it will ignore the assert statements.
I needed to return all the members of an object as an XML document in Python. I used the ElementTree library to do this.
The class in question is pretty basic: It has a constructor, member variables, getters and setters for the member variables, and now this new function.
Every Python class has a built-in __dict__ member, which is a dictionary ({}) of key/value pairs for all of the member variables, so I use that to get all of the variables to add to the ElementTree.
This function returns an xml.etree.ElementTree.Element object, which can be turned into a string if needed by using ElementTree’s tostring() method.
def getXML(self): """ Returns an XML representation of the object """ topElem = Element("item") for key in self.__dict__.keys(): elem = SubElement(topElem, key) elem.text = str(self.__dict__[key]) return topElem
Often times, in your Squid proxy, you may have a redirector configured – such as SquidGuard:
redirect_program /usr/local/bin/squidGuard -c /usr/local/etc/squid/squidGuard.conf
I ran into a problem tonight with my Roku box where SquidGuard was seeing Roku’s NetFlix access as a security threat. So, to make Squid bypass the redirector, add an ACL and a redirector-access rule:
acl netflix dstdomain .netflix.com redirector_access deny netflix
There you have it – any requests to *.netflix.com will skip the redirector.
By default, Squid sends HTTP headers on every request that can give away information about your internal network. Here’s an example of these headers:
HTTP_VIA:1.1 proxyserver.local (squid/3.1.16) HTTP_X_FORWARDED_FOR:192.168.0.123
That’s three pieces of information you may not want to give away: The host name of your proxy server, the version of Squid it’s running, and the IP address of the system that’s making the request via the proxy.
Fortunately, it’s simple (and does not apparently violate any standards) to make these headers more anonymous – just use these configuration directives in your squid.conf:
# Be more anonymous forwarded_for off visible_hostname proxy.local httpd_suppress_version_string on
That will change the headers to look more like this:
HTTP_VIA:1.1 proxy.local (squid) HTTP_X_FORWARDED_FOR:unknown
If you have a switch, access point or other piece of network hardware that supports 802.1q VLAN tagging, and you’d like to your FreeBSD system to recognize them, it’s a pretty straight-forward configuration. I’ll use examples from my network to illustrate. My goal in this case, which I may write about in a separate post, was to create two segmented wifi networks – one for my main network and one for guests to connect to. I wanted the guest network to have access to the internet, but not to any of my other systems on the network.
Read the rest of Configure VLANs on FreeBSD (341 words)
Most of us don’t have native IPv6 Internet connections at home. Fortunately, it’s easy (and free) to get connected to the IPv6 Internet. Here’s how to get your FreeBSD box connected.
Read the rest of FreeBSD – IPv6 Tunnel and Gateway Configuration (523 words)
I spent some time thinking about backup strategy, and I decided for my purposes, I’d like to handle the staging process (getting all the files put together), and I’d like the backup solution itself to simply upload the files – but since I want to do nightly backups, I’d like the backup solution to have incremental capabilities.
I narrowed it down to two possible solutions – Tarsnap and Duplicity. Both support incremental backups, both are command-line capable. I decided to use Duplicity because it uploads directly to whichever back-end service you use – be it Amazon S3 or an SFTP server . Tarsnap uses S3, but that’s your only option, and they do some processing for you, and because of that, it costs more.
Now, on to the details.
Read the rest of FreeBSD Backup Using dump and duplicity (1,786 words)
The FreeBSD console is colorless by default – but most terminals and SSH clients these days support color. The benefits of colorizing your console should be pretty obvious. It makes your life a little easier – you don’t have to do as much mental processing.
Read the rest of FreeBSD – Colorize Your Console (154 words)
The Duke URLGrabber package for Python makes it incredibly easy to retrieve files from remote servers, and it abstracts urllib2 for you in a protocol-independent way, so you can focus on your application instead of spending time working with Python’s built-in urllib2.
On Windows and Mac OSX, by default, urllib2 (and therefore URLGrabber) will use the built-in proxy settings of the system – but sometimes you don’t want that. For example, let’s say you’re using a Windows box that’s on a domain, and proxy settings have been pushed down by group policy. You want to access local network resources without needing to route through the proxy or authenticate to it.
With urllib2, you would simply add code like the following:
proxy_support = urllib2.ProxyHandler({})
Note the empty dictionary “{}” to specify no proxies. Doing the same for URLGrabber was suggested on a mailing list post – and it apparently worked for the poster. However, I wasn’t able to get it to work, so I came up with another way. I just specified a dummy proxy for a dummy protocol, as follows:
kwargs["proxies"] = { 'nothing': 'http://nothing' }
Have fun!